AFS-Monitor

 view release on metacpan or  search on metacpan

CHANGES  view on Meta::CPAN


 * changed permissions from 755 to 0755 in Makefile.PL
 * ExtUtils::MakeMaker's PERL_MM_USE_DEFAULT environment variable is now obeyed
 * fixed a problem to make it compile on 32 bit RHEL4
 All fixes were submitted by Wolfgang Friebel <Wolfgang.Friebel at desy.de> - Thanks!


Version 0.3.0 (released April 27, 2006)

 * made everything work with OpenAFS-1.4.1
 * cmdebug: PrintCacheEntries() now contains the strings and not the number of the file types
 * added new CallBack statistics from OpenAFS-1.4.1 file servers to xstat_fs_test()
 * added example for CallBack statistics to examples/xstat_fs_test
 * added new statistics "rx_nBusies", "fs_nBusies", "fs_GetCapabilities" to xstat_fs_test()
 * changed call by value to call by reference in a number of functions which reduces the
   memory usage
 * some general code cleanup


Version 0.2.2 (released January 17, 2005)

MANIFEST  view on Meta::CPAN

CHANGES
LICENCES/Artistic
LICENCES/IBM-LICENCE
LICENCES/COPYING
LICENCES/Stanford-LICENCE
Makefile.PL
examples/configs/configfile
examples/configs/badconfig
examples/Meltdown.pl
examples/scripts/HandlerScript
examples/udebug
examples/afsmonitor
examples/scout
examples/cmdebug
examples/rxdebug
examples/xstat_cm_test
examples/xstat_fs_test
pod/Makefile
pod/cmdebug.pod
pod/rxdebug.pod
pod/scout.pod
pod/afsmonitor.pod
pod/udebug.pod
pod/xstat_cm_test.pod
pod/xstat_fs_test.pod
pod/afsmon_stats.pod
pod/Monitor.pod
src/Monitor.xs
src/Makefile.PL
src/ppport.h
src/t/Monitor.t
src/afsmon-labels.h
src/Monitor.pm

Makefile.PL  view on Meta::CPAN


my $VERSION = "0.3.3";

# provide the POD documentation
mkdir('./lib', 0755);
mkdir('./lib/AFS', 0755);
mkdir('./lib/AFS/Monitor', 0755);
system("cp ./pod/Monitor.pod       lib/AFS/Monitor.pod");
system("cp ./pod/afsmon_stats.pod  lib/AFS/Monitor/afsmon_stats.pod");
system("cp ./pod/afsmonitor.pod    lib/AFS/Monitor/afsmonitor.pod");
system("cp ./pod/cmdebug.pod       lib/AFS/Monitor/cmdebug.pod");
system("cp ./pod/rxdebug.pod       lib/AFS/Monitor/rxdebug.pod");
system("cp ./pod/scout.pod         lib/AFS/Monitor/scout.pod");
system("cp ./pod/udebug.pod        lib/AFS/Monitor/udebug.pod");
system("cp ./pod/xstat_cm_test.pod lib/AFS/Monitor/xstat_cm_test.pod");
system("cp ./pod/xstat_fs_test.pod lib/AFS/Monitor/xstat_fs_test.pod");


WriteMakefile(
              'NAME'       => 'AFS::Monitor',
              'VERSION'    => $VERSION,
              ($] >= 5.005 ?
                   ('AUTHOR'   => 'Alf Wachsmann, Elizabeth Cassell, and Steven Jenkins',
                    'ABSTRACT' => 'Perl interface to AFS monitoring and debugging APIs'
                   ) : () ),
              'realclean'  => {FILES => 'Makefile.bak pod/*.html pod/pod2htm* lib/AFS/*.pod lib/AFS/Monitor/*.pod examples/debug_out/debug examples/debug_out/outputfile lib'},
             );


sub MY::postamble {
	'
html: Makefile
	cd pod && $(MAKE) html

pod: blib
	cp pod/Monitor.pod       lib/AFS/Monitor.pod
	cp pod/afsmon_stats.pod  lib/AFS/Monitor/afsmon_stats.pod
	cp pod/afsmonitor.pod    lib/AFS/Monitor/afsmonitor.pod
	cp pod/cmdebug.pod       lib/AFS/Monitor/cmdebug.pod
	cp pod/rxdebug.pod       lib/AFS/Monitor/rxdebug.pod
	cp pod/scout.pod         lib/AFS/Monitor/scout.pod
	cp pod/udebug.pod        lib/AFS/Monitor/udebug.pod
	cp pod/xstat_cm_test.pod lib/AFS/Monitor/xstat_cm_test.pod
	cp pod/xstat_fs_test.pod lib/AFS/Monitor/xstat_fs_test.pod
';
}

README  view on Meta::CPAN

This is the README file for the Perl extension module AFS::Monitor (Version 0.3.3)


DESCRIPTION
    The AFS::Monitor module is a dynamically loadable extension to
    Perl. It gives the AFS user and administrator access to most of the
    AFS monitoring and debugging functions, allowing you to make these calls
    directly from Perl, rather than processing the output of a command.


