Whamcloud - gitweb
LU-9679 lustre: use LIST_HEAD() for local lists.
[fs/lustre-release.git] / lustre / lfsck / lfsck_lib.c
index 6f2fa9e..72be4f5 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/kthread.h>
 #include <linux/sched.h>
 #include <linux/list.h>
+#include <linux/delay.h>
 #include <lu_object.h>
 #include <dt_object.h>
 #include <md_object.h>
@@ -62,9 +63,9 @@ 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 struct list_head lfsck_instance_list;
-static struct list_head lfsck_ost_orphan_list;
-static struct list_head lfsck_mdt_orphan_list;
+static LIST_HEAD(lfsck_instance_list);
+static LIST_HEAD(lfsck_ost_orphan_list);
+static LIST_HEAD(lfsck_mdt_orphan_list);
 static DEFINE_SPINLOCK(lfsck_instance_lock);
 
 const char *lfsck_flags_names[] = {
@@ -379,8 +380,14 @@ static int __lfsck_ibits_lock(const struct lu_env *env,
                einfo->ei_res_id = resid;
 
                rc = dt_object_lock(env, obj, lh, einfo, policy);
+               /* for regular checks LFSCK doesn't use LDLM locking,
+                * so the state isn't coherent. here we just took LDLM
+                * lock for coherency and it's time to invalidate
+                * previous state */
+               if (rc == ELDLM_OK)
+                       dt_invalidate(env, obj);
        } else {
-               rc = ldlm_cli_enqueue_local(lfsck->li_namespace, resid,
+               rc = ldlm_cli_enqueue_local(env, lfsck->li_namespace, resid,
                                            LDLM_IBITS, policy, mode,
                                            &flags, ldlm_blocking_ast,
                                            ldlm_completion_ast, NULL, NULL,
@@ -426,6 +433,36 @@ int lfsck_ibits_lock(const struct lu_env *env, struct lfsck_instance *lfsck,
 }
 
 /**
+ * Request the remote LOOKUP lock for the given object.
+ *
+ * If \a pobj is remote, the LOOKUP lock of \a obj is on the MDT where
+ * \a pobj is, acquire LOOKUP lock there.
+ *
+ * \param[in] env      pointer to the thread context
+ * \param[in] lfsck    pointer to the lfsck instance
+ * \param[in] pobj     pointer to parent dt_object
+ * \param[in] obj      pointer to the dt_object to be locked
+ * \param[out] lh      pointer to the lock handle
+ * \param[in] mode     the mode for the ldlm lock to be acquired
+ *
+ * \retval             0 for success
+ * \retval             negative error number on failure
+ */
+int lfsck_remote_lookup_lock(const struct lu_env *env,
+                            struct lfsck_instance *lfsck,
+                            struct dt_object *pobj, struct dt_object *obj,
+                            struct lustre_handle *lh, enum ldlm_mode mode)
+{
+       struct ldlm_res_id *resid = &lfsck_env_info(env)->lti_resid;
+
+       LASSERT(!lustre_handle_is_used(lh));
+
+       fid_build_reg_res_name(lfsck_dto2fid(obj), resid);
+       return __lfsck_ibits_lock(env, lfsck, pobj, resid, lh,
+                                 MDS_INODELOCK_LOOKUP, mode);
+}
+
+/**
  * Release the the specified ibits lock.
  *
  * If the lock has been acquired before, release it
@@ -727,14 +764,14 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
        /* 3b. 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, 1);
+                      (const struct dt_key *)dot, th);
        if (rc != 0)
                GOTO(unlock, rc);
 
        /* 4b. 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, 1);
+                      (const struct dt_key *)dotdot, th);
        if (rc != 0)
                GOTO(unlock, rc);
 
@@ -748,7 +785,7 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
        /* 6b. 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, 1);
+                      (const struct dt_key *)name, th);
        if (rc != 0)
                GOTO(stop, rc);
 
@@ -893,14 +930,14 @@ static int lfsck_create_lpf_remote(const struct lu_env *env,
        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, 1);
+                      (const struct dt_key *)dot, th);
        if (rc != 0)
                GOTO(unlock, rc);
 
        /* 4b. 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, 1);
+                      (const struct dt_key *)dotdot, th);
        if (rc != 0)
                GOTO(unlock, rc);
 
@@ -948,7 +985,7 @@ static int lfsck_create_lpf_remote(const struct lu_env *env,
 
        /* 5b. insert name into parent dir */
        rc = dt_insert(env, parent, (const struct dt_rec *)rec,
-                      (const struct dt_key *)name, th, 1);
+                      (const struct dt_key *)name, th);
        if (rc != 0)
                GOTO(stop, rc);
 
@@ -1835,14 +1872,12 @@ bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
        bool dirty = false;
 
        if (limit != LFSCK_SPEED_NO_LIMIT) {
-               if (limit > msecs_to_jiffies(MSEC_PER_SEC)) {
-                       lfsck->li_sleep_rate = limit /
-                                              msecs_to_jiffies(MSEC_PER_SEC);
+               if (limit > cfs_time_seconds(1)) {
+                       lfsck->li_sleep_rate = limit / cfs_time_seconds(1);
                        lfsck->li_sleep_jif = 1;
                } else {
                        lfsck->li_sleep_rate = 1;
-                       lfsck->li_sleep_jif = msecs_to_jiffies(MSEC_PER_SEC) /
-                                             limit;
+                       lfsck->li_sleep_jif = cfs_time_seconds(1) / limit;
                }
        } else {
                lfsck->li_sleep_jif = 0;
@@ -1860,16 +1895,12 @@ bool __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
 void lfsck_control_speed(struct lfsck_instance *lfsck)
 {
        struct ptlrpc_thread *thread = &lfsck->li_thread;
-       struct l_wait_info    lwi;
 
        if (lfsck->li_sleep_jif > 0 &&
            lfsck->li_new_scanned >= lfsck->li_sleep_rate) {
-               lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
-                                      LWI_ON_SIGNAL_NOOP, NULL);
-
-               l_wait_event(thread->t_ctl_waitq,
-                            !thread_is_running(thread),
-                            &lwi);
+               wait_event_idle_timeout(thread->t_ctl_waitq,
+                                       !thread_is_running(thread),
+                                       lfsck->li_sleep_jif);
                lfsck->li_new_scanned = 0;
        }
 }
@@ -1878,16 +1909,12 @@ void lfsck_control_speed_by_self(struct lfsck_component *com)
 {
        struct lfsck_instance   *lfsck  = com->lc_lfsck;
        struct ptlrpc_thread    *thread = &lfsck->li_thread;
-       struct l_wait_info       lwi;
 
        if (lfsck->li_sleep_jif > 0 &&
            com->lc_new_scanned >= lfsck->li_sleep_rate) {
-               lwi = LWI_TIMEOUT_INTR(lfsck->li_sleep_jif, NULL,
-                                      LWI_ON_SIGNAL_NOOP, NULL);
-
-               l_wait_event(thread->t_ctl_waitq,
-                            !thread_is_running(thread),
-                            &lwi);
+               wait_event_idle_timeout(thread->t_ctl_waitq,
+                                       !thread_is_running(thread),
+                                       lfsck->li_sleep_jif);
                com->lc_new_scanned = 0;
        }
 }
@@ -2336,7 +2363,7 @@ static int lfsck_stop_notify(const struct lu_env *env,
                laia->laia_ltd = ltd;
                laia->laia_lr = lr;
 
-               rc = lfsck_async_request(env, ltd, lr, set,
+               rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
                                         lfsck_async_interpret_common,
                                         laia, LFSCK_NOTIFY);
                if (rc != 0) {
@@ -2347,7 +2374,7 @@ static int lfsck_stop_notify(const struct lu_env *env,
                               ltd->ltd_index, lad->lad_name, rc);
                        lfsck_tgt_put(ltd);
                } else {
-                       rc = ptlrpc_set_wait(set);
+                       rc = ptlrpc_set_wait(env, set);
                }
 
                ptlrpc_set_destroy(set);
@@ -2374,22 +2401,18 @@ static int lfsck_async_interpret(const struct lu_env *env,
        return 0;
 }
 
-int lfsck_async_request(const struct lu_env *env, struct lfsck_tgt_desc *ltd,
+int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
                        struct lfsck_request *lr,
                        struct ptlrpc_request_set *set,
                        ptlrpc_interpterer_t interpreter,
                        void *args, int request)
 {
-       struct obd_import *imp = class_exp2cliimp(ltd->ltd_exp);
        struct lfsck_async_interpret_args *laia;
        struct ptlrpc_request             *req;
        struct lfsck_request              *tmp;
        struct req_format                 *format;
        int                                rc;
 
-       if (unlikely(ltd->ltd_dead))
-               return -ENODEV;
-
        switch (request) {
        case LFSCK_NOTIFY:
                format = &RQF_LFSCK_NOTIFY;
@@ -2399,11 +2422,11 @@ int lfsck_async_request(const struct lu_env *env, struct lfsck_tgt_desc *ltd,
                break;
        default:
                CDEBUG(D_LFSCK, "%s: unknown async request %d: rc = %d\n",
-                      imp->imp_obd->obd_name, request, -EINVAL);
+                      exp->exp_obd->obd_name, request, -EINVAL);
                return -EINVAL;
        }
 
-       req = ptlrpc_request_alloc(imp, format);
+       req = ptlrpc_request_alloc(class_exp2cliimp(exp), format);
        if (req == NULL)
                return -ENOMEM;
 
@@ -2414,18 +2437,11 @@ int lfsck_async_request(const struct lu_env *env, struct lfsck_tgt_desc *ltd,
                return rc;
        }
 
-       if (unlikely(imp->imp_state != LUSTRE_IMP_FULL))
-               LCONSOLE_INFO("%s (%d): sending async LFSCK RPC (%u) to %s%4x "
-                             "on non-full connection (%u), may be blocked.\n",
-                             imp->imp_obd->obd_name, current_pid(),
-                             lr->lr_event, ltd->ltd_for_ost ? "OST" : "MDT",
-                             ltd->ltd_index, imp->imp_state);
-
        tmp = req_capsule_client_get(&req->rq_pill, &RMF_LFSCK_REQUEST);
        *tmp = *lr;
        ptlrpc_request_set_replen(req);
 
-       laia = ptlrpc_req_async_args(req);
+       laia = ptlrpc_req_async_args(laia, req);
        *laia = *(struct lfsck_async_interpret_args *)args;
        if (laia->laia_com != NULL)
                lfsck_component_get(laia->laia_com);
@@ -2472,7 +2488,7 @@ again:
 
                laia->laia_ltd = ltd;
                up_read(&ltds->ltd_rw_sem);
-               rc = lfsck_async_request(env, ltd, lr, set,
+               rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
                                         lfsck_async_interpret_common,
                                         laia, LFSCK_QUERY);
                if (rc != 0) {
@@ -2495,7 +2511,7 @@ again:
                goto again;
        }
 
-       rc = ptlrpc_set_wait(set);
+       rc = ptlrpc_set_wait(env, set);
        ptlrpc_set_destroy(set);
 
        RETURN(rc);
@@ -2515,10 +2531,7 @@ int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
 
        lad->lad_assistant_status = 0;
        lad->lad_post_result = 0;
-       lad->lad_to_post = 0;
-       lad->lad_to_double_scan = 0;
-       lad->lad_in_double_scan = 0;
-       lad->lad_exit = 0;
+       lad->lad_flags = 0;
        lad->lad_advance_lock = false;
        thread_set_flags(athread, 0);
 
@@ -2533,13 +2546,10 @@ int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
                       "rc = %d\n", lfsck_lfsck2name(lfsck), lad->lad_name, rc);
                lfsck_thread_args_fini(lta);
        } else {
-               struct l_wait_info lwi = { 0 };
-
-               l_wait_event(mthread->t_ctl_waitq,
-                            thread_is_running(athread) ||
-                            thread_is_stopped(athread) ||
-                            !thread_is_starting(mthread),
-                            &lwi);
+               wait_event_idle(mthread->t_ctl_waitq,
+                               thread_is_running(athread) ||
+                               thread_is_stopped(athread) ||
+                               !thread_is_starting(mthread));
                if (unlikely(!thread_is_starting(mthread)))
                        /* stopped by race */
                        rc = -ESRCH;
@@ -2558,13 +2568,11 @@ int lfsck_checkpoint_generic(const struct lu_env *env,
        struct lfsck_assistant_data     *lad     = com->lc_data;
        struct ptlrpc_thread            *mthread = &com->lc_lfsck->li_thread;
        struct ptlrpc_thread            *athread = &lad->lad_thread;
-       struct l_wait_info               lwi     = { 0 };
 
-       l_wait_event(mthread->t_ctl_waitq,
-                    list_empty(&lad->lad_req_list) ||
-                    !thread_is_running(mthread) ||
-                    thread_is_stopped(athread),
-                    &lwi);
+       wait_event_idle(mthread->t_ctl_waitq,
+                       list_empty(&lad->lad_req_list) ||
+                       !thread_is_running(mthread) ||
+                       thread_is_stopped(athread));
 
        if (!thread_is_running(mthread) || thread_is_stopped(athread))
                return LFSCK_CHECKPOINT_SKIP;
@@ -2578,21 +2586,19 @@ void lfsck_post_generic(const struct lu_env *env,
        struct lfsck_assistant_data     *lad     = com->lc_data;
        struct ptlrpc_thread            *athread = &lad->lad_thread;
        struct ptlrpc_thread            *mthread = &com->lc_lfsck->li_thread;
-       struct l_wait_info               lwi     = { 0 };
 
        lad->lad_post_result = *result;
        if (*result <= 0)
-               lad->lad_exit = 1;
-       lad->lad_to_post = 1;
+               set_bit(LAD_EXIT, &lad->lad_flags);
+       set_bit(LAD_TO_POST, &lad->lad_flags);
 
        CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s post, rc = %d\n",
               lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, *result);
 
        wake_up_all(&athread->t_ctl_waitq);
-       l_wait_event(mthread->t_ctl_waitq,
-                    (*result > 0 && list_empty(&lad->lad_req_list)) ||
-                    thread_is_stopped(athread),
-                    &lwi);
+       wait_event_idle(mthread->t_ctl_waitq,
+                       (*result > 0 && list_empty(&lad->lad_req_list)) ||
+                       thread_is_stopped(athread));
 
        if (lad->lad_assistant_status < 0)
                *result = lad->lad_assistant_status;
@@ -2607,22 +2613,20 @@ int lfsck_double_scan_generic(const struct lu_env *env,
        struct lfsck_assistant_data     *lad     = com->lc_data;
        struct ptlrpc_thread            *mthread = &com->lc_lfsck->li_thread;
        struct ptlrpc_thread            *athread = &lad->lad_thread;
-       struct l_wait_info               lwi     = { 0 };
 
        if (status != LS_SCANNING_PHASE2)
-               lad->lad_exit = 1;
+               set_bit(LAD_EXIT, &lad->lad_flags);
        else
-               lad->lad_to_double_scan = 1;
+               set_bit(LAD_TO_DOUBLE_SCAN, &lad->lad_flags);
 
        CDEBUG(D_LFSCK, "%s: waiting for assistant to do %s double_scan, "
               "status %d\n",
               lfsck_lfsck2name(com->lc_lfsck), lad->lad_name, status);
 
        wake_up_all(&athread->t_ctl_waitq);
-       l_wait_event(mthread->t_ctl_waitq,
-                    lad->lad_in_double_scan ||
-                    thread_is_stopped(athread),
-                    &lwi);
+       wait_event_idle(mthread->t_ctl_waitq,
+                       test_bit(LAD_IN_DOUBLE_SCAN, &lad->lad_flags) ||
+                       thread_is_stopped(athread));
 
        CDEBUG(D_LFSCK, "%s: the assistant has done %s double_scan, "
               "status %d\n", lfsck_lfsck2name(com->lc_lfsck), lad->lad_name,
@@ -2640,14 +2644,12 @@ void lfsck_quit_generic(const struct lu_env *env,
        struct lfsck_assistant_data     *lad     = com->lc_data;
        struct ptlrpc_thread            *mthread = &com->lc_lfsck->li_thread;
        struct ptlrpc_thread            *athread = &lad->lad_thread;
-       struct l_wait_info               lwi     = { 0 };
 
-       lad->lad_exit = 1;
+       set_bit(LAD_EXIT, &lad->lad_flags);
        wake_up_all(&athread->t_ctl_waitq);
-       l_wait_event(mthread->t_ctl_waitq,
-                    thread_is_init(athread) ||
-                    thread_is_stopped(athread),
-                    &lwi);
+       wait_event_idle(mthread->t_ctl_waitq,
+                       thread_is_init(athread) ||
+                       thread_is_stopped(athread));
 }
 
 int lfsck_load_one_trace_file(const struct lu_env *env,
@@ -2716,10 +2718,14 @@ unlink:
                RETURN(PTR_ERR(obj));
 
        rc = obj->do_ops->do_index_try(env, obj, ft);
-       if (rc)
+       if (rc) {
                lfsck_object_put(env, obj);
-       else
+               CDEBUG(D_LFSCK, "%s: LFSCK fail to load "
+                      "sub trace file %s: rc = %d\n",
+                      lfsck_lfsck2name(com->lc_lfsck), name, rc);
+       } else {
                *child = obj;
+       }
 
        RETURN(rc);
 }
@@ -2746,8 +2752,7 @@ int lfsck_load_sub_trace_files(const struct lu_env *env,
 }
 
 /* external interfaces */
-
-int lfsck_get_speed(struct seq_file *m, struct dt_device *key)
+int lfsck_get_speed(char *buf, struct dt_device *key)
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -2759,8 +2764,9 @@ int lfsck_get_speed(struct seq_file *m, struct dt_device *key)
                RETURN(rc);
 
        lfsck = lfsck_instance_find(key, true, false);
-       if (likely(lfsck != NULL)) {
-               seq_printf(m, "%u\n", lfsck->li_bookmark_ram.lb_speed_limit);
+       if (lfsck && buf) {
+               rc = sprintf(buf, "%u\n",
+                            lfsck->li_bookmark_ram.lb_speed_limit);
                lfsck_instance_put(&env, lfsck);
        } else {
                rc = -ENXIO;
@@ -2800,7 +2806,7 @@ int lfsck_set_speed(struct dt_device *key, __u32 val)
 }
 EXPORT_SYMBOL(lfsck_set_speed);
 
-int lfsck_get_windows(struct seq_file *m, struct dt_device *key)
+int lfsck_get_windows(char *buf, struct dt_device *key)
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -2813,7 +2819,8 @@ int lfsck_get_windows(struct seq_file *m, struct dt_device *key)
 
        lfsck = lfsck_instance_find(key, true, false);
        if (likely(lfsck != NULL)) {
-               seq_printf(m, "%u\n", lfsck->li_bookmark_ram.lb_async_windows);
+               rc = sprintf(buf, "%u\n",
+                            lfsck->li_bookmark_ram.lb_async_windows);
                lfsck_instance_put(&env, lfsck);
        } else {
                rc = -ENXIO;
@@ -2935,7 +2942,7 @@ static int lfsck_stop_all(const struct lu_env *env,
                LASSERT(ltd != NULL);
 
                laia->laia_ltd = ltd;
-               rc = lfsck_async_request(env, ltd, lr, set,
+               rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
                                         lfsck_async_interpret, laia,
                                         LFSCK_NOTIFY);
                if (rc != 0) {
@@ -2948,7 +2955,7 @@ static int lfsck_stop_all(const struct lu_env *env,
        }
        up_read(&ltds->ltd_rw_sem);
 
-       rc = ptlrpc_set_wait(set);
+       rc = ptlrpc_set_wait(env, set);
        ptlrpc_set_destroy(set);
 
        if (rc == 0)
@@ -3019,7 +3026,7 @@ again:
                ltd->ltd_layout_done = 0;
                ltd->ltd_namespace_done = 0;
                ltd->ltd_synced_failures = 0;
-               rc = lfsck_async_request(env, ltd, lr, set,
+               rc = lfsck_async_request(env, ltd->ltd_exp, lr, set,
                                         lfsck_async_interpret, laia,
                                         LFSCK_NOTIFY);
                if (rc != 0) {
@@ -3039,7 +3046,7 @@ again:
                RETURN(rc);
        }
 
-       rc = ptlrpc_set_wait(set);
+       rc = ptlrpc_set_wait(env, set);
        ptlrpc_set_destroy(set);
 
        if (rc == 0)
@@ -3048,7 +3055,7 @@ again:
        if (unlikely(rc == -EINPROGRESS)) {
                retry = true;
                set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC));
+               schedule_timeout(cfs_time_seconds(1));
                set_current_state(TASK_RUNNING);
                if (!signal_pending(current) &&
                    thread_is_running(&lfsck->li_thread))
@@ -3081,7 +3088,6 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
        struct lfsck_bookmark           *bk;
        struct ptlrpc_thread            *thread;
        struct lfsck_component          *com;
-       struct l_wait_info               lwi    = { 0 };
        struct lfsck_thread_args        *lta;
        struct task_struct              *task;
        struct lfsck_tgt_descs          *ltds;
@@ -3316,10 +3322,9 @@ trigger:
                GOTO(out, rc);
        }
 
-       l_wait_event(thread->t_ctl_waitq,
-                    thread_is_running(thread) ||
-                    thread_is_stopped(thread),
-                    &lwi);
+       wait_event_idle(thread->t_ctl_waitq,
+                       thread_is_running(thread) ||
+                       thread_is_stopped(thread));
        if (start == NULL || !(start->ls_flags & LPF_BROADCAST)) {
                lfsck->li_start_unplug = 1;
                wake_up_all(&thread->t_ctl_waitq);
@@ -3342,9 +3347,8 @@ trigger:
 
                        lfsck->li_start_unplug = 1;
                        wake_up_all(&thread->t_ctl_waitq);
-                       l_wait_event(thread->t_ctl_waitq,
-                                    thread_is_stopped(thread),
-                                    &lwi);
+                       wait_event_idle(thread->t_ctl_waitq,
+                                       thread_is_stopped(thread));
                }
        } else {
                lfsck->li_start_unplug = 1;
@@ -3368,7 +3372,6 @@ int lfsck_stop(const struct lu_env *env, struct dt_device *key,
 {
        struct lfsck_instance   *lfsck;
        struct ptlrpc_thread    *thread;
-       struct l_wait_info       lwi    = { 0 };
        int                      rc     = 0;
        int                      rc1    = 0;
        ENTRY;
@@ -3407,6 +3410,9 @@ int lfsck_stop(const struct lu_env *env, struct dt_device *key,
 
        thread_set_flags(thread, SVC_STOPPING);
 
+       LASSERT(lfsck->li_task != NULL);
+       cfs_force_sig(SIGINT, lfsck->li_task);
+
        if (lfsck->li_master) {
                struct lfsck_component *com;
                struct lfsck_assistant_data *lad;
@@ -3415,7 +3421,7 @@ int lfsck_stop(const struct lu_env *env, struct dt_device *key,
                        lad = com->lc_data;
                        spin_lock(&lad->lad_lock);
                        if (lad->lad_task != NULL)
-                               force_sig(SIGINT, lad->lad_task);
+                               cfs_force_sig(SIGINT, lad->lad_task);
                        spin_unlock(&lad->lad_lock);
                }
 
@@ -3423,7 +3429,7 @@ int lfsck_stop(const struct lu_env *env, struct dt_device *key,
                        lad = com->lc_data;
                        spin_lock(&lad->lad_lock);
                        if (lad->lad_task != NULL)
-                               force_sig(SIGINT, lad->lad_task);
+                               cfs_force_sig(SIGINT, lad->lad_task);
                        spin_unlock(&lad->lad_lock);
                }
        }
@@ -3435,9 +3441,8 @@ int lfsck_stop(const struct lu_env *env, struct dt_device *key,
 
        /* It was me set the status as 'stopping' just now, if it is not
         * 'stopping' now, then either stopped, or re-started by race. */
-       l_wait_event(thread->t_ctl_waitq,
-                    !thread_is_stopping(thread),
-                    &lwi);
+       wait_event_idle(thread->t_ctl_waitq,
+                       !thread_is_stopping(thread));
 
        GOTO(put, rc = 0);
 
@@ -3599,17 +3604,16 @@ again:
                            que->lu_mdts_count[i][LS_SCANNING_PHASE2] != 0 ||
                            que->lu_osts_count[i][LS_SCANNING_PHASE1] != 0 ||
                            que->lu_osts_count[i][LS_SCANNING_PHASE2] != 0) {
-                               struct l_wait_info lwi;
-
                                /* If it is required to wait, then sleep
-                                * 3 seconds and try to query again. */
-                               lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(3),
-                                                      NULL,
-                                                      LWI_ON_SIGNAL_NOOP,
-                                                      NULL);
-                               rc = l_wait_event(lfsck->li_thread.t_ctl_waitq,
-                                                 0, &lwi);
-                               if (rc == -ETIMEDOUT)
+                                * 3 seconds and try to query again.
+                                */
+                               unsigned long timeout =
+                                       msecs_to_jiffies(3000) + 1;
+                               while (timeout &&
+                                      !fatal_signal_pending(current))
+                                       timeout = schedule_timeout_killable(
+                                               timeout);
+                               if (timeout == 0)
                                        goto again;
                        }
                }
@@ -3852,8 +3856,6 @@ int lfsck_add_target(const struct lu_env *env, struct dt_device *key,
        ltd->ltd_tgt = tgt;
        ltd->ltd_key = key;
        ltd->ltd_exp = exp;
-       if (for_ost)
-               ltd->ltd_for_ost = 1;
        INIT_LIST_HEAD(&ltd->ltd_orphan_list);
        INIT_LIST_HEAD(&ltd->ltd_layout_list);
        INIT_LIST_HEAD(&ltd->ltd_layout_phase_list);
@@ -3971,9 +3973,6 @@ 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);
        rc = lu_context_key_register(&lfsck_thread_key);
        if (!rc) {