bcachefs: bch2_io_opts_fixups()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 20 Oct 2024 05:21:43 +0000 (01:21 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:15 +0000 (01:36 -0500)
Centralize some io path option fixups - they weren't always being
applied correctly:

- background_compression uses compression if unset
- background_target uses foreground_target if unset
- nocow disables most fancy io path options

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/data_update.c
fs/bcachefs/extents.c
fs/bcachefs/inode.c
fs/bcachefs/opts.c
fs/bcachefs/opts.h
fs/bcachefs/rebalance.c

index 5ea432bc00523e3bfdc322c0d57913f4485b4efa..a176e5439cbfcd7b0838933c7400d9262328b10a 100644 (file)
@@ -535,7 +535,7 @@ void bch2_data_update_opts_to_text(struct printbuf *out, struct bch_fs *c,
        prt_newline(out);
 
        prt_str(out, "compression:\t");
-       bch2_compression_opt_to_text(out, background_compression(*io_opts));
+       bch2_compression_opt_to_text(out, io_opts->background_compression);
        prt_newline(out);
 
        prt_str(out, "opts.replicas:\t");
@@ -647,7 +647,7 @@ int bch2_data_update_init(struct btree_trans *trans,
                BCH_WRITE_DATA_ENCODED|
                BCH_WRITE_MOVE|
                m->data_opts.write_flags;
-       m->op.compression_opt   = background_compression(io_opts);
+       m->op.compression_opt   = io_opts.background_compression;
        m->op.watermark         = m->data_opts.btree_insert_flags & BCH_WATERMARK_MASK;
 
        unsigned durability_have = 0, durability_removing = 0;
index 85b98c782e1b67a5b4c064df02e613ce6a0fd378..45a67daf0d642de30d430e400b9663aa7e389038 100644 (file)
@@ -1504,7 +1504,7 @@ int bch2_bkey_set_needs_rebalance(struct bch_fs *c, struct bkey_i *_k,
        struct bkey_s k = bkey_i_to_s(_k);
        struct bch_extent_rebalance *r;
        unsigned target = opts->background_target;
-       unsigned compression = background_compression(*opts);
+       unsigned compression = opts->background_compression;
        bool needs_rebalance;
 
        if (!bkey_extent_is_direct_data(k.k))
index 43653cf050e9eb79f897751bf575fc270c9f4223..fbdd11802bdf2e2752c913ce3c6c19708cea3f5d 100644 (file)
@@ -14,6 +14,7 @@
 #include "extent_update.h"
 #include "fs.h"
 #include "inode.h"
+#include "opts.h"
 #include "str_hash.h"
 #include "snapshot.h"
 #include "subvolume.h"
@@ -1145,8 +1146,7 @@ void bch2_inode_opts_get(struct bch_io_opts *opts, struct bch_fs *c,
        BCH_INODE_OPTS()
 #undef x
 
-       if (opts->nocow)
-               opts->compression = opts->background_compression = opts->data_checksum = opts->erasure_code = 0;
+       bch2_io_opts_fixups(opts);
 }
 
 int bch2_inum_opts_get(struct btree_trans *trans, subvol_inum inum, struct bch_io_opts *opts)
index 0e2ee262fbd4b4d158f5fc66d481cbeb634f8204..1f5843284e9e60a7236a3b6ecb218c2c0baa0347 100644 (file)
@@ -710,11 +710,14 @@ void bch2_opt_set_sb(struct bch_fs *c, struct bch_dev *ca,
 
 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts src)
 {
-       return (struct bch_io_opts) {
+       struct bch_io_opts opts = {
 #define x(_name, _bits)        ._name = src._name,
        BCH_INODE_OPTS()
 #undef x
        };
+
+       bch2_io_opts_fixups(&opts);
+       return opts;
 }
 
 bool bch2_opt_is_inode_opt(enum bch_opt_id id)
index 23dda014e331b132d21511684cd6ba2e0e55ea82..dd27ef5566117adf51ae507823cfa32949507870 100644 (file)
@@ -626,9 +626,17 @@ struct bch_io_opts {
 #undef x
 };
 
-static inline unsigned background_compression(struct bch_io_opts opts)
+static inline void bch2_io_opts_fixups(struct bch_io_opts *opts)
 {
-       return opts.background_compression ?: opts.compression;
+       if (!opts->background_target)
+               opts->background_target = opts->foreground_target;
+       if (!opts->background_compression)
+               opts->background_compression = opts->compression;
+       if (opts->nocow) {
+               opts->compression = opts->background_compression = 0;
+               opts->data_checksum = 0;
+               opts->erasure_code = 0;
+       }
 }
 
 struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
index cd6647374353fb167dfb075a58350f33429f6b9d..2f93ae8781bb04922820ca71ce0e18417464d0d6 100644 (file)
@@ -257,12 +257,12 @@ static bool rebalance_pred(struct bch_fs *c, void *arg,
 
        if (k.k->p.inode) {
                target          = io_opts->background_target;
-               compression     = background_compression(*io_opts);
+               compression     = io_opts->background_compression;
        } else {
                const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k);
 
                target          = r ? r->target : io_opts->background_target;
-               compression     = r ? r->compression : background_compression(*io_opts);
+               compression     = r ? r->compression : io_opts->background_compression;
        }
 
        data_opts->rewrite_ptrs         = bch2_bkey_ptrs_need_rebalance(c, k, target, compression);