From: Ojaswin Mujoo Date: Fri, 10 Apr 2026 06:36:02 +0000 (+0530) Subject: common/rc: Add _sysfs_queue_path helper with partition support X-Git-Tag: v2026.04.20~9 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2c002c3a86c03155e6129fea77c1b2c29a43b18a;p=xfstests-dev.git common/rc: Add _sysfs_queue_path helper with partition support Add a generic helper function to get the sysfs queue path for block devices, properly handling partitions. Partitions don't have their own queue directory in sysfs - they inherit from their parent device. This helper checks if a device is a partition and returns the parent device's queue path accordingly, making it easier to access queue attributes for both whole disks and partitions. Signed-off-by: Ojaswin Mujoo Reviewed-by: Darrick J. Wong Signed-off-by: Zorro Lang --- diff --git a/common/rc b/common/rc index 5fe44e21..d7db5db1 100644 --- a/common/rc +++ b/common/rc @@ -5172,6 +5172,30 @@ _sysfs_dev() echo /sys/dev/block/$maj:$min } +# Get the sysfs queue path for a block device, handling partitions correctly. +_sysfs_queue_path() +{ + local dev parent + dev=$(_short_dev "$1") + + # For partitions, queue details are in the parent device's sysfs dir + if [ -e "/sys/class/block/$dev/partition" ]; then + parent=$(basename "$(readlink -f /sys/class/block/$dev/..)") + else + parent="$dev" + fi + + local queue_path="/sys/block/$parent/queue" + + # Verify the path exists before returning + if [ -e "$queue_path" ]; then + echo "$queue_path" + return 0 + else + return 1 + fi +} + # Get the minimum block size of a file. Usually this is the # minimum fs block size, but some filesystems (ocfs2) do block # mappings in larger units.