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