]> git.proxmox.com Git - mirror_ovs.git/blame - rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh
rhel: Revert RHEL 7.4 comp_ver change
[mirror_ovs.git] / rhel / usr_share_openvswitch_scripts_ovs-kmod-manage.sh
CommitLineData
89dd5819
MX
1#!/bin/sh
2
3# Copyright (c) 2018 Nicira/VMware, Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at:
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
402efbe4
YHW
17# This script is intended to be used on the following kernels.
18# - 3.10.0 major revision 327 (RHEL 7.2)
19# - 3.10.0 major revision 693 (RHEL 7.4)
52d12cc4 20# - 3.10.0 major revision 957 (RHEL 7.6)
402efbe4
YHW
21# - 4.4.x, x >= 73 (SLES 12 SP3)
22# - 4.12.x, x >= 14 (SLES 12 SP4).
23# It is packaged in the openvswitch kmod RPM and run in the post-install
24# scripts.
89dd5819 25#
52d12cc4
YS
26# For kernel 3.10.0-957,
27# due to some backward incompatible changes introduced in minor revision 12.1,
28# kernel modules built against kernels newer than 12.1 cannot be loaded on
29# system running kernels older than 12.1, vice versa.
30#
c8cd1307
MX
31# For kernel 3.10.0-693,
32# due to some backward incompatible changes introduced in minor revision 17.1,
89dd5819
MX
33# kernel modules built against kernels newer than 17.1 cannot be loaded on
34# system running kernels older than 17.1, vice versa.
35#
c8cd1307
MX
36# For kernel 3.10.0-327,
37# due to some backward incompatible changes introduced in minor revision 41.3,
38# kernel modules built against kernels newer than 41.3 cannot be loaded on
39# system running kernels older than 41.3, vice versa.
40#
c3570519
MX
41# For kernel >= 4.4.73,
42# kernel modules built with 4.4.73 can run on systems with kernel versions from
43# 4.4.73 to 4.4.114; modules built against 4.4.120 can run on systems from
44# 4.4.120 onwards.
45#
402efbe4
YHW
46# For kernel 4.12.x, x>=14,
47# kernel modules built with the oldest compatible kernel 4.12.14-94.41.1 can
48# run on all versions onwards.
49#
89dd5819
MX
50# This script checks the current running kernel version, and update symlinks
51# for the openvswitch kernel modules in the appropriate kernel directory,
52# provided the kmod RPM has installed kernel modules files built from both
c8cd1307 53# minor revisions.
c3570519 54#
89dd5819
MX
55# In case of a kernel minor revision change after the openvswitch kmod package
56# is installed, this script shall be run manually after system reboots and
57# switches to a different kernel
c8cd1307
MX
58if [ -n "$(rpm -qa kmod-openvswitch)" ]; then
59 rpmname="kmod-openvswitch"
60elif [ -n "$(rpm -qa openvswitch-kmod)" ]; then
61 rpmname="openvswitch-kmod"
62else
63 echo "openvswitch kmod package not installed, existing"
64 exit 1
65fi
66#echo $rpmname
89dd5819
MX
67script_name=$(basename -- "$0")
68current_kernel=$(uname -r)
69echo current kernel is $current_kernel
70
c3570519
MX
71IFS='.\|-' read mainline_major mainline_minor mainline_patch major_rev \
72 minor_rev _extra <<<"${current_kernel}"
73# echo mainline_major=$mainline_major mainline_minor=$mainline_minor \
74# mainline_patch=$mainline_patch major_rev=$major_rev minor_rev=$minor_rev
89dd5819 75
c3570519
MX
76expected_rhel_base_minor="el7"
77if [ "$mainline_major" = "3" ] && [ "$mainline_minor" = "10" ]; then
78 if [ "$major_rev" = "327" ]; then
79# echo "rhel72"
80 comp_ver=36
81 ver_offset=4
82 installed_ver="$minor_rev"
e64c2c1e
GR
83 elif [ "$major_rev" = "514" ]; then
84# echo "rhel73"
85 comp_ver=26
86 ver_offset=4
87 installed_ver="$minor_rev"
c3570519
MX
88 elif [ "$major_rev" = "693" ]; then
89# echo "rhel74"
d0fa7d7f 90 comp_ver=11
c3570519
MX
91 ver_offset=4
92 installed_ver="$minor_rev"
22abff20
GR
93 elif [ "$major_rev" = "862" ]; then
94# echo "rhel75"
e64c2c1e 95 comp_ver=20
22abff20
GR
96 ver_offset=4
97 installed_ver="$minor_rev"
52d12cc4
YS
98 elif [ "$major_rev" = "957" ]; then
99# echo "rhel76"
100 comp_ver=10
101 ver_offset=4
102 installed_ver="$minor_rev"
c3570519
MX
103 fi
104elif [ "$mainline_major" = "4" ] && [ "$mainline_minor" = "4" ]; then
105 if [ "$mainline_patch" -ge "73" ]; then
106# echo "sles12sp3"
107 comp_ver=114
108 ver_offset=2
109 installed_ver="$mainline_patch"
110 fi
402efbe4
YHW
111elif [ "$mainline_major" = "4" ] && [ "$mainline_minor" = "12" ]; then
112 if [ "$mainline_patch" -ge "14" ]; then
113# echo "sles12sp4"
114 comp_ver=14
115 ver_offset=2
116 installed_ver="$mainline_patch"
117 fi
c3570519
MX
118fi
119
120if [ X"$ver_offset" = X ]; then
c8cd1307
MX
121 echo "This script is not intended to run on kernel $(uname -r)"
122 exit 1
123fi
124
c3570519
MX
125#IFS='.\|-' read -r -a version_nums <<<"${current_kernel}"
126#echo ver_offset=$ver_offset
127#echo installed_ver="$installed_ver"
128#echo installed_ver="${version_nums[$ver_offset]}"
129
130kmod_versions=()
c8cd1307
MX
131kversion=$(rpm -ql ${rpmname} | grep '\.ko$' | \
132 sed -n -e 's/^\/lib\/modules\/\(.*\)\/extra\/.*$/\1/p' | \
133 sort | uniq)
134for kv in $kversion; do
c3570519
MX
135 IFS='.\|-' read -r -a kv_nums <<<"${kv}"
136 kmod_versions+=(${kv_nums[$ver_offset]})
c8cd1307 137done
c3570519
MX
138sorted_kmod_vers=$(printf "%s\n" "${kmod_versions[@]}" | \
139 sort -n)
140#echo "$sorted_kmod_vers"
c8cd1307 141
c3570519 142if [ ! -n "$sorted_kmod_vers" ]; then
c8cd1307
MX
143 echo "No kernel modules found from package $rpmname, exiting"
144 exit 1
145else
c3570519
MX
146 # first line for kmod_low_ver, last for kmod_high_ver
147 kmod_low_ver=$(echo "$sorted_kmod_vers" | head -1)
148 kmod_high_ver=$(echo "$sorted_kmod_vers" | tail -1)
c8cd1307 149fi
c3570519
MX
150#echo "Installing KMOD with minor revisions $kmod_low_ver and \
151#$kmod_high_ver"
89dd5819
MX
152
153found_match=false
154for kname in `ls -d /lib/modules/*`
155do
c3570519
MX
156 IFS='.\|-' read -r -a pkg_ver_nums <<<"${kname}"
157 pkg_ver=${pkg_ver_nums[$ver_offset]}
158 if [ "$installed_ver" = "$expected_rhel_base_minor" ] ||
159 [ "$installed_ver" -le "$comp_ver" ]; then
160 if [ "$pkg_ver" = "$kmod_low_ver" ]; then
89dd5819
MX
161 requested_kernel=$kname
162 found_match="true"
163 echo "Installing Openvswitch KMOD from kernel $kname"
164 break
165 fi
166 else
c3570519 167 if [ "$pkg_ver" = "$kmod_high_ver" ]; then
89dd5819
MX
168 requested_kernel=$kname
169 found_match="true"
170 echo "Installing Openvswitch KMOD from kernel $kname"
171 break
172 fi
173 fi
174done
175
176if [ "$found_match" = "false" ]; then
177 echo $script_name: Failed
178 exit 1
179fi
180
181if [ "$requested_kernel" != "/lib/modules/$current_kernel" ]; then
c3570519
MX
182 if [ ! -d /lib/modules/$current_kernel/weak-updates/openvswitch ]; then
183 mkdir -p /lib/modules/$current_kernel/weak-updates
184 mkdir -p /lib/modules/$current_kernel/weak-updates/openvswitch
89dd5819 185 fi
c3570519
MX
186 for m in openvswitch vport-gre vport-stt vport-geneve \
187 vport-lisp vport-vxlan; do
188 ln -f -s $requested_kernel/extra/openvswitch/$m.ko \
189 /lib/modules/$current_kernel/weak-updates/openvswitch/$m.ko
190 done
89dd5819
MX
191else
192 echo Proper OVS kernel modules already configured
193fi
194# Always run depmod
195/sbin/depmod -a