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