--- dahdi-base.c.orig 2008-12-04 10:32:00.000000000 +0000 +++ dahdi-base.c 2008-12-04 09:50:29.000000000 +0000 @@ -83,6 +83,7 @@ /* Grab fasthdlc with tables */ #define FAST_HDLC_NEED_TABLES #include +#include #include "hpec/hpec_user.h" @@ -577,6 +578,8 @@ if(spans[span] == master) len += sprintf(page + len, " (MASTER)"); + len += sprintf(page + len, " SyncPrio: %d", spans[span]->syncprio); + if (spans[span]->lineconfig) { /* framing first */ if (spans[span]->lineconfig & DAHDI_CONFIG_B8ZS) @@ -3239,25 +3242,42 @@ { int x; - span->alarms &= ~DAHDI_ALARM_LOOPBACK; - /* Determine maint status */ - if (span->maintstat || span->mainttimer) - span->alarms |= DAHDI_ALARM_LOOPBACK; - /* DON'T CHANGE THIS AGAIN. THIS WAS DONE FOR A REASON. - The expression (a != b) does *NOT* do the same thing - as ((!a) != (!b)) */ - /* if change in general state */ - if ((!span->alarms) != (!span->lastalarms)) { - span->lastalarms = span->alarms; - for (x = 0; x < span->channels; x++) - dahdi_alarm_channel(span->chans[x], span->alarms); - /* Switch to other master if current master in alarm */ - for (x=1; xalarms && (spans[x]->flags & DAHDI_FLAG_RUNNING)) { - if(master != spans[x]) - module_printk(KERN_NOTICE, "Master changed to %s\n", spans[x]->name); - master = spans[x]; - break; + + if (span) { + span->alarms &= ~DAHDI_ALARM_LOOPBACK; + /* Determine maint status */ + if (span->maintstat || span->mainttimer) + span->alarms |= DAHDI_ALARM_LOOPBACK; + /* DON'T CHANGE THIS AGAIN. THIS WAS DONE FOR A REASON. + The expression (a != b) does *NOT* do the same thing + as ((!a) != (!b)) */ + /* if change in general state */ + if ((!span->alarms) != (!span->lastalarms)) { + span->lastalarms = span->alarms; + for (x = 0; x < span->channels; x++) + dahdi_alarm_channel(span->chans[x], span->alarms); + } + } + + /* Good a time as any to check our clock config */ + master = NULL; + for (x=1; xalarms) { // We only care about alarms - not the running flag. Running flag seems not to make sense a lot of the time. + if (master && spans[x]) { + if ((spans[x]->syncprio > 0) && ((spans[x]->syncprio < master->syncprio) || (master->syncprio == 0))) { + module_printk(KERN_NOTICE, "Span ('%s') is new master with syncprio %d which is better than %d\n", spans[x]->name, spans[x]->syncprio, master->syncprio); + master = spans[x]; + } else { + module_printk(KERN_NOTICE, "Span ('%s') had syncprio %d which was worse than %d\n", + spans[x]->name, spans[x]->syncprio, master->syncprio); + } + } else if (spans[x]) { + if (spans[x]->syncprio > 0) { + module_printk(KERN_NOTICE, "Span ('%s') is new master with syncprio %d which is better than 0\n", spans[x]->name, spans[x]->syncprio); + master = spans[x]; + } else { + module_printk(KERN_NOTICE, "No Master yet because span ('%s') has syncprio 0\n", spans[x]->name); + } } } } @@ -3721,6 +3741,7 @@ spans[lc.span]->lbo = lc.lbo; spans[lc.span]->txlevel = lc.lbo; spans[lc.span]->rxlevel = 0; + spans[lc.span]->syncprio = lc.sync; return spans[lc.span]->spanconfig(spans[lc.span], &lc); } @@ -4170,6 +4191,7 @@ default: return dahdi_common_ioctl(inode, file, cmd, data, 0); } + dahdi_alarm_notify(NULL); return 0; } @@ -5391,13 +5413,7 @@ "%d channels\n", span->spanno, span->name, span->channels); } - if (!master || prefmaster) { - master = span; - if (debug) { - module_printk(KERN_NOTICE, "Span ('%s') is new master\n", - span->name); - } - } + dahdi_alarm_notify(span); return 0; }