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