Whamcloud - gitweb
LU-6354 mdd: use cr_tfid on error in mdd_changelog_ns_store()
[fs/lustre-release.git] / lustre / mdd / mdd_dir.c
index acb4775..b472596 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2013, Intel Corporation.
+ * Copyright (c) 2011, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -99,8 +99,7 @@ __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
 
        if (likely(S_ISDIR(mdd_object_type(mdd_obj)) &&
                   dt_try_as_dir(env, dir)))
-               rc = dt_lookup(env, dir, (struct dt_rec *)fid, key,
-                              mdd_object_capa(env, mdd_obj));
+               rc = dt_lookup(env, dir, (struct dt_rec *)fid, key);
        else
                rc = -ENOTDIR;
 
@@ -115,11 +114,12 @@ int mdd_lookup(const struct lu_env *env,
         int rc;
         ENTRY;
 
-       rc = mdd_la_get(env, md2mdd_obj(pobj), pattr, BYPASS_CAPA);
+       rc = mdd_la_get(env, md2mdd_obj(pobj), pattr);
        if (rc != 0)
                RETURN(rc);
 
-       rc = __mdd_lookup(env, pobj, pattr, lname, fid, MAY_EXEC);
+       rc = __mdd_lookup(env, pobj, pattr, lname, fid,
+                         (spec != NULL && spec->sp_permitted) ? 0 : MAY_EXEC);
         RETURN(rc);
 }
 
