linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: sagi@grimberg.me (Sagi Grimberg)
Subject: [PATCH nvme-cli 2/4] fabrics: stringify discover output.
Date: Sun,  7 Aug 2016 15:19:23 +0300	[thread overview]
Message-ID: <1470572365-20674-3-git-send-email-sagi@grimberg.me> (raw)
In-Reply-To: <1470572365-20674-1-git-send-email-sagi@grimberg.me>

Just so we have a nice readable output.

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
 fabrics.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 107 insertions(+), 8 deletions(-)

diff --git a/fabrics.c b/fabrics.c
index 221e34e5e39b..9f99e6175428 100644
--- a/fabrics.c
+++ b/fabrics.c
@@ -63,6 +63,106 @@ static const match_table_t opt_tokens = {
 	{ OPT_ERR,		NULL		},
 };
 
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+static const char * const trtypes[] = {
+	[NVMF_TRTYPE_RDMA]	= "rdma",
+	[NVMF_TRTYPE_FC]	= "fibre-channel",
+	[NVMF_TRTYPE_LOOP]	= "loop",
+};
+
+static inline const char *trtype_str(__u8 trtype)
+{
+	size_t idx = trtype;
+
+	return (idx < ARRAY_SIZE(trtypes) && trtypes[idx]) ?
+			trtypes[idx] : "unrecognized";
+}
+
+static const char * const adrfams[] = {
+	[NVMF_ADDR_FAMILY_PCI]	= "pci",
+	[NVMF_ADDR_FAMILY_IP4]	= "ipv4",
+	[NVMF_ADDR_FAMILY_IP6]	= "ipv6",
+	[NVMF_ADDR_FAMILY_IB]	= "infiniband",
+	[NVMF_ADDR_FAMILY_FC]	= "fibre-channel",
+};
+
+static inline const char *adrfam_str(__u8 adrfam)
+{
+	size_t idx = adrfam;
+
+	return (idx < ARRAY_SIZE(adrfams) && adrfams[idx]) ?
+			adrfams[idx] : "unrecognized";
+}
+
+static const char * const nqntypes[] = {
+	[NVME_NQN_DISC]		= "discovery subsystem",
+	[NVME_NQN_NVME]		= "nvme subsystem",
+};
+
+static inline const char *nqntype_str(__u8 nqntype)
+{
+	size_t idx = nqntype;
+
+	return (idx < ARRAY_SIZE(nqntypes) && nqntypes[idx]) ?
+			nqntypes[idx] : "unrecognized";
+}
+
+static const char * const treqs[] = {
+	[NVMF_TREQ_NOT_SPECIFIED]	= "unspecified transport requirements",
+	[NVMF_TREQ_REQUIRED]		= "required",
+	[NVMF_TREQ_NOT_REQUIRED]	= "not required",
+};
+
+static inline const char *treq_str(__u8 treq)
+{
+	size_t idx = treq;
+
+	return (idx < ARRAY_SIZE(treqs) && treqs[idx]) ?
+			treqs[idx] : "unrecognized";
+}
+
+static const char * const prtypes[] = {
+	[NVMF_RDMA_PRTYPE_NOT_SPECIFIED]	= "not specified",
+	[NVMF_RDMA_PRTYPE_IB]			= "infiniband",
+	[NVMF_RDMA_PRTYPE_ROCE]			= "roce",
+	[NVMF_RDMA_PRTYPE_ROCEV2]		= "roce-v2",
+	[NVMF_RDMA_PRTYPE_IWARP]		= "iwarp",
+};
+
+static inline const char *prtype_str(__u8 prtype)
+{
+	size_t idx = prtype;
+
+	return (idx < ARRAY_SIZE(prtypes) && prtypes[idx]) ?
+			prtypes[idx] : "unrecognized";
+}
+
+static const char * const qptypes[] = {
+	[NVMF_RDMA_QPTYPE_CONNECTED]	= "connected",
+	[NVMF_RDMA_QPTYPE_DATAGRAM]	= "datagram",
+};
+
+static inline const char *qptype_str(__u8 qptype)
+{
+	size_t idx = qptype;
+
+	return (idx < ARRAY_SIZE(qptypes) && qptypes[idx]) ?
+			qptypes[idx] : "unrecognized";
+}
+
+static const char * const cms[] = {
+	[NVMF_RDMA_CMS_RDMA_CM]	= "rdma-cm",
+};
+
+static const char *cms_str(__u8 cm)
+{
+	size_t idx = cm;
+
+	return (idx < ARRAY_SIZE(cms) && cms[idx]) ?
+			cms[idx] : "unrecognized";
+}
+
 static int do_discover(char *argstr, bool connect);
 
 static int add_ctrl(const char *argstr)
