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