[PATCH rfc 2/3] fabrics: move connect_args extraction to a dedicated routine
Sagi Grimberg
sagi at grimberg.me
Fri Aug 14 16:42:38 EDT 2020
We will need it to track controllers as we are iterating over
nested discovery log pages recursion.
Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
fabrics.c | 48 +++++++++++++++++++++++++++++++++---------------
1 file changed, 33 insertions(+), 15 deletions(-)
diff --git a/fabrics.c b/fabrics.c
index 17d969b17dd5..6d6b3b5a3ca7 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -360,6 +360,31 @@ cleanup_devices:
return devname;
}
+static struct connect_args *extract_connect_args(char *argstr)
+{
+ struct connect_args *cargs;
+
+ cargs = calloc(1, sizeof(*cargs));
+ if (!cargs)
+ return NULL;
+ cargs->subsysnqn = parse_conn_arg(argstr, ',', conarg_nqn);
+ cargs->transport = parse_conn_arg(argstr, ',', conarg_transport);
+ cargs->traddr = parse_conn_arg(argstr, ',', conarg_traddr);
+ cargs->trsvcid = parse_conn_arg(argstr, ',', conarg_trsvcid);
+ cargs->host_traddr = parse_conn_arg(argstr, ',', conarg_host_traddr);
+ return cargs;
+}
+
+static void free_connect_args(struct connect_args *cargs)
+{
+ free(cargs->subsysnqn);
+ free(cargs->transport);
+ free(cargs->traddr);
+ free(cargs->trsvcid);
+ free(cargs->host_traddr);
+ free(cargs);
+}
+
static int add_ctrl(const char *argstr)
{
substring_t args[MAX_OPT_ARGS];
@@ -1192,14 +1217,11 @@ static int do_discover(char *argstr, bool connect)
int status = 0;
if (cfg.device) {
- struct connect_args cargs;
+ struct connect_args *cargs;
- memset(&cargs, 0, sizeof(cargs));
- cargs.subsysnqn = parse_conn_arg(argstr, ',', conarg_nqn);
- cargs.transport = parse_conn_arg(argstr, ',', conarg_transport);
- cargs.traddr = parse_conn_arg(argstr, ',', conarg_traddr);
- cargs.trsvcid = parse_conn_arg(argstr, ',', conarg_trsvcid);
- cargs.host_traddr = parse_conn_arg(argstr, ',', conarg_host_traddr);
+ cargs = extract_connect_args(argstr);
+ if (!cargs)
+ return -ENOMEM;
/*
* if the cfg.device passed in matches the connect args
@@ -1212,14 +1234,10 @@ static int do_discover(char *argstr, bool connect)
* create a new ctrl.
* endif
*/
- if (!ctrl_matches_connectargs(cfg.device, &cargs))
- cfg.device = find_ctrl_with_connectargs(&cargs);
-
- free(cargs.subsysnqn);
- free(cargs.transport);
- free(cargs.traddr);
- free(cargs.trsvcid);
- free(cargs.host_traddr);
+ if (!ctrl_matches_connectargs(cfg.device, cargs))
+ cfg.device = find_ctrl_with_connectargs(cargs);
+
+ free_connect_args(cargs);
}
if (!cfg.device) {
--
2.25.1
More information about the Linux-nvme
mailing list