@@ -270,10 +370,10 @@ static void print_discovery_log(struct nvmf_disc_rsp_page_hdr *log, int numrec)
 		struct nvmf_disc_rsp_page_entry *e = &log->entries[i];
 
 		printf("=====Discovery Log Entry %d======\n", i);
-		printf("trtype:  %d\n", e->trtype);
-		printf("adrfam:  %d\n", e->adrfam);
-		printf("nqntype: %d\n", e->nqntype);
-		printf("treq:    %d\n", e->treq);
+		printf("trtype:  %s\n", trtype_str(e->trtype));
+		printf("adrfam:  %s\n", adrfam_str(e->adrfam));
+		printf("nqntype: %s\n", nqntype_str(e->nqntype));
+		printf("treq:    %s\n", treq_str(e->treq));
 		printf("portid:  %d\n", e->portid);
 		printf("trsvcid: %s\n", e->trsvcid);
 		printf("subnqn:  %s\n", e->subnqn);
@@ -281,10 +381,9 @@ static void print_discovery_log(struct nvmf_disc_rsp_page_hdr *log, int numrec)
 
 		switch (e->trtype) {
 		case NVMF_TRTYPE_RDMA:
-			printf("rdma_prtype: %d\n", e->tsas.rdma.prtype);
-			printf("rdma_qptype: %d\n", e->tsas.rdma.qptype);
-			printf("rdma_cms:    %d\n", e->tsas.rdma.cms);
-			printf("rdma_pkey: 0x%04x\n", e->tsas.rdma.pkey);
+			printf("rdma_prtype: %s\n", prtype_str(e->tsas.rdma.prtype));
+			printf("rdma_qptype: %s\n", qptype_str(e->tsas.rdma.qptype));
+			printf("rdma_cms:    %s\n", cms_str(e->tsas.rdma.cms));
 			break;
 		}
 	}
-- 
1.9.1

  parent reply	other threads:[~2016-08-07 12:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-07 12:19 [PATCH nvme-cli 0/4] Some useful fabrics patches Sagi Grimberg
2016-08-07 12:19 ` [PATCH nvme-cli 1/4] fabrics: Allow ipv6 address resolution Sagi Grimberg
2016-08-08  6:55   ` Christoph Hellwig
2016-08-08 20:53     ` J Freyensee
2016-08-07 12:19 ` Sagi Grimberg [this message]
2016-08-08  6:59   ` [PATCH nvme-cli 2/4] fabrics: stringify discover output Christoph Hellwig
2016-08-08  8:41     ` Sagi Grimberg
2016-08-07 12:19 ` [PATCH nvme-cli 3/4] fabrics: Remove redundant build_options Sagi Grimberg
2016-08-08  7:01   ` Christoph Hellwig
2016-08-08  8:41     ` Sagi Grimberg
2016-08-07 12:19 ` [PATCH RFC nvme-cli 4/4] fabrics: Allow discover params to come from a conf file Sagi Grimberg
2016-08-08  7:03   ` Christoph Hellwig
2016-08-08  8:45     ` Sagi Grimberg
2016-08-08 21:13   ` J Freyensee

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=1470572365-20674-3-git-send-email-sagi@grimberg.me \
    --to=sagi@grimberg.me \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).