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