commit:     5e47ac6dcaa221c21f68d733efe780fab29286c6
Author:     Marc Schiffbauer <mschiff <AT> gentoo <DOT> org>
AuthorDate: Thu Oct  9 19:04:25 2025 +0000
Commit:     Marc Schiffbauer <mschiff <AT> gentoo <DOT> org>
CommitDate: Thu Oct  9 19:10:04 2025 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=5e47ac6d

sys-fs/zfs: merge zfs-kmod into zfs

This commit merges the kmod-zfs ebuild into this ebuild so
this package will install kernel modules and userspace tools
in one package in the future

Thanks to Nowa Ammerlaan <nowa <AT> gentoo.org> for doing most
of the work here!
( https://github.com/gentoo/gentoo/pull/36718 )

Signed-off-by: Marc Schiffbauer <mschiff <AT> gentoo.org>

 sys-fs/zfs/files/zfs-2.1.11-gentoo.patch |  24 +++++
 sys-fs/zfs/metadata.xml                  |   3 +-
 sys-fs/zfs/zfs-9999.ebuild               | 168 +++++++++++++++++++++++++++----
 3 files changed, 172 insertions(+), 23 deletions(-)

diff --git a/sys-fs/zfs/files/zfs-2.1.11-gentoo.patch 
b/sys-fs/zfs/files/zfs-2.1.11-gentoo.patch
new file mode 100644
index 000000000000..53c5f27b3bed
--- /dev/null
+++ b/sys-fs/zfs/files/zfs-2.1.11-gentoo.patch
@@ -0,0 +1,24 @@
+Hack to pass the full linux-mod-r1 toolchain to make during ./configure.
+Not needed at build time given can pass it normally then.
+
+Eclass has workarounds, compiler/version matching, and its own set of
+user variables which creates disparity between ebuilds if not used.
+
+For the (normal) alternative: KERNEL_{CC,LD} alone is insufficient,
+but combining with KERNEL_LLVM=1 when CC_IS_CLANG will allow it
+to work for *most* people (will likely still need KERNEL_LD from
+linux-mod-r1, or ThinLTO kernels may fail with sandbox violations).
+
+Note KERNEL_* also cause failure if they contain spaces.
+
+https://bugs.gentoo.org/865157
+--- a/config/kernel.m4
++++ b/config/kernel.m4
+@@ -646,6 +646,5 @@
+       AC_TRY_COMMAND([
+           KBUILD_MODPOST_NOFINAL="$5" KBUILD_MODPOST_WARN="$6"
+-          make modules -k -j$TEST_JOBS ${KERNEL_CC:+CC=$KERNEL_CC}
+-          ${KERNEL_LD:+LD=$KERNEL_LD} ${KERNEL_LLVM:+LLVM=$KERNEL_LLVM}
++          make modules -k -j$TEST_JOBS '${GENTOO_MAKEARGS_EVAL}'
+           CONFIG_MODULES=y CFLAGS_MODULE=-DCONFIG_MODULES
+           -C $LINUX_OBJ $ARCH_UM M=$PWD/$1 >$1/build.log 2>&1])

diff --git a/sys-fs/zfs/metadata.xml b/sys-fs/zfs/metadata.xml
index ba57b9d0929d..51fb5208f9d8 100644
--- a/sys-fs/zfs/metadata.xml
+++ b/sys-fs/zfs/metadata.xml
@@ -6,6 +6,7 @@
                <name>Marc Schiffbauer</name>
        </maintainer>
        <use>
+               <flag name="dist-kernel-cap">Prevents upgrading to an 
unsupported kernel version when combined with USE=dist-kernel</flag>
                <flag name="kernel-builtin">Disable dependency on 
<pkg>sys-fs/zfs-kmod</pkg> under the assumption that ZFS is part of the kernel 
source tree</flag>
                <flag name="minimal">Don't install python scripts (arcstat, 
dbufstat etc) and avoid dependency on <pkg>dev-lang/python</pkg></flag>
                <flag name="pam">Install zfs_key pam module, for automatically 
