3 # Copyright (c) 2006 The Regents of the University of California.
4 # Copyright (c) 2007-2008 Voltaire, Inc. All rights reserved.
6 # Produced at Lawrence Livermore National Laboratory.
7 # Written by Ira Weiny <weiny2@llnl.gov>.
9 # This software is available to you under a choice of one of two
10 # licenses. You may choose to be licensed under the terms of the GNU
11 # General Public License (GPL) Version 2, available from the file
12 # COPYING in the main directory of this source tree, or the
13 # OpenIB.org BSD license below:
15 # Redistribution and use in source and binary forms, with or
16 # without modification, are permitted provided that the following
19 # - Redistributions of source code must retain the above
20 # copyright notice, this list of conditions and the following
23 # - Redistributions in binary form must reproduce the above
24 # copyright notice, this list of conditions and the following
25 # disclaimer in the documentation and/or other materials
26 # provided with the distribution.
28 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43 # =========================================================================
48 print "Usage: $prog [-R -l] [-G <ca_guid> | <node_name>]\n";
49 print " print only the ca specified from the ibnetdiscover output\n";
50 print " -R Recalculate ibnetdiscover information\n";
51 print " -l list cas\n";
52 print " -C <ca_name> use selected channel adaptor name for queries\n";
53 print " -P <ca_port> use selected channel adaptor port for queries\n";
54 print " -G node is specified with GUID\n";
58 my $argv0 = `basename $0`;
59 my $regenerate_map = undef;
60 my $list_hcas = undef;
63 my $name_is_guid = "no";
65 if (!getopts("hRlC:P:G")) { usage_and_exit $argv0; }
66 if (defined $Getopt::Std::opt_h) { usage_and_exit $argv0; }
67 if (defined $Getopt::Std::opt_R) { $regenerate_map = $Getopt::Std::opt_R; }
68 if (defined $Getopt::Std::opt_l) { $list_hcas = $Getopt::Std::opt_l; }
69 if (defined $Getopt::Std::opt_C) { $ca_name = $Getopt::Std::opt_C; }
70 if (defined $Getopt::Std::opt_P) { $ca_port = $Getopt::Std::opt_P; }
71 if (defined $Getopt::Std::opt_G) { $name_is_guid = "yes"; }
73 my $target_hca = $ARGV[0];
75 if ($name_is_guid eq "yes") {
76 $target_hca = format_guid($target_hca);
79 my $cache_file = get_cache_file($ca_name, $ca_port);
81 if ($regenerate_map || !(-f "$cache_file")) {
82 generate_ibnetdiscover_topology($ca_name, $ca_port);
86 system("ibhosts $cache_file");
90 if ($target_hca eq "") {
91 usage_and_exit $argv0;
94 # =========================================================================
99 open IBNET_TOPO, "<$cache_file" or die "Failed to open ibnet topology\n";
102 while (my $line = <IBNET_TOPO>) {
103 if ($line =~ /^Ca.*\"H-(.*)\"\s+# (.*)/) {
106 if ($in_hca eq "yes") {
108 foreach my $port (sort { $a <=> $b } (keys %ports)) {
112 if ("0x$guid" eq $target_hca || $desc =~ /[\s\"]$target_hca[\s\"]/) {
118 if ($line =~ /^Switch.*/ || $line =~ /^Rt.*/) { $in_hca = "no"; }
120 if ($line =~ /^\[(\d+)\].*/ && $in_hca eq "yes") {
125 if ($found_hca == 0) {
126 die "\"$target_hca\" not found\n" .
127 " Try running with the \"-R\" option.\n" .
128 " If still not found the node is probably down.\n";
130 if ($found_hca > 1) {
131 print "\nWARNING: Found $found_hca CA's with the name \"$target_hca\"\n";