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