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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon May 17 17:33:44 CDT 2010


Author: tzafrir
Date: Mon May 17 17:33:40 2010
New Revision: 8655

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8655
Log:
DAHDI-tools: dial_byname: Add span mapping:

* dahdi_genconf generate span strings for "span=" lines:
  - Hardware ID + Span ID (if there's Hardware ID)
  - Otherwise: Location + Span ID (if there's Location)
  - Otherwise: nomal span number
* dahdi_pools:
  - creates a /dev/dahdi/spanmap
  - In this directory, symlinks translate alternative span names
    to span numbers.
* dahdi_cfg:
  - Tries to use /dev/dahdi/spanmap/* to map span name to span number.
  - Alternatively, tries to parse simple numbers (backward compat)
  - Otherwise, fails.
  - The printconfig() function, also shows the spanmap names (if available).

Modified:
    tools/team/tzafrir/sysfs/dahdi_cfg.c
    tools/team/tzafrir/sysfs/xpp/dahdi_pools
    tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Config/Gen/System.pm
    tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm

Modified: tools/team/tzafrir/sysfs/dahdi_cfg.c
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/dahdi_cfg.c?view=diff&rev=8655&r1=8654&r2=8655
==============================================================================
--- tools/team/tzafrir/sysfs/dahdi_cfg.c (original)
+++ tools/team/tzafrir/sysfs/dahdi_cfg.c Mon May 17 17:33:40 2010
@@ -138,6 +138,7 @@
 static int	path_channels;
 static char	*chan_pathnames[DAHDI_MAX_CHANNELS];
 static int	chan_indexes[DAHDI_MAX_CHANNELS];
+static char	*spanmap[DAHDI_MAX_SPANS];
 
 static const char *sigtype_to_str(const int sig)
 {
@@ -312,6 +313,40 @@
 	return 0;
 }
 
+int span_string2num(const char *span_string)
+{
+	char		path[PATH_MAX];
+	struct stat	stbuf;
+	char		spanstr[10];
+	int		span;
+
+	snprintf(path, sizeof(path), "/dev/dahdi/spanmap/%s", span_string);
+	if (lstat(path, &stbuf) >= 0) {
+		int n;
+
+		if (! S_ISLNK(stbuf.st_mode)) {
+			error("span '%s' (%s) is not a symlink\n", span_string, path);
+			return -1;
+		}
+		n = readlink(path, spanstr, sizeof(spanstr));
+		if (n < 0) {
+			error("failed reading symlink '%s': %s\n", path, strerror(errno));
+			return -1;
+		}
+		spanstr[n] = '\0';
+		span_string = spanstr;
+	}
+	if (sscanf(span_string, "%i", &span) != 1) {
+		error("Span number should be a valid span number, not '%s'\n", span_string);
+		return -1;
+	}
+	if(span_string == spanstr) {
+		spanmap[span] = strdup(path);
+		printf("%s: %d -> %s\n", __func__, span, spanmap[span]);
+	}
+	return span;
+}
+
 int spanconfig(char *keyword, char *args)
 {
 	static char *realargs[10];
@@ -325,8 +360,8 @@
 		error("Incorrect number of arguments to 'span' (should be <spanno>,<timing>,<lbo>,<framing>,<coding>[, crc4 | yellow [, yellow]])\n");
 		return -1;
 	}
-	res = sscanf(realargs[0], "%i", &span);
-	if (res != 1) {
+	span = span_string2num(realargs[0]);
+	if (span < 0) {
 		error("Span number should be a valid span number, not '%s'\n", realargs[0]);
 		return -1;
 	}
@@ -1285,6 +1320,9 @@
 			lc[x].lineconfig & DAHDI_CONFIG_B8ZS ? "B8ZS" :
 			lc[x].lineconfig & DAHDI_CONFIG_HDB3 ? "HDB3" : "???"),
 		       lbostr[lc[x].lbo]);
+		if(spanmap[lc[x].span]) {
+			printf("\t-> %s\n", spanmap[lc[x].span]);
+		}
 	}
 	for (x=0;x<numdynamic;x++) {
 		printf("Dynamic span %d: driver %s, addr %s, channels %d, timing %d\n",

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=8655&r1=8654&r2=8655
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/dahdi_pools (original)
+++ tools/team/tzafrir/sysfs/xpp/dahdi_pools Mon May 17 17:33:40 2010
@@ -10,9 +10,11 @@
 use strict;
 use File::Basename;
 BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); }
+use Dahdi::Span;
 use Dahdi::Pool;
 
 my $poolbase = "/dev/dahdi/pool";
+my $spanmap = "/dev/dahdi/spanmap";
 
 sub make_path($) {
 	my $dir = shift || die;
@@ -24,6 +26,9 @@
 	print STDERR "Removing '$poolbase'\n";
 	system("rm -rf -- '$poolbase'");
 	die "$0: Failed removing '$poolbase' (status $?)" if $?;
+	print STDERR "Removing '$spanmap'\n";
+	system("rm -rf -- '$spanmap'");
+	die "$0: Failed removing '$spanmap' (status $?)" if $?;
 }
 
 sub list_pools() {
@@ -59,6 +64,39 @@
 	}
 }
 
+sub list_spanmaps() {
+	my @entries = glob "$spanmap/*";
+	print "\nSpan Map:\n";
+	foreach my $link (sort @entries) {
+		my $name = $link;
+		$name =~ s|$spanmap/||;
+		my $linkdest = readlink "$link";
+		if($linkdest) {
+			print "$name -> $linkdest\n";
+		}
+	}
+}
+
+sub create_spanmap($) {
+	my $span = shift || die;
+	my $hardware_id = $span->hardware_id;
+	my $location = $span->location;
+	my $span_id = $span->span_id;
+	my $num = $span->num;
+	my $link;
+	make_path "$spanmap";
+	if ($hardware_id) {
+		$link = sprintf "%s/%s(%s)", $spanmap, $hardware_id, $span_id;
+	}
+	if ($location) {
+		$link = sprintf "%s/%s(%s)", $spanmap, $location, $span_id;
+	}
+	if (defined $link) {
+		#print STDERR "symlink(\"$num\", \"$link\")\n";
+		symlink($num, $link) || die "$0: Failed symlink($num, $link): $!\n";
+	}
+}
+
 sub usage() {
 	die "Usage: $0 {list|create|delete}\n";
 }
@@ -67,14 +105,19 @@
 
 if($mode eq 'create') {
 	my @pools = Dahdi::Pool->get_pools;
+	my @spans = Dahdi::spans;
 	remove_tree();
 	foreach my $pool (@pools) {
 		process_pool($pool);
+	}
+	foreach my $span (@spans) {
+		create_spanmap($span);
 	}
 } elsif($mode eq 'delete') {
 	remove_tree();
 } elsif($mode eq 'list') {
 	list_pools;
+	list_spanmaps;
 } else {
 	usage;
 }

Modified: tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Config/Gen/System.pm
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Config/Gen/System.pm?view=diff&rev=8655&r1=8654&r2=8655
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Config/Gen/System.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Config/Gen/System.pm Mon May 17 17:33:40 2010
@@ -125,8 +125,8 @@
 		$framing = 'cas';
 	}
 	$timing = ($termtype eq 'NT') ? 0 : $bri_te_last_timing++;
-	printf "span=%d,%d,%d,%s,%s%s%s%s%s\n",
-			$num,
+	printf "span=%s,%d,%d,%s,%s%s%s%s%s\n",
+			$span->unique_string,
 			$timing,
 			$lbo,
 			$framing,

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=8655&r1=8654&r2=8655
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm Mon May 17 17:33:40 2010
@@ -335,6 +335,12 @@
 	$self->{ALARMS} = $self->_get_dev_attr('alarms');
 	$self->{HARDWARE_ID} = $self->_get_dev_attr('hardware_id');
 	$self->{SPAN_ID} = $self->_get_dev_attr('span_id');
+	my $hwname = $self->{HARDWARE_ID} || $self->{LOCATION};
+	if (defined $hwname) {
+		$self->{UNIQUE_STRING} = sprintf "%s(%s)", $hwname, $self->{SPAN_ID};
+	} else {
+		$self->{UNIQUE_STRING} = $num;
+	}
 	if ($self->spantype =~ /^(TE|NT|BRI|BRI_(NT|TE))$/) {
 		# FIXME: BRI modules of wct24xxp?
 		$self->{IS_DIGITAL} = 1;




More information about the svn-commits mailing list