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