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