Skip to content

btrfs: btrfs: fix possible race between error handling and writeback

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 Latest4 patches 5 repliesIn review
  2. v13 patches 3 repliesSuperseded

Changes in v2 from the cover letter

- Add a new patch to explain the error handling better
This makes the later nocow_one_range() error handling change easier to explain.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4btrfs: rework the error handling of run_delalloc_nocow()fs/btrfs/inode.c+61 -590 replies
2/4btrfs: enhance error messages for delalloc range failurefs/btrfs/inode.c+18 -110 replies
3/4btrfs: make nocow_one_range() to do cleanup on errorfs/btrfs/inode.c+38 -210 replies
4/4btrfs: keep folios locked inside run_delalloc_nocow()fs/btrfs/inode.c+22 -512 replies

Reviews trailers per patch

1 of 4 patches has a Reviewed-by or Acked-by.

PatchBoris Burkov
1/4
2/4R-b
3/4
4/4

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

Read the v2 thread

Cover letter [PATCH v2 0/4] btrfs: btrfs: fix possible race between error handling and writeback

[CHANGELOG]
v2:
- Add a new patch to explain the error handling better
This makes the later nocow_one_range() error handling change easier to explain.

There are some rare kernel warning for experimental btrfs builds that the DEBUG_WARN() can be triggered from btrfs_writepage_cow_fixup(), mostly after some delalloc range failure.

The root cause is explained the the last patch, the TL;DR is we shouldn't call btrfs_cleanup_ordered_extents() on folios that are already unlocked.

Those unlocked folios can be under writeback, and if we cleared the order flag just before the writeback thread entering btrfs_writepage_cow_fixup(), we will trigger the warning.

The first patch enhance the error handling of run_delalloc_nocow(), with proper comments and charts explaining the cleanup range.

The second patch is a small enhancement to the error messages, which helps debugging.

The third patch is to make nocow_one_range() to do proper cleanup, aligning itself to cow_file_range().

The last one is to fix the race window by keep folios of successful ranges locked, so that we either unlock them manually at the end of run_delalloc_nocow(), or get btrfs_cleanup_ordered_extents() called on locked folios for error handling.

Qu Wenruo (4):
btrfs: rework the error handling of run_delalloc_nocow()
btrfs: enhance error messages for delalloc range failure
btrfs: make nocow_one_range() to do cleanup on error
btrfs: keep folios locked inside run_delalloc_nocow()

 fs/btrfs/inode.c | 259 +++++++++++++++++++++++------------------------
 1 file changed, 128 insertions(+), 131 deletions(-)
Signature · 1 line
2.50.1