summaryrefslogtreecommitdiff
path: root/libbcachefs/disk_groups.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-02-21 05:38:44 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2022-02-21 05:38:44 -0500
commitc06026ac542911329a99a3f02a4f5732d6c8e51c (patch)
tree01498700cb8255284e8d32a6e1703edfc33e9d99 /libbcachefs/disk_groups.c
parentf85062409230ee9c0ce9e1a7bedb916006597e97 (diff)
Update bcachefs sources to 9d554fa16d bcachefs: Add .to_text() methods for all superblock sections
Diffstat (limited to 'libbcachefs/disk_groups.c')
-rw-r--r--libbcachefs/disk_groups.c49
1 files changed, 38 insertions, 11 deletions
diff --git a/libbcachefs/disk_groups.c b/libbcachefs/disk_groups.c
index 6c84297..19698e5 100644
--- a/libbcachefs/disk_groups.c
+++ b/libbcachefs/disk_groups.c
@@ -76,8 +76,9 @@ static int bch2_sb_disk_groups_validate(struct bch_sb *sb,
for (g = sorted; g + 1 < sorted + nr_groups; g++)
if (!BCH_GROUP_DELETED(g) &&
!group_cmp(&g[0], &g[1])) {
- pr_buf(err, "duplicate label %llu.", BCH_GROUP_PARENT(g));
- bch_scnmemcpy(err, g->label, strnlen(g->label, sizeof(g->label)));
+ pr_buf(err, "duplicate label %llu.%.*s",
+ BCH_GROUP_PARENT(g),
+ (int) sizeof(g->label), g->label);
goto err;
}
@@ -342,12 +343,10 @@ 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_sb_handle *sb,
- unsigned v)
+void bch2_disk_path_to_text(struct printbuf *out, struct bch_sb *sb, unsigned v)
{
struct bch_sb_field_disk_groups *groups =
- bch2_sb_get_disk_groups(sb->sb);
+ bch2_sb_get_disk_groups(sb);
struct bch_disk_group *g;
unsigned nr = 0;
u16 path[32];
@@ -376,15 +375,13 @@ void bch2_disk_path_to_text(struct printbuf *out,
v = path[--nr];
g = groups->entries + v;
- bch_scnmemcpy(out, g->label,
- strnlen(g->label, sizeof(g->label)));
-
+ pr_buf(out, "%.*s", (int) sizeof(g->label), g->label);
if (nr)
pr_buf(out, ".");
}
return;
inval:
- pr_buf(out, "invalid group %u", v);
+ pr_buf(out, "invalid label %u", v);
}
int bch2_dev_group_set(struct bch_fs *c, struct bch_dev *ca, const char *name)
@@ -448,6 +445,36 @@ 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)
+{
+ struct target t = target_decode(v);
+
+ switch (t.type) {
+ 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);
+ } 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);
@@ -481,7 +508,7 @@ void bch2_opt_target_to_text(struct printbuf *out, struct bch_fs *c, u64 v)
}
case TARGET_GROUP:
mutex_lock(&c->sb_lock);
- bch2_disk_path_to_text(out, &c->disk_sb, t.group);
+ bch2_disk_path_to_text(out, c->disk_sb.sb, t.group);
mutex_unlock(&c->sb_lock);
break;
default: