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