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