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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Mar 28 16:24:54 CDT 2010


Author: tzafrir
Date: Sun Mar 28 16:24:50 2010
New Revision: 8442

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8442
Log:
dahdi pools: group devices of several spans

Make it possible to group DAHDI device files of several spans in a
simple and configurable way through a 'pool' file.

/etc/dahdi/pool is a mapping of "span names" (location / hardware_id) to
logical group: each line is a set of of such logical names.

Generate dahdi-channels.conf with named spans for spans that are in
such a pool.

Added:
    tools/team/tzafrir/sysfs/xpp/dahdi_pools   (with props)
    tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm   (with props)
Modified:
    tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Chans.pm
    tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Config/Gen/Chandahdi.pm
    tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm

Added: tools/team/tzafrir/sysfs/xpp/dahdi_pools
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/dahdi_pools?view=auto&rev=8442
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/dahdi_pools (added)
+++ tools/team/tzafrir/sysfs/xpp/dahdi_pools Sun Mar 28 16:24:50 2010
@@ -1,0 +1,123 @@
+#! /usr/bin/perl -w
+#
+# Written by Oron Peled <oron at actcom.co.il>
+# Copyright (C) 2010, Xorcom
+# This program is free software; you can redistribute and/or
+# modify it under the same terms as Perl itself.
+#
+# $Id$
+#
+use strict;
+use File::Basename;
+BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); }
+use Dahdi::Pool;
+
+my $poolbase = "/dev/dahdi/pool";
+
+sub make_path($) {
+	my $dir = shift || die;
+	system("mkdir -p -- '$dir'");
+	die "$0: Failed creating '$dir' (status $?)" if $?;
+}
+
+sub remove_tree($) {
+	my $dir = shift || die;
+	system("rm -rf -- '$dir'");
+	die "$0: Failed removing '$dir' (status $?)" if $?;
+}
+
+sub process_pool($) {
+	my $pool = shift || die;
+	my $poolname = $pool->{NAME};
+	my $destdir = "$poolbase/$poolname";
+	make_path "$destdir";
+	foreach (@{$pool->{ENTRIES}}) {
+		my $device = $_->{DEVICE};
+		my $dest = $_->{DEST};
+		symlink($device, $dest) || die "$0: Failed symlink($device, $dest): $!\n";
+		#print "symlink($device, $dest)\n";
+	}
+}
+
+my @pools = Dahdi::Pool->get_pools;
+remove_tree($poolbase);
+foreach my $pool (@pools) {
+	process_pool($pool);
+}
+
+__END__
+
+=head1 NAME
+
+dahdi_pool - maintain pools of DAHDI spans
+
+=head1 SYNOPSIS
+
+dahdi_pool
+
+=head1 DESCRIPTION
+
+dahdi_pool 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.
+
+Pools are configured through C</etc/dahdi/pool>. This file has:
+
+  # comments and blank lines are ignored
+  # format is:
+  # <name of pool> <directory> [<directory> ...]
+
+The name of each pool is the name of a subdirecotry under
+C</dev/dahdi/pool> to create. It should probably avoid any special
+characters.
+
+Following in the same line are names of directories under
+/etc/dahdi/devices in which to look for device nodes.
+
+The udev rules create symlinks from the subdirectories of
+C<dev/dahdi/devices> to the device files C</dev/dahdi/NNN>. Those may be
+created for the location and also (if it is not empty) for the
+hardware_id field of the span.
+
+For example, on a system with two Astribank 32FXS we would get under
+C</dev/dahdi/devices> the subdirectories
+C<@usb-0000:00:1d_7-3>, C<@usb-0000:00:1d_7-4> (locations), C<usb:12345678>.
+and C<usb:11223344> (hardware_ids). Under each of those we have the
+subdirectories C<00>, C<10>, C<20> and C<30>. 
+
+Several optional pools would be:
+
+  astbank1  usb:12345678
+  astbank2  usb:11223344
+
+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 
+
+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.
+
+=head1 FILES
+
+=over
+
+=item /etc/dahdi/pool
+
+List of pools. See description above.
+
+=item /dev/dahdi/devices
+
+"Physical" device symlinks that may be included in pools.
+
+=item /dev/dahdi/pool
+
+Location of generated device pools.
+
+=back
+

Propchange: tools/team/tzafrir/sysfs/xpp/dahdi_pools
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tools/team/tzafrir/sysfs/xpp/dahdi_pools
------------------------------------------------------------------------------
    svn:executable = *

