Whamcloud - gitweb
LU-4713 tests: fix fhandle syscall test progarm
[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 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
30 # bug number for skipped test:      LU-2285
31         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3"
32 # bug number for slowed tests:                          LU-2887
33         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 8a 8b"
34 fi
35
36 build_test_filter
37
38 check_and_setup_lustre
39 assert_DIR
40 rm -rf $DIR/[df][0-9]*
41
42 TDIR=$DIR/d0.${TESTSUITE}
43 mkdir -p $TDIR
44 $LFS setstripe $TDIR -i 0 -c 1
45 $LFS getstripe $TDIR
46
47 test_0a() {
48     zconf_umount `hostname` $MOUNT -f
49     # needs to run during initial client->OST connection
50     #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
51     do_facet ost1 "lctl set_param fail_loc=0x80000211"
52     zconf_mount `hostname` $MOUNT && df $MOUNT || error "0a mount fail"
53 }
54 run_test 0a "target handle mismatch (bug 5317) `date +%H:%M:%S`"
55
56 test_0b() {
57     fail ost1
58     cp /etc/profile  $TDIR/$tfile
59     sync
60     diff /etc/profile $TDIR/$tfile
61     rm -f $TDIR/$tfile
62 }
63 run_test 0b "empty replay"
64
65 test_1() {
66     date > $TDIR/$tfile || error "error creating $TDIR/$tfile"
67     fail ost1
68     $CHECKSTAT -t file $TDIR/$tfile || return 1
69     rm -f $TDIR/$tfile
70 }
71 run_test 1 "touch"
72
73 test_2() {
74     for i in `seq 10`; do
75         echo "tag-$i" > $TDIR/$tfile-$i || error "create $TDIR/$tfile-$i"
76     done 
77     fail ost1
78     for i in `seq 10`; do
79       grep -q "tag-$i" $TDIR/$tfile-$i || error "grep $TDIR/$tfile-$i"
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 || return 1
92     cmp $verify $TDIR/$tfile || return 2
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 || return 1
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
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         rm -f $f
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 || return 4
194         wait_destroy_complete || return 5
195
196         local before=$(kbytesfree)
197         dd if=/dev/urandom bs=4096 count=1280 of=$f || return 28
198         lfs getstripe $f
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 || return 4
229         wait_delete_completed || return 5
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         rm -f $f
240         sync && sleep 5 && sync # wait for delete thread
241
242         # wait till space is returned, following
243         # (( $before > $after_dd)) test counting on that
244         wait_mds_ost_sync || return 4
245         wait_destroy_complete || return 5
246
247         local before=$(kbytesfree)
248         dd if=/dev/urandom bs=4096 count=1280 of=$f || 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 || return 4
271         wait_delete_completed || return 5
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                 return 1
293         fi
294         do_facet ost1 "lctl set_param fail_loc=0"
295         wait $ddpid || true
296         cancel_lru_locks osc
297         cmp $verify $TDIR/$tfile || return 2
298         rm -f $verify $TDIR/$tfile
299         message=`dmesg | grep "redo for recoverable error -115"`
300         [ -z "$message" ] || error "redo error messages found in dmesg"
301 }
302 run_test 8a "Verify redo io: redo io when get -EINPROGRESS error"
303
304 test_8b() {
305         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
306                 { skip "Need MDS version at least 2.3.0"; return; }
307         verify=$ROOT/tmp/verify-$$
308         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
309                 error "Create verify file failed"
310 #define OBD_FAIL_OST_DQACQ_NET 0x230
311         do_facet ost1 "lctl set_param fail_loc=0x230"
312         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
313         ddpid=$!
314         sleep $TIMEOUT  # wait for the io to become redo io
315         fail ost1
316         do_facet ost1 "lctl set_param fail_loc=0"
317         wait $ddpid || return 1
318         cancel_lru_locks osc
319         cmp $verify $TDIR/$tfile || return 2
320         rm -f $verify $TDIR/$tfile
321 }
322 run_test 8b "Verify redo io: redo io should success after recovery"
323
324 test_8c() {
325         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
326                 { skip "Need MDS version at least 2.3.0"; return; }
327         verify=$ROOT/tmp/verify-$$
328         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
329                 error "Create verify file failed"
330 #define OBD_FAIL_OST_DQACQ_NET 0x230
331         do_facet ost1 "lctl set_param fail_loc=0x230"
332         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
333         ddpid=$!
334         sleep $TIMEOUT  # wait for the io to become redo io
335         ost_evict_client
336         # allow recovery to complete
337         sleep $((TIMEOUT + 2))
338         do_facet ost1 "lctl set_param fail_loc=0"
339         wait $ddpid
340         cancel_lru_locks osc
341         cmp $verify $TDIR/$tfile && return 2
342         rm -f $verify $TDIR/$tfile
343 }
344 run_test 8c "Verify redo io: redo io should fail after eviction"
345
346 test_8d() {
347         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
348                 { skip "Need MDS version at least 2.3.0"; return; }
349 #define OBD_FAIL_MDS_DQACQ_NET 0x187
350         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
351         # test the non-intent create path
352         mcreate $TDIR/$tfile &
353         cpid=$!
354         sleep $TIMEOUT
355         if ! ps -p $cpid  > /dev/null 2>&1; then
356                 error "mknod finished incorrectly"
357                 return 1
358         fi
359         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
360         wait $cpid || return 2
361         stat $TDIR/$tfile || error "mknod failed"
362
363         rm $TDIR/$tfile
364
365 #define OBD_FAIL_MDS_DQACQ_NET 0x187
366         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
367         # test the intent create path
368         openfile -f O_RDWR:O_CREAT $TDIR/$tfile &
369         cpid=$!
370         sleep $TIMEOUT
371         if ! ps -p $cpid > /dev/null 2>&1; then
372                 error "open finished incorrectly"
373                 return 3
374         fi
375         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
376         wait $cpid || return 4
377         stat $TDIR/$tfile || error "open failed"
378 }
379 run_test 8d "Verify redo creation on -EINPROGRESS"
380
381 test_8e() {
382         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
383                 { skip "Need MDS version at least 2.3.0"; return; }
384         sleep 1 # ensure we have a fresh statfs
385 #define OBD_FAIL_OST_STATFS_EINPROGRESS 0x231
386         do_facet ost1 "lctl set_param fail_loc=0x231"
387         df $MOUNT &
388         dfpid=$!
389         sleep $TIMEOUT
390         if ! ps -p $dfpid  > /dev/null 2>&1; then
391                         do_facet ost1 "lctl set_param fail_loc=0"
392                         error "df shouldn't have completed!"
393                         return 1
394         fi
395         do_facet ost1 "lctl set_param fail_loc=0"
396 }
397 run_test 8e "Verify that ptlrpc resends request on -EINPROGRESS"
398
399 complete $SECONDS
400 check_and_cleanup_lustre
401 exit_status