From a6644f49a5af1dae5de7c87b704c8a7bee2ccf87 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Thu, 5 Aug 2010 11:15:09 -0700 Subject: [PATCH] Add cleanup option -c to zconfig.sh Several folks have now remarked that when the regression tests fail they leave a mess behind. This was done intentionally at the time to facilitate debugging the wreckage. However, this also means that you may need to do some manual cleanup such as removing the loopback devices before re-running the tests. To simplify this proceedure I've added the '-c' option to zconfig.sh which will attempt to cleanup the mess from a previous test before starting. This is somewhat dangerous because it must guess as to which loopback devices you were using. But this risk is fairly minimal because devices which are currently still is use can not be cleaned up. And because only devices with 'zpool' in the name are considered for removal. That said if your running parallel copies of say zconfig.sh this may cause you some trouble. --- scripts/common.sh.in | 19 +++++++++++++++++++ scripts/zconfig.sh | 14 ++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/scripts/common.sh.in b/scripts/common.sh.in index bb602474b0..00418696c8 100644 --- a/scripts/common.sh.in +++ b/scripts/common.sh.in @@ -15,6 +15,7 @@ MODULES=(zlib_deflate spl splat zavl znvpair zunicode zcommon zfs) fi PROG="" +CLEANUP= VERBOSE= VERBOSE_FLAG= FORCE= @@ -207,6 +208,24 @@ unused_loop_device() { die "Error: Unable to find unused loopback device" } +# +# This can be slightly dangerous because the loop devices we are +# cleanup up may not be ours. However, if the devices are currently +# in use we will not be able to remove them, and we only remove +# devices which include 'zpool' in the name. So any damage we might +# do should be limited to other zfs related testing. +# +cleanup_loop_devices() { + local TMP_FILE=`mktemp` + + ${LOSETUP} -a | tr -d '()' >${TMP_FILE} + ${AWK} -F":" -v losetup="$LOSETUP" \ + '/zpool/ { system("losetup -d "$1) }' ${TMP_FILE} + ${AWK} -F" " '/zpool/ { system("rm -f "$3) }' ${TMP_FILE} + + rm -f ${TMP_FILE} +} + # # The following udev helper functions assume that the provided # udev rules file will create a /dev/disk/zpool/ diff --git a/scripts/zconfig.sh b/scripts/zconfig.sh index 0220d9f5fa..c671206186 100755 --- a/scripts/zconfig.sh +++ b/scripts/zconfig.sh @@ -16,7 +16,7 @@ PROG=zconfig.sh usage() { cat << EOF USAGE: -$0 [hv] +$0 [hvc] DESCRIPTION: ZFS/ZPOOL configuration tests @@ -24,11 +24,12 @@ DESCRIPTION: OPTIONS: -h Show this message -v Verbose + -c Cleanup lo+file devices at start EOF } -while getopts 'hv' OPTION; do +while getopts 'hvc?' OPTION; do case $OPTION in h) usage @@ -37,6 +38,9 @@ while getopts 'hv' OPTION; do v) VERBOSE=1 ;; + c) + CLEANUP=1 + ;; ?) usage exit @@ -48,6 +52,12 @@ if [ $(id -u) != 0 ]; then die "Must run as root" fi +# Perform pre-cleanup is requested +if [ ${CLEANUP} ]; then + cleanup_loop_devices + rm -f /tmp/zpool.cache.* +fi + zconfig_partition() { local DEVICE=$1 local START=$2