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