support ip resolution with hostnames
Sagi Grimberg
maintainercover support ip resolution with hostnames
People hate IP addresses, that's why DNS exist. This simple patch allows the user to connect to fabric device using a --hostname parameter instead of a --traddr to make peoples' lives a little more convinient (consider this nvme-cli small contribution to the covid19 battle).
Sagi Grimberg (2):
fabrics: add fabrics_ prefix to fabrics operations
fabrics: allow user to pass hostname instead of traddr
fabrics.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- fabrics.h | 8 +++--- nvme.c | 10 +++---- 3 files changed, 88 insertions(+), 13 deletions(-)
Signature · 7 lines
2.20.1 _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRFC PATCH 1/2 fabrics: add fabrics_ prefix to fabrics operations
discover/connect/disconnect are generic names which might clash with other external included libraries.
--- fabrics.c | 8 ++++---- fabrics.h | 8 ++++---- nvme.c | 10 +++++----- 3 files changed, 13 insertions(+), 13 deletions(-)
fabrics.c +4 -4
@@ -1251,7 +1251,7 @@ out:return ret; } -int discover (const char *desc,int argc,char **argv,bool connect) +int fabrics_discover (const char *desc,int argc,char **argv,bool connect) {char argstr[BUF_SIZE ];int ret;
@@ -1306,7 +1306,7 @@ out:return nvme_status_to_errno (ret, true); } -int connect (const char *desc,int argc,char **argv) +int fabrics_connect (const char *desc,int argc,char **argv) {char argstr[BUF_SIZE ];int instance, ret;
@@ -1439,7 +1439,7 @@ static int disconnect_by_device(char *device)return remove_ctrl (instance); } -int disconnect (const char *desc,int argc,char **argv) +int fabrics_disconnect (const char *desc,int argc,char **argv) {const char *nqn ="nqn name" ;const char *device ="nvme device" ;
@@ -1484,7 +1484,7 @@ out:return nvme_status_to_errno (ret, true); } -int disconnect_all (const char *desc,int argc,char **argv) +int fabrics_disconnect_all (const char *desc,int argc,char **argv) {struct nvme_topology t = { };int i, j, err;
fabrics.h +4 -4
@@ -5,9 +5,9 @@extern char *hostnqn_read (void ); -extern int discover (const char *desc,int argc,char **argv,bool connect); -extern int connect (const char *desc,int argc,char **argv); -extern int disconnect (const char *desc,int argc,char **argv); -extern int disconnect_all (const char *desc,int argc,char **argv); +extern int fabrics_discover (const char *desc,int argc,char **argv,bool connect); +extern int fabrics_connect (const char *desc,int argc,char **argv); +extern int fabrics_disconnect (const char *desc,int argc,char **argv); +extern int fabrics_disconnect_all (const char *desc,int argc,char **argv);#endif
nvme.c +5 -5
@@ -4779,31 +4779,31 @@ static int show_hostnqn_cmd(int argc, char **argv, struct command *command, strustatic int discover_cmd (int argc,char **argv,struct command *command,struct plugin *plugin) {const char *desc ="Send Get Log Page request to Discovery Controller." ; -return discover (desc, argc, argv, false); +return fabrics_discover (desc, argc, argv, false); }static int connect_all_cmd (int argc,char **argv,struct command *command,struct plugin *plugin) {const char *desc ="Discover NVMeoF subsystems and connect to them" ; -return discover (desc, argc, argv, true); +return fabrics_discover (desc, argc, argv, true); }static int connect_cmd (int argc,char **argv,struct command *command,struct plugin *plugin) {const char *desc ="Connect to NVMeoF subsystem" ; -return connect (desc, argc, argv); +return fabrics_connect (desc, argc, argv); }static int disconnect_cmd (int argc,char **argv,struct command *command,struct plugin *plugin) {const char *desc ="Disconnect from NVMeoF subsystem" ; -return disconnect (desc, argc, argv); +return fabrics_disconnect (desc, argc, argv); }static int disconnect_all_cmd (int argc,char **argv,struct command *command,struct plugin *plugin) {const char *desc ="Disconnect from all connected NVMeoF subsystems" ; -return disconnect_all (desc, argc, argv); +return fabrics_disconnect_all (desc, argc, argv); }void register_extension (struct plugin *plugin)
Signature · 7 lines
2.20.1 _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRFC PATCH 2/2 fabrics: allow user to pass hostname instead of traddr
In reply to Sagi GrimbergSome users would like to use well known hostnames instead of remembering ip addresses. So, allow users to pass --hostname and we will attempt to resolve against the DNS.
--- fabrics.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
fabrics.c +75 -0
@@ -33,6 +33,10 @@#include <sys/stat.h> #include <stddef.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <netdb.h> +#include "util/parser.h" #include "nvme-ioctl.h" #include "nvme-status.h"
@@ -60,6 +64,7 @@ static struct config {char *nqn;char *transport;char *traddr; +char *hostname;char *trsvcid;char *host_traddr;char *hostnqn;
@@ -857,6 +862,54 @@ static int build_options(char *argstr, int max_len, bool discover)return 0 ; } +static int hostname2traddr (struct config *cfg) +{ +struct addrinfo *host_info, hints = {.ai_family =AF_UNSPEC }; +char addrstr[NVMF_TRADDR_SIZE ]; +const char *p; +int ret; + +if (cfg->traddr) { +fprintf (stderr,"hostname and traddr cannot be passed together\n" ); +return -EINVAL ; + } + + ret =getaddrinfo (cfg->hostname,NULL , &hints, &host_info); +if (ret) { +fprintf (stderr,"failed to get host info for %s\n" , cfg->hostname); +return ret; + } + +switch (host_info->ai_family) { +case AF_INET : + p =inet_ntop (host_info->ai_family, + &(((struct sockaddr_in *)host_info->ai_addr)->sin_addr), + addrstr,NVMF_TRADDR_SIZE ); +break ; +case AF_INET6 : + p =inet_ntop (host_info->ai_family, + &(((struct sockaddr_in6 *)host_info->ai_addr)->sin6_addr), + addrstr,NVMF_TRADDR_SIZE ); +break ; +default : +fprintf (stderr,"unrecognized address family (%d) %s\n" , + host_info->ai_family, cfg->hostname); + ret = -EINVAL ; + goto free_addrinfo; + } + +if (!p) { +fprintf (stderr,"failed to get traddr for %s\n" , cfg->hostname); + ret = -errno; + goto free_addrinfo; + } + cfg->traddr =strdup (addrstr); + +free_addrinfo: +freeaddrinfo (host_info); +return ret; +} +static int connect_ctrl (struct nvmf_disc_rsp_page_entry *e) {char argstr[BUF_SIZE ], *p;
@@ -1230,6 +1283,13 @@ static int discover_from_conf_file(const char *desc, char *argstr,if (cfg.persistent && !cfg.keep_alive_tmo) cfg.keep_alive_tmo =NVMF_DEF_DISC_TMO ; +if (cfg.hostname) { + ret =hostname2traddr (&cfg); +if (ret) + goto out; + cfg.hostname =NULL ; + } + err =build_options (argstr,BUF_SIZE , true);if (err) { ret = err;
@@ -1259,6 +1319,7 @@ int fabrics_discover(const char *desc, int argc, char **argv, bool connect)OPT_ARGS (opts) = {OPT_LIST ("transport" ,'t' , &cfg.transport,"transport type" ),OPT_LIST ("traddr" ,'a' , &cfg.traddr,"transport address" ), +OPT_LIST ("hostname" ,'A' , &cfg.hostname,"transport address in a hostname form" ),OPT_LIST ("trsvcid" ,'s' , &cfg.trsvcid,"transport service id (e.g. IP port)" ),OPT_LIST ("host-traddr" ,'w' , &cfg.host_traddr,"host traddr (e.g. FC WWN's)" ),OPT_LIST ("hostnqn" ,'q' , &cfg.hostnqn,"user-defined hostnqn (if default not used)" ),
@@ -1295,6 +1356,13 @@ int fabrics_discover(const char *desc, int argc, char **argv, bool connect) }else {if (cfg.persistent && !cfg.keep_alive_tmo) cfg.keep_alive_tmo =NVMF_DEF_DISC_TMO ; + +if (cfg.hostname) { + ret =hostname2traddr (&cfg); +if (ret) + goto out; + } + ret =build_options (argstr,BUF_SIZE , true);if (ret) goto out;
@@ -1315,6 +1383,7 @@ int fabrics_connect(const char *desc, int argc, char **argv)OPT_LIST ("transport" ,'t' , &cfg.transport,"transport type" ),OPT_LIST ("nqn" ,'n' , &cfg.nqn,"nqn name" ),OPT_LIST ("traddr" ,'a' , &cfg.traddr,"transport address" ), +OPT_LIST ("hostname" ,'A' , &cfg.hostname,"transport address in a hostname form" ),OPT_LIST ("trsvcid" ,'s' , &cfg.trsvcid,"transport service id (e.g. IP port)" ),OPT_LIST ("host-traddr" ,'w' , &cfg.host_traddr,"host traddr (e.g. FC WWN's)" ), OPT_LIST("hostnqn", 'q', &cfg.hostnqn, "user-defined hostnqn"),
@@ -1339,6 +1408,12 @@ int fabrics_connect(const char *desc, int argc, char **argv)if (ret) goto out; +if (cfg.hostname) { + ret =hostname2traddr (&cfg); +if (ret) + goto out; + } + ret =build_options (argstr,BUF_SIZE , false);if (ret) goto out;
Signature · 7 lines
2.20.1 _______________________________________________ linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH rfc 2/2] fabrics: allow user to pass hostname instead of traddr
Quoted 88 lines · Sagi Grimberg
Some users would like to use well known hostnames instead of remembering ip addresses. So, allow users to pass --hostname and we will attempt to resolve against the DNS.
Signed-off-by Sagi Grimberg <[email protected]>--- fabrics.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)fabrics.c +53
-0@@ -33,6 +33,10 @@#include <sys/stat.h> #include <stddef.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <netdb.h> +#include "util/parser.h" #include "nvme-ioctl.h" #include "nvme-status.h" @@ -60,6 +64,7 @@ static struct config {char *nqn;char *transport;char *traddr; +char *hostname;char *trsvcid;char *host_traddr;char *hostnqn;@@ -857,6 +862,54 @@ static int build_options(char *argstr, int max_len, bool discover)return 0 ; } +static int hostname2traddr (struct config *cfg) +{ +struct addrinfo *host_info, hints = {.ai_family =AF_UNSPEC }; +char addrstr[NVMF_TRADDR_SIZE ]; +const char *p; +int ret; + +if (cfg->traddr) { +fprintf (stderr,"hostname and traddr cannot be passed together\n" ); +return -EINVAL ; + } + + ret =getaddrinfo (cfg->hostname,NULL , &hints, &host_info); +if (ret) { +fprintf (stderr,"failed to get host info for %s\n" , cfg->hostname); +return ret; + } + +switch (host_info->ai_family) { +case AF_INET : + p =inet_ntop (host_info->ai_family, + &(((struct sockaddr_in *)host_info->ai_addr)->sin_addr), + addrstr,NVMF_TRADDR_SIZE ); +break ; +case AF_INET6 : + p =inet_ntop (host_info->ai_family, + &(((struct sockaddr_in6 *)host_info->ai_addr)->sin6_addr), + addrstr,NVMF_TRADDR_SIZE ); +break ; +default : +fprintf (stderr,"unrecognized address family (%d) %s\n" , + host_info->ai_family, cfg->hostname); + ret = -EINVAL ; + goto free_addrinfo; + } + +if (!p) { +fprintf (stderr,"failed to get traddr for %s\n" , cfg->hostname); + ret = -errno; + goto free_addrinfo; + } + cfg->traddr =strdup (addrstr); + +free_addrinfo: +freeaddrinfo (host_info); +return ret; +} +static int connect_ctrl (struct nvmf_disc_rsp_page_entry *e) {char argstr[BUF_SIZE ], *p;
fabrics.c static int discover_from_conf_file(const char *desc, char *argstr, · line 1292
Quoted 10 lines
fabrics.c +7
-0@@ -1230,6 +1283,13 @@ static int discover_from_conf_file(const char *desc, char *argstr,if (cfg.persistent && !cfg.keep_alive_tmo) cfg.keep_alive_tmo =NVMF_DEF_DISC_TMO ; +if (cfg.hostname) { + ret =hostname2traddr (&cfg); +if (ret) + goto out; + cfg.hostname =NULL ; + } +
I guess you add the NULL to check mutual exclusion later ?
Can we check it in build_options ?
Quoted 12 lines
fabrics.c +1
-0err =build_options (argstr,BUF_SIZE , true);if (err) { ret = err;@@ -1259,6 +1319,7 @@ int fabrics_discover(const char *desc, int argc, char **argv, bool connect)OPT_ARGS (opts) = {OPT_LIST ("transport" ,'t' , &cfg.transport,"transport type" ),OPT_LIST ("traddr" ,'a' , &cfg.traddr,"transport address" ), +OPT_LIST ("hostname" ,'A' , &cfg.hostname,"transport address in a hostname form" ),OPT_LIST ("trsvcid" ,'s' , &cfg.trsvcid,"transport service id (e.g. IP port)" ),OPT_LIST ("host-traddr" ,'w' , &cfg.host_traddr,"host traddr (e.g. FC WWN's)" ),OPT_LIST ("hostnqn" ,'q' , &cfg.hostnqn,"user-defined hostnqn (if default not used)" ),
fabrics.c int fabrics_discover(const char *desc, int argc, char **argv, bool connect) · line 1363
Quoted 8 lines
fabrics.c +5
-0@@ -1295,6 +1356,13 @@ int fabrics_discover(const char *desc, int argc, char **argv, bool connect) }else {if (cfg.persistent && !cfg.keep_alive_tmo) cfg.keep_alive_tmo =NVMF_DEF_DISC_TMO ; + +if (cfg.hostname) { + ret =hostname2traddr (&cfg); +if (ret) + goto out;
please NULLify the hostname for Mutual exclusion check.
Quoted 14 lines
fabrics.c +3
-0+ } + ret =build_options (argstr,BUF_SIZE , true);if (ret) goto out;@@ -1315,6 +1383,7 @@ int fabrics_connect(const char *desc, int argc, char **argv)OPT_LIST ("transport" ,'t' , &cfg.transport,"transport type" ),OPT_LIST ("nqn" ,'n' , &cfg.nqn,"nqn name" ),OPT_LIST ("traddr" ,'a' , &cfg.traddr,"transport address" ), +OPT_LIST ("hostname" ,'A' , &cfg.hostname,"transport address in a hostname form" ),OPT_LIST ("trsvcid" ,'s' , &cfg.trsvcid,"transport service id (e.g. IP port)" ),OPT_LIST ("host-traddr" ,'w' , &cfg.host_traddr,"host traddr (e.g. FC WWN's)" ), OPT_LIST("hostnqn", 'q', &cfg.hostnqn, "user-defined hostnqn"),
fabrics.c int fabrics_connect(const char *desc, int argc, char **argv) · line 1414
Quoted 7 lines
fabrics.c +4
-0@@ -1339,6 +1408,12 @@ int fabrics_connect(const char *desc, int argc, char **argv)if (ret) goto out; +if (cfg.hostname) { + ret =hostname2traddr (&cfg); +if (ret) + goto out;
same here.
fabrics.c int fabrics_connect(const char *desc, int argc, char **argv) · line 1419
Quoted 5 lines
fabrics.c +2
-0+ } + ret =build_options (argstr,BUF_SIZE , false);if (ret) goto out;
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRe: [PATCH rfc 2/2] fabrics: allow user to pass hostname instead of traddr
Quoted 95 lines · Max Gurtovoy
Quoted 93 lines · Sagi Grimberg
Some users would like to use well known hostnames instead of remembering ip addresses. So, allow users to pass --hostname and we will attempt to resolve against the DNS.
Signed-off-by Sagi Grimberg <[email protected]>---
fabrics.c| 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 75 insertions(+)fabrics.c +53
-0@@ -33,6 +33,10 @@ #include <sys/stat.h> #include <stddef.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <netdb.h> + #include "util/parser.h" #include "nvme-ioctl.h" #include "nvme-status.h"@@ -60,6 +64,7 @@ static struct config { char *nqn; char *transport; char *traddr; + char *hostname; char *trsvcid; char *host_traddr; char *hostnqn;@@ -857,6 +862,54 @@ static int build_options(char *argstr, int max_len, bool discover) return 0; } +static int hostname2traddr (struct config *cfg) +{ + struct addrinfo *host_info, hints = {.ai_family = AF_UNSPEC}; + char addrstr[NVMF_TRADDR_SIZE]; + const char *p; + int ret; + + if (cfg->traddr) { + fprintf(stderr, "hostname and traddr cannot be passed together\n"); + return -EINVAL; + } + + ret = getaddrinfo(cfg->hostname, NULL, &hints, &host_info); + if (ret) { + fprintf(stderr, "failed to get host info for %s\n", cfg->hostname); + return ret; + } + + switch (host_info->ai_family) { + case AF_INET: + p = inet_ntop(host_info->ai_family, + &(((struct sockaddr_in *)host_info->ai_addr)->sin_addr), + addrstr, NVMF_TRADDR_SIZE); + break; + case AF_INET6: + p = inet_ntop(host_info->ai_family, + &(((struct sockaddr_in6 *)host_info->ai_addr)->sin6_addr), + addrstr, NVMF_TRADDR_SIZE); + break; + default: + fprintf(stderr, "unrecognized address family (%d) %s\n", + host_info->ai_family, cfg->hostname); + ret = -EINVAL; + goto free_addrinfo; + } + + if (!p) { + fprintf(stderr, "failed to get traddr for %s\n", cfg->hostname); + ret = -errno; + goto free_addrinfo; + } + cfg->traddr = strdup(addrstr); + +free_addrinfo: + freeaddrinfo(host_info); + return ret; +} + static int connect_ctrl(struct nvmf_disc_rsp_page_entry *e){
char argstr[BUF_SIZE], *p;fabrics.c +1
-0@@ -1230,6 +1283,13 @@ static int discover_from_conf_file(const char *desc, char *argstr, if (cfg.persistent && !cfg.keep_alive_tmo) cfg.keep_alive_tmo = NVMF_DEF_DISC_TMO; + if (cfg.hostname) {
Quoted 8 lines
fabrics.c static int discover_from_conf_file(const char *desc, char *argstr, · line 1292
Quoted 6 lines
fabrics.c +6
-0+ ret = hostname2traddr(&cfg); + if (ret) + goto out; + cfg.hostname = NULL; + } +I guess you add the NULL to check mutual exclusion later ?
The NULL assignment here is because we are looping on the conf file entries which can have a different hostname. The other locations are a one-shot so this assignment is not needed.
Quoted 1 line
Can we check it in
build_options?
When we get a hostname we resolve the traddr which is what build_options needs (hostname not an option that is passed to the driver).
Does that answer your question?
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH rfc 2/2] fabrics: allow user to pass hostname instead of traddr
Quoted 113 lines · Sagi Grimberg
Quoted 97 lines · Max Gurtovoy
Quoted 95 lines · Sagi Grimberg
Some users would like to use well known hostnames instead of remembering ip addresses. So, allow users to pass --hostname and we will attempt to resolve against the DNS.
Signed-off-by Sagi Grimberg <[email protected]>---
fabrics.c| 75
+++++++++++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 75 insertions(+)fabrics.c +53
-0@@ -33,6 +33,10 @@ #include <sys/stat.h> #include <stddef.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <netdb.h> + #include "util/parser.h" #include "nvme-ioctl.h" #include "nvme-status.h"@@ -60,6 +64,7 @@ static struct config { char *nqn; char *transport; char *traddr; + char *hostname; char *trsvcid; char *host_traddr; char *hostnqn;@@ -857,6 +862,54 @@ static int build_options(char *argstr, int max_len, bool discover) return 0; } +static int hostname2traddr (struct config *cfg) +{ + struct addrinfo *host_info, hints = {.ai_family = AF_UNSPEC}; + char addrstr[NVMF_TRADDR_SIZE]; + const char *p; + int ret; + + if (cfg->traddr) { + fprintf(stderr, "hostname and traddr cannot be passed together\n"); + return -EINVAL; + } + + ret = getaddrinfo(cfg->hostname, NULL, &hints, &host_info); + if (ret) { + fprintf(stderr, "failed to get host info for %s\n", cfg->hostname); + return ret; + } + + switch (host_info->ai_family) { + case AF_INET: + p = inet_ntop(host_info->ai_family, + &(((struct sockaddr_in *)host_info->ai_addr)->sin_addr), + addrstr, NVMF_TRADDR_SIZE); + break; + case AF_INET6: + p = inet_ntop(host_info->ai_family, + &(((struct sockaddr_in6 *)host_info->ai_addr)->sin6_addr), + addrstr, NVMF_TRADDR_SIZE); + break; + default: + fprintf(stderr, "unrecognized address family (%d) %s\n", + host_info->ai_family, cfg->hostname); + ret = -EINVAL; + goto free_addrinfo; + } + + if (!p) { + fprintf(stderr, "failed to get traddr for %s\n", cfg->hostname); + ret = -errno; + goto free_addrinfo; + } + cfg->traddr = strdup(addrstr); + +free_addrinfo: + freeaddrinfo(host_info); + return ret; +} +static int
connect_ctrl(struct nvmf_disc_rsp_page_entry *e){
char argstr[BUF_SIZE], *p;fabrics.c +1
-0@@ -1230,6 +1283,13 @@ static int discover_from_conf_file(const char *desc, char *argstr, if (cfg.persistent && !cfg.keep_alive_tmo) cfg.keep_alive_tmo = NVMF_DEF_DISC_TMO; + if (cfg.hostname) {Quoted 8 lines
fabrics.c static int discover_from_conf_file(const char *desc, char *argstr, · line 1292
Quoted 6 lines
fabrics.c +6
-0+ ret = hostname2traddr(&cfg); + if (ret) + goto out; + cfg.hostname = NULL; + } +I guess you add the NULL to check mutual exclusion later ?
The NULL assignment here is because we are looping on the conf file entries which can have a different hostname. The other locations are a one-shot so this assignment is not needed.
Quoted 7 lines
Quoted 1 line
Can we check it in
build_options?When we get a hostname we resolve the traddr which is what
build_optionsneeds (hostname not an option that is passed to the driver).Does that answer your question?
I meant to prevent a user to send them both in the command line (no to send it to the driver).
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRe: [PATCH rfc 2/2] fabrics: allow user to pass hostname instead of traddr
Quoted 24 lines
Quoted 24 lines
Quoted 17 lines
Quoted 5 lines
static int
connect_ctrl(struct nvmf_disc_rsp_page_entry *e){
char argstr[BUF_SIZE], *p;fabrics.c static int discover_from_conf_file(const char · line 1292
Quoted 10 lines
fabrics.c +7
-0@@ -1230,6 +1283,13 @@ static int discover_from_conf_file(const char *desc, char *argstr, if (cfg.persistent && !cfg.keep_alive_tmo) cfg.keep_alive_tmo = NVMF_DEF_DISC_TMO; + if (cfg.hostname) { + ret = hostname2traddr(&cfg); + if (ret) + goto out; + cfg.hostname = NULL; + } +I guess you add the NULL to check mutual exclusion later ?
The NULL assignment here is because we are looping on the conf file entries which can have a different hostname. The other locations are a one-shot so this assignment is not needed.
Quoted 1 line
Can we check it in
build_options?
Quoted 7 lines
Quoted 5 lines
When we get a hostname we resolve the traddr which is what
build_optionsneeds (hostname not an option that is passed to the driver).Does that answer your question?
I meant to prevent a user to send them both in the command line (no to send it to the driver).
build_options is just converting options to an argstr, not sure its a good idea to move that there...
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH rfc 2/2] fabrics: allow user to pass hostname instead of traddr
Quoted 28 lines · Sagi Grimberg
Quoted 28 lines
Quoted 28 lines
Quoted 17 lines
Quoted 5 lines
static int
connect_ctrl(struct nvmf_disc_rsp_page_entry *e){
char argstr[BUF_SIZE], *p;fabrics.c static int discover_from_conf_file(const · line 1292
Quoted 10 lines
fabrics.c +7
-0@@ -1230,6 +1283,13 @@ static int discover_from_conf_file(const char *desc, char *argstr, if (cfg.persistent && !cfg.keep_alive_tmo) cfg.keep_alive_tmo = NVMF_DEF_DISC_TMO; + if (cfg.hostname) { + ret = hostname2traddr(&cfg); + if (ret) + goto out; + cfg.hostname = NULL; + } +I guess you add the NULL to check mutual exclusion later ?
The NULL assignment here is because we are looping on the conf file entries which can have a different hostname. The other locations are a one-shot so this assignment is not needed.
Quoted 1 line
Can we check it in
build_options?When we get a hostname we resolve the traddr which is what
build_optionsneeds (hostname not an option that is passed to the driver).
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Does that answer your question?
I meant to prevent a user to send them both in the command line (no to send it to the driver).
build_optionsis just converting options to an argstr, not sure its a good idea to move that there...
You right, I was just thinking out loud.
We can check it before calling the resolution function hostname2traddr.
.
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keith Busch
maintainerRe: [PATCH rfc 2/2] fabrics: allow user to pass hostname instead of traddr
In reply to Sagi GrimbergQuoted 33 lines · Sagi Grimberg
Some users would like to use well known hostnames instead of remembering ip addresses. So, allow users to pass --hostname and we will attempt to resolve against the DNS.
Signed-off-by Sagi Grimberg <[email protected]>--- fabrics.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)fabrics.c +5
-0@@ -33,6 +33,10 @@#include <sys/stat.h> #include <stddef.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <netdb.h> +#include "util/parser.h" #include "nvme-ioctl.h" #include "nvme-status.h" @@ -60,6 +64,7 @@ static struct config {char *nqn;char *transport;char *traddr; +char *hostname;char *trsvcid;char *host_traddr;char *hostnqn;
fabrics.c static int build_options(char *argstr, int max_len, bool discover) · line 863
Quoted 2 lines
fabrics.c +0
-0@@ -857,6 +862,54 @@ static int build_options(char *argstr, int max_len, bool discover)return 0 ; }
The code looks fine.
I realize 'hostname' in this context is referring to the remote host and resolves the target's transport address, but it just sounds potentially confusing given we have "host_traddr". I'm not sure of a better name, though, so if this is normal convention, then okay.
Quoted 111 lines
fabrics.c +70
-0+static int hostname2traddr (struct config *cfg) +{ +struct addrinfo *host_info, hints = {.ai_family =AF_UNSPEC }; +char addrstr[NVMF_TRADDR_SIZE ]; +const char *p; +int ret; + +if (cfg->traddr) { +fprintf (stderr,"hostname and traddr cannot be passed together\n" ); +return -EINVAL ; + } + + ret =getaddrinfo (cfg->hostname,NULL , &hints, &host_info); +if (ret) { +fprintf (stderr,"failed to get host info for %s\n" , cfg->hostname); +return ret; + } + +switch (host_info->ai_family) { +case AF_INET : + p =inet_ntop (host_info->ai_family, + &(((struct sockaddr_in *)host_info->ai_addr)->sin_addr), + addrstr,NVMF_TRADDR_SIZE ); +break ; +case AF_INET6 : + p =inet_ntop (host_info->ai_family, + &(((struct sockaddr_in6 *)host_info->ai_addr)->sin6_addr), + addrstr,NVMF_TRADDR_SIZE ); +break ; +default : +fprintf (stderr,"unrecognized address family (%d) %s\n" , + host_info->ai_family, cfg->hostname); + ret = -EINVAL ; + goto free_addrinfo; + } + +if (!p) { +fprintf (stderr,"failed to get traddr for %s\n" , cfg->hostname); + ret = -errno; + goto free_addrinfo; + } + cfg->traddr =strdup (addrstr); + +free_addrinfo: +freeaddrinfo (host_info); +return ret; +} +static int connect_ctrl (struct nvmf_disc_rsp_page_entry *e) {char argstr[BUF_SIZE ], *p;@@ -1230,6 +1283,13 @@ static int discover_from_conf_file(const char *desc, char *argstr,if (cfg.persistent && !cfg.keep_alive_tmo) cfg.keep_alive_tmo =NVMF_DEF_DISC_TMO ; +if (cfg.hostname) { + ret =hostname2traddr (&cfg); +if (ret) + goto out; + cfg.hostname =NULL ; + } + err =build_options (argstr,BUF_SIZE , true);if (err) { ret = err;@@ -1259,6 +1319,7 @@ int fabrics_discover(const char *desc, int argc, char **argv, bool connect)OPT_ARGS (opts) = {OPT_LIST ("transport" ,'t' , &cfg.transport,"transport type" ),OPT_LIST ("traddr" ,'a' , &cfg.traddr,"transport address" ), +OPT_LIST ("hostname" ,'A' , &cfg.hostname,"transport address in a hostname form" ),OPT_LIST ("trsvcid" ,'s' , &cfg.trsvcid,"transport service id (e.g. IP port)" ),OPT_LIST ("host-traddr" ,'w' , &cfg.host_traddr,"host traddr (e.g. FC WWN's)" ),OPT_LIST ("hostnqn" ,'q' , &cfg.hostnqn,"user-defined hostnqn (if default not used)" ),@@ -1295,6 +1356,13 @@ int fabrics_discover(const char *desc, int argc, char **argv, bool connect) }else {if (cfg.persistent && !cfg.keep_alive_tmo) cfg.keep_alive_tmo =NVMF_DEF_DISC_TMO ; + +if (cfg.hostname) { + ret =hostname2traddr (&cfg); +if (ret) + goto out; + } + ret =build_options (argstr,BUF_SIZE , true);if (ret) goto out;@@ -1315,6 +1383,7 @@ int fabrics_connect(const char *desc, int argc, char **argv)OPT_LIST ("transport" ,'t' , &cfg.transport,"transport type" ),OPT_LIST ("nqn" ,'n' , &cfg.nqn,"nqn name" ),OPT_LIST ("traddr" ,'a' , &cfg.traddr,"transport address" ), +OPT_LIST ("hostname" ,'A' , &cfg.hostname,"transport address in a hostname form" ),OPT_LIST ("trsvcid" ,'s' , &cfg.trsvcid,"transport service id (e.g. IP port)" ),OPT_LIST ("host-traddr" ,'w' , &cfg.host_traddr,"host traddr (e.g. FC WWN's)" ), OPT_LIST("hostnqn", 'q', &cfg.hostnqn, "user-defined hostnqn"),@@ -1339,6 +1408,12 @@ int fabrics_connect(const char *desc, int argc, char **argv)if (ret) goto out; +if (cfg.hostname) { + ret =hostname2traddr (&cfg); +if (ret) + goto out; + } + ret =build_options (argstr,BUF_SIZE , false);if (ret) goto out;Signature · 1 line
2.20.1
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerRe: [PATCH rfc 2/2] fabrics: allow user to pass hostname instead of traddr
Quoted 39 lines
Quoted 34 lines
Some users would like to use well known hostnames instead of remembering ip addresses. So, allow users to pass --hostname and we will attempt to resolve against the DNS.
Signed-off-by Sagi Grimberg <[email protected]>--- fabrics.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)fabrics.c +5
-0@@ -33,6 +33,10 @@#include <sys/stat.h> #include <stddef.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <netdb.h> +#include "util/parser.h" #include "nvme-ioctl.h" #include "nvme-status.h" @@ -60,6 +64,7 @@ static struct config {char *nqn;char *transport;char *traddr; +char *hostname;char *trsvcid;char *host_traddr;char *hostnqn;fabrics.c static int build_options(char *argstr, int max_len, bool discover) · line 863
Quoted 2 lines
fabrics.c +0
-0@@ -857,6 +862,54 @@ static int build_options(char *argstr, int max_len, bool discover)return 0 ; }The code looks fine.
Quoted 4 lines
I realize 'hostname' in this context is referring to the remote host and resolves the target's transport address, but it just sounds potentially confusing given we have "
host_traddr". I'm not sure of a better name, though, so if this is normal convention, then okay.
We could do it like ssh that can accept either IP or hostname (we check if string is IP and if not, resort to name resolution)
Is that preferable?
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keith Busch
maintainerRe: [PATCH rfc 2/2] fabrics: allow user to pass hostname instead of traddr
Quoted 43 lines · Sagi Grimberg
Quoted 38 lines
Quoted 33 lines
Some users would like to use well known hostnames instead of remembering ip addresses. So, allow users to pass --hostname and we will attempt to resolve against the DNS.
Signed-off-by Sagi Grimberg <[email protected]>--- fabrics.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)fabrics.c +5
-0@@ -33,6 +33,10 @@#include <sys/stat.h> #include <stddef.h> +#include <sys/types.h> +#include <arpa/inet.h> +#include <netdb.h> +#include "util/parser.h" #include "nvme-ioctl.h" #include "nvme-status.h" @@ -60,6 +64,7 @@ static struct config {char *nqn;char *transport;char *traddr; +char *hostname;char *trsvcid;char *host_traddr;char *hostnqn;fabrics.c static int build_options(char *argstr, int max_len, bool discover) · line 863
Quoted 2 lines
fabrics.c +0
-0@@ -857,6 +862,54 @@ static int build_options(char *argstr, int max_len, bool discover)return 0 ; }The code looks fine.
Quoted 4 lines
I realize 'hostname' in this context is referring to the remote host and resolves the target's transport address, but it just sounds potentially confusing given we have "
host_traddr". I'm not sure of a better name, though, so if this is normal convention, then okay.
Quoted 4 lines
We could do it like ssh that can accept either IP or hostname (we check if string is IP and if not, resort to name resolution)
Is that preferable?
Yah, that option sounds more appealing to me.
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerNeedless to say that this series is for nvme-cli...
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Sagi Grimberg
maintainerAny other feedback in this approach?
_______________________________________________
linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme