]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/removal/removal_resume_export.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / removal / removal_resume_export.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) 2017 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 # When a pool has an ongoing removal and it is exported ZFS
28 # suspends the removal thread beforehand. This test ensures
29 # that ZFS restarts the removal thread if the export fails
30 # for some reason.
31 #
32 # STRATEGY:
33 #
34 # 1. Create a pool with one vdev and do some writes on it.
35 # 2. Add a new vdev to the pool and start the removal of
36 #    the first vdev.
37 # 3. Inject a fault in the pool and attempt to export (it
38 #    should fail).
39 # 4. After the export fails ensure that the removal thread
40 #    was restarted and the process complete successfully.
41 #
42
43
44 function cleanup
45 {
46         zinject -c all
47         default_cleanup_noexit
48 }
49
50 function callback
51 {
52         #
53         # Inject an error so export fails after having just suspended
54         # the removal thread. [spa_inject_ref gets incremented]
55         #
56         log_must zinject -d $REMOVEDISK -D 10:1 $TESTPOOL
57
58         #
59         # Because of the above error export should fail.
60         #
61         log_mustnot zpool export $TESTPOOL
62
63         #
64         # Let the removal finish.
65         #
66         log_must zinject -c all
67
68         return 0
69 }
70
71 log_onexit cleanup
72
73 #
74 # Create pool with one disk.
75 #
76 log_must default_setup_noexit "$REMOVEDISK"
77
78 #
79 # Turn off compression to raise capacity as much as possible
80 # for the little time that this test runs.
81 #
82 log_must zfs set compression=off $TESTPOOL/$TESTFS
83
84 #
85 # Write some data that will be evacuated from the device when
86 # we start the removal.
87 #
88 log_must dd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=64M count=32
89
90 #
91 # Add second device where all the data will be evacuated.
92 #
93 log_must zpool add -f $TESTPOOL $NOTREMOVEDISK
94
95 #
96 # Attempt the export with errors injected.
97 #
98 log_must attempt_during_removal $TESTPOOL $REMOVEDISK callback
99
100 log_pass "Device removal thread resumes after failed export"