]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
bcachefs: Don't unconditially version_upgrade in initialize
authorKent Overstreet <kent.overstreet@gmail.com>
Sun, 21 Mar 2021 20:20:40 +0000 (16:20 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:56 +0000 (17:08 -0400)
This is mkfs's job. Also, clean up the handling of feature bits some.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/alloc_background.c
fs/bcachefs/bcachefs_format.h
fs/bcachefs/recovery.c

index e2200cedeccab5b04774a74cf3aa3b5606cd63e6..be86e36e816a837b5953ee51ae17450148d7b048 100644 (file)
@@ -114,25 +114,6 @@ static void bch2_alloc_unpack_v1(struct bkey_alloc_unpacked *out,
 #undef  x
 }
 
-static void bch2_alloc_pack_v1(struct bkey_alloc_buf *dst,
-                              const struct bkey_alloc_unpacked src)
-{
-       struct bkey_i_alloc *a = bkey_alloc_init(&dst->k);
-       void *d = a->v.data;
-       unsigned bytes, idx = 0;
-
-       a->k.p          = POS(src.dev, src.bucket);
-       a->v.fields     = 0;
-       a->v.gen        = src.gen;
-
-#define x(_name, _bits)        alloc_field_v1_put(a, &d, idx++, src._name);
-       BCH_ALLOC_FIELDS_V1()
-#undef  x
-       bytes = (void *) d - (void *) &a->v;
-       set_bkey_val_bytes(&a->k, bytes);
-       memset_u64s_tail(&a->v, 0, bytes);
-}
-
 static int bch2_alloc_unpack_v2(struct bkey_alloc_unpacked *out,
                                struct bkey_s_c k)
 {
@@ -225,10 +206,7 @@ void bch2_alloc_pack(struct bch_fs *c,
                     struct bkey_alloc_buf *dst,
                     const struct bkey_alloc_unpacked src)
 {
-       if (c->sb.features & (1ULL << BCH_FEATURE_alloc_v2))
-               bch2_alloc_pack_v2(dst, src);
-       else
-               bch2_alloc_pack_v1(dst, src);
+       bch2_alloc_pack_v2(dst, src);
 }
 
 static unsigned bch_alloc_val_u64s(const struct bch_alloc *a)
index df6961805f6ff5b4691f1579eb814debbd115937..111f7d3c312e20c915b0c6d9eaf612317a085a03 100644 (file)
@@ -1380,6 +1380,7 @@ LE64_BITMASK(BCH_SB_METADATA_TARGET,      struct bch_sb, flags[3], 16, 28);
        ((1ULL << BCH_FEATURE_new_extent_overwrite)|    \
         (1ULL << BCH_FEATURE_extents_above_btree_updates)|\
         (1ULL << BCH_FEATURE_btree_updates_journalled)|\
+        (1ULL << BCH_FEATURE_alloc_v2)|\
         (1ULL << BCH_FEATURE_extents_across_btree_nodes))
 
 #define BCH_SB_FEATURES_ALL                            \
@@ -1387,8 +1388,7 @@ LE64_BITMASK(BCH_SB_METADATA_TARGET,      struct bch_sb, flags[3], 16, 28);
         (1ULL << BCH_FEATURE_new_siphash)|             \
         (1ULL << BCH_FEATURE_btree_ptr_v2)|            \
         (1ULL << BCH_FEATURE_new_varint)|              \
-        (1ULL << BCH_FEATURE_journal_no_flush)|        \
-        (1ULL << BCH_FEATURE_alloc_v2))
+        (1ULL << BCH_FEATURE_journal_no_flush))
 
 enum bch_sb_feature {
 #define x(f, n) BCH_FEATURE_##f,
index 03a25dd5acc6f1e79fb9c4b48e6023ee6ef7e28f..92f7568175eb42b32c23da5b163cc8396bfd617d 100644 (file)
@@ -991,11 +991,17 @@ int bch2_fs_recovery(struct bch_fs *c)
                goto err;
        }
 
+       if (!c->sb.clean &&
+           !(c->sb.features & (1ULL << BCH_FEATURE_extents_above_btree_updates))) {
+               bch_err(c, "filesystem needs recovery from older version; run fsck from older bcachefs-tools to fix");
+               ret = -EINVAL;
+               goto err;
+       }
+
        if (!(c->sb.features & (1ULL << BCH_FEATURE_alloc_v2))) {
                bch_info(c, "alloc_v2 feature bit not set, fsck required");
                c->opts.fsck = true;
                c->opts.fix_errors = FSCK_OPT_YES;
-               c->disk_sb.sb->features[0] |= 1ULL << BCH_FEATURE_alloc_v2;
        }
 
        if (!c->replicas.entries ||
@@ -1061,13 +1067,6 @@ use_clean:
                blacklist_seq = journal_seq = le64_to_cpu(clean->journal_seq) + 1;
        }
 
-       if (!c->sb.clean &&
-           !(c->sb.features & (1ULL << BCH_FEATURE_extents_above_btree_updates))) {
-               bch_err(c, "filesystem needs recovery from older version; run fsck from older bcachefs-tools to fix");
-               ret = -EINVAL;
-               goto err;
-       }
-
        if (c->opts.reconstruct_alloc) {
                c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info);
                drop_alloc_keys(&c->journal_keys);
@@ -1228,9 +1227,6 @@ use_clean:
 
        mutex_lock(&c->sb_lock);
        if (c->opts.version_upgrade) {
-               if (c->sb.version < bcachefs_metadata_version_new_versioning)
-                       c->disk_sb.sb->version_min =
-                               le16_to_cpu(bcachefs_metadata_version_min);
                c->disk_sb.sb->version = le16_to_cpu(bcachefs_metadata_version_current);
                c->disk_sb.sb->features[0] |= BCH_SB_FEATURES_ALL;
                write_sb = true;
@@ -1288,19 +1284,17 @@ int bch2_fs_initialize(struct bch_fs *c)
        bch_notice(c, "initializing new filesystem");
 
        mutex_lock(&c->sb_lock);
-       for_each_online_member(ca, c, i)
-               bch2_mark_dev_superblock(c, ca, 0);
-       mutex_unlock(&c->sb_lock);
-
-       mutex_lock(&c->sb_lock);
-       c->disk_sb.sb->version = c->disk_sb.sb->version_min =
-               le16_to_cpu(bcachefs_metadata_version_current);
-       c->disk_sb.sb->features[0] |= 1ULL << BCH_FEATURE_atomic_nlink;
-       c->disk_sb.sb->features[0] |= BCH_SB_FEATURES_ALL;
        c->disk_sb.sb->compat[0] |= 1ULL << BCH_COMPAT_extents_above_btree_updates_done;
        c->disk_sb.sb->compat[0] |= 1ULL << BCH_COMPAT_bformat_overflow_done;
 
-       bch2_write_super(c);
+       if (c->opts.version_upgrade) {
+               c->disk_sb.sb->version = le16_to_cpu(bcachefs_metadata_version_current);
+               c->disk_sb.sb->features[0] |= BCH_SB_FEATURES_ALL;
+               bch2_write_super(c);
+       }
+
+       for_each_online_member(ca, c, i)
+               bch2_mark_dev_superblock(c, ca, 0);
        mutex_unlock(&c->sb_lock);
 
        set_bit(BCH_FS_ALLOC_READ_DONE, &c->flags);