[PATCH rfc 1/3] nvme: add fabrics discovery controller default port number

Sagi Grimberg sagi at grimberg.me
Fri Aug 14 16:42:37 EDT 2020


The IANA port number for a discovery controller is 8009
for NVMe/TCP and 4420 for any NVMe/RDMA port number. So make
sure to fill it and pass it down, it will help us as we
track and match connection arguments for filtering purposes.

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
 common.h     |  3 +++
 fabrics.c    | 17 +++++++++++++++++
 linux/nvme.h |  1 +
 3 files changed, 21 insertions(+)

diff --git a/common.h b/common.h
index aed2a9918b23..1c214a447fd3 100644
--- a/common.h
+++ b/common.h
@@ -9,4 +9,7 @@
 #define min(x, y) ((x) > (y) ? (y) : (x))
 #define max(x, y) ((x) > (y) ? (x) : (y))
 
+#define __stringify_1(x...) #x
+#define __stringify(x...)  __stringify_1(x)
+
 #endif
diff --git a/fabrics.c b/fabrics.c
index 78ed6251f8a6..17d969b17dd5 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -863,6 +863,17 @@ static int build_options(char *argstr, int max_len, bool discover)
 	return 0;
 }
 
+static void discovery_trsvcid(struct config *cfg)
+{
+	if (!strcmp(cfg->transport, "tcp")) {
+		/* Default port for NVMe/TCP discovery controllers */
+		cfg->trsvcid = __stringify(NVME_DISC_IP_PORT);
+	} else if (!strcmp(cfg->transport, "rdma")) {
+		/* Default port for NVMe/RDMA controllers */
+		cfg->trsvcid = __stringify(NVME_RDMA_IP_PORT);
+	}
+}
+
 static bool traddr_is_hostname(struct config *cfg)
 {
 	char addrstr[NVMF_TRADDR_SIZE];
@@ -1320,6 +1331,9 @@ static int discover_from_conf_file(const char *desc, char *argstr,
 				goto out;
 		}
 
+		if (!cfg.trsvcid)
+			discovery_trsvcid(&cfg);
+
 		err = build_options(argstr, BUF_SIZE, true);
 		if (err) {
 			ret = err;
@@ -1392,6 +1406,9 @@ int fabrics_discover(const char *desc, int argc, char **argv, bool connect)
 				goto out;
 		}
 
+		if (!cfg.trsvcid)
+			discovery_trsvcid(&cfg);
+
 		ret = build_options(argstr, BUF_SIZE, true);
 		if (ret)
 			goto out;
diff --git a/linux/nvme.h b/linux/nvme.h
index a7ab85d03067..de2502929ebb 100644
--- a/linux/nvme.h
+++ b/linux/nvme.h
@@ -70,6 +70,7 @@ static inline uint64_t le64_to_cpu(__le64 x)
 #define NVME_DISC_SUBSYS_NAME	"nqn.2014-08.org.nvmexpress.discovery"
 
 #define NVME_RDMA_IP_PORT	4420
+#define NVME_DISC_IP_PORT	8009
 
 #define NVME_NSID_ALL		0xffffffff
 
-- 
2.25.1




More information about the Linux-nvme mailing list