REQUIREMENTS
    Before you can build the AFS module you need to have the
    following installed on your system:

        * Perl 5.6.1 or newer (haven't tested on any older versions)
        * system libraries for OpenAFS 1.2.x and newer (it is unknown
	whether IBM AFS wil work)

examples/Meltdown.pl  view on Meta::CPAN

#!/usr/bin/perl
#
# Meltdown.pl - Used to collect stats on running AFS process with rxdebug.
#
# Original Implementation:
#	Unknown - Meltdown.csh, Meltdown.awk
#
# Change History:
#	Jul 02, 2002 - Rex Basham - Added check for wproc, left out during the
#				    original conversion from awk/csh scripts.
#	Mar 21, 2002 - Rex Basham - Merged original csh and awk scripts
#	                            and converted to perl
#	Mar 23, 2002 - Rex Basham - Fixed the display format and added

examples/Meltdown.pl  view on Meta::CPAN

#
#   Aug 30, 2006 - Jeff Blaine - Added CSV stats output mode
#
# Parameters are -s <server> -p <port> -t <sleeptime in seconds>
# and -C to enable CSV-output mode
#
# Example:
#	Meltdown.pl -s point -p 7000 -t 300
#
#	Check the server 'point' on port '7000' with 5 minutes between
#	rxdebug commands.
#

use blib;
use AFS::Monitor;

sub Usage {
	print STDERR "\n\n$progName: collect rxdebug stats on AFS process.\n";
	print STDERR "usage: $progName [options]\n";
	print STDERR "options:\n";
	print STDERR " -s <server>    (required parameter, no default).\n";
	print STDERR " -p <port>      (default: 7000).\n";
	print STDERR " -t <interval>  (default: 1200 seconds).\n";
	print STDERR " -C             \n";
	print STDERR " -h             (help: show this help message).\n\n";
	print STDERR "Example: $progName -s point -p 7000\n";
	print STDERR "Collect statistics on server point for port 7000\n";
	print STDERR "Refresh interval will default to 20 minutes (1200 seconds)\n\n";

examples/Meltdown.pl  view on Meta::CPAN

	#
	# snag the current time
	#
	($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isDST) = localtime();


	#
	# fire the command and collect the stats
	#

	$rx = rxdebug(servers => $server,
		port => $port,
		rxstats => 1,
		noconns => 1
		);

	# $wpack doesn't seem to have a corresponding value.
        # It is always zero.

	$tstats = $rx->{tstats};

examples/afsmonitor  view on Meta::CPAN


use blib;
use strict;
use AFS::Monitor;
use Data::Dumper;

my @cmhosts = ("www.openafs.org", "virtue.openafs.org", "andrew.e.kth.se");  # cache manager machines to monitor
my @fshosts = ("www.openafs.org", "virtue.openafs.org", "andrew.e.kth.se"); # file server machines to monitor
my $configfilename = 'configs/configfile';
my $badconfigfile  = 'configs/badconfig';
my $outputfilename = 'debug_out/outputfile';

my @tests;      # choose which tests to run
$tests[1] = 1;  # test of FS afsmonitor with detailed output file
$tests[2] = 2;  # test of CM afsmonitor
$tests[3] = 0;  # test of invalid file name
$tests[4] = 0;  # test of detailed flag without output flag
$tests[5] = 0;  # test of invalid FS host
$tests[6] = 0;  # test of invalid CM host
$tests[7] = 0;  # test of no flags
$tests[8] = 0;  # test of cmhosts and fshosts and config flags all at once

examples/cmdebug  view on Meta::CPAN

#!/usr/bin/perl -w
#
# Copyright © 2004 Alf Wachsmann <alfw@slac.stanford.edu> and
#                  Elizabeth Cassell <e_a_c@mailsnare.net>
#
# $Revision: 1.8 $ $Date: 2006/07/05 22:25:10 $ $Author: alfw $
#

use blib;
use strict;
use AFS::Monitor qw(cmdebug constant);
use Data::Dumper;

#my $server = "virtue.openafs.org";
my $server = "afs04.slac.stanford.edu";
my $port   = 7001;

my @tests;      # choose which tests to run
$tests[1] = 1;  # test of server $server, port $port, long output
$tests[2] = 0;  # test of server $server, no port
$tests[3] = 0;  # test of nonexistant server
$tests[4] = 0;  # test of server $server, bad port
$tests[5] = 0;  # test of server $server, port $port

my $all = 0;

my $showdump = 1;   # print entire contents of hash for each test
my $formatted = 1;  # print output formatted like the c cmdebug program

print "# Starting now... #\n";
my $locks;
my $cache_entries;

if ($all || $tests[1]) {
  print "\n******** TEST 1: ********\n";

  print "\ncmdebug -server $server -port $port -long\n\n";

  ($locks, $cache_entries) = cmdebug(server => $server,
                                     port   => $port,
                                     long   => 1
                                    );
  parse_result($locks, $cache_entries);
}

if ($all || $tests[2]) {
  print "\n******** TEST 2: ********\n";

  print "\ncmdebug -server $server\n\n";

  ($locks, $cache_entries) = cmdebug(server => $server);
  parse_result($locks, $cache_entries);
}

if ($all || $tests[3]) {
  print "\n******** TEST 3: ********\n";

  print "\ncmdebug -server nonexistant\n\n";

  ($locks, $cache_entries) = cmdebug(server => "nonexistant");
  parse_result($locks, $cache_entries);
}

if ($all || $tests[4]) {
  print "\n******** TEST 4: ********\n";

  print "\ncmdebug -server $server -port 7001\n\n";

  ($locks, $cache_entries) = cmdebug(server => $server,
                                     port   => 7001
                                    );
  parse_result($locks, $cache_entries);
}

if ($all || $tests[5]) {
  print "\n******** TEST 5: ********\n";

  print "\ncmdebug -server $server -port $port\n\n";

  ($locks, $cache_entries) = cmdebug(server => $server,
                                     port   => $port
                                    );
  parse_result($locks, $cache_entries);
}


sub parse_result {
  my $l = shift;
  my $c = shift;

examples/rxdebug  view on Meta::CPAN

#!/usr/bin/perl -w
#
# Copyright © 2004 Alf Wachsmann <alfw@slac.stanford.edu> and
#                  Elizabeth Cassell <e_a_c@mailsnare.net>
#
# $Revision: 1.9 $ $Date: 2004/10/22 15:04:40 $ $Author: alfw $
#

use blib;
use strict;
use AFS::Monitor qw(rxdebug constant);
use Data::Dumper;

my $servers  = 'virtue.openafs.org'; # machine to run this on
my $port     = 7001;      # port to run this on
my $onlyhost = 'andrew.e.kth.se';  # some of the tests will show only connections from this host
my $onlyport = 7000;      # some of the tests will show only connections on this port
my $onlyauth = 'auth';    # some of the tests will show only connections with this auth level

my @tests;      # choose which tests to run
$tests[1] = 1;  # prints version

examples/rxdebug  view on Meta::CPAN

$tests[11] = 0; # shows all server connections. (can be long)
$tests[12] = 0; # shows all client connections on port $port from host $onlyhost
$tests[13] = 0; # doesn't give port, tries default (7000).
$tests[14] = 0; # no arguments, runs on current machine with default port.
$tests[15] = 0; # port $port, runs on current machine.
$tests[16] = 0; # prints rxstats, all connections, long version of all peers.
                # (can be very long)

my $all = 1;    # show all tests

my $showdump = 0; # dump contents of hash to the screen for each test instead of printing rxdebug formatted output

# all available options:
# rxdebug(nodally        => 1,
#         allconnections => 1,
#         rxstats        => 1,
#         onlyserver     => 1,
#         onlyclient     => 1,
#         onlyport       => $onlyport,
#         version        => 1,
#         noconns        => 1,
#         peers          => 1,
#         long           => 1,
#         servers        => $servers, # required

examples/rxdebug  view on Meta::CPAN

#         onlyhost       => $onlyhost,
#         onlyauth       => $onlyauth,
#        );

print "***** Starting now... *****\n";
my $rxdeb;

if ($all || $tests[1]) {
  print "\n******** TEST 1: ********\n";

  print "\nrxdebug -version -servers $servers -port $port\n\n";

  $rxdeb = rxdebug(version => 1,
                   servers => $servers, # required
                   port    => $port
                  );
  parse_results($rxdeb);
}

if ($all || $tests[2]) {
  print "\n******** TEST 2: ********\n";

  print "\nrxdebug -nodally -allconnections -peers -servers $servers -port $port\n\n";

  $rxdeb = rxdebug(nodally        => 1,
                   allconnections => 1,
                   peers          => 1,
                   servers        => $servers,
                   port           => $port
                  );
  parse_results($rxdeb);
}

if ($all || $tests[3]) {
  print "\n******** TEST 3: ********\n";

  print "\nrxdebug -servers speedy1 -port $port\n\n";

  $rxdeb = rxdebug(servers => 'speedy1',
                   port    => $port
                  );
  parse_results($rxdeb);
}

if ($all || $tests[4]) {
  print "\n******** TEST 4 ********\n";

  print "\nrxdebug -servers $servers -port no\n\n";

  $rxdeb = rxdebug(servers => $servers,
                   port    => 'no'
                  );
  parse_results($rxdeb);
}

if ($all || $tests[5]) {
  print "\n******** TEST 5 ********\n";

  print "\nrxdebug -servers $servers -port 643543\n(may take a while..)\n\n";

  $rxdeb = rxdebug(servers => $servers,
                   port    => 643543
                  );
  parse_results($rxdeb);
}

if ($all || $tests[6]) {
  print "\n******** TEST 6 ********\n";

  print "\nrxdebug -servers $servers -port $port -noconns -peers -long\n\n";

  $rxdeb = rxdebug(servers => $servers,
                   port    => $port,
                   noconns => 1,
                   peers   => 1,
                   long    => 1
                  );
  parse_results($rxdeb);
}

if ($all || $tests[7]) {
  print "\n******** TEST 7 ********\n";

  print "\nrxdebug -servers $servers -port $port\n\n";

  $rxdeb = rxdebug(servers => $servers,
                   port    => $port
                  );
  parse_results($rxdeb);
}

if ($all || $tests[8]) {
  print "\n******** TEST 8 ********\n";

  print "\nrxdebug -noconns -servers $servers -port $port -rxstats\n\n";

  $rxdeb = rxdebug(noconns => 1,
                   servers => $servers,
                   port    => $port,
                   rxstats => 1
                  );
  parse_results($rxdeb);
}

if ($all || $tests[9]) {
  print "\n******** TEST 9 ********\n";

  print "\nrxdebug -servers $servers -port $port -onlyauth $onlyauth\n\n";

  $rxdeb = rxdebug(servers  => $servers,
                   port     => $port,
                   onlyauth => $onlyauth
                  );
  parse_results($rxdeb);
}

if ($all || $tests[10]) {
  print "\n******** TEST 10 ********\n";

  print "\nrxdebug -servers $servers -port $port -allconnections\n\n";

  $rxdeb = rxdebug(servers        => $servers,
                   port           => $port,
                   allconnections => 1
                  );
  parse_results($rxdeb);
}

if ($all || $tests[11]) {
  print "\n******** TEST 11 ********\n";

  print "\nrxdebug -servers $servers -port $port -allconnections -onlyserver\n\n";

  $rxdeb = rxdebug(allconnections => 1,
                   onlyserver     => 1,
                   servers        => $servers,
                   port           => $port
                  );
  parse_results($rxdeb);
}

if ($all || $tests[12]) {
  print "\n******** TEST 12 ********\n";

  print "\nrxdebug -servers $servers -port $port -allconnections -onlyclient -onlyport $onlyport -onlyhost $onlyhost\n\n";

  $rxdeb = rxdebug(allconnections => 1,
                   onlyclient     => 1,
                   onlyport       => $onlyport,
                   servers        => $servers,
                   port           => $port,
                   onlyhost       => $onlyhost
                  );
  parse_results ($rxdeb);
}

if ($all || $tests[13]) {
  print "\n******** TEST 13 ********\n";

  print "\nrxdebug -servers $servers\n\n";

  $rxdeb = rxdebug(servers => $servers);
  parse_results ($rxdeb);
}

if ($all || $tests[14]) {
  print "\n******** TEST 14 ********\n";

  print "\nrxdebug 0\n\n";

  $rxdeb = rxdebug();
  parse_results ($rxdeb);
}

if ($all || $tests[15]) {
  print "\n******** TEST 15 ********\n";

  print "\nrxdebug 0 -port $port\n\n";

  $rxdeb = rxdebug(port => $port);
  parse_results ($rxdeb);
}

if ($all || $tests[16]) {
  print "\n******** TEST 16 ********\n";

  print "\nrxdebug -servers $servers -port $port -allconnections -peers -long -rxstats\n\n";

  $rxdeb = rxdebug(allconnections => 1,
                   rxstats        => 1,
                   peers          => 1,
                   long           => 1,
                   servers        => $servers,
                   port           => $port
                  );
  parse_results($rxdeb);
}


examples/rxdebug  view on Meta::CPAN


  # print entire hash to screen
  if ($showdump) {
    print Dumper($val);
    return;
  }

  # print ip address and port
  print "For ", $val->{address}, " (port ", $val->{port}, ") ...\n";

  # prints everything as the rxdebug function would

  # print version if it was returned
  if (exists $val->{version}) {
    print "AFS version: ", $val->{version}, "\n";
  }

  # print tstats if they were returned
  if (exists $val->{tstats}) {
    print "Free packets: $val->{tstats}->{nFreePackets}, ";
    print "packet reclaims: $val->{tstats}->{packetReclaims}, ";

examples/scout  view on Meta::CPAN

#
# $Revision: 1.6 $ $Date: 2004/10/22 15:04:40 $ $Author: alfw $
#

use blib;
use strict;
use AFS::Monitor;
use Data::Dumper;

my @servers   = ("virtue");
my $debugfile = "debug_out/debug";
my $basename  = "openafs.org";

my @tests;      # choose which tests to run
$tests[1] = 1;  # blank
$tests[2] = 1;  # blank

my $all = 0;

my $showdump = 1;   # print entire contents of hash for each test
my $formatted = 0;  # print formatted, easy to read output
my $scout = 1;      # print only the information displayed by the original (c) scout program

print "# Starting now... #\n";
my $result;


if ($all || $tests[1]) {
  print "\n******** TEST 1: ********\n";

  print "\nscout -server ", join(" ", @servers),
        " -debug $debugfile -basename $basename\n\n";

  $result = scout(server   => \@servers,
                  debug    => $debugfile,
                  basename => $basename);
  parse_result($result);
}


if ($all || $tests[2]) {
  print "\n******** TEST 2: ********\n";

  print "\nscout -server virtue.openafs.org\n\n";

examples/udebug  view on Meta::CPAN

#!/usr/bin/perl -w
#
# Copyright © 2004 Alf Wachsmann <alfw@slac.stanford.edu> and
#                  Elizabeth Cassell <e_a_c@mailsnare.net>
#
# $Revision: 1.8 $ $Date: 2004/10/22 15:04:40 $ $Author: alfw $
#

use blib;
use strict;
use AFS::Monitor qw(udebug constant);
use Data::Dumper;

my $server          = "virtue.openafs.org";
my $non_sync_server = "andrew.e.kth.se";
my $port            = 7003;

my @tests;      # choose which tests to run
$tests[1] = 0;  # test of server $server, port $port, long output
$tests[2] = 0;  # test of server $non_sync_server, port $port, short output
$tests[3] = 0;  # test of server $non_sync_server, port $port, long output
$tests[4] = 0;  # test of server $server, no port
$tests[5] = 1;  # test of nonexistant server
$tests[6] = 1;  # test of server $server, bad port
$tests[7] = 0;  # test of server $server, port $port

my $all = 0;

my $showdump = 0;   # print entire contents of hash for each test
my $formatted = 1;  # print output formatted like the C udebug program


print "# Starting now... #\n";
my $result;

if ($all || $tests[1]) {
  print "\n******** TEST 1: ********\n";

  print "\nudebug -server $server -port $port -long\n\n";

  $result = udebug(server => $server,
                   port   => $port
                  );
  parse_result($result);
}

if ($all || $tests[2]) {
  print "\n******** TEST 2: ********\n";

  print "\nudebug -server $non_sync_server -port $port\n\n";

  $result = udebug(server => $non_sync_server,
                   port   => $port
                  );
  parse_result($result);
}

if ($all || $tests[3]) {
  print "\n******** TEST 3: ********\n";

  print "\nudebug -server $non_sync_server -port $port -long\n\n";

  $result = udebug(server => $non_sync_server,
                   port   => $port,
                   long   => 1
                  );
  parse_result($result);
}

if ($all || $tests[4]) {
  print "\n******** TEST 4: ********\n";

  print "\nudebug -server $server\n\n";

  $result =udebug(server => $server);
  parse_result($result);
}

if ($all || $tests[5]) {
  print "\n******** TEST 5: ********\n";

  print "\nudebug -server nonexistant\n\n";

  $result = udebug(server => "nonexistant");
  parse_result($result);
}

if ($all || $tests[6]) {
  print "\n******** TEST 6: ********\n";

  print "\nudebug -server $server -port 7001\n\n";

  $result = udebug(server => $server,
                   port   => 7001
                  );
  parse_result($result);
}

if ($all || $tests[7]) {
  print "\n******** TEST 7: ********\n";

  print "\nudebug -server $server -port $port\n\n";

  $result = udebug(server => $server,
                   port   => $port
                  );
  parse_result($result);
}


sub parse_result {
  my $info = shift;

  if ($AFS::CODE) {

pod/Makefile  view on Meta::CPAN

CONVERTERS = pod2html

POD2HTML = $(P2H) \
	    --htmlroot=./ \
	    --podpath=./ \
	    --verbose \
	    --noindex \
	    --libpods=Monitor:afsmon_stats:afsmonitor:cmdebug:rxdebug:scout:udebug:xstat_cm_test:xstat_fs_test

all: $(CONVERTERS)

converters: $(CONVERTERS)

P2H = /usr/local/bin/pod2html

POD = \
	afsmon_stats.pod  \
	afsmonitor.pod    \
	Monitor.pod  \
	cmdebug.pod       \
	rxdebug.pod       \
	scout.pod         \
	udebug.pod        \
	xstat_cm_test.pod \
	xstat_fs_test.pod

HTML = \
	afsmon_stats.html  \
	afsmonitor.html    \
	Monitor.html  \
	cmdebug.html       \
	rxdebug.html       \
	scout.html         \
	udebug.html        \
	xstat_cm_test.html \
	xstat_fs_test.html

html:	$(P2H) $(HTML)

.SUFFIXES: .pm .pod

.SUFFIXES: .html

.pod.html:

pod/Monitor.pod  view on Meta::CPAN

#------------------------------------------------------------------------------
# afsperldebug.pod
#
# Copyright © 2004-2006 Alf Wachsmann <alfw@slac.stanford.edu> and
#                  Elizabeth Cassell <e_a_c@mailsnare.net>
#
# $Revision: 1.2 $ $Date: 2006/07/05 22:25:10 $ $Author: alfw $
#
# This library is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#------------------------------------------------------------------------------

=head1 NAME

B<AFS::Monitor> - Perl interface to AFS monitoring and debugging tools

=head1 DESCRIPTION

=over

=item B<afsmonitor>

Gathers statistics about specified File Server and Cache Manager operations.
There are 271 available File Server statistics and 571 available Cache Manager
statistics, listed in L<afsmon_stats(1)>.
See L<afsmonitor(1)>

=item B<cmdebug>

Reports status of cache manager and cache entries on a particular AFS
client machine. See L<cmdebug(1)>

=item B<rxdebug>

Provides debugging trace of Rx activity for a specified server or client
machine. See L<rxdebug(1)>

=item B<scout>

Gathers statistics from the File Server processes running on the specified
machines. See L<scout(1)>

=item B<udebug>

Reports the status of the Ubik process associated with a database server
process. See L<udebug(1)>

=item B<xstat_cm_test>

Gathers the specified data collections associated with the specified Cache
Manager. See L<xstat_cm_test(1)>

=item B<xstat_fs_test>

Gathers the specified data collections associated with the specified File
Server process. See L<xstat_fs_test(1)>

pod/cmdebug.pod  view on Meta::CPAN

#------------------------------------------------------------------------------
# cmdebug.pod
#
# Copyright © 2004 Alf Wachsmann <alfw@slac.stanford.edu> and
#                  Elizabeth Cassell <e_a_c@mailsnare.net>
#
# This library is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#------------------------------------------------------------------------------

=head1 NAME

B<cmdebug> - Reports status of cache manager and cache entries on a particular AFS client machine.

=head1 SYNOPSIS

  use AFS::Monitor qw(cmdebug);

  my ($locks, $cache_entries) =
      cmdebug(server => "hostName",
              port   => 7001,
              long   => 1
             );

=head1 DESCRIPTION

The B<cmdebug> function can be used to examine the status of the
cache manager and cache entries on a particular AFS client machine.
This function is useful when you suspect that the cache manager is
hung, or is performing poorly.

=head1 OPTIONS

=over

=item B<server>

pod/cmdebug.pod  view on Meta::CPAN

This switch is only useful with port 7001 since that is the
callback port.

=item B<long>

This switch will display the status of all of the cache entries
on the AFS client when there are no problems.

=back

As a first step in diagnosing a problem, run B<cmdebug> without the
B<long> switch. A machine running in a normal state (i.e. not
experiencing any problems), may display some locks set, but these
locks should not be continually set over multiple B<cmdebug>s. If the
functions returns with no output, it simply means there is nothing
to report.

=head1 OUTPUT

The return values are references to two arrays.
Each entry in the first array represents the status of the cache manager's data
structures. Each entry in the second array represents an individual cache entry.

=head1 AUTHORS

pod/rxdebug.pod  view on Meta::CPAN

#------------------------------------------------------------------------------
# rxdebug.pod
#
# Copyright © 2004 Alf Wachsmann <alfw@slac.stanford.edu> and
#                  Elizabeth Cassell <e_a_c@mailsnare.net>
#
# This library is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#------------------------------------------------------------------------------

=head1 NAME

B<rxdebug> - Provides debugging trace of Rx activity

=head1 SYNOPSIS

  use AFS::Monitor qw(rxdebug);

  my $rxd = rxdebug(version => 1,
                    servers => 'hostname',
                   );
  print "AFS build level of $rxd->{address} port $rxd->{port} is:";
  print $rxd->{version};

  $rxd = rxdebug(rxstats => 1,
                 noconns => 1,
                 servers => 'hostname',
                 port    => 7001,
                );

  $rxd = rxdebug(noconns  => 1,
                 peers    => 1,
                 long     => 1,
                 servers  => 'hostname',
                 port     => 7001,
                );

  $rxd = rxdebug(allconnections => 1,
                 servers        => 'hostname',
                 port           => 7002,
                );

  $rxd = rxdebug(nodally      => 1,
                 onlyserver   => 1,
                 onlyhost     => 'host2',
                 servers      => 'hostname',
                 port         => 7001,
                );

  $rxd = rxdebug(onlyclient   => 1,
                 onlyport     => 7002,
                 onlyauth     => 'crypt',
                 servers      => 'hostname',
                 port         => 7001,
                );

=head1 DESCRIPTION

The B<rxdebug> function provides a trace of Rx activity for the
server or client machine named by the B<servers> argument. Rx
is AFS's proprietary remote procedure call (RPC) protocol,
so this function enables the issuer to check the status of
communication between the Cache Manager or an AFS server
process (as specified with the B<port> argument) on the
machine and one or more processes on other machines.

=head1 OPTIONS

=over

pod/rxdebug.pod  view on Meta::CPAN

C<peers>: a reference to an array of hash references containing information about each peer.

=back

The simplest case would be if the version flag was set.
The hash table would have only three keys in it:
C<address>, C<port>, and C<version>.

For more details about the contents of the returned hash reference,
and an example of printing its entire contents in a readable format,
refer to the B<rxdebug> script in the B<examples> directory.


=head1 AUTHORS

The code and documentation for this class were contributed by Stanford
Linear Accelerator Center, a department of Stanford University.  This
documentation was written by

=over

pod/scout.pod  view on Meta::CPAN


=head1 SYNOPSIS

  use AFS::Monitor qw(scout);
  my $scout;

  $scout = scout(server   => "serverName1");

  $scout = scout(server   => ["serverName1", "serverName2"],
                 basename => "example.com",
                 debug    => "debug_out/debug.file"
                );

=head1 DESCRIPTION

The B<scout> function gathers statistics from the File Server process running
on each machine specified with the B<server> argument. The B<Output> section
explains the meaning of the statistics.

=head1 OPTIONS

pod/scout.pod  view on Meta::CPAN

=item B<basename>

String that specifies the basename (domain name) suffix common to all of the
file server machine names specified with the B<server> argument, and is
automatically appended to them. This argument is normally the name of the cell
to which the machines belong. Do not include the period that separates this
suffix from the distinguishing part of each file server machine name, but do
include any periods that occur within the suffix itself. For example, in the
ABC Corporation cell, the proper value is abc.com rather than .abc.com.

=item B<debug>

Specifies the pathname of the file into which to write a debugging trace.
Partial pathnames are interpreted relative to the current working directory.

=back

=head1 OUTPUT

Returns a reference to an array, with one element per host specified. Each
element in the array is a reference to a hash containing information about the
file server, as described below.

pod/udebug.pod  view on Meta::CPAN

#------------------------------------------------------------------------------
# udebug.pod
#
# Copyright © 2004 Alf Wachsmann <alfw@slac.stanford.edu> and
#                  Elizabeth Cassell <e_a_c@mailsnare.net>
#
# This library is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#------------------------------------------------------------------------------

=head1 NAME

B<udebug> - Reports status of Ubik process associated with a database server process

=head1 SYNOPSIS

  use AFS::Monitor qw(udebug);

  my $udb = udebug(server => "hostName",
                   port   => 7002,
                   long   => 1
                  );

  $udb = udebug(server => "hostName",
                port   => 7021
               );

=head1 DESCRIPTION

The B<udebug> function returns the status of the lightweight
Ubik process for the database server process identified by
the B<port> argument that is running on the database server
machine named by the B<server> argument. The output identifies
the machines where peer database server processes are running,
which of them is the synchronization site (Ubik coordinator),
and the status of the connections between them.

=head1 OPTIONS

=over

pod/udebug.pod  view on Meta::CPAN


=item B<now>

The time according to the clock on the database server machine
specified by the B<server> argument, measured in seconds since the
Epoch (00:00:00 UTC, January 1, 1970). For correct Ubik operation,
the database server machine clocks must agree on the time.

=item B<lastYesHost>, B<lastYesTime> and B<lastYesClaim>

If the B<udebug> function was issues during the coordinator election
process and voting has not yet begun, this key will not exist.
Otherwise, this key indicates which peer this Ubik process last voted
for as coordinator (it can vote for itself). The key B<lastYesTime>
contains the time (in seconds since the Epoch), of the vote. The key
B<lastYesClaim> contains the time (in seconds since the Epoch) that the
Ubik coordinator requested confirming votes from the secondary sites.
Usually, the B<lastYesTime> and B<lastYesClaim> values are the same;
a difference between them can indicate clock skew or a slow network
connection between the two database server machines. A small difference
is not harmful.

pod/udebug.pod  view on Meta::CPAN

in the quorum.

=item B<recoveryState>

If there are multiple database sites, and the B<server> argument
names the coordinator (synchronization site), then this entry will
contain a hexadecimal number that indicates the current state of the quorum.
A value of C<1f> indicates complete database synchronization, whereas a value
of C<f> means that the coordinator has the correct database but cannot contact
all secondary sites to determine if they also have it. Lesser values are
acceptable if the B<udebug> function is issued during coordinator election, but
they denote a problem if they persist. The individual flags have the
following meanings:

=over

=item C<0x1>

This machine is the coordinator

=item C<0x2>

pod/udebug.pod  view on Meta::CPAN

The database's version number has been updated correctly

=item C<0x10>

All sites have the database with the highest version number

=back

=item B<activeWrite>, B<epochTime> and B<tidCounter>

Indicates whether the B<udebug> function was issued while the coordinator was
writing a change into the database. The entries B<epochTime> and B<tidCounter>
identify the transaction.

=item B<isClone>

True if the machine named by the B<server> argument is a clone, which can
never become sync site.

=item B<lowestHost> and B<syncHost>

pod/udebug.pod  view on Meta::CPAN

=item B<syncVersion>

A reference to a hash containing two entries, B<epoch> and B<counter>,
indicating the version number of the database at the synchronization site,
which needs to match the version number of the local databse, indicated
by B<localVersion> (see above).

=item B<lockedPages> and B<writeLockedPages>

Indicates how many VLDB records are currently locked for any operation
or for writing in particular. The values are nonzero if the B<udebug> function
is issued while an operation is in progress.

=item B<anyReadLocks> and B<anyWriteLocks>

These values are true if there are any read or write locks on database records.

=item B<currentTrans> and B<writeTrans>

These values are true if there are any read or write transactions in
progress when the B<udebug> function is issued.

=item B<syncTid>

A reference to a hash containing two entries, B<epoch> and B<counter>, indicating
the transaction tid for the transaction indicated by B<currentTrans> or B<writeTrans>
above.

=item B<epochTime>

If the machine named by the B<server> argument is the coordinator,

pod/udebug.pod  view on Meta::CPAN

indicating the version number of the database it is maintaining.

=item B<isClone>

True if the site is only a clone.

=item B<lastVoteTime>

The time, in seconds since the Epoch, the coordinator last received a vote
message from the Ubik process at the site.
If the B<udebug> function is issued during the coordinator election process
and voting has not yet begun, this will be 0.

=item B<lastBeaconSent>

The time, in seconds since the Epoch, the coordinator last requested a vote message.
If the B<udebug> function is issued during the coordinator election process
and voting has not yet begun, this will be 0.

=item B<lastVote>

True if the last vote was yes; false if the last vote was no.

=item B<currentDB>

1 if the site has the database with the highest version number, 0 if it does not.

pod/udebug.pod  view on Meta::CPAN

guaranteed to be accurate. For example, the value in the B<remoteVersion> field
is usually 0.0, because secondary sites do not poll their peers for this
information. The values in the B<lastVoteTime> and B<lastBeaconSent> fields
indicate when this site last received or requested a vote as coordinator; they
generally indicate the time of the last coordinator election.

=back

For further details of interpreting the contents of the returned hash
reference, and an example of printing its entire contents in a readable
format, refer to the B<udebug> script in the B<examples> directory.

=head1 AUTHORS

The code and documentation for this class were contributed by Stanford
Linear Accelerator Center, a department of Stanford University.  This
documentation was written by

=over

=item Elizabeth Cassell <e_a_c@mailsnare.net> and

src/Monitor.pm  view on Meta::CPAN

require DynaLoader;

use vars qw(@ISA $VERSION);

@ISA = qw(Exporter AutoLoader DynaLoader);

$VERSION = "0.3.2";

@EXPORT = qw (
              afsmonitor
              rxdebug
              udebug
              cmdebug
              scout
              xstat_fs_test
              xstat_cm_test
             );


# Other items we are prepared to export if requested
@EXPORT_OK = qw(
                error_message
		constant
               );

sub rxdebug {
  my %subreq;

  # parse the arguments and build a hash to pass to the XS do_rxdebug call.
  return eval {
    while (@_) {
      $_ = shift;

      if ( @_ and $_[0] !~ /^-/ ) {
        $subreq{$_} = shift;
      }
      else {
        $subreq{$_} = 1;
      }
    }
    my $rxd = do_rxdebug(\%subreq);
    return $rxd;
  }
}

sub afsmonitor {
  my %subreq;

  return eval {
    while (@_) {
      $_ = shift;

src/Monitor.pm  view on Meta::CPAN

      }
      else {
        $subreq{$_} = 1;
      }
    }
    my ($fs, $cm) = do_afsmonitor(\%subreq);
    return ($fs, $cm);
  }
}

sub cmdebug {
  my %subreq;

  return eval {
    while (@_) {
     $_ = shift;

      if ( @_ and $_[0] !~ /^-/ ) {
        $subreq{$_} = shift;
      }
      else {
        $subreq{$_} = 1;
      }
    }
    my ($locks, $cache_entries) = do_cmdebug(\%subreq);
    return ($locks, $cache_entries);
  }
}

sub udebug {
  my %subreq;

  return eval {
    while (@_) {
     $_ = shift;

      if ( @_ and $_[0] !~ /^-/ ) {
        $subreq{$_} = shift;
      }
      else {
        $subreq{$_} = 1;
      }
    }
    my $result = do_udebug(\%subreq);
    return $result;
  }
}

sub scout {
  my %subreq;

  return eval {
    while (@_) {
     $_ = shift;

src/Monitor.xs  view on Meta::CPAN

         croak(buffer);
      }
      sv_setpv(sv, (char *)error_message(code));
   }
   SvIOK_on(sv);
}

/* end of error handling macros */


/* start of rxdebug helper functions */


/*
 * from src/rxdebug/rxdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

static short
rxdebug_PortNumber(aport)
   register char *aport;
{
   register int tc;
   register short total;

   total = 0;
   while ((tc = (*aport++))) {
      if (tc < '0' || tc > '9')
         return -1; /* bad port number */
      total *= 10;
      total += tc - (int)'0';
   }
   return htons(total);
}


/*
 * from src/rxdebug/rxdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

static short
rxdebug_PortName(char *aname)
{
   register struct servent *ts;
   ts = getservbyname(aname, (char *) NULL);
   if (!ts)
      return -1;
   return ts->s_port;   /* returns it in network byte order */
}


/*

src/Monitor.xs  view on Meta::CPAN

   MAXRTT = newHV();
   hv_store(MAXRTT, "sec", 3, newSViv(rxstats->maxRtt.sec), 0);
   hv_store(MAXRTT, "usec", 4, newSViv(rxstats->maxRtt.usec), 0);
   hv_store(RXSTATS, "maxRtt", 6, newRV_inc((SV *) (MAXRTT)), 0);

#if !defined(AFS_PTHREAD_ENV) && !defined(AFS_USE_GETTIMEOFDAY)
   hv_store(RXSTATS, "clock_nUpdates", 14, newSViv(clock_nUpdates), 0);
#endif
}

/* end of rxdebug helper functions */





/* start of afsmonitor helper functions */

/*
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");

src/Monitor.xs  view on Meta::CPAN

      fflush(cm_outFD);
   }

   fclose(cm_outFD);

}   /* my_afsmon_cmOutput() */



/*
 * unchanged except for removing debugging print statements at beginning, and one
 * correction (replacing xstat_cm_Results with a_cmResults)
 *
 * from src/afsmonitor/afsmonitor.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_cm_Results_ltoa(a_cmData, a_cmResults)
   struct cm_Display_Data *a_cmData;    /* target buffer */
   struct xstat_cm_ProbeResults *a_cmResults;   /* ptr to xstat cm Results */

src/Monitor.xs  view on Meta::CPAN

   return (code);

}   /* my_xstat_cm_Cleanup() */



/* end of afsmonitor helper functions */



/* cmdebug helper functions */

/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

static int
IsLocked(register struct AFSDBLockDesc *alock)
{
    if (alock->waitStates || alock->exclLocked || alock->numWaiting
        || alock->readersReading)
        return 1;
    return 0;
}


/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

struct cell_cache {
   afs_int32 cellnum;
   char *cellname;
   struct cell_cache *next;
};


/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

#ifdef USE_GETCELLNAME
static char *
GetCellName(struct rx_connection *aconn, afs_int32 cellnum)
{
   static int no_getcellbynum;
   static struct cell_cache *cache;
   struct cell_cache *tcp;

src/Monitor.xs  view on Meta::CPAN

   tcp->cellnum = cellnum;
   tcp->cellname = cellname;
   cache = tcp;

   return cellname;
}
#endif


/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

void
my_PrintLock(register struct AFSDBLockDesc *alock, HV *LOCK)
{
   hv_store(LOCK, "waitStates", 10, newSViv(alock->waitStates), 0);
   hv_store(LOCK, "exclLocked", 10, newSViv(alock->exclLocked), 0);
   hv_store(LOCK, "pid_writer", 10, newSViv(alock->pid_writer), 0);
   hv_store(LOCK, "src_indicator", 13, newSViv(alock->src_indicator), 0);
   hv_store(LOCK, "readersReading", 14, newSViv(alock->readersReading), 0);
   hv_store(LOCK, "pid_last_reader", 15, newSViv(alock->pid_last_reader), 0);
   hv_store(LOCK, "numWaiting", 10, newSViv(alock->numWaiting), 0);
}


/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_PrintLocks(register struct rx_connection *aconn, int aint32,
              AV *LOCKS, char *buffer)
{
   register int i;
   struct AFSDBLock lock;
   afs_int32 code;
   HV *LOCK;
   HV *LOCKDESC;

   for (i = 0; i < 1000; i++) {
      code = RXAFSCB_GetLock(aconn, i, &lock);
      if (code) {
         if (code == 1)
            break;
         /* otherwise we have an unrecognized error */
         sprintf(buffer, "cmdebug: error checking locks: %s",
                 error_message(code));
         return code;
      }
      /* here we have the lock information, so display it, perhaps */
      if (aint32 || IsLocked(&lock.lock)) {
         LOCK = newHV();
         hv_store(LOCK, "name", 4, newSVpv(lock.name, 0), 0);
         LOCKDESC = newHV();
         my_PrintLock(&lock.lock, LOCKDESC);
         hv_store(LOCK, "lock", 4, newRV_inc((SV *) LOCKDESC), 0);

src/Monitor.xs  view on Meta::CPAN

   char *cellname;
   HV *NETFID;
   HV *CENTRY;
   HV *LOCK;

   for (i = 0; i < 10000; i++) {
      code = RXAFSCB_GetCE(aconn, i, &centry);
      if (code) {
         if (code == 1)
            break;
         sprintf(buffer, "cmdebug: failed to get cache entry %d (%s)", i,
                 error_message(code));
         return code;
      }

      CENTRY = newHV();

      hv_store(CENTRY, "addr", 4, newSViv(centry.addr), 0);

      if (centry.addr == 0) {
         /* PS output */

src/Monitor.xs  view on Meta::CPAN

      av_store(CACHE_ENTRIES, i, newRV_inc((SV *) CENTRY));
   }
   return 0;
}
#endif		/* ifdef OpenAFS_1_2 */



#ifdef OpenAFS_1_4
/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
PrintCacheEntries32(struct rx_connection *aconn, int aint32,
                    AV *CACHE_ENTRIES, char *buffer)
{
    register int i;
    register afs_int32 code;
    struct AFSDBCacheEntry centry;
    char *cellname;
    HV *NETFID;
    HV *CENTRY;
    HV *LOCK;

    for (i = 0; i < 10000; i++) {
        code = RXAFSCB_GetCE(aconn, i, &centry);
        if (code) {
            if (code == 1)
                break;
            sprintf(buffer, "cmdebug: failed to get cache entry %d (%s)\n", i,
                   error_message(code));
            return code;
        }

        CENTRY = newHV();

        hv_store(CENTRY, "addr", 4, newSViv(centry.addr), 0);

        if (centry.addr == 0) {
            /* PS output */

src/Monitor.xs  view on Meta::CPAN

        hv_store(CENTRY, "mvstat", 6, newSViv(centry.mvstat), 0);

        hv_store(CENTRY, "states", 6, newSViv(centry.states), 0);
        av_store(CACHE_ENTRIES, i, newRV_inc((SV *) CENTRY));
    }
    return 0;
}


/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
PrintCacheEntries64(struct rx_connection *aconn, int aint32,
                    AV *CACHE_ENTRIES, char *buffer)
{
    register int i;
    register afs_int32 code;
    struct AFSDBCacheEntry64 centry;

src/Monitor.xs  view on Meta::CPAN

    char *data_name;
    HV *NETFID;
    HV *CENTRY;
    HV *LOCK;

    for (i = 0; i < 10000; i++) {
        code = RXAFSCB_GetCE64(aconn, i, &centry);
        if (code) {
            if (code == 1)
                break;
            sprintf(buffer, "cmdebug: failed to get cache entry %d (%s)\n", i,
                   error_message(code));
            return code;
        }

        CENTRY = newHV();

        hv_store(CENTRY, "addr", 4, newSViv(centry.addr), 0);

        if (centry.addr == 0) {
            /* PS output */

src/Monitor.xs  view on Meta::CPAN

            sprintf(data_name, "%s, mapped", data_name);
        hv_store(CENTRY, "states", 6, newSVpv(data_name, strlen(data_name)), 0);

        av_store(CACHE_ENTRIES, i, newRV_inc((SV *) CENTRY));
    }
    return 0;
}


/*
 * from src/venus/cmdebug.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_PrintCacheEntries(struct rx_connection *aconn, int aint32,
                     AV *CACHE_ENTRIES, char *buffer)
{
    register afs_int32 code;
    struct AFSDBCacheEntry64 centry64;

    code = RXAFSCB_GetCE64(aconn, 0, &centry64);
    if (code != RXGEN_OPCODE)
        return PrintCacheEntries64(aconn, aint32, CACHE_ENTRIES, buffer);
    else
        return PrintCacheEntries32(aconn, aint32, CACHE_ENTRIES, buffer);
}
#endif		/* ifdef OpenAFS_1_4 */


/* end of cmdebug helper functions */



/* udebug helper functions */

/*
 * from src/ubik/ubik.h
 *
 */

#define MAXSKEW  10


/*
 * from src/ubik/udebug.c
 *     ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

static short
udebug_PortNumber(register char *aport)
{
       register int tc;
    register afs_int32 total;

    total = 0;
    while ((tc = *aport++)) {
        if (tc < '0' || tc > '9')
            return -1;          /* bad port number */
        total *= 10;
        total += tc - (int)'0';
    }
    return (total);
}


/*
 * from src/ubik/udebug.c
 *     ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

static short
udebug_PortName(char *aname)
{
    struct servent *ts;
    int len;

    ts = getservbyname(aname, NULL);

    if (ts)
        return ntohs(ts->s_port);       /* returns it in host byte order */

    len = strlen(aname);

src/Monitor.xs  view on Meta::CPAN

        return 7002;
    } else if (strncmp(aname, "kaserver", len) == 0) {
        return 7004;
    } else if (strncmp(aname, "buserver", len) == 0) {
        return 7021;
    }
    return (-1);
}


/* end of udebug helper functions */





/* scout helper functions */


/*
 * from src/fsprobe/fsprobe.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

#define FSPROBE_CBPORT  7101

extern int RXAFSCB_ExecuteRequest();

int
my_fsprobe_LWP(fsprobe_numServers, fsprobe_ConnInfo, fsprobe_Results,
               fsprobe_statsBytes, fsprobe_probeOKBytes,
               scout_debugfd, RETVAL, buffer)
   int fsprobe_numServers;
   struct fsprobe_ConnectionInfo *fsprobe_ConnInfo;
   struct fsprobe_ProbeResults *fsprobe_Results;
   int fsprobe_statsBytes;
   int fsprobe_probeOKBytes;
   FILE *scout_debugfd;
   AV *RETVAL;
   char *buffer;
{
   static char rn[] = "fsprobe_LWP";    /*Routine name */
   register afs_int32 code = 0; /*Results of calls */
   int conn_idx;                /*Connection index */
   struct fsprobe_ConnectionInfo *curr_conn;    /*Current connection */
   struct ProbeViceStatistics *curr_stats;  /*Current stats region */
   int *curr_probeOK;           /*Current probeOK field */
   int i;

   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Called\n", rn);
      fprintf(scout_debugfd,
              "[%s] Collecting data from %d connected servers\n", rn,
              fsprobe_numServers);
      fflush(scout_debugfd);
   }
   curr_conn = fsprobe_ConnInfo;
   curr_stats = fsprobe_Results->stats;
   curr_probeOK = fsprobe_Results->probeOK;
   fsprobe_Results->probeNum++;
   memset(fsprobe_Results->stats, 0, fsprobe_statsBytes);
   memset(fsprobe_Results->probeOK, 0, fsprobe_probeOKBytes);

   for (conn_idx = 0; conn_idx < fsprobe_numServers; conn_idx++) {
      /*
       * Grab the statistics for the current FileServer, if the
       * connection is valid.
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd, "[%s] Contacting server %s\n", rn,
                 curr_conn->hostName);
         fflush(scout_debugfd);
      }
      if (curr_conn->rxconn != (struct rx_connection *) NULL) {
         if (scout_debugfd) {
            fprintf(scout_debugfd,
                    "[%s] Connection valid, calling RXAFS_GetStatistics\n",
                    rn);
            fflush(scout_debugfd);
         }
         *curr_probeOK = RXAFS_GetStatistics(curr_conn->rxconn, (struct ViceStatistics *)curr_stats);

      } /*Valid Rx connection */

      /*
       * Call the Volume Server too to get additional stats
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd, "[%s] Contacting volume server %s\n", rn,
                 curr_conn->hostName);
         fflush(scout_debugfd);
      }
      if (curr_conn->rxVolconn != (struct rx_connection *) NULL) {
         char pname[10];
         struct diskPartition partition;

         if (scout_debugfd) {
            fprintf(scout_debugfd,
                    "[%s] Connection valid, calling RXAFS_GetStatistics\n",
                    rn);
            fflush(scout_debugfd);
         }
         for (i = 0; i < curr_conn->partCnt; i++) {
            if (curr_conn->partList.partFlags[i] & PARTVALID) {
               MapPartIdIntoName(curr_conn->partList.partId[i], pname);
               code =
                  AFSVolPartitionInfo(curr_conn->rxVolconn, pname,
                                      &partition);
               if (code) {
                  sprintf(buffer,
                          "Could not get information on server %s partition %s",

src/Monitor.xs  view on Meta::CPAN

   return (code);
}   /* my_fsprobe_LWP */


/*
 * from src/fsprobe/fsprobe.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_XListPartitions(aconn, ptrPartList, cntp, scout_debugfd)
   struct rx_connection *aconn;
   struct partList *ptrPartList;
   afs_int32 *cntp;
   FILE *scout_debugfd;
{
   struct pIDs partIds;
   struct partEntries partEnts;
   register int i, j = 0, code;
   static int newvolserver = 0;

   static char rn[] = "my_XListPartitions";
   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Called\n", rn);
      fflush(scout_debugfd);
   }

   *cntp = 0;
   if (newvolserver == 1) {
      for (i = 0; i < 26; i++)
         partIds.partIds[i] = -1;
    tryold:
      code = AFSVolListPartitions(aconn, &partIds);
      if (!code) {
         for (i = 0; i < 26; i++) {

src/Monitor.xs  view on Meta::CPAN

}


/*
 * from src/fsprobe/fsprobe.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_fsprobe_Cleanup(fsprobe_Results, fsprobe_ConnInfo, fsprobe_numServers,
                   scout_debugfd, buffer)
   struct fsprobe_ProbeResults *fsprobe_Results;
   struct fsprobe_ConnectionInfo *fsprobe_ConnInfo;
   int fsprobe_numServers;
   FILE *scout_debugfd;
   char *buffer;
{

   int code = 0;                /*Return code */
   int conn_idx;                /*Current connection index */
   struct fsprobe_ConnectionInfo *curr_conn;    /*Ptr to fsprobe connection */
   static char rn[] = "my_fsprobe_Cleanup";

   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Called\n", rn);
      fflush(scout_debugfd);
   }


   /*
    * Take care of all Rx connections first.  Check to see that the
    * server count is a legal value.
    */
   if (fsprobe_numServers <= 0) {
      sprintf(buffer,
              "[%s] Illegal number of servers to clean up (fsprobe_numServers = %d)",

src/Monitor.xs  view on Meta::CPAN

}


/*
 * from src/fsprobe/fsprobe.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_fsprobe_Init(fsprobe_Results, fsprobe_ConnInfo, a_numServers,
                a_socketArray, RETVAL, scout_debugfd, buffer)
   struct fsprobe_ProbeResults *fsprobe_Results;    /*Latest probe results */
   struct fsprobe_ConnectionInfo **fsprobe_ConnInfo;    /*Ptr to connection array */
   int a_numServers;
   struct sockaddr_in *a_socketArray;
   AV *RETVAL;
   FILE *scout_debugfd;
   char *buffer;
{
   static char rn[] = "my_fsprobe_Init";
   struct fsprobe_ConnectionInfo *curr_conn;    /*Current connection */
   int fsprobe_statsBytes;      /*Num bytes in stats block */
   int fsprobe_probeOKBytes;    /*Num bytes in probeOK block */
   int conn_err = 0, code = 0;
   int curr_srv;
   char *hostNameFound;
   int PortToUse;

src/Monitor.xs  view on Meta::CPAN

   struct rx_securityClass *CBsecobj;
   struct rx_service *rxsrv_afsserver;
   char buff2[256] = "";

   struct rx_call *rxcall;      /*Bogus param */
   AFSCBFids *Fids_Array;       /*Bogus param */
   AFSCBs *CallBack_Array;      /*Bogus param */
   struct interfaceAddr *interfaceAddr; /*Bogus param */


   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Called\n", rn);
      fflush(scout_debugfd);
   }
   if (a_numServers <= 0) {
      sprintf(buffer, "[%s] Illegal number of servers: %d", rn, a_numServers);
      return (-1);
   }
   if (a_socketArray == (struct sockaddr_in *) NULL) {
      sprintf(buffer, "[%s] Null server socket array argument", rn);
      return (-1);
   }

src/Monitor.xs  view on Meta::CPAN


   *fsprobe_ConnInfo = (struct fsprobe_ConnectionInfo *)
      malloc(a_numServers * sizeof(struct fsprobe_ConnectionInfo));
   if (*fsprobe_ConnInfo == (struct fsprobe_ConnectionInfo *) NULL) {
      sprintf(buffer,
              "[%s] Can't allocate %d connection info structs (%d bytes)\n",
              rn, a_numServers,
              (a_numServers * sizeof(struct fsprobe_ConnectionInfo)));
      return (-1);  /*No cleanup needs to be done yet */
   }
   else if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] *fsprobe_ConnInfo allocated (%d bytes)\n",
              rn, a_numServers * sizeof(struct fsprobe_ConnectionInfo));
      fflush(scout_debugfd);
   }

   fsprobe_statsBytes = a_numServers * sizeof(struct ProbeViceStatistics);
   fsprobe_Results->stats = (struct ProbeViceStatistics *)
      malloc(fsprobe_statsBytes);
   if (fsprobe_Results->stats == (struct ProbeViceStatistics *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't allocate %d statistics structs (%d bytes). %s", rn,
              a_numServers, fsprobe_statsBytes, buff2);
      return (-1);
   }
   else if (scout_debugfd) {
      fprintf(scout_debugfd,
              "[%s] fsprobe_Results->stats allocated (%d bytes)\n", rn,
              fsprobe_statsBytes);
      fflush(scout_debugfd);
   }

   fsprobe_probeOKBytes = a_numServers * sizeof(int);
   fsprobe_Results->probeOK = (int *)malloc(fsprobe_probeOKBytes);
   if (fsprobe_Results->probeOK == (int *) NULL) {
      /* Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't allocate %d probeOK array entries (%d bytes). %s",
              rn, a_numServers, fsprobe_probeOKBytes, buff2);
      return (-1);
   }
   else if (scout_debugfd) {
      fprintf(scout_debugfd,
              "[%s] fsprobe_Results->probeOK allocated (%d bytes)\n",
              rn, fsprobe_probeOKBytes);
      fflush(scout_debugfd);
   }
   fsprobe_Results->probeNum = 0;
   fsprobe_Results->probeTime = 0;
   memset(fsprobe_Results->stats, 0,
          (a_numServers * sizeof(struct ProbeViceStatistics)));

   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Initializing Rx\n", rn);
      fflush(scout_debugfd);
   }
   PortToUse = FSPROBE_CBPORT;
   do {
      code = rx_Init(htons(PortToUse));
      if (code) {
         if (code == RX_ADDRINUSE) {
            if (scout_debugfd) {
               fprintf(scout_debugfd,
                       "[%s] Callback port %d in use, advancing\n", rn,
                       PortToUse);
               fflush(scout_debugfd);
            }
            PortToUse++;
         }
         else {
            sprintf(buffer, "[%s] Fatal error in rx_Init()\n", rn);
            return (-1);
         }
      }
   } while (code);
   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Rx initialized on port %d\n", rn,
              PortToUse);
      fflush(scout_debugfd);
   }


   /*
    * Create a null Rx server security object, to be used by the
    * Callback listener.
    */
   CBsecobj = (struct rx_securityClass *)rxnull_NewServerSecurityObject();
   if (CBsecobj == (struct rx_securityClass *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't create null security object for the callback listener. %s",
              rn, buff2);
      return (-1);
   }
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Callback server security object created\n",
              rn);


   /*
    * Create a null Rx client security object, to be used by the
    * probe LWP.
    */
   secobj = (struct rx_securityClass *)rxnull_NewClientSecurityObject();
   if (secobj == (struct rx_securityClass *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer,
              "[%s] Can't create client security object for probe LWP. %s",
              rn, buff2);
      return (-1);
   }
   if (scout_debugfd) {
      fprintf(scout_debugfd,
              "[%s] Probe LWP client security object created\n", rn);
      fflush(scout_debugfd);
   }


   curr_conn = *fsprobe_ConnInfo;
   conn_err = 0;
   for (curr_srv = 0; curr_srv < a_numServers; curr_srv++) {
      /*
       * Copy in the socket info for the current server, resolve its
       * printable name if possible.
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd,
                 "[%s] Copying in the following socket info:\n", rn);
         fprintf(scout_debugfd, "[%s] IP addr 0x%lx, port %d\n", rn,
                 (a_socketArray + curr_srv)->sin_addr.s_addr,
                 (a_socketArray + curr_srv)->sin_port);
         fflush(scout_debugfd);
      }
      memcpy(&(curr_conn->skt), a_socketArray + curr_srv,
             sizeof(struct sockaddr_in));

      hostNameFound = hostutil_GetNameByINet(curr_conn->skt.sin_addr.s_addr);
      if (hostNameFound == (char *) NULL) {
         warn("Can't map Internet address %lu to a string name\n",
              curr_conn->skt.sin_addr.s_addr);
         curr_conn->hostName[0] = '\0';
      }
      else {
         strcpy(curr_conn->hostName, hostNameFound);
         if (scout_debugfd) {
            fprintf(scout_debugfd,
                    "[%s] Host name for server index %d is %s\n", rn,
                    curr_srv, curr_conn->hostName);
            fflush(scout_debugfd);
         }
      }

      /*
       * Make an Rx connection to the current server.
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd,
                 "[%s] Connecting to srv idx %d, IP addr 0x%lx, port %d, service 1\n",
                 rn, curr_srv, curr_conn->skt.sin_addr.s_addr,
                 curr_conn->skt.sin_port);
         fflush(scout_debugfd);
      }

      curr_conn->rxconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,  /*Server addr */
                                           curr_conn->skt.sin_port, /*Server port */
                                           1,   /*AFS service num */
                                           secobj,  /*Security object */
                                           0);  /*Number of above */
      if (curr_conn->rxconn == (struct rx_connection *) NULL) {
         sprintf(buffer,
                 "[%s] Can't create Rx connection to server %s (%lu)",
                 rn, curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
         conn_err = 1;
      }
      if (scout_debugfd) {
         fprintf(scout_debugfd, "[%s] New connection at 0x%lx\n",
                 rn, curr_conn->rxconn);
         fflush(scout_debugfd);
      }

      /*
       * Make an Rx connection to the current volume server.
       */
      if (scout_debugfd) {
         fprintf(scout_debugfd,
                 "[%s] Connecting to srv idx %d, IP addr 0x%lx, port %d, service 1\n",
                 rn, curr_srv, curr_conn->skt.sin_addr.s_addr, htons(7005));
         fflush(scout_debugfd);
      }
      curr_conn->rxVolconn = rx_NewConnection(curr_conn->skt.sin_addr.s_addr,   /*Server addr */
                                              htons(AFSCONF_VOLUMEPORT),    /*Volume Server port */
                                              VOLSERVICE_ID,    /*AFS service num */
                                              secobj,   /*Security object */
                                              0);   /*Number of above */
      if (curr_conn->rxVolconn == (struct rx_connection *) NULL) {
         sprintf(buffer,
                 "[%s] Can't create Rx connection to volume server %s (%lu)\n",
                 rn, curr_conn->hostName, curr_conn->skt.sin_addr.s_addr);
         conn_err = 1;
      }
      else {
         int i, cnt;

         memset(&curr_conn->partList, 0, sizeof(struct partList));
         curr_conn->partCnt = 0;
         i = my_XListPartitions(curr_conn->rxVolconn, &curr_conn->partList,
                                &cnt, scout_debugfd);
         if (!i) {
            curr_conn->partCnt = cnt;
         }
      }
      if (scout_debugfd) {
         fprintf(scout_debugfd, "[%s] New connection at 0x%lx\n",
                 rn, curr_conn->rxVolconn);
         fflush(scout_debugfd);
      }


      /*
       * Bump the current fsprobe connection to set up.
       */
      curr_conn++;
   }    /*for curr_srv */

   /*
    * Create the AFS callback service (listener).
    */
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Creating AFS callback listener\n", rn);
   rxsrv_afsserver = rx_NewService(0,   /*Use default port */
                                   1,   /*Service ID */
                                   "afs",   /*Service name */
                                   &CBsecobj,   /*Ptr to security object(s) */
                                   1,   /*Number of security objects */
                                   RXAFSCB_ExecuteRequest); /*Dispatcher */
   if (rxsrv_afsserver == (struct rx_service *) NULL) {
      /*Delete already-malloc'ed areas */
      my_fsprobe_Cleanup(fsprobe_Results, *fsprobe_ConnInfo, a_numServers,
                         scout_debugfd, buff2);
      sprintf(buffer, "[%s] Can't create callback Rx service/listener. %s",
              rn, buff2);
      return (-1);
   }
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Callback listener created\n", rn);

   /*
    * Start up the AFS callback service.
    */
   if (scout_debugfd)
      fprintf(scout_debugfd, "[%s] Starting up callback listener.\n", rn);
   rx_StartServer(0 /*Don't donate yourself to LWP pool */ );

   /* start probe */
   code = my_fsprobe_LWP(a_numServers, *fsprobe_ConnInfo, fsprobe_Results,
                         fsprobe_statsBytes, fsprobe_probeOKBytes,
                         scout_debugfd, RETVAL, buffer);
   if (code)
      return (code);

   if (conn_err)
      return (-2);
   else
      return (0);

}   /* my_fsprobe_Init() */


