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