summaryrefslogtreecommitdiff
path: root/fs/bcachefs/disk_groups.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-03-05 12:01:16 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:27 -0400
commit5521b1dfa20262a9cb8d1214c095c9ca2a4cb127 (patch)
tree9b325632f659d23c241d2c67567e331c654ebdb4 /fs/bcachefs/disk_groups.c
parent4eea53de8a1882e75d3640dce06c8c2874a77b05 (diff)
bcachefs: Convert bch2_sb_to_text to master option list
Options no longer have to be manually added to bch2_sb_to_text() - it now uses the master list of options in opts.h. Also, improve some of the formatting by converting it to tabstops. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/disk_groups.c')
-rw-r--r--fs/bcachefs/disk_groups.c87
1 files changed, 38 insertions, 49 deletions
diff --git a/fs/bcachefs/disk_groups.c b/fs/bcachefs/disk_groups.c
index e9ee37f1e07d..97eb21827cb3 100644
--- a/fs/bcachefs/disk_groups.c
+++ b/fs/bcachefs/disk_groups.c
@@ -445,7 +445,10 @@ int bch2_opt_target_parse(struct bch_fs *c, const char *buf, u64 *v)
return -EINVAL;
}
-void bch2_sb_target_to_text(struct printbuf *out, struct bch_sb *sb, u64 v)
+void bch2_opt_target_to_text(struct printbuf *out,
+ struct bch_fs *c,
+ struct bch_sb *sb,
+ u64 v)
{
struct target t = target_decode(v);
@@ -453,60 +456,46 @@ void bch2_sb_target_to_text(struct printbuf *out, struct bch_sb *sb, u64 v)
case TARGET_NULL:
pr_buf(out, "none");
break;
- case TARGET_DEV: {
- struct bch_sb_field_members *mi = bch2_sb_get_members(sb);
- struct bch_member *m = mi->members + t.dev;
-
- if (bch2_dev_exists(sb, mi, t.dev)) {
- pr_buf(out, "Device ");
- pr_uuid(out, m->uuid.b);
- pr_buf(out, " (%u)", t.dev);
+ case TARGET_DEV:
+ if (c) {
+ struct bch_dev *ca;
+
+ rcu_read_lock();
+ ca = t.dev < c->sb.nr_devices
+ ? rcu_dereference(c->devs[t.dev])
+ : NULL;
+
+ if (ca && percpu_ref_tryget(&ca->io_ref)) {
+ pr_buf(out, "/dev/%pg", ca->disk_sb.bdev);
+ percpu_ref_put(&ca->io_ref);
+ } else if (ca) {
+ pr_buf(out, "offline device %u", t.dev);
+ } else {
+ pr_buf(out, "invalid device %u", t.dev);
+ }
+
+ rcu_read_unlock();
} else {
- pr_buf(out, "Bad device %u", t.dev);
+ struct bch_sb_field_members *mi = bch2_sb_get_members(sb);
+ struct bch_member *m = mi->members + t.dev;
+
+ if (bch2_dev_exists(sb, mi, t.dev)) {
+ pr_buf(out, "Device ");
+ pr_uuid(out, m->uuid.b);
+ pr_buf(out, " (%u)", t.dev);
+ } else {
+ pr_buf(out, "Bad device %u", t.dev);
+ }
}
-
break;
- }
case TARGET_GROUP:
- bch2_disk_path_to_text(out, sb, t.group);
- break;
- default:
- BUG();
- }
-}
-
-void bch2_opt_target_to_text(struct printbuf *out, struct bch_fs *c, u64 v)
-{
- struct target t = target_decode(v);
-
- switch (t.type) {
- case TARGET_NULL:
- pr_buf(out, "none");
- break;
- case TARGET_DEV: {
- struct bch_dev *ca;
-
- rcu_read_lock();
- ca = t.dev < c->sb.nr_devices
- ? rcu_dereference(c->devs[t.dev])
- : NULL;
-
- if (ca && percpu_ref_tryget(&ca->io_ref)) {
- pr_buf(out, "/dev/%pg", ca->disk_sb.bdev);
- percpu_ref_put(&ca->io_ref);
- } else if (ca) {
- pr_buf(out, "offline device %u", t.dev);
+ if (c) {
+ mutex_lock(&c->sb_lock);
+ bch2_disk_path_to_text(out, c->disk_sb.sb, t.group);
+ mutex_unlock(&c->sb_lock);
} else {
- pr_buf(out, "invalid device %u", t.dev);
+ bch2_disk_path_to_text(out, sb, t.group);
}
-
- rcu_read_unlock();
- break;
- }
- case TARGET_GROUP:
- mutex_lock(&c->sb_lock);
- bch2_disk_path_to_text(out, c->disk_sb.sb, t.group);
- mutex_unlock(&c->sb_lock);
break;
default:
BUG();