[ovs-dev] [PATCH v1] rhel: support kmod build against mulitple kernel versions, fedora

Martin Xu martinxu9.ovs at gmail.com
Fri Jul 20 22:24:53 UTC 2018


This patch ports changes from kmod rhel6 spec file to fedora spec file,
to support packaging kernel modules built against multiple versions of
kernel sources.

RHEL 7.4 introduced backward incompatible changes in the kernel. As
a result, prebuilt PRM packages against kernels newer than 693.17.1
will cannot be used on systems with older kernels, vice versa.

Intended to work only on RHEL 7.4 (kernel version 3.10.0-693.yy.zz).
This patch allows multiple kernel version numbers delimited by
whitespace to be passed as variable "kversion". The result RPM packages
the kernel module .ko files from all specified kernel versions. For
example,

make rpm-fedora-kmod \
    RPMBUILD_OPT='-D "kversion 3.10.0-693.1.1.el7.x86_64 \
    3.10.0-693.17.1.el7.x86_64"'

By default, make tries to build against the current running kernel.

This patch also includes a script to update the weak-update symlinks
if the system kernel version is upgraded or downgraded after
openvswitch-kmod is installed.

Signed-off-by: Martin Xu <martinxu9.ovs at gmail.com>
CC: Greg Rose <gvrose8192 at gmail.com>
CC: Flavio Leitner <fbl at redhat.com>
---
 rhel/openvswitch-kmod-fedora.spec.in | 86 +++++++++++++++++++++++-------------
 1 file changed, 55 insertions(+), 31 deletions(-)

diff --git a/rhel/openvswitch-kmod-fedora.spec.in b/rhel/openvswitch-kmod-fedora.spec.in
index c0cd298..24f8290 100644
--- a/rhel/openvswitch-kmod-fedora.spec.in
+++ b/rhel/openvswitch-kmod-fedora.spec.in
@@ -1,6 +1,6 @@
 # Spec file for Open vSwitch.
 
-# Copyright (C) 2009, 2010, 2015 Nicira Networks, Inc.
+# Copyright (C) 2009, 2010, 2015, 2018 Nicira Networks, Inc.
 #
 # Copying and distribution of this file, with or without modification,
 # are permitted in any medium without royalty provided the copyright
@@ -26,6 +26,9 @@ Release: 1%{?dist}
 Source: openvswitch-%{version}.tar.gz
 #Source1: openvswitch-init
 Buildroot: /tmp/openvswitch-xen-rpm
+Provides: kmod-openvswitch
+Conflicts: kmod-openvswitch
+Obsoletes: kmod-openvswitch
 
 %description
 Open vSwitch provides standard network bridging functions augmented with
@@ -36,55 +39,76 @@ traffic. This package contains the kernel modules.
 %setup -q -n openvswitch-%{version}
 
 %build
-%configure --with-linux=/lib/modules/%{kernel}/build --enable-ssl
-make %{_smp_mflags} -C datapath/linux
+for kv in %{kversion}; do
+    mkdir -p _$kv
+    (cd _$kv && /bin/cp -f ../configure . && %configure --srcdir=.. \
+        --with-linux=/usr/src/kernels/${kv}/ --enable-ssl)
+    make %{_smp_mflags} -C _$kv/datapath/linux
+done
 
 %install
+export INSTALL_MOD_DIR=extra/openvswitch
 rm -rf $RPM_BUILD_ROOT
-make INSTALL_MOD_PATH=$RPM_BUILD_ROOT -C datapath/linux modules_install
+for kv in %{kversion}; do
+    make INSTALL_MOD_PATH=$RPM_BUILD_ROOT -C _$kv/datapath/linux modules_install
+done
 mkdir -p $RPM_BUILD_ROOT/etc/depmod.d
