From: Mathieu Desnoyers Date: Thu, 12 Dec 2019 16:57:43 +0000 (-0500) Subject: sessiond: add clear notifier X-Git-Tag: v2.12.0-rc1~131 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=ccbdaca404a66cf124ec7e4926b1507327f6d165;p=lttng-tools.git sessiond: add clear notifier Add a clear notifier array to reply to clients requesting a clear command. Signed-off-by: Mathieu Desnoyers Change-Id: I422d87b0122b75be47ae5941fed15f09e87460fe Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/session.c b/src/bin/lttng-sessiond/session.c index 3a537e49e..0da2058fd 100644 --- a/src/bin/lttng-sessiond/session.c +++ b/src/bin/lttng-sessiond/session.c @@ -46,6 +46,11 @@ struct ltt_session_destroy_notifier_element { void *user_data; }; +struct ltt_session_clear_notifier_element { + ltt_session_clear_notifier notifier; + void *user_data; +}; + /* * NOTES: * @@ -769,6 +774,25 @@ void session_notify_destruction(const struct ltt_session *session) } } +/* + * Fire each clear notifier once, and remove them from the array. + */ +void session_notify_clear(struct ltt_session *session) +{ + size_t i; + const size_t count = lttng_dynamic_array_get_count( + &session->clear_notifiers); + + for (i = 0; i < count; i++) { + const struct ltt_session_clear_notifier_element *element = + lttng_dynamic_array_get_element( + &session->clear_notifiers, i); + + element->notifier(session, element->user_data); + } + lttng_dynamic_array_clear(&session->clear_notifiers); +} + static void session_release(struct urcu_ref *ref) { @@ -831,6 +855,7 @@ void session_release(struct urcu_ref *ref) session->ust_session = NULL; } lttng_dynamic_array_reset(&session->destroy_notifiers); + lttng_dynamic_array_reset(&session->clear_notifiers); free(session->last_archived_chunk_name); free(session->base_path); free(session); @@ -899,6 +924,18 @@ int session_add_destroy_notifier(struct ltt_session *session, &element); } +int session_add_clear_notifier(struct ltt_session *session, + ltt_session_clear_notifier notifier, void *user_data) +{ + const struct ltt_session_clear_notifier_element element = { + .notifier = notifier, + .user_data = user_data + }; + + return lttng_dynamic_array_add_element(&session->clear_notifiers, + &element); +} + /* * Return a ltt_session structure ptr that matches name. If no session found, * NULL is returned. This must be called with the session list lock held using @@ -990,6 +1027,9 @@ enum lttng_error_code session_create(const char *name, uid_t uid, gid_t gid, lttng_dynamic_array_init(&new_session->destroy_notifiers, sizeof(struct ltt_session_destroy_notifier_element), NULL); + lttng_dynamic_array_init(&new_session->clear_notifiers, + sizeof(struct ltt_session_clear_notifier_element), + NULL); urcu_ref_init(&new_session->ref); pthread_mutex_init(&new_session->lock, NULL); @@ -1184,6 +1224,11 @@ int session_reset_rotation_state(struct ltt_session *session, chunk_id); lttng_trace_chunk_put(session->chunk_being_archived); session->chunk_being_archived = NULL; + /* + * Fire the clear reply notifiers if we are completing a clear + * rotation. + */ + session_notify_clear(session); } return ret; } diff --git a/src/bin/lttng-sessiond/session.h b/src/bin/lttng-sessiond/session.h index a60354d75..da3805658 100644 --- a/src/bin/lttng-sessiond/session.h +++ b/src/bin/lttng-sessiond/session.h @@ -36,6 +36,8 @@ struct ltt_ust_session; typedef void (*ltt_session_destroy_notifier)(const struct ltt_session *session, void *user_data); +typedef void (*ltt_session_clear_notifier)(const struct ltt_session *session, + void *user_data); /* * Tracing session list @@ -193,6 +195,7 @@ struct ltt_session { char *last_archived_chunk_name; LTTNG_OPTIONAL(uint64_t) last_archived_chunk_id; struct lttng_dynamic_array destroy_notifiers; + struct lttng_dynamic_array clear_notifiers; /* Session base path override. Set non-null. */ char *base_path; }; @@ -210,6 +213,10 @@ void session_destroy(struct ltt_session *session); int session_add_destroy_notifier(struct ltt_session *session, ltt_session_destroy_notifier notifier, void *user_data); +int session_add_clear_notifier(struct ltt_session *session, + ltt_session_clear_notifier notifier, void *user_data); +void session_notify_clear(struct ltt_session *session); + bool session_get(struct ltt_session *session); void session_put(struct ltt_session *session);