Skip to content

btrfs: Enhancement to tree block validation

Qu Wenruo linux-btrfs 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest12 patches 4 repliesIn review
  2. v412 patches 20 repliesSuperseded
  3. v35 patches 10 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v25 patches7 repliesSuperseded
v15 patches5 repliesSuperseded

Changes in v5 from the cover letter

- Do proper error-out handling other than relying on flush_write_bio() to clean up.
This has a side effect that no Reviewed-by tags for modified patches.
- New comment for why we don't need to do anything about ebp->bio when submit_one_bio() fails.
- Add some Reviewed-by tag.

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/12btrfs: Always output error message when key/level verification failsfs/btrfs/disk-io.c+4 -60 replies
2/12btrfs: extent_io: Kill the forward declaration of flush_write_bio()fs/btrfs/extent_io.c+32 -340 replies
3/12btrfs: disk-io: Show the timing of corrupted tree block explicitlyfs/btrfs/disk-io.c+2 -00 replies
4/12btrfs: extent_io: Move the BUG_ON() in flush_write_bio() one level upfs/btrfs/extent_io.c+41 -140 replies
5/12btrfs: extent_io: Handle error better in extent_write_full_page()fs/btrfs/extent_io.c+21 -30 replies
6/12btrfs: extent_io: Handle error better in btree_write_cache_pages()fs/btrfs/extent_io.c+6 -30 replies
7/12btrfs: extent_io: Kill the dead branch in extent_write_cache_pages()fs/btrfs/extent_io.c+0 -50 replies
8/12btrfs: extent_io: Handle error better in extent_write_locked_range()fs/btrfs/extent_io.c+6 -30 replies
9/12btrfs: extent_io: Kill the BUG_ON() in lock_extent_buffer_for_io()fs/btrfs/extent_io.c+20 -50 replies
10/12btrfs: extent_io: Kill the BUG_ON() in extent_write_cache_pages()fs/btrfs/extent_io.c+8 -20 replies
11/12btrfs: extent_io: Handle error better in extent_writepages()fs/btrfs/extent_io.c+6 -30 replies
12/12btrfs: Do mandatory tree block check before submitting biofs/btrfs/disk-io.c fs/btrfs/tree-checker.c fs/btrfs/tree-checker.h+38 -30 replies

Reviews trailers per patch

6 of 12 patches have a Reviewed-by or Acked-by.

PatchNikolay BorisovJohannes Thumshirn
1/12R-b R-b
2/12R-b R-b
3/12R-b R-b
4/12R-b
5/12
6/12
7/12R-b
8/12
9/12
10/12R-b
11/12
12/12

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH v5 00/12] 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.
Also there is no conflict rebasing the patchset to misc-next.

This patchset has the following 3 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: 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

- Better error handling before calling flush_write_bio() One hidden reason of calling flush_write_bio() under all cases is, flush_write_bio() will trigger endio function and endio function of epd->bio will free the bio under all cases.
So we're in fact abusing flush_write_bio() as cleanup.

Since now flush_write_bio() has its own return value, we shouldn't call flush_write_bio() no-brain, here we introduce proper cleanup helper, end_write_bio(). Now we call flush_write_bio() like:
New | Old
--------------------------------------------------------------
ret = do_some_evil(&epd); | ret = do_some_evil(&epd);
if (ret < 0) { | flush_write_bio(&epd);
end_write_bio(&epd, ret); | ^^^ submitting half-backed epd->bio?
return ret; | return ret;

  }                               |
  ret = flush_write_bio(&epd);    |
  return ret;                     |

Above code should be more streamline for the error handling part.

Changelog:
v2:
- Unlock locked pages in lock_extent_buffer_for_io() for error handling.
- Added Reviewed-by tags.

v3:
- Remove duplicated error message.
- Use IS_ENABLED() macro to replace #ifdef.
- Added Reviewed-by tags.

v4:
- Re-organized patch split
Now each BUG_ON() cleanup has its own patch
- Dig much further into the call sites to eliminate unexpected >0 return May be a little paranoid and abuse some ASSERT(), but it should be much safer against further code change.
- Fix the false alert caused by balance and memory pressure The fix it skip owner checker for non-essential tree at write time. Since owner root can't always be reliable, either due to commit root created in current transaction or balance + memory pressure.

v5:
- Do proper error-out handling other than relying on flush_write_bio() to clean up.
This has a side effect that no Reviewed-by tags for modified patches.
- New comment for why we don't need to do anything about ebp->bio when submit_one_bio() fails.
- Add some Reviewed-by tag.

Qu Wenruo (12):
btrfs: Always output error message when key/level verification fails
btrfs: extent_io: Kill the forward declaration of flush_write_bio()
btrfs: disk-io: Show the timing of corrupted tree block explicitly
btrfs: extent_io: Move the BUG_ON() in flush_write_bio() one level up
btrfs: extent_io: Handle error better in extent_write_full_page()
btrfs: extent_io: Handle error better in btree_write_cache_pages()
btrfs: extent_io: Kill the dead branch in extent_write_cache_pages()
btrfs: extent_io: Handle error better in extent_write_locked_range()
btrfs: extent_io: Kill the BUG_ON() in lock_extent_buffer_for_io()
btrfs: extent_io: Kill the BUG_ON() in extent_write_cache_pages()
btrfs: extent_io: Handle error better in extent_writepages()
btrfs: Do mandatory tree block check before submitting bio

 fs/btrfs/disk-io.c      |  21 +++--
 fs/btrfs/extent_io.c    | 168 ++++++++++++++++++++++++++++------------
 fs/btrfs/tree-checker.c |  24 +++++-
 fs/btrfs/tree-checker.h |   8 ++
 4 files changed, 162 insertions(+), 59 deletions(-)
Signature · 1 line
2.20.1