@@ -170,8 +170,7 @@ static int mdd_is_parent(const struct lu_env *env,
                 RETURN(0);
 
         for(;;) {
-               /* this is done recursively, bypass capa for each obj */
-               mdd_set_capainfo(env, 4, p1, BYPASS_CAPA);
+               /* this is done recursively */
                rc = mdd_parent_fid(env, p1, attr, pfid);
                if (rc)
                        GOTO(out, rc);
@@ -206,7 +205,7 @@ out:
  * No permission check is needed.
  *
  * returns 1: if fid is ancestor of @mo;
- * returns 0: if fid is not a ancestor of @mo;
+ * returns 0: if fid is not an ancestor of @mo;
  *
  * returns EREMOTE if remote object is found, fid of remote object is saved to
  * @fid;
@@ -224,7 +223,7 @@ int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
        if (!S_ISDIR(mdd_object_type(md2mdd_obj(mo))))
                RETURN(0);
 
-       rc = mdd_la_get(env, md2mdd_obj(mo), attr, BYPASS_CAPA);
+       rc = mdd_la_get(env, md2mdd_obj(mo), attr);
        if (rc != 0)
                RETURN(rc);
 
@@ -265,7 +264,7 @@ static int mdd_dir_is_empty(const struct lu_env *env,
                RETURN(-ENOTDIR);
 
        iops = &obj->do_index_ops->dio_it;
-       it = iops->init(env, obj, LUDA_64BITHASH, BYPASS_CAPA);
+       it = iops->init(env, obj, LUDA_64BITHASH);
        if (!IS_ERR(it)) {
                result = iops->get(env, it, (const struct dt_key *)"");
                if (result > 0) {
@@ -350,8 +349,7 @@ int mdd_may_create(const struct lu_env *env, struct mdd_object *pobj,
 
        /* If the parent is a sub-stripe, check whether it is dead */
        xbuf = mdd_buf_get(env, info->mti_key, sizeof(info->mti_key));
-       rc = mdo_xattr_get(env, pobj, xbuf, XATTR_NAME_LMV,
-                          mdd_object_capa(env, pobj));
+       rc = mdo_xattr_get(env, pobj, xbuf, XATTR_NAME_LMV);
        if (unlikely(rc > 0)) {
                struct lmv_mds_md_v1  *lmv1 = xbuf->lb_buf;
 
@@ -380,17 +378,16 @@ int mdd_may_unlink(const struct lu_env *env, struct mdd_object *pobj,
        if (mdd_is_dead_obj(pobj))
                RETURN(-ENOENT);
 
-       if ((attr->la_valid & LA_FLAGS) &&
-           (attr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL)))
+       if (attr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))
                RETURN(-EPERM);
 
        rc = mdd_permission_internal_locked(env, pobj, pattr,
                                            MAY_WRITE | MAY_EXEC,
                                            MOR_TGT_PARENT);
-       if (rc)
+       if (rc != 0)
                RETURN(rc);
 
-       if (mdd_is_append(pobj))
+       if (pattr->la_flags & LUSTRE_APPEND_FL)
                RETURN(-EPERM);
 
        RETURN(rc);
@@ -445,7 +442,7 @@ static int mdd_may_delete_entry(const struct lu_env *env,
                        RETURN(rc);
        }
 
-       if (mdd_is_append(pobj))
+       if (pattr->la_flags & LUSTRE_APPEND_FL)
                RETURN(-EPERM);
 
        RETURN(0);
@@ -482,11 +479,7 @@ int mdd_may_delete(const struct lu_env *env, struct mdd_object *tpobj,
        if (mdd_is_sticky(env, tpobj, tpattr, tobj, tattr))
                RETURN(-EPERM);
 
-       if (mdd_is_immutable(tobj) || mdd_is_append(tobj))
-               RETURN(-EPERM);
-
-       if ((tattr->la_valid & LA_FLAGS) &&
-           (tattr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL)))
+       if (tattr->la_flags & (LUSTRE_APPEND_FL | LUSTRE_IMMUTABLE_FL))
                RETURN(-EPERM);
 
        /* additional check the rename case */
@@ -546,11 +539,11 @@ static int mdd_link_sanity_check(const struct lu_env *env,
        if (rc < 0)
                RETURN(rc);
 
-        if (mdd_is_immutable(src_obj) || mdd_is_append(src_obj))
-                RETURN(-EPERM);
+       if (cattr->la_flags & (LUSTRE_IMMUTABLE_FL | LUSTRE_APPEND_FL))
+               RETURN(-EPERM);
 
-        if (S_ISDIR(mdd_object_type(src_obj)))
-                RETURN(-EPERM);
+       if (S_ISDIR(mdd_object_type(src_obj)))
+               RETURN(-EPERM);
 
        LASSERT(src_obj != tgt_obj);
        rc = mdd_may_create(env, tgt_obj, tattr, NULL, true);
@@ -563,15 +556,14 @@ static int mdd_link_sanity_check(const struct lu_env *env,
 }
 
 static int __mdd_index_delete_only(const struct lu_env *env, struct mdd_object *pobj,
-                                  const char *name, struct thandle *handle,
-                                  struct lustre_capa *capa)
+                                  const char *name, struct thandle *handle)
 {
        struct dt_object *next = mdd_object_child(pobj);
        int rc;
        ENTRY;
 
        if (dt_try_as_dir(env, next))
-               rc = dt_delete(env, next, (struct dt_key *)name, handle, capa);
+               rc = dt_delete(env, next, (struct dt_key *)name, handle);
        else
                rc = -ENOTDIR;
 
@@ -582,8 +574,7 @@ static int __mdd_index_insert_only(const struct lu_env *env,
                                   struct mdd_object *pobj,
                                   const struct lu_fid *lf, __u32 type,
                                   const char *name,
-                                  struct thandle *handle,
-                                  struct lustre_capa *capa)
+                                  struct thandle *handle)
 {
        struct dt_object *next = mdd_object_child(pobj);
        int               rc;
@@ -598,7 +589,7 @@ static int __mdd_index_insert_only(const struct lu_env *env,
                rec->rec_type = type;
                ignore_quota = uc ? uc->uc_cap & CFS_CAP_SYS_RESOURCE_MASK : 1;
                rc = dt_insert(env, next, (const struct dt_rec *)rec,
-                              (const struct dt_key *)name, handle, capa,
+                              (const struct dt_key *)name, handle,
                               ignore_quota);
        } else {
                rc = -ENOTDIR;
@@ -609,13 +600,12 @@ static int __mdd_index_insert_only(const struct lu_env *env,
 /* insert named index, add reference if isdir */
 static int __mdd_index_insert(const struct lu_env *env, struct mdd_object *pobj,
                              const struct lu_fid *lf, __u32 type,
-                             const char *name, struct thandle *handle,
-                             struct lustre_capa *capa)
+                             const char *name, struct thandle *handle)
 {
        int rc;
        ENTRY;
 
-       rc = __mdd_index_insert_only(env, pobj, lf, type, name, handle, capa);
+       rc = __mdd_index_insert_only(env, pobj, lf, type, name, handle);
        if (rc == 0 && S_ISDIR(type)) {
                mdd_write_lock(env, pobj, MOR_TGT_PARENT);
                mdo_ref_add(env, pobj, handle);
@@ -627,13 +617,13 @@ static int __mdd_index_insert(const struct lu_env *env, struct mdd_object *pobj,
 
 /* delete named index, drop reference if isdir */
 static int __mdd_index_delete(const struct lu_env *env, struct mdd_object *pobj,
-                              const char *name, int is_dir, struct thandle *handle,
-                              struct lustre_capa *capa)
+                             const char *name, int is_dir,
+                             struct thandle *handle)
 {
         int               rc;
         ENTRY;
 
-        rc = __mdd_index_delete_only(env, pobj, name, handle, capa);
+       rc = __mdd_index_delete_only(env, pobj, name, handle);
         if (rc == 0 && is_dir) {
                 mdd_write_lock(env, pobj, MOR_TGT_PARENT);
                 mdo_ref_del(env, pobj, handle);
@@ -643,52 +633,37 @@ static int __mdd_index_delete(const struct lu_env *env, struct mdd_object *pobj,
         RETURN(rc);
 }
 
-int mdd_declare_changelog_store(const struct lu_env *env,
-                               struct mdd_device *mdd,
-                               const struct lu_name *fname,
-                               struct thandle *handle)
+static int mdd_llog_record_calc_size(const struct lu_env *env,
+                                    const struct lu_name *tname,
+                                    const struct lu_name *sname)
 {
-       struct obd_device               *obd = mdd2obd_dev(mdd);
-       struct llog_ctxt                *ctxt;
-       struct llog_changelog_rec       *rec;
-       struct lu_buf                   *buf;
-       int                              reclen;
-       int                              rc;
-
-       /* Not recording */
-       if (!(mdd->mdd_cl.mc_flags & CLM_ON))
-               return 0;
-
-       reclen = llog_data_len(sizeof(*rec) +
-                              (fname != NULL ? fname->ln_namelen : 0));
-       buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
-       if (buf->lb_buf == NULL)
-               return -ENOMEM;
-
-       rec = buf->lb_buf;
-       rec->cr_hdr.lrh_len = reclen;
-       rec->cr_hdr.lrh_type = CHANGELOG_REC;
+       const struct lu_ucred   *uc = lu_ucred(env);
+       enum changelog_rec_flags crf = 0;
+       size_t                   hdr_size = sizeof(struct llog_changelog_rec) -
+                                           sizeof(struct changelog_rec);
 
-       ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
-       if (ctxt == NULL)
-               return -ENXIO;
+       if (sname != NULL)
+               crf |= CLF_RENAME;
 
-       rc = llog_declare_add(env, ctxt->loc_handle, &rec->cr_hdr, handle);
-       llog_ctxt_put(ctxt);
+       if (uc != NULL && uc->uc_jobid[0] != '\0')
+               crf |= CLF_JOBID;
 
-       return rc;
+       return llog_data_len(hdr_size + changelog_rec_offset(crf) +
+                            (tname != NULL ? tname->ln_namelen : 0) +
+                            (sname != NULL ? 1 + sname->ln_namelen : 0));
 }
 
-static int mdd_declare_changelog_ext_store(const struct lu_env *env,
-                                          struct mdd_device *mdd,
-                                          const struct lu_name *tname,
-                                          const struct lu_name *sname,
-                                          struct thandle *handle)
+int mdd_declare_changelog_store(const struct lu_env *env,
+                               struct mdd_device *mdd,
+                               const struct lu_name *tname,
+                               const struct lu_name *sname,
+                               struct thandle *handle)
 {
        struct obd_device               *obd = mdd2obd_dev(mdd);
        struct llog_ctxt                *ctxt;
-       struct llog_changelog_ext_rec   *rec;
+       struct llog_changelog_rec       *rec;
        struct lu_buf                   *buf;
+       struct thandle                  *llog_th;
        int                              reclen;
        int                              rc;
 
@@ -696,9 +671,7 @@ static int mdd_declare_changelog_ext_store(const struct lu_env *env,
        if (!(mdd->mdd_cl.mc_flags & CLM_ON))
                return 0;
 
-       reclen = llog_data_len(sizeof(*rec) +
-                              (tname != NULL ? tname->ln_namelen : 0) +
-                              (sname != NULL ? 1 + sname->ln_namelen : 0));
+       reclen = mdd_llog_record_calc_size(env, tname, sname);
        buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
        if (buf->lb_buf == NULL)
                return -ENOMEM;
@@ -711,7 +684,13 @@ static int mdd_declare_changelog_ext_store(const struct lu_env *env,
        if (ctxt == NULL)
                return -ENXIO;
 
-       rc = llog_declare_add(env, ctxt->loc_handle, &rec->cr_hdr, handle);
+       llog_th = thandle_get_sub(env, handle, ctxt->loc_handle->lgh_obj);
+       if (IS_ERR(llog_th))
+               GOTO(out_put, rc = PTR_ERR(llog_th));
+
+       rc = llog_declare_add(env, ctxt->loc_handle, &rec->cr_hdr, llog_th);
+
+out_put:
        llog_ctxt_put(ctxt);
 
        return rc;
@@ -721,7 +700,7 @@ static int mdd_declare_changelog_ext_store(const struct lu_env *env,
  * \param mdd
  * \param rec
  * \param handle - currently ignored since llogs start their own transaction;
- *                 this will hopefully be fixed in llog rewrite
+ *             this will hopefully be fixed in llog rewrite
  * \retval 0 ok
  */
 int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
@@ -729,46 +708,12 @@ int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
 {
        struct obd_device       *obd = mdd2obd_dev(mdd);
        struct llog_ctxt        *ctxt;
+       struct thandle          *llog_th;
        int                      rc;
 
-       rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) + rec->cr.cr_namelen);
-       rec->cr_hdr.lrh_type = CHANGELOG_REC;
-       rec->cr.cr_time = cl_time();
-
-       spin_lock(&mdd->mdd_cl.mc_lock);
-       /* NB: I suppose it's possible llog_add adds out of order wrt cr_index,
-        * but as long as the MDD transactions are ordered correctly for e.g.
-        * rename conflicts, I don't think this should matter. */
-       rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
-       spin_unlock(&mdd->mdd_cl.mc_lock);
-
-       ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
-       if (ctxt == NULL)
-               return -ENXIO;
-
-       rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, th);
-       llog_ctxt_put(ctxt);
-       if (rc > 0)
-               rc = 0;
-       return rc;
-}
-
-/** Add a changelog_ext entry \a rec to the changelog llog
- * \param mdd
- * \param rec
- * \param handle - currently ignored since llogs start their own transaction;
- *             this will hopefully be fixed in llog rewrite
- * \retval 0 ok
- */
-static int
-mdd_changelog_ext_store(const struct lu_env *env, struct mdd_device *mdd,
-                       struct llog_changelog_ext_rec *rec, struct thandle *th)
-{
-       struct obd_device       *obd = mdd2obd_dev(mdd);
-       struct llog_ctxt        *ctxt;
-       int                      rc;
+       rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) +
+                                           changelog_rec_varsize(&rec->cr));
 
-       rec->cr_hdr.lrh_len = llog_data_len(sizeof(*rec) + rec->cr.cr_namelen);
        /* llog_lvfs_write_rec sets the llog tail len */
        rec->cr_hdr.lrh_type = CHANGELOG_REC;
        rec->cr.cr_time = cl_time();
@@ -784,72 +729,50 @@ mdd_changelog_ext_store(const struct lu_env *env, struct mdd_device *mdd,
        if (ctxt == NULL)
                return -ENXIO;
 
+       llog_th = thandle_get_sub(env, th, ctxt->loc_handle->lgh_obj);
+       if (IS_ERR(llog_th))
+               GOTO(out_put, rc = PTR_ERR(llog_th));
+
        /* nested journal transaction */
-       rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, th);
+       rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, llog_th);
+
+out_put:
        llog_ctxt_put(ctxt);
        if (rc > 0)
                rc = 0;
-
        return rc;
 }
 
-/** Store a namespace change changelog record
- * If this fails, we must fail the whole transaction; we don't
- * want the change to commit without the log entry.
- * \param target - mdd_object of change
- * \param parent - parent dir/object
- * \param tname - target name string
- * \param handle - transacion handle
- */
-int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
-                          enum changelog_rec_type type, unsigned flags,
-                          struct mdd_object *target, struct mdd_object *parent,
-                          const struct lu_name *tname, struct thandle *handle)
+static void mdd_changelog_rec_ext_rename(struct changelog_rec *rec,
+                                        const struct lu_fid *sfid,
+                                        const struct lu_fid *spfid,
+                                        const struct lu_name *sname)
 {
-       struct llog_changelog_rec *rec;
-       struct lu_buf *buf;
-       int reclen;
-       int rc;
-       ENTRY;
-
-       /* Not recording */
-       if (!(mdd->mdd_cl.mc_flags & CLM_ON))
-               RETURN(0);
-       if ((mdd->mdd_cl.mc_mask & (1 << type)) == 0)
-               RETURN(0);
+       struct changelog_ext_rename     *rnm = changelog_rec_rename(rec);
+       size_t                           extsize = sname->ln_namelen + 1;
 
-       LASSERT(target != NULL);
-       LASSERT(parent != NULL);
-       LASSERT(tname != NULL);
-       LASSERT(handle != NULL);
+       LASSERT(sfid != NULL);
+       LASSERT(spfid != NULL);
+       LASSERT(sname != NULL);
 
-       reclen = llog_data_len(sizeof(*rec) + tname->ln_namelen);
-       buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
-       if (buf->lb_buf == NULL)
-               RETURN(-ENOMEM);
-       rec = buf->lb_buf;
+       rnm->cr_sfid = *sfid;
+       rnm->cr_spfid = *spfid;
 
-       rec->cr.cr_flags = CLF_VERSION | (CLF_FLAGMASK & flags);
-       rec->cr.cr_type = (__u32)type;
-       rec->cr.cr_tfid = *mdo2fid(target);
-       rec->cr.cr_pfid = *mdo2fid(parent);
-       rec->cr.cr_namelen = tname->ln_namelen;
-       memcpy(rec->cr.cr_name, tname->ln_name, tname->ln_namelen);
+       changelog_rec_name(rec)[rec->cr_namelen] = '\0';
+       strlcpy(changelog_rec_sname(rec), sname->ln_name, extsize);
+       rec->cr_namelen += extsize;
+}
 
-       target->mod_cltime = cfs_time_current_64();
+void mdd_changelog_rec_ext_jobid(struct changelog_rec *rec, const char *jobid)
+{
+       struct changelog_ext_jobid      *jid = changelog_rec_jobid(rec);
 
-       rc = mdd_changelog_store(env, mdd, rec, handle);
-       if (rc < 0) {
-               CERROR("changelog failed: rc=%d, op%d %s c"DFID" p"DFID"\n",
-                       rc, type, tname->ln_name, PFID(&rec->cr.cr_tfid),
-                       PFID(&rec->cr.cr_pfid));
-               RETURN(-EFAULT);
-       }
+       if (jobid == NULL || jobid[0] == '\0')
+               return;
 
-       RETURN(0);
+       strlcpy(jid->cr_jobid, jobid, sizeof(jid->cr_jobid));
 }
 
-
 /** Store a namespace change changelog record
  * If this fails, we must fail the whole transaction; we don't
  * want the change to commit without the log entry.
@@ -861,55 +784,63 @@ int mdd_changelog_ns_store(const struct lu_env *env, struct mdd_device *mdd,
  * \param sname - source name string
  * \param handle - transacion handle
  */
-static int mdd_changelog_ext_ns_store(const struct lu_env  *env,
-                                     struct mdd_device    *mdd,
-                                     enum changelog_rec_type type,
-                                     unsigned flags,
-                                     struct mdd_object    *target,
-                                     const struct lu_fid  *tpfid,
-                                     const struct lu_fid  *sfid,
-                                     const struct lu_fid  *spfid,
-                                     const struct lu_name *tname,
-                                     const struct lu_name *sname,
-                                     struct thandle *handle)
-{
-       struct llog_changelog_ext_rec *rec;
-       struct lu_buf *buf;
-       int reclen;
-       int rc;
+int mdd_changelog_ns_store(const struct lu_env *env,
+                          struct mdd_device *mdd,
+                          enum changelog_rec_type type,
+                          enum changelog_rec_flags crf,
+                          struct mdd_object *target,
+                          const struct lu_fid *tpfid,
+                          const struct lu_fid *sfid,
+                          const struct lu_fid *spfid,
+                          const struct lu_name *tname,
+                          const struct lu_name *sname,
+                          struct thandle *handle)
+{
+       const struct lu_ucred           *uc = lu_ucred(env);
+       struct llog_changelog_rec       *rec;
+       struct lu_buf                   *buf;
+       int                              reclen;
+       int                              rc;
        ENTRY;
 
        /* Not recording */
        if (!(mdd->mdd_cl.mc_flags & CLM_ON))
                RETURN(0);
+
        if ((mdd->mdd_cl.mc_mask & (1 << type)) == 0)
                RETURN(0);
 
-       LASSERT(sfid != NULL);
        LASSERT(tpfid != NULL);
        LASSERT(tname != NULL);
        LASSERT(handle != NULL);
 
-       reclen = llog_data_len(sizeof(*rec) +
-                              sname != NULL ? 1 + sname->ln_namelen : 0);
+       reclen = mdd_llog_record_calc_size(env, tname, sname);
        buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
        if (buf->lb_buf == NULL)
                RETURN(-ENOMEM);
        rec = buf->lb_buf;
 
-       rec->cr.cr_flags = CLF_EXT_VERSION | (CLF_FLAGMASK & flags);
+       crf &= CLF_FLAGMASK;
+
+       if (uc != NULL && uc->uc_jobid[0] != '\0')
+               crf |= CLF_JOBID;
+
+       if (sname != NULL)
+               crf |= CLF_RENAME;
+       else
+               crf |= CLF_VERSION;
+
+       rec->cr.cr_flags = crf;
        rec->cr.cr_type = (__u32)type;
        rec->cr.cr_pfid = *tpfid;
-       rec->cr.cr_sfid = *sfid;
-       rec->cr.cr_spfid = *spfid;
        rec->cr.cr_namelen = tname->ln_namelen;
-       memcpy(rec->cr.cr_name, tname->ln_name, tname->ln_namelen);
-       if (sname) {
-               rec->cr.cr_name[tname->ln_namelen] = '\0';
-               memcpy(rec->cr.cr_name + tname->ln_namelen + 1, sname->ln_name,
-                       sname->ln_namelen);
-               rec->cr.cr_namelen += 1 + sname->ln_namelen;
-       }
+       memcpy(changelog_rec_name(&rec->cr), tname->ln_name, tname->ln_namelen);
+
+       if (crf & CLF_RENAME)
+               mdd_changelog_rec_ext_rename(&rec->cr, sfid, spfid, sname);
+
+       if (crf & CLF_JOBID)
+               mdd_changelog_rec_ext_jobid(&rec->cr, uc->uc_jobid);
 
        if (likely(target != NULL)) {
                rec->cr.cr_tfid = *mdo2fid(target);
@@ -918,10 +849,12 @@ static int mdd_changelog_ext_ns_store(const struct lu_env  *env,
                fid_zero(&rec->cr.cr_tfid);
        }
 
-       rc = mdd_changelog_ext_store(env, mdd, rec, handle);
+       rc = mdd_changelog_store(env, mdd, rec, handle);
        if (rc < 0) {
-               CERROR("changelog failed: rc=%d, op%d %s c"DFID" p"DFID"\n",
-                       rc, type, tname->ln_name, PFID(sfid), PFID(tpfid));
+               CERROR("%s: cannot store changelog record: type = %d, "
+                      "name = '%s', t = "DFID", p = "DFID": rc = %d\n",
+                      mdd2obd_dev(mdd)->obd_name, type, tname->ln_name,
+                      PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid), rc);
                return -EFAULT;
        }
 
@@ -1141,20 +1074,19 @@ int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
        if (ldata->ld_buf->lb_buf == NULL)
                return -ENOMEM;
 
-       rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf, XATTR_NAME_LINK,
-                         BYPASS_CAPA);
+       rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf, XATTR_NAME_LINK);
        if (rc == -ERANGE) {
                /* Buf was too small, figure out what we need. */
                lu_buf_free(ldata->ld_buf);
                rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf,
-                                  XATTR_NAME_LINK, BYPASS_CAPA);
+                                  XATTR_NAME_LINK);
                if (rc < 0)
                        return rc;
                ldata->ld_buf = lu_buf_check_and_alloc(ldata->ld_buf, rc);
                if (ldata->ld_buf->lb_buf == NULL)
                        return -ENOMEM;
                rc = mdo_xattr_get(env, mdd_obj, ldata->ld_buf,
-                                 XATTR_NAME_LINK, BYPASS_CAPA);
+                                 XATTR_NAME_LINK);
        }
        if (rc < 0) {
                lu_buf_free(ldata->ld_buf);
@@ -1173,7 +1105,7 @@ int mdd_links_read(const struct lu_env *env, struct mdd_object *mdd_obj,
 struct lu_buf *mdd_links_get(const struct lu_env *env,
                             struct mdd_object *mdd_obj)
 {
-       struct linkea_data ldata = { 0 };
+       struct linkea_data ldata = { NULL };
        int rc;
 
        rc = mdd_links_read(env, mdd_obj, &ldata);
@@ -1185,16 +1117,38 @@ int mdd_links_write(const struct lu_env *env, struct mdd_object *mdd_obj,
 {
        const struct lu_buf *buf = mdd_buf_get_const(env, ldata->ld_buf->lb_buf,
                                                     ldata->ld_leh->leh_len);
+       int                 rc;
 
        if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_LINKEA))
                return 0;
 
-       return mdo_xattr_set(env, mdd_obj, buf, XATTR_NAME_LINK, 0, handle,
-                            mdd_object_capa(env, mdd_obj));
+       rc = mdo_xattr_set(env, mdd_obj, buf, XATTR_NAME_LINK, 0, handle);
+       if (unlikely(rc == -ENOSPC) && S_ISREG(mdd_object_type(mdd_obj)) &&
+           mdd_object_remote(mdd_obj) == 0) {
+               struct lfsck_request *lr = &mdd_env_info(env)->mti_lr;
+               struct thandle  *sub_th;
+
+               /* XXX: If the linkEA is overflow, then we need to notify the
+                *      namespace LFSCK to skip "nlink" attribute verification
+                *      on this object to avoid the "nlink" to be shrinked by
+                *      wrong. It may be not good an interaction with LFSCK
+                *      like this. We will consider to replace it with other
+                *      mechanism in future. LU-5802. */
+               lfsck_pack_rfa(lr, mdo2fid(mdd_obj), LE_SKIP_NLINK,
+                              LFSCK_TYPE_NAMESPACE);
+
+               sub_th = thandle_get_sub_by_dt(env, handle,
+                               mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom);
+               lfsck_in_notify(env, mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom,
+                               lr, sub_th);
+       }
+
+       return rc;
 }
 
 int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
-                         struct thandle *handle, struct linkea_data *ldata)
+                         struct thandle *handle, struct linkea_data *ldata,
+                         enum mdd_links_add_overflow overflow)
 {
        int     rc;
        int     ea_len;
@@ -1212,6 +1166,29 @@ int mdd_declare_links_add(const struct lu_env *env, struct mdd_object *mdd_obj,
        rc = mdo_declare_xattr_set(env, mdd_obj,
                                   mdd_buf_get_const(env, linkea, ea_len),
                                   XATTR_NAME_LINK, 0, handle);
+       if (rc != 0)
+               return rc;
+
+       if (mdd_object_remote(mdd_obj) == 0 && overflow == MLAO_CHECK) {
+               struct lfsck_request *lr = &mdd_env_info(env)->mti_lr;
+               struct thandle  *sub_th;
+
+               /* XXX: If the linkEA is overflow, then we need to notify the
+                *      namespace LFSCK to skip "nlink" attribute verification
+                *      on this object to avoid the "nlink" to be shrinked by
+                *      wrong. It may be not good an interaction with LFSCK
+                *      like this. We will consider to replace it with other
+                *      mechanism in future. LU-5802. */
+               lfsck_pack_rfa(lr, mdo2fid(mdd_obj), LE_SKIP_NLINK_DECLARE,
+                              LFSCK_TYPE_NAMESPACE);
+
+               sub_th = thandle_get_sub_by_dt(env, handle,
+                               mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom);
+               rc = lfsck_in_notify(env,
+                                    mdo2mdd(&mdd_obj->mod_obj)->mdd_bottom,
+                                    lr, sub_th);
+       }
+
        return rc;
 }
 
@@ -1224,7 +1201,7 @@ static inline int mdd_declare_links_del(const struct lu_env *env,
        /* For directory, the linkEA will be removed together
         * with the object. */
        if (!S_ISDIR(mdd_object_type(c)))
-               rc = mdd_declare_links_add(env, c, handle, NULL);
+               rc = mdd_declare_links_add(env, c, handle, NULL, MLAO_IGNORE);
 
        return rc;
 }
@@ -1243,11 +1220,17 @@ static int mdd_declare_link(const struct lu_env *env,
        rc = mdo_declare_index_insert(env, p, mdo2fid(c), mdd_object_type(c),
                                      name->ln_name, handle);
        if (rc != 0)
-                return rc;
+               return rc;
 
-        rc = mdo_declare_ref_add(env, c, handle);
-        if (rc)
-                return rc;
+       rc = mdo_declare_ref_add(env, c, handle);
+       if (rc != 0)
+               return rc;
+
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MORE_NLINK)) {
+               rc = mdo_declare_ref_add(env, c, handle);
+               if (rc != 0)
+                       return rc;
+       }
 
        la->la_valid = LA_CTIME | LA_MTIME;
        rc = mdo_declare_attr_set(env, p, la, handle);
@@ -1256,16 +1239,17 @@ static int mdd_declare_link(const struct lu_env *env,
 
        la->la_valid = LA_CTIME;
        rc = mdo_declare_attr_set(env, c, la, handle);
-        if (rc)
-                return rc;
+       if (rc != 0)
+               return rc;
 
-       rc = mdd_declare_links_add(env, c, handle, data);
-        if (rc)
-                return rc;
+       rc = mdd_declare_links_add(env, c, handle, data,
+                       S_ISREG(mdd_object_type(c)) ? MLAO_CHECK : MLAO_IGNORE);
+       if (rc != 0)
+               return rc;
 
-        rc = mdd_declare_changelog_store(env, mdd, name, handle);
+       rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
 
-        return rc;
+       return rc;
 }
 
 static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
@@ -1284,11 +1268,11 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
        int rc;
        ENTRY;
 
-       rc = mdd_la_get(env, mdd_sobj, cattr, BYPASS_CAPA);
+       rc = mdd_la_get(env, mdd_sobj, cattr);
        if (rc != 0)
                RETURN(rc);
 
-       rc = mdd_la_get(env, mdd_tobj, tattr, BYPASS_CAPA);
+       rc = mdd_la_get(env, mdd_tobj, tattr);
        if (rc != 0)
                RETURN(rc);
 
@@ -1316,14 +1300,31 @@ static int mdd_link(const struct lu_env *env, struct md_object *tgt_obj,
        if (rc)
                GOTO(out_unlock, rc);
 
-       rc = mdo_ref_add(env, mdd_sobj, handle);
-       if (rc)
-               GOTO(out_unlock, rc);
+       if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LESS_NLINK)) {
+               rc = mdo_ref_add(env, mdd_sobj, handle);
+               if (rc != 0)
+                       GOTO(out_unlock, rc);
+       }
+
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MORE_NLINK)) {
+               rc = mdo_ref_add(env, mdd_sobj, handle);
+               if (rc != 0)
+                       GOTO(out_unlock, rc);
+       }
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING3)) {
+               struct lu_fid tfid = *mdo2fid(mdd_sobj);
+
+               tfid.f_oid++;
+               rc = __mdd_index_insert_only(env, mdd_tobj, &tfid,
+                                            mdd_object_type(mdd_sobj),
+                                            name, handle);
+       } else {
+               rc = __mdd_index_insert_only(env, mdd_tobj, mdo2fid(mdd_sobj),
+                                            mdd_object_type(mdd_sobj),
+                                            name, handle);
+       }
 
-       rc = __mdd_index_insert_only(env, mdd_tobj, mdo2fid(mdd_sobj),
-                                    mdd_object_type(mdd_sobj), name, handle,
-                                    mdd_object_capa(env, mdd_tobj));
        if (rc != 0) {
                mdo_ref_del(env, mdd_sobj, handle);
                GOTO(out_unlock, rc);
@@ -1352,7 +1353,8 @@ out_unlock:
         mdd_write_unlock(env, mdd_sobj);
         if (rc == 0)
                rc = mdd_changelog_ns_store(env, mdd, CL_HARDLINK, 0, mdd_sobj,
-                                           mdd_tobj, lname, handle);
+                                           mdo2fid(mdd_tobj), NULL, NULL,
+                                           lname, NULL, handle);
 stop:
        mdd_trans_stop(env, mdd, rc, handle);
 
@@ -1382,8 +1384,7 @@ static int mdd_mark_dead_object(const struct lu_env *env,
        if (declare)
                rc = mdo_declare_attr_set(env, obj, attr, handle);
        else
-               rc = mdo_attr_set(env, obj, attr, handle,
-                                 mdd_object_capa(env, obj));
+               rc = mdo_attr_set(env, obj, attr, handle);
 
        return rc;
 }
@@ -1473,20 +1474,25 @@ int mdd_unlink_sanity_check(const struct lu_env *env, struct mdd_object *pobj,
 static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd,
                              struct mdd_object *p, struct mdd_object *c,
                              const struct lu_name *name, struct md_attr *ma,
-                             struct thandle *handle, int no_name)
+                             struct thandle *handle, int no_name, int is_dir)
 {
-       struct lu_attr     *la = &mdd_env_info(env)->mti_la_for_fix;
-        int rc;
+       struct lu_attr  *la = &mdd_env_info(env)->mti_la_for_fix;
+       int              rc;
 
-       if (likely(no_name == 0)) {
-               rc = mdo_declare_index_delete(env, p, name->ln_name, handle);
-               if (rc)
-                       return rc;
-       }
+       if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
+               if (likely(no_name == 0)) {
+                       rc = mdo_declare_index_delete(env, p, name->ln_name,
+                                                     handle);
+                       if (rc != 0)
+                               return rc;
+               }
 
-        rc = mdo_declare_ref_del(env, p, handle);
-        if (rc)
-                return rc;
+               if (is_dir != 0) {
+                       rc = mdo_declare_ref_del(env, p, handle);
+                       if (rc != 0)
+                               return rc;
+               }
+       }
 
        LASSERT(ma->ma_attr.la_valid & LA_CTIME);
        la->la_ctime = la->la_mtime = ma->ma_attr.la_ctime;
