]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/removal/removal_with_errors.ksh
Add subcommand to wait for background zfs activity to complete
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / removal / removal_with_errors.ksh
1 #! /bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
8 # 1.0 of the CDDL.
9 #
10 # A full copy of the text of the CDDL should have accompanied this
11 # source.  A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
13 #
14 # CDDL HEADER END
15 #
16
17 #
18 # Copyright (c) 2014, 2017 by Delphix. All rights reserved.
19 # Copyright (c) 2018 by Lawrence Livermore National Security, LLC.
20 #
21
22 . $STF_SUITE/include/libtest.shlib
23 . $STF_SUITE/tests/functional/removal/removal.kshlib
24
25 #
26 # DESCRIPTION:
27 #
28 # This test ensures the device removal is cancelled when hard IO
29 # errors are encountered during the removal process.  This is done
30 # to ensure that when removing a device all of the data is copied.
31 #
32 # STRATEGY:
33 #
34 # 1. We create a pool with enough redundancy such that IO errors
35 #    will not result in the pool being suspended.
36 # 2. We write some test data to the pool.
37 # 3. We inject READ errors in to one half of the top-level mirror-0
38 #    vdev which is being removed.  Then we start the removal process.
39 # 4. Verify that the injected read errors cause the removal of
40 #    mirror-0 to be cancelled and that mirror-0 has not been removed.
41 # 5. Clear the read fault injection.
42 # 6. Repeat steps 3-6 above except inject WRITE errors on one of
43 #    child vdevs in the destination mirror-1.
44 # 7. Lastly verify the pool data is still intact.
45 #
46
47 TMPDIR=${TMPDIR:-$TEST_BASE_DIR}
48 DISK0=$TMPDIR/dsk0
49 DISK1=$TMPDIR/dsk1
50 DISK2=$TMPDIR/dsk2
51 DISK3=$TMPDIR/dsk3
52
53 log_must truncate -s $MINVDEVSIZE $DISK0 $DISK1
54 log_must truncate -s $((MINVDEVSIZE * 4)) $DISK2 $DISK3
55
56 function cleanup
57 {
58         log_must zinject -c all
59         default_cleanup_noexit
60         log_must rm -f $DISK0 $DISK1 $DISK2 $DISK3
61 }
62
63 function wait_for_removing_cancel
64 {
65         typeset pool=$1
66
67         log_must zpool wait -t remove $pool
68
69         #
70         # The pool state changes before the TXG finishes syncing; wait for
71         # the removal to be completed on disk.
72         #
73         sync_pool
74
75         log_mustnot is_pool_removed $pool
76         return 0
77 }
78
79 default_setup_noexit "mirror $DISK0 $DISK1 mirror $DISK2 $DISK3"
80 log_onexit cleanup
81
82 FILE_CONTENTS="Leeloo Dallas mul-ti-pass."
83
84 echo $FILE_CONTENTS  >$TESTDIR/$TESTFILE0
85 log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
86 log_must file_write -o create -f $TESTDIR/$TESTFILE1 -b $((2**20)) -c $((2**7))
87 sync_pool $TESTPOOL
88
89 # Verify that unexpected read errors automatically cancel the removal.
90 log_must zinject -d $DISK0 -e io -T all -f 100 $TESTPOOL
91 log_must zpool remove $TESTPOOL mirror-0
92 log_must wait_for_removing_cancel $TESTPOOL
93 log_must vdevs_in_pool $TESTPOOL mirror-0
94 log_must zinject -c all
95
96 # Verify that unexpected write errors automatically cancel the removal.
97 log_must zinject -d $DISK3 -e io -T all -f 100 $TESTPOOL
98 log_must zpool remove $TESTPOOL mirror-0
99 log_must wait_for_removing_cancel $TESTPOOL
100 log_must vdevs_in_pool $TESTPOOL mirror-0
101 log_must zinject -c all
102
103 log_must dd if=$TESTDIR/$TESTFILE0 of=/dev/null
104 log_must [ "x$(<$TESTDIR/$TESTFILE0)" = "x$FILE_CONTENTS" ]
105 log_must dd if=$TESTDIR/$TESTFILE1 of=/dev/null
106
107 log_pass "Device not removed due to unexpected errors."