Whamcloud - gitweb
LU-3569 ofd: packing ost_idx in IDIF
[fs/lustre-release.git] / lustre / lfsck / lfsck_lib.c
index e459c44..a4c963c 100644 (file)
  * Author: Fan, Yong <fan.yong@intel.com>
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
 #define DEBUG_SUBSYSTEM S_LFSCK
 
 #include <libcfs/list.h>
 #include <lu_object.h>
 #include <dt_object.h>
+#include <md_object.h>
+#include <lustre_fld.h>
 #include <lustre_lib.h>
 #include <lustre_net.h>
 #include <lustre_lfsck.h>
@@ -86,11 +85,6 @@ const char *lfsck_param_names[] = {
        NULL
 };
 
-static inline mdsno_t lfsck_dev_idx(struct dt_device *dev)
-{
-       return dev->dd_lu_dev.ld_site->ld_seq_site->ss_node_id;
-}
-
 static inline void lfsck_component_get(struct lfsck_component *com)
 {
        atomic_inc(&com->lc_ref);
@@ -101,7 +95,7 @@ static inline void lfsck_component_put(const struct lu_env *env,
 {
        if (atomic_dec_and_test(&com->lc_ref)) {
                if (com->lc_obj != NULL)
-                       lu_object_put(env, &com->lc_obj->do_lu);
+                       lu_object_put_nocache(env, &com->lc_obj->do_lu);
                if (com->lc_file_ram != NULL)
                        OBD_FREE(com->lc_file_ram, com->lc_file_size);
                if (com->lc_file_disk != NULL)
@@ -168,7 +162,7 @@ static void lfsck_instance_cleanup(const struct lu_env *env,
        LASSERT(thread_is_init(thread) || thread_is_stopped(thread));
 
        if (lfsck->li_obj_oit != NULL) {
-               lu_object_put(env, &lfsck->li_obj_oit->do_lu);
+               lu_object_put_nocache(env, &lfsck->li_obj_oit->do_lu);
                lfsck->li_obj_oit = NULL;
        }
 
@@ -198,7 +192,7 @@ static void lfsck_instance_cleanup(const struct lu_env *env,
        }
 
        if (lfsck->li_bookmark_obj != NULL) {
-               lu_object_put(env, &lfsck->li_bookmark_obj->do_lu);
+               lu_object_put_nocache(env, &lfsck->li_bookmark_obj->do_lu);
                lfsck->li_bookmark_obj = NULL;
        }
 
@@ -207,11 +201,6 @@ static void lfsck_instance_cleanup(const struct lu_env *env,
                lfsck->li_los = NULL;
        }
 
-       if (lfsck->li_local_root != NULL) {
-               lu_object_put(env, &lfsck->li_local_root->do_lu);
-               lfsck->li_local_root = NULL;
-       }
-
        OBD_FREE_PTR(lfsck);
 }
 
@@ -373,12 +362,12 @@ static void __lfsck_set_speed(struct lfsck_instance *lfsck, __u32 limit)
 {
        lfsck->li_bookmark_ram.lb_speed_limit = limit;
        if (limit != LFSCK_SPEED_NO_LIMIT) {
-               if (limit > CFS_HZ) {
-                       lfsck->li_sleep_rate = limit / CFS_HZ;
+               if (limit > HZ) {
+                       lfsck->li_sleep_rate = limit / HZ;
                        lfsck->li_sleep_jif = 1;
                } else {
                        lfsck->li_sleep_rate = 1;
-                       lfsck->li_sleep_jif = CFS_HZ / limit;
+                       lfsck->li_sleep_jif = HZ / limit;
                }
        } else {
                lfsck->li_sleep_jif = 0;
@@ -482,8 +471,7 @@ static int lfsck_needs_scan_dir(const struct lu_env *env,
                if (rc != 0)
                        return rc;
 
-               if (unlikely(lu_fid_eq(fid,
-                                      lfsck_dto2fid(lfsck->li_local_root))))
+               if (unlikely(lu_fid_eq(fid, &lfsck->li_local_root_fid)))
                        return 0;
 
                obj = lfsck_object_find(env, lfsck, fid);
@@ -870,7 +858,7 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
        struct lfsck_component *com;
        struct l_wait_info      lwi    = { 0 };
        bool                    dirty  = false;
-       int                     rc     = 0;
+       long                    rc     = 0;
        __u16                   valid  = 0;
        __u16                   flags  = 0;
        ENTRY;
@@ -929,6 +917,10 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
        }
 
        if (start->ls_valid & LSV_DRYRUN) {
+               valid |= DOIV_DRYRUN;
+               if (start->ls_flags & LPF_DRYRUN)
+                       flags |= DOIF_DRYRUN;
+
                if ((start->ls_flags & LPF_DRYRUN) &&
                    !(bk->lb_param & LPF_DRYRUN)) {
                        bk->lb_param |= LPF_DRYRUN;
@@ -1001,8 +993,11 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
 
 trigger:
        lfsck->li_args_dir = LUDA_64BITHASH | LUDA_VERIFY;
-       if (bk->lb_param & LPF_DRYRUN)
+       if (bk->lb_param & LPF_DRYRUN) {
                lfsck->li_args_dir |= LUDA_VERIFY_DRYRUN;
+               valid |= DOIV_DRYRUN;
+               flags |= DOIF_DRYRUN;
+       }
 
        if (bk->lb_param & LPF_FAILOUT) {
                valid |= DOIV_ERROR_HANDLE;
@@ -1014,18 +1009,19 @@ trigger:
 
        lfsck->li_args_oit = (flags << DT_OTABLE_IT_FLAGS_SHIFT) | valid;
        thread_set_flags(thread, 0);
-       if (lfsck->li_master)
-               rc = PTR_ERR(kthread_run(lfsck_master_engine, lfsck, "lfsck"));
-       if (rc < 0)
-               CERROR("%s: cannot start LFSCK thread, rc = %d\n",
+       rc = PTR_ERR(kthread_run(lfsck_master_engine, lfsck, "lfsck"));
+       if (IS_ERR_VALUE(rc)) {
+               CERROR("%s: cannot start LFSCK thread, rc = %ld\n",
                       lfsck_lfsck2name(lfsck), rc);
-       else
+       } else {
+               rc = 0;
                l_wait_event(thread->t_ctl_waitq,
                             thread_is_running(thread) ||
                             thread_is_stopped(thread),
                             &lwi);
+       }
 
-       GOTO(out, rc = 0);
+       GOTO(out, rc);
 
 out:
        mutex_unlock(&lfsck->li_mutex);
@@ -1061,7 +1057,7 @@ int lfsck_stop(const struct lu_env *env, struct dt_device *key, bool pause)
        thread_set_flags(thread, SVC_STOPPING);
        spin_unlock(&lfsck->li_lock);
 
-       cfs_waitq_broadcast(&thread->t_ctl_waitq);
+       wake_up_all(&thread->t_ctl_waitq);
        l_wait_event(thread->t_ctl_waitq,
                     thread_is_stopped(thread),
                     &lwi);
@@ -1076,7 +1072,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
                   struct dt_device *next, bool master)
 {
        struct lfsck_instance   *lfsck;
-       struct dt_object        *root;
+       struct dt_object        *root  = NULL;
        struct dt_object        *obj;
        struct lu_fid           *fid   = &lfsck_env_info(env)->lti_fid;
        int                      rc;
@@ -1098,7 +1094,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
        CFS_INIT_LIST_HEAD(&lfsck->li_list_double_scan);
        CFS_INIT_LIST_HEAD(&lfsck->li_list_idle);
        atomic_set(&lfsck->li_ref, 1);
-       cfs_waitq_init(&lfsck->li_thread.t_ctl_waitq);
+       init_waitqueue_head(&lfsck->li_thread.t_ctl_waitq);
        lfsck->li_next = next;
        lfsck->li_bottom = key;
 
@@ -1117,7 +1113,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
        if (IS_ERR(root))
                GOTO(out, rc = PTR_ERR(root));
 
-       lfsck->li_local_root = root;
+       lfsck->li_local_root_fid = *fid;
         dt_try_as_dir(env, root);
        if (master) {
                lfsck->li_master = 1;
@@ -1161,6 +1157,8 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
 add:
        rc = lfsck_instance_add(lfsck);
 out:
+       if (root != NULL && !IS_ERR(root))
+               lu_object_put(env, &root->do_lu);
        if (rc != 0)
                lfsck_instance_cleanup(env, lfsck);
        return rc;