X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-relayd%2Fsessiond-trace-chunks.c;h=1065234739a8d6e529c1dc58ba3dde24140c2666;hb=7ca172c15891d4ff3f711dcc05f991fd2c094bc7;hp=01d5b3c2d695583f6e6b09ee30ed4aafff2ab623;hpb=c35f9726a22f1d93e14589688d830efccda196f3;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 01d5b3c2d..106523473 100644 --- a/src/bin/lttng-relayd/sessiond-trace-chunks.c +++ b/src/bin/lttng-relayd/sessiond-trace-chunks.c @@ -1,18 +1,8 @@ /* - * Copyright (C) 2019 - Jérémie Galarneau + * Copyright (C) 2019 Jérémie Galarneau * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2 only, - * as published by the Free Software Foundation. + * SPDX-License-Identifier: GPL-2.0-only * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "sessiond-trace-chunks.h" @@ -120,7 +110,7 @@ void trace_chunk_registry_ht_element_release(struct urcu_ref *ref) { struct trace_chunk_registry_ht_element *element = container_of(ref, typeof(*element), ref); - char uuid_str[UUID_STR_LEN]; + char uuid_str[LTTNG_UUID_STR_LEN]; lttng_uuid_to_str(element->key.sessiond_uuid, uuid_str); @@ -151,6 +141,10 @@ static void trace_chunk_registry_ht_element_put( struct trace_chunk_registry_ht_element *element) { + if (!element) { + return; + } + urcu_ref_put(&element->ref, trace_chunk_registry_ht_element_release); } @@ -193,7 +187,7 @@ int trace_chunk_registry_ht_element_create( int ret = 0; struct trace_chunk_registry_ht_element *new_element; struct lttng_trace_chunk_registry *trace_chunk_registry; - char uuid_str[UUID_STR_LEN]; + char uuid_str[LTTNG_UUID_STR_LEN]; lttng_uuid_to_str(key->sessiond_uuid, uuid_str); @@ -213,6 +207,7 @@ int trace_chunk_registry_ht_element_create( urcu_ref_init(&new_element->ref); cds_lfht_node_init(&new_element->ht_node); new_element->trace_chunk_registry = trace_chunk_registry; + trace_chunk_registry = NULL; /* Attempt to publish the new element. */ rcu_read_lock(); @@ -261,6 +256,7 @@ end: ERR("Failed to create trace chunk registry for session daemon {%s}", uuid_str); } + lttng_trace_chunk_registry_destroy(trace_chunk_registry); return ret; } @@ -307,7 +303,7 @@ int sessiond_trace_chunk_registry_session_created( element = trace_chunk_registry_ht_element_find(sessiond_registry, &key); if (element) { - char uuid_str[UUID_STR_LEN]; + char uuid_str[LTTNG_UUID_STR_LEN]; lttng_uuid_to_str(sessiond_uuid, uuid_str); DBG("Acquired reference to trace chunk registry of sessiond {%s}", @@ -328,7 +324,7 @@ int sessiond_trace_chunk_registry_session_destroyed( int ret = 0; struct trace_chunk_registry_ht_key key; struct trace_chunk_registry_ht_element *element; - char uuid_str[UUID_STR_LEN]; + char uuid_str[LTTNG_UUID_STR_LEN]; lttng_uuid_to_str(sessiond_uuid, uuid_str); lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid); @@ -361,7 +357,7 @@ struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk( bool is_anonymous_chunk; struct trace_chunk_registry_ht_key key; struct trace_chunk_registry_ht_element *element = NULL; - char uuid_str[UUID_STR_LEN]; + 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; @@ -369,7 +365,7 @@ struct lttng_trace_chunk *sessiond_trace_chunk_registry_publish_chunk( 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, @@ -379,25 +375,25 @@ 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( + published_chunk = lttng_trace_chunk_registry_publish_chunk( element->trace_chunk_registry, session_id, new_chunk); /* * At this point, two references to the published chunks exist. One @@ -426,7 +422,7 @@ sessiond_trace_chunk_registry_get_anonymous_chunk( struct lttng_trace_chunk *chunk = NULL; struct trace_chunk_registry_ht_element *element; struct trace_chunk_registry_ht_key key; - char uuid_str[UUID_STR_LEN]; + char uuid_str[LTTNG_UUID_STR_LEN]; lttng_uuid_to_str(sessiond_uuid, uuid_str); @@ -455,7 +451,7 @@ sessiond_trace_chunk_registry_get_chunk( struct lttng_trace_chunk *chunk = NULL; struct trace_chunk_registry_ht_element *element; struct trace_chunk_registry_ht_key key; - char uuid_str[UUID_STR_LEN]; + char uuid_str[LTTNG_UUID_STR_LEN]; lttng_uuid_to_str(sessiond_uuid, uuid_str); @@ -474,3 +470,39 @@ sessiond_trace_chunk_registry_get_chunk( end: return chunk; } + +int sessiond_trace_chunk_registry_chunk_exists( + struct sessiond_trace_chunk_registry *sessiond_registry, + const lttng_uuid sessiond_uuid, + uint64_t session_id, uint64_t chunk_id, bool *chunk_exists) +{ + int ret; + struct trace_chunk_registry_ht_element *element; + struct trace_chunk_registry_ht_key key; + + lttng_uuid_copy(key.sessiond_uuid, sessiond_uuid); + element = trace_chunk_registry_ht_element_find(sessiond_registry, &key); + if (!element) { + char uuid_str[LTTNG_UUID_STR_LEN]; + + lttng_uuid_to_str(sessiond_uuid, uuid_str); + /* + * While this certainly means that the chunk does not exist, + * it is unexpected for a chunk existence query to target a + * session daemon that does not have an active + * connection/registry. This would indicate a protocol + * (or internal) error. + */ + ERR("Failed to find trace chunk registry of sessiond {%s}", + uuid_str); + ret = -1; + goto end; + } + + ret = lttng_trace_chunk_registry_chunk_exists( + element->trace_chunk_registry, + session_id, chunk_id, chunk_exists); + trace_chunk_registry_ht_element_put(element); +end: + return ret; +}