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