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