Commit eacb7555 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

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: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 16de2c85
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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))
+2 −2
Original line number Diff line number Diff line
@@ -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)
+4 −1
Original line number Diff line number Diff line
@@ -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)
+10 −2
Original line number Diff line number Diff line
@@ -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);
Loading