]> 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)
committerGitHub <noreply@github.com>
Fri, 15 Dec 2023 17:51:41 +0000 (09:51 -0800)
commit9b1677fb5a0824b5f4b425c0ee950aaecf252029
tree380231bb74ac74ca4c43a29682f095e894d13678
parent86e115e21e5bdeee73c88c5a1a73a29d9637380a
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
module/zfs/dsl_bookmark.c