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 2019, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22. $STF_SUITE/tests/functional/removal/removal.kshlib
23
24#
25# DESCRIPTION:
26# Device removal cannot remove non-concrete vdevs
27#
28# STRATEGY:
29# 1. Create a pool with removable devices
30# 2. Remove a top-level device
31# 3. Verify we can't remove the "indirect" vdev created by the first removal
32#
33
34verify_runnable "global"
35
36function cleanup
37{
38	destroy_pool $TESTPOOL
39	log_must rm -f $TEST_BASE_DIR/device-{1,2,3}
40}
41
42log_assert "Device removal should not be able to remove non-concrete vdevs"
43log_onexit cleanup
44
45# 1. Create a pool with removable devices
46truncate -s $MINVDEVSIZE $TEST_BASE_DIR/device-{1,2,3}
47zpool create $TESTPOOL $TEST_BASE_DIR/device-{1,2,3}
48
49# 2. Remove a top-level device
50log_must zpool remove $TESTPOOL $TEST_BASE_DIR/device-1
51log_must wait_for_removal $TESTPOOL
52
53# 3. Verify we can't remove the "indirect" vdev created by the first removal
54INDIRECT_VDEV=$(zpool list -v -g $TESTPOOL | awk '{if ($2 == "-") { print $1; exit} }')
55log_must test -n "$INDIRECT_VDEV"
56log_mustnot zpool remove $TESTPOOL $INDIRECT_VDEV
57
58log_pass "Device removal cannot remove non-concrete vdevs"
59