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