Whamcloud - gitweb
LU-10092 pcc: change detach behavior and add keep option
[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         sync_all_data
200
201         local before=$(kbytesfree)
202         dd if=/dev/urandom bs=4096 count=1280 of=$f || error "dd failed"
203         $LFS getstripe $f || error "$LFS getstripe $f failed"
204         local stripe_index=$(lfs getstripe -i $f)
205
206         sync
207         sleep 2 # ensure we have a fresh statfs
208         sync
209
210         #define OBD_FAIL_MDS_REINT_NET_REP       0x119
211         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
212
213         # retry till statfs returns useful results
214         local after_dd=$(kbytesfree)
215         local i=0
216         while (( $before <= $after_dd && $i < 20 )); do
217                 sync
218                 sleep 1
219                 let ++i
220                 after_dd=$(kbytesfree)
221         done
222
223         log "before_free: $before after_dd_free: $after_dd took $i seconds"
224         (( $before > $after_dd )) ||
225                 error "free grew after dd: before:$before after_dd:$after_dd"
226
227         rm -f $f
228         fail ost$((stripe_index + 1))
229         wait_recovery_complete ost$((stripe_index + 1)) ||
230                 error "OST$((stripe_index + 1)) recovery not completed"
231         $CHECKSTAT -t file $f && return 2 || true
232         sync
233         # let the delete happen
234         wait_mds_ost_sync || error "second wait_mds_ost_sync failed"
235         wait_delete_completed || error "second wait_delete_completed failed"
236         local after=$(kbytesfree)
237         log "free_before: $before free_after: $after"
238         (( $before <= $after + $(fs_log_size) )) ||
239                 error "$before > $after + logsize $(fs_log_size)"
240 }
241 run_test 6 "Fail OST before obd_destroy"
242
243 test_7() {
244         local f=$TDIR/$tfile
245         sync && sleep 5 && sync # wait for delete thread
246
247         # wait till space is returned, following
248         # (( $before > $after_dd)) test counting on that
249         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
250         wait_destroy_complete || error "wait_destroy_complete failed"
251
252         local before=$(kbytesfree)
253         dd if=/dev/urandom bs=4096 count=1280 of=$f ||
254                 error "dd to file failed: $?"
255
256         sync
257         local after_dd=$(kbytesfree)
258         local i=0
259         while (( $before <= $after_dd && $i < 10 )); do
260                 sync
261                 sleep 1
262                 let ++i
263                 after_dd=$(kbytesfree)
264         done
265
266         log "before: $before after_dd: $after_dd took $i seconds"
267         (( $before > $after_dd )) ||
268                 error "space grew after dd: before:$before after_dd:$after_dd"
269         replay_barrier ost1
270         rm -f $f
271         fail ost1
272         wait_recovery_complete ost1 || error "OST recovery not done"
273         $CHECKSTAT -t file $f && return 2 || true
274         sync
275         # let the delete happen
276         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
277         wait_delete_completed || error "wait_delete_completed failed"
278         local after=$(kbytesfree)
279         log "before: $before after: $after"
280         (( $before <= $after + $(fs_log_size) )) ||
281                  error "$before > $after + logsize $(fs_log_size)"
282 }
283 run_test 7 "Fail OST before obd_destroy"
284
285 test_8a() {
286         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
287                 { skip "Need MDS version at least 2.3.0"; return; }
288         verify=$ROOT/tmp/verify-$$
289         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
290                 error "Create verify file failed"
291         #define OBD_FAIL_OST_DQACQ_NET 0x230
292         do_facet ost1 "lctl set_param fail_loc=0x230"
293         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
294         ddpid=$!
295         sleep $TIMEOUT  # wait for the io to become redo io
296         if ! ps -p $ddpid  > /dev/null 2>&1; then
297                 error "redo io finished incorrectly"
298         fi
299         do_facet ost1 "lctl set_param fail_loc=0"
300         wait $ddpid || true
301         cancel_lru_locks osc
302         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
303         rm -f $verify $TDIR/$tfile
304         message=$(dmesg | grep "redo for recoverable error -115")
305         [ -z "$message" ] || error "redo error messages found in dmesg"
306 }
307 run_test 8a "Verify redo io: redo io when get -EINPROGRESS error"
308
309 test_8b() {
310         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
311                 { skip "Need MDS version at least 2.3.0"; return; }
312         verify=$ROOT/tmp/verify-$$
313         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
314                 error "Create verify file failed"
315         #define OBD_FAIL_OST_DQACQ_NET 0x230
316         do_facet ost1 "lctl set_param fail_loc=0x230"
317         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
318         ddpid=$!
319         sleep $TIMEOUT  # wait for the io to become redo io
320         fail ost1
321         do_facet ost1 "lctl set_param fail_loc=0"
322         wait $ddpid || error "dd did not complete"
323         cancel_lru_locks osc
324         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
325         rm -f $verify $TDIR/$tfile
326 }
327 run_test 8b "Verify redo io: redo io should success after recovery"
328
329 test_8c() {
330         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
331                 { skip "Need MDS version at least 2.3.0"; return; }
332         verify=$ROOT/tmp/verify-$$
333         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
334                 error "Create verify file failed"
335         #define OBD_FAIL_OST_DQACQ_NET 0x230
336         do_facet ost1 "lctl set_param fail_loc=0x230"
337         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
338         ddpid=$!
339         sleep $TIMEOUT  # wait for the io to become redo io
340         ost_evict_client
341         # allow recovery to complete
342         sleep $((TIMEOUT + 2))
343         do_facet ost1 "lctl set_param fail_loc=0"
344         wait $ddpid
345         cancel_lru_locks osc
346         cmp $verify $TDIR/$tfile && error "compare files should fail"
347         rm -f $verify $TDIR/$tfile
348 }
349 run_test 8c "Verify redo io: redo io should fail after eviction"
350
351 test_8d() {
352         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
353                 { skip "Need MDS version at least 2.3.0"; return; }
354         #define OBD_FAIL_MDS_DQACQ_NET 0x187
355         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
356         # test the non-intent create path
357         mcreate $TDIR/$tfile &
358         cpid=$!
359         sleep $TIMEOUT
360         if ! ps -p $cpid  > /dev/null 2>&1; then
361                 error "mknod finished incorrectly"
362         fi
363         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
364         wait $cpid || error "mcreate did not complete"
365         stat $TDIR/$tfile || error "mknod failed"
366
367         rm $TDIR/$tfile
368
369         #define OBD_FAIL_MDS_DQACQ_NET 0x187
370         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
371         # test the intent create path
372         openfile -f O_RDWR:O_CREAT $TDIR/$tfile &
373         cpid=$!
374         sleep $TIMEOUT
375         if ! ps -p $cpid > /dev/null 2>&1; then
376                 error "open finished incorrectly"
377         fi
378         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
379         wait $cpid || error "openfile failed"
380         stat $TDIR/$tfile || error "open failed"
381 }
382 run_test 8d "Verify redo creation on -EINPROGRESS"
383
384 test_8e() {
385         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
386                 { skip "Need MDS version at least 2.3.0"; return; }
387         sleep 1 # ensure we have a fresh statfs
388         #define OBD_FAIL_OST_STATFS_EINPROGRESS 0x231
389         do_facet ost1 "lctl set_param fail_loc=0x231"
390         $LFS df $MOUNT &
391         dfpid=$!
392         sleep $TIMEOUT
393         if ! ps -p $dfpid  > /dev/null 2>&1; then
394                 do_facet ost1 "lctl set_param fail_loc=0"
395                 error "df shouldn't have completed!"
396         fi
397 }
398 run_test 8e "Verify that ptlrpc resends request on -EINPROGRESS"
399
400 test_9() {
401         [ $(lustre_version_code ost1) -ge $(version_code 2.6.54) ] ||
402                 { skip "Need OST version at least 2.6.54"; return; }
403         $LFS setstripe -i 0 -c 1 $DIR/$tfile || error "setstripe failed"
404
405         # LU-1573 - Add duplicate write to generate grants
406         dd if=/dev/zero of=$DIR/$tfile count=1 bs=1M > /dev/null ||
407                 error "First write failed"
408         replay_barrier ost1
409         # do IO
410         dd if=/dev/zero of=$DIR/$tfile count=1 bs=1M > /dev/null ||
411                 error "failed to write"
412         # failover, replay and resend replayed waiting request
413         #define OBD_FAIL_TGT_REPLAY_DELAY2       0x714
414         do_facet ost1 $LCTL set_param fail_loc=0x00000714
415         do_facet ost1 $LCTL set_param fail_val=$TIMEOUT
416         fail ost1
417         do_facet ost1 $LCTL set_param fail_loc=0
418         do_facet ost1 "dmesg | tail -n 100" |
419                 sed -n '/no req deadline/,$ p' | grep -q 'Already past' &&
420                 return 1
421         return 0
422 }
423 run_test 9 "Verify that no req deadline happened during recovery"
424
425 test_10() {
426         rm -f $TDIR/$tfile
427
428         dd if=/dev/zero of=$TDIR/$tfile count=10 || error "dd failed"
429
430         #define OBD_FAIL_OSC_DELAY_IO            0x414
431         $LCTL set_param fail_val=60 fail_loc=0x414
432         cancel_lru_locks OST0000-osc &
433         sleep 2
434         facet_failover ost1 || error "failover: $?"
435
436         #define OBD_FAIL_LDLM_GRANT_CHECK        0x32a
437         $LCTL set_param fail_loc=0x32a
438         stat $TDIR/$tfile
439
440         wait
441 }
442 run_test 10 "conflicting PW & PR locks on a client"
443
444 test_12() {
445         [ $FAILURE_MODE != "HARD" ] &&
446                 skip "Test needs FAILURE_MODE HARD" && return 0
447         remote_ost || { skip "need remote OST" && return 0; }
448
449         local tmp=$TMP/$tdir
450         local dir=$DIR/$tdir
451         declare -a pids
452
453
454         mkdir -p $tmp || error "can't create $tmp"
455         mkdir -p $dir || error "can't create $dir"
456
457         $LFS setstripe -c 1 -i 0 $dir
458
459         for i in `seq 1 10`; do mkdir $dir/d$i; done
460
461         #define OBD_FAIL_OST_DELAY_TRANS        0x245
462         do_facet ost1 "$LCTL set_param fail_loc=0x245" ||
463                 error "can't set fail_loc"
464
465         for i in `seq 1 10`;
466         do
467                 createmany -o $dir/d$i/$(openssl rand -base64 12) 500 &
468                 pids+=($!)
469         done
470         echo "Waiting createmany pids"
471         wait ${pids[@]}
472
473         ls -lR $dir > $tmp/ls_r_out 2>&1&
474         local ls_pid=$!
475
476         facet_failover ost1
477
478         echo "starting wait for ls -l"
479         wait $ls_pid
480         grep "?\|No such file or directory" $tmp/ls_r_out &&
481                 error "Found file without object on OST"
482         rm -rf $tmp
483         rm -rf $dir
484 }
485 run_test 12 "check stat after OST failover"
486
487 complete $SECONDS
488 check_and_cleanup_lustre
489 exit_status