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