]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
treewide: Use _sysfs_queue_path helper in all queue access locations
authorOjaswin Mujoo <ojaswin@linux.ibm.com>
Fri, 10 Apr 2026 06:36:06 +0000 (12:06 +0530)
committerZorro Lang <zlang@kernel.org>
Mon, 13 Apr 2026 17:42:42 +0000 (01:42 +0800)
The sysfs queue dir for partitions is present in their parent device's
sysfs dir. This requires extra checks when trying to reading queue data
from sysfs. Currently, fstests open codes this handling or straight up
ignores it in some places.

Avoid this by converting all remaining direct sysfs queue accesses to
use the _sysfs_queue_path helper function. This ensures proper handling
of partitions across the entire codebase and provides a consistent
interface for accessing queue attributes.

Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/encrypt
common/rc
common/report
common/zoned
tests/btrfs/076
tests/btrfs/237
tests/btrfs/273
tests/btrfs/283

index f2687631b214cf80d979a4c22850235f2294f533..c9e0853d8d8c885ef797d056099db4f85ead53b9 100644 (file)
@@ -173,11 +173,8 @@ _require_hw_wrapped_key_support()
        local dev=$1
 
        echo "Checking for HW-wrapped key support on $dev" >> $seqres.full
-       local sysfs_dir=$(_sysfs_dev $dev)
-       if [ ! -e $sysfs_dir/queue ]; then
-               sysfs_dir=$sysfs_dir/..
-       fi
-       if [ ! -e $sysfs_dir/queue/crypto/hw_wrapped_keys ]; then
+       local queue_path=$(_sysfs_queue_path $dev)
+       if [ $? -ne 0 ] || [ ! -e $queue_path/crypto/hw_wrapped_keys ]; then
                _notrun "$dev doesn't support hardware-wrapped inline encryption keys"
        fi
 
index d7db5db1d1cf6099e1947866c987f798a8e7fef1..9632b211b58fe4870d7abf4b9970174b38162583 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -2502,7 +2502,11 @@ __scratch_dev_has_dax()
 {
        local sysfs="/sys/block/$(_short_dev $SCRATCH_DEV)"
        test -e "${sysfs}/dax" && return 0
-       test "$(cat "${sysfs}/queue/dax" 2>/dev/null)" = "1" && return 0
+
+       local queue_path=$(_sysfs_queue_path $SCRATCH_DEV)
+       if [ $? -eq 0 ]; then
+               test "$(cat "${queue_path}/dax" 2>/dev/null)" = "1" && return 0
+       fi
 
        return 1
 }
@@ -2562,10 +2566,10 @@ _zone_type()
                echo "Usage: _zone_type <device>"
                _exit 1
        fi
-       local sdev=`_short_dev $target`
 
-       if [ -e /sys/block/${sdev}/queue/zoned ]; then
-               cat /sys/block/${sdev}/queue/zoned
+       local queue_path=$(_sysfs_queue_path $target)
+       if [ $? -eq 0 ] && [ -e "$queue_path/zoned" ]; then
+               cat "$queue_path/zoned"
        else
                echo none
        fi
