mirror of
https://github.com/torvalds/linux.git
synced 2026-06-02 11:33:28 +02:00
bcachefs: Improve bch2_disk_groups_to_text()
Print out the actual name of each path/label, instead of just the integer indexes. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
c53e5c0c19
commit
a42f709f9a
|
|
@ -86,35 +86,6 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb, struct bch_sb_field *
|
|||
return ret;
|
||||
}
|
||||
|
||||
void bch2_disk_groups_to_text(struct printbuf *out, struct bch_fs *c)
|
||||
{
|
||||
out->atomic++;
|
||||
rcu_read_lock();
|
||||
|
||||
struct bch_disk_groups_cpu *g = rcu_dereference(c->disk_groups);
|
||||
if (!g)
|
||||
goto out;
|
||||
|
||||
for (unsigned i = 0; i < g->nr; i++) {
|
||||
if (i)
|
||||
prt_printf(out, " ");
|
||||
|
||||
if (g->entries[i].deleted) {
|
||||
prt_printf(out, "[deleted]");
|
||||
continue;
|
||||
}
|
||||
|
||||
prt_printf(out, "[parent %d devs", g->entries[i].parent);
|
||||
for_each_member_device_rcu(c, ca, &g->entries[i].devs)
|
||||
prt_printf(out, " %s", ca->name);
|
||||
prt_printf(out, "]");
|
||||
}
|
||||
|
||||
out:
|
||||
rcu_read_unlock();
|
||||
out->atomic--;
|
||||
}
|
||||
|
||||
static void bch2_sb_disk_groups_to_text(struct printbuf *out,
|
||||
struct bch_sb *sb,
|
||||
struct bch_sb_field *f)
|
||||
|
|
@ -241,17 +212,14 @@ bool bch2_dev_in_target(struct bch_fs *c, unsigned dev, unsigned target)
|
|||
case TARGET_DEV:
|
||||
return dev == t.dev;
|
||||
case TARGET_GROUP: {
|
||||
struct bch_disk_groups_cpu *g;
|
||||
const struct bch_devs_mask *m;
|
||||
bool ret;
|
||||
|
||||
rcu_read_lock();
|
||||
g = rcu_dereference(c->disk_groups);
|
||||
m = g && t.group < g->nr && !g->entries[t.group].deleted
|
||||
struct bch_disk_groups_cpu *g = rcu_dereference(c->disk_groups);
|
||||
const struct bch_devs_mask *m =
|
||||
g && t.group < g->nr && !g->entries[t.group].deleted
|
||||
? &g->entries[t.group].devs
|
||||
: NULL;
|
||||
|
||||
ret = m ? test_bit(dev, m->d) : false;
|
||||
bool ret = m ? test_bit(dev, m->d) : false;
|
||||
rcu_read_unlock();
|
||||
|
||||
return ret;
|
||||
|
|
@ -377,54 +345,81 @@ int bch2_disk_path_find_or_create(struct bch_sb_handle *sb, const char *name)
|
|||
return v;
|
||||
}
|
||||
|
||||
void bch2_disk_path_to_text(struct printbuf *out, struct bch_fs *c, unsigned v)
|
||||
static void __bch2_disk_path_to_text(struct printbuf *out, struct bch_disk_groups_cpu *g,
|
||||
unsigned v)
|
||||
{
|
||||
struct bch_disk_groups_cpu *groups;
|
||||
struct bch_disk_group_cpu *g;
|
||||
unsigned nr = 0;
|
||||
u16 path[32];
|
||||
|
||||
out->atomic++;
|
||||
rcu_read_lock();
|
||||
groups = rcu_dereference(c->disk_groups);
|
||||
if (!groups)
|
||||
goto invalid;
|
||||
unsigned nr = 0;
|
||||
|
||||
while (1) {
|
||||
if (nr == ARRAY_SIZE(path))
|
||||
goto invalid;
|
||||
|
||||
if (v >= groups->nr)
|
||||
if (v >= (g ? g->nr : 0))
|
||||
goto invalid;
|
||||
|
||||
g = groups->entries + v;
|
||||
struct bch_disk_group_cpu *e = g->entries + v;
|
||||
|
||||
if (g->deleted)
|
||||
if (e->deleted)
|
||||
goto invalid;
|
||||
|
||||
path[nr++] = v;
|
||||
|
||||
if (!g->parent)
|
||||
if (!e->parent)
|
||||
break;
|
||||
|
||||
v = g->parent - 1;
|
||||
v = e->parent - 1;
|
||||
}
|
||||
|
||||
while (nr) {
|
||||
v = path[--nr];
|
||||
g = groups->entries + v;
|
||||
struct bch_disk_group_cpu *e = g->entries + path[--nr];
|
||||
|
||||
prt_printf(out, "%.*s", (int) sizeof(g->label), g->label);
|
||||
prt_printf(out, "%.*s", (int) sizeof(e->label), e->label);
|
||||
if (nr)
|
||||
prt_printf(out, ".");
|
||||
}
|
||||
out:
|
||||
rcu_read_unlock();
|
||||
out->atomic--;
|
||||
return;
|
||||
invalid:
|
||||
prt_printf(out, "invalid label %u", v);
|
||||
goto out;
|
||||
}
|
||||
|
||||
void bch2_disk_groups_to_text(struct printbuf *out, struct bch_fs *c)
|
||||
{
|
||||
bch2_printbuf_make_room(out, 4096);
|
||||
|
||||
out->atomic++;
|
||||
rcu_read_lock();
|
||||
struct bch_disk_groups_cpu *g = rcu_dereference(c->disk_groups);
|
||||
|
||||
for (unsigned i = 0; i < (g ? g->nr : 0); i++) {
|
||||
prt_printf(out, "%2u: ", i);
|
||||
|
||||
if (g->entries[i].deleted) {
|
||||
prt_printf(out, "[deleted]");
|
||||
goto next;
|
||||
}
|
||||
|
||||
__bch2_disk_path_to_text(out, g, i);
|
||||
|
||||
prt_printf(out, " devs");
|
||||
|
||||
for_each_member_device_rcu(c, ca, &g->entries[i].devs)
|
||||
prt_printf(out, " %s", ca->name);
|
||||
next:
|
||||
prt_newline(out);
|
||||
}
|
||||
|
||||
rcu_read_unlock();
|
||||
out->atomic--;
|
||||
}
|
||||
|
||||
void bch2_disk_path_to_text(struct printbuf *out, struct bch_fs *c, unsigned v)
|
||||
{
|
||||
out->atomic++;
|
||||
rcu_read_lock();
|
||||
__bch2_disk_path_to_text(out, rcu_dereference(c->disk_groups), v),
|
||||
rcu_read_unlock();
|
||||
--out->atomic;
|
||||
}
|
||||
|
||||
void bch2_disk_path_to_text_sb(struct printbuf *out, struct bch_sb *sb, unsigned v)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user