Whamcloud - gitweb
b=24078 replay barrier checks sequence allocation
[fs/lustre-release.git] / lustre / tests / replay-single.sh
1 #!/bin/bash
2
3 set -e
4 #set -v
5
6 #
7 # This test needs to be run on the client
8 #
9 SAVE_PWD=$PWD
10 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
11 SETUP=${SETUP:-}
12 CLEANUP=${CLEANUP:-}
13 . $LUSTRE/tests/test-framework.sh
14 init_test_env $@
15 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
16 init_logging
17 CHECK_GRANT=${CHECK_GRANT:-"yes"}
18 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
19
20 require_dsh_mds || exit 0
21
22 # Skip these tests
23 # bug number:  17466 18857
24 ALWAYS_EXCEPT="61d   33a 33b    $REPLAY_SINGLE_EXCEPT"
25
26 #                                                  63 min  7 min  AT AT AT AT"
27 [ "$SLOW" = "no" ] && EXCEPT_SLOW="1 2 3 4 6 12 16 44a      44b    65 66 67 68"
28
29 build_test_filter
30
31 check_and_setup_lustre
32
33 mkdir -p $DIR
34
35 assert_DIR
36 rm -rf $DIR/[df][0-9]*
37
38 test_0a() {     # was test_0
39     sleep 10
40     mkdir $DIR/$tfile
41     replay_barrier $SINGLEMDS
42     fail $SINGLEMDS
43     rmdir $DIR/$tfile
44 }
45 run_test 0a "empty replay"
46
47 test_0b() {
48     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
49
50     # this test attempts to trigger a race in the precreation code,
51     # and must run before any other objects are created on the filesystem
52     fail ost1
53     createmany -o $DIR/$tfile 20 || return 1
54     unlinkmany $DIR/$tfile 20 || return 2
55 }
56 run_test 0b "ensure object created after recover exists. (3284)"
57
58 test_0d() {
59     replay_barrier $SINGLEMDS
60     umount $MOUNT
61     facet_failover $SINGLEMDS
62     zconf_mount `hostname` $MOUNT || error "mount fails"
63     client_up || error "post-failover df failed"
64 }
65 run_test 0d "expired recovery with no clients"
66
67 test_1() {
68     replay_barrier $SINGLEMDS
69     mcreate $DIR/$tfile
70     fail $SINGLEMDS
71     $CHECKSTAT -t file $DIR/$tfile || return 1
72     rm $DIR/$tfile
73 }
74 run_test 1 "simple create"
75
76 test_2a() {
77     replay_barrier $SINGLEMDS
78     touch $DIR/$tfile
79     fail $SINGLEMDS
80     $CHECKSTAT -t file $DIR/$tfile || return 1
81     rm $DIR/$tfile
82 }
83 run_test 2a "touch"
84
85 test_2b() {
86     mcreate $DIR/$tfile
87     replay_barrier $SINGLEMDS
88     touch $DIR/$tfile
89     fail $SINGLEMDS
90     $CHECKSTAT -t file $DIR/$tfile || return 1
91     rm $DIR/$tfile
92 }
93 run_test 2b "touch"
94
95 test_3a() {
96     local file=$DIR/$tfile
97     replay_barrier $SINGLEMDS
98     mcreate $file
99     openfile -f O_DIRECTORY $file
100     fail $SINGLEMDS
101     $CHECKSTAT -t file $file || return 2
102     rm $file
103 }
104 run_test 3a "replay failed open(O_DIRECTORY)"
105
106 test_3b() {
107     replay_barrier $SINGLEMDS
108 #define OBD_FAIL_MDS_OPEN_PACK | OBD_FAIL_ONCE
109     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000114"
110     touch $DIR/$tfile
111     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
112     fail $SINGLEMDS
113     $CHECKSTAT -t file $DIR/$tfile && return 2
114     return 0
115 }
116 run_test 3b "replay failed open -ENOMEM"
117
118 test_3c() {
119     replay_barrier $SINGLEMDS
120 #define OBD_FAIL_MDS_ALLOC_OBDO | OBD_FAIL_ONCE
121     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000128"
122     touch $DIR/$tfile
123     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
124     fail $SINGLEMDS
125
126     $CHECKSTAT -t file $DIR/$tfile && return 2
127     return 0
128 }
129 run_test 3c "replay failed open -ENOMEM"
130
131 test_4a() {     # was test_4
132     replay_barrier $SINGLEMDS
133     for i in `seq 10`; do
134         echo "tag-$i" > $DIR/$tfile-$i
135     done
136     fail $SINGLEMDS
137     for i in `seq 10`; do
138       grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
139     done
140 }
141 run_test 4a "|x| 10 open(O_CREAT)s"
142
143 test_4b() {
144     replay_barrier $SINGLEMDS
145     rm -rf $DIR/$tfile-*
146     fail $SINGLEMDS
147     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
148 }
149 run_test 4b "|x| rm 10 files"
150
151 # The idea is to get past the first block of precreated files on both
152 # osts, and then replay.
153 test_5() {
154     replay_barrier $SINGLEMDS
155     for i in `seq 220`; do
156         echo "tag-$i" > $DIR/$tfile-$i
157     done
158     fail $SINGLEMDS
159     for i in `seq 220`; do
160       grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
161     done
162     rm -rf $DIR/$tfile-*
163     sleep 3
164     # waiting for commitment of removal
165 }
166 run_test 5 "|x| 220 open(O_CREAT)"
167
168
169 test_6a() {     # was test_6
170     mkdir -p $DIR/$tdir
171     replay_barrier $SINGLEMDS
172     mcreate $DIR/$tdir/$tfile
173     fail $SINGLEMDS
174     $CHECKSTAT -t dir $DIR/$tdir || return 1
175     $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
176     sleep 2
177     # waiting for log process thread
178 }
179 run_test 6a "mkdir + contained create"
180
181 test_6b() {
182     mkdir -p $DIR/$tdir
183     replay_barrier $SINGLEMDS
184     rm -rf $DIR/$tdir
185     fail $SINGLEMDS
186     $CHECKSTAT -t dir $DIR/$tdir && return 1 || true
187 }
188 run_test 6b "|X| rmdir"
189
190 test_7() {
191     mkdir -p $DIR/$tdir
192     replay_barrier $SINGLEMDS
193     mcreate $DIR/$tdir/$tfile
194     fail $SINGLEMDS
195     $CHECKSTAT -t dir $DIR/$tdir || return 1
196     $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
197     rm -fr $DIR/$tdir
198 }
199 run_test 7 "mkdir |X| contained create"
200
201 test_8() {
202     # make sure no side-effect from previous test.
203     rm -f $DIR/$tfile
204     replay_barrier $SINGLEMDS
205     multiop_bg_pause $DIR/$tfile mo_c || return 4
206     MULTIPID=$!
207     fail $SINGLEMDS
208     ls $DIR/$tfile
209     $CHECKSTAT -t file $DIR/$tfile || return 1
210     kill -USR1 $MULTIPID || return 2
211     wait $MULTIPID || return 3
212     rm $DIR/$tfile
213 }
214 run_test 8 "creat open |X| close"
215
216 test_9() {
217     replay_barrier $SINGLEMDS
218     mcreate $DIR/$tfile
219     local old_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
220     fail $SINGLEMDS
221     local new_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
222
223     echo " old_inum == $old_inum, new_inum == $new_inum"
224     if [ $old_inum -eq $new_inum  ] ;
225     then
226         echo " old_inum and new_inum match"
227     else
228         echo "!!!! old_inum and new_inum NOT match"
229         return 1
230     fi
231     rm $DIR/$tfile
232 }
233 run_test 9  "|X| create (same inum/gen)"
234
235 test_10() {
236     mcreate $DIR/$tfile
237     replay_barrier $SINGLEMDS
238     mv $DIR/$tfile $DIR/$tfile-2
239     rm -f $DIR/$tfile
240     fail $SINGLEMDS
241     $CHECKSTAT $DIR/$tfile && return 1
242     $CHECKSTAT $DIR/$tfile-2 ||return 2
243     rm $DIR/$tfile-2
244     return 0
245 }
246 run_test 10 "create |X| rename unlink"
247
248 test_11() {
249     mcreate $DIR/$tfile
250     echo "old" > $DIR/$tfile
251     mv $DIR/$tfile $DIR/$tfile-2
252     replay_barrier $SINGLEMDS
253     echo "new" > $DIR/$tfile
254     grep new $DIR/$tfile
255     grep old $DIR/$tfile-2
256     fail $SINGLEMDS
257     grep new $DIR/$tfile || return 1
258     grep old $DIR/$tfile-2 || return 2
259 }
260 run_test 11 "create open write rename |X| create-old-name read"
261
262 test_12() {
263     mcreate $DIR/$tfile
264     multiop_bg_pause $DIR/$tfile o_tSc || return 3
265     pid=$!
266     rm -f $DIR/$tfile
267     replay_barrier $SINGLEMDS
268     kill -USR1 $pid
269     wait $pid || return 1
270
271     fail $SINGLEMDS
272     [ -e $DIR/$tfile ] && return 2
273     return 0
274 }
275 run_test 12 "open, unlink |X| close"
276
277
278 # 1777 - replay open after committed chmod that would make
279 #        a regular open a failure
280 test_13() {
281     mcreate $DIR/$tfile
282     multiop_bg_pause $DIR/$tfile O_wc || return 3
283     pid=$!
284     chmod 0 $DIR/$tfile
285     $CHECKSTAT -p 0 $DIR/$tfile
286     replay_barrier $SINGLEMDS
287     fail $SINGLEMDS
288     kill -USR1 $pid
289     wait $pid || return 1
290
291     $CHECKSTAT -s 1 -p 0 $DIR/$tfile || return 2
292     rm $DIR/$tfile || return 4
293     return 0
294 }
295 run_test 13 "open chmod 0 |x| write close"
296
297 test_14() {
298     multiop_bg_pause $DIR/$tfile O_tSc || return 4
299     pid=$!
300     rm -f $DIR/$tfile
301     replay_barrier $SINGLEMDS
302     kill -USR1 $pid || return 1
303     wait $pid || return 2
304
305     fail $SINGLEMDS
306     [ -e $DIR/$tfile ] && return 3
307     return 0
308 }
309 run_test 14 "open(O_CREAT), unlink |X| close"
310
311 test_15() {
312     multiop_bg_pause $DIR/$tfile O_tSc || return 5
313     pid=$!
314     rm -f $DIR/$tfile
315     replay_barrier $SINGLEMDS
316     touch $DIR/g11 || return 1
317     kill -USR1 $pid
318     wait $pid || return 2
319
320     fail $SINGLEMDS
321     [ -e $DIR/$tfile ] && return 3
322     touch $DIR/h11 || return 4
323     return 0
324 }
325 run_test 15 "open(O_CREAT), unlink |X|  touch new, close"
326
327
328 test_16() {
329     replay_barrier $SINGLEMDS
330     mcreate $DIR/$tfile
331     munlink $DIR/$tfile
332     mcreate $DIR/$tfile-2
333     fail $SINGLEMDS
334     [ -e $DIR/$tfile ] && return 1
335     [ -e $DIR/$tfile-2 ] || return 2
336     munlink $DIR/$tfile-2 || return 3
337 }
338 run_test 16 "|X| open(O_CREAT), unlink, touch new,  unlink new"
339
340 test_17() {
341     replay_barrier $SINGLEMDS
342     multiop_bg_pause $DIR/$tfile O_c || return 4
343     pid=$!
344     fail $SINGLEMDS
345     kill -USR1 $pid || return 1
346     wait $pid || return 2
347     $CHECKSTAT -t file $DIR/$tfile || return 3
348     rm $DIR/$tfile
349 }
350 run_test 17 "|X| open(O_CREAT), |replay| close"
351
352 test_18() {
353     replay_barrier $SINGLEMDS
354     multiop_bg_pause $DIR/$tfile O_tSc || return 8
355     pid=$!
356     rm -f $DIR/$tfile
357     touch $DIR/$tfile-2 || return 1
358     echo "pid: $pid will close"
359     kill -USR1 $pid
360     wait $pid || return 2
361
362     fail $SINGLEMDS
363     [ -e $DIR/$tfile ] && return 3
364     [ -e $DIR/$tfile-2 ] || return 4
365     # this touch frequently fails
366     touch $DIR/$tfile-3 || return 5
367     munlink $DIR/$tfile-2 || return 6
368     munlink $DIR/$tfile-3 || return 7
369     return 0
370 }
371 run_test 18 "|X| open(O_CREAT), unlink, touch new, close, touch, unlink"
372
373 # bug 1855 (a simpler form of test_11 above)
374 test_19() {
375     replay_barrier $SINGLEMDS
376     mcreate $DIR/$tfile
377     echo "old" > $DIR/$tfile
378     mv $DIR/$tfile $DIR/$tfile-2
379     grep old $DIR/$tfile-2
380     fail $SINGLEMDS
381     grep old $DIR/$tfile-2 || return 2
382 }
383 run_test 19 "|X| mcreate, open, write, rename "
384
385 test_20a() {    # was test_20
386     replay_barrier $SINGLEMDS
387     multiop_bg_pause $DIR/$tfile O_tSc || return 3
388     pid=$!
389     rm -f $DIR/$tfile
390
391     fail $SINGLEMDS
392     kill -USR1 $pid
393     wait $pid || return 1
394     [ -e $DIR/$tfile ] && return 2
395     return 0
396 }
397 run_test 20a "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
398
399 test_20b() { # bug 10480
400     BEFOREUSED=`df -P $DIR | tail -1 | awk '{ print $3 }'`
401
402     dd if=/dev/zero of=$DIR/$tfile bs=4k count=10000 &
403     pid=$!
404     while [ ! -e $DIR/$tfile ] ; do
405         usleep 60                           # give dd a chance to start
406     done
407
408     lfs getstripe $DIR/$tfile || return 1
409     rm -f $DIR/$tfile || return 2       # make it an orphan
410     mds_evict_client
411     client_up || client_up || true    # reconnect
412
413     fail $SINGLEMDS                            # start orphan recovery
414     wait_recovery_complete $SINGLEMDS || error "MDS recovery not done"
415     wait_mds_ost_sync || return 3
416     AFTERUSED=`df -P $DIR | tail -1 | awk '{ print $3 }'`
417     log "before $BEFOREUSED, after $AFTERUSED"
418     [ $AFTERUSED -gt $((BEFOREUSED + 20)) ] && \
419         error "after $AFTERUSED > before $BEFOREUSED"
420     return 0
421 }
422 run_test 20b "write, unlink, eviction, replay, (test mds_cleanup_orphans)"
423
424 test_20c() { # bug 10480
425     multiop_bg_pause $DIR/$tfile Ow_c || return 1
426     pid=$!
427
428     ls -la $DIR/$tfile
429
430     mds_evict_client
431     client_up || client_up || true    # reconnect
432
433     kill -USR1 $pid
434     wait $pid || return 1
435     [ -s $DIR/$tfile ] || error "File was truncated"
436
437     return 0
438 }
439 run_test 20c "check that client eviction does not affect file content"
440
441 test_21() {
442     replay_barrier $SINGLEMDS
443     multiop_bg_pause $DIR/$tfile O_tSc || return 5
444     pid=$!
445     rm -f $DIR/$tfile
446     touch $DIR/g11 || return 1
447
448     fail $SINGLEMDS
449     kill -USR1 $pid
450     wait $pid || return 2
451     [ -e $DIR/$tfile ] && return 3
452     touch $DIR/h11 || return 4
453     return 0
454 }
455 run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"
456
457 test_22() {
458     multiop_bg_pause $DIR/$tfile O_tSc || return 3
459     pid=$!
460
461     replay_barrier $SINGLEMDS
462     rm -f $DIR/$tfile
463
464     fail $SINGLEMDS
465     kill -USR1 $pid
466     wait $pid || return 1
467     [ -e $DIR/$tfile ] && return 2
468     return 0
469 }
470 run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"
471
472 test_23() {
473     multiop_bg_pause $DIR/$tfile O_tSc || return 5
474     pid=$!
475
476     replay_barrier $SINGLEMDS
477     rm -f $DIR/$tfile
478     touch $DIR/g11 || return 1
479
480     fail $SINGLEMDS
481     kill -USR1 $pid
482     wait $pid || return 2
483     [ -e $DIR/$tfile ] && return 3
484     touch $DIR/h11 || return 4
485     return 0
486 }
487 run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"
488
489 test_24() {
490     multiop_bg_pause $DIR/$tfile O_tSc || return 3
491     pid=$!
492
493     replay_barrier $SINGLEMDS
494     fail $SINGLEMDS
495     rm -f $DIR/$tfile
496     kill -USR1 $pid
497     wait $pid || return 1
498     [ -e $DIR/$tfile ] && return 2
499     return 0
500 }
501 run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"
502
503 test_25() {
504     multiop_bg_pause $DIR/$tfile O_tSc || return 3
505     pid=$!
506     rm -f $DIR/$tfile
507
508     replay_barrier $SINGLEMDS
509     fail $SINGLEMDS
510     kill -USR1 $pid
511     wait $pid || return 1
512     [ -e $DIR/$tfile ] && return 2
513     return 0
514 }
515 run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
516
517 test_26() {
518     replay_barrier $SINGLEMDS
519     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
520     pid1=$!
521     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
522     pid2=$!
523     rm -f $DIR/$tfile-1
524     rm -f $DIR/$tfile-2
525     kill -USR1 $pid2
526     wait $pid2 || return 1
527
528     fail $SINGLEMDS
529     kill -USR1 $pid1
530     wait $pid1 || return 2
531     [ -e $DIR/$tfile-1 ] && return 3
532     [ -e $DIR/$tfile-2 ] && return 4
533     return 0
534 }
535 run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"
536
537 test_27() {
538     replay_barrier $SINGLEMDS
539     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
540     pid1=$!
541     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
542     pid2=$!
543     rm -f $DIR/$tfile-1
544     rm -f $DIR/$tfile-2
545
546     fail $SINGLEMDS
547     kill -USR1 $pid1
548     wait $pid1 || return 1
549     kill -USR1 $pid2
550     wait $pid2 || return 2
551     [ -e $DIR/$tfile-1 ] && return 3
552     [ -e $DIR/$tfile-2 ] && return 4
553     return 0
554 }
555 run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"
556
557 test_28() {
558     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
559     pid1=$!
560     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
561     pid2=$!
562     replay_barrier $SINGLEMDS
563     rm -f $DIR/$tfile-1
564     rm -f $DIR/$tfile-2
565     kill -USR1 $pid2
566     wait $pid2 || return 1
567
568     fail $SINGLEMDS
569     kill -USR1 $pid1
570     wait $pid1 || return 2
571     [ -e $DIR/$tfile-1 ] && return 3
572     [ -e $DIR/$tfile-2 ] && return 4
573     return 0
574 }
575 run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"
576
577 test_29() {
578     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
579     pid1=$!
580     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
581     pid2=$!
582     replay_barrier $SINGLEMDS
583     rm -f $DIR/$tfile-1
584     rm -f $DIR/$tfile-2
585
586     fail $SINGLEMDS
587     kill -USR1 $pid1
588     wait $pid1 || return 1
589     kill -USR1 $pid2
590     wait $pid2 || return 2
591     [ -e $DIR/$tfile-1 ] && return 3
592     [ -e $DIR/$tfile-2 ] && return 4
593     return 0
594 }
595 run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"
596
597 test_30() {
598     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
599     pid1=$!
600     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
601     pid2=$!
602     rm -f $DIR/$tfile-1
603     rm -f $DIR/$tfile-2
604
605     replay_barrier $SINGLEMDS
606     fail $SINGLEMDS
607     kill -USR1 $pid1
608     wait $pid1 || return 1
609     kill -USR1 $pid2
610     wait $pid2 || return 2
611     [ -e $DIR/$tfile-1 ] && return 3
612     [ -e $DIR/$tfile-2 ] && return 4
613     return 0
614 }
615 run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"
616
617 test_31() {
618     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
619     pid1=$!
620     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
621     pid2=$!
622     rm -f $DIR/$tfile-1
623
624     replay_barrier $SINGLEMDS
625     rm -f $DIR/$tfile-2
626     fail $SINGLEMDS
627     kill -USR1 $pid1
628     wait $pid1 || return 1
629     kill -USR1 $pid2
630     wait $pid2 || return 2
631     [ -e $DIR/$tfile-1 ] && return 3
632     [ -e $DIR/$tfile-2 ] && return 4
633     return 0
634 }
635 run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"
636
637 # tests for bug 2104; completion without crashing is success.  The close is
638 # stale, but we always return 0 for close, so the app never sees it.
639 test_32() {
640     multiop_bg_pause $DIR/$tfile O_c || return 2
641     pid1=$!
642     multiop_bg_pause $DIR/$tfile O_c || return 3
643     pid2=$!
644     mds_evict_client
645     client_up || client_up || return 1
646     kill -USR1 $pid1
647     kill -USR1 $pid2
648     wait $pid1 || return 4
649     wait $pid2 || return 5
650     return 0
651 }
652 run_test 32 "close() notices client eviction; close() after client eviction"
653
654 test_33a() {
655     createmany -o $DIR/$tfile-%d 10
656     replay_barrier_nosync $SINGLEMDS
657     fail_abort $SINGLEMDS
658     # recreate shouldn't fail
659     createmany -o $DIR/$tfile--%d 10 || return 1
660     rm $DIR/$tfile-* -f
661     return 0
662 }
663 run_test 33a "fid seq shouldn't be reused after abort recovery"
664
665 test_33b() {
666     #define OBD_FAIL_SEQ_ALLOC                          0x1311
667     do_facet $SINGLEMDS "lctl set_param fail_loc=0x1311"
668
669     createmany -o $DIR/$tfile-%d 10
670     replay_barrier_nosync $SINGLEMDS
671     fail_abort $SINGLEMDS
672     # recreate shouldn't fail
673     createmany -o $DIR/$tfile--%d 10 || return 1
674     rm $DIR/$tfile-* -f
675     return 0
676 }
677 run_test 33b "test fid seq allocation"
678
679 test_34() {
680     multiop_bg_pause $DIR/$tfile O_c || return 2
681     pid=$!
682     rm -f $DIR/$tfile
683
684     replay_barrier $SINGLEMDS
685     fail_abort $SINGLEMDS
686     kill -USR1 $pid
687     wait $pid || return 3
688     [ -e $DIR/$tfile ] && return 1
689     sync
690     return 0
691 }
692 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
693
694 # bug 2278 - generate one orphan on OST, then destroy it during recovery from llog
695 test_35() {
696     touch $DIR/$tfile
697
698 #define OBD_FAIL_MDS_REINT_NET_REP       0x119
699     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
700     rm -f $DIR/$tfile &
701     sleep 1
702     sync
703     sleep 1
704     # give a chance to remove from MDS
705     fail_abort $SINGLEMDS
706     $CHECKSTAT -t file $DIR/$tfile && return 1 || true
707 }
708 run_test 35 "test recovery from llog for unlink op"
709
710 # b=2432 resent cancel after replay uses wrong cookie,
711 # so don't resend cancels
712 test_36() {
713     replay_barrier $SINGLEMDS
714     touch $DIR/$tfile
715     checkstat $DIR/$tfile
716     facet_failover $SINGLEMDS
717     cancel_lru_locks mdc
718     if dmesg | grep "unknown lock cookie"; then
719         echo "cancel after replay failed"
720         return 1
721     fi
722 }
723 run_test 36 "don't resend cancel"
724
725 # b=2368
726 # directory orphans can't be unlinked from PENDING directory
727 test_37() {
728     rmdir $DIR/$tfile 2>/dev/null
729     multiop_bg_pause $DIR/$tfile dD_c || return 2
730     pid=$!
731     rmdir $DIR/$tfile
732
733     replay_barrier $SINGLEMDS
734     # clear the dmesg buffer so we only see errors from this recovery
735     dmesg -c >/dev/null
736     fail_abort $SINGLEMDS
737     kill -USR1 $pid
738     dmesg | grep  "mds_unlink_orphan.*error .* unlinking orphan" && return 1
739     wait $pid || return 3
740     sync
741     return 0
742 }
743 start_full_debug_logging
744 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
745 stop_full_debug_logging
746
747 test_38() {
748     createmany -o $DIR/$tfile-%d 800
749     unlinkmany $DIR/$tfile-%d 0 400
750     replay_barrier $SINGLEMDS
751     fail $SINGLEMDS
752     unlinkmany $DIR/$tfile-%d 400 400
753     sleep 2
754     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
755 }
756 run_test 38 "test recovery from unlink llog (test llog_gen_rec) "
757
758 test_39() { # bug 4176
759     createmany -o $DIR/$tfile-%d 800
760     replay_barrier $SINGLEMDS
761     unlinkmany $DIR/$tfile-%d 0 400
762     fail $SINGLEMDS
763     unlinkmany $DIR/$tfile-%d 400 400
764     sleep 2
765     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
766 }
767 run_test 39 "test recovery from unlink llog (test llog_gen_rec) "
768
769 count_ost_writes() {
770     lctl get_param -n osc.*.stats | awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
771 }
772
773 #b=2477,2532
774 test_40(){
775     $LCTL mark multiop $MOUNT/$tfile OS_c
776     multiop $MOUNT/$tfile OS_c  &
777     PID=$!
778     writeme -s $MOUNT/${tfile}-2 &
779     WRITE_PID=$!
780     sleep 1
781     facet_failover $SINGLEMDS
782 #define OBD_FAIL_MDS_CONNECT_NET         0x117
783     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000117"
784     kill -USR1 $PID
785     stat1=`count_ost_writes`
786     sleep $TIMEOUT
787     stat2=`count_ost_writes`
788     echo "$stat1, $stat2"
789     if [ $stat1 -lt $stat2 ]; then
790        echo "writes continuing during recovery"
791        RC=0
792     else
793        echo "writes not continuing during recovery, bug 2477"
794        RC=4
795     fi
796     echo "waiting for writeme $WRITE_PID"
797     kill $WRITE_PID
798     wait $WRITE_PID
799
800     echo "waiting for multiop $PID"
801     wait $PID || return 2
802     do_facet client munlink $MOUNT/$tfile  || return 3
803     do_facet client munlink $MOUNT/${tfile}-2  || return 3
804     return $RC
805 }
806 run_test 40 "cause recovery in ptlrpc, ensure IO continues"
807
808
809 #b=2814
810 # make sure that a read to one osc doesn't try to double-unlock its page just
811 # because another osc is invalid.  trigger_group_io used to mistakenly return
812 # an error if any oscs were invalid even after having successfully put rpcs
813 # on valid oscs.  This was fatal if the caller was ll_readpage who unlocked
814 # the page, guarnateeing that the unlock from the RPC completion would
815 # assert on trying to unlock the unlocked page.
816 test_41() {
817     [ $OSTCOUNT -lt 2 ] && \
818         skip_env "skipping test 41: we don't have a second OST to test with" && \
819         return
820
821     local f=$MOUNT/$tfile
822     # make sure the start of the file is ost1
823     lfs setstripe $f -s $((128 * 1024)) -i 0
824     do_facet client dd if=/dev/zero of=$f bs=4k count=1 || return 3
825     cancel_lru_locks osc
826     # fail ost2 and read from ost1
827     local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $ost2_svc)
828     local osc2dev=$(do_facet $SINGLEMDS "lctl get_param -n devices" | \
829         grep $mdtosc | awk '{print $1}')
830     [ -z "$osc2dev" ] && echo "OST: $ost2_svc" && lctl get_param -n devices && return 4
831     do_facet $SINGLEMDS $LCTL --device $osc2dev deactivate || return 1
832     do_facet client dd if=$f of=/dev/null bs=4k count=1 || return 3
833     do_facet $SINGLEMDS $LCTL --device $osc2dev activate || return 2
834     return 0
835 }
836 run_test 41 "read from a valid osc while other oscs are invalid"
837
838 # test MDS recovery after ost failure
839 test_42() {
840     blocks=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
841     createmany -o $DIR/$tfile-%d 800
842     replay_barrier ost1
843     unlinkmany $DIR/$tfile-%d 0 400
844     debugsave
845     lctl set_param debug=-1
846     facet_failover ost1
847
848     # osc is evicted, fs is smaller (but only with failout OSTs (bug 7287)
849     #blocks_after=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
850     #[ $blocks_after -lt $blocks ] || return 1
851     echo wait for MDS to timeout and recover
852     sleep $((TIMEOUT * 2))
853     debugrestore
854     unlinkmany $DIR/$tfile-%d 400 400
855     $CHECKSTAT -t file $DIR/$tfile-* && return 2 || true
856 }
857 run_test 42 "recovery after ost failure"
858
859 # timeout in MDS/OST recovery RPC will LBUG MDS
860 test_43() { # bug 2530
861     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
862
863     replay_barrier $SINGLEMDS
864
865     # OBD_FAIL_OST_CREATE_NET 0x204
866     do_facet ost1 "lctl set_param fail_loc=0x80000204"
867     fail $SINGLEMDS
868     sleep 10
869     do_facet ost1 "lctl set_param fail_loc=0"
870
871     return 0
872 }
873 run_test 43 "mds osc import failure during recovery; don't LBUG"
874
875 test_44a() { # was test_44
876     local at_max_saved=0
877
878     mdcdev=`lctl get_param -n devices | awk '/MDT0000-mdc-/ {print $1}'`
879     [ "$mdcdev" ] || return 2
880     [ $(echo $mdcdev | wc -w) -eq 1 ] || { echo $mdcdev=$mdcdev && return 3; }
881
882     # adaptive timeouts slow this way down
883     if at_is_enabled; then
884         at_max_saved=$(at_max_get mds)
885         at_max_set 40 mds
886     fi
887
888     for i in `seq 1 10`; do
889         echo "$i of 10 ($(date +%s))"
890         do_facet $SINGLEMDS "lctl get_param -n mdt.*.mdt.timeouts | grep service"
891         #define OBD_FAIL_TGT_CONN_RACE     0x701
892         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000701"
893         # lctl below may fail, it is valid case
894         $LCTL --device $mdcdev recover
895         df $MOUNT
896     done
897     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
898     [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds
899     return 0
900 }
901 run_test 44a "race in target handle connect"
902
903 test_44b() {
904     local mdcdev=`lctl get_param -n devices | awk '/MDT0000-mdc-/ {print $1}'`
905     [ "$mdcdev" ] || return 2
906     [ $(echo $mdcdev | wc -w) -eq 1 ] || { echo $mdcdev=$mdcdev && return 3; }
907
908     for i in `seq 1 10`; do
909         echo "$i of 10 ($(date +%s))"
910         do_facet $SINGLEMDS "lctl get_param -n mdt.*.mdt.timeouts | grep service"
911         #define OBD_FAIL_TGT_DELAY_RECONNECT 0x704
912         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000704"
913         # lctl below may fail, it is valid case
914         $LCTL --device $mdcdev recover
915         df $MOUNT
916     done
917     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
918     return 0
919 }
920 run_test 44b "race in target handle connect"
921
922 # Handle failed close
923 test_45() {
924     mdcdev=`lctl get_param -n devices | awk '/MDT0000-mdc-/ {print $1}'`
925     [ "$mdcdev" ] || return 2
926     [ $(echo $mdcdev | wc -w) -eq 1 ] || { echo $mdcdev=$mdcdev && return 3; }
927
928     $LCTL --device $mdcdev recover || return 6 
929
930     multiop_bg_pause $DIR/$tfile O_c || return 1
931     pid=$!
932
933     # This will cause the CLOSE to fail before even
934     # allocating a reply buffer
935     $LCTL --device $mdcdev deactivate || return 4
936
937     # try the close
938     kill -USR1 $pid
939     wait $pid || return 1
940
941     $LCTL --device $mdcdev activate || return 5
942     sleep 1
943
944     $CHECKSTAT -t file $DIR/$tfile || return 2
945     return 0
946 }
947 run_test 45 "Handle failed close"
948
949 test_46() {
950     dmesg -c >/dev/null
951     drop_reply "touch $DIR/$tfile"
952     fail $SINGLEMDS
953     # ironically, the previous test, 45, will cause a real forced close,
954     # so just look for one for this test
955     dmesg | grep -i "force closing client file handle for $tfile" && return 1
956     return 0
957 }
958 run_test 46 "Don't leak file handle after open resend (3325)"
959
960 test_47() { # bug 2824
961     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
962
963     # create some files to make sure precreate has been done on all
964     # OSTs. (just in case this test is run independently)
965     createmany -o $DIR/$tfile 20  || return 1
966
967     # OBD_FAIL_OST_CREATE_NET 0x204
968     fail ost1
969     do_facet ost1 "lctl set_param fail_loc=0x80000204"
970     client_up || return 2
971
972     # let the MDS discover the OST failure, attempt to recover, fail
973     # and recover again.
974     sleep $((3 * TIMEOUT))
975
976     # Without 2824, this createmany would hang
977     createmany -o $DIR/$tfile 20 || return 3
978     unlinkmany $DIR/$tfile 20 || return 4
979
980     do_facet ost1 "lctl set_param fail_loc=0"
981     return 0
982 }
983 run_test 47 "MDS->OSC failure during precreate cleanup (2824)"
984
985 test_48() {
986     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
987     [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
988
989     replay_barrier $SINGLEMDS
990     createmany -o $DIR/$tfile 20  || return 1
991     # OBD_FAIL_OST_EROFS 0x216
992     facet_failover $SINGLEMDS
993     do_facet ost1 "lctl set_param fail_loc=0x80000216"
994     client_up || return 2
995
996     createmany -o $DIR/$tfile 20 20 || return 2
997     unlinkmany $DIR/$tfile 40 || return 3
998     return 0
999 }
1000 run_test 48 "MDS->OSC failure during precreate cleanup (2824)"
1001
1002 test_50() {
1003     local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $ost1_svc) 
1004     local oscdev=$(do_facet $SINGLEMDS "lctl get_param -n devices" | \
1005         grep $mdtosc | awk '{print $1}')
1006     [ "$oscdev" ] || return 1
1007     do_facet $SINGLEMDS $LCTL --device $oscdev recover || return 2
1008     do_facet $SINGLEMDS $LCTL --device $oscdev recover || return 3
1009     # give the mds_lov_sync threads a chance to run
1010     sleep 5
1011 }
1012 run_test 50 "Double OSC recovery, don't LASSERT (3812)"
1013
1014 # b3764 timed out lock replay
1015 test_52() {
1016     touch $DIR/$tfile
1017     cancel_lru_locks mdc
1018
1019     multiop $DIR/$tfile s || return 1
1020     replay_barrier $SINGLEMDS
1021 #define OBD_FAIL_LDLM_REPLY              0x30c
1022     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000030c"
1023     fail $SINGLEMDS || return 2
1024     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1025
1026     $CHECKSTAT -t file $DIR/$tfile-* && return 3 || true
1027 }
1028 run_test 52 "time out lock replay (3764)"
1029
1030 # bug 3462 - simultaneous MDC requests
1031 test_53a() {
1032         cancel_lru_locks mdc    # cleanup locks from former test cases
1033         mkdir -p $DIR/${tdir}-1
1034         mkdir -p $DIR/${tdir}-2
1035         multiop $DIR/${tdir}-1/f O_c &
1036         close_pid=$!
1037         # give multiop a change to open
1038         sleep 1
1039
1040         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1041         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1042         kill -USR1 $close_pid
1043         cancel_lru_locks mdc    # force the close
1044         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1045
1046         mcreate $DIR/${tdir}-2/f || return 1
1047
1048         # close should still be here
1049         [ -d /proc/$close_pid ] || return 2
1050
1051         replay_barrier_nodf $SINGLEMDS
1052         fail $SINGLEMDS
1053         wait $close_pid || return 3
1054
1055         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1056         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1057         rm -rf $DIR/${tdir}-*
1058 }
1059 run_test 53a "|X| close request while two MDC requests in flight"
1060
1061 test_53b() {
1062         cancel_lru_locks mdc    # cleanup locks from former test cases
1063         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1064
1065         mkdir -p $DIR/${tdir}-1
1066         mkdir -p $DIR/${tdir}-2
1067         multiop_bg_pause $DIR/${tdir}-1/f O_c || return 6
1068         close_pid=$!
1069
1070         #define OBD_FAIL_MDS_REINT_NET 0x107
1071         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1072         mcreate $DIR/${tdir}-2/f &
1073         open_pid=$!
1074         sleep 1
1075
1076         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1077         kill -USR1 $close_pid
1078         cancel_lru_locks mdc    # force the close
1079         wait $close_pid || return 1
1080         # open should still be here
1081         [ -d /proc/$open_pid ] || return 2
1082
1083         replay_barrier_nodf $SINGLEMDS
1084         fail $SINGLEMDS
1085         wait $open_pid || return 3
1086
1087         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1088         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1089         rm -rf $DIR/${tdir}-*
1090 }
1091 run_test 53b "|X| open request while two MDC requests in flight"
1092
1093 test_53c() {
1094         cancel_lru_locks mdc    # cleanup locks from former test cases
1095         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1096
1097         mkdir -p $DIR/${tdir}-1
1098         mkdir -p $DIR/${tdir}-2
1099         multiop $DIR/${tdir}-1/f O_c &
1100         close_pid=$!
1101
1102         #define OBD_FAIL_MDS_REINT_NET 0x107
1103         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1104         mcreate $DIR/${tdir}-2/f &
1105         open_pid=$!
1106         sleep 1
1107
1108         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1109         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1110         kill -USR1 $close_pid
1111         cancel_lru_locks mdc    # force the close
1112
1113         #bz20647: make sure all pids are exists before failover
1114         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1115         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1116         replay_barrier_nodf $SINGLEMDS
1117         fail_nodf $SINGLEMDS
1118         wait $open_pid || return 1
1119         sleep 2
1120         # close should be gone
1121         [ -d /proc/$close_pid ] && return 2
1122         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1123
1124         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1125         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1126         rm -rf $DIR/${tdir}-*
1127 }
1128 run_test 53c "|X| open request and close request while two MDC requests in flight"
1129
1130 test_53d() {
1131         cancel_lru_locks mdc    # cleanup locks from former test cases
1132         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1133
1134         mkdir -p $DIR/${tdir}-1
1135         mkdir -p $DIR/${tdir}-2
1136         multiop $DIR/${tdir}-1/f O_c &
1137         close_pid=$!
1138         # give multiop a chance to open
1139         sleep 1
1140
1141         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1142         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1143         kill -USR1 $close_pid
1144         cancel_lru_locks mdc    # force the close
1145         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1146         mcreate $DIR/${tdir}-2/f || return 1
1147
1148         # close should still be here
1149         [ -d /proc/$close_pid ] || return 2
1150         fail $SINGLEMDS
1151         wait $close_pid || return 3
1152
1153         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1154         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1155         rm -rf $DIR/${tdir}-*
1156 }
1157 run_test 53d "|X| close reply while two MDC requests in flight"
1158
1159 test_53e() {
1160         cancel_lru_locks mdc    # cleanup locks from former test cases
1161         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1162
1163         mkdir -p $DIR/${tdir}-1
1164         mkdir -p $DIR/${tdir}-2
1165         multiop $DIR/${tdir}-1/f O_c &
1166         close_pid=$!
1167
1168         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1169         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1170         mcreate $DIR/${tdir}-2/f &
1171         open_pid=$!
1172         sleep 1
1173
1174         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1175         kill -USR1 $close_pid
1176         cancel_lru_locks mdc    # force the close
1177         wait $close_pid || return 1
1178         # open should still be here
1179         [ -d /proc/$open_pid ] || return 2
1180
1181         replay_barrier_nodf $SINGLEMDS
1182         fail $SINGLEMDS
1183         wait $open_pid || return 3
1184
1185         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1186         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1187         rm -rf $DIR/${tdir}-*
1188 }
1189 run_test 53e "|X| open reply while two MDC requests in flight"
1190
1191 test_53f() {
1192         cancel_lru_locks mdc    # cleanup locks from former test cases
1193         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1194
1195         mkdir -p $DIR/${tdir}-1
1196         mkdir -p $DIR/${tdir}-2
1197         multiop $DIR/${tdir}-1/f O_c &
1198         close_pid=$!
1199
1200         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1201         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1202         mcreate $DIR/${tdir}-2/f &
1203         open_pid=$!
1204         sleep 1
1205
1206         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1207         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1208         kill -USR1 $close_pid
1209         cancel_lru_locks mdc    # force the close
1210
1211         #bz20647: make sure all pids are exists before failover
1212         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1213         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1214         replay_barrier_nodf $SINGLEMDS
1215         fail_nodf $SINGLEMDS
1216         wait $open_pid || return 1
1217         sleep 2
1218         # close should be gone
1219         [ -d /proc/$close_pid ] && return 2
1220         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1221
1222         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1223         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1224         rm -rf $DIR/${tdir}-*
1225 }
1226 run_test 53f "|X| open reply and close reply while two MDC requests in flight"
1227
1228 test_53g() {
1229         cancel_lru_locks mdc    # cleanup locks from former test cases
1230         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1231
1232         mkdir -p $DIR/${tdir}-1
1233         mkdir -p $DIR/${tdir}-2
1234         multiop $DIR/${tdir}-1/f O_c &
1235         close_pid=$!
1236
1237         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1238         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1239         mcreate $DIR/${tdir}-2/f &
1240         open_pid=$!
1241         sleep 1
1242
1243         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1244         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1245         kill -USR1 $close_pid
1246         cancel_lru_locks mdc    # force the close
1247         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1248
1249         #bz20647: make sure all pids are exists before failover
1250         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1251         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1252         replay_barrier_nodf $SINGLEMDS
1253         fail_nodf $SINGLEMDS
1254         wait $open_pid || return 1
1255         sleep 2
1256         # close should be gone
1257         [ -d /proc/$close_pid ] && return 2
1258
1259         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1260         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1261         rm -rf $DIR/${tdir}-*
1262 }
1263 run_test 53g "|X| drop open reply and close request while close and open are both in flight"
1264
1265 test_53h() {
1266         cancel_lru_locks mdc    # cleanup locks from former test cases
1267         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1268
1269         mkdir -p $DIR/${tdir}-1
1270         mkdir -p $DIR/${tdir}-2
1271         multiop $DIR/${tdir}-1/f O_c &
1272         close_pid=$!
1273
1274         #define OBD_FAIL_MDS_REINT_NET 0x107
1275         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1276         mcreate $DIR/${tdir}-2/f &
1277         open_pid=$!
1278         sleep 1
1279
1280         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1281         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1282         kill -USR1 $close_pid
1283         cancel_lru_locks mdc    # force the close
1284         sleep 1
1285
1286         #bz20647: make sure all pids are exists before failover
1287         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1288         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1289         replay_barrier_nodf $SINGLEMDS
1290         fail_nodf $SINGLEMDS
1291         wait $open_pid || return 1
1292         sleep 2
1293         # close should be gone
1294         [ -d /proc/$close_pid ] && return 2
1295         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1296
1297         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1298         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1299         rm -rf $DIR/${tdir}-*
1300 }
1301 run_test 53h "|X| open request and close reply while two MDC requests in flight"
1302
1303 #b_cray 54 "|X| open request and close reply while two MDC requests in flight"
1304
1305 #b3761 ASSERTION(hash != 0) failed
1306 test_55() {
1307 # OBD_FAIL_MDS_OPEN_CREATE | OBD_FAIL_ONCE
1308     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012b"
1309     touch $DIR/$tfile &
1310     # give touch a chance to run
1311     sleep 5
1312     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1313     rm $DIR/$tfile
1314     return 0
1315 }
1316 run_test 55 "let MDS_CHECK_RESENT return the original return code instead of 0"
1317
1318 #b3440 ASSERTION(rec->ur_fid2->id) failed
1319 test_56() {
1320     ln -s foo $DIR/$tfile
1321     replay_barrier $SINGLEMDS
1322     #drop_reply "cat $DIR/$tfile"
1323     fail $SINGLEMDS
1324     sleep 10
1325 }
1326 run_test 56 "don't replay a symlink open request (3440)"
1327
1328 #recovery one mds-ost setattr from llog
1329 test_57() {
1330 #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1331     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1332     touch $DIR/$tfile
1333     replay_barrier $SINGLEMDS
1334     fail $SINGLEMDS
1335     sleep 1
1336     $CHECKSTAT -t file $DIR/$tfile || return 1
1337     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1338     rm $DIR/$tfile
1339 }
1340 run_test 57 "test recovery from llog for setattr op"
1341
1342 #recovery many mds-ost setattr from llog
1343 test_58a() {
1344     mkdir -p $DIR/$tdir
1345 #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1346     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1347     createmany -o $DIR/$tdir/$tfile-%d 2500
1348     replay_barrier $SINGLEMDS
1349     fail $SINGLEMDS
1350     sleep 2
1351     $CHECKSTAT -t file $DIR/$tdir/$tfile-* >/dev/null || return 1
1352     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1353     unlinkmany $DIR/$tdir/$tfile-%d 2500
1354     rmdir $DIR/$tdir
1355 }
1356 run_test 58a "test recovery from llog for setattr op (test llog_gen_rec)"
1357
1358 test_58b() {
1359     mount_client $MOUNT2
1360     mkdir -p $DIR/$tdir
1361     touch $DIR/$tdir/$tfile
1362     replay_barrier $SINGLEMDS
1363     setfattr -n trusted.foo -v bar $DIR/$tdir/$tfile
1364     fail $SINGLEMDS
1365     VAL=`getfattr --absolute-names --only-value -n trusted.foo $MOUNT2/$tdir/$tfile`
1366     [ x$VAL = x"bar" ] || return 1
1367     rm -f $DIR/$tdir/$tfile
1368     rmdir $DIR/$tdir
1369     zconf_umount `hostname` $MOUNT2
1370 }
1371 run_test 58b "test replay of setxattr op"
1372
1373 test_58c() { # bug 16570
1374         mount_client $MOUNT2
1375         mkdir -p $DIR/$tdir
1376         touch $DIR/$tdir/$tfile
1377         drop_request "setfattr -n trusted.foo -v bar $DIR/$tdir/$tfile" || \
1378                 return 1
1379         VAL=`getfattr --absolute-names --only-value -n trusted.foo $MOUNT2/$tdir/$tfile`
1380         [ x$VAL = x"bar" ] || return 2
1381         drop_reint_reply "setfattr -n trusted.foo1 -v bar1 $DIR/$tdir/$tfile" || \
1382                 return 3
1383         VAL=`getfattr --absolute-names --only-value -n trusted.foo1 $MOUNT2/$tdir/$tfile`
1384         [ x$VAL = x"bar1" ] || return 4
1385         rm -f $DIR/$tdir/$tfile
1386         rmdir $DIR/$tdir
1387         zconf_umount `hostname` $MOUNT2
1388 }
1389 run_test 58c "resend/reconstruct setxattr op"
1390
1391 # log_commit_thread vs filter_destroy race used to lead to import use after free
1392 # bug 11658
1393 test_59() {
1394     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1395
1396     mkdir -p $DIR/$tdir
1397     createmany -o $DIR/$tdir/$tfile-%d 200
1398     sync
1399     unlinkmany $DIR/$tdir/$tfile-%d 200
1400 #define OBD_FAIL_PTLRPC_DELAY_RECOV       0x507
1401     do_facet ost1 "lctl set_param fail_loc=0x507"
1402     fail ost1
1403     fail $SINGLEMDS
1404     do_facet ost1 "lctl set_param fail_loc=0x0"
1405     sleep 20
1406     rmdir $DIR/$tdir
1407 }
1408 run_test 59 "test log_commit_thread vs filter_destroy race"
1409
1410 # race between add unlink llog vs cat log init in post_recovery (only for b1_6)
1411 # bug 12086: should no oops and No ctxt error for this test
1412 test_60() {
1413     mkdir -p $DIR/$tdir
1414     createmany -o $DIR/$tdir/$tfile-%d 200
1415     replay_barrier $SINGLEMDS
1416     unlinkmany $DIR/$tdir/$tfile-%d 0 100
1417     fail $SINGLEMDS
1418     unlinkmany $DIR/$tdir/$tfile-%d 100 100
1419     local no_ctxt=`dmesg | grep "No ctxt"`
1420     [ -z "$no_ctxt" ] || error "ctxt is not initialized in recovery"
1421 }
1422 run_test 60 "test llog post recovery init vs llog unlink"
1423
1424 #test race  llog recovery thread vs llog cleanup
1425 test_61a() {    # was test_61
1426     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1427
1428     mkdir -p $DIR/$tdir
1429     createmany -o $DIR/$tdir/$tfile-%d 800
1430     replay_barrier ost1
1431 #   OBD_FAIL_OST_LLOG_RECOVERY_TIMEOUT 0x221
1432     unlinkmany $DIR/$tdir/$tfile-%d 800
1433     set_nodes_failloc "$(osts_nodes)" 0x80000221
1434     facet_failover ost1
1435     sleep 10
1436     fail ost1
1437     sleep 30
1438     set_nodes_failloc "$(osts_nodes)" 0x0
1439
1440     $CHECKSTAT -t file $DIR/$tdir/$tfile-* && return 1
1441     rmdir $DIR/$tdir
1442 }
1443 run_test 61a "test race llog recovery vs llog cleanup"
1444
1445 #test race  mds llog sync vs llog cleanup
1446 test_61b() {
1447 #   OBD_FAIL_MDS_LLOG_SYNC_TIMEOUT 0x13a
1448     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013a"
1449     facet_failover $SINGLEMDS
1450     sleep 10
1451     fail $SINGLEMDS
1452     do_facet client dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 || return 1
1453 }
1454 run_test 61b "test race mds llog sync vs llog cleanup"
1455
1456 #test race  cancel cookie cb vs llog cleanup
1457 test_61c() {
1458     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1459
1460 #   OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT 0x222
1461     touch $DIR/$tfile
1462     set_nodes_failloc "$(osts_nodes)" 0x80000222
1463     rm $DIR/$tfile
1464     sleep 10
1465     fail ost1
1466     set_nodes_failloc "$(osts_nodes)" 0x0
1467 }
1468 run_test 61c "test race mds llog sync vs llog cleanup"
1469
1470 test_61d() { # bug 16002 # bug 17466 # bug 22137
1471 #   OBD_FAIL_OBD_LLOG_SETUP        0x605
1472     stop mgs
1473     do_facet mgs "lctl set_param fail_loc=0x80000605"
1474     start mgs $MGSDEV $MGS_MOUNT_OPTS && error "mgs start should have failed"
1475     do_facet mgs "lctl set_param fail_loc=0"
1476     start mgs $MGSDEV $MGS_MOUNT_OPTS || error "cannot restart mgs"
1477 }
1478 run_test 61d "error in llog_setup should cleanup the llog context correctly"
1479
1480 test_62() { # Bug 15756 - don't mis-drop resent replay
1481     mkdir -p $DIR/$tdir
1482     replay_barrier $SINGLEMDS
1483     createmany -o $DIR/$tdir/$tfile- 25
1484 #define OBD_FAIL_TGT_REPLAY_DROP         0x707
1485     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000707"
1486     fail $SINGLEMDS
1487     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1488     unlinkmany $DIR/$tdir/$tfile- 25 || return 2
1489     return 0
1490 }
1491 run_test 62 "don't mis-drop resent replay"
1492
1493 #Adaptive Timeouts (bug 3055)
1494 AT_MAX_SET=0
1495
1496 at_cleanup () {
1497     local var
1498     local facet
1499     local at_new
1500
1501     echo "Cleaning up AT ..."
1502     if [ -n "$ATOLDBASE" ]; then
1503         local at_history=$($LCTL get_param -n at_history)
1504         do_facet $SINGLEMDS "lctl set_param at_history=$at_history" || true
1505         do_facet ost1 "lctl set_param at_history=$at_history" || true
1506     fi
1507
1508     if [ $AT_MAX_SET -ne 0 ]; then
1509         for facet in mds client ost; do
1510             var=AT_MAX_SAVE_${facet}
1511             echo restore AT on $facet to saved value ${!var}
1512             at_max_set ${!var} $facet
1513             at_new=$(at_max_get $facet)
1514             echo Restored AT value on $facet $at_new
1515             [ $at_new -eq ${!var} ] || \
1516             error "$facet : AT value was not restored SAVED ${!var} NEW $at_new"
1517         done
1518     fi
1519 }
1520
1521 at_start()
1522 {
1523     local at_max_new=600
1524
1525     # Save at_max original values
1526     local facet
1527     if [ $AT_MAX_SET -eq 0 ]; then
1528         # Suppose that all osts have the same at_max
1529         for facet in mds client ost; do
1530             eval AT_MAX_SAVE_${facet}=$(at_max_get $facet)
1531         done
1532     fi
1533     local at_max
1534     for facet in mds client ost; do
1535         at_max=$(at_max_get $facet)
1536         if [ $at_max -ne $at_max_new ]; then
1537             echo "AT value on $facet is $at_max, set it by force temporarily to $at_max_new"
1538             at_max_set $at_max_new $facet
1539             AT_MAX_SET=1
1540         fi
1541     done
1542
1543     if [ -z "$ATOLDBASE" ]; then
1544         ATOLDBASE=$(do_facet $SINGLEMDS "lctl get_param -n at_history")
1545         # speed up the timebase so we can check decreasing AT
1546         do_facet $SINGLEMDS "lctl set_param at_history=8" || true
1547         do_facet ost1 "lctl set_param at_history=8" || true
1548
1549         # sleep for a while to cool down, should be > 8s and also allow
1550         # at least one ping to be sent. simply use TIMEOUT to be safe.
1551         sleep $TIMEOUT
1552     fi
1553 }
1554
1555 test_65a() #bug 3055
1556 {
1557     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1558
1559     at_start || return 0
1560     $LCTL dk > /dev/null
1561     debugsave
1562     sysctl -w lnet.debug="+other"
1563     # Slow down a request to the current service time, this is critical
1564     # because previous tests may have caused this value to increase.
1565     REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
1566                awk '/portal 12/ {print $5}'`
1567     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1568
1569     do_facet $SINGLEMDS lctl set_param fail_val=$((${REQ_DELAY} * 1000))
1570 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1571     do_facet $SINGLEMDS sysctl -w lustre.fail_loc=0x8000050a
1572     createmany -o $DIR/$tfile 10 > /dev/null
1573     unlinkmany $DIR/$tfile 10 > /dev/null
1574     # check for log message
1575     $LCTL dk | grep "Early reply #" || error "No early reply"
1576     debugrestore
1577     # client should show REQ_DELAY estimates
1578     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1579     sleep 9
1580     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1581 }
1582 run_test 65a "AT: verify early replies"
1583
1584 test_65b() #bug 3055
1585 {
1586     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1587
1588     at_start || return 0
1589     # turn on D_ADAPTTO
1590     debugsave
1591     sysctl -w lnet.debug="other trace"
1592     $LCTL dk > /dev/null
1593     # Slow down a request to the current service time, this is critical
1594     # because previous tests may have caused this value to increase.
1595     lfs setstripe $DIR/$tfile --index=0 --count=1
1596     multiop $DIR/$tfile Ow1yc
1597     REQ_DELAY=`lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts |
1598                awk '/portal 6/ {print $5}'`
1599     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1600
1601     do_facet ost1 lctl set_param fail_val=${REQ_DELAY}
1602 #define OBD_FAIL_OST_BRW_PAUSE_PACK      0x224
1603     do_facet ost1 sysctl -w lustre.fail_loc=0x224
1604
1605     rm -f $DIR/$tfile
1606     lfs setstripe $DIR/$tfile --index=0 --count=1
1607     # force some real bulk transfer
1608     multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
1609
1610     do_facet ost1 sysctl -w lustre.fail_loc=0
1611     # check for log message
1612     $LCTL dk | grep "Early reply #" || error "No early reply"
1613     debugrestore
1614     # client should show REQ_DELAY estimates
1615     lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts | grep portal
1616 }
1617 run_test 65b "AT: verify early replies on packed reply / bulk"
1618
1619 test_66a() #bug 3055
1620 {
1621     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1622
1623     at_start || return 0
1624     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1625     # adjust 5s at a time so no early reply is sent (within deadline)
1626     do_facet $SINGLEMDS "sysctl -w lustre.fail_val=5000"
1627 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1628     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x8000050a"
1629     createmany -o $DIR/$tfile 20 > /dev/null
1630     unlinkmany $DIR/$tfile 20 > /dev/null
1631     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1632     do_facet $SINGLEMDS "sysctl -w lustre.fail_val=10000"
1633     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x8000050a"
1634     createmany -o $DIR/$tfile 20 > /dev/null
1635     unlinkmany $DIR/$tfile 20 > /dev/null
1636     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1637     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1638     sleep 9
1639     createmany -o $DIR/$tfile 20 > /dev/null
1640     unlinkmany $DIR/$tfile 20 > /dev/null
1641     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1642     CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $5}')
1643     WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $7}')
1644     echo "Current MDT timeout $CUR, worst $WORST"
1645     [ $CUR -lt $WORST ] || error "Current $CUR should be less than worst $WORST"
1646 }
1647 run_test 66a "AT: verify MDT service time adjusts with no early replies"
1648
1649 test_66b() #bug 3055
1650 {
1651     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1652
1653     at_start || return 0
1654     ORIG=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $4}')
1655     sysctl -w lustre.fail_val=$(($ORIG + 5))
1656 #define OBD_FAIL_PTLRPC_PAUSE_REP      0x50c
1657     sysctl -w lustre.fail_loc=0x50c
1658     ls $DIR/$tfile > /dev/null 2>&1
1659     sysctl -w lustre.fail_loc=0
1660     CUR=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $4}')
1661     WORST=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $6}')
1662     echo "network timeout orig $ORIG, cur $CUR, worst $WORST"
1663     [ $WORST -gt $ORIG ] || error "Worst $WORST should be worse than orig $ORIG"
1664 }
1665 run_test 66b "AT: verify net latency adjusts"
1666
1667 test_67a() #bug 3055
1668 {
1669     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1670
1671     at_start || return 0
1672     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1673     # sleeping threads may drive values above this
1674     do_facet ost1 "sysctl -w lustre.fail_val=400"
1675 #define OBD_FAIL_PTLRPC_PAUSE_REQ    0x50a
1676     do_facet ost1 "sysctl -w lustre.fail_loc=0x50a"
1677     createmany -o $DIR/$tfile 20 > /dev/null
1678     unlinkmany $DIR/$tfile 20 > /dev/null
1679     do_facet ost1 "sysctl -w lustre.fail_loc=0"
1680     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1681     ATTEMPTS=$(($CONN2 - $CONN1))
1682     echo "$ATTEMPTS osc reconnect attempts on gradual slow"
1683     [ $ATTEMPTS -gt 0 ] && error_ignore 13721 "AT should have prevented reconnect"
1684     return 0
1685 }
1686 run_test 67a "AT: verify slow request processing doesn't induce reconnects"
1687
1688 test_67b() #bug 3055
1689 {
1690     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1691
1692     at_start || return 0
1693     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1694
1695     # exhaust precreations on ost1
1696     local OST=$(lfs osts | grep ^0": " | awk '{print $2}' | sed -e 's/_UUID$//')
1697     local mdtosc=$(get_mdtosc_proc_path mds $OST)
1698     local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1699         osc.$mdtosc.prealloc_last_id)
1700     local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1701         osc.$mdtosc.prealloc_next_id)
1702
1703     mkdir -p $DIR/$tdir/${OST}
1704     lfs setstripe $DIR/$tdir/${OST} -o 0 -c 1 || error "setstripe"
1705     echo "Creating to objid $last_id on ost $OST..."
1706 #define OBD_FAIL_OST_PAUSE_CREATE        0x223
1707     do_facet ost1 "sysctl -w lustre.fail_val=20000"
1708     do_facet ost1 "sysctl -w lustre.fail_loc=0x80000223"
1709     createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1710
1711     client_reconnect
1712     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1713     log "phase 2"
1714     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1715     ATTEMPTS=$(($CONN2 - $CONN1))
1716     echo "$ATTEMPTS osc reconnect attempts on instant slow"
1717     # do it again; should not timeout
1718     do_facet ost1 "sysctl -w lustre.fail_loc=0x80000223"
1719     cp /etc/profile $DIR/$tfile || error "cp failed"
1720     do_facet ost1 "sysctl -w lustre.fail_loc=0"
1721     client_reconnect
1722     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1723     CONN3=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1724     ATTEMPTS=$(($CONN3 - $CONN2))
1725     echo "$ATTEMPTS osc reconnect attempts on 2nd slow"
1726     [ $ATTEMPTS -gt 0 ] && error "AT should have prevented reconnect"
1727     return 0
1728 }
1729 run_test 67b "AT: verify instant slowdown doesn't induce reconnects"
1730
1731 test_68 () #bug 13813
1732 {
1733     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1734
1735     at_start || return 0
1736     local ldlm_enqueue_min=$(find /sys -name ldlm_enqueue_min)
1737     [ -z "$ldlm_enqueue_min" ] && skip "missing /sys/.../ldlm_enqueue_min" && return 0
1738     local ldlm_enqueue_min_r=$(do_facet ost1 "find /sys -name ldlm_enqueue_min")
1739     [ -z "$ldlm_enqueue_min_r" ] && skip "missing /sys/.../ldlm_enqueue_min in the ost1" && return 0
1740     local ENQ_MIN=$(cat $ldlm_enqueue_min)
1741     local ENQ_MIN_R=$(do_facet ost1 "cat $ldlm_enqueue_min_r")
1742     echo $TIMEOUT >> $ldlm_enqueue_min
1743     do_facet ost1 "echo $TIMEOUT >> $ldlm_enqueue_min_r"
1744
1745     rm -rf $DIR/$tdir
1746     mkdir -p $DIR/$tdir
1747     lfs setstripe $DIR/$tdir --index=0 --count=1
1748 #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
1749     sysctl -w lustre.fail_val=$(($TIMEOUT - 1))
1750     sysctl -w lustre.fail_loc=0x80000312
1751     cp /etc/profile $DIR/$tdir/${tfile}_1 || error "1st cp failed $?"
1752     sysctl -w lustre.fail_val=$((TIMEOUT * 5 / 4))
1753     sysctl -w lustre.fail_loc=0x80000312
1754     cp /etc/profile $DIR/$tdir/${tfile}_2 || error "2nd cp failed $?"
1755     sysctl -w lustre.fail_loc=0
1756
1757     echo $ENQ_MIN >> $ldlm_enqueue_min
1758     do_facet ost1 "echo $ENQ_MIN_R >> $ldlm_enqueue_min_r"
1759     rm -rf $DIR/$tdir
1760     return 0
1761 }
1762 run_test 68 "AT: verify slowing locks"
1763
1764 at_cleanup
1765 # end of AT tests includes above lines
1766
1767
1768 # start multi-client tests
1769 test_70a () {
1770         [ -z "$CLIENTS" ] && \
1771                 { skip "Need two or more clients." && return; }
1772         [ $CLIENTCOUNT -lt 2 ] && \
1773                 { skip "Need two or more clients, have $CLIENTCOUNT" && return; }
1774
1775         echo "mount clients $CLIENTS ..."
1776         zconf_mount_clients $CLIENTS $MOUNT
1777
1778         local clients=${CLIENTS//,/ }
1779         echo "Write/read files on $DIR ; clients $CLIENTS ... "
1780         for CLIENT in $clients; do
1781                 do_node $CLIENT dd bs=1M count=10 if=/dev/zero \
1782                         of=$DIR/${tfile}_${CLIENT} 2>/dev/null || \
1783                                 error "dd failed on $CLIENT"
1784         done
1785
1786         local prev_client=$(echo $clients | sed 's/^.* \(.\+\)$/\1/')
1787         for C in ${CLIENTS//,/ }; do
1788                 do_node $prev_client dd if=$DIR/${tfile}_${C} of=/dev/null 2>/dev/null || \
1789                         error "dd if=$DIR/${tfile}_${C} failed on $prev_client"
1790                 prev_client=$C
1791         done
1792         
1793         ls $DIR
1794 }
1795 run_test 70a "check multi client t-f"
1796
1797 check_for_process () {
1798         local clients=$1
1799         shift
1800         local prog=$@
1801
1802         killall_process $clients "$prog" -0
1803 }
1804
1805 killall_process () {
1806         local clients=${1:-$(hostname)}
1807         local name=$2
1808         local signal=$3
1809         local rc=0
1810
1811         do_nodes $clients "killall $signal $name"
1812 }
1813
1814 test_70b () {
1815         local clients=${CLIENTS:-$HOSTNAME}
1816
1817         zconf_mount_clients $clients $MOUNT
1818         
1819         local duration=300
1820         [ "$SLOW" = "no" ] && duration=60
1821         # set duration to 900 because it takes some time to boot node
1822         [ "$FAILURE_MODE" = HARD ] && duration=900
1823
1824         local cmd="rundbench 1 -t $duration"
1825         local pid=""
1826         do_nodesv $clients "set -x; MISSING_DBENCH_OK=$MISSING_DBENCH_OK \
1827                 PATH=:$PATH:$LUSTRE/utils:$LUSTRE/tests/:$DBENCH_LIB \
1828                 DBENCH_LIB=$DBENCH_LIB TESTSUITE=$TESTSUITE TESTNAME=$TESTNAME \
1829                 LCTL=$LCTL $cmd" &
1830         pid=$!
1831         log "Started rundbench load pid=$pid ..."
1832
1833         # give rundbench a chance to start, bug 24118
1834         sleep 2
1835         local elapsed=0
1836         local num_failovers=0
1837         local start_ts=$(date +%s)
1838         while [ $elapsed -lt $duration ]; do
1839                 if ! check_for_process $clients rundbench; then
1840                         error_noexit "rundbench not found on some of $clients!"
1841                         killall_process $clients dbench
1842                         break
1843                 fi
1844                 sleep 1
1845                 replay_barrier $SINGLEMDS
1846                 sleep 1 # give clients a time to do operations
1847                 # Increment the number of failovers
1848                 num_failovers=$((num_failovers+1))
1849                 log "$TESTNAME fail $SINGLEMDS $num_failovers times"
1850                 fail $SINGLEMDS
1851                 elapsed=$(($(date +%s) - start_ts))
1852         done
1853
1854         wait $pid || error "rundbench load on $clients failed!"
1855 }
1856 run_test 70b "mds recovery; $CLIENTCOUNT clients"
1857 # end multi-client tests
1858
1859 test_73a() {
1860     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1861     pid=$!
1862     rm -f $DIR/$tfile
1863
1864     replay_barrier $SINGLEMDS
1865 #define OBD_FAIL_LDLM_ENQUEUE       0x302
1866     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000302"
1867     fail $SINGLEMDS
1868     kill -USR1 $pid
1869     wait $pid || return 1
1870     [ -e $DIR/$tfile ] && return 2
1871     return 0
1872 }
1873 run_test 73a "open(O_CREAT), unlink, replay, reconnect before open replay , close"
1874
1875 test_73b() {
1876     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1877     pid=$!
1878     rm -f $DIR/$tfile
1879
1880     replay_barrier $SINGLEMDS
1881 #define OBD_FAIL_LDLM_REPLY       0x30c
1882     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000030c"
1883     fail $SINGLEMDS
1884     kill -USR1 $pid
1885     wait $pid || return 1
1886     [ -e $DIR/$tfile ] && return 2
1887     return 0
1888 }
1889 run_test 73b "open(O_CREAT), unlink, replay, reconnect at open_replay reply, close"
1890
1891 test_73c() {
1892     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1893     pid=$!
1894     rm -f $DIR/$tfile
1895
1896     replay_barrier $SINGLEMDS
1897 #define OBD_FAIL_TGT_LAST_REPLAY       0x710
1898     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000710"
1899     fail $SINGLEMDS
1900     kill -USR1 $pid
1901     wait $pid || return 1
1902     [ -e $DIR/$tfile ] && return 2
1903     return 0
1904 }
1905 run_test 73c "open(O_CREAT), unlink, replay, reconnect at last_replay, close"
1906
1907 # bug 18554
1908 test_74() {
1909     local clients=${CLIENTS:-$HOSTNAME}
1910
1911     stop ost1
1912     zconf_umount_clients $clients $MOUNT
1913     facet_failover $SINGLEMDS
1914     zconf_mount_clients $clients $MOUNT
1915     mount_facet ost1
1916     touch $DIR/$tfile || return 1
1917     rm $DIR/$tfile || return 2
1918     clients_up || error "client evicted: $?"
1919     return 0
1920 }
1921 run_test 74 "Ensure applications don't fail waiting for OST recovery"
1922
1923 test_80a() {
1924     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1925
1926     mkdir -p $DIR/$tdir
1927     replay_barrier mds2
1928     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir $DIR/$tdir failed"
1929     rmdir $DIR/$tdir || error "rmdir $DIR/$tdir failed"
1930     fail mds2
1931     stat $DIR/$tdir 2&>/dev/null && error "$DIR/$tdir still exist after recovery!"
1932     return 0
1933 }
1934 run_test 80a "CMD: unlink cross-node dir (fail mds with inode)"
1935
1936 test_80b() {
1937     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1938
1939     mkdir -p $DIR/$tdir
1940     replay_barrier $SINGLEMDS
1941     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir $DIR/$tdir failed"
1942     rmdir $DIR/$tdir || error "rmdir $DIR/$tdir failed"
1943     fail $SINGLEMDS
1944     stat $DIR/$tdir 2&>/dev/null && error "$DIR/$tdir still exist after recovery!"
1945     return 0
1946 }
1947 run_test 80b "CMD: unlink cross-node dir (fail mds with name)"
1948
1949 test_81a() {
1950     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1951
1952     mkdir -p $DIR/$tdir
1953     createmany -o $DIR/$tdir/f 3000 || error "createmany failed"
1954     sleep 10
1955     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir failed"
1956     $CHECKSTAT -t file $DIR/$tdir/f1002 || error "$CHECKSTAT -t file failed"
1957     replay_barrier $SINGLEMDS
1958     rm $DIR/$tdir/f1002 || error "rm $DIR/$tdir/f1002 failed"
1959     fail $SINGLEMDS
1960     stat $DIR/$tdir/f1002
1961 }
1962 run_test 81a "CMD: unlink cross-node file (fail mds with name)"
1963
1964 test_82a() {
1965     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1966
1967     local dir=$DIR/d82a
1968     replay_barrier mds2
1969     mkdir $dir || error "mkdir $dir failed"
1970     log "FAILOVER mds2"
1971     fail mds2
1972     stat $DIR
1973     $CHECKSTAT -t dir $dir || error "$CHECKSTAT -t dir $dir failed"
1974 }
1975 run_test 82a "CMD: mkdir cross-node dir (fail mds with inode)"
1976
1977 test_82b() {
1978     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1979
1980     local dir=$DIR/d82b
1981     replay_barrier $SINGLEMDS
1982     mkdir $dir || error "mkdir $dir failed"
1983     log "FAILOVER mds1"
1984     fail $SINGLEMDS
1985     stat $DIR
1986     $CHECKSTAT -t dir $dir || error "$CHECKSTAT -t dir $dir failed"
1987 }
1988 run_test 82b "CMD: mkdir cross-node dir (fail mds with name)"
1989
1990 test_83a() {
1991     mkdir -p $DIR/$tdir
1992     createmany -o $DIR/$tdir/$tfile- 10 || return 1
1993 #define OBD_FAIL_MDS_FAIL_LOV_LOG_ADD       0x140
1994     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000140"
1995     unlinkmany $DIR/$tdir/$tfile- 10 || return 2
1996 }
1997 run_test 83a "fail log_add during unlink recovery"
1998
1999 test_83b() {
2000     mkdir -p $DIR/$tdir
2001     createmany -o $DIR/$tdir/$tfile- 10 || return 1
2002     replay_barrier $SINGLEMDS
2003     unlinkmany $DIR/$tdir/$tfile- 10 || return 2
2004 #define OBD_FAIL_MDS_FAIL_LOV_LOG_ADD       0x140
2005     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000140"
2006     fail $SINGLEMDS
2007 }
2008 run_test 83b "fail log_add during unlink recovery"
2009
2010 test_84a() {
2011 #define OBD_FAIL_MDS_OPEN_WAIT_CREATE  0x144
2012     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000144"
2013     createmany -o $DIR/$tfile- 1 &
2014     PID=$!
2015     mds_evict_client
2016     wait $PID
2017     client_up || client_up || true    # reconnect
2018 }
2019 run_test 84a "stale open during export disconnect"
2020
2021 test_85a() { #bug 16774
2022     lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
2023
2024     for i in `seq 100`; do
2025         echo "tag-$i" > $DIR/$tfile-$i
2026         grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
2027     done
2028
2029     lov_id=`lctl dl | grep "clilov"`
2030     addr=`echo $lov_id | awk '{print $4}' | awk -F '-' '{print $3}'`
2031     count=`lctl get_param -n ldlm.namespaces.*MDT0000*$addr.lock_unused_count`
2032     echo "before recovery: unused locks count = $count"
2033
2034     fail $SINGLEMDS
2035
2036     count2=`lctl get_param -n ldlm.namespaces.*MDT0000*$addr.lock_unused_count`
2037     echo "after recovery: unused locks count = $count2"
2038
2039     if [ $count2 -ge $count ]; then
2040         error "unused locks are not canceled"
2041     fi
2042 }
2043 run_test 85a "check the cancellation of unused locks during recovery(IBITS)"
2044
2045 test_85b() { #bug 16774
2046     lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
2047
2048     lfs setstripe -o 0 -c 1 $DIR
2049
2050     for i in `seq 100`; do
2051         dd if=/dev/urandom of=$DIR/$tfile-$i bs=4096 count=32 >/dev/null 2>&1
2052     done
2053
2054     cancel_lru_locks osc
2055
2056     for i in `seq 100`; do
2057         dd if=$DIR/$tfile-$i of=/dev/null bs=4096 count=32 >/dev/null 2>&1
2058     done
2059
2060     lov_id=`lctl dl | grep "clilov"`
2061     addr=`echo $lov_id | awk '{print $4}' | awk -F '-' '{print $3}'`
2062     count=`lctl get_param -n ldlm.namespaces.*OST0000*$addr.lock_unused_count`
2063     echo "before recovery: unused locks count = $count"
2064
2065     fail ost1
2066
2067     count2=`lctl get_param -n ldlm.namespaces.*OST0000*$addr.lock_unused_count`
2068     echo "after recovery: unused locks count = $count2"
2069
2070     if [ $count2 -ge $count ]; then
2071         error "unused locks are not canceled"
2072     fi
2073 }
2074 run_test 85b "check the cancellation of unused locks during recovery(EXTENT)"
2075
2076 test_86() {
2077         local clients=${CLIENTS:-$HOSTNAME}
2078
2079         zconf_umount_clients $clients $MOUNT
2080         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT*.exports.clear=0
2081         remount_facet $SINGLEMDS
2082         zconf_mount_clients $clients $MOUNT
2083 }
2084 run_test 86 "umount server after clear nid_stats should not hit LBUG"
2085
2086 test_87() {
2087     do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
2088
2089     replay_barrier ost1
2090     lfs setstripe -i 0 -c 1 $DIR/$tfile
2091     dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 || error "Cannot write"
2092     cksum=`md5sum $DIR/$tfile | awk '{print $1}'`
2093     cancel_lru_locks osc
2094     fail ost1
2095     dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
2096     cksum2=`md5sum $DIR/$tfile | awk '{print $1}'`
2097     if [ $cksum != $cksum2 ] ; then
2098         error "New checksum $cksum2 does not match original $cksum"
2099     fi
2100 }
2101 run_test 87 "write replay"
2102
2103 test_87b() {
2104     do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
2105
2106     replay_barrier ost1
2107     lfs setstripe -i 0 -c 1 $DIR/$tfile
2108     dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 || error "Cannot write"
2109     sleep 1 # Give it a chance to flush dirty data
2110     echo TESTTEST | dd of=$DIR/$tfile bs=1 count=8 seek=64
2111     cksum=`md5sum $DIR/$tfile | awk '{print $1}'`
2112     cancel_lru_locks osc
2113     fail ost1
2114     dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
2115     cksum2=`md5sum $DIR/$tfile | awk '{print $1}'`
2116     if [ $cksum != $cksum2 ] ; then
2117         error "New checksum $cksum2 does not match original $cksum"
2118     fi
2119 }
2120 run_test 87b "write replay with changed data (checksum resend)"
2121
2122 test_88() { #bug 17485
2123     mkdir -p $DIR/$tdir
2124     mkdir -p $TMP/$tdir
2125
2126     lfs setstripe $DIR/$tdir -o 0 -c 1 || error "setstripe"
2127
2128     replay_barrier ost1
2129     replay_barrier $SINGLEMDS
2130
2131     # exhaust precreations on ost1
2132     local OST=$(lfs osts | grep ^0": " | awk '{print $2}' | sed -e 's/_UUID$//')
2133     local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $OST)
2134     local last_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
2135     local next_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
2136     echo "before test: last_id = $last_id, next_id = $next_id"
2137
2138     echo "Creating to objid $last_id on ost $OST..."
2139     createmany -o $DIR/$tdir/f-%d $next_id $((last_id - next_id + 2))
2140
2141     #create some files to use some uncommitted objids
2142     last_id=$(($last_id + 1))
2143     createmany -o $DIR/$tdir/f-%d $last_id 8
2144
2145     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
2146     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
2147     echo "before recovery: last_id = $last_id2, next_id = $next_id2" 
2148
2149     # if test uses shutdown_facet && reboot_facet instead of facet_failover ()
2150     # it has to take care about the affected facets, bug20407
2151     local affected_mds1=$(affected_facets mds1)
2152     local affected_ost1=$(affected_facets ost1)
2153
2154     shutdown_facet $SINGLEMDS
2155     shutdown_facet ost1
2156
2157     reboot_facet $SINGLEMDS
2158     change_active $affected_mds1
2159     wait_for_facet $affected_mds1
2160     mount_facets $affected_mds1 || error "Restart of mds failed"
2161
2162     reboot_facet ost1
2163     change_active $affected_ost1
2164     wait_for_facet $affected_ost1
2165     mount_facets $affected_ost1 || error "Restart of ost1 failed"
2166
2167     clients_up
2168
2169     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
2170     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
2171     echo "after recovery: last_id = $last_id2, next_id = $next_id2" 
2172
2173     # create new files, which should use new objids, and ensure the orphan 
2174     # cleanup phase for ost1 is completed at the same time
2175     for i in `seq 8`; do
2176         file_id=$(($last_id + 10 + $i))
2177         dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
2178     done
2179
2180     # if the objids were not recreated, then "ls" will failed for -ENOENT
2181     ls -l $DIR/$tdir/* || error "can't get the status of precreated files"
2182
2183     local file_id
2184     # write into previously created files
2185     for i in `seq 8`; do
2186         file_id=$(($last_id + $i))
2187         dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
2188         cp -f $DIR/$tdir/f-$file_id $TMP/$tdir/
2189     done
2190
2191     # compare the content
2192     for i in `seq 8`; do
2193         file_id=$(($last_id + $i))
2194         cmp $TMP/$tdir/f-$file_id $DIR/$tdir/f-$file_id || error "the content" \
2195         "of file is modified!"
2196     done
2197
2198     rm -fr $TMP/$tdir
2199 }
2200 run_test 88 "MDS should not assign same objid to different files "
2201
2202 test_89() {
2203         cancel_lru_locks osc
2204         mkdir -p $DIR/$tdir
2205         rm -f $DIR/$tdir/$tfile
2206         wait_mds_ost_sync
2207         wait_destroy_complete
2208         BLOCKS1=$(df -P $MOUNT | tail -n 1 | awk '{ print $3 }')
2209         lfs setstripe -i 0 -c 1 $DIR/$tdir/$tfile
2210         dd if=/dev/zero bs=1M count=10 of=$DIR/$tdir/$tfile
2211         sync
2212         stop ost1
2213         facet_failover $SINGLEMDS
2214         rm $DIR/$tdir/$tfile
2215         umount $MOUNT
2216         mount_facet ost1
2217         zconf_mount $(hostname) $MOUNT
2218         client_up || return 1
2219         wait_mds_ost_sync
2220         BLOCKS2=$(df -P $MOUNT | tail -n 1 | awk '{ print $3 }')
2221         [ "$BLOCKS1" == "$BLOCKS2" ] || error $((BLOCKS2 - BLOCKS1)) blocks leaked
2222 }
2223
2224 run_test 89 "no disk space leak on late ost connection"
2225
2226 equals_msg `basename $0`: test complete, cleaning up
2227 check_and_cleanup_lustre
2228 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true