summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2022-11-24 04:14:55 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:49 +0300
commit01ad673727b59664c9d12df4e5b6f5bad1ea2825 (patch)
treedb93047878a22efa13d8c91c3229639a5c4ebf79
parentf52dd1ae20ac8094eb881f816e7274d3f7910a84 (diff)
downloadlinux-01ad673727b59664c9d12df4e5b6f5bad1ea2825.tar.xz
bcachefs: bch2_inode_opts_get()
This improves io_opts() and makes it a non-inline function - it's big enough that it probably shouldn't be. Also, bch_io_opts no longer needs fields for whether options are defined, so we can slim it down a bit. We'd like to stop passing around the full bch_io_opts, but that'll be tricky because of bch2_rebalance_add_key(). Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/fs-io.c34
-rw-r--r--fs/bcachefs/inode.c8
-rw-r--r--fs/bcachefs/inode.h24
-rw-r--r--fs/bcachefs/move.c2
-rw-r--r--fs/bcachefs/opts.c17
-rw-r--r--fs/bcachefs/opts.h5
6 files changed, 39 insertions, 51 deletions
diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c
index 0bb8b39140ec..25094e0406da 100644
--- a/fs/bcachefs/fs-io.c
+++ b/fs/bcachefs/fs-io.c
@@ -1102,12 +1102,14 @@ void bch2_readahead(struct readahead_control *ractl)
{
struct bch_inode_info *inode = to_bch_ei(ractl->mapping->host);
struct bch_fs *c = inode->v.i_sb->s_fs_info;
- struct bch_io_opts opts = io_opts(c, &inode->ei_inode);
+ struct bch_io_opts opts;
struct btree_trans trans;
struct page *page;
struct readpages_iter readpages_iter;
int ret;
+ bch2_inode_opts_get(&opts, c, &inode->ei_inode);
+
ret = readpages_iter_init(&readpages_iter, ractl);
BUG_ON(ret);
@@ -1170,11 +1172,14 @@ static int bch2_read_single_page(struct page *page,
struct bch_inode_info *inode = to_bch_ei(mapping->host);
struct bch_fs *c = inode->v.i_sb->s_fs_info;
struct bch_read_bio *rbio;
+ struct bch_io_opts opts;
int ret;
DECLARE_COMPLETION_ONSTACK(done);
+ bch2_inode_opts_get(&opts, c, &inode->ei_inode);
+
rbio = rbio_init(bio_alloc_bioset(NULL, 1, REQ_OP_READ, GFP_NOFS, &c->bio_read),
- io_opts(c, &inode->ei_inode));
+ opts);
rbio->bio.bi_private = &done;
rbio->bio.bi_end_io = bch2_read_single_page_end_io;
@@ -1211,9 +1216,10 @@ struct bch_writepage_state {
static inline struct bch_writepage_state bch_writepage_state_init(struct bch_fs *c,
struct bch_inode_info *inode)
{
- return (struct bch_writepage_state) {
- .opts = io_opts(c, &inode->ei_inode)
- };
+ struct bch_writepage_state ret = { 0 };
+
+ bch2_inode_opts_get(&ret.opts, c, &inode->ei_inode);
+ return ret;
}
static void bch2_writepage_io_done(struct bch_write_op *op)
@@ -1879,7 +1885,7 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter)
struct file *file = req->ki_filp;
struct bch_inode_info *inode = file_bch_inode(file);
struct bch_fs *c = inode->v.i_sb->s_fs_info;
- struct bch_io_opts opts = io_opts(c, &inode->ei_inode);
+ struct bch_io_opts opts;
struct dio_read *dio;
struct bio *bio;
loff_t offset = req->ki_pos;
@@ -1887,6 +1893,8 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter)
size_t shorten;
ssize_t ret;
+ bch2_inode_opts_get(&opts, c, &inode->ei_inode);
+
if ((offset|iter->count) & (block_bytes(c) - 1))
return -EINVAL;
@@ -2224,11 +2232,14 @@ static __always_inline long bch2_dio_write_loop(struct dio_write *dio)
struct kiocb *req = dio->req;
struct address_space *mapping = dio->mapping;
struct bch_inode_info *inode = dio->inode;
+ struct bch_io_opts opts;
struct bio *bio = &dio->op.wbio.bio;
unsigned unaligned, iter_count;
bool sync = dio->sync, dropped_locks;
long ret;
+ bch2_inode_opts_get(&opts, c, &inode->ei_inode);
+
while (1) {
iter_count = dio->iter.count;
@@ -2276,7 +2287,7 @@ static __always_inline long bch2_dio_write_loop(struct dio_write *dio)
goto err;
}
- bch2_write_op_init(&dio->op, c, io_opts(c, &inode->ei_inode));
+ bch2_write_op_init(&dio->op, c, opts);
dio->op.end_io = sync
? NULL
: bch2_dio_write_loop_async;
@@ -3055,9 +3066,10 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
struct btree_trans trans;
struct btree_iter iter;
struct bpos end_pos = POS(inode->v.i_ino, end_sector);
- unsigned replicas = io_opts(c, &inode->ei_inode).data_replicas;
+ struct bch_io_opts opts;
int ret = 0;
+ bch2_inode_opts_get(&opts, c, &inode->ei_inode);
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 512);
bch2_trans_iter_init(&trans, &iter, BTREE_ID_extents,
@@ -3088,7 +3100,7 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
/* already reserved */
if (k.k->type == KEY_TYPE_reservation &&
- bkey_s_c_to_reservation(k).v->nr_replicas >= replicas) {
+ bkey_s_c_to_reservation(k).v->nr_replicas >= opts.data_replicas) {
bch2_btree_iter_advance(&iter);
continue;
}
@@ -3118,10 +3130,10 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
goto bkey_err;
}
- if (reservation.v.nr_replicas < replicas ||
+ if (reservation.v.nr_replicas < opts.data_replicas ||
bch2_bkey_sectors_compressed(k)) {
ret = bch2_disk_reservation_get(c, &disk_res, sectors,
- replicas, 0);
+ opts.data_replicas, 0);
if (unlikely(ret))
goto bkey_err;
diff --git a/fs/bcachefs/inode.c b/fs/bcachefs/inode.c
index 6e7ba2e6fe33..9eeabe70aec1 100644
--- a/fs/bcachefs/inode.c
+++ b/fs/bcachefs/inode.c
@@ -768,3 +768,11 @@ struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *inode)
#undef x
return ret;
}
+
+void bch2_inode_opts_get(struct bch_io_opts *opts, struct bch_fs *c,
+ struct bch_inode_unpacked *inode)
+{
+#define x(_name, _bits) opts->_name = inode_opt_get(c, inode, _name);
+ BCH_INODE_OPTS()
+#undef x
+}
diff --git a/fs/bcachefs/inode.h b/fs/bcachefs/inode.h
index 27744f78ae96..da78ed023a30 100644
--- a/fs/bcachefs/inode.h
+++ b/fs/bcachefs/inode.h
@@ -98,17 +98,8 @@ int bch2_inode_find_by_inum_trans(struct btree_trans *, subvol_inum,
int bch2_inode_find_by_inum(struct bch_fs *, subvol_inum,
struct bch_inode_unpacked *);
-static inline struct bch_io_opts bch2_inode_opts_get(struct bch_inode_unpacked *inode)
-{
- struct bch_io_opts ret = { 0 };
-
-#define x(_name, _bits) \
- if (inode->bi_##_name) \
- opt_set(ret, _name, inode->bi_##_name - 1);
- BCH_INODE_OPTS()
-#undef x
- return ret;
-}
+#define inode_opt_get(_c, _inode, _name) \
+ ((_inode)->bi_##_name ? (_inode)->bi_##_name - 1 : (_c)->opts._name)
static inline void bch2_inode_opt_set(struct bch_inode_unpacked *inode,
enum inode_opt_id id, u64 v)
@@ -139,15 +130,6 @@ static inline u64 bch2_inode_opt_get(struct bch_inode_unpacked *inode,
}
}
-static inline struct bch_io_opts
-io_opts(struct bch_fs *c, struct bch_inode_unpacked *inode)
-{
- struct bch_io_opts opts = bch2_opts_to_inode_opts(c->opts);
-
- bch2_io_opts_apply(&opts, bch2_inode_opts_get(inode));
- return opts;
-}
-
static inline u8 mode_to_type(umode_t mode)
{
return (mode >> 12) & 15;
@@ -188,5 +170,7 @@ int bch2_inode_nlink_inc(struct bch_inode_unpacked *);
void bch2_inode_nlink_dec(struct btree_trans *, struct bch_inode_unpacked *);
struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *);
+void bch2_inode_opts_get(struct bch_io_opts *, struct bch_fs *,
+ struct bch_inode_unpacked *);
#endif /* _BCACHEFS_INODE_H */
diff --git a/fs/bcachefs/move.c b/fs/bcachefs/move.c
index 848a415b6797..65c3af1b2e11 100644
--- a/fs/bcachefs/move.c
+++ b/fs/bcachefs/move.c
@@ -465,7 +465,7 @@ static int __bch2_move_data(struct moving_context *ctxt,
continue;
if (!ret)
- bch2_io_opts_apply(&io_opts, bch2_inode_opts_get(&inode));
+ bch2_inode_opts_get(&io_opts, c, &inode);
cur_inum = k.k->p.inode;
}
diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c
index 9c49d543b062..04e2989cd6b3 100644
--- a/fs/bcachefs/opts.c
+++ b/fs/bcachefs/opts.c
@@ -531,22 +531,11 @@ void bch2_opt_set_sb(struct bch_fs *c, const struct bch_option *opt, u64 v)
struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts src)
{
- struct bch_io_opts ret = { 0 };
-#define x(_name, _bits) \
- if (opt_defined(src, _name)) \
- opt_set(ret, _name, src._name);
- BCH_INODE_OPTS()
-#undef x
- return ret;
-}
-
-void bch2_io_opts_apply(struct bch_io_opts *dst, struct bch_io_opts src)
-{
-#define x(_name, _bits) \
- if (opt_defined(src, _name)) \
- opt_set(*dst, _name, src._name);
+ return (struct bch_io_opts) {
+#define x(_name, _bits) ._name = src._name,
BCH_INODE_OPTS()
#undef x
+ };
}
bool bch2_opt_is_inode_opt(enum bch_opt_id id)
diff --git a/fs/bcachefs/opts.h b/fs/bcachefs/opts.h
index a32a7ab73bd5..c6025172f32e 100644
--- a/fs/bcachefs/opts.h
+++ b/fs/bcachefs/opts.h
@@ -503,17 +503,12 @@ int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
/* inode opts: */
struct bch_io_opts {
-#define x(_name, _bits) unsigned _name##_defined:1;
- BCH_INODE_OPTS()
-#undef x
-
#define x(_name, _bits) u##_bits _name;
BCH_INODE_OPTS()
#undef x
};
struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
-void bch2_io_opts_apply(struct bch_io_opts *, struct bch_io_opts);
bool bch2_opt_is_inode_opt(enum bch_opt_id);
#endif /* _BCACHEFS_OPTS_H */