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