parted/0043-tests-cleanup-losetup-usage.patch

84 lines
2.5 KiB
Diff
Raw Normal View History

From 2ab9f04692e74c8b1daae68f1c22c5723f6c39ef Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl@redhat.com>
Date: Wed, 17 Oct 2012 21:42:12 +0200
Subject: [PATCH 43/89] 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/t-lvm.sh (unsafe_losetup_): Remove function.
(loop_setup_): Use losetup's --show option instead.
Use dd with /dev/null, not /dev/zero.
* tests/t6001-psep.sh: Use loop_setup_ rather than losetup --show.
---
tests/t-lvm.sh | 23 ++---------------------
tests/t6001-psep.sh | 8 ++------
2 files changed, 4 insertions(+), 27 deletions(-)
diff --git a/tests/t-lvm.sh b/tests/t-lvm.sh
index cf1b8b8..001523b 100644
--- a/tests/t-lvm.sh
+++ b/tests/t-lvm.sh
@@ -13,33 +13,14 @@
export LVM_SUPPRESS_FD_WARNINGS=1
-unsafe_losetup_()
-{
- f=$1
-
- G_dev_=/dev
-
- # 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 1>&2 && 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") \
|| { 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"
--
1.8.5.3