]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Remove the global tempHeader/stuff structures
authorAndrew Deason <adeason@sinenomine.net>
Thu, 22 Apr 2010 22:09:18 +0000 (17:09 -0500)
committerStephan Wiesand <stephan.wiesand@desy.de>
Wed, 11 Sep 2013 21:21:47 +0000 (14:21 -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.

Reviewed-on: http://gerrit.openafs.org/1869
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
(cherry picked from commit d8f2debce49a8a0eb310bdaf8ad0ee7601a0542e)

Change-Id: I1567e9184327b1cfa397b0bf37d611c2e8c2b8a1
Reviewed-on: http://gerrit.openafs.org/9409
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Reviewed-by: Stephan Wiesand <stephan.wiesand@desy.de>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
src/vol/vol-salvage.c
src/vol/vol-salvage.h
src/vol/volinodes.h
src/vol/vutil.c

index 8cd5e9cb2c977496abdc240a78d89a176227722d..bfd18fb5f3f5eae796e331c0d50384a2839d5544 100644 (file)
@@ -2161,6 +2161,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
@@ -2186,6 +2188,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
@@ -2397,7 +2401,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 1f7c44350629f7d0e13238fab4ad21faec4754b1..f0efef42f7165553bd7b82c9915912905d68d13f 100644 (file)
@@ -233,7 +233,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 4b7f5f5298e974d58745d3a719e73489555633cf..181b441d986450aef15cb2c93cd83a5f091f29b2 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 7b2cd8b23e82780ab229d78c8009dc801f5b46c8..8e2a7002adaa8b2435ad6dcdd1accc2aa0e8e32d 100644 (file)
@@ -71,7 +71,6 @@
 #define afs_open       open
 #endif /* !O_LARGEFILE */
 
-#define nFILES (sizeof (stuff)/sizeof(struct stuff))
 
 #ifndef AFS_NT40_ENV
 # ifdef O_LARGEFILE
@@ -91,7 +90,8 @@
 
 #ifdef FSSYNC_BUILD_CLIENT
 static void
-RemoveInodes(Device dev, VolumeId parent, VolumeId vid)
+RemoveInodes(struct afs_inode_info *stuff, Device dev, VolumeId parent,
+             VolumeId vid)
 {
     int i;
     IHandle_t *handle;
@@ -100,7 +100,7 @@ RemoveInodes(Device dev, VolumeId parent, VolumeId vid)
      * needs the dev and vid to decrement volume special files.
      */
     IH_INIT(handle, dev, parent, -1);
-    for (i = 0; i < nFILES; i++) {
+    for (i = 0; i < MAXINODETYPE; i++) {
        Inode inode = *stuff[i].inode;
        if (VALID_INO(inode)) {
            if (stuff[i].inodeType == VI_LINKTABLE) {
@@ -140,10 +140,14 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId)
     char *part, *name;
     struct stat st;
     afs_ino_str_t stmp;
+    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;
@@ -220,8 +224,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
@@ -261,7 +265,7 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId)
          bad:
            if (handle)
                IH_RELEASE(handle);
-           RemoveInodes(device, vol.parentId, vol.id);
+           RemoveInodes(stuff, device, vol.parentId, vol.id);
            if (!*ec) {
                *ec = VNOVOL;
            }