Whamcloud - gitweb
LU-6027 mdt: Allow user EAs with empty values
[fs/lustre-release.git] / lustre / lfsck / lfsck_namespace.c
index c67e5fc..887c145 100644 (file)
@@ -835,17 +835,17 @@ static int lfsck_namespace_insert_orphan(const struct lu_env *env,
        struct lfsck_thread_info        *info   = lfsck_env_info(env);
        struct lu_name                  *cname  = &info->lti_name;
        struct dt_insert_rec            *rec    = &info->lti_dt_rec;
-       struct lu_fid                   *tfid   = &info->lti_fid5;
        struct lu_attr                  *la     = &info->lti_la3;
        const struct lu_fid             *cfid   = lfsck_dto2fid(orphan);
        const struct lu_fid             *pfid;
+       struct lu_fid                    tfid;
        struct lfsck_instance           *lfsck  = com->lc_lfsck;
        struct dt_device                *dev    = lfsck->li_bottom;
        struct dt_object                *parent;
        struct thandle                  *th     = NULL;
        struct lustre_handle             plh    = { 0 };
        struct lustre_handle             clh    = { 0 };
-       struct linkea_data               ldata  = { 0 };
+       struct linkea_data               ldata  = { NULL };
        struct lu_buf                    linkea_buf;
        int                              namelen;
        int                              idx    = 0;
@@ -854,12 +854,8 @@ static int lfsck_namespace_insert_orphan(const struct lu_env *env,
        ENTRY;
 
        cname->ln_name = NULL;
-       /* Create .lustre/lost+found/MDTxxxx when needed. */
-       if (unlikely(lfsck->li_lpf_obj == NULL)) {
-               rc = lfsck_create_lpf(env, lfsck);
-               if (rc != 0)
-                       GOTO(log, rc);
-       }
+       if (unlikely(lfsck->li_lpf_obj == NULL))
+               GOTO(log, rc = -ENXIO);
 
        parent = lfsck->li_lpf_obj;
        pfid = lfsck_dto2fid(parent);
@@ -873,13 +869,13 @@ static int lfsck_namespace_insert_orphan(const struct lu_env *env,
        do {
                namelen = snprintf(info->lti_key, NAME_MAX, DFID"%s-%s-%d",
                                   PFID(cfid), infix, type, idx++);
-               rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
+               rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
                               (const struct dt_key *)info->lti_key,
                               BYPASS_CAPA);
                if (rc != 0 && rc != -ENOENT)
                        GOTO(log, rc);
 
-               if (unlikely(rc == 0 && lu_fid_eq(cfid, tfid)))
+               if (unlikely(rc == 0 && lu_fid_eq(cfid, &tfid)))
                        exist = true;
        } while (rc == 0 && !exist);
 
@@ -1154,119 +1150,7 @@ log:
 }
 
 /**
- * Create the specified orphan MDT-object on remote MDT.
- *
- * The LFSCK instance on this MDT will send LFSCK RPC to remote MDT to
- * ask the remote LFSCK instance to create the specified orphan object
- * under .lustre/lost+found/MDTxxxx/ directory with the name:
- * ${FID}-P-${conflict_version}.
- *
- * \param[in] env      pointer to the thread context
- * \param[in] com      pointer to the lfsck component
- * \param[in] orphan   pointer to the orphan MDT-object
- * \param[in] type     the orphan's type to be created
- *
- *  type "P":          The orphan object to be created was a parent directory
- *                     of some MDT-object which linkEA shows that the @orphan
- *                     object is missing.
- *
- * \see lfsck_layout_recreate_parent() for more types.
- *
- * \param[in] lmv      pointer to master LMV EA that will be set to the orphan
- *
- * \retval             positive number for repaired cases
- * \retval             0 if needs to repair nothing
- * \retval             negative error number on failure
- */
-static int lfsck_namespace_create_orphan_remote(const struct lu_env *env,
-                                               struct lfsck_component *com,
-                                               struct dt_object *orphan,
-                                               __u32 type,
-                                               struct lmv_mds_md_v1 *lmv)
-{
-       struct lfsck_thread_info        *info   = lfsck_env_info(env);
-       struct lfsck_request            *lr     = &info->lti_lr;
-       struct lu_seq_range             *range  = &info->lti_range;
-       const struct lu_fid             *fid    = lfsck_dto2fid(orphan);
-       struct lfsck_namespace          *ns     = com->lc_file_ram;
-       struct lfsck_instance           *lfsck  = com->lc_lfsck;
-       struct seq_server_site          *ss     =
-                       lu_site2seq(lfsck->li_bottom->dd_lu_dev.ld_site);
-       struct lfsck_tgt_desc           *ltd    = NULL;
-       struct ptlrpc_request           *req    = NULL;
-       int                              rc;
-       ENTRY;
-
-       if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
-               GOTO(out, rc = 1);
-
-       fld_range_set_mdt(range);
-       rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
-       if (rc != 0)
-               GOTO(out, rc);
-
-       ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, range->lsr_index);
-       if (ltd == NULL) {
-               ns->ln_flags |= LF_INCOMPLETE;
-
-               GOTO(out, rc = -ENODEV);
-       }
-
-       req = ptlrpc_request_alloc(class_exp2cliimp(ltd->ltd_exp),
-                                  &RQF_LFSCK_NOTIFY);
-       if (req == NULL)
-               GOTO(out, rc = -ENOMEM);
-
-       rc = ptlrpc_request_pack(req, LUSTRE_OBD_VERSION, LFSCK_NOTIFY);
-       if (rc != 0) {
-               ptlrpc_request_free(req);
-
-               GOTO(out, rc);
-       }
-
-       lr = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
-       memset(lr, 0, sizeof(*lr));
-       lr->lr_event = LE_CREATE_ORPHAN;
-       lr->lr_index = lfsck_dev_idx(lfsck->li_bottom);
-       lr->lr_active = LFSCK_TYPE_NAMESPACE;
-       lr->lr_fid = *fid;
-       lr->lr_type = type;
-       if (lmv != NULL) {
-               lr->lr_hash_type = lmv->lmv_hash_type;
-               lr->lr_stripe_count = lmv->lmv_stripe_count;
-               lr->lr_layout_version = lmv->lmv_layout_version;
-               memcpy(lr->lr_pool_name, lmv->lmv_pool_name,
-                      sizeof(lr->lr_pool_name));
-       }
-
-       ptlrpc_request_set_replen(req);
-       rc = ptlrpc_queue_wait(req);
-       ptlrpc_req_finished(req);
-
-       if (rc == 0) {
-               orphan->do_lu.lo_header->loh_attr |= LOHA_EXISTS;
-               rc = 1;
-       } else if (rc == -EEXIST) {
-               orphan->do_lu.lo_header->loh_attr |= LOHA_EXISTS;
-               rc = 0;
-       }
-
-       GOTO(out, rc);
-
-out:
-       CDEBUG(D_LFSCK, "%s: namespace LFSCK create object "
-              DFID" on the MDT %x remotely: rc = %d\n",
-              lfsck_lfsck2name(lfsck), PFID(fid),
-              ltd != NULL ? ltd->ltd_index : -1, rc);
-
-       if (ltd != NULL)
-               lfsck_tgt_put(ltd);
-
-       return rc;
-}
-
-/**
- * Create the specified orphan MDT-object locally.
+ * Create the specified orphan directory.
  *
  * For the case that the parent MDT-object stored in some MDT-object's
  * linkEA entry is lost, the LFSCK will re-create the parent object as
@@ -1276,24 +1160,15 @@ out:
  * \param[in] env      pointer to the thread context
  * \param[in] com      pointer to the lfsck component
  * \param[in] orphan   pointer to the orphan MDT-object to be created
- * \param[in] type     the orphan's type to be created
- *
- *  type "P":          The orphan object to be created was a parent directory
- *                     of some MDT-object which linkEA shows that the @orphan
- *                     object is missing.
- *
- * \see lfsck_layout_recreate_parent() for more types.
- *
  * \param[in] lmv      pointer to master LMV EA that will be set to the orphan
  *
  * \retval             positive number for repaired cases
  * \retval             negative error number on failure
  */
