diff mbox series

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

Message ID CAFu83u-SZQ4XOUfjgOhp3B+tzt41_Krn=sB9rCpSuuWaD5kX3A@mail.gmail.com
State Not Applicable
Headers show
Series [ovs-dev] rhel: support kmod-openvswitch build against multiple kernels, rhel6 | expand

Commit Message

Martin Xu July 10, 2018, 10:42 p.m. UTC
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.

Previouly the kernel_module_package macro is used to generate spec file
template to build kmod-openvswitch RPM. This macro is now removed.
Everything is built in the main package. To maintain consistent naming,
the rhel6 kmod spec file is renamed to kmod-openvswitch-rhel6.spec to
match the built package name kmod-openvswitch.

This patch also removes the openvswitch-kmod package.
---
 Documentation/intro/install/rhel.rst               |   7 +-
 poc/playbook-centos-builder.yml                    |   8 +-
 rhel/.gitignore                                    |   1 +
 rhel/automake.mk                                   |   8 +-
 rhel/kmod-openvswitch-rhel6.spec.in                | 120
+++++++++++++++++++++
 rhel/openvswitch-kmod-rhel6.spec.in                | 103 ------------------
 rhel/openvswitch-kmod.files                        |   3 -
 ...sr_share_openvswitch_scripts_ovs-kmod-manage.sh |  71 ++++++++++++
 8 files changed, 203 insertions(+), 118 deletions(-)
 create mode 100644 rhel/kmod-openvswitch-rhel6.spec.in
 delete mode 100644 rhel/openvswitch-kmod-rhel6.spec.in
 delete mode 100644 rhel/openvswitch-kmod.files
 create mode 100644 rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh

+    echo Proper OVS kernel modules already configured
+fi
+# Always run depmod
+/sbin/depmod -a

Comments

Gregory Rose July 10, 2018, 10:54 p.m. UTC | #1
On 7/10/2018 3:42 PM, 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.
>
> Previouly the kernel_module_package macro is used to generate spec file
> template to build kmod-openvswitch RPM. This macro is now removed.
> Everything is built in the main package. To maintain consistent naming,
> the rhel6 kmod spec file is renamed to kmod-openvswitch-rhel6.spec to
> match the built package name kmod-openvswitch.
>
> This patch also removes the openvswitch-kmod package.

Oops, no signed off by line.

I'm adding Aaron and Flavio so the Red Hat guys can give it a look. You 
can wait for their review
comments and then spin up a Rev 2 with the fixed signed off by line.

Thanks for the patch!

- Greg



