Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/cddl/zfs/tests/hotspare/hotspare_add_003_neg.ksh
Show All 33 Lines | |||||
# | # | ||||
# __stc_assertion_start | # __stc_assertion_start | ||||
# | # | ||||
# ID: hotspare_add_003_neg | # ID: hotspare_add_003_neg | ||||
# | # | ||||
# DESCRIPTION: | # DESCRIPTION: | ||||
# 'zpool add' with hot spares will fail | # 'zpool add' with hot spares will fail | ||||
# while the hot spares belong to the following cases: | # while the hot spares belong to the following cases: | ||||
# - nonexist device, | # - nonexistent device, | ||||
# - part of an active pool, | # - part of an active pool, | ||||
# - currently mounted, | # - currently mounted, | ||||
# - devices in /etc/vfstab, | # - a swap device, | ||||
# - specified as the dedicated dump device, | # - a dump device, | ||||
# - identical with the basic or spares vdev within the pool, | # - identical with the basic or spares vdev within the pool, | ||||
# - belong to a exported or potentially active ZFS pool, | # - belong to a exported or potentially active ZFS pool, | ||||
# - a volume device that belong to the given pool, | # - a volume device that belong to the given pool, | ||||
# | # | ||||
# STRATEGY: | # STRATEGY: | ||||
# 1. Create case scenarios | # 1. Create case scenarios | ||||
# 2. For each scenario, try to add [-f] the device to the pool | # 2. For each scenario, try to add [-f] the device to the pool | ||||
# 3. Verify the add operation failes as expected. | # 3. Verify the add operation failes as expected. | ||||
Show All 12 Lines | |||||
function cleanup | function cleanup | ||||
{ | { | ||||
poolexists "$TESTPOOL" && \ | poolexists "$TESTPOOL" && \ | ||||
destroy_pool "$TESTPOOL" | destroy_pool "$TESTPOOL" | ||||
poolexists "$TESTPOOL1" && \ | poolexists "$TESTPOOL1" && \ | ||||
destroy_pool "$TESTPOOL1" | destroy_pool "$TESTPOOL1" | ||||
if [[ -n $saved_dump_dev ]]; then | log_onfail $UMOUNT $TMPDIR/mounted_dir | ||||
if [[ -n $DUMPADM ]]; then | log_onfail $SWAPOFF $swap_dev | ||||
log_must $DUMPADM -u -d $saved_dump_dev | log_onfail $DUMPON -r $dump_dev | ||||
fi | |||||
fi | |||||
if [[ -n $DUMPADM ]]; then | |||||
cleanup_devices $dump_dev | |||||
fi | |||||
partition_cleanup | partition_cleanup | ||||
} | } | ||||
log_assert "'zpool add [-f]' with hot spares should fail with inapplicable scenarios." | log_assert "'zpool add [-f]' with hot spares should fail with inapplicable scenarios." | ||||
log_onexit cleanup | log_onexit cleanup | ||||
set_devs | set_devs | ||||
mnttab_dev=$(find_mnttab_dev) | mounted_dev=${DISK0} | ||||
vfstab_dev=$(find_vfstab_dev) | swap_dev=${DISK1} | ||||
saved_dump_dev=$(save_dump_dev) | dump_dev=${DISK2} | ||||
dump_dev=${disk}s0 | nonexist_dev=${DISK2}bad_slice_num | ||||
nonexist_dev=${disk}sbad_slice_num | |||||
create_pool "$TESTPOOL" "${pooldevs[0]}" | create_pool "$TESTPOOL" "${pooldevs[0]}" | ||||
log_must poolexists "$TESTPOOL" | log_must poolexists "$TESTPOOL" | ||||
create_pool "$TESTPOOL1" "${pooldevs[1]}" | create_pool "$TESTPOOL1" "${pooldevs[1]}" | ||||
log_must poolexists "$TESTPOOL1" | log_must poolexists "$TESTPOOL1" | ||||
[[ -n $mnttab_dev ]] || log_note "No mnttab devices found" | log_must $MKDIR $TMPDIR/mounted_dir | ||||
[[ -n $vfstab_dev ]] || log_note "No vfstab devices found" | log_must $NEWFS $mounted_dev | ||||
# - nonexist device, | log_must $MOUNT $mounted_dev $TMPDIR/mounted_dir | ||||
log_must $SWAPON $swap_dev | |||||
log_must $DUMPON $dump_dev | |||||
# - nonexistent device, | |||||
# - part of an active pool, | # - part of an active pool, | ||||
# - currently mounted, | # - currently mounted, | ||||
# - devices in /etc/vfstab, | # - a swap device, | ||||
# - identical with the basic or spares vdev within the pool, | # - identical with the basic or spares vdev within the pool, | ||||
set -A arg "$nonexist_dev" \ | set -A arg "$nonexist_dev" \ | ||||
"${pooldevs[0]}" \ | "${pooldevs[0]}" \ | ||||
"${pooldevs[1]}" \ | "${pooldevs[1]}" \ | ||||
"$mnttab_dev" \ | "$mounted_dev" \ | ||||
"$vfstab_dev" | "$swap_dev" | ||||
typeset -i i=0 | typeset -i i=0 | ||||
while (( i < ${#arg[*]} )); do | while (( i < ${#arg[*]} )); do | ||||
if [[ -n "${arg[i]}" ]]; then | if [[ -n "${arg[i]}" ]]; then | ||||
log_mustnot $ZPOOL add $TESTPOOL spare ${arg[i]} | log_mustnot $ZPOOL add $TESTPOOL spare ${arg[i]} | ||||
log_mustnot $ZPOOL add -f $TESTPOOL spare ${arg[i]} | log_mustnot $ZPOOL add -f $TESTPOOL spare ${arg[i]} | ||||
fi | fi | ||||
(( i = i + 1 )) | (( i = i + 1 )) | ||||
done | done | ||||
# - specified as the dedicated dump device, | # - a dump device, | ||||
# This part of the test can only be run on platforms for which DUMPADM is | # https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=241070 | ||||
# defined; ie Solaris | # When that bug is fixed, add $dump_dev to $arg and remove this block. | ||||
if [[ -n $DUMPADM ]]; then | log_must $ZPOOL add $TESTPOOL spare ${dump_dev} | ||||
log_must $DUMPADM -u -d /dev/$dump_dev | log_must $ZPOOL remove $TESTPOOL ${dump_dev} | ||||
log_mustnot $ZPOOL add "$TESTPOOL" spare $dump_dev | log_must $ZPOOL add -f $TESTPOOL spare ${dump_dev} | ||||
log_mustnot $ZPOOL add -f "$TESTPOOL" spare $dump_dev | log_must $ZPOOL remove $TESTPOOL ${dump_dev} | ||||
fi | |||||
# - belong to a exported or potentially active ZFS pool, | # - belong to a exported or potentially active ZFS pool, | ||||
log_must $ZPOOL export $TESTPOOL1 | log_must $ZPOOL export $TESTPOOL1 | ||||
log_mustnot $ZPOOL add "$TESTPOOL" spare ${pooldevs[1]} | log_mustnot $ZPOOL add "$TESTPOOL" spare ${pooldevs[1]} | ||||
log_must $ZPOOL import -d $HOTSPARE_TMPDIR $TESTPOOL1 | log_must $ZPOOL import -d $HOTSPARE_TMPDIR $TESTPOOL1 | ||||
log_pass "'zpool add [-f]' with hot spares should fail with inapplicable scenarios." | log_pass "'zpool add [-f]' with hot spares should fail with inapplicable scenarios." |