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.
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.
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]
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 .
$STF_SUITE/include
/libtest.shlib
33 .
$STF_SUITE/tests
/functional
/cli_root
/zpool_create
/zpool_create.shlib
37 # 'zpool create' have to use '-f' scenarios
40 # 1. Prepare the scenarios
41 # 2. Create pool without '-f' and verify it fails
42 # 3. Create pool with '-f' and verify it succeeds
45 verify_runnable
"global"
48 # Versions of libblkid older than 2.27.0 will not always detect member
49 # devices of a pool, therefore skip this test case for old versions.
50 currentver
="$(blkid -v | tr ',' ' ' | awk '/libblkid/ { print $6 }')"
53 if [ "$(printf "$requiredver\n$currentver" | sort -V | head -n1)" == \
54 "$currentver" ] && [ "$currentver" != "$requiredver" ]; then
55 log_unsupported
"libblkid ($currentver) may not detect pools"
61 if [[ $exported_pool == true
]]; then
62 if [[ $force_pool == true
]]; then
63 log_must zpool create \
64 -f $TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0}
66 log_must zpool import
$TESTPOOL
70 if poolexists
$TESTPOOL ; then
71 destroy_pool
$TESTPOOL
74 if poolexists
$TESTPOOL1 ; then
75 destroy_pool
$TESTPOOL1
79 # recover it back to EFI label
81 create_pool
$TESTPOOL $disk
82 destroy_pool
$TESTPOOL
84 partition_disk
$SIZE $disk 6
88 # create overlap slice 0 and 1 on $disk
90 function create_overlap_slice
92 typeset format_file
=/var
/tmp
/format_overlap.$$
95 echo "partition" >$format_file
96 echo "0" >> $format_file
97 echo "" >> $format_file
98 echo "" >> $format_file
99 echo "0" >> $format_file
100 echo "200m" >> $format_file
101 echo "1" >> $format_file
102 echo "" >> $format_file
103 echo "" >> $format_file
104 echo "0" >> $format_file
105 echo "400m" >> $format_file
106 echo "label" >> $format_file
107 echo "" >> $format_file
108 echo "q" >> $format_file
109 echo "q" >> $format_file
111 format
-e -s -d $disk -f $format_file
115 if (( ret
!= 0 )); then
116 log_fail
"unable to create overlap slice."
122 log_assert
"'zpool create' have to use '-f' scenarios"
125 typeset exported_pool
=false
126 typeset force_pool
=false
128 if [[ -n $DISK ]]; then
134 # overlapped slices as vdev need -f to create pool
136 # Make the disk is EFI labeled first via pool creation
137 create_pool
$TESTPOOL $disk
138 destroy_pool
$TESTPOOL
141 # Make the disk is VTOC labeled since only VTOC label supports overlap
142 log_must labelvtoc
$disk
143 log_must create_overlap_slice
$disk
146 log_mustnot zpool create
$TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0}
147 log_must zpool create
-f $TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0}
148 destroy_pool
$TESTPOOL
151 # exported device to be as spare vdev need -f to create pool
153 log_must zpool create
-f $TESTPOOL $disk
154 destroy_pool
$TESTPOOL
155 log_must partition_disk
$SIZE $disk 6
156 create_pool
$TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0} \
157 ${disk}${SLICE_PREFIX}${SLICE1}
158 log_must zpool
export $TESTPOOL
160 log_mustnot zpool create
$TESTPOOL1 ${disk}${SLICE_PREFIX}${SLICE3} \
161 spare
${disk}${SLICE_PREFIX}${SLICE1}
162 create_pool
$TESTPOOL1 ${disk}${SLICE_PREFIX}${SLICE3} \
163 spare
${disk}${SLICE_PREFIX}${SLICE1}
165 destroy_pool
$TESTPOOL1
167 log_pass
"'zpool create' have to use '-f' scenarios"