[PATCH] tree: Add NVM subsystem controller identifier

Nilay Shroff nilay at linux.ibm.com
Tue Mar 26 00:03:48 PDT 2024


I forgot to add that this is libnvme patch in the subject. Sorry about that.

Thanks,
--Nilay

On 3/26/24 12:27, 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
> 
> # nvme list -o json
> {
>   "Devices":[
>   ]
> }
> 
> Though it's possible to find the cntlid looking at the sysfs file, 
> it'd be convenient to have it readily avaliable under nvme list 
> verbose output. 
> 
> This patch adds support for retrieving the cntlid in libnvme, 
> the subsequent nvme-cli patch shall use this information to 
> print the cntlid field in nvme list verbose output.
> 
> Thanks,
> --Nilay
> 
> ---
>  src/libnvme.map    | 1 +
>  src/nvme/private.h | 1 +
>  src/nvme/tree.c    | 7 +++++++
>  src/nvme/tree.h    | 7 +++++++
>  4 files changed, 16 insertions(+)
> 
> diff --git a/src/libnvme.map b/src/libnvme.map
> index c03a99d1..8710c41f 100644
> --- a/src/libnvme.map
> +++ b/src/libnvme.map
> @@ -9,6 +9,7 @@ LIBNVME_1.9 {
>  		nvme_submit_passthru;
>  		nvme_submit_passthru64;
>  		nvme_update_key;
> +		nvme_ctrl_get_cntlid;
>  };
>  
>  LIBNVME_1_8 {
> diff --git a/src/nvme/private.h b/src/nvme/private.h
> index 11744c25..723740be 100644
> --- a/src/nvme/private.h
> +++ b/src/nvme/private.h
> @@ -86,6 +86,7 @@ struct nvme_ctrl {
>  	char *dhchap_key;
>  	char *dhchap_ctrl_key;
>  	char *cntrltype;
> +	char *cntlid;
>  	char *dctype;
>  	char *phy_slot;
>  	bool discovery_ctrl;
> diff --git a/src/nvme/tree.c b/src/nvme/tree.c
> index 584e3f6a..6efdf992 100644
> --- a/src/nvme/tree.c
> +++ b/src/nvme/tree.c
> @@ -1008,6 +1008,11 @@ const char *nvme_ctrl_get_dhchap_host_key(nvme_ctrl_t c)
>  	return c->dhchap_key;
>  }
>  
> +const char *nvme_ctrl_get_cntlid(nvme_ctrl_t c)
> +{
> +	return c->cntlid;
> +}
> +
>  void nvme_ctrl_set_dhchap_host_key(nvme_ctrl_t c, const char *key)
>  {
>  	if (c->dhchap_key) {
> @@ -1117,6 +1122,7 @@ void nvme_deconfigure_ctrl(nvme_ctrl_t c)
>  	FREE_CTRL_ATTR(c->address);
>  	FREE_CTRL_ATTR(c->dctype);
>  	FREE_CTRL_ATTR(c->cntrltype);
> +	FREE_CTRL_ATTR(c->cntlid);
>  	FREE_CTRL_ATTR(c->phy_slot);
>  }
>  
> @@ -1800,6 +1806,7 @@ static int nvme_configure_ctrl(nvme_root_t r, nvme_ctrl_t c, const char *path,
>  		}
>  	}
>  	c->cntrltype = nvme_get_ctrl_attr(c, "cntrltype");
> +	c->cntlid = nvme_get_ctrl_attr(c, "cntlid");
>  	c->dctype = nvme_get_ctrl_attr(c, "dctype");
>  	c->phy_slot = nvme_ctrl_lookup_phy_slot(r, c->address);
>  
> diff --git a/src/nvme/tree.h b/src/nvme/tree.h
> index a30e8eb7..1d635baa 100644
> --- a/src/nvme/tree.h
> +++ b/src/nvme/tree.h
> @@ -1025,6 +1025,13 @@ const char *nvme_ctrl_get_host_iface(nvme_ctrl_t c);
>   */
>  const char *nvme_ctrl_get_dhchap_host_key(nvme_ctrl_t c);
>  
> +/**
> + *  nvme_ctrl_get_cntlid() - Controller id
> + *  @c:	Controller to be checked
> + *
> + *  Return : Controller id of @c
> + */
> +const char *nvme_ctrl_get_cntlid(nvme_ctrl_t c);
>  /**
>   * nvme_ctrl_set_dhchap_host_key() - Set host key
>   * @c:		Host for which the key should be set



More information about the Linux-nvme mailing list