[ovs-dev] [PATCH v3 3/3] rhel: support kmod-openvswitch build against multiple kernels, rhel6

Flavio Leitner fbl at redhat.com
Thu Jul 12 19:47:50 UTC 2018


On Thu, Jul 12, 2018 at 10:35:56AM -0700, Martin Xu wrote:
> This patch only affects rhel6 spec file.
> 
> 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.
> 
> This patch allows multiple kernel version numbers delimited by
> whitespace to be passed as variable "kversion". kmod-openvswitch RPM
> packages the kernel module .ko files from all specified kernel
> versions.
> 
> This patch also includes a script to update the weak-update symlinks
> if the system kernel version is upgraded or downgraded after
> kmod-openvswitch is installed.
> 
> Signed-off-by: Martin Xu <martinxu9.ovs at gmail.com>
> Co-authored-by: Greg Rose <gvrose8192 at gmail.com>
> CC: Ben Pfaff <blp at ovn.org>
> CC: Flavio Leitner <fbl at redhat.com>
> CC: Aaron Conole <aconole at redhat.com>
> ---
>  rhel/automake.mk                                   |  1 +
>  rhel/kmod-openvswitch-rhel6.spec.in                | 87 +++++++++++++---------
>  ...sr_share_openvswitch_scripts_ovs-kmod-manage.sh | 74 ++++++++++++++++++
>  3 files changed, 127 insertions(+), 35 deletions(-)
>  create mode 100644 rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh
> 
> diff --git a/rhel/automake.mk b/rhel/automake.mk
> index 180419427..7b6c78fd7 100644
> --- a/rhel/automake.mk
> +++ b/rhel/automake.mk
> @@ -26,6 +26,7 @@ EXTRA_DIST += \
>  	rhel/usr_share_openvswitch_scripts_ovs-systemd-reload \
>  	rhel/usr_share_openvswitch_scripts_sysconfig.template \
>  	rhel/usr_share_openvswitch_scripts_systemd_sysconfig.template \
> +	rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh \
>  	rhel/usr_lib_udev_rules.d_91-vfio.rules \
>  	rhel/usr_lib_systemd_system_openvswitch.service \
>  	rhel/usr_lib_systemd_system_ovsdb-server.service \
> diff --git a/rhel/kmod-openvswitch-rhel6.spec.in b/rhel/kmod-openvswitch-rhel6.spec.in
> index 7b9424968..f5ca134ed 100644
> --- a/rhel/kmod-openvswitch-rhel6.spec.in
> +++ b/rhel/kmod-openvswitch-rhel6.spec.in
> @@ -27,10 +27,12 @@ BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
>  
>  %define kernel_source_extended() /usr/src/kernels/%{2}$([ %{1} = default ] || echo ".%{1}")
>  
> -# By default, build against the latest installed kernel-devel
> -%{!?kversion:%global kversion %(rpm -q --qf '%{VERSION}-%{RELEASE}.%{ARCH}' `rpm -qa | egrep "^kernel(-rt|-aarch64)?-devel" | /usr/lib/rpm/redhat/rpmsort -r | head -n 1` | head -n 1)}
>  # Use -D 'kversion 2.6.32-131.6.1.el6.x86_64' to build package
>  # for specified kernel version.
> +# Use -D 'kversion 3.10.0-693.1.1.el7.x86_64 3.10.0-693.17.1.el7.x86_64'
> +# to build package for mulitple kernel versions in the same package
> +# By default, build against the latest installed kernel-devel
> +%{!?kversion:%global kversion %(rpm -q --qf '%{VERSION}-%{RELEASE}.%{ARCH}' `rpm -qa | egrep "^kernel(-rt|-aarch64)?-devel" | /usr/lib/rpm/redhat/rpmsort -r | head -n 1` | head -n 1)}

Same comment as for the previous patch about macro expansion.