-for module in $RPM_BUILD_ROOT/lib/modules/%{kernel}/extra/*.ko
-do
-    modname="$(basename ${module})"
-    echo "override ${modname%.ko} * extra" >> \
-        $RPM_BUILD_ROOT/etc/depmod.d/kmod-openvswitch.conf
-    echo "override ${modname%.ko} * weak-updates" >> \
-        $RPM_BUILD_ROOT/etc/depmod.d/kmod-openvswitch.conf
+for kv in %{kversion}; do
+    for module in $RPM_BUILD_ROOT/lib/modules/${kv}/extra/openvswitch/*.ko
+    do
+        modname="$(basename ${module})"
+        grep -qsPo "^\s*override ${modname%.ko} \* extra\/openvwitch" \
+            $RPM_BUILD_ROOT/etc/depmod.d/kmod-openvswitch.conf || \
+            echo "override ${modname%.ko} * extra/openvswitch" >> \
+            $RPM_BUILD_ROOT/etc/depmod.d/kmod-openvswitch.conf
+        grep -qsPo "^\s*override ${modname%.ko} \* weak-updates\/openvwitch" \
+            $RPM_BUILD_ROOT/etc/depmod.d/kmod-openvswitch.conf || \
+            echo "override ${modname%.ko} * weak-updates/openvswitch" >> \
+            $RPM_BUILD_ROOT/etc/depmod.d/kmod-openvswitch.conf
+    done
 done
+install -d -m 0755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
+install -p -m 0755 rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh \
+    $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-kmod-manage.sh
 
 %clean
 rm -rf $RPM_BUILD_ROOT
 
 %post
-# Ensure that modprobe will find our modules.
-for k in $(cd /lib/modules && /bin/ls); do
-    [ -d "/lib/modules/$k/kernel/" ] && depmod -a "$k"
-done
-if [ -x "/sbin/weak-modules" ]; then
-    for m in openvswitch vport-gre vport-stt vport-geneve \
-             vport-lisp vport-vxlan; do
-        echo "/lib/modules/%{kernel}/extra/$m.ko"
-    done | /sbin/weak-modules --add-modules
-fi
-
-%postun
-for k in $(cd /lib/modules && /bin/ls); do
-    [ -d "/lib/modules/$k/kernel/" ] && depmod -a "$k"
-done
-if [ "$1" = 0 ]; then  # Erase, not upgrade
+current_kernel=$(uname -r)
+IFS=. read installed_major installed_minor installed_micro installed_arch \
+    installed_build <<<"${current_kernel##*-}"
+if [ "$installed_major" = "693" ]; then
+    # Workaround for RHEL 7.4
+    if [ -x "/usr/share/openvswitch/scripts/ovs-kmod-manage.sh" ]; then
+        /usr/share/openvswitch/scripts/ovs-kmod-manage.sh
+    fi
+else
+    # Ensure that modprobe will find our modules.
+    for k in $(cd /lib/modules && /bin/ls); do
+        [ -d "/lib/modules/$k/kernel/" ] && depmod -a "$k"
+    done
     if [ -x "/sbin/weak-modules" ]; then
         for m in openvswitch vport-gre vport-stt vport-geneve \
                  vport-lisp vport-vxlan; do
-        echo "/lib/modules/%{kernel}/extra/$m.ko"
-    done | /sbin/weak-modules --remove-modules
+            echo "/lib/modules/%{kernel}/extra/openvswitch/$m.ko"
+        done | /sbin/weak-modules --add-modules
     fi
 fi
 
+%postun
+for kname in `ls -d /lib/modules/*`
+do
+    rm -rf $kname/weak-updates/openvswitch
+done
+/sbin/depmod -a
+
 %files
 %defattr(0644,root,root)
-/lib/modules/%{kernel}/extra/*.ko
+/lib/modules/*/extra/openvswitch/*.ko
 /etc/depmod.d/kmod-openvswitch.conf
-%exclude /lib/modules/%{kernel}/modules.*
+%exclude /lib/modules/*/modules.*
+%attr(755,root,root) /usr/share/openvswitch/scripts/ovs-kmod-manage.sh
 
 %changelog
 * Wed Sep 21 2011 Kyle Mestery <kmestery at cisco.com>
-- 
1.8.3.1



More information about the dev mailing list