Whamcloud - gitweb
LU-3963 libcfs: convert llite/lmv/lod/lov cfs_atomic primitive
[fs/lustre-release.git] / lustre / lfsck / lfsck_lib.c
index 4f05c19..3b1fe0c 100644 (file)
@@ -92,6 +92,8 @@ const char *lfsck_param_names[] = {
        "failout",
        "dryrun",
        "all_targets",
+       "broadcast",
+       "orphan",
        NULL
 };
 
@@ -395,7 +397,8 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
                GOTO(stop, rc);
 
        /* 5a. update bookmark */
-       rc = dt_declare_record_write(env, bk_obj, len, 0, th);
+       rc = dt_declare_record_write(env, bk_obj,
+                                    lfsck_buf_get(env, bk, len), 0, th);
        if (rc != 0)
                GOTO(stop, rc);
 
@@ -584,7 +587,8 @@ static int lfsck_create_lpf_remote(const struct lu_env *env,
                GOTO(stop, rc);
 
        /* 8a. update bookmark locally. */
-       rc = dt_declare_record_write(env, bk_obj, len, 0, th);
+       rc = dt_declare_record_write(env, bk_obj,
+                                    lfsck_buf_get(env, bk, len), 0, th);
        if (rc != 0)
                GOTO(stop, rc);
 
@@ -656,7 +660,7 @@ int lfsck_create_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
 
                ltd = lfsck_tgt_get(&lfsck->li_mdt_descs, 0);
                if (unlikely(ltd == NULL))
-                       RETURN(-ENODEV);
+                       RETURN(-ENXIO);
 
                parent = lfsck_object_find_by_dev(env, ltd->ltd_tgt,
                                                  &LU_LPF_FID);
@@ -746,7 +750,7 @@ static int lfsck_fid_init(struct lfsck_instance *lfsck)
 
        ss = lu_site2seq(lfsck->li_bottom->dd_lu_dev.ld_site);
        if (unlikely(ss == NULL))
-               RETURN(-ENODEV);
+               RETURN(-ENXIO);
 
        OBD_ALLOC_PTR(lfsck->li_seq);
        if (lfsck->li_seq == NULL)
@@ -902,8 +906,9 @@ int lfsck_bits_dump(char **buf, int *len, int bits, const char *names[],
        int flag;
        int rc;
        int i;
+       bool newline = (bits != 0 ? false : true);
 
-       rc = snprintf(*buf, *len, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
+       rc = snprintf(*buf, *len, "%s:%c", prefix, newline ? '\n' : ' ');
        if (rc <= 0)
                return -ENOSPC;
 
@@ -913,8 +918,11 @@ int lfsck_bits_dump(char **buf, int *len, int bits, const char *names[],
                if (flag & bits) {
                        bits &= ~flag;
                        if (names[i] != NULL) {
+                               if (bits == 0)
+                                       newline = true;
+
                                rc = snprintf(*buf, *len, "%s%c", names[i],
-                                             bits != 0 ? ',' : '\n');
+                                             newline ? '\n' : ',');
                                if (rc <= 0)
                                        return -ENOSPC;
 
@@ -923,6 +931,16 @@ int lfsck_bits_dump(char **buf, int *len, int bits, const char *names[],
                        }
                }
        }
+
+       if (!newline) {
+               rc = snprintf(*buf, *len, "\n");
+               if (rc <= 0)
+                       return -ENOSPC;
+
+               *buf += rc;
+               *len -= rc;
+       }
+
        return save - *len;
 }
 
@@ -1442,6 +1460,7 @@ static void lfsck_interpret(const struct lu_env *env,
        struct lfsck_async_interpret_args *laia = args;
        struct lfsck_component            *com;
 
+       LASSERT(laia->laia_com == NULL);
        LASSERT(laia->laia_shared);
 
        spin_lock(&lfsck->li_lock);
@@ -1469,8 +1488,7 @@ int lfsck_double_scan(const struct lu_env *env, struct lfsck_instance *lfsck)
        int                     rc  = 0;
        int                     rc1 = 0;
 
-       cfs_list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
-                                    lc_link) {
+       list_for_each_entry(com, &lfsck->li_list_double_scan, lc_link) {
                if (lfsck->li_bookmark_ram.lb_param & LPF_DRYRUN)
                        com->lc_journal = 0;
 
@@ -1483,6 +1501,17 @@ int lfsck_double_scan(const struct lu_env *env, struct lfsck_instance *lfsck)
                     atomic_read(&lfsck->li_double_scan_count) == 0,
                     &lwi);
 
+       if (lfsck->li_status != LS_PAUSED &&
+           lfsck->li_status != LS_CO_PAUSED) {
+               list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
+                                        lc_link) {
+                       spin_lock(&lfsck->li_lock);
+                       list_del_init(&com->lc_link);
+                       list_add_tail(&com->lc_link, &lfsck->li_list_idle);
+                       spin_unlock(&lfsck->li_lock);
+               }
+       }
+
        return rc1 != 0 ? rc1 : rc;
 }
 
@@ -1537,12 +1566,23 @@ void lfsck_quit(const struct lu_env *env, struct lfsck_instance *lfsck)
                                 lc_link) {
                if (com->lc_ops->lfsck_quit != NULL)
                        com->lc_ops->lfsck_quit(env, com);
+
+               spin_lock(&lfsck->li_lock);
+               list_del_init(&com->lc_link);
+               list_del_init(&com->lc_link_dir);
+               list_add_tail(&com->lc_link, &lfsck->li_list_idle);
+               spin_unlock(&lfsck->li_lock);
        }
 
        list_for_each_entry_safe(com, next, &lfsck->li_list_double_scan,
                                 lc_link) {
                if (com->lc_ops->lfsck_quit != NULL)
                        com->lc_ops->lfsck_quit(env, com);
+
+               spin_lock(&lfsck->li_lock);
+               list_del_init(&com->lc_link);
+               list_add_tail(&com->lc_link, &lfsck->li_list_idle);
+               spin_unlock(&lfsck->li_lock);
        }
 }
 
