[ofa-general] [PATCH] infiniband-diags/scripts/ibprint[ca|switch|rt].pl: fix printing by name

Ira Weiny weiny2 at llnl.gov
Wed May 28 17:57:19 PDT 2008


I guess when I added support to search by GUID I must have broken the printing
by name.  This changes these scripts to use the common convention of "-G" to
specify that a GUID is to be searched for and fixes the printing when a name is
specified.

Ira

>From e9b6766bd6b3661a5bc1e78c9e95784a99a631c0 Mon Sep 17 00:00:00 2001
From: Ira Weiny <weiny2 at llnl.gov>
Date: Fri, 23 May 2008 16:19:57 -0700
Subject: [PATCH] infiniband-diags/scripts/ibprint[ca|switch|rt].pl: fix printing by name


Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
---
 infiniband-diags/scripts/ibprintca.pl     |   15 +++++++++++----
 infiniband-diags/scripts/ibprintrt.pl     |   15 +++++++++++----
 infiniband-diags/scripts/ibprintswitch.pl |   15 +++++++++++----
 3 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/infiniband-diags/scripts/ibprintca.pl b/infiniband-diags/scripts/ibprintca.pl
index 38b4330..b13a83b 100755
--- a/infiniband-diags/scripts/ibprintca.pl
+++ b/infiniband-diags/scripts/ibprintca.pl
@@ -45,12 +45,13 @@ use IBswcountlimits;
 sub usage_and_exit
 {
 	my $prog = $_[0];
-	print "Usage: $prog [-R -l] [<ca_guid|node_name>]\n";
+	print "Usage: $prog [-R -l] [-G <ca_guid> | <node_name>]\n";
 	print "   print only the ca specified from the ibnetdiscover output\n";
 	print "   -R Recalculate ibnetdiscover information\n";
 	print "   -l list cas\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";
+	print "   -G node is specified with GUID\n";
 	exit 0;
 }
 
@@ -59,15 +60,21 @@ my $regenerate_map = undef;
 my $list_hcas      = undef;
 my $ca_name        = "";
 my $ca_port        = "";
+my $name_is_guid   = "no";
 chomp $argv0;
-if (!getopts("hRlC:P:"))         { usage_and_exit $argv0; }
+if (!getopts("hRlC:P:G"))         { 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_l) { $list_hcas      = $Getopt::Std::opt_l; }
 if (defined $Getopt::Std::opt_C) { $ca_name        = $Getopt::Std::opt_C; }
 if (defined $Getopt::Std::opt_P) { $ca_port        = $Getopt::Std::opt_P; }
+if (defined $Getopt::Std::opt_G) { $name_is_guid   = "yes"; }
 
-my $target_hca = format_guid($ARGV[0]);
+my $target_hca = $ARGV[0];
+
+if ($name_is_guid eq "yes") {
+	$target_hca = format_guid($target_hca);
+}
 
 my $cache_file = get_cache_file($ca_name, $ca_port);
 
@@ -100,7 +107,7 @@ sub main
 				$in_hca = "no";
 				goto DONE;
 			}
