[svn-commits] irroot: branch irroot/distrotech-customers-10 r342537 - in /team/irroot/distr...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Oct 26 00:37:17 CDT 2011


Author: irroot
Date: Wed Oct 26 00:37:07 2011
New Revision: 342537

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=342537
Log:
Multiple revisions 342381,342384,342436,342485,342488

........
  r342381 | twilson | 2011-10-25 21:53:13 +0200 (Tue, 25 Oct 2011) | 12 lines
  
  Properly update membercount for reloaded members
  
  Since q->membercount is set to 0 before reloading, it is important
  to increment it again for reloaded members as well as added.
  
  (closes issue AST-676)
  
  Review: https://reviewboard.asterisk.org/r/1541/
  ........
  
  Merged revisions 342380 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
  r342384 | twilson | 2011-10-25 22:04:15 +0200 (Tue, 25 Oct 2011) | 24 lines
  
  Simplify queue membercount code
  
  Despite an ominous sounding comment stating that membercount was for "logged
  in" members only and thus we couldn't use ao2_container_count(), I could not
  find a single place in the code where that seemed to be accurate. The only time
  we decremented membercount was when we were marking something dead or actually
  removing it. The only places we incremented it were either after ao2_link(), or
  trying to correct for having set it to 0 during a reload. In every case where
  we were correcting the value, it seemed that we were trying to make the count
  actually match what ao2_container_count() would return. The only place I could
  find where we made a determination about something being "logged in" or not, we
  didn't trust the membercount, but instead looked at devicestate, paused, etc.
  
  This patch removes membercount, replaces its use with ao2_container_count, and
  manually adds the results of ao2_container_count to a "membercount" field for
  ast_data queue query results. This patch also would fix AST-676, but as it is
  slightly riskier than the previously committed fix, the two commits have been
  made separately.
  
  Reivew: https://reviewboard.asterisk.org/r/1541/
  ........
  
  Merged revisions 342383 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
  r342436 | twilson | 2011-10-25 23:10:02 +0200 (Tue, 25 Oct 2011) | 7 lines
  
  Use int for storing ao2_container_count instad of size_t
  
  AST-676
  ........
  
  Merged revisions 342435 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
  r342485 | rmudgett | 2011-10-25 23:50:21 +0200 (Tue, 25 Oct 2011) | 15 lines
  
  Change D-channel warning to be less confusing on non-NFAS setups.
  
  The "No D-channels available!  Using Primary channel as D-channel anyway!"
  WARNING message has been confusing on non-NFAS setups.  The message refers
  to things that are NFAS specific.
  
  * Changed the warning to several different warnings to be more accurate
  for the situation and less confusing as a result:
  "No D-channels up!  Switching selected D-channel from X to Y.",
  "No D-channels up!", and
  "D-channel is down!".
  ........
  
  Merged revisions 342484 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
  r342488 | rmudgett | 2011-10-26 00:05:46 +0200 (Wed, 26 Oct 2011) | 10 lines
  
  Check fopen return value for ao2 reference debug output.
  
  Reported by: wdoekes
  Patched by: wdoekes
  
  Review: https://reviewboard.asterisk.org/r/1539/
  ........
  
  Merged revisions 342487 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 342381,342384,342436,342485,342488 from http://svn.asterisk.org/svn/asterisk/branches/10

Modified:
    team/irroot/distrotech-customers-10/   (props changed)
    team/irroot/distrotech-customers-10/apps/app_queue.c
    team/irroot/distrotech-customers-10/channels/sig_pri.c
    team/irroot/distrotech-customers-10/main/astobj2.c

Propchange: team/irroot/distrotech-customers-10/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.

Propchange: team/irroot/distrotech-customers-10/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Wed Oct 26 00:37:07 2011
@@ -1,1 +1,1 @@
-/branches/10:1-342340
+/branches/10:1-342536

