X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fsessiond-trace-chunks.c;h=7005ef4965b5b99ce40e7ea931222edf3ccbf4b1;hb=2c93dc32c897a1bf6535a84817a6e5430b51189b;hp=3db2133ed87f1fc0263834995cbb3ecea7737545;hpb=ab5be9fa2eb5ba9600a82cd18fd3cfcbac69169a;p=lttng-tools.git diff --git a/src/bin/lttng-relayd/sessiond-trace-chunks.c b/src/bin/lttng-relayd/sessiond-trace-chunks.c index 3db2133ed..7005ef496 100644 --- a/src/bin/lttng-relayd/sessiond-trace-chunks.c +++ b/src/bin/lttng-relayd/sessiond-trace-chunks.c @@ -360,12 +360,13 @@ struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk( char uuid_str[LTTNG_UUID_STR_LEN]; char chunk_id_str[MAX_INT_DEC_LEN(typeof(chunk_id))] = "-1"; struct lttng_trace_chunk *published_chunk = NULL; + bool trace_chunk_already_published; lttng_uuid_to_str(sessiond_uuid, uuid_str); lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid); status = lttng_trace_chunk_get_id(new_chunk, &chunk_id); - if (status == LTTNG_TRACE_CHUNK_STATUS_OK) { + if (status == LTTNG_TRACE_CHUNK_STATUS_OK) { int ret; ret = snprintf(chunk_id_str, sizeof(chunk_id_str), "%" PRIu64, @@ -375,39 +376,48 @@ struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk( WARN("Failed to format trace chunk id"); } is_anonymous_chunk = false; - } else if (status == LTTNG_TRACE_CHUNK_STATUS_NONE) { + } else if (status == LTTNG_TRACE_CHUNK_STATUS_NONE) { is_anonymous_chunk = true; } else { ERR("Failed to get trace chunk id"); goto end; } - DBG("Attempting to publish trace chunk: sessiond {%s}, session_id = " + DBG("Attempting to publish trace chunk: sessiond {%s}, session_id = " "%" PRIu64 ", chunk_id = %s", uuid_str, session_id, is_anonymous_chunk ? "anonymous" : chunk_id_str); - element = trace_chunk_registry_ht_element_find(sessiond_registry, &key); + element = trace_chunk_registry_ht_element_find(sessiond_registry, &key); if (!element) { ERR("Failed to find registry of sessiond {%s}", uuid_str); goto end; } - published_chunk = lttng_trace_chunk_registry_publish_chunk( - element->trace_chunk_registry, session_id, new_chunk); + published_chunk = lttng_trace_chunk_registry_publish_chunk_published( + element->trace_chunk_registry, session_id, new_chunk, + &trace_chunk_already_published); /* - * At this point, two references to the published chunks exist. One - * is taken by the registry while the other is being returned to the - * caller. In the use case of the relay daemon, the reference held - * by the registry itself is undesirable. + * When the trace chunk is first published, two references to the + * published chunks exist. One is taken by the registry while the other + * is being returned to the caller. In the use case of the relay daemon, + * the reference held by the registry itself is undesirable. * * We want the trace chunk to be removed from the registry as soon * as it is not being used by the relay daemon (through a session * or a stream). This differs from the behaviour of the consumer * daemon which relies on an explicit command from the session * daemon to release the registry's reference. + * + * In cases where the trace chunk had already been published, + * the reference belonging to the sessiond trace chunk + * registry instance has already been 'put'. We simply return + * the published trace chunk with a reference taken on behalf of the + * caller. */ - lttng_trace_chunk_put(published_chunk); + if (!trace_chunk_already_published) { + lttng_trace_chunk_put(published_chunk); + } end: trace_chunk_registry_ht_element_put(element); return published_chunk;