Whamcloud - gitweb
LU-1285 tests: fix tar breakage in 102d/102f/102j
[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     $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     $SETSTRIPE -S $((128 * 1024)) -i 0 $f
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 &&
836         return 4
837     do_facet $SINGLEMDS $LCTL --device $osc2dev deactivate || return 1
838     do_facet client dd if=$f of=/dev/null bs=4k count=1 || return 3
839     do_facet $SINGLEMDS $LCTL --device $osc2dev activate || return 2
840     return 0
841 }
842 run_test 41 "read from a valid osc while other oscs are invalid"
843
844 # test MDS recovery after ost failure
845 test_42() {
846     blocks=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
847     createmany -o $DIR/$tfile-%d 800
848     replay_barrier ost1
849     unlinkmany $DIR/$tfile-%d 0 400
850     debugsave
851     lctl set_param debug=-1
852     facet_failover ost1
853
854     # osc is evicted, fs is smaller (but only with failout OSTs (bug 7287)
855     #blocks_after=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
856     #[ $blocks_after -lt $blocks ] || return 1
857     echo wait for MDS to timeout and recover
858     sleep $((TIMEOUT * 2))
859     debugrestore
860     unlinkmany $DIR/$tfile-%d 400 400
861     $CHECKSTAT -t file $DIR/$tfile-* && return 2 || true
862 }
863 run_test 42 "recovery after ost failure"
864
865 # timeout in MDS/OST recovery RPC will LBUG MDS
866 test_43() { # bug 2530
867     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
868
869     replay_barrier $SINGLEMDS
870
871     # OBD_FAIL_OST_CREATE_NET 0x204
872     do_facet ost1 "lctl set_param fail_loc=0x80000204"
873     fail $SINGLEMDS
874     sleep 10
875     do_facet ost1 "lctl set_param fail_loc=0"
876
877     return 0
878 }
879 run_test 43 "mds osc import failure during recovery; don't LBUG"
880
881 test_44a() { # was test_44
882     local at_max_saved=0
883
884     mdcdev=`lctl get_param -n devices | awk '/MDT0000-mdc-/ {print $1}'`
885     [ "$mdcdev" ] || return 2
886     [ $(echo $mdcdev | wc -w) -eq 1 ] || { echo $mdcdev=$mdcdev && return 3; }
887
888     # adaptive timeouts slow this way down
889     if at_is_enabled; then
890         at_max_saved=$(at_max_get mds)
891         at_max_set 40 mds
892     fi
893
894     for i in `seq 1 10`; do
895         echo "$i of 10 ($(date +%s))"
896         do_facet $SINGLEMDS "lctl get_param -n mdt.*.mdt.timeouts | grep service"
897         #define OBD_FAIL_TGT_CONN_RACE     0x701
898         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000701"
899         # lctl below may fail, it is valid case
900         $LCTL --device $mdcdev recover
901         df $MOUNT
902     done
903     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
904     [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds
905     return 0
906 }
907 run_test 44a "race in target handle connect"
908
909 test_44b() {
910     local mdcdev=`lctl get_param -n devices | awk '/MDT0000-mdc-/ {print $1}'`
911     [ "$mdcdev" ] || return 2
912     [ $(echo $mdcdev | wc -w) -eq 1 ] || { echo $mdcdev=$mdcdev && return 3; }
913
914     for i in `seq 1 10`; do
915         echo "$i of 10 ($(date +%s))"
916         do_facet $SINGLEMDS "lctl get_param -n mdt.*.mdt.timeouts | grep service"
917         #define OBD_FAIL_TGT_DELAY_RECONNECT 0x704
918         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000704"
919         # lctl below may fail, it is valid case
920         $LCTL --device $mdcdev recover
921         df $MOUNT
922     done
923     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
924     return 0
925 }
926 run_test 44b "race in target handle connect"
927
928 test_44c() {
929     replay_barrier $SINGLEMDS
930     createmany -m $DIR/$tfile-%d 100
931 #define OBD_FAIL_TGT_RCVG_FLAG 0x712
932     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000712"
933     fail_abort $SINGLEMDS
934     unlinkmany $DIR/$tfile-%d 100 && return 1
935     fail $SINGLEMDS
936     unlinkmany $DIR/$tfile-%d 100 && return 1
937     return 0
938 }
939 run_test 44c "race in target handle connect"
940
941 # Handle failed close
942 test_45() {
943     mdcdev=`lctl get_param -n devices | awk '/MDT0000-mdc-/ {print $1}'`
944     [ "$mdcdev" ] || return 2
945     [ $(echo $mdcdev | wc -w) -eq 1 ] || { echo $mdcdev=$mdcdev && return 3; }
946
947     $LCTL --device $mdcdev recover || return 6 
948
949     multiop_bg_pause $DIR/$tfile O_c || return 1
950     pid=$!
951
952     # This will cause the CLOSE to fail before even
953     # allocating a reply buffer
954     $LCTL --device $mdcdev deactivate || return 4
955
956     # try the close
957     kill -USR1 $pid
958     wait $pid || return 1
959
960     $LCTL --device $mdcdev activate || return 5
961     sleep 1
962
963     $CHECKSTAT -t file $DIR/$tfile || return 2
964     return 0
965 }
966 run_test 45 "Handle failed close"
967
968 test_46() {
969     dmesg -c >/dev/null
970     drop_reply "touch $DIR/$tfile"
971     fail $SINGLEMDS
972     # ironically, the previous test, 45, will cause a real forced close,
973     # so just look for one for this test
974     dmesg | grep -i "force closing client file handle for $tfile" && return 1
975     return 0
976 }
977 run_test 46 "Don't leak file handle after open resend (3325)"
978
979 test_47() { # bug 2824
980     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
981
982     # create some files to make sure precreate has been done on all
983     # OSTs. (just in case this test is run independently)
984     createmany -o $DIR/$tfile 20  || return 1
985
986     # OBD_FAIL_OST_CREATE_NET 0x204
987     fail ost1
988     do_facet ost1 "lctl set_param fail_loc=0x80000204"
989     client_up || return 2
990
991     # let the MDS discover the OST failure, attempt to recover, fail
992     # and recover again.
993     sleep $((3 * TIMEOUT))
994
995     # Without 2824, this createmany would hang
996     createmany -o $DIR/$tfile 20 || return 3
997     unlinkmany $DIR/$tfile 20 || return 4
998
999     do_facet ost1 "lctl set_param fail_loc=0"
1000     return 0
1001 }
1002 run_test 47 "MDS->OSC failure during precreate cleanup (2824)"
1003
1004 test_48() {
1005     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1006     [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
1007
1008     replay_barrier $SINGLEMDS
1009     createmany -o $DIR/$tfile 20  || return 1
1010     # OBD_FAIL_OST_EROFS 0x216
1011     facet_failover $SINGLEMDS
1012     do_facet ost1 "lctl set_param fail_loc=0x80000216"
1013     client_up || return 2
1014
1015     createmany -o $DIR/$tfile 20 20 || return 2
1016     unlinkmany $DIR/$tfile 40 || return 3
1017     return 0
1018 }
1019 run_test 48 "MDS->OSC failure during precreate cleanup (2824)"
1020
1021 test_50() {
1022     local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $ost1_svc) 
1023     local oscdev=$(do_facet $SINGLEMDS "lctl get_param -n devices" | \
1024         grep $mdtosc | awk '{print $1}')
1025     [ "$oscdev" ] || return 1
1026     do_facet $SINGLEMDS $LCTL --device $oscdev recover || return 2
1027     do_facet $SINGLEMDS $LCTL --device $oscdev recover || return 3
1028     # give the mds_lov_sync threads a chance to run
1029     sleep 5
1030 }
1031 run_test 50 "Double OSC recovery, don't LASSERT (3812)"
1032
1033 # b3764 timed out lock replay
1034 test_52() {
1035     touch $DIR/$tfile
1036     cancel_lru_locks mdc
1037
1038     multiop $DIR/$tfile s || return 1
1039     replay_barrier $SINGLEMDS
1040 #define OBD_FAIL_LDLM_REPLY              0x30c
1041     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000030c"
1042     fail $SINGLEMDS || return 2
1043     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1044
1045     $CHECKSTAT -t file $DIR/$tfile-* && return 3 || true
1046 }
1047 run_test 52 "time out lock replay (3764)"
1048
1049 # bug 3462 - simultaneous MDC requests
1050 test_53a() {
1051         cancel_lru_locks mdc    # cleanup locks from former test cases
1052         mkdir -p $DIR/${tdir}-1
1053         mkdir -p $DIR/${tdir}-2
1054         multiop $DIR/${tdir}-1/f O_c &
1055         close_pid=$!
1056         # give multiop a change to open
1057         sleep 1
1058
1059         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1060         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1061         kill -USR1 $close_pid
1062         cancel_lru_locks mdc    # force the close
1063         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1064
1065         mcreate $DIR/${tdir}-2/f || return 1
1066
1067         # close should still be here
1068         [ -d /proc/$close_pid ] || return 2
1069
1070         replay_barrier_nodf $SINGLEMDS
1071         fail $SINGLEMDS
1072         wait $close_pid || return 3
1073
1074         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1075         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1076         rm -rf $DIR/${tdir}-*
1077 }
1078 run_test 53a "|X| close request while two MDC requests in flight"
1079
1080 test_53b() {
1081         cancel_lru_locks mdc    # cleanup locks from former test cases
1082         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1083
1084         mkdir -p $DIR/${tdir}-1
1085         mkdir -p $DIR/${tdir}-2
1086         multiop_bg_pause $DIR/${tdir}-1/f O_c || return 6
1087         close_pid=$!
1088
1089         #define OBD_FAIL_MDS_REINT_NET 0x107
1090         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1091         mcreate $DIR/${tdir}-2/f &
1092         open_pid=$!
1093         sleep 1
1094
1095         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1096         kill -USR1 $close_pid
1097         cancel_lru_locks mdc    # force the close
1098         wait $close_pid || return 1
1099         # open should still be here
1100         [ -d /proc/$open_pid ] || return 2
1101
1102         replay_barrier_nodf $SINGLEMDS
1103         fail $SINGLEMDS
1104         wait $open_pid || return 3
1105
1106         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1107         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1108         rm -rf $DIR/${tdir}-*
1109 }
1110 run_test 53b "|X| open request while two MDC requests in flight"
1111
1112 test_53c() {
1113         cancel_lru_locks mdc    # cleanup locks from former test cases
1114         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1115
1116         mkdir -p $DIR/${tdir}-1
1117         mkdir -p $DIR/${tdir}-2
1118         multiop $DIR/${tdir}-1/f O_c &
1119         close_pid=$!
1120
1121         #define OBD_FAIL_MDS_REINT_NET 0x107
1122         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1123         mcreate $DIR/${tdir}-2/f &
1124         open_pid=$!
1125         sleep 1
1126
1127         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1128         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1129         kill -USR1 $close_pid
1130         cancel_lru_locks mdc    # force the close
1131
1132         #bz20647: make sure all pids are exists before failover
1133         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1134         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1135         replay_barrier_nodf $SINGLEMDS
1136         fail_nodf $SINGLEMDS
1137         wait $open_pid || return 1
1138         sleep 2
1139         # close should be gone
1140         [ -d /proc/$close_pid ] && return 2
1141         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1142
1143         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1144         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1145         rm -rf $DIR/${tdir}-*
1146 }
1147 run_test 53c "|X| open request and close request while two MDC requests in flight"
1148
1149 test_53d() {
1150         cancel_lru_locks mdc    # cleanup locks from former test cases
1151         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1152
1153         mkdir -p $DIR/${tdir}-1
1154         mkdir -p $DIR/${tdir}-2
1155         multiop $DIR/${tdir}-1/f O_c &
1156         close_pid=$!
1157         # give multiop a chance to open
1158         sleep 1
1159
1160         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1161         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1162         kill -USR1 $close_pid
1163         cancel_lru_locks mdc    # force the close
1164         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1165         mcreate $DIR/${tdir}-2/f || return 1
1166
1167         # close should still be here
1168         [ -d /proc/$close_pid ] || return 2
1169         fail $SINGLEMDS
1170         wait $close_pid || return 3
1171
1172         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1173         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1174         rm -rf $DIR/${tdir}-*
1175 }
1176 run_test 53d "|X| close reply while two MDC requests in flight"
1177
1178 test_53e() {
1179         cancel_lru_locks mdc    # cleanup locks from former test cases
1180         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1181
1182         mkdir -p $DIR/${tdir}-1
1183         mkdir -p $DIR/${tdir}-2
1184         multiop $DIR/${tdir}-1/f O_c &
1185         close_pid=$!
1186
1187         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1188         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1189         mcreate $DIR/${tdir}-2/f &
1190         open_pid=$!
1191         sleep 1
1192
1193         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1194         kill -USR1 $close_pid
1195         cancel_lru_locks mdc    # force the close
1196         wait $close_pid || return 1
1197         # open should still be here
1198         [ -d /proc/$open_pid ] || return 2
1199
1200         replay_barrier_nodf $SINGLEMDS
1201         fail $SINGLEMDS
1202         wait $open_pid || return 3
1203
1204         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1205         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1206         rm -rf $DIR/${tdir}-*
1207 }
1208 run_test 53e "|X| open reply while two MDC requests in flight"
1209
1210 test_53f() {
1211         cancel_lru_locks mdc    # cleanup locks from former test cases
1212         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1213
1214         mkdir -p $DIR/${tdir}-1
1215         mkdir -p $DIR/${tdir}-2
1216         multiop $DIR/${tdir}-1/f O_c &
1217         close_pid=$!
1218
1219         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1220         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1221         mcreate $DIR/${tdir}-2/f &
1222         open_pid=$!
1223         sleep 1
1224
1225         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1226         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1227         kill -USR1 $close_pid
1228         cancel_lru_locks mdc    # force the close
1229
1230         #bz20647: make sure all pids are exists before failover
1231         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1232         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1233         replay_barrier_nodf $SINGLEMDS
1234         fail_nodf $SINGLEMDS
1235         wait $open_pid || return 1
1236         sleep 2
1237         # close should be gone
1238         [ -d /proc/$close_pid ] && return 2
1239         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1240
1241         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1242         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1243         rm -rf $DIR/${tdir}-*
1244 }
1245 run_test 53f "|X| open reply and close reply while two MDC requests in flight"
1246
1247 test_53g() {
1248         cancel_lru_locks mdc    # cleanup locks from former test cases
1249         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1250
1251         mkdir -p $DIR/${tdir}-1
1252         mkdir -p $DIR/${tdir}-2
1253         multiop $DIR/${tdir}-1/f O_c &
1254         close_pid=$!
1255
1256         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1257         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1258         mcreate $DIR/${tdir}-2/f &
1259         open_pid=$!
1260         sleep 1
1261
1262         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1263         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1264         kill -USR1 $close_pid
1265         cancel_lru_locks mdc    # force the close
1266         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1267
1268         #bz20647: make sure all pids are exists before failover
1269         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1270         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1271         replay_barrier_nodf $SINGLEMDS
1272         fail_nodf $SINGLEMDS
1273         wait $open_pid || return 1
1274         sleep 2
1275         # close should be gone
1276         [ -d /proc/$close_pid ] && return 2
1277
1278         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1279         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1280         rm -rf $DIR/${tdir}-*
1281 }
1282 run_test 53g "|X| drop open reply and close request while close and open are both in flight"
1283
1284 test_53h() {
1285         cancel_lru_locks mdc    # cleanup locks from former test cases
1286         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1287
1288         mkdir -p $DIR/${tdir}-1
1289         mkdir -p $DIR/${tdir}-2
1290         multiop $DIR/${tdir}-1/f O_c &
1291         close_pid=$!
1292
1293         #define OBD_FAIL_MDS_REINT_NET 0x107
1294         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1295         mcreate $DIR/${tdir}-2/f &
1296         open_pid=$!
1297         sleep 1
1298
1299         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1300         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1301         kill -USR1 $close_pid
1302         cancel_lru_locks mdc    # force the close
1303         sleep 1
1304
1305         #bz20647: make sure all pids are exists before failover
1306         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1307         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1308         replay_barrier_nodf $SINGLEMDS
1309         fail_nodf $SINGLEMDS
1310         wait $open_pid || return 1
1311         sleep 2
1312         # close should be gone
1313         [ -d /proc/$close_pid ] && return 2
1314         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1315
1316         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1317         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1318         rm -rf $DIR/${tdir}-*
1319 }
1320 run_test 53h "|X| open request and close reply while two MDC requests in flight"
1321
1322 #b_cray 54 "|X| open request and close reply while two MDC requests in flight"
1323
1324 #b3761 ASSERTION(hash != 0) failed
1325 test_55() {
1326 # OBD_FAIL_MDS_OPEN_CREATE | OBD_FAIL_ONCE
1327     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012b"
1328     touch $DIR/$tfile &
1329     # give touch a chance to run
1330     sleep 5
1331     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1332     rm $DIR/$tfile
1333     return 0
1334 }
1335 run_test 55 "let MDS_CHECK_RESENT return the original return code instead of 0"
1336
1337 #b3440 ASSERTION(rec->ur_fid2->id) failed
1338 test_56() {
1339     ln -s foo $DIR/$tfile
1340     replay_barrier $SINGLEMDS
1341     #drop_reply "cat $DIR/$tfile"
1342     fail $SINGLEMDS
1343     sleep 10
1344 }
1345 run_test 56 "don't replay a symlink open request (3440)"
1346
1347 #recovery one mds-ost setattr from llog
1348 test_57() {
1349 #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1350     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1351     touch $DIR/$tfile
1352     replay_barrier $SINGLEMDS
1353     fail $SINGLEMDS
1354     sleep 1
1355     $CHECKSTAT -t file $DIR/$tfile || return 1
1356     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1357     rm $DIR/$tfile
1358 }
1359 run_test 57 "test recovery from llog for setattr op"
1360
1361 #recovery many mds-ost setattr from llog
1362 test_58a() {
1363     mkdir -p $DIR/$tdir
1364 #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1365     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1366     createmany -o $DIR/$tdir/$tfile-%d 2500
1367     replay_barrier $SINGLEMDS
1368     fail $SINGLEMDS
1369     sleep 2
1370     $CHECKSTAT -t file $DIR/$tdir/$tfile-* >/dev/null || return 1
1371     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1372     unlinkmany $DIR/$tdir/$tfile-%d 2500
1373     rmdir $DIR/$tdir
1374 }
1375 run_test 58a "test recovery from llog for setattr op (test llog_gen_rec)"
1376
1377 test_58b() {
1378     local orig
1379     local new
1380
1381     large_xattr_enabled &&
1382         orig="$(generate_string $(max_xattr_size))" || orig="bar"
1383
1384     mount_client $MOUNT2
1385     mkdir -p $DIR/$tdir
1386     touch $DIR/$tdir/$tfile
1387     replay_barrier $SINGLEMDS
1388     setfattr -n trusted.foo -v $orig $DIR/$tdir/$tfile
1389     fail $SINGLEMDS
1390     new=$(get_xattr_value trusted.foo $MOUNT2/$tdir/$tfile)
1391     [[ "$new" = "$orig" ]] || return 1
1392     rm -f $DIR/$tdir/$tfile
1393     rmdir $DIR/$tdir
1394     zconf_umount `hostname` $MOUNT2
1395 }
1396 run_test 58b "test replay of setxattr op"
1397
1398 test_58c() { # bug 16570
1399     local orig
1400     local orig1
1401     local new
1402
1403     if large_xattr_enabled; then
1404         local xattr_size=$(max_xattr_size)
1405         orig="$(generate_string $((xattr_size / 2)))"
1406         orig1="$(generate_string $xattr_size)"
1407     else
1408         orig="bar"
1409         orig1="bar1"
1410     fi
1411
1412     mount_client $MOUNT2
1413     mkdir -p $DIR/$tdir
1414     touch $DIR/$tdir/$tfile
1415     drop_request "setfattr -n trusted.foo -v $orig $DIR/$tdir/$tfile" ||
1416         return 1
1417     new=$(get_xattr_value trusted.foo $MOUNT2/$tdir/$tfile)
1418     [[ "$new" = "$orig" ]] || return 2
1419     drop_reint_reply "setfattr -n trusted.foo1 -v $orig1 $DIR/$tdir/$tfile" ||
1420         return 3
1421     new=$(get_xattr_value trusted.foo1 $MOUNT2/$tdir/$tfile)
1422     [[ "$new" = "$orig1" ]] || return 4
1423     rm -f $DIR/$tdir/$tfile
1424     rmdir $DIR/$tdir
1425     zconf_umount $HOSTNAME $MOUNT2
1426 }
1427 run_test 58c "resend/reconstruct setxattr op"
1428
1429 # log_commit_thread vs filter_destroy race used to lead to import use after free
1430 # bug 11658
1431 test_59() {
1432     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1433
1434     mkdir -p $DIR/$tdir
1435     createmany -o $DIR/$tdir/$tfile-%d 200
1436     sync
1437     unlinkmany $DIR/$tdir/$tfile-%d 200
1438 #define OBD_FAIL_PTLRPC_DELAY_RECOV       0x507
1439     do_facet ost1 "lctl set_param fail_loc=0x507"
1440     fail ost1
1441     fail $SINGLEMDS
1442     do_facet ost1 "lctl set_param fail_loc=0x0"
1443     sleep 20
1444     rmdir $DIR/$tdir
1445 }
1446 run_test 59 "test log_commit_thread vs filter_destroy race"
1447
1448 # race between add unlink llog vs cat log init in post_recovery (only for b1_6)
1449 # bug 12086: should no oops and No ctxt error for this test
1450 test_60() {
1451     mkdir -p $DIR/$tdir
1452     createmany -o $DIR/$tdir/$tfile-%d 200
1453     replay_barrier $SINGLEMDS
1454     unlinkmany $DIR/$tdir/$tfile-%d 0 100
1455     fail $SINGLEMDS
1456     unlinkmany $DIR/$tdir/$tfile-%d 100 100
1457     local no_ctxt=`dmesg | grep "No ctxt"`
1458     [ -z "$no_ctxt" ] || error "ctxt is not initialized in recovery"
1459 }
1460 run_test 60 "test llog post recovery init vs llog unlink"
1461
1462 #test race  llog recovery thread vs llog cleanup
1463 test_61a() {    # was test_61
1464     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1465
1466     mkdir -p $DIR/$tdir
1467     createmany -o $DIR/$tdir/$tfile-%d 800
1468     replay_barrier ost1
1469 #   OBD_FAIL_OST_LLOG_RECOVERY_TIMEOUT 0x221
1470     unlinkmany $DIR/$tdir/$tfile-%d 800
1471     set_nodes_failloc "$(osts_nodes)" 0x80000221
1472     facet_failover ost1
1473     sleep 10
1474     fail ost1
1475     sleep 30
1476     set_nodes_failloc "$(osts_nodes)" 0x0
1477
1478     $CHECKSTAT -t file $DIR/$tdir/$tfile-* && return 1
1479     rmdir $DIR/$tdir
1480 }
1481 run_test 61a "test race llog recovery vs llog cleanup"
1482
1483 #test race  mds llog sync vs llog cleanup
1484 test_61b() {
1485 #   OBD_FAIL_MDS_LLOG_SYNC_TIMEOUT 0x13a
1486     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013a"
1487     facet_failover $SINGLEMDS
1488     sleep 10
1489     fail $SINGLEMDS
1490     do_facet client dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 || return 1
1491 }
1492 run_test 61b "test race mds llog sync vs llog cleanup"
1493
1494 #test race  cancel cookie cb vs llog cleanup
1495 test_61c() {
1496     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1497
1498 #   OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT 0x222
1499     touch $DIR/$tfile
1500     set_nodes_failloc "$(osts_nodes)" 0x80000222
1501     rm $DIR/$tfile
1502     sleep 10
1503     fail ost1
1504     set_nodes_failloc "$(osts_nodes)" 0x0
1505 }
1506 run_test 61c "test race mds llog sync vs llog cleanup"
1507
1508 test_61d() { # bug 16002 # bug 17466 # bug 22137
1509 #   OBD_FAIL_OBD_LLOG_SETUP        0x605
1510     stop mgs
1511     do_facet mgs "lctl set_param fail_loc=0x80000605"
1512     start mgs $MGSDEV $MGS_MOUNT_OPTS && error "mgs start should have failed"
1513     do_facet mgs "lctl set_param fail_loc=0"
1514     start mgs $MGSDEV $MGS_MOUNT_OPTS || error "cannot restart mgs"
1515 }
1516 run_test 61d "error in llog_setup should cleanup the llog context correctly"
1517
1518 test_62() { # Bug 15756 - don't mis-drop resent replay
1519     mkdir -p $DIR/$tdir
1520     replay_barrier $SINGLEMDS
1521     createmany -o $DIR/$tdir/$tfile- 25
1522 #define OBD_FAIL_TGT_REPLAY_DROP         0x707
1523     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000707"
1524     fail $SINGLEMDS
1525     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1526     unlinkmany $DIR/$tdir/$tfile- 25 || return 2
1527     return 0
1528 }
1529 run_test 62 "don't mis-drop resent replay"
1530
1531 #Adaptive Timeouts (bug 3055)
1532 AT_MAX_SET=0
1533
1534 at_cleanup () {
1535     local var
1536     local facet
1537     local at_new
1538
1539     echo "Cleaning up AT ..."
1540     if [ -n "$ATOLDBASE" ]; then
1541         local at_history=$($LCTL get_param -n at_history)
1542         do_facet $SINGLEMDS "lctl set_param at_history=$at_history" || true
1543         do_facet ost1 "lctl set_param at_history=$at_history" || true
1544     fi
1545
1546     if [ $AT_MAX_SET -ne 0 ]; then
1547         for facet in mds client ost; do
1548             var=AT_MAX_SAVE_${facet}
1549             echo restore AT on $facet to saved value ${!var}
1550             at_max_set ${!var} $facet
1551             at_new=$(at_max_get $facet)
1552             echo Restored AT value on $facet $at_new
1553             [ $at_new -eq ${!var} ] || \
1554             error "$facet : AT value was not restored SAVED ${!var} NEW $at_new"
1555         done
1556     fi
1557 }
1558
1559 at_start()
1560 {
1561     local at_max_new=600
1562
1563     # Save at_max original values
1564     local facet
1565     if [ $AT_MAX_SET -eq 0 ]; then
1566         # Suppose that all osts have the same at_max
1567         for facet in mds client ost; do
1568             eval AT_MAX_SAVE_${facet}=$(at_max_get $facet)
1569         done
1570     fi
1571     local at_max
1572     for facet in mds client ost; do
1573         at_max=$(at_max_get $facet)
1574         if [ $at_max -ne $at_max_new ]; then
1575             echo "AT value on $facet is $at_max, set it by force temporarily to $at_max_new"
1576             at_max_set $at_max_new $facet
1577             AT_MAX_SET=1
1578         fi
1579     done
1580
1581     if [ -z "$ATOLDBASE" ]; then
1582         ATOLDBASE=$(do_facet $SINGLEMDS "lctl get_param -n at_history")
1583         # speed up the timebase so we can check decreasing AT
1584         do_facet $SINGLEMDS "lctl set_param at_history=8" || true
1585         do_facet ost1 "lctl set_param at_history=8" || true
1586
1587         # sleep for a while to cool down, should be > 8s and also allow
1588         # at least one ping to be sent. simply use TIMEOUT to be safe.
1589         sleep $TIMEOUT
1590     fi
1591 }
1592
1593 test_65a() #bug 3055
1594 {
1595     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1596
1597     at_start || return 0
1598     $LCTL dk > /dev/null
1599     debugsave
1600     $LCTL set_param debug="other"
1601     # Slow down a request to the current service time, this is critical
1602     # because previous tests may have caused this value to increase.
1603     REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
1604                awk '/portal 12/ {print $5}'`
1605     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1606
1607     do_facet $SINGLEMDS lctl set_param fail_val=$((${REQ_DELAY} * 1000))
1608 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1609     do_facet $SINGLEMDS $LCTL set_param fail_loc=0x8000050a
1610     createmany -o $DIR/$tfile 10 > /dev/null
1611     unlinkmany $DIR/$tfile 10 > /dev/null
1612     # check for log message
1613     $LCTL dk | grep "Early reply #" || error "No early reply"
1614     debugrestore
1615     # client should show REQ_DELAY estimates
1616     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1617     sleep 9
1618     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1619 }
1620 run_test 65a "AT: verify early replies"
1621
1622 test_65b() #bug 3055
1623 {
1624     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1625
1626     at_start || return 0
1627     # turn on D_ADAPTTO
1628     debugsave
1629     $LCTL set_param debug="other trace"
1630     $LCTL dk > /dev/null
1631     # Slow down a request to the current service time, this is critical
1632     # because previous tests may have caused this value to increase.
1633     $SETSTRIPE --stripe-index=0 --count=1 $DIR/$tfile
1634     multiop $DIR/$tfile Ow1yc
1635     REQ_DELAY=`lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts |
1636                awk '/portal 6/ {print $5}'`
1637     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1638
1639     do_facet ost1 lctl set_param fail_val=${REQ_DELAY}
1640 #define OBD_FAIL_OST_BRW_PAUSE_PACK      0x224
1641     do_facet ost1 $LCTL set_param fail_loc=0x224
1642
1643     rm -f $DIR/$tfile
1644     $SETSTRIPE --stripe-index=0 --count=1 $DIR/$tfile
1645     # force some real bulk transfer
1646     multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
1647
1648     do_facet ost1 $LCTL set_param fail_loc=0
1649     # check for log message
1650     $LCTL dk | grep "Early reply #" || error "No early reply"
1651     debugrestore
1652     # client should show REQ_DELAY estimates
1653     lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts | grep portal
1654 }
1655 run_test 65b "AT: verify early replies on packed reply / bulk"
1656
1657 test_66a() #bug 3055
1658 {
1659     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1660
1661     at_start || return 0
1662     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1663     # adjust 5s at a time so no early reply is sent (within deadline)
1664     do_facet $SINGLEMDS "$LCTL set_param fail_val=5000"
1665 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1666     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x8000050a"
1667     createmany -o $DIR/$tfile 20 > /dev/null
1668     unlinkmany $DIR/$tfile 20 > /dev/null
1669     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1670     do_facet $SINGLEMDS "$LCTL set_param fail_val=10000"
1671     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x8000050a"
1672     createmany -o $DIR/$tfile 20 > /dev/null
1673     unlinkmany $DIR/$tfile 20 > /dev/null
1674     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1675     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0"
1676     sleep 9
1677     createmany -o $DIR/$tfile 20 > /dev/null
1678     unlinkmany $DIR/$tfile 20 > /dev/null
1679     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1680     CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $5}')
1681     WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $7}')
1682     echo "Current MDT timeout $CUR, worst $WORST"
1683     [ $CUR -lt $WORST ] || error "Current $CUR should be less than worst $WORST"
1684 }
1685 run_test 66a "AT: verify MDT service time adjusts with no early replies"
1686
1687 test_66b() #bug 3055
1688 {
1689     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1690
1691     at_start || return 0
1692     ORIG=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $4}')
1693     $LCTL set_param fail_val=$(($ORIG + 5))
1694 #define OBD_FAIL_PTLRPC_PAUSE_REP      0x50c
1695     $LCTL set_param fail_loc=0x50c
1696     ls $DIR/$tfile > /dev/null 2>&1
1697     $LCTL set_param fail_loc=0
1698     CUR=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $4}')
1699     WORST=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $6}')
1700     echo "network timeout orig $ORIG, cur $CUR, worst $WORST"
1701     [ $WORST -gt $ORIG ] || error "Worst $WORST should be worse than orig $ORIG"
1702 }
1703 run_test 66b "AT: verify net latency adjusts"
1704
1705 test_67a() #bug 3055
1706 {
1707     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1708
1709     at_start || return 0
1710     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1711     # sleeping threads may drive values above this
1712     do_facet ost1 "$LCTL set_param fail_val=400"
1713 #define OBD_FAIL_PTLRPC_PAUSE_REQ    0x50a
1714     do_facet ost1 "$LCTL set_param fail_loc=0x50a"
1715     createmany -o $DIR/$tfile 20 > /dev/null
1716     unlinkmany $DIR/$tfile 20 > /dev/null
1717     do_facet ost1 "$LCTL set_param fail_loc=0"
1718     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1719     ATTEMPTS=$(($CONN2 - $CONN1))
1720     echo "$ATTEMPTS osc reconnect attempts on gradual slow"
1721     [ $ATTEMPTS -gt 0 ] && error_ignore 13721 "AT should have prevented reconnect"
1722     return 0
1723 }
1724 run_test 67a "AT: verify slow request processing doesn't induce reconnects"
1725
1726 test_67b() #bug 3055
1727 {
1728     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1729
1730     at_start || return 0
1731     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1732
1733     # exhaust precreations on ost1
1734     local OST=$(ostname_from_index 0)
1735     local mdtosc=$(get_mdtosc_proc_path mds $OST)
1736     local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1737         osc.$mdtosc.prealloc_last_id)
1738     local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1739         osc.$mdtosc.prealloc_next_id)
1740
1741     mkdir -p $DIR/$tdir/${OST}
1742     $SETSTRIPE -i 0 -c 1 $DIR/$tdir/${OST} || error "$SETSTRIPE"
1743     echo "Creating to objid $last_id on ost $OST..."
1744 #define OBD_FAIL_OST_PAUSE_CREATE        0x223
1745     do_facet ost1 "$LCTL set_param fail_val=20000"
1746     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1747     createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1748
1749     client_reconnect
1750     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1751     log "phase 2"
1752     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1753     ATTEMPTS=$(($CONN2 - $CONN1))
1754     echo "$ATTEMPTS osc reconnect attempts on instant slow"
1755     # do it again; should not timeout
1756     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1757     cp /etc/profile $DIR/$tfile || error "cp failed"
1758     do_facet ost1 "$LCTL set_param fail_loc=0"
1759     client_reconnect
1760     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1761     CONN3=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1762     ATTEMPTS=$(($CONN3 - $CONN2))
1763     echo "$ATTEMPTS osc reconnect attempts on 2nd slow"
1764     [ $ATTEMPTS -gt 0 ] && error "AT should have prevented reconnect"
1765     return 0
1766 }
1767 run_test 67b "AT: verify instant slowdown doesn't induce reconnects"
1768
1769 test_68 () #bug 13813
1770 {
1771     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1772
1773     at_start || return 0
1774     local ldlm_enqueue_min=$(find /sys -name ldlm_enqueue_min)
1775     [ -z "$ldlm_enqueue_min" ] && skip "missing /sys/.../ldlm_enqueue_min" && return 0
1776     local ldlm_enqueue_min_r=$(do_facet ost1 "find /sys -name ldlm_enqueue_min")
1777     [ -z "$ldlm_enqueue_min_r" ] && skip "missing /sys/.../ldlm_enqueue_min in the ost1" && return 0
1778     local ENQ_MIN=$(cat $ldlm_enqueue_min)
1779     local ENQ_MIN_R=$(do_facet ost1 "cat $ldlm_enqueue_min_r")
1780     echo $TIMEOUT >> $ldlm_enqueue_min
1781     do_facet ost1 "echo $TIMEOUT >> $ldlm_enqueue_min_r"
1782
1783     rm -rf $DIR/$tdir
1784     mkdir -p $DIR/$tdir
1785     $SETSTRIPE --stripe-index=0 --count=1 $DIR/$tdir
1786 #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
1787     $LCTL set_param fail_val=$(($TIMEOUT - 1))
1788     $LCTL set_param fail_loc=0x80000312
1789     cp /etc/profile $DIR/$tdir/${tfile}_1 || error "1st cp failed $?"
1790     $LCTL set_param fail_val=$((TIMEOUT * 5 / 4))
1791     $LCTL set_param fail_loc=0x80000312
1792     cp /etc/profile $DIR/$tdir/${tfile}_2 || error "2nd cp failed $?"
1793     $LCTL set_param fail_loc=0
1794
1795     echo $ENQ_MIN >> $ldlm_enqueue_min
1796     do_facet ost1 "echo $ENQ_MIN_R >> $ldlm_enqueue_min_r"
1797     rm -rf $DIR/$tdir
1798     return 0
1799 }
1800 run_test 68 "AT: verify slowing locks"
1801
1802 at_cleanup
1803 # end of AT tests includes above lines
1804
1805
1806 # start multi-client tests
1807 test_70a () {
1808         [ -z "$CLIENTS" ] && \
1809                 { skip "Need two or more clients." && return; }
1810         [ $CLIENTCOUNT -lt 2 ] && \
1811                 { skip "Need two or more clients, have $CLIENTCOUNT" && return; }
1812
1813         echo "mount clients $CLIENTS ..."
1814         zconf_mount_clients $CLIENTS $MOUNT
1815
1816         local clients=${CLIENTS//,/ }
1817         echo "Write/read files on $DIR ; clients $CLIENTS ... "
1818         for CLIENT in $clients; do
1819                 do_node $CLIENT dd bs=1M count=10 if=/dev/zero \
1820                         of=$DIR/${tfile}_${CLIENT} 2>/dev/null || \
1821                                 error "dd failed on $CLIENT"
1822         done
1823
1824         local prev_client=$(echo $clients | sed 's/^.* \(.\+\)$/\1/')
1825         for C in ${CLIENTS//,/ }; do
1826                 do_node $prev_client dd if=$DIR/${tfile}_${C} of=/dev/null 2>/dev/null || \
1827                         error "dd if=$DIR/${tfile}_${C} failed on $prev_client"
1828                 prev_client=$C
1829         done
1830         
1831         ls $DIR
1832 }
1833 run_test 70a "check multi client t-f"
1834
1835 check_for_process () {
1836         local clients=$1
1837         shift
1838         local prog=$@
1839
1840         killall_process $clients "$prog" -0
1841 }
1842
1843 killall_process () {
1844         local clients=${1:-$(hostname)}
1845         local name=$2
1846         local signal=$3
1847         local rc=0
1848
1849         do_nodes $clients "killall $signal $name"
1850 }
1851
1852 test_70b () {
1853         local clients=${CLIENTS:-$HOSTNAME}
1854
1855         zconf_mount_clients $clients $MOUNT
1856         
1857         local duration=300
1858         [ "$SLOW" = "no" ] && duration=60
1859         # set duration to 900 because it takes some time to boot node
1860         [ "$FAILURE_MODE" = HARD ] && duration=900
1861
1862         local cmd="rundbench 1 -t $duration"
1863         local pid=""
1864         do_nodesv $clients "set -x; MISSING_DBENCH_OK=$MISSING_DBENCH_OK \
1865                 PATH=:$PATH:$LUSTRE/utils:$LUSTRE/tests/:$DBENCH_LIB \
1866                 DBENCH_LIB=$DBENCH_LIB TESTSUITE=$TESTSUITE TESTNAME=$TESTNAME \
1867                 LCTL=$LCTL $cmd" &
1868         pid=$!
1869         log "Started rundbench load pid=$pid ..."
1870
1871         # give rundbench a chance to start, bug 24118
1872         sleep 2
1873         local elapsed=0
1874         local num_failovers=0
1875         local start_ts=$(date +%s)
1876         while [ $elapsed -lt $duration ]; do
1877                 if ! check_for_process $clients rundbench; then
1878                         error_noexit "rundbench not found on some of $clients!"
1879                         killall_process $clients dbench
1880                         break
1881                 fi
1882                 sleep 1
1883                 replay_barrier $SINGLEMDS
1884                 sleep 1 # give clients a time to do operations
1885                 # Increment the number of failovers
1886                 num_failovers=$((num_failovers+1))
1887                 log "$TESTNAME fail $SINGLEMDS $num_failovers times"
1888                 fail $SINGLEMDS
1889                 elapsed=$(($(date +%s) - start_ts))
1890         done
1891
1892         wait $pid || error "rundbench load on $clients failed!"
1893 }
1894 run_test 70b "mds recovery; $CLIENTCOUNT clients"
1895 # end multi-client tests
1896
1897 test_73a() {
1898     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1899     pid=$!
1900     rm -f $DIR/$tfile
1901
1902     replay_barrier $SINGLEMDS
1903 #define OBD_FAIL_LDLM_ENQUEUE       0x302
1904     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000302"
1905     fail $SINGLEMDS
1906     kill -USR1 $pid
1907     wait $pid || return 1
1908     [ -e $DIR/$tfile ] && return 2
1909     return 0
1910 }
1911 run_test 73a "open(O_CREAT), unlink, replay, reconnect before open replay , close"
1912
1913 test_73b() {
1914     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1915     pid=$!
1916     rm -f $DIR/$tfile
1917
1918     replay_barrier $SINGLEMDS
1919 #define OBD_FAIL_LDLM_REPLY       0x30c
1920     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000030c"
1921     fail $SINGLEMDS
1922     kill -USR1 $pid
1923     wait $pid || return 1
1924     [ -e $DIR/$tfile ] && return 2
1925     return 0
1926 }
1927 run_test 73b "open(O_CREAT), unlink, replay, reconnect at open_replay reply, close"
1928
1929 test_73c() {
1930     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1931     pid=$!
1932     rm -f $DIR/$tfile
1933
1934     replay_barrier $SINGLEMDS
1935 #define OBD_FAIL_TGT_LAST_REPLAY       0x710
1936     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000710"
1937     fail $SINGLEMDS
1938     kill -USR1 $pid
1939     wait $pid || return 1
1940     [ -e $DIR/$tfile ] && return 2
1941     return 0
1942 }
1943 run_test 73c "open(O_CREAT), unlink, replay, reconnect at last_replay, close"
1944
1945 # bug 18554
1946 test_74() {
1947     local clients=${CLIENTS:-$HOSTNAME}
1948
1949     stop ost1
1950     zconf_umount_clients $clients $MOUNT
1951     facet_failover $SINGLEMDS
1952     zconf_mount_clients $clients $MOUNT
1953     mount_facet ost1
1954     touch $DIR/$tfile || return 1
1955     rm $DIR/$tfile || return 2
1956     clients_up || error "client evicted: $?"
1957     return 0
1958 }
1959 run_test 74 "Ensure applications don't fail waiting for OST recovery"
1960
1961 test_80a() {
1962     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1963
1964     mkdir -p $DIR/$tdir
1965     replay_barrier mds2
1966     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir $DIR/$tdir failed"
1967     rmdir $DIR/$tdir || error "rmdir $DIR/$tdir failed"
1968     fail mds2
1969     stat $DIR/$tdir 2&>/dev/null && error "$DIR/$tdir still exist after recovery!"
1970     return 0
1971 }
1972 run_test 80a "CMD: unlink cross-node dir (fail mds with inode)"
1973
1974 test_80b() {
1975     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1976
1977     mkdir -p $DIR/$tdir
1978     replay_barrier $SINGLEMDS
1979     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir $DIR/$tdir failed"
1980     rmdir $DIR/$tdir || error "rmdir $DIR/$tdir failed"
1981     fail $SINGLEMDS
1982     stat $DIR/$tdir 2&>/dev/null && error "$DIR/$tdir still exist after recovery!"
1983     return 0
1984 }
1985 run_test 80b "CMD: unlink cross-node dir (fail mds with name)"
1986
1987 test_81a() {
1988     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1989
1990     mkdir -p $DIR/$tdir
1991     createmany -o $DIR/$tdir/f 3000 || error "createmany failed"
1992     sleep 10
1993     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir failed"
1994     $CHECKSTAT -t file $DIR/$tdir/f1002 || error "$CHECKSTAT -t file failed"
1995     replay_barrier $SINGLEMDS
1996     rm $DIR/$tdir/f1002 || error "rm $DIR/$tdir/f1002 failed"
1997     fail $SINGLEMDS
1998     stat $DIR/$tdir/f1002
1999 }
2000 run_test 81a "CMD: unlink cross-node file (fail mds with name)"
2001
2002 test_82a() {
2003     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2004
2005     local dir=$DIR/d82a
2006     replay_barrier mds2
2007     mkdir $dir || error "mkdir $dir failed"
2008     log "FAILOVER mds2"
2009     fail mds2
2010     stat $DIR
2011     $CHECKSTAT -t dir $dir || error "$CHECKSTAT -t dir $dir failed"
2012 }
2013 run_test 82a "CMD: mkdir cross-node dir (fail mds with inode)"
2014
2015 test_82b() {
2016     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2017
2018     local dir=$DIR/d82b
2019     replay_barrier $SINGLEMDS
2020     mkdir $dir || error "mkdir $dir failed"
2021     log "FAILOVER mds1"
2022     fail $SINGLEMDS
2023     stat $DIR
2024     $CHECKSTAT -t dir $dir || error "$CHECKSTAT -t dir $dir failed"
2025 }
2026 run_test 82b "CMD: mkdir cross-node dir (fail mds with name)"
2027
2028 test_83a() {
2029     mkdir -p $DIR/$tdir
2030     createmany -o $DIR/$tdir/$tfile- 10 || return 1
2031 #define OBD_FAIL_MDS_FAIL_LOV_LOG_ADD       0x140
2032     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000140"
2033     unlinkmany $DIR/$tdir/$tfile- 10 || return 2
2034 }
2035 run_test 83a "fail log_add during unlink recovery"
2036
2037 test_83b() {
2038     mkdir -p $DIR/$tdir
2039     createmany -o $DIR/$tdir/$tfile- 10 || return 1
2040     replay_barrier $SINGLEMDS
2041     unlinkmany $DIR/$tdir/$tfile- 10 || return 2
2042 #define OBD_FAIL_MDS_FAIL_LOV_LOG_ADD       0x140
2043     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000140"
2044     fail $SINGLEMDS
2045 }
2046 run_test 83b "fail log_add during unlink recovery"
2047
2048 test_84a() {
2049 #define OBD_FAIL_MDS_OPEN_WAIT_CREATE  0x144
2050     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000144"
2051     createmany -o $DIR/$tfile- 1 &
2052     PID=$!
2053     mds_evict_client
2054     wait $PID
2055     client_up || client_up || true    # reconnect
2056 }
2057 run_test 84a "stale open during export disconnect"
2058
2059 test_85a() { #bug 16774
2060     lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
2061
2062     for i in `seq 100`; do
2063         echo "tag-$i" > $DIR/$tfile-$i
2064         grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
2065     done
2066
2067     lov_id=`lctl dl | grep "clilov"`
2068     addr=`echo $lov_id | awk '{print $4}' | awk -F '-' '{print $3}'`
2069     count=`lctl get_param -n ldlm.namespaces.*MDT0000*$addr.lock_unused_count`
2070     echo "before recovery: unused locks count = $count"
2071
2072     fail $SINGLEMDS
2073
2074     count2=`lctl get_param -n ldlm.namespaces.*MDT0000*$addr.lock_unused_count`
2075     echo "after recovery: unused locks count = $count2"
2076
2077     if [ $count2 -ge $count ]; then
2078         error "unused locks are not canceled"
2079     fi
2080 }
2081 run_test 85a "check the cancellation of unused locks during recovery(IBITS)"
2082
2083 test_85b() { #bug 16774
2084     lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
2085
2086     do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
2087     do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $FSNAME-OST0000 || return 2
2088
2089     $SETSTRIPE -c 1 -p $FSNAME.$TESTNAME $DIR
2090
2091     for i in `seq 100`; do
2092         dd if=/dev/urandom of=$DIR/$tfile-$i bs=4096 count=32 >/dev/null 2>&1
2093     done
2094
2095     cancel_lru_locks osc
2096
2097     for i in `seq 100`; do
2098         dd if=$DIR/$tfile-$i of=/dev/null bs=4096 count=32 >/dev/null 2>&1
2099     done
2100
2101     lov_id=`lctl dl | grep "clilov"`
2102     addr=`echo $lov_id | awk '{print $4}' | awk -F '-' '{print $3}'`
2103     count=`lctl get_param -n ldlm.namespaces.*OST0000*$addr.lock_unused_count`
2104     echo "before recovery: unused locks count = $count"
2105     [ $count != 0 ] || return 3
2106
2107     fail ost1
2108
2109     count2=`lctl get_param -n ldlm.namespaces.*OST0000*$addr.lock_unused_count`
2110     echo "after recovery: unused locks count = $count2"
2111
2112     do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $FSNAME-OST0000 || return 4
2113     do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
2114
2115     if [ $count2 -ge $count ]; then
2116         error "unused locks are not canceled"
2117     fi
2118 }
2119 run_test 85b "check the cancellation of unused locks during recovery(EXTENT)"
2120
2121 test_86() {
2122         local clients=${CLIENTS:-$HOSTNAME}
2123
2124         zconf_umount_clients $clients $MOUNT
2125         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT*.exports.clear=0
2126         remount_facet $SINGLEMDS
2127         zconf_mount_clients $clients $MOUNT
2128 }
2129 run_test 86 "umount server after clear nid_stats should not hit LBUG"
2130
2131 test_87() {
2132     do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
2133
2134     replay_barrier ost1
2135     $SETSTRIPE -i 0 -c 1 $DIR/$tfile
2136     dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 || error "Cannot write"
2137     cksum=`md5sum $DIR/$tfile | awk '{print $1}'`
2138     cancel_lru_locks osc
2139     fail ost1
2140     dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
2141     cksum2=`md5sum $DIR/$tfile | awk '{print $1}'`
2142     if [ $cksum != $cksum2 ] ; then
2143         error "New checksum $cksum2 does not match original $cksum"
2144     fi
2145 }
2146 run_test 87 "write replay"
2147
2148 test_87b() {
2149     do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
2150
2151     replay_barrier ost1
2152     $SETSTRIPE -i 0 -c 1 $DIR/$tfile
2153     dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 || error "Cannot write"
2154     sleep 1 # Give it a chance to flush dirty data
2155     echo TESTTEST | dd of=$DIR/$tfile bs=1 count=8 seek=64
2156     cksum=`md5sum $DIR/$tfile | awk '{print $1}'`
2157     cancel_lru_locks osc
2158     fail ost1
2159     dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
2160     cksum2=`md5sum $DIR/$tfile | awk '{print $1}'`
2161     if [ $cksum != $cksum2 ] ; then
2162         error "New checksum $cksum2 does not match original $cksum"
2163     fi
2164 }
2165 run_test 87b "write replay with changed data (checksum resend)"
2166
2167 test_88() { #bug 17485
2168     mkdir -p $DIR/$tdir
2169     mkdir -p $TMP/$tdir
2170
2171     $SETSTRIPE -i 0 -c 1 $DIR/$tdir || error "$SETSTRIPE"
2172
2173     replay_barrier ost1
2174     replay_barrier $SINGLEMDS
2175
2176     # exhaust precreations on ost1
2177     local OST=$(ostname_from_index 0)
2178     local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $OST)
2179     local last_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
2180     local next_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
2181     echo "before test: last_id = $last_id, next_id = $next_id"
2182
2183     echo "Creating to objid $last_id on ost $OST..."
2184     createmany -o $DIR/$tdir/f-%d $next_id $((last_id - next_id + 2))
2185
2186     #create some files to use some uncommitted objids
2187     last_id=$(($last_id + 1))
2188     createmany -o $DIR/$tdir/f-%d $last_id 8
2189
2190     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
2191     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
2192     echo "before recovery: last_id = $last_id2, next_id = $next_id2" 
2193
2194     # if test uses shutdown_facet && reboot_facet instead of facet_failover ()
2195     # it has to take care about the affected facets, bug20407
2196     local affected_mds1=$(affected_facets mds1)
2197     local affected_ost1=$(affected_facets ost1)
2198
2199     shutdown_facet $SINGLEMDS
2200     shutdown_facet ost1
2201
2202     reboot_facet $SINGLEMDS
2203     change_active $affected_mds1
2204     wait_for_facet $affected_mds1
2205     mount_facets $affected_mds1 || error "Restart of mds failed"
2206
2207     reboot_facet ost1
2208     change_active $affected_ost1
2209     wait_for_facet $affected_ost1
2210     mount_facets $affected_ost1 || error "Restart of ost1 failed"
2211
2212     clients_up
2213
2214     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
2215     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
2216     echo "after recovery: last_id = $last_id2, next_id = $next_id2" 
2217
2218     # create new files, which should use new objids, and ensure the orphan 
2219     # cleanup phase for ost1 is completed at the same time
2220     for i in `seq 8`; do
2221         file_id=$(($last_id + 10 + $i))
2222         dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
2223     done
2224
2225     # if the objids were not recreated, then "ls" will failed for -ENOENT
2226     ls -l $DIR/$tdir/* || error "can't get the status of precreated files"
2227
2228     local file_id
2229     # write into previously created files
2230     for i in `seq 8`; do
2231         file_id=$(($last_id + $i))
2232         dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
2233         cp -f $DIR/$tdir/f-$file_id $TMP/$tdir/
2234     done
2235
2236     # compare the content
2237     for i in `seq 8`; do
2238         file_id=$(($last_id + $i))
2239         cmp $TMP/$tdir/f-$file_id $DIR/$tdir/f-$file_id || error "the content" \
2240         "of file is modified!"
2241     done
2242
2243     rm -fr $TMP/$tdir
2244 }
2245 run_test 88 "MDS should not assign same objid to different files "
2246
2247 test_89() {
2248         cancel_lru_locks osc
2249         mkdir -p $DIR/$tdir
2250         rm -f $DIR/$tdir/$tfile
2251         wait_mds_ost_sync
2252         wait_destroy_complete
2253         BLOCKS1=$(df -P $MOUNT | tail -n 1 | awk '{ print $3 }')
2254         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/$tfile
2255         dd if=/dev/zero bs=1M count=10 of=$DIR/$tdir/$tfile
2256         sync
2257         stop ost1
2258         facet_failover $SINGLEMDS
2259         rm $DIR/$tdir/$tfile
2260         umount $MOUNT
2261         mount_facet ost1
2262         zconf_mount $(hostname) $MOUNT
2263         client_up || return 1
2264         wait_mds_ost_sync
2265         BLOCKS2=$(df -P $MOUNT | tail -n 1 | awk '{ print $3 }')
2266         [ "$BLOCKS1" == "$BLOCKS2" ] || error $((BLOCKS2 - BLOCKS1)) blocks leaked
2267 }
2268
2269 run_test 89 "no disk space leak on late ost connection"
2270
2271 cleanup_90 () {
2272     local facet=$1
2273     trap 0
2274     reboot_facet $facet
2275     change_active $facet
2276     wait_for_facet $facet
2277     mount_facet $facet || error "Restart of $facet failed"
2278     clients_up
2279 }
2280
2281 test_90() { # bug 19494
2282     local dir=$DIR/$tdir
2283     local ostfail=$(get_random_entry $(get_facets OST))
2284
2285     if [[ $FAILURE_MODE = HARD ]]; then
2286         local affected=$(affected_facets $ostfail);
2287         if [[ "$affected" != $ostfail ]]; then
2288             skip not functional with FAILURE_MODE=$FAILURE_MODE, affected: $affected
2289             return 0
2290         fi
2291     fi
2292
2293     mkdir -p $dir
2294
2295     echo "Create the files"
2296
2297     # file "f${index}" striped over 1 OST
2298     # file "all" striped over all OSTs
2299
2300     $SETSTRIPE -c $OSTCOUNT $dir/all ||
2301         error "setstripe failed to create $dir/all"
2302
2303     for (( i=0; i<$OSTCOUNT; i++ )); do
2304         local f=$dir/f$i
2305         $SETSTRIPE -i $i -c 1 $f || error "$SETSTRIPE failed to create $f"
2306
2307         # confirm setstripe actually created the stripe on the requested OST
2308         local uuid=$(ostuuid_from_index $i)
2309         for file in f$i all; do
2310             if [[ $dir/$file != $($LFS find --obd $uuid --name $file $dir) ]]; then
2311                 $GETSTRIPE $dir/file
2312                 error wrong stripe: $file, uuid: $uuid
2313             fi
2314         done
2315     done
2316
2317     # Before failing an OST, get its obd name and index
2318     local varsvc=${ostfail}_svc
2319     local obd=$(do_facet $ostfail lctl get_param -n obdfilter.${!varsvc}.uuid)
2320     local index=${obd:(-6):1}
2321
2322     echo "Fail $ostfail $obd, display the list of affected files"
2323     shutdown_facet $ostfail || return 2
2324
2325     trap "cleanup_90 $ostfail" EXIT INT
2326     echo "General Query: lfs find $dir"
2327     local list=$($LFS find $dir)
2328     echo "$list"
2329     for (( i=0; i<$OSTCOUNT; i++ )); do
2330         list_member "$list" $dir/f$i || error_noexit "lfs find $dir: no file f$i"
2331     done
2332     list_member "$list" $dir/all || error_noexit "lfs find $dir: no file all"
2333
2334     # focus on the missing OST,
2335     # we expect to see only two files affected: "f$(index)" and "all"
2336
2337     echo "Querying files on shutdown $ostfail: lfs find --obd $obd"
2338     list=$($LFS find --obd $obd $dir)
2339     echo "$list"
2340     for file in all f$index; do
2341         list_member "$list" $dir/$file ||
2342             error_noexit "lfs find does not report the affected $obd for $file"
2343     done
2344
2345     [[ $(echo $list | wc -w) -eq 2 ]] ||
2346         error_noexit "lfs find reports the wrong list of affected files ${#list[@]}"
2347
2348     echo "Check getstripe: $GETSTRIPE -r --obd $obd"
2349     list=$($GETSTRIPE -r --obd $obd $dir)
2350     echo "$list"
2351     for file in all f$index; do
2352         echo "$list" | grep $dir/$file ||
2353             error_noexit "lfs getsripe does not report the affected $obd for $file"
2354     done
2355
2356     cleanup_90 $ostfail
2357 }
2358 run_test 90 "lfs find identifies the missing striped file segments"
2359
2360 complete $(basename $0) $SECONDS
2361 check_and_cleanup_lustre
2362 exit_status