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
419 echo $(echo "$*" | xargs -n 1 | sort -u)
427 if [ -z "$target" ]; then
428 fatal 1 "fetch_url() called without a target to fetch to"
431 if [ -d $target ]; then
432 target+="/${url##*/}"
436 if which wget >/dev/null 2>&1; then
437 if ! wget -nv "$url" -O "$target"; then
440 elif which curl >/dev/null 2>&1; then
441 if ! curl -n -L -s -o "$target" "$url"; then
445 fatal 1 "Could not find either wget or curl to fetch URLs."
455 local force="${3:-false}"
457 # let the download_file handle the concurrency
460 # get the location from a distro specific method if it exists
461 if type -p kernel_srpm_location; then
462 location=$(kernel_srpm_location)
464 fatal 1 "Must specify location for download kernel SRPM."
466 echo "Downloading $location/$srpm..."
468 "$location/$srpm" "$KERNELDIR/$srpm" "$force" 2>&1 ||
469 [ ! -s "$KERNELDIR/$srpm" ]; then
470 rm -f $KERNELDIR/$srpm
471 fatal 1 "Could not download target $target's kernel \
472 SRPM $srpm from $location."
477 download_debuginfo_common() {
479 local force="${2:-false}"
481 # let the download_file handle the concurrency
483 # get the location from a distro specific method if it exists
484 if type -p kernel_debuginfo_location; then
485 location=$(kernel_debuginfo_location)
487 echo "Downloading $location/$rpm"
489 "$location/$rpm" "$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$rpm" "$force" 2>&1 ||
490 [ ! -s "$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$rpm" ]; then
491 rm -f $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$rpm
492 fatal 1 "Could not download $rpm from $location."
502 local file=${from##*/}
508 local semaphore="$to-downloading"
511 if [ ! -f $semaphore ]; then
515 # make sure the download has not been aborted
516 local now=$(date +%s)
517 local file_mtime=$(stat -c %Y "$to")
518 local staleness=$((now - file_mtime))
519 # let's assume an active download will write at least once a minute
520 if [ $staleness -gt 60 ]; then
528 # if the semaphore file exists, the file is either still downloading
529 # or a download was aborted and we cannot trust the target file
530 if [ -f $semaphore ]; then
534 if ! is_downloading && [ -r "$to" ] && [ -s "$to" ]; then
541 if $force || ! is_downloaded; then
542 if is_downloading; then
543 echo "Somebody else is downloading $from..."
544 while is_downloading; do
545 echo "Waiting for $to to finish downloading"
548 if is_downloaded; then
551 echo "The download we were waiting for seems to have been aborted"
557 echo "Downloading $from..."
558 # flag others so they don't try to download also
559 push_exit_trap "rm -f $to $semaphore" "download"
561 if ! fetch_url "$from" "$to" || [ ! -s "$to" ]; then
562 # the trap will remove the files via the fatal below
563 fatal 1 "Could not download ${to##*/} from ${from%/*}/."
566 delete_exit_trap "download"
568 fatal 1 "${to##*/} not found in directory ${to%/*}."
578 local ofed_version="$2"
579 local force="${3:-false}"
580 local distro_name="${DISTRO}"
581 local arch="${TARGET_ARCH}"
585 #if a src tarball has been given in the command line, we use it
586 #The format of the tarball must be OFED-${OFED_VERSION}.tgz
587 [ -n "${OFED_SRC}" ] && return 0
591 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version}/"
593 if [[ $ofed_version = *-[rR][cC][0-9] ]]; then
594 ofed_version_loc=${ofed_version%%-[rR][cC][0-9]}
595 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version_loc}/"
598 if [[ $ofed_version = *-daily ]]; then
599 ofed_version=${ofed_version/-daily/}
600 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version}-daily/"
601 # find the filename for latest version
602 ofed_version=$(curl -1 -s "$location" | sed -nre "s/.*href=\"OFED-(${ofed_version//./\\.}-[0-9]{8}-[0-9]{4}).tgz.*$/\1/p" | tail -1)
603 if [ -z "$ofed_version" ]; then
604 fatal 1 "Could not determine the filename of the OFED snapshot from daily "
608 file="OFED-${ofed_version}.tgz"
609 download_file "$location/$file" "$KERNELTREE" "$force"
612 location="http://www.mellanox.com/downloads/ofed/MLNX_OFED-${ofed_version}"
613 # this is a work around for suse distro (sles11.3). what we need is
614 # sles11sp3. We really need to redesign how we use target and distro
615 [[ $distro_name =~ sles ]] && distro_name=${DISTRO/./sp}
616 if [[ $arch = "aarch64" ]]; then
617 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}alternate-${arch}.tgz"
619 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}-${arch}.tgz"
621 download_file "$location/$file" "$KERNELTREE" "$force"
624 location="http://downloadmirror.intel.com/24625/eng/"
625 file="IntelIB-Basic.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.${ofed_version}.tgz"
626 download_file "$location/$file" "$KERNELTREE" "$force"
629 fatal 1 "Error: unknown OFED type: $ofed_type"
632 # version might change due to detect daily version
633 OFED_VERSION=${ofed_version}
639 EXTRA_VERSION_save="$EXTRA_VERSION"
640 for patchesdir in "$EXTERNAL_PATCHES" \
641 "$TOPDIR/lustre/lustre/kernel_patches"; do
642 TARGET_FILE="$patchesdir/targets/$TARGET.target"
643 [ -r "$TARGET_FILE" ] && break
645 [ -r "$TARGET_FILE" ] || fatal 1 "Target $TARGET was not found."
647 echo "Loading target config file $TARGET.target..."
649 # if the caller specified an OFED_VERSION it should override whatever
650 # the target file specifies
651 local env_OFED_VERSION="$OFED_VERSION"
655 if [ -n "$env_OFED_VERSION" ]; then
656 OFED_VERSION="$env_OFED_VERSION"
659 # doesn't make any sense to build OFED for xen domX's
664 # XXX - set_rpm_smp_type is an ugly undeterministic hack. it needs to
665 # go away and the target just specify the $RPMSMPTYPE
666 [ -z "$RPMSMPTYPE" ] && set_rpm_smp_type
668 # CC might have been overwritten in TARGET_FILE
669 if [[ $CC != ccache\ * ]] && which "$CCACHE" &>/dev/null; then
670 export CCACHE && export CC="ccache $CC"
673 if [ ! "$KERNELTREE" = "" ] && [ -d "$KERNELTREE" ]; then
674 KERNELDIR="$KERNELTREE/${lnxmaj}"
675 [ -d "$KERNELDIR" ] || mkdir "$KERNELDIR"
678 # verify the series is available
679 if [ "$SERIES" ]; then
680 for series in $SERIES; do
681 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
682 [ -r "$patchesdir/series/$series" ] && continue 2
684 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."
688 # set the location of the .config file
694 if $ENABLE_KERNEL_DEBUG; then
695 if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config-debug ]; then
696 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH.config-debug"
699 if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config ]; then
700 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH.config"
704 local lnxrelnew=${lnxrel//-/_}
706 # remember the EXTRA_VERSION before we diddle it here
707 # XXX - we really should not diddle with any values read in from the
708 # target file. if we want to modify a value, we should create
710 PRISTINE_EXTRA_VERSION=$EXTRA_VERSION
712 if ! $PATCHLESS && [ ! -f "$CONFIG_FILE" ]; then
713 fatal 1 "Config file for target $TARGET missing from $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
716 if [ "$EXTRA_VERSION_save" ]; then
717 EXTRA_VERSION="$EXTRA_VERSION_save"
718 elif ! $RELEASE; then
719 # if there is no patch series, then this is not a lustre specific
720 # kernel. don't make it look like one
721 if $PATCHLESS || [ -n "$SERIES" ]; then
722 EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
725 # EXTRA_VERSION=${EXTRA_VERSION//-/_}
731 echo -n '--wildcards '
734 fatal 1 "tarflags(): File name argument missing."
746 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
755 local extractfile="$@"
757 echo "Untarring ${tarfile##*/}..."
758 tar $(tarflags "$tarfile") "$tarfile" $extractfile
764 local ofed_version="$2"
765 local distro_name="${DISTRO}"
766 local arch="${TARGET_ARCH}"
769 #if a src tarball has been given in the command line, we use it
770 #The format of the directory after untar MUST be in OFED-${version}
771 #even if it's from MLNX or IFS...or whatever
772 if [ -n "${OFED_SRC}" ]; then
773 if ! untar "$KERNELTREE/${OFED_SRC}"; then
776 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
781 file="OFED-${ofed_version}"
782 if ! untar "$KERNELTREE/${file}.tgz"; then
785 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
788 # this is a work around for suse distro (sles11.3). what we need is
789 # sles11sp3. We really need to redesign how we use target and distro
790 [[ $distro_name =~ sles ]] && distro_name=${DISTRO/./sp}
791 if [[ $arch = "aarch64" ]]; then
792 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}alternate-${arch}"
794 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}-${arch}"
796 # it's not important what distro we get the tarball since we only
797 # interest in the src
798 if ! untar "$KERNELTREE/${file}.tgz"; then
801 # we need to untar again to get the src since it's being
802 # wrapped inside the tarball
803 # There are cases where the source version is different
805 # (ie. MLNX_OFED_LINUX-2.3-1.0.1 but MLNX_OFED_SRC-2.3-1.0.0)
806 local src=$(ls ${file}/src/MLNX_OFED_SRC-${ofed_version%.*}*.tgz)
807 if ! untar "$src"; then
810 [ -d OFED ] || ln -sf MLNX_OFED_SRC-[0-9].[0-9]* OFED
811 [ -d OFED_RPMS ] || ln -sf ${file}/RPMS OFED_RPMS
814 file="IntelIB-Basic.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.${ofed_version}"
815 if ! untar "$KERNELTREE/${file}.tgz"; then
818 [ -d OFED ] || ln -sf $file/IntelIB-OFED.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.* OFED
819 ofed_version="$(cat OFED/Version)"
822 # version might change due to detect daily version
823 OFED_VERSION=${ofed_version}
828 untar "$LUSTRE" || fatal 1 "Error unpacking Lustre tarball"
829 [ -d lustre ] || ln -sf lustre-[0-9].[0-9]* lustre
835 local do_patch=${1:-true}
837 FULL_PATCH="$PWD/lustre-kernel-${TARGET}-${EXTRA_VERSION}.patch"
838 [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
839 $do_patch && pushd linux >/dev/null
840 for series in $SERIES; do
841 echo -n "Applying series $series:"
842 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
843 [ -r "$patchesdir/series/$series" ] || continue
844 SERIES_FILE="$patchesdir/series/$series"
845 for patch in $(<"$SERIES_FILE"); do
847 PATCH_FILE="$patchesdir/patches/$patch"
848 [ -r "$PATCH_FILE" ] || \
849 fatal 1 "Patch $patch does not exist in Lustre tree."
850 cat "$PATCH_FILE" >> "$FULL_PATCH" || {
852 fatal 1 "Error adding patch $patch to full patch."
855 patch -s -p1 < "$PATCH_FILE" 2>&1 || {
857 fatal 1 "Error applying patch $patch."
865 $do_patch && popd >/dev/null
866 echo "Full patch has been saved in ${FULL_PATCH##*/}."
873 local configure_args=""
877 pushd lustre >/dev/null
879 if ! build_lustre_dkms; then
880 popd >/dev/null # pushd lustre
884 echo "Building Lustre RPMs for: $TARGET_ARCH"
886 # If server we now build the spl and zfs modules against the lustre kernel.
887 # These are required prior to the building of lustre server. Client does
888 # not require spl/zfs. Use !PATCHLESS to indicate server which follows the
889 # line above so is at least consistant.
890 if [ $PATCHLESS == false ] && [ "x$WITH_ZFS" == "x" ]; then
891 if ! build_spl_zfs; then
892 popd >/dev/null # pushd lustre
898 configure_args="$configure_args --disable-server"
901 # ditto for the lustre-tests boolean
902 if ! $LUSTRE_TESTS; then
903 configure_args="$configure_args --disable-tests"
907 configure_args="$configure_args --disable-iokit"
910 if ! $OSDZFSRPM; then
911 configure_args="$configure_args --without-zfs"
914 if ! $OSDLDISKFSRPM; then
915 configure_args="$configure_args --disable-ldiskfs"
918 configure_args="$configure_args --with-linux=$linux"
919 configure_args="$configure_args ${linuxobj:+--with-linux-obj=$linuxobj}"
921 # allow environment setting to override ldiskfs series selection
922 [ -n "$LDISKFS_SERIES" ] && export LDISKFS_SERIES
924 ./configure $configure_args $CONFIGURE_FLAGS 2>&1 ||
925 fatal 1 "Error in configure."
927 if type -p apply_kmod_requires_conflicts; then
928 apply_kmod_requires_conflicts
932 fatal 1 "Error building rpms for $TARGET_ARCH."
934 # move RPMs into place where they are expected to be
935 mv -f *lustre*.${TARGET_ARCH}.rpm $TOPDIR/RPMS/${TARGET_ARCH}/
936 mv -f lustre-*.src.rpm $TOPDIR/SRPMS/
939 if type -p cleanup_rpmmacros; then
946 build_lustre_dkms() {
948 local ver=$(sed -n -e 's/^LUSTRE_VERSION = //p' LUSTRE-VERSION-FILE)
950 echo "Building Lustre DKMS RPMs for: $TARGET_ARCH"
951 ./configure --enable-dist || fatal 1 "Error in DKMS configure."
954 build_args="--without servers"
957 rpmbuild --define "_topdir $TOPDIR" $build_args -bs lustre-dkms.spec ||
958 fatal 1 "Error building DKMS .src.rpm for $TARGET_ARCH."
961 rpmbuild --define "_topdir $TOPDIR" $build_args \
962 --rebuild $TOPDIR/SRPMS/lustre-client-dkms-$ver-*.src.rpm ||
963 fatal 1 "Error building DKMS .rpm for $TARGET_ARCH."
965 rpmbuild --define="_topdir $TOPDIR" --with servers \
966 --with zfs --without ldiskfs -bs lustre-dkms.spec ||
967 fatal 1 "Error creating DKMS (zfs) .srpm for $TARGET_ARCH."
968 rpmbuild --define="_topdir $TOPDIR" --with servers \
969 --without zfs --with ldiskfs -bs lustre-dkms.spec ||
970 fatal 1 "Error creating DKMS (ldiskfs) .srpm for $TARGET_ARCH."
971 rpmbuild --define="_topdir $TOPDIR" --with servers \
972 --with zfs --with ldiskfs -bs lustre-dkms.spec ||
973 fatal 1 "Error creating DKMS (all) .srpm for $TARGET_ARCH."
975 rpmbuild --rebuild --define="_topdir $TOPDIR" --with servers \
976 --with zfs --without ldiskfs $TOPDIR/SRPMS/lustre-zfs-dkms-$ver-*.src.rpm ||
977 fatal 1 "Error building DKMS (zfs) .rpm for $TARGET_ARCH."
978 rpmbuild --rebuild --define="_topdir $TOPDIR" --with servers \
979 --without zfs --with ldiskfs $TOPDIR/SRPMS/lustre-ldiskfs-dkms-$ver-*.src.rpm ||
980 fatal 1 "Error building DKMS (ldiskfs) .rpm for $TARGET_ARCH."
981 rpmbuild --rebuild --define="_topdir $TOPDIR" --with servers \
982 --with zfs --with ldiskfs $TOPDIR/SRPMS/lustre-all-dkms-$ver-*.src.rpm ||
983 fatal 1 "Error building DKMS (all) .rpm for $TARGET_ARCH."
992 # Fetch spl/zfs from the git repo and prepare for lustre build
995 # SPLZFSGITREPO - URI of directory where spl.git and zfs.git are located
996 # SPLZFSTAG - Tag to checkout of clone repositories
997 # SPLZFSVER - Version to checkout of both (format zfs/spl-$SPLZFSVER)
999 # return 0 if successful, else 255
1001 # make sure the RPM build environment is set up
1003 create_rpmbuild_dirs
1006 # The spl/zfs spec files expect RPM_BUILD_ROOT to point to the root of the
1007 # destination for the rpms
1008 export RPM_BUILD_ROOT=$TOPDIR
1009 SPLZFSVER=${SPLZFSVER:-0.7.13}
1010 SPLZFSTAG=${SPLZFSTAG:-}
1011 # "spl zfs" prior to 0.8.0
1012 # "zfs" for 0.8.0 and later
1013 SPLZFSPKGS="spl zfs"
1015 # The files expect a kver to be set to the kernel version .
1016 local kver=$(find_linux_release)
1018 # build and install the spl and zfs (and -devel) RPMs for lustre to use
1021 for pkg in $SPLZFSPKGS; do
1025 # need to fetch the repo in order to build it.
1026 # default to github but allow override
1027 git clone -n ${SPLZFSGITREPO:-"https://github.com/zfsonlinux"}/$pkg.git $pkg 2>&1
1029 pushd $pkg || return 255
1031 if [ -n "$SPLZFSTAG" ]; then
1036 git checkout -b lbuild $tag || fatal 1 "Failed to checkout \"$tag\" for $pkg.git"
1038 # This differentiates between older zfs versions
1039 if [ -f $pkg-modules.spec.in ]; then
1042 speclist="$pkg.spec $rpmpkg.spec"
1044 rpmpkg=kmod-$pkg-devel
1046 speclist="$pkg.spec $pkg-kmod.spec $pkg-dkms.spec"
1049 sh autogen.sh || return 255
1051 if ! ./configure --with-linux=${LINUX} --with-linux-obj=${LINUXOBJ:-$LINUX} \
1052 ${spldir:+--with-spl="${spldir}"} 2>&1 ||
1053 ! make dist 2>&1; then
1059 ln -f $pkg/$pkg-*.tar.gz $TOPDIR/SOURCES ||
1060 error "failed to link $pkg/$pkg-*.tar.gz into $TOPDIR/SOURCES"
1061 if [ -f $pkg/scripts/kmodtool ]; then
1062 ln -f $pkg/scripts/kmodtool $TOPDIR/SOURCES/
1072 # set search dir for our own kmodtool to find correct
1074 export KERNELSOURCE=$(dirname ${LINUX})
1075 # Manually build rpms
1076 for spec in $speclist; do
1077 echo "Building RPMs from $pkg/$specdir/$spec"
1078 if ! rpmbuild $rpmb $pkg/$specdir/$spec \
1080 --define "_use_internal_dependency_generator 0" \
1081 --define "require_kdir ${LINUX}" \
1082 ${LINUXOBJ:+--define "require_kobj ${LINUXOBJ}"} \
1083 ${spldir:+--define "require_spldir ${spldir}"} \
1084 --define "kver $kver" \
1085 --define "kernels $kver" \
1086 --define "_tmppath /var/tmp" \
1087 --define "kernelbuildroot $TOPDIR/reused" \
1088 --define "_topdir $TOPDIR" 2>&1; then
1093 # We have built the rpms for the package. Now we need to extract the
1094 # contained files so we can build further things against them
1095 local rpms=$(ls -1 $TOPDIR/RPMS/*/$rpmpkg-*.rpm)
1097 # cpio only extract to pwd so we need to go there.
1100 for rpm in $rpms; do
1101 rpm2cpio $rpm | cpio -id
1104 if [ "$pkg" == "zfs" ]; then
1105 # We also need to extract both the zfs and zfs-devel rpms
1106 # the zfs rpm is needed because it has the actual libraries in
1107 # it and the zfs-devel rpm only has unversioned symlinks to the
1108 # libraries in the zfs rpm
1109 # this will all change one day when we have a libzfs rpm per
1110 # https://github.com/zfsonlinux/zfs/issues/2329
1111 # and it looks like it could be one day soon:
1112 # https://github.com/zfsonlinux/zfs/pull/2341
1113 local devel_rpms=$(ls -1 $TOPDIR/RPMS/*/{$pkg-devel,$pkg-$SPLZFSVER,lib*}-*.rpm)
1114 for rpm in $devel_rpms; do
1115 rpm2cpio $rpm | cpio -id
1117 CONFIGURE_FLAGS="--with-$pkg-devel=$TOPDIR ${CONFIGURE_FLAGS}"
1118 if [ -z "$spldir" ]; then
1119 # if spldir is empty, then we are only building ZFS and need to define SPL config flags
1120 CONFIGURE_FLAGS="--with-spl=$(ls -d $TOPDIR/usr/src/spl-*|tail -1) ${CONFIGURE_FLAGS}"
1121 CONFIGURE_FLAGS="--with-spl-obj=$(ls -d $TOPDIR/usr/src/$pkg-*/$kver*|tail -1) ${CONFIGURE_FLAGS}"
1123 elif [ "$pkg" == "spl" ]; then
1124 spldir="$(ls -d $TOPDIR/usr/src/spl-*|tail -1)"
1128 CONFIGURE_FLAGS="--with-$pkg=$(ls -d $TOPDIR/usr/src/$pkg-*|tail -1) ${CONFIGURE_FLAGS}"
1129 CONFIGURE_FLAGS="--with-$pkg-obj=$(ls -d $TOPDIR/usr/src/$pkg-*/$kver*|tail -1) ${CONFIGURE_FLAGS}"
1139 [ "$STAGEDIR" ] || return 0
1141 rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${TARGET_ARCH}"
1142 echo "${0##*/}: Copying RPMs into ${rpmdir}"
1143 mkdir -p "${rpmdir}"
1144 for rpm in $(ls RPMS/${TARGET_ARCH}/*.rpm RPMS/noarch/*.rpm); do
1145 cp -v $rpm "${rpmdir}"
1148 cp -v "$LUSTRE" "$STAGEDIR"
1152 set_rpm_smp_type() {
1154 local infact_arch="${TARGET_ARCH}"
1157 [ "$infact_arch" == "i586" ] && infact_arch="i686"
1160 for smp_type in $SMP_ARCHS; do
1161 [ $infact_arch == $smp_type ] && RPMSMPTYPE=smp && break
1164 for smp_type in $BIGSMP_ARCHS; do
1165 [ $infact_arch == $smp_type ] && RPMSMPTYPE=bigsmp && break
1168 for smp_type in $PPC64_ARCHS; do
1169 [ $infact_arch == $smp_type ] && RPMSMPTYPE=ppc64 && break
1172 for smp_type in $DEFAULT_ARCHS; do
1173 [ $infact_arch == $smp_type ] && RPMSMPTYPE=default && break
1178 # This function takes a linux include tree and digs out the linux release
1179 # from it. It is never called directly, only called from the distro
1180 # specific function find_linux_release() in lbuild-{rhel,sles}.
1181 _find_linux_release() {
1183 local LINUXRELEASEHEADER=""
1185 LINUXRELEASEHEADER=$SRC/include/linux/version.h
1186 if [ -s $SRC/include/generated/utsrelease.h ]; then
1187 LINUXRELEASEHEADER=$SRC/include/generated/utsrelease.h
1188 elif [ -s $SRC/include/linux/utsrelease.h ]; then
1189 LINUXRELEASEHEADER=$SRC/include/linux/utsrelease.h
1192 if [ ! -s $LINUXRELEASEHEADER ]; then
1193 fatal 1 "could not find UTS_RELEASE"
1196 sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' $LINUXRELEASEHEADER
1199 # unpack kernel(/source/devel) RPM
1201 unpack_linux_devel_rpm() {
1202 local kernelrpm="${1}"
1204 [ -f "$kernelrpm" ] || return 255
1205 [ -d $TOPDIR/reused ] || mkdir $TOPDIR/reused || return 255
1207 pushd $TOPDIR/reused &>/dev/null || return 255
1209 if ! rpm2cpio < "$kernelrpm" | cpio -id > /dev/null 2>&1; then
1213 # call a distro specific hook, if available
1214 if type -p unpack_linux_devel_rpm-$DISTROMAJ; then
1215 if ! unpack_linux_devel_rpm-$DISTROMAJ "$kernelrpm"; then
1222 find_linux_devel_paths $TOPDIR/reused
1230 local kib_prefix="$2"
1232 local ofed_type="${4}"
1233 local ofed_version="${5}"
1235 # build kernel-ib{,-devel}/compat-rdma{,-devel}
1238 local OFED_CORE="--with-core-mod --with-ipoib-mod --with-user_mad-mod \
1239 --with-user_access-mod --with-addr_trans-mod --with-innova-flex "
1240 local OFED_HARDWARE="--with-mlx4-mod --with-mlx4_en-mod \
1241 --with-srp-mod --with-iser-mod --with-isert-mod --with-mlx5-mod \
1244 # some I/B drivers are architecture dependent and kernel-ib's configure
1245 # does not figure it out for us ~sigh~
1246 case "$TARGET_ARCH" in
1248 OFED_HARDWARE="$OFED_HARDWARE --with-ehca-mod"
1252 # assume we are just rebuilding the SRPM
1253 local BUILD_TYPE=${BUILD_TYPE:-"--rebuild"}
1254 local SOURCE="${TOPDIR}/OFED/SRPMS/${kib_prefix}-*.src.rpm"
1256 # but switch to building from the SPEC if we need to apply patches
1257 if ls ${TOPDIR}/lustre/contrib/patches/ofed/* >/dev/null; then
1259 rpm --define "_topdir ${TOPDIR}" -ivh $SOURCE
1260 SOURCE="${TOPDIR}/SPECS/${kib_prefix}.spec"
1261 local file ed_fragment1 ed_fragment2 n=1
1262 for file in $(ls ${TOPDIR}/lustre/contrib/patches/ofed/*.patch 2>/dev/null); do
1263 ed_fragment1="$ed_fragment1
1264 Patch$n: ${file%%*/}"
1265 ed_fragment2="$ed_fragment2
1267 cp $file ${TOPDIR}/SOURCES
1270 for file in $(ls ${TOPDIR}/lustre/contrib/patches/ofed/*.ed 2>/dev/null); do
1271 # Only apply the ed-scripts that should be used for the canonical target
1272 # ed-files in ${TOPDIR}/lustre/contrib/patches/ofed/ have to follow the naming
1274 # <two-digits>-<descriptive-name>:<canonical_target_1>: ...:<canonical_target_N>.ed
1275 # To apply the same change to multiple canonical target simply specify
1276 # a list of colon separated canoncial target names in the file name.
1277 echo "$file" | grep -q -e ":${CANONICAL_TARGET}:" \
1278 -e ":${CANONICAL_TARGET}.ed$"
1279 if [ $? -eq 0 ] ; then
1280 ed_fragment3="$ed_fragment3
1286 if [ $n -gt 1 ]; then
1300 local linuxrelease=$(find_linux_release)
1301 # a place to change/add any unique config
1303 ofa|ifs) local K_SRC_OBJ="K_SRC_OBJ"
1304 if ! $RPMBUILD $BUILD_TYPE --define 'build_kernel_ib 1' \
1305 --define 'build_kernel_ib_devel 1' \
1306 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1307 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1308 --define "KVERSION ${linuxrelease}" \
1309 --define "$K_SRC ${linux}" \
1310 ${K_SRC_OBJ:+--define "$K_SRC_OBJ ${linux}"} \
1311 ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
1312 --define "configure_options --without-quilt $OFED_CORE $OFED_HARDWARE $OFED_ISCSI" \
1313 ${SOURCE} 2>&1; then
1314 fatal 1 "Error building ${kib_rpm}"
1318 if ! $RPMBUILD $BUILD_TYPE \
1319 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1320 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1321 --define "KVERSION ${linuxrelease}" \
1323 --define "$K_SRC ${linux}" \
1324 ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
1325 ${SOURCE} 2>&1; then
1326 fatal 1 "Error building ${kib_rpm}"
1328 # now that we have the kernel rpms, we need to lib rpms too
1329 # we don't have to rebuild since MOFED include the binaries
1330 cp -f OFED_RPMS/{libibmad-*,libibverbs-*,libibumad-*,librdmacm*,ibutils*,opensm-*}.${TARGET_ARCH}.rpm \
1331 ${TOPDIR}/RPMS/${TARGET_ARCH} || \
1332 fatal 1 "Failed to copy MOFED rpms"
1342 local signature="$4"
1343 local use_links="$5"
1350 local unique_id=$(hostname -s)
1351 if [ -z "$unique_id" ]; then
1352 fatal 1 "Failed to determine hostname."
1355 local finallocation="$location"/"$signature"/"$module"
1356 location="$location"/"$signature-${unique_id}"/"$module"
1357 mkdir -p "$location"
1358 # the cleanup script removes any directory that doesn't have a
1359 # .lastused, so let's try to prevent that as soon as we can
1360 # this solution still slightly racy with the cleanup script
1361 # but the race is a lot tighter now
1362 touch -t 197001010000 "$location/.lastused"
1363 ## use eval/echo here to make sure shell expansions are performed
1364 #if ! cp -a${linkflag} $(eval echo $articles) "$location"; then
1366 for article in $(eval echo $articles); do
1367 if ! cp -a${linkflag} "$article" "$location"; then
1368 error "Failed to copy \"$article\" to \"$location\" in store_for_reuse()"
1369 # rename the cache location so that it's not cached
1370 # product, but is around for analysis
1371 mv "$location"{,-bad-$(date +%s)} ||
1372 error "failed to clean up a failed cache attempt" \
1373 "in \"$location\" -- manual cleanup will be" \
1379 # flag the cache as complete (i.e. in case lbuild was previously
1380 # interrupted while caching)
1381 touch "$location/.lastused"
1383 # put the temporary location into the final location
1385 mkdir -p "${finallocation%/*}"
1386 mv "$location" "$finallocation"
1387 rmdir "${location%/*}"
1395 local use_links="${3:-false}"
1396 local signature="$4"
1398 if [ -n "$REUSEBUILD" ] && [ -d "$REUSEBUILD/$signature/$module" ]; then
1399 if [ ! -f "$REUSEBUILD/$signature/$module/.lastused" ]; then
1400 # the .lastused flag is populated at the end of the caching to
1401 # signal that the caching was completed. if that flag is not
1402 # there, then the cache is invalid (and should be removed in fact)
1403 mv "$REUSEBUILD/$signature/$module"{,-bad-$(date +%s)} ||
1404 fatal 1 "failed to clean up a bad cache in location $REUSEBUILD/$signature/$module\" -- manual cleanup will be necessary"
1408 # so that we know how stale this entry is
1409 touch $REUSEBUILD/$signature/$module/.lastused
1412 if ls $REUSEBUILD/$signature/$module/* >/dev/null 2>&1; then
1413 cp -al $REUSEBUILD/$signature/$module/* $dest/
1416 # copying is pretty heavy
1417 # cp -a $REUSEBUILD/$signature/$module/* $dest/
1418 # do some creative symlinking instead
1420 for dir in BUILD SRPMS SPECS; do
1421 if ls $REUSEBUILD/$signature/$module/$dir/* >/dev/null 2>&1; then
1422 ln -s $REUSEBUILD/$signature/$module/$dir/* $dest/$dir
1425 # sources have to be copied by file because we need SOURCES to
1426 # be a dir we can write into
1427 # could overrun ls's arg list here
1428 #ls $REUSEBUILD/$signature/$module/SOURCES/* |
1429 find $REUSEBUILD/$signature/$module/SOURCES/ -type f |
1430 xargs ln -t $dest/SOURCES -s
1432 # same for RPMS/* dirs
1433 # could overrun ls's arg list here
1434 #ls $REUSEBUILD/$signature/$module/RPMS/$TARGET_ARCH/* |
1436 for dir in $REUSEBUILD/$signature/$module/RPMS/*; do
1437 mkdir -p $dest/RPMS/${dir##*/}
1439 xargs ln -t $dest/RPMS/${dir##*/} -s
1451 if [[ $arch = i[3456]86 ]]; then
1459 build_kernel_with_srpm() {
1462 if [ -z "$outfd" ] || [ $outfd = 1 ]; then
1463 fatal 1 "You must supply a file descriptor to ${FUNCNAME[0]} and it cannot be 1"
1466 # need to generate the patch for this target
1467 do_patch_linux false >&${outfd} # sets global $FULL_PATCH (yeah, yuck)
1469 # get an md5sum of the kernel patch + config for reuse check
1472 local release_str="RELEASE=$RELEASE\n"
1475 if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1476 local REUSE_SIGNATURE=$({ echo -en $release_str;
1479 cat "$TARGET_FILE" |
1480 sed -e '/_VERSION=/s/_[0-9]*_g.*$//g';
1482 cat "$LBUILD_DIR/lbuild";
1483 cat "$LBUILD_DIR/lbuild-$DISTROMAJ"; } |
1484 md5sum | cut -d" " -f1)
1485 # see if we can link to the reuse pool
1486 # XXX - hrm. i'm not convinced this doesn't belong in the reuse
1488 local CAN_LINK_FOR_REUSE=false
1489 touch $REUSEBUILD/$$
1490 if cp -al $REUSEBUILD/$$ $TOPDIR/ 2>/dev/null; then
1491 CAN_LINK_FOR_REUSE=true
1496 # the extra version string to use for the kernel (which might be a reused
1498 local kernel_extra_version=""
1499 if ! $USE_BUILD_CACHE || ! reuse kernel "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1500 "$REUSE_SIGNATURE"; then
1501 # nothing cached, build from scratch
1502 echo "Downloading kernel SRPM" >&${outfd}
1503 download_srpm "$CANONICAL_TARGET" "$KERNEL_SRPM" >&${outfd}
1505 if ! rpm -ivh $KERNELDIR/$KERNEL_SRPM \
1506 --define "_topdir $TOPDIR" >&${outfd} 2>&1; then
1507 # should we clean this up or leave it for analysis?
1509 fatal 1 "Error installing kernel SRPM."
1512 # put the Lustre kernel patch into the RPM build tree
1513 cp $FULL_PATCH $TOPDIR/SOURCES/linux-${lnxmaj}-lustre.patch
1514 prepare_and_build_srpm >&${outfd} ||
1515 fatal 1 "failed to prepare_and_build_srpm"
1517 if [ -z "$REUSE_SIGNATURE" ]; then
1518 echo "No reuse signature was caculated so not storing the built kernel" >&${outfd}
1520 # store the resulting kernel RPM build tree for future use
1521 echo "Storing the built kernel for future reuse" >&${outfd}
1522 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,SRPMS,RPMS}" \
1523 "kernel" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1524 "$CAN_LINK_FOR_REUSE"; then
1525 error "Failed to store kernel RPMS for reuse"
1526 echo "unknown" >&${outfd}
1532 # figure out the EXTRA_VERSION of the kernel we built or are re-using
1534 if ! KERNEL_RPM=$(find_rpm "$TOPDIR/RPMS/$TARGET_ARCH/" provides "^kernel(-default)? ="); then
1535 fatal 1 "Failed to find a kernel RPM in $TOPDIR/RPMS/$TARGET_ARCH/"
1537 kernel_extra_version=$(rpm -q --queryformat "%{RELEASE}" -p $TOPDIR/RPMS/$TARGET_ARCH/$KERNEL_RPM)
1539 # should now have the following RPMs
1540 # $TOPDIR/RPMS/$arch/kernel-lustre-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1541 # $TOPDIR/RPMS/$arch/kernel-lustre-devel-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1542 # $TOPDIR/RPMS/$arch/kernel-lustre-headers-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1543 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-common-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1544 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1546 echo $kernel_extra_version
1554 # REUSEBUILD, USE_BUILD_CACHE
1559 local ofed_type="$2"
1560 local ofed_version="$3"
1567 if [ "$ofed_version" = "inkernel" ]; then
1568 # see if there is a distro specific override for this and use
1570 # XXX we need to better integrate a distro specific override with
1571 # the rest of this function so that all of the reuse cache
1572 # stuff is leveraged given that 80% of this function is reuse
1573 if type -p build_ofed-$DISTROMAJ; then
1575 ofed_location=$(build_ofed-$DISTROMAJ ${STDOUT})
1576 local rc=${PIPESTATUS[0]}
1577 CONFIGURE_FLAGS="--with-o2ib=${ofed_location} ${CONFIGURE_FLAGS}"
1584 mlnx) # no compat-rdma for mlnx as of 3.1
1585 kib_prefix="ofa_kernel"
1587 kib_rpm="${pre_prefix}${kib_prefix}"
1590 if compare_version $ofed_version 3.0; then
1591 kib_prefix="ofa_kernel"
1592 kib_rpm="${pre_prefix}${kib_prefix}"
1594 kib_prefix="compat-rdma"
1595 kib_rpm="compat-rdma"
1601 # build kernel-ib/compat-rdma
1602 if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1603 local REUSE_SIGNATURE=$({ echo "$ofed_version";
1604 echo "$(find_linux_release;
1605 echo "$BUILD_GEN")";
1606 cat "${linux}/include/linux/autoconf.h";
1607 cat "$LBUILD_DIR/lbuild";
1608 cat "$LBUILD_DIR/lbuild-$DISTROMAJ"; } |
1609 md5sum | cut -d" " -f1)
1610 # see if we can link to the reuse pool
1611 # XXX - hrm. i'm not convinced this doesn't belong in the reuse
1613 local CAN_LINK_FOR_REUSE=false
1614 touch $REUSEBUILD/$$
1615 if cp -al $REUSEBUILD/$$ $TOPDIR/; then
1616 CAN_LINK_FOR_REUSE=true
1621 if ! $USE_BUILD_CACHE || ! reuse ofed "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1622 "$REUSE_SIGNATURE"; then
1623 if [ -n "$REUSE_SIGNATURE" ]; then
1624 # stash away the existing built articles for a moment
1626 mv {BUILD,{S,}RPMS,S{OURCE,PEC}S} bak
1629 find . | cpio -pudlm ..
1633 create_rpmbuild_dirs
1636 build_kernel_ib "${linux}" "${pre_prefix}${kib_prefix}" "${kib_rpm}" "${ofed_type}"
1638 if [ -z "$REUSE_SIGNATURE" ]; then
1639 echo "No reuse signature was caculated so not storing the built ofed"
1641 # store the resulting RPM build tree for future use
1642 echo "Storing the built ofed for future reuse"
1643 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
1644 "ofed" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1645 "$CAN_LINK_FOR_REUSE"; then
1646 error "Failed to store OFED RPMS for reuse"
1650 # put the stuff we stashed away back
1655 pushd "$TOPDIR" >/dev/null
1656 rm -rf ${kib_rpm}-devel
1657 mkdir ${kib_rpm}-devel
1660 o2ib_location="$(pwd)/usr/src/${kib_prefix}"
1662 mlnx) # Prior to MOFED 3.1, we had to use build_kernel_ib=1 to
1663 # build devel rpm. not so after 3.1
1664 if compare_version $ofed_version 3.0; then
1665 rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version%%-*}-*.rpm)
1667 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-${ofed_version%%-*}-*.rpm)
1669 o2ib_location="${o2ib_location}/default"
1671 ofa) # Prior to OFA 3.18, we had to use build_kernel_ib=1 during configure,
1673 if compare_version $ofed_version 3.18; then
1674 rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version%%-*}-*.rpm)
1676 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-${ofed_version%%-*}-*.rpm)
1679 ifs) # ifs doesn't follow any convention (if any)
1680 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-*.rpm)
1684 if ! rpm2cpio < $rpm | cpio -id; then
1685 fatal 1 "could not unpack the $rpm."
1687 CONFIGURE_FLAGS="--with-o2ib=${o2ib_location} ${CONFIGURE_FLAGS}"
1693 local ofed_type="$1"
1694 local ofed_version="$2"
1697 if ! $PATCHLESS; then
1698 if $PATCHLESS_SERVER; then
1699 # need to find and unpack the vendor's own kernel-devel
1700 # for patchless server build
1701 if ! kernelrpm=$(find_linux_rpm "-$DEVEL_KERNEL_TYPE"); then
1702 fatal 1 "Could not find the kernel-$DEVEL_KERNEL_TYPE RPM in $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ"
1704 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm "$kernelrpm" "-"; then
1705 fatal 1 "Could not find the Linux tree in $kernelrpm"
1707 # download and unpack kernel-debuginfo-common (only in EL)
1708 if [[ $DISTROMAJ =~ rhel ]]; then
1709 local KERNEL_DEBUGINFO="kernel-debuginfo-common-${TARGET_ARCH}-${lnxmaj}-${lnxrel}.${TARGET_ARCH}.rpm"
1710 download_debuginfo_common "$KERNEL_DEBUGINFO"
1711 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm \
1712 "$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$KERNEL_DEBUGINFO"; then
1713 fatal 1 "Could not find the Linux debuginfo common rpm in $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$KERNEL_DEBUGINFO"
1717 local kernel_extra_version
1718 if ! kernel_extra_version=$(build_kernel_with_srpm ${STDOUT}); then
1719 fatal 1 "Failed to build the kernel from it's SRPM"
1722 local kernel_devel_rpm
1723 if ! kernel_devel_rpm=$(find_rpm "$TOPDIR/RPMS/${TARGET_ARCH}/" provides "^$(devel_kernel_name $KERNEL_LUSTRE_NAMING) ="); then
1724 fatal 1 "Failed to find a kernel development RPM in $TOPDIR/RPMS/${TARGET_ARCH}/"
1727 # install the -devel RPM in preparation for modules builds
1728 if ! lnxrel="$kernel_extra_version" unpack_linux_devel_rpm \
1729 "$TOPDIR/RPMS/${TARGET_ARCH}/$kernel_devel_rpm"; then
1730 fatal 1 "Could not find the Linux tree in $TOPDIR/RPMS/${TARGET_ARCH}/$kernel_devel_rpm"
1734 # need to find and unpack the vendor's own kernel-devel for patchless
1736 if ! kernelrpm=$(find_linux_rpm "-$DEVEL_KERNEL_TYPE"); then
1737 fatal 1 "Could not find the kernel-$DEVEL_KERNEL_TYPE RPM in $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ"
1739 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm "$kernelrpm" "-"; then
1740 fatal 1 "Could not find the Linux tree in $kernelrpm"
1744 # ~sigh~ have to make copies of and modify some of the rpm
1745 # infrastructure files so that find-requires can find our unpacked
1746 # kernel-devel artifacts
1747 cp $RPM_HELPERS_DIR/{symset-table,find-requires{,.ksyms}} .
1748 export FIND_REQUIRES="$(pwd)/find-requires"
1749 chmod 755 {symset-table,find-requires{,.ksyms}}
1751 tmp="${tmp//\//\\/}"
1752 ed find-requires <<EOF
1756 /|.*find-requires.ksyms/s/|/| bash -x/
1757 g/ [^ ]*\/\(find-requires\.ksyms\)/s// $tmp\/\1/g
1760 ed find-requires.ksyms <<EOF
1764 g/\/.*\/\(symset-table\)/s//$tmp\/\1/g
1765 g/\(\/usr\/src\/kernels\/\)/s//$tmp\/reused\1/g
1768 ed symset-table <<EOF
1772 g/\(\/boot\/\)/s//$tmp\/reused\1/g
1773 g/\(\/usr\/src\/kernels\/\)/s//$tmp\/reused\1/g
1777 build_ofed "${LINUXOBJ:-$LINUX}" "$ofed_type" "$ofed_version" ||
1778 fatal 1 "error building OFED"
1781 if build_lustre "$LINUX" "$LINUXOBJ"; then
1782 # the build worked. resolve any symlinked files (i.e. from reuse)
1783 # in RPMS/$arch to real files so that that that huge mess of
1784 # complication known as LTS can copy them yet somewhere else.
1785 # is it any wonder this whole process is so damn so? anyone ever
1786 # heard of hardlinks? it's this cool new thing that allows you save
1787 # tons of time and space by creating... well you can go read about
1788 # them if you have not heard about them yet.
1789 # can i say how much the implemenation of all of this really impedes
1792 for dir in RPMS/*; do
1794 for file in $(ls); do
1795 if [ -h $file ]; then
1802 # also, for i?86, make sure all of the RPMs are in RPMS/$TARGET_ARCH
1803 # as that's where LTS expects to find them
1804 for dir in RPMS/*; do
1805 if [ $dir = RPMS/$TARGET_ARCH ]; then
1810 if [ -n "$files" ]; then
1811 cp -al $files ../$TARGET_ARCH
1821 create_rpmbuild_dirs() {
1823 [ -d RPMS ] || mkdir RPMS
1824 [ -d RPMS/${TARGET_ARCH} ] || mkdir RPMS/${TARGET_ARCH}
1825 [ -d RPMS/noarch ] || mkdir RPMS/noarch
1826 [ -d BUILD ] || mkdir BUILD
1827 [ -d SOURCES ] || mkdir SOURCES
1828 [ -d SPECS ] || mkdir SPECS
1829 [ -d SRPMS ] || mkdir SRPMS
1851 [[ $list\ == *\ $item\ * ]]
1855 #########################################################################
1856 # Generate a backtrace through the call stack.
1860 #########################################################################
1864 local funcname="" sourcefile="" lineno="" n
1866 echo "Call stack: (most recent first)"
1867 for (( n = $strip ; n < ${#FUNCNAME[@]} ; ++n )) ; do
1868 funcname=${FUNCNAME[$n - 1]}
1869 sourcefile=$(basename ${BASH_SOURCE[$n]})
1870 lineno=${BASH_LINENO[$n - 1]}
1874 # Display function arguments
1875 if [[ ! -z "${BASH_ARGV[@]}" ]]; then
1876 local args newarg j p=0
1877 for (( j = ${BASH_ARGC[$n - 1]}; j > 0; j-- )); do
1878 newarg=${BASH_ARGV[$j + $p - 1]}
1879 args="${args:+${args} }'${newarg}'"
1881 let p+=${BASH_ARGC[$n - 1]}
1883 echo " ${funcname} ${args:+${args} }at ${sourcefile}:${lineno}"
1887 echo "BEGIN BACKTRACE"
1889 #echo ${BASH_LINENO[*]}
1890 #echo ${BASH_SOURCE[*]}
1891 #echo ${FUNCNAME[*]}
1892 local i=$((${#FUNCNAME[@]} - 1))
1893 while [ $i -ge 0 ]; do
1894 local lineno=${BASH_LINENO[$i]}
1898 local SOURCELINE="${BASH_SOURCE[$i + 1]}:${lineno}"
1899 # Can't figure out how to get function args from other frames...
1900 local FUNCTION="${FUNCNAME[$i]}()"
1901 echo "$SOURCELINE:$FUNCTION"
1905 echo "END BACKTRACE"
1911 seen_list=$(new_list)
1913 echo "An unexpected error has occurred at ${BASH_SOURCE[0]##*/}:$((LINENO-1)).
1914 Unfortunately the above line number in the message may or may not be correct,
1915 but details have been send to the lbuild maintainer. Attempting to continue."; (echo "Untrapped error"
1917 # have we seen this one
1918 echo "checking seen list for ${BASH_SOURCE[0]}:${BASH_LINENO[0]}"
1920 if is_list_member "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}"; then
1921 echo "seen this one already"
1923 seen_list=$(add_list "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}")
1926 ) ; set $xtrace' ERR
1929 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
1931 options=$(getopt -o D:h -l kerneltree:,distro:,kernelrpm:,reusebuild:,\
1932 patchless,patchless-server,enable-kernel-debug,ccache,norpm,external-patches:,timestamp:,\
1933 extraversion:,kerneldir:,linux:,lustre:,nodownload,nosrc,noiokit,ofed-type:,\
1934 ofed-version:,mlnx-version:,ofed-src:,publish,disable-zfs,release,set-value:,\
1935 src,stage:,target:,with-linux:,xen -- "$@")
1937 if [ $? != 0 ]; then
1941 eval set -- "$options"
1972 if ! KERNELTREE=$(canon_path "$2"); then
1973 fatal 1 "Could not determine the canonical location of $2"
1977 --linux | --with-linux)
1978 if ! LINUX=$(canon_path "$2"); then
1979 fatal 1 "Could not determine the canonical location of $2"
1988 if ! REUSEBUILD=$(canon_path "$2"); then
1989 fatal 1 "Could not determine the canonical location of $2"
2005 PATCHLESS_SERVER=true
2008 --enable-kernel-debug)
2009 ENABLE_KERNEL_DEBUG=true
2013 if ! KERNELRPMSBASE=$(canon_path "$2"); then
2014 fatal 1 "Could not determine the canonical location of $2"
2023 if ! LUSTRE=$(canon_filepath "$2"); then
2024 fatal 1 "Could not determine the canonical location of $2"
2081 # there are actually some lustre configure flags that we need to
2082 # handle ourselves (but we still give them to configure)
2083 if [[ \ $@\ == *\ --disable-tests\ * ]]; then
2090 usage 1 "Unrecognized option: $1"
2101 if [ -n "$OFED_TYPE" -a "$OFED_TYPE" != "inkernel" ]; then
2102 download_ofed "$OFED_TYPE" "$OFED_VERSION"
2103 unpack_ofed "$OFED_TYPE" "$OFED_VERSION" || fatal 1 "Error unpacking OFED tarball"
2106 # make sure the RPM build environment is set up
2107 create_rpmbuild_dirs
2109 # if an unpacked kernel source tree was given on the command line
2110 # just build lustre with it (nothing distro kernel specific here)
2111 if [ -n "$LINUX" ]; then
2112 find_linux_release() {
2113 _find_linux_release $LINUX
2115 build_ofed "${LINUXOBJ:-$LINUX}" "$OFED_TYPE" "$OFED_VERSION" ||
2116 fatal 1 "error building OFED"
2117 build_lustre "$LINUX" "$LINUXOBJ"
2119 if [ ! -f "${LBUILD_DIR}/lbuild-$DISTROMAJ" ]; then
2120 fatal 1 "${LBUILD_DIR}/lbuild-$DISTROMAJ not found"
2122 source ${LBUILD_DIR}/lbuild-$DISTROMAJ
2123 build_with_srpm "$OFED_TYPE" "$OFED_VERSION" || fatal 1 "Failed to build_with_srpm"