Whamcloud - gitweb
LU-10467 lustre: convert most users of LWI_TIMEOUT_INTERVAL()
[fs/lustre-release.git] / lustre / lfsck / lfsck_engine.c
index f49fda2..914ad83 100644 (file)
@@ -136,6 +136,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 +145,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 +190,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 +201,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);
 
@@ -234,7 +248,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);
 
@@ -620,7 +634,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 +643,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) {
@@ -1012,7 +1024,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;
 
@@ -1072,10 +1083,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);
 
@@ -1235,7 +1245,7 @@ again:
        }
        spin_unlock(&ltds->ltd_lock);
 
-       rc = ptlrpc_set_wait(set);
+       rc = ptlrpc_set_wait(env, set);
        if (rc < 0) {
                ptlrpc_set_destroy(set);
                RETURN(rc);
@@ -1330,7 +1340,7 @@ static int lfsck_assistant_notify_others(const struct lu_env *env,
                up_read(&ltds->ltd_rw_sem);
 
                /* Sync up */
-               rc = ptlrpc_set_wait(set);
+               rc = ptlrpc_set_wait(env, set);
                if (rc < 0) {
                        ptlrpc_set_destroy(set);
                        RETURN(rc);
@@ -1462,7 +1472,7 @@ again:
                }
                spin_unlock(&ltds->ltd_lock);
 
-               rc = ptlrpc_set_wait(set);
+               rc = ptlrpc_set_wait(env, set);
                if (rc < 0) {
                        ptlrpc_set_destroy(set);
                        RETURN(rc);
@@ -1536,7 +1546,7 @@ again:
                break;
        }
 
-       rc1 = ptlrpc_set_wait(set);
+       rc1 = ptlrpc_set_wait(env, set);
        ptlrpc_set_destroy(set);
 
        RETURN(rc != 0 ? rc : rc1);
@@ -1606,7 +1616,7 @@ int lfsck_assistant_engine(void *args)
                while (!list_empty(&lad->lad_req_list)) {
                        bool wakeup = false;
 
-                       if (unlikely(lad->lad_exit ||
+                       if (unlikely(test_bit(LAD_EXIT, &lad->lad_flags) ||
                                     !thread_is_running(mthread)))
                                GOTO(cleanup, rc = lad->lad_post_result);
 
@@ -1638,25 +1648,25 @@ int lfsck_assistant_engine(void *args)
 
                l_wait_event(athread->t_ctl_waitq,
                             !lfsck_assistant_req_empty(lad) ||
-                            lad->lad_exit ||
-                            lad->lad_to_post ||
-                            lad->lad_to_double_scan,
+                            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);
 
-               if (unlikely(lad->lad_exit))
+               if (unlikely(test_bit(LAD_EXIT, &lad->lad_flags)))
                        GOTO(cleanup, rc = lad->lad_post_result);
 
                if (!list_empty(&lad->lad_req_list))
                        continue;
 
-               if (lad->lad_to_post) {
+               if (test_bit(LAD_TO_POST, &lad->lad_flags)) {
                        CDEBUG(D_LFSCK, "%s: %s LFSCK assistant thread post\n",
                               lfsck_lfsck2name(lfsck), lad->lad_name);
 
-                       if (unlikely(lad->lad_exit))
+                       if (unlikely(test_bit(LAD_EXIT, &lad->lad_flags)))
                                GOTO(cleanup, rc = lad->lad_post_result);
 
-                       lad->lad_to_post = 0;
+                       clear_bit(LAD_TO_POST, &lad->lad_flags);
                        LASSERT(lad->lad_post_result > 0);
 
                        /* Wakeup the master engine to go ahead. */
@@ -1673,10 +1683,10 @@ int lfsck_assistant_engine(void *args)
                               lad->lad_name, rc);
                }
 
-               if (lad->lad_to_double_scan) {
-                       lad->lad_to_double_scan = 0;
+               if (test_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags)) {
+                       clear_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags);
                        atomic_inc(&lfsck->li_double_scan_count);
-                       lad->lad_in_double_scan = 1;
+                       set_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags);
                        wake_up_all(&mthread->t_ctl_waitq);
 
                        com->lc_new_checked = 0;
@@ -1700,7 +1710,9 @@ int lfsck_assistant_engine(void *args)
                        if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_NO_DOUBLESCAN))
                                GOTO(cleanup, rc = 0);
 
-                       while (lad->lad_in_double_scan) {
+                       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;
@@ -1710,32 +1722,32 @@ 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) ||
-                                       lad->lad_exit ||
-                                       !thread_is_running(mthread),
-                                       &lwi);
-
-                               if (unlikely(lad->lad_exit ||
-                                            !thread_is_running(mthread)))
+                               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)
                                        GOTO(cleanup, rc);
 
-                               if (unlikely(lad->lad_exit ||
-                                            !thread_is_running(mthread)))
+                               if (unlikely(
+                                       test_bit(LAD_EXIT, &lad->lad_flags) ||
+                                       !thread_is_running(mthread)))
                                        GOTO(cleanup, rc = 0);
                        }
                }
@@ -1747,7 +1759,7 @@ cleanup:
        if (rc < 0)
                lad->lad_assistant_status = rc;
 
-       if (lad->lad_exit && lad->lad_post_result <= 0)
+       if (test_bit(LAD_EXIT, &lad->lad_flags) && lad->lad_post_result <= 0)
                lao->la_fill_pos(env, com, &lfsck->li_pos_checkpoint);
 
        thread_set_flags(athread, SVC_STOPPING);
@@ -1821,8 +1833,8 @@ cleanup:
        /* Under force exit case, some requests may be just freed without
         * verification, those objects should be re-handled when next run.
         * So not update the on-disk trace file under such case. */
-       if (lad->lad_in_double_scan) {
-               if (!lad->lad_exit)
+       if (test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags)) {
+               if (!test_bit(LAD_EXIT, &lad->lad_flags))
                        rc1 = lao->la_double_scan_result(env, com, rc);
 
                CDEBUG(D_LFSCK, "%s: LFSCK assistant phase2 scan "
@@ -1831,13 +1843,12 @@ cleanup:
        }
 
 fini:
-       if (lad->lad_in_double_scan)
+       if (test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags))
                atomic_dec(&lfsck->li_double_scan_count);
 
        spin_lock(&lad->lad_lock);
        lad->lad_assistant_status = (rc1 != 0 ? rc1 : rc);
        thread_set_flags(athread, SVC_STOPPED);
-       wake_up_all(&mthread->t_ctl_waitq);
        lad->lad_task = NULL;
        spin_unlock(&lad->lad_lock);
 
@@ -1846,6 +1857,7 @@ fini:
               lad->lad_assistant_status);
 
        lfsck_thread_args_fini(lta);
+       wake_up_all(&mthread->t_ctl_waitq);
 
        return rc;
 }