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