]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commit
btrfs/327: add a test case to verify inline extent data read v2024.12.01
authorQu Wenruo <wqu@suse.com>
Fri, 15 Nov 2024 09:19:26 +0000 (19:49 +1030)
committerZorro Lang <zlang@kernel.org>
Fri, 29 Nov 2024 03:20:18 +0000 (11:20 +0800)
commit8467552f09e1672a02712653b532a84bd46ea10e
treedb63bd486ae1f8c4c6a2d9b07d144aa5380d193d
parent4906a5ab94ee4a75c9bb013cfb8a832b887a4fd0
btrfs/327: add a test case to verify inline extent data read

[BUG]
When developing sector size < page size handling for btrfs, I'm hitting
a data corruption, which is only possible with the following out-of-tree
patches:

  btrfs: allow inline data extents creation if sector size < page size
  btrfs: allow buffered write to skip full page if it's sector aligned

[CAUSE]
Thankfully no upstream kernels are affected, even if some one is
mounting a btrfs created by x86_64 with inlined data extents, they won't
hit the corruption.

The root cause is that when reading inline extents, we zero out the
whole remaining range until folio end.

This means such zeroing out can cover ranges that is dirtied but not yet
written back, thus lead to data corruption.

This needs all the following conditions to be met:

- Sector size < page size
  So no x86_64 is affected. The most common users should be Asahi Linux.
  But they are safe due to the next two conditions.

- Inline data extents are present
  For sector size < page size cases, we do not allow creating new inline
  data extents but only reading it.

  But even all above cases are met by using a x86_64 created btrfs with
  inlined data extents, the next point will still save us.

- Partial uptodate folios are allowed
  This requires the out-of-tree patch "btrfs: allow buffered write to skip
  full page if it's sector aligned", or buffered write will read out the
  whole folio before dirting any range.

So end users are completely safe.

[TEST CASE]
The test case itself is pretty straightforward:

- Buffered write [0, 4k)
- Drop all page cache
- Buffered write [8k, 12k)
- Verify the file content

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Signed-off-by: Zorro Lang <zlang@kernel.org>
tests/btrfs/327 [new file with mode: 0755]
tests/btrfs/327.out [new file with mode: 0644]