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