All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/4] infiniband-diags: properly resolve node guids
@ 2011-07-05 19:08 Ira Weiny
       [not found] ` <20110705120815.3cc7d59b.weiny2-i2BcT+NCU+M@public.gmane.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Ira Weiny @ 2011-07-05 19:08 UTC (permalink / raw)
  To: linux-rdma-u79uwXL29TY76Z2rM5mHXA



Signed-off-by: Ira Weiny <weiny2-i2BcT+NCU+M@public.gmane.org>
---
 include/ibdiag_common.h |    3 ++
 src/ibdiag_common.c     |   55 +++++++++++++++++++++++++++++++++++++++++++++++
 src/iblinkinfo.c        |    5 +--
 src/ibqueryerrors.c     |    8 ++----
 4 files changed, 63 insertions(+), 8 deletions(-)

diff --git a/include/ibdiag_common.h b/include/ibdiag_common.h
index 69cddfb..e107a43 100644
--- a/include/ibdiag_common.h
+++ b/include/ibdiag_common.h
@@ -126,4 +126,7 @@ void sa_report_err(int status);
 		comp_mask |= IB_##name##_COMPMASK_##mask; \
 	}
 
+int resolve_node_guid(ib_portid_t *port_id, char *node_guid,
+			struct ibmad_port *ibmad_port);
+
 #endif				/* _IBDIAG_COMMON_H_ */
diff --git a/src/ibdiag_common.c b/src/ibdiag_common.c
index 6d03a43..66dc132 100644
--- a/src/ibdiag_common.c
+++ b/src/ibdiag_common.c
@@ -509,3 +509,58 @@ void sa_report_err(int status)
 	fprintf(stderr, "ERROR: Query result returned 0x%04x, %s%s\n",
 		status, sm_err_str, sa_err_str);
 }
+
+int resolve_node_guid(ib_portid_t *port_id, char *node_guid,
+			struct ibmad_port *ibmad_port)
+{
+	ib_node_record_t nr;
+	ib_node_record_t *found_nr;
+	uint64_t comp_mask = 0;
+	struct sa_query_result result;
+	uint64_t guid = strtoull(node_guid, NULL, 0);
+	bind_handle_t h;
+	int ret = 0;
+
+	if (guid == 0 || guid == ULLONG_MAX)
+		return -EINVAL;
+
+	memset(&nr, 0, sizeof(nr));
+	CHECK_AND_SET_VAL(guid, 64, 0, nr.node_info.node_guid, NR, NODEGUID);
+
+	if (!ibd_timeout)
+		ibd_timeout = MAD_DEF_TIMEOUT_MS;
+
+	h = sa_get_bind_handle();
+	if (!h)
+		return -EIO;
+
+	ret = sa_query(h, IB_MAD_METHOD_GET_TABLE, IB_SA_ATTR_NODERECORD, 0,
+			   cl_hton64(comp_mask), 0, &nr, &result);
+	if (ret) {
+		fprintf(stderr, "Query SA failed: %s\n", ib_get_err_str(ret));
+		ret = -EIO;
+		goto free_bind_handle;
+	}
+
+	if (result.status != IB_SA_MAD_STATUS_SUCCESS) {
+		sa_report_err(result.status);
+		ret = -EIO;
+		goto free_result;
+	}
+
+	if (result.result_cnt > 1)
+		fprintf(stderr, "%s resolved to more than one port.\n",
+			node_guid);
+
+	found_nr = (ib_node_record_t *)sa_get_query_rec(result.p_result_madw,
+							0);
+	guid = cl_ntoh64(found_nr->node_info.port_guid);
+	ret = ib_resolve_guid_via(port_id, &guid, NULL, ibd_timeout,
+				  ibmad_port);
+
+free_result:
+	sa_free_result_mad(&result);
+free_bind_handle:
+	sa_free_bind_handle(h);
+	return ret;
+}
diff --git a/src/iblinkinfo.c b/src/iblinkinfo.c
index 8cf755d..2f69acf 100644
--- a/src/iblinkinfo.c
+++ b/src/iblinkinfo.c
@@ -619,9 +619,8 @@ int main(int argc, char **argv)
 			IBWARN("Failed to resolve %s; attempting full scan\n",
 			       dr_path);
 	} else if (guid_str) {
-		if ((resolved =
-		     ib_resolve_portid_str_via(&port_id, guid_str, IB_DEST_GUID,
-					       NULL, ibmad_port)) < 0)
+		if ((resolved = resolve_node_guid(&port_id, guid_str,
+						  ibmad_port)) < 0)
 			IBWARN("Failed to resolve %s; attempting full scan\n",
 			       guid_str);
 	}
diff --git a/src/ibqueryerrors.c b/src/ibqueryerrors.c
index 1bba0e0..4b59c6f 100644
--- a/src/ibqueryerrors.c
+++ b/src/ibqueryerrors.c
@@ -914,11 +914,9 @@ int main(int argc, char **argv)
 			IBWARN("Failed to resolve %s; attempting full scan",
 			       dr_path);
 	} else if (node_guid_str) {
-		if ((resolved =
-		     ib_resolve_portid_str_via(&portid, node_guid_str,
-					       IB_DEST_GUID, ibd_sm_id,
-					       ibmad_port)) < 0)
-			IBWARN("Failed to resolve %s; attempting full scan",
+		if ((resolved = resolve_node_guid(&portid, node_guid_str,
+						  ibmad_port)) < 0)
+			IBWARN("Failed to resolve %s; attempting full scan\n",
 			       node_guid_str);
 	}
 
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-07-13  5:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-05 19:08 [PATCH 3/4] infiniband-diags: properly resolve node guids Ira Weiny
     [not found] ` <20110705120815.3cc7d59b.weiny2-i2BcT+NCU+M@public.gmane.org>
2011-07-08 21:42   ` Hal Rosenstock
     [not found]     ` <4E1779CE.9030502-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2011-07-08 21:50       ` Jason Gunthorpe
     [not found]         ` <20110708215046.GB10216-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2011-07-08 21:59           ` Hal Rosenstock
     [not found]             ` <4E177DA5.9030600-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2011-07-08 22:29               ` Ira Weiny
     [not found]                 ` <20110708152953.0063fb7b.weiny2-i2BcT+NCU+M@public.gmane.org>
2011-07-08 22:55                   ` Jason Gunthorpe
     [not found]                     ` <20110708225510.GC10216-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2011-07-11 21:06                       ` Ira Weiny
     [not found]                         ` <20110711140602.9ae3943e.weiny2-i2BcT+NCU+M@public.gmane.org>
2011-07-11 21:18                           ` Jason Gunthorpe
     [not found]                             ` <20110711211843.GD10216-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2011-07-12 23:52                               ` Ira Weiny
     [not found]                                 ` <20110712165250.a3cb9d47.weiny2-i2BcT+NCU+M@public.gmane.org>
2011-07-13  5:09                                   ` Jason Gunthorpe
2011-07-11 19:02                   ` Hal Rosenstock

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.