bcachefs: bch2_io_opts_fixups()

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>
This commit is contained in:
Kent Overstreet 2024-10-20 01:21:43 -04:00
parent 16de2c856a
commit eacb755568
6 changed files with 21 additions and 10 deletions

View 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;

View 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))

View 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)

View 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)

View 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);

View 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);