diff options
Diffstat (limited to 'libbcachefs/replicas.c')
-rw-r--r-- | libbcachefs/replicas.c | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/libbcachefs/replicas.c b/libbcachefs/replicas.c index b0cef995..4da35d09 100644 --- a/libbcachefs/replicas.c +++ b/libbcachefs/replicas.c @@ -39,38 +39,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, @@ -266,6 +259,8 @@ int bch2_mark_bkey_replicas(struct bch_fs *c, struct bch_replicas_entry_padded search; int ret; + memset(&search, 0, sizeof(search)); + if (type == BKEY_TYPE_EXTENTS) { struct bch_devs_list cached = bch2_bkey_cached_devs(k); unsigned i; @@ -507,32 +502,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, @@ -563,6 +554,8 @@ bool bch2_bkey_replicas_marked(struct bch_fs *c, struct bch_replicas_entry_padded search; bool ret; + memset(&search, 0, sizeof(search)); + if (type == BKEY_TYPE_EXTENTS) { struct bch_devs_list cached = bch2_bkey_cached_devs(k); unsigned i; |