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