1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
|
#!/bin/bash
#
# run test suite for mdadm
user=`id -un`
if [ " $user" != " root" ]
then echo >&2 "test: testing can only be done as 'root'."
exit 1;
fi
prefix='[0-9][0-9]'
dir=`pwd`
mdadm=$dir/mdadm
if [ \! -x $mdadm ]
then
echo >&2 "test: $mdadm isn't usable."
fi
testdir="tests"
logdir="$testdir/logs"
logsave=0
exitonerror=1
# Check whether to run multipath tests
modprobe multipath 2> /dev/null
if grep -s 'Personalities : .*multipath' > /dev/null /proc/mdstat ; then
MULTIPATH="yes"
fi
INTEGRITY=yes
# assume md0, md1, md2 exist in /dev
md0=/dev/md0 md1=/dev/md1 md2=/dev/md2
mdp0=/dev/md_d0
mdp1=/dev/md_d1
# We test mdadm on loop-back block devices.
# dir for storing files should be settable by command line maybe
targetdir=/var/tmp
size=20000
# super0, round down to multiple of 64 and substract 64
mdsize0=19904
# super00 is nested, subtract 128
mdsize00=19840
# super1.0 round down to multiple of 2, subtract 8
mdsize1=19992
mdsize1a=19988
mdsize12=19988
# super1.2 for linear: round to multiple of 2, subtract 4
mdsize1_l=19996
mdsize2_l=19996
# subtract another 4 for bitmaps
mdsize1b=19988
mdsize11=19992
mdsize11a=19456
mdsize12=19988
# ddf needs bigger devices as 32Meg is reserved!
ddfsize=65536
config=/tmp/mdadm.conf
cleanup() {
udevadm settle
$mdadm -Ssq 2> /dev/null
for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
do
losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d
rm -f /dev/disk/by-path/loop*
done
}
ctrl-c() {
exitonerror=1
}
do_setup() {
trap cleanup 0 1 3 15
trap ctrl-c 2
devlist=
for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
do
sz=$size
if [ $d -gt 7 ]; then sz=$ddfsize ; fi
[ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1
[ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
if [ $d -eq 7 ]
then
losetup /dev/loop$d $targetdir/mdtest6 # for multipath use
else
losetup /dev/loop$d $targetdir/mdtest$d
fi
eval dev$d=/dev/loop$d
eval file$d=$targetdir/mdtest$d
eval devlist=\"\$devlist \$dev$d\"
#" <-- add this quote to un-confuse vim syntax highlighting
done
path0=$dev6
path1=$dev7
ulimit -c unlimited
[ -f /proc/mdstat ] || modprobe md_mod
echo 2000 > /proc/sys/dev/raid/speed_limit_max
echo 0 > /sys/module/md_mod/parameters/start_ro
}
# mdadm always adds --quiet, and we want to see any unexpected messages
mdadm() {
rm -f $targetdir/stderr
case $* in
*-S* ) udevadm settle;;
esac
case $* in
*-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;;
* ) $mdadm 2> $targetdir/stderr --quiet "$@"
esac
rv=$?
case $* in
*-S* ) udevadm settle;;
esac
cat >&2 $targetdir/stderr
return $rv
}
# check various things
check() {
case $1 in
spares )
spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0`
if [ $spares -ne $2 ]
then
echo >&2 "ERROR expected $2 spares, found $spares"; exit 1;
fi
;;
raid* | linear )
grep -s "active $1 " /proc/mdstat > /dev/null || {
echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
;;
resync | recovery | reshape)
sleep 0.5
grep -s $1 /proc/mdstat > /dev/null || {
echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; }
;;
nosync )
sleep 0.5
if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat ; then
echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1;
fi
;;
wait )
sleep 0.1
while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat
do sleep 2;
done
;;
state )
grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || {
echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; }
sleep 0.5
;;
bitmap )
grep -s bitmap > /dev/null /proc/mdstat || {
echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; }
;;
nobitmap )
if grep -s "bitmap" > /dev/null /proc/mdstat
then
echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1;
fi
;;
* ) echo >&2 ERROR unknown check $1 ; exit 1;
esac
}
no_errors() {
if [ -s $targetdir/stderr ]
then echo Bad errors from mdadm: ; cat $targetdir/stderr; exit 2;
fi
}
# basic device test
testdev() {
udevadm settle
dev=$1
cnt=$2
dvsize=$3
chunk=$4
if [ -z "$5" ]; then
mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
fi
dsize=$[dvsize/chunk]
dsize=$[dsize*chunk]
rasize=$[dsize*2*cnt]
# rasize is in sectors
if [ -n "$DEV_ROUND_K" ]; then
rasize=$[rasize/DEV_ROUND_K/2]
rasize=$[rasize*DEV_ROUND_K*2]
fi
if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi
_sz=`/sbin/blockdev --getsize $dev`
if [ $rasize -lt $_sz -o $[rasize*4/5] -gt $_sz ]
then
echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
exit 1
fi
}
rotest() {
dev=$1
fsck -fn $dev >&2
}
do_test() {
_script=$1
_basename=`basename $_script`
if [ -f "$_script" ]
then
rm -f $targetdir/stderr
# stop all arrays, just incase some script left an array active.
$mdadm -Ssq 2> /dev/null
mdadm --zero $devlist 2> /dev/null
mdadm --zero $devlist 2> /dev/null
# source script in a subshell, so it has access to our
# namespace, but cannot change it.
echo -ne "$_script... "
if ( set -ex ; . $_script ) &> $targetdir/log
then
echo "succeeded"
_fail=0
else
log=log
if [ $exitonerror == 0 ]; then
log=log-`basename $_script`
mv $targetdir/log $targetdir/$log
fi
echo "FAILED - see $targetdir/$log for details"
_fail=1
fi
if [ "$savelogs" == "1" ]; then
cp $targetdir/log $logdir/$_basename.log
fi
if [ "$_fail" == "1" -a "$exitonerror" == "1" ]; then
exit 1
fi
fi
}
do_help() {
echo "Usage: $0 [options]"
echo " Options:"
echo " --tests=<test1,test2,..> Comma separated list of tests to run"
echo " --disable-multipath Disable any tests involving multipath"
echo " --disable-integrity Disable slow tests of RAID[56] consistency"
echo " --logdir=<directory> Directory to save logfiles in"
echo " --save-logs Save all logs in <logdir>"
echo " --keep-going Don't stop on error, ie. run all tests"
echo " setup Setup test environment and exit"
echo " cleanup Cleanup test environment"
echo " <prefix> Run tests with <prefix>"
}
parse_args() {
for i in $*
do
case $i in
[0-9]*)
prefix=$i
;;
setup)
echo "mdadm test environment setup"
do_setup
trap 0; exit 0
;;
cleanup)
cleanup
exit 0
;;
--tests=*)
TESTLIST=`expr "x$i" : 'x[^=]*=\(.*\)' | sed -e 's/,/ /g'`
;;
--logdir=*)
logdir=`expr "x$i" : 'x[^=]*=\(.*\)'`
;;
--save-logs)
savelogs=1
if [ ! -d $logdir ] ; then
mkdir $logdir
if [ $? -ne 0 ] ; then
exit 1;
fi
fi
;;
--keep-going | --no-error)
exitonerror=0
;;
--disable-multipath)
unset MULTIPATH
;;
--disable-integrity)
unset INTEGRITY
;;
--help)
do_help
exit 0;
;;
-*)
echo " $0: Unknown argument: $i"
do_help
exit 0;
;;
esac
done
}
parse_args $@
do_setup
if [ "$savelogs" == "1" ]; then
echo "Saving logs to $logdir"
fi
if [ "x$TESTLIST" != "x" ]; then
for script in $TESTLIST
do
do_test $testdir/$script
done
else
for script in $testdir/$prefix $testdir/$prefix*[^~]
do
do_test $script
done
fi
exit 0
|