btrfs: send: fix missing hole punching during incremental send
When using the no-holes feature (enabled by default since btrfs-progs
v5.15) and doing an incremental send, we can miss issuing a hole punching
command when the following conditions happen:
1) A hole is punched in a tail section of a file extent item that happens
to be the last item in a leaf (for example the extent covers the file
range [1M, 3M) and a hole is punched in the range [2M, 3M)). Between
the end of this file extent item's range and the i_size, there are
other file extent items;
2) The next leaf was not modified in the send snapshot, remaining shared
with the parent snapshot.
In this scenario we are unable to detect a hole was punched and never
issue a hole punch command because with no-holes there we don't have an
explicit file extent item to mark a hole.
Fix this by teaching maybe_send_hole() to detect such case.
A test case for fstests will follow soon.
Reported-by: Tristan Elvers <tristanelvers@gmail.com>
Link: https://lore.kernel.org/linux-btrfs/CAFoLKK+aErV4p6ZJPnVeH5SHQ5++0f=8ZgxPWe-E-CkeKBs8PA@mail.gmail.com/
Fixes: 16e7549f045d ("Btrfs: incompatible format change to remove hole extents")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>