2 # Copyright (C) 2008 Red Hat, Inc. All rights reserved.
3 # Copyright (C) 2007 NEC Corporation
5 # This copyrighted material is made available to anyone wishing to use,
6 # modify, copy, or redistribute it subject to the terms and conditions
7 # of the GNU General Public License v.2.
9 # You should have received a copy of the GNU General Public License
10 # along with this program; if not, write to the Free Software Foundation,
11 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
13 test_description
="ensure that basic operations on mirrored LV works"
17 dmsetup_has_dm_devdir_support_ ||
exit 200
19 # ---------------------------------------------------------------------
27 mimages_are_redundant_
()
34 for i
in $
(lvs
-odevices --noheadings $lv |
sed 's/([^)]*)//g; s/,/ /g'); do
35 lvs
-a -odevices --noheadings $vg/$i |
sed 's/([^)]*)//g; s/,/ /g' | \
39 # if any duplication is found, it's not redundant
40 sort out |
uniq -d |
grep .
&& return 1
49 # if the lv has multiple segments, it's not contiguous
50 [ $
(lvs
-a --segments --noheadings $lv |
wc -l) -ne 1 ] && return 1
59 # if any duplication is found, it's not redundant
60 [ $
(lvs
-a -odevices --noheadings $lv |
sed 's/([^)]*)//g' | \
61 sort |
uniq |
wc -l) -ne 1 ] && return 1
66 mimages_are_contiguous_
()
72 for i
in $
(lvs
-odevices --noheadings $lv |
sed 's/([^)]*)//g; s/,/ /g'); do
73 lv_is_contiguous_
$vg/$i ||
return 1
85 for i
in $
(lvs
-odevices --noheadings $lv |
sed 's/([^)]*)//g; s/,/ /g'); do
86 lv_is_clung_
$vg/$i ||
return 1
96 lvs
-a -odevices --noheadings $lv |
sed 's/,/\n/g' > out
97 for d
in $
*; do grep "$d(" out
; done
98 for d
in $
*; do ! grep -v "$d(" out
; done
104 mkfs.ext3
$1 > /dev
/null
&&
105 md5sum $1 > md5.$
(basename $1)
110 md5sum $1 > md5.tmp
&& cmp md5.$
(basename $1) md5.tmp
113 # ---------------------------------------------------------------------
114 # Initialize PVs and VGs
118 # ---------------------------------------------------------------------
119 # Common environment setup/cleanup for each sub testcases
124 if dmsetup table|
grep $vg; then
125 echo "ERROR: lvremove did leave some some mappings in DM behind!"
131 check_and_cleanup_lvs_
()
133 lvs
-a -o+devices
$vg
135 if dmsetup table|
grep $vg; then
136 echo "ERROR: lvremove did leave some some mappings in DM behind!"
141 #COMM "check environment setup/cleanup"
143 check_and_cleanup_lvs_
145 # ---------------------------------------------------------------------
151 #COMM "create 2-way mirror with disklog from 3 PVs"
153 lvcreate
-l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
154 mimages_are_redundant_
$vg $lv1
155 mirrorlog_is_on_
$vg/$lv1 $dev3
156 check_and_cleanup_lvs_
158 #COMM "create 2-way mirror with corelog from 2 PVs"
160 lvcreate
-l2 -m1 --mirrorlog core
-n $lv1 $vg $dev1 $dev2
161 mimages_are_redundant_
$vg $lv1
162 check_and_cleanup_lvs_
164 #COMM "create 3-way mirror with disklog from 4 PVs"
166 lvcreate
-l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev4 $dev3:0-1
167 mimages_are_redundant_
$vg $lv1
168 mirrorlog_is_on_
$vg/$lv1 $dev3
169 check_and_cleanup_lvs_
171 #COMM "lvcreate --nosync is in 100% sync after creation (bz429342)"
173 lvcreate
-l2 -m1 --nosync -n $lv1 $vg $dev1 $dev2 $dev3:0-1 2>out
174 grep "New mirror won't be synchronised." out
175 lvs
-o copy_percent
--noheadings $vg/$lv1 |
grep 100.00
176 check_and_cleanup_lvs_
181 #COMM "convert from linear to 2-way mirror"
183 lvcreate
-l2 -n $lv1 $vg $dev1
184 lvconvert
-m+1 $vg/$lv1 $dev2 $dev3:0-1
185 mimages_are_redundant_
$vg $lv1
186 mirrorlog_is_on_
$vg/$lv1 $dev3
187 check_and_cleanup_lvs_
189 #COMM "convert from 2-way mirror to linear"
191 lvcreate
-l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
192 lvconvert
-m-1 $vg/$lv1
193 mimages_are_redundant_
$vg $lv1
194 check_and_cleanup_lvs_
196 for status
in active inactive
; do
197 # bz192865 lvconvert log of an inactive mirror lv
198 #COMM "convert from disklog to corelog"
200 lvcreate
-l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
201 test $status = "inactive" && lvchange
-an $vg/$lv1
202 yes | lvconvert
--mirrorlog core
$vg/$lv1
203 mimages_are_redundant_
$vg $lv1
204 check_and_cleanup_lvs_
206 #COMM "convert from corelog to disklog"
208 lvcreate
-l2 -m1 --mirrorlog core
-n $lv1 $vg $dev1 $dev2
209 test $status = "inactive" && lvchange
-an $vg/$lv1
210 lvconvert
--mirrorlog disk
$vg/$lv1 $dev3:0-1
211 mimages_are_redundant_
$vg $lv1
212 mirrorlog_is_on_
$vg/$lv1 $dev3
213 check_and_cleanup_lvs_
219 #COMM "extend 2-way mirror"
221 lvcreate
-l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
222 lvchange
-an $vg/$lv1
223 lvextend
-l+2 $vg/$lv1
224 mimages_are_redundant_
$vg $lv1
225 mimages_are_contiguous_
$vg $lv1
226 check_and_cleanup_lvs_
228 #COMM "reduce 2-way mirror"
230 lvcreate
-l4 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
231 lvchange
-an $vg/$lv1
232 lvreduce
-l-2 $vg/$lv1
233 check_and_cleanup_lvs_
235 #COMM "extend 2-way mirror (cling if not contiguous)"
237 lvcreate
-l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
238 lvcreate
-l1 -n $lv2 $vg $dev1
239 lvcreate
-l1 -n $lv3 $vg $dev2
240 lvchange
-an $vg/$lv1
241 lvextend
-l+2 $vg/$lv1
242 mimages_are_redundant_
$vg $lv1
243 mimages_are_clung_
$vg $lv1
244 check_and_cleanup_lvs_
249 #COMM "create 2-way mirror with disklog from 2 PVs"
251 not lvcreate
-l2 -m1 -n $lv1 $vg $dev1 $dev2
252 # "(cleanup previous test)"
253 check_and_cleanup_lvs_
255 #COMM "convert linear to 2-way mirror with 1 PV"
257 lvcreate
-l2 -n $lv1 $vg $dev1
258 not lvconvert
-m+1 --mirrorlog core
$vg/$lv1 $dev1
259 # "(cleanup previous test)"
260 check_and_cleanup_lvs_
264 # FIXME: using dm-delay to properly check whether the resync really started
266 #COMM "force resync 2-way active mirror"
268 lvcreate
-l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
269 mirrorlog_is_on_
$vg/$lv1 $dev3
270 yes | lvchange
--resync $vg/$lv1
271 mirrorlog_is_on_
$vg/$lv1 $dev3
272 check_and_cleanup_lvs_
274 #COMM "force resync 2-way inactive mirror"
276 lvcreate
-l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
277 lvchange
-an $vg/$lv1
278 mirrorlog_is_on_
$vg/$lv1 $dev3
279 lvchange
--resync $vg/$lv1
280 mirrorlog_is_on_
$vg/$lv1 $dev3
281 check_and_cleanup_lvs_
283 # ---------------------------------------------------------------------