ZTS: add zed_fd_spill to verify the fds ZEDLETs inherit
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #11891
This commit is contained in:
parent
55cf5a255a
commit
15d3470c2e
|
@ -90,7 +90,7 @@ tests = ['devices_001_pos', 'devices_002_neg', 'devices_003_pos']
|
||||||
tags = ['functional', 'devices']
|
tags = ['functional', 'devices']
|
||||||
|
|
||||||
[tests/functional/events:Linux]
|
[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']
|
tags = ['functional', 'events']
|
||||||
|
|
||||||
[tests/functional/fallocate:Linux]
|
[tests/functional/fallocate:Linux]
|
||||||
|
|
|
@ -3577,16 +3577,11 @@ function wait_replacing #pool
|
||||||
# Wait for a pool to be scrubbed
|
# Wait for a pool to be scrubbed
|
||||||
#
|
#
|
||||||
# $1 pool name
|
# $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
|
function wait_scrubbed
|
||||||
{
|
{
|
||||||
typeset pool=${1:-$TESTPOOL}
|
typeset pool=${1:-$TESTPOOL}
|
||||||
while true ; do
|
while ! is_pool_scrubbed $pool ; do
|
||||||
is_pool_scrubbed $pool && break
|
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
/zed_fd_spill-zedlet
|
|
@ -1,11 +1,18 @@
|
||||||
|
include $(top_srcdir)/config/Rules.am
|
||||||
|
|
||||||
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/events
|
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/events
|
||||||
dist_pkgdata_SCRIPTS = \
|
dist_pkgdata_SCRIPTS = \
|
||||||
setup.ksh \
|
setup.ksh \
|
||||||
cleanup.ksh \
|
cleanup.ksh \
|
||||||
events_001_pos.ksh \
|
events_001_pos.ksh \
|
||||||
events_002_pos.ksh \
|
events_002_pos.ksh \
|
||||||
zed_rc_filter.ksh
|
zed_rc_filter.ksh \
|
||||||
|
zed_fd_spill.ksh
|
||||||
|
|
||||||
dist_pkgdata_DATA = \
|
dist_pkgdata_DATA = \
|
||||||
events.cfg \
|
events.cfg \
|
||||||
events_common.kshlib
|
events_common.kshlib
|
||||||
|
|
||||||
|
pkgexecdir = $(pkgdatadir)
|
||||||
|
pkgexec_PROGRAMS = zed_fd_spill-zedlet
|
||||||
|
zed_fd_spill_zedlet_SOURCES = zed_fd_spill-zedlet.c
|
||||||
|
|
|
@ -26,6 +26,6 @@
|
||||||
|
|
||||||
. $STF_SUITE/include/libtest.shlib
|
. $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
|
default_cleanup
|
||||||
|
|
|
@ -50,11 +50,11 @@ function cleanup
|
||||||
[[ -f $file ]] && rm -f $file
|
[[ -f $file ]] && rm -f $file
|
||||||
done
|
done
|
||||||
|
|
||||||
log_must rm -f $TMP_EVENTS_ZED $TMP_EVENTS_ZED
|
log_must rm -f $TMP_EVENTS_ZED
|
||||||
log_must zed_stop
|
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_onexit cleanup
|
||||||
|
|
||||||
log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2
|
log_must truncate -s $MINVDEVSIZE $VDEV1 $VDEV2
|
||||||
|
|
|
@ -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 <sys/types.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
|
@ -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"
|
Loading…
Reference in New Issue