1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

tests: add error_dev aux

Aux function to replace PV with specifically damaged device.
Usage:

   aux error_dev "$dev1" 8:32 96:8

Replaces from 8 sector 32 error 512b sectors
and from 96 sector next 8 sectors will fail on rw.
Rest of device is preserved.

For testing:
dd if="$dev1" of=x bs=512 count=104 conv=sync,noerror iflag=direct
This commit is contained in:
Zdenek Kabelac 2012-12-01 17:09:18 +01:00
parent 0dc6ba8309
commit c5e2f08cf9

View File

@ -371,6 +371,53 @@ enable_dev() {
finish_udev_transaction
}
#
# Convert device to device with errors
# Takes the list of pairs of error segment from:len
# Original device table is replace with multiple lines
# i.e. error_dev "$dev1" 8:32 96:8
error_dev() {
local dev=$1
local name=$(echo "$dev" | sed -e 's,.*/,,')
local fromlen
local pos
local size
local type
local pvdev
local offset
read pos size type pvdev offset < $name.table
shift
rm -f $name.errtable
for fromlen in "$@"; do
from=${fromlen%%:*}
len=${fromlen##*:}
diff=$(($from - $pos))
if test $diff -gt 0 ; then
echo "$pos $diff $type $pvdev $(($pos + $offset))" >>$name.errtable
pos=$(($pos + $diff))
elif test $diff -lt 0 ; then
die "Position error"
fi
echo "$from $len error" >>$name.errtable
pos=$(($pos + $len))
done
diff=$(($size - $pos))
test $diff -gt 0 && echo "$pos $diff $type $pvdev $(($pos + $offset))" >>$name.errtable
init_udev_transaction
if dmsetup table $name ; then
dmsetup load "$name" "$name.errtable"
else
dmsetup create -u "TEST-$name" "$name" "$name.errtable"
fi
# using device name (since device path does not exists yet with udev)
notify_lvmetad "$dev"
dmsetup resume "$name"
finish_udev_transaction
}
backup_dev() {
local dev