> ---
>   Documentation/intro/install/rhel.rst               |   7 +-
>   poc/playbook-centos-builder.yml                    |   8 +-
>   rhel/.gitignore                                    |   1 +
>   rhel/automake.mk                                   |   8 +-
>   rhel/kmod-openvswitch-rhel6.spec.in                | 120
> +++++++++++++++++++++
>   rhel/openvswitch-kmod-rhel6.spec.in                | 103 ------------------
>   rhel/openvswitch-kmod.files                        |   3 -
>   ...sr_share_openvswitch_scripts_ovs-kmod-manage.sh |  71 ++++++++++++
>   8 files changed, 203 insertions(+), 118 deletions(-)
>   create mode 100644 rhel/kmod-openvswitch-rhel6.spec.in
>   delete mode 100644 rhel/openvswitch-kmod-rhel6.spec.in
>   delete mode 100644 rhel/openvswitch-kmod.files
>   create mode 100644 rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh
>
> diff --git a/Documentation/intro/install/rhel.rst
> b/Documentation/intro/install/rhel.rst
> index f8b2606..6f062e8 100644
> --- a/Documentation/intro/install/rhel.rst
> +++ b/Documentation/intro/install/rhel.rst
> @@ -197,17 +197,16 @@ the unit tests, run::
>   Kernel Module
>   ~~~~~~~~~~~~~
>
> -On RHEL 6, to build the Open vSwitch kernel module, copy
> -rhel/openvswitch-kmod.files into the RPM sources directory and run::
> +On RHEL 6, to build the Open vSwitch kernel module run::
>
> -    $ rpmbuild -bb rhel/openvswitch-kmod-rhel6.spec
> +    $ rpmbuild -bb rhel/kmod-openvswitch-rhel6.spec
>
>   You might have to specify a kernel version and/or variants, e.g.:
>
>       $ rpmbuild -bb \
>           -D "kversion 2.6.32-131.6.1.el6.x86_64" \
>           -D "kflavors default debug kdump" \
> -        rhel/openvswitch-kmod-rhel6.spec
> +        rhel/kmod-openvswitch-rhel6.spec
>
>   This produces an "kmod-openvswitch" RPM for each kernel variant, in this
>   example: "kmod-openvswitch", "kmod-openvswitch-debug", and
> diff --git a/poc/playbook-centos-builder.yml b/poc/playbook-centos-builder.
> yml
> index 71f1040..e902db7 100644
> --- a/poc/playbook-centos-builder.yml
> +++ b/poc/playbook-centos-builder.yml
> @@ -41,13 +41,13 @@
>           chdir: /git/ovs/rhel
>       with_items:
>         - openvswitch.spec
> -      - openvswitch-kmod-rhel6.spec
> +      - kmod-openvswitch-rhel6.spec
>
>     - name: Install build dependencies specified from spec files
>       shell: echo "y" | yum-builddep /tmp/{{item}}
>       with_items:
>         - openvswitch.spec
> -      - openvswitch-kmod-rhel6.spec
> +      - kmod-openvswitch-rhel6.spec
>
>     - name: Create rpm dev tree
>       command: rpmdev-setuptree
> @@ -81,7 +81,7 @@
>         line: "Release: {{ ansible_local.builder.release }}"
>       with_items:
>         - openvswitch.spec
> -      - openvswitch-kmod-rhel6.spec
> +      - kmod-openvswitch-rhel6.spec
>
>     - name: Build Open vSwitch user space rpms
>       command: rpmbuild -bb --without check rhel/openvswitch.spec
> @@ -89,7 +89,7 @@
>           chdir: "{{SOURCE}}/openvswitch-{{version.stdout}}"
>
>     - name: Build Open vSwitch kmod rpms (only for currently loaded kernel)
> -    command: rpmbuild -bb  --without check rhel/openvswitch-kmod-rhel6.spec
> +    command: rpmbuild -bb  --without check rhel/kmod-openvswitch-rhel6.spec
>       args:
>           chdir: "{{SOURCE}}/openvswitch-{{version.stdout}}"
>
> diff --git a/rhel/.gitignore b/rhel/.gitignore
> index e584a1e..9b0ce1d 100644
> --- a/rhel/.gitignore
> +++ b/rhel/.gitignore
> @@ -1,6 +1,7 @@
>   openvswitch-dkms.spec
>   openvswitch-kmod-rhel5.spec
>   openvswitch-kmod-rhel6.spec
> +kmod-openvswitch-rhel6.spec
>   openvswitch-kmod-fedora.spec
>   openvswitch.spec
>   openvswitch-fedora.spec
> diff --git a/rhel/automake.mk b/rhel/automake.mk
> index 137ff4a..7b6c78f 100644
> --- a/rhel/automake.mk
> +++ b/rhel/automake.mk
> @@ -15,9 +15,8 @@ EXTRA_DIST += \
>    rhel/etc_sysconfig_network-scripts_ifup-ovs \
>    rhel/openvswitch-dkms.spec \
>    rhel/openvswitch-dkms.spec.in \
> - rhel/openvswitch-kmod-rhel6.spec \
> - rhel/openvswitch-kmod-rhel6.spec.in \
> - rhel/openvswitch-kmod.files \
> + rhel/kmod-openvswitch-rhel6.spec \
> + rhel/kmod-openvswitch-rhel6.spec.in \
>    rhel/openvswitch-kmod-fedora.spec \
>    rhel/openvswitch-kmod-fedora.spec.in \
>    rhel/openvswitch.spec \
> @@ -27,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 \
> @@ -48,7 +48,7 @@ update_rhel_spec = \
>   $(srcdir)/rhel/openvswitch-dkms.spec: rhel/openvswitch-dkms.spec.in
> $(top_builddir)/config.status
>    $(update_rhel_spec)
>
> -$(srcdir)/rhel/openvswitch-kmod-rhel6.spec: rhel/openvswitch-kmod-rhel6.
> spec.in $(top_builddir)/config.status
> +$(srcdir)/rhel/kmod-openvswitch-rhel6.spec: rhel/kmod-openvswitch-rhel6.
> spec.in $(top_builddir)/config.status
>    $(update_rhel_spec)
>
>   $(srcdir)/rhel/openvswitch-kmod-fedora.spec: rhel/openvswitch-kmod-fedora.
> spec.in $(top_builddir)/config.status
> diff --git a/rhel/kmod-openvswitch-rhel6.spec.in b/rhel/
> kmod-openvswitch-rhel6.spec.in
> new file mode 100644
> index 0000000..b0e50a4
> --- /dev/null
> +++ b/rhel/kmod-openvswitch-rhel6.spec.in
> @@ -0,0 +1,120 @@
> +# Spec file for Open vSwitch kernel modules on Red Hat Enterprise
> +# Linux 6.
> +
> +# Copyright (C) 2011, 2012, 2018 Nicira, Inc.
> +#
> +# Copying and distribution of this file, with or without modification,
> +# are permitted in any medium without royalty provided the copyright
> +# notice and this notice are preserved.  This file is offered as-is,
> +# without warranty of any kind.
> +
> +%define oname openvswitch
> +
> +Name:           kmod-%{oname}
> +Version:        @VERSION@
> +Release:        1%{?dist}
> +Summary:        Open vSwitch kernel module
> +
> +Group:          System/Kernel
> +License:        GPLv2
> +URL:            http://openvswitch.org/
> +Source0:        %{oname}-%{version}.tar.gz
> +Source1:        %{oname}-kmod.files
> +BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}
> -%{release}-XXXXXX)
> +
> +# Without this we get an empty openvswitch-debuginfo package (whose name
> +# conflicts with the openvswitch-debuginfo package for OVS userspace).
> +%undefine _enable_debug_packages
> +
> +%define kernel_source_extended() /usr/src/kernels/%{2}$([ %{1} = default ]
> || echo ".%{1}")
> +
> +# By default, build against the latest installed kernel
> +%{!?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 'kflavors default debug kdump' to build packages for
> +# specified kernel variants.
> +%{!?kflavors:%global kflavors default}
> +
> +%description
> +Open vSwitch Linux kernel module.
> +
> +%prep
> +
> +%setup -n %{oname}-%{version}
> +
> +%build
> +
> +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 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 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
> +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/%{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/openvswitch-kmod-rhel6.spec.in b/rhel/
> openvswitch-kmod-rhel6.spec.in
> deleted file mode 100644
> index daa3dad..0000000
> --- a/rhel/openvswitch-kmod-rhel6.spec.in
> +++ /dev/null
> @@ -1,103 +0,0 @@
> -# Spec file for Open vSwitch kernel modules on Red Hat Enterprise
> -# Linux 6.
> -
> -# Copyright (C) 2011, 2012 Nicira, Inc.
> -#
> -# Copying and distribution of this file, with or without modification,
> -# are permitted in any medium without royalty provided the copyright
> -# notice and this notice are preserved.  This file is offered as-is,
> -# without warranty of any kind.
> -
> -%define oname openvswitch
> -
> -Name:           %{oname}-kmod
> -Version:        @VERSION@
> -Release:        1%{?dist}
> -Summary:        Open vSwitch kernel module
> -
> -Group:          System/Kernel
> -License:        GPLv2
> -URL:            http://openvswitch.org/
> -Source0:        %{oname}-%{version}.tar.gz
> -Source1:        %{oname}-kmod.files
> -BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}
> -%{release}-XXXXXX)
> -BuildRequires:  %kernel_module_package_buildreqs
> -
> -# Without this we get an empty openvswitch-debuginfo package (whose name
> -# conflicts with the openvswitch-debuginfo package for OVS userspace).
> -%undefine _enable_debug_packages
> -
> -# Use -D 'kversion 2.6.32-131.6.1.el6.x86_64' to build package
> -# for specified kernel version.
> -%{?kversion:%define kernel_version %kversion}
> -
> -# Use -D 'kflavors default debug kdump' to build packages for
> -# specified kernel variants.
> -%{!?kflavors:%define kflavors default}
> -
> -%kernel_module_package -n %{oname} -f %{SOURCE1} %kflavors
> -
> -%description
> -Open vSwitch Linux kernel module.
> -
> -%prep
> -
> -%setup -n %{oname}-%{version}
> -
> -%build
> -for flavor in %flavors_to_build; do
> -        mkdir _$flavor
> -        (cd _$flavor && ../configure --with-linux="%{kernel_source
> $flavor}")
> -        %{__make} -C _$flavor/datapath/linux %{?_smp_mflags}
> -done
> -
> -%install
> -export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
> -export INSTALL_MOD_DIR=extra/%{oname}
> -for flavor in %flavors_to_build ; do
> -         make -C %{kernel_source $flavor} modules_install \
> -                 M="`pwd`"/_$flavor/datapath/linux
> -
> -         # Cleanup unnecessary kernel-generated module dependency files.
> -         find $INSTALL_MOD_PATH/lib/modules -iname 'modules.*' -exec rm {}
> \;
> -done
> -install -d %{buildroot}%{_sysconfdir}/depmod.d/
> -for module in %{buildroot}/lib/modules/%{kernel_version}/$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
> -done
> -install -m 644 %{oname}.conf %{buildroot}%{_sysconfdir}/depmod.d/
> -
> -%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
> -    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
> -    fi
> -fi
> -
> -%files
> -%defattr(644,root,root)
> -/etc/depmod.d/%{oname}.conf
> -
> -%clean
> -rm -rf $RPM_BUILD_ROOT
> diff --git a/rhel/openvswitch-kmod.files b/rhel/openvswitch-kmod.files
> deleted file mode 100644
> index 357c2e8..0000000
> --- a/rhel/openvswitch-kmod.files
> +++ /dev/null
> @@ -1,3 +0,0 @@
> -%defattr(644,root,root,755)
> -/lib/modules/%2-%1
> -/etc/depmod.d/openvswitch.conf
> 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 0000000..e89ad86
> --- /dev/null
> +++ b/rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh
> @@ -0,0 +1,71 @@
> +#!/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.
> +
> +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
0-day Robot July 10, 2018, 11:25 p.m. UTC | #2
Bleep bloop.  Greetings Martin Xu, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


