[asterisk-commits] mjordan: trunk r402082 - in /trunk: ./ addons/ cdr/ include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Oct 27 15:04:19 CDT 2013


Author: mjordan
Date: Sun Oct 27 15:04:17 2013
New Revision: 402082

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=402082
Log:
Prevent CDR backends from unregistering while billing data is in flight

This patch makes it so that CDR backends cannot be unregistered while active
CDR records exist. This helps to prevent billing data from being lost during
restarts and shutdowns.

Review: https://reviewboard.asterisk.org/r/2880/
........

Merged revisions 402081 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/addons/cdr_mysql.c
    trunk/cdr/cdr_adaptive_odbc.c
    trunk/cdr/cdr_csv.c
    trunk/cdr/cdr_custom.c
    trunk/cdr/cdr_manager.c
    trunk/cdr/cdr_odbc.c
    trunk/cdr/cdr_pgsql.c
    trunk/cdr/cdr_radius.c
    trunk/cdr/cdr_sqlite.c
    trunk/cdr/cdr_sqlite3_custom.c
    trunk/cdr/cdr_syslog.c
    trunk/cdr/cdr_tds.c
    trunk/include/asterisk/cdr.h
    trunk/main/cdr.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/addons/cdr_mysql.c
URL: http://svnview.digium.com/svn/asterisk/trunk/addons/cdr_mysql.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/addons/cdr_mysql.c (original)
+++ trunk/addons/cdr_mysql.c Sun Oct 27 15:04:17 2013
@@ -384,9 +384,11 @@
 	}
 
 	dbport = 0;
-	ast_cdr_unregister(name);
-	
-	return 0;
+	if (reload) {
+		return ast_cdr_backend_suspend(name);
+	} else {
+		return ast_cdr_unregister(name);
+	}
 }
 
 static int my_load_config_string(struct ast_config *cfg, const char *category, const char *variable, struct ast_str **field, const char *def)
