]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Fix lseek(SEEK_DATA/SEEK_HOLE) mmap consistency
authorBrian Behlendorf <behlendorf1@llnl.gov>
Sun, 7 Nov 2021 21:27:44 +0000 (13:27 -0800)
committerMark Johnston <markj@FreeBSD.org>
Tue, 15 Mar 2022 18:09:52 +0000 (14:09 -0400)
commitf5be20afc3568876c44269420a542627238e4da0
tree750c9d1a4f0ebeaf3ddb756c1c84c2c428772241
parent0abaf7f630235933aca9dd5819d4c0aea9985f3a
Fix lseek(SEEK_DATA/SEEK_HOLE) mmap consistency

When using lseek(2) to report data/holes memory mapped regions of
the file were ignored.  This could result in incorrect results.
To handle this zfs_holey_common() was updated to asynchronously
writeback any dirty mmap(2) regions prior to reporting holes.

Additionally, while not strictly required, the dn_struct_rwlock is
now held over the dirty check to prevent the dnode structure from
changing.  This ensures that a clean dnode can't be dirtied before
the data/hole is located.  The range lock is now also taken to
ensure the call cannot race with zfs_write().

Furthermore, the code was refactored to provide a dnode_is_dirty()
helper function which checks the dnode for any dirty records to
determine its dirtiness.

Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Rich Ercolani <rincebrain@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #11900
Closes #12724
(cherry picked from commit 664d487a5dbd758216ac613934a4080fcc1de347)

Approved by: so
Security: FreeBSD-EN-22:11.zfs
17 files changed:
sys/contrib/openzfs/configure.ac
sys/contrib/openzfs/include/os/freebsd/spl/sys/vnode.h
sys/contrib/openzfs/include/os/freebsd/zfs/sys/zfs_znode_impl.h
sys/contrib/openzfs/include/os/linux/zfs/sys/zfs_znode_impl.h
sys/contrib/openzfs/include/sys/dnode.h
sys/contrib/openzfs/module/zfs/dmu.c
sys/contrib/openzfs/module/zfs/dnode.c
sys/contrib/openzfs/module/zfs/zfs_vnops.c
sys/contrib/openzfs/tests/runfiles/common.run
sys/contrib/openzfs/tests/zfs-tests/cmd/Makefile.am
sys/contrib/openzfs/tests/zfs-tests/include/commands.cfg
sys/contrib/openzfs/tests/zfs-tests/include/tunables.cfg
sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/Makefile.am
sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/mmap_seek_001_pos.ksh [new file with mode: 0755]
tests/zfs-tests/cmd/mmap_seek/.gitignore [new file with mode: 0644]
tests/zfs-tests/cmd/mmap_seek/Makefile.am [new file with mode: 0644]
tests/zfs-tests/cmd/mmap_seek/mmap_seek.c [new file with mode: 0644]