git-am:
fatal: corrupt patch at line 127
Repository lacks necessary blobs to fall back on 3-way merge.
Cannot fall back to three-way merge.
Patch failed at 0001 rhel: support kmod-openvswitch build against multiple kernels, rhel6
The copy of the patch that failed is found in:
   /var/lib/jenkins/jobs/upstream_build_from_pw/workspace/.git/rebase-apply/patch
When you have resolved this problem, run "git am --resolved".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".


Please check this out.  If you feel there has been an error, please email aconole@bytheb.org

Thanks,
0-day Robot
Martin Xu July 11, 2018, 7:43 p.m. UTC | #3
Adding Ben.

On Tue, Jul 10, 2018 at 3:54 PM Gregory Rose <gvrose8192@gmail.com> wrote:

> On 7/10/2018 3:42 PM, 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.
> >
> > Previouly the kernel_module_package macro is used to generate spec file
> > template to build kmod-openvswitch RPM. This macro is now removed.
> > Everything is built in the main package. To maintain consistent naming,
> > the rhel6 kmod spec file is renamed to kmod-openvswitch-rhel6.spec to
> > match the built package name kmod-openvswitch.
> >
> > This patch also removes the openvswitch-kmod package.
>
> Oops, no signed off by line.
>
> I'm adding Aaron and Flavio so the Red Hat guys can give it a look. You
> can wait for their review
> comments and then spin up a Rev 2 with the fixed signed off by line.
>
> Thanks for the patch!
>
> - Greg
>
>
>
> > ---
> >   Documentation/intro/install/rhel.rst               |   7 +-
> >   poc/playbook-centos-builder.yml                    |   8 +-
> >   rhel/.gitignore                                    |   1 +
> >   rhel/automake.mk                                   |   8 +-
> >   rhel/kmod-openvswitch-rhel6.spec.in                | 120
> > +++++++++++++++++++++
> >   rhel/openvswitch-kmod-rhel6.spec.in                | 103
> ------------------
> >   rhel/openvswitch-kmod.files                        |   3 -
> >   ...sr_share_openvswitch_scripts_ovs-kmod-manage.sh |  71 ++++++++++++
> >   8 files changed, 203 insertions(+), 118 deletions(-)
> >   create mode 100644 rhel/kmod-openvswitch-rhel6.spec.in
> >   delete mode 100644 rhel/openvswitch-kmod-rhel6.spec.in
> >   delete mode 100644 rhel/openvswitch-kmod.files
> >   create mode 100644
> rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh
> >
> > diff --git a/Documentation/intro/install/rhel.rst
> > b/Documentation/intro/install/rhel.rst
> > index f8b2606..6f062e8 100644
> > --- a/Documentation/intro/install/rhel.rst
> > +++ b/Documentation/intro/install/rhel.rst
> > @@ -197,17 +197,16 @@ the unit tests, run::
> >   Kernel Module
> >   ~~~~~~~~~~~~~
> >
> > -On RHEL 6, to build the Open vSwitch kernel module, copy
> > -rhel/openvswitch-kmod.files into the RPM sources directory and run::
> > +On RHEL 6, to build the Open vSwitch kernel module run::
> >
> > -    $ rpmbuild -bb rhel/openvswitch-kmod-rhel6.spec
> > +    $ rpmbuild -bb rhel/kmod-openvswitch-rhel6.spec
> >
> >   You might have to specify a kernel version and/or variants, e.g.:
> >
> >       $ rpmbuild -bb \
> >           -D "kversion 2.6.32-131.6.1.el6.x86_64" \
> >           -D "kflavors default debug kdump" \
> > -        rhel/openvswitch-kmod-rhel6.spec
> > +        rhel/kmod-openvswitch-rhel6.spec
> >
> >   This produces an "kmod-openvswitch" RPM for each kernel variant, in
> this
> >   example: "kmod-openvswitch", "kmod-openvswitch-debug", and
> > diff --git a/poc/playbook-centos-builder.yml
> b/poc/playbook-centos-builder.
> > yml
> > index 71f1040..e902db7 100644
> > --- a/poc/playbook-centos-builder.yml
> > +++ b/poc/playbook-centos-builder.yml
> > @@ -41,13 +41,13 @@
> >           chdir: /git/ovs/rhel
> >       with_items:
> >         - openvswitch.spec
> > -      - openvswitch-kmod-rhel6.spec
> > +      - kmod-openvswitch-rhel6.spec
> >
> >     - name: Install build dependencies specified from spec files
> >       shell: echo "y" | yum-builddep /tmp/{{item}}
> >       with_items:
> >         - openvswitch.spec
> > -      - openvswitch-kmod-rhel6.spec
> > +      - kmod-openvswitch-rhel6.spec
> >
> >     - name: Create rpm dev tree
> >       command: rpmdev-setuptree
> > @@ -81,7 +81,7 @@
> >         line: "Release: {{ ansible_local.builder.release }}"
> >       with_items:
> >         - openvswitch.spec
> > -      - openvswitch-kmod-rhel6.spec
> > +      - kmod-openvswitch-rhel6.spec
> >
> >     - name: Build Open vSwitch user space rpms
> >       command: rpmbuild -bb --without check rhel/openvswitch.spec
> > @@ -89,7 +89,7 @@
> >           chdir: "{{SOURCE}}/openvswitch-{{version.stdout}}"
> >
> >     - name: Build Open vSwitch kmod rpms (only for currently loaded
> kernel)
> > -    command: rpmbuild -bb  --without check
> rhel/openvswitch-kmod-rhel6.spec
> > +    command: rpmbuild -bb  --without check
> rhel/kmod-openvswitch-rhel6.spec
> >       args:
> >           chdir: "{{SOURCE}}/openvswitch-{{version.stdout}}"
> >
> > diff --git a/rhel/.gitignore b/rhel/.gitignore
> > index e584a1e..9b0ce1d 100644
> > --- a/rhel/.gitignore
> > +++ b/rhel/.gitignore
> > @@ -1,6 +1,7 @@
> >   openvswitch-dkms.spec
> >   openvswitch-kmod-rhel5.spec
> >   openvswitch-kmod-rhel6.spec
> > +kmod-openvswitch-rhel6.spec
> >   openvswitch-kmod-fedora.spec
> >   openvswitch.spec
> >   openvswitch-fedora.spec
> > diff --git a/rhel/automake.mk b/rhel/automake.mk
> > index 137ff4a..7b6c78f 100644
> > --- a/rhel/automake.mk
> > +++ b/rhel/automake.mk
> > @@ -15,9 +15,8 @@ EXTRA_DIST += \
> >    rhel/etc_sysconfig_network-scripts_ifup-ovs \
> >    rhel/openvswitch-dkms.spec \
> >    rhel/openvswitch-dkms.spec.in \
> > - rhel/openvswitch-kmod-rhel6.spec \
> > - rhel/openvswitch-kmod-rhel6.spec.in \
> > - rhel/openvswitch-kmod.files \
> > + rhel/kmod-openvswitch-rhel6.spec \
> > + rhel/kmod-openvswitch-rhel6.spec.in \
> >    rhel/openvswitch-kmod-fedora.spec \
> >    rhel/openvswitch-kmod-fedora.spec.in \
> >    rhel/openvswitch.spec \
> > @@ -27,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 \
> > @@ -48,7 +48,7 @@ update_rhel_spec = \
> >   $(srcdir)/rhel/openvswitch-dkms.spec: rhel/openvswitch-dkms.spec.in
> > $(top_builddir)/config.status
> >    $(update_rhel_spec)
> >
> > -$(srcdir)/rhel/openvswitch-kmod-rhel6.spec: rhel/openvswitch-kmod-rhel6.
> > spec.in $(top_builddir)/config.status
> > +$(srcdir)/rhel/kmod-openvswitch-rhel6.spec: rhel/kmod-openvswitch-rhel6.
> > spec.in $(top_builddir)/config.status
> >    $(update_rhel_spec)
> >
> >   $(srcdir)/rhel/openvswitch-kmod-fedora.spec:
> rhel/openvswitch-kmod-fedora.
> > spec.in $(top_builddir)/config.status
> > diff --git a/rhel/kmod-openvswitch-rhel6.spec.in b/rhel/
> > kmod-openvswitch-rhel6.spec.in
> > new file mode 100644
> > index 0000000..b0e50a4
> > --- /dev/null
> > +++ b/rhel/kmod-openvswitch-rhel6.spec.in
> > @@ -0,0 +1,120 @@
> > +# Spec file for Open vSwitch kernel modules on Red Hat Enterprise
> > +# Linux 6.
> > +
> > +# Copyright (C) 2011, 2012, 2018 Nicira, Inc.
> > +#
> > +# Copying and distribution of this file, with or without modification,
> > +# are permitted in any medium without royalty provided the copyright
> > +# notice and this notice are preserved.  This file is offered as-is,
> > +# without warranty of any kind.
> > +
> > +%define oname openvswitch
> > +
> > +Name:           kmod-%{oname}
> > +Version:        @VERSION@
> > +Release:        1%{?dist}
> > +Summary:        Open vSwitch kernel module
> > +
> > +Group:          System/Kernel
> > +License:        GPLv2
> > +URL:            http://openvswitch.org/
> > +Source0:        %{oname}-%{version}.tar.gz
> > +Source1:        %{oname}-kmod.files
> > +BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}
> > -%{release}-XXXXXX)
> > +
> > +# Without this we get an empty openvswitch-debuginfo package (whose name
> > +# conflicts with the openvswitch-debuginfo package for OVS userspace).
> > +%undefine _enable_debug_packages
> > +
> > +%define kernel_source_extended() /usr/src/kernels/%{2}$([ %{1} =
> default ]
> > || echo ".%{1}")
> > +
> > +# By default, build against the latest installed kernel
> > +%{!?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 'kflavors default debug kdump' to build packages for
> > +# specified kernel variants.
> > +%{!?kflavors:%global kflavors default}
> > +
> > +%description
> > +Open vSwitch Linux kernel module.
> > +
> > +%prep
> > +
> > +%setup -n %{oname}-%{version}
> > +
> > +%build
> > +
> > +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 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 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
> > +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/%{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/openvswitch-kmod-rhel6.spec.in b/rhel/
> > openvswitch-kmod-rhel6.spec.in
> > deleted file mode 100644
> > index daa3dad..0000000
> > --- a/rhel/openvswitch-kmod-rhel6.spec.in
> > +++ /dev/null
> > @@ -1,103 +0,0 @@
> > -# Spec file for Open vSwitch kernel modules on Red Hat Enterprise
> > -# Linux 6.
> > -
> > -# Copyright (C) 2011, 2012 Nicira, Inc.
> > -#
> > -# Copying and distribution of this file, with or without modification,
> > -# are permitted in any medium without royalty provided the copyright
> > -# notice and this notice are preserved.  This file is offered as-is,
> > -# without warranty of any kind.
> > -
> > -%define oname openvswitch
> > -
> > -Name:           %{oname}-kmod
> > -Version:        @VERSION@
> > -Release:        1%{?dist}
> > -Summary:        Open vSwitch kernel module
> > -
> > -Group:          System/Kernel
> > -License:        GPLv2
> > -URL:            http://openvswitch.org/
> > -Source0:        %{oname}-%{version}.tar.gz
> > -Source1:        %{oname}-kmod.files
> > -BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}
> > -%{release}-XXXXXX)
> > -BuildRequires:  %kernel_module_package_buildreqs
> > -
> > -# Without this we get an empty openvswitch-debuginfo package (whose name
> > -# conflicts with the openvswitch-debuginfo package for OVS userspace).
> > -%undefine _enable_debug_packages
> > -
> > -# Use -D 'kversion 2.6.32-131.6.1.el6.x86_64' to build package
> > -# for specified kernel version.
> > -%{?kversion:%define kernel_version %kversion}
> > -
> > -# Use -D 'kflavors default debug kdump' to build packages for
> > -# specified kernel variants.
> > -%{!?kflavors:%define kflavors default}
> > -
> > -%kernel_module_package -n %{oname} -f %{SOURCE1} %kflavors
> > -
> > -%description
> > -Open vSwitch Linux kernel module.
> > -
> > -%prep
> > -
> > -%setup -n %{oname}-%{version}
> > -
> > -%build
> > -for flavor in %flavors_to_build; do
> > -        mkdir _$flavor
> > -        (cd _$flavor && ../configure --with-linux="%{kernel_source
> > $flavor}")
> > -        %{__make} -C _$flavor/datapath/linux %{?_smp_mflags}
> > -done
> > -
> > -%install
> > -export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
> > -export INSTALL_MOD_DIR=extra/%{oname}
> > -for flavor in %flavors_to_build ; do
> > -         make -C %{kernel_source $flavor} modules_install \
> > -                 M="`pwd`"/_$flavor/datapath/linux
> > -
> > -         # Cleanup unnecessary kernel-generated module dependency files.
> > -         find $INSTALL_MOD_PATH/lib/modules -iname 'modules.*' -exec rm
> {}
> > \;
> > -done
> > -install -d %{buildroot}%{_sysconfdir}/depmod.d/
> > -for module in %{buildroot}/lib/modules/%{kernel_version}/$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
> > -done
> > -install -m 644 %{oname}.conf %{buildroot}%{_sysconfdir}/depmod.d/
> > -
> > -%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
> > -    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
> > -    fi
> > -fi
> > -
> > -%files
> > -%defattr(644,root,root)
> > -/etc/depmod.d/%{oname}.conf
> > -
> > -%clean
> > -rm -rf $RPM_BUILD_ROOT
> > diff --git a/rhel/openvswitch-kmod.files b/rhel/openvswitch-kmod.files
> > deleted file mode 100644
> > index 357c2e8..0000000
> > --- a/rhel/openvswitch-kmod.files
> > +++ /dev/null
> > @@ -1,3 +0,0 @@
> > -%defattr(644,root,root,755)
> > -/lib/modules/%2-%1
> > -/etc/depmod.d/openvswitch.conf
> > 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 0000000..e89ad86
> > --- /dev/null
> > +++ b/rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh
> > @@ -0,0 +1,71 @@
> > +#!/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.
> > +
> > +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
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
diff mbox series

