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