Github messages for voidlinux
 help / color / mirror / Atom feed
From: ahesford <ahesford@users.noreply.github.com>
To: ml@inbox.vuxu.org
Subject: Re: [PR PATCH] [Updated] dkms: run depmod if necessary in kernel post-install hook
Date: Sun, 05 Jul 2020 03:19:21 +0200	[thread overview]
Message-ID: <20200705011921.VJtqYye8MNWUiKAwn4LfuFJtMlYlhJDCYWI7Pz8zzys@z> (raw)
In-Reply-To: <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-23392@inbox.vuxu.org>

[-- Attachment #1: Type: text/plain, Size: 1888 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages dkms
https://github.com/void-linux/void-packages/pull/23392

dkms: run depmod if necessary in kernel post-install hook
Normally, `dkms install` will run depmod with each installed module to update module dependency lists. When force-reinstalling kernel packages, `dkms install` will not run because modules are already marked installed, but the kernel package will overwrite `modules.dep` and `modules.dep.bin` with packaged versions that do not include any modules installed by dkms. The kernel post-install hook now tracks whether depmod should be run and will do so if necessary.

To demonstrate the original problem:

1. Install `zfs` and enable the dracut zfs module with `add_dracutmodules+=" zfs "` in `dracut.conf` or a `.conf` file in `/etc/dracut.conf.d`.
2. Rerun `dracut`, e.g., with `xbps-reconfigure -f linuxX.Y` for an appropriate kernel package.
3. Confirm that `zfs.ko.gz` is in the newly generated initramfs.
4. Force-reinstall the kernel package: `xbps-install -f linuxX.Y`.
5. Confirm that `zfs.ko.gz` is *missing* from the newly generated initramfs.

With the changes in the hook, the force-installation of `linuxX.Y` should display `Generating kernel module dependency lists... done.` after "building" all DKMS modules (note: the modules were already built for the reinstalled kernel, so the `dkms build` run by the hook is basically a no-op). The resulting initramfs will contain `zfs.ko.gz` as expected.

Also, I propagated some return codes from `dkms` through the hook, which I believe was the original intention. (Before the fix, `exit $?` after an `echo` would generally always exit 0 because `echo` is unlikely to fail.)

A patch file from https://github.com/void-linux/void-packages/pull/23392.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-dkms-23392.patch --]
[-- Type: text/x-diff, Size: 4269 bytes --]

From 4e0fc9fd770d069fc5802b6aff687a430787d705 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Sat, 4 Jul 2020 16:33:31 -0400
Subject: [PATCH] dkms: improvements to kernel post-install hook

When force-reinstalling kernel packages, `dkms install` is not run in
the kernel post-install hook because the modules are already installed.
This prevents `dkms install` from running `depmod -a` as it normally
does, but the forced reinstallation clobbers `modules.dep{,.bin}` with
the packaged versions that do not include DKMS-installed modules. The
post-install hook now tracks whether `depmod -a` should be run and does
so when necessary.

Other changes, courtesy of @ericonr, address issue #23124 wherein a DKMS
failure will terminate the script, preventing building or installation
of subsequent modules. The fix follows logic similar to that in the DKMS
xbps-trigger.
---
 srcpkgs/dkms/files/kernel.d/dkms.postinst | 55 +++++++++++++++++------
 srcpkgs/dkms/template                     |  2 +-
 2 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/srcpkgs/dkms/files/kernel.d/dkms.postinst b/srcpkgs/dkms/files/kernel.d/dkms.postinst
index bfeaf34fccf..c8a8deae0d4 100644
--- a/srcpkgs/dkms/files/kernel.d/dkms.postinst
+++ b/srcpkgs/dkms/files/kernel.d/dkms.postinst
@@ -40,49 +40,78 @@ for _mod_ in /var/lib/dkms/*; do
 	done
 done
 
+# This sections builds and install the available modules.
+#
+# If either building or installing a module fails, a warning is
+# printed and it is skipped, but the script still tries to build
+# the other modules.
+#
+# The list of available modules is in the form
+# [module1, modulever1, module2, modulever2, ...]
+#
 set -- ${DKMS_MODULES}
 while [ $# -ne 0 ]; do
 	module="$1"
 	modulever="$2"
 
+	# If adding a module, depmod is necessary unless dkms runs it
+	do_depmod="yes"
+
 	status=$(dkms status -m ${module} -v ${modulever} -k ${VERSION})
 	if [ $(echo "$status"|grep -c ": built") -eq 0 ]; then
 		# Check if the module is still there.
 		if [ ! -f usr/src/${module}-${modulever}/dkms.conf ]; then
 			echo "Skipping unexistent DKMS module: ${module}-${modulever}."
-			shift 2
-			continue
+			shift 2; continue
 		fi
 		# Build the module
 		echo -n "Building DKMS module: ${module}-${modulever}... "
 		dkms build -q -m ${module} -v ${modulever} -k ${VERSION} -a ${ARCH}
 		rval=$?
-		if [ $rval -eq 9 ]; then
-			echo "skipped!"
-			shift; shift
-			continue
-		elif [ $rval -eq 0 ]; then
+		# If the module was skipped or failed, go to the next module.
+		if [ $rval -eq 0 ]; then
 			echo "done."
+		elif [ $rval -eq 9 ]; then
+			echo "skipped!"
+			shift 2; continue
 		else
 			echo "FAILED!"
-			exit $?
+			shift 2; continue
 		fi
 		status=$(dkms status -m ${module} -v ${modulever} -k ${VERSION})
 	fi
 
-	#if the module is built (either pre-built or just now), install it
+	# If the module is built (either pre-built or just now), install it
 	if [ $(echo "$status"|grep -c ": built") -eq 1 ] &&
 	   [ $(echo "$status"|grep -c ": installed") -eq 0 ]; then
 		echo -n "Installing DKMS module: ${module}-${modulever}... "
-	        dkms install -q -m ${module} -v ${modulever} -k ${VERSION} -a ${ARCH}
-		if [ $? -eq 0 ]; then
+		dkms install -q -m ${module} -v ${modulever} -k ${VERSION} -a ${ARCH}
+		rval=$?
+		# If the module failed installation, go to the next module.
+		if [ $rval -eq 0 ]; then
+			# dkms runs depmod as part of the installation
+			unset do_depmod
 			echo "done."
 		else
 			echo "FAILED!"
-			exit $?
+			shift 2; continue
 		fi
 	fi
-	shift; shift
+
+	# Go to the next module - all steps for this module were successful.
+	shift 2
 done
 
+if [ -n "$do_depmod" ]; then
+	echo -n "Generating kernel module dependency lists... "
+	depmod -a ${VERSION}
+	rval=$?
+	if [ $rval -eq 0 ]; then
+		echo "done."
+	else
+		echo "FAILED!"
+		exit $rval
+	fi
+fi
+
 exit 0
diff --git a/srcpkgs/dkms/template b/srcpkgs/dkms/template
index 521dfde1114..32345b9b421 100644
--- a/srcpkgs/dkms/template
+++ b/srcpkgs/dkms/template
@@ -2,7 +2,7 @@
 pkgname=dkms
 reverts="2.8.2_1"
 version=2.8.1
-revision=3
+revision=4
 conf_files="/etc/dkms/framework.conf"
 depends="bash kmod gcc make coreutils linux-headers"
 short_desc="Dynamic Kernel Modules System"

  reply	other threads:[~2020-07-05  1:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-04 20:51 [PR PATCH] " ahesford
2020-07-05  1:19 ` ahesford [this message]
2020-07-05  1:20 ` ahesford
2020-07-11  1:34 ` [PR PATCH] [Updated] dkms: improvements to post-install hook: run depmod if necessary and better handle DKMS build/install failures ahesford
2020-07-11  1:44 ` [PR REVIEW] " ericonr
2020-07-11  1:50 ` [PR PATCH] [Updated] " ahesford
2020-07-11  2:00 ` ahesford
2020-07-11  2:01 ` [PR REVIEW] " ahesford
2020-07-11  2:18 ` [PR PATCH] [Updated] " ahesford
2020-07-11  2:21 ` [PR PATCH] [Merged]: " ahesford

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200705011921.VJtqYye8MNWUiKAwn4LfuFJtMlYlhJDCYWI7Pz8zzys@z \
    --to=ahesford@users.noreply.github.com \
    --cc=ml@inbox.vuxu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).