-			if ("0x$guid" eq $target_hca || $desc =~ /.*$target_hca.*/) {
+			if ("0x$guid" eq $target_hca || $desc =~ /[\s\"]$target_hca[\s\"]/) {
 				print $line;
 				$in_hca    = "yes";
 				$found_hca = "yes";
diff --git a/infiniband-diags/scripts/ibprintrt.pl b/infiniband-diags/scripts/ibprintrt.pl
index 86dcb64..e9e6cc4 100755
--- a/infiniband-diags/scripts/ibprintrt.pl
+++ b/infiniband-diags/scripts/ibprintrt.pl
@@ -45,12 +45,13 @@ use IBswcountlimits;
 sub usage_and_exit
 {
 	my $prog = $_[0];
-	print "Usage: $prog [-R -l] [<rt_guid|node_name>]\n";
+	print "Usage: $prog [-R -l] [-G <rt_guid> | <node_name>]\n";
 	print "   print only the rt specified from the ibnetdiscover output\n";
 	print "   -R Recalculate ibnetdiscover information\n";
 	print "   -l list rts\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";
+	print "   -G node is specified with GUID\n";
 	exit 0;
 }
 
@@ -59,15 +60,21 @@ my $regenerate_map = undef;
 my $list_rts       = undef;
 my $ca_name        = "";
 my $ca_port        = "";
+my $name_is_guid   = "no";
 chomp $argv0;
-if (!getopts("hRlC:P:"))         { usage_and_exit $argv0; }
+if (!getopts("hRlC:P:G"))         { 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_l) { $list_rts       = $Getopt::Std::opt_l; }
 if (defined $Getopt::Std::opt_C) { $ca_name        = $Getopt::Std::opt_C; }
 if (defined $Getopt::Std::opt_P) { $ca_port        = $Getopt::Std::opt_P; }
+if (defined $Getopt::Std::opt_G) { $name_is_guid   = "yes"; }
 
-my $target_rt = format_guid($ARGV[0]);
+my $target_rt = $ARGV[0];
+
+if ($name_is_guid eq "yes") {
+	$target_rt = format_guid($target_rt);
+}
 
 my $cache_file = get_cache_file($ca_name, $ca_port);
 
@@ -100,7 +107,7 @@ sub main
 				$in_rt = "no";
 				goto DONE;
 			}
-			if ("0x$guid" eq $target_rt || $desc =~ /.*$target_rt.*/) {
+			if ("0x$guid" eq $target_rt || $desc =~ /[\s\"]$target_rt[\s\"]/) {
 				print $line;
 				$in_rt    = "yes";
 				$found_rt = "yes";
diff --git a/infiniband-diags/scripts/ibprintswitch.pl b/infiniband-diags/scripts/ibprintswitch.pl
index 6712201..148d70e 100755
--- a/infiniband-diags/scripts/ibprintswitch.pl
+++ b/infiniband-diags/scripts/ibprintswitch.pl
@@ -44,12 +44,13 @@ use IBswcountlimits;
 sub usage_and_exit
 {
 	my $prog = $_[0];
-	print "Usage: $prog [-R -l] [<switch_guid|switch_name>]\n";
+	print "Usage: $prog [-R -l] [-G <switch_guid> | <switch_name>]\n";
 	print "   print only the switch specified from the ibnetdiscover output\n";
 	print "   -R Recalculate ibnetdiscover information\n";
 	print "   -l list switches\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";
+	print "   -G node is specified with GUID\n";
 	exit 0;
 }
 
@@ -58,15 +59,21 @@ my $regenerate_map = undef;
 my $list_switches  = undef;
 my $ca_name        = "";
 my $ca_port        = "";
+my $name_is_guid   = "no";
 chomp $argv0;
-if (!getopts("hRlC:P:"))         { usage_and_exit $argv0; }
+if (!getopts("hRlC:P:G"))         { 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_l) { $list_switches  = $Getopt::Std::opt_l; }
 if (defined $Getopt::Std::opt_C) { $ca_name        = $Getopt::Std::opt_C; }
 if (defined $Getopt::Std::opt_P) { $ca_port        = $Getopt::Std::opt_P; }
+if (defined $Getopt::Std::opt_G) { $name_is_guid   = "yes"; }
 
-my $target_switch = format_guid($ARGV[0]);
+my $target_switch = $ARGV[0];
+
+if ($name_is_guid eq "yes") {
+	$target_switch = format_guid($target_switch);
+}
 
 my $cache_file = get_cache_file($ca_name, $ca_port);
 
@@ -99,7 +106,7 @@ sub main
 				$in_switch = "no";
 				goto DONE;
 			}
-			if ("0x$guid" eq $target_switch || $desc =~ /.*$target_switch.*/) {
+			if ("0x$guid" eq $target_switch || $desc =~ /[\s\"]$target_switch[\s\"]/) {
 				print $line;
 				$in_switch    = "yes";
 				$found_switch = "yes";
-- 
1.5.4.5




More information about the general mailing list