void osi_Init(void) { static int once = 0; if (once++ > 0) /* just in case */ return; osi_InitGlock(); /* Initialize a lock for the kernel hcrypto bits. */ #ifndef UKERNEL init_hckernel_mutex(); #endif if (!afs_osicred_initialized) { #if defined(AFS_DARWIN80_ENV) afs_osi_ctxtp_initialized = 0; afs_osi_ctxtp = NULL; /* initialized in afs_Daemon since it has a proc reference that cannot be changed */ #endif #if defined(AFS_XBSD_ENV) /* Can't just invent one, must use crget() because of mutex */ afs_osi_credp = crdup(osi_curcred()); #elif defined(AFS_SUN5_ENV) afs_osi_credp = kcred; #else memset(&afs_osi_cred, 0, sizeof(afs_ucred_t)); #if defined(AFS_LINUX26_ENV) afs_set_cr_group_info(&afs_osi_cred, groups_alloc(0)); #endif #if defined(AFS_DARWIN80_ENV) afs_osi_cred.cr_ref = 1; /* kauth_cred_get_ref needs 1 existing ref */ #else # if !(defined(AFS_LINUX26_ENV) && defined(STRUCT_TASK_STRUCT_HAS_CRED)) crhold(&afs_osi_cred); /* don't let it evaporate */ # endif #endif afs_osi_credp = &afs_osi_cred; #endif afs_osicred_initialized = 1; } #ifdef AFS_SGI64_ENV osi_flid.fl_pid = osi_flid.fl_sysid = 0; #endif init_et_to_sys_error(); }
void osi_Init(void) { static int once = 0; if (once++ > 0) /* just in case */ return; #if defined(AFS_HPUX_ENV) osi_InitGlock(); #else /* AFS_HPUX_ENV */ #if defined(AFS_GLOBAL_SUNLOCK) #if defined(AFS_SGI62_ENV) mutex_init(&afs_global_lock, MUTEX_DEFAULT, "afs_global_lock"); #elif defined(AFS_OSF_ENV) usimple_lock_init(&afs_global_lock); afs_global_owner = (thread_t) 0; #elif defined(AFS_FBSD50_ENV) #if defined(AFS_FBSD80_ENV) && defined(WITNESS) /* "lock_initalized" (sic) can panic, checks a flag bit * is unset _before_ init */ memset(&afs_global_mtx, 0, sizeof(struct mtx)); #endif mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF); #elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) #if !defined(AFS_DARWIN80_ENV) lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0); #endif afs_global_owner = 0; #elif defined(AFS_AIX41_ENV) lock_alloc((void *)&afs_global_lock, LOCK_ALLOC_PIN, 1, 1); simple_lock_init((void *)&afs_global_lock); #elif !defined(AFS_LINUX22_ENV) /* Linux initialization in osi directory. Should move the others. */ mutex_init(&afs_global_lock, "afs_global_lock", MUTEX_DEFAULT, NULL); #endif #endif /* AFS_GLOBAL_SUNLOCK */ #endif /* AFS_HPUX_ENV */ if (!afs_osicred_initialized) { #if defined(AFS_DARWIN80_ENV) afs_osi_ctxtp_initialized = 0; afs_osi_ctxtp = NULL; /* initialized in afs_Daemon since it has a proc reference that cannot be changed */ #endif #if defined(AFS_XBSD_ENV) /* Can't just invent one, must use crget() because of mutex */ afs_osi_credp = crdup(osi_curcred()); #else memset(&afs_osi_cred, 0, sizeof(struct AFS_UCRED)); #if defined(AFS_LINUX26_ENV) afs_osi_cred.cr_group_info = groups_alloc(0); #endif #if defined(AFS_DARWIN80_ENV) afs_osi_cred.cr_ref = 1; /* kauth_cred_get_ref needs 1 existing ref */ #else crhold(&afs_osi_cred); /* don't let it evaporate */ #endif afs_osi_credp = &afs_osi_cred; #endif afs_osicred_initialized = 1; } #ifdef AFS_SGI64_ENV osi_flid.fl_pid = osi_flid.fl_sysid = 0; #endif init_et_to_sys_error(); }
afs_root(struct mount *mp, struct vnode **vpp) #endif { int error; struct vrequest treq; struct vcache *tvp = 0; struct vcache *gvp; #if !defined(AFS_FBSD53_ENV) || defined(AFS_FBSD80_ENV) struct thread *td = curthread; #endif struct ucred *cr = osi_curcred(); AFS_GLOCK(); AFS_STATCNT(afs_root); crhold(cr); tryagain: if (afs_globalVp && (afs_globalVp->f.states & CStatd)) { tvp = afs_globalVp; error = 0; } else { if (!(error = afs_InitReq(&treq, cr)) && !(error = afs_CheckInit())) { tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL); /* we really want this to stay around */ if (tvp) { gvp = afs_globalVp; afs_globalVp = tvp; if (gvp) { afs_PutVCache(gvp); if (tvp != afs_globalVp) { /* someone raced us and won */ afs_PutVCache(tvp); goto tryagain; } } } else error = ENOENT; } } if (tvp) { struct vnode *vp = AFSTOV(tvp); ASSERT_VI_UNLOCKED(vp, "afs_root"); AFS_GUNLOCK(); error = vget(vp, LK_EXCLUSIVE | LK_RETRY, td); AFS_GLOCK(); /* we dropped the glock, so re-check everything it had serialized */ if (!afs_globalVp || !(afs_globalVp->f.states & CStatd) || tvp != afs_globalVp) { vput(vp); afs_PutVCache(tvp); goto tryagain; } if (error != 0) goto tryagain; /* * I'm uncomfortable about this. Shouldn't this happen at a * higher level, and shouldn't we busy the top-level directory * to prevent recycling? */ vp->v_vflag |= VV_ROOT; afs_globalVFS = mp; *vpp = vp; } afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, tvp ? AFSTOV(tvp) : NULL, ICL_TYPE_INT32, error); AFS_GUNLOCK(); crfree(cr); return error; }