index 7128bbebac8b75c903001872a0e5834ba0c89d76..0d9ad78c612d02049dd3264ce8f9ac73bf83775a 100644 (file)
@@ -37,16 +37,18 @@ __generate_blockdev_report_vars() {
 
        test -z "$bdev" && return
        test -b "$bdev" || return
-       local sysfs_bdev="$(_sysfs_dev "$bdev")"
-
        REPORT_VARS["${bdev_var}_SIZE_KB"]="$(( "$(blockdev --getsz "$bdev")" / 2 ))"
-       REPORT_VARS["${bdev_var}_ROTATIONAL"]="$(cat "$sysfs_bdev/queue/rotational" 2>/dev/null)"
-       REPORT_VARS["${bdev_var}_DAX"]="$(cat "$sysfs_bdev/queue/dax" 2>/dev/null)"
-       REPORT_VARS["${bdev_var}_DISCARD"]="$(sed -e 's/[1-9][0-9]*/1/g' "$sysfs_bdev/queue/discard_max_bytes" 2>/dev/null)"
-       REPORT_VARS["${bdev_var}_WRITE_ZEROES"]="$(sed -e 's/[1-9][0-9]*/1/g' "$sysfs_bdev/queue/write_zeroes_max_bytes" 2>/dev/null)"
-       REPORT_VARS["${bdev_var}_PHYS_BLOCK_BYTES"]="$(cat "$sysfs_bdev/queue/physical_block_size" 2>/dev/null)"
-       REPORT_VARS["${bdev_var}_LBA_BYTES"]="$(cat "$sysfs_bdev/queue/logical_block_size" 2>/dev/null)"
-       REPORT_VARS["${bdev_var}_ZONES"]="$(cat "$sysfs_bdev/queue/nr_zones" 2>/dev/null)"
+
+       local queue_path="$(_sysfs_queue_path "$bdev")"
+       if [ $? -eq 0 ]; then
+               REPORT_VARS["${bdev_var}_ROTATIONAL"]="$(cat "$queue_path/rotational" 2>/dev/null)"
+               REPORT_VARS["${bdev_var}_DAX"]="$(cat "$queue_path/dax" 2>/dev/null)"
+               REPORT_VARS["${bdev_var}_DISCARD"]="$(sed -e 's/[1-9][0-9]*/1/g' "$queue_path/discard_max_bytes" 2>/dev/null)"
+               REPORT_VARS["${bdev_var}_WRITE_ZEROES"]="$(sed -e 's/[1-9][0-9]*/1/g' "$queue_path/write_zeroes_max_bytes" 2>/dev/null)"
+               REPORT_VARS["${bdev_var}_PHYS_BLOCK_BYTES"]="$(cat "$queue_path/physical_block_size" 2>/dev/null)"
+               REPORT_VARS["${bdev_var}_LBA_BYTES"]="$(cat "$queue_path/logical_block_size" 2>/dev/null)"
+               REPORT_VARS["${bdev_var}_ZONES"]="$(cat "$queue_path/nr_zones" 2>/dev/null)"
+       fi
 }
 
 __import_report_vars() {
index 88b81de5db4db014607c4588a92d3e86d2458780..89d0a061fe444db68252160db5f9ce025daa8d3f 100644 (file)
@@ -17,8 +17,9 @@ _filter_blkzone_report()
 
 _require_limited_active_zones() {
     local dev=$1
-    local sysfs=$(_sysfs_dev ${dev})
-    local attr="${sysfs}/queue/max_active_zones"
+    local queue_path=$(_sysfs_queue_path ${dev})
+    [ $? -ne 0 ] && _notrun "cannot find queue path: $queue_path"
+    local attr="${queue_path}/max_active_zones"
 
     [ -e "${attr}" ] || _notrun "cannot find queue/max_active_zones. Maybe non-zoned device?"
     if [ $(cat "${attr}") == 0 ]; then
index c148406fd692b6732e106bec221cafa236c7132e..0a1e660d4b05f90df27784afcd0219f5c2445e96 100755 (executable)
@@ -28,10 +28,13 @@ _fixed_by_kernel_commit 4bcbb3325513 \
 # An extent size can be up to BTRFS_MAX_UNCOMPRESSED
 max_extent_size=$(( 128 * 1024 ))
 if _scratch_btrfs_is_zoned; then
-       zone_append_max=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/zone_append_max_bytes")
-       if [[ $zone_append_max -gt 0 && $zone_append_max -lt $max_extent_size ]]; then
-               # Round down to PAGE_SIZE
-               max_extent_size=$(( $zone_append_max / 4096 * 4096 ))
+       queue_path=$(_sysfs_queue_path $SCRATCH_DEV)
+       if [ $? -eq 0 ]; then
+               zone_append_max=$(cat "$queue_path/zone_append_max_bytes")
+               if [[ $zone_append_max -gt 0 && $zone_append_max -lt $max_extent_size ]]; then
+                       # Round down to PAGE_SIZE
+                       max_extent_size=$(( $zone_append_max / 4096 * 4096 ))
+               fi
        fi
 fi
 file_size=$(( 10 * 1024 * 1024 ))
index 675f4c42eb20e57259e4f2382ce2dc3c636c6d9c..07a5633610b4d73cbf8f2fb676f958f3c5f3659a 100755 (executable)
@@ -44,8 +44,9 @@ get_data_bg_physical()
 $BLKZONE_PROG report $SCRATCH_DEV | grep -q -e "nw" && \
        _notrun "test is unreliable on devices with conventional zones"
 
-sdev="$(_short_dev $SCRATCH_DEV)"
-zone_size=$(($(cat /sys/block/${sdev}/queue/chunk_sectors) << 9))
+queue_path=$(_sysfs_queue_path $SCRATCH_DEV) || \
+    _notrun "Failed to get queue path: $queue_path"
+zone_size=$(($(cat "$queue_path/chunk_sectors") << 9))
 fssize=$((zone_size * 16))
 devsize=$(($(_get_device_size $SCRATCH_DEV) * 1024))
 # Create a minimal FS to kick the reclaim process
index 06ae5d53b8bd29261c55a8245c6295d70adfcc4d..60c3967b648cdf7a30e9ff79b0d60b3dd823ca89 100755 (executable)
@@ -38,7 +38,9 @@ _require_btrfs_command inspect-internal dump-tree
 # enabled.
 _require_no_compress
 
-max_active=$(cat $(_sysfs_dev ${SCRATCH_DEV})/queue/max_active_zones)
+queue_path=$(_sysfs_queue_path ${SCRATCH_DEV}) || \
+    _notrun "Failed to get queue path: $queue_path"
+max_active=$(cat "$queue_path/max_active_zones")
 
 # Fill the zones leaving the last 1MB
 fill_active_zones() {
index f7a8290af4264e0dd1bac6b6bd2995af0d0dff57..9f89fafb1370cc4761d1fa4eda1e064d8405b7bd 100755 (executable)
@@ -26,7 +26,9 @@ _wants_kernel_commit c7499a64dcf6 \
 
 extent_size=$(( 128 * 1024 ))
 if _scratch_btrfs_is_zoned; then
-       zone_append_max=$(cat "/sys/block/$(_short_dev $SCRATCH_DEV)/queue/zone_append_max_bytes")
+       queue_path=$(_sysfs_queue_path $SCRATCH_DEV) ||
+           _notrun "Couldn't find queue path for zoned device"
+       zone_append_max=$(cat "$queue_path/zone_append_max_bytes")
        if [[ $zone_append_max -gt 0 && $zone_append_max -lt $extent_size ]]; then
                _notrun "zone append max $zone_append_max is smaller than wanted extent size $extent_size"
        fi