Whamcloud - gitweb
LU-3319 procfs: move mdd/ofd proc handling to seq_files
[fs/lustre-release.git] / lustre / lfsck / lfsck_lib.c
index 1f85e1a..f6f1cce 100644 (file)
@@ -900,21 +900,15 @@ static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
        return 0;
 }
 
-int lfsck_bits_dump(char **buf, int *len, int bits, const char *names[],
+int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
                    const char *prefix)
 {
-       int save = *len;
        int flag;
-       int rc;
        int i;
        bool newline = (bits != 0 ? false : true);
 
-       rc = snprintf(*buf, *len, "%s:%c", prefix, newline ? '\n' : ' ');
-       if (rc <= 0)
-               return -ENOSPC;
+       seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
 
-       *buf += rc;
-       *len -= rc;
        for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
                if (flag & bits) {
                        bits &= ~flag;
@@ -922,69 +916,43 @@ int lfsck_bits_dump(char **buf, int *len, int bits, const char *names[],
                                if (bits == 0)
                                        newline = true;
 
-                               rc = snprintf(*buf, *len, "%s%c", names[i],
-                                             newline ? '\n' : ',');
-                               if (rc <= 0)
-                                       return -ENOSPC;
-
-                               *buf += rc;
-                               *len -= rc;
+                               seq_printf(m, "%s%c", names[i],
+                                          newline ? '\n' : ',');
                        }
                }
        }
 
-       if (!newline) {
-               rc = snprintf(*buf, *len, "\n");
-               if (rc <= 0)
-                       return -ENOSPC;
-
-               *buf += rc;
-               *len -= rc;
-       }
-
-       return save - *len;
+       if (!newline)
+               seq_printf(m, "\n");
+       return 0;
 }
 
-int lfsck_time_dump(char **buf, int *len, __u64 time, const char *prefix)
+int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix)
 {
-       int rc;
-
        if (time != 0)
-               rc = snprintf(*buf, *len, "%s: "LPU64" seconds\n", prefix,
-                             cfs_time_current_sec() - time);
+               seq_printf(m, "%s: "LPU64" seconds\n", prefix,
+                         cfs_time_current_sec() - time);
        else
-               rc = snprintf(*buf, *len, "%s: N/A\n", prefix);
-       if (rc <= 0)
-               return -ENOSPC;
-
-       *buf += rc;
-       *len -= rc;
-       return rc;
+               seq_printf(m, "%s: N/A\n", prefix);
+       return 0;
 }
 
