Whamcloud - gitweb
LU-17705 ptlrpc: replace synchronize_rcu() with rcu_barrier()
[fs/lustre-release.git] / contrib / lbuild / lbuild-rhel
1 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
2
3 # increment this if you have made a change that should force a new kernel
4 # to build built for all releases of this distribution (only -- if you want
5 # to force a kernel build on all distributions, update the BUILD_GEN variable
6 # in build/lbuild)
7 #BUILD_GEN+=".0"
8 #BUILD_GEN+=".1"        # refactor both rhel5 and rhel6
9 #BUILD_GEN+=".0"        # TT-107: don't cache the BUILD dir (reset major to 5)
10 BUILD_GEN+=".2" # LU-9850
11
12 DEVEL_KERNEL_TYPE="devel"
13 RPM_HELPERS_DIR="/usr/lib/rpm/redhat"
14 # Pkg which contains ext4 source code
15 KERNEL_DEBUGINFO="kernel-debuginfo-common-${TARGET_ARCH}-${lnxmaj}-${lnxrel}.${TARGET_ARCH}.rpm"
16
17 # a method which can be overriden by the release specific code
18 get_rpmbuildopts() {
19
20     return 0
21
22 }
23
24 # patching common to all releases
25 patch_spec_common() {
26
27     sed -i -e '/Provides: kernel-uname-r =/a\
28 Provides: kernel-lustre = %{KVRA}%{?1:.%{1}}\\' \
29            -e '/Provides: kernel-devel-uname-r =/a\
30 Provides: kernel-devel-lustre = %{KVRA}%{?1:.%{1}}\\' \
31            -e '/find $RPM_BUILD_ROOT\/lib\/modules\/$KernelVer/a\
32     cp -a fs/ext3/* $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/fs/ext3 \
33     cp -a fs/ext4/* $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/fs/ext4' \
34           SPECS/$SPEC_NAME 2>&1 || \
35         fatal 1 "Error while editing SPECS/$SPEC_NAME"
36
37     # XXX - a building-on-Ubuntu hack
38     if grep -q "Ubuntu" /etc/issue; then
39         sed  -i -e 's/^\(BuildPreReq: .*\)$/#NOU \1/g' \
40                -e 's/^\(BuildRequires: .*\)$/#NOU \1/g' \
41                -e 's/sha512hmac/md5sum/g' \
42             SPECS/$SPEC_NAME 2>&1 || \
43                 fatal 1 "Error while editing SPECS/$SPEC_NAME"
44     fi
45
46 }
47
48 prepare_and_build_srpm() {
49
50         pushd $TOPDIR >/dev/null
51         # create the buildid
52         if $ENABLE_KERNEL_DEBUG; then
53                 local buildid="_lustre_debug${EXTRA_VERSION##*_lustre}"
54         else
55                 local buildid="_lustre${EXTRA_VERSION##*_lustre}"
56         fi
57
58         # edit the SPEC with our changes
59         patch_spec
60         popd >/dev/null
61
62         # copy our .config into the RPM build tree
63         if [[ $DISTROMAJ == "rhel7" || $DISTROMAJ == "rhel9" ]];then
64                 local cfg_file_name=kernel-$lnxmaj-${TARGET_ARCH}.config
65         else
66                 local cfg_file_name=kernel-${TARGET_ARCH}.config
67         fi
68         (echo "# $(basearch ${TARGET_ARCH})"; cat $CONFIG_FILE) > \
69                 SOURCES/$cfg_file_name
70
71         # XXX - hackity hack -- until we get (or generate from the base
72         #                       config) configs for xen and debug
73         local f=""
74         for f in SOURCES/kernel-*.config; do
75                 grep -q "^CONFIG_SD_IOSTATS=y" $f || \
76                 echo "CONFIG_SD_IOSTATS=y" >> $f
77         done
78
79     # do we need any special rpm build options
80     local rpmbuildopt="-bb"
81     if $DO_SRC; then
82         rpmbuildopt="-ba"
83     fi
84
85     # stupid Ubuntu's rpm doesn't do debuginfo properly
86     if [ ! -f /usr/lib/rpm/debugedit ]; then
87         rpmbuildopt="$rpmbuildopt --without debuginfo"
88     fi
89
90     # XXX - need to figure this kabichk crap out -- it fails the build
91     if ! $USE_KABI; then
92         rpmbuildopt="$rpmbuildopt --without kabichk"
93     fi
94
95     # get any release specific build options
96     rpmbuildopt="$rpmbuildopt $(get_rpmbuildopts)"
97
98         # now build it
99         if ! eval rpmbuild $rpmbuildopt --target ${TARGET_ARCH} \
100                 --define \"_topdir $TOPDIR\" \
101                 ${buildid:+--define \"buildid $buildid\"} \
102                 --define \"_tmppath $TMPDIR\" \
103                 $TOPDIR/SPECS/$SPEC_NAME 2>&1; then
104                 return 1
105         fi
106
107     # for informative purposes, display a diff between the .config that
108     # was actually built and what we proposed as a .config
109     echo "Diffs between $(basename $CONFIG_FILE) and the built kernel's .config:"
110     local rpmname="$TOPDIR/RPMS/${TARGET_ARCH}/kernel-${lnxmaj}-${lnxrel}${buildid}.${TARGET_ARCH}.rpm"
111     rpmcfg=$(rpm -qpl $rpmname | grep '/boot/config-')
112     rpm2cpio $rpmname | cpio -id .$rpmcfg
113     diff -u $CONFIG_FILE .$rpmcfg
114     rm -rf .$rpmcfg
115
116     return 0
117
118 }
119
120 devel_kernel_name() {
121     local lustre=${1:-false}
122
123     if $lustre; then
124         echo "kernel-lustre-$DEVEL_KERNEL_TYPE"
125     else
126         echo "kernel-$DEVEL_KERNEL_TYPE"
127     fi
128
129 }
130
131 rpm_BUILD_kernel_dirname() {
132     local rpmsmptype="$1"
133     local lnxmaj="$2"
134     local lnxmin="$3"
135     local arch="$4"
136
137     local lustre=""
138     if $KERNEL_LUSTRE_NAMING; then
139         $lustre="-lustre"
140     fi
141     echo kernel${lustre}${lnxmaj}${lnxmin}/linux-${lnxmaj}.$arch
142 }
143
144 find_linux_devel_paths() {
145     local path="$1"
146     local ARCH=$TARGET_ARCH
147
148     # If DEVEL_PATH_ARCH is set, use it. Added for fc11 as it needs i586 string for i686.
149     if [ $DEVEL_PATH_ARCH ];then
150         ARCH=$DEVEL_PATH_ARCH
151     fi
152
153     LINUX=$path/usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}${ARCH}
154     # RHEL doesn't have the -obj tree
155     LINUXOBJ=""
156
157     return 0
158 }
159
160 unpack_linux_devel_rpm-rhel() {
161     local callers_rpm="$1"
162
163     # now just sanity check that everything needed to build properly versioned
164     # modules is in place
165     if [ ! -f usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}$TARGET_ARCH/Module.symvers ]; then
166         fatal 1 "cannot build kernel modules: the Kernel's Module.symvers is missing."
167     fi
168
169     return 0
170
171 }
172
173 # this of course requires a sudo rule on the builder for real RHEL:
174 # hudson ALL= NOPASSWD: /usr/bin/yumdownloader
175 # also must disable the requiretty attribute in the sudoers file
176 find_linux_rpm-rhel() {
177     local prefix="$1"
178     local wanted_kernel="$2"
179     local pathtorpms=${3:-"$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH"}
180
181     local tmpdir=$(mktemp -d $pathtorpms/yumXXXXXX)
182     local sudo=""
183     if [ "$(lsb_release -s -i)" = "RedHatEnterpriseServer" ]; then
184         sudo="sudo"
185     fi
186     if ! $sudo yumdownloader --destdir "$tmpdir" kernel-devel-"$wanted_kernel" > /dev/null; then
187         fatal 1 "failed to fetch kernel-devel-$wanted_kernel with yumdownloader."
188     fi
189     local rpm=$(cd $tmpdir; echo *)
190     mv "$tmpdir/$rpm" "$pathtorpms"
191     rmdir $tmpdir
192     echo "$rpm"
193
194     return 0
195
196 }
197
198 # This function digs out the linux release from the linux source tree
199 find_linux_release() {
200         _find_linux_release $LINUX
201 }