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