namei: Remove redundant linktable SetLinkCount
[openafs.git] / 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,