bcachefs: bch2_check_set_feature()
authorKent Overstreet <kent.overstreet@gmail.com>
Fri, 29 Nov 2019 18:47:42 +0000 (13:47 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:32 +0000 (17:08 -0400)
New helper function for setting incompatible feature bits

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

index 5de554a883ef6d346ead2149fa5bda15775253f0..6934a0339eb0b735220c9f4fcd29480cd056f908 100644 (file)
@@ -1141,6 +1141,8 @@ static void bch2_write_data_inline(struct bch_write_op *op, unsigned data_len)
        unsigned sectors;
        int ret;
 
+       bch2_check_set_feature(op->c, BCH_FEATURE_INLINE_DATA);
+
        ret = bch2_keylist_realloc(&op->insert_keys, op->inline_keys,
                                   ARRAY_SIZE(op->inline_keys),
                                   BKEY_U64s + DIV_ROUND_UP(data_len, 8));
index 13a9a2fcd575853e07bcde406a364f92aa741495..cbacd2f36799bdf265181d381b6858540bfd7b15 100644 (file)
@@ -299,15 +299,8 @@ int bch2_opt_check_may_set(struct bch_fs *c, int id, u64 v)
                ret = bch2_check_set_has_compressed_data(c, v);
                break;
        case Opt_erasure_code:
-               if (v &&
-                   !(c->sb.features & (1ULL << BCH_FEATURE_EC))) {
-                       mutex_lock(&c->sb_lock);
-                       c->disk_sb.sb->features[0] |=
-                               cpu_to_le64(1ULL << BCH_FEATURE_EC);
-
-                       bch2_write_super(c);
-                       mutex_unlock(&c->sb_lock);
-               }
+               if (v)
+                       bch2_check_set_feature(c, BCH_FEATURE_EC);
                break;
        }
 
index d4002b7fc917e4dc1645787bc490ec7dee775b56..e6b51131cff2d990c3c66b6256ec3eb13134a816 100644 (file)
@@ -913,12 +913,6 @@ int bch2_fs_recovery(struct bch_fs *c)
                write_sb = true;
        }
 
-       if (!(c->sb.features & (1ULL << BCH_FEATURE_INLINE_DATA))) {
-               c->disk_sb.sb->features[0] |=
-                       cpu_to_le64(1ULL << BCH_FEATURE_INLINE_DATA);
-               write_sb = true;
-       }
-
        if (!test_bit(BCH_FS_ERROR, &c->flags)) {
                c->disk_sb.sb->compat[0] |= 1ULL << BCH_COMPAT_FEAT_ALLOC_INFO;
                write_sb = true;
index 2812fa305c0edea7457a8698fd3965771b74d89d..53bd0e0ea058ad5585e183aeadd37d5213e88831 100644 (file)
@@ -171,16 +171,7 @@ s64 bch2_remap_range(struct bch_fs *c,
        if (!percpu_ref_tryget(&c->writes))
                return -EROFS;
 
-       if (!(c->sb.features & (1ULL << BCH_FEATURE_REFLINK))) {
-               mutex_lock(&c->sb_lock);
-               if (!(c->sb.features & (1ULL << BCH_FEATURE_REFLINK))) {
-                       c->disk_sb.sb->features[0] |=
-                               cpu_to_le64(1ULL << BCH_FEATURE_REFLINK);
-
-                       bch2_write_super(c);
-               }
-               mutex_unlock(&c->sb_lock);
-       }
+       bch2_check_set_feature(c, BCH_FEATURE_REFLINK);
 
        dst_end.offset += remap_sectors;
        src_end.offset += remap_sectors;
index 6544bbf18e704e6cda39e902b163793864b04ecc..cd1aa3891c2e46d64dff8725a2f97630ab7ee41e 100644 (file)
@@ -795,6 +795,17 @@ out:
        return ret;
 }
 
+void __bch2_check_set_feature(struct bch_fs *c, unsigned feat)
+{
+       mutex_lock(&c->sb_lock);
+       if (!(c->sb.features & (1ULL << feat))) {
+               c->disk_sb.sb->features[0] |= cpu_to_le64(1ULL << feat);
+
+               bch2_write_super(c);
+       }
+       mutex_unlock(&c->sb_lock);
+}
+
 /* BCH_SB_FIELD_journal: */
 
 static int u64_cmp(const void *_l, const void *_r)
index 31b8b8307ac3334c2d3f883727138cda788a7605..402ae563b3c70a1f7dff18988479a216d12b185a 100644 (file)
@@ -43,26 +43,6 @@ struct bch_sb_field_ops {
                                   struct bch_sb_field *);
 };
 
-static inline bool bch2_sb_test_feature(struct bch_sb *sb,
-                                       enum bch_sb_features f)
-{
-       unsigned w = f / 64;
-       unsigned b = f % 64;
-
-       return le64_to_cpu(sb->features[w]) & (1ULL << b);
-}
-
-static inline void bch2_sb_set_feature(struct bch_sb *sb,
-                                      enum bch_sb_features f)
-{
-       if (!bch2_sb_test_feature(sb, f)) {
-               unsigned w = f / 64;
-               unsigned b = f % 64;
-
-               le64_add_cpu(&sb->features[w], 1ULL << b);
-       }
-}
-
 static inline __le64 bch2_sb_magic(struct bch_fs *c)
 {
        __le64 ret;
@@ -90,6 +70,13 @@ const char *bch2_sb_validate(struct bch_sb_handle *);
 
 int bch2_read_super(const char *, struct bch_opts *, struct bch_sb_handle *);
 int bch2_write_super(struct bch_fs *);
+void __bch2_check_set_feature(struct bch_fs *, unsigned);
+
+static inline void bch2_check_set_feature(struct bch_fs *c, unsigned feat)
+{
+       if (!(c->sb.features & (1ULL << feat)))
+               __bch2_check_set_feature(c, feat);
+}
 
 /* BCH_SB_FIELD_journal: */