Skip to content

Commit 7aa5123

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: pass a btrfs_bio to btrfs_repair_one_sector
Pass the btrfs_bio instead of the plain bio to btrfs_repair_one_sector, and remove the start and failed_mirror arguments in favor of deriving them from the btrfs_bio. For this to work ensure that the file_offset field is also initialized for buffered I/O. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 524bcd1 commit 7aa5123

3 files changed

Lines changed: 31 additions & 29 deletions

File tree

fs/btrfs/extent_io.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -182,19 +182,23 @@ static int add_extent_changeset(struct extent_state *state, u32 bits,
182182
static void submit_one_bio(struct btrfs_bio_ctrl *bio_ctrl)
183183
{
184184
struct bio *bio;
185+
struct bio_vec *bv;
185186
struct inode *inode;
186187
int mirror_num;
187188

188189
if (!bio_ctrl->bio)
189190
return;
190191

191192
bio = bio_ctrl->bio;
192-
inode = bio_first_page_all(bio)->mapping->host;
193+
bv = bio_first_bvec_all(bio);
194+
inode = bv->bv_page->mapping->host;
193195
mirror_num = bio_ctrl->mirror_num;
194196

195197
/* Caller should ensure the bio has at least some range added */
196198
ASSERT(bio->bi_iter.bi_size);
197199

200+
btrfs_bio(bio)->file_offset = page_offset(bv->bv_page) + bv->bv_offset;
201+
198202
if (!is_data_inode(inode))
199203
btrfs_submit_metadata_bio(inode, bio, mirror_num);
200204
else if (btrfs_op(bio) == BTRFS_MAP_WRITE)
@@ -2535,10 +2539,11 @@ void btrfs_free_io_failure_record(struct btrfs_inode *inode, u64 start, u64 end)
25352539
}
25362540

25372541
static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode,
2538-
u64 start,
2539-
int failed_mirror)
2542+
struct btrfs_bio *bbio,
2543+
unsigned int bio_offset)
25402544
{
25412545
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
2546+
u64 start = bbio->file_offset + bio_offset;
25422547
struct io_failure_record *failrec;
25432548
struct extent_map *em;
25442549
struct extent_io_tree *failure_tree = &BTRFS_I(inode)->io_failure_tree;
@@ -2558,7 +2563,7 @@ static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode
25582563
* (e.g. with a list for failed_mirror) to make
25592564
* clean_io_failure() clean all those errors at once.
25602565
*/
2561-
ASSERT(failrec->this_mirror == failed_mirror);
2566+
ASSERT(failrec->this_mirror == bbio->mirror_num);
25622567
ASSERT(failrec->len == fs_info->sectorsize);
25632568
return failrec;
25642569
}
@@ -2569,8 +2574,8 @@ static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode
25692574

25702575
failrec->start = start;
25712576
failrec->len = sectorsize;
2572-
failrec->failed_mirror = failed_mirror;
2573-
failrec->this_mirror = failed_mirror;
2577+
failrec->failed_mirror = bbio->mirror_num;
2578+
failrec->this_mirror = bbio->mirror_num;
25742579
failrec->compress_type = BTRFS_COMPRESS_NONE;
25752580

25762581
read_lock(&em_tree->lock);
@@ -2635,17 +2640,16 @@ static struct io_failure_record *btrfs_get_io_failure_record(struct inode *inode
26352640
return failrec;
26362641
}
26372642

