2008-09-29 19:59:19 +04:00
# Copyright (C) 2008 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
test_description = "foo" # silence test-lib for now
. ./test-lib.sh
aux( ) {
2008-10-14 23:48:01 +04:00
# use just "$@" for verbose operation
" $@ " > /dev/null 2> /dev/null
2008-10-06 20:55:30 +04:00
#"$@"
2008-09-29 19:59:19 +04:00
}
2008-10-06 20:55:30 +04:00
STACKTRACE( ) {
trap - ERR;
i = 0;
while FUNC = ${ FUNCNAME [ $i ] } ; test " $FUNC " != "main" ; do
echo " $i ${ FUNC } () called from ${ BASH_SOURCE [ $i ] } : ${ BASH_LINENO [ $i ] } "
i = $(( $i + 1 )) ;
done
}
2008-09-29 19:59:19 +04:00
teardown( ) {
2008-10-14 23:48:01 +04:00
echo $LOOP
echo $PREFIX
test -n " $PREFIX " && {
2008-12-10 19:16:53 +03:00
rm -rf $G_root_ /dev/$PREFIX *
2008-10-14 23:48:01 +04:00
while dmsetup table | grep -q ^$PREFIX ; do
2009-05-13 23:18:47 +04:00
for s in ` dmsetup table | grep ^$PREFIX | awk '{ print substr($1,1,length($1)-1) }' ` ; do
2008-10-14 23:48:01 +04:00
dmsetup resume $s 2>/dev/null > /dev/null || true
dmsetup remove $s 2>/dev/null > /dev/null || true
done
done
}
2008-09-29 19:59:19 +04:00
2008-10-14 23:48:01 +04:00
test -n " $LOOP " && losetup -d $LOOP
test -n " $LOOPFILE " && rm -f $LOOPFILE
2009-01-09 13:16:57 +03:00
}
2008-09-29 19:59:19 +04:00
2009-01-09 13:16:57 +03:00
teardown_( ) {
teardown
2008-10-14 23:48:01 +04:00
cleanup_ # user-overridable cleanup
testlib_cleanup_ # call test-lib cleanup routine, too
2008-09-29 19:59:19 +04:00
}
make_ioerror( ) {
2008-10-14 23:48:01 +04:00
echo 0 10000000 error | dmsetup create ioerror
dmsetup resume ioerror
2008-12-10 19:16:53 +03:00
ln -s $G_dev_ /mapper/ioerror $G_dev_ /ioerror
2008-09-29 19:59:19 +04:00
}
prepare_loop( ) {
2008-10-14 23:48:01 +04:00
size = $1
test -n " $size " || size = 32
2008-09-29 19:59:19 +04:00
2008-10-14 23:48:01 +04:00
test -n " $LOOP " && return 0
2009-01-09 13:16:57 +03:00
trap 'aux teardown_' EXIT # don't forget to clean up
2008-10-06 20:55:30 +04:00
trap 'set +vex; STACKTRACE; set -vex' ERR
#trap - ERR
LOOPFILE = " $PWD /test.img "
dd if = /dev/zero of = " $LOOPFILE " bs = $(( 1024 * 1024 )) count = 1 seek = $(( $size - 1 ))
if LOOP = ` losetup -s -f " $LOOPFILE " 2>/dev/null` ; then
return 0
elif LOOP = ` losetup -f` && losetup $LOOP " $LOOPFILE " ; then
# no -s support
return 0
else
# no -f support
2008-12-05 08:03:23 +03:00
# Iterate through $G_dev_/loop{,/}{0,1,2,3,4,5,6,7}
2008-10-06 20:55:30 +04:00
for slash in '' /; do
2008-12-05 08:03:23 +03:00
for i in 0 1 2 3 4 5 6 7; do
2008-10-06 20:55:30 +04:00
local dev = $G_dev_ /loop$slash $i
! losetup $dev >/dev/null 2>& 1 || continue
# got a free
losetup " $dev " " $LOOPFILE "
LOOP = $dev
2008-12-05 08:03:23 +03:00
break
2008-10-06 20:55:30 +04:00
done
2008-12-05 08:03:23 +03:00
if [ -n " $LOOP " ] ; then
break
fi
2008-10-06 20:55:30 +04:00
done
2008-11-04 17:38:53 +03:00
test -n " $LOOP " # confirm or fail
return 0
2008-10-06 20:55:30 +04:00
fi
2008-11-04 17:38:53 +03:00
exit 1 # should not happen
2008-09-29 19:59:19 +04:00
}
prepare_devs( ) {
2008-10-14 23:48:01 +04:00
local n = " $1 "
test -z " $n " && n = 3
local devsize = " $2 "
test -z " $devsize " && devsize = 33
2009-05-13 23:18:47 +04:00
local pvname = " $3 "
test -z " $pvname " && pvname = "pv"
2008-10-14 23:48:01 +04:00
prepare_loop $(( $n * $devsize ))
PREFIX = " LVMTEST $$ "
2008-12-05 08:03:23 +03:00
if ! loopsz = ` blockdev --getsz $LOOP 2>/dev/null` ; then
loopsz = ` blockdev --getsize $LOOP 2>/dev/null`
fi
2008-10-14 23:48:01 +04:00
local size = $(( $loopsz / $n ))
for i in ` seq 1 $n ` ; do
2009-05-13 23:18:47 +04:00
local name = " ${ PREFIX } $pvname $i "
2008-10-14 23:48:01 +04:00
local dev = " $G_dev_ /mapper/ $name "
eval " dev $i = $dev "
devs = " $devs $dev "
echo 0 $size linear $LOOP $(( ( $i - 1 ) * $size )) > $name .table
dmsetup create $name $name .table
dmsetup resume $name
done
2008-09-29 19:59:19 +04:00
# set up some default names
2008-10-14 23:48:01 +04:00
vg = ${ PREFIX } vg
vg1 = ${ PREFIX } vg1
vg2 = ${ PREFIX } vg2
lv = LV
lv1 = LV1
lv2 = LV2
lv3 = LV3
2008-09-29 19:59:19 +04:00
}
disable_dev( ) {
2008-10-14 23:48:01 +04:00
for dev in " $@ " ; do
2008-09-29 19:59:19 +04:00
# first we make the device inaccessible
2008-10-14 23:48:01 +04:00
echo 0 10000000 error | dmsetup load $dev
dmsetup resume $dev
2008-09-29 19:59:19 +04:00
# now let's try to get rid of it if it's unused
#dmsetup remove $dev
2008-10-14 23:48:01 +04:00
done
2008-09-29 19:59:19 +04:00
}
enable_dev( ) {
2008-10-14 23:48:01 +04:00
for dev in " $@ " ; do
local name = ` echo " $dev " | sed -e 's,.*/,,' `
dmsetup create $name $name .table || dmsetup load $name $name .table
dmsetup resume $dev
done
2008-09-29 19:59:19 +04:00
}
2009-01-09 13:16:57 +03:00
backup_dev( ) {
for dev in " $@ " ; do
dd if = $dev of = $dev .backup bs = 1024
done
}
restore_dev( ) {
for dev in " $@ " ; do
test -e $dev .backup || {
echo " Internal error: $dev not backed up, can't restore! "
exit 1
}
dd of = $dev if = $dev .backup bs = 1024
done
}
2008-09-29 19:59:19 +04:00
prepare_pvs( ) {
2008-10-14 23:48:01 +04:00
prepare_devs " $@ "
pvcreate $devs
2008-09-29 19:59:19 +04:00
}
prepare_vg( ) {
2008-10-14 23:48:01 +04:00
prepare_pvs " $@ "
vgcreate $vg $devs
2008-09-29 19:59:19 +04:00
}
prepare_lvmconf( ) {
2008-10-14 23:48:01 +04:00
cat > $G_root_ /etc/lvm.conf <<-EOF
2008-09-29 19:59:19 +04:00
devices {
dir = " $G_dev_ "
scan = " $G_dev_ "
2009-04-24 12:00:48 +04:00
filter = [ "a/dev\/mirror/" , " a/dev\/mapper\/.*pv[0-9_]* $/ " , "r/.*/" ]
2008-09-29 19:59:19 +04:00
cache_dir = " $G_root_ /etc "
sysfs_scan = 0
}
log {
verbose = $verboselevel
syslog = 0
indent = 1
}
backup {
backup = 0
archive = 0
}
global {
library_dir = " $G_root_ /lib "
2008-11-10 15:36:23 +03:00
locking_dir = " $G_root_ /var/lock/lvm "
2008-09-29 19:59:19 +04:00
}
EOF
}
2008-10-06 20:55:30 +04:00
set -vexE
2008-09-29 19:59:19 +04:00
aux prepare_lvmconf