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