[PATCH rfc 1/6] nvme-fabrics: add helper to resolve ipv4/ipv6 or dns name

Hannes Reinecke hare at suse.de
Thu Aug 10 06:29:46 PDT 2023


On 7/24/23 11:20, Sagi Grimberg wrote:
> Allow userspace to pass in traddr as a dns name as well. This may be
> useful for a discovery service that may have a dns name, that may also
> change in time (with an updated dns record).
> 
> Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
> ---
>   drivers/nvme/host/fabrics.c | 28 ++++++++++++++++++++++++++++
>   drivers/nvme/host/fabrics.h |  2 ++
>   2 files changed, 30 insertions(+)
> 
> diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
> index 8175d49f2909..fadd25538d1b 100644
> --- a/drivers/nvme/host/fabrics.c
> +++ b/drivers/nvme/host/fabrics.c
> @@ -10,6 +10,7 @@
>   #include <linux/mutex.h>
>   #include <linux/parser.h>
>   #include <linux/seq_file.h>
> +#include <linux/dns_resolver.h>
>   #include "nvme.h"
>   #include "fabrics.h"
>   
> @@ -1133,6 +1134,33 @@ bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
>   }
>   EXPORT_SYMBOL_GPL(nvmf_ip_options_match);
>   
> +int nvmf_resolve_ip_address(struct nvmf_ctrl_options *opts,
> +		struct sockaddr_storage *traddr)
> +{
> +	char *traddr_str = NULL;
> +	int traddr_len;
> +	int ret;
> +
> +	/* first check if traddr is ipv4/ipv6 address */
> +	ret = inet_pton_with_scope(&init_net, AF_UNSPEC,
> +			opts->traddr, opts->trsvcid, traddr);
> +	if (!ret)
> +		return ret;
> +
> +	/* second check if traddr is dns name */
> +	traddr_len = dns_query(&init_net, NULL, opts->traddr,
> +			strlen(opts->traddr), NULL, &traddr_str,
> +			NULL, false);
> +	if (traddr_len < 0)
> +		return traddr_len;
> +
> +	ret = inet_pton_with_scope(&init_net, AF_UNSPEC,
> +			traddr_str, opts->trsvcid, traddr);
> +	kfree(traddr_str);
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(nvmf_resolve_ip_address);
> +
>   static int nvmf_check_allowed_opts(struct nvmf_ctrl_options *opts,
>   		unsigned int allowed_opts)
>   {
> diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h
> index 82e7a27ffbde..603d8d176168 100644
> --- a/drivers/nvme/host/fabrics.h
> +++ b/drivers/nvme/host/fabrics.h
> @@ -222,6 +222,8 @@ int nvmf_get_address(struct nvme_ctrl *ctrl, char *buf, int size);
>   bool nvmf_should_reconnect(struct nvme_ctrl *ctrl);
>   bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
>   		struct nvmf_ctrl_options *opts);
> +int nvmf_resolve_ip_address(struct nvmf_ctrl_options *opts,
> +		struct sockaddr_storage *traddr);
>   void nvmf_set_io_queues(struct nvmf_ctrl_options *opts, u32 nr_io_queues,IS
>   			u32 io_queues[HCTX_MAX_TYPES]);
>   void nvmf_map_queues(struct blk_mq_tag_set *set, struct nvme_ctrl *ctrl,

dns resolver is a config option, so we would need either a '#ifdef 
DNS_RESOLVER' or if (IS_ENABLED(CONFIG_DNS_RESOLVER))' somewhere ...

Cheers,

Hannes




More information about the Linux-nvme mailing list