]> git.proxmox.com Git - mirror_zfs.git/commit
dmu: Allow buffer fills to fail
authorAlexander Motin <mav@FreeBSD.org>
Fri, 15 Dec 2023 17:51:41 +0000 (12:51 -0500)
committerTony Hutter <hutter2@llnl.gov>
Tue, 20 Feb 2024 23:53:02 +0000 (15:53 -0800)
commitc0c4866f8a29a38b2bb683c267d7278e0020d90c
tree6eaa8d0fb0a6c3d8ce4f7f2d8b247b2bd5f961bc
parentb62fd2cef9baede3fb9ee7dca980a0eb10d694f8
dmu: Allow buffer fills to fail

When ZFS overwrites a whole block, it does not bother to read the
old content from disk. It is a good optimization, but if the buffer
fill fails due to page fault or something else, the buffer ends up
corrupted, neither keeping old content, nor getting the new one.

On FreeBSD this is additionally complicated by page faults being
blocked by VFS layer, always returning EFAULT on attempt to write
from mmap()'ed but not yet cached address range.  Normally it is
not a big problem, since after original failure VFS will retry the
write after reading the required data.  The problem becomes worse
in specific case when somebody tries to write into a file its own
mmap()'ed content from the same location.  In that situation the
only copy of the data is getting corrupted on the page fault and
the following retries only fixate the status quo.  Block cloning
makes this issue easier to reproduce, since it does not read the
old data, unlike traditional file copy, that may work by chance.

This patch provides the fill status to dmu_buf_fill_done(), that
in case of error can destroy the corrupted buffer as if no write
happened.  One more complication in case of block cloning is that
if error is possible during fill, dmu_buf_will_fill() must read
the data via fall-back to dmu_buf_will_dirty().  It is required
to allow in case of error restoring the buffer to a state after
the cloning, not not before it, that would happen if we just call
dbuf_undirty().

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Rob Norris <robn@despairlabs.com>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored by: iXsystems, Inc.
Closes #15665
include/os/freebsd/spl/sys/uio.h
include/os/linux/spl/sys/uio.h
include/sys/dbuf.h
lib/libspl/include/sys/uio.h
module/os/freebsd/zfs/dmu_os.c
module/zfs/dbuf.c
module/zfs/dmu.c
module/zfs/dmu_recv.c