]> Gentwo Git Trees - linux/.git/commit
btrfs: rework error handling of run_delalloc_nocow()
authorQu Wenruo <wqu@suse.com>
Mon, 28 Jul 2025 08:27:54 +0000 (17:57 +0930)
committerDavid Sterba <dsterba@suse.com>
Mon, 22 Sep 2025 08:54:32 +0000 (10:54 +0200)
commit3239c44df756bbc28182eb05aeeea84875c315fe
treef81a74e09480e7688ec10aafeea0c322e7856791
parent46d33a0cc484ceb11aa47166e66d349ab3074eef
btrfs: rework error handling of run_delalloc_nocow()

Currently the error handling of run_delalloc_nocow() modifies
@cur_offset to handle different parts of the delalloc range.

However the error handling can always be split into 3 parts:

1) The range with ordered extents allocated (OE cleanup)
   We have to cleanup the ordered extents and unlock the folios.

2) The range that have been cleaned up (skip)
   For now it's only for the range of fallback_to_cow().

   We should not touch it at all.

3) The range that is not yet touched (untouched)
   We have to unlock the folios and clear any reserved space.

This 3 ranges split has the same principle as cow_file_range(), however
the NOCOW/COW handling makes the above 3 range split much more complex:

a) Failure immediately after a successful OE allocation
   Thus no @cow_start nor @cow_end set.

   start         cur_offset               end
   | OE cleanup  |       untouched        |

b) Failure after hitting a COW range but before calling
   fallback_to_cow()

   start        cow_start    cur_offset   end
   | OE Cleanup |       untouched         |

c) Failure to call fallback_to_cow()

   start        cow_start    cow_end      end
   | OE Cleanup |    skip    |  untouched |

Instead of modifying @cur_offset, do proper range calculation for
OE-cleanup and untouched ranges using above 3 cases with proper range
charts.

This avoid updating @cur_offset, as it will an extra output for debug
purposes later, and explain the behavior easier.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c