-int lfsck_pos_dump(char **buf, int *len, struct lfsck_position *pos,
+int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
                   const char *prefix)
 {
-       int rc;
-
        if (fid_is_zero(&pos->lp_dir_parent)) {
                if (pos->lp_oit_cookie == 0)
-                       rc = snprintf(*buf, *len, "%s: N/A, N/A, N/A\n",
-                                     prefix);
+                       seq_printf(m, "%s: N/A, N/A, N/A\n",
+                                  prefix);
                else
-                       rc = snprintf(*buf, *len, "%s: "LPU64", N/A, N/A\n",
-                                     prefix, pos->lp_oit_cookie);
+                       seq_printf(m, "%s: "LPU64", N/A, N/A\n",
+                                  prefix, pos->lp_oit_cookie);
        } else {
-               rc = snprintf(*buf, *len, "%s: "LPU64", "DFID", "LPU64"\n",
-                             prefix, pos->lp_oit_cookie,
-                             PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
+               seq_printf(m, "%s: "LPU64", "DFID", "LPU64"\n",
+                          prefix, pos->lp_oit_cookie,
+                          PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
        }
-       if (rc <= 0)
-               return -ENOSPC;
-
-       *buf += rc;
-       *len -= rc;
-       return rc;
+       return 0;
 }
 
 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
@@ -1116,8 +1084,8 @@ static int lfsck_needs_scan_dir(const struct lu_env *env,
                        return 1;
                }
 
-               /* .lustre doesn't contain "real" user objects, no need lfsck */
-               if (fid_is_dot_lustre(lfsck_dto2fid(obj))) {
+               /* No need to check .lustre and its children. */
+               if (fid_seq_is_dot_lustre(fid_seq(lfsck_dto2fid(obj)))) {
                        if (depth > 0)
                                lfsck_object_put(env, obj);
                        return 0;
@@ -1167,10 +1135,16 @@ static int lfsck_needs_scan_dir(const struct lu_env *env,
                        return 0;
                }
 
-               /* Currently, only client visible directory can be remote. */
                if (dt_object_remote(obj)) {
+                       /* .lustre/lost+found/MDTxxx can be remote directory. */
+                       if (fid_seq_is_dot_lustre(fid_seq(lfsck_dto2fid(obj))))
+                               rc = 0;
+                       else
+                               /* Other remote directory should be client
+                                * visible and need to be checked. */
+                               rc = 1;
                        lfsck_object_put(env, obj);
-                       return 1;
+                       return rc;
                }
 
                depth++;
@@ -1664,7 +1638,7 @@ int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
 
 /* external interfaces */
 
-int lfsck_get_speed(struct dt_device *key, void *buf, int len)
+int lfsck_get_speed(struct seq_file *m, struct dt_device *key)
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -1677,8 +1651,7 @@ int lfsck_get_speed(struct dt_device *key, void *buf, int len)
 
        lfsck = lfsck_instance_find(key, true, false);
        if (likely(lfsck != NULL)) {
-               rc = snprintf(buf, len, "%u\n",
-                             lfsck->li_bookmark_ram.lb_speed_limit);
+               seq_printf(m, "%u\n", lfsck->li_bookmark_ram.lb_speed_limit);
                lfsck_instance_put(&env, lfsck);
        } else {
                rc = -ENXIO;
@@ -1718,7 +1691,7 @@ int lfsck_set_speed(struct dt_device *key, int val)
 }
 EXPORT_SYMBOL(lfsck_set_speed);
 
-int lfsck_get_windows(struct dt_device *key, void *buf, int len)
+int lfsck_get_windows(struct seq_file *m, struct dt_device *key)
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -1731,8 +1704,7 @@ int lfsck_get_windows(struct dt_device *key, void *buf, int len)
 
        lfsck = lfsck_instance_find(key, true, false);
        if (likely(lfsck != NULL)) {
-               rc = snprintf(buf, len, "%u\n",
-                             lfsck->li_bookmark_ram.lb_async_windows);
+               seq_printf(m, "%u\n", lfsck->li_bookmark_ram.lb_async_windows);
                lfsck_instance_put(&env, lfsck);
        } else {
                rc = -ENXIO;
@@ -1782,7 +1754,7 @@ int lfsck_set_windows(struct dt_device *key, int val)
 }
 EXPORT_SYMBOL(lfsck_set_windows);
 
-int lfsck_dump(struct dt_device *key, void *buf, int len, enum lfsck_type type)
+int lfsck_dump(struct seq_file *m, struct dt_device *key, enum lfsck_type type)
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -1798,7 +1770,7 @@ int lfsck_dump(struct dt_device *key, void *buf, int len, 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, buf, len);
+                       rc = com->lc_ops->lfsck_dump(&env, com, m);
                        lfsck_component_put(&env, com);
                } else {
                        rc = -ENOTSUPP;
@@ -2014,7 +1986,8 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
        struct lfsck_component          *com;
        struct l_wait_info               lwi    = { 0 };
        struct lfsck_thread_args        *lta;
-       long                             rc     = 0;
+       struct task_struct              *task;
+       int                              rc     = 0;
        __u16                            valid  = 0;
        __u16                            flags  = 0;
        __u16                            type   = 1;
@@ -2040,6 +2013,11 @@ int lfsck_start(const struct lu_env *env, struct dt_device *key,
        spin_lock(&lfsck->li_lock);
        if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
                rc = -EALREADY;
+               if (unlikely(start == NULL)) {
+                       spin_unlock(&lfsck->li_lock);
+                       GOTO(out, rc);
+               }
+
                while (start->ls_active != 0) {
                        if (!(type & start->ls_active)) {
                                type <<= 1;
@@ -2184,9 +2162,10 @@ trigger:
                GOTO(out, rc = PTR_ERR(lta));
 
        __lfsck_set_speed(lfsck, bk->lb_speed_limit);
-       rc = PTR_ERR(kthread_run(lfsck_master_engine, lta, "lfsck"));
-       if (IS_ERR_VALUE(rc)) {
-               CERROR("%s: cannot start LFSCK thread: rc = %ld\n",
+       task = kthread_run(lfsck_master_engine, lta, "lfsck");
+       if (IS_ERR(task)) {
+               rc = PTR_ERR(task);
+               CERROR("%s: cannot start LFSCK thread: rc = %d\n",
                       lfsck_lfsck2name(lfsck), rc);
                lfsck_thread_args_fini(lta);