1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-18 10:04:20 +03:00
lvm2/test/t-mirror-lvconvert.sh
Jonathan Earl Brassow 6753ff894f The following tests in the testsuite have race conditions:
1) Test that the primary mirror image cannot be removed while
   the mirror set is sync'ing.
2) Test that you cannot start a second mirror up-convert while
   one is already in progress.

The trouble is that if the sync/conversion finishes before the
tests occur, the tests will fail by why of success where there
should have been failure.  This means the sync/conversion must
happen very quickly, but this is possible because the test
mirrors we are creating are so small.

In order to decrease the likelyhood of these test failing (or
more correctly, failing to test the right thing), I've increase
the size of the mirrors.  It will still be remotely possible that
the tests will fail (by way of failing to test the right thing).
If this continues to happen, more involved mechanisms will need
to be put in place.  (Perhaps these will still be created, but
this change should be a remedy until that time.)
2010-04-22 15:39:40 +00:00

475 lines
12 KiB
Bash
Executable File

# 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 || :;
}
prepare_lvs_
check_and_cleanup_lvs_
# ---------------------------------------------------------------------
# mirrored LV tests
# ---
# add mirror to mirror
# 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_