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