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