Commit 01ad6737 authored by Kent Overstreet's avatar Kent Overstreet

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: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent f52dd1ae
...@@ -1102,12 +1102,14 @@ void bch2_readahead(struct readahead_control *ractl) ...@@ -1102,12 +1102,14 @@ void bch2_readahead(struct readahead_control *ractl)
{ {
struct bch_inode_info *inode = to_bch_ei(ractl->mapping->host); struct bch_inode_info *inode = to_bch_ei(ractl->mapping->host);
struct bch_fs *c = inode->v.i_sb->s_fs_info; 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 btree_trans trans;
struct page *page; struct page *page;
struct readpages_iter readpages_iter; struct readpages_iter readpages_iter;
int ret; int ret;
bch2_inode_opts_get(&opts, c, &inode->ei_inode);
ret = readpages_iter_init(&readpages_iter, ractl); ret = readpages_iter_init(&readpages_iter, ractl);
BUG_ON(ret); BUG_ON(ret);
...@@ -1170,11 +1172,14 @@ static int bch2_read_single_page(struct page *page, ...@@ -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_inode_info *inode = to_bch_ei(mapping->host);
struct bch_fs *c = inode->v.i_sb->s_fs_info; struct bch_fs *c = inode->v.i_sb->s_fs_info;
struct bch_read_bio *rbio; struct bch_read_bio *rbio;
struct bch_io_opts opts;
int ret; int ret;
DECLARE_COMPLETION_ONSTACK(done); 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), 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_private = &done;
rbio->bio.bi_end_io = bch2_read_single_page_end_io; rbio->bio.bi_end_io = bch2_read_single_page_end_io;
...@@ -1211,9 +1216,10 @@ struct bch_writepage_state { ...@@ -1211,9 +1216,10 @@ struct bch_writepage_state {
static inline struct bch_writepage_state bch_writepage_state_init(struct bch_fs *c, static inline struct bch_writepage_state bch_writepage_state_init(struct bch_fs *c,
struct bch_inode_info *inode) struct bch_inode_info *inode)
{ {
return (struct bch_writepage_state) { struct bch_writepage_state ret = { 0 };
.opts = io_opts(c, &inode->ei_inode)
}; bch2_inode_opts_get(&ret.opts, c, &inode->ei_inode);
return ret;
} }
static void bch2_writepage_io_done(struct bch_write_op *op) 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) ...@@ -1879,7 +1885,7 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter)
struct file *file = req->ki_filp; struct file *file = req->ki_filp;
struct bch_inode_info *inode = file_bch_inode(file); struct bch_inode_info *inode = file_bch_inode(file);
struct bch_fs *c = inode->v.i_sb->s_fs_info; 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 dio_read *dio;
struct bio *bio; struct bio *bio;
loff_t offset = req->ki_pos; loff_t offset = req->ki_pos;
...@@ -1887,6 +1893,8 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter) ...@@ -1887,6 +1893,8 @@ static int bch2_direct_IO_read(struct kiocb *req, struct iov_iter *iter)
size_t shorten; size_t shorten;
ssize_t ret; ssize_t ret;
bch2_inode_opts_get(&opts, c, &inode->ei_inode);
if ((offset|iter->count) & (block_bytes(c) - 1)) if ((offset|iter->count) & (block_bytes(c) - 1))
return -EINVAL; return -EINVAL;
...@@ -2224,11 +2232,14 @@ static __always_inline long bch2_dio_write_loop(struct dio_write *dio) ...@@ -2224,11 +2232,14 @@ static __always_inline long bch2_dio_write_loop(struct dio_write *dio)
struct kiocb *req = dio->req; struct kiocb *req = dio->req;
struct address_space *mapping = dio->mapping; struct address_space *mapping = dio->mapping;
struct bch_inode_info *inode = dio->inode; struct bch_inode_info *inode = dio->inode;
struct bch_io_opts opts;
struct bio *bio = &dio->op.wbio.bio; struct bio *bio = &dio->op.wbio.bio;
unsigned unaligned, iter_count; unsigned unaligned, iter_count;
bool sync = dio->sync, dropped_locks; bool sync = dio->sync, dropped_locks;
long ret; long ret;
bch2_inode_opts_get(&opts, c, &inode->ei_inode);
while (1) { while (1) {
iter_count = dio->iter.count; iter_count = dio->iter.count;
...@@ -2276,7 +2287,7 @@ static __always_inline long bch2_dio_write_loop(struct dio_write *dio) ...@@ -2276,7 +2287,7 @@ static __always_inline long bch2_dio_write_loop(struct dio_write *dio)
goto err; 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 dio->op.end_io = sync
? NULL ? NULL
: bch2_dio_write_loop_async; : bch2_dio_write_loop_async;
...@@ -3055,9 +3066,10 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode, ...@@ -3055,9 +3066,10 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
struct btree_trans trans; struct btree_trans trans;
struct btree_iter iter; struct btree_iter iter;
struct bpos end_pos = POS(inode->v.i_ino, end_sector); 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; int ret = 0;
bch2_inode_opts_get(&opts, c, &inode->ei_inode);
bch2_trans_init(&trans, c, BTREE_ITER_MAX, 512); bch2_trans_init(&trans, c, BTREE_ITER_MAX, 512);
bch2_trans_iter_init(&trans, &iter, BTREE_ID_extents, bch2_trans_iter_init(&trans, &iter, BTREE_ID_extents,
...@@ -3088,7 +3100,7 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode, ...@@ -3088,7 +3100,7 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
/* already reserved */ /* already reserved */
if (k.k->type == KEY_TYPE_reservation && 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); bch2_btree_iter_advance(&iter);
continue; continue;
} }
...@@ -3118,10 +3130,10 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode, ...@@ -3118,10 +3130,10 @@ static int __bchfs_fallocate(struct bch_inode_info *inode, int mode,
goto bkey_err; goto bkey_err;
} }
if (reservation.v.nr_replicas < replicas || if (reservation.v.nr_replicas < opts.data_replicas ||
bch2_bkey_sectors_compressed(k)) { bch2_bkey_sectors_compressed(k)) {
ret = bch2_disk_reservation_get(c, &disk_res, sectors, ret = bch2_disk_reservation_get(c, &disk_res, sectors,
replicas, 0); opts.data_replicas, 0);
if (unlikely(ret)) if (unlikely(ret))
goto bkey_err; goto bkey_err;
......
...@@ -768,3 +768,11 @@ struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *inode) ...@@ -768,3 +768,11 @@ struct bch_opts bch2_inode_opts_to_opts(struct bch_inode_unpacked *inode)
#undef x #undef x
return ret; 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
}
...@@ -98,17 +98,8 @@ int bch2_inode_find_by_inum_trans(struct btree_trans *, subvol_inum, ...@@ -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, int bch2_inode_find_by_inum(struct bch_fs *, subvol_inum,
struct bch_inode_unpacked *); struct bch_inode_unpacked *);
static inline struct bch_io_opts bch2_inode_opts_get(struct bch_inode_unpacked *inode) #define inode_opt_get(_c, _inode, _name) \
{ ((_inode)->bi_##_name ? (_inode)->bi_##_name - 1 : (_c)->opts._name)
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;
}
static inline void bch2_inode_opt_set(struct bch_inode_unpacked *inode, static inline void bch2_inode_opt_set(struct bch_inode_unpacked *inode,
enum inode_opt_id id, u64 v) enum inode_opt_id id, u64 v)
...@@ -139,15 +130,6 @@ static inline u64 bch2_inode_opt_get(struct bch_inode_unpacked *inode, ...@@ -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) static inline u8 mode_to_type(umode_t mode)
{ {
return (mode >> 12) & 15; return (mode >> 12) & 15;
...@@ -188,5 +170,7 @@ int bch2_inode_nlink_inc(struct bch_inode_unpacked *); ...@@ -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 *); void bch2_inode_nlink_dec(struct btree_trans *, struct bch_inode_unpacked *);
struct bch_opts bch2_inode_opts_to_opts(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 */ #endif /* _BCACHEFS_INODE_H */
...@@ -465,7 +465,7 @@ static int __bch2_move_data(struct moving_context *ctxt, ...@@ -465,7 +465,7 @@ static int __bch2_move_data(struct moving_context *ctxt,
continue; continue;
if (!ret) 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; cur_inum = k.k->p.inode;
} }
......
...@@ -531,22 +531,11 @@ void bch2_opt_set_sb(struct bch_fs *c, const struct bch_option *opt, u64 v) ...@@ -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 bch2_opts_to_inode_opts(struct bch_opts src)
{ {
struct bch_io_opts ret = { 0 }; return (struct bch_io_opts) {
#define x(_name, _bits) \ #define x(_name, _bits) ._name = src._name,
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);
BCH_INODE_OPTS() BCH_INODE_OPTS()
#undef x #undef x
};
} }
bool bch2_opt_is_inode_opt(enum bch_opt_id id) bool bch2_opt_is_inode_opt(enum bch_opt_id id)
......
...@@ -503,17 +503,12 @@ int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *); ...@@ -503,17 +503,12 @@ int bch2_parse_mount_opts(struct bch_fs *, struct bch_opts *, char *);
/* inode opts: */ /* inode opts: */
struct bch_io_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; #define x(_name, _bits) u##_bits _name;
BCH_INODE_OPTS() BCH_INODE_OPTS()
#undef x #undef x
}; };
struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts); 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); bool bch2_opt_is_inode_opt(enum bch_opt_id);
#endif /* _BCACHEFS_OPTS_H */ #endif /* _BCACHEFS_OPTS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment