Skip to content

Commit

Permalink
Add a mechanishm to avoid building rust in tmpfs.
Browse files Browse the repository at this point in the history
- TMPFS_BLACKLIST should contain a list of package globs
- TMPFS_BLACKLIST_TMPDIR should contain a host directory prefix where
  temporary directories can be created, outside tmpfs of course, to be
  used as the WRKDIR for packages in TMPFS_BLACKLIST.

Fixes #888
  • Loading branch information
bdrewery committed Nov 24, 2021
1 parent 0237303 commit 56233a1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/etc/poudriere.conf.sample
Expand Up @@ -62,6 +62,15 @@ USE_TMPFS=yes
# (default: none)
#TMPFS_LIMIT=8

# List of package globs that are not allowed to use tmpfs for their WRKDIR
# Note that you *must* set TMPFS_BLACKLIST_TMPDIR
# EXAMPLE: TMPFS_BLACKLIST="rust"

# The host path where tmpfs-blacklisted packages can be built in.
# A temporary directory will be generated here and be null-mounted as the
# WRKDIR for any packages listed in TMPFS_BLACKLIST.
# EXAMPLE: TMPFS_BLACKLIST_TMPDIR=${BASEFS}/data/cache/tmp

# How much memory to limit jail processes to for *each builder*
# in GiB (default: none)
#MAX_MEMORY=8
Expand Down
36 changes: 36 additions & 0 deletions src/share/poudriere/common.sh
Expand Up @@ -4633,6 +4633,16 @@ stop_builders() {
parallel_run stop_builder "${j}"
done
parallel_stop

if [ -n "${TMPFS_BLACKLIST_TMPDIR-}" ] &&
[ -d "${TMPFS_BLACKLIST_TMPDIR}/wrkdirs" ]; then
if ! rm -rf "${TMPFS_BLACKLIST_TMPDIR}/wrkdirs/"*; then
chflags -R 0 \
"${TMPFS_BLACKLIST_TMPDIR}/wkrdirs"/* || :
rm -rf "${TMPFS_BLACKLIST_TMPDIR}/wrkdirs"/* ||
:
fi
fi
fi

# No builders running, unset JOBS
Expand Down Expand Up @@ -5006,6 +5016,7 @@ build_pkg() {
local log
local errortype
local ret=0
local tmpfs_blacklist_dir
local elapsed now pkgname_varname jpkg originspec

_my_path mnt
Expand Down Expand Up @@ -5052,11 +5063,30 @@ build_pkg() {
:> "${mnt}/${LOCALBASE:-/usr/local}/.mounted"
fi

if [ -f "${mnt}/.tmpfs_blacklist_dir" ]; then
umount "${mnt}/wrkdirs"
rm -rf $(cat "${mnt}/.tmpfs_blacklist_dir")
fi
[ -f ${mnt}/.need_rollback ] && rollbackfs prepkg ${mnt}
[ -f ${mnt}/.need_rollback ] && \
err 1 "Failed to rollback ${mnt} to prepkg"
:> ${mnt}/.need_rollback

for jpkg in ${TMPFS_BLACKLIST-}; do
case "${pkgname%-*}" in
${jpkg})
mkdir -p "${TMPFS_BLACKLIST_TMPDIR:?}/wrkdirs"
tmpfs_blacklist_dir=$(\
TMPDIR="${TMPFS_BLACKLIST_TMPDIR:?}/wrkdirs" \
mktemp -dt "${pkgname}")
${NULLMOUNT} "${tmpfs_blacklist_dir}" "${mnt}/wrkdirs"
echo "${tmpfs_blacklist_dir}" \
> "${mnt}/.tmpfs_blacklist_dir"
break
;;
esac
done

rm -rfx ${mnt}/wrkdirs/* || :

log_start "${pkgname}" 0
Expand Down Expand Up @@ -5135,6 +5165,12 @@ build_pkg() {
-DNOCLEANDEPENDS clean ${MAKE_ARGS} || :
rm -rfx ${mnt}/wrkdirs/* || :

if [ -n "${tmpfs_blacklist_dir}" ]; then
umount "${mnt}/wrkdirs"
rm -f "${mnt}/.tmpfs_blacklist_dir"
rm -rf "${tmpfs_blacklist_dir}"
fi

clean_pool "${pkgname}" "${originspec}" "${clean_rdepends}"

stop_build "${pkgname}" "${originspec}" ${build_failed}
Expand Down

0 comments on commit 56233a1

Please sign in to comment.