FSTATUS getDestPath(struct oib_port *port, EUI64 destPortGuid, char *cmd, IB_PATH_RECORD *pathp) { FSTATUS fstatus; EUI64 portGuid = -1; QUERY query; PQUERY_RESULT_VALUES pq = NULL; portGuid = oib_get_port_guid(port); memset(&query, 0, sizeof(query)); // initialize reserved fields query.InputType = InputTypePortGuidPair; query.InputValue.PortGuidPair.SourcePortGuid = portGuid; query.InputValue.PortGuidPair.DestPortGuid = destPortGuid; query.OutputType = OutputTypePathRecord; DBGPRINT("Query: Input=%s, Output=%s\n", iba_sd_query_input_type_msg(query.InputType), iba_sd_query_result_type_msg(query.OutputType)); // this call is synchronous fstatus = oib_query_sa(port, &query, &pq); if (! pq) { fprintf(stderr, "%*sSA PathRecord query Failed: %s\n", 0, "", FSTATUS_MSG(fstatus)); goto fail; } else if (pq->Status != FSUCCESS) { fprintf(stderr, "%*sSA PathRecord query Failed: %s MadStatus 0x%x: %s\n", 0, "", FSTATUS_MSG(pq->Status), pq->MadStatus, iba_sd_mad_status_msg(pq->MadStatus)); free(pq); goto fail; } else if (pq->ResultDataSize == 0) { fprintf(stderr, "%*sNo Path Records Returned\n", 0, ""); fstatus = FNOT_FOUND; free(pq); goto fail; } else { PATH_RESULTS *p = (PATH_RESULTS*)pq->QueryResult; DBGPRINT("MadStatus 0x%x: %s\n", pq->MadStatus, iba_sd_mad_status_msg(pq->MadStatus)); DBGPRINT("%d Bytes Returned\n", pq->ResultDataSize); if (p->NumPathRecords == 0) { fprintf(stderr, "%*sNo Path Records Returned\n", 0, ""); fstatus = FNOT_FOUND; goto fail; } *pathp = p->PathRecords[0]; return(FSUCCESS); } fail: return(FERROR); }
// perform the given query and display the results // if portGuid is -1, 1st active port is used to issue query //void do_query(EUI64 portGuid, QUERY *pQuery) void do_query(struct oib_port *port, QUERY *pQuery) { FSTATUS status; PQUERY_RESULT_VALUES pQueryResults = NULL; DBGPRINT("Query: Input=%s (0x%x), Output=%s (0x%x)\n", iba_sd_query_input_type_msg(pQuery->InputType), pQuery->InputType, iba_sd_query_result_type_msg(pQuery->OutputType), pQuery->OutputType); // this call is synchronous status = oib_query_sa(port, pQuery, &pQueryResults); g_exitstatus = PrintQueryResult(&g_dest, 0, &g_dbgDest, pQuery->OutputType, g_CSV, status, pQueryResults); // iba_sd_query_port_fabric_info will have allocated a result buffer // we must free the buffer when we are done with it if (pQueryResults) oib_free_query_result_buffer(pQueryResults); }