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