diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run index 4952f30132..c6d4f5f6d3 100644 --- a/tests/runfiles/linux.run +++ b/tests/runfiles/linux.run @@ -90,7 +90,7 @@ tests = ['devices_001_pos', 'devices_002_neg', 'devices_003_pos'] tags = ['functional', 'devices'] [tests/functional/events:Linux] -tests = ['events_001_pos', 'events_002_pos', 'zed_rc_filter'] +tests = ['events_001_pos', 'events_002_pos', 'zed_rc_filter', 'zed_fd_spill'] tags = ['functional', 'events'] [tests/functional/fallocate:Linux] diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index c3b1adc93a..08c29c25fa 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -3577,16 +3577,11 @@ function wait_replacing #pool # Wait for a pool to be scrubbed # # $1 pool name -# $2 number of seconds to wait (optional) -# -# Returns true when pool has been scrubbed, or false if there's a timeout or if -# no scrub was done. # function wait_scrubbed { typeset pool=${1:-$TESTPOOL} - while true ; do - is_pool_scrubbed $pool && break + while ! is_pool_scrubbed $pool ; do sleep 1 done } diff --git a/tests/zfs-tests/tests/functional/events/.gitignore b/tests/zfs-tests/tests/functional/events/.gitignore new file mode 100644 index 0000000000..ed5af03a10 --- /dev/null +++ b/tests/zfs-tests/tests/functional/events/.gitignore @@ -0,0 +1 @@ +/zed_fd_spill-zedlet diff --git a/tests/zfs-tests/tests/functional/events/Makefile.am b/tests/zfs-tests/tests/functional/events/Makefile.am index e1fe490812..92ce5dbc38 100644 --- a/tests/zfs-tests/tests/functional/events/Makefile.am +++ b/tests/zfs-tests/tests/functional/events/Makefile.am @@ -1,11 +1,18 @@ +include $(top_srcdir)/config/Rules.am + pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/events dist_pkgdata_SCRIPTS = \ setup.ksh \ cleanup.ksh \ events_001_pos.ksh \ events_002_pos.ksh \ - zed_rc_filter.ksh + zed_rc_filter.ksh \ + zed_fd_spill.ksh dist_pkgdata_DATA = \ events.cfg \ events_common.kshlib + +pkgexecdir = $(pkgdatadir) +pkgexec_PROGRAMS = zed_fd_spill-zedlet +zed_fd_spill_zedlet_SOURCES = zed_fd_spill-zedlet.c diff --git a/tests/zfs-tests/tests/functional/events/cleanup.ksh b/tests/zfs-tests/tests/functional/events/cleanup.ksh index 4905342b71..699bc28233 100755 --- a/tests/zfs-tests/tests/functional/events/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/events/cleanup.ksh @@ -26,6 +26,6 @@ . $STF_SUITE/include/libtest.shlib -zed_cleanup all-debug.sh all-syslog.sh +zed_cleanup all-debug.sh all-syslog.sh all-dumpfds default_cleanup diff --git a/tests/zfs-tests/tests/functional/events/events_002_pos.ksh b/tests/zfs-tests/tests/functional/events/events_002_pos.ksh index 586eaa9e1f..af2be33dbc 100755 --- a/tests/zfs-tests/tests/functional/events/events_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/events/events_002_pos.ksh @@ -50,11 +50,11 @@ function cleanup [[ -f $file ]] && rm -f $file done - log_must rm -f $TMP_EVENTS_ZED $TMP_EVENTS_ZED + log_must rm -f $TMP_EVENTS_ZED log_must zed_stop } -log_assert "Verify ZED handles missed events on when starting" +log_assert "Verify ZED handles missed events when starting" log_onexit cleanup log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2 diff --git a/tests/zfs-tests/tests/functional/events/zed_fd_spill-zedlet.c b/tests/zfs-tests/tests/functional/events/zed_fd_spill-zedlet.c new file mode 100644 index 0000000000..c072f906d2 --- /dev/null +++ b/tests/zfs-tests/tests/functional/events/zed_fd_spill-zedlet.c @@ -0,0 +1,36 @@ +/* + * Permission to use, copy, modify, and/or distribute this software for + * any purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include + +int main(void) { + if (fork()) { + int err; + wait(&err); + return (err); + } + + char buf[64]; + sprintf(buf, "/tmp/zts-zed_fd_spill-logdir/%d", getppid()); + dup2(creat(buf, 0644), STDOUT_FILENO); + + snprintf(buf, sizeof (buf), "/proc/%d/fd", getppid()); + execlp("ls", "ls", buf, NULL); + _exit(127); +} diff --git a/tests/zfs-tests/tests/functional/events/zed_fd_spill.ksh b/tests/zfs-tests/tests/functional/events/zed_fd_spill.ksh new file mode 100755 index 0000000000..8736a7fdf7 --- /dev/null +++ b/tests/zfs-tests/tests/functional/events/zed_fd_spill.ksh @@ -0,0 +1,77 @@ +#!/bin/ksh -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 +# + +# DESCRIPTION: +# Verify ZEDLETs only inherit the fds specified in the manpage +# +# STRATEGY: +# 1. Inject a ZEDLET that dumps the fds it gets to a file. +# 2. Generate some events. +# 3. Read back the generated files and assert that there is no fd past 3, +# and there are exactly 4 fds. + +. $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/events/events_common.kshlib + +verify_runnable "both" + +function cleanup +{ + log_must rm -rf "$logdir" + log_must rm "/tmp/zts-zed_fd_spill-logdir" + log_must zed_stop +} + +log_assert "Verify ZEDLETs inherit only the fds specified" +log_onexit cleanup + +logdir="$(mktemp -d)" +log_must ln -s "$logdir" /tmp/zts-zed_fd_spill-logdir + +self="$(readlink -f "$0")" +log_must ln -s "${self%/*}/zed_fd_spill-zedlet" "${ZEDLET_DIR}/all-dumpfds" + +log_must zpool events -c +log_must zed_stop +log_must zed_start + +log_must truncate -s 0 $ZED_DEBUG_LOG +log_must zpool scrub $TESTPOOL +log_must zfs set compression=off $TESTPOOL/$TESTFS +log_must wait_scrubbed $TESTPOOL +log_must file_wait $ZED_DEBUG_LOG 3 + +if [ -n "$(find "$logdir" -maxdepth 0 -empty)" ]; then + log_fail "Our ZEDLET didn't run!" +fi +log_must awk ' + !/^[0123]$/ { + print FILENAME ": " $0 + err=1 + } + END { + exit err + } +' "$logdir"/* +wc -l "$logdir"/* | log_must awk '$1 != "4" && $2 != "total" {print; exit 1}' + +log_pass "ZED doesn't leak fds to ZEDLETs"