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