Whamcloud - gitweb
LU-1187 mdt: enqueue rename lock locally for phase I.
authorwangdi <di.wang@whamcloud.com>
Mon, 12 Nov 2012 14:39:25 +0000 (06:39 -0800)
committerOleg Drokin <green@whamcloud.com>
Fri, 18 Jan 2013 16:45:51 +0000 (11:45 -0500)
Because cross-rename is not permitted in phase I, it only
needs to enqueue rename lock locally for phase I.

Change-Id: I954a6c7c5ab914df4b756c6eae4fc0bfddad8e6b
Signed-off-by: wang di <di.wang@intel.com>
Reviewed-on: http://review.whamcloud.com/4355
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
lustre/mdt/mdt_reint.c

index 191801d..f334dd6 100644 (file)
@@ -877,46 +877,35 @@ static int mdt_pdir_hash_lock(struct mdt_thread_info *info,
 static int mdt_rename_lock(struct mdt_thread_info *info,
                            struct lustre_handle *lh)
 {
 static int mdt_rename_lock(struct mdt_thread_info *info,
                            struct lustre_handle *lh)
 {
-        struct ldlm_namespace *ns     = info->mti_mdt->mdt_namespace;
-        ldlm_policy_data_t    *policy = &info->mti_policy;
-        struct ldlm_res_id    *res_id = &info->mti_res_id;
-       __u64                  flags = 0;
-       struct seq_server_site  *ss;
-        int rc;
-        ENTRY;
+       struct ldlm_namespace   *ns = info->mti_mdt->mdt_namespace;
+       ldlm_policy_data_t      *policy = &info->mti_policy;
+       struct ldlm_res_id      *res_id = &info->mti_res_id;
+       __u64                   flags = 0;
+       int rc;
+       ENTRY;
 
 
-       ss = mdt_seq_site(info->mti_mdt);
        fid_build_reg_res_name(&LUSTRE_BFL_FID, res_id);
 
        fid_build_reg_res_name(&LUSTRE_BFL_FID, res_id);
 
-        memset(policy, 0, sizeof *policy);
-        policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
-
-       if (ss->ss_control_exp == NULL) {
-               flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB;
-
-                /*
-                 * Current node is controller, that is mdt0, where we should
-                 * take BFL lock.
-                 */
-                rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy,
-                                            LCK_EX, &flags, ldlm_blocking_ast,
-                                            ldlm_completion_ast, NULL, NULL, 0,
-                                           LVB_T_NONE,
-                                           &info->mti_exp->exp_handle.h_cookie,
-                                            lh);
-        } else {
-                struct ldlm_enqueue_info einfo = { LDLM_IBITS, LCK_EX,
-                     ldlm_blocking_ast, ldlm_completion_ast, NULL, NULL, NULL };
-
-               /*
-                * This is the case mdt0 is remote node, issue DLM lock like
-                * other clients.
-                */
-               rc = ldlm_cli_enqueue(ss->ss_control_exp, NULL, &einfo, res_id,
-                                     policy, &flags, NULL, 0, LVB_T_NONE, lh,
-                                     0);
-        }
-
+       memset(policy, 0, sizeof *policy);
+       policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 4, 53, 0)
+       /* In phase I, we will not do cross-rename, so local BFL lock would
+        * be enough
+        */
+       flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB;
+       /*
+        * Current node is controller, that is mdt0, where we should
+        * take BFL lock.
+        */
+       rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy,
+                                   LCK_EX, &flags, ldlm_blocking_ast,
+                                   ldlm_completion_ast, NULL, NULL, 0,
+                                   LVB_T_NONE,
+                                   &info->mti_exp->exp_handle.h_cookie,
+                                   lh);
+#else
+#warning "Local rename lock is invalid for DNE phase II."
+#endif
         RETURN(rc);
 }
 
         RETURN(rc);
 }
 
@@ -998,11 +987,13 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
                   PFID(rr->rr_fid1), rr->rr_name,
                   PFID(rr->rr_fid2), rr->rr_tgt);
 
                   PFID(rr->rr_fid1), rr->rr_name,
                   PFID(rr->rr_fid2), rr->rr_tgt);
 
-        rc = mdt_rename_lock(info, &rename_lh);
-        if (rc) {
-                CERROR("Can't lock FS for rename, rc %d\n", rc);
-                RETURN(rc);
-        }
+       if (!lu_fid_eq(rr->rr_fid1, rr->rr_fid2)) {
+               rc = mdt_rename_lock(info, &rename_lh);
+               if (rc) {
+                       CERROR("Can't lock FS for rename, rc %d\n", rc);
+                       RETURN(rc);
+               }
+       }
 
         lh_newp = &info->mti_lh[MDT_LH_NEW];
 
 
         lh_newp = &info->mti_lh[MDT_LH_NEW];
 
@@ -1179,8 +1170,9 @@ out_put_target:
 out_unlock_source:
         mdt_object_unlock_put(info, msrcdir, lh_srcdirp, rc);
 out_rename_lock:
 out_unlock_source:
         mdt_object_unlock_put(info, msrcdir, lh_srcdirp, rc);
 out_rename_lock:
-        mdt_rename_unlock(&rename_lh);
-        return rc;
+       if (lustre_handle_is_used(&rename_lh))
+               mdt_rename_unlock(&rename_lh);
+       return rc;
 }
 
 typedef int (*mdt_reinter)(struct mdt_thread_info *info,
 }
 
 typedef int (*mdt_reinter)(struct mdt_thread_info *info,