fabrics: fail early if argconfig_parse failed
Sagi Grimberg
maintainerPATCH 1/2 fabrics: fail early if argconfig_parse failed
If user got params wrong or asked for --help,
we shouldn't try to execute the command.
Signed-off-by Sagi Grimberg <sagi at grimberg.me>
--- fabrics.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
fabrics.c +14 -5
@@ -784,7 +784,9 @@ static int discover_from_conf_file(const char *desc, char *argstr,while ((ptr =strsep (&args," =\n" )) !=NULL ) argv[argc++] = ptr; -argconfig_parse (argc, argv, desc, opts, &cfg,sizeof (cfg)); + err =argconfig_parse (argc, argv, desc, opts, &cfg,sizeof (cfg)); +if (err) +continue ; err =build_options (argstr,BUF_SIZE );if (err) {
@@ -827,8 +829,10 @@ int discover(const char *desc, int argc, char **argv, bool connect) {NULL}, }; -argconfig_parse (argc, argv, desc, command_line_options, &cfg, + ret =argconfig_parse (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); +if (ret) +return ret; cfg.nqn =NVME_DISC_SUBSYS_NAME ;
@@ -865,8 +869,10 @@ int connect(const char *desc, int argc, char **argv) {NULL}, }; -argconfig_parse (argc, argv, desc, command_line_options, &cfg, + ret =argconfig_parse (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); +if (ret) +return ret; ret =build_options (argstr,BUF_SIZE );if (ret)
@@ -971,7 +977,7 @@ int disconnect(const char *desc, int argc, char **argv) {const char *nqn ="nqn name" ;const char *device ="nvme device" ; -int ret =0 ; +int ret;const struct argconfig_commandline_options command_line_options[] = { {"nqn" ,'n' ,"LIST" ,CFG_STRING , &cfg.nqn, required_argument, nqn},
@@ -979,8 +985,11 @@ int disconnect(const char *desc, int argc, char **argv) {NULL}, }; -argconfig_parse (argc, argv, desc, command_line_options, &cfg, + ret =argconfig_parse (argc, argv, desc, command_line_options, &cfg,sizeof (cfg)); +if (ret) +return ret; +if (!cfg.nqn && !cfg.device) {fprintf (stderr,"need a -n or -d argument\n" );return -EINVAL ;
Signature · 1 line
2.14.1
Sagi Grimberg
maintainerPATCH 2/2 fabrics: omit newline character when reading nvme host nqn
This breaks the command string.
Signed-off-by Sagi Grimberg <sagi at grimberg.me>
--- fabrics.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fabrics.c +1 -1
@@ -452,7 +452,7 @@ static int nvmf_hostnqn_file(void)if (fgets (hostnqn,sizeof (hostnqn), f) ==NULL ) goto out; - cfg.hostnqn =strdup (hostnqn); + cfg.hostnqn =strndup (hostnqn,strcspn (hostnqn,"\n" ));if (!cfg.hostnqn) goto out;
Signature · 1 line
2.14.1
Keith Busch
AppliedPATCH 1/2 fabrics: fail early if argconfig_parse failed
In reply to Sagi GrimbergThanks, applied both.