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