[PATCH 2/4] nvme: add host symbolic name

Hannes Reinecke hare at suse.de
Thu Jan 27 01:18:54 PST 2022


On 1/25/22 15:59, Martin Belanger wrote:
> From: Martin Belanger <martin.belanger at dell.com>
> 
> TP8010 introduces the 'host symbolic name' as an optional
> parameter for explicit registration with a central discovery
> controller.
> 
> Signed-off-by: Martin Belanger <martin.belanger at dell.com>
> ---
>   drivers/nvme/host/core.c    | 14 ++++++++++++++
>   drivers/nvme/host/fabrics.c | 17 +++++++++++++++--
>   drivers/nvme/host/fabrics.h |  2 ++
>   include/linux/nvme.h        |  2 ++
>   4 files changed, 33 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index cd34b92e8e9d..cf5d9984f8f6 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3404,6 +3404,16 @@ static ssize_t nvme_sysfs_show_hostnqn(struct device *dev,
>   }
>   static DEVICE_ATTR(hostnqn, S_IRUGO, nvme_sysfs_show_hostnqn, NULL);
>   
> +static ssize_t nvme_sysfs_show_hostsymname(struct device *dev,
> +					struct device_attribute *attr,
> +					char *buf)
> +{
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +
> +	return sysfs_emit(buf, "%s\n", ctrl->opts->host->symname);
> +}
> +static DEVICE_ATTR(hostsymname, S_IRUGO, nvme_sysfs_show_hostsymname, NULL);
> +
>   static ssize_t nvme_sysfs_show_hostid(struct device *dev,
>   					struct device_attribute *attr,
>   					char *buf)
> @@ -3531,6 +3541,7 @@ static struct attribute *nvme_dev_attrs[] = {
>   	&dev_attr_sqsize.attr,
>   	&dev_attr_hostnqn.attr,
>   	&dev_attr_hostid.attr,
> +	&dev_attr_hostsymname.attr,
>   	&dev_attr_ctrl_loss_tmo.attr,
>   	&dev_attr_reconnect_delay.attr,
>   	&dev_attr_fast_io_fail_tmo.attr,
> @@ -3553,6 +3564,9 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
>   		return 0;
>   	if (a == &dev_attr_hostid.attr && !ctrl->opts)
>   		return 0;
> +	if (a == &dev_attr_hostsymname.attr &&
> +	    (!ctrl->opts || (ctrl->opts->host->symname[0] == '\0')))
> +		return 0;
>   	if (a == &dev_attr_ctrl_loss_tmo.attr && !ctrl->opts)
>   		return 0;
>   	if (a == &dev_attr_reconnect_delay.attr && !ctrl->opts)
> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
> index 7ae041e2b3fb..040a6cce6afa 100644
> --- a/drivers/nvme/host/fabrics.c
> +++ b/drivers/nvme/host/fabrics.c
> @@ -540,6 +540,7 @@ static const match_table_t opt_tokens = {
>   	{ NVMF_OPT_HOST_TRADDR,		"host_traddr=%s"	},
>   	{ NVMF_OPT_HOST_IFACE,		"host_iface=%s"		},
>   	{ NVMF_OPT_HOST_ID,		"hostid=%s"		},
> +	{ NVMF_OPT_SYMNAME,		"hostsymname=%s"	},
>   	{ NVMF_OPT_DUP_CONNECT,		"duplicate_connect"	},
>   	{ NVMF_OPT_DISABLE_SQFLOW,	"disable_sqflow"	},
>   	{ NVMF_OPT_HDR_DIGEST,		"hdr_digest"		},
> @@ -556,7 +557,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
>   		const char *buf)
>   {
>   	substring_t args[MAX_OPT_ARGS];
> -	char *options, *o, *p;
> +	char *options, *o, *p, *hostsymname = NULL;
>   	int token, ret = 0;
>   	size_t nqnlen  = 0;
>   	int ctrl_loss_tmo = NVMF_DEF_CTRL_LOSS_TMO;
> @@ -830,6 +831,13 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
>   		case NVMF_OPT_DISCOVERY:
>   			opts->discovery_nqn = true;
>   			break;
> +		case NVMF_OPT_SYMNAME:
> +			hostsymname = match_strdup(args);
> +			if (!hostsymname) {
> +				ret = -ENOMEM;
> +				goto out;
> +			}
> +			break;
>   		default:
>   			pr_warn("unknown parameter or missing value '%s' in ctrl creation request\n",
>   				p);
> @@ -864,8 +872,13 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
>   
>   	uuid_copy(&opts->host->id, &hostid);
>   
> +	if (hostsymname)
> +		strncpy(opts->host->symname, hostsymname,
> +			sizeof(opts->host->symname) - 1);
> +
>   out:
>   	kfree(options);
> +	kfree(hostsymname);
>   	return ret;
>   }
>   
> @@ -957,7 +970,7 @@ EXPORT_SYMBOL_GPL(nvmf_free_options);
>   				 NVMF_OPT_KATO | NVMF_OPT_HOSTNQN | \
>   				 NVMF_OPT_HOST_ID | NVMF_OPT_DUP_CONNECT |\
>   				 NVMF_OPT_DISABLE_SQFLOW | NVMF_OPT_DISCOVERY |\
> -				 NVMF_OPT_FAIL_FAST_TMO)
> +				 NVMF_OPT_FAIL_FAST_TMO | NVMF_OPT_SYMNAME)
>   
>   static struct nvme_ctrl *
>   nvmf_create_ctrl(struct device *dev, const char *buf)
> diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
> index c3203ff1c654..494e6dbe233a 100644
> --- a/drivers/nvme/host/fabrics.h
> +++ b/drivers/nvme/host/fabrics.h
> @@ -38,6 +38,7 @@ struct nvmf_host {
>   	struct list_head	list;
>   	char			nqn[NVMF_NQN_SIZE];
>   	uuid_t			id;
> +	char			symname[NVMF_HOSTSYMNAME_SIZE+1];
>   };
>   
>   /**
> @@ -68,6 +69,7 @@ enum {
>   	NVMF_OPT_FAIL_FAST_TMO	= 1 << 20,
>   	NVMF_OPT_HOST_IFACE	= 1 << 21,
>   	NVMF_OPT_DISCOVERY	= 1 << 22,
> +	NVMF_OPT_SYMNAME	= 1 << 23,
>   };
>   
>   /**
> diff --git a/include/linux/nvme.h b/include/linux/nvme.h
> index 82567d493c51..3b47951342f4 100644
> --- a/include/linux/nvme.h
> +++ b/include/linux/nvme.h
> @@ -16,6 +16,8 @@
>   /* However the max length of a qualified name is another size */
>   #define NVMF_NQN_SIZE		223
>   
> +#define NVMF_HOSTSYMNAME_SIZE	256
> +
>   #define NVMF_TRSVCID_SIZE	32
>   #define NVMF_TRADDR_SIZE	256
>   #define NVMF_TSAS_SIZE		256

Reviewed-by: Hannes Reinecke <hare at suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		           Kernel Storage Architect
hare at suse.de			                  +49 911 74053 688
SUSE Software Solutions Germany GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), GF: Felix Imendörffer



More information about the Linux-nvme mailing list