Whamcloud - gitweb
b=16721 fix rename pdif lock, when source and target in the same directory.
[fs/lustre-release.git] / lustre / mdt / mdt_reint.c
index 51f87c2..60dbfc2 100644 (file)
@@ -80,7 +80,8 @@ static int mdt_create_pack_capa(struct mdt_thread_info *info, int rc,
         if (repbody->valid & OBD_MD_FLMDSCAPA)
                 RETURN(rc);
 
-        if (rc == 0 && info->mti_mdt->mdt_opts.mo_mds_capa) {
+        if (rc == 0 && info->mti_mdt->mdt_opts.mo_mds_capa &&
+            info->mti_exp->exp_connect_flags & OBD_CONNECT_MDS_CAPA) {
                 struct lustre_capa *capa;
 
                 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA1);
@@ -95,6 +96,52 @@ static int mdt_create_pack_capa(struct mdt_thread_info *info, int rc,
         RETURN(rc);
 }
 
+int mdt_version_get_check(struct mdt_thread_info *info, int index)
+{
+        /** version recovery */
+        struct md_object *mo;
+        struct ptlrpc_request *req = mdt_info_req(info);
+        __u64 curr_version, *pre_versions;
+        ENTRY;
+
+        if (!exp_connect_vbr(req->rq_export))
+                RETURN(0);
+
+        LASSERT(info->mti_mos[index]);
+        if (mdt_object_exists(info->mti_mos[index]) == 0)
+                RETURN(-ESTALE);
+        mo = mdt_object_child(info->mti_mos[index]);
+
+        curr_version = mo_version_get(info->mti_env, mo);
+        CDEBUG(D_INODE, "Version is "LPX64"\n", curr_version);
+        /** VBR: version is checked always because costs nothing */
+        if (lustre_msg_get_transno(req->rq_reqmsg) != 0) {
+                pre_versions = lustre_msg_get_versions(req->rq_reqmsg);
+                LASSERT(index < PTLRPC_NUM_VERSIONS);
+                /** Sanity check for malformed buffers */
+                if (pre_versions == NULL) {
+                        CERROR("No versions in request buffer\n");
+                        cfs_spin_lock(&req->rq_export->exp_lock);
+                        req->rq_export->exp_vbr_failed = 1;
+                        cfs_spin_unlock(&req->rq_export->exp_lock);
+                        RETURN(-EOVERFLOW);
+                } else if (pre_versions[index] != curr_version) {
+                        CDEBUG(D_INODE, "Version mismatch "LPX64" != "LPX64"\n",
+                               pre_versions[index], curr_version);
+                        cfs_spin_lock(&req->rq_export->exp_lock);
+                        req->rq_export->exp_vbr_failed = 1;
+                        cfs_spin_unlock(&req->rq_export->exp_lock);
+                        RETURN(-EOVERFLOW);
+                }
+        }
+        /** save pre-versions in reply */
+        LASSERT(req->rq_repmsg != NULL);
+        pre_versions = lustre_msg_get_versions(req->rq_repmsg);
+        if (pre_versions)
+                pre_versions[index] = curr_version;
+        RETURN(0);
+}
+
 static int mdt_md_create(struct mdt_thread_info *info)
 {
         struct mdt_device       *mdt = info->mti_mdt;
@@ -135,6 +182,12 @@ static int mdt_md_create(struct mdt_thread_info *info)
                 mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
                                OBD_FAIL_MDS_REINT_CREATE_WRITE);
 
+                info->mti_mos[0] = parent;
+                info->mti_mos[1] = child;
+                rc = mdt_version_get_check(info, 0);
+                if (rc)
+                        GOTO(out_put_child, rc);
+
                 /* Let lower layer know current lock mode. */
                 info->mti_spec.sp_cr_mode =
                         mdt_dlm_mode2mdl_mode(lh->mlh_pdo_mode);
@@ -144,6 +197,7 @@ static int mdt_md_create(struct mdt_thread_info *info)
                  * or not.
                  */
                 info->mti_spec.sp_cr_lookup = 1;
+                info->mti_spec.sp_feat = &dt_directory_features;
 
                 lname = mdt_name(info->mti_env, (char *)rr->rr_name,
                                  rr->rr_namelen);
@@ -156,6 +210,7 @@ static int mdt_md_create(struct mdt_thread_info *info)
                                 mdt_pack_attr2body(info, repbody, &ma->ma_attr,
                                                    mdt_object_fid(child));
                 }
+out_put_child:
                 mdt_object_put(info->mti_env, child);
         } else
                 rc = PTR_ERR(child);
