]> git.ipfire.org Git - thirdparty/mdadm.git/blob - tests/11spare-migration
Spare migration tests updated
[thirdparty/mdadm.git] / tests / 11spare-migration
1 # Set of tests for autorebuild functionality using mdadm -F
2 # To be able to test ddf one must have all loop devices of bigger size, with the ones
3 # above number 7 bigger again by any amount (this is not changed for now as it
4 # could affect other tests)
5
6 export IMSM_DEVNAME_AS_SERIAL=1
7 export IMSM_TEST_OROM=1
8 export IMSM_NO_PLATFORM=1
9
10 . tests/utils
11 set -ex
12 verbose="yes"
13 sleeptime=10
14
15 # if listfailed=yes then don't exit if test failed due to wrong
16 # spare-migration and just print a list at the end. Other errors still
17 # stop the test.
18 # if listfailed=no then exit on first failure
19 listfailed="yes"
20
21 # start Monitor, set monitorpid
22 # uses global scan variable
23 # all parameters are numbers of devices to be monitored. only used when $scan="no"
24 # eg. monitor 0 1 will start monitoring of containers c0, c1 and subarrays v0, v1
25 monitor(){
26 [ -z $monitorpid ] || return
27 if [ "$scan" == "yes" ]; then
28 $mdadm -F -d 1 --scan --mail root@localhost &
29 monitorpid=$!
30 return
31 fi
32 unset mddevs
33 while [ -n "$1" ]
34 do
35 eval container=\$c$1
36 eval volumes=\$v$1
37 mddevs="$mddevs /dev/$container"
38 if [ "$container" != "$volumes" ]; then
39 for vol in $volumes; do
40 mddevs="$mddevs /dev/$vol"
41 done
42 fi
43 shift
44 done
45 if [ -n "$mddevs" ]; then
46 if [ "$verbose" != "yes" ]; then
47 $mdadm -F -d 1 $mddevs >&2 &
48 monitorpid=$!
49 else
50 $mdadm -F -t -d 1 $mddevs &
51 monitorpid=$!
52 fi
53 fi
54 [ "$verbose" != "yes" ] || echo $mddevs $monitorpid
55 }
56
57 test0()
58 {
59 dsc "Test 0: No config file, no spare should be moved"
60 setupdevs 0 0 1 $platform
61 setupdevs 1 3 4 $platform
62 monitor 0 1
63 mdadm -a /dev/$c1 $dev2
64 mdadm --fail /dev/$v0 $dev0
65 # check that spare loop2 was not moved from container c1 to container c0
66 chksparemoved $c1 $c0 $dev2 n
67 tidyup
68 }
69
70 test0a()
71 {
72 dsc "Test 0a: No domains in config file, no spare should be moved"
73 setupdevs 0 0 1 $platform
74 setupdevs 1 3 4 $platform
75 createconfig a
76 monitor 0 1
77 mdadm -a /dev/$c1 $dev2
78 mdadm --fail /dev/$v0 $dev0
79 # check that spare loop2 was not moved from container c1 to container c0
80 chksparemoved $c1 $c0 $dev2 n
81 tidyup
82 }
83
84 test1()
85 {
86 dsc "Test 1: Common domain, add disk to one container and fail first one in another container, spare should be moved"
87 setupdevs 0 0 1 $platform
88 setupdevs 1 3 4 $platform
89 # create config file with arrays and common domain
90 createconfig a
91 createconfig domain-$platform $platform spare 0 1 2 3 4
92 monitor 0 1
93 mdadm -a /dev/$c1 $dev2
94 mdadm --fail /dev/$v0 $dev0
95 # check that spare loop2 was moved from container c1 to container c0
96 chksparemoved $c1 $c0 $dev2
97 tidyup
98 }
99
100 test1a()
101 {
102 dsc "Test 1a: Common domain, add disk to one container and fail second one in another container, spare should be moved"
103 setupdevs 0 0 1 $platform
104 setupdevs 1 3 4 $platform
105 createconfig a
106 createconfig domain-$platform $platform spare 0 1 2 3 4
107 monitor 0 1
108 mdadm -a /dev/$c1 $dev2
109 mdadm --fail /dev/$v0 $dev1
110 # check that spare loop2 was moved from container c1 to container c0
111 chksparemoved $c1 $c0 $dev2
112 tidyup
113 }
114
115 test2()
116 {
117 dsc "Test 2: Common domain, fail disk in one container and add one to another container, spare should be moved"
118 setupdevs 0 0 1 $platform
119 setupdevs 1 3 4 $platform
120 createconfig a
121 createconfig domain-$platform $platform spare 0 1 2 3 4
122 monitor 0 1
123 mdadm --fail /dev/$v0 $dev1
124 mdadm -a /dev/$c1 $dev2
125 chksparemoved $c1 $c0 $dev2
126 tidyup
127 }
128
129 test3()
130 {
131 dsc "Test 3: Two domains, fail a disk in one domain, add a disk to another domain, the spare should not be moved"
132 setupdevs 0 0 1 $platform
133 setupdevs 1 3 4 $platform
134 # create config file with 2 domains
135 createconfig a
136 createconfig domain-$platform"1" $platform spare 0 1 2
137 createconfig domain-$platform"2" $platform spare 3 4 5
138 monitor 0 1
139 mdadm --fail /dev/$v0 $dev1
140 mdadm -a /dev/$c1 $dev5
141 chksparemoved $c1 $c0 $dev5 n
142 tidyup
143 }
144
145 test4()
146 {
147 dsc "Test 4: One domain holds one container, fail a disk in domain, and add disk to a container not described by domain, move if metadata allows"
148 setupdevs 0 0 1 $platform
149 setupdevs 1 3 4 $platform
150 createconfig a
151 createconfig domain-$platform $platform spare 0 1 2
152 monitor 0 1
153 mdadm --fail /dev/$v0 $dev1
154 mdadm -a /dev/$c1 $dev5
155 unset shouldmove
156 [ "$platform" == "imsm" ] || shouldmove="n"
157 chksparemoved $c1 $c0 $dev5 $shouldmove
158 tidyup
159 }
160
161 test5()
162 {
163 dsc "Test 5: Two domains, two containers in each domain"
164 setupdevs 0 0 1 $platform
165 setupdevs 1 3 4 $platform
166 setupdevs 2 5 6 $platform
167 setupdevs 3 7 8 $platform
168 # 2 and 9 for spares
169 createconfig a
170 createconfig domain-$platform"1" $platform spare 0 1 2 3 4
171 createconfig domain-$platform"2" $platform spare 5 6 7 8 9
172 monitor 0 1 2 3
173 test5a
174 test5b
175 test5c
176 tidyup
177 }
178
179 test5a()
180 {
181 dsc "Test 5a: Two containers in each domain, add spare loop2 to domain1 and fail disk in the other domain, the spare should not be moved"
182 mdadm -a /dev/$c0 $dev2
183 mdadm --fail /dev/$v2 $dev5
184 chksparemoved $c0 $c2 $dev2 n
185 }
186
187 test5b()
188 {
189 dsc "Test 5b: Fail disk in the same domain but different container, spare loop2 should be moved"
190 mdadm --fail /dev/$v1 $dev3
191 chksparemoved $c0 $c1 $dev2
192 }
193
194 test5c()
195 {
196 dsc "Test 5c: Add spare loop9 to different container in domain with degraded array, spare should be moved"
197 mdadm -a /dev/$c3 $dev9
198 chksparemoved $c3 $c2 $dev9
199 }
200
201 test6()
202 {
203 dsc "Test 6: One domain has two containers, fail a disk in one container, there is a spare in other container too small to use for rebuild"
204 setupdevs 0 0 1 $platform
205 setupdevs 1 8 9 $platform
206 # all devices in one domain
207 createconfig a
208 createconfig domain-$platform $platform spare 0 1 2 8 9
209 monitor 0 1
210 mdadm -a /dev/$c0 $dev2
211 mdadm --fail /dev/$v1 $dev8
212 chksparemoved $c0 $c1 $dev2 n
213 tidyup
214 }
215
216 test7()
217 {
218 dsc "Test 7: One domain, add small spare to container, fail disk in array, spare not used, add suitable spare to other container, spare should be moved"
219 setupdevs 0 0 1 $platform
220 setupdevs 1 8 9 $platform
221 createconfig a
222 createconfig domain-$platform $platform spare 0 1 2 8 9 10
223 monitor 0 1
224 mdadm -a /dev/$c1 $dev2
225 mdadm --fail /dev/$v1 $dev8
226 mdadm -a /dev/$c0 $dev10
227 chksparemoved $c0 $c1 $dev10
228 tidyup
229 }
230
231
232 test7a()
233 {
234 dsc "Test 7a: Small spare in parent, suitable one in other container, $dev2 in $c1 is not in common domain"
235 setupdevs 0 0 1 $platform
236 setupdevs 1 8 9 $platform
237 #all $platform devices in one domain
238 createconfig a
239 createconfig domain-$platform"1" $platform spare 0 1 8 9 10
240 createconfig domain-$platform"2" $platform spare 2
241 monitor 0 1
242 mdadm -a /dev/$c1 $dev2
243 chkspare $c1 $dev2
244 mdadm --fail /dev/$v1 $dev8
245 mdadm -a /dev/$c0 $dev10
246 chksparemoved $c0 $c1 $dev10
247 tidyup
248 }
249
250 test8()
251 {
252 # ddf does not have getinfo_super_disks implemented so skip this test
253 return
254 dsc "Test 8: imsm and ddf - spare should not be migrated"
255 setupdevs 0 10 11 imsm
256 setupdevs 1 8 9 ddf
257 createconfig a
258 createconfig domain0 noplatform spare 8 9 10 11 12
259 monitor 0 1
260 mdadm -a /dev/$c1 $dev12
261 mdadm --fail /dev/$v0 $dev10
262 chksparemoved $c1 $c0 $dev12 n
263 tidyup
264 }
265
266 test9()
267 {
268 dsc "Test 9: imsm and native 1.2 - one domain, no metadata specified, spare should be moved"
269 setupdevs 0 10 11 imsm
270 setupdevs 1 8 9 1.2
271 createconfig a
272 createconfig domain0 noplatform spare 8 9 10 11 12
273 monitor 0 1
274 mdadm -a /dev/$c1 $dev12
275 mdadm --fail /dev/$v0 $dev10
276 chksparemoved $c1 $c0 $dev12
277 tidyup
278 }
279
280 test9a()
281 {
282 dsc "Test 9a: imsm and native 1.2 - spare in global domain, should be moved"
283 setupdevs 0 10 11 imsm
284 setupdevs 1 8 9 1.2
285 createconfig a
286 createconfig domain-global noplatform spare 8 9 10 11 12
287 createconfig domain-1.2 1.2 spare 8 9
288 createconfig domain-imsm imsm spare 10 11
289 monitor 0 1
290 mdadm -a /dev/$c1 $dev12
291 mdadm --fail /dev/$v0 $dev10
292 chksparemoved $c1 $c0 $dev12
293 tidyup
294 }
295
296 test10()
297 {
298 dsc "Test 10: Two arrays on the same devices in container"
299 setupdevs 0 0 1 $platform 10000
300 setupdevs 1 3 4 $platform
301 createconfig a
302 createconfig domain-$platform $platform spare 0 1 2 3 4 5
303 monitor 0 1
304 mdadm -a /dev/$c1 $dev2
305 mdadm --fail /dev/md/sub0_ $dev0
306 chksparemoved $c1 $c0 $dev2
307 if [ $failed -eq 0 ]; then
308 # now fail the spare and see if we get another one
309 mdadm --fail /dev/md/sub0_ $dev2
310 mdadm -a /dev/$c1 $dev5
311 chksparemoved $c1 $c0 $dev5
312 fi
313 tidyup
314 }
315
316 test11()
317 {
318 dsc "Test 11: Failed spare from other container should not be used"
319 setupdevs 0 0 1 $platform
320 setupdevs 1 3 4 $platform
321 createconfig a
322 createconfig domain-$platform $platform spare 0 1 2 3 4
323 monitor 0 1
324 mdadm -a /dev/$c1 $dev2
325 mdadm --fail /dev/$v1 $dev3
326 #wait until recovery finishes so no degraded array in c1
327 check wait
328 mdadm --fail /dev/$v0 $dev0
329 chksparemoved $c1 $c0 $dev3 n
330 tidyup
331 }
332
333 test12()
334 {
335 dsc "Test 12: Only one spare should be taken for rebuild, second not needed"
336 setupdevs 0 0 1 $platform
337 setupdevs 1 3 4 $platform
338 createconfig a
339 createconfig domain-$platform $platform spare 0 1 2 3 4 5
340 monitor 0 1
341 mdadm -a /dev/$c1 $dev2
342 mdadm -a /dev/$c1 $dev5
343 mdadm --fail /dev/$v0 $dev0
344 sleep $sleeptime
345 chkarray $dev2 n
346 sc1=$c
347 chkarray $dev5 n
348 sc2=$c
349 [ "$sc1" != "$sc2" ] || err "both spares in the same container $sc1"
350 tidyup
351 }
352
353 test13()
354 {
355 dsc "Test 13: Common domain, two containers, fail a disk in container, action is below spare, the spare should be moved regadless of action"
356 setupdevs 0 0 1 $platform
357 setupdevs 1 4 5 $platform
358 # same domain but different action on 4 5 6
359 createconfig a
360 createconfig domain-$platform $platform spare 0 1
361 createconfig domain-$platform $platform include 4 5 6
362 monitor 0 1
363 mdadm -a /dev/$c1 $dev6
364 mdadm --fail /dev/$v0 $dev0
365 chksparemoved $c1 $c0 $d6
366 tidyup
367 }
368
369 test14()
370 {
371 dsc "Test 14: One domain, small array on big disks, check if small spare is accepted"
372 setupdevs 0 8 9 $platform 10000 1
373 setupdevs 1 0 1 $platform
374 createconfig a
375 createconfig domain-$platform $platform spare 0 1 2 8 9
376 monitor 0 1
377 mdadm -a /dev/$c1 $dev2
378 mdadm --fail /dev/$v0 $dev9
379 chksparemoved $c1 $c0 $d2
380 tidyup
381 }
382
383 test15()
384 {
385 dsc "Test 15: spare in global domain for $platform metadata, should be moved"
386 # this is like 9a but only one metadata used
387 setupdevs 0 10 11 $platform
388 setupdevs 1 8 9 $platform
389 createconfig a
390 createconfig domain-global $platform spare 8 9 10 11 12
391 createconfig domain-1 $platform spare 8 9
392 createconfig domain-2 $platform spare 10 11
393 monitor 0 1
394 mdadm -a /dev/$c1 $dev12
395 mdadm --fail /dev/$v0 $dev10
396 chksparemoved $c1 $c0 $dev12
397 tidyup
398 }
399
400 try()
401 {
402 test0
403 test0a
404 test1
405 test1a
406 test2
407 test3
408 test4
409 test5
410 test6
411 if [ "$platform" != "1.2" ]; then
412 # this is because we can't have a small spare added to native array
413 test7
414 test7a
415 fi
416 test8
417 test9
418 test9a
419 if [ "$platform" != "1.2" ]; then
420 # we can't create two subarrays on the same devices for native (without
421 # partitions)
422 test10
423 fi
424 test11
425 test12
426 test13
427 test14
428 test15
429 }
430
431 try_failed()
432 {
433 platform="1.2"
434 scan="no"
435 test5
436 test9
437 test13
438 scan="yes"
439 test9
440 }
441
442 #try_failed
443
444 for scan in no yes; do
445 for platform in 1.2 imsm; do
446 try
447 done
448 done
449
450 [ $listfailed == "no" ] || [ -z $flist ] || echo -e "\n FAILED TESTS: $flist"
451
452 #cat $targetdir/log
453 rm -f /dev/disk/by-path/loop*