Index: projects/zfsd/head/tests/sys/cddl/zfs/include/libsas.kshlib =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/include/libsas.kshlib (revision 329031) +++ projects/zfsd/head/tests/sys/cddl/zfs/include/libsas.kshlib (nonexistent) @@ -1,214 +0,0 @@ -# -# Copyright (c) 2010 Spectra Logic Corporation -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions, and the following disclaimer, -# without modification. -# 2. Redistributions in binary form must reproduce at minimum a disclaimer -# substantially similar to the "NO WARRANTY" disclaimer below -# ("Disclaimer") and any redistribution must be conditioned upon -# including a substantially similar Disclaimer requirement for further -# binary redistribution. -# -# NO WARRANTY -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING -# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGES. -# -# $FreeBSD$ -# - -# Get all PHYs for a given expander. -# Returns formatting suitable for iteration. -function get_all_phys -{ - typeset expander=$1 - camcontrol smpphylist $expander -q | awk '{print $1" "$NF}' | \ - tr -d '()' | tr ',' ' ' | tr '\n' ',' -} - -# -# Given a disk (e.g. /dev/da0 or da0), determine the following: -# - Does it exist in CAM? -# - Is it attached to an expander and can we find that expander? -# Returns two variables: -# EXPANDER -- The peripheral we need to talk to to communicate with the -# expander that is connected to the given disk. -# PHY -- The phy on the expander that we need to talk to. -# -function find_verify_sas_disk -{ - typeset DISK=${1##*/} - typeset i - - [ ! -c /dev/$DISK ] && log_fail "\"/dev/$DISK\" is not a char device" - - # Make sure this device exists. An inquiry should always succeed, - # even if there is a pending error. - log_must camcontrol inquiry $DISK > /dev/null - - # Pull the list of every peripheral in the system, except for - # peripherals that are attached to the disk we're looking for - - typeset PASSLIST=`camcontrol devlist |awk '{print $NF}' |\ - egrep -v ".*$DISK[^[:digit:]]" |tr -d '()' |awk -F, '{print $1}'` - - typeset FOUND=0 - - for i in $PASSLIST; do - # Make sure this particular device supports SMP. If not, - # no big deal, keep going. - camcontrol smprg $i > /dev/null 2>&1 - [ $? -ne 0 ] && continue - - # Make sure this particular device is an Enclosure Services - # device. That way, we won't wind up removing the device - # we're trying to operate on. - # XXX this will need to change once CAM is changed to - # include SMP targets in the topology. This merely takes - # advantage of the fact that most (all?) expanders include - # a SES device. - camcontrol inquiry $i |grep "Enclosure Services" > /dev/null - [ $? -ne 0 ] && continue - - # For every peripheral, we go through and pull out the - # list of devices and their phys that we can see via this - # peripheral. - IFS="," - for j in $(get_all_phys $i); do - IFS=", \n" - set -A PERIPHLIST $j - unset IFS - typeset NUMPERIPHS=${#PERIPHLIST[*]} - ((k=1)) - while [ $k -lt $NUMPERIPHS ]; do - if [ "${PERIPHLIST[$k]}" = "$DISK" ]; then -# echo "found $DISK PHY = ${PERIPHLIST[0]} on $i" - FOUND=1 - export EXPANDER=$i - export PHY=${PERIPHLIST[0]} - break; - fi - ((k=k+1)) - done - if [ $FOUND != 0 ]; then - break; - fi - done - unset IFS - - [ $FOUND -ne 0 ] && break - done - [ $FOUND -eq 0 ] && log_fail "Could not find PHY for disk $DISK" -} - -# -# Given an expander and phy number, find the disk device name. -# -function find_disk_by_phy -{ - typeset EXPANDER=$1 - typeset PHY=$2 - typeset FOUND=0 - - unset FOUNDDISK - - IFS="," - for j in $(get_all_phys $EXPANDER); do - IFS=", \n" - set -A PERIPHLIST $j - unset IFS - [ "${PERIPHLIST[0]}" != "$PHY" ] && continue - - typeset NUMPERIPHS=${#PERIPHLIST[*]} - - for ((k=1; $k < $NUMPERIPHS; k=$k + 1)); do - ((PSTOP=$NUMPERIPHS-1)) - if [ "${PERIPHLIST[$k]%%[0-9]*}" != "pass" ] || \ - [ "$k" -eq $PSTOP ]; then - export FOUNDDISK=${PERIPHLIST[$k]} - break; - fi - done - FOUND=1 - break; - done -} - -# Given an expander and phy on that expander, disable the phy. -# This function will exit (via log_fail) if it can't send the disable -# request. -function disable_sas_disk -{ - typeset EXPANDER=$1 - typeset PHY=$2 - typeset DISK=${3##*/} - - # Disable the phy for this particular device - log_must camcontrol smppc $EXPANDER -v -p $PHY -o disable - # Wait up to 16 seconds for the disk to disappear. - for (( i=0; i<8; i=i+1)); do - # CAM waits 2 seconds to ensure the disk is really gone - sleep 2 - if [ -c /dev/${DISK} ]; then - # Error recovery routines in the HBA sometimes reenable - # the phy if a command fails at the wrong time, so we - # may have to disable it multiple times. - log_must camcontrol smppc $EXPANDER -v -p $PHY -o disable - else - return - fi - done - log_fail "Disk $DISK never disappeared" -} - -# Given an expander and phy on that expander, enable the phy. -# This function will exit (via log_fail) if it can't send the link reset -# request. -function enable_sas_disk -{ - typeset EXPANDER=$1 - typeset PHY=$2 - - # Send a link reset to bring the device back - log_must camcontrol smppc $EXPANDER -p $PHY -o linkreset - wait_for_disk_to_reappear 30 $EXPANDER $PHY -} - -function rescan_disks -{ - if [[ -z "$1" ]]; then - log_must camcontrol rescan all >/dev/null - return - fi - - for device in $(echo $* | sort -u); do - log_must camcontrol rescan $device >/dev/null - done -} - -function wait_for_disk_to_reappear -{ - typeset -i timeout=$1 - typeset EXPANDER=$2 - typeset PHY=$3 - - for ((; $timeout > 0; timeout=$timeout-1)); do - find_disk_by_phy $EXPANDER $PHY - [ -n "$FOUNDDISK" -a -e "/dev/$FOUNDDISK" ] && return - $SLEEP 1 - done - log_fail "ERROR: Disk at ${EXPANDER}:${PHY} never reappeared" -} Index: projects/zfsd/head/tests/sys/cddl/zfs/include/Makefile =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/include/Makefile (revision 329031) +++ projects/zfsd/head/tests/sys/cddl/zfs/include/Makefile (revision 329032) @@ -1,33 +1,32 @@ # $FreeBSD$ .include PACKAGE= tests TESTSDIR=${TESTSBASE}/sys/cddl/zfs/include STFSUITEDIR=${TESTSBASE}/sys/cddl/zfs MAN= FILESDIR= ${TESTSBASE}/sys/cddl/zfs/include ${PACKAGE}FILES+= constants.cfg ${PACKAGE}FILES+= libremote.kshlib -${PACKAGE}FILES+= libsas.kshlib ${PACKAGE}FILES+= libgnop.kshlib ${PACKAGE}FILES+= logapi.kshlib ${PACKAGE}FILES+= libtest.kshlib ${PACKAGE}FILES+= stf.shlib ${PACKAGE}FILES+= testenv.kshlib ${PACKAGE}FILES+= commands.cfg CLEANFILES+= commands.cfg commands.cfg: translatecommands.awk commands.txt awk -v stfsuitedir=${STFSUITEDIR} -f ${.ALLSRC} > ${.TARGET} ${PACKAGE}FILES+= default.cfg CLEANFILES+= default.cfg default.cfg: default.cfg.in sed "s:%%STFSUITEDIR%%:${STFSUITEDIR}:" ${.ALLSRC} > ${.TARGET} ATF_TESTS_KSH93+= libtest_test .include Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib (revision 329031) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib (revision 329032) @@ -1,162 +1,82 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2013 Spectra Logic. All rights reserved. # Use is subject to license terms. # # Common routines used by multiple zfsd tests function wait_for_pool_dev_state_change { typeset -i timeout=$1 typeset disk=$2 typeset state=$3 log_note "Waiting up to $timeout seconds for $disk to become $state ..." for ((; $timeout > 0; timeout=$timeout-1)); do check_state $TESTPOOL "$disk" "$state" [ $? -eq 0 ] && return $SLEEP 1 done log_must $ZPOOL status $TESTPOOL log_fail "ERROR: Disk $disk not marked as $state in $TESTPOOL" } function wait_for_pool_removal { typeset -i timeout=$1 wait_for_pool_dev_state_change $timeout $REMOVAL_DISK "REMOVED|UNAVAIL" } function wait_until_scrubbed { typeset pool=$1 while is_pool_scrubbing $pool; do log_note "$pool still scrubbing..." $SLEEP 1 done } function corrupt_pool_vdev { typeset pool=$1 typeset vdev=$2 typeset file=$3 # do some IO on the pool log_must $DD if=/dev/zero of=$file bs=1024k count=128 $FSYNC $file # scribble on the underlying file to corrupt the vdev log_must $DD if=/dev/urandom of=$vdev bs=1024k count=64 conv=notrunc # Scrub the pool to detect the corruption log_must $ZPOOL scrub $pool wait_until_scrubbed $pool # ZFSD can take up to 60 seconds to degrade an array in response to # errors (though it's usually faster). wait_for_pool_dev_state_change 60 $vdev DEGRADED } - -# -# do_autoreplace -# Common code that walks through an autoreplace scenario -# Does not verify the final behavior -# -# $1 spare disk name. Empty if no spare -# -function do_autoreplace -{ - typeset SPARE_DISK=$1 - - # Remove a vdev by disabling its SAS phy - find_verify_sas_disk $REMOVAL_DISK - log_note "Disabling \"$REMOVAL_DISK\" on expander $EXPANDER phy $PHY" - disable_sas_disk $EXPANDER $PHY $REMOVAL_DISK - - # Check to make sure ZFS sees the disk as removed - wait_for_pool_removal 30 - - if [ -n "$SPARE_DISK" ]; then - # Verify that the spare activates - for ((timeout=0; $timeout<10; timeout=$timeout+1)); do - check_state $TESTPOOL $SPARE_DISK "ONLINE" && break - $SLEEP 6 - done - zpool status $TESTPOOL - log_must check_state $TESTPOOL "$SPARE_DISK" "ONLINE" - - wait_until_resilvered - fi - - # Export the pool - # This is to prevent REMOVAL_DISK from being added to the pool when - # we reenable its phy - log_must $ZPOOL export $TESTPOOL - - # Reenable the missing dev's SAS phy - log_note "Reenabling phy on expander $EXPANDER phy $PHY" - enable_sas_disk $EXPANDER $PHY - - # Erase the missing dev's ZFS label - log_must $ZPOOL labelclear -f $( find_disks $FOUNDDISK ) - - # Disable the missing dev's SAS phy again - find_verify_sas_disk $FOUNDDISK - log_note "Disabling \"$FOUNDDISK\" on expander $EXPANDER phy $PHY" - disable_sas_disk $EXPANDER $PHY $FOUNDDISK - - # Import the pool - log_must $ZPOOL import $TESTPOOL - # Wait 5 seconds before enabling the phy so zfsd.log will be easier - # to interpret - $SLEEP 5 - - # Reenable the missing dev's SAS phy - log_note "Reenabling phy on expander $EXPANDER phy $PHY" - enable_sas_disk $EXPANDER $PHY -} - -function autoreplace_cleanup -{ - destroy_pool $TESTPOOL - - # See if the phy has been disabled, and try to re-enable it if possible. - if [ -n "$REMOVAL_DISK" -a -n "$EXPANDER" -a -n "$PHY" ]; then - log_note "Renabling ${EXPANDER}:${PHY} for disk ${REMOVAL_DISK}" - enable_sas_disk $EXPANDER $PHY - - # For debugging purposes, log the partial output of - # camcontrol to see if the disk actually came back. - out=$(camcontrol smpphylist ${EXPANDER} | ${GREP} "^ *${PHY}") - log_note "Expander has: ${out}" - fi - - [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/* - - partition_cleanup - restart_zfsd -}