[PATCH] tree: Add NVM subsystem controller identifier

Nilay Shroff nilay at linux.ibm.com
Tue Mar 26 01:50:11 PDT 2024



On 3/26/24 12:40, Hannes Reinecke wrote:
> On 3/26/24 07:57, Nilay Shroff wrote:
>> This commit introduces a field "cntlid" for controller,
>> that contains the NVM subsystem unique identifier assigned
>> to each controller device in an NVM subsystem.
>>
>> While attaching a namespace, typically user needs to specify the
>> controller identifier (cntlid). The cntlid could be referenced from
>> sysfs (/sys/class/nvme/nvmeX/cntlid) but it would be nice to have
>> a direct option.
>>  > Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
>> ---
>> Hi all,
>>
>> While attaching an NVMe namespace using nvme-cli command
>> "nvme attach-ns", we need to specifiy controller identifier
>> (cntlid) against which the namespace is being attached.
>>
>> Not specifying cntlid while attaching namespace would result in
>> no actual change in namespace attachment. For instance,
>>
>> # nvme create-ns /dev/nvme0 --nsze=0x156d56 --ncap=0x156d56  --block-size=4096
>> create-ns: Success, created nsid:1
>>
>> # nvme attach-ns /dev/nvme0 -n 1
>> warning: empty controller-id list will result in no actual change in namespace attachment
>> attach-ns: Success, nsid:1
>>
> 
> Errm. How would that work? /dev/nvme0 _is_ a controller, and as such will have an assigned cntlid. And if one would issue an 'attach-ns'
> command the only controller which it could address is that controller
> to which the command is issued.
> I'd be _very_ surprised if you could issue 'attach-ns' against _another_
> controller. So why do we need this option?
> Shouldn't we rather infer the cntlid from the existing controller?
> 
Yes it's possible to attach a namespace against the cntlid which could be different from 
the nvmeX device we use while attaching the namespace. Moreover, if we want to create a shared 
namespace then we need to specify all controller identifiers which would share that namespace.

For reference, I would show the example output below:

Example 1: Create a shared namespace and attach to multiple controllers:
------------------------------------------------------------------------

# nvme list -v 
Subsystem        Subsystem-NQN                                                                                    Controllers
---------------- ------------------------------------------------------------------------------------------------ ----------------
nvme-subsys1     nqn.1994-11.com.samsung:nvme:PM1735a:2.5-inch:S6RTNE0R900057                                     nvme1, nvme3
[...]

As we could see above I have two controllers (nvme1 and nvme3) under NVM subsys1. 
Lets find cntlid of each controller.

# cat /sys/class/nvme/nvme1/cntlid 
66 
# cat /sys/class/nvme/nvme3/cntlid 
65

Now create a shared namespace and attach it against the above controllers:

# nvme create-ns /dev/nvme1 --nsze=0x156d56 --ncap=0x156d56  --block-size=4096 -m 1 
create-ns: Success, created nsid:1

# nvme attach-ns /dev/nvme1 -n 0x1 -c 65,66 
attach-ns: Success, nsid:1

# nvme list -v
[...]

Device       Generic      NSID       Usage                      Format           Controllers     
------------ ------------ ---------- -------------------------- ---------------- ----------------
/dev/nvme1n1 /dev/ng1n1   0x1          5.75  GB /   5.75  GB      4 KiB +  0 B   nvme1, nvme3


As we could see above for creating shared namespace we need to know the cntlid of both 
nvme1 and nvme3 controllers.

Example 2: Create a private namespace and attach to a controller other than the one specified in nvmeX
------------------------------------------------------------------------------------------------------

# nvme create-ns /dev/nvme1 --nsze=0x156d56 --ncap=0x156d56  --block-size=4096
create-ns: Success, created nsid:2

# nvme attach-ns /dev/nvme1 -n 2 -c 65
attach-ns: Success, nsid:2

Please note above that I attached the namespace against controller nvme3 (the cntlid 65 is assigned to nvme3)

# nvme list -v
[...]

Device       Generic      NSID       Usage                      Format           Controllers     
------------ ------------ ---------- -------------------------- ---------------- ----------------
/dev/nvme1n1 /dev/ng1n1   0x1          5.75  GB /   5.75  GB      4 KiB +  0 B   nvme1, nvme3
/dev/nvme1n2 /dev/ng1n2   0x2          5.75  GB /   5.75  GB      4 KiB +  0 B   nvme3

Thanks,
--Nilay



More information about the Linux-nvme mailing list