X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbin%2Flttng-sessiond%2Fcontext.cpp;h=8dc82fbe82e70b538d41c2df88a1deb377df9412;hb=HEAD;hp=c8c89243823fe47a883e675532252065a75a551f;hpb=7966af5763c4aaca39df9bbfa9277ff15715c720;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/context.cpp b/src/bin/lttng-sessiond/context.cpp index c8c892438..79c454809 100644 --- a/src/bin/lttng-sessiond/context.cpp +++ b/src/bin/lttng-sessiond/context.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 EfficiOS Inc. * Copyright (C) 2016 Jérémie Galarneau * * SPDX-License-Identifier: GPL-2.0-only @@ -7,28 +7,27 @@ */ #define _LGPL_SOURCE +#include "agent.hpp" +#include "context.hpp" +#include "kernel.hpp" +#include "trace-ust.hpp" +#include "ust-app.hpp" + +#include +#include +#include + #include -#include -#include #include #include -#include -#include - -#include "context.h" -#include "kernel.h" -#include "ust-app.h" -#include "trace-ust.h" -#include "agent.h" - /* * Add kernel context to all channel. * * Assumes the ownership of kctx. */ static int add_kctx_all_channels(struct ltt_kernel_session *ksession, - struct ltt_kernel_context *kctx) + struct ltt_kernel_context *kctx) { int ret; struct ltt_kernel_channel *kchan; @@ -39,7 +38,7 @@ static int add_kctx_all_channels(struct ltt_kernel_session *ksession, DBG("Adding kernel context to all channels"); /* Go over all channels */ - cds_list_for_each_entry(kchan, &ksession->channel_list.head, list) { + cds_list_for_each_entry (kchan, &ksession->channel_list.head, list) { struct ltt_kernel_context *kctx_copy; kctx_copy = trace_kernel_copy_context(kctx); @@ -51,7 +50,7 @@ static int add_kctx_all_channels(struct ltt_kernel_session *ksession, /* Ownership of kctx_copy is transferred to the callee. */ ret = kernel_add_channel_context(kchan, kctx_copy); - kctx_copy = NULL; + kctx_copy = nullptr; if (ret != 0) { goto error; } @@ -69,8 +68,7 @@ error: * * Assumes the ownership of kctx. */ -static int add_kctx_to_channel(struct ltt_kernel_context *kctx, - struct ltt_kernel_channel *kchan) +static int add_kctx_to_channel(struct ltt_kernel_context *kctx, struct ltt_kernel_channel *kchan) { int ret; @@ -81,7 +79,7 @@ static int add_kctx_to_channel(struct ltt_kernel_context *kctx, /* Ownership of kctx is transferred to the callee. */ ret = kernel_add_channel_context(kchan, kctx); - kctx = NULL; + kctx = nullptr; if (ret != 0) { goto error; } @@ -96,25 +94,25 @@ error: * Add UST context to channel. */ static int add_uctx_to_channel(struct ltt_ust_session *usess, - enum lttng_domain_type domain, - struct ltt_ust_channel *uchan, - const struct lttng_event_context *ctx) + enum lttng_domain_type domain, + struct ltt_ust_channel *uchan, + const struct lttng_event_context *ctx) { int ret; - struct ltt_ust_context *uctx = NULL; + struct ltt_ust_context *uctx = nullptr; LTTNG_ASSERT(usess); LTTNG_ASSERT(uchan); LTTNG_ASSERT(ctx); /* Check if context is duplicate */ - cds_list_for_each_entry(uctx, &uchan->ctx_list, list) { + cds_list_for_each_entry (uctx, &uchan->ctx_list, list) { if (trace_ust_match_context(uctx, ctx)) { ret = LTTNG_ERR_UST_CONTEXT_EXIST; goto duplicate; } } - uctx = NULL; + uctx = nullptr; switch (domain) { case LTTNG_DOMAIN_JUL: @@ -155,7 +153,7 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess, /* Create ltt UST context */ uctx = trace_ust_create_context(ctx); - if (uctx == NULL) { + if (uctx == nullptr) { ret = LTTNG_ERR_UST_CONTEXT_INVAL; goto error; } @@ -187,7 +185,8 @@ duplicate: * Add kernel context to tracer. */ int context_kernel_add(struct ltt_kernel_session *ksession, - const struct lttng_event_context *ctx, char *channel_name) + const struct lttng_event_context *ctx, + const char *channel_name) { int ret; struct ltt_kernel_channel *kchan; @@ -197,7 +196,7 @@ int context_kernel_add(struct ltt_kernel_session *ksession, LTTNG_ASSERT(ctx); LTTNG_ASSERT(channel_name); - kctx = trace_kernel_create_context(NULL); + kctx = trace_kernel_create_context(nullptr); if (!kctx) { ret = -LTTNG_ERR_NOMEM; goto error; @@ -324,28 +323,27 @@ int context_kernel_add(struct ltt_kernel_session *ksession, kctx->ctx.u.perf_counter.type = ctx->u.perf_counter.type; kctx->ctx.u.perf_counter.config = ctx->u.perf_counter.config; - strncpy(kctx->ctx.u.perf_counter.name, ctx->u.perf_counter.name, - LTTNG_SYMBOL_NAME_LEN); + strncpy(kctx->ctx.u.perf_counter.name, ctx->u.perf_counter.name, LTTNG_SYMBOL_NAME_LEN); kctx->ctx.u.perf_counter.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; if (*channel_name == '\0') { ret = add_kctx_all_channels(ksession, kctx); /* Ownership of kctx is transferred to the callee. */ - kctx = NULL; + kctx = nullptr; if (ret != LTTNG_OK) { goto error; } } else { /* Get kernel channel */ kchan = trace_kernel_get_channel_by_name(channel_name, ksession); - if (kchan == NULL) { + if (kchan == nullptr) { ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND; goto error; } ret = add_kctx_to_channel(kctx, kchan); /* Ownership of kctx is transferred to the callee. */ - kctx = NULL; + kctx = nullptr; if (ret != LTTNG_OK) { goto error; } @@ -364,27 +362,27 @@ error: * Add UST context to tracer. */ int context_ust_add(struct ltt_ust_session *usess, - enum lttng_domain_type domain, - const struct lttng_event_context *ctx, - char *channel_name) + enum lttng_domain_type domain, + const struct lttng_event_context *ctx, + const char *channel_name) { int ret = LTTNG_OK; struct lttng_ht_iter iter; struct lttng_ht *chan_ht; - struct ltt_ust_channel *uchan = NULL; + struct ltt_ust_channel *uchan = nullptr; LTTNG_ASSERT(usess); LTTNG_ASSERT(ctx); LTTNG_ASSERT(channel_name); - rcu_read_lock(); + lttng::urcu::read_lock_guard read_lock; chan_ht = usess->domain_global.channels; /* Get UST channel if defined */ if (channel_name[0] != '\0') { uchan = trace_ust_find_channel_by_name(chan_ht, channel_name); - if (uchan == NULL) { + if (uchan == nullptr) { ret = LTTNG_ERR_UST_CHAN_NOT_FOUND; goto error; } @@ -394,17 +392,14 @@ int context_ust_add(struct ltt_ust_session *usess, /* Add ctx to channel */ ret = add_uctx_to_channel(usess, domain, uchan, ctx); } else { - rcu_read_lock(); /* Add ctx all events, all channels */ - cds_lfht_for_each_entry(chan_ht->ht, &iter.iter, uchan, node.node) { + cds_lfht_for_each_entry (chan_ht->ht, &iter.iter, uchan, node.node) { ret = add_uctx_to_channel(usess, domain, uchan, ctx); if (ret) { - ERR("Failed to add context to channel %s", - uchan->name); + ERR("Failed to add context to channel %s", uchan->name); continue; } } - rcu_read_unlock(); } switch (ret) { @@ -430,6 +425,5 @@ int context_ust_add(struct ltt_ust_session *usess, } error: - rcu_read_unlock(); return ret; }