dmu_read_l0_bps() captures the source block pointers for a clone
without consulting dnode_block_freed(). A block whose free is recorded
but not yet synced still has a valid on-disk pointer, so the clone
registers a BRT reference to a block about to be returned to the
allocator, and it is freed twice. On a debug build this trips the
metaslab double-free verifier; on a release build the space map is
silently corrupted.
Check for a pending free and return EAGAIN, as dbuf_read_hole() already
does for buffered reads. zfs_clone_range() waits a TXG and retries, by
which point the block reads as a hole.
Two cases need more than the plain check. A hole has nothing to free,
so guard with !BP_IS_HOLE(bp), otherwise a hole inside a pending free
range fails a FICLONE that master cloned. When the head dirty record
already overrode the BP, only frees after the override count against
it, so use dnode_block_freed_after(); dbuf_free_range() leaves the
override in place across a later punch, and cloning the clone would
otherwise capture it.
Reproduced with fstests generic/733, which panicked within a minute on
a debug build, and with a FICLONE of a sparse file in a pending free
range. Both clean after. bclonesaved is correct and scrub is clean.
Suggested-by: mkhllr
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Patrick Domack <patrickdk@patrickdk.com>
Closes #18842
Closes #18853
(cherry picked from commit 39764eb06bd079b31cf830c8582870753aebcafb)