[ofa-general] [PATCH] infiniband-diags/scripts/ibprint[ca|switch|rt].pl: allow printing of multiple matches but print warning to user that multiple matches were found

Ira Weiny weiny2 at llnl.gov
Wed May 28 17:59:41 PDT 2008


I think it is useful to print multiple matches found when searching for
matches.  Specifically when switches have not been named, ie they all have some
"Mellanox..." or "Voltaire..." name.

This prints all matches but also warns the user at the end that it found X
matches.

Ira

>From 11b85c9b526b9067aa12eac5d445d8ee43a7d024 Mon Sep 17 00:00:00 2001
From: Ira Weiny <weiny2 at llnl.gov>
Date: Fri, 23 May 2008 16:25:19 -0700
Subject: [PATCH] infiniband-diags/scripts/ibprint[ca|switch|rt].pl: allow printing of multiple
 matches but print warning to user that multiple matches were found


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

diff --git a/infiniband-diags/scripts/ibprintca.pl b/infiniband-diags/scripts/ibprintca.pl
index b13a83b..ccd5473 100755
--- a/infiniband-diags/scripts/ibprintca.pl
+++ b/infiniband-diags/scripts/ibprintca.pl
@@ -95,7 +95,7 @@ if ($target_hca eq "") {
 #
 sub main
 {
-	my $found_hca = undef;
+	my $found_hca = 0;
 	open IBNET_TOPO, "<$cache_file" or die "Failed to open ibnet topology\n";
 	my $in_hca = "no";
 	my %ports  = undef;
@@ -105,12 +105,14 @@ sub main
 			my $desc = $2;
 			if ($in_hca eq "yes") {
 				$in_hca = "no";
-				goto DONE;
+				foreach my $port (sort { $a <=> $b } (keys %ports)) {
+					print $ports{$port};
+				}
 			}
 			if ("0x$guid" eq $target_hca || $desc =~ /[\s\"]$target_hca[\s\"]/) {
 				print $line;
 				$in_hca    = "yes";
-				$found_hca = "yes";
+				$found_hca++;
 			}
 		}
 		if ($line =~ /^Switch.*/ || $line =~ /^Rt.*/) { $in_hca = "no"; }
@@ -120,15 +122,14 @@ sub main
 		}
 
 	}
-	DONE:
-	foreach my $port (sort { $a <=> $b } (keys %ports)) {
-		print $ports{$port};
-	}
-	if (!$found_hca) {
+	if ($found_hca == 0) {
 		print "\"$target_hca\" not found\n";
 		print "   Try running with the \"-R\" option.\n";
 		print "   If still not found the node is probably down.\n";
 	}
+	if ($found_hca > 1) {
+		print "\nWARNING: Found $found_hca CA's with the name \"$target_hca\"\n";
+	}
 	close IBNET_TOPO;
 }
 main
diff --git a/infiniband-diags/scripts/ibprintrt.pl b/infiniband-diags/scripts/ibprintrt.pl
index e9e6cc4..4b83ff0 100755
--- a/infiniband-diags/scripts/ibprintrt.pl
+++ b/infiniband-diags/scripts/ibprintrt.pl
@@ -95,7 +95,7 @@ if ($target_rt eq "") {
 #
 sub main
 {
-	my $found_rt = undef;
+	my $found_rt = 0;
 	open IBNET_TOPO, "<$cache_file" or die "Failed to open ibnet topology\n";
 	my $in_rt = "no";
 	my %ports = undef;
@@ -105,12 +105,14 @@ sub main
 			my $desc = $2;
 			if ($in_rt eq "yes") {
 				$in_rt = "no";
-				goto DONE;
+				foreach my $port (sort { $a <=> $b } (keys %ports)) {
+					print $ports{$port};
+				}
 			}
 			if ("0x$guid" eq $target_rt || $desc =~ /[\s\"]$target_rt[\s\"]/) {
 				print $line;
 				$in_rt    = "yes";
-				$found_rt = "yes";
+				$found_rt++;
 			}
 		}
 		if ($line =~ /^Switch.*/ || $line =~ /^Ca.*/) { $in_rt = "no"; }
@@ -120,15 +122,14 @@ sub main
 		}
 
 	}
-	DONE:
-	foreach my $port (sort { $a <=> $b } (keys %ports)) {
-		print $ports{$port};
-	}
-	if (!$found_rt) {
+	if ($found_rt == 0) {
 		print "\"$target_rt\" not found\n";
 		print "   Try running with the \"-R\" option.\n";
 		print "   If still not found the node is probably down.\n";
 	}
+	if ($found_rt > 1) {
+		print "\nWARNING: Found $found_rt Router's with the name \"$target_rt\"\n";
+	}
 	close IBNET_TOPO;
 }
 main
diff --git a/infiniband-diags/scripts/ibprintswitch.pl b/infiniband-diags/scripts/ibprintswitch.pl
index 148d70e..9426673 100755
--- a/infiniband-diags/scripts/ibprintswitch.pl
+++ b/infiniband-diags/scripts/ibprintswitch.pl
@@ -94,7 +94,7 @@ if ($target_switch eq "") {
 #
 sub main
 {
-	my $found_switch = undef;
+	my $found_switch = 0;
 	open IBNET_TOPO, "<$cache_file" or die "Failed to open ibnet topology\n";
 	my $in_switch = "no";
 	my %ports     = undef;
@@ -104,12 +104,14 @@ sub main
 			my $desc = $2;
 			if ($in_switch eq "yes") {
 				$in_switch = "no";
-				goto DONE;
+				foreach my $port (sort { $a <=> $b } (keys %ports)) {
+					print $ports{$port};
+				}
 			}
 			if ("0x$guid" eq $target_switch || $desc =~ /[\s\"]$target_switch[\s\"]/) {
 				print $line;
 				$in_switch    = "yes";
-				$found_switch = "yes";
+				$found_switch++;
 			}
 		}
 		if ($line =~ /^Ca.*/) { $in_switch = "no"; }
@@ -119,14 +121,13 @@ sub main
 		}
 
 	}
-	DONE:
-	foreach my $port (sort { $a <=> $b } (keys %ports)) {
-		print $ports{$port};
-	}
-	if (!$found_switch) {
+	if ($found_switch == 0) {
 		print "Switch \"$target_switch\" not found\n";
 		print "   Try running with the \"-R\" option.\n";
 	}
+	if ($found_switch > 1) {
+		print "\nWARNING: Found $found_switch switches with the name \"$target_switch\"\n";
+	}
 	close IBNET_TOPO;
 }
 main
-- 
1.5.4.5




More information about the general mailing list