Modified: team/irroot/distrotech-customers-10/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-10/apps/app_queue.c?view=diff&rev=342537&r1=342536&r2=342537
==============================================================================
--- team/irroot/distrotech-customers-10/apps/app_queue.c (original)
+++ team/irroot/distrotech-customers-10/apps/app_queue.c Wed Oct 26 00:37:07 2011
@@ -1195,12 +1195,6 @@
 	int autofill;                       /*!< Ignore the head call status and ring an available agent */
 	
 	struct ao2_container *members;             /*!< Head of the list of members */
-	/*! 
-	 * \brief Number of members _logged in_
-	 * \note There will be members in the members container that are not logged
-	 *       in, so this can not simply be replaced with ao2_container_count(). 
-	 */
-	int membercount;
 	struct queue_ent *head;             /*!< Head of the list of callers */
 	AST_LIST_ENTRY(call_queue) list;    /*!< Next call queue */
 	AST_LIST_HEAD_NOLOCK(, penalty_rule) rules; /*!< The list of penalty rules to invoke */
@@ -2242,8 +2236,6 @@
 		}
 		ao2_link(q->members, m);
 		ao2_ref(m, -1);
-		m = NULL;
-		q->membercount++;
 	}
 }
 
@@ -2257,7 +2249,6 @@
 	while ((cur = ao2_iterator_next(&mem_iter))) {
 		if (all || !cur->dynamic) {
 			ao2_unlink(q->members, cur);
-			q->membercount--;
 		}
 		ao2_ref(cur, -1);
 	}
@@ -2359,7 +2350,6 @@
 		ao2_lock(q);
 		clear_queue(q);
 		q->realtime = 1;
-		q->membercount = 0;
 		/*Before we initialize the queue, we need to set the strategy, so that linear strategy
 		 * will allocate the members properly
 		 */
@@ -2400,11 +2390,9 @@
 		queue_set_param(q, tmp_name, v->value, -1, 0);
 	}
 
-	/* Temporarily set realtime members dead so we can detect deleted ones.
-	 * Also set the membercount correctly for realtime*/
+	/* Temporarily set realtime members dead so we can detect deleted ones. */
 	mem_iter = ao2_iterator_init(q->members, 0);
 	while ((m = ao2_iterator_next(&mem_iter))) {
-		q->membercount++;
 		if (m->realtime) {
 			m->dead = 1;
 		}
@@ -2426,7 +2414,6 @@
 				ast_queue_log(q->name, "REALTIME", m->membername, "REMOVEMEMBER", "%s", "");
 			}
 			ao2_unlink(q->members, m);
-			q->membercount--;
 		}
 		ao2_ref(m, -1);
 	}
@@ -2544,7 +2531,6 @@
 				ast_queue_log(q->name, "REALTIME", m->membername, "REMOVEMEMBER", "%s", "");
 			}
 			ao2_unlink(q->members, m);
-			q->membercount--;
 		}
 		ao2_ref(m, -1);
 	}
@@ -4201,7 +4187,8 @@
 static int calc_metric(struct call_queue *q, struct member *mem, int pos, struct queue_ent *qe, struct callattempt *tmp)
 {
 	/* disregarding penalty on too few members? */
-	unsigned char usepenalty = (q->membercount <= q->penaltymemberslimit) ? 0 : 1;
+	int membercount = ao2_container_count(q->members);
+	unsigned char usepenalty = (membercount <= q->penaltymemberslimit) ? 0 : 1;
 
 	if (usepenalty) {
 		if ((qe->max_penalty && (mem->penalty > qe->max_penalty)) ||
@@ -4210,7 +4197,7 @@
 		}
 	} else {
 		ast_debug(1, "Disregarding penalty, %d members and %d in penaltymemberslimit.\n",
-			  q->membercount, q->penaltymemberslimit);
+			  membercount, q->penaltymemberslimit);
 	}
 
 	switch (q->strategy) {
@@ -4553,7 +4540,7 @@
 			if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY || qe->parent->strategy == QUEUE_STRATEGY_LINEAR || qe->parent->strategy == QUEUE_STRATEGY_RRORDERED)
 				(*tries)++;
 			else
