Skip to content

Commit

Permalink
ZTS: update existing kstat users to new helper
Browse files Browse the repository at this point in the history
Removes other custom helpers and direct accesses to /proc.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Signed-off-by: Rob Norris <[email protected]>
  • Loading branch information
robn committed Jan 16, 2025
1 parent 094b306 commit dc62479
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 129 deletions.
13 changes: 4 additions & 9 deletions tests/zfs-tests/tests/functional/arc/dbufstats_001_pos.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

#
# DESCRIPTION:
# Ensure stats presented in /proc/spl/kstat/zfs/dbufstats are correct
# based on /proc/spl/kstat/zfs/dbufs.
# Ensure stats presented in the dbufstats kstat are correct based on the
# dbufs kstat.
#
# STRATEGY:
# 1. Generate a file with random data in it
Expand All @@ -55,12 +55,7 @@ function testdbufstat # stat_name dbufstat_filter

[[ -n "$2" ]] && filter="-F $2"

if is_linux; then
read -r _ _ from_dbufstat _ < <(grep -w "$name" "$DBUFSTATS_FILE")
else
from_dbufstat=$(awk "/dbufstats\.$name:/ { print \$2 }" \
"$DBUFSTATS_FILE")
fi
from_dbufstat=$(grep "^$name " "$DBUFSTATS_FILE" | cut -f2 -d' ')
from_dbufs=$(dbufstat -bxn -i "$DBUFS_FILE" "$filter" | wc -l)

within_tolerance $from_dbufstat $from_dbufs 15 \
Expand All @@ -77,7 +72,7 @@ log_must file_write -o create -f "$TESTDIR/file" -b 1048576 -c 20 -d R
sync_all_pools

log_must eval "kstat dbufs > $DBUFS_FILE"
log_must eval "kstat dbufstats '' > $DBUFSTATS_FILE"
log_must eval "kstat -g dbufstats > $DBUFSTATS_FILE"

for level in {0..11}; do
testdbufstat "cache_level_$level" "dbc=1,level=$level"
Expand Down
17 changes: 6 additions & 11 deletions tests/zfs-tests/tests/functional/cli_root/zdb/zdb_objset_id.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
# 7. Run zdb -dddddd pool/objsetID objectID (hex)
# 8. Confirm names
# 9. Repeat with zdb -NNNNNN pool/objsetID objectID
# 10. Obtain objsetID from /proc/spl/kstat/zfs/testpool/obset-0x<ID>
# (linux only)
# 10. Obtain dataset name from testpool.objset-0x<objsetID>.dataset_name kstat
# 11. Run zdb -dddddd pool/objsetID (hex)
# 12. Match name from zdb against proc entry
# 12. Match name from zdb against kstat
# 13. Create dataset with hex numeric name
# 14. Create dataset with decimal numeric name
# 15. zdb -d for numeric datasets succeeds
Expand Down Expand Up @@ -68,7 +67,7 @@ log_note "file $init_data has object number $obj"
sync_pool $TESTPOOL

IFS=", " read -r _ _ _ _ objset_id _ < <(zdb -d $TESTPOOL/$TESTFS)
objset_hex=$(printf "0x%X" $objset_id)
objset_hex=$(printf "0x%x" $objset_id)
log_note "objset $TESTPOOL/$TESTFS has objset ID $objset_id ($objset_hex)"

for id in "$objset_id" "$objset_hex"
Expand All @@ -89,13 +88,9 @@ do
log_fail "zdb -NNNNNN $TESTPOOL/$id $obj failed (file1 not in zdb output)"
done

if is_linux; then
output=$(ls -1 /proc/spl/kstat/zfs/$TESTPOOL | grep objset- | tail -1)
objset_hex=${output#*-}
name_from_proc=$(grep dataset_name /proc/spl/kstat/zfs/$TESTPOOL/$output | cut -d' ' -f3)
log_note "checking zdb output for $name_from_proc"
log_must eval "zdb -dddddd $TESTPOOL/$objset_hex | grep -q \"$name_from_proc\""
fi
name_from_proc=$(kstat_dataset -N $TESTPOOL/$objset_id dataset_name)
log_note "checking zdb output for $name_from_proc"
log_must eval "zdb -dddddd $TESTPOOL/$objset_hex | grep -q \"$name_from_proc\""

log_must zfs create $hex_ds
log_must zfs create $num_ds
Expand Down
6 changes: 1 addition & 5 deletions tests/zfs-tests/tests/functional/deadman/deadman_sync.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ log_must zinject -c all
sync_all_pools

# Log txg sync times for reference and the zpool event summary.
if is_freebsd; then
log_must sysctl -n kstat.zfs.$TESTPOOL.txgs
else
log_must cat /proc/spl/kstat/zfs/$TESTPOOL/txgs
fi
log_must kstat_pool $TESTPOOL txgs
log_must zpool events

# Verify at least 3 deadman events were logged. The first after 5 seconds,
Expand Down
73 changes: 15 additions & 58 deletions tests/zfs-tests/tests/functional/direct/dio.kshlib
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,6 @@ function check_dio_chksum_verify_failures # pool vdev_type op expect_errors

}

