From: james_p_freyensee@linux.intel.com (J Freyensee)
Subject: [PATCH v2 nvme-cli 3/4] fabrics: Allow discover params to come from a conf file
Date: Mon, 08 Aug 2016 14:51:14 -0700 [thread overview]
Message-ID: <1470693074.4368.44.camel@linux.intel.com> (raw)
In-Reply-To: <1470657480-5868-4-git-send-email-sagi@grimberg.me>
I missed some things on this patch.
> ?
> ?#define BUF_SIZE 4096
> ?#define PATH_NVME_FABRICS "/dev/nvme-fabrics"
> +#define PATH_NVMF_DISC "/etc/nvme/nvmf_disc"
> +#define MAX_DISC_ARGS 10
> ?
> ?enum {
> ? OPT_INSTANCE,
> @@ -575,6 +577,62 @@ static int do_discover(char *argstr, bool
> connect)
> ? return ret;
> ?}
> ?
> +static int discover_from_conf_file(const char *desc, char *argstr,
> + const struct argconfig_commandline_options *opts, bool
> connect)
> +{
> + FILE *f;
> + char line[255], *ptr, *args, **argv;
Why is line 255 and not 256? ?Maybe want it a #define?
> + int argc, err, ret = 0;
> +
> + f = fopen(PATH_NVMF_DISC, "r");
> + if (f == NULL) {
> + fprintf(stderr, "No discover params given and no %s
> conf\n", PATH_NVMF_DISC);
> + return -EINVAL;
> + }
> +
> + while (fgets(line, sizeof(line), f) != NULL) {
> + if (line[0] == '#' || line[0] == '\n')
> + continue;
> +
> + args = strdup(line);
> + if (!args) {
> + fprintf(stderr, "failed to strdup args\n");
Be useful to print out the line so you know where you failed.
> + return -ENOMEM;
> + }
> +
> + argv = calloc(MAX_DISC_ARGS, BUF_SIZE);
> + if (!argv) {
> + fprintf(stderr, "failed to allocate args
> vector\n");
memory leak from not free'ing args in this case???
Also fprintf() says 'args' not 'argv'. ?And again may be useful to
print out the line of where you failed.
> + return -ENOMEM;
> + }
> +
> + argc = 0;
> + argv[argc++] = "discover";
> + while ((ptr = strsep(&args, " =\n")) != NULL)
> + argv[argc++] = ptr;
> +
> + argconfig_parse(argc, argv, desc, opts, &cfg,
> sizeof(cfg));
> +
> + err = build_options(argstr, BUF_SIZE);
> + if (err) {
> + ret = err;
Again mentioned by Christoph, probably need some diagnostics on why err
didn't get set to 0.
> + continue;
> + }
> +
> + err = do_discover(argstr, connect);
> + if (err) {
> + ret = err;
Same here.
> + continue;
> + }
> +
> + free(args);
> + free(argv);
> + }
> +
> + fclose(f);
> + return ret;
> +}
> +
> ?int discover(const char *desc, int argc, char **argv, bool connect)
> ?{
> ? char argstr[BUF_SIZE];
> @@ -597,11 +655,16 @@ int discover(const char *desc, int argc, char
> **argv, bool connect)
> ?
> ? cfg.nqn = NVME_DISC_SUBSYS_NAME;
> ?
> - ret = build_options(argstr, BUF_SIZE);
> - if (ret)
> - return ret;
> + if (!cfg.transport && !cfg.traddr) {
> + return discover_from_conf_file(desc, argstr,
> + command_line_options, connect);
> + } else {
> + ret = build_options(argstr, BUF_SIZE);
> + if (ret)
same here.
> + return ret;
> ?
> - return do_discover(argstr, connect);
> + return do_discover(argstr, connect);
> + }
> ?}
> ?
> ?int connect(const char *desc, int argc, char **argv)
next prev parent reply other threads:[~2016-08-08 21:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-08 11:57 [PATCH v2 nvme-cli 0/4] Useful fabrics patches Sagi Grimberg
2016-08-08 11:57 ` [PATCH v2 nvme-cli 1/4] fabrics: Allow ipv6 address resolution Sagi Grimberg
2016-08-08 21:17 ` J Freyensee
2016-08-08 11:57 ` [PATCH v2 nvme-cli 2/4] fabrics: stringify discover output Sagi Grimberg
2016-08-08 13:31 ` Christoph Hellwig
2016-08-08 11:57 ` [PATCH v2 nvme-cli 3/4] fabrics: Allow discover params to come from a conf file Sagi Grimberg
2016-08-08 13:35 ` Christoph Hellwig
2016-08-08 21:29 ` J Freyensee
2016-08-09 6:52 ` Sagi Grimberg
2016-08-08 21:51 ` J Freyensee [this message]
2016-08-09 6:58 ` Sagi Grimberg
2016-08-08 11:58 ` [PATCH v2 nvme-cli 4/4] fabrics: Take the hostnqn parameter from a conf file if not given Sagi Grimberg
2016-08-08 13:36 ` Christoph Hellwig
2016-08-08 21:37 ` J Freyensee
2016-08-08 15:36 ` [PATCH v2 nvme-cli 0/4] Useful fabrics patches Keith Busch
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=1470693074.4368.44.camel@linux.intel.com \
--to=james_p_freyensee@linux.intel.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 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.