Whamcloud - gitweb
LU-10212 test: ESTALE read
[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         local iozone_opts="-i 0 -i 1 -i 2 -+d -r 4 -s $size -f $TDIR/$tfile"
161
162         iozone_bg $iozone_opts &
163         local pid=$!
164
165         echo iozone bg pid=$pid
166
167         sleep 8
168         fail ost1
169         local rc=0
170         wait $pid || error "wait on iozone failed"
171         rc=$?
172         log "iozone rc=$rc"
173         rm -f $TDIR/$tfile
174         wait_delete_completed_mds
175         [ $rc -eq 0 ] || error "iozone failed"
176         return $rc
177 }
178 run_test 5 "Fail OST during iozone"
179
180 kbytesfree() {
181    calc_osc_kbytes kbytesfree
182 }
183
184 test_6() {
185         remote_mds_nodsh && skip "remote MDS with nodsh" && return 0
186
187         local f=$TDIR/$tfile
188         sync && sleep 5 && sync  # wait for delete thread
189
190         # wait till space is returned, following
191         # (( $before > $after_dd)) test counting on that
192         wait_mds_ost_sync || error "first wait_mds_ost_sync failed"
193         wait_destroy_complete || error "first wait_destroy_complete failed"
194
195         local before=$(kbytesfree)
196         dd if=/dev/urandom bs=4096 count=1280 of=$f || error "dd failed"
197         $GETSTRIPE $f || error "$GETSTRIPE $f failed"
198         local stripe_index=$(lfs getstripe -i $f)
199
200         sync
201         sleep 2 # ensure we have a fresh statfs
202         sync
203
204         #define OBD_FAIL_MDS_REINT_NET_REP       0x119
205         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
206
207         # retry till statfs returns useful results
208         local after_dd=$(kbytesfree)
209         local i=0
210         while (( $before <= $after_dd && $i < 20 )); do
211                 sync
212                 sleep 1
213                 let ++i
214                 after_dd=$(kbytesfree)
215         done
216
217         log "before: $before after_dd: $after_dd took $i seconds"
218         (( $before > $after_dd )) ||
219                 error "space grew after dd: before:$before after_dd:$after_dd"
220         rm -f $f
221         fail ost$((stripe_index + 1))
222         wait_recovery_complete ost$((stripe_index + 1)) ||
223                 error "OST$((stripe_index + 1)) recovery not completed"
224         $CHECKSTAT -t file $f && return 2 || true
225         sync
226         # let the delete happen
227         wait_mds_ost_sync || error "second wait_mds_ost_sync failed"
228         wait_delete_completed || error "second wait_delete_completed failed"
229         local after=$(kbytesfree)
230         log "before: $before after: $after"
231         (( $before <= $after + $(fs_log_size) )) ||
232                 error "$before > $after + logsize $(fs_log_size)"
233 }
234 run_test 6 "Fail OST before obd_destroy"
235
236 test_7() {
237         local f=$TDIR/$tfile
238         sync && sleep 5 && sync # wait for delete thread
239
240         # wait till space is returned, following
241         # (( $before > $after_dd)) test counting on that
242         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
243         wait_destroy_complete || error "wait_destroy_complete failed"
244
245         local before=$(kbytesfree)
246         dd if=/dev/urandom bs=4096 count=1280 of=$f ||
247                 error "dd to file failed: $?"
248
249         sync
250         local after_dd=$(kbytesfree)
251         local i=0
252         while (( $before <= $after_dd && $i < 10 )); do
253                 sync
254                 sleep 1
255                 let ++i
256                 after_dd=$(kbytesfree)
257         done
258
259         log "before: $before after_dd: $after_dd took $i seconds"
260         (( $before > $after_dd )) ||
261                 error "space grew after dd: before:$before after_dd:$after_dd"
262         replay_barrier ost1
263         rm -f $f
264         fail ost1
265         wait_recovery_complete ost1 || error "OST recovery not done"
266         $CHECKSTAT -t file $f && return 2 || true
267         sync
268         # let the delete happen
269         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
270         wait_delete_completed || error "wait_delete_completed failed"
271         local after=$(kbytesfree)
272         log "before: $before after: $after"
273         (( $before <= $after + $(fs_log_size) )) ||
274                  error "$before > $after + logsize $(fs_log_size)"
275 }
276 run_test 7 "Fail OST before obd_destroy"
277
278 test_8a() {
279         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
280                 { skip "Need MDS version at least 2.3.0"; return; }
281         verify=$ROOT/tmp/verify-$$
282         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
283                 error "Create verify file failed"
284         #define OBD_FAIL_OST_DQACQ_NET 0x230
285         do_facet ost1 "lctl set_param fail_loc=0x230"
286         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
287         ddpid=$!
288         sleep $TIMEOUT  # wait for the io to become redo io
289         if ! ps -p $ddpid  > /dev/null 2>&1; then
290                 error "redo io finished incorrectly"
291         fi
292         do_facet ost1 "lctl set_param fail_loc=0"
293         wait $ddpid || true
294         cancel_lru_locks osc
295         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
296         rm -f $verify $TDIR/$tfile
297         message=$(dmesg | grep "redo for recoverable error -115")
298         [ -z "$message" ] || error "redo error messages found in dmesg"
299 }
300 run_test 8a "Verify redo io: redo io when get -EINPROGRESS error"
301
302 test_8b() {
303         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
304                 { skip "Need MDS version at least 2.3.0"; return; }
305         verify=$ROOT/tmp/verify-$$
306         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
307                 error "Create verify file failed"
308         #define OBD_FAIL_OST_DQACQ_NET 0x230
309         do_facet ost1 "lctl set_param fail_loc=0x230"
310         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
311         ddpid=$!
312         sleep $TIMEOUT  # wait for the io to become redo io
313         fail ost1
314         do_facet ost1 "lctl set_param fail_loc=0"
315         wait $ddpid || error "dd did not complete"
316         cancel_lru_locks osc
317         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
318         rm -f $verify $TDIR/$tfile
319 }
320 run_test 8b "Verify redo io: redo io should success after recovery"
321
322 test_8c() {
323         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
324                 { skip "Need MDS version at least 2.3.0"; return; }
325         verify=$ROOT/tmp/verify-$$
326         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
327                 error "Create verify file failed"
328         #define OBD_FAIL_OST_DQACQ_NET 0x230
329         do_facet ost1 "lctl set_param fail_loc=0x230"
330         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
331         ddpid=$!
332         sleep $TIMEOUT  # wait for the io to become redo io
333         ost_evict_client
334         # allow recovery to complete
335         sleep $((TIMEOUT + 2))
336         do_facet ost1 "lctl set_param fail_loc=0"
337         wait $ddpid
338         cancel_lru_locks osc
339         cmp $verify $TDIR/$tfile && error "compare files should fail"
340         rm -f $verify $TDIR/$tfile
341 }
342 run_test 8c "Verify redo io: redo io should fail after eviction"
343
344 test_8d() {
345         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
346                 { skip "Need MDS version at least 2.3.0"; return; }
347         #define OBD_FAIL_MDS_DQACQ_NET 0x187
348         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
349         # test the non-intent create path
350         mcreate $TDIR/$tfile &
351         cpid=$!
352         sleep $TIMEOUT
353         if ! ps -p $cpid  > /dev/null 2>&1; then
354                 error "mknod finished incorrectly"
355         fi
356         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
357         wait $cpid || error "mcreate did not complete"
358         stat $TDIR/$tfile || error "mknod failed"
359
360         rm $TDIR/$tfile
361
362         #define OBD_FAIL_MDS_DQACQ_NET 0x187
363         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
364         # test the intent create path
365         openfile -f O_RDWR:O_CREAT $TDIR/$tfile &
366         cpid=$!
367         sleep $TIMEOUT
368         if ! ps -p $cpid > /dev/null 2>&1; then
369                 error "open finished incorrectly"
370         fi
371         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
372         wait $cpid || error "openfile failed"
373         stat $TDIR/$tfile || error "open failed"
374 }
375 run_test 8d "Verify redo creation on -EINPROGRESS"
376
377 test_8e() {
378         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
379                 { skip "Need MDS version at least 2.3.0"; return; }
380         sleep 1 # ensure we have a fresh statfs
381         #define OBD_FAIL_OST_STATFS_EINPROGRESS 0x231
382         do_facet ost1 "lctl set_param fail_loc=0x231"
383         $LFS df $MOUNT &
384         dfpid=$!
385         sleep $TIMEOUT
386         if ! ps -p $dfpid  > /dev/null 2>&1; then
387                 do_facet ost1 "lctl set_param fail_loc=0"
388                 error "df shouldn't have completed!"
389         fi
390 }
391 run_test 8e "Verify that ptlrpc resends request on -EINPROGRESS"
392
393 test_9() {
394         [ $(lustre_version_code ost1) -ge $(version_code 2.6.54) ] ||
395                 { skip "Need OST version at least 2.6.54"; return; }
396         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
397
398         # LU-1573 - Add duplicate write to generate grants
399         dd if=/dev/zero of=$DIR/$tfile count=1 bs=1M > /dev/null ||
400                 error "First write failed"
401         replay_barrier ost1
402         # do IO
403         dd if=/dev/zero of=$DIR/$tfile count=1 bs=1M > /dev/null ||
404                 error "failed to write"
405         # failover, replay and resend replayed waiting request
406         #define OBD_FAIL_TGT_REPLAY_DELAY2       0x714
407         do_facet ost1 $LCTL set_param fail_loc=0x00000714
408         do_facet ost1 $LCTL set_param fail_val=$TIMEOUT
409         fail ost1
410         do_facet ost1 $LCTL set_param fail_loc=0
411         do_facet ost1 "dmesg | tail -n 100" |
412                 sed -n '/no req deadline/,$ p' | grep -q 'Already past' &&
413                 return 1
414         return 0
415 }
416 run_test 9 "Verify that no req deadline happened during recovery"
417
418 test_10() {
419         rm -f $TDIR/$tfile
420
421         dd if=/dev/zero of=$TDIR/$tfile count=10 || error "dd failed"
422
423         #define OBD_FAIL_OSC_DELAY_IO            0x414
424         $LCTL set_param fail_val=60 fail_loc=0x414
425         cancel_lru_locks OST0000-osc &
426         sleep 2
427         facet_failover ost1 || error "failover: $?"
428
429         #define OBD_FAIL_LDLM_GRANT_CHECK        0x32a
430         $LCTL set_param fail_loc=0x32a
431         stat $TDIR/$tfile
432
433         wait
434 }
435 run_test 10 "conflicting PW & PR locks on a client"
436
437 complete $SECONDS
438 check_and_cleanup_lustre
439 exit_status