btrfs: Enhancement to tree block validation
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
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 | 122 ++++++++++++++++++++++++++----------------- 2 files changed, 90 insertions(+), 52 deletions(-)
Signature · 1 line
2.20.1
PATCH 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
PATCH 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 2/5] btrfs: extent_io: Kill the forward declaration of flush_write_bio()
Quoted 7 lines · Qu Wenruo
There is no need to forward declare
flush_write_bio(), as it only depends onsubmit_one_bio().Both of them are pretty small, just move them to kill the forward declaration.
Signed-off-by Qu Wenruo <[email protected]>
I'm very much in favor of killing forward declarations for static functions.
Quoted 96 lines
--- 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;
PATCH 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 | 64 +++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 18 deletions(-)
fs/btrfs/extent_io.c +46 -18
@@ -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 )
@@ -3509,8 +3509,10 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,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,9 @@ 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 ) +return ret; flush =1 ; }lock_page (p);
@@ -3751,6 +3757,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 +3825,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 +3862,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 +3961,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 +3973,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 +4038,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 +4048,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 +4091,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 +4110,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
Re: [PATCH 3/5] btrfs: extent_io: Kill the BUG_ON() in flush_write_bio()
Quoted 62 lines · Qu Wenruo
This
BUG_ON()is really just a crappy way to workaround the_must_checkattribute ofsubmit_one_bio().Now kill the
BUG_ON()and allowflush_write_bio()to return error number.Also add
_must_checkattribute toflush_write_bio(), and modify all callers to handle the possible error returned.Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/extent_io.c | 64 +++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 18 deletions(-)fs/btrfs/extent_io.c +10
-6@@ -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 )@@ -3509,8 +3509,10 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,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 ) {
fs/btrfs/extent_io.c lock_extent_buffer_for_io(struct extent_buffer *eb, · line 3569
Quoted 7 lines
fs/btrfs/extent_io.c +3
-1@@ -3560,7 +3564,9 @@ 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 ) +return ret;
Can't you end up with partially locked pages here? Are you sure that flush_write_bio will ALWAYS be executed when i = 0? If that\'s the case then I think an assert(i == 0) is in order there.
Quoted 3 lines
fs/btrfs/extent_io.c +0
-0flush =1 ; }lock_page (p);
<snip>
Re: [PATCH 3/5] btrfs: extent_io: Kill the BUG_ON() in flush_write_bio()
Quoted 66 lines · Nikolay Borisov
Quoted 63 lines · Qu Wenruo
This
BUG_ON()is really just a crappy way to workaround the_must_checkattribute ofsubmit_one_bio().Now kill the
BUG_ON()and allowflush_write_bio()to return error number.Also add
_must_checkattribute toflush_write_bio(), and modify all callers to handle the possible error returned.Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/extent_io.c | 64 +++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 18 deletions(-)fs/btrfs/extent_io.c +10
-6@@ -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 )@@ -3509,8 +3509,10 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,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,9 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,
Quoted 10 lines
fs/btrfs/extent_io.c lock_extent_buffer_for_io(struct extent_buffer *eb, · line 3569
Quoted 6 lines
fs/btrfs/extent_io.c +3
-1if (!trylock_page (p)) {if (!flush) { -flush_write_bio (epd); + ret =flush_write_bio (epd); +if (ret <0 ) +return ret;Can't you end up with partially locked pages here? Are you sure that
flush_write_biowill ALWAYS be executed when i = 0? If that\'s the case then I think an assert(i == 0) is in order there.
An ASSERT() indeed makes sense here.
Although I could also make it better by recording the failed page number and unlock those already locked pages.
I'm OK either way.
Thanks,
Qu
Quoted 7 lines
Quoted 4 lines
fs/btrfs/extent_io.c +0
-0flush =1 ; }lock_page (p);<snip>
Re: [PATCH 3/5] btrfs: extent_io: Kill the BUG_ON() in flush_write_bio()
Quoted 80 lines · Qu Wenruo
Quoted 66 lines · Nikolay Borisov
Quoted 63 lines · Qu Wenruo
This
BUG_ON()is really just a crappy way to workaround the_must_checkattribute ofsubmit_one_bio().Now kill the
BUG_ON()and allowflush_write_bio()to return error number.Also add
_must_checkattribute toflush_write_bio(), and modify all callers to handle the possible error returned.Signed-off-by Qu Wenruo <[email protected]>--- fs/btrfs/extent_io.c | 64 +++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 18 deletions(-)fs/btrfs/extent_io.c +10
-6@@ -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 )@@ -3509,8 +3509,10 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,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,9 @@ lock_extent_buffer_for_io(struct extent_buffer *eb,Quoted 10 lines
fs/btrfs/extent_io.c lock_extent_buffer_for_io(struct extent_buffer *eb, · line 3569
Quoted 6 lines
fs/btrfs/extent_io.c +3
-1if (!trylock_page (p)) {if (!flush) { -flush_write_bio (epd); + ret =flush_write_bio (epd); +if (ret <0 ) +return ret;Can't you end up with partially locked pages here? Are you sure that
flush_write_biowill ALWAYS be executed when i = 0? If that\'s the case then I think an assert(i == 0) is in order there.
Quoted 4 lines
An
ASSERT()indeed makes sense here.Although I could also make it better by recording the failed page number and unlock those already locked pages.
Unlocking is the correct way to handle it, the assert would be there to prove that you won't ever need the unlocking code. If it triggers then this case must be handled.
Quoted 13 lines
I'm OK either way.
Thanks,
QuQuoted 7 lines
Quoted 4 lines
fs/btrfs/extent_io.c +0
-0flush =1 ; }lock_page (p);<snip>
PATCH 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 4/5] btrfs: disk-io: Show the timing of corrupted tree block explicitly
Quoted 4 lines · Qu Wenruo
Just add one extra line to show when the corruption is detected. Currently only read time detection is possible.
Signed-off-by Qu Wenruo <[email protected]>
Quoted 25 lines
--- 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);
PATCH 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