Whamcloud - gitweb
LU-15210 tests: fix sanity-lnet to handle duplicate IP
[fs/lustre-release.git] / lustre / tests / replay-single.sh
1 #!/bin/bash
2
3 set -e
4
5 LUSTRE=${LUSTRE:-$(dirname $0)/..}
6 . $LUSTRE/tests/test-framework.sh
7 init_test_env $@
8 init_logging
9
10 ALWAYS_EXCEPT="$REPLAY_SINGLE_EXCEPT "
11 # bug number for skipped test: LU-13614
12 ALWAYS_EXCEPT+="               59"
13
14 if [ "$mds1_FSTYPE" = zfs ]; then
15         # bug number for skipped test: LU-11388
16         ALWAYS_EXCEPT+="               131b"
17 fi
18
19 if $SHARED_KEY; then
20         # bug number for skipped tests: LU-9795
21         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   121"
22 fi
23 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
24
25 build_test_filter
26
27 CHECK_GRANT=${CHECK_GRANT:-"yes"}
28 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
29
30 require_dsh_mds || exit 0
31 check_and_setup_lustre
32
33 mkdir -p $DIR
34
35 assert_DIR
36 rm -rf $DIR/[df][0-9]* $DIR/f.$TESTSUITE.*
37
38 # LU-482 Avert LVM and VM inability to flush caches in pre .33 kernels
39 if [ $LINUX_VERSION_CODE -lt $(version_code 2.6.33) ]; then
40     sync
41     do_facet $SINGLEMDS sync
42 fi
43
44 test_0a() {     # was test_0
45         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
46         replay_barrier $SINGLEMDS
47         fail $SINGLEMDS
48         rmdir $DIR/$tdir
49 }
50 run_test 0a "empty replay"
51
52 test_0b() {
53         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
54
55         # this test attempts to trigger a race in the precreation code,
56         # and must run before any other objects are created on the filesystem
57         fail ost1
58         createmany -o $DIR/$tfile 20 || error "createmany -o $DIR/$tfile failed"
59         unlinkmany $DIR/$tfile 20 || error "unlinkmany $DIR/$tfile failed"
60 }
61 run_test 0b "ensure object created after recover exists. (3284)"
62
63 test_0c() {
64         replay_barrier $SINGLEMDS
65         mcreate $DIR/$tfile
66         umount $MOUNT
67         facet_failover $SINGLEMDS
68         zconf_mount $(hostname) $MOUNT || error "mount fails"
69         client_up || error "post-failover df failed"
70         # file shouldn't exist if replay-barrier works as expected
71         rm $DIR/$tfile && error "File exists and it shouldn't"
72         return 0
73 }
74 run_test 0c "check replay-barrier"
75
76 test_0d() {
77         replay_barrier $SINGLEMDS
78         umount $MOUNT
79         facet_failover $SINGLEMDS
80         zconf_mount $(hostname) $MOUNT || error "mount fails"
81         client_up || error "post-failover df failed"
82 }
83 run_test 0d "expired recovery with no clients"
84
85 test_1() {
86         replay_barrier $SINGLEMDS
87         mcreate $DIR/$tfile
88         fail $SINGLEMDS
89         $CHECKSTAT -t file $DIR/$tfile ||
90                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
91         rm $DIR/$tfile
92 }
93 run_test 1 "simple create"
94
95 test_2a() {
96         replay_barrier $SINGLEMDS
97         touch $DIR/$tfile
98         fail $SINGLEMDS
99         $CHECKSTAT -t file $DIR/$tfile ||
100                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
101         rm $DIR/$tfile
102 }
103 run_test 2a "touch"
104
105 test_2b() {
106         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
107         replay_barrier $SINGLEMDS
108         touch $DIR/$tfile
109         fail $SINGLEMDS
110         $CHECKSTAT -t file $DIR/$tfile ||
111                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
112         rm $DIR/$tfile
113 }
114 run_test 2b "touch"
115
116 test_2c() {
117         replay_barrier $SINGLEMDS
118         $LFS setstripe -c $OSTCOUNT $DIR/$tfile
119         fail $SINGLEMDS
120         $CHECKSTAT -t file $DIR/$tfile ||
121                 error "$CHECKSTAT $DIR/$tfile check failed"
122 }
123 run_test 2c "setstripe replay"
124
125 test_2d() {
126         [[ "$mds1_FSTYPE" = zfs ]] &&
127                 [[ "$MDS1_VERSION" -lt $(version_code 2.12.51) ]] &&
128                 skip "requires LU-10143 fix on MDS"
129         replay_barrier $SINGLEMDS
130         $LFS setdirstripe -i 0 -c $MDSCOUNT $DIR/$tdir
131         fail $SINGLEMDS
132         $CHECKSTAT -t dir $DIR/$tdir ||
133                 error "$CHECKSTAT $DIR/$tdir check failed"
134 }
135 run_test 2d "setdirstripe replay"
136
137 test_3a() {
138         local file=$DIR/$tfile
139         replay_barrier $SINGLEMDS
140         mcreate $file
141         openfile -f O_DIRECTORY $file
142         fail $SINGLEMDS
143         $CHECKSTAT -t file $file ||
144                 error "$CHECKSTAT $file attribute check failed"
145         rm $file
146 }
147 run_test 3a "replay failed open(O_DIRECTORY)"
148
149 test_3b() {
150         replay_barrier $SINGLEMDS
151         #define OBD_FAIL_MDS_OPEN_PACK | OBD_FAIL_ONCE
152         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000114"
153         touch $DIR/$tfile
154         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
155         fail $SINGLEMDS
156         $CHECKSTAT -t file $DIR/$tfile &&
157                 error "$CHECKSTAT $DIR/$tfile attribute check should fail"
158         return 0
159 }
160 run_test 3b "replay failed open -ENOMEM"
161
162 test_3c() {
163         replay_barrier $SINGLEMDS
164         #define OBD_FAIL_MDS_ALLOC_OBDO | OBD_FAIL_ONCE
165         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000128"
166         touch $DIR/$tfile
167         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
168         fail $SINGLEMDS
169
170         $CHECKSTAT -t file $DIR/$tfile &&
171                 error "$CHECKSTAT $DIR/$tfile attribute check should fail"
172         return 0
173 }
174 run_test 3c "replay failed open -ENOMEM"
175
176 test_4a() {     # was test_4
177         replay_barrier $SINGLEMDS
178         for i in $(seq 10); do
179                 echo "tag-$i" > $DIR/$tfile-$i
180         done
181         fail $SINGLEMDS
182         for i in $(seq 10); do
183                 grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
184         done
185 }
186 run_test 4a "|x| 10 open(O_CREAT)s"
187
188 test_4b() {
189         for i in $(seq 10); do
190                 echo "tag-$i" > $DIR/$tfile-$i
191         done
192         replay_barrier $SINGLEMDS
193         rm -rf $DIR/$tfile-*
194         fail $SINGLEMDS
195         $CHECKSTAT -t file $DIR/$tfile-* &&
196                 error "$CHECKSTAT $DIR/$tfile-* attribute check should fail" ||
197                 true
198 }
199 run_test 4b "|x| rm 10 files"
200
201 # The idea is to get past the first block of precreated files on both
202 # osts, and then replay.
203 test_5() {
204         replay_barrier $SINGLEMDS
205         for i in $(seq 220); do
206                 echo "tag-$i" > $DIR/$tfile-$i
207         done
208         fail $SINGLEMDS
209         for i in $(seq 220); do
210                 grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
211         done
212         rm -rf $DIR/$tfile-*
213         sleep 3
214         # waiting for commitment of removal
215 }
216 run_test 5 "|x| 220 open(O_CREAT)"
217
218 test_6a() {     # was test_6
219         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
220         replay_barrier $SINGLEMDS
221         mcreate $DIR/$tdir/$tfile
222         fail $SINGLEMDS
223         $CHECKSTAT -t dir $DIR/$tdir ||
224                 error "$CHECKSTAT $DIR/$tdir attribute check failed"
225         $CHECKSTAT -t file $DIR/$tdir/$tfile ||
226                 error "$CHECKSTAT $DIR/$tdir/$tfile attribute check failed"
227         sleep 2
228         # waiting for log process thread
229 }
230 run_test 6a "mkdir + contained create"
231
232 test_6b() {
233         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
234         replay_barrier $SINGLEMDS
235         rm -rf $DIR/$tdir
236         fail $SINGLEMDS
237         $CHECKSTAT -t dir $DIR/$tdir &&
238                 error "$CHECKSTAT $DIR/$tdir attribute check should fail" ||
239                 true
240 }
241 run_test 6b "|X| rmdir"
242
243 test_7() {
244         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
245         replay_barrier $SINGLEMDS
246         mcreate $DIR/$tdir/$tfile
247         fail $SINGLEMDS
248         $CHECKSTAT -t dir $DIR/$tdir ||
249                 error "$CHECKSTAT $DIR/$tdir attribute check failed"
250         $CHECKSTAT -t file $DIR/$tdir/$tfile ||
251                 error "$CHECKSTAT $DIR/$tdir/$tfile attribute check failed"
252         rm -fr $DIR/$tdir
253 }
254 run_test 7 "mkdir |X| contained create"
255
256 test_8() {
257         replay_barrier $SINGLEMDS
258         multiop_bg_pause $DIR/$tfile mo_c ||
259                 error "multiop mknod $DIR/$tfile failed"
260         MULTIPID=$!
261         fail $SINGLEMDS
262         ls $DIR/$tfile
263         $CHECKSTAT -t file $DIR/$tfile ||
264                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
265         kill -USR1 $MULTIPID || error "multiop mknod $MULTIPID not running"
266         wait $MULTIPID || error "multiop mknod $MULTIPID failed"
267         rm $DIR/$tfile
268 }
269 run_test 8 "creat open |X| close"
270
271 test_9() {
272         replay_barrier $SINGLEMDS
273         mcreate $DIR/$tfile
274         local old_inum=$(ls -i $DIR/$tfile | awk '{print $1}')
275         fail $SINGLEMDS
276         local new_inum=$(ls -i $DIR/$tfile | awk '{print $1}')
277
278         echo " old_inum == $old_inum, new_inum == $new_inum"
279         if [ $old_inum -eq $new_inum  ] ;
280         then
281                 echo "old_inum and new_inum match"
282         else
283                 echo " old_inum and new_inum do not match"
284                 error "old index($old_inum) does not match new index($new_inum)"
285         fi
286         rm $DIR/$tfile
287 }
288 run_test 9 "|X| create (same inum/gen)"
289
290 test_10() {
291         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
292         replay_barrier $SINGLEMDS
293         mv $DIR/$tfile $DIR/$tfile-2
294         rm -f $DIR/$tfile
295         fail $SINGLEMDS
296         $CHECKSTAT $DIR/$tfile &&
297                 error "$CHECKSTAT $DIR/$tfile attribute check should fail"
298         $CHECKSTAT $DIR/$tfile-2 ||
299                 error "$CHECKSTAT $DIR/$tfile-2 attribute check failed"
300         rm $DIR/$tfile-2
301         return 0
302 }
303 run_test 10 "create |X| rename unlink"
304
305 test_11() {
306         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
307         echo "old" > $DIR/$tfile
308         mv $DIR/$tfile $DIR/$tfile-2
309         replay_barrier $SINGLEMDS
310         echo "new" > $DIR/$tfile
311         grep new $DIR/$tfile
312         grep old $DIR/$tfile-2
313         fail $SINGLEMDS
314         grep new $DIR/$tfile || error "grep $DIR/$tfile failed"
315         grep old $DIR/$tfile-2 || error "grep $DIR/$tfile-2 failed"
316 }
317 run_test 11 "create open write rename |X| create-old-name read"
318
319 test_12() {
320         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
321         multiop_bg_pause $DIR/$tfile o_tSc ||
322                 error "multiop_bg_pause $DIR/$tfile failed"
323         pid=$!
324         rm -f $DIR/$tfile
325         replay_barrier $SINGLEMDS
326         kill -USR1 $pid || error "multiop $pid not running"
327         wait $pid || error "multiop $pid failed"
328
329         fail $SINGLEMDS
330         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
331         return 0
332 }
333 run_test 12 "open, unlink |X| close"
334
335 # 1777 - replay open after committed chmod that would make
336 #        a regular open a failure
337 test_13() {
338         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
339         multiop_bg_pause $DIR/$tfile O_wc ||
340                 error "multiop_bg_pause $DIR/$tfile failed"
341         pid=$!
342         chmod 0 $DIR/$tfile
343         $CHECKSTAT -p 0 $DIR/$tfile ||
344                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
345         replay_barrier $SINGLEMDS
346         fail $SINGLEMDS
347         kill -USR1 $pid || error "multiop $pid not running"
348         wait $pid || error "multiop $pid failed"
349
350         $CHECKSTAT -s 1 -p 0 $DIR/$tfile ||
351                 error "second $CHECKSTAT $DIR/$tfile attribute check failed"
352         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
353         return 0
354 }
355 run_test 13 "open chmod 0 |x| write close"
356
357 test_14() {
358         multiop_bg_pause $DIR/$tfile O_tSc ||
359                 error "multiop_bg_pause $DIR/$tfile failed"
360         pid=$!
361         rm -f $DIR/$tfile
362         replay_barrier $SINGLEMDS
363         kill -USR1 $pid || error "multiop $pid not running"
364         wait $pid || error "multiop $pid failed"
365
366         fail $SINGLEMDS
367         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
368         return 0
369 }
370 run_test 14 "open(O_CREAT), unlink |X| close"
371
372 test_15() {
373         multiop_bg_pause $DIR/$tfile O_tSc ||
374                 error "multiop_bg_pause $DIR/$tfile failed"
375         pid=$!
376         rm -f $DIR/$tfile
377         replay_barrier $SINGLEMDS
378         touch $DIR/$tfile-1 || error "touch $DIR/$tfile-1 failed"
379         kill -USR1 $pid || error "multiop $pid not running"
380         wait $pid || error "multiop $pid failed"
381
382         fail $SINGLEMDS
383         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
384         touch $DIR/$tfile-2 || error "touch $DIR/$tfile-2 failed"
385         return 0
386 }
387 run_test 15 "open(O_CREAT), unlink |X|  touch new, close"
388
389 test_16() {
390         replay_barrier $SINGLEMDS
391         mcreate $DIR/$tfile
392         munlink $DIR/$tfile
393         mcreate $DIR/$tfile-2
394         fail $SINGLEMDS
395         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
396         [ -e $DIR/$tfile-2 ] || error "file $DIR/$tfile-2 does not exist"
397         munlink $DIR/$tfile-2 || error "munlink $DIR/$tfile-2 failed"
398 }
399 run_test 16 "|X| open(O_CREAT), unlink, touch new,  unlink new"
400
401 test_17() {
402         replay_barrier $SINGLEMDS
403         multiop_bg_pause $DIR/$tfile O_c ||
404                 error "multiop_bg_pause $DIR/$tfile failed"
405         pid=$!
406         fail $SINGLEMDS
407         kill -USR1 $pid || error "multiop $pid not running"
408         wait $pid || error "multiop $pid failed"
409         $CHECKSTAT -t file $DIR/$tfile ||
410                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
411         rm $DIR/$tfile
412 }
413 run_test 17 "|X| open(O_CREAT), |replay| close"
414
415 test_18() {
416         replay_barrier $SINGLEMDS
417         multiop_bg_pause $DIR/$tfile O_tSc ||
418                 error "multiop_bg_pause $DIR/$tfile failed"
419         pid=$!
420         rm -f $DIR/$tfile
421         touch $DIR/$tfile-2 || error "touch $DIR/$tfile-2 failed"
422         echo "pid: $pid will close"
423         kill -USR1 $pid || error "multiop $pid not running"
424         wait $pid || error "multiop $pid failed"
425
426         fail $SINGLEMDS
427         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
428         [ -e $DIR/$tfile-2 ] || error "file $DIR/$tfile-2 does not exist"
429         # this touch frequently fails
430         touch $DIR/$tfile-3 || error "touch $DIR/$tfile-3 failed"
431         munlink $DIR/$tfile-2 || error "munlink $DIR/$tfile-2 failed"
432         munlink $DIR/$tfile-3 || error "munlink $DIR/$tfile-3 failed"
433         return 0
434 }
435 run_test 18 "open(O_CREAT), unlink, touch new, close, touch, unlink"
436
437 # bug 1855 (a simpler form of test_11 above)
438 test_19() {
439         replay_barrier $SINGLEMDS
440         mcreate $DIR/$tfile
441         echo "old" > $DIR/$tfile
442         mv $DIR/$tfile $DIR/$tfile-2
443         grep old $DIR/$tfile-2
444         fail $SINGLEMDS
445         grep old $DIR/$tfile-2 || error "grep $DIR/$tfile-2 failed"
446 }
447 run_test 19 "mcreate, open, write, rename "
448
449 test_20a() {    # was test_20
450         replay_barrier $SINGLEMDS
451         multiop_bg_pause $DIR/$tfile O_tSc ||
452                 error "multiop_bg_pause $DIR/$tfile failed"
453         pid=$!
454         rm -f $DIR/$tfile
455
456         fail $SINGLEMDS
457         kill -USR1 $pid || error "multiop $pid not running"
458         wait $pid || error "multiop $pid failed"
459         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
460         return 0
461 }
462 run_test 20a "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
463
464 test_20b() { # bug 10480
465         local wait_timeout=$((TIMEOUT * 4))
466         local extra=$(fs_log_size)
467         local n_attempts=1
468
469         sync_all_data
470         save_layout_restore_at_exit $MOUNT
471         $LFS setstripe -i 0 -c 1 $DIR
472
473         local beforeused=$(df -P $DIR | tail -1 | awk '{ print $3 }')
474
475         dd if=/dev/zero of=$DIR/$tfile bs=4k count=10000 &
476         while [ ! -e $DIR/$tfile ] ; do
477                 sleep 0.01                      # give dd a chance to start
478         done
479
480         $LFS getstripe $DIR/$tfile || error "$LFS getstripe $DIR/$tfile failed"
481         # make it an orphan
482         rm -f $DIR/$tfile || error "rm -f $DIR/$tfile failed"
483         mds_evict_client
484         client_up || client_up || true          # reconnect
485
486         do_facet $SINGLEMDS "lctl set_param -n osd*.*MDT*.force_sync=1"
487
488         fail $SINGLEMDS                         # start orphan recovery
489         wait_recovery_complete $SINGLEMDS || error "MDS recovery not done"
490         wait_delete_completed $wait_timeout || error "delete did not finish"
491         sync_all_data
492
493         while true; do
494                 local afterused=$(df -P $DIR | tail -1 | awk '{ print $3 }')
495                 log "before $beforeused, after $afterused"
496
497                 (( $beforeused + $extra >= $afterused )) && break
498                 n_attempts=$((n_attempts + 1))
499                 [ $n_attempts -gt 3 ] &&
500                         error "after $afterused > before $beforeused + $extra"
501
502                 wait_zfs_commit $SINGLEMDS 5
503                 sync_all_data
504         done
505 }
506
507 run_test 20b "write, unlink, eviction, replay (test mds_cleanup_orphans)"
508
509 test_20c() { # bug 10480
510         multiop_bg_pause $DIR/$tfile Ow_c ||
511                 error "multiop_bg_pause $DIR/$tfile failed"
512         pid=$!
513
514         ls -la $DIR/$tfile
515
516         mds_evict_client
517         client_up || client_up || true    # reconnect
518
519         kill -USR1 $pid || error "multiop $pid not running"
520         wait $pid || error "multiop $pid failed"
521         [ -s $DIR/$tfile ] || error "File was truncated"
522
523         return 0
524 }
525 run_test 20c "check that client eviction does not affect file content"
526
527 test_21() {
528         replay_barrier $SINGLEMDS
529         multiop_bg_pause $DIR/$tfile O_tSc ||
530                 error "multiop_bg_pause $DIR/$tfile failed"
531         pid=$!
532         rm -f $DIR/$tfile
533         touch $DIR/$tfile-1 || error "touch $DIR/$tfile-1 failed"
534
535         fail $SINGLEMDS
536         kill -USR1 $pid || error "multiop $pid not running"
537         wait $pid || error "multiop $pid failed"
538         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
539         touch $DIR/$tfile-2 || error "touch $DIR/$tfile-2 failed"
540         return 0
541 }
542 run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"
543
544 test_22() {
545         multiop_bg_pause $DIR/$tfile O_tSc ||
546                 error "multiop_bg_pause $DIR/$tfile failed"
547         pid=$!
548
549         replay_barrier $SINGLEMDS
550         rm -f $DIR/$tfile
551
552         fail $SINGLEMDS
553         kill -USR1 $pid || error "multiop $pid not running"
554         wait $pid || error "multiop $pid failed"
555         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
556         return 0
557 }
558 run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"
559
560 test_23() {
561         multiop_bg_pause $DIR/$tfile O_tSc ||
562                 error "multiop_bg_pause $DIR/$tfile failed"
563         pid=$!
564
565         replay_barrier $SINGLEMDS
566         rm -f $DIR/$tfile
567         touch $DIR/$tfile-1 || error "touch $DIR/$tfile-1 failed"
568
569         fail $SINGLEMDS
570         kill -USR1 $pid || error "multiop $pid not running"
571         wait $pid || error "multiop $pid failed"
572         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
573         touch $DIR/$tfile-2 || error "touch $DIR/$tfile-2 failed"
574         return 0
575 }
576 run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"
577
578 test_24() {
579         multiop_bg_pause $DIR/$tfile O_tSc ||
580                 error "multiop_bg_pause $DIR/$tfile failed"
581         pid=$!
582
583         replay_barrier $SINGLEMDS
584         fail $SINGLEMDS
585         rm -f $DIR/$tfile
586         kill -USR1 $pid || error "multiop $pid not running"
587         wait $pid || error "multiop $pid failed"
588         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
589         return 0
590 }
591 run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"
592
593 test_25() {
594         multiop_bg_pause $DIR/$tfile O_tSc ||
595                 error "multiop_bg_pause $DIR/$tfile failed"
596         pid=$!
597         rm -f $DIR/$tfile
598
599         replay_barrier $SINGLEMDS
600         fail $SINGLEMDS
601         kill -USR1 $pid || error "multiop $pid not running"
602         wait $pid || error "multiop $pid failed"
603         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
604         return 0
605 }
606 run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
607
608 test_26() {
609         replay_barrier $SINGLEMDS
610         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
611                 error "multiop_bg_pause $DIR/$tfile-1 failed"
612         pid1=$!
613         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
614                 error "multiop_bg_pause $DIR/$tfile-2 failed"
615         pid2=$!
616         rm -f $DIR/$tfile-1
617         rm -f $DIR/$tfile-2
618         kill -USR1 $pid2 || error "second multiop $pid2 not running"
619         wait $pid2 || error "second multiop $pid2 failed"
620
621         fail $SINGLEMDS
622         kill -USR1 $pid1 || error "multiop $pid1 not running"
623         wait $pid1 || error "multiop $pid1 failed"
624         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
625         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
626         return 0
627 }
628 run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"
629
630 test_27() {
631         replay_barrier $SINGLEMDS
632         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
633                 error "multiop_bg_pause $DIR/$tfile-1 failed"
634         pid1=$!
635         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
636                 error "multiop_bg_pause $DIR/$tfile-2 failed"
637         pid2=$!
638         rm -f $DIR/$tfile-1
639         rm -f $DIR/$tfile-2
640
641         fail $SINGLEMDS
642         kill -USR1 $pid1 || error "multiop $pid1 not running"
643         wait $pid1 || error "multiop $pid1 failed"
644         kill -USR1 $pid2 || error "second multiop $pid2 not running"
645         wait $pid2 || error "second multiop $pid2 failed"
646         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
647         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
648         return 0
649 }
650 run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"
651
652 test_28() {
653         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
654                 error "multiop_bg_pause $DIR/$tfile-1 failed"
655         pid1=$!
656         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
657                 error "multiop_bg_pause $DIR/$tfile-2 failed"
658         pid2=$!
659         replay_barrier $SINGLEMDS
660         rm -f $DIR/$tfile-1
661         rm -f $DIR/$tfile-2
662         kill -USR1 $pid2 || error "second multiop $pid2 not running"
663         wait $pid2 || error "second multiop $pid2 failed"
664
665         fail $SINGLEMDS
666         kill -USR1 $pid1 || error "multiop $pid1 not running"
667         wait $pid1 || error "multiop $pid1 failed"
668         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
669         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
670         return 0
671 }
672 run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"
673
674 test_29() {
675         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
676                 error "multiop_bg_pause $DIR/$tfile-1 failed"
677         pid1=$!
678         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
679                 error "multiop_bg_pause $DIR/$tfile-2 failed"
680         pid2=$!
681         replay_barrier $SINGLEMDS
682         rm -f $DIR/$tfile-1
683         rm -f $DIR/$tfile-2
684
685         fail $SINGLEMDS
686         kill -USR1 $pid1 || error "multiop $pid1 not running"
687         wait $pid1 || error "multiop $pid1 failed"
688         kill -USR1 $pid2 || error "second multiop $pid2 not running"
689         wait $pid2 || error "second multiop $pid2 failed"
690         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
691         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
692         return 0
693 }
694 run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"
695
696 test_30() {
697         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
698                 error "multiop_bg_pause $DIR/$tfile-1 failed"
699         pid1=$!
700         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
701                 error "multiop_bg_pause $DIR/$tfile-2 failed"
702         pid2=$!
703         rm -f $DIR/$tfile-1
704         rm -f $DIR/$tfile-2
705
706         replay_barrier $SINGLEMDS
707         fail $SINGLEMDS
708         kill -USR1 $pid1 || error "multiop $pid1 not running"
709         wait $pid1 || error "multiop $pid1 failed"
710         kill -USR1 $pid2 || error "second multiop $pid2 not running"
711         wait $pid2 || error "second multiop $pid2 failed"
712         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
713         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
714         return 0
715 }
716 run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"
717
718 test_31() {
719         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
720                 error "multiop_bg_pause $DIR/$tfile-1 failed"
721         pid1=$!
722         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
723                 error "multiop_bg_pause $DIR/$tfile-2 failed"
724         pid2=$!
725         rm -f $DIR/$tfile-1
726
727         replay_barrier $SINGLEMDS
728         rm -f $DIR/$tfile-2
729         fail $SINGLEMDS
730         kill -USR1 $pid1 || error "multiop $pid1 not running"
731         wait $pid1 || error "multiop $pid1 failed"
732         kill -USR1 $pid2 || error "second multiop $pid2 not running"
733         wait $pid2 || error "second multiop $pid2 failed"
734         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
735         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
736         return 0
737 }
738 run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"
739
740 # tests for bug 2104; completion without crashing is success.  The close is
741 # stale, but we always return 0 for close, so the app never sees it.
742 test_32() {
743         multiop_bg_pause $DIR/$tfile O_c ||
744                 error "multiop_bg_pause $DIR/$tfile failed"
745         pid1=$!
746         multiop_bg_pause $DIR/$tfile O_c ||
747                 error "second multiop_bg_pause $DIR/$tfile failed"
748         pid2=$!
749         mds_evict_client
750         client_up || client_up || error "client_up failed"
751         kill -USR1 $pid1 || error "multiop $pid1 not running"
752         kill -USR1 $pid2 || error "second multiop $pid2 not running"
753         wait $pid1 || error "multiop $pid1 failed"
754         wait $pid2 || error "second multiop $pid2 failed"
755         return 0
756 }
757 run_test 32 "close() notices client eviction; close() after client eviction"
758
759 test_33a() {
760         createmany -o $DIR/$tfile-%d 10 ||
761                 error "createmany create $DIR/$tfile failed"
762         replay_barrier_nosync $SINGLEMDS
763         fail_abort $SINGLEMDS
764         # recreate shouldn't fail
765         createmany -o $DIR/$tfile--%d 10 ||
766                 error "createmany recreate $DIR/$tfile failed"
767         rm $DIR/$tfile-* -f
768         return 0
769 }
770 run_test 33a "fid seq shouldn't be reused after abort recovery"
771
772 test_33b() {
773         #define OBD_FAIL_SEQ_ALLOC                          0x1311
774         do_facet $SINGLEMDS "lctl set_param fail_loc=0x1311"
775
776         createmany -o $DIR/$tfile-%d 10
777         replay_barrier_nosync $SINGLEMDS
778         fail_abort $SINGLEMDS
779         # recreate shouldn't fail
780         createmany -o $DIR/$tfile--%d 10 ||
781                 error "createmany recreate $DIR/$tfile failed"
782         rm $DIR/$tfile-* -f
783         return 0
784 }
785 run_test 33b "test fid seq allocation"
786
787 test_34() {
788         multiop_bg_pause $DIR/$tfile O_c ||
789                 error "multiop_bg_pause $DIR/$tfile failed"
790         pid=$!
791         rm -f $DIR/$tfile
792
793         replay_barrier $SINGLEMDS
794         fail_abort $SINGLEMDS
795         kill -USR1 $pid || error "multiop $pid not running"
796         wait $pid || error "multiop $pid failed"
797         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
798         sync
799         return 0
800 }
801 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
802
803 # bug 2278 - generate one orphan on OST, then destroy it during recovery from llog
804 test_35() {
805         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
806
807         #define OBD_FAIL_MDS_REINT_NET_REP       0x119
808         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
809         rm -f $DIR/$tfile &
810         sleep 1
811         sync
812         sleep 1
813         # give a chance to remove from MDS
814         fail_abort $SINGLEMDS
815         $CHECKSTAT -t file $DIR/$tfile &&
816                 error "$CHECKSTAT $DIR/$tfile attribute check should fail" ||
817                 true
818 }
819 run_test 35 "test recovery from llog for unlink op"
820
821 # b=2432 resent cancel after replay uses wrong cookie,
822 # so don't resend cancels
823 test_36() {
824         replay_barrier $SINGLEMDS
825         touch $DIR/$tfile
826         checkstat $DIR/$tfile
827         facet_failover $SINGLEMDS
828         cancel_lru_locks mdc
829         if $LCTL dk | grep "stale lock .*cookie"; then
830                 error "cancel after replay failed"
831         fi
832 }
833 run_test 36 "don't resend cancel"
834
835 # b=2368
836 # directory orphans can't be unlinked from PENDING directory
837 test_37() {
838         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $tdir failed"
839         rmdir $DIR/$tdir/$tfile 2>/dev/null
840         multiop_bg_pause $DIR/$tdir/$tfile dD_c ||
841                 error "multiop_bg_pause $tfile failed"
842         pid=$!
843         rmdir $DIR/$tdir/$tfile
844
845         replay_barrier $SINGLEMDS
846         # clear the dmesg buffer so we only see errors from this recovery
847         do_facet $SINGLEMDS dmesg -c >/dev/null
848         fail_abort $SINGLEMDS
849         kill -USR1 $pid || error "multiop $pid not running"
850         do_facet $SINGLEMDS dmesg | grep "error unlinking orphan" &&
851                 error "error unlinking files"
852         wait $pid || error "multiop $pid failed"
853         sync
854         return 0
855 }
856 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
857
858 test_38() {
859         createmany -o $DIR/$tfile-%d 800 ||
860                 error "createmany -o $DIR/$tfile failed"
861         unlinkmany $DIR/$tfile-%d 0 400 || error "unlinkmany $DIR/$tfile failed"
862         replay_barrier $SINGLEMDS
863         fail $SINGLEMDS
864         unlinkmany $DIR/$tfile-%d 400 400 ||
865                 error "unlinkmany $DIR/$tfile 400 failed"
866         sleep 2
867         $CHECKSTAT -t file $DIR/$tfile-* &&
868                 error "$CHECKSTAT $DIR/$tfile-* attribute check should fail" ||
869                 true
870 }
871 run_test 38 "test recovery from unlink llog (test llog_gen_rec) "
872
873 test_39() { # bug 4176
874         createmany -o $DIR/$tfile-%d 800 ||
875                 error "createmany -o $DIR/$tfile failed"
876         replay_barrier $SINGLEMDS
877         unlinkmany $DIR/$tfile-%d 0 400
878         fail $SINGLEMDS
879         unlinkmany $DIR/$tfile-%d 400 400 ||
880                 error "unlinkmany $DIR/$tfile 400 failed"
881         sleep 2
882         $CHECKSTAT -t file $DIR/$tfile-* &&
883                 error "$CHECKSTAT $DIR/$tfile-* attribute check should fail" ||
884                 true
885 }
886 run_test 39 "test recovery from unlink llog (test llog_gen_rec) "
887
888 count_ost_writes() {
889     lctl get_param -n osc.*.stats | awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
890 }
891
892 #b=2477,2532
893 test_40(){
894         # always need connection to MDS to verify layout during IO. LU-2628.
895         lctl get_param mdc.*.connect_flags | grep -q layout_lock &&
896                 skip "layout_lock needs MDS connection for IO" && return 0
897
898         $LCTL mark multiop $MOUNT/$tfile OS_c
899         multiop $MOUNT/$tfile OS_c  &
900         PID=$!
901         writeme -s $MOUNT/${tfile}-2 &
902         WRITE_PID=$!
903         sleep 1
904         facet_failover $SINGLEMDS
905         #define OBD_FAIL_MDS_CONNECT_NET         0x117
906         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000117"
907         kill -USR1 $PID
908         stat1=$(count_ost_writes)
909         sleep $TIMEOUT
910         stat2=$(count_ost_writes)
911         echo "$stat1, $stat2"
912         if [ $stat1 -lt $stat2 ]; then
913                 echo "writes continuing during recovery"
914                 RC=0
915         else
916                 echo "writes not continuing during recovery, bug 2477"
917                 RC=4
918         fi
919         echo "waiting for writeme $WRITE_PID"
920         kill $WRITE_PID
921         wait $WRITE_PID
922
923         echo "waiting for multiop $PID"
924         wait $PID || error "multiop $PID failed"
925         do_facet client munlink $MOUNT/$tfile  ||
926                 error "munlink $MOUNT/$tfile failed"
927         do_facet client munlink $MOUNT/${tfile}-2  ||
928                 error "munlink $MOUNT/$tfile-2 failed"
929         return $RC
930 }
931 run_test 40 "cause recovery in ptlrpc, ensure IO continues"
932
933 #b=2814
934 # make sure that a read to one osc doesn't try to double-unlock its page just
935 # because another osc is invalid.  trigger_group_io used to mistakenly return
936 # an error if any oscs were invalid even after having successfully put rpcs
937 # on valid oscs.  This was fatal if the caller was ll_readpage who unlocked
938 # the page, guarnateeing that the unlock from the RPC completion would
939 # assert on trying to unlock the unlocked page.
940 test_41() {
941         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs" && return
942
943         local f=$MOUNT/$tfile
944         # make sure the start of the file is ost1
945         $LFS setstripe -S $((128 * 1024)) -i 0 $f
946         do_facet client dd if=/dev/zero of=$f bs=4k count=1 ||
947                 error "dd on client failed"
948         cancel_lru_locks osc
949         # fail ost2 and read from ost1
950         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $ost2_svc)
951         local osc2dev=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
952                 grep $mdtosc | awk '{print $1}')
953         [ -z "$osc2dev" ] && echo "OST: $ost2_svc" &&
954                 lctl get_param -n devices &&
955                 error "OST 2 $osc2dev does not exist"
956         do_facet $SINGLEMDS $LCTL --device $osc2dev deactivate ||
957                 error "deactive device on $SINGLEMDS failed"
958         do_facet client dd if=$f of=/dev/null bs=4k count=1 ||
959                 error "second dd on client failed"
960         do_facet $SINGLEMDS $LCTL --device $osc2dev activate ||
961                 error "active device on $SINGLEMDS failed"
962         return 0
963 }
964 run_test 41 "read from a valid osc while other oscs are invalid"
965
966 # test MDS recovery after ost failure
967 test_42() {
968         blocks=$(df -P $MOUNT | tail -n 1 | awk '{ print $2 }')
969         createmany -o $DIR/$tfile-%d 800 ||
970                 error "createmany -o $DIR/$tfile failed"
971         replay_barrier ost1
972         unlinkmany $DIR/$tfile-%d 0 400
973         debugsave
974         lctl set_param debug=-1
975         facet_failover ost1
976
977         # osc is evicted, fs is smaller (but only with failout OSTs (bug 7287)
978         #blocks_after=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
979         #[ $blocks_after -lt $blocks ] || return 1
980         echo "wait for MDS to timeout and recover"
981         sleep $((TIMEOUT * 2))
982         debugrestore
983         unlinkmany $DIR/$tfile-%d 400 400 ||
984                 error "unlinkmany $DIR/$tfile 400 failed"
985         $CHECKSTAT -t file $DIR/$tfile-* &&
986                 error "$CHECKSTAT $DIR/$tfile-* attribute check should fail" ||
987                 true
988 }
989 run_test 42 "recovery after ost failure"
990
991 # timeout in MDS/OST recovery RPC will LBUG MDS
992 test_43() { # bug 2530
993         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
994
995         replay_barrier $SINGLEMDS
996
997         # OBD_FAIL_OST_CREATE_NET 0x204
998         do_facet ost1 "lctl set_param fail_loc=0x80000204"
999         fail $SINGLEMDS
1000         sleep 10
1001
1002         return 0
1003 }
1004 run_test 43 "mds osc import failure during recovery; don't LBUG"
1005
1006 test_44a() { # was test_44
1007         local at_max_saved=0
1008
1009         local mdcdev=$($LCTL dl |
1010                 awk "/${FSNAME}-MDT0000-mdc-/ {if (\$2 == \"UP\") {print \$1}}")
1011         [ "$mdcdev" ] || error "${FSNAME}-MDT0000-mdc- not UP"
1012         [ $(echo $mdcdev | wc -w) -eq 1 ] ||
1013                 { $LCTL dl; error "looking for mdcdev=$mdcdev"; }
1014
1015         # adaptive timeouts slow this way down
1016         if at_is_enabled; then
1017                 at_max_saved=$(at_max_get mds)
1018                 at_max_set 40 mds
1019         fi
1020
1021         for i in $(seq 1 10); do
1022                 echo "$i of 10 ($(date +%s))"
1023                 do_facet $SINGLEMDS \
1024                         "lctl get_param -n md[ts].*.mdt.timeouts | grep service"
1025                 #define OBD_FAIL_TGT_CONN_RACE     0x701
1026                 do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000701"
1027                 # lctl below may fail, it is valid case
1028                 $LCTL --device $mdcdev recover
1029                 $LFS df $MOUNT
1030         done
1031         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1032         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds
1033         return 0
1034 }
1035 run_test 44a "race in target handle connect"
1036
1037 test_44b() {
1038         local mdcdev=$($LCTL dl |
1039                 awk "/${FSNAME}-MDT0000-mdc-/ {if (\$2 == \"UP\") {print \$1}}")
1040         [ "$mdcdev" ] || error "${FSNAME}-MDT0000-mdc not up"
1041         [ $(echo $mdcdev | wc -w) -eq 1 ] ||
1042                 { echo mdcdev=$mdcdev; $LCTL dl;
1043                   error "more than one ${FSNAME}-MDT0000-mdc"; }
1044
1045         for i in $(seq 1 10); do
1046                 echo "$i of 10 ($(date +%s))"
1047                 do_facet $SINGLEMDS \
1048                         "lctl get_param -n md[ts].*.mdt.timeouts | grep service"
1049                 #define OBD_FAIL_TGT_DELAY_RECONNECT 0x704
1050                 do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000704"
1051                 # lctl below may fail, it is valid case
1052                 $LCTL --device $mdcdev recover
1053                 df $MOUNT
1054         done
1055         return 0
1056 }
1057 run_test 44b "race in target handle connect"
1058
1059 test_44c() {
1060         replay_barrier $SINGLEMDS
1061         createmany -m $DIR/$tfile-%d 100 || error "failed to create directories"
1062         #define OBD_FAIL_TGT_RCVG_FLAG 0x712
1063         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000712"
1064         fail_abort $SINGLEMDS
1065         unlinkmany $DIR/$tfile-%d 100 && error "unliked after fail abort"
1066         fail $SINGLEMDS
1067         unlinkmany $DIR/$tfile-%d 100 && error "unliked after fail"
1068         return 0
1069 }
1070 run_test 44c "race in target handle connect"
1071
1072 # Handle failed close
1073 test_45() {
1074         local mdcdev=$($LCTL get_param -n devices |
1075                 awk "/ ${FSNAME}-MDT0000-mdc-/ {print \$1}")
1076         [ "$mdcdev" ] || error "${FSNAME}-MDT0000-mdc not up"
1077         [ $(echo $mdcdev | wc -w) -eq 1 ] ||
1078                 { echo mdcdev=$mdcdev; $LCTL dl;
1079                   error "more than one ${FSNAME}-MDT0000-mdc"; }
1080
1081         $LCTL --device $mdcdev recover ||
1082                 error "$LCTL --device $mdcdev recover failed"
1083
1084         multiop_bg_pause $DIR/$tfile O_c ||
1085                 error "multiop_bg_pause $DIR/$tfile failed"
1086         pid=$!
1087
1088         # This will cause the CLOSE to fail before even
1089         # allocating a reply buffer
1090         $LCTL --device $mdcdev deactivate ||
1091                 error "$LCTL --device $mdcdev deactivate failed"
1092
1093         # try the close
1094         kill -USR1 $pid || error "multiop $pid not running"
1095         wait $pid || error "multiop $pid failed"
1096
1097         $LCTL --device $mdcdev activate ||
1098                 error "$LCTL --device $mdcdev activate failed"
1099         sleep 1
1100
1101         $CHECKSTAT -t file $DIR/$tfile ||
1102                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
1103         return 0
1104 }
1105 run_test 45 "Handle failed close"
1106
1107 test_46() {
1108         drop_reply "touch $DIR/$tfile"
1109         fail $SINGLEMDS
1110         # ironically, the previous test, 45, will cause a real forced close,
1111         # so just look for one for this test
1112         local FID=$($LFS path2fid $tfile)
1113         $LCTL dk | grep -i "force closing file handle $FID" &&
1114                 error "found force closing in dmesg"
1115         return 0
1116 }
1117 run_test 46 "Don't leak file handle after open resend (3325)"
1118
1119 test_47() { # bug 2824
1120         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1121
1122         # create some files to make sure precreate has been done on all
1123         # OSTs. (just in case this test is run independently)
1124         createmany -o $DIR/$tfile 20  ||
1125                 error "createmany create $DIR/$tfile failed"
1126
1127         # OBD_FAIL_OST_CREATE_NET 0x204
1128         fail ost1
1129         do_facet ost1 "lctl set_param fail_loc=0x80000204"
1130         client_up || error "client_up failed"
1131
1132         # let the MDS discover the OST failure, attempt to recover, fail
1133         # and recover again.
1134         sleep $((3 * TIMEOUT))
1135
1136         # Without 2824, this createmany would hang
1137         createmany -o $DIR/$tfile 20 ||
1138                 error "createmany recraete $DIR/$tfile failed"
1139         unlinkmany $DIR/$tfile 20 || error "unlinkmany $DIR/$tfile failed"
1140
1141         return 0
1142 }
1143 run_test 47 "MDS->OSC failure during precreate cleanup (2824)"
1144
1145 test_48() {
1146         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1147         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1148
1149         replay_barrier $SINGLEMDS
1150         createmany -o $DIR/$tfile 20  ||
1151                 error "createmany -o $DIR/$tfile failed"
1152         # OBD_FAIL_OST_EROFS 0x216
1153         facet_failover $SINGLEMDS
1154         do_facet ost1 "lctl set_param fail_loc=0x80000216"
1155         client_up || error "client_up failed"
1156
1157         # let the MDS discover the OST failure, attempt to recover, fail
1158         # and recover again.
1159         sleep $((3 * TIMEOUT))
1160
1161         createmany -o $DIR/$tfile 20 20 ||
1162                 error "createmany recraete $DIR/$tfile failed"
1163         unlinkmany $DIR/$tfile 40 || error "unlinkmany $DIR/$tfile failed"
1164         return 0
1165 }
1166 run_test 48 "MDS->OSC failure during precreate cleanup (2824)"
1167
1168 test_50() {
1169         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $ost1_svc)
1170         local oscdev=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
1171                 grep $mdtosc | awk '{print $1}')
1172         [ "$oscdev" ] || error "could not find OSC device on MDS"
1173         do_facet $SINGLEMDS $LCTL --device $oscdev recover ||
1174                 error "OSC device $oscdev recovery failed"
1175         do_facet $SINGLEMDS $LCTL --device $oscdev recover ||
1176                 error "second OSC device $oscdev recovery failed"
1177         # give the mds_lov_sync threads a chance to run
1178         sleep 5
1179 }
1180 run_test 50 "Double OSC recovery, don't LASSERT (3812)"
1181
1182 # b3764 timed out lock replay
1183 test_52() {
1184         [ "$MDS1_VERSION" -lt $(version_code 2.6.90) ] &&
1185                 skip "MDS prior to 2.6.90 handle LDLM_REPLY_NET incorrectly"
1186
1187         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
1188         cancel_lru_locks mdc
1189
1190         multiop_bg_pause $DIR/$tfile s_s || error "multiop $DIR/$tfile failed"
1191         mpid=$!
1192
1193         #define OBD_FAIL_MDS_LDLM_REPLY_NET     0x157
1194         lctl set_param -n ldlm.cancel_unused_locks_before_replay "0"
1195         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000157"
1196
1197         fail $SINGLEMDS || error "fail $SINGLEMDS failed"
1198         kill -USR1 $mpid
1199         wait $mpid || error "multiop_bg_pause pid failed"
1200
1201         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1202         lctl set_param fail_loc=0x0
1203         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
1204         rm -f $DIR/$tfile
1205 }
1206 run_test 52 "time out lock replay (3764)"
1207
1208 # bug 3462 - simultaneous MDC requests
1209 test_53a() {
1210         [[ $(lctl get_param mdc.*.import |
1211              grep "connect_flags:.*multi_mod_rpc") ]] ||
1212                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
1213
1214         cancel_lru_locks mdc    # cleanup locks from former test cases
1215         mkdir_on_mdt0 $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1216         mkdir_on_mdt0 $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1217         multiop $DIR/${tdir}-1/f O_c &
1218         close_pid=$!
1219         # give multiop a change to open
1220         sleep 1
1221
1222         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1223         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1224         kill -USR1 $close_pid
1225         cancel_lru_locks mdc    # force the close
1226         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1227
1228         mcreate $DIR/${tdir}-2/f || error "mcreate $DIR/${tdir}-2/f failed"
1229
1230         # close should still be here
1231         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1232
1233         replay_barrier_nodf $SINGLEMDS
1234         fail $SINGLEMDS
1235         wait $close_pid || error "close_pid $close_pid failed"
1236
1237         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1238                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1239         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1240                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1241         rm -rf $DIR/${tdir}-*
1242 }
1243 run_test 53a "|X| close request while two MDC requests in flight"
1244
1245 test_53b() {
1246         cancel_lru_locks mdc    # cleanup locks from former test cases
1247
1248         mkdir_on_mdt0 $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1249         mkdir_on_mdt0 $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1250         multiop_bg_pause $DIR/${tdir}-1/f O_c ||
1251                 error "multiop_bg_pause $DIR/${tdir}-1/f failed"
1252         close_pid=$!
1253
1254         #define OBD_FAIL_MDS_REINT_NET 0x107
1255         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1256         mcreate $DIR/${tdir}-2/f &
1257         open_pid=$!
1258         sleep 1
1259
1260         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1261         kill -USR1 $close_pid
1262         cancel_lru_locks mdc    # force the close
1263         wait $close_pid || error "close_pid $close_pid failed"
1264         # open should still be here
1265         [ -d /proc/$open_pid ] || error "open_pid doesn't exist"
1266
1267         replay_barrier_nodf $SINGLEMDS
1268         fail $SINGLEMDS
1269         wait $open_pid || error "open_pid failed"
1270
1271         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1272                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1273         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1274                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1275         rm -rf $DIR/${tdir}-*
1276 }
1277 run_test 53b "|X| open request while two MDC requests in flight"
1278
1279 test_53c() {
1280         cancel_lru_locks mdc    # cleanup locks from former test cases
1281
1282         mkdir_on_mdt0 $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1283         mkdir_on_mdt0 $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1284         multiop $DIR/${tdir}-1/f O_c &
1285         close_pid=$!
1286
1287         #define OBD_FAIL_MDS_REINT_NET 0x107
1288         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1289         mcreate $DIR/${tdir}-2/f &
1290         open_pid=$!
1291         sleep 1
1292
1293         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1294         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1295         kill -USR1 $close_pid
1296         cancel_lru_locks mdc    # force the close
1297
1298         #bz20647: make sure all pids exist before failover
1299         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1300         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1301         replay_barrier_nodf $SINGLEMDS
1302         fail_nodf $SINGLEMDS
1303         wait $open_pid || error "open_pid failed"
1304         sleep 2
1305         # close should be gone
1306         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1307         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1308
1309         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1310                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1311         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1312                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1313         rm -rf $DIR/${tdir}-*
1314 }
1315 run_test 53c "|X| open request and close request while two MDC requests in flight"
1316
1317 test_53d() {
1318         [[ $(lctl get_param mdc.*.import |
1319              grep "connect_flags:.*multi_mod_rpc") ]] ||
1320                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
1321
1322         cancel_lru_locks mdc    # cleanup locks from former test cases
1323
1324         mkdir_on_mdt0 $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1325         mkdir_on_mdt0 $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1326         multiop $DIR/${tdir}-1/f O_c &
1327         close_pid=$!
1328         # give multiop a chance to open
1329         sleep 1
1330
1331         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1332         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1333         kill -USR1 $close_pid
1334         cancel_lru_locks mdc    # force the close
1335         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1336         mcreate $DIR/${tdir}-2/f || error "mcreate $DIR/${tdir}-2/f failed"
1337
1338         # close should still be here
1339         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1340         fail $SINGLEMDS
1341         wait $close_pid || error "close_pid failed"
1342
1343         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1344                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1345         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1346                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1347         rm -rf $DIR/${tdir}-*
1348 }
1349 run_test 53d "close reply while two MDC requests in flight"
1350
1351 test_53e() {
1352         cancel_lru_locks mdc    # cleanup locks from former test cases
1353
1354         mkdir_on_mdt0 $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1355         mkdir_on_mdt0 $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1356         multiop $DIR/${tdir}-1/f O_c &
1357         close_pid=$!
1358
1359         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1360         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1361         mcreate $DIR/${tdir}-2/f &
1362         open_pid=$!
1363         sleep 1
1364
1365         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1366         kill -USR1 $close_pid
1367         cancel_lru_locks mdc    # force the close
1368         wait $close_pid || error "close_pid failed"
1369         # open should still be here
1370         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1371
1372         replay_barrier_nodf $SINGLEMDS
1373         fail $SINGLEMDS
1374         wait $open_pid || error "open_pid failed"
1375
1376         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1377                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1378         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1379                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1380         rm -rf $DIR/${tdir}-*
1381 }
1382 run_test 53e "|X| open reply while two MDC requests in flight"
1383
1384 test_53f() {
1385         cancel_lru_locks mdc    # cleanup locks from former test cases
1386
1387         mkdir_on_mdt0 $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1388         mkdir_on_mdt0 $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1389         multiop $DIR/${tdir}-1/f O_c &
1390         close_pid=$!
1391
1392         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1393         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1394         mcreate $DIR/${tdir}-2/f &
1395         open_pid=$!
1396         sleep 1
1397
1398         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1399         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1400         kill -USR1 $close_pid
1401         cancel_lru_locks mdc    # force the close
1402
1403         #bz20647: make sure all pids are exists before failover
1404         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1405         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1406         replay_barrier_nodf $SINGLEMDS
1407         fail_nodf $SINGLEMDS
1408         wait $open_pid || error "open_pid failed"
1409         sleep 2
1410         # close should be gone
1411         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1412         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1413
1414         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1415                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1416         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1417                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1418         rm -rf $DIR/${tdir}-*
1419 }
1420 run_test 53f "|X| open reply and close reply while two MDC requests in flight"
1421
1422 test_53g() {
1423         cancel_lru_locks mdc    # cleanup locks from former test cases
1424
1425         mkdir_on_mdt0 $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1426         mkdir_on_mdt0 $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1427         multiop $DIR/${tdir}-1/f O_c &
1428         close_pid=$!
1429
1430         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1431         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1432         mcreate $DIR/${tdir}-2/f &
1433         open_pid=$!
1434         sleep 1
1435
1436         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1437         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1438         kill -USR1 $close_pid
1439         cancel_lru_locks mdc    # force the close
1440         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1441
1442         #bz20647: make sure all pids are exists before failover
1443         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1444         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1445         replay_barrier_nodf $SINGLEMDS
1446         fail_nodf $SINGLEMDS
1447         wait $open_pid || error "open_pid failed"
1448         sleep 2
1449         # close should be gone
1450         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1451
1452         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1453                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1454         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1455                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1456         rm -rf $DIR/${tdir}-*
1457 }
1458 run_test 53g "|X| drop open reply and close request while close and open are both in flight"
1459
1460 test_53h() {
1461         cancel_lru_locks mdc    # cleanup locks from former test cases
1462
1463         mkdir_on_mdt0 $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1464         mkdir_on_mdt0 $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1465         multiop $DIR/${tdir}-1/f O_c &
1466         close_pid=$!
1467
1468         #define OBD_FAIL_MDS_REINT_NET 0x107
1469         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1470         mcreate $DIR/${tdir}-2/f &
1471         open_pid=$!
1472         sleep 1
1473
1474         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1475         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1476         kill -USR1 $close_pid
1477         cancel_lru_locks mdc    # force the close
1478         sleep 1
1479
1480         #bz20647: make sure all pids are exists before failover
1481         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1482         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1483         replay_barrier_nodf $SINGLEMDS
1484         fail_nodf $SINGLEMDS
1485         wait $open_pid || error "open_pid failed"
1486         sleep 2
1487         # close should be gone
1488         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1489         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1490
1491         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1492                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1493         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1494                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1495         rm -rf $DIR/${tdir}-*
1496 }
1497 run_test 53h "open request and close reply while two MDC requests in flight"
1498
1499 #b3761 ASSERTION(hash != 0) failed
1500 test_55() {
1501 # OBD_FAIL_MDS_OPEN_CREATE | OBD_FAIL_ONCE
1502     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012b"
1503     touch $DIR/$tfile &
1504     # give touch a chance to run
1505     sleep 5
1506     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1507     rm $DIR/$tfile
1508     return 0
1509 }
1510 run_test 55 "let MDS_CHECK_RESENT return the original return code instead of 0"
1511
1512 #b3440 ASSERTION(rec->ur_fid2->id) failed
1513 test_56() {
1514     ln -s foo $DIR/$tfile
1515     replay_barrier $SINGLEMDS
1516     #drop_reply "cat $DIR/$tfile"
1517     fail $SINGLEMDS
1518     sleep 10
1519 }
1520 run_test 56 "don't replay a symlink open request (3440)"
1521
1522 #recovery one mds-ost setattr from llog
1523 test_57() {
1524         #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1525         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1526         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
1527         replay_barrier $SINGLEMDS
1528         fail $SINGLEMDS
1529         wait_recovery_complete $SINGLEMDS || error "MDS recovery is not done"
1530         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
1531         $CHECKSTAT -t file $DIR/$tfile ||
1532                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
1533         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1534         rm $DIR/$tfile
1535 }
1536 run_test 57 "test recovery from llog for setattr op"
1537
1538 cleanup_58() {
1539         zconf_umount $(hostname) $MOUNT2
1540         trap - EXIT
1541 }
1542
1543 #recovery many mds-ost setattr from llog
1544 test_58a() {
1545         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1546         #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1547         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1548         createmany -o $DIR/$tdir/$tfile-%d 2500
1549         replay_barrier $SINGLEMDS
1550         fail $SINGLEMDS
1551         sleep 2
1552         $CHECKSTAT -t file $DIR/$tdir/$tfile-* >/dev/null ||
1553                 error "$CHECKSTAT $DIR/$tfile-* attribute check failed"
1554         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1555         unlinkmany $DIR/$tdir/$tfile-%d 2500 ||
1556                 error "unlinkmany $DIR/$tfile failed"
1557         rmdir $DIR/$tdir
1558 }
1559 run_test 58a "test recovery from llog for setattr op (test llog_gen_rec)"
1560
1561 test_58b() {
1562         local orig
1563         local new
1564
1565         trap cleanup_58 EXIT
1566
1567         large_xattr_enabled &&
1568                 orig="$(generate_string $(max_xattr_size))" || orig="bar"
1569         # Original extended attribute can be long. Print a small version of
1570         # attribute if an error occurs
1571         local sm_msg=$(printf "%.9s" $orig)
1572
1573         mount_client $MOUNT2 || error "mount_client on $MOUNT2 failed"
1574         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1575         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
1576         replay_barrier $SINGLEMDS
1577         setfattr -n trusted.foo -v $orig $DIR/$tdir/$tfile
1578         fail $SINGLEMDS
1579         new=$(get_xattr_value trusted.foo $MOUNT2/$tdir/$tfile)
1580         [[ "$new" = "$orig" ]] ||
1581                 error "xattr set ($sm_msg...) differs from xattr get ($new)"
1582         rm -f $DIR/$tdir/$tfile
1583         rmdir $DIR/$tdir
1584         cleanup_58
1585         wait_clients_import_state ${CLIENTS:-$HOSTNAME} "mgs" FULL
1586 }
1587 run_test 58b "test replay of setxattr op"
1588
1589 test_58c() { # bug 16570
1590         local orig
1591         local orig1
1592         local new
1593
1594         trap cleanup_58 EXIT
1595
1596         if large_xattr_enabled; then
1597                 local xattr_size=$(max_xattr_size)
1598                 orig="$(generate_string $((xattr_size / 2)))"
1599                 orig1="$(generate_string $xattr_size)"
1600         else
1601                 orig="bar"
1602                 orig1="bar1"
1603         fi
1604
1605         # PING_INTERVAL max(obd_timeout / 4, 1U)
1606         sleep $((TIMEOUT / 4))
1607
1608         # Original extended attribute can be long. Print a small version of
1609         # attribute if an error occurs
1610         local sm_msg=$(printf "%.9s" $orig)
1611         local sm_msg1=$(printf "%.9s" $orig1)
1612
1613         mount_client $MOUNT2 || error "mount_client on $MOUNT2 failed"
1614         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1615         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
1616         drop_request "setfattr -n trusted.foo -v $orig $DIR/$tdir/$tfile" ||
1617                 error "drop_request for setfattr failed"
1618         new=$(get_xattr_value trusted.foo $MOUNT2/$tdir/$tfile)
1619         [[ "$new" = "$orig" ]] ||
1620                 error "xattr set ($sm_msg...) differs from xattr get ($new)"
1621         drop_reint_reply "setfattr -n trusted.foo1 \
1622                           -v $orig1 $DIR/$tdir/$tfile" ||
1623                 error "drop_reint_reply for setfattr failed"
1624         new=$(get_xattr_value trusted.foo1 $MOUNT2/$tdir/$tfile)
1625         [[ "$new" = "$orig1" ]] ||
1626                 error "second xattr set ($sm_msg1...) differs xattr get ($new)"
1627         rm -f $DIR/$tdir/$tfile
1628         rmdir $DIR/$tdir
1629         cleanup_58
1630 }
1631 run_test 58c "resend/reconstruct setxattr op"
1632
1633 # log_commit_thread vs filter_destroy race used to lead to import use after free
1634 # bug 11658
1635 test_59() {
1636         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1637
1638         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1639         createmany -o $DIR/$tdir/$tfile-%d 200 ||
1640                 error "createmany create files failed"
1641         sync
1642         unlinkmany $DIR/$tdir/$tfile-%d 200 ||
1643                 error "unlinkmany $DIR/$tdir/$tfile failed"
1644         #define OBD_FAIL_PTLRPC_DELAY_RECOV       0x507
1645         do_facet ost1 "lctl set_param fail_loc=0x507"
1646         fail ost1
1647         fail $SINGLEMDS
1648         do_facet ost1 "lctl set_param fail_loc=0x0"
1649         sleep 20
1650         rmdir $DIR/$tdir
1651 }
1652 run_test 59 "test log_commit_thread vs filter_destroy race"
1653
1654 # race between add unlink llog vs cat log init in post_recovery (only for b1_6)
1655 # bug 12086: should no oops and No ctxt error for this test
1656 test_60() {
1657         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1658         createmany -o $DIR/$tdir/$tfile-%d 200 ||
1659                 error "createmany create files failed"
1660         replay_barrier $SINGLEMDS
1661         unlinkmany $DIR/$tdir/$tfile-%d 0 100
1662         fail $SINGLEMDS
1663         unlinkmany $DIR/$tdir/$tfile-%d 100 100
1664         local no_ctxt=$(dmesg | grep "No ctxt")
1665         [ -z "$no_ctxt" ] || error "ctxt is not initialized in recovery"
1666 }
1667 run_test 60 "test llog post recovery init vs llog unlink"
1668
1669 #test race  llog recovery thread vs llog cleanup
1670 test_61a() {    # was test_61
1671         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1672
1673         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1674         createmany -o $DIR/$tdir/$tfile-%d 800 ||
1675                 error "createmany create files failed"
1676         replay_barrier ost1
1677         unlinkmany $DIR/$tdir/$tfile-%d 800
1678         #   OBD_FAIL_OST_LLOG_RECOVERY_TIMEOUT 0x221
1679         set_nodes_failloc "$(osts_nodes)" 0x80000221
1680         facet_failover ost1
1681         sleep 10
1682         fail ost1
1683         sleep 30
1684         set_nodes_failloc "$(osts_nodes)" 0x0
1685
1686         $CHECKSTAT -t file $DIR/$tdir/$tfile-* &&
1687                 error "$CHECKSTAT $DIR/$tdir/$tfile attribute check should fail"
1688         rmdir $DIR/$tdir
1689 }
1690 run_test 61a "test race llog recovery vs llog cleanup"
1691
1692 #test race  mds llog sync vs llog cleanup
1693 test_61b() {
1694         #   OBD_FAIL_MDS_LLOG_SYNC_TIMEOUT 0x13a
1695         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013a"
1696         facet_failover $SINGLEMDS
1697         sleep 10
1698         fail $SINGLEMDS
1699         do_facet client dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 ||
1700                 error "dd failed"
1701 }
1702 run_test 61b "test race mds llog sync vs llog cleanup"
1703
1704 #test race  cancel cookie cb vs llog cleanup
1705 test_61c() {
1706         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1707
1708         #   OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT 0x222
1709         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
1710         set_nodes_failloc "$(osts_nodes)" 0x80000222
1711         rm $DIR/$tfile
1712         sleep 10
1713         fail ost1
1714         set_nodes_failloc "$(osts_nodes)" 0x0
1715 }
1716 run_test 61c "test race mds llog sync vs llog cleanup"
1717
1718 test_61d() { # bug 16002 # bug 17466 # bug 22137
1719 #   OBD_FAIL_OBD_LLOG_SETUP        0x605
1720     stop mgs
1721     do_facet mgs "lctl set_param fail_loc=0x80000605"
1722     start mgs $(mgsdevname) $MGS_MOUNT_OPTS &&
1723         error "mgs start should have failed"
1724     do_facet mgs "lctl set_param fail_loc=0"
1725     start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "cannot restart mgs"
1726 }
1727 run_test 61d "error in llog_setup should cleanup the llog context correctly"
1728
1729 test_62() { # Bug 15756 - don't mis-drop resent replay
1730         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1731         replay_barrier $SINGLEMDS
1732         createmany -o $DIR/$tdir/$tfile- 25 ||
1733                 error "createmany create files failed"
1734         #define OBD_FAIL_TGT_REPLAY_DROP         0x707
1735         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000707"
1736         fail $SINGLEMDS
1737         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1738         unlinkmany $DIR/$tdir/$tfile- 25 ||
1739                 error "unlinkmany $DIR/$tdir/$tfile failed"
1740         return 0
1741 }
1742 run_test 62 "don't mis-drop resent replay"
1743
1744 #Adaptive Timeouts (bug 3055)
1745 AT_MAX_SET=0
1746
1747 at_cleanup () {
1748     local var
1749     local facet
1750     local at_new
1751
1752     echo "Cleaning up AT ..."
1753     if [ -n "$ATOLDBASE" ]; then
1754         local at_history=$($LCTL get_param -n at_history)
1755         do_facet $SINGLEMDS "lctl set_param at_history=$at_history" || true
1756         do_facet ost1 "lctl set_param at_history=$at_history" || true
1757     fi
1758
1759         if [ $AT_MAX_SET -ne 0 ]; then
1760                 for facet in mds client ost; do
1761                         var=AT_MAX_SAVE_${facet}
1762                         echo restore AT on $facet to saved value ${!var}
1763                         at_max_set ${!var} $facet
1764                         at_new=$(at_max_get $facet)
1765                         echo Restored AT value on $facet $at_new
1766                         [ $at_new -eq ${!var} ] ||
1767                         error "AT value not restored SAVED ${!var} NEW $at_new"
1768                 done
1769         fi
1770 }
1771
1772 at_start()
1773 {
1774     local at_max_new=600
1775
1776     # Save at_max original values
1777     local facet
1778     if [ $AT_MAX_SET -eq 0 ]; then
1779         # Suppose that all osts have the same at_max
1780         for facet in mds client ost; do
1781             eval AT_MAX_SAVE_${facet}=$(at_max_get $facet)
1782         done
1783     fi
1784     local at_max
1785     for facet in mds client ost; do
1786         at_max=$(at_max_get $facet)
1787         if [ $at_max -ne $at_max_new ]; then
1788             echo "AT value on $facet is $at_max, set it by force temporarily to $at_max_new"
1789             at_max_set $at_max_new $facet
1790             AT_MAX_SET=1
1791         fi
1792     done
1793
1794     if [ -z "$ATOLDBASE" ]; then
1795         ATOLDBASE=$(do_facet $SINGLEMDS "lctl get_param -n at_history")
1796         # speed up the timebase so we can check decreasing AT
1797         do_facet $SINGLEMDS "lctl set_param at_history=8" || true
1798         do_facet ost1 "lctl set_param at_history=8" || true
1799
1800         # sleep for a while to cool down, should be > 8s and also allow
1801         # at least one ping to be sent. simply use TIMEOUT to be safe.
1802         sleep $TIMEOUT
1803     fi
1804 }
1805
1806 test_65a() #bug 3055
1807 {
1808     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1809
1810     at_start || return 0
1811     $LCTL dk > /dev/null
1812     debugsave
1813     $LCTL set_param debug="other"
1814     # Slow down a request to the current service time, this is critical
1815     # because previous tests may have caused this value to increase.
1816     REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
1817                awk '/portal 12/ {print $5}'`
1818     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1819
1820     do_facet $SINGLEMDS lctl set_param fail_val=$((${REQ_DELAY} * 1000))
1821 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1822     do_facet $SINGLEMDS $LCTL set_param fail_loc=0x8000050a
1823     createmany -o $DIR/$tfile 10 > /dev/null
1824     unlinkmany $DIR/$tfile 10 > /dev/null
1825     # check for log message
1826     $LCTL dk | grep -i "Early reply #" || error "No early reply"
1827     debugrestore
1828     # client should show REQ_DELAY estimates
1829     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1830     sleep 9
1831     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1832 }
1833 run_test 65a "AT: verify early replies"
1834
1835 test_65b() #bug 3055
1836 {
1837         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1838
1839         at_start || return 0
1840         # turn on D_ADAPTTO
1841         debugsave
1842         $LCTL set_param debug="other trace"
1843         $LCTL dk > /dev/null
1844         # Slow down a request to the current service time, this is critical
1845         # because previous tests may have caused this value to increase.
1846         $LFS setstripe --stripe-index=0 --stripe-count=1 $DIR/$tfile ||
1847                 error "$LFS setstripe failed for $DIR/$tfile"
1848
1849         multiop $DIR/$tfile Ow1yc
1850         REQ_DELAY=`lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts |
1851                    awk '/portal 6/ {print $5}'`
1852         REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1853
1854         do_facet ost1 lctl set_param fail_val=${REQ_DELAY}
1855         #define OBD_FAIL_OST_BRW_PAUSE_PACK      0x224
1856         do_facet ost1 $LCTL set_param fail_loc=0x224
1857
1858         rm -f $DIR/$tfile
1859         $LFS setstripe --stripe-index=0 --stripe-count=1 $DIR/$tfile ||
1860                 error "$LFS setstripe failed"
1861         # force some real bulk transfer
1862         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
1863
1864         do_facet ost1 $LCTL set_param fail_loc=0
1865         # check for log message
1866         $LCTL dk | grep -i "Early reply #" || error "No early reply"
1867         debugrestore
1868         # client should show REQ_DELAY estimates
1869         lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts | grep portal
1870 }
1871 run_test 65b "AT: verify early replies on packed reply / bulk"
1872
1873 test_66a() #bug 3055
1874 {
1875     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1876
1877     at_start || return 0
1878     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1879     # adjust 5s at a time so no early reply is sent (within deadline)
1880     do_facet $SINGLEMDS "$LCTL set_param fail_val=5000"
1881 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1882     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x8000050a"
1883     createmany -o $DIR/$tfile 20 > /dev/null
1884     unlinkmany $DIR/$tfile 20 > /dev/null
1885     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1886     do_facet $SINGLEMDS "$LCTL set_param fail_val=10000"
1887     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x8000050a"
1888     createmany -o $DIR/$tfile 20 > /dev/null
1889     unlinkmany $DIR/$tfile 20 > /dev/null
1890     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1891     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0"
1892     sleep 9
1893     createmany -o $DIR/$tfile 20 > /dev/null
1894     unlinkmany $DIR/$tfile 20 > /dev/null
1895     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1896     CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $5}')
1897     WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $7}')
1898     echo "Current MDT timeout $CUR, worst $WORST"
1899     [ $CUR -lt $WORST ] || error "Current $CUR should be less than worst $WORST"
1900 }
1901 run_test 66a "AT: verify MDT service time adjusts with no early replies"
1902
1903 test_66b() #bug 3055
1904 {
1905         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1906
1907         at_start || return 0
1908         ORIG=$(lctl get_param -n mdc.${FSNAME}-MDT0000*.timeouts |
1909                 awk '/network/ {print $4}')
1910         $LCTL set_param fail_val=$(($ORIG + 5))
1911         #define OBD_FAIL_PTLRPC_PAUSE_REP      0x50c
1912         $LCTL set_param fail_loc=0x50c
1913         touch $DIR/$tfile > /dev/null 2>&1
1914         $LCTL set_param fail_loc=0
1915         CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000*.timeouts |
1916                 awk '/network/ {print $4}')
1917         WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000*.timeouts |
1918                 awk '/network/ {print $6}')
1919         echo "network timeout orig $ORIG, cur $CUR, worst $WORST"
1920         [ $WORST -gt $ORIG ] ||
1921                 error "Worst $WORST should be worse than orig $ORIG"
1922 }
1923 run_test 66b "AT: verify net latency adjusts"
1924
1925 test_67a() #bug 3055
1926 {
1927     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1928
1929     at_start || return 0
1930     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1931     # sleeping threads may drive values above this
1932     do_facet ost1 "$LCTL set_param fail_val=400"
1933 #define OBD_FAIL_PTLRPC_PAUSE_REQ    0x50a
1934     do_facet ost1 "$LCTL set_param fail_loc=0x50a"
1935     createmany -o $DIR/$tfile 20 > /dev/null
1936     unlinkmany $DIR/$tfile 20 > /dev/null
1937     do_facet ost1 "$LCTL set_param fail_loc=0"
1938     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1939     ATTEMPTS=$(($CONN2 - $CONN1))
1940     echo "$ATTEMPTS osc reconnect attempts on gradual slow"
1941         [ $ATTEMPTS -gt 0 ] &&
1942                 error_ignore bz13721 "AT should have prevented reconnect"
1943         return 0
1944 }
1945 run_test 67a "AT: verify slow request processing doesn't induce reconnects"
1946
1947 test_67b() #bug 3055
1948 {
1949     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1950
1951     at_start || return 0
1952     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1953
1954         # exhaust precreations on ost1
1955         local OST=$(ostname_from_index 0)
1956         local mdtosc=$(get_mdtosc_proc_path mds $OST)
1957         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1958                         osp.$mdtosc.prealloc_last_id)
1959         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1960                         osp.$mdtosc.prealloc_next_id)
1961
1962         mkdir -p $DIR/$tdir/${OST} || error "mkdir $DIR/$tdir/${OST} failed"
1963         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${OST} ||
1964                 error "$LFS setstripe failed"
1965         echo "Creating to objid $last_id on ost $OST..."
1966 #define OBD_FAIL_OST_PAUSE_CREATE        0x223
1967     do_facet ost1 "$LCTL set_param fail_val=20000"
1968     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1969     createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1970
1971     client_reconnect
1972     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1973     log "phase 2"
1974     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1975     ATTEMPTS=$(($CONN2 - $CONN1))
1976     echo "$ATTEMPTS osc reconnect attempts on instant slow"
1977     # do it again; should not timeout
1978     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1979     cp /etc/profile $DIR/$tfile || error "cp failed"
1980     do_facet ost1 "$LCTL set_param fail_loc=0"
1981     client_reconnect
1982     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1983     CONN3=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1984     ATTEMPTS=$(($CONN3 - $CONN2))
1985     echo "$ATTEMPTS osc reconnect attempts on 2nd slow"
1986     [ $ATTEMPTS -gt 0 ] && error "AT should have prevented reconnect"
1987     return 0
1988 }
1989 run_test 67b "AT: verify instant slowdown doesn't induce reconnects"
1990
1991 test_68 () #bug 13813
1992 {
1993     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1994
1995     at_start || return 0
1996     local ldlm_enqueue_min=$(find /sys -name ldlm_enqueue_min)
1997     [ -z "$ldlm_enqueue_min" ] && skip "missing /sys/.../ldlm_enqueue_min" && return 0
1998     local ldlm_enqueue_min_r=$(do_facet ost1 "find /sys -name ldlm_enqueue_min")
1999     [ -z "$ldlm_enqueue_min_r" ] && skip "missing /sys/.../ldlm_enqueue_min in the ost1" && return 0
2000     local ENQ_MIN=$(cat $ldlm_enqueue_min)
2001     local ENQ_MIN_R=$(do_facet ost1 "cat $ldlm_enqueue_min_r")
2002         echo $TIMEOUT >> $ldlm_enqueue_min
2003         do_facet ost1 "echo $TIMEOUT >> $ldlm_enqueue_min_r"
2004
2005         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2006         $LFS setstripe --stripe-index=0 -c 1 $DIR/$tdir ||
2007                 error "$LFS setstripe failed for $DIR/$tdir"
2008         #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
2009         $LCTL set_param fail_val=$(($TIMEOUT - 1))
2010         $LCTL set_param fail_loc=0x80000312
2011         cp /etc/profile $DIR/$tdir/${tfile}_1 || error "1st cp failed $?"
2012         $LCTL set_param fail_val=$((TIMEOUT * 5 / 4))
2013         $LCTL set_param fail_loc=0x80000312
2014         cp /etc/profile $DIR/$tdir/${tfile}_2 || error "2nd cp failed $?"
2015         $LCTL set_param fail_loc=0
2016
2017         echo $ENQ_MIN >> $ldlm_enqueue_min
2018         do_facet ost1 "echo $ENQ_MIN_R >> $ldlm_enqueue_min_r"
2019         rm -rf $DIR/$tdir
2020         return 0
2021 }
2022 run_test 68 "AT: verify slowing locks"
2023
2024 at_cleanup
2025 # end of AT tests includes above lines
2026
2027 # start multi-client tests
2028 test_70a () {
2029         [ -z "$CLIENTS" ] &&
2030                 { skip "Need two or more clients." && return; }
2031         [ $CLIENTCOUNT -lt 2 ] &&
2032                 { skip "Need two or more clients, have $CLIENTCOUNT" && return; }
2033
2034         echo "mount clients $CLIENTS ..."
2035         zconf_mount_clients $CLIENTS $MOUNT
2036
2037         local clients=${CLIENTS//,/ }
2038         echo "Write/read files on $DIR ; clients $CLIENTS ... "
2039         for CLIENT in $clients; do
2040                 do_node $CLIENT dd bs=1M count=10 if=/dev/zero \
2041                         of=$DIR/${tfile}_${CLIENT} 2>/dev/null ||
2042                                 error "dd failed on $CLIENT"
2043         done
2044
2045         local prev_client=$(echo $clients | sed 's/^.* \(.\+\)$/\1/')
2046         for C in ${CLIENTS//,/ }; do
2047                 do_node $prev_client dd if=$DIR/${tfile}_${C} \
2048                         of=/dev/null 2>/dev/null ||
2049                         error "dd if=$DIR/${tfile}_${C} failed on $prev_client"
2050                 prev_client=$C
2051         done
2052
2053         ls $DIR
2054 }
2055 run_test 70a "check multi client t-f"
2056
2057 check_for_process () {
2058         local clients=$1
2059         shift
2060         local prog=$@
2061
2062         killall_process $clients "$prog" -0
2063 }
2064
2065 test_70b () {
2066         local clients=${CLIENTS:-$HOSTNAME}
2067
2068         zconf_mount_clients $clients $MOUNT
2069
2070         local duration=300
2071         [ "$SLOW" = "no" ] && duration=120
2072         # set duration to 900 because it takes some time to boot node
2073         [ "$FAILURE_MODE" = HARD ] && duration=900
2074
2075         local elapsed
2076         local start_ts=$(date +%s)
2077         local cmd="rundbench 1 -t $duration"
2078         local pid=""
2079         if [ $MDSCOUNT -ge 2 ]; then
2080                 test_mkdir -p -c$MDSCOUNT $DIR/$tdir
2081                 $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
2082         fi
2083         do_nodesv $clients "set -x; MISSING_DBENCH_OK=$MISSING_DBENCH_OK \
2084                 PATH=\$PATH:$LUSTRE/utils:$LUSTRE/tests/:$DBENCH_LIB \
2085                 DBENCH_LIB=$DBENCH_LIB TESTSUITE=$TESTSUITE TESTNAME=$TESTNAME \
2086                 MOUNT=$MOUNT DIR=$DIR/$tdir/\\\$(hostname) LCTL=$LCTL $cmd" &
2087         pid=$!
2088
2089         #LU-1897 wait for all dbench copies to start
2090         while ! check_for_process $clients dbench; do
2091                 elapsed=$(($(date +%s) - start_ts))
2092                 if [ $elapsed -gt $duration ]; then
2093                         killall_process $clients dbench
2094                         error "dbench failed to start on $clients!"
2095                 fi
2096                 sleep 1
2097         done
2098
2099         log "Started rundbench load pid=$pid ..."
2100
2101         elapsed=$(($(date +%s) - start_ts))
2102         local num_failovers=0
2103         local fail_index=1
2104         while [ $elapsed -lt $duration ]; do
2105                 if ! check_for_process $clients dbench; then
2106                         error_noexit "dbench stopped on some of $clients!"
2107                         killall_process $clients dbench
2108                         break
2109                 fi
2110                 sleep 1
2111                 replay_barrier mds$fail_index
2112                 sleep 1 # give clients a time to do operations
2113                 # Increment the number of failovers
2114                 num_failovers=$((num_failovers+1))
2115                 log "$TESTNAME fail mds$fail_index $num_failovers times"
2116                 fail mds$fail_index
2117                 elapsed=$(($(date +%s) - start_ts))
2118                 if [ $fail_index -ge $MDSCOUNT ]; then
2119                         fail_index=1
2120                 else
2121                         fail_index=$((fail_index+1))
2122                 fi
2123         done
2124
2125         wait $pid || error "rundbench load on $clients failed!"
2126 }
2127 run_test 70b "dbench ${MDSCOUNT}mdts recovery; $CLIENTCOUNT clients"
2128 # end multi-client tests
2129
2130 random_fail_mdt() {
2131         local max_index=$1
2132         local duration=$2
2133         local monitor_pid=$3
2134         local elapsed
2135         local start_ts=$(date +%s)
2136         local num_failovers=0
2137         local fail_index
2138
2139         elapsed=$(($(date +%s) - start_ts))
2140         while [ $elapsed -lt $duration ]; do
2141                 fail_index=$((RANDOM%max_index+1))
2142                 kill -0 $monitor_pid ||
2143                         error "$monitor_pid stopped"
2144                 sleep 120
2145                 replay_barrier mds$fail_index
2146                 sleep 10
2147                 # Increment the number of failovers
2148                 num_failovers=$((num_failovers+1))
2149                 log "$TESTNAME fail mds$fail_index $num_failovers times"
2150                 fail mds$fail_index
2151                 elapsed=$(($(date +%s) - start_ts))
2152         done
2153 }
2154
2155 cleanup_70c() {
2156         trap 0
2157         rm -f $DIR/replay-single.70c.lck
2158         rm -rf /$DIR/$tdir
2159 }
2160
2161 test_70c () {
2162         local clients=${CLIENTS:-$HOSTNAME}
2163         local rc=0
2164
2165         zconf_mount_clients $clients $MOUNT
2166
2167         local duration=300
2168         [ "$SLOW" = "no" ] && duration=180
2169         # set duration to 900 because it takes some time to boot node
2170         [ "$FAILURE_MODE" = HARD ] && duration=600
2171
2172         local elapsed
2173         local start_ts=$(date +%s)
2174
2175         trap cleanup_70c EXIT
2176         (
2177                 while [ ! -e $DIR/replay-single.70c.lck ]; do
2178                         test_mkdir -p -c$MDSCOUNT $DIR/$tdir || break
2179                         if [ $MDSCOUNT -ge 2 ]; then
2180                                 $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir ||
2181                                 error "set default dirstripe failed"
2182                         fi
2183                         cd $DIR/$tdir || break
2184                         tar cf - /etc | tar xf - || error "tar failed in loop"
2185                 done
2186         )&
2187         tar_70c_pid=$!
2188         echo "Started tar $tar_70c_pid"
2189
2190         random_fail_mdt $MDSCOUNT $duration $tar_70c_pid
2191         kill -0 $tar_70c_pid || error "tar $tar_70c_pid stopped"
2192
2193         touch $DIR/replay-single.70c.lck
2194         wait $tar_70c_pid || error "$?: tar failed"
2195
2196         cleanup_70c
2197         true
2198 }
2199 run_test 70c "tar ${MDSCOUNT}mdts recovery"
2200
2201 cleanup_70d() {
2202         trap 0
2203         kill -9 $mkdir_70d_pid
2204 }
2205
2206 test_70d () {
2207         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2208         local clients=${CLIENTS:-$HOSTNAME}
2209         local rc=0
2210
2211         zconf_mount_clients $clients $MOUNT
2212
2213         local duration=300
2214         [ "$SLOW" = "no" ] && duration=180
2215         # set duration to 900 because it takes some time to boot node
2216         [ "$FAILURE_MODE" = HARD ] && duration=900
2217
2218         mkdir -p $DIR/$tdir
2219
2220         local elapsed
2221         local start_ts=$(date +%s)
2222
2223         trap cleanup_70d EXIT
2224         (
2225                 while true; do
2226                         $LFS mkdir -i0 -c2 $DIR/$tdir/test || {
2227                                 echo "mkdir fails"
2228                                 break
2229                         }
2230                         $LFS mkdir -i1 -c2 $DIR/$tdir/test1 || {
2231                                 echo "mkdir fails"
2232                                 break
2233                         }
2234
2235                         touch $DIR/$tdir/test/a || {
2236                                 echo "touch fails"
2237                                 break;
2238                         }
2239                         mkdir $DIR/$tdir/test/b || {
2240                                 echo "mkdir fails"
2241                                 break;
2242                         }
2243                         rm -rf $DIR/$tdir/test || {
2244                                 echo "rmdir fails"
2245                                 ls -lR $DIR/$tdir
2246                                 break
2247                         }
2248
2249                         touch $DIR/$tdir/test1/a || {
2250                                 echo "touch fails"
2251                                 break;
2252                         }
2253                         mkdir $DIR/$tdir/test1/b || {
2254                                 echo "mkdir fails"
2255                                 break;
2256                         }
2257
2258                         rm -rf $DIR/$tdir/test1 || {
2259                                 echo "rmdir fails"
2260                                 ls -lR $DIR/$tdir/test1
2261                                 break
2262                         }
2263                 done
2264         )&
2265         mkdir_70d_pid=$!
2266         echo "Started  $mkdir_70d_pid"
2267
2268         random_fail_mdt $MDSCOUNT $duration $mkdir_70d_pid
2269         kill -0 $mkdir_70d_pid || error "mkdir/rmdir $mkdir_70d_pid stopped"
2270
2271         cleanup_70d
2272         true
2273 }
2274 run_test 70d "mkdir/rmdir striped dir ${MDSCOUNT}mdts recovery"
2275
2276 test_70e () {
2277         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2278         local clients=${CLIENTS:-$HOSTNAME}
2279         local rc=0
2280
2281         lctl set_param debug=+ha
2282         zconf_mount_clients $clients $MOUNT
2283
2284         local duration=300
2285         [ "$SLOW" = "no" ] && duration=180
2286         # set duration to 900 because it takes some time to boot node
2287         [ "$FAILURE_MODE" = HARD ] && duration=900
2288
2289         mkdir -p $DIR/$tdir
2290         $LFS mkdir -i0 $DIR/$tdir/test_0
2291         $LFS mkdir -i0 $DIR/$tdir/test_1
2292         touch $DIR/$tdir/test_0/a
2293         touch $DIR/$tdir/test_1/b
2294         (
2295         while true; do
2296                 mrename $DIR/$tdir/test_0/a $DIR/$tdir/test_1/b > /dev/null || {
2297                         echo "a->b fails"
2298                         break;
2299                 }
2300
2301                 checkstat $DIR/$tdir/test_0/a && {
2302                         echo "a still exists"
2303                         break
2304                 }
2305
2306                 checkstat $DIR/$tdir/test_1/b || {
2307                         echo "b still  exists"
2308                         break
2309                 }
2310
2311                 touch $DIR/$tdir/test_0/a || {
2312                         echo "touch a fails"
2313                         break
2314                 }
2315
2316                 mrename $DIR/$tdir/test_1/b $DIR/$tdir/test_0/a > /dev/null || {
2317                         echo "a->a fails"
2318                         break;
2319                 }
2320         done
2321         )&
2322         rename_70e_pid=$!
2323         stack_trap "kill -9 $rename_70e_pid" EXIT
2324         echo "Started PID=$rename_70e_pid"
2325
2326         random_fail_mdt 2 $duration $rename_70e_pid
2327         kill -0 $rename_70e_pid || error "rename $rename_70e_pid stopped"
2328 }
2329 run_test 70e "rename cross-MDT with random fails"
2330
2331 test_70f_write_and_read(){
2332         local srcfile=$1
2333         local stopflag=$2
2334         local client
2335
2336         echo "Write/read files in: '$DIR/$tdir', clients: '$CLIENTS' ..."
2337         for client in ${CLIENTS//,/ }; do
2338                 [ -f $stopflag ] || return
2339
2340                 local tgtfile=$DIR/$tdir/$tfile.$client
2341                 do_node $client dd $DD_OPTS bs=1M count=10 if=$srcfile \
2342                         of=$tgtfile 2>/dev/null ||
2343                         error "dd $DD_OPTS bs=1M count=10 if=$srcfile " \
2344                               "of=$tgtfile failed on $client, rc=$?"
2345         done
2346
2347         local prev_client=$(echo ${CLIENTS//,/ } | awk '{ print $NF }')
2348         local index=0
2349
2350         for client in ${CLIENTS//,/ }; do
2351                 [ -f $stopflag ] || return
2352
2353                 # flush client cache in case test is running on only one client
2354                 # do_node $client cancel_lru_locks osc
2355                 do_node $client $LCTL set_param ldlm.namespaces.*.lru_size=clear
2356
2357                 tgtfile=$DIR/$tdir/$tfile.$client
2358                 local md5=$(do_node $prev_client "md5sum $tgtfile")
2359                 [ ${checksum[$index]// */} = ${md5// */} ] ||
2360                         error "$tgtfile: checksum doesn't match on $prev_client"
2361                 index=$((index + 1))
2362                 prev_client=$client
2363         done
2364 }
2365
2366 test_70f_loop(){
2367         local srcfile=$1
2368         local stopflag=$2
2369         DD_OPTS=
2370
2371         mkdir -p $DIR/$tdir || error "cannot create $DIR/$tdir directory"
2372         $LFS setstripe -c -1 $DIR/$tdir ||
2373                 error "cannot $LFS setstripe $DIR/$tdir"
2374
2375         touch $stopflag
2376         while [ -f $stopflag ]; do
2377                 test_70f_write_and_read $srcfile $stopflag
2378                 # use direct IO and buffer cache in turns if loop
2379                 [ -n "$DD_OPTS" ] && DD_OPTS="" || DD_OPTS="oflag=direct"
2380         done
2381 }
2382
2383 test_70f_cleanup() {
2384         trap 0
2385         rm -f $TMP/$tfile.stop
2386         do_nodes $CLIENTS rm -f $TMP/$tfile
2387         rm -f $DIR/$tdir/$tfile.*
2388 }
2389
2390 test_70f() {
2391 #       [ x$ost1failover_HOST = x$ost_HOST ] &&
2392 #               { skip "Failover host not defined" && return; }
2393 #       [ -z "$CLIENTS" ] &&
2394 #               { skip "CLIENTS are not specified." && return; }
2395 #       [ $CLIENTCOUNT -lt 2 ] &&
2396 #               { skip "Need 2 or more clients, have $CLIENTCOUNT" && return; }
2397
2398         [[ "$OST1_VERSION" -lt $(version_code 2.9.53) ]] &&
2399                 skip "Need server version at least 2.9.53"
2400
2401         echo "mount clients $CLIENTS ..."
2402         zconf_mount_clients $CLIENTS $MOUNT
2403
2404         local srcfile=$TMP/$tfile
2405         local client
2406         local index=0
2407
2408         trap test_70f_cleanup EXIT
2409         # create a different source file local to each client node so we can
2410         # detect if the file wasn't written out properly after failover
2411         do_nodes $CLIENTS dd bs=1M count=10 if=/dev/urandom of=$srcfile \
2412                 2>/dev/null || error "can't create $srcfile on $CLIENTS"
2413         for client in ${CLIENTS//,/ }; do
2414                 checksum[$index]=$(do_node $client "md5sum $srcfile")
2415                 index=$((index + 1))
2416         done
2417
2418         local duration=120
2419         [ "$SLOW" = "no" ] && duration=60
2420         # set duration to 900 because it takes some time to boot node
2421         [ "$FAILURE_MODE" = HARD ] && duration=900
2422
2423         local stopflag=$TMP/$tfile.stop
2424         test_70f_loop $srcfile $stopflag &
2425         local pid=$!
2426
2427         local elapsed=0
2428         local num_failovers=0
2429         local start_ts=$SECONDS
2430         while [ $elapsed -lt $duration ]; do
2431                 sleep 3
2432                 replay_barrier ost1
2433                 sleep 1
2434                 num_failovers=$((num_failovers + 1))
2435                 log "$TESTNAME failing OST $num_failovers times"
2436                 fail ost1
2437                 sleep 2
2438                 elapsed=$((SECONDS - start_ts))
2439         done
2440
2441         rm -f $stopflag
2442         wait $pid
2443         test_70f_cleanup
2444 }
2445 run_test 70f "OSS O_DIRECT recovery with $CLIENTCOUNT clients"
2446
2447 cleanup_71a() {
2448         trap 0
2449         kill -9 $mkdir_71a_pid
2450 }
2451
2452 random_double_fail_mdt() {
2453         local max_index=$1
2454         local duration=$2
2455         local monitor_pid=$3
2456         local elapsed
2457         local start_ts=$(date +%s)
2458         local num_failovers=0
2459         local fail_index
2460         local second_index
2461
2462         elapsed=$(($(date +%s) - start_ts))
2463         while [ $elapsed -lt $duration ]; do
2464                 fail_index=$((RANDOM%max_index + 1))
2465                 if [ $fail_index -eq $max_index ]; then
2466                         second_index=1
2467                 else
2468                         second_index=$((fail_index + 1))
2469                 fi
2470                 kill -0 $monitor_pid ||
2471                         error "$monitor_pid stopped"
2472                 sleep 120
2473                 replay_barrier mds$fail_index
2474                 replay_barrier mds$second_index
2475                 sleep 10
2476                 # Increment the number of failovers
2477                 num_failovers=$((num_failovers+1))
2478                 log "fail mds$fail_index mds$second_index $num_failovers times"
2479                 fail mds${fail_index},mds${second_index}
2480                 elapsed=$(($(date +%s) - start_ts))
2481         done
2482 }
2483
2484 test_71a () {
2485         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2486         local clients=${CLIENTS:-$HOSTNAME}
2487         local rc=0
2488
2489         zconf_mount_clients $clients $MOUNT
2490
2491         local duration=300
2492         [ "$SLOW" = "no" ] && duration=180
2493         # set duration to 900 because it takes some time to boot node
2494         [ "$FAILURE_MODE" = HARD ] && duration=900
2495
2496         mkdir_on_mdt0 $DIR/$tdir
2497
2498         local elapsed
2499         local start_ts=$(date +%s)
2500
2501         trap cleanup_71a EXIT
2502         (
2503                 while true; do
2504                         $LFS mkdir -i0 -c2 $DIR/$tdir/test
2505                         rmdir $DIR/$tdir/test
2506                 done
2507         )&
2508         mkdir_71a_pid=$!
2509         echo "Started  $mkdir_71a_pid"
2510
2511         random_double_fail_mdt 2 $duration $mkdir_71a_pid
2512         kill -0 $mkdir_71a_pid || error "mkdir/rmdir $mkdir_71a_pid stopped"
2513
2514         cleanup_71a
2515         true
2516 }
2517 run_test 71a "mkdir/rmdir striped dir with 2 mdts recovery"
2518
2519 test_73a() {
2520         multiop_bg_pause $DIR/$tfile O_tSc ||
2521                 error "multiop_bg_pause $DIR/$tfile failed"
2522         pid=$!
2523         rm -f $DIR/$tfile
2524
2525         replay_barrier $SINGLEMDS
2526         #define OBD_FAIL_LDLM_ENQUEUE_NET                       0x302
2527         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000302"
2528         fail $SINGLEMDS
2529         kill -USR1 $pid
2530         wait $pid || error "multiop pid failed"
2531         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
2532         return 0
2533 }
2534 run_test 73a "open(O_CREAT), unlink, replay, reconnect before open replay, close"
2535
2536 test_73b() {
2537         multiop_bg_pause $DIR/$tfile O_tSc ||
2538                 error "multiop_bg_pause $DIR/$tfile failed"
2539         pid=$!
2540         rm -f $DIR/$tfile
2541
2542         replay_barrier $SINGLEMDS
2543         #define OBD_FAIL_MDS_LDLM_REPLY_NET       0x157
2544         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000157"
2545         fail $SINGLEMDS
2546         kill -USR1 $pid
2547         wait $pid || error "multiop pid failed"
2548         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
2549         return 0
2550 }
2551 run_test 73b "open(O_CREAT), unlink, replay, reconnect at open_replay reply, close"
2552
2553 # bug 18554
2554 test_74() {
2555         local clients=${CLIENTS:-$HOSTNAME}
2556
2557         zconf_umount_clients $clients $MOUNT
2558         stop ost1
2559         facet_failover $SINGLEMDS
2560         zconf_mount_clients $clients $MOUNT
2561         mount_facet ost1
2562         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2563         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
2564         clients_up || error "client evicted: $?"
2565         return 0
2566 }
2567 run_test 74 "Ensure applications don't fail waiting for OST recovery"
2568
2569 remote_dir_check_80() {
2570         local mdtidx=1
2571         local diridx
2572         local fileidx
2573
2574         diridx=$($LFS getstripe -m $remote_dir) ||
2575                 error "$LFS getstripe -m $remote_dir failed"
2576         [ $diridx -eq $mdtidx ] || error "$diridx != $mdtidx"
2577
2578         createmany -o $remote_dir/f-%d 20 || error "creation failed"
2579         fileidx=$($LFS getstripe -m $remote_dir/f-1) ||
2580                 error "$LFS getstripe -m $remote_dir/f-1 failed"
2581         [ $fileidx -eq $mdtidx ] || error "$fileidx != $mdtidx"
2582
2583         return 0
2584 }
2585
2586 test_80a() {
2587         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2588         ([ $FAILURE_MODE == "HARD" ] &&
2589                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2590                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2591                 return 0
2592
2593         local MDTIDX=1
2594         local remote_dir=$DIR/$tdir/remote_dir
2595
2596         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2597         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2598         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2599         $LFS mkdir -i $MDTIDX $remote_dir &
2600         local CLIENT_PID=$!
2601
2602         replay_barrier mds1
2603         fail mds${MDTIDX}
2604
2605         wait $CLIENT_PID || error "remote creation failed"
2606
2607         remote_dir_check_80 || error "remote dir check failed"
2608         rm -rf $DIR/$tdir || error "rmdir failed"
2609
2610         return 0
2611 }
2612 run_test 80a "DNE: create remote dir, drop update rep from MDT0, fail MDT0"
2613
2614 test_80b() {
2615         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2616         ([ $FAILURE_MODE == "HARD" ] &&
2617                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2618                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2619                 return 0
2620
2621         local MDTIDX=1
2622         local remote_dir=$DIR/$tdir/remote_dir
2623
2624         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2625         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2626         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2627         $LFS mkdir -i $MDTIDX $remote_dir &
2628         local CLIENT_PID=$!
2629
2630         replay_barrier mds1
2631         replay_barrier mds2
2632         fail mds$((MDTIDX + 1))
2633
2634         wait $CLIENT_PID || error "remote creation failed"
2635
2636         remote_dir_check_80 || error "remote dir check failed"
2637         rm -rf $DIR/$tdir || error "rmdir failed"
2638
2639         return 0
2640 }
2641 run_test 80b "DNE: create remote dir, drop update rep from MDT0, fail MDT1"
2642
2643 test_80c() {
2644         [[ "$mds1_FSTYPE" = zfs ]] &&
2645                 [[ $MDS1_VERSION -lt $(version_code 2.12.51) ]] &&
2646                 skip "requires LU-10143 fix on MDS"
2647         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2648         ([ $FAILURE_MODE == "HARD" ] &&
2649                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2650                 skip "MDTs needs to be on diff hosts for HARD fail mode"
2651
2652         local MDTIDX=1
2653         local remote_dir=$DIR/$tdir/remote_dir
2654
2655         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2656         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2657         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2658         $LFS mkdir -i $MDTIDX $remote_dir &
2659         local CLIENT_PID=$!
2660
2661         replay_barrier mds1
2662         replay_barrier mds2
2663         fail mds${MDTIDX}
2664         fail mds$((MDTIDX + 1))
2665
2666         wait $CLIENT_PID || error "remote creation failed"
2667
2668         remote_dir_check_80 || error "remote dir check failed"
2669         rm -rf $DIR/$tdir || error "rmdir failed"
2670
2671         return 0
2672 }
2673 run_test 80c "DNE: create remote dir, drop update rep from MDT1, fail MDT[0,1]"
2674
2675 test_80d() {
2676         [[ "$mds1_FSTYPE" = zfs ]] &&
2677                 [[ $MDS1_VERSION -lt $(version_code 2.12.51) ]] &&
2678                 skip "requires LU-10143 fix on MDS"
2679         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2680         local MDTIDX=1
2681         local remote_dir=$DIR/$tdir/remote_dir
2682
2683         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2684         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2685         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2686         $LFS mkdir -i $MDTIDX $remote_dir &
2687         local CLIENT_PID=$!
2688
2689         # sleep 3 seconds to make sure MDTs are failed after
2690         # lfs mkdir -i has finished on all of MDTs.
2691         sleep 3
2692
2693         replay_barrier mds1
2694         replay_barrier mds2
2695         fail mds${MDTIDX},mds$((MDTIDX + 1))
2696
2697         wait $CLIENT_PID || error "remote creation failed"
2698
2699         remote_dir_check_80 || error "remote dir check failed"
2700         rm -rf $DIR/$tdir || error "rmdir failed"
2701
2702         return 0
2703 }
2704 run_test 80d "DNE: create remote dir, drop update rep from MDT1, fail 2 MDTs"
2705
2706 test_80e() {
2707         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2708         ([ $FAILURE_MODE == "HARD" ] &&
2709                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2710                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2711                 return 0
2712
2713         local MDTIDX=1
2714         local remote_dir=$DIR/$tdir/remote_dir
2715
2716         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2717         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2718         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2719         $LFS mkdir -i $MDTIDX $remote_dir &
2720         local CLIENT_PID=$!
2721
2722         # sleep 3 seconds to make sure MDTs are failed after
2723         # lfs mkdir -i has finished on all of MDTs.
2724         sleep 3
2725
2726         replay_barrier mds1
2727         fail mds${MDTIDX}
2728
2729         wait $CLIENT_PID || error "remote creation failed"
2730
2731         remote_dir_check_80 || error "remote dir check failed"
2732         rm -rf $DIR/$tdir || error "rmdir failed"
2733
2734         return 0
2735 }
2736 run_test 80e "DNE: create remote dir, drop MDT1 rep, fail MDT0"
2737
2738 test_80f() {
2739         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2740         ([ $FAILURE_MODE == "HARD" ] &&
2741                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2742                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2743                 return 0
2744         local MDTIDX=1
2745         local remote_dir=$DIR/$tdir/remote_dir
2746
2747         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2748         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2749         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2750         $LFS mkdir -i $MDTIDX $remote_dir &
2751         local CLIENT_PID=$!
2752
2753         replay_barrier mds2
2754         fail mds$((MDTIDX + 1))
2755
2756         wait $CLIENT_PID || error "remote creation failed"
2757
2758         remote_dir_check_80 || error "remote dir check failed"
2759         rm -rf $DIR/$tdir || error "rmdir failed"
2760
2761         return 0
2762 }
2763 run_test 80f "DNE: create remote dir, drop MDT1 rep, fail MDT1"
2764
2765 test_80g() {
2766         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2767         ([ $FAILURE_MODE == "HARD" ] &&
2768                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2769                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2770                 return 0
2771
2772         local MDTIDX=1
2773         local remote_dir=$DIR/$tdir/remote_dir
2774
2775         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2776         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2777         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2778         $LFS mkdir -i $MDTIDX $remote_dir &
2779         local CLIENT_PID=$!
2780
2781         # sleep 3 seconds to make sure MDTs are failed after
2782         # lfs mkdir -i has finished on all of MDTs.
2783         sleep 3
2784
2785         replay_barrier mds1
2786         replay_barrier mds2
2787         fail mds${MDTIDX}
2788         fail mds$((MDTIDX + 1))
2789
2790         wait $CLIENT_PID || error "remote creation failed"
2791
2792         remote_dir_check_80 || error "remote dir check failed"
2793         rm -rf $DIR/$tdir || error "rmdir failed"
2794
2795         return 0
2796 }
2797 run_test 80g "DNE: create remote dir, drop MDT1 rep, fail MDT0, then MDT1"
2798
2799 test_80h() {
2800         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2801         local MDTIDX=1
2802         local remote_dir=$DIR/$tdir/remote_dir
2803
2804         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2805         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2806         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2807         $LFS mkdir -i $MDTIDX $remote_dir &
2808         local CLIENT_PID=$!
2809
2810         # sleep 3 seconds to make sure MDTs are failed after
2811         # lfs mkdir -i has finished on all of MDTs.
2812         sleep 3
2813
2814         replay_barrier mds1
2815         replay_barrier mds2
2816         fail mds${MDTIDX},mds$((MDTIDX + 1))
2817
2818         wait $CLIENT_PID || error "remote dir creation failed"
2819
2820         remote_dir_check_80 || error "remote dir check failed"
2821         rm -rf $DIR/$tdir || error "rmdir failed"
2822
2823         return 0
2824 }
2825 run_test 80h "DNE: create remote dir, drop MDT1 rep, fail 2 MDTs"
2826
2827 test_81a() {
2828         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2829         ([ $FAILURE_MODE == "HARD" ] &&
2830                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2831                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2832                 return 0
2833
2834         local MDTIDX=1
2835         local remote_dir=$DIR/$tdir/remote_dir
2836
2837         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2838         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2839
2840         touch $remote_dir || error "touch $remote_dir failed"
2841         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2842         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2843         rmdir $remote_dir &
2844         local CLIENT_PID=$!
2845
2846         replay_barrier mds2
2847         fail mds$((MDTIDX + 1))
2848
2849         wait $CLIENT_PID || error "rm remote dir failed"
2850
2851         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2852
2853         rm -rf $DIR/$tdir || error "rmdir failed"
2854
2855         return 0
2856 }
2857 run_test 81a "DNE: unlink remote dir, drop MDT0 update rep,  fail MDT1"
2858
2859 test_81b() {
2860         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2861         ([ $FAILURE_MODE == "HARD" ] &&
2862                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2863                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2864                 return 0
2865         local MDTIDX=1
2866         local remote_dir=$DIR/$tdir/remote_dir
2867
2868         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2869         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2870
2871         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2872         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2873         rmdir $remote_dir &
2874         local CLIENT_PID=$!
2875
2876         replay_barrier mds1
2877         fail mds${MDTIDX}
2878
2879         wait $CLIENT_PID || error "rm remote dir failed"
2880
2881         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2882
2883         rm -rf $DIR/$tdir || error "rmdir failed"
2884
2885         return 0
2886 }
2887 run_test 81b "DNE: unlink remote dir, drop MDT0 update reply,  fail MDT0"
2888
2889 test_81c() {
2890         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2891         ([ $FAILURE_MODE == "HARD" ] &&
2892                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2893                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2894                 return 0
2895
2896         local MDTIDX=1
2897         local remote_dir=$DIR/$tdir/remote_dir
2898
2899         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2900         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2901
2902         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2903         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2904         rmdir $remote_dir &
2905         local CLIENT_PID=$!
2906
2907         replay_barrier mds1
2908         replay_barrier mds2
2909         fail mds${MDTIDX}
2910         fail mds$((MDTIDX + 1))
2911
2912         wait $CLIENT_PID || error "rm remote dir failed"
2913
2914         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2915
2916         rm -rf $DIR/$tdir || error "rmdir failed"
2917
2918         return 0
2919 }
2920 run_test 81c "DNE: unlink remote dir, drop MDT0 update reply, fail MDT0,MDT1"
2921
2922 test_81d() {
2923         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2924         local MDTIDX=1
2925         local remote_dir=$DIR/$tdir/remote_dir
2926
2927         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2928         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2929
2930         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2931         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2932         rmdir $remote_dir &
2933         local CLIENT_PID=$!
2934
2935         replay_barrier mds1
2936         replay_barrier mds2
2937         fail mds${MDTIDX},mds$((MDTIDX + 1))
2938
2939         wait $CLIENT_PID || error "rm remote dir failed"
2940
2941         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2942
2943         rm -rf $DIR/$tdir || error "rmdir failed"
2944
2945         return 0
2946 }
2947 run_test 81d "DNE: unlink remote dir, drop MDT0 update reply,  fail 2 MDTs"
2948
2949 test_81e() {
2950         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2951         ([ $FAILURE_MODE == "HARD" ] &&
2952                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2953                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2954                 return 0
2955
2956         local MDTIDX=1
2957         local remote_dir=$DIR/$tdir/remote_dir
2958
2959         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2960         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2961
2962         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2963         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2964         rmdir $remote_dir &
2965         local CLIENT_PID=$!
2966         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0
2967
2968         replay_barrier mds1
2969         fail mds${MDTIDX}
2970
2971         wait $CLIENT_PID || error "rm remote dir failed"
2972
2973         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2974
2975         rm -rf $DIR/$tdir || error "rmdir failed"
2976
2977         return 0
2978 }
2979 run_test 81e "DNE: unlink remote dir, drop MDT1 req reply, fail MDT0"
2980
2981 test_81f() {
2982         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2983         ([ $FAILURE_MODE == "HARD" ] &&
2984                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2985                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2986                 return 0
2987
2988         local MDTIDX=1
2989         local remote_dir=$DIR/$tdir/remote_dir
2990
2991         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2992         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2993
2994         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2995         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2996         rmdir $remote_dir &
2997         local CLIENT_PID=$!
2998
2999         replay_barrier mds2
3000         fail mds$((MDTIDX + 1))
3001
3002         wait $CLIENT_PID || error "rm remote dir failed"
3003
3004         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3005
3006         rm -rf $DIR/$tdir || error "rmdir failed"
3007
3008         return 0
3009 }
3010 run_test 81f "DNE: unlink remote dir, drop MDT1 req reply, fail MDT1"
3011
3012 test_81g() {
3013         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3014         ([ $FAILURE_MODE == "HARD" ] &&
3015                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3016                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3017                 return 0
3018
3019         local MDTIDX=1
3020         local remote_dir=$DIR/$tdir/remote_dir
3021
3022         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3023         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
3024
3025         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3026         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
3027         rmdir $remote_dir &
3028         local CLIENT_PID=$!
3029
3030         replay_barrier mds1
3031         replay_barrier mds2
3032         fail mds${MDTIDX}
3033         fail mds$((MDTIDX + 1))
3034
3035         wait $CLIENT_PID || error "rm remote dir failed"
3036
3037         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3038
3039         rm -rf $DIR/$tdir || error "rmdir failed"
3040
3041         return 0
3042 }
3043 run_test 81g "DNE: unlink remote dir, drop req reply, fail M0, then M1"
3044
3045 test_81h() {
3046         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3047         local MDTIDX=1
3048         local remote_dir=$DIR/$tdir/remote_dir
3049
3050         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3051         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
3052
3053         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3054         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
3055         rmdir $remote_dir &
3056         local CLIENT_PID=$!
3057
3058         replay_barrier mds1
3059         replay_barrier mds2
3060         fail mds${MDTIDX},mds$((MDTIDX + 1))
3061
3062         wait $CLIENT_PID || error "rm remote dir failed"
3063
3064         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3065
3066         rm -rf $DIR/$tdir || error "rmdir failed"
3067
3068         return 0
3069 }
3070 run_test 81h "DNE: unlink remote dir, drop request reply, fail 2 MDTs"
3071
3072 test_84a() {
3073 #define OBD_FAIL_MDS_OPEN_WAIT_CREATE  0x144
3074     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000144"
3075     createmany -o $DIR/$tfile- 1 &
3076     PID=$!
3077     mds_evict_client
3078     wait $PID
3079     client_up || client_up || true    # reconnect
3080 }
3081 run_test 84a "stale open during export disconnect"
3082
3083 test_85a() { #bug 16774
3084         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
3085
3086         for i in $(seq 100); do
3087                 echo "tag-$i" > $DIR/$tfile-$i
3088                 grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
3089         done
3090
3091         lov_id=$(lctl dl | grep "clilov")
3092         addr=$(echo $lov_id | awk '{print $4}' | awk -F '-' '{print $NF}')
3093         count=$(lctl get_param -n \
3094                 ldlm.namespaces.*MDT0000*$addr.lock_unused_count)
3095         echo "before recovery: unused locks count = $count"
3096
3097         fail $SINGLEMDS
3098
3099         count2=$(lctl get_param -n \
3100                  ldlm.namespaces.*MDT0000*$addr.lock_unused_count)
3101         echo "after recovery: unused locks count = $count2"
3102
3103         if [ $count2 -ge $count ]; then
3104                 error "unused locks are not canceled"
3105         fi
3106 }
3107 run_test 85a "check the cancellation of unused locks during recovery(IBITS)"
3108
3109 test_85b() { #bug 16774
3110         rm -rf $DIR/$tdir
3111         mkdir $DIR/$tdir
3112
3113         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
3114
3115         $LFS setstripe -c 1 -i 0 $DIR/$tdir
3116
3117         for i in $(seq 100); do
3118                 dd if=/dev/urandom of=$DIR/$tdir/$tfile-$i bs=4096 \
3119                         count=32 >/dev/null 2>&1
3120         done
3121
3122         cancel_lru_locks osc
3123
3124         for i in $(seq 100); do
3125                 dd if=$DIR/$tdir/$tfile-$i of=/dev/null bs=4096 \
3126                         count=32 >/dev/null 2>&1
3127         done
3128
3129         lov_id=$(lctl dl | grep "clilov")
3130         addr=$(echo $lov_id | awk '{print $4}' | awk -F '-' '{print $NF}')
3131         count=$(lctl get_param -n \
3132                           ldlm.namespaces.*OST0000*$addr.lock_unused_count)
3133         echo "before recovery: unused locks count = $count"
3134         [ $count -ne 0 ] || error "unused locks ($count) should be zero"
3135
3136         fail ost1
3137
3138         count2=$(lctl get_param \
3139                  -n ldlm.namespaces.*OST0000*$addr.lock_unused_count)
3140         echo "after recovery: unused locks count = $count2"
3141
3142         if [ $count2 -ge $count ]; then
3143                 error "unused locks are not canceled"
3144         fi
3145
3146         rm -rf $DIR/$tdir
3147 }
3148 run_test 85b "check the cancellation of unused locks during recovery(EXTENT)"
3149
3150 test_86() {
3151         local clients=${CLIENTS:-$HOSTNAME}
3152
3153         zconf_umount_clients $clients $MOUNT
3154         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT*.exports.clear=0
3155         remount_facet $SINGLEMDS
3156         zconf_mount_clients $clients $MOUNT
3157 }
3158 run_test 86 "umount server after clear nid_stats should not hit LBUG"
3159
3160 test_87a() {
3161         do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
3162
3163         replay_barrier ost1
3164         $LFS setstripe -i 0 -c 1 $DIR/$tfile
3165         dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 ||
3166                 error "dd to $DIR/$tfile failed"
3167         cksum=$(md5sum $DIR/$tfile | awk '{print $1}')
3168         cancel_lru_locks osc
3169         fail ost1
3170         dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
3171         cksum2=$(md5sum $DIR/$tfile | awk '{print $1}')
3172         if [ $cksum != $cksum2 ] ; then
3173                 error "New checksum $cksum2 does not match original $cksum"
3174         fi
3175 }
3176 run_test 87a "write replay"
3177
3178 test_87b() {
3179         do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
3180
3181         replay_barrier ost1
3182         $LFS setstripe -i 0 -c 1 $DIR/$tfile
3183         dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 ||
3184                 error "dd to $DIR/$tfile failed"
3185         sleep 1 # Give it a chance to flush dirty data
3186         echo TESTTEST | dd of=$DIR/$tfile bs=1 count=8 seek=64
3187         cksum=$(md5sum $DIR/$tfile | awk '{print $1}')
3188         cancel_lru_locks osc
3189         fail ost1
3190         dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
3191         cksum2=$(md5sum $DIR/$tfile | awk '{print $1}')
3192         if [ $cksum != $cksum2 ] ; then
3193                 error "New checksum $cksum2 does not match original $cksum"
3194         fi
3195 }
3196 run_test 87b "write replay with changed data (checksum resend)"
3197
3198 test_88() { #bug 17485
3199         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3200         mkdir -p $TMP/$tdir || error "mkdir $TMP/$tdir failed"
3201
3202         $LFS setstripe -i 0 -c 1 $DIR/$tdir || error "$LFS setstripe failed"
3203
3204         replay_barrier ost1
3205         replay_barrier $SINGLEMDS
3206
3207         # exhaust precreations on ost1
3208         local OST=$(ostname_from_index 0)
3209         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $OST)
3210         local last_id=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_last_id)
3211         local next_id=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_next_id)
3212         echo "before test: last_id = $last_id, next_id = $next_id"
3213
3214         echo "Creating to objid $last_id on ost $OST..."
3215         createmany -o $DIR/$tdir/f-%d $next_id $((last_id - next_id + 2)) ||
3216                 error "createmany create files to last_id failed"
3217
3218         #create some files to use some uncommitted objids
3219         last_id=$(($last_id + 1))
3220         createmany -o $DIR/$tdir/f-%d $last_id 8 ||
3221                 error "createmany create files with uncommitted objids failed"
3222
3223     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_last_id)
3224     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_next_id)
3225     echo "before recovery: last_id = $last_id2, next_id = $next_id2" 
3226
3227     # if test uses shutdown_facet && reboot_facet instead of facet_failover ()
3228     # it has to take care about the affected facets, bug20407
3229     local affected_mds1=$(affected_facets mds1)
3230     local affected_ost1=$(affected_facets ost1)
3231
3232     shutdown_facet $SINGLEMDS
3233     shutdown_facet ost1
3234
3235     reboot_facet $SINGLEMDS
3236     change_active $affected_mds1
3237     wait_for_facet $affected_mds1
3238     mount_facets $affected_mds1 || error "Restart of mds failed"
3239
3240     reboot_facet ost1
3241     change_active $affected_ost1
3242     wait_for_facet $affected_ost1
3243     mount_facets $affected_ost1 || error "Restart of ost1 failed"
3244
3245     clients_up
3246
3247     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_last_id)
3248     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_next_id)
3249         echo "after recovery: last_id = $last_id2, next_id = $next_id2"
3250
3251         # create new files, which should use new objids, and ensure the orphan
3252         # cleanup phase for ost1 is completed at the same time
3253         for i in $(seq 8); do
3254                 file_id=$(($last_id + 10 + $i))
3255                 dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
3256         done
3257
3258         # if the objids were not recreated, then "ls" will fail with -ENOENT
3259         ls -l $DIR/$tdir/* || error "can't get the status of precreated files"
3260
3261         local file_id
3262         # write into previously created files
3263         for i in $(seq 8); do
3264                 file_id=$(($last_id + $i))
3265                 dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
3266                 cp -f $DIR/$tdir/f-$file_id $TMP/$tdir/
3267         done
3268
3269         # compare the content
3270         for i in $(seq 8); do
3271                 file_id=$(($last_id + $i))
3272                 cmp $TMP/$tdir/f-$file_id $DIR/$tdir/f-$file_id ||
3273                         error "the content of file is modified!"
3274         done
3275
3276         rm -fr $TMP/$tdir
3277 }
3278 run_test 88 "MDS should not assign same objid to different files "
3279
3280 function calc_osc_kbytes_used() {
3281         local kbtotal=$(calc_osc_kbytes kbytestotal)
3282         local kbfree=$(calc_osc_kbytes kbytesfree)
3283         echo $((kbtotal-kbfree))
3284 }
3285
3286 test_89() {
3287         cancel_lru_locks osc
3288         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3289         rm -f $DIR/$tdir/$tfile
3290         wait_mds_ost_sync || error "initial MDS-OST sync timed out"
3291         wait_delete_completed || error "initial wait delete timed out"
3292         local blocks1=$(calc_osc_kbytes_used)
3293         local write_size=$(fs_log_size)
3294
3295         $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3296         [ $write_size -lt 1024 ] && write_size=1024
3297         dd if=/dev/zero bs=${write_size}k count=10 of=$DIR/$tdir/$tfile
3298         sync
3299         stop ost1
3300         facet_failover $SINGLEMDS
3301         rm $DIR/$tdir/$tfile
3302         umount $MOUNT
3303         mount_facet ost1
3304         zconf_mount $(hostname) $MOUNT || error "mount fails"
3305         client_up || error "client_up failed"
3306
3307         # wait for the remounted client to connect to ost1
3308         local target=$(get_osc_import_name client ost1)
3309         wait_import_state "FULL" "osc.${target}.ost_server_uuid" \
3310                 $(max_recovery_time)
3311
3312         wait_mds_ost_sync || error "MDS-OST sync timed out"
3313         wait_delete_completed || error "wait delete timed out"
3314         local blocks2=$(calc_osc_kbytes_used)
3315
3316         [ $((blocks2 - blocks1)) -le $(fs_log_size)  ] ||
3317                 error $((blocks2 - blocks1)) blocks leaked
3318 }
3319 run_test 89 "no disk space leak on late ost connection"
3320
3321 cleanup_90 () {
3322         local facet=$1
3323
3324         trap 0
3325         reboot_facet $facet
3326         change_active $facet
3327         wait_for_facet $facet
3328         mount_facet $facet || error "Restart of $facet failed"
3329         clients_up
3330 }
3331
3332 test_90() { # bug 19494
3333         local dir=$DIR/$tdir
3334         local ostfail=$(get_random_entry $(get_facets OST))
3335
3336         if [[ $FAILURE_MODE = HARD ]]; then
3337                 local affected=$(affected_facets $ostfail);
3338
3339                 [[ "$affected" == $ostfail ]] ||
3340                         skip "cannot use FAILURE_MODE=$FAILURE_MODE, affected: $affected"
3341         fi
3342         # ensure all OSTs are active to allow allocations
3343         wait_osts_up
3344
3345         mkdir $dir || error "mkdir $dir failed"
3346
3347         echo "Create the files"
3348
3349         # file "f${index}" striped over 1 OST
3350         # file "all" striped over all OSTs
3351
3352         $LFS setstripe -c $OSTCOUNT $dir/all ||
3353                 error "setstripe failed to create $dir/all"
3354
3355         for ((i = 0; i < $OSTCOUNT; i++)); do
3356                 local f=$dir/f$i
3357
3358                 $LFS setstripe -i $i -c 1 $f ||
3359                         error "$LFS setstripe failed to create $f"
3360
3361                 # confirm setstripe actually created stripe on requested OST
3362                 local uuid=$(ostuuid_from_index $i)
3363
3364                 for file in f$i all; do
3365                         local found=$($LFS find --obd $uuid --name $file $dir)
3366
3367                         if [[ $dir/$file != $found ]]; then
3368                                 $LFS getstripe $dir/$file
3369                                 error "wrong stripe: $file, uuid: $uuid"
3370                         fi
3371                 done
3372         done
3373
3374         # Before failing an OST, get its obd name and index
3375         local varsvc=${ostfail}_svc
3376         local obd=$(do_facet $ostfail lctl get_param \
3377                     -n obdfilter.${!varsvc}.uuid)
3378         local index=$(($(facet_number $ostfail) - 1))
3379
3380         echo "Fail $ostfail $obd, display the list of affected files"
3381         shutdown_facet $ostfail || error "shutdown_facet $ostfail failed"
3382
3383         trap "cleanup_90 $ostfail" EXIT INT
3384         echo "General Query: lfs find $dir"
3385         local list=$($LFS find $dir)
3386         echo "$list"
3387         for (( i=0; i<$OSTCOUNT; i++ )); do
3388                 list_member "$list" $dir/f$i ||
3389                         error_noexit "lfs find $dir: no file f$i"
3390         done
3391         list_member "$list" $dir/all ||
3392                 error_noexit "lfs find $dir: no file all"
3393
3394         # focus on the missing OST,
3395         # we expect to see only two files affected: "f$(index)" and "all"
3396
3397         echo "Querying files on shutdown $ostfail: lfs find --obd $obd"
3398     list=$($LFS find --obd $obd $dir)
3399     echo "$list"
3400     for file in all f$index; do
3401         list_member "$list" $dir/$file ||
3402             error_noexit "lfs find does not report the affected $obd for $file"
3403     done
3404
3405     [[ $(echo $list | wc -w) -eq 2 ]] ||
3406         error_noexit "lfs find reports the wrong list of affected files ${#list[@]}"
3407
3408         echo "Check getstripe: $LFS getstripe -r --obd $obd"
3409         list=$($LFS getstripe -r --obd $obd $dir)
3410         echo "$list"
3411     for file in all f$index; do
3412         echo "$list" | grep $dir/$file ||
3413             error_noexit "lfs getsripe does not report the affected $obd for $file"
3414     done
3415
3416     cleanup_90 $ostfail
3417 }
3418 run_test 90 "lfs find identifies the missing striped file segments"
3419
3420 test_93a() {
3421         [[ "$MDS1_VERSION" -ge $(version_code 2.6.90) ]] ||
3422                 [[ "$MDS1_VERSION" -ge $(version_code 2.5.4) &&
3423                    "$MDS1_VERSION" -lt $(version_code 2.5.50) ]] ||
3424                 skip "Need MDS version 2.5.4+ or 2.6.90+"
3425
3426         cancel_lru_locks osc
3427
3428         $LFS setstripe -i 0 -c 1 $DIR/$tfile ||
3429                 error "$LFS setstripe  $DIR/$tfile failed"
3430         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 ||
3431                 error "dd to $DIR/$tfile failed"
3432         #define OBD_FAIL_TGT_REPLAY_RECONNECT     0x715
3433         # We need to emulate a state that OST is waiting for other clients
3434         # not completing the recovery. Final ping is queued, but reply will be
3435         # sent on the recovery completion. It is done by sleep before
3436         # processing final pings
3437         do_facet ost1 "$LCTL set_param fail_val=40"
3438         do_facet ost1 "$LCTL set_param fail_loc=0x715"
3439         fail ost1
3440 }
3441 run_test 93a "replay + reconnect"
3442
3443 test_93b() {
3444         [[ "$MDS1_VERSION" -ge $(version_code 2.7.90) ]] ||
3445                 skip "Need MDS version 2.7.90+"
3446
3447         cancel_lru_locks mdc
3448
3449         createmany -o $DIR/$tfile 20 ||
3450                         error "createmany -o $DIR/$tfile failed"
3451
3452         #define OBD_FAIL_TGT_REPLAY_RECONNECT     0x715
3453         # We need to emulate a state that MDT is waiting for other clients
3454         # not completing the recovery. Final ping is queued, but reply will be
3455         # sent on the recovery completion. It is done by sleep before
3456         # processing final pings
3457         do_facet mds1 "$LCTL set_param fail_val=80"
3458         do_facet mds1 "$LCTL set_param fail_loc=0x715"
3459         fail mds1
3460 }
3461 run_test 93b "replay + reconnect on mds"
3462
3463 striped_dir_check_100() {
3464         local striped_dir=$DIR/$tdir/striped_dir
3465         local stripe_count=$($LFS getdirstripe -c $striped_dir)
3466
3467         $LFS getdirstripe $striped_dir
3468         [ $stripe_count -eq 2 ] || error "$stripe_count != 2"
3469
3470         createmany -o $striped_dir/f-%d 20 ||
3471                 error "creation failed under striped dir"
3472 }
3473
3474 test_100a() {
3475         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3476         ([ $FAILURE_MODE == "HARD" ] &&
3477                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3478                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3479                 return 0
3480
3481         local striped_dir=$DIR/$tdir/striped_dir
3482         local MDTIDX=1
3483
3484         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3485
3486         #To make sure MDT1 and MDT0 are connected
3487         #otherwise it may create single stripe dir here
3488         $LFS setdirstripe -i1 $DIR/$tdir/remote_dir
3489
3490         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
3491         do_facet mds$((MDTIDX+1)) lctl set_param fail_loc=0x1701
3492         $LFS setdirstripe -i0 -c2 $striped_dir &
3493         local CLIENT_PID=$!
3494
3495         fail mds$((MDTIDX + 1))
3496
3497         wait $CLIENT_PID || error "striped dir creation failed"
3498
3499         striped_dir_check_100 || error "striped dir check failed"
3500         rm -rf $DIR/$tdir || error "rmdir failed"
3501 }
3502 run_test 100a "DNE: create striped dir, drop update rep from MDT1, fail MDT1"
3503
3504 test_100b() {
3505         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3506         ([ $FAILURE_MODE == "HARD" ] &&
3507                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3508                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3509                 return 0
3510
3511         local striped_dir=$DIR/$tdir/striped_dir
3512         local MDTIDX=1
3513
3514         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3515
3516         #To make sure MDT1 and MDT0 are connected
3517         #otherwise it may create single stripe dir here
3518         $LFS setdirstripe -i1 $DIR/$tdir/remote_dir
3519
3520         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3521         do_facet mds$MDTIDX lctl set_param fail_loc=0x119
3522         $LFS mkdir -i0 -c2 $striped_dir &
3523
3524         local CLIENT_PID=$!
3525         fail mds$MDTIDX
3526
3527         wait $CLIENT_PID || error "striped dir creation failed"
3528
3529         striped_dir_check_100 || error "striped dir check failed"
3530         rm -rf $DIR/$tdir || error "rmdir failed"
3531 }
3532 run_test 100b "DNE: create striped dir, fail MDT0"
3533
3534 test_100c() {
3535         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3536         ([ $FAILURE_MODE == "HARD" ] &&
3537                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3538                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3539                 return 0
3540
3541         local striped_dir=$DIR/$tdir/striped_dir
3542
3543         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3544
3545         #To make sure MDT1 and MDT0 are connected
3546         #otherwise it may create single stripe dir here
3547         $LFS setdirstripe -i1 $DIR/$tdir/remote_dir
3548
3549         replay_barrier mds2
3550         $LFS mkdir -i1 -c2 $striped_dir
3551
3552         fail_abort mds2 abort_recov_mdt
3553
3554         createmany -o $striped_dir/f-%d 20 &&
3555                         error "createmany -o $DIR/$tfile should fail"
3556
3557         fail mds2
3558         striped_dir_check_100 || error "striped dir check failed"
3559         rm -rf $DIR/$tdir || error "rmdir failed"
3560 }
3561 run_test 100c "DNE: create striped dir, fail MDT0"
3562
3563 test_101() { #LU-5648
3564         mkdir -p $DIR/$tdir/d1
3565         mkdir -p $DIR/$tdir/d2
3566         touch $DIR/$tdir/file0
3567         num=1000
3568
3569         replay_barrier $SINGLEMDS
3570         for i in $(seq $num) ; do
3571                 echo test$i > $DIR/$tdir/d1/file$i
3572         done
3573
3574         fail_abort $SINGLEMDS
3575         for i in $(seq $num) ; do
3576                 touch $DIR/$tdir/d2/file$i
3577                 test -s $DIR/$tdir/d2/file$i &&
3578                         ls -al $DIR/$tdir/d2/file$i && error "file$i's size > 0"
3579         done
3580
3581         rm -rf $DIR/$tdir
3582 }
3583 run_test 101 "Shouldn't reassign precreated objs to other files after recovery"
3584
3585 test_102a() {
3586         local idx
3587         local facet
3588         local num
3589         local i
3590         local pids pid
3591
3592         [[ $(lctl get_param mdc.*.import |
3593              grep "connect_flags:.*multi_mod_rpc") ]] ||
3594                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3595
3596         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3597         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3598         facet="mds$((0x$idx + 1))"
3599
3600         # get current value of max_mod_rcps_in_flight
3601         num=$($LCTL get_param -n \
3602                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3603         # set default value if client does not support multi mod RPCs
3604         [ -z "$num" ] && num=1
3605
3606         echo "creating $num files ..."
3607         umask 0022
3608         for i in $(seq $num); do
3609                 touch $DIR/$tdir/file-$i
3610         done
3611
3612         # drop request on MDT to force resend
3613         #define OBD_FAIL_MDS_REINT_MULTI_NET 0x159
3614         do_facet $facet "$LCTL set_param fail_loc=0x159"
3615         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3616         for i in $(seq $num); do
3617                 chmod 0600 $DIR/$tdir/file-$i &
3618                 pids="$pids $!"
3619         done
3620         sleep 1
3621         do_facet $facet "$LCTL set_param fail_loc=0"
3622         for pid in $pids; do
3623                 wait $pid || error "chmod failed"
3624         done
3625         echo "done ($(date +%H:%M:%S))"
3626
3627         # check chmod succeed
3628         for i in $(seq $num); do
3629                 checkstat -vp 0600 $DIR/$tdir/file-$i
3630         done
3631
3632         rm -rf $DIR/$tdir
3633 }
3634 run_test 102a "check resend (request lost) with multiple modify RPCs in flight"
3635
3636 test_102b() {
3637         local idx
3638         local facet
3639         local num
3640         local i
3641         local pids pid
3642
3643         [[ $(lctl get_param mdc.*.import |
3644              grep "connect_flags:.*multi_mod_rpc") ]] ||
3645                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3646
3647         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3648         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3649         facet="mds$((0x$idx + 1))"
3650
3651         # get current value of max_mod_rcps_in_flight
3652         num=$($LCTL get_param -n \
3653                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3654         # set default value if client does not support multi mod RPCs
3655         [ -z "$num" ] && num=1
3656
3657         echo "creating $num files ..."
3658         umask 0022
3659         for i in $(seq $num); do
3660                 touch $DIR/$tdir/file-$i
3661         done
3662
3663         # drop reply on MDT to force reconstruction
3664         #define OBD_FAIL_MDS_REINT_MULTI_NET_REP 0x15a
3665         do_facet $facet "$LCTL set_param fail_loc=0x15a"
3666         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3667         for i in $(seq $num); do
3668                 chmod 0600 $DIR/$tdir/file-$i &
3669                 pids="$pids $!"
3670         done
3671         sleep 1
3672         do_facet $facet "$LCTL set_param fail_loc=0"
3673         for pid in $pids; do
3674                 wait $pid || error "chmod failed"
3675         done
3676         echo "done ($(date +%H:%M:%S))"
3677
3678         # check chmod succeed
3679         for i in $(seq $num); do
3680                 checkstat -vp 0600 $DIR/$tdir/file-$i
3681         done
3682
3683         rm -rf $DIR/$tdir
3684 }
3685 run_test 102b "check resend (reply lost) with multiple modify RPCs in flight"
3686
3687 test_102c() {
3688         local idx
3689         local facet
3690         local num
3691         local i
3692         local pids pid
3693
3694         [[ $(lctl get_param mdc.*.import |
3695              grep "connect_flags:.*multi_mod_rpc") ]] ||
3696                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3697
3698         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3699         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3700         facet="mds$((0x$idx + 1))"
3701
3702         # get current value of max_mod_rcps_in_flight
3703         num=$($LCTL get_param -n \
3704                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3705         # set default value if client does not support multi mod RPCs
3706         [ -z "$num" ] && num=1
3707
3708         echo "creating $num files ..."
3709         umask 0022
3710         for i in $(seq $num); do
3711                 touch $DIR/$tdir/file-$i
3712         done
3713
3714         replay_barrier $facet
3715
3716         # drop reply on MDT
3717         #define OBD_FAIL_MDS_REINT_MULTI_NET_REP 0x15a
3718         do_facet $facet "$LCTL set_param fail_loc=0x15a"
3719         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3720         for i in $(seq $num); do
3721                 chmod 0600 $DIR/$tdir/file-$i &
3722                 pids="$pids $!"
3723         done
3724         sleep 1
3725         do_facet $facet "$LCTL set_param fail_loc=0"
3726
3727         # fail MDT
3728         fail $facet
3729
3730         for pid in $pids; do
3731                 wait $pid || error "chmod failed"
3732         done
3733         echo "done ($(date +%H:%M:%S))"
3734
3735         # check chmod succeed
3736         for i in $(seq $num); do
3737                 checkstat -vp 0600 $DIR/$tdir/file-$i
3738         done
3739
3740         rm -rf $DIR/$tdir
3741 }
3742 run_test 102c "check replay w/o reconstruction with multiple mod RPCs in flight"
3743
3744 test_102d() {
3745         local idx
3746         local facet
3747         local num
3748         local i
3749         local pids pid
3750
3751         [[ $(lctl get_param mdc.*.import |
3752              grep "connect_flags:.*multi_mod_rpc") ]] ||
3753                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3754
3755         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3756         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3757         facet="mds$((0x$idx + 1))"
3758
3759         # get current value of max_mod_rcps_in_flight
3760         num=$($LCTL get_param -n \
3761                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3762         # set default value if client does not support multi mod RPCs
3763         [ -z "$num" ] && num=1
3764
3765         echo "creating $num files ..."
3766         umask 0022
3767         for i in $(seq $num); do
3768                 touch $DIR/$tdir/file-$i
3769         done
3770
3771         # drop reply on MDT
3772         #define OBD_FAIL_MDS_REINT_MULTI_NET_REP 0x15a
3773         do_facet $facet "$LCTL set_param fail_loc=0x15a"
3774         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3775         for i in $(seq $num); do
3776                 chmod 0600 $DIR/$tdir/file-$i &
3777                 pids="$pids $!"
3778         done
3779         sleep 1
3780
3781         # write MDT transactions to disk
3782         do_facet $facet "sync; sync; sync"
3783
3784         do_facet $facet "$LCTL set_param fail_loc=0"
3785
3786         # fail MDT
3787         fail $facet
3788
3789         for pid in $pids; do
3790                 wait $pid || error "chmod failed"
3791         done
3792         echo "done ($(date +%H:%M:%S))"
3793
3794         # check chmod succeed
3795         for i in $(seq $num); do
3796                 checkstat -vp 0600 $DIR/$tdir/file-$i
3797         done
3798
3799         rm -rf $DIR/$tdir
3800 }
3801 run_test 102d "check replay & reconstruction with multiple mod RPCs in flight"
3802
3803 test_103() {
3804         remote_mds_nodsh && skip "remote MDS with nodsh"
3805         [[ "$MDS1_VERSION" -gt $(version_code 2.8.54) ]] ||
3806                 skip "Need MDS version 2.8.54+"
3807
3808 #define OBD_FAIL_MDS_TRACK_OVERFLOW 0x162
3809         do_facet mds1 $LCTL set_param fail_loc=0x80000162
3810
3811         mkdir -p $DIR/$tdir
3812         createmany -o $DIR/$tdir/t- 30 ||
3813                 error "create files on remote directory failed"
3814         sync
3815         rm -rf $DIR/$tdir/t-*
3816         sync
3817 #MDS should crash with tr->otr_next_id overflow
3818         fail mds1
3819 }
3820 run_test 103 "Check otr_next_id overflow"
3821
3822
3823 check_striped_dir_110()
3824 {
3825         $CHECKSTAT -t dir $DIR/$tdir/striped_dir ||
3826                         error "create striped dir failed"
3827         local stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
3828         [ $stripe_count -eq $MDSCOUNT ] ||
3829                 error "$stripe_count != 2 after recovery"
3830 }
3831
3832 test_110a() {
3833         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3834         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
3835                 skip "Need MDS version at least 2.7.56"
3836
3837         ([ $FAILURE_MODE == "HARD" ] &&
3838                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3839                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3840                 return 0
3841
3842         mkdir -p $DIR/$tdir
3843         replay_barrier mds1
3844         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3845         fail mds1
3846
3847         check_striped_dir_110 || error "check striped_dir failed"
3848         rm -rf $DIR/$tdir || error "rmdir failed"
3849
3850         return 0
3851 }
3852 run_test 110a "DNE: create striped dir, fail MDT1"
3853
3854 test_110b() {
3855         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3856         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
3857                 skip "Need MDS version at least 2.7.56"
3858
3859         ([ $FAILURE_MODE == "HARD" ] &&
3860                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3861                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3862                 return 0
3863
3864         mkdir -p $DIR/$tdir
3865         replay_barrier mds1
3866         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3867         umount $MOUNT
3868         fail mds1
3869         zconf_mount $(hostname) $MOUNT
3870         client_up || return 1
3871
3872         check_striped_dir_110 || error "check striped_dir failed"
3873
3874         rm -rf $DIR/$tdir || error "rmdir failed"
3875
3876         return 0
3877 }
3878 run_test 110b "DNE: create striped dir, fail MDT1 and client"
3879
3880 test_110c() {
3881         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3882         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
3883                 skip "Need MDS version at least 2.7.56"
3884
3885         ([ $FAILURE_MODE == "HARD" ] &&
3886                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3887                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3888                 return 0
3889
3890         mkdir -p $DIR/$tdir
3891         replay_barrier mds2
3892         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3893         fail mds2
3894
3895         check_striped_dir_110 || error "check striped_dir failed"
3896
3897         rm -rf $DIR/$tdir || error "rmdir failed"
3898
3899         return 0
3900 }
3901 run_test 110c "DNE: create striped dir, fail MDT2"
3902
3903 test_110d() {
3904         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3905         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
3906                 skip "Need MDS version at least 2.7.56"
3907
3908         ([ $FAILURE_MODE == "HARD" ] &&
3909                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3910                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3911                 return 0
3912
3913         mkdir -p $DIR/$tdir
3914         replay_barrier mds2
3915         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3916         umount $MOUNT
3917         fail mds2
3918         zconf_mount $(hostname) $MOUNT
3919         client_up || return 1
3920
3921         check_striped_dir_110 || error "check striped_dir failed"
3922
3923         rm -rf $DIR/$tdir || error "rmdir failed"
3924
3925         return 0
3926 }
3927 run_test 110d "DNE: create striped dir, fail MDT2 and client"
3928
3929 test_110e() {
3930         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3931         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
3932                 skip "Need MDS version at least 2.7.56"
3933
3934         ([ $FAILURE_MODE == "HARD" ] &&
3935                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3936                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3937                 return 0
3938
3939         mkdir -p $DIR/$tdir
3940         replay_barrier mds2
3941         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3942         umount $MOUNT
3943         replay_barrier mds1
3944         fail mds1,mds2
3945         zconf_mount $(hostname) $MOUNT
3946         client_up || return 1
3947
3948         check_striped_dir_110 || error "check striped_dir failed"
3949
3950         rm -rf $DIR/$tdir || error "rmdir failed"
3951
3952         return 0
3953 }
3954 run_test 110e "DNE: create striped dir, uncommit on MDT2, fail client/MDT1/MDT2"
3955
3956 test_110f() {
3957         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3958         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
3959                 skip "Need MDS version at least 2.7.56"
3960
3961         ([ $FAILURE_MODE == "HARD" ] &&
3962                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3963                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3964                 return 0
3965
3966         mkdir -p $DIR/$tdir
3967         replay_barrier mds1
3968         replay_barrier mds2
3969         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3970         fail mds2,mds1
3971
3972         check_striped_dir_110 || error "check striped_dir failed"
3973
3974         rm -rf $DIR/$tdir || error "rmdir failed"
3975
3976         return 0
3977 }
3978 run_test 110f "DNE: create striped dir, fail MDT1/MDT2"
3979
3980 test_110g() {
3981         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3982         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
3983                 skip "Need MDS version at least 2.7.56"
3984
3985         ([ $FAILURE_MODE == "HARD" ] &&
3986                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3987                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3988                 return 0
3989
3990         mkdir -p $DIR/$tdir
3991         replay_barrier mds1
3992         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3993         umount $MOUNT
3994         replay_barrier mds2
3995         fail mds1,mds2
3996         zconf_mount $(hostname) $MOUNT
3997         client_up || return 1
3998
3999         check_striped_dir_110 || error "check striped_dir failed"
4000
4001         rm -rf $DIR/$tdir || error "rmdir failed"
4002
4003         return 0
4004 }
4005 run_test 110g "DNE: create striped dir, uncommit on MDT1, fail client/MDT1/MDT2"
4006
4007 test_111a() {
4008         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4009         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4010                 skip "Need MDS version at least 2.7.56"
4011
4012         ([ $FAILURE_MODE == "HARD" ] &&
4013                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4014                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4015                 return 0
4016
4017         mkdir -p $DIR/$tdir
4018         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4019         replay_barrier mds1
4020         rm -rf $DIR/$tdir/striped_dir
4021         fail mds1
4022
4023         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4024                         error "striped dir still exists"
4025         return 0
4026 }
4027 run_test 111a "DNE: unlink striped dir, fail MDT1"
4028
4029 test_111b() {
4030         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4031         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4032                 skip "Need MDS version at least 2.7.56"
4033
4034         ([ $FAILURE_MODE == "HARD" ] &&
4035                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4036                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4037                 return 0
4038
4039         mkdir -p $DIR/$tdir
4040         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4041         replay_barrier mds2
4042         rm -rf $DIR/$tdir/striped_dir
4043         umount $MOUNT
4044         fail mds2
4045         zconf_mount $(hostname) $MOUNT
4046         client_up || return 1
4047
4048         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4049                         error "striped dir still exists"
4050         return 0
4051 }
4052 run_test 111b "DNE: unlink striped dir, fail MDT2"
4053
4054 test_111c() {
4055         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4056         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4057                 skip "Need MDS version at least 2.7.56"
4058
4059         ([ $FAILURE_MODE == "HARD" ] &&
4060                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4061                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4062                 return 0
4063
4064         mkdir -p $DIR/$tdir
4065         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4066         replay_barrier mds1
4067         rm -rf $DIR/$tdir/striped_dir
4068         umount $MOUNT
4069         replay_barrier mds2
4070         fail mds1,mds2
4071         zconf_mount $(hostname) $MOUNT
4072         client_up || return 1
4073         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4074                         error "striped dir still exists"
4075         return 0
4076 }
4077 run_test 111c "DNE: unlink striped dir, uncommit on MDT1, fail client/MDT1/MDT2"
4078
4079 test_111d() {
4080         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4081         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4082                 skip "Need MDS version at least 2.7.56"
4083
4084         ([ $FAILURE_MODE == "HARD" ] &&
4085                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4086                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4087                 return 0
4088
4089         mkdir -p $DIR/$tdir
4090         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4091         replay_barrier mds2
4092         rm -rf $DIR/$tdir/striped_dir
4093         umount $MOUNT
4094         replay_barrier mds1
4095         fail mds1,mds2
4096         zconf_mount $(hostname) $MOUNT
4097         client_up || return 1
4098         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4099                         error "striped dir still exists"
4100
4101         return 0
4102 }
4103 run_test 111d "DNE: unlink striped dir, uncommit on MDT2, fail client/MDT1/MDT2"
4104
4105 test_111e() {
4106         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4107         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4108                 skip "Need MDS version at least 2.7.56"
4109
4110         ([ $FAILURE_MODE == "HARD" ] &&
4111                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4112                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4113                 return 0
4114
4115         mkdir -p $DIR/$tdir
4116         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4117         replay_barrier mds2
4118         rm -rf $DIR/$tdir/striped_dir
4119         replay_barrier mds1
4120         fail mds1,mds2
4121         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4122                         error "striped dir still exists"
4123         return 0
4124 }
4125 run_test 111e "DNE: unlink striped dir, uncommit on MDT2, fail MDT1/MDT2"
4126
4127 test_111f() {
4128         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4129         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4130                 skip "Need MDS version at least 2.7.56"
4131
4132         ([ $FAILURE_MODE == "HARD" ] &&
4133                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4134                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4135                 return 0
4136
4137         mkdir -p $DIR/$tdir
4138         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4139         replay_barrier mds1
4140         rm -rf $DIR/$tdir/striped_dir
4141         replay_barrier mds2
4142         fail mds1,mds2
4143         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4144                         error "striped dir still exists"
4145         return 0
4146 }
4147 run_test 111f "DNE: unlink striped dir, uncommit on MDT1, fail MDT1/MDT2"
4148
4149 test_111g() {
4150         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4151         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4152                 skip "Need MDS version at least 2.7.56"
4153
4154         ([ $FAILURE_MODE == "HARD" ] &&
4155                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4156                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4157                 return 0
4158
4159         mkdir -p $DIR/$tdir
4160         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4161         replay_barrier mds1
4162         replay_barrier mds2
4163         rm -rf $DIR/$tdir/striped_dir
4164         fail mds1,mds2
4165         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4166                         error "striped dir still exists"
4167         return 0
4168 }
4169 run_test 111g "DNE: unlink striped dir, fail MDT1/MDT2"
4170
4171 test_112_rename_prepare() {
4172         mkdir_on_mdt0 $DIR/$tdir
4173         mkdir -p $DIR/$tdir/src_dir
4174         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
4175                 error "create remote source failed"
4176
4177         touch $DIR/$tdir/src_dir/src_child/a
4178
4179         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
4180                 error "create remote target dir failed"
4181
4182         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
4183                 error "create remote target child failed"
4184 }
4185
4186 test_112_check() {
4187         find $DIR/$tdir/
4188         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
4189                 error "src_child still exists after rename"
4190
4191         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
4192                 error "missing file(a) after rename"
4193 }
4194
4195 test_112a() {
4196         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4197         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4198                 skip "Need MDS version at least 2.7.56"
4199
4200         ([ $FAILURE_MODE == "HARD" ] &&
4201                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4202                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4203                 return 0
4204
4205         test_112_rename_prepare
4206         replay_barrier mds1
4207
4208         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4209                 error "rename dir cross MDT failed!"
4210         fail mds1
4211
4212         test_112_check
4213         rm -rf $DIR/$tdir || error "rmdir failed"
4214 }
4215 run_test 112a "DNE: cross MDT rename, fail MDT1"
4216
4217 test_112b() {
4218         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4219         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4220                 skip "Need MDS version at least 2.7.56"
4221
4222         ([ $FAILURE_MODE == "HARD" ] &&
4223                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4224                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4225                 return 0
4226
4227         test_112_rename_prepare
4228         replay_barrier mds2
4229
4230         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4231                 error "rename dir cross MDT failed!"
4232
4233         fail mds2
4234
4235         test_112_check
4236         rm -rf $DIR/$tdir || error "rmdir failed"
4237 }
4238 run_test 112b "DNE: cross MDT rename, fail MDT2"
4239
4240 test_112c() {
4241         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4242         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4243                 skip "Need MDS version at least 2.7.56"
4244
4245         ([ $FAILURE_MODE == "HARD" ] &&
4246                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4247                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4248                 return 0
4249
4250         test_112_rename_prepare
4251         replay_barrier mds3
4252
4253         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4254                 error "rename dir cross MDT failed!"
4255
4256         fail mds3
4257
4258         test_112_check
4259         rm -rf $DIR/$tdir || error "rmdir failed"
4260 }
4261 run_test 112c "DNE: cross MDT rename, fail MDT3"
4262
4263 test_112d() {
4264         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4265         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4266                 skip "Need MDS version at least 2.7.56"
4267
4268         ([ $FAILURE_MODE == "HARD" ] &&
4269                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4270                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4271                 return 0
4272
4273         test_112_rename_prepare
4274         replay_barrier mds4
4275
4276         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4277                 error "rename dir cross MDT failed!"
4278
4279         fail mds4
4280
4281         test_112_check
4282         rm -rf $DIR/$tdir || error "rmdir failed"
4283 }
4284 run_test 112d "DNE: cross MDT rename, fail MDT4"
4285
4286 test_112e() {
4287         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4288         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4289                 skip "Need MDS version at least 2.7.56"
4290
4291         ([ $FAILURE_MODE == "HARD" ] &&
4292                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4293                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4294                 return 0
4295
4296         test_112_rename_prepare
4297         replay_barrier mds1
4298         replay_barrier mds2
4299
4300         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4301                 error "rename dir cross MDT failed!"
4302
4303         fail mds1,mds2
4304
4305         test_112_check
4306         rm -rf $DIR/$tdir || error "rmdir failed"
4307 }
4308 run_test 112e "DNE: cross MDT rename, fail MDT1 and MDT2"
4309
4310 test_112f() {
4311         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4312         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4313                 skip "Need MDS version at least 2.7.56"
4314
4315         ([ $FAILURE_MODE == "HARD" ] &&
4316                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4317                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4318                 return 0
4319
4320         test_112_rename_prepare
4321         replay_barrier mds1
4322         replay_barrier mds3
4323
4324         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4325                 error "rename dir cross MDT failed!"
4326
4327         fail mds1,mds3
4328
4329         test_112_check
4330         rm -rf $DIR/$tdir || error "rmdir failed"
4331 }
4332 run_test 112f "DNE: cross MDT rename, fail MDT1 and MDT3"
4333
4334 test_112g() {
4335         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4336         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4337                 skip "Need MDS version at least 2.7.56"
4338
4339         ([ $FAILURE_MODE == "HARD" ] &&
4340                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4341                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4342                 return 0
4343
4344         test_112_rename_prepare
4345         replay_barrier mds1
4346         replay_barrier mds4
4347
4348         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4349                 error "rename dir cross MDT failed!"
4350
4351         fail mds1,mds4
4352
4353         test_112_check
4354         rm -rf $DIR/$tdir || error "rmdir failed"
4355 }
4356 run_test 112g "DNE: cross MDT rename, fail MDT1 and MDT4"
4357
4358 test_112h() {
4359         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4360         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4361                 skip "Need MDS version at least 2.7.56"
4362
4363         ([ $FAILURE_MODE == "HARD" ] &&
4364                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4365                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4366                 return 0
4367
4368         test_112_rename_prepare
4369         replay_barrier mds2
4370         replay_barrier mds3
4371
4372         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4373                 error "rename dir cross MDT failed!"
4374
4375         fail mds2,mds3
4376
4377         test_112_check
4378         rm -rf $DIR/$tdir || error "rmdir failed"
4379 }
4380 run_test 112h "DNE: cross MDT rename, fail MDT2 and MDT3"
4381
4382 test_112i() {
4383         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4384         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4385                 skip "Need MDS version at least 2.7.56"
4386
4387         ([ $FAILURE_MODE == "HARD" ] &&
4388                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4389                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4390                 return 0
4391
4392         test_112_rename_prepare
4393         replay_barrier mds2
4394         replay_barrier mds4
4395
4396         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4397                 error "rename dir cross MDT failed!"
4398
4399         fail mds2,mds4
4400
4401         test_112_check
4402         rm -rf $DIR/$tdir || error "rmdir failed"
4403 }
4404 run_test 112i "DNE: cross MDT rename, fail MDT2 and MDT4"
4405
4406 test_112j() {
4407         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4408         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4409                 skip "Need MDS version at least 2.7.56"
4410
4411         ([ $FAILURE_MODE == "HARD" ] &&
4412                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4413                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4414                 return 0
4415
4416         test_112_rename_prepare
4417         replay_barrier mds3
4418         replay_barrier mds4
4419
4420         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4421                 error "rename dir cross MDT failed!"
4422
4423         fail mds3,mds4
4424
4425         test_112_check
4426         rm -rf $DIR/$tdir || error "rmdir failed"
4427 }
4428 run_test 112j "DNE: cross MDT rename, fail MDT3 and MDT4"
4429
4430 test_112k() {
4431         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4432         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4433                 skip "Need MDS version at least 2.7.56"
4434
4435         ([ $FAILURE_MODE == "HARD" ] &&
4436                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4437                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4438                 return 0
4439
4440         test_112_rename_prepare
4441         replay_barrier mds1
4442         replay_barrier mds2
4443         replay_barrier mds3
4444
4445         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4446                 error "rename dir cross MDT failed!"
4447
4448         fail mds1,mds2,mds3
4449
4450         test_112_check
4451         rm -rf $DIR/$tdir || error "rmdir failed"
4452 }
4453 run_test 112k "DNE: cross MDT rename, fail MDT1,MDT2,MDT3"
4454
4455 test_112l() {
4456         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4457         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4458                 skip "Need MDS version at least 2.7.56"
4459
4460         ([ $FAILURE_MODE == "HARD" ] &&
4461                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4462                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4463                 return 0
4464
4465         test_112_rename_prepare
4466         replay_barrier mds1
4467         replay_barrier mds2
4468         replay_barrier mds4
4469
4470         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4471                 error "rename dir cross MDT failed!"
4472
4473         fail mds1,mds2,mds4
4474
4475         test_112_check
4476         rm -rf $DIR/$tdir || error "rmdir failed"
4477 }
4478 run_test 112l "DNE: cross MDT rename, fail MDT1,MDT2,MDT4"
4479
4480 test_112m() {
4481         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4482         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4483                 skip "Need MDS version at least 2.7.56"
4484
4485         ([ $FAILURE_MODE == "HARD" ] &&
4486                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4487                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4488                 return 0
4489
4490         test_112_rename_prepare
4491         replay_barrier mds1
4492         replay_barrier mds3
4493         replay_barrier mds4
4494
4495         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4496                 error "rename dir cross MDT failed!"
4497
4498         fail mds1,mds3,mds4
4499
4500         test_112_check
4501         rm -rf $DIR/$tdir || error "rmdir failed"
4502 }
4503 run_test 112m "DNE: cross MDT rename, fail MDT1,MDT3,MDT4"
4504
4505 test_112n() {
4506         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4507         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4508                 skip "Need MDS version at least 2.7.56"
4509
4510         ([ $FAILURE_MODE == "HARD" ] &&
4511                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4512                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4513                 return 0
4514
4515         test_112_rename_prepare
4516         replay_barrier mds2
4517         replay_barrier mds3
4518         replay_barrier mds4
4519
4520         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4521                 error "rename dir cross MDT failed!"
4522
4523         fail mds2,mds3,mds4
4524
4525         test_112_check
4526         rm -rf $DIR/$tdir || error "rmdir failed"
4527 }
4528 run_test 112n "DNE: cross MDT rename, fail MDT2,MDT3,MDT4"
4529
4530 test_115() {
4531         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4532         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
4533                 skip "Need MDS version at least 2.7.56"
4534
4535         ([ $FAILURE_MODE == "HARD" ] &&
4536                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4537                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4538                 return 0
4539         local fail_index=0
4540         local index
4541         local i
4542         local j
4543
4544         mkdir -p $DIR/$tdir
4545         for ((j=0;j<$((MDSCOUNT));j++)); do
4546                 fail_index=$((fail_index+1))
4547                 index=$((fail_index % MDSCOUNT))
4548                 replay_barrier mds$((index + 1))
4549                 for ((i=0;i<5;i++)); do
4550                         test_mkdir -i$index -c$MDSCOUNT $DIR/$tdir/test_$i ||
4551                                 error "create striped dir $DIR/$tdir/test_$i"
4552                 done
4553
4554                 fail mds$((index + 1))
4555                 for ((i=0;i<5;i++)); do
4556                         checkstat -t dir $DIR/$tdir/test_$i ||
4557                                 error "$DIR/$tdir/test_$i does not exist!"
4558                 done
4559                 rm -rf $DIR/$tdir/test_* ||
4560                                 error "rmdir fails"
4561         done
4562 }
4563 run_test 115 "failover for create/unlink striped directory"
4564
4565 test_116a() {
4566         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4567         [ "$MDS1_VERSION" -lt $(version_code 2.7.55) ] &&
4568                 skip "Do not support large update log before 2.7.55" &&
4569                 return 0
4570         ([ $FAILURE_MODE == "HARD" ] &&
4571                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4572                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4573                 return 0
4574         local fail_index=0
4575
4576         mkdir_on_mdt0 $DIR/$tdir
4577         replay_barrier mds1
4578
4579         # OBD_FAIL_SPLIT_UPDATE_REC       0x1702
4580         do_facet mds1 "lctl set_param fail_loc=0x80001702"
4581         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
4582
4583         fail mds1
4584         $CHECKSTAT -t dir $DIR/$tdir/striped_dir ||
4585                 error "stried_dir does not exists"
4586 }
4587 run_test 116a "large update log master MDT recovery"
4588
4589 test_116b() {
4590         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4591         [ "$MDS1_VERSION" -lt $(version_code 2.7.55) ] &&
4592                 skip "Do not support large update log before 2.7.55" &&
4593                 return 0
4594
4595         ([ $FAILURE_MODE == "HARD" ] &&
4596                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4597                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4598                 return 0
4599         local fail_index=0
4600
4601         mkdir_on_mdt0 $DIR/$tdir
4602         replay_barrier mds2
4603
4604         # OBD_FAIL_SPLIT_UPDATE_REC       0x1702
4605         do_facet mds2 "lctl set_param fail_loc=0x80001702"
4606         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
4607
4608         fail mds2
4609         $CHECKSTAT -t dir $DIR/$tdir/striped_dir ||
4610                 error "stried_dir does not exists"
4611 }
4612 run_test 116b "large update log slave MDT recovery"
4613
4614 test_117() {
4615         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4616         ([ $FAILURE_MODE == "HARD" ] &&
4617                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4618                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4619                 return 0
4620         local index
4621         local mds_indexs
4622
4623         mkdir -p $DIR/$tdir
4624         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/remote_dir
4625         $LFS setdirstripe -i1 -c$MDSCOUNT $DIR/$tdir/remote_dir_1
4626         sleep 2
4627
4628         # Let's set rdonly on all MDTs, so client will send
4629         # replay requests on all MDTs and replay these requests
4630         # at the same time. This test will verify the recovery
4631         # will not be deadlock in this case, LU-7531.
4632         for ((index = 0; index < $((MDSCOUNT)); index++)); do
4633                 replay_barrier mds$((index + 1))
4634                 if [ -z $mds_indexs ]; then
4635                         mds_indexs="${mds_indexs}mds$((index+1))"
4636                 else
4637                         mds_indexs="${mds_indexs},mds$((index+1))"
4638                 fi
4639         done
4640
4641         rm -rf $DIR/$tdir/remote_dir
4642         rm -rf $DIR/$tdir/remote_dir_1
4643
4644         fail $mds_indexs
4645
4646         rm -rf $DIR/$tdir || error "rmdir failed"
4647 }
4648 run_test 117 "DNE: cross MDT unlink, fail MDT1 and MDT2"
4649
4650 test_118() {
4651         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4652         [ "$MDS1_VERSION" -lt $(version_code 2.7.64) ] &&
4653                 skip "Do not support large update log before 2.7.64" &&
4654                 return 0
4655
4656         mkdir -p $DIR/$tdir
4657
4658         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
4659                 error "setdirstripe fails"
4660         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir1 ||
4661                 error "setdirstripe fails 1"
4662         rm -rf $DIR/$tdir/striped_dir* || error "rmdir fails"
4663
4664         # OBD_FAIL_INVALIDATE_UPDATE       0x1705
4665         do_facet mds1 "lctl set_param fail_loc=0x1705"
4666         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir
4667         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir1
4668         do_facet mds1 "lctl set_param fail_loc=0x0"
4669
4670         replay_barrier mds1
4671         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir
4672         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir1
4673         fail mds1
4674
4675         true
4676 }
4677 run_test 118 "invalidate osp update will not cause update log corruption"
4678
4679 test_119() {
4680         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4681         [ "$MDS1_VERSION" -lt $(version_code 2.7.64) ] &&
4682                 skip "Do not support large update log before 2.7.64" &&
4683                 return 0
4684         local stripe_count
4685         local hard_timeout=$(do_facet mds1 \
4686                 "lctl get_param -n mdt.$FSNAME-MDT0000.recovery_time_hard")
4687
4688         local clients=${CLIENTS:-$HOSTNAME}
4689         local time_min=$(recovery_time_min)
4690
4691         mkdir_on_mdt0 $DIR/$tdir
4692         mkdir $DIR/$tdir/tmp
4693         rmdir $DIR/$tdir/tmp
4694
4695         replay_barrier mds1
4696         mkdir $DIR/$tdir/dir_1
4697         for ((i = 0; i < 20; i++)); do
4698                 $LFS setdirstripe -i0 -c2 $DIR/$tdir/stripe_dir-$i
4699         done
4700
4701         stop mds1
4702         change_active mds1
4703         wait_for_facet mds1
4704
4705         #define OBD_FAIL_TGT_REPLAY_DELAY  0x714
4706         do_facet mds1 $LCTL set_param fail_loc=0x80000714
4707         #sleep (timeout + 5), so mds will evict the client exports,
4708         #but DNE update recovery will keep going.
4709         do_facet mds1 $LCTL set_param fail_val=$((time_min + 5))
4710
4711         mount_facet mds1 "-o recovery_time_hard=$time_min"
4712
4713         wait_clients_import_state "$clients" mds1 FULL
4714
4715         clients_up || clients_up || error "failover df: $?"
4716
4717         #revert back the hard timeout
4718         do_facet mds1 $LCTL set_param \
4719                 mdt.$FSNAME-MDT0000.recovery_time_hard=$hard_timeout
4720
4721         for ((i = 0; i < 20; i++)); do
4722                 stripe_count=$($LFS getdirstripe -c $DIR/$tdir/stripe_dir-$i)
4723                 [ $stripe_count == 2 ] || {
4724                         error "stripe_dir-$i creation replay fails"
4725                         break
4726                 }
4727         done
4728 }
4729 run_test 119 "timeout of normal replay does not cause DNE replay fails  "
4730
4731 test_120() {
4732         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4733         [ "$MDS1_VERSION" -lt $(version_code 2.7.64) ] &&
4734                 skip "Do not support large update log before 2.7.64" &&
4735                 return 0
4736
4737         mkdir_on_mdt0 $DIR/$tdir
4738         replay_barrier_nosync mds1
4739         for ((i = 0; i < 20; i++)); do
4740                 mkdir $DIR/$tdir/dir-$i || {
4741                         error "create dir-$i fails"
4742                         break
4743                 }
4744                 $LFS setdirstripe -i0 -c2 $DIR/$tdir/stripe_dir-$i || {
4745                         error "create stripe_dir-$i fails"
4746                         break
4747                 }
4748         done
4749
4750         fail_abort mds1
4751
4752         for ((i = 0; i < 20; i++)); do
4753                 [ ! -e "$DIR/$tdir/dir-$i" ] || {
4754                         error "dir-$i still exists"
4755                         break
4756                 }
4757                 [ ! -e "$DIR/$tdir/stripe_dir-$i" ] || {
4758                         error "stripe_dir-$i still exists"
4759                         break
4760                 }
4761         done
4762 }
4763 run_test 120 "DNE fail abort should stop both normal and DNE replay"
4764
4765 test_121() {
4766         [ "$MDS1_VERSION" -lt $(version_code 2.10.90) ] &&
4767                 skip "Don't support it before 2.11" &&
4768                 return 0
4769
4770         local at_max_saved=$(at_max_get mds)
4771
4772         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4773         cancel_lru_locks mdc
4774
4775         multiop_bg_pause $DIR/$tfile s_s || error "multiop $DIR/$tfile failed"
4776         mpid=$!
4777
4778         lctl set_param -n ldlm.cancel_unused_locks_before_replay "0"
4779
4780         stop mds1
4781         change_active mds1
4782         wait_for_facet mds1
4783
4784         #define OBD_FAIL_TGT_RECOVERY_REQ_RACE  0x721
4785         do_facet $SINGLEMDS "lctl set_param fail_loc=0x721 fail_val=0"
4786         at_max_set 0 mds
4787
4788         mount_facet mds1
4789         wait_clients_import_state "$clients" mds1 FULL
4790         clients_up || clients_up || error "failover df: $?"
4791
4792         kill -USR1 $mpid
4793         wait $mpid || error "multiop_bg_pause pid failed"
4794
4795         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
4796         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
4797         at_max_set $at_max_saved mds
4798         rm -f $DIR/$tfile
4799 }
4800 run_test 121 "lock replay timed out and race"
4801
4802 test_130a() {
4803         [ "$MDS1_VERSION" -lt $(version_code 2.10.90) ] &&
4804                 skip "Do not support Data-on-MDT before 2.11"
4805
4806         replay_barrier $SINGLEMDS
4807         $LFS setstripe -E 1M -L mdt -E EOF -c 2 $DIR/$tfile
4808         fail $SINGLEMDS
4809
4810         [ $($LFS getstripe -L $DIR/$tfile) == "mdt" ] ||
4811                 error "Fail to replay DoM file creation"
4812 }
4813 run_test 130a "DoM file create (setstripe) replay"
4814
4815 test_130b() {
4816         [ "$MDS1_VERSION" -lt $(version_code 2.10.90) ] &&
4817                 skip "Do not support Data-on-MDT before 2.11"
4818
4819         mkdir_on_mdt0 $DIR/$tdir
4820         $LFS setstripe -E 1M -L mdt -E EOF -c 2 $DIR/$tdir
4821         replay_barrier $SINGLEMDS
4822         touch $DIR/$tdir/$tfile
4823         fail $SINGLEMDS
4824
4825         [ $($LFS getstripe -L $DIR/$tdir/$tfile) == "mdt" ] ||
4826                 error "Fail to replay DoM file creation"
4827 }
4828 run_test 130b "DoM file create (inherited) replay"
4829
4830 test_131a() {
4831         [ "$MDS1_VERSION" -lt $(version_code 2.10.90) ] &&
4832                 skip "Do not support Data-on-MDT before 2.11"
4833
4834         $LFS setstripe -E 1M -L mdt -E EOF -c 2 $DIR/$tfile
4835         replay_barrier $SINGLEMDS
4836         echo "dom_data" | dd of=$DIR/$tfile bs=8 count=1
4837         # lock is not canceled and will be replayed
4838         fail $SINGLEMDS
4839
4840         [ $(cat $DIR/$tfile) == "dom_data" ] ||
4841                 error "Wrong file content after failover"
4842 }
4843 run_test 131a "DoM file write lock replay"
4844
4845 test_131b() {
4846         [ "$MDS1_VERSION" -lt $(version_code 2.10.90) ] &&
4847                 skip "Do not support Data-on-MDT before 2.11"
4848
4849         $LFS setstripe -E 1M -L mdt -E EOF -c 2 $DIR/$tfile
4850         replay_barrier $SINGLEMDS
4851         echo "dom_data" | dd of=$DIR/$tfile bs=8 count=1
4852         cancel_lru_locks mdc
4853
4854         fail $SINGLEMDS
4855
4856         [ $(cat $DIR/$tfile) == "dom_data" ] ||
4857                 error "Wrong file content after failover"
4858 }
4859 run_test 131b "DoM file write replay"
4860
4861 test_132a() {
4862         [ "$MDS1_VERSION" -lt $(version_code 2.12.0) ] &&
4863                 skip "Need MDS version 2.12.0 or later"
4864
4865         $LFS setstripe -E 1M -c 1 -E EOF -c 2 $DIR/$tfile
4866         replay_barrier $SINGLEMDS
4867         # write over the first component size cause next component instantiation
4868         dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 seek=1 ||
4869                 error "dd to $DIR/$tfile failed"
4870         lfs getstripe $DIR/$tfile
4871
4872         cksum=$(md5sum $DIR/$tfile | awk '{print $1}')
4873         $LFS getstripe -I2 $DIR/$tfile | grep -q lmm_objects ||
4874                 error "Component #1 was not instantiated"
4875
4876         fail $SINGLEMDS
4877
4878         lfs getstripe $DIR/$tfile
4879         $LFS getstripe -I2 $DIR/$tfile | grep -q lmm_objects ||
4880                 error "Component #1 instantiation was not replayed"
4881         cksum2=$(md5sum $DIR/$tfile | awk '{print $1}')
4882         if [ $cksum != $cksum2 ] ; then
4883                 error_noexit "New cksum $cksum2 does not match original $cksum"
4884         fi
4885 }
4886 run_test 132a "PFL new component instantiate replay"
4887
4888 test_133() {
4889         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4890         ([ $FAILURE_MODE == "HARD" ] &&
4891                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4892                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4893                 return 0
4894
4895         local remote_dir=$DIR/$tdir/remote_dir
4896
4897         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4898         $LFS mkdir -i 1 $remote_dir
4899
4900         umount $MOUNT
4901         do_facet mds2 $LCTL set_param seq.srv*MDT0001.space=clear
4902
4903         zconf_mount $(hostname) $MOUNT
4904         client_up || return 1
4905
4906         #define OBD_FAIL_MDS_ALL_REQUEST_NET     0x123
4907         # SEQ_QUERY                       = 700
4908         do_facet mds1 $LCTL set_param fail_val=700 fail_loc=0x80000123
4909         cp /etc/hosts $remote_dir/file &
4910         local pid=$!
4911         sleep 1
4912
4913         fail_nodf mds1
4914
4915         wait $pid || error "cp failed"
4916         rm -rf $DIR/$tdir || error "rmdir failed"
4917
4918         return 0
4919 }
4920 run_test 133 "check resend of ongoing requests for lwp during failover"
4921
4922 test_134() {
4923         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return 0
4924
4925         pool_add pool_134
4926         pool_add_targets pool_134 1 1
4927
4928         mkdir -p $DIR/$tdir/{A,B}
4929         $LFS setstripe -p pool_134 $DIR/$tdir/A
4930         $LFS setstripe -E EOF -p pool_134 $DIR/$tdir/B
4931
4932         replay_barrier mds1
4933
4934         touch $DIR/$tdir/A/$tfile || error "touch non-pfl file failed"
4935         touch $DIR/$tdir/B/$tfile || error "touch pfl failed"
4936
4937         fail mds1
4938
4939         [ -f $DIR/$tdir/A/$tfile ] || error "non-pfl file does not exist"
4940         [ -f $DIR/$tdir/B/$tfile ] || error "pfl file does not exist"
4941 }
4942 run_test 134 "replay creation of a file created in a pool"
4943
4944 # LU-14027
4945 test_135() {
4946         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4947
4948         # All files to ost1
4949         $LFS setstripe -S $((128 * 1024)) -i 0 $DIR/$tdir
4950
4951         replay_barrier ost1
4952
4953         # Create 20 files so we have 20 ost locks
4954         for i in $(seq 20) ; do
4955                 echo blah > $DIR/$tdir/file.${i}
4956         done
4957
4958         shutdown_facet ost1
4959         reboot_facet ost1
4960         change_active ost1
4961         wait_for_facet ost1
4962
4963         #define OBD_FAIL_TGT_REPLAY_RECONNECT     0x32d
4964         # Make sure lock replay server side never completes and errors out.
4965         do_facet ost1 "$LCTL set_param fail_val=20"
4966         do_facet ost1 "$LCTL set_param fail_loc=0x32d"
4967
4968         mount_facet ost1
4969
4970         # Now make sure we notice
4971         (sync;sync;sync) &
4972         local PID=$?
4973         sleep 20 # should we do something proactive to make reconnects go?
4974         kill -0 $PID || error "Unexpected sync success"
4975
4976         shutdown_facet ost1
4977         reboot_facet ost1
4978         change_active ost1
4979         wait_for_facet ost1
4980
4981         do_facet ost1 "$LCTL set_param fail_loc=0"
4982         mount_facet ost1
4983         echo blah > $DIR/$tdir/file.test2
4984
4985         rm -rf $DIR/$tdir
4986 }
4987 run_test 135 "Server failure in lock replay phase"
4988
4989 complete $SECONDS
4990 check_and_cleanup_lustre
4991 exit_status