Skip to content

Commit

Permalink
Add auto-online test for ZED/FMA as part of the ZTS
Browse files Browse the repository at this point in the history
Automated auto-online test to go along with ZED FMA integration (PR 4673)
auto_online_001.pos works with real devices (sd- and mpath) and with non-real
block devices (loop) by adding a scsi_debug device to the pool

Note: In order for test group to run, ZED must not currently be running.
Kernel 3.16.37 or higher needed for scsi_debug to work properly
If timeout occurs on test using a scsi_debug device (error noticed on Ubuntu
system), a reboot might be needed in order for test to pass. (more
investigation into this)

Also suppressed output from is_real_device/is_loop_device/is_mpath_device -
was making the log file very cluttered with useless error messages
"ie /dev/mapper/sdc is not a block device" from previous patch

Reviewed-by: Don Brady <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: David Quigley <[email protected]>
Signed-off-by: Sydney Vanda <[email protected]>
Closes #5774
  • Loading branch information
sydneyvanda authored and behlendorf committed Mar 1, 2017
1 parent 4859fe7 commit ec0e24c
Show file tree
Hide file tree
Showing 13 changed files with 524 additions and 21 deletions.
3 changes: 3 additions & 0 deletions config/user-commands.m4
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ AC_DEFUN([ZFS_AC_CONFIG_USER_COMMANDS_LINUX], [
AC_PATH_TOOL(IOSTAT, iostat, "")
AC_PATH_TOOL(LOCKFS, lsof, "")
AC_PATH_TOOL(LSBLK, lsblk, "")
AC_PATH_TOOL(LSMOD, lsmod, "")
AC_PATH_TOOL(LSSCSI, lsscsi, "")
AC_PATH_TOOL(MODLOAD, modprobe, "")
AC_PATH_TOOL(MODUNLOAD, rmmod, "")
AC_PATH_TOOL(MPSTAT, mpstat, "")
AC_PATH_TOOL(NEWFS, mke2fs, "")
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ AC_CONFIG_FILES([
tests/zfs-tests/tests/functional/delegate/Makefile
tests/zfs-tests/tests/functional/devices/Makefile
tests/zfs-tests/tests/functional/exec/Makefile
tests/zfs-tests/tests/functional/fault/Makefile
tests/zfs-tests/tests/functional/features/async_destroy/Makefile
tests/zfs-tests/tests/functional/features/large_dnode/Makefile
tests/zfs-tests/tests/functional/features/Makefile
Expand Down
3 changes: 3 additions & 0 deletions tests/runfiles/linux.run
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ tests = ['devices_003_pos']
[tests/functional/exec]
tests = ['exec_001_pos']

[tests/functional/fault]
tests = ['auto_online_001_pos']

[tests/functional/features/async_destroy]
tests = ['async_destroy_001_pos']

Expand Down
3 changes: 3 additions & 0 deletions tests/zfs-tests/include/commands.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ export LOFIADM="@LOFIADM@"
export LOGNAME="@LOGNAME@"
export LS="@LS@"
export LSBLK="@LSBLK@"
export LSMOD="@LSMOD@"
export LSSCSI="@LSSCSI@"
export MD5SUM="@MD5SUM@"
export MKDIR="@MKDIR@"
export MKNOD="@MKNOD@"
export MKTEMP="@MKTEMP@"
export MNTTAB="@MNTTAB@"
export MODINFO="@MODINFO@"
export MODLOAD="@MODLOAD@"
export MODUNLOAD="@MODUNLOAD@"
export MOUNT="@MOUNT@"
export MPSTAT="@MPSTAT@"
Expand Down
5 changes: 5 additions & 0 deletions tests/zfs-tests/include/default.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
# Common paths
bindir=@bindir@
sbindir=@sbindir@
etcdir=@sysconfdir@

# ZFS Directories
export ZEDLETDIR=${ZEDLETDIR:-${etcdir}/zfs/zed.d}

# ZFS Commands
export ZDB=${ZDB:-${sbindir}/zdb}
Expand All @@ -47,6 +51,7 @@ export RAIDZ_TEST=${RAIDZ_TEST:-${bindir}/raidz_test}
export ARC_SUMMARY=${ARC_SUMMARY:-${bindir}/arc_summary.py}
export ARCSTAT=${ARCSTAT:-${bindir}/arcstat.py}
export DBUFSTAT=${DBUFSTAT:-${bindir}/dbufstat.py}
export ZED=${ZED:-${sbindir}/zed}

. $STF_SUITE/include/libtest.shlib

Expand Down
186 changes: 165 additions & 21 deletions tests/zfs-tests/include/libtest.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -1645,22 +1645,144 @@ function reexport_pool
}

#
# Verify a given disk is online or offline
# Verify a given disk or pool state
#
# Return 0 is pool/disk matches expected state, 1 otherwise
#
function check_state # pool disk state{online,offline}
function check_state # pool disk state{online,offline,degraded}
{
typeset pool=$1
typeset disk=${2#$DEV_DSKDIR/}
typeset state=$3

$ZPOOL status -v $pool | grep "$disk" \
| grep -i "$state" > /dev/null 2>&1
[[ -z $pool ]] || [[ -z $state ]] \
&& log_fail "Arguments invalid or missing"

if [[ -z $disk ]]; then
#check pool state only
$ZPOOL get -H -o value health $pool \
| grep -i "$state" > /dev/null 2>&1
else
$ZPOOL status -v $pool | grep "$disk" \
| grep -i "$state" > /dev/null 2>&1
fi

return $?
}

#
# Cause a scan of all scsi host adapters by default
#
# $1 optional host number
#
function scan_scsi_hosts
{
typeset hostnum=${1}

if [[ -z $hostnum ]]; then
for host in /sys/class/scsi_host/host*; do
echo '- - -' > $host/scan
done
else
echo "/sys/class/scsi_host/host$hostnum/scan"
echo '- - -' > "/sys/class/scsi_host/host$hostnum/scan"
fi
}
#
# Wait for newly created block devices to have their minors created.
#
function block_device_wait
{
if is_linux; then
$UDEVADM trigger
$UDEVADM settle
fi
}

#
# Online or offline a disk on the system
#
# First checks state of disk. Test will fail if disk is not properly onlined
# or offlined. Online is a full rescan of SCSI disks by echoing to every
# host entry.
#
function on_off_disk # disk state{online,offline} host
{
typeset disk=$1
typeset state=$2
typeset host=$3

[[ -z $disk ]] || [[ -z $state ]] && \
log_fail "Arguments invalid or missing"

if is_linux; then
if [[ $state == "offline" ]] && ( is_mpath_device $disk ); then
dm_name="$($READLINK $DEV_DSKDIR/$disk \
| $NAWK -F / '{print $2}')"
slave="$($LS /sys/block/${dm_name}/slaves \
| $NAWK '{print $1}')"
while [[ -n $slave ]]; do
#check if disk is online
$LSSCSI | $EGREP $slave > /dev/null
if (($? == 0)); then
slave_dir="/sys/block/${dm_name}"
slave_dir+="/slaves/${slave}/device"
ss="${slave_dir}/state"
sd="${slave_dir}/delete"
log_must eval "$ECHO 'offline' > ${ss}"
log_must eval "$ECHO '1' > ${sd}"
$LSSCSI | $EGREP $slave > /dev/null
if (($? == 0)); then
log_fail "Offlining" \
"$disk failed"
fi
fi
slave="$($LS /sys/block/$dm_name/slaves \
2>/dev/null | $NAWK '{print $1}')"
done
elif [[ $state == "offline" ]] && ( is_real_device $disk ); then
#check if disk is online
$LSSCSI | $EGREP $disk > /dev/null
if (($? == 0)); then
dev_state="/sys/block/$disk/device/state"
dev_delete="/sys/block/$disk/device/delete"
log_must eval "$ECHO 'offline' > ${dev_state}"
log_must eval "$ECHO '1' > ${dev_delete}"
$LSSCSI | $EGREP $disk > /dev/null
if (($? == 0)); then
log_fail "Offlining $disk" \
"failed"
fi
else
log_note "$disk is already offline"
fi
elif [[ $state == "online" ]]; then
#force a full rescan
log_must scan_scsi_hosts $host
block_device_wait
if is_mpath_device $disk; then
dm_name="$($READLINK $DEV_DSKDIR/$disk \
| $NAWK -F / '{print $2}')"
slave="$($LS /sys/block/$dm_name/slaves \
| $NAWK '{print $1}')"
$LSSCSI | $EGREP $slave > /dev/null
if (($? != 0)); then
log_fail "Onlining $disk failed"
fi
elif is_real_device $disk; then
$LSSCSI | $EGREP $disk > /dev/null
if (($? != 0)); then
log_fail "Onlining $disk failed"
fi
else
log_fail "$disk is not a real dev"
fi
else
log_fail "$disk failed to $state"
fi
fi
}

#
# Get the mountpoint of snapshot
# For the snapshot use <mp_filesystem>/.zfs/snapshot/<snap>
Expand Down Expand Up @@ -2754,7 +2876,8 @@ function is_real_device #disk
[[ -z $disk ]] && log_fail "No argument for disk given."

if is_linux; then
$LSBLK $DEV_RDSKDIR/$disk -o TYPE | $EGREP disk > /dev/null 2>&1
($LSBLK $DEV_RDSKDIR/$disk -o TYPE | $EGREP disk > /dev/null) \
2>/dev/null
return $?
fi
}
Expand All @@ -2768,7 +2891,8 @@ function is_loop_device #disk
[[ -z $disk ]] && log_fail "No argument for disk given."

if is_linux; then
$LSBLK $DEV_RDSKDIR/$disk -o TYPE | $EGREP loop > /dev/null 2>&1
($LSBLK $DEV_RDSKDIR/$disk -o TYPE | $EGREP loop > /dev/null) \
2>/dev/null
return $?
fi
}
Expand All @@ -2784,7 +2908,8 @@ function is_mpath_device #disk
[[ -z $disk ]] && log_fail "No argument for disk given."

if is_linux; then
$LSBLK $DEV_MPATHDIR/$disk -o TYPE | $EGREP mpath > /dev/null 2>&1
($LSBLK $DEV_MPATHDIR/$disk -o TYPE | $EGREP mpath >/dev/null) \
2>/dev/null
if (($? == 0)); then
$READLINK $DEV_MPATHDIR/$disk > /dev/null 2>&1
return $?
Expand All @@ -2807,11 +2932,13 @@ function set_slice_prefix
if is_linux; then
while (( i < $DISK_ARRAY_NUM )); do
disk="$($ECHO $DISKS | $NAWK '{print $(i + 1)}')"
if ( is_mpath_device $disk ) && [[ -z $($ECHO $disk | awk 'substr($1,18,1)\
~ /^[[:digit:]]+$/') ]] || ( is_real_device $disk ); then
if ( is_mpath_device $disk ) && [[ -z $($ECHO $disk \
| awk 'substr($1,18,1) ~ /^[[:digit:]]+$/') ]] || \
( is_real_device $disk ); then
export SLICE_PREFIX=""
return 0
elif ( is_mpath_device $disk || is_loop_device $disk ); then
elif ( is_mpath_device $disk || is_loop_device \
$disk ); then
export SLICE_PREFIX="p"
return 0
else
Expand Down Expand Up @@ -2872,6 +2999,34 @@ function get_device_dir #device
fi
}

#
# Get persistent name for given disk
#
function get_persistent_disk_name #device
{
typeset device=$1
typeset dev_id

if is_linux; then
if is_real_device $device; then
dev_id="$($UDEVADM info -q all -n $DEV_DSKDIR/$device \
| $EGREP disk/by-id | $NAWK '{print $2; exit}' \
| $NAWK -F / '{print $3}')"
$ECHO $dev_id
elif is_mpath_device $device; then
dev_id="$($UDEVADM info -q all -n $DEV_DSKDIR/$device \
| $EGREP disk/by-id/dm-uuid \
| $NAWK '{print $2; exit}' \
| $NAWK -F / '{print $3}')"
$ECHO $dev_id
else
$ECHO $device
fi
else
$ECHO $device
fi
}

#
# Get the package name
#
Expand Down Expand Up @@ -3028,17 +3183,6 @@ function get_min
echo $min
}

#
# Wait for newly created block devices to have their minors created.
#
function block_device_wait
{
if is_linux; then
$UDEVADM trigger
$UDEVADM settle
fi
}

#
# Synchronize all the data in pool
#
Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/tests/functional/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SUBDIRS = \
delegate \
devices \
exec \
fault \
features \
grow_pool \
grow_replicas \
Expand Down
6 changes: 6 additions & 0 deletions tests/zfs-tests/tests/functional/fault/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/fault
dist_pkgdata_SCRIPTS = \
fault.cfg \
setup.ksh \
cleanup.ksh \
auto_online_001_pos.ksh
Loading

0 comments on commit ec0e24c

Please sign in to comment.