From a1aa9eb26f357bb1a5111eb332594dfb7b39ace0 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Mon, 15 Oct 2012 17:27:18 -0700 Subject: [PATCH 1/2] tests: cleanup losetup usage The unsafe_losetup_ function was failing because losetup didn't recognize that the 'private' /dev/loopX devices were the same as /dev/loopX, it would fail even if one was in use. Switch to using losetup --show which is a cleaner solution. Also use sparse file for loop_setup to save space. --- tests/lvm-utils.sh | 24 ++---------------------- tests/t-lvm.sh | 24 ++---------------------- tests/t6001-psep.sh | 8 ++------ tests/t6003-dm-uuid.sh | 3 +-- 4 files changed, 7 insertions(+), 52 deletions(-) diff --git a/tests/lvm-utils.sh b/tests/lvm-utils.sh index 456d265..a204b08 100644 --- a/tests/lvm-utils.sh +++ b/tests/lvm-utils.sh @@ -16,34 +16,14 @@ export LVM_SUPPRESS_FD_WARNINGS=1 ME=$(basename "$0") warn() { echo >&2 "$ME: $@"; } -unsafe_losetup_() -{ - f=$1 - - test -n "$G_dev_" \ - || fail_ "Internal error: unsafe_losetup_ called before init_root_dir_" - - # Iterate through $G_dev_/loop{,/}{0,1,2,3,4,5,6,7,8,9} - for slash in '' /; do - for i in 0 1 2 3 4 5 6 7 8 9; do - dev=$G_dev_/loop$slash$i - losetup $dev > /dev/null 2>&1 && continue; - losetup "$dev" "$f" > /dev/null && { echo "$dev"; return 0; } - break - done - done - - return 1 -} - loop_setup_() { file=$1 - dd if=/dev/zero of="$file" bs=1M count=1 seek=1000 > /dev/null 2>&1 \ + dd if=/dev/null of="$file" bs=1M count=1 seek=1000 > /dev/null 2>&1 \ || { warn "loop_setup_ failed: Unable to create tmp file $file"; return 1; } # NOTE: this requires a new enough version of losetup - dev=$(unsafe_losetup_ "$file") \ + dev=$(losetup --show -f "$file") 2>/dev/null \ || { warn "loop_setup_ failed: Unable to create loopback device"; return 1; } echo "$dev" diff --git a/tests/t-lvm.sh b/tests/t-lvm.sh index b08f934..3c7657b 100644 --- a/tests/t-lvm.sh +++ b/tests/t-lvm.sh @@ -16,34 +16,14 @@ export LVM_SUPPRESS_FD_WARNINGS=1 ME=$(basename "$0") warn() { echo >&2 "$ME: $@"; } -unsafe_losetup_() -{ - f=$1 - - test -n "$G_dev_" \ - || error "Internal error: unsafe_losetup_ called before init_root_dir_" - - # Iterate through $G_dev_/loop{,/}{0,1,2,3,4,5,6,7,8,9} - for slash in '' /; do - for i in 0 1 2 3 4 5 6 7 8 9; do - dev=$G_dev_/loop$slash$i - losetup $dev > /dev/null 2>&1 && continue; - losetup "$dev" "$f" > /dev/null && { echo "$dev"; return 0; } - break - done - done - - return 1 -} - loop_setup_() { file=$1 - dd if=/dev/zero of="$file" bs=1M count=1 seek=1000 > /dev/null 2>&1 \ + dd if=/dev/null of="$file" bs=1M count=1 seek=1000 > /dev/null 2>&1 \ || { warn "loop_setup_ failed: Unable to create tmp file $file"; return 1; } # NOTE: this requires a new enough version of losetup - dev=$(unsafe_losetup_ "$file" 2>/dev/null) \ + dev=$(losetup --show -f "$file") 2>/dev/null \ || { warn "loop_setup_ failed: Unable to create loopback device"; return 1; } echo "$dev" diff --git a/tests/t6001-psep.sh b/tests/t6001-psep.sh index 490c6d2..1859ac9 100644 --- a/tests/t6001-psep.sh +++ b/tests/t6001-psep.sh @@ -44,14 +44,10 @@ cleanup_fn_() { # create a file of size N bytes N=10M -# create the test file -f1=$(pwd)/1; dd if=/dev/null of=$f1 bs=1 seek=$N 2> /dev/null || fail=1 -f2=$(pwd)/2; dd if=/dev/null of=$f2 bs=1 seek=$N 2> /dev/null || fail=1 - -d1=$(loop_setup_ "$f1") \ +f1=$(pwd)/1; d1=$(loop_setup_ "$f1") \ || skip_ "is this partition mounted with 'nodev'?" -d2=$(loop_setup_ "$f2") \ +f2=$(pwd)/2 ;d2=$(loop_setup_ "$f2") \ || skip_ "is this partition mounted with 'nodev'?" dmsetup_cmd="0 `blockdev --getsz $d1` linear $d1 0" diff --git a/tests/t6003-dm-uuid.sh b/tests/t6003-dm-uuid.sh index 1751cb4..f58cb06 100755 --- a/tests/t6003-dm-uuid.sh +++ b/tests/t6003-dm-uuid.sh @@ -36,8 +36,7 @@ cleanup_() { } # create a file large enough to hold a GPT partition table -dd if=/dev/null of=$loop_file bs=$ss seek=$ns || framework_failure -dev=$(losetup --show -f $loop_file) || framework_failure +dev=$(loop_setup_ $loop_file) || framework_failure dmsetup create $dm_name --table "0 $ns linear $dev 0" || framework_failure dmsetup rename $dm_name --setuuid f139317b-f98a-45d7-ab3b-9b4e0a336872 || framework_failure -- 1.7.11.4