fabrics: add hostid option to connect command
PATCH 1/1 fabrics: add hostid option to connect command
Add an option to pass in the hostid either via command line or a new config file /etc/nvme/hostid.
--- fabrics.c | 42 ++++++++++++++++++++++++++++++++++++++++++ linux/nvme.h | 1 + 2 files changed, 43 insertions(+)
fabrics.c +42 -0
@@ -51,6 +51,7 @@ static struct config {char *trsvcid;char *host_traddr;char *hostnqn; +char *hostid;char *nr_io_queues;char *queue_size;char *keep_alive_tmo;
@@ -63,6 +64,7 @@ static struct config {#define PATH_NVME_FABRICS "/dev/nvme-fabrics"#define PATH_NVMF_DISC "/etc/nvme/discovery.conf"#define PATH_NVMF_HOSTNQN "/etc/nvme/hostnqn" +#define PATH_NVMF_HOSTID "/etc/nvme/hostid"#define SYS_NVME "/sys/class/nvme"#define MAX_DISC_ARGS 10
@@ -456,6 +458,29 @@ out:return ret; } +static int nvmf_hostid_file (void ) +{ +FILE *f; +char hostid[NVMF_HOSTID_SIZE ]; +int ret = false; + + f =fopen (PATH_NVMF_HOSTID ,"r" ); +if (f ==NULL ) +return false; + +if (fgets (hostid,sizeof (hostid), f) ==NULL ) + goto out; + + cfg.hostid =strdup (hostid); +if (!cfg.hostid) + goto out; + + ret = true; +out: +fclose (f); +return ret; +} +static int build_options (char *argstr,int max_len) {int len;
@@ -516,6 +541,14 @@ static int build_options(char *argstr, int max_len) max_len -= len; } +if (cfg.hostid ||nvmf_hostid_file ()) { + len =snprintf (argstr, max_len,",hostid=%s" , cfg.hostid); +if (len <0 ) +return -EINVAL ; + argstr += len; + max_len -= len; + } +if (cfg.nr_io_queues) { len =snprintf (argstr, max_len,",nr_io_queues=%s" , cfg.nr_io_queues);
@@ -582,6 +615,13 @@ static int connect_ctrl(struct nvmf_disc_rsp_page_entry *e) p += len; } +if (cfg.hostid) { + len =sprintf (p,",hostid=%s" , cfg.hostid); +if (len <0 ) +return -EINVAL ; + p += len; + } +switch (e->trtype) {case NVMF_TRTYPE_LOOP :/* loop */ len =sprintf (p,",transport=loop" );
@@ -782,6 +822,7 @@ int discover(const char *desc, int argc, char **argv, bool connect) {"trsvcid", 's', "LIST", CFG_STRING, &cfg.trsvcid, required_argument, "transport service id (e.g. IP port)" }, {"host-traddr", 'w', "LIST", CFG_STRING, &cfg.host_traddr, required_argument, "host traddr (e.g. FC WWN's)" }, {"hostnqn", 'q', "LIST", CFG_STRING, &cfg.hostnqn, required_argument, "user-defined hostnqn (if default not used)" }, + {"hostid", 'I', "LIST", CFG_STRING, &cfg.hostid, required_argument, "user-defined hostid (if default not used)"}, {"queue-size", 'Q', "LIST", CFG_STRING, &cfg.queue_size, required_argument, "number of io queue elements to use (default 128)" }, {"raw", 'r', "LIST", CFG_STRING, &cfg.raw, required_argument, "raw output file" }, {NULL},
@@ -815,6 +856,7 @@ int connect(const char *desc, int argc, char **argv) {"trsvcid", 's', "LIST", CFG_STRING, &cfg.trsvcid, required_argument, "transport service id (e.g. IP port)" }, {"host-traddr", 'w', "LIST", CFG_STRING, &cfg.host_traddr, required_argument, "host traddr (e.g. FC WWN's)" }, {"hostnqn", 'q', "LIST", CFG_STRING, &cfg.hostnqn, required_argument, "user-defined hostnqn" }, + {"hostid", 'I', "LIST", CFG_STRING, &cfg.hostid, required_argument, "user-defined hostid (if default not used)"}, {"nr-io-queues", 'i', "LIST", CFG_STRING, &cfg.nr_io_queues, required_argument, "number of io queues to use (default is core count)" }, {"queue-size", 'Q', "LIST", CFG_STRING, &cfg.queue_size, required_argument, "number of io queue elements to use (default 128)" }, {"keep-alive-tmo", 'k', "LIST", CFG_STRING, &cfg.keep_alive_tmo, required_argument, "keep alive timeout period in seconds" },
linux/nvme.h +1 -0
@@ -23,6 +23,7 @@/* However the max length of a qualified name is another size */ #define NVMF_NQN_SIZE 223 +#define NVMF_HOSTID_SIZE 36#define NVMF_TRSVCID_SIZE 32#define NVMF_TRADDR_SIZE 256#define NVMF_TSAS_SIZE 256
Signature · 1 line
2.12.3
Christoph Hellwig
maintainerPATCH 1/1 fabrics: add hostid option to connect command
Quoted 2 lines · Johannes Thumshirn
Add an option to pass in the hostid either via command line or a new config file
/etc/nvme/hostid.
Looks great!
I think we should also add code to generate a default hostid somewhere. I guess we could just uuidgen(1) and drive it from the package? Sagi added a call to genhostnqn to the specfile, so that should go into it as well.
(and it seems like Debian packaging isn't present at all in the package)
PATCH 1/1 fabrics: add hostid option to connect command
Quoted 4 lines · Christoph Hellwig
Quoted 2 lines · Johannes Thumshirn
Add an option to pass in the hostid either via command line or a new config file
/etc/nvme/hostid.
Quoted 8 lines
Looks great!
Reviewed-by Christoph Hellwig <hch at lst.de>I think we should also add code to generate a default hostid somewhere. I guess we could just uuidgen(1) and drive it from the package? Sagi added a call to genhostnqn to the specfile, so that should go into it as well.
sth like:
%postin
uuidgen > /etc/nvme/hostid
should do the trick methinks.
Quoted 2 lines
(and it seems like Debian packaging isn't present at all in the package)
Aren't you a Debian user ;-)
Signature · 6 lines
Johannes Thumshirn Storage jthumshirn at suse.de +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg GF: Felix Imend?rffer, Jane Smithard, Graham Norton HRB 21284 (AG N?rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Christoph Hellwig
maintainerPATCH 1/1 fabrics: add hostid option to connect command
Quoted 4 lines · Johannes Thumshirn
Quoted 2 lines
(and it seems like Debian packaging isn't present at all in the package)
Aren't you a Debian user ;-)
I am. But I just run the newest nvme-cli out of the build directory on my development systems.
PATCH 1/1 fabrics: add hostid option to connect command
Quoted 8 lines · Christoph Hellwig
Quoted 4 lines · Johannes Thumshirn
Quoted 2 lines
(and it seems like Debian packaging isn't present at all in the package)
Aren't you a Debian user ;-)
I am. But I just run the newest nvme-cli out of the build directory on my development systems.
sounds familiar :-D
Signature · 6 lines
Johannes Thumshirn Storage jthumshirn at suse.de +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg GF: Felix Imend?rffer, Jane Smithard, Graham Norton HRB 21284 (AG N?rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850