Whamcloud - gitweb
8babef8685486bd9f8fbb2d45489d3fe737d00fc
[fs/lustre-release.git] / lustre / tests / replay-ost-single.sh
1 #!/bin/bash
2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
4
5 set -e
6
7 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
8 SETUP=${SETUP:-""}
9 CLEANUP=${CLEANUP:-""}
10 . $LUSTRE/tests/test-framework.sh
11 init_test_env $@
12 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
13 init_logging
14
15 # While we do not use OSTCOUNT=1 setup anymore,
16 # ost1failover_HOST is used
17 #ostfailover_HOST=${ostfailover_HOST:-$ost_HOST}
18 #failover= must be defined in OST_MKFS_OPTIONS if ostfailover_HOST != ost_HOST
19
20 require_dsh_ost || exit 0
21
22 # Skip these tests
23 # BUG NUMBER: 
24 ALWAYS_EXCEPT="$REPLAY_OST_SINGLE_EXCEPT"
25
26 #                                       
27 [ "$SLOW" = "no" ] && EXCEPT_SLOW="5"
28
29 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
30 # bug number for skipped test:      LU-2285
31         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3"
32
33 build_test_filter
34
35 check_and_setup_lustre
36 assert_DIR
37 rm -rf $DIR/[df][0-9]*
38
39 TDIR=$DIR/d0.${TESTSUITE}
40 mkdir -p $TDIR
41 $LFS setstripe $TDIR -i 0 -c 1
42 $LFS getstripe $TDIR
43
44 test_0a() {
45     zconf_umount `hostname` $MOUNT -f
46     # needs to run during initial client->OST connection
47     #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
48     do_facet ost1 "lctl set_param fail_loc=0x80000211"
49     zconf_mount `hostname` $MOUNT && df $MOUNT || error "0a mount fail"
50 }
51 run_test 0a "target handle mismatch (bug 5317) `date +%H:%M:%S`"
52
53 test_0b() {
54     fail ost1
55     cp /etc/profile  $TDIR/$tfile
56     sync
57     diff /etc/profile $TDIR/$tfile
58     rm -f $TDIR/$tfile
59 }
60 run_test 0b "empty replay"
61
62 test_1() {
63     date > $TDIR/$tfile || error "error creating $TDIR/$tfile"
64     fail ost1
65     $CHECKSTAT -t file $TDIR/$tfile || return 1
66     rm -f $TDIR/$tfile
67 }
68 run_test 1 "touch"
69
70 test_2() {
71     for i in `seq 10`; do
72         echo "tag-$i" > $TDIR/$tfile-$i || error "create $TDIR/$tfile-$i"
73     done 
74     fail ost1
75     for i in `seq 10`; do
76       grep -q "tag-$i" $TDIR/$tfile-$i || error "grep $TDIR/$tfile-$i"
77     done 
78     rm -f $TDIR/$tfile-*
79 }
80 run_test 2 "|x| 10 open(O_CREAT)s"
81
82 test_3() {
83     verify=$ROOT/tmp/verify-$$
84     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile &
85     ddpid=$!
86     sync &
87     fail ost1
88     wait $ddpid || return 1
89     cmp $verify $TDIR/$tfile || return 2
90     rm -f $verify $TDIR/$tfile
91 }
92 run_test 3 "Fail OST during write, with verification"
93
94 test_4() {
95     verify=$ROOT/tmp/verify-$$
96     dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile
97     # invalidate cache, so that we're reading over the wire
98     cancel_lru_locks osc
99     cmp $verify $TDIR/$tfile &
100     cmppid=$!
101     fail ost1
102     wait $cmppid || return 1
103     rm -f $verify $TDIR/$tfile
104 }
105 run_test 4 "Fail OST during read, with verification"
106
107 iozone_bg () {
108     local args=$@
109
110     local tmppipe=$TMP/${TESTSUITE}.${TESTNAME}.pipe
111     mkfifo $tmppipe
112
113     echo "+ iozone $args"
114     iozone $args > $tmppipe &
115
116     local pid=$!
117
118     echo "tmppipe=$tmppipe"
119     echo iozone pid=$pid
120
121     # iozone exit code is 0 even if iozone is not completed
122     # need to check iozone output  on "complete"
123     local iozonelog=$TMP/${TESTSUITE}.iozone.log
124     rm -f $iozonelog
125     cat $tmppipe | while read line ; do
126         echo "$line"
127         echo "$line" >>$iozonelog
128     done;
129
130     local rc=0
131     wait $pid
132     rc=$?
133     if ! $(tail -1 $iozonelog | grep -q complete); then
134         echo iozone failed!
135         rc=1
136     fi
137     rm -f $tmppipe
138     rm -f $iozonelog
139     return $rc
140 }
141
142 test_5() {
143     [ -z "`which iozone 2> /dev/null`" ] && skip_env "iozone missing" && return 0
144
145     # striping is -c 1, get min of available
146     local minavail=$(lctl get_param -n osc.*[oO][sS][cC][-_]*.kbytesavail | sort -n | head -1)
147     local size=$(( minavail * 3/4 ))
148     local GB=1048576  # 1048576KB == 1GB
149
150     if (( size > GB )); then
151         size=$GB
152     fi
153     local iozone_opts="-i 0 -i 1 -i 2 -+d -r 4 -s $size -f $TDIR/$tfile"
154
155     iozone_bg $iozone_opts &
156     local pid=$!
157
158     echo iozone bg pid=$pid
159
160     sleep 8
161     fail ost1
162     local rc=0
163     wait $pid
164     rc=$?
165     log "iozone rc=$rc"
166     rm -f $TDIR/$tfile
167     wait_delete_completed_mds
168     [ $rc -eq 0 ] || error "iozone failed"
169     return $rc
170 }
171 run_test 5 "Fail OST during iozone"
172
173 kbytesfree() {
174    calc_osc_kbytes kbytesfree
175 }
176
177 test_6() {
178     remote_mds_nodsh && skip "remote MDS with nodsh" && return 0
179
180     f=$TDIR/$tfile
181     rm -f $f
182     sync && sleep 2 && sync  # wait for delete thread
183
184     # wait till space is returned, following
185     # (( $before > $after_dd)) test counting on that
186     wait_mds_ost_sync || return 4
187     wait_destroy_complete || return 5
188
189     before=`kbytesfree`
190     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 28
191     lfs getstripe $f
192     stripe_index=$(lfs getstripe -i $f)
193
194     sync
195     sleep 2 # ensure we have a fresh statfs
196     sync
197
198     #define OBD_FAIL_MDS_REINT_NET_REP       0x119
199     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
200     after_dd=`kbytesfree`
201     log "before: $before after_dd: $after_dd"
202     (( $before > $after_dd )) || return 1
203     rm -f $f
204     fail ost$((stripe_index + 1))
205     wait_recovery_complete ost$((stripe_index + 1)) ||
206         error "OST$((stripe_index + 1)) recovery not completed"
207     $CHECKSTAT -t file $f && return 2 || true
208     sync
209     # let the delete happen
210     wait_mds_ost_sync || return 4
211         wait_delete_completed || return 5
212     after=`kbytesfree`
213     log "before: $before after: $after"
214     (( $before <= $after + 40 )) || return 3   # take OST logs into account
215 }
216 run_test 6 "Fail OST before obd_destroy"
217
218 test_7() {
219     f=$TDIR/$tfile
220     rm -f $f
221     sync && sleep 5 && sync     # wait for delete thread
222
223     # wait till space is returned, following
224     # (( $before > $after_dd)) test counting on that
225     wait_mds_ost_sync || return 4
226     wait_destroy_complete || return 5
227
228     before=`kbytesfree`
229     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 4
230     sync
231     sleep 2 # ensure we have a fresh statfs
232     sync
233     after_dd=`kbytesfree`
234     log "before: $before after_dd: $after_dd"
235     (( $before > $after_dd )) || return 1
236     replay_barrier ost1
237     rm -f $f
238     fail ost1
239     wait_recovery_complete ost1 || error "OST recovery not done"
240     $CHECKSTAT -t file $f && return 2 || true
241     sync
242     # let the delete happen
243     wait_mds_ost_sync || return 4
244         wait_delete_completed || return 5
245     after=`kbytesfree`
246     log "before: $before after: $after"
247     (( $before <= $after + 40 )) || return 3    # take OST logs into account
248 }
249 run_test 7 "Fail OST before obd_destroy"
250
251 test_8a() {
252         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
253                 { skip "Need MDS version at least 2.3.0"; return; }
254         verify=$ROOT/tmp/verify-$$
255         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
256                 error "Create verify file failed"
257 #define OBD_FAIL_OST_DQACQ_NET 0x230
258         do_facet ost1 "lctl set_param fail_loc=0x230"
259         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
260         ddpid=$!
261         sleep $TIMEOUT  # wait for the io to become redo io
262         if ! ps -p $ddpid  > /dev/null 2>&1; then
263                 error "redo io finished incorrectly"
264                 return 1
265         fi
266         do_facet ost1 "lctl set_param fail_loc=0"
267         wait $ddpid || true
268         cancel_lru_locks osc
269         cmp $verify $TDIR/$tfile || return 2
270         rm -f $verify $TDIR/$tfile
271         message=`dmesg | grep "redo for recoverable error -115"`
272         [ -z "$message" ] || error "redo error messages found in dmesg"
273 }
274 run_test 8a "Verify redo io: redo io when get -EINPROGRESS error"
275
276 test_8b() {
277         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
278                 { skip "Need MDS version at least 2.3.0"; return; }
279         verify=$ROOT/tmp/verify-$$
280         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
281                 error "Create verify file failed"
282 #define OBD_FAIL_OST_DQACQ_NET 0x230
283         do_facet ost1 "lctl set_param fail_loc=0x230"
284         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
285         ddpid=$!
286         sleep $TIMEOUT  # wait for the io to become redo io
287         fail ost1
288         do_facet ost1 "lctl set_param fail_loc=0"
289         wait $ddpid || return 1
290         cancel_lru_locks osc
291         cmp $verify $TDIR/$tfile || return 2
292         rm -f $verify $TDIR/$tfile
293 }
294 run_test 8b "Verify redo io: redo io should success after recovery"
295
296 test_8c() {
297         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
298                 { skip "Need MDS version at least 2.3.0"; return; }
299         verify=$ROOT/tmp/verify-$$
300         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
301                 error "Create verify file failed"
302 #define OBD_FAIL_OST_DQACQ_NET 0x230
303         do_facet ost1 "lctl set_param fail_loc=0x230"
304         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
305         ddpid=$!
306         sleep $TIMEOUT  # wait for the io to become redo io
307         ost_evict_client
308         # allow recovery to complete
309         sleep $((TIMEOUT + 2))
310         do_facet ost1 "lctl set_param fail_loc=0"
311         wait $ddpid
312         cancel_lru_locks osc
313         cmp $verify $TDIR/$tfile && return 2
314         rm -f $verify $TDIR/$tfile
315 }
316 run_test 8c "Verify redo io: redo io should fail after eviction"
317
318 test_8d() {
319         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
320                 { skip "Need MDS version at least 2.3.0"; return; }
321 #define OBD_FAIL_MDS_DQACQ_NET 0x187
322         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
323         # test the non-intent create path
324         mcreate $TDIR/$tfile &
325         cpid=$!
326         sleep $TIMEOUT
327         if ! ps -p $cpid  > /dev/null 2>&1; then
328                 error "mknod finished incorrectly"
329                 return 1
330         fi
331         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
332         wait $cpid || return 2
333         stat $TDIR/$tfile || error "mknod failed"
334
335         rm $TDIR/$tfile
336
337 #define OBD_FAIL_MDS_DQACQ_NET 0x187
338         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
339         # test the intent create path
340         openfile -f O_RDWR:O_CREAT $TDIR/$tfile &
341         cpid=$!
342         sleep $TIMEOUT
343         if ! ps -p $cpid > /dev/null 2>&1; then
344                 error "open finished incorrectly"
345                 return 3
346         fi
347         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
348         wait $cpid || return 4
349         stat $TDIR/$tfile || error "open failed"
350 }
351 run_test 8d "Verify redo creation on -EINPROGRESS"
352
353 test_8e() {
354         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
355                 { skip "Need MDS version at least 2.3.0"; return; }
356         sleep 1 # ensure we have a fresh statfs
357 #define OBD_FAIL_OST_STATFS_EINPROGRESS 0x231
358         do_facet ost1 "lctl set_param fail_loc=0x231"
359         df $MOUNT &
360         dfpid=$!
361         sleep $TIMEOUT
362         if ! ps -p $dfpid  > /dev/null 2>&1; then
363                         do_facet ost1 "lctl set_param fail_loc=0"
364                         error "df shouldn't have completed!"
365                         return 1
366         fi
367         do_facet ost1 "lctl set_param fail_loc=0"
368 }
369 run_test 8e "Verify that ptlrpc resends request on -EINPROGRESS"
370
371 complete $SECONDS
372 check_and_cleanup_lustre
373 exit_status