[svn-commits] tzafrir: branch tools/tzafrir/sysfs r8596 - in /tools/team/tzafrir/sysfs/xpp:...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon May 3 10:17:40 CDT 2010


Author: tzafrir
Date: Mon May  3 10:17:36 2010
New Revision: 8596

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8596
Log:
Adjust tools to sysfs changes of r8595:

* Adjust pathes under /sys and under /dev .
* Simplify handling of span pools.
* Also install dahdi_pools.

Modified:
    tools/team/tzafrir/sysfs/xpp/   (props changed)
    tools/team/tzafrir/sysfs/xpp/Makefile
    tools/team/tzafrir/sysfs/xpp/dahdi_pools
    tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm
    tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm
    tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Utils.pm

Propchange: tools/team/tzafrir/sysfs/xpp/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon May  3 10:17:36 2010
@@ -18,5 +18,6 @@
 dahdi_hardware.8
 dahdi_registration.8
 dahdi_genconf.8
+dahdi_pools.8
 lsdahdi.8
 *.8.html

Modified: tools/team/tzafrir/sysfs/xpp/Makefile
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/Makefile?view=diff&rev=8596&r1=8595&r2=8596
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/Makefile (original)
+++ tools/team/tzafrir/sysfs/xpp/Makefile Mon May  3 10:17:36 2010
@@ -49,6 +49,7 @@
 		xpp_blink	\
 		dahdi_genconf	\
 		dahdi_hardware	\
+		dahdi_pools	\
 		twinstar	\
 		#
 

Modified: tools/team/tzafrir/sysfs/xpp/dahdi_pools
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/dahdi_pools?view=diff&rev=8596&r1=8595&r2=8596
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/dahdi_pools (original)
+++ tools/team/tzafrir/sysfs/xpp/dahdi_pools Mon May  3 10:17:36 2010
@@ -30,34 +30,42 @@
 	my $pool = shift || die;
 	my $poolname = $pool->{NAME};
 	my $destdir = "$poolbase/$poolname";
+	my @entries = @{$pool->{ENTRIES}};
+	return unless @entries;
 	make_path "$destdir";
-	foreach (@{$pool->{ENTRIES}}) {
+	foreach (@entries) {
 		my $device = $_->{DEVICE};
 		my $dest = $_->{DEST};
 		symlink($device, $dest) || die "$0: Failed symlink($device, $dest): $!\n";
-		#print "symlink($device, $dest)\n";
+		#print STDERR "symlink($device, $dest)\n";
 	}
 }
 
