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