2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2012-03-16 17:00:05 +04:00
# Copyright (C) 2010-2012 Red Hat, Inc. All rights reserved.
2010-07-28 16:20:38 +04:00
#
# 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
2010-07-28 16:20:38 +04:00
2018-05-24 17:49:48 +03:00
2016-02-23 01:13:42 +03:00
2014-06-06 19:40:04 +04:00
. lib/inittest
2010-05-12 14:08:35 +04:00
2023-10-02 23:42:36 +03:00
test " ${ LVM_VALGRIND :- 0 } " -eq 0 || skip # too slow test for valgrind
2018-12-23 03:06:16 +03:00
aux lvmconf "global/support_mirrored_mirror_log=1"
2012-03-16 17:00:05 +04:00
log_name_to_count( ) {
case " $1 " in
mirrored) echo 2 ; ;
disk) echo 1 ; ;
*) echo 0 ; ;
esac
2010-05-12 14:08:35 +04:00
}
# 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
2012-03-16 17:00:05 +04:00
test_lvconvert( ) {
2010-05-12 14:08:35 +04:00
local start_count = $1
2017-07-06 20:27:04 +03:00
local start_count_p1 = $(( start_count + 1 ))
2010-05-12 14:08:35 +04:00
local start_log_type = $2
local finish_count = $3
2017-07-06 20:27:04 +03:00
local finish_count_p1 = $(( finish_count + 1 ))
2010-05-12 14:08:35 +04:00
local finish_log_type = $4
local start_log_count
local finish_log_count
local max_log_count
local alloc = ""
2017-07-11 12:16:24 +03:00
local active = "-aey"
2010-05-12 14:08:35 +04:00
local i
2017-07-11 12:16:24 +03:00
test " $5 " = "active" && active = "-an"
2010-05-12 14:08:35 +04:00
#test $finish_count -gt $start_count && up=true
# Do we have enough devices for the mirror images?
2017-07-11 12:16:24 +03:00
test $start_count_p1 -gt ${# DEVICES [@] } && \
2012-03-16 17:00:05 +04:00
die "Action requires too many devices"
2010-05-12 14:08:35 +04:00
# Do we have enough devices for the mirror images?
2017-07-11 12:16:24 +03:00
test $finish_count_p1 -gt ${# DEVICES [@] } && \
2012-03-16 17:00:05 +04:00
die "Action requires too many devices"
2010-05-12 14:08:35 +04:00
2012-03-16 17:00:05 +04:00
start_log_count = $( log_name_to_count $start_log_type )
finish_log_count = $( log_name_to_count $finish_log_type )
2010-05-12 14:08:35 +04:00
if [ $finish_log_count -gt $start_log_count ] ; then
max_log_count = $finish_log_count
else
max_log_count = $start_log_count
fi
if [ $start_count -gt 0 ] ; then
# Are there extra devices for the log or do we overlap
2017-07-11 12:16:24 +03:00
if [ $(( start_count_p1 + start_log_count )) -gt ${# DEVICES [@] } ] ; then
2010-05-12 14:08:35 +04:00
alloc = "--alloc anywhere"
fi
2017-07-11 12:16:24 +03:00
lvcreate " $active " -Zn -l2 --type mirror -m $start_count --mirrorlog $start_log_type \
2014-05-19 15:22:46 +04:00
-n $lv1 $vg $alloc
2010-05-12 14:08:35 +04:00
check mirror_legs $vg $lv1 $start_count_p1
# FIXME: check mirror log
else
2017-07-11 12:16:24 +03:00
lvcreate " $active " -Zn -l2 -n $lv1 $vg
2010-05-12 14:08:35 +04:00
fi
lvs -a -o name,copy_percent,devices $vg
# Are there extra devices for the log or do we overlap
2017-07-11 12:16:24 +03:00
if [ $(( finish_count_p1 + finish_log_count )) -gt ${# DEVICES [@] } ] ; then
2010-05-12 14:08:35 +04:00
alloc = "--alloc anywhere"
fi
2016-08-08 20:43:54 +03:00
# --mirrorlog is invalid with -m0
if [ " $finish_count " -eq 0 ] ; then
mirrorlog = ""
finish_log_type = ""
else
mirrorlog = "--mirrorlog"
fi
lvconvert --type mirror -m $finish_count $mirrorlog $finish_log_type \
2010-05-12 14:08:35 +04:00
$vg /$lv1 $alloc
2017-07-11 12:16:24 +03:00
test " $active " = "-an" || lvchange " $active " $vg /$lv1
2010-05-12 14:08:35 +04:00
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
}
2016-12-12 13:22:41 +03:00
aux prepare_vg 5 5
2017-07-11 12:16:24 +03:00
get_devs
2013-05-31 23:11:51 +04:00
2018-12-18 12:55:35 +03:00
MIRRORED = "mirrored"
# FIXME: Cluster is not supporting exlusive activation of mirrored log
test -e LOCAL_CLVMD && MIRRORED =
2010-05-12 17:15:38 +04:00
test_many( ) {
i = $1
for j in $( seq 0 3) ; do
2018-12-18 12:55:35 +03:00
for k in core disk $MIRRORED ; do
for l in core disk $MIRRORED ; do
2010-05-12 14:08:35 +04:00
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
2011-01-28 19:07:04 +03:00
lvremove -ff $vg
2010-05-12 14:08:35 +04:00
test_lvconvert $i $k $j $l 1
2011-01-28 19:07:04 +03:00
lvremove -ff $vg
2010-05-12 14:08:35 +04:00
done
done
done
2010-05-12 17:15:38 +04:00
}