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
33 #BUILD_GEN=2 # bz19952: remove -lustre tag from kernel RPM names
34 #BUILD_GEN=3 # bz19975: enable the building of src.rpms by default
35 #BUILD_GEN=4 # bz22281: use the git hash in the kernel extra version
36 #BUILD_GEN=5 # TT-107: don't cache the BUILD dir
37 BUILD_GEN=6 # TT-1092: don't cache the BUILD dir, to rebuild external OFED
45 # XXX - some recent hacking has pretty much neutered this option.
46 # search through this file for "-bb" and see how many places
47 # simply don't account for this option
52 TARGET_ARCH="$(uname -m)"
53 # change default behavior to only build for the current arch
54 TARGET_ARCHS="$TARGET_ARCH"
55 TARGET_ARCHS_ALL="$TARGET_ARCH"
56 [ "$TARGET_ARCH" = "i686" ] && TARGET_ARCHS_ALL="i686 i586 i386"
61 TMPDIR=${TMPDIR:-"/var/tmp"}
65 # this is the dir that should be used to store reuse products
67 # should cached products be used or force rebuilding?
69 # what does this do exactly? does it imply no kernel build?
73 SMPTYPES="smp bigsmp default ''"
80 # default to not adding -lustre- into the kernel RPM package names
81 KERNEL_LUSTRE_NAMING=false
82 # default not use kabi check.
100 # not in the target file any more
103 # build the lustre-tests rpm?
112 # Readlink is not present on some older distributions: emulate it.
116 if [ -L "$path" ]; then
117 ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
126 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
128 --external-patches=EXTERNAL_PATCHES
129 Directory similar to lustre/lustre/kernel_patches/ that lbuild should
130 look for seres and config files in before looking in the lustre
133 --extraversion=EXTRAVERSION
134 Text to use for the rpm release and kernel extraversion.
136 --timestamp=TIMESTAMP
137 Date of building lustre in format YYYYMMDDhhmmss
140 Try to reuse old kernel builds from DIR
143 Path to distro kernel RPM collection
152 Build lustre client only
155 Which distro using. Autodetect by default
157 --kerneldir=KERNELDIR
158 Directory containing Linux source tarballs referenced by target
161 --kerneltree=KERNELTREE
162 Directory containing dirs with Linux source tarballs referenced by target
163 files. Dir names in format kernel version ('2.6.9', etc.)
165 --linux=LINUX --with-linux=LINUX
166 Directory of Linux kernel sources. When this option is used, only
167 Lustre modules and userspace are built.
170 Path to an existing lustre source tarball to use.
173 Do not try to download a kernel from downloads.hpdd.intel.com
176 Do not build a .src.rpm, a full kernel patch, or a patched kernel
180 Type of OFED to build with lustre: inkernel, ofa, mlnx, ifs
181 ofa: OpenFabrics Alliance
183 ifs: Intel True Scale Fabric
186 Version of external OFED to build with lustre
189 Version of external Mellanox OFED to build with lustre
192 Tarball for either OFED. Tarball must follow below format
193 OFED-<ofed-version>.tgz regardless of vendors
194 It's likely that you need to reconstruct the directory name
195 It must be placed under KERNELTREE directory
198 Build with ldiskfs support. (Deprecated, always true)
201 Do not build lustre-iokit RPM. Now true by default
207 Specifies that the files generated do not include timestamps, and
208 that this is an official release.
211 Build Lustre without ZFS.
214 Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
217 Directory used to stage packages for release. RPMs will be placed
218 more or less in DIR/<target>-<arch>, and the tarball will be
222 The name of the target to build. The available targets are listed
225 --target-archs=TARGET_ARCHS
226 A (space delimited) list of architectures to build. By default,
227 all of the archs supported by the TARGET will be built, in
228 addition to a .src.rpm. This option can limit those, for machines
229 that can only build certain archs or if you only want a certain
230 arch built (for testing, or a one-off kernel).
232 Also note that by using a non-"base" arch (eg, i386) only kernels
233 will be built - there will be no lustre-lite-utils package.
236 Builds a Xen domX kernel.
239 Sets a variable to a given value.
248 # canonicalize a relative path to a file
252 if [ ! -f "$PATH" ]; then
256 local FILE=${PATH##*/}
259 echo $(canon_path "$DIR")/$FILE
263 # canonicalize a relative path to a dir
267 if [ ! -d "$PATH" ]; then
271 pushd "$PATH" >/dev/null || return 1
281 if [ -z "$LUSTRE" -o ! -r "$LUSTRE" ]; then
282 usage 1 "Could not find Lustre source tarball '$LUSTRE'."
285 if [ -n "${OFED_SRC}" ]; then
286 if [ -z "${OFED_VERSION}" ]; then
287 usage 1 "Need to provide version for file ${OFED_SRC}."
289 if [ "${OFED_TYPE}" = "inkernel" ]; then
290 usage 1 "Need to provide ofed type for file ${OFED_SRC}."
293 if [ "${OFED_TYPE}" != "inkernel" -a -z "${OFED_VERSION}" ]; then
294 usage 1 "Need to provide version for $OFED_TYPE OFED"
297 if [ "${OFED_TYPE}" = "inkernel" -a -n "${OFED_VERSION}" ]; then
298 usage 1 "Can not specify version with inkernel OFED"
302 if [ -z "$DISTRO" ] ; then
303 DISTRO=$(autodetect_distro)
307 DISTROMAJ=${DISTRO%%.*}
309 [ -z "$TARGET" ] && TARGET=$(autodetect_target "$DISTRO")
311 if [ -z "$LINUX" ]; then
312 [ "$KERNELDIR" -o "$KERNELTREE" ] || \
313 usage 1 "A kernel directory must be specified with --kerneldir or --kerneltree."
315 [ -d "$KERNELDIR" -o -d "$KERNELTREE" ] || \
316 usage 1 "$KERNELDIR and $KERNELTREE are not a directory."
318 # TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
319 # [ -r "$TARGET_FILE" ] || \
320 # usage 1 "Target '$TARGET' was not found."
324 3.12-sles12 | 4.4-sles12)
325 CANONICAL_TARGET="sles12"
328 CANONICAL_TARGET="rhel7"
331 CANONICAL_TARGET="rhel6"
334 CANONICAL_TARGET="rhel5"
337 CANONICAL_TARGET="rhel-2.6"
340 CANONICAL_TARGET="sles-2.6"
343 CANONICAL_TARGET="sles10-2.6"
345 2.6-sles11 | 3.0-sles11)
346 CANONICAL_TARGET="sles11"
349 CANONICAL_TARGET="oel5"
352 CANONICAL_TARGET="hp-pnnl-2.4"
360 CANONICAL_TARGET="$TARGET"
364 local timestampnodig=$(echo $TIMESTAMP | sed -e s/[0-9]*//g)
365 [ "$timestampnodig" = "" ] || TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
366 local timestamplength="${#TIMESTAMP}"
367 if [ $timestamplength -eq 12 ]; then
368 TIMESTAMP="${TIMESTAMP}00"
369 elif [ $timestamplength -ne 14 ]; then
370 TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
373 RPMBUILD=$(which rpmbuild 2>/dev/null | head -n 1)
374 RPMBUILD=${RPMBUILD:-$(which rpm 2>/dev/null | head -n 1)}
375 if [ -z "$RPMBUILD" ]; then
376 usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
379 local BINDIR="$TOPDIR/bin"
380 if [ -d $BINDIR ]; then
381 rm -rf $BINDIR >/dev/null 2>&1 || true
384 mkdir -p $BINDIR || fatal 1 "error trying to create $BINDIR"
385 export PATH=$BINDIR:$PATH
387 cat >${BINDIR}/rpmbuild <<EOF
390 ARGS="\${FIND_REQUIRES:+--define \"__find_requires \$FIND_REQUIRES\"}"
393 *\'* ) ARGS="\$ARGS \"\$arg\"" ;;
394 * ) ARGS="\$ARGS '\$arg'" ;;
398 eval $RPMBUILD \$ARGS
400 chmod 755 ${BINDIR}/rpmbuild
402 if [ -n "$CCACHE" ]; then
403 which "$DISTCC" &>/dev/null && export DISTCC RPM_BUILD_NCPUS
405 if which "$CCACHE" &>/dev/null; then
406 local ccache=$(which "$CCACHE" 2>/dev/null | head -n 1)
408 ln -s "$ccache" ${BINDIR}/ccache
409 ln -s "$ccache" ${BINDIR}/cc
410 ln -s "$ccache" ${BINDIR}/$CC
413 export CC="ccache $CC"
414 # zero the cache so we can see how effective we are being with it
418 # get some ccache stats when we are done
419 push_exit_trap '[ -n "$CCACHE" ] && ccache -s' "ccache_summary"
420 # should remove the ccache trap if lbuild is interrupted
421 trap 'echo "Received an INT TERM or HUP signal, terminating."; delete_exit_trap "ccache_summary"; exit 1' INT TERM HUP
428 # compare two versions $1 and $2. if $1 < $2, return 0 otherwise return 1.
430 [[ $1 == $2 ]] && return 1
432 local i val1=($1) val2=($2)
434 # padding zero to val1 if it needs
435 for ((i=${#val1[@]}; i<${#val2[@]}; i++)); do
438 for ((i=0; i<${#val1[@]}; i++)); do
439 [[ -z ${val2[i]} ]] && return 1
441 if [[ ${val1[i]} < ${val2[i]} ]]; then
443 elif [[ ${val1[i]} > ${val2[i]} ]]; then
452 echo $(echo "$*" | xargs -n 1 | sort -u)
460 if [ -z "$target" ]; then
461 fatal 1 "fetch_url() called without a target to fetch to"
464 if [ -d $target ]; then
465 target+="/${url##*/}"
469 if which wget >/dev/null 2>&1; then
470 if ! wget -nv "$url" -O "$target"; then
473 elif which curl >/dev/null 2>&1; then
474 if ! curl -n -L -s -o "$target" "$url"; then
478 fatal 1 "Could not find either wget or curl to fetch URLs."
488 local force="${3:-false}"
490 # let the download_file handle the concurrency
493 "https://downloads.hpdd.intel.com/public/kernels/$target/old"
494 # get the location from a distro specific method if it exists
495 if type -p kernel_srpm_location; then
496 location=$(kernel_srpm_location)
498 echo "Downloading $location/$srpm..."
500 "$location/$srpm" "$KERNELDIR/$srpm" "$force" 2>&1 ||
501 [ ! -s "$KERNELDIR/$srpm" ]; then
502 rm -f $KERNELDIR/$srpm
503 fatal 1 "Could not download target $target's kernel \
504 SRPM $srpm from $location."
514 local file=${from##*/}
520 local semaphore="$to-downloading"
523 if [ ! -f $semaphore ]; then
527 # make sure the download has not been aborted
528 local now=$(date +%s)
529 local file_mtime=$(stat -c %Y "$to")
530 local staleness=$((now - file_mtime))
531 # let's assume an active download will write at least once a minute
532 if [ $staleness -gt 60 ]; then
540 # if the semaphore file exists, the file is either still downloading
541 # or a download was aborted and we cannot trust the target file
542 if [ -f $semaphore ]; then
546 if ! is_downloading && [ -r "$to" ] && [ -s "$to" ]; then
553 if $force || ! is_downloaded; then
554 if is_downloading; then
555 echo "Somebody else is downloading $from..."
556 while is_downloading; do
557 echo "Waiting for $to to finish downloading"
560 if is_downloaded; then
563 echo "The download we were waiting for seems to have been aborted"
569 echo "Downloading $from..."
570 # flag others so they don't try to download also
571 push_exit_trap "rm -f $to $semaphore" "download"
573 if ! fetch_url "$from" "$to" || [ ! -s "$to" ]; then
574 # the trap will remove the files via the fatal below
575 fatal 1 "Could not download ${to##*/} from ${from%/*}/."
578 delete_exit_trap "download"
580 fatal 1 "${to##*/} not found in directory ${to%/*}."
590 local ofed_version="$2"
591 local force="${3:-false}"
592 local distro_name="${DISTRO}"
593 local arch="${TARGET_ARCH}"
597 #if a src tarball has been given in the command line, we use it
598 #The format of the tarball must be OFED-${OFED_VERSION}.tgz
599 [ -n "${OFED_SRC}" ] && return 0
603 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version}/"
605 if [[ $ofed_version = *-[rR][cC][0-9] ]]; then
606 ofed_version_loc=${ofed_version%%-[rR][cC][0-9]}
607 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version_loc}/"
610 if [[ $ofed_version = *-daily ]]; then
611 ofed_version=${ofed_version/-daily/}
612 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version}-daily/"
613 # find the filename for latest version
614 ofed_version=$(curl -1 -s "$location" | sed -nre "s/.*href=\"OFED-(${ofed_version//./\\.}-[0-9]{8}-[0-9]{4}).tgz.*$/\1/p" | tail -1)
615 if [ -z "$ofed_version" ]; then
616 fatal 1 "Could not determine the filename of the OFED snapshot from daily "
620 file="OFED-${ofed_version}.tgz"
621 download_file "$location/$file" "$KERNELTREE" "$force"
624 location="http://www.mellanox.com/downloads/ofed/MLNX_OFED-${ofed_version}"
625 # this is a work around for suse distro (sles11.3). what we need is
626 # sles11sp3. We really need to redesign how we use target and distro
627 [[ $distro_name =~ sles ]] && distro_name=${DISTRO/./sp}
628 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 [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config ]; then
703 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH.config"
706 local lnxrelnew=${lnxrel//-/_}
708 # remember the EXTRA_VERSION before we diddle it here
709 # XXX - we really should not diddle with any values read in from the
710 # target file. if we want to modify a value, we should create
712 PRISTINE_EXTRA_VERSION=$EXTRA_VERSION
714 if ! $PATCHLESS && [ ! -f "$CONFIG_FILE" ]; then
715 fatal 1 "Config file for target $TARGET missing from $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
718 if [ "$EXTRA_VERSION_save" ]; then
719 EXTRA_VERSION="$EXTRA_VERSION_save"
720 elif ! $RELEASE; then
721 # if there is no patch series, then this is not a lustre specific
722 # kernel. don't make it look like one
723 if $PATCHLESS || [ -n "$SERIES" ]; then
724 EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
727 # EXTRA_VERSION=${EXTRA_VERSION//-/_}
729 ALL_ARCHS="$BASE_ARCHS $BIGMEM_ARCHS $BOOT_ARCHS $JENSEN_ARCHS $SMP_ARCHS $BIGSMP_ARCHS $PSERIES64_ARCHS $UP_ARCHS"
732 for arch in $(uniqify "$ALL_ARCHS"); do
733 if [ -z "$TARGET_ARCHS" ] ||
734 [[ \ $TARGET_ARCHS\ = *\ $arch\ * ]]; then
735 BUILD_ARCHS="$BUILD_ARCHS $arch"
738 [ "$BUILD_ARCHS" ] || usage 1 "No available target archs to build."
739 echo "Building for: $BUILD_ARCHS"
745 echo -n '--wildcards '
748 fatal 1 "tarflags(): File name argument missing."
760 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
769 local extractfile="$@"
771 echo "Untarring ${tarfile##*/}..."
772 tar $(tarflags "$tarfile") "$tarfile" $extractfile
778 local ofed_version="$2"
779 local distro_name="${DISTRO}"
780 local arch="${TARGET_ARCH}"
783 #if a src tarball has been given in the command line, we use it
784 #The format of the directory after untar MUST be in OFED-${version}
785 #even if it's from MLNX or IFS...or whatever
786 if [ -n "${OFED_SRC}" ]; then
787 if ! untar "$KERNELTREE/${OFED_SRC}"; then
790 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
795 file="OFED-${ofed_version}"
796 if ! untar "$KERNELTREE/${file}.tgz"; then
799 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
802 # this is a work around for suse distro (sles11.3). what we need is
803 # sles11sp3. We really need to redesign how we use target and distro
804 [[ $distro_name =~ sles ]] && distro_name=${DISTRO/./sp}
805 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}-${arch}"
807 # it's not important what distro we get the tarball since we only
808 # interest in the src
809 if ! untar "$KERNELTREE/${file}.tgz"; then
812 # we need to untar again to get the src since it's being
813 # wrapped inside the tarball
814 # There are cases where the source version is different
816 # (ie. MLNX_OFED_LINUX-2.3-1.0.1 but MLNX_OFED_SRC-2.3-1.0.0)
817 local src=$(ls ${file}/src/MLNX_OFED_SRC-${ofed_version%.*}*.tgz)
818 if ! untar "$src"; then
821 [ -d OFED ] || ln -sf MLNX_OFED_SRC-[0-9].[0-9]* OFED
824 file="IntelIB-Basic.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.${ofed_version}"
825 if ! untar "$KERNELTREE/${file}.tgz"; then
828 [ -d OFED ] || ln -sf $file/IntelIB-OFED.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.* OFED
829 ofed_version="$(cat OFED/Version)"
832 # version might change due to detect daily version
833 OFED_VERSION=${ofed_version}
838 untar "$LUSTRE" || fatal 1 "Error unpacking Lustre tarball"
839 [ -d lustre ] || ln -sf lustre-[0-9].[0-9]* lustre
845 local do_patch=${1:-true}
847 FULL_PATCH="$PWD/lustre-kernel-${TARGET}-${EXTRA_VERSION}.patch"
848 [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
849 $do_patch && pushd linux >/dev/null
850 for series in $SERIES; do
851 echo -n "Applying series $series:"
852 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
853 [ -r "$patchesdir/series/$series" ] || continue
854 SERIES_FILE="$patchesdir/series/$series"
855 for patch in $(<"$SERIES_FILE"); do
857 PATCH_FILE="$patchesdir/patches/$patch"
858 [ -r "$PATCH_FILE" ] || \
859 fatal 1 "Patch $patch does not exist in Lustre tree."
860 cat "$PATCH_FILE" >> "$FULL_PATCH" || {
862 fatal 1 "Error adding patch $patch to full patch."
865 patch -s -p1 < "$PATCH_FILE" 2>&1 || {
867 fatal 1 "Error applying patch $patch."
875 $do_patch && popd >/dev/null
876 echo "Full patch has been saved in ${FULL_PATCH##*/}."
883 local configure_args=""
887 pushd lustre >/dev/null
889 if ! build_lustre_dkms; then
890 popd >/dev/null # pushd lustre
894 echo "Building Lustre RPMs for: $BUILD_ARCHS..."
896 # If server we now build the spl and zfs modules against the lustre kernel.
897 # These are required prior to the building of lustre server. Client does
898 # not require spl/zfs. Use !PATCHLESS to indicate server which follows the
899 # line above so is at least consistant.
900 if [ $PATCHLESS == false ] && [ "x$WITH_ZFS" == "x" ]; then
901 if ! build_spl_zfs; then
902 popd >/dev/null # pushd lustre
908 configure_args="$configure_args --disable-server"
911 # ditto for the lustre-tests boolean
912 if ! $LUSTRE_TESTS; then
913 configure_args="$configure_args --disable-tests"
917 configure_args="$configure_args --disable-iokit"
920 if ! $OSDZFSRPM; then
921 configure_args="$configure_args --without-zfs"
924 if ! $OSDLDISKFSRPM; then
925 configure_args="$configure_args --disable-ldiskfs"
928 configure_args="$configure_args --with-linux=$linux"
929 configure_args="$configure_args ${linuxobj:+--with-linux-obj=$linuxobj}"
931 # allow environment setting to override ldiskfs series selection
932 [ -n "$LDISKFS_SERIES" ] && export LDISKFS_SERIES
934 ./configure $configure_args $CONFIGURE_FLAGS 2>&1 ||
935 fatal 1 "Error in configure."
937 if type -p apply_kmod_requires; then
942 fatal 1 "Error building rpms for $BUILD_ARCHS."
944 # move RPMs into place where they are expected to be
945 for arch in $BUILD_ARCHS; do
946 mv -f *lustre*.${arch}.rpm $TOPDIR/RPMS/${arch}/
948 mv -f lustre-*.src.rpm $TOPDIR/SRPMS/
951 if type -p cleanup_rpmmacros; then
958 # Only zfs Lustre DKMS Server is supported
959 build_lustre_dkms() {
961 local name_prefix="lustre"
962 local ver=$(sed -n -e 's/^LUSTRE_VERSION = //p' LUSTRE-VERSION-FILE)
964 echo "Building Lustre DKMS RPMs for: $BUILD_ARCHS..."
965 ./configure --enable-dist || fatal 1 "Error in DKMS configure."
968 build_args="--without servers"
969 name_prefix="lustre-client"
972 rpmbuild --define "_topdir $TOPDIR" $build_args -bs lustre-dkms.spec ||
973 fatal 1 "Error building DKMS .src.rpm for $BUILD_ARCHS."
974 rpmbuild --define "_topdir $TOPDIR" $build_args \
975 --rebuild $TOPDIR/SRPMS/$name_prefix-dkms-$ver-*.src.rpm ||
976 fatal 1 "Error building DKMS .rpm for $BUILD_ARCHS."
984 # Fetch spl/zfs from the git repo and prepare for lustre build
987 # SPLZFSGITREPO - URI of directory where spl.git and zfs.git are located
988 # SPLZFSTAG - Tag to checkout of clone repositories
989 # SPLZFSVER - Version to checkout of both (format zfs/spl-$SPLZFSVER)
991 # return 0 if successful, else 255
993 # make sure the RPM build environment is set up
998 # The spl/zfs spec files expect RPM_BUILD_ROOT to point to the root of the
999 # destination for the rpms
1000 export RPM_BUILD_ROOT=$TOPDIR
1001 SPLZFSVER=${SPLZFSVER:-0.7.1}
1002 SPLZFSTAG=${SPLZFSTAG:-}
1004 # The files expect a kver to be set to the kernel version .
1005 local kver=$(find_linux_release)
1007 # build and install the spl and zfs (and -devel) RPMs for lustre to use
1009 for pkg in spl zfs; do
1013 [ "$pkg" == "zfs" ] && spldir="$(ls -d $TOPDIR/usr/src/spl-*|tail -1)"
1015 # need to fetch the repo in order to build it.
1016 # default to github but allow override
1017 git clone -n ${SPLZFSGITREPO:-"https://github.com/zfsonlinux"}/$pkg.git $pkg 2>&1
1019 pushd $pkg || return 255
1021 if [ -n "$SPLZFSTAG" ]; then
1026 git checkout -b lbuild $tag || fatal 1 "Failed to checkout \"$tag\" for $pkg.git"
1028 # This differentiates between older zfs versions
1029 if [ -f $pkg-modules.spec.in ]; then
1032 speclist="$pkg.spec $rpmpkg.spec"
1034 rpmpkg=kmod-$pkg-devel
1036 speclist="$pkg.spec $pkg-kmod.spec $pkg-dkms.spec"
1039 sh autogen.sh || return 255
1041 if ! ./configure --with-linux=${LINUX} --with-linux-obj=${LINUXOBJ:-$LINUX} \
1042 ${spldir:+--with-spl="${spldir}"} 2>&1 ||
1043 ! make dist 2>&1; then
1049 ln -f $pkg/$pkg-*.tar.gz $TOPDIR/SOURCES ||
1050 error "failed to link $pkg/$pkg-*.tar.gz into $TOPDIR/SOURCES"
1051 if [ -f $pkg/scripts/kmodtool ]; then
1052 ln -f $pkg/scripts/kmodtool $TOPDIR/SOURCES/
1062 # set search dir for our own kmodtool to find correct
1064 export KERNELSOURCE=$(dirname ${LINUX})
1065 # Manually build rpms
1066 for spec in $speclist; do
1067 echo "Building RPMs from $pkg/$specdir/$spec"
1068 if ! rpmbuild $rpmb $pkg/$specdir/$spec \
1070 --define "_use_internal_dependency_generator 0" \
1071 --define "require_kdir ${LINUX}" \
1072 ${LINUXOBJ:+--define "require_kobj ${LINUXOBJ}"} \
1073 ${spldir:+--define "require_spldir ${spldir}"} \
1074 --define "kver $kver" \
1075 --define "kernels $kver" \
1076 --define "_tmppath /var/tmp" \
1077 --define "kernelbuildroot $TOPDIR/reused" \
1078 --define "_topdir $TOPDIR" 2>&1; then
1083 # We have built the rpms for the package. Now we need to extract the
1084 # contained files so we can build further things against them
1085 local rpms=$(ls -1 $TOPDIR/RPMS/*/$rpmpkg-*.rpm)
1087 # cpio only extract to pwd so we need to go there.
1090 for rpm in $rpms; do
1091 rpm2cpio $rpm | cpio -id
1094 if [ "$pkg" == "zfs" ]; then
1095 # We also need to extract both the zfs and zfs-devel rpms
1096 # the zfs rpm is needed because it has the actual libraries in
1097 # it and the zfs-devel rpm only has unversioned symlinks to the
1098 # libraries in the zfs rpm
1099 # this will all change one day when we have a libzfs rpm per
1100 # https://github.com/zfsonlinux/zfs/issues/2329
1101 # and it looks like it could be one day soon:
1102 # https://github.com/zfsonlinux/zfs/pull/2341
1103 local devel_rpms=$(ls -1 $TOPDIR/RPMS/*/{$pkg-devel,$pkg-$SPLZFSVER,lib*}-*.rpm)
1104 for rpm in $devel_rpms; do
1105 rpm2cpio $rpm | cpio -id
1107 CONFIGURE_FLAGS="--with-$pkg-devel=$TOPDIR ${CONFIGURE_FLAGS}"
1111 CONFIGURE_FLAGS="--with-$pkg=$(ls -d $TOPDIR/usr/src/$pkg-*|tail -1) ${CONFIGURE_FLAGS}"
1112 CONFIGURE_FLAGS="--with-$pkg-obj=$(ls -d $TOPDIR/usr/src/$pkg-*/$kver*|tail -1) ${CONFIGURE_FLAGS}"
1122 [ "$STAGEDIR" ] || return 0
1124 for arch in $BUILD_ARCHS; do
1125 rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${arch}"
1126 echo "${0##*/}: Copying RPMs into ${rpmdir}"
1127 mkdir -p "${rpmdir}"
1128 for rpm in $(ls RPMS/${arch}/*.rpm RPMS/noarch/*.rpm); do
1129 cp -v $rpm "${rpmdir}"
1133 cp -v "$LUSTRE" "$STAGEDIR"
1137 set_rpm_smp_type() {
1139 local infact_arch="${TARGET_ARCH}"
1142 [ "$infact_arch" == "i586" ] && infact_arch="i686"
1145 for smp_type in $SMP_ARCHS; do
1146 [ $infact_arch == $smp_type ] && RPMSMPTYPE=smp && break
1149 for smp_type in $BIGSMP_ARCHS; do
1150 [ $infact_arch == $smp_type ] && RPMSMPTYPE=bigsmp && break
1153 for smp_type in $PPC64_ARCHS; do
1154 [ $infact_arch == $smp_type ] && RPMSMPTYPE=ppc64 && break
1157 for smp_type in $DEFAULT_ARCHS; do
1158 [ $infact_arch == $smp_type ] && RPMSMPTYPE=default && break
1163 # This function takes a linux include tree and digs out the linux release
1164 # from it. It is never called directly, only called from the distro
1165 # specific function find_linux_release() in lbuild-{rhel,sles}.
1166 _find_linux_release() {
1168 local LINUXRELEASEHEADER=""
1170 LINUXRELEASEHEADER=$SRC/include/linux/version.h
1171 if [ -s $SRC/include/generated/utsrelease.h ]; then
1172 LINUXRELEASEHEADER=$SRC/include/generated/utsrelease.h
1173 elif [ -s $SRC/include/linux/utsrelease.h ]; then
1174 LINUXRELEASEHEADER=$SRC/include/linux/utsrelease.h
1177 if [ ! -s $LINUXRELEASEHEADER ]; then
1178 fatal 1 "could not find UTS_RELEASE"
1181 sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' $LINUXRELEASEHEADER
1184 # unpack kernel(/source/devel) RPM
1186 # This function and it's setting of $LINUX and $LINUXOBJ is a total hack that
1187 # needs to completely refactored. It completely ingores that $BUILD_ARCHS may
1188 # contain a list of arches for which rpmbuild commands (including the one for
1190 unpack_linux_devel_rpm() {
1191 local kernelrpm="${1}"
1193 [ -f "$kernelrpm" ] || return 255
1194 [ -d $TOPDIR/reused ] || mkdir $TOPDIR/reused || return 255
1196 pushd $TOPDIR/reused &>/dev/null || return 255
1198 if ! rpm2cpio < "$kernelrpm" | cpio -id > /dev/null 2>&1; then
1202 # call a distro specific hook, if available
1203 if type -p unpack_linux_devel_rpm-$DISTROMAJ; then
1204 if ! unpack_linux_devel_rpm-$DISTROMAJ "$kernelrpm"; then
1211 find_linux_devel_paths $TOPDIR/reused
1219 local kib_prefix="$2"
1221 local ofed_type="${4}"
1222 local ofed_version="${5}"
1224 # build kernel-ib{,-devel}/compat-rdma{,-devel}
1227 local OFED_CORE="--with-core-mod --with-ipoib-mod --with-user_mad-mod \
1228 --with-user_access-mod --with-addr_trans-mod --with-madeye-mod"
1229 local OFED_HARDWARE="--with-mthca-mod --with-mlx4-mod \
1230 --with-mlx4_en-mod --with-cxgb3-mod --with-mlx4_en-mod \
1231 --with-cxgb3-mod --with-nes-mod --with-mlx5-mod --with-cxgb4-mod \
1234 # Removing the check for older version support
1235 #if compare_version $OFED_VERSION 3.0; then
1236 #OFED_CORE="$OFED_CORE --with-madeye-mod --with-rds-mod"
1238 #OFED_HARDWARE="$OFED_HARDWARE --with-mlx5-mod --with-cxgb4-mod --with-ocrdma-mod --with-qib-mod"
1241 # some I/B drivers are architecture dependent and kernel-ib's configure
1242 # does not figure it out for us ~sigh~
1243 case "$TARGET_ARCH" in
1245 OFED_HARDWARE="$OFED_HARDWARE --with-ehca-mod"
1248 # we're no longer shipping the OFED iSCSI target
1249 #OFED_ISCSI="--with-srp-mod --with-srp-target-mod"
1250 OFED_ISCSI="--with-srp-mod"
1251 ## ISER module has no backport support as of OFED 1.5 (i.e. only builds on
1252 ##kernels >= 2.6.30)
1253 #if [[ $OFED_VERSION = 1.[0-4]* ]]; then
1254 # OFED_ISCSI="$OFED_ISCSI --with-iser-mod"
1257 # assume we are just rebuilding the SRPM
1258 local BUILD_TYPE=${BUILD_TYPE:-"--rebuild"}
1259 local SOURCE="${TOPDIR}/OFED/SRPMS/${kib_prefix}-*.src.rpm"
1261 # but switch to building from the SPEC if we need to apply patches
1262 if ls ${TOPDIR}/lustre/contrib/patches/ofed/* >/dev/null; then
1264 rpm --define "_topdir ${TOPDIR}" -ivh $SOURCE
1265 SOURCE="${TOPDIR}/SPECS/${kib_prefix}.spec"
1266 local file ed_fragment1 ed_fragment2 n=1
1267 for file in $(ls ${TOPDIR}/lustre/contrib/patches/ofed/*.patch); do
1268 ed_fragment1="$ed_fragment1
1269 Patch$n: ${file%%*/}"
1270 ed_fragment2="$ed_fragment2
1272 cp $file ${TOPDIR}/SOURCES
1275 for file in $(ls ${TOPDIR}/lustre/contrib/patches/ofed/*.ed); do
1276 # Only apply the ed-scripts that should be used for the canonical target
1277 # ed-files in ${TOPDIR}/lustre/contrib/patches/ofed/ have to follow the naming
1279 # <two-digits>-<descriptive-name>:<canonical_target_1>: ...:<canonical_target_N>.ed
1280 # To apply the same change to multiple canonical target simply specify
1281 # a list of colon separated canoncial target names in the file name.
1282 echo "$file" | grep -q -e ":${CANONICAL_TARGET}:" \
1283 -e ":${CANONICAL_TARGET}.ed$"
1284 if [ $? -eq 0 ] ; then
1285 ed_fragment3="$ed_fragment3
1291 if [ $n -gt 1 ]; then
1305 local linuxrelease=$(find_linux_release)
1306 # a place to change/add any unique config
1308 ofa|ifs) local K_SRC_OBJ="K_SRC_OBJ"
1309 if ! $RPMBUILD $BUILD_TYPE --define 'build_kernel_ib 1' \
1310 --define 'build_kernel_ib_devel 1' \
1311 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1312 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1313 --define "KVERSION ${linuxrelease}" \
1314 --define "$K_SRC ${linux}" \
1315 ${K_SRC_OBJ:+--define "$K_SRC_OBJ ${linux}"} \
1316 ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
1317 --define "configure_options --without-quilt $OFED_CORE $OFED_HARDWARE $OFED_ISCSI" \
1318 ${SOURCE} 2>&1; then
1319 fatal 1 "Error building ${kib_rpm}"
1323 if ! $RPMBUILD $BUILD_TYPE \
1324 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1325 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1326 --define "KVERSION ${linuxrelease}" \
1327 --define "$K_SRC ${linux}" \
1328 ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
1329 --define "configure_options --without-quilt $OFED_CORE $OFED_HARDWARE $OFED_ISCSI" \
1330 ${SOURCE} 2>&1; then
1331 fatal 1 "Error building ${kib_rpm}"
1342 local signature="$4"
1343 local use_links="$5"
1350 local default_iface=$(/sbin/ip route get 192.1.1.1 | sed -ne 's/.* dev \(.*\) * src .*/\1/p')
1351 if [ -z "$default_iface" ]; then
1352 fatal 1 "Failed to determine the default route interface"
1354 local unique_id=$(/sbin/ip addr show dev $default_iface | sed -ne '/ inet /s/ *inet \(.*\)\/.*/\1/p' | head -1)
1355 if [ -z "$unique_id" ]; then
1356 fatal 1 "Failed to determine a unique id from interface $default_interface"
1359 local finallocation="$location"/"$signature"/"$module"
1360 location="$location"/"$signature-${unique_id}"/"$module"
1361 mkdir -p "$location"
1362 # the cleanup script removes any directory that doesn't have a
1363 # .lastused, so let's try to prevent that as soon as we can
1364 # this solution still slightly racy with the cleanup script
1365 # but the race is a lot tighter now
1366 touch -t 197001010000 "$location/.lastused"
1367 ## use eval/echo here to make sure shell expansions are performed
1368 #if ! cp -a${linkflag} $(eval echo $articles) "$location"; then
1370 for article in $(eval echo $articles); do
1371 if ! cp -a${linkflag} "$article" "$location"; then
1372 error "Failed to copy \"$article\" to \"$location\" in store_for_reuse()"
1373 # rename the cache location so that it's not cached
1374 # product, but is around for analysis
1375 mv "$location"{,-bad-$(date +%s)} ||
1376 error "failed to clean up a failed cache attempt" \
1377 "in \"$location\" -- manual cleanup will be" \
1383 # flag the cache as complete (i.e. in case lbuild was previously
1384 # interrupted while caching)
1385 touch "$location/.lastused"
1387 # put the temporary location into the final location
1389 mkdir -p "${finallocation%/*}"
1390 mv "$location" "$finallocation"
1391 rmdir "${location%/*}"
1399 local use_links="${3:-false}"
1400 local signature="$4"
1402 if [ -n "$REUSEBUILD" ] && [ -d "$REUSEBUILD/$signature/$module" ]; then
1403 if [ ! -f "$REUSEBUILD/$signature/$module/.lastused" ]; then
1404 # the .lastused flag is populated at the end of the caching to
1405 # signal that the caching was completed. if that flag is not
1406 # there, then the cache is invalid (and should be removed in fact)
1407 mv "$REUSEBUILD/$signature/$module"{,-bad-$(date +%s)} ||
1408 fatal 1 "failed to clean up a bad cache in location $REUSEBUILD/$signature/$module\" -- manual cleanup will be necessary"
1412 # so that we know how stale this entry is
1413 touch $REUSEBUILD/$signature/$module/.lastused
1416 if ls $REUSEBUILD/$signature/$module/* >/dev/null 2>&1; then
1417 cp -al $REUSEBUILD/$signature/$module/* $dest/
1420 # copying is pretty heavy
1421 # cp -a $REUSEBUILD/$signature/$module/* $dest/
1422 # do some creative symlinking instead
1424 for dir in BUILD SRPMS SPECS; do
1425 if ls $REUSEBUILD/$signature/$module/$dir/* >/dev/null 2>&1; then
1426 ln -s $REUSEBUILD/$signature/$module/$dir/* $dest/$dir
1429 # sources have to be copied by file because we need SOURCES to
1430 # be a dir we can write into
1431 # could overrun ls's arg list here
1432 #ls $REUSEBUILD/$signature/$module/SOURCES/* |
1433 find $REUSEBUILD/$signature/$module/SOURCES/ -type f |
1434 xargs ln -t $dest/SOURCES -s
1436 # same for RPMS/* dirs
1437 # could overrun ls's arg list here
1438 #ls $REUSEBUILD/$signature/$module/RPMS/$TARGET_ARCH/* |
1440 for dir in $REUSEBUILD/$signature/$module/RPMS/*; do
1441 mkdir -p $dest/RPMS/${dir##*/}
1443 xargs ln -t $dest/RPMS/${dir##*/} -s
1455 if [[ $arch = i[3456]86 ]]; then
1463 build_kernel_with_srpm() {
1466 if [ -z "$outfd" ] || [ $outfd = 1 ]; then
1467 fatal 1 "You must supply a file descriptor to ${FUNCNAME[0]} and it cannot be 1"
1470 # need to generate the patch for this target
1471 do_patch_linux false >&${outfd} # sets global $FULL_PATCH (yeah, yuck)
1473 # get an md5sum of the kernel patch + config for reuse check
1474 # XXX really, there needs to be a signature and a CONFIG_FILE per arch
1478 local release_str="RELEASE=$RELEASE\n"
1481 if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1482 local REUSE_SIGNATURE=$({ echo -en $release_str;
1485 cat "$TARGET_FILE" |
1486 sed -e '/_VERSION=/s/_[0-9]*_g.*$//g';
1488 cat "$LBUILD_DIR/lbuild";
1489 cat "$LBUILD_DIR/lbuild-$DISTROMAJ"; } |
1490 md5sum | cut -d" " -f1)
1491 # see if we can link to the reuse pool
1492 # XXX - hrm. i'm not convinced this doesn't belong in the reuse
1494 local CAN_LINK_FOR_REUSE=false
1495 touch $REUSEBUILD/$$
1496 if cp -al $REUSEBUILD/$$ $TOPDIR/ 2>/dev/null; then
1497 CAN_LINK_FOR_REUSE=true
1502 # the extra version string to use for the kernel (which might be a reused
1504 local kernel_extra_version=""
1505 if ! $USE_BUILD_CACHE || ! reuse kernel "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1506 "$REUSE_SIGNATURE"; then
1507 # nothing cached, build from scratch
1508 echo "Downloading kernel SRPM" >&${outfd}
1509 download_srpm "$CANONICAL_TARGET" "$KERNEL_SRPM" >&${outfd}
1511 if ! rpm -ivh $KERNELDIR/$KERNEL_SRPM \
1512 --define "_topdir $TOPDIR" >&${outfd} 2>&1; then
1513 # should we clean this up or leave it for analysis?
1515 fatal 1 "Error installing kernel SRPM."
1518 # put the Lustre kernel patch into the RPM build tree
1519 cp $FULL_PATCH $TOPDIR/SOURCES/linux-${lnxmaj}-lustre.patch
1520 prepare_and_build_srpm >&${outfd} ||
1521 fatal 1 "failed to prepare_and_build_srpm"
1523 if [ -z "$REUSE_SIGNATURE" ]; then
1524 echo "No reuse signature was caculated so not storing the built kernel" >&${outfd}
1526 # store the resulting kernel RPM build tree for future use
1527 echo "Storing the built kernel for future reuse" >&${outfd}
1528 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,SRPMS,RPMS}" \
1529 "kernel" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1530 "$CAN_LINK_FOR_REUSE"; then
1531 error "Failed to store kernel RPMS for reuse"
1532 echo "unknown" >&${outfd}
1538 # figure out the EXTRA_VERSION of the kernel we built or are re-using
1540 if ! KERNEL_RPM=$(find_rpm "$TOPDIR/RPMS/$TARGET_ARCH/" provides "^kernel(-default)? ="); then
1541 fatal 1 "Failed to find a kernel RPM in $TOPDIR/RPMS/$TARGET_ARCH/"
1543 kernel_extra_version=$(rpm -q --queryformat "%{RELEASE}" -p $TOPDIR/RPMS/$TARGET_ARCH/$KERNEL_RPM)
1545 # should now have the following RPMs
1546 # $TOPDIR/RPMS/$arch/kernel-lustre-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1547 # $TOPDIR/RPMS/$arch/kernel-lustre-devel-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1548 # $TOPDIR/RPMS/$arch/kernel-lustre-headers-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1549 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-common-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1550 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1552 echo $kernel_extra_version
1560 # REUSEBUILD, USE_BUILD_CACHE
1565 local ofed_type="$2"
1566 local ofed_version="$3"
1573 if [ "$ofed_version" = "inkernel" ]; then
1574 # see if there is a distro specific override for this and use
1576 # XXX we need to better integrate a distro specific override with
1577 # the rest of this function so that all of the reuse cache
1578 # stuff is leveraged given that 80% of this function is reuse
1579 if type -p build_ofed-$DISTROMAJ; then
1581 ofed_location=$(build_ofed-$DISTROMAJ ${STDOUT})
1582 local rc=${PIPESTATUS[0]}
1583 CONFIGURE_FLAGS="--with-o2ib=${ofed_location} ${CONFIGURE_FLAGS}"
1590 mlnx) # no compat-rdma for mlnx as of 3.1
1591 kib_prefix="ofa_kernel"
1593 kib_rpm="${pre_prefix}${kib_prefix}"
1596 if compare_version $ofed_version 3.0; then
1597 kib_prefix="ofa_kernel"
1598 kib_rpm="${pre_prefix}${kib_prefix}"
1600 kib_prefix="compat-rdma"
1601 kib_rpm="compat-rdma"
1607 # build kernel-ib/compat-rdma
1608 if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1609 local REUSE_SIGNATURE=$({ echo "$ofed_version";
1610 echo "$(find_linux_release;
1611 echo "$BUILD_GEN")";
1612 cat "${linux}/include/linux/autoconf.h";
1613 cat "$LBUILD_DIR/lbuild";
1614 cat "$LBUILD_DIR/lbuild-$DISTROMAJ"; } |
1615 md5sum | cut -d" " -f1)
1616 # see if we can link to the reuse pool
1617 # XXX - hrm. i'm not convinced this doesn't belong in the reuse
1619 local CAN_LINK_FOR_REUSE=false
1620 touch $REUSEBUILD/$$
1621 if cp -al $REUSEBUILD/$$ $TOPDIR/; then
1622 CAN_LINK_FOR_REUSE=true
1627 if ! $USE_BUILD_CACHE || ! reuse ofed "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1628 "$REUSE_SIGNATURE"; then
1629 if [ -n "$REUSE_SIGNATURE" ]; then
1630 # stash away the existing built articles for a moment
1632 mv {BUILD,{S,}RPMS,S{OURCE,PEC}S} bak
1635 find . | cpio -pudlm ..
1639 create_rpmbuild_dirs
1642 build_kernel_ib "${linux}" "${pre_prefix}${kib_prefix}" "${kib_rpm}" "${ofed_type}"
1644 if [ -z "$REUSE_SIGNATURE" ]; then
1645 echo "No reuse signature was caculated so not storing the built ofed"
1647 # store the resulting RPM build tree for future use
1648 echo "Storing the built ofed for future reuse"
1649 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
1650 "ofed" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1651 "$CAN_LINK_FOR_REUSE"; then
1652 error "Failed to store OFED RPMS for reuse"
1656 # put the stuff we stashed away back
1661 pushd "$TOPDIR" >/dev/null
1662 rm -rf ${kib_rpm}-devel
1663 mkdir ${kib_rpm}-devel
1666 o2ib_location="$(pwd)/usr/src/${kib_prefix}"
1668 mlnx) # Prior to MOFED 3.1, we had to use build_kernel_ib=1 to
1669 # build devel rpm. not so after 3.1
1670 if compare_version $ofed_version 3.0; then
1671 rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version%%-*}-*.rpm)
1673 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-${ofed_version%%-*}-*.rpm)
1675 o2ib_location="${o2ib_location}/default"
1677 ofa) # Prior to OFA 3.18, we had to use build_kernel_ib=1 during configure,
1679 if compare_version $ofed_version 3.18; then
1680 rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version%%-*}-*.rpm)
1682 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-${ofed_version%%-*}-*.rpm)
1685 ifs) # ifs doesn't follow any convention (if any)
1686 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-*.rpm)
1690 if ! rpm2cpio < $rpm | cpio -id; then
1691 fatal 1 "could not unpack the $rpm."
1693 CONFIGURE_FLAGS="--with-o2ib=${o2ib_location} ${CONFIGURE_FLAGS}"
1699 local ofed_type="$1"
1700 local ofed_version="$2"
1702 if ! $PATCHLESS; then
1703 local kernel_extra_version
1704 if ! kernel_extra_version=$(build_kernel_with_srpm ${STDOUT}); then
1705 fatal 1 "Failed to build the kernel from it's SRPM"
1708 for arch in $BUILD_ARCHS; do
1709 local kernel_devel_rpm
1710 if ! kernel_devel_rpm=$(find_rpm "$TOPDIR/RPMS/$arch/" provides "^$(devel_kernel_name $KERNEL_LUSTRE_NAMING) ="); then
1711 fatal 1 "Failed to find a kernel development RPM in $TOPDIR/RPMS/$arch/"
1714 # install the -devel RPM in preparation for modules builds
1715 if ! lnxrel="$kernel_extra_version" unpack_linux_devel_rpm \
1716 "$TOPDIR/RPMS/$arch/$kernel_devel_rpm"; then
1717 fatal 1 "Could not find the Linux tree in $TOPDIR/RPMS/$arch/$kernel_devel_rpm"
1721 # need to find and unpack the vendor's own kernel-devel for patchless
1724 if ! kernelrpm=$(find_linux_rpm "-$DEVEL_KERNEL_TYPE"); then
1725 fatal 1 "Could not find the kernel-$DEVEL_KERNEL_TYPE RPM in $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ"
1727 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm "$kernelrpm" "-"; then
1728 fatal 1 "Could not find the Linux tree in $kernelrpm"
1732 # ~sigh~ have to make copies of and modify some of the rpm
1733 # infrastructure files so that find-requires can find our unpacked
1734 # kernel-devel artifacts
1735 cp $RPM_HELPERS_DIR/{symset-table,find-requires{,.ksyms}} .
1736 export FIND_REQUIRES="$(pwd)/find-requires"
1737 chmod 755 {symset-table,find-requires{,.ksyms}}
1739 tmp="${tmp//\//\\/}"
1740 ed find-requires <<EOF
1744 /|.*find-requires.ksyms/s/|/| bash -x/
1745 g/ [^ ]*\/\(find-requires\.ksyms\)/s// $tmp\/\1/g
1748 ed find-requires.ksyms <<EOF
1752 g/\/.*\/\(symset-table\)/s//$tmp\/\1/g
1753 g/\(\/usr\/src\/kernels\/\)/s//$tmp\/reused\1/g
1756 ed symset-table <<EOF
1760 g/\(\/boot\/\)/s//$tmp\/reused\1/g
1761 g/\(\/usr\/src\/kernels\/\)/s//$tmp\/reused\1/g
1765 build_ofed "${LINUXOBJ:-$LINUX}" "$ofed_type" "$ofed_version" ||
1766 fatal 1 "error building OFED"
1769 if build_lustre "$LINUX" "$LINUXOBJ"; then
1770 # the build worked. resolve any symlinked files (i.e. from reuse)
1771 # in RPMS/$arch to real files so that that that huge mess of
1772 # complication known as LTS can copy them yet somewhere else.
1773 # is it any wonder this whole process is so damn so? anyone ever
1774 # heard of hardlinks? it's this cool new thing that allows you save
1775 # tons of time and space by creating... well you can go read about
1776 # them if you have not heard about them yet.
1777 # can i say how much the implemenation of all of this really impedes
1780 for dir in RPMS/*; do
1782 for file in $(ls); do
1783 if [ -h $file ]; then
1790 # also, for i?86, make sure all of the RPMs are in RPMS/$TARGET_ARCH
1791 # as that's where LTS expects to find them
1792 for dir in RPMS/*; do
1793 if [ $dir = RPMS/$TARGET_ARCH ]; then
1798 if [ -n "$files" ]; then
1799 cp -al $files ../$TARGET_ARCH
1809 create_rpmbuild_dirs() {
1811 [ -d RPMS ] || mkdir RPMS
1812 for arch in $BUILD_ARCHS; do
1813 if [[ $arch = i?86 ]]; then
1814 # some stupidity in the sles11 kernel spec requires an RPMS/i386
1815 # even if the target arch is i686
1816 [ -d RPMS/i386 ] || mkdir RPMS/i386
1818 [ -d RPMS/$arch ] || mkdir RPMS/$arch
1820 [ -d RPMS/noarch ] || mkdir RPMS/noarch
1821 [ -d BUILD ] || mkdir BUILD
1822 [ -d SOURCES ] || mkdir SOURCES
1823 [ -d SPECS ] || mkdir SPECS
1824 [ -d SRPMS ] || mkdir SRPMS
1846 [[ $list\ == *\ $item\ * ]]
1850 #########################################################################
1851 # Generate a backtrace through the call stack.
1855 #########################################################################
1859 local funcname="" sourcefile="" lineno="" n
1861 echo "Call stack: (most recent first)"
1862 for (( n = $strip ; n < ${#FUNCNAME[@]} ; ++n )) ; do
1863 funcname=${FUNCNAME[$n - 1]}
1864 sourcefile=$(basename ${BASH_SOURCE[$n]})
1865 lineno=${BASH_LINENO[$n - 1]}
1869 # Display function arguments
1870 if [[ ! -z "${BASH_ARGV[@]}" ]]; then
1871 local args newarg j p=0
1872 for (( j = ${BASH_ARGC[$n - 1]}; j > 0; j-- )); do
1873 newarg=${BASH_ARGV[$j + $p - 1]}
1874 args="${args:+${args} }'${newarg}'"
1876 let p+=${BASH_ARGC[$n - 1]}
1878 echo " ${funcname} ${args:+${args} }at ${sourcefile}:${lineno}"
1882 echo "BEGIN BACKTRACE"
1884 #echo ${BASH_LINENO[*]}
1885 #echo ${BASH_SOURCE[*]}
1886 #echo ${FUNCNAME[*]}
1887 local i=$((${#FUNCNAME[@]} - 1))
1888 while [ $i -ge 0 ]; do
1889 local lineno=${BASH_LINENO[$i]}
1893 local SOURCELINE="${BASH_SOURCE[$i + 1]}:${lineno}"
1894 # Can't figure out how to get function args from other frames...
1895 local FUNCTION="${FUNCNAME[$i]}()"
1896 echo "$SOURCELINE:$FUNCTION"
1900 echo "END BACKTRACE"
1906 seen_list=$(new_list)
1908 echo "An unexpected error has occurred at ${BASH_SOURCE[0]##*/}:$((LINENO-1)).
1909 Unfortunately the above line number in the message may or may not be correct,
1910 but details have been send to the lbuild maintainer. Attempting to continue."; (echo "Untrapped error"
1912 # have we seen this one
1913 echo "checking seen list for ${BASH_SOURCE[0]}:${BASH_LINENO[0]}"
1915 if is_list_member "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}"; then
1916 echo "seen this one already"
1918 seen_list=$(add_list "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}")
1921 ) ; set $xtrace' ERR
1924 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
1926 options=$(getopt -o D:h -l kerneltree:,distro:,kernelrpm:,reusebuild:,patchless,ccache,norpm,external-patches:,timestamp:,extraversion:,kerneldir:,linux:,lustre:,nodownload,nosrc,noiokit,ofed-type:,ofed-version:,mlnx-version:,ofed-src:,publish,disable-zfs,release,set-value:,src,stage:,target:,target-archs:,with-linux:,xen -- "$@")
1928 if [ $? != 0 ]; then
1932 eval set -- "$options"
1963 if ! KERNELTREE=$(canon_path "$2"); then
1964 fatal 1 "Could not determine the canonical location of $2"
1968 --linux | --with-linux)
1969 if ! LINUX=$(canon_path "$2"); then
1970 fatal 1 "Could not determine the canonical location of $2"
1979 if ! REUSEBUILD=$(canon_path "$2"); then
1980 fatal 1 "Could not determine the canonical location of $2"
1996 if ! KERNELRPMSBASE=$(canon_path "$2"); then
1997 fatal 1 "Could not determine the canonical location of $2"
2006 if ! LUSTRE=$(canon_filepath "$2"); then
2007 fatal 1 "Could not determine the canonical location of $2"
2068 # there are actually some lustre configure flags that we need to
2069 # handle ourselves (but we still give them to configure)
2070 if [[ \ $@\ == *\ --disable-tests\ * ]]; then
2077 usage 1 "Unrecognized option: $1"
2088 if [ -n "$OFED_TYPE" -a "$OFED_TYPE" != "inkernel" ]; then
2089 download_ofed "$OFED_TYPE" "$OFED_VERSION"
2090 unpack_ofed "$OFED_TYPE" "$OFED_VERSION" || fatal 1 "Error unpacking OFED tarball"
2093 # make sure the RPM build environment is set up
2094 create_rpmbuild_dirs
2096 # if an unpacked kernel source tree was given on the command line
2097 # just build lustre with it (nothing distro kernel specific here)
2098 if [ -n "$LINUX" ]; then
2099 find_linux_release() {
2100 _find_linux_release $LINUX
2102 build_ofed "${LINUXOBJ:-$LINUX}" "$OFED_TYPE" "$OFED_VERSION" ||
2103 fatal 1 "error building OFED"
2104 build_lustre "$LINUX" "$LINUXOBJ"
2106 if [ ! -f "${LBUILD_DIR}/lbuild-$DISTROMAJ" ]; then
2107 fatal 1 "${LBUILD_DIR}/lbuild-$DISTROMAJ not found"
2109 source ${LBUILD_DIR}/lbuild-$DISTROMAJ
2110 build_with_srpm "$OFED_TYPE" "$OFED_VERSION" || fatal 1 "Failed to build_with_srpm"