dahdi_registration: adapt to pinned-spans

* If xpp.dahdi_autoreg parameter is 'Y' -- Skip actuall registration.
* If dahdi.auto_assign_spans is '0' and there's no /etc/dahdi/pinned-spans.conf
  Than use 'span_assignments auto ...' to assign device spans.
* Since dahdi_registration iterate in correct xpp_order, the span
  assignment logic provides migration path for users who did not
  generate their pinned-spans.conf configuration yet.

Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
This commit is contained in:
Oron Peled 2013-09-29 18:24:08 +02:00 committed by Tzafrir Cohen
parent 60fca920bc
commit 680f3e1d1d
1 changed files with 48 additions and 4 deletions

View File

@ -19,11 +19,27 @@ use Dahdi::Xpp::Xpd;
use Getopt::Std;
sub usage {
die "Usage: $0 [-s sort_order] [on|off|1|0]\n";
die "Usage: $0 [-v] [-R] [-s sort_order] [on|off|1|0]\n";
}
sub check_param {
my $param = shift || die;
open(F, $param) || return '';
my $val = <F>;
close F;
chomp $val;
return $val;
}
my %opts;
getopts('s:', \%opts) || usage;
getopts('vRs:', \%opts) || usage;
my $dahdi_autoreg = check_param('/sys/module/xpp/parameters/dahdi_autoreg') eq 'Y';
my $auto_assign_spans = check_param('/sys/module/dahdi/parameters/auto_assign_spans') eq '1';
my $pinned_spans_config = $ENV{'PINNED_SPANS_CONF_FILE'} || '/etc/dahdi/pinned-spans.conf';
my $span_types_config = $ENV{'SPAN_TYPES_CONF_FILE'} || '/etc/dahdi/span-types.conf';
my $have_pinned_spans_config = -f $pinned_spans_config || 0;
my $have_span_types_config = -f $span_types_config || 0;
my $sorter;
my $sort_order = $opts{'s'};
@ -41,9 +57,11 @@ if(defined $sort_order) {
@ARGV == 0 or @ARGV == 1 or usage;
my $on = shift;
my $verbose = 0;
my $verbose = $opts{'v'};
my $should_output = 1;
#print "dahdi_autoreg=$dahdi_autoreg auto_assign_spans=$auto_assign_spans have_pinned_spans_config='$have_pinned_spans_config' have_span_types_config='$have_span_types_config'\n";
if(defined($on)) { # Translate to booleans
$on = uc($on);
$on =~ /^(ON|OFF|1|0)$/ or usage;
@ -51,6 +69,8 @@ if(defined($on)) { # Translate to booleans
$should_output = 0 unless $verbose;
}
undef $on if $dahdi_autoreg and not $opts{'R'};
sub state2str($) {
return (shift)?"on":"off";
}
@ -80,6 +100,15 @@ foreach my $xbus (Dahdi::Xpp::xbuses($sorter)) {
}
myprintf "%3s ==> %3s\n", state2str($prev), state2str($on);
}
if (defined($on) && $on && ! $have_pinned_spans_config && ! $auto_assign_spans) {
# Emulate /etc/dahdi/pinned-spans.conf:
# - We iterate over $xbus according to /etc/dahdi/xpp_order
# - We "auto" assign all spans of current $xbus
my $devpath = sprintf "/sys/bus/dahdi_devices/devices/astribanks:xbus-%02d", $xbus->num;
my @cmd = ('span_assignments', 'auto', $devpath);
system @cmd;
warn "Failed '@cmd' (status=$?)\n" if $?;
}
}
myprintf "# Sorted: $sort_order\n" if defined $sort_order;
@ -91,7 +120,7 @@ dahdi_registration - Handle registration of Xorcom XPD modules in dahdi.
=head1 SYNOPSIS
dahdi_registration [-s sortorder] [on|off]
dahdi_registration [-v] [-s sortorder] [-R] [on|off]
=head1 DESCRIPTION
@ -105,6 +134,12 @@ Span registration should generally always succeed. Span unregistration may
fail if channels from the span are in use by e.g. asterisk. In such a case
you'll also see those channels as '(In use)' in the output of lsdahdi(8).
dahdi_registration is intended to be used when the xpp module parameter
B<dahdi_autoreg> is false (and implicitly: when the dahdi module parameter
B<auto_assign_span> is true.
If dahdi_autoreg is true, the program will normally do nothing.
=head2 Parameters
off -- deregisters all XPD's from dahdi.
@ -115,6 +150,15 @@ on -- registers all XPD's to dahdi.
=over
=item -v
verbose output.
=item -R
Force operations (on/off) even if the module parameter B<dahdi_autoreg>
for xpp is enabled (which makes this program unneeded).
=item -s I<sort_order>
The sort order to use.