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