#
# Get the value of a counter from
# Linux: /proc/spl/kstat/zfs/$pool/iostats file.
# FreeBSD: kstat.zfs.$pool.msic.iostats.$stat
#
function get_iostats_stat # pool stat
{
typeset pool=$1
typeset stat=$2

if is_linux; then
iostats_file=/proc/spl/kstat/zfs/$pool/iostats
val=$(grep -m1 "$stat" $iostats_file | awk '{ print $3 }')
else
val=$(sysctl -n kstat.zfs.$pool.misc.iostats.$stat)
fi
if [[ -z "$val" ]]; then
log_fail "Unable to read $stat counter"
fi

echo "$val"
}

#
# Evict any buffered blocks by overwritting them using an O_DIRECT request.
#
Expand Down Expand Up @@ -190,17 +167,13 @@ function verify_dio_write_count #pool bs size mnpnt

log_note "Checking for $dio_wr_expected Direct I/O writes"

prev_dio_wr=$(get_iostats_stat $pool direct_write_count)
prev_dio_wr=$(kstat_pool $pool iostats.direct_write_count)
dio_and_verify write $size $bs $mntpnt "sync"
curr_dio_wr=$(get_iostats_stat $pool direct_write_count)
curr_dio_wr=$(kstat_pool $pool iostats.direct_write_count)
dio_wr_actual=$((curr_dio_wr - prev_dio_wr))

if [[ $dio_wr_actual -lt $dio_wr_expected ]]; then
if is_linux; then
cat /proc/spl/kstat/zfs/$pool/iostats
else
sysctl kstat.zfs.$pool.misc.iostats
fi
kstat_pool -g $pool iostats
log_fail "Direct writes $dio_wr_actual of $dio_wr_expected"
fi
}
Expand All @@ -223,33 +196,25 @@ function check_write # pool file bs count seek flags buf_wr dio_wr

log_note "Checking $count * $bs write(s) at offset $seek, $flags"

prev_buf_wr=$(get_iostats_stat $pool arc_write_count)
prev_dio_wr=$(get_iostats_stat $pool direct_write_count)
prev_buf_wr=$(kstat_pool $pool iostats.arc_write_count)
prev_dio_wr=$(kstat_pool $pool iostats.direct_write_count)

log_must stride_dd -i /dev/urandom -o $file -b $bs -c $count \
-k $seek $flags

curr_buf_wr=$(get_iostats_stat $pool arc_write_count)
curr_buf_wr=$(kstat_pool $pool iostats.arc_write_count)
buf_wr_actual=$((curr_buf_wr - prev_buf_wr))

curr_dio_wr=$(get_iostats_stat $pool direct_write_count)
curr_dio_wr=$(kstat_pool $pool iostats.direct_write_count)
dio_wr_actual=$((curr_dio_wr - prev_dio_wr))

if [[ $buf_wr_actual -lt $buf_wr_expect ]]; then
if is_linux; then
cat /proc/spl/kstat/zfs/$pool/iostats
else
sysctl kstat.zfs.$pool.misc.iostats
fi
kstat_pool -g $pool iostats
log_fail "Buffered writes $buf_wr_actual of $buf_wr_expect"
fi

if [[ $dio_wr_actual -lt $dio_wr_expect ]]; then
if is_linux; then
cat /proc/spl/kstat/zfs/$pool/iostats
else
sysctl kstat.zfs.$pool.misc.iostats
fi
kstat_pool -g $pool iostats
log_fail "Direct writes $dio_wr_actual of $dio_wr_expect"
fi
}
Expand All @@ -272,33 +237,25 @@ function check_read # pool file bs count skip flags buf_rd dio_rd

log_note "Checking $count * $bs read(s) at offset $skip, $flags"

prev_buf_rd=$(get_iostats_stat $pool arc_read_count)
prev_dio_rd=$(get_iostats_stat $pool direct_read_count)
prev_buf_rd=$(kstat_pool $pool iostats.arc_read_count)
prev_dio_rd=$(kstat_pool $pool iostats.direct_read_count)

log_must stride_dd -i $file -o /dev/null -b $bs -c $count \
-p $skip $flags

curr_buf_rd=$(get_iostats_stat $pool arc_read_count)
curr_buf_rd=$(kstat_pool $pool iostats.arc_read_count)
buf_rd_actual=$((curr_buf_rd - prev_buf_rd))

