Whamcloud - gitweb
LU-8929 lfsck: dumper gets current position properly
[fs/lustre-release.git] / lustre / lfsck / lfsck_engine.c
index 56052c2..0af5e95 100644 (file)
@@ -20,7 +20,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2013, 2015, Intel Corporation.
+ * Copyright (c) 2013, 2016, Intel Corporation.
  */
 /*
  * lustre/lfsck/lfsck_engine.c
@@ -362,7 +362,9 @@ int lfsck_open_dir(const struct lu_env *env,
                GOTO(out, rc = PTR_ERR(di));
 
        rc = iops->load(env, di, cookie);
-       if (rc == 0 || (rc > 0 && cookie > 0))
+       if (rc == -ENODATA)
+               rc = 1;
+       else if (rc == 0 || (rc > 0 && cookie > 0))
                rc = iops->next(env, di);
        else if (rc > 0)
                rc = 0;
@@ -441,7 +443,7 @@ static int lfsck_prep(const struct lu_env *env, struct lfsck_instance *lfsck,
        /* Init otable-based iterator. */
        if (pos == NULL) {
                rc = iops->load(env, lfsck->li_di_oit, 0);
-               if (rc > 0) {
+               if (rc > 0 || unlikely(rc == -ENODATA)) {
                        lfsck->li_oit_over = 1;
                        rc = 0;
                }
@@ -450,10 +452,10 @@ static int lfsck_prep(const struct lu_env *env, struct lfsck_instance *lfsck,
        }
 
        rc = iops->load(env, lfsck->li_di_oit, pos->lp_oit_cookie);
-       if (rc < 0)
-               GOTO(out, rc);
-       else if (rc > 0)
+       if (rc > 0 || unlikely(rc == -ENODATA))
                lfsck->li_oit_over = 1;
+       else if (rc < 0)
+               GOTO(out, rc);
 
        if (!lfsck->li_master || fid_is_zero(&pos->lp_dir_parent))
                GOTO(out, rc = 0);
@@ -695,7 +697,7 @@ static int lfsck_master_dir_engine(const struct lu_env *env,
                if (CFS_FAIL_TIMEOUT(OBD_FAIL_LFSCK_DELAY2, cfs_fail_val) &&
                    unlikely(!thread_is_running(thread))) {
                        CDEBUG(D_LFSCK, "%s: scan dir exit for engine stop, "
-                              "parent "DFID", cookie "LPX64"\n",
+                              "parent "DFID", cookie %#llx\n",
                               lfsck_lfsck2name(lfsck),
                               PFID(lfsck_dto2fid(dir)), lfsck->li_cookie_dir);
 
@@ -711,7 +713,7 @@ static int lfsck_master_dir_engine(const struct lu_env *env,
 
                if (rc != 0) {
                        CDEBUG(D_LFSCK, "%s: scan dir failed at rec(), "
-                              "parent "DFID", cookie "LPX64": rc = %d\n",
+                              "parent "DFID", cookie %#llx: rc = %d\n",
                               lfsck_lfsck2name(lfsck),
                               PFID(lfsck_dto2fid(dir)),
                               lfsck->li_cookie_dir, rc);
@@ -757,7 +759,7 @@ checkpoint:
                lfsck_control_speed(lfsck);
                if (unlikely(!thread_is_running(thread))) {
                        CDEBUG(D_LFSCK, "%s: scan dir exit for engine stop, "
-                              "parent "DFID", cookie "LPX64"\n",
+                              "parent "DFID", cookie %#llx\n",
                               lfsck_lfsck2name(lfsck),
                               PFID(lfsck_dto2fid(dir)),
                               lfsck->li_cookie_dir);
@@ -772,6 +774,11 @@ checkpoint:
                }
 
                rc = iops->next(env, di);
+               if (rc < 0)
+                       CDEBUG(D_LFSCK, "%s dir engine fail to locate next "
+                              "for the directory "DFID": rc = %d\n",
+                              lfsck_lfsck2name(lfsck),
+                              PFID(&lfsck->li_pos_current.lp_dir_parent), rc);
        } while (rc == 0);
 
        if (rc > 0 && !lfsck->li_oit_over)
@@ -841,7 +848,7 @@ static int lfsck_master_oit_engine(const struct lu_env *env,
                if (CFS_FAIL_TIMEOUT(OBD_FAIL_LFSCK_DELAY1, cfs_fail_val) &&
                    unlikely(!thread_is_running(thread))) {
                        CDEBUG(D_LFSCK, "%s: OIT scan exit for engine stop, "
-                              "cookie "LPU64"\n",
+                              "cookie %llu\n",
                               lfsck_lfsck2name(lfsck), iops->store(env, di));
 
                        RETURN(0);
@@ -944,7 +951,7 @@ static int lfsck_master_oit_engine(const struct lu_env *env,
                target = lfsck_object_find_bottom(env, lfsck, fid);
                if (IS_ERR(target)) {
                        CDEBUG(D_LFSCK, "%s: OIT scan failed at find target "
-                              DFID", cookie "LPU64": rc = %d\n",
+                              DFID", cookie %llu: rc = %d\n",
                               lfsck_lfsck2name(lfsck), PFID(fid),
                               iops->store(env, di), rc);
                        lfsck_fail(env, lfsck, true);
@@ -981,10 +988,14 @@ checkpoint:
                        lfsck->li_oit_over = 1;
                else if (likely(rc == 0))
                        lfsck->li_current_oit_processed = 0;
+               else
+                       CDEBUG(D_LFSCK, "%s oit engine fail to locate next at "
+                              "%llu: rc = %d\n", lfsck_lfsck2name(lfsck),
+                              iops->store(env, di), rc);
 
                if (unlikely(!thread_is_running(thread))) {
                        CDEBUG(D_LFSCK, "%s: OIT scan exit for engine stop, "
-                              "cookie "LPU64"\n", lfsck_lfsck2name(lfsck),
+                              "cookie %llu\n", lfsck_lfsck2name(lfsck),
                               iops->store(env, di));
                        RETURN(0);
                }
@@ -1041,7 +1052,7 @@ int lfsck_master_engine(void *args)
                GOTO(fini_oit, rc);
 
        CDEBUG(D_LFSCK, "LFSCK entry: oit_flags = %#x, dir_flags = %#x, "
-              "oit_cookie = "LPU64", dir_cookie = "LPX64", parent = "DFID
+              "oit_cookie = %llu, dir_cookie = %#llx, parent = "DFID
               ", pid = %d\n", lfsck->li_args_oit, lfsck->li_args_dir,
               lfsck->li_pos_checkpoint.lp_oit_cookie,
               lfsck->li_pos_checkpoint.lp_dir_cookie,
@@ -1068,7 +1079,7 @@ int lfsck_master_engine(void *args)
 
        lfsck_pos_fill(env, lfsck, &lfsck->li_pos_checkpoint, false);
        CDEBUG(D_LFSCK, "LFSCK exit: oit_flags = %#x, dir_flags = %#x, "
-              "oit_cookie = "LPU64", dir_cookie = "LPX64", parent = "DFID
+              "oit_cookie = %llu, dir_cookie = %#llx, parent = "DFID
               ", pid = %d, rc = %d\n", lfsck->li_args_oit, lfsck->li_args_dir,
               lfsck->li_pos_checkpoint.lp_oit_cookie,
               lfsck->li_pos_checkpoint.lp_dir_cookie,
@@ -1588,7 +1599,7 @@ int lfsck_assistant_engine(void *args)
 
                        if (unlikely(lad->lad_exit ||
                                     !thread_is_running(mthread)))
-                               GOTO(cleanup1, rc = lad->lad_post_result);
+                               GOTO(cleanup, rc = lad->lad_post_result);
 
                        lar = list_entry(lad->lad_req_list.next,
                                         struct lfsck_assistant_req,
@@ -1613,7 +1624,7 @@ int lfsck_assistant_engine(void *args)
 
                        lao->la_req_fini(env, lar);
                        if (rc < 0 && bk->lb_param & LPF_FAILOUT)
-                               GOTO(cleanup1, rc);
+                               GOTO(cleanup, rc);
                }
 
                l_wait_event(athread->t_ctl_waitq,
@@ -1624,7 +1635,7 @@ int lfsck_assistant_engine(void *args)
                             &lwi);
 
                if (unlikely(lad->lad_exit))
-                       GOTO(cleanup1, rc = lad->lad_post_result);
+                       GOTO(cleanup, rc = lad->lad_post_result);
 
                if (!list_empty(&lad->lad_req_list))
                        continue;
@@ -1634,7 +1645,7 @@ int lfsck_assistant_engine(void *args)
                               lfsck_lfsck2name(lfsck), lad->lad_name);
 
                        if (unlikely(lad->lad_exit))
-                               GOTO(cleanup1, rc = lad->lad_post_result);
+                               GOTO(cleanup, rc = lad->lad_post_result);
 
                        lad->lad_to_post = 0;
                        LASSERT(lad->lad_post_result > 0);
@@ -1678,7 +1689,7 @@ int lfsck_assistant_engine(void *args)
                               lfsck_lfsck2name(lfsck), rc2);
 
                        if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_DOUBLESCAN))
-                               GOTO(cleanup2, rc = 0);
+                               GOTO(cleanup, rc = 0);
 
                        while (lad->lad_in_double_scan) {
                                rc = lfsck_assistant_query_others(env, com);
@@ -1686,7 +1697,7 @@ int lfsck_assistant_engine(void *args)
                                        goto p2_next;
 
                                if (rc < 0)
-                                       GOTO(cleanup2, rc);
+                                       GOTO(cleanup, rc);
 
                                /* Pull LFSCK status on related targets once
                                 * per 30 seconds if we are not notified. */
@@ -1701,27 +1712,27 @@ int lfsck_assistant_engine(void *args)
 
                                if (unlikely(lad->lad_exit ||
                                             !thread_is_running(mthread)))
-                                       GOTO(cleanup2, rc = 0);
+                                       GOTO(cleanup, rc = 0);
 
                                if (rc == -ETIMEDOUT)
                                        continue;
 
                                if (rc < 0)
-                                       GOTO(cleanup2, rc);
+                                       GOTO(cleanup, rc);
 
 p2_next:
                                rc = lao->la_handler_p2(env, com);
                                if (rc != 0)
-                                       GOTO(cleanup2, rc);
+                                       GOTO(cleanup, rc);
 
                                if (unlikely(lad->lad_exit ||
                                             !thread_is_running(mthread)))
-                                       GOTO(cleanup2, rc = 0);
+                                       GOTO(cleanup, rc = 0);
                        }
                }
        }
 
-cleanup1:
+cleanup:
        /* Cleanup the unfinished requests. */
        spin_lock(&lad->lad_lock);
        if (rc < 0)
@@ -1730,6 +1741,7 @@ cleanup1:
        if (lad->lad_exit && lad->lad_post_result <= 0)
                lao->la_fill_pos(env, com, &lfsck->li_pos_checkpoint);
 
+       thread_set_flags(athread, SVC_STOPPING);
        while (!list_empty(&lad->lad_req_list)) {
                lar = list_entry(lad->lad_req_list.next,
                                 struct lfsck_assistant_req,
@@ -1745,7 +1757,6 @@ cleanup1:
        LASSERTF(lad->lad_prefetched == 0, "unmatched prefeteched objs %d\n",
                 lad->lad_prefetched);
 
-cleanup2:
        memset(lr, 0, sizeof(*lr));
        if (rc > 0) {
                lr->lr_event = LE_PHASE2_DONE;