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