Whamcloud - gitweb
LU-12037 mdt: add option for cross-MDT rename
[fs/lustre-release.git] / lustre / mdt / mdt_reint.c
index b0cc3a2..505b254 100644 (file)
@@ -2139,7 +2139,7 @@ unlock_open_sem:
        if (open_sem_locked)
                up_write(&sobj->mot_open_sem);
 unlock_links:
-       mdt_unlock_list(info, &link_locks, do_sync ?: rc);
+       mdt_unlock_list(info, &link_locks, do_sync ? 1 : rc);
 put_source:
        mdt_object_put(env, sobj);
        mdt_object_put(env, spobj);
@@ -2273,20 +2273,10 @@ static int mdt_rename_determine_lock_order(struct mdt_thread_info *info,
  * 2 - srcdir child; 3 - tgtdir child.
  * Update on disk version of srcdir child.
  */
-/**
- * For DNE phase I, only these renames are allowed
- *     mv src_p/src_c tgt_p/tgt_c
- * 1. src_p/src_c/tgt_p/tgt_c are in the same MDT.
- * 2. src_p and tgt_p are same directory, and tgt_c does not
- *    exists. In this case, all of modification will happen
- *    in the MDT where ithesource parent is, only one remote
- *    update is needed, i.e. set c_time/m_time on the child.
- *    And tgt_c will be still in the same MDT as the original
- *    src_c.
- */
 static int mdt_reint_rename(struct mdt_thread_info *info,
                            struct mdt_lock_handle *unused)
 {
+       struct mdt_device *mdt = info->mti_mdt;
        struct mdt_reint_record *rr = &info->mti_rr;
        struct md_attr *ma = &info->mti_attr;
        struct ptlrpc_request *req = mdt_info_req(info);
@@ -2318,25 +2308,10 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
            !fid_is_md_operative(rr->rr_fid2))
                RETURN(-EPERM);
 
-       /*
-        * Note: do not enqueue rename lock for replay request, because
-        * if other MDT holds rename lock, but being blocked to wait for
-        * this MDT to finish its recovery, and the failover MDT can not
-        * get rename lock, which will cause deadlock.
-        */
-       if (!req_is_replay(req)) {
-               rc = mdt_rename_lock(info, &rename_lh);
-               if (rc != 0) {
-                       CERROR("%s: can't lock FS for rename: rc = %d\n",
-                              mdt_obd_name(info->mti_mdt), rc);
-                       RETURN(rc);
-               }
-       }
-
        /* find both parents. */
        msrcdir = mdt_parent_find_check(info, rr->rr_fid1, 0);
        if (IS_ERR(msrcdir))
-               GOTO(out_unlock_rename, rc = PTR_ERR(msrcdir));
+               RETURN(PTR_ERR(msrcdir));
 
        OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME3, 5);
 
@@ -2349,9 +2324,36 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
                        GOTO(out_put_srcdir, rc = PTR_ERR(mtgtdir));
        }
 
+       /*
+        * Note: do not enqueue rename lock for replay request, because
+        * if other MDT holds rename lock, but being blocked to wait for
+        * this MDT to finish its recovery, and the failover MDT can not
+        * get rename lock, which will cause deadlock.
+        */
+       if (!req_is_replay(req)) {
+               /*
+                * Normally rename RPC is handled on the MDT with the target
+                * directory (if target exists, it's on the MDT with the
+                * target), if the source directory is remote, it's a hint that
+                * source is remote too (this may not be true, but it won't
+                * cause any issue), return -EXDEV early to avoid taking
+                * rename_lock.
+                */
+               if (!mdt->mdt_enable_remote_rename &&
+                   mdt_object_remote(msrcdir))
+                       GOTO(out_put_tgtdir, rc = -EXDEV);
+
+               rc = mdt_rename_lock(info, &rename_lh);
+               if (rc != 0) {
+                       CERROR("%s: can't lock FS for rename: rc = %d\n",
+                              mdt_obd_name(mdt), rc);
+                       GOTO(out_put_tgtdir, rc);
+               }
+       }
+
        rc = mdt_rename_determine_lock_order(info, msrcdir, mtgtdir);
        if (rc < 0)
-               GOTO(out_put_tgtdir, rc);
+               GOTO(out_unlock_rename, rc);
 
        reverse = rc;
 
@@ -2376,7 +2378,7 @@ relock:
                rc = mdt_object_lock_save(info, mtgtdir, lh_tgtdirp, 1,
                                          cos_incompat);
                if (rc)
-                       GOTO(out_put_tgtdir, rc);
+                       GOTO(out_unlock_rename, rc);
 
                OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
 
@@ -2384,20 +2386,21 @@ relock:
                                          cos_incompat);
                if (rc != 0) {
                        mdt_object_unlock(info, mtgtdir, lh_tgtdirp, rc);
-                       GOTO(out_put_tgtdir, rc);
+                       GOTO(out_unlock_rename, rc);
                }
        } else {
                rc = mdt_object_lock_save(info, msrcdir, lh_srcdirp, 0,
                                          cos_incompat);
                if (rc)
-                       GOTO(out_put_tgtdir, rc);
+                       GOTO(out_unlock_rename, rc);
 
                OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_RENAME, 5);
 
                if (mtgtdir != msrcdir) {
                        rc = mdt_object_lock_save(info, mtgtdir, lh_tgtdirp, 1,
                                                  cos_incompat);
-               } else if (lh_srcdirp->mlh_pdo_hash !=
+               } else if (!mdt_object_remote(mtgtdir) &&
+                          lh_srcdirp->mlh_pdo_hash !=
                           lh_tgtdirp->mlh_pdo_hash) {
                        rc = mdt_pdir_hash_lock(info, lh_tgtdirp, mtgtdir,
                                                MDS_INODELOCK_UPDATE,
@@ -2406,7 +2409,7 @@ relock:
                }
                if (rc != 0) {
                        mdt_object_unlock(info, msrcdir, lh_srcdirp, rc);
-                       GOTO(out_put_tgtdir, rc);
+                       GOTO(out_unlock_rename, rc);
                }
        }
 
@@ -2436,6 +2439,9 @@ relock:
                GOTO(out_put_old, rc = -ENOENT);
        }
 
+       if (mdt_object_remote(mold) && !mdt->mdt_enable_remote_rename)
+               GOTO(out_put_old, rc = -EXDEV);
+
        /* Check if @mtgtdir is subdir of @mold, before locking child
         * to avoid reverse locking. */
        if (mtgtdir != msrcdir) {
@@ -2628,13 +2634,13 @@ out_put_old:
 out_unlock_parents:
        mdt_object_unlock(info, mtgtdir, lh_tgtdirp, rc);
        mdt_object_unlock(info, msrcdir, lh_srcdirp, rc);
+out_unlock_rename:
+       if (lustre_handle_is_used(&rename_lh))
+               mdt_rename_unlock(&rename_lh);
 out_put_tgtdir:
        mdt_object_put(info->mti_env, mtgtdir);
 out_put_srcdir:
        mdt_object_put(info->mti_env, msrcdir);
-out_unlock_rename:
-       if (lustre_handle_is_used(&rename_lh))
-               mdt_rename_unlock(&rename_lh);
 
        /* If 'discard' is set then new_fid must exits.
         * DOM data discard need neither object nor lock,