Useful fabrics patches
Sagi Grimberg
maintainerv3 cover Useful fabrics patches
hey keith,
changes from v2:
- read 223 bytes from hostnqn file
- some styling review fixes on the stringify patch
- modified the adrfam statement to a proper switch-case
changes from v1:
- fixed review comments from christoph
- added a patch to take hostnqn from a default conf file if it exists (and a hostnqn param wasn't given, patches by jay and roy)
Sagi Grimberg (4):
fabrics: Allow ipv6 address resolution
fabrics: stringify discover output.
fabrics: Allow discover params to come from a conf file
fabrics: Take the hostnqn parameter from a conf file if not given
common.h | 2 + fabrics.c | 270 +++++++++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 210 insertions(+), 62 deletions(-)
Signature · 1 line
1.9.1
Sagi Grimberg
maintainerPATCH v3 1/4 fabrics: Allow ipv6 address resolution
While we're at it, make the adrfam condition
a proper switch-case statement.
--- fabrics.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
fabrics.c +20 -16
@@ -438,25 +438,29 @@ static int connect_ctrl(struct nvmf_disc_rsp_page_entry *e)/* we can safely ignore the rest of the entries */ break ;case NVMF_TRTYPE_RDMA : -if (e->adrfam !=NVMF_ADDR_FAMILY_IP4 ) { +switch (e->adrfam) { +case NVMF_ADDR_FAMILY_IP4 : +case NVMF_ADDR_FAMILY_IP6 : +/* FALLTHRU */ + len =sprintf (p,",transport=rdma" ); +if (len <0 ) +return -EINVAL ; + p += len; + + len =sprintf (p,",traddr=%s" , e->traddr); +if (len <0 ) +return -EINVAL ; + p += len; + + len =sprintf (p,",trsvcid=%s" , e->trsvcid); +if (len <0 ) +return -EINVAL ; + p += len; +break ; +default :fprintf (stderr,"skipping unsupported adrfam\n" );return -EINVAL ; } - - len =sprintf (p,",transport=rdma" ); -if (len <0 ) -return -EINVAL ; - p += len; - - len =sprintf (p,",traddr=%s" , e->traddr); -if (len <0 ) -return -EINVAL ; - p += len; - - len =sprintf (p,",trsvcid=%s" , e->trsvcid); -if (len <0 ) -return -EINVAL ; - p += len;break ;default : fprintf(stderr, "skipping unsupported transport %d\n",
Signature · 1 line
1.9.1
Sagi Grimberg
maintainerPATCH v3 2/4 fabrics: stringify discover output.
In reply to Sagi GrimbergJust so we have a nice readable output.
--- common.h | 2 + fabrics.c | 133 +++++++++++++++++++++++++++++++++++++++++++------------------- 2 files changed, 94 insertions(+), 41 deletions(-)
common.h +2 -0
@@ -6,4 +6,6 @@#define __round_mask (x, y) ((__typeof__(x))((y)-1))#define round_up (x, y) ((((x)-1) | __round_mask(x, y))+1) +#define ARRAY_SIZE (arr) (sizeof(arr) / sizeof((arr)[0])) +#endif
fabrics.c +92 -41
151 lines not on this page · raw message
Signature · 1 line
1.9.1
Sagi Grimberg
maintainerPATCH v3 3/4 fabrics: Allow discover params to come from a conf file
In reply to Sagi GrimbergAllow the user to just run "nvme discover" or "nvme connect-all" in case it finds a default /etc/nvme/nvmf_disc conf file.
We allow multiple discovery addresses by iterating over the lines of the file and executing a discover (with or without connect) for each line. We allow newlines and '#' prefixed comments.
The return value is or'ed on all discover attempts.
In order to minimize some parsing code, I just convert the file line into an (argc, argv) pair and feed it to argconfig_parse() which dictates that the file lines are identical to what one would pass nvme discover <params>. I'm open to better ideas.
--- fabrics.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 4 deletions(-)
fabrics.c +71 -4
@@ -56,6 +56,8 @@ struct config {#define BUF_SIZE 4096#define PATH_NVME_FABRICS "/dev/nvme-fabrics" +#define PATH_NVMF_DISC "/etc/nvme/discovery.conf" +#define MAX_DISC_ARGS 10enum {OPT_INSTANCE ,
@@ -578,6 +580,66 @@ 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[256 ], *ptr, *args, **argv; +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" ); + ret = -ENOMEM ; + goto out; + } + + argv =calloc (MAX_DISC_ARGS ,BUF_SIZE ); +if (!argv) { +fprintf (stderr,"failed to allocate argv vector\n" ); +free (args); + ret = -ENOMEM ; + goto out; + } + + 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; +continue ; + } + + err =do_discover (argstr, connect); +if (err) { + ret = err; +continue ; + } + +free (args); +free (argv); + } + +out: +fclose (f); +return ret; +} +int discover (const char *desc,int argc,char **argv,bool connect) {char argstr[BUF_SIZE ];
@@ -600,11 +662,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) +return ret; -return do_discover (argstr, connect); +return do_discover (argstr, connect); + } }int connect (const char *desc,int argc,char **argv)
Signature · 1 line
1.9.1
Sagi Grimberg
maintainerPATCH v3 4/4 fabrics: Take the hostnqn parameter from a conf file if not given
In reply to Sagi GrimbergIn order to allow persistent hostnqns, take the hostnqn parameter for /etc/nvme/hostnqn if exists.
--- fabrics.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-)
fabrics.c +25 -1
@@ -57,6 +57,7 @@ struct config {#define BUF_SIZE 4096#define PATH_NVME_FABRICS "/dev/nvme-fabrics"#define PATH_NVMF_DISC "/etc/nvme/discovery.conf" +#define PATH_NVMF_HOSTNQN "/etc/nvme/hostnqn"#define MAX_DISC_ARGS 10enum {
@@ -405,6 +406,29 @@ static void save_discovery_log(struct nvmf_disc_rsp_page_hdr *log, int numrec)close (fd); } +static int nvmf_hostnqn_file (void ) +{ +FILE *f; +char hostnqn[NVMF_NQN_SIZE ]; +int ret = false; + + f =fopen (PATH_NVMF_HOSTNQN ,"r" ); +if (f ==NULL ) +return false; + +if (fgets (hostnqn,sizeof (hostnqn), f) ==NULL ) + goto out; + + cfg.hostnqn =strdup (hostnqn); +if (!cfg.hostnqn) + goto out; + + ret = true; +out: +fclose (f); +return ret; +} +static int build_options (char *argstr,int max_len) {int len;
@@ -449,7 +473,7 @@ static int build_options(char *argstr, int max_len) max_len -= len; } -if (cfg.hostnqn) { +if (cfg.hostnqn ||nvmf_hostnqn_file ()) { len =snprintf (argstr, max_len,",hostnqn=%s" , cfg.hostnqn);if (len <0 )return -EINVAL ;
Signature · 1 line
1.9.1
v3 cover Useful fabrics patches
In reply to Sagi GrimbergQuoted 12 lines · Sagi Grimberg
hey keith,
changes from v2:
- read 223 bytes from hostnqn file
- some styling review fixes on the stringify patch
- modified the adrfam statement to a proper switch-casechanges from v1:
- fixed review comments from christoph
- added a patch to take hostnqn from a default conf file if it exists (and a hostnqn param wasn't given, patches by jay and roy)
Quoted 5 lines
Sagi Grimberg (4):
fabrics: Allow ipv6 address resolution
fabrics: stringify discover output.
fabrics: Allow discover params to come from a conf file
fabrics: Take the hostnqn parameter from a conf file if not given
Thanks, Sagi. All applied and pushed to github.