bcachefs: create internal disk_groups sysfs file
authorBrian Foster <bfoster@redhat.com>
Tue, 30 May 2023 18:41:50 +0000 (14:41 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:03 +0000 (17:10 -0400)
We have bch2_sb_disk_groups_to_text() to dump disk group labels, but
no good information on device group membership at runtime. Add
bch2_disk_groups_to_text() and an associated 'disk_groups' sysfs
file to print group and device relationships.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/disk_groups.c
fs/bcachefs/disk_groups.h
fs/bcachefs/sysfs.c

index 1a8f8b3750da15ebf6e9731cdab43de35e391b79..aa3a4e5a8b2ecea8c9845e6565df9d429a34a311 100644 (file)
@@ -87,6 +87,40 @@ err:
        return ret;
 }
 
+void bch2_disk_groups_to_text(struct printbuf *out, struct bch_fs *c)
+{
+       struct bch_disk_groups_cpu *g;
+       struct bch_dev *ca;
+       int i;
+       unsigned iter;
+
+       out->atomic++;
+       rcu_read_lock();
+
+       g = rcu_dereference(c->disk_groups);
+       if (!g)
+               goto out;
+
+       for (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(ca, c, iter, &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)
index e4470c357a66b8ee6ae2d72526a558e23edee249..bf39db3868bfe8b17d95f8ef76910dcbada6823e 100644 (file)
@@ -88,4 +88,6 @@ int bch2_dev_group_set(struct bch_fs *, struct bch_dev *, const char *);
 const char *bch2_sb_validate_disk_groups(struct bch_sb *,
                                         struct bch_sb_field *);
 
+void bch2_disk_groups_to_text(struct printbuf *, struct bch_fs *);
+
 #endif /* _BCACHEFS_DISK_GROUPS_H */
index b2274cb351721fc2218bac86ba1c17849ad86c3e..77f92d537af62360919bf5e4649d8cd00f99a54c 100644 (file)
@@ -223,6 +223,7 @@ static void bch2_write_refs_to_text(struct printbuf *out, struct bch_fs *c)
 #endif
 
 read_attribute(internal_uuid);
+read_attribute(disk_groups);
 
 read_attribute(has_data);
 read_attribute(alloc_debug);
@@ -471,6 +472,9 @@ SHOW(bch2_fs)
        if (attr == &sysfs_nocow_lock_table)
                bch2_nocow_locks_to_text(out, &c->nocow_locks);
 
+       if (attr == &sysfs_disk_groups)
+               bch2_disk_groups_to_text(out, c);
+
        return 0;
 }
 
@@ -681,6 +685,8 @@ struct attribute *bch2_fs_internal_files[] = {
        &sysfs_moving_ctxts,
 
        &sysfs_internal_uuid,
+
+       &sysfs_disk_groups,
        NULL
 };