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