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