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