+}
+
+build_kernel_ib() {
+ local linux="$1"
+
+ # build kernel-ib{,-devel}
+ local K_SRC="K_SRC"
+ # ofed 1.3 had a bug in the rpm spec
+ if [ "$OFED_VERSION" = "1.3" ]; then
+ K_SRC="KSRC"
+ fi
+
+ local OFED_CORE="--with-core-mod --with-ipoib-mod --with-sdp-mod --with-user_mad-mod --with-user_access-mod --with-addr_trans-mod --with-rds-mod --with-qlgc_vnic-mod --with-madeye-mod"
+ local OFED_HARDWARE="--with-mthca-mod --with-mlx4-mod --with-mlx4_en-mod --with-cxgb3-mod --with-nes-mod"
+ # some I/B drivers are architecture dependent and kernel-ib's configure
+ # does not figure it out for us ~sigh~
+ case "$TARGET_ARCH" in
+ ppc64)
+ OFED_HARDWARE="$OFED_HARDWARE --with-ehca-mod"
+ ;;
+ esac
+ # we're no longer shipping the OFED iSCSI
+ #OFED_ISCSI="--with-srp-mod --with-srp-target-mod"
+ ## ISER module has no backport support as of OFED 1.5 (i.e. only builds on
+ ##kernels >= 2.6.30)
+ #if [[ $OFED_VERSION = 1.[0-4]* ]]; then
+ # OFED_ISCSI="$OFED_ISCSI --with-iser-mod"
+ #fi
+
+ # assume we are just rebuilding the SRPM
+ local BUILD_TYPE=${BUILD_TYPE:-"--rebuild"}
+ local SOURCE="${TOPDIR}/OFED/SRPMS/ofa_kernel-*.src.rpm"
+
+ # but switch to building from the SPEC if we need to apply patches
+ if ls ${TOPDIR}/lustre/build/patches/ofed/* >/dev/null; then
+ BUILD_TYPE="-bb"
+ rpm --define "_topdir ${TOPDIR}" -ivh $SOURCE
+ SOURCE="${TOPDIR}/SPECS/ofa_kernel.spec"
+ local file ed_fragment1 ed_fragment2 n=1
+ for file in $(ls ${TOPDIR}/lustre/build/patches/ofed/*); do
+ ed_fragment1="$ed_fragment1
+Patch$n: ${file%%*/}"
+ ed_fragment2="$ed_fragment2
+%patch$n -p0"
+ cp $file ${TOPDIR}/SOURCES
+ let n=$n+1
+ done
+
+ if [ $n -gt 1 ]; then
+ ed $SOURCE <<EOF
+/^Source: /a
+$ed_fragment1
+.
+/^%setup /a
+$ed_fragment2
+.
+wq
+EOF
+ fi
+ fi
+
+ local linuxrelease=$(find_linux_release "$linux")
+ if ! $RPMBUILD $BUILD_TYPE --define 'build_kernel_ib 1' --define 'build_kernel_ib_devel 1' \
+ ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \
+ --define "_topdir ${TOPDIR}" --target ${TARGET_ARCH} \
+ --define "KVERSION ${linuxrelease}" \
+ --define "$K_SRC ${linux}" \
+ --define "LIB_MOD_DIR /lib/modules/${linuxrelease}/updates" \
+ ${OFA_KERNEL_RELEASE:+--define "_release $OFA_KERNEL_RELEASE"} \
+ --define "configure_options --without-quilt $OFED_CORE $OFED_HARDWARE $OFED_ISCSI" \
+ ${SOURCE} 2>&1; then
+ fatal 1 "Error building kernel-ib"
+ fi
+
+}
+
+store_for_reuse() {
+ local articles="$1"
+ local module="$2"
+ local location="$3"
+ local signature="$4"
+ local use_links="$5"
+
+ local linkflag=""
+ if $use_links; then
+ linkflag="l"
+ fi
+
+ location="$location"/"$signature"/"$module"
+ mkdir -p "$location"
+ # the cleanup script removes any directory that doesn't have a
+ # .lastused, so let's try to prevent that as soon as we can
+ # this solution still slightly racy with the cleanup script
+ # but the race is a lot tighter now
+ touch -t 197001010000 "$location/.lastused"
+ ## use eval/echo here to make sure shell expansions are performed
+ #if ! cp -a${linkflag} $(eval echo $articles) "$location"; then
+ local article
+ for article in $(eval echo $articles); do
+ if ! cp -a${linkflag} "$article" "$location"; then
+ error "Failed to copy \"$article\" to \"$location\" in store_for_reuse()"
+ # rename the cache location so that it's not cached
+ # product, but is around for analysis
+ mv "$location"{,-bad-$(date +%s)} ||
+ error "failed to clean up a failed cache attempt" \
+ "in \"$location\" -- manual cleanup will be" \
+ "necessary"
+ return 1