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 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/include/libtest.kshlib
27. $STF_SUITE/tests/cli_root/zpool_create/zpool_create.kshlib
28
29################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zpool_create_011_neg
34#
35# DESCRIPTION:
36# 'zpool create' will fail in the following cases:
37# existent pool; device is part of an active pool; nested virtual devices;
38# differently sized devices without -f option; device being currently
39# mounted; devices in /etc/fstab; specified as the dedicated dump device.
40#
41# STRATEGY:
42# 1. Create case scenarios
43# 2. For each scenario, try to create a new pool with the virtual devices
44# 3. Verify the creation is failed.
45#
46# TESTABILITY: explicit
47#
48# TEST_AUTOMATION_LEVEL: automated
49#
50# CODING_STATUS: COMPLETED (2005-07-04)
51#
52# __stc_assertion_end
53#
54################################################################################
55
56verify_runnable "global"
57
58function cleanup
59{
60        for pool in $TESTPOOL $TESTPOOL1
61        do
62                destroy_pool $pool
63        done
64
65	if [[ -n $specified_dump_dev ]]; then
66		$DUMPON -r $specified_dump_dev
67	fi
68}
69
70log_assert "'zpool create' should be failed with inapplicable scenarios."
71log_onexit cleanup
72
73if [[ -n $DISK ]]; then
74        disk=$DISK
75else
76        disk=$DISK0
77fi
78pooldev1=${disk}p1
79pooldev2=${disk}p2
80mirror1="${disk}p2 ${disk}p3"
81mirror2="${disk}p4 ${disk}p5"
82raidz1=$mirror1
83raidz2=$mirror2
84diff_size_dev="${disk}p6 ${disk}p7"
85fstab_dev=$(find_fstab_dev)
86specified_dump_dev=${disk}
87
88lba=$(get_partition_end $disk 6)
89$GPART delete -i 7 $disk
90set_partition 7 "$lba" $SIZE1 $disk
91create_pool "$TESTPOOL" "$pooldev1"
92
93#
94# Set up the testing scenarios parameters
95#
96set -A arg "$TESTPOOL $pooldev2" \
97        "$TESTPOOL1 $pooldev1" \
98        "$TESTPOOL1 $TESTDIR0/$FILEDISK0" \
99        "$TESTPOOL1 mirror mirror $mirror1 mirror $mirror2" \
100        "$TESTPOOL1 raidz raidz $raidz1 raidz $raidz2" \
101        "$TESTPOOL1 raidz1 raidz1 $raidz1 raidz1 $raidz2" \
102        "$TESTPOOL1 mirror raidz $raidz1 raidz $raidz2" \
103        "$TESTPOOL1 mirror raidz1 $raidz1 raidz1 $raidz2" \
104        "$TESTPOOL1 raidz mirror $mirror1 mirror $mirror2" \
105        "$TESTPOOL1 raidz1 mirror $mirror1 mirror $mirror2" \
106        "$TESTPOOL1 mirror $diff_size_dev" \
107        "$TESTPOOL1 raidz $diff_size_dev" \
108        "$TESTPOOL1 raidz1 $diff_size_dev" \
109	"$TESTPOOL1 mirror $mirror1 spare $mirror2 spare $diff_size_dev" \
110        "$TESTPOOL1 $fstab_dev" \
111        "$TESTPOOL1 ${disk}s10" \
112	"$TESTPOOL1 spare $pooldev2"
113
114typeset -i i=0
115while (( i < ${#arg[*]} )); do
116        log_mustnot $ZPOOL create ${arg[i]}
117        (( i = i+1 ))
118done
119
120# now destroy the pool to be polite
121log_must $ZPOOL destroy -f $TESTPOOL
122
123# create/destroy a pool as a simple way to set the partitioning
124# back to something normal so we can use this $disk as a dump device
125log_must $ZPOOL create -f $TESTPOOL3 $disk
126log_must $ZPOOL destroy -f $TESTPOOL3
127
128log_must dumpon $specified_dump_dev
129log_mustnot $ZPOOL create -f $TESTPOOL1 "$specified_dump_dev"
130
131# Also check to see that in-use checking prevents us from creating
132# a zpool from just the first slice on the disk.
133log_mustnot $ZPOOL create -f $TESTPOOL1 ${specified_dump_dev}s0
134
135log_pass "'zpool create' is failed as expected with inapplicable scenarios."
136