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