Whamcloud - gitweb
b=1719
[fs/lustre-release.git] / lustre / tests / recovery-cleanup.sh
1 #!/bin/sh
2
3 set -ex
4
5 LUSTRE=${LUSTRE:-`dirname $0`/..}
6 LTESTDIR=${LTESTDIR:-"$LUSTRE/../ltest"}
7 PATH=$PATH:$LUSTRE/utils:$LUSTRE/tests
8
9 . $LTESTDIR/functional/llite/common/common.sh
10
11 # Allow us to override the setup if we already have a mounted system by
12 # setting SETUP=" " and CLEANUP=" "
13 SETUP=${SETUP:-"setup"}
14 CLEANUP=${CLEANUP:-"cleanup"}
15
16 PDSH='pdsh -S -w'
17
18 # XXX I wish all this stuff was in some default-config.sh somewhere
19 MDSNODE=${MDSNODE:-mdev6}
20 OSTNODE=${OSTNODE:-mdev7}
21 CLIENT=${CLIENT:-mdev8}
22 NETWORKTYPE=${NETWORKTYPE:-tcp}
23 MOUNTPT=${MOUNTPT:-/mnt/lustre}
24 CONFIG=${CONFIG:-recovery-cleanup.xml}
25 MDSDEV=${MDSDEV:-/tmp/mds-`hostname`}
26 MDSSIZE=${MDSSIZE:-100000}
27 FSTYPE=${FSTYPE:-ext3}
28 OSTDEV=${OSTDEV:-/tmp/ost-`hostname`}
29 OSTSIZE=${OSTSIZE:-100000}
30
31 do_mds() {
32     $PDSH $MDSNODE "PATH=\$PATH:$LUSTRE/utils:$LUSTRE/tests; cd $PWD; $@" || exit $?
33 }
34
35 do_client() {
36     $PDSH $CLIENT "PATH=\$PATH:$LUSTRE/utils:$LUSTRE/tests; cd $PWD; $@" || exit $?
37 }
38
39 do_ost() {
40     $PDSH $OSTNODE "PATH=\$PATH:$LUSTRE/utils:$LUSTRE/tests; cd $PWD; $@" || exit $?
41 }
42
43 drop_request() {
44     do_mds "echo 0x121 > /proc/sys/lustre/fail_loc"
45     do_client "$1 & sleep ${TIMEOUT:-5}; sleep 2; kill \$!"
46     do_mds "echo 0 > /proc/sys/lustre/fail_loc"
47 }
48
49 make_config() {
50     rm -f $CONFIG
51     for NODE in $CLIENT $MDSNODE $OSTNODE; do
52        lmc -m $CONFIG --add net --node $NODE --nid `h2$NETWORKTYPE $NODE` \
53            --nettype $NETWORKTYPE || exit 4
54     done
55     lmc -m $CONFIG --add mds --node $MDSNODE --mds mds1 --fstype $FSTYPE \
56         --dev $MDSDEV --size $MDSSIZE || exit 5
57     lmc -m $CONFIG --add lov --lov lov1 --mds mds1 --stripe_sz 65536 \
58         --stripe_cnt 0 --stripe_pattern 0 || exit 6
59     lmc -m $CONFIG --add ost --nspath /mnt/ost_ns --node $OSTNODE \
60         --lov lov1 --dev $OSTDEV --size $OSTSIZE --fstype $FSTYPE || exit 7
61     lmc -m $CONFIG --add mtpt --node $CLIENT --path $MOUNTPT --mds mds1 \
62         --lov lov1 || exit 8
63 }
64
65 start_mds() {
66     do_mds "lconf $@ $CONFIG"
67 }
68
69 shutdown_mds() {
70     do_mds "lconf $@ --cleanup $CONFIG"
71 }
72
73 start_ost() {
74     do_ost "lconf $@ $CONFIG"
75 }
76
77 shutdown_ost() {
78     do_ost "lconf $@ --cleanup $CONFIG"
79 }
80
81 mount_client() {
82     do_client "lconf $@ $CONFIG"
83 }
84
85 unmount_client() {
86     do_client "lconf $@ --cleanup $CONFIG"
87 }
88
89 setup() {
90     make_config
91     start_mds ${REFORMAT:---reformat}
92     start_ost ${REFORMAT:---reformat}
93     mount_client --timeout=${TIMEOUT:-5} --lustre_upcall=/bin/true
94 }
95
96 cleanup() {
97     do_mds "echo 0 > /proc/sys/lustre/fail_loc"
98     unmount_client $@ || exit 97
99     shutdown_mds $@ || exit 98
100     shutdown_ost $@ || exit 99
101 }
102
103 wait_for_timeout() {
104     # wait to make sure we enter recovery
105     # it'd be better if the upcall notified us somehow, I think
106     sleep $(( ${TIMEOUT:-5} + 2 ))
107 }
108
109 try_to_cleanup() {
110     kill -INT $!
111     unmount_client --force --dump /tmp/client-cleanup-`date +%s`.log
112     mount_client --timeout=${TIMEOUT:-5} --lustre_upcall=/bin/true
113 }
114
115 if [ ! -z "$ONLY" ]; then
116     eval "$ONLY"
117     exit $?
118 fi
119
120 $SETUP
121
122 drop_request "mcreate /mnt/lustre/1" & wait_for_timeout
123 try_to_cleanup
124
125 drop_request "tchmod 111 /mnt/lustre/2" & wait_for_timeout
126 try_to_cleanup
127
128 drop_request "statone /mnt/lustre/2" & wait_for_timeout
129 try_to_cleanup
130
131 do_client "cp /etc/resolv.conf /mnt/lustre/resolv.conf"
132 drop_request "cat /mnt/lustre/resolv.conf > /dev/null" & wait_for_timeout
133 try_to_cleanup
134
135 drop_request "mv /mnt/lustre/resolv.conf /mnt/lustre/renamed" & wait_for_timeout
136 try_to_cleanup
137
138 drop_request "mlink /mnt/lustre/renamed-again /mnt/lustre/link1" & wait_for_timeout
139 try_to_cleanup
140
141 drop_request "munlink /mnt/lustre/link1" & wait_for_timeout
142 try_to_cleanup
143
144 $CLEANUP '--dump /tmp/`hostname`-cleanup.log'