Skip to content

btrfs-progs: check: properly generate csum for various complex combinations

Qu Wenruo linux-btrfs 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 4 repliesIn review
  2. v15 patches 1 replySuperseded

Changes in v2 from the cover letter

- Handle written extents then hole punched cases
Now we always generate csum for a data extent as long as it doesn't belong to a NODATASUM inode, then remove the csum for preallocated range.

- Enhance test case to include hole punching and compressed extents

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5btrfs-progs: backref: properly queue indirect refskernel-shared/backref.c+8 -20 replies
2/5btrfs-progs: check: move csum tree population into mode-common.[ch]check/main.c check/mode-common.c check/mode-common.h+245 -2440 replies
3/5btrfs-progs: check: don't calculate csum for preallocated file extentscheck/mode-common.c+105 -10 replies
4/5btrfs-progs: check: handle csum generation properly for `--init-csum-tree --init-extent-tree`check/mode-common.c+49 -40 replies
5/5btrfs-progs: fsck-tests: add test case for init-csum-treetests/fsck-tests/052-init-csum-tree/test.sh+72 -03 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/5] btrfs-progs: check: properly generate csum for various complex combinations

[BUG]
Issue #420 mentions that --init-csum-tree creates extra csum for preallocated extents.

Causing extra errors after --init-csum-tree.

[CAUSE]
Csum re-calculation code doesn't take the following factors into consideration:

- NODATASUM inodes
- Preallocated extents
No csum should be calculated for those data extents

- Partically written preallocated csum
Csum should only be created for the referred part

So currently csum recalculation will just create csum for any data extents it found, causing the mentioned errors.

[FIX]
- Bug fix for backref iteration
Firstly fix a bug in backref code where indirect ref is not properly resolved.

This allows us to use iterate_extent_inodes() to make our lives much easier checking the file extents.

- Code move for --init-csum-tree
Move it to mode independent mode-common.[ch]

- Fix for --init-csum-tree
There are some extreme corner cases to consider, in fact we can not really determine a range should have csum or not:
* Preallocated, written, then hole punched range
Should still have csum for the written (now hole) part.

* Preallocated, then hole punched range.
Should not have csum for the now hole part.

* Regular written extent, then hole punched range Should have csum for the now hole part.

But there is still one thing to follow, if a range is preallocated, it should not have csum.

So here we go a different route, by always generate csum for the whole extent (as long as it's not belonging to NODATASUM inode), then remove csums for preallocated range.

- Fix for --init-csum-tree --init-extent-tree
The same fix, just into a different context

- New test case

[CHANGELOG]
v2:
- Handle written extents then hole punched cases
Now we always generate csum for a data extent as long as it doesn't belong to a NODATASUM inode, then remove the csum for preallocated range.

- Enhance test case to include hole punching and compressed extents

Qu Wenruo (5):
btrfs-progs: backref: properly queue indirect refs
btrfs-progs: check: move csum tree population into mode-common.[ch]
btrfs-progs: check: don't calculate csum for preallocated file extents
btrfs-progs: check: handle csum generation properly for

    `--init-csum-tree --init-extent-tree`

btrfs-progs: fsck-tests: add test case for init-csum-tree

 check/main.c                                | 244 ------------
 check/mode-common.c                         | 393 ++++++++++++++++++++
 check/mode-common.h                         |   1 +
 kernel-shared/backref.c                     |  10 +-
 tests/fsck-tests/052-init-csum-tree/test.sh |  72 ++++
 5 files changed, 474 insertions(+), 246 deletions(-)
 create mode 100755 tests/fsck-tests/052-init-csum-tree/test.sh
Signature · 1 line
2.34.1