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