Skip to contentSkip to conversation

fix %preun script in drbd-km.spec from 8.3 package

Drbd-dev Alessandro Bono 2 participants 3 messages Oct 26, 2012 – Oct 29, 2012 DRBD driver

lore
Share & tools
lore
#0 lore raw

Hi

%preun script in drbd-km.spec try to unload drbd.ko if present without check kernel version running without this patch it's not possible to remove drbd-km package of old kernel

drbd-km.spec 2012-10-26 13:44:33.368384889 +0200 renamed from drbd-km.spec 2012-10-26 13:43:43.163366400 +0200 +2 -0
@@ -80,10 +80,12 @@
 rm -rf %{buildroot}
 
 %preun %{krelver}
+if [ 'uname -r' = %{kernelversion} ]; then
 lsmod | grep drbd > /dev/null 2>&1
 if [ $? -eq 0 ]; then
     rmmod drbd
 fi
+fi
 
 %post %{krelver}
 # hack for distribution kernel packages,                                  
maintainer
#1 lore raw
Quoted 4 lines · Alessandro Bono

Hi

%preun script in drbd-km.spec try to unload drbd.ko if present without check kernel version running without this patch it's not possible to remove drbd-km package of old kernel

... unless you first unload the current DRBD module as well, or use rpm -e --noscript.

Which in fact is intentional, to prevent people from "accidentally" uninstall a module package while the provided module is still in use (it may have been symlinked in place into some other kernel version
by some weak-module magic, or explicitly).

But yes, it may be annoying at times.

So maybe
filename=$(modinfo -F filename drbd)
filename=$(readlink "$filename")
rpm -qf $filename
and check if that is in fact the current package?

Quoted 15 lines
drbd-km.spec 2012-10-26 13:44:33.368384889 +0200 renamed from drbd-km.spec 2012-10-26 13:43:43.163366400 +0200 +2 -0
@@ -80,10 +80,12 @@
 rm -rf %{buildroot}
 
 %preun %{krelver}
+if [ 'uname -r' = %{kernelversion} ]; then
 lsmod | grep drbd > /dev/null 2>&1
 if [ $? -eq 0 ]; then
     rmmod drbd
 fi
+fi
 
 %post %{krelver}
 # hack for distribution kernel packages,                                  
Signature · 3 lines
: Lars Ellenberg
: LINBIT | Your Way to High Availability
: DRBD/HA support and consulting http://www.linbit.com
#2 lore raw
Quoted 13 lines · Lars Ellenberg
Quoted 4 lines · Alessandro Bono

Hi

%preun script in drbd-km.spec try to unload drbd.ko if present without check kernel version running without this patch it's not possible to remove drbd-km package of old kernel

... unless you first unload the current DRBD module as well, or use rpm -e --noscript.

Which in fact is intentional, to prevent people from "accidentally" uninstall a module package while the provided module is still in use (it may have been symlinked in place into some other kernel version
by some weak-module magic, or explicitly).

Quoted 7 lines

But yes, it may be annoying at times.

So maybe
filename=$(modinfo -F filename drbd)
filename=$(readlink "$filename")
rpm -qf $filename
and check if that is in fact the current package?

ok I cooked this patch
tested removing drbd for old and in use kernel on centos 6 please check readlink option, -e seems to me correct one but not sure

drbd-km.spec 2012-10-29 21:50:20.470461556 +0100 renamed from drbd-km.spec 2012-10-29 17:39:48.786446160 +0100 +6 -0
@@ -80,10 +80,16 @@
 rm -rf %{buildroot}
                                                                                                                                                                                                                                         
 %preun %{krelver}
+filename=$(modinfo -F filename drbd)
+filename=$(readlink -e "$filename")
+drbdrpm=$(rpm -qf "$filename")
+arch=$(uname -i)
+if [ $drbdrpm = %{name}-%{krelver}-%{version}-%{release}.$arch ]; then
 lsmod | grep drbd > /dev/null 2>&1
 if [ $? -eq 0 ]; then
     rmmod drbd
 fi
+fi
                                                                                                                                                                                                                                         
 %post %{krelver}
 # hack for distribution kernel packages,
Quoted 15 lines
Quoted 15 lines
drbd-km.spec 2012-10-26 13:44:33.368384889 +0200 renamed from drbd-km.spec 2012-10-26 13:43:43.163366400 +0200 +2 -0
@@ -80,10 +80,12 @@
  rm -rf %{buildroot}
 
  %preun %{krelver}
+if [ 'uname -r' = %{kernelversion} ]; then
  lsmod | grep drbd > /dev/null 2>&1
  if [ $? -eq 0 ]; then
      rmmod drbd
  fi
+fi
 
  %post %{krelver}
  # hack for distribution kernel packages,
Signature · 2 lines
Cordiali Saluti
Alessandro Bono