loading zfs encryption keys for home datasets</flag>
@@ -14,7 +15,7 @@
        </use>
        <upstream>
                <bugs-to>https://github.com/openzfs/zfs/issues</bugs-to>
-               <doc>https://openzfs.github.io/openzfs-docs</doc>
+               <doc>https://openzfs.github.io/openzfs-docs/</doc>
                <remote-id type="github">openzfs/zfs</remote-id>
        </upstream>
        <longdescription lang="en">

diff --git a/sys-fs/zfs/zfs-9999.ebuild b/sys-fs/zfs/zfs-9999.ebuild
index b06580130ffd..97c08351ca1c 100644
--- a/sys-fs/zfs/zfs-9999.ebuild
+++ b/sys-fs/zfs/zfs-9999.ebuild
@@ -10,13 +10,20 @@ EAPI=8
 
 DISTUTILS_OPTIONAL=1
 DISTUTILS_USE_PEP517=setuptools
-PYTHON_COMPAT=( python3_{10..13} )
+PYTHON_COMPAT=( python3_{10..14} )
 
-inherit autotools bash-completion-r1 dist-kernel-utils distutils-r1 
flag-o-matic linux-info pam systemd udev usr-ldscript
+MODULES_INITRAMFS_IUSE=+initramfs
+MODULES_OPTIONAL_IUSE=+modules
 
-DESCRIPTION="Userland utilities for ZFS Linux kernel module"
+inherit autotools bash-completion-r1 distutils-r1 flag-o-matic linux-info
+inherit linux-mod-r1 multiprocessing pam systemd udev usr-ldscript
+
+DESCRIPTION="Linux kernel module and userland utilities for ZFS"
 HOMEPAGE="https://github.com/openzfs/zfs";
 
+MODULES_KERNEL_MAX=6.17
+MODULES_KERNEL_MIN=4.18
+
 if [[ ${PV} == "9999" ]]; then
        inherit git-r3
        EGIT_REPO_URI="https://github.com/openzfs/zfs.git";
@@ -29,17 +36,22 @@ else
        SRC_URI+=" verify-sig? ( 
https://github.com/openzfs/${PN}/releases/download/${MY_P}/${MY_P}.tar.gz.asc )"
        S="${WORKDIR}/${MY_P}"
 
+       ZFS_KERNEL_COMPAT="${MODULES_KERNEL_MAX}"
+       # 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 ~loong ~ppc64 ~riscv ~sparc"
        fi
 fi
 
-LICENSE="BSD-2 CDDL MIT"
+LICENSE="BSD-2 CDDL MIT modules? ( debug? ( GPL-2+ ) )"
 # just libzfs soname major for now.
 # possible candidates: libuutil, libzpool, libnvpair. Those do not provide 
stable abi, but are considered.
 # see libsoversion_check() below as well
 SLOT="0/6"
-IUSE="custom-cflags debug dist-kernel kernel-builtin minimal nls pam python 
+rootfs selinux test-suite unwind"
+IUSE="custom-cflags debug dist-kernel minimal nls pam python +rootfs selinux 
test-suite unwind"
 
 DEPEND="
        dev-libs/openssl:=
@@ -58,6 +70,7 @@ DEPEND="
 BDEPEND="
        app-alternatives/awk
        virtual/pkgconfig
+       modules? ( dev-lang/perl )
        nls? ( sys-devel/gettext )
        python? (
                ${DISTUTILS_DEPS}
@@ -70,12 +83,18 @@ BDEPEND="
 
 if [[ ${PV} != "9999" ]] ; then
        BDEPEND+=" verify-sig? ( sec-keys/openpgp-keys-openzfs )"
+
+       IUSE+=" +dist-kernel-cap"
+       RDEPEND="
+               dist-kernel-cap? ( dist-kernel? (
+                       <virtual/dist-kernel-${ZFS_KERNEL_DEP}
+               ) )
+       "
 fi
 
 # awk is used for some scripts, completions, and the Dracut module
 RDEPEND="
        ${DEPEND}
-       !kernel-builtin? ( ~sys-fs/zfs-kmod-${PV}:= )
        !prefix? ( virtual/udev )
        app-alternatives/awk
        sys-fs/udev-init-scripts
@@ -95,12 +114,9 @@ RDEPEND="
                sys-fs/mdadm
                sys-process/procps
        )