Patch

diff --git a/Documentation/intro/install/rhel.rst
b/Documentation/intro/install/rhel.rst
index f8b2606..6f062e8 100644
--- a/Documentation/intro/install/rhel.rst
+++ b/Documentation/intro/install/rhel.rst
@@ -197,17 +197,16 @@  the unit tests, run::
 Kernel Module
 ~~~~~~~~~~~~~

-On RHEL 6, to build the Open vSwitch kernel module, copy
-rhel/openvswitch-kmod.files into the RPM sources directory and run::
+On RHEL 6, to build the Open vSwitch kernel module run::

-    $ rpmbuild -bb rhel/openvswitch-kmod-rhel6.spec
+    $ rpmbuild -bb rhel/kmod-openvswitch-rhel6.spec

 You might have to specify a kernel version and/or variants, e.g.:

     $ rpmbuild -bb \
         -D "kversion 2.6.32-131.6.1.el6.x86_64" \
         -D "kflavors default debug kdump" \
-        rhel/openvswitch-kmod-rhel6.spec
+        rhel/kmod-openvswitch-rhel6.spec

 This produces an "kmod-openvswitch" RPM for each kernel variant, in this
 example: "kmod-openvswitch", "kmod-openvswitch-debug", and
diff --git a/poc/playbook-centos-builder.yml b/poc/playbook-centos-builder.
yml
index 71f1040..e902db7 100644
--- a/poc/playbook-centos-builder.yml
+++ b/poc/playbook-centos-builder.yml
@@ -41,13 +41,13 @@ 
         chdir: /git/ovs/rhel
     with_items:
       - openvswitch.spec
