1#!/usr/local/bin/ksh93 -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. $STF_SUITE/tests/hotspare/hotspare.kshlib 27 28################################################################################ 29# 30# __stc_assertion_start 31# 32# ID: hotspare_add_003_neg 33# 34# DESCRIPTION: 35# 'zpool add' with hot spares will fail 36# while the hot spares belong to the following cases: 37# - nonexistent device, 38# - part of an active pool, 39# - currently mounted, 40# - a swap device, 41# - a dump device, 42# - identical with the basic or spares vdev within the pool, 43# - belong to a exported or potentially active ZFS pool, 44# - a volume device that belong to the given pool, 45# 46# STRATEGY: 47# 1. Create case scenarios 48# 2. For each scenario, try to add [-f] the device to the pool 49# 3. Verify the add operation failes as expected. 50# 51# TESTABILITY: explicit 52# 53# TEST_AUTOMATION_LEVEL: automated 54# 55# CODING_STATUS: COMPLETED (2006-06-07) 56# 57# __stc_assertion_end 58# 59############################################################################### 60 61verify_runnable "global" 62 63function cleanup 64{ 65 poolexists "$TESTPOOL" && \ 66 destroy_pool "$TESTPOOL" 67 poolexists "$TESTPOOL1" && \ 68 destroy_pool "$TESTPOOL1" 69 70 log_onfail $UMOUNT $TMPDIR/mounted_dir 71 log_onfail $SWAPOFF $swap_dev 72 log_onfail $DUMPON -r $dump_dev 73 74 partition_cleanup 75} 76 77log_assert "'zpool add [-f]' with hot spares should fail with inapplicable scenarios." 78 79log_onexit cleanup 80 81set_devs 82 83mounted_dev=${DISK0} 84swap_dev=${DISK1} 85dump_dev=${DISK2} 86nonexist_dev=${DISK2}bad_slice_num 87 88create_pool "$TESTPOOL" "${pooldevs[0]}" 89log_must poolexists "$TESTPOOL" 90 91create_pool "$TESTPOOL1" "${pooldevs[1]}" 92log_must poolexists "$TESTPOOL1" 93 94log_must $MKDIR $TMPDIR/mounted_dir 95log_must $NEWFS $mounted_dev 96log_must $MOUNT $mounted_dev $TMPDIR/mounted_dir 97 98log_must $SWAPON $swap_dev 99 100log_must $DUMPON $dump_dev 101 102# - nonexistent device, 103# - part of an active pool, 104# - currently mounted, 105# - a swap device, 106# - identical with the basic or spares vdev within the pool, 107 108set -A arg "$nonexist_dev" \ 109 "${pooldevs[0]}" \ 110 "${pooldevs[1]}" \ 111 "$mounted_dev" \ 112 "$swap_dev" 113 114typeset -i i=0 115while (( i < ${#arg[*]} )); do 116 if [[ -n "${arg[i]}" ]]; then 117 log_mustnot $ZPOOL add $TESTPOOL spare ${arg[i]} 118 log_mustnot $ZPOOL add -f $TESTPOOL spare ${arg[i]} 119 fi 120 (( i = i + 1 )) 121done 122 123# - a dump device, 124# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=241070 125# When that bug is fixed, add $dump_dev to $arg and remove this block. 126log_must $ZPOOL add $TESTPOOL spare ${dump_dev} 127log_must $ZPOOL remove $TESTPOOL ${dump_dev} 128log_must $ZPOOL add -f $TESTPOOL spare ${dump_dev} 129log_must $ZPOOL remove $TESTPOOL ${dump_dev} 130 131# - belong to a exported or potentially active ZFS pool, 132 133log_must $ZPOOL export $TESTPOOL1 134log_mustnot $ZPOOL add "$TESTPOOL" spare ${pooldevs[1]} 135log_must $ZPOOL import -d $HOTSPARE_TMPDIR $TESTPOOL1 136 137log_pass "'zpool add [-f]' with hot spares should fail with inapplicable scenarios." 138