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