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