btrfs: Enhancement to tree block validation
v2 cover btrfs: Enhancement to tree block validation
Patchset can be fetched from github:
https://github.com/adam900710/linux/tree/write_time_tree_checker
Which is based on v5.0-rc1 tag.
This patchset has the following two features:
- Tree block validation output enhancement
* Output validation failure timing (write time or read time)
* Always output tree block level/key mismatch error message This part is already submitted and reviewed.
- Write time tree block validation check
To catch memory corruption either from hardware or kernel. Example output would be:
BTRFS critical (device dm-3): corrupt leaf: root=2 block=1350630375424 slot=68, bad key order, prev (10510212874240 169 0) current (1714119868416 169 0) BTRFS error (device dm-3): write time tree block corruption detected
BTRFS critical (device dm-3): corrupt leaf: root=2 block=1350630375424 slot=68, bad key order, prev (10510212874240 169 0) current (1714119868416 169 0) BTRFS error (device dm-3): write time tree block corruption detected
BTRFS: error (device dm-3) in btrfs_commit_transaction:2220: errno=-5 IO failure (Error while writing out transaction)
BTRFS info (device dm-3): forced readonly
BTRFS warning (device dm-3): Skipping commit of aborted transaction.
BTRFS: error (device dm-3) in cleanup_transaction:1839: errno=-5 IO failure
BTRFS info (device dm-3): delayed_refs has NO entry
Changelog:
- Unlock locked pages in lock_extent_buffer_for_io() for error handling
- Added Reviewed-by tags.
Qu Wenruo (5):
btrfs: Always output error message when key/level verification fails
btrfs: extent_io: Kill the forward declaration of flush_write_bio()
btrfs: extent_io: Kill the BUG_ON() in flush_write_bio()
btrfs: disk-io: Show the timing of corrupted tree block explicitly
btrfs: Do mandatory tree block check before submitting bio
fs/btrfs/disk-io.c | 20 +++++-- fs/btrfs/extent_io.c | 135 +++++++++++++++++++++++++++---------------- 2 files changed, 102 insertions(+), 53 deletions(-)
Signature · 1 line
2.20.1
PATCH v2 1/5 btrfs: Always output error message when key/level verification fails
We have internal report of strange transaction abort due to EUCLEAN without any error message.
Since error message inside verify_level_key() is only enabled for CONFIG_BTRFS_DEBUG, the error message won't output for most distro.
This patch will make the error message mandatory, so when problem happens we know what's causing the problem.
--- fs/btrfs/disk-io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/disk-io.c +3 -3
@@ -425,10 +425,10 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,if (found_level != level) {#ifdef CONFIG_BTRFS_DEBUG WARN_ON (1 ); +#endif btrfs_err (fs_info,"tree level mismatch detected, bytenr=%llu level expected=%u has=%u" , eb->start, level, found_level); -#endif return -EIO ; }
@@ -449,9 +449,10 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,btrfs_item_key_to_cpu (eb, &found_key,0 ); ret =btrfs_comp_cpu_keys (first_key, &found_key); -#ifdef CONFIG_BTRFS_DEBUG if (ret) { +#ifdef CONFIG_BTRFS_DEBUG WARN_ON (1 ); +#endif btrfs_err(fs_info, "tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)", eb->start, parent_transid, first_key->objectid,
@@ -459,7 +460,6 @@ static int verify_level_key(struct btrfs_fs_info *fs_info, found_key.objectid, found_key.type, found_key.offset); } -#endif return ret; }
Signature · 1 line
2.20.1
Re: [PATCH v2 1/5] btrfs: Always output error message when key/level verification fails
Quoted 13 lines · Qu Wenruo
fs/btrfs/disk-io.c +2
-1@@ -449,9 +449,10 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,btrfs_item_key_to_cpu (eb, &found_key,0 ); ret =btrfs_comp_cpu_keys (first_key, &found_key); -#ifdef CONFIG_BTRFS_DEBUG if (ret) { +#ifdef CONFIG_BTRFS_DEBUG WARN_ON (1 ); +#endif btrfs_err(fs_info, "tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)", eb->start, parent_transid, first_key->objectid,
fs/btrfs/disk-io.c static int verify_level_key(struct btrfs_fs_info *fs_info, · line 464
Quoted 6 lines
fs/btrfs/disk-io.c +0
-1@@ -459,7 +460,6 @@ static int verify_level_key(struct btrfs_fs_info *fs_info, found_key.objectid, found_key.type, found_key.offset); } -#endif return ret; }
Hmm I think the resulting code looks a bit odd now, doesn't it? if (ret) {
#ifdef CONFIG_BTRFS_DEBUG WARN_ON(1);
#endif
btrfs_err(fs_info,
Why not something like:
if (ret) {
if (IS_ENABLED(CONFIG_BTRFS_DEBUG))
WARN_ON(1);
btrfs_err(fs_info,Or even hide the if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) WARN_ON(1); in a macro
#define BTRFS_DEBUG_WARN_ON(x) do { \
if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) \
WARN_ON((x)); \
} while(0)Signature · 6 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH v2 1/5] btrfs: Always output error message when key/level verification fails
Quoted 28 lines · Johannes Thumshirn
Quoted 13 lines · Qu Wenruo
fs/btrfs/disk-io.c +2
-1@@ -449,9 +449,10 @@ static int verify_level_key(struct btrfs_fs_info *fs_info,btrfs_item_key_to_cpu (eb, &found_key,0 ); ret =btrfs_comp_cpu_keys (first_key, &found_key); -#ifdef CONFIG_BTRFS_DEBUG if (ret) { +#ifdef CONFIG_BTRFS_DEBUG WARN_ON (1 ); +#endif btrfs_err(fs_info, "tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)", eb->start, parent_transid, first_key->objectid,fs/btrfs/disk-io.c static int verify_level_key(struct btrfs_fs_info *fs_info, · line 464
Quoted 6 lines
fs/btrfs/disk-io.c +0
-1@@ -459,7 +460,6 @@ static int verify_level_key(struct btrfs_fs_info *fs_info, found_key.objectid, found_key.type, found_key.offset); } -#endif return ret; }Hmm I think the resulting code looks a bit odd now, doesn't it? if (ret) {
#ifdef CONFIG_BTRFS_DEBUG WARN_ON(1);#endif
Quoted 7 lines
btrfs_err(fs_info,
Why not something like:
if (ret) { if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) WARN_ON(1);
Didn't know that macro, and indeed it looks much better.
Quoted 8 lines
btrfs_err(fs_info,
Or even hide the if (
IS_ENABLED(CONFIG_BTRFS_DEBUG))WARN_ON(1); in a macro#define BTRFS_DEBUG_WARN_ON(x) do { \ if (IS_ENABLED(CONFIG_BTRFS_DEBUG)) \ WARN_ON((x)); \ } while(0)
Although I'd say such WARN_ON() for DEBUG build will finally get moved to any build.
Thanks,
Qu
Quoted 1 line
PATCH v2 2/5 btrfs: extent_io: Kill the forward declaration of flush_write_bio()
In reply to Qu WenruoThere is no need to forward declare flush_write_bio(), as it only depends on submit_one_bio().
Both of them are pretty small, just move them to kill the forward declaration.
--- fs/btrfs/extent_io.c | 66 +++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 34 deletions(-)
fs/btrfs/extent_io.c +32 -34
@@ -147,7 +147,38 @@ static int add_extent_changeset(struct extent_state *state, unsigned bits,return ret; } -static void flush_write_bio (struct extent_page_data *epd); +static int __must_check submit_one_bio (struct bio *bio,int mirror_num, +unsigned long bio_flags) +{ +blk_status_t ret =0 ; +struct bio_vec *bvec =bio_last_bvec_all (bio); +struct page *page = bvec->bv_page; +struct extent_io_tree *tree = bio->bi_private; +u64 start; + + start =page_offset (page) + bvec->bv_offset; + + bio->bi_private =NULL ; + +if (tree->ops) + ret = tree->ops->submit_bio_hook (tree->private_data, bio, + mirror_num, bio_flags, start); +else +btrfsic_submit_bio (bio); + +return blk_status_to_errno (ret); +} + +static void flush_write_bio (struct extent_page_data *epd) +{ +if (epd->bio) { +int ret; + + ret =submit_one_bio (epd->bio,0 ,0 ); +BUG_ON (ret <0 );/* -ENOMEM */ + epd->bio =NULL ; + } +}int __init extent_io_init (void ) {
@@ -2692,28 +2723,6 @@ struct bio *btrfs_bio_clone_partial(struct bio *orig, int offset, int size)return bio; } -static int __must_check submit_one_bio (struct bio *bio,int mirror_num, -unsigned long bio_flags) -{ -blk_status_t ret =0 ; -struct bio_vec *bvec =bio_last_bvec_all (bio); -struct page *page = bvec->bv_page; -struct extent_io_tree *tree = bio->bi_private; -u64 start; - - start =page_offset (page) + bvec->bv_offset; - - bio->bi_private =NULL ; - -if (tree->ops) - ret = tree->ops->submit_bio_hook (tree->private_data, bio, - mirror_num, bio_flags, start); -else -btrfsic_submit_bio (bio); - -return blk_status_to_errno (ret); -} -/* * @opf: bio REQ_OP_* and REQ_* flags as one value * @tree: tree so we can call our merge_bio hook
@@ -4007,17 +4016,6 @@ static int extent_write_cache_pages(struct address_space *mapping,return ret; } -static void flush_write_bio (struct extent_page_data *epd) -{ -if (epd->bio) { -int ret; - - ret =submit_one_bio (epd->bio,0 ,0 ); -BUG_ON (ret <0 );/* -ENOMEM */ - epd->bio =NULL ; - } -} -int extent_write_full_page (struct page *page,struct writeback_control *wbc) {int ret;
Signature · 1 line
2.20.1
Re: [PATCH v2 2/5] btrfs: extent_io: Kill the forward declaration of flush_write_bio()
Looks good,
Signature · 6 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
PATCH v2 3/5 btrfs: extent_io: Kill the BUG_ON() in flush_write_bio()
In reply to Qu WenruoThis BUG_ON() is really just a crappy way to workaround the _must_check attribute of submit_one_bio().
Now kill the BUG_ON() and allow flush_write_bio() to return error number.
Also add _must_check attribute to flush_write_bio(), and modify all callers to handle the possible error returned.
--- fs/btrfs/extent_io.c | 77 +++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 19 deletions(-)
fs/btrfs/extent_io.c +58 -19
@@ -169,15 +169,15 @@ static int __must_check submit_one_bio(struct bio *bio, int mirror_num,return blk_status_to_errno (ret); } -static void flush_write_bio (struct extent_page_data *epd) +static int __must_check flush_write_bio (struct extent_page_data *epd) { -if (epd->bio) { -int ret; +int ret =0 ; +if (epd->bio) { ret =submit_one_bio (epd->bio,0 ,0 ); -BUG_ON (ret <0 );/* -ENOMEM */ epd->bio =NULL ; } +return ret; }int __init extent_io_init (void )
@@ -3504,13 +3504,15 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,struct btrfs_fs_info *fs_info, struct extent_page_data *epd) { - int i, num_pages; + int i, num_pages, failed_page_nr;int flush =0 ;int ret =0 ;if (!btrfs_try_tree_write_lock (eb)) { + ret =flush_write_bio (epd); +if (ret <0 ) +return ret; flush =1 ; -flush_write_bio (epd);btrfs_tree_lock (eb); }
@@ -3519,7 +3521,9 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,if (!epd->sync_io)return 0 ;if (!flush) { -flush_write_bio (epd); + ret =flush_write_bio (epd); +if (ret <0 ) +return ret; flush =1 ; }while (1 ) {
@@ -3560,7 +3564,11 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,if (!trylock_page (p)) {if (!flush) { -flush_write_bio (epd); + ret =flush_write_bio (epd); +if (ret <0 ) { + failed_page_nr = i; + goto err_unlock; + } flush =1 ; }lock_page (p);
@@ -3568,6 +3576,15 @@ lock_extent_buffer_for_io(struct extent_buffer *eb, }return ret; + +err_unlock: +/* Unlock these already locked pages */ +for (i =0 ; i < failed_page_nr; i++) { +struct page *p = eb->pages[i]; + +unlock_page (p); + } +return ret; }static void end_extent_buffer_writeback (struct extent_buffer *eb)
@@ -3751,6 +3768,7 @@ int btree_write_cache_pages(struct address_space *mapping, .sync_io = wbc->sync_mode == WB_SYNC_ALL, };int ret =0 ; +int flush_ret;int done =0 ;int nr_to_write_done =0 ;struct pagevec pvec;
@@ -3818,6 +3836,11 @@ int btree_write_cache_pages(struct address_space *mapping, prev_eb = eb; ret =lock_extent_buffer_for_io (eb, fs_info, &epd); +if (ret <0 ) { +free_extent_buffer (eb); + done =1 ; +break ; + }if (!ret) {free_extent_buffer (eb);continue ;
@@ -3850,8 +3873,10 @@ int btree_write_cache_pages(struct address_space *mapping, index =0 ; goto retry; } -flush_write_bio (&epd); -return ret; + flush_ret =flush_write_bio (&epd); +if (ret) +return ret; +return flush_ret; }/**
@@ -3947,7 +3972,9 @@ static int extent_write_cache_pages(struct address_space *mapping,* tmpfs file mapping */ if (!trylock_page (page)) { -flush_write_bio (epd); + ret =flush_write_bio (epd); +if (ret <0 ) +break ;lock_page (page); }
@@ -3957,8 +3984,11 @@ static int extent_write_cache_pages(struct address_space *mapping, }if (wbc->sync_mode !=WB_SYNC_NONE ) { -if (PageWriteback (page)) -flush_write_bio (epd); +if (PageWriteback (page)) { + ret =flush_write_bio (epd); +if (ret <0 ) +break ; + }wait_on_page_writeback (page); }
@@ -4019,6 +4049,7 @@ static int extent_write_cache_pages(struct address_space *mapping,int extent_write_full_page (struct page *page,struct writeback_control *wbc) {int ret; +int flush_ret;struct extent_page_data epd = { .bio =NULL , .tree = &BTRFS_I (page->mapping->host)->io_tree,
@@ -4028,14 +4059,17 @@ int extent_write_full_page(struct page *page, struct writeback_control *wbc) ret =__extent_writepage (page, wbc, &epd); -flush_write_bio (&epd); -return ret; + flush_ret =flush_write_bio (&epd); +if (ret) +return ret; +return flush_ret; }int extent_write_locked_range (struct inode *inode,u64 start,u64 end,int mode) {int ret =0 ; +int flush_ret;struct address_space *mapping = inode->i_mapping;struct extent_io_tree *tree = &BTRFS_I (inode)->io_tree;struct page *page;
@@ -4068,14 +4102,17 @@ int extent_write_locked_range(struct inode *inode, u64 start, u64 end, start +=PAGE_SIZE ; } -flush_write_bio (&epd); -return ret; + flush_ret =flush_write_bio (&epd); +if (ret) +return ret; +return flush_ret; }int extent_writepages (struct address_space *mapping,struct writeback_control *wbc) {int ret =0 ; +int flush_ret;struct extent_page_data epd = { .bio =NULL , .tree = &BTRFS_I (mapping->host)->io_tree,
@@ -4084,8 +4121,10 @@ int extent_writepages(struct address_space *mapping, }; ret =extent_write_cache_pages (mapping, wbc, &epd); -flush_write_bio (&epd); -return ret; + flush_ret =flush_write_bio (&epd); +if (ret) +return ret; +return flush_ret; } int extent_readpages(struct address_space *mapping, struct list_head *pages,
Signature · 1 line
2.20.1
PATCH v2 4/5 btrfs: disk-io: Show the timing of corrupted tree block explicitly
In reply to Qu WenruoJust add one extra line to show when the corruption is detected. Currently only read time detection is possible.
--- fs/btrfs/disk-io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/btrfs/disk-io.c +4 -1
@@ -652,11 +652,14 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,*/ if (found_level ==0 &&btrfs_check_leaf_full (fs_info, eb)) {set_bit (EXTENT_BUFFER_CORRUPT , &eb->bflags); +btrfs_err (fs_info,"read time tree block corruption detected" ); ret = -EIO ; } -if (found_level >0 &&btrfs_check_node (fs_info, eb)) +if (found_level >0 &&btrfs_check_node (fs_info, eb)) { +btrfs_err (fs_info,"read time tree block corruption detected" ); ret = -EIO ; + }if (!ret)set_extent_buffer_uptodate (eb);
Signature · 1 line
2.20.1
Re: [PATCH v2 4/5] btrfs: disk-io: Show the timing of corrupted tree block explicitly
Quoted 16 lines · Qu Wenruo
Just add one extra line to show when the corruption is detected. Currently only read time detection is possible.
Reviewed-by Nikolay Borisov <[email protected]>Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/disk-io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/btrfs/disk-io.c +0
-0@@ -652,11 +652,14 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,*/ if (found_level ==0 &&btrfs_check_leaf_full (fs_info, eb)) {
fs/btrfs/disk-io.c static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, · line 662
Quoted 10 lines
fs/btrfs/disk-io.c +4
-1set_bit (EXTENT_BUFFER_CORRUPT , &eb->bflags); +btrfs_err (fs_info,"read time tree block corruption detected" ); ret = -EIO ; } -if (found_level >0 &&btrfs_check_node (fs_info, eb)) +if (found_level >0 &&btrfs_check_node (fs_info, eb)) { +btrfs_err (fs_info,"read time tree block corruption detected" ); ret = -EIO ; + }
It's still the same error message for two different checks (check_node vs. check_leaf_full).
Granted you can still refer to the messages of btrfs_check_node() and btrfs_check_leaf_full() but where's the point in having the new message?
Byte,
Johannes
Signature · 6 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH v2 4/5] btrfs: disk-io: Show the timing of corrupted tree block explicitly
Quoted 31 lines · Johannes Thumshirn
Quoted 16 lines · Qu Wenruo
Just add one extra line to show when the corruption is detected. Currently only read time detection is possible.
Reviewed-by Nikolay Borisov <[email protected]>Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/disk-io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)fs/btrfs/disk-io.c +0
-0@@ -652,11 +652,14 @@ static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio,*/ if (found_level ==0 &&btrfs_check_leaf_full (fs_info, eb)) {fs/btrfs/disk-io.c static int btree_readpage_end_io_hook(struct btrfs_io_bio *io_bio, · line 662
Quoted 10 lines
fs/btrfs/disk-io.c +4
-1set_bit (EXTENT_BUFFER_CORRUPT , &eb->bflags); +btrfs_err (fs_info,"read time tree block corruption detected" ); ret = -EIO ; } -if (found_level >0 &&btrfs_check_node (fs_info, eb)) +if (found_level >0 &&btrfs_check_node (fs_info, eb)) { +btrfs_err (fs_info,"read time tree block corruption detected" ); ret = -EIO ; + }It's still the same error message for two different checks (
check_nodevs.check_leaf_full).
Quoted 2 lines
Granted you can still refer to the messages of
btrfs_check_node()andbtrfs_check_leaf_full()but where's the point in having the new message?
To show when the error happens.
This patch only handles the read time error, thus we have two same error message.
But the next patch will introduce new write time validation check, thus we need to distinguish then by the extra message.
Thanks,
Qu
Quoted 4 lines
Byte,
Johannes
Re: [PATCH v2 4/5] btrfs: disk-io: Show the timing of corrupted tree block explicitly
Quoted 8 lines · Qu Wenruo
To show when the error happens.
This patch only handles the read time error, thus we have two same error message.
But the next patch will introduce new write time validation check, thus we need to distinguish then by the extra message.
OK, so if we really want the same message printed for all read time errors, how about this:
if (found_level == 0 && btrfs_check_leaf_full(fs_info, eb)) {
set_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags);
ret = -EIO;
}
if (found_level > 0 && btrfs_check_node(fs_info, eb))
ret = -EIO;+ if (ret == -EIO)
+ btrfs_err(fs_info,
+ "read time tree block corruption detected");
+ else if (!ret)
- if (!ret)
set_extent_buffer_uptodate(eb);
So we really only have one message printed and not duplicating the prints.
Byte,
Johannes
Signature · 6 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: Felix Imendörffer, Jane Smithard, Graham Norton HRB 21284 (AG Nürnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH v2 4/5] btrfs: disk-io: Show the timing of corrupted tree block explicitly
Quoted 29 lines · Johannes Thumshirn
Quoted 8 lines · Qu Wenruo
To show when the error happens.
This patch only handles the read time error, thus we have two same error message.
But the next patch will introduce new write time validation check, thus we need to distinguish then by the extra message.
OK, so if we really want the same message printed for all read time errors, how about this:
if (found_level == 0 && btrfs_check_leaf_full(fs_info, eb)) { set_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags); ret = -EIO; } if (found_level > 0 && btrfs_check_node(fs_info, eb)) ret = -EIO;(quoted diff) +4
-1+ if (ret == -EIO) + btrfs_err(fs_info, + "read time tree block corruption detected"); + else if (!ret) - if (!ret) set_extent_buffer_uptodate(eb);
Quoted 1 line
So we really only have one message printed and not duplicating the prints.
Works for me, I'll use this one in next version.
Thanks,
Qu
Quoted 4 lines
Byte,
Johannes
PATCH v2 5/5 btrfs: Do mandatory tree block check before submitting bio
In reply to Qu WenruoThere are at least 2 reports about memory bit flip sneaking into on-disk data.
Currently we only have a relaxed check triggered at btrfs_mark_buffer_dirty() time, as it's not mandatory, only for CONFIG_BTRFS_FS_CHECK_INTEGRITY enabled build.
This patch will address the hole by triggering comprehensive check on tree blocks before writing it back to disk.
The timing is set to csum_tree_block() where @verify == 0. At that timing, we're generation csum for tree blocks before submitting the metadata bio, so we could avoid all the unnecessary calls at btrfs_mark_buffer_dirty(), but still catch enough error.
The example error output will be something like:
BTRFS critical (device dm-3): corrupt leaf: root=2 block=1350630375424 slot=68, bad key order, prev (10510212874240 169 0) current (1714119868416 169 0) BTRFS error (device dm-3): write time tree block corruption detected
BTRFS critical (device dm-3): corrupt leaf: root=2 block=1350630375424 slot=68, bad key order, prev (10510212874240 169 0) current (1714119868416 169 0) BTRFS error (device dm-3): write time tree block corruption detected
BTRFS: error (device dm-3) in btrfs_commit_transaction:2220: errno=-5 IO failure (Error while writing out transaction)
BTRFS info (device dm-3): forced readonly
BTRFS warning (device dm-3): Skipping commit of aborted transaction.
BTRFS: error (device dm-3) in cleanup_transaction:1839: errno=-5 IO failure
BTRFS info (device dm-3): delayed_refs has NO entry
--- fs/btrfs/disk-io.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/btrfs/disk-io.c +9 -0
@@ -313,6 +313,15 @@ static int csum_tree_block(struct btrfs_fs_info *fs_info,return -EUCLEAN ; } }else { +if (btrfs_header_level (buf)) + err =btrfs_check_node (fs_info, buf); +else + err =btrfs_check_leaf_full (fs_info, buf); +if (err <0 ) { +btrfs_err (fs_info, +"write time tree block corruption detected" ); +return err; + }write_extent_buffer (buf, result,0 , csum_size); }
Signature · 1 line
2.20.1