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