]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/removal/remove_expanded.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / removal / remove_expanded.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 # BACKGROUND:
26 #
27 # ztest hit an issue where it ran zdb and zdb failed because
28 # it couldn't access some indirect mappings at the end of a
29 # vdev. The issue was that the vdev's ms_shift had changed after
30 # it was removed by the addition of another vdev. This test is
31 # a regression test for ensuring this case doesn't come up again.
32 #
33
34
35 TMPDIR=${TMPDIR:-$TEST_BASE_DIR}
36 DISK0=$TMPDIR/dsk0
37 DISK1=$TMPDIR/dsk1
38 DISK2=$TMPDIR/dsk2
39
40 log_must truncate -s $MINVDEVSIZE $DISK0
41 log_must truncate -s $(($MINVDEVSIZE * 3)) $DISK1
42 log_must truncate -s $MINVDEVSIZE $DISK2
43
44 function cleanup
45 {
46         default_cleanup_noexit
47         log_must rm -f $DISK0 $DISK1 $DISK2
48 }
49
50 #
51 # Setup the pool with one disk .
52 #
53 log_must default_setup_noexit "$DISK0"
54 log_onexit cleanup
55
56 #
57 # Expand vdev.
58 #
59 log_must truncate -s $(($MINVDEVSIZE * 2)) $DISK0
60 log_must zpool reopen $TESTPOOL
61 log_must zpool online -e $TESTPOOL $DISK0
62
63 #
64 # Fill up the whole vdev.
65 #
66 dd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=8M
67
68 #
69 # Add another vdev and remove the first vdev creating indirect
70 # mappings for nearly all the allocatable space from the first
71 # vdev. Wait for removal to finish.
72 #
73 log_must zpool add $TESTPOOL $DISK1
74 log_must zpool remove $TESTPOOL $DISK0
75 log_must wait_for_removal $TESTPOOL
76
77 #
78 # Add a new vdev that will trigger a change in the config.
79 # Run sync once to ensure that the config actually changed.
80 #
81 log_must zpool add $TESTPOOL $DISK2
82 log_must sync
83
84 #
85 # Ensure that zdb does not find any problems with this.
86 #
87 log_must zdb $TESTPOOL
88
89 log_pass "Removal of expanded vdev doesn't cause any problems."