summaryrefslogtreecommitdiff
path: root/fs/bcachefs/fs-io.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-03-25 15:10:15 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:18 -0400
commit424eb881300467a21a108d04c9dd08a6f8c007dc (patch)
tree760482adf8b16aa98b03932d5fabaab8e514c998 /fs/bcachefs/fs-io.c
parent5df4be3f62c9bde73db801504b3db2693b28328c (diff)
downloadlwn-424eb881300467a21a108d04c9dd08a6f8c007dc.tar.gz
lwn-424eb881300467a21a108d04c9dd08a6f8c007dc.zip
bcachefs: Only get btree iters from btree transactions
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/fs-io.c')
-rw-r--r--fs/bcachefs/fs-io.c59
1 files changed, 38 insertions, 21 deletions
diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c
index 251c811abeda..efc189c02db7 100644
--- a/fs/bcachefs/fs-io.c
+++ b/fs/bcachefs/fs-io.c
@@ -997,7 +997,8 @@ 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);
- struct btree_iter iter;
+ struct btree_trans trans;
+ struct btree_iter *iter;
struct page *page;
struct readpages_iter readpages_iter;
int ret;
@@ -1005,8 +1006,10 @@ void bch2_readahead(struct readahead_control *ractl)
ret = readpages_iter_init(&readpages_iter, ractl);
BUG_ON(ret);
- bch2_btree_iter_init(&iter, c, BTREE_ID_EXTENTS, POS_MIN,
- BTREE_ITER_SLOTS);
+ bch2_trans_init(&trans, c);
+
+ iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, POS_MIN,
+ BTREE_ITER_SLOTS);
bch2_pagecache_add_get(&inode->ei_pagecache_lock);
@@ -1027,26 +1030,33 @@ void bch2_readahead(struct readahead_control *ractl)
rbio->bio.bi_end_io = bch2_readpages_end_io;
__bio_add_page(&rbio->bio, page, PAGE_SIZE, 0);
- bchfs_read(c, &iter, rbio, inode->v.i_ino, &readpages_iter);
+ bchfs_read(c, iter, rbio, inode->v.i_ino, &readpages_iter);
}
bch2_pagecache_add_put(&inode->ei_pagecache_lock);
+
+ bch2_trans_exit(&trans);
kfree(readpages_iter.pages);
}
static void __bchfs_readpage(struct bch_fs *c, struct bch_read_bio *rbio,
u64 inum, struct page *page)
{
- struct btree_iter iter;
+ struct btree_trans trans;
+ struct btree_iter *iter;
page_state_init_for_read(page);
rbio->bio.bi_opf = REQ_OP_READ|REQ_SYNC;
bio_add_page_contig(&rbio->bio, page);
- bch2_btree_iter_init(&iter, c, BTREE_ID_EXTENTS, POS_MIN,
- BTREE_ITER_SLOTS);
- bchfs_read(c, &iter, rbio, inum, NULL);
+ bch2_trans_init(&trans, c);
+ iter = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, POS_MIN,
+ BTREE_ITER_SLOTS);
+
+ bchfs_read(c, iter, rbio, inum, NULL);
+
+ bch2_trans_exit(&trans);
}
static void bch2_read_single_page_end_io(struct bio *bio)
@@ -2111,7 +2121,7 @@ static int __bch2_fpunch(struct bch_fs *c, struct bch_inode_info *inode,
if (ret)
break;
- bch2_btree_iter_cond_resched(iter);
+ bch2_trans_cond_resched(&trans);
}
bch2_trans_exit(&trans);
@@ -2123,13 +2133,14 @@ static inline int range_has_data(struct bch_fs *c,
struct bpos start,
struct bpos end)
{
-
- struct btree_iter iter;
+ struct btree_trans trans;
+ struct btree_iter *iter;
struct bkey_s_c k;
int ret = 0;
- for_each_btree_key(&iter, c, BTREE_ID_EXTENTS,
- start, 0, k) {
+ bch2_trans_init(&trans, c);
+
+ for_each_btree_key(&trans, iter, BTREE_ID_EXTENTS, start, 0, k) {
if (bkey_cmp(bkey_start_pos(k.k), end) >= 0)
break;
@@ -2139,7 +2150,7 @@ static inline int range_has_data(struct bch_fs *c,
}
}
- return bch2_btree_iter_unlock(&iter) ?: ret;
+ return bch2_trans_exit(&trans) ?: ret;
}
static int __bch2_truncate_page(struct bch_inode_info *inode,
@@ -2464,7 +2475,7 @@ btree_iter_err:
* pointers... which isn't a _super_ serious problem...
*/
- bch2_btree_iter_cond_resched(src);
+ bch2_trans_cond_resched(&trans);
}
bch2_trans_unlock(&trans);
@@ -2709,7 +2720,8 @@ static loff_t bch2_seek_data(struct file *file, u64 offset)
{
struct bch_inode_info *inode = file_bch_inode(file);
struct bch_fs *c = inode->v.i_sb->s_fs_info;
- struct btree_iter iter;
+ struct btree_trans trans;
+ struct btree_iter *iter;
struct bkey_s_c k;
u64 isize, next_data = MAX_LFS_FILESIZE;
int ret;
@@ -2718,7 +2730,9 @@ static loff_t bch2_seek_data(struct file *file, u64 offset)
if (offset >= isize)
return -ENXIO;
- for_each_btree_key(&iter, c, BTREE_ID_EXTENTS,
+ bch2_trans_init(&trans, c);
+
+ for_each_btree_key(&trans, iter, BTREE_ID_EXTENTS,
POS(inode->v.i_ino, offset >> 9), 0, k) {
if (k.k->p.inode != inode->v.i_ino) {
break;
@@ -2729,7 +2743,7 @@ static loff_t bch2_seek_data(struct file *file, u64 offset)
break;
}
- ret = bch2_btree_iter_unlock(&iter);
+ ret = bch2_trans_exit(&trans);
if (ret)
return ret;
@@ -2779,7 +2793,8 @@ static loff_t bch2_seek_hole(struct file *file, u64 offset)
{
struct bch_inode_info *inode = file_bch_inode(file);
struct bch_fs *c = inode->v.i_sb->s_fs_info;
- struct btree_iter iter;
+ struct btree_trans trans;
+ struct btree_iter *iter;
struct bkey_s_c k;
u64 isize, next_hole = MAX_LFS_FILESIZE;
int ret;
@@ -2788,7 +2803,9 @@ static loff_t bch2_seek_hole(struct file *file, u64 offset)
if (offset >= isize)
return -ENXIO;
- for_each_btree_key(&iter, c, BTREE_ID_EXTENTS,
+ bch2_trans_init(&trans, c);
+
+ for_each_btree_key(&trans, iter, BTREE_ID_EXTENTS,
POS(inode->v.i_ino, offset >> 9),
BTREE_ITER_SLOTS, k) {
if (k.k->p.inode != inode->v.i_ino) {
@@ -2807,7 +2824,7 @@ static loff_t bch2_seek_hole(struct file *file, u64 offset)
}
}
- ret = bch2_btree_iter_unlock(&iter);
+ ret = bch2_trans_exit(&trans);
if (ret)
return ret;