Whamcloud - gitweb
b=13974
[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 mds $MDSDEV $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
58     do_facet ost1 "sysctl -w lustre.fail_loc=0"
59 }
60
61 mkdir -p $DIR
62
63 $SETUP
64 test_0b() {
65     fail ost1
66     cp /etc/profile  $DIR/$tfile
67     sync
68     diff /etc/profile $DIR/$tfile
69     rm -f $DIR/$tfile
70 }
71 run_test 0b "empty replay"
72
73 test_1() {
74     date > $DIR/$tfile
75     fail ost1
76     $CHECKSTAT -t file $DIR/$tfile || return 1
77     rm -f $DIR/$tfile
78 }
79 run_test 1 "touch"
80
81 test_2() {
82     for i in `seq 10`; do
83         echo "tag-$i" > $DIR/$tfile-$i
84     done 
85     fail ost1
86     for i in `seq 10`; do
87       grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
88     done 
89     rm -f $DIR/$tfile-*
90 }
91 run_test 2 "|x| 10 open(O_CREAT)s"
92
93 test_3() {
94     verify=$ROOT/tmp/verify-$$
95     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $DIR/$tfile &
96     ddpid=$!
97     sync &
98     fail ost1
99     wait $ddpid || return 1
100     cmp $verify $DIR/$tfile || return 2
101     rm -f $verify $DIR/$tfile
102 }
103 run_test 3 "Fail OST during write, with verification"
104
105 test_4() {
106     verify=$ROOT/tmp/verify-$$
107     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $DIR/$tfile
108     # invalidate cache, so that we're reading over the wire
109     cancel_lru_locks osc
110     cmp $verify $DIR/$tfile &
111     cmppid=$!
112     fail ost1
113     wait $cmppid || return 1
114     rm -f $verify $DIR/$tfile
115 }
116 run_test 4 "Fail OST during read, with verification"
117
118 test_5() {
119     [ -z "`which iozone 2> /dev/null`" ] && log "iozone missing" && return
120     FREE=`df -P -h $DIR | tail -n 1 | awk '{ print $3 }'`
121     case $FREE in
122     *T|*G) FREE=1G;;
123     esac
124     IOZONE_OPTS="-i 0 -i 1 -i 2 -+d -r 4 -s $FREE"
125     iozone $IOZONE_OPTS -f $DIR/$tfile &
126     PID=$!
127     
128     sleep 8
129     fail ost1
130     wait $PID
131     RC=$?
132     log "iozone rc=$RC"
133     rm -f $DIR/$tfile
134     [ $RC -ne 0 ] && return $RC || true
135 }
136 run_test 5 "Fail OST during iozone"
137
138 kbytesfree() {
139    awk '{total+=$1} END {print total}' /proc/fs/lustre/osc/*-osc-*/kbytesfree
140 }
141
142 test_6() {
143     f=$DIR/$tfile
144     rm -f $f
145     sync && sleep 2 && sync     # wait for delete thread
146     before=`kbytesfree`
147     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 28
148     lfs getstripe $f
149     sync
150     sleep 2                                     # ensure we have a fresh statfs
151     sync
152 #define OBD_FAIL_MDS_REINT_NET_REP       0x119
153     do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
154     after_dd=`kbytesfree`
155     log "before: $before after_dd: $after_dd"
156     (( $before > $after_dd )) || return 1
157     rm -f $f
158     fail ost1
159     $CHECKSTAT -t file $f && return 2 || true
160     sync
161     # let the delete happen
162     sleep 5
163     after=`kbytesfree`
164     log "before: $before after: $after"
165     (( $before <= $after + 40 )) || return 3    # take OST logs into account
166 }
167 run_test 6 "Fail OST before obd_destroy"
168
169 test_7() {
170     f=$DIR/$tfile
171     rm -f $f
172     sync && sleep 2 && sync     # wait for delete thread
173     before=`kbytesfree`
174     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 4
175     sync
176     sleep 2                                     # ensure we have a fresh statfs
177     sync
178     after_dd=`kbytesfree`
179     log "before: $before after_dd: $after_dd"
180     (( $before > $after_dd )) || return 1
181     replay_barrier ost1
182     rm -f $f
183     fail ost1
184     $CHECKSTAT -t file $f && return 2 || true
185     sync
186     # let the delete happen
187     sleep 2
188     after=`kbytesfree`
189     log "before: $before after: $after"
190     (( $before <= $after + 40 )) || return 3    # take OST logs into account
191 }
192 run_test 7 "Fail OST before obd_destroy"
193
194 equals_msg `basename $0`: test complete, cleaning up
195 check_and_cleanup_lustre
196 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true