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!"
323 # It only can be used when there is only one raid
325 chunk_size
=`awk -F',' '/chunk/{print $2}' /proc/mdstat | awk -F'[a-z]' '{print $1}'`
326 if [ "$chunk_size" -ne "$2" ] ; then
327 die
"chunksize should be $2, but it's $chunk_size"
331 die
"unknown check $1"
337 if [ -s $targetdir/stderr
]
339 echo Bad errors from mdadm
:
340 cat $targetdir/stderr
347 [ -b $1 ] || die
"$1 isn't a block device."
348 [ "$DEVTYPE" == "disk" ] && return 0
356 mkfs.ext3
-F -j $dev > /dev
/null
2>&1 && fsck
-fn $dev >&2
358 dsize
=$
[dvsize
/chunk
]
360 rasize
=$
[dsize
*2*cnt
]
361 # rasize is in sectors
362 if [ -n "$DEV_ROUND_K" ]
364 rasize
=$
[rasize
/DEV_ROUND_K
/2]
365 rasize
=$
[rasize
*DEV_ROUND_K
*2]
367 [ `/sbin/blockdev --getsize $dev` -eq 0 ] && sleep 2
368 _sz
=`/sbin/blockdev --getsize $dev`
369 [ $rasize -lt $_sz -o $
[rasize
*4/5] -gt $_sz ] &&
370 die
"size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
381 _basename
=`basename $_script`
384 rm -f $targetdir/stderr
385 # stop all arrays, just incase some script left an array active.
386 $mdadm -Ssq 2> /dev
/null
387 mdadm
--zero $devlist 2> /dev
/null
388 # this might have been reset: restore the default.
389 echo 2000 > /proc
/sys
/dev
/raid
/speed_limit_max
390 # source script in a subshell, so it has access to our
391 # namespace, but cannot change it.
392 echo -ne "$_script... "
393 if ( set -ex ; .
$_script ) &> $targetdir/log
395 dmesg |
grep -iq "error\|call trace\|segfault" &&
396 die
"dmesg prints errors when testing $_basename!"
403 [ "$savelogs" == "1" ] &&
404 mv -f $targetdir/log
$logdir/$_basename.log
405 [ "$_fail" == "1" -a "$exitonerror" == "1" ] && exit 1
412 Example for disk mode: ./test --dev=disk --disks=/dev/sda{2..15}
414 --tests=test1,test2,... Comma separated list of tests to run
415 --raidtype= raid0|linear|raid1|raid456|raid10|ddf|imsm
416 --disable-multipath Disable any tests involving multipath
417 --disable-integrity Disable slow tests of RAID[56] consistency
418 --logdir=directory Directory to save all logfiles in
419 --save-logs Usually use with --logdir together
420 --keep-going | --no-error Don't stop on error, ie. run all tests
421 --dev=loop|lvm|ram|disk Use loop devices (default), LVM, RAM or disk
422 --disks= Provide a bunch of physical devices for test
423 --volgroup=name LVM volume group for LVM test
424 setup Setup test environment and exit
425 cleanup Cleanup test environment
426 prefix Run tests with <prefix>
427 --help | -h Print this usage
439 echo "mdadm test environment setup"
449 TESTLIST
=($
(echo ${i##*=} |
sed -e 's/,/ /g'))
454 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]r0\|raid0"))
457 TESTLIST
=($
(ls $testdir |
grep "linear"))
460 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]r1\|raid1" |
grep -vi raid10
))
463 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]r[4-6]\|raid[4-6]"))
466 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]r10\|raid10"))
469 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]ddf"))
472 TESTLIST
=($
(ls $testdir |
grep "[0-9][0-9]imsm"))
475 echo "Unknown argument: $i"
487 --keep-going |
--no-error )
490 --disable-multipath )
493 --disable-integrity )
511 echo "Unknown argument: $i"
518 disks
=(${disks[*]} ${i##*=})
521 LVM_VOLGROUP
=`expr "x$i" : 'x[^=]*=\(.*\)'`
528 echo " $0: Unknown argument: $i"
538 [ "X$user" != "Xroot" ] && {
539 echo "test: testing can only be done as 'root'."
542 [ -x "raid6check" -a -x $mdadm ] ||
{
543 echo "test: please run 'make everything' before perform testing."
546 cmds
=(mdadm lsblk df udevadm losetup mkfs.ext3 fsck
seq)
547 for cmd
in ${cmds[@]}
549 which $cmd > /dev
/null ||
{
550 echo "$cmd command not found!"
554 mdadm_src_ver
="$($mdadm -V 2>&1)"
555 mdadm_sbin_ver
="$($(which mdadm) -V 2>&1)"
556 if [ "$mdadm_src_ver" != "$mdadm_sbin_ver" ]
558 # it's nessesary to 'make install' mdadm to /SBIN/DIR,
559 # such as systemd/mdadm-grow-continue@.service, would
560 # run as an instance by systemd when reshape happens,
561 # thus ensure that the correct mdadm is in testing.
562 echo "test: please run 'make install' before testing."
565 if ! $
(df
-T . |
grep -iq ext
)
567 # 'external file' bitmap only supports with ext[2-4] file system
568 echo "test: please run test suite with ext[2-4] file system."
571 if $
(lsblk
-a |
grep -iq raid
)
573 # donot run mdadm -Ss directly if there are RAIDs working.
574 echo "test: please run test suite without running RAIDs environment."
577 # Check whether to run multipath tests
578 modprobe multipath
2> /dev
/null
579 grep -sq 'Personalities : .*multipath' /proc
/mdstat
&&
587 echo "Testing on linux-$(uname -r) kernel"
588 [ "$savelogs" == "1" ] &&
589 echo "Saving logs to $logdir"
590 if [ "x$TESTLIST" != "x" ]
592 for script in ${TESTLIST[@]}
594 do_test
$testdir/$script
597 for script in $testdir/$prefix $testdir/$prefix*[^~
]