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