Commit 59a1a62a authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_sb_nr_devices()

factoring out a helper
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 11827dba
...@@ -465,3 +465,12 @@ void bch2_dev_btree_bitmap_mark(struct bch_fs *c, struct bkey_s_c k) ...@@ -465,3 +465,12 @@ void bch2_dev_btree_bitmap_mark(struct bch_fs *c, struct bkey_s_c k)
__bch2_dev_btree_bitmap_mark(mi, ptr->dev, ptr->offset, btree_sectors(c)); __bch2_dev_btree_bitmap_mark(mi, ptr->dev, ptr->offset, btree_sectors(c));
} }
} }
unsigned bch2_sb_nr_devices(const struct bch_sb *sb)
{
unsigned nr = 0;
for (unsigned i = 0; i < sb->nr_devices; i++)
nr += bch2_member_exists((struct bch_sb *) sb, i);
return nr;
}
...@@ -307,6 +307,8 @@ static inline bool bch2_member_exists(struct bch_sb *sb, unsigned dev) ...@@ -307,6 +307,8 @@ static inline bool bch2_member_exists(struct bch_sb *sb, unsigned dev)
return false; return false;
} }
unsigned bch2_sb_nr_devices(const struct bch_sb *);
static inline struct bch_member_cpu bch2_mi_to_cpu(struct bch_member *mi) static inline struct bch_member_cpu bch2_mi_to_cpu(struct bch_member *mi)
{ {
return (struct bch_member_cpu) { return (struct bch_member_cpu) {
......
...@@ -1295,15 +1295,9 @@ void bch2_sb_layout_to_text(struct printbuf *out, struct bch_sb_layout *l) ...@@ -1295,15 +1295,9 @@ void bch2_sb_layout_to_text(struct printbuf *out, struct bch_sb_layout *l)
void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb, void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
bool print_layout, unsigned fields) bool print_layout, unsigned fields)
{ {
u64 fields_have = 0;
unsigned nr_devices = 0;
if (!out->nr_tabstops) if (!out->nr_tabstops)
printbuf_tabstop_push(out, 44); printbuf_tabstop_push(out, 44);
for (int i = 0; i < sb->nr_devices; i++)
nr_devices += bch2_member_exists(sb, i);
prt_printf(out, "External UUID:\t"); prt_printf(out, "External UUID:\t");
pr_uuid(out, sb->user_uuid.b); pr_uuid(out, sb->user_uuid.b);
prt_newline(out); prt_newline(out);
...@@ -1359,9 +1353,10 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb, ...@@ -1359,9 +1353,10 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
prt_newline(out); prt_newline(out);
prt_printf(out, "Clean:\t%llu\n", BCH_SB_CLEAN(sb)); prt_printf(out, "Clean:\t%llu\n", BCH_SB_CLEAN(sb));
prt_printf(out, "Devices:\t%u\n", nr_devices); prt_printf(out, "Devices:\t%u\n", bch2_sb_nr_devices(sb));
prt_printf(out, "Sections:\t"); prt_printf(out, "Sections:\t");
u64 fields_have = 0;
vstruct_for_each(sb, f) vstruct_for_each(sb, f)
fields_have |= 1 << le32_to_cpu(f->type); fields_have |= 1 << le32_to_cpu(f->type);
prt_bitflags(out, bch2_sb_fields, fields_have); prt_bitflags(out, bch2_sb_fields, fields_have);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment