]>
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 | # subtract another 4 for bitmaps | |
38 | mdsize1b=19988 | |
39 | mdsize11=19992 | |
40 | mdsize12=19988 | |
41 | ||
42 | cleanup() { | |
43 | $mdadm -Ss | |
44 | for d in 0 1 2 3 4 5 6 7 | |
45 | do | |
46 | losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d | |
47 | done | |
48 | } | |
49 | ||
50 | trap cleanup 0 1 2 3 15 | |
51 | ||
52 | devlist= | |
53 | for d in 0 1 2 3 4 5 6 7 | |
54 | do | |
55 | [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$size bs=1K > /dev/null 2>&1 | |
56 | [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d | |
57 | if [ $d -eq 7 ] | |
58 | then | |
59 | losetup /dev/loop$d $targetdir/mdtest6 # for multipath use | |
60 | else | |
61 | losetup /dev/loop$d $targetdir/mdtest$d | |
62 | fi | |
63 | eval dev$d=/dev/loop$d | |
64 | eval file$d=$targetdir/mdtest$d | |
65 | eval devlist=\"\$devlist \$dev$d\" | |
66 | done | |
67 | path0=$dev6 | |
68 | path1=$dev7 | |
69 | ||
70 | echo 2000 > /proc/sys/dev/raid/speed_limit_max | |
71 | echo 0 > /sys/module/md_mod/parameters/start_ro | |
72 | ||
73 | if [ " $1" = " setup" ] | |
74 | then trap 0 ; exit 0 | |
75 | fi | |
76 | ||
77 | # mdadm always adds --quiet, and we want to see any unexpected messages | |
78 | mdadm() { | |
79 | rm -f $targetdir/stderr | |
80 | case $* in | |
81 | *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;; | |
82 | * ) $mdadm 2> $targetdir/stderr --quiet "$@" | |
83 | esac | |
84 | cat >&2 $targetdir/stderr | |
85 | } | |
86 | ||
87 | # check various things | |
88 | check() { | |
89 | case $1 in | |
90 | spares ) | |
91 | spares=`tr '] ' '\012\012' < /proc/mdstat | grep -c '(S)' || exit 0` | |
92 | if [ $spares -ne $2 ] | |
93 | then | |
94 | echo >&2 "ERROR expected $2 spares, found $spares"; exit 1; | |
95 | fi | |
96 | ;; | |
97 | raid* | linear ) | |
98 | grep -s "active $1 " /proc/mdstat > /dev/null || { | |
99 | echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;} | |
100 | ;; | |
101 | resync | recovery | reshape) | |
102 | sleep 0.5 | |
103 | grep -s $1 /proc/mdstat > /dev/null || { | |
104 | echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; } | |
105 | ;; | |
106 | ||
107 | nosync ) | |
108 | sleep 0.5 | |
109 | if grep -s -E '(resync|recovery|reshape) =' > /dev/null /proc/mdstat ; then | |
110 | echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1; | |
111 | fi | |
112 | ;; | |
113 | ||
114 | wait ) | |
115 | sleep 0.1 | |
116 | while grep -E '(resync|recovery|reshape|check|repair) =' > /dev/null /proc/mdstat | |
117 | do sleep 2; | |
118 | done | |
119 | ;; | |
120 | ||
121 | state ) | |
122 | grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || { | |
123 | echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; } | |
124 | sleep 0.5 | |
125 | ;; | |
126 | ||
127 | bitmap ) | |
128 | grep -s bitmap > /dev/null /proc/mdstat || { | |
129 | echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; } | |
130 | ;; | |
131 | nobitmap ) | |
132 | if grep -s "bitmap" > /dev/null /proc/mdstat | |
133 | then | |
134 | echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1; | |
135 | fi | |
136 | ;; | |
137 | ||
138 | * ) echo >&2 ERROR unknown check $1 ; exit 1; | |
139 | esac | |
140 | } | |
141 | ||
142 | no_errors() { | |
143 | if [ -s $targetdir/stderr ] | |
144 | then echo Bad errors from mdadm: ; cat $targetdir/stderr; exit 2; | |
145 | fi | |
146 | } | |
147 | # basic device test | |
148 | ||
149 | testdev() { | |
150 | dev=$1 | |
151 | cnt=$2 | |
152 | dvsize=$3 | |
153 | chunk=$4 | |
154 | mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2 | |
155 | dsize=$[dvsize/chunk] | |
156 | dsize=$[dsize*chunk] | |
157 | rasize=$[dsize*2*cnt] | |
158 | if [ $rasize -ne `/sbin/blockdev --getsize $dev` ] | |
159 | then | |
160 | echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not `/sbin/blockdev --getsize $dev`" | |
161 | exit 1 | |
162 | fi | |
163 | } | |
164 | ||
165 | rotest() { | |
166 | dev=$1 | |
167 | fsck -fn $dev >&2 | |
168 | } | |
169 | ||
170 | ||
171 | ||
172 | for script in tests/$prefix tests/$prefix*[^~] | |
173 | do | |
174 | if [ -f "$script" ] | |
175 | then | |
176 | rm -f $targetdir/stderr | |
177 | # stop all arrays, just incase some script left an array active. | |
178 | mdadm -Ssq | |
179 | # source script in a subshell, so it has access to our | |
180 | # namespace, but cannot change it. | |
181 | if ( set -ex ; . $script ) 2> $targetdir/log | |
182 | then echo "$script succeeded" | |
183 | else cat $targetdir/log ; cat $targetdir/stderr | |
184 | echo "$script failed" | |
185 | exit 1 | |
186 | fi | |
187 | fi | |
188 | done | |
189 | exit 0 |