[svn-commits] tzafrir: tools/trunk r8215 - in /tools/trunk/xpp: ./ perl_modules/ perl_modul...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue Mar 2 12:07:41 CST 2010
Author: tzafrir
Date: Tue Mar 2 12:07:37 2010
New Revision: 8215
URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8215
Log:
DAHDI-perl: allow setting base of system files with DAHDI_VIRT_TOP
If the user set DAHDI_VIRT_TOP in the environment, consider it as a path
under which to look for ProcFS and SysFS files. This allows running the
DAHDI-perl tools on filesystem dumps generated by
build_tools/dump_sys_state .
To reduce the number of dependencies between various modules, the 'xpd'
member of a Dahdi::Span is removed. Dahdi::Xpp::xpd_of_span() can be
used if needed.
Modified:
tools/trunk/xpp/lsdahdi
tools/trunk/xpp/perl_modules/Dahdi.pm
tools/trunk/xpp/perl_modules/Dahdi/Hardware/PCI.pm
tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm
tools/trunk/xpp/perl_modules/Dahdi/Span.pm
tools/trunk/xpp/perl_modules/Dahdi/Utils.pm
tools/trunk/xpp/perl_modules/Dahdi/Xpp.pm
tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
Modified: tools/trunk/xpp/lsdahdi
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/lsdahdi?view=diff&rev=8215&r1=8214&r2=8215
==============================================================================
--- tools/trunk/xpp/lsdahdi (original)
+++ tools/trunk/xpp/lsdahdi Tue Mar 2 12:07:37 2010
@@ -22,7 +22,7 @@
foreach my $span (Dahdi::spans()) {
my $spanno = $span->num;
- my $xpd = $span->xpd;
+ my $xpd = Dahdi::Xpp::xpd_of_span($span);
my @lines;
my $index = 0;
Modified: tools/trunk/xpp/perl_modules/Dahdi.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi.pm?view=diff&rev=8215&r1=8214&r2=8215
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi.pm Tue Mar 2 12:07:37 2010
@@ -32,7 +32,11 @@
}
=cut
-my $proc_base = "/proc/dahdi";
+our $virt_base;
+our $proc_dahdi_base;
+our $proc_xpp_base;
+our $proc_usb_base;
+our $sys_base;
=head1 spans()
@@ -43,16 +47,22 @@
sub spans() {
my @spans;
- -d $proc_base or return ();
- foreach my $zfile (glob "$proc_base/*") {
- $zfile =~ s:$proc_base/::;
- next unless ($zfile =~ /^\d+$/);
+ -d $proc_dahdi_base or return ();
+ foreach my $zfile (glob "$proc_dahdi_base/*") {
+ next unless ($zfile =~ m{^$proc_dahdi_base/\d+$});
my $span = Dahdi::Span->new($zfile);
push(@spans, $span);
}
@spans = sort { $a->num <=> $b->num } @spans;
return @spans;
}
+
+=head1 ENVIRONMENT
+
+If C<DAHDI_VIRT_TOP> is set in the environment, it will be considered
+as a path to a directory that holds a dump (copy) of all the required
+files from /proc and /sys . You can generate that directory using the
+script C<build_tools/dump_sys_state> .
=head1 SEE ALSO
Modified: tools/trunk/xpp/perl_modules/Dahdi/Hardware/PCI.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Hardware/PCI.pm?view=diff&rev=8215&r1=8214&r2=8215
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Hardware/PCI.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Hardware/PCI.pm Tue Mar 2 12:07:37 2010
@@ -170,7 +170,7 @@
sub scan_devices($) {
my @devices;
- while(</sys/bus/pci/devices/*>) {
+ while(<$Dahdi::sys_base/bus/pci/devices/*>) {
m,([^/]+)$,,;
my $name = $1;
my $l = readlink $_ || die;
Modified: tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm?view=diff&rev=8215&r1=8214&r2=8215
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Hardware/USB.pm Tue Mar 2 12:07:37 2010
@@ -135,7 +135,7 @@
my $pack = shift || die;
my @devices = ();
- while (</sys/bus/usb/devices/*-*>) {
+ while (<$Dahdi::sys_base/bus/usb/devices/*-*>) {
next unless -r "$_/idVendor"; # endpoints
# Older kernels, e.g. 2.6.9, don't have the attribute
@@ -165,7 +165,7 @@
sub scan_devices($) {
my $pack = shift || die;
- my $usb_device_list = "/proc/bus/usb/devices";
+ my $usb_device_list = "$Dahdi::proc_usb_base/devices";
return $pack->scan_devices_sysfs() unless (-r $usb_device_list);
my @devices;
Modified: tools/trunk/xpp/perl_modules/Dahdi/Span.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Span.pm?view=diff&rev=8215&r1=8214&r2=8215
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Span.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Span.pm Tue Mar 2 12:07:37 2010
@@ -10,7 +10,6 @@
use strict;
use Dahdi::Utils;
use Dahdi::Chans;
-use Dahdi::Xpp::Xpd;
=head1 NAME
@@ -112,8 +111,6 @@
"signalling" is set, look for "SIGNALLING".
=cut
-
-my $proc_base = "/proc/dahdi";
sub chans($) {
my $span = shift;
@@ -176,17 +173,13 @@
sub new($$) {
my $pack = shift or die "Wasn't called as a class method\n";
- my $num = shift or die "Missing a span number parameter\n";
+ my $proc_file = shift or die "Missing a proc file parameter\n";
+ $proc_file =~ m{[^/]*/(\d+)$};
+ my $num = $1 or die " Invalid span file name: $proc_file\n";
my $self = { NUM => $num };
bless $self, $pack;
$self->{TYPE} = "UNKNOWN";
- my @xpds = Dahdi::Xpp::Xpd::xpds_by_spanno;
- my $xpd = $xpds[$num];
- if(defined $xpd) {
- die "Spanno mismatch: $xpd->spanno, $num" unless $xpd->spanno == $num;
- $self->{XPD} = $xpd;
- }
- open(F, "$proc_base/$num") or die "Failed to open '$proc_base/$num\n";
+ open(F, "$proc_file") or die "Failed to open '$proc_file\n";
my $head = <F>;
chomp $head;
$self->{IS_DIGITAL} = 0;
Modified: tools/trunk/xpp/perl_modules/Dahdi/Utils.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Utils.pm?view=diff&rev=8215&r1=8214&r2=8215
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Utils.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Utils.pm Tue Mar 2 12:07:37 2010
@@ -21,6 +21,20 @@
#print STDERR "get: $key ($val)\n";
return $val;
}
+}
+
+# Initialize ProcFS and SysFS pathes, in case the user set
+# DAHDI_VIRT_TOP
+BEGIN {
+ if (exists $ENV{DAHDI_VIRT_TOP}) {
+ $Dahdi::virt_base = $ENV{DAHDI_VIRT_TOP};
+ } else {
+ $Dahdi::virt_base = '';
+ }
+ $Dahdi::proc_dahdi_base = "$Dahdi::virt_base/proc/dahdi";
+ $Dahdi::proc_xpp_base = "$Dahdi::virt_base/proc/xpp";
+ $Dahdi::proc_usb_base = "$Dahdi::virt_base/proc/bus/usb";
+ $Dahdi::sys_base = "$Dahdi::virt_base/sys";
}
sub xpp_dump($) {
Modified: tools/trunk/xpp/perl_modules/Dahdi/Xpp.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Xpp.pm?view=diff&rev=8215&r1=8214&r2=8215
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Xpp.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Xpp.pm Tue Mar 2 12:07:37 2010
@@ -34,10 +34,16 @@
#
my @xbuses;
-my $proc_base = "/proc/xpp";
-our $sysfs_astribanks = "/sys/bus/astribanks/devices";
-our $sysfs_xpds = "/sys/bus/xpds/devices";
-our $sysfs_ab_driver = "/sys/bus/astribanks/drivers/xppdrv";
+our $sysfs_astribanks;
+our $sysfs_xpds;
+our $sysfs_ab_driver;
+
+BEGIN {
+ my $virt_base = $Dahdi::virt_base;
+ $sysfs_astribanks = "$virt_base/sys/bus/astribanks/devices";
+ $sysfs_xpds = "$virt_base/sys/bus/xpds/devices";
+ $sysfs_ab_driver = "$virt_base/sys/bus/astribanks/drivers/xppdrv";
+}
sub scan($) {
my $pack = shift || die;
@@ -253,6 +259,7 @@
my $result;
my $newapi = 0;
+ my $proc_base = $Dahdi::proc_xpp_base;
my $file = "$proc_base/sync";
return '' unless -f $file;
# First query
Modified: tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm
URL: http://svnview.digium.com/svn/dahdi/tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm?view=diff&rev=8215&r1=8214&r2=8215
==============================================================================
--- tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm (original)
+++ tools/trunk/xpp/perl_modules/Dahdi/Xpp/Xbus.pm Tue Mar 2 12:07:37 2010
@@ -12,8 +12,6 @@
use Dahdi::Hardware;
use Dahdi::Xpp::Xpd;
-my $proc_base = "/proc/xpp";
-
sub xpds($) {
my $xbus = shift;
return @{$xbus->{XPDS}};
@@ -54,7 +52,7 @@
foreach my $attr (@attr) {
my $file = sprintf "$Dahdi::Xpp::sysfs_astribanks/xbus-%02d/$attr", $busnum;
unless(-f $file) {
- my $procfile = sprintf "/proc/xpp/XBUS-%02d/$attr", $busnum;
+ my $procfile = sprintf "$Dahdi::proc_xpp_base/XBUS-%02d/$attr", $busnum;
warn "$0: warning - OLD DRIVER: missing '$file'. Fall back to '$procfile'\n"
unless $file_warned{$attr}++;
$file = $procfile;
@@ -113,7 +111,7 @@
sub read_xpdnames_old($) {
my $xbus_num = shift || die;
- my $pat = sprintf "/proc/xpp/XBUS-%02d/XPD-[0-9][0-9]", $xbus_num;
+ my $pat = sprintf "$Dahdi::proc_xpp_base/XBUS-%02d/XPD-[0-9][0-9]", $xbus_num;
my @xpdnames;
#print STDERR "read_xpdnames_old($xbus_num): $pat\n";
@@ -175,7 +173,7 @@
}
foreach my $xpdstr (@xpdnames) {
my ($busnum, $unit, $subunit) = split(/:/, $xpdstr);
- my $procdir = "/proc/xpp/XBUS-$busnum/XPD-$unit$subunit";
+ my $procdir = "$Dahdi::proc_xpp_base/XBUS-$busnum/XPD-$unit$subunit";
my $xpd = Dahdi::Xpp::Xpd->new($self, $unit, $subunit, $procdir, "$xbus_dir/$xpdstr");
push(@xpds, $xpd);
}
More information about the svn-commits
mailing list