Skip to content

btrfs: trim: Fix a bug certain range may not be trimmed properly

Qu Wenruo linux-btrfs 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest2 patches 3 repliesIn review
  2. v32 patches 4 repliesSuperseded
  3. v22 patches 3 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches4 repliesSuperseded

Changes in v4 from the cover letter

- Use better ASCII graph to show the bug
No code change at all.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2btrfs: volumes: Use more straightforward way to calculate map lengthfs/btrfs/volumes.c+1 -11 reply
2/2btrfs: extent-tree: Ensure we trim ranges across block group boundaryfs/btrfs/extent-tree.c fs/btrfs/volumes.c+35 -122 replies

Reviews trailers per patch

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

PatchJosef Bacik
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 v4 thread

Cover letter [PATCH v4 0/2] btrfs: trim: Fix a bug certain range may not be trimmed properly

There is a bug report about discard mount option not trimming some range properly, and causing unexpected space usage for thin device.

It turns out to be that, if there are pinned extents across block group boundary, we will only trim to the end of current block group, skipping the remaining.

This patchset will fix it by ensuring btrfs_discard_extent() will iterate the full range before exiting.

The first patch is just a tiny readability improvement found during the fix.
The second patch is the main body of the fix.

Meanwhile I'm still looking into how to craft such test case for btrfs, so the test case may be late for several days.

Changelog:
v2:
- Fold the __btrfs_map_block_for_discard() @length change into the main patch
Since the @length parameter change itself doesn't make much sense, folding it into the fix looks more reasonable.

- Split the tiny readability improvement patch into its own patch

v3:
- Reset @num_bytes for btrfs_map_block() to limit the trim range inside the original range.
Or we can trim into existing extent to corrupt data.

v4:
- Use better ASCII graph to show the bug
No code change at all.

Qu Wenruo (2):
btrfs: volumes: Use more straightforward way to calculate map length
btrfs: extent-tree: Ensure we trim ranges across block group boundary

 fs/btrfs/extent-tree.c | 41 +++++++++++++++++++++++++++++++----------
 fs/btrfs/volumes.c     |  8 +++++---
 2 files changed, 36 insertions(+), 13 deletions(-)
Signature · 1 line
2.23.0