[sheepdog] [PATCH 5/9] tests: introduce helpers to create loopback devices
MORITA Kazutaka
morita.kazutaka at lab.ntt.co.jp
Mon Sep 17 00:59:58 CEST 2012
This prepares for the next patches
Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
tests/011 | 41 +++--------------------------------------
tests/common.rc | 45 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 38 deletions(-)
diff --git a/tests/011 b/tests/011
index 4e8c30a..803ace7 100755
--- a/tests/011
+++ b/tests/011
@@ -9,52 +9,17 @@ here=`pwd`
tmp=/tmp/$$
status=1 # failure is the default!
-trap "_cleanup_devices; exit \$status" 0 1 2 3 15
-
# get standard environment, filters and checks
. ./common.rc
. ./common.filter
-_cleanup_devices()
-{
- _kill_all_collies
- _kill_all_sheeps
-
- sleep 1
-
- for i in 0 1 2; do
- umount $STORE/$i
- rm -f $STORE/$i.img
- done
- rm $seq.full
-}
-
_cleanup
-dd if=/dev/zero of=$STORE/0.img seek=$((2 * 1024 ** 3 - 1)) bs=1 count=1 > $seq.full 2>&1
-dd if=/dev/zero of=$STORE/1.img seek=$((4 * 1024 ** 3 - 1)) bs=1 count=1 > $seq.full 2>&1
-dd if=/dev/zero of=$STORE/2.img seek=$((8 * 1024 ** 3 - 1)) bs=1 count=1 > $seq.full 2>&1
-
-fstype="$(df -T / | tail -1 | awk '{print $2}')"
-case $fstype in
- ext2)
- mkops="-t $fstype -q -F"
- ;;
- ext[3-4])
- mkops="-t $fstype -q -F -J size=4"
- ;;
- xfs)
- mkops="-t $fstype -f"
- ;;
- *)
- _die "For now we only support xfs and ext*."
- ;;
-esac
+_make_device 0 $((2 * 1024 ** 3))
+_make_device 1 $((4 * 1024 ** 3))
+_make_device 2 $((8 * 1024 ** 3))
for i in 0 1 2; do
- mkfs $mkops $STORE/$i.img > $seq.full
- mkdir $STORE/$i
- mount -o loop $STORE/$i.img $STORE/$i
_start_sheep $i
done
diff --git a/tests/common.rc b/tests/common.rc
index 4f29bbc..99b31c4 100644
--- a/tests/common.rc
+++ b/tests/common.rc
@@ -123,6 +123,8 @@ _cleanup()
_kill_all_collies
_kill_all_sheeps
+ _cleanup_devices
+
mkdir -p $STORE
for i in $STORE/?; do
rm -rf $i
@@ -286,5 +288,48 @@ _cleanup_machine_simulation()
iptables -D INPUT -p tcp --dport $((7000+$1)) -j DROP
}
+_make_device()
+{
+ idx=$1; shift
+ size=$1; shift
+ args=$@
+
+ dd if=/dev/zero of=$STORE/$idx.img seek=$(($size - 1)) bs=1 count=1 > $seq.full 2>&1
+ if [ $? != 0 ]; then
+ _die "failed to create $STORE/$idx.img"
+ fi
+
+ fstype="$(df -T / | tail -1 | awk '{print $2}')"
+ case $fstype in
+ ext2)
+ mkops="-t $fstype -q -F"
+ mntops="-o user_xattr"
+ ;;
+ ext[3-4])
+ mkops="-t $fstype -q -F -J size=4"
+ mntops="-o user_xattr"
+ ;;
+ xfs)
+ mkops="-t $fstype -f"
+ mntops=""
+ ;;
+ *)
+ _die "For now we only support xfs and ext*."
+ ;;
+ esac
+
+ mkfs $mkops $STORE/$idx.img > $seq.full
+ mkdir $STORE/$idx
+ mount -o loop $mntops $args $STORE/$idx.img $STORE/$idx
+}
+
+_cleanup_devices()
+{
+ for d in `mount | grep -o $STORE/.`; do
+ umount -l $d
+ rm -f $d.img
+ done
+}
+
# make sure this script returns success
/bin/true
--
1.7.2.5
More information about the sheepdog
mailing list