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