2008-01-17 00:21:22 +03:00
#!/bin/sh
2013-09-16 13:18:31 +04:00
# Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
2008-01-17 00:21:22 +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
test_description = "ensure that pvmove works with basic options"
2011-01-05 03:16:18 +03:00
. lib/test
2008-01-17 00:21:22 +03:00
2012-03-04 20:02:19 +04:00
which mkfs.ext2 || skip
which md5sum || skip
2008-01-17 00:21:22 +03:00
# ---------------------------------------------------------------------
# Utilities
2013-09-16 13:18:31 +04:00
create_vg_( ) {
vgcreate -c n -s 128k $vg $( cat DEVICES)
2008-01-17 00:21:22 +03:00
}
2013-09-16 13:18:31 +04:00
# ---------------------------------------------------------------------
# Common environment setup/cleanup for each sub testcases
prepare_lvs_( ) {
lvcreate -l2 -n $lv1 $vg " $dev1 "
check lv_on $vg $lv1 " $dev1 "
lvcreate -l9 -i3 -n $lv2 $vg " $dev2 " " $dev3 " " $dev4 "
check lv_on $vg $lv2 " $dev2 " " $dev3 " " $dev4 "
lvextend -l+2 $vg /$lv1 " $dev2 "
check lv_on $vg $lv1 " $dev1 " " $dev2 "
lvextend -l+2 $vg /$lv1 " $dev3 "
lvextend -l+2 $vg /$lv1 " $dev1 "
check lv_on $vg $lv1 " $dev1 " " $dev2 " " $dev3 "
lvcreate -l1 -n $lv3 $vg " $dev2 "
check lv_on $vg $lv3 " $dev2 "
aux mkdev_md5sum $vg $lv1
aux mkdev_md5sum $vg $lv2
aux mkdev_md5sum $vg $lv3
get lv_devices " $vg / $lv1 " > " ${ lv1 } _devs "
get lv_devices " $vg / $lv2 " > " ${ lv2 } _devs "
get lv_devices " $vg / $lv3 " > " ${ lv3 } _devs "
lvs -a -o name,size,seg_pe_ranges $vg
vgcfgbackup -f bak-$$ $vg
2008-01-17 00:21:22 +03:00
}
2013-09-16 13:18:31 +04:00
# Restore metadata content, since data are pvmove-ed
# original content should be preserved
restore_lvs_( ) {
vgcfgrestore -f bak-$$ $vg
vgchange -ay $vg
2008-01-17 00:21:22 +03:00
}
2013-09-16 13:18:31 +04:00
lvs_not_changed_( ) {
for i in " ${ @ } " ; do
get lv_devices " $vg / $i " | tee out
diff " ${ i } _devs " out || \
( cat " ${ i } _devs " ; die " Devices for LV $vg / $i differs! " )
done
2008-01-17 00:21:22 +03:00
}
2013-09-16 13:18:31 +04:00
check_and_cleanup_lvs_( ) {
check dev_md5sum $vg $lv1
check dev_md5sum $vg $lv2
check dev_md5sum $vg $lv3
get lv_field $vg name >out
not grep ^pvmove out
vgchange -an $vg
lvremove -ff $vg
( dm_table | not grep $vg ) || \
die "ERROR: lvremove did leave some some mappings in DM behind!"
2012-03-04 20:02:19 +04:00
}
2013-09-16 13:18:31 +04:00
2008-01-17 00:21:22 +03:00
# ---------------------------------------------------------------------
# Initialize PVs and VGs
2012-03-04 20:02:19 +04:00
aux prepare_pvs 5 5
create_vg_
2008-01-17 00:21:22 +03:00
2008-10-06 20:47:07 +04:00
#COMM "check environment setup/cleanup"
prepare_lvs_
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---------------------------------------------------------------------
# pvmove tests
# ---
# filter by LV
2008-10-06 20:47:07 +04:00
#COMM "only specified LV is moved: from pv2 to pv5 only for lv1"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i1 -n $vg /$lv1 " $dev2 " " $dev5 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv1 " $dev1 " " $dev5 " " $dev3 "
lvs_not_changed_ $lv2 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---
# segments in a LV
2008-10-06 20:47:07 +04:00
#COMM "the 1st seg of 3-segs LV is moved: from pv1 of lv1 to pv4"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 -n $vg /$lv1 " $dev1 " " $dev4 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv1 " $dev4 " " $dev2 " " $dev3 "
lvs_not_changed_ $lv2 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "the 2nd seg of 3-segs LV is moved: from pv2 of lv1 to pv4"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 -n $vg /$lv1 " $dev2 " " $dev4 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv1 " $dev1 " " $dev4 " " $dev3 "
lvs_not_changed_ $lv2 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "the 3rd seg of 3-segs LV is moved: from pv3 of lv1 to pv4"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 -n $vg /$lv1 " $dev3 " " $dev4 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv1 " $dev1 " " $dev2 " " $dev4 "
lvs_not_changed_ $lv2 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---
# multiple LVs matching
2008-10-06 20:47:07 +04:00
#COMM "1 out of 3 LVs is moved: from pv4 to pv5"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 " $dev4 " " $dev5 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev2 " " $dev3 " " $dev5 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "2 out of 3 LVs are moved: from pv3 to pv5"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 " $dev3 " " $dev5 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv1 " $dev1 " " $dev2 " " $dev5 "
check lv_on $vg $lv2 " $dev2 " " $dev5 " " $dev4 "
lvs_not_changed_ $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "3 out of 3 LVs are moved: from pv2 to pv5"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 " $dev2 " " $dev5 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv1 " $dev1 " " $dev5 " " $dev3 "
check lv_on $vg $lv2 " $dev5 " " $dev3 " " $dev4 "
check lv_on $vg $lv3 " $dev5 "
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---
# areas of striping
2008-10-06 20:47:07 +04:00
#COMM "move the 1st stripe: from pv2 of lv2 to pv1"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 -n $vg /$lv2 " $dev2 " " $dev1 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev1 " " $dev3 " " $dev4 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "move the 2nd stripe: from pv3 of lv2 to pv1"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 -n $vg /$lv2 " $dev3 " " $dev1 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev2 " " $dev1 " " $dev4 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "move the 3rd stripe: from pv4 of lv2 to pv1"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 -n $vg /$lv2 " $dev4 " " $dev1 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev2 " " $dev3 " " $dev1 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---
# partial segment match (source segment splitted)
2008-10-06 20:47:07 +04:00
#COMM "match to the start of segment:from pv2:0-0 to pv5"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 " $dev2 " :0-0 " $dev5 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev5 " " $dev2 " " $dev3 " " $dev4 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2013-09-16 13:18:31 +04:00
#exit 0
2008-10-06 20:47:07 +04:00
#COMM "match to the middle of segment: from pv2:1-1 to pv5"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 " $dev2 " :1-1 " $dev5 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev2 " " $dev3 " " $dev4 " " $dev5 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "match to the end of segment: from pv2:2-2 to pv5"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 " $dev2 " :2-2 " $dev5 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev2 " " $dev5 " " $dev3 " " $dev4 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---
# destination segment splitted
2008-10-06 20:47:07 +04:00
#COMM "no destination split: from pv2:0-2 to pv5"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 " $dev2 " :0-2 " $dev5 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev5 " " $dev3 " " $dev4 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "destination split into 2: from pv2:0-2 to pv5:5-5 and pv4:5-6"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 --alloc anywhere " $dev2 " :0-2 " $dev5 " :5-5 " $dev4 " :5-6
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev5 " " $dev4 " " $dev3 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "destination split into 3: from pv2:0-2 to {pv3,4,5}:5-5"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 --alloc anywhere " $dev2 " :0-2 " $dev3 " :5-5 " $dev4 " :5-5 " $dev5 " :5-5
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev3 " " $dev4 " " $dev5 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---
# alloc policy (anywhere, contiguous) with both success and failure cases
2012-03-16 17:00:05 +04:00
#COMM "alloc normal on same PV for source and destination: from pv3:0-2 to pv3:5-7"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
not pvmove -i0 " $dev3 " :0-2 " $dev3 " :5-7
2008-10-06 20:47:07 +04:00
# "(cleanup previous test)"
2013-09-16 13:18:31 +04:00
lvs_not_changed_ $lv1 $lv2 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "alloc anywhere on same PV for source and destination: from pv3:0-2 to pv3:5-7"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 --alloc anywhere " $dev3 " :0-2 " $dev3 " :5-7
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev2 " " $dev3 " " $dev4 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "alloc anywhere but better area available: from pv3:0-2 to pv3:5-7 or pv5:5-6,pv4:5-5"
2013-09-16 13:18:31 +04:00
restore_lvs_
#lvs -a -o name,size,seg_pe_ranges $vg
#LV2 1.12m @TESTDIR@/dev/mapper/@PREFIX@pv2:0-2 @TESTDIR@/dev/mapper/@PREFIX@pv3:0-2 @TESTDIR@/dev/mapper/@PREFIX@pv4:0-2
2012-03-16 17:00:05 +04:00
pvmove -i0 --alloc anywhere " $dev3 " :0-2 " $dev3 " :5-7 " $dev5 " :5-6 " $dev4 " :5-5
2013-09-16 13:18:31 +04:00
#lvs -a -o name,size,seg_pe_ranges $vg
# Hmm is this correct ? - why pv2 is split
#LV2 1.12m @TESTDIR@/dev/mapper/@PREFIX@pv2:0-1 @TESTDIR@/dev/mapper/@PREFIX@pv5:5-6 @TESTDIR@/dev/mapper/@PREFIX@pv4:0-1
#LV2 1.12m @TESTDIR@/dev/mapper/@PREFIX@pv2:2-2 @TESTDIR@/dev/mapper/@PREFIX@pv3:5-5 @TESTDIR@/dev/mapper/@PREFIX@pv4:2-2
check lv_on $vg $lv2 " $dev2 " " $dev3 " " $dev4 " " $dev5 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "alloc contiguous but area not available: from pv2:0-2 to pv5:5-5 and pv4:5-6"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
not pvmove -i0 --alloc contiguous " $dev2 " :0-2 " $dev5 " :5-5 " $dev4 " :5-6
2008-10-06 20:47:07 +04:00
# "(cleanup previous test)"
2013-09-16 13:18:31 +04:00
lvs_not_changed_ $lv1 $lv2 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "alloc contiguous and contiguous area available: from pv2:0-2 to pv5:0-0,pv5:3-5 and pv4:5-6"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 --alloc contiguous " $dev2 " :0-2 " $dev5 " :0-0 " $dev5 " :3-5 " $dev4 " :5-6
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv2 " $dev5 " " $dev3 " " $dev4 "
lvs_not_changed_ $lv1 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---
# multiple segments in a LV
2008-10-06 20:47:07 +04:00
#COMM "multiple source LVs: from pv3 to pv5"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 " $dev3 " " $dev5 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv1 " $dev1 " " $dev2 " " $dev5 "
check lv_on $vg $lv2 " $dev2 " " $dev5 " " $dev4 "
lvs_not_changed_ $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---
# move inactive LV
2008-10-06 20:47:07 +04:00
#COMM "move inactive LV: from pv2 to pv5"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
lvchange -an $vg /$lv1
lvchange -an $vg /$lv3
pvmove -i0 " $dev2 " " $dev5 "
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv1 " $dev1 " " $dev5 " " $dev3 "
check lv_on $vg $lv2 " $dev5 " " $dev3 " " $dev4 "
check lv_on $vg $lv3 " $dev5 "
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---
# other failure cases
2008-10-06 20:47:07 +04:00
#COMM "no PEs to move: from pv3 to pv1"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i0 " $dev3 " " $dev1 "
not pvmove -i0 " $dev3 " " $dev1 "
2008-10-06 20:47:07 +04:00
# "(cleanup previous test)"
2013-09-16 13:18:31 +04:00
check lv_on $vg $lv1 " $dev1 " " $dev2 " " $dev1 "
check lv_on $vg $lv2 " $dev2 " " $dev1 " " $dev4 "
lvs_not_changed_ $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2012-03-16 17:00:05 +04:00
#COMM "no space available: from pv2:0-0 to pv1:0-0"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
not pvmove -i0 " $dev2 " :0-0 " $dev1 " :0-0
2008-10-06 20:47:07 +04:00
# "(cleanup previous test)"
2013-09-16 13:18:31 +04:00
lvs_not_changed_ $lv1 $lv2 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM 'same source and destination: from pv1 to pv1'
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
not pvmove -i0 " $dev1 " " $dev1 "
2008-10-06 20:47:07 +04:00
#"(cleanup previous test)"
2013-09-16 13:18:31 +04:00
lvs_not_changed_ $lv1 $lv2 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
#COMM "sum of specified destination PEs is large enough, but it includes source PEs and the free PEs are not enough"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
not pvmove --alloc anywhere " $dev1 " :0-2 " $dev1 " :0-2 " $dev5 " :0-0 2> err
2008-10-06 20:47:07 +04:00
#"(cleanup previous test)"
2012-03-16 17:00:05 +04:00
grep "Insufficient free space" err
2013-09-16 13:18:31 +04:00
lvs_not_changed_ $lv1 $lv2 $lv3
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
# ---------------------------------------------------------------------
2008-10-06 20:47:07 +04:00
#COMM "pvmove abort"
2013-09-16 13:18:31 +04:00
restore_lvs_
2012-03-16 17:00:05 +04:00
pvmove -i100 -b " $dev1 " " $dev3 "
pvmove --abort
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-17 00:21:22 +03:00
2008-11-10 15:41:52 +03:00
#COMM "pvmove out of --metadatacopies 0 PV (bz252150)"
vgremove -ff $vg
2011-01-05 03:16:18 +03:00
pvcreate $( cat DEVICES)
2012-03-16 17:00:05 +04:00
pvcreate --metadatacopies 0 " $dev1 " " $dev2 "
2012-03-04 20:02:19 +04:00
create_vg_
2012-03-16 17:00:05 +04:00
lvcreate -l4 -n $lv1 $vg " $dev1 "
pvmove " $dev1 "
2008-11-10 15:41:52 +03:00
2009-05-19 13:51:02 +04:00
#COMM "pvmove fails activating mirror, properly restores state before pvmove"
2012-03-16 17:00:05 +04:00
dmsetup create $vg -pvmove0 --notable
not pvmove -i 1 " $dev2 "
test $( dmsetup info --noheadings -c -o suspended $vg -$lv1 ) = "Active"
dmsetup remove $vg -pvmove0