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