@@ -1514,7 +1520,7 @@ static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd,
                        return rc;
 
                /* FIXME: need changelog for remove entry */
-               rc = mdd_declare_changelog_store(env, mdd, name, handle);
+               rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
        }
 
        return rc;
@@ -1539,8 +1545,7 @@ static bool mdd_hsm_archive_exists(const struct lu_env *env,
 
                hsm_buf = mdd_buf_get(env, NULL, 0);
                lu_buf_alloc(hsm_buf, buflen);
-               rc = mdo_xattr_get(env, obj, hsm_buf, XATTR_NAME_HSM,
-                                  mdd_object_capa(env, obj));
+               rc = mdo_xattr_get(env, obj, hsm_buf, XATTR_NAME_HSM);
                rc = lustre_buf2hsm(hsm_buf->lb_buf, rc, &ma->ma_hsm);
                lu_buf_free(hsm_buf);
                if (rc < 0)
@@ -1584,13 +1589,13 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
                        RETURN(-ENOENT);
        }
 
-       rc = mdd_la_get(env, mdd_pobj, pattr, BYPASS_CAPA);
+       rc = mdd_la_get(env, mdd_pobj, pattr);
        if (rc)
                RETURN(rc);
 
        if (likely(mdd_cobj != NULL)) {
                /* fetch cattr */
-               rc = mdd_la_get(env, mdd_cobj, cattr, BYPASS_CAPA);
+               rc = mdd_la_get(env, mdd_cobj, cattr);
                if (rc)
                        RETURN(rc);
 
@@ -1606,7 +1611,7 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
                RETURN(PTR_ERR(handle));
 
        rc = mdd_declare_unlink(env, mdd, mdd_pobj, mdd_cobj,
-                               lname, ma, handle, no_name);
+                               lname, ma, handle, no_name, is_dir);
        if (rc)
                GOTO(stop, rc);
 
