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