Whamcloud - gitweb
LU-4972 lfsck: skip .lustre and children for namespace check
[fs/lustre-release.git] / lustre / lfsck / lfsck_namespace.c
index 796c6b3..586694f 100644 (file)
 
 static const char lfsck_namespace_name[] = "lfsck_namespace";
 
-static void lfsck_namespace_le_to_cpu(struct lfsck_namespace *des,
+static void lfsck_namespace_le_to_cpu(struct lfsck_namespace *dst,
                                      struct lfsck_namespace *src)
 {
-       des->ln_magic = le32_to_cpu(src->ln_magic);
-       des->ln_status = le32_to_cpu(src->ln_status);
-       des->ln_flags = le32_to_cpu(src->ln_flags);
-       des->ln_success_count = le32_to_cpu(src->ln_success_count);
-       des->ln_run_time_phase1 = le32_to_cpu(src->ln_run_time_phase1);
-       des->ln_run_time_phase2 = le32_to_cpu(src->ln_run_time_phase2);
-       des->ln_time_last_complete = le64_to_cpu(src->ln_time_last_complete);
-       des->ln_time_latest_start = le64_to_cpu(src->ln_time_latest_start);
-       des->ln_time_last_checkpoint =
+       dst->ln_magic = le32_to_cpu(src->ln_magic);
+       dst->ln_status = le32_to_cpu(src->ln_status);
+       dst->ln_flags = le32_to_cpu(src->ln_flags);
+       dst->ln_success_count = le32_to_cpu(src->ln_success_count);
+       dst->ln_run_time_phase1 = le32_to_cpu(src->ln_run_time_phase1);
+       dst->ln_run_time_phase2 = le32_to_cpu(src->ln_run_time_phase2);
+       dst->ln_time_last_complete = le64_to_cpu(src->ln_time_last_complete);
+       dst->ln_time_latest_start = le64_to_cpu(src->ln_time_latest_start);
+       dst->ln_time_last_checkpoint =
                                le64_to_cpu(src->ln_time_last_checkpoint);
-       lfsck_position_le_to_cpu(&des->ln_pos_latest_start,
+       lfsck_position_le_to_cpu(&dst->ln_pos_latest_start,
                                 &src->ln_pos_latest_start);
-       lfsck_position_le_to_cpu(&des->ln_pos_last_checkpoint,
+       lfsck_position_le_to_cpu(&dst->ln_pos_last_checkpoint,
                                 &src->ln_pos_last_checkpoint);
-       lfsck_position_le_to_cpu(&des->ln_pos_first_inconsistent,
+       lfsck_position_le_to_cpu(&dst->ln_pos_first_inconsistent,
                                 &src->ln_pos_first_inconsistent);
-       des->ln_items_checked = le64_to_cpu(src->ln_items_checked);
-       des->ln_items_repaired = le64_to_cpu(src->ln_items_repaired);
-       des->ln_items_failed = le64_to_cpu(src->ln_items_failed);
-       des->ln_dirs_checked = le64_to_cpu(src->ln_dirs_checked);
-       des->ln_mlinked_checked = le64_to_cpu(src->ln_mlinked_checked);
-       des->ln_objs_checked_phase2 = le64_to_cpu(src->ln_objs_checked_phase2);
-       des->ln_objs_repaired_phase2 =
+       dst->ln_items_checked = le64_to_cpu(src->ln_items_checked);
+       dst->ln_items_repaired = le64_to_cpu(src->ln_items_repaired);
+       dst->ln_items_failed = le64_to_cpu(src->ln_items_failed);
+       dst->ln_dirs_checked = le64_to_cpu(src->ln_dirs_checked);
+       dst->ln_mlinked_checked = le64_to_cpu(src->ln_mlinked_checked);
+       dst->ln_objs_checked_phase2 = le64_to_cpu(src->ln_objs_checked_phase2);
+       dst->ln_objs_repaired_phase2 =
                                le64_to_cpu(src->ln_objs_repaired_phase2);
-       des->ln_objs_failed_phase2 = le64_to_cpu(src->ln_objs_failed_phase2);
-       des->ln_objs_nlink_repaired = le64_to_cpu(src->ln_objs_nlink_repaired);
-       des->ln_objs_lost_found = le64_to_cpu(src->ln_objs_lost_found);
-       fid_le_to_cpu(&des->ln_fid_latest_scanned_phase2,
+       dst->ln_objs_failed_phase2 = le64_to_cpu(src->ln_objs_failed_phase2);
+       dst->ln_objs_nlink_repaired = le64_to_cpu(src->ln_objs_nlink_repaired);
+       dst->ln_objs_lost_found = le64_to_cpu(src->ln_objs_lost_found);
+       fid_le_to_cpu(&dst->ln_fid_latest_scanned_phase2,
                      &src->ln_fid_latest_scanned_phase2);
+       dst->ln_dirent_repaired = le64_to_cpu(src->ln_dirent_repaired);
+       dst->ln_linkea_repaired = le64_to_cpu(src->ln_linkea_repaired);
 }
 
-static void lfsck_namespace_cpu_to_le(struct lfsck_namespace *des,
+static void lfsck_namespace_cpu_to_le(struct lfsck_namespace *dst,
                                      struct lfsck_namespace *src)
 {
-       des->ln_magic = cpu_to_le32(src->ln_magic);
-       des->ln_status = cpu_to_le32(src->ln_status);
-       des->ln_flags = cpu_to_le32(src->ln_flags);
-       des->ln_success_count = cpu_to_le32(src->ln_success_count);
-       des->ln_run_time_phase1 = cpu_to_le32(src->ln_run_time_phase1);
-       des->ln_run_time_phase2 = cpu_to_le32(src->ln_run_time_phase2);
-       des->ln_time_last_complete = cpu_to_le64(src->ln_time_last_complete);
-       des->ln_time_latest_start = cpu_to_le64(src->ln_time_latest_start);
-       des->ln_time_last_checkpoint =
+       dst->ln_magic = cpu_to_le32(src->ln_magic);
+       dst->ln_status = cpu_to_le32(src->ln_status);
+       dst->ln_flags = cpu_to_le32(src->ln_flags);
+       dst->ln_success_count = cpu_to_le32(src->ln_success_count);
+       dst->ln_run_time_phase1 = cpu_to_le32(src->ln_run_time_phase1);
+       dst->ln_run_time_phase2 = cpu_to_le32(src->ln_run_time_phase2);
+       dst->ln_time_last_complete = cpu_to_le64(src->ln_time_last_complete);
+       dst->ln_time_latest_start = cpu_to_le64(src->ln_time_latest_start);
+       dst->ln_time_last_checkpoint =
                                cpu_to_le64(src->ln_time_last_checkpoint);
-       lfsck_position_cpu_to_le(&des->ln_pos_latest_start,
+       lfsck_position_cpu_to_le(&dst->ln_pos_latest_start,
                                 &src->ln_pos_latest_start);
-       lfsck_position_cpu_to_le(&des->ln_pos_last_checkpoint,
+       lfsck_position_cpu_to_le(&dst->ln_pos_last_checkpoint,
                                 &src->ln_pos_last_checkpoint);
-       lfsck_position_cpu_to_le(&des->ln_pos_first_inconsistent,
+       lfsck_position_cpu_to_le(&dst->ln_pos_first_inconsistent,
                                 &src->ln_pos_first_inconsistent);
-       des->ln_items_checked = cpu_to_le64(src->ln_items_checked);
-       des->ln_items_repaired = cpu_to_le64(src->ln_items_repaired);
-       des->ln_items_failed = cpu_to_le64(src->ln_items_failed);
-       des->ln_dirs_checked = cpu_to_le64(src->ln_dirs_checked);
-       des->ln_mlinked_checked = cpu_to_le64(src->ln_mlinked_checked);
-       des->ln_objs_checked_phase2 = cpu_to_le64(src->ln_objs_checked_phase2);
-       des->ln_objs_repaired_phase2 =
+       dst->ln_items_checked = cpu_to_le64(src->ln_items_checked);
+       dst->ln_items_repaired = cpu_to_le64(src->ln_items_repaired);
+       dst->ln_items_failed = cpu_to_le64(src->ln_items_failed);
+       dst->ln_dirs_checked = cpu_to_le64(src->ln_dirs_checked);
+       dst->ln_mlinked_checked = cpu_to_le64(src->ln_mlinked_checked);
+       dst->ln_objs_checked_phase2 = cpu_to_le64(src->ln_objs_checked_phase2);
+       dst->ln_objs_repaired_phase2 =
                                cpu_to_le64(src->ln_objs_repaired_phase2);
-       des->ln_objs_failed_phase2 = cpu_to_le64(src->ln_objs_failed_phase2);
-       des->ln_objs_nlink_repaired = cpu_to_le64(src->ln_objs_nlink_repaired);
-       des->ln_objs_lost_found = cpu_to_le64(src->ln_objs_lost_found);
-       fid_cpu_to_le(&des->ln_fid_latest_scanned_phase2,
+       dst->ln_objs_failed_phase2 = cpu_to_le64(src->ln_objs_failed_phase2);
+       dst->ln_objs_nlink_repaired = cpu_to_le64(src->ln_objs_nlink_repaired);
+       dst->ln_objs_lost_found = cpu_to_le64(src->ln_objs_lost_found);
+       fid_cpu_to_le(&dst->ln_fid_latest_scanned_phase2,
                      &src->ln_fid_latest_scanned_phase2);
+       dst->ln_dirent_repaired = cpu_to_le64(src->ln_dirent_repaired);
+       dst->ln_linkea_repaired = cpu_to_le64(src->ln_linkea_repaired);
 }
 
 /**
@@ -134,16 +138,15 @@ static int lfsck_namespace_load(const struct lu_env *env,
                lfsck_namespace_le_to_cpu(ns,
                                (struct lfsck_namespace *)com->lc_file_disk);
                if (ns->ln_magic != LFSCK_NAMESPACE_MAGIC) {
-                       CWARN("%.16s: invalid lfsck_namespace magic "
-                             "0x%x != 0x%x\n",
-                             lfsck_lfsck2name(com->lc_lfsck),
-                             ns->ln_magic, LFSCK_NAMESPACE_MAGIC);
+                       CWARN("%s: invalid lfsck_namespace magic %#x != %#x\n",
+                             lfsck_lfsck2name(com->lc_lfsck), ns->ln_magic,
+                             LFSCK_NAMESPACE_MAGIC);
                        rc = 1;
                } else {
                        rc = 0;
                }
        } else if (rc != -ENODATA) {
-               CERROR("%.16s: fail to load lfsck_namespace, expected = %d, "
+               CERROR("%s: fail to load lfsck_namespace: expected = %d, "
                       "rc = %d\n", lfsck_lfsck2name(com->lc_lfsck), len, rc);
                if (rc >= 0)
                        rc = 1;
@@ -166,8 +169,8 @@ static int lfsck_namespace_store(const struct lu_env *env,
        handle = dt_trans_create(env, lfsck->li_bottom);
        if (IS_ERR(handle)) {
                rc = PTR_ERR(handle);
-               CERROR("%.16s: fail to create trans for storing "
-                      "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
+               CERROR("%s: fail to create trans for storing lfsck_namespace: "
+                      "rc = %d\n", lfsck_lfsck2name(lfsck), rc);
                RETURN(rc);
        }
 
@@ -175,15 +178,15 @@ static int lfsck_namespace_store(const struct lu_env *env,
                                  lfsck_buf_get(env, com->lc_file_disk, len),
                                  XATTR_NAME_LFSCK_NAMESPACE, 0, handle);
        if (rc != 0) {
-               CERROR("%.16s: fail to declare trans for storing "
-                      "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
+               CERROR("%s: fail to declare trans for storing lfsck_namespace: "
+                      "rc = %d\n", lfsck_lfsck2name(lfsck), rc);
                GOTO(out, rc);
        }
 
        rc = dt_trans_start_local(env, lfsck->li_bottom, handle);
        if (rc != 0) {
-               CERROR("%.16s: fail to start trans for storing "
-                      "lfsck_namespace: %d\n,", lfsck_lfsck2name(lfsck), rc);
+               CERROR("%s: fail to start trans for storing lfsck_namespace: "
+                      "rc = %d\n", lfsck_lfsck2name(lfsck), rc);
                GOTO(out, rc);
        }
 
@@ -193,7 +196,7 @@ static int lfsck_namespace_store(const struct lu_env *env,
                          init ? LU_XATTR_CREATE : LU_XATTR_REPLACE,
                          handle, BYPASS_CAPA);
        if (rc != 0)
-               CERROR("%.16s: fail to store lfsck_namespace, len = %d, "
+               CERROR("%s: fail to store lfsck_namespace: len = %d, "
                       "rc = %d\n", lfsck_lfsck2name(lfsck), len, rc);
 
        GOTO(out, rc);
@@ -206,7 +209,7 @@ out:
 static int lfsck_namespace_init(const struct lu_env *env,
                                struct lfsck_component *com)
 {
-       struct lfsck_namespace *ns = (struct lfsck_namespace *)com->lc_file_ram;
+       struct lfsck_namespace *ns = com->lc_file_ram;
        int rc;
 
        memset(ns, 0, sizeof(*ns));
@@ -316,7 +319,7 @@ static int lfsck_namespace_update(const struct lu_env *env,
                rc = dt_delete(env, obj, (const struct dt_key *)key, handle,
                               BYPASS_CAPA);
                if (rc != 0) {
-                       CERROR("%s: fail to insert "DFID", rc = %d\n",
+                       CERROR("%s: fail to insert "DFID": rc = %d\n",
                               lfsck_lfsck2name(com->lc_lfsck), PFID(fid), rc);
                        GOTO(out, rc);
                }
@@ -473,8 +476,7 @@ static int lfsck_namespace_double_scan_one(const struct lu_env *env,
        struct lu_fid            *cfid    = &info->lti_fid2;
        struct lfsck_instance   *lfsck    = com->lc_lfsck;
        struct lfsck_bookmark   *bk       = &lfsck->li_bookmark_ram;
-       struct lfsck_namespace  *ns       =
-                               (struct lfsck_namespace *)com->lc_file_ram;
+       struct lfsck_namespace  *ns       = com->lc_file_ram;
        struct linkea_data       ldata    = { 0 };
        struct thandle          *handle   = NULL;
        bool                     locked   = false;
@@ -625,7 +627,7 @@ stop:
                if (rc == 0 && !lfsck_is_dead_obj(child) &&
                    ldata.ld_leh != NULL &&
                    ldata.ld_leh->leh_reccount != la->la_nlink)
-                       CWARN("%.16s: the object "DFID" linkEA entry count %u "
+                       CWARN("%s: the object "DFID" linkEA entry count %u "
                              "may not match its hardlink count %u\n",
                              lfsck_lfsck2name(lfsck), PFID(cfid),
                              ldata.ld_leh->leh_reccount, la->la_nlink);
@@ -650,12 +652,21 @@ static int lfsck_namespace_reset(const struct lu_env *env,
                                 struct lfsck_component *com, bool init)
 {
        struct lfsck_instance   *lfsck = com->lc_lfsck;
-       struct lfsck_namespace  *ns    =
-                               (struct lfsck_namespace *)com->lc_file_ram;
+       struct lfsck_namespace  *ns    = com->lc_file_ram;
+       struct dt_object        *root;
        struct dt_object        *dto;
        int                      rc;
        ENTRY;
 
+       root = dt_locate(env, lfsck->li_bottom, &lfsck->li_local_root_fid);
+       if (IS_ERR(root))
+               RETURN(PTR_ERR(root));
+
+       if (unlikely(!dt_try_as_dir(env, root))) {
+               lu_object_put(env, &root->do_lu);
+               RETURN(-ENOTDIR);
+       }
+
        down_write(&com->lc_sem);
        if (init) {
                memset(ns, 0, sizeof(*ns));
@@ -670,12 +681,14 @@ static int lfsck_namespace_reset(const struct lu_env *env,
        ns->ln_magic = LFSCK_NAMESPACE_MAGIC;
        ns->ln_status = LS_INIT;
 
-       rc = local_object_unlink(env, lfsck->li_bottom, lfsck->li_local_root,
+       rc = local_object_unlink(env, lfsck->li_bottom, root,
                                 lfsck_namespace_name);
        if (rc != 0)
                GOTO(out, rc);
 
-       dto = local_index_find_or_create(env, lfsck->li_los, lfsck->li_local_root,
+       lfsck_object_put(env, com->lc_obj);
+       com->lc_obj = NULL;
+       dto = local_index_find_or_create(env, lfsck->li_los, root,
                                         lfsck_namespace_name,
                                         S_IFREG | S_IRUGO | S_IWUSR,
                                         &dt_lfsck_features);
@@ -693,6 +706,7 @@ static int lfsck_namespace_reset(const struct lu_env *env,
 
 out:
        up_write(&com->lc_sem);
+       lu_object_put(env, &root->do_lu);
        return rc;
 }
 
@@ -700,7 +714,7 @@ static void
 lfsck_namespace_fail(const struct lu_env *env, struct lfsck_component *com,
                     bool new_checked)
 {
-       struct lfsck_namespace *ns = (struct lfsck_namespace *)com->lc_file_ram;
+       struct lfsck_namespace *ns = com->lc_file_ram;
 
        down_write(&com->lc_sem);
        if (new_checked)
@@ -716,8 +730,7 @@ static int lfsck_namespace_checkpoint(const struct lu_env *env,
                                      struct lfsck_component *com, bool init)
 {
        struct lfsck_instance   *lfsck = com->lc_lfsck;
-       struct lfsck_namespace  *ns    =
-                               (struct lfsck_namespace *)com->lc_file_ram;
+       struct lfsck_namespace  *ns    = com->lc_file_ram;
        int                      rc;
 
        if (com->lc_new_checked == 0 && !init)
@@ -743,17 +756,20 @@ static int lfsck_namespace_checkpoint(const struct lu_env *env,
 }
 
 static int lfsck_namespace_prep(const struct lu_env *env,
-                               struct lfsck_component *com)
+                               struct lfsck_component *com,
+                               struct lfsck_start_param *lsp)
 {
        struct lfsck_instance   *lfsck  = com->lc_lfsck;
-       struct lfsck_namespace  *ns     =
-                               (struct lfsck_namespace *)com->lc_file_ram;
+       struct lfsck_namespace  *ns     = com->lc_file_ram;
        struct lfsck_position   *pos    = &com->lc_pos_start;
 
        if (ns->ln_status == LS_COMPLETED) {
                int rc;
 
                rc = lfsck_namespace_reset(env, com, false);
+               if (rc == 0)
+                       rc = lfsck_set_param(env, lfsck, lsp->lsp_start, true);
+
                if (rc != 0)
                        return rc;
        }
@@ -833,11 +849,9 @@ static int lfsck_namespace_exec_dir(const struct lu_env *env,
        struct lu_attr             *la       = &info->lti_la;
        struct lfsck_instance      *lfsck    = com->lc_lfsck;
        struct lfsck_bookmark      *bk       = &lfsck->li_bookmark_ram;
-       struct lfsck_namespace     *ns       =
-                               (struct lfsck_namespace *)com->lc_file_ram;
+       struct lfsck_namespace     *ns       = com->lc_file_ram;
        struct linkea_data          ldata    = { 0 };
-       const struct lu_fid        *pfid     =
-                               lu_object_fid(&lfsck->li_obj_dir->do_lu);
+       const struct lu_fid        *pfid     = lfsck_dto2fid(lfsck->li_obj_dir);
        const struct lu_fid        *cfid     = lfsck_dto2fid(obj);
        const struct lu_name       *cname;
        struct thandle             *handle   = NULL;
@@ -855,16 +869,18 @@ static int lfsck_namespace_exec_dir(const struct lu_env *env,
 
        if (ent->lde_attrs & LUDA_UPGRADE) {
                ns->ln_flags |= LF_UPGRADE;
+               ns->ln_dirent_repaired++;
                repaired = true;
        } else if (ent->lde_attrs & LUDA_REPAIR) {
                ns->ln_flags |= LF_INCONSISTENT;
+               ns->ln_dirent_repaired++;
                repaired = true;
        }
 
        if (ent->lde_name[0] == '.' &&
            (ent->lde_namelen == 1 ||
             (ent->lde_namelen == 2 && ent->lde_name[1] == '.') ||
-            fid_is_dot_lustre(&ent->lde_fid)))
+            fid_seq_is_dot_lustre(fid_seq(&ent->lde_fid))))
                GOTO(out, rc = 0);
 
        if (!(bk->lb_param & LPF_DRYRUN) &&
@@ -930,6 +946,7 @@ again:
 
 nodata:
                if (bk->lb_param & LPF_DRYRUN) {
+                       ns->ln_linkea_repaired++;
                        repaired = true;
                        goto record;
                }
@@ -962,6 +979,7 @@ nodata:
                        GOTO(stop, rc);
 
                count = ldata.ld_leh->leh_reccount;
+               ns->ln_linkea_repaired++;
                repaired = true;
        } else {
                GOTO(stop, rc);
@@ -1012,10 +1030,16 @@ out:
                if (!(bk->lb_param & LPF_FAILOUT))
                        rc = 0;
        } else {
-               if (repaired)
+               if (repaired) {
                        ns->ln_items_repaired++;
-               else
+                       if (bk->lb_param & LPF_DRYRUN &&
+                           lfsck_pos_is_zero(&ns->ln_pos_first_inconsistent))
+                               lfsck_pos_fill(env, lfsck,
+                                              &ns->ln_pos_first_inconsistent,
+                                              false);
+               } else {
                        com->lc_journal = 0;
+               }
                rc = 0;
        }
        up_write(&com->lc_sem);
@@ -1027,8 +1051,7 @@ static int lfsck_namespace_post(const struct lu_env *env,
                                int result, bool init)
 {
        struct lfsck_instance   *lfsck = com->lc_lfsck;
-       struct lfsck_namespace  *ns    =
-                               (struct lfsck_namespace *)com->lc_file_ram;
+       struct lfsck_namespace  *ns    = com->lc_file_ram;
        int                      rc;
 
        down_write(&com->lc_sem);
@@ -1044,10 +1067,10 @@ static int lfsck_namespace_post(const struct lu_env *env,
                cfs_list_del_init(&com->lc_link_dir);
                cfs_list_add_tail(&com->lc_link, &lfsck->li_list_double_scan);
        } else if (result == 0) {
-               if (lfsck->li_paused) {
-                       ns->ln_status = LS_PAUSED;
-               } else {
+               ns->ln_status = lfsck->li_status;
+               if (ns->ln_status == 0)
                        ns->ln_status = LS_STOPPED;
+               if (ns->ln_status != LS_PAUSED) {
                        cfs_list_del_init(&com->lc_link);
                        cfs_list_del_init(&com->lc_link_dir);
                        cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
@@ -1080,8 +1103,7 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
 {
        struct lfsck_instance   *lfsck = com->lc_lfsck;
        struct lfsck_bookmark   *bk    = &lfsck->li_bookmark_ram;
-       struct lfsck_namespace  *ns    =
-                               (struct lfsck_namespace *)com->lc_file_ram;
+       struct lfsck_namespace  *ns    = com->lc_file_ram;
        int                      save  = len;
        int                      ret   = -ENOSPC;
        int                      rc;
@@ -1089,12 +1111,12 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
        down_read(&com->lc_sem);
        rc = snprintf(buf, len,
                      "name: lfsck_namespace\n"
-                     "magic: 0x%x\n"
+                     "magic: %#x\n"
                      "version: %d\n"
                      "status: %s\n",
                      ns->ln_magic,
                      bk->lb_version,
-                     lfsck_status_names[ns->ln_status]);
+                     lfsck_status2names(ns->ln_status));
        if (rc <= 0)
                goto out;
 
@@ -1147,7 +1169,7 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
                                          lfsck->li_time_last_checkpoint;
                __u64 checked = ns->ln_items_checked + com->lc_new_checked;
                __u64 speed = checked;
-               __u64 new_checked = com->lc_new_checked * CFS_HZ;
+               __u64 new_checked = com->lc_new_checked * HZ;
                __u32 rtime = ns->ln_run_time_phase1 +
                              cfs_duration_sec(duration + HALF_SEC);
 
@@ -1164,6 +1186,8 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
                              "failed_phase2: "LPU64"\n"
                              "dirs: "LPU64"\n"
                              "M-linked: "LPU64"\n"
+                             "dirent_repaired: "LPU64"\n"
+                             "linkea_repaired: "LPU64"\n"
                              "nlinks_repaired: "LPU64"\n"
                              "lost_found: "LPU64"\n"
                              "success_count: %u\n"
@@ -1181,6 +1205,8 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
                              ns->ln_objs_failed_phase2,
                              ns->ln_dirs_checked,
                              ns->ln_mlinked_checked,
+                             ns->ln_dirent_repaired,
+                             ns->ln_linkea_repaired,
                              ns->ln_objs_nlink_repaired,
                              ns->ln_objs_lost_found,
                              ns->ln_success_count,
@@ -1214,7 +1240,7 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
                                pos.lp_dir_cookie = 0;
                        } else {
                                pos.lp_dir_parent =
-                               *lu_object_fid(&lfsck->li_obj_dir->do_lu);
+                                       *lfsck_dto2fid(lfsck->li_obj_dir);
                        }
                } else {
                        fid_zero(&pos.lp_dir_parent);
@@ -1231,7 +1257,7 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
                                com->lc_new_checked;
                __u64 speed1 = ns->ln_items_checked;
                __u64 speed2 = checked;
-               __u64 new_checked = com->lc_new_checked * CFS_HZ;
+               __u64 new_checked = com->lc_new_checked * HZ;
                __u32 rtime = ns->ln_run_time_phase2 +
                              cfs_duration_sec(duration + HALF_SEC);
 
@@ -1250,6 +1276,8 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
                              "failed_phase2: "LPU64"\n"
                              "dirs: "LPU64"\n"
                              "M-linked: "LPU64"\n"
+                             "dirent_repaired: "LPU64"\n"
+                             "linkea_repaired: "LPU64"\n"
                              "nlinks_repaired: "LPU64"\n"
                              "lost_found: "LPU64"\n"
                              "success_count: %u\n"
@@ -1268,6 +1296,8 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
                              ns->ln_objs_failed_phase2,
                              ns->ln_dirs_checked,
                              ns->ln_mlinked_checked,
+                             ns->ln_dirent_repaired,
+                             ns->ln_linkea_repaired,
                              ns->ln_objs_nlink_repaired,
                              ns->ln_objs_lost_found,
                              ns->ln_success_count,
@@ -1299,6 +1329,8 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
                              "failed_phase2: "LPU64"\n"
                              "dirs: "LPU64"\n"
                              "M-linked: "LPU64"\n"
+                             "dirent_repaired: "LPU64"\n"
+                             "linkea_repaired: "LPU64"\n"
                              "nlinks_repaired: "LPU64"\n"
                              "lost_found: "LPU64"\n"
                              "success_count: %u\n"
@@ -1317,6 +1349,8 @@ lfsck_namespace_dump(const struct lu_env *env, struct lfsck_component *com,
                              ns->ln_objs_failed_phase2,
                              ns->ln_dirs_checked,
                              ns->ln_mlinked_checked,
+                             ns->ln_dirent_repaired,
+                             ns->ln_linkea_repaired,
                              ns->ln_objs_nlink_repaired,
                              ns->ln_objs_lost_found,
                              ns->ln_success_count,
@@ -1337,14 +1371,15 @@ out:
        return ret;
 }
 
-static int lfsck_namespace_double_scan(const struct lu_env *env,
-                                      struct lfsck_component *com)
+static int lfsck_namespace_double_scan_main(void *args)
 {
+       struct lfsck_thread_args *lta   = args;
+       const struct lu_env     *env    = &lta->lta_env;
+       struct lfsck_component  *com    = lta->lta_com;
        struct lfsck_instance   *lfsck  = com->lc_lfsck;
        struct ptlrpc_thread    *thread = &lfsck->li_thread;
        struct lfsck_bookmark   *bk     = &lfsck->li_bookmark_ram;
-       struct lfsck_namespace  *ns     =
-                               (struct lfsck_namespace *)com->lc_file_ram;
+       struct lfsck_namespace  *ns     = com->lc_file_ram;
        struct dt_object        *obj    = com->lc_obj;
        const struct dt_it_ops  *iops   = &obj->do_index_ops->dio_it;
        struct dt_object        *target;
@@ -1352,17 +1387,18 @@ static int lfsck_namespace_double_scan(const struct lu_env *env,
        struct dt_key           *key;
        struct lu_fid            fid;
        int                      rc;
-       __u8                     flags;
+       __u8                     flags = 0;
        ENTRY;
 
-       lfsck->li_new_scanned = 0;
-       lfsck->li_time_last_checkpoint = cfs_time_current();
-       lfsck->li_time_next_checkpoint = lfsck->li_time_last_checkpoint +
+       com->lc_new_checked = 0;
+       com->lc_new_scanned = 0;
+       com->lc_time_last_checkpoint = cfs_time_current();
+       com->lc_time_next_checkpoint = com->lc_time_last_checkpoint +
                                cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
 
        di = iops->init(env, obj, 0, BYPASS_CAPA);
        if (IS_ERR(di))
-               RETURN(PTR_ERR(di));
+               GOTO(out, rc = PTR_ERR(di));
 
        fid_cpu_to_be(&fid, &ns->ln_fid_latest_scanned_phase2);
        rc = iops->get(env, di, (const struct dt_key *)&fid);
@@ -1413,8 +1449,8 @@ static int lfsck_namespace_double_scan(const struct lu_env *env,
                lfsck_object_put(env, target);
 
 checkpoint:
-               lfsck->li_new_scanned++;
                com->lc_new_checked++;
+               com->lc_new_scanned++;
                ns->ln_fid_latest_scanned_phase2 = fid;
                if (rc > 0)
                        ns->ln_objs_repaired_phase2++;
@@ -1432,13 +1468,13 @@ checkpoint:
                if (rc < 0 && bk->lb_param & LPF_FAILOUT)
                        GOTO(put, rc);
 
-               if (unlikely(cfs_time_beforeq(lfsck->li_time_next_checkpoint,
+               if (unlikely(cfs_time_beforeq(com->lc_time_next_checkpoint,
                                              cfs_time_current())) &&
                    com->lc_new_checked != 0) {
                        down_write(&com->lc_sem);
                        ns->ln_run_time_phase2 +=
                                cfs_duration_sec(cfs_time_current() +
-                               HALF_SEC - lfsck->li_time_last_checkpoint);
+                               HALF_SEC - com->lc_time_last_checkpoint);
                        ns->ln_time_last_checkpoint = cfs_time_current_sec();
                        ns->ln_objs_checked_phase2 += com->lc_new_checked;
                        com->lc_new_checked = 0;
@@ -1447,13 +1483,13 @@ checkpoint:
                        if (rc != 0)
                                GOTO(put, rc);
 
-                       lfsck->li_time_last_checkpoint = cfs_time_current();
-                       lfsck->li_time_next_checkpoint =
-                               lfsck->li_time_last_checkpoint +
+                       com->lc_time_last_checkpoint = cfs_time_current();
+                       com->lc_time_next_checkpoint =
+                               com->lc_time_last_checkpoint +
                                cfs_time_seconds(LFSCK_CHECKPOINT_INTERVAL);
                }
 
-               lfsck_control_speed(lfsck);
+               lfsck_control_speed_by_self(com);
                if (unlikely(!thread_is_running(thread)))
                        GOTO(put, rc = 0);
 
@@ -1467,8 +1503,9 @@ put:
 
 fini:
        iops->fini(env, di);
-       down_write(&com->lc_sem);
 
+out:
+       down_write(&com->lc_sem);
        ns->ln_run_time_phase2 += cfs_duration_sec(cfs_time_current() +
                                HALF_SEC - lfsck->li_time_last_checkpoint);
        ns->ln_time_last_checkpoint = cfs_time_current_sec();
@@ -1479,32 +1516,73 @@ fini:
                com->lc_journal = 0;
                ns->ln_status = LS_COMPLETED;
                if (!(bk->lb_param & LPF_DRYRUN))
-                       ns->ln_flags &=
-                       ~(LF_SCANNED_ONCE | LF_INCONSISTENT | LF_UPGRADE);
+                       ns->ln_flags &= ~(LF_SCANNED_ONCE | LF_INCONSISTENT);
                ns->ln_time_last_complete = ns->ln_time_last_checkpoint;
                ns->ln_success_count++;
        } else if (rc == 0) {
-               if (lfsck->li_paused)
-                       ns->ln_status = LS_PAUSED;
-               else
+               ns->ln_status = lfsck->li_status;
+               if (ns->ln_status == 0)
                        ns->ln_status = LS_STOPPED;
        } else {
                ns->ln_status = LS_FAILED;
        }
 
-       if (ns->ln_status != LS_PAUSED) {
-               spin_lock(&lfsck->li_lock);
-               cfs_list_del_init(&com->lc_link);
-               cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
-               spin_unlock(&lfsck->li_lock);
-       }
-
        rc = lfsck_namespace_store(env, com, false);
-
        up_write(&com->lc_sem);
+       if (atomic_dec_and_test(&lfsck->li_double_scan_count))
+               wake_up_all(&thread->t_ctl_waitq);
+
+       lfsck_thread_args_fini(lta);
+
        return rc;
 }
 
+static int lfsck_namespace_double_scan(const struct lu_env *env,
+                                      struct lfsck_component *com)
+{
+       struct lfsck_instance           *lfsck = com->lc_lfsck;
+       struct lfsck_namespace          *ns    = com->lc_file_ram;
+       struct lfsck_thread_args        *lta;
+       long                             rc;
+       ENTRY;
+
+       if (unlikely(ns->ln_status != LS_SCANNING_PHASE2))
+               RETURN(0);
+
+       lta = lfsck_thread_args_init(lfsck, com, NULL);
+       if (IS_ERR(lta))
+               RETURN(PTR_ERR(lta));
+
+       atomic_inc(&lfsck->li_double_scan_count);
+       rc = PTR_ERR(kthread_run(lfsck_namespace_double_scan_main, lta,
+                                "lfsck_namespace"));
+       if (IS_ERR_VALUE(rc)) {
+               CERROR("%s: cannot start LFSCK namespace thread: rc = %ld\n",
+                      lfsck_lfsck2name(lfsck), rc);
+               atomic_dec(&lfsck->li_double_scan_count);
+               lfsck_thread_args_fini(lta);
+       } else {
+               rc = 0;
+       }
+
+       RETURN(rc);
+}
+
+static int lfsck_namespace_in_notify(const struct lu_env *env,
+                                    struct lfsck_component *com,
+                                    struct lfsck_request *lr)
+{
+       return 0;
+}
+
+static int lfsck_namespace_query(const struct lu_env *env,
+                                struct lfsck_component *com)
+{
+       struct lfsck_namespace *ns = com->lc_file_ram;
+
+       return ns->ln_status;
+}
+
 static struct lfsck_operations lfsck_namespace_ops = {
        .lfsck_reset            = lfsck_namespace_reset,
        .lfsck_fail             = lfsck_namespace_fail,
@@ -1515,6 +1593,8 @@ static struct lfsck_operations lfsck_namespace_ops = {
        .lfsck_post             = lfsck_namespace_post,
        .lfsck_dump             = lfsck_namespace_dump,
        .lfsck_double_scan      = lfsck_namespace_double_scan,
+       .lfsck_in_notify        = lfsck_namespace_in_notify,
+       .lfsck_query            = lfsck_namespace_query,
 };
 
 int lfsck_namespace_setup(const struct lu_env *env,
@@ -1522,6 +1602,7 @@ int lfsck_namespace_setup(const struct lu_env *env,
 {
        struct lfsck_component  *com;
        struct lfsck_namespace  *ns;
+       struct dt_object        *root = NULL;
        struct dt_object        *obj;
        int                      rc;
        ENTRY;
@@ -1548,8 +1629,14 @@ int lfsck_namespace_setup(const struct lu_env *env,
        if (com->lc_file_disk == NULL)
                GOTO(out, rc = -ENOMEM);
 
-       obj = local_index_find_or_create(env, lfsck->li_los,
-                                        lfsck->li_local_root,
+       root = dt_locate(env, lfsck->li_bottom, &lfsck->li_local_root_fid);
+       if (IS_ERR(root))
+               GOTO(out, rc = PTR_ERR(root));
+
+       if (unlikely(!dt_try_as_dir(env, root)))
+               GOTO(out, rc = -ENOTDIR);
+
+       obj = local_index_find_or_create(env, lfsck->li_los, root,
                                         lfsck_namespace_name,
                                         S_IFREG | S_IRUGO | S_IWUSR,
                                         &dt_lfsck_features);
@@ -1569,16 +1656,18 @@ int lfsck_namespace_setup(const struct lu_env *env,
        if (rc != 0)
                GOTO(out, rc);
 
-       ns = (struct lfsck_namespace *)com->lc_file_ram;
+       ns = com->lc_file_ram;
        switch (ns->ln_status) {
        case LS_INIT:
        case LS_COMPLETED:
        case LS_FAILED:
        case LS_STOPPED:
+               spin_lock(&lfsck->li_lock);
                cfs_list_add_tail(&com->lc_link, &lfsck->li_list_idle);
+               spin_unlock(&lfsck->li_lock);
                break;
        default:
-               CERROR("%s: unknown lfsck_namespace status: %u\n",
+               CERROR("%s: unknown lfsck_namespace status: rc = %u\n",
                       lfsck_lfsck2name(lfsck), ns->ln_status);
                /* fall through */
        case LS_SCANNING_PHASE1:
@@ -1590,14 +1679,18 @@ int lfsck_namespace_setup(const struct lu_env *env,
                /* fall through */
        case LS_PAUSED:
        case LS_CRASHED:
+               spin_lock(&lfsck->li_lock);
                cfs_list_add_tail(&com->lc_link, &lfsck->li_list_scan);
                cfs_list_add_tail(&com->lc_link_dir, &lfsck->li_list_dir);
+               spin_unlock(&lfsck->li_lock);
                break;
        }
 
        GOTO(out, rc = 0);
 
 out:
+       if (root != NULL && !IS_ERR(root))
+               lu_object_put(env, &root->do_lu);
        if (rc != 0)
                lfsck_component_cleanup(env, com);
        return rc;