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