+       !sys-fs/zfs-kmod
 "
 
-# PDEPEND in this form is needed to trick portage suggest
-# enabling dist-kernel if only 1 package have it set, without suggesting to 
disable
-PDEPEND="dist-kernel? ( ~sys-fs/zfs-kmod-${PV}[dist-kernel] )"
-
 REQUIRED_USE="
        !minimal? ( ${PYTHON_REQUIRED_USE} )
        python? ( !minimal )
@@ -109,7 +125,13 @@ REQUIRED_USE="
 
 RESTRICT="test"
 
-PATCHES=()
+PATCHES=(
+       "${FILESDIR}"/${PN}-2.1.11-gentoo.patch
+)
+
+DOCS=(
+       AUTHORS COPYRIGHT META README.md
+)
 
 pkg_pretend() {
        use rootfs || return 0
@@ -124,7 +146,40 @@ pkg_pretend() {
 
 pkg_setup() {
        if use kernel_linux; then
-               linux-info_pkg_setup
+               if use modules; then
+                       local CONFIG_CHECK="
+                               EFI_PARTITION
+                               ZLIB_DEFLATE
+                               ZLIB_INFLATE
+                               !DEBUG_LOCK_ALLOC
+                               !PAX_KERNEXEC_PLUGIN_METHOD_OR
+                       "
+                       use debug && CONFIG_CHECK+="
+                               DEBUG_INFO
+                               FRAME_POINTER
+                               !DEBUG_INFO_REDUCED
+                       "
+                       use rootfs && CONFIG_CHECK+="
+                               BLK_DEV_INITRD
+                               DEVTMPFS
+                       "
+
+                       kernel_is -lt 5 && CONFIG_CHECK+=" IOSCHED_NOOP"
+
+                       if [[ ${PV} != 9999 ]] ; then
+                               local kv_major_max kv_minor_max zcompat
+                               
zcompat="${ZFS_KERNEL_COMPAT_OVERRIDE:-${ZFS_KERNEL_COMPAT}}"
+                               kv_major_max="${zcompat%%.*}"
+                               zcompat="${zcompat#*.}"
+                               kv_minor_max="${zcompat%%.*}"
+                               kernel_is -le "${kv_major_max}" 
"${kv_minor_max}" || die \
+                                       "Linux ${kv_major_max}.${kv_minor_max} 
is the latest supported version"
+                       fi
+
+                       linux-mod-r1_pkg_setup
+               else
+                       linux-info_pkg_setup
+               fi
 
                if ! linux_config_exists; then
                        ewarn "Cannot check the linux kernel configuration."
@@ -199,11 +254,12 @@ src_configure() {
 
        local myconf=(
                --bindir="${EPREFIX}/bin"
+               --sbindir="${EPREFIX}/sbin"
                --enable-shared
                --enable-sysvinit
                --localstatedir="${EPREFIX}/var"
                --sbindir="${EPREFIX}/sbin"
-               --with-config=user
+               --with-config="$(usex modules all user)"
                --with-dracutdir="${EPREFIX}/usr/lib/dracut"
                --with-linux="${KV_DIR}"
                --with-linux-obj="${KV_OUT_DIR}"
@@ -227,13 +283,22 @@ src_configure() {
                $(use_with unwind libunwind)
                --disable-static
                $(usex minimal --without-python --with-python="${EPYTHON}")
+
+               # See gentoo.patch
+               GENTOO_MAKEARGS_EVAL="${MODULES_MAKEARGS[*]@Q}"
+               TEST_JOBS="$(makeopts_jobs)"
        )
 
        econf "${myconf[@]}"
 }
 
 src_compile() {
-       default
+       if use modules; then
+               emake "${MODULES_MAKEARGS[@]}"
+       else
+               default
+       fi
+
        if use python; then
                pushd contrib/pyzfs >/dev/null || die
                distutils-r1_src_compile
@@ -242,7 +307,12 @@ src_compile() {
 }
 
 src_install() {
-       default
+       if use modules; then
+               emake "${MODULES_MAKEARGS[@]}" DESTDIR="${ED}" install
+               modules_post_process
+       else
+               default
+       fi
 
        gen_usr_ldscript -a nvpair uutil zfsbootenv zfs zfs_core zpool
 
@@ -268,16 +338,70 @@ src_install() {
        use minimal || python_fix_shebang "${ED}/bin"
 }
 
+_old_layout_cleanup() {
+       # new files are just extra/{spl,zfs}.ko with no subdirs.
+       local olddir=(
+               avl/zavl
+               icp/icp
+               lua/zlua
+               nvpair/znvpair
+               spl/spl
+               unicode/zunicode
+               zcommon/zcommon
+               zfs/zfs
+               zstd/zzstd
+       )
+
+       # kernel/module/Kconfig contains possible compressed extentions.
+       local kext kextfiles
+               for kext in .ko{,.{gz,xz,zst}}; do
+               kextfiles+=( "${olddir[@]/%/${kext}}" )
+       done
+
+       local oldfile oldpath
+       for oldfile in "${kextfiles[@]}"; do
+               oldpath="${EROOT}/lib/modules/${KV_FULL}/extra/${oldfile}"
+               if [[ -f "${oldpath}" ]]; then
+                       ewarn "Found obsolete zfs module ${oldfile} for current 
kernel ${KV_FULL}, removing."
+                       rm -rv "${oldpath}" || die
+                       # we do not remove non-empty directories just for 
safety in case there's something else.
+                       # also it may fail if there are both compressed and 
uncompressed modules installed.
+                       rmdir -v --ignore-fail-on-non-empty "${oldpath%/*.*}" 
|| die
+               fi
+       done
+}
+
 pkg_postinst() {
        udev_reload
 
-       # we always need userspace utils in sync with zfs-kmod
-       # so force initrd update for userspace as well, to avoid
-       # situation when zfs-kmod trigger initrd rebuild before
-       # userspace component is rebuilt
-       # KV_* variables are provided by linux-info.eclass
-       if [[ -z ${ROOT} ]] && use dist-kernel; then
-               dist-kernel_reinstall_initramfs "${KV_DIR}" "${KV_FULL}"
+       if use modules; then
+               # Check for old module layout before doing anything else.
+               # only attempt layout cleanup if new .ko location is used.
+               local newko=( 
"${EROOT}/lib/modules/${KV_FULL}/extra"/{zfs,spl}.ko* )
+               # We check first array member, if glob above did not exand, it 
will be "zfs.ko*" and -f will return false.
+               # if glob expanded -f will do correct file precense check.
+               [[ -f ${newko[0]} ]] && _old_layout_cleanup
+
+               linux-mod-r1_pkg_postinst
+
+               if use x86 || use arm ; then
+                       ewarn "32-bit kernels will likely require increasing 
vmalloc to"
+                       ewarn "at least 256M and decreasing zfs_arc_max to some 
value less than that."
+               fi
+
+               if has_version sys-boot/grub ; then
+                       ewarn "This version of OpenZFS includes support for new 
feature flags"
+                       ewarn "that are incompatible with previous versions. 
GRUB2 support for"
+                       ewarn "/boot with the new feature flags is not yet 
available."
+                       ewarn "Do *NOT* upgrade root pools to use the new 
feature flags."
+                       ewarn "Any new pools will be created with the new 
feature flags by default"
+                       ewarn "and will not be compatible with older versions 
of OpenZFS. To"
+                       ewarn "create a new pool that is backward compatible 
wih GRUB2, use "
+                       ewarn
+                       ewarn "zpool create -o compatibility=grub2 ..."
+                       ewarn
+                       ewarn "Refer to /usr/share/zfs/compatibility.d/grub2 
for list of features."
+               fi
        fi
 
        if use rootfs; then

Reply via email to