From: Jonathan Rajotte Date: Wed, 9 Sep 2020 21:16:53 +0000 (-0400) Subject: trigger: generate and add tracer token on registration X-Git-Tag: v2.13.0-rc1~427 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=e6887944f09a8985efb521ea638b4dfe557ff4ed;hp=34f87583034e1aa9d65ce5d35b09bd5e8cfba875 trigger: generate and add tracer token on registration Assign a unique tracer token to a trigger. This token will be used as the unique id that will be communicated back to the sessiond by the tracers for tracer notification. Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau Change-Id: I2033dcaa4c5536b29dd4d7c57933e1aa686082cd --- diff --git a/include/lttng/trigger/trigger-internal.h b/include/lttng/trigger/trigger-internal.h index 20b1ff33a..df69f3d11 100644 --- a/include/lttng/trigger/trigger-internal.h +++ b/include/lttng/trigger/trigger-internal.h @@ -29,6 +29,12 @@ struct lttng_trigger { char *name; /* For now only the uid portion of the credentials is used. */ struct lttng_credentials creds; + /* + * Internal use only. + * The unique token passed to the tracer to identify an event-rule + * notification. + */ + LTTNG_OPTIONAL(uint64_t) tracer_token; }; struct lttng_trigger_comm { @@ -71,6 +77,13 @@ LTTNG_HIDDEN int lttng_trigger_assign_name( struct lttng_trigger *dst, const struct lttng_trigger *src); +LTTNG_HIDDEN +void lttng_trigger_set_tracer_token( + struct lttng_trigger *trigger, uint64_t token); + +LTTNG_HIDDEN +uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger); + LTTNG_HIDDEN int lttng_trigger_generate_name(struct lttng_trigger *trigger, uint64_t unique_id); diff --git a/src/bin/lttng-sessiond/notification-thread-events.c b/src/bin/lttng-sessiond/notification-thread-events.c index b47a79528..398ddc389 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.c +++ b/src/bin/lttng-sessiond/notification-thread-events.c @@ -2232,9 +2232,14 @@ int handle_notification_thread_command_register_trigger( uid_t object_uid; gid_t object_gid; enum action_executor_status executor_status; + const uint64_t trigger_tracer_token = + state->trigger_id.next_tracer_token++; rcu_read_lock(); + /* Set the trigger's tracer token. */ + lttng_trigger_set_tracer_token(trigger, trigger_tracer_token); + if (lttng_trigger_get_name(trigger, &trigger_name) == LTTNG_TRIGGER_STATUS_UNSET) { const enum lttng_error_code ret_code = generate_trigger_name( @@ -2473,6 +2478,8 @@ int handle_notification_thread_command_register_trigger( end: *cmd_result = LTTNG_OK; + DBG("Registered trigger: name = `%s`, tracer token = %" PRIu64, + trigger_name, trigger_tracer_token); error_put_client_list: notification_client_list_put(client_list); diff --git a/src/bin/lttng-sessiond/notification-thread.c b/src/bin/lttng-sessiond/notification-thread.c index 0c2d0d294..9b2cd5b96 100644 --- a/src/bin/lttng-sessiond/notification-thread.c +++ b/src/bin/lttng-sessiond/notification-thread.c @@ -407,6 +407,7 @@ int init_thread_state(struct notification_thread_handle *handle, memset(state, 0, sizeof(*state)); state->notification_channel_socket = -1; + state->trigger_id.next_tracer_token = 1; lttng_poll_init(&state->events); ret = notification_channel_socket_create(); diff --git a/src/bin/lttng-sessiond/notification-thread.h b/src/bin/lttng-sessiond/notification-thread.h index 4e1ca4b80..c80bb691d 100644 --- a/src/bin/lttng-sessiond/notification-thread.h +++ b/src/bin/lttng-sessiond/notification-thread.h @@ -219,6 +219,7 @@ struct notification_thread_state { struct cds_lfht *triggers_ht; struct cds_lfht *triggers_by_name_uid_ht; struct { + uint64_t next_tracer_token; uint64_t name_offset; } trigger_id; notification_client_id next_notification_client_id; diff --git a/src/common/trigger.c b/src/common/trigger.c index af0c5fa34..f77a32129 100644 --- a/src/common/trigger.c +++ b/src/common/trigger.c @@ -395,6 +395,22 @@ end: return ret; } +LTTNG_HIDDEN +void lttng_trigger_set_tracer_token(struct lttng_trigger *trigger, + uint64_t token) +{ + assert(trigger); + LTTNG_OPTIONAL_SET(&trigger->tracer_token, token); +} + +LTTNG_HIDDEN +uint64_t lttng_trigger_get_tracer_token(const struct lttng_trigger *trigger) +{ + assert(trigger); + + return LTTNG_OPTIONAL_GET(trigger->tracer_token); +} + LTTNG_HIDDEN int lttng_trigger_generate_name(struct lttng_trigger *trigger, uint64_t unique_id)