Whamcloud - gitweb
LU-13614 ldlm: revert LU-11762
[fs/lustre-release.git] / lustre / tests / replay-single.sh
1 #!/bin/bash
2
3 set -e
4
5 LUSTRE=${LUSTRE:-$(dirname $0)/..}
6 . $LUSTRE/tests/test-framework.sh
7 init_test_env $@
8 init_logging
9
10 ALWAYS_EXCEPT="$REPLAY_SINGLE_EXCEPT "
11 # bug number for skipped test: LU-13614
12 ALWAYS_EXCEPT+="               59"
13
14 if [ "$mds1_FSTYPE" = zfs ]; then
15         # bug number for skipped test: LU-11388
16         ALWAYS_EXCEPT+="               131b"
17 fi
18 if $SHARED_KEY; then
19         # bug number for skipped tests: LU-9795 (all below)
20         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   0b      0c      0d      34      45"
21         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   47      58b     58c     71a     85a"
22         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   85b     86      88      89      90"
23         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   93a     100a    100b    120"
24 fi
25 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
26
27 build_test_filter
28
29 CHECK_GRANT=${CHECK_GRANT:-"yes"}
30 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
31
32 require_dsh_mds || exit 0
33 check_and_setup_lustre
34
35 mkdir -p $DIR
36
37 assert_DIR
38 rm -rf $DIR/[df][0-9]* $DIR/f.$TESTSUITE.*
39
40 # LU-482 Avert LVM and VM inability to flush caches in pre .33 kernels
41 if [ $LINUX_VERSION_CODE -lt $(version_code 2.6.33) ]; then
42     sync
43     do_facet $SINGLEMDS sync
44 fi
45
46 test_0a() {     # was test_0
47         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
48         replay_barrier $SINGLEMDS
49         fail $SINGLEMDS
50         rmdir $DIR/$tdir
51 }
52 run_test 0a "empty replay"
53
54 test_0b() {
55         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
56
57         # this test attempts to trigger a race in the precreation code,
58         # and must run before any other objects are created on the filesystem
59         fail ost1
60         createmany -o $DIR/$tfile 20 || error "createmany -o $DIR/$tfile failed"
61         unlinkmany $DIR/$tfile 20 || error "unlinkmany $DIR/$tfile failed"
62 }
63 run_test 0b "ensure object created after recover exists. (3284)"
64
65 test_0c() {
66         replay_barrier $SINGLEMDS
67         mcreate $DIR/$tfile
68         umount $MOUNT
69         facet_failover $SINGLEMDS
70         zconf_mount $(hostname) $MOUNT || error "mount fails"
71         client_up || error "post-failover df failed"
72         # file shouldn't exist if replay-barrier works as expected
73         rm $DIR/$tfile && error "File exists and it shouldn't"
74         return 0
75 }
76 run_test 0c "check replay-barrier"
77
78 test_0d() {
79         replay_barrier $SINGLEMDS
80         umount $MOUNT
81         facet_failover $SINGLEMDS
82         zconf_mount $(hostname) $MOUNT || error "mount fails"
83         client_up || error "post-failover df failed"
84 }
85 run_test 0d "expired recovery with no clients"
86
87 test_1() {
88         replay_barrier $SINGLEMDS
89         mcreate $DIR/$tfile
90         fail $SINGLEMDS
91         $CHECKSTAT -t file $DIR/$tfile ||
92                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
93         rm $DIR/$tfile
94 }
95 run_test 1 "simple create"
96
97 test_2a() {
98         replay_barrier $SINGLEMDS
99         touch $DIR/$tfile
100         fail $SINGLEMDS
101         $CHECKSTAT -t file $DIR/$tfile ||
102                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
103         rm $DIR/$tfile
104 }
105 run_test 2a "touch"
106
107 test_2b() {
108         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
109         replay_barrier $SINGLEMDS
110         touch $DIR/$tfile
111         fail $SINGLEMDS
112         $CHECKSTAT -t file $DIR/$tfile ||
113                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
114         rm $DIR/$tfile
115 }
116 run_test 2b "touch"
117
118 test_2c() {
119         replay_barrier $SINGLEMDS
120         $LFS setstripe -c $OSTCOUNT $DIR/$tfile
121         fail $SINGLEMDS
122         $CHECKSTAT -t file $DIR/$tfile ||
123                 error "$CHECKSTAT $DIR/$tfile check failed"
124 }
125 run_test 2c "setstripe replay"
126
127 test_2d() {
128         [[ "$mds1_FSTYPE" = zfs ]] &&
129                 [[ "$MDS1_VERSION" -lt $(version_code 2.12.51) ]] &&
130                 skip "requires LU-10143 fix on MDS"
131         replay_barrier $SINGLEMDS
132         $LFS setdirstripe -i 0 -c $MDSCOUNT $DIR/$tdir
133         fail $SINGLEMDS
134         $CHECKSTAT -t dir $DIR/$tdir ||
135                 error "$CHECKSTAT $DIR/$tdir check failed"
136 }
137 run_test 2d "setdirstripe replay"
138
139 test_3a() {
140         local file=$DIR/$tfile
141         replay_barrier $SINGLEMDS
142         mcreate $file
143         openfile -f O_DIRECTORY $file
144         fail $SINGLEMDS
145         $CHECKSTAT -t file $file ||
146                 error "$CHECKSTAT $file attribute check failed"
147         rm $file
148 }
149 run_test 3a "replay failed open(O_DIRECTORY)"
150
151 test_3b() {
152         replay_barrier $SINGLEMDS
153         #define OBD_FAIL_MDS_OPEN_PACK | OBD_FAIL_ONCE
154         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000114"
155         touch $DIR/$tfile
156         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
157         fail $SINGLEMDS
158         $CHECKSTAT -t file $DIR/$tfile &&
159                 error "$CHECKSTAT $DIR/$tfile attribute check should fail"
160         return 0
161 }
162 run_test 3b "replay failed open -ENOMEM"
163
164 test_3c() {
165         replay_barrier $SINGLEMDS
166         #define OBD_FAIL_MDS_ALLOC_OBDO | OBD_FAIL_ONCE
167         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000128"
168         touch $DIR/$tfile
169         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
170         fail $SINGLEMDS
171
172         $CHECKSTAT -t file $DIR/$tfile &&
173                 error "$CHECKSTAT $DIR/$tfile attribute check should fail"
174         return 0
175 }
176 run_test 3c "replay failed open -ENOMEM"
177
178 test_4a() {     # was test_4
179         replay_barrier $SINGLEMDS
180         for i in $(seq 10); do
181                 echo "tag-$i" > $DIR/$tfile-$i
182         done
183         fail $SINGLEMDS
184         for i in $(seq 10); do
185                 grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
186         done
187 }
188 run_test 4a "|x| 10 open(O_CREAT)s"
189
190 test_4b() {
191         for i in $(seq 10); do
192                 echo "tag-$i" > $DIR/$tfile-$i
193         done
194         replay_barrier $SINGLEMDS
195         rm -rf $DIR/$tfile-*
196         fail $SINGLEMDS
197         $CHECKSTAT -t file $DIR/$tfile-* &&
198                 error "$CHECKSTAT $DIR/$tfile-* attribute check should fail" ||
199                 true
200 }
201 run_test 4b "|x| rm 10 files"
202
203 # The idea is to get past the first block of precreated files on both
204 # osts, and then replay.
205 test_5() {
206         replay_barrier $SINGLEMDS
207         for i in $(seq 220); do
208                 echo "tag-$i" > $DIR/$tfile-$i
209         done
210         fail $SINGLEMDS
211         for i in $(seq 220); do
212                 grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
213         done
214         rm -rf $DIR/$tfile-*
215         sleep 3
216         # waiting for commitment of removal
217 }
218 run_test 5 "|x| 220 open(O_CREAT)"
219
220 test_6a() {     # was test_6
221         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
222         replay_barrier $SINGLEMDS
223         mcreate $DIR/$tdir/$tfile
224         fail $SINGLEMDS
225         $CHECKSTAT -t dir $DIR/$tdir ||
226                 error "$CHECKSTAT $DIR/$tdir attribute check failed"
227         $CHECKSTAT -t file $DIR/$tdir/$tfile ||
228                 error "$CHECKSTAT $DIR/$tdir/$tfile attribute check failed"
229         sleep 2
230         # waiting for log process thread
231 }
232 run_test 6a "mkdir + contained create"
233
234 test_6b() {
235         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
236         replay_barrier $SINGLEMDS
237         rm -rf $DIR/$tdir
238         fail $SINGLEMDS
239         $CHECKSTAT -t dir $DIR/$tdir &&
240                 error "$CHECKSTAT $DIR/$tdir attribute check should fail" ||
241                 true
242 }
243 run_test 6b "|X| rmdir"
244
245 test_7() {
246         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
247         replay_barrier $SINGLEMDS
248         mcreate $DIR/$tdir/$tfile
249         fail $SINGLEMDS
250         $CHECKSTAT -t dir $DIR/$tdir ||
251                 error "$CHECKSTAT $DIR/$tdir attribute check failed"
252         $CHECKSTAT -t file $DIR/$tdir/$tfile ||
253                 error "$CHECKSTAT $DIR/$tdir/$tfile attribute check failed"
254         rm -fr $DIR/$tdir
255 }
256 run_test 7 "mkdir |X| contained create"
257
258 test_8() {
259         replay_barrier $SINGLEMDS
260         multiop_bg_pause $DIR/$tfile mo_c ||
261                 error "multiop mknod $DIR/$tfile failed"
262         MULTIPID=$!
263         fail $SINGLEMDS
264         ls $DIR/$tfile
265         $CHECKSTAT -t file $DIR/$tfile ||
266                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
267         kill -USR1 $MULTIPID || error "multiop mknod $MULTIPID not running"
268         wait $MULTIPID || error "multiop mknod $MULTIPID failed"
269         rm $DIR/$tfile
270 }
271 run_test 8 "creat open |X| close"
272
273 test_9() {
274         replay_barrier $SINGLEMDS
275         mcreate $DIR/$tfile
276         local old_inum=$(ls -i $DIR/$tfile | awk '{print $1}')
277         fail $SINGLEMDS
278         local new_inum=$(ls -i $DIR/$tfile | awk '{print $1}')
279
280         echo " old_inum == $old_inum, new_inum == $new_inum"
281         if [ $old_inum -eq $new_inum  ] ;
282         then
283                 echo "old_inum and new_inum match"
284         else
285                 echo " old_inum and new_inum do not match"
286                 error "old index($old_inum) does not match new index($new_inum)"
287         fi
288         rm $DIR/$tfile
289 }
290 run_test 9 "|X| create (same inum/gen)"
291
292 test_10() {
293         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
294         replay_barrier $SINGLEMDS
295         mv $DIR/$tfile $DIR/$tfile-2
296         rm -f $DIR/$tfile
297         fail $SINGLEMDS
298         $CHECKSTAT $DIR/$tfile &&
299                 error "$CHECKSTAT $DIR/$tfile attribute check should fail"
300         $CHECKSTAT $DIR/$tfile-2 ||
301                 error "$CHECKSTAT $DIR/$tfile-2 attribute check failed"
302         rm $DIR/$tfile-2
303         return 0
304 }
305 run_test 10 "create |X| rename unlink"
306
307 test_11() {
308         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
309         echo "old" > $DIR/$tfile
310         mv $DIR/$tfile $DIR/$tfile-2
311         replay_barrier $SINGLEMDS
312         echo "new" > $DIR/$tfile
313         grep new $DIR/$tfile
314         grep old $DIR/$tfile-2
315         fail $SINGLEMDS
316         grep new $DIR/$tfile || error "grep $DIR/$tfile failed"
317         grep old $DIR/$tfile-2 || error "grep $DIR/$tfile-2 failed"
318 }
319 run_test 11 "create open write rename |X| create-old-name read"
320
321 test_12() {
322         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
323         multiop_bg_pause $DIR/$tfile o_tSc ||
324                 error "multiop_bg_pause $DIR/$tfile failed"
325         pid=$!
326         rm -f $DIR/$tfile
327         replay_barrier $SINGLEMDS
328         kill -USR1 $pid || error "multiop $pid not running"
329         wait $pid || error "multiop $pid failed"
330
331         fail $SINGLEMDS
332         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
333         return 0
334 }
335 run_test 12 "open, unlink |X| close"
336
337 # 1777 - replay open after committed chmod that would make
338 #        a regular open a failure
339 test_13() {
340         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
341         multiop_bg_pause $DIR/$tfile O_wc ||
342                 error "multiop_bg_pause $DIR/$tfile failed"
343         pid=$!
344         chmod 0 $DIR/$tfile
345         $CHECKSTAT -p 0 $DIR/$tfile ||
346                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
347         replay_barrier $SINGLEMDS
348         fail $SINGLEMDS
349         kill -USR1 $pid || error "multiop $pid not running"
350         wait $pid || error "multiop $pid failed"
351
352         $CHECKSTAT -s 1 -p 0 $DIR/$tfile ||
353                 error "second $CHECKSTAT $DIR/$tfile attribute check failed"
354         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
355         return 0
356 }
357 run_test 13 "open chmod 0 |x| write close"
358
359 test_14() {
360         multiop_bg_pause $DIR/$tfile O_tSc ||
361                 error "multiop_bg_pause $DIR/$tfile failed"
362         pid=$!
363         rm -f $DIR/$tfile
364         replay_barrier $SINGLEMDS
365         kill -USR1 $pid || error "multiop $pid not running"
366         wait $pid || error "multiop $pid failed"
367
368         fail $SINGLEMDS
369         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
370         return 0
371 }
372 run_test 14 "open(O_CREAT), unlink |X| close"
373
374 test_15() {
375         multiop_bg_pause $DIR/$tfile O_tSc ||
376                 error "multiop_bg_pause $DIR/$tfile failed"
377         pid=$!
378         rm -f $DIR/$tfile
379         replay_barrier $SINGLEMDS
380         touch $DIR/$tfile-1 || error "touch $DIR/$tfile-1 failed"
381         kill -USR1 $pid || error "multiop $pid not running"
382         wait $pid || error "multiop $pid failed"
383
384         fail $SINGLEMDS
385         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
386         touch $DIR/$tfile-2 || error "touch $DIR/$tfile-2 failed"
387         return 0
388 }
389 run_test 15 "open(O_CREAT), unlink |X|  touch new, close"
390
391 test_16() {
392         replay_barrier $SINGLEMDS
393         mcreate $DIR/$tfile
394         munlink $DIR/$tfile
395         mcreate $DIR/$tfile-2
396         fail $SINGLEMDS
397         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
398         [ -e $DIR/$tfile-2 ] || error "file $DIR/$tfile-2 does not exist"
399         munlink $DIR/$tfile-2 || error "munlink $DIR/$tfile-2 failed"
400 }
401 run_test 16 "|X| open(O_CREAT), unlink, touch new,  unlink new"
402
403 test_17() {
404         replay_barrier $SINGLEMDS
405         multiop_bg_pause $DIR/$tfile O_c ||
406                 error "multiop_bg_pause $DIR/$tfile failed"
407         pid=$!
408         fail $SINGLEMDS
409         kill -USR1 $pid || error "multiop $pid not running"
410         wait $pid || error "multiop $pid failed"
411         $CHECKSTAT -t file $DIR/$tfile ||
412                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
413         rm $DIR/$tfile
414 }
415 run_test 17 "|X| open(O_CREAT), |replay| close"
416
417 test_18() {
418         replay_barrier $SINGLEMDS
419         multiop_bg_pause $DIR/$tfile O_tSc ||
420                 error "multiop_bg_pause $DIR/$tfile failed"
421         pid=$!
422         rm -f $DIR/$tfile
423         touch $DIR/$tfile-2 || error "touch $DIR/$tfile-2 failed"
424         echo "pid: $pid will close"
425         kill -USR1 $pid || error "multiop $pid not running"
426         wait $pid || error "multiop $pid failed"
427
428         fail $SINGLEMDS
429         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
430         [ -e $DIR/$tfile-2 ] || error "file $DIR/$tfile-2 does not exist"
431         # this touch frequently fails
432         touch $DIR/$tfile-3 || error "touch $DIR/$tfile-3 failed"
433         munlink $DIR/$tfile-2 || error "munlink $DIR/$tfile-2 failed"
434         munlink $DIR/$tfile-3 || error "munlink $DIR/$tfile-3 failed"
435         return 0
436 }
437 run_test 18 "open(O_CREAT), unlink, touch new, close, touch, unlink"
438
439 # bug 1855 (a simpler form of test_11 above)
440 test_19() {
441         replay_barrier $SINGLEMDS
442         mcreate $DIR/$tfile
443         echo "old" > $DIR/$tfile
444         mv $DIR/$tfile $DIR/$tfile-2
445         grep old $DIR/$tfile-2
446         fail $SINGLEMDS
447         grep old $DIR/$tfile-2 || error "grep $DIR/$tfile-2 failed"
448 }
449 run_test 19 "mcreate, open, write, rename "
450
451 test_20a() {    # was test_20
452         replay_barrier $SINGLEMDS
453         multiop_bg_pause $DIR/$tfile O_tSc ||
454                 error "multiop_bg_pause $DIR/$tfile failed"
455         pid=$!
456         rm -f $DIR/$tfile
457
458         fail $SINGLEMDS
459         kill -USR1 $pid || error "multiop $pid not running"
460         wait $pid || error "multiop $pid failed"
461         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
462         return 0
463 }
464 run_test 20a "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
465
466 test_20b() { # bug 10480
467         local wait_timeout=$((TIMEOUT * 4))
468         local extra=$(fs_log_size)
469         local n_attempts=1
470
471         sync_all_data
472         $LFS setstripe -i 0 -c 1 $DIR
473
474         local beforeused=$(df -P $DIR | tail -1 | awk '{ print $3 }')
475
476         dd if=/dev/zero of=$DIR/$tfile bs=4k count=10000 &
477         while [ ! -e $DIR/$tfile ] ; do
478                 sleep 0.01                      # give dd a chance to start
479         done
480
481         $LFS getstripe $DIR/$tfile || error "$LFS getstripe $DIR/$tfile failed"
482         # make it an orphan
483         rm -f $DIR/$tfile || error "rm -f $DIR/$tfile failed"
484         mds_evict_client
485         client_up || client_up || true          # reconnect
486
487         do_facet $SINGLEMDS "lctl set_param -n osd*.*MDT*.force_sync=1"
488
489         fail $SINGLEMDS                         # start orphan recovery
490         wait_recovery_complete $SINGLEMDS || error "MDS recovery not done"
491         wait_delete_completed $wait_timeout || error "delete did not finish"
492         sync_all_data
493
494         while true; do
495                 local afterused=$(df -P $DIR | tail -1 | awk '{ print $3 }')
496                 log "before $beforeused, after $afterused"
497
498                 (( $beforeused + $extra >= $afterused )) && break
499                 n_attempts=$((n_attempts + 1))
500                 [ $n_attempts -gt 3 ] &&
501                         error "after $afterused > before $beforeused + $extra"
502
503                 wait_zfs_commit $SINGLEMDS 5
504                 sync_all_data
505         done
506 }
507
508 run_test 20b "write, unlink, eviction, replay (test mds_cleanup_orphans)"
509
510 test_20c() { # bug 10480
511         multiop_bg_pause $DIR/$tfile Ow_c ||
512                 error "multiop_bg_pause $DIR/$tfile failed"
513         pid=$!
514
515         ls -la $DIR/$tfile
516
517         mds_evict_client
518         client_up || client_up || true    # reconnect
519
520         kill -USR1 $pid || error "multiop $pid not running"
521         wait $pid || error "multiop $pid failed"
522         [ -s $DIR/$tfile ] || error "File was truncated"
523
524         return 0
525 }
526 run_test 20c "check that client eviction does not affect file content"
527
528 test_21() {
529         replay_barrier $SINGLEMDS
530         multiop_bg_pause $DIR/$tfile O_tSc ||
531                 error "multiop_bg_pause $DIR/$tfile failed"
532         pid=$!
533         rm -f $DIR/$tfile
534         touch $DIR/$tfile-1 || error "touch $DIR/$tfile-1 failed"
535
536         fail $SINGLEMDS
537         kill -USR1 $pid || error "multiop $pid not running"
538         wait $pid || error "multiop $pid failed"
539         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
540         touch $DIR/$tfile-2 || error "touch $DIR/$tfile-2 failed"
541         return 0
542 }
543 run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"
544
545 test_22() {
546         multiop_bg_pause $DIR/$tfile O_tSc ||
547                 error "multiop_bg_pause $DIR/$tfile failed"
548         pid=$!
549
550         replay_barrier $SINGLEMDS
551         rm -f $DIR/$tfile
552
553         fail $SINGLEMDS
554         kill -USR1 $pid || error "multiop $pid not running"
555         wait $pid || error "multiop $pid failed"
556         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
557         return 0
558 }
559 run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"
560
561 test_23() {
562         multiop_bg_pause $DIR/$tfile O_tSc ||
563                 error "multiop_bg_pause $DIR/$tfile failed"
564         pid=$!
565
566         replay_barrier $SINGLEMDS
567         rm -f $DIR/$tfile
568         touch $DIR/$tfile-1 || error "touch $DIR/$tfile-1 failed"
569
570         fail $SINGLEMDS
571         kill -USR1 $pid || error "multiop $pid not running"
572         wait $pid || error "multiop $pid failed"
573         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
574         touch $DIR/$tfile-2 || error "touch $DIR/$tfile-2 failed"
575         return 0
576 }
577 run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"
578
579 test_24() {
580         multiop_bg_pause $DIR/$tfile O_tSc ||
581                 error "multiop_bg_pause $DIR/$tfile failed"
582         pid=$!
583
584         replay_barrier $SINGLEMDS
585         fail $SINGLEMDS
586         rm -f $DIR/$tfile
587         kill -USR1 $pid || error "multiop $pid not running"
588         wait $pid || error "multiop $pid failed"
589         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
590         return 0
591 }
592 run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"
593
594 test_25() {
595         multiop_bg_pause $DIR/$tfile O_tSc ||
596                 error "multiop_bg_pause $DIR/$tfile failed"
597         pid=$!
598         rm -f $DIR/$tfile
599
600         replay_barrier $SINGLEMDS
601         fail $SINGLEMDS
602         kill -USR1 $pid || error "multiop $pid not running"
603         wait $pid || error "multiop $pid failed"
604         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
605         return 0
606 }
607 run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
608
609 test_26() {
610         replay_barrier $SINGLEMDS
611         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
612                 error "multiop_bg_pause $DIR/$tfile-1 failed"
613         pid1=$!
614         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
615                 error "multiop_bg_pause $DIR/$tfile-2 failed"
616         pid2=$!
617         rm -f $DIR/$tfile-1
618         rm -f $DIR/$tfile-2
619         kill -USR1 $pid2 || error "second multiop $pid2 not running"
620         wait $pid2 || error "second multiop $pid2 failed"
621
622         fail $SINGLEMDS
623         kill -USR1 $pid1 || error "multiop $pid1 not running"
624         wait $pid1 || error "multiop $pid1 failed"
625         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
626         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
627         return 0
628 }
629 run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"
630
631 test_27() {
632         replay_barrier $SINGLEMDS
633         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
634                 error "multiop_bg_pause $DIR/$tfile-1 failed"
635         pid1=$!
636         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
637                 error "multiop_bg_pause $DIR/$tfile-2 failed"
638         pid2=$!
639         rm -f $DIR/$tfile-1
640         rm -f $DIR/$tfile-2
641
642         fail $SINGLEMDS
643         kill -USR1 $pid1 || error "multiop $pid1 not running"
644         wait $pid1 || error "multiop $pid1 failed"
645         kill -USR1 $pid2 || error "second multiop $pid2 not running"
646         wait $pid2 || error "second multiop $pid2 failed"
647         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
648         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
649         return 0
650 }
651 run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"
652
653 test_28() {
654         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
655                 error "multiop_bg_pause $DIR/$tfile-1 failed"
656         pid1=$!
657         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
658                 error "multiop_bg_pause $DIR/$tfile-2 failed"
659         pid2=$!
660         replay_barrier $SINGLEMDS
661         rm -f $DIR/$tfile-1
662         rm -f $DIR/$tfile-2
663         kill -USR1 $pid2 || error "second multiop $pid2 not running"
664         wait $pid2 || error "second multiop $pid2 failed"
665
666         fail $SINGLEMDS
667         kill -USR1 $pid1 || error "multiop $pid1 not running"
668         wait $pid1 || error "multiop $pid1 failed"
669         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
670         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
671         return 0
672 }
673 run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"
674
675 test_29() {
676         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
677                 error "multiop_bg_pause $DIR/$tfile-1 failed"
678         pid1=$!
679         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
680                 error "multiop_bg_pause $DIR/$tfile-2 failed"
681         pid2=$!
682         replay_barrier $SINGLEMDS
683         rm -f $DIR/$tfile-1
684         rm -f $DIR/$tfile-2
685
686         fail $SINGLEMDS
687         kill -USR1 $pid1 || error "multiop $pid1 not running"
688         wait $pid1 || error "multiop $pid1 failed"
689         kill -USR1 $pid2 || error "second multiop $pid2 not running"
690         wait $pid2 || error "second multiop $pid2 failed"
691         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
692         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
693         return 0
694 }
695 run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"
696
697 test_30() {
698         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
699                 error "multiop_bg_pause $DIR/$tfile-1 failed"
700         pid1=$!
701         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
702                 error "multiop_bg_pause $DIR/$tfile-2 failed"
703         pid2=$!
704         rm -f $DIR/$tfile-1
705         rm -f $DIR/$tfile-2
706
707         replay_barrier $SINGLEMDS
708         fail $SINGLEMDS
709         kill -USR1 $pid1 || error "multiop $pid1 not running"
710         wait $pid1 || error "multiop $pid1 failed"
711         kill -USR1 $pid2 || error "second multiop $pid2 not running"
712         wait $pid2 || error "second multiop $pid2 failed"
713         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
714         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
715         return 0
716 }
717 run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"
718
719 test_31() {
720         multiop_bg_pause $DIR/$tfile-1 O_tSc ||
721                 error "multiop_bg_pause $DIR/$tfile-1 failed"
722         pid1=$!
723         multiop_bg_pause $DIR/$tfile-2 O_tSc ||
724                 error "multiop_bg_pause $DIR/$tfile-2 failed"
725         pid2=$!
726         rm -f $DIR/$tfile-1
727
728         replay_barrier $SINGLEMDS
729         rm -f $DIR/$tfile-2
730         fail $SINGLEMDS
731         kill -USR1 $pid1 || error "multiop $pid1 not running"
732         wait $pid1 || error "multiop $pid1 failed"
733         kill -USR1 $pid2 || error "second multiop $pid2 not running"
734         wait $pid2 || error "second multiop $pid2 failed"
735         [ -e $DIR/$tfile-1 ] && error "file $DIR/$tfile-1 should not exist"
736         [ -e $DIR/$tfile-2 ] && error "file $DIR/$tfile-2 should not exist"
737         return 0
738 }
739 run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"
740
741 # tests for bug 2104; completion without crashing is success.  The close is
742 # stale, but we always return 0 for close, so the app never sees it.
743 test_32() {
744         multiop_bg_pause $DIR/$tfile O_c ||
745                 error "multiop_bg_pause $DIR/$tfile failed"
746         pid1=$!
747         multiop_bg_pause $DIR/$tfile O_c ||
748                 error "second multiop_bg_pause $DIR/$tfile failed"
749         pid2=$!
750         mds_evict_client
751         client_up || client_up || error "client_up failed"
752         kill -USR1 $pid1 || error "multiop $pid1 not running"
753         kill -USR1 $pid2 || error "second multiop $pid2 not running"
754         wait $pid1 || error "multiop $pid1 failed"
755         wait $pid2 || error "second multiop $pid2 failed"
756         return 0
757 }
758 run_test 32 "close() notices client eviction; close() after client eviction"
759
760 test_33a() {
761         createmany -o $DIR/$tfile-%d 10 ||
762                 error "createmany create $DIR/$tfile failed"
763         replay_barrier_nosync $SINGLEMDS
764         fail_abort $SINGLEMDS
765         # recreate shouldn't fail
766         createmany -o $DIR/$tfile--%d 10 ||
767                 error "createmany recreate $DIR/$tfile failed"
768         rm $DIR/$tfile-* -f
769         return 0
770 }
771 run_test 33a "fid seq shouldn't be reused after abort recovery"
772
773 test_33b() {
774         #define OBD_FAIL_SEQ_ALLOC                          0x1311
775         do_facet $SINGLEMDS "lctl set_param fail_loc=0x1311"
776
777         createmany -o $DIR/$tfile-%d 10
778         replay_barrier_nosync $SINGLEMDS
779         fail_abort $SINGLEMDS
780         # recreate shouldn't fail
781         createmany -o $DIR/$tfile--%d 10 ||
782                 error "createmany recreate $DIR/$tfile failed"
783         rm $DIR/$tfile-* -f
784         return 0
785 }
786 run_test 33b "test fid seq allocation"
787
788 test_34() {
789         multiop_bg_pause $DIR/$tfile O_c ||
790                 error "multiop_bg_pause $DIR/$tfile failed"
791         pid=$!
792         rm -f $DIR/$tfile
793
794         replay_barrier $SINGLEMDS
795         fail_abort $SINGLEMDS
796         kill -USR1 $pid || error "multiop $pid not running"
797         wait $pid || error "multiop $pid failed"
798         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
799         sync
800         return 0
801 }
802 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
803
804 # bug 2278 - generate one orphan on OST, then destroy it during recovery from llog
805 test_35() {
806         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
807
808         #define OBD_FAIL_MDS_REINT_NET_REP       0x119
809         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
810         rm -f $DIR/$tfile &
811         sleep 1
812         sync
813         sleep 1
814         # give a chance to remove from MDS
815         fail_abort $SINGLEMDS
816         $CHECKSTAT -t file $DIR/$tfile &&
817                 error "$CHECKSTAT $DIR/$tfile attribute check should fail" ||
818                 true
819 }
820 run_test 35 "test recovery from llog for unlink op"
821
822 # b=2432 resent cancel after replay uses wrong cookie,
823 # so don't resend cancels
824 test_36() {
825         replay_barrier $SINGLEMDS
826         touch $DIR/$tfile
827         checkstat $DIR/$tfile
828         facet_failover $SINGLEMDS
829         cancel_lru_locks mdc
830         if $LCTL dk | grep "stale lock .*cookie"; then
831                 error "cancel after replay failed"
832         fi
833 }
834 run_test 36 "don't resend cancel"
835
836 # b=2368
837 # directory orphans can't be unlinked from PENDING directory
838 test_37() {
839         rmdir $DIR/$tfile 2>/dev/null
840         multiop_bg_pause $DIR/$tfile dD_c ||
841                 error "multiop_bg_pause $DIR/$tfile failed"
842         pid=$!
843         rmdir $DIR/$tfile
844
845         replay_barrier $SINGLEMDS
846         # clear the dmesg buffer so we only see errors from this recovery
847         do_facet $SINGLEMDS dmesg -c >/dev/null
848         fail_abort $SINGLEMDS
849         kill -USR1 $pid || error "multiop $pid not running"
850         do_facet $SINGLEMDS dmesg | grep "error unlinking orphan" &&
851                 error "error unlinking files"
852         wait $pid || error "multiop $pid failed"
853         sync
854         return 0
855 }
856 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
857
858 test_38() {
859         createmany -o $DIR/$tfile-%d 800 ||
860                 error "createmany -o $DIR/$tfile failed"
861         unlinkmany $DIR/$tfile-%d 0 400 || error "unlinkmany $DIR/$tfile failed"
862         replay_barrier $SINGLEMDS
863         fail $SINGLEMDS
864         unlinkmany $DIR/$tfile-%d 400 400 ||
865                 error "unlinkmany $DIR/$tfile 400 failed"
866         sleep 2
867         $CHECKSTAT -t file $DIR/$tfile-* &&
868                 error "$CHECKSTAT $DIR/$tfile-* attribute check should fail" ||
869                 true
870 }
871 run_test 38 "test recovery from unlink llog (test llog_gen_rec) "
872
873 test_39() { # bug 4176
874         createmany -o $DIR/$tfile-%d 800 ||
875                 error "createmany -o $DIR/$tfile failed"
876         replay_barrier $SINGLEMDS
877         unlinkmany $DIR/$tfile-%d 0 400
878         fail $SINGLEMDS
879         unlinkmany $DIR/$tfile-%d 400 400 ||
880                 error "unlinkmany $DIR/$tfile 400 failed"
881         sleep 2
882         $CHECKSTAT -t file $DIR/$tfile-* &&
883                 error "$CHECKSTAT $DIR/$tfile-* attribute check should fail" ||
884                 true
885 }
886 run_test 39 "test recovery from unlink llog (test llog_gen_rec) "
887
888 count_ost_writes() {
889     lctl get_param -n osc.*.stats | awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
890 }
891
892 #b=2477,2532
893 test_40(){
894         # always need connection to MDS to verify layout during IO. LU-2628.
895         lctl get_param mdc.*.connect_flags | grep -q layout_lock &&
896                 skip "layout_lock needs MDS connection for IO" && return 0
897
898         $LCTL mark multiop $MOUNT/$tfile OS_c
899         multiop $MOUNT/$tfile OS_c  &
900         PID=$!
901         writeme -s $MOUNT/${tfile}-2 &
902         WRITE_PID=$!
903         sleep 1
904         facet_failover $SINGLEMDS
905         #define OBD_FAIL_MDS_CONNECT_NET         0x117
906         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000117"
907         kill -USR1 $PID
908         stat1=$(count_ost_writes)
909         sleep $TIMEOUT
910         stat2=$(count_ost_writes)
911         echo "$stat1, $stat2"
912         if [ $stat1 -lt $stat2 ]; then
913                 echo "writes continuing during recovery"
914                 RC=0
915         else
916                 echo "writes not continuing during recovery, bug 2477"
917                 RC=4
918         fi
919         echo "waiting for writeme $WRITE_PID"
920         kill $WRITE_PID
921         wait $WRITE_PID
922
923         echo "waiting for multiop $PID"
924         wait $PID || error "multiop $PID failed"
925         do_facet client munlink $MOUNT/$tfile  ||
926                 error "munlink $MOUNT/$tfile failed"
927         do_facet client munlink $MOUNT/${tfile}-2  ||
928                 error "munlink $MOUNT/$tfile-2 failed"
929         return $RC
930 }
931 run_test 40 "cause recovery in ptlrpc, ensure IO continues"
932
933 #b=2814
934 # make sure that a read to one osc doesn't try to double-unlock its page just
935 # because another osc is invalid.  trigger_group_io used to mistakenly return
936 # an error if any oscs were invalid even after having successfully put rpcs
937 # on valid oscs.  This was fatal if the caller was ll_readpage who unlocked
938 # the page, guarnateeing that the unlock from the RPC completion would
939 # assert on trying to unlock the unlocked page.
940 test_41() {
941         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs" && return
942
943         local f=$MOUNT/$tfile
944         # make sure the start of the file is ost1
945         $LFS setstripe -S $((128 * 1024)) -i 0 $f
946         do_facet client dd if=/dev/zero of=$f bs=4k count=1 ||
947                 error "dd on client failed"
948         cancel_lru_locks osc
949         # fail ost2 and read from ost1
950         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $ost2_svc)
951         local osc2dev=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
952                 grep $mdtosc | awk '{print $1}')
953         [ -z "$osc2dev" ] && echo "OST: $ost2_svc" &&
954                 lctl get_param -n devices &&
955                 error "OST 2 $osc2dev does not exist"
956         do_facet $SINGLEMDS $LCTL --device $osc2dev deactivate ||
957                 error "deactive device on $SINGLEMDS failed"
958         do_facet client dd if=$f of=/dev/null bs=4k count=1 ||
959                 error "second dd on client failed"
960         do_facet $SINGLEMDS $LCTL --device $osc2dev activate ||
961                 error "active device on $SINGLEMDS failed"
962         return 0
963 }
964 run_test 41 "read from a valid osc while other oscs are invalid"
965
966 # test MDS recovery after ost failure
967 test_42() {
968         blocks=$(df -P $MOUNT | tail -n 1 | awk '{ print $2 }')
969         createmany -o $DIR/$tfile-%d 800 ||
970                 error "createmany -o $DIR/$tfile failed"
971         replay_barrier ost1
972         unlinkmany $DIR/$tfile-%d 0 400
973         debugsave
974         lctl set_param debug=-1
975         facet_failover ost1
976
977         # osc is evicted, fs is smaller (but only with failout OSTs (bug 7287)
978         #blocks_after=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
979         #[ $blocks_after -lt $blocks ] || return 1
980         echo "wait for MDS to timeout and recover"
981         sleep $((TIMEOUT * 2))
982         debugrestore
983         unlinkmany $DIR/$tfile-%d 400 400 ||
984                 error "unlinkmany $DIR/$tfile 400 failed"
985         $CHECKSTAT -t file $DIR/$tfile-* &&
986                 error "$CHECKSTAT $DIR/$tfile-* attribute check should fail" ||
987                 true
988 }
989 run_test 42 "recovery after ost failure"
990
991 # timeout in MDS/OST recovery RPC will LBUG MDS
992 test_43() { # bug 2530
993         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
994
995         replay_barrier $SINGLEMDS
996
997         # OBD_FAIL_OST_CREATE_NET 0x204
998         do_facet ost1 "lctl set_param fail_loc=0x80000204"
999         fail $SINGLEMDS
1000         sleep 10
1001
1002         return 0
1003 }
1004 run_test 43 "mds osc import failure during recovery; don't LBUG"
1005
1006 test_44a() { # was test_44
1007         local at_max_saved=0
1008
1009         local mdcdev=$($LCTL dl |
1010                 awk "/${FSNAME}-MDT0000-mdc-/ {if (\$2 == \"UP\") {print \$1}}")
1011         [ "$mdcdev" ] || error "${FSNAME}-MDT0000-mdc- not UP"
1012         [ $(echo $mdcdev | wc -w) -eq 1 ] ||
1013                 { $LCTL dl; error "looking for mdcdev=$mdcdev"; }
1014
1015         # adaptive timeouts slow this way down
1016         if at_is_enabled; then
1017                 at_max_saved=$(at_max_get mds)
1018                 at_max_set 40 mds
1019         fi
1020
1021         for i in $(seq 1 10); do
1022                 echo "$i of 10 ($(date +%s))"
1023                 do_facet $SINGLEMDS \
1024                         "lctl get_param -n md[ts].*.mdt.timeouts | grep service"
1025                 #define OBD_FAIL_TGT_CONN_RACE     0x701
1026                 do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000701"
1027                 # lctl below may fail, it is valid case
1028                 $LCTL --device $mdcdev recover
1029                 $LFS df $MOUNT
1030         done
1031         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1032         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds
1033         return 0
1034 }
1035 run_test 44a "race in target handle connect"
1036
1037 test_44b() {
1038         local mdcdev=$($LCTL dl |
1039                 awk "/${FSNAME}-MDT0000-mdc-/ {if (\$2 == \"UP\") {print \$1}}")
1040         [ "$mdcdev" ] || error "${FSNAME}-MDT0000-mdc not up"
1041         [ $(echo $mdcdev | wc -w) -eq 1 ] ||
1042                 { echo mdcdev=$mdcdev; $LCTL dl;
1043                   error "more than one ${FSNAME}-MDT0000-mdc"; }
1044
1045         for i in $(seq 1 10); do
1046                 echo "$i of 10 ($(date +%s))"
1047                 do_facet $SINGLEMDS \
1048                         "lctl get_param -n md[ts].*.mdt.timeouts | grep service"
1049                 #define OBD_FAIL_TGT_DELAY_RECONNECT 0x704
1050                 do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000704"
1051                 # lctl below may fail, it is valid case
1052                 $LCTL --device $mdcdev recover
1053                 df $MOUNT
1054         done
1055         return 0
1056 }
1057 run_test 44b "race in target handle connect"
1058
1059 test_44c() {
1060         replay_barrier $SINGLEMDS
1061         createmany -m $DIR/$tfile-%d 100 || error "failed to create directories"
1062         #define OBD_FAIL_TGT_RCVG_FLAG 0x712
1063         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000712"
1064         fail_abort $SINGLEMDS
1065         unlinkmany $DIR/$tfile-%d 100 && error "unliked after fail abort"
1066         fail $SINGLEMDS
1067         unlinkmany $DIR/$tfile-%d 100 && error "unliked after fail"
1068         return 0
1069 }
1070 run_test 44c "race in target handle connect"
1071
1072 # Handle failed close
1073 test_45() {
1074         local mdcdev=$($LCTL get_param -n devices |
1075                 awk "/ ${FSNAME}-MDT0000-mdc-/ {print \$1}")
1076         [ "$mdcdev" ] || error "${FSNAME}-MDT0000-mdc not up"
1077         [ $(echo $mdcdev | wc -w) -eq 1 ] ||
1078                 { echo mdcdev=$mdcdev; $LCTL dl;
1079                   error "more than one ${FSNAME}-MDT0000-mdc"; }
1080
1081         $LCTL --device $mdcdev recover ||
1082                 error "$LCTL --device $mdcdev recover failed"
1083
1084         multiop_bg_pause $DIR/$tfile O_c ||
1085                 error "multiop_bg_pause $DIR/$tfile failed"
1086         pid=$!
1087
1088         # This will cause the CLOSE to fail before even
1089         # allocating a reply buffer
1090         $LCTL --device $mdcdev deactivate ||
1091                 error "$LCTL --device $mdcdev deactivate failed"
1092
1093         # try the close
1094         kill -USR1 $pid || error "multiop $pid not running"
1095         wait $pid || error "multiop $pid failed"
1096
1097         $LCTL --device $mdcdev activate ||
1098                 error "$LCTL --device $mdcdev activate failed"
1099         sleep 1
1100
1101         $CHECKSTAT -t file $DIR/$tfile ||
1102                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
1103         return 0
1104 }
1105 run_test 45 "Handle failed close"
1106
1107 test_46() {
1108         drop_reply "touch $DIR/$tfile"
1109         fail $SINGLEMDS
1110         # ironically, the previous test, 45, will cause a real forced close,
1111         # so just look for one for this test
1112         local FID=$($LFS path2fid $tfile)
1113         $LCTL dk | grep -i "force closing file handle $FID" &&
1114                 error "found force closing in dmesg"
1115         return 0
1116 }
1117 run_test 46 "Don't leak file handle after open resend (3325)"
1118
1119 test_47() { # bug 2824
1120         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1121
1122         # create some files to make sure precreate has been done on all
1123         # OSTs. (just in case this test is run independently)
1124         createmany -o $DIR/$tfile 20  ||
1125                 error "createmany create $DIR/$tfile failed"
1126
1127         # OBD_FAIL_OST_CREATE_NET 0x204
1128         fail ost1
1129         do_facet ost1 "lctl set_param fail_loc=0x80000204"
1130         client_up || error "client_up failed"
1131
1132         # let the MDS discover the OST failure, attempt to recover, fail
1133         # and recover again.
1134         sleep $((3 * TIMEOUT))
1135
1136         # Without 2824, this createmany would hang
1137         createmany -o $DIR/$tfile 20 ||
1138                 error "createmany recraete $DIR/$tfile failed"
1139         unlinkmany $DIR/$tfile 20 || error "unlinkmany $DIR/$tfile failed"
1140
1141         return 0
1142 }
1143 run_test 47 "MDS->OSC failure during precreate cleanup (2824)"
1144
1145 test_48() {
1146         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1147         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1148
1149         replay_barrier $SINGLEMDS
1150         createmany -o $DIR/$tfile 20  ||
1151                 error "createmany -o $DIR/$tfile failed"
1152         # OBD_FAIL_OST_EROFS 0x216
1153         facet_failover $SINGLEMDS
1154         do_facet ost1 "lctl set_param fail_loc=0x80000216"
1155         client_up || error "client_up failed"
1156
1157         # let the MDS discover the OST failure, attempt to recover, fail
1158         # and recover again.
1159         sleep $((3 * TIMEOUT))
1160
1161         createmany -o $DIR/$tfile 20 20 ||
1162                 error "createmany recraete $DIR/$tfile failed"
1163         unlinkmany $DIR/$tfile 40 || error "unlinkmany $DIR/$tfile failed"
1164         return 0
1165 }
1166 run_test 48 "MDS->OSC failure during precreate cleanup (2824)"
1167
1168 test_50() {
1169         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $ost1_svc)
1170         local oscdev=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
1171                 grep $mdtosc | awk '{print $1}')
1172         [ "$oscdev" ] || error "could not find OSC device on MDS"
1173         do_facet $SINGLEMDS $LCTL --device $oscdev recover ||
1174                 error "OSC device $oscdev recovery failed"
1175         do_facet $SINGLEMDS $LCTL --device $oscdev recover ||
1176                 error "second OSC device $oscdev recovery failed"
1177         # give the mds_lov_sync threads a chance to run
1178         sleep 5
1179 }
1180 run_test 50 "Double OSC recovery, don't LASSERT (3812)"
1181
1182 # b3764 timed out lock replay
1183 test_52() {
1184         [ "$MDS1_VERSION" -lt $(version_code 2.6.90) ] &&
1185                 skip "MDS prior to 2.6.90 handle LDLM_REPLY_NET incorrectly"
1186
1187         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
1188         cancel_lru_locks mdc
1189
1190         multiop_bg_pause $DIR/$tfile s_s || error "multiop $DIR/$tfile failed"
1191         mpid=$!
1192
1193         #define OBD_FAIL_MDS_LDLM_REPLY_NET     0x157
1194         lctl set_param -n ldlm.cancel_unused_locks_before_replay "0"
1195         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000157"
1196
1197         fail $SINGLEMDS || error "fail $SINGLEMDS failed"
1198         kill -USR1 $mpid
1199         wait $mpid || error "multiop_bg_pause pid failed"
1200
1201         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1202         lctl set_param fail_loc=0x0
1203         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
1204         rm -f $DIR/$tfile
1205 }
1206 run_test 52 "time out lock replay (3764)"
1207
1208 # bug 3462 - simultaneous MDC requests
1209 test_53a() {
1210         [[ $(lctl get_param mdc.*.import |
1211              grep "connect_flags:.*multi_mod_rpc") ]] ||
1212                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
1213
1214         cancel_lru_locks mdc    # cleanup locks from former test cases
1215         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1216         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1217         multiop $DIR/${tdir}-1/f O_c &
1218         close_pid=$!
1219         # give multiop a change to open
1220         sleep 1
1221
1222         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1223         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1224         kill -USR1 $close_pid
1225         cancel_lru_locks mdc    # force the close
1226         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1227
1228         mcreate $DIR/${tdir}-2/f || error "mcreate $DIR/${tdir}-2/f failed"
1229
1230         # close should still be here
1231         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1232
1233         replay_barrier_nodf $SINGLEMDS
1234         fail $SINGLEMDS
1235         wait $close_pid || error "close_pid $close_pid failed"
1236
1237         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1238                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1239         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1240                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1241         rm -rf $DIR/${tdir}-*
1242 }
1243 run_test 53a "|X| close request while two MDC requests in flight"
1244
1245 test_53b() {
1246         cancel_lru_locks mdc    # cleanup locks from former test cases
1247
1248         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1249         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1250         multiop_bg_pause $DIR/${tdir}-1/f O_c ||
1251                 error "multiop_bg_pause $DIR/${tdir}-1/f failed"
1252         close_pid=$!
1253
1254         #define OBD_FAIL_MDS_REINT_NET 0x107
1255         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1256         mcreate $DIR/${tdir}-2/f &
1257         open_pid=$!
1258         sleep 1
1259
1260         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1261         kill -USR1 $close_pid
1262         cancel_lru_locks mdc    # force the close
1263         wait $close_pid || error "close_pid $close_pid failed"
1264         # open should still be here
1265         [ -d /proc/$open_pid ] || error "open_pid doesn't exist"
1266
1267         replay_barrier_nodf $SINGLEMDS
1268         fail $SINGLEMDS
1269         wait $open_pid || error "open_pid failed"
1270
1271         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1272                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1273         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1274                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1275         rm -rf $DIR/${tdir}-*
1276 }
1277 run_test 53b "|X| open request while two MDC requests in flight"
1278
1279 test_53c() {
1280         cancel_lru_locks mdc    # cleanup locks from former test cases
1281
1282         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1283         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1284         multiop $DIR/${tdir}-1/f O_c &
1285         close_pid=$!
1286
1287         #define OBD_FAIL_MDS_REINT_NET 0x107
1288         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1289         mcreate $DIR/${tdir}-2/f &
1290         open_pid=$!
1291         sleep 1
1292
1293         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1294         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1295         kill -USR1 $close_pid
1296         cancel_lru_locks mdc    # force the close
1297
1298         #bz20647: make sure all pids exist before failover
1299         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1300         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1301         replay_barrier_nodf $SINGLEMDS
1302         fail_nodf $SINGLEMDS
1303         wait $open_pid || error "open_pid failed"
1304         sleep 2
1305         # close should be gone
1306         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1307         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1308
1309         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1310                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1311         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1312                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1313         rm -rf $DIR/${tdir}-*
1314 }
1315 run_test 53c "|X| open request and close request while two MDC requests in flight"
1316
1317 test_53d() {
1318         [[ $(lctl get_param mdc.*.import |
1319              grep "connect_flags:.*multi_mod_rpc") ]] ||
1320                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
1321
1322         cancel_lru_locks mdc    # cleanup locks from former test cases
1323
1324         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1325         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1326         multiop $DIR/${tdir}-1/f O_c &
1327         close_pid=$!
1328         # give multiop a chance to open
1329         sleep 1
1330
1331         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1332         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1333         kill -USR1 $close_pid
1334         cancel_lru_locks mdc    # force the close
1335         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1336         mcreate $DIR/${tdir}-2/f || error "mcreate $DIR/${tdir}-2/f failed"
1337
1338         # close should still be here
1339         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1340         fail $SINGLEMDS
1341         wait $close_pid || error "close_pid failed"
1342
1343         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1344                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1345         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1346                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1347         rm -rf $DIR/${tdir}-*
1348 }
1349 run_test 53d "close reply while two MDC requests in flight"
1350
1351 test_53e() {
1352         cancel_lru_locks mdc    # cleanup locks from former test cases
1353
1354         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1355         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1356         multiop $DIR/${tdir}-1/f O_c &
1357         close_pid=$!
1358
1359         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1360         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1361         mcreate $DIR/${tdir}-2/f &
1362         open_pid=$!
1363         sleep 1
1364
1365         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1366         kill -USR1 $close_pid
1367         cancel_lru_locks mdc    # force the close
1368         wait $close_pid || error "close_pid failed"
1369         # open should still be here
1370         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1371
1372         replay_barrier_nodf $SINGLEMDS
1373         fail $SINGLEMDS
1374         wait $open_pid || error "open_pid failed"
1375
1376         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1377                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1378         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1379                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1380         rm -rf $DIR/${tdir}-*
1381 }
1382 run_test 53e "|X| open reply while two MDC requests in flight"
1383
1384 test_53f() {
1385         cancel_lru_locks mdc    # cleanup locks from former test cases
1386
1387         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1388         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1389         multiop $DIR/${tdir}-1/f O_c &
1390         close_pid=$!
1391
1392         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1393         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1394         mcreate $DIR/${tdir}-2/f &
1395         open_pid=$!
1396         sleep 1
1397
1398         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1399         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1400         kill -USR1 $close_pid
1401         cancel_lru_locks mdc    # force the close
1402
1403         #bz20647: make sure all pids are exists before failover
1404         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1405         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1406         replay_barrier_nodf $SINGLEMDS
1407         fail_nodf $SINGLEMDS
1408         wait $open_pid || error "open_pid failed"
1409         sleep 2
1410         # close should be gone
1411         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1412         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1413
1414         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1415                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1416         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1417                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1418         rm -rf $DIR/${tdir}-*
1419 }
1420 run_test 53f "|X| open reply and close reply while two MDC requests in flight"
1421
1422 test_53g() {
1423         cancel_lru_locks mdc    # cleanup locks from former test cases
1424
1425         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1426         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1427         multiop $DIR/${tdir}-1/f O_c &
1428         close_pid=$!
1429
1430         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1431         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1432         mcreate $DIR/${tdir}-2/f &
1433         open_pid=$!
1434         sleep 1
1435
1436         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1437         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1438         kill -USR1 $close_pid
1439         cancel_lru_locks mdc    # force the close
1440         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1441
1442         #bz20647: make sure all pids are exists before failover
1443         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1444         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1445         replay_barrier_nodf $SINGLEMDS
1446         fail_nodf $SINGLEMDS
1447         wait $open_pid || error "open_pid failed"
1448         sleep 2
1449         # close should be gone
1450         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1451
1452         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1453                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1454         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1455                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1456         rm -rf $DIR/${tdir}-*
1457 }
1458 run_test 53g "|X| drop open reply and close request while close and open are both in flight"
1459
1460 test_53h() {
1461         cancel_lru_locks mdc    # cleanup locks from former test cases
1462
1463         mkdir $DIR/${tdir}-1 || error "mkdir $DIR/${tdir}-1 failed"
1464         mkdir $DIR/${tdir}-2 || error "mkdir $DIR/${tdir}-2 failed"
1465         multiop $DIR/${tdir}-1/f O_c &
1466         close_pid=$!
1467
1468         #define OBD_FAIL_MDS_REINT_NET 0x107
1469         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1470         mcreate $DIR/${tdir}-2/f &
1471         open_pid=$!
1472         sleep 1
1473
1474         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13b
1475         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013b"
1476         kill -USR1 $close_pid
1477         cancel_lru_locks mdc    # force the close
1478         sleep 1
1479
1480         #bz20647: make sure all pids are exists before failover
1481         [ -d /proc/$close_pid ] || error "close_pid doesn't exist"
1482         [ -d /proc/$open_pid ] || error "open_pid doesn't exists"
1483         replay_barrier_nodf $SINGLEMDS
1484         fail_nodf $SINGLEMDS
1485         wait $open_pid || error "open_pid failed"
1486         sleep 2
1487         # close should be gone
1488         [ -d /proc/$close_pid ] && error "close_pid should not exist"
1489         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1490
1491         $CHECKSTAT -t file $DIR/${tdir}-1/f ||
1492                 error "$CHECKSTAT $DIR/${tdir}-1/f attribute check failed"
1493         $CHECKSTAT -t file $DIR/${tdir}-2/f ||
1494                 error "$CHECKSTAT $DIR/${tdir}-2/f attribute check failed"
1495         rm -rf $DIR/${tdir}-*
1496 }
1497 run_test 53h "open request and close reply while two MDC requests in flight"
1498
1499 #b3761 ASSERTION(hash != 0) failed
1500 test_55() {
1501 # OBD_FAIL_MDS_OPEN_CREATE | OBD_FAIL_ONCE
1502     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012b"
1503     touch $DIR/$tfile &
1504     # give touch a chance to run
1505     sleep 5
1506     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1507     rm $DIR/$tfile
1508     return 0
1509 }
1510 run_test 55 "let MDS_CHECK_RESENT return the original return code instead of 0"
1511
1512 #b3440 ASSERTION(rec->ur_fid2->id) failed
1513 test_56() {
1514     ln -s foo $DIR/$tfile
1515     replay_barrier $SINGLEMDS
1516     #drop_reply "cat $DIR/$tfile"
1517     fail $SINGLEMDS
1518     sleep 10
1519 }
1520 run_test 56 "don't replay a symlink open request (3440)"
1521
1522 #recovery one mds-ost setattr from llog
1523 test_57() {
1524         #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1525         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1526         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
1527         replay_barrier $SINGLEMDS
1528         fail $SINGLEMDS
1529         wait_recovery_complete $SINGLEMDS || error "MDS recovery is not done"
1530         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
1531         $CHECKSTAT -t file $DIR/$tfile ||
1532                 error "$CHECKSTAT $DIR/$tfile attribute check failed"
1533         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1534         rm $DIR/$tfile
1535 }
1536 run_test 57 "test recovery from llog for setattr op"
1537
1538 cleanup_58() {
1539         zconf_umount $(hostname) $MOUNT2
1540         trap - EXIT
1541 }
1542
1543 #recovery many mds-ost setattr from llog
1544 test_58a() {
1545         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1546         #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1547         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1548         createmany -o $DIR/$tdir/$tfile-%d 2500
1549         replay_barrier $SINGLEMDS
1550         fail $SINGLEMDS
1551         sleep 2
1552         $CHECKSTAT -t file $DIR/$tdir/$tfile-* >/dev/null ||
1553                 error "$CHECKSTAT $DIR/$tfile-* attribute check failed"
1554         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1555         unlinkmany $DIR/$tdir/$tfile-%d 2500 ||
1556                 error "unlinkmany $DIR/$tfile failed"
1557         rmdir $DIR/$tdir
1558 }
1559 run_test 58a "test recovery from llog for setattr op (test llog_gen_rec)"
1560
1561 test_58b() {
1562         local orig
1563         local new
1564
1565         trap cleanup_58 EXIT
1566
1567         large_xattr_enabled &&
1568                 orig="$(generate_string $(max_xattr_size))" || orig="bar"
1569         # Original extended attribute can be long. Print a small version of
1570         # attribute if an error occurs
1571         local sm_msg=$(printf "%.9s" $orig)
1572
1573         mount_client $MOUNT2 || error "mount_client on $MOUNT2 failed"
1574         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1575         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
1576         replay_barrier $SINGLEMDS
1577         setfattr -n trusted.foo -v $orig $DIR/$tdir/$tfile
1578         fail $SINGLEMDS
1579         new=$(get_xattr_value trusted.foo $MOUNT2/$tdir/$tfile)
1580         [[ "$new" = "$orig" ]] ||
1581                 error "xattr set ($sm_msg...) differs from xattr get ($new)"
1582         rm -f $DIR/$tdir/$tfile
1583         rmdir $DIR/$tdir
1584         cleanup_58
1585         wait_clients_import_state ${CLIENTS:-$HOSTNAME} "mgs" FULL
1586 }
1587 run_test 58b "test replay of setxattr op"
1588
1589 test_58c() { # bug 16570
1590         local orig
1591         local orig1
1592         local new
1593
1594         trap cleanup_58 EXIT
1595
1596         if large_xattr_enabled; then
1597                 local xattr_size=$(max_xattr_size)
1598                 orig="$(generate_string $((xattr_size / 2)))"
1599                 orig1="$(generate_string $xattr_size)"
1600         else
1601                 orig="bar"
1602                 orig1="bar1"
1603         fi
1604
1605         # PING_INTERVAL max(obd_timeout / 4, 1U)
1606         sleep $((TIMEOUT / 4))
1607
1608         # Original extended attribute can be long. Print a small version of
1609         # attribute if an error occurs
1610         local sm_msg=$(printf "%.9s" $orig)
1611         local sm_msg1=$(printf "%.9s" $orig1)
1612
1613         mount_client $MOUNT2 || error "mount_client on $MOUNT2 failed"
1614         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1615         touch $DIR/$tdir/$tfile || error "touch $DIR/$tdir/$tfile failed"
1616         drop_request "setfattr -n trusted.foo -v $orig $DIR/$tdir/$tfile" ||
1617                 error "drop_request for setfattr failed"
1618         new=$(get_xattr_value trusted.foo $MOUNT2/$tdir/$tfile)
1619         [[ "$new" = "$orig" ]] ||
1620                 error "xattr set ($sm_msg...) differs from xattr get ($new)"
1621         drop_reint_reply "setfattr -n trusted.foo1 \
1622                           -v $orig1 $DIR/$tdir/$tfile" ||
1623                 error "drop_reint_reply for setfattr failed"
1624         new=$(get_xattr_value trusted.foo1 $MOUNT2/$tdir/$tfile)
1625         [[ "$new" = "$orig1" ]] ||
1626                 error "second xattr set ($sm_msg1...) differs xattr get ($new)"
1627         rm -f $DIR/$tdir/$tfile
1628         rmdir $DIR/$tdir
1629         cleanup_58
1630 }
1631 run_test 58c "resend/reconstruct setxattr op"
1632
1633 # log_commit_thread vs filter_destroy race used to lead to import use after free
1634 # bug 11658
1635 test_59() {
1636         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1637
1638         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1639         createmany -o $DIR/$tdir/$tfile-%d 200 ||
1640                 error "createmany create files failed"
1641         sync
1642         unlinkmany $DIR/$tdir/$tfile-%d 200 ||
1643                 error "unlinkmany $DIR/$tdir/$tfile failed"
1644         #define OBD_FAIL_PTLRPC_DELAY_RECOV       0x507
1645         do_facet ost1 "lctl set_param fail_loc=0x507"
1646         fail ost1
1647         fail $SINGLEMDS
1648         do_facet ost1 "lctl set_param fail_loc=0x0"
1649         sleep 20
1650         rmdir $DIR/$tdir
1651 }
1652 run_test 59 "test log_commit_thread vs filter_destroy race"
1653
1654 # race between add unlink llog vs cat log init in post_recovery (only for b1_6)
1655 # bug 12086: should no oops and No ctxt error for this test
1656 test_60() {
1657         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1658         createmany -o $DIR/$tdir/$tfile-%d 200 ||
1659                 error "createmany create files failed"
1660         replay_barrier $SINGLEMDS
1661         unlinkmany $DIR/$tdir/$tfile-%d 0 100
1662         fail $SINGLEMDS
1663         unlinkmany $DIR/$tdir/$tfile-%d 100 100
1664         local no_ctxt=$(dmesg | grep "No ctxt")
1665         [ -z "$no_ctxt" ] || error "ctxt is not initialized in recovery"
1666 }
1667 run_test 60 "test llog post recovery init vs llog unlink"
1668
1669 #test race  llog recovery thread vs llog cleanup
1670 test_61a() {    # was test_61
1671         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1672
1673         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1674         createmany -o $DIR/$tdir/$tfile-%d 800 ||
1675                 error "createmany create files failed"
1676         replay_barrier ost1
1677         unlinkmany $DIR/$tdir/$tfile-%d 800
1678         #   OBD_FAIL_OST_LLOG_RECOVERY_TIMEOUT 0x221
1679         set_nodes_failloc "$(osts_nodes)" 0x80000221
1680         facet_failover ost1
1681         sleep 10
1682         fail ost1
1683         sleep 30
1684         set_nodes_failloc "$(osts_nodes)" 0x0
1685
1686         $CHECKSTAT -t file $DIR/$tdir/$tfile-* &&
1687                 error "$CHECKSTAT $DIR/$tdir/$tfile attribute check should fail"
1688         rmdir $DIR/$tdir
1689 }
1690 run_test 61a "test race llog recovery vs llog cleanup"
1691
1692 #test race  mds llog sync vs llog cleanup
1693 test_61b() {
1694         #   OBD_FAIL_MDS_LLOG_SYNC_TIMEOUT 0x13a
1695         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013a"
1696         facet_failover $SINGLEMDS
1697         sleep 10
1698         fail $SINGLEMDS
1699         do_facet client dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 ||
1700                 error "dd failed"
1701 }
1702 run_test 61b "test race mds llog sync vs llog cleanup"
1703
1704 #test race  cancel cookie cb vs llog cleanup
1705 test_61c() {
1706         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1707
1708         #   OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT 0x222
1709         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
1710         set_nodes_failloc "$(osts_nodes)" 0x80000222
1711         rm $DIR/$tfile
1712         sleep 10
1713         fail ost1
1714         set_nodes_failloc "$(osts_nodes)" 0x0
1715 }
1716 run_test 61c "test race mds llog sync vs llog cleanup"
1717
1718 test_61d() { # bug 16002 # bug 17466 # bug 22137
1719 #   OBD_FAIL_OBD_LLOG_SETUP        0x605
1720     stop mgs
1721     do_facet mgs "lctl set_param fail_loc=0x80000605"
1722     start mgs $(mgsdevname) $MGS_MOUNT_OPTS &&
1723         error "mgs start should have failed"
1724     do_facet mgs "lctl set_param fail_loc=0"
1725     start mgs $(mgsdevname) $MGS_MOUNT_OPTS || error "cannot restart mgs"
1726 }
1727 run_test 61d "error in llog_setup should cleanup the llog context correctly"
1728
1729 test_62() { # Bug 15756 - don't mis-drop resent replay
1730         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
1731         replay_barrier $SINGLEMDS
1732         createmany -o $DIR/$tdir/$tfile- 25 ||
1733                 error "createmany create files failed"
1734         #define OBD_FAIL_TGT_REPLAY_DROP         0x707
1735         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000707"
1736         fail $SINGLEMDS
1737         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1738         unlinkmany $DIR/$tdir/$tfile- 25 ||
1739                 error "unlinkmany $DIR/$tdir/$tfile failed"
1740         return 0
1741 }
1742 run_test 62 "don't mis-drop resent replay"
1743
1744 #Adaptive Timeouts (bug 3055)
1745 AT_MAX_SET=0
1746
1747 at_cleanup () {
1748     local var
1749     local facet
1750     local at_new
1751
1752     echo "Cleaning up AT ..."
1753     if [ -n "$ATOLDBASE" ]; then
1754         local at_history=$($LCTL get_param -n at_history)
1755         do_facet $SINGLEMDS "lctl set_param at_history=$at_history" || true
1756         do_facet ost1 "lctl set_param at_history=$at_history" || true
1757     fi
1758
1759         if [ $AT_MAX_SET -ne 0 ]; then
1760                 for facet in mds client ost; do
1761                         var=AT_MAX_SAVE_${facet}
1762                         echo restore AT on $facet to saved value ${!var}
1763                         at_max_set ${!var} $facet
1764                         at_new=$(at_max_get $facet)
1765                         echo Restored AT value on $facet $at_new
1766                         [ $at_new -eq ${!var} ] ||
1767                         error "AT value not restored SAVED ${!var} NEW $at_new"
1768                 done
1769         fi
1770 }
1771
1772 at_start()
1773 {
1774     local at_max_new=600
1775
1776     # Save at_max original values
1777     local facet
1778     if [ $AT_MAX_SET -eq 0 ]; then
1779         # Suppose that all osts have the same at_max
1780         for facet in mds client ost; do
1781             eval AT_MAX_SAVE_${facet}=$(at_max_get $facet)
1782         done
1783     fi
1784     local at_max
1785     for facet in mds client ost; do
1786         at_max=$(at_max_get $facet)
1787         if [ $at_max -ne $at_max_new ]; then
1788             echo "AT value on $facet is $at_max, set it by force temporarily to $at_max_new"
1789             at_max_set $at_max_new $facet
1790             AT_MAX_SET=1
1791         fi
1792     done
1793
1794     if [ -z "$ATOLDBASE" ]; then
1795         ATOLDBASE=$(do_facet $SINGLEMDS "lctl get_param -n at_history")
1796         # speed up the timebase so we can check decreasing AT
1797         do_facet $SINGLEMDS "lctl set_param at_history=8" || true
1798         do_facet ost1 "lctl set_param at_history=8" || true
1799
1800         # sleep for a while to cool down, should be > 8s and also allow
1801         # at least one ping to be sent. simply use TIMEOUT to be safe.
1802         sleep $TIMEOUT
1803     fi
1804 }
1805
1806 test_65a() #bug 3055
1807 {
1808     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1809
1810     at_start || return 0
1811     $LCTL dk > /dev/null
1812     debugsave
1813     $LCTL set_param debug="other"
1814     # Slow down a request to the current service time, this is critical
1815     # because previous tests may have caused this value to increase.
1816     REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
1817                awk '/portal 12/ {print $5}'`
1818     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1819
1820     do_facet $SINGLEMDS lctl set_param fail_val=$((${REQ_DELAY} * 1000))
1821 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1822     do_facet $SINGLEMDS $LCTL set_param fail_loc=0x8000050a
1823     createmany -o $DIR/$tfile 10 > /dev/null
1824     unlinkmany $DIR/$tfile 10 > /dev/null
1825     # check for log message
1826     $LCTL dk | grep -i "Early reply #" || error "No early reply"
1827     debugrestore
1828     # client should show REQ_DELAY estimates
1829     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1830     sleep 9
1831     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1832 }
1833 run_test 65a "AT: verify early replies"
1834
1835 test_65b() #bug 3055
1836 {
1837         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1838
1839         at_start || return 0
1840         # turn on D_ADAPTTO
1841         debugsave
1842         $LCTL set_param debug="other trace"
1843         $LCTL dk > /dev/null
1844         # Slow down a request to the current service time, this is critical
1845         # because previous tests may have caused this value to increase.
1846         $LFS setstripe --stripe-index=0 --stripe-count=1 $DIR/$tfile ||
1847                 error "$LFS setstripe failed for $DIR/$tfile"
1848
1849         multiop $DIR/$tfile Ow1yc
1850         REQ_DELAY=`lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts |
1851                    awk '/portal 6/ {print $5}'`
1852         REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1853
1854         do_facet ost1 lctl set_param fail_val=${REQ_DELAY}
1855         #define OBD_FAIL_OST_BRW_PAUSE_PACK      0x224
1856         do_facet ost1 $LCTL set_param fail_loc=0x224
1857
1858         rm -f $DIR/$tfile
1859         $LFS setstripe --stripe-index=0 --stripe-count=1 $DIR/$tfile ||
1860                 error "$LFS setstripe failed"
1861         # force some real bulk transfer
1862         multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
1863
1864         do_facet ost1 $LCTL set_param fail_loc=0
1865         # check for log message
1866         $LCTL dk | grep -i "Early reply #" || error "No early reply"
1867         debugrestore
1868         # client should show REQ_DELAY estimates
1869         lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts | grep portal
1870 }
1871 run_test 65b "AT: verify early replies on packed reply / bulk"
1872
1873 test_66a() #bug 3055
1874 {
1875     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1876
1877     at_start || return 0
1878     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1879     # adjust 5s at a time so no early reply is sent (within deadline)
1880     do_facet $SINGLEMDS "$LCTL set_param fail_val=5000"
1881 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1882     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x8000050a"
1883     createmany -o $DIR/$tfile 20 > /dev/null
1884     unlinkmany $DIR/$tfile 20 > /dev/null
1885     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1886     do_facet $SINGLEMDS "$LCTL set_param fail_val=10000"
1887     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x8000050a"
1888     createmany -o $DIR/$tfile 20 > /dev/null
1889     unlinkmany $DIR/$tfile 20 > /dev/null
1890     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1891     do_facet $SINGLEMDS "$LCTL set_param fail_loc=0"
1892     sleep 9
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     CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $5}')
1897     WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $7}')
1898     echo "Current MDT timeout $CUR, worst $WORST"
1899     [ $CUR -lt $WORST ] || error "Current $CUR should be less than worst $WORST"
1900 }
1901 run_test 66a "AT: verify MDT service time adjusts with no early replies"
1902
1903 test_66b() #bug 3055
1904 {
1905         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1906
1907         at_start || return 0
1908         ORIG=$(lctl get_param -n mdc.${FSNAME}-MDT0000*.timeouts |
1909                 awk '/network/ {print $4}')
1910         $LCTL set_param fail_val=$(($ORIG + 5))
1911         #define OBD_FAIL_PTLRPC_PAUSE_REP      0x50c
1912         $LCTL set_param fail_loc=0x50c
1913         touch $DIR/$tfile > /dev/null 2>&1
1914         $LCTL set_param fail_loc=0
1915         CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000*.timeouts |
1916                 awk '/network/ {print $4}')
1917         WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000*.timeouts |
1918                 awk '/network/ {print $6}')
1919         echo "network timeout orig $ORIG, cur $CUR, worst $WORST"
1920         [ $WORST -gt $ORIG ] ||
1921                 error "Worst $WORST should be worse than orig $ORIG"
1922 }
1923 run_test 66b "AT: verify net latency adjusts"
1924
1925 test_67a() #bug 3055
1926 {
1927     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1928
1929     at_start || return 0
1930     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1931     # sleeping threads may drive values above this
1932     do_facet ost1 "$LCTL set_param fail_val=400"
1933 #define OBD_FAIL_PTLRPC_PAUSE_REQ    0x50a
1934     do_facet ost1 "$LCTL set_param fail_loc=0x50a"
1935     createmany -o $DIR/$tfile 20 > /dev/null
1936     unlinkmany $DIR/$tfile 20 > /dev/null
1937     do_facet ost1 "$LCTL set_param fail_loc=0"
1938     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1939     ATTEMPTS=$(($CONN2 - $CONN1))
1940     echo "$ATTEMPTS osc reconnect attempts on gradual slow"
1941         [ $ATTEMPTS -gt 0 ] &&
1942                 error_ignore bz13721 "AT should have prevented reconnect"
1943         return 0
1944 }
1945 run_test 67a "AT: verify slow request processing doesn't induce reconnects"
1946
1947 test_67b() #bug 3055
1948 {
1949     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1950
1951     at_start || return 0
1952     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1953
1954         # exhaust precreations on ost1
1955         local OST=$(ostname_from_index 0)
1956         local mdtosc=$(get_mdtosc_proc_path mds $OST)
1957         local last_id=$(do_facet $SINGLEMDS lctl get_param -n \
1958                         osp.$mdtosc.prealloc_last_id)
1959         local next_id=$(do_facet $SINGLEMDS lctl get_param -n \
1960                         osp.$mdtosc.prealloc_next_id)
1961
1962         mkdir -p $DIR/$tdir/${OST} || error "mkdir $DIR/$tdir/${OST} failed"
1963         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${OST} ||
1964                 error "$LFS setstripe failed"
1965         echo "Creating to objid $last_id on ost $OST..."
1966 #define OBD_FAIL_OST_PAUSE_CREATE        0x223
1967     do_facet ost1 "$LCTL set_param fail_val=20000"
1968     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1969     createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1970
1971     client_reconnect
1972     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1973     log "phase 2"
1974     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1975     ATTEMPTS=$(($CONN2 - $CONN1))
1976     echo "$ATTEMPTS osc reconnect attempts on instant slow"
1977     # do it again; should not timeout
1978     do_facet ost1 "$LCTL set_param fail_loc=0x80000223"
1979     cp /etc/profile $DIR/$tfile || error "cp failed"
1980     do_facet ost1 "$LCTL set_param fail_loc=0"
1981     client_reconnect
1982     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1983     CONN3=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1984     ATTEMPTS=$(($CONN3 - $CONN2))
1985     echo "$ATTEMPTS osc reconnect attempts on 2nd slow"
1986     [ $ATTEMPTS -gt 0 ] && error "AT should have prevented reconnect"
1987     return 0
1988 }
1989 run_test 67b "AT: verify instant slowdown doesn't induce reconnects"
1990
1991 test_68 () #bug 13813
1992 {
1993     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1994
1995     at_start || return 0
1996     local ldlm_enqueue_min=$(find /sys -name ldlm_enqueue_min)
1997     [ -z "$ldlm_enqueue_min" ] && skip "missing /sys/.../ldlm_enqueue_min" && return 0
1998     local ldlm_enqueue_min_r=$(do_facet ost1 "find /sys -name ldlm_enqueue_min")
1999     [ -z "$ldlm_enqueue_min_r" ] && skip "missing /sys/.../ldlm_enqueue_min in the ost1" && return 0
2000     local ENQ_MIN=$(cat $ldlm_enqueue_min)
2001     local ENQ_MIN_R=$(do_facet ost1 "cat $ldlm_enqueue_min_r")
2002         echo $TIMEOUT >> $ldlm_enqueue_min
2003         do_facet ost1 "echo $TIMEOUT >> $ldlm_enqueue_min_r"
2004
2005         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2006         $LFS setstripe --stripe-index=0 -c 1 $DIR/$tdir ||
2007                 error "$LFS setstripe failed for $DIR/$tdir"
2008         #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
2009         $LCTL set_param fail_val=$(($TIMEOUT - 1))
2010         $LCTL set_param fail_loc=0x80000312
2011         cp /etc/profile $DIR/$tdir/${tfile}_1 || error "1st cp failed $?"
2012         $LCTL set_param fail_val=$((TIMEOUT * 5 / 4))
2013         $LCTL set_param fail_loc=0x80000312
2014         cp /etc/profile $DIR/$tdir/${tfile}_2 || error "2nd cp failed $?"
2015         $LCTL set_param fail_loc=0
2016
2017         echo $ENQ_MIN >> $ldlm_enqueue_min
2018         do_facet ost1 "echo $ENQ_MIN_R >> $ldlm_enqueue_min_r"
2019         rm -rf $DIR/$tdir
2020         return 0
2021 }
2022 run_test 68 "AT: verify slowing locks"
2023
2024 at_cleanup
2025 # end of AT tests includes above lines
2026
2027 # start multi-client tests
2028 test_70a () {
2029         [ -z "$CLIENTS" ] &&
2030                 { skip "Need two or more clients." && return; }
2031         [ $CLIENTCOUNT -lt 2 ] &&
2032                 { skip "Need two or more clients, have $CLIENTCOUNT" && return; }
2033
2034         echo "mount clients $CLIENTS ..."
2035         zconf_mount_clients $CLIENTS $MOUNT
2036
2037         local clients=${CLIENTS//,/ }
2038         echo "Write/read files on $DIR ; clients $CLIENTS ... "
2039         for CLIENT in $clients; do
2040                 do_node $CLIENT dd bs=1M count=10 if=/dev/zero \
2041                         of=$DIR/${tfile}_${CLIENT} 2>/dev/null ||
2042                                 error "dd failed on $CLIENT"
2043         done
2044
2045         local prev_client=$(echo $clients | sed 's/^.* \(.\+\)$/\1/')
2046         for C in ${CLIENTS//,/ }; do
2047                 do_node $prev_client dd if=$DIR/${tfile}_${C} \
2048                         of=/dev/null 2>/dev/null ||
2049                         error "dd if=$DIR/${tfile}_${C} failed on $prev_client"
2050                 prev_client=$C
2051         done
2052
2053         ls $DIR
2054 }
2055 run_test 70a "check multi client t-f"
2056
2057 check_for_process () {
2058         local clients=$1
2059         shift
2060         local prog=$@
2061
2062         killall_process $clients "$prog" -0
2063 }
2064
2065 test_70b () {
2066         local clients=${CLIENTS:-$HOSTNAME}
2067
2068         zconf_mount_clients $clients $MOUNT
2069
2070         local duration=300
2071         [ "$SLOW" = "no" ] && duration=120
2072         # set duration to 900 because it takes some time to boot node
2073         [ "$FAILURE_MODE" = HARD ] && duration=900
2074
2075         local elapsed
2076         local start_ts=$(date +%s)
2077         local cmd="rundbench 1 -t $duration"
2078         local pid=""
2079         if [ $MDSCOUNT -ge 2 ]; then
2080                 test_mkdir -p -c$MDSCOUNT $DIR/$tdir
2081                 $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir
2082         fi
2083         do_nodesv $clients "set -x; MISSING_DBENCH_OK=$MISSING_DBENCH_OK \
2084                 PATH=\$PATH:$LUSTRE/utils:$LUSTRE/tests/:$DBENCH_LIB \
2085                 DBENCH_LIB=$DBENCH_LIB TESTSUITE=$TESTSUITE TESTNAME=$TESTNAME \
2086                 MOUNT=$MOUNT DIR=$DIR/$tdir/\\\$(hostname) LCTL=$LCTL $cmd" &
2087         pid=$!
2088
2089         #LU-1897 wait for all dbench copies to start
2090         while ! check_for_process $clients dbench; do
2091                 elapsed=$(($(date +%s) - start_ts))
2092                 if [ $elapsed -gt $duration ]; then
2093                         killall_process $clients dbench
2094                         error "dbench failed to start on $clients!"
2095                 fi
2096                 sleep 1
2097         done
2098
2099         log "Started rundbench load pid=$pid ..."
2100
2101         elapsed=$(($(date +%s) - start_ts))
2102         local num_failovers=0
2103         local fail_index=1
2104         while [ $elapsed -lt $duration ]; do
2105                 if ! check_for_process $clients dbench; then
2106                         error_noexit "dbench stopped on some of $clients!"
2107                         killall_process $clients dbench
2108                         break
2109                 fi
2110                 sleep 1
2111                 replay_barrier mds$fail_index
2112                 sleep 1 # give clients a time to do operations
2113                 # Increment the number of failovers
2114                 num_failovers=$((num_failovers+1))
2115                 log "$TESTNAME fail mds$fail_index $num_failovers times"
2116                 fail mds$fail_index
2117                 elapsed=$(($(date +%s) - start_ts))
2118                 if [ $fail_index -ge $MDSCOUNT ]; then
2119                         fail_index=1
2120                 else
2121                         fail_index=$((fail_index+1))
2122                 fi
2123         done
2124
2125         wait $pid || error "rundbench load on $clients failed!"
2126 }
2127 run_test 70b "dbench ${MDSCOUNT}mdts recovery; $CLIENTCOUNT clients"
2128 # end multi-client tests
2129
2130 random_fail_mdt() {
2131         local max_index=$1
2132         local duration=$2
2133         local monitor_pid=$3
2134         local elapsed
2135         local start_ts=$(date +%s)
2136         local num_failovers=0
2137         local fail_index
2138
2139         elapsed=$(($(date +%s) - start_ts))
2140         while [ $elapsed -lt $duration ]; do
2141                 fail_index=$((RANDOM%max_index+1))
2142                 kill -0 $monitor_pid ||
2143                         error "$monitor_pid stopped"
2144                 sleep 120
2145                 replay_barrier mds$fail_index
2146                 sleep 10
2147                 # Increment the number of failovers
2148                 num_failovers=$((num_failovers+1))
2149                 log "$TESTNAME fail mds$fail_index $num_failovers times"
2150                 fail mds$fail_index
2151                 elapsed=$(($(date +%s) - start_ts))
2152         done
2153 }
2154
2155 cleanup_70c() {
2156         trap 0
2157         rm -f $DIR/replay-single.70c.lck
2158         rm -rf /$DIR/$tdir
2159 }
2160
2161 test_70c () {
2162         local clients=${CLIENTS:-$HOSTNAME}
2163         local rc=0
2164
2165         zconf_mount_clients $clients $MOUNT
2166
2167         local duration=300
2168         [ "$SLOW" = "no" ] && duration=180
2169         # set duration to 900 because it takes some time to boot node
2170         [ "$FAILURE_MODE" = HARD ] && duration=600
2171
2172         local elapsed
2173         local start_ts=$(date +%s)
2174
2175         trap cleanup_70c EXIT
2176         (
2177                 while [ ! -e $DIR/replay-single.70c.lck ]; do
2178                         test_mkdir -p -c$MDSCOUNT $DIR/$tdir || break
2179                         if [ $MDSCOUNT -ge 2 ]; then
2180                                 $LFS setdirstripe -D -c$MDSCOUNT $DIR/$tdir ||
2181                                 error "set default dirstripe failed"
2182                         fi
2183                         cd $DIR/$tdir || break
2184                         tar cf - /etc | tar xf - || error "tar failed in loop"
2185                 done
2186         )&
2187         tar_70c_pid=$!
2188         echo "Started tar $tar_70c_pid"
2189
2190         random_fail_mdt $MDSCOUNT $duration $tar_70c_pid
2191         kill -0 $tar_70c_pid || error "tar $tar_70c_pid stopped"
2192
2193         touch $DIR/replay-single.70c.lck
2194         wait $tar_70c_pid || error "$?: tar failed"
2195
2196         cleanup_70c
2197         true
2198 }
2199 run_test 70c "tar ${MDSCOUNT}mdts recovery"
2200
2201 cleanup_70d() {
2202         trap 0
2203         kill -9 $mkdir_70d_pid
2204 }
2205
2206 test_70d () {
2207         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2208         local clients=${CLIENTS:-$HOSTNAME}
2209         local rc=0
2210
2211         zconf_mount_clients $clients $MOUNT
2212
2213         local duration=300
2214         [ "$SLOW" = "no" ] && duration=180
2215         # set duration to 900 because it takes some time to boot node
2216         [ "$FAILURE_MODE" = HARD ] && duration=900
2217
2218         mkdir -p $DIR/$tdir
2219
2220         local elapsed
2221         local start_ts=$(date +%s)
2222
2223         trap cleanup_70d EXIT
2224         (
2225                 while true; do
2226                         $LFS mkdir -i0 -c2 $DIR/$tdir/test || {
2227                                 echo "mkdir fails"
2228                                 break
2229                         }
2230                         $LFS mkdir -i1 -c2 $DIR/$tdir/test1 || {
2231                                 echo "mkdir fails"
2232                                 break
2233                         }
2234
2235                         touch $DIR/$tdir/test/a || {
2236                                 echo "touch fails"
2237                                 break;
2238                         }
2239                         mkdir $DIR/$tdir/test/b || {
2240                                 echo "mkdir fails"
2241                                 break;
2242                         }
2243                         rm -rf $DIR/$tdir/test || {
2244                                 echo "rmdir fails"
2245                                 ls -lR $DIR/$tdir
2246                                 break
2247                         }
2248
2249                         touch $DIR/$tdir/test1/a || {
2250                                 echo "touch fails"
2251                                 break;
2252                         }
2253                         mkdir $DIR/$tdir/test1/b || {
2254                                 echo "mkdir fails"
2255                                 break;
2256                         }
2257
2258                         rm -rf $DIR/$tdir/test1 || {
2259                                 echo "rmdir fails"
2260                                 ls -lR $DIR/$tdir/test1
2261                                 break
2262                         }
2263                 done
2264         )&
2265         mkdir_70d_pid=$!
2266         echo "Started  $mkdir_70d_pid"
2267
2268         random_fail_mdt $MDSCOUNT $duration $mkdir_70d_pid
2269         kill -0 $mkdir_70d_pid || error "mkdir/rmdir $mkdir_70d_pid stopped"
2270
2271         cleanup_70d
2272         true
2273 }
2274 run_test 70d "mkdir/rmdir striped dir ${MDSCOUNT}mdts recovery"
2275
2276 test_70e () {
2277         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2278         local clients=${CLIENTS:-$HOSTNAME}
2279         local rc=0
2280
2281         lctl set_param debug=+ha
2282         zconf_mount_clients $clients $MOUNT
2283
2284         local duration=300
2285         [ "$SLOW" = "no" ] && duration=180
2286         # set duration to 900 because it takes some time to boot node
2287         [ "$FAILURE_MODE" = HARD ] && duration=900
2288
2289         mkdir -p $DIR/$tdir
2290         $LFS mkdir -i0 $DIR/$tdir/test_0
2291         $LFS mkdir -i0 $DIR/$tdir/test_1
2292         touch $DIR/$tdir/test_0/a
2293         touch $DIR/$tdir/test_1/b
2294         (
2295         while true; do
2296                 mrename $DIR/$tdir/test_0/a $DIR/$tdir/test_1/b > /dev/null || {
2297                         echo "a->b fails"
2298                         break;
2299                 }
2300
2301                 checkstat $DIR/$tdir/test_0/a && {
2302                         echo "a still exists"
2303                         break
2304                 }
2305
2306                 checkstat $DIR/$tdir/test_1/b || {
2307                         echo "b still  exists"
2308                         break
2309                 }
2310
2311                 touch $DIR/$tdir/test_0/a || {
2312                         echo "touch a fails"
2313                         break
2314                 }
2315
2316                 mrename $DIR/$tdir/test_1/b $DIR/$tdir/test_0/a > /dev/null || {
2317                         echo "a->a fails"
2318                         break;
2319                 }
2320         done
2321         )&
2322         rename_70e_pid=$!
2323         stack_trap "kill -9 $rename_70e_pid" EXIT
2324         echo "Started PID=$rename_70e_pid"
2325
2326         random_fail_mdt 2 $duration $rename_70e_pid
2327         kill -0 $rename_70e_pid || error "rename $rename_70e_pid stopped"
2328 }
2329 run_test 70e "rename cross-MDT with random fails"
2330
2331 test_70f_write_and_read(){
2332         local srcfile=$1
2333         local stopflag=$2
2334         local client
2335
2336         echo "Write/read files in: '$DIR/$tdir', clients: '$CLIENTS' ..."
2337         for client in ${CLIENTS//,/ }; do
2338                 [ -f $stopflag ] || return
2339
2340                 local tgtfile=$DIR/$tdir/$tfile.$client
2341                 do_node $client dd $DD_OPTS bs=1M count=10 if=$srcfile \
2342                         of=$tgtfile 2>/dev/null ||
2343                         error "dd $DD_OPTS bs=1M count=10 if=$srcfile " \
2344                               "of=$tgtfile failed on $client, rc=$?"
2345         done
2346
2347         local prev_client=$(echo ${CLIENTS//,/ } | awk '{ print $NF }')
2348         local index=0
2349
2350         for client in ${CLIENTS//,/ }; do
2351                 [ -f $stopflag ] || return
2352
2353                 # flush client cache in case test is running on only one client
2354                 # do_node $client cancel_lru_locks osc
2355                 do_node $client $LCTL set_param ldlm.namespaces.*.lru_size=clear
2356
2357                 tgtfile=$DIR/$tdir/$tfile.$client
2358                 local md5=$(do_node $prev_client "md5sum $tgtfile")
2359                 [ ${checksum[$index]// */} = ${md5// */} ] ||
2360                         error "$tgtfile: checksum doesn't match on $prev_client"
2361                 index=$((index + 1))
2362                 prev_client=$client
2363         done
2364 }
2365
2366 test_70f_loop(){
2367         local srcfile=$1
2368         local stopflag=$2
2369         DD_OPTS=
2370
2371         mkdir -p $DIR/$tdir || error "cannot create $DIR/$tdir directory"
2372         $LFS setstripe -c -1 $DIR/$tdir ||
2373                 error "cannot $LFS setstripe $DIR/$tdir"
2374
2375         touch $stopflag
2376         while [ -f $stopflag ]; do
2377                 test_70f_write_and_read $srcfile $stopflag
2378                 # use direct IO and buffer cache in turns if loop
2379                 [ -n "$DD_OPTS" ] && DD_OPTS="" || DD_OPTS="oflag=direct"
2380         done
2381 }
2382
2383 test_70f_cleanup() {
2384         trap 0
2385         rm -f $TMP/$tfile.stop
2386         do_nodes $CLIENTS rm -f $TMP/$tfile
2387         rm -f $DIR/$tdir/$tfile.*
2388 }
2389
2390 test_70f() {
2391 #       [ x$ost1failover_HOST = x$ost_HOST ] &&
2392 #               { skip "Failover host not defined" && return; }
2393 #       [ -z "$CLIENTS" ] &&
2394 #               { skip "CLIENTS are not specified." && return; }
2395 #       [ $CLIENTCOUNT -lt 2 ] &&
2396 #               { skip "Need 2 or more clients, have $CLIENTCOUNT" && return; }
2397
2398         [[ "$OST1_VERSION" -lt $(version_code 2.9.53) ]] &&
2399                 skip "Need server version at least 2.9.53"
2400
2401         echo "mount clients $CLIENTS ..."
2402         zconf_mount_clients $CLIENTS $MOUNT
2403
2404         local srcfile=$TMP/$tfile
2405         local client
2406         local index=0
2407
2408         trap test_70f_cleanup EXIT
2409         # create a different source file local to each client node so we can
2410         # detect if the file wasn't written out properly after failover
2411         do_nodes $CLIENTS dd bs=1M count=10 if=/dev/urandom of=$srcfile \
2412                 2>/dev/null || error "can't create $srcfile on $CLIENTS"
2413         for client in ${CLIENTS//,/ }; do
2414                 checksum[$index]=$(do_node $client "md5sum $srcfile")
2415                 index=$((index + 1))
2416         done
2417
2418         local duration=120
2419         [ "$SLOW" = "no" ] && duration=60
2420         # set duration to 900 because it takes some time to boot node
2421         [ "$FAILURE_MODE" = HARD ] && duration=900
2422
2423         local stopflag=$TMP/$tfile.stop
2424         test_70f_loop $srcfile $stopflag &
2425         local pid=$!
2426
2427         local elapsed=0
2428         local num_failovers=0
2429         local start_ts=$SECONDS
2430         while [ $elapsed -lt $duration ]; do
2431                 sleep 3
2432                 replay_barrier ost1
2433                 sleep 1
2434                 num_failovers=$((num_failovers + 1))
2435                 log "$TESTNAME failing OST $num_failovers times"
2436                 fail ost1
2437                 sleep 2
2438                 elapsed=$((SECONDS - start_ts))
2439         done
2440
2441         rm -f $stopflag
2442         wait $pid
2443         test_70f_cleanup
2444 }
2445 run_test 70f "OSS O_DIRECT recovery with $CLIENTCOUNT clients"
2446
2447 cleanup_71a() {
2448         trap 0
2449         kill -9 $mkdir_71a_pid
2450 }
2451
2452 random_double_fail_mdt() {
2453         local max_index=$1
2454         local duration=$2
2455         local monitor_pid=$3
2456         local elapsed
2457         local start_ts=$(date +%s)
2458         local num_failovers=0
2459         local fail_index
2460         local second_index
2461
2462         elapsed=$(($(date +%s) - start_ts))
2463         while [ $elapsed -lt $duration ]; do
2464                 fail_index=$((RANDOM%max_index + 1))
2465                 if [ $fail_index -eq $max_index ]; then
2466                         second_index=1
2467                 else
2468                         second_index=$((fail_index + 1))
2469                 fi
2470                 kill -0 $monitor_pid ||
2471                         error "$monitor_pid stopped"
2472                 sleep 120
2473                 replay_barrier mds$fail_index
2474                 replay_barrier mds$second_index
2475                 sleep 10
2476                 # Increment the number of failovers
2477                 num_failovers=$((num_failovers+1))
2478                 log "fail mds$fail_index mds$second_index $num_failovers times"
2479                 fail mds${fail_index},mds${second_index}
2480                 elapsed=$(($(date +%s) - start_ts))
2481         done
2482 }
2483
2484 test_71a () {
2485         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2486         local clients=${CLIENTS:-$HOSTNAME}
2487         local rc=0
2488
2489         zconf_mount_clients $clients $MOUNT
2490
2491         local duration=300
2492         [ "$SLOW" = "no" ] && duration=180
2493         # set duration to 900 because it takes some time to boot node
2494         [ "$FAILURE_MODE" = HARD ] && duration=900
2495
2496         mkdir -p $DIR/$tdir
2497
2498         local elapsed
2499         local start_ts=$(date +%s)
2500
2501         trap cleanup_71a EXIT
2502         (
2503                 while true; do
2504                         $LFS mkdir -i0 -c2 $DIR/$tdir/test
2505                         rmdir $DIR/$tdir/test
2506                 done
2507         )&
2508         mkdir_71a_pid=$!
2509         echo "Started  $mkdir_71a_pid"
2510
2511         random_double_fail_mdt 2 $duration $mkdir_71a_pid
2512         kill -0 $mkdir_71a_pid || error "mkdir/rmdir $mkdir_71a_pid stopped"
2513
2514         cleanup_71a
2515         true
2516 }
2517 run_test 71a "mkdir/rmdir striped dir with 2 mdts recovery"
2518
2519 test_73a() {
2520         multiop_bg_pause $DIR/$tfile O_tSc ||
2521                 error "multiop_bg_pause $DIR/$tfile failed"
2522         pid=$!
2523         rm -f $DIR/$tfile
2524
2525         replay_barrier $SINGLEMDS
2526         #define OBD_FAIL_LDLM_ENQUEUE_NET                       0x302
2527         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000302"
2528         fail $SINGLEMDS
2529         kill -USR1 $pid
2530         wait $pid || error "multiop pid failed"
2531         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
2532         return 0
2533 }
2534 run_test 73a "open(O_CREAT), unlink, replay, reconnect before open replay, close"
2535
2536 test_73b() {
2537         multiop_bg_pause $DIR/$tfile O_tSc ||
2538                 error "multiop_bg_pause $DIR/$tfile failed"
2539         pid=$!
2540         rm -f $DIR/$tfile
2541
2542         replay_barrier $SINGLEMDS
2543         #define OBD_FAIL_MDS_LDLM_REPLY_NET       0x157
2544         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000157"
2545         fail $SINGLEMDS
2546         kill -USR1 $pid
2547         wait $pid || error "multiop pid failed"
2548         [ -e $DIR/$tfile ] && error "file $DIR/$tfile should not exist"
2549         return 0
2550 }
2551 run_test 73b "open(O_CREAT), unlink, replay, reconnect at open_replay reply, close"
2552
2553 # bug 18554
2554 test_74() {
2555         local clients=${CLIENTS:-$HOSTNAME}
2556
2557         zconf_umount_clients $clients $MOUNT
2558         stop ost1
2559         facet_failover $SINGLEMDS
2560         zconf_mount_clients $clients $MOUNT
2561         mount_facet ost1
2562         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2563         rm $DIR/$tfile || error "rm $DIR/$tfile failed"
2564         clients_up || error "client evicted: $?"
2565         return 0
2566 }
2567 run_test 74 "Ensure applications don't fail waiting for OST recovery"
2568
2569 remote_dir_check_80() {
2570         local mdtidx=1
2571         local diridx
2572         local fileidx
2573
2574         diridx=$($LFS getstripe -m $remote_dir) ||
2575                 error "$LFS getstripe -m $remote_dir failed"
2576         [ $diridx -eq $mdtidx ] || error "$diridx != $mdtidx"
2577
2578         createmany -o $remote_dir/f-%d 20 || error "creation failed"
2579         fileidx=$($LFS getstripe -m $remote_dir/f-1) ||
2580                 error "$LFS getstripe -m $remote_dir/f-1 failed"
2581         [ $fileidx -eq $mdtidx ] || error "$fileidx != $mdtidx"
2582
2583         return 0
2584 }
2585
2586 test_80a() {
2587         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2588         ([ $FAILURE_MODE == "HARD" ] &&
2589                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2590                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2591                 return 0
2592
2593         local MDTIDX=1
2594         local remote_dir=$DIR/$tdir/remote_dir
2595
2596         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2597         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2598         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2599         $LFS mkdir -i $MDTIDX $remote_dir &
2600         local CLIENT_PID=$!
2601
2602         replay_barrier mds1
2603         fail mds${MDTIDX}
2604
2605         wait $CLIENT_PID || error "remote creation failed"
2606
2607         remote_dir_check_80 || error "remote dir check failed"
2608         rm -rf $DIR/$tdir || error "rmdir failed"
2609
2610         return 0
2611 }
2612 run_test 80a "DNE: create remote dir, drop update rep from MDT0, fail MDT0"
2613
2614 test_80b() {
2615         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2616         ([ $FAILURE_MODE == "HARD" ] &&
2617                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2618                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2619                 return 0
2620
2621         local MDTIDX=1
2622         local remote_dir=$DIR/$tdir/remote_dir
2623
2624         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2625         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2626         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2627         $LFS mkdir -i $MDTIDX $remote_dir &
2628         local CLIENT_PID=$!
2629
2630         replay_barrier mds1
2631         replay_barrier mds2
2632         fail mds$((MDTIDX + 1))
2633
2634         wait $CLIENT_PID || error "remote creation failed"
2635
2636         remote_dir_check_80 || error "remote dir check failed"
2637         rm -rf $DIR/$tdir || error "rmdir failed"
2638
2639         return 0
2640 }
2641 run_test 80b "DNE: create remote dir, drop update rep from MDT0, fail MDT1"
2642
2643 test_80c() {
2644         [[ "$mds1_FSTYPE" = zfs ]] &&
2645                 [[ $MDS1_VERSION -lt $(version_code 2.12.51) ]] &&
2646                 skip "requires LU-10143 fix on MDS"
2647         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2648         ([ $FAILURE_MODE == "HARD" ] &&
2649                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2650                 skip "MDTs needs to be on diff hosts for HARD fail mode"
2651
2652         local MDTIDX=1
2653         local remote_dir=$DIR/$tdir/remote_dir
2654
2655         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2656         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2657         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2658         $LFS mkdir -i $MDTIDX $remote_dir &
2659         local CLIENT_PID=$!
2660
2661         replay_barrier mds1
2662         replay_barrier mds2
2663         fail mds${MDTIDX}
2664         fail mds$((MDTIDX + 1))
2665
2666         wait $CLIENT_PID || error "remote creation failed"
2667
2668         remote_dir_check_80 || error "remote dir check failed"
2669         rm -rf $DIR/$tdir || error "rmdir failed"
2670
2671         return 0
2672 }
2673 run_test 80c "DNE: create remote dir, drop update rep from MDT1, fail MDT[0,1]"
2674
2675 test_80d() {
2676         [[ "$mds1_FSTYPE" = zfs ]] &&
2677                 [[ $MDS1_VERSION -lt $(version_code 2.12.51) ]] &&
2678                 skip "requires LU-10143 fix on MDS"
2679         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2680         local MDTIDX=1
2681         local remote_dir=$DIR/$tdir/remote_dir
2682
2683         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2684         #define OBD_FAIL_OUT_UPDATE_NET_REP     0x1701
2685         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2686         $LFS mkdir -i $MDTIDX $remote_dir &
2687         local CLIENT_PID=$!
2688
2689         # sleep 3 seconds to make sure MDTs are failed after
2690         # lfs mkdir -i has finished on all of MDTs.
2691         sleep 3
2692
2693         replay_barrier mds1
2694         replay_barrier mds2
2695         fail mds${MDTIDX},mds$((MDTIDX + 1))
2696
2697         wait $CLIENT_PID || error "remote creation failed"
2698
2699         remote_dir_check_80 || error "remote dir check failed"
2700         rm -rf $DIR/$tdir || error "rmdir failed"
2701
2702         return 0
2703 }
2704 run_test 80d "DNE: create remote dir, drop update rep from MDT1, fail 2 MDTs"
2705
2706 test_80e() {
2707         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2708         ([ $FAILURE_MODE == "HARD" ] &&
2709                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2710                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2711                 return 0
2712
2713         local MDTIDX=1
2714         local remote_dir=$DIR/$tdir/remote_dir
2715
2716         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2717         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2718         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2719         $LFS mkdir -i $MDTIDX $remote_dir &
2720         local CLIENT_PID=$!
2721
2722         # sleep 3 seconds to make sure MDTs are failed after
2723         # lfs mkdir -i has finished on all of MDTs.
2724         sleep 3
2725
2726         replay_barrier mds1
2727         fail mds${MDTIDX}
2728
2729         wait $CLIENT_PID || error "remote creation failed"
2730
2731         remote_dir_check_80 || error "remote dir check failed"
2732         rm -rf $DIR/$tdir || error "rmdir failed"
2733
2734         return 0
2735 }
2736 run_test 80e "DNE: create remote dir, drop MDT1 rep, fail MDT0"
2737
2738 test_80f() {
2739         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2740         ([ $FAILURE_MODE == "HARD" ] &&
2741                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2742                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2743                 return 0
2744         local MDTIDX=1
2745         local remote_dir=$DIR/$tdir/remote_dir
2746
2747         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2748         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2749         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2750         $LFS mkdir -i $MDTIDX $remote_dir &
2751         local CLIENT_PID=$!
2752
2753         replay_barrier mds2
2754         fail mds$((MDTIDX + 1))
2755
2756         wait $CLIENT_PID || error "remote creation failed"
2757
2758         remote_dir_check_80 || error "remote dir check failed"
2759         rm -rf $DIR/$tdir || error "rmdir failed"
2760
2761         return 0
2762 }
2763 run_test 80f "DNE: create remote dir, drop MDT1 rep, fail MDT1"
2764
2765 test_80g() {
2766         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2767         ([ $FAILURE_MODE == "HARD" ] &&
2768                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2769                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2770                 return 0
2771
2772         local MDTIDX=1
2773         local remote_dir=$DIR/$tdir/remote_dir
2774
2775         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2776         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2777         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2778         $LFS mkdir -i $MDTIDX $remote_dir &
2779         local CLIENT_PID=$!
2780
2781         # sleep 3 seconds to make sure MDTs are failed after
2782         # lfs mkdir -i has finished on all of MDTs.
2783         sleep 3
2784
2785         replay_barrier mds1
2786         replay_barrier mds2
2787         fail mds${MDTIDX}
2788         fail mds$((MDTIDX + 1))
2789
2790         wait $CLIENT_PID || error "remote creation failed"
2791
2792         remote_dir_check_80 || error "remote dir check failed"
2793         rm -rf $DIR/$tdir || error "rmdir failed"
2794
2795         return 0
2796 }
2797 run_test 80g "DNE: create remote dir, drop MDT1 rep, fail MDT0, then MDT1"
2798
2799 test_80h() {
2800         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2801         local MDTIDX=1
2802         local remote_dir=$DIR/$tdir/remote_dir
2803
2804         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2805         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2806         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2807         $LFS mkdir -i $MDTIDX $remote_dir &
2808         local CLIENT_PID=$!
2809
2810         # sleep 3 seconds to make sure MDTs are failed after
2811         # lfs mkdir -i has finished on all of MDTs.
2812         sleep 3
2813
2814         replay_barrier mds1
2815         replay_barrier mds2
2816         fail mds${MDTIDX},mds$((MDTIDX + 1))
2817
2818         wait $CLIENT_PID || error "remote dir creation failed"
2819
2820         remote_dir_check_80 || error "remote dir check failed"
2821         rm -rf $DIR/$tdir || error "rmdir failed"
2822
2823         return 0
2824 }
2825 run_test 80h "DNE: create remote dir, drop MDT1 rep, fail 2 MDTs"
2826
2827 test_81a() {
2828         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2829         ([ $FAILURE_MODE == "HARD" ] &&
2830                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2831                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2832                 return 0
2833
2834         local MDTIDX=1
2835         local remote_dir=$DIR/$tdir/remote_dir
2836
2837         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2838         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2839
2840         touch $remote_dir || error "touch $remote_dir failed"
2841         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2842         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2843         rmdir $remote_dir &
2844         local CLIENT_PID=$!
2845
2846         replay_barrier mds2
2847         fail mds$((MDTIDX + 1))
2848
2849         wait $CLIENT_PID || error "rm remote dir failed"
2850
2851         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2852
2853         rm -rf $DIR/$tdir || error "rmdir failed"
2854
2855         return 0
2856 }
2857 run_test 81a "DNE: unlink remote dir, drop MDT0 update rep,  fail MDT1"
2858
2859 test_81b() {
2860         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2861         ([ $FAILURE_MODE == "HARD" ] &&
2862                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2863                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2864                 return 0
2865         local MDTIDX=1
2866         local remote_dir=$DIR/$tdir/remote_dir
2867
2868         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2869         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2870
2871         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2872         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2873         rmdir $remote_dir &
2874         local CLIENT_PID=$!
2875
2876         replay_barrier mds1
2877         fail mds${MDTIDX}
2878
2879         wait $CLIENT_PID || error "rm remote dir failed"
2880
2881         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2882
2883         rm -rf $DIR/$tdir || error "rmdir failed"
2884
2885         return 0
2886 }
2887 run_test 81b "DNE: unlink remote dir, drop MDT0 update reply,  fail MDT0"
2888
2889 test_81c() {
2890         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2891         ([ $FAILURE_MODE == "HARD" ] &&
2892                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2893                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2894                 return 0
2895
2896         local MDTIDX=1
2897         local remote_dir=$DIR/$tdir/remote_dir
2898
2899         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2900         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2901
2902         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2903         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2904         rmdir $remote_dir &
2905         local CLIENT_PID=$!
2906
2907         replay_barrier mds1
2908         replay_barrier mds2
2909         fail mds${MDTIDX}
2910         fail mds$((MDTIDX + 1))
2911
2912         wait $CLIENT_PID || error "rm remote dir failed"
2913
2914         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2915
2916         rm -rf $DIR/$tdir || error "rmdir failed"
2917
2918         return 0
2919 }
2920 run_test 81c "DNE: unlink remote dir, drop MDT0 update reply, fail MDT0,MDT1"
2921
2922 test_81d() {
2923         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2924         local MDTIDX=1
2925         local remote_dir=$DIR/$tdir/remote_dir
2926
2927         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2928         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2929
2930         # OBD_FAIL_OUT_UPDATE_NET_REP       0x1701
2931         do_facet mds${MDTIDX} lctl set_param fail_loc=0x1701
2932         rmdir $remote_dir &
2933         local CLIENT_PID=$!
2934
2935         replay_barrier mds1
2936         replay_barrier mds2
2937         fail mds${MDTIDX},mds$((MDTIDX + 1))
2938
2939         wait $CLIENT_PID || error "rm remote dir failed"
2940
2941         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2942
2943         rm -rf $DIR/$tdir || error "rmdir failed"
2944
2945         return 0
2946 }
2947 run_test 81d "DNE: unlink remote dir, drop MDT0 update reply,  fail 2 MDTs"
2948
2949 test_81e() {
2950         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2951         ([ $FAILURE_MODE == "HARD" ] &&
2952                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2953                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2954                 return 0
2955
2956         local MDTIDX=1
2957         local remote_dir=$DIR/$tdir/remote_dir
2958
2959         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2960         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2961
2962         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2963         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2964         rmdir $remote_dir &
2965         local CLIENT_PID=$!
2966         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0
2967
2968         replay_barrier mds1
2969         fail mds${MDTIDX}
2970
2971         wait $CLIENT_PID || error "rm remote dir failed"
2972
2973         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
2974
2975         rm -rf $DIR/$tdir || error "rmdir failed"
2976
2977         return 0
2978 }
2979 run_test 81e "DNE: unlink remote dir, drop MDT1 req reply, fail MDT0"
2980
2981 test_81f() {
2982         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2983         ([ $FAILURE_MODE == "HARD" ] &&
2984                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
2985                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
2986                 return 0
2987
2988         local MDTIDX=1
2989         local remote_dir=$DIR/$tdir/remote_dir
2990
2991         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2992         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
2993
2994         # OBD_FAIL_MDS_REINT_NET_REP       0x119
2995         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
2996         rmdir $remote_dir &
2997         local CLIENT_PID=$!
2998
2999         replay_barrier mds2
3000         fail mds$((MDTIDX + 1))
3001
3002         wait $CLIENT_PID || error "rm remote dir failed"
3003
3004         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3005
3006         rm -rf $DIR/$tdir || error "rmdir failed"
3007
3008         return 0
3009 }
3010 run_test 81f "DNE: unlink remote dir, drop MDT1 req reply, fail MDT1"
3011
3012 test_81g() {
3013         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3014         ([ $FAILURE_MODE == "HARD" ] &&
3015                 [ "$(facet_host mds1)" == "$(facet_host mds2)" ]) &&
3016                 skip "MDTs needs to be on diff hosts for HARD fail mode" &&
3017                 return 0
3018
3019         local MDTIDX=1
3020         local remote_dir=$DIR/$tdir/remote_dir
3021
3022         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3023         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
3024
3025         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3026         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
3027         rmdir $remote_dir &
3028         local CLIENT_PID=$!
3029
3030         replay_barrier mds1
3031         replay_barrier mds2
3032         fail mds${MDTIDX}
3033         fail mds$((MDTIDX + 1))
3034
3035         wait $CLIENT_PID || error "rm remote dir failed"
3036
3037         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3038
3039         rm -rf $DIR/$tdir || error "rmdir failed"
3040
3041         return 0
3042 }
3043 run_test 81g "DNE: unlink remote dir, drop req reply, fail M0, then M1"
3044
3045 test_81h() {
3046         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
3047         local MDTIDX=1
3048         local remote_dir=$DIR/$tdir/remote_dir
3049
3050         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3051         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
3052
3053         # OBD_FAIL_MDS_REINT_NET_REP       0x119
3054         do_facet mds$((MDTIDX + 1)) lctl set_param fail_loc=0x119
3055         rmdir $remote_dir &
3056         local CLIENT_PID=$!
3057
3058         replay_barrier mds1
3059         replay_barrier mds2
3060         fail mds${MDTIDX},mds$((MDTIDX + 1))
3061
3062         wait $CLIENT_PID || error "rm remote dir failed"
3063
3064         stat $remote_dir &>/dev/null && error "$remote_dir still exist!"
3065
3066         rm -rf $DIR/$tdir || error "rmdir failed"
3067
3068         return 0
3069 }
3070 run_test 81h "DNE: unlink remote dir, drop request reply, fail 2 MDTs"
3071
3072 test_84a() {
3073 #define OBD_FAIL_MDS_OPEN_WAIT_CREATE  0x144
3074     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000144"
3075     createmany -o $DIR/$tfile- 1 &
3076     PID=$!
3077     mds_evict_client
3078     wait $PID
3079     client_up || client_up || true    # reconnect
3080 }
3081 run_test 84a "stale open during export disconnect"
3082
3083 test_85a() { #bug 16774
3084         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
3085
3086         for i in $(seq 100); do
3087                 echo "tag-$i" > $DIR/$tfile-$i
3088                 grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
3089         done
3090
3091         lov_id=$(lctl dl | grep "clilov")
3092         addr=$(echo $lov_id | awk '{print $4}' | awk -F '-' '{print $NF}')
3093         count=$(lctl get_param -n \
3094                 ldlm.namespaces.*MDT0000*$addr.lock_unused_count)
3095         echo "before recovery: unused locks count = $count"
3096
3097         fail $SINGLEMDS
3098
3099         count2=$(lctl get_param -n \
3100                  ldlm.namespaces.*MDT0000*$addr.lock_unused_count)
3101         echo "after recovery: unused locks count = $count2"
3102
3103         if [ $count2 -ge $count ]; then
3104                 error "unused locks are not canceled"
3105         fi
3106 }
3107 run_test 85a "check the cancellation of unused locks during recovery(IBITS)"
3108
3109 test_85b() { #bug 16774
3110         rm -rf $DIR/$tdir
3111         mkdir $DIR/$tdir
3112
3113         lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
3114
3115         $LFS setstripe -c 1 -i 0 $DIR/$tdir
3116
3117         for i in $(seq 100); do
3118                 dd if=/dev/urandom of=$DIR/$tdir/$tfile-$i bs=4096 \
3119                         count=32 >/dev/null 2>&1
3120         done
3121
3122         cancel_lru_locks osc
3123
3124         for i in $(seq 100); do
3125                 dd if=$DIR/$tdir/$tfile-$i of=/dev/null bs=4096 \
3126                         count=32 >/dev/null 2>&1
3127         done
3128
3129         lov_id=$(lctl dl | grep "clilov")
3130         addr=$(echo $lov_id | awk '{print $4}' | awk -F '-' '{print $NF}')
3131         count=$(lctl get_param -n \
3132                           ldlm.namespaces.*OST0000*$addr.lock_unused_count)
3133         echo "before recovery: unused locks count = $count"
3134         [ $count -ne 0 ] || error "unused locks ($count) should be zero"
3135
3136         fail ost1
3137
3138         count2=$(lctl get_param \
3139                  -n ldlm.namespaces.*OST0000*$addr.lock_unused_count)
3140         echo "after recovery: unused locks count = $count2"
3141
3142         if [ $count2 -ge $count ]; then
3143                 error "unused locks are not canceled"
3144         fi
3145
3146         rm -rf $DIR/$tdir
3147 }
3148 run_test 85b "check the cancellation of unused locks during recovery(EXTENT)"
3149
3150 test_86() {
3151         local clients=${CLIENTS:-$HOSTNAME}
3152
3153         zconf_umount_clients $clients $MOUNT
3154         do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT*.exports.clear=0
3155         remount_facet $SINGLEMDS
3156         zconf_mount_clients $clients $MOUNT
3157 }
3158 run_test 86 "umount server after clear nid_stats should not hit LBUG"
3159
3160 test_87a() {
3161         do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
3162
3163         replay_barrier ost1
3164         $LFS setstripe -i 0 -c 1 $DIR/$tfile
3165         dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 ||
3166                 error "dd to $DIR/$tfile failed"
3167         cksum=$(md5sum $DIR/$tfile | awk '{print $1}')
3168         cancel_lru_locks osc
3169         fail ost1
3170         dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
3171         cksum2=$(md5sum $DIR/$tfile | awk '{print $1}')
3172         if [ $cksum != $cksum2 ] ; then
3173                 error "New checksum $cksum2 does not match original $cksum"
3174         fi
3175 }
3176 run_test 87a "write replay"
3177
3178 test_87b() {
3179         do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
3180
3181         replay_barrier ost1
3182         $LFS setstripe -i 0 -c 1 $DIR/$tfile
3183         dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 ||
3184                 error "dd to $DIR/$tfile failed"
3185         sleep 1 # Give it a chance to flush dirty data
3186         echo TESTTEST | dd of=$DIR/$tfile bs=1 count=8 seek=64
3187         cksum=$(md5sum $DIR/$tfile | awk '{print $1}')
3188         cancel_lru_locks osc
3189         fail ost1
3190         dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
3191         cksum2=$(md5sum $DIR/$tfile | awk '{print $1}')
3192         if [ $cksum != $cksum2 ] ; then
3193                 error "New checksum $cksum2 does not match original $cksum"
3194         fi
3195 }
3196 run_test 87b "write replay with changed data (checksum resend)"
3197
3198 test_88() { #bug 17485
3199         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3200         mkdir -p $TMP/$tdir || error "mkdir $TMP/$tdir failed"
3201
3202         $LFS setstripe -i 0 -c 1 $DIR/$tdir || error "$LFS setstripe failed"
3203
3204         replay_barrier ost1
3205         replay_barrier $SINGLEMDS
3206
3207         # exhaust precreations on ost1
3208         local OST=$(ostname_from_index 0)
3209         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $OST)
3210         local last_id=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_last_id)
3211         local next_id=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_next_id)
3212         echo "before test: last_id = $last_id, next_id = $next_id"
3213
3214         echo "Creating to objid $last_id on ost $OST..."
3215         createmany -o $DIR/$tdir/f-%d $next_id $((last_id - next_id + 2)) ||
3216                 error "createmany create files to last_id failed"
3217
3218         #create some files to use some uncommitted objids
3219         last_id=$(($last_id + 1))
3220         createmany -o $DIR/$tdir/f-%d $last_id 8 ||
3221                 error "createmany create files with uncommitted objids failed"
3222
3223     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_last_id)
3224     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_next_id)
3225     echo "before recovery: last_id = $last_id2, next_id = $next_id2" 
3226
3227     # if test uses shutdown_facet && reboot_facet instead of facet_failover ()
3228     # it has to take care about the affected facets, bug20407
3229     local affected_mds1=$(affected_facets mds1)
3230     local affected_ost1=$(affected_facets ost1)
3231
3232     shutdown_facet $SINGLEMDS
3233     shutdown_facet ost1
3234
3235     reboot_facet $SINGLEMDS
3236     change_active $affected_mds1
3237     wait_for_facet $affected_mds1
3238     mount_facets $affected_mds1 || error "Restart of mds failed"
3239
3240     reboot_facet ost1
3241     change_active $affected_ost1
3242     wait_for_facet $affected_ost1
3243     mount_facets $affected_ost1 || error "Restart of ost1 failed"
3244
3245     clients_up
3246
3247     last_id2=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_last_id)
3248     next_id2=$(do_facet $SINGLEMDS lctl get_param -n osp.$mdtosc.prealloc_next_id)
3249         echo "after recovery: last_id = $last_id2, next_id = $next_id2"
3250
3251         # create new files, which should use new objids, and ensure the orphan
3252         # cleanup phase for ost1 is completed at the same time
3253         for i in $(seq 8); do
3254                 file_id=$(($last_id + 10 + $i))
3255                 dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
3256         done
3257
3258         # if the objids were not recreated, then "ls" will fail with -ENOENT
3259         ls -l $DIR/$tdir/* || error "can't get the status of precreated files"
3260
3261         local file_id
3262         # write into previously created files
3263         for i in $(seq 8); do
3264                 file_id=$(($last_id + $i))
3265                 dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
3266                 cp -f $DIR/$tdir/f-$file_id $TMP/$tdir/
3267         done
3268
3269         # compare the content
3270         for i in $(seq 8); do
3271                 file_id=$(($last_id + $i))
3272                 cmp $TMP/$tdir/f-$file_id $DIR/$tdir/f-$file_id ||
3273                         error "the content of file is modified!"
3274         done
3275
3276         rm -fr $TMP/$tdir
3277 }
3278 run_test 88 "MDS should not assign same objid to different files "
3279
3280 function calc_osc_kbytes_used() {
3281         local kbtotal=$(calc_osc_kbytes kbytestotal)
3282         local kbfree=$(calc_osc_kbytes kbytesfree)
3283         echo $((kbtotal-kbfree))
3284 }
3285
3286 test_89() {
3287         cancel_lru_locks osc
3288         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3289         rm -f $DIR/$tdir/$tfile
3290         wait_mds_ost_sync || error "initial MDS-OST sync timed out"
3291         wait_delete_completed || error "initial wait delete timed out"
3292         local blocks1=$(calc_osc_kbytes_used)
3293         local write_size=$(fs_log_size)
3294
3295         $LFS setstripe -i 0 -c 1 $DIR/$tdir/$tfile
3296         [ $write_size -lt 1024 ] && write_size=1024
3297         dd if=/dev/zero bs=${write_size}k count=10 of=$DIR/$tdir/$tfile
3298         sync
3299         stop ost1
3300         facet_failover $SINGLEMDS
3301         rm $DIR/$tdir/$tfile
3302         umount $MOUNT
3303         mount_facet ost1
3304         zconf_mount $(hostname) $MOUNT || error "mount fails"
3305         client_up || error "client_up failed"
3306
3307         # wait for the remounted client to connect to ost1
3308         local target=$(get_osc_import_name client ost1)
3309         wait_import_state "FULL" "osc.${target}.ost_server_uuid" \
3310                 $(max_recovery_time)
3311
3312         wait_mds_ost_sync || error "MDS-OST sync timed out"
3313         wait_delete_completed || error "wait delete timed out"
3314         local blocks2=$(calc_osc_kbytes_used)
3315
3316         [ $((blocks2 - blocks1)) -le $(fs_log_size)  ] ||
3317                 error $((blocks2 - blocks1)) blocks leaked
3318 }
3319 run_test 89 "no disk space leak on late ost connection"
3320