namei: Remove redundant linktable SetLinkCount
authorAndrew Deason <adeason@sinenomine.net>
Thu, 29 Aug 2013 20:16:00 +0000 (15:16 -0500)
committerD Brashear <shadow@your-file-system.com>
Mon, 1 Dec 2014 16:53:22 +0000 (11:53 -0500)
If we're setting the linktable linkcount to 0, we're about to delete
the whole linktable. So, don't bother setting the link count. Still
make sure we unlock the linktable, as we still have it locked at this
point, from the previous GetLinkCount call.

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

src/vol/namei_ops.c

index 05d20e9..bae4039 100644 (file)
@@ -70,6 +70,7 @@
 
 int Testing=0;
 
+static void namei_UnlockLinkCount(FdHandle_t * fdP, Inode ino);
 
 afs_sfsize_t
 namei_iread(IHandle_t * h, afs_foff_t offset, char *buf, afs_fsize_t size)
@@ -1162,18 +1163,23 @@ namei_dec(IHandle_t * ih, Inode ino, int p1)
            }
 
            count--;
-           if (namei_SetLinkCount(fdP, (Inode) 0, count < 0 ? 0 : count, 1) <
-               0) {
-               FDH_REALLYCLOSE(fdP);
-               IH_RELEASE(tmp);
-               return -1;
-           }
-
            if (count > 0) {
+               /* if our count is non-zero, we just set our new linkcount and
+                * return. But if our count is 0, don't bother updating the
+                * linktable, since we're about to delete the link table,
+                * below. */
+               if (namei_SetLinkCount(fdP, (Inode) 0, count < 0 ? 0 : count, 1) < 0) {
+                   FDH_REALLYCLOSE(fdP);
+                   IH_RELEASE(tmp);
+                   return -1;
+               }
+
                FDH_CLOSE(fdP);
                IH_RELEASE(tmp);
                return 0;
            }
+
+           namei_UnlockLinkCount(fdP, (Inode) 0);
        }
 
        if ((code = OS_UNLINK(name.n_path)) == 0) {
@@ -1716,6 +1722,17 @@ namei_SetLinkCount(FdHandle_t * fdP, Inode ino, int count, int locked)
     return (int)nBytes;
 }
 
+static void
+namei_UnlockLinkCount(FdHandle_t * fdP, Inode ino)
+{
+    afs_foff_t offset;
+    int index;
+
+    namei_GetLCOffsetAndIndexFromIno(ino, &offset, &index);
+
+    FDH_UNLOCKFILE(fdP, offset);
+}
+
 
 /* ListViceInodes - write inode data to a results file. */
 static int DecodeInode(char *dpath, char *name, struct ViceInodeInfo *info,