Skip to content

Commit cfa30a4

Browse files
nabijaczleweliYannick Le Pennec
authored andcommitted
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 <[email protected]> Reviewed-by: John Kennedy <[email protected]> Reviewed-by: Ryan Moeller <[email protected]> Co-authored-by: Yannick Le Pennec <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes openzfs#13259
1 parent ee5c12e commit cfa30a4

File tree

5 files changed

+78
-90
lines changed

5 files changed

+78
-90
lines changed

scripts/zloop.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ FreeBSD)
7979
;;
8080
Linux)
8181
# core file helpers
82-
origcorepattern="$(cat /proc/sys/kernel/core_pattern)"
82+
read -r origcorepattern </proc/sys/kernel/core_pattern
8383
coreglob="$(grep -E -o '^([^|%[:space:]]*)' /proc/sys/kernel/core_pattern)*"
8484

8585
if [[ $coreglob = "*" ]]; then

tests/zfs-tests/include/libtest.shlib

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,3 +3999,47 @@ function replay_directory_diff # dir_a dir_b
39993999
{
40004000
LIBTEST_DIFF_ZIL_REPLAY=1 directory_diff "$@"
40014001
}
4002+
4003+
#
4004+
# Put coredumps into $1/core.{basename}
4005+
#
4006+
# Output must be saved and passed to pop_coredump_pattern on cleanup
4007+
#
4008+
function push_coredump_pattern # dir
4009+
{
4010+
ulimit -c unlimited
4011+
case $(uname) in
4012+
Linux)
4013+
cat /proc/sys/kernel/core_pattern /proc/sys/kernel/core_uses_pid
4014+
echo "$1/core.%e" >/proc/sys/kernel/core_pattern &&
4015+
echo 0 >/proc/sys/kernel/core_uses_pid
4016+
;;
4017+
FreeBSD)
4018+
sysctl -n kern.corefile
4019+
sysctl kern.corefile="$1/core.%N" >/dev/null
4020+
;;
4021+
*)
4022+
# Nothing to output – set only for this shell
4023+
coreadm -p "$1/core.%f"
4024+
;;
4025+
esac
4026+
}
4027+
4028+
#
4029+
# Put coredumps back into the default location
4030+
#
4031+
function pop_coredump_pattern
4032+
{
4033+
[ -s "$1" ] || return 0
4034+
case $(uname) in
4035+
Linux)
4036+
typeset pat pid
4037+
{ read -r pat; read -r pid; } < "$1"
4038+
echo "$pat" >/proc/sys/kernel/core_pattern &&
4039+
echo "$pid" >/proc/sys/kernel/core_uses_pid
4040+
;;
4041+
FreeBSD)
4042+
sysctl kern.corefile="$(<"$1")" >/dev/null
4043+
;;
4044+
esac
4045+
}

tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,33 +48,23 @@ function cleanup
4848
{
4949
unset ZFS_ABORT
5050

51-
if is_freebsd && [[ -n $savedcorefile ]]; then
52-
sysctl kern.corefile=$savedcorefile
53-
fi
51+
log_must pop_coredump_pattern "$coresavepath"
5452

55-
if [[ -d $corepath ]]; then
56-
rm -rf $corepath
57-
fi
5853
for ds in $fs1 $fs $ctr; do
5954
datasetexists $ds && destroy_dataset $ds -rRf
6055
done
6156
}
6257

63-
log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a " \
64-
"core file."
58+
log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a core file."
6559
log_onexit cleanup
6660

61+
ctr=$TESTPOOL/$TESTCTR
62+
log_must zfs create -p $ctr
63+
6764
# Preparation work for testing
68-
savedcorefile=""
69-
corepath=$TESTDIR/core
65+
corepath=/$ctr
7066
corefile=$corepath/core.zfs
71-
if [[ -d $corepath ]]; then
72-
rm -rf $corepath
73-
fi
74-
log_must mkdir $corepath
75-
76-
ctr=$TESTPOOL/$TESTCTR
77-
log_must zfs create $ctr
67+
coresavepath=$corepath/save
7868

7969
fs=$ctr/$TESTFS
8070
fs1=$ctr/$TESTFS1
@@ -93,24 +83,12 @@ typeset badparams=("" "create" "destroy" "snapshot" "rollback" "clone" \
9383
"promote" "rename" "list -*" "set" "get -*" "inherit" "mount -A" \
9484
"unmount" "share" "unshare" "send" "receive")
9585

96-
if is_linux; then
97-
ulimit -c unlimited
98-
echo "$corefile" >/proc/sys/kernel/core_pattern
99-
echo 0 >/proc/sys/kernel/core_uses_pid
100-
elif is_freebsd; then
101-
ulimit -c unlimited
102-
savedcorefile=$(sysctl -n kern.corefile)
103-
log_must sysctl kern.corefile=$corepath/core.%N
104-
else
105-
log_must coreadm -p ${corepath}/core.%f
106-
fi
107-
86+
log_must eval "push_coredump_pattern \"$corepath\" > \"$coresavepath\""
10887
log_must export ZFS_ABORT=yes
10988

11089
for subcmd in "${cmds[@]}" "${badparams[@]}"; do
111-
log_mustnot eval "zfs $subcmd >/dev/null 2>&1"
112-
log_must rm $corefile
90+
log_mustnot eval "zfs $subcmd"
91+
log_must rm "$corefile"
11392
done
11493

115-
log_pass "With ZFS_ABORT set, zfs command can abort and generate core file " \
116-
"as expected."
94+
log_pass "With ZFS_ABORT set, zfs command can abort and generate core file as expected."

tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,33 +47,27 @@ function cleanup
4747
{
4848
unset ZFS_ABORT
4949

50-
if is_freebsd && [ -n "$old_corefile" ]; then
51-
sysctl kern.corefile=$old_corefile
52-
fi
50+
log_must pop_coredump_pattern "$coresavepath"
51+
log_must rm -rf $corepath $vdev1 $vdev2 $vdev3
5352

5453
# Clean up the pool created if we failed to abort.
5554
poolexists $pool && destroy_pool $pool
56-
57-
rm -rf $corepath $vdev1 $vdev2 $vdev3
5855
}
5956

6057
log_assert "With ZFS_ABORT set, all zpool commands can abort and generate a core file."
6158
log_onexit cleanup
6259

6360
corepath=$TESTDIR/core
64-
corefile=$corepath/zpool.core
65-
if [[ -d $corepath ]]; then
66-
log_must rm -rf $corepath
67-
fi
61+
corefile=$corepath/core.zpool
62+
coresavepath=$corepath/save
63+
log_must rm -rf $corepath
6864
log_must mkdir $corepath
6965

7066
pool=pool.$$
7167
vdev1=$TESTDIR/file1
7268
vdev2=$TESTDIR/file2
7369
vdev3=$TESTDIR/file3
74-
for vdev in $vdev1 $vdev2 $vdev3; do
75-
log_must mkfile $MINVDEVSIZE $vdev
76-
done
70+
log_must mkfile $MINVDEVSIZE $vdev1 $vdev2 $vdev3
7771

7872
set -A cmds "create $pool mirror $vdev1 $vdev2" "list $pool" "iostat $pool" \
7973
"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"
8680
"online" "offline" "clear" "attach" "detach" "replace" "scrub" \
8781
"import" "export" "upgrade" "history -?" "get" "set"
8882

89-
if is_linux; then
90-
echo $corefile >/proc/sys/kernel/core_pattern
91-
echo 0 >/proc/sys/kernel/core_uses_pid
92-
elif is_freebsd; then
93-
old_corefile=$(sysctl -n kern.corefile)
94-
log_must sysctl kern.corefile=$corefile
95-
fi
96-
ulimit -c unlimited
97-
98-
export ZFS_ABORT=yes
83+
log_must eval "push_coredump_pattern \"$corepath\" > \"$coresavepath\""
84+
log_must export ZFS_ABORT=yes
9985

10086
for subcmd in "${cmds[@]}" "${badparams[@]}"; do
101-
zpool $subcmd >/dev/null 2>&1
102-
if [[ ! -e $corefile ]]; then
103-
log_fail "zpool $subcmd cannot generate core file with ZFS_ABORT set."
104-
fi
105-
rm -f $corefile
87+
log_mustnot eval "zpool $subcmd"
88+
log_must rm "$corefile"
10689
done
10790

108-
unset ZFS_ABORT
109-
11091
log_pass "With ZFS_ABORT set, zpool command can abort and generate core file as expected."

tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,12 @@ function cleanup
4646
{
4747
unset ZFS_ABORT
4848

49-
if is_freebsd && [ -n "$old_corefile" ]; then
50-
sysctl kern.corefile=$old_corefile
51-
fi
52-
53-
rm -rf $corepath
49+
log_must pop_coredump_pattern "$coresavepath"
50+
log_must rm -rf $corepath
5451

5552
# Don't leave the pool frozen.
56-
destroy_pool $TESTPOOL
57-
default_mirror_setup $DISKS
53+
log_must destroy_pool $TESTPOOL
54+
log_must default_mirror_setup $DISKS
5855
}
5956

6057
verify_runnable "both"
@@ -63,15 +60,14 @@ log_assert "Debugging features of zpool should succeed."
6360
log_onexit cleanup
6461

6562
corepath=$TESTDIR/core
66-
corefile=$corepath/zpool.core
67-
if [[ -d $corepath ]]; then
68-
log_must rm -rf $corepath
69-
fi
63+
corefile=$corepath/core.zpool
64+
coresavepath=$corepath/save
65+
log_must rm -rf $corepath
7066
log_must mkdir $corepath
7167

7268
log_must eval "zpool -? >/dev/null 2>&1"
7369

74-
if is_global_zone ; then
70+
if is_global_zone; then
7571
log_must zpool freeze $TESTPOOL
7672
else
7773
log_mustnot zpool freeze $TESTPOOL
@@ -80,21 +76,10 @@ fi
8076

8177
log_mustnot zpool freeze fakepool
8278

83-
if is_linux; then
84-
echo $corefile >/proc/sys/kernel/core_pattern
85-
echo 0 >/proc/sys/kernel/core_uses_pid
86-
elif is_freebsd; then
87-
old_corefile=$(sysctl -n kern.corefile)
88-
log_must sysctl kern.corefile=$corefile
89-
fi
90-
ulimit -c unlimited
91-
92-
export ZFS_ABORT=yes
93-
94-
zpool >/dev/null 2>&1
95-
96-
unset ZFS_ABORT
79+
log_must eval "push_coredump_pattern \"$corepath\" > \"$coresavepath\""
80+
log_must export ZFS_ABORT=yes
9781

98-
[[ -f $corefile ]] || log_fail "zpool did not dump core by request."
82+
log_mustnot eval "zpool >/dev/null 2>&1"
83+
log_must [ -f "$corefile" ]
9984

10085
log_pass "Debugging features of zpool succeed."

0 commit comments

Comments
 (0)