Whamcloud - gitweb
LU-80 tests: large xattr support
[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     local orig
1373     local new
1374
1375     large_xattr_enabled &&
1376         orig="$(generate_string $(max_xattr_size))" || orig="bar"
1377
1378     mount_client $MOUNT2
1379     mkdir -p $DIR/$tdir
1380     touch $DIR/$tdir/$tfile
1381     replay_barrier $SINGLEMDS
1382     setfattr -n trusted.foo -v $orig $DIR/$tdir/$tfile
1383     fail $SINGLEMDS
1384     new=$(get_xattr_value trusted.foo $MOUNT2/$tdir/$tfile)
1385     [[ "$new" = "$orig" ]] || return 1
1386     rm -f $DIR/$tdir/$tfile
1387     rmdir $DIR/$tdir
1388     zconf_umount `hostname` $MOUNT2
1389 }
1390 run_test 58b "test replay of setxattr op"
1391
1392 test_58c() { # bug 16570
1393     local orig
1394     local orig1
1395     local new
1396
1397     if large_xattr_enabled; then
1398         local xattr_size=$(max_xattr_size)
1399         orig="$(generate_string $((xattr_size / 2)))"
1400         orig1="$(generate_string $xattr_size)"
1401     else
1402         orig="bar"
1403         orig1="bar1"
1404     fi
1405
1406     mount_client $MOUNT2
1407     mkdir -p $DIR/$tdir
1408     touch $DIR/$tdir/$tfile
1409     drop_request "setfattr -n trusted.foo -v $orig $DIR/$tdir/$tfile" ||
1410         return 1
1411     new=$(get_xattr_value trusted.foo $MOUNT2/$tdir/$tfile)
1412     [[ "$new" = "$orig" ]] || return 2
1413     drop_reint_reply "setfattr -n trusted.foo1 -v $orig1 $DIR/$tdir/$tfile" ||
1414         return 3
1415     new=$(get_xattr_value trusted.foo1 $MOUNT2/$tdir/$tfile)
1416     [[ "$new" = "$orig1" ]] || return 4
1417     rm -f $DIR/$tdir/$tfile
1418     rmdir $DIR/$tdir
1419     zconf_umount $HOSTNAME $MOUNT2
1420 }
1421 run_test 58c "resend/reconstruct setxattr op"
1422
1423 # log_commit_thread vs filter_destroy race used to lead to import use after free
1424 # bug 11658
1425 test_59() {
1426     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1427
1428     mkdir -p $DIR/$tdir
1429     createmany -o $DIR/$tdir/$tfile-%d 200
1430     sync
1431     unlinkmany $DIR/$tdir/$tfile-%d 200
1432 #define OBD_FAIL_PTLRPC_DELAY_RECOV       0x507
1433     do_facet ost1 "lctl set_param fail_loc=0x507"
1434     fail ost1
1435     fail $SINGLEMDS
1436     do_facet ost1 "lctl set_param fail_loc=0x0"
1437     sleep 20
1438     rmdir $DIR/$tdir
1439 }
1440 run_test 59 "test log_commit_thread vs filter_destroy race"
1441
1442 # race between add unlink llog vs cat log init in post_recovery (only for b1_6)
1443 # bug 12086: should no oops and No ctxt error for this test
1444 test_60() {
1445     mkdir -p $DIR/$tdir
1446     createmany -o $DIR/$tdir/$tfile-%d 200
1447     replay_barrier $SINGLEMDS
1448     unlinkmany $DIR/$tdir/$tfile-%d 0 100
1449     fail $SINGLEMDS
1450     unlinkmany $DIR/$tdir/$tfile-%d 100 100
1451     local no_ctxt=`dmesg | grep "No ctxt"`
1452     [ -z "$no_ctxt" ] || error "ctxt is not initialized in recovery"
1453 }
1454 run_test 60 "test llog post recovery init vs llog unlink"
1455
1456 #test race  llog recovery thread vs llog cleanup
1457 test_61a() {    # was test_61
1458     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1459
1460     mkdir -p $DIR/$tdir
1461     createmany -o $DIR/$tdir/$tfile-%d 800
1462     replay_barrier ost1
1463 #   OBD_FAIL_OST_LLOG_RECOVERY_TIMEOUT 0x221
1464     unlinkmany $DIR/$tdir/$tfile-%d 800
1465     set_nodes_failloc "$(osts_nodes)" 0x80000221
1466     facet_failover ost1
1467     sleep 10
1468     fail ost1
1469     sleep 30
1470     set_nodes_failloc "$(osts_nodes)" 0x0
1471
1472     $CHECKSTAT -t file $DIR/$tdir/$tfile-* && return 1
1473     rmdir $DIR/$tdir
1474 }
1475 run_test 61a "test race llog recovery vs llog cleanup"
1476
1477 #test race  mds llog sync vs llog cleanup
1478 test_61b() {
1479 #   OBD_FAIL_MDS_LLOG_SYNC_TIMEOUT 0x13a
1480     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013a"
1481     facet_failover $SINGLEMDS
1482     sleep 10
1483     fail $SINGLEMDS
1484     do_facet client dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 || return 1
1485 }
1486 run_test 61b "test race mds llog sync vs llog cleanup"
1487
1488 #test race  cancel cookie cb vs llog cleanup
1489 test_61c() {
1490     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1491
1492 #   OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT 0x222
1493     touch $DIR/$tfile
1494     set_nodes_failloc "$(osts_nodes)" 0x80000222
1495     rm $DIR/$tfile
1496     sleep 10
1497     fail ost1
1498     set_nodes_failloc "$(osts_nodes)" 0x0
1499 }
1500 run_test 61c "test race mds llog sync vs llog cleanup"
1501
1502 test_61d() { # bug 16002 # bug 17466 # bug 22137
1503 #   OBD_FAIL_OBD_LLOG_SETUP        0x605
1504     stop mgs
1505     do_facet mgs "lctl set_param fail_loc=0x80000605"
1506     start mgs $MGSDEV $MGS_MOUNT_OPTS && error "mgs start should have failed"
1507     do_facet mgs "lctl set_param fail_loc=0"
1508     start mgs $MGSDEV $MGS_MOUNT_OPTS || error "cannot restart mgs"
1509 }
1510 run_test 61d "error in llog_setup should cleanup the llog context correctly"
1511
1512 test_62() { # Bug 15756 - don't mis-drop resent replay
1513     mkdir -p $DIR/$tdir
1514     replay_barrier $SINGLEMDS
1515     createmany -o $DIR/$tdir/$tfile- 25
1516 #define OBD_FAIL_TGT_REPLAY_DROP         0x707
1517     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000707"
1518     fail $SINGLEMDS
1519     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1520     unlinkmany $DIR/$tdir/$tfile- 25 || return 2
1521     return 0
1522 }
1523 run_test 62 "don't mis-drop resent replay"
1524
1525 #Adaptive Timeouts (bug 3055)
1526 AT_MAX_SET=0
1527
1528 at_cleanup () {
1529     local var
1530     local facet
1531     local at_new
1532
1533     echo "Cleaning up AT ..."
1534     if [ -n "$ATOLDBASE" ]; then
1535         local at_history=$($LCTL get_param -n at_history)
1536         do_facet $SINGLEMDS "lctl set_param at_history=$at_history" || true
1537         do_facet ost1 "lctl set_param at_history=$at_history" || true
1538     fi
1539
1540     if [ $AT_MAX_SET -ne 0 ]; then
1541         for facet in mds client ost; do
1542             var=AT_MAX_SAVE_${facet}
1543             echo restore AT on $facet to saved value ${!var}
1544             at_max_set ${!var} $facet
1545             at_new=$(at_max_get $facet)
1546             echo Restored AT value on $facet $at_new
1547             [ $at_new -eq ${!var} ] || \
1548             error "$facet : AT value was not restored SAVED ${!var} NEW $at_new"
1549         done
1550     fi
1551 }
1552
1553 at_start()
1554 {
1555     local at_max_new=600
1556
1557     # Save at_max original values
1558     local facet
1559     if [ $AT_MAX_SET -eq 0 ]; then
1560         # Suppose that all osts have the same at_max
1561         for facet in mds client ost; do
1562             eval AT_MAX_SAVE_${facet}=$(at_max_get $facet)
1563         done
1564     fi
1565     local at_max
1566     for facet in mds client ost; do
1567         at_max=$(at_max_get $facet)
1568         if [ $at_max -ne $at_max_new ]; then
1569             echo "AT value on $facet is $at_max, set it by force temporarily to $at_max_new"
1570             at_max_set $at_max_new $facet
1571             AT_MAX_SET=1
1572         fi
1573     done
1574
1575     if [ -z "$ATOLDBASE" ]; then
1576         ATOLDBASE=$(do_facet $SINGLEMDS "lctl get_param -n at_history")
1577         # speed up the timebase so we can check decreasing AT
1578         do_facet $SINGLEMDS "lctl set_param at_history=8" || true
1579         do_facet ost1 "lctl set_param at_history=8" || true
1580
1581         # sleep for a while to cool down, should be > 8s and also allow
1582         # at least one ping to be sent. simply use TIMEOUT to be safe.
1583         sleep $TIMEOUT
1584     fi
1585 }
1586
1587 test_65a() #bug 3055
1588 {
1589     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1590
1591     at_start || return 0
1592     $LCTL dk > /dev/null
1593     debugsave
1594     $LCTL set_param debug="other"
1595     # Slow down a request to the current service time, this is critical
1596     # because previous tests may have caused this value to increase.
1597     REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
1598                awk '/portal 12/ {print $5}'`
1599     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1600
1601     do_facet $SINGLEMDS lctl set_param fail_val=$((${REQ_DELAY} * 1000))
1602 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1603     do_facet $SINGLEMDS $LCTL set_param fail_loc=0x8000050a
1604     createmany -o $DIR/$tfile 10 > /dev/null
1605     unlinkmany $DIR/$tfile 10 > /dev/null
1606     # check for log message
1607     $LCTL dk | grep "Early reply #" || error "No early reply"
1608     debugrestore
1609     # client should show REQ_DELAY estimates
1610     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1611     sleep 9
1612     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1613 }
1614 run_test 65a "AT: verify early replies"
1615
1616 test_65b() #bug 3055
1617 {
1618     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1619
1620     at_start || return 0
1621     # turn on D_ADAPTTO
1622     debugsave
1623     $LCTL set_param debug="other trace"
1624     $LCTL dk > /dev/null
1625     # Slow down a request to the current service time, this is critical
1626     # because previous tests may have caused this value to increase.
1627     lfs setstripe $DIR/$tfile --index=0 --count=1
1628     multiop $DIR/$tfile Ow1yc
1629     REQ_DELAY=`lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts |
1630                awk '/portal 6/ {print $5}'`
1631     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1632
1633     do_facet ost1 lctl set_param fail_val=${REQ_DELAY}
1634 #define OBD_FAIL_OST_BRW_PAUSE_PACK      0x224
1635     do_facet ost1 $LCTL set_param fail_loc=0x224
1636
1637     rm -f $DIR/$tfile
1638     lfs setstripe $DIR/$tfile --index=0 --count=1
1639     # force some real bulk transfer
1640     multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
1641
1642     do_facet ost1 $LCTL set_param fail_loc=0
1643     # check for log message
1644     $LCTL dk | grep "Early reply #" || error "No early reply"
1645     debugrestore
1646     # client should show REQ_DELAY estimates
1647     lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts | grep portal
1648 }
1649 run_test 65b "AT: verify early replies on packed reply / bulk"
1650
1651 test_66a() #bug 3055
1652 {
1653     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1654
1655     at_start || return 0
1656     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1657     # adjust 5s at a time so no early reply is sent (within deadline)
1658     do_facet $SINGLEMDS "$LCTL set_param fail_val=5000"
1659 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1660     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x8000050a"
1661     createmany -o $DIR/$tfile 20 > /dev/null
1662     unlinkmany $DIR/$tfile 20 > /dev/null
1663     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1664     do_facet $SINGLEMDS "$LCTL set_param fail_val=10000"
1665     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x8000050a"
1666     createmany -o $DIR/$tfile 20 > /dev/null
1667     unlinkmany $DIR/$tfile 20 > /dev/null
1668     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1669     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0"
1670     sleep 9
1671     createmany -o $DIR/$tfile 20 > /dev/null
1672     unlinkmany $DIR/$tfile 20 > /dev/null
1673     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1674     CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $5}')
1675     WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $7}')
1676     echo "Current MDT timeout $CUR, worst $WORST"
1677     [ $CUR -lt $WORST ] || error "Current $CUR should be less than worst $WORST"
1678 }
1679 run_test 66a "AT: verify MDT service time adjusts with no early replies"
1680
1681 test_66b() #bug 3055
1682 {
1683     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1684
1685     at_start || return 0
1686     ORIG=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $4}')
1687     $LCTL set_param fail_val=$(($ORIG + 5))
1688 #define OBD_FAIL_PTLRPC_PAUSE_REP      0x50c
1689     $LCTL set_param fail_loc=0x50c
1690     ls $DIR/$tfile > /dev/null 2>&1
1691     $LCTL set_param fail_loc=0
1692     CUR=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $4}')
1693     WORST=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $6}')
1694     echo "network timeout orig $ORIG, cur $CUR, worst $WORST"
1695     [ $WORST -gt $ORIG ] || error "Worst $WORST should be worse than orig $ORIG"
1696 }
1697 run_test 66b "AT: verify net latency adjusts"
1698
1699 test_67a() #bug 3055
1700 {
1701     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1702
1703     at_start || return 0
1704     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1705     # sleeping threads may drive values above this
1706     do_facet ost1 "$LCTL set_param fail_val=400"
1707 #define OBD_FAIL_PTLRPC_PAUSE_REQ    0x50a
1708     do_facet ost1 "$LCTL set_param fail_loc=0x50a"
1709     createmany -o $DIR/$tfile 20 > /dev/null
1710     unlinkmany $DIR/$tfile 20 > /dev/null
1711     do_facet ost1 "$LCTL set_param fail_loc=0"
1712     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1713     ATTEMPTS=$(($CONN2 - $CONN1))
1714     echo "$ATTEMPTS osc reconnect attempts on gradual slow"
1715     [ $ATTEMPTS -gt 0 ] && error_ignore 13721 "AT should have prevented reconnect"
1716     return 0
1717 }
1718 run_test 67a "AT: verify slow request processing doesn't induce reconnects"
1719
1720 test_67b() #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
1727     # exhaust precreations on ost1
1728     local OST=$(ostname_from_index 0)
1729     local mdtosc=$(get_mdtosc_proc_path mds $OST)
1730     local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1731         osc.$mdtosc.prealloc_last_id)
1732     local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1733         osc.$mdtosc.prealloc_next_id)
1734
1735     mkdir -p $DIR/$tdir/${OST}
1736     lfs setstripe $DIR/$tdir/${OST} -o 0 -c 1 || error "setstripe"
1737     echo "Creating to objid $last_id on ost $OST..."
1738 #define OBD_FAIL_OST_PAUSE_CREATE        0x223
1739     do_facet ost1 "$LCTL set_param fail_val=20000"
1740     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1741     createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1742
1743     client_reconnect
1744     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1745     log "phase 2"
1746     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1747     ATTEMPTS=$(($CONN2 - $CONN1))
1748     echo "$ATTEMPTS osc reconnect attempts on instant slow"
1749     # do it again; should not timeout
1750     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1751     cp /etc/profile $DIR/$tfile || error "cp failed"
1752     do_facet ost1 "$LCTL set_param fail_loc=0"
1753     client_reconnect
1754     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1755     CONN3=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1756     ATTEMPTS=$(($CONN3 - $CONN2))
1757     echo "$ATTEMPTS osc reconnect attempts on 2nd slow"
1758     [ $ATTEMPTS -gt 0 ] && error "AT should have prevented reconnect"
1759     return 0
1760 }
1761 run_test 67b "AT: verify instant slowdown doesn't induce reconnects"
1762
1763 test_68 () #bug 13813
1764 {
1765     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1766
1767     at_start || return 0
1768     local ldlm_enqueue_min=$(find /sys -name ldlm_enqueue_min)
1769     [ -z "$ldlm_enqueue_min" ] && skip "missing /sys/.../ldlm_enqueue_min" && return 0
1770     local ldlm_enqueue_min_r=$(do_facet ost1 "find /sys -name ldlm_enqueue_min")
1771     [ -z "$ldlm_enqueue_min_r" ] && skip "missing /sys/.../ldlm_enqueue_min in the ost1" && return 0
1772     local ENQ_MIN=$(cat $ldlm_enqueue_min)
1773     local ENQ_MIN_R=$(do_facet ost1 "cat $ldlm_enqueue_min_r")
1774     echo $TIMEOUT >> $ldlm_enqueue_min
1775     do_facet ost1 "echo $TIMEOUT >> $ldlm_enqueue_min_r"
1776
1777     rm -rf $DIR/$tdir
1778     mkdir -p $DIR/$tdir
1779     lfs setstripe $DIR/$tdir --index=0 --count=1
1780 #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
1781     $LCTL set_param fail_val=$(($TIMEOUT - 1))
1782     $LCTL set_param fail_loc=0x80000312
1783     cp /etc/profile $DIR/$tdir/${tfile}_1 || error "1st cp failed $?"
1784     $LCTL set_param fail_val=$((TIMEOUT * 5 / 4))
1785     $LCTL set_param fail_loc=0x80000312
1786     cp /etc/profile $DIR/$tdir/${tfile}_2 || error "2nd cp failed $?"
1787     $LCTL set_param fail_loc=0
1788
1789     echo $ENQ_MIN >> $ldlm_enqueue_min
1790     do_facet ost1 "echo $ENQ_MIN_R >> $ldlm_enqueue_min_r"
1791     rm -rf $DIR/$tdir
1792     return 0
1793 }
1794 run_test 68 "AT: verify slowing locks"
1795
1796 at_cleanup
1797 # end of AT tests includes above lines
1798
1799
1800 # start multi-client tests
1801 test_70a () {
1802         [ -z "$CLIENTS" ] && \
1803                 { skip "Need two or more clients." && return; }
1804         [ $CLIENTCOUNT -lt 2 ] && \
1805                 { skip "Need two or more clients, have $CLIENTCOUNT" && return; }
1806
1807         echo "mount clients $CLIENTS ..."
1808         zconf_mount_clients $CLIENTS $MOUNT
1809
1810         local clients=${CLIENTS//,/ }
1811         echo "Write/read files on $DIR ; clients $CLIENTS ... "
1812         for CLIENT in $clients; do
1813                 do_node $CLIENT dd bs=1M count=10 if=/dev/zero \
1814                         of=$DIR/${tfile}_${CLIENT} 2>/dev/null || \
1815                                 error "dd failed on $CLIENT"
1816         done
1817
1818         local prev_client=$(echo $clients | sed 's/^.* \(.\+\)$/\1/')
1819         for C in ${CLIENTS//,/ }; do
1820                 do_node $prev_client dd if=$DIR/${tfile}_${C} of=/dev/null 2>/dev/null || \
1821                         error "dd if=$DIR/${tfile}_${C} failed on $prev_client"
1822                 prev_client=$C
1823         done
1824         
1825         ls $DIR
1826 }
1827 run_test 70a "check multi client t-f"
1828
1829 check_for_process () {
1830         local clients=$1
1831         shift
1832         local prog=$@
1833
1834         killall_process $clients "$prog" -0
1835 }
1836
1837 killall_process () {
1838         local clients=${1:-$(hostname)}
1839         local name=$2
1840         local signal=$3
1841         local rc=0
1842
1843         do_nodes $clients "killall $signal $name"
1844 }
1845
1846 test_70b () {
1847         local clients=${CLIENTS:-$HOSTNAME}
1848
1849         zconf_mount_clients $clients $MOUNT
1850         
1851         local duration=300
1852         [ "$SLOW" = "no" ] && duration=60
1853         # set duration to 900 because it takes some time to boot node
1854         [ "$FAILURE_MODE" = HARD ] && duration=900
1855
1856         local cmd="rundbench 1 -t $duration"
1857         local pid=""
1858         do_nodesv $clients "set -x; MISSING_DBENCH_OK=$MISSING_DBENCH_OK \
1859                 PATH=:$PATH:$LUSTRE/utils:$LUSTRE/tests/:$DBENCH_LIB \
1860                 DBENCH_LIB=$DBENCH_LIB TESTSUITE=$TESTSUITE TESTNAME=$TESTNAME \
1861                 LCTL=$LCTL $cmd" &
1862         pid=$!
1863         log "Started rundbench load pid=$pid ..."
1864
1865         # give rundbench a chance to start, bug 24118
1866         sleep 2
1867         local elapsed=0
1868         local num_failovers=0
1869         local start_ts=$(date +%s)
1870         while [ $elapsed -lt $duration ]; do
1871                 if ! check_for_process $clients rundbench; then
1872                         error_noexit "rundbench not found on some of $clients!"
1873                         killall_process $clients dbench
1874                         break
1875                 fi
1876                 sleep 1
1877                 replay_barrier $SINGLEMDS
1878                 sleep 1 # give clients a time to do operations
1879                 # Increment the number of failovers
1880                 num_failovers=$((num_failovers+1))
1881                 log "$TESTNAME fail $SINGLEMDS $num_failovers times"
1882                 fail $SINGLEMDS
1883                 elapsed=$(($(date +%s) - start_ts))
1884         done
1885
1886         wait $pid || error "rundbench load on $clients failed!"
1887 }
1888 run_test 70b "mds recovery; $CLIENTCOUNT clients"
1889 # end multi-client tests
1890
1891 test_73a() {
1892     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1893     pid=$!
1894     rm -f $DIR/$tfile
1895
1896     replay_barrier $SINGLEMDS
1897 #define OBD_FAIL_LDLM_ENQUEUE       0x302
1898     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000302"
1899     fail $SINGLEMDS
1900     kill -USR1 $pid
1901     wait $pid || return 1
1902     [ -e $DIR/$tfile ] && return 2
1903     return 0
1904 }
1905 run_test 73a "open(O_CREAT), unlink, replay, reconnect before open replay , close"
1906
1907 test_73b() {
1908     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1909     pid=$!
1910     rm -f $DIR/$tfile
1911
1912     replay_barrier $SINGLEMDS
1913 #define OBD_FAIL_LDLM_REPLY       0x30c
1914     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000030c"
1915     fail $SINGLEMDS
1916     kill -USR1 $pid
1917     wait $pid || return 1
1918     [ -e $DIR/$tfile ] && return 2
1919     return 0
1920 }
1921 run_test 73b "open(O_CREAT), unlink, replay, reconnect at open_replay reply, close"
1922
1923 test_73c() {
1924     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1925     pid=$!
1926     rm -f $DIR/$tfile
1927
1928     replay_barrier $SINGLEMDS
1929 #define OBD_FAIL_TGT_LAST_REPLAY       0x710
1930     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000710"
1931     fail $SINGLEMDS
1932     kill -USR1 $pid
1933     wait $pid || return 1
1934     [ -e $DIR/$tfile ] && return 2
1935     return 0
1936 }
1937 run_test 73c "open(O_CREAT), unlink, replay, reconnect at last_replay, close"
1938
1939 # bug 18554
1940 test_74() {
1941     local clients=${CLIENTS:-$HOSTNAME}
1942
1943     stop ost1
1944     zconf_umount_clients $clients $MOUNT
1945     facet_failover $SINGLEMDS
1946     zconf_mount_clients $clients $MOUNT
1947     mount_facet ost1
1948     touch $DIR/$tfile || return 1
1949     rm $DIR/$tfile || return 2
1950     clients_up || error "client evicted: $?"
1951     return 0
1952 }
1953 run_test 74 "Ensure applications don't fail waiting for OST recovery"
1954
1955 test_80a() {
1956     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1957
1958     mkdir -p $DIR/$tdir
1959     replay_barrier mds2
1960     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir $DIR/$tdir failed"
1961     rmdir $DIR/$tdir || error "rmdir $DIR/$tdir failed"
1962     fail mds2
1963     stat $DIR/$tdir 2&>/dev/null && error "$DIR/$tdir still exist after recovery!"
1964     return 0
1965 }
1966 run_test 80a "CMD: unlink cross-node dir (fail mds with inode)"
1967
1968 test_80b() {
1969     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1970
1971     mkdir -p $DIR/$tdir
1972     replay_barrier $SINGLEMDS
1973     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir $DIR/$tdir failed"
1974     rmdir $DIR/$tdir || error "rmdir $DIR/$tdir failed"
1975     fail $SINGLEMDS
1976     stat $DIR/$tdir 2&>/dev/null && error "$DIR/$tdir still exist after recovery!"
1977     return 0
1978 }
1979 run_test 80b "CMD: unlink cross-node dir (fail mds with name)"
1980
1981 test_81a() {
1982     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1983
1984     mkdir -p $DIR/$tdir
1985     createmany -o $DIR/$tdir/f 3000 || error "createmany failed"
1986     sleep 10
1987     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir failed"
1988     $CHECKSTAT -t file $DIR/$tdir/f1002 || error "$CHECKSTAT -t file failed"
1989     replay_barrier $SINGLEMDS
1990     rm $DIR/$tdir/f1002 || error "rm $DIR/$tdir/f1002 failed"
1991     fail $SINGLEMDS
1992     stat $DIR/$tdir/f1002
1993 }
1994 run_test 81a "CMD: unlink cross-node file (fail mds with name)"
1995
1996 test_82a() {
1997     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1998
1999     local dir=$DIR/d82a
2000     replay_barrier mds2
2001     mkdir $dir || error "mkdir $dir failed"
2002     log "FAILOVER mds2"
2003     fail mds2
2004     stat $DIR
2005     $CHECKSTAT -t dir $dir || error "$CHECKSTAT -t dir $dir failed"
2006 }
2007 run_test 82a "CMD: mkdir cross-node dir (fail mds with inode)"
2008
2009 test_82b() {
2010     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2011
2012     local dir=$DIR/d82b
2013     replay_barrier $SINGLEMDS
2014     mkdir $dir || error "mkdir $dir failed"
2015     log "FAILOVER mds1"
2016     fail $SINGLEMDS
2017     stat $DIR
2018     $CHECKSTAT -t dir $dir || error "$CHECKSTAT -t dir $dir failed"
2019 }
2020 run_test 82b "CMD: mkdir cross-node dir (fail mds with name)"
2021
2022 test_83a() {
2023     mkdir -p $DIR/$tdir
2024     createmany -o $DIR/$tdir/$tfile- 10 || return 1
2025 #define OBD_FAIL_MDS_FAIL_LOV_LOG_ADD       0x140
2026     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000140"
2027     unlinkmany $DIR/$tdir/$tfile- 10 || return 2
2028 }
2029 run_test 83a "fail log_add during unlink recovery"
2030
2031 test_83b() {
2032     mkdir -p $DIR/$tdir
2033     createmany -o $DIR/$tdir/$tfile- 10 || return 1
2034     replay_barrier $SINGLEMDS
2035     unlinkmany $DIR/$tdir/$tfile- 10 || return 2
2036 #define OBD_FAIL_MDS_FAIL_LOV_LOG_ADD       0x140
2037     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000140"
2038     fail $SINGLEMDS
2039 }
2040 run_test 83b "fail log_add during unlink recovery"
2041
2042 test_84a() {
2043 #define OBD_FAIL_MDS_OPEN_WAIT_CREATE  0x144
2044     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000144"
2045     createmany -o $DIR/$tfile- 1 &
2046     PID=$!
2047     mds_evict_client
2048     wait $PID
2049     client_up || client_up || true    # reconnect
2050 }
2051 run_test 84a "stale open during export disconnect"
2052
2053 test_85a() { #bug 16774
2054     lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
2055
2056     for i in `seq 100`; do
2057         echo "tag-$i" > $DIR/$tfile-$i
2058         grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
2059     done
2060
2061     lov_id=`lctl dl | grep "clilov"`
2062     addr=`echo $lov_id | awk '{print $4}' | awk -F '-' '{print $3}'`
2063     count=`lctl get_param -n ldlm.namespaces.*MDT0000*$addr.lock_unused_count`
2064     echo "before recovery: unused locks count = $count"
2065
2066     fail $SINGLEMDS
2067
2068     count2=`lctl get_param -n ldlm.namespaces.*MDT0000*$addr.lock_unused_count`
2069     echo "after recovery: unused locks count = $count2"
2070
2071     if [ $count2 -ge $count ]; then
2072         error "unused locks are not canceled"
2073     fi
2074 }
2075 run_test 85a "check the cancellation of unused locks during recovery(IBITS)"
2076
2077 test_85b() { #bug 16774
2078     lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
2079
2080     lfs setstripe -o 0 -c 1 $DIR
2081
2082     for i in `seq 100`; do
2083         dd if=/dev/urandom of=$DIR/$tfile-$i bs=4096 count=32 >/dev/null 2>&1
2084     done
2085
2086     cancel_lru_locks osc
2087
2088     for i in `seq 100`; do
2089         dd if=$DIR/$tfile-$i of=/dev/null bs=4096 count=32 >/dev/null 2>&1
2090     done
2091
2092     lov_id=`lctl dl | grep "clilov"`
2093     addr=`echo $lov_id | awk '{print $4}' | awk -F '-' '{print $3}'`
2094     count=`lctl get_param -n ldlm.namespaces.*OST0000*$addr.lock_unused_count`
2095     echo "before recovery: unused locks count = $count"
2096
2097     fail ost1
2098
2099     count2=`lctl get_param -n ldlm.namespaces.*OST0000*$addr.lock_unused_count`
2100     echo "after recovery: unused locks count = $count2"
2101
2102     if [ $count2 -ge $count ]; then
2103         error "unused locks are not canceled"
2104     fi
2105 }
2106 run_test 85b "check the cancellation of unused locks during recovery(EXTENT)"
2107
2108 test_86() {
2109         local clients=${CLIENTS:-$HOSTNAME}
2110
2111         zconf_umount_clients $clients $MOUNT
2112         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT*.exports.clear=0
2113         remount_facet $SINGLEMDS
2114         zconf_mount_clients $clients $MOUNT
2115 }
2116 run_test 86 "umount server after clear nid_stats should not hit LBUG"
2117
2118 test_87() {
2119     do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
2120
2121     replay_barrier ost1
2122     lfs setstripe -i 0 -c 1 $DIR/$tfile
2123     dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 || error "Cannot write"
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 87 "write replay"
2134
2135 test_87b() {
2136     do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
2137
2138     replay_barrier ost1
2139     lfs setstripe -i 0 -c 1 $DIR/$tfile
2140     dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 || error "Cannot write"
2141     sleep 1 # Give it a chance to flush dirty data
2142     echo TESTTEST | dd of=$DIR/$tfile bs=1 count=8 seek=64
2143     cksum=`md5sum $DIR/$tfile | awk '{print $1}'`
2144     cancel_lru_locks osc
2145     fail ost1
2146     dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
2147     cksum2=`md5sum $DIR/$tfile | awk '{print $1}'`
2148     if [ $cksum != $cksum2 ] ; then
2149         error "New checksum $cksum2 does not match original $cksum"
2150     fi
2151 }
2152 run_test 87b "write replay with changed data (checksum resend)"
2153
2154 test_88() { #bug 17485
2155     mkdir -p $DIR/$tdir
2156     mkdir -p $TMP/$tdir
2157
2158     lfs setstripe $DIR/$tdir -o 0 -c 1 || error "setstripe"
2159
2160     replay_barrier ost1
2161     replay_barrier $SINGLEMDS
2162
2163     # exhaust precreations on ost1
2164     local OST=$(ostname_from_index 0)
2165     local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $OST)
2166     local last_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
2167     local next_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
2168     echo "before test: last_id = $last_id, next_id = $next_id"
2169
2170     echo "Creating to objid $last_id on ost $OST..."
2171     createmany -o $DIR/$tdir/f-%d $next_id $((last_id - next_id + 2))
2172
2173     #create some files to use some uncommitted objids
2174     last_id=$(($last_id + 1))
2175     createmany -o $DIR/$tdir/f-%d $last_id 8
2176
2177     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
2178     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
2179     echo "before recovery: last_id = $last_id2, next_id = $next_id2" 
2180
2181     # if test uses shutdown_facet && reboot_facet instead of facet_failover ()
2182     # it has to take care about the affected facets, bug20407
2183     local affected_mds1=$(affected_facets mds1)
2184     local affected_ost1=$(affected_facets ost1)
2185
2186     shutdown_facet $SINGLEMDS
2187     shutdown_facet ost1
2188
2189     reboot_facet $SINGLEMDS
2190     change_active $affected_mds1
2191     wait_for_facet $affected_mds1
2192     mount_facets $affected_mds1 || error "Restart of mds failed"
2193
2194     reboot_facet ost1
2195     change_active $affected_ost1
2196     wait_for_facet $affected_ost1
2197     mount_facets $affected_ost1 || error "Restart of ost1 failed"
2198
2199     clients_up
2200
2201     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
2202     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
2203     echo "after recovery: last_id = $last_id2, next_id = $next_id2" 
2204
2205     # create new files, which should use new objids, and ensure the orphan 
2206     # cleanup phase for ost1 is completed at the same time
2207     for i in `seq 8`; do
2208         file_id=$(($last_id + 10 + $i))
2209         dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
2210     done
2211
2212     # if the objids were not recreated, then "ls" will failed for -ENOENT
2213     ls -l $DIR/$tdir/* || error "can't get the status of precreated files"
2214
2215     local file_id
2216     # write into previously created files
2217     for i in `seq 8`; do
2218         file_id=$(($last_id + $i))
2219         dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
2220         cp -f $DIR/$tdir/f-$file_id $TMP/$tdir/
2221     done
2222
2223     # compare the content
2224     for i in `seq 8`; do
2225         file_id=$(($last_id + $i))
2226         cmp $TMP/$tdir/f-$file_id $DIR/$tdir/f-$file_id || error "the content" \
2227         "of file is modified!"
2228     done
2229
2230     rm -fr $TMP/$tdir
2231 }
2232 run_test 88 "MDS should not assign same objid to different files "
2233
2234 test_89() {
2235         cancel_lru_locks osc
2236         mkdir -p $DIR/$tdir
2237         rm -f $DIR/$tdir/$tfile
2238         wait_mds_ost_sync
2239         wait_destroy_complete
2240         BLOCKS1=$(df -P $MOUNT | tail -n 1 | awk '{ print $3 }')
2241         lfs setstripe -i 0 -c 1 $DIR/$tdir/$tfile
2242         dd if=/dev/zero bs=1M count=10 of=$DIR/$tdir/$tfile
2243         sync
2244         stop ost1
2245         facet_failover $SINGLEMDS
2246         rm $DIR/$tdir/$tfile
2247         umount $MOUNT
2248         mount_facet ost1
2249         zconf_mount $(hostname) $MOUNT
2250         client_up || return 1
2251         wait_mds_ost_sync
2252         BLOCKS2=$(df -P $MOUNT | tail -n 1 | awk '{ print $3 }')
2253         [ "$BLOCKS1" == "$BLOCKS2" ] || error $((BLOCKS2 - BLOCKS1)) blocks leaked
2254 }
2255
2256 run_test 89 "no disk space leak on late ost connection"
2257
2258 cleanup_90 () {
2259     local facet=$1
2260     trap 0
2261     reboot_facet $facet
2262     change_active $facet
2263     wait_for_facet $facet
2264     mount_facet $facet || error "Restart of $facet failed"
2265     clients_up
2266 }
2267
2268 test_90() { # bug 19494
2269     local dir=$DIR/$tdir
2270     local ostfail=$(get_random_entry $(get_facets OST))
2271
2272     if [[ $FAILURE_MODE = HARD ]]; then
2273         local affected=$(affected_facets $ostfail);
2274         if [[ "$affected" != $ostfail ]]; then
2275             skip not functional with FAILURE_MODE=$FAILURE_MODE, affected: $affected
2276             return 0
2277         fi
2278     fi
2279
2280     mkdir -p $dir
2281
2282     echo "Create the files"
2283
2284     # file "f${index}" striped over 1 OST
2285     # file "all" striped over all OSTs
2286
2287     $LFS setstripe -c $OSTCOUNT $dir/all || error "setstripe failed to create $dir/all"
2288
2289     for (( i=0; i<$OSTCOUNT; i++ )); do
2290         local f=$dir/f$i
2291         $LFS setstripe -i $i -c 1 $f || error "setstripe failed to create $f"
2292
2293         # confirm that setstripe actually created the stripe on the requested OST
2294         local uuid=$(ostuuid_from_index $i)
2295         for file in f$i all; do
2296             if [[ $dir/$file != $($LFS find --obd $uuid --name $file $dir) ]]; then
2297                 $LFS getstripe $dir/file
2298                 error wrong stripe: $file, uuid: $uuid
2299             fi
2300         done
2301     done
2302
2303     # Before failing an OST, get its obd name and index
2304     local varsvc=${ostfail}_svc
2305     local obd=$(do_facet $ostfail lctl get_param -n obdfilter.${!varsvc}.uuid)
2306     local index=${obd:(-6):1}
2307
2308     echo "Fail $ostfail $obd, display the list of affected files"
2309     shutdown_facet $ostfail || return 2
2310
2311     trap "cleanup_90 $ostfail" EXIT INT
2312     echo "General Query: lfs find $dir"
2313     local list=$($LFS find $dir)
2314     echo "$list"
2315     for (( i=0; i<$OSTCOUNT; i++ )); do
2316         list_member "$list" $dir/f$i || error_noexit "lfs find $dir: no file f$i"
2317     done
2318     list_member "$list" $dir/all || error_noexit "lfs find $dir: no file all"
2319
2320     # focus on the missing OST,
2321     # we expect to see only two files affected: "f$(index)" and "all"
2322
2323     echo "Querying files on shutdown $ostfail: lfs find --obd $obd"
2324     list=$($LFS find --obd $obd $dir)
2325     echo "$list"
2326     for file in all f$index; do
2327         list_member "$list" $dir/$file ||
2328             error_noexit "lfs find does not report the affected $obd for $file"
2329     done
2330
2331     [[ $(echo $list | wc -w) -eq 2 ]] ||
2332         error_noexit "lfs find reports the wrong list of affected files ${#list[@]}"
2333
2334     echo "Check getstripe: lfs getstripe -r --obd $obd"
2335     list=$($LFS getstripe -r --obd $obd $dir)
2336     echo "$list"
2337     for file in all f$index; do
2338         echo "$list" | grep $dir/$file ||
2339             error_noexit "lfs getsripe does not report the affected $obd for $file"
2340     done
2341
2342     cleanup_90 $ostfail
2343 }
2344 run_test 90 "lfs find identifies the missing striped file segments"
2345
2346 complete $(basename $0) $SECONDS
2347 check_and_cleanup_lustre
2348 exit_status