Remove the global tempHeader/stuff structures
authorAndrew Deason <adeason@sinenomine.net>
Thu, 22 Apr 2010 22:09:18 +0000 (17:09 -0500)
committerDerrick Brashear <shadow@dementia.org>
Thu, 19 Aug 2010 06:59:18 +0000 (23:59 -0700)
Currently, volinodes.h defines an array ('stuff') for easily accessing
information about different inode types. Part of the array points to
parts of a global 'tempHeader' structure, making this not threadsafe.
Change this into an interface which utilizes local storage to make
this threadsafe and remove those horridly-named global variables.

This adds the init_inode_info static inline function, for initializing
a local inode information table.

Change-Id: If4562e724fd7a8e5f8166ea0fe409d6765d0de2b
Reviewed-on: http://gerrit.openafs.org/1869
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/vol/vol-salvage.c
src/vol/vol-salvage.h
src/vol/volinodes.h
src/vol/vutil.c

index e07c90c..b34bc00 100644 (file)
@@ -2097,6 +2097,8 @@ SalvageVolumeHeaderFile(struct SalvInfo *salvinfo, struct InodeSummary *isp,
     struct VolumeDiskHeader diskHeader;
     afs_int32 (*writefunc)(VolumeDiskHeader_t *, struct DiskPartition64 *) = NULL;
     int *skip;
+    struct VolumeHeader tempHeader;
+    struct afs_inode_info stuff[MAXINODETYPE];
 
     /* keeps track of special inodes that are probably 'good'; they are
      * referenced in the vol header, and are included in the given inodes
@@ -2122,6 +2124,8 @@ SalvageVolumeHeaderFile(struct SalvInfo *salvinfo, struct InodeSummary *isp,
         * if we detect duplicate special inodes */
     }
 
+    init_inode_info(&tempHeader, stuff);
+
     /*
      * First, look at the special inodes and see if any are referenced by
      * the existing volume header. If we find duplicate special inodes, we
@@ -2333,7 +2337,7 @@ SalvageVolumeHeaderFile(struct SalvInfo *salvinfo, struct InodeSummary *isp,
 }
 
 int
-SalvageHeader(struct SalvInfo *salvinfo, struct stuff *sp,
+SalvageHeader(struct SalvInfo *salvinfo, struct afs_inode_info *sp,
               struct InodeSummary *isp, int check, int *deleteMe)
 {
     union {
index 36ac93f..9984ee2 100644 (file)
@@ -231,7 +231,7 @@ extern void SalvageFileSysParallel(struct DiskPartition64 *partP);
 extern void SalvageFileSys(struct DiskPartition64 *partP, VolumeId singleVolumeNumber);
 extern void SalvageFileSys1(struct DiskPartition64 *partP,
                            VolumeId singleVolumeNumber);
-extern int SalvageHeader(struct SalvInfo *salvinfo, struct stuff *sp,
+extern int SalvageHeader(struct SalvInfo *salvinfo, struct afs_inode_info *sp,
                         struct InodeSummary *isp, int check, int *deleteMe);
 extern int SalvageIndex(struct SalvInfo *salvinfo, Inode ino, VnodeClass class,
                         int RW, struct ViceInodeInfo *ip, int nInodes,
index 4b7f5f5..181b441 100644 (file)
 #ifndef __volinodes_h_
 #define __volinodes_h_
 
-/* Used by vutil.c and salvager.c */
+#include <stddef.h>
 
-private struct VolumeHeader tempHeader;
+/* Used by vutil.c and salvager.c */
 
 #ifdef AFS_NAMEI_ENV
 #define NO_LINK_TABLE 0
 #else
 #define NO_LINK_TABLE 1
 #endif
