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

Conversion of last 2 tests to use test-utils.sh, by jstava.

This commit is contained in:
Petr Rockai 2008-10-14 19:41:12 +00:00
parent ffc4a05bda
commit f6d7cec859
2 changed files with 350 additions and 426 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# Copyright (C) 2007 Red Hat, Inc. All rights reserved. # Copyright (C) 2008 Red Hat, Inc. All rights reserved.
# Copyright (C) 2007 NEC Corporation # Copyright (C) 2007 NEC Corporation
# #
# This copyrighted material is made available to anyone wishing to use, # This copyrighted material is made available to anyone wishing to use,
@ -11,52 +11,14 @@
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
test_description="ensure that basic operations on mirrored LV works" test_description="ensure that basic operations on mirrored LV works"
privileges_required_=1
. ./test-lib.sh . ./test-utils.sh
dmsetup_has_dm_devdir_support_ || dmsetup_has_dm_devdir_support_ || exit 200
{
say "Your version of dmsetup lacks support for changing DM_DEVDIR."
say "Skipping this test"
exit 0
}
cleanup_()
{
test -n "$vg" && {
lvremove -ff $vg
vgremove $vg
} > /dev/null
test -n "$pvs" && {
pvremove $pvs > /dev/null
for d in $pvs; do
dmsetup remove $(basename $d)
done
}
losetup -d $lodev
rm -f $lofile
}
# ---------------------------------------------------------------------
# config
nr_pvs=5
pvsize=$((80 * 1024 * 2))
vg=mirror-basic-vg-$$
lv1=lv1
lv2=lv2
lv3=lv3
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Utilities # Utilities
pv_()
{
echo "$G_dev_/mapper/pv$1"
}
lvdev_() lvdev_()
{ {
echo "$G_dev_/$1/$2" echo "$G_dev_/$1/$2"
@ -132,9 +94,8 @@ mirrorlog_is_on_()
local lv="$1"_mlog local lv="$1"_mlog
shift 1 shift 1
lvs -a -odevices --noheadings $lv | sed 's/,/\n/g' > out lvs -a -odevices --noheadings $lv | sed 's/,/\n/g' > out
for d in $*; do grep "$d(" out || return 1; done for d in $*; do grep "$d(" out; done
for d in $*; do grep -v "$d(" out > out2; mv out2 out; done for d in $*; do ! grep -v "$d(" out; done
grep . out && return 1
return 0 return 0
} }
@ -152,31 +113,7 @@ check_dev_sum_()
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Initialize PVs and VGs # Initialize PVs and VGs
test_expect_success \ aux prepare_vg 5 80
'set up temp file and loopback device' \
'lofile=$(pwd)/lofile && lodev=$(loop_setup_ "$lofile")'
offset=0
pvs=
for n in $(seq 1 $nr_pvs); do
test_expect_success \
"create pv$n" \
'echo "0 $pvsize linear $lodev $offset" > in &&
dmsetup create pv$n < in'
offset=$(($offset + $pvsize))
done
for n in $(seq 1 $nr_pvs); do
pvs="$pvs $(pv_ $n)"
done
test_expect_success \
"Run this: pvcreate $pvs" \
'pvcreate $pvs'
test_expect_success \
'set up a VG' \
'vgcreate $vg $pvs'
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Common environment setup/cleanup for each sub testcases # Common environment setup/cleanup for each sub testcases
@ -189,13 +126,13 @@ prepare_lvs_()
check_and_cleanup_lvs_() check_and_cleanup_lvs_()
{ {
lvs -a -o+devices $vg && lvs -a -o+devices $vg
lvremove -ff $vg lvremove -ff $vg
} }
test_expect_success "check environment setup/cleanup" \ #COMM "check environment setup/cleanup"
'prepare_lvs_ && prepare_lvs_
check_and_cleanup_lvs_' check_and_cleanup_lvs_
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# mirrored LV tests # mirrored LV tests
@ -203,126 +140,125 @@ test_expect_success "check environment setup/cleanup" \
# --- # ---
# create # create
test_expect_success "create 2-way mirror with disklog from 3 PVs" \ #COMM "create 2-way mirror with disklog from 3 PVs"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
mimages_are_redundant_ $vg $lv1 && mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $(pv_ 3) && mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_' check_and_cleanup_lvs_
test_expect_success "create 2-way mirror with corelog from 2 PVs" \ #COMM "create 2-way mirror with corelog from 2 PVs"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $(pv_ 1) $(pv_ 2) && lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
mimages_are_redundant_ $vg $lv1 && mimages_are_redundant_ $vg $lv1
check_and_cleanup_lvs_' check_and_cleanup_lvs_
test_expect_success "create 3-way mirror with disklog from 4 PVs" \ #COMM "create 3-way mirror with disklog from 4 PVs"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m2 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 4) $(pv_ 3):0-1 && lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev4 $dev3:0-1
mimages_are_redundant_ $vg $lv1 && mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $(pv_ 3) && mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_' check_and_cleanup_lvs_
# --- # ---
# convert # convert
test_expect_success "convert from linear to 2-way mirror" \ #COMM "convert from linear to 2-way mirror"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -n $lv1 $vg $(pv_ 1) && lvcreate -l2 -n $lv1 $vg $dev1
lvconvert -m+1 $vg/$lv1 $(pv_ 2) $(pv_ 3):0-1 && lvconvert -m+1 $vg/$lv1 $dev2 $dev3:0-1
mimages_are_redundant_ $vg $lv1 && mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $(pv_ 3) && mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_' check_and_cleanup_lvs_
test_expect_success "convert from 2-way mirror to linear" \ #COMM "convert from 2-way mirror to linear"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvconvert -m-1 $vg/$lv1 && lvconvert -m-1 $vg/$lv1
mimages_are_redundant_ $vg $lv1 && mimages_are_redundant_ $vg $lv1
check_and_cleanup_lvs_' check_and_cleanup_lvs_
test_expect_success "convert from disklog to corelog" \ #COMM "convert from disklog to corelog"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvconvert --mirrorlog core $vg/$lv1 && lvconvert --mirrorlog core $vg/$lv1
mimages_are_redundant_ $vg $lv1 && mimages_are_redundant_ $vg $lv1
check_and_cleanup_lvs_' check_and_cleanup_lvs_
test_expect_success "convert from corelog to disklog" \ #COMM "convert from corelog to disklog"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $(pv_ 1) $(pv_ 2) && lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
lvconvert --mirrorlog disk $vg/$lv1 $(pv_ 3):0-1 && lvconvert --mirrorlog disk $vg/$lv1 $dev3:0-1
mimages_are_redundant_ $vg $lv1 && mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $(pv_ 3) && mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_' check_and_cleanup_lvs_
# --- # ---
# resize # resize
test_expect_success "extend 2-way mirror" \ #COMM "extend 2-way mirror"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvextend -l+2 $vg/$lv1 && lvextend -l+2 $vg/$lv1
mimages_are_redundant_ $vg $lv1 && mimages_are_redundant_ $vg $lv1
mimages_are_contiguous_ $vg $lv1 && mimages_are_contiguous_ $vg $lv1
check_and_cleanup_lvs_' check_and_cleanup_lvs_
test_expect_success "reduce 2-way mirror" \ #COMM "reduce 2-way mirror"
'prepare_lvs_ && prepare_lvs_
lvcreate -l4 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3):0-1 && lvcreate -l4 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvreduce -l-2 $vg/$lv1 && lvreduce -l-2 $vg/$lv1
check_and_cleanup_lvs_' check_and_cleanup_lvs_
test_expect_success "extend 2-way mirror (cling if not contiguous)" \ #COMM "extend 2-way mirror (cling if not contiguous)"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvcreate -l1 -n $lv2 $vg $(pv_ 1) && lvcreate -l1 -n $lv2 $vg $dev1
lvcreate -l1 -n $lv3 $vg $(pv_ 2) && lvcreate -l1 -n $lv3 $vg $dev2
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvextend -l+2 $vg/$lv1 && lvextend -l+2 $vg/$lv1
mimages_are_redundant_ $vg $lv1 && mimages_are_redundant_ $vg $lv1
mimages_are_clung_ $vg $lv1 && mimages_are_clung_ $vg $lv1
check_and_cleanup_lvs_' check_and_cleanup_lvs_
# --- # ---
# failure cases # failure cases
test_expect_failure "create 2-way mirror with disklog from 2 PVs" \ #COMM "create 2-way mirror with disklog from 2 PVs"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2)' not lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2
test_expect_success "(cleanup previous test)" \ # "(cleanup previous test)"
'check_and_cleanup_lvs_' check_and_cleanup_lvs_
test_expect_failure "convert linear to 2-way mirror with 1 PV" \ #COMM "convert linear to 2-way mirror with 1 PV"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -n $lv1 $vg $(pv_ 1) && lvcreate -l2 -n $lv1 $vg $dev1
lvconvert -m+1 --mirrorlog core $vg/$lv1 $(pv_ 1)' not lvconvert -m+1 --mirrorlog core $vg/$lv1 $dev1
test_expect_success "(cleanup previous test)" \ # "(cleanup previous test)"
'check_and_cleanup_lvs_' check_and_cleanup_lvs_
# --- # ---
# resync # resync
# FIXME: using dm-delay to properly check whether the resync really started # FIXME: using dm-delay to properly check whether the resync really started
test_expect_success "force resync 2-way active mirror" \ #COMM "force resync 2-way active mirror"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
mirrorlog_is_on_ $vg/$lv1 $(pv_ 3) && mirrorlog_is_on_ $vg/$lv1 $dev3
yes | lvchange --resync $vg/$lv1 && yes | lvchange --resync $vg/$lv1
mirrorlog_is_on_ $vg/$lv1 $(pv_ 3) && mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_' check_and_cleanup_lvs_
test_expect_success "force resync 2-way inactive mirror" \ #COMM "force resync 2-way inactive mirror"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
mirrorlog_is_on_ $vg/$lv1 $(pv_ 3) && mirrorlog_is_on_ $vg/$lv1 $dev3
lvchange --resync $vg/$lv1 && lvchange --resync $vg/$lv1
mirrorlog_is_on_ $vg/$lv1 $(pv_ 3) && mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_' check_and_cleanup_lvs_
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
test_done

