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