Whamcloud - gitweb
LU-12040 mdc: reset lmm->lmm_stripe_offset in mdc_save_lovea
[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         $LFS 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         $LFS setstripe --stripe-index=0 --stripe-count=1 $DIR/$tfile ||
1860                 error "$LFS 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         $LFS setstripe --stripe-index=0 --stripe-count=1 $DIR/$tfile ||
1873                 error "$LFS 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         osc.$mdtosc.prealloc_last_id)
1972     local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1973         osc.$mdtosc.prealloc_next_id)
1974
1975         mkdir -p $DIR/$tdir/${OST} || error "mkdir $DIR/$tdir/${OST} failed"
1976         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${OST} ||
1977                 error "$LFS setstripe failed"
1978         echo "Creating to objid $last_id on ost $OST..."
1979 #define OBD_FAIL_OST_PAUSE_CREATE        0x223
1980     do_facet ost1 "$LCTL set_param fail_val=20000"
1981     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1982     createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1983
1984     client_reconnect
1985     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1986     log "phase 2"
1987     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1988     ATTEMPTS=$(($CONN2 - $CONN1))
1989     echo "$ATTEMPTS osc reconnect attempts on instant slow"
1990     # do it again; should not timeout
1991     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1992     cp /etc/profile $DIR/$tfile || error "cp failed"
1993     do_facet ost1 "$LCTL set_param fail_loc=0"
1994     client_reconnect
1995     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1996     CONN3=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1997     ATTEMPTS=$(($CONN3 - $CONN2))
1998     echo "$ATTEMPTS osc reconnect attempts on 2nd slow"
1999     [ $ATTEMPTS -gt 0 ] && error "AT should have prevented reconnect"
2000     return 0
2001 }
2002 run_test 67b "AT: verify instant slowdown doesn't induce reconnects"
2003
2004 test_68 () #bug 13813
2005 {
2006     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
2007
2008     at_start || return 0
2009     local ldlm_enqueue_min=$(find /sys -name ldlm_enqueue_min)
2010     [ -z "$ldlm_enqueue_min" ] && skip "missing /sys/.../ldlm_enqueue_min" && return 0
2011     local ldlm_enqueue_min_r=$(do_facet ost1 "find /sys -name ldlm_enqueue_min")
2012     [ -z "$ldlm_enqueue_min_r" ] && skip "missing /sys/.../ldlm_enqueue_min in the ost1" && return 0
2013     local ENQ_MIN=$(cat $ldlm_enqueue_min)
2014     local ENQ_MIN_R=$(do_facet ost1 "cat $ldlm_enqueue_min_r")
2015         echo $TIMEOUT >> $ldlm_enqueue_min
2016         do_facet ost1 "echo $TIMEOUT >> $ldlm_enqueue_min_r"
2017
2018         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2019         $LFS setstripe --stripe-index=0 -c 1 $DIR/$tdir ||
2020                 error "$LFS setstripe failed for $DIR/$tdir"
2021         #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
2022         $LCTL set_param fail_val=$(($TIMEOUT - 1))
2023         $LCTL set_param fail_loc=0x80000312
2024         cp /etc/profile $DIR/$tdir/${tfile}_1 || error "1st cp failed $?"
2025         $LCTL set_param fail_val=$((TIMEOUT * 5 / 4))
2026         $LCTL set_param fail_loc=0x80000312
2027         cp /etc/profile $DIR/$tdir/${tfile}_2 || error "2nd cp failed $?"
2028         $LCTL set_param fail_loc=0
2029
2030         echo $ENQ_MIN >> $ldlm_enqueue_min
2031         do_facet ost1 "echo $ENQ_MIN_R >> $ldlm_enqueue_min_r"
2032         rm -rf $DIR/$tdir
2033         return 0
2034 }
2035 run_test 68 "AT: verify slowing locks"
2036
2037 at_cleanup
2038 # end of AT tests includes above lines
2039
2040 # start multi-client tests
2041 test_70a () {
2042         [ -z "$CLIENTS" ] &&
2043                 { skip "Need two or more clients." && return; }
2044         [ $CLIENTCOUNT -lt 2 ] &&
2045                 { skip "Need two or more clients, have $CLIENTCOUNT" && return; }
2046
2047         echo "mount clients $CLIENTS ..."
2048         zconf_mount_clients $CLIENTS $MOUNT
2049
2050         local clients=${CLIENTS//,/ }
2051         echo "Write/read files on $DIR ; clients $CLIENTS ... "
2052         for CLIENT in $clients; do
2053                 do_node $CLIENT dd bs=1M count=10 if=/dev/zero \
2054                         of=$DIR/${tfile}_${CLIENT} 2>/dev/null ||
2055                                 error "dd failed on $CLIENT"
2056         done
2057
2058         local prev_client=$(echo $clients | sed 's/^.* \(.\+\)$/\1/')
2059         for C in ${CLIENTS//,/ }; do
2060                 do_node $prev_client dd if=$DIR/${tfile}_${C} \
2061                         of=/dev/null 2>/dev/null ||
2062                         error "dd if=$DIR/${tfile}_${C} failed on $prev_client"
2063                 prev_client=$C
2064         done
2065
2066         ls $DIR
2067 }
2068 run_test 70a "check multi client t-f"
2069
2070 check_for_process () {
2071         local clients=$1
2072         shift
2073         local prog=$@
2074
2075         killall_process $clients "$prog" -0
2076 }
2077
2078 test_70b () {
2079         local clients=${CLIENTS:-$HOSTNAME}
2080
2081         zconf_mount_clients $clients $MOUNT
2082
2083         local duration=300
2084         [ "$SLOW" = "no" ] && duration=120
2085         # set duration to 900 because it takes some time to boot node
2086         [ "$FAILURE_MODE" = HARD ] && duration=900
2087
2088         local elapsed
2089         local start_ts=$(date +%s)
2090         local cmd="rundbench 1 -t $duration"
2091         local pid=""
2092         if [ $MDSCOUNT -ge 2 ]; then
2093                 test_mkdir -p -c$MDSCOUNT $DIR/$tdir
2094                 $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
2095         fi
2096         do_nodesv $clients "set -x; MISSING_DBENCH_OK=$MISSING_DBENCH_OK \
2097                 PATH=\$PATH:$LUSTRE/utils:$LUSTRE/tests/:$DBENCH_LIB \
2098                 DBENCH_LIB=$DBENCH_LIB TESTSUITE=$TESTSUITE TESTNAME=$TESTNAME \
2099                 MOUNT=$MOUNT DIR=$DIR/$tdir/\\\$(hostname) LCTL=$LCTL $cmd" &
2100         pid=$!
2101
2102         #LU-1897 wait for all dbench copies to start
2103         while ! check_for_process $clients dbench; do
2104                 elapsed=$(($(date +%s) - start_ts))
2105                 if [ $elapsed -gt $duration ]; then
2106                         killall_process $clients dbench
2107                         error "dbench failed to start on $clients!"
2108                 fi
2109                 sleep 1
2110         done
2111
2112         log "Started rundbench load pid=$pid ..."
2113
2114         elapsed=$(($(date +%s) - start_ts))
2115         local num_failovers=0
2116         local fail_index=1
2117         while [ $elapsed -lt $duration ]; do
2118                 if ! check_for_process $clients dbench; then
2119                         error_noexit "dbench stopped on some of $clients!"
2120                         killall_process $clients dbench
2121                         break
2122                 fi
2123                 sleep 1
2124                 replay_barrier mds$fail_index
2125                 sleep 1 # give clients a time to do operations
2126                 # Increment the number of failovers
2127                 num_failovers=$((num_failovers+1))
2128                 log "$TESTNAME fail mds$fail_index $num_failovers times"
2129                 fail mds$fail_index
2130                 elapsed=$(($(date +%s) - start_ts))
2131                 if [ $fail_index -ge $MDSCOUNT ]; then
2132                         fail_index=1
2133                 else
2134                         fail_index=$((fail_index+1))
2135                 fi
2136         done
2137
2138         wait $pid || error "rundbench load on $clients failed!"
2139 }
2140 run_test 70b "dbench ${MDSCOUNT}mdts recovery; $CLIENTCOUNT clients"
2141 # end multi-client tests
2142
2143 random_fail_mdt() {
2144         local max_index=$1
2145         local duration=$2
2146         local monitor_pid=$3
2147         local elapsed
2148         local start_ts=$(date +%s)
2149         local num_failovers=0
2150         local fail_index
2151
2152         elapsed=$(($(date +%s) - start_ts))
2153         while [ $elapsed -lt $duration ]; do
2154                 fail_index=$((RANDOM%max_index+1))
2155                 kill -0 $monitor_pid ||
2156                         error "$monitor_pid stopped"
2157                 sleep 120
2158                 replay_barrier mds$fail_index
2159                 sleep 10
2160                 # Increment the number of failovers
2161                 num_failovers=$((num_failovers+1))
2162                 log "$TESTNAME fail mds$fail_index $num_failovers times"
2163                 fail mds$fail_index
2164                 elapsed=$(($(date +%s) - start_ts))
2165         done
2166 }
2167
2168 cleanup_70c() {
2169         trap 0
2170         rm -f $DIR/replay-single.70c.lck
2171         rm -rf /$DIR/$tdir
2172 }
2173
2174 test_70c () {
2175         local clients=${CLIENTS:-$HOSTNAME}
2176         local rc=0
2177
2178         zconf_mount_clients $clients $MOUNT
2179
2180         local duration=300
2181         [ "$SLOW" = "no" ] && duration=180
2182         # set duration to 900 because it takes some time to boot node
2183         [ "$FAILURE_MODE" = HARD ] && duration=600
2184
2185         local elapsed
2186         local start_ts=$(date +%s)
2187
2188         trap cleanup_70c EXIT
2189         (
2190                 while [ ! -e $DIR/replay-single.70c.lck ]; do
2191                         test_mkdir -p -c$MDSCOUNT $DIR/$tdir || break
2192                         if [ $MDSCOUNT -ge 2 ]; then
2193                                 $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir ||
2194                                 error "set default dirstripe failed"
2195                         fi
2196                         cd $DIR/$tdir || break
2197                         tar cf - /etc | tar xf - || error "tar failed in loop"
2198                 done
2199         )&
2200         tar_70c_pid=$!
2201         echo "Started tar $tar_70c_pid"
2202
2203         random_fail_mdt $MDSCOUNT $duration $tar_70c_pid
2204         kill -0 $tar_70c_pid || error "tar $tar_70c_pid stopped"
2205
2206         touch $DIR/replay-single.70c.lck
2207         wait $tar_70c_pid || error "$?: tar failed"
2208
2209         cleanup_70c
2210         true
2211 }
2212 run_test 70c "tar ${MDSCOUNT}mdts recovery"
2213
2214 cleanup_70d() {
2215         trap 0
2216         kill -9 $mkdir_70d_pid
2217 }
2218
2219 test_70d () {
2220         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2221         local clients=${CLIENTS:-$HOSTNAME}
2222         local rc=0
2223
2224         zconf_mount_clients $clients $MOUNT
2225
2226         local duration=300
2227         [ "$SLOW" = "no" ] && duration=180
2228         # set duration to 900 because it takes some time to boot node
2229         [ "$FAILURE_MODE" = HARD ] && duration=900
2230
2231         mkdir -p $DIR/$tdir
2232
2233         local elapsed
2234         local start_ts=$(date +%s)
2235
2236         trap cleanup_70d EXIT
2237         (
2238                 while true; do
2239                         $LFS mkdir -i0 -c2 $DIR/$tdir/test || {
2240                                 echo "mkdir fails"
2241                                 break
2242                         }
2243                         $LFS mkdir -i1 -c2 $DIR/$tdir/test1 || {
2244                                 echo "mkdir fails"
2245                                 break
2246                         }
2247
2248                         touch $DIR/$tdir/test/a || {
2249                                 echo "touch fails"
2250                                 break;
2251                         }
2252                         mkdir $DIR/$tdir/test/b || {
2253                                 echo "mkdir fails"
2254                                 break;
2255                         }
2256                         rm -rf $DIR/$tdir/test || {
2257                                 echo "rmdir fails"
2258                                 ls -lR $DIR/$tdir
2259                                 break
2260                         }
2261
2262                         touch $DIR/$tdir/test1/a || {
2263                                 echo "touch fails"
2264                                 break;
2265                         }
2266                         mkdir $DIR/$tdir/test1/b || {
2267                                 echo "mkdir fails"
2268                                 break;
2269                         }
2270
2271                         rm -rf $DIR/$tdir/test1 || {
2272                                 echo "rmdir fails"
2273                                 ls -lR $DIR/$tdir/test1
2274                                 break
2275                         }
2276                 done
2277         )&
2278         mkdir_70d_pid=$!
2279         echo "Started  $mkdir_70d_pid"
2280
2281         random_fail_mdt $MDSCOUNT $duration $mkdir_70d_pid
2282         kill -0 $mkdir_70d_pid || error "mkdir/rmdir $mkdir_70d_pid stopped"
2283
2284         cleanup_70d
2285         true
2286 }
2287 run_test 70d "mkdir/rmdir striped dir ${MDSCOUNT}mdts recovery"
2288
2289 test_70e () {
2290         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2291         local clients=${CLIENTS:-$HOSTNAME}
2292         local rc=0
2293
2294         lctl set_param debug=+ha
2295         zconf_mount_clients $clients $MOUNT
2296
2297         local duration=300
2298         [ "$SLOW" = "no" ] && duration=180
2299         # set duration to 900 because it takes some time to boot node
2300         [ "$FAILURE_MODE" = HARD ] && duration=900
2301
2302         mkdir -p $DIR/$tdir
2303         $LFS mkdir -i0 $DIR/$tdir/test_0
2304         $LFS mkdir -i0 $DIR/$tdir/test_1
2305         touch $DIR/$tdir/test_0/a
2306         touch $DIR/$tdir/test_1/b
2307         (
2308         while true; do
2309                 mrename $DIR/$tdir/test_0/a $DIR/$tdir/test_1/b > /dev/null || {
2310                         echo "a->b fails"
2311                         break;
2312                 }
2313
2314                 checkstat $DIR/$tdir/test_0/a && {
2315                         echo "a still exists"
2316                         break
2317                 }
2318
2319                 checkstat $DIR/$tdir/test_1/b || {
2320                         echo "b still  exists"
2321                         break
2322                 }
2323
2324                 touch $DIR/$tdir/test_0/a || {
2325                         echo "touch a fails"
2326                         break
2327                 }
2328
2329                 mrename $DIR/$tdir/test_1/b $DIR/$tdir/test_0/a > /dev/null || {
2330                         echo "a->a fails"
2331                         break;
2332                 }
2333         done
2334         )&
2335         rename_70e_pid=$!
2336         stack_trap "kill -9 $rename_70e_pid" EXIT
2337         echo "Started PID=$rename_70e_pid"
2338
2339         random_fail_mdt 2 $duration $rename_70e_pid
2340         kill -0 $rename_70e_pid || error "rename $rename_70e_pid stopped"
2341 }
2342 run_test 70e "rename cross-MDT with random fails"
2343
2344 test_70f_write_and_read(){
2345         local srcfile=$1
2346         local stopflag=$2
2347         local client
2348
2349         echo "Write/read files in: '$DIR/$tdir', clients: '$CLIENTS' ..."
2350         for client in ${CLIENTS//,/ }; do
2351                 [ -f $stopflag ] || return
2352
2353                 local tgtfile=$DIR/$tdir/$tfile.$client
2354                 do_node $client dd $DD_OPTS bs=1M count=10 if=$srcfile \
2355                         of=$tgtfile 2>/dev/null ||
2356                         error "dd $DD_OPTS bs=1M count=10 if=$srcfile " \
2357                               "of=$tgtfile failed on $client, rc=$?"
2358         done
2359
2360         local prev_client=$(echo ${CLIENTS//,/ } | awk '{ print $NF }')
2361         local index=0
2362
2363         for client in ${CLIENTS//,/ }; do
2364                 [ -f $stopflag ] || return
2365
2366                 # flush client cache in case test is running on only one client
2367                 # do_node $client cancel_lru_locks osc
2368                 do_node $client $LCTL set_param ldlm.namespaces.*.lru_size=clear
2369
2370                 tgtfile=$DIR/$tdir/$tfile.$client
2371                 local md5=$(do_node $prev_client "md5sum $tgtfile")
2372                 [ ${checksum[$index]// */} = ${md5// */} ] ||
2373                         error "$tgtfile: checksum doesn't match on $prev_client"
2374                 index=$((index + 1))
2375                 prev_client=$client
2376         done
2377 }
2378
2379 test_70f_loop(){
2380         local srcfile=$1
2381         local stopflag=$2
2382         DD_OPTS=
2383
2384         mkdir -p $DIR/$tdir || error "cannot create $DIR/$tdir directory"
2385         $LFS setstripe -c -1 $DIR/$tdir ||
2386                 error "cannot $LFS setstripe $DIR/$tdir"
2387
2388         touch $stopflag
2389         while [ -f $stopflag ]; do
2390                 test_70f_write_and_read $srcfile $stopflag
2391                 # use direct IO and buffer cache in turns if loop
2392                 [ -n "$DD_OPTS" ] && DD_OPTS="" || DD_OPTS="oflag=direct"
2393         done
2394 }
2395
2396 test_70f_cleanup() {
2397         trap 0
2398         rm -f $TMP/$tfile.stop
2399         do_nodes $CLIENTS rm -f $TMP/$tfile
2400         rm -f $DIR/$tdir/$tfile.*
2401 }
2402
2403 test_70f() {
2404 #       [ x$ost1failover_HOST = x$ost_HOST ] &&
2405 #               { skip "Failover host not defined" && return; }
2406 #       [ -z "$CLIENTS" ] &&
2407 #               { skip "CLIENTS are not specified." && return; }
2408 #       [ $CLIENTCOUNT -lt 2 ] &&
2409 #               { skip "Need 2 or more clients, have $CLIENTCOUNT" && return; }
2410
2411         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.53) ]] &&
2412                 skip "Need server version at least 2.9.53" && return
2413
2414         echo "mount clients $CLIENTS ..."
2415         zconf_mount_clients $CLIENTS $MOUNT
2416
2417         local srcfile=$TMP/$tfile
2418         local client
2419         local index=0
2420
2421         trap test_70f_cleanup EXIT
2422         # create a different source file local to each client node so we can
2423         # detect if the file wasn't written out properly after failover
2424         do_nodes $CLIENTS dd bs=1M count=10 if=/dev/urandom of=$srcfile \
2425                 2>/dev/null || error "can't create $srcfile on $CLIENTS"
2426         for client in ${CLIENTS//,/ }; do
2427                 checksum[$index]=$(do_node $client "md5sum $srcfile")
2428                 index=$((index + 1))
2429         done
2430
2431         local duration=120
2432         [ "$SLOW" = "no" ] && duration=60
2433         # set duration to 900 because it takes some time to boot node
2434         [ "$FAILURE_MODE" = HARD ] && duration=900
2435
2436         local stopflag=$TMP/$tfile.stop
2437         test_70f_loop $srcfile $stopflag &
2438         local pid=$!
2439
2440         local elapsed=0
2441         local num_failovers=0
2442         local start_ts=$SECONDS
2443         while [ $elapsed -lt $duration ]; do
2444                 sleep 3
2445                 replay_barrier ost1
2446                 sleep 1
2447                 num_failovers=$((num_failovers + 1))
2448                 log "$TESTNAME failing OST $num_failovers times"
2449                 fail ost1
2450                 sleep 2
2451                 elapsed=$((SECONDS - start_ts))
2452         done
2453
2454         rm -f $stopflag
2455         wait $pid
2456         test_70f_cleanup
2457 }
2458 run_test 70f "OSS O_DIRECT recovery with $CLIENTCOUNT clients"
2459
2460 cleanup_71a() {
2461         trap 0
2462         kill -9 $mkdir_71a_pid
2463 }
2464
2465 random_double_fail_mdt() {
2466         local max_index=$1
2467         local duration=$2
2468         local monitor_pid=$3
2469         local elapsed
2470         local start_ts=$(date +%s)
2471         local num_failovers=0
2472         local fail_index
2473         local second_index
2474
2475         elapsed=$(($(date +%s) - start_ts))
2476         while [ $elapsed -lt $duration ]; do
2477                 fail_index=$((RANDOM%max_index + 1))
2478                 if [ $fail_index -eq $max_index ]; then
2479                         second_index=1
2480                 else
2481                         second_index=$((fail_index + 1))
2482                 fi
2483                 kill -0 $monitor_pid ||
2484                         error "$monitor_pid stopped"
2485                 sleep 120
2486                 replay_barrier mds$fail_index
2487                 replay_barrier mds$second_index
2488                 sleep 10
2489                 # Increment the number of failovers
2490                 num_failovers=$((num_failovers+1))
2491                 log "fail mds$fail_index mds$second_index $num_failovers times"
2492                 fail mds${fail_index},mds${second_index}
2493                 elapsed=$(($(date +%s) - start_ts))
2494         done
2495 }
2496
2497 test_71a () {
2498         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2499         local clients=${CLIENTS:-$HOSTNAME}
2500         local rc=0
2501
2502         zconf_mount_clients $clients $MOUNT
2503
2504         local duration=300
2505         [ "$SLOW" = "no" ] && duration=180
2506         # set duration to 900 because it takes some time to boot node
2507         [ "$FAILURE_MODE" = HARD ] && duration=900
2508
2509         mkdir -p $DIR/$tdir
2510
2511         local elapsed
2512         local start_ts=$(date +%s)
2513
2514         trap cleanup_71a EXIT
2515         (
2516                 while true; do
2517                         $LFS mkdir -i0 -c2 $DIR/$tdir/test
2518                         rmdir $DIR/$tdir/test
2519                 done
2520         )&
2521         mkdir_71a_pid=$!
2522         echo "Started  $mkdir_71a_pid"
2523
2524         random_double_fail_mdt 2 $duration $mkdir_71a_pid
2525         kill -0 $mkdir_71a_pid || error "mkdir/rmdir $mkdir_71a_pid stopped"
2526
2527         cleanup_71a
2528         true
2529 }
2530 run_test 71a "mkdir/rmdir striped dir with 2 mdts recovery"
2531
2532 test_73a() {
2533         multiop_bg_pause $DIR/$tfile O_tSc ||
2534                 error "multiop_bg_pause $DIR/$tfile failed"
2535         pid=$!
2536         rm -f $DIR/$tfile
2537
2538         replay_barrier $SINGLEMDS
2539         #define OBD_FAIL_LDLM_ENQUEUE_NET                       0x302
2540         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000302"
2541         fail $SINGLEMDS
2542         kill -USR1 $pid
2543         wait $pid || error "multiop pid failed"
2544         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
2545         return 0
2546 }
2547 run_test 73a "open(O_CREAT), unlink, replay, reconnect before open replay, close"
2548
2549 test_73b() {
2550         multiop_bg_pause $DIR/$tfile O_tSc ||
2551                 error "multiop_bg_pause $DIR/$tfile failed"
2552         pid=$!
2553         rm -f $DIR/$tfile
2554
2555         replay_barrier $SINGLEMDS
2556         #define OBD_FAIL_MDS_LDLM_REPLY_NET       0x157
2557         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000157"
2558         fail $SINGLEMDS
2559         kill -USR1 $pid
2560         wait $pid || error "multiop pid failed"
2561         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
2562         return 0
2563 }
2564 run_test 73b "open(O_CREAT), unlink, replay, reconnect at open_replay reply, close"
2565
2566 # bug 18554
2567 test_74() {
2568         local clients=${CLIENTS:-$HOSTNAME}
2569
2570         zconf_umount_clients $clients $MOUNT
2571         stop ost1
2572         facet_failover $SINGLEMDS
2573         zconf_mount_clients $clients $MOUNT
2574         mount_facet ost1
2575         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2576         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
2577         clients_up || error "client evicted: $?"
2578         return 0
2579 }
2580 run_test 74 "Ensure applications don't fail waiting for OST recovery"
2581
2582 remote_dir_check_80() {
2583         local mdtidx=1
2584         local diridx
2585         local fileidx
2586
2587         diridx=$($LFS getstripe -m $remote_dir) ||
2588                 error "$LFS getstripe -m $remote_dir failed"
2589         [ $diridx -eq $mdtidx ] || error "$diridx != $mdtidx"
2590
2591         createmany -o $remote_dir/f-%d 20 || error "creation failed"
2592         fileidx=$($LFS getstripe -m $remote_dir/f-1) ||
2593                 error "$LFS getstripe -m $remote_dir/f-1 failed"
2594         [ $fileidx -eq $mdtidx ] || error "$fileidx != $mdtidx"
2595
2596         return 0
2597 }
2598
2599 test_80a() {
2600         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2601         ([ $FAILURE_MODE == "HARD" ] &&
2602                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2603                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2604                 return 0
2605
2606         local MDTIDX=1
2607         local remote_dir=$DIR/$tdir/remote_dir
2608
2609         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2610         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2611         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2612         $LFS mkdir -i $MDTIDX $remote_dir &
2613         local CLIENT_PID=$!
2614
2615         replay_barrier mds1
2616         fail mds${MDTIDX}
2617
2618         wait $CLIENT_PID || error "remote creation failed"
2619
2620         remote_dir_check_80 || error "remote dir check failed"
2621         rm -rf $DIR/$tdir || error "rmdir failed"
2622
2623         return 0
2624 }
2625 run_test 80a "DNE: create remote dir, drop update rep from MDT0, fail MDT0"
2626
2627 test_80b() {
2628         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2629         ([ $FAILURE_MODE == "HARD" ] &&
2630                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2631                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2632                 return 0
2633
2634         local MDTIDX=1
2635         local remote_dir=$DIR/$tdir/remote_dir
2636
2637         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2638         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2639         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2640         $LFS mkdir -i $MDTIDX $remote_dir &
2641         local CLIENT_PID=$!
2642
2643         replay_barrier mds1
2644         replay_barrier mds2
2645         fail mds$((MDTIDX + 1))
2646
2647         wait $CLIENT_PID || error "remote creation failed"
2648
2649         remote_dir_check_80 || error "remote dir check failed"
2650         rm -rf $DIR/$tdir || error "rmdir failed"
2651
2652         return 0
2653 }
2654 run_test 80b "DNE: create remote dir, drop update rep from MDT0, fail MDT1"
2655
2656 test_80c() {
2657         [[ $mds1_FSTYPE = "zfs" ]] &&
2658                 [[ $MDS1_VERSION -lt $(version_code 2.12.51) ]] &&
2659                 skip "requires LU-10143 fix on MDS"
2660         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2661         ([ $FAILURE_MODE == "HARD" ] &&
2662                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2663                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2664                 return 0
2665
2666         local MDTIDX=1
2667         local remote_dir=$DIR/$tdir/remote_dir
2668
2669         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2670         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2671         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2672         $LFS mkdir -i $MDTIDX $remote_dir &
2673         local CLIENT_PID=$!
2674
2675         replay_barrier mds1
2676         replay_barrier mds2
2677         fail mds${MDTIDX}
2678         fail mds$((MDTIDX + 1))
2679
2680         wait $CLIENT_PID || error "remote creation failed"
2681
2682         remote_dir_check_80 || error "remote dir check failed"
2683         rm -rf $DIR/$tdir || error "rmdir failed"
2684
2685         return 0
2686 }
2687 run_test 80c "DNE: create remote dir, drop update rep from MDT1, fail MDT[0,1]"
2688
2689 test_80d() {
2690         [[ $mds1_FSTYPE = "zfs" ]] &&
2691                 [[ $MDS1_VERSION -lt $(version_code 2.12.51) ]] &&
2692                 skip "requires LU-10143 fix on MDS"
2693         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2694         local MDTIDX=1
2695         local remote_dir=$DIR/$tdir/remote_dir
2696
2697         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2698         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2699         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2700         $LFS mkdir -i $MDTIDX $remote_dir &
2701         local CLIENT_PID=$!
2702
2703         # sleep 3 seconds to make sure MDTs are failed after
2704         # lfs mkdir -i has finished on all of MDTs.
2705         sleep 3
2706
2707         replay_barrier mds1
2708         replay_barrier mds2
2709         fail mds${MDTIDX},mds$((MDTIDX + 1))
2710
2711         wait $CLIENT_PID || error "remote creation failed"
2712
2713         remote_dir_check_80 || error "remote dir check failed"
2714         rm -rf $DIR/$tdir || error "rmdir failed"
2715
2716         return 0
2717 }
2718 run_test 80d "DNE: create remote dir, drop update rep from MDT1, fail 2 MDTs"
2719
2720 test_80e() {
2721         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2722         ([ $FAILURE_MODE == "HARD" ] &&
2723                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2724                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2725                 return 0
2726
2727         local MDTIDX=1
2728         local remote_dir=$DIR/$tdir/remote_dir
2729
2730         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2731         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2732         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2733         $LFS mkdir -i $MDTIDX $remote_dir &
2734         local CLIENT_PID=$!
2735
2736         # sleep 3 seconds to make sure MDTs are failed after
2737         # lfs mkdir -i has finished on all of MDTs.
2738         sleep 3
2739
2740         replay_barrier mds1
2741         fail mds${MDTIDX}
2742
2743         wait $CLIENT_PID || error "remote creation failed"
2744
2745         remote_dir_check_80 || error "remote dir check failed"
2746         rm -rf $DIR/$tdir || error "rmdir failed"
2747
2748         return 0
2749 }
2750 run_test 80e "DNE: create remote dir, drop MDT1 rep, fail MDT0"
2751
2752 test_80f() {
2753         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2754         ([ $FAILURE_MODE == "HARD" ] &&
2755                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2756                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2757                 return 0
2758         local MDTIDX=1
2759         local remote_dir=$DIR/$tdir/remote_dir
2760
2761         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2762         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2763         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2764         $LFS mkdir -i $MDTIDX $remote_dir &
2765         local CLIENT_PID=$!
2766
2767         replay_barrier mds2
2768         fail mds$((MDTIDX + 1))
2769
2770         wait $CLIENT_PID || error "remote creation failed"
2771
2772         remote_dir_check_80 || error "remote dir check failed"
2773         rm -rf $DIR/$tdir || error "rmdir failed"
2774
2775         return 0
2776 }
2777 run_test 80f "DNE: create remote dir, drop MDT1 rep, fail MDT1"
2778
2779 test_80g() {
2780         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2781         ([ $FAILURE_MODE == "HARD" ] &&
2782                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2783                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2784                 return 0
2785
2786         local MDTIDX=1
2787         local remote_dir=$DIR/$tdir/remote_dir
2788
2789         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2790         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2791         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2792         $LFS mkdir -i $MDTIDX $remote_dir &
2793         local CLIENT_PID=$!
2794
2795         # sleep 3 seconds to make sure MDTs are failed after
2796         # lfs mkdir -i has finished on all of MDTs.
2797         sleep 3
2798
2799         replay_barrier mds1
2800         replay_barrier mds2
2801         fail mds${MDTIDX}
2802         fail mds$((MDTIDX + 1))
2803
2804         wait $CLIENT_PID || error "remote creation failed"
2805
2806         remote_dir_check_80 || error "remote dir check failed"
2807         rm -rf $DIR/$tdir || error "rmdir failed"
2808
2809         return 0
2810 }
2811 run_test 80g "DNE: create remote dir, drop MDT1 rep, fail MDT0, then MDT1"
2812
2813 test_80h() {
2814         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2815         local MDTIDX=1
2816         local remote_dir=$DIR/$tdir/remote_dir
2817
2818         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2819         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2820         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2821         $LFS mkdir -i $MDTIDX $remote_dir &
2822         local CLIENT_PID=$!
2823
2824         # sleep 3 seconds to make sure MDTs are failed after
2825         # lfs mkdir -i has finished on all of MDTs.
2826         sleep 3
2827
2828         replay_barrier mds1
2829         replay_barrier mds2
2830         fail mds${MDTIDX},mds$((MDTIDX + 1))
2831
2832         wait $CLIENT_PID || error "remote dir creation failed"
2833
2834         remote_dir_check_80 || error "remote dir check failed"
2835         rm -rf $DIR/$tdir || error "rmdir failed"
2836
2837         return 0
2838 }
2839 run_test 80h "DNE: create remote dir, drop MDT1 rep, fail 2 MDTs"
2840
2841 test_81a() {
2842         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2843         ([ $FAILURE_MODE == "HARD" ] &&
2844                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2845                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2846                 return 0
2847
2848         local MDTIDX=1
2849         local remote_dir=$DIR/$tdir/remote_dir
2850
2851         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2852         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2853
2854         touch $remote_dir || error "touch $remote_dir failed"
2855         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2856         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2857         rmdir $remote_dir &
2858         local CLIENT_PID=$!
2859
2860         replay_barrier mds2
2861         fail mds$((MDTIDX + 1))
2862
2863         wait $CLIENT_PID || error "rm remote dir failed"
2864
2865         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2866
2867         rm -rf $DIR/$tdir || error "rmdir failed"
2868
2869         return 0
2870 }
2871 run_test 81a "DNE: unlink remote dir, drop MDT0 update rep,  fail MDT1"
2872
2873 test_81b() {
2874         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2875         ([ $FAILURE_MODE == "HARD" ] &&
2876                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2877                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2878                 return 0
2879         local MDTIDX=1
2880         local remote_dir=$DIR/$tdir/remote_dir
2881
2882         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2883         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2884
2885         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2886         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2887         rmdir $remote_dir &
2888         local CLIENT_PID=$!
2889
2890         replay_barrier mds1
2891         fail mds${MDTIDX}
2892
2893         wait $CLIENT_PID || error "rm remote dir failed"
2894
2895         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2896
2897         rm -rf $DIR/$tdir || error "rmdir failed"
2898
2899         return 0
2900 }
2901 run_test 81b "DNE: unlink remote dir, drop MDT0 update reply,  fail MDT0"
2902
2903 test_81c() {
2904         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2905         ([ $FAILURE_MODE == "HARD" ] &&
2906                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2907                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2908                 return 0
2909
2910         local MDTIDX=1
2911         local remote_dir=$DIR/$tdir/remote_dir
2912
2913         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2914         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2915
2916         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2917         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2918         rmdir $remote_dir &
2919         local CLIENT_PID=$!
2920
2921         replay_barrier mds1
2922         replay_barrier mds2
2923         fail mds${MDTIDX}
2924         fail mds$((MDTIDX + 1))
2925
2926         wait $CLIENT_PID || error "rm remote dir failed"
2927
2928         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2929
2930         rm -rf $DIR/$tdir || error "rmdir failed"
2931
2932         return 0
2933 }
2934 run_test 81c "DNE: unlink remote dir, drop MDT0 update reply, fail MDT0,MDT1"
2935
2936 test_81d() {
2937         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2938         local MDTIDX=1
2939         local remote_dir=$DIR/$tdir/remote_dir
2940
2941         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2942         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2943
2944         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2945         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2946         rmdir $remote_dir &
2947         local CLIENT_PID=$!
2948
2949         replay_barrier mds1
2950         replay_barrier mds2
2951         fail mds${MDTIDX},mds$((MDTIDX + 1))
2952
2953         wait $CLIENT_PID || error "rm remote dir failed"
2954
2955         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2956
2957         rm -rf $DIR/$tdir || error "rmdir failed"
2958
2959         return 0
2960 }
2961 run_test 81d "DNE: unlink remote dir, drop MDT0 update reply,  fail 2 MDTs"
2962
2963 test_81e() {
2964         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2965         ([ $FAILURE_MODE == "HARD" ] &&
2966                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2967                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2968                 return 0
2969
2970         local MDTIDX=1
2971         local remote_dir=$DIR/$tdir/remote_dir
2972
2973         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2974         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2975
2976         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2977         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2978         rmdir $remote_dir &
2979         local CLIENT_PID=$!
2980         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0
2981
2982         replay_barrier mds1
2983         fail mds${MDTIDX}
2984
2985         wait $CLIENT_PID || error "rm remote dir failed"
2986
2987         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2988
2989         rm -rf $DIR/$tdir || error "rmdir failed"
2990
2991         return 0
2992 }
2993 run_test 81e "DNE: unlink remote dir, drop MDT1 req reply, fail MDT0"
2994
2995 test_81f() {
2996         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2997         ([ $FAILURE_MODE == "HARD" ] &&
2998                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2999                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3000                 return 0
3001
3002         local MDTIDX=1
3003         local remote_dir=$DIR/$tdir/remote_dir
3004
3005         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3006         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
3007
3008         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3009         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
3010         rmdir $remote_dir &
3011         local CLIENT_PID=$!
3012
3013         replay_barrier mds2
3014         fail mds$((MDTIDX + 1))
3015
3016         wait $CLIENT_PID || error "rm remote dir failed"
3017
3018         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3019
3020         rm -rf $DIR/$tdir || error "rmdir failed"
3021
3022         return 0
3023 }
3024 run_test 81f "DNE: unlink remote dir, drop MDT1 req reply, fail MDT1"
3025
3026 test_81g() {
3027         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3028         ([ $FAILURE_MODE == "HARD" ] &&
3029                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3030                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3031                 return 0
3032
3033         local MDTIDX=1
3034         local remote_dir=$DIR/$tdir/remote_dir
3035
3036         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3037         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
3038
3039         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3040         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
3041         rmdir $remote_dir &
3042         local CLIENT_PID=$!
3043
3044         replay_barrier mds1
3045         replay_barrier mds2
3046         fail mds${MDTIDX}
3047         fail mds$((MDTIDX + 1))
3048
3049         wait $CLIENT_PID || error "rm remote dir failed"
3050
3051         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3052
3053         rm -rf $DIR/$tdir || error "rmdir failed"
3054
3055         return 0
3056 }
3057 run_test 81g "DNE: unlink remote dir, drop req reply, fail M0, then M1"
3058
3059 test_81h() {
3060         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3061         local MDTIDX=1
3062         local remote_dir=$DIR/$tdir/remote_dir
3063
3064         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3065         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
3066
3067         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3068         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
3069         rmdir $remote_dir &
3070         local CLIENT_PID=$!
3071
3072         replay_barrier mds1
3073         replay_barrier mds2
3074         fail mds${MDTIDX},mds$((MDTIDX + 1))
3075
3076         wait $CLIENT_PID || error "rm remote dir failed"
3077
3078         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3079
3080         rm -rf $DIR/$tdir || error "rmdir failed"
3081
3082         return 0
3083 }
3084 run_test 81h "DNE: unlink remote dir, drop request reply, fail 2 MDTs"
3085
3086 test_84a() {
3087 #define OBD_FAIL_MDS_OPEN_WAIT_CREATE  0x144
3088     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000144"
3089     createmany -o $DIR/$tfile- 1 &
3090     PID=$!
3091     mds_evict_client
3092     wait $PID
3093     client_up || client_up || true    # reconnect
3094 }
3095 run_test 84a "stale open during export disconnect"
3096
3097 test_85a() { #bug 16774
3098         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
3099
3100         for i in $(seq 100); do
3101                 echo "tag-$i" > $DIR/$tfile-$i
3102                 grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
3103         done
3104
3105         lov_id=$(lctl dl | grep "clilov")
3106         addr=$(echo $lov_id | awk '{print $4}' | awk -F '-' '{print $NF}')
3107         count=$(lctl get_param -n \
3108                 ldlm.namespaces.*MDT0000*$addr.lock_unused_count)
3109         echo "before recovery: unused locks count = $count"
3110
3111         fail $SINGLEMDS
3112
3113         count2=$(lctl get_param -n \
3114                  ldlm.namespaces.*MDT0000*$addr.lock_unused_count)
3115         echo "after recovery: unused locks count = $count2"
3116
3117         if [ $count2 -ge $count ]; then
3118                 error "unused locks are not canceled"
3119         fi
3120 }
3121 run_test 85a "check the cancellation of unused locks during recovery(IBITS)"
3122
3123 test_85b() { #bug 16774
3124         rm -rf $DIR/$tdir
3125         mkdir $DIR/$tdir
3126
3127         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
3128
3129         if ! combined_mgs_mds ; then
3130                 mount_mgs_client
3131         fi
3132
3133         $LFS setstripe -c 1 -i 0 $DIR/$tdir
3134
3135         for i in $(seq 100); do
3136                 dd if=/dev/urandom of=$DIR/$tdir/$tfile-$i bs=4096 \
3137                         count=32 >/dev/null 2>&1
3138         done
3139
3140         cancel_lru_locks osc
3141
3142         for i in $(seq 100); do
3143                 dd if=$DIR/$tdir/$tfile-$i of=/dev/null bs=4096 \
3144                         count=32 >/dev/null 2>&1
3145         done
3146
3147         lov_id=$(lctl dl | grep "clilov")
3148         addr=$(echo $lov_id | awk '{print $4}' | awk -F '-' '{print $NF}')
3149         count=$(lctl get_param -n \
3150                           ldlm.namespaces.*OST0000*$addr.lock_unused_count)
3151         echo "before recovery: unused locks count = $count"
3152         [ $count -ne 0 ] || error "unused locks ($count) should be zero"
3153
3154         fail ost1
3155
3156         count2=$(lctl get_param \
3157                  -n ldlm.namespaces.*OST0000*$addr.lock_unused_count)
3158         echo "after recovery: unused locks count = $count2"
3159
3160         if ! combined_mgs_mds ; then
3161                 umount_mgs_client
3162         fi
3163
3164         if [ $count2 -ge $count ]; then
3165                 error "unused locks are not canceled"
3166         fi
3167
3168         rm -rf $DIR/$tdir
3169 }
3170 run_test 85b "check the cancellation of unused locks during recovery(EXTENT)"
3171
3172 test_86() {
3173         local clients=${CLIENTS:-$HOSTNAME}
3174
3175         zconf_umount_clients $clients $MOUNT
3176         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT*.exports.clear=0
3177         remount_facet $SINGLEMDS
3178         zconf_mount_clients $clients $MOUNT
3179 }
3180 run_test 86 "umount server after clear nid_stats should not hit LBUG"
3181
3182 test_87a() {
3183         do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
3184
3185         replay_barrier ost1
3186         $LFS setstripe -i 0 -c 1 $DIR/$tfile
3187         dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 ||
3188                 error "dd to $DIR/$tfile failed"
3189         cksum=$(md5sum $DIR/$tfile | awk '{print $1}')
3190         cancel_lru_locks osc
3191         fail ost1
3192         dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
3193         cksum2=$(md5sum $DIR/$tfile | awk '{print $1}')
3194         if [ $cksum != $cksum2 ] ; then
3195                 error "New checksum $cksum2 does not match original $cksum"
3196         fi
3197 }
3198 run_test 87a "write replay"
3199
3200 test_87b() {
3201         do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
3202
3203         replay_barrier ost1
3204         $LFS setstripe -i 0 -c 1 $DIR/$tfile
3205         dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 ||
3206                 error "dd to $DIR/$tfile failed"
3207         sleep 1 # Give it a chance to flush dirty data
3208         echo TESTTEST | dd of=$DIR/$tfile bs=1 count=8 seek=64
3209         cksum=$(md5sum $DIR/$tfile | awk '{print $1}')
3210         cancel_lru_locks osc
3211         fail ost1
3212         dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
3213         cksum2=$(md5sum $DIR/$tfile | awk '{print $1}')
3214         if [ $cksum != $cksum2 ] ; then
3215                 error "New checksum $cksum2 does not match original $cksum"
3216         fi
3217 }
3218 run_test 87b "write replay with changed data (checksum resend)"
3219
3220 test_88() { #bug 17485
3221         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3222         mkdir -p $TMP/$tdir || error "mkdir $TMP/$tdir failed"
3223
3224         $LFS setstripe -i 0 -c 1 $DIR/$tdir || error "$LFS setstripe failed"
3225
3226         replay_barrier ost1
3227         replay_barrier $SINGLEMDS
3228
3229     # exhaust precreations on ost1
3230     local OST=$(ostname_from_index 0)
3231     local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $OST)
3232     local last_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
3233     local next_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
3234         echo "before test: last_id = $last_id, next_id = $next_id"
3235
3236         echo "Creating to objid $last_id on ost $OST..."
3237         createmany -o $DIR/$tdir/f-%d $next_id $((last_id - next_id + 2)) ||
3238                 error "createmany create files to last_id failed"
3239
3240         #create some files to use some uncommitted objids
3241         last_id=$(($last_id + 1))
3242         createmany -o $DIR/$tdir/f-%d $last_id 8 ||
3243                 error "createmany create files with uncommitted objids failed"
3244
3245     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
3246     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
3247     echo "before recovery: last_id = $last_id2, next_id = $next_id2" 
3248
3249     # if test uses shutdown_facet && reboot_facet instead of facet_failover ()
3250     # it has to take care about the affected facets, bug20407
3251     local affected_mds1=$(affected_facets mds1)
3252     local affected_ost1=$(affected_facets ost1)
3253
3254     shutdown_facet $SINGLEMDS
3255     shutdown_facet ost1
3256
3257     reboot_facet $SINGLEMDS
3258     change_active $affected_mds1
3259     wait_for_facet $affected_mds1
3260     mount_facets $affected_mds1 || error "Restart of mds failed"
3261
3262     reboot_facet ost1
3263     change_active $affected_ost1
3264     wait_for_facet $affected_ost1
3265     mount_facets $affected_ost1 || error "Restart of ost1 failed"
3266
3267     clients_up
3268
3269     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
3270     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
3271         echo "after recovery: last_id = $last_id2, next_id = $next_id2"
3272
3273         # create new files, which should use new objids, and ensure the orphan
3274         # cleanup phase for ost1 is completed at the same time
3275         for i in $(seq 8); do
3276                 file_id=$(($last_id + 10 + $i))
3277                 dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
3278         done
3279
3280         # if the objids were not recreated, then "ls" will fail with -ENOENT
3281         ls -l $DIR/$tdir/* || error "can't get the status of precreated files"
3282
3283         local file_id
3284         # write into previously created files
3285         for i in $(seq 8); do
3286                 file_id=$(($last_id + $i))
3287                 dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
3288                 cp -f $DIR/$tdir/f-$file_id $TMP/$tdir/
3289         done
3290
3291         # compare the content
3292         for i in $(seq 8); do
3293                 file_id=$(($last_id + $i))
3294                 cmp $TMP/$tdir/f-$file_id $DIR/$tdir/f-$file_id ||
3295                         error "the content of file is modified!"
3296         done
3297
3298         rm -fr $TMP/$tdir
3299 }
3300 run_test 88 "MDS should not assign same objid to different files "
3301
3302 function calc_osc_kbytes_used() {
3303         local kbtotal=$(calc_osc_kbytes kbytestotal)
3304         local kbfree=$(calc_osc_kbytes kbytesfree)
3305         echo $((kbtotal-kbfree))
3306 }
3307
3308 test_89() {
3309         cancel_lru_locks osc
3310         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3311         rm -f $DIR/$tdir/$tfile
3312         wait_mds_ost_sync || error "initial MDS-OST sync timed out"
3313         wait_delete_completed || error "initial wait delete timed out"
3314         local blocks1=$(calc_osc_kbytes_used)
3315         local write_size=$(fs_log_size)
3316
3317         $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3318         [ $write_size -lt 1024 ] && write_size=1024
3319         dd if=/dev/zero bs=${write_size}k count=10 of=$DIR/$tdir/$tfile
3320         sync
3321         stop ost1
3322         facet_failover $SINGLEMDS
3323         rm $DIR/$tdir/$tfile
3324         umount $MOUNT
3325         mount_facet ost1
3326         zconf_mount $(hostname) $MOUNT || error "mount fails"
3327         client_up || error "client_up failed"
3328
3329         # wait for the remounted client to connect to ost1
3330         local target=$(get_osc_import_name client ost1)
3331         wait_import_state "FULL" "osc.${target}.ost_server_uuid" \
3332                 $(max_recovery_time)
3333
3334         wait_mds_ost_sync || error "MDS-OST sync timed out"
3335         wait_delete_completed || error "wait delete timed out"
3336         local blocks2=$(calc_osc_kbytes_used)
3337
3338         [ $((blocks2 - blocks1)) -le $(fs_log_size)  ] ||
3339                 error $((blocks2 - blocks1)) blocks leaked
3340 }
3341 run_test 89 "no disk space leak on late ost connection"
3342
3343 cleanup_90 () {
3344         local facet=$1
3345
3346         trap 0
3347         reboot_facet $facet
3348         change_active $facet
3349         wait_for_facet $facet
3350         mount_facet $facet || error "Restart of $facet failed"
3351         clients_up
3352 }
3353
3354 test_90() { # bug 19494
3355     local dir=$DIR/$tdir
3356     local ostfail=$(get_random_entry $(get_facets OST))
3357
3358     if [[ $FAILURE_MODE = HARD ]]; then
3359         local affected=$(affected_facets $ostfail);
3360         if [[ "$affected" != $ostfail ]]; then
3361             skip not functional with FAILURE_MODE=$FAILURE_MODE, affected: $affected
3362             return 0
3363         fi
3364     fi
3365         # ensure all OSTs are active to allow allocations
3366         wait_osts_up
3367
3368         mkdir $dir || error "mkdir $dir failed"
3369
3370         echo "Create the files"
3371
3372         # file "f${index}" striped over 1 OST
3373         # file "all" striped over all OSTs
3374
3375         $LFS setstripe -c $OSTCOUNT $dir/all ||
3376                 error "setstripe failed to create $dir/all"
3377
3378         for ((i = 0; i < $OSTCOUNT; i++)); do
3379                 local f=$dir/f$i
3380
3381                 $LFS setstripe -i $i -c 1 $f ||
3382                         error "$LFS setstripe failed to create $f"
3383
3384                 # confirm setstripe actually created stripe on requested OST
3385                 local uuid=$(ostuuid_from_index $i)
3386
3387                 for file in f$i all; do
3388                         local found=$($LFS find --obd $uuid --name $file $dir)
3389
3390                         if [[ $dir/$file != $found ]]; then
3391                                 $LFS getstripe $dir/$file
3392                                 error "wrong stripe: $file, uuid: $uuid"
3393                         fi
3394                 done
3395         done
3396
3397         # Before failing an OST, get its obd name and index
3398         local varsvc=${ostfail}_svc
3399         local obd=$(do_facet $ostfail lctl get_param \
3400                     -n obdfilter.${!varsvc}.uuid)
3401         local index=$(($(facet_number $ostfail) - 1))
3402
3403         echo "Fail $ostfail $obd, display the list of affected files"
3404         shutdown_facet $ostfail || error "shutdown_facet $ostfail failed"
3405
3406         trap "cleanup_90 $ostfail" EXIT INT
3407         echo "General Query: lfs find $dir"
3408         local list=$($LFS find $dir)
3409         echo "$list"
3410         for (( i=0; i<$OSTCOUNT; i++ )); do
3411                 list_member "$list" $dir/f$i ||
3412                         error_noexit "lfs find $dir: no file f$i"
3413         done
3414         list_member "$list" $dir/all ||
3415                 error_noexit "lfs find $dir: no file all"
3416
3417         # focus on the missing OST,
3418         # we expect to see only two files affected: "f$(index)" and "all"
3419
3420         echo "Querying files on shutdown $ostfail: lfs find --obd $obd"
3421     list=$($LFS find --obd $obd $dir)
3422     echo "$list"
3423     for file in all f$index; do
3424         list_member "$list" $dir/$file ||
3425             error_noexit "lfs find does not report the affected $obd for $file"
3426     done
3427
3428     [[ $(echo $list | wc -w) -eq 2 ]] ||
3429         error_noexit "lfs find reports the wrong list of affected files ${#list[@]}"
3430
3431         echo "Check getstripe: $LFS getstripe -r --obd $obd"
3432         list=$($LFS getstripe -r --obd $obd $dir)
3433         echo "$list"
3434     for file in all f$index; do
3435         echo "$list" | grep $dir/$file ||
3436             error_noexit "lfs getsripe does not report the affected $obd for $file"
3437     done
3438
3439     cleanup_90 $ostfail
3440 }
3441 run_test 90 "lfs find identifies the missing striped file segments"
3442
3443 test_93a() {
3444         local server_version=$(lustre_version_code $SINGLEMDS)
3445                 [[ $server_version -ge $(version_code 2.6.90) ]] ||
3446                 [[ $server_version -ge $(version_code 2.5.4) &&
3447                    $server_version -lt $(version_code 2.5.50) ]] ||
3448                 { skip "Need MDS version 2.5.4+ or 2.6.90+"; return; }
3449
3450         cancel_lru_locks osc
3451
3452         $LFS setstripe -i 0 -c 1 $DIR/$tfile ||
3453                 error "$LFS setstripe  $DIR/$tfile failed"
3454         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 ||
3455                 error "dd to $DIR/$tfile failed"
3456         #define OBD_FAIL_TGT_REPLAY_RECONNECT     0x715
3457         # We need to emulate a state that OST is waiting for other clients
3458         # not completing the recovery. Final ping is queued, but reply will be
3459         # sent on the recovery completion. It is done by sleep before
3460         # processing final pings
3461         do_facet ost1 "$LCTL set_param fail_val=40"
3462         do_facet ost1 "$LCTL set_param fail_loc=0x715"
3463         fail ost1
3464 }
3465 run_test 93a "replay + reconnect"
3466
3467 test_93b() {
3468         local server_version=$(lustre_version_code $SINGLEMDS)
3469                 [[ $server_version -ge $(version_code 2.7.90) ]] ||
3470                 { skip "Need MDS version 2.7.90+"; return; }
3471
3472         cancel_lru_locks mdc
3473
3474         createmany -o $DIR/$tfile 20 ||
3475                         error "createmany -o $DIR/$tfile failed"
3476
3477         #define OBD_FAIL_TGT_REPLAY_RECONNECT     0x715
3478         # We need to emulate a state that MDT is waiting for other clients
3479         # not completing the recovery. Final ping is queued, but reply will be
3480         # sent on the recovery completion. It is done by sleep before
3481         # processing final pings
3482         do_facet mds1 "$LCTL set_param fail_val=80"
3483         do_facet mds1 "$LCTL set_param fail_loc=0x715"
3484         fail mds1
3485 }
3486 run_test 93b "replay + reconnect on mds"
3487
3488 striped_dir_check_100() {
3489         local striped_dir=$DIR/$tdir/striped_dir
3490         local stripe_count=$($LFS getdirstripe -c $striped_dir)
3491
3492         $LFS getdirstripe $striped_dir
3493         [ $stripe_count -eq 2 ] || error "$stripe_count != 2"
3494
3495         createmany -o $striped_dir/f-%d 20 ||
3496                 error "creation failed under striped dir"
3497 }
3498
3499 test_100a() {
3500         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3501         ([ $FAILURE_MODE == "HARD" ] &&
3502                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3503                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3504                 return 0
3505
3506         local striped_dir=$DIR/$tdir/striped_dir
3507         local MDTIDX=1
3508
3509         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3510
3511         #To make sure MDT1 and MDT0 are connected
3512         #otherwise it may create single stripe dir here
3513         $LFS setdirstripe -i1 $DIR/$tdir/remote_dir
3514
3515         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
3516         do_facet mds$((MDTIDX+1)) lctl set_param fail_loc=0x1701
3517         $LFS setdirstripe -i0 -c2 $striped_dir &
3518         local CLIENT_PID=$!
3519
3520         fail mds$((MDTIDX + 1))
3521
3522         wait $CLIENT_PID || error "striped dir creation failed"
3523
3524         striped_dir_check_100 || error "striped dir check failed"
3525         rm -rf $DIR/$tdir || error "rmdir failed"
3526 }
3527 run_test 100a "DNE: create striped dir, drop update rep from MDT1, fail MDT1"
3528
3529 test_100b() {
3530         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3531         ([ $FAILURE_MODE == "HARD" ] &&
3532                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3533                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3534                 return 0
3535
3536         local striped_dir=$DIR/$tdir/striped_dir
3537         local MDTIDX=1
3538
3539         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3540
3541         #To make sure MDT1 and MDT0 are connected
3542         #otherwise it may create single stripe dir here
3543         $LFS setdirstripe -i1 $DIR/$tdir/remote_dir
3544
3545         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3546         do_facet mds$MDTIDX lctl set_param fail_loc=0x119
3547         $LFS mkdir -i0 -c2 $striped_dir &
3548
3549         local CLIENT_PID=$!
3550         fail mds$MDTIDX
3551
3552         wait $CLIENT_PID || error "striped dir creation failed"
3553
3554         striped_dir_check_100 || error "striped dir check failed"
3555         rm -rf $DIR/$tdir || error "rmdir failed"
3556 }
3557 run_test 100b "DNE: create striped dir, fail MDT0"
3558
3559 test_101() { #LU-5648
3560         mkdir -p $DIR/$tdir/d1
3561         mkdir -p $DIR/$tdir/d2
3562         touch $DIR/$tdir/file0
3563         num=1000
3564
3565         replay_barrier $SINGLEMDS
3566         for i in $(seq $num) ; do
3567                 echo test$i > $DIR/$tdir/d1/file$i
3568         done
3569
3570         fail_abort $SINGLEMDS
3571         for i in $(seq $num) ; do
3572                 touch $DIR/$tdir/d2/file$i
3573                 test -s $DIR/$tdir/d2/file$i &&
3574                         ls -al $DIR/$tdir/d2/file$i && error "file$i's size > 0"
3575         done
3576
3577         rm -rf $DIR/$tdir
3578 }
3579 run_test 101 "Shouldn't reassign precreated objs to other files after recovery"
3580
3581 test_102a() {
3582         local idx
3583         local facet
3584         local num
3585         local i
3586         local pids pid
3587
3588         [[ $(lctl get_param mdc.*.import |
3589              grep "connect_flags:.*multi_mod_rpc") ]] ||
3590                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3591
3592         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3593         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3594         facet="mds$((0x$idx + 1))"
3595
3596         # get current value of max_mod_rcps_in_flight
3597         num=$($LCTL get_param -n \
3598                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3599         # set default value if client does not support multi mod RPCs
3600         [ -z "$num" ] && num=1
3601
3602         echo "creating $num files ..."
3603         umask 0022
3604         for i in $(seq $num); do
3605                 touch $DIR/$tdir/file-$i
3606         done
3607
3608         # drop request on MDT to force resend
3609         #define OBD_FAIL_MDS_REINT_MULTI_NET 0x159
3610         do_facet $facet "$LCTL set_param fail_loc=0x159"
3611         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3612         for i in $(seq $num); do
3613                 chmod 0600 $DIR/$tdir/file-$i &
3614                 pids="$pids $!"
3615         done
3616         sleep 1
3617         do_facet $facet "$LCTL set_param fail_loc=0"
3618         for pid in $pids; do
3619                 wait $pid || error "chmod failed"
3620         done
3621         echo "done ($(date +%H:%M:%S))"
3622
3623         # check chmod succeed
3624         for i in $(seq $num); do
3625                 checkstat -vp 0600 $DIR/$tdir/file-$i
3626         done
3627
3628         rm -rf $DIR/$tdir
3629 }
3630 run_test 102a "check resend (request lost) with multiple modify RPCs in flight"
3631
3632 test_102b() {
3633         local idx
3634         local facet
3635         local num
3636         local i
3637         local pids pid
3638
3639         [[ $(lctl get_param mdc.*.import |
3640              grep "connect_flags:.*multi_mod_rpc") ]] ||
3641                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3642
3643         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3644         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3645         facet="mds$((0x$idx + 1))"
3646
3647         # get current value of max_mod_rcps_in_flight
3648         num=$($LCTL get_param -n \
3649                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3650         # set default value if client does not support multi mod RPCs
3651         [ -z "$num" ] && num=1
3652
3653         echo "creating $num files ..."
3654         umask 0022
3655         for i in $(seq $num); do
3656                 touch $DIR/$tdir/file-$i
3657         done
3658
3659         # drop reply on MDT to force reconstruction
3660         #define OBD_FAIL_MDS_REINT_MULTI_NET_REP 0x15a
3661         do_facet $facet "$LCTL set_param fail_loc=0x15a"
3662         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3663         for i in $(seq $num); do
3664                 chmod 0600 $DIR/$tdir/file-$i &
3665                 pids="$pids $!"
3666         done
3667         sleep 1
3668         do_facet $facet "$LCTL set_param fail_loc=0"
3669         for pid in $pids; do
3670                 wait $pid || error "chmod failed"
3671         done
3672         echo "done ($(date +%H:%M:%S))"
3673
3674         # check chmod succeed
3675         for i in $(seq $num); do
3676                 checkstat -vp 0600 $DIR/$tdir/file-$i
3677         done
3678
3679         rm -rf $DIR/$tdir
3680 }
3681 run_test 102b "check resend (reply lost) with multiple modify RPCs in flight"
3682
3683 test_102c() {
3684         local idx
3685         local facet
3686         local num
3687         local i
3688         local pids pid
3689
3690         [[ $(lctl get_param mdc.*.import |
3691              grep "connect_flags:.*multi_mod_rpc") ]] ||
3692                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3693
3694         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3695         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3696         facet="mds$((0x$idx + 1))"
3697
3698         # get current value of max_mod_rcps_in_flight
3699         num=$($LCTL get_param -n \
3700                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3701         # set default value if client does not support multi mod RPCs
3702         [ -z "$num" ] && num=1
3703
3704         echo "creating $num files ..."
3705         umask 0022
3706         for i in $(seq $num); do
3707                 touch $DIR/$tdir/file-$i
3708         done
3709
3710         replay_barrier $facet
3711
3712         # drop reply on MDT
3713         #define OBD_FAIL_MDS_REINT_MULTI_NET_REP 0x15a
3714         do_facet $facet "$LCTL set_param fail_loc=0x15a"
3715         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3716         for i in $(seq $num); do
3717                 chmod 0600 $DIR/$tdir/file-$i &
3718                 pids="$pids $!"
3719         done
3720         sleep 1
3721         do_facet $facet "$LCTL set_param fail_loc=0"
3722
3723         # fail MDT
3724         fail $facet
3725
3726         for pid in $pids; do
3727                 wait $pid || error "chmod failed"
3728         done
3729         echo "done ($(date +%H:%M:%S))"
3730
3731         # check chmod succeed
3732         for i in $(seq $num); do
3733                 checkstat -vp 0600 $DIR/$tdir/file-$i
3734         done
3735
3736         rm -rf $DIR/$tdir
3737 }
3738 run_test 102c "check replay w/o reconstruction with multiple mod RPCs in flight"
3739
3740 test_102d() {
3741         local idx
3742         local facet
3743         local num
3744         local i
3745         local pids pid
3746
3747         [[ $(lctl get_param mdc.*.import |
3748              grep "connect_flags:.*multi_mod_rpc") ]] ||
3749                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3750
3751         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3752         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3753         facet="mds$((0x$idx + 1))"
3754
3755         # get current value of max_mod_rcps_in_flight
3756         num=$($LCTL get_param -n \
3757                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3758         # set default value if client does not support multi mod RPCs
3759         [ -z "$num" ] && num=1
3760
3761         echo "creating $num files ..."
3762         umask 0022
3763         for i in $(seq $num); do
3764                 touch $DIR/$tdir/file-$i
3765         done
3766
3767         # drop reply on MDT
3768         #define OBD_FAIL_MDS_REINT_MULTI_NET_REP 0x15a
3769         do_facet $facet "$LCTL set_param fail_loc=0x15a"
3770         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3771         for i in $(seq $num); do
3772                 chmod 0600 $DIR/$tdir/file-$i &
3773                 pids="$pids $!"
3774         done
3775         sleep 1
3776
3777         # write MDT transactions to disk
3778         do_facet $facet "sync; sync; sync"
3779
3780         do_facet $facet "$LCTL set_param fail_loc=0"
3781
3782         # fail MDT
3783         fail $facet
3784
3785         for pid in $pids; do
3786                 wait $pid || error "chmod failed"
3787         done
3788         echo "done ($(date +%H:%M:%S))"
3789
3790         # check chmod succeed
3791         for i in $(seq $num); do
3792                 checkstat -vp 0600 $DIR/$tdir/file-$i
3793         done
3794
3795         rm -rf $DIR/$tdir
3796 }
3797 run_test 102d "check replay & reconstruction with multiple mod RPCs in flight"
3798
3799 test_103() {
3800         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3801         local mds_version=$(lustre_version_code $SINGLEMDS)
3802         [[ $mds_version -gt $(version_code 2.8.54) ]] ||
3803                 { skip "Need MDS version 2.8.54+"; return; }
3804
3805 #define OBD_FAIL_MDS_TRACK_OVERFLOW 0x162
3806         do_facet mds1 $LCTL set_param fail_loc=0x80000162
3807
3808         mkdir -p $DIR/$tdir
3809         createmany -o $DIR/$tdir/t- 30 ||
3810                 error "create files on remote directory failed"
3811         sync
3812         rm -rf $DIR/$tdir/t-*
3813         sync
3814 #MDS should crash with tr->otr_next_id overflow
3815         fail mds1
3816 }
3817 run_test 103 "Check otr_next_id overflow"
3818
3819
3820 check_striped_dir_110()
3821 {
3822         $CHECKSTAT -t dir $DIR/$tdir/striped_dir ||
3823                         error "create striped dir failed"
3824         local stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
3825         [ $stripe_count -eq $MDSCOUNT ] ||
3826                 error "$stripe_count != 2 after recovery"
3827 }
3828
3829 test_110a() {
3830         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3831         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
3832                 skip "Need MDS version at least 2.7.56"
3833
3834         ([ $FAILURE_MODE == "HARD" ] &&
3835                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3836                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3837                 return 0
3838
3839         mkdir -p $DIR/$tdir
3840         replay_barrier mds1
3841         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3842         fail mds1
3843
3844         check_striped_dir_110 || error "check striped_dir failed"
3845         rm -rf $DIR/$tdir || error "rmdir failed"
3846
3847         return 0
3848 }
3849 run_test 110a "DNE: create striped dir, fail MDT1"
3850
3851 test_110b() {
3852         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3853         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
3854                 skip "Need MDS version at least 2.7.56"
3855
3856         ([ $FAILURE_MODE == "HARD" ] &&
3857                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3858                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3859                 return 0
3860
3861         mkdir -p $DIR/$tdir
3862         replay_barrier mds1
3863         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3864         umount $MOUNT
3865         fail mds1
3866         zconf_mount $(hostname) $MOUNT
3867         client_up || return 1
3868
3869         check_striped_dir_110 || error "check striped_dir failed"
3870
3871         rm -rf $DIR/$tdir || error "rmdir failed"
3872
3873         return 0
3874 }
3875 run_test 110b "DNE: create striped dir, fail MDT1 and client"
3876
3877 test_110c() {
3878         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3879         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
3880                 skip "Need MDS version at least 2.7.56"
3881
3882         ([ $FAILURE_MODE == "HARD" ] &&
3883                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3884                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3885                 return 0
3886
3887         mkdir -p $DIR/$tdir
3888         replay_barrier mds2
3889         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3890         fail mds2
3891
3892         check_striped_dir_110 || error "check striped_dir failed"
3893
3894         rm -rf $DIR/$tdir || error "rmdir failed"
3895
3896         return 0
3897 }
3898 run_test 110c "DNE: create striped dir, fail MDT2"
3899
3900 test_110d() {
3901         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3902         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
3903                 skip "Need MDS version at least 2.7.56"
3904
3905         ([ $FAILURE_MODE == "HARD" ] &&
3906                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3907                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3908                 return 0
3909
3910         mkdir -p $DIR/$tdir
3911         replay_barrier mds2
3912         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3913         umount $MOUNT
3914         fail mds2
3915         zconf_mount $(hostname) $MOUNT
3916         client_up || return 1
3917
3918         check_striped_dir_110 || error "check striped_dir failed"
3919
3920         rm -rf $DIR/$tdir || error "rmdir failed"
3921
3922         return 0
3923 }
3924 run_test 110d "DNE: create striped dir, fail MDT2 and client"
3925
3926 test_110e() {
3927         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3928         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
3929                 skip "Need MDS version at least 2.7.56"
3930
3931         ([ $FAILURE_MODE == "HARD" ] &&
3932                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3933                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3934                 return 0
3935
3936         mkdir -p $DIR/$tdir
3937         replay_barrier mds2
3938         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3939         umount $MOUNT
3940         replay_barrier mds1
3941         fail mds1,mds2
3942         zconf_mount $(hostname) $MOUNT
3943         client_up || return 1
3944
3945         check_striped_dir_110 || error "check striped_dir failed"
3946
3947         rm -rf $DIR/$tdir || error "rmdir failed"
3948
3949         return 0
3950 }
3951 run_test 110e "DNE: create striped dir, uncommit on MDT2, fail client/MDT1/MDT2"
3952
3953 test_110f() {
3954         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3955         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
3956                 skip "Need MDS version at least 2.7.56"
3957
3958         ([ $FAILURE_MODE == "HARD" ] &&
3959                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3960                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3961                 return 0
3962
3963         mkdir -p $DIR/$tdir
3964         replay_barrier mds1
3965         replay_barrier mds2
3966         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3967         fail mds2,mds1
3968
3969         check_striped_dir_110 || error "check striped_dir failed"
3970
3971         rm -rf $DIR/$tdir || error "rmdir failed"
3972
3973         return 0
3974 }
3975 run_test 110f "DNE: create striped dir, fail MDT1/MDT2"
3976
3977 test_110g() {
3978         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3979         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
3980                 skip "Need MDS version at least 2.7.56"
3981
3982         ([ $FAILURE_MODE == "HARD" ] &&
3983                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3984                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3985                 return 0
3986
3987         mkdir -p $DIR/$tdir
3988         replay_barrier mds1
3989         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3990         umount $MOUNT
3991         replay_barrier mds2
3992         fail mds1,mds2
3993         zconf_mount $(hostname) $MOUNT
3994         client_up || return 1
3995
3996         check_striped_dir_110 || error "check striped_dir failed"
3997
3998         rm -rf $DIR/$tdir || error "rmdir failed"
3999
4000         return 0
4001 }
4002 run_test 110g "DNE: create striped dir, uncommit on MDT1, fail client/MDT1/MDT2"
4003
4004 test_111a() {
4005         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4006         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4007                 skip "Need MDS version at least 2.7.56"
4008
4009         ([ $FAILURE_MODE == "HARD" ] &&
4010                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4011                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4012                 return 0
4013
4014         mkdir -p $DIR/$tdir
4015         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4016         replay_barrier mds1
4017         rm -rf $DIR/$tdir/striped_dir
4018         fail mds1
4019
4020         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4021                         error "striped dir still exists"
4022         return 0
4023 }
4024 run_test 111a "DNE: unlink striped dir, fail MDT1"
4025
4026 test_111b() {
4027         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4028         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4029                 skip "Need MDS version at least 2.7.56"
4030
4031         ([ $FAILURE_MODE == "HARD" ] &&
4032                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4033                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4034                 return 0
4035
4036         mkdir -p $DIR/$tdir
4037         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4038         replay_barrier mds2
4039         rm -rf $DIR/$tdir/striped_dir
4040         umount $MOUNT
4041         fail mds2
4042         zconf_mount $(hostname) $MOUNT
4043         client_up || return 1
4044
4045         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4046                         error "striped dir still exists"
4047         return 0
4048 }
4049 run_test 111b "DNE: unlink striped dir, fail MDT2"
4050
4051 test_111c() {
4052         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4053         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4054                 skip "Need MDS version at least 2.7.56"
4055
4056         ([ $FAILURE_MODE == "HARD" ] &&
4057                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4058                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4059                 return 0
4060
4061         mkdir -p $DIR/$tdir
4062         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4063         replay_barrier mds1
4064         rm -rf $DIR/$tdir/striped_dir
4065         umount $MOUNT
4066         replay_barrier mds2
4067         fail mds1,mds2
4068         zconf_mount $(hostname) $MOUNT
4069         client_up || return 1
4070         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4071                         error "striped dir still exists"
4072         return 0
4073 }
4074 run_test 111c "DNE: unlink striped dir, uncommit on MDT1, fail client/MDT1/MDT2"
4075
4076 test_111d() {
4077         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4078         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4079                 skip "Need MDS version at least 2.7.56"
4080
4081         ([ $FAILURE_MODE == "HARD" ] &&
4082                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4083                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4084                 return 0
4085
4086         mkdir -p $DIR/$tdir
4087         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4088         replay_barrier mds2
4089         rm -rf $DIR/$tdir/striped_dir
4090         umount $MOUNT
4091         replay_barrier mds1
4092         fail mds1,mds2
4093         zconf_mount $(hostname) $MOUNT
4094         client_up || return 1
4095         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4096                         error "striped dir still exists"
4097
4098         return 0
4099 }
4100 run_test 111d "DNE: unlink striped dir, uncommit on MDT2, fail client/MDT1/MDT2"
4101
4102 test_111e() {
4103         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4104         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4105                 skip "Need MDS version at least 2.7.56"
4106
4107         ([ $FAILURE_MODE == "HARD" ] &&
4108                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4109                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4110                 return 0
4111
4112         mkdir -p $DIR/$tdir
4113         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4114         replay_barrier mds2
4115         rm -rf $DIR/$tdir/striped_dir
4116         replay_barrier mds1
4117         fail mds1,mds2
4118         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4119                         error "striped dir still exists"
4120         return 0
4121 }
4122 run_test 111e "DNE: unlink striped dir, uncommit on MDT2, fail MDT1/MDT2"
4123
4124 test_111f() {
4125         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4126         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4127                 skip "Need MDS version at least 2.7.56"
4128
4129         ([ $FAILURE_MODE == "HARD" ] &&
4130                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4131                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4132                 return 0
4133
4134         mkdir -p $DIR/$tdir
4135         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4136         replay_barrier mds1
4137         rm -rf $DIR/$tdir/striped_dir
4138         replay_barrier mds2
4139         fail mds1,mds2
4140         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4141                         error "striped dir still exists"
4142         return 0
4143 }
4144 run_test 111f "DNE: unlink striped dir, uncommit on MDT1, fail MDT1/MDT2"
4145
4146 test_111g() {
4147         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4148         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4149                 skip "Need MDS version at least 2.7.56"
4150
4151         ([ $FAILURE_MODE == "HARD" ] &&
4152                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4153                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4154                 return 0
4155
4156         mkdir -p $DIR/$tdir
4157         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4158         replay_barrier mds1
4159         replay_barrier mds2
4160         rm -rf $DIR/$tdir/striped_dir
4161         fail mds1,mds2
4162         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4163                         error "striped dir still exists"
4164         return 0
4165 }
4166 run_test 111g "DNE: unlink striped dir, fail MDT1/MDT2"
4167
4168 test_112_rename_prepare() {
4169         mkdir -p $DIR/$tdir/src_dir
4170         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
4171                 error "create remote source failed"
4172
4173         touch $DIR/$tdir/src_dir/src_child/a
4174
4175         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
4176                 error "create remote target dir failed"
4177
4178         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
4179                 error "create remote target child failed"
4180 }
4181
4182 test_112_check() {
4183         find $DIR/$tdir/
4184         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
4185                 error "src_child still exists after rename"
4186
4187         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
4188                 error "missing file(a) after rename"
4189 }
4190
4191 test_112a() {
4192         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4193         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4194                 skip "Need MDS version at least 2.7.56"
4195
4196         ([ $FAILURE_MODE == "HARD" ] &&
4197                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4198                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4199                 return 0
4200
4201         test_112_rename_prepare
4202         replay_barrier mds1
4203
4204         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4205                 error "rename dir cross MDT failed!"
4206         fail mds1
4207
4208         test_112_check
4209         rm -rf $DIR/$tdir || error "rmdir failed"
4210 }
4211 run_test 112a "DNE: cross MDT rename, fail MDT1"
4212
4213 test_112b() {
4214         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4215         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4216                 skip "Need MDS version at least 2.7.56"
4217
4218         ([ $FAILURE_MODE == "HARD" ] &&
4219                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4220                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4221                 return 0
4222
4223         test_112_rename_prepare
4224         replay_barrier mds2
4225
4226         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4227                 error "rename dir cross MDT failed!"
4228
4229         fail mds2
4230
4231         test_112_check
4232         rm -rf $DIR/$tdir || error "rmdir failed"
4233 }
4234 run_test 112b "DNE: cross MDT rename, fail MDT2"
4235
4236 test_112c() {
4237         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4238         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4239                 skip "Need MDS version at least 2.7.56"
4240
4241         ([ $FAILURE_MODE == "HARD" ] &&
4242                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4243                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4244                 return 0
4245
4246         test_112_rename_prepare
4247         replay_barrier mds3
4248
4249         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4250                 error "rename dir cross MDT failed!"
4251
4252         fail mds3
4253
4254         test_112_check
4255         rm -rf $DIR/$tdir || error "rmdir failed"
4256 }
4257 run_test 112c "DNE: cross MDT rename, fail MDT3"
4258
4259 test_112d() {
4260         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4261         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4262                 skip "Need MDS version at least 2.7.56"
4263
4264         ([ $FAILURE_MODE == "HARD" ] &&
4265                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4266                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4267                 return 0
4268
4269         test_112_rename_prepare
4270         replay_barrier mds4
4271
4272         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4273                 error "rename dir cross MDT failed!"
4274
4275         fail mds4
4276
4277         test_112_check
4278         rm -rf $DIR/$tdir || error "rmdir failed"
4279 }
4280 run_test 112d "DNE: cross MDT rename, fail MDT4"
4281
4282 test_112e() {
4283         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4284         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4285                 skip "Need MDS version at least 2.7.56"
4286
4287         ([ $FAILURE_MODE == "HARD" ] &&
4288                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4289                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4290                 return 0
4291
4292         test_112_rename_prepare
4293         replay_barrier mds1
4294         replay_barrier mds2
4295
4296         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4297                 error "rename dir cross MDT failed!"
4298
4299         fail mds1,mds2
4300
4301         test_112_check
4302         rm -rf $DIR/$tdir || error "rmdir failed"
4303 }
4304 run_test 112e "DNE: cross MDT rename, fail MDT1 and MDT2"
4305
4306 test_112f() {
4307         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4308         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4309                 skip "Need MDS version at least 2.7.56"
4310
4311         ([ $FAILURE_MODE == "HARD" ] &&
4312                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4313                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4314                 return 0
4315
4316         test_112_rename_prepare
4317         replay_barrier mds1
4318         replay_barrier mds3
4319
4320         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4321                 error "rename dir cross MDT failed!"
4322
4323         fail mds1,mds3
4324
4325         test_112_check
4326         rm -rf $DIR/$tdir || error "rmdir failed"
4327 }
4328 run_test 112f "DNE: cross MDT rename, fail MDT1 and MDT3"
4329
4330 test_112g() {
4331         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4332         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4333                 skip "Need MDS version at least 2.7.56"
4334
4335         ([ $FAILURE_MODE == "HARD" ] &&
4336                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4337                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4338                 return 0
4339
4340         test_112_rename_prepare
4341         replay_barrier mds1
4342         replay_barrier mds4
4343
4344         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4345                 error "rename dir cross MDT failed!"
4346
4347         fail mds1,mds4
4348
4349         test_112_check
4350         rm -rf $DIR/$tdir || error "rmdir failed"
4351 }
4352 run_test 112g "DNE: cross MDT rename, fail MDT1 and MDT4"
4353
4354 test_112h() {
4355         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4356         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4357                 skip "Need MDS version at least 2.7.56"
4358
4359         ([ $FAILURE_MODE == "HARD" ] &&
4360                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4361                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4362                 return 0
4363
4364         test_112_rename_prepare
4365         replay_barrier mds2
4366         replay_barrier mds3
4367
4368         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4369                 error "rename dir cross MDT failed!"
4370
4371         fail mds2,mds3
4372
4373         test_112_check
4374         rm -rf $DIR/$tdir || error "rmdir failed"
4375 }
4376 run_test 112h "DNE: cross MDT rename, fail MDT2 and MDT3"
4377
4378 test_112i() {
4379         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4380         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4381                 skip "Need MDS version at least 2.7.56"
4382
4383         ([ $FAILURE_MODE == "HARD" ] &&
4384                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4385                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4386                 return 0
4387
4388         test_112_rename_prepare
4389         replay_barrier mds2
4390         replay_barrier mds4
4391
4392         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4393                 error "rename dir cross MDT failed!"
4394
4395         fail mds2,mds4
4396
4397         test_112_check
4398         rm -rf $DIR/$tdir || error "rmdir failed"
4399 }
4400 run_test 112i "DNE: cross MDT rename, fail MDT2 and MDT4"
4401
4402 test_112j() {
4403         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4404         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4405                 skip "Need MDS version at least 2.7.56"
4406
4407         ([ $FAILURE_MODE == "HARD" ] &&
4408                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4409                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4410                 return 0
4411
4412         test_112_rename_prepare
4413         replay_barrier mds3
4414         replay_barrier mds4
4415
4416         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4417                 error "rename dir cross MDT failed!"
4418
4419         fail mds3,mds4
4420
4421         test_112_check
4422         rm -rf $DIR/$tdir || error "rmdir failed"
4423 }
4424 run_test 112j "DNE: cross MDT rename, fail MDT3 and MDT4"
4425
4426 test_112k() {
4427         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4428         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4429                 skip "Need MDS version at least 2.7.56"
4430
4431         ([ $FAILURE_MODE == "HARD" ] &&
4432                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4433                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4434                 return 0
4435
4436         test_112_rename_prepare
4437         replay_barrier mds1
4438         replay_barrier mds2
4439         replay_barrier mds3
4440
4441         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4442                 error "rename dir cross MDT failed!"
4443
4444         fail mds1,mds2,mds3
4445
4446         test_112_check
4447         rm -rf $DIR/$tdir || error "rmdir failed"
4448 }
4449 run_test 112k "DNE: cross MDT rename, fail MDT1,MDT2,MDT3"
4450
4451 test_112l() {
4452         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4453         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4454                 skip "Need MDS version at least 2.7.56"
4455
4456         ([ $FAILURE_MODE == "HARD" ] &&
4457                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4458                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4459                 return 0
4460
4461         test_112_rename_prepare
4462         replay_barrier mds1
4463         replay_barrier mds2
4464         replay_barrier mds4
4465
4466         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4467                 error "rename dir cross MDT failed!"
4468
4469         fail mds1,mds2,mds4
4470
4471         test_112_check
4472         rm -rf $DIR/$tdir || error "rmdir failed"
4473 }
4474 run_test 112l "DNE: cross MDT rename, fail MDT1,MDT2,MDT4"
4475
4476 test_112m() {
4477         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4478         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4479                 skip "Need MDS version at least 2.7.56"
4480
4481         ([ $FAILURE_MODE == "HARD" ] &&
4482                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4483                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4484                 return 0
4485
4486         test_112_rename_prepare
4487         replay_barrier mds1
4488         replay_barrier mds3
4489         replay_barrier mds4
4490
4491         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4492                 error "rename dir cross MDT failed!"
4493
4494         fail mds1,mds3,mds4
4495
4496         test_112_check
4497         rm -rf $DIR/$tdir || error "rmdir failed"
4498 }
4499 run_test 112m "DNE: cross MDT rename, fail MDT1,MDT3,MDT4"
4500
4501 test_112n() {
4502         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4503         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4504                 skip "Need MDS version at least 2.7.56"
4505
4506         ([ $FAILURE_MODE == "HARD" ] &&
4507                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4508                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4509                 return 0
4510
4511         test_112_rename_prepare
4512         replay_barrier mds2
4513         replay_barrier mds3
4514         replay_barrier mds4
4515
4516         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4517                 error "rename dir cross MDT failed!"
4518
4519         fail mds2,mds3,mds4
4520
4521         test_112_check
4522         rm -rf $DIR/$tdir || error "rmdir failed"
4523 }
4524 run_test 112n "DNE: cross MDT rename, fail MDT2,MDT3,MDT4"
4525
4526 test_115() {
4527         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4528         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.56) ]] ||
4529                 skip "Need MDS version at least 2.7.56"
4530
4531         ([ $FAILURE_MODE == "HARD" ] &&
4532                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4533                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4534                 return 0
4535         local fail_index=0
4536         local index
4537         local i
4538         local j
4539
4540         mkdir -p $DIR/$tdir
4541         for ((j=0;j<$((MDSCOUNT));j++)); do
4542                 fail_index=$((fail_index+1))
4543                 index=$((fail_index % MDSCOUNT))
4544                 replay_barrier mds$((index + 1))
4545                 for ((i=0;i<5;i++)); do
4546                         test_mkdir -i$index -c$MDSCOUNT $DIR/$tdir/test_$i ||
4547                                 error "create striped dir $DIR/$tdir/test_$i"
4548                 done
4549
4550                 fail mds$((index + 1))
4551                 for ((i=0;i<5;i++)); do
4552                         checkstat -t dir $DIR/$tdir/test_$i ||
4553                                 error "$DIR/$tdir/test_$i does not exist!"
4554                 done
4555                 rm -rf $DIR/$tdir/test_* ||
4556                                 error "rmdir fails"
4557         done
4558 }
4559 run_test 115 "failover for create/unlink striped directory"
4560
4561 test_116a() {
4562         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4563         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
4564                 skip "Do not support large update log before 2.7.55" &&
4565                 return 0
4566         ([ $FAILURE_MODE == "HARD" ] &&
4567                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4568                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4569                 return 0
4570         local fail_index=0
4571
4572         mkdir -p $DIR/$tdir
4573         replay_barrier mds1
4574
4575         # OBD_FAIL_SPLIT_UPDATE_REC       0x1702
4576         do_facet mds1 "lctl set_param fail_loc=0x80001702"
4577         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
4578
4579         fail mds1
4580         $CHECKSTAT -t dir $DIR/$tdir/striped_dir ||
4581                 error "stried_dir does not exists"
4582 }
4583 run_test 116a "large update log master MDT recovery"
4584
4585 test_116b() {
4586         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4587         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
4588                 skip "Do not support large update log before 2.7.55" &&
4589                 return 0
4590
4591         ([ $FAILURE_MODE == "HARD" ] &&
4592                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4593                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4594                 return 0
4595         local fail_index=0
4596
4597         mkdir -p $DIR/$tdir
4598         replay_barrier mds2
4599
4600         # OBD_FAIL_SPLIT_UPDATE_REC       0x1702
4601         do_facet mds2 "lctl set_param fail_loc=0x80001702"
4602         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir
4603
4604         fail mds2
4605         $CHECKSTAT -t dir $DIR/$tdir/striped_dir ||
4606                 error "stried_dir does not exists"
4607 }
4608 run_test 116b "large update log slave MDT recovery"
4609
4610 test_117() {
4611         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4612         ([ $FAILURE_MODE == "HARD" ] &&
4613                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4614                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4615                 return 0
4616         local index
4617         local mds_indexs
4618
4619         mkdir -p $DIR/$tdir
4620         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/remote_dir
4621         $LFS setdirstripe -i1 -c$MDSCOUNT $DIR/$tdir/remote_dir_1
4622         sleep 2
4623
4624         # Let's set rdonly on all MDTs, so client will send
4625         # replay requests on all MDTs and replay these requests
4626         # at the same time. This test will verify the recovery
4627         # will not be deadlock in this case, LU-7531.
4628         for ((index = 0; index < $((MDSCOUNT)); index++)); do
4629                 replay_barrier mds$((index + 1))
4630                 if [ -z $mds_indexs ]; then
4631                         mds_indexs="${mds_indexs}mds$((index+1))"
4632                 else
4633                         mds_indexs="${mds_indexs},mds$((index+1))"
4634                 fi
4635         done
4636
4637         rm -rf $DIR/$tdir/remote_dir
4638         rm -rf $DIR/$tdir/remote_dir_1
4639
4640         fail $mds_indexs
4641
4642         rm -rf $DIR/$tdir || error "rmdir failed"
4643 }
4644 run_test 117 "DNE: cross MDT unlink, fail MDT1 and MDT2"
4645
4646 test_118() {
4647         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4648         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4649                 skip "Do not support large update log before 2.7.64" &&
4650                 return 0
4651
4652         mkdir -p $DIR/$tdir
4653
4654         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
4655                 error "setdirstripe fails"
4656         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir1 ||
4657                 error "setdirstripe fails 1"
4658         rm -rf $DIR/$tdir/striped_dir* || error "rmdir fails"
4659
4660         # OBD_FAIL_INVALIDATE_UPDATE       0x1705
4661         do_facet mds1 "lctl set_param fail_loc=0x1705"
4662         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir
4663         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir1
4664         do_facet mds1 "lctl set_param fail_loc=0x0"
4665
4666         replay_barrier mds1
4667         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir
4668         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir1
4669         fail mds1
4670
4671         true
4672 }
4673 run_test 118 "invalidate osp update will not cause update log corruption"
4674
4675 test_119() {
4676         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4677         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4678                 skip "Do not support large update log before 2.7.64" &&
4679                 return 0
4680         local stripe_count
4681         local hard_timeout=$(do_facet mds1 \
4682                 "lctl get_param -n mdt.$FSNAME-MDT0000.recovery_time_hard")
4683
4684         local clients=${CLIENTS:-$HOSTNAME}
4685         local time_min=$(recovery_time_min)
4686
4687         mkdir -p $DIR/$tdir
4688         mkdir $DIR/$tdir/tmp
4689         rmdir $DIR/$tdir/tmp
4690
4691         replay_barrier mds1
4692         mkdir $DIR/$tdir/dir_1
4693         for ((i = 0; i < 20; i++)); do
4694                 $LFS setdirstripe -i0 -c2 $DIR/$tdir/stripe_dir-$i
4695         done
4696
4697         stop mds1
4698         change_active mds1
4699         wait_for_facet mds1
4700
4701         #define OBD_FAIL_TGT_REPLAY_DELAY  0x714
4702         do_facet mds1 $LCTL set_param fail_loc=0x80000714
4703         #sleep (timeout + 5), so mds will evict the client exports,
4704         #but DNE update recovery will keep going.
4705         do_facet mds1 $LCTL set_param fail_val=$((time_min + 5))
4706
4707         mount_facet mds1 "-o recovery_time_hard=$time_min"
4708
4709         wait_clients_import_state "$clients" mds1 FULL
4710
4711         clients_up || clients_up || error "failover df: $?"
4712
4713         #revert back the hard timeout
4714         do_facet mds1 $LCTL set_param \
4715                 mdt.$FSNAME-MDT0000.recovery_time_hard=$hard_timeout
4716
4717         for ((i = 0; i < 20; i++)); do
4718                 stripe_count=$($LFS getdirstripe -c $DIR/$tdir/stripe_dir-$i)
4719                 [ $stripe_count == 2 ] || {
4720                         error "stripe_dir-$i creation replay fails"
4721                         break
4722                 }
4723         done
4724 }
4725 run_test 119 "timeout of normal replay does not cause DNE replay fails  "
4726
4727 test_120() {
4728         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4729         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4730                 skip "Do not support large update log before 2.7.64" &&
4731                 return 0
4732
4733         mkdir $DIR/$tdir
4734         replay_barrier_nosync mds1
4735         for ((i = 0; i < 20; i++)); do
4736                 mkdir $DIR/$tdir/dir-$i || {
4737                         error "create dir-$i fails"
4738                         break
4739                 }
4740                 $LFS setdirstripe -i0 -c2 $DIR/$tdir/stripe_dir-$i || {
4741                         error "create stripe_dir-$i fails"
4742                         break
4743                 }
4744         done
4745
4746         fail_abort mds1
4747
4748         for ((i = 0; i < 20; i++)); do
4749                 [ ! -e "$DIR/$tdir/dir-$i" ] || {
4750                         error "dir-$i still exists"
4751                         break
4752                 }
4753                 [ ! -e "$DIR/$tdir/stripe_dir-$i" ] || {
4754                         error "stripe_dir-$i still exists"
4755                         break
4756                 }
4757         done
4758 }
4759 run_test 120 "DNE fail abort should stop both normal and DNE replay"
4760
4761 test_121() {
4762         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.90) ] &&
4763                 skip "Don't support it before 2.11" &&
4764                 return 0
4765
4766         local at_max_saved=$(at_max_get mds)
4767
4768         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4769         cancel_lru_locks mdc
4770
4771         multiop_bg_pause $DIR/$tfile s_s || error "multiop $DIR/$tfile failed"
4772         mpid=$!
4773
4774         lctl set_param -n ldlm.cancel_unused_locks_before_replay "0"
4775
4776         stop mds1
4777         change_active mds1
4778         wait_for_facet mds1
4779
4780         #define OBD_FAIL_TGT_RECOVERY_REQ_RACE  0x721
4781         do_facet $SINGLEMDS "lctl set_param fail_loc=0x721 fail_val=0"
4782         at_max_set 0 mds
4783
4784         mount_facet mds1
4785         wait_clients_import_state "$clients" mds1 FULL
4786         clients_up || clients_up || error "failover df: $?"
4787
4788         kill -USR1 $mpid
4789         wait $mpid || error "multiop_bg_pause pid failed"
4790
4791         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
4792         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
4793         at_max_set $at_max_saved mds
4794         rm -f $DIR/$tfile
4795 }
4796 run_test 121 "lock replay timed out and race"
4797
4798 test_130a() {
4799         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.90) ] &&
4800                 skip "Do not support Data-on-MDT before 2.11"
4801
4802         replay_barrier $SINGLEMDS
4803         $LFS setstripe -E 1M -L mdt -E EOF -c 2 $DIR/$tfile
4804         fail $SINGLEMDS
4805
4806         [ $($LFS getstripe -L $DIR/$tfile) == "mdt" ] ||
4807                 error "Fail to replay DoM file creation"
4808 }
4809 run_test 130a "DoM file create (setstripe) replay"
4810
4811 test_130b() {
4812         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.90) ] &&
4813                 skip "Do not support Data-on-MDT before 2.11"
4814
4815         mkdir $DIR/$tdir
4816         $LFS setstripe -E 1M -L mdt -E EOF -c 2 $DIR/$tdir
4817         replay_barrier $SINGLEMDS
4818         touch $DIR/$tdir/$tfile
4819         fail $SINGLEMDS
4820
4821         [ $($LFS getstripe -L $DIR/$tdir/$tfile) == "mdt" ] ||
4822                 error "Fail to replay DoM file creation"
4823 }
4824 run_test 130b "DoM file create (inherited) replay"
4825
4826 test_131a() {
4827         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.90) ] &&
4828                 skip "Do not support Data-on-MDT before 2.11"
4829
4830         $LFS setstripe -E 1M -L mdt -E EOF -c 2 $DIR/$tfile
4831         replay_barrier $SINGLEMDS
4832         echo "dom_data" | dd of=$DIR/$tfile bs=8 count=1
4833         # lock is not canceled and will be replayed
4834         fail $SINGLEMDS
4835
4836         [ $(cat $DIR/$tfile) == "dom_data" ] ||
4837                 error "Wrong file content after failover"
4838 }
4839 run_test 131a "DoM file write lock replay"
4840
4841 test_131b() {
4842         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.90) ] &&
4843                 skip "Do not support Data-on-MDT before 2.11"
4844
4845         $LFS setstripe -E 1M -L mdt -E EOF -c 2 $DIR/$tfile
4846         replay_barrier $SINGLEMDS
4847         echo "dom_data" | dd of=$DIR/$tfile bs=8 count=1
4848         cancel_lru_locks mdc
4849
4850         fail $SINGLEMDS
4851
4852         [ $(cat $DIR/$tfile) == "dom_data" ] ||
4853                 error "Wrong file content after failover"
4854 }
4855 run_test 131b "DoM file write replay"
4856
4857 test_132a() {
4858         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.90) ] &&
4859                 skip "Do not support PFL files before 2.10"
4860
4861         $LFS setstripe -E 1M -c 1 -E EOF -c 2 $DIR/$tfile
4862         replay_barrier $SINGLEMDS
4863         # write over the first component size cause next component instantiation
4864         dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 seek=1 ||
4865                 error "dd to $DIR/$tfile failed"
4866         lfs getstripe $DIR/$tfile
4867
4868         cksum=$(md5sum $DIR/$tfile | awk '{print $1}')
4869         $LFS getstripe -I2 $DIR/$tfile | grep -q lmm_objects ||
4870                 error "Component #1 was not instantiated"
4871
4872         fail $SINGLEMDS
4873
4874         lfs getstripe $DIR/$tfile
4875         $LFS getstripe -I2 $DIR/$tfile | grep -q lmm_objects ||
4876                 error "Component #1 instantiation was not replayed"
4877         cksum2=$(md5sum $DIR/$tfile | awk '{print $1}')
4878         if [ $cksum != $cksum2 ] ; then
4879                 error_noexit "New cksum $cksum2 does not match original $cksum"
4880         fi
4881 }
4882 run_test 132a "PFL new component instantiate replay"
4883
4884 test_133() {
4885         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4886         ([ $FAILURE_MODE == "HARD" ] &&
4887                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4888                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4889                 return 0
4890
4891         local remote_dir=$DIR/$tdir/remote_dir
4892
4893         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4894         $LFS mkdir -i 1 $remote_dir
4895
4896         umount $MOUNT
4897         do_facet mds2 $LCTL set_param seq.srv*MDT0001.space=clear
4898
4899         zconf_mount $(hostname) $MOUNT
4900         client_up || return 1
4901
4902         #define OBD_FAIL_MDS_ALL_REQUEST_NET     0x123
4903         # SEQ_QUERY                       = 700
4904         do_facet mds1 $LCTL set_param fail_val=700 fail_loc=0x80000123
4905         cp /etc/hosts $remote_dir/file &
4906         local pid=$!
4907         sleep 1
4908
4909         fail_nodf mds1
4910
4911         wait $pid || error "cp failed"
4912         rm -rf $DIR/$tdir || error "rmdir failed"
4913
4914         return 0
4915 }
4916 run_test 133 "check resend of ongoing requests for lwp during failover"
4917
4918 test_134() {
4919         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return 0
4920
4921         pool_add pool_134
4922         pool_add_targets pool_134 1 1
4923
4924         mkdir $DIR/$tdir
4925         $LFS setstripe -p pool_134 $DIR/$tdir
4926
4927         replay_barrier mds1
4928
4929         touch $DIR/$tdir/$tfile
4930
4931         fail mds1
4932
4933         [ -f $DIR/$tdir/$tfile ] || error "file does not exist"
4934 }
4935 run_test 134 "replay creation of a file created in a pool"
4936
4937 complete $SECONDS
4938 check_and_cleanup_lustre
4939 exit_status