-      - openvswitch-kmod-rhel6.spec
+      - kmod-openvswitch-rhel6.spec

   - name: Install build dependencies specified from spec files
     shell: echo "y" | yum-builddep /tmp/{{item}}
     with_items:
       - openvswitch.spec
-      - openvswitch-kmod-rhel6.spec
+      - kmod-openvswitch-rhel6.spec

   - name: Create rpm dev tree
     command: rpmdev-setuptree
@@ -81,7 +81,7 @@ 
       line: "Release: {{ ansible_local.builder.release }}"
     with_items:
       - openvswitch.spec
-      - openvswitch-kmod-rhel6.spec
+      - kmod-openvswitch-rhel6.spec

   - name: Build Open vSwitch user space rpms
     command: rpmbuild -bb --without check rhel/openvswitch.spec
@@ -89,7 +89,7 @@ 
         chdir: "{{SOURCE}}/openvswitch-{{version.stdout}}"

   - name: Build Open vSwitch kmod rpms (only for currently loaded kernel)
-    command: rpmbuild -bb  --without check rhel/openvswitch-kmod-rhel6.spec
+    command: rpmbuild -bb  --without check rhel/kmod-openvswitch-rhel6.spec
     args:
         chdir: "{{SOURCE}}/openvswitch-{{version.stdout}}"

