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