-static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
-                                              struct lfsck_component *com,
-                                              struct dt_object *orphan,
-                                              __u32 type,
-                                              struct lmv_mds_md_v1 *lmv)
+static int lfsck_namespace_create_orphan_dir(const struct lu_env *env,
+                                            struct lfsck_component *com,
+                                            struct dt_object *orphan,
+                                            struct lmv_mds_md_v1 *lmv)
 {
        struct lfsck_thread_info        *info   = lfsck_env_info(env);
        struct lu_attr                  *la     = &info->lti_la;
@@ -1301,17 +1176,17 @@ static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
        struct dt_object_format         *dof    = &info->lti_dof;
        struct lu_name                  *cname  = &info->lti_name2;
        struct dt_insert_rec            *rec    = &info->lti_dt_rec;
-       struct lu_fid                   *tfid   = &info->lti_fid;
        struct lmv_mds_md_v1            *lmv2   = &info->lti_lmv2;
        const struct lu_fid             *cfid   = lfsck_dto2fid(orphan);
-       const struct lu_fid             *pfid;
+       struct lu_fid                    tfid;
        struct lfsck_instance           *lfsck  = com->lc_lfsck;
-       struct dt_device                *dev    = lfsck->li_bottom;
+       struct lfsck_namespace          *ns     = com->lc_file_ram;
+       struct dt_device                *dev;
        struct dt_object                *parent = NULL;
        struct dt_object                *child  = NULL;
        struct thandle                  *th     = NULL;
        struct lustre_handle             lh     = { 0 };
-       struct linkea_data               ldata  = { 0 };
+       struct linkea_data               ldata  = { NULL };
        struct lu_buf                    linkea_buf;
        struct lu_buf                    lmv_buf;
        char                             name[32];
@@ -1321,26 +1196,45 @@ static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
        ENTRY;
 
        LASSERT(!dt_object_exists(orphan));
-       LASSERT(!dt_object_remote(orphan));
-
-       /* @orphan maybe not attached to lfsck->li_bottom */
-       child = lfsck_object_find_by_dev(env, dev, cfid);
-       if (IS_ERR(child))
-               GOTO(log, rc = PTR_ERR(child));
 
        cname->ln_name = NULL;
        if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
                GOTO(log, rc = 1);
 
-       /* Create .lustre/lost+found/MDTxxxx when needed. */
-       if (unlikely(lfsck->li_lpf_obj == NULL)) {
-               rc = lfsck_create_lpf(env, lfsck);
+       if (dt_object_remote(orphan)) {
+               LASSERT(lfsck->li_lpf_root_obj != NULL);
+
+               idx = lfsck_find_mdt_idx_by_fid(env, lfsck, cfid);
+               if (idx < 0)
+                       GOTO(log, rc = idx);
+
+               snprintf(name, 8, "MDT%04x", idx);
+               rc = dt_lookup(env, lfsck->li_lpf_root_obj,
+                              (struct dt_rec *)&tfid,
+                              (const struct dt_key *)name, BYPASS_CAPA);
                if (rc != 0)
-                       GOTO(log, rc);
+                       GOTO(log, rc = (rc == -ENOENT ? -ENXIO : rc));
+
+               parent = lfsck_object_find_bottom(env, lfsck, &tfid);
+               if (IS_ERR(parent))
+                       GOTO(log, rc = PTR_ERR(parent));
+
+               if (unlikely(!dt_try_as_dir(env, parent)))
+                       GOTO(log, rc = -ENOTDIR);
+       } else {
+               if (unlikely(lfsck->li_lpf_obj == NULL))
+                       GOTO(log, rc = -ENXIO);
+
+               parent = lfsck->li_lpf_obj;
        }
 
-       parent = lfsck->li_lpf_obj;
-       pfid = lfsck_dto2fid(parent);
+       dev = lfsck_find_dev_by_fid(env, lfsck, cfid);
+       if (IS_ERR(dev))
+               GOTO(log, rc = PTR_ERR(dev));
+
+       child = lfsck_object_find_by_dev(env, dev, cfid);
+       if (IS_ERR(child))
+               GOTO(log, rc = PTR_ERR(child));
 
        /* Hold update lock on the parent to prevent others to access. */
        rc = lfsck_ibits_lock(env, lfsck, parent, &lh,
@@ -1348,10 +1242,11 @@ static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
        if (rc != 0)
                GOTO(log, rc);
 
+       idx = 0;
        do {
                namelen = snprintf(name, 31, DFID"-P-%d",
                                   PFID(cfid), idx++);
-               rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
+               rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
                               (const struct dt_key *)name, BYPASS_CAPA);
                if (rc != 0 && rc != -ENOENT)
                        GOTO(unlock1, rc);
@@ -1361,7 +1256,7 @@ static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
        cname->ln_namelen = namelen;
 
        memset(la, 0, sizeof(*la));
-       la->la_mode = type | (S_ISDIR(type) ? 0700 : 0600);
+       la->la_mode = S_IFDIR | 0700;
        la->la_valid = LA_TYPE | LA_MODE | LA_UID | LA_GID |
                       LA_ATIME | LA_MTIME | LA_CTIME;
 
@@ -1369,13 +1264,13 @@ static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
                                  la->la_mode & S_IFMT);
 
        memset(dof, 0, sizeof(*dof));
-       dof->dof_type = dt_mode_to_dft(type);
+       dof->dof_type = dt_mode_to_dft(S_IFDIR);
 
        rc = linkea_data_new(&ldata, &info->lti_linkea_buf2);
        if (rc != 0)
                GOTO(unlock1, rc);
 
-       rc = linkea_add_buf(&ldata, cname, pfid);
+       rc = linkea_add_buf(&ldata, cname, lfsck_dto2fid(parent));
        if (rc != 0)
                GOTO(unlock1, rc);
 
@@ -1383,13 +1278,38 @@ static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
        if (IS_ERR(th))
                GOTO(unlock1, rc = PTR_ERR(th));
 
+       /* Sync the remote transaction to guarantee that the subsequent
+        * lock against the @orphan can find the @orphan in time. */
+       if (dt_object_remote(orphan))
+               th->th_sync = 1;
+
        rc = dt_declare_create(env, child, la, hint, dof, th);
-       if (rc == 0 && S_ISDIR(type))
+       if (rc != 0)
+               GOTO(stop, rc);
+
+       if (unlikely(!dt_try_as_dir(env, child)))
+               GOTO(stop, rc = -ENOTDIR);
+
+       rec->rec_type = S_IFDIR;
+       rec->rec_fid = cfid;
+       rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
+                              (const struct dt_key *)dot, th);
+       if (rc != 0)
+               GOTO(stop, rc);
+
+       rec->rec_fid = lfsck_dto2fid(parent);
+       rc = dt_declare_insert(env, child, (const struct dt_rec *)rec,
+                              (const struct dt_key *)dotdot, th);
+       if (rc == 0)
                rc = dt_declare_ref_add(env, child, th);
 
        if (rc != 0)
                GOTO(stop, rc);
 
+       rc = dt_declare_ref_add(env, child, th);
+       if (rc != 0)
+               GOTO(stop, rc);
+
        if (lmv != NULL) {
                lmv->lmv_magic = LMV_MAGIC;
                lmv->lmv_master_mdt_index = lfsck_dev_idx(dev);
@@ -1408,11 +1328,10 @@ static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
        if (rc != 0)
                GOTO(stop, rc);
 
-       rec->rec_type = type;
        rec->rec_fid = cfid;
        rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
                               (const struct dt_key *)name, th);
-       if (rc == 0 && S_ISDIR(type))
+       if (rc == 0)
                rc = dt_declare_ref_add(env, parent, th);
 
        if (rc != 0)
@@ -1427,28 +1346,22 @@ static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
        if (rc != 0)
                GOTO(unlock2, rc);
 
-       if (S_ISDIR(type)) {
-               if (unlikely(!dt_try_as_dir(env, child)))
-                       GOTO(unlock2, rc = -ENOTDIR);
-
-               rec->rec_type = S_IFDIR;
-               rec->rec_fid = cfid;
-               rc = dt_insert(env, child, (const struct dt_rec *)rec,
-                              (const struct dt_key *)dot, th, BYPASS_CAPA, 1);
-               if (rc != 0)
-                       GOTO(unlock2, rc);
+       rec->rec_fid = cfid;
+       rc = dt_insert(env, child, (const struct dt_rec *)rec,
+                      (const struct dt_key *)dot, th, BYPASS_CAPA, 1);
+       if (rc != 0)
+               GOTO(unlock2, rc);
 
-               rec->rec_fid = pfid;
-               rc = dt_insert(env, child, (const struct dt_rec *)rec,
-                              (const struct dt_key *)dotdot, th,
-                              BYPASS_CAPA, 1);
-               if (rc != 0)
-                       GOTO(unlock2, rc);
+       rec->rec_fid = lfsck_dto2fid(parent);
+       rc = dt_insert(env, child, (const struct dt_rec *)rec,
+                      (const struct dt_key *)dotdot, th,
+                      BYPASS_CAPA, 1);
+       if (rc != 0)
+               GOTO(unlock2, rc);
 
-               rc = dt_ref_add(env, child, th);
-               if (rc != 0)
-                       GOTO(unlock2, rc);
-       }
+       rc = dt_ref_add(env, child, th);
+       if (rc != 0)
+               GOTO(unlock2, rc);
 
        if (lmv != NULL) {
                rc = dt_xattr_set(env, child, &lmv_buf, XATTR_NAME_LMV, 0,
@@ -1463,11 +1376,10 @@ static int lfsck_namespace_create_orphan_local(const struct lu_env *env,
        if (rc != 0)
                GOTO(stop, rc);
 
-       rec->rec_type = type;
        rec->rec_fid = cfid;
        rc = dt_insert(env, parent, (const struct dt_rec *)rec,
                       (const struct dt_key *)name, th, BYPASS_CAPA, 1);
-       if (rc == 0 && S_ISDIR(type)) {
+       if (rc == 0) {
                dt_write_lock(env, parent, 0);
                rc = dt_ref_add(env, parent, th);
                dt_write_unlock(env, parent);
@@ -1485,55 +1397,16 @@ unlock1:
        lfsck_ibits_unlock(&lh, LCK_EX);
 
 log:
-       CDEBUG(D_LFSCK, "%s: namespace LFSCK create orphan locally for "
-              "the object "DFID", name = %s, type %o: rc = %d\n",
+       CDEBUG(D_LFSCK, "%s: namespace LFSCK create orphan dir for "
+              "the object "DFID", name = %s: rc = %d\n",
               lfsck_lfsck2name(lfsck), PFID(cfid),
-              cname->ln_name != NULL ? cname->ln_name : "<NULL>", type, rc);
+              cname->ln_name != NULL ? cname->ln_name : "<NULL>", rc);
 
        if (child != NULL && !IS_ERR(child))
                lfsck_object_put(env, child);
 
-       return rc;
-}
-
-/**
- * Create the specified orphan MDT-object.
- *
- * For the case that the parent MDT-object stored in some MDT-object's
- * linkEA entry is lost, the LFSCK will re-create the parent object as
- * an orphan and insert it into .lustre/lost+found/MDTxxxx/ directory
- * with the name: ${FID}-P-${conflict_version}.
- *
- * \param[in] env      pointer to the thread context
- * \param[in] com      pointer to the lfsck component
- * \param[in] orphan   pointer to the orphan MDT-object
- *
- *  type "P":          The orphan object to be created was a parent directory
- *                     of some MDT-object which linkEA shows that the @orphan
- *                     object is missing.
- *
- * \see lfsck_layout_recreate_parent() for more types.
- *
- * \param[in] lmv      pointer to master LMV EA that will be set to the orphan
- *
- * \retval             positive number for repaired cases
- * \retval             0 if needs to repair nothing
- * \retval             negative error number on failure
- */
-static int lfsck_namespace_create_orphan(const struct lu_env *env,
-                                        struct lfsck_component *com,
-                                        struct dt_object *orphan,
-                                        struct lmv_mds_md_v1 *lmv)
-{
-       struct lfsck_namespace *ns = com->lc_file_ram;
-       int                     rc;
-
-       if (dt_object_remote(orphan))
-               rc = lfsck_namespace_create_orphan_remote(env, com, orphan,
-                                                         S_IFDIR, lmv);
-       else
-               rc = lfsck_namespace_create_orphan_local(env, com, orphan,
-                                                        S_IFDIR, lmv);
+       if (parent != NULL && !IS_ERR(parent) && parent != lfsck->li_lpf_obj)
+               lfsck_object_put(env, parent);
 
        if (rc != 0)
                ns->ln_flags |= LF_INCONSISTENT;
@@ -1574,7 +1447,7 @@ static int lfsck_namespace_shrink_linkea(const struct lu_env *env,
        struct lfsck_bookmark           *bk        = &lfsck->li_bookmark_ram;
        struct thandle                  *th        = NULL;
        struct lustre_handle             lh        = { 0 };
-       struct linkea_data               ldata_new = { 0 };
+       struct linkea_data               ldata_new = { NULL };
        struct lu_buf                    linkea_buf;
        int                              rc        = 0;
        ENTRY;
@@ -1783,16 +1656,16 @@ static int lfsck_namespace_replace_cond(const struct lu_env *env,
                                        const struct lu_name *cname)
 {
        struct lfsck_thread_info        *info   = lfsck_env_info(env);
-       struct lu_fid                   *tfid   = &info->lti_fid5;
        struct lu_attr                  *la     = &info->lti_la;
        struct dt_insert_rec            *rec    = &info->lti_dt_rec;
+       struct lu_fid                    tfid;
        struct lfsck_instance           *lfsck  = com->lc_lfsck;
        struct dt_device                *dev    = lfsck->li_next;
        const char                      *name   = cname->ln_name;
        struct dt_object                *obj    = NULL;
        struct lustre_handle             plh    = { 0 };
        struct lustre_handle             clh    = { 0 };
-       struct linkea_data               ldata  = { 0 };
+       struct linkea_data               ldata  = { NULL };
        struct thandle                  *th     = NULL;
        bool                             exist  = true;
        int                              rc     = 0;
@@ -1824,7 +1697,7 @@ static int lfsck_namespace_replace_cond(const struct lu_env *env,
                goto replace;
        }
 
-       rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
+       rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
                       (const struct dt_key *)name, BYPASS_CAPA);
        if (rc == -ENOENT) {
                exist = false;
@@ -1835,7 +1708,7 @@ static int lfsck_namespace_replace_cond(const struct lu_env *env,
                GOTO(log, rc);
 
        /* Someone changed the name entry, cannot replace it. */
-       if (!lu_fid_eq(cfid, tfid))
+       if (!lu_fid_eq(cfid, &tfid))
                GOTO(log, rc = 0);
 
        /* lock the object to be destroyed. */
@@ -1973,8 +1846,6 @@ int lfsck_namespace_rebuild_linkea(const struct lu_env *env,
        int                              rc     = 0;
        ENTRY;
 
-       LASSERT(!dt_object_remote(obj));
-
        th = dt_trans_create(env, dev);
        if (IS_ERR(th))
                GOTO(log, rc = PTR_ERR(th));
@@ -2050,15 +1921,14 @@ int lfsck_namespace_repair_dirent(const struct lu_env *env,
                                  const char *name, const char *name2,
                                  __u16 type, bool update, bool dec)
 {
-       struct lfsck_thread_info        *info   = lfsck_env_info(env);
-       struct dt_insert_rec            *rec    = &info->lti_dt_rec;
-       const struct lu_fid             *cfid   = lfsck_dto2fid(child);
-       struct lu_fid                   *tfid   = &info->lti_fid5;
-       struct lfsck_instance           *lfsck  = com->lc_lfsck;
-       struct dt_device                *dev    = lfsck->li_next;
-       struct thandle                  *th     = NULL;
-       struct lustre_handle             lh     = { 0 };
-       int                              rc     = 0;
+       struct dt_insert_rec    *rec    = &lfsck_env_info(env)->lti_dt_rec;
+       const struct lu_fid     *cfid   = lfsck_dto2fid(child);
+       struct lu_fid            tfid;
+       struct lfsck_instance   *lfsck  = com->lc_lfsck;
+       struct dt_device        *dev    = lfsck->li_next;
+       struct thandle          *th     = NULL;
+       struct lustre_handle     lh     = { 0 };
+       int                      rc     = 0;
        ENTRY;
 
        if (unlikely(!dt_try_as_dir(env, parent)))
@@ -2098,7 +1968,7 @@ int lfsck_namespace_repair_dirent(const struct lu_env *env,
                GOTO(stop, rc);
 
        dt_write_lock(env, parent, 0);
-       rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
+       rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
                       (const struct dt_key *)name, BYPASS_CAPA);
        /* Someone has removed the bad name entry by race. */
        if (rc == -ENOENT)
@@ -2109,7 +1979,7 @@ int lfsck_namespace_repair_dirent(const struct lu_env *env,
 
        /* Someone has removed the bad name entry and reused it for other
         * object by race. */
-       if (!lu_fid_eq(tfid, cfid))
+       if (!lu_fid_eq(&tfid, cfid))
                GOTO(unlock2, rc = 0);
 
        if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
@@ -2200,7 +2070,7 @@ static int lfsck_namespace_repair_unmatched_pairs(const struct lu_env *env,
        struct lfsck_instance           *lfsck  = com->lc_lfsck;
        struct dt_device                *dev    = lfsck->li_bottom;
        struct thandle                  *th     = NULL;
-       struct linkea_data               ldata  = { 0 };
+       struct linkea_data               ldata  = { NULL };
        struct lu_buf                    linkea_buf;
        int                              rc     = 0;
        ENTRY;
@@ -2383,7 +2253,7 @@ lfsck_namespace_dsd_single(const struct lu_env *env,
        struct lfsck_thread_info *info          = lfsck_env_info(env);
        struct lu_name           *cname         = &info->lti_name;
        const struct lu_fid      *cfid          = lfsck_dto2fid(child);
-       struct lu_fid            *tfid          = &info->lti_fid3;
+       struct lu_fid             tfid;
        struct lfsck_namespace   *ns            = com->lc_file_ram;
        struct lfsck_instance    *lfsck         = com->lc_lfsck;
        struct dt_object         *parent        = NULL;
@@ -2391,9 +2261,9 @@ lfsck_namespace_dsd_single(const struct lu_env *env,
        int                       rc            = 0;
        ENTRY;
 
-       lfsck_namespace_unpack_linkea_entry(ldata, cname, tfid, info->lti_key);
+       lfsck_namespace_unpack_linkea_entry(ldata, cname, &tfid, info->lti_key);
        /* The unique linkEA entry with bad parent will be handled as orphan. */
-       if (!fid_is_sane(tfid)) {
+       if (!fid_is_sane(&tfid)) {
                if (!lustre_handle_is_used(lh) && retry != NULL)
                        *retry = true;
                else
@@ -2403,7 +2273,7 @@ lfsck_namespace_dsd_single(const struct lu_env *env,
                GOTO(out, rc);
        }
 
-       parent = lfsck_object_find_bottom(env, lfsck, tfid);
+       parent = lfsck_object_find_bottom(env, lfsck, &tfid);
        if (IS_ERR(parent))
                GOTO(out, rc = PTR_ERR(parent));
 
@@ -2445,7 +2315,7 @@ lost_parent:
                        /* It is an invalid name entry, we
                         * cannot trust the parent also. */
                        rc = lfsck_namespace_shrink_linkea(env, com, child,
-                                               ldata, cname, tfid, true);
+                                               ldata, cname, &tfid, true);
                        if (rc < 0)
                                GOTO(out, rc);
 
@@ -2458,7 +2328,7 @@ lost_parent:
                }
 
                /* Create the lost parent as an orphan. */
-               rc = lfsck_namespace_create_orphan(env, com, parent, lmv);
+               rc = lfsck_namespace_create_orphan_dir(env, com, parent, lmv);
                if (rc >= 0) {
                        /* Add the missing name entry to the parent. */
                        rc = lfsck_namespace_insert_normal(env, com, parent,
@@ -2474,7 +2344,7 @@ lost_parent:
                                 * current system to be consistent. */
                                rc = lfsck_namespace_shrink_linkea(env,
                                                com, child, ldata,
-                                               cname, tfid, true);
+                                               cname, &tfid, true);
                                if (rc >= 0) {
                                        snprintf(info->lti_tmpbuf,
                                                 sizeof(info->lti_tmpbuf),
@@ -2500,7 +2370,7 @@ lost_parent:
                GOTO(out, rc);
        }
 
-       rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
+       rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
                       (const struct dt_key *)cname->ln_name, BYPASS_CAPA);
        if (rc == -ENOENT) {
                /* If the LFSCK is marked as LF_INCOMPLETE, then means some MDT
@@ -2530,7 +2400,7 @@ lost_parent:
                /* It is an invalid name entry, drop it. */
                if (unlikely(rc > 0)) {
                        rc = lfsck_namespace_shrink_linkea(env, com, child,
-                                               ldata, cname, tfid, true);
+                                               ldata, cname, &tfid, true);
                        if (rc >= 0) {
                                snprintf(info->lti_tmpbuf,
                                         sizeof(info->lti_tmpbuf),
@@ -2562,7 +2432,7 @@ lost_parent:
                         * internal status of create operation. Under such
                         * case, nothing to be done. */
                        rc = lfsck_namespace_shrink_linkea_cond(env, com,
-                                       parent, child, ldata, cname, tfid);
+                                       parent, child, ldata, cname, &tfid);
                        if (rc >= 0) {
                                snprintf(info->lti_tmpbuf,
                                         sizeof(info->lti_tmpbuf),
@@ -2578,7 +2448,7 @@ lost_parent:
        if (rc != 0)
                GOTO(out, rc);
 
-       if (!lu_fid_eq(tfid, cfid)) {
+       if (!lu_fid_eq(&tfid, cfid)) {
                if (!lustre_handle_is_used(lh) && retry != NULL) {
                        *retry = true;
 
@@ -2590,7 +2460,7 @@ lost_parent:
                 * may be created by the LFSCK for repairing dangling
                 * name entry. Try to replace it. */
                rc = lfsck_namespace_replace_cond(env, com, parent, child,
-                                                 tfid, cname);
+                                                 &tfid, cname);
                if (rc == 0)
                        rc = lfsck_namespace_dsd_orphan(env, com, child,
                                                        pfid, lh, type);
@@ -2659,13 +2529,13 @@ lfsck_namespace_dsd_multiple(const struct lu_env *env,
        struct lfsck_thread_info *info          = lfsck_env_info(env);
        struct lu_name           *cname         = &info->lti_name;
        const struct lu_fid      *cfid          = lfsck_dto2fid(child);
-       struct lu_fid            *tfid          = &info->lti_fid3;
-       struct lu_fid            *pfid2         = &info->lti_fid4;
+       struct lu_fid            *pfid2         = &info->lti_fid3;
+       struct lu_fid             tfid;
        struct lfsck_namespace   *ns            = com->lc_file_ram;
        struct lfsck_instance    *lfsck         = com->lc_lfsck;
        struct lfsck_bookmark    *bk            = &lfsck->li_bookmark_ram;
        struct dt_object         *parent        = NULL;
-       struct linkea_data        ldata_new     = { 0 };
+       struct linkea_data        ldata_new     = { NULL };
        int                       dirent_count  = 0;
        int                       linkea_count  = 0;
        int                       rc            = 0;
@@ -2674,12 +2544,12 @@ lfsck_namespace_dsd_multiple(const struct lu_env *env,
 
 again:
        while (ldata->ld_lee != NULL) {
-               lfsck_namespace_unpack_linkea_entry(ldata, cname, tfid,
+               lfsck_namespace_unpack_linkea_entry(ldata, cname, &tfid,
                                                    info->lti_key);
                /* Drop repeated linkEA entries. */
-               lfsck_namespace_filter_linkea_entry(ldata, cname, tfid, true);
+               lfsck_namespace_filter_linkea_entry(ldata, cname, &tfid, true);
                /* Drop invalid linkEA entry. */
-               if (!fid_is_sane(tfid)) {
+               if (!fid_is_sane(&tfid)) {
                        linkea_del_buf(ldata, cname);
                        linkea_count++;
                        continue;
@@ -2698,12 +2568,12 @@ again:
                 * When the LFSCK runs again, if the dangling name is still
                 * there, the LFSCK should move the orphan directory object
                 * back to the normal namespace. */
-               if (!lpf && !lu_fid_eq(pfid, tfid) && once) {
+               if (!lpf && !lu_fid_eq(pfid, &tfid) && once) {
                        linkea_next_entry(ldata);
                        continue;
                }
 
-               parent = lfsck_object_find_bottom(env, lfsck, tfid);
+               parent = lfsck_object_find_bottom(env, lfsck, &tfid);
                if (IS_ERR(parent))
                        RETURN(PTR_ERR(parent));
 
@@ -2730,7 +2600,7 @@ again:
                        continue;
                }
 
-               rc = dt_lookup(env, parent, (struct dt_rec *)tfid,
+               rc = dt_lookup(env, parent, (struct dt_rec *)&tfid,
                               (const struct dt_key *)cname->ln_name,
                               BYPASS_CAPA);
                *pfid2 = *lfsck_dto2fid(parent);
@@ -2746,7 +2616,7 @@ again:
                        RETURN(rc);
                }
 
-               if (lu_fid_eq(tfid, cfid)) {
+               if (lu_fid_eq(&tfid, cfid)) {
                        lfsck_object_put(env, parent);
                        if (!lu_fid_eq(pfid, pfid2)) {
                                *type = LNIT_UNMATCHED_PAIRS;
@@ -2780,12 +2650,12 @@ rebuild:
                         * other parent directories, remove all of them. */
                        while (ldata->ld_lee != NULL) {
                                lfsck_namespace_unpack_linkea_entry(ldata,
-                                               cname, tfid, info->lti_key);
-                               if (!fid_is_sane(tfid))
+                                               cname, &tfid, info->lti_key);
+                               if (!fid_is_sane(&tfid))
                                        goto next;
 
                                parent = lfsck_object_find_bottom(env, lfsck,
-                                                                 tfid);
+                                                                 &tfid);
                                if (IS_ERR(parent)) {
                                        rc = PTR_ERR(parent);
                                        if (rc != -ENOENT &&
@@ -2827,7 +2697,7 @@ next:
                 * created by the LFSCK for repairing dangling name entry.
                 * Try to replace it. */
                rc = lfsck_namespace_replace_cond(env, com, parent, child,
-                                                 tfid, cname);
+                                                 &tfid, cname);
                lfsck_object_put(env, parent);
                if (rc < 0)
                        RETURN(rc);
@@ -2890,7 +2760,7 @@ next:
  * \param[in] env      pointer to the thread context
  * \param[in] com      pointer to the lfsck component
  * \param[in] obj      pointer to the dt_object to be handled
- * \param[in,out] nlink        pointer to buffer to object's hard lock count before
+ * \param[in,out] la   pointer to buffer to object's attribute before
  *                     and after the repairing
  *
  * \retval             positive number for repaired cases
@@ -2899,10 +2769,10 @@ next:
  */
 static int lfsck_namespace_repair_nlink(const struct lu_env *env,
                                        struct lfsck_component *com,
-                                       struct dt_object *obj, __u32 *nlink)
+                                       struct dt_object *obj,
+                                       struct lu_attr *la)
 {
        struct lfsck_thread_info        *info   = lfsck_env_info(env);
-       struct lu_attr                  *la     = &info->lti_la3;
        struct lu_fid                   *tfid   = &info->lti_fid3;
        struct lfsck_namespace          *ns     = com->lc_file_ram;
        struct lfsck_instance           *lfsck  = com->lc_lfsck;
@@ -2910,9 +2780,9 @@ static int lfsck_namespace_repair_nlink(const struct lu_env *env,
        const struct lu_fid             *cfid   = lfsck_dto2fid(obj);
        struct dt_object                *child  = NULL;
        struct thandle                  *th     = NULL;
-       struct linkea_data               ldata  = { 0 };
+       struct linkea_data               ldata  = { NULL };
        struct lustre_handle             lh     = { 0 };
-       __u32                            old    = *nlink;
+       __u32                            old    = la->la_nlink;
        int                              rc     = 0;
        __u8                             flags;
        ENTRY;
@@ -2963,17 +2833,19 @@ static int lfsck_namespace_repair_nlink(const struct lu_env *env,
        if (flags & LNTF_SKIP_NLINK)
                GOTO(unlock, rc = 0);
 
-       rc = lfsck_links_read2(env, child, &ldata);
-       if (rc == -ENODATA)
-               GOTO(unlock, rc = 0);
+       rc = dt_attr_get(env, child, la, BYPASS_CAPA);
+       if (rc != 0)
+               GOTO(unlock, rc = (rc == -ENOENT ? 0 : rc));
 
+       rc = lfsck_links_read2(env, child, &ldata);
        if (rc != 0)
-               GOTO(unlock, rc);
+               GOTO(unlock, rc = (rc == -ENODATA ? 0 : rc));
 
-       if (*nlink == ldata.ld_leh->leh_reccount)
+       if (la->la_nlink == ldata.ld_leh->leh_reccount ||
+           unlikely(la->la_nlink == 0))
                GOTO(unlock, rc = 0);
 
-       la->la_nlink = *nlink = ldata.ld_leh->leh_reccount;
+       la->la_nlink = ldata.ld_leh->leh_reccount;
        if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
                GOTO(unlock, rc = 1);
 
@@ -2994,7 +2866,7 @@ log:
 
        CDEBUG(D_LFSCK, "%s: namespace LFSCK repaired the object "DFID"'s "
               "nlink count from %u to %u: rc = %d\n",
-              lfsck_lfsck2name(lfsck), PFID(cfid), old, *nlink, rc);
+              lfsck_lfsck2name(lfsck), PFID(cfid), old, la->la_nlink, rc);
 
        if (rc != 0)
                ns->ln_flags |= LF_INCONSISTENT;
@@ -3049,7 +2921,7 @@ static int lfsck_namespace_double_scan_dir(const struct lu_env *env,
        struct lfsck_namespace   *ns            = com->lc_file_ram;
        struct lfsck_instance    *lfsck         = com->lc_lfsck;
        struct lustre_handle      lh            = { 0 };
-       struct linkea_data        ldata         = { 0 };
+       struct linkea_data        ldata         = { NULL };
        bool                      unknown       = false;
        bool                      lpf           = false;
        bool                      retry         = false;
@@ -3281,7 +3153,7 @@ static int lfsck_namespace_double_scan_one(const struct lu_env *env,
        struct lfsck_instance    *lfsck    = com->lc_lfsck;
        struct lfsck_namespace   *ns       = com->lc_file_ram;
        struct dt_object         *parent   = NULL;
-       struct linkea_data        ldata    = { 0 };
+       struct linkea_data        ldata    = { NULL };
        bool                      repaired = false;
        int                       count    = 0;
        int                       rc;
@@ -3372,7 +3244,7 @@ lost_parent:
                                }
 
                                /* Create the lost parent as an orphan. */
-                               rc = lfsck_namespace_create_orphan(env, com,
+                               rc = lfsck_namespace_create_orphan_dir(env, com,
                                                                parent, NULL);
                                if (rc < 0) {
                                        lfsck_object_put(env, parent);
@@ -3572,37 +3444,38 @@ out:
                count = ldata.ld_leh->leh_reccount;
        }
 
-       /* If the LFSCK is marked as LF_INCOMPLETE, then means some
-        * MDT has ever tried to verify some remote MDT-object that
-        * resides on this MDT, but this MDT failed to respond such
-        * request. So means there may be some remote name entry on
-        * other MDT that references this object with another name,
-        * so we cannot know whether this linkEA is valid or not.
-        * So keep it there and maybe resolved when next LFSCK run. */
-       if (count == 0 && !(ns->ln_flags & LF_INCOMPLETE)) {
-               /* If the child becomes orphan, then insert it into
-                * the global .lustre/lost+found/MDTxxxx directory. */
-               rc = lfsck_namespace_insert_orphan(env, com, child, "", "O",
-                                                  &count);
-               if (rc < 0)
-                       return rc;
+       if (count == 0) {
+               /* If the LFSCK is marked as LF_INCOMPLETE, then means some
+                * MDT has ever tried to verify some remote MDT-object that
+                * resides on this MDT, but this MDT failed to respond such
+                * request. So means there may be some remote name entry on
+                * other MDT that references this object with another name,
+                * so we cannot know whether this linkEA is valid or not.
+                * So keep it there and maybe resolved when next LFSCK run. */
+               if (!(ns->ln_flags & LF_INCOMPLETE)) {
+                       /* If the child becomes orphan, then insert it into
+                        * the global .lustre/lost+found/MDTxxxx directory. */
+                       rc = lfsck_namespace_insert_orphan(env, com, child,
+                                                          "", "O", &count);
+                       if (rc < 0)
+                               return rc;
 
-               if (rc > 0) {
-                       ns->ln_mul_ref_repaired++;
-                       repaired = true;
+                       if (rc > 0) {
+                               ns->ln_mul_ref_repaired++;
+                               repaired = true;
+                       }
                }
-       }
-
-       rc = dt_attr_get(env, child, la, BYPASS_CAPA);
-       if (rc != 0)
-               return rc;
+       } else {
+               rc = dt_attr_get(env, child, la, BYPASS_CAPA);
+               if (rc != 0)
+                       return rc;
 
-       if (la->la_nlink != count) {
-               rc = lfsck_namespace_repair_nlink(env, com, child,
-                                                 &la->la_nlink);
-               if (rc > 0) {
-                       ns->ln_objs_nlink_repaired++;
-                       rc = 0;
+               if (la->la_nlink != 0 && la->la_nlink != count) {
+                       rc = lfsck_namespace_repair_nlink(env, com, child, la);
+                       if (rc > 0) {
+                               ns->ln_objs_nlink_repaired++;
+                               rc = 0;
+                       }
                }
        }
 
@@ -4041,7 +3914,7 @@ static int lfsck_namespace_exec_oit(const struct lu_env *env,
        struct dt_device         *dev   = lfsck->li_bottom;
        struct seq_server_site   *ss    =
                                lu_site2seq(dev->dd_lu_dev.ld_site);
-       struct linkea_data        ldata = { 0 };
+       struct linkea_data        ldata = { NULL };
        __u32                     idx   = lfsck_dev_idx(dev);
        int                       rc;
        ENTRY;
@@ -4536,50 +4409,6 @@ static int lfsck_namespace_in_notify(const struct lu_env *env,
        ENTRY;
 
        switch (lr->lr_event) {
-       case LE_CREATE_ORPHAN: {
-               struct dt_object *orphan = NULL;
-               struct lmv_mds_md_v1 *lmv;
-
-               CDEBUG(D_LFSCK, "%s: namespace LFSCK handling notify from "
-                      "MDT %x to create orphan"DFID" with type %o\n",
-                      lfsck_lfsck2name(lfsck), lr->lr_index,
-                      PFID(&lr->lr_fid), lr->lr_type);
-
-               orphan = lfsck_object_find(env, lfsck, &lr->lr_fid);
-               if (IS_ERR(orphan))
-                       GOTO(out_create, rc = PTR_ERR(orphan));
-
-               if (dt_object_exists(orphan))
-                       GOTO(out_create, rc = -EEXIST);
-
-               if (lr->lr_stripe_count > 0) {
-                       lmv = &lfsck_env_info(env)->lti_lmv;
-                       memset(lmv, 0, sizeof(*lmv));
-                       lmv->lmv_hash_type = lr->lr_hash_type;
-                       lmv->lmv_stripe_count = lr->lr_stripe_count;
-                       lmv->lmv_layout_version = lr->lr_layout_version;
-                       memcpy(lmv->lmv_pool_name, lr->lr_pool_name,
-                              sizeof(lmv->lmv_pool_name));
-               } else {
-                       lmv = NULL;
-               }
-
-               rc = lfsck_namespace_create_orphan_local(env, com, orphan,
-                                                        lr->lr_type, lmv);
-
-               GOTO(out_create, rc = (rc == 1) ? 0 : rc);
-
-out_create:
-               CDEBUG(D_LFSCK, "%s: namespace LFSCK handled notify from "
-                      "MDT %x to create orphan"DFID" with type %o: rc = %d\n",
-                      lfsck_lfsck2name(lfsck), lr->lr_index,
-                      PFID(&lr->lr_fid), lr->lr_type, rc);
-
-               if (orphan != NULL && !IS_ERR(orphan))
-                       lfsck_object_put(env, orphan);
-
-               return rc;
-       }
        case LE_SKIP_NLINK_DECLARE: {
                struct dt_object        *obj   = com->lc_obj;
                struct lu_fid           *key   = &lfsck_env_info(env)->lti_fid3;
@@ -4807,7 +4636,7 @@ int lfsck_namespace_repair_dangling(const struct lu_env *env,
        struct lmv_mds_md_v1            *lmv2   = &info->lti_lmv2;
        struct dt_object                *parent = lnr->lnr_obj;
        const struct lu_name            *cname;
-       struct linkea_data               ldata  = { 0 };
+       struct linkea_data               ldata  = { NULL };
        struct lustre_handle             lh     = { 0 };
        struct lu_buf                    linkea_buf;
        struct lu_buf                    lmv_buf;
@@ -5014,7 +4843,7 @@ static int lfsck_namespace_assistant_handler_p1(const struct lu_env *env,
        struct lfsck_instance      *lfsck    = com->lc_lfsck;
        struct lfsck_bookmark      *bk       = &lfsck->li_bookmark_ram;
        struct lfsck_namespace     *ns       = com->lc_file_ram;
-       struct linkea_data          ldata    = { 0 };
+       struct linkea_data          ldata    = { NULL };
        const struct lu_name       *cname;
        struct thandle             *handle   = NULL;
        struct lfsck_namespace_req *lnr      =
@@ -6242,7 +6071,7 @@ int lfsck_verify_linkea(const struct lu_env *env, struct dt_device *dev,
                        struct dt_object *obj, const struct lu_name *cname,
                        const struct lu_fid *pfid)
 {
-       struct linkea_data       ldata  = { 0 };
+       struct linkea_data       ldata  = { NULL };
        struct lu_buf            linkea_buf;
        struct thandle          *th;
        int                      rc;
@@ -6321,7 +6150,7 @@ int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
                          char *name, struct lu_fid *pfid)
 {
        struct lu_name           *cname = &lfsck_env_info(env)->lti_name;
-       struct linkea_data        ldata = { 0 };
+       struct linkea_data        ldata = { NULL };
        int                       rc;
 
        rc = lfsck_links_read(env, obj, &ldata);
@@ -6341,82 +6170,6 @@ int lfsck_links_get_first(const struct lu_env *env, struct dt_object *obj,
 }
 
 /**
- * Remove the name entry from the parent directory.
- *
- * No need to care about the object referenced by the name entry,
- * either the name entry is invalid or redundant, or the referenced
- * object has been processed has been or will be handled by others.
- *
- * \param[in] env      pointer to the thread context
- * \param[in] lfsck    pointer to the lfsck instance
- * \param[in] parent   pointer to the lost+found object
- * \param[in] name     the name for the name entry to be removed
- * \param[in] type     the type for the name entry to be removed
- *
- * \retval             0 for success
- * \retval             negative error number on failure
- */
-int lfsck_remove_name_entry(const struct lu_env *env,
-                           struct lfsck_instance *lfsck,
-                           struct dt_object *parent,
-                           const char *name, __u32 type)
-{
-       struct dt_device        *dev    = lfsck->li_next;
-       struct thandle          *th;
-       struct lustre_handle     lh     = { 0 };
-       int                      rc;
-       ENTRY;
-
-       rc = lfsck_ibits_lock(env, lfsck, parent, &lh,
-                             MDS_INODELOCK_UPDATE, LCK_EX);
-       if (rc != 0)
-               RETURN(rc);
-
-       th = dt_trans_create(env, dev);
-       if (IS_ERR(th))
-               GOTO(unlock, rc = PTR_ERR(th));
-
-       rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
-       if (rc != 0)
-               GOTO(stop, rc);
-
-       if (S_ISDIR(type)) {
-               rc = dt_declare_ref_del(env, parent, th);
-               if (rc != 0)
-                       GOTO(stop, rc);
-       }
-
-       rc = dt_trans_start(env, dev, th);
-       if (rc != 0)
-               GOTO(stop, rc);
-
-       rc = dt_delete(env, parent, (const struct dt_key *)name, th,
-                      BYPASS_CAPA);
-       if (rc != 0)
-               GOTO(stop, rc);
-
-       if (S_ISDIR(type)) {
-               dt_write_lock(env, parent, 0);
-               rc = dt_ref_del(env, parent, th);
-               dt_write_unlock(env, parent);
-       }
-
-       GOTO(stop, rc);
-
-stop:
-       dt_trans_stop(env, dev, th);
-
-unlock:
-       lfsck_ibits_unlock(&lh, LCK_EX);
-
-       CDEBUG(D_LFSCK, "%s: remove name entry "DFID"/%s "
-              "with type %o: rc = %d\n", lfsck_lfsck2name(lfsck),
-              PFID(lfsck_dto2fid(parent)), name, type, rc);
-
-       return rc;
-}
-
-/**
  * Update the object's name entry with the given FID.
  *
  * \param[in] env      pointer to the thread context