Skip to content

Commit 722c82a

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: pass the btrfs_bio_ctrl to submit_one_bio
submit_one_bio always works on the bio and compression flags from a btrfs_bio_ctrl structure. Pass the explicitly and clean up the calling conventions by handling a NULL bio in submit_one_bio, and using the btrfs_bio_ctrl to pass the mirror number as well. Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 9845e5d commit 722c82a

File tree

1 file changed

+39
-46
lines changed

1 file changed

+39
-46
lines changed

fs/btrfs/extent_io.c

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ struct tree_entry {
144144
*/
145145
struct btrfs_bio_ctrl {
146146
struct bio *bio;
147+
int mirror_num;
147148
enum btrfs_compression_type compress_type;
148149
u32 len_to_stripe_boundary;
149150
u32 len_to_oe_boundary;
@@ -178,10 +179,18 @@ static int add_extent_changeset(struct extent_state *state, u32 bits,
178179
return ret;
179180
}
180181

181-
static void submit_one_bio(struct bio *bio, int mirror_num,
182-
enum btrfs_compression_type compress_type)
182+
static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
183183
{
184-
struct inode *inode = bio_first_page_all(bio)->mapping->host;
184+
struct bio *bio;
185+
struct inode *inode;
186+
int mirror_num;
187+
188+
if (!bio_ctrl->bio)
189+
return;
190+
191+
bio = bio_ctrl->bio;
192+
inode = bio_first_page_all(bio)->mapping->host;
193+
mirror_num = bio_ctrl->mirror_num;
185194

186195
/* Caller should ensure the bio has at least some range added */
187196
ASSERT(bio->bi_iter.bi_size);
@@ -191,14 +200,11 @@ static void submit_one_bio(struct bio *bio, int mirror_num,
191200
else if (btrfs_op(bio) == BTRFS_MAP_WRITE)
192201
btrfs_submit_data_write_bio(inode, bio, mirror_num);
193202
else
194-
btrfs_submit_data_read_bio(inode, bio, mirror_num, compress_type);
203+
btrfs_submit_data_read_bio(inode, bio, mirror_num,
204+
bio_ctrl->compress_type);
195205

196-
/*
197-
* Above submission hooks will handle the error by ending the bio,
198-
* which will do the cleanup properly. So here we should not return
199-
* any error, or the caller of submit_extent_page() will do cleanup
200-
* again, causing problems.
201-
*/
206+
/* The bio is owned by the bi_end_io handler now */
207+
bio_ctrl->bio = NULL;
202208
}
203209

204210
/*
@@ -215,12 +221,11 @@ static void submit_write_bio(struct extent_page_data *epd, int ret)
215221
ASSERT(ret < 0);
216222
bio->bi_status = errno_to_blk_status(ret);
217223
bio_endio(bio);
224+
/* The bio is owned by the bi_end_io handler now */
225+
epd->bio_ctrl.bio = NULL;
218226
} else {
219-
submit_one_bio(bio, 0, 0);
227+
submit_one_bio(&epd->bio_ctrl);
220228
}
221-
222-
/* The bio is owned by the bi_end_io handler now */
223-
epd->bio_ctrl.bio = NULL;
224229
}
225230

226231
int __init extent_state_cache_init(void)
@@ -3410,7 +3415,6 @@ static int submit_extent_page(unsigned int opf,
34103415
struct page *page, u64 disk_bytenr,
34113416
size_t size, unsigned long pg_offset,
34123417
bio_end_io_t end_io_func,
3413-
int mirror_num,
34143418
enum btrfs_compression_type compress_type,
34153419
bool force_bio_submit)
34163420
{
@@ -3422,10 +3426,8 @@ static int submit_extent_page(unsigned int opf,
34223426

34233427
ASSERT(pg_offset < PAGE_SIZE && size <= PAGE_SIZE &&
34243428
pg_offset + size <= PAGE_SIZE);
3425-
if (force_bio_submit && bio_ctrl->bio) {
3426-
submit_one_bio(bio_ctrl->bio, mirror_num, bio_ctrl->compress_type);
3427-
bio_ctrl->bio = NULL;
3428-
}
3429+
if (force_bio_submit)
3430+
submit_one_bio(bio_ctrl);
34293431

34303432
while (cur < pg_offset + size) {
34313433
u32 offset = cur - pg_offset;
@@ -3465,8 +3467,7 @@ static int submit_extent_page(unsigned int opf,
34653467
if (added < size - offset) {
34663468
/* The bio should contain some page(s) */
34673469
ASSERT(bio_ctrl->bio->bi_iter.bi_size);
3468-
submit_one_bio(bio_ctrl->bio, mirror_num, bio_ctrl->compress_type);
3469-
bio_ctrl->bio = NULL;
3470+
submit_one_bio(bio_ctrl);
34703471
}
34713472
cur += added;
34723473
}
@@ -3743,10 +3744,8 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached,
37433744

37443745
ret = submit_extent_page(REQ_OP_READ | read_flags, NULL,
37453746
bio_ctrl, page, disk_bytenr, iosize,
3746-
pg_offset,
3747-
end_bio_extent_readpage, 0,
3748-
this_bio_flag,
3749-
force_bio_submit);
3747+
pg_offset, end_bio_extent_readpage,
3748+
this_bio_flag, force_bio_submit);
37503749
if (ret) {
37513750
/*
37523751
* We have to unlock the remaining range, or the page
@@ -3779,8 +3778,7 @@ int btrfs_read_folio(struct file *file, struct folio *folio)
37793778
* If btrfs_do_readpage() failed we will want to submit the assembled
37803779
* bio to do the cleanup.
37813780
*/
3782-
if (bio_ctrl.bio)
3783-
submit_one_bio(bio_ctrl.bio, 0, bio_ctrl.compress_type);
3781+
submit_one_bio(&bio_ctrl);
37843782
return ret;
37853783
}
37863784

@@ -4063,7 +4061,7 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
40634061
disk_bytenr, iosize,
40644062
cur - page_offset(page),
40654063
end_bio_extent_writepage,
4066-
0, 0, false);
4064+
0, false);
40674065
if (ret) {
40684066
has_error = true;
40694067
if (!saved_ret)
@@ -4556,7 +4554,7 @@ static int write_one_subpage_eb(struct extent_buffer *eb,
45564554
ret = submit_extent_page(REQ_OP_WRITE | write_flags, wbc,
45574555
&epd->bio_ctrl, page, eb->start, eb->len,
45584556
eb->start - page_offset(page),
4559-
end_bio_subpage_eb_writepage, 0, 0, false);
4557+
end_bio_subpage_eb_writepage, 0, false);
45604558
if (ret) {
45614559
btrfs_subpage_clear_writeback(fs_info, page, eb->start, eb->len);
45624560
set_btree_ioerr(page, eb);
@@ -4597,7 +4595,7 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
45974595
&epd->bio_ctrl, p, disk_bytenr,
45984596
PAGE_SIZE, 0,
45994597
end_bio_extent_buffer_writepage,
4600-
0, 0, false);
4598+
0, false);
46014599
if (ret) {
46024600
set_btree_ioerr(p, eb);
46034601
if (PageWriteback(p))
@@ -5209,9 +5207,7 @@ void extent_readahead(struct readahead_control *rac)
52095207

52105208
if (em_cached)
52115209
free_extent_map(em_cached);
5212-
5213-
if (bio_ctrl.bio)
5214-
submit_one_bio(bio_ctrl.bio, 0, bio_ctrl.compress_type);
5210+
submit_one_bio(&bio_ctrl);
52155211
}
52165212

52175213
/*
@@ -6545,7 +6541,9 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait,
65456541
struct btrfs_fs_info *fs_info = eb->fs_info;
65466542
struct extent_io_tree *io_tree;
65476543
struct page *page = eb->pages[0];
6548-
struct btrfs_bio_ctrl bio_ctrl = { 0 };
6544+
struct btrfs_bio_ctrl bio_ctrl = {
6545+
.mirror_num = mirror_num,
6546+
};
65496547
int ret = 0;
65506548

65516549
ASSERT(!test_bit(EXTENT_BUFFER_UNMAPPED, &eb->bflags));
@@ -6580,8 +6578,7 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait,
65806578
ret = submit_extent_page(REQ_OP_READ, NULL, &bio_ctrl,
65816579
page, eb->start, eb->len,
65826580
eb->start - page_offset(page),
6583-
end_bio_extent_readpage, mirror_num, 0,
6584-
true);
6581+
end_bio_extent_readpage, 0, true);
65856582
if (ret) {
65866583
/*
65876584
* In the endio function, if we hit something wrong we will
@@ -6590,10 +6587,7 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait,
65906587
*/
65916588
atomic_dec(&eb->io_pages);
65926589
}
6593-
if (bio_ctrl.bio) {
6594-
submit_one_bio(bio_ctrl.bio, mirror_num, 0);
6595-
bio_ctrl.bio = NULL;
6596-
}
6590+
submit_one_bio(&bio_ctrl);
65976591
if (ret || wait != WAIT_COMPLETE)
65986592
return ret;
65996593

