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