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