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