@@ -220,25 +275,17 @@ static int mdt_md_mkobj(struct mdt_thread_info *info)
  *               the client holds a lock already.
  * We use the ATTR_FROM_OPEN (translated into MRF_SETATTR_LOCKED by
  * mdt_setattr_unpack()) flag to tell these cases apart. */
-int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo, int flags)
+int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo,
+                 struct md_attr *ma, int flags)
 {
-        struct md_attr          *ma = &info->mti_attr;
         struct mdt_lock_handle  *lh;
-        int som_update = 0;
+        int do_vbr = ma->ma_attr.la_valid & (LA_MODE|LA_UID|LA_GID|LA_FLAGS);
         int rc;
         ENTRY;
 
         /* attr shouldn't be set on remote object */
         LASSERT(mdt_object_exists(mo) >= 0);
 
-        if (info->mti_epoch)
-                som_update = (info->mti_epoch->flags & MF_SOM_CHANGE);
-
-        /* Try to avoid object_lock if another epoch has been started
-         * already. */
-        if (som_update && (info->mti_epoch->ioepoch != mo->mot_ioepoch))
-                RETURN(0);
-
         lh = &info->mti_lh[MDT_LH_PARENT];
         mdt_lock_reg_init(lh, LCK_PW);
 
@@ -252,12 +299,6 @@ int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo, int flags)
                         RETURN(rc);
         }
 
-        /* Setattrs are syncronized through dlm lock taken above. If another
-         * epoch started, its attributes may be already flushed on disk,
-         * skip setattr. */
-        if (som_update && (info->mti_epoch->ioepoch != mo->mot_ioepoch))
-                GOTO(out_unlock, rc = 0);
-
         if (mdt_object_exists(mo) == 0)
                 GOTO(out_unlock, rc = -ENOENT);
 
@@ -269,19 +310,19 @@ int mdt_attr_set(struct mdt_thread_info *info, struct mdt_object *mo, int flags)
         if (unlikely(ma->ma_attr.la_valid == LA_CTIME))
                 ma->ma_attr_flags |= MDS_VTX_BYPASS;
 
+        /* VBR: update version if attr changed are important for recovery */
+        if (do_vbr) {
+                info->mti_mos[0] = mo;
+                rc = mdt_version_get_check(info, 0);
+                if (rc)
+                        GOTO(out_unlock, rc);
+        }
+
         /* all attrs are packed into mti_attr in unpack_setattr */
         rc = mo_attr_set(info->mti_env, mdt_object_child(mo), ma);
         if (rc != 0)
                 GOTO(out_unlock, rc);
 
-        /* Re-enable SIZEONMDS. */
-        if (som_update) {
-                CDEBUG(D_INODE, "Closing epoch "LPU64" on "DFID". Count %d\n",
-                       mo->mot_ioepoch, PFID(mdt_object_fid(mo)),
-                       mo->mot_epochcount);
-                mdt_sizeonmds_enable(info, mo);
-        }
-
         EXIT;
 out_unlock:
         mdt_object_unlock(info, mo, lh, rc);