/*
 * from src/scout/scout.c
 *    ("$Header: /afs/slac/g/scs/slur/Repository/AFSDebug/Debug/src/Monitor.xs,v 1.2 2006/07/05 22:25:10 alfw Exp $");
 */

int
my_FS_Handler(fsprobe_Results, numServers, fsprobe_ConnInfo, scout_debugfd,
              RETVAL, buffer)
   struct fsprobe_ProbeResults fsprobe_Results;
   int numServers;
   struct fsprobe_ConnectionInfo *fsprobe_ConnInfo;
   FILE *scout_debugfd;
   AV *RETVAL;
   char *buffer;
{
   static char rn[] = "my_FS_Handler";  /*Routine name */
   int code;                    /*Return code */
   struct ProbeViceStatistics *curr_stats;  /*Ptr to current stats */
   struct fsprobe_ConnectionInfo *curr_conn;
   ViceDisk *curr_diskstat;
   int curr_disk;
   int *curr_probeOK;           /*Ptr to current probeOK field */
   int i = 0, j = 0;
   HV *RESULTS;
   HV *STATS;
   AV *DISKS;
   HV *DISK;

   if (scout_debugfd) {
      fprintf(scout_debugfd, "[%s] Called\n", rn);
      fflush(scout_debugfd);
   }

   curr_stats = fsprobe_Results.stats;
   curr_probeOK = fsprobe_Results.probeOK;
   curr_conn = fsprobe_ConnInfo;

   for (i = 0; i < numServers; i++) {
      RESULTS = newHV();

      hv_store(RESULTS, "probeOK", 7, newSViv((*curr_probeOK) ? 0 : 1), 0);

src/Monitor.xs  view on Meta::CPAN

         hv_store(RESULTS, "stats", 5, newRV_inc((SV *) STATS), 0);
      }
      av_store(RETVAL, i, newRV_inc((SV *) RESULTS));
      curr_stats++;
      curr_probeOK++;
      curr_conn++;
   }

   code =
      my_fsprobe_Cleanup(&fsprobe_Results, fsprobe_ConnInfo, numServers,
                         scout_debugfd, buffer);

   return code;
}

