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