[PATCH libnvme 2/1] nvme: Add generic connect parameter support detection

Sagi Grimberg sagi at grimberg.me
Wed Sep 7 07:24:09 PDT 2022


When reading from the nvmf misc device, a concatenated string
of all the supported opts is returned. Add a helper that detects
if a parameter string exists in the output.

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
 src/libnvme.map    |  1 +
 src/nvme/fabrics.c | 32 ++++++++++++++++++++++++++++++++
 src/nvme/fabrics.h | 11 +++++++++++
 3 files changed, 44 insertions(+)

diff --git a/src/libnvme.map b/src/libnvme.map
index 79b8f88ecd3a..80fbe218cb9a 100644
--- a/src/libnvme.map
+++ b/src/libnvme.map
@@ -352,6 +352,7 @@ LIBNVME_1_0 {
 		nvmf_treq_str;
 		nvmf_trtype_str;
 		nvmf_update_config;
+		nvmf_check_param_support;
 	local:
 		*;
 };
diff --git a/src/nvme/fabrics.c b/src/nvme/fabrics.c
index d5db5090e30b..678ca2af2561 100644
--- a/src/nvme/fabrics.c
+++ b/src/nvme/fabrics.c
@@ -526,6 +526,38 @@ static int build_options(nvme_host_t h, nvme_ctrl_t c, char **argstr)
 	return 0;
 }
 
+int nvmf_check_param_support(const char *param, bool *supported)
+{
+	int ret = 0, fd, len;
+	char buf[0x1000];
+
+	fd = open(nvmf_dev, O_RDWR);
+	if (fd < 0) {
+		nvme_msg(NULL, LOG_ERR, "Failed to open %s: %s\n",
+			 nvmf_dev, strerror(errno));
+		return -ENVME_CONNECT_OPEN;
+	}
+
+	memset(buf, 0x0, sizeof(buf));
+	len = read(fd, buf, sizeof(buf) - 1);
+	if (len < 0) {
+		nvme_msg(NULL, LOG_ERR, "Failed to read from %s: %s\n",
+			 nvmf_dev, strerror(errno));
+		ret = -ENVME_CONNECT_READ;
+		goto out_close;
+	}
+	nvme_msg(NULL, LOG_DEBUG, "supported opts: '%.*s'\n", (int)strcspn(buf, "\n"), buf);
+	buf[len] = '\0';
+
+	if (strstr(buf, param) != NULL)
+		*supported = true;
+	else
+		*supported = false;
+out_close:
+	close(fd);
+	return ret;
+}
+
 static int __nvmf_add_ctrl(nvme_root_t r, const char *argstr)
 {
 	int ret, fd, len = strlen(argstr);
diff --git a/src/nvme/fabrics.h b/src/nvme/fabrics.h
index 9e099feeeb08..83353a65c5d7 100644
--- a/src/nvme/fabrics.h
+++ b/src/nvme/fabrics.h
@@ -270,4 +270,15 @@ bool nvmf_is_registration_supported(nvme_ctrl_t c);
  */
 int nvmf_register_ctrl(nvme_ctrl_t c, enum nvmf_dim_tas tas, __u32 *result);
 
+/**
+ * nvmf_check_param_support() - Check parameter support from the kernel
+ * @param:	Parameter string
+ * @supported:	Parameter Support indicator
+ *
+ * Read from the misc device the supported parameters and search the @param string
+ *
+ * Return: 0 on success to query; on failure errno is returned
+ */
+int nvmf_check_param_support(const char *param, bool *supported);
+
 #endif /* _LIBNVME_FABRICS_H */
-- 
2.34.1




More information about the Linux-nvme mailing list