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