2011-01-28 19:10:21 +03:00
#!/bin/bash
2012-01-26 22:25:46 +04:00
# Copyright (C) 2011-2012 Red Hat, Inc. All rights reserved.
2011-01-05 03:16:18 +03:00
#
# 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
. lib/utils
2012-03-16 16:59:02 +04:00
run_valgrind( ) {
2012-03-20 14:51:57 +04:00
# Execute script which may use $TESTNAME for creating individual
2012-03-16 16:59:02 +04:00
# log files for each execute command
exec " ${ VALGRIND :- valg } " " $@ "
}
2011-01-05 03:16:18 +03:00
prepare_clvmd( ) {
2012-03-16 16:59:02 +04:00
test " ${ LVM_TEST_LOCKING :- 0 } " -ne 3 && return # not needed
2011-01-05 03:16:18 +03:00
if pgrep clvmd ; then
echo " Cannot use fake cluster locking with real clvmd ( $( pgrep clvmd) ) running. "
2012-03-16 16:59:02 +04:00
skip
2011-01-05 03:16:18 +03:00
fi
# skip if we don't have our own clvmd...
2012-03-16 16:59:02 +04:00
( which clvmd 2>/dev/null | grep " $abs_builddir " ) || skip
2011-01-05 03:16:18 +03:00
# skip if we singlenode is not compiled in
2012-03-16 16:59:02 +04:00
( clvmd --help 2>& 1 | grep "Available cluster managers" | grep "singlenode" ) || skip
2011-01-05 03:16:18 +03:00
2012-03-16 16:59:02 +04:00
# lvmconf "activation/monitoring = 1"
local run_valgrind =
test -z " $LVM_VALGRIND_CLVMD " || run_valgrind = "run_valgrind"
$run_valgrind lib/clvmd -Isinglenode -d 1 -f &
local local_clvmd = $!
2012-03-16 23:08:09 +04:00
sleep .3
2012-03-16 16:59:02 +04:00
# extra sleep for slow valgrind
test -z " $LVM_VALGRIND_CLVMD " || sleep 5
# check that it is really running now
ps $local_clvmd || die
echo $local_clvmd > LOCAL_CLVMD
2011-01-05 03:16:18 +03:00
}
prepare_dmeventd( ) {
if pgrep dmeventd ; then
echo " Cannot test dmeventd with real dmeventd ( $( pgrep dmeventd) ) running. "
2012-03-16 16:59:02 +04:00
skip
2011-01-05 03:16:18 +03:00
fi
# skip if we don't have our own dmeventd...
2012-03-16 16:59:02 +04:00
( which dmeventd 2>/dev/null | grep " $abs_builddir " ) || skip
2011-01-05 03:16:18 +03:00
2012-03-16 16:59:02 +04:00
lvmconf "activation/monitoring = 1"
2011-01-07 16:04:17 +03:00
dmeventd -f " $@ " &
2012-03-16 16:59:02 +04:00
echo $! > LOCAL_DMEVENTD
2011-03-04 17:19:18 +03:00
# FIXME wait for pipe in /var/run instead
2012-03-20 14:51:57 +04:00
sleep .3
2011-01-05 03:16:18 +03:00
}
2011-08-31 15:31:57 +04:00
prepare_lvmetad( ) {
# skip if we don't have our own lvmetad...
2012-03-16 16:59:02 +04:00
( which lvmetad 2>/dev/null | grep " $abs_builddir " ) || skip
2011-08-31 15:31:57 +04:00
2012-02-15 18:24:31 +04:00
lvmconf "global/use_lvmetad = 1"
2012-02-23 17:11:07 +04:00
lvmconf "devices/md_component_detection = 0"
2011-08-31 15:31:57 +04:00
2012-03-16 16:59:02 +04:00
echo "preparing lvmetad..."
lvmetad -f " $@ " -s " $TESTDIR /lvmetad.socket " &
echo $! > LOCAL_LVMETAD
2011-08-31 15:31:57 +04:00
2012-03-20 14:51:57 +04:00
sleep .3
2011-08-31 15:31:57 +04:00
}
2012-02-24 03:58:42 +04:00
notify_lvmetad( ) {
if test -e LOCAL_LVMETAD; then
2012-03-02 22:09:46 +04:00
pvscan --cache " $@ " || true
2012-02-24 03:58:42 +04:00
fi
}
2012-03-20 14:51:57 +04:00
teardown_devs_prefixed( ) {
local prefix = $1
local stray = ${ 2 :- 0 }
local IFS = $IFS_NL
local dm
2012-03-16 16:59:02 +04:00
2012-03-20 14:51:57 +04:00
# Resume suspended devices first
2012-03-28 15:10:08 +04:00
for dm in $( dm_info suspended,name | grep " ^Suspended:.* $prefix " ) ; do
2012-03-20 14:51:57 +04:00
echo " dmsetup resume \" ${ dm #Suspended : } \" "
dmsetup resume " ${ dm #Suspended : } " || true
done
2011-06-29 22:14:08 +04:00
2012-03-20 14:51:57 +04:00
local mounts = ( $( grep " $prefix " /proc/mounts | cut -d' ' -f1) )
if test ${# mounts [@] } -gt 0; then
test " $stray " -eq 0 || echo " Removing stray mounted devices containing $prefix : ${ mounts [@] } "
if umount -fl " ${ mounts [@] } " ; then
udev_wait
fi
fi
2012-03-16 16:59:02 +04:00
2012-03-20 14:51:57 +04:00
# Remove devices, start with closed (sorted by open count)
local remfail = no
local need_udev_wait = 0
init_udev_transaction
2012-03-28 15:10:08 +04:00
for dm in $( dm_info name --sort open | grep " $prefix " ) ; do
2012-03-20 14:51:57 +04:00
dmsetup remove " $dm " & >/dev/null || remfail = yes
need_udev_wait = 1
done
finish_udev_transaction
test $need_udev_wait -eq 0 || udev_wait
if test $remfail = yes; then
local num_devs
local num_remaining_devs = 999
2012-03-28 15:10:08 +04:00
while num_devs = $( dm_table | grep " $prefix " | wc -l) && \
2012-03-20 14:51:57 +04:00
test $num_devs -lt $num_remaining_devs -a $num_devs -ne 0; do
test " $stray " -eq 0 || echo " Removing $num_devs stray mapped devices with names beginning with $prefix : "
2012-03-28 15:10:08 +04:00
for dm in $( dm_info name --sort open | grep " $prefix " ) ; do
2012-03-20 14:51:57 +04:00
dmsetup remove -f " $dm " || true
2012-03-16 16:59:02 +04:00
done
2012-03-20 14:51:57 +04:00
num_remaining_devs = $num_devs
2012-03-16 16:59:02 +04:00
done
2012-03-20 14:51:57 +04:00
fi
}
teardown_devs( ) {
# Delete any remaining dm/udev semaphores
teardown_udev_cookies
test -z " $PREFIX " || {
rm -rf " $TESTDIR /dev/ $PREFIX " *
teardown_devs_prefixed " $PREFIX "
2011-01-05 03:16:18 +03:00
}
# NOTE: SCSI_DEBUG_DEV test must come before the LOOP test because
# prepare_scsi_debug_dev() also sets LOOP to short-circuit prepare_loop()
if test -f SCSI_DEBUG_DEV; then
2012-03-28 15:10:08 +04:00
test ${ LVM_TEST_PARALLEL :- 0 } -eq 1 || modprobe -r scsi_debug
2011-01-05 03:16:18 +03:00
else
2012-03-20 14:51:57 +04:00
test ! -f LOOP || losetup -d $( cat LOOP) || true
2012-03-16 16:59:02 +04:00
test ! -f LOOPFILE || rm -f $( cat LOOPFILE)
2011-01-05 03:16:18 +03:00
fi
rm -f DEVICES # devs is set in prepare_devs()
rm -f LOOP
2011-06-29 21:33:39 +04:00
2011-06-30 13:15:53 +04:00
# Attempt to remove any loop devices that failed to get torn down if earlier tests aborted
2012-03-28 15:10:08 +04:00
test ${ LVM_TEST_PARALLEL :- 0 } -eq 1 -o -z " $COMMON_PREFIX " || {
2012-03-20 14:51:57 +04:00
teardown_devs_prefixed " $COMMON_PREFIX " 1
local stray_loops = ( $( losetup -a | grep " $COMMON_PREFIX " | cut -d: -f1) )
test ${# stray_loops [@] } -eq 0 || {
echo " Removing stray loop devices containing $COMMON_PREFIX : ${ stray_loops [@] } "
losetup -d " ${ stray_loops [@] } "
}
2011-06-30 13:15:53 +04:00
}
2011-01-05 03:16:18 +03:00
}
teardown( ) {
2012-03-16 16:59:02 +04:00
echo -n "## teardown..."
2011-01-05 03:16:18 +03:00
2012-03-28 15:10:08 +04:00
dm_table | not egrep -q " $vg | $vg1 | $vg2 | $vg3 | $vg4 " || {
2012-03-23 13:41:20 +04:00
# Avoid activation of dmeventd if there is no pid
2012-03-28 15:10:08 +04:00
cfg = $( test -s LOCAL_DMEVENTD || echo "--config activation{monitoring=0}" )
2012-03-23 13:41:20 +04:00
vgremove -ff $cfg \
$vg $vg1 $vg2 $vg3 $vg4 & >/dev/null || rm -f debug.log
}
test -s LOCAL_CLVMD && {
2012-03-16 16:59:02 +04:00
kill -INT " $( cat LOCAL_CLVMD) "
test -z " $LVM_VALGRIND_CLVMD " || sleep 1
sleep .1
2012-03-16 23:08:09 +04:00
kill -9 " $( cat LOCAL_CLVMD) " & >/dev/null || true
2012-03-16 16:59:02 +04:00
}
echo -n .
2011-01-05 03:16:18 +03:00
2012-03-20 14:51:57 +04:00
pgrep dmeventd || true
2012-03-23 13:41:20 +04:00
test ! -s LOCAL_DMEVENTD || kill -9 " $( cat LOCAL_DMEVENTD) " || true
test ! -s LOCAL_LVMETAD || kill -9 " $( cat LOCAL_LVMETAD) " || true
2011-01-05 03:16:18 +03:00
2012-03-16 16:59:02 +04:00
echo -n .
2011-01-05 03:16:18 +03:00
2012-03-16 16:59:02 +04:00
test -d " $DM_DEV_DIR /mapper " && teardown_devs
2011-01-05 03:16:18 +03:00
2012-03-16 16:59:02 +04:00
echo -n .
2011-01-05 03:16:18 +03:00
2012-03-16 16:59:02 +04:00
test -n " $TESTDIR " && {
cd " $TESTOLDPWD "
rm -rf " $TESTDIR " || echo BLA
}
2011-01-05 03:16:18 +03:00
2012-03-16 16:59:02 +04:00
echo "ok"
2011-01-05 03:16:18 +03:00
2012-03-28 15:10:08 +04:00
test ${ LVM_TEST_PARALLEL :- 0 } -eq 1 -o -n " $RUNNING_DMEVENTD " || not pgrep dmeventd #&>/dev/null
2011-01-05 03:16:18 +03:00
}
make_ioerror( ) {
2012-03-20 14:51:57 +04:00
echo 0 10000000 error | dmsetup create -u ${ PREFIX } -ioerror ioerror
2012-03-16 16:59:02 +04:00
ln -s " $DM_DEV_DIR /mapper/ioerror " " $DM_DEV_DIR /ioerror "
2011-01-05 03:16:18 +03:00
}
prepare_loop( ) {
2012-03-16 16:59:02 +04:00
local size = ${ 1 =32 }
2012-03-20 14:51:57 +04:00
local i
local slash
2011-01-05 03:16:18 +03:00
2012-03-20 14:51:57 +04:00
test -f LOOP && LOOP = $( cat LOOP)
2012-03-16 16:59:02 +04:00
echo -n "## preparing loop device..."
2011-01-05 03:16:18 +03:00
# skip if prepare_scsi_debug_dev() was used
2012-03-16 16:59:02 +04:00
if test -f SCSI_DEBUG_DEV -a -f LOOP ; then
echo "(skipped)"
2011-01-05 03:16:18 +03:00
return 0
fi
test ! -e LOOP
test -n " $DM_DEV_DIR "
for i in 0 1 2 3 4 5 6 7; do
2012-03-16 16:59:02 +04:00
test -e " $DM_DEV_DIR /loop $i " || mknod " $DM_DEV_DIR /loop $i " b 7 $i
2011-01-05 03:16:18 +03:00
done
2012-03-16 16:59:02 +04:00
echo -n .
2011-01-05 03:16:18 +03:00
2012-03-16 16:59:02 +04:00
local LOOPFILE = " $PWD /test.img "
2011-01-05 03:16:18 +03:00
dd if = /dev/zero of = " $LOOPFILE " bs = $(( 1024 * 1024 )) count = 0 seek = $(( $size - 1 )) 2> /dev/null
2012-03-16 16:59:02 +04:00
if LOOP = $( losetup -s -f " $LOOPFILE " 2>/dev/null) ; then
2011-01-05 03:16:18 +03:00
:
2012-03-16 16:59:02 +04:00
elif LOOP = $( losetup -f) && losetup " $LOOP " " $LOOPFILE " ; then
2011-01-05 03:16:18 +03:00
# no -s support
:
else
2012-03-16 16:59:02 +04:00
# no -f support
2011-01-05 03:16:18 +03:00
# Iterate through $DM_DEV_DIR/loop{,/}{0,1,2,3,4,5,6,7}
for slash in '' /; do
for i in 0 1 2 3 4 5 6 7; do
2012-03-16 16:59:02 +04:00
local dev = " $DM_DEV_DIR /loop $slash $i "
! losetup " $dev " >/dev/null 2>& 1 || continue
2011-01-05 03:16:18 +03:00
# got a free
losetup " $dev " " $LOOPFILE "
LOOP = $dev
break
done
2012-03-16 16:59:02 +04:00
test -z " $LOOP " || break
2011-01-05 03:16:18 +03:00
done
fi
test -n " $LOOP " # confirm or fail
2012-03-16 16:59:02 +04:00
echo " $LOOP " > LOOP
echo " ok ( $LOOP ) "
2011-01-05 03:16:18 +03:00
}
# A drop-in replacement for prepare_loop() that uses scsi_debug to create
# a ramdisk-based SCSI device upon which all LVM devices will be created
# - scripts must take care not to use a DEV_SIZE that will enduce OOM-killer
2012-03-16 16:59:02 +04:00
prepare_scsi_debug_dev( ) {
local DEV_SIZE = $1
local SCSI_DEBUG_PARAMS = ${ @ : 2 }
test -f "SCSI_DEBUG_DEV" && return 0
test -z " $LOOP "
test -n " $DM_DEV_DIR "
# Skip test if awk isn't available (required for get_sd_devs_)
which awk || skip
# Skip test if scsi_debug module is unavailable or is already in use
modprobe --dry-run scsi_debug || skip
lsmod | grep -q scsi_debug && skip
# Create the scsi_debug device and determine the new scsi device's name
# NOTE: it will _never_ make sense to pass num_tgts param;
# last param wins.. so num_tgts=1 is imposed
modprobe scsi_debug dev_size_mb = $DEV_SIZE $SCSI_DEBUG_PARAMS num_tgts = 1 || skip
sleep 2 # allow for async Linux SCSI device registration
local DEBUG_DEV = " /dev/ $( grep -H scsi_debug /sys/block/*/device/model | cut -f4 -d /) "
test -b " $DEBUG_DEV " || return 1 # should not happen
# Create symlink to scsi_debug device in $DM_DEV_DIR
SCSI_DEBUG_DEV = " $DM_DEV_DIR / $( basename $DEBUG_DEV ) "
echo " $SCSI_DEBUG_DEV " > SCSI_DEBUG_DEV
echo " $SCSI_DEBUG_DEV " > LOOP
# Setting $LOOP provides means for prepare_devs() override
test " $LVM_TEST_DEVDIR " != "/dev" && ln -snf " $DEBUG_DEV " " $SCSI_DEBUG_DEV "
2011-01-05 03:16:18 +03:00
}
2012-03-16 16:59:02 +04:00
cleanup_scsi_debug_dev( ) {
2012-03-16 23:08:09 +04:00
teardown_devs
2012-03-16 16:59:02 +04:00
rm -f SCSI_DEBUG_DEV LOOP
2011-01-05 03:16:18 +03:00
}
prepare_devs( ) {
2012-03-16 16:59:02 +04:00
local n = ${ 1 :- 3 }
local devsize = ${ 2 :- 34 }
local pvname = ${ 3 :- pv }
2012-03-20 14:51:57 +04:00
local loopsz
2011-01-05 03:16:18 +03:00
prepare_loop $(( $n * $devsize ))
2012-03-16 16:59:02 +04:00
echo -n " ## preparing $n devices... "
2011-01-05 03:16:18 +03:00
2012-03-16 16:59:02 +04:00
if ! loopsz = $( blockdev --getsz " $LOOP " 2>/dev/null) ; then
loopsz = $( blockdev --getsize " $LOOP " 2>/dev/null)
2011-01-05 03:16:18 +03:00
fi
local size = $(( $loopsz / $n ))
2012-03-16 16:59:02 +04:00
devs =
2011-01-05 03:16:18 +03:00
init_udev_transaction
2012-03-16 16:59:02 +04:00
for i in $( seq 1 $n ) ; do
2011-01-05 03:16:18 +03:00
local name = " ${ PREFIX } $pvname $i "
local dev = " $DM_DEV_DIR /mapper/ $name "
devs = " $devs $dev "
2012-03-16 16:59:02 +04:00
echo 0 $size linear " $LOOP " $(( ( $i - 1 ) * $size )) > " $name .table "
dmsetup create -u " TEST- $name " " $name " " $name .table "
2011-01-05 03:16:18 +03:00
done
finish_udev_transaction
#for i in `seq 1 $n`; do
# local name="${PREFIX}$pvname$i"
# dmsetup info -c $name
#done
#for i in `seq 1 $n`; do
# local name="${PREFIX}$pvname$i"
# dmsetup table $name
#done
2012-03-16 16:59:02 +04:00
echo $devs > DEVICES
echo "ok"
2011-01-05 03:16:18 +03:00
}
disable_dev( ) {
2012-03-20 14:51:57 +04:00
local dev
2011-01-05 03:16:18 +03:00
init_udev_transaction
for dev in " $@ " ; do
2012-03-16 16:59:02 +04:00
maj = $(( $( stat --printf= 0x%t " $dev " ) ))
min = $(( $( stat --printf= 0x%T " $dev " ) ))
echo " Disabling device $dev ( $maj : $min ) "
dmsetup remove -f " $dev " || true
notify_lvmetad --major " $maj " --minor " $min "
2011-01-05 03:16:18 +03:00
done
finish_udev_transaction
}
enable_dev( ) {
2012-03-20 14:51:57 +04:00
local dev
2011-01-05 03:16:18 +03:00
init_udev_transaction
for dev in " $@ " ; do
2012-03-16 16:59:02 +04:00
local name = $( echo " $dev " | sed -e 's,.*/,,' )
dmsetup create -u " TEST- $name " " $name " " $name .table " || \
dmsetup load " $name " " $name .table "
2011-10-23 19:43:10 +04:00
# using device name (since device path does not exists yes with udev)
2012-03-16 16:59:02 +04:00
dmsetup resume " $name "
notify_lvmetad " $dev "
2011-01-05 03:16:18 +03:00
done
finish_udev_transaction
}
backup_dev( ) {
2012-03-20 14:51:57 +04:00
local dev
2011-01-05 03:16:18 +03:00
for dev in " $@ " ; do
2012-03-16 16:59:02 +04:00
dd if = " $dev " of = " $dev .backup " bs = 1024
2011-01-05 03:16:18 +03:00
done
}
restore_dev( ) {
2012-03-20 14:51:57 +04:00
local dev
2011-01-05 03:16:18 +03:00
for dev in " $@ " ; do
2012-03-16 16:59:02 +04:00
test -e " $dev .backup " || \
die " Internal error: $dev not backed up, can't restore! "
dd of = " $dev " if = " $dev .backup " bs = 1024
2011-01-05 03:16:18 +03:00
done
}
prepare_pvs( ) {
prepare_devs " $@ "
pvcreate -ff $devs
}
prepare_vg( ) {
teardown_devs
prepare_pvs " $@ "
vgcreate -c n $vg $devs
}
lvmconf( ) {
2012-03-16 16:59:02 +04:00
LVM_TEST_LOCKING = ${ LVM_TEST_LOCKING :- 1 }
if test " $DM_DEV_DIR " = "/dev" ; then
LVM_VERIFY_UDEV = ${ LVM_VERIFY_UDEV :- 0 }
else
LVM_VERIFY_UDEV = ${ LVM_VERIFY_UDEV :- 1 }
fi
test -f CONFIG_VALUES || {
cat > CONFIG_VALUES <<-EOF
2011-01-05 03:16:18 +03:00
devices/dir = " $DM_DEV_DIR "
devices/scan = " $DM_DEV_DIR "
2011-12-12 04:01:12 +04:00
devices/filter = [ "a/dev\\\\/mirror/" , " a/dev\\\\/mapper\\\\/.*pv[0-9_]* $/ " , "r/.*/" ]
2011-01-05 03:16:18 +03:00
devices/cache_dir = " $TESTDIR /etc "
devices/sysfs_scan = 0
devices/default_data_alignment = 1
2012-03-16 16:57:28 +04:00
devices/md_component_detection = 0
2011-01-05 03:16:18 +03:00
log/syslog = 0
log/indent = 1
log/level = 9
log/file = " $TESTDIR /debug.log "
log/overwrite = 1
log/activation = 1
2012-03-16 16:59:02 +04:00
log/verbose = 0
activation/retry_deactivation = 1
2011-01-05 03:16:18 +03:00
backup/backup = 0
backup/archive = 0
global/abort_on_internal_errors = 1
2011-08-11 21:46:13 +04:00
global/detect_internal_vg_cache_corruption = 1
2011-01-05 03:16:18 +03:00
global/library_dir = " $TESTDIR /lib "
global/locking_dir = " $TESTDIR /var/lock/lvm "
global/locking_type= $LVM_TEST_LOCKING
global/si_unit_consistency = 1
global/fallback_to_local_locking = 0
2011-07-01 18:09:19 +04:00
activation/checks = 1
2011-01-05 03:16:18 +03:00
activation/udev_sync = 1
2011-06-28 04:38:26 +04:00
activation/udev_rules = 1
2011-09-25 01:15:13 +04:00
activation/verify_udev_operations = $LVM_VERIFY_UDEV
2011-01-05 03:16:18 +03:00
activation/polling_interval = 0
activation/snapshot_autoextend_percent = 50
activation/snapshot_autoextend_threshold = 50
2011-01-07 16:04:17 +03:00
activation/monitoring = 0
2011-01-05 03:16:18 +03:00
EOF
2012-03-16 16:59:02 +04:00
}
2012-03-20 14:51:57 +04:00
local v
2012-03-16 16:59:02 +04:00
for v in " $@ " ; do
echo " $v " >> CONFIG_VALUES
done
rm -f CONFIG
2012-03-20 14:51:57 +04:00
local s
2012-03-16 16:59:02 +04:00
for s in $( cat CONFIG_VALUES | cut -f1 -d/ | sort | uniq) ; do
echo " $s { " >> CONFIG
2012-03-20 14:51:57 +04:00
local k
for k in $( grep ^" $s " / CONFIG_VALUES | cut -f1 -d= | sed -e 's, *$,,' | sort | uniq) ; do
2012-03-16 16:59:02 +04:00
grep " ^ $k " CONFIG_VALUES | tail -n 1 | sed -e " s,^ $s /, , " >> CONFIG
done
echo "}" >> CONFIG
echo >> CONFIG
done
2012-03-20 14:51:57 +04:00
mv -f CONFIG etc/lvm.conf
2011-01-05 03:16:18 +03:00
}
apitest( ) {
2012-03-20 14:51:57 +04:00
local t = $1
2012-03-16 16:59:02 +04:00
shift
test -x " $abs_top_builddir /test/api/ $t .t " || skip
" $abs_top_builddir /test/api/ $t .t " " $@ " && rm -f debug.log
2011-01-05 03:16:18 +03:00
}
api( ) {
2012-03-16 16:59:02 +04:00
test -x " $abs_top_builddir /test/api/wrapper " || skip
" $abs_top_builddir /test/api/wrapper " " $@ " && rm -f debug.log
2011-01-05 03:16:18 +03:00
}
2011-01-28 19:10:21 +03:00
udev_wait( ) {
2011-03-02 02:44:07 +03:00
pgrep udev >/dev/null || return 0
which udevadm >/dev/null || return 0
2011-01-28 19:10:21 +03:00
if test -n " $1 " ; then
2012-03-20 14:51:57 +04:00
udevadm settle --exit-if-exists= " $1 " || true
2011-01-28 19:10:21 +03:00
else
2012-03-20 14:51:57 +04:00
udevadm settle --timeout= 15 || true
2011-01-28 19:10:21 +03:00
fi
}
2011-11-10 16:44:00 +04:00
#
# Check wheter kernel [dm module] target exist
# at least in expected version
#
# [dm-]target-name major minor revision
#
# i.e. dm_target_at_least dm-thin-pool 1 0
target_at_least( )
{
case " $1 " in
dm-*) modprobe " $1 " ; ;
esac
2012-03-20 14:51:57 +04:00
local version = $( dmsetup targets 2>/dev/null | grep " ${ 1 ##dm- } " 2>/dev/null)
2011-11-10 16:44:00 +04:00
version = ${ version ##* v }
shift
2012-03-20 14:51:57 +04:00
local major = $( echo " $version " | cut -d. -f1)
2011-11-10 16:44:00 +04:00
test -z " $1 " && return 0
2012-03-16 16:59:02 +04:00
test -n " $major " || return 1
2011-11-10 16:44:00 +04:00
test " $major " -gt " $1 " && return 0
2012-03-16 16:59:02 +04:00
test " $major " -eq " $1 " || return 1
2012-03-20 14:51:57 +04:00
2011-11-10 16:44:00 +04:00
test -z " $2 " && return 0
2012-03-20 14:51:57 +04:00
local minor = $( echo " $version " | cut -d. -f2)
2012-03-16 16:59:02 +04:00
test -n " $minor " || return 1
2011-11-10 16:44:00 +04:00
test " $minor " -gt " $2 " && return 0
2012-03-16 16:59:02 +04:00
test " $minor " -eq " $2 " || return 1
2012-03-20 14:51:57 +04:00
test -z " $3 " && return 0
local revision = $( echo " $version " | cut -d. -f3)
test " $revision " -ge " $3 " 2>/dev/null || return 1
2011-11-10 16:44:00 +04:00
}
2011-01-05 03:16:18 +03:00
test -f DEVICES && devs = $( cat DEVICES)
2012-03-16 16:59:02 +04:00
unset LVM_VALGRIND
2011-01-05 03:16:18 +03:00
" $@ "