2638-
int btrfs_repair_one_sector(struct inode *inode,
2639-
struct bio *failed_bio, u32 bio_offset,
2640-
struct page *page, unsigned int pgoff,
2641-
u64 start, int failed_mirror,
2643+
int btrfs_repair_one_sector(struct inode *inode, struct btrfs_bio *failed_bbio,
2644+
u32 bio_offset, struct page *page, unsigned int pgoff,
26422645
submit_bio_hook_t *submit_bio_hook)
26432646
{
2647+
u64 start = failed_bbio->file_offset + bio_offset;
26442648
struct io_failure_record *failrec;
26452649
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
26462650
struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
26472651
struct extent_io_tree *failure_tree = &BTRFS_I(inode)->io_failure_tree;
2648-
struct btrfs_bio *failed_bbio = btrfs_bio(failed_bio);
2652+
struct bio *failed_bio = &failed_bbio->bio;
26492653
const int icsum = bio_offset >> fs_info->sectorsize_bits;
26502654
struct bio *repair_bio;
26512655
struct btrfs_bio *repair_bbio;
@@ -2655,7 +2659,7 @@ int btrfs_repair_one_sector(struct inode *inode,
26552659

26562660
BUG_ON(bio_op(failed_bio) == REQ_OP_WRITE);
26572661

2658-
failrec = btrfs_get_io_failure_record(inode, start, failed_mirror);
2662+
failrec = btrfs_get_io_failure_record(inode, failed_bbio, bio_offset);
26592663
if (IS_ERR(failrec))
26602664
return PTR_ERR(failrec);
26612665

@@ -2751,9 +2755,10 @@ static void end_sector_io(struct page *page, u64 offset, bool uptodate)
27512755
offset + sectorsize - 1, &cached);
27522756
}
27532757

2754-
static void submit_data_read_repair(struct inode *inode, struct bio *failed_bio,
2758+
static void submit_data_read_repair(struct inode *inode,
2759+
struct btrfs_bio *failed_bbio,
27552760
u32 bio_offset, const struct bio_vec *bvec,
2756-
int failed_mirror, unsigned int error_bitmap)
2761+
unsigned int error_bitmap)
27572762
{
27582763
const unsigned int pgoff = bvec->bv_offset;
27592764
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
@@ -2764,7 +2769,7 @@ static void submit_data_read_repair(struct inode *inode, struct bio *failed_bio,
27642769
const int nr_bits = (end + 1 - start) >> fs_info->sectorsize_bits;
27652770
int i;
27662771

2767-
BUG_ON(bio_op(failed_bio) == REQ_OP_WRITE);
2772+
BUG_ON(bio_op(&failed_bbio->bio) == REQ_OP_WRITE);
27682773

27692774
/* This repair is only for data */
27702775
ASSERT(is_data_inode(inode));
@@ -2776,7 +2781,7 @@ static void submit_data_read_repair(struct inode *inode, struct bio *failed_bio,
27762781
* We only get called on buffered IO, thus page must be mapped and bio
27772782
* must not be cloned.
27782783
*/
2779-
ASSERT(page->mapping && !bio_flagged(failed_bio, BIO_CLONED));
2784+
ASSERT(page->mapping && !bio_flagged(&failed_bbio->bio, BIO_CLONED));
27802785

27812786
/* Iterate through all the sectors in the range */
27822787
for (i = 0; i < nr_bits; i++) {
@@ -2793,10 +2798,9 @@ static void submit_data_read_repair(struct inode *inode, struct bio *failed_bio,
27932798
goto next;
27942799
}
27952800

2796-
ret = btrfs_repair_one_sector(inode, failed_bio,
2797-
bio_offset + offset,
2798-
page, pgoff + offset, start + offset,
2799-
failed_mirror, btrfs_submit_data_read_bio);
2801+
ret = btrfs_repair_one_sector(inode, failed_bbio,
2802+
bio_offset + offset, page, pgoff + offset,
2803+
btrfs_submit_data_read_bio);
28002804
if (!ret) {
28012805
/*
28022806
* We have submitted the read repair, the page release
@@ -3130,8 +3134,8 @@ static void end_bio_extent_readpage(struct bio *bio)
31303134
* submit_data_read_repair() will handle all the good
31313135
* and bad sectors, we just continue to the next bvec.
31323136
*/
3133-
submit_data_read_repair(inode, bio, bio_offset, bvec,
3134-
mirror, error_bitmap);
3137+
submit_data_read_repair(inode, bbio, bio_offset, bvec,
3138+
error_bitmap);
31353139
} else {
31363140
/* Update page status and unlock */
31373141
end_page_read(page, uptodate, start, len);

fs/btrfs/extent_io.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ enum {
5757
#define BITMAP_LAST_BYTE_MASK(nbits) \
5858
(BYTE_MASK >> (-(nbits) & (BITS_PER_BYTE - 1)))
5959

60+
struct btrfs_bio;
6061
struct btrfs_root;
6162
struct btrfs_inode;
6263
struct btrfs_io_bio;
@@ -266,10 +267,8 @@ struct io_failure_record {
266267
int num_copies;
267268
};
268269

269-
int btrfs_repair_one_sector(struct inode *inode,
270-
struct bio *failed_bio, u32 bio_offset,
271-
struct page *page, unsigned int pgoff,
272-
u64 start, int failed_mirror,
270+
int btrfs_repair_one_sector(struct inode *inode, struct btrfs_bio *failed_bbio,
271+
u32 bio_offset, struct page *page, unsigned int pgoff,
273272
submit_bio_hook_t *submit_bio_hook);
274273

275274
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS

fs/btrfs/inode.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8012,9 +8012,8 @@ static blk_status_t btrfs_check_read_dio_bio(struct btrfs_dio_private *dip,
80128012
} else {
80138013
int ret;
80148014

8015-
ret = btrfs_repair_one_sector(inode, &bbio->bio, offset,
8016-
bv.bv_page, bv.bv_offset, start,
8017-
bbio->mirror_num,
8015+
ret = btrfs_repair_one_sector(inode, bbio, offset,
8016+
bv.bv_page, bv.bv_offset,
80188017
submit_dio_repair_bio);
80198018
if (ret)
80208019
err = errno_to_blk_status(ret);

0 commit comments

Comments
 (0)