All of lore.kernel.org
 help / color / mirror / Atom feed
From: sagi@grimberg.me (Sagi Grimberg)
Subject: [PATCH 5/3 rfc nvme-cli] fabrics: allow user to retrieve discovery log from existing discovery controller
Date: Thu,  4 Oct 2018 14:23:28 -0700	[thread overview]
Message-ID: <20181004212328.30205-6-sagi@grimberg.me> (raw)
In-Reply-To: <20181004212328.30205-1-sagi@grimberg.me>

Simply allow discover to receive an existing discovery device node name.
Also centralize extraction of controller instance from the controller
name to a common helper.

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

diff --git a/fabrics.c b/fabrics.c
index f5b822902aa2..d937df47b68e 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -173,6 +173,19 @@ static const char *cms_str(__u8 cm)
 
 static int do_discover(char *argstr, bool connect);
 
+static int ctrl_instance(char *device)
+{
+	int ret, instance;
+
+	device = basename(device);
+	ret = sscanf(device, "nvme%d", &instance);
+	if (ret < 0)
+		return ret;
+	if (!ret)
+		return -1;
+	return instance;
+}
+
 static int add_ctrl(const char *argstr)
 {
 	substring_t args[MAX_OPT_ARGS];
@@ -755,7 +768,10 @@ static int do_discover(char *argstr, bool connect)
 	char *dev_name;
 	int instance, numrec = 0, ret;
 
-	instance = add_ctrl(argstr);
+	if (!cfg.device)
+		instance = add_ctrl(argstr);
+	else
+		instance = ctrl_instance(cfg.device);
 	if (instance < 0)
 		return instance;
 
@@ -763,7 +779,7 @@ static int do_discover(char *argstr, bool connect)
 		return errno;
 	ret = nvmf_get_log_page_discovery(dev_name, &log, &numrec);
 	free(dev_name);
-	if (!cfg.persistent)
+	if (!cfg.device && !cfg.persistent)
 		remove_ctrl(instance);
 
 	switch (ret) {
@@ -876,6 +892,7 @@ int discover(const char *desc, int argc, char **argv, bool connect)
 		{"hostnqn",     'q', "LIST", CFG_STRING, &cfg.hostnqn,     required_argument, "user-defined hostnqn (if default not used)" },
 		{"hostid",      'I', "LIST", CFG_STRING, &cfg.hostid,      required_argument, "user-defined hostid (if default not used)"},
 		{"raw",         'r', "LIST", CFG_STRING, &cfg.raw,         required_argument, "raw output file" },
+		{"device",      'd', "LIST", CFG_STRING, &cfg.device, required_argument, "use existing discovery contoller device" },
 		{"keep-alive-tmo",  'k', "LIST", CFG_INT, &cfg.keep_alive_tmo,  required_argument, "keep alive timeout period in seconds" },
 		{"reconnect-delay", 'c', "LIST", CFG_INT, &cfg.reconnect_delay, required_argument, "reconnect timeout period in seconds" },
 		{"ctrl-loss-tmo",   'l', "LIST", CFG_INT, &cfg.ctrl_loss_tmo,   required_argument, "controller loss timeout period in seconds" },
@@ -1020,15 +1037,10 @@ static int disconnect_by_nqn(char *nqn)
 static int disconnect_by_device(char *device)
 {
 	int instance;
-	int ret;
-
-	device = basename(device);
-	ret = sscanf(device, "nvme%d", &instance);
-	if (ret < 0)
-		return ret;
-	if (!ret)
-		return -1;
 
+	instance = ctrl_instance(device);
+	if (instance < 0)
+		return instance;
 	return remove_ctrl(instance);
 }
 
-- 
2.17.1

  parent reply	other threads:[~2018-10-04 21:23 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04 21:23 [PATCH rfc 0/3] add support to discovery async event notifications Sagi Grimberg
2018-10-04 21:23 ` [PATCH rfc 1/3] nvme-fabrics: allow discovery subsystems accept a kato Sagi Grimberg
2018-10-05  5:50   ` Hannes Reinecke
2018-10-04 21:23 ` [PATCH rfc 2/3] nvme: enable aen also for discovery controllers Sagi Grimberg
2018-10-05  5:51   ` Hannes Reinecke
2018-10-04 21:23 ` [PATCH rfc 3/3] nvme: fire discovery log page change events to userspace Sagi Grimberg
2018-10-05  5:51   ` Hannes Reinecke
2018-10-04 21:23 ` [PATCH 4/3 rfc nvme-cli] fabrics: support persistent connections to a discovery controller Sagi Grimberg
2018-10-04 21:23 ` Sagi Grimberg [this message]
2018-10-05  5:50 ` [PATCH rfc 0/3] add support to discovery async event notifications Hannes Reinecke
2018-10-05  7:08   ` Sagi Grimberg
2018-10-05  7:36     ` Hannes Reinecke
2018-10-05 19:34       ` Sagi Grimberg
2018-10-16  1:11         ` Sagi Grimberg
2018-10-16  5:59           ` Hannes Reinecke
2018-10-16 17:59             ` James Smart
2018-10-17 15:29               ` Hannes Reinecke
2018-10-19  0:44                 ` Sagi Grimberg
2018-10-19 16:09                 ` James Smart
2018-10-17  0:38             ` Sagi Grimberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181004212328.30205-6-sagi@grimberg.me \
    --to=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.