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