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