Skip to content

Commit 5467abb

Browse files
adam900710kdave
authored andcommitted
btrfs: move end_io_func argument to btrfs_bio_ctrl structure
For function submit_extent_page() and alloc_new_bio(), we have an argument @end_io_func to indicate the end io function. But that function never change inside any call site of them, thus no need to pass the pointer around everywhere. There is a better match for the lifespan of all the call sites, as we have btrfs_bio_ctrl structure, thus we can put the endio function pointer there, and grab the pointer every time we allocate a new bio. Also add extra ASSERT()s to make sure every call site of submit_extent_page() and alloc_new_bio() has properly set the pointer inside btrfs_bio_ctrl. This removes one argument from the already long argument list of submit_extent_page(). Reviewed-by: Anand Jain <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 209ecde commit 5467abb

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

fs/btrfs/extent_io.c

+23-17
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ struct btrfs_bio_ctrl {
9595
enum btrfs_compression_type compress_type;
9696
u32 len_to_stripe_boundary;
9797
u32 len_to_oe_boundary;
98+
btrfs_bio_end_io_t end_io_func;
9899
};
99100

100101
struct extent_page_data {
@@ -1479,15 +1480,16 @@ static int alloc_new_bio(struct btrfs_inode *inode,
14791480
struct btrfs_bio_ctrl *bio_ctrl,
14801481
struct writeback_control *wbc,
14811482
blk_opf_t opf,
1482-
btrfs_bio_end_io_t end_io_func,
14831483
u64 disk_bytenr, u32 offset, u64 file_offset,
14841484
enum btrfs_compression_type compress_type)
14851485
{
14861486
struct btrfs_fs_info *fs_info = inode->root->fs_info;
14871487
struct bio *bio;
14881488
int ret;
14891489

1490-
bio = btrfs_bio_alloc(BIO_MAX_VECS, opf, end_io_func, NULL);
1490+
ASSERT(bio_ctrl->end_io_func);
1491+
1492+
bio = btrfs_bio_alloc(BIO_MAX_VECS, opf, bio_ctrl->end_io_func, NULL);
14911493
/*
14921494
* For compressed page range, its disk_bytenr is always @disk_bytenr
14931495
* passed in, no matter if we have added any range into previous bio.
@@ -1548,7 +1550,6 @@ static int alloc_new_bio(struct btrfs_inode *inode,
15481550
* @size: portion of page that we want to write to
15491551
* @pg_offset: offset of the new bio or to check whether we are adding
15501552
* a contiguous page to the previous one
1551-
* @end_io_func: end_io callback for new bio
15521553
* @compress_type: compress type for current bio
15531554
*
15541555
* The will either add the page into the existing @bio_ctrl->bio, or allocate a
@@ -1561,7 +1562,6 @@ static int submit_extent_page(blk_opf_t opf,
15611562
struct btrfs_bio_ctrl *bio_ctrl,
15621563
u64 disk_bytenr, struct page *page,
15631564
size_t size, unsigned long pg_offset,
1564-
btrfs_bio_end_io_t end_io_func,
15651565
enum btrfs_compression_type compress_type,
15661566
bool force_bio_submit)
15671567
{
@@ -1573,6 +1573,9 @@ static int submit_extent_page(blk_opf_t opf,
15731573

15741574
ASSERT(pg_offset < PAGE_SIZE && size <= PAGE_SIZE &&
15751575
pg_offset + size <= PAGE_SIZE);
1576+
1577+
ASSERT(bio_ctrl->end_io_func);
1578+
15761579
if (force_bio_submit)
15771580
submit_one_bio(bio_ctrl);
15781581

@@ -1583,7 +1586,7 @@ static int submit_extent_page(blk_opf_t opf,
15831586
/* Allocate new bio if needed */
15841587
if (!bio_ctrl->bio) {
15851588
ret = alloc_new_bio(inode, bio_ctrl, wbc, opf,
1586-
end_io_func, disk_bytenr, offset,
1589+
disk_bytenr, offset,
15871590
page_offset(page) + cur,
15881591
compress_type);
15891592
if (ret < 0)
@@ -1763,6 +1766,7 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached,
17631766
memzero_page(page, zero_offset, iosize);
17641767
}
17651768
}
1769+
bio_ctrl->end_io_func = end_bio_extent_readpage;
17661770
begin_page_read(fs_info, page);
17671771
while (cur <= end) {
17681772
unsigned long this_bio_flag = 0;
@@ -1876,8 +1880,8 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached,
18761880

18771881
ret = submit_extent_page(REQ_OP_READ | read_flags, NULL,
18781882
bio_ctrl, disk_bytenr, page, iosize,
1879-
pg_offset, end_bio_extent_readpage,
1880-
this_bio_flag, force_bio_submit);
1883+
pg_offset, this_bio_flag,
1884+
force_bio_submit);
18811885
if (ret) {
18821886
/*
18831887
* We have to unlock the remaining range, or the page
@@ -2096,6 +2100,7 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
20962100
*/
20972101
wbc->nr_to_write--;
20982102

2103+
epd->bio_ctrl.end_io_func = end_bio_extent_writepage;
20992104
while (cur <= end) {
21002105
u64 disk_bytenr;
21012106
u64 em_end;
@@ -2192,7 +2197,6 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
21922197
&epd->bio_ctrl, disk_bytenr,
21932198
page, iosize,
21942199
cur - page_offset(page),
2195-
end_bio_extent_writepage,
21962200
0, false);
21972201
if (ret) {
21982202
has_error = true;
@@ -2685,10 +2689,11 @@ static int write_one_subpage_eb(struct extent_buffer *eb,
26852689
if (no_dirty_ebs)
26862690
clear_page_dirty_for_io(page);
26872691

2692+
epd->bio_ctrl.end_io_func = end_bio_subpage_eb_writepage;
2693+
26882694
ret = submit_extent_page(REQ_OP_WRITE | write_flags, wbc,
26892695
&epd->bio_ctrl, eb->start, page, eb->len,
2690-
eb->start - page_offset(page),
2691-
end_bio_subpage_eb_writepage, 0, false);
2696+
eb->start - page_offset(page), 0, false);
26922697
if (ret) {
26932698
btrfs_subpage_clear_writeback(fs_info, page, eb->start, eb->len);
26942699
set_btree_ioerr(page, eb);
@@ -2719,6 +2724,8 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
27192724

27202725
prepare_eb_write(eb);
27212726

2727+
epd->bio_ctrl.end_io_func = end_bio_extent_buffer_writepage;
2728+
27222729
num_pages = num_extent_pages(eb);
27232730
for (i = 0; i < num_pages; i++) {
27242731
struct page *p = eb->pages[i];
@@ -2727,9 +2734,7 @@ static noinline_for_stack int write_one_eb(struct extent_buffer *eb,
27272734
set_page_writeback(p);
27282735
ret = submit_extent_page(REQ_OP_WRITE | write_flags, wbc,
27292736
&epd->bio_ctrl, disk_bytenr, p,
2730-
PAGE_SIZE, 0,
2731-
end_bio_extent_buffer_writepage,
2732-
0, false);
2737+
PAGE_SIZE, 0, 0, false);
27332738
if (ret) {
27342739
set_btree_ioerr(p, eb);
27352740
if (PageWriteback(p))
@@ -4978,13 +4983,14 @@ static int read_extent_buffer_subpage(struct extent_buffer *eb, int wait,
49784983
eb->read_mirror = 0;
49794984
atomic_set(&eb->io_pages, 1);
49804985
check_buffer_tree_ref(eb);
4986+
bio_ctrl.end_io_func = end_bio_extent_readpage;
4987+
49814988
btrfs_subpage_clear_error(fs_info, page, eb->start, eb->len);
49824989

49834990
btrfs_subpage_start_reader(fs_info, page, eb->start, eb->len);
49844991
ret = submit_extent_page(REQ_OP_READ, NULL, &bio_ctrl,
49854992
eb->start, page, eb->len,
4986-
eb->start - page_offset(page),
4987-
end_bio_extent_readpage, 0, true);
4993+
eb->start - page_offset(page), 0, true);
49884994
if (ret) {
49894995
/*
49904996
* In the endio function, if we hit something wrong we will
@@ -5075,6 +5081,7 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num)
50755081
* set io_pages. See check_buffer_tree_ref for a more detailed comment.
50765082
*/
50775083
check_buffer_tree_ref(eb);
5084+
bio_ctrl.end_io_func = end_bio_extent_readpage;
50785085
for (i = 0; i < num_pages; i++) {
50795086
page = eb->pages[i];
50805087

@@ -5088,8 +5095,7 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int wait, int mirror_num)
50885095
ClearPageError(page);
50895096
err = submit_extent_page(REQ_OP_READ, NULL,
50905097
&bio_ctrl, page_offset(page), page,
5091-
PAGE_SIZE, 0, end_bio_extent_readpage,
5092-
0, false);
5098+
PAGE_SIZE, 0, 0, false);
50935099
if (err) {
50945100
/*
50955101
* We failed to submit the bio so it's the

0 commit comments

Comments
 (0)