2012-03-16 17:00:05 +04:00
#!/bin/sh
# Copyright (C) 2008-2012 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,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2008-01-17 21:29:36 +03:00
2008-10-14 23:41:12 +04:00
test_description = "ensure that 'vgreduce --removemissing' works on mirrored LV"
2016-02-23 01:13:42 +03:00
SKIP_WITH_LVMLOCKD = 1
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
2008-10-14 23:41:12 +04:00
2014-10-01 10:31:53 +04:00
# disable lvmetad logging as it bogs down test systems
2015-05-01 15:45:47 +03:00
export LVM_TEST_LVMETAD_DEBUG_OPTS = ${ LVM_TEST_LVMETAD_DEBUG_OPTS - }
. lib/inittest
2014-10-01 10:31:53 +04:00
2008-01-17 21:29:36 +03:00
lv_is_on_ ( )
{
2008-10-14 23:41:12 +04:00
local lv = $vg /$1
shift
2012-03-16 17:00:05 +04:00
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
2012-03-16 17:00:05 +04:00
get lv_devices $lv | sed 's/ /\n/g' | 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
2012-03-16 17:00:05 +04:00
local pvs = $@
2008-10-14 23:41:12 +04:00
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
2013-06-15 13:21:03 +04:00
lvs --noheadings -a -o lv_name $vg | tee lvs_log
2011-03-03 18:46:05 +03:00
mimages = $( grep " ${ lv } _mimage_ " lvs_log | \
sed 's/\[//g; s/\]//g' || true )
2012-03-16 17:00:05 +04:00
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
2013-06-15 13:21:03 +04:00
lvs -a -odevices --noheadings $vg /$i | tee lvs_log
2011-03-03 18:46:05 +03:00
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_( )
{
2012-03-16 17:00:05 +04:00
local lv = ${ 1 } _mlog
2008-10-14 23:41:12 +04:00
shift
2012-03-16 17:00:05 +04:00
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) "
2013-06-15 13:21:03 +04:00
get lv_field $vg /$1 "stripes,attr" | tee out
grep "^1 -" out >/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
2012-03-16 17:00:05 +04:00
local rem =
2008-10-14 23:41:12 +04:00
local n
2014-06-30 22:04:24 +04:00
local dev
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
2014-06-30 22:04:24 +04:00
eval dev = $\d ev$n
2008-10-14 23:41:12 +04:00
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
2013-06-15 13:21:03 +04:00
aux prepare_pvs 5 80
2008-01-17 21:29:36 +03:00
2013-06-15 13:21:03 +04:00
vgcreate -s 64k $vg $( cat DEVICES)
BLOCKS = 0-7
BLOCKS1 = 8-15
2008-01-17 21:29:36 +03:00
# ---------------------------------------------------------------------
# Common environment setup/cleanup for each sub testcases
prepare_lvs_( )
{
2012-03-28 15:10:08 +04:00
lvremove -ff $vg
( dm_table | not grep $vg ) || \
2012-03-16 17:00:05 +04:00
die "ERROR: lvremove did leave some some mappings in DM behind!"
2008-01-17 21:29:36 +03:00
}
check_and_cleanup_lvs_( )
{
2012-03-16 17:00:05 +04:00
lvs -a -o+devices $vg
2012-03-28 15:10:08 +04:00
prepare_lvs_
2008-01-17 21:29:36 +03:00
}
recover_vg_( )
{
2012-03-16 17:00:05 +04:00
aux enable_dev " $@ "
pvcreate -ff " $@ "
vgextend $vg " $@ "
2008-10-14 23:41:12 +04:00
check_and_cleanup_lvs_
2008-01-17 21:29:36 +03:00
}
2012-03-16 17:00:05 +04:00
#COMM "check environment setup/cleanup"
prepare_lvs_
2008-10-14 23:41:12 +04:00
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_
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv1 $vg " $dev1 " " $dev2 " " $dev3 " :$BLOCKS
2014-03-20 02:32:25 +04:00
mimages_are_on_ $lv1 " $dev1 " " $dev2 "
mirrorlog_is_on_ $lv1 " $dev3 "
2012-03-16 17:00:05 +04:00
aux disable_dev " $dev2 "
2008-09-29 20:02:50 +04:00
vgreduce --removemissing --force $vg
lv_is_linear_ $lv1
2012-03-16 17:00:05 +04:00
lv_is_on_ $lv1 " $dev1 "
2008-09-29 20:02:50 +04:00
2008-10-14 23:41:12 +04:00
# "cleanup"
2012-03-16 17:00:05 +04:00
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
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m2 --nosync -n $lv1 $vg " $dev1 " " $dev2 " " $dev3 " " $dev4 " :$BLOCKS
2012-03-16 17:00:05 +04:00
mimages_are_on_ $lv1 " $dev1 " " $dev2 " " $dev3 "
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
mimages_are_on_ $lv1 $( rest_pvs_ $index 3)
2012-03-16 17:00:05 +04:00
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
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m2 --nosync -n $lv1 $vg " $dev1 " " $dev2 " " $dev3 " " $dev4 " :$BLOCKS
2012-03-16 17:00:05 +04:00
mimages_are_on_ $lv1 " $dev1 " " $dev2 " " $dev3 "
mirrorlog_is_on_ $lv1 " $dev4 "
2008-10-14 23:41:12 +04:00
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
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
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m2 -n $lv1 $vg " $dev1 " " $dev2 " " $dev3 " " $dev5 " :$BLOCKS
2012-03-16 17:00:05 +04:00
lvconvert -m+1 $vg /$lv1 " $dev4 "
check mirror_images_on $vg $lv1 " $dev1 " " $dev2 " " $dev3 " " $dev4 "
check mirror_log_on $vg $lv1 " $dev5 "
eval aux disable_dev \$ dev$index
2011-05-07 19:52:16 +04:00
lvs -a -o +devices
2012-03-16 17:00:05 +04:00
vgreduce --removemissing --force $vg
lvs -a -o+devices # $vg
check mirror_images_on $vg $lv1 " $dev5 " # $(rest_pvs_ $index 4)
check mirror_log_on $vg $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
2014-06-30 22:04:24 +04:00
local dev
2008-10-14 23:41:12 +04:00
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m2 -n $lv1 $vg " $dev1 " " $dev2 " " $dev3 " " $dev5 " :$BLOCKS
2012-03-16 17:00:05 +04:00
lvconvert -m+1 $vg /$lv1 " $dev4 "
check mirror_images_on $vg $lv1 " $dev1 " " $dev2 " " $dev3 " " $dev4 "
check mirror_log_on $vg $lv1 " $dev5 "
2011-05-07 19:52:16 +04:00
lvs -a -o+devices $vg
aux disable_dev $( rest_pvs_ $index 4)
vgreduce --removemissing --force $vg
lvs -a -o+devices $vg
2014-06-30 22:04:24 +04:00
eval dev = \$ dev$n
2011-05-07 19:52:16 +04:00
check linear $vg $lv1
2014-06-30 22:04:24 +04:00
check lv_on $vg $lv1 " $dev "
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
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m1 -n $lv1 $vg " $dev1 " " $dev2 " " $dev5 " :$BLOCKS
2012-03-16 17:00:05 +04:00
lvconvert -m+2 $vg /$lv1 " $dev3 " " $dev4 "
mimages_are_on_ $lv1 " $dev1 " " $dev2 " " $dev3 " " $dev4 "
mirrorlog_is_on_ $lv1 " $dev5 "
eval aux disable_dev \$ dev$n
vgreduce --removemissing --force $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
2012-03-16 17:00:05 +04:00
#COMM "fail mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV"
prepare_lvs_
2008-10-14 23:41:12 +04:00
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
2014-06-30 22:04:24 +04:00
local dev
2008-10-14 23:41:12 +04:00
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m1 -n $lv1 $vg " $dev1 " " $dev2 " " $dev5 " :$BLOCKS
2012-03-16 17:00:05 +04:00
lvconvert -m+2 $vg /$lv1 " $dev3 " " $dev4 "
mimages_are_on_ $lv1 " $dev1 " " $dev2 " " $dev3 " " $dev4 "
mirrorlog_is_on_ $lv1 " $dev5 "
aux disable_dev $( rest_pvs_ $index 4)
vgreduce --removemissing --force $vg
lvs -a -o+devices $vg
2014-06-30 22:04:24 +04:00
eval dev = \$ dev$n
2014-03-20 02:32:25 +04:00
mimages_are_on_ $lv1 " $dev " || lv_is_on_ $lv1 " $dev "
2012-03-16 17:00:05 +04:00
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)
2012-03-16 17:00:05 +04:00
#COMM "fail mirror log of 2-way mirrored LV"
prepare_lvs_
2013-08-08 00:48:31 +04:00
lvcreate -aey -l2 --type mirror -m1 -n $lv1 $vg " $dev1 " " $dev2 " " $dev5 " :$BLOCKS
2012-03-16 17:00:05 +04:00
mimages_are_on_ $lv1 " $dev1 " " $dev2 "
mirrorlog_is_on_ $lv1 " $dev5 "
aux disable_dev " $dev5 "
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_
2013-08-08 00:48:31 +04:00
lvcreate -aey -l2 --type mirror -m1 -n $lv1 $vg " $dev1 " " $dev2 " " $dev5 " :$BLOCKS
2012-03-16 17:00:05 +04:00
lvconvert -m+1 $vg /$lv1 " $dev3 "
mimages_are_on_ $lv1 " $dev1 " " $dev2 " " $dev3 "
mirrorlog_is_on_ $lv1 " $dev5 "
aux disable_dev " $dev5 "
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"
2012-03-16 17:00:05 +04:00
prepare_lvs_
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv1 $vg " $dev1 " " $dev2 " " $dev5 " :$BLOCKS
2012-03-16 17:00:05 +04:00
mimages_are_on_ $lv1 " $dev1 " " $dev2 "
mirrorlog_is_on_ $lv1 " $dev5 "
aux disable_dev " $dev1 " " $dev2 "
vgreduce --removemissing --force $vg
2008-10-14 23:41:12 +04:00
not lvs $vg /$lv1
2012-03-16 17:00:05 +04:00
recover_vg_ " $dev1 " " $dev2 "
2008-10-14 23:41:12 +04:00
#COMM "fail all mirror images of 3-way (1 converting) mirrored LV"
2012-03-16 17:00:05 +04:00
prepare_lvs_
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m1 -n $lv1 $vg " $dev1 " " $dev2 " " $dev5 " :$BLOCKS
2012-03-16 17:00:05 +04:00
lvconvert -m+1 $vg /$lv1 " $dev3 "
mimages_are_on_ $lv1 " $dev1 " " $dev2 " " $dev3 "
mirrorlog_is_on_ $lv1 " $dev5 "
aux disable_dev " $dev1 " " $dev2 " " $dev3 "
vgreduce --removemissing --force $vg
2008-10-14 23:41:12 +04:00
not lvs $vg /$lv1
2012-03-16 17:00:05 +04:00
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"
2012-03-16 17:00:05 +04:00
prepare_lvs_
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv1 $vg " $dev1 " " $dev2 " " $dev5 " :$BLOCKS
lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv2 $vg " $dev3 " " $dev4 " " $dev5 " :$BLOCKS1
2012-03-16 17:00:05 +04:00
mimages_are_on_ $lv1 " $dev1 " " $dev2 "
mimages_are_on_ $lv2 " $dev3 " " $dev4 "
mirrorlog_is_on_ $lv1 " $dev5 "
mirrorlog_is_on_ $lv2 " $dev5 "
aux disable_dev " $dev2 "
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 "
2008-10-14 23:41:12 +04:00
#COMM "fail mirror images, one for each mirrored LV"
2012-03-16 17:00:05 +04:00
prepare_lvs_
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv1 $vg " $dev1 " " $dev2 " " $dev5 " :$BLOCKS
lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv2 $vg " $dev3 " " $dev4 " " $dev5 " :$BLOCKS1
2012-03-16 17:00:05 +04:00
mimages_are_on_ $lv1 " $dev1 " " $dev2 "
mimages_are_on_ $lv2 " $dev3 " " $dev4 "
mirrorlog_is_on_ $lv1 " $dev5 "
mirrorlog_is_on_ $lv2 " $dev5 "
aux disable_dev " $dev2 "
aux disable_dev " $dev4 "
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"
2012-03-16 17:00:05 +04:00
prepare_lvs_
2013-08-08 00:48:31 +04:00
lvcreate -an -Zn -l2 --type mirror -m1 --nosync -n $lv1 $vg " $dev1 " " $dev2 " " $dev5 " :$BLOCKS
2012-03-16 17:00:05 +04:00
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 "
2008-10-14 23:41:12 +04:00
check_and_cleanup_lvs_
2008-01-17 21:29:36 +03:00
# ---------------------------------------------------------------------