@@ -6613,7 +6607,9 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num)
66136607
int all_uptodate = 1;
66146608
int num_pages;
66156609
unsigned long num_reads = 0;
6616-
struct btrfs_bio_ctrl bio_ctrl = { 0 };
6610+
struct btrfs_bio_ctrl bio_ctrl = {
6611+
.mirror_num = mirror_num,
6612+
};
66176613

66186614
if (test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags))
66196615
return 0;
@@ -6687,7 +6683,7 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num)
66876683
err = submit_extent_page(REQ_OP_READ, NULL,
66886684
&bio_ctrl, page, page_offset(page),
66896685
PAGE_SIZE, 0, end_bio_extent_readpage,
6690-
mirror_num, 0, false);
6686+
0, false);
66916687
if (err) {
66926688
/*
66936689
* We failed to submit the bio so it's the
@@ -6704,10 +6700,7 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num)
67046700
}
67056701
}
67066702

6707-
if (bio_ctrl.bio) {
6708-
submit_one_bio(bio_ctrl.bio, mirror_num, bio_ctrl.compress_type);
6709-
bio_ctrl.bio = NULL;
6710-
}
6703+
submit_one_bio(&bio_ctrl);
67116704

67126705
if (ret || wait != WAIT_COMPLETE)
67136706
return ret;

0 commit comments

Comments
 (0)