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