1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or https://opensource.org/licenses/CDDL-1.0.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/cli_root/zpool_remove/zpool_remove.cfg
34
35#
36# DESCRIPTION:
37# Verify that 'zpool can not remove device except inactive hot spares from pool'
38#
39# STRATEGY:
40# 1. Create all kinds of pool (strip, mirror, raidz, hotspare)
41# 2. Try to remove device from the pool
42# 3. Verify that the remove failed.
43#
44
45typeset vdev_devs="${DISK0}"
46typeset mirror_devs="${DISK0} ${DISK1}"
47typeset raidz_devs=${mirror_devs}
48typeset raidz1_devs=${mirror_devs}
49typeset raidz2_devs="${mirror_devs} ${DISK2}"
50typeset spare_devs1="${DISK0}"
51typeset spare_devs2="${DISK1}"
52
53function check_remove
54{
55        typeset pool=$1
56        typeset devs="$2"
57        typeset dev
58
59        for dev in $devs; do
60                log_mustnot zpool remove $dev
61        done
62
63        destroy_pool $pool
64
65}
66
67function cleanup
68{
69        if poolexists $TESTPOOL; then
70                destroy_pool $TESTPOOL
71        fi
72}
73
74set -A create_args "$vdev_devs" "mirror $mirror_devs"  \
75		"raidz $raidz_devs" "raidz $raidz1_devs" \
76		"raidz2 $raidz2_devs" \
77		"$spare_devs1 spare $spare_devs2"
78
79set -A verify_disks "$vdev_devs" "$mirror_devs" "$raidz_devs" \
80		"$raidz1_devs" "$raidz2_devs" "$spare_devs1"
81
82
83log_assert "Check zpool remove <pool> <device> can not remove " \
84	"active device from pool"
85
86log_onexit cleanup
87
88typeset -i i=0
89while [[ $i -lt ${#create_args[*]} ]]; do
90	log_must zpool create $TESTPOOL ${create_args[i]}
91	check_remove $TESTPOOL "${verify_disks[i]}"
92	(( i = i + 1))
93done
94
95log_pass "'zpool remove <pool> <device> fail as expected .'"
96