]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
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 | if [ -n "$1" ] | |
12 | then prefix=$1 | |
13 | fi | |
14 | ||
15 | dir=`pwd` | |
16 | mdadm=$dir/mdadm | |
17 | if [ \! -x $mdadm ] | |
18 | then | |
19 | echo >&2 "test: $mdadm isn't usable." | |
20 | fi | |
21 | ||
22 | # assume md0, md1, md2 exist in /dev | |
23 | md0=/dev/md0 md1=/dev/md1 md2=/dev/md2 | |
24 | mdp0=/dev/md_d0 | |
25 | mdp1=/dev/md_d1 | |
26 | ||
27 | # We test mdadm on loop-back block devices. | |
28 | # dir for storing files should be settable by command line maybe | |
29 | targetdir=/var/tmp | |
30 | size=20000 | |
31 | # super0, round down to multiple of 64 and substract 64 | |
32 | mdsize0=19904 | |
33 | # super00 is nested, subtract 128 | |
34 | mdsize00=19840 | |
35 | # super1.0 round down to multiple of 2, subtract 8 | |
36 | mdsize1=19992 | |
37 | mdsize1a=19988 | |
38 | mdsize12=19988 | |
39 | # super1.2 for linear: round to multiple of 2, subtract 4 | |
40 | mdsize1_l=18976 | |
41 | mdsize2_l=18976 | |
42 | # subtract another 4 for bitmaps | |
43 | mdsize1b=19988 | |
44 | mdsize11=19992 | |
45 | mdsize11a=18944 | |
46 | mdsize12=19988 | |
47 | ||
48 | # ddf needs bigger devices as 32Meg is reserved! | |
49 | ddfsize=65536 | |
50 | ||
51 | cleanup() { | |
52 | udevadm settle | |
53 | $mdadm -Ssq 2> /dev/null | |
54 | for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 | |
55 | do | |
56 | losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d | |
57 | rm -f /dev/disk/by-path/loop* | |
58 | done | |
59 | } | |
60 | ||
61 | trap cleanup 0 1 2 3 15 | |
62 | ||
63 | devlist= | |
64 | for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 | |
65 | do | |
66 | sz=$size | |
67 | if [ $d -gt 7 ]; then sz=$ddfsize ; fi | |
68 | [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1 | |
69 | [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d | |
70 | if [ $d -eq 7 ] | |
71 | then | |
72 | losetup /dev/loop$d $targetdir/mdtest6 # for multipath use | |
73 | else | |
74 | losetup /dev/loop$d $targetdir/mdtest$d | |
75 | fi | |
76 | eval dev$d=/dev/loop$d | |
77 | eval file$d=$targetdir/mdtest$d | |
78 | eval devlist=\"\$devlist \$dev$d\" | |
79 | #" <-- add this quote to un-confuse vim syntax highlighting | |
80 | done | |
81 | path0=$dev6 | |
82 | path1=$dev7 | |
83 | ||
84 | ulimit -c unlimited | |
85 | [ -f /proc/mdstat ] || modprobe md_mod | |
86 | echo 2000 > /proc/sys/dev/raid/speed_limit_max | |
87 | echo 0 > /sys/module/md_mod/parameters/start_ro | |
88 | ||
89 | if [ " $1" = " setup" ] | |
90 | then trap 0 ; exit 0 | |
91 | fi | |
92 | ||
93 | # mdadm always adds --quiet, and we want to see any unexpected messages | |
94 | mdadm() { | |
95 | rm -f $targetdir/stderr | |
96 | case $* in | |
97 | *-S* ) udevadm settle;; | |
98 | esac | |
99 | case $* in | |
100 | *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;; | |
101 | * ) $mdadm 2> $targetdir/stderr --quiet "$@" | |
102 | esac | |
103 | rv=$? | |
104 | cat >&2 $targetdir/stderr | |
105 | return $rv | |
106 | } | |
107 | ||
108 | # check various things | |
109 | check() { | |
110 | case $1 in | |
111 | spares ) | |
112 | spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0` | |
113 | if [ $spares -ne $2 ] | |
114 | then | |
115 | echo >&2 "ERROR expected $2 spares, found $spares"; exit 1; | |
116 | fi | |
117 | ;; | |
118 | raid* | linear ) | |
119 | grep -s "active $1 " /proc/mdstat > /dev/null || { | |
120 | echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;} | |
121 | ;; | |
122 | resync | recovery | reshape) | |
123 | sleep 0.5 | |
124 | grep -s $1 /proc/mdstat > /dev/null || { | |
125 | echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; } | |
126 | ;; | |
127 | ||
128 | nosync ) | |
129 | sleep 0.5 | |
130 | if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat ; then | |
131 | echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1; | |
132 | fi | |
133 | ;; | |
134 | ||
135 | wait ) | |
136 | sleep 0.1 | |
137 | while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat | |
138 | do sleep 2; | |
139 | done | |
140 | ;; | |
141 | ||
142 | state ) | |
143 | grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || { | |
144 | echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; } | |
145 | sleep 0.5 | |
146 | ;; | |
147 | ||
148 | bitmap ) | |
149 | grep -s bitmap > /dev/null /proc/mdstat || { | |
150 | echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; } | |
151 | ;; | |
152 | nobitmap ) | |
153 | if grep -s "bitmap" > /dev/null /proc/mdstat | |
154 | then | |
155 | echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1; | |
156 | fi | |
157 | ;; | |
158 | ||
159 | * ) echo >&2 ERROR unknown check $1 ; exit 1; | |
160 | esac | |
161 | } | |
162 | ||
163 | no_errors() { | |
164 | if [ -s $targetdir/stderr ] | |
165 | then echo Bad errors from mdadm: ; cat $targetdir/stderr; exit 2; | |
166 | fi | |
167 | } | |
168 | # basic device test | |
169 | ||
170 | testdev() { | |
171 | udevadm settle | |
172 | dev=$1 | |
173 | cnt=$2 | |
174 | dvsize=$3 | |
175 | chunk=$4 | |
176 | if [ -z "$5" ]; then | |
177 | mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2 | |
178 | fi | |
179 | dsize=$[dvsize/chunk] | |
180 | dsize=$[dsize*chunk] | |
181 | rasize=$[dsize*2*cnt] | |
182 | # rasize is in sectors | |
183 | if [ -n "$DEV_ROUND_K" ]; then | |
184 | rasize=$[rasize/DEV_ROUND_K/2] | |
185 | rasize=$[rasize*DEV_ROUND_K*2] | |
186 | fi | |
187 | if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi | |
188 | if [ $rasize -ne `/sbin/blockdev --getsize $dev` ] | |
189 | then | |
190 | echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not `/sbin/blockdev --getsize $dev`" | |
191 | exit 1 | |
192 | fi | |
193 | } | |
194 | ||
195 | rotest() { | |
196 | dev=$1 | |
197 | fsck -fn $dev >&2 | |
198 | } | |
199 | ||
200 | for script in tests/$prefix tests/$prefix*[^~] | |
201 | do | |
202 | if [ -f "$script" ] | |
203 | then | |
204 | rm -f $targetdir/stderr | |
205 | # stop all arrays, just incase some script left an array active. | |
206 | $mdadm -Ssq 2> /dev/null | |
207 | mdadm --zero $devlist 2> /dev/null | |
208 | mdadm --zero $devlist 2> /dev/null | |
209 | # source script in a subshell, so it has access to our | |
210 | # namespace, but cannot change it. | |
211 | echo -ne "$script... " | |
212 | if ( set -ex ; . $script ) 2> $targetdir/log | |
213 | then echo "succeeded" | |
214 | else echo "FAILED - see $targetdir/log for details" | |
215 | exit 1 | |
216 | fi | |
217 | fi | |
218 | done | |
219 | exit 0 |