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