]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common/rc: Add _sysfs_queue_path helper with partition support
authorOjaswin Mujoo <ojaswin@linux.ibm.com>
Fri, 10 Apr 2026 06:36:02 +0000 (12:06 +0530)
committerZorro Lang <zlang@kernel.org>
Mon, 13 Apr 2026 17:42:41 +0000 (01:42 +0800)
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 <ojaswin@linux.ibm.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/rc

index 5fe44e2158ffb3bfd287b2db97e20c2dc7b9361e..d7db5db1d1cf6099e1947866c987f798a8e7fef1 100644 (file)
--- 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.