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
60 echo "## $HOSTNAME: no array assembled!" >> $logdir/$logfile
67 $mdadm -Ssq 2> /dev
/null
70 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
72 losetup
-d /dev
/loop
$d &> /dev
/null
73 rm -f /dev
/disk
/by-path
/loop
*
74 rm -f /var
/tmp
/mdtest
$d
78 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
80 eval "lvremove --quiet -f \$dev$d"
84 $mdadm --zero ${disks[@]} &> /dev
/null
91 [ "X$user" != "Xroot" ] && {
92 echo "test: testing can only be done as 'root'."
95 [ -x "raid6check" -a -x $mdadm ] ||
{
96 echo "test: please run 'make everything' before perform testing."
99 cmds
=(mdadm lsblk df udevadm losetup mkfs.ext3 fsck
seq)
100 for cmd
in ${cmds[@]}
102 which $cmd > /dev
/null ||
{
103 echo "$cmd command not found!"
107 mdadm_src_ver
="$($mdadm -V 2>&1)"
108 mdadm_sbin_ver
="$($(which mdadm) -V 2>&1)"
109 if [ "$mdadm_src_ver" != "$mdadm_sbin_ver" ]
111 # it's nessesary to 'make install' mdadm to /SBIN/DIR,
112 # such as systemd/mdadm-grow-continue@.service, would
113 # run as an instance by systemd when reshape happens,
114 # thus ensure that the correct mdadm is in testing.
115 echo "test: please run 'make install' before testing."
118 if ! $
(df
-T . |
grep -iq ext
)
120 # 'external file' bitmap only supports with ext[2-4] file system
121 echo "test: please run test suite with ext[2-4] file system."
124 if $
(lsblk
-a |
grep -iq raid
)
126 # donot run mdadm -Ss directly if there are RAIDs working.
127 echo "test: please run test suite without running RAIDs environment."
130 # Check whether to run multipath tests
131 modprobe multipath
2> /dev
/null
132 grep -sq 'Personalities : .*multipath' /proc
/mdstat
&&
137 trap cleanup
0 1 3 15
141 [ -d $logdir ] || mkdir
-p $logdir
145 if [ "$DEVTYPE" == "loop" ]
147 # make sure there are no loop devices remaining.
148 # udev started things can sometimes prevent them being stopped
150 while grep loop
/proc
/partitions
> /dev
/null
2>&1
153 losetup
-d /dev
/loop
[0-9]* 2> /dev
/null
156 elif [ "$DEVTYPE" == "disk" ]
160 for d
in $
(seq 0 ${#disks[@]})
162 eval "dev$d=${disks[$d]}"
163 eval devlist
=\"\
$devlist \
$dev$d\"
164 eval devlist
$d=\"\
$devlist\"
166 $mdadm --zero ${disks[@]} &> /dev
/null
168 echo "Forget to provide physical devices for disk mode."
172 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
175 [ $d -gt 7 ] && sz
=$ddfsize
178 [ -f $targetdir/mdtest
$d ] ||
179 dd if=/dev
/zero of
=$targetdir/mdtest
$d count
=$sz bs
=1K
> /dev
/null
2>&1
180 # make sure udev doesn't touch
181 mdadm
--zero $targetdir/mdtest
$d 2> /dev
/null
182 [ -b /dev
/loop
$d ] || mknod
/dev
/loop
$d b
7 $d
185 losetup
/dev
/loop
$d $targetdir/mdtest6
# for multipath use
187 losetup
/dev
/loop
$d $targetdir/mdtest
$d
189 eval dev
$d=/dev
/loop
$d
190 eval file$d=$targetdir/mdtest
$d
194 eval dev
$d=/dev
/mapper
/${LVM_VOLGROUP}-mdtest$d
195 if ! lvcreate
--quiet -L ${sz}K
-n mdtest
$d $LVM_VOLGROUP
197 trap '' 0 # make sure lvremove is not called
198 eval echo error creating \
$dev$d
204 eval dev
$d=/dev
/ram
$d
207 eval devlist
=\"\
$devlist \
$dev$d\"
208 eval devlist
$d=\"\
$devlist\"
209 #" <-- add this quote to un-confuse vim syntax highlighting
214 [ -f /proc
/mdstat
] || modprobe md_mod
215 echo 2000 > /proc
/sys
/dev
/raid
/speed_limit_max
216 echo 0 > /sys
/module
/md_mod
/parameters
/start_ro
219 # check various things
223 if [ $?
-eq 0 ]; then
224 die
"This command shouldn't run successfully"
227 spares
=$
(tr '] ' '\012\012' < /proc
/mdstat |
grep -c '(S)' ||
exit 0)
228 [ $spares -ne $2 ] &&
229 die
"expected $2 spares, found $spares"
232 grep -sq "active $1 " /proc
/mdstat ||
233 die
"active $1 not found"
236 grep -sq " algorithm $2 " /proc
/mdstat ||
237 die
"algorithm $2 not found"
239 resync | recovery | reshape
)
241 while ! grep -sq $1 /proc
/mdstat
243 if [ $cnt -gt 0 ] && grep -v idle
/sys
/block
/md
*/md
/sync_action
> /dev
/null
244 then # Something isn't idle - wait a bit
248 die
"no $1 happening"
254 # Since 4.2 we delay the close of recovery until there has been a chance for
255 # spares to be activated. That means that a recovery that finds nothing
256 # to do can still take a little longer than expected.
257 # add an extra check: is sync_completed shows the end is reached, assume
258 # there is no recovery.
259 if grep -sq -E '(resync|recovery|reshape) *=' /proc
/mdstat
261 incomplete
=`grep / /sys/block/md*/md/sync_completed 2> /dev/null | sed '/^ *\([0-9]*\) \/ \1/d'`
262 [ -n "$incomplete" ] &&
263 die
"resync or recovery is happening!"
267 p
=`cat /proc/sys/dev/raid/speed_limit_max`
268 echo 2000000 > /proc
/sys
/dev
/raid
/speed_limit_max
270 while grep -Eq '(resync|recovery|reshape|check|repair) *=' /proc
/mdstat ||
271 grep -v idle
> /dev
/null
/sys
/block
/md
*/md
/sync_action
275 echo $p > /proc
/sys
/dev
/raid
/speed_limit_max
278 grep -sq "blocks.*\[$2\]\$" /proc
/mdstat ||
279 die
"state $2 not found!"
283 grep -sq bitmap
/proc
/mdstat ||
287 grep -sq "bitmap" /proc
/mdstat
&&
291 grep -sq "read-only" /proc
/mdstat ||
292 die
"array is not read-only!"
295 grep -sq "inactive" /proc
/mdstat ||
296 die
"array is not inactive!"
298 # It only can be used when there is only one raid
300 chunk_size
=`awk -F',' '/chunk/{print $2}' /proc/mdstat | awk -F'[a-z]' '{print $1}'`
301 if [ "$chunk_size" -ne "$2" ] ; then
302 die
"chunksize should be $2, but it's $chunk_size"
306 die
"unknown check $1"
312 if [ -s $targetdir/stderr
]
314 echo Bad errors from mdadm
:
315 cat $targetdir/stderr
322 [ -b $1 ] || die
"$1 isn't a block device."
323 [ "$DEVTYPE" == "disk" ] && return 0
331 mkfs.ext3
-F -j $dev > /dev
/null
2>&1 && fsck
-fn $dev >&2
333 dsize
=$
[dvsize
/chunk
]
335 rasize
=$
[dsize
*2*cnt
]
336 # rasize is in sectors
337 if [ -n "$DEV_ROUND_K" ]
339 rasize
=$
[rasize
/DEV_ROUND_K
/2]
340 rasize
=$
[rasize
*DEV_ROUND_K
*2]
342 [ `/sbin/blockdev --getsize $dev` -eq 0 ] && sleep 2
343 _sz
=`/sbin/blockdev --getsize $dev`
344 [ $rasize -lt $_sz -o $
[rasize
*4/5] -gt $_sz ] &&
345 die
"size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"