]>
Commit | Line | Data |
---|---|---|
23b7d3b9 | 1 | #!/bin/bash |
5e7519fa NB |
2 | # |
3 | # run test suite for mdadm | |
4 | user=`id -un` | |
5 | if [ " $user" != " root" ] | |
6 | then echo >&2 "test: testing can only be done as 'root'." | |
7 | exit 1; | |
8 | fi | |
9 | ||
10 | prefix='[0-9][0-9]' | |
5e7519fa NB |
11 | |
12 | dir=`pwd` | |
13 | mdadm=$dir/mdadm | |
5e7519fa NB |
14 | if [ \! -x $mdadm ] |
15 | then | |
16 | echo >&2 "test: $mdadm isn't usable." | |
17 | fi | |
18 | ||
60381555 JS |
19 | testdir="tests" |
20 | logdir="$testdir/logs" | |
21 | logsave=0 | |
b8e91a32 | 22 | exitonerror=1 |
60381555 | 23 | |
98a92cff GE |
24 | echo "Testing on linux-$(uname -r) kernel" |
25 | ||
04c1ca5f JS |
26 | # Check whether to run multipath tests |
27 | modprobe multipath 2> /dev/null | |
28 | if grep -s 'Personalities : .*multipath' > /dev/null /proc/mdstat ; then | |
29 | MULTIPATH="yes" | |
30 | fi | |
bde085f4 | 31 | INTEGRITY=yes |
7d8a70bf | 32 | DEVTYPE=loop |
33 | LVM_VOLGROUP=mdtest | |
04c1ca5f | 34 | |
9540cc24 N |
35 | # make sure to test local mdmon, not system one |
36 | export MDADM_NO_SYSTEMCTL=1 | |
37 | ||
5e7519fa | 38 | # assume md0, md1, md2 exist in /dev |
dab6685f | 39 | md0=/dev/md0 md1=/dev/md1 md2=/dev/md2 |
1f48664b NB |
40 | mdp0=/dev/md_d0 |
41 | mdp1=/dev/md_d1 | |
5e7519fa NB |
42 | |
43 | # We test mdadm on loop-back block devices. | |
44 | # dir for storing files should be settable by command line maybe | |
1bf4e2d9 | 45 | targetdir=/var/tmp |
5e7519fa | 46 | size=20000 |
69646c14 | 47 | # super0, round down to multiple of 64 and substract 64 |
5e7519fa | 48 | mdsize0=19904 |
1c203a4b NB |
49 | # super00 is nested, subtract 128 |
50 | mdsize00=19840 | |
69646c14 | 51 | # super1.0 round down to multiple of 2, subtract 8 |
1bf4e2d9 | 52 | mdsize1=19992 |
ebe6ea0c N |
53 | mdsize1a=19988 |
54 | mdsize12=19988 | |
55 | # super1.2 for linear: round to multiple of 2, subtract 4 | |
3c8b2739 N |
56 | mdsize1_l=19996 |
57 | mdsize2_l=19996 | |
69646c14 NB |
58 | # subtract another 4 for bitmaps |
59 | mdsize1b=19988 | |
60 | mdsize11=19992 | |
3c8b2739 | 61 | mdsize11a=19456 |
69646c14 | 62 | mdsize12=19988 |
5e7519fa | 63 | |
d50683f9 N |
64 | # ddf needs bigger devices as 32Meg is reserved! |
65 | ddfsize=65536 | |
66 | ||
ed02d9cc CA |
67 | config=/tmp/mdadm.conf |
68 | ||
5e7519fa | 69 | cleanup() { |
2952742d | 70 | udevadm settle |
4f8a3e5b | 71 | $mdadm -Ssq 2> /dev/null |
7d8a70bf | 72 | case $DEVTYPE in |
73 | loop) | |
74 | for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 | |
75 | do | |
97691508 AC |
76 | losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d |
77 | rm -f /dev/disk/by-path/loop* | |
7d8a70bf | 78 | done |
79 | ;; | |
80 | lvm) | |
81 | for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 | |
82 | do | |
83 | eval "lvremove --quiet -f \$dev$d" | |
84 | done | |
85 | ;; | |
86 | esac | |
5e7519fa NB |
87 | } |
88 | ||
d5a221a5 | 89 | ctrl_c() { |
4d5995c4 GE |
90 | exitonerror=1 |
91 | } | |
92 | ||
572d7091 | 93 | do_setup() { |
4d5995c4 | 94 | trap cleanup 0 1 3 15 |
d5a221a5 | 95 | trap ctrl_c 2 |
5e7519fa | 96 | |
dd0468af N |
97 | # make sure there are no loop devices remaining. |
98 | # udev started things can sometimes prevent them being stopped | |
99 | # immediately | |
100 | while grep loop /proc/partitions > /dev/null 2>&1 | |
101 | do | |
5c351af1 | 102 | mdadm -Ss |
dd0468af N |
103 | losetup -d /dev/loop[0-9]* 2> /dev/null |
104 | sleep 1 | |
105 | done | |
572d7091 | 106 | devlist= |
840ad583 | 107 | for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 |
572d7091 JS |
108 | do |
109 | sz=$size | |
110 | if [ $d -gt 7 ]; then sz=$ddfsize ; fi | |
7d8a70bf | 111 | case $DEVTYPE in |
112 | loop) | |
113 | [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1 | |
21a1287a N |
114 | # make sure udev doesn't touch |
115 | mdadm --zero $targetdir/mdtest$d 2> /dev/null | |
7d8a70bf | 116 | [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d |
117 | if [ $d -eq 7 ] | |
118 | then | |
119 | losetup /dev/loop$d $targetdir/mdtest6 # for multipath use | |
120 | else | |
121 | losetup /dev/loop$d $targetdir/mdtest$d | |
122 | fi | |
123 | eval dev$d=/dev/loop$d | |
124 | eval file$d=$targetdir/mdtest$d | |
125 | ;; | |
126 | lvm) | |
127 | unset MULTIPATH | |
128 | eval dev$d=/dev/mapper/${LVM_VOLGROUP}-mdtest$d | |
129 | if ! lvcreate --quiet -L ${sz}K -n mdtest$d $LVM_VOLGROUP; then | |
130 | trap '' 0 # make sure lvremove is not called | |
131 | eval echo error creating \$dev$d | |
132 | exit 129 | |
133 | fi | |
134 | ;; | |
135 | ram) | |
136 | unset MULTIPATH | |
137 | eval dev$d=/dev/ram$d | |
138 | ;; | |
139 | esac | |
572d7091 | 140 | eval devlist=\"\$devlist \$dev$d\" |
aef14b9e | 141 | eval devlist$d=\"\$devlist\" |
4b7a9ee3 | 142 | #" <-- add this quote to un-confuse vim syntax highlighting |
572d7091 JS |
143 | done |
144 | path0=$dev6 | |
145 | path1=$dev7 | |
c13c45e9 | 146 | |
572d7091 JS |
147 | ulimit -c unlimited |
148 | [ -f /proc/mdstat ] || modprobe md_mod | |
149 | echo 2000 > /proc/sys/dev/raid/speed_limit_max | |
150 | echo 0 > /sys/module/md_mod/parameters/start_ro | |
151 | } | |
0aa389dc | 152 | |
dab6685f NB |
153 | # mdadm always adds --quiet, and we want to see any unexpected messages |
154 | mdadm() { | |
beae1dfe | 155 | rm -f $targetdir/stderr |
045495a3 | 156 | case $* in |
602b9169 N |
157 | *-S* ) udevadm settle |
158 | p=`cat /proc/sys/dev/raid/speed_limit_max` | |
0832fb09 | 159 | echo 20000 > /proc/sys/dev/raid/speed_limit_max |
045495a3 | 160 | esac |
9860f271 | 161 | case $* in |
602b9169 N |
162 | *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;; |
163 | * ) $mdadm 2> $targetdir/stderr --quiet "$@" | |
9860f271 | 164 | esac |
dd4ae23a | 165 | rv=$? |
019ca1e1 | 166 | case $* in |
602b9169 N |
167 | *-S* ) udevadm settle |
168 | echo $p > /proc/sys/dev/raid/speed_limit_max | |
019ca1e1 | 169 | esac |
bf4fb153 | 170 | cat >&2 $targetdir/stderr |
dd4ae23a | 171 | return $rv |
dab6685f NB |
172 | } |
173 | ||
174 | # check various things | |
175 | check() { | |
176 | case $1 in | |
308e1801 NB |
177 | spares ) |
178 | spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0` | |
179 | if [ $spares -ne $2 ] | |
180 | then | |
181 | echo >&2 "ERROR expected $2 spares, found $spares"; exit 1; | |
182 | fi | |
183 | ;; | |
dab6685f NB |
184 | raid* | linear ) |
185 | grep -s "active $1 " /proc/mdstat > /dev/null || { | |
4f8a3e5b | 186 | echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;} |
dab6685f | 187 | ;; |
35698c6e N |
188 | algorithm ) |
189 | grep -s " algorithm $2 " /proc/mdstat > /dev/null || { | |
190 | echo >&2 "ERROR algorithm $2 not found"; cat /proc/mdstat; exit 1;} | |
191 | ;; | |
0aa389dc | 192 | resync | recovery | reshape) |
a76b3a34 N |
193 | cnt=5 |
194 | while ! grep -s $1 /proc/mdstat > /dev/null | |
195 | do | |
196 | if [ $cnt -gt 0 ] && grep -v idle /sys/block/md*/md/sync_action > /dev/null | |
197 | then # Something isn't idle - wait a bit | |
198 | sleep 0.5 | |
199 | cnt=$[cnt-1] | |
200 | else | |
201 | echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1 | |
202 | fi | |
203 | done | |
204 | ;; | |
4f8a3e5b | 205 | |
dab6685f NB |
206 | nosync ) |
207 | sleep 0.5 | |
6fba5a33 N |
208 | # Since 4.2 we delay the close of recovery until there has been a chance for |
209 | # spares to be activated. That means that a recovery that finds nothing | |
210 | # to do can still take a little longer than expected. | |
211 | # add an extra check: is sync_completed shows the end is reached, assume | |
212 | # there is no recovery. | |
0d711ba4 | 213 | if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat ; then |
6fba5a33 N |
214 | incomplete=`grep / /sys/block/md*/md/sync_completed 2> /dev/null | sed '/^ *\([0-9]*\) \/ \1/d'` |
215 | if [ -n "$incomplete" ]; then | |
4f8a3e5b | 216 | echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1; |
6fba5a33 | 217 | fi |
dab6685f NB |
218 | fi |
219 | ;; | |
4f8a3e5b | 220 | |
dab6685f | 221 | wait ) |
6fd2a36f N |
222 | p=`cat /proc/sys/dev/raid/speed_limit_max` |
223 | echo 2000000 > /proc/sys/dev/raid/speed_limit_max | |
dab6685f | 224 | sleep 0.1 |
a76b3a34 N |
225 | while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat || |
226 | grep -v idle > /dev/null /sys/block/md*/md/sync_action | |
6fd2a36f | 227 | do sleep 0.5; |
dab6685f | 228 | done |
6fd2a36f | 229 | echo $p > /proc/sys/dev/raid/speed_limit_max |
dab6685f | 230 | ;; |
4f8a3e5b | 231 | |
dab6685f NB |
232 | state ) |
233 | grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || { | |
4f8a3e5b | 234 | echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; } |
dab6685f NB |
235 | sleep 0.5 |
236 | ;; | |
fe80f49b NB |
237 | |
238 | bitmap ) | |
239 | grep -s bitmap > /dev/null /proc/mdstat || { | |
4f8a3e5b | 240 | echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; } |
fe80f49b NB |
241 | ;; |
242 | nobitmap ) | |
4f8a3e5b | 243 | if grep -s "bitmap" > /dev/null /proc/mdstat |
fe80f49b | 244 | then |
4f8a3e5b | 245 | echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1; |
fe80f49b NB |
246 | fi |
247 | ;; | |
4f8a3e5b | 248 | |
dab6685f NB |
249 | * ) echo >&2 ERROR unknown check $1 ; exit 1; |
250 | esac | |
251 | } | |
252 | ||
bf4fb153 NB |
253 | no_errors() { |
254 | if [ -s $targetdir/stderr ] | |
255 | then echo Bad errors from mdadm: ; cat $targetdir/stderr; exit 2; | |
256 | fi | |
257 | } | |
dab6685f NB |
258 | # basic device test |
259 | ||
260 | testdev() { | |
ba624124 | 261 | udevadm settle |
dab6685f NB |
262 | dev=$1 |
263 | cnt=$2 | |
264 | dvsize=$3 | |
265 | chunk=$4 | |
487e48af | 266 | if [ -z "$5" ]; then |
d51e39c0 | 267 | mkfs.ext3 -F -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2 |
487e48af | 268 | fi |
dab6685f NB |
269 | dsize=$[dvsize/chunk] |
270 | dsize=$[dsize*chunk] | |
81074c9f | 271 | rasize=$[dsize*2*cnt] |
6636f0ef N |
272 | # rasize is in sectors |
273 | if [ -n "$DEV_ROUND_K" ]; then | |
274 | rasize=$[rasize/DEV_ROUND_K/2] | |
275 | rasize=$[rasize*DEV_ROUND_K*2] | |
276 | fi | |
7801ac20 | 277 | if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi |
974e0395 N |
278 | _sz=`/sbin/blockdev --getsize $dev` |
279 | if [ $rasize -lt $_sz -o $[rasize*4/5] -gt $_sz ] | |
dab6685f | 280 | then |
974e0395 | 281 | echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz" |
dab6685f NB |
282 | exit 1 |
283 | fi | |
284 | } | |
285 | ||
6fd2a36f N |
286 | fast_sync() { |
287 | echo 200000 > /proc/sys/dev/raid/speed_limit_max | |
288 | } | |
289 | ||
c13c45e9 NB |
290 | rotest() { |
291 | dev=$1 | |
292 | fsck -fn $dev >&2 | |
293 | } | |
294 | ||
4e5ce543 JS |
295 | do_test() { |
296 | _script=$1 | |
60381555 | 297 | _basename=`basename $_script` |
4e5ce543 | 298 | if [ -f "$_script" ] |
34163fc7 | 299 | then |
4e5ce543 JS |
300 | rm -f $targetdir/stderr |
301 | # stop all arrays, just incase some script left an array active. | |
302 | $mdadm -Ssq 2> /dev/null | |
303 | mdadm --zero $devlist 2> /dev/null | |
304 | mdadm --zero $devlist 2> /dev/null | |
6fd2a36f N |
305 | # this might have been reset: restore the default. |
306 | echo 2000 > /proc/sys/dev/raid/speed_limit_max | |
4e5ce543 JS |
307 | # source script in a subshell, so it has access to our |
308 | # namespace, but cannot change it. | |
309 | echo -ne "$_script... " | |
45e34015 | 310 | if ( set -ex ; . $_script ) &> $targetdir/log |
60381555 JS |
311 | then |
312 | echo "succeeded" | |
313 | _fail=0 | |
314 | else | |
1dc837e4 | 315 | log=log |
855a3539 | 316 | cat $targetdir/stderr >> $targetdir/log |
bc6ccf96 N |
317 | echo "=======================dmesg=================" >> $targetdir/log |
318 | dmesg | tail -n 200 >> $targetdir/log | |
1dc837e4 N |
319 | if [ $exitonerror == 0 ]; then |
320 | log=log-`basename $_script` | |
5bc29745 | 321 | mv $targetdir/log $logdir/$log |
1dc837e4 | 322 | fi |
5bc29745 | 323 | echo "FAILED - see $logdir/$log for details" |
60381555 JS |
324 | _fail=1 |
325 | fi | |
326 | if [ "$savelogs" == "1" ]; then | |
327 | cp $targetdir/log $logdir/$_basename.log | |
328 | fi | |
b8e91a32 | 329 | if [ "$_fail" == "1" -a "$exitonerror" == "1" ]; then |
4e5ce543 JS |
330 | exit 1 |
331 | fi | |
34163fc7 | 332 | fi |
4e5ce543 JS |
333 | } |
334 | ||
335 | do_help() { | |
0aaecb43 JS |
336 | echo "Usage: $0 [options]" |
337 | echo " Options:" | |
338 | echo " --tests=<test1,test2,..> Comma separated list of tests to run" | |
339 | echo " --disable-multipath Disable any tests involving multipath" | |
bde085f4 | 340 | echo " --disable-integrity Disable slow tests of RAID[56] consistency" |
0aaecb43 JS |
341 | echo " --logdir=<directory> Directory to save logfiles in" |
342 | echo " --save-logs Save all logs in <logdir>" | |
4d327173 | 343 | echo " --keep-going Don't stop on error, ie. run all tests" |
7d8a70bf | 344 | echo " --dev=[loop|lvm|ram] Use loop devices (default), LVM, or RAM disk" |
345 | echo " --volgroup=<name> LVM volume group for LVM test" | |
0aaecb43 | 346 | echo " setup Setup test environment and exit" |
572d7091 | 347 | echo " cleanup Cleanup test environment" |
0aaecb43 | 348 | echo " <prefix> Run tests with <prefix>" |
4e5ce543 JS |
349 | } |
350 | ||
351 | parse_args() { | |
352 | for i in $* | |
353 | do | |
354 | case $i in | |
355 | [0-9]*) | |
356 | prefix=$i | |
357 | ;; | |
358 | setup) | |
359 | echo "mdadm test environment setup" | |
572d7091 | 360 | do_setup |
4e5ce543 JS |
361 | trap 0; exit 0 |
362 | ;; | |
572d7091 JS |
363 | cleanup) |
364 | cleanup | |
365 | exit 0 | |
366 | ;; | |
4e5ce543 JS |
367 | --tests=*) |
368 | TESTLIST=`expr "x$i" : 'x[^=]*=\(.*\)' | sed -e 's/,/ /g'` | |
369 | ;; | |
60381555 JS |
370 | --logdir=*) |
371 | logdir=`expr "x$i" : 'x[^=]*=\(.*\)'` | |
372 | ;; | |
373 | --save-logs) | |
374 | savelogs=1 | |
60381555 | 375 | ;; |
4d327173 | 376 | --keep-going | --no-error) |
fc092254 | 377 | exitonerror=0 |
b8e91a32 | 378 | ;; |
4e5ce543 JS |
379 | --disable-multipath) |
380 | unset MULTIPATH | |
381 | ;; | |
bde085f4 N |
382 | --disable-integrity) |
383 | unset INTEGRITY | |
384 | ;; | |
7d8a70bf | 385 | --dev=loop) |
386 | DEVTYPE=loop | |
387 | ;; | |
388 | --dev=lvm) | |
389 | DEVTYPE=lvm | |
390 | ;; | |
391 | --dev=ram) | |
392 | DEVTYPE=ram | |
393 | ;; | |
394 | --volgroup=*) | |
395 | LVM_VOLGROUP=`expr "x$i" : 'x[^=]*=\(.*\)'` | |
396 | ;; | |
4e5ce543 JS |
397 | --help) |
398 | do_help | |
399 | exit 0; | |
400 | ;; | |
401 | -*) | |
402 | echo " $0: Unknown argument: $i" | |
403 | do_help | |
404 | exit 0; | |
405 | ;; | |
406 | esac | |
5e7519fa | 407 | done |
4e5ce543 JS |
408 | } |
409 | ||
5bc29745 | 410 | logdir=$targetdir |
4e5ce543 JS |
411 | parse_args $@ |
412 | ||
572d7091 | 413 | do_setup |
5bc29745 | 414 | mkdir -p $logdir |
572d7091 | 415 | |
60381555 JS |
416 | if [ "$savelogs" == "1" ]; then |
417 | echo "Saving logs to $logdir" | |
418 | fi | |
419 | ||
4e5ce543 JS |
420 | if [ "x$TESTLIST" != "x" ]; then |
421 | for script in $TESTLIST | |
422 | do | |
60381555 | 423 | do_test $testdir/$script |
4e5ce543 JS |
424 | done |
425 | else | |
60381555 | 426 | for script in $testdir/$prefix $testdir/$prefix*[^~] |
4e5ce543 JS |
427 | do |
428 | do_test $script | |
429 | done | |
430 | fi | |
5e7519fa | 431 | exit 0 |