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