diff --git a/xCAT-client/bin/pping b/xCAT-client/bin/pping index 0c59acf3e..c928d529b 100755 --- a/xCAT-client/bin/pping +++ b/xCAT-client/bin/pping @@ -21,7 +21,7 @@ use IO::Handle; use IO::Select; use Getopt::Long; -my $USAGE="Usage: pping [-i|--interface interface] noderange +my $USAGE="Usage: pping [-i|--interface interfaces] noderange pping -h|--help pping -v|--version\n"; @@ -95,35 +95,54 @@ unless (scalar(@nodes)) { exit 1; } -my $children = 0; -my $inputs = new IO::Select; -$SIG{CHLD} = sub { while (waitpid(-1,WNOHANG) > 0) { $children--; } }; -if ($interface) { - foreach (@nodes) { - s/$/-$interface/; - } +# I think this was only needed when we forked ping ourselves +#my $children = 0; +#my $inputs = new IO::Select; +#$SIG{CHLD} = sub { while (waitpid(-1,WNOHANG) > 0) { $children--; } }; + +my $usenmap = (-x '/usr/bin/nmap' or -x '/usr/local/bin/nmap'); + +my @interfaces; +if ($interface) { @interfaces = split(/,/, $interface); } +else { $interfaces[0] = ''; } + +# Do the pings to the nodes for each interface in sequence. We could consider doing all the interfaces +# in parallel, but then the output would get all mixed up and be confusing for the user. +foreach my $interf (@interfaces) { + my $noderef; + if ($interf) { + # make a copy of the node list and add the interface on + $noderef = [ @nodes ]; + foreach (@$noderef) { s/$/-$interf/; } + } + else { + $noderef = \@nodes; # use the original node list + } + + if ($usenmap) { nmap_pping($noderef); } + else { fping_pping($noderef); } } -if (-x '/usr/bin/nmap' or -x '/usr/local/bin/nmap') { - nmap_pping(); - exit; -} -open (FPING, "fping ".join(' ',@nodes). " 2> /dev/null|") or die("Cannot open fping pipe: $!"); -while () { - if ($_ =~ /is unreachable/) { - s/ is unreachable/: noping/; - } elsif ($_ =~ /is alive/) { - s/ is alive/: ping/; - } - print $_; +sub fping_pping { + my $nodes = shift; + open (FPING, "fping ".join(' ',@$nodes). " 2>&1 |") or die("Cannot open fping pipe: $!"); + while () { + if ($_ =~ /is unreachable/) { + s/ is unreachable/: noping/; + } elsif ($_ =~ /is alive/) { + s/ is alive/: ping/; + } + print $_; + } } sub nmap_pping { + my $nodes = shift; my %deadnodes; - foreach (@nodes) { + foreach (@$nodes) { $deadnodes{$_}=1; } - open (FPING, "nmap -PE --send-ip -sP ".join(' ',@nodes). " 2> /dev/null|") or die("Cannot open nmap pipe: $!"); + open (FPING, "nmap -PE --send-ip -sP ".join(' ',@$nodes). " 2> /dev/null|") or die("Cannot open nmap pipe: $!"); my $node; while () { if (/Host (.*) \(.*\) appears to be up/) { diff --git a/xCAT-client/pods/man1/pping.1.pod b/xCAT-client/pods/man1/pping.1.pod index 0df9262c7..38b34ecc5 100644 --- a/xCAT-client/pods/man1/pping.1.pod +++ b/xCAT-client/pods/man1/pping.1.pod @@ -5,7 +5,7 @@ B - parallel ping the nodes. =head1 SYNOPSIS -B [B<-i>|B<--interface> I] I +B [B<-i>|B<--interface> I] I B [B<-h>|B<--help>] @@ -16,7 +16,7 @@ B {B<-v>|B<--version>} B is a utility used to ping a list of nodes in parallel. B will return an unsorted list of nodes with a ping or noping status. -B front-ends nmap and fping if available. +B front-ends nmap or fping if available. This command does not support the xcatd client/server communication. It must be run on the management node. @@ -24,12 +24,14 @@ This command does not support the xcatd client/server communication. It must be =over 10 -=item B<-i>|B<--interface> I +=item B<-i>|B<--interface> I -An interface name that should be pinged instead of the interface represented by the nodename/hostname. +A comma separated list of network interface names that should be pinged instead of the interface represented by the nodename/hostname. The following name resolution convention is assumed: an interface is reachable by the hostname -. For example, the ib2 interface on node3 has a hostname of node3-ib2. +If more than one interface is specified, each interface will be combined with the nodenames as described above and will be pinged in turn. + =item B<-h>|B<--help> Show usage information. @@ -48,18 +50,20 @@ Display the installed version of xCAT. pping all - blade7: ping - blade8: ping - blade9: ping - devmaster: ping - node4: ping - node2: noping + node1: ping + node2: ping + node3: noping =item 2. -pping all -i eth1 +pping all -i ib0,ib1 - node2-eth1: noping + node1-ib0: ping + node2-ib0: ping + node3-ib0: noping + node1-ib1: ping + node2-ib1: ping + node3-ib1: noping =back