]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/sys/cddl/zfs/tests/cli_root/zpool_create/zpool_create_011_neg.ksh
MFC r353117-r353118, r353281-r353282, r353284-r353289, r353309-r353310, r353360-r3533...
[FreeBSD/FreeBSD.git] / tests / sys / cddl / zfs / tests / cli_root / zpool_create / zpool_create_011_neg.ksh
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/fstab; 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
61 verify_runnable "global"
62
63 function cleanup
64 {
65         for pool in $TESTPOOL $TESTPOOL1
66         do
67                 destroy_pool $pool
68         done
69
70         if [[ -n $specified_dump_dev ]]; then
71                 $DUMPON -r $specified_dump_dev
72         fi
73 }
74
75 log_assert "'zpool create' should be failed with inapplicable scenarios."
76 log_onexit cleanup
77
78 if [[ -n $DISK ]]; then
79         disk=$DISK
80 else
81         disk=$DISK0
82 fi
83 pooldev1=${disk}p1
84 pooldev2=${disk}p2
85 mirror1="${disk}p2 ${disk}p3"
86 mirror2="${disk}p4 ${disk}p5"
87 raidz1=$mirror1
88 raidz2=$mirror2
89 diff_size_dev="${disk}p6 ${disk}p7"
90 fstab_dev=$(find_fstab_dev)
91 specified_dump_dev=${disk}
92
93 lba=$(get_partition_end $disk 6)
94 $GPART delete -i 7 $disk
95 set_partition 7 "$lba" $SIZE1 $disk
96 create_pool "$TESTPOOL" "$pooldev1"
97
98 #
99 # Set up the testing scenarios parameters
100 #
101 set -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 $fstab_dev" \
116         "$TESTPOOL1 ${disk}s10" \
117         "$TESTPOOL1 spare $pooldev2"
118
119 typeset -i i=0
120 while (( i < ${#arg[*]} )); do
121         log_mustnot $ZPOOL create ${arg[i]}
122         (( i = i+1 ))
123 done
124
125 # now destroy the pool to be polite
126 log_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
130 log_must $ZPOOL create -f $TESTPOOL3 $disk
131 log_must $ZPOOL destroy -f $TESTPOOL3
132
133 log_must dumpon $specified_dump_dev
134 log_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.
138 log_mustnot $ZPOOL create -f $TESTPOOL1 ${specified_dump_dev}s0
139
140 log_pass "'zpool create' is failed as expected with inapplicable scenarios."