@@ -291,7 +332,6 @@ out_unlock:
 static int mdt_reint_setattr(struct mdt_thread_info *info,
                              struct mdt_lock_handle *lhc)
 {
-        struct mdt_device       *mdt = info->mti_mdt;
         struct md_attr          *ma = &info->mti_attr;
         struct mdt_reint_record *rr = &info->mti_rr;
         struct ptlrpc_request   *req = mdt_info_req(info);
@@ -300,7 +340,7 @@ static int mdt_reint_setattr(struct mdt_thread_info *info,
         struct mdt_object       *mo;
         struct md_object        *next;
         struct mdt_body         *repbody;
-        int                      rc;
+        int                      som_au, rc;
         ENTRY;
 
         DEBUG_REQ(D_INODE, req, "setattr "DFID" %x", PFID(rr->rr_fid1),
@@ -308,74 +348,84 @@ static int mdt_reint_setattr(struct mdt_thread_info *info,
 
         if (info->mti_dlm_req)
                 ldlm_request_cancel(req, info->mti_dlm_req, 0);
-        
+
         repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
         mo = mdt_object_find(info->mti_env, info->mti_mdt, rr->rr_fid1);
         if (IS_ERR(mo))
                 GOTO(out, rc = PTR_ERR(mo));
 
+        /* start a log jounal handle if needed */
         if (!(mdt_conn_flags(info) & OBD_CONNECT_SOM)) {
                 if ((ma->ma_attr.la_valid & LA_SIZE) ||
                     (rr->rr_flags & MRF_SETATTR_LOCKED)) {
                         /* Check write access for the O_TRUNC case */
-                        if (mdt_write_read(info->mti_mdt, mo) < 0)
+                        if (mdt_write_read(mo) < 0)
                                 GOTO(out_put, rc = -ETXTBSY);
                 }
-        } else if (info->mti_epoch &&
-                    (info->mti_epoch->flags & MF_EPOCH_OPEN)) {
-                /* Truncate case. */
-                rc = mdt_write_get(info->mti_mdt, mo);
+        } else if (info->mti_ioepoch &&
+                   (info->mti_ioepoch->flags & MF_EPOCH_OPEN)) {
+                /* Truncate case. IOEpoch is opened. */
+                rc = mdt_write_get(mo);
                 if (rc)
                         GOTO(out_put, rc);
 
                 mfd = mdt_mfd_new();
-                if (mfd == NULL)
+                if (mfd == NULL) {
+                        mdt_write_put(mo);
                         GOTO(out_put, rc = -ENOMEM);
+                }
 
-                mdt_epoch_open(info, mo);
+                mdt_ioepoch_open(info, mo, 0);
                 repbody->ioepoch = mo->mot_ioepoch;
 
                 mdt_object_get(info->mti_env, mo);
-                mdt_mfd_set_mode(mfd, FMODE_EPOCHLCK);
+                mdt_mfd_set_mode(mfd, FMODE_TRUNC);
                 mfd->mfd_object = mo;
                 mfd->mfd_xid = req->rq_xid;
 
-                spin_lock(&med->med_open_lock);
-                list_add(&mfd->mfd_list, &med->med_open_head);
-                spin_unlock(&med->med_open_lock);
+                cfs_spin_lock(&med->med_open_lock);
+                cfs_list_add(&mfd->mfd_list, &med->med_open_head);
+                cfs_spin_unlock(&med->med_open_lock);
                 repbody->handle.cookie = mfd->mfd_handle.h_cookie;
         }
 
-        if (info->mti_epoch && (info->mti_epoch->flags & MF_SOM_CHANGE))
-                ma->ma_attr_flags |= MDS_PERM_BYPASS | MDS_SOM;
-
-        rc = mdt_attr_set(info, mo, rr->rr_flags);
-        if (rc)
-                GOTO(out_put, rc);
-
-        if (info->mti_epoch && (info->mti_epoch->flags & MF_SOM_CHANGE)) {
+        som_au = info->mti_ioepoch && info->mti_ioepoch->flags & MF_SOM_CHANGE;
+        if (som_au) {
+                /* SOM Attribute update case. Find the proper mfd and update
+                 * SOM attributes on the proper object. */
                 LASSERT(mdt_conn_flags(info) & OBD_CONNECT_SOM);
-                LASSERT(info->mti_epoch);
+                LASSERT(info->mti_ioepoch);
 
-                spin_lock(&med->med_open_lock);
-                /* Size-on-MDS Update. Find and free mfd. */
-                mfd = mdt_handle2mfd(info, &info->mti_epoch->handle);
+                cfs_spin_lock(&med->med_open_lock);
+                mfd = mdt_handle2mfd(info, &info->mti_ioepoch->handle);
                 if (mfd == NULL) {
-                        spin_unlock(&med->med_open_lock);
-                        CDEBUG(D_INODE | D_ERROR, "no handle for file close: "
-                                        "fid = "DFID": cookie = "LPX64"\n",
-                                        PFID(info->mti_rr.rr_fid1),
-                                        info->mti_epoch->handle.cookie);
+                        cfs_spin_unlock(&med->med_open_lock);
+                        CDEBUG(D_INODE, "no handle for file close: "
+                               "fid = "DFID": cookie = "LPX64"\n",
+                               PFID(info->mti_rr.rr_fid1),
+                               info->mti_ioepoch->handle.cookie);
                         GOTO(out_put, rc = -ESTALE);
                 }
                 LASSERT(mfd->mfd_mode == FMODE_SOM);
-                LASSERT(!(info->mti_epoch->flags & MF_EPOCH_CLOSE));
+                LASSERT(!(info->mti_ioepoch->flags & MF_EPOCH_CLOSE));
 
                 class_handle_unhash(&mfd->mfd_handle);
-                list_del_init(&mfd->mfd_list);
-                spin_unlock(&med->med_open_lock);
+                cfs_list_del_init(&mfd->mfd_list);
+                cfs_spin_unlock(&med->med_open_lock);
+
+                /* Close the found mfd, update attributes. */
+                ma->ma_lmm_size = info->mti_mdt->mdt_max_mdsize;
+                OBD_ALLOC(ma->ma_lmm, ma->ma_lmm_size);
+                if (ma->ma_lmm == NULL)
+                        GOTO(out_put, rc = -ENOMEM);
 
                 mdt_mfd_close(info, mfd);
+
+                OBD_FREE(ma->ma_lmm, ma->ma_lmm_size);
+        } else {
+                rc = mdt_attr_set(info, mo, ma, rr->rr_flags);
+                if (rc)
+                        GOTO(out_put, rc);
         }
 
         ma->ma_need = MA_INODE;
@@ -387,9 +437,10 @@ static int mdt_reint_setattr(struct mdt_thread_info *info,
 
         mdt_pack_attr2body(info, repbody, &ma->ma_attr, mdt_object_fid(mo));
 
-        if (mdt->mdt_opts.mo_oss_capa &&
+        if (info->mti_mdt->mdt_opts.mo_oss_capa &&
+            info->mti_exp->exp_connect_flags & OBD_CONNECT_OSS_CAPA &&
             S_ISREG(lu_object_attr(&mo->mot_obj.mo_lu)) &&
-            (ma->ma_attr.la_valid & LA_SIZE)) {
+            (ma->ma_attr.la_valid & LA_SIZE) && !som_au) {
                 struct lustre_capa *capa;
 
                 capa = req_capsule_server_get(info->mti_pill, &RMF_CAPA2);
@@ -470,21 +521,36 @@ static int mdt_reint_unlink(struct mdt_thread_info *info,
         if (OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNLINK))
                 RETURN(err_serious(-ENOENT));
 
-        /* step 1: lock the parent */
+        /*
+         * step 1: lock the parent. Note, this may be child in case of
+         * remote operation denoted by ->mti_cross_ref flag.
+         */
         parent_lh = &info->mti_lh[MDT_LH_PARENT];
-        mdt_lock_pdo_init(parent_lh, LCK_PW, rr->rr_name,
-                          rr->rr_namelen);
-
+        if (info->mti_cross_ref) {
+                /*
+                 * Init reg lock for cross ref case when we need to do only
+                 * ref del locally.
+                 */
+                mdt_lock_reg_init(parent_lh, LCK_PW);
+        } else {
+                mdt_lock_pdo_init(parent_lh, LCK_PW, rr->rr_name,
+                                  rr->rr_namelen);
+        }
         mp = mdt_object_find_lock(info, rr->rr_fid1, parent_lh,
                                   MDS_INODELOCK_UPDATE);
         if (IS_ERR(mp)) {
                 rc = PTR_ERR(mp);
-                /* errors are possible here in cross-ref cases, see below */ 
+                /* errors are possible here in cross-ref cases, see below */
                 if (info->mti_cross_ref)
                         rc = 0;
                 GOTO(out, rc);
         }
 
+        info->mti_mos[0] = mp;
+        rc = mdt_version_get_check(info, 0);
+        if (rc)
+                GOTO(out_unlock_parent, rc);
+
         mdt_reint_init_ma(info, ma);
         if (!ma->ma_lmm || !ma->ma_cookie)
                 GOTO(out_unlock_parent, rc = -EINVAL);
@@ -500,7 +566,8 @@ static int mdt_reint_unlink(struct mdt_thread_info *info,
                         mdt_set_capainfo(info, 0, rr->rr_fid1, BYPASS_CAPA);
                         rc = mo_ref_del(info->mti_env,
                                         mdt_object_child(mp), ma);
-                        mdt_handle_last_unlink(info, mp, ma);
+                        if (rc == 0)
+                                mdt_handle_last_unlink(info, mp, ma);
                 } else
                         rc = 0;
                 GOTO(out_unlock_parent, rc);
@@ -529,6 +596,11 @@ static int mdt_reint_unlink(struct mdt_thread_info *info,
         mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
                        OBD_FAIL_MDS_REINT_UNLINK_WRITE);
 
+        info->mti_mos[1] = mc;
+        rc = mdt_version_get_check(info, 1);
+        if (rc)
+                GOTO(out_unlock_child, rc);
+
         /*
          * Now we can only make sure we need MA_INODE, in mdd layer, will check
          * whether need MA_LOV and MA_COOKIE.
@@ -542,6 +614,7 @@ static int mdt_reint_unlink(struct mdt_thread_info *info,
                 mdt_handle_last_unlink(info, mc, ma);
 
         EXIT;
+out_unlock_child:
         mdt_object_unlock_put(info, mc, child_lh, rc);
 out_unlock_parent:
         mdt_object_unlock_put(info, mp, parent_lh, rc);
@@ -601,6 +674,11 @@ static int mdt_reint_link(struct mdt_thread_info *info,
         if (IS_ERR(mp))
                 RETURN(PTR_ERR(mp));
 
+        info->mti_mos[0] = mp;
+        rc = mdt_version_get_check(info, 0);
+        if (rc)
+                GOTO(out_unlock_parent, rc);
+
         /* step 2: find & lock the source */
         lhs = &info->mti_lh[MDT_LH_CHILD];
         mdt_lock_reg_init(lhs, LCK_EX);
@@ -620,16 +698,53 @@ static int mdt_reint_link(struct mdt_thread_info *info,
         mdt_fail_write(info->mti_env, info->mti_mdt->mdt_bottom,
                        OBD_FAIL_MDS_REINT_LINK_WRITE);
 
+        info->mti_mos[1] = ms;
+        rc = mdt_version_get_check(info, 1);
+        if (rc)
+                GOTO(out_unlock_child, rc);
+
         lname = mdt_name(info->mti_env, (char *)rr->rr_name, rr->rr_namelen);
         rc = mdo_link(info->mti_env, mdt_object_child(mp),
                       mdt_object_child(ms), lname, ma);
 
         EXIT;
+out_unlock_child:
         mdt_object_unlock_put(info, ms, lhs, rc);
 out_unlock_parent:
         mdt_object_unlock_put(info, mp, lhp, rc);
         return rc;
 }
+/**
+ * lock the part of the directory according to the hash of the name
+ * (lh->mlh_pdo_hash) in parallel directory lock.
+ */
+static int mdt_pdir_hash_lock(struct mdt_thread_info *info,
+                       struct mdt_lock_handle *lh,
+                       struct mdt_object *obj, __u64 ibits)
+{
+        struct ldlm_res_id *res_id = &info->mti_res_id;
+        struct ldlm_namespace *ns = info->mti_mdt->mdt_namespace;
+        ldlm_policy_data_t *policy = &info->mti_policy;
+        int rc;
+
+        /*
+         * Finish res_id initializing by name hash marking part of
+         * directory which is taking modification.
+         */
+        LASSERT(lh->mlh_pdo_hash != 0);
+        fid_build_pdo_res_name(mdt_object_fid(obj), lh->mlh_pdo_hash, res_id);
+        memset(policy, 0, sizeof(*policy));
+        policy->l_inodebits.bits = ibits;
+        /*
+         * Use LDLM_FL_LOCAL_ONLY for this lock. We do not know yet if it is
+         * going to be sent to client. If it is - mdt_intent_policy() path will
+         * fix it up and turn FL_LOCAL flag off.
+         */
+        rc = mdt_fid_lock(ns, &lh->mlh_reg_lh, lh->mlh_reg_mode, policy,
+                          res_id, LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB,
+                          &info->mti_exp->exp_handle.h_cookie);
+        return rc;
+}
 
 /* partial operation for rename */
 static int mdt_reint_rename_tgt(struct mdt_thread_info *info)
@@ -712,25 +827,17 @@ static int mdt_rename_lock(struct mdt_thread_info *info,
         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;
-        struct lu_site        *ls;
+        struct md_site        *ms;
         int rc;
         ENTRY;
 
-        /* 
-         * Disable global rename BFL lock temporarily because 
-         * when a mds do rename recoverying, which might enqueue 
-         * BFL lock to the controller mds. and this req might be 
-         * replay req for controller mds. but we did not have 
-         * such handling in controller mds. XXX
-         */
-        RETURN(0);
-        ls = info->mti_mdt->mdt_md_dev.md_lu_dev.ld_site;
+        ms = mdt_md_site(info->mti_mdt);
         fid_build_reg_res_name(&LUSTRE_BFL_FID, res_id);
 
         memset(policy, 0, sizeof *policy);
         policy->l_inodebits.bits = MDS_INODELOCK_UPDATE;
 
-        if (ls->ls_control_exp == NULL) {
+        if (ms->ms_control_exp == NULL) {
                 int flags = LDLM_FL_LOCAL_ONLY | LDLM_FL_ATOMIC_CB;
 
                 /*
@@ -740,18 +847,19 @@ static int mdt_rename_lock(struct mdt_thread_info *info,
                 rc = ldlm_cli_enqueue_local(ns, res_id, LDLM_IBITS, policy,
                                             LCK_EX, &flags, ldlm_blocking_ast,
                                             ldlm_completion_ast, NULL, NULL, 0,
-                                            NULL, lh);
+                                            &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 };
+                     ldlm_blocking_ast, ldlm_completion_ast, NULL, NULL, NULL };
                 int flags = 0;
 
                 /*
                  * This is the case mdt0 is remote node, issue DLM lock like
                  * other clients.
                  */
-                rc = ldlm_cli_enqueue(ls->ls_control_exp, NULL, &einfo, res_id,
-                                      policy, &flags, NULL, 0, NULL, lh, 0);
+                rc = ldlm_cli_enqueue(ms->ms_control_exp, NULL, &einfo, res_id,
+                                      policy, &flags, NULL, 0, lh, 0);
         }
 
         RETURN(rc);
@@ -760,9 +868,6 @@ static int mdt_rename_lock(struct mdt_thread_info *info,
 static void mdt_rename_unlock(struct lustre_handle *lh)
 {
         ENTRY;
-        /* Disable global rename BFL lock temporarily. see above XXX*/
-        EXIT;
-        return;
         LASSERT(lustre_handle_is_used(lh));
         ldlm_lock_decref(lh, LCK_EX);
         EXIT;
@@ -855,6 +960,11 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
         if (IS_ERR(msrcdir))
                 GOTO(out_rename_lock, rc = PTR_ERR(msrcdir));
 
+        info->mti_mos[0] = msrcdir;
+        rc = mdt_version_get_check(info, 0);
+        if (rc)
+                GOTO(out_unlock_source, rc);
+
         /* step 2: find & lock the target dir. */
         lh_tgtdirp = &info->mti_lh[MDT_LH_CHILD];
         mdt_lock_pdo_init(lh_tgtdirp, LCK_PW, rr->rr_tgt,
@@ -862,6 +972,12 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
         if (lu_fid_eq(rr->rr_fid1, rr->rr_fid2)) {
                 mdt_object_get(info->mti_env, msrcdir);
                 mtgtdir = msrcdir;
+                if (lh_tgtdirp->mlh_pdo_hash != lh_srcdirp->mlh_pdo_hash) {
+                         rc = mdt_pdir_hash_lock(info, lh_tgtdirp, mtgtdir,
+                                                 MDS_INODELOCK_UPDATE);
+                         if (rc)
+                                 GOTO(out_unlock_source, rc);
+                }
         } else {
                 mtgtdir = mdt_object_find(info->mti_env, info->mti_mdt,
                                           rr->rr_fid2);
@@ -876,7 +992,14 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
                         rc = mdt_object_lock(info, mtgtdir, lh_tgtdirp,
                                              MDS_INODELOCK_UPDATE,
                                              MDT_LOCAL_LOCK);
-                        if (rc != 0)
+                        if (rc != 0) {
+                                mdt_object_put(info->mti_env, mtgtdir);
+                                GOTO(out_unlock_source, rc);
+                        }
+
+                        info->mti_mos[1] = mtgtdir;
+                        rc = mdt_version_get_check(info, 1);
+                        if (rc)
                                 GOTO(out_unlock_target, rc);
                 }
         }
@@ -904,6 +1027,12 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
                 mdt_object_put(info->mti_env, mold);
                 GOTO(out_unlock_target, rc);
         }
+
+        info->mti_mos[2] = mold;
+        rc = mdt_version_get_check(info, 2);
+        if (rc)
+                GOTO(out_unlock_old, rc);
+
         mdt_set_capainfo(info, 2, old_fid, BYPASS_CAPA);
 
         /* step 4: find & lock the new object. */
@@ -931,6 +1060,12 @@ static int mdt_reint_rename(struct mdt_thread_info *info,
                         mdt_object_put(info->mti_env, mnew);
                         GOTO(out_unlock_old, rc);
                 }
+
+                info->mti_mos[3] = mnew;
+                rc = mdt_version_get_check(info, 3);
+                if (rc)
+                        GOTO(out_unlock_new, rc);
+
                 mdt_set_capainfo(info, 3, new_fid, BYPASS_CAPA);
         } else if (rc != -EREMOTE && rc != -ENOENT)
                 GOTO(out_unlock_old, rc);