3 # run test suite for mdadm
5 if [ " $user" != " root" ]
6 then echo >&2 "test: testing can only be done as 'root'."
16 echo >&2 "test: $mdadm isn't usable."
20 logdir
="$testdir/logs"
24 echo "Testing on linux-$(uname -r) kernel"
26 # Check whether to run multipath tests
27 modprobe multipath
2> /dev
/null
28 if grep -s 'Personalities : .*multipath' > /dev
/null
/proc
/mdstat
; then
35 # make sure to test local mdmon, not system one
36 export MDADM_NO_SYSTEMCTL
=1
38 # assume md0, md1, md2 exist in /dev
39 md0
=/dev
/md0 md1
=/dev
/md1 md2
=/dev
/md2
43 # We test mdadm on loop-back block devices.
44 # dir for storing files should be settable by command line maybe
47 # super0, round down to multiple of 64 and substract 64
49 # super00 is nested, subtract 128
51 # super1.0 round down to multiple of 2, subtract 8
55 # super1.2 for linear: round to multiple of 2, subtract 4
58 # subtract another 4 for bitmaps
64 # ddf needs bigger devices as 32Meg is reserved!
67 config
=/tmp
/mdadm.conf
71 $mdadm -Ssq 2> /dev
/null
74 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
76 losetup
-d /dev
/loop
$d ; # rm -f $targetdir/mdtest$d
77 rm -f /dev
/disk
/by-path
/loop
*
81 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
83 eval "lvremove --quiet -f \$dev$d"
97 # make sure there are no loop devices remaining.
98 # udev started things can sometimes prevent them being stopped
100 while grep loop
/proc
/partitions
> /dev
/null
2>&1
103 losetup
-d /dev
/loop
[0-9]* 2> /dev
/null
107 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
110 if [ $d -gt 7 ]; then sz
=$ddfsize ; fi
113 [ -f $targetdir/mdtest
$d ] ||
dd if=/dev
/zero of
=$targetdir/mdtest
$d count
=$sz bs
=1K
> /dev
/null
2>&1
114 # make sure udev doesn't touch
115 mdadm
--zero $targetdir/mdtest
$d 2> /dev
/null
116 [ -b /dev
/loop
$d ] || mknod
/dev
/loop
$d b
7 $d
119 losetup
/dev
/loop
$d $targetdir/mdtest6
# for multipath use
121 losetup
/dev
/loop
$d $targetdir/mdtest
$d
123 eval dev
$d=/dev
/loop
$d
124 eval file$d=$targetdir/mdtest
$d
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
137 eval dev
$d=/dev
/ram
$d
140 eval devlist
=\"\
$devlist \
$dev$d\"
141 eval devlist
$d=\"\
$devlist\"
142 #" <-- add this quote to un-confuse vim syntax highlighting
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
153 # mdadm always adds --quiet, and we want to see any unexpected messages
155 rm -f $targetdir/stderr
157 *-S* ) udevadm settle
158 p
=`cat /proc/sys/dev/raid/speed_limit_max`
159 echo 20000 > /proc
/sys
/dev
/raid
/speed_limit_max
162 *-C* ) $mdadm 2> $targetdir/stderr
--quiet "$@" --auto=yes;;
163 * ) $mdadm 2> $targetdir/stderr
--quiet "$@"
167 *-S* ) udevadm settle
168 echo $p > /proc
/sys
/dev
/raid
/speed_limit_max
170 cat >&2 $targetdir/stderr
174 # check various things
178 spares
=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
179 if [ $spares -ne $2 ]
181 echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
185 grep -s "active $1 " /proc
/mdstat
> /dev
/null ||
{
186 echo >&2 "ERROR active $1 not found" ; cat /proc
/mdstat
; exit 1;}
189 grep -s " algorithm $2 " /proc
/mdstat
> /dev
/null ||
{
190 echo >&2 "ERROR algorithm $2 not found"; cat /proc
/mdstat
; exit 1;}
192 resync | recovery | reshape
)
194 while ! grep -s $1 /proc
/mdstat
> /dev
/null
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
201 echo >&2 ERROR no
$1 happening
; cat /proc
/mdstat
; exit 1
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.
213 if grep -s -E '(resync|recovery|reshape) *=' > /dev
/null
/proc
/mdstat
; then
214 incomplete
=`grep / /sys/block/md*/md/sync_completed 2> /dev/null | sed '/^ *\([0-9]*\) \/ \1/d'`
215 if [ -n "$incomplete" ]; then
216 echo >&2 "ERROR resync or recovery is happening!"; cat /proc
/mdstat
; exit 1;
222 p
=`cat /proc/sys/dev/raid/speed_limit_max`
223 echo 2000000 > /proc
/sys
/dev
/raid
/speed_limit_max
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
229 echo $p > /proc
/sys
/dev
/raid
/speed_limit_max
233 grep -s "blocks.*\[$2\]\$" /proc
/mdstat
> /dev
/null ||
{
234 echo >&2 "ERROR state $2 not found!"; cat /proc
/mdstat
; exit 1; }
239 grep -s bitmap
> /dev
/null
/proc
/mdstat ||
{
240 echo >&2 ERROR no bitmap
; cat /proc
/mdstat
; exit 1; }
243 if grep -s "bitmap" > /dev
/null
/proc
/mdstat
245 echo >&2 ERROR bitmap present
; cat /proc
/mdstat
; exit 1;
250 grep -s "read-only" > /dev
/null
/proc
/mdstat ||
{
251 echo >&2 "ERROR array is not read-only!"; cat /proc
/mdstat
; exit 1; }
255 grep -s "inactive" > /dev
/null
/proc
/mdstat ||
{
256 echo >&2 "ERROR array is not inactive!"; cat /proc
/mdstat
; exit 1; }
258 * ) echo >&2 ERROR unknown check
$1 ; exit 1;
263 if [ -s $targetdir/stderr
]
264 then echo Bad errors from mdadm
: ; cat $targetdir/stderr
; exit 2;
276 mkfs.ext3
-F -j $dev > /dev
/null
2>&1 && fsck
-fn $dev >&2
278 dsize
=$
[dvsize
/chunk
]
280 rasize
=$
[dsize
*2*cnt
]
281 # rasize is in sectors
282 if [ -n "$DEV_ROUND_K" ]; then
283 rasize
=$
[rasize
/DEV_ROUND_K
/2]
284 rasize
=$
[rasize
*DEV_ROUND_K
*2]
286 if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi
287 _sz
=`/sbin/blockdev --getsize $dev`
288 if [ $rasize -lt $_sz -o $
[rasize
*4/5] -gt $_sz ]
290 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
296 echo 200000 > /proc
/sys
/dev
/raid
/speed_limit_max
306 _basename
=`basename $_script`
309 rm -f $targetdir/stderr
310 # stop all arrays, just incase some script left an array active.
311 $mdadm -Ssq 2> /dev
/null
312 mdadm
--zero $devlist 2> /dev
/null
313 mdadm
--zero $devlist 2> /dev
/null
314 # this might have been reset: restore the default.
315 echo 2000 > /proc
/sys
/dev
/raid
/speed_limit_max
316 # source script in a subshell, so it has access to our
317 # namespace, but cannot change it.
318 echo -ne "$_script... "
319 if ( set -ex ; .
$_script ) &> $targetdir/log
325 cat $targetdir/stderr
>> $targetdir/log
326 echo "=======================dmesg=================" >> $targetdir/log
327 dmesg |
tail -n 200 >> $targetdir/log
328 if [ $exitonerror == 0 ]; then
329 log
=log-
`basename $_script`
330 mv $targetdir/log
$logdir/$log
332 echo "FAILED - see $logdir/$log for details"
335 if [ "$savelogs" == "1" ]; then
336 cp $targetdir/log
$logdir/$_basename.log
338 if [ "$_fail" == "1" -a "$exitonerror" == "1" ]; then
345 echo "Usage: $0 [options]"
347 echo " --tests=<test1,test2,..> Comma separated list of tests to run"
348 echo " --disable-multipath Disable any tests involving multipath"
349 echo " --disable-integrity Disable slow tests of RAID[56] consistency"
350 echo " --logdir=<directory> Directory to save logfiles in"
351 echo " --save-logs Save all logs in <logdir>"
352 echo " --keep-going Don't stop on error, ie. run all tests"
353 echo " --dev=[loop|lvm|ram] Use loop devices (default), LVM, or RAM disk"
354 echo " --volgroup=<name> LVM volume group for LVM test"
355 echo " setup Setup test environment and exit"
356 echo " cleanup Cleanup test environment"
357 echo " <prefix> Run tests with <prefix>"
368 echo "mdadm test environment setup"
377 TESTLIST
=`expr "x$i" : 'x[^=]*=\(.*\)' | sed -e 's/,/ /g'`
380 logdir
=`expr "x$i" : 'x[^=]*=\(.*\)'`
385 --keep-going |
--no-error)
404 LVM_VOLGROUP
=`expr "x$i" : 'x[^=]*=\(.*\)'`
411 echo " $0: Unknown argument: $i"
425 if [ "$savelogs" == "1" ]; then
426 echo "Saving logs to $logdir"
429 if [ "x$TESTLIST" != "x" ]; then
430 for script in $TESTLIST
432 do_test
$testdir/$script
435 for script in $testdir/$prefix $testdir/$prefix*[^~
]