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