@@ -1617,21 +1622,23 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
        if (likely(mdd_cobj != NULL))
                mdd_write_lock(env, mdd_cobj, MOR_TGT_CHILD);
 
-       if (likely(no_name == 0)) {
-               rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle,
-                                       mdd_object_capa(env, mdd_pobj));
+       if (likely(no_name == 0) && !OBD_FAIL_CHECK(OBD_FAIL_LFSCK_DANGLING2)) {
+               rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle);
                if (rc)
                        GOTO(cleanup, rc);
        }
 
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_MUL_REF) ||
+           OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_NAMEENTRY))
+               GOTO(cleanup, rc = 0);
+
        if (likely(mdd_cobj != NULL)) {
                rc = mdo_ref_del(env, mdd_cobj, handle);
                if (rc != 0) {
                        __mdd_index_insert_only(env, mdd_pobj,
                                                mdo2fid(mdd_cobj),
                                                mdd_object_type(mdd_cobj),
-                                               name, handle,
-                                               mdd_object_capa(env, mdd_pobj));
+                                               name, handle);
                        GOTO(cleanup, rc);
                }
 
@@ -1640,7 +1647,7 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
                        mdo_ref_del(env, mdd_cobj, handle);
 
                /* fetch updated nlink */
-               rc = mdd_la_get(env, mdd_cobj, cattr, BYPASS_CAPA);
+               rc = mdd_la_get(env, mdd_cobj, cattr);
                if (rc)
                        GOTO(cleanup, rc);
        }
