Whamcloud - gitweb
LU-3319 procfs: move mdd/ofd proc handling to seq_files
[fs/lustre-release.git] / lustre / lfsck / lfsck_lib.c
index db73616..f6f1cce 100644 (file)
@@ -900,21 +900,15 @@ static inline int lfsck_instance_add(struct lfsck_instance *lfsck)
        return 0;
 }
 
        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)
 {
                    const char *prefix)
 {
-       int save = *len;
        int flag;
        int flag;
-       int rc;
        int i;
        bool newline = (bits != 0 ? false : true);
 
        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;
        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;
 
                                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)
        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
        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)
 {
                   const char *prefix)
 {
-       int rc;
-
        if (fid_is_zero(&pos->lp_dir_parent)) {
                if (pos->lp_oit_cookie == 0)
        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
                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 {
        } 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,
 }
 
 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
@@ -1670,7 +1638,7 @@ int lfsck_async_request(const struct lu_env *env, struct obd_export *exp,
 
 /* external interfaces */
 
 
 /* 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;
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -1683,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)) {
 
        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;
                lfsck_instance_put(&env, lfsck);
        } else {
                rc = -ENXIO;
@@ -1724,7 +1691,7 @@ int lfsck_set_speed(struct dt_device *key, int val)
 }
 EXPORT_SYMBOL(lfsck_set_speed);
 
 }
 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;
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -1737,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)) {
 
        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;
                lfsck_instance_put(&env, lfsck);
        } else {
                rc = -ENXIO;
@@ -1788,7 +1754,7 @@ int lfsck_set_windows(struct dt_device *key, int val)
 }
 EXPORT_SYMBOL(lfsck_set_windows);
 
 }
 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;
 {
        struct lu_env           env;
        struct lfsck_instance  *lfsck;
@@ -1804,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)) {
        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;
                        lfsck_component_put(&env, com);
                } else {
                        rc = -ENOTSUPP;