Whamcloud - gitweb
LU-9273 tests: disable random I/O in replay-ost-single/5
[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 init_logging
12
13 # While we do not use OSTCOUNT=1 setup anymore,
14 # ost1failover_HOST is used
15 #ostfailover_HOST=${ostfailover_HOST:-$ost_HOST}
16 #failover= must be defined in OST_MKFS_OPTIONS if ostfailover_HOST != ost_HOST
17
18 require_dsh_ost || exit 0
19
20 # bug number for skipped test:
21 ALWAYS_EXCEPT="$REPLAY_OST_SINGLE_EXCEPT"
22 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
23
24 # bug number for SLOW test:
25 #                                  40  (min)"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW="5"
27
28 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
29 # bug number for slowed tests:                          LU-2887
30         #                                               32  12.5  (min)"
31         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 8a  8b"
32 fi
33
34 build_test_filter
35
36 check_and_setup_lustre
37 assert_DIR
38 rm -rf $DIR/[df][0-9]*
39
40 TDIR=$DIR/d0.${TESTSUITE}
41 mkdir -p $TDIR
42 $SETSTRIPE $TDIR -i 0 -c 1
43 $GETSTRIPE $TDIR
44
45 test_0a() {
46         zconf_umount $(hostname) $MOUNT -f
47         # needs to run during initial client->OST connection
48         #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
49         do_facet ost1 "lctl set_param fail_loc=0x80000211"
50         zconf_mount $(hostname) $MOUNT && $LFS df $MOUNT || error "mount fail"
51 }
52 run_test 0a "target handle mismatch (bug 5317)"
53
54 test_0b() {
55         fail ost1
56         cp /etc/profile  $TDIR/$tfile
57         sync
58         diff /etc/profile $TDIR/$tfile
59         rm -f $TDIR/$tfile
60 }
61 run_test 0b "empty replay"
62
63 test_1() {
64         date > $TDIR/$tfile || error "error creating $TDIR/$tfile"
65         fail ost1
66         $CHECKSTAT -t file $TDIR/$tfile || error "check for file failed"
67         rm -f $TDIR/$tfile
68 }
69 run_test 1 "touch"
70
71 test_2() {
72         for i in $(seq 10); do
73                 echo "tag-$i" > $TDIR/$tfile-$i ||
74                         error "create $TDIR/$tfile-$i failed"
75         done
76         fail ost1
77         for i in $(seq 10); do
78                 grep -q "tag-$i" $TDIR/$tfile-$i ||
79                         error "grep $TDIR/$tfile-$i failed"
80         done
81         rm -f $TDIR/$tfile-*
82 }
83 run_test 2 "|x| 10 open(O_CREAT)s"
84
85 test_3() {
86         verify=$ROOT/tmp/verify-$$
87         dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile &
88         ddpid=$!
89         sync &
90         fail ost1
91         wait $ddpid || error "wait for dd failed"
92         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
93         rm -f $verify $TDIR/$tfile
94 }
95 run_test 3 "Fail OST during write, with verification"
96
97 test_4() {
98         verify=$ROOT/tmp/verify-$$
99         dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile
100         # invalidate cache, so that we're reading over the wire
101         cancel_lru_locks osc
102         cmp $verify $TDIR/$tfile &
103         cmppid=$!
104         fail ost1
105         wait $cmppid || error "wait on cmp failed"
106         rm -f $verify $TDIR/$tfile
107 }
108 run_test 4 "Fail OST during read, with verification"
109
110 iozone_bg () {
111     local args=$@
112
113     local tmppipe=$TMP/${TESTSUITE}.${TESTNAME}.pipe
114     mkfifo $tmppipe
115
116     echo "+ iozone $args"
117     iozone $args > $tmppipe &
118
119     local pid=$!
120
121     echo "tmppipe=$tmppipe"
122     echo iozone pid=$pid
123
124     # iozone exit code is 0 even if iozone is not completed
125     # need to check iozone output  on "complete"
126     local iozonelog=$TMP/${TESTSUITE}.iozone.log
127     rm -f $iozonelog
128     cat $tmppipe | while read line ; do
129         echo "$line"
130         echo "$line" >>$iozonelog
131     done;
132
133     local rc=0
134     wait $pid
135     rc=$?
136     if ! $(tail -1 $iozonelog | grep -q complete); then
137         echo iozone failed!
138         rc=1
139     fi
140     rm -f $tmppipe
141     rm -f $iozonelog
142     return $rc
143 }
144
145 test_5() {
146         if [ -z "$(which iozone 2> /dev/null)" ]; then
147                 skip_env "iozone missing"
148                 return 0
149         fi
150
151         # striping is -c 1, get min of available
152         local minavail=$(lctl get_param -n osc.*[oO][sS][cC][-_]*.kbytesavail |
153                 sort -n | head -n1)
154         local size=$(( minavail * 3/4 ))
155         local GB=1048576  # 1048576KB == 1GB
156
157         if (( size > GB )); then
158                 size=$GB
159         fi
160         # no random I/O (-i 2) as it's very slow with ZFS
161         local iozone_opts="-i 0 -i 1 -+d -r 4 -s $size -f $TDIR/$tfile"
162
163         iozone_bg $iozone_opts &
164         local pid=$!
165
166         echo iozone bg pid=$pid
167
168         sleep 8
169         fail ost1
170         local rc=0
171         wait $pid || error "wait on iozone failed"
172         rc=$?
173         log "iozone rc=$rc"
174         rm -f $TDIR/$tfile
175         wait_delete_completed_mds
176         [ $rc -eq 0 ] || error "iozone failed"
177         return $rc
178 }
179 run_test 5 "Fail OST during iozone"
180
181 kbytesfree() {
182    calc_osc_kbytes kbytesfree
183 }
184
185 test_6() {
186         remote_mds_nodsh && skip "remote MDS with nodsh" && return 0
187
188         local f=$TDIR/$tfile
189         sync && sleep 5 && sync  # wait for delete thread
190
191         # wait till space is returned, following
192         # (( $before > $after_dd)) test counting on that
193         wait_mds_ost_sync || error "first wait_mds_ost_sync failed"
194         wait_destroy_complete || error "first wait_destroy_complete failed"
195
196         local before=$(kbytesfree)
197         dd if=/dev/urandom bs=4096 count=1280 of=$f || error "dd failed"
198         $GETSTRIPE $f || error "$GETSTRIPE $f failed"
199         local stripe_index=$(lfs getstripe -i $f)
200
201         sync
202         sleep 2 # ensure we have a fresh statfs
203         sync
204
205         #define OBD_FAIL_MDS_REINT_NET_REP       0x119
206         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
207
208         # retry till statfs returns useful results
209         local after_dd=$(kbytesfree)
210         local i=0
211         while (( $before <= $after_dd && $i < 20 )); do
212                 sync
213                 sleep 1
214                 let ++i
215                 after_dd=$(kbytesfree)
216         done
217
218         log "before: $before after_dd: $after_dd took $i seconds"
219         (( $before > $after_dd )) ||
220                 error "space grew after dd: before:$before after_dd:$after_dd"
221         rm -f $f
222         fail ost$((stripe_index + 1))
223         wait_recovery_complete ost$((stripe_index + 1)) ||
224                 error "OST$((stripe_index + 1)) recovery not completed"
225         $CHECKSTAT -t file $f && return 2 || true
226         sync
227         # let the delete happen
228         wait_mds_ost_sync || error "second wait_mds_ost_sync failed"
229         wait_delete_completed || error "second wait_delete_completed failed"
230         local after=$(kbytesfree)
231         log "before: $before after: $after"
232         (( $before <= $after + $(fs_log_size) )) ||
233                 error "$before > $after + logsize $(fs_log_size)"
234 }
235 run_test 6 "Fail OST before obd_destroy"
236
237 test_7() {
238         local f=$TDIR/$tfile
239         sync && sleep 5 && sync # wait for delete thread
240
241         # wait till space is returned, following
242         # (( $before > $after_dd)) test counting on that
243         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
244         wait_destroy_complete || error "wait_destroy_complete failed"
245
246         local before=$(kbytesfree)
247         dd if=/dev/urandom bs=4096 count=1280 of=$f ||
248                 error "dd to file failed: $?"
249
250         sync
251         local after_dd=$(kbytesfree)
252         local i=0
253         while (( $before <= $after_dd && $i < 10 )); do
254                 sync
255                 sleep 1
256                 let ++i
257                 after_dd=$(kbytesfree)
258         done
259
260         log "before: $before after_dd: $after_dd took $i seconds"
261         (( $before > $after_dd )) ||
262                 error "space grew after dd: before:$before after_dd:$after_dd"
263         replay_barrier ost1
264         rm -f $f
265         fail ost1
266         wait_recovery_complete ost1 || error "OST recovery not done"
267         $CHECKSTAT -t file $f && return 2 || true
268         sync
269         # let the delete happen
270         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
271         wait_delete_completed || error "wait_delete_completed failed"
272         local after=$(kbytesfree)
273         log "before: $before after: $after"
274         (( $before <= $after + $(fs_log_size) )) ||
275                  error "$before > $after + logsize $(fs_log_size)"
276 }
277 run_test 7 "Fail OST before obd_destroy"
278
279 test_8a() {
280         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
281                 { skip "Need MDS version at least 2.3.0"; return; }
282         verify=$ROOT/tmp/verify-$$
283         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
284                 error "Create verify file failed"
285         #define OBD_FAIL_OST_DQACQ_NET 0x230
286         do_facet ost1 "lctl set_param fail_loc=0x230"
287         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
288         ddpid=$!
289         sleep $TIMEOUT  # wait for the io to become redo io
290         if ! ps -p $ddpid  > /dev/null 2>&1; then
291                 error "redo io finished incorrectly"
292         fi
293         do_facet ost1 "lctl set_param fail_loc=0"
294         wait $ddpid || true
295         cancel_lru_locks osc
296         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
297         rm -f $verify $TDIR/$tfile
298         message=$(dmesg | grep "redo for recoverable error -115")
299         [ -z "$message" ] || error "redo error messages found in dmesg"
300 }
301 run_test 8a "Verify redo io: redo io when get -EINPROGRESS error"
302
303 test_8b() {
304         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
305                 { skip "Need MDS version at least 2.3.0"; return; }
306         verify=$ROOT/tmp/verify-$$
307         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
308                 error "Create verify file failed"
309         #define OBD_FAIL_OST_DQACQ_NET 0x230
310         do_facet ost1 "lctl set_param fail_loc=0x230"
311         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
312         ddpid=$!
313         sleep $TIMEOUT  # wait for the io to become redo io
314         fail ost1
315         do_facet ost1 "lctl set_param fail_loc=0"
316         wait $ddpid || error "dd did not complete"
317         cancel_lru_locks osc
318         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
319         rm -f $verify $TDIR/$tfile
320 }
321 run_test 8b "Verify redo io: redo io should success after recovery"
322
323 test_8c() {
324         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
325                 { skip "Need MDS version at least 2.3.0"; return; }
326         verify=$ROOT/tmp/verify-$$
327         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
328                 error "Create verify file failed"
329         #define OBD_FAIL_OST_DQACQ_NET 0x230
330         do_facet ost1 "lctl set_param fail_loc=0x230"
331         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
332         ddpid=$!
333         sleep $TIMEOUT  # wait for the io to become redo io
334         ost_evict_client
335         # allow recovery to complete
336         sleep $((TIMEOUT + 2))
337         do_facet ost1 "lctl set_param fail_loc=0"
338         wait $ddpid
339         cancel_lru_locks osc
340         cmp $verify $TDIR/$tfile && error "compare files should fail"
341         rm -f $verify $TDIR/$tfile
342 }
343 run_test 8c "Verify redo io: redo io should fail after eviction"
344
345 test_8d() {
346         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
347                 { skip "Need MDS version at least 2.3.0"; return; }
348         #define OBD_FAIL_MDS_DQACQ_NET 0x187
349         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
350         # test the non-intent create path
351         mcreate $TDIR/$tfile &
352         cpid=$!
353         sleep $TIMEOUT
354         if ! ps -p $cpid  > /dev/null 2>&1; then
355                 error "mknod finished incorrectly"
356         fi
357         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
358         wait $cpid || error "mcreate did not complete"
359         stat $TDIR/$tfile || error "mknod failed"
360
361         rm $TDIR/$tfile
362
363         #define OBD_FAIL_MDS_DQACQ_NET 0x187
364         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
365         # test the intent create path
366         openfile -f O_RDWR:O_CREAT $TDIR/$tfile &
367         cpid=$!
368         sleep $TIMEOUT
369         if ! ps -p $cpid > /dev/null 2>&1; then
370                 error "open finished incorrectly"
371         fi
372         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
373         wait $cpid || error "openfile failed"
374         stat $TDIR/$tfile || error "open failed"
375 }
376 run_test 8d "Verify redo creation on -EINPROGRESS"
377
378 test_8e() {
379         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
380                 { skip "Need MDS version at least 2.3.0"; return; }
381         sleep 1 # ensure we have a fresh statfs
382         #define OBD_FAIL_OST_STATFS_EINPROGRESS 0x231
383         do_facet ost1 "lctl set_param fail_loc=0x231"
384         $LFS df $MOUNT &
385         dfpid=$!
386         sleep $TIMEOUT
387         if ! ps -p $dfpid  > /dev/null 2>&1; then
388                 do_facet ost1 "lctl set_param fail_loc=0"
389                 error "df shouldn't have completed!"
390         fi
391 }
392 run_test 8e "Verify that ptlrpc resends request on -EINPROGRESS"
393
394 test_9() {
395         [ $(lustre_version_code ost1) -ge $(version_code 2.6.54) ] ||
396                 { skip "Need OST version at least 2.6.54"; return; }
397         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
398
399         # LU-1573 - Add duplicate write to generate grants
400         dd if=/dev/zero of=$DIR/$tfile count=1 bs=1M > /dev/null ||
401                 error "First write failed"
402         replay_barrier ost1
403         # do IO
404         dd if=/dev/zero of=$DIR/$tfile count=1 bs=1M > /dev/null ||
405                 error "failed to write"
406         # failover, replay and resend replayed waiting request
407         #define OBD_FAIL_TGT_REPLAY_DELAY2       0x714
408         do_facet ost1 $LCTL set_param fail_loc=0x00000714
409         do_facet ost1 $LCTL set_param fail_val=$TIMEOUT
410         fail ost1
411         do_facet ost1 $LCTL set_param fail_loc=0
412         do_facet ost1 "dmesg | tail -n 100" |
413                 sed -n '/no req deadline/,$ p' | grep -q 'Already past' &&
414                 return 1
415         return 0
416 }
417 run_test 9 "Verify that no req deadline happened during recovery"
418
419 test_10() {
420         rm -f $TDIR/$tfile
421
422         dd if=/dev/zero of=$TDIR/$tfile count=10 || error "dd failed"
423
424         #define OBD_FAIL_OSC_DELAY_IO            0x414
425         $LCTL set_param fail_val=60 fail_loc=0x414
426         cancel_lru_locks OST0000-osc &
427         sleep 2
428         facet_failover ost1 || error "failover: $?"
429
430         #define OBD_FAIL_LDLM_GRANT_CHECK        0x32a
431         $LCTL set_param fail_loc=0x32a
432         stat $TDIR/$tfile
433
434         wait
435 }
436 run_test 10 "conflicting PW & PR locks on a client"
437
438 complete $SECONDS
439 check_and_cleanup_lustre
440 exit_status