[ofa-general] [PATCH] Add -C and -P options to perl diags to be able to use alternate CA's and ports

Ira Weiny weiny2 at llnl.gov
Fri Sep 7 15:25:41 PDT 2007


We have a few nodes which are connected to multiple fabrics.  The perl diags were unable to specify which port or CA to use.  In our case this left us unable to use these tools on one of the subnets attached.  This patch adds that support.

Ira


>From b2f95d93e1c2a730f554275cf636ccd687d1106e Mon Sep 17 00:00:00 2001
From: Ira K. Weiny <weiny2 at llnl.gov>
Date: Thu, 6 Sep 2007 09:37:10 -0700
Subject: [PATCH] Add -C and -P options to perl diags to be able to use alternate CA's and ports

infiniband-diags/scripts/IBswcountlimits.pm
infiniband-diags/scripts/ibfindnodesusing.pl
infiniband-diags/scripts/iblinkinfo.pl
infiniband-diags/scripts/ibqueryerrors.pl

Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
---
 infiniband-diags/scripts/IBswcountlimits.pm  |   53 +++++++++++++++++++++++--
 infiniband-diags/scripts/ibfindnodesusing.pl |   21 +++++++---
 infiniband-diags/scripts/iblinkinfo.pl       |   23 +++++++----
 infiniband-diags/scripts/ibqueryerrors.pl    |   31 +++++++++++----
 4 files changed, 100 insertions(+), 28 deletions(-)

diff --git a/infiniband-diags/scripts/IBswcountlimits.pm b/infiniband-diags/scripts/IBswcountlimits.pm
index f1e16d2..ece1284 100755
--- a/infiniband-diags/scripts/IBswcountlimits.pm
+++ b/infiniband-diags/scripts/IBswcountlimits.pm
@@ -215,22 +215,59 @@ sub ensure_cache_dir
 }
 
 # =========================================================================
+# get_link_ends(ca_name, ca_port)
 #
-sub generate_ibnetdiscover_topology
+sub get_cache_file
 {
+   my $ca_name = $_[0];
+   my $ca_port = $_[1];
    ensure_cache_dir;
-   `ibnetdiscover -g > $IBswcountlimits::cache_dir/ibnetdiscover.topology`;
+   return ("$IBswcountlimits::cache_dir/ibnetdiscover-$ca_name-$ca_port.topology");
+}
+
+# =========================================================================
+# get_ca_name_port_param_string(ca_name, ca_port)
+#
+sub get_ca_name_port_param_string
+{
+   my $ca_name = $_[0];
+   my $ca_port = $_[1];
+
+   if ("$ca_name" ne "") { $ca_name = "-C $ca_name"; }
+   if ("$ca_port" ne "") { $ca_port = "-P $ca_port"; }
+
+   return ("$ca_name $ca_port");
+}
+
+# =========================================================================
+# generate_ibnetdiscover_topology(ca_name, ca_port)
+#
+sub generate_ibnetdiscover_topology
+{
+   my $ca_name = $_[0];
+   my $ca_port = $_[1];
+   my $cache_file = get_cache_file($ca_name, $ca_port);
+   my $extra_params = get_ca_name_port_param_string($ca_name, $ca_port);
+
+   `ibnetdiscover -g $extra_params > $cache_file`;
    if ($? != 0) {
        die "Execution of ibnetdiscover failed with errors\n";
    }
 }
 
 # =========================================================================
+# get_link_ends(regenerate_map, ca_name, ca_port)
 #
 sub get_link_ends
 {
-   if (!(-f "$IBswcountlimits::cache_dir/ibnetdiscover.topology")) { generate_ibnetdiscover_topology; }
-   open IBNET_TOPO, "<$IBswcountlimits::cache_dir/ibnetdiscover.topology" or die "Failed to open ibnet topology: $!\n";
+   my $regenerate_map = $_[0];
+   my $ca_name = $_[1];
+   my $ca_port = $_[2];
+
+   my $cache_file = get_cache_file($ca_name, $ca_port);
+
+   if ($regenerate_map || !(-f "$cache_file")) { generate_ibnetdiscover_topology($ca_name, $ca_port); }
+   open IBNET_TOPO, "<$cache_file" or die "Failed to open ibnet topology: $!\n";
    my $in_switch = "no";
    my $desc = "";
    my $guid = "";
@@ -310,12 +347,18 @@ sub get_link_ends
    close IBNET_TOPO;
 }
 
