From dda140e0543254c4085db4ff1dacb2aa46303ae8 Mon Sep 17 00:00:00 2001 From: Janpieter Sollie Date: Sat, 18 Nov 2023 14:37:51 +0100 Subject: [PATCH] ktest: use overlays to store arch-specific bcachefs-tools build when running tests, eg test1 on arch 1, and then on arch 2, the whole bcachefs-tools package needs to be rebuilt: all binaries of arch 1 need to be erased, and recompiled for arch 2 when going back to arch 1, it happens again This patch fixes the issue by applying a arch-specific overlay, so bcachefs-tools doesn't need a full rebuild every time. The overlay is mounted via fuse-overlay. If this isn't available, it will fall back to rsync, causing a larger waste of disk space, and not-applied-immediately git commits. Signed-of-by: jpsollie --- lib/common.sh | 2 ++ tests/bcachefs/bcachefs-test-libs.sh | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/common.sh b/lib/common.sh index 0015c6fa..68982700 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -19,6 +19,8 @@ ktest_exit() fi [[ -n $ktest_tmp ]] && rm -rf "$ktest_tmp" + #umount overlayfs of bcachefs-tools if needed + [[ -n $ktest_tmp && $(grep bcachefs-tools-$ktest_arch /proc/mounts) ]] && umount $(grep bcachefs-tools-$ktest_arch /proc/mounts | cut -d' ' -f 2) true } diff --git a/tests/bcachefs/bcachefs-test-libs.sh b/tests/bcachefs/bcachefs-test-libs.sh index 90c36b6f..f6461b5f 100644 --- a/tests/bcachefs/bcachefs-test-libs.sh +++ b/tests/bcachefs/bcachefs-test-libs.sh @@ -7,16 +7,32 @@ . $(dirname $(readlink -e "${BASH_SOURCE[0]}"))/../test-libs.sh bch_loc=$(dirname $(readlink -e "${BASH_SOURCE[0]}"))/bcachefs-tools -require-git http://evilpiepirate.org/git/bcachefs-tools.git -if [[ ! -f "${bch_loc}/.last_arch_for_compile" || "$(cat ${bch_loc}/.last_arch_for_compile)" != $ktest_arch ]]; then +declare -A ov_dirs=(["tmp"]="${bch_loc}/../.tmp-bcachefs-tools-overlay" \ + ["diff"]="${bch_loc}/../.bcachefs-tools-overlay-${ktest_arch}" \ + ["merge"]="${bch_loc}/../bcachefs-tools-${ktest_arch}") + +for dir_overlay in ${ov_dirs[@]}; do + if [[ ! -d ${dir_overlay} ]]; then mkdir -p ${dir_overlay}; fi +done + +if [[ $(which fuse-overlayfs) && ! $(grep bcachefs-tools-$ktest_arch /proc/mounts) ]]; then + fuse-overlayfs -o lowerdir=${bch_loc},upperdir=${ov_dirs["diff"]},workdir=${ov_dirs["tmp"]} ${ov_dirs["merge"]} +elif [[ ! $(grep bcachefs-tools-$ktest_arch /proc/mounts) ]]; then + rsync -av ${bch_loc}/ ${ov_dirs["merge"]}/ +fi + +bch_loc=$(dirname $(readlink -e "${BASH_SOURCE[0]}"))/bcachefs-tools-${ktest_arch} + +if [[ ! -f "${bch_loc}/.last_arch_for_compile" || "$(cat ${bch_loc}/.last_arch_for_compile)" != ${ktest_arch} ]]; then make -C ${bch_loc} clean >/dev/null 2>&1; rm -rf "${bch_loc}/rust-src/target/*"; find ${bch_loc} -name "*.o" -exec rm {} \; find ${bch_loc} -name "*.a" -exec rm {} \; echo $ktest_arch > ${bch_loc}/.last_arch_for_compile fi -require-make bcachefs-tools +require-git http://evilpiepirate.org/git/bcachefs-tools.git +require-make bcachefs-tools-${ktest_arch} require-kernel-config BCACHEFS_FS if [[ ! -v NO_BCACHEFS_DEBUG ]]; then