How to look up an ns cdev from block maj:min?

Daniel Wagner dwagner at suse.de
Wed Feb 15 02:09:42 PST 2023


On Wed, Feb 15, 2023 at 10:56:33AM +0100, Daniel Wagner wrote:
> On Wed, Feb 15, 2023 at 10:41:08AM +0200, Sagi Grimberg wrote:
> > 
> > > Hi,
> > > Is there an official way for userspace to look up an ns cdev from a
> > > block maj:min?
> > > 
> > > For example, how should a userspace program determine that /dev/ng0n1 is
> > > the corresponding ns cdev when given just the block device node
> > > /dev/nvme0n1?
> > > 
> > > Parsing the filename is an obvious option but it makes assumptions about
> > > the naming convention of both the block device node and the character
> > > device node.
> > > 
> > > Is there a better way via sysfs? (I couldn't find it.)
> > 
> > Not that I can see... It follows the same rules as the
> > normal namespace, which means that it takes the subsystem or ctrl
> > instance number (depending if multipathing is enabled) and it will have
> > the same namespace instance number.
> > 
> > In other words, every namespace nvmeXnY will present an 'nvme generic'
> > chardev in the form of ngXnY.
> > 
> > Looks like nvme-cli is missing the generic representation in the json
> > output as well. Perhaps that is the best tool to use (once fixed with
> > the json output with the below):
> 
> Looks good. I've created a PR for it.
> 
> https://github.com/linux-nvme/nvme-cli/pull/1820
> 
> Can I add your SoB?

Ah, I didn't reach the end of the mailbox. I pick up your patch :)



More information about the Linux-nvme mailing list