[PATCH 2/6] common/rc: Add _sysfs_queue_path helper with partition support
Ojaswin Mujoo <[email protected]>
| Newsgroups | org.kernel.vger.fstests |
|---|---|
| Message-ID | <b88d249da588e8caf671088b34ced493e494d595.1775802601.git.ojaswin@linux.ibm.com> |
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 <[email protected]> --- common/rc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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. -- 2.53.0