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