Whamcloud - gitweb
LU-14119 lfsck: replace dt_lookup() with dt_lookup_dir()
[fs/lustre-release.git] / lustre / lfsck / lfsck_engine.c
index a25d949..f9c65b8 100644 (file)
@@ -93,17 +93,6 @@ static void lfsck_di_dir_put(const struct lu_env *env, struct lfsck_instance *lf
        iops->put(env, di);
 }
 
-static int lfsck_parent_fid(const struct lu_env *env, struct dt_object *obj,
-                           struct lu_fid *fid)
-{
-       if (unlikely(!S_ISDIR(lfsck_object_type(obj)) ||
-                    !dt_try_as_dir(env, obj)))
-               return -ENOTDIR;
-
-       return dt_lookup(env, obj, (struct dt_rec *)fid,
-                        (const struct dt_key *)"..");
-}
-
 /**
  * Check whether needs to scan the directory or not.
  *
@@ -136,6 +125,7 @@ static int lfsck_needs_scan_dir(const struct lu_env *env,
        struct lfsck_thread_info *info    = lfsck_env_info(env);
        struct lu_fid            *fid     = &info->lti_fid;
        struct lu_seq_range      *range   = &info->lti_range;
+       struct lu_attr           *la      = &info->lti_la;
        struct seq_server_site   *ss      = lfsck_dev_site(lfsck);
        __u32                     idx     = lfsck_dev_idx(lfsck);
        int                       depth   = 0;
@@ -144,9 +134,21 @@ static int lfsck_needs_scan_dir(const struct lu_env *env,
        if (list_empty(&lfsck->li_list_dir) || !S_ISDIR(lfsck_object_type(obj)))
                return 0;
 
+       *fid = *lfsck_dto2fid(obj);
+       rc = dt_attr_get(env, obj, la);
+       if (unlikely(rc || (la->la_valid & LA_FLAGS &&
+                           la->la_flags & LUSTRE_ORPHAN_FL))) {
+               /* Orphan directory is empty, does not need scan. */
+               CDEBUG(D_INFO,
+                      "%s: skip orphan dir "DFID", %llx/%x: rc = %d\n",
+                      lfsck_lfsck2name(lfsck), PFID(fid),
+                      la->la_valid, la->la_flags, rc);
+
+               return rc;
+       }
+
        LASSERT(ss != NULL);
 
