1#!/usr/local/bin/ksh93 -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 http://www.opensolaris.org/os/licensing.
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 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/tests/hotspare/hotspare.kshlib
27
28################################################################################
29#
30# __stc_assertion_start
31#
32# ID: hotspare_create_001_neg
33#
34# DESCRIPTION:
35# 'zpool create [-f]' with hot spares will fail
36# while the hot spares belong to the following cases:
37#	- existing pool
38#	- nonexistent device,
39#	- part of an active pool,
40#	- currently mounted,
41#	- a swap device,
42#	- a dump device,
43#	- identical with the basic vdev within the pool,
44#
45# STRATEGY:
46# 1. Create case scenarios
47# 2. For each scenario, try to create a new pool with hot spares
48# 	of the virtual devices
49# 3. Verify the creation is failed.
50#
51# TESTABILITY: explicit
52#
53# TEST_AUTOMATION_LEVEL: automated
54#
55# CODING_STATUS: COMPLETED (2006-06-07)
56#
57# __stc_assertion_end
58#
59################################################################################
60
61verify_runnable "global"
62
63function cleanup
64{
65	for pool in $TESTPOOL $TESTPOOL1
66	do
67		destroy_pool $pool
68	done
69
70	log_onfail $UMOUNT $TMPDIR/mounted_dir
71	log_onfail $SWAPOFF $swap_dev
72	log_onfail $DUMPON -r $dump_dev
73
74	partition_cleanup
75}
76
77log_assert "'zpool create [-f]' with hot spares should be failed " \
78	"with inapplicable scenarios."
79log_onexit cleanup
80
81set_devs
82
83mounted_dev=${DISK0}
84swap_dev=${DISK1}
85dump_dev=${DISK2}
86nonexist_dev=${disk}sbad_slice_num
87
88create_pool "$TESTPOOL" ${pooldevs[0]}
89
90log_must $MKDIR $TMPDIR/mounted_dir
91log_must $NEWFS $mounted_dev
92log_must $MOUNT $mounted_dev $TMPDIR/mounted_dir
93
94log_must $SWAPON $swap_dev
95
96log_must $DUMPON $dump_dev
97
98#
99# Set up the testing scenarios parameters
100#	- existing pool
101#	- nonexistent device,
102#	- part of an active pool,
103#	- currently mounted,
104#	- a swap device,
105#	- identical with the basic vdev within the pool,
106
107set -A arg "$TESTPOOL ${pooldevs[1]} spare ${pooldevs[2]}" \
108	"$TESTPOOL1 ${pooldevs[1]} spare $nonexist_dev" \
109	"$TESTPOOL1 ${pooldevs[1]} spare ${pooldevs[0]}" \
110	"$TESTPOOL1 ${pooldevs[1]} spare $mounted_dev" \
111	"$TESTPOOL1 ${pooldevs[1]} spare $swap_dev" \
112	"$TESTPOOL1 ${pooldevs[1]} spare ${pooldevs[1]}"
113
114typeset -i i=0
115while (( i < ${#arg[*]} )); do
116	log_mustnot $ZPOOL create ${arg[i]}
117	log_mustnot $ZPOOL create -f ${arg[i]}
118	(( i = i + 1 ))
119done
120
121#	- a dump device,
122# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=241070
123# When that bug is fixed, add $dump_dev to $arg and remove this block.
124log_must $ZPOOL create $TESTPOOL1 ${pooldevs[1]} spare $dump_dev
125log_must $ZPOOL destroy -f $TESTPOOL1
126log_must $ZPOOL create -f $TESTPOOL1 ${pooldevs[1]} spare $dump_dev
127log_must $ZPOOL destroy -f $TESTPOOL1
128
129# now destroy the pool to be polite
130log_must $ZPOOL destroy -f $TESTPOOL
131
132log_pass "'zpool create [-f]' with hot spare is failed as expected with inapplicable scenarios."
133