Whamcloud - gitweb
b7115a699c0d7d42cd83568ea3080ba33ef4336c
[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     [ $rc -eq 0 ] || error "iozone failed"
164     return $rc
165 }
166 run_test 5 "Fail OST during iozone"
167
168 kbytesfree() {
169    calc_osc_kbytes kbytesfree
170 }
171
172 test_6() {
173     remote_mds_nodsh && skip "remote MDS with nodsh" && return 0
174
175     f=$TDIR/$tfile
176     rm -f $f
177     sync && sleep 2 && sync  # wait for delete thread
178
179     # wait till space is returned, following
180     # (( $before > $after_dd)) test counting on that
181     wait_mds_ost_sync || return 4
182     wait_destroy_complete || return 5
183
184     before=`kbytesfree`
185     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 28
186     lfs getstripe $f
187     stripe_index=$(lfs getstripe -i $f)
188
189     sync
190     sleep 2 # ensure we have a fresh statfs
191     sync
192
193     #define OBD_FAIL_MDS_REINT_NET_REP       0x119
194     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
195     after_dd=`kbytesfree`
196     log "before: $before after_dd: $after_dd"
197     (( $before > $after_dd )) || return 1
198     rm -f $f
199     fail ost$((stripe_index + 1))
200     wait_recovery_complete ost$((stripe_index + 1)) ||
201         error "OST$((stripe_index + 1)) recovery not completed"
202     $CHECKSTAT -t file $f && return 2 || true
203     sync
204     # let the delete happen
205     wait_mds_ost_sync || return 4
206         wait_delete_completed || return 5
207     after=`kbytesfree`
208     log "before: $before after: $after"
209     (( $before <= $after + 40 )) || return 3   # take OST logs into account
210 }
211 run_test 6 "Fail OST before obd_destroy"
212
213 test_7() {
214     f=$TDIR/$tfile
215     rm -f $f
216     sync && sleep 5 && sync     # wait for delete thread
217
218     # wait till space is returned, following
219     # (( $before > $after_dd)) test counting on that
220     wait_mds_ost_sync || return 4
221     wait_destroy_complete || return 5
222
223     before=`kbytesfree`
224     dd if=/dev/urandom bs=4096 count=1280 of=$f || return 4
225     sync
226     sleep 2 # ensure we have a fresh statfs
227     sync
228     after_dd=`kbytesfree`
229     log "before: $before after_dd: $after_dd"
230     (( $before > $after_dd )) || return 1
231     replay_barrier ost1
232     rm -f $f
233     fail ost1
234     wait_recovery_complete ost1 || error "OST recovery not done"
235     $CHECKSTAT -t file $f && return 2 || true
236     sync
237     # let the delete happen
238     wait_mds_ost_sync || return 4
239         wait_delete_completed || return 5
240     after=`kbytesfree`
241     log "before: $before after: $after"
242     (( $before <= $after + 40 )) || return 3    # take OST logs into account
243 }
244 run_test 7 "Fail OST before obd_destroy"
245
246 test_8a() {
247         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
248                 { skip "Need MDS version at least 2.3.0"; return; }
249         verify=$ROOT/tmp/verify-$$
250         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
251                 error "Create verify file failed"
252 #define OBD_FAIL_OST_DQACQ_NET 0x230
253         do_facet ost1 "lctl set_param fail_loc=0x230"
254         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
255         ddpid=$!
256         sleep $TIMEOUT  # wait for the io to become redo io
257         if ! ps -p $ddpid  > /dev/null 2>&1; then
258                 error "redo io finished incorrectly"
259                 return 1
260         fi
261         do_facet ost1 "lctl set_param fail_loc=0"
262         wait $ddpid || true
263         cancel_lru_locks osc
264         cmp $verify $TDIR/$tfile || return 2
265         rm -f $verify $TDIR/$tfile
266         message=`dmesg | grep "redo for recoverable error -115"`
267         [ -z "$message" ] || error "redo error messages found in dmesg"
268 }
269 run_test 8a "Verify redo io: redo io when get -EINPROGRESS error"
270
271 test_8b() {
272         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
273                 { skip "Need MDS version at least 2.3.0"; return; }
274         verify=$ROOT/tmp/verify-$$
275         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
276                 error "Create verify file failed"
277 #define OBD_FAIL_OST_DQACQ_NET 0x230
278         do_facet ost1 "lctl set_param fail_loc=0x230"
279         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
280         ddpid=$!
281         sleep $TIMEOUT  # wait for the io to become redo io
282         fail ost1
283         do_facet ost1 "lctl set_param fail_loc=0"
284         wait $ddpid || return 1
285         cancel_lru_locks osc
286         cmp $verify $TDIR/$tfile || return 2
287         rm -f $verify $TDIR/$tfile
288 }
289 run_test 8b "Verify redo io: redo io should success after recovery"
290
291 test_8c() {
292         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
293                 { skip "Need MDS version at least 2.3.0"; return; }
294         verify=$ROOT/tmp/verify-$$
295         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
296                 error "Create verify file failed"
297 #define OBD_FAIL_OST_DQACQ_NET 0x230
298         do_facet ost1 "lctl set_param fail_loc=0x230"
299         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
300         ddpid=$!
301         sleep $TIMEOUT  # wait for the io to become redo io
302         ost_evict_client
303         # allow recovery to complete
304         sleep $((TIMEOUT + 2))
305         do_facet ost1 "lctl set_param fail_loc=0"
306         wait $ddpid
307         cancel_lru_locks osc
308         cmp $verify $TDIR/$tfile && return 2
309         rm -f $verify $TDIR/$tfile
310 }
311 run_test 8c "Verify redo io: redo io should fail after eviction"
312
313 test_8d() {
314         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
315                 { skip "Need MDS version at least 2.3.0"; return; }
316 #define OBD_FAIL_MDS_DQACQ_NET 0x187
317         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
318         # test the non-intent create path
319         mcreate $TDIR/$tfile &
320         cpid=$!
321         sleep $TIMEOUT
322         if ! ps -p $cpid  > /dev/null 2>&1; then
323                 error "mknod finished incorrectly"
324                 return 1
325         fi
326         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
327         wait $cpid || return 2
328         stat $TDIR/$tfile || error "mknod failed"
329
330         rm $TDIR/$tfile
331
332 #define OBD_FAIL_MDS_DQACQ_NET 0x187
333         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
334         # test the intent create path
335         openfile -f O_RDWR:O_CREAT $TDIR/$tfile &
336         cpid=$!
337         sleep $TIMEOUT
338         if ! ps -p $cpid > /dev/null 2>&1; then
339                 error "open finished incorrectly"
340                 return 3
341         fi
342         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
343         wait $cpid || return 4
344         stat $TDIR/$tfile || error "open failed"
345 }
346 run_test 8d "Verify redo creation on -EINPROGRESS"
347
348 test_8e() {
349         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
350                 { skip "Need MDS version at least 2.3.0"; return; }
351         sleep 1 # ensure we have a fresh statfs
352 #define OBD_FAIL_OST_STATFS_EINPROGRESS 0x231
353         do_facet ost1 "lctl set_param fail_loc=0x231"
354         df $MOUNT &
355         dfpid=$!
356         sleep $TIMEOUT
357         if ! ps -p $dfpid  > /dev/null 2>&1; then
358                         do_facet ost1 "lctl set_param fail_loc=0"
359                         error "df shouldn't have completed!"
360                         return 1
361         fi
362         do_facet ost1 "lctl set_param fail_loc=0"
363 }
364 run_test 8e "Verify that ptlrpc resends request on -EINPROGRESS"
365
366 complete $SECONDS
367 check_and_cleanup_lustre
368 exit_status