Whamcloud - gitweb
b=15221
[fs/lustre-release.git] / lustre / tests / recovery-small.sh
1 #!/bin/bash
2
3 set -e
4
5 #         bug  5494 7288 5493
6 ALWAYS_EXCEPT="24   27   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 # also long tests: 19, 21a, 21e, 21f, 23, 27
15 #                                   1  2.5  2.5    4    4          (min)"
16 [ "$SLOW" = "no" ] && EXCEPT_SLOW="17  26a  26b    50   51     57"
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 SAMPLE_NAME=recovery-small.junk
29 SAMPLE_FILE=$TMP/$SAMPLE_NAME
30 # make this big, else test 9 doesn't wait for bulk -- bz 5595
31 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=4
32
33 test_1() {
34     drop_request "mcreate $MOUNT/1"  || return 1
35     drop_reint_reply "mcreate $MOUNT/2"    || return 2
36 }
37 run_test 1 "mcreate: drop req, drop rep"
38
39 test_2() {
40     drop_request "tchmod 111 $MOUNT/2"  || return 1
41     drop_reint_reply "tchmod 666 $MOUNT/2"    || return 2
42 }
43 run_test 2 "chmod: drop req, drop rep"
44
45 test_3() {
46     drop_request "statone $MOUNT/2" || return 1
47     drop_reply "statone $MOUNT/2"   || return 2
48 }
49 run_test 3 "stat: drop req, drop rep"
50
51 test_4() {
52     do_facet client "cp /etc/inittab $MOUNT/inittab" || return 1
53     drop_request "cat $MOUNT/inittab > /dev/null"   || return 2
54     drop_reply "cat $MOUNT/inittab > /dev/null"     || return 3
55 }
56 run_test 4 "open: drop req, drop rep"
57
58 test_5() {
59     drop_request "mv $MOUNT/inittab $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 /etc/inittab $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 #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 $SINGLEMDS "sysctl -w lustre.fail_loc=0x115"
127     clear_failloc $SINGLEMDS $((TIMEOUT * 2)) &
128     multiop_bg_pause $MOUNT/$tfile OS_c || return 1
129     PID=$!
130 #define OBD_FAIL_MDS_CLOSE_NET           0x115
131     kill -USR1 $PID
132     echo "waiting for multiop $PID"
133     wait $PID || return 2
134     do_facet client munlink $MOUNT/$tfile  || return 3
135 }
136 run_test 12 "recover from timed out resend in ptlrpcd (b=2494)"
137
138 # Bug 113, check that readdir lost recv timeout works.
139 test_13() {
140     mkdir $MOUNT/readdir || return 1
141     touch $MOUNT/readdir/newentry || return
142 # OBD_FAIL_MDS_READPAGE_NET|OBD_FAIL_ONCE
143     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000104"
144     ls $MOUNT/readdir || return 3
145     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
146     rm -rf $MOUNT/readdir || return 4
147 }
148 run_test 13 "mdc_readpage restart test (bug 1138)"
149
150 # Bug 113, check that readdir lost send timeout works.
151 test_14() {
152     mkdir $MOUNT/readdir
153     touch $MOUNT/readdir/newentry
154 # OBD_FAIL_MDS_SENDPAGE|OBD_FAIL_ONCE
155     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000106"
156     ls $MOUNT/readdir || return 1
157     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
158 }
159 run_test 14 "mdc_readpage resend test (bug 1138)"
160
161 test_15() {
162     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000128"
163     touch $DIR/$tfile && return 1
164     return 0
165 }
166 run_test 15 "failed open (-ENOMEM)"
167
168 READ_AHEAD=`lctl get_param -n llite.*.max_read_ahead_mb | head -n 1`
169 stop_read_ahead() {
170    lctl set_param -n llite.*.max_read_ahead_mb 0
171 }
172
173 start_read_ahead() {
174    lctl set_param -n llite.*.max_read_ahead_mb $READ_AHEAD
175 }
176
177 test_16() {
178     do_facet client cp /etc/termcap $MOUNT
179     sync
180     stop_read_ahead
181
182 #define OBD_FAIL_PTLRPC_BULK_PUT_NET 0x504 | OBD_FAIL_ONCE
183     do_facet ost1 "sysctl -w lustre.fail_loc=0x80000504"
184     cancel_lru_locks osc
185     # OST bulk will time out here, client resends
186     do_facet client "cmp /etc/termcap $MOUNT/termcap" || return 1
187     do_facet ost1 sysctl -w lustre.fail_loc=0
188     # give recovery a chance to finish (shouldn't take long)
189     sleep $TIMEOUT
190     do_facet client "cmp /etc/termcap $MOUNT/termcap" || return 2
191     start_read_ahead
192 }
193 run_test 16 "timeout bulk put, don't evict client (2732)"
194
195 test_17() {
196     # OBD_FAIL_PTLRPC_BULK_GET_NET 0x0503 | OBD_FAIL_ONCE
197     # OST bulk will time out here, client retries
198     do_facet ost1 sysctl -w lustre.fail_loc=0x80000503
199     # need to ensure we send an RPC
200     do_facet client cp /etc/termcap $DIR/$tfile
201     sync
202
203     sleep $TIMEOUT
204     do_facet ost1 sysctl -w lustre.fail_loc=0
205     do_facet client "df $DIR"
206     # expect cmp to succeed, client resent bulk
207     do_facet client "cmp /etc/termcap $DIR/$tfile" || return 3
208     do_facet client "rm $DIR/$tfile" || return 4
209     return 0
210 }
211 run_test 17 "timeout bulk get, don't evict client (2732)"
212
213 test_18a() {
214     [ -z ${ost2_svc} ] && skip "needs 2 osts" && return 0
215
216     do_facet client mkdir -p $MOUNT/$tdir
217     f=$MOUNT/$tdir/$tfile
218
219     cancel_lru_locks osc
220     pgcache_empty || return 1
221
222     # 1 stripe on ost2
223     lfs setstripe $f -s $((128 * 1024)) -i 1 -c 1
224
225     do_facet client cp $SAMPLE_FILE $f
226     sync
227     local osc2dev=`lctl get_param -n devices | grep ${ost2_svc}-osc- | egrep -v 'MDT' | awk '{print $1}'`
228     $LCTL --device $osc2dev deactivate || return 3
229     # my understanding is that there should be nothing in the page
230     # cache after the client reconnects?     
231     rc=0
232     pgcache_empty || rc=2
233     $LCTL --device $osc2dev activate
234     rm -f $f
235     return $rc
236 }
237 run_test 18a "manual ost invalidate clears page cache immediately"
238
239 test_18b() {
240     do_facet client mkdir -p $MOUNT/$tdir
241     f=$MOUNT/$tdir/$tfile
242     f2=$MOUNT/$tdir/${tfile}-2
243
244     cancel_lru_locks osc
245     pgcache_empty || return 1
246
247     # shouldn't have to set stripe size of count==1
248     lfs setstripe $f -s $((128 * 1024)) -i 0 -c 1
249     lfs setstripe $f2 -s $((128 * 1024)) -i 0 -c 1
250
251     do_facet client cp $SAMPLE_FILE $f
252     sync
253     ost_evict_client
254     # allow recovery to complete
255     sleep $((TIMEOUT + 2))
256     # my understanding is that there should be nothing in the page
257     # cache after the client reconnects?     
258     rc=0
259     pgcache_empty || rc=2
260     rm -f $f $f2
261     return $rc
262 }
263 run_test 18b "eviction and reconnect clears page cache (2766)"
264
265 test_18c() {
266     do_facet client mkdir -p $MOUNT/$tdir
267     f=$MOUNT/$tdir/$tfile
268     f2=$MOUNT/$tdir/${tfile}-2
269
270     cancel_lru_locks osc
271     pgcache_empty || return 1
272
273     # shouldn't have to set stripe size of count==1
274     lfs setstripe $f -s $((128 * 1024)) -i 0 -c 1
275     lfs setstripe $f2 -s $((128 * 1024)) -i 0 -c 1
276
277     do_facet client cp $SAMPLE_FILE $f
278     sync
279     ost_evict_client
280
281     # OBD_FAIL_OST_CONNECT_NET2
282     # lost reply to connect request
283     do_facet ost1 sysctl -w lustre.fail_loc=0x80000225
284     # force reconnect
285     df $MOUNT > /dev/null 2>&1
286     sleep 2
287     # my understanding is that there should be nothing in the page
288     # cache after the client reconnects?     
289     rc=0
290     pgcache_empty || rc=2
291     rm -f $f $f2
292     return $rc
293 }
294 run_test 18c "Dropped connect reply after eviction handing (14755)"
295
296 test_19a() {
297     f=$MOUNT/$tfile
298     do_facet client mcreate $f        || return 1
299     drop_ldlm_cancel "chmod 0777 $f"  || echo "evicted as expected"
300
301     do_facet client checkstat -v -p 0777 $f  || echo evicted
302     # let the client reconnect
303     sleep 5
304     do_facet client "munlink $f"
305 }
306 run_test 19a "test expired_lock_main on mds (2867)"
307
308 test_19b() {
309     f=$MOUNT/$tfile
310     do_facet client multiop $f Ow  || return 1
311     do_facet client multiop $f or  || return 2
312
313     cancel_lru_locks osc
314
315     do_facet client multiop $f or  || return 3
316     drop_ldlm_cancel multiop $f Ow  || echo "client evicted, as expected"
317
318     do_facet client munlink $f  || return 4
319 }
320 run_test 19b "test expired_lock_main on ost (2867)"
321
322 test_20a() {    # bug 2983 - ldlm_handle_enqueue cleanup
323         mkdir -p $DIR/$tdir
324         multiop_bg_pause $DIR/$tdir/${tfile} O_wc || return 1
325         MULTI_PID=$!
326         cancel_lru_locks osc
327 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
328         do_facet ost1 sysctl -w lustre.fail_loc=0x80000308
329         kill -USR1 $MULTI_PID
330         wait $MULTI_PID
331         rc=$?
332         [ $rc -eq 0 ] && error "multiop didn't fail enqueue: rc $rc" || true
333 }
334 run_test 20a "ldlm_handle_enqueue error (should return error)" 
335
336 test_20b() {    # bug 2986 - ldlm_handle_enqueue error during open
337         mkdir -p $DIR/$tdir
338         touch $DIR/$tdir/${tfile}
339         cancel_lru_locks osc
340 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
341         do_facet ost1 sysctl -w lustre.fail_loc=0x80000308
342         dd if=/etc/hosts of=$DIR/$tdir/$tfile && \
343                 error "didn't fail open enqueue" || true
344 }
345 run_test 20b "ldlm_handle_enqueue error (should return error)"
346
347 test_21a() {
348        mkdir -p $DIR/$tdir-1
349        mkdir -p $DIR/$tdir-2
350        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
351        close_pid=$!
352
353        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000129"
354        multiop $DIR/$tdir-2/f Oc &
355        open_pid=$!
356        sleep 1
357        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
358
359        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000115"
360        kill -USR1 $close_pid
361        cancel_lru_locks mdc
362        wait $close_pid || return 1
363        wait $open_pid || return 2
364        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
365
366        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
367        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
368
369        rm -rf $DIR/$tdir-*
370 }
371 run_test 21a "drop close request while close and open are both in flight"
372
373 test_21b() {
374        mkdir -p $DIR/$tdir-1
375        mkdir -p $DIR/$tdir-2
376        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
377        close_pid=$!
378
379        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000107"
380        mcreate $DIR/$tdir-2/f &
381        open_pid=$!
382        sleep 1
383        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
384
385        kill -USR1 $close_pid
386        cancel_lru_locks mdc
387        wait $close_pid || return 1
388        wait $open_pid || return 3
389
390        $CHECKSTAT -t file $DIR/$tdir-1/f || return 4
391        $CHECKSTAT -t file $DIR/$tdir-2/f || return 5
392        rm -rf $DIR/$tdir-*
393 }
394 run_test 21b "drop open request while close and open are both in flight"
395
396 test_21c() {
397        mkdir -p $DIR/$tdir-1
398        mkdir -p $DIR/$tdir-2
399        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
400        close_pid=$!
401
402        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000107"
403        mcreate $DIR/$tdir-2/f &
404        open_pid=$!
405        sleep 3
406        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
407
408        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000115"
409        kill -USR1 $close_pid
410        cancel_lru_locks mdc
411        wait $close_pid || return 1
412        wait $open_pid || return 2
413
414        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
415
416        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
417        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
418        rm -rf $DIR/$tdir-*
419 }
420 run_test 21c "drop both request while close and open are both in flight"
421
422 test_21d() {
423        mkdir -p $DIR/$tdir-1
424        mkdir -p $DIR/$tdir-2
425        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
426        pid=$!
427
428        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000129"
429        multiop $DIR/$tdir-2/f Oc &
430        sleep 1
431        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
432
433        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000122"
434        kill -USR1 $pid
435        cancel_lru_locks mdc
436        wait $pid || return 1
437        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
438
439        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
440        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
441
442        rm -rf $DIR/$tdir-*
443 }
444 run_test 21d "drop close reply while close and open are both in flight"
445
446 test_21e() {
447        mkdir -p $DIR/$tdir-1
448        mkdir -p $DIR/$tdir-2
449        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
450        pid=$!
451
452        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000119"
453        touch $DIR/$tdir-2/f &
454        sleep 1
455        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
456
457        kill -USR1 $pid
458        cancel_lru_locks mdc
459        wait $pid || return 1
460
461        sleep $TIMEOUT
462        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
463        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
464        rm -rf $DIR/$tdir-*
465 }
466 run_test 21e "drop open reply while close and open are both in flight"
467
468 test_21f() {
469        mkdir -p $DIR/$tdir-1
470        mkdir -p $DIR/$tdir-2
471        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
472        pid=$!
473
474        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000119"
475        touch $DIR/$tdir-2/f &
476        sleep 1
477        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
478
479        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000122"
480        kill -USR1 $pid
481        cancel_lru_locks mdc
482        wait $pid || return 1
483        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
484
485        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
486        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
487        rm -rf $DIR/$tdir-*
488 }
489 run_test 21f "drop both reply while close and open are both in flight"
490
491 test_21g() {
492        mkdir -p $DIR/$tdir-1
493        mkdir -p $DIR/$tdir-2
494        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
495        pid=$!
496
497        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000119"
498        touch $DIR/$tdir-2/f &
499        sleep 1
500        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
501
502        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000115"
503        kill -USR1 $pid
504        cancel_lru_locks mdc
505        wait $pid || return 1
506        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
507
508        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
509        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
510        rm -rf $DIR/$tdir-*
511 }
512 run_test 21g "drop open reply and close request while close and open are both in flight"
513
514 test_21h() {
515        mkdir -p $DIR/$tdir-1
516        mkdir -p $DIR/$tdir-2
517        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
518        pid=$!
519
520        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000107"
521        touch $DIR/$tdir-2/f &
522        touch_pid=$!
523        sleep 1
524        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
525
526        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000122"
527        cancel_lru_locks mdc
528        kill -USR1 $pid
529        wait $pid || return 1
530        do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
531
532        wait $touch_pid || return 2
533
534        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
535        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
536        rm -rf $DIR/$tdir-*
537 }
538 run_test 21h "drop open request and close reply while close and open are both in flight"
539
540 # bug 3462 - multiple MDC requests
541 test_22() {
542     f1=$DIR/${tfile}-1
543     f2=$DIR/${tfile}-2
544     
545     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000115"
546     multiop $f2 Oc &
547     close_pid=$!
548
549     sleep 1
550     multiop $f1 msu || return 1
551
552     cancel_lru_locks mdc
553     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
554
555     wait $close_pid || return 2
556     rm -rf $f2 || return 4
557 }
558 run_test 22 "drop close request and do mknod"
559
560 test_23() { #b=4561
561     multiop_bg_pause $DIR/$tfile O_c || return 1
562     pid=$!
563     # give a chance for open
564     sleep 5
565
566     # try the close
567     drop_request "kill -USR1 $pid"
568
569     fail $SINGLEMDS
570     wait $pid || return 1
571     return 0
572 }
573 run_test 23 "client hang when close a file after mds crash"
574
575 test_24() {     # bug 2248 - eviction fails writeback but app doesn't see it
576         mkdir -p $DIR/$tdir
577         cancel_lru_locks osc
578         multiop_bg_pause $DIR/$tdir/$tfile Owy_wyc || return 1
579         MULTI_PID=$!
580         ost_evict_client
581         kill -USR1 $MULTI_PID
582         wait $MULTI_PID
583         rc=$?
584         sysctl -w lustre.fail_loc=0x0
585         client_reconnect
586         [ $rc -eq 0 ] && error_ignore 5494 "multiop didn't fail fsync: rc $rc" || true
587 }
588 run_test 24 "fsync error (should return error)"
589
590 test_26a() {      # was test_26 bug 5921 - evict dead exports by pinger
591 # this test can only run from a client on a separate node.
592         remote_ost || { skip "local OST" && return 0; }
593         remote_mds || { skip "local MDS" && return 0; }
594         OST_FILE=obdfilter.${ost1_svc}.num_exports
595         OST_EXP="`do_facet ost1 lctl get_param -n $OST_FILE`"
596         OST_NEXP1=`echo $OST_EXP | cut -d' ' -f2`
597         echo starting with $OST_NEXP1 OST exports
598 # OBD_FAIL_PTLRPC_DROP_RPC 0x505
599         do_facet client sysctl -w lustre.fail_loc=0x505
600         # evictor takes up to 2.25x to evict.  But if there's a 
601         # race to start the evictor from various obds, the loser
602         # might have to wait for the next ping.
603         echo Waiting for $(($TIMEOUT * 4)) secs
604         sleep $(($TIMEOUT * 4))
605         OST_EXP="`do_facet ost1 lctl get_param -n $OST_FILE`"
606         OST_NEXP2=`echo $OST_EXP | cut -d' ' -f2`
607         echo ending with $OST_NEXP2 OST exports
608         do_facet client sysctl -w lustre.fail_loc=0x0
609         [ $OST_NEXP1 -le $OST_NEXP2 ] && error "client not evicted"
610         return 0
611 }
612 run_test 26a "evict dead exports"
613
614 test_26b() {      # bug 10140 - evict dead exports by pinger
615         client_df
616         zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
617         sleep 1 # wait connections being established
618         MDS_FILE=mdt.${mds1_svc}.num_exports
619         MDS_NEXP1="`do_facet $SINGLEMDS lctl get_param -n $MDS_FILE | cut -d' ' -f2`"
620         OST_FILE=obdfilter.${ost1_svc}.num_exports
621         OST_NEXP1="`do_facet ost1 lctl get_param -n $OST_FILE | cut -d' ' -f2`"
622         echo starting with $OST_NEXP1 OST and $MDS_NEXP1 MDS exports
623         zconf_umount `hostname` $MOUNT2 -f
624         # evictor takes up to 2.25x to evict.  But if there's a 
625         # race to start the evictor from various obds, the loser
626         # might have to wait for the next ping.
627         echo Waiting for $(($TIMEOUT * 4)) secs
628         sleep $(($TIMEOUT * 4))
629         OST_NEXP2="`do_facet ost1 lctl get_param -n $OST_FILE | cut -d' ' -f2`"
630         MDS_NEXP2="`do_facet $SINGLEMDS lctl get_param -n $MDS_FILE | cut -d' ' -f2`"
631         echo ending with $OST_NEXP2 OST and $MDS_NEXP2 MDS exports
632         [ $OST_NEXP1 -le $OST_NEXP2 ] && error "client not evicted from OST"
633         [ $MDS_NEXP1 -le $MDS_NEXP2 ] && error "client not evicted from MDS"
634         return 0
635 }
636 run_test 26b "evict dead exports"
637
638 test_27() {
639         remote_mds && { skip "remote MDS" && return 0; }
640         mkdir -p $DIR/$tdir
641         writemany -q -a $DIR/$tdir/$tfile 0 5 &
642         CLIENT_PID=$!
643         sleep 1
644         FAILURE_MODE="SOFT"
645         facet_failover $SINGLEMDS
646 #define OBD_FAIL_OSC_SHUTDOWN            0x407
647         sysctl -w lustre.fail_loc=0x80000407
648         # need to wait for reconnect
649         echo -n waiting for fail_loc
650         while [ `sysctl -n lustre.fail_loc` -eq -2147482617 ]; do
651             sleep 1
652             echo -n .
653         done
654         facet_failover $SINGLEMDS
655         #no crashes allowed!
656         kill -USR1 $CLIENT_PID
657         wait $CLIENT_PID 
658         true
659 }
660 run_test 27 "fail LOV while using OSC's"
661
662 test_28() {      # bug 6086 - error adding new clients
663         do_facet client mcreate $MOUNT/$tfile       || return 1
664         drop_bl_callback "chmod 0777 $MOUNT/$tfile" ||echo "evicted as expected"
665         #define OBD_FAIL_MDS_CLIENT_ADD 0x12f
666         do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x8000012f"
667         # fail once (evicted), reconnect fail (fail_loc), ok
668         df || (sleep 10; df) || (sleep 10; df) || error "reconnect failed"
669         rm -f $MOUNT/$tfile
670         fail $SINGLEMDS         # verify MDS last_rcvd can be loaded
671 }
672 run_test 28 "handle error adding new clients (bug 6086)"
673
674 test_50() {
675         mkdir -p $DIR/$tdir
676         # put a load of file creates/writes/deletes
677         writemany -q $DIR/$tdir/$tfile 0 5 &
678         CLIENT_PID=$!
679         echo writemany pid $CLIENT_PID
680         sleep 10
681         FAILURE_MODE="SOFT"
682         fail $SINGLEMDS
683         # wait for client to reconnect to MDS
684         sleep 60
685         fail $SINGLEMDS
686         sleep 60
687         fail $SINGLEMDS
688         # client process should see no problems even though MDS went down
689         sleep $TIMEOUT
690         kill -USR1 $CLIENT_PID
691         wait $CLIENT_PID 
692         rc=$?
693         echo writemany returned $rc
694         #these may fail because of eviction due to slow AST response.
695         [ $rc -eq 0 ] || error_ignore 13652 "writemany returned rc $rc" || true
696 }
697 run_test 50 "failover MDS under load"
698
699 test_51() {
700         mkdir -p $DIR/$tdir
701         # put a load of file creates/writes/deletes
702         writemany -q $DIR/$tdir/$tfile 0 5 &
703         CLIENT_PID=$!
704         sleep 1
705         FAILURE_MODE="SOFT"
706         facet_failover $SINGLEMDS
707         # failover at various points during recovery
708         SEQ="1 5 10 $(seq $TIMEOUT 5 $(($TIMEOUT+10)))"
709         echo will failover at $SEQ
710         for i in $SEQ
711           do
712           echo failover in $i sec
713           sleep $i
714           facet_failover $SINGLEMDS
715         done
716         # client process should see no problems even though MDS went down
717         # and recovery was interrupted
718         sleep $TIMEOUT
719         kill -USR1 $CLIENT_PID
720         wait $CLIENT_PID 
721         rc=$?
722         echo writemany returned $rc
723         [ $rc -eq 0 ] || error_ignore 13652 "writemany returned rc $rc" || true
724 }
725 run_test 51 "failover MDS during recovery"
726
727 test_52_guts() {
728         do_facet client "writemany -q -a $DIR/$tdir/$tfile 300 5" &
729         CLIENT_PID=$!
730         echo writemany pid $CLIENT_PID
731         sleep 10
732         FAILURE_MODE="SOFT"
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
747         rc=$?
748         [ $rc -ne 0 ] && { return $rc; }
749         # wait for client to reconnect to OST
750         sleep 30
751         test_52_guts
752         rc=$?
753         [ $rc -ne 0 ] && { return $rc; }
754         sleep 30
755         test_52_guts
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 $SINGLEMDS
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 $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000136"
845         stat $DIR/$tfile
846         do_facet $SINGLEMDS "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 lctl get_param osc.*.* > /dev/null 2>&1; do
854                 : # loop until proc file is removed
855         done
856 }
857
858 test_57() { # bug 10866
859         test_57_helper &
860         pid=$!
861         sleep 1
862 #define OBD_FAIL_LPROC_REMOVE            0xB00
863         sysctl -w lustre.fail_loc=0x80000B00
864         zconf_umount `hostname` $DIR
865         sysctl -w lustre.fail_loc=0x80000B00
866         fail_abort $SINGLEMDS
867         kill -9 $pid
868         sysctl -w lustre.fail_loc=0
869         mount_client $DIR
870         do_facet client "df $DIR"
871 }
872 run_test 57 "read procfs entries causes kernel crash"
873
874 test_58() { # bug 11546
875 #define OBD_FAIL_MDC_ENQUEUE_PAUSE        0x801
876         touch $MOUNT/$tfile
877         ls -la $MOUNT/$tfile
878         sysctl -w lustre.fail_loc=0x80000801
879         cp $MOUNT/$tfile /dev/null &
880         pid=$!
881         sleep 1
882         sysctl -w lustre.fail_loc=0
883         drop_bl_callback rm -f $MOUNT/$tfile
884         wait $pid
885         do_facet client "df $DIR"
886 }
887 run_test 58 "Eviction in the middle of open RPC reply processing"
888
889 test_59() { # bug 10589
890         zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
891         echo $DIR2 | grep -q $MOUNT2 || error "DIR2 is not set properly: $DIR2"
892 #define OBD_FAIL_LDLM_CANCEL_EVICT_RACE  0x311
893         sysctl -w lustre.fail_loc=0x311
894         writes=$(LANG=C dd if=/dev/zero of=$DIR2/$tfile count=1 2>&1)
895         [ $? = 0 ] || error "dd write failed"
896         writes=$(echo $writes | awk  -F '+' '/out/ {print $1}')
897         sysctl -w lustre.fail_loc=0
898         sync
899         zconf_umount `hostname` $MOUNT2 -f
900         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1)
901         [ $? = 0 ] || error "dd read failed"
902         reads=$(echo $reads | awk -F '+' '/in/ {print $1}')
903         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
904 }
905 run_test 59 "Read cancel race on client eviction"
906
907 equals_msg `basename $0`: test complete, cleaning up
908 check_and_cleanup_lustre
909 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true