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