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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon May 17 18:09:55 CDT 2010


Author: tzafrir
Date: Mon May 17 18:09:51 2010
New Revision: 8661

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8661
Log:
add symlink_span:
* New script to be installed in /usr/share/dahdi and be called from UDEV:
  - Creates symlinks mapping span names to numbers
  - Removed old span links code from dahdi_pools
  - Renamed spanmap -> span-names (the name spanmap is already used
    for trunkgroups in Asterisk)
  - All done in the scripts now (dahdi_cfg simply get a link name)
* Add '-k' flag to dahdi_cfg (keep going) -- so it does not abort
  if some channels cannot be configured.
* Also handle the "span=" in T1-CAS (was separate config)

Added:
    tools/team/tzafrir/sysfs/xpp/symlink_span   (with props)
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=8661&r1=8660&r2=8661
==============================================================================
--- tools/team/tzafrir/sysfs/dahdi_cfg.c (original)
+++ tools/team/tzafrir/sysfs/dahdi_cfg.c Mon May 17 18:09:51 2010
@@ -110,6 +110,8 @@
 
 static int showpaths = 0;
 
+static int keep_going = 0;
+
 static int numdynamic = 0;
 
 static char zonestoload[DAHDI_TONE_ZONE_MAX][10];
@@ -138,7 +140,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 char	*span_names[DAHDI_MAX_SPANS];
 
 static const char *sigtype_to_str(const int sig)
 {
@@ -320,7 +322,7 @@
 	char		spanstr[PATH_MAX];
 	int		span;
 
-	snprintf(path, sizeof(path), "/dev/dahdi/spanmap/%s", span_string);
+	snprintf(path, sizeof(path), "/dev/dahdi/%s", span_string);
 	if (lstat(path, &stbuf) >= 0) {
 		int	n;
 		char	*tmp;
@@ -350,12 +352,16 @@
 		}
 	}
 	if (sscanf(span_string, "%d", &span) != 1) {
-		error("Span number should be a valid span number, not '%s'\n", span_string);
-		return -1;
+		if(keep_going) {
+			return 0;
+		} else {
+			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]);
+		span_names[span] = strdup(path);
+		printf("%s: %d -> %s\n", __func__, span, span_names[span]);
 	}
 	return span;
 }
@@ -374,7 +380,12 @@
 		return -1;
 	}
 	span = span_string2num(realargs[0]);
-	if (span <= 0) {
+	if (span == 0) {
+		if (debug & DEBUG_APPLY) {
+			printf("Skipping failed span '%s'\n", realargs[0]);
+		}
+		return 0;
+	} else if (span < 0) {
 		error("Span number should be a valid span number, not '%s'\n", realargs[0]);
 		return -1;
 	}
@@ -460,11 +471,11 @@
 	snprintf(path, sizeof(path), "/dev/dahdi/%s/%d", relative_path, relative_index);
 	if (stat(path, &stbuf) < 0) {
 		perror(path);
-		exit(-1);
+		return (keep_going) ? 0 : -1;
 	}
 	if (! S_ISCHR(stbuf.st_mode)) {
 		fprintf(stderr, "%s is not a character device\n", path);
-		exit(-1);
+		return (keep_going) ? 0 : -1;
 	}
 	channo = minor(stbuf.st_rdev);
 	path_channels++;
@@ -527,6 +538,12 @@
 			}
 			for (y=start;y<=finish;y++) {
 				int realchan = path2channo(pname, y);
+				if (realchan < 0) {
+					error("Could not resolve '%s' to valid channel\n", pname);
+					return -1;
+				}
+				if (realchan == 0)
+					continue;
 				chans[realchan]=1;
 				chan_pathnames[realchan] = pname;
 				chan_indexes[realchan] = y;
@@ -545,6 +562,12 @@
 				return -1;
 			}
 			realchan = path2channo(pname, chan);
+			if (realchan < 0) {
+				error("Could not resolve '%s' to valid channel\n", pname);
+				return -1;
+			}
+			if (realchan == 0)
+				continue;
 			chans[realchan]=1;
 			chan_pathnames[realchan] = pname;
 			chan_indexes[realchan] = chan;
@@ -1333,8 +1356,8 @@
 			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]);
