vol: Fix VCreateVolume special inode cleanup
[openafs.git] / src / vol / vutil.c
index b918389..80bbf97 100644 (file)
 
 #include <roken.h>
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <errno.h>
-#ifdef AFS_NT40_ENV
-#include <time.h>
-#include <fcntl.h>
-#else
-#include <sys/time.h>
+#ifdef HAVE_SYS_FILE_H
 #include <sys/file.h>
-#include <unistd.h>
 #endif
-#include <dirent.h>
-#include <sys/stat.h>
-#include <afs/afs_assert.h>
+
+#ifdef HAVE_SYS_LOCKF_H
+#include <sys/lockf.h>
+#endif
 
 #include <rx/xdr.h>
 #include <afs/afsint.h>
@@ -45,7 +38,6 @@
 #include <afs/afsutil.h>
 #ifdef AFS_NT40_ENV
 #include "ntops.h"
-#include <io.h>
 #endif
 #include "vnode.h"
 #include "volume.h"
 #include "vol_prototypes.h"
 #include "common.h"
 
-#ifdef AFS_AIX_ENV
-#include <sys/lockf.h>
-#endif
-#if defined(AFS_SUN5_ENV) || defined(AFS_NT40_ENV) || defined(AFS_LINUX20_ENV)
-#include <string.h>
-#else
-#include <strings.h>
-#endif
-
 #ifndef AFS_NT40_ENV
 # ifdef O_LARGEFILE
 #  define AFS_SETLKW   F_SETLKW64
@@ -84,7 +67,8 @@
 
 #ifdef FSSYNC_BUILD_CLIENT
 static void
-RemoveInodes(struct afs_inode_info *stuff, Device dev, VolumeId vid)
+RemoveInodes(struct afs_inode_info *stuff, Device dev, VolumeId parent,
+             VolumeId vid)
 {
     int i;
     IHandle_t *handle;
@@ -92,11 +76,16 @@ RemoveInodes(struct afs_inode_info *stuff, Device dev, VolumeId vid)
     /* This relies on the fact that IDEC only needs the device and NT only
      * needs the dev and vid to decrement volume special files.
      */
-    IH_INIT(handle, dev, vid, -1);
+    IH_INIT(handle, dev, parent, -1);
     for (i = 0; i < MAXINODETYPE; i++) {
        Inode inode = *stuff[i].inode;
-       if (VALID_INO(inode))
-           IH_DEC(handle, inode, vid);
+       if (VALID_INO(inode)) {
+           if (stuff[i].inodeType == VI_LINKTABLE) {
+               IH_DEC(handle, inode, parent);
+           } else {
+               IH_DEC(handle, inode, vid);
+           }
+       }
     }
     IH_RELEASE(handle);
 }
@@ -124,7 +113,7 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId)
     struct VolumeDiskHeader diskHeader;
     IHandle_t *handle;
     FdHandle_t *fdP;
-    Inode nearInode = 0;
+    Inode nearInode AFS_UNUSED = 0;
     char *part, *name;
     struct stat st;
     struct VolumeHeader tempHeader;
@@ -254,7 +243,7 @@ VCreateVolume_r(Error * ec, char *partname, VolId volumeId, VolId parentId)
          bad:
            if (handle)
                IH_RELEASE(handle);
-           RemoveInodes(stuff, device, vol.id);
+           RemoveInodes(stuff, device, vol.parentId, vol.id);
            if (!*ec) {
                *ec = VNOVOL;
            }