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