btrfs: make btrfs_check_nocow_lock() check more than one extent
authorFilipe Manana <fdmanana@suse.com>
Wed, 9 Jul 2025 15:34:20 +0000 (16:34 +0100)
committerDavid Sterba <dsterba@suse.com>
Mon, 21 Jul 2025 22:09:22 +0000 (00:09 +0200)
commit240fafaa4400f7c577a5e8e40c496663da0e0798
tree4760597a9ddfcd185a4eb3cd396b15275470ef8e
parent68e0fcc3617b7a61ab93eeb6d8b935046d152685
btrfs: make btrfs_check_nocow_lock() check more than one extent

Currently btrfs_check_nocow_lock() stops at the first extent it finds and
that extent may be smaller than the target range we want to NOCOW into.
But we can have multiple consecutive extents which we can NOCOW into, so
by stopping at the first one we find we just make the caller do more work
by splitting the write into multiple ones, or in the case of mmap writes
with large folios we fail with -ENOSPC in case the folio's range is
covered by more than one extent (the fallback to NOCOW for mmap writes in
case there's no available data space to reserve/allocate was recently
added by the patch "btrfs: fix -ENOSPC mmap write failure on NOCOW
files/extents").

Improve on this by checking for multiple consecutive extents.

Reviewed-by: Boris Burkov <boris@bur.io>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/file.c