X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-sessiond%2Fsession.cpp;h=e9d7261031d632fc44e4f820621a8e471a3e9e74;hb=a3c9aa3ccf6bf710701074ffa97f2b7a59b0fc16;hp=f01f3439cb8f6ca7b53aaf2828c59ad67800181b;hpb=f149493493fbd8a3efa4748832c03278c96c38ca;p=lttng-tools.git diff --git a/src/bin/lttng-sessiond/session.cpp b/src/bin/lttng-sessiond/session.cpp index f01f3439c..e9d726103 100644 --- a/src/bin/lttng-sessiond/session.cpp +++ b/src/bin/lttng-sessiond/session.cpp @@ -6,30 +6,32 @@ */ #define _LGPL_SOURCE -#include +#include #include +#include +#include #include #include #include #include -#include -#include #include -#include +#include #include -#include -#include #include -#include +#include +#include +#include + #include "lttng-sessiond.hpp" -#include "kernel.hpp" +#include +#include "cmd.hpp" +#include "kernel.hpp" #include "session.hpp" -#include "utils.hpp" -#include "trace-ust.hpp" #include "timer.hpp" -#include "cmd.hpp" +#include "trace-ust.hpp" +#include "utils.hpp" namespace { struct ltt_session_destroy_notifier_element { @@ -42,6 +44,8 @@ struct ltt_session_clear_notifier_element { void *user_data; }; +namespace ls = lttng::sessiond; + /* * NOTES: * @@ -872,7 +876,7 @@ enum lttng_error_code session_kernel_open_packets(struct ltt_session *session) cds_lfht_first(session->kernel_session->consumer->socks->ht, &iter.iter); node = cds_lfht_iter_get_node(&iter.iter); - socket = container_of(node, typeof(*socket), node.node); + socket = caa_container_of(node, typeof(*socket), node.node); cds_list_for_each_entry(chan, &session->kernel_session->channel_list.head, list) { @@ -975,7 +979,7 @@ void session_release(struct urcu_ref *ref) int ret; struct ltt_ust_session *usess; struct ltt_kernel_session *ksess; - struct ltt_session *session = container_of(ref, typeof(*session), ref); + struct ltt_session *session = lttng::utils::container_of(ref, <t_session::ref); const bool session_published = session->published; LTTNG_ASSERT(!session->chunk_being_archived); @@ -1034,6 +1038,7 @@ void session_release(struct urcu_ref *ref) lttng_dynamic_array_reset(&session->clear_notifiers); free(session->last_archived_chunk_name); free(session->base_path); + lttng_trigger_put(session->rotate_trigger); free(session); if (session_published) { /* @@ -1178,7 +1183,7 @@ struct ltt_session *session_find_by_id(uint64_t id) if (node == NULL) { goto end; } - ls = caa_container_of(node, struct ltt_session, node); + ls = lttng::utils::container_of(node, <t_session::node); DBG3("Session %" PRIu64 " found by id.", id); return session_get(ls) ? ls : NULL; @@ -1451,7 +1456,7 @@ bool sample_session_id_by_name(const char *name, uint64_t *id) goto end; } - ls = caa_container_of(node, struct ltt_session, node_by_name); + ls = lttng::utils::container_of(node, <t_session::node_by_name); *id = ls->id; found = true; @@ -1460,3 +1465,38 @@ end: rcu_read_unlock(); return found; } + +void ls::details::locked_session_release(ltt_session *session) +{ + session_unlock(session); + session_put(session); +} + +ltt_session::locked_ptr ls::find_locked_session_by_id(ltt_session::id_t id) +{ + lttng::urcu::read_lock_guard rcu_lock; + auto session = session_find_by_id(id); + + if (!session) { + return nullptr; + } + + /* + * The pointer falling out of scope will unlock and release the reference to the + * session. + */ + session_lock(session); + return ltt_session::locked_ptr(session); +} + +ltt_session::sptr ls::find_session_by_id(ltt_session::id_t id) +{ + lttng::urcu::read_lock_guard rcu_lock; + auto session = session_find_by_id(id); + + if (!session) { + return nullptr; + } + + return {session, session_put}; +}