Whamcloud - gitweb
b=21115
[fs/lustre-release.git] / lustre / tests / replay-ost-single.sh
1 #!/bin/bash
2
3 set -e
4
5 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
6 SETUP=${SETUP:-""}
7 CLEANUP=${CLEANUP:-""}
8 . $LUSTRE/tests/test-framework.sh
9 init_test_env $@
10 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
11
12 # While we do not use OSTCOUNT=1 setup anymore,
13 # ost1failover_HOST is used
14 #ostfailover_HOST=${ostfailover_HOST:-$ost_HOST}
15 #failover= must be defined in OST_MKFS_OPTIONS if ostfailover_HOST != ost_HOST
16
17 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
18
19 if [ "$FAILURE_MODE" = "HARD" ] && mixed_ost_devs; then
20     skip_env "$0: Several ost services on one ost node are used with FAILURE_MODE=$FAILURE_MODE. "
21     exit 0
22 fi
23
24 # Tests that fail on uml
25 CPU=`awk '/model/ {print $4}' /proc/cpuinfo`
26 [ "$CPU" = "UML" ] && EXCEPT="$EXCEPT 6"
27
28 # Skip these tests
29 # BUG NUMBER: 
30 ALWAYS_EXCEPT="$REPLAY_OST_SINGLE_EXCEPT"
31
32 #                                       
33 [ "$SLOW" = "no" ] && EXCEPT_SLOW="5"
34
35 build_test_filter
36
37 check_and_setup_lustre
38 assert_DIR
39 rm -rf $DIR/[df][0-9]*
40
41 TDIR=$DIR/d0.${TESTSUITE}
42 mkdir -p $TDIR
43 $LFS setstripe $TDIR -i 0 -c 1
44 $LFS getstripe $TDIR
45
46 test_0a() {
47     zconf_umount `hostname` $MOUNT -f
48     # needs to run during initial client->OST connection
49     #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
50     do_facet ost1 "lctl set_param fail_loc=0x80000211"
51     zconf_mount `hostname` $MOUNT && df $MOUNT || error "0a mount fail"
52 }
53 run_test 0a "target handle mismatch (bug 5317) `date +%H:%M:%S`"
54
55 test_0b() {
56     fail ost1
57     cp /etc/profile  $TDIR/$tfile
58     sync
59     diff /etc/profile $TDIR/$tfile
60     rm -f $TDIR/$tfile
61 }
62 run_test 0b "empty replay"
63
64 test_1() {
65     date > $TDIR/$tfile || error "error creating $TDIR/$tfile"
66     fail ost1
67     $CHECKSTAT -t file $TDIR/$tfile || return 1
68     rm -f $TDIR/$tfile
69 }
70 run_test 1 "touch"
71
72 test_2() {
73     for i in `seq 10`; do
74         echo "tag-$i" > $TDIR/$tfile-$i || error "create $TDIR/$tfile-$i"
75     done 
76     fail ost1
77     for i in `seq 10`; do
78       grep -q "tag-$i" $TDIR/$tfile-$i || error "grep $TDIR/$tfile-$i"
79     done 
80     rm -f $TDIR/$tfile-*
81 }
82 run_test 2 "|x| 10 open(O_CREAT)s"
83
84 test_3() {
85     verify=$ROOT/tmp/verify-$$
86     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile &
87     ddpid=$!
88     sync &
89     fail ost1
90     wait $ddpid || return 1
91     cmp $verify $TDIR/$tfile || return 2
92     rm -f $verify $TDIR/$tfile
93 }
94 run_test 3 "Fail OST during write, with verification"
95
96 test_4() {
97     verify=$ROOT/tmp/verify-$$
98     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile
99     # invalidate cache, so that we're reading over the wire
100     cancel_lru_locks osc
101     cmp $verify $TDIR/$tfile &
102     cmppid=$!
103     fail ost1
104     wait $cmppid || return 1
105     rm -f $verify $TDIR/$tfile
106 }
107 run_test 4 "Fail OST during read, with verification"
108
109 iozone_bg () {
110     local args=$@
111
112     local tmppipe=$TMP/${TESTSUITE}.${TESTNAME}.pipe
113     mkfifo $tmppipe
114
115     echo "+ iozone $args"
116     iozone $args > $tmppipe &
117
118     local pid=$!
119
120     echo "tmppipe=$tmppipe"
121     echo iozone pid=$pid
122
123     # iozone exit code is 0 even if iozone is not completed
124     # need to check iozone output  on "complete"
125     local iozonelog=$TMP/${TESTSUITE}.iozone.log
126     rm -f $iozonelog
127     cat $tmppipe | while read line ; do
128         echo "$line"
129         echo "$line" >>$iozonelog
130     done;
131
132     local rc=0
133     wait $pid
134     rc=$?
135     if ! $(tail -1 $iozonelog | grep -q complete); then
136         echo iozone failed!
137         rc=1
138     fi
139     rm -f $tmppipe
140     rm -f $iozonelog
141     return $rc
142 }
143
144 test_5() {
145     [ -z "`which iozone 2> /dev/null`" ] && skip_env "iozone missing" && return 0
146
147     # striping is -c 1, get min of available
148     local minavail=$(lctl get_param -n osc.*[oO][sS][cC][-_]*.kbytesavail | sort -n | head -1)
149     local size=$(( minavail * 3/4 ))
150     local GB=1048576  # 1048576KB == 1GB
151
152     if (( size > GB )); then
153         size=$GB
154     fi
155     local iozone_opts="-i 0 -i 1 -i 2 -+d -r 4 -s $size -f $TDIR/$tfile"
156
157     iozone_bg $iozone_opts &
158     local pid=$!
159
160     echo iozone bg pid=$pid
161
162     sleep 8
163     fail ost1
164     local rc=0
165     wait $pid
166     rc=$?
167     log "iozone rc=$rc"
168     rm -f $TDIR/$tfile
169     [ $rc -eq 0 ] || error "iozone failed"
170     return $rc
171 }
172 run_test 5 "Fail OST during iozone"
173
174 kbytesfree() {
175    calc_osc_kbytes kbytesfree
176 }
177
178 test_6() {
179     remote_mds_nodsh && skip "remote MDS with nodsh" && return 0
180
181     f=$TDIR/$tfile
182     rm -f $f
183     sync && sleep 2 && sync     # wait for delete thread
184     before=`kbytesfree`
185     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 28
186     lfs getstripe $f
187     get_stripe_info client $f
188
189     sync
190     sleep 2 # ensure we have a fresh statfs
191     sync
192 #define OBD_FAIL_MDS_REINT_NET_REP       0x119
193     do_facet mds "lctl set_param fail_loc=0x80000119"
194     after_dd=`kbytesfree`
195     log "before: $before after_dd: $after_dd"
196     (( $before > $after_dd )) || return 1
197     rm -f $f
198     fail ost$((stripe_index + 1))
199     wait_recovery_complete ost$((stripe_index + 1)) || error "OST recovery not done"
200     $CHECKSTAT -t file $f && return 2 || true
201     sync
202     # let the delete happen
203     wait_mds_ost_sync || return 4
204     wait_destroy_complete || return 5
205     after=`kbytesfree`
206     log "before: $before after: $after"
207     (( $before <= $after + 40 )) || return 3    # take OST logs into account
208 }
209 run_test 6 "Fail OST before obd_destroy"
210
211 test_7() {
212     f=$TDIR/$tfile
213     rm -f $f
214     sync && sleep 5 && sync     # wait for delete thread
215     before=`kbytesfree`
216     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 4
217     sync
218     sleep 2 # ensure we have a fresh statfs
219     sync
220     after_dd=`kbytesfree`
221     log "before: $before after_dd: $after_dd"
222     (( $before > $after_dd )) || return 1
223     replay_barrier ost1
224     rm -f $f
225     fail ost1
226     wait_recovery_complete ost1 || error "OST recovery not done"
227     $CHECKSTAT -t file $f && return 2 || true
228     sync
229     # let the delete happen
230     wait_mds_ost_sync || return 4
231     wait_destroy_complete || return 5
232     after=`kbytesfree`
233     log "before: $before after: $after"
234     (( $before <= $after + 40 )) || return 3    # take OST logs into account
235 }
236 run_test 7 "Fail OST before obd_destroy"
237
238 equals_msg `basename $0`: test complete, cleaning up
239 check_and_cleanup_lustre
240 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true