diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2018-11-09 01:24:07 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:08:11 -0400 |
commit | 319f9ac38eaba628d69b6ddbf402b35487315fc1 (patch) | |
tree | 01daddd4881b1f09bb4d50087e8b8803e59fea35 /fs/bcachefs/replicas.c | |
parent | 75369d4ec3d2dfc52af18a2d20cd0af14c935ac9 (diff) |
bcachefs: revamp to_text methods
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/replicas.c')
-rw-r--r-- | fs/bcachefs/replicas.c | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/fs/bcachefs/replicas.c b/fs/bcachefs/replicas.c index a7c3aca1bf01..fb11b97cdeee 100644 --- a/fs/bcachefs/replicas.c +++ b/fs/bcachefs/replicas.c @@ -40,38 +40,31 @@ static void bch2_cpu_replicas_sort(struct bch_replicas_cpu *r) eytzinger0_sort(r->entries, r->nr, r->entry_size, memcmp, NULL); } -static int replicas_entry_to_text(struct bch_replicas_entry *e, - char *buf, size_t size) +static void replicas_entry_to_text(struct printbuf *out, + struct bch_replicas_entry *e) { - char *out = buf, *end = out + size; unsigned i; - out += scnprintf(out, end - out, "%u: [", e->data_type); + pr_buf(out, "%u: [", e->data_type); for (i = 0; i < e->nr_devs; i++) - out += scnprintf(out, end - out, - i ? " %u" : "%u", e->devs[i]); - out += scnprintf(out, end - out, "]"); - - return out - buf; + pr_buf(out, i ? " %u" : "%u", e->devs[i]); + pr_buf(out, "]"); } -int bch2_cpu_replicas_to_text(struct bch_replicas_cpu *r, - char *buf, size_t size) +void bch2_cpu_replicas_to_text(struct printbuf *out, + struct bch_replicas_cpu *r) { - char *out = buf, *end = out + size; struct bch_replicas_entry *e; bool first = true; for_each_cpu_replicas_entry(r, e) { if (!first) - out += scnprintf(out, end - out, " "); + pr_buf(out, " "); first = false; - out += replicas_entry_to_text(e, out, end - out); + replicas_entry_to_text(out, e); } - - return out - buf; } static void extent_to_replicas(struct bkey_s_c k, @@ -510,32 +503,28 @@ err: return err; } -const struct bch_sb_field_ops bch_sb_field_ops_replicas = { - .validate = bch2_sb_validate_replicas, -}; - -int bch2_sb_replicas_to_text(struct bch_sb_field_replicas *r, char *buf, size_t size) +static void bch2_sb_replicas_to_text(struct printbuf *out, + struct bch_sb *sb, + struct bch_sb_field *f) { - char *out = buf, *end = out + size; + struct bch_sb_field_replicas *r = field_to_type(f, replicas); struct bch_replicas_entry *e; bool first = true; - if (!r) { - out += scnprintf(out, end - out, "(no replicas section found)"); - return out - buf; - } - for_each_replicas_entry(r, e) { if (!first) - out += scnprintf(out, end - out, " "); + pr_buf(out, " "); first = false; - out += replicas_entry_to_text(e, out, end - out); + replicas_entry_to_text(out, e); } - - return out - buf; } +const struct bch_sb_field_ops bch_sb_field_ops_replicas = { + .validate = bch2_sb_validate_replicas, + .to_text = bch2_sb_replicas_to_text, +}; + /* Query replicas: */ bool bch2_replicas_marked(struct bch_fs *c, |