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