[XFS] kill usesless IHOLD calls in xfs_rename
authorChristoph Hellwig <hch@infradead.org>
Tue, 22 Apr 2008 07:34:12 +0000 (17:34 +1000)
committerLachlan McIlroy <lachlan@redback.melbourne.sgi.com>
Tue, 29 Apr 2008 05:54:24 +0000 (15:54 +1000)
Similar to to the previous patch for remove and rmdir only grab a
reference to inodes when we join them to transaction to balance the
decrement on transaction completion. Everything else it taken care of by
the VFS.

Note that the old case had leaks of inode count when src == target or src
or target == one of the parent inodes, but these cases are fortunately
already rejected by the VFS.

SGI-PV: 976035
SGI-Modid: xfs-linux-melb:xfs-kern:30904a

Signed-off-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>
fs/xfs/xfs_rename.c

index 6a14142..d8063e1 100644 (file)
@@ -137,9 +137,7 @@ xfs_rename(
        int             cancel_flags;
        int             committed;
        xfs_inode_t     *inodes[4];
-       int             target_ip_dropped = 0;  /* dropped target_ip link? */
        int             spaceres;
-       int             target_link_zero = 0;
        int             num_inodes;
 
        xfs_itrace_entry(src_dp);
@@ -174,10 +172,6 @@ xfs_rename(
        xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip,
                                inodes, &num_inodes);
 
-       IHOLD(src_ip);
-       if (target_ip)
-               IHOLD(target_ip);
-
        XFS_BMAP_INIT(&free_list, &first_block);
        tp = xfs_trans_alloc(mp, XFS_TRANS_RENAME);
        cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
@@ -191,7 +185,7 @@ xfs_rename(
        }
        if (error) {
                xfs_trans_cancel(tp, 0);
-               goto rele_return;
+               goto std_return;
        }
 
        /*
@@ -199,7 +193,7 @@ xfs_rename(
         */
        if ((error = XFS_QM_DQVOPRENAME(mp, inodes))) {
                xfs_trans_cancel(tp, cancel_flags);
-               goto rele_return;
+               goto std_return;
        }
 
        /*
@@ -220,7 +214,7 @@ xfs_rename(
                error = XFS_ERROR(EXDEV);
                xfs_rename_unlock4(inodes, XFS_ILOCK_SHARED);
                xfs_trans_cancel(tp, cancel_flags);
-               goto rele_return;
+               goto std_return;
        }
 
        /*
@@ -233,17 +227,17 @@ xfs_rename(
         */
        IHOLD(src_dp);
        xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL);
+
        if (new_parent) {
                IHOLD(target_dp);
                xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL);
        }
-       if ((src_ip != src_dp) && (src_ip != target_dp)) {
-               xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL);
-       }
-       if ((target_ip != NULL) &&
-           (target_ip != src_ip) &&
-           (target_ip != src_dp) &&
-           (target_ip != target_dp)) {
+
+       IHOLD(src_ip);
+       xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL);
+
+       if (target_ip) {
+               IHOLD(target_ip);
                xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL);
        }
 
@@ -317,7 +311,6 @@ xfs_rename(
                error = xfs_droplink(tp, target_ip);
                if (error)
                        goto abort_return;
-               target_ip_dropped = 1;
 
                if (src_is_directory) {
                        /*
@@ -327,10 +320,6 @@ xfs_rename(
                        if (error)
                                goto abort_return;
                }
-
-               /* Do this test while we still hold the locks */
-               target_link_zero = (target_ip)->i_d.di_nlink==0;
-
        } /* target_ip != NULL */
 
        /*
@@ -396,15 +385,6 @@ xfs_rename(
                xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE);
        }
 
-       /*
-        * If there was a target inode, take an extra reference on
-        * it here so that it doesn't go to xfs_inactive() from
-        * within the commit.
-        */
-       if (target_ip != NULL) {
-               IHOLD(target_ip);
-       }
-
        /*
         * If this is a synchronous mount, make sure that the
         * rename transaction goes to disk before returning to
@@ -414,30 +394,11 @@ xfs_rename(
                xfs_trans_set_sync(tp);
        }
 
-       /*
-        * Take refs. for vop_link_removed calls below.  No need to worry
-        * about directory refs. because the caller holds them.
-        *
-        * Do holds before the xfs_bmap_finish since it might rele them down
-        * to zero.
-        */
-
-       if (target_ip_dropped)
-               IHOLD(target_ip);
-       IHOLD(src_ip);
-
        error = xfs_bmap_finish(&tp, &free_list, &committed);
        if (error) {
                xfs_bmap_cancel(&free_list);
                xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES |
                                 XFS_TRANS_ABORT));
-               if (target_ip != NULL) {
-                       IRELE(target_ip);
-               }
-               if (target_ip_dropped) {
-                       IRELE(target_ip);
-               }
-               IRELE(src_ip);
                goto std_return;
        }
 
@@ -446,15 +407,6 @@ xfs_rename(
         * the vnode references.
         */
        error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
-       if (target_ip != NULL)
-               IRELE(target_ip);
-       /*
-        * Let interposed file systems know about removed links.
-        */
-       if (target_ip_dropped)
-               IRELE(target_ip);
-
-       IRELE(src_ip);
 
        /* Fall through to std_return with error = 0 or errno from
         * xfs_trans_commit      */
@@ -476,11 +428,4 @@ std_return:
        xfs_bmap_cancel(&free_list);
        xfs_trans_cancel(tp, cancel_flags);
        goto std_return;
-
- rele_return:
-       IRELE(src_ip);
-       if (target_ip != NULL) {
-               IRELE(target_ip);
-       }
-       goto std_return;
 }