Whamcloud - gitweb
1c4759c419e1dab7898d38b609077db8bf801b0d
[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    60      $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}.mds_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_17() {
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 17 "timeout bulk get, don't evict client (2732)"
463
464 test_18a() {
465     [ -z ${ost2_svc} ] && skip_env "needs 2 osts" && return 0
466
467         do_facet_create_file client $TMP/$tfile 20K ||
468                 { error_noexit "Create file $TMP/$tfile" ; return 0; }
469
470     do_facet client mkdir -p $DIR/$tdir
471     f=$DIR/$tdir/$tfile
472
473     cancel_lru_locks osc
474     pgcache_empty || return 1
475
476     # 1 stripe on ost2
477     $LFS setstripe -i 1 -c 1 $f
478     stripe_index=$($LFS getstripe -i $f)
479     if [ $stripe_index -ne 1 ]; then
480         $LFS getstripe $f
481         error "$f: stripe_index $stripe_index != 1" && return
482     fi
483
484     do_facet client cp $TMP/$tfile $f
485     sync
486     local osc2dev=`lctl get_param -n devices | grep ${ost2_svc}-osc- | egrep -v 'MDT' | awk '{print $1}'`
487     $LCTL --device $osc2dev deactivate || return 3
488     # my understanding is that there should be nothing in the page
489     # cache after the client reconnects?     
490     rc=0
491     pgcache_empty || rc=2
492     $LCTL --device $osc2dev activate
493     rm -f $f $TMP/$tfile
494     return $rc
495 }
496 run_test 18a "manual ost invalidate clears page cache immediately"
497
498 test_18b() {
499     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
500
501         do_facet_create_file client $TMP/$tfile 20K ||
502                 { error_noexit "Create file $TMP/$tfile" ; return 0; }
503
504     do_facet client mkdir -p $DIR/$tdir
505     f=$DIR/$tdir/$tfile
506
507     cancel_lru_locks osc
508     pgcache_empty || return 1
509
510     $LFS setstripe -i 0 -c 1 $f
511     stripe_index=$($LFS getstripe -i $f)
512     if [ $stripe_index -ne 0 ]; then
513         $LFS getstripe $f
514         error "$f: stripe_index $stripe_index != 0" && return
515     fi
516
517     do_facet client cp $TMP/$tfile $f
518     sync
519     ost_evict_client
520     # allow recovery to complete
521     sleep $((TIMEOUT + 2))
522     # my understanding is that there should be nothing in the page
523     # cache after the client reconnects?     
524     rc=0
525     pgcache_empty || rc=2
526     rm -f $f $TMP/$tfile
527     return $rc
528 }
529 run_test 18b "eviction and reconnect clears page cache (2766)"
530
531 test_18c() {
532     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
533
534         do_facet_create_file client $TMP/$tfile 20K ||
535                 { error_noexit "Create file $TMP/$tfile" ; return 0; }
536
537     do_facet client mkdir -p $DIR/$tdir
538     f=$DIR/$tdir/$tfile
539
540     cancel_lru_locks osc
541     pgcache_empty || return 1
542
543     $LFS setstripe -i 0 -c 1 $f
544     stripe_index=$($LFS getstripe -i $f)
545     if [ $stripe_index -ne 0 ]; then
546         $LFS getstripe $f
547         error "$f: stripe_index $stripe_index != 0" && return
548     fi
549
550     do_facet client cp $TMP/$tfile $f
551     sync
552     ost_evict_client
553
554     # OBD_FAIL_OST_CONNECT_NET2
555     # lost reply to connect request
556     do_facet ost1 lctl set_param fail_loc=0x80000225
557     # force reconnect
558     sleep 1
559     $LFS df $MOUNT > /dev/null 2>&1
560     sleep 2
561     # my understanding is that there should be nothing in the page
562     # cache after the client reconnects?
563     rc=0
564     pgcache_empty || rc=2
565     rm -f $f $TMP/$tfile
566     return $rc
567 }
568 run_test 18c "Dropped connect reply after eviction handing (14755)"
569
570 test_19a() {
571         local BEFORE=`date +%s`
572         local EVICT
573
574         mount_client $DIR2 || error "failed to mount $DIR2"
575
576         # cancel cached locks from OST to avoid eviction from it
577         cancel_lru_locks osc
578
579         do_facet client "stat $DIR > /dev/null"  ||
580                 error "failed to stat $DIR: $?"
581         drop_ldlm_cancel "chmod 0777 $DIR2" ||
582                 error "failed to chmod $DIR2"
583
584         umount_client $DIR2
585
586         # let the client reconnect
587         client_reconnect
588         EVICT=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
589                 awk -F"[ [,]" '/EVICTED ]$/ \
590                         { if (mx<$5) {mx=$5;} } END { print mx }')
591
592         [ ! -z "$EVICT" ] && [[ $EVICT -gt $BEFORE ]] ||
593                 (do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state;
594                     error "no eviction: $EVICT before:$BEFORE")
595 }
596 run_test 19a "test expired_lock_main on mds (2867)"
597
598 test_19b() {
599         local BEFORE=`date +%s`
600         local EVICT
601
602         mount_client $DIR2 || error "failed to mount $DIR2: $?"
603
604         # cancel cached locks from MDT to avoid eviction from it
605         cancel_lru_locks mdc
606
607         do_facet client $MULTIOP $DIR/$tfile Ow ||
608                 error "failed to run multiop: $?"
609         drop_ldlm_cancel $MULTIOP $DIR2/$tfile Ow ||
610                 error "failed to ldlm_cancel: $?"
611
612         umount_client $DIR2 || error "failed to unmount $DIR2: $?"
613         do_facet client munlink $DIR/$tfile ||
614                 error "failed to unlink $DIR/$tfile: $?"
615
616         # let the client reconnect
617         client_reconnect
618         EVICT=$(do_facet client $LCTL get_param osc.$FSNAME-OST*.state |
619                 awk -F"[ [,]" '/EVICTED ]$/ \
620                         { if (mx < $5) {mx = $5;} } END { print mx }')
621
622         [ ! -z "$EVICT" ] && [[ $EVICT -gt $BEFORE ]] ||
623                 (do_facet client $LCTL get_param osc.$FSNAME-OST*.state;
624                     error "no eviction: $EVICT before:$BEFORE")
625 }
626 run_test 19b "test expired_lock_main on ost (2867)"
627
628 test_19c() {
629         local BEFORE=`date +%s`
630
631         mount_client $DIR2
632         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=0
633
634         mkdir -p $DIR1/$tfile
635         stat $DIR1/$tfile
636
637 #define OBD_FAIL_PTLRPC_CANCEL_RESEND 0x516
638         do_facet mds $LCTL set_param fail_loc=0x80000516
639
640         touch $DIR2/$tfile/file1 &
641         PID1=$!
642         # let touch to get blocked on the server
643         sleep 2
644
645         wait $PID1
646         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=1
647         umount_client $DIR2
648
649         # let the client reconnect
650         sleep 5
651         EVICT=$(do_facet client $LCTL get_param mdc.$FSNAME-MDT*.state |
652           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
653
654         [ -z "$EVICT" ] || [[ $EVICT -le $BEFORE ]] || error "eviction happened"
655 }
656 run_test 19c "check reconnect and lock resend do not trigger expired_lock_main"
657
658 test_20a() {    # bug 2983 - ldlm_handle_enqueue cleanup
659         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
660
661         mkdir -p $DIR/$tdir
662         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${tfile}
663         multiop_bg_pause $DIR/$tdir/${tfile} O_wc || return 1
664         MULTI_PID=$!
665         cancel_lru_locks osc
666 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
667         do_facet ost1 lctl set_param fail_loc=0x80000308
668         kill -USR1 $MULTI_PID
669         wait $MULTI_PID
670         rc=$?
671         [ $rc -eq 0 ] && error "multiop didn't fail enqueue: rc $rc" || true
672 }
673 run_test 20a "ldlm_handle_enqueue error (should return error)" 
674
675 test_20b() {    # bug 2986 - ldlm_handle_enqueue error during open
676         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
677
678         mkdir -p $DIR/$tdir
679         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${tfile}
680         cancel_lru_locks osc
681 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
682         do_facet ost1 lctl set_param fail_loc=0x80000308
683         dd if=/etc/hosts of=$DIR/$tdir/$tfile && \
684                 error "didn't fail open enqueue" || true
685 }
686 run_test 20b "ldlm_handle_enqueue error (should return error)"
687
688 test_21a() {
689        mkdir -p $DIR/$tdir-1
690        mkdir -p $DIR/$tdir-2
691        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
692        close_pid=$!
693
694        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000129"
695        $MULTIOP $DIR/$tdir-2/f Oc &
696        open_pid=$!
697        sleep 1
698        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
699
700        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
701        kill -USR1 $close_pid
702        cancel_lru_locks mdc
703        wait $close_pid || return 1
704        wait $open_pid || return 2
705        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
706
707        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
708        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
709
710        rm -rf $DIR/$tdir-*
711 }
712 run_test 21a "drop close request while close and open are both in flight"
713
714 test_21b() {
715        mkdir -p $DIR/$tdir-1
716        mkdir -p $DIR/$tdir-2
717        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
718        close_pid=$!
719
720        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
721        mcreate $DIR/$tdir-2/f &
722        open_pid=$!
723        sleep 1
724        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
725
726        kill -USR1 $close_pid
727        cancel_lru_locks mdc
728        wait $close_pid || return 1
729        wait $open_pid || return 3
730
731        $CHECKSTAT -t file $DIR/$tdir-1/f || return 4
732        $CHECKSTAT -t file $DIR/$tdir-2/f || return 5
733        rm -rf $DIR/$tdir-*
734 }
735 run_test 21b "drop open request while close and open are both in flight"
736
737 test_21c() {
738        mkdir -p $DIR/$tdir-1
739        mkdir -p $DIR/$tdir-2
740        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
741        close_pid=$!
742
743        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
744        mcreate $DIR/$tdir-2/f &
745        open_pid=$!
746        sleep 3
747        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
748
749        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
750        kill -USR1 $close_pid
751        cancel_lru_locks mdc
752        wait $close_pid || return 1
753        wait $open_pid || return 2
754
755        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
756
757        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
758        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
759        rm -rf $DIR/$tdir-*
760 }
761 run_test 21c "drop both request while close and open are both in flight"
762
763 test_21d() {
764        mkdir -p $DIR/$tdir-1
765        mkdir -p $DIR/$tdir-2
766        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
767        pid=$!
768
769        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000129"
770        $MULTIOP $DIR/$tdir-2/f Oc &
771        sleep 1
772        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
773
774        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
775        kill -USR1 $pid
776        cancel_lru_locks mdc
777        wait $pid || return 1
778        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
779
780        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
781        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
782
783        rm -rf $DIR/$tdir-*
784 }
785 run_test 21d "drop close reply while close and open are both in flight"
786
787 test_21e() {
788        mkdir -p $DIR/$tdir-1
789        mkdir -p $DIR/$tdir-2
790        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
791        pid=$!
792
793        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
794        touch $DIR/$tdir-2/f &
795        sleep 1
796        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
797
798        kill -USR1 $pid
799        cancel_lru_locks mdc
800        wait $pid || return 1
801
802        sleep $TIMEOUT
803        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
804        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
805        rm -rf $DIR/$tdir-*
806 }
807 run_test 21e "drop open reply while close and open are both in flight"
808
809 test_21f() {
810        mkdir -p $DIR/$tdir-1
811        mkdir -p $DIR/$tdir-2
812        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
813        pid=$!
814
815        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
816        touch $DIR/$tdir-2/f &
817        sleep 1
818        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
819
820        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
821        kill -USR1 $pid
822        cancel_lru_locks mdc
823        wait $pid || return 1
824        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
825
826        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
827        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
828        rm -rf $DIR/$tdir-*
829 }
830 run_test 21f "drop both reply while close and open are both in flight"
831
832 test_21g() {
833        mkdir -p $DIR/$tdir-1
834        mkdir -p $DIR/$tdir-2
835        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
836        pid=$!
837
838        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
839        touch $DIR/$tdir-2/f &
840        sleep 1
841        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
842
843        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
844        kill -USR1 $pid
845        cancel_lru_locks mdc
846        wait $pid || return 1
847        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
848
849        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
850        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
851        rm -rf $DIR/$tdir-*
852 }
853 run_test 21g "drop open reply and close request while close and open are both in flight"
854
855 test_21h() {
856        mkdir -p $DIR/$tdir-1
857        mkdir -p $DIR/$tdir-2
858        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
859        pid=$!
860
861        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
862        touch $DIR/$tdir-2/f &
863        touch_pid=$!
864        sleep 1
865        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
866
867        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
868        cancel_lru_locks mdc
869        kill -USR1 $pid
870        wait $pid || return 1
871        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
872
873        wait $touch_pid || return 2
874
875        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
876        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
877        rm -rf $DIR/$tdir-*
878 }
879 run_test 21h "drop open request and close reply while close and open are both in flight"
880
881 # bug 3462 - multiple MDC requests
882 test_22() {
883     f1=$DIR/${tfile}-1
884     f2=$DIR/${tfile}-2
885     
886     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
887     $MULTIOP $f2 Oc &
888     close_pid=$!
889
890     sleep 1
891     $MULTIOP $f1 msu || return 1
892
893     cancel_lru_locks mdc
894     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
895
896     wait $close_pid || return 2
897     rm -rf $f2 || return 4
898 }
899 run_test 22 "drop close request and do mknod"
900
901 test_23() { #b=4561
902     multiop_bg_pause $DIR/$tfile O_c || return 1
903     pid=$!
904     # give a chance for open
905     sleep 5
906
907     # try the close
908     drop_request "kill -USR1 $pid"
909
910     fail $SINGLEMDS
911     wait $pid || return 1
912     return 0
913 }
914 run_test 23 "client hang when close a file after mds crash"
915
916 test_24a() { # bug 11710 details correct fsync() behavior
917         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
918
919         mkdir -p $DIR/$tdir
920         $LFS setstripe -i 0 -c 1 $DIR/$tdir
921         cancel_lru_locks osc
922         multiop_bg_pause $DIR/$tdir/$tfile Owy_wyc || return 1
923         MULTI_PID=$!
924         ost_evict_client
925         kill -USR1 $MULTI_PID
926         wait $MULTI_PID
927         rc=$?
928         lctl set_param fail_loc=0x0
929         client_reconnect
930         [ $rc -eq 0 ] &&
931                 error_ignore bz5494 "multiop didn't fail fsync: rc $rc" || true
932 }
933 run_test 24a "fsync error (should return error)"
934
935 wait_client_evicted () {
936         local facet=$1
937         local exports=$2
938         local varsvc=${facet}_svc
939
940         wait_update $(facet_active_host $facet) \
941                 "lctl get_param -n *.${!varsvc}.num_exports | cut -d' ' -f2" \
942                 $((exports - 1)) $3
943 }
944
945 test_24b() {
946         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
947
948         dmesg -c > /dev/null
949         mkdir -p $DIR/$tdir
950         lfs setstripe $DIR/$tdir -s 0 -i 0 -c 1
951         cancel_lru_locks osc
952         multiop_bg_pause $DIR/$tdir/$tfile-1 Ow8192_yc ||
953                 error "mulitop Ow8192_yc failed"
954
955         MULTI_PID1=$!
956         multiop_bg_pause $DIR/$tdir/$tfile-2 Ow8192_c ||
957                 error "mulitop Ow8192_c failed"
958
959         MULTI_PID2=$!
960         ost_evict_client
961
962         kill -USR1 $MULTI_PID1
963         wait $MULTI_PID1
964         rc1=$?
965         kill -USR1 $MULTI_PID2
966         wait $MULTI_PID2
967         rc2=$?
968         lctl set_param fail_loc=0x0
969         client_reconnect
970         [ $rc1 -eq 0 -o $rc2 -eq 0 ] &&
971         error_ignore bz5494 "multiop didn't fail fsync: $rc1 or close: $rc2" ||
972                 true
973
974         dmesg | grep "dirty page discard:" ||
975                 error "no discarded dirty page found!"
976 }
977 run_test 24b "test dirty page discard due to client eviction"
978
979 test_26a() {      # was test_26 bug 5921 - evict dead exports by pinger
980 # this test can only run from a client on a separate node.
981         remote_ost || { skip "local OST" && return 0; }
982         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
983         remote_mds || { skip "local MDS" && return 0; }
984
985         if [ $(facet_host mgs) = $(facet_host ost1) ]; then
986                 skip "msg and ost1 are at the same node"
987                 return 0
988         fi
989
990         check_timeout || return 1
991
992         local OST_NEXP=$(do_facet ost1 lctl get_param -n obdfilter.${ost1_svc}.num_exports | cut -d' ' -f2)
993
994         echo starting with $OST_NEXP OST exports
995 # OBD_FAIL_PTLRPC_DROP_RPC 0x505
996         do_facet client lctl set_param fail_loc=0x505
997         # evictor takes PING_EVICT_TIMEOUT + 3 * PING_INTERVAL to evict.
998         # But if there's a race to start the evictor from various obds,
999         # the loser might have to wait for the next ping.
1000
1001         local rc=0
1002         wait_client_evicted ost1 $OST_NEXP $((TIMEOUT * 2 + TIMEOUT * 3 / 4))
1003         rc=$?
1004         do_facet client lctl set_param fail_loc=0x0
1005         [ $rc -eq 0 ] || error "client not evicted from OST"
1006 }
1007 run_test 26a "evict dead exports"
1008
1009 test_26b() {      # bug 10140 - evict dead exports by pinger
1010         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1011
1012         if [ $(facet_host mgs) = $(facet_host ost1) ]; then
1013                 skip "msg and ost1 are at the same node"
1014                 return 0
1015         fi
1016
1017         check_timeout || return 1
1018         clients_up
1019         zconf_mount `hostname` $MOUNT2 ||
1020                 { error "Failed to mount $MOUNT2"; return 2; }
1021         sleep 1 # wait connections being established
1022
1023         local MDS_NEXP=$(do_facet $SINGLEMDS lctl get_param -n mdt.${mds1_svc}.num_exports | cut -d' ' -f2)
1024         local OST_NEXP=$(do_facet ost1 lctl get_param -n obdfilter.${ost1_svc}.num_exports | cut -d' ' -f2)
1025
1026         echo starting with $OST_NEXP OST and $MDS_NEXP MDS exports
1027
1028         zconf_umount `hostname` $MOUNT2 -f
1029
1030         # PING_INTERVAL max(obd_timeout / 4, 1U)
1031         # PING_EVICT_TIMEOUT (PING_INTERVAL * 6)
1032
1033         # evictor takes PING_EVICT_TIMEOUT + 3 * PING_INTERVAL to evict.  
1034         # But if there's a race to start the evictor from various obds, 
1035         # the loser might have to wait for the next ping.
1036         # = 9 * PING_INTERVAL + PING_INTERVAL
1037         # = 10 PING_INTERVAL = 10 obd_timeout / 4 = 2.5 obd_timeout
1038         # let's wait $((TIMEOUT * 3)) # bug 19887
1039         local rc=0
1040         wait_client_evicted ost1 $OST_NEXP $((TIMEOUT * 3)) || \
1041                 error "Client was not evicted by ost" rc=1
1042         wait_client_evicted $SINGLEMDS $MDS_NEXP $((TIMEOUT * 3)) || \
1043                 error "Client was not evicted by mds"
1044 }
1045 run_test 26b "evict dead exports"
1046
1047 test_27() {
1048         mkdir -p $DIR/$tdir
1049         writemany -q -a $DIR/$tdir/$tfile 0 5 &
1050         CLIENT_PID=$!
1051         sleep 1
1052         local save_FAILURE_MODE=$FAILURE_MODE
1053         FAILURE_MODE="SOFT"
1054         facet_failover $SINGLEMDS
1055 #define OBD_FAIL_OSC_SHUTDOWN            0x407
1056         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000407
1057         # need to wait for reconnect
1058         echo waiting for fail_loc
1059         wait_update_facet $SINGLEMDS "lctl get_param -n fail_loc" "-2147482617"
1060         facet_failover $SINGLEMDS
1061         #no crashes allowed!
1062         kill -USR1 $CLIENT_PID
1063         wait $CLIENT_PID 
1064         true
1065         FAILURE_MODE=$save_FAILURE_MODE
1066 }
1067 run_test 27 "fail LOV while using OSC's"
1068
1069 test_28() {      # bug 6086 - error adding new clients
1070         do_facet client mcreate $DIR/$tfile       || return 1
1071         drop_bl_callback_once "chmod 0777 $DIR/$tfile" ||
1072                 echo "evicted as expected"
1073         #define OBD_FAIL_MDS_CLIENT_ADD 0x12f
1074         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012f"
1075         # fail once (evicted), reconnect fail (fail_loc), ok
1076         client_up || (sleep 10; client_up) || (sleep 10; client_up) || error "reconnect failed"
1077         rm -f $DIR/$tfile
1078         fail $SINGLEMDS         # verify MDS last_rcvd can be loaded
1079 }
1080 run_test 28 "handle error adding new clients (bug 6086)"
1081
1082 test_29a() { # bug 22273 - error adding new clients
1083         #define OBD_FAIL_TGT_CLIENT_ADD 0x711
1084         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000711"
1085         # fail abort so client will be new again
1086         fail_abort $SINGLEMDS
1087         client_up || error "reconnect failed"
1088         wait_osc_import_state $SINGLEMDS ost FULL
1089         return 0
1090 }
1091 run_test 29a "error adding new clients doesn't cause LBUG (bug 22273)"
1092
1093 test_29b() { # bug 22273 - error adding new clients
1094         #define OBD_FAIL_TGT_CLIENT_ADD 0x711
1095         do_facet ost1 "lctl set_param fail_loc=0x80000711"
1096         # fail abort so client will be new again
1097         fail_abort ost1
1098         client_up || error "reconnect failed"
1099         return 0
1100 }
1101 run_test 29b "error adding new clients doesn't cause LBUG (bug 22273)"
1102
1103 test_50() {
1104         mkdir -p $DIR/$tdir
1105         # put a load of file creates/writes/deletes
1106         writemany -q $DIR/$tdir/$tfile 0 5 &
1107         CLIENT_PID=$!
1108         echo writemany pid $CLIENT_PID
1109         sleep 10
1110         FAILURE_MODE="SOFT"
1111         fail $SINGLEMDS
1112         # wait for client to reconnect to MDS
1113         sleep 60
1114         fail $SINGLEMDS
1115         sleep 60
1116         fail $SINGLEMDS
1117         # client process should see no problems even though MDS went down
1118         sleep $TIMEOUT
1119         kill -USR1 $CLIENT_PID
1120         wait $CLIENT_PID 
1121         rc=$?
1122         echo writemany returned $rc
1123         #these may fail because of eviction due to slow AST response.
1124         [ $rc -eq 0 ] ||
1125                 error_ignore bz13652 "writemany returned rc $rc" || true
1126 }
1127 run_test 50 "failover MDS under load"
1128
1129 test_51() {
1130         #define OBD_FAIL_MDS_SYNC_CAPA_SL                    0x1310
1131         do_facet ost1 lctl set_param fail_loc=0x00001310
1132
1133         mkdir -p $DIR/$tdir
1134         # put a load of file creates/writes/deletes
1135         writemany -q $DIR/$tdir/$tfile 0 5 &
1136         CLIENT_PID=$!
1137         sleep 1
1138         FAILURE_MODE="SOFT"
1139         facet_failover $SINGLEMDS
1140         # failover at various points during recovery
1141         SEQ="1 5 10 $(seq $TIMEOUT 5 $(($TIMEOUT+10)))"
1142         echo will failover at $SEQ
1143         for i in $SEQ
1144         do
1145                 #echo failover in $i sec
1146                 log "test_$testnum: failover in $i sec"
1147                 sleep $i
1148                 facet_failover $SINGLEMDS
1149         done
1150         # client process should see no problems even though MDS went down
1151         # and recovery was interrupted
1152         sleep $TIMEOUT
1153         kill -USR1 $CLIENT_PID
1154         wait $CLIENT_PID
1155         rc=$?
1156         echo writemany returned $rc
1157         [ $rc -eq 0 ] ||
1158                 error_ignore bz13652 "writemany returned rc $rc" || true
1159 }
1160 run_test 51 "failover MDS during recovery"
1161
1162 test_52_guts() {
1163         do_facet client "mkdir -p $DIR/$tdir"
1164         do_facet client "writemany -q -a $DIR/$tdir/$tfile 300 5" &
1165         CLIENT_PID=$!
1166         echo writemany pid $CLIENT_PID
1167         sleep 10
1168         FAILURE_MODE="SOFT"
1169         fail ost1
1170         rc=0
1171         wait $CLIENT_PID || rc=$?
1172         # active client process should see an EIO for down OST
1173         [ $rc -eq 5 ] && { echo "writemany correctly failed $rc" && return 0; }
1174         # but timing or failover setup may allow success
1175         [ $rc -eq 0 ] && { echo "writemany succeeded" && return 0; }
1176         echo "writemany returned $rc"
1177         return $rc
1178 }
1179
1180 test_52() {
1181         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1182
1183         mkdir -p $DIR/$tdir
1184         test_52_guts
1185         rc=$?
1186         [ $rc -ne 0 ] && { return $rc; }
1187         # wait for client to reconnect to OST
1188         sleep 30
1189         test_52_guts
1190         rc=$?
1191         [ $rc -ne 0 ] && { return $rc; }
1192         sleep 30
1193         test_52_guts
1194         rc=$?
1195         client_reconnect
1196         #return $rc
1197 }
1198 run_test 52 "failover OST under load"
1199
1200 # test of open reconstruct
1201 test_53() {
1202         touch $DIR/$tfile
1203         drop_ldlm_reply "openfile -f O_RDWR:O_CREAT -m 0755 $DIR/$tfile" ||\
1204                 return 2
1205 }
1206 run_test 53 "touch: drop rep"
1207
1208 test_54() {
1209         zconf_mount `hostname` $MOUNT2
1210         touch $DIR/$tfile
1211         touch $DIR2/$tfile.1
1212         sleep 10
1213         cat $DIR2/$tfile.missing # save transno = 0, rc != 0 into last_rcvd
1214         fail $SINGLEMDS
1215         umount $MOUNT2
1216         ERROR=`dmesg | egrep "(test 54|went back in time)" | tail -n1 | grep "went back in time"`
1217         [ x"$ERROR" == x ] || error "back in time occured"
1218 }
1219 run_test 54 "back in time"
1220
1221 # bug 11330 - liblustre application death during I/O locks up OST
1222 test_55() {
1223         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1224
1225         mkdir -p $DIR/$tdir
1226
1227         # Minimum pass speed is 2MBps
1228         local ddtimeout=64
1229         # LU-2887/LU-3089 - set min pass speed to 500KBps
1230         [ "$(facet_fstype ost1)" = "zfs" ] && ddtimeout=256
1231
1232         # first dd should be finished quickly
1233         $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile-1
1234         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=32M count=4 &
1235         DDPID=$!
1236         count=0
1237         echo  "step1: testing ......"
1238         while kill -0 $DDPID 2> /dev/null; do
1239                 let count++
1240                 if [ $count -gt $ddtimeout ]; then
1241                         error "dd should be finished!"
1242                 fi
1243                 sleep 1
1244         done
1245         echo "(dd_pid=$DDPID, time=$count)successful"
1246
1247         $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile-2
1248         #define OBD_FAIL_OST_DROP_REQ            0x21d
1249         do_facet ost1 lctl set_param fail_loc=0x0000021d
1250         # second dd will be never finished
1251         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=32M count=4 &
1252         DDPID=$!
1253         count=0
1254         echo  "step2: testing ......"
1255         while [ $count -le $ddtimeout ]; do
1256                 if ! kill -0 $DDPID 2> /dev/null; then
1257                         ls -l $DIR/$tdir
1258                         error "dd shouldn't be finished! (time=$count)"
1259                 fi
1260                 let count++
1261                 sleep 1
1262         done
1263         echo "(dd_pid=$DDPID, time=$count)successful"
1264
1265         #Recover fail_loc and dd will finish soon
1266         do_facet ost1 lctl set_param fail_loc=0
1267         count=0
1268         echo  "step3: testing ......"
1269         while kill -0 $DDPID 2> /dev/null; do
1270                 let count++
1271                 if [ $count -gt $((ddtimeout + 440)) ]; then
1272                         error "dd should be finished!"
1273                 fi
1274                 sleep 1
1275         done
1276         echo "(dd_pid=$DDPID, time=$count)successful"
1277
1278         rm -rf $DIR/$tdir
1279 }
1280 run_test 55 "ost_brw_read/write drops timed-out read/write request"
1281
1282 test_56() { # b=11277
1283 #define OBD_FAIL_MDS_RESEND      0x136
1284         touch $DIR/$tfile
1285         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000136"
1286         stat $DIR/$tfile || error "stat failed"
1287         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1288         rm -f $DIR/$tfile
1289 }
1290 run_test 56 "do not fail on getattr resend"
1291
1292 test_57_helper() {
1293         # no oscs means no client or mdt 
1294         while lctl get_param osc.*.* > /dev/null 2>&1; do
1295                 : # loop until proc file is removed
1296         done
1297 }
1298
1299 test_57() { # bug 10866
1300         test_57_helper &
1301         pid=$!
1302         sleep 1
1303 #define OBD_FAIL_LPROC_REMOVE            0xB00
1304         lctl set_param fail_loc=0x80000B00
1305         zconf_umount `hostname` $DIR
1306         lctl set_param fail_loc=0x80000B00
1307         fail_abort $SINGLEMDS
1308         kill -9 $pid
1309         lctl set_param fail_loc=0
1310         mount_client $DIR
1311         do_facet client "df $DIR"
1312 }
1313 run_test 57 "read procfs entries causes kernel crash"
1314
1315 test_58() { # bug 11546
1316 #define OBD_FAIL_MDC_ENQUEUE_PAUSE        0x801
1317         touch $DIR/$tfile
1318         ls -la $DIR/$tfile
1319         lctl set_param fail_loc=0x80000801
1320         cp $DIR/$tfile /dev/null &
1321         pid=$!
1322         sleep 1
1323         lctl set_param fail_loc=0
1324         drop_bl_callback_once rm -f $DIR/$tfile
1325         wait $pid
1326         # the first 'df' could tigger the eviction caused by
1327         # 'drop_bl_callback_once', and it's normal case.
1328         # but the next 'df' should return successfully.
1329         do_facet client "df $DIR" || do_facet client "df $DIR"
1330 }
1331 run_test 58 "Eviction in the middle of open RPC reply processing"
1332
1333 test_59() { # bug 10589
1334         zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
1335         echo $DIR2 | grep -q $MOUNT2 || error "DIR2 is not set properly: $DIR2"
1336 #define OBD_FAIL_LDLM_CANCEL_EVICT_RACE  0x311
1337         lctl set_param fail_loc=0x311
1338         writes=$(LANG=C dd if=/dev/zero of=$DIR2/$tfile count=1 2>&1)
1339         [ $? = 0 ] || error "dd write failed"
1340         writes=$(echo $writes | awk  -F '+' '/out/ {print $1}')
1341         lctl set_param fail_loc=0
1342         sync
1343         zconf_umount `hostname` $MOUNT2 -f
1344         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1)
1345         [ $? = 0 ] || error "dd read failed"
1346         reads=$(echo $reads | awk -F '+' '/in/ {print $1}')
1347         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
1348 }
1349 run_test 59 "Read cancel race on client eviction"
1350
1351 err17935 () {
1352         # we assume that all md changes are in the MDT0 changelog
1353         if [ $MDSCOUNT -gt 1 ]; then
1354                 error_ignore bz17935 $*
1355         else
1356                 error $*
1357         fi
1358 }
1359
1360 test_60() {
1361         MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
1362                 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
1363
1364         NUM_FILES=15000
1365         mkdir -p $DIR/$tdir
1366
1367         # Register (and start) changelog
1368         USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
1369         echo "Registered as $MDT0 changelog user $USER"
1370
1371         # Generate a large number of changelog entries
1372         createmany -o $DIR/$tdir/$tfile $NUM_FILES
1373         sync
1374         sleep 5
1375
1376         # Unlink files in the background
1377         unlinkmany $DIR/$tdir/$tfile $NUM_FILES &
1378         CLIENT_PID=$!
1379         sleep 1
1380
1381         # Failover the MDS while unlinks are happening
1382         facet_failover $SINGLEMDS
1383
1384         # Wait for unlinkmany to finish
1385         wait $CLIENT_PID
1386
1387         # Check if all the create/unlink events were recorded
1388         # in the changelog
1389         $LFS changelog $MDT0 >> $DIR/$tdir/changelog
1390         local cl_count=$(grep UNLNK $DIR/$tdir/changelog | wc -l)
1391         echo "$cl_count unlinks in $MDT0 changelog"
1392
1393         do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $USER
1394         USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
1395             mdd.$MDT0.changelog_users | wc -l) - 2 ))
1396         if [ $USERS -eq 0 ]; then
1397             [ $cl_count -eq $NUM_FILES ] || \
1398                 err17935 "Recorded ${cl_count} unlinks out of $NUM_FILES"
1399             # Also make sure we can clear large changelogs
1400             cl_count=$($LFS changelog $FSNAME | wc -l)
1401             [ $cl_count -le 2 ] || \
1402                 error "Changelog not empty: $cl_count entries"
1403         else
1404             # If there are other users, there may be other unlinks in the log
1405             [ $cl_count -ge $NUM_FILES ] || \
1406                 err17935 "Recorded ${cl_count} unlinks out of $NUM_FILES"
1407             echo "$USERS other changelog users; can't verify clear"
1408         fi
1409 }
1410 run_test 60 "Add Changelog entries during MDS failover"
1411
1412 test_61()
1413 {
1414         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1415         mdtosc=${mdtosc/-MDT*/-MDT\*}
1416         local cflags="osc.$mdtosc.connect_flags"
1417         do_facet $SINGLEMDS "lctl get_param -n $cflags" |grep -q skip_orphan
1418         [ $? -ne 0 ] && skip "don't have skip orphan feature" && return
1419
1420         mkdir -p $DIR/$tdir || error "mkdir dir $DIR/$tdir failed"
1421         # Set the default stripe of $DIR/$tdir to put the files to ost1
1422         $LFS setstripe -c 1 -i 0 $DIR/$tdir
1423
1424         replay_barrier $SINGLEMDS
1425         createmany -o $DIR/$tdir/$tfile-%d 10 
1426         local oid=$(do_facet ost1 "lctl get_param -n \
1427                 obdfilter.${ost1_svc}.last_id" | sed -e 's/.*://')
1428
1429         fail_abort $SINGLEMDS
1430
1431         touch $DIR/$tdir/$tfile
1432         local id=$($LFS getstripe $DIR/$tdir/$tfile |
1433                 awk '$1 == 0 { print $2 }')
1434         [ $id -le $oid ] && error "the orphan objid was reused, failed"
1435
1436         # Cleanup
1437         rm -rf $DIR/$tdir
1438 }
1439 run_test 61 "Verify to not reuse orphan objects - bug 17025"
1440
1441 # test_62 as seen it b2_1 please do not reuse test_62
1442 #test_62()
1443 #{
1444 #       zconf_umount `hostname` $DIR
1445 #       #define OBD_FAIL_PTLRPC_DELAY_IMP_FULL   0x516
1446 #       lctl set_param fail_loc=0x516
1447 #       mount_client $DIR
1448 #}
1449 #run_test 62 "Verify connection flags race - bug LU-1716"
1450
1451 test_66()
1452 {
1453         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.51) ]] ||
1454                 { skip "Need MDS version at least 2.7.51"; return 0; }
1455
1456         local list=$(comma_list $(osts_nodes))
1457
1458         # modify dir so that next revalidate would not obtain UPDATE lock
1459         touch $DIR
1460
1461         # drop 1 reply with UPDATE lock
1462         mcreate $DIR/$tfile || error "mcreate failed: $?"
1463         drop_ldlm_reply_once "stat $DIR/$tfile" &
1464         sleep 2
1465
1466         # make the re-sent lock to sleep
1467 #define OBD_FAIL_MDS_RESEND              0x136
1468         do_nodes $list $LCTL set_param fail_loc=0x80000136
1469
1470         #initiate the re-connect & re-send
1471         local mdccli=$($LCTL dl | awk '/-mdc-/ {print $4;}')
1472         local conn_uuid=$($LCTL get_param -n mdc.${mdccli}.mds_conn_uuid)
1473         $LCTL set_param "mdc.${mdccli}.import=connection=${conn_uuid}"
1474         sleep 2
1475
1476         #initiate the client eviction while enqueue re-send is in progress
1477         mds_evict_client
1478
1479         client_reconnect
1480         wait
1481 }
1482 run_test 66 "lock enqueue re-send vs client eviction"
1483
1484 test_65() {
1485         mount_client $DIR2
1486
1487         #grant lock1, export2
1488         $SETSTRIPE -i -0 $DIR2/$tfile || return 1
1489         $MULTIOP $DIR2/$tfile Ow  || return 2
1490
1491 #define OBD_FAIL_LDLM_BL_EVICT            0x31e
1492         do_facet ost $LCTL set_param fail_loc=0x31e
1493         #get waiting lock2, export1
1494         $MULTIOP $DIR/$tfile Ow &
1495         PID1=$!
1496         # let enqueue to get asleep
1497         sleep 2
1498
1499         #get lock2 blocked
1500         $MULTIOP $DIR2/$tfile Ow &
1501         PID2=$!
1502         sleep 2
1503
1504         #evict export1
1505         ost_evict_client
1506
1507         sleep 2
1508         do_facet ost $LCTL set_param fail_loc=0
1509
1510         wait $PID1
1511         wait $PID2
1512
1513         umount_client $DIR2
1514 }
1515 run_test 65 "lock enqueue for destroyed export"
1516
1517 check_cli_ir_state()
1518 {
1519         local NODE=${1:-$HOSTNAME}
1520         local st
1521         st=$(do_node $NODE "lctl get_param mgc.*.ir_state |
1522                             awk '/imperative_recovery:/ { print \\\$2}'")
1523         [ $st != ON -o $st != OFF -o $st != ENABLED -o $st != DISABLED ] ||
1524                 error "Error state $st, must be ENABLED or DISABLED"
1525         echo -n $st
1526 }
1527
1528 check_target_ir_state()
1529 {
1530         local target=${1}
1531         local name=${target}_svc
1532         local recovery_proc=obdfilter.${!name}.recovery_status
1533         local st
1534
1535         while : ; do
1536                 st=$(do_facet $target "$LCTL get_param -n $recovery_proc |
1537                         awk '/status:/{ print \\\$2}'")
1538                 [ x$st = xRECOVERING ] || break
1539         done
1540         st=$(do_facet $target "lctl get_param -n $recovery_proc |
1541                                awk '/IR:/{ print \\\$2}'")
1542         [ $st != ON -o $st != OFF -o $st != ENABLED -o $st != DISABLED ] ||
1543                 error "Error state $st, must be ENABLED or DISABLED"
1544         echo -n $st
1545 }
1546
1547 set_ir_status()
1548 {
1549         do_facet mgs lctl set_param -n mgs.MGS.live.$FSNAME="state=$1"
1550 }
1551
1552 get_ir_status()
1553 {
1554         local state=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
1555                                     awk '/state:/{ print \\\$2 }'")
1556         echo -n ${state/,/}
1557 }
1558
1559 nidtbl_version_mgs()
1560 {
1561         local ver=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
1562                                   awk '/nidtbl_version:/{ print \\\$2 }'")
1563         echo -n $ver
1564 }
1565
1566 # nidtbl_version_client <mds1|client> [node]
1567 nidtbl_version_client()
1568 {
1569         local cli=$1
1570         local node=${2:-$HOSTNAME}
1571
1572         if [ X$cli = Xclient ]; then
1573                 cli=$FSNAME-client
1574         else
1575                 local obdtype=${cli/%[0-9]*/}
1576                 [ $obdtype != mds ] && error "wrong parameters $cli"
1577
1578                 node=$(facet_active_host $cli)
1579                 local t=${cli}_svc
1580                 cli=${!t}
1581         fi
1582
1583         local vers=$(do_node $node "lctl get_param -n mgc.*.ir_state" |
1584                      awk "/$cli/{print \$6}" |sort -u)
1585
1586         # in case there are multiple mounts on the client node
1587         local arr=($vers)
1588         [ ${#arr[@]} -ne 1 ] && error "versions on client node mismatch"
1589         echo -n $vers
1590 }
1591
1592 nidtbl_versions_match()
1593 {
1594         [ $(nidtbl_version_mgs) -eq $(nidtbl_version_client ${1:-client}) ]
1595 }
1596
1597 target_instance_match()
1598 {
1599         local srv=$1
1600         local obdtype
1601         local cliname
1602
1603         obdtype=${srv/%[0-9]*/}
1604         case $obdtype in
1605         mds)
1606                 obdname="mdt"
1607                 cliname="mdc"
1608                 ;;
1609         ost)
1610                 obdname="obdfilter"
1611                 cliname="osc"
1612                 ;;
1613         *)
1614                 error "invalid target type" $srv
1615                 return 1
1616                 ;;
1617         esac
1618
1619         local target=${srv}_svc
1620         local si=$(do_facet $srv lctl get_param -n $obdname.${!target}.instance)
1621         local ci=$(lctl get_param -n $cliname.${!target}-${cliname}-*.import |
1622                 awk '/instance/{ print $2 }' | head -n1)
1623
1624         return $([ $si -eq $ci ])
1625 }
1626
1627 test_100()
1628 {
1629         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1630                 { skip "MGS without IR support"; return 0; }
1631
1632         # MDT was just restarted in the previous test, make sure everything
1633         # is all set.
1634         local cnt=30
1635         while [ $cnt -gt 0 ]; do
1636                 nidtbl_versions_match && break
1637                 sleep 1
1638                 cnt=$((cnt - 1))
1639         done
1640
1641         # disable IR
1642         set_ir_status disabled
1643
1644         local prev_ver=$(nidtbl_version_client client)
1645
1646         local saved_FAILURE_MODE=$FAILURE_MODE
1647         [ $(facet_host mgs) = $(facet_host ost1) ] && FAILURE_MODE="SOFT"
1648         fail ost1
1649
1650         # valid check
1651         [ $(nidtbl_version_client client) -eq $prev_ver ] ||
1652                 error "version must not change due to IR disabled"
1653         target_instance_match ost1 || error "instance mismatch"
1654
1655         # restore env
1656         set_ir_status full
1657         FAILURE_MODE=$saved_FAILURE_MODE
1658 }
1659 run_test 100 "IR: Make sure normal recovery still works w/o IR"
1660
1661 test_101()
1662 {
1663         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1664                 { skip "MGS without IR support"; return 0; }
1665
1666         set_ir_status full
1667
1668         local OST1_IMP=$(get_osc_import_name client ost1)
1669
1670         # disable pinger recovery
1671         lctl set_param -n osc.$OST1_IMP.pinger_recov=0
1672
1673         fail ost1
1674
1675         target_instance_match ost1 || error "instance mismatch"
1676         nidtbl_versions_match || error "version must match"
1677
1678         lctl set_param -n osc.$OST1_IMP.pinger_recov=1
1679 }
1680 run_test 101 "IR: Make sure IR works w/o normal recovery"
1681
1682 test_102()
1683 {
1684         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1685                 { skip "MGS without IR support"; return 0; }
1686
1687         local clients=${CLIENTS:-$HOSTNAME}
1688         local old_version
1689         local new_version
1690         local mgsdev=mgs
1691
1692         set_ir_status full
1693
1694         # let's have a new nidtbl version
1695         fail ost1
1696
1697         # sleep for a while so that clients can see the failure of ost
1698         # it must be MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC.
1699         # int mgc_request.c:
1700         # define MGC_TIMEOUT_MIN_SECONDS   5
1701         # define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 *
1702         local count=30  # 20 seconds at most
1703         while [ $count -gt 0 ]; do
1704                 nidtbl_versions_match && break
1705                 sleep 1
1706                 count=$((count-1))
1707         done
1708
1709         nidtbl_versions_match || error "nidtbl mismatch"
1710
1711         # get the version #
1712         old_version=$(nidtbl_version_client client)
1713
1714         zconf_umount_clients $clients $MOUNT || error "Cannot umount client"
1715
1716         # restart mgs
1717         combined_mgs_mds && mgsdev=mds1
1718         remount_facet $mgsdev
1719         fail ost1
1720
1721         zconf_mount_clients $clients $MOUNT || error "Cannot mount client"
1722
1723         # check new version
1724         new_version=$(nidtbl_version_client client)
1725         [ $new_version -lt $old_version ] &&
1726                 error "nidtbl version wrong after mgs restarts"
1727         return 0
1728 }
1729 run_test 102 "IR: New client gets updated nidtbl after MGS restart"
1730
1731 test_103()
1732 {
1733         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1734                 { skip "MGS without IR support"; return 0; }
1735
1736         combined_mgs_mds && skip "mgs and mds on the same target" && return 0
1737
1738         # workaround solution to generate config log on the mds
1739         remount_facet mds1
1740
1741         stop mgs
1742         stop mds1
1743
1744         # We need this test because mds is like a client in IR context.
1745         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS ||
1746                 error "MDS should start w/o mgs"
1747
1748         # start mgs and remount mds w/ ir
1749         start mgs $(mgsdevname) $MGS_MOUNT_OPTS
1750         clients_up
1751
1752         # remount client so that fsdb will be created on the MGS
1753         umount_client $MOUNT || error "umount failed"
1754         mount_client $MOUNT || error "mount failed"
1755
1756         # sleep 30 seconds so the MDS has a chance to detect MGS restarting
1757         local count=30
1758         while [ $count -gt 0 ]; do
1759                 [ $(nidtbl_version_client mds1) -ne 0 ] && break
1760                 sleep 1
1761                 count=$((count-1))
1762         done
1763
1764         # after a while, mds should be able to reconnect to mgs and fetch
1765         # up-to-date nidtbl version
1766         nidtbl_versions_match mds1 || error "mds nidtbl mismatch"
1767
1768         # reset everything
1769         set_ir_status full
1770 }
1771 run_test 103 "IR: MDS can start w/o MGS and get updated nidtbl later"
1772
1773 test_104()
1774 {
1775         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1776                 { skip "MGS without IR support"; return 0; }
1777
1778         set_ir_status full
1779
1780         stop ost1
1781         start ost1 $(ostdevname 1) "$OST_MOUNT_OPTS -onoir" ||
1782                 error "OST1 cannot start"
1783         clients_up
1784
1785         local ir_state=$(check_target_ir_state ost1)
1786         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1787                 error "ir status on ost1 should be DISABLED"
1788 }
1789 run_test 104 "IR: ost can disable IR voluntarily"
1790
1791 test_105()
1792 {
1793         [ -z "$RCLIENTS" ] && skip "Needs multiple clients" && return 0
1794         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1795                 { skip "MGS without IR support"; return 0; }
1796
1797         set_ir_status full
1798
1799         # get one of the clients from client list
1800         local rcli=$(echo $RCLIENTS |cut -d' ' -f 1)
1801
1802         local mount_opts=${MOUNT_OPTS:+$MOUNT_OPTS,}noir
1803         zconf_umount $rcli $MOUNT || error "umount failed"
1804         zconf_mount $rcli $MOUNT $mount_opts || error "mount failed"
1805
1806         # make sure lustre mount at $rcli disabling IR
1807         local ir_state=$(check_cli_ir_state $rcli)
1808         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1809                 error "IR state must be DISABLED at $rcli"
1810
1811         # Since the client just mounted, its last_rcvd entry is not on disk.
1812         # Send an RPC so exp_need_sync forces last_rcvd to commit this export
1813         # so the client can reconnect during OST recovery (LU-924, LU-1582)
1814         $SETSTRIPE -i 0 $DIR/$tfile
1815         dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 conv=sync
1816
1817         # make sure MGS's state is Partial
1818         [ $(get_ir_status) = "partial" ] || error "MGS IR state must be partial"
1819
1820         fail ost1
1821         # make sure IR on ost1 is DISABLED
1822         local ir_state=$(check_target_ir_state ost1)
1823         [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
1824                 error "IR status on ost1 should be DISABLED"
1825
1826         # remount with the default MOUNT_OPTS
1827         zconf_umount $rcli $MOUNT || error "umount failed"
1828         zconf_mount $rcli $MOUNT || error "mount failed"
1829
1830         # make sure MGS's state is full
1831         [ $(get_ir_status) = "full" ] || error "MGS IR status must be full"
1832
1833         fail ost1
1834         # make sure IR on ost1 is ENABLED
1835         local ir_state=$(check_target_ir_state ost1)
1836         [ $ir_state = "ENABLED" -o $ir_state = "ON" ] ||
1837                 error "IR status on ost1 should be ENABLED"
1838
1839         return 0
1840 }
1841 run_test 105 "IR: NON IR clients support"
1842
1843 cleanup_106() {
1844         trap 0
1845         umount_client $DIR2
1846         debugrestore
1847 }
1848
1849 test_106() { # LU-1789
1850         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.50) ]] ||
1851                 { skip "Need MDS version at least 2.3.50"; return 0; }
1852
1853 #define OBD_FAIL_MDC_LIGHTWEIGHT         0x805
1854         $LCTL set_param fail_loc=0x805
1855
1856         debugsave
1857         trap cleanup_106 EXIT
1858
1859         # enable lightweight flag on mdc connection
1860         mount_client $DIR2
1861
1862         local MDS_NEXP=$(do_facet $SINGLEMDS \
1863                          lctl get_param -n mdt.${mds1_svc}.num_exports |
1864                          cut -d' ' -f2)
1865         $LCTL set_param fail_loc=0
1866
1867         touch $DIR2/$tfile || error "failed to create empty file"
1868         replay_barrier $SINGLEMDS
1869
1870         $LCTL set_param debug=console
1871         $LCTL clear
1872         facet_failover $SINGLEMDS
1873
1874         # lightweight connection must be evicted
1875         touch -c $DIR2/$tfile || true
1876         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1877         evicted=`awk '/This client was evicted by .*MDT0000/ {
1878                                       print;
1879                       }' $TMP/lustre-log-$TESTNAME.log`
1880         [ -z "$evicted" ] && error "lightweight client not evicted by mds"
1881
1882         # and all operations performed by lightweight client should be
1883         # synchronous, so the file created before mds restart should be there
1884         $CHECKSTAT -t file $DIR/$tfile || error "file not present"
1885         rm -f $DIR/$tfile
1886
1887         cleanup_106
1888 }
1889 run_test 106 "lightweight connection support"
1890
1891 test_107 () {
1892         local CLIENT_PID
1893         local close_pid
1894
1895         mkdir -p $DIR/$tdir
1896         # OBD_FAIL_MDS_REINT_NET_REP   0x119
1897         do_facet $SINGLEMDS lctl set_param fail_loc=0x119
1898         multiop $DIR/$tdir D_c &
1899         close_pid=$!
1900         mkdir $DIR/$tdir/dir_106 &
1901         CLIENT_PID=$!
1902         do_facet $SINGLEMDS lctl set_param fail_loc=0
1903         fail $SINGLEMDS
1904
1905         wait $CLIENT_PID || rc=$?
1906         checkstat -t dir $DIR/$tdir/dir_106 || return 1
1907
1908         kill -USR1 $close_pid
1909         wait $close_pid || return 2
1910
1911         return $rc
1912 }
1913 run_test 107 "drop reint reply, then restart MDT"
1914
1915 test_108() {
1916         mkdir -p $DIR/$tdir
1917         $SETSTRIPE -c 1 -i 0 $DIR/$tdir
1918
1919         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=256 &
1920         local dd_pid=$!
1921         sleep 0.1
1922
1923         ost_evict_client
1924
1925         wait $dd_pid
1926
1927         client_up || error "reconnect failed"
1928         rm -f $DIR/$tdir/$tfile
1929 }
1930 run_test 108 "client eviction don't crash"
1931
1932 test_110a () {
1933         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1934         local remote_dir=$DIR/$tdir/remote_dir
1935         local MDTIDX=1
1936         local num
1937
1938         #prepare for 110 test, which need set striped dir on remote MDT.
1939         for num in $(seq $MDSCOUNT); do
1940                 do_facet mds$num \
1941                         lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
1942                                 2>/dev/null
1943         done
1944
1945         mkdir -p $DIR/$tdir
1946         drop_request "$LFS mkdir -i $MDTIDX -c2 $remote_dir" ||
1947                                         error "lfs mkdir failed"
1948         local diridx=$($GETSTRIPE -M $remote_dir)
1949         [ $diridx -eq $MDTIDX ] || error "$diridx != $MDTIDX"
1950
1951         rm -rf $DIR/$tdir || error "rmdir failed"
1952 }
1953 run_test 110a "create remote directory: drop client req"
1954
1955 test_110b () {
1956         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1957         local remote_dir=$DIR/$tdir/remote_dir
1958         local MDTIDX=1
1959
1960         mkdir -p $DIR/$tdir
1961         drop_reint_reply "$LFS mkdir -i $MDTIDX -c2 $remote_dir" ||
1962                                         error "lfs mkdir failed"
1963
1964         diridx=$($GETSTRIPE -M $remote_dir)
1965         [ $diridx -eq $MDTIDX ] || error "$diridx != $MDTIDX"
1966
1967         rm -rf $DIR/$tdir || error "rmdir failed"
1968 }
1969 run_test 110b "create remote directory: drop Master rep"
1970
1971 test_110c () {
1972         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1973         local remote_dir=$DIR/$tdir/remote_dir
1974         local MDTIDX=1
1975
1976         mkdir -p $DIR/$tdir
1977         drop_update_reply $MDTIDX "$LFS mkdir -i $MDTIDX -c2 $remote_dir" ||
1978                                                 error "lfs mkdir failed"
1979
1980         diridx=$($GETSTRIPE -M $remote_dir)
1981         [ $diridx -eq $MDTIDX ] || error "$diridx != $MDTIDX"
1982
1983         rm -rf $DIR/$tdir || error "rmdir failed"
1984 }
1985 run_test 110c "create remote directory: drop update rep on slave MDT"
1986
1987 test_110d () {
1988         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1989         local remote_dir=$DIR/$tdir/remote_dir
1990         local MDTIDX=1
1991
1992         mkdir -p $DIR/$tdir
1993         $LFS mkdir -i $MDTIDX -c2 $remote_dir || error "lfs mkdir failed"
1994
1995         drop_request "rm -rf $remote_dir" || error "rm remote dir failed"
1996
1997         rm -rf $DIR/$tdir || error "rmdir failed"
1998
1999         return 0
2000 }
2001 run_test 110d "remove remote directory: drop client req"
2002
2003 test_110e () {
2004         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2005         local remote_dir=$DIR/$tdir/remote_dir
2006         local MDTIDX=1
2007
2008         mkdir -p $DIR/$tdir
2009         $LFS mkdir -i $MDTIDX -c2 $remote_dir  || error "lfs mkdir failed"
2010         drop_reint_reply "rm -rf $remote_dir" || error "rm remote dir failed"
2011
2012         rm -rf $DIR/$tdir || error "rmdir failed"
2013
2014         return 0
2015 }
2016 run_test 110e "remove remote directory: drop master rep"
2017
2018 test_110f () {
2019         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2020         local remote_dir=$DIR/$tdir/remote_dir
2021         local MDTIDX=1
2022
2023         mkdir -p $DIR/$tdir
2024         $LFS mkdir -i $MDTIDX -c2 $remote_dir || error "lfs mkdir failed"
2025         drop_update_reply $MDTIDX "rm -rf $remote_dir" ||
2026                                         error "rm remote dir failed"
2027
2028         rm -rf $DIR/$tdir || error "rmdir failed"
2029 }
2030 run_test 110f "remove remote directory: drop slave rep"
2031
2032 test_110g () {
2033         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2034         local remote_dir=$DIR/$tdir/remote_dir
2035         local MDTIDX=1
2036
2037         mkdir -p $remote_dir
2038
2039         createmany -o $remote_dir/f 100
2040
2041         #define OBD_FAIL_MIGRATE_NET_REP                0x1800
2042         do_facet mds$MDTIDX lctl set_param fail_loc=0x1800
2043         $LFS migrate -m $MDTIDX $remote_dir || error "migrate failed"
2044         do_facet mds$MDTIDX lctl set_param fail_loc=0x0
2045
2046         for file in $(find $remote_dir); do
2047                 mdt_index=$($LFS getstripe -M $file)
2048                 [ $mdt_index == $MDTIDX ] ||
2049                         error "$file is not on MDT${MDTIDX}"
2050         done
2051
2052         rm -rf $DIR/$tdir || error "rmdir failed"
2053 }
2054 run_test 110g "drop reply during migration"
2055
2056 test_110h () {
2057         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2058         local src_dir=$DIR/$tdir/source_dir
2059         local tgt_dir=$DIR/$tdir/target_dir
2060         local MDTIDX=1
2061
2062         mkdir -p $src_dir
2063         $LFS mkdir -i $MDTIDX $tgt_dir
2064
2065         dd if=/etc/hosts of=$src_dir/src_file
2066         touch $tgt_dir/tgt_file
2067         drop_update_reply $MDTIDX \
2068                 "mrename $src_dir/src_file $tgt_dir/tgt_file" ||
2069                 error "mrename failed"
2070
2071         $CHECKSTAT -t file $src_dir/src_file &&
2072                                 error "src_file present after rename"
2073
2074         diff /etc/hosts $tgt_dir/tgt_file ||
2075                         error "file changed after rename"
2076
2077 }
2078 run_test 110h "drop update reply during cross-MDT file rename"
2079
2080 test_110i () {
2081         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2082         local src_dir=$DIR/$tdir/source_dir
2083         local tgt_dir=$DIR/$tdir/target_dir
2084         local MDTIDX=1
2085
2086         mkdir -p $src_dir
2087         $LFS mkdir -i $MDTIDX $tgt_dir
2088
2089         mkdir $src_dir/src_dir
2090         touch $src_dir/src_dir/a
2091         mkdir $tgt_dir/tgt_dir
2092         drop_update_reply $MDTIDX \
2093                 "mrename $src_dir/src_dir $tgt_dir/tgt_dir" ||
2094                 error "mrename failed"
2095
2096         $CHECKSTAT -t dir $src_dir/src_dir &&
2097                         error "src_dir present after rename"
2098
2099         $CHECKSTAT -t dir $tgt_dir/tgt_dir ||
2100                                 error "tgt_dir not present after rename"
2101
2102         $CHECKSTAT -t file $tgt_dir/tgt_dir/a ||
2103                                 error "a not present after rename"
2104 }
2105 run_test 110i "drop update reply during cross-MDT dir rename"
2106
2107 test_110j () {
2108         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
2109         local remote_dir=$DIR/$tdir/remote_dir
2110         local local_dir=$DIR/$tdir/local_dir
2111         local MDTIDX=1
2112
2113         mkdir -p $DIR/$tdir
2114         mkdir $DIR/$tdir/local_dir
2115         $LFS mkdir -i $MDTIDX $remote_dir
2116
2117         touch $local_dir/local_file
2118         drop_update_reply $MDTIDX \
2119                 "ln $local_dir/local_file $remote_dir/remote_file" ||
2120                 error "ln failed"
2121
2122         $CHECKSTAT -t file $remote_dir/remote_file ||
2123                                 error "remote not present after ln"
2124 }
2125 run_test 110j "drop update reply during cross-MDT ln"
2126
2127 # LU-2844 mdt prepare fail should not cause umount oops
2128 test_111 ()
2129 {
2130         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.62) ]] ||
2131                 { skip "Need MDS version at least 2.3.62"; return 0; }
2132
2133         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2134 #define OBD_FAIL_MDS_CHANGELOG_INIT 0x151
2135         do_facet $SINGLEMDS lctl set_param fail_loc=0x151
2136         stop $SINGLEMDS || error "stop MDS failed"
2137         start $SINGLEMDS $mdsdev && error "start MDS should fail"
2138         do_facet $SINGLEMDS lctl set_param fail_loc=0
2139         start $SINGLEMDS $mdsdev || error "start MDS failed"
2140 }
2141 run_test 111 "mdd setup fail should not cause umount oops"
2142
2143 # LU-793
2144 test_112a() {
2145         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
2146
2147         do_facet_random_file client $TMP/$tfile 100K ||
2148                 error_noexit "Create random file $TMP/$tfile"
2149
2150         pause_bulk "cp $TMP/$tfile $DIR/$tfile" $TIMEOUT ||
2151                 error_noexit "Can't pause_bulk copy"
2152
2153         df $DIR
2154         # expect cmp to succeed, client resent bulk
2155         cmp $TMP/$tfile $DIR/$tfile ||
2156                 error_noexit "Wrong data has been written"
2157         rm $DIR/$tfile ||
2158                 error_noexit "Can't remove file"
2159         rm $TMP/$tfile
2160 }
2161 run_test 112a "bulk resend while orignal request is in progress"
2162
2163 test_115_read() {
2164         local fail1=$1
2165         local fail2=$2
2166
2167         df $DIR
2168         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1
2169         cancel_lru_locks osc
2170
2171         # OST_READ       =  3,
2172         $LCTL set_param fail_loc=$fail1 fail_val=3
2173         dd of=/dev/null if=$DIR/$tfile bs=4096 count=1 &
2174         pid=$!
2175         sleep 1
2176
2177         set_nodes_failloc "$(osts_nodes)" $fail2
2178
2179         wait $pid || error "dd failed"
2180         return 0
2181 }
2182
2183 test_115_write() {
2184         local fail1=$1
2185         local fail2=$2
2186         local error=$3
2187         local fail_val2=${4:-0}
2188
2189         df $DIR
2190         touch $DIR/$tfile
2191
2192         # OST_WRITE      =  4,
2193         $LCTL set_param fail_loc=$fail1 fail_val=4
2194         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 oflag=dsync &
2195         pid=$!
2196         sleep 1
2197
2198         df $MOUNT
2199         set_nodes_failloc "$(osts_nodes)" $fail2 $fail_val2
2200
2201         wait $pid
2202         rc=$?
2203         [ $error -eq 0 ] && [ $rc -ne 0 ] && error "dd error ($rc)"
2204         [ $error -ne 0 ] && [ $rc -eq 0 ] && error "dd success"
2205         return 0
2206 }
2207
2208 test_115a() {
2209         [ $(lustre_version_code ost1) -lt $(version_code 2.8.50) ] &&
2210                 skip "need at least 2.8.50 on OST" && return 0
2211
2212         #define OBD_FAIL_PTLRPC_LONG_REQ_UNLINK  0x51b
2213         #define OBD_FAIL_PTLRPC_DROP_BULK        0x51a
2214         test_115_read 0x8000051b 0x8000051a
2215 }
2216 run_test 115a "read: late REQ MDunlink and no bulk"
2217
2218 test_115b() {
2219         [ $(lustre_version_code ost1) -lt $(version_code 2.8.50) ] &&
2220                 skip "need at least 2.8.50 on OST" && return 0
2221
2222         #define OBD_FAIL_PTLRPC_LONG_REQ_UNLINK  0x51b
2223         #define OBD_FAIL_OST_ENOSPC              0x215
2224
2225         # pass $OSTCOUNT for the fail_loc to be caught
2226         # appropriately by the IO thread
2227         test_115_write 0x8000051b 0x80000215 1 $OSTCOUNT
2228 }
2229 run_test 115b "write: late REQ MDunlink and no bulk"
2230
2231 test_115c() {
2232         [ $(lustre_version_code ost1) -lt $(version_code 2.8.50) ] &&
2233                 skip "need at least 2.8.50 on OST" && return 0
2234
2235         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK 0x50f
2236         #define OBD_FAIL_PTLRPC_DROP_BULK        0x51a
2237         test_115_read 0x8000050f 0x8000051a
2238 }
2239 run_test 115c "read: late Reply MDunlink and no bulk"
2240
2241 test_115d() {
2242         [ $(lustre_version_code ost1) -lt $(version_code 2.8.50) ] &&
2243                 skip "need at least 2.8.50 on OST" && return 0
2244
2245         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK 0x50f
2246         #define OBD_FAIL_OST_ENOSPC              0x215
2247         test_115_write 0x8000050f 0x80000215 0
2248 }
2249 run_test 115d "write: late Reply MDunlink and no bulk"
2250
2251 test_115e() {
2252         [ $(lustre_version_code ost1) -lt $(version_code 2.8.50) ] &&
2253                 skip "need at least 2.8.50 on OST" && return 0
2254
2255         #define OBD_FAIL_PTLRPC_LONG_BULK_UNLINK 0x510
2256         #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
2257         test_115_read 0x80000510 0x80000211
2258 }
2259 run_test 115e "read: late Bulk MDunlink and no reply"
2260
2261 test_115f() {
2262         [ $(lustre_version_code ost1) -lt $(version_code 2.8.50) ] &&
2263                 skip "need at least 2.8.50 on OST" && return 0
2264
2265         #define OBD_FAIL_PTLRPC_LONG_REQ_UNLINK  0x51b
2266         #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
2267         test_115_read 0x8000051b 0x80000211
2268 }
2269 run_test 115f "read: late REQ MDunlink and no reply"
2270
2271 test_115g() {
2272         [ $(lustre_version_code ost1) -lt $(version_code 2.8.50) ] &&
2273                 skip "need at least 2.8.50 on OST" && return 0
2274
2275         #define OBD_FAIL_PTLRPC_LONG_BOTH_UNLINK 0x51c
2276         test_115_read 0x8000051c 0
2277 }
2278 run_test 115g "read: late REQ MDunlink and Reply MDunlink"
2279
2280 # parameters: fail_loc CMD RC
2281 test_120_reply() {
2282         local PID
2283         local PID2
2284         local rc=5
2285         local fail
2286
2287         #define OBD_FAIL_LDLM_CP_CB_WAIT2       0x320
2288         #define OBD_FAIL_LDLM_CP_CB_WAIT3       0x321
2289         #define OBD_FAIL_LDLM_CP_CB_WAIT4       0x322
2290         #define OBD_FAIL_LDLM_CP_CB_WAIT5       0x323
2291
2292         echo
2293         echo -n "** FLOCK REPLY vs. EVICTION race, lock $2"
2294         [ "$1" = "CLEANUP" ] &&
2295                 fail=0x80000320 && echo ", $1 cp first"
2296         [ "$1" = "REPLY" ] &&
2297                 fail=0x80000321 && echo ", $1 cp first"
2298         [ "$1" = "DEADLOCK CLEANUP" ] &&
2299                 fail=0x80000322 && echo " DEADLOCK, CLEANUP cp first"
2300         [ "$1" = "DEADLOCK REPLY" ] &&
2301                 fail=0x80000323 && echo " DEADLOCK, REPLY cp first"
2302
2303         if [ x"$2" = x"get" ]; then
2304                 #for TEST lock, take a conflict in advance
2305                 # sleep longer than evictor to not confuse fail_loc: 2+2+4
2306                 echo "** Taking conflict **"
2307                 flocks_test 5 set read sleep 10 $DIR/$tfile &
2308                 PID2=$!
2309
2310                 sleep 2
2311         fi
2312
2313         $LCTL set_param fail_loc=$fail
2314
2315         flocks_test 5 $2 write $DIR/$tfile &
2316         PID=$!
2317
2318         sleep 2
2319         echo "** Evicting and re-connecting client **"
2320         mds_evict_client
2321
2322         client_reconnect
2323
2324         if [ x"$2" = x"get" ]; then
2325                 wait $PID2
2326         fi
2327
2328         wait $PID
2329         rc=$?
2330
2331         # check if the return value is allowed
2332         [ $rc -eq $3 ] && rc=0
2333
2334         $LCTL set_param fail_loc=0
2335         return $rc
2336 }
2337
2338 # a lock is taken, unlock vs. cleanup_resource() race for destroying
2339 # the ORIGINAL lock.
2340 test_120_destroy()
2341 {
2342         local PID
2343
2344         flocks_test 5 set write sleep 4 $DIR/$tfile &
2345         PID=$!
2346         sleep 2
2347
2348         # let unlock to sleep in CP CB
2349         $LCTL set_param fail_loc=$1
2350         sleep 4
2351
2352         # let cleanup to cleep in CP CB
2353         mds_evict_client
2354
2355         client_reconnect
2356
2357         wait $PID
2358         rc=$?
2359
2360         $LCTL set_param fail_loc=0
2361         return $rc
2362 }
2363
2364 test_120() {
2365         flock_is_enabled || { skip "mount w/o flock enabled" && return; }
2366         touch $DIR/$tfile
2367
2368         test_120_reply "CLEANUP" set 5 || error "SET race failed"
2369         test_120_reply "CLEANUP" get 5 || error "GET race failed"
2370         test_120_reply "CLEANUP" unlock 5 || error "UNLOCK race failed"
2371
2372         test_120_reply "REPLY" set 5 || error "SET race failed"
2373         test_120_reply "REPLY" get 5 || error "GET race failed"
2374         test_120_reply "REPLY" unlock 5 || error "UNLOCK race failed"
2375
2376         # DEADLOCK tests
2377         test_120_reply "DEADLOCK CLEANUP" set 5 || error "DEADLOCK race failed"
2378         test_120_reply "DEADLOCK REPLY" set 35 || error "DEADLOCK race failed"
2379
2380         test_120_destroy 0x320 || error "unlock-cleanup race failed"
2381 }
2382 run_test 120 "flock race: completion vs. evict"
2383
2384 test_113() {
2385         local BEFORE=$(date +%s)
2386         local EVICT
2387
2388         # modify dir so that next revalidate would not obtain UPDATE lock
2389         touch $DIR
2390
2391         # drop 1 reply with UPDATE lock,
2392         # resend should not create 2nd lock on server
2393         mcreate $DIR/$tfile || error "mcreate failed: $?"
2394         drop_ldlm_reply_once "stat $DIR/$tfile" || error "stat failed: $?"
2395
2396         # 2 BL AST will be sent to client, both must find the same lock,
2397         # race them to not get EINVAL for 2nd BL AST
2398         #define OBD_FAIL_LDLM_PAUSE_CANCEL2      0x31f
2399         $LCTL set_param fail_loc=0x8000031f
2400
2401         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=0 > /dev/null
2402         chmod 0777 $DIR/$tfile || error "chmod failed: $?"
2403         $LCTL set_param ldlm.namespaces.*.early_lock_cancel=1 > /dev/null
2404
2405         # let the client reconnect
2406         client_reconnect
2407         EVICT=$($LCTL get_param mdc.$FSNAME-MDT*.state |
2408           awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
2409
2410         [ -z "$EVICT" ] || [[ $EVICT -le $BEFORE ]] || error "eviction happened"
2411 }
2412 run_test 113 "ldlm enqueue dropped reply should not cause deadlocks"
2413
2414 T130_PID=0
2415 test_130_base() {
2416         test_mkdir -p $DIR/$tdir
2417
2418         # Prevent interference from layout intent RPCs due to
2419         # asynchronous writeback. These will be tested in 130c below.
2420         do_nodes ${CLIENTS:-$HOSTNAME} sync
2421
2422         # get only LOOKUP lock on $tdir
2423         cancel_lru_locks mdc
2424         ls $DIR/$tdir/$tfile 2>/dev/null
2425
2426         # get getattr by fid on $tdir
2427         #
2428         # we need to race with unlink, unlink must complete before we will
2429         # take a DLM lock, otherwise unlink will wait until getattr will
2430         # complete; but later than getattr starts so that getattr found
2431         # the object
2432 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
2433         set_nodes_failloc "$(mdts_nodes)" 0x80000160
2434         stat $DIR/$tdir &
2435         T130_PID=$!
2436         sleep 2
2437
2438         rm -rf $DIR/$tdir
2439
2440         # drop the reply so that resend happens on an unlinked file.
2441 #define OBD_FAIL_MDS_LDLM_REPLY_NET      0x157
2442         set_nodes_failloc "$(mdts_nodes)" 0x80000157
2443 }
2444
2445 test_130a() {
2446         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2447         test_130_base
2448
2449         wait $T130_PID || [ $? -eq 0 ] && error "stat should fail"
2450         return 0
2451 }
2452 run_test 130a "enqueue resend on not existing file"
2453
2454 test_130b() {
2455         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2456         test_130_base
2457         # let the reply to be dropped
2458         sleep 10
2459
2460 #define OBD_FAIL_SRV_ENOENT              0x217
2461         set_nodes_failloc "$(mdts_nodes)" 0x80000217
2462
2463         wait $T130_PID || [ $? -eq 0 ] && error "stat should fail"
2464         return 0
2465 }
2466 run_test 130b "enqueue resend on a stale inode"
2467
2468 test_130c() {
2469         remote_mds_nodsh && skip "remote MDS with nodsh" && return
2470
2471         do_nodes ${CLIENTS:-$HOSTNAME} sync
2472         echo XXX > $DIR/$tfile
2473
2474         cancel_lru_locks mdc
2475
2476         # Trigger writeback on $tfile.
2477         #
2478         # we need to race with unlink, unlink must complete before we will
2479         # take a DLM lock, otherwise unlink will wait until intent will
2480         # complete; but later than intent starts so that intent found
2481         # the object
2482 #define OBD_FAIL_MDS_INTENT_DELAY               0x160
2483         set_nodes_failloc "$(mdts_nodes)" 0x80000160
2484         sync &
2485         T130_PID=$!
2486         sleep 2
2487
2488         rm $DIR/$tfile
2489
2490         # drop the reply so that resend happens on an unlinked file.
2491 #define OBD_FAIL_MDS_LDLM_REPLY_NET      0x157
2492         set_nodes_failloc "$(mdts_nodes)" 0x80000157
2493
2494         # let the reply to be dropped
2495         sleep 10
2496
2497 #define OBD_FAIL_SRV_ENOENT              0x217
2498         set_nodes_failloc "$(mdts_nodes)" 0x80000217
2499
2500         wait $T130_PID
2501
2502         return 0
2503 }
2504 run_test 130c "layout intent resend on a stale inode"
2505
2506 test_132() {
2507         local before=$(date +%s)
2508         local evict
2509
2510         mount_client $MOUNT2 || error "mount filed"
2511
2512         rm -f $DIR/$tfile
2513         # get a lock on client so that export would reach the stale list
2514         $SETSTRIPE -i 0 $DIR/$tfile || error "setstripe failed"
2515         dd if=/dev/zero of=$DIR/$tfile bs=4096 count=1 conv=fsync ||
2516                 error "dd failed"
2517
2518         #define OBD_FAIL_OST_PAUSE_PUNCH         0x236
2519         do_facet ost1 $LCTL set_param fail_val=120 fail_loc=0x80000236
2520
2521         $TRUNCATE $DIR/$tfile 100 &
2522
2523         sleep 1
2524         dd if=/dev/zero of=$DIR2/$tfile bs=4096 count=1 conv=notrunc ||
2525                 error "dd failed"
2526
2527         wait
2528         umount_client $MOUNT2
2529
2530         evict=$(do_facet client $LCTL get_param \
2531                 osc.$FSNAME-OST0000-osc-*/state |
2532             awk -F"[ [,]" '/EVICTED ]$/ { if (t<$5) {t=$5;} } END { print t }')
2533
2534         [ -z "$evict" ] || [[ $evict -le $before ]] ||
2535                 (do_facet client $LCTL get_param \
2536                         osc.$FSNAME-OST0000-osc-*/state;
2537                     error "eviction happened: $evict before:$before")
2538 }
2539 run_test 132 "long punch"
2540
2541 test_131() {
2542         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
2543
2544         rm -f $DIR/$tfile
2545         # get a lock on client so that export would reach the stale list
2546         $SETSTRIPE -i 0 $DIR/$tfile || error "setstripe failed"
2547         dd if=/dev/zero of=$DIR/$tfile count=1 || error "dd failed"
2548
2549         # another IO under the same lock
2550         #define OBD_FAIL_OSC_DELAY_IO            0x414
2551         $LCTL set_param fail_loc=0x80000414
2552         $LCTL set_param fail_val=4 fail_loc=0x80000414
2553         dd if=/dev/zero of=$DIR/$tfile count=1 conv=notrunc oflag=dsync &
2554         local pid=$!
2555         sleep 1
2556
2557         #define OBD_FAIL_LDLM_BL_EVICT           0x31e
2558         set_nodes_failloc "$(osts_nodes)" 0x8000031e
2559         ost_evict_client
2560         client_reconnect
2561
2562         wait $pid && error "dd succeeded"
2563         return 0
2564 }
2565 run_test 131 "IO vs evict results to IO under staled lock"
2566
2567 test_133() {
2568         local list=$(comma_list $(mdts_nodes))
2569
2570         local t=$((TIMEOUT * 2))
2571         touch $DIR/$tfile
2572
2573         flock $DIR/$tfile -c "echo bl lock;sleep $t;echo bl flock unlocked" &
2574         sleep 1
2575         multiop_bg_pause $DIR/$tfile O_jc || return 1
2576         PID=$!
2577
2578         #define OBD_FAIL_LDLM_REPLY              0x30c
2579         do_nodes $list $LCTL set_param fail_loc=0x8000030c
2580         kill -USR1 $PID
2581         echo "waiting for multiop $PID"
2582         wait $PID || return 2
2583
2584         rm -f $DIR/$tfile
2585
2586         return 0
2587 }
2588 run_test 133 "don't fail on flock resend"
2589
2590 test_134() {
2591         local file1
2592         local pid1
2593         local pid2
2594         local i
2595
2596         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return 0
2597         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.59) ]] &&
2598                 skip "Need MDS version at least 2.8.59" && return
2599
2600         test_mkdir -p $DIR/$tdir
2601         file1="$DIR/$tdir/file1"
2602         file2="$DIR/$tdir/file2"
2603
2604 #define OBD_FAIL_MDS_OSP_PRECREATE_WAIT  0x164
2605         # reserve stripe on ost1, block on ost2
2606         do_facet $SINGLEMDS \
2607                 "lctl set_param fail_loc=0x80000164 fail_val=1"
2608         $SETSTRIPE  -c 2 -o 0,1 $file1 &
2609         pid1=$!
2610         sleep 1
2611
2612         # initiate recovery with orphan cleanup on ost1
2613         facet_failover ost1
2614
2615         # when OST1 recovery is over, the first setstripe should still
2616         # have the object reserved, but that should not block new creates
2617         # on OST1
2618         $SETSTRIPE  -c 1 -o 0 $file2 &
2619         pid2=$!
2620         for ((i=0;i<$((TIMEOUT/2));i++)); do
2621                 if ! stat /proc/$pid2 >&/dev/null; then
2622                         echo "DONE!"
2623                         break
2624                 fi
2625                 echo "WAITING ..."
2626                 sleep 1
2627         done
2628         if let "i >= (TIMEOUT/2)"; then
2629                 error "create seem to get blocked by recovery"
2630         fi
2631         wait $pid1
2632         wait $pid2
2633         return 0
2634 }
2635 run_test 134 "MDT<>OST recovery don't block multistripe file creation"
2636
2637 complete $SECONDS
2638 check_and_cleanup_lustre
2639 exit_status