curr_dio_rd=$(get_iostats_stat $pool direct_read_count)
curr_dio_rd=$(kstat_pool $pool iostats.direct_read_count)
dio_rd_actual=$((curr_dio_rd - prev_dio_rd))

if [[ $buf_rd_actual -lt $buf_rd_expect ]]; then
if is_linux; then
cat /proc/spl/kstat/zfs/$pool/iostats
else
sysctl kstat.zfs.$pool.misc.iostats
fi
kstat_pool -g $pool iostats
log_fail "Buffered reads $buf_rd_actual of $buf_rd_expect"
fi

if [[ $dio_rd_actual -lt $dio_rd_expect ]]; then
if is_linux; then
cat /proc/spl/kstat/zfs/$pool/iostats
else
sysctl kstat.zfs.$pool.misc.iostats
fi
kstat_pool -g $pool iostats
log_fail "Direct reads $dio_rd_actual of $dio_rd_expect"
fi
}
Expand Down
8 changes: 4 additions & 4 deletions tests/zfs-tests/tests/functional/direct/dio_read_verify.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ for type in "" "mirror" "raidz" "draid"; do
$TESTPOOL1/$TESTFS1"

mntpnt=$(get_prop mountpoint $TESTPOOL1/$TESTFS1)
prev_dio_rd=$(get_iostats_stat $TESTPOOL1 direct_read_count)
prev_arc_rd=$(get_iostats_stat $TESTPOOL1 arc_read_count)
prev_dio_rd=$(kstat_pool $TESTPOOL1 iostats.direct_read_count)
prev_arc_rd=$(kstat_pool $TESTPOOL1 iostats.arc_read_count)

# Create the file before trying to manipulate the contents
log_must stride_dd -o "$mntpnt/direct-write.iso" -i /dev/urandom \
Expand All @@ -83,8 +83,8 @@ for type in "" "mirror" "raidz" "draid"; do
-n $NUMBLOCKS -b $BS -r

# Getting new Direct I/O and ARC Write counts.
curr_dio_rd=$(get_iostats_stat $TESTPOOL1 direct_read_count)
curr_arc_rd=$(get_iostats_stat $TESTPOOL1 arc_read_count)
curr_dio_rd=$(kstat_pool $TESTPOOL1 iostats.direct_read_count)
curr_arc_rd=$(kstat_pool $TESTPOOL1 iostats.arc_read_count)
total_dio_rd=$((curr_dio_rd - prev_dio_rd))
total_arc_rd=$((curr_arc_rd - prev_arc_rd))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ log_must zpool export $TESTPOOL
log_must zpool import $TESTPOOL

# Reading the file back using Direct I/O
prev_dio_read=$(get_iostats_stat $TESTPOOL direct_read_count)
prev_arc_read=$(get_iostats_stat $TESTPOOL arc_read_count)
prev_dio_read=$(kstat_pool $TESTPOOL iostats.direct_read_count)
prev_arc_read=$(kstat_pool $TESTPOOL iostats.arc_read_count)
log_must stride_dd -i $filename -o /dev/null -b $bs -e -d
curr_dio_read=$(get_iostats_stat $TESTPOOL direct_read_count)
curr_arc_read=$(get_iostats_stat $TESTPOOL arc_read_count)
curr_dio_read=$(kstat_pool $TESTPOOL iostats.direct_read_count)
curr_arc_read=$(kstat_pool $TESTPOOL iostats.arc_read_count)
total_dio_read=$((curr_dio_read - prev_dio_read))
total_arc_read=$((curr_arc_read - prev_arc_read))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ do
log_note "Verifying stable pages for Direct I/O writes \
iteration $i of $ITERATIONS"

prev_dio_wr=$(get_iostats_stat $TESTPOOL direct_write_count)
prev_dio_wr=$(kstat_pool $TESTPOOL iostats.direct_write_count)

# Manipulate the user's buffer while running O_DIRECT write
# workload with the buffer.
Expand All @@ -83,7 +83,7 @@ do
log_must stride_dd -i $mntpnt/direct-write.iso -o /dev/null \
-b $BS -c $NUMBLOCKS

curr_dio_wr=$(get_iostats_stat $TESTPOOL direct_write_count)
curr_dio_wr=$(kstat_pool $TESTPOOL iostats.direct_write_count)
total_dio_wr=$((curr_dio_wr - prev_dio_wr))

log_note "Making sure we have Direct I/O writes logged"
Expand Down
12 changes: 6 additions & 6 deletions tests/zfs-tests/tests/functional/direct/dio_write_verify.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ log_must set_tunable32 VDEV_DIRECT_WR_VERIFY 0
# failures
log_note "Verifying no panics for Direct I/O writes with compression"
log_must zfs set compression=on $TESTPOOL/$TESTFS
prev_dio_wr=$(get_iostats_stat $TESTPOOL direct_write_count)
prev_dio_wr=$(kstat_pool $TESTPOOL iostats.direct_write_count)
log_must manipulate_user_buffer -f "$mntpnt/direct-write.iso" -n $NUMBLOCKS \
-b $BS -w
curr_dio_wr=$(get_iostats_stat $TESTPOOL direct_write_count)
curr_dio_wr=$(kstat_pool $TESTPOOL iostats.direct_write_count)
total_dio_wr=$((curr_dio_wr - prev_dio_wr))

