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