]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/removal/removal_cancel.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / removal / removal_cancel.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) 2018 by Delphix. All rights reserved.
19 #
20
21 . $STF_SUITE/include/libtest.shlib
22 . $STF_SUITE/tests/functional/removal/removal.kshlib
23
24 #
25 # DESCRIPTION:
26 #
27 # Ensure that cancelling a removal midway does not cause any
28 # issues like cause a panic.
29 #
30 # STRATEGY:
31 #
32 # 1. Create a pool with one vdev and do some writes on it.
33 # 2. Add a new vdev to the pool and start the removal of
34 #    the first vdev.
35 # 3. Cancel the removal after some segments have been copied
36 #    over to the new vdev.
37 # 4. Run zdb to ensure the on-disk state of the pool is ok.
38 #
39
40 function cleanup
41 {
42         #
43         # Reset tunable.
44         #
45         log_must set_tunable32 REMOVAL_SUSPEND_PROGRESS 0
46 }
47 log_onexit cleanup
48
49 SAMPLEFILE=/$TESTDIR/00
50
51 #
52 # Create pool with one disk.
53 #
54 log_must default_setup_noexit "$REMOVEDISK"
55
56 #
57 # Create a file of size 1GB and then do some random writes.
58 # Since randwritecomp does 8K writes we do 25000 writes
59 # which means we write ~200MB to the vdev.
60 #
61 log_must mkfile -n 1g $SAMPLEFILE
62 log_must randwritecomp $SAMPLEFILE 25000
63
64 #
65 # Add second device where all the data will be evacuated.
66 #
67 log_must zpool add -f $TESTPOOL $NOTREMOVEDISK
68
69 #
70 # Block removal.
71 #
72 log_must set_tunable32 REMOVAL_SUSPEND_PROGRESS 1
73
74 #
75 # Start removal.
76 #
77 log_must zpool remove $TESTPOOL $REMOVEDISK
78
79 #
80 # Only for debugging purposes in test logs.
81 #
82 log_must zpool status $TESTPOOL
83
84 #
85 # Cancel removal.
86 #
87 log_must zpool remove -s $TESTPOOL
88
89 #
90 # Verify on-disk state.
91 #
92 log_must zdb $TESTPOOL
93
94 log_pass "Device removal thread cancelled successfully."