3 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
5 # this is an alternative FD for stdout, to be used especially when we are
6 # taking stdout from a function as it's return value. i.e. foo=$(bar)
7 # this is a workaround until a version of bash where we can put xtrace
13 if [[ $SHELLOPTS = *xtrace* ]]; then
18 # Assume that lbuild's support files can be found in the same
19 # canonicalized path as this very script.
20 LBUILD_SCRIPT=$(readlink -f ${0})
21 LBUILD_DIR=${LBUILD_DIR:-$(dirname ${LBUILD_SCRIPT})}
23 # include the exit_traps library
24 . ${LBUILD_DIR}/exit_traps.sh
25 . ${LBUILD_DIR}/funcs.sh
27 # our children should die when we do
28 push_exit_trap "kill -INT -$$ || true" kill_children
30 # increment this if you have made a change that should force a new kernel
40 # XXX - some recent hacking has pretty much neutered this option.
41 # search through this file for "-bb" and see how many places
42 # simply don't account for this option
47 TARGET_ARCH="$(uname -m)"
52 TMPDIR=${TMPDIR:-"/var/tmp"}
56 # this is the dir that should be used to store reuse products
58 # should cached products be used or force rebuilding?
60 # what does this do exactly? does it imply no kernel build?
64 SMPTYPES="smp bigsmp default ''"
66 PATCHLESS_SERVER=false
72 # default to not adding -lustre- into the kernel RPM package names
73 KERNEL_LUSTRE_NAMING=false
74 ENABLE_KERNEL_DEBUG=false
75 # default not use kabi check.
93 # not in the target file any more
96 # build the lustre-tests rpm?
105 # Readlink is not present on some older distributions: emulate it.
109 if [ -L "$path" ]; then
110 ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
119 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
121 --external-patches=EXTERNAL_PATCHES
122 Directory similar to lustre/lustre/kernel_patches/ that lbuild should
123 look for seres and config files in before looking in the lustre
126 --extraversion=EXTRAVERSION
127 Text to use for the rpm release and kernel extraversion.
129 --timestamp=TIMESTAMP
130 Date of building lustre in format YYYYMMDDhhmmss
133 Try to reuse old kernel builds from DIR
136 Path to distro kernel RPM collection
145 Build lustre client only
148 Build lustre server without patching the kernel
151 Which distro using. Autodetect by default
153 --kerneldir=KERNELDIR
154 Directory containing Linux source tarballs referenced by target
157 --kerneltree=KERNELTREE
158 Directory containing dirs with Linux source tarballs referenced by target
159 files. Dir names in format kernel version ('2.6.9', etc.)
161 --enable-kernel-debug
162 Build with kernel-<version>.config-debug instead
164 --linux=LINUX --with-linux=LINUX
165 Directory of Linux kernel sources. When this option is used, only
166 Lustre modules and userspace are built.
169 Path to an existing lustre source tarball to use.
172 Do not try to download a kernel from downloads.whamcloud.com
175 Do not build a .src.rpm, a full kernel patch, or a patched kernel
179 Type of OFED to build with lustre: inkernel, ofa, mlnx, ifs
180 ofa: OpenFabrics Alliance
182 ifs: Intel True Scale Fabric
185 Version of external OFED to build with lustre
188 Version of external Mellanox OFED to build with lustre
191 Tarball for either OFED. Tarball must follow below format
192 OFED-<ofed-version>.tgz regardless of vendors
193 It's likely that you need to reconstruct the directory name
194 It must be placed under KERNELTREE directory
197 Build with ldiskfs support. (Deprecated, always true)
200 Do not build lustre-iokit RPM. Now true by default
206 Specifies that the files generated do not include timestamps, and
207 that this is an official release.
210 Build Lustre without ZFS.
213 Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
216 Directory used to stage packages for release. RPMs will be placed
217 more or less in DIR/<target>-<arch>, and the tarball will be
221 The name of the target to build. The available targets are listed
225 Builds a Xen domX kernel.
228 Sets a variable to a given value.
237 # canonicalize a relative path to a file
241 if [ ! -f "$PATH" ]; then
245 local FILE=${PATH##*/}
248 echo $(canon_path "$DIR")/$FILE
252 # canonicalize a relative path to a dir
256 if [ ! -d "$PATH" ]; then
260 pushd "$PATH" >/dev/null || return 1
270 if [ -z "$LUSTRE" -o ! -r "$LUSTRE" ]; then
271 usage 1 "Could not find Lustre source tarball '$LUSTRE'."
274 if $PATCHLESS && $PATCHLESS_SERVER; then
275 usage 1 "Can not use both --patchless and --patchless-server."
278 if [ -n "${OFED_SRC}" ]; then
279 if [ -z "${OFED_VERSION}" ]; then
280 usage 1 "Need to provide version for file ${OFED_SRC}."
282 if [ "${OFED_TYPE}" = "inkernel" ]; then
283 usage 1 "Need to provide ofed type for file ${OFED_SRC}."
286 if [ "${OFED_TYPE}" != "inkernel" -a -z "${OFED_VERSION}" ]; then
287 usage 1 "Need to provide version for $OFED_TYPE OFED"
290 if [ "${OFED_TYPE}" = "inkernel" -a -n "${OFED_VERSION}" ]; then
291 usage 1 "Can not specify version with inkernel OFED"
295 if [ -z "$DISTRO" ] ; then
296 DISTRO=$(autodetect_distro)
300 DISTROMAJ=${DISTRO%%.*}
302 [ -z "$TARGET" ] && TARGET=$(autodetect_target "$DISTRO")
304 if [ -z "$LINUX" ]; then
305 [ "$KERNELDIR" -o "$KERNELTREE" ] || \
306 usage 1 "A kernel directory must be specified with --kerneldir or --kerneltree."
308 [ -d "$KERNELDIR" -o -d "$KERNELTREE" ] || \
309 usage 1 "$KERNELDIR and $KERNELTREE are not a directory."
311 # TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
312 # [ -r "$TARGET_FILE" ] || \
313 # usage 1 "Target '$TARGET' was not found."
317 3.12-sles12 | 4.4-sles12)
318 CANONICAL_TARGET="sles12"
321 CANONICAL_TARGET="rhel8"
324 CANONICAL_TARGET="rhel7"
327 CANONICAL_TARGET="sles11"
331 local timestampnodig=$(echo $TIMESTAMP | sed -e s/[0-9]*//g)
332 [ "$timestampnodig" = "" ] || TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
333 local timestamplength="${#TIMESTAMP}"
334 if [ $timestamplength -eq 12 ]; then
335 TIMESTAMP="${TIMESTAMP}00"
336 elif [ $timestamplength -ne 14 ]; then
337 TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
340 RPMBUILD=$(which rpmbuild 2>/dev/null | head -n 1)
341 RPMBUILD=${RPMBUILD:-$(which rpm 2>/dev/null | head -n 1)}
342 if [ -z "$RPMBUILD" ]; then
343 usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
346 local BINDIR="$TOPDIR/bin"
347 if [ -d $BINDIR ]; then
348 rm -rf $BINDIR >/dev/null 2>&1 || true
351 mkdir -p $BINDIR || fatal 1 "error trying to create $BINDIR"
352 export PATH=$BINDIR:$PATH
354 cat >${BINDIR}/rpmbuild <<EOF
357 ARGS="\${FIND_REQUIRES:+--define \"__find_requires \$FIND_REQUIRES\"}"
360 *\'* ) ARGS="\$ARGS \"\$arg\"" ;;
361 * ) ARGS="\$ARGS '\$arg'" ;;
365 eval $RPMBUILD \$ARGS
367 chmod 755 ${BINDIR}/rpmbuild
369 if [ -n "$CCACHE" ]; then
370 which "$DISTCC" &>/dev/null && export DISTCC RPM_BUILD_NCPUS
372 if which "$CCACHE" &>/dev/null; then
373 local ccache=$(which "$CCACHE" 2>/dev/null | head -n 1)
375 ln -s "$ccache" ${BINDIR}/ccache
376 ln -s "$ccache" ${BINDIR}/cc
377 ln -s "$ccache" ${BINDIR}/$CC
380 export CC="ccache $CC"
381 # zero the cache so we can see how effective we are being with it
385 # get some ccache stats when we are done
386 push_exit_trap '[ -n "$CCACHE" ] && ccache -s' "ccache_summary"
387 # should remove the ccache trap if lbuild is interrupted
388 trap 'echo "Received an INT TERM or HUP signal, terminating."; delete_exit_trap "ccache_summary"; exit 1' INT TERM HUP
395 # compare two versions $1 and $2. if $1 < $2, return 0 otherwise return 1.
397 [[ $1 == $2 ]] && return 1
399 local i val1=($1) val2=($2)
401 # padding zero to val1 if it needs
402 for ((i=${#val1[@]}; i<${#val2[@]}; i++)); do
405 for ((i=0; i<${#val1[@]}; i++)); do
406 [[ -z ${val2[i]} ]] && return 1
408 if [[ ${val1[i]} < ${val2[i]} ]]; then
410 elif [[ ${val1[i]} > ${val2[i]} ]]; then
417 # Return a numeric version code based on a version string. The version
418 # code is useful for comparison two version strings to see which is newer.
420 # split arguments like "0.8.0" into "0", "8", "0"
421 eval set -- $(tr "[:punct:]" " " <<< $*)
422 echo -n "$((($1 << 16) | ($2 << 8) | $3))"
427 echo $(echo "$*" | xargs -n 1 | sort -u)
435 if [ -z "$target" ]; then
436 fatal 1 "fetch_url() called without a target to fetch to"
439 if [ -d $target ]; then
440 target+="/${url##*/}"
444 if which wget >/dev/null 2>&1; then
445 if ! wget -nv "$url" -O "$target"; then
448 elif which curl >/dev/null 2>&1; then
449 if ! curl -n -L -s -o "$target" "$url"; then
453 fatal 1 "Could not find either wget or curl to fetch URLs."
463 local force="${3:-false}"
465 # let the download_file handle the concurrency
468 # get the location from a distro specific method if it exists
469 if type -p kernel_srpm_location; then
470 location=$(kernel_srpm_location)
472 fatal 1 "Must specify location for download kernel SRPM."
474 echo "Downloading $location/$srpm..."
476 "$location/$srpm" "$KERNELDIR/$srpm" "$force" 2>&1 ||
477 [ ! -s "$KERNELDIR/$srpm" ]; then
478 rm -f $KERNELDIR/$srpm
479 fatal 1 "Could not download target $target's kernel \
480 SRPM $srpm from $location."
485 download_debuginfo_common() {
487 local force="${2:-false}"
489 # let the download_file handle the concurrency
491 # get the location from a distro specific method if it exists
492 if type -p kernel_debuginfo_location; then
493 location=$(kernel_debuginfo_location)
495 echo "Downloading $location/$rpm"
497 "$location/$rpm" "$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$rpm" "$force" 2>&1 ||
498 [ ! -s "$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$rpm" ]; then
499 rm -f $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$rpm
500 fatal 1 "Could not download $rpm from $location."
510 local file=${from##*/}
516 local semaphore="$to-downloading"
519 if [ ! -f $semaphore ]; then
523 # make sure the download has not been aborted
524 local now=$(date +%s)
525 local file_mtime=$(stat -c %Y "$to")
526 local staleness=$((now - file_mtime))
527 # let's assume an active download will write at least once a minute
528 if [ $staleness -gt 60 ]; then
536 # if the semaphore file exists, the file is either still downloading
537 # or a download was aborted and we cannot trust the target file
538 if [ -f $semaphore ]; then
542 if ! is_downloading && [ -r "$to" ] && [ -s "$to" ]; then
549 if $force || ! is_downloaded; then
550 if is_downloading; then
551 echo "Somebody else is downloading $from..."
552 while is_downloading; do
553 echo "Waiting for $to to finish downloading"
556 if is_downloaded; then
559 echo "The download we were waiting for seems to have been aborted"
565 echo "Downloading $from..."
566 # flag others so they don't try to download also
567 push_exit_trap "rm -f $to $semaphore" "download"
569 if ! fetch_url "$from" "$to" || [ ! -s "$to" ]; then
570 # the trap will remove the files via the fatal below
571 fatal 1 "Could not download ${to##*/} from ${from%/*}/."
574 delete_exit_trap "download"
576 fatal 1 "${to##*/} not found in directory ${to%/*}."
586 local ofed_version="$2"
587 local force="${3:-false}"
588 local distro_name="${DISTRO}"
589 local arch="${TARGET_ARCH}"
593 #if a src tarball has been given in the command line, we use it
594 #The format of the tarball must be OFED-${OFED_VERSION}.tgz
595 [ -n "${OFED_SRC}" ] && return 0
599 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version}/"
601 if [[ $ofed_version = *-[rR][cC][0-9] ]]; then
602 ofed_version_loc=${ofed_version%%-[rR][cC][0-9]}
603 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version_loc}/"
606 if [[ $ofed_version = *-daily ]]; then
607 ofed_version=${ofed_version/-daily/}
608 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version}-daily/"
609 # find the filename for latest version
610 ofed_version=$(curl -1 -s "$location" | sed -nre "s/.*href=\"OFED-(${ofed_version//./\\.}-[0-9]{8}-[0-9]{4}).tgz.*$/\1/p" | tail -1)
611 if [ -z "$ofed_version" ]; then
612 fatal 1 "Could not determine the filename of the OFED snapshot from daily "
616 file="OFED-${ofed_version}.tgz"
617 download_file "$location/$file" "$KERNELTREE" "$force"
620 location="http://www.mellanox.com/downloads/ofed/MLNX_OFED-${ofed_version}"
621 # this is a work around for suse distro (sles11.3). what we need is
622 # sles11sp3. We really need to redesign how we use target and distro
623 [[ $distro_name =~ sles ]] && distro_name=${DISTRO/./sp}
624 if [[ $arch = "aarch64" ]] && [[ $DISTROMAJ < "rhel8" ]]; then
625 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}alternate-${arch}.tgz"
627 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}-${arch}.tgz"
629 download_file "$location/$file" "$KERNELTREE" "$force"
632 location="http://downloadmirror.intel.com/24625/eng/"
633 file="IntelIB-Basic.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.${ofed_version}.tgz"
634 download_file "$location/$file" "$KERNELTREE" "$force"
637 fatal 1 "Error: unknown OFED type: $ofed_type"
640 # version might change due to detect daily version
641 OFED_VERSION=${ofed_version}
647 EXTRA_VERSION_save="$EXTRA_VERSION"
648 for patchesdir in "$EXTERNAL_PATCHES" \
649 "$TOPDIR/lustre/lustre/kernel_patches"; do
650 TARGET_FILE="$patchesdir/targets/$TARGET.target"
651 [ -r "$TARGET_FILE" ] && break
653 [ -r "$TARGET_FILE" ] || fatal 1 "Target $TARGET was not found."
655 echo "Loading target config file $TARGET.target..."
657 # if the caller specified an OFED_VERSION it should override whatever
658 # the target file specifies
659 local env_OFED_VERSION="$OFED_VERSION"
663 if [ -n "$env_OFED_VERSION" ]; then
664 OFED_VERSION="$env_OFED_VERSION"
667 # doesn't make any sense to build OFED for xen domX's
672 # XXX - set_rpm_smp_type is an ugly undeterministic hack. it needs to
673 # go away and the target just specify the $RPMSMPTYPE
674 [ -z "$RPMSMPTYPE" ] && set_rpm_smp_type
676 # CC might have been overwritten in TARGET_FILE
677 if [[ $CC != ccache\ * ]] && which "$CCACHE" &>/dev/null; then
678 export CCACHE && export CC="ccache $CC"
681 if [ ! "$KERNELTREE" = "" ] && [ -d "$KERNELTREE" ]; then
682 KERNELDIR="$KERNELTREE/${lnxmaj}"
683 [ -d "$KERNELDIR" ] || mkdir "$KERNELDIR"
686 # verify the series is available
687 if [ "$SERIES" ]; then
688 for series in $SERIES; do
689 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
690 [ -r "$patchesdir/series/$series" ] && continue 2
692 fatal 1 "Target $TARGET's series $SERIES could not be found.\nSearched:\n\t$EXTERNAL_PATCHES/series\n\t$TOPDIR/lustre/lustre/kernel_patches/series."
696 # set the location of the .config file
702 if $ENABLE_KERNEL_DEBUG; then
703 if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config-debug ]; then
704 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH.config-debug"
707 if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config ]; then
708 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH.config"
712 local lnxrelnew=${lnxrel//-/_}
714 # remember the EXTRA_VERSION before we diddle it here
715 # XXX - we really should not diddle with any values read in from the
716 # target file. if we want to modify a value, we should create
718 PRISTINE_EXTRA_VERSION=$EXTRA_VERSION
720 if ! $PATCHLESS && [ ! -f "$CONFIG_FILE" ]; then
721 fatal 1 "Config file for target $TARGET missing from $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
724 if [ "$EXTRA_VERSION_save" ]; then
725 EXTRA_VERSION="$EXTRA_VERSION_save"
726 elif ! $RELEASE; then
727 # if there is no patch series, then this is not a lustre specific
728 # kernel. don't make it look like one
729 if $PATCHLESS || [ -n "$SERIES" ]; then
730 EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
733 # EXTRA_VERSION=${EXTRA_VERSION//-/_}
739 echo -n '--wildcards '
742 fatal 1 "tarflags(): File name argument missing."
754 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
763 local extractfile="$@"
765 echo "Untarring ${tarfile##*/}..."
766 tar $(tarflags "$tarfile") "$tarfile" $extractfile
772 local ofed_version="$2"
773 local distro_name="${DISTRO}"
774 local arch="${TARGET_ARCH}"
777 #if a src tarball has been given in the command line, we use it
778 #The format of the directory after untar MUST be in OFED-${version}
779 #even if it's from MLNX or IFS...or whatever
780 if [ -n "${OFED_SRC}" ]; then
781 if ! untar "$KERNELTREE/${OFED_SRC}"; then
784 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
789 file="OFED-${ofed_version}"
790 if ! untar "$KERNELTREE/${file}.tgz"; then
793 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
796 # this is a work around for suse distro (sles11.3). what we need is
797 # sles11sp3. We really need to redesign how we use target and distro
798 [[ $distro_name =~ sles ]] && distro_name=${DISTRO/./sp}
799 if [[ $arch = "aarch64" ]] && [[ $DISTROMAJ < "rhel8" ]]; then
800 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}alternate-${arch}"
802 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}-${arch}"
804 # it's not important what distro we get the tarball since we only
805 # interest in the src
806 if ! untar "$KERNELTREE/${file}.tgz"; then
809 # we need to untar again to get the src since it's being
810 # wrapped inside the tarball
811 # There are cases where the source version is different
813 # (ie. MLNX_OFED_LINUX-2.3-1.0.1 but MLNX_OFED_SRC-2.3-1.0.0)
814 local src=$(ls ${file}/src/MLNX_OFED_SRC-${ofed_version%.*}*.tgz)
815 if ! untar "$src"; then
818 [ -d OFED ] || ln -sf MLNX_OFED_SRC-[0-9].[0-9]* OFED
819 if compare_version $ofed_version 4.7; then
820 [ -d OFED_RPMS ] || ln -sf ${file}/RPMS OFED_RPMS
822 [ -d OFED_RPMS ] || ln -sf ${file}/RPMS/MLNX_LIBS OFED_RPMS
826 file="IntelIB-Basic.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.${ofed_version}"
827 if ! untar "$KERNELTREE/${file}.tgz"; then
830 [ -d OFED ] || ln -sf $file/IntelIB-OFED.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.* OFED
831 ofed_version="$(cat OFED/Version)"
834 # version might change due to detect daily version
835 OFED_VERSION=${ofed_version}
840 untar "$LUSTRE" || fatal 1 "Error unpacking Lustre tarball"
841 [ -d lustre ] || ln -sf lustre-[0-9].[0-9]* lustre
847 local do_patch=${1:-true}
849 FULL_PATCH="$PWD/lustre-kernel-${TARGET}-${EXTRA_VERSION}.patch"
850 [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
851 $do_patch && pushd linux >/dev/null
852 for series in $SERIES; do
853 echo -n "Applying series $series:"
854 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
855 [ -r "$patchesdir/series/$series" ] || continue
856 SERIES_FILE="$patchesdir/series/$series"
857 for patch in $(<"$SERIES_FILE"); do
859 PATCH_FILE="$patchesdir/patches/$patch"
860 [ -r "$PATCH_FILE" ] || \
861 fatal 1 "Patch $patch does not exist in Lustre tree."
862 cat "$PATCH_FILE" >> "$FULL_PATCH" || {
864 fatal 1 "Error adding patch $patch to full patch."
867 patch -s -p1 < "$PATCH_FILE" 2>&1 || {
869 fatal 1 "Error applying patch $patch."
877 $do_patch && popd >/dev/null
878 echo "Full patch has been saved in ${FULL_PATCH##*/}."
885 local configure_args=""
889 pushd lustre >/dev/null
891 if ! build_lustre_dkms; then
892 popd >/dev/null # pushd lustre
896 echo "Building Lustre RPMs for: $TARGET_ARCH"
898 # If server we now build the spl and zfs modules against the lustre kernel.
899 # These are required prior to the building of lustre server. Client does
900 # not require spl/zfs. Use !PATCHLESS to indicate server which follows the
901 # line above so is at least consistant.
902 if [ $PATCHLESS == false ] && [ "x$WITH_ZFS" == "x" ]; then
903 if ! build_spl_zfs; then
904 popd >/dev/null # pushd lustre
910 configure_args="$configure_args --disable-server"
913 # ditto for the lustre-tests boolean
914 if ! $LUSTRE_TESTS; then
915 configure_args="$configure_args --disable-tests"
919 configure_args="$configure_args --disable-iokit"
922 if ! $OSDZFSRPM; then
923 configure_args="$configure_args --without-zfs"
926 if ! $OSDLDISKFSRPM; then
927 configure_args="$configure_args --disable-ldiskfs"
930 configure_args="$configure_args --with-linux=$linux"
931 configure_args="$configure_args ${linuxobj:+--with-linux-obj=$linuxobj}"
933 # allow environment setting to override ldiskfs series selection
934 [ -n "$LDISKFS_SERIES" ] && export LDISKFS_SERIES
936 ./configure $configure_args $CONFIGURE_FLAGS 2>&1 ||
937 fatal 1 "Error in configure."
939 if type -p apply_kmod_requires_conflicts; then
940 apply_kmod_requires_conflicts
944 fatal 1 "Error building rpms for $TARGET_ARCH."
946 # move RPMs into place where they are expected to be
947 mv -f *lustre*.${TARGET_ARCH}.rpm $TOPDIR/RPMS/${TARGET_ARCH}/
948 mv -f lustre-*.src.rpm $TOPDIR/SRPMS/
951 if type -p cleanup_rpmmacros; then
958 build_lustre_dkms() {
960 local ver=$(sed -n -e 's/^LUSTRE_VERSION = //p' LUSTRE-VERSION-FILE)
962 echo "Building Lustre DKMS RPMs for: $TARGET_ARCH"
963 ./configure --enable-dist || fatal 1 "Error in DKMS configure."
966 build_args="--without servers"
969 rpmbuild --define "_topdir $TOPDIR" $build_args -bs lustre-dkms.spec ||
970 fatal 1 "Error building DKMS .src.rpm for $TARGET_ARCH."
973 rpmbuild --define "_topdir $TOPDIR" $build_args \
974 --rebuild $TOPDIR/SRPMS/lustre-client-dkms-$ver-*.src.rpm ||
975 fatal 1 "Error building DKMS .rpm for $TARGET_ARCH."
977 rpmbuild --define="_topdir $TOPDIR" --with servers \
978 --with zfs --without ldiskfs -bs lustre-dkms.spec ||
979 fatal 1 "Error creating DKMS (zfs) .srpm for $TARGET_ARCH."
980 rpmbuild --define="_topdir $TOPDIR" --with servers \
981 --without zfs --with ldiskfs -bs lustre-dkms.spec ||
982 fatal 1 "Error creating DKMS (ldiskfs) .srpm for $TARGET_ARCH."
983 rpmbuild --define="_topdir $TOPDIR" --with servers \
984 --with zfs --with ldiskfs -bs lustre-dkms.spec ||
985 fatal 1 "Error creating DKMS (all) .srpm for $TARGET_ARCH."
987 rpmbuild --rebuild --define="_topdir $TOPDIR" --with servers \
988 --with zfs --without ldiskfs $TOPDIR/SRPMS/lustre-zfs-dkms-$ver-*.src.rpm ||
989 fatal 1 "Error building DKMS (zfs) .rpm for $TARGET_ARCH."
990 rpmbuild --rebuild --define="_topdir $TOPDIR" --with servers \
991 --without zfs --with ldiskfs $TOPDIR/SRPMS/lustre-ldiskfs-dkms-$ver-*.src.rpm ||
992 fatal 1 "Error building DKMS (ldiskfs) .rpm for $TARGET_ARCH."
993 rpmbuild --rebuild --define="_topdir $TOPDIR" --with servers \
994 --with zfs --with ldiskfs $TOPDIR/SRPMS/lustre-all-dkms-$ver-*.src.rpm ||
995 fatal 1 "Error building DKMS (all) .rpm for $TARGET_ARCH."
1004 # Fetch spl/zfs from the git repo and prepare for lustre build
1007 # SPLZFSGITREPO - URI of directory where spl.git and zfs.git are located
1008 # SPLZFSTAG - Tag to checkout of clone repositories
1009 # SPLZFSVER - Version to checkout of both (format zfs/spl-$SPLZFSVER)
1011 # return 0 if successful, else 255
1013 # make sure the RPM build environment is set up
1015 create_rpmbuild_dirs
1018 # The spl/zfs spec files expect RPM_BUILD_ROOT to point to the root of the
1019 # destination for the rpms
1020 export RPM_BUILD_ROOT=$TOPDIR
1021 SPLZFSVER=${SPLZFSVER:-0.8.4}
1022 SPLZFSTAG=${SPLZFSTAG:-}
1023 # "spl zfs" prior to 0.8.0
1024 # "zfs" for 0.8.0 and later
1025 (( $(version_code $SPLZFSVER) < $(version_code 0.8.0) )) &&
1026 SPLZFSPKGS="spl zfs" || SPLZFSPKGS="zfs"
1028 # The files expect a kver to be set to the kernel version .
1029 local kver=$(find_linux_release)
1031 # build and install the spl and zfs (and -devel) RPMs for lustre to use
1034 for pkg in $SPLZFSPKGS; do
1038 # need to fetch the repo in order to build it.
1039 # default to github but allow override
1040 git clone -n ${SPLZFSGITREPO:-"https://github.com/zfsonlinux"}/$pkg.git $pkg 2>&1
1042 pushd $pkg || return 255
1044 if [ -n "$SPLZFSTAG" ]; then
1049 git checkout -b lbuild $tag || fatal 1 "Failed to checkout \"$tag\" for $pkg.git"
1051 # This differentiates between older zfs versions
1052 if [ -f $pkg-modules.spec.in ]; then
1055 speclist="$pkg.spec $rpmpkg.spec"
1057 rpmpkg=kmod-$pkg-devel
1059 speclist="$pkg.spec $pkg-kmod.spec $pkg-dkms.spec"
1062 sh autogen.sh || return 255
1064 if ! ./configure --with-linux=${LINUX} --with-linux-obj=${LINUXOBJ:-$LINUX} \
1065 ${spldir:+--with-spl="${spldir}"} 2>&1 ||
1066 ! make dist 2>&1; then
1072 ln -f $pkg/$pkg-*.tar.gz $TOPDIR/SOURCES ||
1073 error "failed to link $pkg/$pkg-*.tar.gz into $TOPDIR/SOURCES"
1074 if [ -f $pkg/scripts/kmodtool ]; then
1075 ln -f $pkg/scripts/kmodtool $TOPDIR/SOURCES/
1085 # set search dir for our own kmodtool to find correct
1087 export KERNELSOURCE=$(dirname ${LINUX})
1088 # Manually build rpms
1089 for spec in $speclist; do
1090 echo "Building RPMs from $pkg/$specdir/$spec"
1091 if ! rpmbuild $rpmb $pkg/$specdir/$spec \
1093 --define "_use_internal_dependency_generator 0" \
1094 --define "require_kdir ${LINUX}" \
1095 ${LINUXOBJ:+--define "require_kobj ${LINUXOBJ}"} \
1096 ${spldir:+--define "require_spldir ${spldir}"} \
1097 --define "kver $kver" \
1098 --define "kernels $kver" \
1099 --define "_tmppath /var/tmp" \
1100 --define "kernelbuildroot $TOPDIR/reused" \
1101 --define "_topdir $TOPDIR" 2>&1; then
1106 # We have built the rpms for the package. Now we need to extract the
1107 # contained files so we can build further things against them
1108 local rpms=$(ls -1 $TOPDIR/RPMS/*/$rpmpkg-*.rpm)
1110 # cpio only extract to pwd so we need to go there.
1113 for rpm in $rpms; do
1114 rpm2cpio $rpm | cpio -id
1117 if [ "$pkg" == "zfs" ]; then
1118 # We also need to extract both the zfs and zfs-devel rpms
1119 # the zfs rpm is needed because it has the actual libraries in
1120 # it and the zfs-devel rpm only has unversioned symlinks to the
1121 # libraries in the zfs rpm
1122 # this will all change one day when we have a libzfs rpm per
1123 # https://github.com/zfsonlinux/zfs/issues/2329
1124 # and it looks like it could be one day soon:
1125 # https://github.com/zfsonlinux/zfs/pull/2341
1126 local devel_rpms=$(ls -1 $TOPDIR/RPMS/*/{$pkg-devel,$pkg-$SPLZFSVER,lib*}-*.rpm)
1127 for rpm in $devel_rpms; do
1128 rpm2cpio $rpm | cpio -id
1130 CONFIGURE_FLAGS="--with-$pkg-devel=$TOPDIR ${CONFIGURE_FLAGS}"
1131 if [ -z "$spldir" ]; then
1132 # if spldir is empty, then we are only building ZFS and need to define SPL config flags
1133 CONFIGURE_FLAGS="--with-spl=$(ls -d $TOPDIR/usr/src/spl-*|tail -1) ${CONFIGURE_FLAGS}"
1134 CONFIGURE_FLAGS="--with-spl-obj=$(ls -d $TOPDIR/usr/src/$pkg-*/$kver*|tail -1) ${CONFIGURE_FLAGS}"
1136 elif [ "$pkg" == "spl" ]; then
1137 spldir="$(ls -d $TOPDIR/usr/src/spl-*|tail -1)"
1141 CONFIGURE_FLAGS="--with-$pkg=$(ls -d $TOPDIR/usr/src/$pkg-*|tail -1) ${CONFIGURE_FLAGS}"
1142 CONFIGURE_FLAGS="--with-$pkg-obj=$(ls -d $TOPDIR/usr/src/$pkg-*/$kver*|tail -1) ${CONFIGURE_FLAGS}"
1152 [ "$STAGEDIR" ] || return 0
1154 rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${TARGET_ARCH}"
1155 echo "${0##*/}: Copying RPMs into ${rpmdir}"
1156 mkdir -p "${rpmdir}"
1157 for rpm in $(ls RPMS/${TARGET_ARCH}/*.rpm RPMS/noarch/*.rpm); do
1158 cp -v $rpm "${rpmdir}"
1161 cp -v "$LUSTRE" "$STAGEDIR"
1165 set_rpm_smp_type() {
1167 local infact_arch="${TARGET_ARCH}"
1170 [ "$infact_arch" == "i586" ] && infact_arch="i686"
1173 for smp_type in $SMP_ARCHS; do
1174 [ $infact_arch == $smp_type ] && RPMSMPTYPE=smp && break
1177 for smp_type in $BIGSMP_ARCHS; do
1178 [ $infact_arch == $smp_type ] && RPMSMPTYPE=bigsmp && break
1181 for smp_type in $PPC64_ARCHS; do
1182 [ $infact_arch == $smp_type ] && RPMSMPTYPE=ppc64 && break
1185 for smp_type in $DEFAULT_ARCHS; do
1186 [ $infact_arch == $smp_type ] && RPMSMPTYPE=default && break
1191 # This function takes a linux include tree and digs out the linux release
1192 # from it. It is never called directly, only called from the distro
1193 # specific function find_linux_release() in lbuild-{rhel,sles}.
1194 _find_linux_release() {
1196 local LINUXRELEASEHEADER=""
1198 LINUXRELEASEHEADER=$SRC/include/linux/version.h
1199 if [ -s $SRC/include/generated/utsrelease.h ]; then
1200 LINUXRELEASEHEADER=$SRC/include/generated/utsrelease.h
1201 elif [ -s $SRC/include/linux/utsrelease.h ]; then
1202 LINUXRELEASEHEADER=$SRC/include/linux/utsrelease.h
1205 if [ ! -s $LINUXRELEASEHEADER ]; then
1206 fatal 1 "could not find UTS_RELEASE"
1209 sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' $LINUXRELEASEHEADER
1212 # unpack kernel(/source/devel) RPM
1214 unpack_linux_devel_rpm() {
1215 local kernelrpm="${1}"
1217 [ -f "$kernelrpm" ] || return 255
1218 [ -d $TOPDIR/reused ] || mkdir $TOPDIR/reused || return 255
1220 pushd $TOPDIR/reused &>/dev/null || return 255
1222 if ! rpm2cpio < "$kernelrpm" | cpio -id > /dev/null 2>&1; then
1226 # call a distro specific hook, if available
1227 if type -p unpack_linux_devel_rpm-$DISTROMAJ; then
1228 if ! unpack_linux_devel_rpm-$DISTROMAJ "$kernelrpm"; then
1235 find_linux_devel_paths $TOPDIR/reused
1243 local kib_prefix="$2"
1245 local ofed_type="${4}"
1246 local ofed_version="${5}"
1248 # build kernel-ib{,-devel}/compat-rdma{,-devel}
1251 local OFED_CORE="--with-core-mod --with-ipoib-mod --with-user_mad-mod \
1252 --with-user_access-mod --with-addr_trans-mod --with-innova-flex "
1253 local OFED_HARDWARE="--with-mlx4-mod --with-mlx4_en-mod \
1254 --with-srp-mod --with-iser-mod --with-isert-mod --with-mlx5-mod \
1257 # some I/B drivers are architecture dependent and kernel-ib's configure
1258 # does not figure it out for us ~sigh~
1259 case "$TARGET_ARCH" in
1261 OFED_HARDWARE="$OFED_HARDWARE --with-ehca-mod"
1265 # assume we are just rebuilding the SRPM
1266 local BUILD_TYPE=${BUILD_TYPE:-"--rebuild"}
1267 local SOURCE="${TOPDIR}/OFED/SRPMS/${kib_prefix}-*.src.rpm"
1269 # but switch to building from the SPEC if we need to apply patches
1270 if ls ${TOPDIR}/lustre/contrib/patches/ofed/* >/dev/null; then
1272 rpm --define "_topdir ${TOPDIR}" -ivh $SOURCE
1273 SOURCE="${TOPDIR}/SPECS/${kib_prefix}.spec"
1274 local file ed_fragment1 ed_fragment2 n=1
1275 for file in $(ls ${TOPDIR}/lustre/contrib/patches/ofed/*.patch 2>/dev/null); do
1276 ed_fragment1="$ed_fragment1
1277 Patch$n: ${file%%*/}"
1278 ed_fragment2="$ed_fragment2
1280 cp $file ${TOPDIR}/SOURCES
1283 for file in $(ls ${TOPDIR}/lustre/contrib/patches/ofed/*.ed 2>/dev/null); do
1284 # Only apply the ed-scripts that should be used for the canonical target
1285 # ed-files in ${TOPDIR}/lustre/contrib/patches/ofed/ have to follow the naming
1287 # <two-digits>-<descriptive-name>:<canonical_target_1>: ...:<canonical_target_N>.ed
1288 # To apply the same change to multiple canonical target simply specify
1289 # a list of colon separated canoncial target names in the file name.
1290 echo "$file" | grep -q -e ":${CANONICAL_TARGET}:" \
1291 -e ":${CANONICAL_TARGET}.ed$"
1292 if [ $? -eq 0 ] ; then
1293 ed_fragment3="$ed_fragment3
1299 if [ $n -gt 1 ]; then
1313 local linuxrelease=$(find_linux_release)
1314 # a place to change/add any unique config
1316 ofa|ifs) local K_SRC_OBJ="K_SRC_OBJ"
1317 if ! $RPMBUILD $BUILD_TYPE --define 'build_kernel_ib 1' \
1318 --define 'build_kernel_ib_devel 1' \
1319 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1320 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1321 --define "KVERSION ${linuxrelease}" \
1322 --define "$K_SRC ${linux}" \
1323 ${K_SRC_OBJ:+--define "$K_SRC_OBJ ${linux}"} \
1324 ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
1325 --define "configure_options --without-quilt $OFED_CORE $OFED_HARDWARE $OFED_ISCSI" \
1326 ${SOURCE} 2>&1; then
1327 fatal 1 "Error building ${kib_rpm}"
1331 if ! $RPMBUILD $BUILD_TYPE \
1332 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1333 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1334 --define "KVERSION ${linuxrelease}" \
1336 --define "$K_SRC ${linux}" \
1337 ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
1338 ${SOURCE} 2>&1; then
1339 fatal 1 "Error building ${kib_rpm}"
1341 # now that we have the kernel rpms, we need to lib rpms too
1342 # we don't have to rebuild since MOFED include the binaries
1343 cp -f OFED_RPMS/{libibmad-*,libibverbs-*,libibumad-*,librdmacm*,ibutils*,opensm-*}.${TARGET_ARCH}.rpm \
1344 ${TOPDIR}/RPMS/${TARGET_ARCH} || \
1345 fatal 1 "Failed to copy MOFED rpms"
1355 local signature="$4"
1356 local use_links="$5"
1363 local unique_id=$(hostname -s)
1364 if [ -z "$unique_id" ]; then
1365 fatal 1 "Failed to determine hostname."
1368 local finallocation="$location"/"$signature"/"$module"
1369 location="$location"/"$signature-${unique_id}"/"$module"
1370 mkdir -p "$location"
1371 # the cleanup script removes any directory that doesn't have a
1372 # .lastused, so let's try to prevent that as soon as we can
1373 # this solution still slightly racy with the cleanup script
1374 # but the race is a lot tighter now
1375 touch -t 197001010000 "$location/.lastused"
1376 ## use eval/echo here to make sure shell expansions are performed
1377 #if ! cp -a${linkflag} $(eval echo $articles) "$location"; then
1379 for article in $(eval echo $articles); do
1380 if ! cp -a${linkflag} "$article" "$location"; then
1381 error "Failed to copy \"$article\" to \"$location\" in store_for_reuse()"
1382 # rename the cache location so that it's not cached
1383 # product, but is around for analysis
1384 mv "$location"{,-bad-$(date +%s)} ||
1385 error "failed to clean up a failed cache attempt" \
1386 "in \"$location\" -- manual cleanup will be" \
1392 # flag the cache as complete (i.e. in case lbuild was previously
1393 # interrupted while caching)
1394 touch "$location/.lastused"
1396 # put the temporary location into the final location
1398 mkdir -p "${finallocation%/*}"
1399 mv "$location" "$finallocation"
1400 rmdir "${location%/*}"
1408 local use_links="${3:-false}"
1409 local signature="$4"
1411 if [ -n "$REUSEBUILD" ] && [ -d "$REUSEBUILD/$signature/$module" ]; then
1412 if [ ! -f "$REUSEBUILD/$signature/$module/.lastused" ]; then
1413 # the .lastused flag is populated at the end of the caching to
1414 # signal that the caching was completed. if that flag is not
1415 # there, then the cache is invalid (and should be removed in fact)
1416 mv "$REUSEBUILD/$signature/$module"{,-bad-$(date +%s)} ||
1417 fatal 1 "failed to clean up a bad cache in location $REUSEBUILD/$signature/$module\" -- manual cleanup will be necessary"
1421 # so that we know how stale this entry is
1422 touch $REUSEBUILD/$signature/$module/.lastused
1425 if ls $REUSEBUILD/$signature/$module/* >/dev/null 2>&1; then
1426 cp -al $REUSEBUILD/$signature/$module/* $dest/
1429 # copying is pretty heavy
1430 # cp -a $REUSEBUILD/$signature/$module/* $dest/
1431 # do some creative symlinking instead
1433 for dir in BUILD SRPMS SPECS; do
1434 if ls $REUSEBUILD/$signature/$module/$dir/* >/dev/null 2>&1; then
1435 ln -s $REUSEBUILD/$signature/$module/$dir/* $dest/$dir
1438 # sources have to be copied by file because we need SOURCES to
1439 # be a dir we can write into
1440 # could overrun ls's arg list here
1441 #ls $REUSEBUILD/$signature/$module/SOURCES/* |
1442 find $REUSEBUILD/$signature/$module/SOURCES/ -type f |
1443 xargs ln -t $dest/SOURCES -s
1445 # same for RPMS/* dirs
1446 # could overrun ls's arg list here
1447 #ls $REUSEBUILD/$signature/$module/RPMS/$TARGET_ARCH/* |
1449 for dir in $REUSEBUILD/$signature/$module/RPMS/*; do
1450 mkdir -p $dest/RPMS/${dir##*/}
1452 xargs ln -t $dest/RPMS/${dir##*/} -s
1464 if [[ $arch = i[3456]86 ]]; then
1472 build_kernel_with_srpm() {
1475 if [ -z "$outfd" ] || [ $outfd = 1 ]; then
1476 fatal 1 "You must supply a file descriptor to ${FUNCNAME[0]} and it cannot be 1"
1479 # need to generate the patch for this target
1480 do_patch_linux false >&${outfd} # sets global $FULL_PATCH (yeah, yuck)
1482 # get an md5sum of the kernel patch + config for reuse check
1485 local release_str="RELEASE=$RELEASE\n"
1488 if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1489 local REUSE_SIGNATURE=$({ echo -en $release_str;
1492 cat "$TARGET_FILE" |
1493 sed -e '/_VERSION=/s/_[0-9]*_g.*$//g';
1495 cat "$LBUILD_DIR/lbuild";
1496 test -f lbuild-${DISTROMAJ%%[0-9]*} &&
1497 cat lbuild-${DISTROMAJ%%[0-9]*};
1498 cat "$LBUILD_DIR/lbuild-$DISTROMAJ"; } |
1499 md5sum | cut -d" " -f1)
1500 # see if we can link to the reuse pool
1501 # XXX - hrm. i'm not convinced this doesn't belong in the reuse
1503 local CAN_LINK_FOR_REUSE=false
1504 touch $REUSEBUILD/$$
1505 if cp -al $REUSEBUILD/$$ $TOPDIR/ 2>/dev/null; then
1506 CAN_LINK_FOR_REUSE=true
1511 # the extra version string to use for the kernel (which might be a reused
1513 local kernel_extra_version=""
1514 if ! $USE_BUILD_CACHE || ! reuse kernel "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1515 "$REUSE_SIGNATURE"; then
1516 # nothing cached, build from scratch
1517 echo "Downloading kernel SRPM" >&${outfd}
1518 download_srpm "$CANONICAL_TARGET" "$KERNEL_SRPM" >&${outfd}
1520 if ! rpm -ivh $KERNELDIR/$KERNEL_SRPM \
1521 --define "_topdir $TOPDIR" >&${outfd} 2>&1; then
1522 # should we clean this up or leave it for analysis?
1524 fatal 1 "Error installing kernel SRPM."
1527 # put the Lustre kernel patch into the RPM build tree
1528 cp $FULL_PATCH $TOPDIR/SOURCES/linux-${lnxmaj}-lustre.patch
1529 prepare_and_build_srpm >&${outfd} ||
1530 fatal 1 "failed to prepare_and_build_srpm"
1532 if [ -z "$REUSE_SIGNATURE" ]; then
1533 echo "No reuse signature was caculated so not storing the built kernel" >&${outfd}
1535 # store the resulting kernel RPM build tree for future use
1536 echo "Storing the built kernel for future reuse" >&${outfd}
1537 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,SRPMS,RPMS}" \
1538 "kernel" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1539 "$CAN_LINK_FOR_REUSE"; then
1540 error "Failed to store kernel RPMS for reuse"
1541 echo "unknown" >&${outfd}
1547 # figure out the EXTRA_VERSION of the kernel we built or are re-using
1549 if ! KERNEL_RPM=$(find_rpm "$TOPDIR/RPMS/$TARGET_ARCH/" provides "^kernel(-default)? ="); then
1550 fatal 1 "Failed to find a kernel RPM in $TOPDIR/RPMS/$TARGET_ARCH/"
1552 kernel_extra_version=$(rpm -q --queryformat "%{RELEASE}" -p $TOPDIR/RPMS/$TARGET_ARCH/$KERNEL_RPM)
1554 # should now have the following RPMs
1555 # $TOPDIR/RPMS/$arch/kernel-lustre-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1556 # $TOPDIR/RPMS/$arch/kernel-lustre-devel-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1557 # $TOPDIR/RPMS/$arch/kernel-lustre-headers-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1558 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-common-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1559 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1561 echo $kernel_extra_version
1569 # REUSEBUILD, USE_BUILD_CACHE
1574 local ofed_type="$2"
1575 local ofed_version="$3"
1582 if [ "$ofed_version" = "inkernel" ]; then
1583 # see if there is a distro specific override for this and use
1585 # XXX we need to better integrate a distro specific override with
1586 # the rest of this function so that all of the reuse cache
1587 # stuff is leveraged given that 80% of this function is reuse
1588 if type -p build_ofed-$DISTROMAJ; then
1590 ofed_location=$(build_ofed-$DISTROMAJ ${STDOUT})
1591 local rc=${PIPESTATUS[0]}
1592 CONFIGURE_FLAGS="--with-o2ib=${ofed_location} ${CONFIGURE_FLAGS}"
1599 mlnx) # no compat-rdma for mlnx as of 3.1
1600 kib_prefix="ofa_kernel"
1602 kib_rpm="${pre_prefix}${kib_prefix}"
1605 if compare_version $ofed_version 3.0; then
1606 kib_prefix="ofa_kernel"
1607 kib_rpm="${pre_prefix}${kib_prefix}"
1609 kib_prefix="compat-rdma"
1610 kib_rpm="compat-rdma"
1616 # build kernel-ib/compat-rdma
1617 if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1618 local REUSE_SIGNATURE=$({ echo "$ofed_version";
1619 echo "$(find_linux_release;
1620 echo "$BUILD_GEN")";
1621 cat "${linux}/include/linux/autoconf.h";
1622 cat "$LBUILD_DIR/lbuild";
1623 test -f lbuild-${DISTROMAJ%%[0-9]*} &&
1624 cat lbuild-${DISTROMAJ%%[0-9]*};
1625 cat "$LBUILD_DIR/lbuild-$DISTROMAJ"; } |
1626 md5sum | cut -d" " -f1)
1627 # see if we can link to the reuse pool
1628 # XXX - hrm. i'm not convinced this doesn't belong in the reuse
1630 local CAN_LINK_FOR_REUSE=false
1631 touch $REUSEBUILD/$$
1632 if cp -al $REUSEBUILD/$$ $TOPDIR/; then
1633 CAN_LINK_FOR_REUSE=true
1638 if ! $USE_BUILD_CACHE || ! reuse ofed "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1639 "$REUSE_SIGNATURE"; then
1640 if [ -n "$REUSE_SIGNATURE" ]; then
1641 # stash away the existing built articles for a moment
1643 mv {BUILD,{S,}RPMS,S{OURCE,PEC}S} bak
1646 find . | cpio -pudlm ..
1650 create_rpmbuild_dirs
1653 build_kernel_ib "${linux}" "${pre_prefix}${kib_prefix}" "${kib_rpm}" "${ofed_type}"
1655 if [ -z "$REUSE_SIGNATURE" ]; then
1656 echo "No reuse signature was caculated so not storing the built ofed"
1658 # store the resulting RPM build tree for future use
1659 echo "Storing the built ofed for future reuse"
1660 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
1661 "ofed" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1662 "$CAN_LINK_FOR_REUSE"; then
1663 error "Failed to store OFED RPMS for reuse"
1667 # put the stuff we stashed away back
1672 pushd "$TOPDIR" >/dev/null
1673 rm -rf ${kib_rpm}-devel
1674 mkdir ${kib_rpm}-devel
1677 o2ib_location="$(pwd)/usr/src/${kib_prefix}"
1679 mlnx) # Prior to MOFED 3.1, we had to use build_kernel_ib=1 to
1680 # build devel rpm. not so after 3.1
1681 if compare_version $ofed_version 3.0; then
1682 rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version%%-*}-*.rpm)
1684 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-${ofed_version%%-*}-*.rpm)
1686 o2ib_location="${o2ib_location}/default"
1688 ofa) # Prior to OFA 3.18, we had to use build_kernel_ib=1 during configure,
1690 if compare_version $ofed_version 3.18; then
1691 rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version%%-*}-*.rpm)
1693 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-${ofed_version%%-*}-*.rpm)
1696 ifs) # ifs doesn't follow any convention (if any)
1697 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-*.rpm)
1701 if ! rpm2cpio < $rpm | cpio -id; then
1702 fatal 1 "could not unpack the $rpm."
1704 CONFIGURE_FLAGS="--with-o2ib=${o2ib_location} ${CONFIGURE_FLAGS}"
1710 local ofed_type="$1"
1711 local ofed_version="$2"
1714 if ! $PATCHLESS; then
1715 if $PATCHLESS_SERVER; then
1716 # need to find and unpack the vendor's own kernel-devel
1717 # for patchless server build
1718 if ! kernelrpm=$(find_linux_rpm "-$DEVEL_KERNEL_TYPE"); then
1719 fatal 1 "Could not find the kernel-$DEVEL_KERNEL_TYPE RPM in $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ"
1721 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm "$kernelrpm" "-"; then
1722 fatal 1 "Could not find the Linux tree in $kernelrpm"
1724 # download and unpack kernel-debuginfo-common (only in EL)
1725 if [[ $DISTROMAJ =~ rhel ]]; then
1726 local KERNEL_DEBUGINFO="kernel-debuginfo-common-${TARGET_ARCH}-${lnxmaj}-${lnxrel}.${TARGET_ARCH}.rpm"
1727 download_debuginfo_common "$KERNEL_DEBUGINFO"
1728 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm \
1729 "$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$KERNEL_DEBUGINFO"; then
1730 fatal 1 "Could not find the Linux debuginfo common rpm in $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$KERNEL_DEBUGINFO"
1734 local kernel_extra_version
1735 if ! kernel_extra_version=$(build_kernel_with_srpm ${STDOUT}); then
1736 fatal 1 "Failed to build the kernel from it's SRPM"
1739 local kernel_devel_rpm
1740 if ! kernel_devel_rpm=$(find_rpm "$TOPDIR/RPMS/${TARGET_ARCH}/" provides "^$(devel_kernel_name $KERNEL_LUSTRE_NAMING) ="); then
1741 fatal 1 "Failed to find a kernel development RPM in $TOPDIR/RPMS/${TARGET_ARCH}/"
1744 # install the -devel RPM in preparation for modules builds
1745 if ! lnxrel="$kernel_extra_version" unpack_linux_devel_rpm \
1746 "$TOPDIR/RPMS/${TARGET_ARCH}/$kernel_devel_rpm"; then
1747 fatal 1 "Could not find the Linux tree in $TOPDIR/RPMS/${TARGET_ARCH}/$kernel_devel_rpm"
1751 # need to find and unpack the vendor's own kernel-devel for patchless
1753 if ! kernelrpm=$(find_linux_rpm "-$DEVEL_KERNEL_TYPE"); then
1754 fatal 1 "Could not find the kernel-$DEVEL_KERNEL_TYPE RPM in $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ"
1756 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm "$kernelrpm" "-"; then
1757 fatal 1 "Could not find the Linux tree in $kernelrpm"
1761 # ~sigh~ have to make copies of and modify some of the rpm
1762 # infrastructure files so that find-requires can find our unpacked
1763 # kernel-devel artifacts
1764 cp $RPM_HELPERS_DIR/{symset-table,find-requires{,.ksyms}} .
1765 export FIND_REQUIRES="$(pwd)/find-requires"
1766 chmod 755 {symset-table,find-requires{,.ksyms}}
1768 tmp="${tmp//\//\\/}"
1769 sed -i "s/\/.*find-requires.ksyms/$tmp\/find-requires.ksyms/g" find-requires
1770 sed -i "s/\/usr\/src\/kernels/$tmp\/reused\/usr\/src\/kernels/" find-requires.ksyms
1771 sed -i "s/\/boot/$tmp\/reused\/boot/; s/\/usr\/src\/kernels/$tmp\/reused\/usr\/src\/kernels/" symset-table
1773 build_ofed "${LINUXOBJ:-$LINUX}" "$ofed_type" "$ofed_version" ||
1774 fatal 1 "error building OFED"
1777 if build_lustre "$LINUX" "$LINUXOBJ"; then
1778 # the build worked. resolve any symlinked files (i.e. from reuse)
1779 # in RPMS/$arch to real files so that that that huge mess of
1780 # complication known as LTS can copy them yet somewhere else.
1781 # is it any wonder this whole process is so damn so? anyone ever
1782 # heard of hardlinks? it's this cool new thing that allows you save
1783 # tons of time and space by creating... well you can go read about
1784 # them if you have not heard about them yet.
1785 # can i say how much the implemenation of all of this really impedes
1788 for dir in RPMS/*; do
1790 for file in $(ls); do
1791 if [ -h $file ]; then
1798 # also, for i?86, make sure all of the RPMs are in RPMS/$TARGET_ARCH
1799 # as that's where LTS expects to find them
1800 for dir in RPMS/*; do
1801 if [ $dir = RPMS/$TARGET_ARCH ]; then
1806 if [ -n "$files" ]; then
1807 cp -al $files ../$TARGET_ARCH
1817 create_rpmbuild_dirs() {
1819 [ -d RPMS ] || mkdir RPMS
1820 [ -d RPMS/${TARGET_ARCH} ] || mkdir RPMS/${TARGET_ARCH}
1821 [ -d RPMS/noarch ] || mkdir RPMS/noarch
1822 [ -d BUILD ] || mkdir BUILD
1823 [ -d SOURCES ] || mkdir SOURCES
1824 [ -d SPECS ] || mkdir SPECS
1825 [ -d SRPMS ] || mkdir SRPMS
1847 [[ $list\ == *\ $item\ * ]]
1851 #########################################################################
1852 # Generate a backtrace through the call stack.
1856 #########################################################################
1860 local funcname="" sourcefile="" lineno="" n
1862 echo "Call stack: (most recent first)"
1863 for (( n = $strip ; n < ${#FUNCNAME[@]} ; ++n )) ; do
1864 funcname=${FUNCNAME[$n - 1]}
1865 sourcefile=$(basename ${BASH_SOURCE[$n]})
1866 lineno=${BASH_LINENO[$n - 1]}
1870 # Display function arguments
1871 if [[ ! -z "${BASH_ARGV[@]}" ]]; then
1872 local args newarg j p=0
1873 for (( j = ${BASH_ARGC[$n - 1]}; j > 0; j-- )); do
1874 newarg=${BASH_ARGV[$j + $p - 1]}
1875 args="${args:+${args} }'${newarg}'"
1877 let p+=${BASH_ARGC[$n - 1]}
1879 echo " ${funcname} ${args:+${args} }at ${sourcefile}:${lineno}"
1883 echo "BEGIN BACKTRACE"
1885 #echo ${BASH_LINENO[*]}
1886 #echo ${BASH_SOURCE[*]}
1887 #echo ${FUNCNAME[*]}
1888 local i=$((${#FUNCNAME[@]} - 1))
1889 while [ $i -ge 0 ]; do
1890 local lineno=${BASH_LINENO[$i]}
1894 local SOURCELINE="${BASH_SOURCE[$i + 1]}:${lineno}"
1895 # Can't figure out how to get function args from other frames...
1896 local FUNCTION="${FUNCNAME[$i]}()"
1897 echo "$SOURCELINE:$FUNCTION"
1901 echo "END BACKTRACE"
1907 seen_list=$(new_list)
1909 echo "An unexpected error has occurred at ${BASH_SOURCE[0]##*/}:$((LINENO-1)).
1910 Unfortunately the above line number in the message may or may not be correct,
1911 but details have been send to the lbuild maintainer. Attempting to continue."; (echo "Untrapped error"
1913 # have we seen this one
1914 echo "checking seen list for ${BASH_SOURCE[0]}:${BASH_LINENO[0]}"
1916 if is_list_member "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}"; then
1917 echo "seen this one already"
1919 seen_list=$(add_list "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}")
1922 ) ; set $xtrace' ERR
1925 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
1927 options=$(getopt -o D:h -l kerneltree:,distro:,kernelrpm:,reusebuild:,\
1928 patchless,patchless-server,enable-kernel-debug,ccache,norpm,external-patches:,timestamp:,\
1929 extraversion:,kerneldir:,linux:,lustre:,nodownload,nosrc,noiokit,ofed-type:,\
1930 ofed-version:,mlnx-version:,ofed-src:,publish,disable-zfs,release,set-value:,\
1931 src,stage:,target:,with-linux:,xen -- "$@")
1933 if [ $? != 0 ]; then
1937 eval set -- "$options"
1968 if ! KERNELTREE=$(canon_path "$2"); then
1969 fatal 1 "Could not determine the canonical location of $2"
1973 --linux | --with-linux)
1974 if ! LINUX=$(canon_path "$2"); then
1975 fatal 1 "Could not determine the canonical location of $2"
1984 if ! REUSEBUILD=$(canon_path "$2"); then
1985 fatal 1 "Could not determine the canonical location of $2"
2001 PATCHLESS_SERVER=true
2004 --enable-kernel-debug)
2005 ENABLE_KERNEL_DEBUG=true
2009 if ! KERNELRPMSBASE=$(canon_path "$2"); then
2010 fatal 1 "Could not determine the canonical location of $2"
2019 if ! LUSTRE=$(canon_filepath "$2"); then
2020 fatal 1 "Could not determine the canonical location of $2"
2077 # there are actually some lustre configure flags that we need to
2078 # handle ourselves (but we still give them to configure)
2079 if [[ \ $@\ == *\ --disable-tests\ * ]]; then
2086 usage 1 "Unrecognized option: $1"
2097 if [ -n "$OFED_TYPE" -a "$OFED_TYPE" != "inkernel" ]; then
2098 download_ofed "$OFED_TYPE" "$OFED_VERSION"
2099 unpack_ofed "$OFED_TYPE" "$OFED_VERSION" || fatal 1 "Error unpacking OFED tarball"
2102 # make sure the RPM build environment is set up
2103 create_rpmbuild_dirs
2105 # if an unpacked kernel source tree was given on the command line
2106 # just build lustre with it (nothing distro kernel specific here)
2107 if [ -n "$LINUX" ]; then
2108 find_linux_release() {
2109 _find_linux_release $LINUX
2111 build_ofed "${LINUXOBJ:-$LINUX}" "$OFED_TYPE" "$OFED_VERSION" ||
2112 fatal 1 "error building OFED"
2113 build_lustre "$LINUX" "$LINUXOBJ"
2115 if [ ! -f "${LBUILD_DIR}/lbuild-$DISTROMAJ" ]; then
2116 fatal 1 "${LBUILD_DIR}/lbuild-$DISTROMAJ not found"
2118 source ${LBUILD_DIR}/lbuild-$DISTROMAJ
2119 build_with_srpm "$OFED_TYPE" "$OFED_VERSION" || fatal 1 "Failed to build_with_srpm"