Whamcloud - gitweb
LU-4690 osp: some cleanup for patch 9511
[fs/lustre-release.git] / lustre / mdd / mdd_dir.c
index 2b57407..d1009a3 100644 (file)
@@ -57,6 +57,17 @@ static struct lu_name lname_dotdot = {
         sizeof(dotdot) - 1
 };
 
+static inline int
+mdd_name_check(struct mdd_device *m, const struct lu_name *ln)
+{
+       if (!lu_name_is_valid(ln))
+               return -EINVAL;
+       else if (ln->ln_namelen > m->mdd_dt_conf.ddp_max_name_len)
+               return -ENAMETOOLONG;
+       else
+               return 0;
+}
+
 /* Get FID from name and parent */
 static int
 __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
@@ -81,10 +92,6 @@ __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
                RETURN(-ESTALE);
        }
 
-       /* The common filename length check. */
-       if (unlikely(lname->ln_namelen > m->mdd_dt_conf.ddp_max_name_len))
-               RETURN(-ENAMETOOLONG);
-
        rc = mdd_permission_internal_locked(env, mdd_obj, pattr, mask,
                                            MOR_TGT_PARENT);
        if (rc)
@@ -253,39 +260,39 @@ int mdd_is_subdir(const struct lu_env *env, struct md_object *mo,
 static int mdd_dir_is_empty(const struct lu_env *env,
                             struct mdd_object *dir)
 {
-        struct dt_it     *it;
-        struct dt_object *obj;
-        const struct dt_it_ops *iops;
-        int result;
-        ENTRY;
+       struct dt_it     *it;
+       struct dt_object *obj;
+       const struct dt_it_ops *iops;
+       int result;
+       ENTRY;
 
-        obj = mdd_object_child(dir);
-        if (!dt_try_as_dir(env, obj))
-                RETURN(-ENOTDIR);
-
-        iops = &obj->do_index_ops->dio_it;
-        it = iops->init(env, obj, LUDA_64BITHASH, BYPASS_CAPA);
-        if (!IS_ERR(it)) {
-                result = iops->get(env, it, (const void *)"");
-                if (result > 0) {
-                        int i;
-                        for (result = 0, i = 0; result == 0 && i < 3; ++i)
-                                result = iops->next(env, it);
-                        if (result == 0)
-                                result = -ENOTEMPTY;
-                        else if (result == +1)
-                                result = 0;
-                } else if (result == 0)
-                        /*
-                         * Huh? Index contains no zero key?
-                         */
-                        result = -EIO;
-
-                iops->put(env, it);
-                iops->fini(env, it);
-        } else
-                result = PTR_ERR(it);
-        RETURN(result);
+       obj = mdd_object_child(dir);
+       if (!dt_try_as_dir(env, obj))
+               RETURN(-ENOTDIR);
+
+       iops = &obj->do_index_ops->dio_it;
+       it = iops->init(env, obj, LUDA_64BITHASH, BYPASS_CAPA);
+       if (!IS_ERR(it)) {
+               result = iops->get(env, it, (const struct dt_key *)"");
+               if (result > 0) {
+                       int i;
+                       for (result = 0, i = 0; result == 0 && i < 3; ++i)
+                               result = iops->next(env, it);
+                       if (result == 0)
+                               result = -ENOTEMPTY;
+                       else if (result == 1)
+                               result = 0;
+               } else if (result == 0)
+                       /*
+                        * Huh? Index contains no zero key?
+                        */
+                       result = -EIO;
+
+               iops->put(env, it);
+               iops->fini(env, it);
+       } else
+               result = PTR_ERR(it);
+       RETURN(result);
 }
 
 static int __mdd_may_link(const struct lu_env *env, struct mdd_object *obj,
@@ -314,8 +321,10 @@ static int __mdd_may_link(const struct lu_env *env, struct mdd_object *obj,
  */
 int mdd_may_create(const struct lu_env *env,
                   struct mdd_object *pobj, const struct lu_attr *pattr,
-                  struct mdd_object *cobj, int check_perm, int check_nlink)
+                  struct mdd_object *cobj, bool check_perm, bool check_nlink)
 {
+       struct mdd_thread_info *info = mdd_env_info(env);
+       struct lu_buf   *xbuf;
        int rc = 0;
        ENTRY;
 
@@ -325,6 +334,19 @@ int mdd_may_create(const struct lu_env *env,
        if (mdd_is_dead_obj(pobj))
                RETURN(-ENOENT);
 
+       /* 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));
+       if (unlikely(rc > 0)) {
+               struct lmv_mds_md_v1  *lmv1 = xbuf->lb_buf;
+
+               if (le32_to_cpu(lmv1->lmv_magic) == LMV_MAGIC_STRIPE &&
+                   le32_to_cpu(lmv1->lmv_hash_type) & LMV_HASH_FLAG_DEAD)
+                       RETURN(-ESTALE);
+       }
+       rc = 0;
+
        if (check_perm)
                rc = mdd_permission_internal_locked(env, pobj, pattr,
                                                    MAY_WRITE | MAY_EXEC,
@@ -498,8 +520,9 @@ static int mdd_link_sanity_check(const struct lu_env *env,
                 RETURN(-ESTALE);
 
         /* Local ops, no lookup before link, check filename length here. */
-        if (lname && (lname->ln_namelen > m->mdd_dt_conf.ddp_max_name_len))
-                RETURN(-ENAMETOOLONG);
+       rc = mdd_name_check(m, lname);
+       if (rc < 0)
+               RETURN(rc);
 
         if (mdd_is_immutable(src_obj) || mdd_is_append(src_obj))
                 RETURN(-EPERM);
@@ -509,7 +532,7 @@ static int mdd_link_sanity_check(const struct lu_env *env,
 
        LASSERT(src_obj != tgt_obj);
        if (tgt_obj) {
-               rc = mdd_may_create(env, tgt_obj, tattr, NULL, 1, 0);
+               rc = mdd_may_create(env, tgt_obj, tattr, NULL, true, false);
                if (rc)
                        RETURN(rc);
        }
@@ -700,7 +723,7 @@ int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
        if (ctxt == NULL)
                return -ENXIO;
 
-       rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, NULL, th);
+       rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, th);
        llog_ctxt_put(ctxt);
        if (rc > 0)
                rc = 0;
@@ -714,9 +737,9 @@ int mdd_changelog_store(const struct lu_env *env, struct mdd_device *mdd,
  *             this will hopefully be fixed in llog rewrite
  * \retval 0 ok
  */
-int mdd_changelog_ext_store(const struct lu_env *env, struct mdd_device *mdd,
-                           struct llog_changelog_ext_rec *rec,
-                           struct thandle *th)
+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;
@@ -739,7 +762,7 @@ int mdd_changelog_ext_store(const struct lu_env *env, struct mdd_device *mdd,
                return -ENXIO;
 
        /* nested journal transaction */
-       rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, NULL, th);
+       rc = llog_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL, th);
        llog_ctxt_put(ctxt);
        if (rc > 0)
                rc = 0;
@@ -1315,17 +1338,50 @@ out_pending:
         return rc;
 }
 
+static int mdd_mark_dead_object(const struct lu_env *env,
+                               struct mdd_object *obj, struct thandle *handle,
+                               bool declare)
+{
+       struct lu_attr *attr = MDD_ENV_VAR(env, la_for_start);
+       int rc;
+
+       if (!declare)
+               obj->mod_flags |= DEAD_OBJ;
+
+       if (!S_ISDIR(mdd_object_type(obj)))
+               return 0;
+
+       attr->la_valid = LA_FLAGS;
+       attr->la_flags = LUSTRE_SLAVE_DEAD_FL;
+
+       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));
+
+       return rc;
+}
+
 static int mdd_declare_finish_unlink(const struct lu_env *env,
                                     struct mdd_object *obj,
                                     struct thandle *handle)
 {
        int     rc;
 
+       rc = mdd_mark_dead_object(env, obj, handle, true);
+       if (rc != 0)
+               return rc;
+
        rc = orph_declare_index_insert(env, obj, mdd_object_type(obj), handle);
-       if (rc)
+       if (rc != 0)
+               return rc;
+
+       rc = mdo_declare_destroy(env, obj, handle);
+       if (rc != 0)
                return rc;
 
-       return mdo_declare_destroy(env, obj, handle);
+       return mdd_declare_links_del(env, obj, handle);
 }
 
 /* caller should take a lock before calling */
