trigger: generate and add tracer token on registration
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Wed, 9 Sep 2020 21:16:53 +0000 (17:16 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 12 Nov 2020 16:53:06 +0000 (11:53 -0500)
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 <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I2033dcaa4c5536b29dd4d7c57933e1aa686082cd

include/lttng/trigger/trigger-internal.h
src/bin/lttng-sessiond/notification-thread-events.c
src/bin/lttng-sessiond/notification-thread.c
src/bin/lttng-sessiond/notification-thread.h
src/common/trigger.c

index 20b1ff33aab687b499c8e92f68ef4a2e929e9934..df69f3d110a2c49fe970f80883f74f018cea0c37 100644 (file)
@@ -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);
index b47a79528c329026870ed9afe4815b72da2be3fe..398ddc3896c39c7a94a67778a986057dceeae93c 100644 (file)
@@ -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);
index 0c2d0d294628e2aea442498592ec1f379b15727a..9b2cd5b96a9139ad9cea7e934b4e84770167d40c 100644 (file)
@@ -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();
index 4e1ca4b8011fc3392394a09dc4f3f5303e07ee2c..c80bb691db52263c9075a31e21f968037811f51b 100644 (file)
@@ -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;
index af0c5fa348166b833c61331f19f2cc2dba69567d..f77a321295d4c10a9c7d67ce51071bc649854a19 100644 (file)
@@ -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)
This page took 0.03886 seconds and 4 git commands to generate.