@@ -1635,7 +1675,7 @@ int lfsck_get_speed(struct dt_device *key, void *buf, int len)
                              lfsck->li_bookmark_ram.lb_speed_limit);
                lfsck_instance_put(&env, lfsck);
        } else {
-               rc = -ENODEV;
+               rc = -ENXIO;
        }
 
        lu_env_fini(&env);
@@ -1663,7 +1703,7 @@ int lfsck_set_speed(struct dt_device *key, int val)
                mutex_unlock(&lfsck->li_mutex);
                lfsck_instance_put(&env, lfsck);
        } else {
-               rc = -ENODEV;
+               rc = -ENXIO;
        }
 
        lu_env_fini(&env);
@@ -1689,7 +1729,7 @@ int lfsck_get_windows(struct dt_device *key, void *buf, int len)
                              lfsck->li_bookmark_ram.lb_async_windows);
                lfsck_instance_put(&env, lfsck);
        } else {
-               rc = -ENODEV;
+               rc = -ENXIO;
        }
 
        lu_env_fini(&env);
@@ -1727,7 +1767,7 @@ int lfsck_set_windows(struct dt_device *key, int val)
                }
                lfsck_instance_put(&env, lfsck);
        } else {
-               rc = -ENODEV;
+               rc = -ENXIO;
        }
 
        lu_env_fini(&env);
@@ -1760,7 +1800,7 @@ int lfsck_dump(struct dt_device *key, void *buf, int len, enum lfsck_type type)
 
                lfsck_instance_put(&env, lfsck);
        } else {
-               rc = -ENODEV;
+               rc = -ENXIO;
        }
 
        lu_env_fini(&env);
@@ -1977,7 +2017,7 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
 
        lfsck = lfsck_instance_find(key, true, false);
        if (unlikely(lfsck == NULL))
-               RETURN(-ENODEV);
+               RETURN(-ENXIO);
 
        /* System is not ready, try again later. */
        if (unlikely(lfsck->li_namespace == NULL))
@@ -2253,7 +2293,7 @@ int lfsck_stop(const struct lu_env *env, struct dt_device *key,
 
        lfsck = lfsck_instance_find(key, true, false);
        if (unlikely(lfsck == NULL))
-               RETURN(-ENODEV);
+               RETURN(-ENXIO);
 
        thread = &lfsck->li_thread;
        /* release lfsck::li_mutex to avoid deadlock. */
@@ -2339,13 +2379,14 @@ int lfsck_in_notify(const struct lu_env *env, struct dt_device *key,
        case LE_PHASE2_DONE:
        case LE_FID_ACCESSED:
        case LE_PEER_EXIT:
-       case LE_CONDITIONAL_DESTROY: {
+       case LE_CONDITIONAL_DESTROY:
+       case LE_PAIRS_VERIFY: {
                struct lfsck_instance  *lfsck;
                struct lfsck_component *com;
 
                lfsck = lfsck_instance_find(key, true, false);
                if (unlikely(lfsck == NULL))
-                       RETURN(-ENODEV);
+                       RETURN(-ENXIO);
 
                com = lfsck_component_find(lfsck, lr->lr_active);
                if (likely(com != NULL)) {
@@ -2374,7 +2415,7 @@ int lfsck_query(const struct lu_env *env, struct dt_device *key,
 
        lfsck = lfsck_instance_find(key, true, false);
        if (unlikely(lfsck == NULL))
-               RETURN(-ENODEV);
+               RETURN(-ENXIO);
 
        com = lfsck_component_find(lfsck, lr->lr_active);
        if (likely(com != NULL)) {
@@ -2394,7 +2435,7 @@ int lfsck_register_namespace(const struct lu_env *env, struct dt_device *key,
                             struct ldlm_namespace *ns)
 {
        struct lfsck_instance  *lfsck;
-       int                     rc      = -ENODEV;
+       int                     rc      = -ENXIO;
 
        lfsck = lfsck_instance_find(key, true, false);
        if (likely(lfsck != NULL)) {