Re: [PATCH 2/6] common/rc: Add _sysfs_queue_path helper with partition support

"Darrick J. Wong" <[email protected]>
Newsgroups org.kernel.vger.fstests
Message-ID <20260410165014.GQ6212@frogsfrogsfrogs>
On Fri, Apr 10, 2026 at 12:06:02PM +0530, Ojaswin Mujoo wrote:
> 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]>

Excellent!
Reviewed-by: "Darrick J. Wong" <[email protected]>

--D

> ---
>  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
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.