1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-10 05:18:36 +03:00

A fairly extensive refactor of the mirror testing code. The exhaustive

lvconvert testing is now in its own test, t-lvconvert-mirror-basic ... it
doesn't do anything fancy but it does run lvconvert through a lot of
combinations.

I have also merged the remaining t-mirror-lvconvert tests into
t-lvconvert-mirror and abolished the former. The latter will be split again
later into more thematic divisions. (The previous split was rather arbitrary,
may I even say random...)
This commit is contained in:
Petr Rockai 2010-05-12 10:08:35 +00:00
parent 2400150734
commit d7eaafe9c1
7 changed files with 378 additions and 804 deletions

View File

@ -1,5 +1,18 @@
#!/bin/bash
# check.sh: assert various things about volumes
# USAGE
# check linear VG LV
# check lv_on VG LV PV
# check mirror VG LV [LOGDEV|core]
# check mirror_nonredundant VG LV
# check mirror_legs VG LV N
# check mirror_images_on VG LV DEV [DEV...]
# ...
set -e -o pipefail
lvl() {
@ -15,7 +28,7 @@ mirror_images_redundant()
vg=$1
lv=$vg/$2
lvs -a $vg
lvs -a $vg -o+devices
for i in `lvdevices $lv`; do
echo "# $i:"
lvdevices $vg/$i | sort | uniq
@ -31,23 +44,26 @@ mirror_images_redundant()
}
mirror_images_on() {
lv=$1
vg=$1
lv=$2
shift 2
for i in `lvdevices $lv`; do
lv_on $vg $lv $1
shift
lv_on $lv $1
done
}
lv_on()
{
lv="$1"
lvdevices $lv | grep -F "$2" || {
echo "LV $lv expected on $2 but is not:" >&2
lv="$1/$2"
lvdevices $lv | grep -F "$3" || {
echo "LV $lv expected on $3 but is not:" >&2
lvdevices $lv >&2
exit 1
}
test `lvdevices $lv | grep -vF "$2" | wc -l` -eq 0 || {
test `lvdevices $lv | grep -vF "$3" | wc -l` -eq 0 || {
echo "LV $lv contains unexpected devices:" >&2
lvdevices $lv >&2
exit 1
@ -56,7 +72,14 @@ lv_on()
mirror_log_on()
{
lv_on "${1}_mlog" "$2"
vg="$1"
lv="$2"
where="$3"
if test "$where" = "core"; then
lvl -omirror_log "$vg/$lv" | not grep mlog
else
lv_on $vg "${lv}_mlog" "$where"
fi
}
lv_is_contiguous()
@ -92,14 +115,18 @@ mirror_images_clung()
}
mirror() {
mirror_nonredundant "$@"
mirror_images_redundant "$1" "$2"
}
mirror_nonredundant() {
lv="$1/$2"
lvl -oattr "$lv" | grep "m" || {
lvs -oattr "$lv" | grep -q "^ *m.....$" || {
echo "$lv expected a mirror, but is not:"
lvl -a $lv
lvs -a $lv
exit 1
}
mirror_images_redundant "$1" "$2"
if test -n "$3"; then mirror_log_on "$lv" "$3"; fi
if test -n "$3"; then mirror_log_on "$1" "$2" "$3"; fi
}
mirror_legs() {
@ -110,6 +137,17 @@ mirror_legs() {
test "$expect" = "$real"
}
mirror_no_temporaries()
{
vg=$1
lv=$2
lvl -oname $vg | grep $lv | not grep "tmp" || {
echo "$lv has temporary mirror images unexpectedly:"
lvl $vg | grep $lv
exit 1
}
}
linear() {
lv="$1/$2"
lvl -ostripes "$lv" | grep -q "1" || {

View File

@ -0,0 +1,139 @@
. ./test-utils.sh
log_name_to_count()
{
if [ $1 == "mirrored" ]; then
echo 2
elif [ $1 == "disk" ]; then
echo 1
else
echo 0
fi
}
# FIXME: For test_[up|down]convert, I'd still like to be able
# to specifiy devices - especially if I can do partial PV
# specification for down-converts. It may even be wise to
# do one round through these tests without specifying the PVs
# to use and one round where we do.
# test_lvconvert
# start_mirror_count: The '-m' argument to create with
# start_log_type: core|disk|mirrored
# final_mirror_count: The '-m' argument to convert to
# final_log_type: core|disk|mirrored
# active: Whether the LV should be active when the convert happens
#
# Exmaple: Convert 3-way disk-log mirror to
# 2-way disk-log mirror while not active
# -> test_lvconvert 2 disk 3 disk 0
test_lvconvert()
{
local start_count=$1
local start_count_p1=$(($start_count + 1))
local start_log_type=$2
local finish_count=$3
local finish_count_p1=$(($finish_count + 1))
local finish_log_type=$4
local dev_array=($dev1 $dev2 $dev3 $dev4 $dev5)
local start_log_count
local finish_log_count
local max_log_count
local alloc=""
local active=true
local i
if [ $start_log_type == "disk" ] &&
[ $finish_log_type == "mirrored" ]; then
echo "FIXME: disk -> mirrored log conversion not yet supported by LVM"
return 0
fi
test "$5" = "active" && active=false
#test $finish_count -gt $start_count && up=true
# Do we have enough devices for the mirror images?
if [ $start_count_p1 -gt ${#dev_array[@]} ]; then
echo "Action requires too many devices"
return 1
fi
# Do we have enough devices for the mirror images?
if [ $finish_count_p1 -gt ${#dev_array[@]} ]; then
echo "Action requires too many devices"
return 1
fi
start_log_count=`log_name_to_count $start_log_type`
finish_log_count=`log_name_to_count $finish_log_type`
if [ $finish_log_count -gt $start_log_count ]; then
max_log_count=$finish_log_count
else
max_log_count=$start_log_count
fi
prepare_vg 5
if [ $start_count -gt 0 ]; then
# Are there extra devices for the log or do we overlap
if [ $(($start_count_p1 + $start_log_count)) -gt ${#dev_array[@]} ]; then
alloc="--alloc anywhere"
fi
lvcreate -l2 -m $start_count --mirrorlog $start_log_type \
-n $lv1 $vg $alloc
check mirror_legs $vg $lv1 $start_count_p1
# FIXME: check mirror log
else
lvcreate -l2 -n $lv1 $vg
fi
lvs -a -o name,copy_percent,devices $vg
if ! $active; then
lvchange -an $vg/$lv1
fi
# Are there extra devices for the log or do we overlap
if [ $(($finish_count_p1 + $finish_log_count)) -gt ${#dev_array[@]} ]; then
alloc="--alloc anywhere"
fi
echo y | lvconvert -m $finish_count --mirrorlog $finish_log_type \
$vg/$lv1 $alloc
if ! $active; then
lvchange -ay $vg/$lv1
fi
check mirror_no_temporaries $vg $lv1
if [ "$finish_count_p1" -eq 1 ]; then
check linear $vg $lv1
else
if test -n "$alloc"; then
check mirror_nonredundant $vg $lv1
else
check mirror $vg $lv1
fi
check mirror_legs $vg $lv1 $finish_count_p1
fi
}
aux prepare_vg 5
# Test conversion combinations from linear <-> 4-way mirrors
for i in $(seq 0 4); do
for j in $(seq 0 4); do
for k in core disk mirrored; do
for l in core disk mirrored; do
if test "$i" -eq "$j" && test "$k" = "$l"; then continue; fi
: ----------------------------------------------------
: "Testing mirror conversion -m$i/$k -> -m$j/$l"
: ----------------------------------------------------
test_lvconvert $i $k $j $l 0
test_lvconvert $i $k $j $l 1
done
done
done
done

View File

@ -10,15 +10,15 @@
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
. ./test-utils.sh
aux prepare_vg 5
# convert from linear to 2-way mirror
aux prepare_vg 5
lvcreate -l2 -n $lv1 $vg $dev1
lvconvert -i1 -m+1 $vg/$lv1 $dev2 $dev3:0-1
check mirror $vg $lv1 $dev3
lvremove -ff $vg
# convert from 2-way mirror to linear
aux prepare_vg 5
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvconvert -m-1 $vg/$lv1
check linear $vg $lv1
@ -26,16 +26,18 @@ lvremove -ff $vg
# and now try removing a specific leg (bz453643)
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvconvert -m0 $vg/$lv1 $dev2
check lv_on $vg/$lv1 $dev1
check lv_on $vg $lv1 $dev1
lvremove -ff $vg
# convert from disklog to corelog, active
aux prepare_vg 5
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvconvert -f --mirrorlog core $vg/$lv1
check mirror $vg $lv1 ""
check mirror $vg $lv1 core
lvremove -ff $vg
# convert from corelog to disklog, active
aux prepare_vg 5
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
lvconvert --mirrorlog disk $vg/$lv1 $dev3:0-1
check mirror $vg $lv1 $dev3
@ -43,13 +45,15 @@ lvremove -ff $vg
# bz192865: lvconvert log of an inactive mirror lv
# convert from disklog to corelog, inactive
aux prepare_vg 5
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
lvchange -an $vg/$lv1
echo y | lvconvert -f --mirrorlog core $vg/$lv1
check mirror $vg $lv1 ""
check mirror $vg $lv1 core
lvremove -ff $vg
# convert from corelog to disklog, inactive
aux prepare_vg 5
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
lvchange -an $vg/$lv1
lvconvert --mirrorlog disk $vg/$lv1 $dev3:0-1
@ -57,6 +61,7 @@ check mirror $vg $lv1 $dev3
lvremove -ff $vg
# convert linear to 2-way mirror with 1 PV
aux prepare_vg 5
lvcreate -l2 -n $lv1 $vg $dev1
not lvconvert -m+1 --mirrorlog core $vg/$lv1 $dev1
lvremove -ff $vg
@ -70,13 +75,166 @@ lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev4 $dev3:0
# This is somewhat timing dependent - sync /could/ finish before
# we get a chance to have this command fail
should not lvconvert -m-1 $vg/$lv1 $dev1
while [ `lvs --noheadings -o copy_percent $vg/$lv1` != "100.00" ]; do
sleep 1
done
lvconvert -m2 $vg/$lv1 $dev1 $dev2 $dev4 $dev3:0
lvconvert $vg/$lv1 # wait
lvconvert -m2 $vg/$lv1 $dev1 $dev2 $dev4 $dev3:0 # If the above "should" failed...
lvconvert -m-1 $vg/$lv1 $dev1
check mirror_images_on $lv1 $dev2 $dev4
lvconvert -m-1 $vg/$lv1 $dev2
check linear $vg $lv1
check lv_on $vg/$lv1 $dev4
check lv_on $vg $lv1 $dev4
# No parallel lvconverts on a single LV please
aux prepare_vg 5
lvcreate -l5 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
check mirror $vg $lv1
check mirror_legs $vg $lv1 2
lvconvert -m+1 -b $vg/$lv1 $dev4
# Next convert should fail b/c we can't have 2 at once
should not lvconvert -m+1 $vg/$lv1 $dev5
lvconvert $vg/$lv1 # wait
lvconvert -m2 $vg/$lv1 # In case the above "should" actually failed
check mirror $vg $lv1 $dev3
check mirror_no_temporaries $vg $lv1
check mirror_legs $vg $lv1 3
# add 1 mirror to core log mirror, but
# implicitly keep log as 'core'
aux prepare_vg 5
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
lvconvert -m +1 -i1 $vg/$lv1
check mirror $vg $lv1 core
check mirror_no_temporaries $vg $lv1
check mirror_legs $vg $lv1 3
# remove 1 mirror from corelog'ed mirror; should retain 'core' log type
aux prepare_vg 5
lvcreate -l2 -m2 --corelog -n $lv1 $vg
lvconvert -m -1 -i1 $vg/$lv1
check mirror $vg $lv1 core
check mirror_no_temporaries $vg $lv1
check mirror_legs $vg $lv1 2
# add 1 mirror then add 1 more mirror during conversion
# FIXME this has been explicitly forbidden?
#aux prepare_vg 5
#lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
#lvconvert -m+1 -b $vg/$lv1 $dev4
#lvconvert -m+1 $vg/$lv1 $dev5
#
#check mirror $vg $lv1 $dev3
#check mirror_no_temporaries $vg $lv1
#check mirror_legs $vg $lv1 4
# Linear to mirror with mirrored log using --alloc anywhere
aux prepare_vg 5
lvcreate -l2 -n $lv1 $vg $dev1
lvconvert -m +1 --mirrorlog mirrored $vg/$lv1 $dev1 $dev2 --alloc anywhere
should check mirror $vg $lv1
# convert inactive mirror and start polling
aux prepare_vg 5
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvchange -an $vg/$lv1
lvconvert -m+1 $vg/$lv1 $dev4
lvchange -ay $vg/$lv1
lvconvert $vg/$lv1 # wait
check mirror $vg $lv1 $dev3
check mirror_no_temporaries $vg $lv1
# ---------------------------------------------------------------------
# removal during conversion
# "remove newly added mirror"
aux prepare_vg 5
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvconvert -m+1 -b $vg/$lv1 $dev4
lvconvert -m-1 $vg/$lv1 $dev4
lvconvert $vg/$lv1 # wait
check mirror $vg $lv1 $dev3
check mirror_no_temporaries $vg $lv1
check mirror_legs $vg $lv1 2
# "remove one of newly added mirrors"
aux prepare_vg 5
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvconvert -m+2 -b $vg/$lv1 $dev4 $dev5
lvconvert -m-1 $vg/$lv1 $dev4
lvconvert $vg/$lv1 # wait
check mirror $vg $lv1 $dev3
check mirror_no_temporaries $vg $lv1
check mirror_legs $vg $lv1 3
# "remove from original mirror (the original is still mirror)"
aux prepare_vg 5
lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev5 $dev3:0
lvconvert -m+1 -b $vg/$lv1 $dev4
lvconvert -m-1 $vg/$lv1 $dev2
lvconvert $vg/$lv1
check mirror $vg $lv1 $dev3
check mirror_no_temporaries $vg $lv1
check mirror_legs $vg $lv1 3
# "remove from original mirror (the original becomes linear)"
aux prepare_vg 5
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvconvert -m+1 -b $vg/$lv1 $dev4
lvconvert -m-1 $vg/$lv1 $dev2
lvconvert $vg/$lv1
check mirror $vg $lv1 $dev3
check mirror_no_temporaries $vg $lv1
check mirror_legs $vg $lv1 2
# ---------------------------------------------------------------------
# "rhbz440405: lvconvert -m0 incorrectly fails if all PEs allocated"
aux prepare_vg 5
lvcreate -l`pvs --noheadings -ope_count $dev1` -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
while [ `lvs --noheadings -o copy_percent $vg/$lv1` != "100.00" ]; do sleep 1; done
lvconvert -m0 $vg/$lv1 $dev1
check linear $vg $lv1
# "rhbz264241: lvm mirror doesn't lose it's "M" --nosync attribute after being down and the up converted"
aux prepare_vg 5
lvcreate -l2 -m1 -n$lv1 --nosync $vg
lvconvert -m0 $vg/$lv1
lvconvert -m1 $vg/$lv1
lvs --noheadings -o attr $vg/$lv1 | grep '^ *m'
# lvconvert from linear (on multiple PVs) to mirror
aux prepare_vg 5
lvcreate -l 8 -n $lv1 $vg $dev1:0-3 $dev2:0-3
lvconvert -m1 $vg/$lv1
should check mirror $vg $lv1
check mirror_legs $vg $lv1 2
# BZ 463272: disk log mirror convert option is lost if downconvert option is also given
aux prepare_vg 5
lvcreate -l1 -m2 --corelog -n $lv1 $vg $dev1 $dev2 $dev3
lvconvert -m1 --mirrorlog disk $vg/$lv1 $dev1
check mirror $vg $lv1 $dev1
# ---
# add mirror and disk log
# "add 1 mirror and disk log"
aux prepare_vg 5
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
# FIXME on next line, specifying $dev3:0 $dev4 (i.e log device first) fails (!)
lvconvert -m+1 --mirrorlog disk -i1 $vg/$lv1 $dev4 $dev3:0
check mirror $vg $lv1 $dev3
check mirror_no_temporaries $vg $lv1
check mirror_legs $vg $lv1 3

View File

@ -20,13 +20,13 @@ lvremove -ff $vg
# 2-way mirror with disklog, 3 PVs
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
check mirror_images_redundant $vg $lv1
check mirror_log_on $vg/$lv1 $dev3
check mirror_log_on $vg $lv1 $dev3
lvremove -ff $vg
# 3-way mirror with disklog, 4 PVs
lvcreate -l2 -m2 --mirrorlog disk -n $lv1 $vg $dev1 $dev2 $dev4 $dev3:0-1
check mirror_images_redundant $vg $lv1
check mirror_log_on $vg/$lv1 $dev3
check mirror_log_on $vg $lv1 $dev3
lvremove -ff $vg
# lvcreate --nosync is in 100% sync after creation (bz429342)

View File

@ -1,767 +0,0 @@
# Copyright (C) 2008 Red Hat, Inc. All rights reserved.
# 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-utils.sh
mimages_are_redundant_ ()
{
local vg=$1
local lv=$vg/$2
local i
rm -f out
for i in $(lvs -odevices --noheadings $lv | sed 's/([^)]*)//g; s/,/ /g'); do
lvs -a -o+devices $vg/$i
lvs -a -odevices --noheadings $vg/$i | sed 's/([^)]*)//g; s/,/ /g' | \
sort | uniq >> out
done
# if any duplication is found, it's not redundant
sort out | uniq -d | grep . && return 1
return 0
}
lv_is_contiguous_ ()
{
local lv=$1
# if the lv has multiple segments, it's not contiguous
lvs -a --segments $lv
[ $(lvs -a --segments --noheadings $lv | wc -l) -ne 1 ] && return 1
return 0
}
mimages_are_contiguous_ ()
{
local vg=$1
local lv=$vg/$2
local i
for i in $(lvs -odevices --noheadings $lv | sed 's/([^)]*)//g; s/,/ /g'); do
lv_is_contiguous_ $vg/$i || return 1
done
return 0
}
mirrorlog_is_on_()
{
local lv="$1"_mlog
shift 1
if ! lvs -a $lv; then return 0; fi # FIXME?
lvs -a -o+devices $lv
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 -v "$d(" out > out2 || true; mv out2 out; done
grep . out && return 1
return 0
}
save_dev_sum_()
{
mkfs.ext3 $1 > /dev/null &&
md5sum $1 > md5.$(basename $1)
}
check_dev_sum_()
{
md5sum $1 > md5.tmp && cmp md5.$(basename $1) md5.tmp
}
check_mirror_count_()
{
local lv=$1
local mirrors=$2
[ "$mirrors" -eq "$(lvs --noheadings -ostripes $lv)" ]
}
check_mirror_log_()
{
local lv=$1
local mlog=$(lvs --noheadings -omirror_log $lv | sed -e 's/ //g')
[ "$(basename $lv)_mlog" == "$mlog" ]
}
wait_conversion_()
{
local lv=$1
while (lvs --noheadings -oattr "$lv" | grep -q '^ *c'); do sleep 1; done
}
wait_sync_()
{
local lv=$1
while [ `lvs --noheadings -o copy_percent $lv` != "100.00" ]; do sleep 1; done
}
check_no_tmplvs_()
{
local lv=$1
lvs -a -oname $(dirname $lv)
lvs -a --noheadings -oname $(dirname $lv) > out
! grep tmp out
}
aux prepare_vg 5 200
# ---------------------------------------------------------------------
# Common environment setup/cleanup for each sub testcases
prepare_lvs_()
{
lvremove -ff $vg
if dmsetup table|grep $vg; then
echo "ERROR: lvremove did leave some some mappings in DM behind!"
return 1
fi
:
}
check_and_cleanup_lvs_()
{
lvs -a -o+devices $vg
lvremove -ff $vg
if dmsetup table|grep $vg; then
echo "ERROR: lvremove did leave some some mappings in DM behind!"
return 1
fi
}
not_sh ()
{
"$@" && exit 1 || :;
}
# ---------------------------------------------------------------------
# Main repeating test function
log_name_to_count()
{
if [ $1 == "mirrored" ]; then
echo 2
elif [ $1 == "disk" ]; then
echo 1
else
echo 0
fi
}
#
# FIXME: For test_[up|down]convert, I'd still like to be able
# to specifiy devices - especially if I can do partial PV
# specification for down-converts. It may even be wise to
# do one round through these tests without specifying the PVs
# to use and one round where we do.
#
#
# test_upconvert
# start_mirror_count: The '-m' argument to create with
# start_log_type: core|disk|mirrored
# final_mirror_count: The '-m' argument to convert to
# final_log_type: core|disk|mirrored
# active: Whether the LV should be active when the convert happens
#
# Exmaple: Convert 2-way disk-log mirror to
# 3-way disk-log mirror while not active
# -> test_upconvert 1 disk 2 disk 0
test_upconvert()
{
local start_count=$1
local start_count_p1=$(($start_count + 1))
local start_log_type=$2
local finish_count=$3
local finish_count_p1=$(($finish_count + 1))
local finish_log_type=$4
local dev_array=($dev1 $dev2 $dev3 $dev4 $dev5)
local create_devs=""
local convert_devs=""
local log_devs=""
local start_log_count
local finish_log_count
local max_log_count
local alloc=""
local active=true
local i
if [ $start_log_type == "disk" ] &&
[ $finish_log_type == "mirrored" ]; then
echo "FIXME: disk -> mirrored log conversion not yet supported by LVM"
return 0
fi
if [ $5 -eq 0 ]; then
active=false
fi
# Do we have enough devices for the mirror images?
if [ $finish_count_p1 -gt ${#dev_array[@]} ]; then
echo "Action requires too many devices"
return 1
fi
start_log_count=`log_name_to_count $start_log_type`
finish_log_count=`log_name_to_count $finish_log_type`
if [ $finish_log_count -gt $start_log_count ]; then
max_log_count=$finish_log_count
else
max_log_count=$start_log_count
fi
# First group of devs for create
# for i in $(seq 0 $start_count); do
# create_devs="$create_devs ${dev_array[$i]}"
# done
# Second group of devs for convert
# for i in $(seq $start_count_p1 $finish_count); do
# convert_devs="$convert_devs ${dev_array[$i]}"
# done
# Third (or overlapping) group of devs for log
# for i in $(seq $((${#dev_array[@]} - $max_log_count)) $((${#dev_array[@]} - 1))); do
# if [ $i -gt $finish_count ]; then
# log_devs="$log_devs ${dev_array[$i]}:0"
# else
# log_devs="$log_devs ${dev_array[$i]}"
# fi
# done
prepare_lvs_
if [ $start_count -gt 0 ]; then
# Are there extra devices for the log or do we overlap
if [ $(($start_count_p1 + $start_log_count)) -gt ${#dev_array[@]} ]; then
alloc="--alloc anywhere"
fi
lvcreate -l2 -m $start_count --mirrorlog $start_log_type \
-n $lv1 $vg $alloc $create_devs $log_devs || return 1
check_mirror_count_ $vg/$lv1 $start_count_p1
# FIXME: check mirror log
else
lvcreate -l15 -n $lv1 $vg $create_devs || return 1
fi
lvs -a -o name,copy_percent,devices $vg
if ! $active; then
lvchange -an $vg/$lv1 || return 1
fi
# Are there extra devices for the log or do we overlap
if [ $(($finish_count_p1 + $finish_log_count)) -gt ${#dev_array[@]} ]; then
alloc="--alloc anywhere"
fi
echo y | lvconvert -m $finish_count --mirrorlog $finish_log_type \
$vg/$lv1 $alloc $convert_devs $log_devs || return 1
if ! $active; then
lvchange -ay $vg/$lv1 || return 1
fi
wait_conversion_ $vg/$lv1
lvs -a -o name,copy_percent,devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 $finish_count_p1
mimages_are_redundant_ $vg $lv1
check_and_cleanup_lvs_
}
#
# test_downconvert
# start_mirror_count: The '-m' argument to create with
# start_log_type: core|disk|mirrored
# final_mirror_count: The '-m' argument to convert to
# final_log_type: core|disk|mirrored
# active: Whether the LV should be active when the convert happens
#
# Exmaple: Convert 3-way disk-log mirror to
# 2-way disk-log mirror while not active
# -> test_downconvert 2 disk 3 disk 0
test_downconvert()
{
local start_count=$1
local start_count_p1=$(($start_count + 1))
local start_log_type=$2
local finish_count=$3
local finish_count_p1=$(($finish_count + 1))
local finish_log_type=$4
local dev_array=($dev1 $dev2 $dev3 $dev4 $dev5)
local create_devs=""
local convert_devs=""
local log_devs=""
local start_log_count
local finish_log_count
local max_log_count
local alloc=""
local active=true
local i
if [ $start_log_type == "disk" ] &&
[ $finish_log_type == "mirrored" ]; then
echo "FIXME: disk -> mirrored log conversion not yet supported by LVM"
return 0
fi
if [ $5 -eq 0 ]; then
active=false
fi
# Do we have enough devices for the mirror images?
if [ $start_count_p1 -gt ${#dev_array[@]} ]; then
echo "Action requires too many devices"
return 1
fi
start_log_count=`log_name_to_count $start_log_type`
finish_log_count=`log_name_to_count $finish_log_type`
if [ $finish_log_count -gt $start_log_count ]; then
max_log_count=$finish_log_count
else
max_log_count=$start_log_count
fi
# First group of devs for create
# for i in $(seq 0 $start_count); do
# create_devs="$create_devs ${dev_array[$i]}"
# done
# Same devices for convert (because we are down-converting)
# for i in $(seq 0 $start_count); do
# convert_devs="$convert_devs ${dev_array[$i]}"
# done
# Third (or overlapping) group of devs for log creation
# for i in $(seq $((${#dev_array[@]} - $max_log_count)) $((${#dev_array[@]} - 1))); do
# if [ $i -gt $start_count ]; then
# log_devs="$log_devs ${dev_array[$i]}:0"
# else
# log_devs="$log_devs ${dev_array[$i]}"
# fi
# done
prepare_lvs_
if [ $start_count -gt 0 ]; then
# Are there extra devices for the log or do we overlap
if [ $(($start_count_p1 + $start_log_count)) -gt ${#dev_array[@]} ]; then
alloc="--alloc anywhere"
fi
lvcreate -l2 -m $start_count --mirrorlog $start_log_type \
-n $lv1 $vg $alloc $create_devs $log_devs || return 1
check_mirror_count_ $vg/$lv1 $start_count_p1
# FIXME: check mirror log
else
lvcreate -l15 -n $lv1 $vg $create_devs || return 1
fi
lvs -a -o name,copy_percent,devices $vg
if ! $active; then
lvchange -an $vg/$lv1 || return 1
fi
# Are there extra devices for the log or do we overlap
if [ $(($finish_count_p1 + $finish_log_count)) -gt ${#dev_array[@]} ]; then
alloc="--alloc anywhere"
fi
echo y | lvconvert -m $finish_count --mirrorlog $finish_log_type \
$vg/$lv1 $alloc $convert_devs $log_devs || return 1
if ! $active; then
lvchange -ay $vg/$lv1 || return 1
fi
wait_conversion_ $vg/$lv1
lvs -a -o name,copy_percent,devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 $finish_count_p1
mimages_are_redundant_ $vg $lv1
check_and_cleanup_lvs_
}
# test_convert
# start_image_count
# start_log_type
# finish_image_count
# finish_log_type
test_convert()
{
if [ $1 -lt $3 ]; then
test_upconvert $1 $2 $3 $4 0 || return 1
test_upconvert $1 $2 $3 $4 1 || return 1
else
test_downconvert $1 $2 $3 $4 0 || return 1
test_downconvert $1 $2 $3 $4 1 || return 1
fi
}
prepare_lvs_
check_and_cleanup_lvs_
# ---------------------------------------------------------------------
# mirrored LV tests
# ---
# Test conversion combinations from linear <-> 4-way mirrors
for i in $(seq 0 4); do
for j in $(seq 0 4); do
for k in core disk mirrored; do
for l in core disk mirrored; do
#############################################
echo "Testing mirror conversion -m$i/$k -> -m$j/$l"
test_convert $i $k $j $l
#############################################
done
done
done
done
# ---
# add mirror to mirror
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l15 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
check_mirror_log_ $vg/$lv1
lvconvert -m+1 -i 20 -b $vg/$lv1 $dev4
# Next convert should fail b/c we can't have 2 at once
not lvconvert -m+1 -b $vg/$lv1 $dev5
wait_conversion_ $vg/$lv1
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 3
mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_
# add 1 mirror
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l15 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
check_mirror_log_ $vg/$lv1
lvconvert -m+1 -i 20 -b $vg/$lv1 $dev4
# Next convert should fail b/c we can't have 2 at once
not lvconvert -m+1 -b $vg/$lv1 $dev5
wait_conversion_ $vg/$lv1
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 3
mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_
# remove 1 mirror from corelog'ed mirror
# should retain 'core' log type
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m2 --corelog -n $lv1 $vg
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 3
not_sh check_mirror_log_ $vg/$lv1
lvconvert -m -1 -i1 $vg/$lv1
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 2
mimages_are_redundant_ $vg $lv1
not_sh check_mirror_log_ $vg/$lv1
check_and_cleanup_lvs_
# add 2 mirrors
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
check_mirror_log_ $vg/$lv1
lvconvert -m+2 -i1 $vg/$lv1 $dev4 $dev5
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 4
mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_
# add 1 mirror to core log mirror,
# explicitly keep log as 'core'
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
not_sh check_mirror_log_ $vg/$lv1
lvconvert -m+1 -i1 --mirrorlog core $vg/$lv1 $dev4
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 3
not_sh check_mirror_log_ $vg/$lv1
mimages_are_redundant_ $vg $lv1
check_and_cleanup_lvs_
# add 1 mirror to core log mirror, but
# implicitly keep log as 'core'
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
not_sh check_mirror_log_ $vg/$lv1
lvconvert -m +1 -i1 $vg/$lv1
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 3
not_sh check_mirror_log_ $vg/$lv1
mimages_are_redundant_ $vg $lv1
check_and_cleanup_lvs_
# add 2 mirrors to core log mirror"
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
not_sh check_mirror_log_ $vg/$lv1
lvconvert -m+2 -i1 --mirrorlog core $vg/$lv1 $dev4 $dev5
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 4
not_sh check_mirror_log_ $vg/$lv1
mimages_are_redundant_ $vg $lv1
check_and_cleanup_lvs_
# ---
# add to converting mirror
# add 1 mirror then add 1 more mirror during conversion
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
check_mirror_log_ $vg/$lv1
lvconvert -m+1 -b $vg/$lv1 $dev4
lvs -a -o+devices $vg
lvconvert -m+1 -i3 $vg/$lv1 $dev5
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 4
mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_
# ---
# core log to mirrored log
# change the log type from 'core' to 'mirrored'
prepare_lvs_
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
check_mirror_count_ $vg/$lv1 2
not_sh check_mirror_log_ $vg/$lv1
lvconvert --mirrorlog mirrored -i1 $vg/$lv1 $dev3 $dev4
check_no_tmplvs_ $vg/$lv1
check_mirror_log_ $vg/$lv1
mimages_are_redundant_ $vg $lv1
# ---
# mirrored log to core log
# change the log type from 'mirrored' to 'core'
lvconvert --mirrorlog core -i1 $vg/$lv1 $dev3 $dev4
check_no_tmplvs_ $vg/$lv1
not_sh check_mirror_log_ $vg/$lv1
mimages_are_redundant_ $vg $lv1
check_and_cleanup_lvs_
# ---
# Linear to mirror with mirrored log using --alloc anywhere
prepare_lvs_
lvcreate -l2 -n $lv1 $vg $dev1
lvconvert -m +1 --mirrorlog mirrored $vg/$lv1 $dev1 $dev2 --alloc anywhere
# FIXME Disable next check: --alloc anywhere makes *no* guarantees about placement - that's the entire point of it!
#mimages_are_redundant_ $vg $lv1
check_and_cleanup_lvs_
# ---
# check polldaemon restarts
# convert inactive mirror and start polling
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
lvchange -an $vg/$lv1
lvconvert -m+1 $vg/$lv1 $dev4
lvs -a -o+devices $vg
lvchange -ay $vg/$lv1
wait_conversion_ $vg/$lv1
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_and_cleanup_lvs_
# ---------------------------------------------------------------------
# removal during conversion
# "remove newly added mirror"
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
check_mirror_log_ $vg/$lv1
lvconvert -m+1 -b $vg/$lv1 $dev4
lvs -a -o+devices $vg
lvconvert -m-1 $vg/$lv1 $dev4
lvs -a -o+devices $vg
wait_conversion_ $vg/$lv1
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 2
mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_
# "remove one of newly added mirrors"
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
check_mirror_log_ $vg/$lv1
lvconvert -m+2 -b $vg/$lv1 $dev4 $dev5
lvs -a -o+devices $vg
lvconvert -m-1 $vg/$lv1 $dev4
lvs -a -o+devices $vg
lvconvert -i1 $vg/$lv1
lvs -a -o+devices $vg
wait_conversion_ $vg/$lv1
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 3
mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_
# "remove from original mirror (the original is still mirror)"
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev5 $dev3:0
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 3
check_mirror_log_ $vg/$lv1
lvconvert -m+1 -b $vg/$lv1 $dev4
lvs -a -o+devices $vg
lvconvert -m-1 $vg/$lv1 $dev2
lvs -a -o+devices $vg
lvconvert -i1 $vg/$lv1
lvs -a -o+devices $vg
wait_conversion_ $vg/$lv1
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 3
mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_
# "remove from original mirror (the original becomes linear)"
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
check_mirror_log_ $vg/$lv1
lvconvert -m+1 -b $vg/$lv1 $dev4
lvs -a -o+devices $vg
lvconvert -m-1 $vg/$lv1 $dev2
lvs -a -o+devices $vg
lvconvert -i1 $vg/$lv1
lvs -a -o+devices $vg
wait_conversion_ $vg/$lv1
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 2
mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_
# ---------------------------------------------------------------------
# "rhbz440405: lvconvert -m0 incorrectly fails if all PEs allocated"
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l`pvs --noheadings -ope_count $dev1` -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
check_mirror_log_ $vg/$lv1
wait_sync_ $vg/$lv1 # cannot pull primary unless mirror in-sync
lvconvert -m0 $vg/$lv1 $dev1
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 1
check_and_cleanup_lvs_
# "rhbz264241: lvm mirror doesn't lose it's "M" --nosync attribute after being down and the up converted"
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 -n$lv1 --nosync $vg
lvs -a -o+devices $vg
lvconvert -m0 $vg/$lv1
lvs -a -o+devices $vg
lvconvert -m1 $vg/$lv1
lvs -a -o+devices $vg
lvs --noheadings -o attr $vg/$lv1 | grep '^ *m'
check_and_cleanup_lvs_
# lvconvert from linear (on multiple PVs) to mirror
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l 8 -n $lv1 $vg $dev1:0-3 $dev2:0-3
lvs -a -o+devices $vg
lvconvert -m1 $vg/$lv1
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
check_mirror_log_ $vg/$lv1
check_and_cleanup_lvs_
# BZ 463272: disk log mirror convert option is lost if downconvert option is also given
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l1 -m2 --corelog -n $lv1 $vg
lvs -a -o+devices $vg
lvconvert -m1 --mirrorlog disk $vg/$lv1
lvs -a -o+devices $vg
check_mirror_log_ $vg/$lv1
# ---
# add mirror and disk log
# "add 1 mirror and disk log"
prepare_lvs_
lvs -a -o+devices $vg
lvcreate -l2 -m1 --mirrorlog core -n $lv1 $vg $dev1 $dev2
lvs -a -o+devices $vg
check_mirror_count_ $vg/$lv1 2
not_sh check_mirror_log_ $vg/$lv1
# FIXME on next line, specifying $dev3:0 $dev4 (i.e log device first) fails (!)
lvconvert -m+1 --mirrorlog disk -i1 $vg/$lv1 $dev4 $dev3:0
lvs -a -o+devices $vg
check_no_tmplvs_ $vg/$lv1
check_mirror_count_ $vg/$lv1 3
check_mirror_log_ $vg/$lv1
mimages_are_redundant_ $vg $lv1
mirrorlog_is_on_ $vg/$lv1 $dev3
check_and_cleanup_lvs_

View File

@ -17,6 +17,8 @@ aux prepare_devs 3
pvcreate $dev1 $dev2
pvcreate --metadatacopies 0 $dev3
vg=${PREFIX}vg
#COMM 'vgcreate accepts 8.00m physicalextentsize for VG'
vgcreate -c n $vg --physicalextentsize 8.00m $dev1 $dev2
check_vg_field_ $vg vg_extent_size 8.00m

View File

@ -94,7 +94,7 @@ prepare_testroot() {
trap_teardown
TESTDIR=$($abs_srcdir/mkdtemp ${LVM_TEST_DIR-$(pwd)} $PREFIX.XXXXXXXXXX) \
|| { echo "failed to create temporary directory in $test_dir_"; exit 1; }
|| { echo "failed to create temporary directory in ${LVM_TEST_DIR-$(pwd)}"; exit 1; }
export LVM_SYSTEM_DIR=$TESTDIR/etc
export DM_DEV_DIR=$TESTDIR/dev
@ -131,6 +131,7 @@ teardown_devs() {
test -n "$LOOPFILE" && rm -f $LOOPFILE
fi
unset devs # devs is set in prepare_devs()
unset LOOP
}
teardown() {
@ -178,7 +179,7 @@ prepare_loop() {
trap_teardown
for i in 0 1 2 3 4 5 6 7; do
mknod $DM_DEV_DIR/loop$i b 7 $i
test -e $DM_DEV_DIR/loop$i || mknod $DM_DEV_DIR/loop$i b 7 $i
done
LOOPFILE="$PWD/test.img"
@ -291,16 +292,6 @@ prepare_devs() {
local name="${PREFIX}$pvname$i"
dmsetup table $name
done
# set up some default names
vg=${PREFIX}vg
vg1=${PREFIX}vg1
vg2=${PREFIX}vg2
lv=LV
lv1=LV1
lv2=LV2
lv3=LV3
lv4=LV4
}
disable_dev() {
@ -346,10 +337,13 @@ restore_dev() {
prepare_pvs() {
prepare_devs "$@"
pvcreate $devs
pvcreate -ff $devs
}
prepare_vg() {
vgremove -ff $vg || true
teardown_devs
prepare_pvs "$@"
vgcreate -c n $vg $devs
pvs -v
@ -400,6 +394,16 @@ prepare() {
prepare_testroot
prepare_lvmconf
prepare_clvmd
# set up some default names
vg=${PREFIX}vg
vg1=${PREFIX}vg1
vg2=${PREFIX}vg2
lv=LV
lv1=LV1
lv2=LV2
lv3=LV3
lv4=LV4
}
LANG=C