+# =========================================================================
+# get_num_ports(switch_guid, ca_name, ca_port)
+#
 sub get_num_ports
 {
         my $guid = $_[0];
+	my $ca_name = $_[1];
+	my $ca_port = $_[2];
         my $num_ports = 0;
+        my $extra_params = get_ca_name_port_param_string($ca_name, $ca_port);
 
-        my $data = `smpquery -G nodeinfo $guid`;
+        my $data = `smpquery $extra_params -G nodeinfo $guid`;
         my @lines = split("\n", $data);
         my $pkt_lifetime = "";
         foreach my $line (@lines) {
diff --git a/infiniband-diags/scripts/ibfindnodesusing.pl b/infiniband-diags/scripts/ibfindnodesusing.pl
index 1b60328..626bebe 100755
--- a/infiniband-diags/scripts/ibfindnodesusing.pl
+++ b/infiniband-diags/scripts/ibfindnodesusing.pl
@@ -42,6 +42,8 @@ use strict;
 
 use Getopt::Std;
 use IBswcountlimits;
+my $ca_name = "";
+my $ca_port = "";
 
 # =========================================================================
 #
@@ -50,10 +52,11 @@ sub get_hosts_routed
    my $sw_guid = $_[0];
    my $sw_port = $_[1];
    my @hosts = undef;
+   my $extra_params = get_ca_name_port_param_string($ca_name, $ca_port);
 
    if ($sw_guid eq "") { return (@hosts); }
 
-   my $data = `ibroute -G $sw_guid`;
+   my $data = `ibroute $extra_params -G $sw_guid`;
    my @lines = split("\n", $data);
    foreach my $line (@lines) {
       if ($line =~ /\w+\s+(\d+)\s+:\s+\(Channel Adapter.*:\s+'(.*)'\)/)
@@ -73,23 +76,27 @@ sub get_hosts_routed
 sub usage_and_exit
 {
    my $prog = $_[0];
-   print "Usage: $prog <switch_guid|switch_name> <port>\n";
+   print "Usage: $prog [-R -C <ca_name> -P <ca_port>] <switch_guid|switch_name> <port>\n";
    print "   find a list of nodes which are routed through switch:port\n";
    print "   -R Recalculate ibnetdiscover information\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 0;
 }
 
 my $argv0 = `basename $0`;
 my $regenerate_map = undef;
 chomp $argv0;
-if (!getopts("hR")) { usage_and_exit $argv0; }
+if (!getopts("hRC:P:")) { usage_and_exit $argv0; }
 if (defined $Getopt::Std::opt_h) { usage_and_exit $argv0; }
 if (defined $Getopt::Std::opt_R) { $regenerate_map = $Getopt::Std::opt_R; }
+if (defined $Getopt::Std::opt_C) { $ca_name = $Getopt::Std::opt_C; }
+if (defined $Getopt::Std::opt_P) { $ca_port = $Getopt::Std::opt_P; }
 
 my $target_switch = $ARGV[0];
 my $target_port = $ARGV[1];
 
-if ($regenerate_map || !(-f "$IBswcountlimits::cache_dir/ibnetdiscover.topology")) { generate_ibnetdiscover_topology; }
+get_link_ends($regenerate_map, $ca_name, $ca_port);
 
 if ($target_switch eq "" || $target_port eq "")
 {
@@ -160,7 +167,8 @@ sub compress_hostlist
 sub main
 {
    my $found_switch = undef;
-   open IBNET_TOPO, "<$IBswcountlimits::cache_dir/ibnetdiscover.topology" or die "Failed to open ibnet topology\n";
+   my $cache_file = get_cache_file($ca_name, $ca_port);
+   open IBNET_TOPO, "<$cache_file" or die "Failed to open ibnet topology\n";
    my $in_switch = "no";
    my $switch_guid = "";
    my $desc = undef;
@@ -191,13 +199,12 @@ FOUND:
    if (! $found_switch)
    {
       print "Switch \"$target_switch\" not found\n";
-      print "   Try running with the \"-R\" option.\n";
+      print "   Try running with the \"-R\" or \"-P\" option.\n";
       exit 1;
    }
 
    $switch_guid = "0x$switch_guid";
 
-   get_link_ends;
    my $hr = $IBswcountlimits::link_ends{$switch_guid}{$target_port};
    my $rem_sw_guid = $hr->{rem_guid};
    my $rem_sw_port = $hr->{rem_port};
diff --git a/infiniband-diags/scripts/iblinkinfo.pl b/infiniband-diags/scripts/iblinkinfo.pl
index 73ac585..1298f57 100755
--- a/infiniband-diags/scripts/iblinkinfo.pl
+++ b/infiniband-diags/scripts/iblinkinfo.pl
@@ -43,7 +43,7 @@ use IBswcountlimits;
 sub usage_and_exit
 {
    my $prog = $_[0];
-   print "Usage: $prog [-Rhclp -S <guid>]\n";
+   print "Usage: $prog [-Rhclp -S <guid> -C <ca_name> -P <ca_port>]\n";
    print "   Report link speed and connection for each port of each switch which is active\n";
    print "   -h This help message\n";
    print "   -R Recalculate ibnetdiscover information (Default is to reuse ibnetdiscover output)\n";
@@ -52,6 +52,8 @@ sub usage_and_exit
    print "   -l (line mode) print all information for each link on each line\n";
    print "   -p print additional switch settings (PktLifeTime,HoqLife,VLStallCount)\n";
    print "   -c print port capabilities (enabled/supported values)\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 0;
 }
 
@@ -62,9 +64,11 @@ my $line_mode = undef;
 my $print_add_switch = undef;
 my $print_extended_cap = undef;
 my $only_down_links = undef;
+my $ca_name = "";
+my $ca_port = "";
 chomp $argv0;
 
-if (!getopts("hcpldRS:")) { usage_and_exit $argv0; }
+if (!getopts("hcpldRS:C:P:")) { usage_and_exit $argv0; }
 if (defined $Getopt::Std::opt_h) { usage_and_exit $argv0; }
 if (defined $Getopt::Std::opt_R) { $regenerate_map = $Getopt::Std::opt_R; }
 if (defined $Getopt::Std::opt_S) { $single_switch = $Getopt::Std::opt_S; }
@@ -72,18 +76,21 @@ if (defined $Getopt::Std::opt_d) { $only_down_links = $Getopt::Std::opt_d; }
 if (defined $Getopt::Std::opt_l) { $line_mode = $Getopt::Std::opt_l; }
 if (defined $Getopt::Std::opt_p) { $print_add_switch = $Getopt::Std::opt_p; }
 if (defined $Getopt::Std::opt_c) { $print_extended_cap = $Getopt::Std::opt_c; }
+if (defined $Getopt::Std::opt_C) { $ca_name = $Getopt::Std::opt_C; }
+if (defined $Getopt::Std::opt_P) { $ca_port = $Getopt::Std::opt_P; }
+
+my $extra_smpquery_params = get_ca_name_port_param_string($ca_name, $ca_port);
 
 sub main
 {
-   if ($regenerate_map) { generate_ibnetdiscover_topology; }
-   get_link_ends;
+   get_link_ends($regenerate_map, $ca_name, $ca_port);
    foreach my $switch (sort (keys (%IBswcountlimits::link_ends))) {
       if ($single_switch && $switch ne $single_switch)
       {
          next;
       }
       my $switch_prompt = "no";
-      my $num_ports = get_num_ports($switch);
+      my $num_ports = get_num_ports($switch, $ca_name, $ca_port);
       if ($num_ports == 0) {
             printf("ERROR: switch $switch has 0 ports???\n");
       }
@@ -95,7 +102,7 @@ sub main
       if ($only_down_links) { $print_switch = "no"; }
       if ($print_add_switch)
       {
-         my $data = `smpquery -G switchinfo $switch`;
+         my $data = `smpquery $extra_smpquery_params -G switchinfo $switch`;
          if ($data eq "") {
             printf("ERROR: failed to get switchinfo for $switch\n");
          }
@@ -111,7 +118,7 @@ sub main
                 sprintf ("Switch %18s %s%s:\n", $switch, $hr->{loc_desc}, $pkt_life_prompt));
             $switch_prompt = "yes";
          }
-         my $data = `smpquery -G portinfo $switch $port`;
+         my $data = `smpquery $extra_smpquery_params -G portinfo $switch $port`;
          if ($data eq "") {
             printf("ERROR: failed to get portinfo for $switch port $port\n");
          }
@@ -147,7 +154,7 @@ sub main
          my $rem_width_enable = "";
          if ($rem_lid ne "" && $rem_port ne "")
          {
-            $data = `smpquery portinfo $rem_lid $rem_port`;
+            $data = `smpquery $extra_smpquery_params portinfo $rem_lid $rem_port`;
             if ($data eq "") {
                printf("ERROR: failed to get portinfo for $switch port $port\n");
             }
diff --git a/infiniband-diags/scripts/ibqueryerrors.pl b/infiniband-diags/scripts/ibqueryerrors.pl
index 67e5f0f..bdb458d 100755
--- a/infiniband-diags/scripts/ibqueryerrors.pl
+++ b/infiniband-diags/scripts/ibqueryerrors.pl
@@ -43,6 +43,7 @@ my $print_action = "no";
 my $report_port_info = undef;
 my $single_switch = undef;
 my $include_data_counters = undef;
+my $cache_file = "";
 
 # =========================================================================
 #
@@ -50,6 +51,9 @@ 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())
    {
@@ -65,7 +69,7 @@ sub report_counts
          my $lid = "";
          my $speed = "";
          my $width = "";
-         my $data = `smpquery -G portinfo $addr $port`;
+         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; }
@@ -94,7 +98,11 @@ sub get_counts
 {
    my $addr = $_[0];
    my $port = $_[1];
-   my $data = `perfquery -G $addr $port`;
+   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`;
    my @lines = split("\n", $data);
    foreach my $line (@lines)
    {
@@ -113,7 +121,7 @@ sub get_counts
 my %switches = ();
 sub get_switches
 {
-   my $data = `ibswitches $IBswcountlimits::cache_dir/ibnetdiscover.topology`;
+   my $data = `ibswitches $cache_file`;
    my @lines = split("\n", $data);
    foreach my $line (@lines) {
       if ($line =~ /^Switch\s+:\s+(\w+)\s+ports\s+(\d+)\s+.*/)
@@ -128,7 +136,7 @@ sub get_switches
 sub usage_and_exit
 {
    my $prog = $_[0];
-   print "Usage: $prog [-a -c -r -R -s <err1,err2,...> -S <switch_guid> -d]\n";
+   print "Usage: $prog [-a -c -r -R -s <err1,err2,...> -S <switch_guid> -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";
@@ -137,15 +145,19 @@ sub usage_and_exit
    print "   -s <err1,err2,...> suppress errors listed\n";
    print "   -S <switch_guid> query only <switch_guid>\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 0;
 }
 
 my $argv0 = `basename $0`;
 my $regenerate_map = undef;
 my $single_switch = undef;
+my $ca_name = "";
+my $ca_port = "";
 
 chomp $argv0;
-if (!getopts("has:crRS:d")) { usage_and_exit $argv0; }
+if (!getopts("has:crRS: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); }
@@ -157,6 +169,10 @@ 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_S) { $single_switch = $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
 {
@@ -165,16 +181,15 @@ sub main
       my $msg = join(",", @IBswcountlimits::suppress_errors);
       print "Suppressing: $msg\n";
    }
-   if ($regenerate_map || !(-f "$IBswcountlimits::cache_dir/ibnetdiscover.topology")) { generate_ibnetdiscover_topology; }
+   get_link_ends($regenerate_map, $ca_name, $ca_port);
    get_switches;
-   get_link_ends;
    foreach my $sw_addr (keys %switches) {
       if ($single_switch && $sw_addr ne "$single_switch") { next; }
 
       my $switch_prompt = "no";
       foreach my $sw_port (1 .. $switches{$sw_addr}) {
          clear_counters;
-         get_counts($sw_addr, $sw_port);
+         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};
-- 
1.5.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Add-C-and-P-options-to-perl-diags-to-be-able-to-us.patch
Type: application/octet-stream
Size: 15256 bytes
Desc: not available
URL: <http://lists.openfabrics.org/pipermail/general/attachments/20070907/0e32747e/attachment.obj>


More information about the general mailing list