summaryrefslogtreecommitdiff
path: root/sys-fs/zfs-kmod
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2021-11-13 13:10:00 +0000
committerV3n3RiX <venerix@koprulu.sector>2021-11-13 13:10:00 +0000
commite9d044d4b9b71200a96adfa280848858c0f468c9 (patch)
tree1bd8ef816043a8cd340f1d774e79553a1a7d31d8 /sys-fs/zfs-kmod
parentfc2f1018fc323ef2c6572734a9b130427cba76a6 (diff)
gentoo resync : 13.11.2021
Diffstat (limited to 'sys-fs/zfs-kmod')
-rw-r--r--sys-fs/zfs-kmod/Manifest10
-rw-r--r--sys-fs/zfs-kmod/files/2.1.1-SEEK_DATA-SEEK_HOLE.patch594
-rw-r--r--sys-fs/zfs-kmod/files/2.1.1-restore-dirty-dnode-logic.patch31
-rw-r--r--sys-fs/zfs-kmod/zfs-kmod-0.8.6.ebuild5
-rw-r--r--sys-fs/zfs-kmod/zfs-kmod-2.0.6.ebuild13
-rw-r--r--sys-fs/zfs-kmod/zfs-kmod-2.1.1-r3.ebuild (renamed from sys-fs/zfs-kmod/zfs-kmod-2.1.1.ebuild)24
-rw-r--r--sys-fs/zfs-kmod/zfs-kmod-9999.ebuild13
7 files changed, 683 insertions, 7 deletions
diff --git a/sys-fs/zfs-kmod/Manifest b/sys-fs/zfs-kmod/Manifest
index 10403340c068..5319dff6c58e 100644
--- a/sys-fs/zfs-kmod/Manifest
+++ b/sys-fs/zfs-kmod/Manifest
@@ -1,11 +1,13 @@
AUX 0.8.6-copy-builtin.patch 988 BLAKE2B f79add4b341075e3cd98b6aee4bb74b8fadd28b5ee1062f9260c0418909d380cdd2d637b52d4959ec19cafec1e55b1d05cd6bc358fdffbd6dc1b159e9935083d SHA512 af6b73a2d9d1b4e028c9b959950934798f4d048211d6e4a7e94595982ad2dc8bb4befd52122e3fa0890548e192f2f2ae41d877cad057543e940a7c2710c81a23
+AUX 2.1.1-SEEK_DATA-SEEK_HOLE.patch 19794 BLAKE2B c3259c50e96e7c28a8d6a18693674c1a6b233fb8eb1cbdd4a4c87e085b0b787c8b512231f109c4600da1a7a571c6129a3acd904303967543c1a12bb1042ed2b5 SHA512 098d0b6cb25fb90ac987e7e0913b2681a297bf3138d6708d4f4bb9b6402f0ec71f4848c50bbec6ef006208f40fa709b1d58ca46c9cbf08a125a9165f83287c52
+AUX 2.1.1-restore-dirty-dnode-logic.patch 1075 BLAKE2B 04720dbfb3f4fc223c329dee330330a94224119dcdfb7240c8bb629fbc4f8206acf95c021219844ad289ddcd2cced7b686418d9f59c3c21d2b08d029100fa29d SHA512 5122de3b1fa9875d47afe52da624a25c1b24ad917ee195769828efdb3c510c709b1cee95914e0a0f2959b41324ac0b61fe77675901dfd95955994d52434b8c3a
DIST zfs-0.8.6.tar.gz 9295260 BLAKE2B 45424d710aaf75a05f766ae523ae157a24b5cbdcefe72a59e4cede81e42f7a92ae7f01150388437b78cd49f3d28b9664599f2a624516e6b3f1073497194a99f2 SHA512 626b172554f39a5c70f6ea5c599a92fae52534590d1b0273de2bbfc3676d29dff0eade8ca17e5f179a59870c12bc758fb53b7900f8a1fdbdef3a9161b93f9cce
DIST zfs-2.0.6.tar.gz 13192941 BLAKE2B 3a83303b016ec4259c286af8a9ceb281829d26508d411df91dd94193bca8c3155ef0ba63604e95f6add5f0c6cf6d100b0f567efc33b6c484c9ff811924da6ccd SHA512 52a5576eed21868b2a3d63d05d3d8c35b5e59ee88c7ddab1dc070644539f9acd56bde43ba5e965ad951a6d50a014fb429a7977d2ab1a2bfcadd92ea78dd57bf8
DIST zfs-2.0.6.tar.gz.asc 836 BLAKE2B 065eba3361ef4234acc67df0236ab9a6737ba9fe5a706be98b55dd64d10360160ca787d8873f27451a2107225ae657dc4cab20a7c2a268cd2de64c8d82d0327a SHA512 123569ecfcee22ac462160acf61b120144c774bc5c0d46a50d2b7312f7565da1a9d780e1a6207dba5834917c66d5b852763e4a3162378d5c9bb90b0dfde35c5c
DIST zfs-2.1.1.tar.gz 34836374 BLAKE2B 09ee6bd30e8266342bd975454086049c3fd9142e7dacfe52166575c20e3c92688f9b457d75b2a2068fc281e65f78e1d47450545504cdf8bc31e23663545d7800 SHA512 b69ce764a9f7438ec2c90f86be02abfd684c67cd38de876374e3e6f4b2f82a75d86fa70205def2ba454ad27e52ec8d955ebc4ba456e91d397129a54ea849c19c
DIST zfs-2.1.1.tar.gz.asc 195 BLAKE2B d886e7dc74270228f98dfc5ca85bbbe897d5a87a5ae8bbfde28e2af1b36218227bc9f1b5902e97beebe160a298857d6e4673829d87cd8039332dc1858cfcffc0 SHA512 d76956b5c1bd547a319e70dd33d50beae39f65fca54532731426d2ef209385a556c51b3936051f75bc3800623c42da5b8d279c51f501a896f5fdfb7b4ed7fb94
-EBUILD zfs-kmod-0.8.6.ebuild 5481 BLAKE2B a367b1cec0374f6c9266bf599944ef5493eae21a91704572f806ec2486707a6d3cae876f52f97d527744c66596204b2dcdb435b2beb7cd182ca524cb991f8915 SHA512 014332fa562aae19d65c3f31ba1179e0c623dc3293e45e51323bb2b279641ee6926ac9d8cca3aba8407b44a2787be19abbaa3945f48e6e40f9aa27b1458e647a
-EBUILD zfs-kmod-2.0.6.ebuild 5524 BLAKE2B 92a1d66c9d994129b54957858eb2235f018df88e4a564a7dcfbe0a7d0d558dbbb81661a48fa0d6bc8a745cfff08b2d5f01a1263d2ef7a6b509d4ea4439d06e39 SHA512 37ca8be74fa3dbca773c76ddd60dcb9ce790e92174d400c4abb0837e6bce6dee24a3cdfa0366fa5e6bb196691ac9a17c976ee272516b2a918b872741f7c9fd23
-EBUILD zfs-kmod-2.1.1.ebuild 4740 BLAKE2B 8706911cc8e55df54477c0c00c6a36e0c1444154be4ef3c0a0e6bd53790550aa54fe70ed3719fa5a09f1fc0bf1d165ac821f756cccbc3c5cdeda5029d2056b97 SHA512 58f44cd588e4b4afdcf2f7d1d102b42a7b1767dd196f6d85cd2daf1d084ebf2586ade44f3c66ce56613fa0bad09a21c44c529584cbc630ec9f7e28c890a09e04
-EBUILD zfs-kmod-9999.ebuild 4722 BLAKE2B 559e7c1574b6f22a8e251fbad495cbd4341f58a496bf0cfb6c6f188ec5cb8091fa8514e485ae327f83ad1e80bff8a3e67b9cb55a4f5fb8e96a66205b9c1c17e7 SHA512 3e9ee32d5906dd3a0fa9f630309a89ecb5ea095f96e3ec1feec3db0faf02c23cfba37e472ada753f1f7e46186d9ec33ea86e6f9b30cf3e7a3dc995217c9458bc
+EBUILD zfs-kmod-0.8.6.ebuild 5749 BLAKE2B 867ba8d060dc08eae4027d8c6e17f8ed31f429c87cc0ad9faa88aab0ee60d91e0a2a1d0b9dc59974d3c406a6266d4a4f752dab9e909a0df18ddf5c65152e6e13 SHA512 3f7303584c5324ed8715cd5a473344564ce2862b3e730722ac128a758f2750c1cb3ab2521185eae6e237ec1aa5dda82b8780009a51fc6798e27fc45b18c96f6a
+EBUILD zfs-kmod-2.0.6.ebuild 6045 BLAKE2B 02a899203203caf05268bebd5e275aefdfb6ebdf71feecc9df9c3e5d861f635d8b0632afb51edf62450b2c82cf58396d3df812b721fd40906655c16aa7280b67 SHA512 d25e34726710e9b2bfda4467f03df4376cce9eb988c4449d54aeee47c7d7c717326e9e56d58fb69d8bfff47fb6a0a1f69d4cb8ca5cf28a7efa29f76f8caccf83
+EBUILD zfs-kmod-2.1.1-r3.ebuild 5584 BLAKE2B 29b6b8e78b9f9cbe872977ada4ae2a10cf2ae31dd02077065c2b383f87829a552ad6e06363a7734934d1edc6758fbe068e5a8e90b44a7427110c66f67e1eee1b SHA512 1f5723a243e4d39bce5e57e132b540b5ac83371ae1262e641996f5a19eabbbe077e4f1756a9db465db01009f776578c54ef56cbabfa166355ea3f76979198ce2
+EBUILD zfs-kmod-9999.ebuild 5243 BLAKE2B fb00deb56979862a3249a9be33dc438153945dc38384473c6d24534d9cbde56fc17b5dde81c110239dd8945079417a912f614f611be1b036106201fde4028125 SHA512 a3ade0ec20a34b0e28f8af9a674c3124c283097b405b222d4518122e81cf6a215aa1eacfed1d6beea04c782af3b8a2c9b8763188dfd94f9a94f10e6a6ebb0199
MISC metadata.xml 549 BLAKE2B ae860684a4cf82c277fe91d11e0bcf283103a08442e78584c9962b1571efed7e6ee0e215f3341263f809978e63e01d70275a80fa4996b8265569539e0b2ffe34 SHA512 7a97c7965147549da470c9d5d3a541284964c5ec276d005a2f7aa1a4550c915cce32b2593257e5ad373c84955e3bf74b235297d540364ee4a17cf9e1e705b650
diff --git a/sys-fs/zfs-kmod/files/2.1.1-SEEK_DATA-SEEK_HOLE.patch b/sys-fs/zfs-kmod/files/2.1.1-SEEK_DATA-SEEK_HOLE.patch
new file mode 100644
index 000000000000..458fe279ee23
--- /dev/null
+++ b/sys-fs/zfs-kmod/files/2.1.1-SEEK_DATA-SEEK_HOLE.patch
@@ -0,0 +1,594 @@
+From 664d487a5dbd758216ac613934a4080fcc1de347 Mon Sep 17 00:00:00 2001
+From: Brian Behlendorf <behlendorf1@llnl.gov>
+Date: Sun, 7 Nov 2021 13:27:44 -0800
+Subject: [PATCH] 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
+---
+ configure.ac | 1 +
+ include/os/freebsd/spl/sys/vnode.h | 18 +++
+ include/os/freebsd/zfs/sys/zfs_znode_impl.h | 3 +-
+ include/os/linux/zfs/sys/zfs_znode_impl.h | 1 +
+ include/sys/dnode.h | 1 +
+ man/man4/zfs.4 | 2 +-
+ module/zfs/dmu.c | 53 ++++---
+ module/zfs/dnode.c | 20 +++
+ module/zfs/zfs_vnops.c | 9 +-
+ tests/runfiles/common.run | 2 +-
+ tests/zfs-tests/cmd/Makefile.am | 1 +
+ tests/zfs-tests/cmd/mmap_seek/.gitignore | 1 +
+ tests/zfs-tests/cmd/mmap_seek/Makefile.am | 6 +
+ tests/zfs-tests/cmd/mmap_seek/mmap_seek.c | 147 ++++++++++++++++++
+ tests/zfs-tests/include/commands.cfg | 1 +
+ tests/zfs-tests/include/tunables.cfg | 1 +
+ .../tests/functional/mmap/Makefile.am | 3 +-
+ .../functional/mmap/mmap_seek_001_pos.ksh | 67 ++++++++
+ 18 files changed, 305 insertions(+), 32 deletions(-)
+ create mode 100644 tests/zfs-tests/cmd/mmap_seek/.gitignore
+ create mode 100644 tests/zfs-tests/cmd/mmap_seek/Makefile.am
+ create mode 100644 tests/zfs-tests/cmd/mmap_seek/mmap_seek.c
+ create mode 100755 tests/zfs-tests/tests/functional/mmap/mmap_seek_001_pos.ksh
+
+diff --git a/configure.ac b/configure.ac
+index 6f34b210d2b..ebc7b276a64 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -221,6 +221,7 @@ AC_CONFIG_FILES([
+ tests/zfs-tests/cmd/mktree/Makefile
+ tests/zfs-tests/cmd/mmap_exec/Makefile
+ tests/zfs-tests/cmd/mmap_libaio/Makefile
++ tests/zfs-tests/cmd/mmap_seek/Makefile
+ tests/zfs-tests/cmd/mmapwrite/Makefile
+ tests/zfs-tests/cmd/nvlist_to_lua/Makefile
+ tests/zfs-tests/cmd/randfree_file/Makefile
+diff --git a/include/os/freebsd/spl/sys/vnode.h b/include/os/freebsd/spl/sys/vnode.h
+index 3670712a045..3bc8a18eeb7 100644
+--- a/include/os/freebsd/spl/sys/vnode.h
++++ b/include/os/freebsd/spl/sys/vnode.h
+@@ -59,6 +59,8 @@ enum symfollow { NO_FOLLOW = NOFOLLOW };
+ #include <sys/file.h>
+ #include <sys/filedesc.h>
+ #include <sys/syscallsubr.h>
++#include <sys/vm.h>
++#include <vm/vm_object.h>
+
+ typedef struct vop_vector vnodeops_t;
+ #define VOP_FID VOP_VPTOFH
+@@ -83,6 +85,22 @@ vn_is_readonly(vnode_t *vp)
+ #define vn_has_cached_data(vp) \
+ ((vp)->v_object != NULL && \
+ (vp)->v_object->resident_page_count > 0)
++
++static __inline void
++vn_flush_cached_data(vnode_t *vp, boolean_t sync)
++{
++#if __FreeBSD_version > 1300054
++ if (vm_object_mightbedirty(vp->v_object)) {
++#else
++ if (vp->v_object->flags & OBJ_MIGHTBEDIRTY) {
++#endif
++ int flags = sync ? OBJPC_SYNC : 0;
++ zfs_vmobject_wlock(vp->v_object);
++ vm_object_page_clean(vp->v_object, 0, 0, flags);
++ zfs_vmobject_wunlock(vp->v_object);
++ }
++}
++
+ #define vn_exists(vp) do { } while (0)
+ #define vn_invalid(vp) do { } while (0)
+ #define vn_renamepath(tdvp, svp, tnm, lentnm) do { } while (0)
+diff --git a/include/os/freebsd/zfs/sys/zfs_znode_impl.h b/include/os/freebsd/zfs/sys/zfs_znode_impl.h
+index e90008c70a8..edb28d041a0 100644
+--- a/include/os/freebsd/zfs/sys/zfs_znode_impl.h
++++ b/include/os/freebsd/zfs/sys/zfs_znode_impl.h
+@@ -118,7 +118,8 @@ extern minor_t zfsdev_minor_alloc(void);
+ #define Z_ISLNK(type) ((type) == VLNK)
+ #define Z_ISDIR(type) ((type) == VDIR)
+
+-#define zn_has_cached_data(zp) vn_has_cached_data(ZTOV(zp))
++#define zn_has_cached_data(zp) vn_has_cached_data(ZTOV(zp))
++#define zn_flush_cached_data(zp, sync) vn_flush_cached_data(ZTOV(zp), sync)
+ #define zn_rlimit_fsize(zp, uio) \
+ vn_rlimit_fsize(ZTOV(zp), GET_UIO_STRUCT(uio), zfs_uio_td(uio))
+
+diff --git a/include/os/linux/zfs/sys/zfs_znode_impl.h b/include/os/linux/zfs/sys/zfs_znode_impl.h
+index 0a6273442b7..de46fc8f2bd 100644
+--- a/include/os/linux/zfs/sys/zfs_znode_impl.h
++++ b/include/os/linux/zfs/sys/zfs_znode_impl.h
+@@ -71,6 +71,7 @@ extern "C" {
+ #define Z_ISDIR(type) S_ISDIR(type)
+
+ #define zn_has_cached_data(zp) ((zp)->z_is_mapped)
++#define zn_flush_cached_data(zp, sync) write_inode_now(ZTOI(zp), sync)
+ #define zn_rlimit_fsize(zp, uio) (0)
+
+ /*
+diff --git a/include/sys/dnode.h b/include/sys/dnode.h
+index 2cdc5b8798a..af8775b9ee0 100644
+--- a/include/sys/dnode.h
++++ b/include/sys/dnode.h
+@@ -425,6 +425,7 @@ boolean_t dnode_add_ref(dnode_t *dn, void *ref);
+ void dnode_rele(dnode_t *dn, void *ref);
+ void dnode_rele_and_unlock(dnode_t *dn, void *tag, boolean_t evicting);
+ int dnode_try_claim(objset_t *os, uint64_t object, int slots);
++boolean_t dnode_is_dirty(dnode_t *dn);
+ void dnode_setdirty(dnode_t *dn, dmu_tx_t *tx);
+ void dnode_set_dirtyctx(dnode_t *dn, dmu_tx_t *tx, void *tag);
+ void dnode_sync(dnode_t *dn, dmu_tx_t *tx);
+diff --git a/man/man4/zfs.4 b/man/man4/zfs.4
+index 2aed6895754..20b24d898d8 100644
+--- a/man/man4/zfs.4
++++ b/man/man4/zfs.4
+@@ -1574,7 +1574,7 @@ Allow no-operation writes.
+ The occurrence of nopwrites will further depend on other pool properties
+ .Pq i.a. the checksumming and compression algorithms .
+ .
+-.It Sy zfs_dmu_offset_next_sync Ns = Ns Sy 0 Ns | ns 1 Pq int
++.It Sy zfs_dmu_offset_next_sync Ns = Ns Sy 0 Ns | Ns 1 Pq int
+ Enable forcing TXG sync to find holes.
+ When enabled forces ZFS to act like prior versions when
+ .Sy SEEK_HOLE No or Sy SEEK_DATA
+diff --git a/module/zfs/dmu.c b/module/zfs/dmu.c
+index 1c47430953b..8302d506146 100644
+--- a/module/zfs/dmu.c
++++ b/module/zfs/dmu.c
+@@ -2095,42 +2095,41 @@ int
+ dmu_offset_next(objset_t *os, uint64_t object, boolean_t hole, uint64_t *off)
+ {
+ dnode_t *dn;
+- int i, err;
+- boolean_t clean = B_TRUE;
++ int err;
+
++restart:
+ err = dnode_hold(os, object, FTAG, &dn);
+ if (err)
+ return (err);
+
+- /*
+- * Check if dnode is dirty
+- */
+- for (i = 0; i < TXG_SIZE; i++) {
+- if (multilist_link_active(&dn->dn_dirty_link[i])) {
+- clean = B_FALSE;
+- break;
+- }
+- }
++ rw_enter(&dn->dn_struct_rwlock, RW_READER);
+
+- /*
+- * If compatibility option is on, sync any current changes before
+- * we go trundling through the block pointers.
+- */
+- if (!clean && zfs_dmu_offset_next_sync) {
+- clean = B_TRUE;
+- dnode_rele(dn, FTAG);
+- txg_wait_synced(dmu_objset_pool(os), 0);
+- err = dnode_hold(os, object, FTAG, &dn);
+- if (err)
+- return (err);
+- }
++ if (dnode_is_dirty(dn)) {
++ /*
++ * If the zfs_dmu_offset_next_sync module option is enabled
++ * then strict hole reporting has been requested. Dirty
++ * dnodes must be synced to disk to accurately report all
++ * holes. When disabled (the default) dirty dnodes are
++ * reported to not have any holes which is always safe.
++ *
++ * When called by zfs_holey_common() the zp->z_rangelock
++ * is held to prevent zfs_write() and mmap writeback from
++ * re-dirtying the dnode after txg_wait_synced().
++ */
++ if (zfs_dmu_offset_next_sync) {
++ rw_exit(&dn->dn_struct_rwlock);
++ dnode_rele(dn, FTAG);
++ txg_wait_synced(dmu_objset_pool(os), 0);
++ goto restart;
++ }
+
+- if (clean)
+- err = dnode_next_offset(dn,
+- (hole ? DNODE_FIND_HOLE : 0), off, 1, 1, 0);
+- else
+ err = SET_ERROR(EBUSY);
++ } else {
++ err = dnode_next_offset(dn, DNODE_FIND_HAVELOCK |
++ (hole ? DNODE_FIND_HOLE : 0), off, 1, 1, 0);
++ }
+
++ rw_exit(&dn->dn_struct_rwlock);
+ dnode_rele(dn, FTAG);
+
+ return (err);
+diff --git a/module/zfs/dnode.c b/module/zfs/dnode.c
+index 7f741542ce0..572d88ec2bf 100644
+--- a/module/zfs/dnode.c
++++ b/module/zfs/dnode.c
+@@ -1648,6 +1648,26 @@ dnode_try_claim(objset_t *os, uint64_t object, int slots)
+ slots, NULL, NULL));
+ }
+
++/*
++ * Checks if the dnode contains any uncommitted dirty records.
++ */
++boolean_t
++dnode_is_dirty(dnode_t *dn)
++{
++ mutex_enter(&dn->dn_mtx);
++
++ for (int i = 0; i < TXG_SIZE; i++) {
++ if (list_head(&dn->dn_dirty_records[i]) != NULL) {
++ mutex_exit(&dn->dn_mtx);
++ return (B_TRUE);
++ }
++ }
++
++ mutex_exit(&dn->dn_mtx);
++
++ return (B_FALSE);
++}
++
+ void
+ dnode_setdirty(dnode_t *dn, dmu_tx_t *tx)
+ {
+diff --git a/module/zfs/zfs_vnops.c b/module/zfs/zfs_vnops.c
+index 8229bc9a93e..170e392abe9 100644
+--- a/module/zfs/zfs_vnops.c
++++ b/module/zfs/zfs_vnops.c
+@@ -85,6 +85,7 @@ zfs_fsync(znode_t *zp, int syncflag, cred_t *cr)
+ static int
+ zfs_holey_common(znode_t *zp, ulong_t cmd, loff_t *off)
+ {
++ zfs_locked_range_t *lr;
+ uint64_t noff = (uint64_t)*off; /* new offset */
+ uint64_t file_sz;
+ int error;
+@@ -100,12 +101,18 @@ zfs_holey_common(znode_t *zp, ulong_t cmd, loff_t *off)
+ else
+ hole = B_FALSE;
+
++ /* Flush any mmap()'d data to disk */
++ if (zn_has_cached_data(zp))
++ zn_flush_cached_data(zp, B_FALSE);
++
++ lr = zfs_rangelock_enter(&zp->z_rangelock, 0, file_sz, RL_READER);
+ error = dmu_offset_next(ZTOZSB(zp)->z_os, zp->z_id, hole, &noff);
++ zfs_rangelock_exit(lr);
+
+ if (error == ESRCH)
+ return (SET_ERROR(ENXIO));
+
+- /* file was dirty, so fall back to using generic logic */
++ /* File was dirty, so fall back to using generic logic */
+ if (error == EBUSY) {
+ if (hole)
+ *off = file_sz;
+diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run
+index a62cd6ad39f..97ee7b8ae24 100644
+--- a/tests/runfiles/common.run
++++ b/tests/runfiles/common.run
+@@ -669,7 +669,7 @@ tests = ['migration_001_pos', 'migration_002_pos', 'migration_003_pos',
+ tags = ['functional', 'migration']
+
+ [tests/functional/mmap]
+-tests = ['mmap_write_001_pos', 'mmap_read_001_pos']
++tests = ['mmap_write_001_pos', 'mmap_read_001_pos', 'mmap_seek_001_pos']
+ tags = ['functional', 'mmap']
+
+ [tests/functional/mount]
+diff --git a/tests/zfs-tests/cmd/Makefile.am b/tests/zfs-tests/cmd/Makefile.am
+index 2b965ca7000..d1c29fcd1c6 100644
+--- a/tests/zfs-tests/cmd/Makefile.am
++++ b/tests/zfs-tests/cmd/Makefile.am
+@@ -19,6 +19,7 @@ SUBDIRS = \
+ mktree \
+ mmap_exec \
+ mmap_libaio \
++ mmap_seek \
+ mmapwrite \
+ nvlist_to_lua \
+ randwritecomp \
+diff --git a/tests/zfs-tests/cmd/mmap_seek/.gitignore b/tests/zfs-tests/cmd/mmap_seek/.gitignore
+new file mode 100644
+index 00000000000..6b05a791750
+--- /dev/null
++++ b/tests/zfs-tests/cmd/mmap_seek/.gitignore
+@@ -0,0 +1 @@
++/mmap_seek
+diff --git a/tests/zfs-tests/cmd/mmap_seek/Makefile.am b/tests/zfs-tests/cmd/mmap_seek/Makefile.am
+new file mode 100644
+index 00000000000..b938931125f
+--- /dev/null
++++ b/tests/zfs-tests/cmd/mmap_seek/Makefile.am
+@@ -0,0 +1,6 @@
++include $(top_srcdir)/config/Rules.am
++
++pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin
++
++pkgexec_PROGRAMS = mmap_seek
++mmap_seek_SOURCES = mmap_seek.c
+diff --git a/tests/zfs-tests/cmd/mmap_seek/mmap_seek.c b/tests/zfs-tests/cmd/mmap_seek/mmap_seek.c
+new file mode 100644
+index 00000000000..f476e1dba9a
+--- /dev/null
++++ b/tests/zfs-tests/cmd/mmap_seek/mmap_seek.c
+@@ -0,0 +1,147 @@
++/*
++ * CDDL HEADER START
++ *
++ * The contents of this file are subject to the terms of the
++ * Common Development and Distribution License (the "License").
++ * You may not use this file except in compliance with the License.
++ *
++ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
++ * or http://www.opensolaris.org/os/licensing.
++ * See the License for the specific language governing permissions
++ * and limitations under the License.
++ *
++ * When distributing Covered Code, include this CDDL HEADER in each
++ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
++ * If applicable, add the following below this CDDL HEADER, with the
++ * fields enclosed by brackets "[]" replaced with your own identifying
++ * information: Portions Copyright [yyyy] [name of copyright owner]
++ *
++ * CDDL HEADER END
++ */
++
++/*
++ * Copyright (c) 2021 by Lawrence Livermore National Security, LLC.
++ */
++
++#include <unistd.h>
++#include <fcntl.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <sys/mman.h>
++#include <errno.h>
++
++static void
++seek_data(int fd, off_t offset, off_t expected)
++{
++ off_t data_offset = lseek(fd, offset, SEEK_DATA);
++ if (data_offset != expected) {
++ fprintf(stderr, "lseek(fd, %d, SEEK_DATA) = %d (expected %d)\n",
++ (int)offset, (int)data_offset, (int)expected);
++ exit(2);
++ }
++}
++
++static void
++seek_hole(int fd, off_t offset, off_t expected)
++{
++ off_t hole_offset = lseek(fd, offset, SEEK_HOLE);
++ if (hole_offset != expected) {
++ fprintf(stderr, "lseek(fd, %d, SEEK_HOLE) = %d (expected %d)\n",
++ (int)offset, (int)hole_offset, (int)expected);
++ exit(2);
++ }
++}
++
++int
++main(int argc, char **argv)
++{
++ char *execname = argv[0];
++ char *file_path = argv[1];
++ char *buf = NULL;
++ int err;
++
++ if (argc != 4) {
++ (void) printf("usage: %s <file name> <file size> "
++ "<block size>\n", argv[0]);
++ exit(1);
++ }
++
++ int fd = open(file_path, O_RDWR | O_CREAT, 0666);
++ if (fd == -1) {
++ (void) fprintf(stderr, "%s: %s: ", execname, file_path);
++ perror("open");
++ exit(2);
++ }
++
++ off_t file_size = atoi(argv[2]);
++ off_t block_size = atoi(argv[3]);
++
++ if (block_size * 2 > file_size) {
++ (void) fprintf(stderr, "file size must be at least "
++ "double the block size\n");
++ exit(2);
++ }
++
++ err = ftruncate(fd, file_size);
++ if (err == -1) {
++ perror("ftruncate");
++ exit(2);
++ }
++
++ if ((buf = mmap(NULL, file_size, PROT_READ | PROT_WRITE,
++ MAP_SHARED, fd, 0)) == MAP_FAILED) {
++ perror("mmap");
++ exit(2);
++ }
++
++ /* Verify the file is sparse and reports no data. */
++ seek_data(fd, 0, -1);
++
++ /* Verify the file is reported as a hole. */
++ seek_hole(fd, 0, 0);
++
++ /* Verify search beyond end of file is an error. */
++ seek_data(fd, 2 * file_size, -1);
++ seek_hole(fd, 2 * file_size, -1);
++
++ /* Dirty the first byte. */
++ memset(buf, 'a', 1);
++ seek_data(fd, 0, 0);
++ seek_data(fd, block_size, -1);
++ seek_hole(fd, 0, block_size);
++ seek_hole(fd, block_size, block_size);
++
++ /* Dirty the first half of the file. */
++ memset(buf, 'b', file_size / 2);
++ seek_data(fd, 0, 0);
++ seek_data(fd, block_size, block_size);
++ seek_hole(fd, 0, P2ROUNDUP(file_size / 2, block_size));
++ seek_hole(fd, block_size, P2ROUNDUP(file_size / 2, block_size));
++
++ /* Dirty the whole file. */
++ memset(buf, 'c', file_size);
++ seek_data(fd, 0, 0);
++ seek_data(fd, file_size * 3 / 4,
++ P2ROUNDUP(file_size * 3 / 4, block_size));
++ seek_hole(fd, 0, file_size);
++ seek_hole(fd, file_size / 2, file_size);
++
++ /* Punch a hole (required compression be enabled). */
++ memset(buf + block_size, 0, block_size);
++ seek_data(fd, 0, 0);
++ seek_data(fd, block_size, 2 * block_size);
++ seek_hole(fd, 0, block_size);
++ seek_hole(fd, block_size, block_size);
++ seek_hole(fd, 2 * block_size, file_size);
++
++ err = munmap(buf, file_size);
++ if (err == -1) {
++ perror("munmap");
++ exit(2);
++ }
++
++ close(fd);
++
++ return (0);
++}
+diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg
+index 1ec73f25bae..4497a6248b4 100644
+--- a/tests/zfs-tests/include/commands.cfg
++++ b/tests/zfs-tests/include/commands.cfg
+@@ -209,6 +209,7 @@ export ZFSTEST_FILES='badsend
+ mktree
+ mmap_exec
+ mmap_libaio
++ mmap_seek
+ mmapwrite
+ nvlist_to_lua
+ randfree_file
+diff --git a/tests/zfs-tests/include/tunables.cfg b/tests/zfs-tests/include/tunables.cfg
+index 56d430a3987..fff43e46916 100644
+--- a/tests/zfs-tests/include/tunables.cfg
++++ b/tests/zfs-tests/include/tunables.cfg
+@@ -33,6 +33,7 @@ DEADMAN_FAILMODE deadman.failmode zfs_deadman_failmode
+ DEADMAN_SYNCTIME_MS deadman.synctime_ms zfs_deadman_synctime_ms
+ DEADMAN_ZIOTIME_MS deadman.ziotime_ms zfs_deadman_ziotime_ms
+ DISABLE_IVSET_GUID_CHECK disable_ivset_guid_check zfs_disable_ivset_guid_check
++DMU_OFFSET_NEXT_SYNC dmu_offset_next_sync zfs_dmu_offset_next_sync
+ INITIALIZE_CHUNK_SIZE initialize_chunk_size zfs_initialize_chunk_size
+ INITIALIZE_VALUE initialize_value zfs_initialize_value
+ KEEP_LOG_SPACEMAPS_AT_EXPORT keep_log_spacemaps_at_export zfs_keep_log_spacemaps_at_export
+diff --git a/tests/zfs-tests/tests/functional/mmap/Makefile.am b/tests/zfs-tests/tests/functional/mmap/Makefile.am
+index 2adc398b8c0..b26791ee7ce 100644
+--- a/tests/zfs-tests/tests/functional/mmap/Makefile.am
++++ b/tests/zfs-tests/tests/functional/mmap/Makefile.am
+@@ -4,7 +4,8 @@ dist_pkgdata_SCRIPTS = \
+ cleanup.ksh \
+ mmap_read_001_pos.ksh \
+ mmap_write_001_pos.ksh \
+- mmap_libaio_001_pos.ksh
++ mmap_libaio_001_pos.ksh \
++ mmap_seek_001_pos.ksh
+
+ dist_pkgdata_DATA = \
+ mmap.cfg
+diff --git a/tests/zfs-tests/tests/functional/mmap/mmap_seek_001_pos.ksh b/tests/zfs-tests/tests/functional/mmap/mmap_seek_001_pos.ksh
+new file mode 100755
+index 00000000000..6188549ad8d
+--- /dev/null
++++ b/tests/zfs-tests/tests/functional/mmap/mmap_seek_001_pos.ksh
+@@ -0,0 +1,67 @@
++#!/bin/ksh -p
++#
++# CDDL HEADER START
++#
++# The contents of this file are subject to the terms of the
++# Common Development and Distribution License (the "License").
++# You may not use this file except in compliance with the License.
++#
++# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
++# or http://www.opensolaris.org/os/licensing.
++# See the License for the specific language governing permissions
++# and limitations under the License.
++#
++# When distributing Covered Code, include this CDDL HEADER in each
++# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
++# If applicable, add the following below this CDDL HEADER, with the
++# fields enclosed by brackets "[]" replaced with your own identifying
++# information: Portions Copyright [yyyy] [name of copyright owner]
++#
++# CDDL HEADER END
++#
++
++#
++# Copyright (c) 2021 by Lawrence Livermore National Security, LLC.
++#
++
++. $STF_SUITE/include/libtest.shlib
++. $STF_SUITE/tests/functional/mmap/mmap.cfg
++
++#
++# DESCRIPTION:
++# lseek() data/holes for an mmap()'d file.
++#
++# STRATEGY:
++# 1. Enable compression and hole reporting for dirty files.
++# 2. Call mmap_seek binary test case for various record sizes.
++#
++
++verify_runnable "global"
++
++function cleanup
++{
++ log_must zfs set compression=off $TESTPOOL/$TESTFS
++ log_must zfs set recordsize=128k $TESTPOOL/$TESTFS
++ log_must rm -f $TESTDIR/test-mmap-file
++ log_must set_tunable64 DMU_OFFSET_NEXT_SYNC $dmu_offset_next_sync
++}
++
++log_assert "lseek() data/holes for an mmap()'d file."
++
++log_onexit cleanup
++
++# Enable hole reporting for dirty files.
++typeset dmu_offset_next_sync=$(get_tunable DMU_OFFSET_NEXT_SYNC)
++log_must set_tunable64 DMU_OFFSET_NEXT_SYNC 1
++
++# Compression must be enabled to convert zero'd blocks to holes.
++# This behavior is checked by the mmap_seek test.
++log_must zfs set compression=on $TESTPOOL/$TESTFS
++
++for bs in 4096 8192 16384 32768 65536 131072; do
++ log_must zfs set recordsize=$bs $TESTPOOL/$TESTFS
++ log_must mmap_seek $TESTDIR/test-mmap-file $((1024*1024)) $bs
++ log_must rm $TESTDIR/test-mmap-file
++done
++
++log_pass "lseek() data/holes for an mmap()'d file succeeded."
diff --git a/sys-fs/zfs-kmod/files/2.1.1-restore-dirty-dnode-logic.patch b/sys-fs/zfs-kmod/files/2.1.1-restore-dirty-dnode-logic.patch
new file mode 100644
index 000000000000..d33735ff9ff6
--- /dev/null
+++ b/sys-fs/zfs-kmod/files/2.1.1-restore-dirty-dnode-logic.patch
@@ -0,0 +1,31 @@
+From d7e640cf95f72deeca501d34afed59a0bc9d7940 Mon Sep 17 00:00:00 2001
+From: Brian Behlendorf <behlendorf1@llnl.gov>
+Date: Wed, 10 Nov 2021 16:14:32 -0800
+Subject: [PATCH] Restore dirty dnode detection logic
+
+In addition to flushing memory mapped regions when checking holes,
+commit de198f2d95 modified the dirty dnode detection logic to check
+the dn->dn_dirty_records instead of the dn->dn_dirty_link. Relying
+on the dirty record has not be reliable, switch back to the previous
+method.
+
+Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
+Issue #11900
+Closes #12745
+---
+ module/zfs/dnode.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/module/zfs/dnode.c b/module/zfs/dnode.c
+index 572d88ec2bf..7044c1fc634 100644
+--- a/module/zfs/dnode.c
++++ b/module/zfs/dnode.c
+@@ -1657,7 +1657,7 @@ dnode_is_dirty(dnode_t *dn)
+ mutex_enter(&dn->dn_mtx);
+
+ for (int i = 0; i < TXG_SIZE; i++) {
+- if (list_head(&dn->dn_dirty_records[i]) != NULL) {
++ if (multilist_link_active(&dn->dn_dirty_link[i])) {
+ mutex_exit(&dn->dn_mtx);
+ return (B_TRUE);
+ }
diff --git a/sys-fs/zfs-kmod/zfs-kmod-0.8.6.ebuild b/sys-fs/zfs-kmod/zfs-kmod-0.8.6.ebuild
index e5b3df641c98..3d63f3f393bf 100644
--- a/sys-fs/zfs-kmod/zfs-kmod-0.8.6.ebuild
+++ b/sys-fs/zfs-kmod/zfs-kmod-0.8.6.ebuild
@@ -16,6 +16,10 @@ else
KEYWORDS="amd64 arm64 ppc64"
S="${WORKDIR}/zfs-${PV}"
ZFS_KERNEL_COMPAT="5.9"
+
+ # increments minor eg 5.14 -> 5.15, and still supports override.
+ ZFS_KERNEL_DEP="${ZFS_KERNEL_COMPAT_OVERRIDE:-${ZFS_KERNEL_COMPAT}}"
+ ZFS_KERNEL_DEP="${ZFS_KERNEL_DEP%%.*}.$(( ${ZFS_KERNEL_DEP##*.} + 1))"
fi
LICENSE="CDDL debug? ( GPL-2+ )"
@@ -31,6 +35,7 @@ RDEPEND="${DEPEND}
BDEPEND="
dev-lang/perl
virtual/awk
+ dist-kernel? ( <virtual/dist-kernel-${ZFS_KERNEL_DEP}:= )
"
# PDEPEND in this form is needed to trick portage suggest
diff --git a/sys-fs/zfs-kmod/zfs-kmod-2.0.6.ebuild b/sys-fs/zfs-kmod/zfs-kmod-2.0.6.ebuild
index 5c445cce099f..d12b2a434901 100644
--- a/sys-fs/zfs-kmod/zfs-kmod-2.0.6.ebuild
+++ b/sys-fs/zfs-kmod/zfs-kmod-2.0.6.ebuild
@@ -21,6 +21,10 @@ else
S="${WORKDIR}/zfs-${PV%_rc?}"
ZFS_KERNEL_COMPAT="5.14"
+ # increments minor eg 5.14 -> 5.15, and still supports override.
+ ZFS_KERNEL_DEP="${ZFS_KERNEL_COMPAT_OVERRIDE:-${ZFS_KERNEL_COMPAT}}"
+ ZFS_KERNEL_DEP="${ZFS_KERNEL_DEP%%.*}.$(( ${ZFS_KERNEL_DEP##*.} + 1))"
+
if [[ ${PV} != *_rc* ]]; then
KEYWORDS="amd64 arm64 ppc64"
fi
@@ -39,8 +43,15 @@ BDEPEND="
virtual/awk
"
+# we want dist-kernel block in BDEPEND because of portage resolver.
+# since linux-mod.eclass already sets version-unbounded dep, portage
+# will pull new versions. So we set it in BDEPEND which takes priority.
+# and we don't need in in git ebuild.
if [[ ${PV} != "9999" ]] ; then
- BDEPEND+=" verify-sig? ( app-crypt/openpgp-keys-openzfs )"
+ BDEPEND+="
+ verify-sig? ( app-crypt/openpgp-keys-openzfs )
+ dist-kernel? ( <virtual/dist-kernel-${ZFS_KERNEL_DEP}:= )
+ "
fi
# PDEPEND in this form is needed to trick portage suggest
diff --git a/sys-fs/zfs-kmod/zfs-kmod-2.1.1.ebuild b/sys-fs/zfs-kmod/zfs-kmod-2.1.1-r3.ebuild
index 996dd40ebdcb..ea61ad1dc0a9 100644
--- a/sys-fs/zfs-kmod/zfs-kmod-2.1.1.ebuild
+++ b/sys-fs/zfs-kmod/zfs-kmod-2.1.1-r3.ebuild
@@ -21,6 +21,10 @@ else
S="${WORKDIR}/zfs-${PV%_rc?}"
ZFS_KERNEL_COMPAT="5.14"
+ # increments minor eg 5.14 -> 5.15, and still supports override.
+ ZFS_KERNEL_DEP="${ZFS_KERNEL_COMPAT_OVERRIDE:-${ZFS_KERNEL_COMPAT}}"
+ ZFS_KERNEL_DEP="${ZFS_KERNEL_DEP%%.*}.$(( ${ZFS_KERNEL_DEP##*.} + 1))"
+
if [[ ${PV} != *_rc* ]]; then
KEYWORDS="~amd64 ~arm64 ~ppc64 ~riscv"
fi
@@ -39,8 +43,15 @@ BDEPEND="
virtual/awk
"
+# we want dist-kernel block in BDEPEND because of portage resolver.
+# since linux-mod.eclass already sets version-unbounded dep, portage
+# will pull new versions. So we set it in BDEPEND which takes priority.
+# and we don't need in in git ebuild.
if [[ ${PV} != "9999" ]] ; then
- BDEPEND+=" verify-sig? ( app-crypt/openpgp-keys-openzfs )"
+ BDEPEND+="
+ verify-sig? ( app-crypt/openpgp-keys-openzfs )
+ dist-kernel? ( <virtual/dist-kernel-${ZFS_KERNEL_DEP}:= )
+ "
fi
# PDEPEND in this form is needed to trick portage suggest
@@ -51,6 +62,11 @@ RESTRICT="debug? ( strip ) test"
DOCS=( AUTHORS COPYRIGHT META README.md )
+PATCHES=(
+ "${FILESDIR}/2.1.1-SEEK_DATA-SEEK_HOLE.patch"
+ "${FILESDIR}/2.1.1-restore-dirty-dnode-logic.patch"
+)
+
pkg_pretend() {
use rootfs || return 0
@@ -191,4 +207,10 @@ pkg_postinst() {
ewarn
ewarn "Refer to /etc/zfs/compatibility.d/grub2 for list of features."
fi
+
+ echo
+ ewarn "This versions of ${PN} includes a very important fix for upstream bug"
+ ewarn "https://github.com/openzfs/zfs/issues/11900"
+ ewarn "Please reboot into kernel with ${P} as soon as possible"
+ echo
}
diff --git a/sys-fs/zfs-kmod/zfs-kmod-9999.ebuild b/sys-fs/zfs-kmod/zfs-kmod-9999.ebuild
index 255ef48a0b4b..5b11d92a6ea3 100644
--- a/sys-fs/zfs-kmod/zfs-kmod-9999.ebuild
+++ b/sys-fs/zfs-kmod/zfs-kmod-9999.ebuild
@@ -21,6 +21,10 @@ else
S="${WORKDIR}/zfs-${PV%_rc?}"
ZFS_KERNEL_COMPAT="5.14"
+ # increments minor eg 5.14 -> 5.15, and still supports override.
+ ZFS_KERNEL_DEP="${ZFS_KERNEL_COMPAT_OVERRIDE:-${ZFS_KERNEL_COMPAT}}"
+ ZFS_KERNEL_DEP="${ZFS_KERNEL_DEP%%.*}.$(( ${ZFS_KERNEL_DEP##*.} + 1))"
+
if [[ ${PV} != *_rc* ]]; then
KEYWORDS="~amd64 ~arm64 ~ppc64 ~riscv"
fi
@@ -39,8 +43,15 @@ BDEPEND="
virtual/awk
"
+# we want dist-kernel block in BDEPEND because of portage resolver.
+# since linux-mod.eclass already sets version-unbounded dep, portage
+# will pull new versions. So we set it in BDEPEND which takes priority.
+# and we don't need in in git ebuild.
if [[ ${PV} != "9999" ]] ; then
- BDEPEND+=" verify-sig? ( app-crypt/openpgp-keys-openzfs )"
+ BDEPEND+="
+ verify-sig? ( app-crypt/openpgp-keys-openzfs )
+ dist-kernel? ( <virtual/dist-kernel-${ZFS_KERNEL_DEP}:= )
+ "
fi
# PDEPEND in this form is needed to trick portage suggest