From 598fed7ecdade29e569067ba49d5556a78f1adc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Wed, 16 Mar 2022 14:27:04 +0100 Subject: [PATCH] tests: revert back to original coredump patterns on Linux, too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise, they leak past the tests and contaminate the running system, breaking coredumps entirely Reviewed-by: Brian Behlendorf Reviewed-by: John Kennedy Reviewed-by: Ryan Moeller Co-authored-by: Yannick Le Pennec Signed-off-by: Ahelenia Ziemiańska Closes #13259 --- scripts/zloop.sh | 2 +- tests/zfs-tests/include/libtest.shlib | 44 ++++++++++++++++++ .../functional/cli_root/zfs/zfs_002_pos.ksh | 46 +++++-------------- .../cli_root/zpool/zpool_002_pos.ksh | 39 ++++------------ .../cli_root/zpool/zpool_003_pos.ksh | 39 +++++----------- 5 files changed, 79 insertions(+), 91 deletions(-) diff --git a/scripts/zloop.sh b/scripts/zloop.sh index dd89ff6fdf..8d5c0271f1 100755 --- a/scripts/zloop.sh +++ b/scripts/zloop.sh @@ -79,7 +79,7 @@ FreeBSD) ;; Linux) # core file helpers - origcorepattern="$(cat /proc/sys/kernel/core_pattern)" + read -r origcorepattern /proc/sys/kernel/core_pattern && + echo 0 >/proc/sys/kernel/core_uses_pid + ;; + FreeBSD) + sysctl -n kern.corefile + sysctl kern.corefile="$1/core.%N" >/dev/null + ;; + *) + # Nothing to output – set only for this shell + coreadm -p "$1/core.%f" + ;; + esac +} + +# +# Put coredumps back into the default location +# +function pop_coredump_pattern +{ + [ -s "$1" ] || return 0 + case $(uname) in + Linux) + typeset pat pid + { read -r pat; read -r pid; } < "$1" + echo "$pat" >/proc/sys/kernel/core_pattern && + echo "$pid" >/proc/sys/kernel/core_uses_pid + ;; + FreeBSD) + sysctl kern.corefile="$(<"$1")" >/dev/null + ;; + esac +} diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh index 796b38928e..044ccb185c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh @@ -48,33 +48,23 @@ function cleanup { unset ZFS_ABORT - if is_freebsd && [[ -n $savedcorefile ]]; then - sysctl kern.corefile=$savedcorefile - fi + log_must pop_coredump_pattern "$coresavepath" - if [[ -d $corepath ]]; then - rm -rf $corepath - fi for ds in $fs1 $fs $ctr; do datasetexists $ds && destroy_dataset $ds -rRf done } -log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a " \ - "core file." +log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a core file." log_onexit cleanup -# Preparation work for testing -savedcorefile="" -corepath=$TESTDIR/core -corefile=$corepath/core.zfs -if [[ -d $corepath ]]; then - rm -rf $corepath -fi -log_must mkdir $corepath - ctr=$TESTPOOL/$TESTCTR -log_must zfs create $ctr +log_must zfs create -p $ctr + +# Preparation work for testing +corepath=/$ctr +corefile=$corepath/core.zfs +coresavepath=$corepath/save fs=$ctr/$TESTFS fs1=$ctr/$TESTFS1 @@ -93,24 +83,12 @@ typeset badparams=("" "create" "destroy" "snapshot" "rollback" "clone" \ "promote" "rename" "list -*" "set" "get -*" "inherit" "mount -A" \ "unmount" "share" "unshare" "send" "receive") -if is_linux; then - ulimit -c unlimited - echo "$corefile" >/proc/sys/kernel/core_pattern - echo 0 >/proc/sys/kernel/core_uses_pid -elif is_freebsd; then - ulimit -c unlimited - savedcorefile=$(sysctl -n kern.corefile) - log_must sysctl kern.corefile=$corepath/core.%N -else - log_must coreadm -p ${corepath}/core.%f -fi - +log_must eval "push_coredump_pattern \"$corepath\" > \"$coresavepath\"" log_must export ZFS_ABORT=yes for subcmd in "${cmds[@]}" "${badparams[@]}"; do - log_mustnot eval "zfs $subcmd >/dev/null 2>&1" - log_must rm $corefile + log_mustnot eval "zfs $subcmd" + log_must rm "$corefile" done -log_pass "With ZFS_ABORT set, zfs command can abort and generate core file " \ - "as expected." +log_pass "With ZFS_ABORT set, zfs command can abort and generate core file as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh index e4ffa2a6c0..ef88925dc9 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh @@ -47,33 +47,27 @@ function cleanup { unset ZFS_ABORT - if is_freebsd && [ -n "$old_corefile" ]; then - sysctl kern.corefile=$old_corefile - fi + log_must pop_coredump_pattern "$coresavepath" + log_must rm -rf $corepath $vdev1 $vdev2 $vdev3 # Clean up the pool created if we failed to abort. poolexists $pool && destroy_pool $pool - - rm -rf $corepath $vdev1 $vdev2 $vdev3 } log_assert "With ZFS_ABORT set, all zpool commands can abort and generate a core file." log_onexit cleanup corepath=$TESTDIR/core -corefile=$corepath/zpool.core -if [[ -d $corepath ]]; then - log_must rm -rf $corepath -fi +corefile=$corepath/core.zpool +coresavepath=$corepath/save +log_must rm -rf $corepath log_must mkdir $corepath pool=pool.$$ vdev1=$TESTDIR/file1 vdev2=$TESTDIR/file2 vdev3=$TESTDIR/file3 -for vdev in $vdev1 $vdev2 $vdev3; do - log_must mkfile $MINVDEVSIZE $vdev -done +log_must mkfile $MINVDEVSIZE $vdev1 $vdev2 $vdev3 set -A cmds "create $pool mirror $vdev1 $vdev2" "list $pool" "iostat $pool" \ "status $pool" "upgrade $pool" "get delegation $pool" "set delegation=off $pool" \ @@ -86,25 +80,12 @@ set -A badparams "" "create" "destroy" "add" "remove" "list *" "iostat" "status" "online" "offline" "clear" "attach" "detach" "replace" "scrub" \ "import" "export" "upgrade" "history -?" "get" "set" -if is_linux; then - echo $corefile >/proc/sys/kernel/core_pattern - echo 0 >/proc/sys/kernel/core_uses_pid -elif is_freebsd; then - old_corefile=$(sysctl -n kern.corefile) - log_must sysctl kern.corefile=$corefile -fi -ulimit -c unlimited - -export ZFS_ABORT=yes +log_must eval "push_coredump_pattern \"$corepath\" > \"$coresavepath\"" +log_must export ZFS_ABORT=yes for subcmd in "${cmds[@]}" "${badparams[@]}"; do - zpool $subcmd >/dev/null 2>&1 - if [[ ! -e $corefile ]]; then - log_fail "zpool $subcmd cannot generate core file with ZFS_ABORT set." - fi - rm -f $corefile + log_mustnot eval "zpool $subcmd" + log_must rm "$corefile" done -unset ZFS_ABORT - log_pass "With ZFS_ABORT set, zpool command can abort and generate core file as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh index 6f15c09a52..00f24bdff0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh @@ -46,15 +46,12 @@ function cleanup { unset ZFS_ABORT - if is_freebsd && [ -n "$old_corefile" ]; then - sysctl kern.corefile=$old_corefile - fi - - rm -rf $corepath + log_must pop_coredump_pattern "$coresavepath" + log_must rm -rf $corepath # Don't leave the pool frozen. - destroy_pool $TESTPOOL - default_mirror_setup $DISKS + log_must destroy_pool $TESTPOOL + log_must default_mirror_setup $DISKS } verify_runnable "both" @@ -63,15 +60,14 @@ log_assert "Debugging features of zpool should succeed." log_onexit cleanup corepath=$TESTDIR/core -corefile=$corepath/zpool.core -if [[ -d $corepath ]]; then - log_must rm -rf $corepath -fi +corefile=$corepath/core.zpool +coresavepath=$corepath/save +log_must rm -rf $corepath log_must mkdir $corepath log_must eval "zpool -? >/dev/null 2>&1" -if is_global_zone ; then +if is_global_zone; then log_must zpool freeze $TESTPOOL else log_mustnot zpool freeze $TESTPOOL @@ -80,21 +76,10 @@ fi log_mustnot zpool freeze fakepool -if is_linux; then - echo $corefile >/proc/sys/kernel/core_pattern - echo 0 >/proc/sys/kernel/core_uses_pid -elif is_freebsd; then - old_corefile=$(sysctl -n kern.corefile) - log_must sysctl kern.corefile=$corefile -fi -ulimit -c unlimited +log_must eval "push_coredump_pattern \"$corepath\" > \"$coresavepath\"" +log_must export ZFS_ABORT=yes -export ZFS_ABORT=yes - -zpool >/dev/null 2>&1 - -unset ZFS_ABORT - -[[ -f $corefile ]] || log_fail "zpool did not dump core by request." +log_mustnot eval "zpool >/dev/null 2>&1" +log_must [ -f "$corefile" ] log_pass "Debugging features of zpool succeed."