Whamcloud - gitweb
b=13726
[fs/lustre-release.git] / lustre / tests / recovery-small.sh
1 #!/bin/bash
2
3 set -e
4
5 #         bug  5493
6 ALWAYS_EXCEPT="52 $RECOVERY_SMALL_EXCEPT"
7
8 # also long tests: 19, 21a, 21e, 21f, 23, 27                            
9 #                                     1     2.5    4    4          (min)"  
10 [ "$SLOW" = "no" ] && EXCEPT_SLOW="17    26b    50   51     57" 
11
12 #PTLDEBUG=${PTLDEBUG:--1}
13 LUSTRE=${LUSTRE:-`dirname $0`/..}
14 . $LUSTRE/tests/test-framework.sh
15 init_test_env $@
16 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
17
18 build_test_filter
19
20 # Allow us to override the setup if we already have a mounted system by
21 # setting SETUP=" " and CLEANUP=" "
22 SETUP=${SETUP:-""}
23 CLEANUP=${CLEANUP:-""}
24
25 cleanup_and_setup_lustre
26 rm -rf $DIR/[df][0-9]*
27
28 test_1() {
29     drop_request "mcreate $MOUNT/1"  || return 1
30     drop_reint_reply "mcreate $MOUNT/2"    || return 2
31 }
32 run_test 1 "mcreate: drop req, drop rep"
33
34 test_2() {
35     drop_request "tchmod 111 $MOUNT/2"  || return 1
36     drop_reint_reply "tchmod 666 $MOUNT/2"    || return 2
37 }
38 run_test 2 "chmod: drop req, drop rep"
39
40 test_3() {
41     drop_request "statone $MOUNT/2" || return 1
42     drop_reply "statone $MOUNT/2"   || return 2
43 }
44 run_test 3 "stat: drop req, drop rep"
45
46 SAMPLE_NAME=recovery-small.junk
47 SAMPLE_FILE=$TMP/$SAMPLE_NAME
48 # make this big, else test 9 doesn't wait for bulk -- bz 5595
49 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=4
50
51 test_4() {
52     do_facet client "cp $SAMPLE_FILE $MOUNT/$SAMPLE_NAME" || return 1
53     drop_request "cat $MOUNT/$SAMPLE_NAME > /dev/null"   || return 2
54     drop_reply "cat $MOUNT/$SAMPLE_NAME > /dev/null"     || return 3
55 }
56 run_test 4 "open: drop req, drop rep"
57
58 test_5() {
59     drop_request "mv $MOUNT/$SAMPLE_NAME $MOUNT/renamed" || return 1
60     drop_reint_reply "mv $MOUNT/renamed $MOUNT/renamed-again" || return 2
61     do_facet client "checkstat -v $MOUNT/renamed-again"  || return 3
62 }
63 run_test 5 "rename: drop req, drop rep"
64
65 [ ! -e $MOUNT/renamed-again ] && cp $SAMPLE_FILE $MOUNT/renamed-again
66 test_6() {
67     drop_request "mlink $MOUNT/renamed-again $MOUNT/link1" || return 1
68     drop_reint_reply "mlink $MOUNT/renamed-again $MOUNT/link2"   || return 2
69 }
70 run_test 6 "link: drop req, drop rep"
71
72 [ ! -e $MOUNT/link1 ] && mlink $MOUNT/renamed-again $MOUNT/link1
73 [ ! -e $MOUNT/link2 ] && mlink $MOUNT/renamed-again $MOUNT/link2
74 test_7() {
75     drop_request "munlink $MOUNT/link1"   || return 1
76     drop_reint_reply "munlink $MOUNT/link2"     || return 2
77 }
78 run_test 7 "unlink: drop req, drop rep"
79
80 #bug 1423
81 test_8() {
82     drop_reint_reply "touch $MOUNT/$tfile"    || return 1
83 }
84 run_test 8 "touch: drop rep (bug 1423)"
85
86 SAMPLE_FILE=$TMP/recovery-small.junk
87 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=4
88
89 #bug 1420
90 test_9() {
91     pause_bulk "cp /etc/profile $MOUNT/$tfile"       || return 1
92     do_facet client "cp $SAMPLE_FILE $MOUNT/${tfile}.2"  || return 2
93     do_facet client "sync"
94     do_facet client "rm $MOUNT/$tfile $MOUNT/${tfile}.2" || return 3
95 }
96 run_test 9 "pause bulk on OST (bug 1420)"
97
98 #bug 1521
99 test_10() {
100     do_facet client mcreate $MOUNT/$tfile        || return 1
101     drop_bl_callback "chmod 0777 $MOUNT/$tfile"  || echo "evicted as expected"
102     # wait for the mds to evict the client
103     #echo "sleep $(($TIMEOUT*2))"
104     #sleep $(($TIMEOUT*2))
105     do_facet client touch $MOUNT/$tfile || echo "touch failed, evicted"
106     do_facet client checkstat -v -p 0777 $MOUNT/$tfile  || return 3
107     do_facet client "munlink $MOUNT/$tfile"
108 }
109 run_test 10 "finish request on server after client eviction (bug 1521)"
110
111 #bug 2460
112 # wake up a thread waiting for completion after eviction
113 test_11(){
114     do_facet client multiop $MOUNT/$tfile Ow  || return 1
115     do_facet client multiop $MOUNT/$tfile or  || return 2
116
117     cancel_lru_locks osc
118
119     do_facet client multiop $MOUNT/$tfile or  || return 3
120     drop_bl_callback multiop $MOUNT/$tfile Ow || echo "evicted as expected"
121
122     do_facet client munlink $MOUNT/$tfile  || return 4
123 }
124 run_test 11 "wake up a thread waiting for completion after eviction (b=2460)"
125
126 #b=2494
127 test_12(){
128     $LCTL mark multiop $MOUNT/$tfile OS_c 
129     do_facet mds "sysctl -w lustre.fail_loc=0x115"
130     clear_failloc mds $((TIMEOUT * 2)) &
131     multiop $MOUNT/$tfile OS_c  &
132     PID=$!
133 #define OBD_FAIL_MDS_CLOSE_NET           0x115
134     sleep 2
135     kill -USR1 $PID
136     echo "waiting for multiop $PID"
137     wait $PID || return 2
138     do_facet client munlink $MOUNT/$tfile  || return 3
139 }
140 run_test 12 "recover from timed out resend in ptlrpcd (b=2494)"
141
142 # Bug 113, check that readdir lost recv timeout works.
143 test_13() {
144     mkdir $MOUNT/readdir || return 1
145     touch $MOUNT/readdir/newentry || return
146 # OBD_FAIL_MDS_READPAGE_NET|OBD_FAIL_ONCE
147     do_facet mds "sysctl -w lustre.fail_loc=0x80000104"
148     ls $MOUNT/readdir || return 3
149     do_facet mds "sysctl -w lustre.fail_loc=0"
150     rm -rf $MOUNT/readdir || return 4
151 }
152 run_test 13 "mdc_readpage restart test (bug 1138)"
153
154 # Bug 113, check that readdir lost send timeout works.
155 test_14() {
156     mkdir $MOUNT/readdir
157     touch $MOUNT/readdir/newentry
158 # OBD_FAIL_MDS_SENDPAGE|OBD_FAIL_ONCE
159     do_facet mds "sysctl -w lustre.fail_loc=0x80000106"
160     ls $MOUNT/readdir || return 1
161     do_facet mds "sysctl -w lustre.fail_loc=0"
162 }
163 run_test 14 "mdc_readpage resend test (bug 1138)"
164
165 test_15() {
166     do_facet mds "sysctl -w lustre.fail_loc=0x80000128"
167     touch $DIR/$tfile && return 1
168     return 0
169 }
170 run_test 15 "failed open (-ENOMEM)"
171
172 READ_AHEAD=`cat $LPROC/llite/*/max_read_ahead_mb | head -n 1`
173 stop_read_ahead() {
174    for f in $LPROC/llite/*/max_read_ahead_mb; do 
175       echo 0 > $f
176    done
177 }
178
179 start_read_ahead() {
180    for f in $LPROC/llite/*/max_read_ahead_mb; do 
181       echo $READ_AHEAD > $f
182    done
183 }
184
185 test_16() {
186     do_facet client cp $SAMPLE_FILE $MOUNT
187     sync
188     stop_read_ahead
189
190 #define OBD_FAIL_PTLRPC_BULK_PUT_NET 0x504 | OBD_FAIL_ONCE
191     do_facet ost1 sysctl -w lustre.fail_loc=0x80000504
192     cancel_lru_locks osc
193     # OST bulk will time out here, client resends
194     do_facet client "cmp $SAMPLE_FILE $MOUNT/${SAMPLE_FILE##*/}" || return 1
195     do_facet ost1 sysctl -w lustre.fail_loc=0
196     # give recovery a chance to finish (shouldn't take long)
197     sleep $TIMEOUT
198     do_facet client "cmp $SAMPLE_FILE $MOUNT/${SAMPLE_FILE##*/}" || return 2
199     start_read_ahead
200 }
201 run_test 16 "timeout bulk put, don't evict client (2732)"
202
203 test_17() {
204     # With adaptive timeouts, bulk_get won't expire until adaptive_timeout_max
205     local at_max=$(do_facet ost1 "find /sys/ -name at_max")
206     [ -z "$at_max" ] && skip "missing /sys/.../at_max" && return 0
207     OST_AT_MAX=$(do_facet ost1 "cat $at_max")
208     do_facet ost1 "echo $TIMEOUT >> $at_max"
209
210     # OBD_FAIL_PTLRPC_BULK_GET_NET 0x0503 | OBD_FAIL_ONCE
211     # OST bulk will time out here, client retries
212     do_facet ost1 sysctl -w lustre.fail_loc=0x80000503
213     # need to ensure we send an RPC
214     do_facet client cp $SAMPLE_FILE $DIR/$tfile
215     sync
216
217     # with AT, client will wait adaptive_max*factor+net_latency before
218     # expiring the req, hopefully timeout*2 is enough
219     sleep $(($TIMEOUT*2))
220
221     do_facet ost1 sysctl -w lustre.fail_loc=0
222     do_facet client "df $DIR"
223     # expect cmp to succeed, client resent bulk
224     do_facet client "cmp $SAMPLE_FILE $DIR/$tfile" || return 3
225     do_facet client "rm $DIR/$tfile" || return 4
226     do_facet ost1 "echo $OST_AT_MAX >> $at_max"
227     return 0
228 }
229 run_test 17 "timeout bulk get, don't evict client (2732)"
230
231 test_18a() {
232     [ -z ${ost2_svc} ] && skip "needs 2 osts" && return 0
233
234     do_facet client mkdir -p $MOUNT/$tdir
235     f=$MOUNT/$tdir/$tfile
236
237     cancel_lru_locks osc
238     pgcache_empty || return 1
239
240     # 1 stripe on ost2
241     lfs setstripe $f -s $((128 * 1024)) -i 1 -c 1
242
243     do_facet client cp $SAMPLE_FILE $f
244     sync
245     local osc2dev=`grep ${ost2_svc}-osc- $LPROC/devices | awk '{print $1}'`
246     $LCTL --device $osc2dev deactivate || return 3
247     # my understanding is that there should be nothing in the page
248     # cache after the client reconnects?     
249     rc=0
250     pgcache_empty || rc=2
251     $LCTL --device $osc2dev activate
252     rm -f $f
253     return $rc
254 }
255 run_test 18a "manual ost invalidate clears page cache immediately"
256
257 test_18b() {
258     do_facet client mkdir -p $MOUNT/$tdir
259     f=$MOUNT/$tdir/$tfile
260     f2=$MOUNT/$tdir/${tfile}-2
261
262     cancel_lru_locks osc
263     pgcache_empty || return 1
264
265     # shouldn't have to set stripe size of count==1
266     lfs setstripe $f -s $((128 * 1024)) -i 0 -c 1
267     lfs setstripe $f2 -s $((128 * 1024)) -i 0 -c 1
268
269     do_facet client cp $SAMPLE_FILE $f
270     sync
271     ost_evict_client
272     # force reconnect
273     df $MOUNT > /dev/null 2>&1
274     sleep 2
275     # my understanding is that there should be nothing in the page
276     # cache after the client reconnects?     
277     rc=0
278     pgcache_empty || rc=2
279     rm -f $f $f2
280     return $rc
281 }
282 run_test 18b "eviction and reconnect clears page cache (2766)"
283
284 test_19a() {
285     f=$MOUNT/$tfile
286     do_facet client mcreate $f        || return 1
287     drop_ldlm_cancel "chmod 0777 $f"  || echo "evicted as expected"
288
289     do_facet client checkstat -v -p 0777 $f  || echo evicted
290     # let the client reconnect
291     sleep 5
292     do_facet client "munlink $f"
293 }
294 run_test 19a "test expired_lock_main on mds (2867)"
295
296 test_19b() {
297     f=$MOUNT/$tfile
298     do_facet client multiop $f Ow  || return 1
299     do_facet client multiop $f or  || return 2
300
301     cancel_lru_locks osc
302
303     do_facet client multiop $f or  || return 3
304     drop_ldlm_cancel multiop $f Ow  || echo "client evicted, as expected"
305
306     do_facet client munlink $f  || return 4
307 }
308 run_test 19b "test expired_lock_main on ost (2867)"
309
310 test_20a() {    # bug 2983 - ldlm_handle_enqueue cleanup
311         mkdir -p $DIR/$tdir
312         multiop $DIR/$tdir/${tfile} O_wc &
313         MULTI_PID=$!
314         sleep 1
315         cancel_lru_locks osc
316 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
317         do_facet ost1 sysctl -w lustre.fail_loc=0x80000308
318         kill -USR1 $MULTI_PID
319         wait $MULTI_PID
320         rc=$?
321         [ $rc -eq 0 ] && error "multiop didn't fail enqueue: rc $rc" || true
322 }
323 run_test 20a "ldlm_handle_enqueue error (should return error)" 
324
325 test_20b() {    # bug 2986 - ldlm_handle_enqueue error during open
326         mkdir -p $DIR/$tdir
327         touch $DIR/$tdir/${tfile}
328         cancel_lru_locks osc
329 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
330         do_facet ost1 sysctl -w lustre.fail_loc=0x80000308
331         dd if=/etc/hosts of=$DIR/$tdir/$tfile && \
332                 error "didn't fail open enqueue" || true
333 }
334 run_test 20b "ldlm_handle_enqueue error (should return error)"
335
336 test_21a() {
337        mkdir -p $DIR/$tdir-1
338        mkdir -p $DIR/$tdir-2
339        multiop $DIR/$tdir-1/f O_c &
340        close_pid=$!
341
342        do_facet mds "sysctl -w lustre.fail_loc=0x80000129"
343        multiop $DIR/$tdir-2/f Oc &
344        open_pid=$!
345        sleep 1
346        do_facet mds "sysctl -w lustre.fail_loc=0"
347
348        do_facet mds "sysctl -w lustre.fail_loc=0x80000115"
349        kill -USR1 $close_pid
350        cancel_lru_locks mdc
351        wait $close_pid || return 1
352        wait $open_pid || return 2
353        do_facet mds "sysctl -w lustre.fail_loc=0"
354
355        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
356        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
357
358        rm -rf $DIR/$tdir-*
359 }
360 run_test 21a "drop close request while close and open are both in flight"
361
362 test_21b() {
363        mkdir -p $DIR/$tdir-1
364        mkdir -p $DIR/$tdir-2
365        multiop $DIR/$tdir-1/f O_c &
366        close_pid=$!
367
368        do_facet mds "sysctl -w lustre.fail_loc=0x80000107"
369        mcreate $DIR/$tdir-2/f &
370        open_pid=$!
371        sleep 1
372        do_facet mds "sysctl -w lustre.fail_loc=0"
373
374        kill -USR1 $close_pid
375        cancel_lru_locks mdc
376        wait $close_pid || return 1
377        wait $open_pid || return 3
378
379        $CHECKSTAT -t file $DIR/$tdir-1/f || return 4
380        $CHECKSTAT -t file $DIR/$tdir-2/f || return 5
381        rm -rf $DIR/$tdir-*
382 }
383 run_test 21b "drop open request while close and open are both in flight"
384
385 test_21c() {
386        mkdir -p $DIR/$tdir-1
387        mkdir -p $DIR/$tdir-2
388        multiop $DIR/$tdir-1/f O_c &
389        close_pid=$!
390
391        do_facet mds "sysctl -w lustre.fail_loc=0x80000107"
392        mcreate $DIR/$tdir-2/f &
393        open_pid=$!
394        sleep 3
395        do_facet mds "sysctl -w lustre.fail_loc=0"
396
397        do_facet mds "sysctl -w lustre.fail_loc=0x80000115"
398        kill -USR1 $close_pid
399        cancel_lru_locks mdc
400        wait $close_pid || return 1
401        wait $open_pid || return 2
402
403        do_facet mds "sysctl -w lustre.fail_loc=0"
404
405        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
406        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
407        rm -rf $DIR/$tdir-*
408 }
409 run_test 21c "drop both request while close and open are both in flight"
410
411 test_21d() {
412        mkdir -p $DIR/$tdir-1
413        mkdir -p $DIR/$tdir-2
414        multiop $DIR/$tdir-1/f O_c &
415        pid=$!
416
417        do_facet mds "sysctl -w lustre.fail_loc=0x80000129"
418        multiop $DIR/$tdir-2/f Oc &
419        sleep 1
420        do_facet mds "sysctl -w lustre.fail_loc=0"
421
422        do_facet mds "sysctl -w lustre.fail_loc=0x80000122"
423        kill -USR1 $pid
424        cancel_lru_locks mdc
425        wait $pid || return 1
426        do_facet mds "sysctl -w lustre.fail_loc=0"
427
428        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
429        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
430
431        rm -rf $DIR/$tdir-*
432 }
433 run_test 21d "drop close reply while close and open are both in flight"
434
435 test_21e() {
436        mkdir -p $DIR/$tdir-1
437        mkdir -p $DIR/$tdir-2
438        multiop $DIR/$tdir-1/f O_c &
439        pid=$!
440
441        do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
442        touch $DIR/$tdir-2/f &
443        sleep 1
444        do_facet mds "sysctl -w lustre.fail_loc=0"
445
446        kill -USR1 $pid
447        cancel_lru_locks mdc
448        wait $pid || return 1
449
450        sleep $TIMEOUT
451        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
452        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
453        rm -rf $DIR/$tdir-*
454 }
455 run_test 21e "drop open reply while close and open are both in flight"
456
457 test_21f() {
458        mkdir -p $DIR/$tdir-1
459        mkdir -p $DIR/$tdir-2
460        multiop $DIR/$tdir-1/f O_c &
461        pid=$!
462
463        do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
464        touch $DIR/$tdir-2/f &
465        sleep 1
466        do_facet mds "sysctl -w lustre.fail_loc=0"
467
468        do_facet mds "sysctl -w lustre.fail_loc=0x80000122"
469        kill -USR1 $pid
470        cancel_lru_locks mdc
471        wait $pid || return 1
472        do_facet mds "sysctl -w lustre.fail_loc=0"
473
474        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
475        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
476        rm -rf $DIR/$tdir-*
477 }
478 run_test 21f "drop both reply while close and open are both in flight"
479
480 test_21g() {
481        mkdir -p $DIR/$tdir-1
482        mkdir -p $DIR/$tdir-2
483        multiop $DIR/$tdir-1/f O_c &
484        pid=$!
485
486        do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
487        touch $DIR/$tdir-2/f &
488        sleep 1
489        do_facet mds "sysctl -w lustre.fail_loc=0"
490
491        do_facet mds "sysctl -w lustre.fail_loc=0x80000115"
492        kill -USR1 $pid
493        cancel_lru_locks mdc
494        wait $pid || return 1
495        do_facet mds "sysctl -w lustre.fail_loc=0"
496
497        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
498        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
499        rm -rf $DIR/$tdir-*
500 }
501 run_test 21g "drop open reply and close request while close and open are both in flight"
502
503 test_21h() {
504        mkdir -p $DIR/$tdir-1
505        mkdir -p $DIR/$tdir-2
506        multiop $DIR/$tdir-1/f O_c &
507        pid=$!
508
509        do_facet mds "sysctl -w lustre.fail_loc=0x80000107"
510        touch $DIR/$tdir-2/f &
511        touch_pid=$!
512        sleep 1
513        do_facet mds "sysctl -w lustre.fail_loc=0"
514
515        do_facet mds "sysctl -w lustre.fail_loc=0x80000122"
516        cancel_lru_locks mdc
517        kill -USR1 $pid
518        wait $pid || return 1
519        do_facet mds "sysctl -w lustre.fail_loc=0"
520
521        wait $touch_pid || return 2
522
523        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
524        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
525        rm -rf $DIR/$tdir-*
526 }
527 run_test 21h "drop open request and close reply while close and open are both in flight"
528
529 # bug 3462 - multiple MDC requests
530 test_22() {
531     f1=$DIR/${tfile}-1
532     f2=$DIR/${tfile}-2
533     
534     do_facet mds "sysctl -w lustre.fail_loc=0x80000115"
535     multiop $f2 Oc &
536     close_pid=$!
537
538     sleep 1
539     multiop $f1 msu || return 1
540
541     cancel_lru_locks mdc
542     do_facet mds "sysctl -w lustre.fail_loc=0"
543
544     wait $close_pid || return 2
545     rm -rf $f2 || return 4
546 }
547 run_test 22 "drop close request and do mknod"
548
549 test_23() { #b=4561
550     multiop $DIR/$tfile O_c &
551     pid=$!
552     # give a chance for open
553     sleep 5
554
555     # try the close
556     drop_request "kill -USR1 $pid"
557
558     fail mds
559     wait $pid || return 1
560     return 0
561 }
562 run_test 23 "client hang when close a file after mds crash"
563
564 test_24() {     # bug 2248 - eviction fails writeback but app doesn't see it
565         mkdir -p $DIR/$tdir
566         cancel_lru_locks osc
567         multiop $DIR/$tdir/$tfile Owy_wyc &
568         MULTI_PID=$!
569         sleep 0.500s
570         ost_evict_client
571         sleep 0.500s
572         kill -USR1 $MULTI_PID
573         wait $MULTI_PID
574         rc=$?
575         sysctl -w lustre.fail_loc=0x0
576         client_reconnect
577         [ $rc -eq 0 ] && error_ignore 5494 "multiop didn't fail fsync: rc $rc" || true
578 }
579 run_test 24 "fsync error (should return error)"
580
581 test_26() {      # bug 5921 - evict dead exports by pinger
582 # this test can only run from a client on a separate node.
583         remote_ost || skip "local OST" && return
584         remote_mds || skip "local MDS" && return
585         OST_FILE=$LPROC/obdfilter/${ost1_svc}/num_exports
586         OST_EXP="`do_facet ost1 cat $OST_FILE`"
587         OST_NEXP1=`echo $OST_EXP | cut -d' ' -f2`
588         echo starting with $OST_NEXP1 OST exports
589 # OBD_FAIL_PTLRPC_DROP_RPC 0x505
590         do_facet client sysctl -w lustre.fail_loc=0x505
591         # evictor takes up to 2.25x to evict.  But if there's a 
592         # race to start the evictor from various obds, the loser
593         # might have to wait for the next ping.
594         echo Waiting for $(($TIMEOUT * 4)) secs
595         sleep $(($TIMEOUT * 4))
596         OST_EXP="`do_facet ost1 cat $OST_FILE`"
597         OST_NEXP2=`echo $OST_EXP | cut -d' ' -f2`
598         echo ending with $OST_NEXP2 OST exports
599         do_facet client sysctl -w lustre.fail_loc=0x0
600         [ $OST_NEXP1 -le $OST_NEXP2 ] && error "client not evicted"
601         return 0
602 }
603 run_test 26 "evict dead exports"
604
605 test_26b() {      # bug 10140 - evict dead exports by pinger
606         client_df
607         zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
608         MDS_FILE=$LPROC/mds/${mds_svc}/num_exports
609         MDS_NEXP1="`do_facet mds cat $MDS_FILE | cut -d' ' -f2`"
610         OST_FILE=$LPROC/obdfilter/${ost1_svc}/num_exports
611         OST_NEXP1="`do_facet ost1 cat $OST_FILE | cut -d' ' -f2`"
612         echo starting with $OST_NEXP1 OST and $MDS_NEXP1 MDS exports
613         #force umount a client; exports should get evicted
614         zconf_umount `hostname` $MOUNT2 -f
615         # evictor takes PING_EVICT_TIMEOUT + 3 * PING_INTERVAL to evict.  
616         # But if there's a race to start the evictor from various obds, 
617         # the loser might have to wait for the next ping.
618         echo Waiting for $(($TIMEOUT * 8)) secs
619         sleep $(($TIMEOUT * 8))
620         OST_NEXP2="`do_facet ost1 cat $OST_FILE | cut -d' ' -f2`"
621         MDS_NEXP2="`do_facet mds cat $MDS_FILE | cut -d' ' -f2`"
622         echo ending with $OST_NEXP2 OST and $MDS_NEXP2 MDS exports
623         [ $OST_NEXP1 -le $OST_NEXP2 ] && error "client not evicted from OST"
624         [ $MDS_NEXP1 -le $MDS_NEXP2 ] && error "client not evicted from MDS"
625         return 0
626 }
627 run_test 26b "evict dead exports"
628
629 test_27() {
630         remote_mds && { skip "remote MDS" && return 0; }
631         mkdir -p $DIR/$tdir
632         writemany -q -a $DIR/$tdir/$tfile 0 5 &
633         CLIENT_PID=$!
634         sleep 1
635         FAILURE_MODE="SOFT"
636         facet_failover mds
637 #define OBD_FAIL_OSC_SHUTDOWN            0x407
638         sysctl -w lustre.fail_loc=0x80000407
639         # need to wait for reconnect
640         echo -n waiting for fail_loc
641         while [ `sysctl -n lustre.fail_loc` -eq -2147482617 ]; do
642             sleep 1
643             echo -n .
644         done
645         facet_failover mds
646         #no crashes allowed!
647         kill -USR1 $CLIENT_PID
648         wait $CLIENT_PID 
649         true
650 }
651 run_test 27 "fail LOV while using OSC's"
652
653 test_28() {      # bug 6086 - error adding new clients
654         do_facet client mcreate $MOUNT/$tfile       || return 1
655         drop_bl_callback "chmod 0777 $MOUNT/$tfile" ||echo "evicted as expected"
656         #define OBD_FAIL_MDS_ADD_CLIENT 0x12f
657         do_facet mds sysctl -w lustre.fail_loc=0x8000012f
658         # fail once (evicted), reconnect fail (fail_loc), ok
659         df || (sleep 1; df) || (sleep 1; df) || error "reconnect failed"
660         rm -f $MOUNT/$tfile
661         fail mds                # verify MDS last_rcvd can be loaded
662 }
663 run_test 28 "handle error adding new clients (bug 6086)"
664
665 test_50() {
666         mkdir -p $DIR/$tdir
667         debugsave
668         sysctl -w lnet.debug="-dlmtrace -ha"
669         # put a load of file creates/writes/deletes
670         writemany -q $DIR/$tdir/$tfile 0 5 &
671         CLIENT_PID=$!
672         echo writemany pid $CLIENT_PID
673         sleep 10
674         FAILURE_MODE="SOFT"
675         $LCTL mark "$TESTNAME fail mds 1"
676         fail mds
677         # wait for client to reconnect to MDS
678         sleep 60
679         $LCTL mark "$TESTNAME fail mds 2"
680         fail mds
681         sleep 60
682         $LCTL mark "$TESTNAME fail mds 3"
683         fail mds
684         # client process should see no problems even though MDS went down
685         sleep $TIMEOUT
686         kill -USR1 $CLIENT_PID
687         wait $CLIENT_PID 
688         rc=$?
689         echo writemany returned $rc
690         #these may fail because of eviction due to slow AST response.
691         debugrestore
692         [ $rc -eq 0 ] || error_ignore 13652 "writemany returned rc $rc" || true
693 }
694 run_test 50 "failover MDS under load"
695
696 test_51() {
697         mkdir -p $DIR/$tdir
698         # put a load of file creates/writes/deletes
699         writemany -q $DIR/$tdir/$tfile 0 5 &
700         CLIENT_PID=$!
701         sleep 1
702         FAILURE_MODE="SOFT"
703         facet_failover mds
704         # failover at various points during recovery
705         SEQ="1 5 10 $(seq $TIMEOUT 5 $(($TIMEOUT+10)))"
706         echo will failover at $SEQ
707         for i in $SEQ
708           do
709           echo failover in $i sec
710           sleep $i
711           $LCTL mark "$TESTNAME fail mds $i"
712           facet_failover mds
713         done
714         # client process should see no problems even though MDS went down
715         # and recovery was interrupted
716         sleep $TIMEOUT
717         kill -USR1 $CLIENT_PID
718         wait $CLIENT_PID 
719         rc=$?
720         echo writemany returned $rc
721         [ $rc -eq 0 ] || error_ignore 13652 "writemany returned rc $rc" || true
722 }
723 run_test 51 "failover MDS during recovery"
724
725 test_52_guts() {
726         do_facet client "writemany -q -a $DIR/$tdir/$tfile 300 5" &
727         CLIENT_PID=$!
728         echo writemany pid $CLIENT_PID
729         sleep 10
730         FAILURE_MODE="SOFT"
731         $LCTL mark "$TESTNAME fail ost $1"
732         fail ost1
733         rc=0
734         wait $CLIENT_PID || rc=$?
735         # active client process should see an EIO for down OST
736         [ $rc -eq 5 ] && { echo "writemany correctly failed $rc" && return 0; }
737         # but timing or failover setup may allow success
738         [ $rc -eq 0 ] && { echo "writemany succeeded" && return 0; }
739         echo "writemany returned $rc"
740         return $rc
741 }
742
743 test_52() {
744         mkdir -p $DIR/$tdir
745         test_52_guts 1
746         rc=$?
747         [ $rc -ne 0 ] && { return $rc; }
748         # wait for client to reconnect to OST
749         sleep 30
750         test_52_guts 2
751         rc=$?
752         [ $rc -ne 0 ] && { return $rc; }
753         sleep 30
754         test_52_guts 3
755         rc=$?
756         client_reconnect
757         #return $rc
758 }
759 run_test 52 "failover OST under load"
760
761 # test of open reconstruct
762 test_53() {
763         touch $DIR/$tfile
764         drop_ldlm_reply "openfile -f O_RDWR:O_CREAT -m 0755 $DIR/$tfile" ||\
765                 return 2
766 }
767 run_test 53 "touch: drop rep"
768
769 test_54() {
770         zconf_mount `hostname` $MOUNT2
771         touch $DIR/$tfile
772         touch $DIR2/$tfile.1
773         sleep 10
774         cat $DIR2/$tfile.missing # save transno = 0, rc != 0 into last_rcvd
775         fail mds
776         umount $MOUNT2
777         ERROR=`dmesg | egrep "(test 54|went back in time)" | tail -n1 | grep "went back in time"`
778         [ x"$ERROR" == x ] || error "back in time occured"
779 }
780 run_test 54 "back in time"
781
782 # bug 11330 - liblustre application death during I/O locks up OST
783 test_55() {
784         remote_ost && { skip "remote OST" && return 0; }
785
786         mkdir -p $DIR/$tdir
787
788         # first dd should be finished quickly
789         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=32M count=4  &
790         DDPID=$!
791         count=0
792         echo  "step1: testing ......"
793         while [ true ]; do
794             if [ -z `ps x | awk '$1 == '$DDPID' { print $5 }'` ]; then break; fi
795             count=$[count+1]
796             if [ $count -gt 64 ]; then
797                 error "dd should be finished!"
798             fi
799             sleep 1
800         done    
801         echo "(dd_pid=$DDPID, time=$count)successful"
802
803         #define OBD_FAIL_OST_DROP_REQ            0x21d
804         do_facet ost sysctl -w lustre.fail_loc=0x0000021d
805         # second dd will be never finished
806         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=32M count=4  &        
807         DDPID=$!
808         count=0
809         echo  "step2: testing ......"
810         while [ $count -le 64 ]; do
811             dd_name="`ps x | awk '$1 == '$DDPID' { print $5 }'`"            
812             if [ -z  $dd_name ]; then 
813                 ls -l $DIR/$tdir
814                 echo  "debug: (dd_name=$dd_name, dd_pid=$DDPID, time=$count)"
815                 error "dd shouldn't be finished!"
816             fi
817             count=$[count+1]
818             sleep 1
819         done    
820         echo "(dd_pid=$DDPID, time=$count)successful"
821
822         #Recover fail_loc and dd will finish soon
823         do_facet ost sysctl -w lustre.fail_loc=0
824         count=0
825         echo  "step3: testing ......"
826         while [ true ]; do
827             if [ -z `ps x | awk '$1 == '$DDPID' { print $5 }'` ]; then break; fi
828             count=$[count+1]
829             if [ $count -gt 500 ]; then
830                 error "dd should be finished!"
831             fi
832             sleep 1
833         done    
834         echo "(dd_pid=$DDPID, time=$count)successful"
835
836         rm -rf $DIR/$tdir
837 }
838 run_test 55 "ost_brw_read/write drops timed-out read/write request"
839
840 test_56() { # b=11277
841 #define OBD_FAIL_MDS_RESEND      0x136
842         touch $DIR/$tfile
843         do_facet mds sysctl -w lustre.fail_loc=0x80000136
844         stat $DIR/$tfile
845         do_facet mds sysctl -w lustre.fail_loc=0
846         rm -f $DIR/$tfile
847 }
848 run_test 56 "do not allow reconnect to busy exports"
849
850 test_57_helper() {
851         # no oscs means no client or mdt 
852         while [ -e $LPROC/osc ]; do
853                 for f in `find $LPROC -type f`; do 
854                         cat $f > /dev/null 2>&1
855                 done
856         done
857 }
858
859 test_57() { # bug 10866
860         test_57_helper &
861         pid=$!
862         sleep 1
863 #define OBD_FAIL_LPROC_REMOVE            0xB00
864         sysctl -w lustre.fail_loc=0x80000B00
865         zconf_umount `hostname` $DIR
866         sysctl -w lustre.fail_loc=0x80000B00
867         fail_abort mds
868         kill -9 $pid
869         sysctl -w lustre.fail_loc=0
870         mount_client $DIR
871         do_facet client "df $DIR"
872 }
873 run_test 57 "read procfs entries causes kernel crash"
874
875 test_58() { # bug 11546
876 #define OBD_FAIL_MDC_ENQUEUE_PAUSE        0x801
877         touch $MOUNT/$tfile
878         ls -la $MOUNT/$tfile
879         sysctl -w lustre.fail_loc=0x80000801
880         cp $MOUNT/$tfile /dev/null &
881         pid=$!
882         sleep 1
883         sysctl -w lustre.fail_loc=0
884         drop_bl_callback rm -f $MOUNT/$tfile
885         wait $pid
886         do_facet client "df $DIR"
887 }
888 run_test 58 "Eviction in the middle of open RPC reply processing"
889
890 test_59() { # bug 10589
891         zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
892         sysctl -w lustre.fail_loc=0x311
893         writes=$(LANG=C dd if=/dev/zero of=$DIR2/$tfile count=1 2>&1 | awk  -F '+' '/out/ {print $1}')
894         sysctl -w lustre.fail_loc=0
895         sync
896         zconf_umount `hostname` $DIR2 -f
897         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1 | awk -F '+' '/in/ {print $1}')
898         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
899 }
900 run_test 59 "Read cancel race on client eviction"
901
902 equals_msg `basename $0`: test complete, cleaning up
903 check_and_cleanup_lustre
904 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true