mirror_zfs/module/os/freebsd/zfs
Alexander Motin 9b1677fb5a
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
2023-12-15 09:51:41 -08:00
..
abd_os.c FreeBSD: use zero_region instead of allocating a dedicated page 2022-05-04 11:46:37 -07:00
arc_os.c Unify arc_prune_async() code 2023-10-30 16:56:04 -07:00
crypto_os.c freebsd: remove __FBSDID macro use 2023-11-17 14:02:09 -08:00
dmu_os.c dmu: Allow buffer fills to fail 2023-12-15 09:51:41 -08:00
event_os.c FreeBSD: Fix the build on FreeBSD 12 2023-11-27 12:58:03 -08:00
hkdf.c Remove bcopy(), bzero(), bcmp() 2022-03-15 15:13:42 -07:00
kmod_core.c freebsd: remove __FBSDID macro use 2023-11-17 14:02:09 -08:00
spa_os.c Fix build on FreeBSD 2023-03-22 09:24:41 -07:00
sysctl_os.c freebsd: remove __FBSDID macro use 2023-11-17 14:02:09 -08:00
vdev_file.c Cleanup: 64-bit kernel module parameters should use fixed width types 2022-10-13 10:03:29 -07:00
vdev_geom.c Fix build on FreeBSD 2023-03-22 09:24:41 -07:00
vdev_label_os.c Use abd_zero_off() where applicable 2023-11-17 13:28:32 -08:00
zfs_acl.c Use list_remove_head() where possible. 2023-06-09 10:12:52 -07:00
zfs_ctldir.c FreeBSD: Fix ZFS so that snapshots under .zfs/snapshot are NFS visible 2023-11-27 16:31:03 -08:00
zfs_debug.c Cleanup: Replace oldstyle struct hack with C99 flexible array members 2023-01-12 16:00:03 -08:00
zfs_dir.c Fix unprotected zfs_znode_dmu_fini 2023-01-19 16:59:05 -08:00
zfs_file_os.c freebsd: remove __FBSDID macro use 2023-11-17 14:02:09 -08:00
zfs_ioctl_compat.c freebsd: remove __FBSDID macro use 2023-11-17 14:02:09 -08:00
zfs_ioctl_os.c freebsd: remove __FBSDID macro use 2023-11-17 14:02:09 -08:00
zfs_racct.c module: zfs: fix unused, remove argsused 2021-12-23 09:42:47 -08:00
zfs_vfsops.c Add a tunable to disable BRT support. 2023-11-16 11:35:22 -08:00
zfs_vnops_os.c FreeBSD: Ensure that zfs_getattr() initializes the va_rdev field 2023-12-07 08:20:11 -08:00
zfs_znode.c Retire z_nr_znodes 2023-09-18 16:53:33 -07:00
zio_crypt.c ZIL: Assert record sizes in different places 2023-11-28 13:35:14 -08:00
zvol_os.c Update the kstat dataset_name when renaming a zvol 2023-11-07 11:34:50 -08:00