Btrfs: fix kernel oops while reading compressed data
PATCH 1/2 Btrfs: fix kernel oops while reading compressed data
The kernel oops happens at
kernel BUG at fs/btrfs/extent_io.c:2104!
...
RIP: clean_io_failure+0x263/0x2a0 [btrfs]
It's showing that read-repair code is using an improper mirror index. This is due to the fact that compression read's endio hasn't recorded the failed mirror index in %cb->orig_bio.
With this, btrfs's read-repair can work properly on reading compressed data.
--- fs/btrfs/compression.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/btrfs/compression.c +9 -0
@@ -107,6 +107,7 @@ static void end_compressed_bio_read(struct bio *bio)struct inode *inode;struct page *page;unsigned long index; +unsigned int mirror =btrfs_io_bio (bio)->mirror_num;int ret;if (bio->bi_status)
@@ -118,6 +119,14 @@ static void end_compressed_bio_read(struct bio *bio)if (!refcount_dec_and_test (&cb->pending_bios)) goto out; +/* +* Record the correct mirror_num in cb->orig_bio so that +* read-repair can work properly. +*/ +ASSERT (btrfs_io_bio (cb->orig_bio)); +btrfs_io_bio (cb->orig_bio)->mirror_num = mirror; + cb->mirror_num = mirror; + inode = cb->inode; ret =check_compressed_csum (BTRFS_I (inode), cb, (u64 )bio->bi_iter.bi_sector <<9 );
Signature · 1 line
2.9.4
PATCH 2/2 Btrfs: skip checksum when reading compressed data if some IO have failed
Currently even if the underlying disk reports failure on IO, compressed read endio still gets to verify checksum and reports it as a checksum error.
In fact, if some IO have failed during reading a compressed data extent , there's no way the checksum could match, therefore, we can skip that in order to return error quickly to the upper layer.
Please note that we need to do this after recording the failed mirror index so that read-repair in the upper layer's endio can work properly.
--- fs/btrfs/compression.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/btrfs/compression.c +8 -1
@@ -108,7 +108,7 @@ static void end_compressed_bio_read(struct bio *bio)struct page *page;unsigned long index;unsigned int mirror =btrfs_io_bio (bio)->mirror_num; -int ret; +int ret =0 ;if (bio->bi_status) cb->errors =1 ;
@@ -127,6 +127,13 @@ static void end_compressed_bio_read(struct bio *bio)btrfs_io_bio (cb->orig_bio)->mirror_num = mirror; cb->mirror_num = mirror; +/* +* Some IO in this cb have failed, just skip checksum as there +* is no way it could be correct. +*/ +if (cb->errors ==1 ) + goto csum_failed; + inode = cb->inode; ret =check_compressed_csum (BTRFS_I (inode), cb, (u64 )bio->bi_iter.bi_sector <<9 );
Signature · 1 line
2.9.4
Re: [PATCH 2/2] Btrfs: skip checksum when reading compressed data if some IO have failed
Quoted 8 lines · Liu Bo
Currently even if the underlying disk reports failure on IO, compressed read endio still gets to verify checksum and reports it as a checksum error.
In fact, if some IO have failed during reading a compressed data extent , there's no way the checksum could match, therefore, we can skip that in order to return error quickly to the upper layer.
Quoted 5 lines
Please note that we need to do this after recording the failed mirror index so that read-repair in the upper layer's endio can work properly.
Signed-off-by Liu Bo <[email protected]>
Quoted 9 lines · Liu Bo
The kernel oops happens at
kernel BUG at
fs/btrfs/extent_io.c:2104!
...RIP: clean_io_failure+0x263/0x2a0 [btrfs]It's showing that read-repair code is using an improper mirror index. This is due to the fact that compression read's endio hasn't recorded the failed mirror index in %cb->orig_bio.
This sounds like the corner case of raid1 repair that was reported i the past and actually is the only thing because of which we are not so comfortable to mark raid1 'completely ok' in the Status page.
Quoted 10 lines · Liu Bo
The kernel oops happens at
kernel BUG at
fs/btrfs/extent_io.c:2104!
...RIP: clean_io_failure+0x263/0x2a0 [btrfs]It's showing that read-repair code is using an improper mirror index. This is due to the fact that compression read's endio hasn't recorded the failed mirror index in %cb->orig_bio.
Quoted 5 lines
With this, btrfs's read-repair can work properly on reading compressed data.
Signed-off-by Liu Bo <[email protected]>Reported-by Paul Jones <[email protected]>
Paul Jones
Tested-byQuoted 20 lines
-----Original Message-----
From: [email protected] [mailto:linux-btrfs- [email protected]] On Behalf Of David Sterba
Sent: Sunday, 24 September 2017 11:46 PM
To: Liu Bo <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 1/2] Btrfs: fix kernel oops while reading compressed dataQuoted 10 lines · Liu Bo
The kernel oops happens at
kernel BUG at
fs/btrfs/extent_io.c:2104!
...RIP: clean_io_failure+0x263/0x2a0 [btrfs]It's showing that read-repair code is using an improper mirror index. This is due to the fact that compression read's endio hasn't recorded the failed mirror index in %cb->orig_bio.
Quoted 7 lines
Quoted 5 lines
With this, btrfs's read-repair can work properly on reading compressed data.
Signed-off-by Liu Bo <[email protected]>Reported-by Paul Jones <[email protected]>Reviewed-by David Sterba <[email protected]>
For both patches.
I caused the same thing to happen again, this time by unplugging the wrong hard drive. Applied the patches and problem (BUG_ON) is gone. Should this also go to stable? Seems like a rather glaring problem to me.
Paul.
Quoted 23 lines · Paul Jones
Quoted 23 lines
-----Original Message-----
From: [email protected] [mailto:linux-btrfs- [email protected]] On Behalf Of David Sterba
Sent: Sunday, 24 September 2017 11:46 PM
To: Liu Bo <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 1/2] Btrfs: fix kernel oops while reading compressed dataQuoted 13 lines · Liu Bo
The kernel oops happens at
kernel BUG at
fs/btrfs/extent_io.c:2104!
...RIP: clean_io_failure+0x263/0x2a0 [btrfs]It's showing that read-repair code is using an improper mirror index. This is due to the fact that compression read's endio hasn't recorded the failed mirror index in %cb->orig_bio.
With this, btrfs's read-repair can work properly on reading compressed data.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Signed-off-by Liu Bo <[email protected]>Reported-by Paul Jones <[email protected]>Reviewed-by David Sterba <[email protected]>Tested-by <[email protected]>For both patches.
Thanks for testing.
Quoted 3 lines
I caused the same thing to happen again, this time by unplugging the wrong hard drive. Applied the patches and problem (
BUG_ON) is gone. Should this also go to stable? Seems like a rather glaring problem to me.
Yes it should and will be forwarded there once it's merged to Linus' tree.