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