View File

@ -1,4 +1,4 @@
# Copyright (C) 2007 Red Hat, Inc. All rights reserved. # Copyright (C) 2008 Red Hat, Inc. All rights reserved.
# Copyright (C) 2007 NEC Corporation # Copyright (C) 2007 NEC Corporation
# #
# This copyrighted material is made available to anyone wishing to use, # This copyrighted material is made available to anyone wishing to use,
@ -9,242 +9,239 @@
# along with this program; if not, write to the Free Software Foundation, # along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
test_description="ensure that 'vgreduce --removemissing' works on mirrored LV"
. ./test-utils.sh . ./test-utils.sh
dmsetup_has_dm_devdir_support_ || exit 200 dmsetup_has_dm_devdir_support_ || exit 200
pv_() {
eval "echo \$dev$1"
}
lv_is_on_ () lv_is_on_ ()
{ {
local lv=$vg/$1 local lv=$vg/$1
shift shift
local pvs=$* local pvs=$*
echo "Check if $lv is exactly on PVs $pvs" echo "Check if $lv is exactly on PVs $pvs"
rm -f out1 out2 rm -f out1 out2
echo $pvs | sed 's/ /\n/g' | sort | uniq > out1 echo $pvs | sed 's/ /\n/g' | sort | uniq > out1
lvs -a -odevices --noheadings $lv | \ lvs -a -odevices --noheadings $lv | \
sed 's/([^)]*)//g; s/[ ,]/\n/g' | sort | uniq > out2 sed 's/([^)]*)//g; s/[ ,]/\n/g' | sort | uniq > out2
diff --ignore-blank-lines out1 out2 diff --ignore-blank-lines out1 out2
} }
mimages_are_on_ () mimages_are_on_ ()
{ {
local lv=$1 local lv=$1
shift shift
local pvs="$*" local pvs="$*"
local mimages local mimages
local i local i
echo "Check if mirror images of $lv are on PVs $pvs" echo "Check if mirror images of $lv are on PVs $pvs"
rm -f out1 out2 rm -f out1 out2
echo $pvs | sed 's/ /\n/g' | sort | uniq > out1 echo $pvs | sed 's/ /\n/g' | sort | uniq > out1
mimages=$(lvs --noheadings -a -o lv_name $vg | grep "${lv}_mimage_" | \ mimages=$(lvs --noheadings -a -o lv_name $vg | grep "${lv}_mimage_" | \
sed 's/\[//g; s/\]//g') sed 's/\[//g; s/\]//g')
for i in $mimages; do for i in $mimages; do
echo "Checking $vg/$i" echo "Checking $vg/$i"
lvs -a -odevices --noheadings $vg/$i | \ lvs -a -odevices --noheadings $vg/$i | \
sed 's/([^)]*)//g; s/ //g; s/,/ /g' | sort | uniq >> out2 sed 's/([^)]*)//g; s/ //g; s/,/ /g' | sort | uniq >> out2
done done
diff --ignore-blank-lines out1 out2 diff --ignore-blank-lines out1 out2
} }
mirrorlog_is_on_() mirrorlog_is_on_()
{ {
local lv="$1"_mlog local lv="$1"_mlog
shift shift
lv_is_on_ $lv $* lv_is_on_ $lv $*
} }
lv_is_linear_() lv_is_linear_()
{ {
echo "Check if $1 is linear LV (i.e. not a mirror)" echo "Check if $1 is linear LV (i.e. not a mirror)"
lvs -o stripes,attr --noheadings $vg/$1 | sed 's/ //g' lvs -o stripes,attr --noheadings $vg/$1 | sed 's/ //g'
lvs -o stripes,attr --noheadings $vg/$1 | sed 's/ //g' | grep -q '^1-' lvs -o stripes,attr --noheadings $vg/$1 | sed 's/ //g' | grep -q '^1-'
} }
rest_pvs_() rest_pvs_()
{ {
local index=$1 local index=$1
local num=$2 local num=$2
local rem="" local rem=""
local n local n
for n in $(seq 1 $(($index - 1))) $(seq $((index + 1)) $num); do for n in $(seq 1 $(($index - 1))) $(seq $(($index + 1)) $num); do
rem="$rem $(pv_ $n)" eval local dev=$\dev$n
done rem="$rem $dev"
done
echo "$rem" echo "$rem"
} }
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Initialize PVs and VGs # Initialize PVs and VGs
aux prepare_vg 5 prepare_vg 5
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Common environment setup/cleanup for each sub testcases # Common environment setup/cleanup for each sub testcases
prepare_lvs_() prepare_lvs_()
{ {
lvremove -ff $vg; lvremove -ff $vg;
: :
} }
check_and_cleanup_lvs_() check_and_cleanup_lvs_()
{ {
lvs -a -o+devices $vg && lvs -a -o+devices $vg
lvremove -ff $vg lvremove -ff $vg
} }
recover_vg_() recover_vg_()
{ {
enable_dev $* && enable_dev $*
pvcreate -ff $* && pvcreate -ff $*
vgextend $vg $* && vgextend $vg $*
check_and_cleanup_lvs_ check_and_cleanup_lvs_
} }
test_expect_success "check environment setup/cleanup" \ #COMM "check environment setup/cleanup"
'prepare_lvs_ && prepare_lvs_
check_and_cleanup_lvs_' check_and_cleanup_lvs_
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# one of mirror images has failed # one of mirror images has failed
# basic: fail the 2nd mirror image of 2-way mirrored LV #COMM "basic: fail the 2nd mirror image of 2-way mirrored LV"
prepare_lvs_ prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3):0-1 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvchange -an $vg/$lv1 lvchange -an $vg/$lv1
aux mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) aux mimages_are_on_ $lv1 $dev1 $dev2
mirrorlog_is_on_ $lv1 $(pv_ 3) mirrorlog_is_on_ $lv1 $dev3
disable_dev $(pv_ 2) disable_dev $dev2
vgreduce --removemissing --force $vg vgreduce --removemissing --force $vg
lv_is_linear_ $lv1 lv_is_linear_ $lv1
lv_is_on_ $lv1 $(pv_ 1) lv_is_on_ $lv1 $dev1
test_expect_success "cleanup" \ # "cleanup"
'recover_vg_ $(pv_ 2)' recover_vg_ $dev2
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# LV has 3 images in flat, # LV has 3 images in flat,
# 1 out of 3 images fails # 1 out of 3 images fails
# test_3way_mirror_fail_1_ <PV# to fail> #COMM test_3way_mirror_fail_1_ <PV# to fail>
test_3way_mirror_fail_1_() test_3way_mirror_fail_1_()
{ {
local index=$1 local index=$1
lvcreate -l2 -m2 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3) $(pv_ 4):0-1 lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev4:0-1
lvchange -an $vg/$lv1 lvchange -an $vg/$lv1
aux mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) $(pv_ 3) aux mimages_are_on_ $lv1 $dev1 $dev2 $dev3
mirrorlog_is_on_ $lv1 $(pv_ 4) mirrorlog_is_on_ $lv1 $dev4
disable_dev $(pv_ $index) eval disable_dev \$dev$index
vgreduce --removemissing --force $vg vgreduce --removemissing --force $vg
lvs -a -o+devices $vg lvs -a -o+devices $vg
cat $G_root_/etc/lvm.conf mimages_are_on_ $lv1 $(rest_pvs_ $index 3)
mimages_are_on_ $lv1 $(rest_pvs_ $index 3) mirrorlog_is_on_ $lv1 $dev4
mirrorlog_is_on_ $lv1 $(pv_ 4)
} }
for n in $(seq 1 3); do for n in $(seq 1 3); do
# fail mirror image $(($n - 1)) of 3-way mirrored LV" \ #COMM fail mirror image $(($n - 1)) of 3-way mirrored LV"
prepare_lvs_ prepare_lvs_
test_3way_mirror_fail_1_ $n test_3way_mirror_fail_1_ $n
recover_vg_ $(pv_ $n) eval recover_vg_ \$dev$n
done done
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# LV has 3 images in flat, # LV has 3 images in flat,
# 2 out of 3 images fail # 2 out of 3 images fail
# test_3way_mirror_fail_2_ <PV# NOT to fail> #COMM test_3way_mirror_fail_2_ <PV# NOT to fail>
test_3way_mirror_fail_2_() test_3way_mirror_fail_2_()
{ {
local index=$1 local index=$1
lvcreate -l2 -m2 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3) $(pv_ 4):0-1 lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev4:0-1
lvchange -an $vg/$lv1 lvchange -an $vg/$lv1
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) $(pv_ 3) mimages_are_on_ $lv1 $dev1 $dev2 $dev3
mirrorlog_is_on_ $lv1 $(pv_ 4) mirrorlog_is_on_ $lv1 $dev4
rest_pvs_ $index 3 rest_pvs_ $index 3
disable_dev $(rest_pvs_ $index 3) disable_dev $(rest_pvs_ $index 3)
vgreduce --force --removemissing $vg vgreduce --force --removemissing $vg
lvs -a -o+devices $vg lvs -a -o+devices $vg
aux lv_is_linear_ $lv1 aux lv_is_linear_ $lv1
lv_is_on_ $lv1 $(pv_ $index) eval lv_is_on_ $lv1 \$dev$n
} }
for n in $(seq 1 3); do for n in $(seq 1 3); do
# fail mirror images other than mirror image $(($n - 1)) of 3-way mirrored LV #COMM fail mirror images other than mirror image $(($n - 1)) of 3-way mirrored LV
prepare_lvs_ prepare_lvs_
test_3way_mirror_fail_2_ $n test_3way_mirror_fail_2_ $n
recover_vg_ $(rest_pvs_ $n 3) recover_vg_ $(rest_pvs_ $n 3)
done done
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# LV has 4 images, 1 of them is in the temporary mirror for syncing. # LV has 4 images, 1 of them is in the temporary mirror for syncing.
# 1 out of 4 images fails # 1 out of 4 images fails
# test_3way_mirror_plus_1_fail_1_ <PV# to fail> #COMM test_3way_mirror_plus_1_fail_1_ <PV# to fail>
test_3way_mirror_plus_1_fail_1_() test_3way_mirror_plus_1_fail_1_()
{ {
local index=$1 local index=$1
lvcreate -l2 -m2 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3) $(pv_ 5):0-1 && lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvconvert -m+1 $vg/$lv1 $(pv_ 4) && lvconvert -m+1 $vg/$lv1 $dev4
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) $(pv_ 3) $(pv_ 4) && mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
disable_dev $(pv_ $index) && eval disable_dev \$dev$n
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
lvs -a -o+devices $vg && lvs -a -o+devices $vg
mimages_are_on_ $lv1 $(rest_pvs_ $index 4) && mimages_are_on_ $lv1 $(rest_pvs_ $index 4)
mirrorlog_is_on_ $lv1 $(pv_ 5) mirrorlog_is_on_ $lv1 $dev5
} }
for n in $(seq 1 4); do for n in $(seq 1 4); do
test_expect_success "fail mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV" \ #COMM "fail mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV"
"prepare_lvs_ && prepare_lvs_
test_3way_mirror_plus_1_fail_1_ $n" test_3way_mirror_plus_1_fail_1_ $n
test_expect_success "cleanup" \ eval recover_vg_ \$dev$n
"recover_vg_ $(pv_ $n)"
done done
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# LV has 4 images, 1 of them is in the temporary mirror for syncing. # LV has 4 images, 1 of them is in the temporary mirror for syncing.
# 3 out of 4 images fail # 3 out of 4 images fail
# test_3way_mirror_plus_1_fail_3_ <PV# NOT to fail> #COMM test_3way_mirror_plus_1_fail_3_ <PV# NOT to fail>
test_3way_mirror_plus_1_fail_3_() test_3way_mirror_plus_1_fail_3_()
{ {
local index=$1 local index=$1
lvcreate -l2 -m2 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 3) $(pv_ 5):0-1 && lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvconvert -m+1 $vg/$lv1 $(pv_ 4) && lvconvert -m+1 $vg/$lv1 $dev4
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) $(pv_ 3) $(pv_ 4) && mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
disable_dev $(rest_pvs_ $index 4) && disable_dev $(rest_pvs_ $index 4)
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
lvs -a -o+devices $vg && lvs -a -o+devices $vg
(mimages_are_on_ $lv1 $(pv_ $index) || lv_is_on_ $lv1 $(pv_ $index)) && eval local dev=\$dev$n
! mirrorlog_is_on_ $lv1 $(pv_ 5) mimages_are_on_ $lv1 $dev || lv_is_on_ $lv1 $dev
not mirrorlog_is_on_ $lv1 $dev5
} }
for n in $(seq 1 4); do for n in $(seq 1 4); do
test_expect_success "fail mirror images other than mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV" \ #COMM "fail mirror images other than mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV"
"prepare_lvs_ && prepare_lvs_
test_3way_mirror_plus_1_fail_3_ $n" test_3way_mirror_plus_1_fail_3_ $n
test_expect_success "cleanup" \ recover_vg_ $(rest_pvs_ $n 4)
"recover_vg_ $(rest_pvs_ $n 4)"
done done
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
@ -254,26 +251,25 @@ done
# test_2way_mirror_plus_2_fail_1_ <PV# to fail> # test_2way_mirror_plus_2_fail_1_ <PV# to fail>
test_2way_mirror_plus_2_fail_1_() test_2way_mirror_plus_2_fail_1_()
{ {
local index=$1 local index=$1
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 5):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvconvert -m+2 $vg/$lv1 $(pv_ 3) $(pv_ 4) && lvconvert -m+2 $vg/$lv1 $dev3 $dev4
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) $(pv_ 3) $(pv_ 4) && mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
disable_dev $(pv_ $index) && eval disable_dev \$dev$n
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
lvs -a -o+devices $vg && lvs -a -o+devices $vg
mimages_are_on_ $lv1 $(rest_pvs_ $index 4) && mimages_are_on_ $lv1 $(rest_pvs_ $index 4)
mirrorlog_is_on_ $lv1 $(pv_ 5) mirrorlog_is_on_ $lv1 $dev5
} }
for n in $(seq 1 4); do for n in $(seq 1 4); do
test_expect_success "fail mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV" \ #COMM "fail mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV"
"prepare_lvs_ && prepare_lvs_
test_2way_mirror_plus_2_fail_1_ $n" test_2way_mirror_plus_2_fail_1_ $n
test_expect_success "cleanup" \ eval recover_vg_ \$dev$n
"recover_vg_ $(pv_ $n)"
done done
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
@ -283,143 +279,135 @@ done
# test_2way_mirror_plus_2_fail_3_ <PV# NOT to fail> # test_2way_mirror_plus_2_fail_3_ <PV# NOT to fail>
test_2way_mirror_plus_2_fail_3_() test_2way_mirror_plus_2_fail_3_()
{ {
local index=$1 local index=$1
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 5):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvconvert -m+2 $vg/$lv1 $(pv_ 3) $(pv_ 4) && lvconvert -m+2 $vg/$lv1 $dev3 $dev4
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) $(pv_ 3) $(pv_ 4) && mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
disable_dev $(rest_pvs_ $index 4) && disable_dev $(rest_pvs_ $index 4)
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
lvs -a -o+devices $vg && lvs -a -o+devices $vg
(mimages_are_on_ $lv1 $(pv_ $index) || lv_is_on_ $lv1 $(pv_ $index)) && eval local dev=\$dev$n
! mirrorlog_is_on_ $lv1 $(pv_ 5) mimages_are_on_ $lv1 $dev || lv_is_on_ $lv1 $dev
not mirrorlog_is_on_ $lv1 $dev5
} }
for n in $(seq 1 4); do for n in $(seq 1 4); do
test_expect_success "fail mirror images other than mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV" \ #COMM "fail mirror images other than mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV"
"prepare_lvs_ && prepare_lvs_
test_2way_mirror_plus_2_fail_3_ $n" test_2way_mirror_plus_2_fail_3_ $n
test_expect_success "cleanup" \ recover_vg_ $(rest_pvs_ $n 4)
"recover_vg_ $(rest_pvs_ $n 4)"
done done
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# log device is gone (flat mirror and stacked mirror) # log device is gone (flat mirror and stacked mirror)
test_expect_success "fail mirror log of 2-way mirrored LV" \ #COMM "fail mirror log of 2-way mirrored LV"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 5):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) && mimages_are_on_ $lv1 $dev1 $dev2
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
disable_dev $(pv_ 5) && disable_dev $dev5
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) && mimages_are_on_ $lv1 $dev1 $dev2
! mirrorlog_is_on_ $lv1 $(pv_ 5)' not mirrorlog_is_on_ $lv1 $dev5
test_expect_success "cleanup" \ recover_vg_ $dev5
"recover_vg_ $(pv_ 5)"
test_expect_success "fail mirror log of 3-way (1 converting) mirrored LV" \ #COMM "fail mirror log of 3-way (1 converting) mirrored LV"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 5):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvconvert -m+1 $vg/$lv1 $(pv_ 3) && lvconvert -m+1 $vg/$lv1 $dev3
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) $(pv_ 3) && mimages_are_on_ $lv1 $dev1 $dev2 $dev3
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
disable_dev $(pv_ 5) && disable_dev $dev5
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) $(pv_ 3) && mimages_are_on_ $lv1 $dev1 $dev2 $dev3
! mirrorlog_is_on_ $lv1 $(pv_ 5)' not mirrorlog_is_on_ $lv1 $dev5
test_expect_success "cleanup" \ recover_vg_ $dev5
"recover_vg_ $(pv_ 5)"
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# all images are gone (flat mirror and stacked mirror) # all images are gone (flat mirror and stacked mirror)
test_expect_success "fail all mirror images of 2-way mirrored LV" \ #COMM "fail all mirror images of 2-way mirrored LV"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 5):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) && mimages_are_on_ $lv1 $dev1 $dev2
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
disable_dev $(pv_ 1) $(pv_ 2) && disable_dev $dev1 $dev2
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
! lvs $vg/$lv1' not lvs $vg/$lv1
test_expect_success "cleanup" \ recover_vg_ $dev1 $dev2
"recover_vg_ $(pv_ 1) $(pv_ 2)"
test_expect_success "fail all mirror images of 3-way (1 converting) mirrored LV" \ #COMM "fail all mirror images of 3-way (1 converting) mirrored LV"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 5):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvconvert -m+1 $vg/$lv1 $(pv_ 3) && lvconvert -m+1 $vg/$lv1 $dev3
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) $(pv_ 3) && mimages_are_on_ $lv1 $dev1 $dev2 $dev3
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
disable_dev $(pv_ 1) $(pv_ 2) $(pv_ 3) && disable_dev $dev1 $dev2 $dev3
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
! lvs $vg/$lv1' not lvs $vg/$lv1
test_expect_success "cleanup" \ recover_vg_ $dev1 $dev2 $dev3
"recover_vg_ $(pv_ 1) $(pv_ 2) $(pv_ 3)"
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# Multiple LVs # Multiple LVs
test_expect_success "fail a mirror image of one of mirrored LV" \ #COMM "fail a mirror image of one of mirrored LV"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 5):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvcreate -l2 -m1 -n $lv2 $vg $(pv_ 3) $(pv_ 4) $(pv_ 5):1-1 && lvcreate -l2 -m1 -n $lv2 $vg $dev3 $dev4 $dev5:1-1
lvchange -an $vg/$lv2 && lvchange -an $vg/$lv2
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) && mimages_are_on_ $lv1 $dev1 $dev2
mimages_are_on_ $lv2 $(pv_ 3) $(pv_ 4) && mimages_are_on_ $lv2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
mirrorlog_is_on_ $lv2 $(pv_ 5) && mirrorlog_is_on_ $lv2 $dev5
disable_dev $(pv_ 2) && disable_dev $dev2
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
mimages_are_on_ $lv2 $(pv_ 3) $(pv_ 4) && mimages_are_on_ $lv2 $dev3 $dev4
mirrorlog_is_on_ $lv2 $(pv_ 5) && mirrorlog_is_on_ $lv2 $dev5
lv_is_linear_ $lv1 && lv_is_linear_ $lv1
lv_is_on_ $lv1 $(pv_ 1)' lv_is_on_ $lv1 $dev1
test_expect_success "cleanup" \ recover_vg_ $dev2
"recover_vg_ $(pv_ 2)"
test_expect_success "fail mirror images, one for each mirrored LV" \ #COMM "fail mirror images, one for each mirrored LV"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 5):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
lvcreate -l2 -m1 -n $lv2 $vg $(pv_ 3) $(pv_ 4) $(pv_ 5):1-1 && lvcreate -l2 -m1 -n $lv2 $vg $dev3 $dev4 $dev5:1-1
lvchange -an $vg/$lv2 && lvchange -an $vg/$lv2
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) && mimages_are_on_ $lv1 $dev1 $dev2
mimages_are_on_ $lv2 $(pv_ 3) $(pv_ 4) && mimages_are_on_ $lv2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
mirrorlog_is_on_ $lv2 $(pv_ 5) && mirrorlog_is_on_ $lv2 $dev5
disable_dev $(pv_ 2) && disable_dev $dev2
disable_dev $(pv_ 4) && disable_dev $dev4
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
lv_is_linear_ $lv1 && lv_is_linear_ $lv1
lv_is_on_ $lv1 $(pv_ 1) && lv_is_on_ $lv1 $dev1
lv_is_linear_ $lv2 && lv_is_linear_ $lv2
lv_is_on_ $lv2 $(pv_ 3)' lv_is_on_ $lv2 $dev3
test_expect_success "cleanup" \ recover_vg_ $dev2 $dev4
"recover_vg_ $(pv_ 2) $(pv_ 4)"
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
# no failure # no failure
test_expect_success "no failures" \ #COMM "no failures"
'prepare_lvs_ && prepare_lvs_
lvcreate -l2 -m1 -n $lv1 $vg $(pv_ 1) $(pv_ 2) $(pv_ 5):0-1 && lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
lvchange -an $vg/$lv1 && lvchange -an $vg/$lv1
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) && mimages_are_on_ $lv1 $dev1 $dev2
mirrorlog_is_on_ $lv1 $(pv_ 5) && mirrorlog_is_on_ $lv1 $dev5
vgreduce --removemissing --force $vg && vgreduce --removemissing --force $vg
mimages_are_on_ $lv1 $(pv_ 1) $(pv_ 2) && mimages_are_on_ $lv1 $dev1 $dev2
mirrorlog_is_on_ $lv1 $(pv_ 5)' mirrorlog_is_on_ $lv1 $dev5
test_expect_success "cleanup" \ check_and_cleanup_lvs_
'check_and_cleanup_lvs_'
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
test_done