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 2020 Attila Fülöp <attila@fueloep.org> 25# 26 27. $STF_SUITE/include/libtest.shlib 28 29typeset STR_DRYRUN="would update '$TESTPOOL' to the following configuration:" 30typeset VDEV_PREFIX="$TEST_BASE_DIR/filedev" 31 32# 33# DESCRIPTION: 34# 'zpool add -n <pool> <vdev> ...' can display the correct configuration 35# 36# STRATEGY: 37# 1. Create different storage pools, use -n to add devices to the pool and 38# verify the output is as expected. 39# 2. Create a pool with a hole vdev and verify it's not listed with add -n. 40# 41 42typeset -a dev=( 43 "${VDEV_PREFIX}00" "${VDEV_PREFIX}01" "${VDEV_PREFIX}02" 44 "${VDEV_PREFIX}03" "${VDEV_PREFIX}04" "${VDEV_PREFIX}05" 45 "${VDEV_PREFIX}06" "${VDEV_PREFIX}07" "${VDEV_PREFIX}08" 46 "${VDEV_PREFIX}09" "${VDEV_PREFIX}10" "${VDEV_PREFIX}11" 47) 48 49typeset -a tests=( 50 ( 51 tree="'${dev[0]}' log '${dev[1]}' special '${dev[2]}' dedup '${dev[3]}'" 52 add="spare '${dev[4]}' cache '${dev[5]}'" 53 want="$STR_DRYRUN 54 55 $TESTPOOL 56 ${dev[0]} 57 dedup 58 ${dev[3]} 59 special 60 ${dev[2]} 61 logs 62 ${dev[1]} 63 cache 64 ${dev[5]} 65 spares 66 ${dev[4]}" 67 ) 68 ( 69 tree="'${dev[0]}' log '${dev[1]}' special '${dev[2]}' dedup '${dev[3]}' \ 70 spare '${dev[4]}' cache '${dev[5]}'" 71 72 add="'${dev[6]}' log '${dev[7]}' special '${dev[8]}' dedup '${dev[9]}' \ 73 spare '${dev[10]}' cache '${dev[11]}'" 74 75 want="$STR_DRYRUN 76 77 $TESTPOOL 78 ${dev[0]} 79 ${dev[6]} 80 dedup 81 ${dev[3]} 82 ${dev[9]} 83 special 84 ${dev[2]} 85 ${dev[8]} 86 logs 87 ${dev[1]} 88 ${dev[7]} 89 cache 90 ${dev[5]} 91 ${dev[11]} 92 spares 93 ${dev[4]} 94 ${dev[10]}" 95 ) 96 ( 97 tree="mirror '${dev[0]}' '${dev[1]}' \ 98 log mirror '${dev[2]}' '${dev[3]}' \ 99 dedup mirror '${dev[6]}' '${dev[7]}' \ 100 spare '${dev[8]}'" 101 102 add="special mirror '${dev[4]}' '${dev[5]}' \ 103 spare '${dev[9]}' cache '${dev[10]}' '${dev[11]}'" 104 105 want="$STR_DRYRUN 106 107 $TESTPOOL 108 mirror-0 109 ${dev[0]} 110 ${dev[1]} 111 dedup 112 mirror 113 ${dev[6]} 114 ${dev[7]} 115 special 116 mirror 117 ${dev[4]} 118 ${dev[5]} 119 logs 120 mirror 121 ${dev[2]} 122 ${dev[3]} 123 cache 124 ${dev[10]} 125 ${dev[11]} 126 spares 127 ${dev[8]} 128 ${dev[9]}" 129 ) 130) 131 132verify_runnable "global" 133 134function cleanup 135{ 136 destroy_pool "$TESTPOOL" 137 rm -f "$VDEV_PREFIX"* 138} 139 140log_assert "'zpool add -n <pool> <vdev> ...' can display the configuration" 141 142log_onexit cleanup 143 144# Create needed file vdevs. 145for (( i=0; i < ${#dev[@]}; i+=1 )); do 146 log_must truncate -s $SPA_MINDEVSIZE "${dev[$i]}" 147done 148 149# Foreach test create pool, add -n devices and check output. 150for (( i=0; i < ${#tests[@]}; i+=1 )); do 151 typeset tree="${tests[$i].tree}" 152 typeset add="${tests[$i].add}" 153 typeset want="${tests[$i].want}" 154 155 log_must eval zpool create "$TESTPOOL" $tree 156 log_must poolexists "$TESTPOOL" 157 typeset out="$(log_must eval "zpool add -n '$TESTPOOL' $add" | \ 158 sed /^SUCCESS/d)" 159 160 if [[ "$out" != "$want" ]]; then 161 log_fail "Got:\n" "$out" "\nbut expected:\n" "$want" 162 fi 163 log_must destroy_pool "$TESTPOOL" 164done 165 166# Make sure hole vdevs are skipped in output. 167log_must eval "zpool create '$TESTPOOL' '${dev[0]}' log '${dev[1]}' \ 168 cache '${dev[2]}'" 169 170# Create a hole vdev. 171log_must eval "zpool remove '$TESTPOOL' '${dev[1]}'" 172log_mustnot eval "zpool add -n '$TESTPOOL' '${dev[1]}' | \ 173 grep -qE '[[:space:]]+hole'" 174 175log_pass "'zpool add -n <pool> <vdev> ...' displays config correctly." 176