]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Improve bch2_disk_groups_to_text()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 1 May 2025 02:26:00 +0000 (22:26 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:39 +0000 (20:14 -0400)
Print out the actual name of each path/label, instead of just the
integer indexes.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/disk_groups.c

index 4e2f237338c20fbacf6034aba98e0a7fc06d6114..c1a2a957c884eeb35237f2409fe5078c43b92e9e 100644 (file)
@@ -86,35 +86,6 @@ err:
        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)