3 # We test mdadm on loop-back block devices.
4 # dir for storing files should be settable by command line maybe
6 # super0, round down to multiple of 64 and substract 64
8 # super00 is nested, subtract 128
10 # super1.0 round down to multiple of 2, subtract 8
14 # super1.2 for linear: round to multiple of 2, subtract 4
17 # subtract another 4 for bitmaps
23 # ddf needs bigger devices as 32Meg is reserved!
26 # $1 is optional parameter, it shows why to save log
29 logfile
="$status""$_basename".log
31 cat $targetdir/stderr
>> $targetdir/log
32 cp $targetdir/log
$logdir/$_basename.log
33 echo "## $HOSTNAME: saving dmesg." >> $logdir/$logfile
34 dmesg
-c >> $logdir/$logfile
35 echo "## $HOSTNAME: saving proc mdstat." >> $logdir/$logfile
36 cat /proc
/mdstat
>> $logdir/$logfile
37 array
=($
(mdadm
-Ds | cut
-d' ' -f2))
39 echo "FAILED - see $logdir/$_basename.log and $logdir/$logfile for details"
40 if [ $DEVTYPE == 'lvm' ]
42 # not supported lvm type yet
44 elif [ "$DEVTYPE" == 'loop' -o "$DEVTYPE" == 'disk' ]
46 if [ ! -z "$array" -a ${#array[@]} -ge 1 ]
48 echo "## $HOSTNAME: mdadm -D ${array[@]}" >> $logdir/$logfile
49 $mdadm -D ${array[@]} >> $logdir/$logfile
50 # ignore saving external(external file, imsm...) bitmap
51 cat /proc
/mdstat |
grep -q "linear\|external" && return 0
52 md_disks
=($
($mdadm -D -Y ${array[@]} |
grep "/dev/" | cut
-d'=' -f2))
53 cat /proc
/mdstat |
grep -q "bitmap"
56 echo "## $HOSTNAME: mdadm -X ${md_disks[@]}" >> $logdir/$logfile
57 $mdadm -X ${md_disks[@]} >> $logdir/$logfile
58 echo "## $HOSTNAME: mdadm -E ${md_disks[@]}" >> $logdir/$logfile
59 $mdadm -E ${md_disks[@]} >> $logdir/$logfile
62 echo "## $HOSTNAME: no array assembled!" >> $logdir/$logfile
69 $mdadm -Ssq 2> /dev
/null
72 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
74 losetup
-d /dev
/loop
$d &> /dev
/null
75 rm -f /dev
/disk
/by-path
/loop
*
76 rm -f /var
/tmp
/mdtest
$d
80 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
82 eval "lvremove --quiet -f \$dev$d"
86 $mdadm --zero ${disks[@]} &> /dev
/null
94 mdadm
--zero $devlist 2> /dev
/null
100 [ "X$user" != "Xroot" ] && {
101 echo "test: testing can only be done as 'root'."
104 [ \
! -x $mdadm ] && {
105 echo "test: please run make everything before perform testing."
108 cmds
=(mdadm lsblk df udevadm losetup mkfs.ext3 fsck
seq)
109 for cmd
in ${cmds[@]}
111 which $cmd > /dev
/null ||
{
112 echo "$cmd command not found!"
116 if $
(lsblk
-a |
grep -iq raid
)
118 # donot run mdadm -Ss directly if there are RAIDs working.
119 echo "test: please run test suite without running RAIDs environment."
122 # Check whether to run multipath tests
123 modprobe multipath
2> /dev
/null
124 grep -sq 'Personalities : .*multipath' /proc
/mdstat
&&
129 trap cleanup
0 1 3 15
133 [ -d $logdir ] || mkdir
-p $logdir
136 if [ "$DEVTYPE" == "loop" ]
138 # make sure there are no loop devices remaining.
139 # udev started things can sometimes prevent them being stopped
141 while grep loop
/proc
/partitions
> /dev
/null
2>&1
144 losetup
-d /dev
/loop
[0-9]* 2> /dev
/null
147 elif [ "$DEVTYPE" == "disk" ]
151 for d
in $
(seq 0 ${#disks[@]})
153 eval "dev$d=${disks[$d]}"
154 eval devlist
=\"\
$devlist \
$dev$d\"
155 eval devlist
$d=\"\
$devlist\"
157 $mdadm --zero ${disks[@]} &> /dev
/null
159 echo "Forget to provide physical devices for disk mode."
163 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
166 [ $d -gt 7 ] && sz
=$ddfsize
169 [ -f $targetdir/mdtest
$d ] ||
170 dd if=/dev
/zero of
=$targetdir/mdtest
$d count
=$sz bs
=1K
> /dev
/null
2>&1
171 # make sure udev doesn't touch
172 mdadm
--zero $targetdir/mdtest
$d 2> /dev
/null
173 [ -b /dev
/loop
$d ] || mknod
/dev
/loop
$d b
7 $d
176 losetup
/dev
/loop
$d $targetdir/mdtest6
# for multipath use
178 losetup
/dev
/loop
$d $targetdir/mdtest
$d
180 eval dev
$d=/dev
/loop
$d
181 eval file$d=$targetdir/mdtest
$d
185 eval dev
$d=/dev
/mapper
/${LVM_VOLGROUP}-mdtest$d
186 if ! lvcreate
--quiet -L ${sz}K
-n mdtest
$d $LVM_VOLGROUP
188 trap '' 0 # make sure lvremove is not called
189 eval echo error creating \
$dev$d
195 eval dev
$d=/dev
/ram
$d
198 eval devlist
=\"\
$devlist \
$dev$d\"
199 eval devlist
$d=\"\
$devlist\"
200 #" <-- add this quote to un-confuse vim syntax highlighting
205 [ -f /proc
/mdstat
] || modprobe md_mod
206 echo 2000 > /proc
/sys
/dev
/raid
/speed_limit_max
207 echo 0 > /sys
/module
/md_mod
/parameters
/start_ro
210 # check various things
214 if [ $?
-eq 0 ]; then
215 die
"This command shouldn't run successfully"
219 spares
=$
(tr '] ' '\012\012' < /proc
/mdstat |
grep -c '(S)' ||
exit 0)
220 [ $spares -ne $2 ] &&
221 die
"expected $2 spares, found $spares"
224 grep -sq "active $1 " /proc
/mdstat ||
225 die
"active $1 not found"
228 grep -sq " algorithm $2 " /proc
/mdstat ||
229 die
"algorithm $2 not found"
231 resync | recovery | reshape
)
233 while ! grep -sq $1 /proc
/mdstat
235 if [ $cnt -gt 0 ] && grep -v idle
/sys
/block
/md
*/md
/sync_action
> /dev
/null
236 then # Something isn't idle - wait a bit
240 die
"no $1 happening"
246 # Since 4.2 we delay the close of recovery until there has been a chance for
247 # spares to be activated. That means that a recovery that finds nothing
248 # to do can still take a little longer than expected.
249 # add an extra check: is sync_completed shows the end is reached, assume
250 # there is no recovery.
251 if grep -sq -E '(resync|recovery|reshape) *=' /proc
/mdstat
253 incomplete
=`grep / /sys/block/md*/md/sync_completed 2> /dev/null | sed '/^ *\([0-9]*\) \/ \1/d'`
254 [ -n "$incomplete" ] &&
255 die
"resync or recovery is happening!"
259 p
=`cat /proc/sys/dev/raid/speed_limit_max`
260 echo 2000000 > /proc
/sys
/dev
/raid
/speed_limit_max
262 while grep -Eq '(resync|recovery|reshape|check|repair) *=' /proc
/mdstat ||
263 grep -v idle
> /dev
/null
/sys
/block
/md
*/md
/sync_action
267 echo $p > /proc
/sys
/dev
/raid
/speed_limit_max
270 grep -sq "blocks.*\[$2\]\$" /proc
/mdstat ||
271 die
"state $2 not found!"
275 grep -sq bitmap
/proc
/mdstat ||
279 grep -sq "bitmap" /proc
/mdstat
&&
283 grep -sq "read-only" /proc
/mdstat ||
284 die
"array is not read-only!"
287 grep -sq "inactive" /proc
/mdstat ||
288 die
"array is not inactive!"
290 # It only can be used when there is only one raid
292 chunk_size
=`awk -F',' '/chunk/{print $2}' /proc/mdstat | awk -F'[a-z]' '{print $1}'`
293 if [ "$chunk_size" -ne "$2" ] ; then
294 die
"chunksize should be $2, but it's $chunk_size"
298 die
"unknown check $1"
304 if [ -s $targetdir/stderr
]
306 echo Bad errors from mdadm
:
307 cat $targetdir/stderr
314 [ -b $1 ] || die
"$1 isn't a block device."
315 [ "$DEVTYPE" == "disk" ] && return 0
323 mkfs.ext3
-F -j $dev > /dev
/null
2>&1 && fsck
-fn $dev >&2
325 dsize
=$
[dvsize
/chunk
]
327 rasize
=$
[dsize
*2*cnt
]
328 # rasize is in sectors
329 if [ -n "$DEV_ROUND_K" ]
331 rasize
=$
[rasize
/DEV_ROUND_K
/2]
332 rasize
=$
[rasize
*DEV_ROUND_K
*2]
334 [ `/sbin/blockdev --getsize $dev` -eq 0 ] && sleep 2
335 _sz
=`/sbin/blockdev --getsize $dev`
336 [ $rasize -lt $_sz -o $
[rasize
*4/5] -gt $_sz ] &&
337 die
"size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"