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