|
| 1 | +# Copyright 1999-2024 Gentoo Authors |
| 2 | +# Distributed under the terms of the GNU General Public License v2 |
| 3 | + |
| 4 | +EAPI=8 |
| 5 | + |
| 6 | +MODULES_INITRAMFS_IUSE=+initramfs |
| 7 | +inherit autotools flag-o-matic linux-mod-r1 multiprocessing |
| 8 | + |
| 9 | +DESCRIPTION="Linux ZFS kernel module for sys-fs/zfs" |
| 10 | +HOMEPAGE="https://github.com/openzfs/zfs" |
| 11 | + |
| 12 | +MODULES_KERNEL_MAX=6.12 |
| 13 | +MODULES_KERNEL_MIN=4.18 |
| 14 | + |
| 15 | +if [[ ${PV} == 9999 ]] ; then |
| 16 | + EGIT_REPO_URI="https://github.com/openzfs/zfs.git" |
| 17 | + inherit git-r3 |
| 18 | + unset MODULES_KERNEL_MAX |
| 19 | +else |
| 20 | + VERIFY_SIG_OPENPGP_KEY_PATH=/usr/share/openpgp-keys/openzfs.asc |
| 21 | + inherit verify-sig |
| 22 | + |
| 23 | + MY_PV=${PV/_rc/-rc} |
| 24 | + SRC_URI="https://github.com/openzfs/zfs/releases/download/zfs-${MY_PV}/zfs-${MY_PV}.tar.gz" |
| 25 | + SRC_URI+=" verify-sig? ( https://github.com/openzfs/zfs/releases/download/zfs-${MY_PV}/zfs-${MY_PV}.tar.gz.asc )" |
| 26 | + S="${WORKDIR}/zfs-${MY_PV}" |
| 27 | + |
| 28 | + ZFS_KERNEL_COMPAT="${MODULES_KERNEL_MAX}" |
| 29 | + # Increments minor eg 5.14 -> 5.15, and still supports override. |
| 30 | + ZFS_KERNEL_DEP="${ZFS_KERNEL_COMPAT_OVERRIDE:-${ZFS_KERNEL_COMPAT}}" |
| 31 | + ZFS_KERNEL_DEP="${ZFS_KERNEL_DEP%%.*}.$(( ${ZFS_KERNEL_DEP##*.} + 1))" |
| 32 | + |
| 33 | + if [[ ${PV} != *_rc* ]] ; then |
| 34 | + KEYWORDS="amd64 arm64 ~loong ~ppc64 ~riscv ~sparc" |
| 35 | + fi |
| 36 | +fi |
| 37 | + |
| 38 | +LICENSE="CDDL MIT debug? ( GPL-2+ )" |
| 39 | +SLOT="0/${PVR}" |
| 40 | +IUSE="custom-cflags debug +rootfs" |
| 41 | +RESTRICT="test" |
| 42 | + |
| 43 | +BDEPEND=" |
| 44 | + app-alternatives/awk |
| 45 | + dev-lang/perl |
| 46 | +" |
| 47 | + |
| 48 | +if [[ ${PV} != 9999 ]] ; then |
| 49 | + BDEPEND+=" verify-sig? ( sec-keys/openpgp-keys-openzfs )" |
| 50 | + |
| 51 | + IUSE+=" +dist-kernel-cap" |
| 52 | + RDEPEND=" |
| 53 | + dist-kernel-cap? ( dist-kernel? ( |
| 54 | + <virtual/dist-kernel-${ZFS_KERNEL_DEP} |
| 55 | + ) ) |
| 56 | + " |
| 57 | +fi |
| 58 | + |
| 59 | +# Used to suggest matching USE, but without suggesting to disable |
| 60 | +PDEPEND="dist-kernel? ( ~sys-fs/zfs-${PV}[dist-kernel] )" |
| 61 | + |
| 62 | +PATCHES=( |
| 63 | + "${FILESDIR}"/${PN}-2.1.11-gentoo.patch |
| 64 | +) |
| 65 | + |
| 66 | +pkg_pretend() { |
| 67 | + use rootfs || return 0 |
| 68 | +} |
| 69 | + |
| 70 | +pkg_setup() { |
| 71 | + local CONFIG_CHECK=" |
| 72 | + EFI_PARTITION |
| 73 | + ZLIB_DEFLATE |
| 74 | + ZLIB_INFLATE |
| 75 | + !DEBUG_LOCK_ALLOC |
| 76 | + !PAX_KERNEXEC_PLUGIN_METHOD_OR |
| 77 | + " |
| 78 | + use debug && CONFIG_CHECK+=" |
| 79 | + DEBUG_INFO |
| 80 | + FRAME_POINTER |
| 81 | + !DEBUG_INFO_REDUCED |
| 82 | + " |
| 83 | + use rootfs && CONFIG_CHECK+=" |
| 84 | + BLK_DEV_INITRD |
| 85 | + DEVTMPFS |
| 86 | + " |
| 87 | + |
| 88 | + kernel_is -lt 5 && CONFIG_CHECK+=" IOSCHED_NOOP" |
| 89 | + |
| 90 | + if [[ ${PV} != 9999 ]] ; then |
| 91 | + local kv_major_max kv_minor_max zcompat |
| 92 | + zcompat="${ZFS_KERNEL_COMPAT_OVERRIDE:-${ZFS_KERNEL_COMPAT}}" |
| 93 | + kv_major_max="${zcompat%%.*}" |
| 94 | + zcompat="${zcompat#*.}" |
| 95 | + kv_minor_max="${zcompat%%.*}" |
| 96 | + kernel_is -le "${kv_major_max}" "${kv_minor_max}" || die \ |
| 97 | + "Linux ${kv_major_max}.${kv_minor_max} is the latest supported version" |
| 98 | + fi |
| 99 | + |
| 100 | + linux-mod-r1_pkg_setup |
| 101 | +} |
| 102 | + |
| 103 | +src_prepare() { |
| 104 | + default |
| 105 | + |
| 106 | + # Run unconditionally (bug #792627) |
| 107 | + eautoreconf |
| 108 | + |
| 109 | + if [[ ${PV} != 9999 ]] ; then |
| 110 | + # Set module revision number |
| 111 | + sed -Ei "s/(Release:.*)1/\1${PR}-gentoo/" META || die |
| 112 | + fi |
| 113 | +} |
| 114 | + |
| 115 | +src_configure() { |
| 116 | + use custom-cflags || strip-flags |
| 117 | + filter-ldflags -Wl,* |
| 118 | + |
| 119 | + local myconf=( |
| 120 | + --bindir="${EPREFIX}"/bin |
| 121 | + --sbindir="${EPREFIX}"/sbin |
| 122 | + --with-config=kernel |
| 123 | + --with-linux="${KV_DIR}" |
| 124 | + --with-linux-obj="${KV_OUT_DIR}" |
| 125 | + $(use_enable debug) |
| 126 | + |
| 127 | + # See gentoo.patch |
| 128 | + GENTOO_MAKEARGS_EVAL="${MODULES_MAKEARGS[*]@Q}" |
| 129 | + TEST_JOBS="$(makeopts_jobs)" |
| 130 | + ) |
| 131 | + |
| 132 | + econf "${myconf[@]}" |
| 133 | +} |
| 134 | + |
| 135 | +src_compile() { |
| 136 | + emake "${MODULES_MAKEARGS[@]}" |
| 137 | +} |
| 138 | + |
| 139 | +src_install() { |
| 140 | + emake "${MODULES_MAKEARGS[@]}" DESTDIR="${ED}" install |
| 141 | + modules_post_process |
| 142 | + |
| 143 | + dodoc AUTHORS COPYRIGHT META README.md |
| 144 | +} |
| 145 | + |
| 146 | +_old_layout_cleanup() { |
| 147 | + # new files are just extra/{spl,zfs}.ko with no subdirs. |
| 148 | + local olddir=( |
| 149 | + avl/zavl |
| 150 | + icp/icp |
| 151 | + lua/zlua |
| 152 | + nvpair/znvpair |
| 153 | + spl/spl |
| 154 | + unicode/zunicode |
| 155 | + zcommon/zcommon |
| 156 | + zfs/zfs |
| 157 | + zstd/zzstd |
| 158 | + ) |
| 159 | + |
| 160 | + # kernel/module/Kconfig contains possible compressed extentions. |
| 161 | + local kext kextfiles |
| 162 | + for kext in .ko{,.{gz,xz,zst}}; do |
| 163 | + kextfiles+=( "${olddir[@]/%/${kext}}" ) |
| 164 | + done |
| 165 | + |
| 166 | + local oldfile oldpath |
| 167 | + for oldfile in "${kextfiles[@]}"; do |
| 168 | + oldpath="${EROOT}/lib/modules/${KV_FULL}/extra/${oldfile}" |
| 169 | + if [[ -f "${oldpath}" ]]; then |
| 170 | + ewarn "Found obsolete zfs module ${oldfile} for current kernel ${KV_FULL}, removing." |
| 171 | + rm -rv "${oldpath}" || die |
| 172 | + # we do not remove non-empty directories just for safety in case there's something else. |
| 173 | + # also it may fail if there are both compressed and uncompressed modules installed. |
| 174 | + rmdir -v --ignore-fail-on-non-empty "${oldpath%/*.*}" || die |
| 175 | + fi |
| 176 | + done |
| 177 | +} |
| 178 | + |
| 179 | +pkg_postinst() { |
| 180 | + # Check for old module layout before doing anything else. |
| 181 | + # only attempt layout cleanup if new .ko location is used. |
| 182 | + local newko=( "${EROOT}/lib/modules/${KV_FULL}/extra"/{zfs,spl}.ko* ) |
| 183 | + # We check first array member, if glob above did not exand, it will be "zfs.ko*" and -f will return false. |
| 184 | + # if glob expanded -f will do correct file precense check. |
| 185 | + [[ -f ${newko[0]} ]] && _old_layout_cleanup |
| 186 | + |
| 187 | + linux-mod-r1_pkg_postinst |
| 188 | + |
| 189 | + if use x86 || use arm ; then |
| 190 | + ewarn "32-bit kernels will likely require increasing vmalloc to" |
| 191 | + ewarn "at least 256M and decreasing zfs_arc_max to some value less than that." |
| 192 | + fi |
| 193 | + |
| 194 | + if has_version sys-boot/grub ; then |
| 195 | + ewarn "This version of OpenZFS includes support for new feature flags" |
| 196 | + ewarn "that are incompatible with previous versions. GRUB2 support for" |
| 197 | + ewarn "/boot with the new feature flags is not yet available." |
| 198 | + ewarn "Do *NOT* upgrade root pools to use the new feature flags." |
| 199 | + ewarn "Any new pools will be created with the new feature flags by default" |
| 200 | + ewarn "and will not be compatible with older versions of OpenZFS. To" |
| 201 | + ewarn "create a new pool that is backward compatible wih GRUB2, use " |
| 202 | + ewarn |
| 203 | + ewarn "zpool create -o compatibility=grub2 ..." |
| 204 | + ewarn |
| 205 | + ewarn "Refer to /usr/share/zfs/compatibility.d/grub2 for list of features." |
| 206 | + fi |
| 207 | +} |
0 commit comments