@@ -1673,7 +1680,7 @@ static int mdd_unlink(const struct lu_env *env, struct md_object *pobj,
 
        /* fetch updated nlink */
        if (rc == 0)
-               rc = mdd_la_get(env, mdd_cobj, cattr, BYPASS_CAPA);
+               rc = mdd_la_get(env, mdd_cobj, cattr);
 
        /* if object is removed then we can't get its attrs, use last get */
        if (cattr->la_nlink == 0) {
@@ -1697,7 +1704,8 @@ cleanup:
 
                rc = mdd_changelog_ns_store(env, mdd,
                        is_dir ? CL_RMDIR : CL_UNLINK, cl_flags,
-                       mdd_cobj, mdd_pobj, lname, handle);
+                       mdd_cobj, mdo2fid(mdd_pobj), NULL, NULL, lname, NULL,
+                       handle);
        }
 
 stop:
@@ -1748,7 +1756,7 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
         *    striping can be specified or not
         * 2) CMD?
         */
-       rc = mdd_la_get(env, son, attr, BYPASS_CAPA);
+       rc = mdd_la_get(env, son, attr);
        if (rc)
                RETURN(rc);
 
@@ -1779,7 +1787,7 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
        if (rc)
                GOTO(stop, rc);
 
-       rc = mdd_declare_changelog_store(env, mdd, NULL, handle);
+       rc = mdd_declare_changelog_store(env, mdd, NULL, NULL, handle);
        if (rc)
                GOTO(stop, rc);
 
@@ -1788,7 +1796,7 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
                GOTO(stop, rc);
 
        rc = dt_xattr_set(env, mdd_object_child(son), buf, XATTR_NAME_LOV,
-                         0, handle, mdd_object_capa(env, son));
+                         0, handle);
 
        if (rc)
                GOTO(stop, rc);
@@ -1844,28 +1852,17 @@ static int mdd_object_initialize(const struct lu_env *env,
                                 struct lu_attr *attr, struct thandle *handle,
                                 const struct md_op_spec *spec)
 {
-        int rc;
-        ENTRY;
-
-        /*
-         * Update attributes for child.
-         *
-         * FIXME:
-         *  (1) the valid bits should be converted between Lustre and Linux;
-         *  (2) maybe, the child attributes should be set in OSD when creation.
-         */
+       int rc = 0;
+       ENTRY;
 
-       rc = mdd_attr_set_internal(env, child, attr, handle, 0);
-       /* arguments are supposed to stay the same */
        if (S_ISDIR(attr->la_mode)) {
                 /* Add "." and ".." for newly created dir */
                 mdo_ref_add(env, child, handle);
                 rc = __mdd_index_insert_only(env, child, mdo2fid(child),
-                                            S_IFDIR, dot, handle, BYPASS_CAPA);
+                                            S_IFDIR, dot, handle);
                if (rc == 0)
                        rc = __mdd_index_insert_only(env, child, pfid, S_IFDIR,
-                                                    dotdot, handle,
-                                                    BYPASS_CAPA);
+                                                    dotdot, handle);
                if (rc != 0)
                        mdo_ref_del(env, child, handle);
        }
@@ -2076,7 +2073,7 @@ static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd,
                if (rc != 0)
                        return rc;
 
-               rc = mdd_declare_links_add(env, c, handle, ldata);
+               rc = mdd_declare_links_add(env, c, handle, ldata, MLAO_IGNORE);
                if (rc)
                        return rc;
 
@@ -2086,17 +2083,10 @@ static int mdd_declare_create(const struct lu_env *env, struct mdd_device *mdd,
                if (rc)
                        return rc;
 
-               rc = mdd_declare_changelog_store(env, mdd, name, handle);
+               rc = mdd_declare_changelog_store(env, mdd, name, NULL, handle);
                if (rc)
                        return rc;
        }
-
-       /* XXX: For remote create, it should indicate the remote RPC
-        * will be sent after local transaction is finished, which
-        * is not very nice, but it will be removed once we fully support
-        * async update */
-       if (mdd_object_remote(p) && handle->th_update != NULL)
-               handle->th_update->tu_sent_after_local_trans = 1;
 out:
        return rc;
 }
@@ -2116,7 +2106,7 @@ static int mdd_acl_init(const struct lu_env *env, struct mdd_object *pobj,
 
        mdd_read_lock(env, pobj, MOR_TGT_PARENT);
        rc = mdo_xattr_get(env, pobj, def_acl_buf,
-                          XATTR_NAME_ACL_DEFAULT, BYPASS_CAPA);
+                          XATTR_NAME_ACL_DEFAULT);
        mdd_read_unlock(env, pobj);
        if (rc > 0) {
                /* If there are default ACL, fix mode/ACL by default ACL */
@@ -2180,9 +2170,11 @@ static int mdd_object_create(const struct lu_env *env, struct mdd_object *pobj,
        /* During creation, there are only a few cases we need do xattr_set to
         * create stripes.
         * 1. regular file: see comments above.
-        * 2. create striped directory with provided stripeEA.
-        * 3. create striped directory because inherit default layout from the
-        * parent. */
+        * 2. dir: inherit default striping or pool settings from parent.
+        * 3. create striped directory with provided stripeEA.
+        * 4. create striped directory because inherit default layout from the
+        * parent.
+        */
        if (spec->no_create ||
            (S_ISREG(attr->la_mode) && spec->sp_cr_flags & MDS_OPEN_HAS_EA) ||
            S_ISDIR(attr->la_mode)) {
@@ -2193,7 +2185,7 @@ static int mdd_object_create(const struct lu_env *env, struct mdd_object *pobj,
                rc = mdo_xattr_set(env, son, buf,
                                   S_ISDIR(attr->la_mode) ? XATTR_NAME_LMV :
                                                            XATTR_NAME_LOV, 0,
-                                  handle, BYPASS_CAPA);
+                                  handle);
                if (rc != 0)
                        GOTO(err_destroy, rc);
        }
@@ -2204,7 +2196,7 @@ static int mdd_object_create(const struct lu_env *env, struct mdd_object *pobj,
                /* set default acl */
                rc = mdo_xattr_set(env, son, def_acl_buf,
                                   XATTR_NAME_ACL_DEFAULT, 0,
-                                  handle, BYPASS_CAPA);
+                                  handle);
                if (rc)
                        GOTO(err_destroy, rc);
        }
@@ -2212,7 +2204,7 @@ static int mdd_object_create(const struct lu_env *env, struct mdd_object *pobj,
        if (acl_buf != NULL && acl_buf->lb_len > 0) {
                rc = mdo_xattr_set(env, son, acl_buf,
                                   XATTR_NAME_ACL_ACCESS,
-                                  0, handle, BYPASS_CAPA);
+                                  0, handle);
                if (rc)
                        GOTO(err_destroy, rc);
        }
@@ -2228,7 +2220,6 @@ static int mdd_object_create(const struct lu_env *env, struct mdd_object *pobj,
 
                buf = mdd_buf_get_const(env, target_name, sym_len);
                rc = dt->do_body_ops->dbo_write(env, dt, buf, &pos, handle,
-                                               mdd_object_capa(env, son),
                                                uc->uc_cap &
                                                CFS_CAP_SYS_RESOURCE_MASK);
 
@@ -2319,7 +2310,7 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
          *     2. insert            (__mdd_index_insert(), lookup again)
          */
 
-       rc = mdd_la_get(env, mdd_pobj, pattr, BYPASS_CAPA);
+       rc = mdd_la_get(env, mdd_pobj, pattr);
        if (rc != 0)
                RETURN(rc);
 
@@ -2346,7 +2337,7 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
        mdd_object_make_hint(env, mdd_pobj, son, attr, spec, hint);
 
        memset(ldata, 0, sizeof(*ldata));
-       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT2)) {
+       if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_BAD_PARENT)) {
                struct lu_fid tfid = *mdd_object_fid(mdd_pobj);
 
                tfid.f_oid--;
@@ -2379,8 +2370,7 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
                GOTO(out_volatile, rc);
        } else {
                rc = __mdd_index_insert(env, mdd_pobj, mdo2fid(son),
-                                       attr->la_mode, name, handle,
-                                       mdd_object_capa(env, mdd_pobj));
+                                       attr->la_mode, name, handle);
                if (rc != 0)
                        GOTO(err_created, rc);
 
