[XFS] merge xfs_imap into xfs_dilocate
[safe/jmp/linux-2.6] / fs / xfs / xfs_rename.c
index 6a14142..02f0e8f 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 */
 
        /*
@@ -347,22 +336,18 @@ xfs_rename(
                ASSERT(error != EEXIST);
                if (error)
                        goto abort_return;
-               xfs_ichgtime(src_ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
-
-       } else {
-               /*
-                * We always want to hit the ctime on the source inode.
-                * We do it in the if clause above for the 'new_parent &&
-                * src_is_directory' case, and here we get all the other
-                * cases.  This isn't strictly required by the standards
-                * since the source inode isn't really being changed,
-                * but old unix file systems did it and some incremental
-                * backup programs won't work without it.
-                */
-               xfs_ichgtime(src_ip, XFS_ICHGTIME_CHG);
        }
 
        /*
+        * We always want to hit the ctime on the source inode.
+        *
+        * This isn't strictly required by the standards since the source
+        * inode isn't really being changed, but old unix file systems did
+        * it and some incremental backup programs won't work without it.
+        */
+       xfs_ichgtime(src_ip, XFS_ICHGTIME_CHG);
+
+       /*
         * Adjust the link count on src_dp.  This is necessary when
         * renaming a directory, either within one parent when
         * the target existed, or across two parent directories.
@@ -382,28 +367,11 @@ xfs_rename(
                                        &first_block, &free_list, spaceres);
        if (error)
                goto abort_return;
-       xfs_ichgtime(src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
 
-       /*
-        * Update the generation counts on all the directory inodes
-        * that we're modifying.
-        */
-       src_dp->i_gen++;
+       xfs_ichgtime(src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
        xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE);
-
-       if (new_parent) {
-               target_dp->i_gen++;
+       if (new_parent)
                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
@@ -414,30 +382,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 +395,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 +416,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;
 }