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 "raid6check" -a -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 mdadm_src_ver
="$($mdadm -V 2>&1)"
117 mdadm_sbin_ver
="$($(which mdadm) -V 2>&1)"
118 if [ "$mdadm_src_ver" != "$mdadm_sbin_ver" ]
120 # it's nessesary to 'make install' mdadm to /SBIN/DIR,
121 # such as systemd/mdadm-grow-continue@.service, would
122 # run as an instance by systemd when reshape happens,
123 # thus ensure that the correct mdadm is in testing.
124 echo "test: please run 'make install' before testing."
127 if ! $
(df
-T . |
grep -iq ext
)
129 # 'external file' bitmap only supports with ext[2-4] file system
130 echo "test: please run test suite with ext[2-4] file system."
133 if $
(lsblk
-a |
grep -iq raid
)
135 # donot run mdadm -Ss directly if there are RAIDs working.
136 echo "test: please run test suite without running RAIDs environment."
139 # Check whether to run multipath tests
140 modprobe multipath
2> /dev
/null
141 grep -sq 'Personalities : .*multipath' /proc
/mdstat
&&
146 trap cleanup
0 1 3 15
150 [ -d $logdir ] || mkdir
-p $logdir
153 if [ "$DEVTYPE" == "loop" ]
155 # make sure there are no loop devices remaining.
156 # udev started things can sometimes prevent them being stopped
158 while grep loop
/proc
/partitions
> /dev
/null
2>&1
161 losetup
-d /dev
/loop
[0-9]* 2> /dev
/null
164 elif [ "$DEVTYPE" == "disk" ]
168 for d
in $
(seq 0 ${#disks[@]})
170 eval "dev$d=${disks[$d]}"
171 eval devlist
=\"\
$devlist \
$dev$d\"
172 eval devlist
$d=\"\
$devlist\"
174 $mdadm --zero ${disks[@]} &> /dev
/null
176 echo "Forget to provide physical devices for disk mode."
180 for d
in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
183 [ $d -gt 7 ] && sz
=$ddfsize
186 [ -f $targetdir/mdtest
$d ] ||
187 dd if=/dev
/zero of
=$targetdir/mdtest
$d count
=$sz bs
=1K
> /dev
/null
2>&1
188 # make sure udev doesn't touch
189 mdadm
--zero $targetdir/mdtest
$d 2> /dev
/null
190 [ -b /dev
/loop
$d ] || mknod
/dev
/loop
$d b
7 $d
193 losetup
/dev
/loop
$d $targetdir/mdtest6
# for multipath use
195 losetup
/dev
/loop
$d $targetdir/mdtest
$d
197 eval dev
$d=/dev
/loop
$d
198 eval file$d=$targetdir/mdtest
$d
202 eval dev
$d=/dev
/mapper
/${LVM_VOLGROUP}-mdtest$d
203 if ! lvcreate
--quiet -L ${sz}K
-n mdtest
$d $LVM_VOLGROUP
205 trap '' 0 # make sure lvremove is not called
206 eval echo error creating \
$dev$d
212 eval dev
$d=/dev
/ram
$d
215 eval devlist
=\"\
$devlist \
$dev$d\"
216 eval devlist
$d=\"\
$devlist\"
217 #" <-- add this quote to un-confuse vim syntax highlighting
222 [ -f /proc
/mdstat
] || modprobe md_mod
223 echo 2000 > /proc
/sys
/dev
/raid
/speed_limit_max
224 echo 0 > /sys
/module
/md_mod
/parameters
/start_ro
227 # check various things
231 if [ $?
-eq 0 ]; then
232 die
"This command shouldn't run successfully"
235 spares
=$
(tr '] ' '\012\012' < /proc
/mdstat |
grep -c '(S)' ||
exit 0)
236 [ $spares -ne $2 ] &&
237 die
"expected $2 spares, found $spares"
240 grep -sq "active $1 " /proc
/mdstat ||
241 die
"active $1 not found"
244 grep -sq " algorithm $2 " /proc
/mdstat ||
245 die
"algorithm $2 not found"
247 resync | recovery | reshape
)
249 while ! grep -sq $1 /proc
/mdstat
251 if [ $cnt -gt 0 ] && grep -v idle
/sys
/block
/md
*/md
/sync_action
> /dev
/null
252 then # Something isn't idle - wait a bit
256 die
"no $1 happening"
262 # Since 4.2 we delay the close of recovery until there has been a chance for
263 # spares to be activated. That means that a recovery that finds nothing
264 # to do can still take a little longer than expected.
265 # add an extra check: is sync_completed shows the end is reached, assume
266 # there is no recovery.
267 if grep -sq -E '(resync|recovery|reshape) *=' /proc
/mdstat
269 incomplete
=`grep / /sys/block/md*/md/sync_completed 2> /dev/null | sed '/^ *\([0-9]*\) \/ \1/d'`
270 [ -n "$incomplete" ] &&
271 die
"resync or recovery is happening!"
275 p
=`cat /proc/sys/dev/raid/speed_limit_max`
276 echo 2000000 > /proc
/sys
/dev
/raid
/speed_limit_max
278 while grep -Eq '(resync|recovery|reshape|check|repair) *=' /proc
/mdstat ||
279 grep -v idle
> /dev
/null
/sys
/block
/md
*/md
/sync_action
283 echo $p > /proc
/sys
/dev
/raid
/speed_limit_max
286 grep -sq "blocks.*\[$2\]\$" /proc
/mdstat ||
287 die
"state $2 not found!"
291 grep -sq bitmap
/proc
/mdstat ||
295 grep -sq "bitmap" /proc
/mdstat
&&
299 grep -sq "read-only" /proc
/mdstat ||
300 die
"array is not read-only!"
303 grep -sq "inactive" /proc
/mdstat ||
304 die
"array is not inactive!"
306 # It only can be used when there is only one raid
308 chunk_size
=`awk -F',' '/chunk/{print $2}' /proc/mdstat | awk -F'[a-z]' '{print $1}'`
309 if [ "$chunk_size" -ne "$2" ] ; then
310 die
"chunksize should be $2, but it's $chunk_size"
314 die
"unknown check $1"
320 if [ -s $targetdir/stderr
]
322 echo Bad errors from mdadm
:
323 cat $targetdir/stderr
330 [ -b $1 ] || die
"$1 isn't a block device."
331 [ "$DEVTYPE" == "disk" ] && return 0
339 mkfs.ext3
-F -j $dev > /dev
/null
2>&1 && fsck
-fn $dev >&2
341 dsize
=$
[dvsize
/chunk
]
343 rasize
=$
[dsize
*2*cnt
]
344 # rasize is in sectors
345 if [ -n "$DEV_ROUND_K" ]
347 rasize
=$
[rasize
/DEV_ROUND_K
/2]
348 rasize
=$
[rasize
*DEV_ROUND_K
*2]
350 [ `/sbin/blockdev --getsize $dev` -eq 0 ] && sleep 2
351 _sz
=`/sbin/blockdev --getsize $dev`
352 [ $rasize -lt $_sz -o $
[rasize
*4/5] -gt $_sz ] &&
353 die
"size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"