bcachefs: version_upgrade is now an enum
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 28 Jun 2023 03:34:02 +0000 (23:34 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:06 +0000 (17:10 -0400)
The version_upgrade parameter is now an enum, not a bool, and it's
persistent in the superblock:
 - compatible (default): upgrade to the latest compatible version
 - incompatible: upgrade to latest incompatible version
 - none

Currently all upgrades are incompatible upgrades, but the next release
will introduce major:minor versions.

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

index d7f030aa30392ff9e7196bf2a65b6165117f77f0..1ab32b61f060cbd49a4a0311db773440eba2e979 100644 (file)
@@ -573,6 +573,7 @@ enum {
        BCH_FS_INITIAL_GC_UNFIXED,      /* kill when we enumerate fsck errors */
        BCH_FS_NEED_ANOTHER_GC,
 
+       BCH_FS_VERSION_UPGRADE,
        BCH_FS_HAVE_DELETED_SNAPSHOTS,
 
        /* errors: */
index c397a3b96bd112cb55510fd16af53dbe18bb54e0..8a0f90a83da91fd0ad3145bf2cbb0595bc6414c5 100644 (file)
@@ -1747,6 +1747,7 @@ LE64_BITMASK(BCH_SB_JOURNAL_RECLAIM_DELAY,struct bch_sb, flags[4], 0, 32);
 LE64_BITMASK(BCH_SB_JOURNAL_TRANSACTION_NAMES,struct bch_sb, flags[4], 32, 33);
 LE64_BITMASK(BCH_SB_NOCOW,             struct bch_sb, flags[4], 33, 34);
 LE64_BITMASK(BCH_SB_WRITE_BUFFER_SIZE, struct bch_sb, flags[4], 34, 54);
+LE64_BITMASK(BCH_SB_VERSION_UPGRADE,   struct bch_sb, flags[4], 54, 56);
 
 /* flags[4] 56-64 unused: */
 
@@ -1819,6 +1820,17 @@ enum bch_sb_compat {
 
 /* options: */
 
+#define BCH_VERSION_UPGRADE_OPTS()     \
+       x(compatible,           0)      \
+       x(incompatible,         1)      \
+       x(none,                 2)
+
+enum bch_version_upgrade_opts {
+#define x(t, n) BCH_VERSION_UPGRADE_##t = n,
+       BCH_VERSION_UPGRADE_OPTS()
+#undef x
+};
+
 #define BCH_REPLICAS_MAX               4U
 
 #define BCH_BKEY_PTRS_MAX              16U
index a05c389830dc066e53038d23061b660075146ead..0c0c83fa426407ee6beff0bd3b0b75e3c6a53cc3 100644 (file)
@@ -16,6 +16,11 @@ const char * const bch2_error_actions[] = {
        NULL
 };
 
+const char * const bch2_version_upgrade_opts[] = {
+       BCH_VERSION_UPGRADE_OPTS()
+       NULL
+};
+
 const char * const bch2_sb_features[] = {
        BCH_SB_FEATURES()
        NULL
index e7cf7e92f3dba40144cea48b3d8a3b6322522765..e105a742fd443b17cecb271b526b25adcb3e3958 100644 (file)
@@ -9,6 +9,7 @@
 #include "bcachefs_format.h"
 
 extern const char * const bch2_error_actions[];
+extern const char * const bch2_version_upgrade_opts[];
 extern const char * const bch2_sb_features[];
 extern const char * const bch2_sb_compat[];
 extern const char * const bch2_btree_ids[];
@@ -388,8 +389,8 @@ enum opt_type {
          NULL,         "Reconstruct alloc btree")                      \
        x(version_upgrade,              u8,                             \
          OPT_FS|OPT_MOUNT,                                             \
-         OPT_BOOL(),                                                   \
-         BCH2_NO_SB_OPT,               false,                          \
+         OPT_STR(bch2_version_upgrade_opts),                           \
+         BCH_SB_VERSION_UPGRADE,       BCH_VERSION_UPGRADE_compatible, \
          NULL,         "Set superblock to latest version,\n"           \
                        "allowing any new features to be used")         \
        x(buckets_nouse,                u8,                             \
index 0173707cfd2ea70c9b147895add41ce15f2731e3..c90205aa223e52a496764d63de61f9a5ad6b7707 100644 (file)
@@ -1111,11 +1111,16 @@ static void check_version_upgrade(struct bch_fs *c)
 {
        unsigned version = c->sb.version_upgrade_complete ?: c->sb.version;
 
-       if (version < bcachefs_metadata_required_upgrade_below) {
+       if (version < bcachefs_metadata_required_upgrade_below ||
+           (version < bcachefs_metadata_version_current &&
+            c->opts.version_upgrade != BCH_VERSION_UPGRADE_none)) {
                struct printbuf buf = PRINTBUF;
 
-               if (version != c->sb.version)
-                       prt_str(&buf, "version upgrade incomplete:\n");
+               if (version != c->sb.version) {
+                       prt_str(&buf, "version upgrade to ");
+                       bch2_version_to_text(&buf, c->sb.version);
+                       prt_str(&buf, " incomplete:\n");
+               }
 
                prt_str(&buf, "version ");
                bch2_version_to_text(&buf, version);
@@ -1126,9 +1131,9 @@ static void check_version_upgrade(struct bch_fs *c)
                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;
+               set_bit(BCH_FS_VERSION_UPGRADE, &c->flags);
        }
 }
 
@@ -1534,11 +1539,9 @@ int bch2_fs_initialize(struct bch_fs *c)
        c->disk_sb.sb->compat[0] |= cpu_to_le64(1ULL << BCH_COMPAT_extents_above_btree_updates_done);
        c->disk_sb.sb->compat[0] |= cpu_to_le64(1ULL << BCH_COMPAT_bformat_overflow_done);
 
-       if (c->sb.version < bcachefs_metadata_version_inode_v3)
-               c->opts.version_upgrade = true;
-
-       if (c->opts.version_upgrade) {
+       if (c->opts.version_upgrade != BCH_VERSION_UPGRADE_none) {
                c->disk_sb.sb->version = cpu_to_le16(bcachefs_metadata_version_current);
+               SET_BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb, bcachefs_metadata_version_current);
                c->disk_sb.sb->features[0] |= cpu_to_le64(BCH_SB_FEATURES_ALL);
                bch2_write_super(c);
        }
index 71a1e2d76a15126b835c8bc73b2b06019f7591f6..1437c363a4abca304759e4a39eec72ccdfb9194d 100644 (file)
@@ -816,7 +816,7 @@ int bch2_write_super(struct bch_fs *c)
        closure_init_stack(cl);
        memset(&sb_written, 0, sizeof(sb_written));
 
-       if (c->opts.version_upgrade) {
+       if (test_bit(BCH_FS_VERSION_UPGRADE, &c->flags)) {
                c->disk_sb.sb->magic = BCHFS_MAGIC;
                c->disk_sb.sb->layout.magic = BCHFS_MAGIC;
        }
@@ -1197,11 +1197,11 @@ int bch2_fs_mark_dirty(struct bch_fs *c)
        if (BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb) > bcachefs_metadata_version_current)
                SET_BCH_SB_VERSION_UPGRADE_COMPLETE(c->disk_sb.sb, bcachefs_metadata_version_current);
 
-       if (c->opts.version_upgrade ||
+       if (test_bit(BCH_FS_VERSION_UPGRADE, &c->flags) ||
            c->sb.version > bcachefs_metadata_version_current)
                c->disk_sb.sb->version = cpu_to_le16(bcachefs_metadata_version_current);
 
-       if (c->opts.version_upgrade)
+       if (test_bit(BCH_FS_VERSION_UPGRADE, &c->flags))
                c->disk_sb.sb->features[0] |= cpu_to_le64(BCH_SB_FEATURES_ALL);
 
        c->disk_sb.sb->features[0] |= cpu_to_le64(BCH_SB_FEATURES_ALWAYS);