/* end of scout helper functions */



/* xstat_fs_test helper functions */

src/Monitor.xs  view on Meta::CPAN

    char buff2[256] = "";

    char basename[64] = "";
    int numservers = 0;
    char fullsrvname[128] = "";
    struct sockaddr_in *FSSktArray;
    struct sockaddr_in *curr_skt;
    struct hostent *he;
    int i, code;
    int sktbytes;
    FILE *scout_debugfd = (FILE *) NULL;
    char *debug_filename = (char *) NULL;

    AV *host_array = (AV *) NULL;

    AV *RETVAL = newAV();

    /* parse arguments */
    num_args = hv_iterinit(args);
    while (num_args--) {

      value = hv_iternextsv(args, &key, &keylen);

      switch (*key) {

        case 'b':
          if(strncmp(key, "basename", keylen) == 0 && keylen <= 8) {
            sprintf(basename, "%s", SvPV(value, PL_na));
          } else goto unrecognized;
        break;

        case 'd':
          if(strncmp(key, "debug", keylen) == 0 && keylen <= 5) {
            debug_filename = (char *) SvPV(value, PL_na);
          } else goto unrecognized;
        break;

        case 's':
          if(strncmp(key, "servers", keylen) == 0 && keylen <= 7) {
            if (SvROK(value))
              host_array = (AV*) SvRV(value);
            else {
              host_array = av_make(1, &value);
              sv_2mortal((SV *) host_array);

src/Monitor.xs  view on Meta::CPAN

      } /* end switch */
    } /* end while */
    /* done parsing arguments */

    if(numservers == 0) {
      sprintf(buffer, "Missing required parameter 'server'");
      BSETCODE(-1, buffer);
      XSRETURN_UNDEF;
    }

    if(debug_filename) {
      scout_debugfd = fopen(debug_filename, "w");
      if(scout_debugfd == (FILE *) NULL) {
        sprintf(buffer, "Can't open debugging file '%s'!", debug_filename);
        BSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
      fprintf(scout_debugfd, "[%s] Writing to Scout debugging file '%s'\n",
              rn, debug_filename);
      fflush(scout_debugfd);
    }

    /* execute_scout */

    sktbytes = numservers * sizeof(struct sockaddr_in);
    FSSktArray = (struct sockaddr_in *) malloc(sktbytes);
    if (FSSktArray == (struct sockaddr_in *) NULL) {
      sprintf(buffer,
              "Can't malloc() %d sockaddrs (%d bytes) for the given servers",
              numservers, sktbytes);
      BSETCODE(-1, buffer);
      if (scout_debugfd != (FILE *) NULL) {
        fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
        fclose(scout_debugfd);
      }
      XSRETURN_UNDEF;
    }
    memset(FSSktArray, 0, sktbytes);

    curr_skt = FSSktArray;
    for(i=0; i<numservers; i++) {
       if(*basename == '\0')
         sprintf(fullsrvname, "%s", (char *) SvPV(*av_fetch(host_array, i, 0), PL_na));
       else
         sprintf(fullsrvname, "%s.%s", (char *) SvPV(*av_fetch(host_array, i, 0), PL_na), basename);
       he = hostutil_GetHostByName(fullsrvname);
       if(he == (struct hostent *) NULL) {
         sprintf(buffer, "Can't get host info for '%s'", fullsrvname);
         BSETCODE(-1, buffer);
         if (scout_debugfd != (FILE *) NULL) {
           fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
           fclose(scout_debugfd);
         }
         XSRETURN_UNDEF;
       }
       memcpy(&(curr_skt->sin_addr.s_addr), he->h_addr, 4);
#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
        curr_skt->sin_family = AF_INET;         /*Internet family */
#else
        curr_skt->sin_family = htons(AF_INET);  /*Internet family */
#endif
       curr_skt->sin_port   = htons(7000);       /* FileServer port */
       curr_skt++;
    }
    code = my_fsprobe_Init(&fsprobe_Results, &fsprobe_ConnInfo, numservers,
                           FSSktArray, RETVAL, scout_debugfd, buffer);
    if(code) {
      if(buffer == "") {
        sprintf(buffer, "Error returned by fsprobe_Init: %d", code);
      }
      BSETCODE(code, buffer);
      if (scout_debugfd != (FILE *) NULL) {
        fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
        fclose(scout_debugfd);
      }
      XSRETURN_UNDEF;
    }
    code = my_FS_Handler(fsprobe_Results, numservers, fsprobe_ConnInfo,
                         scout_debugfd, RETVAL, buff2);
    if (code) {
      sprintf(buffer, "[%s] Handler routine returned error code %d. %s", rn, code, buff2);
      BSETCODE(code, buffer);
      if (scout_debugfd != (FILE *) NULL) {
        fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
        fclose(scout_debugfd);
      }
      XSRETURN_UNDEF;
    }

    if (scout_debugfd != (FILE *) NULL) {
       fprintf(scout_debugfd, "[%s] Closing debugging file\n", rn);
       fclose(scout_debugfd);
    }

    ST(0) = sv_2mortal(newRV_inc((SV*)RETVAL));
    SETCODE(0);
    XSRETURN(1);
  }

void
afs_do_udebug(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {

    SV *value;
    I32 keylen = 0;
    char *key;
    int num_args = 0;
    char buffer[256] = "";

src/Monitor.xs  view on Meta::CPAN

    char *hostName = (char *) NULL;
    char *portName = (char *) NULL;
    afs_int32 hostAddr;
    struct in_addr inhostAddr;
    register afs_int32 i, j, code;
    short port;
    int int32p = 0;
    struct hostent *th;
    struct rx_connection *tconn;
    struct rx_securityClass *sc;
    struct ubik_debug udebug;
    struct ubik_sdebug usdebug;
    int oldServer = 0;   /* are we talking to a pre 3.5 server? */
    afs_int32 isClone = 0;

    HV *RETVAL = newHV();
    AV *ADDRESSES;
    HV *LOCALVERSION;
    HV *SYNCVERSION;
    HV *SYNCTID;
    AV *SERVERS;
    HV *USDEBUG;

src/Monitor.xs  view on Meta::CPAN

        break;
      } /* end switch */
    } /* end while */
    /* done parsing arguments */


    /* lookup host */
    if (hostName) {
       th = hostutil_GetHostByName(hostName);
       if (!th) {
          sprintf(buffer, "udebug: host %s not found in host table", hostName);
          BSETCODE(1, buffer);
          XSRETURN_UNDEF;
       }
       memcpy(&hostAddr, th->h_addr, sizeof(afs_int32));
    }
    else hostAddr = htonl(0x7f000001);  /* IP localhost */


    if (!portName)
       port = htons(3000);             /* default */
    else {
       port = udebug_PortNumber(portName);
       if (port < 0)
          port = udebug_PortName(portName);
       if (port < 0) {
          sprintf(buffer, "udebug: can't resolve port name %s", portName);
          BSETCODE(1, buffer);
          XSRETURN_UNDEF;
       }
       port = htons(port);
    }

    rx_Init(0);
    sc = rxnull_NewClientSecurityObject();
    tconn = rx_NewConnection(hostAddr, port, VOTE_SERVICE_ID, sc, 0);

    /* now do the main call */
#ifdef USE_VOTEXDEBUG
    code = VOTE_XDebug(tconn, &udebug, &isClone);
    if (code) code = VOTE_Debug(tconn, &udebug);
#else
    code = VOTE_Debug(tconn, &udebug);
#endif
    if (code == RXGEN_OPCODE)
    {  ubik_debug * ptr = &udebug;
       oldServer = 1;             /* talking to a pre 3.5 server */
       memset(&udebug, 0, sizeof(udebug));
       code = VOTE_DebugOld(tconn, (struct ubik_debug_old *) ptr);
    }

    if (code) {
       sprintf(buffer, "return code %d from VOTE_Debug", code);
       BSETCODE(code, buffer);
       XSRETURN_UNDEF;
    }

    /* now print the main info */
    inhostAddr.s_addr = hostAddr;
    if ( !oldServer )
    {
       ADDRESSES = newAV();
       for ( j=0; udebug.interfaceAddr[j] && ( j<UBIK_MAX_INTERFACE_ADDR ); j++) {
          av_store(ADDRESSES, j, newSVpv(afs_inet_ntoa(htonl(udebug.interfaceAddr[j])), 0));
       }
       hv_store(RETVAL, "interfaceAddr", 13, newRV_inc((SV*)ADDRESSES), 0);
    }

    hv_store(RETVAL, "host", 4, newSVpv(inet_ntoa(inhostAddr), 0), 0);
    hv_store(RETVAL, "now", 3, newSViv(udebug.now), 0);

    /* UBIK skips the voting if 1 server - so we fudge it here */
    if ( udebug.amSyncSite && (udebug.nServers == 1) ) {
       udebug.lastYesHost  = hostAddr;
       udebug.lastYesTime  = udebug.now;
       udebug.lastYesState = 1;
       udebug.lastYesClaim = udebug.now;
       udebug.syncVersion.epoch   = udebug.localVersion.epoch;
       udebug.syncVersion.counter = udebug.localVersion.counter;
    }

    /* sockaddr is always in net-order */
    if ( udebug.lastYesHost != 0xffffffff ) {
       inhostAddr.s_addr = htonl(udebug.lastYesHost);
       hv_store(RETVAL, "lastYesHost", 11, newSVpv(inet_ntoa(inhostAddr), 0), 0);
       hv_store(RETVAL, "lastYesTime", 11, newSViv(udebug.lastYesTime), 0);
       hv_store(RETVAL, "lastYesState", 12, newSViv(udebug.lastYesState), 0);
       hv_store(RETVAL, "lastYesClaim", 12, newSViv(udebug.lastYesClaim), 0);
    }

    LOCALVERSION = newHV();
    hv_store(LOCALVERSION, "epoch", 5, newSViv(udebug.localVersion.epoch), 0);
    hv_store(LOCALVERSION, "counter", 7, newSViv(udebug.localVersion.counter), 0);
    hv_store(RETVAL, "localVersion", 12, newRV_inc((SV*)LOCALVERSION), 0);

    hv_store(RETVAL, "amSyncSite", 10, newSViv(udebug.amSyncSite), 0);

    hv_store(RETVAL, "epochTime", 9, newSViv(udebug.epochTime), 0);

    if (udebug.amSyncSite) {
       hv_store(RETVAL, "syncSiteUntil", 13, newSViv(udebug.syncSiteUntil), 0);
       hv_store(RETVAL, "nServers", 8, newSViv(udebug.nServers), 0);
       hv_store(RETVAL, "recoveryState", 13, newSViv(udebug.recoveryState), 0);
       if (udebug.activeWrite) {
          hv_store(RETVAL, "tidCounter", 10, newSViv(udebug.tidCounter), 0);
       }
    }
    else {
       hv_store(RETVAL, "isClone", 7, newSViv(isClone), 0);

       inhostAddr.s_addr = htonl(udebug.lowestHost);
       hv_store(RETVAL, "lowestHost", 10, newSVpv(inet_ntoa(inhostAddr), 0), 0);
       hv_store(RETVAL, "lowestTime", 10, newSViv(udebug.lowestTime), 0);

       inhostAddr.s_addr = htonl(udebug.syncHost);
       hv_store(RETVAL, "syncHost", 8, newSVpv(inet_ntoa(inhostAddr), 0), 0);
       hv_store(RETVAL, "syncTime", 8, newSViv(udebug.syncTime), 0);
    }

    SYNCVERSION = newHV();
    hv_store(SYNCVERSION, "epoch", 5, newSViv(udebug.syncVersion.epoch), 0);
    hv_store(SYNCVERSION, "counter", 7, newSViv(udebug.syncVersion.counter), 0);
    hv_store(RETVAL, "syncVersion", 11, newRV_inc((SV*)SYNCVERSION), 0);

    hv_store(RETVAL, "lockedPages", 11, newSViv(udebug.lockedPages), 0);
    hv_store(RETVAL, "writeLockedPages", 16, newSViv(udebug.writeLockedPages), 0);

    hv_store(RETVAL, "anyReadLocks", 12, newSViv(udebug.anyReadLocks), 0);
    hv_store(RETVAL, "anyWriteLocks", 13, newSViv(udebug.anyWriteLocks), 0);

    hv_store(RETVAL, "currentTrans", 12, newSViv(udebug.currentTrans), 0);
    if (udebug.currentTrans) {
       hv_store(RETVAL, "writeTrans", 10, newSViv(udebug.writeTrans), 0);
       SYNCTID = newHV();
       hv_store(SYNCTID, "epoch", 5, newSViv(udebug.syncTid.epoch), 0);
       hv_store(SYNCTID, "counter", 7, newSViv(udebug.syncTid.counter), 0);
       hv_store(RETVAL, "syncTid", 7, newRV_inc((SV*)SYNCTID), 0);
    }

    if (int32p || udebug.amSyncSite) {
       /* now do the subcalls */
       SERVERS = newAV();

       for ( i=0; ; i++ ) {
#ifdef USE_VOTEXDEBUG
          isClone = 0;
          code = VOTE_XSDebug(tconn, i, &usdebug, &isClone);
          if (code < 0) {
             if ( oldServer ) {                      /* pre 3.5 server */
                ubik_sdebug * ptr = &usdebug;
                memset(&usdebug, 0, sizeof(usdebug));
                code = VOTE_SDebugOld(tconn, i, (struct ubik_sdebug_old *) ptr);
             }
             else
                code = VOTE_SDebug(tconn, i, &usdebug);
          }
#else
          if ( oldServer ) {                      /* pre 3.5 server */
             ubik_sdebug * ptr = &usdebug;
             memset(&usdebug, 0, sizeof(usdebug));
             code = VOTE_SDebugOld(tconn, i, (struct ubik_sdebug_old *) ptr);
          }
          else
             code = VOTE_SDebug(tconn, i, &usdebug);
#endif

          if (code > 0)
                break;          /* done */
          if (code < 0) {
             warn("error code %d from VOTE_SDebug\n", code);
             break;
          }

          /* otherwise print the structure */
          USDEBUG = newHV();
          inhostAddr.s_addr = htonl(usdebug.addr);

          hv_store(USDEBUG, "addr", 4, newSVpv(afs_inet_ntoa(htonl(usdebug.addr)), 0), 0);

          ALTADDR = newAV();
          for ( j=0;((usdebug.altAddr[j]) && (j<UBIK_MAX_INTERFACE_ADDR-1)); j++) {
             av_store(ALTADDR, j, newSVpv(afs_inet_ntoa(htonl(usdebug.altAddr[j])), 0));
          }
          if (j) hv_store(USDEBUG, "altAddr", 7, newRV_inc((SV*)ALTADDR), 0);

          REMOTEVERSION = newHV();
          hv_store(REMOTEVERSION, "epoch", 5, newSViv(usdebug.remoteVersion.epoch), 0);
          hv_store(REMOTEVERSION, "counter", 7, newSViv(usdebug.remoteVersion.counter), 0);
          hv_store(USDEBUG, "remoteVersion", 13, newRV_inc((SV*)REMOTEVERSION), 0);

          hv_store(USDEBUG, "isClone", 7, newSViv(isClone), 0);

          hv_store(USDEBUG, "lastVoteTime", 12, newSViv(usdebug.lastVoteTime), 0);

          hv_store(USDEBUG, "lastBeaconSent", 14, newSViv(usdebug.lastBeaconSent), 0);
          hv_store(USDEBUG, "lastVote", 8, newSViv(usdebug.lastVote), 0);

          hv_store(USDEBUG, "currentDB", 9, newSViv(usdebug.currentDB), 0);
          hv_store(USDEBUG, "up", 2, newSViv(usdebug.up), 0);
          hv_store(USDEBUG, "beaconSinceDown", 15, newSViv(usdebug.beaconSinceDown), 0);

          av_store(SERVERS, i, newRV_inc((SV*)USDEBUG));
       }
       hv_store(RETVAL, "servers", 7, newRV_inc((SV*)SERVERS), 0);
    }

    /* return RETVAL */
    ST(0) = sv_2mortal(newRV_inc((SV*)RETVAL));
    SETCODE(0);
    XSRETURN(1);

  }

void
afs_do_cmdebug(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {
    SV *value;
    I32 keylen = 0;
    char *key;
    int num_args = 0;
    int code = 0;
    int aint32 = 0;

src/Monitor.xs  view on Meta::CPAN


    SETCODE(0);

    EXTEND(SP, 2);
    PUSHs(sv_2mortal(newRV_inc((SV*)FILESERV)));
    PUSHs(sv_2mortal(newRV_inc((SV*)CACHEMAN)));
  }


void
afs_do_rxdebug(args)
    HV* args = (HV*) SvRV($arg);
  PREINIT:
  PPCODE:
  {
    int size;
    I32 keylen;
    char *key;
    HE* entry;
    SV* value;
    HV* RETVAL = newHV(); /* return value */

src/Monitor.xs  view on Meta::CPAN

    short onlyPort = -1;
    int onlyAuth = 999;
    int flag;
    int dallyCounter;
    int withSecStats;
    int withAllConn;
    int withRxStats;
    int withWaiters;
    int withIdleThreads;
    int withPeers;
    struct rx_debugStats tstats;
    char *portName = (char *) NULL;
    char *hostName = (char *) NULL;
    struct rx_debugConn tconn;
    short noConns=0;
    short showPeers=0;
    short showLong=0;
    int version_flag=0;
    afs_int32 length=64;
    char version[64];
    char buffer[240]; /* for error messages */

    afs_uint32 supportedDebugValues = 0;
    afs_uint32 supportedStatValues = 0;

src/Monitor.xs  view on Meta::CPAN

    case 'o':
        if (memcmp( flag, "onlyserver", 10) == 0 ) {
            onlyServer = (int) SvIV(value);
        } else if (memcmp( flag, "onlyclient", 10) == 0 ) {
            onlyClient = (int) SvIV(value);
        } else if (memcmp( flag, "onlyhost", 8) == 0 ) {
            char *name = (char *) SvPV(value, PL_na);
        struct hostent *th;
        th = hostutil_GetHostByName(name);
        if (!th) {
            sprintf(buffer, "rxdebug: host %s not found in host table", name);
            BSETCODE(-1, buffer);
            XSRETURN_UNDEF;
        }
        memcpy(&onlyHost, th->h_addr, sizeof(afs_int32));

        } else if (memcmp( flag, "onlyauth", 8) == 0 ) {
            char *name = (char *) SvPV(value, PL_na);
            if (strcmp (name, "clear") == 0) onlyAuth = 0;
            else if (strcmp (name, "auth") == 0) onlyAuth = 1;
            else if (strcmp (name, "crypt") == 0) onlyAuth = 2;

src/Monitor.xs  view on Meta::CPAN

                     (strncmp (name, "noauth", 6) == 0) ||
                     (strncmp (name, "unauth", 6) == 0)) onlyAuth = -1;
            else {
              sprintf (buffer, "Unknown authentication level: %s", name);
              BSETCODE(-1, buffer);
              XSRETURN_UNDEF;
            }

        } else if (memcmp( flag, "onlyport", 8) == 0 ) {
            char *name = (char *) SvPV(value, PL_na);
            if ((onlyPort = rxdebug_PortNumber(name)) == -1)
              onlyPort = rxdebug_PortName(name);
            if (onlyPort == -1) {
              sprintf(buffer, "rxdebug: can't resolve port name %s", name);
              VSETCODE(-1, buffer);
              XSRETURN_UNDEF;
            }
        }

        break;

    case 'p':
        if (memcmp( flag, "port", 4) == 0 ) {
            portName = (char *) SvPV(value, PL_na);

src/Monitor.xs  view on Meta::CPAN

    default:
        break;
    } /* switch */
  } /* while */
  /*  fprintf(STDERR, "Done parsing args\n\n"); */

    /* lookup host */
    if (hostName) {
      th = hostutil_GetHostByName(hostName);
      if (!th) {
        sprintf(buffer, "rxdebug: host %s not found in host table", hostName);
        VSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
      memcpy(&host, th->h_addr, sizeof(afs_int32));
    }
    else host = htonl(0x7f000001);    /* IP localhost */

    if (!portName)
      port = htons(7000);        /* default is fileserver */
    else {
      if ((port = rxdebug_PortNumber(portName)) == -1)
        port = rxdebug_PortName(portName);
      if (port == -1) {
        sprintf(buffer, "rxdebug: can't resolve port name %s", portName);
        VSETCODE(-1, buffer);
        XSRETURN_UNDEF;
      }
    }

    dallyCounter = 0;
    hostAddr.s_addr = host;
    /* add address and port to RETVAL hash */
    hv_store(RETVAL, "address", 7, newSVpv(inet_ntoa(hostAddr), 0), 0);
    hv_store(RETVAL, "port", 4, newSViv(ntohs(port)), 0);

src/Monitor.xs  view on Meta::CPAN

        struct rx_statistics rxstats;

        /* should gracefully handle the case where rx_statistics grows */
        code = rx_GetServerStats(s, host, port, &rxstats, &supportedStatValues);
        if (code < 0) {
          sprintf(buffer, "rxstats call failed with code %d", code);
          VSETCODE(code, buffer);
          XSRETURN_UNDEF;
        }
        if (code != sizeof(rxstats)) {
          if ((((struct rx_debugIn *)(&rxstats))->type == RX_DEBUGI_BADTYPE))
            goto noRxStats;
          warn("WARNING: returned Rx statistics of unexpected size (got %d)\n", code);
          /* handle other versions?... */
        }

        RXSTATS = newHV();

        myPrintTheseStats(RXSTATS, &rxstats);

        hv_store(RETVAL, "rxstats", 7, newRV_inc((SV*)(RXSTATS)), 0);

src/Monitor.xs  view on Meta::CPAN

      if (nodally) hv_store(RETVAL, "dallyCounter", 12, newSViv(dallyCounter), 0);
      hv_store(RETVAL, "connections", 11, newRV_inc((SV*)(CONNECTIONS)), 0);
    } /* end of if (!noConns) */

    /* get peers if requested */
    /* array of peers added at key 'peers' in RETVAL hash */
    if (showPeers && withPeers) {
      PEERS = newAV();
      index = 0;
      for (i = 0; ; i++) {
        struct rx_debugPeer tpeer;
        code = rx_GetServerPeers(s, host, port, &nextpeer, allconns,
                                 &tpeer, &supportedPeerValues);
        if (code < 0) {
          warn("getpeer call failed with code %d\n", code);
          break;
        }
        if (tpeer.host == 0xffffffff) {
          break;
        }

src/t/Monitor.t  view on Meta::CPAN

is(constant('RX_CONN_DESTROY_ME', 2), 2, 'Constant RX_CONN_DESTROY_ME with argument');
isnt(constant('zzz'), 2, 'Unknown Constant zzz');

# test AUTOLOAD running function "constant"
is(&AFS::Monitor::RX_CONN_DESTROY_ME, 2, 'AutoLoad Constant RX_CONN_DESTROY_ME');


# Now some more AFS function tests:

use AFS::Monitor;
can_ok('AFS::Monitor', qw(rxdebug));

my $servers = 'afs02.slac.stanford.edu';
my $port    = 7001;
my $rxdeb   = rxdebug(version => 1,
                      servers => $servers,
                      port    => $port
                     );
ok(defined $rxdeb->{version}, 'version');



( run in 0.837 second using v1.01-cache-2.11-cpan-49f99fa48dc )