1 # Copyright (C) 2008 Red Hat, Inc. All rights reserved.
3 # This copyrighted material is made available to anyone wishing to use,
4 # modify, copy, or redistribute it subject to the terms and conditions
5 # of the GNU General Public License v.2.
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software Foundation,
9 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
11 test_description
="foo" # silence test-lib for now
15 # use just "$@" for verbose operation
16 "$@" > /dev
/null
2> /dev
/null
23 while FUNC
=${FUNCNAME[$i]}; test "$FUNC" != "main"; do
24 echo "$i ${FUNC}() called from ${BASH_SOURCE[$i]}:${BASH_LINENO[$i]}"
33 test -n "$PREFIX" && {
34 rm -rf $G_root_/dev
/$PREFIX*
35 while dmsetup table |
grep -q ^
$PREFIX; do
36 for s
in `dmsetup table | grep ^$PREFIX| awk '{ print substr($1,1,length($1)-1) }'`; do
37 dmsetup resume
$s 2>/dev
/null
> /dev
/null || true
38 dmsetup remove
$s 2>/dev
/null
> /dev
/null || true
43 test -n "$LOOP" && losetup
-d $LOOP
44 test -n "$LOOPFILE" && rm -f $LOOPFILE
49 cleanup_
# user-overridable cleanup
50 testlib_cleanup_
# call test-lib cleanup routine, too
54 echo 0 10000000 error | dmsetup create ioerror
55 dmsetup resume ioerror
56 ln -s $G_dev_/mapper
/ioerror
$G_dev_/ioerror
61 test -n "$size" || size
=32
63 test -n "$LOOP" && return 0
64 trap 'aux teardown_' EXIT
# don't forget to clean up
65 trap 'set +vex; STACKTRACE; set -vex' ERR
68 LOOPFILE
="$PWD/test.img"
69 dd if=/dev
/zero of
="$LOOPFILE" bs
=$
((1024*1024)) count
=1 seek
=$
(($size-1))
70 if LOOP
=`losetup -s -f "$LOOPFILE" 2>/dev/null`; then
72 elif LOOP
=`losetup -f` && losetup
$LOOP "$LOOPFILE"; then
77 # Iterate through $G_dev_/loop{,/}{0,1,2,3,4,5,6,7}
79 for i
in 0 1 2 3 4 5 6 7; do
80 local dev
=$G_dev_/loop
$slash$i
81 ! losetup
$dev >/dev
/null
2>&1 ||
continue
83 losetup
"$dev" "$LOOPFILE"
87 if [ -n "$LOOP" ]; then
91 test -n "$LOOP" # confirm or fail
94 exit 1 # should not happen
101 test -z "$devsize" && devsize
=33
103 test -z "$pvname" && pvname
="pv"
105 prepare_loop $
(($n*$devsize))
109 if ! loopsz
=`blockdev --getsz $LOOP 2>/dev/null`; then
110 loopsz
=`blockdev --getsize $LOOP 2>/dev/null`
113 local size
=$
(($loopsz/$n))
115 for i
in `seq 1 $n`; do
116 local name
="${PREFIX}$pvname$i"
117 local dev
="$G_dev_/mapper/$name"
120 echo 0 $size linear
$LOOP $
((($i-1)*$size)) > $name.table
121 dmsetup create
$name $name.table
125 # set up some default names
138 # first we make the device inaccessible
139 echo 0 10000000 error | dmsetup load
$dev
141 # now let's try to get rid of it if it's unused
148 local name
=`echo "$dev" | sed -e 's,.*/,,'`
149 dmsetup create
$name $name.table || dmsetup load
$name $name.table
156 dd if=$dev of
=$dev.backup bs
=1024
162 test -e $dev.backup ||
{
163 echo "Internal error: $dev not backed up, can't restore!"
166 dd of
=$dev if=$dev.backup bs
=1024
182 test -z "$filter" && \
183 filter
='[ "a/dev\/mirror/", "a/dev\/mapper\/.*pv[0-9_]*$/", "r/.*/" ]'
184 cat > $G_root_/etc
/lvm.conf
<<-EOF
189 cache_dir = "$G_root_/etc"
193 verbose = $verboselevel
202 library_dir = "$G_root_/lib"
203 locking_dir = "$G_root_/var/lock/lvm"