@@ -660,7 +662,11 @@
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
-	res = ast_cdr_register(name, desc, mysql_log);
+	if (!reload) {
+		res = ast_cdr_register(name, desc, mysql_log);
+	} else {
+		res = ast_cdr_backend_unsuspend(name);
+	}
 	if (res) {
 		ast_log(LOG_ERROR, "Unable to register MySQL CDR handling\n");
 	} else {

Modified: trunk/cdr/cdr_adaptive_odbc.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_adaptive_odbc.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_adaptive_odbc.c (original)
+++ trunk/cdr/cdr_adaptive_odbc.c Sun Oct 27 15:04:17 2013
@@ -767,7 +767,10 @@
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
+
 	if (AST_RWLIST_WRLOCK(&odbc_tables)) {
 		ast_cdr_register(name, ast_module_info->description, odbc_log);
 		ast_log(LOG_ERROR, "Unable to lock column list.  Unload failed.\n");

Modified: trunk/cdr/cdr_csv.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_csv.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_csv.c (original)
+++ trunk/cdr/cdr_csv.c Sun Oct 27 15:04:17 2013
@@ -315,7 +315,10 @@
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
+
 	loaded = 0;
 	return 0;
 }

Modified: trunk/cdr/cdr_custom.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_custom.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_custom.c (original)
+++ trunk/cdr/cdr_custom.c Sun Oct 27 15:04:17 2013
@@ -184,7 +184,9 @@
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
 
 	if (AST_RWLIST_WRLOCK(&sinks)) {
 		ast_cdr_register(name, ast_module_info->description, custom_log);

Modified: trunk/cdr/cdr_manager.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_manager.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_manager.c (original)
+++ trunk/cdr/cdr_manager.c Sun Oct 27 15:04:17 2013
@@ -86,8 +86,9 @@
 	if (!cfg) {
 		/* Standard configuration */
 		ast_log(LOG_WARNING, "Failed to load configuration file. Module not activated.\n");
-		if (enablecdr)
-			ast_cdr_unregister(name);
+		if (enablecdr) {
+			ast_cdr_backend_suspend(name);
+		}
 		enablecdr = 0;
 		return -1;
 	}
@@ -135,10 +136,11 @@
 
 	ast_config_destroy(cfg);
 
-	if (enablecdr && !newenablecdr)
-		ast_cdr_unregister(name);
-	else if (!enablecdr && newenablecdr)
-		ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log);
+	if (!newenablecdr) {
+		ast_cdr_backend_suspend(name);
+	} else if (newenablecdr) {
+		ast_cdr_backend_unsuspend(name);
+	}
 	enablecdr = newenablecdr;
 
 	return 0;
@@ -210,7 +212,10 @@
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
+
 	if (customfields)
 		ast_free(customfields);
 
@@ -219,7 +224,12 @@
 
 static int load_module(void)
 {
+	if (ast_cdr_register(name, "Asterisk Manager Interface CDR Backend", manager_log)) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
 	if (load_config(0)) {
+		ast_cdr_unregister(name);
 		return AST_MODULE_LOAD_DECLINE;
 	}
 

Modified: trunk/cdr/cdr_odbc.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_odbc.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_odbc.c (original)
+++ trunk/cdr/cdr_odbc.c Sun Oct 27 15:04:17 2013
@@ -266,8 +266,10 @@
 	} while (0);
 
 	if (ast_test_flag(&config, CONFIG_REGISTERED) && (!cfg || dsn == NULL || table == NULL)) {
-		ast_cdr_unregister(name);
+		ast_cdr_backend_suspend(name);
 		ast_clear_flag(&config, CONFIG_REGISTERED);
+	} else {
+		ast_cdr_backend_unsuspend(name);
 	}
 
 	if (cfg && cfg != CONFIG_STATUS_FILEUNCHANGED && cfg != CONFIG_STATUS_FILEINVALID) {
@@ -283,7 +285,9 @@
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
 
 	if (dsn) {
 		ast_verb(11, "cdr_odbc: free dsn\n");

Modified: trunk/cdr/cdr_pgsql.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_pgsql.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_pgsql.c (original)
+++ trunk/cdr/cdr_pgsql.c Sun Oct 27 15:04:17 2013
@@ -436,7 +436,10 @@
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
+
 	ast_cli_unregister_multiple(cdr_pgsql_status_cli, ARRAY_LEN(cdr_pgsql_status_cli));
 
 	PQfinish(conn);

Modified: trunk/cdr/cdr_radius.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_radius.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_radius.c (original)
+++ trunk/cdr/cdr_radius.c Sun Oct 27 15:04:17 2013
@@ -230,7 +230,10 @@
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
+
 	if (rh) {
 		rc_destroy(rh);
 		rh = NULL;

Modified: trunk/cdr/cdr_sqlite.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_sqlite.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_sqlite.c (original)
+++ trunk/cdr/cdr_sqlite.c Sun Oct 27 15:04:17 2013
@@ -191,7 +191,10 @@
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
+
 	if (db) {
 		sqlite_close(db);
 	}

Modified: trunk/cdr/cdr_sqlite3_custom.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_sqlite3_custom.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_sqlite3_custom.c (original)
+++ trunk/cdr/cdr_sqlite3_custom.c Sun Oct 27 15:04:17 2013
@@ -289,7 +289,9 @@
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
 
 	free_config(0);
 

Modified: trunk/cdr/cdr_syslog.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_syslog.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_syslog.c (original)
+++ trunk/cdr/cdr_syslog.c Sun Oct 27 15:04:17 2013
@@ -235,7 +235,9 @@
 
 static int unload_module(void)
 {
-	ast_cdr_unregister(name);
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
 
 	if (AST_RWLIST_WRLOCK(&sinks)) {
 		ast_cdr_register(name, ast_module_info->description, syslog_log);

Modified: trunk/cdr/cdr_tds.c
URL: http://svnview.digium.com/svn/asterisk/trunk/cdr/cdr_tds.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/cdr/cdr_tds.c (original)
+++ trunk/cdr/cdr_tds.c Sun Oct 27 15:04:17 2013
@@ -443,6 +443,10 @@
 
 static int tds_unload_module(void)
 {
+	if (ast_cdr_unregister(name)) {
+		return -1;
+	}
+
 	if (settings) {
 		ast_mutex_lock(&tds_lock);
 		mssql_disconnect();
@@ -451,8 +455,6 @@
 		ast_string_field_free_memory(settings);
 		ast_free(settings);
 	}
-
-	ast_cdr_unregister(name);
 
 	dbexit();
 

Modified: trunk/include/asterisk/cdr.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/cdr.h?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/include/asterisk/cdr.h (original)
+++ trunk/include/asterisk/cdr.h Sun Oct 27 15:04:17 2013
@@ -503,8 +503,27 @@
  * \brief Unregister a CDR handling engine
  * \param name name of CDR handler to unregister
  * Unregisters a CDR by it's name
- */
-void ast_cdr_unregister(const char *name);
+ *
+ * \retval 0 The backend unregistered successfully
+ * \retval -1 The backend could not be unregistered at this time
+ */
+int ast_cdr_unregister(const char *name);
+
+/*!
+ * \brief Suspend a CDR backend temporarily
+ *
+  * \retval 0 The backend is suspdended
+  * \retval -1 The backend could not be suspended
+  */
+int ast_cdr_backend_suspend(const char *name);
+
+/*!
+ * \brief Unsuspend a CDR backend
+ *
+ * \retval 0 The backend was unsuspended
+ * \retval -1 The back could not be unsuspended
+ */
+int ast_cdr_backend_unsuspend(const char *name);
 
 /*!
  * \brief Disposition to a string

Modified: trunk/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/cdr.c?view=diff&rev=402082&r1=402081&r2=402082
==============================================================================
--- trunk/main/cdr.c (original)
+++ trunk/main/cdr.c Sun Oct 27 15:04:17 2013
@@ -294,6 +294,7 @@
 	char desc[80];
 	ast_cdrbe be;
 	AST_RWLIST_ENTRY(cdr_beitem) list;
+	int suspended:1;
 };
 
 /*! \brief List of registered backends */
@@ -2581,6 +2582,42 @@
 	return ast_test_flag(&mod_cfg->general->settings, CDR_ENABLED);
 }
 
+int ast_cdr_backend_suspend(const char *name)
+{
+	int success = -1;
+	struct cdr_beitem *i = NULL;
+
+	AST_RWLIST_WRLOCK(&be_list);
+	AST_RWLIST_TRAVERSE(&be_list, i, list) {
+		if (!strcasecmp(name, i->name)) {
+			ast_debug(3, "Suspending CDR backend %s\n", i->name);
+			i->suspended = 1;
+			success = 0;
+		}
+	}
+	AST_RWLIST_UNLOCK(&be_list);
+
+	return success;
+}
+
+int ast_cdr_backend_unsuspend(const char *name)
+{
+	int success = -1;
+	struct cdr_beitem *i = NULL;
+
+	AST_RWLIST_WRLOCK(&be_list);
+	AST_RWLIST_TRAVERSE(&be_list, i, list) {
+		if (!strcasecmp(name, i->name)) {
+			ast_debug(3, "Unsuspending CDR backend %s\n", i->name);
+			i->suspended = 0;
+			success = 0;
+		}
+	}
+	AST_RWLIST_UNLOCK(&be_list);
+
+	return success;
+}
+
 int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
 {
 	struct cdr_beitem *i = NULL;
@@ -2615,24 +2652,39 @@
 	return 0;
 }
 
-void ast_cdr_unregister(const char *name)
-{
-	struct cdr_beitem *i = NULL;
+int ast_cdr_unregister(const char *name)
+{
+	struct cdr_beitem *match = NULL;
+	int active_count;
 
 	AST_RWLIST_WRLOCK(&be_list);
-	AST_RWLIST_TRAVERSE_SAFE_BEGIN(&be_list, i, list) {
-		if (!strcasecmp(name, i->name)) {
-			AST_RWLIST_REMOVE_CURRENT(list);
+	AST_RWLIST_TRAVERSE(&be_list, match, list) {
+		if (!strcasecmp(name, match->name)) {
 			break;
 		}
 	}
-	AST_RWLIST_TRAVERSE_SAFE_END;
+
+	if (!match) {
+		AST_RWLIST_UNLOCK(&be_list);
+		return 0;
+	}
+
+	active_count = ao2_container_count(active_cdrs_by_channel);
+
+	if (!match->suspended && active_count != 0) {
+		AST_RWLIST_UNLOCK(&be_list);
+		ast_log(AST_LOG_WARNING, "Unable to unregister CDR backend %s; %d CDRs are still active\n",
+			name, active_count);
+		return -1;
+	}
+
+	AST_RWLIST_REMOVE(&be_list, match, list);
 	AST_RWLIST_UNLOCK(&be_list);
 
-	if (i) {
-		ast_verb(2, "Unregistered '%s' CDR backend\n", name);
-		ast_free(i);
-	}
+	ast_verb(2, "Unregistered '%s' CDR backend\n", name);
+	ast_free(match);
+
+	return 0;
 }
 
 struct ast_cdr *ast_cdr_dup(struct ast_cdr *cdr)
@@ -3159,7 +3211,9 @@
 		}
 		AST_RWLIST_RDLOCK(&be_list);
 		AST_RWLIST_TRAVERSE(&be_list, i, list) {
-			i->be(cdr);
+			if (!i->suspended) {
+				i->be(cdr);
+			}
 		}
 		AST_RWLIST_UNLOCK(&be_list);
 	}
@@ -3772,7 +3826,7 @@
 			ast_cli(a->fd, "    (none)\n");
 		} else {
 			AST_RWLIST_TRAVERSE(&be_list, beitem, list) {
-				ast_cli(a->fd, "    %s\n", beitem->name);
+				ast_cli(a->fd, "    %s%s\n", beitem->name, beitem->suspended ? " (suspended) " : "");
 			}
 		}
 		AST_RWLIST_UNLOCK(&be_list);




More information about the asterisk-commits mailing list