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