libafs: afs_SetupVolSlot function
authorMichael Meffie <mmeffie@sinenomine.net>
Sat, 8 Mar 2014 19:30:27 +0000 (14:30 -0500)
committerD Brashear <shadow@your-file-system.com>
Tue, 25 Mar 2014 16:49:18 +0000 (09:49 -0700)
Move the code block to get and setup volume slots out of
afs_SetupVolume to a new local function called afs_SetupVolSlot.
This new function acquires the afs_xvolume lock and releases it
before returning.

Change-Id: I1bd33f13e0525f9ff050d7e161cf29a511e5c4b8
Reviewed-on: http://gerrit.openafs.org/10879
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: D Brashear <shadow@your-file-system.com>

src/afs/afs_stats.h
src/afs/afs_volume.c

index 687244b..9a96b41 100644 (file)
@@ -658,7 +658,8 @@ struct afs_MeanStats {
     AFS_CS(PSetTokens2)                /* afs_pioctl.c */ \
     AFS_CS(PPrefetchFromTape)   /* afs_pioctl.c */ \
     AFS_CS(PFlushAllVolumeData)        /* afs_pioctl.c */ \
-    AFS_CS(afs_InitVolSlot)     /* afs_volume.c */
+    AFS_CS(afs_InitVolSlot)     /* afs_volume.c */ \
+    AFS_CS(afs_SetupVolSlot)    /* afs_volume.c */
 
 struct afs_CMCallStats {
 #define AFS_CS(call) afs_int32 C_ ## call;
index 92b6e17..827ff12 100644 (file)
@@ -325,6 +325,46 @@ afs_MemGetVolSlot(afs_int32 volid, struct cell *tcell)
 }                              /*afs_MemGetVolSlot */
 
 /*!
+ * Setup a volume slot for cell:volume.
+ *
+ * Find the volume slot for the cell:volume, otherwise get
+ * and initialize a new slot.
+ *
+ * \param volid volume id
+ * \param cell  cell
+ * \return volume
+ */
+static struct volume *
+afs_SetupVolSlot(afs_int32 volid, struct cell *tcell)
+{
+    struct volume *tv;
+    int i;
+
+    AFS_STATCNT(afs_SetupVolSlot);
+    ObtainWriteLock(&afs_xvolume, 108);
+    i = VHash(volid);
+    for (tv = afs_volumes[i]; tv; tv = tv->next) {
+       if (tv->volume == volid && tv->cell == tcell->cellNum) {
+           break;
+       }
+    }
+    if (!tv) {
+       tv = afs_GetVolSlot(volid, tcell);
+       if (!tv) {
+           ReleaseWriteLock(&afs_xvolume);
+           return NULL;
+       }
+       tv->next = afs_volumes[i];      /* thread into list */
+       afs_volumes[i] = tv;
+    }
+    tv->refCount++;
+    tv->states &= ~VRecheck;   /* just checked it */
+    tv->accessTime = osi_Time();
+    ReleaseWriteLock(&afs_xvolume);
+    return tv;
+}
+
+/*!
  * Reset volume information for all volume structs that
  * point to a speicific server, skipping a given volume if provided.
  *
@@ -636,27 +676,11 @@ afs_SetupVolume(afs_int32 volid, char *aname, void *ve, struct cell *tcell,
        } /* end of if (volid == 0) */
     } /* end of if (!volid) */
 
-
-    ObtainWriteLock(&afs_xvolume, 108);
-    i = VHash(volid);
-    for (tv = afs_volumes[i]; tv; tv = tv->next) {
-       if (tv->volume == volid && tv->cell == tcell->cellNum) {
-           break;
-       }
-    }
+    tv = afs_SetupVolSlot(volid, tcell);
     if (!tv) {
-       tv = afs_GetVolSlot(volid, tcell);
-       if (!tv) {
-           ReleaseWriteLock(&afs_xvolume);
-           return NULL;
-       }
-       tv->next = afs_volumes[i];      /* thread into list */
-       afs_volumes[i] = tv;
+       return NULL;
     }
-    tv->refCount++;
-    tv->states &= ~VRecheck;   /* just checked it */
-    tv->accessTime = osi_Time();
-    ReleaseWriteLock(&afs_xvolume);
+
     if (type == 2) {
        LockAndInstallUVolumeEntry(tv, uve, tcell->cellNum, tcell, areq);
     } else if (type == 1)