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