@@ -1342,7 +1398,9 @@ int mdd_finish_unlink(const struct lu_env *env,
         LASSERT(mdd_write_locked(env, obj) != 0);
 
        if (ma->ma_attr.la_nlink == 0 || is_dir) {
-                obj->mod_flags |= DEAD_OBJ;
+               rc = mdd_mark_dead_object(env, obj, th, false);
+               if (rc != 0)
+                       RETURN(rc);
 
                 /* add new orphan and the object
                  * will be deleted during mdd_close() */
@@ -1430,10 +1488,6 @@ static int mdd_declare_unlink(const struct lu_env *env, struct mdd_device *mdd,
                if (rc)
                        return rc;
 
-               rc = mdd_declare_links_del(env, c, handle);
-               if (rc != 0)
-                       return rc;
-
                /* FIXME: need changelog for remove entry */
                rc = mdd_declare_changelog_store(env, mdd, name, handle);
        }
@@ -1794,12 +1848,12 @@ static int mdd_create_sanity_check(const struct lu_env *env,
                                   struct lu_attr *cattr,
                                    struct md_op_spec *spec)
 {
-        struct mdd_thread_info *info = mdd_env_info(env);
-        struct lu_fid     *fid       = &info->mti_fid;
-        struct mdd_object *obj       = md2mdd_obj(pobj);
-        struct mdd_device *m         = mdo2mdd(pobj);
-        int rc;
-        ENTRY;
+       struct mdd_thread_info *info = mdd_env_info(env);
+       struct lu_fid     *fid       = &info->mti_fid;
+       struct mdd_object *obj       = md2mdd_obj(pobj);
+       struct mdd_device *m         = mdo2mdd(pobj);
+       int rc;
+       ENTRY;
 
         /* EEXIST check */
         if (mdd_is_dead_obj(obj))
@@ -1818,17 +1872,11 @@ static int mdd_create_sanity_check(const struct lu_env *env,
                  */
                rc = __mdd_lookup(env, pobj, pattr, lname, fid,
                                  MAY_WRITE | MAY_EXEC);
-                if (rc != -ENOENT)
-                        RETURN(rc ? : -EEXIST);
-        } else {
-               /*
-                * Check WRITE permission for the parent.
-                * EXEC permission have been checked
-                * when lookup before create already.
-                */
-               rc = mdd_permission_internal_locked(env, obj, pattr, MAY_WRITE,
-                                                   MOR_TGT_PARENT);
-               if (rc)
+               if (rc != -ENOENT)
+                       RETURN(rc ? : -EEXIST);
+       } else {
+               rc = mdd_may_create(env, obj, pattr, NULL, true, false);
+               if (rc != 0)
                        RETURN(rc);
        }
 
@@ -1841,6 +1889,10 @@ static int mdd_create_sanity_check(const struct lu_env *env,
                }
        }
 
+       rc = mdd_name_check(m, lname);
+       if (rc < 0)
+               RETURN(rc);
+
        switch (cattr->la_mode & S_IFMT) {
         case S_IFLNK: {
                 unsigned int symlen = strlen(spec->u.sp_symname) + 1;
@@ -2055,6 +2107,43 @@ static int mdd_object_create(const struct lu_env *env, struct mdd_object *pobj,
        if (rc)
                GOTO(unlock, rc);
 
+       /* Note: In DNE phase I, for striped dir, though sub-stripes will be
+        * created in declare phase, they also needs to be added to master
+        * object as sub-directory entry. So it has to initialize the master
+        * object, then set dir striped EA.(in mdo_xattr_set) */
+       rc = mdd_object_initialize(env, mdo2fid(pobj), son, attr, handle,
+                                  spec);
+       if (rc != 0)
+               GOTO(err_destroy, rc);
+
+       /*
+        * in case of replay we just set LOVEA provided by the client
+        * XXX: I think it would be interesting to try "old" way where
+        *      MDT calls this xattr_set(LOV) in a different transaction.
+        *      probably this way we code can be made better.
+        */
+
+       /* 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. */
+       if (spec->no_create ||
+           (S_ISREG(attr->la_mode) && spec->sp_cr_flags & MDS_OPEN_HAS_EA) ||
+           S_ISDIR(attr->la_mode)) {
+               const struct lu_buf *buf;
+
+               buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
+                                       spec->u.sp_ea.eadatalen);
+               rc = mdo_xattr_set(env, son, buf,
+                                  S_ISDIR(attr->la_mode) ? XATTR_NAME_LMV :
+                                                           XATTR_NAME_LOV, 0,
+                                  handle, BYPASS_CAPA);
+               if (rc != 0)
+                       GOTO(err_destroy, rc);
+       }
+
 #ifdef CONFIG_FS_POSIX_ACL
        if (def_acl_buf != NULL && def_acl_buf->lb_len > 0 &&
            S_ISDIR(attr->la_mode)) {
@@ -2075,29 +2164,6 @@ static int mdd_object_create(const struct lu_env *env, struct mdd_object *pobj,
        }
 #endif
 
-       rc = mdd_object_initialize(env, mdo2fid(pobj), son, attr, handle,
-                                  spec);
-       if (rc != 0)
-               GOTO(err_destroy, rc);
-
-       /*
-        * in case of replay we just set LOVEA provided by the client
-        * XXX: I think it would be interesting to try "old" way where
-        *      MDT calls this xattr_set(LOV) in a different transaction.
-        *      probably this way we code can be made better.
-        */
-       if (spec->no_create || (spec->sp_cr_flags & MDS_OPEN_HAS_EA &&
-                               S_ISREG(attr->la_mode))) {
-               const struct lu_buf *buf;
-
-               buf = mdd_buf_get_const(env, spec->u.sp_ea.eadata,
-                               spec->u.sp_ea.eadatalen);
-               rc = mdo_xattr_set(env, son, buf, XATTR_NAME_LOV, 0, handle,
-                                  BYPASS_CAPA);
-               if (rc != 0)
-                       GOTO(err_destroy, rc);
-       }
-
        if (S_ISLNK(attr->la_mode)) {
                struct lu_ucred  *uc = lu_ucred_assert(env);
                struct dt_object *dt = mdd_object_child(son);
@@ -2160,6 +2226,7 @@ static int mdd_create(const struct lu_env *env, struct md_object *pobj,
        const char              *name = lname->ln_name;
        struct dt_allocation_hint *hint = &mdd_env_info(env)->mti_hint;
        int                      rc;
+       int                      rc2;
        ENTRY;
 
         /*
@@ -2310,7 +2377,9 @@ err_created:
                        S_ISLNK(attr->la_mode) ? CL_SOFTLINK : CL_MKNOD,
                        0, son, mdd_pobj, lname, handle);
 out_stop:
-        mdd_trans_stop(env, mdd, rc, handle);
+       rc2 = mdd_trans_stop(env, mdd, rc, handle);
+       if (rc == 0)
+               rc = rc2;
 out_free:
        if (ldata->ld_buf && ldata->ld_buf->lb_len > OBD_ALLOC_BIG)
                /* if we vmalloced a large buffer drop it */
@@ -2396,7 +2465,7 @@ static int mdd_rename_sanity_check(const struct lu_env *env,
         * So check may_create, but not check may_unlink. */
        if (!tobj)
                rc = mdd_may_create(env, tgt_pobj, tpattr, NULL,
-                                   (src_pobj != tgt_pobj), 0);
+                                   (src_pobj != tgt_pobj), false);
        else
                rc = mdd_may_delete(env, tgt_pobj, tpattr, tobj, tattr, cattr,
                                    (src_pobj != tgt_pobj), 1);
@@ -2515,10 +2584,6 @@ static int mdd_declare_rename(const struct lu_env *env,
                if (rc)
                        return rc;
 
-               rc = mdd_declare_links_del(env, mdd_tobj, handle);
-               if (rc)
-                       return rc;
-
                rc = mdd_declare_finish_unlink(env, mdd_tobj, handle);
                if (rc)
                        return rc;
@@ -2589,6 +2654,10 @@ static int mdd_rename(const struct lu_env *env,
        if (rc)
                GOTO(out_pending, rc);
 
+       rc = mdd_name_check(mdd, ltname);
+       if (rc < 0)
+               GOTO(out_pending, rc);
+
         handle = mdd_trans_create(env, mdd);
         if (IS_ERR(handle))
                 GOTO(out_pending, rc = PTR_ERR(handle));
@@ -2708,7 +2777,7 @@ static int mdd_rename(const struct lu_env *env,
                ma->ma_attr = *tattr;
                ma->ma_valid |= MA_INODE;
                rc = mdd_finish_unlink(env, mdd_tobj, ma, mdd_tpobj, ltname,
-                                        handle);
+                                      handle);
                if (rc != 0) {
                        CERROR("%s: Failed to unlink tobj "
                                DFID": rc = %d\n",
@@ -2871,7 +2940,7 @@ static int mdd_linkea_update_child_internal(const struct lu_env *env,
                linkea_entry_unpack(ldata.ld_lee, &ldata.ld_reclen,
                                    &lname, &fid);
 
-               if (strncmp(lname.ln_name, name, namelen) ||
+               if (strncmp(lname.ln_name, name, namelen) != 0 ||
                    lu_fid_eq(&fid, mdd_object_fid(parent))) {
                        ldata.ld_lee = (struct link_ea_entry *)
                                       ((char *)ldata.ld_lee +
@@ -3191,7 +3260,7 @@ static int mdd_declare_migrate_create(const struct lu_env *env,
                        return rc;
        }
 
-       mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_MIGRATE);
+       mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_V1);
        buf = mdd_buf_get_const(env, mgr_ea, mgr_easize);
        rc = mdo_declare_xattr_set(env, mdd_sobj, buf, XATTR_NAME_LMV,
                                   0, handle);
@@ -3199,7 +3268,7 @@ static int mdd_declare_migrate_create(const struct lu_env *env,
                return rc;
 
        la_flag->la_valid = LA_FLAGS;
-       la_flag->la_flags = LUSTRE_IMMUTABLE_FL;
+       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);
 
@@ -3221,6 +3290,7 @@ static int mdd_migrate_create(const struct lu_env *env,
        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;
        int                     rc;
        ENTRY;
@@ -3244,7 +3314,7 @@ static int mdd_migrate_create(const struct lu_env *env,
                        RETURN(rc);
                }
                spec->u.sp_symname = link_buf.lb_buf;
-       } else{
+       } else if S_ISREG(la->la_mode) {
                /* retrieve lov of the old object */
                rc = mdd_get_lov_ea(env, mdd_sobj, &lmm_buf);
                if (rc != 0 && rc != -ENODATA)
@@ -3257,13 +3327,16 @@ static int mdd_migrate_create(const struct lu_env *env,
        }
 
        mgr_ea = (struct lmv_mds_md_v1 *)info->mti_xattr_buf;
-       mgr_ea->lmv_magic = cpu_to_le32(LMV_MAGIC_MIGRATE);
+       mgr_ea->lmv_magic = cpu_to_le32(LMV_MAGIC_V1);
        mgr_ea->lmv_stripe_count = cpu_to_le32(2);
        mgr_ea->lmv_master_mdt_index = mdd_seq_site(mdd)->ss_node_id;
-       mgr_ea->lmv_hash_type = cpu_to_le32(LMV_HASH_TYPE_MIGRATION);
+       mgr_ea->lmv_hash_type = cpu_to_le32(LMV_HASH_FLAG_MIGRATION);
+       fid_cpu_to_le(&mgr_ea->lmv_master_fid, mdd_object_fid(mdd_sobj));
        fid_cpu_to_le(&mgr_ea->lmv_stripe_fids[0], mdd_object_fid(mdd_sobj));
        fid_cpu_to_le(&mgr_ea->lmv_stripe_fids[1], mdd_object_fid(mdd_tobj));
 
+       mdd_object_make_hint(env, mdd_pobj, mdd_tobj, la, spec, hint);
+
        handle = mdd_trans_create(env, mdd);
        if (IS_ERR(handle))
                GOTO(out_free, rc = PTR_ERR(handle));
@@ -3285,22 +3358,14 @@ static int mdd_migrate_create(const struct lu_env *env,
 
        /* create the target object */
        rc = mdd_object_create(env, mdd_pobj, mdd_tobj, la, spec, NULL, NULL,
-                              NULL, handle);
+                              hint, handle);
        if (rc != 0)
                GOTO(stop_trans, rc);
 
-       if (lmm_buf.lb_buf != NULL && lmm_buf.lb_len != 0) {
-               buf = mdd_buf_get_const(env, lmm_buf.lb_buf, lmm_buf.lb_len);
-               rc = mdo_xattr_set(env, mdd_tobj, buf, XATTR_NAME_LOV,
-                                  0, handle, mdd_object_capa(env, mdd_sobj));
-               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_MIGRATE);
+       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));
@@ -3313,7 +3378,7 @@ static int mdd_migrate_create(const struct lu_env *env,
         * IMMUTALBE flag and MIGRATE EA, it need to clear IMMUTABLE
         * flag and approve the migration */
        la_flag->la_valid = LA_FLAGS;
-       la_flag->la_flags = LUSTRE_IMMUTABLE_FL;
+       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));
@@ -3732,9 +3797,14 @@ static int mdd_migrate_update_name(const struct lu_env *env,
        if (is_dir)
                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));
+       if (rc != 0)
+               GOTO(stop_trans, rc);
        ma->ma_attr = *so_attr;
        ma->ma_valid |= MA_INODE;
-       rc = mdd_finish_unlink(env, mdd_sobj, ma, handle);
+       rc = mdd_finish_unlink(env, mdd_sobj, ma, mdd_pobj, lname, handle);
        if (rc != 0)
                GOTO(stop_trans, rc);
 
@@ -3773,7 +3843,7 @@ static int mdd_migrate_sanity_check(const struct lu_env *env,
 
        ENTRY;
 
-       mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_MIGRATE);
+       mgr_easize = lmv_mds_md_size(2, LMV_MAGIC_V1);
        mgr_buf = lu_buf_check_and_alloc(&info->mti_big_buf, mgr_easize);
        if (mgr_buf->lb_buf == NULL)
                RETURN(-ENOMEM);
@@ -3787,8 +3857,8 @@ static int mdd_migrate_sanity_check(const struct lu_env *env,
                 * is being set by previous migration process, so it
                 * needs to override the IMMUTE flag, otherwise the
                 * following sanity check will fail */
-               if (le32_to_cpu(lmm->lmv_md_v1.lmv_magic) ==
-                                               LMV_MAGIC_MIGRATE) {
+               if (le32_to_cpu(lmm->lmv_md_v1.lmv_hash_type) &
+                                               LMV_HASH_FLAG_MIGRATION) {
                        struct mdd_device *mdd = mdo2mdd(&sobj->mod_obj);
 
                        sattr->la_flags &= ~LUSTRE_IMMUTABLE_FL;
@@ -3862,22 +3932,18 @@ static int mdd_migrate_sanity_check(const struct lu_env *env,
 }
 
 static int mdd_migrate(const struct lu_env *env, struct md_object *pobj,
-                      const struct lu_fid *lf, const struct lu_name *lname,
+                      struct md_object *sobj, const struct lu_name *lname,
                       struct md_object *tobj, struct md_attr *ma)
 {
        struct mdd_object       *mdd_pobj = md2mdd_obj(pobj);
        struct mdd_device       *mdd = mdo2mdd(pobj);
-       struct mdd_object       *mdd_sobj = NULL;
+       struct mdd_object       *mdd_sobj = md2mdd_obj(sobj);
        struct mdd_object       *mdd_tobj = NULL;
        struct lu_attr          *so_attr = MDD_ENV_VAR(env, cattr);
        struct lu_attr          *pattr = MDD_ENV_VAR(env, pattr);
        int                     rc;
 
        ENTRY;
-       /* object has to be locked by mdt, so it must exist */
-       mdd_sobj = mdd_object_find(env, mdd, lf);
-       LASSERT(mdd_sobj != NULL);
-
        /* If the file will being migrated, it will check whether
         * the file is being opened by someone else right now */
        mdd_read_lock(env, mdd_sobj, MOR_SRC_CHILD);
@@ -3957,9 +4023,6 @@ static int mdd_migrate(const struct lu_env *env, struct md_object *pobj,
        if (rc != 0)
                GOTO(put, rc);
 put:
-       if (mdd_sobj)
-               mdd_object_put(env, mdd_sobj);
-
        RETURN(rc);
 }