Skip to content

btrfs: handle signal interruption during relocation more gracefully

Qu Wenruo linux-btrfs 2 versions – Applied

Status from this message: I applied these to a 5.7.9 kernel.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest4 patches 2 repliesApplied
  2. v1 RFC2 patches 9 repliesSuperseded

Changes in v3 from the cover letter

- Add back the not-yet-merged first patch
- Rephrase the commit message of the 2nd patch
- Add comment for the 3rd patch about the canceled balance return value
- Add a new patch explaining the flushing level

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/4btrfs: relocation: allow signal to cancel balancefs/btrfs/relocation.c+2 -10 replies
2/4btrfs: avoid possible signal interruption for btrfs_drop_snapshot() on relocation treefs/btrfs/extent-tree.c+4 -10 replies
3/4btrfs: relocation: review the call sites which can be interrupted by signalfs/btrfs/relocation.c fs/btrfs/volumes.c+24 -30 replies
4/4btrfs: Add comments for btrfs_reserve_flush_enumfs/btrfs/ctree.h+32 -20 replies

Reviews trailers per patch

2 of 4 patches have a Reviewed-by or Acked-by.

PatchJosef Bacik
1/4R-b
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 v3 thread

Cover letter [PATCH v3 0/4] btrfs: handle signal interruption during relocation more gracefully

This bug is reported by Hans van Kranenburg <[email protected]>, that when a running btrfs balance get fatal signals (including SIGINT), some bad things can happen, mostly forced RO caused by -EINTR.

It turns out that, although we have addressed the btrfs balance cancel problems, we haven't addressed the signal related problems.

In theory, processes trapped into kernel space won't get interrupted by signals, as signal callbacks happen in user space, but kernel code can still check pending signals and change behavior accordingly.

In this case, the culprit is that, wait_reserve_ticket() can return -EINTR if there is a pending fatal signal.

While for balance, a lot of situations can't handle the -EINTR from it, especially for critical cleanup phase.

This patchset will address the bug in two directions:
- Catch fatal signal early
Now btrfs_should_cancel_balance() will also check pending signals. And will exit gracefully and treat it as a canceled balance.

- Don't allow -EINTR for critical cleanup
For btrfs_drop_snapshot() for reloc trees, we shouldn't be interrupted by signal, thus we use btrfs_join_transaction() instead of btrfs_start_transaction().
And for other critical call sites, change the flushing level to avoid signal interruption.
We also enhance the comment for the btrfs_reserve_flush_enum, to make it easier to grasp.

Changelog:
v1:
- Change the callers of ticketing system
Still allow certain tickets to be interrupted by signals, and change the call sites to avoid signal interruption.

v2:
- Add comment for why we can reduce the meta rsv for tree swap

v3:
- Add back the not-yet-merged first patch
- Rephrase the commit message of the 2nd patch
- Add comment for the 3rd patch about the canceled balance return value
- Add a new patch explaining the flushing level

Qu Wenruo (4):
btrfs: relocation: allow signal to cancel balance
btrfs: avoid possible signal interruption for btrfs_drop_snapshot() on
relocation tree
btrfs: relocation: review the call sites which can be interrupted by
signal
btrfs: Add comments for btrfs_reserve_flush_enum

 fs/btrfs/ctree.h       | 34 ++++++++++++++++++++++++++++++++--
 fs/btrfs/extent-tree.c |  5 ++++-
 fs/btrfs/relocation.c  | 16 +++++++++++++---
 fs/btrfs/volumes.c     | 14 +++++++++++++-
 4 files changed, 62 insertions(+), 7 deletions(-)
Signature · 1 line
2.27.0