aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcmd/dbufstat/dbufstat.in17
-rw-r--r--module/os/freebsd/spl/spl_kstat.c1
-rw-r--r--tests/runfiles/common.run5
-rw-r--r--tests/runfiles/linux.run5
-rw-r--r--tests/zfs-tests/include/libtest.shlib26
-rwxr-xr-xtests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh12
-rwxr-xr-xtests/zfs-tests/tests/functional/arc/dbufstats_002_pos.ksh6
7 files changed, 56 insertions, 16 deletions
diff --git a/cmd/dbufstat/dbufstat.in b/cmd/dbufstat/dbufstat.in
index 98eb79057..1d4eb39d7 100755
--- a/cmd/dbufstat/dbufstat.in
+++ b/cmd/dbufstat/dbufstat.in
@@ -113,6 +113,21 @@ cmd = ("Usage: dbufstat [-bdhnrtvx] [-i file] [-f fields] [-o file] "
raw = 0
+if sys.platform.startswith("freebsd"):
+ import io
+ # Requires py-sysctl on FreeBSD
+ import sysctl
+
+ def default_ifile():
+ dbufs = sysctl.filter("kstat.zfs.misc.dbufs")[0].value
+ sys.stdin = io.StringIO(dbufs)
+ return "-"
+
+elif sys.platform.startswith("linux"):
+ def default_ifile():
+ return "/proc/spl/kstat/zfs/dbufs"
+
+
def print_incompat_helper(incompat):
cnt = 0
for key in sorted(incompat):
@@ -645,7 +660,7 @@ def main():
sys.exit(1)
if not ifile:
- ifile = '/proc/spl/kstat/zfs/dbufs'
+ ifile = default_ifile()
if ifile is not "-":
try:
diff --git a/module/os/freebsd/spl/spl_kstat.c b/module/os/freebsd/spl/spl_kstat.c
index 4cc77e20a..b26753bac 100644
--- a/module/os/freebsd/spl/spl_kstat.c
+++ b/module/os/freebsd/spl/spl_kstat.c
@@ -231,6 +231,7 @@ restart:
}
free(ksp->ks_raw_buf, M_TEMP);
mutex_exit(ksp->ks_lock);
+ sbuf_trim(sb);
rc = sbuf_finish(sb);
if (rc == 0)
rc = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb));
diff --git a/tests/runfiles/common.run b/tests/runfiles/common.run
index a29578b36..228bd5eac 100644
--- a/tests/runfiles/common.run
+++ b/tests/runfiles/common.run
@@ -30,6 +30,11 @@ tests = ['alloc_class_001_pos', 'alloc_class_002_neg', 'alloc_class_003_pos',
'alloc_class_013_pos']
tags = ['functional', 'alloc_class']
+[tests/functional/arc]
+tests = ['dbufstats_001_pos', 'dbufstats_002_pos', 'dbufstats_003_pos',
+ 'arcstats_runtime_tuning']
+tags = ['functional', 'arc']
+
[tests/functional/atime]
tests = ['atime_001_pos', 'atime_002_neg', 'root_atime_off', 'root_atime_on']
tags = ['functional', 'atime']
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
index b6508a5cb..94964434e 100644
--- a/tests/runfiles/linux.run
+++ b/tests/runfiles/linux.run
@@ -26,11 +26,6 @@ tags = ['functional']
tests = ['posix_001_pos', 'posix_002_pos', 'posix_003_pos']
tags = ['functional', 'acl', 'posix']
-[tests/functional/arc:Linux]
-tests = ['dbufstats_001_pos', 'dbufstats_002_pos', 'dbufstats_003_pos',
- 'arcstats_runtime_tuning']
-tags = ['functional', 'arc']
-
[tests/functional/atime:Linux]
tests = ['atime_003_pos', 'root_relatime_on']
tags = ['functional', 'atime']
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib
index 9898bada9..98ef54e4d 100644
--- a/tests/zfs-tests/include/libtest.shlib
+++ b/tests/zfs-tests/include/libtest.shlib
@@ -4154,18 +4154,36 @@ function ls_xattr # path
esac
}
+function kstat # stat flags?
+{
+ typeset stat=$1
+ typeset flags=${2-"-n"}
+
+ case $(uname) in
+ FreeBSD)
+ sysctl $flags kstat.zfs.misc.$stat
+ ;;
+ Linux)
+ typeset zfs_kstat="/proc/spl/kstat/zfs/$stat"
+ [[ -f "$zfs_kstat" ]] || return 1
+ cat $zfs_kstat
+ ;;
+ *)
+ false
+ ;;
+ esac
+}
+
function get_arcstat # stat
{
typeset stat=$1
case $(uname) in
FreeBSD)
- sysctl -n kstat.zfs.misc.arcstats.$stat
+ kstat arcstats.$stat
;;
Linux)
- typeset zfs_arcstats="/proc/spl/kstat/zfs/arcstats"
- [[ -f "$zfs_arcstats" ]] || return 1
- grep $stat $zfs_arcstats | awk '{print $3}'
+ kstat arcstats | awk "/$stat/ { print \$3 }"
;;
*)
false
diff --git a/tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh b/tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh
index 4884f11bb..0577a6b80 100755
--- a/tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh
+++ b/tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh
@@ -55,7 +55,13 @@ function testdbufstat # stat_name dbufstat_filter
[[ -n "$2" ]] && filter="-F $2"
- from_dbufstat=$(grep -w "$name" "$DBUFSTATS_FILE" | awk '{ print $3 }')
+ if is_linux; then
+ from_dbufstat=$(grep -w "$name" "$DBUFSTATS_FILE" |
+ awk '{ print $3 }')
+ else
+ from_dbufstat=$(awk "/dbufstats\.$name:/ { print \$2 }" \
+ "$DBUFSTATS_FILE")
+ fi
from_dbufs=$(dbufstat -bxn -i "$DBUFS_FILE" "$filter" | wc -l)
within_tolerance $from_dbufstat $from_dbufs 15 \
@@ -71,8 +77,8 @@ log_onexit cleanup
log_must file_write -o create -f "$TESTDIR/file" -b 1048576 -c 20 -d R
log_must zpool sync
-log_must eval "cat /proc/spl/kstat/zfs/dbufs > $DBUFS_FILE"
-log_must eval "cat /proc/spl/kstat/zfs/dbufstats > $DBUFSTATS_FILE"
+log_must eval "kstat dbufs > $DBUFS_FILE"
+log_must eval "kstat dbufstats '' > $DBUFSTATS_FILE"
for level in {0..11}; do
testdbufstat "cache_level_$level" "dbc=1,level=$level"
diff --git a/tests/zfs-tests/tests/functional/arc/dbufstats_002_pos.ksh b/tests/zfs-tests/tests/functional/arc/dbufstats_002_pos.ksh
index dc30b6606..58d401539 100755
--- a/tests/zfs-tests/tests/functional/arc/dbufstats_002_pos.ksh
+++ b/tests/zfs-tests/tests/functional/arc/dbufstats_002_pos.ksh
@@ -58,10 +58,10 @@ log_onexit cleanup
log_must file_write -o create -f "$TESTDIR/file" -b 1048576 -c 1 -d R
log_must zpool sync
-objid=$(stat --format="%i" "$TESTDIR/file")
+objid=$(get_objnum "$TESTDIR/file")
log_note "Object ID for $TESTDIR/file is $objid"
-log_must eval "cat /proc/spl/kstat/zfs/dbufs > $DBUFS_FILE"
+log_must eval "kstat dbufs > $DBUFS_FILE"
dbuf=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid" | wc -l)
mru=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=1" | wc -l)
mfu=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=3" | wc -l)
@@ -70,7 +70,7 @@ verify_ne "0" "$mru" "mru count"
verify_eq "0" "$mfu" "mfu count"
log_must eval "cat $TESTDIR/file > /dev/null"
-log_must eval "cat /proc/spl/kstat/zfs/dbufs > $DBUFS_FILE"
+log_must eval "kstat dbufs > $DBUFS_FILE"
dbuf=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid" | wc -l)
mru=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=1" | wc -l)
mfu=$(dbufstat -bxn -i "$DBUFS_FILE" -F "object=$objid,list=3" | wc -l)