From: jsmart2021@gmail.com (James Smart)
Subject: [PATCH rfc v2 06/10] nvme-cli: Add routine to compare ctrl_list_item to connect args
Date: Thu, 11 Jul 2019 17:31:36 -0700 [thread overview]
Message-ID: <20190712003140.16221-7-jsmart2021@gmail.com> (raw)
In-Reply-To: <20190712003140.16221-1-jsmart2021@gmail.com>
In preparation for searching controllers to match with connect args:
Create a new routine that receives a structure containing connect
arguments and a device name. The routine will build and fill in a
ctrl_list_item for the device and compare its attributes with the
connect arguments. The routine returns true/false on whether they
match.
Routine is defined as a global as a subsequent patch will use it
from the fabrics routines.
Signed-off-by: James Smart <jsmart2021 at gmail.com>
CC: Sagi Grimberg <sagi at grimberg.me>
CC: Hannes Reinecke <hare at suse.com>
---
nvme.c | 40 ++++++++++++++++++++++++++++++++++++++++
nvme.h | 9 +++++++++
2 files changed, 49 insertions(+)
diff --git a/nvme.c b/nvme.c
index 66ba2fc..ef3c61c 100644
--- a/nvme.c
+++ b/nvme.c
@@ -2010,6 +2010,46 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugi
return nvme_status_to_errno(ret, false);
}
+static char *nvme_ctrl_dir = "/sys/class/nvme/";
+
+/*
+ * Given a controller name, create a ctrl_list_item with its
+ * attributes and compare the attributes against the connect args
+ * given.
+ * Return true/false based on whether it matches
+ */
+bool ctrl_matches_connectargs(char *name, struct connect_args *args)
+{
+ struct ctrl_list_item *ctrl;
+ bool found = false;
+
+ ctrl = malloc(sizeof(*ctrl));
+ if (!ctrl) {
+ fprintf(stderr, "Failed to allocate controller list element\n");
+ return false;
+ }
+ memset(ctrl, 0, sizeof(*ctrl));
+
+ if (get_nvme_ctrl_info(name, nvme_ctrl_dir, ctrl, NVME_NSID_ALL))
+ goto cleanup_exit;
+
+ if (!strcmp(ctrl->subsysnqn, args->subsysnqn) &&
+ !strcmp(ctrl->transport, args->transport) &&
+ (!strcmp(ctrl->traddr, args->traddr) ||
+ !strcmp(args->traddr, "none")) &&
+ (!strcmp(ctrl->trsvcid, args->trsvcid) ||
+ !strcmp(args->trsvcid, "none")) &&
+ (!strcmp(ctrl->host_traddr, args->host_traddr) ||
+ !strcmp(args->host_traddr, "none")))
+ found = true;
+
+cleanup_exit:
+ free_ctrl_list_item(ctrl);
+ free(ctrl);
+
+ return found;
+}
+
int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, void (*vs)(__u8 *vs, struct json_object *root))
{
const char *desc = "Send an Identify Controller command to "\
diff --git a/nvme.h b/nvme.h
index 470f702..537b8dd 100644
--- a/nvme.h
+++ b/nvme.h
@@ -179,6 +179,15 @@ enum {
BINARY,
};
+struct connect_args {
+ char *subsysnqn;
+ char *transport;
+ char *traddr;
+ char *trsvcid;
+ char *host_traddr;
+};
+
+bool ctrl_matches_connectargs(char *name, struct connect_args *args);
char *__parse_connect_arg(char *conargs, const char delim, const char *fieldnm);
extern const char *conarg_traddr;
--
2.13.7
next prev parent reply other threads:[~2019-07-12 0:31 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-12 0:31 [PATCH rfc v2 00/10] nvme-cli: nvmf auto-connect scripts James Smart
2019-07-12 0:31 ` [PATCH rfc v2 01/10] nvme-cli: ignore arguments that pass in "none" James Smart
2019-07-12 0:31 ` [PATCH rfc v2 02/10] nvme-cli: support persistent connections to a discovery controller James Smart
2019-07-12 0:31 ` [PATCH rfc v2 03/10] nvme-cli: allow discover to address discovery controller by persistent name James Smart
2019-07-12 1:34 ` Minwoo Im
2019-07-12 12:41 ` Hannes Reinecke
2019-07-12 16:37 ` Sagi Grimberg
2019-07-12 0:31 ` [PATCH rfc v2 04/10] nvme-cli: Refactor to create a get_nvme_ctrl_info routine James Smart
2019-07-12 0:50 ` Sagi Grimberg
2019-07-12 6:20 ` Hannes Reinecke
2019-07-12 0:31 ` [PATCH rfc v2 05/10] nvme-cli: extend ctrl_list_item for connect attributes James Smart
2019-07-12 0:47 ` Sagi Grimberg
2019-07-16 0:11 ` James Smart
2019-07-16 1:13 ` Sagi Grimberg
2019-07-12 6:24 ` Hannes Reinecke
2019-07-12 0:31 ` James Smart [this message]
2019-07-12 0:49 ` [PATCH rfc v2 06/10] nvme-cli: Add routine to compare ctrl_list_item to connect args Sagi Grimberg
2019-07-12 6:25 ` Hannes Reinecke
2019-07-12 0:31 ` [PATCH rfc v2 07/10] nvme-cli: Add routine to search for controller with specific attributes James Smart
2019-07-12 0:50 ` Sagi Grimberg
2019-07-12 6:28 ` Hannes Reinecke
2019-07-12 0:31 ` [PATCH rfc v2 08/10] nvme-cli: Expand --device argument processing James Smart
2019-07-12 0:51 ` Sagi Grimberg
2019-07-12 14:10 ` Hannes Reinecke
2019-07-12 0:31 ` [PATCH rfc v2 09/10] nvme-cli: add --quiet option James Smart
2019-07-12 17:35 ` Sagi Grimberg
2019-07-14 14:49 ` James Smart
2019-07-15 23:34 ` James Smart
2019-07-12 0:31 ` [PATCH rfc v2 10/10] nvme-cli: nvmf auto-connect scripts James Smart
2019-07-12 0:42 ` Sagi Grimberg
2019-07-12 17:26 ` Sagi Grimberg
2019-07-14 14:47 ` James Smart
2019-07-15 17:20 ` Sagi Grimberg
2019-07-12 17:55 ` Sagi Grimberg
2019-07-14 14:49 ` James Smart
2019-07-12 17:58 ` Sagi Grimberg
2019-07-14 14:57 ` James Smart
2019-07-15 17:21 ` Sagi Grimberg
2019-07-15 19:04 ` James Smart
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=20190712003140.16221-7-jsmart2021@gmail.com \
--to=jsmart2021@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox