X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbin%2Flttng-sessiond%2Fagent.c;h=7349d09f0e7edd9dbfad5e082e89a0825f440a26;hb=a433283e401f556b0eb87814475fc84b11fc9666;hp=1eb64c25e32b937282bd5f1b45c7442d3909b188;hpb=d558f2363a2daf3e456a28a6089f7464837ed542;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/agent.c b/src/bin/lttng-sessiond/agent.c index 1eb64c25e..7349d09f0 100644 --- a/src/bin/lttng-sessiond/agent.c +++ b/src/bin/lttng-sessiond/agent.c @@ -698,7 +698,7 @@ void agent_delete_app(struct agent_app *app) } /* - * Destroy a agent application object by detaching it from its corresponding + * Destroy an agent application object by detaching it from its corresponding * UST app if one is connected by closing the socket. Finally, perform a * delayed memory reclaim. */ @@ -961,16 +961,67 @@ void agent_destroy(struct agent *agt) } /* - * Initialize agent subsystem. + * Allocate agent_apps_ht_by_sock. */ -int agent_setup(void) +int agent_app_ht_alloc(void) { + int ret = 0; + agent_apps_ht_by_sock = lttng_ht_new(0, LTTNG_HT_TYPE_ULONG); if (!agent_apps_ht_by_sock) { - return -1; + ret = -1; } - return 0; + return ret; +} + +/* + * Destroy a agent application by socket. + */ +void agent_destroy_app_by_sock(int sock) +{ + struct agent_app *app; + + assert(sock >= 0); + + /* + * Not finding an application is a very important error that should NEVER + * happen. The hash table deletion is ONLY done through this call when the + * main sessiond thread is torn down. + */ + rcu_read_lock(); + app = agent_find_app_by_sock(sock); + assert(app); + + /* RCU read side lock is assumed to be held by this function. */ + agent_delete_app(app); + + /* The application is freed in a RCU call but the socket is closed here. */ + agent_destroy_app(app); + rcu_read_unlock(); +} + +/* + * Clean-up the agent app hash table and destroy it. + */ +void agent_app_ht_clean(void) +{ + struct lttng_ht_node_ulong *node; + struct lttng_ht_iter iter; + + if (!agent_apps_ht_by_sock) { + return; + } + rcu_read_lock(); + cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, node, node) { + struct agent_app *app; + + app = caa_container_of(node, struct agent_app, node); + agent_destroy_app_by_sock(app->sock->fd); + } + rcu_read_unlock(); + + lttng_ht_destroy(agent_apps_ht_by_sock); } /*