]> git.proxmox.com Git - ovs.git/blob - rhel/usr_share_openvswitch_scripts_ovs-kmod-manage.sh
c70e135cd5ef8bcf6b9d297f95d644703ca7ec2f
[ovs.git] / rhel / usr_share_openvswitch_scripts_ovs-kmod-manage.sh
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
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)
20 # - 3.10.0 major revision 957 (RHEL 7.6)
21 # - 3.10.0 major revision 1062 (RHEL 7.7)
22 # - 3.10.0 major revision 1101 (RHEL 7.8 Beta)
23 # - 3.10.0 major revision 1127 (RHEL 7.8 GA)
24 # - 4.4.x, x >= 73 (SLES 12 SP3)
25 # - 4.12.x, x >= 14 (SLES 12 SP4).
26 # It is packaged in the openvswitch kmod RPM and run in the post-install
27 # scripts.
28 #
29 # For kernel 3.10.0-957,
30 # due to some backward incompatible changes introduced in minor revision 12.1,
31 # kernel modules built against kernels newer than 12.1 cannot be loaded on
32 # system running kernels older than 12.1, vice versa.
33 #
34 # For kernel 3.10.0-693,
35 # due to some backward incompatible changes introduced in minor revision 17.1,
36 # kernel modules built against kernels newer than 17.1 cannot be loaded on
37 # system running kernels older than 17.1, vice versa.
38 #
39 # For kernel 3.10.0-327,
40 # due to some backward incompatible changes introduced in minor revision 41.3,
41 # kernel modules built against kernels newer than 41.3 cannot be loaded on
42 # system running kernels older than 41.3, vice versa.
43 #
44 # For kernel >= 4.4.73,
45 # kernel modules built with 4.4.73 can run on systems with kernel versions from
46 # 4.4.73 to 4.4.114; modules built against 4.4.120 can run on systems from
47 # 4.4.120 onwards.
48 #
49 # For kernel 4.12.x, x>=14,
50 # kernel modules built with the oldest compatible kernel 4.12.14-94.41.1 can
51 # run on all versions onwards.
52 #
53 # This script checks the current running kernel version, and update symlinks
54 # for the openvswitch kernel modules in the appropriate kernel directory,
55 # provided the kmod RPM has installed kernel modules files built from both
56 # minor revisions.
57 #
58 # In case of a kernel minor revision change after the openvswitch kmod package
59 # is installed, this script shall be run manually after system reboots and
60 # switches to a different kernel
61 if [ -n "$(rpm -qa kmod-openvswitch)" ]; then
62 rpmname="kmod-openvswitch"
63 elif [ -n "$(rpm -qa openvswitch-kmod)" ]; then
64 rpmname="openvswitch-kmod"
65 else
66 echo "openvswitch kmod package not installed, existing"
67 exit 1
68 fi
69 #echo $rpmname
70 script_name=$(basename -- "$0")
71 current_kernel=$(uname -r)
72 echo current kernel is $current_kernel
73
74 IFS='.\|-' read mainline_major mainline_minor mainline_patch major_rev \
75 minor_rev _extra <<<"${current_kernel}"
76 # echo mainline_major=$mainline_major mainline_minor=$mainline_minor \
77 # mainline_patch=$mainline_patch major_rev=$major_rev minor_rev=$minor_rev
78
79 expected_rhel_base_minor="el7"
80 if [ "$mainline_major" = "3" ] && [ "$mainline_minor" = "10" ]; then
81 if [ "$major_rev" = "327" ]; then
82 # echo "rhel72"
83 comp_ver=36
84 ver_offset=4
85 installed_ver="$minor_rev"
86 elif [ "$major_rev" = "514" ]; then
87 # echo "rhel73"
88 comp_ver=26
89 ver_offset=4
90 installed_ver="$minor_rev"
91 elif [ "$major_rev" = "693" ]; then
92 # echo "rhel74"
93 comp_ver=11
94 ver_offset=4
95 installed_ver="$minor_rev"
96 elif [ "$major_rev" = "862" ]; then
97 # echo "rhel75"
98 comp_ver=20
99 ver_offset=4
100 installed_ver="$minor_rev"
101 elif [ "$major_rev" = "957" ]; then
102 # echo "rhel76"
103 comp_ver=10
104 ver_offset=4
105 installed_ver="$minor_rev"
106 elif [ "$major_rev" = "1062" ]; then
107 # echo "rhel77"
108 comp_ver=10
109 ver_offset=4
110 installed_ver="$minor_rev"
111 elif [ "$major_rev" = "1101" ]; then
112 # echo "rhel78"
113 comp_ver=10
114 ver_offset=4
115 installed_ver="$minor_rev"
116 elif [ "$major_rev" = "1127" ]; then
117 # echo "rhel78"
118 comp_ver=10
119 ver_offset=4
120 installed_ver="$minor_rev"
121 fi
122 elif [ "$mainline_major" = "4" ] && [ "$mainline_minor" = "4" ]; then
123 if [ "$mainline_patch" -ge "73" ]; then
124 # echo "sles12sp3"
125 comp_ver=114
126 ver_offset=2
127 installed_ver="$mainline_patch"
128 fi
129 elif [ "$mainline_major" = "4" ] && [ "$mainline_minor" = "12" ]; then
130 if [ "$mainline_patch" -ge "14" ]; then
131 # echo "sles12sp4"
132 comp_ver=1
133 ver_offset=2
134 installed_ver="$mainline_patch"
135 fi
136 fi
137
138 if [ X"$ver_offset" = X ]; then
139 echo "This script is not intended to run on kernel $(uname -r)"
140 exit 1
141 fi
142
143 #IFS='.\|-' read -r -a version_nums <<<"${current_kernel}"
144 #echo ver_offset=$ver_offset
145 #echo installed_ver="$installed_ver"
146 #echo installed_ver="${version_nums[$ver_offset]}"
147
148 kmod_versions=()
149 kversion=$(rpm -ql ${rpmname} | grep '\.ko$' | \
150 sed -n -e 's/^\/lib\/modules\/\(.*\)\/extra\/.*$/\1/p' | \
151 sort | uniq)
152 for kv in $kversion; do
153 IFS='.\|-' read -r -a kv_nums <<<"${kv}"
154 kmod_versions+=(${kv_nums[$ver_offset]})
155 done
156 sorted_kmod_vers=$(printf "%s\n" "${kmod_versions[@]}" | \
157 sort -n)
158 #echo "$sorted_kmod_vers"
159
160 if [ ! -n "$sorted_kmod_vers" ]; then
161 echo "No kernel modules found from package $rpmname, exiting"
162 exit 1
163 else
164 # first line for kmod_low_ver, last for kmod_high_ver
165 kmod_low_ver=$(echo "$sorted_kmod_vers" | head -1)
166 kmod_high_ver=$(echo "$sorted_kmod_vers" | tail -1)
167 fi
168 #echo "Installing KMOD with minor revisions $kmod_low_ver and \
169 #$kmod_high_ver"
170
171 found_match=false
172 for kname in $kversion;
173 do
174 IFS='.\|-' read -r -a pkg_ver_nums <<<"${kname}"
175 pkg_ver=${pkg_ver_nums[$ver_offset]}
176 if [ "$installed_ver" = "$expected_rhel_base_minor" ] ||
177 [ "$installed_ver" -le "$comp_ver" ]; then
178 if [ "$pkg_ver" = "$kmod_low_ver" ]; then
179 requested_kernel=$kname
180 found_match="true"
181 echo "Installing Openvswitch KMOD from kernel $kname"
182 break
183 fi
184 else
185 if [ "$pkg_ver" = "$kmod_high_ver" ]; then
186 requested_kernel=$kname
187 found_match="true"
188 echo "Installing Openvswitch KMOD from kernel $kname"
189 break
190 fi
191 fi
192 done
193
194 if [ "$found_match" = "false" ]; then
195 echo $script_name: Failed
196 exit 1
197 fi
198
199 if [ "$requested_kernel" != "$current_kernel" ]; then
200 if [ ! -d /lib/modules/$current_kernel/weak-updates/openvswitch ]; then
201 mkdir -p /lib/modules/$current_kernel/weak-updates
202 mkdir -p /lib/modules/$current_kernel/weak-updates/openvswitch
203 fi
204 for m in openvswitch vport-gre vport-stt vport-geneve \
205 vport-lisp vport-vxlan; do
206 ln -f -s /lib/modules/$requested_kernel/extra/openvswitch/$m.ko \
207 /lib/modules/$current_kernel/weak-updates/openvswitch/$m.ko
208 done
209 else
210 echo Proper OVS kernel modules already configured
211 fi
212 # Always run depmod
213 /sbin/depmod -a