Whamcloud - gitweb
fd3efa24dab13691f5591ca1b2e7b10389efe1d3
[fs/lustre-release.git] / lustre / tests / recovery-small.sh
1 #!/bin/bash
2
3 set -e
4
5 #         bug  5493  LU2034
6 ALWAYS_EXCEPT="52    60      $RECOVERY_SMALL_EXCEPT"
7
8 export MULTIOP=${MULTIOP:-multiop}
9 PTLDEBUG=${PTLDEBUG:--1}
10 LUSTRE=${LUSTRE:-`dirname $0`/..}
11 . $LUSTRE/tests/test-framework.sh
12 init_test_env $@
13 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
14 init_logging
15
16 require_dsh_mds || exit 0
17
18 # also long tests: 19, 21a, 21e, 21f, 23, 27
19 #                                   1  2.5  2.5    4    4          (min)"
20 [ "$SLOW" = "no" ] && EXCEPT_SLOW="17  26a  26b    50   51     57"
21
22 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
23 # bug number for skipped test:        LU-2194 LU-2547
24         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 19b     24a 24b"
25
26 build_test_filter
27
28 # Allow us to override the setup if we already have a mounted system by
29 # setting SETUP=" " and CLEANUP=" "
30 SETUP=${SETUP:-""}
31 CLEANUP=${CLEANUP:-""}
32
33 check_and_setup_lustre
34
35 assert_DIR
36 rm -rf $DIR/d[0-9]* $DIR/f.${TESTSUITE}*
37
38 test_1() {
39         local f1="$DIR/$tfile"
40         local f2="$DIR/$tfile.2"
41
42         drop_request "mcreate $f1" ||
43                 error_noexit "create '$f1': drop req"
44
45         drop_reint_reply "mcreate $f2" ||
46                 error_noexit "create '$f2': drop rep"
47
48         drop_request "tchmod 111 $f2" ||
49                 error_noexit "chmod '$f2': drop req"
50
51         drop_reint_reply "tchmod 666 $f2" ||
52                 error_noexit "chmod '$f2': drop rep"
53
54         drop_request "statone $f2" ||
55                 error_noexit "stat '$f2': drop req"
56
57         drop_reply  "statone $f2" ||
58                 error_noexit "stat '$f2': drop rep"
59 }
60 run_test 1 "create, chmod, stat: drop req, drop rep"
61
62 test_4() {
63         local t=$DIR/$tfile
64         do_facet_create_file client $t 10K ||
65                 error_noexit "Create file $t"
66
67         drop_request "cat $t > /dev/null" ||
68                 error_noexit "Open request for $t file"
69
70         drop_reply "cat $t > /dev/null" ||
71                 error_noexit "Open replay for $t file"
72 }
73 run_test 4 "open: drop req, drop rep"
74
75 test_5() {
76         local T=$DIR/$tfile
77         local R="$T-renamed"
78         local RR="$T-renamed-again"
79         do_facet_create_file client $T 10K ||
80                 error_noexit "Create file $T"
81
82         drop_request "mv $T $R" ||
83                 error_noexit "Rename $T"
84
85         drop_reint_reply "mv $R $RR" ||
86                 error_noexit "Failed rename replay on $R"
87
88         do_facet client "checkstat -v $RR" ||
89                 error_noexit "checkstat error on $RR"
90
91         do_facet client "rm $RR" ||
92                 error_noexit "Can't remove file $RR"
93 }
94 run_test 5 "rename: drop req, drop rep"
95
96 test_6() {
97         local T=$DIR/$tfile
98         local LINK1=$DIR/$tfile.link1
99         local LINK2=$DIR/$tfile.link2
100
101         do_facet_create_file client $T 10K ||
102                 error_noexit "Create file $T"
103
104         drop_request "mlink $T $LINK1" ||
105                 error_noexit "mlink request for $T"
106
107         drop_reint_reply "mlink $T $LINK2" ||
108                 error_noexit "mlink reply for $T"
109
110         drop_request "munlink $LINK1" ||
111                 error_noexit "munlink request for $T"
112
113         drop_reint_reply "munlink $LINK2" ||
114                 error_noexit "munlink reply for $T"
115
116         do_facet client "rm $T" ||
117                 error_noexit "Can't remove file $T"
118 }
119 run_test 6 "link, unlink: drop req, drop rep"
120
121 #bug 1423
122 test_8() {
123     drop_reint_reply "touch $DIR/$tfile"    || return 1
124 }
125 run_test 8 "touch: drop rep (bug 1423)"
126
127 #bug 1420
128 test_9() {
129         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
130
131         local t1=${tfile}.1
132         local t2=${tfile}.2
133         do_facet_random_file client $TMP/$tfile 1K ||
134                 error_noexit "Create random file $TMP/$tfile"
135         # make this big, else test 9 doesn't wait for bulk -- bz 5595
136         do_facet_create_file client $TMP/$t1 4M ||
137                 error_noexit "Create file $TMP/$t1"
138         do_facet client "cp $TMP/$t1 $DIR/$t1" ||
139                 error_noexit "Can't copy to $DIR/$t1 file"
140         pause_bulk "cp $TMP/$tfile $DIR/$tfile" ||
141                 error_noexit "Can't pause_bulk copy"
142         do_facet client "cp $TMP/$t1 $DIR/$t2" ||
143                 error_noexit "Can't copy file"
144         do_facet client "sync"
145         do_facet client "rm $DIR/$tfile $DIR/$t2 $DIR/$t1" ||
146                 error_noexit "Can't remove files"
147         do_facet client "rm $TMP/$t1 $TMP/$tfile"
148 }
149 run_test 9 "pause bulk on OST (bug 1420)"
150
151 #bug 1521
152 test_10() {
153         do_facet client mcreate $DIR/$tfile ||
154                 { error "mcreate failed: $?"; return 1; }
155         drop_bl_callback "chmod 0777 $DIR/$tfile"  || echo "evicted as expected"
156         # wait for the mds to evict the client
157         #echo "sleep $(($TIMEOUT*2))"
158         #sleep $(($TIMEOUT*2))
159         do_facet client touch $DIR/$tfile || echo "touch failed, evicted"
160         do_facet client checkstat -v -p 0777 $DIR/$tfile ||
161                 { error "client checkstat failed: $?"; return 3; }
162         do_facet client "munlink $DIR/$tfile"
163         # allow recovery to complete
164         client_up || client_up || sleep $TIMEOUT
165 }
166 run_test 10 "finish request on server after client eviction (bug 1521)"
167
168 #bug 2460
169 # wake up a thread waiting for completion after eviction
170 test_11(){
171         do_facet client $MULTIOP $DIR/$tfile Ow  ||
172                 { error "multiop write failed: $?"; return 1; }
173         do_facet client $MULTIOP $DIR/$tfile or  ||
174                 { error "multiop read failed: $?"; return 2; }
175
176         cancel_lru_locks osc
177
178         do_facet client $MULTIOP $DIR/$tfile or  ||
179                 { error "multiop read failed: $?"; return 3; }
180         drop_bl_callback $MULTIOP $DIR/$tfile Ow || echo "evicted as expected"
181
182         do_facet client munlink $DIR/$tfile ||
183                 { error "munlink failed: $?"; return 4; }
184         # allow recovery to complete
185         client_up || client_up || sleep $TIMEOUT
186 }
187 run_test 11 "wake up a thread waiting for completion after eviction (b=2460)"
188
189 #b=2494
190 test_12(){
191         $LCTL mark $MULTIOP $DIR/$tfile OS_c
192         do_facet $SINGLEMDS "lctl set_param fail_loc=0x115"
193         clear_failloc $SINGLEMDS $((TIMEOUT * 2)) &
194         multiop_bg_pause $DIR/$tfile OS_c ||
195                 { error "multiop failed: $?"; return 1; }
196         PID=$!
197 #define OBD_FAIL_MDS_CLOSE_NET           0x115
198         kill -USR1 $PID
199         echo "waiting for multiop $PID"
200         wait $PID || { error "wait for multiop faile: $?"; return 2; }
201         do_facet client munlink $DIR/$tfile ||
202                 { error "client munlink failed: $?"; return 3; }
203         # allow recovery to complete
204         client_up || client_up || sleep $TIMEOUT
205 }
206 run_test 12 "recover from timed out resend in ptlrpcd (b=2494)"
207
208 # Bug 113, check that readdir lost recv timeout works.
209 test_13() {
210         mkdir -p $DIR/$tdir || { error "mkdir failed: $?"; return 1; }
211         touch $DIR/$tdir/newentry || { error "touch failed: $?"; return 2; }
212 # OBD_FAIL_MDS_READPAGE_NET|OBD_FAIL_ONCE
213         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000104"
214         ls $DIR/$tdir || { error "ls failed: $?"; return 3; }
215         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
216         rm -rf $DIR/$tdir || { error "remove test dir failed: $?"; return 4; }
217 }
218 run_test 13 "mdc_readpage restart test (bug 1138)"
219
220 # Bug 113, check that readdir lost send timeout works.
221 test_14() {
222     mkdir -p $DIR/$tdir
223     touch $DIR/$tdir/newentry
224 # OBD_FAIL_MDS_SENDPAGE|OBD_FAIL_ONCE
225     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000106"
226     ls $DIR/$tdir || return 1
227     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
228 }
229 run_test 14 "mdc_readpage resend test (bug 1138)"
230
231 test_15() {
232     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000128"
233     touch $DIR/$tfile && return 1
234     return 0
235 }
236 run_test 15 "failed open (-ENOMEM)"
237
238 READ_AHEAD=`lctl get_param -n llite.*.max_read_ahead_mb | head -n 1`
239 stop_read_ahead() {
240    lctl set_param -n llite.*.max_read_ahead_mb 0
241 }
242
243 start_read_ahead() {
244    lctl set_param -n llite.*.max_read_ahead_mb $READ_AHEAD
245 }
246
247 test_16() {
248         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
249
250         do_facet_random_file client $TMP/$tfile 100K ||
251                 { error_noexit "Create random file $TMP/$T" ; return 0; }
252         do_facet client "cp $TMP/$tfile $DIR/$tfile" ||
253                 { error_noexit "Copy to $DIR/$tfile file" ; return 0; }
254         sync
255         stop_read_ahead
256
257 #define OBD_FAIL_PTLRPC_BULK_PUT_NET 0x504 | OBD_FAIL_ONCE
258         do_facet ost1 "lctl set_param fail_loc=0x80000504"
259         cancel_lru_locks osc
260         # OST bulk will time out here, client resends
261         do_facet client "cmp $TMP/$tfile $DIR/$tfile" || return 1
262         do_facet ost1 lctl set_param fail_loc=0
263         # give recovery a chance to finish (shouldn't take long)
264         sleep $TIMEOUT
265         do_facet client "cmp $TMP/$tfile $DIR/$tfile" || return 2
266         start_read_ahead
267 }
268 run_test 16 "timeout bulk put, don't evict client (2732)"
269
270 test_17() {
271     local at_max_saved=0
272
273     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
274
275         local SAMPLE_FILE=$TMP/$tfile
276         do_facet_random_file client $SAMPLE_FILE 20K ||
277                 { error_noexit "Create random file $SAMPLE_FILE" ; return 0; }
278
279     # With adaptive timeouts, bulk_get won't expire until adaptive_timeout_max
280     if at_is_enabled; then
281         at_max_saved=$(at_max_get ost1)
282         at_max_set $TIMEOUT ost1
283     fi
284
285     # OBD_FAIL_PTLRPC_BULK_GET_NET 0x0503 | OBD_FAIL_ONCE
286     # OST bulk will time out here, client retries
287     do_facet ost1 lctl set_param fail_loc=0x80000503
288     # need to ensure we send an RPC
289     do_facet client cp $SAMPLE_FILE $DIR/$tfile
290     sync
291
292     # with AT, client will wait adaptive_max*factor+net_latency before
293     # expiring the req, hopefully timeout*2 is enough
294     sleep $(($TIMEOUT*2))
295
296     do_facet ost1 lctl set_param fail_loc=0
297     do_facet client "df $DIR"
298     # expect cmp to succeed, client resent bulk
299     do_facet client "cmp $SAMPLE_FILE $DIR/$tfile" || return 3
300     do_facet client "rm $DIR/$tfile" || return 4
301     [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
302     return 0
303 }
304 run_test 17 "timeout bulk get, don't evict client (2732)"
305
306 test_18a() {
307     [ -z ${ost2_svc} ] && skip_env "needs 2 osts" && return 0
308
309         do_facet_create_file client $TMP/$tfile 20K ||
310                 { error_noexit "Create file $TMP/$tfile" ; return 0; }
311
312     do_facet client mkdir -p $DIR/$tdir
313     f=$DIR/$tdir/$tfile
314
315     cancel_lru_locks osc
316     pgcache_empty || return 1
317
318     # 1 stripe on ost2
319     $LFS setstripe -i 1 -c 1 $f
320     stripe_index=$($LFS getstripe -i $f)
321     if [ $stripe_index -ne 1 ]; then
322         $LFS getstripe $f
323         error "$f: stripe_index $stripe_index != 1" && return
324     fi
325
326     do_facet client cp $TMP/$tfile $f
327     sync
328     local osc2dev=`lctl get_param -n devices | grep ${ost2_svc}-osc- | egrep -v 'MDT' | awk '{print $1}'`
329     $LCTL --device $osc2dev deactivate || return 3
330     # my understanding is that there should be nothing in the page
331     # cache after the client reconnects?     
332     rc=0
333     pgcache_empty || rc=2
334     $LCTL --device $osc2dev activate
335     rm -f $f
336     return $rc
337 }
338 run_test 18a "manual ost invalidate clears page cache immediately"
339
340 test_18b() {
341     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
342
343         do_facet_create_file client $TMP/$tfile 20K ||
344                 { error_noexit "Create file $TMP/$tfile" ; return 0; }
345
346     do_facet client mkdir -p $DIR/$tdir
347     f=$DIR/$tdir/$tfile
348
349     cancel_lru_locks osc
350     pgcache_empty || return 1
351
352     $LFS setstripe -i 0 -c 1 $f
353     stripe_index=$($LFS getstripe -i $f)
354     if [ $stripe_index -ne 0 ]; then
355         $LFS getstripe $f
356         error "$f: stripe_index $stripe_index != 0" && return
357     fi
358
359     do_facet client cp $TMP/$tfile $f
360     sync
361     ost_evict_client
362     # allow recovery to complete
363     sleep $((TIMEOUT + 2))
364     # my understanding is that there should be nothing in the page
365     # cache after the client reconnects?     
366     rc=0
367     pgcache_empty || rc=2
368     rm -f $f
369     return $rc
370 }
371 run_test 18b "eviction and reconnect clears page cache (2766)"
372
373 test_18c() {
374     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
375
376         do_facet_create_file client $TMP/$tfile 20K ||
377                 { error_noexit "Create file $TMP/$tfile" ; return 0; }
378
379     do_facet client mkdir -p $DIR/$tdir
380     f=$DIR/$tdir/$tfile
381
382     cancel_lru_locks osc
383     pgcache_empty || return 1
384
385     $LFS setstripe -i 0 -c 1 $f
386     stripe_index=$($LFS getstripe -i $f)
387     if [ $stripe_index -ne 0 ]; then
388         $LFS getstripe $f
389         error "$f: stripe_index $stripe_index != 0" && return
390     fi
391
392     do_facet client cp $TMP/$tfile $f
393     sync
394     ost_evict_client
395
396     # OBD_FAIL_OST_CONNECT_NET2
397     # lost reply to connect request
398     do_facet ost1 lctl set_param fail_loc=0x80000225
399     # force reconnect
400     sleep 1
401     df $MOUNT > /dev/null 2>&1
402     sleep 2
403     # my understanding is that there should be nothing in the page
404     # cache after the client reconnects?     
405     rc=0
406     pgcache_empty || rc=2
407     rm -f $f
408     return $rc
409 }
410 run_test 18c "Dropped connect reply after eviction handing (14755)"
411
412 test_19a() {
413         local BEFORE=`date +%s`
414         local EVICT
415
416         mount_client $DIR2 || error "failed to mount $DIR2"
417
418         # cancel cached locks from OST to avoid eviction from it
419         cancel_lru_locks osc
420
421         do_facet client "stat $DIR > /dev/null"  ||
422                 error "failed to stat $DIR: $?"
423         drop_ldlm_cancel "chmod 0777 $DIR2" ||
424                 error "failed to chmod $DIR2"
425
426         umount_client $DIR2
427
428         # let the client reconnect
429         client_reconnect
430         EVICT=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
431                 awk -F"[ [,]" '/EVICTED ]$/ \
432                         { if (mx<$5) {mx=$5;} } END { print mx }')
433
434         [ ! -z "$EVICT" ] && [[ $EVICT -gt $BEFORE ]] ||
435                 (do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state;
436                     error "no eviction: $EVICT before:$BEFORE")
437 }
438 run_test 19a "test expired_lock_main on mds (2867)"
439
440 test_19b() {
441         local BEFORE=`date +%s`
442         local EVICT
443
444         mount_client $DIR2 || error "failed to mount $DIR2: $?"
445
446         # cancel cached locks from MDT to avoid eviction from it
447         cancel_lru_locks mdc
448
449         do_facet client $MULTIOP $DIR/$tfile Ow ||
450                 error "failed to run multiop: $?"
451         drop_ldlm_cancel $MULTIOP $DIR2/$tfile Ow ||
452                 error "failed to ldlm_cancel: $?"
453
454         umount_client $DIR2 || error "failed to unmount $DIR2: $?"
455         do_facet client munlink $DIR/$tfile ||
456                 error "failed to unlink $DIR/$tfile: $?"
457
458         # let the client reconnect
459         client_reconnect
460         EVICT=$(do_facet client $LCTL get_param osc.$FSNAME-OST*.state |
461                 awk -F"[ [,]" '/EVICTED ]$/ \
462                         { if (mx<$5) {mx=$5;} } END { print mx }')
463
464         [ ! -z "$EVICT" ] && [[ $EVICT -gt $BEFORE ]] ||
465                 (do_facet client $LCTL get_param osc.$FSNAME-OST*.state;
466                     error "no eviction: $EVICT before:$BEFORE")
467 }
468 run_test 19b "test expired_lock_main on ost (2867)"
469
470 test_19c() {
471         local BEFORE=`date +%s`
472
473         mount_client $DIR2
474         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=0
475
476         mkdir -p $DIR1/$tfile
477         stat $DIR1/$tfile
478
479 #define OBD_FAIL_PTLRPC_CANCEL_RESEND 0x516
480         do_facet mds $LCTL set_param fail_loc=0x80000516
481
482         touch $DIR2/$tfile/file1 &
483         PID1=$!
484         # let touch to get blocked on the server
485         sleep 2
486
487         wait $PID1
488         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=1
489         umount_client $DIR2
490
491         # let the client reconnect
492         sleep 5
493         EVICT=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
494            awk -F"[ [,]" '/EVICTED]$/ { if (mx<$4) {mx=$4;} } END { print mx }')
495
496         [ -z "$EVICT" ] || [[ $EVICT -le $BEFORE ]] || error "eviction happened"
497 }
498 run_test 19c "check reconnect and lock resend do not trigger expired_lock_main"
499
500 test_20a() {    # bug 2983 - ldlm_handle_enqueue cleanup
501         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
502
503         mkdir -p $DIR/$tdir
504         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${tfile}
505         multiop_bg_pause $DIR/$tdir/${tfile} O_wc || return 1
506         MULTI_PID=$!
507         cancel_lru_locks osc
508 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
509         do_facet ost1 lctl set_param fail_loc=0x80000308
510         kill -USR1 $MULTI_PID
511         wait $MULTI_PID
512         rc=$?
513         [ $rc -eq 0 ] && error "multiop didn't fail enqueue: rc $rc" || true
514 }
515 run_test 20a "ldlm_handle_enqueue error (should return error)" 
516
517 test_20b() {    # bug 2986 - ldlm_handle_enqueue error during open
518         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
519
520         mkdir -p $DIR/$tdir
521         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${tfile}
522         cancel_lru_locks osc
523 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
524         do_facet ost1 lctl set_param fail_loc=0x80000308
525         dd if=/etc/hosts of=$DIR/$tdir/$tfile && \
526                 error "didn't fail open enqueue" || true
527 }
528 run_test 20b "ldlm_handle_enqueue error (should return error)"
529
530 test_21a() {
531        mkdir -p $DIR/$tdir-1
532        mkdir -p $DIR/$tdir-2
533        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
534        close_pid=$!
535
536        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000129"
537        $MULTIOP $DIR/$tdir-2/f Oc &
538        open_pid=$!
539        sleep 1
540        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
541
542        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
543        kill -USR1 $close_pid
544        cancel_lru_locks mdc
545        wait $close_pid || return 1
546        wait $open_pid || return 2
547        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
548
549        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
550        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
551
552        rm -rf $DIR/$tdir-*
553 }
554 run_test 21a "drop close request while close and open are both in flight"
555
556 test_21b() {
557        mkdir -p $DIR/$tdir-1
558        mkdir -p $DIR/$tdir-2
559        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
560        close_pid=$!
561
562        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
563        mcreate $DIR/$tdir-2/f &
564        open_pid=$!
565        sleep 1
566        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
567
568        kill -USR1 $close_pid
569        cancel_lru_locks mdc
570        wait $close_pid || return 1
571        wait $open_pid || return 3
572
573        $CHECKSTAT -t file $DIR/$tdir-1/f || return 4
574        $CHECKSTAT -t file $DIR/$tdir-2/f || return 5
575        rm -rf $DIR/$tdir-*
576 }
577 run_test 21b "drop open request while close and open are both in flight"
578
579 test_21c() {
580        mkdir -p $DIR/$tdir-1
581        mkdir -p $DIR/$tdir-2
582        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
583        close_pid=$!
584
585        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
586        mcreate $DIR/$tdir-2/f &
587        open_pid=$!
588        sleep 3
589        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
590
591        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
592        kill -USR1 $close_pid
593        cancel_lru_locks mdc
594        wait $close_pid || return 1
595        wait $open_pid || return 2
596
597        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
598
599        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
600        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
601        rm -rf $DIR/$tdir-*
602 }
603 run_test 21c "drop both request while close and open are both in flight"
604
605 test_21d() {
606        mkdir -p $DIR/$tdir-1
607        mkdir -p $DIR/$tdir-2
608        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
609        pid=$!
610
611        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000129"
612        $MULTIOP $DIR/$tdir-2/f Oc &
613        sleep 1
614        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
615
616        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
617        kill -USR1 $pid
618        cancel_lru_locks mdc
619        wait $pid || return 1
620        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
621
622        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
623        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
624
625        rm -rf $DIR/$tdir-*
626 }
627 run_test 21d "drop close reply while close and open are both in flight"
628
629 test_21e() {
630        mkdir -p $DIR/$tdir-1
631        mkdir -p $DIR/$tdir-2
632        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
633        pid=$!
634
635        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
636        touch $DIR/$tdir-2/f &
637        sleep 1
638        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
639
640        kill -USR1 $pid
641        cancel_lru_locks mdc
642        wait $pid || return 1
643
644        sleep $TIMEOUT
645        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
646        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
647        rm -rf $DIR/$tdir-*
648 }
649 run_test 21e "drop open reply while close and open are both in flight"
650
651 test_21f() {
652        mkdir -p $DIR/$tdir-1
653        mkdir -p $DIR/$tdir-2
654        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
655        pid=$!
656
657        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
658        touch $DIR/$tdir-2/f &
659        sleep 1
660        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
661
662        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
663        kill -USR1 $pid
664        cancel_lru_locks mdc
665        wait $pid || return 1
666        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
667
668        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
669        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
670        rm -rf $DIR/$tdir-*
671 }
672 run_test 21f "drop both reply while close and open are both in flight"
673
674 test_21g() {
675        mkdir -p $DIR/$tdir-1
676        mkdir -p $DIR/$tdir-2
677        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
678        pid=$!
679
680        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
681        touch $DIR/$tdir-2/f &
682        sleep 1
683        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
684
685        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
686        kill -USR1 $pid
687        cancel_lru_locks mdc
688        wait $pid || return 1
689        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
690
691        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
692        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
693        rm -rf $DIR/$tdir-*
694 }
695 run_test 21g "drop open reply and close request while close and open are both in flight"
696
697 test_21h() {
698        mkdir -p $DIR/$tdir-1
699        mkdir -p $DIR/$tdir-2
700        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
701        pid=$!
702
703        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
704        touch $DIR/$tdir-2/f &
705        touch_pid=$!
706        sleep 1
707        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
708
709        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
710        cancel_lru_locks mdc
711        kill -USR1 $pid
712        wait $pid || return 1
713        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
714
715        wait $touch_pid || return 2
716
717        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
718        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
719        rm -rf $DIR/$tdir-*
720 }
721 run_test 21h "drop open request and close reply while close and open are both in flight"
722
723 # bug 3462 - multiple MDC requests
724 test_22() {
725     f1=$DIR/${tfile}-1
726     f2=$DIR/${tfile}-2
727     
728     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
729     $MULTIOP $f2 Oc &
730     close_pid=$!
731
732     sleep 1
733     $MULTIOP $f1 msu || return 1
734
735     cancel_lru_locks mdc
736     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
737
738     wait $close_pid || return 2
739     rm -rf $f2 || return 4
740 }
741 run_test 22 "drop close request and do mknod"
742
743 test_23() { #b=4561
744     multiop_bg_pause $DIR/$tfile O_c || return 1
745     pid=$!
746     # give a chance for open
747     sleep 5
748
749     # try the close
750     drop_request "kill -USR1 $pid"
751
752     fail $SINGLEMDS
753     wait $pid || return 1
754     return 0
755 }
756 run_test 23 "client hang when close a file after mds crash"
757
758 test_24a() { # bug 11710 details correct fsync() behavior
759         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
760
761         mkdir -p $DIR/$tdir
762         $LFS setstripe -i 0 -c 1 $DIR/$tdir
763         cancel_lru_locks osc
764         multiop_bg_pause $DIR/$tdir/$tfile Owy_wyc || return 1
765         MULTI_PID=$!
766         ost_evict_client
767         kill -USR1 $MULTI_PID
768         wait $MULTI_PID
769         rc=$?
770         lctl set_param fail_loc=0x0
771         client_reconnect
772         [ $rc -eq 0 ] && error_ignore 5494 "multiop didn't fail fsync: rc $rc" || true
773 }
774 run_test 24a "fsync error (should return error)"
775
776 wait_client_evicted () {
777         local facet=$1
778         local exports=$2
779         local varsvc=${facet}_svc
780
781         wait_update $(facet_active_host $facet) \
782                 "lctl get_param -n *.${!varsvc}.num_exports | cut -d' ' -f2" \
783                 $((exports - 1)) $3
784 }
785
786 test_24b() {
787         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
788
789         dmesg -c > /dev/null
790         mkdir -p $DIR/$tdir
791         lfs setstripe $DIR/$tdir -s 0 -i 0 -c 1
792         cancel_lru_locks osc
793         multiop_bg_pause $DIR/$tdir/$tfile-1 Ow8192_yc ||
794                 error "mulitop Ow8192_yc failed"
795
796         MULTI_PID1=$!
797         multiop_bg_pause $DIR/$tdir/$tfile-2 Ow8192_c ||
798                 error "mulitop Ow8192_c failed"
799
800         MULTI_PID2=$!
801         ost_evict_client
802
803         kill -USR1 $MULTI_PID1
804         wait $MULTI_PID1
805         rc1=$?
806         kill -USR1 $MULTI_PID2
807         wait $MULTI_PID2
808         rc2=$?
809         lctl set_param fail_loc=0x0
810         client_reconnect
811         [ $rc1 -eq 0 -o $rc2 -eq 0 ] &&
812         error_ignore 5494 "multiop didn't fail fsync: $rc1 or close: $rc2" ||
813                 true
814
815         dmesg | grep "dirty page discard:" || \
816                 error "no discarded dirty page found!"
817 }
818 run_test 24b "test dirty page discard due to client eviction"
819
820 test_26a() {      # was test_26 bug 5921 - evict dead exports by pinger
821 # this test can only run from a client on a separate node.
822         remote_ost || { skip "local OST" && return 0; }
823         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
824         remote_mds || { skip "local MDS" && return 0; }
825
826         if [ $(facet_host mgs) = $(facet_host ost1) ]; then
827                 skip "msg and ost1 are at the same node"
828                 return 0
829         fi
830
831         check_timeout || return 1
832
833         local OST_NEXP=$(do_facet ost1 lctl get_param -n obdfilter.${ost1_svc}.num_exports | cut -d' ' -f2)
834
835         echo starting with $OST_NEXP OST exports
836 # OBD_FAIL_PTLRPC_DROP_RPC 0x505
837         do_facet client lctl set_param fail_loc=0x505
838         # evictor takes PING_EVICT_TIMEOUT + 3 * PING_INTERVAL to evict.
839         # But if there's a race to start the evictor from various obds,
840         # the loser might have to wait for the next ping.
841
842         local rc=0
843         wait_client_evicted ost1 $OST_NEXP $((TIMEOUT * 2 + TIMEOUT * 3 / 4))
844         rc=$?
845         do_facet client lctl set_param fail_loc=0x0
846         [ $rc -eq 0 ] || error "client not evicted from OST"
847 }
848 run_test 26a "evict dead exports"
849
850 test_26b() {      # bug 10140 - evict dead exports by pinger
851         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
852
853         if [ $(facet_host mgs) = $(facet_host ost1) ]; then
854                 skip "msg and ost1 are at the same node"
855                 return 0
856         fi
857
858         check_timeout || return 1
859         clients_up
860         zconf_mount `hostname` $MOUNT2 ||
861                 { error "Failed to mount $MOUNT2"; return 2; }
862         sleep 1 # wait connections being established
863
864         local MDS_NEXP=$(do_facet $SINGLEMDS lctl get_param -n mdt.${mds1_svc}.num_exports | cut -d' ' -f2)
865         local OST_NEXP=$(do_facet ost1 lctl get_param -n obdfilter.${ost1_svc}.num_exports | cut -d' ' -f2)
866
867         echo starting with $OST_NEXP OST and $MDS_NEXP MDS exports
868
869         zconf_umount `hostname` $MOUNT2 -f
870
871         # PING_INTERVAL max(obd_timeout / 4, 1U)
872         # PING_EVICT_TIMEOUT (PING_INTERVAL * 6)
873
874         # evictor takes PING_EVICT_TIMEOUT + 3 * PING_INTERVAL to evict.  
875         # But if there's a race to start the evictor from various obds, 
876         # the loser might have to wait for the next ping.
877         # = 9 * PING_INTERVAL + PING_INTERVAL
878         # = 10 PING_INTERVAL = 10 obd_timeout / 4 = 2.5 obd_timeout
879         # let's wait $((TIMEOUT * 3)) # bug 19887
880         local rc=0
881         wait_client_evicted ost1 $OST_NEXP $((TIMEOUT * 3)) || \
882                 error "Client was not evicted by ost" rc=1
883         wait_client_evicted $SINGLEMDS $MDS_NEXP $((TIMEOUT * 3)) || \
884                 error "Client was not evicted by mds"
885 }
886 run_test 26b "evict dead exports"
887
888 test_27() {
889         mkdir -p $DIR/$tdir
890         writemany -q -a $DIR/$tdir/$tfile 0 5 &
891         CLIENT_PID=$!
892         sleep 1
893         local save_FAILURE_MODE=$FAILURE_MODE
894         FAILURE_MODE="SOFT"
895         facet_failover $SINGLEMDS
896 #define OBD_FAIL_OSC_SHUTDOWN            0x407
897         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000407
898         # need to wait for reconnect
899         echo waiting for fail_loc
900         wait_update_facet $SINGLEMDS "lctl get_param -n fail_loc" "-2147482617"
901         facet_failover $SINGLEMDS
902         #no crashes allowed!
903         kill -USR1 $CLIENT_PID
904         wait $CLIENT_PID 
905         true
906         FAILURE_MODE=$save_FAILURE_MODE
907 }
908 run_test 27 "fail LOV while using OSC's"
909
910 test_28() {      # bug 6086 - error adding new clients
911         do_facet client mcreate $DIR/$tfile       || return 1
912         drop_bl_callback "chmod 0777 $DIR/$tfile" ||echo "evicted as expected"
913         #define OBD_FAIL_MDS_CLIENT_ADD 0x12f
914         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012f"
915         # fail once (evicted), reconnect fail (fail_loc), ok
916         client_up || (sleep 10; client_up) || (sleep 10; client_up) || error "reconnect failed"
917         rm -f $DIR/$tfile
918         fail $SINGLEMDS         # verify MDS last_rcvd can be loaded
919 }
920 run_test 28 "handle error adding new clients (bug 6086)"
921
922 test_29a() { # bug 22273 - error adding new clients
923         #define OBD_FAIL_TGT_CLIENT_ADD 0x711
924         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000711"
925         # fail abort so client will be new again
926         fail_abort $SINGLEMDS
927         client_up || error "reconnect failed"
928         wait_osc_import_state $SINGLEMDS ost FULL
929         return 0
930 }
931 run_test 29a "error adding new clients doesn't cause LBUG (bug 22273)"
932
933 test_29b() { # bug 22273 - error adding new clients
934         #define OBD_FAIL_TGT_CLIENT_ADD 0x711
935         do_facet ost1 "lctl set_param fail_loc=0x80000711"
936         # fail abort so client will be new again
937         fail_abort ost1
938         client_up || error "reconnect failed"
939         return 0
940 }
941 run_test 29b "error adding new clients doesn't cause LBUG (bug 22273)"
942
943 test_50() {
944         mkdir -p $DIR/$tdir
945         # put a load of file creates/writes/deletes
946         writemany -q $DIR/$tdir/$tfile 0 5 &
947         CLIENT_PID=$!
948         echo writemany pid $CLIENT_PID
949         sleep 10
950         FAILURE_MODE="SOFT"
951         fail $SINGLEMDS
952         # wait for client to reconnect to MDS
953         sleep 60
954         fail $SINGLEMDS
955         sleep 60
956         fail $SINGLEMDS
957         # client process should see no problems even though MDS went down
958         sleep $TIMEOUT
959         kill -USR1 $CLIENT_PID
960         wait $CLIENT_PID 
961         rc=$?
962         echo writemany returned $rc
963         #these may fail because of eviction due to slow AST response.
964         [ $rc -eq 0 ] || error_ignore 13652 "writemany returned rc $rc" || true
965 }
966 run_test 50 "failover MDS under load"
967
968 test_51() {
969         #define OBD_FAIL_MDS_SYNC_CAPA_SL                    0x1310
970         do_facet ost1 lctl set_param fail_loc=0x00001310
971
972         mkdir -p $DIR/$tdir
973         # put a load of file creates/writes/deletes
974         writemany -q $DIR/$tdir/$tfile 0 5 &
975         CLIENT_PID=$!
976         sleep 1
977         FAILURE_MODE="SOFT"
978         facet_failover $SINGLEMDS
979         # failover at various points during recovery
980         SEQ="1 5 10 $(seq $TIMEOUT 5 $(($TIMEOUT+10)))"
981         echo will failover at $SEQ
982         for i in $SEQ
983         do
984                 #echo failover in $i sec
985                 log "test_$testnum: failover in $i sec"
986                 sleep $i
987                 facet_failover $SINGLEMDS
988         done
989         # client process should see no problems even though MDS went down
990         # and recovery was interrupted
991         sleep $TIMEOUT
992         kill -USR1 $CLIENT_PID
993         wait $CLIENT_PID 
994         rc=$?
995         echo writemany returned $rc
996         [ $rc -eq 0 ] || error_ignore 13652 "writemany returned rc $rc" || true
997 }
998 run_test 51 "failover MDS during recovery"
999
1000 test_52_guts() {
1001         do_facet client "mkdir -p $DIR/$tdir"
1002         do_facet client "writemany -q -a $DIR/$tdir/$tfile 300 5" &
1003         CLIENT_PID=$!
1004         echo writemany pid $CLIENT_PID
1005         sleep 10
1006         FAILURE_MODE="SOFT"
1007         fail ost1
1008         rc=0
1009         wait $CLIENT_PID || rc=$?
1010         # active client process should see an EIO for down OST
1011         [ $rc -eq 5 ] && { echo "writemany correctly failed $rc" && return 0; }
1012         # but timing or failover setup may allow success
1013         [ $rc -eq 0 ] && { echo "writemany succeeded" && return 0; }
1014         echo "writemany returned $rc"
1015         return $rc
1016 }
1017
1018 test_52() {
1019         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1020
1021         mkdir -p $DIR/$tdir
1022         test_52_guts
1023         rc=$?
1024         [ $rc -ne 0 ] && { return $rc; }
1025         # wait for client to reconnect to OST
1026         sleep 30
1027         test_52_guts
1028         rc=$?
1029         [ $rc -ne 0 ] && { return $rc; }
1030         sleep 30
1031         test_52_guts
1032         rc=$?
1033         client_reconnect
1034         #return $rc
1035 }
1036 run_test 52 "failover OST under load"
1037
1038 # test of open reconstruct
1039 test_53() {
1040         touch $DIR/$tfile
1041         drop_ldlm_reply "openfile -f O_RDWR:O_CREAT -m 0755 $DIR/$tfile" ||\
1042                 return 2
1043 }
1044 run_test 53 "touch: drop rep"
1045
1046 test_54() {
1047         zconf_mount `hostname` $MOUNT2
1048         touch $DIR/$tfile
1049         touch $DIR2/$tfile.1
1050         sleep 10
1051         cat $DIR2/$tfile.missing # save transno = 0, rc != 0 into last_rcvd
1052         fail $SINGLEMDS
1053         umount $MOUNT2
1054         ERROR=`dmesg | egrep "(test 54|went back in time)" | tail -n1 | grep "went back in time"`
1055         [ x"$ERROR" == x ] || error "back in time occured"
1056 }
1057 run_test 54 "back in time"
1058
1059 # bug 11330 - liblustre application death during I/O locks up OST
1060 test_55() {
1061         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1062
1063         mkdir -p $DIR/$tdir
1064
1065         # Minimum pass speed is 2MBps
1066         local ddtimeout=64
1067         # LU-2887/LU-3089 - set min pass speed to 500KBps
1068         [ "$(facet_fstype ost1)" = "zfs" ] && ddtimeout=256
1069
1070         # first dd should be finished quickly
1071         $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile-1
1072         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=32M count=4 &
1073         DDPID=$!
1074         count=0
1075         echo  "step1: testing ......"
1076         while kill -0 $DDPID 2> /dev/null; do
1077                 let count++
1078                 if [ $count -gt $ddtimeout ]; then
1079                         error "dd should be finished!"
1080                 fi
1081                 sleep 1
1082         done
1083         echo "(dd_pid=$DDPID, time=$count)successful"
1084
1085         $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile-2
1086         #define OBD_FAIL_OST_DROP_REQ            0x21d
1087         do_facet ost1 lctl set_param fail_loc=0x0000021d
1088         # second dd will be never finished
1089         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=32M count=4 &
1090         DDPID=$!
1091         count=0
1092         echo  "step2: testing ......"
1093         while [ $count -le $ddtimeout ]; do
1094                 if ! kill -0 $DDPID 2> /dev/null; then
1095                         ls -l $DIR/$tdir
1096                         error "dd shouldn't be finished! (time=$count)"
1097                 fi
1098                 let count++
1099                 sleep 1
1100         done
1101         echo "(dd_pid=$DDPID, time=$count)successful"
1102
1103         #Recover fail_loc and dd will finish soon
1104         do_facet ost1 lctl set_param fail_loc=0
1105         count=0
1106         echo  "step3: testing ......"
1107         while kill -0 $DDPID 2> /dev/null; do
1108                 let count++
1109                 if [ $count -gt $((ddtimeout + 440)) ]; then
1110                         error "dd should be finished!"
1111                 fi
1112                 sleep 1
1113         done
1114         echo "(dd_pid=$DDPID, time=$count)successful"
1115
1116         rm -rf $DIR/$tdir
1117 }
1118 run_test 55 "ost_brw_read/write drops timed-out read/write request"
1119
1120 test_56() { # b=11277
1121 #define OBD_FAIL_MDS_RESEND      0x136
1122         touch $DIR/$tfile
1123         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000136"
1124         stat $DIR/$tfile
1125         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1126         rm -f $DIR/$tfile
1127 }
1128 run_test 56 "do not allow reconnect to busy exports"
1129
1130 test_57_helper() {
1131         # no oscs means no client or mdt 
1132         while lctl get_param osc.*.* > /dev/null 2>&1; do
1133                 : # loop until proc file is removed
1134         done
1135 }
1136
1137 test_57() { # bug 10866
1138         test_57_helper &
1139         pid=$!
1140         sleep 1
1141 #define OBD_FAIL_LPROC_REMOVE            0xB00
1142         lctl set_param fail_loc=0x80000B00
1143         zconf_umount `hostname` $DIR
1144         lctl set_param fail_loc=0x80000B00
1145         fail_abort $SINGLEMDS
1146         kill -9 $pid
1147         lctl set_param fail_loc=0
1148         mount_client $DIR
1149         do_facet client "df $DIR"
1150 }
1151 run_test 57 "read procfs entries causes kernel crash"
1152
1153 test_58() { # bug 11546
1154 #define OBD_FAIL_MDC_ENQUEUE_PAUSE        0x801
1155         touch $DIR/$tfile
1156         ls -la $DIR/$tfile
1157         lctl set_param fail_loc=0x80000801
1158         cp $DIR/$tfile /dev/null &
1159         pid=$!
1160         sleep 1
1161         lctl set_param fail_loc=0
1162         drop_bl_callback rm -f $DIR/$tfile
1163         wait $pid
1164         # the first 'df' could tigger the eviction caused by
1165         # 'drop_bl_callback', and it's normal case.
1166         # but the next 'df' should return successfully.
1167         do_facet client "df $DIR" || do_facet client "df $DIR"
1168 }
1169 run_test 58 "Eviction in the middle of open RPC reply processing"
1170
1171 test_59() { # bug 10589
1172         zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
1173         echo $DIR2 | grep -q $MOUNT2 || error "DIR2 is not set properly: $DIR2"
1174 #define OBD_FAIL_LDLM_CANCEL_EVICT_RACE  0x311
1175         lctl set_param fail_loc=0x311
1176         writes=$(LANG=C dd if=/dev/zero of=$DIR2/$tfile count=1 2>&1)
1177         [ $? = 0 ] || error "dd write failed"
1178         writes=$(echo $writes | awk  -F '+' '/out/ {print $1}')
1179         lctl set_param fail_loc=0
1180         sync
1181         zconf_umount `hostname` $MOUNT2 -f
1182         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1)
1183         [ $? = 0 ] || error "dd read failed"
1184         reads=$(echo $reads | awk -F '+' '/in/ {print $1}')
1185         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
1186 }
1187 run_test 59 "Read cancel race on client eviction"
1188
1189 err17935 () {
1190     # we assume that all md changes are in the MDT0 changelog
1191     if [ $MDSCOUNT -gt 1 ]; then
1192         error_ignore 17935 $*
1193     else
1194         error $*
1195     fi
1196 }
1197
1198 test_60() {
1199         MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
1200                 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
1201
1202         NUM_FILES=15000
1203         mkdir -p $DIR/$tdir
1204
1205         # Register (and start) changelog
1206         USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
1207         echo "Registered as $MDT0 changelog user $USER"
1208
1209         # Generate a large number of changelog entries
1210         createmany -o $DIR/$tdir/$tfile $NUM_FILES
1211         sync
1212         sleep 5
1213
1214         # Unlink files in the background
1215         unlinkmany $DIR/$tdir/$tfile $NUM_FILES &
1216         CLIENT_PID=$!
1217         sleep 1
1218
1219         # Failover the MDS while unlinks are happening
1220         facet_failover $SINGLEMDS
1221
1222         # Wait for unlinkmany to finish
1223         wait $CLIENT_PID
1224
1225         # Check if all the create/unlink events were recorded
1226         # in the changelog
1227         $LFS changelog $MDT0 >> $DIR/$tdir/changelog
1228         local cl_count=$(grep UNLNK $DIR/$tdir/changelog | wc -l)
1229         echo "$cl_count unlinks in $MDT0 changelog"
1230
1231         do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $USER
1232         USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
1233             mdd.$MDT0.changelog_users | wc -l) - 2 ))
1234         if [ $USERS -eq 0 ]; then
1235             [ $cl_count -eq $NUM_FILES ] || \
1236                 err17935 "Recorded ${cl_count} unlinks out of $NUM_FILES"
1237             # Also make sure we can clear large changelogs
1238             cl_count=$($LFS changelog $FSNAME | wc -l)
1239             [ $cl_count -le 2 ] || \
1240                 error "Changelog not empty: $cl_count entries"
1241         else
1242             # If there are other users, there may be other unlinks in the log
1243             [ $cl_count -ge $NUM_FILES ] || \
1244                 err17935 "Recorded ${cl_count} unlinks out of $NUM_FILES"
1245             echo "$USERS other changelog users; can't verify clear"
1246         fi
1247 }
1248 run_test 60 "Add Changelog entries during MDS failover"
1249
1250 test_61()
1251 {
1252         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1253         mdtosc=${mdtosc/-MDT*/-MDT\*}
1254         local cflags="osc.$mdtosc.connect_flags"
1255         do_facet $SINGLEMDS "lctl get_param -n $cflags" |grep -q skip_orphan
1256         [ $? -ne 0 ] && skip "don't have skip orphan feature" && return
1257
1258         mkdir -p $DIR/$tdir || error "mkdir dir $DIR/$tdir failed"
1259         # Set the default stripe of $DIR/$tdir to put the files to ost1
1260         $LFS setstripe -c 1 -i 0 $DIR/$tdir
1261
1262         replay_barrier $SINGLEMDS
1263         createmany -o $DIR/$tdir/$tfile-%d 10 
1264         local oid=`do_facet ost1 "lctl get_param -n obdfilter.${ost1_svc}.last_id"`
1265
1266         fail_abort $SINGLEMDS
1267         
1268         touch $DIR/$tdir/$tfile
1269         local id=`$LFS getstripe $DIR/$tdir/$tfile | awk '$1 == 0 { print $2 }'`
1270         [ $id -le $oid ] && error "the orphan objid was reused, failed"
1271
1272         # Cleanup
1273         rm -rf $DIR/$tdir
1274 }
1275 run_test 61 "Verify to not reuse orphan objects - bug 17025"
1276
1277 # test_62 as seen it b2_1 please do not reuse test_62
1278 #test_62()
1279 #{
1280 #       zconf_umount `hostname` $DIR
1281 #       #define OBD_FAIL_PTLRPC_DELAY_IMP_FULL   0x516
1282 #       lctl set_param fail_loc=0x516
1283 #       mount_client $DIR
1284 #}
1285 #run_test 62 "Verify connection flags race - bug LU-1716"
1286
1287 check_cli_ir_state()
1288 {
1289         local NODE=${1:-$HOSTNAME}
1290         local st
1291         st=$(do_node $NODE "lctl get_param mgc.*.ir_state |
1292                             awk '/imperative_recovery:/ { print \\\$2}'")
1293         [ $st != ON -o $st != OFF -o $st != ENABLED -o $st != DISABLED ] ||
1294                 error "Error state $st, must be ENABLED or DISABLED"
1295         echo -n $st
1296 }
1297
1298 check_target_ir_state()
1299 {
1300         local target=${1}
1301         local name=${target}_svc
1302         local recovery_proc=obdfilter.${!name}.recovery_status
1303         local st
1304
1305         st=$(do_facet $target "lctl get_param -n $recovery_proc |
1306                                awk '/IR:/{ print \\\$2}'")
1307         [ $st != ON -o $st != OFF -o $st != ENABLED -o $st != DISABLED ] ||
1308                 error "Error state $st, must be ENABLED or DISABLED"
1309         echo -n $st
1310 }
1311
1312 set_ir_status()
1313 {
1314         do_facet mgs lctl set_param -n mgs.MGS.live.$FSNAME="state=$1"
1315 }
1316
1317 get_ir_status()
1318 {
1319         local state=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
1320                                     awk '/state:/{ print \\\$2 }'")
1321         echo -n ${state/,/}
1322 }
1323
1324 nidtbl_version_mgs()
1325 {
1326         local ver=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
1327                                   awk '/nidtbl_version:/{ print \\\$2 }'")
1328         echo -n $ver
1329 }
1330
1331 # nidtbl_version_client <mds1|client> [node]
1332 nidtbl_version_client()
1333 {
1334         local cli=$1
1335         local node=${2:-$HOSTNAME}
1336
1337         if [ X$cli = Xclient ]; then
1338                 cli=$FSNAME-client
1339         else
1340                 local obdtype=${cli/%[0-9]*/}
1341                 [ $obdtype != mds ] && error "wrong parameters $cli"
1342
1343                 node=$(facet_active_host $cli)
1344                 local t=${cli}_svc
1345                 cli=${!t}
1346         fi
1347
1348         local vers=$(do_node $node "lctl get_param -n mgc.*.ir_state" |
1349                      awk "/$cli/{print \$6}" |sort -u)
1350
1351         # in case there are multiple mounts on the client node
1352         local arr=($vers)
1353         [ ${#arr[@]} -ne 1 ] && error "versions on client node mismatch"
1354         echo -n $vers
1355 }
1356
1357 nidtbl_versions_match()
1358 {
1359         [ $(nidtbl_version_mgs) -eq $(nidtbl_version_client ${1:-client}) ]
1360 }
1361
1362 target_instance_match()
1363 {
1364         local srv=$1
1365         local obdtype
1366         local cliname
1367
1368         obdtype=${srv/%[0-9]*/}
1369         case $obdtype in
1370         mds)
1371                 obdname="mdt"
1372                 cliname="mdc"
1373                 ;;
1374         ost)
1375                 obdname="obdfilter"
1376                 cliname="osc"
1377                 ;;
1378         *)
1379                 error "invalid target type" $srv
1380                 return 1
1381                 ;;
1382         esac
1383
1384         local target=${srv}_svc
1385         local si=$(do_facet $srv lctl get_param -n $obdname.${!target}.instance)
1386         local ci=$(lctl get_param -n $cliname.${!target}-${cliname}-*.import |
1387                 awk '/instance/{ print $2 }' | head -n1)
1388
1389         return $([ $si -eq $ci ])
1390 }
1391
1392 test_100()
1393 {
1394         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1395                 { skip "MGS without IR support"; return 0; }
1396
1397         # MDT was just restarted in the previous test, make sure everything
1398         # is all set.
1399         local cnt=30
1400         while [ $cnt -gt 0 ]; do
1401                 nidtbl_versions_match && break
1402                 sleep 1
1403                 cnt=$((cnt - 1))
1404         done
1405
1406         # disable IR
1407         set_ir_status disabled
1408
1409         local prev_ver=$(nidtbl_version_client client)
1410
1411         local saved_FAILURE_MODE=$FAILURE_MODE
1412         [ $(facet_host mgs) = $(facet_host ost1) ] && FAILURE_MODE="SOFT"
1413         fail ost1
1414
1415         # valid check
1416         [ $(nidtbl_version_client client) -eq $prev_ver ] ||
1417                 error "version must not change due to IR disabled"
1418         target_instance_match ost1 || error "instance mismatch"
1419
1420         # restore env
1421         set_ir_status full
1422         FAILURE_MODE=$saved_FAILURE_MODE
1423 }
1424 run_test 100 "IR: Make sure normal recovery still works w/o IR"
1425
1426 test_101()
1427 {
1428         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1429                 { skip "MGS without IR support"; return 0; }
1430
1431         set_ir_status full
1432
1433         local OST1_IMP=$(get_osc_import_name client ost1)
1434
1435         # disable pinger recovery
1436         lctl set_param -n osc.$OST1_IMP.pinger_recov=0
1437
1438         fail ost1
1439
1440         target_instance_match ost1 || error "instance mismatch"
1441         nidtbl_versions_match || error "version must match"
1442
1443         lctl set_param -n osc.$OST1_IMP.pinger_recov=1
1444 }
1445 run_test 101 "IR: Make sure IR works w/o normal recovery"
1446
1447 test_102()
1448 {
1449         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1450                 { skip "MGS without IR support"; return 0; }
1451
1452         local clients=${CLIENTS:-$HOSTNAME}
1453         local old_version
1454         local new_version
1455         local mgsdev=mgs
1456
1457         set_ir_status full
1458
1459         # let's have a new nidtbl version
1460         fail ost1
1461
1462         # sleep for a while so that clients can see the failure of ost
1463         # it must be MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC.
1464         # int mgc_request.c:
1465         # define MGC_TIMEOUT_MIN_SECONDS   5
1466         # define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 *
1467         local count=30  # 20 seconds at most
1468         while [ $count -gt 0 ]; do
1469                 nidtbl_versions_match && break
1470                 sleep 1
1471                 count=$((count-1))
1472         done
1473
1474         nidtbl_versions_match || error "nidtbl mismatch"
1475
1476         # get the version #
1477         old_version=$(nidtbl_version_client client)
1478
1479         zconf_umount_clients $clients $MOUNT || error "Cannot umount client"
1480
1481         # restart mgs
1482         combined_mgs_mds && mgsdev=mds1
1483         remount_facet $mgsdev
1484         fail ost1
1485
1486         zconf_mount_clients $clients $MOUNT || error "Cannot mount client"
1487
1488         # check new version
1489         new_version=$(nidtbl_version_client client)
1490         [ $new_version -lt $old_version ] &&
1491                 error "nidtbl version wrong after mgs restarts"
1492         return 0
1493 }
1494 run_test 102 "IR: New client gets updated nidtbl after MGS restart"
1495
1496 test_103()
1497 {
1498         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1499                 { skip "MGS without IR support"; return 0; }
1500
1501         combined_mgs_mds && skip "mgs and mds on the same target" && return 0
1502
1503         # workaround solution to generate config log on the mds
1504         remount_facet mds1
1505
1506         stop mgs
1507         stop mds1
1508
1509         # We need this test because mds is like a client in IR context.
1510         start mds1 $MDSDEV1 || error "MDS should start w/o mgs"
1511
1512         # start mgs and remount mds w/ ir
1513         start mgs $MGSDEV
1514         clients_up
1515
1516         # remount client so that fsdb will be created on the MGS
1517         umount_client $MOUNT || error "umount failed"
1518         mount_client $MOUNT || error "mount failed"
1519
1520         # sleep 30 seconds so the MDS has a chance to detect MGS restarting
1521         local count=30
1522         while [ $count -gt 0 ]; do
1523                 [ $(nidtbl_version_client mds1) -ne 0 ] && break
1524                 sleep 1
1525                 count=$((count-1))
1526         done
1527
1528         # after a while, mds should be able to reconnect to mgs and fetch
1529         # up-to-date nidtbl version
1530         nidtbl_versions_match mds1 || error "mds nidtbl mismatch"
1531
1532         # reset everything
1533         set_ir_status full
1534 }
1535 run_test 103 "IR: MDS can start w/o MGS and get updated nidtbl later"
1536
1537 test_104()
1538 {
1539         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1540                 { skip "MGS without IR support"; return 0; }
1541
1542         set_ir_status full
1543
1544         stop ost1
1545         start ost1 $(ostdevname 1) "$OST_MOUNT_OPTS -onoir" ||
1546                 error "OST1 cannot start"
1547         clients_up
1548
1549         local ir_state=$(check_target_ir_state ost1)
1550         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1551                 error "ir status on ost1 should be DISABLED"
1552 }
1553 run_test 104 "IR: ost can disable IR voluntarily"
1554
1555 test_105()
1556 {
1557         [ -z "$RCLIENTS" ] && skip "Needs multiple clients" && return 0
1558         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1559                 { skip "MGS without IR support"; return 0; }
1560
1561         set_ir_status full
1562
1563         # get one of the clients from client list
1564         local rcli=$(echo $RCLIENTS |cut -d' ' -f 1)
1565
1566         local old_MOUNTOPT=$MOUNTOPT
1567         MOUNTOPT=${MOUNTOPT},noir
1568         zconf_umount $rcli $MOUNT || error "umount failed"
1569         zconf_mount $rcli $MOUNT || error "mount failed"
1570
1571         # make sure lustre mount at $rcli disabling IR
1572         local ir_state=$(check_cli_ir_state $rcli)
1573         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1574                 error "IR state must be DISABLED at $rcli"
1575
1576         # Since the client just mounted, its last_rcvd entry is not on disk.
1577         # Send an RPC so exp_need_sync forces last_rcvd to commit this export
1578         # so the client can reconnect during OST recovery (LU-924, LU-1582)
1579         $SETSTRIPE -i 0 $DIR/$tfile
1580         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 conv=sync
1581
1582         # make sure MGS's state is Partial
1583         [ $(get_ir_status) = "partial" ] || error "MGS IR state must be partial"
1584
1585         fail ost1
1586         # make sure IR on ost1 is DISABLED
1587         local ir_state=$(check_target_ir_state ost1)
1588         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1589                 error "IR status on ost1 should be DISABLED"
1590
1591         # restore it
1592         MOUNTOPT=$old_MOUNTOPT
1593         zconf_umount $rcli $MOUNT || error "umount failed"
1594         zconf_mount $rcli $MOUNT || error "mount failed"
1595
1596         # make sure MGS's state is full
1597         [ $(get_ir_status) = "full" ] || error "MGS IR status must be full"
1598
1599         fail ost1
1600         # make sure IR on ost1 is ENABLED
1601         local ir_state=$(check_target_ir_state ost1)
1602         [ $ir_state = "ENABLED" -o $ir_state = "ON" ] ||
1603                 error "IR status on ost1 should be ENABLED"
1604
1605         return 0
1606 }
1607 run_test 105 "IR: NON IR clients support"
1608
1609 cleanup_106() {
1610         trap 0
1611         umount_client $DIR2
1612         debugrestore
1613 }
1614
1615 test_106() { # LU-1789
1616         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.50) ]] ||
1617                 { skip "Need MDS version at least 2.3.50"; return 0; }
1618
1619 #define OBD_FAIL_MDC_LIGHTWEIGHT         0x805
1620         $LCTL set_param fail_loc=0x805
1621
1622         debugsave
1623         trap cleanup_106 EXIT
1624
1625         # enable lightweight flag on mdc connection
1626         mount_client $DIR2
1627
1628         local MDS_NEXP=$(do_facet $SINGLEMDS \
1629                          lctl get_param -n mdt.${mds1_svc}.num_exports |
1630                          cut -d' ' -f2)
1631         $LCTL set_param fail_loc=0
1632
1633         touch $DIR2/$tfile || error "failed to create empty file"
1634         replay_barrier $SINGLEMDS
1635
1636         $LCTL set_param debug=console
1637         $LCTL clear
1638         facet_failover $SINGLEMDS
1639
1640         # lightweight connection must be evicted
1641         touch -c $DIR2/$tfile || true
1642         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1643         evicted=`awk '/This client was evicted by .*MDT0000/ {
1644                                       print;
1645                       }' $TMP/lustre-log-$TESTNAME.log`
1646         [ -z "$evicted" ] && error "lightweight client not evicted by mds"
1647
1648         # and all operations performed by lightweight client should be
1649         # synchronous, so the file created before mds restart should be there
1650         $CHECKSTAT -t file $DIR/$tfile || error "file not present"
1651         rm -f $DIR/$tfile
1652
1653         cleanup_106
1654 }
1655 run_test 106 "lightweight connection support"
1656
1657 test_107 () {
1658         local CLIENT_PID
1659         local close_pid
1660
1661         mkdir -p $DIR/$tdir
1662         # OBD_FAIL_MDS_REINT_NET_REP   0x119
1663         do_facet $SINGLEMDS lctl set_param fail_loc=0x119
1664         multiop $DIR/$tdir D_c &
1665         close_pid=$!
1666         mkdir $DIR/$tdir/dir_106 &
1667         CLIENT_PID=$!
1668         do_facet $SINGLEMDS lctl set_param fail_loc=0
1669         fail $SINGLEMDS
1670
1671         wait $CLIENT_PID || rc=$?
1672         checkstat -t dir $DIR/$tdir/dir_106 || return 1
1673
1674         kill -USR1 $close_pid
1675         wait $close_pid || return 2
1676
1677         return $rc
1678 }
1679 run_test 107 "drop reint reply, then restart MDT"
1680
1681 test_110a () {
1682         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1683         local remote_dir=$DIR/$tdir/remote_dir
1684         local MDTIDX=1
1685
1686         mkdir -p $DIR/$tdir
1687         drop_request "$LFS mkdir -i $MDTIDX $remote_dir" ||
1688                                         error "lfs mkdir failed"
1689         local diridx=$($GETSTRIPE -M $remote_dir)
1690         [ $diridx -eq $MDTIDX ] || error "$diridx != $MDTIDX"
1691
1692         rm -rf $DIR/$tdir || error "rmdir failed"
1693 }
1694 run_test 110a "create remote directory: drop client req"
1695
1696 test_110b () {
1697         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1698         local remote_dir=$DIR/$tdir/remote_dir
1699         local MDTIDX=1
1700
1701         mkdir -p $DIR/$tdir
1702         drop_reint_reply "$LFS mkdir -i $MDTIDX $remote_dir" ||
1703                                         error "lfs mkdir failed"
1704
1705         diridx=$($GETSTRIPE -M $remote_dir)
1706         [ $diridx -eq $MDTIDX ] || error "$diridx != $MDTIDX"
1707
1708         rm -rf $DIR/$tdir || error "rmdir failed"
1709 }
1710 run_test 110b "create remote directory: drop Master rep"
1711
1712 test_110c () {
1713         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1714         local remote_dir=$DIR/$tdir/remote_dir
1715         local MDTIDX=1
1716
1717         mkdir -p $DIR/$tdir
1718         drop_update_reply $((MDTIDX + 1)) "$LFS mkdir -i $MDTIDX $remote_dir" ||
1719                                                 error "lfs mkdir failed"
1720
1721         diridx=$($GETSTRIPE -M $remote_dir)
1722         [ $diridx -eq $MDTIDX ] || error "$diridx != $MDTIDX"
1723
1724         rm -rf $DIR/$tdir || error "rmdir failed"
1725 }
1726 run_test 110c "create remote directory: drop update rep on slave MDT"
1727
1728 test_110d () {
1729         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1730         local remote_dir=$DIR/$tdir/remote_dir
1731         local MDTIDX=1
1732
1733         mkdir -p $DIR/$tdir
1734         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
1735
1736         drop_request "rm -rf $remote_dir" || error "rm remote dir failed"
1737
1738         rm -rf $DIR/$tdir || error "rmdir failed"
1739
1740         return 0
1741 }
1742 run_test 110d "remove remote directory: drop client req"
1743
1744 test_110e () {
1745         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1746         local remote_dir=$DIR/$tdir/remote_dir
1747         local MDTIDX=1
1748
1749         mkdir -p $DIR/$tdir
1750         $LFS mkdir -i $MDTIDX $remote_dir  || error "lfs mkdir failed"
1751         drop_reint_reply "rm -rf $remote_dir" || error "rm remote dir failed"
1752
1753         rm -rf $DIR/$tdir || error "rmdir failed"
1754
1755         return 0
1756 }
1757 run_test 110e "remove remote directory: drop master rep"
1758
1759 test_110f () {
1760         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1761         local remote_dir=$DIR/$tdir/remote_dir
1762         local MDTIDX=1
1763
1764         mkdir -p $DIR/$tdir
1765         $LFS mkdir -i $MDTIDX $remote_dir || error "lfs mkdir failed"
1766         drop_update_reply $MDTIDX "rm -rf $remote_dir" ||
1767                                         error "rm remote dir failed"
1768
1769         rm -rf $DIR/$tdir || error "rmdir failed"
1770 }
1771 run_test 110f "remove remote directory: drop slave rep"
1772
1773 # LU-2844 mdt prepare fail should not cause umount oops
1774 test_111 ()
1775 {
1776         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.62) ]] ||
1777                 { skip "Need MDS version at least 2.3.62"; return 0; }
1778
1779         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
1780 #define OBD_FAIL_MDS_CHANGELOG_INIT 0x151
1781         do_facet $SINGLEMDS lctl set_param fail_loc=0x151
1782         stop $SINGLEMDS || error "stop MDS failed"
1783         start $SINGLEMDS $mdsdev && error "start MDS should fail"
1784         do_facet $SINGLEMDS lctl set_param fail_loc=0
1785         start $SINGLEMDS $mdsdev || error "start MDS failed"
1786 }
1787 run_test 111 "mdd setup fail should not cause umount oops"
1788
1789 complete $SECONDS
1790 check_and_cleanup_lustre
1791 exit_status