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