>  
>  # Use -D 'kflavors default debug kdump' to build packages for
>  # specified kernel variants.
> @@ -44,60 +46,75 @@ Open vSwitch Linux kernel module.
>  %setup -n %{oname}-%{version}
>  
>  %build
> -for flavor in %{kflavors} ; do
> -        mkdir _$flavor
> -        (cd _$flavor && ../configure --with-linux="%{kernel_source_extended $flavor %{kversion}}")
> -        %{__make} -C _$flavor/datapath/linux %{?_smp_mflags}
> +for kv in %{kversion}; do
> +    for flavor in %{kflavors}; do
> +        mkdir -p _$flavor/_$kv
> +        (cd _$flavor/_$kv && ../../configure --with-linux="%{kernel_source_extended $flavor $kv}")
> +        %{__make} -C _$flavor/_$kv/datapath/linux %{?_smp_mflags}
> +        done
>  done
>  
>  %install
>  export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
>  export INSTALL_MOD_DIR=extra/%{oname}
> -for flavor in %{kflavors} ; do
> -         make -C %{kernel_source_extended $flavor %{kversion}} modules_install \
> -                 M="`pwd`"/_$flavor/datapath/linux
> -
> -         # Cleanup unnecessary kernel-generated module dependency files.
> -         find $INSTALL_MOD_PATH/lib/modules -iname 'modules.*' -exec rm {} \;
> +for kv in %{kversion}; do
> +    for flavor in %{kflavors} ; do
> +        make -C %{kernel_source_extended $flavor $kv} modules_install \
> +                M="`pwd`"/_$flavor/_$kv/datapath/linux
> +        # Cleanup unnecessary kernel-generated module dependency files.
> +        find $INSTALL_MOD_PATH/lib/modules -iname 'modules.*' -exec rm {} \;
> +    done
>  done
>  install -d %{buildroot}%{_sysconfdir}/depmod.d/
> -for module in %{buildroot}/lib/modules/%{kversion}/$INSTALL_MOD_DIR/*.ko;
> -do
> -    modname="$(basename ${module})"
> -    echo "override ${modname%.ko} * extra/%{oname}" >> %{oname}.conf
> -    echo "override ${modname%.ko} * weak-updates/%{oname}" >> %{oname}.conf
> +for kv in %{kversion}; do
> +    for module in %{buildroot}/lib/modules/$kv/$INSTALL_MOD_DIR/*.ko;
> +    do
> +        modname="$(basename ${module})"
> +        grep -qsPo "^\s*override ${modname%.ko} \* extra\/%{oname}" %{oname}.conf || \
> +            echo "override ${modname%.ko} * extra/%{oname}" >> %{oname}.conf
> +        grep -qsPo "^\s*override ${modname%.ko} \* weak-updates\/%{oname}" %{oname}.conf || \
> +            echo "override ${modname%.ko} * weak-updates/%{oname}" >> %{oname}.conf
> +    done
>  done
>  install -m 644 %{oname}.conf %{buildroot}%{_sysconfdir}/depmod.d/
> +install -d -m 0755 $RPM_BUILD_ROOT/usr/share/%{oname}/scripts
> +install -p -m 0755 rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh \
> +    $RPM_BUILD_ROOT/usr/share/%{oname}/scripts/ovs-kmod-manage.sh
>  
>  %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/%{kversion}/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/%{oname}/scripts/ovs-kmod-manage.sh" ]; then
> +        /usr/share/%{oname}/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/%{kversion}/extra/$m.ko"
> -    done | /sbin/weak-modules --remove-modules
> +            echo "/lib/modules/%{kversion}/extra/%{oname}/$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(644,root,root,755)
>  /etc/depmod.d/%{oname}.conf
>  /lib/modules/
> +%attr(755,root,root) /usr/share/%{oname}/scripts/ovs-kmod-manage.sh
>  
>  %clean
>  rm -rf $RPM_BUILD_ROOT
> diff --git a/rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh b/rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh
> new file mode 100644
> index 000000000..f2cdca48f
> --- /dev/null
> +++ b/rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh
> @@ -0,0 +1,74 @@
> +#!/bin/sh
> +
> +# Copyright (c) 2018 Nicira/VMware, Inc.
> +#
> +# Licensed under the Apache License, Version 2.0 (the "License");
> +# you may not use this file except in compliance with the License.
> +# You may obtain a copy of the License at:
> +#
> +#     http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS,
> +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +# See the License for the specific language governing permissions and
> +# limitations under the License.

It would be nice to have a small documentation here to what this
script is supposed to do.

I haven't tested this, but I didn't spot anything odd too.
Thanks,
fbl

> +
> +script_name=$(basename -- "$0")
> +current_kernel=$(uname -r)
> +echo current kernel is $current_kernel
> +
> +IFS=. read installed_major installed_minor installed_micro \
> +    installed_arch installed_build <<<"${current_kernel##*-}"
> +# echo installed_major=$installed_major installed_minor=$installed_minor \
> +# installed_micro=$installed_micro installed_arch=$installed_arch \
> +# installed_build=$installed_build
> +
> +expected_base_minor="el7"
> +expected_minor=11
> +
> +found_match=false
> +for kname in `ls -d /lib/modules/*`
> +do
> +    IFS=. read major minor micro arch build <<<"${kname##*-}"
> +#   echo major=$major minor=$minor micro=$micro arch=$arch build=$build
> +    if [ "$installed_minor" = "$expected_base_minor" ] ||
> +       [ "$installed_minor" -le "$expected_minor" ]; then
> +        if [ "$minor" = "1" ]; then
> +            requested_kernel=$kname
> +            found_match="true"
> +            echo "Installing Openvswitch KMOD from kernel $kname"
> +            break
> +        fi
> +    else
> +        if [ "$minor" = "17" ]; then
> +            requested_kernel=$kname
> +            found_match="true"
> +            echo "Installing Openvswitch KMOD from kernel $kname"
> +            break
> +        fi
> +    fi
> +done
> +
> +if [ "$found_match" = "false" ]; then
> +    echo $script_name: Failed
> +    exit 1
> +fi
> +
> +if [ "$requested_kernel" != "/lib/modules/$current_kernel" ]; then
> +    if [ -x "/sbin/weak-modules" ]; then
> +        if [ ! -d /lib/modules/$current_kernel/weak-updates/openvswitch ]; then
> +            mkdir -p /lib/modules/$current_kernel/weak-updates
> +            mkdir -p /lib/modules/$current_kernel/weak-updates/openvswitch
> +        fi
> +        for m in openvswitch vport-gre vport-stt vport-geneve \
> +            vport-lisp vport-vxlan; do
> +            ln -f -s $requested_kernel/extra/openvswitch/$m.ko \
> +                /lib/modules/$current_kernel/weak-updates/openvswitch/$m.ko
> +        done
> +    fi
> +else
> +    echo Proper OVS kernel modules already configured
> +fi
> +# Always run depmod
> +/sbin/depmod -a
> -- 
> 2.15.2 (Apple Git-101.1)
> 

-- 
Flavio


More information about the dev mailing list