Whamcloud - gitweb
b=11564
[fs/lustre-release.git] / lustre / tests / replay-ost-single.sh
1 #!/bin/bash
2
3 set -e
4
5 PTLDEBUG=${PTLDEBUG:--1}
6 LUSTRE=${LUSTRE:-`dirname $0`/..}
7 . $LUSTRE/tests/test-framework.sh
8 init_test_env $@
9 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
10
11 ostfailover_HOST=${ostfailover_HOST:-$ost_HOST}
12 #failover= must be defined in OST_MKFS_OPTIONS if ostfailover_HOST != ost_HOST
13
14 # Tests that fail on uml
15 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
16 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 6"
17
18 # Skip these tests
19 # BUG NUMBER: 
20 ALWAYS_EXCEPT="$REPLAY_OST_SINGLE_EXCEPT"
21
22 # It is replay-ost-single, after all
23 OSTCOUNT=1
24
25 gen_config() {
26     formatall
27 }
28
29 cleanup() {
30     cleanupall
31 }
32
33 if [ "$ONLY" == "cleanup" ]; then
34     cleanup
35     exit
36 fi
37
38 build_test_filter
39
40 SETUP=${SETUP:-"setup"}
41 CLEANUP=${CLEANUP:-"cleanup"}
42
43 test_0a() {
44     # needs to run during initial client->OST connection
45     #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
46     do_facet ost "sysctl -w lustre.fail_loc=0x80000211"
47     zconf_mount `hostname` $MOUNT && df $MOUNT || error "0a mount fail"
48 }
49
50 setup() {
51     gen_config
52     start mds $MDSDEV $MDS_MOUNT_OPTS
53     start ost1 `ostdevname 1` $OST_MOUNT_OPTS
54     [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
55
56     # this might not mount if we aren't running test 0a
57     [ -z "`grep " $MOUNT " /proc/mounts`" ] && \
58         run_test 0a "target handle mismatch (bug 5317) `date +%H:%M:%S`" 
59
60     if [ -z "`grep " $MOUNT " /proc/mounts`" ]; then
61         zconf_mount `hostname` $MOUNT || error "mount fail"
62     fi
63
64     do_facet ost1 "sysctl -w lustre.fail_loc=0"
65 }
66
67 mkdir -p $DIR
68
69 $SETUP
70
71 test_0b() {
72     fail ost1
73     cp /etc/profile  $DIR/$tfile
74     sync
75     diff /etc/profile $DIR/$tfile
76     rm -f $DIR/$tfile
77 }
78 run_test 0b "empty replay"
79
80 test_1() {
81     date > $DIR/$tfile
82     fail ost1
83     $CHECKSTAT -t file $DIR/$tfile || return 1
84     rm -f $DIR/$tfile
85 }
86 run_test 1 "touch"
87
88 test_2() {
89     for i in `seq 10`; do
90         echo "tag-$i" > $DIR/$tfile-$i
91     done 
92     fail ost1
93     for i in `seq 10`; do
94       grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
95     done 
96     rm -f $DIR/$tfile-*
97 }
98 run_test 2 "|x| 10 open(O_CREAT)s"
99
100 test_3() {
101     verify=$ROOT/tmp/verify-$$
102     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $DIR/$tfile &
103     ddpid=$!
104     sync &
105     fail ost1
106     wait $ddpid || return 1
107     cmp $verify $DIR/$tfile || return 2
108     rm -f $verify $DIR/$tfile
109 }
110 run_test 3 "Fail OST during write, with verification"
111
112 test_4() {
113     verify=$ROOT/tmp/verify-$$
114     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $DIR/$tfile
115     # invalidate cache, so that we're reading over the wire
116     for i in /proc/fs/lustre/ldlm/namespaces/*-osc-*; do
117         echo -n clear > $i/lru_size
118     done
119     cmp $verify $DIR/$tfile &
120     cmppid=$!
121     fail ost1
122     wait $cmppid || return 1
123     rm -f $verify $DIR/$tfile
124 }
125 run_test 4 "Fail OST during read, with verification"
126
127 test_5() {
128     [ -z "`which iozone 2> /dev/null`" ] && log "iozone missing" && return
129     FREE=`df -P -h $DIR | tail -n 1 | awk '{ print $3 }'`
130     case $FREE in
131     *T|*G) FREE=1G;;
132     esac
133     IOZONE_OPTS="-i 0 -i 1 -i 2 -+d -r 4 -s $FREE"
134     iozone $IOZONE_OPTS -f $DIR/$tfile &
135     PID=$!
136     
137     sleep 8
138     fail ost1
139     wait $PID
140     RC=$?
141     log "iozone rc=$RC"
142     rm -f $DIR/$tfile
143     [ $RC -ne 0 ] && return $RC || true
144 }
145 run_test 5 "Fail OST during iozone"
146
147 kbytesfree() {
148    awk '{total+=$1} END {print total}' /proc/fs/lustre/osc/*-osc-*/kbytesfree
149 }
150
151 test_6() {
152     f=$DIR/$tfile
153     rm -f $f
154     sync && sleep 2 && sync     # wait for delete thread
155     before=`kbytesfree`
156     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 28
157     lfs getstripe $f
158 #define OBD_FAIL_MDS_REINT_NET_REP       0x119
159     do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
160     sync
161     sleep 1                                     # ensure we have a fresh statfs
162     sync
163     after_dd=`kbytesfree`
164     log "before: $before after_dd: $after_dd"
165     (( $before > $after_dd )) || return 1
166     rm -f $f
167     fail ost1
168     $CHECKSTAT -t file $f && return 2 || true
169     sync
170     # let the delete happen
171     sleep 5
172     after=`kbytesfree`
173     log "before: $before after: $after"
174     (( $before <= $after + 40 )) || return 3    # take OST logs into account
175 }
176 run_test 6 "Fail OST before obd_destroy"
177
178 test_7() {
179     f=$DIR/$tfile
180     rm -f $f
181     sync && sleep 2 && sync     # wait for delete thread
182     before=`kbytesfree`
183     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 4
184     sync
185     sleep 1                                     # ensure we have a fresh statfs
186     after_dd=`kbytesfree`
187     log "before: $before after_dd: $after_dd"
188     (( $before > $after_dd )) || return 1
189     replay_barrier ost1
190     rm -f $f
191     fail ost1
192     $CHECKSTAT -t file $f && return 2 || true
193     sync
194     # let the delete happen
195     sleep 2
196     after=`kbytesfree`
197     log "before: $before after: $after"
198     (( $before <= $after + 40 )) || return 3    # take OST logs into account
199 }
200 run_test 7 "Fail OST before obd_destroy"
201
202 equals_msg test complete, cleaning up
203 $CLEANUP
204 echo "$0: completed"
205