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