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