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