diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-11-29 21:47:42 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:08:32 +0300 |
commit | ba239c954e840875a912230439f28b4e4fbea8ff (patch) | |
tree | a46e408927d580bb1c75f1beb4a93b1d6fbca986 /fs/bcachefs | |
parent | 9ba68f6cdc79b0eab707bf8b50f418da05b6ff5e (diff) | |
download | linux-ba239c954e840875a912230439f28b4e4fbea8ff.tar.xz |
bcachefs: bch2_check_set_feature()
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>
Diffstat (limited to 'fs/bcachefs')
-rw-r--r-- | fs/bcachefs/io.c | 2 | ||||
-rw-r--r-- | fs/bcachefs/opts.c | 11 | ||||
-rw-r--r-- | fs/bcachefs/recovery.c | 6 | ||||
-rw-r--r-- | fs/bcachefs/reflink.c | 11 | ||||
-rw-r--r-- | fs/bcachefs/super-io.c | 11 | ||||
-rw-r--r-- | fs/bcachefs/super-io.h | 27 |
6 files changed, 23 insertions, 45 deletions
diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c index 5de554a883ef..6934a0339eb0 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -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)); diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c index 13a9a2fcd575..cbacd2f36799 100644 --- a/fs/bcachefs/opts.c +++ b/fs/bcachefs/opts.c @@ -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; } diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c index d4002b7fc917..e6b51131cff2 100644 --- a/fs/bcachefs/recovery.c +++ b/fs/bcachefs/recovery.c @@ -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; diff --git a/fs/bcachefs/reflink.c b/fs/bcachefs/reflink.c index 2812fa305c0e..53bd0e0ea058 100644 --- a/fs/bcachefs/reflink.c +++ b/fs/bcachefs/reflink.c @@ -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; diff --git a/fs/bcachefs/super-io.c b/fs/bcachefs/super-io.c index 6544bbf18e70..cd1aa3891c2e 100644 --- a/fs/bcachefs/super-io.c +++ b/fs/bcachefs/super-io.c @@ -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) diff --git a/fs/bcachefs/super-io.h b/fs/bcachefs/super-io.h index 31b8b8307ac3..402ae563b3c7 100644 --- a/fs/bcachefs/super-io.h +++ b/fs/bcachefs/super-io.h @@ -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: */ |