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