diff --git a/rhel/.gitignore b/rhel/.gitignore
index e584a1e..9b0ce1d 100644
--- a/rhel/.gitignore
+++ b/rhel/.gitignore
@@ -1,6 +1,7 @@ 
 openvswitch-dkms.spec
 openvswitch-kmod-rhel5.spec
 openvswitch-kmod-rhel6.spec
+kmod-openvswitch-rhel6.spec
 openvswitch-kmod-fedora.spec
 openvswitch.spec
 openvswitch-fedora.spec
diff --git a/rhel/automake.mk b/rhel/automake.mk
index 137ff4a..7b6c78f 100644
--- a/rhel/automake.mk
+++ b/rhel/automake.mk
@@ -15,9 +15,8 @@  EXTRA_DIST += \
  rhel/etc_sysconfig_network-scripts_ifup-ovs \
  rhel/openvswitch-dkms.spec \
  rhel/openvswitch-dkms.spec.in \
- rhel/openvswitch-kmod-rhel6.spec \
- rhel/openvswitch-kmod-rhel6.spec.in \
- rhel/openvswitch-kmod.files \
+ rhel/kmod-openvswitch-rhel6.spec \
+ rhel/kmod-openvswitch-rhel6.spec.in \
  rhel/openvswitch-kmod-fedora.spec \
  rhel/openvswitch-kmod-fedora.spec.in \
  rhel/openvswitch.spec \
