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