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