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