Propchange: tools/team/tzafrir/sysfs/xpp/dahdi_pools
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: tools/team/tzafrir/sysfs/xpp/dahdi_pools
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Chans.pm
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Chans.pm?view=diff&rev=8442&r1=8441&r2=8442
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Chans.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Chans.pm Sun Mar 28 16:24:50 2010
@@ -9,6 +9,7 @@
 #
 use strict;
 use Dahdi::Utils;
+use Dahdi::Pool;
 
 =head1 NAME
 
@@ -112,8 +113,16 @@
 	};
 	bless $self, $pack;
 	$self->{NUM} = $self->_get_dev_attr('channo');
+	$self->{DEV} = $self->_get_dev_attr('dev');
 	$self->{INDEX} = $self->_get_dev_attr('chanpos');
 	$self->{FQN} = $self->_get_dev_attr('name'); # TODO: correct?
+	my $poolentry = Dahdi::Pool->dev2poolentry($self->{DEV});
+	if(defined $poolentry) {
+		$self->{POOLPOS} = $poolentry->{NUM};
+		$span->{SUBDIR} = $poolentry->{SUBDIR} unless defined $span->{SUBDIR};
+		my $pool = $poolentry->{POOL};
+		$span->{POOLNAME} = $pool->{NAME} unless defined $span->{POOLNAME};
+	}
 
 	$self->{ALARMS} = [];
 	my $alarms = $self->_get_dev_attr('alarms');

Modified: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Config/Gen/Chandahdi.pm
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Config/Gen/Chandahdi.pm?view=diff&rev=8442&r1=8441&r2=8442
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Config/Gen/Chandahdi.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Config/Gen/Chandahdi.pm Sun Mar 28 16:24:50 2010
@@ -36,6 +36,11 @@
 			print "$arg =\n";
 		}
 	}
