bcachefs: bch2_version_to_text()
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 28 Jun 2023 23:53:05 +0000 (19:53 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:05 +0000 (17:10 -0400)
Add a new helper for printing out metadata versions in a standard
format.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/opts.c
fs/bcachefs/opts.h
fs/bcachefs/recovery.c
fs/bcachefs/super-io.c
fs/bcachefs/super-io.h
fs/bcachefs/super.c

index 04e2989cd6b392703592c134b211eefce3d26220..a05c389830dc066e53038d23061b660075146ead 100644 (file)
 
 #define x(t, n) [n] = #t,
 
-const char * const bch2_metadata_versions[] = {
-       BCH_METADATA_VERSIONS()
-       NULL
-};
-
 const char * const bch2_error_actions[] = {
        BCH_ERROR_ACTIONS()
        NULL
index 719693b333da231577d0fe09c38809954cbdfca2..e7cf7e92f3dba40144cea48b3d8a3b6322522765 100644 (file)
@@ -8,7 +8,6 @@
 #include <linux/sysfs.h>
 #include "bcachefs_format.h"
 
-extern const char * const bch2_metadata_versions[];
 extern const char * const bch2_error_actions[];
 extern const char * const bch2_sb_features[];
 extern const char * const bch2_sb_compat[];
index 16a99edb2ea834c891f131506cc0f8ed4b38aa07..b86442c7c912add3eb3f2b0a786861460df8a6ce 100644 (file)
@@ -1146,17 +1146,22 @@ int bch2_fs_recovery(struct bch_fs *c)
                goto err;
        }
 
-       if (!c->opts.nochanges) {
-               if (c->sb.version < bcachefs_metadata_required_upgrade_below) {
-                       bch_info(c, "version %s (%u) prior to %s (%u), upgrade and fsck required",
-                                bch2_metadata_versions[c->sb.version],
-                                c->sb.version,
-                                bch2_metadata_versions[bcachefs_metadata_required_upgrade_below],
-                                bcachefs_metadata_required_upgrade_below);
-                       c->opts.version_upgrade = true;
-                       c->opts.fsck            = true;
-                       c->opts.fix_errors      = FSCK_OPT_YES;
-               }
+       if (!c->opts.nochanges &&
+           c->sb.version < bcachefs_metadata_required_upgrade_below) {
+               struct printbuf buf = PRINTBUF;
+
+               prt_str(&buf, "version ");
+               bch2_version_to_text(&buf, c->sb.version);
+               prt_str(&buf, " prior to ");
+               bch2_version_to_text(&buf, bcachefs_metadata_required_upgrade_below);
+               prt_str(&buf, ", upgrade and fsck required");
+
+               bch_info(c, "%s", buf.buf);
+               printbuf_exit(&buf);
+
+               c->opts.version_upgrade = true;
+               c->opts.fsck            = true;
+               c->opts.fix_errors      = FSCK_OPT_YES;
        }
 
        if (c->opts.fsck && c->opts.norecovery) {
index d23ed9ec30f123395285b317d27b0eb6a2f43d2b..2237b1b94bbcdf010c312db5d025762dd195812d 100644 (file)
 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:");
index ab0ad3248e8fad4bbd63bc1ff811814b0d01bd9d..4a193add3447e16e032897199b8dac1265aced90 100644 (file)
@@ -9,6 +9,8 @@
 
 #include <asm/byteorder.h>
 
+void bch2_version_to_text(struct printbuf *, unsigned);
+
 struct bch_sb_field *bch2_sb_field_get(struct bch_sb *, enum bch_sb_field_type);
 struct bch_sb_field *bch2_sb_field_resize(struct bch_sb_handle *,
                                          enum bch_sb_field_type, unsigned);
index 5b0c7dafae2dee5d306b4230fbe48f59aeb099da..62da48863ffa1eee8eb9837e356a1c39e40b6e18 100644 (file)
@@ -877,7 +877,8 @@ static void print_mount_opts(struct bch_fs *c)
        struct printbuf p = PRINTBUF;
        bool first = true;
 
-       prt_printf(&p, "mounted version=%s", bch2_metadata_versions[c->sb.version]);
+       prt_str(&p, "mounted version ");
+       bch2_version_to_text(&p, c->sb.version);
 
        if (c->opts.read_only) {
                prt_str(&p, " opts=");