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