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 46verify_runnable "global" 47 48function 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 60log_assert "Verify 'zpool add' succeed with keywords combination." 61log_onexit cleanup 62 63# 1. Create several files == $MINVDEVSIZE. 64typeset -i i=0 65while ((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)) 70done 71 72set -A redundancy0_create_args \ 73 "$vdev0" 74 75set -A redundancy1_create_args \ 76 "mirror $vdev0 $vdev1" \ 77 "raidz1 $vdev0 $vdev1" 78 79set -A redundancy2_create_args \ 80 "mirror $vdev0 $vdev1 $vdev2" \ 81 "raidz2 $vdev0 $vdev1 $vdev2" 82 83set -A redundancy3_create_args \ 84 "mirror $vdev0 $vdev1 $vdev2 $vdev3" \ 85 "raidz3 $vdev0 $vdev1 $vdev2 $vdev3" 86 87set -A redundancy0_add_args \ 88 "$vdev5" \ 89 "$vdev5 $vdev6" 90 91set -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 97set -A redundancy2_add_args \ 98 "mirror $vdev5 $vdev6 $vdev7" \ 99 "raidz2 $vdev5 $vdev6 $vdev7" 100 101set -A redundancy3_add_args \ 102 "mirror $vdev5 $vdev6 $vdev7 $vdev8" \ 103 "raidz3 $vdev5 $vdev6 $vdev7 $vdev8" 104 105set -A log_args "log" "$vdev4" 106set -A cache_args "cache" "$vdev4" 107set -A spare_args "spare" "$vdev4" 108 109typeset -i j=0 110 111function 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 130function 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 150function 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. 175zpool_create_add redundancy0_create_args redundancy0_add_args 176zpool_create_add redundancy1_create_args redundancy1_add_args 177zpool_create_add redundancy2_create_args redundancy2_add_args 178zpool_create_add redundancy3_create_args redundancy3_add_args 179 180# 3. Verify 'zpool add' warns with differing redundancy. 181zpool_create_forced_add redundancy0_create_args redundancy1_add_args 182zpool_create_forced_add redundancy0_create_args redundancy2_add_args 183zpool_create_forced_add redundancy0_create_args redundancy3_add_args 184 185zpool_create_forced_add redundancy1_create_args redundancy0_add_args 186zpool_create_forced_add redundancy1_create_args redundancy2_add_args 187zpool_create_forced_add redundancy1_create_args redundancy3_add_args 188 189zpool_create_forced_add redundancy2_create_args redundancy0_add_args 190zpool_create_forced_add redundancy2_create_args redundancy1_add_args 191zpool_create_forced_add redundancy2_create_args redundancy3_add_args 192 193zpool_create_forced_add redundancy3_create_args redundancy0_add_args 194zpool_create_forced_add redundancy3_create_args redundancy1_add_args 195zpool_create_forced_add redundancy3_create_args redundancy2_add_args 196 197# 4. Verify 'zpool add' warns with differing redundancy after removal. 198zpool_create_rm_add redundancy1_create_args redundancy1_add_args log_args 199zpool_create_rm_add redundancy2_create_args redundancy2_add_args log_args 200zpool_create_rm_add redundancy3_create_args redundancy3_add_args log_args 201 202zpool_create_rm_add redundancy1_create_args redundancy1_add_args cache_args 203zpool_create_rm_add redundancy2_create_args redundancy2_add_args cache_args 204zpool_create_rm_add redundancy3_create_args redundancy3_add_args cache_args 205 206zpool_create_rm_add redundancy1_create_args redundancy1_add_args spare_args 207zpool_create_rm_add redundancy2_create_args redundancy2_add_args spare_args 208zpool_create_rm_add redundancy3_create_args redundancy3_add_args spare_args 209 210log_pass "'zpool add' succeed with keywords combination." 211