-       *fid = *lfsck_dto2fid(obj);
        while (1) {
                /* Global /ROOT is visible. */
                if (unlikely(lu_fid_eq(fid, &lfsck->li_global_root_fid)))
@@ -177,6 +179,7 @@ static int lfsck_needs_scan_dir(const struct lu_env *env,
                if (fid_is_norm(fid))
                        return 1;
 
+               /* Only true after "obj = NULL" set below */
                if (obj == NULL) {
                        obj = lfsck_object_find_bottom(env, lfsck, fid);
                        if (IS_ERR(obj))
@@ -187,7 +190,7 @@ static int lfsck_needs_scan_dir(const struct lu_env *env,
                                GOTO(out, rc = 0);
                }
 
-               dt_read_lock(env, obj, MOR_TGT_CHILD);
+               dt_read_lock(env, obj, DT_TGT_CHILD);
                if (unlikely(lfsck_is_dead_obj(obj))) {
                        dt_read_unlock(env, obj);
 
@@ -203,7 +206,7 @@ static int lfsck_needs_scan_dir(const struct lu_env *env,
                if (rc < 0 && rc != -ENODATA)
                        GOTO(out, rc);
 
-               rc = lfsck_parent_fid(env, obj, fid);
+               rc = dt_lookup_dir(env, obj, dotdot, fid);
                if (depth > 0)
                        lfsck_object_put(env, obj);
 
@@ -234,7 +237,7 @@ static int lfsck_load_stripe_lmv(const struct lu_env *env,
        LASSERT(lfsck->li_obj_dir == NULL);
        LASSERT(lfsck->li_lmv == NULL);
 
-       rc = lfsck_read_stripe_lmv(env, obj, lmv);
+       rc = lfsck_read_stripe_lmv(env, lfsck, obj, lmv);
        if (rc == -ENODATA) {
                lfsck->li_obj_dir = lfsck_object_get(obj);
 
@@ -260,7 +263,7 @@ static int lfsck_load_stripe_lmv(const struct lu_env *env,
                else
                        stripes = lmv->lmv_stripe_count;
 
-               OBD_ALLOC_LARGE(lslr, sizeof(*lslr) * stripes);
+               OBD_ALLOC_PTR_ARRAY_LARGE(lslr, stripes);
                if (lslr == NULL) {
                        OBD_FREE_PTR(llmv);
 
@@ -620,7 +623,6 @@ static int lfsck_double_scan(const struct lu_env *env,
 {
        struct lfsck_component *com;
        struct lfsck_component *next;
-       struct l_wait_info      lwi = { 0 };
        int                     rc  = 0;
        int                     rc1 = 0;
 
@@ -630,9 +632,8 @@ static int lfsck_double_scan(const struct lu_env *env,
                        rc1 = rc;
        }
 
-       l_wait_event(lfsck->li_thread.t_ctl_waitq,
-                    atomic_read(&lfsck->li_double_scan_count) == 0,
-                    &lwi);
+       wait_event_idle(lfsck->li_thread.t_ctl_waitq,
+                       atomic_read(&lfsck->li_double_scan_count) == 0);
 
        if (lfsck->li_status != LS_PAUSED &&
            lfsck->li_status != LS_CO_PAUSED) {
@@ -960,19 +961,8 @@ static int lfsck_master_oit_engine(const struct lu_env *env,
                                goto checkpoint;
                }
 
-               if (dt_object_exists(target)) {
-                       struct lu_attr la = { .la_valid = 0 };
-
-                       rc = dt_attr_get(env, target, &la);
-                       if (likely(!rc && (!(la.la_valid & LA_FLAGS) ||
-                                          !(la.la_flags & LUSTRE_ORPHAN_FL))))
-                               rc = lfsck_exec_oit(env, lfsck, target);
-                       else
-                               CDEBUG(D_INFO,
-                                      "%s: orphan "DFID", %llx/%x: rc = %d\n",
-                                      lfsck_lfsck2name(lfsck), PFID(fid),
-                                      la.la_valid, la.la_flags, rc);
-               }
+               if (dt_object_exists(target))
+                       rc = lfsck_exec_oit(env, lfsck, target);
 
                lfsck_object_put(env, target);
                if (rc != 0 && bk->lb_param & LPF_FAILOUT)
@@ -1023,7 +1013,6 @@ int lfsck_master_engine(void *args)
        struct dt_object         *oit_obj  = lfsck->li_obj_oit;
        const struct dt_it_ops   *oit_iops = &oit_obj->do_index_ops->dio_it;
        struct dt_it             *oit_di;
-       struct l_wait_info        lwi      = { 0 };
        int                       rc;
        ENTRY;
 
@@ -1071,7 +1060,7 @@ int lfsck_master_engine(void *args)
               lfsck->li_pos_checkpoint.lp_oit_cookie,
               lfsck->li_pos_checkpoint.lp_dir_cookie,
               PFID(&lfsck->li_pos_checkpoint.lp_dir_parent),
-              current_pid());
+              current->pid);
 
        spin_lock(&lfsck->li_lock);
        if (unlikely(!thread_is_starting(thread))) {
@@ -1083,10 +1072,9 @@ int lfsck_master_engine(void *args)
        spin_unlock(&lfsck->li_lock);
        wake_up_all(&thread->t_ctl_waitq);
 
-       l_wait_event(thread->t_ctl_waitq,
-                    lfsck->li_start_unplug ||
-                    !thread_is_running(thread),
-                    &lwi);
+       wait_event_idle(thread->t_ctl_waitq,
+                       lfsck->li_start_unplug ||
+                       !thread_is_running(thread));
        if (!thread_is_running(thread))
                GOTO(fini_oit, rc = 0);
 
@@ -1103,7 +1091,7 @@ int lfsck_master_engine(void *args)
               lfsck->li_pos_checkpoint.lp_oit_cookie,
               lfsck->li_pos_checkpoint.lp_dir_cookie,
               PFID(&lfsck->li_pos_checkpoint.lp_dir_parent),
-              current_pid(), rc);
+              current->pid, rc);
 
        if (!OBD_FAIL_CHECK(OBD_FAIL_LFSCK_CRASH))
                rc = lfsck_post(env, lfsck, rc);
@@ -1584,9 +1572,8 @@ int lfsck_assistant_engine(void *args)
        struct lfsck_assistant_data       *lad     = com->lc_data;
        struct ptlrpc_thread              *mthread = &lfsck->li_thread;
        struct ptlrpc_thread              *athread = &lad->lad_thread;
-       struct lfsck_assistant_operations *lao     = lad->lad_ops;
+       const struct lfsck_assistant_operations *lao     = lad->lad_ops;
        struct lfsck_assistant_req        *lar;
-       struct l_wait_info                 lwi     = { 0 };
        int                                rc      = 0;
        int                                rc1     = 0;
        int                                rc2;
@@ -1647,12 +1634,11 @@ int lfsck_assistant_engine(void *args)
                                GOTO(cleanup, rc);
                }
 
-               l_wait_event(athread->t_ctl_waitq,
-                            !lfsck_assistant_req_empty(lad) ||
-                            test_bit(LAD_EXIT, &lad->lad_flags) ||
-                            test_bit(LAD_TO_POST, &lad->lad_flags) ||
-                            test_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags),
-                            &lwi);
+               wait_event_idle(athread->t_ctl_waitq,
+                               !lfsck_assistant_req_empty(lad) ||
+                               test_bit(LAD_EXIT, &lad->lad_flags) ||
+                               test_bit(LAD_TO_POST, &lad->lad_flags) ||
+                               test_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags));
 
                if (unlikely(test_bit(LAD_EXIT, &lad->lad_flags)))
                        GOTO(cleanup, rc = lad->lad_post_result);
@@ -1712,6 +1698,8 @@ int lfsck_assistant_engine(void *args)
                                GOTO(cleanup, rc = 0);
 
                        while (test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags)) {
+                               int seconds = 30;
+
                                rc = lfsck_assistant_query_others(env, com);
                                if (lfsck_phase2_next_ready(lad))
                                        goto p2_next;
@@ -1721,26 +1709,24 @@ int lfsck_assistant_engine(void *args)
 
                                /* Pull LFSCK status on related targets once
                                 * per 30 seconds if we are not notified. */
-                               lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(30),
-                                                          cfs_time_seconds(1),
-                                                          NULL, NULL);
-                               rc = l_wait_event(athread->t_ctl_waitq,
-                                       lfsck_phase2_next_ready(lad) ||
-                                       test_bit(LAD_EXIT, &lad->lad_flags) ||
-                                       !thread_is_running(mthread),
-                                       &lwi);
+                               while (seconds > 0 &&
+                                      wait_event_idle_timeout(
+                                              athread->t_ctl_waitq,
+                                              lfsck_phase2_next_ready(lad) ||
+                                              test_bit(LAD_EXIT,
+                                                       &lad->lad_flags) ||
+                                              !thread_is_running(mthread),
+                                              cfs_time_seconds(1)) == 0)
+                                       seconds -= 1;
 
                                if (unlikely(
                                        test_bit(LAD_EXIT, &lad->lad_flags) ||
                                        !thread_is_running(mthread)))
                                        GOTO(cleanup, rc = 0);
 
-                               if (rc == -ETIMEDOUT)
+                               if (seconds == 0)
                                        continue;
 
-                               if (rc < 0)
-                                       GOTO(cleanup, rc);
-
 p2_next:
                                rc = lao->la_handler_p2(env, com);
                                if (rc != 0)