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