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) 2014, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/cli_root/zpool_add/zpool_add.kshlib 34 35# 36# DESCRIPTION: 37# 'zpool add -n <pool> <vdev> ...' can display the configuration without adding 38# the specified devices to given pool 39# 40# STRATEGY: 41# 1. Create a storage pool 42# 2. Use -n to add devices to the pool 43# 3. Verify the devices are not added actually 44# 4. Add devices to the pool for real this time, verify the vdev tree is the 45# same printed by the dryrun iteration 46# 47 48verify_runnable "global" 49 50function cleanup 51{ 52 destroy_pool $TESTPOOL 53 rm -f $TMPFILE_PREFIX* $VDEV_PREFIX* 54} 55 56log_assert "'zpool add -n <pool> <vdev> ...' can display the configuration" \ 57 "without actually adding devices to the pool." 58 59log_onexit cleanup 60 61typeset TMPFILE_PREFIX="$TEST_BASE_DIR/zpool_add_003" 62typeset STR_DRYRUN="would update '$TESTPOOL' to the following configuration:" 63typeset VDEV_PREFIX="$TEST_BASE_DIR/filedev" 64typeset -a VDEV_TYPES=("" "dedup" "special" "log" "cache" "spare") 65 66vdevs="" 67config="" 68 69# 1. Create a storage pool 70log_must truncate -s $SPA_MINDEVSIZE "$VDEV_PREFIX-root" 71log_must zpool create "$TESTPOOL" "$VDEV_PREFIX-root" 72log_must poolexists "$TESTPOOL" 73for vdevtype in "${VDEV_TYPES[@]}"; do 74 log_must truncate -s $SPA_MINDEVSIZE "$VDEV_PREFIX-$vdevtype" 75 vdevs="$vdevs $VDEV_PREFIX-$vdevtype" 76 config="$config $vdevtype $VDEV_PREFIX-$vdevtype" 77done 78 79# 2. Use -n to add devices to the pool 80log_must eval "zpool add -f -n $TESTPOOL $config > $TMPFILE_PREFIX-dryrun" 81log_must grep -q "$STR_DRYRUN" "$TMPFILE_PREFIX-dryrun" 82 83# 3. Verify the devices are not added actually 84for vdev in $vdevs; do 85 log_mustnot vdevs_in_pool "$TESTPOOL" "$vdev" 86done 87 88# 4. Add devices to the pool for real this time, verify the vdev tree is the 89# same printed by the dryrun iteration 90log_must zpool add -f $TESTPOOL $config 91zpool status $TESTPOOL | awk 'NR == 1, /NAME/ { next } /^$/ {exit} 92 {print $1}' > "$TMPFILE_PREFIX-vdevtree" 93awk 'NR == 1, /would/ {next} 94 /^$/ {next} {print $1}' "$TMPFILE_PREFIX-dryrun" > "$TMPFILE_PREFIX-vdevtree-n" 95log_must diff $TMPFILE_PREFIX-vdevtree-n $TMPFILE_PREFIX-vdevtree 96 97log_pass "'zpool add -n <pool> <vdev> ...' executes successfully." 98