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