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