-				*tries = qe->parent->membercount;
+				*tries = ao2_container_count(qe->parent->members);
 			*noption = 1;
 			break;
 		case 'i':
@@ -5338,7 +5325,6 @@
 				queue_t_unref(q, "Interface wasn't dynamic, expiring temporary reference");
 				return RES_NOT_DYNAMIC;
 			}
-			q->membercount--;
 			manager_event(EVENT_FLAG_AGENT, "QueueMemberRemoved",
 				"Queue: %s\r\n"
 				"Location: %s\r\n"
@@ -5385,7 +5371,6 @@
 		if ((new_member = create_queue_member(interface, membername, penalty, paused, state_interface))) {
 			new_member->dynamic = 1;
 			ao2_link(q->members, new_member);
-			q->membercount++;
 			ao2_lock(new_member->device);
 			manager_event(EVENT_FLAG_AGENT, "QueueMemberAdded",
 				"Queue: %s\r\n"
@@ -6161,7 +6146,7 @@
 		}
 
 		/* exit after 'timeout' cycle if 'n' option enabled */
-		if (noption && tries >= qe.parent->membercount) {
+		if (noption && tries >= ao2_container_count(qe.parent->members)) {
 			ast_verb(3, "Exiting on time-out cycle\n");
 			ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
 			record_abandoned(&qe);
@@ -6382,7 +6367,7 @@
 			}
 			ao2_iterator_destroy(&mem_iter);
 		} else if (!strcasecmp(args.option, "count") || ast_strlen_zero(args.option)) {
-			count = q->membercount;
+			count = ao2_container_count(q->members);
 		} else if (!strcasecmp(args.option, "penalty") && !ast_strlen_zero(args.interface) &&
 			   ((m = interface_exists(q, args.interface)))) {
 			count = m->penalty;
@@ -6876,8 +6861,6 @@
 
 	if (cur) {
 		ao2_ref(cur, -1);
-	} else {
-		q->membercount++;
 	}
 }
 
@@ -6893,18 +6876,10 @@
 static int kill_dead_members(void *obj, void *arg, int flags)
 {
 	struct member *member = obj;
-	struct call_queue *q = arg;
 
 	if (!member->delme) {
-		if (member->dynamic) {
-			/* dynamic members were not counted toward the member count
-			 * when reloading members from queues.conf, so we do that here
-			 */
-			q->membercount++;
-		}
 		return 0;
 	} else {
-		q->membercount--;
 		return CMP_MATCH;
 	}
 }
@@ -6980,7 +6955,6 @@
 		init_queue(q);
 	}
 	if (member_reload) {
-		q->membercount = 0;
 		ao2_callback(q->members, OBJ_NODATA, mark_member_dead, NULL);
 	}
 	for (var = ast_variable_browse(cfg, queuename); var; var = var->next) {
@@ -8378,8 +8352,7 @@
 	MEMBER(call_queue, rrpos, AST_DATA_INTEGER)			\
 	MEMBER(call_queue, memberdelay, AST_DATA_INTEGER)		\
 	MEMBER(call_queue, autofill, AST_DATA_INTEGER)			\
-	MEMBER(call_queue, members, AST_DATA_CONTAINER)			\
-	MEMBER(call_queue, membercount, AST_DATA_INTEGER)
+	MEMBER(call_queue, members, AST_DATA_CONTAINER)
 
 AST_DATA_STRUCTURE(call_queue, DATA_EXPORT_CALL_QUEUE);
 
@@ -8445,6 +8418,7 @@
 	ast_data_add_structure(call_queue, data_queue, queue);
 
 	ast_data_add_str(data_queue, "strategy", int2strat(queue->strategy));
+	ast_data_add_int(data_queue, "membercount", ao2_container_count(queue->members));
 
 	/* announce position */
 	enum_node = ast_data_add_node(data_queue, "announceposition");

Modified: team/irroot/distrotech-customers-10/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-10/channels/sig_pri.c?view=diff&rev=342537&r1=342536&r2=342537
==============================================================================
--- team/irroot/distrotech-customers-10/channels/sig_pri.c (original)
+++ team/irroot/distrotech-customers-10/channels/sig_pri.c Wed Oct 26 00:37:07 2011
@@ -1012,7 +1012,7 @@
 	return 0;
 }
 
-static char *pri_order(int level)
+static const char *pri_order(int level)
 {
 	switch (level) {
 	case 0:
@@ -1042,37 +1042,74 @@
 	return -1;
 }
 
-static int pri_find_dchan(struct sig_pri_span *pri)
-{
+static void pri_find_dchan(struct sig_pri_span *pri)
+{
+	struct pri *old;
 	int oldslot = -1;
-	struct pri *old;
 	int newslot = -1;
-	int x;
+	int idx;
+
 	old = pri->pri;
-	for (x = 0; x < SIG_PRI_NUM_DCHANS; x++) {
-		if ((pri->dchanavail[x] == DCHAN_AVAILABLE) && (newslot < 0))
-			newslot = x;
-		if (pri->dchans[x] == old) {
-			oldslot = x;
-		}
-	}
-	if (newslot < 0) {
-		newslot = 0;
-		/* This is annoying to see on non persistent layer 2 connections.  Let's not complain in that case */
-		if (pri->sig != SIG_BRI_PTMP && !pri->no_d_channels) {
-			pri->no_d_channels = 1;
-			ast_log(LOG_WARNING,
-				"Span %d: No D-channels available!  Using Primary channel as D-channel anyway!\n",
-				pri->span);
+	for (idx = 0; idx < SIG_PRI_NUM_DCHANS; ++idx) {
+		if (!pri->dchans[idx]) {
+			/* No more D channels defined on the span. */
+			break;
+		}
+		if (pri->dchans[idx] == old) {
+			oldslot = idx;
+		}
+		if (newslot < 0 && pri->dchanavail[idx] == DCHAN_AVAILABLE) {
+			newslot = idx;
+		}
+	}
+	/* At this point, idx is a count of how many D-channels are defined on the span. */
+
+	if (1 < idx) {
+		/* We have several D-channels defined on the span.  (NFAS PRI setup) */
+		if (newslot < 0) {
+			/* No D-channels available.  Default to the primary D-channel. */
+			newslot = 0;
+
+			if (!pri->no_d_channels) {
+				pri->no_d_channels = 1;
+				if (old && oldslot != newslot) {
+					ast_log(LOG_WARNING,
+						"Span %d: No D-channels up!  Switching selected D-channel from %s to %s.\n",
+						pri->span, pri_order(oldslot), pri_order(newslot));
+				} else {
+					ast_log(LOG_WARNING, "Span %d: No D-channels up!\n", pri->span);
+				}
+			}
+		} else {
+			pri->no_d_channels = 0;
+		}
+		if (old && oldslot != newslot) {
+			ast_log(LOG_NOTICE,
+				"Switching selected D-channel from %s (fd %d) to %s (fd %d)!\n",
+				pri_order(oldslot), pri->fds[oldslot],
+				pri_order(newslot), pri->fds[newslot]);
 		}
 	} else {
-		pri->no_d_channels = 0;
-	}
-	if (old && (oldslot != newslot))
-		ast_log(LOG_NOTICE, "Switching from d-channel fd %d to fd %d!\n",
-			pri->fds[oldslot], pri->fds[newslot]);
+		if (newslot < 0) {
+			/* The only D-channel is not up. */
+			newslot = 0;
+
+			if (!pri->no_d_channels) {
+				pri->no_d_channels = 1;
+
+				/*
+				 * This is annoying to see on non-persistent layer 2
+				 * connections.  Let's not complain in that case.
+				 */
+				if (pri->sig != SIG_BRI_PTMP) {
+					ast_log(LOG_WARNING, "Span %d: D-channel is down!\n", pri->span);
+				}
+			}
+		} else {
+			pri->no_d_channels = 0;
+		}
+	}
 	pri->pri = pri->dchans[newslot];
-	return 0;
 }
 
 /*!
@@ -1936,8 +1973,9 @@
 void pri_event_alarm(struct sig_pri_span *pri, int index, int before_start_pri)
 {
 	pri->dchanavail[index] &= ~(DCHAN_NOTINALARM | DCHAN_UP);
-	if (!before_start_pri)
+	if (!before_start_pri) {
 		pri_find_dchan(pri);
+	}
 }
 
 void pri_event_noalarm(struct sig_pri_span *pri, int index, int before_start_pri)
@@ -5601,7 +5639,9 @@
 			switch (e->e) {
 			case PRI_EVENT_DCHAN_UP:
 				pri->no_d_channels = 0;
-				if (!pri->pri) pri_find_dchan(pri);
+				if (!pri->pri) {
+					pri_find_dchan(pri);
+				}
 
 				/* Note presense of D-channel */
 				time(&pri->lastreset);
@@ -5624,8 +5664,10 @@
 				pri_find_dchan(pri);
 				if (!pri_is_up(pri)) {
 					if (pri->sig == SIG_BRI_PTMP) {
-						/* For PTMP connections with non persistent layer 2 we want
-						 * to *not* declare inalarm unless there actually is an alarm */
+						/*
+						 * For PTMP connections with non-persistent layer 2 we want to
+						 * *not* declare inalarm unless there actually is an alarm.
+						 */
 						break;
 					}
 					/* Hangup active channels and put them in alarm mode */

Modified: team/irroot/distrotech-customers-10/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-10/main/astobj2.c?view=diff&rev=342537&r1=342536&r2=342537
==============================================================================
--- team/irroot/distrotech-customers-10/main/astobj2.c (original)
+++ team/irroot/distrotech-customers-10/main/astobj2.c Wed Oct 26 00:37:07 2011
@@ -210,14 +210,19 @@
 		return -1;
 
 	if (delta != 0) {
-		FILE *refo = fopen(REF_FILE,"a");
-		fprintf(refo, "%p %s%d   %s:%d:%s (%s) [@%d]\n", user_data, (delta<0? "":"+"), delta, file, line, funcname, tag, obj ? obj->priv_data.ref_counter : -1);
-		fclose(refo);
+		FILE *refo = fopen(REF_FILE, "a");
+		if (refo) {
+			fprintf(refo, "%p %s%d   %s:%d:%s (%s) [@%d]\n", user_data, (delta < 0 ? "" : "+"),
+				delta, file, line, funcname, tag, obj ? obj->priv_data.ref_counter : -1);
+			fclose(refo);
+		}
 	}
 	if (obj->priv_data.ref_counter + delta == 0 && obj->priv_data.destructor_fn != NULL) { /* this isn't protected with lock; just for o/p */
-			FILE *refo = fopen(REF_FILE,"a"); 	 
-			fprintf(refo, "%p **call destructor** %s:%d:%s (%s)\n", user_data, file, line, funcname, tag); 	 
+		FILE *refo = fopen(REF_FILE, "a");
+		if (refo) {
+			fprintf(refo, "%p **call destructor** %s:%d:%s (%s)\n", user_data, file, line, funcname, tag);
 			fclose(refo);
+		}
 	}
 	return internal_ao2_ref(user_data, delta);
 }
@@ -319,14 +324,13 @@
 {
 	/* allocation */
 	void *obj;
-	FILE *refo = ref_debug ? fopen(REF_FILE,"a") : NULL;
+	FILE *refo;
 
 	if ((obj = internal_ao2_alloc(data_size, destructor_fn, file, line, funcname)) == NULL) {
-		fclose(refo);
-		return NULL;
-	}
-
-	if (refo) {
+		return NULL;
+	}
+
+	if (ref_debug && (refo = fopen(REF_FILE, "a"))) {
 		fprintf(refo, "%p =1   %s:%d:%s (%s)\n", obj, file, line, funcname, tag);
 		fclose(refo);
 	}




More information about the svn-commits mailing list