-AFS_UNUSED
-private struct stuff {
+
+#define MAXINODETYPE VI_LINKTABLE
+static struct afs_inode_info {
     struct versionStamp stamp;
     bit32 inodeType;
     int size;                  /* size of any fixed size portion of the header */
@@ -37,26 +38,76 @@ private struct stuff {
      * salvager may delete it, and shouldn't complain
      * if it isn't there; create can not bother to create it */
     int obsolete;
-} stuff[] = {
-    { {
-    VOLUMEINFOMAGIC, VOLUMEINFOVERSION}, VI_VOLINFO, sizeof(VolumeDiskData),
-       &tempHeader.volumeInfo, "Volume information", 0}
-    , { {
-    SMALLINDEXMAGIC, SMALLINDEXVERSION}
-    , VI_SMALLINDEX, sizeof(struct versionStamp), &tempHeader.smallVnodeIndex,
-       "small inode index", 0}, { {
-    LARGEINDEXMAGIC, LARGEINDEXVERSION}, VI_LARGEINDEX,
-       sizeof(struct versionStamp), &tempHeader.largeVnodeIndex,
-       "large inode index", 0}, { {
-    ACLMAGIC, ACLVERSION}, VI_ACL, sizeof(struct versionStamp),
-       &tempHeader.volumeAcl, "access control list", 1}, { {
-    MOUNTMAGIC, MOUNTVERSION}, VI_MOUNTTABLE, sizeof(struct versionStamp),
-       &tempHeader.volumeMountTable, "mount table", 1}, { {
-LINKTABLEMAGIC, LINKTABLEVERSION}, VI_LINKTABLE,
-       sizeof(struct versionStamp), &tempHeader.linkTable, "link table",
-       NO_LINK_TABLE},};
+} afs_common_inode_info[MAXINODETYPE] = {
+    {
+       {VOLUMEINFOMAGIC, VOLUMEINFOVERSION},
+       VI_VOLINFO,
+       sizeof(VolumeDiskData),
+       (Inode*)offsetof(struct VolumeHeader, volumeInfo),
+       "Volume information",
+       0
+    },
+    {
+       {SMALLINDEXMAGIC, SMALLINDEXVERSION},
+       VI_SMALLINDEX,
+       sizeof(struct versionStamp),
+       (Inode*)offsetof(struct VolumeHeader, smallVnodeIndex),
+       "small inode index",
+       0
+    },
+    {
+       {LARGEINDEXMAGIC, LARGEINDEXVERSION},
+       VI_LARGEINDEX,
+       sizeof(struct versionStamp),
+       (Inode*)offsetof(struct VolumeHeader, largeVnodeIndex),
+       "large inode index",
+       0
+    },
+    {
+       {ACLMAGIC, ACLVERSION},
+       VI_ACL,
+       sizeof(struct versionStamp),
+       (Inode*)offsetof(struct VolumeHeader, volumeAcl),
+       "access control list",
+       1
+    },
+    {
+       {MOUNTMAGIC, MOUNTVERSION},
+       VI_MOUNTTABLE,
+       sizeof(struct versionStamp),
+       (Inode*)offsetof(struct VolumeHeader, volumeMountTable),
+       "mount table",
+       1
+    },
+    {
+       {LINKTABLEMAGIC, LINKTABLEVERSION},
+       VI_LINKTABLE,
+       sizeof(struct versionStamp),
+       (Inode*)offsetof(struct VolumeHeader, linkTable),
+       "link table",
+       NO_LINK_TABLE
+    },
+};
 /* inodeType is redundant in the above table;  it used to be useful, but now
    we require the table to be ordered */
-#define MAXINODETYPE VI_LINKTABLE
+
+/**
+ * initialize a struct afs_inode_info
+ *
+ * @param[in] header  the volume header struct to use when referencing volume
+ *                    header fields in 'stuff'
+ * @param[out] stuff  the struct afs_inode_info to initialize
+ *
+ */
+static_inline void
+init_inode_info(struct VolumeHeader *header,
+                struct afs_inode_info *stuff)
+{
+    int i;
+    memcpy(stuff, afs_common_inode_info, sizeof(afs_common_inode_info));
+    for (i = 0; i < MAXINODETYPE; i++) {
+       stuff[i].inode = (Inode*)((char*)header + (uintptr_t)stuff[i].inode);
+    }
+}
 
 #endif /* __volinodes_h_ */
index c53ea0e..d9c3246 100644 (file)
@@ -75,7 +75,6 @@
 #define afs_open       open
 #endif /* !O_LARGEFILE */
 
-#define nFILES (sizeof (stuff)/sizeof(struct stuff))
 
 /* Note:  the volume creation functions herein leave the destroyMe flag in the
    volume header ON:  this means that the volumes will not be attached by the
@@ -83,7 +82,7 @@
 
 #ifdef FSSYNC_BUILD_CLIENT
 static void
-RemoveInodes(Device dev, VolumeId vid)
+RemoveInodes(struct afs_inode_info *stuff, Device dev, VolumeId vid)
 {
     int i;
     IHandle_t *handle;
@@ -92,7 +91,7 @@ RemoveInodes(Device dev, VolumeId vid)
      * needs the dev and vid to decrement volume special files.
      */
     IH_INIT(handle, dev, vid, -1);
-    for (i = 0; i < nFILES; i++) {
+    for (i = 0; i < MAXINODETYPE; i++) {
        Inode inode = *stuff[i].inode;
        if (VALID_INO(inode))
            IH_DEC(handle, inode, vid);
@@ -126,10 +125,14 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId)
     Inode nearInode = 0;
     char *part, *name;
     struct stat st;
+    struct VolumeHeader tempHeader;
+    struct afs_inode_info stuff[MAXINODETYPE];
 # ifdef AFS_DEMAND_ATTACH_FS
     int locktype = 0;
 # endif /* AFS_DEMAND_ATTACH_FS */
 
+    init_inode_info(&tempHeader, stuff);
+
     *ec = 0;
     memset(&vol, 0, sizeof(vol));
     vol.id = volumeId;
@@ -206,8 +209,8 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId)
     }
     device = partition->device;
 
-    for (i = 0; i < nFILES; i++) {
-       struct stuff *p = &stuff[i];
+    for (i = 0; i < MAXINODETYPE; i++) {
+       struct afs_inode_info *p = &stuff[i];
        if (p->obsolete)
            continue;
 #ifdef AFS_NAMEI_ENV
@@ -251,7 +254,7 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId)
          bad:
            if (handle)
                IH_RELEASE(handle);
-           RemoveInodes(device, vol.id);
+           RemoveInodes(stuff, device, vol.id);
            if (!*ec) {
                *ec = VNOVOL;
            }