]> git.proxmox.com Git - mirror_zfs.git/blame - tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg.ksh
Update ZTS to work on FreeBSD
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zpool_create / zpool_create_011_neg.ksh
CommitLineData
6bb24f4d
BB
1#!/bin/ksh -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#
27
28#
c1d9abf9 29# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
6bb24f4d
BB
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
34
35#
36# DESCRIPTION:
37# 'zpool create' will fail in the following cases:
38# existent pool; device is part of an active pool; nested virtual devices;
39# differently sized devices without -f option; device being currently
40# mounted; devices in /etc/vfstab; specified as the dedicated dump device.
41#
42# STRATEGY:
43# 1. Create case scenarios
44# 2. For each scenario, try to create a new pool with the virtual devices
45# 3. Verify the creation is failed.
46#
47
48verify_runnable "global"
49
50function cleanup
51{
8c54ddd3
BB
52 for pool in $TESTPOOL $TESTPOOL1
53 do
54 destroy_pool $pool
55 done
6bb24f4d
BB
56
57 if [[ -n $saved_dump_dev ]]; then
7839c4b5
MM
58 if is_freebsd; then
59 log_must dumpon $saved_dump_dev
60 else
61 log_must dumpadm -u -d $saved_dump_dev
62 fi
6bb24f4d
BB
63 fi
64
8c54ddd3 65 partition_disk $SIZE $disk 7
6bb24f4d
BB
66}
67
68log_assert "'zpool create' should be failed with inapplicable scenarios."
69log_onexit cleanup
70
71if [[ -n $DISK ]]; then
8c54ddd3 72 disk=$DISK
6bb24f4d 73else
8c54ddd3 74 disk=$DISK0
6bb24f4d
BB
75fi
76pooldev1=${disk}${SLICE_PREFIX}${SLICE0}
77pooldev2=${disk}${SLICE_PREFIX}${SLICE1}
78mirror1="${disk}${SLICE_PREFIX}${SLICE1} ${disk}${SLICE_PREFIX}${SLICE3}"
79mirror2="${disk}${SLICE_PREFIX}${SLICE4} ${disk}${SLICE_PREFIX}${SLICE5}"
80raidz1=$mirror1
81raidz2=$mirror2
82diff_size_dev="${disk}${SLICE_PREFIX}${SLICE6} ${disk}${SLICE_PREFIX}${SLICE7}"
83vfstab_dev=$(find_vfstab_dev)
6bb24f4d 84
8c54ddd3
BB
85if is_linux; then
86 partition_disk $SIZE $disk 7
87 cyl=$(get_endslice $disk $SLICE5)
cf8738d8 88 log_must set_partition $SLICE6 "$cyl" $SIZE1 $disk
8c54ddd3
BB
89else
90 specified_dump_dev=${disk}${SLICE_PREFIX}${SLICE0}
91 saved_dump_dev=$(save_dump_dev)
92
93 cyl=$(get_endslice $disk $SLICE6)
cf8738d8 94 log_must set_partition $SLICE7 "$cyl" $SIZE1 $disk
8c54ddd3 95fi
6bb24f4d
BB
96create_pool "$TESTPOOL" "$pooldev1"
97
98#
99# Set up the testing scenarios parameters
100#
101set -A arg "$TESTPOOL $pooldev2" \
8c54ddd3
BB
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" \
6bb24f4d 114 "$TESTPOOL1 mirror $mirror1 spare $mirror2 spare $diff_size_dev" \
8c54ddd3
BB
115 "$TESTPOOL1 $vfstab_dev" \
116 "$TESTPOOL1 ${disk}s10" \
6bb24f4d
BB
117 "$TESTPOOL1 spare $pooldev2"
118
2171eb71 119unset NOINUSE_CHECK
6bb24f4d
BB
120typeset -i i=0
121while (( i < ${#arg[*]} )); do
8c54ddd3
BB
122 log_mustnot zpool create ${arg[i]}
123 (( i = i+1 ))
6bb24f4d
BB
124done
125
126# now destroy the pool to be polite
c1d9abf9 127log_must zpool destroy -f $TESTPOOL
6bb24f4d 128
8c54ddd3
BB
129if ! is_linux; then
130 # create/destroy a pool as a simple way to set the partitioning
131 # back to something normal so we can use this $disk as a dump device
132 log_must zpool create -f $TESTPOOL3 $disk
133 log_must zpool destroy -f $TESTPOOL3
6bb24f4d 134
7839c4b5
MM
135 if is_freebsd; then
136 log_must dumpon ${DEV_DSKDIR}/$specified_dump_dev
137 else
138 log_must dumpadm -d ${DEV_DSKDIR}/$specified_dump_dev
139 fi
8c54ddd3 140 log_mustnot zpool create -f $TESTPOOL1 "$specified_dump_dev"
6bb24f4d 141
8c54ddd3
BB
142 # Also check to see that in-use checking prevents us from creating
143 # a zpool from just the first slice on the disk.
144 log_mustnot zpool create \
145 -f $TESTPOOL1 ${specified_dump_dev}${SLICE_PREFIX}${SLICE0}
146fi
6bb24f4d
BB
147
148log_pass "'zpool create' is failed as expected with inapplicable scenarios."