2008-01-31 15:19:36 +03:00
#!/bin/sh
# Copyright (C) 2007-2008 Red Hat, Inc. All rights reserved.
# Copyright (C) 2007-2008 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 = "check namings of mirrored LV"
2008-10-06 20:47:07 +04:00
. ./test-utils.sh
2008-01-31 15:19:36 +03:00
2008-10-06 20:47:07 +04:00
dmsetup_has_dm_devdir_support_ || exit 200
2008-01-31 15:19:36 +03:00
# ---------------------------------------------------------------------
# Utilities
2008-10-06 20:47:07 +04:00
lv_devices_( ) {
2008-01-31 15:19:36 +03:00
local d
local lv = $1
shift
local devices = $*
local devs = $( lvs -a -odevices --noheadings $lv | sed 's/([0-9]*)//g' |
sed 's/ //g' | sed 's/,/ /g' )
for d in $devs ; do
( echo $devices | grep -q $d ) || return 1
devices = $( echo $devices | sed " s/ $d // " )
done
[ " $( echo $devices | sed 's/ //g' ) " = "" ]
}
2008-10-06 20:47:07 +04:00
lv_mirror_log_( ) {
2008-01-31 15:19:36 +03:00
local lv = $1
echo $( lvs -a -omirror_log --noheadings $lv | sed 's/ //g' )
}
2008-10-06 20:47:07 +04:00
lv_convert_lv_( ) {
2008-01-31 15:19:36 +03:00
local lv = $1
echo $( lvs -a -oconvert_lv --noheadings $lv | sed 's/ //g' )
}
# ---------------------------------------------------------------------
# Initialize PVs and VGs
2008-10-06 20:47:07 +04:00
aux prepare_vg 5 80
2008-01-31 15:19:36 +03:00
# ---------------------------------------------------------------------
# Common environment setup/cleanup for each sub testcases
2008-10-06 20:47:07 +04:00
prepare_lvs_( ) {
2008-11-10 15:32:00 +03:00
lvremove -ff $vg
if dmsetup table| grep $vg ; then
echo "ERROR: lvremove did leave some some mappings in DM behind!"
return 1
fi
2008-01-31 15:19:36 +03:00
:
}
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_( ) {
lvs -a -o+devices $vg
2008-01-31 15:19:36 +03: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-01-31 15:19:36 +03:00
}
2008-10-06 20:47:07 +04:00
prepare_lvs_
check_and_cleanup_lvs_
2008-01-31 15:19:36 +03:00
# ---------------------------------------------------------------------
# basic
2008-10-06 20:47:07 +04:00
#COMM "init: lvcreate"
prepare_lvs_
2008-01-31 15:19:36 +03:00
2008-10-06 20:47:07 +04:00
#COMM "mirror images are ${lv1}_mimage_x"
lvcreate -l2 -m1 -n $lv1 $vg
lv_devices_ $vg /$lv1 " $lv1 " _mimage_0 " $lv1 " _mimage_1
2008-01-31 15:19:36 +03:00
2008-10-06 20:47:07 +04:00
#COMM "mirror log is ${lv1}_mlog"
lv_mirror_log_ $vg /$lv1 " $lv1 " _mlog
2008-01-31 15:19:36 +03:00
2008-11-10 15:41:52 +03:00
# "cleanup"
check_and_cleanup_lvs_
#COMM "mirror with name longer than 22 characters (bz221322)"
name = "LVwithanamelogerthan22characters_butidontwonttocounthem"
lvcreate -m1 -l2 -n" $name " $vg
lvs $vg /" $name "
2008-10-06 20:47:07 +04:00
check_and_cleanup_lvs_
2008-01-31 15:19:36 +03:00
# ---------------------------------------------------------------------
# lvrename
2008-10-06 20:47:07 +04:00
#COMM "init: lvrename"
prepare_lvs_
2008-01-31 15:19:36 +03:00
2008-10-06 20:47:07 +04:00
#COMM "renamed mirror names: $lv1 to $lv2"
lvcreate -l2 -m1 -n $lv1 $vg
lvrename $vg /$lv1 $vg /$lv2
lv_devices_ $vg /$lv2 " $lv2 " _mimage_0 " $lv2 " _mimage_1
lv_mirror_log_ $vg /$lv2 " $lv2 " _mlog
2008-01-31 15:19:36 +03:00
2008-10-06 20:47:07 +04:00
#COMM "cleanup"
check_and_cleanup_lvs_
2008-01-31 15:19:36 +03:00
# ---------------------------------------------------------------------
# lvconvert
2008-10-06 20:47:07 +04:00
#COMM "init: lvconvert"
prepare_lvs_
#COMM "converting mirror names is ${lv1}_mimagetmp_2"
lvcreate -l2 -m1 -n $lv1 $vg
lvconvert -m+1 -i1000 -b $vg /$lv1
convlv = $( lv_convert_lv_ " $vg / $lv1 " )
test " $convlv " = " $lv1 " _mimagetmp_2
lv_devices_ $vg /$lv1 " $convlv " " $lv1 " _mimage_2
lv_devices_ " $vg / $convlv " " $lv1 " _mimage_0 " $lv1 " _mimage_1
loglv = $( lv_mirror_log_ " $vg / $convlv " )
test " $loglv " = " $lv1 " _mlog
#COMM "mirror log name after re-adding is ${lv1}_mlog" \
lvconvert --mirrorlog core $vg /$lv1
lvconvert --mirrorlog disk $vg /$lv1
convlv = $( lv_convert_lv_ " $vg / $lv1 " )
lv_devices_ $vg /$lv1 " $convlv " " $lv1 " _mimage_2
lv_devices_ " $vg / $convlv " " $lv1 " _mimage_0 " $lv1 " _mimage_1
loglv = $( lv_mirror_log_ " $vg / $convlv " )
test " $loglv " = " $lv1 " _mlog
#COMM "renamed converting mirror names: $lv1 to $lv2" \
lvrename $vg /$lv1 $vg /$lv2
convlv = $( lv_convert_lv_ " $vg / $lv2 " )
lv_devices_ $vg /$lv2 " $convlv " " $lv2 " _mimage_2
lv_devices_ " $vg / $convlv " " $lv2 " _mimage_0 " $lv2 " _mimage_1
loglv = $( lv_mirror_log_ " $vg / $convlv " )
test " $loglv " = " $lv2 " _mlog
#COMM "cleanup"
check_and_cleanup_lvs_
2008-01-31 15:19:36 +03:00
# Temporary mirror log should have "_mlogtmp_<n>" suffix
# but currently lvconvert doesn't have an option to add the log.
# If such feature is added in future, a test for that should
# be added.
# ---------------------------------------------------------------------