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)
6 export IMSM_DEVNAME_AS_SERIAL=1
7 export IMSM_TEST_OROM=1
8 export IMSM_NO_PLATFORM=1
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
18 # if listfailed=no then exit on first failure
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
26 [ -z $monitorpid ] || return
27 if [ "$scan" == "yes" ]; then
28 $mdadm -F -d 1 --scan --mail root@localhost &
37 mddevs="$mddevs /dev/$container"
38 if [ "$container" != "$volumes" ]; then
39 for vol in $volumes; do
40 mddevs="$mddevs /dev/$vol"
45 if [ -n "$mddevs" ]; then
46 if [ "$verbose" != "yes" ]; then
47 $mdadm -F -d 1 $mddevs >&2 &
50 $mdadm -F -t -d 1 $mddevs &
54 [ "$verbose" != "yes" ] || echo $mddevs $monitorpid
59 dsc "Test 0: No config file, no spare should be moved"
60 setupdevs 0 0 1 $platform
61 setupdevs 1 3 4 $platform
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
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
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
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
91 createconfig domain-$platform $platform spare 0 1 2 3 4
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
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
106 createconfig domain-$platform $platform spare 0 1 2 3 4
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
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
121 createconfig domain-$platform $platform spare 0 1 2 3 4
123 mdadm --fail /dev/$v0 $dev1
124 mdadm -a /dev/$c1 $dev2
125 chksparemoved $c1 $c0 $dev2
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
136 createconfig domain-$platform"1" $platform spare 0 1 2
137 createconfig domain-$platform"2" $platform spare 3 4 5
139 mdadm --fail /dev/$v0 $dev1
140 mdadm -a /dev/$c1 $dev5
141 chksparemoved $c1 $c0 $dev5 n
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
151 createconfig domain-$platform $platform spare 0 1 2
153 mdadm --fail /dev/$v0 $dev1
154 mdadm -a /dev/$c1 $dev5
156 [ "$platform" == "imsm" ] || shouldmove="n"
157 chksparemoved $c1 $c0 $dev5 $shouldmove
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
170 createconfig domain-$platform"1" $platform spare 0 1 2 3 4
171 createconfig domain-$platform"2" $platform spare 5 6 7 8 9
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
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
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
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
208 createconfig domain-$platform $platform spare 0 1 2 8 9
210 mdadm -a /dev/$c0 $dev2
211 mdadm --fail /dev/$v1 $dev8
212 chksparemoved $c0 $c1 $dev2 n
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
222 createconfig domain-$platform $platform spare 0 1 2 8 9 10
224 mdadm -a /dev/$c1 $dev2
225 mdadm --fail /dev/$v1 $dev8
226 mdadm -a /dev/$c0 $dev10
227 chksparemoved $c0 $c1 $dev10
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
239 createconfig domain-$platform"1" $platform spare 0 1 8 9 10
240 createconfig domain-$platform"2" $platform spare 2
242 mdadm -a /dev/$c1 $dev2
244 mdadm --fail /dev/$v1 $dev8
245 mdadm -a /dev/$c0 $dev10
246 chksparemoved $c0 $c1 $dev10
252 # ddf does not have getinfo_super_disks implemented so skip this test
254 dsc "Test 8: imsm and ddf - spare should not be migrated"
255 setupdevs 0 10 11 imsm
258 createconfig domain0 noplatform spare 8 9 10 11 12
260 mdadm -a /dev/$c1 $dev12
261 mdadm --fail /dev/$v0 $dev10
262 chksparemoved $c1 $c0 $dev12 n
268 dsc "Test 9: imsm and native 1.2 - one domain, no metadata specified, spare should be moved"
269 setupdevs 0 10 11 imsm
272 createconfig domain0 noplatform spare 8 9 10 11 12
274 mdadm -a /dev/$c1 $dev12
275 mdadm --fail /dev/$v0 $dev10
276 chksparemoved $c1 $c0 $dev12
282 dsc "Test 9a: imsm and native 1.2 - spare in global domain, should be moved"
283 setupdevs 0 10 11 imsm
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
290 mdadm -a /dev/$c1 $dev12
291 mdadm --fail /dev/$v0 $dev10
292 chksparemoved $c1 $c0 $dev12
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
302 createconfig domain-$platform $platform spare 0 1 2 3 4 5
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
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
322 createconfig domain-$platform $platform spare 0 1 2 3 4
324 mdadm -a /dev/$c1 $dev2
325 mdadm --fail /dev/$v1 $dev3
326 #wait until recovery finishes so no degraded array in c1
328 mdadm --fail /dev/$v0 $dev0
329 chksparemoved $c1 $c0 $dev3 n
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
339 createconfig domain-$platform $platform spare 0 1 2 3 4 5
341 mdadm -a /dev/$c1 $dev2
342 mdadm -a /dev/$c1 $dev5
343 mdadm --fail /dev/$v0 $dev0
349 [ "$sc1" != "$sc2" ] || err "both spares in the same container $sc1"
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
360 createconfig domain-$platform $platform spare 0 1
361 createconfig domain-$platform $platform include 4 5 6
363 mdadm -a /dev/$c1 $dev6
364 mdadm --fail /dev/$v0 $dev0
365 chksparemoved $c1 $c0 $d6
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
375 createconfig domain-$platform $platform spare 0 1 2 8 9
377 mdadm -a /dev/$c1 $dev2
378 mdadm --fail /dev/$v0 $dev9
379 chksparemoved $c1 $c0 $d2
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
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
394 mdadm -a /dev/$c1 $dev12
395 mdadm --fail /dev/$v0 $dev10
396 chksparemoved $c1 $c0 $dev12
411 if [ "$platform" != "1.2" ]; then
412 # this is because we can't have a small spare added to native array
419 if [ "$platform" != "1.2" ]; then
420 # we can't create two subarrays on the same devices for native (without
444 for scan in no yes; do
445 for platform in 1.2 imsm; do
450 [ $listfailed == "no" ] || [ -z $flist ] || echo -e "\n FAILED TESTS: $flist"
453 rm -f /dev/disk/by-path/loop*