]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_010_pos.ksh
b8b25db1b9f92eaa3b6d65f692c685c5d3a0cc81
[mirror_zfs.git] / tests / zfs-tests / tests / functional / cli_root / zpool_add / zpool_add_010_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 https://opensource.org/licenses/CDDL-1.0.
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 # Verify zpool add succeed when adding vdevs with matching redundancy.
38 #
39 # STRATEGY:
40 # 1. Create several files == $MINVDEVSIZE.
41 # 2. Verify 'zpool add' succeeds with matching redundancy.
42 # 3. Verify 'zpool add' warns with differing redundancy.
43 # 4. Verify 'zpool add' warns with differing redundancy after removal.
44 #
45
46 verify_runnable "global"
47
48 function cleanup
49 {
50 datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1
51
52 typeset -i i=0
53 while ((i < 10)); do
54 rm -f $TEST_BASE_DIR/vdev$i
55 ((i += 1))
56 done
57 }
58
59
60 log_assert "Verify 'zpool add' succeed with keywords combination."
61 log_onexit cleanup
62
63 # 1. Create several files == $MINVDEVSIZE.
64 typeset -i i=0
65 while ((i < 10)); do
66 log_must truncate -s $MINVDEVSIZE $TEST_BASE_DIR/vdev$i
67
68 eval vdev$i=$TEST_BASE_DIR/vdev$i
69 ((i += 1))
70 done
71
72 set -A redundancy0_create_args \
73 "$vdev0"
74
75 set -A redundancy1_create_args \
76 "mirror $vdev0 $vdev1" \
77 "raidz1 $vdev0 $vdev1"
78
79 set -A redundancy2_create_args \
80 "mirror $vdev0 $vdev1 $vdev2" \
81 "raidz2 $vdev0 $vdev1 $vdev2"
82
83 set -A redundancy3_create_args \
84 "mirror $vdev0 $vdev1 $vdev2 $vdev3" \
85 "raidz3 $vdev0 $vdev1 $vdev2 $vdev3"
86
87 set -A redundancy0_add_args \
88 "$vdev5" \
89 "$vdev5 $vdev6"
90
91 set -A redundancy1_add_args \
92 "mirror $vdev5 $vdev6" \
93 "raidz1 $vdev5 $vdev6" \
94 "raidz1 $vdev5 $vdev6 mirror $vdev7 $vdev8" \
95 "mirror $vdev5 $vdev6 raidz1 $vdev7 $vdev8"
96
97 set -A redundancy2_add_args \
98 "mirror $vdev5 $vdev6 $vdev7" \
99 "raidz2 $vdev5 $vdev6 $vdev7"
100
101 set -A redundancy3_add_args \
102 "mirror $vdev5 $vdev6 $vdev7 $vdev8" \
103 "raidz3 $vdev5 $vdev6 $vdev7 $vdev8"
104
105 set -A log_args "log" "$vdev4"
106 set -A cache_args "cache" "$vdev4"
107 set -A spare_args "spare" "$vdev4"
108
109 typeset -i j=0
110
111 function zpool_create_add
112 {
113 typeset -n create_args=$1
114 typeset -n add_args=$2
115
116 i=0
117 while ((i < ${#create_args[@]})); do
118 j=0
119 while ((j < ${#add_args[@]})); do
120 log_must zpool create $TESTPOOL1 ${create_args[$i]}
121 log_must zpool add $TESTPOOL1 ${add_args[$j]}
122 log_must zpool destroy -f $TESTPOOL1
123
124 ((j += 1))
125 done
126 ((i += 1))
127 done
128 }
129
130 function zpool_create_forced_add
131 {
132 typeset -n create_args=$1
133 typeset -n add_args=$2
134
135 i=0
136 while ((i < ${#create_args[@]})); do
137 j=0
138 while ((j < ${#add_args[@]})); do
139 log_must zpool create $TESTPOOL1 ${create_args[$i]}
140 log_mustnot zpool add $TESTPOOL1 ${add_args[$j]}
141 log_must zpool add -f $TESTPOOL1 ${add_args[$j]}
142 log_must zpool destroy -f $TESTPOOL1
143
144 ((j += 1))
145 done
146 ((i += 1))
147 done
148 }
149
150 function zpool_create_rm_add
151 {
152 typeset -n create_args=$1
153 typeset -n add_args=$2
154 typeset -n rm_args=$3
155
156 i=0
157 while ((i < ${#create_args[@]})); do
158 j=0
159 while ((j < ${#add_args[@]})); do
160 log_must zpool create $TESTPOOL1 ${create_args[$i]}
161 log_must zpool add $TESTPOOL1 ${rm_args[0]} ${rm_args[1]}
162 log_must zpool add $TESTPOOL1 ${add_args[$j]}
163 log_must zpool remove $TESTPOOL1 ${rm_args[1]}
164 log_mustnot zpool add $TESTPOOL1 ${rm_args[1]}
165 log_must zpool add $TESTPOOL1 ${rm_args[0]} ${rm_args[1]}
166 log_must zpool destroy -f $TESTPOOL1
167
168 ((j += 1))
169 done
170 ((i += 1))
171 done
172 }
173
174 # 2. Verify 'zpool add' succeeds with matching redundancy.
175 zpool_create_add redundancy0_create_args redundancy0_add_args
176 zpool_create_add redundancy1_create_args redundancy1_add_args
177 zpool_create_add redundancy2_create_args redundancy2_add_args
178 zpool_create_add redundancy3_create_args redundancy3_add_args
179
180 # 3. Verify 'zpool add' warns with differing redundancy.
181 zpool_create_forced_add redundancy0_create_args redundancy1_add_args
182 zpool_create_forced_add redundancy0_create_args redundancy2_add_args
183 zpool_create_forced_add redundancy0_create_args redundancy3_add_args
184
185 zpool_create_forced_add redundancy1_create_args redundancy0_add_args
186 zpool_create_forced_add redundancy1_create_args redundancy2_add_args
187 zpool_create_forced_add redundancy1_create_args redundancy3_add_args
188
189 zpool_create_forced_add redundancy2_create_args redundancy0_add_args
190 zpool_create_forced_add redundancy2_create_args redundancy1_add_args
191 zpool_create_forced_add redundancy2_create_args redundancy3_add_args
192
193 zpool_create_forced_add redundancy3_create_args redundancy0_add_args
194 zpool_create_forced_add redundancy3_create_args redundancy1_add_args
195 zpool_create_forced_add redundancy3_create_args redundancy2_add_args
196
197 # 4. Verify 'zpool add' warns with differing redundancy after removal.
198 zpool_create_rm_add redundancy1_create_args redundancy1_add_args log_args
199 zpool_create_rm_add redundancy2_create_args redundancy2_add_args log_args
200 zpool_create_rm_add redundancy3_create_args redundancy3_add_args log_args
201
202 zpool_create_rm_add redundancy1_create_args redundancy1_add_args cache_args
203 zpool_create_rm_add redundancy2_create_args redundancy2_add_args cache_args
204 zpool_create_rm_add redundancy3_create_args redundancy3_add_args cache_args
205
206 zpool_create_rm_add redundancy1_create_args redundancy1_add_args spare_args
207 zpool_create_rm_add redundancy2_create_args redundancy2_add_args spare_args
208 zpool_create_rm_add redundancy3_create_args redundancy3_add_args spare_args
209
210 log_pass "'zpool add' succeed with keywords combination."