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