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