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 <[email protected]>
---
 fs/bcachefs/data_update.c |  4 ++--
 fs/bcachefs/extents.c     |  2 +-
 fs/bcachefs/inode.c       |  4 ++--
 fs/bcachefs/opts.c        |  5 ++++-
 fs/bcachefs/opts.h        | 12 ++++++++++--
 fs/bcachefs/rebalance.c   |  4 ++--
 6 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/fs/bcachefs/data_update.c b/fs/bcachefs/data_update.c
index 5ea432bc0052..a176e5439cbf 100644
--- a/fs/bcachefs/data_update.c
+++ b/fs/bcachefs/data_update.c
@@ -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;
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
index 33f611f13570..f0d9390250c4 100644
--- a/fs/bcachefs/extents.c
+++ b/fs/bcachefs/extents.c
@@ -1501,7 +1501,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))
diff --git a/fs/bcachefs/inode.c b/fs/bcachefs/inode.c
index 46310fcdd2b3..3af6029ea9b7 100644
--- a/fs/bcachefs/inode.c
+++ b/fs/bcachefs/inode.c
@@ -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)
diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c
index 6673cbd8bdb9..3fa8a85b008b 100644
--- a/fs/bcachefs/opts.c
+++ b/fs/bcachefs/opts.c
@@ -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)
diff --git a/fs/bcachefs/opts.h b/fs/bcachefs/opts.h
index 23dda014e331..dd27ef556611 100644
--- a/fs/bcachefs/opts.h
+++ b/fs/bcachefs/opts.h
@@ -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);
diff --git a/fs/bcachefs/rebalance.c b/fs/bcachefs/rebalance.c
index cd6647374353..2f93ae8781bb 100644
--- a/fs/bcachefs/rebalance.c
+++ b/fs/bcachefs/rebalance.c
@@ -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);
-- 
2.45.2


Reply via email to