+}
+
+sub has_pool($) {
+	my $span = shift || die;
+	return defined $span->subdir && $span->subdir;
 }
 
 sub gen_openr2($$$) {
@@ -152,6 +157,7 @@
 sub gen_channel($$) {
 	my $self = shift || die;
 	my $chan = shift || die;
+	my $relative_numbers = has_pool($chan->span);
 	my $gconfig = $self->{GCONFIG};
 	my $type = $chan->type;
 	my $num = $chan->num;
@@ -160,15 +166,22 @@
 	my $sig = $gconfig->{'chan_dahdi_signalling'}{$type};
 	my $context = $gconfig->{'context'}{$type};
 	my $group = $gconfig->{'group'}{$type};
-	my $callerid;
 	my $immediate;
 
 	return if $type eq 'EMPTY';
 	die "missing default_chan_dahdi_signalling for chan #$num type $type" unless $sig;
 	die "missing context for chan #$num type $type" unless $context;
-	$callerid = ($type eq 'FXO')
-			? 'asreceived'
-			: sprintf "\"Channel %d\" <%04d>", $num, $exten;
+	my $caller_id;
+	my $pos;
+	if($relative_numbers) {
+		$pos = $chan->poolpos;
+		my $pool = $chan->span->poolname();
+		$caller_id = sprintf "\"Channel %s-%d\" <%04d>", $pool, $num, $exten;
+	} else {
+		$pos = $num;
+		$caller_id = sprintf "\"Channel %d\" <%04d>", $num, $exten;
+	}
+	$caller_id = ($type eq 'FXO') ? 'asreceived' : $caller_id;
 	if($type eq 'IN') {
 		$immediate = 'yes';
 	}
@@ -179,16 +192,16 @@
 	$signalling = " " . $signalling if $signalling;
 	my $info = $chan->info;
 	$info = " " . $info if $info;
-	printf ";;; line=\"%d %s%s%s\"\n", $num, $chan->fqn, $signalling, $info;
+	printf ";;; line=\"%d (%d) %s%s%s\"\n", $pos, $num, $chan->fqn, $signalling, $info;
 	printf "signalling=$sig\n";
-	printf "callerid=$callerid\n";
+	printf "callerid=$caller_id\n";
 	printf "mailbox=%04d\n", $exten unless $type eq 'FXO';
 	if(defined $group) {
 		printf "group=$group\n";
 	}
 	printf "context=$context\n";
 	printf "immediate=$immediate\n" if defined $immediate;
-	printf "channel => %d\n", $num;
+	printf "channel => %d\n", $pos;
 	# Reset following values to default
 	printf "callerid=\n";
 	printf "mailbox=\n" unless $type eq 'FXO';
@@ -227,6 +240,11 @@
 HEAD
 	foreach my $span (@spans) {
 		printf "; Span %d: %s %s\n", $span->num, $span->name, $span->description;
+		my $subdir = undef;
+		if(has_pool($span)) {
+			$subdir = $span->subdir;
+			printf "subdir = %s\n", $subdir;
+		}
 		if($span->is_digital) {
 			if($span->is_pri) {
 				if($gconfig->{'pri_connection_type'} eq 'R2') {
@@ -253,6 +271,7 @@
 				$self->gen_channel($chan);
 			}
 		}
+		print "subdir=\n" if defined $subdir;
 		print "\n";
 	}
 	close F;

Added: 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=auto&rev=8442
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm (added)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm Sun Mar 28 16:24:50 2010
@@ -1,0 +1,134 @@
+package Dahdi::Pool;
+#
+# Written by Oron Peled <oron at actcom.co.il>
+# Copyright (C) 2010, Xorcom
+# This program is free software; you can redistribute and/or
+# modify it under the same terms as Perl itself.
+#
+# $Id$
+#
+use strict;
+use File::Find;
+
+=head1 NAME
+
+Dahdi::Spans - Perl interface to a Dahdi pool of spans
+
+A pool of spans is a directory under C</dev/dahdi/pool> with symlinks to
+the real device files.
+
+Dahdi::Pool objects are normally created in the initial scan of
+C<Dahdi::spans()>.
+
+A C<Dahdi::Pool> object is essentially a container of "pool-entries".
+Each of those represents a symlink to a device.
+
+=head1 get_pools()
+
+Returns the global hash of pools. Use it to search for a specific pool
+by name.
+
+=cut
+
+my $cfgfile = "/etc/dahdi/chan_pools";
+my $poolbase = "/dev/dahdi/pool";
+my %pool_dirs;
+my %devices;
+my %pools;
+
+my @devfiles;
+
+sub wanted {
+	return unless /^\d+$/ && -l;
+	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;
+}
+
+sub new($$) {
+	my $class = shift || die;
+	my $poolname = shift || die;
+	my $self = {
+		NAME	=> $poolname,
+		ENTRIES	=> [],
+	};
+	bless $self, $class;
+	my $dirs = $pool_dirs{$poolname};
+	my @dirs = map { "/dev/dahdi/devices/$_" } @{$dirs};
+	my @all_devfiles;
+	foreach my $d (@dirs) {
+		undef @devfiles;
+		find(\&wanted, $d);
+		my @devfiles = sort chan_order @devfiles;
+		#print "$d:\n", join("\n", @devfiles), "\n";
+		push(@all_devfiles, @devfiles);
+	}
+	my $destdir = "$poolbase/$poolname";
+	my $curr = 1;
+	foreach (@all_devfiles) {
+		warn "Not a chardev" unless -c $_;
+		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};
+		$devices{$devt} = {
+				DEVICE	=> $_,
+				SUBDIR	=> "pool/$poolname",
+				NUM	=> $curr,
+				POOLSTR	=> "pool/$poolname/$curr",
+				DEST	=> $dest,
+				POOL	=> $self,
+			};
+		$self->{ENTRIES}[$curr - 1] = $devices{$devt};
+		#print "$_: $devt\n";
+		$curr++;
+	}
+	return $self;
+}
+
+sub dev2poolentry($) {
+	my $class = shift || die;
+	my $devt = shift || die;
+	my $dev = $devices{$devt};
+	return $dev;
+}
+
+sub get_pools() {
+	my $class = shift || die;
+	return values %pools;
+}
+
+open(F, $cfgfile) || exit 0;
+while(<F>) {
+	chomp;
+	s/#.*//;
+	next unless /\S/;
+	my ($poolname, @dirs) = split;
+	die "$cfgfile:$.: Bad pool name '$poolname'\n"
+		if $poolname =~ m/[\/\.]/;
+	die "$cfgfile:$.: Pool '$poolname' without components\n"
+		unless @dirs;
+	die "$cfgfile:$.: Doubly defined pool '$poolname'\n"
+		if exists $pool_dirs{$poolname};
+	$pool_dirs{$poolname} = \@dirs;
+}
+close F;
+
+foreach my $poolname (keys %pool_dirs) {
+	my $p = Dahdi::Pool->new($poolname);
+	$pools{$poolname} = $p;
+}
+
+1;

Propchange: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Pool.pm
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=8442&r1=8441&r2=8442
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm Sun Mar 28 16:24:50 2010
@@ -217,6 +217,8 @@
 	$self->{MANUFACTURER} = $self->_get_dev_attr('manufacturer');
 	# FIXME: the following is a number, rather than a readable value:
 	$self->{ALARMS} = $self->_get_dev_attr('alarms');
+	$self->{HARDWARE_ID} = $self->_get_dev_attr('hardware_id');
+	$self->{HARDWARE_PORT} = $self->_get_dev_attr('hardware_port');
 	
 	$self->{CHANS} = [];
 	my @channels;




More information about the svn-commits mailing list