+		if(span_names[lc[x].span]) {
+			printf("\t-> %s\n", span_names[lc[x].span]);
 		}
 	}
 	for (x=0;x<numdynamic;x++) {
@@ -1483,7 +1506,7 @@
 	char *key, *value;
 	int x,found;
 
-	while((c = getopt(argc, argv, "fthc:vsd::p")) != -1) {
+	while((c = getopt(argc, argv, "fthc:vsd::pk")) != -1) {
 		switch(c) {
 		case 'c':
 			filename=optarg;
@@ -1515,6 +1538,9 @@
 		case 'p':
 			showpaths = 1;
 			break;
+		case 'k':
+			keep_going = 1;
+			break;
 		}
 	}
 	

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=8661&r1=8660&r2=8661
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/dahdi_pools (original)
+++ tools/team/tzafrir/sysfs/xpp/dahdi_pools Mon May 17 18:09:51 2010
@@ -14,7 +14,6 @@
 use Dahdi::Pool;
 
 my $poolbase = "/dev/dahdi/pool";
-my $spanmap = "/dev/dahdi/spanmap";
 
 sub make_path($) {
 	my $dir = shift || die;
@@ -26,9 +25,6 @@
 	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() {
@@ -64,39 +60,6 @@
 	}
 }
 
-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";
 }
@@ -110,14 +73,10 @@
 	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=8661&r1=8660&r2=8661
==============================================================================
--- 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 18:09:51 2010
@@ -57,8 +57,8 @@
 	my $span_yellow = $span->yellow();
 	$span_yellow = (defined $span_yellow) ? ",$span_yellow" : '';
 	$timing = ($termtype eq 'NT') ? 0 : $bri_te_last_timing++;
-	printf "span=%d,%d,%d,%s,%s%s%s\n",
-			$num,
+	printf "span=%s,%d,%d,%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=8661&r1=8660&r2=8661
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm (original)
+++ tools/team/tzafrir/sysfs/xpp/perl_modules/Dahdi/Span.pm Mon May 17 18:09:51 2010
@@ -336,7 +336,7 @@
 	$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};
+		$self->{UNIQUE_STRING} = sprintf "span-names/%s(%s)", $hwname, $self->{SPAN_ID};
 	} else {
 		$self->{UNIQUE_STRING} = $num;
 	}

Added: tools/team/tzafrir/sysfs/xpp/symlink_span
URL: http://svnview.digium.com/svn/dahdi/tools/team/tzafrir/sysfs/xpp/symlink_span?view=auto&rev=8661
==============================================================================
--- tools/team/tzafrir/sysfs/xpp/symlink_span (added)
+++ tools/team/tzafrir/sysfs/xpp/symlink_span Mon May 17 18:09:51 2010
@@ -1,0 +1,60 @@
+#! /bin/sh
+
+set -e
+
+#exec 2> /tmp/dahdi-symlinks-$$.stderr
+#env 1>&2
+
+SPANMAP="/dev/dahdi/span-names"
+LINK_DEST="/dev/dahdi/spans/${SPAN_NUM}"
+
+create_links() {
+	mkdir -p "$SPANMAP"
+
+	SPAN_ID=`cat "/sys${DEVPATH}/span_id" | tr -d '\n' | tr '!' '/' | tr -c 'a-zA-Z0-9/:.-' '_'`
+	if [ "$SPAN_ID" == '' ]; then
+		echo >&2 "$0: Missing span_id attribute for '$DEVPATH'"
+		exit 1
+	fi
+	LOCATION=`cat "/sys${DEVPATH}/location" | tr -d '\n' | tr '!' '/' | tr -c 'a-zA-Z0-9/:.-' '_'`
+	if [ "$LOCATION" != '' ]; then
+		LINK="${SPANMAP}/@${LOCATION}($SPAN_ID)"
+		echo "ln -s '$LINK_DEST' '$LINK'" 1>&2
+		ln -s "$LINK_DEST" "$LINK" 1>&2
+	else
+		echo >&2 "$0: Missing location attribute for '$DEVPATH'"
+	fi
+	HARDWARE_ID=`cat "/sys${DEVPATH}/hardware_id" | tr -d '\n' | tr '!' '/' | tr -c 'a-zA-Z0-9/:.-' '_'`
+	if [ "$HARDWARE_ID" != '' ]; then
+		LINK="${SPANMAP}/${HARDWARE_ID}($SPAN_ID)"
+		echo "ln -s '$LINK_DEST' '$LINK'" 1>&2
+		ln -s "$LINK_DEST" "$LINK" 1>&2
+	else
+		echo >&2 "$0: Missing hardware_port attribute for '$DEVPATH'"
+	fi
+}
+
+remove_links() {
+	for i in "$SPANMAP/"*
+	do
+		if [ -L "$i" ]; then
+			LINK_DEST=`readlink "$i"`
+			REAL_SPAN_NUM=`echo "$DEVPATH" | sed 's/.*-//'`
+			if [ "$LINK_DEST" = "/dev/dahdi/spans/$REAL_SPAN_NUM" ]; then
+				echo >&2 "$0: Removing '$i'"
+				rm -f "$i" 1>&2
+			fi
+		fi
+	done
+	echo "$0: Try to remove '$SPANMAP'"
+	rmdir "$SPANMAP" 1>&2
+}
+
+case "$ACTION" in
+online)
+	create_links
+	;;
+offline)
+	remove_links
+	;;
+esac

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

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

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

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




More information about the svn-commits mailing list