btrfs: qgroup: detect and fix leaked data reserved space
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest5 patches 1 replyIn review
- v35 patches 7 repliesSuperseded
- v25 patches 0 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 2 patches | 9 replies | Superseded |
Changes in v4 from the cover letter
- Pure changelog update to co-operate with the dio iomap revert Only the 1st and the 4th patches get updated.
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/5 | btrfs: inode: refactor the parameters of insert_reserved_file_extent()fs/ fs/ | +68 | 0 replies | |
| 2/5 | btrfs: inode: move qgroup reserved space release to the callers of insert_reserved_file_extent()fs/ | +13 | 0 replies | |
| 3/5 | btrfs: file: reserve qgroup space after the hole punch range is lockedfs/ | +4 | 0 replies | |
| 4/5 | btrfs: change the timing for qgroup reserved space for ordered extents to fix reserved space leakfs/ fs/ fs/ | +25 | 0 replies | |
| 5/5 | btrfs: qgroup: catch reserved space leakage at unmount timefs/ fs/ fs/ | +49 | 0 replies |
Reviews trailers per patch
All 5 patches have a Reviewed-by or Acked-by.
| Patch | Josef Bacik | David Sterba |
|---|---|---|
| 1/5 | R-b | R-b |
| 2/5 | R-b | R-b |
| 3/5 | R-b | R-b |
| 4/5 | R-b | |
| 5/5 | R-b | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v4 0/5] btrfs: qgroup: detect and fix leaked data reserved space
There is an internal report complaining that qgroup is only half of the limit, but they still get EDQUOT errors.
With some extra debugging patch added, it turns out that even fsstress with 10 steps can sometimes cause qgroup reserved data space to leak.
The root cause is the chaotic lifespan of qgroup data rsv. Here is the chart explaining the difference between the old and new lifespan of qgroup data rsv:
||: Qgroup data rsv is reserved |: Qgroup data rsv is released but not freed
: Qgroup data rsv is freed
The old The new
TT TT Page get dirtied
|| ||
|| ||
|| ------------ || --------- btrfs_run_delalloc_range()
|| | |- btrfs_add_ordered_extent()
|| |
| ------------ | --------- btrfs_finish_ordered_io()
| |
------------ --------- btrfs_account_extents()Since there is a large window between btrfs_add_ordered_extent() and btrfs_finish_ordered_io(), during which page can be released and clear the QGROUP_RESERVED bit.
In fact during dio, dio will try to flush the range, and then invalidate the pages before submitting direct IO.
Due to the fact that filemap_write_and_wait_range() will only wait for page writeback get cleared, not page dirty cleared, so it will release pages before btrfs_finish_ordered_io() get executed, and clearing QGROUP_RESERVED bit without triggering qgroup rsv release, leading to qgroup data rsv leakage.
With the new timing, QGROUP_RESERVED bit is cleared before filemap_write_and_wait_range() returns, and doing proper qgroup rsv releasing, so there is no window to screw up qgroup rsv anymore.
Although to co-operate the timing change, quite some existing chaotic btrfs_qgroup_release/free_data() calls must be modified/removed to follow the more restrict calling protocol.
But overall, this make the qgroup data rsv lifespan more clear, so it should be still worthy.
After all the big timing change and fixes, add an extra and hopefully final safe net to catch qgroup data rsv leakage.
Now extent io tree based QGROUP_RESERVED bit should detect case like missing btrfs_qgroup_release/free_data() call, while the unmount check should detect unexpected QGROUP_RESERVED bit clearing.
The existing test case btrfs/022 can already catch the bug pretty reliably.
Changelog:
v2:
- Change the lifespan of qgroup data rsv
From the original whac-a-mole method to a more proper timing, to use ordered extents as the proper owner of qgroup data rsv.
- Add commit message for the final patch
- Adds extra refactor to make insert_reserved_file_extent() use less parameters
v3:
- Remove the redundant WARN() message
- Reduce the scope of struct btrfs_qgroup in btrfs_qgroup_has_leak()
v4:
- Pure changelog update to co-operate with the dio iomap revert Only the 1st and the 4th patches get updated.
Qu Wenruo (5):
btrfs: inode: refactor the parameters of insert_reserved_file_extent()
btrfs: inode: move qgroup reserved space release to the callers of
insert_reserved_file_extent()
btrfs: file: reserve qgroup space after the hole punch range is locked
btrfs: change the timing for qgroup reserved space for ordered extents
to fix reserved space leak
btrfs: qgroup: catch reserved space leakage at unmount time
fs/btrfs/ctree.h | 6 +- fs/btrfs/disk-io.c | 5 ++ fs/btrfs/file.c | 8 +-- fs/btrfs/inode.c | 119 +++++++++++++++++++++++----------------- fs/btrfs/ordered-data.c | 22 +++++++- fs/btrfs/ordered-data.h | 3 + fs/btrfs/qgroup.c | 43 +++++++++++++++ fs/btrfs/qgroup.h | 1 + 8 files changed, 151 insertions(+), 56 deletions(-)
Signature · 1 line
2.27.0