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