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