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