]> git.hungrycats.org Git - linux/commit
btrfs: reflink: undo delalloc if inline extent decompression fails
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 26 Oct 2026 19:26:36 +0000 (15:26 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 26 Oct 2026 19:26:36 +0000 (15:26 -0400)
commitbe33f3b2272b357904ead23cff12a8e7007d612b
tree82ad6221af1e77198d6459c380a2815268810738
parentf36cf85b9ec74df310e9a8f24e53d5142b6cad93
btrfs: reflink: undo delalloc if inline extent decompression fails

copy_inline_to_page() marks the destination block delalloc with
btrfs_reset_extent_delalloc() before it copies or decompresses the inline
data into the folio, and dirties the folio only once the data is there.
If btrfs_decompress() fails, the error path releases the space reserved
for the block but leaves EXTENT_DELALLOC (and EXTENT_DELALLOC_NEW, if the
block had no extent) set on a block whose folio is not dirty.  Writeback
never visits it, so the bit stays, and with it an outstanding extent, the
inode's delalloc_bytes and new_delalloc_bytes and its place on the root's
delalloc list.  When the folio is invalidated or the inode evicted, the
stale bit is cleared with EXTENT_DO_ACCOUNTING, which releases the block's
data and metadata reservation a second time.

The decompressors also write the destination range on failure (zeroes, or
part of the data), so a block that was uptodate in the page cache no
longer matches what is on disk, and reads keep returning it.

On a decompression failure, clear the delalloc bits, without
EXTENT_DO_ACCOUNTING or the reservation release bits since the error path
releases the reservation, and clear the block's uptodate state so the next
read gets it from disk.

Fixes: 05a5a7621ce6 ("Btrfs: implement full reflink support for inline extents")
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/reflink.c