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