From patchwork Tue Jul 5 19:08:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 946092 X-Patchwork-Delegate: ira.weiny@intel.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p65J8KLP001594 for ; Tue, 5 Jul 2011 19:08:20 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752504Ab1GETIR (ORCPT ); Tue, 5 Jul 2011 15:08:17 -0400 Received: from nspiron-2.llnl.gov ([128.115.41.82]:64457 "EHLO nspiron-2.llnl.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753344Ab1GETIP (ORCPT ); Tue, 5 Jul 2011 15:08:15 -0400 X-Attachments: None Received: from eris.llnl.gov (HELO trebuchet) ([134.9.2.84]) by nspiron-2.llnl.gov with SMTP; 05 Jul 2011 12:08:15 -0700 Date: Tue, 5 Jul 2011 12:08:15 -0700 From: Ira Weiny To: "linux-rdma@vger.kernel.org" Subject: [PATCH 3/4] infiniband-diags: properly resolve node guids Message-Id: <20110705120815.3cc7d59b.weiny2@llnl.gov> X-Mailer: Sylpheed 3.1.1 (GTK+ 2.18.9; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Tue, 05 Jul 2011 19:08:20 +0000 (UTC) Signed-off-by: Ira Weiny --- 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); }