[PATCH nvme-cli] fabrics: restore discover_from_conf_file to actually work

Sagi Grimberg sagi at grimberg.me
Sun Sep 26 11:27:49 PDT 2021


With all the rework, discover_from_conf_file was completely
broken. Have both discover and connect-all working with
params passed from /etc/nvme/discovery.conf

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
 fabrics.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/fabrics.c b/fabrics.c
index b13254683e14..012bcb8819e0 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -299,7 +299,10 @@ static int discover_from_conf_file(nvme_host_t h, const char *desc,
 	char *hostnqn = NULL, *hostid = NULL;
 	char *ptr, **argv, *p, line[4096];
 	int argc, ret = 0;
+	unsigned int verbose = 0;
 	FILE *f;
+	enum nvme_print_flags flags;
+	char *format = "normal";
 
 	struct nvme_fabrics_config cfg = {
 		.tos = -1,
@@ -308,8 +311,18 @@ static int discover_from_conf_file(nvme_host_t h, const char *desc,
 
 	OPT_ARGS(opts) = {
 		NVMF_OPTS(cfg),
+		OPT_FMT("output-format", 'o', &format,        output_format),
+		OPT_FILE("raw",          'r', &raw,           "save raw output to file"),
+		OPT_FLAG("persistent",   'p', &persistent,    "persistent discovery connection"),
+		OPT_FLAG("quiet",        'S', &quiet,         "suppress already connected errors"),
+		OPT_INCR("verbose",      'v', &verbose,       "Increase logging verbosity"),
+		OPT_END()
 	};
 
+	ret = flags = validate_output_format(format);
+	if (ret < 0)
+		return ret;
+
 	f = fopen(PATH_NVMF_DISC, "r");
 	if (f == NULL) {
 		errno = ENOENT;
@@ -340,7 +353,8 @@ static int discover_from_conf_file(nvme_host_t h, const char *desc,
 		ret = argconfig_parse(argc, argv, desc, opts);
 		if (ret)
 			goto next;
-
+		if (persistent && !cfg.keep_alive_tmo)
+			cfg.keep_alive_tmo = 30;
 		if (!transport && !traddr)
 			goto next;
 
@@ -351,8 +365,8 @@ static int discover_from_conf_file(nvme_host_t h, const char *desc,
 		errno = 0;
 		ret = nvmf_add_ctrl(h, c, &cfg, false);
 		if (!ret) {
-			__discover(c, defcfg, NULL, persistent,
-				   connect, 0);
+			__discover(c, &cfg, raw, connect,
+				   persistent, flags);
 			if (!persistent)
 				ret = nvme_disconnect_ctrl(c);
 			nvme_free_ctrl(c);
-- 
2.30.2




More information about the Linux-nvme mailing list