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 # default not use kabi check.
92 # not in the target file any more
95 # build the lustre-tests rpm?
104 # Readlink is not present on some older distributions: emulate it.
108 if [ -L "$path" ]; then
109 ll="$(LC_ALL=C ls -l "$path" 2> /dev/null)" &&
118 Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
120 --external-patches=EXTERNAL_PATCHES
121 Directory similar to lustre/lustre/kernel_patches/ that lbuild should
122 look for seres and config files in before looking in the lustre
125 --extraversion=EXTRAVERSION
126 Text to use for the rpm release and kernel extraversion.
128 --timestamp=TIMESTAMP
129 Date of building lustre in format YYYYMMDDhhmmss
132 Try to reuse old kernel builds from DIR
135 Path to distro kernel RPM collection
144 Build lustre client only
147 Build lustre server without patching the kernel
150 Which distro using. Autodetect by default
152 --kerneldir=KERNELDIR
153 Directory containing Linux source tarballs referenced by target
156 --kerneltree=KERNELTREE
157 Directory containing dirs with Linux source tarballs referenced by target
158 files. Dir names in format kernel version ('2.6.9', etc.)
160 --linux=LINUX --with-linux=LINUX
161 Directory of Linux kernel sources. When this option is used, only
162 Lustre modules and userspace are built.
165 Path to an existing lustre source tarball to use.
168 Do not try to download a kernel from downloads.whamcloud.com
171 Do not build a .src.rpm, a full kernel patch, or a patched kernel
175 Type of OFED to build with lustre: inkernel, ofa, mlnx, ifs
176 ofa: OpenFabrics Alliance
178 ifs: Intel True Scale Fabric
181 Version of external OFED to build with lustre
184 Version of external Mellanox OFED to build with lustre
187 Tarball for either OFED. Tarball must follow below format
188 OFED-<ofed-version>.tgz regardless of vendors
189 It's likely that you need to reconstruct the directory name
190 It must be placed under KERNELTREE directory
193 Build with ldiskfs support. (Deprecated, always true)
196 Do not build lustre-iokit RPM. Now true by default
202 Specifies that the files generated do not include timestamps, and
203 that this is an official release.
206 Build Lustre without ZFS.
209 Build a .src.rpm, a full kernel patch, and a patched kernel tarball.
212 Directory used to stage packages for release. RPMs will be placed
213 more or less in DIR/<target>-<arch>, and the tarball will be
217 The name of the target to build. The available targets are listed
221 Builds a Xen domX kernel.
224 Sets a variable to a given value.
233 # canonicalize a relative path to a file
237 if [ ! -f "$PATH" ]; then
241 local FILE=${PATH##*/}
244 echo $(canon_path "$DIR")/$FILE
248 # canonicalize a relative path to a dir
252 if [ ! -d "$PATH" ]; then
256 pushd "$PATH" >/dev/null || return 1
266 if [ -z "$LUSTRE" -o ! -r "$LUSTRE" ]; then
267 usage 1 "Could not find Lustre source tarball '$LUSTRE'."
270 if $PATCHLESS && $PATCHLESS_SERVER; then
271 usage 1 "Can not use both --patchless and --patchless-server."
274 if [ -n "${OFED_SRC}" ]; then
275 if [ -z "${OFED_VERSION}" ]; then
276 usage 1 "Need to provide version for file ${OFED_SRC}."
278 if [ "${OFED_TYPE}" = "inkernel" ]; then
279 usage 1 "Need to provide ofed type for file ${OFED_SRC}."
282 if [ "${OFED_TYPE}" != "inkernel" -a -z "${OFED_VERSION}" ]; then
283 usage 1 "Need to provide version for $OFED_TYPE OFED"
286 if [ "${OFED_TYPE}" = "inkernel" -a -n "${OFED_VERSION}" ]; then
287 usage 1 "Can not specify version with inkernel OFED"
291 if [ -z "$DISTRO" ] ; then
292 DISTRO=$(autodetect_distro)
296 DISTROMAJ=${DISTRO%%.*}
298 [ -z "$TARGET" ] && TARGET=$(autodetect_target "$DISTRO")
300 if [ -z "$LINUX" ]; then
301 [ "$KERNELDIR" -o "$KERNELTREE" ] || \
302 usage 1 "A kernel directory must be specified with --kerneldir or --kerneltree."
304 [ -d "$KERNELDIR" -o -d "$KERNELTREE" ] || \
305 usage 1 "$KERNELDIR and $KERNELTREE are not a directory."
307 # TARGET_FILE="$TOPDIR/lustre/kernel_patches/targets/$TARGET.target"
308 # [ -r "$TARGET_FILE" ] || \
309 # usage 1 "Target '$TARGET' was not found."
313 3.12-sles12 | 4.4-sles12)
314 CANONICAL_TARGET="sles12"
317 CANONICAL_TARGET="rhel7"
320 CANONICAL_TARGET="rhel6"
323 CANONICAL_TARGET="rhel5"
326 CANONICAL_TARGET="rhel-2.6"
329 CANONICAL_TARGET="sles-2.6"
332 CANONICAL_TARGET="sles10-2.6"
334 2.6-sles11 | 3.0-sles11)
335 CANONICAL_TARGET="sles11"
338 CANONICAL_TARGET="oel5"
341 CANONICAL_TARGET="hp-pnnl-2.4"
349 CANONICAL_TARGET="$TARGET"
353 local timestampnodig=$(echo $TIMESTAMP | sed -e s/[0-9]*//g)
354 [ "$timestampnodig" = "" ] || TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
355 local timestamplength="${#TIMESTAMP}"
356 if [ $timestamplength -eq 12 ]; then
357 TIMESTAMP="${TIMESTAMP}00"
358 elif [ $timestamplength -ne 14 ]; then
359 TIMESTAMP=$(date -d "$DATE" "+%Y%m%d%H%M%S")
362 RPMBUILD=$(which rpmbuild 2>/dev/null | head -n 1)
363 RPMBUILD=${RPMBUILD:-$(which rpm 2>/dev/null | head -n 1)}
364 if [ -z "$RPMBUILD" ]; then
365 usage 1 "Could not find binary for making rpms (tried rpmbuild and rpm)."
368 local BINDIR="$TOPDIR/bin"
369 if [ -d $BINDIR ]; then
370 rm -rf $BINDIR >/dev/null 2>&1 || true
373 mkdir -p $BINDIR || fatal 1 "error trying to create $BINDIR"
374 export PATH=$BINDIR:$PATH
376 cat >${BINDIR}/rpmbuild <<EOF
379 ARGS="\${FIND_REQUIRES:+--define \"__find_requires \$FIND_REQUIRES\"}"
382 *\'* ) ARGS="\$ARGS \"\$arg\"" ;;
383 * ) ARGS="\$ARGS '\$arg'" ;;
387 eval $RPMBUILD \$ARGS
389 chmod 755 ${BINDIR}/rpmbuild
391 if [ -n "$CCACHE" ]; then
392 which "$DISTCC" &>/dev/null && export DISTCC RPM_BUILD_NCPUS
394 if which "$CCACHE" &>/dev/null; then
395 local ccache=$(which "$CCACHE" 2>/dev/null | head -n 1)
397 ln -s "$ccache" ${BINDIR}/ccache
398 ln -s "$ccache" ${BINDIR}/cc
399 ln -s "$ccache" ${BINDIR}/$CC
402 export CC="ccache $CC"
403 # zero the cache so we can see how effective we are being with it
407 # get some ccache stats when we are done
408 push_exit_trap '[ -n "$CCACHE" ] && ccache -s' "ccache_summary"
409 # should remove the ccache trap if lbuild is interrupted
410 trap 'echo "Received an INT TERM or HUP signal, terminating."; delete_exit_trap "ccache_summary"; exit 1' INT TERM HUP
417 # compare two versions $1 and $2. if $1 < $2, return 0 otherwise return 1.
419 [[ $1 == $2 ]] && return 1
421 local i val1=($1) val2=($2)
423 # padding zero to val1 if it needs
424 for ((i=${#val1[@]}; i<${#val2[@]}; i++)); do
427 for ((i=0; i<${#val1[@]}; i++)); do
428 [[ -z ${val2[i]} ]] && return 1
430 if [[ ${val1[i]} < ${val2[i]} ]]; then
432 elif [[ ${val1[i]} > ${val2[i]} ]]; then
441 echo $(echo "$*" | xargs -n 1 | sort -u)
449 if [ -z "$target" ]; then
450 fatal 1 "fetch_url() called without a target to fetch to"
453 if [ -d $target ]; then
454 target+="/${url##*/}"
458 if which wget >/dev/null 2>&1; then
459 if ! wget -nv "$url" -O "$target"; then
462 elif which curl >/dev/null 2>&1; then
463 if ! curl -n -L -s -o "$target" "$url"; then
467 fatal 1 "Could not find either wget or curl to fetch URLs."
477 local force="${3:-false}"
479 # let the download_file handle the concurrency
482 # get the location from a distro specific method if it exists
483 if type -p kernel_srpm_location; then
484 location=$(kernel_srpm_location)
486 fatal 1 "Must specify location for download kernel SRPM."
488 echo "Downloading $location/$srpm..."
490 "$location/$srpm" "$KERNELDIR/$srpm" "$force" 2>&1 ||
491 [ ! -s "$KERNELDIR/$srpm" ]; then
492 rm -f $KERNELDIR/$srpm
493 fatal 1 "Could not download target $target's kernel \
494 SRPM $srpm from $location."
499 download_debuginfo_common() {
501 local force="${2:-false}"
503 # let the download_file handle the concurrency
505 # get the location from a distro specific method if it exists
506 if type -p kernel_debuginfo_location; then
507 location=$(kernel_debuginfo_location)
509 echo "Downloading $location/$rpm"
511 "$location/$rpm" "$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$rpm" "$force" 2>&1 ||
512 [ ! -s "$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$rpm" ]; then
513 rm -f $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$rpm
514 fatal 1 "Could not download $rpm from $location."
524 local file=${from##*/}
530 local semaphore="$to-downloading"
533 if [ ! -f $semaphore ]; then
537 # make sure the download has not been aborted
538 local now=$(date +%s)
539 local file_mtime=$(stat -c %Y "$to")
540 local staleness=$((now - file_mtime))
541 # let's assume an active download will write at least once a minute
542 if [ $staleness -gt 60 ]; then
550 # if the semaphore file exists, the file is either still downloading
551 # or a download was aborted and we cannot trust the target file
552 if [ -f $semaphore ]; then
556 if ! is_downloading && [ -r "$to" ] && [ -s "$to" ]; then
563 if $force || ! is_downloaded; then
564 if is_downloading; then
565 echo "Somebody else is downloading $from..."
566 while is_downloading; do
567 echo "Waiting for $to to finish downloading"
570 if is_downloaded; then
573 echo "The download we were waiting for seems to have been aborted"
579 echo "Downloading $from..."
580 # flag others so they don't try to download also
581 push_exit_trap "rm -f $to $semaphore" "download"
583 if ! fetch_url "$from" "$to" || [ ! -s "$to" ]; then
584 # the trap will remove the files via the fatal below
585 fatal 1 "Could not download ${to##*/} from ${from%/*}/."
588 delete_exit_trap "download"
590 fatal 1 "${to##*/} not found in directory ${to%/*}."
600 local ofed_version="$2"
601 local force="${3:-false}"
602 local distro_name="${DISTRO}"
603 local arch="${TARGET_ARCH}"
607 #if a src tarball has been given in the command line, we use it
608 #The format of the tarball must be OFED-${OFED_VERSION}.tgz
609 [ -n "${OFED_SRC}" ] && return 0
613 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version}/"
615 if [[ $ofed_version = *-[rR][cC][0-9] ]]; then
616 ofed_version_loc=${ofed_version%%-[rR][cC][0-9]}
617 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version_loc}/"
620 if [[ $ofed_version = *-daily ]]; then
621 ofed_version=${ofed_version/-daily/}
622 location="https://www.openfabrics.org/downloads/OFED/ofed-${ofed_version}-daily/"
623 # find the filename for latest version
624 ofed_version=$(curl -1 -s "$location" | sed -nre "s/.*href=\"OFED-(${ofed_version//./\\.}-[0-9]{8}-[0-9]{4}).tgz.*$/\1/p" | tail -1)
625 if [ -z "$ofed_version" ]; then
626 fatal 1 "Could not determine the filename of the OFED snapshot from daily "
630 file="OFED-${ofed_version}.tgz"
631 download_file "$location/$file" "$KERNELTREE" "$force"
634 location="http://www.mellanox.com/downloads/ofed/MLNX_OFED-${ofed_version}"
635 # this is a work around for suse distro (sles11.3). what we need is
636 # sles11sp3. We really need to redesign how we use target and distro
637 [[ $distro_name =~ sles ]] && distro_name=${DISTRO/./sp}
638 if [[ $arch = "aarch64" ]]; then
639 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}alternate-${arch}.tgz"
641 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}-${arch}.tgz"
643 download_file "$location/$file" "$KERNELTREE" "$force"
646 location="http://downloadmirror.intel.com/24625/eng/"
647 file="IntelIB-Basic.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.${ofed_version}.tgz"
648 download_file "$location/$file" "$KERNELTREE" "$force"
651 fatal 1 "Error: unknown OFED type: $ofed_type"
654 # version might change due to detect daily version
655 OFED_VERSION=${ofed_version}
661 EXTRA_VERSION_save="$EXTRA_VERSION"
662 for patchesdir in "$EXTERNAL_PATCHES" \
663 "$TOPDIR/lustre/lustre/kernel_patches"; do
664 TARGET_FILE="$patchesdir/targets/$TARGET.target"
665 [ -r "$TARGET_FILE" ] && break
667 [ -r "$TARGET_FILE" ] || fatal 1 "Target $TARGET was not found."
669 echo "Loading target config file $TARGET.target..."
671 # if the caller specified an OFED_VERSION it should override whatever
672 # the target file specifies
673 local env_OFED_VERSION="$OFED_VERSION"
677 if [ -n "$env_OFED_VERSION" ]; then
678 OFED_VERSION="$env_OFED_VERSION"
681 # doesn't make any sense to build OFED for xen domX's
686 # XXX - set_rpm_smp_type is an ugly undeterministic hack. it needs to
687 # go away and the target just specify the $RPMSMPTYPE
688 [ -z "$RPMSMPTYPE" ] && set_rpm_smp_type
690 # CC might have been overwritten in TARGET_FILE
691 if [[ $CC != ccache\ * ]] && which "$CCACHE" &>/dev/null; then
692 export CCACHE && export CC="ccache $CC"
695 if [ ! "$KERNELTREE" = "" ] && [ -d "$KERNELTREE" ]; then
696 KERNELDIR="$KERNELTREE/${lnxmaj}"
697 [ -d "$KERNELDIR" ] || mkdir "$KERNELDIR"
700 # verify the series is available
701 if [ "$SERIES" ]; then
702 for series in $SERIES; do
703 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
704 [ -r "$patchesdir/series/$series" ] && continue 2
706 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."
710 # set the location of the .config file
716 if [ -f $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET-$TARGET_ARCH.config ]; then
717 CONFIG_FILE="$TOPDIR/lustre/lustre/kernel_patches/kernel_configs/kernel-$lnxmaj-$TARGET$XENPOSTFIX-$TARGET_ARCH.config"
720 local lnxrelnew=${lnxrel//-/_}
722 # remember the EXTRA_VERSION before we diddle it here
723 # XXX - we really should not diddle with any values read in from the
724 # target file. if we want to modify a value, we should create
726 PRISTINE_EXTRA_VERSION=$EXTRA_VERSION
728 if ! $PATCHLESS && [ ! -f "$CONFIG_FILE" ]; then
729 fatal 1 "Config file for target $TARGET missing from $TOPDIR/lustre/lustre/kernel_patches/kernel_configs/."
732 if [ "$EXTRA_VERSION_save" ]; then
733 EXTRA_VERSION="$EXTRA_VERSION_save"
734 elif ! $RELEASE; then
735 # if there is no patch series, then this is not a lustre specific
736 # kernel. don't make it look like one
737 if $PATCHLESS || [ -n "$SERIES" ]; then
738 EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/")
741 # EXTRA_VERSION=${EXTRA_VERSION//-/_}
747 echo -n '--wildcards '
750 fatal 1 "tarflags(): File name argument missing."
762 fatal 1 "tarflags(): Unrecognized tar extension in file: $1"
771 local extractfile="$@"
773 echo "Untarring ${tarfile##*/}..."
774 tar $(tarflags "$tarfile") "$tarfile" $extractfile
780 local ofed_version="$2"
781 local distro_name="${DISTRO}"
782 local arch="${TARGET_ARCH}"
785 #if a src tarball has been given in the command line, we use it
786 #The format of the directory after untar MUST be in OFED-${version}
787 #even if it's from MLNX or IFS...or whatever
788 if [ -n "${OFED_SRC}" ]; then
789 if ! untar "$KERNELTREE/${OFED_SRC}"; then
792 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
797 file="OFED-${ofed_version}"
798 if ! untar "$KERNELTREE/${file}.tgz"; then
801 [ -d OFED ] || ln -sf OFED-[0-9].[0-9]* OFED
804 # this is a work around for suse distro (sles11.3). what we need is
805 # sles11sp3. We really need to redesign how we use target and distro
806 [[ $distro_name =~ sles ]] && distro_name=${DISTRO/./sp}
807 if [[ $arch = "aarch64" ]]; then
808 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}alternate-${arch}"
810 file="MLNX_OFED_LINUX-${ofed_version}-${distro_name}-${arch}"
812 # it's not important what distro we get the tarball since we only
813 # interest in the src
814 if ! untar "$KERNELTREE/${file}.tgz"; then
817 # we need to untar again to get the src since it's being
818 # wrapped inside the tarball
819 # There are cases where the source version is different
821 # (ie. MLNX_OFED_LINUX-2.3-1.0.1 but MLNX_OFED_SRC-2.3-1.0.0)
822 local src=$(ls ${file}/src/MLNX_OFED_SRC-${ofed_version%.*}*.tgz)
823 if ! untar "$src"; then
826 [ -d OFED ] || ln -sf MLNX_OFED_SRC-[0-9].[0-9]* OFED
827 [ -d OFED_RPMS ] || ln -sf ${file}/RPMS OFED_RPMS
830 file="IntelIB-Basic.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.${ofed_version}"
831 if ! untar "$KERNELTREE/${file}.tgz"; then
834 [ -d OFED ] || ln -sf $file/IntelIB-OFED.$(echo ${distro_name%%.*} | tr '[:lower:]' '[:upper:]')-${arch}.* OFED
835 ofed_version="$(cat OFED/Version)"
838 # version might change due to detect daily version
839 OFED_VERSION=${ofed_version}
844 untar "$LUSTRE" || fatal 1 "Error unpacking Lustre tarball"
845 [ -d lustre ] || ln -sf lustre-[0-9].[0-9]* lustre
851 local do_patch=${1:-true}
853 FULL_PATCH="$PWD/lustre-kernel-${TARGET}-${EXTRA_VERSION}.patch"
854 [ -f "$FULL_PATCH" ] && rm -f "$FULL_PATCH"
855 $do_patch && pushd linux >/dev/null
856 for series in $SERIES; do
857 echo -n "Applying series $series:"
858 for patchesdir in "$EXTERNAL_PATCHES" "$TOPDIR/lustre/lustre/kernel_patches"; do
859 [ -r "$patchesdir/series/$series" ] || continue
860 SERIES_FILE="$patchesdir/series/$series"
861 for patch in $(<"$SERIES_FILE"); do
863 PATCH_FILE="$patchesdir/patches/$patch"
864 [ -r "$PATCH_FILE" ] || \
865 fatal 1 "Patch $patch does not exist in Lustre tree."
866 cat "$PATCH_FILE" >> "$FULL_PATCH" || {
868 fatal 1 "Error adding patch $patch to full patch."
871 patch -s -p1 < "$PATCH_FILE" 2>&1 || {
873 fatal 1 "Error applying patch $patch."
881 $do_patch && popd >/dev/null
882 echo "Full patch has been saved in ${FULL_PATCH##*/}."
889 local configure_args=""
893 pushd lustre >/dev/null
895 if ! build_lustre_dkms; then
896 popd >/dev/null # pushd lustre
900 echo "Building Lustre RPMs for: $TARGET_ARCH"
902 # If server we now build the spl and zfs modules against the lustre kernel.
903 # These are required prior to the building of lustre server. Client does
904 # not require spl/zfs. Use !PATCHLESS to indicate server which follows the
905 # line above so is at least consistant.
906 if [ $PATCHLESS == false ] && [ "x$WITH_ZFS" == "x" ]; then
907 if ! build_spl_zfs; then
908 popd >/dev/null # pushd lustre
914 configure_args="$configure_args --disable-server"
917 # ditto for the lustre-tests boolean
918 if ! $LUSTRE_TESTS; then
919 configure_args="$configure_args --disable-tests"
923 configure_args="$configure_args --disable-iokit"
926 if ! $OSDZFSRPM; then
927 configure_args="$configure_args --without-zfs"
930 if ! $OSDLDISKFSRPM; then
931 configure_args="$configure_args --disable-ldiskfs"
934 configure_args="$configure_args --with-linux=$linux"
935 configure_args="$configure_args ${linuxobj:+--with-linux-obj=$linuxobj}"
937 # allow environment setting to override ldiskfs series selection
938 [ -n "$LDISKFS_SERIES" ] && export LDISKFS_SERIES
940 ./configure $configure_args $CONFIGURE_FLAGS 2>&1 ||
941 fatal 1 "Error in configure."
943 if type -p apply_kmod_requires_conflicts; then
944 apply_kmod_requires_conflicts
948 fatal 1 "Error building rpms for $TARGET_ARCH."
950 # move RPMs into place where they are expected to be
951 mv -f *lustre*.${TARGET_ARCH}.rpm $TOPDIR/RPMS/${TARGET_ARCH}/
952 mv -f lustre-*.src.rpm $TOPDIR/SRPMS/
955 if type -p cleanup_rpmmacros; then
962 build_lustre_dkms() {
964 local ver=$(sed -n -e 's/^LUSTRE_VERSION = //p' LUSTRE-VERSION-FILE)
966 echo "Building Lustre DKMS RPMs for: $TARGET_ARCH"
967 ./configure --enable-dist || fatal 1 "Error in DKMS configure."
970 build_args="--without servers"
973 rpmbuild --define "_topdir $TOPDIR" $build_args -bs lustre-dkms.spec ||
974 fatal 1 "Error building DKMS .src.rpm for $TARGET_ARCH."
977 rpmbuild --define "_topdir $TOPDIR" $build_args \
978 --rebuild $TOPDIR/SRPMS/lustre-client-dkms-$ver-*.src.rpm ||
979 fatal 1 "Error building DKMS .rpm for $TARGET_ARCH."
981 rpmbuild --define="_topdir $TOPDIR" --with servers \
982 --with zfs --without ldiskfs -bs lustre-dkms.spec ||
983 fatal 1 "Error creating DKMS (zfs) .srpm for $TARGET_ARCH."
984 rpmbuild --define="_topdir $TOPDIR" --with servers \
985 --without zfs --with ldiskfs -bs lustre-dkms.spec ||
986 fatal 1 "Error creating DKMS (ldiskfs) .srpm for $TARGET_ARCH."
987 rpmbuild --define="_topdir $TOPDIR" --with servers \
988 --with zfs --with ldiskfs -bs lustre-dkms.spec ||
989 fatal 1 "Error creating DKMS (all) .srpm for $TARGET_ARCH."
991 rpmbuild --rebuild --define="_topdir $TOPDIR" --with servers \
992 --with zfs --without ldiskfs $TOPDIR/SRPMS/lustre-zfs-dkms-$ver-*.src.rpm ||
993 fatal 1 "Error building DKMS (zfs) .rpm for $TARGET_ARCH."
994 rpmbuild --rebuild --define="_topdir $TOPDIR" --with servers \
995 --without zfs --with ldiskfs $TOPDIR/SRPMS/lustre-ldiskfs-dkms-$ver-*.src.rpm ||
996 fatal 1 "Error building DKMS (ldiskfs) .rpm for $TARGET_ARCH."
997 rpmbuild --rebuild --define="_topdir $TOPDIR" --with servers \
998 --with zfs --with ldiskfs $TOPDIR/SRPMS/lustre-all-dkms-$ver-*.src.rpm ||
999 fatal 1 "Error building DKMS (all) .rpm for $TARGET_ARCH."
1008 # Fetch spl/zfs from the git repo and prepare for lustre build
1011 # SPLZFSGITREPO - URI of directory where spl.git and zfs.git are located
1012 # SPLZFSTAG - Tag to checkout of clone repositories
1013 # SPLZFSVER - Version to checkout of both (format zfs/spl-$SPLZFSVER)
1015 # return 0 if successful, else 255
1017 # make sure the RPM build environment is set up
1019 create_rpmbuild_dirs
1022 # The spl/zfs spec files expect RPM_BUILD_ROOT to point to the root of the
1023 # destination for the rpms
1024 export RPM_BUILD_ROOT=$TOPDIR
1025 SPLZFSVER=${SPLZFSVER:-0.7.12}
1026 SPLZFSTAG=${SPLZFSTAG:-}
1028 # The files expect a kver to be set to the kernel version .
1029 local kver=$(find_linux_release)
1031 # build and install the spl and zfs (and -devel) RPMs for lustre to use
1033 for pkg in spl zfs; do
1037 [ "$pkg" == "zfs" ] && spldir="$(ls -d $TOPDIR/usr/src/spl-*|tail -1)"
1039 # need to fetch the repo in order to build it.
1040 # default to github but allow override
1041 git clone -n ${SPLZFSGITREPO:-"https://github.com/zfsonlinux"}/$pkg.git $pkg 2>&1
1043 pushd $pkg || return 255
1045 if [ -n "$SPLZFSTAG" ]; then
1050 git checkout -b lbuild $tag || fatal 1 "Failed to checkout \"$tag\" for $pkg.git"
1052 # This differentiates between older zfs versions
1053 if [ -f $pkg-modules.spec.in ]; then
1056 speclist="$pkg.spec $rpmpkg.spec"
1058 rpmpkg=kmod-$pkg-devel
1060 speclist="$pkg.spec $pkg-kmod.spec $pkg-dkms.spec"
1063 sh autogen.sh || return 255
1065 if ! ./configure --with-linux=${LINUX} --with-linux-obj=${LINUXOBJ:-$LINUX} \
1066 ${spldir:+--with-spl="${spldir}"} 2>&1 ||
1067 ! make dist 2>&1; then
1073 ln -f $pkg/$pkg-*.tar.gz $TOPDIR/SOURCES ||
1074 error "failed to link $pkg/$pkg-*.tar.gz into $TOPDIR/SOURCES"
1075 if [ -f $pkg/scripts/kmodtool ]; then
1076 ln -f $pkg/scripts/kmodtool $TOPDIR/SOURCES/
1086 # set search dir for our own kmodtool to find correct
1088 export KERNELSOURCE=$(dirname ${LINUX})
1089 # Manually build rpms
1090 for spec in $speclist; do
1091 echo "Building RPMs from $pkg/$specdir/$spec"
1092 if ! rpmbuild $rpmb $pkg/$specdir/$spec \
1094 --define "_use_internal_dependency_generator 0" \
1095 --define "require_kdir ${LINUX}" \
1096 ${LINUXOBJ:+--define "require_kobj ${LINUXOBJ}"} \
1097 ${spldir:+--define "require_spldir ${spldir}"} \
1098 --define "kver $kver" \
1099 --define "kernels $kver" \
1100 --define "_tmppath /var/tmp" \
1101 --define "kernelbuildroot $TOPDIR/reused" \
1102 --define "_topdir $TOPDIR" 2>&1; then
1107 # We have built the rpms for the package. Now we need to extract the
1108 # contained files so we can build further things against them
1109 local rpms=$(ls -1 $TOPDIR/RPMS/*/$rpmpkg-*.rpm)
1111 # cpio only extract to pwd so we need to go there.
1114 for rpm in $rpms; do
1115 rpm2cpio $rpm | cpio -id
1118 if [ "$pkg" == "zfs" ]; then
1119 # We also need to extract both the zfs and zfs-devel rpms
1120 # the zfs rpm is needed because it has the actual libraries in
1121 # it and the zfs-devel rpm only has unversioned symlinks to the
1122 # libraries in the zfs rpm
1123 # this will all change one day when we have a libzfs rpm per
1124 # https://github.com/zfsonlinux/zfs/issues/2329
1125 # and it looks like it could be one day soon:
1126 # https://github.com/zfsonlinux/zfs/pull/2341
1127 local devel_rpms=$(ls -1 $TOPDIR/RPMS/*/{$pkg-devel,$pkg-$SPLZFSVER,lib*}-*.rpm)
1128 for rpm in $devel_rpms; do
1129 rpm2cpio $rpm | cpio -id
1131 CONFIGURE_FLAGS="--with-$pkg-devel=$TOPDIR ${CONFIGURE_FLAGS}"
1135 CONFIGURE_FLAGS="--with-$pkg=$(ls -d $TOPDIR/usr/src/$pkg-*|tail -1) ${CONFIGURE_FLAGS}"
1136 CONFIGURE_FLAGS="--with-$pkg-obj=$(ls -d $TOPDIR/usr/src/$pkg-*/$kver*|tail -1) ${CONFIGURE_FLAGS}"
1146 [ "$STAGEDIR" ] || return 0
1148 rpmdir="${STAGEDIR}/${CANONICAL_TARGET}-${TARGET_ARCH}"
1149 echo "${0##*/}: Copying RPMs into ${rpmdir}"
1150 mkdir -p "${rpmdir}"
1151 for rpm in $(ls RPMS/${TARGET_ARCH}/*.rpm RPMS/noarch/*.rpm); do
1152 cp -v $rpm "${rpmdir}"
1155 cp -v "$LUSTRE" "$STAGEDIR"
1159 set_rpm_smp_type() {
1161 local infact_arch="${TARGET_ARCH}"
1164 [ "$infact_arch" == "i586" ] && infact_arch="i686"
1167 for smp_type in $SMP_ARCHS; do
1168 [ $infact_arch == $smp_type ] && RPMSMPTYPE=smp && break
1171 for smp_type in $BIGSMP_ARCHS; do
1172 [ $infact_arch == $smp_type ] && RPMSMPTYPE=bigsmp && break
1175 for smp_type in $PPC64_ARCHS; do
1176 [ $infact_arch == $smp_type ] && RPMSMPTYPE=ppc64 && break
1179 for smp_type in $DEFAULT_ARCHS; do
1180 [ $infact_arch == $smp_type ] && RPMSMPTYPE=default && break
1185 # This function takes a linux include tree and digs out the linux release
1186 # from it. It is never called directly, only called from the distro
1187 # specific function find_linux_release() in lbuild-{rhel,sles}.
1188 _find_linux_release() {
1190 local LINUXRELEASEHEADER=""
1192 LINUXRELEASEHEADER=$SRC/include/linux/version.h
1193 if [ -s $SRC/include/generated/utsrelease.h ]; then
1194 LINUXRELEASEHEADER=$SRC/include/generated/utsrelease.h
1195 elif [ -s $SRC/include/linux/utsrelease.h ]; then
1196 LINUXRELEASEHEADER=$SRC/include/linux/utsrelease.h
1199 if [ ! -s $LINUXRELEASEHEADER ]; then
1200 fatal 1 "could not find UTS_RELEASE"
1203 sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' $LINUXRELEASEHEADER
1206 # unpack kernel(/source/devel) RPM
1208 unpack_linux_devel_rpm() {
1209 local kernelrpm="${1}"
1211 [ -f "$kernelrpm" ] || return 255
1212 [ -d $TOPDIR/reused ] || mkdir $TOPDIR/reused || return 255
1214 pushd $TOPDIR/reused &>/dev/null || return 255
1216 if ! rpm2cpio < "$kernelrpm" | cpio -id > /dev/null 2>&1; then
1220 # call a distro specific hook, if available
1221 if type -p unpack_linux_devel_rpm-$DISTROMAJ; then
1222 if ! unpack_linux_devel_rpm-$DISTROMAJ "$kernelrpm"; then
1229 find_linux_devel_paths $TOPDIR/reused
1237 local kib_prefix="$2"
1239 local ofed_type="${4}"
1240 local ofed_version="${5}"
1242 # build kernel-ib{,-devel}/compat-rdma{,-devel}
1245 local OFED_CORE="--with-core-mod --with-ipoib-mod --with-user_mad-mod \
1246 --with-user_access-mod --with-addr_trans-mod --with-innova-flex "
1247 local OFED_HARDWARE="--with-mlx4-mod --with-mlx4_en-mod \
1248 --with-srp-mod --with-iser-mod --with-isert-mod --with-mlx5-mod \
1251 # some I/B drivers are architecture dependent and kernel-ib's configure
1252 # does not figure it out for us ~sigh~
1253 case "$TARGET_ARCH" in
1255 OFED_HARDWARE="$OFED_HARDWARE --with-ehca-mod"
1259 # assume we are just rebuilding the SRPM
1260 local BUILD_TYPE=${BUILD_TYPE:-"--rebuild"}
1261 local SOURCE="${TOPDIR}/OFED/SRPMS/${kib_prefix}-*.src.rpm"
1263 # but switch to building from the SPEC if we need to apply patches
1264 if ls ${TOPDIR}/lustre/contrib/patches/ofed/* >/dev/null; then
1266 rpm --define "_topdir ${TOPDIR}" -ivh $SOURCE
1267 SOURCE="${TOPDIR}/SPECS/${kib_prefix}.spec"
1268 local file ed_fragment1 ed_fragment2 n=1
1269 for file in $(ls ${TOPDIR}/lustre/contrib/patches/ofed/*.patch); do
1270 ed_fragment1="$ed_fragment1
1271 Patch$n: ${file%%*/}"
1272 ed_fragment2="$ed_fragment2
1274 cp $file ${TOPDIR}/SOURCES
1277 for file in $(ls ${TOPDIR}/lustre/contrib/patches/ofed/*.ed); do
1278 # Only apply the ed-scripts that should be used for the canonical target
1279 # ed-files in ${TOPDIR}/lustre/contrib/patches/ofed/ have to follow the naming
1281 # <two-digits>-<descriptive-name>:<canonical_target_1>: ...:<canonical_target_N>.ed
1282 # To apply the same change to multiple canonical target simply specify
1283 # a list of colon separated canoncial target names in the file name.
1284 echo "$file" | grep -q -e ":${CANONICAL_TARGET}:" \
1285 -e ":${CANONICAL_TARGET}.ed$"
1286 if [ $? -eq 0 ] ; then
1287 ed_fragment3="$ed_fragment3
1293 if [ $n -gt 1 ]; then
1307 local linuxrelease=$(find_linux_release)
1308 # a place to change/add any unique config
1310 ofa|ifs) local K_SRC_OBJ="K_SRC_OBJ"
1311 if ! $RPMBUILD $BUILD_TYPE --define 'build_kernel_ib 1' \
1312 --define 'build_kernel_ib_devel 1' \
1313 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1314 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1315 --define "KVERSION ${linuxrelease}" \
1316 --define "$K_SRC ${linux}" \
1317 ${K_SRC_OBJ:+--define "$K_SRC_OBJ ${linux}"} \
1318 ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
1319 --define "configure_options --without-quilt $OFED_CORE $OFED_HARDWARE $OFED_ISCSI" \
1320 ${SOURCE} 2>&1; then
1321 fatal 1 "Error building ${kib_rpm}"
1325 if ! $RPMBUILD $BUILD_TYPE \
1326 ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
1327 --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
1328 --define "KVERSION ${linuxrelease}" \
1330 --define "$K_SRC ${linux}" \
1331 ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
1332 ${SOURCE} 2>&1; then
1333 fatal 1 "Error building ${kib_rpm}"
1335 # now that we have the kernel rpms, we need to lib rpms too
1336 # we don't have to rebuild since MOFED include the binaries
1337 cp -f OFED_RPMS/{libibmad-*,libibverbs-*,libibumad-*,librdmacm*,ibutils-*,opensm-*}.${TARGET_ARCH}.rpm \
1338 ${TOPDIR}/RPMS/${TARGET_ARCH} || \
1339 fatal 1 "Failed to copy MOFED rpms"
1349 local signature="$4"
1350 local use_links="$5"
1357 local unique_id=$(hostname -s)
1358 if [ -z "$unique_id" ]; then
1359 fatal 1 "Failed to determine hostname."
1362 local finallocation="$location"/"$signature"/"$module"
1363 location="$location"/"$signature-${unique_id}"/"$module"
1364 mkdir -p "$location"
1365 # the cleanup script removes any directory that doesn't have a
1366 # .lastused, so let's try to prevent that as soon as we can
1367 # this solution still slightly racy with the cleanup script
1368 # but the race is a lot tighter now
1369 touch -t 197001010000 "$location/.lastused"
1370 ## use eval/echo here to make sure shell expansions are performed
1371 #if ! cp -a${linkflag} $(eval echo $articles) "$location"; then
1373 for article in $(eval echo $articles); do
1374 if ! cp -a${linkflag} "$article" "$location"; then
1375 error "Failed to copy \"$article\" to \"$location\" in store_for_reuse()"
1376 # rename the cache location so that it's not cached
1377 # product, but is around for analysis
1378 mv "$location"{,-bad-$(date +%s)} ||
1379 error "failed to clean up a failed cache attempt" \
1380 "in \"$location\" -- manual cleanup will be" \
1386 # flag the cache as complete (i.e. in case lbuild was previously
1387 # interrupted while caching)
1388 touch "$location/.lastused"
1390 # put the temporary location into the final location
1392 mkdir -p "${finallocation%/*}"
1393 mv "$location" "$finallocation"
1394 rmdir "${location%/*}"
1402 local use_links="${3:-false}"
1403 local signature="$4"
1405 if [ -n "$REUSEBUILD" ] && [ -d "$REUSEBUILD/$signature/$module" ]; then
1406 if [ ! -f "$REUSEBUILD/$signature/$module/.lastused" ]; then
1407 # the .lastused flag is populated at the end of the caching to
1408 # signal that the caching was completed. if that flag is not
1409 # there, then the cache is invalid (and should be removed in fact)
1410 mv "$REUSEBUILD/$signature/$module"{,-bad-$(date +%s)} ||
1411 fatal 1 "failed to clean up a bad cache in location $REUSEBUILD/$signature/$module\" -- manual cleanup will be necessary"
1415 # so that we know how stale this entry is
1416 touch $REUSEBUILD/$signature/$module/.lastused
1419 if ls $REUSEBUILD/$signature/$module/* >/dev/null 2>&1; then
1420 cp -al $REUSEBUILD/$signature/$module/* $dest/
1423 # copying is pretty heavy
1424 # cp -a $REUSEBUILD/$signature/$module/* $dest/
1425 # do some creative symlinking instead
1427 for dir in BUILD SRPMS SPECS; do
1428 if ls $REUSEBUILD/$signature/$module/$dir/* >/dev/null 2>&1; then
1429 ln -s $REUSEBUILD/$signature/$module/$dir/* $dest/$dir
1432 # sources have to be copied by file because we need SOURCES to
1433 # be a dir we can write into
1434 # could overrun ls's arg list here
1435 #ls $REUSEBUILD/$signature/$module/SOURCES/* |
1436 find $REUSEBUILD/$signature/$module/SOURCES/ -type f |
1437 xargs ln -t $dest/SOURCES -s
1439 # same for RPMS/* dirs
1440 # could overrun ls's arg list here
1441 #ls $REUSEBUILD/$signature/$module/RPMS/$TARGET_ARCH/* |
1443 for dir in $REUSEBUILD/$signature/$module/RPMS/*; do
1444 mkdir -p $dest/RPMS/${dir##*/}
1446 xargs ln -t $dest/RPMS/${dir##*/} -s
1458 if [[ $arch = i[3456]86 ]]; then
1466 build_kernel_with_srpm() {
1469 if [ -z "$outfd" ] || [ $outfd = 1 ]; then
1470 fatal 1 "You must supply a file descriptor to ${FUNCNAME[0]} and it cannot be 1"
1473 # need to generate the patch for this target
1474 do_patch_linux false >&${outfd} # sets global $FULL_PATCH (yeah, yuck)
1476 # get an md5sum of the kernel patch + config for reuse check
1479 local release_str="RELEASE=$RELEASE\n"
1482 if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1483 local REUSE_SIGNATURE=$({ echo -en $release_str;
1486 cat "$TARGET_FILE" |
1487 sed -e '/_VERSION=/s/_[0-9]*_g.*$//g';
1489 cat "$LBUILD_DIR/lbuild";
1490 cat "$LBUILD_DIR/lbuild-$DISTROMAJ"; } |
1491 md5sum | cut -d" " -f1)
1492 # see if we can link to the reuse pool
1493 # XXX - hrm. i'm not convinced this doesn't belong in the reuse
1495 local CAN_LINK_FOR_REUSE=false
1496 touch $REUSEBUILD/$$
1497 if cp -al $REUSEBUILD/$$ $TOPDIR/ 2>/dev/null; then
1498 CAN_LINK_FOR_REUSE=true
1503 # the extra version string to use for the kernel (which might be a reused
1505 local kernel_extra_version=""
1506 if ! $USE_BUILD_CACHE || ! reuse kernel "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1507 "$REUSE_SIGNATURE"; then
1508 # nothing cached, build from scratch
1509 echo "Downloading kernel SRPM" >&${outfd}
1510 download_srpm "$CANONICAL_TARGET" "$KERNEL_SRPM" >&${outfd}
1512 if ! rpm -ivh $KERNELDIR/$KERNEL_SRPM \
1513 --define "_topdir $TOPDIR" >&${outfd} 2>&1; then
1514 # should we clean this up or leave it for analysis?
1516 fatal 1 "Error installing kernel SRPM."
1519 # put the Lustre kernel patch into the RPM build tree
1520 cp $FULL_PATCH $TOPDIR/SOURCES/linux-${lnxmaj}-lustre.patch
1521 prepare_and_build_srpm >&${outfd} ||
1522 fatal 1 "failed to prepare_and_build_srpm"
1524 if [ -z "$REUSE_SIGNATURE" ]; then
1525 echo "No reuse signature was caculated so not storing the built kernel" >&${outfd}
1527 # store the resulting kernel RPM build tree for future use
1528 echo "Storing the built kernel for future reuse" >&${outfd}
1529 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,SRPMS,RPMS}" \
1530 "kernel" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1531 "$CAN_LINK_FOR_REUSE"; then
1532 error "Failed to store kernel RPMS for reuse"
1533 echo "unknown" >&${outfd}
1539 # figure out the EXTRA_VERSION of the kernel we built or are re-using
1541 if ! KERNEL_RPM=$(find_rpm "$TOPDIR/RPMS/$TARGET_ARCH/" provides "^kernel(-default)? ="); then
1542 fatal 1 "Failed to find a kernel RPM in $TOPDIR/RPMS/$TARGET_ARCH/"
1544 kernel_extra_version=$(rpm -q --queryformat "%{RELEASE}" -p $TOPDIR/RPMS/$TARGET_ARCH/$KERNEL_RPM)
1546 # should now have the following RPMs
1547 # $TOPDIR/RPMS/$arch/kernel-lustre-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1548 # $TOPDIR/RPMS/$arch/kernel-lustre-devel-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1549 # $TOPDIR/RPMS/$arch/kernel-lustre-headers-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1550 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-common-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1551 # $TOPDIR/RPMS/$arch/kernel-lustre-debuginfo-2.6.18-53.1.21.el5_lustre.1.6.5.1.$arch.rpm
1553 echo $kernel_extra_version
1561 # REUSEBUILD, USE_BUILD_CACHE
1566 local ofed_type="$2"
1567 local ofed_version="$3"
1574 if [ "$ofed_version" = "inkernel" ]; then
1575 # see if there is a distro specific override for this and use
1577 # XXX we need to better integrate a distro specific override with
1578 # the rest of this function so that all of the reuse cache
1579 # stuff is leveraged given that 80% of this function is reuse
1580 if type -p build_ofed-$DISTROMAJ; then
1582 ofed_location=$(build_ofed-$DISTROMAJ ${STDOUT})
1583 local rc=${PIPESTATUS[0]}
1584 CONFIGURE_FLAGS="--with-o2ib=${ofed_location} ${CONFIGURE_FLAGS}"
1591 mlnx) # no compat-rdma for mlnx as of 3.1
1592 kib_prefix="ofa_kernel"
1594 kib_rpm="${pre_prefix}${kib_prefix}"
1597 if compare_version $ofed_version 3.0; then
1598 kib_prefix="ofa_kernel"
1599 kib_rpm="${pre_prefix}${kib_prefix}"
1601 kib_prefix="compat-rdma"
1602 kib_rpm="compat-rdma"
1608 # build kernel-ib/compat-rdma
1609 if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
1610 local REUSE_SIGNATURE=$({ echo "$ofed_version";
1611 echo "$(find_linux_release;
1612 echo "$BUILD_GEN")";
1613 cat "${linux}/include/linux/autoconf.h";
1614 cat "$LBUILD_DIR/lbuild";
1615 cat "$LBUILD_DIR/lbuild-$DISTROMAJ"; } |
1616 md5sum | cut -d" " -f1)
1617 # see if we can link to the reuse pool
1618 # XXX - hrm. i'm not convinced this doesn't belong in the reuse
1620 local CAN_LINK_FOR_REUSE=false
1621 touch $REUSEBUILD/$$
1622 if cp -al $REUSEBUILD/$$ $TOPDIR/; then
1623 CAN_LINK_FOR_REUSE=true
1628 if ! $USE_BUILD_CACHE || ! reuse ofed "$TOPDIR" "$CAN_LINK_FOR_REUSE" \
1629 "$REUSE_SIGNATURE"; then
1630 if [ -n "$REUSE_SIGNATURE" ]; then
1631 # stash away the existing built articles for a moment
1633 mv {BUILD,{S,}RPMS,S{OURCE,PEC}S} bak
1636 find . | cpio -pudlm ..
1640 create_rpmbuild_dirs
1643 build_kernel_ib "${linux}" "${pre_prefix}${kib_prefix}" "${kib_rpm}" "${ofed_type}"
1645 if [ -z "$REUSE_SIGNATURE" ]; then
1646 echo "No reuse signature was caculated so not storing the built ofed"
1648 # store the resulting RPM build tree for future use
1649 echo "Storing the built ofed for future reuse"
1650 if ! store_for_reuse "$TOPDIR/{SPECS,SOURCES,BUILD,SRPMS,RPMS}" \
1651 "ofed" "$REUSEBUILD" "$REUSE_SIGNATURE" \
1652 "$CAN_LINK_FOR_REUSE"; then
1653 error "Failed to store OFED RPMS for reuse"
1657 # put the stuff we stashed away back
1662 pushd "$TOPDIR" >/dev/null
1663 rm -rf ${kib_rpm}-devel
1664 mkdir ${kib_rpm}-devel
1667 o2ib_location="$(pwd)/usr/src/${kib_prefix}"
1669 mlnx) # Prior to MOFED 3.1, we had to use build_kernel_ib=1 to
1670 # build devel rpm. not so after 3.1
1671 if compare_version $ofed_version 3.0; then
1672 rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version%%-*}-*.rpm)
1674 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-${ofed_version%%-*}-*.rpm)
1676 o2ib_location="${o2ib_location}/default"
1678 ofa) # Prior to OFA 3.18, we had to use build_kernel_ib=1 during configure,
1680 if compare_version $ofed_version 3.18; then
1681 rpm=$(ls $TOPDIR/RPMS/*/kernel-ib-devel-${ofed_version%%-*}-*.rpm)
1683 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-${ofed_version%%-*}-*.rpm)
1686 ifs) # ifs doesn't follow any convention (if any)
1687 rpm=$(ls $TOPDIR/RPMS/*/${kib_rpm}-devel-*.rpm)
1691 if ! rpm2cpio < $rpm | cpio -id; then
1692 fatal 1 "could not unpack the $rpm."
1694 CONFIGURE_FLAGS="--with-o2ib=${o2ib_location} ${CONFIGURE_FLAGS}"
1700 local ofed_type="$1"
1701 local ofed_version="$2"
1704 if ! $PATCHLESS; then
1705 if $PATCHLESS_SERVER; then
1706 # need to find and unpack the vendor's own kernel-devel
1707 # for patchless server build
1708 if ! kernelrpm=$(find_linux_rpm "-$DEVEL_KERNEL_TYPE"); then
1709 fatal 1 "Could not find the kernel-$DEVEL_KERNEL_TYPE RPM in $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ"
1711 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm "$kernelrpm" "-"; then
1712 fatal 1 "Could not find the Linux tree in $kernelrpm"
1714 # download and unpack kernel-debuginfo-common (only in EL)
1715 if [[ $DISTROMAJ =~ rhel ]]; then
1716 local KERNEL_DEBUGINFO="kernel-debuginfo-common-${TARGET_ARCH}-${lnxmaj}-${lnxrel}.${TARGET_ARCH}.rpm"
1717 download_debuginfo_common "$KERNEL_DEBUGINFO"
1718 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm \
1719 "$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$KERNEL_DEBUGINFO"; then
1720 fatal 1 "Could not find the Linux debuginfo common rpm in $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH/$KERNEL_DEBUGINFO"
1724 local kernel_extra_version
1725 if ! kernel_extra_version=$(build_kernel_with_srpm ${STDOUT}); then
1726 fatal 1 "Failed to build the kernel from it's SRPM"
1729 local kernel_devel_rpm
1730 if ! kernel_devel_rpm=$(find_rpm "$TOPDIR/RPMS/${TARGET_ARCH}/" provides "^$(devel_kernel_name $KERNEL_LUSTRE_NAMING) ="); then
1731 fatal 1 "Failed to find a kernel development RPM in $TOPDIR/RPMS/${TARGET_ARCH}/"
1734 # install the -devel RPM in preparation for modules builds
1735 if ! lnxrel="$kernel_extra_version" unpack_linux_devel_rpm \
1736 "$TOPDIR/RPMS/${TARGET_ARCH}/$kernel_devel_rpm"; then
1737 fatal 1 "Could not find the Linux tree in $TOPDIR/RPMS/${TARGET_ARCH}/$kernel_devel_rpm"
1741 # need to find and unpack the vendor's own kernel-devel for patchless
1743 if ! kernelrpm=$(find_linux_rpm "-$DEVEL_KERNEL_TYPE"); then
1744 fatal 1 "Could not find the kernel-$DEVEL_KERNEL_TYPE RPM in $KERNELRPMSBASE/$lnxmaj/$DISTROMAJ"
1746 if ! lnxrel="$lnxrel" unpack_linux_devel_rpm "$kernelrpm" "-"; then
1747 fatal 1 "Could not find the Linux tree in $kernelrpm"
1751 # ~sigh~ have to make copies of and modify some of the rpm
1752 # infrastructure files so that find-requires can find our unpacked
1753 # kernel-devel artifacts
1754 cp $RPM_HELPERS_DIR/{symset-table,find-requires{,.ksyms}} .
1755 export FIND_REQUIRES="$(pwd)/find-requires"
1756 chmod 755 {symset-table,find-requires{,.ksyms}}
1758 tmp="${tmp//\//\\/}"
1759 ed find-requires <<EOF
1763 /|.*find-requires.ksyms/s/|/| bash -x/
1764 g/ [^ ]*\/\(find-requires\.ksyms\)/s// $tmp\/\1/g
1767 ed find-requires.ksyms <<EOF
1771 g/\/.*\/\(symset-table\)/s//$tmp\/\1/g
1772 g/\(\/usr\/src\/kernels\/\)/s//$tmp\/reused\1/g
1775 ed symset-table <<EOF
1779 g/\(\/boot\/\)/s//$tmp\/reused\1/g
1780 g/\(\/usr\/src\/kernels\/\)/s//$tmp\/reused\1/g
1784 build_ofed "${LINUXOBJ:-$LINUX}" "$ofed_type" "$ofed_version" ||
1785 fatal 1 "error building OFED"
1788 if build_lustre "$LINUX" "$LINUXOBJ"; then
1789 # the build worked. resolve any symlinked files (i.e. from reuse)
1790 # in RPMS/$arch to real files so that that that huge mess of
1791 # complication known as LTS can copy them yet somewhere else.
1792 # is it any wonder this whole process is so damn so? anyone ever
1793 # heard of hardlinks? it's this cool new thing that allows you save
1794 # tons of time and space by creating... well you can go read about
1795 # them if you have not heard about them yet.
1796 # can i say how much the implemenation of all of this really impedes
1799 for dir in RPMS/*; do
1801 for file in $(ls); do
1802 if [ -h $file ]; then
1809 # also, for i?86, make sure all of the RPMs are in RPMS/$TARGET_ARCH
1810 # as that's where LTS expects to find them
1811 for dir in RPMS/*; do
1812 if [ $dir = RPMS/$TARGET_ARCH ]; then
1817 if [ -n "$files" ]; then
1818 cp -al $files ../$TARGET_ARCH
1828 create_rpmbuild_dirs() {
1830 [ -d RPMS ] || mkdir RPMS
1831 [ -d RPMS/${TARGET_ARCH} ] || mkdir RPMS/${TARGET_ARCH}
1832 [ -d RPMS/noarch ] || mkdir RPMS/noarch
1833 [ -d BUILD ] || mkdir BUILD
1834 [ -d SOURCES ] || mkdir SOURCES
1835 [ -d SPECS ] || mkdir SPECS
1836 [ -d SRPMS ] || mkdir SRPMS
1858 [[ $list\ == *\ $item\ * ]]
1862 #########################################################################
1863 # Generate a backtrace through the call stack.
1867 #########################################################################
1871 local funcname="" sourcefile="" lineno="" n
1873 echo "Call stack: (most recent first)"
1874 for (( n = $strip ; n < ${#FUNCNAME[@]} ; ++n )) ; do
1875 funcname=${FUNCNAME[$n - 1]}
1876 sourcefile=$(basename ${BASH_SOURCE[$n]})
1877 lineno=${BASH_LINENO[$n - 1]}
1881 # Display function arguments
1882 if [[ ! -z "${BASH_ARGV[@]}" ]]; then
1883 local args newarg j p=0
1884 for (( j = ${BASH_ARGC[$n - 1]}; j > 0; j-- )); do
1885 newarg=${BASH_ARGV[$j + $p - 1]}
1886 args="${args:+${args} }'${newarg}'"
1888 let p+=${BASH_ARGC[$n - 1]}
1890 echo " ${funcname} ${args:+${args} }at ${sourcefile}:${lineno}"
1894 echo "BEGIN BACKTRACE"
1896 #echo ${BASH_LINENO[*]}
1897 #echo ${BASH_SOURCE[*]}
1898 #echo ${FUNCNAME[*]}
1899 local i=$((${#FUNCNAME[@]} - 1))
1900 while [ $i -ge 0 ]; do
1901 local lineno=${BASH_LINENO[$i]}
1905 local SOURCELINE="${BASH_SOURCE[$i + 1]}:${lineno}"
1906 # Can't figure out how to get function args from other frames...
1907 local FUNCTION="${FUNCNAME[$i]}()"
1908 echo "$SOURCELINE:$FUNCTION"
1912 echo "END BACKTRACE"
1918 seen_list=$(new_list)
1920 echo "An unexpected error has occurred at ${BASH_SOURCE[0]##*/}:$((LINENO-1)).
1921 Unfortunately the above line number in the message may or may not be correct,
1922 but details have been send to the lbuild maintainer. Attempting to continue."; (echo "Untrapped error"
1924 # have we seen this one
1925 echo "checking seen list for ${BASH_SOURCE[0]}:${BASH_LINENO[0]}"
1927 if is_list_member "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}"; then
1928 echo "seen this one already"
1930 seen_list=$(add_list "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}")
1933 ) ; set $xtrace' ERR
1936 [ -r ~/.lbuildrc ] && . ~/.lbuildrc
1938 options=$(getopt -o D:h -l kerneltree:,distro:,kernelrpm:,reusebuild:,\
1939 patchless,patchless-server,ccache,norpm,external-patches:,timestamp:,\
1940 extraversion:,kerneldir:,linux:,lustre:,nodownload,nosrc,noiokit,ofed-type:,\
1941 ofed-version:,mlnx-version:,ofed-src:,publish,disable-zfs,release,set-value:,\
1942 src,stage:,target:,with-linux:,xen -- "$@")
1944 if [ $? != 0 ]; then
1948 eval set -- "$options"
1979 if ! KERNELTREE=$(canon_path "$2"); then
1980 fatal 1 "Could not determine the canonical location of $2"
1984 --linux | --with-linux)
1985 if ! LINUX=$(canon_path "$2"); then
1986 fatal 1 "Could not determine the canonical location of $2"
1995 if ! REUSEBUILD=$(canon_path "$2"); then
1996 fatal 1 "Could not determine the canonical location of $2"
2012 PATCHLESS_SERVER=true
2016 if ! KERNELRPMSBASE=$(canon_path "$2"); then
2017 fatal 1 "Could not determine the canonical location of $2"
2026 if ! LUSTRE=$(canon_filepath "$2"); then
2027 fatal 1 "Could not determine the canonical location of $2"
2084 # there are actually some lustre configure flags that we need to
2085 # handle ourselves (but we still give them to configure)
2086 if [[ \ $@\ == *\ --disable-tests\ * ]]; then
2093 usage 1 "Unrecognized option: $1"
2104 if [ -n "$OFED_TYPE" -a "$OFED_TYPE" != "inkernel" ]; then
2105 download_ofed "$OFED_TYPE" "$OFED_VERSION"
2106 unpack_ofed "$OFED_TYPE" "$OFED_VERSION" || fatal 1 "Error unpacking OFED tarball"
2109 # make sure the RPM build environment is set up
2110 create_rpmbuild_dirs
2112 # if an unpacked kernel source tree was given on the command line
2113 # just build lustre with it (nothing distro kernel specific here)
2114 if [ -n "$LINUX" ]; then
2115 find_linux_release() {
2116 _find_linux_release $LINUX
2118 build_ofed "${LINUXOBJ:-$LINUX}" "$OFED_TYPE" "$OFED_VERSION" ||
2119 fatal 1 "error building OFED"
2120 build_lustre "$LINUX" "$LINUXOBJ"
2122 if [ ! -f "${LBUILD_DIR}/lbuild-$DISTROMAJ" ]; then
2123 fatal 1 "${LBUILD_DIR}/lbuild-$DISTROMAJ not found"
2125 source ${LBUILD_DIR}/lbuild-$DISTROMAJ
2126 build_with_srpm "$OFED_TYPE" "$OFED_VERSION" || fatal 1 "Failed to build_with_srpm"