Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[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}
26 OSTDEV=${OSTDEV:-/tmp/ost}
27 MDSSIZE=${MDSSIZE:-100000}
28 OSTSIZE=${OSTSIZE:-100000}
29
30 do_mds() {
31     $PDSH $MDSNODE "PATH=\$PATH:$LUSTRE/utils:$LUSTRE/tests; cd $PWD; $@"
32 }
33
34 do_client() {
35     $PDSH $CLIENT "PATH=\$PATH:$LUSTRE/utils:$LUSTRE/tests; cd $PWD; $@"
36 }
37
38 do_ost() {
39     $PDSH $OSTNODE "PATH=\$PATH:$LUSTRE/utils:$LUSTRE/tests; cd $PWD; $@"
40 }
41
42 drop_request() {
43     do_mds "echo 0x121 > /proc/sys/lustre/fail_loc"
44     do_client "$1 & sleep ${TIMEOUT:-5}; sleep 2; kill \$!"
45     do_mds "echo 0 > /proc/sys/lustre/fail_loc"
46 }
47
48 make_config() {
49     rm -f $CONFIG
50     for NODE in $CLIENT $MDSNODE $OSTNODE; do
51        lmc -m $CONFIG --add net --node $NODE --nid `h2$NETWORKTYPE $NODE` \
52            --nettype $NETWORKTYPE || exit 4
53     done
54     lmc -m $CONFIG --add mds --node $MDSNODE --mds mds1 --dev $MDSDEV \
55         --size $MDSSIZE || exit 5
56     lmc -m $CONFIG --add ost --node $OSTNODE --ost ost1 --dev $OSTDEV \
57         --size $OSTSIZE || exit 6
58     lmc -m $CONFIG --add mtpt --node $CLIENT --path $MOUNTPT --mds mds1 \
59         --ost ost1 || exit 7
60 }
61
62 start_mds() {
63     do_mds "lconf $@ $CONFIG"
64 }
65
66 shutdown_mds() {
67     do_mds "lconf $@ --cleanup $CONFIG"
68 }
69
70 start_ost() {
71     do_ost "lconf $@ $CONFIG"
72 }
73
74 shutdown_ost() {
75     do_ost "lconf $@ --cleanup $CONFIG"
76 }
77
78 mount_client() {
79     do_client "lconf $@ $CONFIG"
80 }
81
82 unmount_client() {
83     do_client "lconf $@ --cleanup $CONFIG"
84 }
85
86 setup() {
87     make_config
88     start_mds ${REFORMAT:---reformat}
89     start_ost ${REFORMAT:---reformat}
90     mount_client --timeout=${TIMEOUT:-5} --recovery_upcall=/bin/true
91 }
92
93 cleanup() {
94     do_mds "echo 0 > /proc/sys/lustre/fail_loc"
95     unmount_client $@ || true
96     shutdown_mds $@ || true
97     shutdown_ost $@ || true
98 }
99
100 wait_for_timeout() {
101     # wait to make sure we enter recovery
102     # it'd be better if the upcall notified us somehow, I think
103     sleep $(( ${TIMEOUT:-5} + 2 ))
104 }
105
106 try_to_cleanup() {
107     kill -INT $!
108     unmount_client --force --dump /tmp/client-cleanup-`date +%s`.log
109     mount_client --timeout=${TIMEOUT:-5} --recovery_upcall=/bin/true
110 }
111
112 if [ ! -z "$ONLY" ]; then
113     eval "$ONLY"
114     exit $?
115 fi
116
117 $SETUP
118
119 drop_request "mcreate /mnt/lustre/1" & wait_for_timeout
120 try_to_cleanup
121
122 drop_request "tchmod 111 /mnt/lustre/2" & wait_for_timeout
123 try_to_cleanup
124
125 drop_request "statone /mnt/lustre/2" & wait_for_timeout
126 try_to_cleanup
127
128 do_client "cp /etc/resolv.conf /mnt/lustre/resolv.conf"
129 drop_request "cat /mnt/lustre/resolv.conf > /dev/null" & wait_for_timeout
130 try_to_cleanup
131
132 drop_request "mv /mnt/lustre/resolv.conf /mnt/lustre/renamed" & wait_for_timeout
133 try_to_cleanup
134
135 drop_request "mlink /mnt/lustre/renamed-again /mnt/lustre/link1" & wait_for_timeout
136 try_to_cleanup
137
138 drop_request "munlink /mnt/lustre/link1" & wait_for_timeout
139 try_to_cleanup
140
141 $CLEANUP '--dump /tmp/`hostname`-cleanup.log'