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