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