Whamcloud - gitweb
LU-3336 lfsck: use rbtree to record OST-object accessing
[fs/lustre-release.git] / lustre / lfsck / lfsck_lib.c
index dc4616e..3fa1f93 100644 (file)
@@ -51,6 +51,7 @@ static void lfsck_key_fini(const struct lu_context *ctx,
        struct lfsck_thread_info *info = data;
 
        lu_buf_free(&info->lti_linkea_buf);
+       lu_buf_free(&info->lti_big_buf);
        OBD_FREE_PTR(info);
 }
 
@@ -90,6 +91,7 @@ const char *lfsck_param_names[] = {
        NULL,
        "failout",
        "dryrun",
+       "all_targets",
        NULL
 };
 
@@ -330,9 +332,6 @@ void lfsck_instance_cleanup(const struct lu_env *env,
        LASSERT(list_empty(&lfsck->li_link));
        LASSERT(thread_is_init(thread) || thread_is_stopped(thread));
 
-       lfsck_tgt_descs_fini(&lfsck->li_ost_descs);
-       lfsck_tgt_descs_fini(&lfsck->li_mdt_descs);
-
        if (lfsck->li_obj_oit != NULL) {
                lu_object_put_nocache(env, &lfsck->li_obj_oit->do_lu);
                lfsck->li_obj_oit = NULL;
@@ -363,6 +362,9 @@ void lfsck_instance_cleanup(const struct lu_env *env,
                lfsck_component_cleanup(env, com);
        }
 
+       lfsck_tgt_descs_fini(&lfsck->li_ost_descs);
+       lfsck_tgt_descs_fini(&lfsck->li_mdt_descs);
+
        if (lfsck->li_bookmark_obj != NULL) {
                lu_object_put_nocache(env, &lfsck->li_bookmark_obj->do_lu);
                lfsck->li_bookmark_obj = NULL;
@@ -681,7 +683,8 @@ static int lfsck_needs_scan_dir(const struct lu_env *env,
 }
 
 struct lfsck_thread_args *lfsck_thread_args_init(struct lfsck_instance *lfsck,
-                                                struct lfsck_component *com)
+                                                struct lfsck_component *com,
+                                                struct lfsck_start_param *lsp)
 {
        struct lfsck_thread_args *lta;
        int                       rc;
@@ -700,6 +703,8 @@ struct lfsck_thread_args *lfsck_thread_args_init(struct lfsck_instance *lfsck,
        if (com != NULL)
                lta->lta_com = lfsck_component_get(com);
 
+       lta->lta_lsp = lsp;
+
        return lta;
 }
 
@@ -747,7 +752,8 @@ int lfsck_checkpoint(const struct lu_env *env, struct lfsck_instance *lfsck)
        return rc1 != 0 ? rc1 : rc;
 }
 
-int lfsck_prep(const struct lu_env *env, struct lfsck_instance *lfsck)
+int lfsck_prep(const struct lu_env *env, struct lfsck_instance *lfsck,
+              struct lfsck_start_param *lsp)
 {
        struct dt_object       *obj     = NULL;
        struct lfsck_component *com;
@@ -768,7 +774,7 @@ int lfsck_prep(const struct lu_env *env, struct lfsck_instance *lfsck)
                if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
                        com->lc_journal = 0;
 
-               rc = com->lc_ops->lfsck_prep(env, com);
+               rc = com->lc_ops->lfsck_prep(env, com, lsp);
                if (rc != 0)
                        GOTO(out, rc);
 
@@ -1090,6 +1096,7 @@ int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
 
        laia = ptlrpc_req_async_args(req);
        *laia = *(struct lfsck_async_interpret_args *)args;
+       lfsck_component_get(laia->laia_com);
        req->rq_interpret_reply = interpreter;
        ptlrpc_set_add_req(set, req);
 
@@ -1283,20 +1290,27 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
        if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
                rc = -EALREADY;
                while (start->ls_active != 0) {
-                       if (type & start->ls_active) {
+                       if (!(type & start->ls_active)) {
+                               type <<= 1;
+                               continue;
+                       }
+
+                       com = __lfsck_component_find(lfsck, type,
+                                                    &lfsck->li_list_scan);
+                       if (com == NULL)
                                com = __lfsck_component_find(lfsck, type,
-                                                       &lfsck->li_list_scan);
-                               if (com == NULL)
-                                       com = __lfsck_component_find(lfsck,
-                                               type,
                                                &lfsck->li_list_double_scan);
-                               if (com == NULL) {
-                                       rc = -EBUSY;
+                       if (com == NULL) {
+                               rc = -EOPNOTSUPP;
+                               break;
+                       }
+
+                       if (com->lc_ops->lfsck_join != NULL) {
+                               rc = com->lc_ops->lfsck_join( env, com, lsp);
+                               if (rc != 0 && rc != -EALREADY)
                                        break;
-                               } else {
-                                       start->ls_active &= ~type;
-                               }
                        }
+                       start->ls_active &= ~type;
                        type <<= 1;
                }
                spin_unlock(&lfsck->li_lock);
@@ -1359,6 +1373,16 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
                }
        }
 
+       if (bk->lb_param & LPF_ALL_MDT &&
+           !(start->ls_flags & LPF_ALL_MDT)) {
+               bk->lb_param &= ~LPF_ALL_MDT;
+               dirty = true;
+       } else if (!(bk->lb_param & LPF_ALL_MDT) &&
+                  start->ls_flags & LPF_ALL_MDT) {
+               bk->lb_param |= LPF_ALL_MDT;
+               dirty = true;
+       }
+
        if (dirty) {
                rc = lfsck_bookmark_store(env, lfsck);
                if (rc != 0)
@@ -1434,7 +1458,7 @@ trigger:
 
        lfsck->li_args_oit = (flags << DT_OTABLE_IT_FLAGS_SHIFT) | valid;
        thread_set_flags(thread, 0);
-       lta = lfsck_thread_args_init(lfsck, NULL);
+       lta = lfsck_thread_args_init(lfsck, NULL, lsp);
        if (IS_ERR(lta))
                GOTO(out, rc = PTR_ERR(lta));
 
@@ -1482,10 +1506,13 @@ int lfsck_stop(const struct lu_env *env, struct dt_device *key,
                GOTO(out, rc = -EALREADY);
        }
 
-       if (stop != NULL)
+       if (stop != NULL) {
                lfsck->li_status = stop->ls_status;
-       else
+               lfsck->li_flags = stop->ls_flags;
+       } else {
                lfsck->li_status = LS_STOPPED;
+               lfsck->li_flags = 0;
+       }
 
        thread_set_flags(thread, SVC_STOPPING);
        spin_unlock(&lfsck->li_lock);
@@ -1517,6 +1544,7 @@ int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
        case LE_STOP:
        case LE_PHASE1_DONE:
        case LE_PHASE2_DONE:
+       case LE_FID_ACCESSED:
                break;
        default:
                RETURN(-EOPNOTSUPP);
@@ -1567,8 +1595,8 @@ int lfsck_query(const struct lu_env *env, struct dt_device *key,
 EXPORT_SYMBOL(lfsck_query);
 
 int lfsck_register(const struct lu_env *env, struct dt_device *key,
-                  struct dt_device *next, lfsck_out_notify notify,
-                  void *notify_data, bool master)
+                  struct dt_device *next, struct obd_device *obd,
+                  lfsck_out_notify notify, void *notify_data, bool master)
 {
        struct lfsck_instance   *lfsck;
        struct dt_object        *root  = NULL;
@@ -1599,6 +1627,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
        lfsck->li_out_notify_data = notify_data;
        lfsck->li_next = next;
        lfsck->li_bottom = key;
+       lfsck->li_obd = obd;
 
        rc = lfsck_tgt_descs_init(&lfsck->li_ost_descs);
        if (rc != 0)
@@ -1791,6 +1820,7 @@ void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
        spin_lock(&ltds->ltd_lock);
        ltd->ltd_dead = 1;
        if (!list_empty(&ltd->ltd_layout_list)) {
+               list_del_init(&ltd->ltd_layout_phase_list);
                list_del_init(&ltd->ltd_layout_list);
                stop = true;
        } else {