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