[svn-commits] tzafrir: branch tools/tzafrir/sysfs r8612 - /tools/team/tzafrir/sysfs/xpp/per...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed May 5 05:54:52 CDT 2010
Author: tzafrir
Date: Wed May 5 05:54:49 2010
New Revision: 8612
URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8612
Log:
Allow per-channel syntax in chan_pools
Support a more precise syntax in /etc/dahdi/chan_pools for specifying
components of a pool:
{@<location>|<hardware_id>}[(<selector>[;<selector>[...])]
That is, the device ID may be followed by one or more selectors:
<hardware_port>/<channels>
Thus it should be possible to select specific channels from a span.
Modified:
tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm
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=8612&r1=8611&r2=8612
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm Wed May 5 05:54:49 2010
@@ -33,27 +33,35 @@
my $cfgfile = "/etc/dahdi/chan_pools";
my $poolbase = "/dev/dahdi/pool";
-my %devdirs;
my %devices;
my %pools;
my %pool_components;
-my @devfiles;
+sub save_linkinfo($$) {
+ my $self = shift || die;
+ my $devfile = shift || die;
+ my $dest = shift;
-sub wanted {
- return unless /^\d+$/ && -c;
- unshift(@devfiles, $File::Find::name);
-}
-
-sub chan_order {
- my $a_dir = $a;
- my $b_dir = $b;
- $a_dir =~ s/(\d+)$//;
- my $a_num = $1;
- $b_dir =~ s/(\d+)$//;
- my $b_num = $1;
- return $a_dir cmp $b_dir if $a_dir ne $b_dir;
- return $a_num <=> $b_num;
+ unless (-c $devfile) {
+ warn "Not a chardev";
+ next;
+ }
+ my $entries = $self->{ENTRIES};
+ my $rdev = (stat($devfile))[6];
+ #symlink($devfile, $dest) || die "$0: Failed symlink($devfile, $dest): $!\n";
+ my $minor = $rdev & 0xFF;
+ my $major = $rdev >> 8;
+ my $devt = "$major:$minor";
+ if (defined $devices{$devt}) {
+ warn "$0: Duplicate '$devt' (from '$devfile')";
+ my $d = $devices{$devt};
+ die "POOL='$d->{SUBDIR}', DEST='$d->{DEST}'\n";
+ }
+ $devices{$devt} = {
+ DEVICE => $devfile,
+ DEST => $dest,
+ };
+ push(@{$entries}, $devices{$devt});
}
sub new($$) {
@@ -66,9 +74,14 @@
};
bless $self, $class;
#print STDERR "new($poolname)\n";
- my @dirs;
+ my @selected_chans;
foreach my $comp (@{$components}) {
my @spans;
+ my $select_spec;
+ if($comp =~ /^(.*)\((.*)\)/) {
+ $comp = $1;
+ $select_spec = $2;
+ }
if($comp =~ /^@/) {
@spans = Dahdi::Span::match_location($comp);
unless (@spans) {
@@ -82,55 +95,31 @@
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;
+ $select_spec = '*' unless defined $select_spec;
+ my @selectors = split(/;/, $select_spec);
+ foreach my $sel (@selectors) {
+ my ($port, $chanspec) = split(/\//, $sel);
+ $chanspec = '*' unless defined $chanspec;
+ $port = Dahdi::Utils::glob2regex($port);
+ $chanspec = Dahdi::Utils::glob2regex($chanspec);
+ my @good_spans = grep { $_->hardware_port =~ /^$port$/ } @spans;
+ my @good_chans;
+ foreach my $s (@good_spans) {
+ my @chans = grep { $_->index =~ /^$chanspec$/ } $s->chans;
+ push(@good_chans, @chans);
}
- #warn "Pool $poolname: processing ($comp) '$dir'\n";
- $devdirs{$dir} = { COMPONENT => $comp, DIR => $dir };
- push(@dirs, $dir);
+ push(@selected_chans, @good_chans);
}
+ #print STDERR "Pool $poolname: $comp -- ", join(' ', map({ $_->fqn } @selected_chans)), "\n";
}
- my @all_devfiles;
- foreach my $d (sort @dirs) {
- undef @devfiles;
- find(\&wanted, $d);
- my @devfiles = sort chan_order @devfiles;
- #print STDERR "DEBUG: $d:\n\t", join("\n\t", @devfiles), "\n";
- push(@all_devfiles, @devfiles);
- }
+ my $curr = 1;
my $destdir = "$poolbase/$poolname";
- my $curr = 1;
- my $entries = $self->{ENTRIES};
- foreach (sort @all_devfiles) {
- unless (-c $_) {
- warn "Not a chardev";
- next;
- }
- my $rdev = (stat($_))[6];
+ foreach my $chan (@selected_chans) {
+ my $span = $chan->span;
+ my $devfile = sprintf "/dev/dahdi/spans/%03d/%02d", $span->num, $chan->index;
+ warn "Missing '$devfile'\n" unless -c $devfile;
my $dest = "$destdir/$curr";
- #symlink($_, $dest) || die "$0: Failed symlink($_, $dest): $!\n";
- my $minor = $rdev & 0xFF;
- my $major = $rdev >> 8;
- my $devt = "$major:$minor";
- 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",
- NUM => $curr,
- POOLSTR => "pool/$poolname/$curr",
- DEST => $dest,
- POOL => $self,
- };
- push(@{$entries}, $devices{$devt});
- #print "$_: $devt\n";
+ $self->save_linkinfo($devfile, $dest);
$curr++;
}
return $self;
More information about the svn-commits
mailing list