Sync usage with man page.
[netbsd-mini2440.git] / external / gpl2 / lvm2 / dist / test / t-mirror-vgreduce-removemissing.sh
blobefd6b5dbb2b0629987b03993392230595c2186d0
1 # Copyright (C) 2008 Red Hat, Inc. All rights reserved.
2 # Copyright (C) 2007 NEC Corporation
4 # This copyrighted material is made available to anyone wishing to use,
5 # modify, copy, or redistribute it subject to the terms and conditions
6 # of the GNU General Public License v.2.
8 # You should have received a copy of the GNU General Public License
9 # along with this program; if not, write to the Free Software Foundation,
10 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12 test_description="ensure that 'vgreduce --removemissing' works on mirrored LV"
14 . ./test-utils.sh
16 dmsetup_has_dm_devdir_support_ || exit 200
18 lv_is_on_ ()
20 local lv=$vg/$1
21 shift
22 local pvs=$*
24 echo "Check if $lv is exactly on PVs $pvs"
25 rm -f out1 out2
26 echo $pvs | sed 's/ /\n/g' | sort | uniq > out1
28 lvs -a -odevices --noheadings $lv | \
29 sed 's/([^)]*)//g; s/[ ,]/\n/g' | sort | uniq > out2
31 diff --ignore-blank-lines out1 out2
34 mimages_are_on_ ()
36 local lv=$1
37 shift
38 local pvs="$*"
39 local mimages
40 local i
42 echo "Check if mirror images of $lv are on PVs $pvs"
43 rm -f out1 out2
44 echo $pvs | sed 's/ /\n/g' | sort | uniq > out1
46 mimages=$(lvs --noheadings -a -o lv_name $vg | grep "${lv}_mimage_" | \
47 sed 's/\[//g; s/\]//g')
48 for i in $mimages; do
49 echo "Checking $vg/$i"
50 lvs -a -odevices --noheadings $vg/$i | \
51 sed 's/([^)]*)//g; s/ //g; s/,/ /g' | sort | uniq >> out2
52 done
54 diff --ignore-blank-lines out1 out2
57 mirrorlog_is_on_()
59 local lv="$1"_mlog
60 shift
61 lv_is_on_ $lv $*
64 lv_is_linear_()
66 echo "Check if $1 is linear LV (i.e. not a mirror)"
67 lvs -o stripes,attr --noheadings $vg/$1 | sed 's/ //g'
68 lvs -o stripes,attr --noheadings $vg/$1 | sed 's/ //g' | grep -q '^1-'
71 rest_pvs_()
73 local index=$1
74 local num=$2
75 local rem=""
76 local n
78 for n in $(seq 1 $(($index - 1))) $(seq $(($index + 1)) $num); do
79 eval local dev=$\dev$n
80 rem="$rem $dev"
81 done
83 echo "$rem"
86 # ---------------------------------------------------------------------
87 # Initialize PVs and VGs
89 prepare_vg 5
91 # ---------------------------------------------------------------------
92 # Common environment setup/cleanup for each sub testcases
94 prepare_lvs_()
96 lvremove -ff $vg;
97 if dmsetup table|grep $vg; then
98 echo "ERROR: lvremove did leave some some mappings in DM behind!"
99 return 1
104 check_and_cleanup_lvs_()
106 lvs -a -o+devices $vg
107 lvremove -ff $vg
108 if dmsetup table|grep $vg; then
109 echo "ERROR: lvremove did leave some some mappings in DM behind!"
110 return 1
114 recover_vg_()
116 enable_dev $*
117 pvcreate -ff $*
118 vgextend $vg $*
119 check_and_cleanup_lvs_
122 #COMM "check environment setup/cleanup"
123 prepare_lvs_
124 check_and_cleanup_lvs_
126 # ---------------------------------------------------------------------
127 # one of mirror images has failed
129 #COMM "basic: fail the 2nd mirror image of 2-way mirrored LV"
130 prepare_lvs_
131 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev3:0-1
132 lvchange -an $vg/$lv1
133 aux mimages_are_on_ $lv1 $dev1 $dev2
134 mirrorlog_is_on_ $lv1 $dev3
135 disable_dev $dev2
136 vgreduce --removemissing --force $vg
137 lv_is_linear_ $lv1
138 lv_is_on_ $lv1 $dev1
140 # "cleanup"
141 recover_vg_ $dev2
143 # ---------------------------------------------------------------------
144 # LV has 3 images in flat,
145 # 1 out of 3 images fails
147 #COMM test_3way_mirror_fail_1_ <PV# to fail>
148 test_3way_mirror_fail_1_()
150 local index=$1
152 lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev4:0-1
153 lvchange -an $vg/$lv1
154 aux mimages_are_on_ $lv1 $dev1 $dev2 $dev3
155 mirrorlog_is_on_ $lv1 $dev4
156 eval disable_dev \$dev$index
157 vgreduce --removemissing --force $vg
158 lvs -a -o+devices $vg
159 mimages_are_on_ $lv1 $(rest_pvs_ $index 3)
160 mirrorlog_is_on_ $lv1 $dev4
163 for n in $(seq 1 3); do
164 #COMM fail mirror image $(($n - 1)) of 3-way mirrored LV"
165 prepare_lvs_
166 test_3way_mirror_fail_1_ $n
167 eval recover_vg_ \$dev$n
168 done
170 # ---------------------------------------------------------------------
171 # LV has 3 images in flat,
172 # 2 out of 3 images fail
174 #COMM test_3way_mirror_fail_2_ <PV# NOT to fail>
175 test_3way_mirror_fail_2_()
177 local index=$1
179 lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev4:0-1
180 lvchange -an $vg/$lv1
181 mimages_are_on_ $lv1 $dev1 $dev2 $dev3
182 mirrorlog_is_on_ $lv1 $dev4
183 rest_pvs_ $index 3
184 disable_dev $(rest_pvs_ $index 3)
185 vgreduce --force --removemissing $vg
186 lvs -a -o+devices $vg
187 aux lv_is_linear_ $lv1
188 eval lv_is_on_ $lv1 \$dev$n
191 for n in $(seq 1 3); do
192 #COMM fail mirror images other than mirror image $(($n - 1)) of 3-way mirrored LV
193 prepare_lvs_
194 test_3way_mirror_fail_2_ $n
195 recover_vg_ $(rest_pvs_ $n 3)
196 done
198 # ---------------------------------------------------------------------
199 # LV has 4 images, 1 of them is in the temporary mirror for syncing.
200 # 1 out of 4 images fails
202 #COMM test_3way_mirror_plus_1_fail_1_ <PV# to fail>
203 test_3way_mirror_plus_1_fail_1_()
205 local index=$1
207 lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev5:0-1
208 lvchange -an $vg/$lv1
209 lvconvert -m+1 $vg/$lv1 $dev4
210 mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
211 mirrorlog_is_on_ $lv1 $dev5
212 eval disable_dev \$dev$n
213 vgreduce --removemissing --force $vg
214 lvs -a -o+devices $vg
215 mimages_are_on_ $lv1 $(rest_pvs_ $index 4)
216 mirrorlog_is_on_ $lv1 $dev5
219 for n in $(seq 1 4); do
220 #COMM "fail mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV"
221 prepare_lvs_
222 test_3way_mirror_plus_1_fail_1_ $n
223 eval recover_vg_ \$dev$n
224 done
226 # ---------------------------------------------------------------------
227 # LV has 4 images, 1 of them is in the temporary mirror for syncing.
228 # 3 out of 4 images fail
230 #COMM test_3way_mirror_plus_1_fail_3_ <PV# NOT to fail>
231 test_3way_mirror_plus_1_fail_3_()
233 local index=$1
235 lvcreate -l2 -m2 -n $lv1 $vg $dev1 $dev2 $dev3 $dev5:0-1
236 lvchange -an $vg/$lv1
237 lvconvert -m+1 $vg/$lv1 $dev4
238 mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
239 mirrorlog_is_on_ $lv1 $dev5
240 disable_dev $(rest_pvs_ $index 4)
241 vgreduce --removemissing --force $vg
242 lvs -a -o+devices $vg
243 eval local dev=\$dev$n
244 mimages_are_on_ $lv1 $dev || lv_is_on_ $lv1 $dev
245 not mirrorlog_is_on_ $lv1 $dev5
248 for n in $(seq 1 4); do
249 #COMM "fail mirror images other than mirror image $(($n - 1)) of 4-way (1 converting) mirrored LV"
250 prepare_lvs_
251 test_3way_mirror_plus_1_fail_3_ $n
252 recover_vg_ $(rest_pvs_ $n 4)
253 done
255 # ---------------------------------------------------------------------
256 # LV has 4 images, 2 of them are in the temporary mirror for syncing.
257 # 1 out of 4 images fail
259 # test_2way_mirror_plus_2_fail_1_ <PV# to fail>
260 test_2way_mirror_plus_2_fail_1_()
262 local index=$1
264 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
265 lvchange -an $vg/$lv1
266 lvconvert -m+2 $vg/$lv1 $dev3 $dev4
267 mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
268 mirrorlog_is_on_ $lv1 $dev5
269 eval disable_dev \$dev$n
270 vgreduce --removemissing --force $vg
271 lvs -a -o+devices $vg
272 mimages_are_on_ $lv1 $(rest_pvs_ $index 4)
273 mirrorlog_is_on_ $lv1 $dev5
276 for n in $(seq 1 4); do
277 #COMM "fail mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV"
278 prepare_lvs_
279 test_2way_mirror_plus_2_fail_1_ $n
280 eval recover_vg_ \$dev$n
281 done
283 # ---------------------------------------------------------------------
284 # LV has 4 images, 2 of them are in the temporary mirror for syncing.
285 # 3 out of 4 images fail
287 # test_2way_mirror_plus_2_fail_3_ <PV# NOT to fail>
288 test_2way_mirror_plus_2_fail_3_()
290 local index=$1
292 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
293 lvchange -an $vg/$lv1
294 lvconvert -m+2 $vg/$lv1 $dev3 $dev4
295 mimages_are_on_ $lv1 $dev1 $dev2 $dev3 $dev4
296 mirrorlog_is_on_ $lv1 $dev5
297 disable_dev $(rest_pvs_ $index 4)
298 vgreduce --removemissing --force $vg
299 lvs -a -o+devices $vg
300 eval local dev=\$dev$n
301 mimages_are_on_ $lv1 $dev || lv_is_on_ $lv1 $dev
302 not mirrorlog_is_on_ $lv1 $dev5
305 for n in $(seq 1 4); do
306 #COMM "fail mirror images other than mirror image $(($n - 1)) of 4-way (2 converting) mirrored LV"
307 prepare_lvs_
308 test_2way_mirror_plus_2_fail_3_ $n
309 recover_vg_ $(rest_pvs_ $n 4)
310 done
312 # ---------------------------------------------------------------------
313 # log device is gone (flat mirror and stacked mirror)
315 #COMM "fail mirror log of 2-way mirrored LV"
316 prepare_lvs_
317 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
318 lvchange -an $vg/$lv1
319 mimages_are_on_ $lv1 $dev1 $dev2
320 mirrorlog_is_on_ $lv1 $dev5
321 disable_dev $dev5
322 vgreduce --removemissing --force $vg
323 mimages_are_on_ $lv1 $dev1 $dev2
324 not mirrorlog_is_on_ $lv1 $dev5
325 recover_vg_ $dev5
327 #COMM "fail mirror log of 3-way (1 converting) mirrored LV"
328 prepare_lvs_
329 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
330 lvchange -an $vg/$lv1
331 lvconvert -m+1 $vg/$lv1 $dev3
332 mimages_are_on_ $lv1 $dev1 $dev2 $dev3
333 mirrorlog_is_on_ $lv1 $dev5
334 disable_dev $dev5
335 vgreduce --removemissing --force $vg
336 mimages_are_on_ $lv1 $dev1 $dev2 $dev3
337 not mirrorlog_is_on_ $lv1 $dev5
338 recover_vg_ $dev5
340 # ---------------------------------------------------------------------
341 # all images are gone (flat mirror and stacked mirror)
343 #COMM "fail all mirror images of 2-way mirrored LV"
344 prepare_lvs_
345 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
346 lvchange -an $vg/$lv1
347 mimages_are_on_ $lv1 $dev1 $dev2
348 mirrorlog_is_on_ $lv1 $dev5
349 disable_dev $dev1 $dev2
350 vgreduce --removemissing --force $vg
351 not lvs $vg/$lv1
352 recover_vg_ $dev1 $dev2
354 #COMM "fail all mirror images of 3-way (1 converting) mirrored LV"
355 prepare_lvs_
356 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
357 lvchange -an $vg/$lv1
358 lvconvert -m+1 $vg/$lv1 $dev3
359 mimages_are_on_ $lv1 $dev1 $dev2 $dev3
360 mirrorlog_is_on_ $lv1 $dev5
361 disable_dev $dev1 $dev2 $dev3
362 vgreduce --removemissing --force $vg
363 not lvs $vg/$lv1
364 recover_vg_ $dev1 $dev2 $dev3
366 # ---------------------------------------------------------------------
367 # Multiple LVs
369 #COMM "fail a mirror image of one of mirrored LV"
370 prepare_lvs_
371 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
372 lvchange -an $vg/$lv1
373 lvcreate -l2 -m1 -n $lv2 $vg $dev3 $dev4 $dev5:1-1
374 lvchange -an $vg/$lv2
375 mimages_are_on_ $lv1 $dev1 $dev2
376 mimages_are_on_ $lv2 $dev3 $dev4
377 mirrorlog_is_on_ $lv1 $dev5
378 mirrorlog_is_on_ $lv2 $dev5
379 disable_dev $dev2
380 vgreduce --removemissing --force $vg
381 mimages_are_on_ $lv2 $dev3 $dev4
382 mirrorlog_is_on_ $lv2 $dev5
383 lv_is_linear_ $lv1
384 lv_is_on_ $lv1 $dev1
385 recover_vg_ $dev2
387 #COMM "fail mirror images, one for each mirrored LV"
388 prepare_lvs_
389 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
390 lvchange -an $vg/$lv1
391 lvcreate -l2 -m1 -n $lv2 $vg $dev3 $dev4 $dev5:1-1
392 lvchange -an $vg/$lv2
393 mimages_are_on_ $lv1 $dev1 $dev2
394 mimages_are_on_ $lv2 $dev3 $dev4
395 mirrorlog_is_on_ $lv1 $dev5
396 mirrorlog_is_on_ $lv2 $dev5
397 disable_dev $dev2
398 disable_dev $dev4
399 vgreduce --removemissing --force $vg
400 lv_is_linear_ $lv1
401 lv_is_on_ $lv1 $dev1
402 lv_is_linear_ $lv2
403 lv_is_on_ $lv2 $dev3
404 recover_vg_ $dev2 $dev4
406 # ---------------------------------------------------------------------
407 # no failure
409 #COMM "no failures"
410 prepare_lvs_
411 lvcreate -l2 -m1 -n $lv1 $vg $dev1 $dev2 $dev5:0-1
412 lvchange -an $vg/$lv1
413 mimages_are_on_ $lv1 $dev1 $dev2
414 mirrorlog_is_on_ $lv1 $dev5
415 vgreduce --removemissing --force $vg
416 mimages_are_on_ $lv1 $dev1 $dev2
417 mirrorlog_is_on_ $lv1 $dev5
418 check_and_cleanup_lvs_
420 # ---------------------------------------------------------------------