Skip to content

btrfs: fix filesystem corruption caused by space cache race

Omar Sandoval linux-btrfs 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 26 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2btrfs: fix space cache corruption and potential double allocationsfs/btrfs/block-group.c fs/btrfs/block-group.h fs/btrfs/extent-tree.c+21 -4818 replies
2/2btrfs: get rid of block group caching progress logicfs/btrfs/block-group.c fs/btrfs/block-group.h fs/btrfs/extent-tree.c +3 more+2 -724 replies

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchFilipe Manana
1/2R-b
2/2R-b

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

Read the v1 thread

Cover letter [PATCH 0/2] btrfs: fix filesystem corruption caused by space cache race

From: Omar Sandoval <[email protected]>

Hello,

We recently deployed space_cache v2 on a large set of machines to do some performance comparisons and found a nasty filesystem corruption bug that was introduced by the fsync transaction optimization in 5.12. It's much more likely to affect space_cache=v2 and nospace_cache, but since space_cache=v1 effectively falls back to nospace_cache if there is a free space inode generation mismatch, space_cache=v1 could also theoretically be affected. discard/discard=sync also makes the bug much easier to hit by making the race window larger.

Patch 1 is the fix itself with a lot more details. Patch 2 is a followup cleanup.

I'm still working on a reproducer, but I wanted to get this fix out ASAP.

Thanks!

Omar Sandoval (2):
btrfs: fix space cache corruption and potential double allocations
btrfs: get rid of block group caching progress logic

 fs/btrfs/block-group.c     | 49 +++++++++++---------------------------
 fs/btrfs/block-group.h     |  5 +---
 fs/btrfs/extent-tree.c     | 39 +++++++-----------------------
 fs/btrfs/free-space-tree.c |  8 -------
 fs/btrfs/transaction.c     | 41 -------------------------------
 fs/btrfs/zoned.c           |  1 -
 6 files changed, 23 insertions(+), 120 deletions(-)
Signature · 1 line
2.37.2