Whamcloud - gitweb
LU-10612 tests: reply_single.sh,test_48: No space left
[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         # let the MDS discover the OST failure, attempt to recover, fail
1142         # and recover again.
1143         sleep $((3 * TIMEOUT))
1144
1145         createmany -o $DIR/$tfile 20 20 ||
1146                 error "createmany recraete $DIR/$tfile failed"
1147         unlinkmany $DIR/$tfile 40 || error "unlinkmany $DIR/$tfile failed"
1148         return 0
1149 }
1150 run_test 48 "MDS->OSC failure during precreate cleanup (2824)"
1151
1152 test_50() {
1153         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $ost1_svc)
1154         local oscdev=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
1155                 grep $mdtosc | awk '{print $1}')
1156         [ "$oscdev" ] || error "could not find OSC device on MDS"
1157         do_facet $SINGLEMDS $LCTL --device $oscdev recover ||
1158                 error "OSC device $oscdev recovery failed"
1159         do_facet $SINGLEMDS $LCTL --device $oscdev recover ||
1160                 error "second OSC device $oscdev recovery failed"
1161         # give the mds_lov_sync threads a chance to run
1162         sleep 5
1163 }
1164 run_test 50 "Double OSC recovery, don't LASSERT (3812)"
1165
1166 # b3764 timed out lock replay
1167 test_52() {
1168         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.6.90) ] &&
1169                 skip "MDS prior to 2.6.90 handle LDLM_REPLY_NET incorrectly" &&
1170                 return 0
1171
1172         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
1173         cancel_lru_locks mdc
1174
1175         multiop_bg_pause $DIR/$tfile s_s || error "multiop $DIR/$tfile failed"
1176         mpid=$!
1177
1178         #define OBD_FAIL_MDS_LDLM_REPLY_NET     0x157
1179         lctl set_param -n ldlm.cancel_unused_locks_before_replay "0"
1180         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000157"
1181
1182         fail $SINGLEMDS || error "fail $SINGLEMDS failed"
1183         kill -USR1 $mpid
1184         wait $mpid || error "multiop_bg_pause pid failed"
1185
1186         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1187         lctl set_param fail_loc=0x0
1188         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
1189         rm -f $DIR/$tfile
1190 }
1191 run_test 52 "time out lock replay (3764)"
1192
1193 # bug 3462 - simultaneous MDC requests
1194 test_53a() {
1195         [[ $(lctl get_param mdc.*.import |
1196              grep "connect_flags:.*multi_mod_rpc") ]] ||
1197                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
1198
1199         cancel_lru_locks mdc    # cleanup locks from former test cases
1200         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1201         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1202         multiop $DIR/${tdir}-1/f O_c &
1203         close_pid=$!
1204         # give multiop a change to open
1205         sleep 1
1206
1207         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1208         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1209         kill -USR1 $close_pid
1210         cancel_lru_locks mdc    # force the close
1211         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1212
1213         mcreate $DIR/${tdir}-2/f || error "mcreate $DIR/${tdir}-2/f failed"
1214
1215         # close should still be here
1216         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1217
1218         replay_barrier_nodf $SINGLEMDS
1219         fail $SINGLEMDS
1220         wait $close_pid || error "close_pid $close_pid failed"
1221
1222         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1223                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1224         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1225                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1226         rm -rf $DIR/${tdir}-*
1227 }
1228 run_test 53a "|X| close request while two MDC requests in flight"
1229
1230 test_53b() {
1231         cancel_lru_locks mdc    # cleanup locks from former test cases
1232
1233         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1234         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1235         multiop_bg_pause $DIR/${tdir}-1/f O_c ||
1236                 error "multiop_bg_pause $DIR/${tdir}-1/f failed"
1237         close_pid=$!
1238
1239         #define OBD_FAIL_MDS_REINT_NET 0x107
1240         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1241         mcreate $DIR/${tdir}-2/f &
1242         open_pid=$!
1243         sleep 1
1244
1245         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1246         kill -USR1 $close_pid
1247         cancel_lru_locks mdc    # force the close
1248         wait $close_pid || error "close_pid $close_pid failed"
1249         # open should still be here
1250         [ -d /proc/$open_pid ] || error "open_pid doesn't exist"
1251
1252         replay_barrier_nodf $SINGLEMDS
1253         fail $SINGLEMDS
1254         wait $open_pid || error "open_pid failed"
1255
1256         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1257                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1258         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1259                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1260         rm -rf $DIR/${tdir}-*
1261 }
1262 run_test 53b "|X| open request while two MDC requests in flight"
1263
1264 test_53c() {
1265         cancel_lru_locks mdc    # cleanup locks from former test cases
1266
1267         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1268         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1269         multiop $DIR/${tdir}-1/f O_c &
1270         close_pid=$!
1271
1272         #define OBD_FAIL_MDS_REINT_NET 0x107
1273         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1274         mcreate $DIR/${tdir}-2/f &
1275         open_pid=$!
1276         sleep 1
1277
1278         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1279         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1280         kill -USR1 $close_pid
1281         cancel_lru_locks mdc    # force the close
1282
1283         #bz20647: make sure all pids exist before failover
1284         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1285         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1286         replay_barrier_nodf $SINGLEMDS
1287         fail_nodf $SINGLEMDS
1288         wait $open_pid || error "open_pid failed"
1289         sleep 2
1290         # close should be gone
1291         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1292         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1293
1294         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1295                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1296         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1297                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1298         rm -rf $DIR/${tdir}-*
1299 }
1300 run_test 53c "|X| open request and close request while two MDC requests in flight"
1301
1302 test_53d() {
1303         [[ $(lctl get_param mdc.*.import |
1304              grep "connect_flags:.*multi_mod_rpc") ]] ||
1305                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
1306
1307         cancel_lru_locks mdc    # cleanup locks from former test cases
1308
1309         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1310         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1311         multiop $DIR/${tdir}-1/f O_c &
1312         close_pid=$!
1313         # give multiop a chance to open
1314         sleep 1
1315
1316         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1317         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1318         kill -USR1 $close_pid
1319         cancel_lru_locks mdc    # force the close
1320         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1321         mcreate $DIR/${tdir}-2/f || error "mcreate $DIR/${tdir}-2/f failed"
1322
1323         # close should still be here
1324         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1325         fail $SINGLEMDS
1326         wait $close_pid || error "close_pid failed"
1327
1328         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1329                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1330         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1331                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1332         rm -rf $DIR/${tdir}-*
1333 }
1334 run_test 53d "close reply while two MDC requests in flight"
1335
1336 test_53e() {
1337         cancel_lru_locks mdc    # cleanup locks from former test cases
1338
1339         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1340         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1341         multiop $DIR/${tdir}-1/f O_c &
1342         close_pid=$!
1343
1344         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1345         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1346         mcreate $DIR/${tdir}-2/f &
1347         open_pid=$!
1348         sleep 1
1349
1350         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1351         kill -USR1 $close_pid
1352         cancel_lru_locks mdc    # force the close
1353         wait $close_pid || error "close_pid failed"
1354         # open should still be here
1355         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1356
1357         replay_barrier_nodf $SINGLEMDS
1358         fail $SINGLEMDS
1359         wait $open_pid || error "open_pid failed"
1360
1361         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1362                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1363         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1364                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1365         rm -rf $DIR/${tdir}-*
1366 }
1367 run_test 53e "|X| open reply while two MDC requests in flight"
1368
1369 test_53f() {
1370         cancel_lru_locks mdc    # cleanup locks from former test cases
1371
1372         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1373         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1374         multiop $DIR/${tdir}-1/f O_c &
1375         close_pid=$!
1376
1377         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1378         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1379         mcreate $DIR/${tdir}-2/f &
1380         open_pid=$!
1381         sleep 1
1382
1383         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1384         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1385         kill -USR1 $close_pid
1386         cancel_lru_locks mdc    # force the close
1387
1388         #bz20647: make sure all pids are exists before failover
1389         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1390         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1391         replay_barrier_nodf $SINGLEMDS
1392         fail_nodf $SINGLEMDS
1393         wait $open_pid || error "open_pid failed"
1394         sleep 2
1395         # close should be gone
1396         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1397         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1398
1399         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1400                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1401         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1402                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1403         rm -rf $DIR/${tdir}-*
1404 }
1405 run_test 53f "|X| open reply and close reply while two MDC requests in flight"
1406
1407 test_53g() {
1408         cancel_lru_locks mdc    # cleanup locks from former test cases
1409
1410         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1411         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1412         multiop $DIR/${tdir}-1/f O_c &
1413         close_pid=$!
1414
1415         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1416         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1417         mcreate $DIR/${tdir}-2/f &
1418         open_pid=$!
1419         sleep 1
1420
1421         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1422         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1423         kill -USR1 $close_pid
1424         cancel_lru_locks mdc    # force the close
1425         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1426
1427         #bz20647: make sure all pids are exists before failover
1428         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1429         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1430         replay_barrier_nodf $SINGLEMDS
1431         fail_nodf $SINGLEMDS
1432         wait $open_pid || error "open_pid failed"
1433         sleep 2
1434         # close should be gone
1435         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1436
1437         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1438                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1439         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1440                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1441         rm -rf $DIR/${tdir}-*
1442 }
1443 run_test 53g "|X| drop open reply and close request while close and open are both in flight"
1444
1445 test_53h() {
1446         cancel_lru_locks mdc    # cleanup locks from former test cases
1447
1448         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1449         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1450         multiop $DIR/${tdir}-1/f O_c &
1451         close_pid=$!
1452
1453         #define OBD_FAIL_MDS_REINT_NET 0x107
1454         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1455         mcreate $DIR/${tdir}-2/f &
1456         open_pid=$!
1457         sleep 1
1458
1459         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1460         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1461         kill -USR1 $close_pid
1462         cancel_lru_locks mdc    # force the close
1463         sleep 1
1464
1465         #bz20647: make sure all pids are exists before failover
1466         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1467         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1468         replay_barrier_nodf $SINGLEMDS
1469         fail_nodf $SINGLEMDS
1470         wait $open_pid || error "open_pid failed"
1471         sleep 2
1472         # close should be gone
1473         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1474         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1475
1476         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1477                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1478         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1479                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1480         rm -rf $DIR/${tdir}-*
1481 }
1482 run_test 53h "open request and close reply while two MDC requests in flight"
1483
1484 #b3761 ASSERTION(hash != 0) failed
1485 test_55() {
1486 # OBD_FAIL_MDS_OPEN_CREATE | OBD_FAIL_ONCE
1487     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012b"
1488     touch $DIR/$tfile &
1489     # give touch a chance to run
1490     sleep 5
1491     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1492     rm $DIR/$tfile
1493     return 0
1494 }
1495 run_test 55 "let MDS_CHECK_RESENT return the original return code instead of 0"
1496
1497 #b3440 ASSERTION(rec->ur_fid2->id) failed
1498 test_56() {
1499     ln -s foo $DIR/$tfile
1500     replay_barrier $SINGLEMDS
1501     #drop_reply "cat $DIR/$tfile"
1502     fail $SINGLEMDS
1503     sleep 10
1504 }
1505 run_test 56 "don't replay a symlink open request (3440)"
1506
1507 #recovery one mds-ost setattr from llog
1508 test_57() {
1509         #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1510         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1511         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
1512         replay_barrier $SINGLEMDS
1513         fail $SINGLEMDS
1514         wait_recovery_complete $SINGLEMDS || error "MDS recovery is not done"
1515         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
1516         $CHECKSTAT -t file $DIR/$tfile ||
1517                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
1518         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1519         rm $DIR/$tfile
1520 }
1521 run_test 57 "test recovery from llog for setattr op"
1522
1523 cleanup_58() {
1524         zconf_umount $(hostname) $MOUNT2
1525         trap - EXIT
1526 }
1527
1528 #recovery many mds-ost setattr from llog
1529 test_58a() {
1530         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1531         #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1532         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1533         createmany -o $DIR/$tdir/$tfile-%d 2500
1534         replay_barrier $SINGLEMDS
1535         fail $SINGLEMDS
1536         sleep 2
1537         $CHECKSTAT -t file $DIR/$tdir/$tfile-* >/dev/null ||
1538                 error "$CHECKSTAT $DIR/$tfile-* attribute check failed"
1539         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1540         unlinkmany $DIR/$tdir/$tfile-%d 2500 ||
1541                 error "unlinkmany $DIR/$tfile failed"
1542         rmdir $DIR/$tdir
1543 }
1544 run_test 58a "test recovery from llog for setattr op (test llog_gen_rec)"
1545
1546 test_58b() {
1547         local orig
1548         local new
1549
1550         trap cleanup_58 EXIT
1551
1552         large_xattr_enabled &&
1553                 orig="$(generate_string $(max_xattr_size))" || orig="bar"
1554         # Original extended attribute can be long. Print a small version of
1555         # attribute if an error occurs
1556         local sm_msg=$(printf "%.9s" $orig)
1557
1558         mount_client $MOUNT2 || error "mount_client on $MOUNT2 failed"
1559         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1560         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
1561         replay_barrier $SINGLEMDS
1562         setfattr -n trusted.foo -v $orig $DIR/$tdir/$tfile
1563         fail $SINGLEMDS
1564         new=$(get_xattr_value trusted.foo $MOUNT2/$tdir/$tfile)
1565         [[ "$new" = "$orig" ]] ||
1566                 error "xattr set ($sm_msg...) differs from xattr get ($new)"
1567         rm -f $DIR/$tdir/$tfile
1568         rmdir $DIR/$tdir
1569         cleanup_58
1570         wait_clients_import_state ${CLIENTS:-$HOSTNAME} "mgs" FULL
1571 }
1572 run_test 58b "test replay of setxattr op"
1573
1574 test_58c() { # bug 16570
1575         local orig
1576         local orig1
1577         local new
1578
1579         trap cleanup_58 EXIT
1580
1581         if large_xattr_enabled; then
1582                 local xattr_size=$(max_xattr_size)
1583                 orig="$(generate_string $((xattr_size / 2)))"
1584                 orig1="$(generate_string $xattr_size)"
1585         else
1586                 orig="bar"
1587                 orig1="bar1"
1588         fi
1589
1590         # PING_INTERVAL max(obd_timeout / 4, 1U)
1591         sleep $((TIMEOUT / 4))
1592
1593         # Original extended attribute can be long. Print a small version of
1594         # attribute if an error occurs
1595         local sm_msg=$(printf "%.9s" $orig)
1596         local sm_msg1=$(printf "%.9s" $orig1)
1597
1598         mount_client $MOUNT2 || error "mount_client on $MOUNT2 failed"
1599         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1600         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
1601         drop_request "setfattr -n trusted.foo -v $orig $DIR/$tdir/$tfile" ||
1602                 error "drop_request for setfattr failed"
1603         new=$(get_xattr_value trusted.foo $MOUNT2/$tdir/$tfile)
1604         [[ "$new" = "$orig" ]] ||
1605                 error "xattr set ($sm_msg...) differs from xattr get ($new)"
1606         drop_reint_reply "setfattr -n trusted.foo1 \
1607                           -v $orig1 $DIR/$tdir/$tfile" ||
1608                 error "drop_reint_reply for setfattr failed"
1609         new=$(get_xattr_value trusted.foo1 $MOUNT2/$tdir/$tfile)
1610         [[ "$new" = "$orig1" ]] ||
1611                 error "second xattr set ($sm_msg1...) differs xattr get ($new)"
1612         rm -f $DIR/$tdir/$tfile
1613         rmdir $DIR/$tdir
1614         cleanup_58
1615 }
1616 run_test 58c "resend/reconstruct setxattr op"
1617
1618 # log_commit_thread vs filter_destroy race used to lead to import use after free
1619 # bug 11658
1620 test_59() {
1621         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1622
1623         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1624         createmany -o $DIR/$tdir/$tfile-%d 200 ||
1625                 error "createmany create files failed"
1626         sync
1627         unlinkmany $DIR/$tdir/$tfile-%d 200 ||
1628                 error "unlinkmany $DIR/$tdir/$tfile failed"
1629         #define OBD_FAIL_PTLRPC_DELAY_RECOV       0x507
1630         do_facet ost1 "lctl set_param fail_loc=0x507"
1631         fail ost1
1632         fail $SINGLEMDS
1633         do_facet ost1 "lctl set_param fail_loc=0x0"
1634         sleep 20
1635         rmdir $DIR/$tdir
1636 }
1637 run_test 59 "test log_commit_thread vs filter_destroy race"
1638
1639 # race between add unlink llog vs cat log init in post_recovery (only for b1_6)
1640 # bug 12086: should no oops and No ctxt error for this test
1641 test_60() {
1642         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1643         createmany -o $DIR/$tdir/$tfile-%d 200 ||
1644                 error "createmany create files failed"
1645         replay_barrier $SINGLEMDS
1646         unlinkmany $DIR/$tdir/$tfile-%d 0 100
1647         fail $SINGLEMDS
1648         unlinkmany $DIR/$tdir/$tfile-%d 100 100
1649         local no_ctxt=$(dmesg | grep "No ctxt")
1650         [ -z "$no_ctxt" ] || error "ctxt is not initialized in recovery"
1651 }
1652 run_test 60 "test llog post recovery init vs llog unlink"
1653
1654 #test race  llog recovery thread vs llog cleanup
1655 test_61a() {    # was test_61
1656         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1657
1658         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1659         createmany -o $DIR/$tdir/$tfile-%d 800 ||
1660                 error "createmany create files failed"
1661         replay_barrier ost1
1662         unlinkmany $DIR/$tdir/$tfile-%d 800
1663         #   OBD_FAIL_OST_LLOG_RECOVERY_TIMEOUT 0x221
1664         set_nodes_failloc "$(osts_nodes)" 0x80000221
1665         facet_failover ost1
1666         sleep 10
1667         fail ost1
1668         sleep 30
1669         set_nodes_failloc "$(osts_nodes)" 0x0
1670
1671         $CHECKSTAT -t file $DIR/$tdir/$tfile-* &&
1672                 error "$CHECKSTAT $DIR/$tdir/$tfile attribute check should fail"
1673         rmdir $DIR/$tdir
1674 }
1675 run_test 61a "test race llog recovery vs llog cleanup"
1676
1677 #test race  mds llog sync vs llog cleanup
1678 test_61b() {
1679         #   OBD_FAIL_MDS_LLOG_SYNC_TIMEOUT 0x13a
1680         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013a"
1681         facet_failover $SINGLEMDS
1682         sleep 10
1683         fail $SINGLEMDS
1684         do_facet client dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 ||
1685                 error "dd failed"
1686 }
1687 run_test 61b "test race mds llog sync vs llog cleanup"
1688
1689 #test race  cancel cookie cb vs llog cleanup
1690 test_61c() {
1691         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1692
1693         #   OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT 0x222
1694         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
1695         set_nodes_failloc "$(osts_nodes)" 0x80000222
1696         rm $DIR/$tfile
1697         sleep 10
1698         fail ost1
1699         set_nodes_failloc "$(osts_nodes)" 0x0
1700 }
1701 run_test 61c "test race mds llog sync vs llog cleanup"
1702
1703 test_61d() { # bug 16002 # bug 17466 # bug 22137
1704 #   OBD_FAIL_OBD_LLOG_SETUP        0x605
1705     stop mgs
1706     do_facet mgs "lctl set_param fail_loc=0x80000605"
1707     start mgs $(mgsdevname) $MGS_MOUNT_OPTS &&
1708         error "mgs start should have failed"
1709     do_facet mgs "lctl set_param fail_loc=0"
1710     start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "cannot restart mgs"
1711 }
1712 run_test 61d "error in llog_setup should cleanup the llog context correctly"
1713
1714 test_62() { # Bug 15756 - don't mis-drop resent replay
1715         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1716         replay_barrier $SINGLEMDS
1717         createmany -o $DIR/$tdir/$tfile- 25 ||
1718                 error "createmany create files failed"
1719         #define OBD_FAIL_TGT_REPLAY_DROP         0x707
1720         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000707"
1721         fail $SINGLEMDS
1722         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1723         unlinkmany $DIR/$tdir/$tfile- 25 ||
1724                 error "unlinkmany $DIR/$tdir/$tfile failed"
1725         return 0
1726 }
1727 run_test 62 "don't mis-drop resent replay"
1728
1729 #Adaptive Timeouts (bug 3055)
1730 AT_MAX_SET=0
1731
1732 at_cleanup () {
1733     local var
1734     local facet
1735     local at_new
1736
1737     echo "Cleaning up AT ..."
1738     if [ -n "$ATOLDBASE" ]; then
1739         local at_history=$($LCTL get_param -n at_history)
1740         do_facet $SINGLEMDS "lctl set_param at_history=$at_history" || true
1741         do_facet ost1 "lctl set_param at_history=$at_history" || true
1742     fi
1743
1744         if [ $AT_MAX_SET -ne 0 ]; then
1745                 for facet in mds client ost; do
1746                         var=AT_MAX_SAVE_${facet}
1747                         echo restore AT on $facet to saved value ${!var}
1748                         at_max_set ${!var} $facet
1749                         at_new=$(at_max_get $facet)
1750                         echo Restored AT value on $facet $at_new
1751                         [ $at_new -eq ${!var} ] ||
1752                         error "AT value not restored SAVED ${!var} NEW $at_new"
1753                 done
1754         fi
1755 }
1756
1757 at_start()
1758 {
1759     local at_max_new=600
1760
1761     # Save at_max original values
1762     local facet
1763     if [ $AT_MAX_SET -eq 0 ]; then
1764         # Suppose that all osts have the same at_max
1765         for facet in mds client ost; do
1766             eval AT_MAX_SAVE_${facet}=$(at_max_get $facet)
1767         done
1768     fi
1769     local at_max
1770     for facet in mds client ost; do
1771         at_max=$(at_max_get $facet)
1772         if [ $at_max -ne $at_max_new ]; then
1773             echo "AT value on $facet is $at_max, set it by force temporarily to $at_max_new"
1774             at_max_set $at_max_new $facet
1775             AT_MAX_SET=1
1776         fi
1777     done
1778
1779     if [ -z "$ATOLDBASE" ]; then
1780         ATOLDBASE=$(do_facet $SINGLEMDS "lctl get_param -n at_history")
1781         # speed up the timebase so we can check decreasing AT
1782         do_facet $SINGLEMDS "lctl set_param at_history=8" || true
1783         do_facet ost1 "lctl set_param at_history=8" || true
1784
1785         # sleep for a while to cool down, should be > 8s and also allow
1786         # at least one ping to be sent. simply use TIMEOUT to be safe.
1787         sleep $TIMEOUT
1788     fi
1789 }
1790
1791 test_65a() #bug 3055
1792 {
1793     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1794
1795     at_start || return 0
1796     $LCTL dk > /dev/null
1797     debugsave
1798     $LCTL set_param debug="other"
1799     # Slow down a request to the current service time, this is critical
1800     # because previous tests may have caused this value to increase.
1801     REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
1802                awk '/portal 12/ {print $5}'`
1803     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1804
1805     do_facet $SINGLEMDS lctl set_param fail_val=$((${REQ_DELAY} * 1000))
1806 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1807     do_facet $SINGLEMDS $LCTL set_param fail_loc=0x8000050a
1808     createmany -o $DIR/$tfile 10 > /dev/null
1809     unlinkmany $DIR/$tfile 10 > /dev/null
1810     # check for log message
1811     $LCTL dk | grep "Early reply #" || error "No early reply"
1812     debugrestore
1813     # client should show REQ_DELAY estimates
1814     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1815     sleep 9
1816     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1817 }
1818 run_test 65a "AT: verify early replies"
1819
1820 test_65b() #bug 3055
1821 {
1822         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1823
1824         at_start || return 0
1825         # turn on D_ADAPTTO
1826         debugsave
1827         $LCTL set_param debug="other trace"
1828         $LCTL dk > /dev/null
1829         # Slow down a request to the current service time, this is critical
1830         # because previous tests may have caused this value to increase.
1831         $SETSTRIPE --stripe-index=0 --stripe-count=1 $DIR/$tfile ||
1832                 error "$SETSTRIPE failed for $DIR/$tfile"
1833
1834         multiop $DIR/$tfile Ow1yc
1835         REQ_DELAY=`lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts |
1836                    awk '/portal 6/ {print $5}'`
1837         REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1838
1839         do_facet ost1 lctl set_param fail_val=${REQ_DELAY}
1840         #define OBD_FAIL_OST_BRW_PAUSE_PACK      0x224
1841         do_facet ost1 $LCTL set_param fail_loc=0x224
1842
1843         rm -f $DIR/$tfile
1844         $SETSTRIPE --stripe-index=0 --stripe-count=1 $DIR/$tfile ||
1845                 error "$SETSTRIPE failed"
1846         # force some real bulk transfer
1847         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
1848
1849         do_facet ost1 $LCTL set_param fail_loc=0
1850         # check for log message
1851         $LCTL dk | grep "Early reply #" || error "No early reply"
1852         debugrestore
1853         # client should show REQ_DELAY estimates
1854         lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts | grep portal
1855 }
1856 run_test 65b "AT: verify early replies on packed reply / bulk"
1857
1858 test_66a() #bug 3055
1859 {
1860     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1861
1862     at_start || return 0
1863     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1864     # adjust 5s at a time so no early reply is sent (within deadline)
1865     do_facet $SINGLEMDS "$LCTL set_param fail_val=5000"
1866 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1867     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x8000050a"
1868     createmany -o $DIR/$tfile 20 > /dev/null
1869     unlinkmany $DIR/$tfile 20 > /dev/null
1870     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1871     do_facet $SINGLEMDS "$LCTL set_param fail_val=10000"
1872     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x8000050a"
1873     createmany -o $DIR/$tfile 20 > /dev/null
1874     unlinkmany $DIR/$tfile 20 > /dev/null
1875     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1876     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0"
1877     sleep 9
1878     createmany -o $DIR/$tfile 20 > /dev/null
1879     unlinkmany $DIR/$tfile 20 > /dev/null
1880     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1881     CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $5}')
1882     WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $7}')
1883     echo "Current MDT timeout $CUR, worst $WORST"
1884     [ $CUR -lt $WORST ] || error "Current $CUR should be less than worst $WORST"
1885 }
1886 run_test 66a "AT: verify MDT service time adjusts with no early replies"
1887
1888 test_66b() #bug 3055
1889 {
1890         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1891
1892         at_start || return 0
1893         ORIG=$(lctl get_param -n mdc.${FSNAME}-MDT0000*.timeouts |
1894                 awk '/network/ {print $4}')
1895         $LCTL set_param fail_val=$(($ORIG + 5))
1896         #define OBD_FAIL_PTLRPC_PAUSE_REP      0x50c
1897         $LCTL set_param fail_loc=0x50c
1898         ls $DIR/$tfile > /dev/null 2>&1
1899         $LCTL set_param fail_loc=0
1900         CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000*.timeouts |
1901                 awk '/network/ {print $4}')
1902         WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000*.timeouts |
1903                 awk '/network/ {print $6}')
1904         echo "network timeout orig $ORIG, cur $CUR, worst $WORST"
1905         [ $WORST -gt $ORIG ] ||
1906                 error "Worst $WORST should be worse than orig $ORIG"
1907 }
1908 run_test 66b "AT: verify net latency adjusts"
1909
1910 test_67a() #bug 3055
1911 {
1912     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1913
1914     at_start || return 0
1915     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1916     # sleeping threads may drive values above this
1917     do_facet ost1 "$LCTL set_param fail_val=400"
1918 #define OBD_FAIL_PTLRPC_PAUSE_REQ    0x50a
1919     do_facet ost1 "$LCTL set_param fail_loc=0x50a"
1920     createmany -o $DIR/$tfile 20 > /dev/null
1921     unlinkmany $DIR/$tfile 20 > /dev/null
1922     do_facet ost1 "$LCTL set_param fail_loc=0"
1923     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1924     ATTEMPTS=$(($CONN2 - $CONN1))
1925     echo "$ATTEMPTS osc reconnect attempts on gradual slow"
1926         [ $ATTEMPTS -gt 0 ] &&
1927                 error_ignore bz13721 "AT should have prevented reconnect"
1928         return 0
1929 }
1930 run_test 67a "AT: verify slow request processing doesn't induce reconnects"
1931
1932 test_67b() #bug 3055
1933 {
1934     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1935
1936     at_start || return 0
1937     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1938
1939     # exhaust precreations on ost1
1940     local OST=$(ostname_from_index 0)
1941     local mdtosc=$(get_mdtosc_proc_path mds $OST)
1942     local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1943         osc.$mdtosc.prealloc_last_id)
1944     local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1945         osc.$mdtosc.prealloc_next_id)
1946
1947         mkdir -p $DIR/$tdir/${OST} || error "mkdir $DIR/$tdir/${OST} failed"
1948         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/${OST} || error "$SETSTRIPE failed"
1949         echo "Creating to objid $last_id on ost $OST..."
1950 #define OBD_FAIL_OST_PAUSE_CREATE        0x223
1951     do_facet ost1 "$LCTL set_param fail_val=20000"
1952     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1953     createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1954
1955     client_reconnect
1956     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1957     log "phase 2"
1958     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1959     ATTEMPTS=$(($CONN2 - $CONN1))
1960     echo "$ATTEMPTS osc reconnect attempts on instant slow"
1961     # do it again; should not timeout
1962     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1963     cp /etc/profile $DIR/$tfile || error "cp failed"
1964     do_facet ost1 "$LCTL set_param fail_loc=0"
1965     client_reconnect
1966     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1967     CONN3=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1968     ATTEMPTS=$(($CONN3 - $CONN2))
1969     echo "$ATTEMPTS osc reconnect attempts on 2nd slow"
1970     [ $ATTEMPTS -gt 0 ] && error "AT should have prevented reconnect"
1971     return 0
1972 }
1973 run_test 67b "AT: verify instant slowdown doesn't induce reconnects"
1974
1975 test_68 () #bug 13813
1976 {
1977     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1978
1979     at_start || return 0
1980     local ldlm_enqueue_min=$(find /sys -name ldlm_enqueue_min)
1981     [ -z "$ldlm_enqueue_min" ] && skip "missing /sys/.../ldlm_enqueue_min" && return 0
1982     local ldlm_enqueue_min_r=$(do_facet ost1 "find /sys -name ldlm_enqueue_min")
1983     [ -z "$ldlm_enqueue_min_r" ] && skip "missing /sys/.../ldlm_enqueue_min in the ost1" && return 0
1984     local ENQ_MIN=$(cat $ldlm_enqueue_min)
1985     local ENQ_MIN_R=$(do_facet ost1 "cat $ldlm_enqueue_min_r")
1986         echo $TIMEOUT >> $ldlm_enqueue_min
1987         do_facet ost1 "echo $TIMEOUT >> $ldlm_enqueue_min_r"
1988
1989         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1990         $SETSTRIPE --stripe-index=0 -c 1 $DIR/$tdir ||
1991                 error "$SETSTRIPE failed for $DIR/$tdir"
1992         #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
1993         $LCTL set_param fail_val=$(($TIMEOUT - 1))
1994         $LCTL set_param fail_loc=0x80000312
1995         cp /etc/profile $DIR/$tdir/${tfile}_1 || error "1st cp failed $?"
1996         $LCTL set_param fail_val=$((TIMEOUT * 5 / 4))
1997         $LCTL set_param fail_loc=0x80000312
1998         cp /etc/profile $DIR/$tdir/${tfile}_2 || error "2nd cp failed $?"
1999         $LCTL set_param fail_loc=0
2000
2001         echo $ENQ_MIN >> $ldlm_enqueue_min
2002         do_facet ost1 "echo $ENQ_MIN_R >> $ldlm_enqueue_min_r"
2003         rm -rf $DIR/$tdir
2004         return 0
2005 }
2006 run_test 68 "AT: verify slowing locks"
2007
2008 at_cleanup
2009 # end of AT tests includes above lines
2010
2011 # start multi-client tests
2012 test_70a () {
2013         [ -z "$CLIENTS" ] &&
2014                 { skip "Need two or more clients." && return; }
2015         [ $CLIENTCOUNT -lt 2 ] &&
2016                 { skip "Need two or more clients, have $CLIENTCOUNT" && return; }
2017
2018         echo "mount clients $CLIENTS ..."
2019         zconf_mount_clients $CLIENTS $MOUNT
2020
2021         local clients=${CLIENTS//,/ }
2022         echo "Write/read files on $DIR ; clients $CLIENTS ... "
2023         for CLIENT in $clients; do
2024                 do_node $CLIENT dd bs=1M count=10 if=/dev/zero \
2025                         of=$DIR/${tfile}_${CLIENT} 2>/dev/null ||
2026                                 error "dd failed on $CLIENT"
2027         done
2028
2029         local prev_client=$(echo $clients | sed 's/^.* \(.\+\)$/\1/')
2030         for C in ${CLIENTS//,/ }; do
2031                 do_node $prev_client dd if=$DIR/${tfile}_${C} \
2032                         of=/dev/null 2>/dev/null ||
2033                         error "dd if=$DIR/${tfile}_${C} failed on $prev_client"
2034                 prev_client=$C
2035         done
2036
2037         ls $DIR
2038 }
2039 run_test 70a "check multi client t-f"
2040
2041 check_for_process () {
2042         local clients=$1
2043         shift
2044         local prog=$@
2045
2046         killall_process $clients "$prog" -0
2047 }
2048
2049 test_70b () {
2050         local clients=${CLIENTS:-$HOSTNAME}
2051
2052         zconf_mount_clients $clients $MOUNT
2053
2054         local duration=300
2055         [ "$SLOW" = "no" ] && duration=120
2056         # set duration to 900 because it takes some time to boot node
2057         [ "$FAILURE_MODE" = HARD ] && duration=900
2058
2059         local elapsed
2060         local start_ts=$(date +%s)
2061         local cmd="rundbench 1 -t $duration"
2062         local pid=""
2063         if [ $MDSCOUNT -ge 2 ]; then
2064                 test_mkdir -p -c$MDSCOUNT $DIR/$tdir
2065                 $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
2066         fi
2067         do_nodesv $clients "set -x; MISSING_DBENCH_OK=$MISSING_DBENCH_OK \
2068                 PATH=\$PATH:$LUSTRE/utils:$LUSTRE/tests/:$DBENCH_LIB \
2069                 DBENCH_LIB=$DBENCH_LIB TESTSUITE=$TESTSUITE TESTNAME=$TESTNAME \
2070                 MOUNT=$MOUNT DIR=$DIR/$tdir/\\\$(hostname) LCTL=$LCTL $cmd" &
2071         pid=$!
2072
2073         #LU-1897 wait for all dbench copies to start
2074         while ! check_for_process $clients dbench; do
2075                 elapsed=$(($(date +%s) - start_ts))
2076                 if [ $elapsed -gt $duration ]; then
2077                         killall_process $clients dbench
2078                         error "dbench failed to start on $clients!"
2079                 fi
2080                 sleep 1
2081         done
2082
2083         log "Started rundbench load pid=$pid ..."
2084
2085         elapsed=$(($(date +%s) - start_ts))
2086         local num_failovers=0
2087         local fail_index=1
2088         while [ $elapsed -lt $duration ]; do
2089                 if ! check_for_process $clients dbench; then
2090                         error_noexit "dbench stopped on some of $clients!"
2091                         killall_process $clients dbench
2092                         break
2093                 fi
2094                 sleep 1
2095                 replay_barrier mds$fail_index
2096                 sleep 1 # give clients a time to do operations
2097                 # Increment the number of failovers
2098                 num_failovers=$((num_failovers+1))
2099                 log "$TESTNAME fail mds$fail_index $num_failovers times"
2100                 fail mds$fail_index
2101                 elapsed=$(($(date +%s) - start_ts))
2102                 if [ $fail_index -ge $MDSCOUNT ]; then
2103                         fail_index=1
2104                 else
2105                         fail_index=$((fail_index+1))
2106                 fi
2107         done
2108
2109         wait $pid || error "rundbench load on $clients failed!"
2110 }
2111 run_test 70b "dbench ${MDSCOUNT}mdts recovery; $CLIENTCOUNT clients"
2112 # end multi-client tests
2113
2114 random_fail_mdt() {
2115         local max_index=$1
2116         local duration=$2
2117         local monitor_pid=$3
2118         local elapsed
2119         local start_ts=$(date +%s)
2120         local num_failovers=0
2121         local fail_index
2122
2123         elapsed=$(($(date +%s) - start_ts))
2124         while [ $elapsed -lt $duration ]; do
2125                 fail_index=$((RANDOM%max_index+1))
2126                 kill -0 $monitor_pid ||
2127                         error "$monitor_pid stopped"
2128                 sleep 120
2129                 replay_barrier mds$fail_index
2130                 sleep 10
2131                 # Increment the number of failovers
2132                 num_failovers=$((num_failovers+1))
2133                 log "$TESTNAME fail mds$fail_index $num_failovers times"
2134                 fail mds$fail_index
2135                 elapsed=$(($(date +%s) - start_ts))
2136         done
2137 }
2138
2139 cleanup_70c() {
2140         trap 0
2141         rm -f $DIR/replay-single.70c.lck
2142         rm -rf /$DIR/$tdir
2143 }
2144
2145 test_70c () {
2146         local clients=${CLIENTS:-$HOSTNAME}
2147         local rc=0
2148
2149         zconf_mount_clients $clients $MOUNT
2150
2151         local duration=300
2152         [ "$SLOW" = "no" ] && duration=180
2153         # set duration to 900 because it takes some time to boot node
2154         [ "$FAILURE_MODE" = HARD ] && duration=600
2155
2156         local elapsed
2157         local start_ts=$(date +%s)
2158
2159         trap cleanup_70c EXIT
2160         (
2161                 while [ ! -e $DIR/replay-single.70c.lck ]; do
2162                         test_mkdir -p -c$MDSCOUNT $DIR/$tdir || break
2163                         if [ $MDSCOUNT -ge 2 ]; then
2164                                 $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir ||
2165                                 error "set default dirstripe failed"
2166                         fi
2167                         cd $DIR/$tdir || break
2168                         tar cf - /etc | tar xf - || error "tar failed in loop"
2169                 done
2170         )&
2171         tar_70c_pid=$!
2172         echo "Started tar $tar_70c_pid"
2173
2174         random_fail_mdt $MDSCOUNT $duration $tar_70c_pid
2175         kill -0 $tar_70c_pid || error "tar $tar_70c_pid stopped"
2176
2177         touch $DIR/replay-single.70c.lck
2178         wait $tar_70c_pid || error "$?: tar failed"
2179
2180         cleanup_70c
2181         true
2182 }
2183 run_test 70c "tar ${MDSCOUNT}mdts recovery"
2184
2185 cleanup_70d() {
2186         trap 0
2187         kill -9 $mkdir_70d_pid
2188 }
2189
2190 test_70d () {
2191         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2192         local clients=${CLIENTS:-$HOSTNAME}
2193         local rc=0
2194
2195         zconf_mount_clients $clients $MOUNT
2196
2197         local duration=300
2198         [ "$SLOW" = "no" ] && duration=180
2199         # set duration to 900 because it takes some time to boot node
2200         [ "$FAILURE_MODE" = HARD ] && duration=900
2201
2202         mkdir -p $DIR/$tdir
2203
2204         local elapsed
2205         local start_ts=$(date +%s)
2206
2207         trap cleanup_70d EXIT
2208         (
2209                 while true; do
2210                         $LFS mkdir -i0 -c2 $DIR/$tdir/test || {
2211                                 echo "mkdir fails"
2212                                 break
2213                         }
2214                         $LFS mkdir -i1 -c2 $DIR/$tdir/test1 || {
2215                                 echo "mkdir fails"
2216                                 break
2217                         }
2218
2219                         touch $DIR/$tdir/test/a || {
2220                                 echo "touch fails"
2221                                 break;
2222                         }
2223                         mkdir $DIR/$tdir/test/b || {
2224                                 echo "mkdir fails"
2225                                 break;
2226                         }
2227                         rm -rf $DIR/$tdir/test || {
2228                                 echo "rmdir fails"
2229                                 break
2230                         }
2231
2232                         touch $DIR/$tdir/test1/a || {
2233                                 echo "touch fails"
2234                                 break;
2235                         }
2236                         mkdir $DIR/$tdir/test1/b || {
2237                                 echo "mkdir fails"
2238                                 break;
2239                         }
2240
2241                         rm -rf $DIR/$tdir/test1 || {
2242                                 echo "rmdir fails"
2243                                 break
2244                         }
2245                 done
2246         )&
2247         mkdir_70d_pid=$!
2248         echo "Started  $mkdir_70d_pid"
2249
2250         random_fail_mdt $MDSCOUNT $duration $mkdir_70d_pid
2251         kill -0 $mkdir_70d_pid || error "mkdir/rmdir $mkdir_70d_pid stopped"
2252
2253         cleanup_70d
2254         true
2255 }
2256 run_test 70d "mkdir/rmdir striped dir ${MDSCOUNT}mdts recovery"
2257
2258 cleanup_70e() {
2259         trap 0
2260         kill -9 $rename_70e_pid
2261 }
2262
2263 test_70e () {
2264         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2265         local clients=${CLIENTS:-$HOSTNAME}
2266         local rc=0
2267
2268         echo ha > /proc/sys/lnet/debug
2269         zconf_mount_clients $clients $MOUNT
2270
2271         local duration=300
2272         [ "$SLOW" = "no" ] && duration=180
2273         # set duration to 900 because it takes some time to boot node
2274         [ "$FAILURE_MODE" = HARD ] && duration=900
2275
2276         mkdir -p $DIR/$tdir
2277         $LFS mkdir -i0 $DIR/$tdir/test_0
2278         $LFS mkdir -i0 $DIR/$tdir/test_1
2279         touch $DIR/$tdir/test_0/a
2280         touch $DIR/$tdir/test_1/b
2281         trap cleanup_70e EXIT
2282         (
2283                 while true; do
2284                         mrename $DIR/$tdir/test_0/a $DIR/$tdir/test_1/b > \
2285                                                 /dev/null || {
2286                                 echo "a->b fails"
2287                                 break;
2288                         }
2289
2290                         checkstat $DIR/$tdir/test_0/a && {
2291                                 echo "a still exists"
2292                                 break
2293                         }
2294
2295                         checkstat $DIR/$tdir/test_1/b || {
2296                                 echo "b still  exists"
2297                                 break
2298                         }
2299
2300                         touch $DIR/$tdir/test_0/a || {
2301                                 echo "touch a fails"
2302                                 break
2303                         }
2304
2305                         mrename $DIR/$tdir/test_1/b $DIR/$tdir/test_0/a > \
2306                                                 /dev/null || {
2307                                 echo "a->a fails"
2308                                 break;
2309                         }
2310                 done
2311         )&
2312         rename_70e_pid=$!
2313         echo "Started  $rename_70e_pid"
2314
2315         random_fail_mdt 2 $duration $rename_70e_pid
2316         kill -0 $rename_70e_pid || error "rename $rename_70e_pid stopped"
2317
2318         cleanup_70e
2319         true
2320 }
2321 run_test 70e "rename cross-MDT with random fails"
2322
2323 test_70f_write_and_read(){
2324         local srcfile=$1
2325         local stopflag=$2
2326         local client
2327
2328         echo "Write/read files in: '$DIR/$tdir', clients: '$CLIENTS' ..."
2329         for client in ${CLIENTS//,/ }; do
2330                 [ -f $stopflag ] || return
2331
2332                 local tgtfile=$DIR/$tdir/$tfile.$client
2333                 do_node $client dd $DD_OPTS bs=1M count=10 if=$srcfile \
2334                         of=$tgtfile 2>/dev/null ||
2335                         error "dd $DD_OPTS bs=1M count=10 if=$srcfile " \
2336                               "of=$tgtfile failed on $client, rc=$?"
2337         done
2338
2339         local prev_client=$(echo ${CLIENTS//,/ } | awk '{ print $NF }')
2340         local index=0
2341
2342         for client in ${CLIENTS//,/ }; do
2343                 [ -f $stopflag ] || return
2344
2345                 # flush client cache in case test is running on only one client
2346                 # do_node $client cancel_lru_locks osc
2347                 do_node $client $LCTL set_param ldlm.namespaces.*.lru_size=clear
2348
2349                 tgtfile=$DIR/$tdir/$tfile.$client
2350                 local md5=$(do_node $prev_client "md5sum $tgtfile")
2351                 [ ${checksum[$index]// */} = ${md5// */} ] ||
2352                         error "$tgtfile: checksum doesn't match on $prev_client"
2353                 index=$((index + 1))
2354                 prev_client=$client
2355         done
2356 }
2357
2358 test_70f_loop(){
2359         local srcfile=$1
2360         local stopflag=$2
2361         DD_OPTS=
2362
2363         mkdir -p $DIR/$tdir || error "cannot create $DIR/$tdir directory"
2364         $SETSTRIPE -c -1 $DIR/$tdir || error "cannot $SETSTRIPE $DIR/$tdir"
2365
2366         touch $stopflag
2367         while [ -f $stopflag ]; do
2368                 test_70f_write_and_read $srcfile $stopflag
2369                 # use direct IO and buffer cache in turns if loop
2370                 [ -n "$DD_OPTS" ] && DD_OPTS="" || DD_OPTS="oflag=direct"
2371         done
2372 }
2373
2374 test_70f_cleanup() {
2375         trap 0
2376         rm -f $TMP/$tfile.stop
2377         do_nodes $CLIENTS rm -f $TMP/$tfile
2378         rm -f $DIR/$tdir/$tfile.*
2379 }
2380
2381 test_70f() {
2382 #       [ x$ost1failover_HOST = x$ost_HOST ] &&
2383 #               { skip "Failover host not defined" && return; }
2384 #       [ -z "$CLIENTS" ] &&
2385 #               { skip "CLIENTS are not specified." && return; }
2386 #       [ $CLIENTCOUNT -lt 2 ] &&
2387 #               { skip "Need 2 or more clients, have $CLIENTCOUNT" && return; }
2388
2389         [[ $(lustre_version_code ost1) -lt $(version_code 2.9.53) ]] &&
2390                 skip "Need server version at least 2.9.53" && return
2391
2392         echo "mount clients $CLIENTS ..."
2393         zconf_mount_clients $CLIENTS $MOUNT
2394
2395         local srcfile=$TMP/$tfile
2396         local client
2397         local index=0
2398
2399         trap test_70f_cleanup EXIT
2400         # create a different source file local to each client node so we can
2401         # detect if the file wasn't written out properly after failover
2402         do_nodes $CLIENTS dd bs=1M count=10 if=/dev/urandom of=$srcfile \
2403                 2>/dev/null || error "can't create $srcfile on $CLIENTS"
2404         for client in ${CLIENTS//,/ }; do
2405                 checksum[$index]=$(do_node $client "md5sum $srcfile")
2406                 index=$((index + 1))
2407         done
2408
2409         local duration=120
2410         [ "$SLOW" = "no" ] && duration=60
2411         # set duration to 900 because it takes some time to boot node
2412         [ "$FAILURE_MODE" = HARD ] && duration=900
2413
2414         local stopflag=$TMP/$tfile.stop
2415         test_70f_loop $srcfile $stopflag &
2416         local pid=$!
2417
2418         local elapsed=0
2419         local num_failovers=0
2420         local start_ts=$SECONDS
2421         while [ $elapsed -lt $duration ]; do
2422                 sleep 3
2423                 replay_barrier ost1
2424                 sleep 1
2425                 num_failovers=$((num_failovers + 1))
2426                 log "$TESTNAME failing OST $num_failovers times"
2427                 fail ost1
2428                 sleep 2
2429                 elapsed=$((SECONDS - start_ts))
2430         done
2431
2432         rm -f $stopflag
2433         wait $pid
2434         test_70f_cleanup
2435 }
2436 run_test 70f "OSS O_DIRECT recovery with $CLIENTCOUNT clients"
2437
2438 cleanup_71a() {
2439         trap 0
2440         kill -9 $mkdir_71a_pid
2441 }
2442
2443 random_double_fail_mdt() {
2444         local max_index=$1
2445         local duration=$2
2446         local monitor_pid=$3
2447         local elapsed
2448         local start_ts=$(date +%s)
2449         local num_failovers=0
2450         local fail_index
2451         local second_index
2452
2453         elapsed=$(($(date +%s) - start_ts))
2454         while [ $elapsed -lt $duration ]; do
2455                 fail_index=$((RANDOM%max_index + 1))
2456                 if [ $fail_index -eq $max_index ]; then
2457                         second_index=1
2458                 else
2459                         second_index=$((fail_index + 1))
2460                 fi
2461                 kill -0 $monitor_pid ||
2462                         error "$monitor_pid stopped"
2463                 sleep 120
2464                 replay_barrier mds$fail_index
2465                 replay_barrier mds$second_index
2466                 sleep 10
2467                 # Increment the number of failovers
2468                 num_failovers=$((num_failovers+1))
2469                 log "fail mds$fail_index mds$second_index $num_failovers times"
2470                 fail mds${fail_index},mds${second_index}
2471                 elapsed=$(($(date +%s) - start_ts))
2472         done
2473 }
2474
2475 test_71a () {
2476         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2477         local clients=${CLIENTS:-$HOSTNAME}
2478         local rc=0
2479
2480         zconf_mount_clients $clients $MOUNT
2481
2482         local duration=300
2483         [ "$SLOW" = "no" ] && duration=180
2484         # set duration to 900 because it takes some time to boot node
2485         [ "$FAILURE_MODE" = HARD ] && duration=900
2486
2487         mkdir -p $DIR/$tdir
2488
2489         local elapsed
2490         local start_ts=$(date +%s)
2491
2492         trap cleanup_71a EXIT
2493         (
2494                 while true; do
2495                         $LFS mkdir -i0 -c2 $DIR/$tdir/test
2496                         rmdir $DIR/$tdir/test
2497                 done
2498         )&
2499         mkdir_71a_pid=$!
2500         echo "Started  $mkdir_71a_pid"
2501
2502         random_double_fail_mdt 2 $duration $mkdir_71a_pid
2503         kill -0 $mkdir_71a_pid || error "mkdir/rmdir $mkdir_71a_pid stopped"
2504
2505         cleanup_71a
2506         true
2507 }
2508 run_test 71a "mkdir/rmdir striped dir with 2 mdts recovery"
2509
2510 test_73a() {
2511         multiop_bg_pause $DIR/$tfile O_tSc ||
2512                 error "multiop_bg_pause $DIR/$tfile failed"
2513         pid=$!
2514         rm -f $DIR/$tfile
2515
2516         replay_barrier $SINGLEMDS
2517         #define OBD_FAIL_LDLM_ENQUEUE_NET                       0x302
2518         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000302"
2519         fail $SINGLEMDS
2520         kill -USR1 $pid
2521         wait $pid || error "multiop pid failed"
2522         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
2523         return 0
2524 }
2525 run_test 73a "open(O_CREAT), unlink, replay, reconnect before open replay, close"
2526
2527 test_73b() {
2528         multiop_bg_pause $DIR/$tfile O_tSc ||
2529                 error "multiop_bg_pause $DIR/$tfile failed"
2530         pid=$!
2531         rm -f $DIR/$tfile
2532
2533         replay_barrier $SINGLEMDS
2534         #define OBD_FAIL_LDLM_REPLY       0x30c
2535         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000030c"
2536         fail $SINGLEMDS
2537         kill -USR1 $pid
2538         wait $pid || error "multiop pid failed"
2539         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
2540         return 0
2541 }
2542 run_test 73b "open(O_CREAT), unlink, replay, reconnect at open_replay reply, close"
2543
2544 # bug 18554
2545 test_74() {
2546         local clients=${CLIENTS:-$HOSTNAME}
2547
2548         zconf_umount_clients $clients $MOUNT
2549         stop ost1
2550         facet_failover $SINGLEMDS
2551         zconf_mount_clients $clients $MOUNT
2552         mount_facet ost1
2553         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2554         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
2555         clients_up || error "client evicted: $?"
2556         return 0
2557 }
2558 run_test 74 "Ensure applications don't fail waiting for OST recovery"
2559
2560 remote_dir_check_80() {
2561         local MDTIDX=1
2562         local diridx
2563         local fileidx
2564
2565         diridx=$($GETSTRIPE -M $remote_dir) ||
2566                 error "$GETSTRIPE -M $remote_dir failed"
2567         [ $diridx -eq $MDTIDX ] || error "$diridx != $MDTIDX"
2568
2569         createmany -o $remote_dir/f-%d 20 || error "creation failed"
2570         fileidx=$($GETSTRIPE -M $remote_dir/f-1) ||
2571                 error "$GETSTRIPE -M $remote_dir/f-1 failed"
2572         [ $fileidx -eq $MDTIDX ] || error "$fileidx != $MDTIDX"
2573
2574         return 0
2575 }
2576
2577 test_80a() {
2578         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2579         ([ $FAILURE_MODE == "HARD" ] &&
2580                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2581                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2582                 return 0
2583
2584         local MDTIDX=1
2585         local remote_dir=$DIR/$tdir/remote_dir
2586
2587         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2588         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2589         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2590         $LFS mkdir -i $MDTIDX $remote_dir &
2591         local CLIENT_PID=$!
2592
2593         replay_barrier mds1
2594         fail mds${MDTIDX}
2595
2596         wait $CLIENT_PID || error "remote creation failed"
2597
2598         remote_dir_check_80 || error "remote dir check failed"
2599         rm -rf $DIR/$tdir || error "rmdir failed"
2600
2601         return 0
2602 }
2603 run_test 80a "DNE: create remote dir, drop update rep from MDT0, fail MDT0"
2604
2605 test_80b() {
2606         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2607         ([ $FAILURE_MODE == "HARD" ] &&
2608                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2609                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2610                 return 0
2611
2612         local MDTIDX=1
2613         local remote_dir=$DIR/$tdir/remote_dir
2614
2615         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2616         #define OBD_FAIL_UPDATE_OBJ_NET_REP     0x1701
2617         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2618         $LFS mkdir -i $MDTIDX $remote_dir &
2619         local CLIENT_PID=$!
2620
2621         replay_barrier mds1
2622         replay_barrier mds2
2623         fail mds$((MDTIDX + 1))
2624
2625         wait $CLIENT_PID || error "remote creation failed"
2626
2627         remote_dir_check_80 || error "remote dir check failed"
2628         rm -rf $DIR/$tdir || error "rmdir failed"
2629
2630         return 0
2631 }
2632 run_test 80b "DNE: create remote dir, drop update rep from MDT0, fail MDT1"
2633
2634 test_80c() {
2635         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2636         ([ $FAILURE_MODE == "HARD" ] &&
2637                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2638                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2639                 return 0
2640
2641         local MDTIDX=1
2642         local remote_dir=$DIR/$tdir/remote_dir
2643
2644         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2645         #define OBD_FAIL_UPDATE_OBJ_NET_REP     0x1701
2646         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2647         $LFS mkdir -i $MDTIDX $remote_dir &
2648         local CLIENT_PID=$!
2649
2650         replay_barrier mds1
2651         replay_barrier mds2
2652         fail mds${MDTIDX}
2653         fail mds$((MDTIDX + 1))
2654
2655         wait $CLIENT_PID || error "remote creation failed"
2656
2657         remote_dir_check_80 || error "remote dir check failed"
2658         rm -rf $DIR/$tdir || error "rmdir failed"
2659
2660         return 0
2661 }
2662 run_test 80c "DNE: create remote dir, drop update rep from MDT1, fail MDT[0,1]"
2663
2664 test_80d() {
2665         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2666         local MDTIDX=1
2667         local remote_dir=$DIR/$tdir/remote_dir
2668
2669         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2670         #define OBD_FAIL_UPDATE_OBJ_NET_REP     0x1701
2671         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2672         $LFS mkdir -i $MDTIDX $remote_dir &
2673         local CLIENT_PID=$!
2674
2675         # sleep 3 seconds to make sure MDTs are failed after
2676         # lfs mkdir -i has finished on all of MDTs.
2677         sleep 3
2678
2679         replay_barrier mds1
2680         replay_barrier mds2
2681         fail mds${MDTIDX},mds$((MDTIDX + 1))
2682
2683         wait $CLIENT_PID || error "remote creation failed"
2684
2685         remote_dir_check_80 || error "remote dir check failed"
2686         rm -rf $DIR/$tdir || error "rmdir failed"
2687
2688         return 0
2689 }
2690 run_test 80d "DNE: create remote dir, drop update rep from MDT1, fail 2 MDTs"
2691
2692 test_80e() {
2693         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2694         ([ $FAILURE_MODE == "HARD" ] &&
2695                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2696                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2697                 return 0
2698
2699         local MDTIDX=1
2700         local remote_dir=$DIR/$tdir/remote_dir
2701
2702         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2703         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2704         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2705         $LFS mkdir -i $MDTIDX $remote_dir &
2706         local CLIENT_PID=$!
2707
2708         # sleep 3 seconds to make sure MDTs are failed after
2709         # lfs mkdir -i has finished on all of MDTs.
2710         sleep 3
2711
2712         replay_barrier mds1
2713         fail mds${MDTIDX}
2714
2715         wait $CLIENT_PID || error "remote creation failed"
2716
2717         remote_dir_check_80 || error "remote dir check failed"
2718         rm -rf $DIR/$tdir || error "rmdir failed"
2719
2720         return 0
2721 }
2722 run_test 80e "DNE: create remote dir, drop MDT1 rep, fail MDT0"
2723
2724 test_80f() {
2725         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2726         ([ $FAILURE_MODE == "HARD" ] &&
2727                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2728                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2729                 return 0
2730         local MDTIDX=1
2731         local remote_dir=$DIR/$tdir/remote_dir
2732
2733         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2734         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2735         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2736         $LFS mkdir -i $MDTIDX $remote_dir &
2737         local CLIENT_PID=$!
2738
2739         replay_barrier mds2
2740         fail mds$((MDTIDX + 1))
2741
2742         wait $CLIENT_PID || error "remote creation failed"
2743
2744         remote_dir_check_80 || error "remote dir check failed"
2745         rm -rf $DIR/$tdir || error "rmdir failed"
2746
2747         return 0
2748 }
2749 run_test 80f "DNE: create remote dir, drop MDT1 rep, fail MDT1"
2750
2751 test_80g() {
2752         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2753         ([ $FAILURE_MODE == "HARD" ] &&
2754                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2755                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2756                 return 0
2757
2758         local MDTIDX=1
2759         local remote_dir=$DIR/$tdir/remote_dir
2760
2761         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2762         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2763         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2764         $LFS mkdir -i $MDTIDX $remote_dir &
2765         local CLIENT_PID=$!
2766
2767         # sleep 3 seconds to make sure MDTs are failed after
2768         # lfs mkdir -i has finished on all of MDTs.
2769         sleep 3
2770
2771         replay_barrier mds1
2772         replay_barrier mds2
2773         fail mds${MDTIDX}
2774         fail mds$((MDTIDX + 1))
2775
2776         wait $CLIENT_PID || error "remote creation failed"
2777
2778         remote_dir_check_80 || error "remote dir check failed"
2779         rm -rf $DIR/$tdir || error "rmdir failed"
2780
2781         return 0
2782 }
2783 run_test 80g "DNE: create remote dir, drop MDT1 rep, fail MDT0, then MDT1"
2784
2785 test_80h() {
2786         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2787         local MDTIDX=1
2788         local remote_dir=$DIR/$tdir/remote_dir
2789
2790         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2791         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2792         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2793         $LFS mkdir -i $MDTIDX $remote_dir &
2794         local CLIENT_PID=$!
2795
2796         # sleep 3 seconds to make sure MDTs are failed after
2797         # lfs mkdir -i has finished on all of MDTs.
2798         sleep 3
2799
2800         replay_barrier mds1
2801         replay_barrier mds2
2802         fail mds${MDTIDX},mds$((MDTIDX + 1))
2803
2804         wait $CLIENT_PID || error "remote dir creation failed"
2805
2806         remote_dir_check_80 || error "remote dir check failed"
2807         rm -rf $DIR/$tdir || error "rmdir failed"
2808
2809         return 0
2810 }
2811 run_test 80h "DNE: create remote dir, drop MDT1 rep, fail 2 MDTs"
2812
2813 test_81a() {
2814         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2815         ([ $FAILURE_MODE == "HARD" ] &&
2816                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2817                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2818                 return 0
2819
2820         local MDTIDX=1
2821         local remote_dir=$DIR/$tdir/remote_dir
2822
2823         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2824         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2825
2826         touch $remote_dir || error "touch $remote_dir failed"
2827         # OBD_FAIL_OBJ_UPDATE_NET_REP       0x1701
2828         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2829         rmdir $remote_dir &
2830         local CLIENT_PID=$!
2831
2832         replay_barrier mds2
2833         fail mds$((MDTIDX + 1))
2834
2835         wait $CLIENT_PID || error "rm remote dir failed"
2836
2837         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2838
2839         rm -rf $DIR/$tdir || error "rmdir failed"
2840
2841         return 0
2842 }
2843 run_test 81a "DNE: unlink remote dir, drop MDT0 update rep,  fail MDT1"
2844
2845 test_81b() {
2846         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2847         ([ $FAILURE_MODE == "HARD" ] &&
2848                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2849                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2850                 return 0
2851         local MDTIDX=1
2852         local remote_dir=$DIR/$tdir/remote_dir
2853
2854         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2855         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2856
2857         # OBD_FAIL_OBJ_UPDATE_NET_REP       0x1701
2858         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2859         rmdir $remote_dir &
2860         local CLIENT_PID=$!
2861
2862         replay_barrier mds1
2863         fail mds${MDTIDX}
2864
2865         wait $CLIENT_PID || error "rm remote dir failed"
2866
2867         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2868
2869         rm -rf $DIR/$tdir || error "rmdir failed"
2870
2871         return 0
2872 }
2873 run_test 81b "DNE: unlink remote dir, drop MDT0 update reply,  fail MDT0"
2874
2875 test_81c() {
2876         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2877         ([ $FAILURE_MODE == "HARD" ] &&
2878                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2879                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2880                 return 0
2881
2882         local MDTIDX=1
2883         local remote_dir=$DIR/$tdir/remote_dir
2884
2885         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2886         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2887
2888         # OBD_FAIL_OBJ_UPDATE_NET_REP       0x1701
2889         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2890         rmdir $remote_dir &
2891         local CLIENT_PID=$!
2892
2893         replay_barrier mds1
2894         replay_barrier mds2
2895         fail mds${MDTIDX}
2896         fail mds$((MDTIDX + 1))
2897
2898         wait $CLIENT_PID || error "rm remote dir failed"
2899
2900         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2901
2902         rm -rf $DIR/$tdir || error "rmdir failed"
2903
2904         return 0
2905 }
2906 run_test 81c "DNE: unlink remote dir, drop MDT0 update reply, fail MDT0,MDT1"
2907
2908 test_81d() {
2909         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2910         local MDTIDX=1
2911         local remote_dir=$DIR/$tdir/remote_dir
2912
2913         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2914         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2915
2916         # OBD_FAIL_OBJ_UPDATE_NET_REP       0x1701
2917         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2918         rmdir $remote_dir &
2919         local CLIENT_PID=$!
2920
2921         replay_barrier mds1
2922         replay_barrier mds2
2923         fail mds${MDTIDX},mds$((MDTIDX + 1))
2924
2925         wait $CLIENT_PID || error "rm remote dir failed"
2926
2927         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2928
2929         rm -rf $DIR/$tdir || error "rmdir failed"
2930
2931         return 0
2932 }
2933 run_test 81d "DNE: unlink remote dir, drop MDT0 update reply,  fail 2 MDTs"
2934
2935 test_81e() {
2936         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2937         ([ $FAILURE_MODE == "HARD" ] &&
2938                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2939                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2940                 return 0
2941
2942         local MDTIDX=1
2943         local remote_dir=$DIR/$tdir/remote_dir
2944
2945         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2946         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2947
2948         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2949         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2950         rmdir $remote_dir &
2951         local CLIENT_PID=$!
2952         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0
2953
2954         replay_barrier mds1
2955         fail mds${MDTIDX}
2956
2957         wait $CLIENT_PID || error "rm remote dir failed"
2958
2959         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2960
2961         rm -rf $DIR/$tdir || error "rmdir failed"
2962
2963         return 0
2964 }
2965 run_test 81e "DNE: unlink remote dir, drop MDT1 req reply, fail MDT0"
2966
2967 test_81f() {
2968         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2969         ([ $FAILURE_MODE == "HARD" ] &&
2970                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2971                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2972                 return 0
2973
2974         local MDTIDX=1
2975         local remote_dir=$DIR/$tdir/remote_dir
2976
2977         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2978         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2979
2980         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2981         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2982         rmdir $remote_dir &
2983         local CLIENT_PID=$!
2984
2985         replay_barrier mds2
2986         fail mds$((MDTIDX + 1))
2987
2988         wait $CLIENT_PID || error "rm remote dir failed"
2989
2990         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2991
2992         rm -rf $DIR/$tdir || error "rmdir failed"
2993
2994         return 0
2995 }
2996 run_test 81f "DNE: unlink remote dir, drop MDT1 req reply, fail MDT1"
2997
2998 test_81g() {
2999         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3000         ([ $FAILURE_MODE == "HARD" ] &&
3001                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3002                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3003                 return 0
3004
3005         local MDTIDX=1
3006         local remote_dir=$DIR/$tdir/remote_dir
3007
3008         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3009         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
3010
3011         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3012         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
3013         rmdir $remote_dir &
3014         local CLIENT_PID=$!
3015
3016         replay_barrier mds1
3017         replay_barrier mds2
3018         fail mds${MDTIDX}
3019         fail mds$((MDTIDX + 1))
3020
3021         wait $CLIENT_PID || error "rm remote dir failed"
3022
3023         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3024
3025         rm -rf $DIR/$tdir || error "rmdir failed"
3026
3027         return 0
3028 }
3029 run_test 81g "DNE: unlink remote dir, drop req reply, fail M0, then M1"
3030
3031 test_81h() {
3032         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3033         local MDTIDX=1
3034         local remote_dir=$DIR/$tdir/remote_dir
3035
3036         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3037         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
3038
3039         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3040         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
3041         rmdir $remote_dir &
3042         local CLIENT_PID=$!
3043
3044         replay_barrier mds1
3045         replay_barrier mds2
3046         fail mds${MDTIDX},mds$((MDTIDX + 1))
3047
3048         wait $CLIENT_PID || error "rm remote dir failed"
3049
3050         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3051
3052         rm -rf $DIR/$tdir || error "rmdir failed"
3053
3054         return 0
3055 }
3056 run_test 81h "DNE: unlink remote dir, drop request reply, fail 2 MDTs"
3057
3058 test_84a() {
3059 #define OBD_FAIL_MDS_OPEN_WAIT_CREATE  0x144
3060     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000144"
3061     createmany -o $DIR/$tfile- 1 &
3062     PID=$!
3063     mds_evict_client
3064     wait $PID
3065     client_up || client_up || true    # reconnect
3066 }
3067 run_test 84a "stale open during export disconnect"
3068
3069 test_85a() { #bug 16774
3070         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
3071
3072         for i in $(seq 100); do
3073                 echo "tag-$i" > $DIR/$tfile-$i
3074                 grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
3075         done
3076
3077         lov_id=$(lctl dl | grep "clilov")
3078         addr=$(echo $lov_id | awk '{print $4}' | awk -F '-' '{print $NF}')
3079         count=$(lctl get_param -n \
3080                 ldlm.namespaces.*MDT0000*$addr.lock_unused_count)
3081         echo "before recovery: unused locks count = $count"
3082
3083         fail $SINGLEMDS
3084
3085         count2=$(lctl get_param -n \
3086                  ldlm.namespaces.*MDT0000*$addr.lock_unused_count)
3087         echo "after recovery: unused locks count = $count2"
3088
3089         if [ $count2 -ge $count ]; then
3090                 error "unused locks are not canceled"
3091         fi
3092 }
3093 run_test 85a "check the cancellation of unused locks during recovery(IBITS)"
3094
3095 test_85b() { #bug 16774
3096         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
3097
3098         if ! combined_mgs_mds ; then
3099                 mount_mgs_client
3100         fi
3101
3102         create_pool $FSNAME.$TESTNAME ||
3103                 error "unable to create pool $TESTNAME"
3104         do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $FSNAME-OST0000 ||
3105                 error "unable to add pool $TESTNAME"
3106
3107         $SETSTRIPE -c 1 -p $FSNAME.$TESTNAME $DIR
3108
3109         for i in $(seq 100); do
3110                 dd if=/dev/urandom of=$DIR/$tfile-$i bs=4096 \
3111                         count=32 >/dev/null 2>&1
3112         done
3113
3114         cancel_lru_locks osc
3115
3116         for i in $(seq 100); do
3117                 dd if=$DIR/$tfile-$i of=/dev/null bs=4096 \
3118                         count=32 >/dev/null 2>&1
3119         done
3120
3121         lov_id=$(lctl dl | grep "clilov")
3122         addr=$(echo $lov_id | awk '{print $4}' | awk -F '-' '{print $NF}')
3123         count=$(lctl get_param -n \
3124                           ldlm.namespaces.*OST0000*$addr.lock_unused_count)
3125         echo "before recovery: unused locks count = $count"
3126         [ $count -ne 0 ] || error "unused locks ($count) should be zero"
3127
3128         fail ost1
3129
3130         count2=$(lctl get_param \
3131                  -n ldlm.namespaces.*OST0000*$addr.lock_unused_count)
3132         echo "after recovery: unused locks count = $count2"
3133
3134         do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $FSNAME-OST0000 ||
3135                 error "unable to remove pool $TESTNAME"
3136         do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME ||
3137                 error "unable to destroy the pool $TESTNAME"
3138
3139         if ! combined_mgs_mds ; then
3140                 umount_mgs_client
3141         fi
3142
3143         if [ $count2 -ge $count ]; then
3144                 error "unused locks are not canceled"
3145         fi
3146 }
3147 run_test 85b "check the cancellation of unused locks during recovery(EXTENT)"
3148
3149 test_86() {
3150         local clients=${CLIENTS:-$HOSTNAME}
3151
3152         zconf_umount_clients $clients $MOUNT
3153         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT*.exports.clear=0
3154         remount_facet $SINGLEMDS
3155         zconf_mount_clients $clients $MOUNT
3156 }
3157 run_test 86 "umount server after clear nid_stats should not hit LBUG"
3158
3159 test_87a() {
3160         do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
3161
3162         replay_barrier ost1
3163         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
3164         dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 ||
3165                 error "dd to $DIR/$tfile failed"
3166         cksum=$(md5sum $DIR/$tfile | awk '{print $1}')
3167         cancel_lru_locks osc
3168         fail ost1
3169         dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
3170         cksum2=$(md5sum $DIR/$tfile | awk '{print $1}')
3171         if [ $cksum != $cksum2 ] ; then
3172                 error "New checksum $cksum2 does not match original $cksum"
3173         fi
3174 }
3175 run_test 87a "write replay"
3176
3177 test_87b() {
3178         do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
3179
3180         replay_barrier ost1
3181         $SETSTRIPE -i 0 -c 1 $DIR/$tfile
3182         dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 ||
3183                 error "dd to $DIR/$tfile failed"
3184         sleep 1 # Give it a chance to flush dirty data
3185         echo TESTTEST | dd of=$DIR/$tfile bs=1 count=8 seek=64
3186         cksum=$(md5sum $DIR/$tfile | awk '{print $1}')
3187         cancel_lru_locks osc
3188         fail ost1
3189         dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
3190         cksum2=$(md5sum $DIR/$tfile | awk '{print $1}')
3191         if [ $cksum != $cksum2 ] ; then
3192                 error "New checksum $cksum2 does not match original $cksum"
3193         fi
3194 }
3195 run_test 87b "write replay with changed data (checksum resend)"
3196
3197 test_88() { #bug 17485
3198         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3199         mkdir -p $TMP/$tdir || error "mkdir $TMP/$tdir failed"
3200
3201         $SETSTRIPE -i 0 -c 1 $DIR/$tdir || error "$SETSTRIPE"
3202
3203         replay_barrier ost1
3204         replay_barrier $SINGLEMDS
3205
3206     # exhaust precreations on ost1
3207     local OST=$(ostname_from_index 0)
3208     local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $OST)
3209     local last_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
3210     local next_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
3211         echo "before test: last_id = $last_id, next_id = $next_id"
3212
3213         echo "Creating to objid $last_id on ost $OST..."
3214         createmany -o $DIR/$tdir/f-%d $next_id $((last_id - next_id + 2)) ||
3215                 error "createmany create files to last_id failed"
3216
3217         #create some files to use some uncommitted objids
3218         last_id=$(($last_id + 1))
3219         createmany -o $DIR/$tdir/f-%d $last_id 8 ||
3220                 error "createmany create files with uncommitted objids failed"
3221
3222     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
3223     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
3224     echo "before recovery: last_id = $last_id2, next_id = $next_id2" 
3225
3226     # if test uses shutdown_facet && reboot_facet instead of facet_failover ()
3227     # it has to take care about the affected facets, bug20407
3228     local affected_mds1=$(affected_facets mds1)
3229     local affected_ost1=$(affected_facets ost1)
3230
3231     shutdown_facet $SINGLEMDS
3232     shutdown_facet ost1
3233
3234     reboot_facet $SINGLEMDS
3235     change_active $affected_mds1
3236     wait_for_facet $affected_mds1
3237     mount_facets $affected_mds1 || error "Restart of mds failed"
3238
3239     reboot_facet ost1
3240     change_active $affected_ost1
3241     wait_for_facet $affected_ost1
3242     mount_facets $affected_ost1 || error "Restart of ost1 failed"
3243
3244     clients_up
3245
3246     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
3247     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
3248         echo "after recovery: last_id = $last_id2, next_id = $next_id2"
3249
3250         # create new files, which should use new objids, and ensure the orphan
3251         # cleanup phase for ost1 is completed at the same time
3252         for i in $(seq 8); do
3253                 file_id=$(($last_id + 10 + $i))
3254                 dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
3255         done
3256
3257         # if the objids were not recreated, then "ls" will fail with -ENOENT
3258         ls -l $DIR/$tdir/* || error "can't get the status of precreated files"
3259
3260         local file_id
3261         # write into previously created files
3262         for i in $(seq 8); do
3263                 file_id=$(($last_id + $i))
3264                 dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
3265                 cp -f $DIR/$tdir/f-$file_id $TMP/$tdir/
3266         done
3267
3268         # compare the content
3269         for i in $(seq 8); do
3270                 file_id=$(($last_id + $i))
3271                 cmp $TMP/$tdir/f-$file_id $DIR/$tdir/f-$file_id ||
3272                         error "the content of file is modified!"
3273         done
3274
3275         rm -fr $TMP/$tdir
3276 }
3277 run_test 88 "MDS should not assign same objid to different files "
3278
3279 test_89() {
3280         cancel_lru_locks osc
3281         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3282         rm -f $DIR/$tdir/$tfile
3283         wait_mds_ost_sync
3284         wait_delete_completed
3285         BLOCKS1=$(df -P $MOUNT | tail -n 1 | awk '{ print $3 }')
3286         $SETSTRIPE -i 0 -c 1 $DIR/$tdir/$tfile
3287         dd if=/dev/zero bs=1M count=10 of=$DIR/$tdir/$tfile
3288         sync
3289         stop ost1
3290         facet_failover $SINGLEMDS
3291         rm $DIR/$tdir/$tfile
3292         umount $MOUNT
3293         mount_facet ost1
3294         zconf_mount $(hostname) $MOUNT || error "mount fails"
3295         client_up || error "client_up failed"
3296         wait_mds_ost_sync
3297         wait_delete_completed
3298         BLOCKS2=$(df -P $MOUNT | tail -n 1 | awk '{ print $3 }')
3299         [ $((BLOCKS2 - BLOCKS1)) -le 4  ] ||
3300                 error $((BLOCKS2 - BLOCKS1)) blocks leaked
3301 }
3302 run_test 89 "no disk space leak on late ost connection"
3303
3304 cleanup_90 () {
3305         local facet=$1
3306
3307         trap 0
3308         reboot_facet $facet
3309         change_active $facet
3310         wait_for_facet $facet
3311         mount_facet $facet || error "Restart of $facet failed"
3312         clients_up
3313 }
3314
3315 test_90() { # bug 19494
3316     local dir=$DIR/$tdir
3317     local ostfail=$(get_random_entry $(get_facets OST))
3318
3319     if [[ $FAILURE_MODE = HARD ]]; then
3320         local affected=$(affected_facets $ostfail);
3321         if [[ "$affected" != $ostfail ]]; then
3322             skip not functional with FAILURE_MODE=$FAILURE_MODE, affected: $affected
3323             return 0
3324         fi
3325     fi
3326         # ensure all OSTs are active to allow allocations
3327         wait_osts_up
3328
3329         mkdir $dir || error "mkdir $dir failed"
3330
3331         echo "Create the files"
3332
3333     # file "f${index}" striped over 1 OST
3334     # file "all" striped over all OSTs
3335
3336     $SETSTRIPE -c $OSTCOUNT $dir/all ||
3337         error "setstripe failed to create $dir/all"
3338
3339     for (( i=0; i<$OSTCOUNT; i++ )); do
3340         local f=$dir/f$i
3341         $SETSTRIPE -i $i -c 1 $f || error "$SETSTRIPE failed to create $f"
3342
3343         # confirm setstripe actually created the stripe on the requested OST
3344         local uuid=$(ostuuid_from_index $i)
3345         for file in f$i all; do
3346             if [[ $dir/$file != $($LFS find --obd $uuid --name $file $dir) ]]; then
3347                 $GETSTRIPE $dir/$file
3348                 error wrong stripe: $file, uuid: $uuid
3349             fi
3350         done
3351     done
3352
3353         # Before failing an OST, get its obd name and index
3354         local varsvc=${ostfail}_svc
3355         local obd=$(do_facet $ostfail lctl get_param \
3356                     -n obdfilter.${!varsvc}.uuid)
3357         local index=$(($(facet_number $ostfail) - 1))
3358
3359         echo "Fail $ostfail $obd, display the list of affected files"
3360         shutdown_facet $ostfail || error "shutdown_facet $ostfail failed"
3361
3362         trap "cleanup_90 $ostfail" EXIT INT
3363         echo "General Query: lfs find $dir"
3364         local list=$($LFS find $dir)
3365         echo "$list"
3366         for (( i=0; i<$OSTCOUNT; i++ )); do
3367                 list_member "$list" $dir/f$i ||
3368                         error_noexit "lfs find $dir: no file f$i"
3369         done
3370         list_member "$list" $dir/all ||
3371                 error_noexit "lfs find $dir: no file all"
3372
3373         # focus on the missing OST,
3374         # we expect to see only two files affected: "f$(index)" and "all"
3375
3376         echo "Querying files on shutdown $ostfail: lfs find --obd $obd"
3377     list=$($LFS find --obd $obd $dir)
3378     echo "$list"
3379     for file in all f$index; do
3380         list_member "$list" $dir/$file ||
3381             error_noexit "lfs find does not report the affected $obd for $file"
3382     done
3383
3384     [[ $(echo $list | wc -w) -eq 2 ]] ||
3385         error_noexit "lfs find reports the wrong list of affected files ${#list[@]}"
3386
3387     echo "Check getstripe: $GETSTRIPE -r --obd $obd"
3388     list=$($GETSTRIPE -r --obd $obd $dir)
3389     echo "$list"
3390     for file in all f$index; do
3391         echo "$list" | grep $dir/$file ||
3392             error_noexit "lfs getsripe does not report the affected $obd for $file"
3393     done
3394
3395     cleanup_90 $ostfail
3396 }
3397 run_test 90 "lfs find identifies the missing striped file segments"
3398
3399 test_93a() {
3400         local server_version=$(lustre_version_code $SINGLEMDS)
3401                 [[ $server_version -ge $(version_code 2.6.90) ]] ||
3402                 [[ $server_version -ge $(version_code 2.5.4) &&
3403                    $server_version -lt $(version_code 2.5.50) ]] ||
3404                 { skip "Need MDS version 2.5.4+ or 2.6.90+"; return; }
3405
3406         cancel_lru_locks osc
3407
3408         $SETSTRIPE -i 0 -c 1 $DIR/$tfile ||
3409                 error "$SETSTRIPE  $DIR/$tfile failed"
3410         dd if=/dev/zero of=$DIR/$tfile bs=1024 count=1 ||
3411                 error "dd to $DIR/$tfile failed"
3412         #define OBD_FAIL_TGT_REPLAY_RECONNECT     0x715
3413         # We need to emulate a state that OST is waiting for other clients
3414         # not completing the recovery. Final ping is queued, but reply will be
3415         # sent on the recovery completion. It is done by sleep before
3416         # processing final pings
3417         do_facet ost1 "$LCTL set_param fail_val=40"
3418         do_facet ost1 "$LCTL set_param fail_loc=0x715"
3419         fail ost1
3420 }
3421 run_test 93a "replay + reconnect"
3422
3423 test_93b() {
3424         local server_version=$(lustre_version_code $SINGLEMDS)
3425                 [[ $server_version -ge $(version_code 2.7.90) ]] ||
3426                 { skip "Need MDS version 2.7.90+"; return; }
3427
3428         cancel_lru_locks mdc
3429
3430         createmany -o $DIR/$tfile 20 ||
3431                         error "createmany -o $DIR/$tfile failed"
3432
3433         #define OBD_FAIL_TGT_REPLAY_RECONNECT     0x715
3434         # We need to emulate a state that MDT is waiting for other clients
3435         # not completing the recovery. Final ping is queued, but reply will be
3436         # sent on the recovery completion. It is done by sleep before
3437         # processing final pings
3438         do_facet mds1 "$LCTL set_param fail_val=80"
3439         do_facet mds1 "$LCTL set_param fail_loc=0x715"
3440         fail mds1
3441 }
3442 run_test 93b "replay + reconnect on mds"
3443
3444 striped_dir_check_100() {
3445         local striped_dir=$DIR/$tdir/striped_dir
3446         local stripe_count=$($LFS getdirstripe -c $striped_dir)
3447
3448         $LFS getdirstripe $striped_dir
3449         [ $stripe_count -eq 2 ] || error "$stripe_count != 2"
3450
3451         createmany -o $striped_dir/f-%d 20 ||
3452                 error "creation failed under striped dir"
3453 }
3454
3455 test_100a() {
3456         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3457         ([ $FAILURE_MODE == "HARD" ] &&
3458                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3459                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3460                 return 0
3461
3462         local striped_dir=$DIR/$tdir/striped_dir
3463         local MDTIDX=1
3464
3465         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3466
3467         #To make sure MDT1 and MDT0 are connected
3468         #otherwise it may create single stripe dir here
3469         $LFS setdirstripe -i1 $DIR/$tdir/remote_dir
3470
3471         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
3472         do_facet mds$((MDTIDX+1)) lctl set_param fail_loc=0x1701
3473         $LFS setdirstripe -i0 -c2 $striped_dir &
3474         local CLIENT_PID=$!
3475
3476         fail mds$((MDTIDX + 1))
3477
3478         wait $CLIENT_PID || error "striped dir creation failed"
3479
3480         striped_dir_check_100 || error "striped dir check failed"
3481         rm -rf $DIR/$tdir || error "rmdir failed"
3482 }
3483 run_test 100a "DNE: create striped dir, drop update rep from MDT1, fail MDT1"
3484
3485 test_100b() {
3486         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3487         ([ $FAILURE_MODE == "HARD" ] &&
3488                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3489                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3490                 return 0
3491
3492         local striped_dir=$DIR/$tdir/striped_dir
3493         local MDTIDX=1
3494
3495         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3496
3497         #To make sure MDT1 and MDT0 are connected
3498         #otherwise it may create single stripe dir here
3499         $LFS setdirstripe -i1 $DIR/$tdir/remote_dir
3500
3501         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3502         do_facet mds$MDTIDX lctl set_param fail_loc=0x119
3503         $LFS mkdir -i0 -c2 $striped_dir &
3504
3505         local CLIENT_PID=$!
3506         fail mds$MDTIDX
3507
3508         wait $CLIENT_PID || error "striped dir creation failed"
3509
3510         striped_dir_check_100 || error "striped dir check failed"
3511         rm -rf $DIR/$tdir || error "rmdir failed"
3512 }
3513 run_test 100b "DNE: create striped dir, fail MDT0"
3514
3515 test_101() { #LU-5648
3516         mkdir -p $DIR/$tdir/d1
3517         mkdir -p $DIR/$tdir/d2
3518         touch $DIR/$tdir/file0
3519         num=1000
3520
3521         replay_barrier $SINGLEMDS
3522         for i in $(seq $num) ; do
3523                 echo test$i > $DIR/$tdir/d1/file$i
3524         done
3525
3526         fail_abort $SINGLEMDS
3527         for i in $(seq $num) ; do
3528                 touch $DIR/$tdir/d2/file$i
3529                 test -s $DIR/$tdir/d2/file$i &&
3530                         ls -al $DIR/$tdir/d2/file$i && error "file$i's size > 0"
3531         done
3532
3533         rm -rf $DIR/$tdir
3534 }
3535 run_test 101 "Shouldn't reassign precreated objs to other files after recovery"
3536
3537 test_102a() {
3538         local idx
3539         local facet
3540         local num
3541         local i
3542         local pids pid
3543
3544         [[ $(lctl get_param mdc.*.import |
3545              grep "connect_flags:.*multi_mod_rpc") ]] ||
3546                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3547
3548         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3549         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3550         facet="mds$((0x$idx + 1))"
3551
3552         # get current value of max_mod_rcps_in_flight
3553         num=$($LCTL get_param -n \
3554                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3555         # set default value if client does not support multi mod RPCs
3556         [ -z "$num" ] && num=1
3557
3558         echo "creating $num files ..."
3559         umask 0022
3560         for i in $(seq $num); do
3561                 touch $DIR/$tdir/file-$i
3562         done
3563
3564         # drop request on MDT to force resend
3565         #define OBD_FAIL_MDS_REINT_MULTI_NET 0x159
3566         do_facet $facet "$LCTL set_param fail_loc=0x159"
3567         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3568         for i in $(seq $num); do
3569                 chmod 0600 $DIR/$tdir/file-$i &
3570                 pids="$pids $!"
3571         done
3572         sleep 1
3573         do_facet $facet "$LCTL set_param fail_loc=0"
3574         for pid in $pids; do
3575                 wait $pid || error "chmod failed"
3576         done
3577         echo "done ($(date +%H:%M:%S))"
3578
3579         # check chmod succeed
3580         for i in $(seq $num); do
3581                 checkstat -vp 0600 $DIR/$tdir/file-$i
3582         done
3583
3584         rm -rf $DIR/$tdir
3585 }
3586 run_test 102a "check resend (request lost) with multiple modify RPCs in flight"
3587
3588 test_102b() {
3589         local idx
3590         local facet
3591         local num
3592         local i
3593         local pids pid
3594
3595         [[ $(lctl get_param mdc.*.import |
3596              grep "connect_flags:.*multi_mod_rpc") ]] ||
3597                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3598
3599         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3600         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3601         facet="mds$((0x$idx + 1))"
3602
3603         # get current value of max_mod_rcps_in_flight
3604         num=$($LCTL get_param -n \
3605                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3606         # set default value if client does not support multi mod RPCs
3607         [ -z "$num" ] && num=1
3608
3609         echo "creating $num files ..."
3610         umask 0022
3611         for i in $(seq $num); do
3612                 touch $DIR/$tdir/file-$i
3613         done
3614
3615         # drop reply on MDT to force reconstruction
3616         #define OBD_FAIL_MDS_REINT_MULTI_NET_REP 0x15a
3617         do_facet $facet "$LCTL set_param fail_loc=0x15a"
3618         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3619         for i in $(seq $num); do
3620                 chmod 0600 $DIR/$tdir/file-$i &
3621                 pids="$pids $!"
3622         done
3623         sleep 1
3624         do_facet $facet "$LCTL set_param fail_loc=0"
3625         for pid in $pids; do
3626                 wait $pid || error "chmod failed"
3627         done
3628         echo "done ($(date +%H:%M:%S))"
3629
3630         # check chmod succeed
3631         for i in $(seq $num); do
3632                 checkstat -vp 0600 $DIR/$tdir/file-$i
3633         done
3634
3635         rm -rf $DIR/$tdir
3636 }
3637 run_test 102b "check resend (reply lost) with multiple modify RPCs in flight"
3638
3639 test_102c() {
3640         local idx
3641         local facet
3642         local num
3643         local i
3644         local pids pid
3645
3646         [[ $(lctl get_param mdc.*.import |
3647              grep "connect_flags:.*multi_mod_rpc") ]] ||
3648                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3649
3650         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3651         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3652         facet="mds$((0x$idx + 1))"
3653
3654         # get current value of max_mod_rcps_in_flight
3655         num=$($LCTL get_param -n \
3656                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3657         # set default value if client does not support multi mod RPCs
3658         [ -z "$num" ] && num=1
3659
3660         echo "creating $num files ..."
3661         umask 0022
3662         for i in $(seq $num); do
3663                 touch $DIR/$tdir/file-$i
3664         done
3665
3666         replay_barrier $facet
3667
3668         # drop reply on MDT
3669         #define OBD_FAIL_MDS_REINT_MULTI_NET_REP 0x15a
3670         do_facet $facet "$LCTL set_param fail_loc=0x15a"
3671         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3672         for i in $(seq $num); do
3673                 chmod 0600 $DIR/$tdir/file-$i &
3674                 pids="$pids $!"
3675         done
3676         sleep 1
3677         do_facet $facet "$LCTL set_param fail_loc=0"
3678
3679         # fail MDT
3680         fail $facet
3681
3682         for pid in $pids; do
3683                 wait $pid || error "chmod failed"
3684         done
3685         echo "done ($(date +%H:%M:%S))"
3686
3687         # check chmod succeed
3688         for i in $(seq $num); do
3689                 checkstat -vp 0600 $DIR/$tdir/file-$i
3690         done
3691
3692         rm -rf $DIR/$tdir
3693 }
3694 run_test 102c "check replay w/o reconstruction with multiple mod RPCs in flight"
3695
3696 test_102d() {
3697         local idx
3698         local facet
3699         local num
3700         local i
3701         local pids pid
3702
3703         [[ $(lctl get_param mdc.*.import |
3704              grep "connect_flags:.*multi_mod_rpc") ]] ||
3705                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
3706
3707         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3708         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
3709         facet="mds$((0x$idx + 1))"
3710
3711         # get current value of max_mod_rcps_in_flight
3712         num=$($LCTL get_param -n \
3713                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
3714         # set default value if client does not support multi mod RPCs
3715         [ -z "$num" ] && num=1
3716
3717         echo "creating $num files ..."
3718         umask 0022
3719         for i in $(seq $num); do
3720                 touch $DIR/$tdir/file-$i
3721         done
3722
3723         # drop reply on MDT
3724         #define OBD_FAIL_MDS_REINT_MULTI_NET_REP 0x15a
3725         do_facet $facet "$LCTL set_param fail_loc=0x15a"
3726         echo "launch $num chmod in parallel ($(date +%H:%M:%S)) ..."
3727         for i in $(seq $num); do
3728                 chmod 0600 $DIR/$tdir/file-$i &
3729                 pids="$pids $!"
3730         done
3731         sleep 1
3732
3733         # write MDT transactions to disk
3734         do_facet $facet "sync; sync; sync"
3735
3736         do_facet $facet "$LCTL set_param fail_loc=0"
3737
3738         # fail MDT
3739         fail $facet
3740
3741         for pid in $pids; do
3742                 wait $pid || error "chmod failed"
3743         done
3744         echo "done ($(date +%H:%M:%S))"
3745
3746         # check chmod succeed
3747         for i in $(seq $num); do
3748                 checkstat -vp 0600 $DIR/$tdir/file-$i
3749         done
3750
3751         rm -rf $DIR/$tdir
3752 }
3753 run_test 102d "check replay & reconstruction with multiple mod RPCs in flight"
3754
3755 test_103() {
3756         remote_mds_nodsh && skip "remote MDS with nodsh" && return
3757 #define OBD_FAIL_MDS_TRACK_OVERFLOW 0x162
3758         do_facet mds1 $LCTL set_param fail_loc=0x80000162
3759
3760         mkdir -p $DIR/$tdir
3761         createmany -o $DIR/$tdir/t- 30 ||
3762                 error "create files on remote directory failed"
3763         sync
3764         rm -rf $DIR/$tdir/t-*
3765         sync
3766 #MDS should crash with tr->otr_next_id overflow
3767         fail mds1
3768 }
3769 run_test 103 "Check otr_next_id overflow"
3770
3771
3772 check_striped_dir_110()
3773 {
3774         $CHECKSTAT -t dir $DIR/$tdir/striped_dir ||
3775                         error "create striped dir failed"
3776         local stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
3777         [ $stripe_count -eq $MDSCOUNT ] ||
3778                 error "$stripe_count != 2 after recovery"
3779 }
3780
3781 test_110a() {
3782         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3783         ([ $FAILURE_MODE == "HARD" ] &&
3784                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3785                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3786                 return 0
3787
3788         mkdir -p $DIR/$tdir
3789         replay_barrier mds1
3790         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3791         fail mds1
3792
3793         check_striped_dir_110 || error "check striped_dir failed"
3794         rm -rf $DIR/$tdir || error "rmdir failed"
3795
3796         return 0
3797 }
3798 run_test 110a "DNE: create striped dir, fail MDT1"
3799
3800 test_110b() {
3801         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3802         ([ $FAILURE_MODE == "HARD" ] &&
3803                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3804                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3805                 return 0
3806
3807         mkdir -p $DIR/$tdir
3808         replay_barrier mds1
3809         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3810         umount $MOUNT
3811         fail mds1
3812         zconf_mount $(hostname) $MOUNT
3813         client_up || return 1
3814
3815         check_striped_dir_110 || error "check striped_dir failed"
3816
3817         rm -rf $DIR/$tdir || error "rmdir failed"
3818
3819         return 0
3820 }
3821 run_test 110b "DNE: create striped dir, fail MDT1 and client"
3822
3823 test_110c() {
3824         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3825         ([ $FAILURE_MODE == "HARD" ] &&
3826                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3827                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3828                 return 0
3829
3830         mkdir -p $DIR/$tdir
3831         replay_barrier mds2
3832         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3833         fail mds2
3834
3835         check_striped_dir_110 || error "check striped_dir failed"
3836
3837         rm -rf $DIR/$tdir || error "rmdir failed"
3838
3839         return 0
3840 }
3841 run_test 110c "DNE: create striped dir, fail MDT2"
3842
3843 test_110d() {
3844         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3845         ([ $FAILURE_MODE == "HARD" ] &&
3846                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3847                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3848                 return 0
3849
3850         mkdir -p $DIR/$tdir
3851         replay_barrier mds2
3852         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3853         umount $MOUNT
3854         fail mds2
3855         zconf_mount $(hostname) $MOUNT
3856         client_up || return 1
3857
3858         check_striped_dir_110 || error "check striped_dir failed"
3859
3860         rm -rf $DIR/$tdir || error "rmdir failed"
3861
3862         return 0
3863 }
3864 run_test 110d "DNE: create striped dir, fail MDT2 and client"
3865
3866 test_110e() {
3867         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3868         ([ $FAILURE_MODE == "HARD" ] &&
3869                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3870                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3871                 return 0
3872
3873         mkdir -p $DIR/$tdir
3874         replay_barrier mds2
3875         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3876         umount $MOUNT
3877         replay_barrier mds1
3878         fail mds1,mds2
3879         zconf_mount $(hostname) $MOUNT
3880         client_up || return 1
3881
3882         check_striped_dir_110 || error "check striped_dir failed"
3883
3884         rm -rf $DIR/$tdir || error "rmdir failed"
3885
3886         return 0
3887 }
3888 run_test 110e "DNE: create striped dir, uncommit on MDT2, fail client/MDT1/MDT2"
3889
3890 test_110f() {
3891         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3892         ([ $FAILURE_MODE == "HARD" ] &&
3893                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3894                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3895                 return 0
3896
3897         mkdir -p $DIR/$tdir
3898         replay_barrier mds1
3899         replay_barrier mds2
3900         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3901         fail mds1,mds2
3902
3903         check_striped_dir_110 || error "check striped_dir failed"
3904
3905         rm -rf $DIR/$tdir || error "rmdir failed"
3906
3907         return 0
3908 }
3909 run_test 110f "DNE: create striped dir, fail MDT1/MDT2"
3910
3911 test_110g() {
3912         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3913         ([ $FAILURE_MODE == "HARD" ] &&
3914                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3915                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3916                 return 0
3917
3918         mkdir -p $DIR/$tdir
3919         replay_barrier mds1
3920         $LFS mkdir -i1 -c$MDSCOUNT $DIR/$tdir/striped_dir
3921         umount $MOUNT
3922         replay_barrier mds2
3923         fail mds1,mds2
3924         zconf_mount $(hostname) $MOUNT
3925         client_up || return 1
3926
3927         check_striped_dir_110 || error "check striped_dir failed"
3928
3929         rm -rf $DIR/$tdir || error "rmdir failed"
3930
3931         return 0
3932 }
3933 run_test 110g "DNE: create striped dir, uncommit on MDT1, fail client/MDT1/MDT2"
3934
3935 test_111a() {
3936         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3937         ([ $FAILURE_MODE == "HARD" ] &&
3938                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3939                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3940                 return 0
3941
3942         mkdir -p $DIR/$tdir
3943         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
3944         replay_barrier mds1
3945         rm -rf $DIR/$tdir/striped_dir
3946         fail mds1
3947
3948         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
3949                         error "striped dir still exists"
3950         return 0
3951 }
3952 run_test 111a "DNE: unlink striped dir, fail MDT1"
3953
3954 test_111b() {
3955         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3956         ([ $FAILURE_MODE == "HARD" ] &&
3957                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3958                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3959                 return 0
3960
3961         mkdir -p $DIR/$tdir
3962         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
3963         replay_barrier mds2
3964         rm -rf $DIR/$tdir/striped_dir
3965         umount $MOUNT
3966         fail mds2
3967         zconf_mount $(hostname) $MOUNT
3968         client_up || return 1
3969
3970         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
3971                         error "striped dir still exists"
3972         return 0
3973 }
3974 run_test 111b "DNE: unlink striped dir, fail MDT2"
3975
3976 test_111c() {
3977         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3978         ([ $FAILURE_MODE == "HARD" ] &&
3979                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3980                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3981                 return 0
3982
3983         mkdir -p $DIR/$tdir
3984         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
3985         replay_barrier mds1
3986         rm -rf $DIR/$tdir/striped_dir
3987         umount $MOUNT
3988         replay_barrier mds2
3989         fail mds1,mds2
3990         zconf_mount $(hostname) $MOUNT
3991         client_up || return 1
3992         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
3993                         error "striped dir still exists"
3994         return 0
3995 }
3996 run_test 111c "DNE: unlink striped dir, uncommit on MDT1, fail client/MDT1/MDT2"
3997
3998 test_111d() {
3999         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4000         ([ $FAILURE_MODE == "HARD" ] &&
4001                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4002                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4003                 return 0
4004
4005         mkdir -p $DIR/$tdir
4006         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4007         replay_barrier mds2
4008         rm -rf $DIR/$tdir/striped_dir
4009         umount $MOUNT
4010         replay_barrier mds1
4011         fail mds1,mds2
4012         zconf_mount $(hostname) $MOUNT
4013         client_up || return 1
4014         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4015                         error "striped dir still exists"
4016
4017         return 0
4018 }
4019 run_test 111d "DNE: unlink striped dir, uncommit on MDT2, fail client/MDT1/MDT2"
4020
4021 test_111e() {
4022         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4023         ([ $FAILURE_MODE == "HARD" ] &&
4024                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4025                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4026                 return 0
4027
4028         mkdir -p $DIR/$tdir
4029         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4030         replay_barrier mds2
4031         rm -rf $DIR/$tdir/striped_dir
4032         replay_barrier mds1
4033         fail mds1,mds2
4034         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4035                         error "striped dir still exists"
4036         return 0
4037 }
4038 run_test 111e "DNE: unlink striped dir, uncommit on MDT2, fail MDT1/MDT2"
4039
4040 test_111f() {
4041         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4042         ([ $FAILURE_MODE == "HARD" ] &&
4043                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4044                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4045                 return 0
4046
4047         mkdir -p $DIR/$tdir
4048         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4049         replay_barrier mds1
4050         rm -rf $DIR/$tdir/striped_dir
4051         replay_barrier mds2
4052         fail mds1,mds2
4053         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4054                         error "striped dir still exists"
4055         return 0
4056 }
4057 run_test 111f "DNE: unlink striped dir, uncommit on MDT1, fail MDT1/MDT2"
4058
4059 test_111g() {
4060         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4061         ([ $FAILURE_MODE == "HARD" ] &&
4062                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4063                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4064                 return 0
4065
4066         mkdir -p $DIR/$tdir
4067         $LFS mkdir -i1 -c2 $DIR/$tdir/striped_dir
4068         replay_barrier mds1
4069         replay_barrier mds2
4070         rm -rf $DIR/$tdir/striped_dir
4071         fail mds1,mds2
4072         $CHECKSTAT -t dir $DIR/$tdir/striped_dir &&
4073                         error "striped dir still exists"
4074         return 0
4075 }
4076 run_test 111g "DNE: unlink striped dir, fail MDT1/MDT2"
4077
4078 test_112_rename_prepare() {
4079         mkdir -p $DIR/$tdir/src_dir
4080         $LFS mkdir -i 1 $DIR/$tdir/src_dir/src_child ||
4081                 error "create remote source failed"
4082
4083         touch $DIR/$tdir/src_dir/src_child/a
4084
4085         $LFS mkdir -i 2 $DIR/$tdir/tgt_dir ||
4086                 error "create remote target dir failed"
4087
4088         $LFS mkdir -i 3 $DIR/$tdir/tgt_dir/tgt_child ||
4089                 error "create remote target child failed"
4090 }
4091
4092 test_112_check() {
4093         find $DIR/$tdir/
4094         $CHECKSTAT -t dir $DIR/$tdir/src_dir/src_child &&
4095                 error "src_child still exists after rename"
4096
4097         $CHECKSTAT -t file $DIR/$tdir/tgt_dir/tgt_child/a ||
4098                 error "missing file(a) after rename"
4099 }
4100
4101 test_112a() {
4102         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4103         ([ $FAILURE_MODE == "HARD" ] &&
4104                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4105                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4106                 return 0
4107
4108         test_112_rename_prepare
4109         replay_barrier mds1
4110
4111         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4112                 error "rename dir cross MDT failed!"
4113         fail mds1
4114
4115         test_112_check
4116         rm -rf $DIR/$tdir || error "rmdir failed"
4117 }
4118 run_test 112a "DNE: cross MDT rename, fail MDT1"
4119
4120 test_112b() {
4121         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4122         ([ $FAILURE_MODE == "HARD" ] &&
4123                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4124                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4125                 return 0
4126
4127         test_112_rename_prepare
4128         replay_barrier mds2
4129
4130         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4131                 error "rename dir cross MDT failed!"
4132
4133         fail mds2
4134
4135         test_112_check
4136         rm -rf $DIR/$tdir || error "rmdir failed"
4137 }
4138 run_test 112b "DNE: cross MDT rename, fail MDT2"
4139
4140 test_112c() {
4141         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4142         ([ $FAILURE_MODE == "HARD" ] &&
4143                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4144                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4145                 return 0
4146
4147         test_112_rename_prepare
4148         replay_barrier mds3
4149
4150         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4151                 error "rename dir cross MDT failed!"
4152
4153         fail mds3
4154
4155         test_112_check
4156         rm -rf $DIR/$tdir || error "rmdir failed"
4157 }
4158 run_test 112c "DNE: cross MDT rename, fail MDT3"
4159
4160 test_112d() {
4161         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4162         ([ $FAILURE_MODE == "HARD" ] &&
4163                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4164                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4165                 return 0
4166
4167         test_112_rename_prepare
4168         replay_barrier mds4
4169
4170         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4171                 error "rename dir cross MDT failed!"
4172
4173         fail mds4
4174
4175         test_112_check
4176         rm -rf $DIR/$tdir || error "rmdir failed"
4177 }
4178 run_test 112d "DNE: cross MDT rename, fail MDT4"
4179
4180 test_112e() {
4181         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4182         ([ $FAILURE_MODE == "HARD" ] &&
4183                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4184                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4185                 return 0
4186
4187         test_112_rename_prepare
4188         replay_barrier mds1
4189         replay_barrier mds2
4190
4191         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4192                 error "rename dir cross MDT failed!"
4193
4194         fail mds1,mds2
4195
4196         test_112_check
4197         rm -rf $DIR/$tdir || error "rmdir failed"
4198 }
4199 run_test 112e "DNE: cross MDT rename, fail MDT1 and MDT2"
4200
4201 test_112f() {
4202         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4203         ([ $FAILURE_MODE == "HARD" ] &&
4204                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4205                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4206                 return 0
4207
4208         test_112_rename_prepare
4209         replay_barrier mds1
4210         replay_barrier mds3
4211
4212         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4213                 error "rename dir cross MDT failed!"
4214
4215         fail mds1,mds3
4216
4217         test_112_check
4218         rm -rf $DIR/$tdir || error "rmdir failed"
4219 }
4220 run_test 112f "DNE: cross MDT rename, fail MDT1 and MDT3"
4221
4222 test_112g() {
4223         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4224         ([ $FAILURE_MODE == "HARD" ] &&
4225                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4226                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4227                 return 0
4228
4229         test_112_rename_prepare
4230         replay_barrier mds1
4231         replay_barrier mds4
4232
4233         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4234                 error "rename dir cross MDT failed!"
4235
4236         fail mds1,mds4
4237
4238         test_112_check
4239         rm -rf $DIR/$tdir || error "rmdir failed"
4240 }
4241 run_test 112g "DNE: cross MDT rename, fail MDT1 and MDT4"
4242
4243 test_112h() {
4244         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4245         ([ $FAILURE_MODE == "HARD" ] &&
4246                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4247                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4248                 return 0
4249
4250         test_112_rename_prepare
4251         replay_barrier mds2
4252         replay_barrier mds3
4253
4254         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4255                 error "rename dir cross MDT failed!"
4256
4257         fail mds2,mds3
4258
4259         test_112_check
4260         rm -rf $DIR/$tdir || error "rmdir failed"
4261 }
4262 run_test 112h "DNE: cross MDT rename, fail MDT2 and MDT3"
4263
4264 test_112i() {
4265         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4266         ([ $FAILURE_MODE == "HARD" ] &&
4267                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4268                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4269                 return 0
4270
4271         test_112_rename_prepare
4272         replay_barrier mds2
4273         replay_barrier mds4
4274
4275         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4276                 error "rename dir cross MDT failed!"
4277
4278         fail mds2,mds4
4279
4280         test_112_check
4281         rm -rf $DIR/$tdir || error "rmdir failed"
4282 }
4283 run_test 112i "DNE: cross MDT rename, fail MDT2 and MDT4"
4284
4285 test_112j() {
4286         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4287         ([ $FAILURE_MODE == "HARD" ] &&
4288                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4289                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4290                 return 0
4291
4292         test_112_rename_prepare
4293         replay_barrier mds3
4294         replay_barrier mds4
4295
4296         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4297                 error "rename dir cross MDT failed!"
4298
4299         fail mds3,mds4
4300
4301         test_112_check
4302         rm -rf $DIR/$tdir || error "rmdir failed"
4303 }
4304 run_test 112j "DNE: cross MDT rename, fail MDT3 and MDT4"
4305
4306 test_112k() {
4307         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4308         ([ $FAILURE_MODE == "HARD" ] &&
4309                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4310                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4311                 return 0
4312
4313         test_112_rename_prepare
4314         replay_barrier mds1
4315         replay_barrier mds2
4316         replay_barrier mds3
4317
4318         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4319                 error "rename dir cross MDT failed!"
4320
4321         fail mds1,mds2,mds3
4322
4323         test_112_check
4324         rm -rf $DIR/$tdir || error "rmdir failed"
4325 }
4326 run_test 112k "DNE: cross MDT rename, fail MDT1,MDT2,MDT3"
4327
4328 test_112l() {
4329         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4330         ([ $FAILURE_MODE == "HARD" ] &&
4331                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4332                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4333                 return 0
4334
4335         test_112_rename_prepare
4336         replay_barrier mds1
4337         replay_barrier mds2
4338         replay_barrier mds4
4339
4340         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4341                 error "rename dir cross MDT failed!"
4342
4343         fail mds1,mds2,mds4
4344
4345         test_112_check
4346         rm -rf $DIR/$tdir || error "rmdir failed"
4347 }
4348 run_test 112l "DNE: cross MDT rename, fail MDT1,MDT2,MDT4"
4349
4350 test_112m() {
4351         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4352         ([ $FAILURE_MODE == "HARD" ] &&
4353                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4354                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4355                 return 0
4356
4357         test_112_rename_prepare
4358         replay_barrier mds1
4359         replay_barrier mds3
4360         replay_barrier mds4
4361
4362         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4363                 error "rename dir cross MDT failed!"
4364
4365         fail mds1,mds3,mds4
4366
4367         test_112_check
4368         rm -rf $DIR/$tdir || error "rmdir failed"
4369 }
4370 run_test 112m "DNE: cross MDT rename, fail MDT1,MDT3,MDT4"
4371
4372 test_112n() {
4373         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4374         ([ $FAILURE_MODE == "HARD" ] &&
4375                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4376                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4377                 return 0
4378
4379         test_112_rename_prepare
4380         replay_barrier mds2
4381         replay_barrier mds3
4382         replay_barrier mds4
4383
4384         mrename $DIR/$tdir/src_dir/src_child $DIR/$tdir/tgt_dir/tgt_child ||
4385                 error "rename dir cross MDT failed!"
4386
4387         fail mds2,mds3,mds4
4388
4389         test_112_check
4390         rm -rf $DIR/$tdir || error "rmdir failed"
4391 }
4392 run_test 112n "DNE: cross MDT rename, fail MDT2,MDT3,MDT4"
4393
4394 test_115() {
4395         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4396         ([ $FAILURE_MODE == "HARD" ] &&
4397                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4398                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4399                 return 0
4400         local fail_index=0
4401         local index
4402         local i
4403         local j
4404
4405         mkdir -p $DIR/$tdir
4406         for ((j=0;j<$((MDSCOUNT));j++)); do
4407                 fail_index=$((fail_index+1))
4408                 index=$((fail_index % MDSCOUNT))
4409                 replay_barrier mds$((index + 1))
4410                 for ((i=0;i<5;i++)); do
4411                         test_mkdir -i$index -c$MDSCOUNT $DIR/$tdir/test_$i ||
4412                                 error "create striped dir $DIR/$tdir/test_$i"
4413                 done
4414
4415                 fail mds$((index + 1))
4416                 for ((i=0;i<5;i++)); do
4417                         checkstat -t dir $DIR/$tdir/test_$i ||
4418                                 error "$DIR/$tdir/test_$i does not exist!"
4419                 done
4420                 rm -rf $DIR/$tdir/test_* ||
4421                                 error "rmdir fails"
4422         done
4423 }
4424 run_test 115 "failover for create/unlink striped directory"
4425
4426 test_116a() {
4427         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4428         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
4429                 skip "Do not support large update log before 2.7.55" &&
4430                 return 0
4431         ([ $FAILURE_MODE == "HARD" ] &&
4432                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4433                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4434                 return 0
4435         local fail_index=0
4436
4437         mkdir -p $DIR/$tdir
4438         replay_barrier mds1
4439
4440         # OBD_FAIL_SPLIT_UPDATE_REC       0x1702
4441         do_facet mds1 "lctl set_param fail_loc=0x80001702"
4442         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
4443
4444         fail mds1
4445         $CHECKSTAT -t dir $DIR/$tdir/striped_dir ||
4446                 error "stried_dir does not exists"
4447 }
4448 run_test 116a "large update log master MDT recovery"
4449
4450 test_116b() {
4451         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4452         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.55) ] &&
4453                 skip "Do not support large update log before 2.7.55" &&
4454                 return 0
4455
4456         ([ $FAILURE_MODE == "HARD" ] &&
4457                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4458                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4459                 return 0
4460         local fail_index=0
4461
4462         mkdir -p $DIR/$tdir
4463         replay_barrier mds2
4464
4465         # OBD_FAIL_SPLIT_UPDATE_REC       0x1702
4466         do_facet mds2 "lctl set_param fail_loc=0x80001702"
4467         $LFS setdirstripe -c$MDSCOUNT $DIR/$tdir/striped_dir
4468
4469         fail mds2
4470         $CHECKSTAT -t dir $DIR/$tdir/striped_dir ||
4471                 error "stried_dir does not exists"
4472 }
4473 run_test 116b "large update log slave MDT recovery"
4474
4475 test_117() {
4476         [ $MDSCOUNT -lt 4 ] && skip "needs >= 4 MDTs" && return 0
4477         ([ $FAILURE_MODE == "HARD" ] &&
4478                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
4479                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
4480                 return 0
4481         local index
4482         local mds_indexs
4483
4484         mkdir -p $DIR/$tdir
4485         $LFS setdirstripe -i0 -c$MDSCOUNT $DIR/$tdir/remote_dir
4486         $LFS setdirstripe -i1 -c$MDSCOUNT $DIR/$tdir/remote_dir_1
4487         sleep 2
4488
4489         # Let's set rdonly on all MDTs, so client will send
4490         # replay requests on all MDTs and replay these requests
4491         # at the same time. This test will verify the recovery
4492         # will not be deadlock in this case, LU-7531.
4493         for ((index = 0; index < $((MDSCOUNT)); index++)); do
4494                 replay_barrier mds$((index + 1))
4495                 if [ -z $mds_indexs ]; then
4496                         mds_indexs="${mds_indexs}mds$((index+1))"
4497                 else
4498                         mds_indexs="${mds_indexs},mds$((index+1))"
4499                 fi
4500         done
4501
4502         rm -rf $DIR/$tdir/remote_dir
4503         rm -rf $DIR/$tdir/remote_dir_1
4504
4505         fail $mds_indexs
4506
4507         rm -rf $DIR/$tdir || error "rmdir failed"
4508 }
4509 run_test 117 "DNE: cross MDT unlink, fail MDT1 and MDT2"
4510
4511 test_118() {
4512         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4513         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4514                 skip "Do not support large update log before 2.7.64" &&
4515                 return 0
4516
4517         mkdir -p $DIR/$tdir
4518
4519         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir ||
4520                 error "setdirstripe fails"
4521         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir1 ||
4522                 error "setdirstripe fails 1"
4523         rm -rf $DIR/$tdir/striped_dir* || error "rmdir fails"
4524
4525         # OBD_FAIL_INVALIDATE_UPDATE       0x1705
4526         do_facet mds1 "lctl set_param fail_loc=0x1705"
4527         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir
4528         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir1
4529         do_facet mds1 "lctl set_param fail_loc=0x0"
4530
4531         replay_barrier mds1
4532         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir
4533         $LFS setdirstripe -c2 $DIR/$tdir/striped_dir1
4534         fail mds1
4535
4536         true
4537 }
4538 run_test 118 "invalidate osp update will not cause update log corruption"
4539
4540 test_119() {
4541         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4542         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4543                 skip "Do not support large update log before 2.7.64" &&
4544                 return 0
4545         local stripe_count
4546         local hard_timeout=$(do_facet mds1 \
4547                 "lctl get_param -n mdt.$FSNAME-MDT0000.recovery_time_hard")
4548
4549         local clients=${CLIENTS:-$HOSTNAME}
4550         local time_min=$(recovery_time_min)
4551
4552         mkdir -p $DIR/$tdir
4553         mkdir $DIR/$tdir/tmp
4554         rmdir $DIR/$tdir/tmp
4555
4556         replay_barrier mds1
4557         mkdir $DIR/$tdir/dir_1
4558         for ((i = 0; i < 20; i++)); do
4559                 $LFS setdirstripe -c2 $DIR/$tdir/stripe_dir-$i
4560         done
4561
4562         stop mds1
4563         change_active mds1
4564         wait_for_facet mds1
4565
4566         #define OBD_FAIL_TGT_REPLAY_DELAY  0x714
4567         do_facet mds1 $LCTL set_param fail_loc=0x80000714
4568         #sleep (timeout + 5), so mds will evict the client exports,
4569         #but DNE update recovery will keep going.
4570         do_facet mds1 $LCTL set_param fail_val=$((time_min + 5))
4571
4572         mount_facet mds1 "-o recovery_time_hard=$time_min"
4573
4574         wait_clients_import_state "$clients" mds1 FULL
4575
4576         clients_up || clients_up || error "failover df: $?"
4577
4578         #revert back the hard timeout
4579         do_facet mds1 $LCTL set_param \
4580                 mdt.$FSNAME-MDT0000.recovery_time_hard=$hard_timeout
4581
4582         for ((i = 0; i < 20; i++)); do
4583                 stripe_count=$($LFS getdirstripe -c $DIR/$tdir/stripe_dir-$i)
4584                 [ $stripe_count == 2 ] || {
4585                         error "stripe_dir-$i creation replay fails"
4586                         break
4587                 }
4588         done
4589 }
4590 run_test 119 "timeout of normal replay does not cause DNE replay fails  "
4591
4592 test_120() {
4593         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
4594         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.7.64) ] &&
4595                 skip "Do not support large update log before 2.7.64" &&
4596                 return 0
4597
4598         mkdir $DIR/$tdir
4599         replay_barrier_nosync mds1
4600         for ((i = 0; i < 20; i++)); do
4601                 mkdir $DIR/$tdir/dir-$i || {
4602                         error "create dir-$i fails"
4603                         break
4604                 }
4605                 $LFS setdirstripe -c2 $DIR/$tdir/stripe_dir-$i || {
4606                         error "create stripe_dir-$i fails"
4607                         break
4608                 }
4609         done
4610
4611         fail_abort mds1
4612
4613         for ((i = 0; i < 20; i++)); do
4614                 [ ! -e "$DIR/$tdir/dir-$i" ] || {
4615                         error "dir-$i still exists"
4616                         break
4617                 }
4618                 [ ! -e "$DIR/$tdir/stripe_dir-$i" ] || {
4619                         error "stripe_dir-$i still exists"
4620                         break
4621                 }
4622         done
4623 }
4624 run_test 120 "DNE fail abort should stop both normal and DNE replay"
4625
4626 complete $SECONDS
4627 check_and_cleanup_lustre
4628 exit_status