Whamcloud - gitweb
LU-4788 lfsck: replace cfs_list_t with list_head
[fs/lustre-release.git] / lustre / lfsck / lfsck_lib.c
index aff81bc..566a99e 100644 (file)
@@ -58,7 +58,7 @@ static void lfsck_key_fini(const struct lu_context *ctx,
 LU_CONTEXT_KEY_DEFINE(lfsck, LCT_MD_THREAD | LCT_DT_THREAD);
 LU_KEY_INIT_GENERIC(lfsck);
 
-static CFS_LIST_HEAD(lfsck_instance_list);
+static struct list_head lfsck_instance_list;
 static struct list_head lfsck_ost_orphan_list;
 static struct list_head lfsck_mdt_orphan_list;
 static DEFINE_SPINLOCK(lfsck_instance_lock);
@@ -244,11 +244,9 @@ static int lfsck_add_target_from_orphan(const struct lu_env *env,
 again:
        spin_lock(&lfsck_instance_lock);
        list_for_each_entry_safe(ltd, next, head, ltd_orphan_list) {
-               if (ltd->ltd_key == lfsck->li_bottom) {
-                       list_del_init(&ltd->ltd_orphan_list);
-                       list_add_tail(&ltd->ltd_orphan_list,
-                                     &ltds->ltd_orphan);
-               }
+               if (ltd->ltd_key == lfsck->li_bottom)
+                       list_move_tail(&ltd->ltd_orphan_list,
+                                      &ltds->ltd_orphan);
        }
        spin_unlock(&lfsck_instance_lock);
 
@@ -279,11 +277,12 @@ again:
 }
 
 static inline struct lfsck_component *
-__lfsck_component_find(struct lfsck_instance *lfsck, __u16 type, cfs_list_t *list)
+__lfsck_component_find(struct lfsck_instance *lfsck, __u16 type,
+                      struct list_head *list)
 {
        struct lfsck_component *com;
 
-       cfs_list_for_each_entry(com, list, lc_link) {
+       list_for_each_entry(com, list, lc_link) {
                if (com->lc_type == type)
                        return com;
        }
@@ -317,10 +316,10 @@ unlock:
 void lfsck_component_cleanup(const struct lu_env *env,
                             struct lfsck_component *com)
 {
-       if (!cfs_list_empty(&com->lc_link))
-               cfs_list_del_init(&com->lc_link);
-       if (!cfs_list_empty(&com->lc_link_dir))
-               cfs_list_del_init(&com->lc_link_dir);
+       if (!list_empty(&com->lc_link))
+               list_del_init(&com->lc_link);
+       if (!list_empty(&com->lc_link_dir))
+               list_del_init(&com->lc_link_dir);
 
        lfsck_component_put(env, com);
 }
@@ -353,6 +352,8 @@ int lfsck_fid_alloc(const struct lu_env *env, struct lfsck_instance *lfsck,
 
 static const char dot[] = ".";
 static const char dotdot[] = "..";
+static const char dotlustre[] = ".lustre";
+static const char lostfound[] = "lost+found";
 
 static int lfsck_create_lpf_local(const struct lu_env *env,
                                  struct lfsck_instance *lfsck,
@@ -362,16 +363,30 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
                                  struct dt_object_format *dof,
                                  const char *name)
 {
+       struct dt_insert_rec    *rec    = &lfsck_env_info(env)->lti_dt_rec;
        struct dt_device        *dev    = lfsck->li_bottom;
        struct lfsck_bookmark   *bk     = &lfsck->li_bookmark_ram;
        struct dt_object        *bk_obj = lfsck->li_bookmark_obj;
-       const struct lu_fid     *cfid   = lu_object_fid(&child->do_lu);
+       const struct lu_fid     *cfid   = lfsck_dto2fid(child);
        struct thandle          *th     = NULL;
+       struct linkea_data       ldata  = { 0 };
+       struct lu_buf            linkea_buf;
+       const struct lu_name    *cname;
        loff_t                   pos    = 0;
        int                      len    = sizeof(struct lfsck_bookmark);
-       int                      rc     = 0;
+       int                      rc;
        ENTRY;
 
+       rc = linkea_data_new(&ldata,
+                            &lfsck_env_info(env)->lti_linkea_buf);
+       if (rc != 0)
+               RETURN(rc);
+
+       cname = lfsck_name_get_const(env, name, strlen(name));
+       rc = linkea_add_buf(&ldata, cname, lfsck_dto2fid(parent));
+       if (rc != 0)
+               RETURN(rc);
+
        th = dt_trans_create(env, dev);
        if (IS_ERR(th))
                RETURN(PTR_ERR(th));
@@ -386,18 +401,28 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
        if (rc != 0)
                GOTO(stop, rc);
 
-       /* 3a. insert name into parent dir */
-       rc = dt_declare_insert(env, parent, (const struct dt_rec *)cfid,
+       /* 3a. insert linkEA for child */
+       linkea_buf.lb_buf = ldata.ld_buf->lb_buf;
+       linkea_buf.lb_len = ldata.ld_leh->leh_len;
+       rc = dt_declare_xattr_set(env, child, &linkea_buf,
+                                 XATTR_NAME_LINK, 0, th);
+       if (rc != 0)
+               GOTO(stop, rc);
+
+       /* 4a. insert name into parent dir */
+       rec->rec_type = S_IFDIR;
+       rec->rec_fid = cfid;
+       rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
                               (const struct dt_key *)name, th);
        if (rc != 0)
                GOTO(stop, rc);
 
-       /* 4a. increase parent nlink */
+       /* 5a. increase parent nlink */
        rc = dt_declare_ref_add(env, parent, th);
        if (rc != 0)
                GOTO(stop, rc);
 
-       /* 5a. update bookmark */
+       /* 6a. update bookmark */
        rc = dt_declare_record_write(env, bk_obj,
                                     lfsck_buf_get(env, bk, len), 0, th);
        if (rc != 0)
@@ -408,7 +433,7 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
                GOTO(stop, rc);
 
        dt_write_lock(env, child, 0);
-       /* 1b.1 create child */
+       /* 1b.1. create child */
        rc = dt_create(env, child, la, NULL, dof, th);
        if (rc != 0)
                GOTO(unlock, rc);
@@ -416,32 +441,41 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
        if (unlikely(!dt_try_as_dir(env, child)))
                GOTO(unlock, rc = -ENOTDIR);
 
-       /* 1b.2 insert dot into child dir */
-       rc = dt_insert(env, child, (const struct dt_rec *)cfid,
+       /* 1b.2. insert dot into child dir */
+       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(unlock, rc);
 
-       /* 1b.3 insert dotdot into child dir */
-       rc = dt_insert(env, child, (const struct dt_rec *)&LU_LPF_FID,
+       /* 1b.3. insert dotdot into child dir */
+       rec->rec_fid = &LU_LPF_FID;
+       rc = dt_insert(env, child, (const struct dt_rec *)rec,
                       (const struct dt_key *)dotdot, th, BYPASS_CAPA, 1);
        if (rc != 0)
                GOTO(unlock, rc);
 
        /* 2b. increase child nlink */
        rc = dt_ref_add(env, child, th);
+       if (rc != 0)
+               GOTO(unlock, rc);
+
+       /* 3b. insert linkEA for child. */
+       rc = dt_xattr_set(env, child, &linkea_buf,
+                         XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
        dt_write_unlock(env, child);
        if (rc != 0)
                GOTO(stop, rc);
 
-       /* 3b. insert name into parent dir */
-       rc = dt_insert(env, parent, (const struct dt_rec *)cfid,
+       /* 4b. insert name into parent dir */
+       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)
                GOTO(stop, rc);
 
        dt_write_lock(env, parent, 0);
-       /* 4b. increase parent nlink */
+       /* 5b. increase parent nlink */
        rc = dt_ref_add(env, parent, th);
        dt_write_unlock(env, parent);
        if (rc != 0)
@@ -450,7 +484,7 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
        bk->lb_lpf_fid = *cfid;
        lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
 
-       /* 5b. update bookmark */
+       /* 6b. update bookmark */
        rc = dt_record_write(env, bk_obj,
                             lfsck_buf_get(env, bk, len), &pos, th);
 
@@ -473,16 +507,30 @@ static int lfsck_create_lpf_remote(const struct lu_env *env,
                                   struct dt_object_format *dof,
                                   const char *name)
 {
+       struct dt_insert_rec    *rec    = &lfsck_env_info(env)->lti_dt_rec;
        struct lfsck_bookmark   *bk     = &lfsck->li_bookmark_ram;
        struct dt_object        *bk_obj = lfsck->li_bookmark_obj;
-       const struct lu_fid     *cfid   = lu_object_fid(&child->do_lu);
+       const struct lu_fid     *cfid   = lfsck_dto2fid(child);
        struct thandle          *th     = NULL;
+       struct linkea_data       ldata  = { 0 };
+       struct lu_buf            linkea_buf;
+       const struct lu_name    *cname;
        struct dt_device        *dev;
        loff_t                   pos    = 0;
        int                      len    = sizeof(struct lfsck_bookmark);
-       int                      rc     = 0;
+       int                      rc;
        ENTRY;
 
+       rc = linkea_data_new(&ldata,
+                            &lfsck_env_info(env)->lti_linkea_buf);
+       if (rc != 0)
+               RETURN(rc);
+
+       cname = lfsck_name_get_const(env, name, strlen(name));
+       rc = linkea_add_buf(&ldata, cname, lfsck_dto2fid(parent));
+       if (rc != 0)
+               RETURN(rc);
+
        /* Create .lustre/lost+found/MDTxxxx. */
 
        /* XXX: Currently, cross-MDT create operation needs to create the child
@@ -495,37 +543,51 @@ static int lfsck_create_lpf_remote(const struct lu_env *env,
         *      To avoid more inconsistency, we split the create operation into
         *      two transactions:
         *
-        *      1) create the child locally.
+        *      1) create the child and update the lfsck_bookmark::lb_lpf_fid
+        *         locally.
         *      2) insert the name "MDTXXXX" in the parent ".lustre/lost+found"
-        *         remotely and update the lfsck_bookmark::lb_lpf_fid locally.
+        *         remotely.
         *
-        *      If 1) done but 2) failed, then the worst case is that we lose
-        *      one object locally, which is not a big issue. (can be repaird
-        *      by LFSCK phase III) */
+        *      If 1) done, but 2) failed, then go ahead, the LFSCK will try to
+        *      repair such inconsistency when LFSCK run next time. */
 
-       /* Transaction I: */
+       /* Transaction I: locally */
 
        dev = lfsck->li_bottom;
        th = dt_trans_create(env, dev);
        if (IS_ERR(th))
                RETURN(PTR_ERR(th));
 
-       /* 1a. create child locally. */
+       /* 1a. create child */
        rc = dt_declare_create(env, child, la, NULL, dof, th);
        if (rc != 0)
                GOTO(stop, rc);
 
-       /* 2a. increase child nlink locally. */
+       /* 2a. increase child nlink */
        rc = dt_declare_ref_add(env, child, th);
        if (rc != 0)
                GOTO(stop, rc);
 
+       /* 3a. insert linkEA for child */
+       linkea_buf.lb_buf = ldata.ld_buf->lb_buf;
+       linkea_buf.lb_len = ldata.ld_leh->leh_len;
+       rc = dt_declare_xattr_set(env, child, &linkea_buf,
+                                 XATTR_NAME_LINK, 0, th);
+       if (rc != 0)
+               GOTO(stop, rc);
+
+       /* 4a. update bookmark */
+       rc = dt_declare_record_write(env, bk_obj,
+                                    lfsck_buf_get(env, bk, len), 0, th);
+       if (rc != 0)
+               GOTO(stop, rc);
+
        rc = dt_trans_start_local(env, dev, th);
        if (rc != 0)
                GOTO(stop, rc);
 
        dt_write_lock(env, child, 0);
-       /* 1b. create child locally. */
+       /* 1b.1. create child */
        rc = dt_create(env, child, la, NULL, dof, th);
        if (rc != 0)
                GOTO(unlock, rc);
@@ -533,95 +595,77 @@ static int lfsck_create_lpf_remote(const struct lu_env *env,
        if (unlikely(!dt_try_as_dir(env, child)))
                GOTO(unlock, rc = -ENOTDIR);
 
-       /* 2b.1 insert dot into child dir locally. */
-       rc = dt_insert(env, child, (const struct dt_rec *)cfid,
+       /* 1b.2. insert dot into child dir */
+       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(unlock, rc);
 
-       /* 2b.2 insert dotdot into child dir locally. */
-       rc = dt_insert(env, child, (const struct dt_rec *)&LU_LPF_FID,
+       /* 1b.3. insert dotdot into child dir */
+       rec->rec_fid = &LU_LPF_FID;
+       rc = dt_insert(env, child, (const struct dt_rec *)rec,
                       (const struct dt_key *)dotdot, th, BYPASS_CAPA, 1);
        if (rc != 0)
                GOTO(unlock, rc);
 
-       /* 2b.3 increase child nlink locally. */
+       /* 2b. increase child nlink */
        rc = dt_ref_add(env, child, th);
+       if (rc != 0)
+               GOTO(unlock, rc);
+
+       /* 3b. insert linkEA for child */
+       rc = dt_xattr_set(env, child, &linkea_buf,
+                         XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
+       if (rc != 0)
+               GOTO(unlock, rc);
+
+       bk->lb_lpf_fid = *cfid;
+       lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
+
+       /* 4b. update bookmark */
+       rc = dt_record_write(env, bk_obj,
+                            lfsck_buf_get(env, bk, len), &pos, th);
+
        dt_write_unlock(env, child);
        dt_trans_stop(env, dev, th);
        if (rc != 0)
                RETURN(rc);
 
-       /* Transaction II: */
+       /* Transaction II: remotely */
 
        dev = lfsck->li_next;
        th = dt_trans_create(env, dev);
        if (IS_ERR(th))
                RETURN(PTR_ERR(th));
 
-       /* 3a. insert name into parent dir remotely. */
-       rc = dt_declare_insert(env, parent, (const struct dt_rec *)cfid,
+       /* 5a. insert name into parent dir */
+       rec->rec_fid = cfid;
+       rc = dt_declare_insert(env, parent, (const struct dt_rec *)rec,
                               (const struct dt_key *)name, th);
        if (rc != 0)
                GOTO(stop, rc);
 
-       /* 4a. increase parent nlink remotely. */
+       /* 6a. increase parent nlink */
        rc = dt_declare_ref_add(env, parent, th);
        if (rc != 0)
                GOTO(stop, rc);
 
-       /* 5a. decrease child nlink for dotdot locally if former remote
-        *     update failed. */
-       rc = dt_declare_ref_del(env, child, th);
-       if (rc != 0)
-               GOTO(stop, rc);
-
-       /* 6a. decrease child nlink for dot locally if former remote
-        *     update failed. */
-       rc = dt_declare_ref_del(env, child, th);
-       if (rc != 0)
-               GOTO(stop, rc);
-
-       /* 7a. destroy child locally if former remote update failed. */
-       rc = dt_declare_destroy(env, child, th);
-       if (rc != 0)
-               GOTO(stop, rc);
-
-       /* 8a. update bookmark locally. */
-       rc = dt_declare_record_write(env, bk_obj,
-                                    lfsck_buf_get(env, bk, len), 0, th);
-       if (rc != 0)
-               GOTO(stop, rc);
-
        rc = dt_trans_start(env, dev, th);
        if (rc != 0)
                GOTO(stop, rc);
 
-       /* 3b. insert name into parent dir remotely. */
-       rc = dt_insert(env, parent, (const struct dt_rec *)cfid,
+       /* 5b. insert name into parent dir */
+       rc = dt_insert(env, parent, (const struct dt_rec *)rec,
                       (const struct dt_key *)name, th, BYPASS_CAPA, 1);
-       if (rc == 0) {
-               dt_write_lock(env, parent, 0);
-               /* 4b. increase parent nlink remotely. */
-               rc = dt_ref_add(env, parent, th);
-               dt_write_unlock(env, parent);
-       }
-       if (rc != 0) {
-               /* 5b. decrease child nlink for dotdot locally. */
-               dt_ref_del(env, child, th);
-               /* 6b. decrease child nlink for dot locally. */
-               dt_ref_del(env, child, th);
-               /* 7b. destroy child locally. */
-               dt_destroy(env, child, th);
+       if (rc != 0)
                GOTO(stop, rc);
-       }
 
-       bk->lb_lpf_fid = *cfid;
-       lfsck_bookmark_cpu_to_le(&lfsck->li_bookmark_disk, bk);
-
-       /* 8b. update bookmark locally. */
-       rc = dt_record_write(env, bk_obj,
-                            lfsck_buf_get(env, bk, len), &pos, th);
+       dt_write_lock(env, parent, 0);
+       /* 6b. increase parent nlink */
+       rc = dt_ref_add(env, parent, th);
+       dt_write_unlock(env, parent);
 
        GOTO(stop, rc);
 
@@ -630,6 +674,13 @@ unlock:
 stop:
        dt_trans_stop(env, dev, th);
 
+       if (rc != 0 && dev == lfsck->li_next)
+               CDEBUG(D_LFSCK, "%s: partially created the object "DFID
+                      "for orphans, but failed to insert the name %s "
+                      "to the .lustre/lost+found/. Such inconsistency "
+                      "will be repaired when LFSCK run next time: rc = %d\n",
+                      lfsck_lfsck2name(lfsck), PFID(cfid), name, rc);
+
        return rc;
 }
 
@@ -705,10 +756,11 @@ int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
 
        if (dt_object_exists(child) != 0) {
                if (unlikely(!dt_try_as_dir(env, child)))
-                       GOTO(unlock, rc = -ENOTDIR);
+                       rc = -ENOTDIR;
+               else
+                       lfsck->li_lpf_obj = child;
 
-               lfsck->li_lpf_obj = child;
-               GOTO(unlock, rc = 0);
+               GOTO(unlock, rc);
        }
 
        memset(la, 0, sizeof(*la));
@@ -794,6 +846,7 @@ void lfsck_instance_cleanup(const struct lu_env *env,
 {
        struct ptlrpc_thread    *thread = &lfsck->li_thread;
        struct lfsck_component  *com;
+       struct lfsck_component  *next;
        ENTRY;
 
        LASSERT(list_empty(&lfsck->li_link));
@@ -806,26 +859,18 @@ void lfsck_instance_cleanup(const struct lu_env *env,
 
        LASSERT(lfsck->li_obj_dir == NULL);
 
-       while (!cfs_list_empty(&lfsck->li_list_scan)) {
-               com = cfs_list_entry(lfsck->li_list_scan.next,
-                                    struct lfsck_component,
-                                    lc_link);
+       list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
                lfsck_component_cleanup(env, com);
        }
 
-       LASSERT(cfs_list_empty(&lfsck->li_list_dir));
+       LASSERT(list_empty(&lfsck->li_list_dir));
 
-       while (!cfs_list_empty(&lfsck->li_list_double_scan)) {
-               com = cfs_list_entry(lfsck->li_list_double_scan.next,
-                                    struct lfsck_component,
-                                    lc_link);
+       list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
+                                lc_link) {
                lfsck_component_cleanup(env, com);
        }
 
-       while (!cfs_list_empty(&lfsck->li_list_idle)) {
-               com = cfs_list_entry(lfsck->li_list_idle.next,
-                                    struct lfsck_component,
-                                    lc_link);
+       list_for_each_entry_safe(com, next, &lfsck->li_list_idle, lc_link) {
                lfsck_component_cleanup(env, com);
        }
 
@@ -857,7 +902,7 @@ __lfsck_instance_find(struct dt_device *key, bool ref, bool unlink)
 {
        struct lfsck_instance *lfsck;
 
-       cfs_list_for_each_entry(lfsck, &lfsck_instance_list, li_link) {
+       list_for_each_entry(lfsck, &lfsck_instance_list, li_link) {
                if (lfsck->li_bottom == key) {
                        if (ref)
                                lfsck_instance_get(lfsck);
@@ -888,33 +933,27 @@ static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
        struct lfsck_instance *tmp;
 
        spin_lock(&lfsck_instance_lock);
-       cfs_list_for_each_entry(tmp, &lfsck_instance_list, li_link) {
+       list_for_each_entry(tmp, &lfsck_instance_list, li_link) {
                if (lfsck->li_bottom == tmp->li_bottom) {
                        spin_unlock(&lfsck_instance_lock);
                        return -EEXIST;
                }
        }
 
-       cfs_list_add_tail(&lfsck->li_link, &lfsck_instance_list);
+       list_add_tail(&lfsck->li_link, &lfsck_instance_list);
        spin_unlock(&lfsck_instance_lock);
        return 0;
 }
 
-int lfsck_bits_dump(char **buf, int *len, int bits, const char *names[],
+int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
                    const char *prefix)
 {
-       int save = *len;
        int flag;
-       int rc;
        int i;
        bool newline = (bits != 0 ? false : true);
 
-       rc = snprintf(*buf, *len, "%s:%c", prefix, newline ? '\n' : ' ');
-       if (rc <= 0)
-               return -ENOSPC;
+       seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
 
-       *buf += rc;
-       *len -= rc;
        for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
                if (flag & bits) {
                        bits &= ~flag;
@@ -922,69 +961,43 @@ int lfsck_bits_dump(char **buf, int *len, int bits, const char *names[],
                                if (bits == 0)
                                        newline = true;
 
-                               rc = snprintf(*buf, *len, "%s%c", names[i],
-                                             newline ? '\n' : ',');
-                               if (rc <= 0)
-                                       return -ENOSPC;
-
-                               *buf += rc;
-                               *len -= rc;
+                               seq_printf(m, "%s%c", names[i],
+                                          newline ? '\n' : ',');
                        }
                }
        }
 
-       if (!newline) {
-               rc = snprintf(*buf, *len, "\n");
-               if (rc <= 0)
-                       return -ENOSPC;
-
-               *buf += rc;
-               *len -= rc;
-       }
-
-       return save - *len;
+       if (!newline)
+               seq_printf(m, "\n");
+       return 0;
 }
 
-int lfsck_time_dump(char **buf, int *len, __u64 time, const char *prefix)
+int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix)
 {
-       int rc;
-
        if (time != 0)
-               rc = snprintf(*buf, *len, "%s: "LPU64" seconds\n", prefix,
-                             cfs_time_current_sec() - time);
+               seq_printf(m, "%s: "LPU64" seconds\n", prefix,
+                         cfs_time_current_sec() - time);
        else
-               rc = snprintf(*buf, *len, "%s: N/A\n", prefix);
-       if (rc <= 0)
-               return -ENOSPC;
-
-       *buf += rc;
-       *len -= rc;
-       return rc;
+               seq_printf(m, "%s: N/A\n", prefix);
+       return 0;
 }
 
-int lfsck_pos_dump(char **buf, int *len, struct lfsck_position *pos,
+int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
                   const char *prefix)
 {
-       int rc;
-
        if (fid_is_zero(&pos->lp_dir_parent)) {
                if (pos->lp_oit_cookie == 0)
-                       rc = snprintf(*buf, *len, "%s: N/A, N/A, N/A\n",
-                                     prefix);
+                       seq_printf(m, "%s: N/A, N/A, N/A\n",
+                                  prefix);
                else
-                       rc = snprintf(*buf, *len, "%s: "LPU64", N/A, N/A\n",
-                                     prefix, pos->lp_oit_cookie);
+                       seq_printf(m, "%s: "LPU64", N/A, N/A\n",
+                                  prefix, pos->lp_oit_cookie);
        } else {
-               rc = snprintf(*buf, *len, "%s: "LPU64", "DFID", "LPU64"\n",
-                             prefix, pos->lp_oit_cookie,
-                             PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
+               seq_printf(m, "%s: "LPU64", "DFID", "LPX64"\n",
+                          prefix, pos->lp_oit_cookie,
+                          PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
        }
-       if (rc <= 0)
-               return -ENOSPC;
-
-       *buf += rc;
-       *len -= rc;
-       return rc;
+       return 0;
 }
 
 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
@@ -1101,7 +1114,7 @@ static int lfsck_needs_scan_dir(const struct lu_env *env,
        int            rc;
 
        if (!lfsck->li_master || !S_ISDIR(lfsck_object_type(obj)) ||
-           cfs_list_empty(&lfsck->li_list_dir))
+           list_empty(&lfsck->li_list_dir))
               RETURN(0);
 
        while (1) {
@@ -1226,7 +1239,7 @@ void lfsck_fail(const struct lu_env *env, struct lfsck_instance *lfsck,
 {
        struct lfsck_component *com;
 
-       cfs_list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
+       list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
                com->lc_ops->lfsck_fail(env, com, new_checked);
        }
 }
@@ -1242,7 +1255,7 @@ int lfsck_checkpoint(const struct lu_env *env, struct lfsck_instance *lfsck)
                return 0;
 
        lfsck_pos_fill(env, lfsck, &lfsck->li_pos_current, false);
-       cfs_list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
+       list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
                rc = com->lc_ops->lfsck_checkpoint(env, com, false);
                if (rc != 0)
                        rc1 = rc;
@@ -1271,7 +1284,7 @@ int lfsck_prep(const struct lu_env *env, struct lfsck_instance *lfsck,
        LASSERT(lfsck->li_di_dir == NULL);
 
        lfsck->li_current_oit_processed = 0;
-       cfs_list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
+       list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
                com->lc_new_checked = 0;
                if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
                        com->lc_journal = 0;
@@ -1355,8 +1368,8 @@ out:
                lfsck_object_put(env, obj);
 
        if (rc < 0) {
-               cfs_list_for_each_entry_safe(com, next, &lfsck->li_list_scan,
-                                            lc_link)
+               list_for_each_entry_safe(com, next, &lfsck->li_list_scan,
+                                        lc_link)
                        com->lc_ops->lfsck_post(env, com, rc, true);
 
                return rc;
@@ -1364,7 +1377,7 @@ out:
 
        rc = 0;
        lfsck_pos_fill(env, lfsck, &lfsck->li_pos_current, true);
-       cfs_list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
+       list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
                rc = com->lc_ops->lfsck_checkpoint(env, com, true);
                if (rc != 0)
                        break;
@@ -1387,7 +1400,7 @@ int lfsck_exec_oit(const struct lu_env *env, struct lfsck_instance *lfsck,
 
        LASSERT(lfsck->li_obj_dir == NULL);
 
-       cfs_list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
+       list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
                rc = com->lc_ops->lfsck_exec_oit(env, com, obj);
                if (rc != 0)
                        RETURN(rc);
@@ -1437,7 +1450,7 @@ int lfsck_exec_dir(const struct lu_env *env, struct lfsck_instance *lfsck,
        struct lfsck_component *com;
        int                     rc;
 
-       cfs_list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
+       list_for_each_entry(com, &lfsck->li_list_scan, lc_link) {
                rc = com->lc_ops->lfsck_exec_dir(env, com, obj, ent);
                if (rc != 0)
                        return rc;
@@ -1454,7 +1467,7 @@ int lfsck_post(const struct lu_env *env, struct lfsck_instance *lfsck,
        int                     rc1 = 0;
 
        lfsck_pos_fill(env, lfsck, &lfsck->li_pos_current, false);
-       cfs_list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
+       list_for_each_entry_safe(com, next, &lfsck->li_list_scan, lc_link) {
                rc = com->lc_ops->lfsck_post(env, com, result, false);
                if (rc != 0)
                        rc1 = rc;
@@ -1521,8 +1534,7 @@ int lfsck_double_scan(const struct lu_env *env, struct lfsck_instance *lfsck)
                list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
                                         lc_link) {
                        spin_lock(&lfsck->li_lock);
-                       list_del_init(&com->lc_link);
-                       list_add_tail(&com->lc_link, &lfsck->li_list_idle);
+                       list_move_tail(&com->lc_link, &lfsck->li_list_idle);
                        spin_unlock(&lfsck->li_lock);
                }
        }
@@ -1547,7 +1559,7 @@ static int lfsck_stop_notify(const struct lu_env *env,
                                             &lfsck->li_list_double_scan);
        if (com != NULL)
                lfsck_component_get(com);
-       spin_lock(&lfsck->li_lock);
+       spin_unlock(&lfsck->li_lock);
 
        if (com != NULL) {
                if (com->lc_ops->lfsck_stop_notify != NULL) {
@@ -1583,9 +1595,8 @@ void lfsck_quit(const struct lu_env *env, struct lfsck_instance *lfsck)
                        com->lc_ops->lfsck_quit(env, com);
 
                spin_lock(&lfsck->li_lock);
-               list_del_init(&com->lc_link);
                list_del_init(&com->lc_link_dir);
-               list_add_tail(&com->lc_link, &lfsck->li_list_idle);
+               list_move_tail(&com->lc_link, &lfsck->li_list_idle);
                spin_unlock(&lfsck->li_lock);
        }
 
@@ -1595,8 +1606,7 @@ void lfsck_quit(const struct lu_env *env, struct lfsck_instance *lfsck)
                        com->lc_ops->lfsck_quit(env, com);
 
                spin_lock(&lfsck->li_lock);
-               list_del_init(&com->lc_link);
-               list_add_tail(&com->lc_link, &lfsck->li_list_idle);
+               list_move_tail(&com->lc_link, &lfsck->li_list_idle);
                spin_unlock(&lfsck->li_lock);
        }
 }
@@ -1638,8 +1648,8 @@ int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
                format = &RQF_LFSCK_QUERY;
                break;
        default:
-               CERROR("%s: unknown async request: opc = %d\n",
-                      exp->exp_obd->obd_name, request);
+               CDEBUG(D_LFSCK, "%s: unknown async request %d: rc = %d\n",
+                      exp->exp_obd->obd_name, request, -EINVAL);
                return -EINVAL;
        }
 
@@ -1670,7 +1680,7 @@ int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
 
 /* external interfaces */
 
-int lfsck_get_speed(struct dt_device *key, void *buf, int len)
+int lfsck_get_speed(struct seq_file *m, struct dt_device *key)
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -1683,8 +1693,7 @@ int lfsck_get_speed(struct dt_device *key, void *buf, int len)
 
        lfsck = lfsck_instance_find(key, true, false);
        if (likely(lfsck != NULL)) {
-               rc = snprintf(buf, len, "%u\n",
-                             lfsck->li_bookmark_ram.lb_speed_limit);
+               seq_printf(m, "%u\n", lfsck->li_bookmark_ram.lb_speed_limit);
                lfsck_instance_put(&env, lfsck);
        } else {
                rc = -ENXIO;
@@ -1724,7 +1733,7 @@ int lfsck_set_speed(struct dt_device *key, int val)
 }
 EXPORT_SYMBOL(lfsck_set_speed);
 
-int lfsck_get_windows(struct dt_device *key, void *buf, int len)
+int lfsck_get_windows(struct seq_file *m, struct dt_device *key)
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -1737,8 +1746,7 @@ int lfsck_get_windows(struct dt_device *key, void *buf, int len)
 
        lfsck = lfsck_instance_find(key, true, false);
        if (likely(lfsck != NULL)) {
-               rc = snprintf(buf, len, "%u\n",
-                             lfsck->li_bookmark_ram.lb_async_windows);
+               seq_printf(m, "%u\n", lfsck->li_bookmark_ram.lb_async_windows);
                lfsck_instance_put(&env, lfsck);
        } else {
                rc = -ENXIO;
@@ -1788,7 +1796,7 @@ int lfsck_set_windows(struct dt_device *key, int val)
 }
 EXPORT_SYMBOL(lfsck_set_windows);
 
-int lfsck_dump(struct dt_device *key, void *buf, int len, enum lfsck_type type)
+int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -1804,7 +1812,7 @@ int lfsck_dump(struct dt_device *key, void *buf, int len, enum lfsck_type type)
        if (likely(lfsck != NULL)) {
                com = lfsck_component_find(lfsck, type);
                if (likely(com != NULL)) {
-                       rc = com->lc_ops->lfsck_dump(&env, com, buf, len);
+                       rc = com->lc_ops->lfsck_dump(&env, com, m);
                        lfsck_component_put(&env, com);
                } else {
                        rc = -ENOTSUPP;
@@ -1840,12 +1848,8 @@ static int lfsck_stop_all(const struct lu_env *env,
        LASSERT(stop->ls_flags & LPF_BROADCAST);
 
        set = ptlrpc_prep_set();
-       if (unlikely(set == NULL)) {
-               CERROR("%s: cannot allocate memory for stop LFSCK on "
-                      "all targets\n", lfsck_lfsck2name(lfsck));
-
+       if (unlikely(set == NULL))
                RETURN(-ENOMEM);
-       }
 
        memset(lr, 0, sizeof(*lr));
        lr->lr_event = LE_STOP;
@@ -1873,8 +1877,8 @@ static int lfsck_stop_all(const struct lu_env *env,
                if (rc != 0) {
                        lfsck_interpret(env, lfsck, NULL, laia, rc);
                        lfsck_tgt_put(ltd);
-                       CWARN("%s: cannot notify MDT %x for LFSCK stop: "
-                             "rc = %d\n", lfsck_lfsck2name(lfsck), idx, rc);
+                       CERROR("%s: cannot notify MDT %x for LFSCK stop: "
+                              "rc = %d\n", lfsck_lfsck2name(lfsck), idx, rc);
                        rc1 = rc;
                }
        }
@@ -1890,8 +1894,8 @@ static int lfsck_stop_all(const struct lu_env *env,
                rc = 0;
 
        if (rc != 0)
-               CWARN("%s: fail to stop LFSCK on some MDTs: rc = %d\n",
-                     lfsck_lfsck2name(lfsck), rc);
+               CERROR("%s: fail to stop LFSCK on some MDTs: rc = %d\n",
+                      lfsck_lfsck2name(lfsck), rc);
 
        RETURN(rc != 0 ? rc : rc1);
 }
@@ -1914,21 +1918,8 @@ static int lfsck_start_all(const struct lu_env *env,
        LASSERT(start->ls_flags & LPF_BROADCAST);
 
        set = ptlrpc_prep_set();
-       if (unlikely(set == NULL)) {
-               if (bk->lb_param & LPF_FAILOUT) {
-                       CERROR("%s: cannot allocate memory for start LFSCK on "
-                              "all targets, failout.\n",
-                              lfsck_lfsck2name(lfsck));
-
-                       RETURN(-ENOMEM);
-               } else {
-                       CWARN("%s: cannot allocate memory for start LFSCK on "
-                             "all targets, partly scan.\n",
-                             lfsck_lfsck2name(lfsck));
-
-                       RETURN(0);
-               }
-       }
+       if (unlikely(set == NULL))
+               RETURN(-ENOMEM);
 
        memset(lr, 0, sizeof(*lr));
        lr->lr_event = LE_START;
@@ -1960,17 +1951,10 @@ static int lfsck_start_all(const struct lu_env *env,
                if (rc != 0) {
                        lfsck_interpret(env, lfsck, NULL, laia, rc);
                        lfsck_tgt_put(ltd);
-                       if (bk->lb_param & LPF_FAILOUT) {
-                               CERROR("%s: cannot notify MDT %x for LFSCK "
-                                      "start, failout: rc = %d\n",
-                                      lfsck_lfsck2name(lfsck), idx, rc);
-                               break;
-                       } else {
-                               CWARN("%s: cannot notify MDT %x for LFSCK "
-                                     "start, partly scan: rc = %d\n",
-                                     lfsck_lfsck2name(lfsck), idx, rc);
-                               rc = 0;
-                       }
+                       CERROR("%s: cannot notify MDT %x for LFSCK "
+                              "start, failout: rc = %d\n",
+                              lfsck_lfsck2name(lfsck), idx, rc);
+                       break;
                }
        }
        up_read(&ltds->ltd_rw_sem);
@@ -1988,22 +1972,15 @@ static int lfsck_start_all(const struct lu_env *env,
                rc = laia->laia_result;
 
        if (rc != 0) {
-               if (bk->lb_param & LPF_FAILOUT) {
-                       struct lfsck_stop *stop = &info->lti_stop;
-
-                       CERROR("%s: cannot start LFSCK on some MDTs, "
-                              "stop all: rc = %d\n",
-                              lfsck_lfsck2name(lfsck), rc);
-                       if (rc != -EALREADY) {
-                               stop->ls_status = LS_FAILED;
-                               stop->ls_flags = LPF_ALL_TGT | LPF_BROADCAST;
-                               lfsck_stop_all(env, lfsck, stop);
-                       }
-               } else {
-                       CWARN("%s: cannot start LFSCK on some MDTs, "
-                             "partly scan: rc = %d\n",
-                             lfsck_lfsck2name(lfsck), rc);
-                       rc = 0;
+               struct lfsck_stop *stop = &info->lti_stop;
+
+               CERROR("%s: cannot start LFSCK on some MDTs, "
+                      "stop all: rc = %d\n",
+                      lfsck_lfsck2name(lfsck), rc);
+               if (rc != -EALREADY) {
+                       stop->ls_status = LS_FAILED;
+                       stop->ls_flags = LPF_ALL_TGT | LPF_BROADCAST;
+                       lfsck_stop_all(env, lfsck, stop);
                }
        }
 
@@ -2020,7 +1997,8 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
        struct lfsck_component          *com;
        struct l_wait_info               lwi    = { 0 };
        struct lfsck_thread_args        *lta;
-       long                             rc     = 0;
+       struct task_struct              *task;
+       int                              rc     = 0;
        __u16                            valid  = 0;
        __u16                            flags  = 0;
        __u16                            type   = 1;
@@ -2036,7 +2014,7 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
 
        /* start == NULL means auto trigger paused LFSCK. */
        if ((start == NULL) &&
-           (cfs_list_empty(&lfsck->li_list_scan) ||
+           (list_empty(&lfsck->li_list_scan) ||
             OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_AUTO)))
                GOTO(put, rc = 0);
 
@@ -2124,14 +2102,12 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
                        if (type & start->ls_active) {
                                com = __lfsck_component_find(lfsck, type,
                                                        &lfsck->li_list_idle);
-                               if (com != NULL) {
+                               if (com != NULL)
                                        /* The component status will be updated
                                         * when its prep() is called later by
                                         * the LFSCK main engine. */
-                                       list_del_init(&com->lc_link);
-                                       list_add_tail(&com->lc_link,
-                                                     &lfsck->li_list_scan);
-                               }
+                                       list_move_tail(&com->lc_link,
+                                                      &lfsck->li_list_scan);
                                start->ls_active &= ~type;
                        }
                        type <<= 1;
@@ -2195,9 +2171,10 @@ trigger:
                GOTO(out, rc = PTR_ERR(lta));
 
        __lfsck_set_speed(lfsck, bk->lb_speed_limit);
-       rc = PTR_ERR(kthread_run(lfsck_master_engine, lta, "lfsck"));
-       if (IS_ERR_VALUE(rc)) {
-               CERROR("%s: cannot start LFSCK thread: rc = %ld\n",
+       task = kthread_run(lfsck_master_engine, lta, "lfsck");
+       if (IS_ERR(task)) {
+               rc = PTR_ERR(task);
+               CERROR("%s: cannot start LFSCK thread: rc = %d\n",
                       lfsck_lfsck2name(lfsck), rc);
                lfsck_thread_args_fini(lta);
 
@@ -2280,9 +2257,10 @@ int lfsck_stop(const struct lu_env *env, struct dt_device *key,
 
        mutex_lock(&lfsck->li_mutex);
        spin_lock(&lfsck->li_lock);
+       /* no error if LFSCK is already stopped, or was never started */
        if (thread_is_init(thread) || thread_is_stopped(thread)) {
                spin_unlock(&lfsck->li_lock);
-               GOTO(out, rc = -EALREADY);
+               GOTO(out, rc = 0);
        }
 
        if (stop != NULL) {
@@ -2424,7 +2402,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
 {
        struct lfsck_instance   *lfsck;
        struct dt_object        *root  = NULL;
-       struct dt_object        *obj;
+       struct dt_object        *obj   = NULL;
        struct lu_fid           *fid   = &lfsck_env_info(env)->lti_fid;
        int                      rc;
        ENTRY;
@@ -2439,11 +2417,11 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
 
        mutex_init(&lfsck->li_mutex);
        spin_lock_init(&lfsck->li_lock);
-       CFS_INIT_LIST_HEAD(&lfsck->li_link);
-       CFS_INIT_LIST_HEAD(&lfsck->li_list_scan);
-       CFS_INIT_LIST_HEAD(&lfsck->li_list_dir);
-       CFS_INIT_LIST_HEAD(&lfsck->li_list_double_scan);
-       CFS_INIT_LIST_HEAD(&lfsck->li_list_idle);
+       INIT_LIST_HEAD(&lfsck->li_link);
+       INIT_LIST_HEAD(&lfsck->li_list_scan);
+       INIT_LIST_HEAD(&lfsck->li_list_dir);
+       INIT_LIST_HEAD(&lfsck->li_list_double_scan);
+       INIT_LIST_HEAD(&lfsck->li_list_idle);
        atomic_set(&lfsck->li_ref, 1);
        atomic_set(&lfsck->li_double_scan_count, 0);
        init_waitqueue_head(&lfsck->li_thread.t_ctl_waitq);
@@ -2464,7 +2442,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
        fid->f_seq = FID_SEQ_LOCAL_NAME;
        fid->f_oid = 1;
        fid->f_ver = 0;
-       rc = local_oid_storage_init(env, lfsck->li_bottom, fid, &lfsck->li_los);
+       rc = local_oid_storage_init(env, key, fid, &lfsck->li_los);
        if (rc != 0)
                GOTO(out, rc);
 
@@ -2472,7 +2450,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
        if (rc != 0)
                GOTO(out, rc);
 
-       root = dt_locate(env, lfsck->li_bottom, fid);
+       root = dt_locate(env, key, fid);
        if (IS_ERR(root))
                GOTO(out, rc = PTR_ERR(root));
 
@@ -2482,30 +2460,72 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
        lfsck->li_local_root_fid = *fid;
        if (master) {
                lfsck->li_master = 1;
-               if (lfsck_dev_idx(lfsck->li_bottom) == 0) {
+               if (lfsck_dev_idx(key) == 0) {
+                       struct lu_fid *pfid = &lfsck_env_info(env)->lti_fid2;
+                       const struct lu_name *cname;
+
                        rc = dt_lookup(env, root,
                                (struct dt_rec *)(&lfsck->li_global_root_fid),
                                (const struct dt_key *)"ROOT", BYPASS_CAPA);
                        if (rc != 0)
                                GOTO(out, rc);
+
+                       obj = dt_locate(env, key, &lfsck->li_global_root_fid);
+                       if (IS_ERR(obj))
+                               GOTO(out, rc = PTR_ERR(obj));
+
+                       rc = dt_lookup(env, obj, (struct dt_rec *)fid,
+                               (const struct dt_key *)dotlustre, BYPASS_CAPA);
+                       if (rc != 0)
+                               GOTO(out, rc);
+
+                       lu_object_put(env, &obj->do_lu);
+                       obj = dt_locate(env, key, fid);
+                       if (IS_ERR(obj))
+                               GOTO(out, rc = PTR_ERR(obj));
+
+                       cname = lfsck_name_get_const(env, dotlustre,
+                                                    strlen(dotlustre));
+                       rc = lfsck_verify_linkea(env, key, obj, cname,
+                                                &lfsck->li_global_root_fid);
+                       if (rc != 0)
+                               GOTO(out, rc);
+
+                       *pfid = *fid;
+                       rc = dt_lookup(env, obj, (struct dt_rec *)fid,
+                                      (const struct dt_key *)lostfound,
+                                      BYPASS_CAPA);
+                       if (rc != 0)
+                               GOTO(out, rc);
+
+                       lu_object_put(env, &obj->do_lu);
+                       obj = dt_locate(env, key, fid);
+                       if (IS_ERR(obj))
+                               GOTO(out, rc = PTR_ERR(obj));
+
+                       cname = lfsck_name_get_const(env, lostfound,
+                                                    strlen(lostfound));
+                       rc = lfsck_verify_linkea(env, key, obj, cname, pfid);
+                       if (rc != 0)
+                               GOTO(out, rc);
+
+                       lu_object_put(env, &obj->do_lu);
+                       obj = NULL;
                }
        }
 
        fid->f_seq = FID_SEQ_LOCAL_FILE;
        fid->f_oid = OTABLE_IT_OID;
        fid->f_ver = 0;
-       obj = dt_locate(env, lfsck->li_bottom, fid);
+       obj = dt_locate(env, key, fid);
        if (IS_ERR(obj))
                GOTO(out, rc = PTR_ERR(obj));
 
+       lu_object_get(&obj->do_lu);
        lfsck->li_obj_oit = obj;
        rc = obj->do_ops->do_index_try(env, obj, &dt_otable_features);
-       if (rc != 0) {
-               if (rc == -ENOTSUPP)
-                       GOTO(add, rc = 0);
-
+       if (rc != 0)
                GOTO(out, rc);
-       }
 
        rc = lfsck_bookmark_setup(env, lfsck);
        if (rc != 0)
@@ -2527,11 +2547,12 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
 
        /* XXX: more LFSCK components initialization to be added here. */
 
-add:
        rc = lfsck_instance_add(lfsck);
        if (rc == 0)
                rc = lfsck_add_target_from_orphan(env, lfsck);
 out:
+       if (obj != NULL && !IS_ERR(obj))
+               lu_object_put(env, &obj->do_lu);
        if (root != NULL && !IS_ERR(root))
                lu_object_put(env, &root->do_lu);
        if (rc != 0)
@@ -2602,7 +2623,7 @@ void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
 {
        struct lfsck_instance   *lfsck;
        struct lfsck_tgt_descs  *ltds;
-       struct lfsck_tgt_desc   *ltd    = NULL;
+       struct lfsck_tgt_desc   *ltd;
        struct list_head        *head;
 
        if (for_ost)
@@ -2621,6 +2642,7 @@ void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
                }
        }
 
+       ltd = NULL;
        lfsck = __lfsck_instance_find(key, true, false);
        spin_unlock(&lfsck_instance_lock);
        if (unlikely(lfsck == NULL))
@@ -2652,7 +2674,7 @@ unlock:
                if (for_ost)
                        head = &lfsck->li_ost_descs.ltd_orphan;
                else
-                       head = &lfsck->li_ost_descs.ltd_orphan;
+                       head = &lfsck->li_mdt_descs.ltd_orphan;
 
                list_for_each_entry(ltd, head, ltd_orphan_list) {
                        if (ltd->ltd_tgt == tgt) {
@@ -2667,7 +2689,7 @@ unlock:
                spin_lock(&ltds->ltd_lock);
                ltd->ltd_dead = 1;
                spin_unlock(&ltds->ltd_lock);
-               lfsck_stop_notify(env, lfsck, ltds, ltd, LT_LAYOUT);
+               lfsck_stop_notify(env, lfsck, ltds, ltd, LFSCK_TYPE_LAYOUT);
                lfsck_tgt_put(ltd);
        }
 
@@ -2679,6 +2701,7 @@ static int __init lfsck_init(void)
 {
        int rc;
 
+       INIT_LIST_HEAD(&lfsck_instance_list);
        INIT_LIST_HEAD(&lfsck_ost_orphan_list);
        INIT_LIST_HEAD(&lfsck_mdt_orphan_list);
        lfsck_key_init_generic(&lfsck_thread_key, NULL);
@@ -2696,7 +2719,7 @@ static void __exit lfsck_exit(void)
        struct lfsck_tgt_desc *ltd;
        struct lfsck_tgt_desc *next;
 
-       LASSERT(cfs_list_empty(&lfsck_instance_list));
+       LASSERT(list_empty(&lfsck_instance_list));
 
        list_for_each_entry_safe(ltd, next, &lfsck_ost_orphan_list,
                                 ltd_orphan_list) {