Blame SOURCES/parted-3.1-tests-cleanup-losetup-usage.patch

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