3 # run test suite for mdadm
5 if [ " $user" != " root" ]
6 then echo >&2 "test: testing can only be done as 'root'."
19 echo >&2 "test: $mdadm isn't usable."
22 # assume md0, md1, md2 exist in /dev
23 md0
=/dev
/md0 md1
=/dev
/md1 md2
=/dev
/md2
27 # We test mdadm on loop-back block devices.
28 # dir for storing files should be settable by command line maybe
31 # super0, round down to multiple of 64 and substract 64
33 # super00 is nested, subtract 128
35 # super1.0 round down to multiple of 2, subtract 8
37 # super1.1 for linear: round to multiple of 2, subtract 4
39 # subtract another 4 for bitmaps
44 # ddf needs bigger devices as 32Meg is reserved!
50 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12
52 losetup
-d /dev
/loop
$d ; # rm -f $targetdir/mdtest$d
56 trap cleanup
0 1 2 3 15
59 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12
62 if [ $d -gt 7 ]; then sz
=$ddfsize ; fi
63 [ -f $targetdir/mdtest
$d ] ||
dd if=/dev
/zero of
=$targetdir/mdtest
$d count
=$sz bs
=1K
> /dev
/null
2>&1
64 [ -b /dev
/loop
$d ] || mknod
/dev
/loop
$d b
7 $d
67 losetup
/dev
/loop
$d $targetdir/mdtest6
# for multipath use
69 losetup
/dev
/loop
$d $targetdir/mdtest
$d
71 eval dev
$d=/dev
/loop
$d
72 eval file$d=$targetdir/mdtest
$d
73 eval devlist
=\"\
$devlist \
$dev$d\"
74 #" <-- add this quote to un-confuse vim syntax highlighting
80 [ -f /proc
/mdstat
] || modprobe md_mod
81 echo 2000 > /proc
/sys
/dev
/raid
/speed_limit_max
82 echo 0 > /sys
/module
/md_mod
/parameters
/start_ro
84 if [ " $1" = " setup" ]
88 # mdadm always adds --quiet, and we want to see any unexpected messages
90 rm -f $targetdir/stderr
92 *-S* ) udevadm settle
;;
95 *-C* ) $mdadm 2> $targetdir/stderr
--quiet "$@" --auto=yes;;
96 * ) $mdadm 2> $targetdir/stderr
--quiet "$@"
99 cat >&2 $targetdir/stderr
103 # check various things
107 spares
=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
108 if [ $spares -ne $2 ]
110 echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
114 grep -s "active $1 " /proc
/mdstat
> /dev
/null ||
{
115 echo >&2 "ERROR active $1 not found" ; cat /proc
/mdstat
; exit 1;}
117 resync | recovery | reshape
)
119 grep -s $1 /proc
/mdstat
> /dev
/null ||
{
120 echo >&2 ERROR no
$1 happening
; cat /proc
/mdstat
; exit 1; }
125 if grep -s -E '(resync|recovery|reshape) =' > /dev
/null
/proc
/mdstat
; then
126 echo >&2 "ERROR resync or recovery is happening!"; cat /proc
/mdstat
; exit 1;
132 while grep -E '(resync|recovery|reshape|check|repair) =' > /dev
/null
/proc
/mdstat
138 grep -s "blocks.*\[$2\]\$" /proc
/mdstat
> /dev
/null ||
{
139 echo >&2 "ERROR state $2 not found!"; cat /proc
/mdstat
; exit 1; }
144 grep -s bitmap
> /dev
/null
/proc
/mdstat ||
{
145 echo >&2 ERROR no bitmap
; cat /proc
/mdstat
; exit 1; }
148 if grep -s "bitmap" > /dev
/null
/proc
/mdstat
150 echo >&2 ERROR bitmap present
; cat /proc
/mdstat
; exit 1;
154 * ) echo >&2 ERROR unknown check
$1 ; exit 1;
159 if [ -s $targetdir/stderr
]
160 then echo Bad errors from mdadm
: ; cat $targetdir/stderr
; exit 2;
172 mkfs
-j $dev > /dev
/null
2>&1 && fsck
-fn $dev >&2
174 dsize
=$
[dvsize
/chunk
]
176 rasize
=$
[dsize
*2*cnt
]
177 # rasize is in sectors
178 if [ -n "$DEV_ROUND_K" ]; then
179 rasize
=$
[rasize
/DEV_ROUND_K
/2]
180 rasize
=$
[rasize
*DEV_ROUND_K
*2]
182 if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi
183 if [ $rasize -ne `/sbin/blockdev --getsize $dev` ]
185 echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not `/sbin/blockdev --getsize $dev`"
195 setup_environment
() {
202 reset_environment
() {
210 for script in tests
/$prefix tests
/$prefix*[^~
]
214 rm -f $targetdir/stderr
215 # stop all arrays, just incase some script left an array active.
217 mdadm
--zero $devlist 2> /dev
/null
218 mdadm
--zero $devlist 2> /dev
/null
219 environment
="tests/env-`basename $script`"
220 setup_environment
$environment
221 # source script in a subshell, so it has access to our
222 # namespace, but cannot change it.
223 if ( set -ex ; .
$script ) 2> $targetdir/log
224 then echo "$script succeeded"
225 else cat $targetdir/log
; cat $targetdir/stderr
226 echo "$script failed"
227 reset_environment
$environment
230 reset_environment
$environment