From: Michael Meffie Date: Sat, 8 Mar 2014 16:41:26 +0000 (-0500) Subject: libafs: afs_InitVolSlot function X-Git-Tag: upstream/1.8.0_pre1^2~754 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=75e3a5897405eeeba047cca1103ac32ccfaa03dc;p=packages%2Fo%2Fopenafs.git libafs: afs_InitVolSlot function Add a new local function to initialize newly gotten volume slots and move that code out of afs_SetupVolume(). Initialize the slot before putting the volume in the volume hash table list. Make it more clear to avoid using record 0. The volume items record 0 is not used, so avoid setting the tf pointer to the static fvolume buffer when reading record 0. Change-Id: Iffba52fbf8d72459c9a36015964e61d485f22ad4 Reviewed-on: http://gerrit.openafs.org/10877 Tested-by: BuildBot Reviewed-by: D Brashear --- diff --git a/src/afs/afs_stats.h b/src/afs/afs_stats.h index 71e337e63..687244b49 100644 --- a/src/afs/afs_stats.h +++ b/src/afs/afs_stats.h @@ -657,7 +657,8 @@ struct afs_MeanStats { AFS_CS(afs_ReadNoCache) /* osi_vnodeops.c */ \ AFS_CS(PSetTokens2) /* afs_pioctl.c */ \ AFS_CS(PPrefetchFromTape) /* afs_pioctl.c */ \ - AFS_CS(PFlushAllVolumeData) /* afs_pioctl.c */ + AFS_CS(PFlushAllVolumeData) /* afs_pioctl.c */ \ + AFS_CS(afs_InitVolSlot) /* afs_volume.c */ struct afs_CMCallStats { #define AFS_CS(call) afs_int32 C_ ## call; diff --git a/src/afs/afs_volume.c b/src/afs/afs_volume.c index ef0d825c5..249179408 100644 --- a/src/afs/afs_volume.c +++ b/src/afs/afs_volume.c @@ -104,6 +104,41 @@ afs_vtoi(char *aname) static struct fvolume staticFVolume; afs_int32 afs_FVIndex = -1; +/*! + * Initialize a newly gotten volume slot. + * + * \param tv volume slot to be initialized + * \param tf volume item data; null if none + * \param volid volume id for this volume slot + * \param cell cell for this volume slot + * \return none + */ +static void +afs_InitVolSlot(struct volume *tv, struct fvolume *tf, afs_int32 volid, + struct cell *tcell) +{ + AFS_STATCNT(afs_InitVolSlot); + memset(tv, 0, sizeof(struct volume)); + tv->cell = tcell->cellNum; + AFS_RWLOCK_INIT(&tv->lock, "volume lock"); + tv->volume = volid; + if (tf) { + tv->vtix = afs_FVIndex; + tv->mtpoint = tf->mtpoint; + tv->dotdot = tf->dotdot; + tv->rootVnode = tf->rootVnode; + tv->rootUnique = tf->rootUnique; + } else { + tv->vtix = -1; + tv->rootVnode = tv->rootUnique = 0; + afs_GetDynrootMountFid(&tv->dotdot); + afs_GetDynrootMountFid(&tv->mtpoint); + tv->mtpoint.Fid.Vnode = + VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2); + tv->mtpoint.Fid.Unique = volid; + } +} + /** * UFS specific version of afs_GetVolSlot * @return @@ -583,7 +618,6 @@ afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell, ReleaseWriteLock(&afs_xvolume); return NULL; } - memset(tv, 0, sizeof(struct volume)); for (j = fvTable[FVHash(tcell->cellNum, volid)]; j != 0; j = tf->next) { if (afs_FVIndex != j) { @@ -606,32 +640,17 @@ afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell, } afs_FVIndex = j; } - tf = &staticFVolume; - if (tf->cell == tcell->cellNum && tf->volume == volid) - break; + if (j != 0) { /* volume items record 0 is not used */ + tf = &staticFVolume; + if (tf->cell == tcell->cellNum && tf->volume == volid) { + break; + } + } } - tv->cell = tcell->cellNum; - AFS_RWLOCK_INIT(&tv->lock, "volume lock"); + afs_InitVolSlot(tv, tf, volid, tcell); tv->next = afs_volumes[i]; /* thread into list */ afs_volumes[i] = tv; - tv->volume = volid; - - if (tf && (j != 0)) { - tv->vtix = afs_FVIndex; - tv->mtpoint = tf->mtpoint; - tv->dotdot = tf->dotdot; - tv->rootVnode = tf->rootVnode; - tv->rootUnique = tf->rootUnique; - } else { - tv->vtix = -1; - tv->rootVnode = tv->rootUnique = 0; - afs_GetDynrootMountFid(&tv->dotdot); - afs_GetDynrootMountFid(&tv->mtpoint); - tv->mtpoint.Fid.Vnode = - VNUM_FROM_TYPEID(VN_TYPE_MOUNT, tcell->cellIndex << 2); - tv->mtpoint.Fid.Unique = volid; - } } tv->refCount++; tv->states &= ~VRecheck; /* just checked it */