xref: /freebsd-src/sys/contrib/openzfs/tests/zfs-tests/tests/functional/removal/remove_expanded.ksh (revision e92ffd9b626833ebdbf2742c8ffddc6cd94b963e)
1eda14cbcSMatt Macy#! /bin/ksh -p
2eda14cbcSMatt Macy#
3eda14cbcSMatt Macy# CDDL HEADER START
4eda14cbcSMatt Macy#
5eda14cbcSMatt Macy# This file and its contents are supplied under the terms of the
6eda14cbcSMatt Macy# Common Development and Distribution License ("CDDL"), version 1.0.
7eda14cbcSMatt Macy# You may only use this file in accordance with the terms of version
8eda14cbcSMatt Macy# 1.0 of the CDDL.
9eda14cbcSMatt Macy#
10eda14cbcSMatt Macy# A full copy of the text of the CDDL should have accompanied this
11eda14cbcSMatt Macy# source.  A copy of the CDDL is also available via the Internet at
12eda14cbcSMatt Macy# http://www.illumos.org/license/CDDL.
13eda14cbcSMatt Macy#
14eda14cbcSMatt Macy# CDDL HEADER END
15eda14cbcSMatt Macy#
16eda14cbcSMatt Macy
17eda14cbcSMatt Macy#
18eda14cbcSMatt Macy# Copyright (c) 2018 by Delphix. All rights reserved.
19eda14cbcSMatt Macy#
20eda14cbcSMatt Macy
21eda14cbcSMatt Macy. $STF_SUITE/include/libtest.shlib
22eda14cbcSMatt Macy. $STF_SUITE/tests/functional/removal/removal.kshlib
23eda14cbcSMatt Macy
24eda14cbcSMatt Macy#
25eda14cbcSMatt Macy# BACKGROUND:
26eda14cbcSMatt Macy#
27eda14cbcSMatt Macy# ztest hit an issue where it ran zdb and zdb failed because
28eda14cbcSMatt Macy# it couldn't access some indirect mappings at the end of a
29eda14cbcSMatt Macy# vdev. The issue was that the vdev's ms_shift had changed after
30eda14cbcSMatt Macy# it was removed by the addition of another vdev. This test is
31eda14cbcSMatt Macy# a regression test for ensuring this case doesn't come up again.
32eda14cbcSMatt Macy#
33eda14cbcSMatt Macy
34eda14cbcSMatt Macy
35eda14cbcSMatt MacyTMPDIR=${TMPDIR:-$TEST_BASE_DIR}
36eda14cbcSMatt MacyDISK0=$TMPDIR/dsk0
37eda14cbcSMatt MacyDISK1=$TMPDIR/dsk1
38eda14cbcSMatt MacyDISK2=$TMPDIR/dsk2
39eda14cbcSMatt Macy
40eda14cbcSMatt Macylog_must truncate -s $MINVDEVSIZE $DISK0
41eda14cbcSMatt Macylog_must truncate -s $(($MINVDEVSIZE * 3)) $DISK1
42eda14cbcSMatt Macylog_must truncate -s $MINVDEVSIZE $DISK2
43eda14cbcSMatt Macy
44eda14cbcSMatt Macyfunction cleanup
45eda14cbcSMatt Macy{
46eda14cbcSMatt Macy	default_cleanup_noexit
47eda14cbcSMatt Macy	log_must rm -f $DISK0 $DISK1 $DISK2
48eda14cbcSMatt Macy}
49eda14cbcSMatt Macy
50eda14cbcSMatt Macy#
51eda14cbcSMatt Macy# Setup the pool with one disk .
52eda14cbcSMatt Macy#
53eda14cbcSMatt Macylog_must default_setup_noexit "$DISK0"
54eda14cbcSMatt Macylog_onexit cleanup
55eda14cbcSMatt Macy
56eda14cbcSMatt Macy#
57eda14cbcSMatt Macy# Expand vdev.
58eda14cbcSMatt Macy#
59eda14cbcSMatt Macylog_must truncate -s $(($MINVDEVSIZE * 2)) $DISK0
60eda14cbcSMatt Macylog_must zpool reopen $TESTPOOL
61eda14cbcSMatt Macylog_must zpool online -e $TESTPOOL $DISK0
62eda14cbcSMatt Macy
63eda14cbcSMatt Macy#
64eda14cbcSMatt Macy# Fill up the whole vdev.
65eda14cbcSMatt Macy#
66eda14cbcSMatt Macydd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=8M
67eda14cbcSMatt Macy
68eda14cbcSMatt Macy#
69eda14cbcSMatt Macy# Add another vdev and remove the first vdev creating indirect
70eda14cbcSMatt Macy# mappings for nearly all the allocatable space from the first
71eda14cbcSMatt Macy# vdev. Wait for removal to finish.
72eda14cbcSMatt Macy#
73eda14cbcSMatt Macylog_must zpool add $TESTPOOL $DISK1
74eda14cbcSMatt Macylog_must zpool remove $TESTPOOL $DISK0
75eda14cbcSMatt Macylog_must wait_for_removal $TESTPOOL
76eda14cbcSMatt Macy
77eda14cbcSMatt Macy#
78eda14cbcSMatt Macy# Add a new vdev that will trigger a change in the config.
79eda14cbcSMatt Macy# Run sync once to ensure that the config actually changed.
80eda14cbcSMatt Macy#
81eda14cbcSMatt Macylog_must zpool add $TESTPOOL $DISK2
82*e92ffd9bSMartin Matuskasync_all_pools
83eda14cbcSMatt Macy
84eda14cbcSMatt Macy#
85eda14cbcSMatt Macy# Ensure that zdb does not find any problems with this.
86eda14cbcSMatt Macy#
87eda14cbcSMatt Macylog_must zdb $TESTPOOL
88eda14cbcSMatt Macy
89eda14cbcSMatt Macylog_pass "Removal of expanded vdev doesn't cause any problems."
90