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