[ofa-general] [PATCH] infiniband-diags/saquery: PortInfoRecord query

Sasha Khapyorsky sashak at voltaire.com
Sat Dec 13 12:47:27 PST 2008


PortInfoRecord query implementation. Alias is "PIR" (case insensitive),
usage is [lid]/[port], all is optional.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 infiniband-diags/man/saquery.8 |    2 +-
 infiniband-diags/src/saquery.c |   67 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/infiniband-diags/man/saquery.8 b/infiniband-diags/man/saquery.8
index 5c75c21..82a5fed 100644
--- a/infiniband-diags/man/saquery.8
+++ b/infiniband-diags/man/saquery.8
@@ -105,7 +105,7 @@ for node name map file format.  Only used with the \fB\-O\fR and \fB\-U\fR optio
 Supported query names (and aliases):
  ClassPortInfo (CPI)
  NodeRecord (NR)
- PortInfoRecord (PIR)
+ PortInfoRecord (PIR) [[lid]/[port]]
  SL2VLTableRecord (SL2VL) [[lid]/[in_port]/[out_port]]
  PKeyTableRecord (PKTR) [[lid]/[port]/[block]]
  VLArbitrationTableRecord (VLAR) [[lid]/[port]/[block]]
diff --git a/infiniband-diags/src/saquery.c b/infiniband-diags/src/saquery.c
index e4175c2..1cc4aca 100644
--- a/infiniband-diags/src/saquery.c
+++ b/infiniband-diags/src/saquery.c
@@ -49,6 +49,7 @@
 #define _GNU_SOURCE
 #include <getopt.h>
 
+#include <infiniband/mad.h>
 #include <infiniband/opensm/osm_log.h>
 #include <infiniband/vendor/osm_vendor_api.h>
 #include <infiniband/vendor/osm_vendor_sa_api.h>
@@ -102,6 +103,20 @@ int requested_lid_flag = 0;
 ib_net64_t requested_guid = 0;
 int requested_guid_flag = 0;
 
+static void format_buf(char *in, char *out, unsigned size)
+{
+	unsigned i;
+
+	for (i = 0; i < size - 3 && *in; i++) {
+		*out++ = *in;
+		if (*in++ == '\n' && *in) {
+			*out++ = '\t';
+			*out++ = '\t';
+		}
+	}
+	*out = '\0';
+}
+
 /**
  * Call back for the various record requests.
  */
@@ -297,6 +312,25 @@ static void dump_portinfo_record(void *data)
 	    );
 }
 
+static void dump_one_portinfo_record(void *data)
+{
+	char buf[2048], buf2[4096];
+	ib_portinfo_record_t *pir = data;
+	ib_port_info_t *pi = &pir->port_info;
+
+	mad_dump_portinfo(buf, sizeof(buf), pi, sizeof(*pi));
+
+	format_buf(buf, buf2, sizeof(buf2));
+
+	printf("PortInfoRecord dump:\n"
+		"\tRID:\n"
+		"\t\tEndPortLid..............%u\n"
+		"\t\tPortNum.................0x%x\n"
+		"\t\tReserved................0x%x\n"
+		"\tPortInfo dump:\n\t\t%s",
+		cl_ntoh16(pir->lid), pir->port_num, pir->resv, buf2);
+}
+
 static void dump_multicast_group_record(void *data)
 {
 	char gid_str[INET6_ADDRSTRLEN];
@@ -1089,7 +1123,36 @@ static int query_node_records(const struct query_cmd *q,
 static int query_portinfo_records(const struct query_cmd *q,
 				  osm_bind_handle_t h, int argc, char *argv[])
 {
-	return print_issm_records(h);
+	ib_portinfo_record_t pir;
+	ib_net64_t comp_mask = 0;
+	int lid = 0, port = -1;
+	ib_api_status_t status;
+
+	if (argc > 0)
+		parse_lid_and_ports(h, argv[0], &lid, &port, NULL);
+
+	memset(&pir, 0, sizeof(pir));
+
+	if (lid > 0) {
+		pir.lid = cl_hton16(lid);
+		comp_mask |= IB_PIR_COMPMASK_LID;
+	}
+	if (port >= 0) {
+		pir.port_num = cl_hton16(port);
+		comp_mask |= IB_PIR_COMPMASK_PORTNUM;
+	}
+
+	status = get_any_records(h, IB_MAD_ATTR_PORTINFO_RECORD, 0,
+				 comp_mask, &pir,
+				 ib_get_attr_offset(sizeof(pir)), 0);
+
+	if (status != IB_SUCCESS)
+		return status;
+
+	dump_results(&result, dump_one_portinfo_record);
+	return_mad();
+
+	return 0;
 }
 
 static int query_mcmember_records(const struct query_cmd *q,
@@ -1439,7 +1502,7 @@ static const struct query_cmd query_cmds[] = {
 	{"NodeRecord", "NR", IB_MAD_ATTR_NODE_RECORD,
 	 NULL, query_node_records},
 	{"PortInfoRecord", "PIR", IB_MAD_ATTR_PORTINFO_RECORD,
-	 NULL, query_portinfo_records},
+	 "[[lid]/[port]]", query_portinfo_records},
 	{"SL2VLTableRecord", "SL2VL", IB_MAD_ATTR_SLVL_RECORD,
 	 "[[lid]/[in_port]/[out_port]]", query_sl2vl_records},
 	{"PKeyTableRecord", "PKTR", IB_MAD_ATTR_PKEY_TBL_RECORD,
-- 
1.6.0.4.766.g6fc4a




More information about the general mailing list