From: Ming Lin Date: Tue, 7 Jun 2016 15:19:24 +0000 (+0200) Subject: Add option to save discovery raw log to a file X-Git-Tag: v0.8~32 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1ba12fcab578e955e1e30fc95768715c2833ef17;p=users%2Fhch%2Fnvme-cli.git Add option to save discovery raw log to a file root@host:~# nvme discover -t rdma -a 192.168.2.2 -p 1023 -r disc.raw Discovery log is saved to disc.raw Signed-off-by: Ming Lin Tested-by: Armen Baloyan Tested-by: Sagi Grimberg --- diff --git a/fabrics.c b/fabrics.c index ad79017..50dfcd8 100644 --- a/fabrics.c +++ b/fabrics.c @@ -45,6 +45,7 @@ struct config { char *transport; char *traddr; char *trsvcid; + char *raw; } cfg = { 0 }; #define BUF_SIZE 4096 @@ -287,6 +288,28 @@ static void print_discovery_log(struct nvmf_disc_rsp_page_hdr *log, int numrec) } } +static void save_discovery_log(struct nvmf_disc_rsp_page_hdr *log, int numrec) +{ + int fd; + int len, ret; + + fd = open(cfg.raw, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR); + if (fd < 0) { + fprintf(stderr, "failed to open %s: %s\n", cfg.raw, strerror(errno)); + return; + } + + len = sizeof(struct nvmf_disc_rsp_page_hdr) + + numrec * sizeof(struct nvmf_disc_rsp_page_entry); + ret = write(fd, log, len); + if (ret < 0) + fprintf(stderr, "failed to write to %s: %s\n", cfg.raw, strerror(errno)); + else + printf("Discovery log is saved to %s\n", cfg.raw); + + close(fd); +} + static int build_options(char *argstr, int max_len) { int len; @@ -347,6 +370,8 @@ int discover(const char *desc, int argc, char **argv) "transport address" }, {"trsvcid", 's', "LIST", CFG_STRING, &cfg.trsvcid, required_argument, "transport service id (e.g. IP port)" }, + {"raw", 'r', "LIST", CFG_STRING, &cfg.raw, required_argument, + "raw" }, {0}, }; @@ -370,7 +395,10 @@ int discover(const char *desc, int argc, char **argv) switch (ret) { case DISC_OK: - print_discovery_log(log, numrec); + if (cfg.raw) + save_discovery_log(log, numrec); + else + print_discovery_log(log, numrec); break; case DISC_GET_NUMRECS: fprintf(stderr, "Get number of discovery log entries failed.\n");