Whamcloud - gitweb
LU-8301 lfsck: handle ROOT fid properly
[fs/lustre-release.git] / lustre / lfsck / lfsck_lib.c
index f6406e0..e3be947 100644 (file)
@@ -32,7 +32,7 @@
 
 #include <linux/kthread.h>
 #include <linux/sched.h>
-#include <libcfs/list.h>
+#include <linux/list.h>
 #include <lu_object.h>
 #include <dt_object.h>
 #include <md_object.h>
@@ -191,8 +191,8 @@ static int __lfsck_add_target(const struct lu_env *env,
        if (index >= ltds->ltd_tgts_bitmap->size) {
                __u32 newsize = max((__u32)ltds->ltd_tgts_bitmap->size,
                                    (__u32)BITS_PER_LONG);
-               cfs_bitmap_t *old_bitmap = ltds->ltd_tgts_bitmap;
-               cfs_bitmap_t *new_bitmap;
+               struct cfs_bitmap *old_bitmap = ltds->ltd_tgts_bitmap;
+               struct cfs_bitmap *new_bitmap;
 
                while (newsize < index + 1)
                        newsize <<= 1;
@@ -531,6 +531,14 @@ int lfsck_find_mdt_idx_by_fid(const struct lu_env *env,
        struct lu_seq_range     *range  = &lfsck_env_info(env)->lti_range;
        int                      rc;
 
+       if (unlikely(fid_seq(fid) == FID_SEQ_LOCAL_FILE)) {
+               /* "ROOT" is always on the MDT0. */
+               if (lu_fid_eq(fid, &lfsck->li_global_root_fid))
+                       return 0;
+
+               return lfsck_dev_idx(lfsck);
+       }
+
        fld_range_set_mdt(range);
        rc = fld_server_lookup(env, ss->ss_server_fld, fid_seq(fid), range);
        if (rc == 0)
@@ -1034,7 +1042,7 @@ static int lfsck_create_lpf(const struct lu_env *env,
                *cfid = bk->lb_lpf_fid;
        }
 
-       child = lfsck_object_find_bottom(env, lfsck, cfid);
+       child = lfsck_object_find_bottom_new(env, lfsck, cfid);
        if (IS_ERR(child))
                GOTO(unlock, rc = PTR_ERR(child));
 
@@ -1738,17 +1746,14 @@ static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
        return 0;
 }
 
-int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
-                   const char *prefix)
+void lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
+                    const char *prefix)
 {
        int flag;
        int i;
        bool newline = (bits != 0 ? false : true);
-       int rc;
 
-       rc = seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
-       if (rc < 0)
-               return rc;
+       seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
 
        for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
                if (flag & bits) {
@@ -1757,54 +1762,43 @@ int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
                                if (bits == 0)
                                        newline = true;
 
-                               rc = seq_printf(m, "%s%c", names[i],
-                                               newline ? '\n' : ',');
-                               if (rc < 0)
-                                       return rc;
+                               seq_printf(m, "%s%c", names[i],
+                                          newline ? '\n' : ',');
                        }
                }
        }
 
        if (!newline)
-               rc = seq_printf(m, "\n");
-
-       return rc;
+               seq_putc(m, '\n');
 }
 
-int lfsck_time_dump(struct seq_file *m, __u64 time, const char *name)
+void lfsck_time_dump(struct seq_file *m, __u64 time, const char *name)
 {
-       int rc;
-
        if (time == 0) {
-               rc = seq_printf(m, "%s_time: N/A\n", name);
-               if (rc == 0)
-                       rc = seq_printf(m, "time_since_%s: N/A\n", name);
-
-               return rc;
+               seq_printf(m, "%s_time: N/A\n", name);
+               seq_printf(m, "time_since_%s: N/A\n", name);
+       } else {
+               seq_printf(m, "%s_time: %llu\n", name, time);
+               seq_printf(m, "time_since_%s: %llu seconds\n",
+                          name, cfs_time_current_sec() - time);
        }
-
-       rc = seq_printf(m, "%s_time: "LPU64"\n", name, time);
-       if (rc == 0)
-               rc = seq_printf(m, "time_since_%s: "LPU64" seconds\n",
-                               name, cfs_time_current_sec() - time);
-
-       return rc;
 }
 
-int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
-                  const char *prefix)
+void lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
+                   const char *prefix)
 {
        if (fid_is_zero(&pos->lp_dir_parent)) {
-               if (pos->lp_oit_cookie == 0)
-                       return seq_printf(m, "%s: N/A, N/A, N/A\n", prefix);
-
-               return seq_printf(m, "%s: "LPU64", N/A, N/A\n",
-                                 prefix, pos->lp_oit_cookie);
+               if (pos->lp_oit_cookie == 0) {
+                       seq_printf(m, "%s: N/A, N/A, N/A\n", prefix);
+                       return;
+               }
+               seq_printf(m, "%s: %llu, N/A, N/A\n",
+                          prefix, pos->lp_oit_cookie);
+       } else {
+               seq_printf(m, "%s: %llu, "DFID", %#llx\n",
+                          prefix, pos->lp_oit_cookie,
+                          PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
        }
-
-       return seq_printf(m, "%s: "LPU64", "DFID", "LPX64"\n",
-                         prefix, pos->lp_oit_cookie,
-                         PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
 }
 
 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
@@ -2667,7 +2661,7 @@ int lfsck_get_speed(struct seq_file *m, struct dt_device *key)
 }
 EXPORT_SYMBOL(lfsck_get_speed);
 
-int lfsck_set_speed(struct dt_device *key, int val)
+int lfsck_set_speed(struct dt_device *key, __u32 val)
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -2772,7 +2766,7 @@ int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
        if (likely(lfsck != NULL)) {
                com = lfsck_component_find(lfsck, type);
                if (likely(com != NULL)) {
-                       rc = com->lc_ops->lfsck_dump(&env, com, m);
+                       com->lc_ops->lfsck_dump(&env, com, m);
                        lfsck_component_put(&env, com);
                } else {
                        rc = -ENOTSUPP;