-my @pools = Dahdi::Pool->get_pools;
-remove_tree($poolbase);
-foreach my $pool (@pools) {
-	process_pool($pool);
+my $mode = shift || die "Usage: $0 {create|delete}\n";
+
+if($mode eq 'create') {
+	my @pools = Dahdi::Pool->get_pools;
+	remove_tree($poolbase);
+	foreach my $pool (@pools) {
+		process_pool($pool);
+	}
+} elsif($mode eq 'delete') {
+	remove_tree($poolbase);
 }
 
 __END__
 
 =head1 NAME
 
-dahdi_pool - maintain pools of DAHDI spans
+dahdi_pools - maintain pools of DAHDI spans
 
 =head1 SYNOPSIS
 
-dahdi_pool
+dahdi_pools
 
 =head1 DESCRIPTION
 
-dahdi_pool Creates and updates pools of DAHDI spans. Such a pool is a
+dahdi_pools Creates and updates pools of DAHDI spans. Such a pool is a
 directory under C</dev/dahdi/pool> with symlinks to all the channels of one
 or more spans listed as plain numbers. On each invocation it deletes the
 symlinks under C</dev/dahdi/pool> and recreates them.
@@ -93,15 +101,15 @@
 
 Alternatively:
 
-  astbank1  usb:12345678/00 usb:12345678/10 usb:12345678/10 usb:12345678/30 
-  astbank2  usb:11223344/00 usb:11223344/10 usb:11223344/10 usb:11223344/30 
+  astbank1  usb:12345678!00 usb:12345678!10 usb:12345678!20 usb:12345678!30 
+  astbank2  usb:11223344!*
 
 Or, put both in the same pool (and let's use location now)
 
   all  usb:12345678 usb:11223344
 
 
-Note that running dahdi_pool several times at boot time should be safe.
+Note that running dahdi_pools several times at boot time should be safe.
 
 =head1 FILES
 

Modified: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm?view=diff&rev=8596&r1=8595&r2=8596
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm Mon May  3 10:17:36 2010
@@ -9,6 +9,7 @@
 #
 use strict;
 use File::Find;
+use Dahdi::Span;
 
 =head1 NAME
 
@@ -32,14 +33,15 @@
 
 my $cfgfile = "/etc/dahdi/chan_pools";
 my $poolbase = "/dev/dahdi/pool";
-my %pool_dirs;
+my %devdirs;
 my %devices;
 my %pools;
+my %pool_components;
 
 my @devfiles;
 
 sub wanted {
-	return unless /^\d+$/ && -l;
+	return unless /^\d+$/ && -c;
 	unshift(@devfiles, $File::Find::name);
 }
 
@@ -57,32 +59,68 @@
 sub new($$) {
 	my $class = shift || die;
 	my $poolname = shift || die;
+	my $components = shift || die;
 	my $self = {
 		NAME	=> $poolname,
 		ENTRIES	=> [],
 	};
 	bless $self, $class;
-	my $dirs = $pool_dirs{$poolname};
-	my @dirs = map { "/dev/dahdi/devices/$_" } @{$dirs};
+	#print STDERR "new($poolname)\n";
+	my @dirs;
+	foreach my $comp (@{$components}) {
+		my @spans;
+		if($comp =~ /^@/) {
+			@spans = Dahdi::Span::match_location($comp);
+			unless (@spans) {
+				warn "Pool $poolname: Ignoring non-existant location '$comp'\n";
+				next;
+			}
+		} else {
+			@spans = Dahdi::Span::match_hardware_id($comp);
+			unless (@spans) {
+				warn "Pool $poolname: Ignoring non-existant hardware_id '$comp'\n";
+				next;
+			}
+		}
+		foreach (@spans) {
+			my $dir = sprintf "/dev/dahdi/spans/%03d", $_->num;
+			my $d = $devdirs{$dir};
+			if(defined $d) {
+				warn "Pool $poolname: ignore duplicate '$comp'\n";
+				next;
+			}
+			#warn "Pool $poolname: processing ($comp) '$dir'\n";
+			$devdirs{$dir} = { COMPONENT => $comp, DIR => $dir };
+			push(@dirs, $dir);
+		}
+	}
 	my @all_devfiles;
-	foreach my $d (@dirs) {
+	foreach my $d (sort @dirs) {
 		undef @devfiles;
 		find(\&wanted, $d);
 		my @devfiles = sort chan_order @devfiles;
-		#print "$d:\n", join("\n", @devfiles), "\n";
+		#print STDERR "DEBUG: $d:\n\t", join("\n\t", @devfiles), "\n";
 		push(@all_devfiles, @devfiles);
 	}
 	my $destdir = "$poolbase/$poolname";
 	my $curr = 1;
-	foreach (@all_devfiles) {
-		warn "Not a chardev" unless -c $_;
+	my $entries = $self->{ENTRIES};
+	foreach (sort @all_devfiles) {
+		unless (-c $_) {
+			warn "Not a chardev";
+			next;
+		}
 		my $rdev = (stat($_))[6];
 		my $dest = "$destdir/$curr";
 		#symlink($_, $dest) || die "$0: Failed symlink($_, $dest): $!\n";
 		my $minor = $rdev & 0xFF;
 		my $major = $rdev >> 8;
 		my $devt = "$major:$minor";
-		die "$0: Duplicate '$devt' (from '$_')" if exists $devices{$devt};
+		if (defined $devices{$devt}) {
+			warn "$0: Duplicate '$devt' (from '$_')";
+			my $d = $devices{$devt};
+			die "POOL='$d->{SUBDIR}', DEST='$d->{DEST}'\n";
+		}
 		$devices{$devt} = {
 				DEVICE	=> $_,
 				SUBDIR	=> "pool/$poolname",
@@ -91,7 +129,7 @@
 				DEST	=> $dest,
 				POOL	=> $self,
 			};
-		$self->{ENTRIES}[$curr - 1] = $devices{$devt};
+		push(@{$entries}, $devices{$devt});
 		#print "$_: $devt\n";
 		$curr++;
 	}
@@ -107,6 +145,12 @@
 
 sub get_pools() {
 	my $class = shift || die;
+	if(! %pools) {
+		foreach my $poolname (keys %pool_components) {
+			my $p = Dahdi::Pool->new($poolname, $pool_components{$poolname});
+			$pools{$poolname} = $p if defined $p;
+		}
+	}
 	return values %pools;
 }
 
@@ -116,21 +160,16 @@
 		chomp;
 		s/#.*//;
 		next unless /\S/;
-		my ($poolname, @dirs) = split;
+		my ($poolname, @components) = split;
 		die "$cfgfile:$.: Bad pool name '$poolname'\n"
 			if $poolname =~ m/[\/\.]/;
 		die "$cfgfile:$.: Pool '$poolname' without components\n"
-			unless @dirs;
+			unless @components;
 		die "$cfgfile:$.: Doubly defined pool '$poolname'\n"
-			if exists $pool_dirs{$poolname};
-		$pool_dirs{$poolname} = \@dirs;
+			if exists $pool_components{$poolname};
+		$pool_components{$poolname} = \@components;
 	}
 	close F;
-
-	foreach my $poolname (keys %pool_dirs) {
-		my $p = Dahdi::Pool->new($poolname);
-		$pools{$poolname} = $p;
-	}
 }
 
 pool_init();

Modified: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm?view=diff&rev=8596&r1=8595&r2=8596
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm Mon May  3 10:17:36 2010
@@ -8,6 +8,7 @@
 # $Id$
 #
 use strict;
+use Dahdi;
 use Dahdi::Utils;
 use Dahdi::Chans;
 use Dahdi::Xpp::Xpd;
@@ -125,6 +126,27 @@
 
 	my ($span) = grep { $_->num == $span_number } @spans;
 	return $span;
+}
+
+sub match_location($) {
+	my $span_location = shift || die "Missing span location";
+	$span_location =~ s/^@//;
+	# Translate globs to regexes
+	$span_location =~ s/\?/./;
+	$span_location =~ s/\*/.*/;
+	my @spans = Dahdi::spans();
+	my @matched = grep { defined($_->location) && $_->location =~ m/^$span_location$/ } @spans;
+	return @matched;
+}
+
+sub match_hardware_id($) {
+	my $span_hardware_id = shift || die "Missing span hardware_id";
+	# Translate globs to regexes
+	$span_hardware_id =~ s/\?/./;
+	$span_hardware_id =~ s/\*/.*/;
+	my @spans = Dahdi::spans();
+	my @matched = grep { defined($_->hardware_id) && $_->hardware_id =~ m/^$span_hardware_id$/ } @spans;
+	return @matched;
 }
 
 my @bri_strings = (

Modified: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Utils.pm
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Utils.pm?view=diff&rev=8596&r1=8595&r2=8596
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Utils.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Utils.pm Mon May  3 10:17:36 2010
@@ -35,7 +35,7 @@
 	$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";
-	$Dahdi::sysfs_span_base = "$Dahdi::sys_base/class/dahdi_span";
+	$Dahdi::sysfs_span_base = "$Dahdi::sys_base/bus/dahdi_spans/devices";
 }
 
 sub xpp_dump($) {




More information about the svn-commits mailing list