tests: revert back to original coredump patterns on Linux, too
Otherwise, they leak past the tests and contaminate the running system, breaking coredumps entirely Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Co-authored-by: Yannick Le Pennec <yannick.lepennec@live.fr> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #13259
This commit is contained in:
parent
912d2aa7d7
commit
598fed7ecd
@ -79,7 +79,7 @@ FreeBSD)
|
||||
;;
|
||||
Linux)
|
||||
# core file helpers
|
||||
origcorepattern="$(cat /proc/sys/kernel/core_pattern)"
|
||||
read -r origcorepattern </proc/sys/kernel/core_pattern
|
||||
coreglob="$(grep -E -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*"
|
||||
|
||||
if [[ $coreglob = "*" ]]; then
|
||||
|
@ -3999,3 +3999,47 @@ function replay_directory_diff # dir_a dir_b
|
||||
{
|
||||
LIBTEST_DIFF_ZIL_REPLAY=1 directory_diff "$@"
|
||||
}
|
||||
|
||||
#
|
||||
# Put coredumps into $1/core.{basename}
|
||||
#
|
||||
# Output must be saved and passed to pop_coredump_pattern on cleanup
|
||||
#
|
||||
function push_coredump_pattern # dir
|
||||
{
|
||||
ulimit -c unlimited
|
||||
case $(uname) in
|
||||
Linux)
|
||||
cat /proc/sys/kernel/core_pattern /proc/sys/kernel/core_uses_pid
|
||||
echo "$1/core.%e" >/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
|
||||
}
|
||||
|
@ -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."
|
||||
|
@ -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."
|
||||
|
@ -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."
|
||||
|
Loading…
Reference in New Issue
Block a user