blob: 3ad0147ebfe6415e4f9d44c0fe6d0155cfc7b9da (
plain)
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
|
#!/bin/sh
#
# 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]'
if [ -n "$1" ]
then prefix=$1
fi
dir=`pwd`
mdadm=$dir/mdadm
if [ \! -x $mdadm ]
then
echo >&2 "test: $mdadm isn't usable."
fi
# assume md0, md1, md2 exist in /dev
md0=/dev/md0 md1=/dev/md1 md2=/dev/md2
# We test mdadm on loop-back block devices.
# dir for storing files should be settable by command line maybe
targetdir=/var/tmp
size=20000
mdsize0=19904
mdsize1=19992
mdsize11=19996
mdsize12=19992
cleanup() {
$mdadm -Ss
for d in 0 1 2 3 4 5 6 7
do losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d
done
}
trap cleanup 0 1 2 3 15
devlist=
for d in 0 1 2 3 4 5 6 7
do
[ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$size bs=1K > /dev/null 2>&1
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\"
done
path0=$dev6
path1=$dev7
# mdadm always adds --quiet, and we want to see any unexpected messages
mdadm() {
$mdadm 2>&1 --quiet "$@"
}
# check various things
check() {
case $1 in
raid* | linear )
grep -s "active $1 " /proc/mdstat > /dev/null || {
echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
;;
resync | recovery )
sleep 0.1
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 're[synccovery]* =' > /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 're[synccovery]* =' > /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
}
# basic device test
testdev() {
dev=$1
cnt=$2
dvsize=$3
chunk=$4
mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
dsize=$[dvsize/chunk]
dsize=$[dsize*chunk]
rasize=$[dsize*1024*cnt]
if [ $rasize -ne `/sbin/blockdev --getsize64 $dev` ]
then
echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not `/sbin/blockdev --getsize64 $dev`"
exit 1
fi
}
rotest() {
dev=$1
fsck -fn $dev >&2
}
for script in tests/$prefix tests/$prefix*[^~]
do
if [ -f "$script" ]
then
# source script in a subshell, so it has access to our
# namespace, but cannot change it.
if ( set -ex ; . $script ) 2> $targetdir/log
then echo "$script succeeded"
else cat $targetdir/log
echo "$script failed"
exit 1
fi
fi
done
exit 0
|