diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-06-27 23:34:02 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:10:06 -0400 |
commit | 3045bb958acf5d3bc799c791d14e40676477bd16 (patch) | |
tree | 96b0cb3ac2b3c92ef2179b0e74e32906aef252d7 /fs | |
parent | 24964e1c5c89e00ca55909ab24ce8d28e2b46406 (diff) | |
download | linux-stable-3045bb958acf5d3bc799c791d14e40676477bd16.tar.gz linux-stable-3045bb958acf5d3bc799c791d14e40676477bd16.tar.bz2 linux-stable-3045bb958acf5d3bc799c791d14e40676477bd16.zip |
bcachefs: version_upgrade is now an enum
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/bcachefs/bcachefs.h | 1 | ||||
-rw-r--r-- | fs/bcachefs/bcachefs_format.h | 12 | ||||
-rw-r--r-- | fs/bcachefs/opts.c | 5 | ||||
-rw-r--r-- | fs/bcachefs/opts.h | 5 | ||||
-rw-r--r-- | fs/bcachefs/recovery.c | 19 | ||||
-rw-r--r-- | fs/bcachefs/super-io.c | 6 |
6 files changed, 35 insertions, 13 deletions
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index d7f030aa3039..1ab32b61f060 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -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: */ diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h index c397a3b96bd1..8a0f90a83da9 100644 --- a/fs/bcachefs/bcachefs_format.h +++ b/fs/bcachefs/bcachefs_format.h @@ -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 diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c index a05c389830dc..0c0c83fa4264 100644 --- a/fs/bcachefs/opts.c +++ b/fs/bcachefs/opts.c @@ -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 diff --git a/fs/bcachefs/opts.h b/fs/bcachefs/opts.h index e7cf7e92f3db..e105a742fd44 100644 --- a/fs/bcachefs/opts.h +++ b/fs/bcachefs/opts.h @@ -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, \ diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c index 0173707cfd2e..c90205aa223e 100644 --- a/fs/bcachefs/recovery.c +++ b/fs/bcachefs/recovery.c @@ -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); } diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c index 71a1e2d76a15..1437c363a4ab 100644 --- a/fs/bcachefs/super-io.c +++ b/fs/bcachefs/super-io.c @@ -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); |