>From f46430ec41406db8a6d0c3799d442a16db9ed8c0 Mon Sep 17 00:00:00 2001 From: Ira Weiny <[email protected]> Date: Wed, 22 Apr 2009 18:44:17 -0700 Subject: [PATCH] Convert ibqueryerrors.pl to C and use new ibnetdisc library.
Signed-off-by: Ira Weiny <[email protected]> --- infiniband-diags/Makefile.am | 5 +- infiniband-diags/configure.in | 1 + infiniband-diags/scripts/ibqueryerrors.pl | 230 ------------- infiniband-diags/scripts/ibqueryerrors.pl.in | 40 +++ infiniband-diags/src/ibqueryerrors.c | 469 ++++++++++++++++++++++++++ 5 files changed, 514 insertions(+), 231 deletions(-) delete mode 100755 infiniband-diags/scripts/ibqueryerrors.pl create mode 100755 infiniband-diags/scripts/ibqueryerrors.pl.in create mode 100644 infiniband-diags/src/ibqueryerrors.c diff --git a/infiniband-diags/Makefile.am b/infiniband-diags/Makefile.am index 19b992c..503d573 100644 --- a/infiniband-diags/Makefile.am +++ b/infiniband-diags/Makefile.am @@ -12,7 +12,8 @@ endif sbin_PROGRAMS = src/ibaddr src/ibnetdiscover src/ibping src/ibportstate \ src/ibroute src/ibstat src/ibsysstat src/ibtracert \ src/perfquery src/sminfo src/smpdump src/smpquery \ - src/saquery src/vendstat src/iblinkinfo + src/saquery src/vendstat src/iblinkinfo \ + src/ibqueryerrors if ENABLE_TEST_UTILS sbin_PROGRAMS += src/ibsendtrap src/mcm_rereg_test @@ -59,6 +60,8 @@ src_vendstat_SOURCES = src/vendstat.c src_mcm_rereg_test_SOURCES = src/mcm_rereg_test.c src_iblinkinfo_SOURCES = src/iblinkinfo.c src_iblinkinfo_LDFLAGS = -L$(top_srcdir)/libibnetdisc -libnetdisc +src_ibqueryerrors_SOURCES = src/ibqueryerrors.c +src_ibqueryerrors_LDFLAGS = -L$(top_srcdir)/libibnetdisc -libnetdisc man_MANS = man/ibaddr.8 man/ibcheckerrors.8 man/ibcheckerrs.8 \ man/ibchecknet.8 man/ibchecknode.8 man/ibcheckport.8 \ diff --git a/infiniband-diags/configure.in b/infiniband-diags/configure.in index 4516dfa..ae492b8 100644 --- a/infiniband-diags/configure.in +++ b/infiniband-diags/configure.in @@ -167,6 +167,7 @@ AC_CONFIG_FILES([\ scripts/ibswitches \ scripts/ibrouters \ scripts/iblinkinfo.pl \ + scripts/ibqueryerrors.pl \ libibnetdisc/Makefile ]) AC_OUTPUT diff --git a/infiniband-diags/scripts/ibqueryerrors.pl b/infiniband-diags/scripts/ibqueryerrors.pl deleted file mode 100755 index 99adac7..0000000 --- a/infiniband-diags/scripts/ibqueryerrors.pl +++ /dev/null @@ -1,230 +0,0 @@ -#!/usr/bin/perl -# -# Copyright (c) 2008 Voltaire, Inc. All rights reserved. -# Copyright (c) 2006 The Regents of the University of California. -# -# Produced at Lawrence Livermore National Laboratory. -# Written by Ira Weiny <[email protected]>. -# -# This software is available to you under a choice of one of two -# licenses. You may choose to be licensed under the terms of the GNU -# General Public License (GPL) Version 2, available from the file -# COPYING in the main directory of this source tree, or the -# OpenIB.org BSD license below: -# -# Redistribution and use in source and binary forms, with or -# without modification, are permitted provided that the following -# conditions are met: -# -# - Redistributions of source code must retain the above -# copyright notice, this list of conditions and the following -# disclaimer. -# -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# - -use strict; - -use Getopt::Std; -use IBswcountlimits; - -my $print_action = "no"; -my $report_port_info = undef; -my $single_switch = undef; -my $include_data_counters = undef; -my $cache_file = ""; -my $switch_found = "no"; - -# ========================================================================= -# -sub report_counts -{ - my $addr = $_[0]; - my $port = $_[1]; - my $ca_name = $_[2]; - my $ca_port = $_[3]; - my $extra_params = get_ca_name_port_param_string($ca_name, $ca_port); - - if (any_counts()) { - print(" GUID $addr port $port:"); - check_counters($print_action); - if ($include_data_counters) { - check_data_counters($print_action); - } - print("\n"); - - if ($report_port_info) { - my $lid = ""; - my $speed = ""; - my $width = ""; - my $data = `smpquery $extra_params -G portinfo $addr $port`; - my @lines = split("\n", $data); - foreach my $line (@lines) { - if ($line =~ /^# Port info: Lid (\w+) port.*/) { $lid = $1; } - if ($line =~ /^LinkSpeedActive:\.+(.*)/) { $speed = $1; } - if ($line =~ /^LinkWidthActive:\.+(.*)/) { $width = $1; } - } - my $hr = $IBswcountlimits::link_ends{"$addr"}{$port}; - if ($hr) { - printf( -" Link info: %6s %4s[%2s] ==(%3s %s)==> %18s %4s[%2s] \"%s\"\n", - $lid, $port, - $hr->{loc_ext_port}, $width, - $speed, $hr->{rem_guid}, - $hr->{rem_port}, $hr->{rem_ext_port}, - $hr->{rem_desc} - ); - } else { - printf( -" Link info: %6s %4s[ ] ==(%3s %s)==> (Disconnected)\n", - $lid, $port, $width, $speed); - } - } - } -} - -# ========================================================================= -# use perfquery to get the counters. -sub get_counts -{ - my $addr = $_[0]; - my $port = $_[1]; - my $ca_name = $_[2]; - my $ca_port = $_[3]; - my $extra_params = get_ca_name_port_param_string($ca_name, $ca_port); - - my $data = `perfquery $extra_params -G $addr $port` || - die "'perfquery $extra_params -G $addr $port' FAILED.\n"; - my @lines = split("\n", $data); - foreach my $line (@lines) { - foreach my $count (@IBswcountlimits::counters) { - if ($line =~ /^$count:\.+(\d+)/) { - $IBswcountlimits::cur_counts{$count} = $1; - } - } - } -} - -# ========================================================================= -# -my %switches = (); - -sub get_switches -{ - my $data = `ibswitches $cache_file` || - die "'ibswitches $cache_file' failed.\n"; - my @lines = split("\n", $data); - foreach my $line (@lines) { - if ($line =~ /^Switch\s+:\s+(\w+)\s+ports\s+(\d+)\s+.*/) { - $switches{$1} = $2; - } - } -} - -# ========================================================================= -# -sub usage_and_exit -{ - my $prog = $_[0]; - print -"Usage: $prog [-a -c -r -R -s <err1,err2,...> -S <switch_guid> -D <direct route> -d -C <ca_name> -P <ca_port>]\n"; - print " Report counters on all switches in subnet\n"; - print " -a Report an action to take\n"; - print " -c suppress some of the common counters\n"; - print " -r report port configuration information\n"; - print " -R Recalculate ibnetdiscover information\n"; - print " -s <err1,err2,...> suppress errors listed\n"; - print -" -D <direct route> output only the switch specified by direct route path\n"; - print " -S <switch_guid> query only <switch_guid> (hex format)\n"; - print " -d include the data counters in the output\n"; - print " -C <ca_name> use selected Channel Adaptor name for queries\n"; - print " -P <ca_port> use selected channel adaptor port for queries\n"; - exit 2; -} - -my $argv0 = `basename $0`; -my $regenerate_map = undef; -my $single_switch = undef; -my $direct_route = undef; -my $ca_name = ""; -my $ca_port = ""; - -chomp $argv0; -if (!getopts("has:crRS:D:dC:P:")) { usage_and_exit $argv0; } -if (defined $Getopt::Std::opt_h) { usage_and_exit $argv0; } -if (defined $Getopt::Std::opt_a) { $print_action = "yes"; } -if (defined $Getopt::Std::opt_s) { - @IBswcountlimits::suppress_errors = split(",", $Getopt::Std::opt_s); -} -if (defined $Getopt::Std::opt_c) { - @IBswcountlimits::suppress_errors = split(",", "RcvSwRelayErrors"); -} -if (defined $Getopt::Std::opt_r) { $report_port_info = $Getopt::Std::opt_r; } -if (defined $Getopt::Std::opt_R) { $regenerate_map = $Getopt::Std::opt_R; } -if (defined $Getopt::Std::opt_D) { $direct_route = $Getopt::Std::opt_D; } -if (defined $Getopt::Std::opt_S) { - $single_switch = format_guid($Getopt::Std::opt_S); -} -if (defined $Getopt::Std::opt_d) { - $include_data_counters = $Getopt::Std::opt_d; -} -if (defined $Getopt::Std::opt_C) { $ca_name = $Getopt::Std::opt_C; } -if (defined $Getopt::Std::opt_P) { $ca_port = $Getopt::Std::opt_P; } - -$cache_file = get_cache_file($ca_name, $ca_port); - -sub main -{ - if (@IBswcountlimits::suppress_errors) { - my $msg = join(",", @IBswcountlimits::suppress_errors); - print "Suppressing: $msg\n"; - } - get_link_ends($regenerate_map, $ca_name, $ca_port); - get_switches; - if (defined($direct_route)) { - # convert DR to guid, then use original single_switch option - $single_switch = convert_dr_to_guid($direct_route); - if (!defined($single_switch) || !is_switch($single_switch)) { - printf("The direct route (%s) does not map to a switch.\n", - $direct_route); - return; - } - } - foreach my $sw_addr (keys %switches) { - if ($single_switch && $sw_addr ne "$single_switch") { - next; - } else { - $switch_found = "yes"; - } - - my $switch_prompt = "no"; - foreach my $sw_port (1 .. $switches{$sw_addr}) { - clear_counters; - get_counts($sw_addr, $sw_port, $ca_name, $ca_port); - if (any_counts() && $switch_prompt eq "no") { - my $hr = $IBswcountlimits::link_ends{"$sw_addr"}{$sw_port}; - printf("Errors for %18s \"%s\"\n", $sw_addr, $hr->{loc_desc}); - $switch_prompt = "yes"; - } - report_counts($sw_addr, $sw_port); - } - } - if ($single_switch && $switch_found ne "yes") { - printf("Switch \"%s\" not found.\n", $single_switch); - } -} -main; - diff --git a/infiniband-diags/scripts/ibqueryerrors.pl.in b/infiniband-diags/scripts/ibqueryerrors.pl.in new file mode 100755 index 0000000..30e610c --- /dev/null +++ b/infiniband-diags/scripts/ibqueryerrors.pl.in @@ -0,0 +1,40 @@ +#!/usr/bin/perl +# +# Copyright (c) 2009 Lawrence Livermore National Security +# +# Produced at Lawrence Livermore National Laboratory. +# Written by Ira Weiny <[email protected]>. +# +# This software is available to you under a choice of one of two +# licenses. You may choose to be licensed under the terms of the GNU +# General Public License (GPL) Version 2, available from the file +# COPYING in the main directory of this source tree, or the +# OpenIB.org BSD license below: +# +# Redistribution and use in source and binary forms, with or +# without modification, are permitted provided that the following +# conditions are met: +# +# - Redistributions of source code must retain the above +# copyright notice, this list of conditions and the following +# disclaimer. +# +# - Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + + +# this is now just a wrapper for the C based utility +$str = join " ",@ARGV; +exec "@IBSCRIPTPATH@/ibqueryerrors $str"; diff --git a/infiniband-diags/src/ibqueryerrors.c b/infiniband-diags/src/ibqueryerrors.c new file mode 100644 index 0000000..9d96190 --- /dev/null +++ b/infiniband-diags/src/ibqueryerrors.c @@ -0,0 +1,469 @@ +/* + * Copyright (c) 2004-2007 Voltaire Inc. All rights reserved. + * Copyright (c) 2007 Xsigo Systems Inc. All rights reserved. + * Copyright (c) 2008 Lawrence Livermore National Lab. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#if HAVE_CONFIG_H +# include <config.h> +#endif /* HAVE_CONFIG_H */ + +#define _GNU_SOURCE +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdarg.h> +#include <time.h> +#include <string.h> +#include <getopt.h> +#include <errno.h> +#include <inttypes.h> + +#include <infiniband/complib/cl_nodenamemap.h> +#include <infiniband/ibnetdisc.h> +#include <infiniband/mad.h> + +#include "ibdiag_common.h" + +char *argv0 = "ibqueryerrors"; +static FILE *f; + +struct ibmad_port *ibmad_port; +static char *node_name_map_file = NULL; +static nn_map_t *node_name_map = NULL; +int data_counters = 0; +int port_config = 0; +uint64_t switch_guid = 0; +char *switch_guid_str = NULL; +int sup_total = 0; +enum MAD_FIELDS *suppressed_fields = NULL; +char *dr_path = NULL; +int all_nodes = 0; + +static unsigned int +get_max(unsigned int num) +{ + unsigned int v = num; // 32-bit word to find the log base 2 of + unsigned r = 0; // r will be lg(v) + + while (v >>= 1) // unroll for more speed... + { + r++; + } + + return (1 << r); +} + +static void +get_msg(char *width_msg, char *speed_msg, int msg_size, ibnd_port_t *port) +{ + char buf[64]; + uint32_t max_speed = 0; + + uint32_t max_width = get_max(mad_get_field(port->info, 0, + IB_PORT_LINK_WIDTH_SUPPORTED_F) + & mad_get_field(port->remoteport->info, 0, + IB_PORT_LINK_WIDTH_SUPPORTED_F)); + if ((max_width & mad_get_field(port->info, 0, + IB_PORT_LINK_WIDTH_ACTIVE_F)) == 0) { + // we are not at the max supported width + // print what we could be at. + snprintf(width_msg, msg_size, "Could be %s", + mad_dump_val(IB_PORT_LINK_WIDTH_ACTIVE_F, + buf, 64, &max_width)); + } + + max_speed = get_max(mad_get_field(port->info, 0, + IB_PORT_LINK_SPEED_SUPPORTED_F) + & mad_get_field(port->remoteport->info, 0, + IB_PORT_LINK_SPEED_SUPPORTED_F)); + if ((max_speed & mad_get_field(port->info, 0, + IB_PORT_LINK_SPEED_ACTIVE_F)) == 0) { + // we are not at the max supported speed + // print what we could be at. + snprintf(speed_msg, msg_size, "Could be %s", + mad_dump_val(IB_PORT_LINK_SPEED_ACTIVE_F, + buf, 64, &max_speed)); + } +} + +static void +print_port_config(ibnd_node_t *node, int portnum) +{ + char width[64], speed[64], state[64], physstate[64]; + char remote_str[256]; + char link_str[256]; + char width_msg[256]; + char speed_msg[256]; + char ext_port_str[256]; + int iwidth, ispeed, istate, iphystate; + int n = 0; + + ibnd_port_t *port = node->ports[portnum]; + + if (!port) + return; + + iwidth = mad_get_field(port->info, 0, IB_PORT_LINK_WIDTH_ACTIVE_F); + ispeed = mad_get_field(port->info, 0, IB_PORT_LINK_SPEED_ACTIVE_F); + istate = mad_get_field(port->info, 0, IB_PORT_STATE_F); + iphystate = mad_get_field(port->info, 0, IB_PORT_PHYS_STATE_F); + + remote_str[0] = '\0'; + link_str[0] = '\0'; + width_msg[0] = '\0'; + speed_msg[0] = '\0'; + + n = snprintf(link_str, 256, "(%3s %s %6s/%8s)", + mad_dump_val(IB_PORT_LINK_WIDTH_ACTIVE_F, width, 64, &iwidth), + mad_dump_val(IB_PORT_LINK_SPEED_ACTIVE_F, speed, 64, &ispeed), + mad_dump_val(IB_PORT_STATE_F, state, 64, &istate), + mad_dump_val(IB_PORT_PHYS_STATE_F, physstate, 64, &iphystate)); + + if (port->remoteport) { + char *remap = remap_node_name(node_name_map, port->remoteport->node->guid, + port->remoteport->node->nodedesc); + + if (port->remoteport->ext_portnum) + snprintf(ext_port_str, 256, "%d", port->remoteport->ext_portnum); + else + ext_port_str[0] = '\0'; + + get_msg(width_msg, speed_msg, 256, port); + + snprintf(remote_str, 256, + "0x%016"PRIx64" %6d %4d[%2s] \"%s\" (%s %s)\n", + port->remoteport->node->guid, + port->remoteport->base_lid ? port->remoteport->base_lid : + port->remoteport->node->smalid, + port->remoteport->portnum, + ext_port_str, + remap, + width_msg, + speed_msg); + free(remap); + } else + snprintf(remote_str, 256, " [ ] \"\" ( )\n"); + + if (port->ext_portnum) + snprintf(ext_port_str, 256, "%d", port->ext_portnum); + else + ext_port_str[0] = '\0'; + + if (node->type == IB_NODE_SWITCH) + printf(" %6d", node->smalid); + else + printf(" %6d", port->base_lid); + + printf("%4d[%2s] ==%s==> %s", + port->portnum, ext_port_str, link_str, remote_str); +} + +static int +suppress(enum MAD_FIELDS field) +{ + int i = 0; + if (suppressed_fields) + for (i = 0; i < sup_total; i++) { + if (field == suppressed_fields[i]) + return (1); + } + return (0); +} + +static void +report_suppressed(void) +{ + int i = 0; + if (suppressed_fields) { + printf("Suppressing:"); + for (i = 0; i < sup_total; i++) { + printf(" %s", mad_field_name(suppressed_fields[i])); + } + printf("\n"); + } +} + +static void +print_results(ibnd_node_t *node, uint8_t *pc, int portnum) +{ + char buf[1024]; + char *str = buf; + uint32_t val = 0; + int n = 0; + int i = 0; + + for (n = 0, i = IB_PC_ERR_SYM_F; i <= IB_PC_VL15_DROPPED_F; i++) { + if (suppress(i)) + continue; + + mad_decode_field(pc, i, (void *)&val); + if (val) + n += snprintf(str+n, 1024-n, " [%s == %d]", + mad_field_name(i), val); + } + + if (!suppress(IB_PC_XMT_WAIT_F)) { + mad_decode_field(pc, IB_PC_XMT_WAIT_F, (void *)&val); + if (val) + n += snprintf(str+n, 1024-n, " [%s == %d]", mad_field_name(i), val); + } + + /* if we found errors. */ + if (n != 0) { + char *nodename = remap_node_name(node_name_map, node->guid, node->nodedesc); + if (data_counters) + for (i = IB_PC_XMT_BYTES_F; i <= IB_PC_RCV_PKTS_F; i++) { + uint64_t val64 = 0; + mad_decode_field(pc, i, (void *)&val64); + if (val64) + n += snprintf(str+n, 1024-n, " [%s == %"PRId64"]", + mad_field_name(i), val64); + } + + printf("Errors for 0x%" PRIx64 " \"%s\"\n", node->guid, nodename); + printf(" GUID 0x%" PRIx64 " port %d:%s\n", + node->guid, portnum, str); + if (port_config) + print_port_config(node, portnum); + free(nodename); + } +} + +static void +print_port(ibnd_node_t *node, int portnum) +{ + uint8_t pc[1024]; + uint16_t cap_mask; + ib_portid_t portid = {0}; + char *nodename = remap_node_name(node_name_map, node->guid, node->nodedesc); + + if (node->type == IB_NODE_SWITCH) + ib_portid_set(&portid, node->smalid, 0, 0); + else + ib_portid_set(&portid, node->ports[portnum]->base_lid, 0, 0); + + /* PerfMgt ClassPortInfo is a required attribute */ + if (!pma_query_via(pc, &portid, portnum, ibd_timeout, CLASS_PORT_INFO, + ibmad_port)) { + IBWARN("classportinfo query failed on %s, %s port %d", + nodename, portid2str(&portid), portnum); + goto cleanup; + } + /* ClassPortInfo should be supported as part of libibmad */ + memcpy(&cap_mask, pc + 2, sizeof(cap_mask)); /* CapabilityMask */ + + if (!pma_query_via(pc, &portid, portnum, ibd_timeout, + IB_GSI_PORT_COUNTERS, + ibmad_port)) { + IBWARN("IB_GSI_PORT_COUNTERS query failed on %s, %s port %d\n", + nodename, portid2str(&portid), portnum); + goto cleanup; + } + if (!(cap_mask & 0x1000)) { + /* if PortCounters:PortXmitWait not suppported clear this counter */ + uint32_t foo = 0; + mad_encode_field(pc, IB_PC_XMT_WAIT_F, &foo); + } + print_results(node, pc, portnum); + +cleanup: + free(nodename); +} + +void +print_node(ibnd_node_t *node, void *user_data) +{ + int p = 0; + int startport = 1; + + if (!all_nodes && node->type != IB_NODE_SWITCH) + return; + + if (node->type == IB_NODE_SWITCH && node->smaenhsp0) + startport = 0; + + for (p = startport; p <= node->numports; p++) { + if (node->ports[p]) { + print_port(node, p); + } + } +} + +static void +add_suppressed(enum MAD_FIELDS field) +{ + suppressed_fields = realloc(suppressed_fields, sizeof(enum MAD_FIELDS)); + suppressed_fields[sup_total] = field; + sup_total++; +} + +static void +calculate_suppressed_fields(char *str) +{ + enum MAD_FIELDS f = 0; + char *tmp = strdup(str); + char *lasts, *val; + + val = strtok_r(tmp, ",", &lasts); + while (val) { + for (f = IB_PC_FIRST_F; f <= IB_PC_LAST_F; f++) { + if (strcmp(val, mad_field_name(f)) == 0) { + add_suppressed(f); + } + } + val = strtok_r(NULL, ",", &lasts); + } + + free(tmp); +} + +static int process_opt(void *context, int ch, char *optarg) +{ + switch (ch) { + case 's': + calculate_suppressed_fields(optarg); + break; + case 'c': + /* Right now this is the only "common" error */ + add_suppressed(IB_PC_ERR_SWITCH_REL_F); + break; + case 1: + node_name_map_file = strdup(optarg); + break; + case 2: + data_counters++; + break; + case 3: + all_nodes++; + break; + case 'S': + switch_guid_str = strdup(optarg); + switch_guid = (uint64_t)strtoull(switch_guid_str, 0, 0); + break; + case 'D': + dr_path = strdup(optarg); + break; + case 'r': + port_config++; + break; + case 'R': /* nop */ + break; + default: + return -1; + } + + return 0; +} + +int +main(int argc, char **argv) +{ + int rc = 0; + ibnd_fabric_t *fabric = NULL; + + int mgmt_classes[4] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS, IB_PERFORMANCE_CLASS}; + + const struct ibdiag_opt opts[] = { + { "suppress", 's', 1, "<err1,err2,...>", "suppress errors listed" }, + { "suppress-common", 'c', 0, NULL, "suppress some of the common counters" }, + { "node-name-map", 1, 1, "<file>", "node name map file" }, + { "switch", 'S', 1, "<switch_guid>", "query only <switch_guid> (hex format)"}, + { "Direct", 'D', 1, "<dr_path>", "query only switch specified by <dr_path>"}, + { "report-port", 'r', 0, NULL, "report port configuration information"}, + { "GNDN", 'R', 0, NULL, "(This option is obsolete and does nothing)"}, + { "data", 2, 0, NULL, "include the data counters in the output"}, + { "all", 3, 0, NULL, "output all nodes (not just switches)"}, + { 0 } + }; + char usage_args[] = ""; + + ibdiag_process_opts(argc, argv, "sDLG", "snSrR", opts, process_opt, + usage_args, NULL); + + f = stdout; + + argc -= optind; + argv += optind; + + if (ibverbose) + ibnd_debug(1); + + ibmad_port = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 4); + if (!ibmad_port) + IBERROR("Failed to open port; %s:%d\n", ibd_ca, ibd_ca_port); + + node_name_map = open_node_name_map(node_name_map_file); + + if (switch_guid) { + /* limit the scan the fabric around the target */ + ib_portid_t portid = {0}; + + if (ib_resolve_portid_str_via(&portid, switch_guid_str, IB_DEST_GUID, + ibd_sm_id, ibmad_port) < 0) { + fprintf(stderr, "can't resolve destination port %s %p\n", + switch_guid_str, ibd_sm_id); + rc = 1; + goto close_port; + } + + if ((fabric = ibnd_discover_fabric(ibmad_port, ibd_timeout, &portid, 1)) == NULL) { + fprintf(stderr, "discover failed\n"); + rc = 1; + goto close_port; + } + } else { + if ((fabric = ibnd_discover_fabric(ibmad_port, ibd_timeout, NULL, -1)) == NULL) { + fprintf(stderr, "discover failed\n"); + rc = 1; + goto close_port; + } + } + + report_suppressed(); + + if (switch_guid) { + ibnd_node_t *node = ibnd_find_node_guid(fabric, switch_guid); + print_node(node, NULL); + } else if (dr_path) { + ibnd_node_t *node = ibnd_find_node_dr(fabric, dr_path); + print_node(node, NULL); + } else + ibnd_iter_nodes(fabric, print_node, NULL); + + ibnd_destroy_fabric(fabric); + +close_port: + mad_rpc_close_port(ibmad_port); + close_node_name_map(node_name_map); + exit(rc); +} -- 1.5.4.5 _______________________________________________ general mailing list [email protected] http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general
