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

Sagi Grimberg sagi at grimberg.me
Mon Jul 24 02:20:17 PDT 2023


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,
 			u32 io_queues[HCTX_MAX_TYPES]);
 void nvmf_map_queues(struct blk_mq_tag_set *set, struct nvme_ctrl *ctrl,
-- 
2.41.0




More information about the Linux-nvme mailing list