3 # run test suite for mdadm
15 # use loop devices by default if doesn't specify --dev
20 # make sure to test local mdmon, not system one
21 export MDADM_NO_SYSTEMCTL
=1
23 # assume md0, md1, md2 exist in /dev
30 # We test mdadm on loop-back block devices.
31 # dir for storing files should be settable by command line maybe
33 # super0, round down to multiple of 64 and substract 64
35 # super00 is nested, subtract 128
37 # super1.0 round down to multiple of 2, subtract 8
41 # super1.2 for linear: round to multiple of 2, subtract 4
44 # subtract another 4 for bitmaps
50 # ddf needs bigger devices as 32Meg is reserved!
53 # $1 is optional parameter, it shows why to save log
56 logfile
="$status""$_basename".log
58 cat $targetdir/stderr
>> $targetdir/log
59 cp $targetdir/log
$logdir/$_basename.log
60 echo "## $HOSTNAME: saving dmesg." >> $logdir/$logfile
61 dmesg
-c >> $logdir/$logfile
62 $mdadm -As 2> /dev
/null
63 echo "## $HOSTNAME: saving proc mdstat." >> $logdir/$logfile
64 cat /proc
/mdstat
>> $logdir/$logfile
65 array
=($
(mdadm
-Ds | cut
-d' ' -f2))
66 echo "## $HOSTNAME: mdadm -D ${array[@]}" >> $logdir/$logfile
67 $mdadm -D ${array[@]} >> $logdir/$logfile
69 echo "FAILED - see $logdir/$_basename.log and $logdir/$logfile for details"
70 # ignore saving external(external file, imsm...) bitmap
71 cat /proc
/mdstat |
grep -q "linear\|external" && return 0
72 if [ $DEVTYPE == 'lvm' ]
74 # not supported lvm type yet
76 elif [ "$DEVTYPE" == 'loop' -o "$DEVTYPE" == 'disk' ]
78 if [ ! -z ${array[@]} -a ${#array[@]} -ge 1 ]
80 md_disks
=($
($mdadm -D -Y ${array[@]} |
grep "/dev/" | cut
-d'=' -f2))
81 cat /proc
/mdstat |
grep -q "bitmap"
84 echo "## $HOSTNAME: mdadm -X ${md_disks[@]}" >> $logdir/$logfile
85 $mdadm -X ${md_disks[@]} >> $logdir/$logfile
88 echo "## $HOSTNAME: no array assembled!" >> $logdir/$logfile
94 echo -e "\n\tERROR: $* \n"
101 $mdadm -Ssq 2> /dev
/null
104 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
106 losetup
-d /dev
/loop
$d
107 rm -f /dev
/disk
/by-path
/loop
*
108 rm -f /var
/tmp
/mdtest
$d
112 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
114 eval "lvremove --quiet -f \$dev$d"
118 $mdadm --zero ${disks[@]} &> /dev
/null
128 trap cleanup
0 1 3 15
131 [ -d $logdir ] || mkdir
-p $logdir
135 if [ "$DEVTYPE" == "loop" ]
137 # make sure there are no loop devices remaining.
138 # udev started things can sometimes prevent them being stopped
140 while grep loop
/proc
/partitions
> /dev
/null
2>&1
143 losetup
-d /dev
/loop
[0-9]* 2> /dev
/null
146 elif [ "$DEVTYPE" == "disk" ]
150 for d
in $
(seq 0 ${#disks[@]})
152 eval "dev$d=${disks[$d]}"
153 eval devlist
=\"\
$devlist \
$dev$d\"
154 eval devlist
$d=\"\
$devlist\"
156 $mdadm --zero ${disks[@]} &> /dev
/null
158 echo "Forget to provide physical devices for disk mode."
162 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
165 [ $d -gt 7 ] && sz
=$ddfsize
168 [ -f $targetdir/mdtest
$d ] ||
169 dd if=/dev
/zero of
=$targetdir/mdtest
$d count
=$sz bs
=1K
> /dev
/null
2>&1
170 # make sure udev doesn't touch
171 mdadm
--zero $targetdir/mdtest
$d 2> /dev
/null
172 [ -b /dev
/loop
$d ] || mknod
/dev
/loop
$d b
7 $d
175 losetup
/dev
/loop
$d $targetdir/mdtest6
# for multipath use
177 losetup
/dev
/loop
$d $targetdir/mdtest
$d
179 eval dev
$d=/dev
/loop
$d
180 eval file$d=$targetdir/mdtest
$d
184 eval dev
$d=/dev
/mapper
/${LVM_VOLGROUP}-mdtest$d
185 if ! lvcreate
--quiet -L ${sz}K
-n mdtest
$d $LVM_VOLGROUP
187 trap '' 0 # make sure lvremove is not called
188 eval echo error creating \
$dev$d
194 eval dev
$d=/dev
/ram
$d
197 eval devlist
=\"\
$devlist \
$dev$d\"
198 eval devlist
$d=\"\
$devlist\"
199 #" <-- add this quote to un-confuse vim syntax highlighting
204 [ -f /proc
/mdstat
] || modprobe md_mod
205 echo 2000 > /proc
/sys
/dev
/raid
/speed_limit_max
206 echo 0 > /sys
/module
/md_mod
/parameters
/start_ro
209 # mdadm always adds --quiet, and we want to see any unexpected messages
211 rm -f $targetdir/stderr
215 p
=`cat /proc/sys/dev/raid/speed_limit_max`
216 echo 20000 > /proc
/sys
/dev
/raid
/speed_limit_max
220 *-C* |
*--create* |
*-B* |
*--build* )
221 # clear superblock every time once creating or
222 # building arrays, because it's always creating
223 # and building array many times in a test case.
226 [[ $args =~
"/dev/" ]] && {
227 [[ $args =~
"md" ]] ||
228 $mdadm --zero $args > /dev
/null
231 $mdadm 2> $targetdir/stderr
--quiet "$@" --auto=yes
234 $mdadm 2> $targetdir/stderr
--quiet "$@"
241 echo $p > /proc
/sys
/dev
/raid
/speed_limit_max
244 cat >&2 $targetdir/stderr
248 # check various things
252 spares
=$
(tr '] ' '\012\012' < /proc
/mdstat |
grep -c '(S)' ||
exit 0)
253 [ $spares -ne $2 ] &&
254 die
"expected $2 spares, found $spares"
257 grep -sq "active $1 " /proc
/mdstat ||
258 die
"active $1 not found"
261 grep -sq " algorithm $2 " /proc
/mdstat ||
262 die
"algorithm $2 not found"
264 resync | recovery | reshape
)
266 while ! grep -sq $1 /proc
/mdstat
268 if [ $cnt -gt 0 ] && grep -v idle
/sys
/block
/md
*/md
/sync_action
> /dev
/null
269 then # Something isn't idle - wait a bit
273 die
"no $1 happening"
279 # Since 4.2 we delay the close of recovery until there has been a chance for
280 # spares to be activated. That means that a recovery that finds nothing
281 # to do can still take a little longer than expected.
282 # add an extra check: is sync_completed shows the end is reached, assume
283 # there is no recovery.
284 if grep -sq -E '(resync|recovery|reshape) *=' /proc
/mdstat
286 incomplete
=`grep / /sys/block/md*/md/sync_completed 2> /dev/null | sed '/^ *\([0-9]*\) \/ \1/d'`
287 [ -n "$incomplete" ] &&
288 die
"resync or recovery is happening!"
292 p
=`cat /proc/sys/dev/raid/speed_limit_max`
293 echo 2000000 > /proc
/sys
/dev
/raid
/speed_limit_max
295 while grep -Eq '(resync|recovery|reshape|check|repair) *=' /proc
/mdstat ||
296 grep -v idle
> /dev
/null
/sys
/block
/md
*/md
/sync_action
300 echo $p > /proc
/sys
/dev
/raid
/speed_limit_max
303 grep -sq "blocks.*\[$2\]\$" /proc
/mdstat ||
304 die
"state $2 not found!"
308 grep -sq bitmap
/proc
/mdstat ||
312 grep -sq "bitmap" /proc
/mdstat
&&
316 grep -sq "read-only" /proc
/mdstat ||
317 die
"array is not read-only!"
320 grep -sq "inactive" /proc
/mdstat ||
321 die
"array is not inactive!"
324 die
"unknown check $1"
330 if [ -s $targetdir/stderr
]
332 echo Bad errors from mdadm
:
333 cat $targetdir/stderr
340 [ -b $1 ] || die
"$1 isn't a block device."
341 [ "$DEVTYPE" == "disk" ] && return 0
349 mkfs.ext3
-F -j $dev > /dev
/null
2>&1 && fsck
-fn $dev >&2
351 dsize
=$
[dvsize
/chunk
]
353 rasize
=$
[dsize
*2*cnt
]
354 # rasize is in sectors
355 if [ -n "$DEV_ROUND_K" ]
357 rasize
=$
[rasize
/DEV_ROUND_K
/2]
358 rasize
=$
[rasize
*DEV_ROUND_K
*2]
360 [ `/sbin/blockdev --getsize $dev` -eq 0 ] && sleep 2
361 _sz
=`/sbin/blockdev --getsize $dev`
362 [ $rasize -lt $_sz -o $
[rasize
*4/5] -gt $_sz ] &&
363 die
"size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
374 _basename
=`basename $_script`
377 rm -f $targetdir/stderr
378 # stop all arrays, just incase some script left an array active.
379 $mdadm -Ssq 2> /dev
/null
380 mdadm
--zero $devlist 2> /dev
/null
381 # this might have been reset: restore the default.
382 echo 2000 > /proc
/sys
/dev
/raid
/speed_limit_max
383 # source script in a subshell, so it has access to our
384 # namespace, but cannot change it.
385 echo -ne "$_script... "
386 if ( set -ex ; .
$_script ) &> $targetdir/log
388 dmesg |
grep -iq "error\|call trace\|segfault" &&
389 die
"dmesg prints errors when testing $_basename!"
396 [ "$savelogs" == "1" ] &&
397 mv -f $targetdir/log
$logdir/$_basename.log
398 [ "$_fail" == "1" -a "$exitonerror" == "1" ] && exit 1
405 Example for disk mode: ./test --dev=disk --disks=/dev/sda{2..15}
407 --tests=test1,test2,... Comma separated list of tests to run
408 --raidtype= raid0|linear|raid1|raid456|raid10|ddf|imsm
409 --disable-multipath Disable any tests involving multipath
410 --disable-integrity Disable slow tests of RAID[56] consistency
411 --logdir=directory Directory to save all logfiles in
412 --save-logs Usually use with --logdir together
413 --keep-going | --no-error Don't stop on error, ie. run all tests
414 --dev=loop|lvm|ram|disk Use loop devices (default), LVM, RAM or disk
415 --disks= Provide a bunch of physical devices for test
416 --volgroup=name LVM volume group for LVM test
417 setup Setup test environment and exit
418 cleanup Cleanup test environment
419 prefix Run tests with <prefix>
420 --help | -h Print this usage
432 echo "mdadm test environment setup"
442 TESTLIST
=($
(echo ${i##*=} |
sed -e 's/,/ /g'))
447 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]r0\|raid0"))
450 TESTLIST
=($
(ls $testdir |
grep "linear"))
453 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]r1\|raid1" |
grep -vi raid10
))
456 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]r[4-6]\|raid[4-6]"))
459 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]r10\|raid10"))
462 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]ddf"))
465 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]imsm"))
468 echo "Unknown argument: $i"
480 --keep-going |
--no-error )
483 --disable-multipath )
486 --disable-integrity )
504 echo "Unknown argument: $i"
511 disks
=(${disks[*]} ${i##*=})
514 LVM_VOLGROUP
=`expr "x$i" : 'x[^=]*=\(.*\)'`
521 echo " $0: Unknown argument: $i"
531 [ "X$user" != "Xroot" ] && {
532 echo "test: testing can only be done as 'root'."
535 [ -x "raid6check" -a -x $mdadm ] ||
{
536 echo "test: please run 'make everything' before perform testing."
539 cmds
=(mdadm lsblk df udevadm losetup mkfs.ext3 fsck
seq)
540 for cmd
in ${cmds[@]}
542 which $cmd > /dev
/null ||
{
543 echo "$cmd command not found!"
547 mdadm_src_ver
="$($mdadm -V 2>&1)"
548 mdadm_sbin_ver
="$($(which mdadm) -V 2>&1)"
549 if [ "$mdadm_src_ver" != "$mdadm_sbin_ver" ]
551 # it's nessesary to 'make install' mdadm to /SBIN/DIR,
552 # such as systemd/mdadm-grow-continue@.service, would
553 # run as an instance by systemd when reshape happens,
554 # thus ensure that the correct mdadm is in testing.
555 echo "test: please run 'make install' before testing."
558 if ! $
(df
-T . |
grep -iq ext
)
560 # 'external file' bitmap only supports with ext[2-4] file system
561 echo "test: please run test suite with ext[2-4] file system."
564 if $
(lsblk
-a |
grep -iq raid
)
566 # donot run mdadm -Ss directly if there are RAIDs working.
567 echo "test: please run test suite without running RAIDs environment."
570 # Check whether to run multipath tests
571 modprobe multipath
2> /dev
/null
572 grep -sq 'Personalities : .*multipath' /proc
/mdstat
&&
580 echo "Testing on linux-$(uname -r) kernel"
581 [ "$savelogs" == "1" ] &&
582 echo "Saving logs to $logdir"
583 if [ "x$TESTLIST" != "x" ]
585 for script in ${TESTLIST[@]}
587 do_test
$testdir/$script
590 for script in $testdir/$prefix $testdir/$prefix*[^~
]