Whamcloud - gitweb
LU-12672 tests: Correctly determine mdccli in recovery-small test 66
[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         [[ "$MDS1_VERSION" -lt $(version_code 2.6.53) ]] &&
177                 skip "Need MDS version at least 2.6.53"
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         [[ "$MDS1_VERSION" -lt $(version_code 2.6.90) ]] &&
249                 skip "Need MDS version at least 2.6.90"
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         [[ "$OST1_VERSION" -le $(version_code 2.8.58) ]] &&
290                 skip "Need OST version at least 2.8.59"
291         [ $CLIENTCOUNT -lt 2 ] && skip "need two clients"
292         [ $(facet_host client) == $(facet_host ost1) ] &&
293                 skip "need ost1 and client on different nodes"
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         [ "$ost1_FSTYPE" = 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         [[ "$MDS1_VERSION" -ge $(version_code 2.7.51) ]] ||
1569                 skip "Need MDS version at least 2.7.51"
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 mdtname="MDT0000"
1587         local mdccli=$($LCTL dl | grep "${mdtname}-mdc" | awk '{print $4;}')
1588         local conn_uuid=$($LCTL get_param -n mdc.${mdccli}.conn_uuid)
1589         $LCTL set_param "mdc.${mdccli}.import=connection=${conn_uuid}"
1590         sleep 2
1591
1592         #initiate the client eviction while enqueue re-send is in progress
1593         mds_evict_client
1594
1595         client_reconnect
1596         wait
1597 }
1598 run_test 66 "lock enqueue re-send vs client eviction"
1599
1600 test_67()
1601 {
1602 #define OBD_FAIL_PTLRPC_CONNECT_RACE     0x531
1603         $LCTL set_param fail_loc=0x80000531
1604
1605         local mdtname="MDT0000"
1606         local mdccli=$($LCTL dl | grep "${mdtname}-mdc" | awk '{print $4;}')
1607         local conn_uuid=$($LCTL get_param -n mdc.${mdccli}.mds_conn_uuid)
1608         $LCTL set_param "mdc.${mdccli}.import=connection=${conn_uuid}" &
1609         sleep 2
1610
1611         mds_evict_client
1612         sleep 1
1613
1614         client_reconnect
1615         wait
1616 }
1617 run_test 67 "connect vs import invalidate race"
1618
1619 check_cli_ir_state()
1620 {
1621         local NODE=${1:-$HOSTNAME}
1622         local st
1623         st=$(do_node $NODE "lctl get_param mgc.*.ir_state |
1624                             awk '/imperative_recovery:/ { print \\\$2}'")
1625         [ $st != ON -o $st != OFF -o $st != ENABLED -o $st != DISABLED ] ||
1626                 error "Error state $st, must be ENABLED or DISABLED"
1627         echo -n $st
1628 }
1629
1630 check_target_ir_state()
1631 {
1632         local target=${1}
1633         local name=${target}_svc
1634         local recovery_proc=obdfilter.${!name}.recovery_status
1635         local st
1636
1637         while : ; do
1638                 st=$(do_facet $target "$LCTL get_param -n $recovery_proc |
1639                         awk '/status:/{ print \\\$2}'")
1640                 [ x$st = xRECOVERING ] || break
1641         done
1642         st=$(do_facet $target "lctl get_param -n $recovery_proc |
1643                                awk '/IR:/{ print \\\$2}'")
1644         [ $st != ON -o $st != OFF -o $st != ENABLED -o $st != DISABLED ] ||
1645                 error "Error state $st, must be ENABLED or DISABLED"
1646         echo -n $st
1647 }
1648
1649 set_ir_status()
1650 {
1651         do_facet mgs lctl set_param -n mgs.MGS.live.$FSNAME="state=$1"
1652 }
1653
1654 get_ir_status()
1655 {
1656         local state=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
1657                                     awk '/state:/{ print \\\$2 }'")
1658         echo -n ${state/,/}
1659 }
1660
1661 nidtbl_version_mgs()
1662 {
1663         local ver=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
1664                                   awk '/nidtbl_version:/{ print \\\$2 }'")
1665         echo -n $ver
1666 }
1667
1668 # nidtbl_version_client <mds1|client> [node]
1669 nidtbl_version_client()
1670 {
1671         local cli=$1
1672         local node=${2:-$HOSTNAME}
1673
1674         if [ X$cli = Xclient ]; then
1675                 cli=$FSNAME-client
1676         else
1677                 local obdtype=${cli/%[0-9]*/}
1678                 [ $obdtype != mds ] && error "wrong parameters $cli"
1679
1680                 node=$(facet_active_host $cli)
1681                 local t=${cli}_svc
1682                 cli=${!t}
1683         fi
1684
1685         local vers=$(do_node $node "lctl get_param -n mgc.*.ir_state" |
1686                      awk "/$cli/{print \$6}" |sort -u)
1687
1688         # in case there are multiple mounts on the client node
1689         local arr=($vers)
1690         [ ${#arr[@]} -ne 1 ] && error "versions on client node mismatch"
1691         echo -n $vers
1692 }
1693
1694 nidtbl_versions_match()
1695 {
1696         [ $(nidtbl_version_mgs) -eq $(nidtbl_version_client ${1:-client}) ]
1697 }
1698
1699 target_instance_match()
1700 {
1701         local srv=$1
1702         local obdtype
1703         local cliname
1704
1705         obdtype=${srv/%[0-9]*/}
1706         case $obdtype in
1707         mds)
1708                 obdname="mdt"
1709                 cliname="mdc"
1710                 ;;
1711         ost)
1712                 obdname="obdfilter"
1713                 cliname="osc"
1714                 ;;
1715         *)
1716                 error "invalid target type" $srv
1717                 return 1
1718                 ;;
1719         esac
1720
1721         local target=${srv}_svc
1722         local si=$(do_facet $srv lctl get_param -n $obdname.${!target}.instance)
1723         local ci=$(lctl get_param -n $cliname.${!target}-${cliname}-*.import |
1724                 awk '/instance/{ print $2 }' | head -n1)
1725
1726         return $([ $si -eq $ci ])
1727 }
1728
1729 test_100()
1730 {
1731         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1732                 { skip "MGS without IR support"; return 0; }
1733
1734         # MDT was just restarted in the previous test, make sure everything
1735         # is all set.
1736         local cnt=30
1737         while [ $cnt -gt 0 ]; do
1738                 nidtbl_versions_match && break
1739                 sleep 1
1740                 cnt=$((cnt - 1))
1741         done
1742
1743         # disable IR
1744         set_ir_status disabled
1745
1746         local prev_ver=$(nidtbl_version_client client)
1747
1748         local saved_FAILURE_MODE=$FAILURE_MODE
1749         [ $(facet_host mgs) = $(facet_host ost1) ] && FAILURE_MODE="SOFT"
1750         fail ost1
1751
1752         # valid check
1753         [ $(nidtbl_version_client client) -eq $prev_ver ] ||
1754                 error "version must not change due to IR disabled"
1755         target_instance_match ost1 || error "instance mismatch"
1756
1757         # restore env
1758         set_ir_status full
1759         FAILURE_MODE=$saved_FAILURE_MODE
1760 }
1761 run_test 100 "IR: Make sure normal recovery still works w/o IR"
1762
1763 test_101a()
1764 {
1765         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1766                 skip "MGS without IR support"
1767
1768         set_ir_status full
1769
1770         local ost1_imp=$(get_osc_import_name client ost1)
1771
1772         # disable pinger recovery
1773         lctl set_param -n osc.$ost1_imp.pinger_recov=0
1774         stack_trap "$LCTL set_param -n osc.$ost1_imp.pinger_recov=1" EXIT
1775
1776         fail ost1
1777
1778         target_instance_match ost1 || error "instance mismatch"
1779         nidtbl_versions_match || error "version must match"
1780 }
1781 run_test 101a "IR: Make sure IR works w/o normal recovery"
1782
1783 test_101b()
1784 {
1785         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1786                 skip "MGS without IR support"
1787
1788         set_ir_status full
1789
1790         local ost1_imp=$(get_osc_import_name client ost1)
1791
1792 #define OBD_FAIL_OST_PREPARE_DELAY       0x247
1793         do_facet ost1 "$LCTL set_param fail_loc=0x247"
1794         # disable pinger recovery
1795         $LCTL set_param -n osc.$ost1_imp.pinger_recov=0
1796         stack_trap "$LCTL set_param -n osc.$ost1_imp.pinger_recov=1" EXIT
1797
1798 #OST may return EAGAIN if it is not configured yet
1799         fail ost1
1800 }
1801 run_test 101b "IR: Make sure IR works w/o normal recovery and proceed EAGAIN"
1802
1803 test_102()
1804 {
1805         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1806                 { skip "MGS without IR support"; return 0; }
1807
1808         local clients=${CLIENTS:-$HOSTNAME}
1809         local old_version
1810         local new_version
1811         local mgsdev=mgs
1812
1813         set_ir_status full
1814
1815         # let's have a new nidtbl version
1816         fail ost1
1817
1818         # sleep for a while so that clients can see the failure of ost
1819         # it must be MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC.
1820         # int mgc_request.c:
1821         # define MGC_TIMEOUT_MIN_SECONDS   5
1822         # define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 *
1823         local count=30  # 20 seconds at most
1824         while [ $count -gt 0 ]; do
1825                 nidtbl_versions_match && break
1826                 sleep 1
1827                 count=$((count-1))
1828         done
1829
1830         nidtbl_versions_match || error "nidtbl mismatch"
1831
1832         # get the version #
1833         old_version=$(nidtbl_version_client client)
1834
1835         zconf_umount_clients $clients $MOUNT || error "Cannot umount client"
1836
1837         # restart mgs
1838         combined_mgs_mds && mgsdev=mds1
1839         remount_facet $mgsdev
1840         fail ost1
1841
1842         zconf_mount_clients $clients $MOUNT || error "Cannot mount client"
1843
1844         # check new version
1845         new_version=$(nidtbl_version_client client)
1846         [ $new_version -lt $old_version ] &&
1847                 error "nidtbl version wrong after mgs restarts"
1848         return 0
1849 }
1850 run_test 102 "IR: New client gets updated nidtbl after MGS restart"
1851
1852 test_103()
1853 {
1854         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1855                 { skip "MGS without IR support"; return 0; }
1856
1857         combined_mgs_mds && skip "needs separate mgs and mds" && return 0
1858
1859         # workaround solution to generate config log on the mds
1860         remount_facet mds1
1861
1862         stop mgs
1863         stop mds1
1864
1865         # We need this test because mds is like a client in IR context.
1866         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS ||
1867                 error "MDS should start w/o mgs"
1868
1869         # start mgs and remount mds w/ ir
1870         start mgs $(mgsdevname) $MGS_MOUNT_OPTS
1871         clients_up
1872
1873         # remount client so that fsdb will be created on the MGS
1874         umount_client $MOUNT || error "umount failed"
1875         mount_client $MOUNT || error "mount failed"
1876
1877         # sleep 30 seconds so the MDS has a chance to detect MGS restarting
1878         local count=30
1879         while [ $count -gt 0 ]; do
1880                 [ $(nidtbl_version_client mds1) -ne 0 ] && break
1881                 sleep 1
1882                 count=$((count-1))
1883         done
1884
1885         # after a while, mds should be able to reconnect to mgs and fetch
1886         # up-to-date nidtbl version
1887         nidtbl_versions_match mds1 || error "mds nidtbl mismatch"
1888
1889         # reset everything
1890         set_ir_status full
1891 }
1892 run_test 103 "IR: MDS can start w/o MGS and get updated nidtbl later"
1893
1894 test_104()
1895 {
1896         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1897                 { skip "MGS without IR support"; return 0; }
1898
1899         set_ir_status full
1900
1901         stop ost1
1902         start ost1 $(ostdevname 1) "$OST_MOUNT_OPTS -onoir" ||
1903                 error "OST1 cannot start"
1904         clients_up
1905
1906         local ir_state=$(check_target_ir_state ost1)
1907         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1908                 error "ir status on ost1 should be DISABLED"
1909 }
1910 run_test 104 "IR: ost can disable IR voluntarily"
1911
1912 test_105()
1913 {
1914         [ -z "$RCLIENTS" ] && skip "Needs multiple clients" && return 0
1915         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1916                 { skip "MGS without IR support"; return 0; }
1917
1918         set_ir_status full
1919
1920         # get one of the clients from client list
1921         local rcli=$(echo $RCLIENTS |cut -d' ' -f 1)
1922
1923         local mount_opts=${MOUNT_OPTS:+$MOUNT_OPTS,}noir
1924         zconf_umount $rcli $MOUNT || error "umount failed"
1925         zconf_mount $rcli $MOUNT $mount_opts || error "mount failed"
1926
1927         # make sure lustre mount at $rcli disabling IR
1928         local ir_state=$(check_cli_ir_state $rcli)
1929         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1930                 error "IR state must be DISABLED at $rcli"
1931
1932         # Since the client just mounted, its last_rcvd entry is not on disk.
1933         # Send an RPC so exp_need_sync forces last_rcvd to commit this export
1934         # so the client can reconnect during OST recovery (LU-924, LU-1582)
1935         $SETSTRIPE -i 0 $DIR/$tfile
1936         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 conv=sync
1937
1938         # make sure MGS's state is Partial
1939         [ $(get_ir_status) = "partial" ] || error "MGS IR state must be partial"
1940
1941         fail ost1
1942         # make sure IR on ost1 is DISABLED
1943         local ir_state=$(check_target_ir_state ost1)
1944         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1945                 error "IR status on ost1 should be DISABLED"
1946
1947         # remount with the default MOUNT_OPTS
1948         zconf_umount $rcli $MOUNT || error "umount failed"
1949         zconf_mount $rcli $MOUNT || error "mount failed"
1950
1951         # make sure MGS's state is full
1952         [ $(get_ir_status) = "full" ] || error "MGS IR status must be full"
1953
1954         fail ost1
1955         # make sure IR on ost1 is ENABLED
1956         local ir_state=$(check_target_ir_state ost1)
1957         [ $ir_state = "ENABLED" -o $ir_state = "ON" ] ||
1958                 error "IR status on ost1 should be ENABLED"
1959
1960         return 0
1961 }
1962 run_test 105 "IR: NON IR clients support"
1963
1964 cleanup_106() {
1965         trap 0
1966         umount_client $DIR2
1967         debugrestore
1968 }
1969
1970 test_106() { # LU-1789
1971         [[ "$MDS1_VERSION" -ge $(version_code 2.3.50) ]] ||
1972                 skip "Need MDS version at least 2.3.50"
1973
1974 #define OBD_FAIL_MDC_LIGHTWEIGHT         0x805
1975         $LCTL set_param fail_loc=0x805
1976
1977         debugsave
1978         trap cleanup_106 EXIT
1979
1980         # enable lightweight flag on mdc connection
1981         mount_client $DIR2
1982
1983         local MDS_NEXP=$(do_facet $SINGLEMDS \
1984                          lctl get_param -n mdt.${mds1_svc}.num_exports |
1985                          cut -d' ' -f2)
1986         $LCTL set_param fail_loc=0
1987
1988         touch $DIR2/$tfile || error "failed to create empty file"
1989         replay_barrier $SINGLEMDS
1990
1991         $LCTL set_param debug=ha
1992         $LCTL clear
1993         facet_failover $SINGLEMDS
1994
1995         # lightweight goes through LUSTRE_IMP_RECOVER during failover
1996         touch -c $DIR2/$tfile || true
1997         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1998         recovered=$(awk '/MDT0000-mdc-[0-9a-f]*. lwp recover/ { print }' \
1999                     $TMP/lustre-log-$TESTNAME.log)
2000         [ -z "$recovered" ] && error "lightweight client was not recovered"
2001
2002         # and all operations performed by lightweight client should be
2003         # synchronous, so the file created before mds restart should be there
2004         $CHECKSTAT -t file $DIR/$tfile || error "file not present"
2005         rm -f $DIR/$tfile
2006
2007         cleanup_106
2008 }
2009 run_test 106 "lightweight connection support"
2010
2011 test_107 () {
2012         local CLIENT_PID
2013         local close_pid
2014
2015         mkdir -p $DIR/$tdir
2016         # OBD_FAIL_MDS_REINT_NET_REP   0x119
2017         do_facet $SINGLEMDS lctl set_param fail_loc=0x119
2018         multiop $DIR/$tdir D_c &
2019         close_pid=$!
2020         mkdir $DIR/$tdir/dir_106 &
2021         CLIENT_PID=$!
2022         do_facet $SINGLEMDS lctl set_param fail_loc=0
2023         fail $SINGLEMDS
2024
2025         wait $CLIENT_PID || rc=$?
2026         checkstat -t dir $DIR/$tdir/dir_106 || return 1
2027
2028         kill -USR1 $close_pid
2029         wait $close_pid || return 2
2030
2031         return $rc
2032 }
2033 run_test 107 "drop reint reply, then restart MDT"
2034
2035 test_108() {
2036         mkdir -p $DIR/$tdir
2037         $SETSTRIPE -c 1 -i 0 $DIR/$tdir
2038
2039         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=256 &
2040         local dd_pid=$!
2041         sleep 0.1
2042
2043         ost_evict_client
2044
2045         wait $dd_pid
2046
2047         client_up || error "reconnect failed"
2048         rm -f $DIR/$tdir/$tfile
2049 }
2050 run_test 108 "client eviction don't crash"
2051
2052 test_110a () {
2053         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2054         local remote_dir=$DIR/$tdir/remote_dir
2055         local mdtidx=1
2056         local num
2057
2058         #prepare for 110 test, which need set striped dir on remote MDT.
2059         for num in $(seq $MDSCOUNT); do
2060                 do_facet mds$num \
2061                         lctl set_param -n mdt.$FSNAME*.enable_remote_dir=1 \
2062                                 2>/dev/null
2063         done
2064
2065         mkdir -p $DIR/$tdir
2066         drop_request "$LFS mkdir -i $mdtidx -c2 $remote_dir" ||
2067                 error "lfs mkdir failed"
2068         local diridx=$($LFS getstripe -m $remote_dir)
2069         [ $diridx -eq $mdtidx ] || error "$diridx != $mdtidx"
2070
2071         rm -rf $DIR/$tdir || error "rmdir failed"
2072 }
2073 run_test 110a "create remote directory: drop client req"
2074
2075 test_110b () {
2076         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2077         local remote_dir=$DIR/$tdir/remote_dir
2078         local mdtidx=1
2079
2080         mkdir -p $DIR/$tdir
2081         drop_reint_reply "$LFS mkdir -i $mdtidx -c2 $remote_dir" ||
2082                 error "lfs mkdir failed"
2083
2084         diridx=$($LFS getstripe -m $remote_dir)
2085         [ $diridx -eq $mdtidx ] || error "$diridx != $mdtidx"
2086
2087         rm -rf $DIR/$tdir || error "rmdir failed"
2088 }
2089 run_test 110b "create remote directory: drop Master rep"
2090
2091 test_110c () {
2092         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2093         local remote_dir=$DIR/$tdir/remote_dir
2094         local mdtidx=1
2095
2096         mkdir -p $DIR/$tdir
2097         drop_update_reply $mdtidx "$LFS mkdir -i $mdtidx -c2 $remote_dir" ||
2098                 error "lfs mkdir failed"
2099
2100         diridx=$($GETSTRIPE -m $remote_dir)
2101         [ $diridx -eq $mdtidx ] || error "$diridx != $mdtidx"
2102
2103         rm -rf $DIR/$tdir || error "rmdir failed"
2104 }
2105 run_test 110c "create remote directory: drop update rep on slave MDT"
2106
2107 test_110d () {
2108         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2109         local remote_dir=$DIR/$tdir/remote_dir
2110         local MDTIDX=1
2111
2112         mkdir -p $DIR/$tdir
2113         $LFS mkdir -i $MDTIDX -c2 $remote_dir || error "lfs mkdir failed"
2114
2115         drop_request "rm -rf $remote_dir" || error "rm remote dir failed"
2116
2117         rm -rf $DIR/$tdir || error "rmdir failed"
2118
2119         return 0
2120 }
2121 run_test 110d "remove remote directory: drop client req"
2122
2123 test_110e () {
2124         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2125         local remote_dir=$DIR/$tdir/remote_dir
2126         local MDTIDX=1
2127
2128         mkdir -p $DIR/$tdir
2129         $LFS mkdir -i $MDTIDX -c2 $remote_dir  || error "lfs mkdir failed"
2130         drop_reint_reply "rm -rf $remote_dir" || error "rm remote dir failed"
2131
2132         rm -rf $DIR/$tdir || error "rmdir failed"
2133
2134         return 0
2135 }
2136 run_test 110e "remove remote directory: drop master rep"
2137
2138 test_110f () {
2139         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2140         local remote_dir=$DIR/$tdir/remote_dir
2141         local MDTIDX=1
2142
2143         mkdir -p $DIR/$tdir
2144         $LFS mkdir -i $MDTIDX -c2 $remote_dir || error "lfs mkdir failed"
2145         drop_update_reply $MDTIDX "rm -rf $remote_dir" ||
2146                                         error "rm remote dir failed"
2147
2148         rm -rf $DIR/$tdir || error "rmdir failed"
2149 }
2150 run_test 110f "remove remote directory: drop slave rep"
2151
2152 test_110g () {
2153         [[ "$MDS1_VERSION" -ge $(version_code 2.11.0) ]] ||
2154                 skip "Need MDS version at least 2.11.0"
2155
2156         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2157
2158         mkdir -p $DIR/$tdir
2159         touch $DIR/$tdir/$tfile
2160
2161         # OBD_FAIL_MDS_REINT_NET_REP    0x119
2162         do_facet mds1 $LCTL set_param fail_loc=0x119
2163         $LFS migrate -m 1 $DIR/$tdir &
2164         migrate_pid=$!
2165         sleep 5
2166         do_facet mds1 $LCTL set_param fail_loc=0
2167         wait $migrate_pid
2168
2169         local mdt_index
2170         mdt_index=$($LFS getstripe -m $DIR/$tdir)
2171         [ $mdt_index == 1 ] || error "$tdir is not on MDT1"
2172         mdt_index=$($LFS getstripe -m $DIR/$tdir/$tfile)
2173         [ $mdt_index == 1 ] || error "$tfile is not on MDT1"
2174
2175         rm -rf $DIR/$tdir || error "rmdir failed"
2176 }
2177 run_test 110g "drop reply during migration"
2178
2179 test_110h () {
2180         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2181         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
2182                 skip "Need MDS version at least 2.7.56"
2183
2184         local src_dir=$DIR/$tdir/source_dir
2185         local tgt_dir=$DIR/$tdir/target_dir
2186         local MDTIDX=1
2187
2188         mkdir -p $src_dir
2189         $LFS mkdir -i $MDTIDX $tgt_dir
2190
2191         dd if=/etc/hosts of=$src_dir/src_file
2192         touch $tgt_dir/tgt_file
2193         drop_update_reply $MDTIDX \
2194                 "mrename $src_dir/src_file $tgt_dir/tgt_file" ||
2195                 error "mrename failed"
2196
2197         $CHECKSTAT -t file $src_dir/src_file &&
2198                                 error "src_file present after rename"
2199
2200         diff /etc/hosts $tgt_dir/tgt_file ||
2201                         error "file changed after rename"
2202
2203 }
2204 run_test 110h "drop update reply during cross-MDT file rename"
2205
2206 test_110i () {
2207         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2208         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
2209                 skip "Need MDS version at least 2.7.56"
2210
2211         local src_dir=$DIR/$tdir/source_dir
2212         local tgt_dir=$DIR/$tdir/target_dir
2213         local MDTIDX=1
2214
2215         mkdir -p $src_dir
2216         $LFS mkdir -i $MDTIDX $tgt_dir
2217
2218         mkdir $src_dir/src_dir
2219         touch $src_dir/src_dir/a
2220         mkdir $tgt_dir/tgt_dir
2221         drop_update_reply $MDTIDX \
2222                 "mrename $src_dir/src_dir $tgt_dir/tgt_dir" ||
2223                 error "mrename failed"
2224
2225         $CHECKSTAT -t dir $src_dir/src_dir &&
2226                         error "src_dir present after rename"
2227
2228         $CHECKSTAT -t dir $tgt_dir/tgt_dir ||
2229                                 error "tgt_dir not present after rename"
2230
2231         $CHECKSTAT -t file $tgt_dir/tgt_dir/a ||
2232                                 error "a not present after rename"
2233 }
2234 run_test 110i "drop update reply during cross-MDT dir rename"
2235
2236 test_110j () {
2237         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2238         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
2239                 skip "Need MDS version at least 2.7.56"
2240
2241         local remote_dir=$DIR/$tdir/remote_dir
2242         local local_dir=$DIR/$tdir/local_dir
2243         local MDTIDX=1
2244
2245         mkdir -p $DIR/$tdir
2246         mkdir $DIR/$tdir/local_dir
2247         $LFS mkdir -i $MDTIDX $remote_dir
2248
2249         touch $local_dir/local_file
2250         drop_update_reply $MDTIDX \
2251                 "ln $local_dir/local_file $remote_dir/remote_file" ||
2252                 error "ln failed"
2253
2254         $CHECKSTAT -t file $remote_dir/remote_file ||
2255                                 error "remote not present after ln"
2256 }
2257 run_test 110j "drop update reply during cross-MDT ln"
2258
2259 test_110k() {
2260         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTS"
2261         [[ "$MDS1_VERSION" -ge $(version_code 2.12.55) ]] ||
2262                 skip "Need MDS version at least 2.12.55"
2263
2264         stop mds2 || error "stop mds2 failed"
2265         umount $MOUNT
2266
2267 #define OBD_FAIL_FLD_QUERY_REQ 0x1103
2268         do_facet mds2 lctl set_param fail_loc=0x1103
2269         start mds2 $(mdsdevname 2) -o abort_recovery ||
2270                 error "start MDS with abort_recovery should succeed"
2271         do_facet mds2 lctl set_param fail_loc=0
2272
2273         # cleanup
2274         stop mds2 || error "cleanup: stop mds2 failed"
2275         start mds2 $(mdsdevname 2) || error "cleanup: start mds2 failed"
2276         zconf_mount $(hostname) $MOUNT || error "cleanup: mount failed"
2277         client_up || error "post-failover df failed"
2278 }
2279 run_test 110k "FID_QUERY failed during recovery"
2280
2281 # LU-2844 mdt prepare fail should not cause umount oops
2282 test_111 ()
2283 {
2284         [[ "$MDS1_VERSION" -ge $(version_code 2.3.62) ]] ||
2285                 skip "Need MDS version at least 2.3.62"
2286
2287 #define OBD_FAIL_MDS_CHANGELOG_INIT 0x151
2288         do_facet $SINGLEMDS lctl set_param fail_loc=0x151
2289         stop $SINGLEMDS || error "stop MDS failed"
2290         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
2291                 error "start MDS should fail"
2292         do_facet $SINGLEMDS lctl set_param fail_loc=0
2293         start $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) ||
2294                 error "start MDS failed"
2295 }
2296 run_test 111 "mdd setup fail should not cause umount oops"
2297
2298 # LU-793
2299 test_112a() {
2300         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
2301
2302         do_facet_random_file client $TMP/$tfile 100K ||
2303                 error_noexit "Create random file $TMP/$tfile"
2304
2305         pause_bulk "cp $TMP/$tfile $DIR/$tfile" $TIMEOUT ||
2306                 error_noexit "Can't pause_bulk copy"
2307
2308         df $DIR
2309         # expect cmp to succeed, client resent bulk
2310         cmp $TMP/$tfile $DIR/$tfile ||
2311                 error_noexit "Wrong data has been written"
2312         rm $DIR/$tfile ||
2313                 error_noexit "Can't remove file"
2314         rm $TMP/$tfile
2315 }
2316 run_test 112a "bulk resend while orignal request is in progress"
2317
2318 test_115_read() {
2319         local fail1=$1
2320         local fail2=$2
2321
2322         df $DIR
2323         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
2324         cancel_lru_locks osc
2325
2326         # OST_READ       =  3,
2327         $LCTL set_param fail_loc=$fail1 fail_val=3
2328         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1 &
2329         pid=$!
2330         sleep 1
2331
2332         set_nodes_failloc "$(osts_nodes)" $fail2
2333
2334         wait $pid || error "dd failed"
2335         return 0
2336 }
2337
2338 test_115_write() {
2339         local fail1=$1
2340         local fail2=$2
2341         local error=$3
2342         local fail_val2=${4:-0}
2343
2344         df $DIR
2345         touch $DIR/$tfile
2346
2347         # OST_WRITE      =  4,
2348         $LCTL set_param fail_loc=$fail1 fail_val=4
2349         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=dsync &
2350         pid=$!
2351         sleep 1
2352
2353         df $MOUNT
2354         set_nodes_failloc "$(osts_nodes)" $fail2 $fail_val2
2355
2356         wait $pid
2357         rc=$?
2358         [ $error -eq 0 ] && [ $rc -ne 0 ] && error "dd error ($rc)"
2359         [ $error -ne 0 ] && [ $rc -eq 0 ] && error "dd success"
2360         return 0
2361 }
2362
2363 test_115a() {
2364         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2365                 skip "need at least 2.8.50 on OST"
2366
2367         #define OBD_FAIL_PTLRPC_LONG_REQ_UNLINK  0x51b
2368         #define OBD_FAIL_PTLRPC_DROP_BULK        0x51a
2369         test_115_read 0x8000051b 0x8000051a
2370 }
2371 run_test 115a "read: late REQ MDunlink and no bulk"
2372
2373 test_115b() {
2374         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2375                 skip "need at least 2.8.50 on OST"
2376
2377         #define OBD_FAIL_PTLRPC_LONG_REQ_UNLINK  0x51b
2378         #define OBD_FAIL_OST_ENOSPC              0x215
2379
2380         # pass $OSTCOUNT for the fail_loc to be caught
2381         # appropriately by the IO thread
2382         test_115_write 0x8000051b 0x80000215 1 $OSTCOUNT
2383 }
2384 run_test 115b "write: late REQ MDunlink and no bulk"
2385
2386 test_115c() {
2387         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2388                 skip "need at least 2.8.50 on OST"
2389
2390         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK 0x50f
2391         #define OBD_FAIL_PTLRPC_DROP_BULK        0x51a
2392         test_115_read 0x8000050f 0x8000051a
2393 }
2394 run_test 115c "read: late Reply MDunlink and no bulk"
2395
2396 test_115d() {
2397         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2398                 skip "need at least 2.8.50 on OST"
2399
2400         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK 0x50f
2401         #define OBD_FAIL_OST_ENOSPC              0x215
2402         test_115_write 0x8000050f 0x80000215 0
2403 }
2404 run_test 115d "write: late Reply MDunlink and no bulk"
2405
2406 test_115e() {
2407         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2408                 skip "need at least 2.8.50 on OST"
2409
2410         #define OBD_FAIL_PTLRPC_LONG_BULK_UNLINK 0x510
2411         #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
2412         test_115_read 0x80000510 0x80000211
2413 }
2414 run_test 115e "read: late Bulk MDunlink and no reply"
2415
2416 test_115f() {
2417         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2418                 skip "need at least 2.8.50 on OST"
2419
2420         #define OBD_FAIL_PTLRPC_LONG_REQ_UNLINK  0x51b
2421         #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
2422         test_115_read 0x8000051b 0x80000211
2423 }
2424 run_test 115f "read: late REQ MDunlink and no reply"
2425
2426 test_115g() {
2427         [ "$OST1_VERSION" -lt $(version_code 2.8.50) ] &&
2428                 skip "need at least 2.8.50 on OST"
2429
2430         #define OBD_FAIL_PTLRPC_LONG_BOTH_UNLINK 0x51c
2431         test_115_read 0x8000051c 0
2432 }
2433 run_test 115g "read: late REQ MDunlink and Reply MDunlink"
2434
2435 # parameters: fail_loc CMD RC
2436 test_120_reply() {
2437         local PID
2438         local PID2
2439         local rc=5
2440         local fail
2441
2442         #define OBD_FAIL_LDLM_CP_CB_WAIT2       0x320
2443         #define OBD_FAIL_LDLM_CP_CB_WAIT3       0x321
2444         #define OBD_FAIL_LDLM_CP_CB_WAIT4       0x322
2445         #define OBD_FAIL_LDLM_CP_CB_WAIT5       0x323
2446
2447         echo
2448         echo -n "** FLOCK REPLY vs. EVICTION race, lock $2"
2449         [ "$1" = "CLEANUP" ] &&
2450                 fail=0x80000320 && echo ", $1 cp first"
2451         [ "$1" = "REPLY" ] &&
2452                 fail=0x80000321 && echo ", $1 cp first"
2453         [ "$1" = "DEADLOCK CLEANUP" ] &&
2454                 fail=0x80000322 && echo " DEADLOCK, CLEANUP cp first"
2455         [ "$1" = "DEADLOCK REPLY" ] &&
2456                 fail=0x80000323 && echo " DEADLOCK, REPLY cp first"
2457
2458         if [ x"$2" = x"get" ]; then
2459                 #for TEST lock, take a conflict in advance
2460                 # sleep longer than evictor to not confuse fail_loc: 2+2+4
2461                 echo "** Taking conflict **"
2462                 flocks_test 5 set read sleep 10 $DIR/$tfile &
2463                 PID2=$!
2464
2465                 sleep 2
2466         fi
2467
2468         $LCTL set_param fail_loc=$fail
2469
2470         flocks_test 5 $2 write $DIR/$tfile &
2471         PID=$!
2472
2473         sleep 2
2474         echo "** Evicting and re-connecting client **"
2475         mds_evict_client
2476
2477         client_reconnect
2478
2479         if [ x"$2" = x"get" ]; then
2480                 wait $PID2
2481         fi
2482
2483         wait $PID
2484         rc=$?
2485
2486         # check if the return value is allowed
2487         [ $rc -eq $3 ] && rc=0
2488
2489         $LCTL set_param fail_loc=0
2490         return $rc
2491 }
2492
2493 # a lock is taken, unlock vs. cleanup_resource() race for destroying
2494 # the ORIGINAL lock.
2495 test_120_destroy()
2496 {
2497         local PID
2498
2499         flocks_test 5 set write sleep 4 $DIR/$tfile &
2500         PID=$!
2501         sleep 2
2502
2503         # let unlock to sleep in CP CB
2504         $LCTL set_param fail_loc=$1
2505         sleep 4
2506
2507         # let cleanup to cleep in CP CB
2508         mds_evict_client
2509
2510         client_reconnect
2511
2512         wait $PID
2513         rc=$?
2514
2515         $LCTL set_param fail_loc=0
2516         return $rc
2517 }
2518
2519 test_120() {
2520         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
2521         touch $DIR/$tfile
2522
2523         test_120_reply "CLEANUP" set 5 || error "SET race failed"
2524         test_120_reply "CLEANUP" get 5 || error "GET race failed"
2525         test_120_reply "CLEANUP" unlock 5 || error "UNLOCK race failed"
2526
2527         test_120_reply "REPLY" set 5 || error "SET race failed"
2528         test_120_reply "REPLY" get 5 || error "GET race failed"
2529         test_120_reply "REPLY" unlock 5 || error "UNLOCK race failed"
2530
2531         # DEADLOCK tests
2532         test_120_reply "DEADLOCK CLEANUP" set 5 || error "DEADLOCK race failed"
2533         test_120_reply "DEADLOCK REPLY" set 35 || error "DEADLOCK race failed"
2534
2535         test_120_destroy 0x320 || error "unlock-cleanup race failed"
2536 }
2537 run_test 120 "flock race: completion vs. evict"
2538
2539 test_113() {
2540         local BEFORE=$(date +%s)
2541         local EVICT
2542
2543         # modify dir so that next revalidate would not obtain UPDATE lock
2544         touch $DIR
2545
2546         # drop 1 reply with UPDATE lock,
2547         # resend should not create 2nd lock on server
2548         mcreate $DIR/$tfile || error "mcreate failed: $?"
2549         drop_mdt_ldlm_reply_once "stat $DIR/$tfile" || error "stat failed: $?"
2550
2551         # 2 BL AST will be sent to client, both must find the same lock,
2552         # race them to not get EINVAL for 2nd BL AST
2553         #define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
2554         $LCTL set_param fail_loc=0x8000031f
2555
2556         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=0 > /dev/null
2557         chmod 0777 $DIR/$tfile || error "chmod failed: $?"
2558         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=1 > /dev/null
2559
2560         # let the client reconnect
2561         client_reconnect
2562         EVICT=$($LCTL get_param mdc.$FSNAME-MDT*.state |
2563           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
2564
2565         [ -z "$EVICT" ] || [[ $EVICT -le $BEFORE ]] || error "eviction happened"
2566 }
2567 run_test 113 "ldlm enqueue dropped reply should not cause deadlocks"
2568
2569 T130_PID=0
2570 test_130_base() {
2571         test_mkdir -p $DIR/$tdir
2572
2573         # Prevent interference from layout intent RPCs due to
2574         # asynchronous writeback. These will be tested in 130c below.
2575         do_nodes ${CLIENTS:-$HOSTNAME} sync
2576
2577         # get only LOOKUP lock on $tdir
2578         cancel_lru_locks mdc
2579         ls $DIR/$tdir/$tfile 2>/dev/null
2580
2581         # get getattr by fid on $tdir
2582         #
2583         # we need to race with unlink, unlink must complete before we will
2584         # take a DLM lock, otherwise unlink will wait until getattr will
2585         # complete; but later than getattr starts so that getattr found
2586         # the object
2587 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
2588         set_nodes_failloc "$(mdts_nodes)" 0x80000160
2589         stat $DIR/$tdir &
2590         T130_PID=$!
2591         sleep 2
2592
2593         rm -rf $DIR/$tdir
2594
2595         # drop the reply so that resend happens on an unlinked file.
2596 #define OBD_FAIL_MDS_LDLM_REPLY_NET      0x157
2597         set_nodes_failloc "$(mdts_nodes)" 0x80000157
2598 }
2599
2600 test_130a() {
2601         remote_mds_nodsh && skip "remote MDS with nodsh"
2602         [[ "$MDS1_VERSION" -ge $(version_code 2.7.2) ]] ||
2603                 skip "Need server version newer than 2.7.1"
2604
2605         test_130_base
2606
2607         wait $T130_PID || [ $? -eq 0 ] && error "stat should fail"
2608         return 0
2609 }
2610 run_test 130a "enqueue resend on not existing file"
2611
2612 test_130b() {
2613         remote_mds_nodsh && skip "remote MDS with nodsh"
2614         [[ "$MDS1_VERSION" -ge $(version_code 2.7.2) ]] ||
2615                 skip "Need server version newer than 2.7.1"
2616
2617         test_130_base
2618         # let the reply to be dropped
2619         sleep 10
2620
2621 #define OBD_FAIL_SRV_ENOENT              0x217
2622         set_nodes_failloc "$(mdts_nodes)" 0x80000217
2623
2624         wait $T130_PID || [ $? -eq 0 ] && error "stat should fail"
2625         return 0
2626 }
2627 run_test 130b "enqueue resend on a stale inode"
2628
2629 test_130c() {
2630         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2631
2632         do_nodes ${CLIENTS:-$HOSTNAME} sync
2633         echo XXX > $DIR/$tfile
2634
2635         cancel_lru_locks mdc
2636
2637         # Trigger writeback on $tfile.
2638         #
2639         # we need to race with unlink, unlink must complete before we will
2640         # take a DLM lock, otherwise unlink will wait until intent will
2641         # complete; but later than intent starts so that intent found
2642         # the object
2643 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
2644         set_nodes_failloc "$(mdts_nodes)" 0x80000160
2645         sync &
2646         T130_PID=$!
2647         sleep 2
2648
2649         rm $DIR/$tfile
2650
2651         # drop the reply so that resend happens on an unlinked file.
2652 #define OBD_FAIL_MDS_LDLM_REPLY_NET      0x157
2653         set_nodes_failloc "$(mdts_nodes)" 0x80000157
2654
2655         # let the reply to be dropped
2656         sleep 10
2657
2658 #define OBD_FAIL_SRV_ENOENT              0x217
2659         set_nodes_failloc "$(mdts_nodes)" 0x80000217
2660
2661         wait $T130_PID
2662
2663         return 0
2664 }
2665 run_test 130c "layout intent resend on a stale inode"
2666
2667 test_132() {
2668         local before=$(date +%s)
2669         local evict
2670
2671         mount_client $MOUNT2 || error "mount filed"
2672
2673         rm -f $DIR/$tfile
2674         # get a lock on client so that export would reach the stale list
2675         $SETSTRIPE -i 0 $DIR/$tfile || error "setstripe failed"
2676         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync ||
2677                 error "dd failed"
2678
2679         #define OBD_FAIL_OST_PAUSE_PUNCH         0x236
2680         do_facet ost1 $LCTL set_param fail_val=120 fail_loc=0x80000236
2681
2682         $TRUNCATE $DIR/$tfile 100 &
2683
2684         sleep 1
2685         dd if=/dev/zero of=$DIR2/$tfile bs=4096 count=1 conv=notrunc ||
2686                 error "dd failed"
2687
2688         wait
2689         umount_client $MOUNT2
2690
2691         evict=$(do_facet client $LCTL get_param \
2692                 osc.$FSNAME-OST0000-osc-*/state |
2693             awk -F"[ [,]" '/EVICTED ]$/ { if (t<$5) {t=$5;} } END { print t }')
2694
2695         [ -z "$evict" ] || [[ $evict -le $before ]] ||
2696                 (do_facet client $LCTL get_param \
2697                         osc.$FSNAME-OST0000-osc-*/state;
2698                     error "eviction happened: $evict before:$before")
2699 }
2700 run_test 132 "long punch"
2701
2702 test_131() {
2703         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
2704
2705         rm -f $DIR/$tfile
2706         # get a lock on client so that export would reach the stale list
2707         $SETSTRIPE -i 0 $DIR/$tfile || error "setstripe failed"
2708         dd if=/dev/zero of=$DIR/$tfile count=1 || error "dd failed"
2709
2710         # another IO under the same lock
2711         #define OBD_FAIL_OSC_DELAY_IO            0x414
2712         $LCTL set_param fail_loc=0x80000414
2713         $LCTL set_param fail_val=4 fail_loc=0x80000414
2714         dd if=/dev/zero of=$DIR/$tfile count=1 conv=notrunc oflag=dsync &
2715         local pid=$!
2716         sleep 1
2717
2718         #define OBD_FAIL_LDLM_BL_EVICT           0x31e
2719         set_nodes_failloc "$(osts_nodes)" 0x8000031e
2720         ost_evict_client
2721         client_reconnect
2722
2723         wait $pid && error "dd succeeded"
2724         return 0
2725 }
2726 run_test 131 "IO vs evict results to IO under staled lock"
2727
2728 test_133() {
2729         local list=$(comma_list $(mdts_nodes))
2730
2731         local t=$((TIMEOUT * 2))
2732         touch $DIR/$tfile
2733
2734         flock $DIR/$tfile -c "echo bl lock;sleep $t;echo bl flock unlocked" &
2735         sleep 1
2736         multiop_bg_pause $DIR/$tfile O_jc || return 1
2737         PID=$!
2738
2739         #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
2740         do_nodes $list $LCTL set_param fail_loc=0x80000157
2741         kill -USR1 $PID
2742         echo "waiting for multiop $PID"
2743         wait $PID || return 2
2744
2745         rm -f $DIR/$tfile
2746
2747         return 0
2748 }
2749 run_test 133 "don't fail on flock resend"
2750
2751 test_134() {
2752         [ -z "$CLIENTS" ] && skip "Need two or more clients" && return
2753         [ $CLIENTCOUNT -lt 2 ] &&
2754                 { skip "Need 2+ clients, have $CLIENTCOUNT" && return; }
2755
2756         mkdir -p $MOUNT/$tdir/1 $MOUNT/$tdir/2 || error "mkdir failed"
2757         touch $MOUNT/$tdir/1/$tfile $MOUNT/$tdir/2/$tfile ||
2758                 error "touch failed"
2759         zconf_umount_clients $CLIENTS $MOUNT
2760         zconf_mount_clients $CLIENTS $MOUNT
2761
2762 #define OBD_FAIL_TGT_REPLY_DATA_RACE    0x722
2763         # assume commit interval is 5
2764         do_facet mds1 "$LCTL set_param fail_loc=0x722 fail_val=5"
2765
2766         local -a clients=(${CLIENTS//,/ })
2767         local client1=${clients[0]}
2768         local client2=${clients[1]}
2769
2770         do_node $client1 rm $MOUNT/$tdir/1/$tfile &
2771         rmpid=$!
2772         do_node $client2 mv $MOUNT/$tdir/2/$tfile $MOUNT/$tdir/2/${tfile}_2 &
2773         mvpid=$!
2774         fail mds1
2775         wait $rmpid || error "rm failed"
2776         wait $mvpid || error "mv failed"
2777         return 0
2778 }
2779 run_test 134 "race between failover and search for reply data free slot"
2780
2781 test_135() {
2782         [ "$MDS1_VERSION" -lt $(version_code 2.12.51) ] &&
2783                 skip "Need MDS version at least 2.12.51"
2784
2785         mkdir -p $DIR/$tdir
2786         $LFS setstripe -E 1M -L mdt $DIR/$tdir
2787         # to have parent dir write lock before open/resend
2788         touch $DIR/$tdir/$tfile
2789         #define OBD_FAIL_MDS_LDLM_REPLY_NET 0x157
2790         do_nodes $(comma_list $(mdts_nodes)) $LCTL set_param fail_loc=0x80000157
2791         openfile -f O_RDWR:O_CREAT -m 0755 $DIR/$tdir/$tfile ||
2792                 error "Failed to open DOM file"
2793 }
2794 run_test 135 "DOM: open/create resend to return size"
2795
2796 test_136() {
2797         remote_mds_nodsh && skip "remote MDS with nodsh"
2798         [[ "$MDS1_VERSION" -ge $(version_code 2.12.52) ]] ||
2799                 skip "Need MDS version at least 2.12.52"
2800
2801         local mdts=$(comma_list $(mdts_nodes))
2802         local MDT0=$(facet_svc $SINGLEMDS)
2803
2804         local clog=$(do_facet mds1 $LCTL --device $MDT0 changelog_register -n)
2805         [ -n "$clog" ] || error "changelog_register failed"
2806         cl_mask=$(do_facet mds1 $LCTL get_param \
2807                                 mdd.$MDT0.changelog_mask -n)
2808         changelog_chmask "ALL"
2809
2810         # generate some changelog records to accumulate
2811         test_mkdir -i 0 -c 0 $DIR/$tdir || error "mkdir $tdir failed"
2812         createmany -m $DIR/$tdir/$tfile 10000 ||
2813                 error "create $DIR/$tdir/$tfile failed"
2814
2815         local size1=$(do_facet $SINGLEMDS \
2816                       $LCTL get_param -n mdd.$MDT0.changelog_size)
2817         echo "Changelog size $size1"
2818
2819         #define OBD_FAIL_LLOG_PURGE_DELAY                   0x1318
2820         do_nodes $mdts $LCTL set_param fail_loc=0x1318 fail_val=30
2821
2822         # launch changelog_deregister in background on MDS
2823         do_facet mds1 "nohup $LCTL --device $MDT0 changelog_deregister $clog \
2824                         > foo.out 2> foo.err < /dev/null &"
2825         # give time to reach fail_loc
2826         sleep 15
2827
2828         # fail_loc will make MDS sleep in the middle of changelog_deregister
2829         # take this opportunity to abruptly kill MDS
2830         FAILURE_MODE_save=$FAILURE_MODE
2831         FAILURE_MODE=HARD
2832         fail mds1
2833         FAILURE_MODE=$FAILURE_MODE_save
2834
2835         do_nodes $mdts $LCTL set_param fail_loc=0x0 fail_val=0
2836
2837         local size2=$(do_facet $SINGLEMDS \
2838                       $LCTL get_param -n mdd.$MDT0.changelog_size)
2839         echo "Changelog size $size2"
2840         local clog2=$(do_facet $SINGLEMDS "$LCTL get_param -n \
2841                         mdd.$MDT0.changelog_users | grep $clog")
2842         echo "After crash, changelog user $clog2"
2843
2844         [ -n "$clog2" -o $size2 -lt $size1 ] ||
2845                 error "changelog record count unchanged"
2846
2847         do_facet mds1 $LCTL set_param mdd.$MDT0.changelog_mask=\'$cl_mask\' -n
2848 }
2849 run_test 136 "changelog_deregister leaving pending records"
2850
2851 test_137() {
2852         df $DIR
2853         mkdir -p $DIR/d1
2854         mkdir -p $DIR/d2
2855         dd if=/dev/zero of=$DIR/d1/$tfile bs=4096 count=1
2856         dd if=/dev/zero of=$DIR/d2/$tfile bs=4096 count=1
2857         cancel_lru_locks osc
2858
2859         #define OBD_FAIL_PTLRPC_RESEND_RACE      0x525
2860         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000525"
2861
2862         # RPC1: any reply is to be delayed to disable last_xid logic
2863         ln $DIR/d1/$tfile $DIR/d1/f2 &
2864         sleep 1
2865
2866         # RPC2: setattr1 reply is delayed & resent
2867         # original reply comes to client; the resend get asleep
2868         chmod 666 $DIR/d2/$tfile
2869
2870         # RPC3: setattr2 on the same file; run ahead of RPC2 resend
2871         chmod 777 $DIR/d2/$tfile
2872
2873         # RPC2 resend wakes up
2874         sleep 5
2875         [ $(stat -c "%a" $DIR/d2/$tfile) == 777 ] || error "resend got applied"
2876 }
2877 run_test 137 "late resend must be skipped if already applied"
2878
2879 complete $SECONDS
2880 check_and_cleanup_lustre
2881 exit_status