@@ -27,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 \
@@ -48,7 +48,7 @@  update_rhel_spec = \
 $(srcdir)/rhel/openvswitch-dkms.spec: rhel/openvswitch-dkms.spec.in
$(top_builddir)/config.status
  $(update_rhel_spec)

-$(srcdir)/rhel/openvswitch-kmod-rhel6.spec: rhel/openvswitch-kmod-rhel6.
spec.in $(top_builddir)/config.status
+$(srcdir)/rhel/kmod-openvswitch-rhel6.spec: rhel/kmod-openvswitch-rhel6.
spec.in $(top_builddir)/config.status
  $(update_rhel_spec)

 $(srcdir)/rhel/openvswitch-kmod-fedora.spec: rhel/openvswitch-kmod-fedora.
spec.in $(top_builddir)/config.status
diff --git a/rhel/kmod-openvswitch-rhel6.spec.in b/rhel/
kmod-openvswitch-rhel6.spec.in
new file mode 100644
index 0000000..b0e50a4
--- /dev/null
+++ b/rhel/kmod-openvswitch-rhel6.spec.in
@@ -0,0 +1,120 @@ 
+# Spec file for Open vSwitch kernel modules on Red Hat Enterprise
+# Linux 6.
+
+# Copyright (C) 2011, 2012, 2018 Nicira, Inc.
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without warranty of any kind.
+
+%define oname openvswitch
+
+Name:           kmod-%{oname}
+Version:        @VERSION@
+Release:        1%{?dist}
+Summary:        Open vSwitch kernel module
+
+Group:          System/Kernel
+License:        GPLv2
+URL:            http://openvswitch.org/
+Source0:        %{oname}-%{version}.tar.gz
+Source1:        %{oname}-kmod.files
+BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}
-%{release}-XXXXXX)
+
+# Without this we get an empty openvswitch-debuginfo package (whose name
+# conflicts with the openvswitch-debuginfo package for OVS userspace).
+%undefine _enable_debug_packages
+
+%define kernel_source_extended() /usr/src/kernels/%{2}$([ %{1} = default ]
|| echo ".%{1}")
+
+# By default, build against the latest installed kernel
+%{!?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 'kflavors default debug kdump' to build packages for
+# specified kernel variants.
+%{!?kflavors:%global kflavors default}
+
+%description
+Open vSwitch Linux kernel module.
+
+%prep
+
+%setup -n %{oname}-%{version}
+
+%build
+
+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 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 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
+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/%{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/openvswitch-kmod-rhel6.spec.in b/rhel/
openvswitch-kmod-rhel6.spec.in
deleted file mode 100644
index daa3dad..0000000
--- a/rhel/openvswitch-kmod-rhel6.spec.in
+++ /dev/null
@@ -1,103 +0,0 @@ 
-# Spec file for Open vSwitch kernel modules on Red Hat Enterprise
-# Linux 6.
-
-# Copyright (C) 2011, 2012 Nicira, Inc.
-#
-# Copying and distribution of this file, with or without modification,
-# are permitted in any medium without royalty provided the copyright
-# notice and this notice are preserved.  This file is offered as-is,
-# without warranty of any kind.
-
-%define oname openvswitch
-
-Name:           %{oname}-kmod
-Version:        @VERSION@
-Release:        1%{?dist}
-Summary:        Open vSwitch kernel module
-
-Group:          System/Kernel
-License:        GPLv2
-URL:            http://openvswitch.org/
-Source0:        %{oname}-%{version}.tar.gz
-Source1:        %{oname}-kmod.files
-BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}
-%{release}-XXXXXX)
-BuildRequires:  %kernel_module_package_buildreqs
-
-# Without this we get an empty openvswitch-debuginfo package (whose name
-# conflicts with the openvswitch-debuginfo package for OVS userspace).
-%undefine _enable_debug_packages
-
-# Use -D 'kversion 2.6.32-131.6.1.el6.x86_64' to build package
-# for specified kernel version.
-%{?kversion:%define kernel_version %kversion}
-
-# Use -D 'kflavors default debug kdump' to build packages for
-# specified kernel variants.
-%{!?kflavors:%define kflavors default}
-
-%kernel_module_package -n %{oname} -f %{SOURCE1} %kflavors
-
-%description
-Open vSwitch Linux kernel module.
-
-%prep
-
-%setup -n %{oname}-%{version}
-
-%build
-for flavor in %flavors_to_build; do
-        mkdir _$flavor
-        (cd _$flavor && ../configure --with-linux="%{kernel_source
$flavor}")
-        %{__make} -C _$flavor/datapath/linux %{?_smp_mflags}
-done
-
-%install
-export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
-export INSTALL_MOD_DIR=extra/%{oname}
-for flavor in %flavors_to_build ; do
-         make -C %{kernel_source $flavor} modules_install \
-                 M="`pwd`"/_$flavor/datapath/linux
-
-         # Cleanup unnecessary kernel-generated module dependency files.
-         find $INSTALL_MOD_PATH/lib/modules -iname 'modules.*' -exec rm {}
\;
-done
-install -d %{buildroot}%{_sysconfdir}/depmod.d/
-for module in %{buildroot}/lib/modules/%{kernel_version}/$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
-done
-install -m 644 %{oname}.conf %{buildroot}%{_sysconfdir}/depmod.d/
-
-%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
-    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
-    fi
-fi
-
-%files
-%defattr(644,root,root)
-/etc/depmod.d/%{oname}.conf
-
-%clean
-rm -rf $RPM_BUILD_ROOT
diff --git a/rhel/openvswitch-kmod.files b/rhel/openvswitch-kmod.files
deleted file mode 100644
index 357c2e8..0000000
--- a/rhel/openvswitch-kmod.files
+++ /dev/null
@@ -1,3 +0,0 @@ 
-%defattr(644,root,root,755)
-/lib/modules/%2-%1
-/etc/depmod.d/openvswitch.conf
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 0000000..e89ad86
--- /dev/null
+++ b/rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh
@@ -0,0 +1,71 @@ 
+#!/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.
+
+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