#include <common/defaults.hpp>
#include <common/fd-tracker/utils.hpp>
#include <common/time.hpp>
+#include <common/urcu.hpp>
#include <common/utils.hpp>
#include <common/uuid.hpp>
* else
* hostname/base_path
*/
- char *session_directory = NULL;
+ char *session_directory = nullptr;
int ret = 0;
if (session->output_path[0] != '\0') {
* integral part of the name and how a user identify a session.
*/
int ret = 0;
- char *session_directory = NULL;
+ char *session_directory = nullptr;
char creation_datetime[DATETIME_STR_LEN];
if (session->output_path[0] != '\0') {
* relayd_output_path/session_directory
* e.g. /home/user/lttng-traces/hostname/session_name
*/
- char *full_session_path = NULL;
- struct lttng_directory_handle *handle = NULL;
+ char *full_session_path = nullptr;
+ struct lttng_directory_handle *handle = nullptr;
pthread_mutex_lock(&session->lock);
full_session_path = create_output_path(session->output_path);
static int session_set_anonymous_chunk(struct relay_session *session)
{
int ret = 0;
- struct lttng_trace_chunk *chunk = NULL;
+ struct lttng_trace_chunk *chunk = nullptr;
enum lttng_trace_chunk_status status;
struct lttng_directory_handle *output_directory;
}
session->current_trace_chunk = chunk;
- chunk = NULL;
+ chunk = nullptr;
end:
lttng_trace_chunk_put(chunk);
lttng_directory_handle_put(output_directory);
bool session_name_contains_creation_time)
{
int ret;
- struct relay_session *session = NULL;
+ struct relay_session *session = nullptr;
LTTNG_ASSERT(session_name);
LTTNG_ASSERT(hostname);
lttng_ht_node_init_u64(&session->session_n, session->id);
urcu_ref_init(&session->ref);
CDS_INIT_LIST_HEAD(&session->recv_list);
- pthread_mutex_init(&session->lock, NULL);
- pthread_mutex_init(&session->recv_list_lock, NULL);
+ pthread_mutex_init(&session->lock, nullptr);
+ pthread_mutex_init(&session->recv_list_lock, nullptr);
if (lttng_strncpy(session->session_name, session_name, sizeof(session->session_name))) {
WARN("Session name exceeds maximal allowed length");
if (creation_time) {
LTTNG_OPTIONAL_SET(&session->creation_time, *creation_time);
} else {
- LTTNG_OPTIONAL_SET(&session->creation_time, time(NULL));
+ LTTNG_OPTIONAL_SET(&session->creation_time, time(nullptr));
if (session->creation_time.value == (time_t) -1) {
PERROR("Failed to sample session creation time");
goto error;
error:
session_put(session);
- return NULL;
+ return nullptr;
}
/* Should be called with RCU read-side lock held. */
*/
struct relay_session *session_get_by_id(uint64_t id)
{
- struct relay_session *session = NULL;
+ struct relay_session *session = nullptr;
struct lttng_ht_node_u64 *node;
struct lttng_ht_iter iter;
- rcu_read_lock();
+ lttng::urcu::read_lock_guard read_lock;
lttng_ht_lookup(sessions_ht, &id, &iter);
node = lttng_ht_iter_get_node_u64(&iter);
if (!node) {
session = lttng::utils::container_of(node, &relay_session::session_n);
DBG("Session find by ID %" PRIu64 " id found", id);
if (!session_get(session)) {
- session = NULL;
+ session = nullptr;
}
end:
- rcu_read_unlock();
return session;
}
goto end;
}
- rcu_read_lock();
/*
* Sample the 'ongoing_rotation' status of all relay sessions that
* originate from the same session daemon session.
*/
- cds_lfht_for_each_entry (sessions_ht->ht, &iter.iter, iterated_session, session_n.node) {
- if (!session_get(iterated_session)) {
- continue;
- }
-
- if (session == iterated_session) {
- /* Skip this session. */
- goto next_session_no_unlock;
- }
-
- pthread_mutex_lock(&iterated_session->lock);
-
- if (!iterated_session->id_sessiond.is_set) {
- /*
- * Session belongs to a peer that doesn't support
- * rotations.
- */
- goto next_session;
- }
-
- if (session->sessiond_uuid != iterated_session->sessiond_uuid) {
- /* Sessions do not originate from the same sessiond. */
- goto next_session;
- }
-
- if (LTTNG_OPTIONAL_GET(session->id_sessiond) !=
- LTTNG_OPTIONAL_GET(iterated_session->id_sessiond)) {
- /*
- * Sessions do not originate from the same sessiond
- * session.
- */
- goto next_session;
- }
-
- ongoing_rotation = iterated_session->ongoing_rotation;
-
- next_session:
- pthread_mutex_unlock(&iterated_session->lock);
- next_session_no_unlock:
- session_put(iterated_session);
-
- if (ongoing_rotation) {
- break;
+ {
+ lttng::urcu::read_lock_guard read_lock;
+
+ cds_lfht_for_each_entry (
+ sessions_ht->ht, &iter.iter, iterated_session, session_n.node) {
+ if (!session_get(iterated_session)) {
+ continue;
+ }
+
+ if (session == iterated_session) {
+ /* Skip this session. */
+ goto next_session_no_unlock;
+ }
+
+ pthread_mutex_lock(&iterated_session->lock);
+
+ if (!iterated_session->id_sessiond.is_set) {
+ /*
+ * Session belongs to a peer that doesn't support
+ * rotations.
+ */
+ goto next_session;
+ }
+
+ if (session->sessiond_uuid != iterated_session->sessiond_uuid) {
+ /* Sessions do not originate from the same sessiond. */
+ goto next_session;
+ }
+
+ if (LTTNG_OPTIONAL_GET(session->id_sessiond) !=
+ LTTNG_OPTIONAL_GET(iterated_session->id_sessiond)) {
+ /*
+ * Sessions do not originate from the same sessiond
+ * session.
+ */
+ goto next_session;
+ }
+
+ ongoing_rotation = iterated_session->ongoing_rotation;
+
+ next_session:
+ pthread_mutex_unlock(&iterated_session->lock);
+ next_session_no_unlock:
+ session_put(iterated_session);
+
+ if (ongoing_rotation) {
+ break;
+ }
}
}
- rcu_read_unlock();
end:
return ongoing_rotation;
ret = session_delete(session);
LTTNG_ASSERT(!ret);
lttng_trace_chunk_put(session->current_trace_chunk);
- session->current_trace_chunk = NULL;
+ session->current_trace_chunk = nullptr;
lttng_trace_chunk_put(session->pending_closure_trace_chunk);
- session->pending_closure_trace_chunk = NULL;
+ session->pending_closure_trace_chunk = nullptr;
ret = sessiond_trace_chunk_registry_session_destroyed(sessiond_trace_chunk_registry,
session->sessiond_uuid);
LTTNG_ASSERT(!ret);
lttng_directory_handle_put(session->output_directory);
- session->output_directory = NULL;
+ session->output_directory = nullptr;
call_rcu(&session->rcu_node, rcu_destroy_session);
}
if (!session) {
return;
}
- rcu_read_lock();
+ lttng::urcu::read_lock_guard read_lock;
urcu_ref_put(&session->ref, session_release);
- rcu_read_unlock();
}
int session_close(struct relay_session *session)
session->connection_closed = true;
pthread_mutex_unlock(&session->lock);
- rcu_read_lock();
- cds_lfht_for_each_entry (session->ctf_traces_ht->ht, &iter.iter, trace, node.node) {
- ret = ctf_trace_close(trace);
- if (ret) {
- goto rcu_unlock;
- }
- }
- cds_list_for_each_entry_rcu(stream, &session->recv_list, recv_node)
{
- /* Close streams which have not been published yet. */
- try_stream_close(stream);
+ lttng::urcu::read_lock_guard read_lock;
+
+ cds_lfht_for_each_entry (session->ctf_traces_ht->ht, &iter.iter, trace, node.node) {
+ ret = ctf_trace_close(trace);
+ if (ret) {
+ goto end;
+ }
+ }
+
+ cds_list_for_each_entry_rcu(stream, &session->recv_list, recv_node)
+ {
+ /* Close streams which have not been published yet. */
+ try_stream_close(stream);
+ }
}
-rcu_unlock:
- rcu_read_unlock();
+
+end:
if (ret) {
return ret;
}
+
/* Put self-reference from create. */
session_put(session);
return ret;
return ret;
}
-void print_sessions(void)
+void print_sessions()
{
struct lttng_ht_iter iter;
struct relay_session *session;
return;
}
- rcu_read_lock();
- cds_lfht_for_each_entry (sessions_ht->ht, &iter.iter, session, session_n.node) {
- if (!session_get(session)) {
- continue;
+ {
+ lttng::urcu::read_lock_guard read_lock;
+
+ cds_lfht_for_each_entry (sessions_ht->ht, &iter.iter, session, session_n.node) {
+ if (!session_get(session)) {
+ continue;
+ }
+ DBG("session %p refcount %ld session %" PRIu64,
+ session,
+ session->ref.refcount,
+ session->id);
+ session_put(session);
}
- DBG("session %p refcount %ld session %" PRIu64,
- session,
- session->ref.refcount,
- session->id);
- session_put(session);
}
- rcu_read_unlock();
}