Skip to content

Commit 9d0d1c8

Browse files
Liu Bokdave
authored andcommitted
Btrfs: bring back repair during read
Commit 20a7db8 ("btrfs: add dummy callback for readpage_io_failed and drop checks") made a cleanup around readpage_io_failed_hook, and it was supposed to keep the original sematics, but it also unexpectedly disabled repair during read for dup, raid1 and raid10. This fixes the problem by letting data's inode call the generic readpage_io_failed callback by returning -EAGAIN from its readpage_io_failed_hook in order to notify end_bio_extent_readpage to do the rest. We don't call it directly because the generic one takes an offset from end_bio_extent_readpage() to calculate the index in the checksum array and inode's readpage_io_failed_hook doesn't offer that offset. Cc: David Sterba <[email protected]> Signed-off-by: Liu Bo <[email protected]> Reviewed-by: David Sterba <[email protected]> [ keep the const function attribute ] Signed-off-by: David Sterba <[email protected]>
1 parent e1699d2 commit 9d0d1c8

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

fs/btrfs/extent_io.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,26 +2584,36 @@ static void end_bio_extent_readpage(struct bio *bio)
25842584

25852585
if (tree->ops) {
25862586
ret = tree->ops->readpage_io_failed_hook(page, mirror);
2587-
if (!ret && !bio->bi_error)
2588-
uptodate = 1;
2589-
} else {
2587+
if (ret == -EAGAIN) {
2588+
/*
2589+
* Data inode's readpage_io_failed_hook() always
2590+
* returns -EAGAIN.
2591+
*
2592+
* The generic bio_readpage_error handles errors
2593+
* the following way: If possible, new read
2594+
* requests are created and submitted and will
2595+
* end up in end_bio_extent_readpage as well (if
2596+
* we're lucky, not in the !uptodate case). In
2597+
* that case it returns 0 and we just go on with
2598+
* the next page in our bio. If it can't handle
2599+
* the error it will return -EIO and we remain
2600+
* responsible for that page.
2601+
*/
2602+
ret = bio_readpage_error(bio, offset, page,
2603+
start, end, mirror);
2604+
if (ret == 0) {
2605+
uptodate = !bio->bi_error;
2606+
offset += len;
2607+
continue;
2608+
}
2609+
}
2610+
25902611
/*
2591-
* The generic bio_readpage_error handles errors the
2592-
* following way: If possible, new read requests are
2593-
* created and submitted and will end up in
2594-
* end_bio_extent_readpage as well (if we're lucky, not
2595-
* in the !uptodate case). In that case it returns 0 and
2596-
* we just go on with the next page in our bio. If it
2597-
* can't handle the error it will return -EIO and we
2598-
* remain responsible for that page.
2612+
* metadata's readpage_io_failed_hook() always returns
2613+
* -EIO and fixes nothing. -EIO is also returned if
2614+
* data inode error could not be fixed.
25992615
*/
2600-
ret = bio_readpage_error(bio, offset, page, start, end,
2601-
mirror);
2602-
if (ret == 0) {
2603-
uptodate = !bio->bi_error;
2604-
offset += len;
2605-
continue;
2606-
}
2616+
ASSERT(ret == -EIO);
26072617
}
26082618
readpage_ok:
26092619
if (likely(uptodate)) {

fs/btrfs/inode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10523,9 +10523,9 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
1052310523
}
1052410524

1052510525
__attribute__((const))
10526-
static int dummy_readpage_io_failed_hook(struct page *page, int failed_mirror)
10526+
static int btrfs_readpage_io_failed_hook(struct page *page, int failed_mirror)
1052710527
{
10528-
return 0;
10528+
return -EAGAIN;
1052910529
}
1053010530

1053110531
static const struct inode_operations btrfs_dir_inode_operations = {
@@ -10570,7 +10570,7 @@ static const struct extent_io_ops btrfs_extent_io_ops = {
1057010570
.submit_bio_hook = btrfs_submit_bio_hook,
1057110571
.readpage_end_io_hook = btrfs_readpage_end_io_hook,
1057210572
.merge_bio_hook = btrfs_merge_bio_hook,
10573-
.readpage_io_failed_hook = dummy_readpage_io_failed_hook,
10573+
.readpage_io_failed_hook = btrfs_readpage_io_failed_hook,
1057410574

1057510575
/* optional callbacks */
1057610576
.fill_delalloc = run_delalloc_range,

0 commit comments

Comments
 (0)