diff options
author | Ryan Moeller <[email protected]> | 2020-10-08 12:40:23 -0400 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2020-10-16 13:00:28 -0700 |
commit | 25e44a17fff45d4d8443ed2b065572d4a440a267 (patch) | |
tree | 1adeb40a0c6abab96fb4e8a4fdd2e11dee38300a /tests/zfs-tests | |
parent | 718d20ed931d768e0252969974dc2d5b26186ac6 (diff) |
Make dbufstat work on FreeBSD
With procfs_list kstats implemented for FreeBSD, dbufs are now exposed
as kstat.zfs.misc.dbufs.
On FreeBSD, dbufstats can use the sysctl instead of procfs when no
input file has been given.
Enable the dbufstats tests on FreeBSD.
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #11008
Diffstat (limited to 'tests/zfs-tests')
-rw-r--r-- | tests/zfs-tests/include/libtest.shlib | 26 | ||||
-rwxr-xr-x | tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh | 12 | ||||
-rwxr-xr-x | tests/zfs-tests/tests/functional/arc/dbufstats_002_pos.ksh | 6 |
3 files changed, 34 insertions, 10 deletions
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index 1618c92bd..dec723e9a 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) |