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