From 4d6e1a14ae231b7ddc695e73e29487b363643094 Mon Sep 17 00:00:00 2001 From: Greg Cymbalski Date: Tue, 2 Apr 2024 11:36:13 -0700 Subject: [PATCH] More safely install/uninstall with weak-modules This addresses some minor issues with how we handle driving the weak-modules infrastructure for handling running on kernels not explicitly built for. For one, we now drive weak-modules at install-time more explicitly (it was adding symlinks for all modules into the right place for the running kernel, whereas now it only handles that for scoutfs against all installed kernels). Also we no longer leave stale modules on the filesystem after an uninstall/upgrade, similar to what's done for vsm's kmods right now. RPM's pre/postinstall scriptlets are used to drive weak-modules to clean things up. Note that this (intentionally) does not (re)generate initrds of any kind. Finally, this was tested on both the native kernel version and on updates that would need the migrated modules. As a result, installs are a little quicker, the module still gets migrated successfully, and uninstalls correctly remove (only) the packaged module. --- kmod/scoutfs-kmod.spec.in | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kmod/scoutfs-kmod.spec.in b/kmod/scoutfs-kmod.spec.in index e9cfc2dc..3a03af1b 100644 --- a/kmod/scoutfs-kmod.spec.in +++ b/kmod/scoutfs-kmod.spec.in @@ -97,10 +97,21 @@ find %{buildroot} -type f -name \*.ko -exec %{__chmod} u+x \{\} \; /lib/modules %post -weak-modules --add-kernel --no-initramfs +echo /lib/modules/%{kversion}/%{install_mod_dir}/scoutfs.ko | weak-modules --add-modules --no-initramfs depmod -a %endif %clean rm -rf %{buildroot} +%preun +# stash our modules for postun cleanup +SCOUTFS_RPM_NAME=$(rpm -q %{name} | grep "%{version}-%{release}") +rpm -ql $SCOUTFS_RPM_NAME | grep '\.ko$' > /var/run/%{name}-modules-%{version}-%{release} || true + +%postun +if [ -x /sbin/weak-modules ]; then + cat /var/run/%{name}-modules-%{version}-%{release} | /sbin/weak-modules --remove-modules --no-initramfs +fi + +rm /var/run/%{name}-modules-%{version}-%{release} || true