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