]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_008_pos.ksh
Encryption patch follow-up
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zpool_create / zpool_create_008_pos.ksh
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 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
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' have to use '-f' scenarios
38 #
39 # STRATEGY:
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
43 #
44
45 verify_runnable "global"
46
47 if is_linux; then
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 }')"
51 requiredver="2.27.0"
52
53 if [ "$(printf "$requiredver\n$currentver" | sort -V | head -n1)" == \
54 "$currentver" ] && [ "$currentver" != "$requiredver" ]; then
55 log_unsupported "libblkid ($currentver) may not detect pools"
56 fi
57 fi
58
59 function cleanup
60 {
61 if [[ $exported_pool == true ]]; then
62 if [[ $force_pool == true ]]; then
63 log_must zpool create \
64 -f $TESTPOOL ${disk}${SLICE_PREFIX}${SLICE0}
65 else
66 log_must zpool import $TESTPOOL
67 fi
68 fi
69
70 if poolexists $TESTPOOL ; then
71 destroy_pool $TESTPOOL
72 fi
73
74 if poolexists $TESTPOOL1 ; then
75 destroy_pool $TESTPOOL1
76 fi
77
78 #
79 # recover it back to EFI label
80 #
81 create_pool $TESTPOOL $disk
82 destroy_pool $TESTPOOL
83
84 partition_disk $SIZE $disk 6
85 }
86
87 #
88 # create overlap slice 0 and 1 on $disk
89 #
90 function create_overlap_slice
91 {
92 typeset format_file=/var/tmp/format_overlap.$$
93 typeset disk=$1
94
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
110
111 format -e -s -d $disk -f $format_file
112 typeset -i ret=$?
113 rm -fr $format_file
114
115 if (( ret != 0 )); then
116 log_fail "unable to create overlap slice."
117 fi
118
119 return 0
120 }
121
122 log_assert "'zpool create' have to use '-f' scenarios"
123 log_onexit cleanup
124
125 typeset exported_pool=false
126 typeset force_pool=false
127
128 if [[ -n $DISK ]]; then
129 disk=$DISK
130 else
131 disk=$DISK0
132 fi
133
134 # overlapped slices as vdev need -f to create pool
135
136 # Make the disk is EFI labeled first via pool creation
137 create_pool $TESTPOOL $disk
138 destroy_pool $TESTPOOL
139
140 if ! is_linux; then
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
144
145 unset NOINUSE_CHECK
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
149 fi
150
151 # exported device to be as spare vdev need -f to create pool
152
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
159 exported_pool=true
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}
164 force_pool=true
165 destroy_pool $TESTPOOL1
166
167 log_pass "'zpool create' have to use '-f' scenarios"