[Asterisk-code-review] stasis: Add function to delete topic from pool (asterisk[13])

George Joseph asteriskteam at digium.com
Mon Sep 24 09:27:46 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/10208 )

Change subject: stasis:  Add function to delete topic from pool
......................................................................

stasis:  Add function to delete topic from pool

There's been a long standing leak when using topic pools.  The
topics in the pool get cleaned up when the last pool reference is
released but you can't remove a topic specifically.  If you reloaded
app_voicemail for instance, and mailboxes went away, their topics
were left in the pool.

* Added stasis_topic_pool_delete_topic() so modules can clean up
  topics from pools.
* Registered the topic pool containers so it can be examined from
  the CLI when AO2_DEBUG is enabled.  They'll be named
  "<topic_pool_name>-pool".

Change-Id: Ib7957951ee5c9b9b4482af7b9b4349112d62bc25
---
M include/asterisk/stasis.h
M main/stasis.c
2 files changed, 48 insertions(+), 0 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  George Joseph: Approved for Submit



diff --git a/include/asterisk/stasis.h b/include/asterisk/stasis.h
index 28c5282..f1a09f7 100644
--- a/include/asterisk/stasis.h
+++ b/include/asterisk/stasis.h
@@ -765,6 +765,18 @@
 struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name);
 
 /*!
+ * \brief Delete a topic from the topic pool
+ *
+ * \param pool Pool from which to delete the topic
+ * \param topic_name Name of the topic to delete
+ *
+ * \since 13.24
+ * \since 15.6
+ * \since 16.1
+ */
+void stasis_topic_pool_delete_topic(struct stasis_topic_pool *pool, const char *topic_name);
+
+/*!
  * \brief Check if a topic exists in a pool
  * \param pool Pool to check
  * \param topic_name Name of the topic to check
diff --git a/main/stasis.c b/main/stasis.c
index 20f865e..bfaf4fb 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -1081,6 +1081,15 @@
 {
 	struct stasis_topic_pool *pool = obj;
 
+#ifdef AO2_DEBUG
+	{
+		char *container_name =
+			ast_alloca(strlen(stasis_topic_name(pool->pool_topic)) + strlen("-pool") + 1);
+		sprintf(container_name, "%s-pool", stasis_topic_name(pool->pool_topic));
+		ao2_container_unregister(container_name);
+	}
+#endif
+
 	ao2_cleanup(pool->pool_container);
 	pool->pool_container = NULL;
 	ao2_cleanup(pool->pool_topic);
@@ -1145,6 +1154,18 @@
 	return CMP_MATCH;
 }
 
+#ifdef AO2_DEBUG
+static void topic_pool_prnt_obj(void *v_obj, void *where, ao2_prnt_fn *prnt)
+{
+	struct topic_pool_entry *entry = v_obj;
+
+	if (!entry) {
+		return;
+	}
+	prnt(where, "%s", stasis_topic_name(entry->topic));
+}
+#endif
+
 struct stasis_topic_pool *stasis_topic_pool_create(struct stasis_topic *pooled_topic)
 {
 	struct stasis_topic_pool *pool;
@@ -1160,12 +1181,27 @@
 		ao2_cleanup(pool);
 		return NULL;
 	}
+
+#ifdef AO2_DEBUG
+	{
+		char *container_name =
+			ast_alloca(strlen(stasis_topic_name(pooled_topic)) + strlen("-pool") + 1);
+		sprintf(container_name, "%s-pool", stasis_topic_name(pooled_topic));
+		ao2_container_register(container_name, pool->pool_container, topic_pool_prnt_obj);
+	}
+#endif
+
 	ao2_ref(pooled_topic, +1);
 	pool->pool_topic = pooled_topic;
 
 	return pool;
 }
 
+void stasis_topic_pool_delete_topic(struct stasis_topic_pool *pool, const char *topic_name)
+{
+	ao2_find(pool->pool_container, topic_name, OBJ_SEARCH_KEY | OBJ_NODATA | OBJ_UNLINK);
+}
+
 struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name)
 {
 	RAII_VAR(struct topic_pool_entry *, topic_pool_entry, NULL, ao2_cleanup);

-- 
To view, visit https://gerrit.asterisk.org/10208
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib7957951ee5c9b9b4482af7b9b4349112d62bc25
Gerrit-Change-Number: 10208
Gerrit-PatchSet: 2
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2 (1000185)
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180924/45b46d31/attachment-0001.html>


More information about the asterisk-code-review mailing list