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