From: Mathieu Desnoyers Date: Tue, 13 Aug 2019 19:28:34 +0000 (-0400) Subject: Fix: keep ust/kernel session items around for destroy notifier X-Git-Tag: v2.12.0-rc1~498 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d070c424703336e9cca9d1603e1a81bee5b59560;p=lttng-tools.git Fix: keep ust/kernel session items around for destroy notifier Split the destruction and release operations for ust and kernel inner-sessions as they may be accessed by session destruction notifiers registered against their parent ltt_session. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c index 4fdc34bad..955fd3ac2 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -131,6 +131,7 @@ int kernel_create_session(struct ltt_session *session, int tracer_fd) error: if (lks) { trace_kernel_destroy_session(lks); + trace_kernel_free_session(lks); } return ret; } @@ -1156,7 +1157,7 @@ end_boot_id: } /* - * Complete teardown of a kernel session. + * Teardown of a kernel session, keeping data required by destroy notifiers. */ void kernel_destroy_session(struct ltt_kernel_session *ksess) { @@ -1205,6 +1206,15 @@ void kernel_destroy_session(struct ltt_kernel_session *ksess) lttng_trace_chunk_put(trace_chunk); } +/* Teardown of data required by destroy notifiers. */ +void kernel_free_session(struct ltt_kernel_session *ksess) +{ + if (ksess == NULL) { + return; + } + trace_kernel_free_session(ksess); +} + /* * Destroy a kernel channel object. It does not do anything on the tracer side. */ diff --git a/src/bin/lttng-sessiond/kernel.h b/src/bin/lttng-sessiond/kernel.h index 978e4cb93..c822e8d76 100644 --- a/src/bin/lttng-sessiond/kernel.h +++ b/src/bin/lttng-sessiond/kernel.h @@ -58,6 +58,7 @@ int kernel_validate_version(int tracer_fd, struct lttng_kernel_tracer_version *kernel_tracer_version, struct lttng_kernel_tracer_abi_version *kernel_tracer_abi_version); void kernel_destroy_session(struct ltt_kernel_session *ksess); +void kernel_free_session(struct ltt_kernel_session *ksess); void kernel_destroy_channel(struct ltt_kernel_channel *kchan); enum lttng_error_code kernel_snapshot_record( struct ltt_kernel_session *ksess, diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.c index 6e187f2ff..514b11e99 100644 --- a/src/bin/lttng-sessiond/session.c +++ b/src/bin/lttng-sessiond/session.c @@ -802,11 +802,10 @@ void session_release(struct urcu_ref *ref) usess = session->ust_session; ksess = session->kernel_session; - /* Clean kernel session teardown */ + /* Clean kernel session teardown, keeping data for destroy notifier. */ kernel_destroy_session(ksess); - session->kernel_session = NULL; - /* UST session teardown */ + /* UST session teardown, keeping data for destroy notifier. */ if (usess) { /* Close any relayd session */ consumer_output_send_destroy_relayd(usess->consumer); @@ -817,9 +816,8 @@ void session_release(struct urcu_ref *ref) ERR("Error in ust_app_destroy_trace_all"); } - /* Clean up the rest. */ + /* Clean up the rest, keeping destroy notifier data. */ trace_ust_destroy_session(usess); - session->ust_session = NULL; } /* @@ -844,6 +842,13 @@ void session_release(struct urcu_ref *ref) del_session_ht(session); } session_notify_destruction(session); + + kernel_free_session(ksess); + session->kernel_session = NULL; + if (usess) { + trace_ust_free_session(usess); + session->ust_session = NULL; + } lttng_dynamic_array_reset(&session->destroy_notifiers); free(session->last_archived_chunk_name); free(session); diff --git a/src/bin/lttng-sessiond/trace-kernel.c b/src/bin/lttng-sessiond/trace-kernel.c index a8aa01b26..36af00b2d 100644 --- a/src/bin/lttng-sessiond/trace-kernel.c +++ b/src/bin/lttng-sessiond/trace-kernel.c @@ -710,7 +710,11 @@ void trace_kernel_destroy_session(struct ltt_kernel_session *session) cds_list_for_each_entry_safe(channel, ctmp, &session->channel_list.head, list) { trace_kernel_destroy_channel(channel); } +} +/* Free elements needed by destroy notifiers. */ +void trace_kernel_free_session(struct ltt_kernel_session *session) +{ /* Wipe consumer output object */ consumer_output_put(session->consumer); diff --git a/src/bin/lttng-sessiond/trace-kernel.h b/src/bin/lttng-sessiond/trace-kernel.h index 00c76a8d3..3b211740a 100644 --- a/src/bin/lttng-sessiond/trace-kernel.h +++ b/src/bin/lttng-sessiond/trace-kernel.h @@ -164,5 +164,6 @@ void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel); void trace_kernel_destroy_event(struct ltt_kernel_event *event); void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream); void trace_kernel_destroy_context(struct ltt_kernel_context *ctx); +void trace_kernel_free_session(struct ltt_kernel_session *session); #endif /* _LTT_TRACE_KERNEL_H */ diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index b1bae1794..569599af2 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -1161,7 +1161,8 @@ static void destroy_domain_global(struct ltt_ust_domain_global *dom) } /* - * Cleanup ust session structure + * Cleanup ust session structure, keeping data required by + * destroy notifier. * * Should *NOT* be called with RCU read-side lock held. */ @@ -1197,9 +1198,13 @@ void trace_ust_destroy_session(struct ltt_ust_session *session) buffer_reg_uid_destroy(reg, session->consumer); } - consumer_output_put(session->consumer); - fini_pid_tracker(&session->pid_tracker); lttng_trace_chunk_put(session->current_trace_chunk); +} + +/* Free elements needed by destroy notifiers. */ +void trace_ust_free_session(struct ltt_ust_session *session) +{ + consumer_output_put(session->consumer); free(session); } diff --git a/src/bin/lttng-sessiond/trace-ust.h b/src/bin/lttng-sessiond/trace-ust.h index 583398026..9316fa817 100644 --- a/src/bin/lttng-sessiond/trace-ust.h +++ b/src/bin/lttng-sessiond/trace-ust.h @@ -217,6 +217,7 @@ void trace_ust_destroy_session(struct ltt_ust_session *session); void trace_ust_destroy_channel(struct ltt_ust_channel *channel); void trace_ust_destroy_event(struct ltt_ust_event *event); void trace_ust_destroy_context(struct ltt_ust_context *ctx); +void trace_ust_free_session(struct ltt_ust_session *session); int trace_ust_track_pid(struct ltt_ust_session *session, int pid); int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid); @@ -279,6 +280,12 @@ static inline void trace_ust_destroy_event(struct ltt_ust_event *event) { } + +static inline +void trace_ust_free_session(struct ltt_ust_session *session) +{ +} + static inline struct ltt_ust_context *trace_ust_create_context( struct lttng_event_context *ctx)