@@ -2405,7 +2395,7 @@ err_insert:
                else
                        rc2 = __mdd_index_delete(env, mdd_pobj, name,
                                                 S_ISDIR(attr->la_mode),
-                                                handle, BYPASS_CAPA);
+                                                handle);
                if (rc2 != 0)
                        goto out_stop;
 
@@ -2443,7 +2433,8 @@ out_volatile:
                                S_ISDIR(attr->la_mode) ? CL_MKDIR :
                                S_ISREG(attr->la_mode) ? CL_CREATE :
                                S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD,
-                               0, son, mdd_pobj, lname, handle);
+                               0, son, mdo2fid(mdd_pobj), NULL, NULL, lname,
+                               NULL, handle);
 out_stop:
        rc2 = mdd_trans_stop(env, mdd, rc, handle);
        if (rc == 0)
@@ -2612,7 +2603,8 @@ static int mdd_declare_rename(const struct lu_env *env,
        if (rc)
                return rc;
 
-       rc = mdd_declare_links_add(env, mdd_sobj, handle, ldata);
+       rc = mdd_declare_links_add(env, mdd_sobj, handle, ldata,
+               S_ISREG(mdd_object_type(mdd_sobj)) ? MLAO_CHECK : MLAO_IGNORE);
        if (rc)
                return rc;
 
@@ -2659,7 +2651,7 @@ static int mdd_declare_rename(const struct lu_env *env,
                        return rc;
         }
 
-       rc = mdd_declare_changelog_ext_store(env, mdd, tname, sname, handle);
+       rc = mdd_declare_changelog_store(env, mdd, tname, sname, handle);
         if (rc)
                 return rc;
 
@@ -2701,21 +2693,21 @@ static int mdd_rename(const struct lu_env *env,
 
        mdd_sobj = mdd_object_find(env, mdd, lf);
 
-       rc = mdd_la_get(env, mdd_sobj, cattr, BYPASS_CAPA);
+       rc = mdd_la_get(env, mdd_sobj, cattr);
        if (rc)
                GOTO(out_pending, rc);
 
-       rc = mdd_la_get(env, mdd_spobj, pattr, BYPASS_CAPA);
+       rc = mdd_la_get(env, mdd_spobj, pattr);
        if (rc)
                GOTO(out_pending, rc);
 
        if (mdd_tobj) {
-               rc = mdd_la_get(env, mdd_tobj, tattr, BYPASS_CAPA);
+               rc = mdd_la_get(env, mdd_tobj, tattr);
                if (rc)
                        GOTO(out_pending, rc);
        }
 
-       rc = mdd_la_get(env, mdd_tpobj, tpattr, BYPASS_CAPA);
+       rc = mdd_la_get(env, mdd_tpobj, tpattr);
        if (rc)
                GOTO(out_pending, rc);
 
@@ -2752,21 +2744,18 @@ static int mdd_rename(const struct lu_env *env,
        is_dir = S_ISDIR(cattr->la_mode);
 
         /* Remove source name from source directory */
-        rc = __mdd_index_delete(env, mdd_spobj, sname, is_dir, handle,
-                                mdd_object_capa(env, mdd_spobj));
+       rc = __mdd_index_delete(env, mdd_spobj, sname, is_dir, handle);
         if (rc)
                 GOTO(cleanup, rc);
 
         /* "mv dir1 dir2" needs "dir1/.." link update */
         if (is_dir && mdd_sobj && !lu_fid_eq(spobj_fid, tpobj_fid)) {
-                rc = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle,
-                                        mdd_object_capa(env, mdd_sobj));
+               rc = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle);
                if (rc != 0)
                        GOTO(fixup_spobj2, rc);
 
                rc = __mdd_index_insert_only(env, mdd_sobj, tpobj_fid, S_IFDIR,
-                                            dotdot, handle,
-                                            mdd_object_capa(env, mdd_sobj));
+                                            dotdot, handle);
                if (rc != 0)
                         GOTO(fixup_spobj, rc);
         }
