Whamcloud - gitweb
fe232a40028091b5e7c4d2a80378a81e44f34a4f
[fs/lustre-release.git] / lustre / tests / replay-ost-single.sh
1 #!/bin/bash
2
3 set -e
4
5 PTLDEBUG=${PTLDEBUG:--1}
6 LUSTRE=${LUSTRE:-`dirname $0`/..}
7 CLEANUP=${CLEANUP:-""}
8 . $LUSTRE/tests/test-framework.sh
9 init_test_env $@
10 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
11
12 ostfailover_HOST=${ostfailover_HOST:-$ost_HOST}
13 #failover= must be defined in OST_MKFS_OPTIONS if ostfailover_HOST != ost_HOST
14
15 # Tests that fail on uml
16 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
17 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 6"
18
19 # Skip these tests
20 # BUG NUMBER: 
21 ALWAYS_EXCEPT="$REPLAY_OST_SINGLE_EXCEPT"
22
23 # It is replay-ost-single, after all
24 OSTCOUNT=1
25
26 gen_config() {
27     formatall
28 }
29
30 cleanup() {
31     cleanupall
32 }
33
34 if [ "$ONLY" == "cleanup" ]; then
35     cleanup
36     exit
37 fi
38
39 build_test_filter
40
41 SETUP=${SETUP:-"setup"}
42
43 test_0a() {
44     # needs to run during initial client->OST connection
45     #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
46     do_facet ost "sysctl -w lustre.fail_loc=0x80000211"
47     zconf_mount `hostname` $MOUNT && df $MOUNT || error "0a mount fail"
48 }
49
50 setup() {
51     gen_config
52     start mds1 `mdsdevname 1` $MDS_MOUNT_OPTS
53     start ost1 `ostdevname 1` $OST_MOUNT_OPTS
54     [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
55
56     # this might not mount if we aren't running test 0a
57     [ -z "`grep " $MOUNT " /proc/mounts`" ] && \
58         run_test 0a "target handle mismatch (bug 5317) `date +%H:%M:%S`" 
59
60     if [ -z "`grep " $MOUNT " /proc/mounts`" ]; then
61         zconf_mount `hostname` $MOUNT || error "mount fail"
62     fi
63     sleep 5
64
65     do_facet ost1 "sysctl -w lustre.fail_loc=0"
66 }
67
68 mkdir -p $DIR
69
70 $SETUP
71
72 test_0b() {
73     fail ost1
74     cp /etc/profile  $DIR/$tfile
75     sync
76     diff /etc/profile $DIR/$tfile
77     rm -f $DIR/$tfile
78 }
79 run_test 0b "empty replay"
80
81 test_1() {
82     date > $DIR/$tfile
83     fail ost1
84     $CHECKSTAT -t file $DIR/$tfile || return 1
85     rm -f $DIR/$tfile
86 }
87 run_test 1 "touch"
88
89 test_2() {
90     for i in `seq 10`; do
91         echo "tag-$i" > $DIR/$tfile-$i
92     done 
93     fail ost1
94     for i in `seq 10`; do
95       grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
96     done 
97     rm -f $DIR/$tfile-*
98 }
99 run_test 2 "|x| 10 open(O_CREAT)s"
100
101 test_3() {
102     verify=$ROOT/tmp/verify-$$
103     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $DIR/$tfile &
104     ddpid=$!
105     sync &
106     fail ost1
107     wait $ddpid || return 1
108     cmp $verify $DIR/$tfile || return 2
109     rm -f $verify $DIR/$tfile
110 }
111 run_test 3 "Fail OST during write, with verification"
112
113 test_4() {
114     verify=$ROOT/tmp/verify-$$
115     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $DIR/$tfile
116     # invalidate cache, so that we're reading over the wire
117     cancel_lru_locks osc
118     cmp $verify $DIR/$tfile &
119     cmppid=$!
120     fail ost1
121     wait $cmppid || return 1
122     rm -f $verify $DIR/$tfile
123 }
124 run_test 4 "Fail OST during read, with verification"
125
126 test_5() {
127     [ -z "`which iozone 2> /dev/null`" ] && log "iozone missing" && return
128     FREE=`df -P -h $DIR | tail -n 1 | awk '{ print $3 }'`
129     case $FREE in
130     *T|*G) FREE=1G;;
131     esac
132     IOZONE_OPTS="-i 0 -i 1 -i 2 -+d -r 4 -s $FREE"
133     iozone $IOZONE_OPTS -f $DIR/$tfile &
134     PID=$!
135     
136     sleep 8
137     fail ost1
138     wait $PID
139     RC=$?
140     log "iozone rc=$RC"
141     rm -f $DIR/$tfile
142     [ $RC -ne 0 ] && return $RC || true
143 }
144 run_test 5 "Fail OST during iozone"
145
146 kbytesfree() {
147    awk '{total+=$1} END {print total}' /proc/fs/lustre/osc/*-osc-*/kbytesfree
148 }
149
150 test_6() {
151     f=$DIR/$tfile
152     rm -f $f
153     sync && sleep 2 && sync     # wait for delete thread
154     before=`kbytesfree`
155     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 28
156     lfs getstripe $f
157     sync
158     sleep 2                                     # ensure we have a fresh statfs
159     sync
160 #define OBD_FAIL_MDS_REINT_NET_REP       0x119
161     do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
162     after_dd=`kbytesfree`
163     log "before: $before after_dd: $after_dd"
164     (( $before > $after_dd )) || return 1
165     rm -f $f
166     fail ost1
167     $CHECKSTAT -t file $f && return 2 || true
168     sync
169     # let the delete happen
170     sleep 5
171     after=`kbytesfree`
172     log "before: $before after: $after"
173     (( $before <= $after + 40 )) || return 3    # take OST logs into account
174 }
175 run_test 6 "Fail OST before obd_destroy"
176
177 test_7() {
178     f=$DIR/$tfile
179     rm -f $f
180     sync && sleep 5 && sync     # wait for delete thread
181     before=`kbytesfree`
182     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 4
183     sync
184     sleep 2                                     # ensure we have a fresh statfs
185     sync
186     after_dd=`kbytesfree`
187     log "before: $before after_dd: $after_dd"
188     (( $before > $after_dd )) || return 1
189     replay_barrier ost1
190     rm -f $f
191     fail ost1
192     $CHECKSTAT -t file $f && return 2 || true
193     sync
194     # let the delete happen
195     sleep 5
196     after=`kbytesfree`
197     log "before: $before after: $after"
198     (( $before <= $after + 40 )) || return 3    # take OST logs into account
199 }
200 run_test 7 "Fail OST before obd_destroy"
201
202 equals_msg `basename $0`: test complete, cleaning up
203 check_and_cleanup_lustre
204 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true