2008-10-14 23:41:12 +04:00
# Copyright (C) 2008 Red Hat, Inc. All rights reserved.
2008-01-17 21:29:36 +03:00
# Copyright (C) 2007 NEC Corporation
#
# 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
2008-10-14 23:41:12 +04:00
test_description = "ensure that 'vgreduce --removemissing' works on mirrored LV"
2011-01-05 03:16:18 +03:00
. lib/test
2008-01-17 21:29:36 +03:00
lv_is_on_ ( )
{
2008-10-14 23:41:12 +04:00
local lv = $vg /$1
shift
local pvs = $*
2008-01-17 21:29:36 +03:00
2008-10-14 23:41:12 +04:00
echo " Check if $lv is exactly on PVs $pvs "
rm -f out1 out2
echo $pvs | sed 's/ /\n/g' | sort | uniq > out1
2008-01-17 21:29:36 +03:00
2010-03-25 15:16:17 +03:00
lvs -a -o+devices $lv
2011-03-03 18:46:05 +03:00
lvs -a -odevices --noheadings $lv > lvs_log
sed 's/([^)]*)//g; s/[ ,]/\n/g' lvs_log | sort | uniq > out2 || true
2008-01-17 21:29:36 +03:00
2008-10-14 23:41:12 +04:00
diff --ignore-blank-lines out1 out2
2008-01-17 21:29:36 +03:00
}
mimages_are_on_ ( )
{
2008-10-14 23:41:12 +04:00
local lv = $1
shift
local pvs = " $* "
local mimages
local i
echo " Check if mirror images of $lv are on PVs $pvs "
rm -f out1 out2
echo $pvs | sed 's/ /\n/g' | sort | uniq > out1
2011-03-03 18:46:05 +03:00
lvs --noheadings -a -o lv_name $vg > lvs_log
mimages = $( grep " ${ lv } _mimage_ " lvs_log | \
sed 's/\[//g; s/\]//g' || true )
2008-10-14 23:41:12 +04:00
for i in $mimages ; do
echo " Checking $vg / $i "
2010-03-25 15:16:17 +03:00
lvs -a -o+devices $vg /$i
2011-03-03 18:46:05 +03:00
lvs -a -odevices --noheadings $vg /$i > lvs_log
sed 's/([^)]*)//g; s/ //g; s/,/ /g' lvs_log | sort | uniq >> out2 || true
2008-10-14 23:41:12 +04:00
done
diff --ignore-blank-lines out1 out2
2008-01-17 21:29:36 +03:00
}
mirrorlog_is_on_( )
{
2008-10-14 23:41:12 +04:00
local lv = " $1 " _mlog
shift
lv_is_on_ $lv $*
2008-01-17 21:29:36 +03:00
}
lv_is_linear_( )
{
2008-10-14 23:41:12 +04:00
echo " Check if $1 is linear LV (i.e. not a mirror) "
lvs -o stripes,attr --noheadings $vg /$1 | sed 's/ //g'
2011-03-30 17:39:24 +04:00
lvs -o stripes,attr --noheadings $vg /$1 | sed 's/ //g' | grep '^1-' >/dev/null
2008-01-17 21:29:36 +03:00
}
rest_pvs_( )
{
2008-10-14 23:41:12 +04:00
local index = $1
local num = $2
local rem = ""
local n
2008-01-17 21:29:36 +03:00
2008-10-14 23:41:12 +04:00
for n in $( seq 1 $(( $index - 1 )) ) $( seq $(( $index + 1 )) $num ) ; do
eval local dev = $\d ev$n
rem = " $rem $dev "
done
2008-01-17 21:29:36 +03:00
2008-10-14 23:41:12 +04:00
echo " $rem "
2008-01-17 21:29:36 +03:00
}
# ---------------------------------------------------------------------
# Initialize PVs and VGs
2011-01-05 03:16:18 +03:00
aux prepare_vg 5
2008-01-17 21:29:36 +03:00
# ---------------------------------------------------------------------
# Common environment setup/cleanup for each sub testcases
prepare_lvs_( )
{
2008-10-14 23:41:12 +04:00
lvremove -ff $vg ;
2008-11-10 15:32:00 +03:00
if dmsetup table| grep $vg ; then
echo "ERROR: lvremove did leave some some mappings in DM behind!"
return 1
fi
2008-10-14 23:41:12 +04:00
:
2008-01-17 21:29:36 +03:00
}
check_and_cleanup_lvs_( )
{
2008-10-14 23:41:12 +04:00
lvs -a -o+devices $vg
lvremove -ff $vg
2008-11-10 15:32:00 +03:00
if dmsetup table| grep $vg ; then
echo "ERROR: lvremove did leave some some mappings in DM behind!"
return 1
fi
2008-01-17 21:29:36 +03:00
}
recover_vg_( )
{
2011-01-05 03:16:18 +03:00
aux enable_dev $*
2008-10-14 23:41:12 +04:00
pvcreate -ff $*
vgextend $vg $*
check_and_cleanup_lvs_
2008-01-17 21:29:36 +03:00
}
2008-10-14 23:41:12 +04:00
#COMM "check environment setup/cleanup"
prepare_lvs_
check_and_cleanup_lvs_
2008-01-17 21:29:36 +03:00
# ---------------------------------------------------------------------
# one of mirror images has failed
2008-10-14 23:41:12 +04:00
#COMM "basic: fail the 2nd mirror image of 2-way mirrored LV"
2008-09-29 20:02:50 +04:00
prepare_lvs_
2010-03-25 14:42:17 +03:00
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3 :0
2008-09-29 20:02:50 +04:00
lvchange -an $vg /$lv1
2011-01-05 03:16:18 +03:00
mimages_are_on_ $lv1 $dev1 $dev2
2008-10-14 23:41:12 +04:00
mirrorlog_is_on_ $lv1 $dev3
2011-01-05 03:16:18 +03:00
aux disable_dev $dev2
2008-09-29 20:02:50 +04:00
vgreduce --removemissing --force $vg
lv_is_linear_ $lv1
2008-10-14 23:41:12 +04:00
lv_is_on_ $lv1 $dev1
2008-09-29 20:02:50 +04:00
2008-10-14 23:41:12 +04:00
# "cleanup"
recover_vg_ $dev2
2008-01-17 21:29:36 +03:00
# ---------------------------------------------------------------------
# LV has 3 images in flat,
# 1 out of 3 images fails
2008-10-14 23:41:12 +04:00
#COMM test_3way_mirror_fail_1_ <PV# to fail>
2008-01-17 21:29:36 +03:00
test_3way_mirror_fail_1_( )
{
2008-10-14 23:41:12 +04:00
local index = $1
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev4 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
2011-01-05 03:16:18 +03:00
mimages_are_on_ $lv1 $dev1 $dev2 $dev3
2008-10-14 23:41:12 +04:00
mirrorlog_is_on_ $lv1 $dev4
2011-01-05 03:16:18 +03:00
eval aux disable_dev \$ dev$index
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
lvs -a -o+devices $vg
mimages_are_on_ $lv1 $( rest_pvs_ $index 3)
mirrorlog_is_on_ $lv1 $dev4
2008-01-17 21:29:36 +03:00
}
for n in $( seq 1 3) ; do
2008-10-14 23:41:12 +04:00
#COMM fail mirror image $(($n - 1)) of 3-way mirrored LV"
prepare_lvs_
test_3way_mirror_fail_1_ $n
eval recover_vg_ \$ dev$n
2008-01-17 21:29:36 +03:00
done
# ---------------------------------------------------------------------
# LV has 3 images in flat,
# 2 out of 3 images fail
2008-10-14 23:41:12 +04:00
#COMM test_3way_mirror_fail_2_ <PV# NOT to fail>
2008-01-17 21:29:36 +03:00
test_3way_mirror_fail_2_( )
{
2008-10-14 23:41:12 +04:00
local index = $1
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev4 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
mimages_are_on_ $lv1 $dev1 $dev2 $dev3
mirrorlog_is_on_ $lv1 $dev4
rest_pvs_ $index 3
2011-01-05 03:16:18 +03:00
aux disable_dev $( rest_pvs_ $index 3)
2008-10-14 23:41:12 +04:00
vgreduce --force --removemissing $vg
lvs -a -o+devices $vg
2011-01-05 03:16:18 +03:00
lv_is_linear_ $lv1
2008-10-14 23:41:12 +04:00
eval lv_is_on_ $lv1 \$ dev$n
2008-01-17 21:29:36 +03:00
}
for n in $( seq 1 3) ; do
2008-10-14 23:41:12 +04:00
#COMM fail mirror images other than mirror image $(($n - 1)) of 3-way mirrored LV
prepare_lvs_
test_3way_mirror_fail_2_ $n
recover_vg_ $( rest_pvs_ $n 3)
2008-01-17 21:29:36 +03:00
done
# ---------------------------------------------------------------------
# LV has 4 images, 1 of them is in the temporary mirror for syncing.
# 1 out of 4 images fails
2008-10-14 23:41:12 +04:00
#COMM test_3way_mirror_plus_1_fail_1_ <PV# to fail>
2008-01-17 21:29:36 +03:00
test_3way_mirror_plus_1_fail_1_( )
{
2008-10-14 23:41:12 +04:00
local index = $1
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
lvconvert -m+1 $vg /$lv1 $dev4
mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $dev5
2011-01-05 03:16:18 +03:00
eval aux disable_dev \$ dev$n
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
lvs -a -o+devices $vg
mimages_are_on_ $lv1 $( rest_pvs_ $index 4)
mirrorlog_is_on_ $lv1 $dev5
2008-01-17 21:29:36 +03:00
}
for n in $( seq 1 4) ; do
2008-10-14 23:41:12 +04:00
#COMM "fail mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV"
prepare_lvs_
test_3way_mirror_plus_1_fail_1_ $n
eval recover_vg_ \$ dev$n
2008-01-17 21:29:36 +03:00
done
# ---------------------------------------------------------------------
# LV has 4 images, 1 of them is in the temporary mirror for syncing.
# 3 out of 4 images fail
2008-10-14 23:41:12 +04:00
#COMM test_3way_mirror_plus_1_fail_3_ <PV# NOT to fail>
2008-01-17 21:29:36 +03:00
test_3way_mirror_plus_1_fail_3_( )
{
2008-10-14 23:41:12 +04:00
local index = $1
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
lvconvert -m+1 $vg /$lv1 $dev4
mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $dev5
2011-01-05 03:16:18 +03:00
aux disable_dev $( rest_pvs_ $index 4)
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
lvs -a -o+devices $vg
eval local dev = \$ dev$n
mimages_are_on_ $lv1 $dev || lv_is_on_ $lv1 $dev
not mirrorlog_is_on_ $lv1 $dev5
2008-01-17 21:29:36 +03:00
}
for n in $( seq 1 4) ; do
2008-10-14 23:41:12 +04:00
#COMM "fail mirror images other than mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV"
prepare_lvs_
test_3way_mirror_plus_1_fail_3_ $n
recover_vg_ $( rest_pvs_ $n 4)
2008-01-17 21:29:36 +03:00
done
# ---------------------------------------------------------------------
# LV has 4 images, 2 of them are in the temporary mirror for syncing.
# 1 out of 4 images fail
# test_2way_mirror_plus_2_fail_1_ <PV# to fail>
test_2way_mirror_plus_2_fail_1_( )
{
2008-10-14 23:41:12 +04:00
local index = $1
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
lvconvert -m+2 $vg /$lv1 $dev3 $dev4
mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $dev5
2011-01-05 03:16:18 +03:00
eval aux disable_dev \$ dev$n
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
lvs -a -o+devices $vg
mimages_are_on_ $lv1 $( rest_pvs_ $index 4)
mirrorlog_is_on_ $lv1 $dev5
2008-01-17 21:29:36 +03:00
}
for n in $( seq 1 4) ; do
2008-10-14 23:41:12 +04:00
#COMM "fail mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV"
prepare_lvs_
test_2way_mirror_plus_2_fail_1_ $n
eval recover_vg_ \$ dev$n
2008-01-17 21:29:36 +03:00
done
# ---------------------------------------------------------------------
# LV has 4 images, 2 of them are in the temporary mirror for syncing.
# 3 out of 4 images fail
# test_2way_mirror_plus_2_fail_3_ <PV# NOT to fail>
test_2way_mirror_plus_2_fail_3_( )
{
2008-10-14 23:41:12 +04:00
local index = $1
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
lvconvert -m+2 $vg /$lv1 $dev3 $dev4
mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $dev5
2011-01-05 03:16:18 +03:00
aux disable_dev $( rest_pvs_ $index 4)
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
lvs -a -o+devices $vg
eval local dev = \$ dev$n
mimages_are_on_ $lv1 $dev || lv_is_on_ $lv1 $dev
not mirrorlog_is_on_ $lv1 $dev5
2008-01-17 21:29:36 +03:00
}
for n in $( seq 1 4) ; do
2008-10-14 23:41:12 +04:00
#COMM "fail mirror images other than mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV"
prepare_lvs_
test_2way_mirror_plus_2_fail_3_ $n
recover_vg_ $( rest_pvs_ $n 4)
2008-01-17 21:29:36 +03:00
done
# ---------------------------------------------------------------------
# log device is gone (flat mirror and stacked mirror)
2008-10-14 23:41:12 +04:00
#COMM "fail mirror log of 2-way mirrored LV"
prepare_lvs_
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
mimages_are_on_ $lv1 $dev1 $dev2
mirrorlog_is_on_ $lv1 $dev5
2011-01-05 03:16:18 +03:00
aux disable_dev $dev5
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
mimages_are_on_ $lv1 $dev1 $dev2
not mirrorlog_is_on_ $lv1 $dev5
recover_vg_ $dev5
#COMM "fail mirror log of 3-way (1 converting) mirrored LV"
prepare_lvs_
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
lvconvert -m+1 $vg /$lv1 $dev3
mimages_are_on_ $lv1 $dev1 $dev2 $dev3
mirrorlog_is_on_ $lv1 $dev5
2011-01-05 03:16:18 +03:00
aux disable_dev $dev5
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
mimages_are_on_ $lv1 $dev1 $dev2 $dev3
not mirrorlog_is_on_ $lv1 $dev5
recover_vg_ $dev5
2008-01-17 21:29:36 +03:00
# ---------------------------------------------------------------------
# all images are gone (flat mirror and stacked mirror)
2008-10-14 23:41:12 +04:00
#COMM "fail all mirror images of 2-way mirrored LV"
prepare_lvs_
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
mimages_are_on_ $lv1 $dev1 $dev2
mirrorlog_is_on_ $lv1 $dev5
2011-01-05 03:16:18 +03:00
aux disable_dev $dev1 $dev2
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
not lvs $vg /$lv1
recover_vg_ $dev1 $dev2
#COMM "fail all mirror images of 3-way (1 converting) mirrored LV"
prepare_lvs_
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
lvconvert -m+1 $vg /$lv1 $dev3
mimages_are_on_ $lv1 $dev1 $dev2 $dev3
mirrorlog_is_on_ $lv1 $dev5
2011-01-05 03:16:18 +03:00
aux disable_dev $dev1 $dev2 $dev3
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
not lvs $vg /$lv1
recover_vg_ $dev1 $dev2 $dev3
2008-01-17 21:29:36 +03:00
# ---------------------------------------------------------------------
# Multiple LVs
2008-10-14 23:41:12 +04:00
#COMM "fail a mirror image of one of mirrored LV"
prepare_lvs_
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv2 $vg $dev3 $dev4 $dev5 :1
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv2
mimages_are_on_ $lv1 $dev1 $dev2
mimages_are_on_ $lv2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $dev5
mirrorlog_is_on_ $lv2 $dev5
2011-01-05 03:16:18 +03:00
aux disable_dev $dev2
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
mimages_are_on_ $lv2 $dev3 $dev4
mirrorlog_is_on_ $lv2 $dev5
lv_is_linear_ $lv1
lv_is_on_ $lv1 $dev1
recover_vg_ $dev2
#COMM "fail mirror images, one for each mirrored LV"
prepare_lvs_
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv2 $vg $dev3 $dev4 $dev5 :1
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv2
mimages_are_on_ $lv1 $dev1 $dev2
mimages_are_on_ $lv2 $dev3 $dev4
mirrorlog_is_on_ $lv1 $dev5
mirrorlog_is_on_ $lv2 $dev5
2011-01-05 03:16:18 +03:00
aux disable_dev $dev2
aux disable_dev $dev4
2008-10-14 23:41:12 +04:00
vgreduce --removemissing --force $vg
lv_is_linear_ $lv1
lv_is_on_ $lv1 $dev1
lv_is_linear_ $lv2
lv_is_on_ $lv2 $dev3
recover_vg_ $dev2 $dev4
2008-01-17 21:29:36 +03:00
# ---------------------------------------------------------------------
# no failure
2008-10-14 23:41:12 +04:00
#COMM "no failures"
prepare_lvs_
2010-03-31 07:56:25 +04:00
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5 :0
2008-10-14 23:41:12 +04:00
lvchange -an $vg /$lv1
mimages_are_on_ $lv1 $dev1 $dev2
mirrorlog_is_on_ $lv1 $dev5
vgreduce --removemissing --force $vg
mimages_are_on_ $lv1 $dev1 $dev2
mirrorlog_is_on_ $lv1 $dev5
check_and_cleanup_lvs_
2008-01-17 21:29:36 +03:00
# ---------------------------------------------------------------------