@@ -2775,8 +2764,7 @@ static int mdd_rename(const struct lu_env *env,
          * Here tobj can be remote one, so we do index_delete unconditionally
          * and -ENOENT is allowed.
          */
-        rc = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle,
-                                mdd_object_capa(env, mdd_tpobj));
+       rc = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle);
         if (rc != 0) {
                 if (mdd_tobj) {
                         /* tname might been renamed to something else */
@@ -2788,7 +2776,7 @@ static int mdd_rename(const struct lu_env *env,
 
         /* Insert new fid with target name into target dir */
        rc = __mdd_index_insert(env, mdd_tpobj, lf, cattr->la_mode,
-                               tname, handle, mdd_object_capa(env, mdd_tpobj));
+                               tname, handle);
        if (rc != 0)
                 GOTO(fixup_tpobj, rc);
 
@@ -2825,7 +2813,7 @@ static int mdd_rename(const struct lu_env *env,
                tobj_ref = 1;
 
                /* fetch updated nlink */
-               rc = mdd_la_get(env, mdd_tobj, tattr, BYPASS_CAPA);
+               rc = mdd_la_get(env, mdd_tobj, tattr);
                if (rc != 0) {
                        CERROR("%s: Failed to get nlink for tobj "
                                DFID": rc = %d\n",
@@ -2858,7 +2846,7 @@ static int mdd_rename(const struct lu_env *env,
                }
 
                /* fetch updated nlink */
-               rc = mdd_la_get(env, mdd_tobj, tattr, BYPASS_CAPA);
+               rc = mdd_la_get(env, mdd_tobj, tattr);
                if (rc != 0) {
                        CERROR("%s: Failed to get nlink for tobj "
                                DFID": rc = %d\n",
@@ -2906,8 +2894,7 @@ static int mdd_rename(const struct lu_env *env,
 
 fixup_tpobj:
         if (rc) {
-                rc2 = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle,
-                                         BYPASS_CAPA);
+               rc2 = __mdd_index_delete(env, mdd_tpobj, tname, is_dir, handle);
                 if (rc2)
                         CWARN("tp obj fix error %d\n",rc2);
 
@@ -2922,7 +2909,7 @@ fixup_tpobj:
                        rc2 = __mdd_index_insert(env, mdd_tpobj,
                                                  mdo2fid(mdd_tobj),
                                                  mdd_object_type(mdd_tobj),
-                                                 tname, handle, BYPASS_CAPA);
+                                                 tname, handle);
                        if (rc2 != 0)
                                CWARN("tp obj fix error: rc = %d\n", rc2);
                }
@@ -2930,16 +2917,14 @@ fixup_tpobj:
 
 fixup_spobj:
        if (rc && is_dir && mdd_sobj && mdd_spobj != mdd_tpobj) {
-               rc2 = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle,
-                                             BYPASS_CAPA);
-
+               rc2 = __mdd_index_delete_only(env, mdd_sobj, dotdot, handle);
                if (rc2)
                        CWARN("%s: sp obj dotdot delete error: rc = %d\n",
                               mdd2obd_dev(mdd)->obd_name, rc2);
 
 
                rc2 = __mdd_index_insert_only(env, mdd_sobj, spobj_fid, S_IFDIR,
-                                             dotdot, handle, BYPASS_CAPA);
+                                             dotdot, handle);
                if (rc2 != 0)
                        CWARN("%s: sp obj dotdot insert error: rc = %d\n",
                              mdd2obd_dev(mdd)->obd_name, rc2);
@@ -2949,7 +2934,7 @@ fixup_spobj2:
        if (rc != 0) {
                rc2 = __mdd_index_insert(env, mdd_spobj, lf,
                                         mdd_object_type(mdd_sobj), sname,
-                                        handle, BYPASS_CAPA);
+                                        handle);
                if (rc2 != 0)
                        CWARN("sp obj fix error: rc = %d\n", rc2);
        }
@@ -2960,10 +2945,9 @@ cleanup:
 
 cleanup_unlocked:
        if (rc == 0)
-               rc = mdd_changelog_ext_ns_store(env, mdd, CL_RENAME, cl_flags,
-                                               mdd_tobj, tpobj_fid, lf,
-                                               spobj_fid, ltname, lsname,
-                                               handle);
+               rc = mdd_changelog_ns_store(env, mdd, CL_RENAME, cl_flags,
+                                           mdd_tobj, tpobj_fid, lf, spobj_fid,
+                                           ltname, lsname, handle);
 
 stop:
        mdd_trans_stop(env, mdd, rc, handle);
@@ -2985,7 +2969,7 @@ static int mdd_linkea_update_child_internal(const struct lu_env *env,
                                            bool declare)
 {
        struct mdd_thread_info  *info = mdd_env_info(env);
-       struct linkea_data      ldata = {0};
+       struct linkea_data      ldata = { NULL };
        struct lu_buf           *buf = &info->mti_link_buf;
        int                     count;
        int                     rc = 0;
@@ -3030,7 +3014,8 @@ static int mdd_linkea_update_child_internal(const struct lu_env *env,
                linkea_entry_pack(ldata.ld_lee, &lname,
                                  mdd_object_fid(parent));
                if (declare)
-                       rc = mdd_declare_links_add(env, child, handle, &ldata);
+                       rc = mdd_declare_links_add(env, child, handle, &ldata,
+                                                  MLAO_IGNORE);
                else
                        rc = mdd_links_write(env, child, &ldata, handle);
                break;
@@ -3079,14 +3064,6 @@ static int mdd_update_linkea_internal(const struct lu_env *env,
                RETURN(rc);
        }
 
-       if (declare)
-               rc = mdd_declare_links_add(env, mdd_tobj, handle, ldata);
-       else
-               rc = mdd_links_write(env, mdd_tobj, ldata, handle);
-
-       if (rc != 0)
-               RETURN(rc);
-
        /* If it is mulitple links file, we need update the name entry for
         * all parent */
        LASSERT(ldata->ld_leh != NULL);
@@ -3153,16 +3130,14 @@ static int mdd_update_linkea_internal(const struct lu_env *env,
                                GOTO(next_put, rc);
                } else {
                        rc = __mdd_index_delete(env, pobj, lname.ln_name,
-                                               0, handle,
-                                               mdd_object_capa(env, pobj));
+                                               0, handle);
                        if (rc)
                                GOTO(next_put, rc);
 
                        rc = __mdd_index_insert(env, pobj,
                                        mdd_object_fid(mdd_tobj),
                                        mdd_object_type(mdd_tobj),
-                                       lname.ln_name, handle,
-                                       mdd_object_capa(env, pobj));
+                                       lname.ln_name, handle);
                        if (rc != 0)
                                GOTO(next_put, rc);
 
@@ -3202,8 +3177,7 @@ static int mdd_migrate_xattrs(const struct lu_env *env,
        int                     rc;
 
        /* retrieve xattr list from the old object */
-       list_xsize = mdo_xattr_list(env, mdd_sobj, &LU_BUF_NULL,
-                                   mdd_object_capa(env, mdd_sobj));
+       list_xsize = mdo_xattr_list(env, mdd_sobj, &LU_BUF_NULL);
        if (list_xsize == -ENODATA)
                return 0;
 
@@ -3216,8 +3190,7 @@ static int mdd_migrate_xattrs(const struct lu_env *env,
 
        list_xbuf.lb_buf = info->mti_big_buf.lb_buf;
        list_xbuf.lb_len = list_xsize;
-       rc = mdo_xattr_list(env, mdd_sobj, &list_xbuf,
-                           mdd_object_capa(env, mdd_sobj));
+       rc = mdo_xattr_list(env, mdd_sobj, &list_xbuf);
        if (rc < 0)
                return rc;
        rc = 0;
@@ -3235,9 +3208,7 @@ static int mdd_migrate_xattrs(const struct lu_env *env,
                    !S_ISDIR(lu_object_attr(&mdd_sobj->mod_obj.mo_lu)))
                        goto next;
 
-               xsize = mdo_xattr_get(env, mdd_sobj, &LU_BUF_NULL,
-                                     xname,
-                                     mdd_object_capa(env, mdd_sobj));
+               xsize = mdo_xattr_get(env, mdd_sobj, &LU_BUF_NULL, xname);
                if (xsize == -ENODATA)
                        goto next;
                if (xsize < 0)
@@ -3249,8 +3220,7 @@ static int mdd_migrate_xattrs(const struct lu_env *env,
 
                xbuf.lb_len = xsize;
                xbuf.lb_buf = info->mti_link_buf.lb_buf;
-               rc = mdo_xattr_get(env, mdd_sobj, &xbuf, xname,
-                                  mdd_object_capa(env, mdd_sobj));
+               rc = mdo_xattr_get(env, mdd_sobj, &xbuf, xname);
                if (rc == -ENODATA)
                        goto next;
                if (rc < 0)
@@ -3272,8 +3242,7 @@ static int mdd_migrate_xattrs(const struct lu_env *env,
                if (rc != 0)
                        GOTO(stop_trans, rc);
 
-               rc = mdo_xattr_set(env, mdd_tobj, &xbuf, xname, 0, handle,
-                                  mdd_object_capa(env, mdd_sobj));
+               rc = mdo_xattr_set(env, mdd_tobj, &xbuf, xname, 0, handle);
                if (rc == -EEXIST)
                        GOTO(stop_trans, rc = 0);
 
@@ -3298,6 +3267,7 @@ static int mdd_declare_migrate_create(const struct lu_env *env,
                                      struct md_op_spec *spec,
                                      struct lu_attr *la,
                                      union lmv_mds_md *mgr_ea,
+                                     struct linkea_data *ldata,
                                      struct thandle *handle)
 {
        struct lu_attr          *la_flag = MDD_ENV_VAR(env, la_for_fix);
@@ -3325,6 +3295,11 @@ static int mdd_declare_migrate_create(const struct lu_env *env,
                                             buf, 0, handle);
                if (rc != 0)
                        return rc;
+       } else if (S_ISDIR(la->la_mode)) {
+               rc = mdd_declare_links_add(env, mdd_tobj, handle, ldata,
+                                          MLAO_IGNORE);
+               if (rc != 0)
+                       return rc;
        }
 
        if (spec->u.sp_ea.eadata != NULL && spec->u.sp_ea.eadatalen != 0) {
@@ -3345,7 +3320,6 @@ static int mdd_declare_migrate_create(const struct lu_env *env,
 
        la_flag->la_valid = LA_FLAGS;
        la_flag->la_flags = la->la_flags | LUSTRE_IMMUTABLE_FL;
-       mdd_flags_xlate(mdd_sobj, la_flag->la_flags);
        rc = mdo_declare_attr_set(env, mdd_sobj, la_flag, handle);
 
        return rc;
@@ -3355,19 +3329,21 @@ static int mdd_migrate_create(const struct lu_env *env,
                              struct mdd_object *mdd_pobj,
                              struct mdd_object *mdd_sobj,
                              struct mdd_object *mdd_tobj,
+                             const struct lu_name *lname,
                              struct lu_attr *la)
 {
        struct mdd_thread_info  *info = mdd_env_info(env);
        struct mdd_device       *mdd = mdo2mdd(&mdd_sobj->mod_obj);
        struct md_op_spec       *spec = &info->mti_spec;
-       struct lu_buf           lmm_buf = { 0 };
-       struct lu_buf           link_buf = { 0 };
+       struct lu_buf           lmm_buf = { NULL };
+       struct lu_buf           link_buf = { NULL };
        const struct lu_buf     *buf;
        struct thandle          *handle;
        struct lmv_mds_md_v1    *mgr_ea;
        struct lu_attr          *la_flag = MDD_ENV_VAR(env, la_for_fix);
        struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
        int                     mgr_easize;
+       struct linkea_data      *ldata = &mdd_env_info(env)->mti_link_data;
        int                     rc;
        ENTRY;
 
@@ -3381,6 +3357,7 @@ static int mdd_migrate_create(const struct lu_env *env,
                                la->la_size + 1);
                link_buf = *buf;
                link_buf.lb_len = la->la_size + 1;
+               memset(link_buf.lb_buf, 0, link_buf.lb_len);
                rc = mdd_readlink(env, &mdd_sobj->mod_obj, &link_buf);
                if (rc <= 0) {
                        rc = rc != 0 ? rc : -EFAULT;
@@ -3400,6 +3377,10 @@ static int mdd_migrate_create(const struct lu_env *env,
                        spec->u.sp_ea.eadatalen = lmm_buf.lb_len;
                        spec->sp_cr_flags |= MDS_OPEN_HAS_EA;
                }
+       } else if (S_ISDIR(la->la_mode)) {
+               rc = mdd_links_read(env, mdd_sobj, ldata);
+               if (rc < 0 && rc != -ENODATA)
+                       RETURN(rc);
        }
 
        mgr_ea = (struct lmv_mds_md_v1 *)info->mti_xattr_buf;
@@ -3424,7 +3405,7 @@ static int mdd_migrate_create(const struct lu_env *env,
        rc = mdd_declare_migrate_create(env, mdd_pobj, mdd_sobj, mdd_tobj,
                                        spec, la,
                                        (union lmv_mds_md *)info->mti_xattr_buf,
-                                       handle);
+                                       ldata, handle);
        if (rc != 0)
                GOTO(stop_trans, rc);
 
@@ -3438,13 +3419,18 @@ static int mdd_migrate_create(const struct lu_env *env,
        if (rc != 0)
                GOTO(stop_trans, rc);
 
+       if (S_ISDIR(la->la_mode)) {
+               rc = mdd_links_write(env, mdd_tobj, ldata, handle);
+               if (rc != 0)
+                       GOTO(stop_trans, rc);
+       }
+
        /* Set MIGRATE EA on the source inode, so once the migration needs
         * to be re-done during failover, the re-do process can locate the
         * target object which is already being created. */
        mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_V1);
        buf = mdd_buf_get_const(env, mgr_ea, mgr_easize);
-       rc = mdo_xattr_set(env, mdd_sobj, buf, XATTR_NAME_LMV, 0,
-                          handle, mdd_object_capa(env, mdd_sobj));
+       rc = mdo_xattr_set(env, mdd_sobj, buf, XATTR_NAME_LMV, 0, handle);
        if (rc != 0)
                GOTO(stop_trans, rc);
 
@@ -3455,9 +3441,7 @@ static int mdd_migrate_create(const struct lu_env *env,
         * flag and approve the migration */
        la_flag->la_valid = LA_FLAGS;
        la_flag->la_flags = la->la_flags | LUSTRE_IMMUTABLE_FL;
-       mdd_flags_xlate(mdd_sobj, la_flag->la_flags);
-       rc = mdo_attr_set(env, mdd_sobj, la_flag, handle,
-                         mdd_object_capa(env, mdd_sobj));
+       rc = mdo_attr_set(env, mdd_sobj, la_flag, handle);
 stop_trans:
        if (handle != NULL)
                mdd_trans_stop(env, mdd, rc, handle);
@@ -3492,8 +3476,7 @@ static int mdd_migrate_entries(const struct lu_env *env,
         * iterate directories
         */
        iops = &next->do_index_ops->dio_it;
-       it = iops->init(env, next, LUDA_FID | LUDA_TYPE,
-                       mdd_object_capa(env, mdd_sobj));
+       it = iops->init(env, next, LUDA_FID | LUDA_TYPE);
        if (IS_ERR(it))
                GOTO(out_ent, rc = PTR_ERR(it));
 
@@ -3552,8 +3535,7 @@ static int mdd_migrate_entries(const struct lu_env *env,
                        struct lu_fid *fid = &mdd_env_info(env)->mti_fid2;
 
                        rc = dt_lookup(env, dt_tobj, (struct dt_rec *)fid,
-                                      (struct dt_key *)name,
-                                      mdd_object_capa(env, mdd_tobj));
+                                      (struct dt_key *)name);
                        if (unlikely(rc == 0))
                                target_exist = true;
                }
@@ -3620,34 +3602,24 @@ static int mdd_migrate_entries(const struct lu_env *env,
                if (likely(!target_exist)) {
                        rc = __mdd_index_insert(env, mdd_tobj, &ent->lde_fid,
                                                mdd_object_type(child),
-                                               name, handle,
-                                               mdd_object_capa(env, mdd_tobj));
+                                               name, handle);
                        if (rc != 0)
                                GOTO(out_put, rc);
-
-                       if (is_dir) {
-                               rc = mdo_ref_add(env, mdd_tobj, handle);
-                               if (rc != 0)
-                                       GOTO(out_put, rc);
-
-                       }
                }
 
-               rc = __mdd_index_delete(env, mdd_sobj, name, is_dir, handle,
-                                       mdd_object_capa(env, mdd_sobj));
+               rc = __mdd_index_delete(env, mdd_sobj, name, is_dir, handle);
                if (rc != 0)
                        GOTO(out_put, rc);
 
                if (is_dir) {
-                       rc = __mdd_index_delete_only(env, child, dotdot, handle,
-                                                  mdd_object_capa(env, child));
+                       rc = __mdd_index_delete_only(env, child, dotdot,
+                                                    handle);
                        if (rc != 0)
                                GOTO(out_put, rc);
 
                        rc = __mdd_index_insert_only(env, child,
                                         mdd_object_fid(mdd_tobj), S_IFDIR,
-                                        dotdot, handle,
-                                        mdd_object_capa(env, child));
+                                        dotdot, handle);
                        if (rc != 0)
                                GOTO(out_put, rc);
                }
@@ -3713,7 +3685,6 @@ static int mdd_declare_migrate_update_name(const struct lu_env *env,
        /* Revert IMMUTABLE flag */
        la_flag->la_valid = LA_FLAGS;
        la_flag->la_flags = la->la_flags & ~LUSTRE_IMMUTABLE_FL;
-       mdd_flags_xlate(mdd_sobj, la_flag->la_flags);
        rc = mdo_declare_attr_set(env, mdd_sobj, la_flag, handle);
        if (rc != 0)
                return rc;
@@ -3748,6 +3719,10 @@ static int mdd_declare_migrate_update_name(const struct lu_env *env,
        if (rc != 0)
                return rc;
 
+       rc = mdd_declare_links_add(env, mdd_tobj, handle, NULL, MLAO_IGNORE);
+       if (rc != 0)
+               return rc;
+
        if (S_ISDIR(mdd_object_type(mdd_sobj))) {
                rc = mdo_declare_ref_add(env, mdd_pobj, handle);
                if (rc != 0)
@@ -3801,7 +3776,7 @@ static int mdd_migrate_update_name(const struct lu_env *env,
        p_la->la_ctime = p_la->la_mtime = ma->ma_attr.la_ctime;
        p_la->la_valid = LA_CTIME;
 
-       rc = mdd_la_get(env, mdd_sobj, so_attr, mdd_object_capa(env, mdd_sobj));
+       rc = mdd_la_get(env, mdd_sobj, so_attr);
        if (rc != 0)
                RETURN(rc);
 
@@ -3832,15 +3807,12 @@ static int mdd_migrate_update_name(const struct lu_env *env,
        /* Revert IMMUTABLE flag */
        la_flag->la_valid = LA_FLAGS;
        la_flag->la_flags = so_attr->la_flags & ~LUSTRE_IMMUTABLE_FL;
-       mdd_flags_xlate(mdd_sobj, la_flag->la_flags);
-       rc = mdo_attr_set(env, mdd_sobj, la_flag, handle,
-                         mdd_object_capa(env, mdd_pobj));
+       rc = mdo_attr_set(env, mdd_sobj, la_flag, handle);
        if (rc != 0)
                GOTO(stop_trans, rc);
 
        /* Remove source name from source directory */
-       rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle,
-                               mdd_object_capa(env, mdd_pobj));
+       rc = __mdd_index_delete(env, mdd_pobj, name, is_dir, handle);
        if (rc != 0)
                GOTO(stop_trans, rc);
 
@@ -3852,8 +3824,7 @@ static int mdd_migrate_update_name(const struct lu_env *env,
        if (S_ISREG(so_attr->la_mode)) {
                if (so_attr->la_nlink == 1) {
                        rc = mdo_xattr_del(env, mdd_sobj, XATTR_NAME_LOV,
-                                          handle,
-                                          mdd_object_capa(env, mdd_sobj));
+                                          handle);
                        if (rc != 0 && rc != -ENODATA)
                                GOTO(stop_trans, rc);
                }
@@ -3861,8 +3832,7 @@ static int mdd_migrate_update_name(const struct lu_env *env,
 
        /* Insert new fid with target name into target dir */
        rc = __mdd_index_insert(env, mdd_pobj, mdd_object_fid(mdd_tobj),
-                               mdd_object_type(mdd_tobj), name,
-                               handle, mdd_object_capa(env, mdd_pobj));
+                               mdd_object_type(mdd_tobj), name, handle);
        if (rc != 0)
                GOTO(stop_trans, rc);
 
@@ -3877,8 +3847,7 @@ static int mdd_migrate_update_name(const struct lu_env *env,
                mdo_ref_del(env, mdd_sobj, handle);
 
        /* Get the attr again after ref_del */
-       rc = mdd_la_get(env, mdd_sobj, so_attr,
-                       mdd_object_capa(env, mdd_sobj));
+       rc = mdd_la_get(env, mdd_sobj, so_attr);
        if (rc != 0)
                GOTO(out_unlock, rc);
 
@@ -3929,8 +3898,7 @@ static int mdd_migrate_sanity_check(const struct lu_env *env,
        if (mgr_buf->lb_buf == NULL)
                RETURN(-ENOMEM);
 
-       rc = mdo_xattr_get(env, sobj, mgr_buf, XATTR_NAME_LMV,
-                          mdd_object_capa(env, sobj));
+       rc = mdo_xattr_get(env, sobj, mgr_buf, XATTR_NAME_LMV);
        if (rc > 0) {
                union lmv_mds_md *lmm = mgr_buf->lb_buf;
 
@@ -3943,7 +3911,6 @@ static int mdd_migrate_sanity_check(const struct lu_env *env,
                        struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
 
                        sattr->la_flags &= ~LUSTRE_IMMUTABLE_FL;
-                       sobj->mod_flags &= ~IMMUTE_OBJ;
                        CDEBUG(D_HA, "%s: "DFID" override IMMUTE FLAG\n",
                               mdd2obd_dev(mdd)->obd_name,
                               PFID(mdd_object_fid(sobj)));
@@ -4038,11 +4005,11 @@ static int mdd_migrate(const struct lu_env *env, struct md_object *pobj,
        }
        mdd_read_unlock(env, mdd_sobj);
 
-       rc = mdd_la_get(env, mdd_sobj, so_attr, mdd_object_capa(env, mdd_sobj));
+       rc = mdd_la_get(env, mdd_sobj, so_attr);
        if (rc != 0)
                GOTO(put, rc);
 
-       rc = mdd_la_get(env, mdd_pobj, pattr, BYPASS_CAPA);
+       rc = mdd_la_get(env, mdd_pobj, pattr);
        if (rc != 0)
                GOTO(put, rc);
 
@@ -4078,7 +4045,7 @@ static int mdd_migrate(const struct lu_env *env, struct md_object *pobj,
        mdd_tobj = md2mdd_obj(tobj);
        if (!mdd_object_exists(mdd_tobj)) {
                rc = mdd_migrate_create(env, mdd_pobj, mdd_sobj, mdd_tobj,
-                                       so_attr);
+                                       lname, so_attr);
                if (rc != 0)
                        GOTO(put, rc);
        }
@@ -4096,6 +4063,8 @@ static int mdd_migrate(const struct lu_env *env, struct md_object *pobj,
                if (unlikely(OBD_FAIL_CHECK_RESET(OBD_FAIL_MIGRATE_NET_REP,
                                                  OBD_FAIL_MDS_REINT_NET_REP)))
                        GOTO(put, rc = 0);
+       } else {
+               OBD_FAIL_TIMEOUT(OBD_FAIL_MIGRATE_DELAY, cfs_fail_val);
        }
 
        /* step 4: update name entry to the new object */