log_note "Making sure we have Direct I/O writes logged"
Expand All @@ -115,7 +115,7 @@ for i in $(seq 1 $ITERATIONS); do
log_note "Verifying Direct I/O write checksums iteration \
$i of $ITERATIONS with zfs_vdev_direct_write_verify=0"

prev_dio_wr=$(get_iostats_stat $TESTPOOL direct_write_count)
prev_dio_wr=$(kstat_pool $TESTPOOL iostats.direct_write_count)
log_must manipulate_user_buffer -f "$mntpnt/direct-write.iso" \
-n $NUMBLOCKS -b $BS -w

Expand All @@ -126,7 +126,7 @@ for i in $(seq 1 $ITERATIONS); do
-c $num_blocks

# Getting new Direct I/O and ARC write counts.
curr_dio_wr=$(get_iostats_stat $TESTPOOL direct_write_count)
curr_dio_wr=$(kstat_pool $TESTPOOL iostats.direct_write_count)
total_dio_wr=$((curr_dio_wr - prev_dio_wr))

# Verifying there are checksum errors
Expand Down Expand Up @@ -165,7 +165,7 @@ for i in $(seq 1 $ITERATIONS); do
log_note "Verifying every Direct I/O write checksums iteration $i of \
$ITERATIONS with zfs_vdev_direct_write_verify=1"

prev_dio_wr=$(get_iostats_stat $TESTPOOL direct_write_count)
prev_dio_wr=$(kstat_pool $TESTPOOL iostats.direct_write_count)
log_must manipulate_user_buffer -f "$mntpnt/direct-write.iso" \
-n $NUMBLOCKS -b $BS -e -w

Expand All @@ -176,7 +176,7 @@ for i in $(seq 1 $ITERATIONS); do
-c $num_blocks

# Getting new Direct I/O write counts.
curr_dio_wr=$(get_iostats_stat $TESTPOOL direct_write_count)
curr_dio_wr=$(kstat_pool $TESTPOOL iostats.direct_write_count)
total_dio_wr=$((curr_dio_wr - prev_dio_wr))

log_note "Making sure there are no checksum errors with the ZPool"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ function cleanup
[[ -e $TESTDIR ]] && log_must rm -Rf $TESTDIR/*
}

getstat() {
awk -v c="$1" '$1 == c {print $3; exit}' /proc/spl/kstat/zfs/arcstats
}

log_assert "Ensure fadvise prefetch data"

log_onexit cleanup
Expand All @@ -67,12 +63,12 @@ log_must zfs set primarycache=metadata $TESTPOOL
log_must file_write -o create -f $FILE -b $BLKSZ -c 1000
sync_pool $TESTPOOL

data_size1=$(getstat data_size)
data_size1=$(kstat arcstats.data_size)

log_must file_fadvise -f $FILE -a 2
sleep 10

data_size2=$(getstat data_size)
data_size2=$(kstat arcstats.data_size)
log_note "original data_size is $data_size1, final data_size is $data_size2"

log_must [ $data_size1 -le $data_size2 ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ log_must dd if=/dev/urandom of=$MNTPOINT/writes bs=1M count=1
# Wait until sync starts, and the pool suspends
log_note "waiting for pool to suspend"
typeset -i tries=30
until [[ $(cat /proc/spl/kstat/zfs/$TESTPOOL/state) == "SUSPENDED" ]] ; do
until [[ $(kstat_pool $TESTPOOL state) == "SUSPENDED" ]] ; do
if ((tries-- == 0)); then
zpool status -s
log_fail "UNEXPECTED -- pool did not suspend"
fi
sleep 1
done
log_note $(cat /proc/spl/kstat/zfs/$TESTPOOL/state)
log_note $(kstat_pool $TESTPOOL state)

# Put the missing disks back into service
log_must eval "echo running > /sys/block/$sd/device/state"
Expand All @@ -137,7 +137,7 @@ log_must zpool clear $TESTPOOL
# Wait until the pool resumes
log_note "waiting for pool to resume"
tries=30
until [[ $(cat /proc/spl/kstat/zfs/$TESTPOOL/state) != "SUSPENDED" ]] ; do
until [[ $(kstat_pool $TESTPOOL state) != "SUSPENDED" ]] ; do
if ((tries-- == 0)); then
log_fail "pool did not resume"
fi
Expand Down
Loading

0 comments on commit dc62479

Please sign in to comment.