#include <common/common.hpp>
#include <common/compat/endian.hpp>
#include <common/sessiond-comm/agent.hpp>
+#include <common/urcu.hpp>
#include <lttng/condition/condition.h>
#include <lttng/condition/event-rule-matches.h>
#include <lttng/event-rule/event-rule.h>
#include <lttng/event-rule/jul-logging.h>
#include <lttng/event-rule/log4j-logging.h>
+#include <lttng/event-rule/log4j2-logging.h>
#include <lttng/event-rule/python-logging.h>
#include <lttng/log-level-rule-internal.hpp>
*/
static int ht_match_event_by_name(struct cds_lfht_node *node, const void *_key)
{
- struct agent_event *event;
- const struct agent_ht_key *key;
-
LTTNG_ASSERT(node);
LTTNG_ASSERT(_key);
- event = caa_container_of(node, struct agent_event, node.node);
- key = (agent_ht_key *) _key;
+ auto *event = lttng_ht_node_container_of(node, &agent_event::node);
+ const auto *key = static_cast<const agent_ht_key *>(_key);
/* Match 1 elements of the key: name. */
*/
static int ht_match_event(struct cds_lfht_node *node, const void *_key)
{
- struct agent_event *event;
- const struct agent_ht_key *key;
- int ll_match;
-
LTTNG_ASSERT(node);
LTTNG_ASSERT(_key);
- event = caa_container_of(node, struct agent_event, node.node);
- key = (agent_ht_key *) _key;
+ const auto *event = lttng_ht_node_container_of(node, &agent_event::node);
+ const auto *key = (agent_ht_key *) _key;
+ bool ll_match;
/* Match 2 elements of the key: name and loglevel. */
int agent_enable_event(struct agent_event *event, enum lttng_domain_type domain)
{
int ret;
- struct agent_app *app;
- struct lttng_ht_iter iter;
LTTNG_ASSERT(event);
- rcu_read_lock();
-
- cds_lfht_for_each_entry (the_agent_apps_ht_by_sock->ht, &iter.iter, app, node.node) {
+ for (auto *app : lttng::urcu::
+ lfht_iteration_adapter<agent_app, decltype(agent_app::node), &agent_app::node>(
+ *the_agent_apps_ht_by_sock->ht)) {
if (app->domain != domain) {
continue;
}
ret = LTTNG_OK;
error:
- rcu_read_unlock();
return ret;
}
int agent_enable_context(const struct lttng_event_context *ctx, enum lttng_domain_type domain)
{
int ret;
- struct agent_app *app;
- struct lttng_ht_iter iter;
LTTNG_ASSERT(ctx);
if (ctx->ctx != LTTNG_EVENT_CONTEXT_APP_CONTEXT) {
goto error;
}
- rcu_read_lock();
-
- cds_lfht_for_each_entry (the_agent_apps_ht_by_sock->ht, &iter.iter, app, node.node) {
+ for (auto *app : lttng::urcu::
+ lfht_iteration_adapter<agent_app, decltype(agent_app::node), &agent_app::node>(
+ *the_agent_apps_ht_by_sock->ht)) {
struct agent_app_ctx *agent_ctx;
if (app->domain != domain) {
ret = LTTNG_OK;
error_unlock:
- rcu_read_unlock();
error:
return ret;
}
int agent_disable_event(struct agent_event *event, enum lttng_domain_type domain)
{
int ret = LTTNG_OK;
- struct agent_app *app;
- struct lttng_ht_iter iter;
LTTNG_ASSERT(event);
if (!AGENT_EVENT_IS_ENABLED(event)) {
goto end;
}
- rcu_read_lock();
-
- cds_lfht_for_each_entry (the_agent_apps_ht_by_sock->ht, &iter.iter, app, node.node) {
+ for (auto *app : lttng::urcu::
+ lfht_iteration_adapter<agent_app, decltype(agent_app::node), &agent_app::node>(
+ *the_agent_apps_ht_by_sock->ht)) {
if (app->domain != domain) {
continue;
}
LTTNG_ASSERT(!AGENT_EVENT_IS_ENABLED(event));
error:
- rcu_read_unlock();
end:
return ret;
}
static int disable_context(struct agent_app_ctx *ctx, enum lttng_domain_type domain)
{
int ret = LTTNG_OK;
- struct agent_app *app;
- struct lttng_ht_iter iter;
LTTNG_ASSERT(ctx);
-
- rcu_read_lock();
DBG2("Disabling agent application context %s:%s", ctx->provider_name, ctx->ctx_name);
- cds_lfht_for_each_entry (the_agent_apps_ht_by_sock->ht, &iter.iter, app, node.node) {
+
+ for (auto *app : lttng::urcu::
+ lfht_iteration_adapter<agent_app, decltype(agent_app::node), &agent_app::node>(
+ *the_agent_apps_ht_by_sock->ht)) {
if (app->domain != domain) {
continue;
}
}
}
end:
- rcu_read_unlock();
return ret;
}
{
int ret;
size_t nbmem, count = 0;
- struct agent_app *app;
struct lttng_event *tmp_events = nullptr;
- struct lttng_ht_iter iter;
LTTNG_ASSERT(events);
goto error;
}
- rcu_read_lock();
- cds_lfht_for_each_entry (the_agent_apps_ht_by_sock->ht, &iter.iter, app, node.node) {
+ for (auto *app : lttng::urcu::
+ lfht_iteration_adapter<agent_app, decltype(agent_app::node), &agent_app::node>(
+ *the_agent_apps_ht_by_sock->ht)) {
ssize_t nb_ev;
struct lttng_event *agent_events;
nb_ev = list_events(app, &agent_events);
if (nb_ev < 0) {
ret = nb_ev;
- goto error_unlock;
+ goto error;
}
if (count + nb_ev > nbmem) {
PERROR("realloc agent events");
ret = -ENOMEM;
free(agent_events);
- goto error_unlock;
+ goto error;
}
+
/* Zero the new memory */
memset(new_tmp_events + nbmem,
0,
free(agent_events);
count += nb_ev;
}
- rcu_read_unlock();
ret = count;
*events = tmp_events;
return ret;
-error_unlock:
- rcu_read_unlock();
error:
free(tmp_events);
return ret;
ASSERT_RCU_READ_LOCKED();
lttng_ht_lookup(the_agent_apps_ht_by_sock, (void *) ((unsigned long) sock), &iter);
- node = lttng_ht_iter_get_node_ulong(&iter);
+ node = lttng_ht_iter_get_node<lttng_ht_node_ulong>(&iter);
if (node == nullptr) {
goto error;
}
logging_get_name_pattern = lttng_event_rule_log4j_logging_get_name_pattern;
logging_get_log_level_rule = lttng_event_rule_log4j_logging_get_log_level_rule;
break;
+ case LTTNG_EVENT_RULE_TYPE_LOG4J2_LOGGING:
+ logging_get_name_pattern = lttng_event_rule_log4j2_logging_get_name_pattern;
+ logging_get_log_level_rule = lttng_event_rule_log4j2_logging_get_log_level_rule;
+ break;
case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING:
logging_get_name_pattern = lttng_event_rule_python_logging_get_name_pattern;
logging_get_log_level_rule = lttng_event_rule_python_logging_get_log_level_rule;
domain = lttng_event_rule_get_domain_type(rule);
LTTNG_ASSERT(domain == LTTNG_DOMAIN_JUL || domain == LTTNG_DOMAIN_LOG4J ||
- domain == LTTNG_DOMAIN_PYTHON);
+ domain == LTTNG_DOMAIN_LOG4J2 || domain == LTTNG_DOMAIN_PYTHON);
/* Get the event's pattern name ('name' in the legacy terminology). */
er_status = logging_get_name_pattern(rule, &name);
ht_match_event,
&key,
&iter.iter);
- node = lttng_ht_iter_get_node_str(&iter);
+ node = lttng_ht_iter_get_node<lttng_ht_node_str>(&iter);
if (node == nullptr) {
goto error;
}
*/
void agent_destroy(struct agent *agt)
{
- struct lttng_ht_node_str *node;
- struct lttng_ht_iter iter;
- struct agent_app_ctx *ctx;
-
LTTNG_ASSERT(agt);
DBG3("Agent destroy");
- rcu_read_lock();
- cds_lfht_for_each_entry (agt->events->ht, &iter.iter, node, node) {
+ for (auto *event :
+ lttng::urcu::lfht_iteration_adapter<agent_event,
+ decltype(agent_event::node),
+ &agent_event::node>(*agt->events->ht)) {
int ret;
- struct agent_event *event;
/*
* When destroying an event, we have to try to disable it on the
* value is not important since we have to continue anyway
* destroying the object.
*/
- event = lttng::utils::container_of(node, &agent_event::node);
(void) agent_disable_event(event, agt->domain);
- ret = lttng_ht_del(agt->events, &iter);
+ ret = cds_lfht_del(agt->events->ht, &event->node.node);
LTTNG_ASSERT(!ret);
- call_rcu(&node->head, destroy_event_agent_rcu);
+ call_rcu(&event->node.head, destroy_event_agent_rcu);
}
+ agent_app_ctx *ctx;
cds_list_for_each_entry_rcu(ctx, &agt->app_ctx_list, list_node)
{
(void) disable_context(ctx, agt->domain);
cds_list_del(&ctx->list_node);
call_rcu(&ctx->rcu_node, destroy_app_ctx_rcu);
}
- rcu_read_unlock();
+
lttng_ht_destroy(agt->events);
free(agt);
}
* happen. The hash table deletion is ONLY done through this call when the
* main sessiond thread is torn down.
*/
- rcu_read_lock();
+ const lttng::urcu::read_lock_guard read_lock;
app = agent_find_app_by_sock(sock);
LTTNG_ASSERT(app);
/* The application is freed in a RCU call but the socket is closed here. */
agent_destroy_app(app);
- rcu_read_unlock();
}
/*
*/
void agent_app_ht_clean()
{
- struct lttng_ht_node_ulong *node;
- struct lttng_ht_iter iter;
-
if (!the_agent_apps_ht_by_sock) {
return;
}
- rcu_read_lock();
- cds_lfht_for_each_entry (the_agent_apps_ht_by_sock->ht, &iter.iter, node, node) {
- struct agent_app *app;
- app = lttng::utils::container_of(node, &agent_app::node);
+ for (auto *app : lttng::urcu::
+ lfht_iteration_adapter<agent_app, decltype(agent_app::node), &agent_app::node>(
+ *the_agent_apps_ht_by_sock->ht)) {
agent_destroy_app_by_sock(app->sock->fd);
}
- rcu_read_unlock();
lttng_ht_destroy(the_agent_apps_ht_by_sock);
}
void agent_update(const struct agent *agt, const struct agent_app *app)
{
int ret;
- struct agent_event *event;
- struct lttng_ht_iter iter;
struct agent_app_ctx *ctx;
LTTNG_ASSERT(agt);
DBG("Agent updating app: pid = %ld", (long) app->pid);
- rcu_read_lock();
/*
* We are in the registration path thus if the application is gone,
* there is a serious code flow error.
*/
-
- cds_lfht_for_each_entry (agt->events->ht, &iter.iter, event, node.node) {
+ for (auto *event :
+ lttng::urcu::lfht_iteration_adapter<agent_event,
+ decltype(agent_event::node),
+ &agent_event::node>(*agt->events->ht)) {
/* Skip event if disabled. */
if (!AGENT_EVENT_IS_ENABLED(event)) {
continue;
continue;
}
}
-
- rcu_read_unlock();
}
/*
*/
void agent_by_event_notifier_domain_ht_destroy()
{
- struct lttng_ht_node_u64 *node;
- struct lttng_ht_iter iter;
-
if (!the_trigger_agents_ht_by_domain) {
return;
}
- rcu_read_lock();
- cds_lfht_for_each_entry (the_trigger_agents_ht_by_domain->ht, &iter.iter, node, node) {
- struct agent *agent = lttng::utils::container_of(node, &agent::node);
- const int ret = lttng_ht_del(the_trigger_agents_ht_by_domain, &iter);
+ for (struct agent *agent :
+ lttng::urcu::lfht_iteration_adapter<struct agent, decltype(agent::node), &agent::node>(
+ *the_trigger_agents_ht_by_domain->ht)) {
+ const auto ret =
+ cds_lfht_del(the_trigger_agents_ht_by_domain->ht, &agent->node.node);
LTTNG_ASSERT(ret == 0);
agent_destroy(agent);
}
- rcu_read_unlock();
lttng_ht_destroy(the_trigger_agents_ht_by_domain);
}
lttng_domain_type_str(domain_type));
lttng_ht_lookup(the_trigger_agents_ht_by_domain, &key, &iter);
- node = lttng_ht_iter_get_node_u64(&iter);
+ node = lttng_ht_iter_get_node<lttng_ht_node_u64>(&iter);
if (!node) {
goto end;
}