summaryrefslogtreecommitdiff
path: root/fs/bcachefs/super-io.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-06-28 19:53:05 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:10:05 -0400
commite3804b55e4358cf5a235fa1ba32204af9f7046dd (patch)
treeb1946b7b645d8de6409aa6f7dfda63fcfd7e6f34 /fs/bcachefs/super-io.c
parentf33c58fc46a9c5bd6cbf90edb6ce17fa3fd912d5 (diff)
bcachefs: bch2_version_to_text()
Add a new helper for printing out metadata versions in a standard format. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/super-io.c')
-rw-r--r--fs/bcachefs/super-io.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c
index d23ed9ec30f1..2237b1b94bbc 100644
--- a/fs/bcachefs/super-io.c
+++ b/fs/bcachefs/super-io.c
@@ -26,6 +26,21 @@
static const struct blk_holder_ops bch2_sb_handle_bdev_ops = {
};
+static const char * const bch2_metadata_versions[] = {
+#define x(t, n) [n] = #t,
+ BCH_METADATA_VERSIONS()
+#undef x
+};
+
+void bch2_version_to_text(struct printbuf *out, unsigned v)
+{
+ const char *str = v < ARRAY_SIZE(bch2_metadata_versions)
+ ? bch2_metadata_versions[v]
+ : "(unknown version)";
+
+ prt_printf(out, "%u: %s", v, str);
+}
+
const char * const bch2_sb_fields[] = {
#define x(name, nr) #name,
BCH_SB_FIELDS()
@@ -1510,12 +1525,12 @@ void bch2_sb_to_text(struct printbuf *out, struct bch_sb *sb,
prt_str(out, "Version:");
prt_tab(out);
- prt_printf(out, "%s", bch2_metadata_versions[le16_to_cpu(sb->version)]);
+ bch2_version_to_text(out, le16_to_cpu(sb->version));
prt_newline(out);
prt_printf(out, "Oldest version on disk:");
prt_tab(out);
- prt_printf(out, "%s", bch2_metadata_versions[le16_to_cpu(sb->version_min)]);
+ bch2_version_to_text(out, le16_to_cpu(sb->version_min));
prt_newline(out);
prt_printf(out, "Created:");