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