Whamcloud - gitweb
LU-904 ptlrpc: redo io on -EINPROGRESS
[fs/lustre-release.git] / lustre / tests / replay-ost-single.sh
1 #!/bin/bash
2
3 set -e
4
5 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
6 SETUP=${SETUP:-""}
7 CLEANUP=${CLEANUP:-""}
8 . $LUSTRE/tests/test-framework.sh
9 init_test_env $@
10 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
11 init_logging
12
13 # While we do not use OSTCOUNT=1 setup anymore,
14 # ost1failover_HOST is used
15 #ostfailover_HOST=${ostfailover_HOST:-$ost_HOST}
16 #failover= must be defined in OST_MKFS_OPTIONS if ostfailover_HOST != ost_HOST
17
18 require_dsh_ost || exit 0
19
20 # Tests that fail on uml
21 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
22 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 6"
23
24 # Skip these tests
25 # BUG NUMBER: 
26 ALWAYS_EXCEPT="$REPLAY_OST_SINGLE_EXCEPT"
27
28 #                                       
29 [ "$SLOW" = "no" ] && EXCEPT_SLOW="5"
30
31 build_test_filter
32
33 check_and_setup_lustre
34 assert_DIR
35 rm -rf $DIR/[df][0-9]*
36
37 TDIR=$DIR/d0.${TESTSUITE}
38 mkdir -p $TDIR
39 $LFS setstripe $TDIR -i 0 -c 1
40 $LFS getstripe $TDIR
41
42 test_0a() {
43     zconf_umount `hostname` $MOUNT -f
44     # needs to run during initial client->OST connection
45     #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
46     do_facet ost1 "lctl set_param fail_loc=0x80000211"
47     zconf_mount `hostname` $MOUNT && df $MOUNT || error "0a mount fail"
48 }
49 run_test 0a "target handle mismatch (bug 5317) `date +%H:%M:%S`"
50
51 test_0b() {
52     fail ost1
53     cp /etc/profile  $TDIR/$tfile
54     sync
55     diff /etc/profile $TDIR/$tfile
56     rm -f $TDIR/$tfile
57 }
58 run_test 0b "empty replay"
59
60 test_1() {
61     date > $TDIR/$tfile || error "error creating $TDIR/$tfile"
62     fail ost1
63     $CHECKSTAT -t file $TDIR/$tfile || return 1
64     rm -f $TDIR/$tfile
65 }
66 run_test 1 "touch"
67
68 test_2() {
69     for i in `seq 10`; do
70         echo "tag-$i" > $TDIR/$tfile-$i || error "create $TDIR/$tfile-$i"
71     done 
72     fail ost1
73     for i in `seq 10`; do
74       grep -q "tag-$i" $TDIR/$tfile-$i || error "grep $TDIR/$tfile-$i"
75     done 
76     rm -f $TDIR/$tfile-*
77 }
78 run_test 2 "|x| 10 open(O_CREAT)s"
79
80 test_3() {
81     verify=$ROOT/tmp/verify-$$
82     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile &
83     ddpid=$!
84     sync &
85     fail ost1
86     wait $ddpid || return 1
87     cmp $verify $TDIR/$tfile || return 2
88     rm -f $verify $TDIR/$tfile
89 }
90 run_test 3 "Fail OST during write, with verification"
91
92 test_4() {
93     verify=$ROOT/tmp/verify-$$
94     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile
95     # invalidate cache, so that we're reading over the wire
96     cancel_lru_locks osc
97     cmp $verify $TDIR/$tfile &
98     cmppid=$!
99     fail ost1
100     wait $cmppid || return 1
101     rm -f $verify $TDIR/$tfile
102 }
103 run_test 4 "Fail OST during read, with verification"
104
105 iozone_bg () {
106     local args=$@
107
108     local tmppipe=$TMP/${TESTSUITE}.${TESTNAME}.pipe
109     mkfifo $tmppipe
110
111     echo "+ iozone $args"
112     iozone $args > $tmppipe &
113
114     local pid=$!
115
116     echo "tmppipe=$tmppipe"
117     echo iozone pid=$pid
118
119     # iozone exit code is 0 even if iozone is not completed
120     # need to check iozone output  on "complete"
121     local iozonelog=$TMP/${TESTSUITE}.iozone.log
122     rm -f $iozonelog
123     cat $tmppipe | while read line ; do
124         echo "$line"
125         echo "$line" >>$iozonelog
126     done;
127
128     local rc=0
129     wait $pid
130     rc=$?
131     if ! $(tail -1 $iozonelog | grep -q complete); then
132         echo iozone failed!
133         rc=1
134     fi
135     rm -f $tmppipe
136     rm -f $iozonelog
137     return $rc
138 }
139
140 test_5() {
141     [ -z "`which iozone 2> /dev/null`" ] && skip_env "iozone missing" && return 0
142
143     # striping is -c 1, get min of available
144     local minavail=$(lctl get_param -n osc.*[oO][sS][cC][-_]*.kbytesavail | sort -n | head -1)
145     local size=$(( minavail * 3/4 ))
146     local GB=1048576  # 1048576KB == 1GB
147
148     if (( size > GB )); then
149         size=$GB
150     fi
151     local iozone_opts="-i 0 -i 1 -i 2 -+d -r 4 -s $size -f $TDIR/$tfile"
152
153     iozone_bg $iozone_opts &
154     local pid=$!
155
156     echo iozone bg pid=$pid
157
158     sleep 8
159     fail ost1
160     local rc=0
161     wait $pid
162     rc=$?
163     log "iozone rc=$rc"
164     rm -f $TDIR/$tfile
165     [ $rc -eq 0 ] || error "iozone failed"
166     return $rc
167 }
168 run_test 5 "Fail OST during iozone"
169
170 kbytesfree() {
171    calc_osc_kbytes kbytesfree
172 }
173
174 test_6() {
175     remote_mds_nodsh && skip "remote MDS with nodsh" && return 0
176
177     f=$TDIR/$tfile
178     rm -f $f
179     sync && sleep 2 && sync  # wait for delete thread
180
181     # wait till space is returned, following
182     # (( $before > $after_dd)) test counting on that
183     wait_mds_ost_sync || return 4
184     wait_destroy_complete || return 5
185
186     before=`kbytesfree`
187     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 28
188     lfs getstripe $f
189     stripe_index=$(lfs getstripe -i $f)
190
191     sync
192     sleep 2 # ensure we have a fresh statfs
193     sync
194
195     #define OBD_FAIL_MDS_REINT_NET_REP       0x119
196     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
197     after_dd=`kbytesfree`
198     log "before: $before after_dd: $after_dd"
199     (( $before > $after_dd )) || return 1
200     rm -f $f
201     fail ost$((stripe_index + 1))
202     wait_recovery_complete ost$((stripe_index + 1)) ||
203         error "OST$((stripe_index + 1)) recovery not completed"
204     $CHECKSTAT -t file $f && return 2 || true
205     sync
206     # let the delete happen
207     wait_mds_ost_sync || return 4
208     wait_destroy_complete || return 5
209     after=`kbytesfree`
210     log "before: $before after: $after"
211     (( $before <= $after + 40 )) || return 3   # take OST logs into account
212 }
213 run_test 6 "Fail OST before obd_destroy"
214
215 test_7() {
216     f=$TDIR/$tfile
217     rm -f $f
218     sync && sleep 5 && sync     # wait for delete thread
219
220     # wait till space is returned, following
221     # (( $before > $after_dd)) test counting on that
222     wait_mds_ost_sync || return 4
223     wait_destroy_complete || return 5
224
225     before=`kbytesfree`
226     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 4
227     sync
228     sleep 2 # ensure we have a fresh statfs
229     sync
230     after_dd=`kbytesfree`
231     log "before: $before after_dd: $after_dd"
232     (( $before > $after_dd )) || return 1
233     replay_barrier ost1
234     rm -f $f
235     fail ost1
236     wait_recovery_complete ost1 || error "OST recovery not done"
237     $CHECKSTAT -t file $f && return 2 || true
238     sync
239     # let the delete happen
240     wait_mds_ost_sync || return 4
241     wait_destroy_complete || return 5
242     after=`kbytesfree`
243     log "before: $before after: $after"
244     (( $before <= $after + 40 )) || return 3    # take OST logs into account
245 }
246 run_test 7 "Fail OST before obd_destroy"
247
248 test_8a() {
249     verify=$ROOT/tmp/verify-$$
250     dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
251         error "Create verify file failed"
252 #define OBD_FAIL_OST_DQACQ_NET           0x230
253     do_facet ost1 "lctl set_param fail_loc=0x230"
254     dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
255     ddpid=$!
256     sleep $TIMEOUT  # wait for the io to become redo io
257     if ! ps -p $ddpid  > /dev/null 2>&1; then
258             error "redo io finished incorrectly"
259             return 1
260     fi
261     do_facet ost1 "lctl set_param fail_loc=0"
262     wait $ddpid || return 1
263     cancel_lru_locks osc
264     cmp $verify $TDIR/$tfile || return 2
265     rm -f $verify $TDIR/$tfile
266 }
267 run_test 8a "Verify redo io: redo io when get -EINPROGRESS error"
268
269 test_8b() {
270     verify=$ROOT/tmp/verify-$$
271     dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
272         error "Create verify file failed"
273 #define OBD_FAIL_OST_DQACQ_NET           0x230
274     do_facet ost1 "lctl set_param fail_loc=0x230"
275     dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
276     ddpid=$!
277     sleep $TIMEOUT  # wait for the io to become redo io
278     fail ost1
279     do_facet ost1 "lctl set_param fail_loc=0"
280     wait $ddpid || return 1
281     cancel_lru_locks osc
282     cmp $verify $TDIR/$tfile || return 2
283     rm -f $verify $TDIR/$tfile
284 }
285 run_test 8b "Verify redo io: redo io should success after recovery"
286
287 test_8c() {
288     verify=$ROOT/tmp/verify-$$
289     dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
290         error "Create verify file failed"
291 #define OBD_FAIL_OST_DQACQ_NET           0x230
292     do_facet ost1 "lctl set_param fail_loc=0x230"
293     dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
294     ddpid=$!
295     sleep $TIMEOUT  # wait for the io to become redo io
296     ost_evict_client
297     # allow recovery to complete
298     sleep $((TIMEOUT + 2))
299     do_facet ost1 "lctl set_param fail_loc=0"
300     wait $ddpid
301     cancel_lru_locks osc
302     cmp $verify $TDIR/$tfile && return 2
303     rm -f $verify $TDIR/$tfile
304 }
305 run_test 8c "Verify redo io: redo io should fail after eviction"
306
307
308 complete $(basename $0) $SECONDS
309 check_and_cleanup_lustre
310 exit_status