From 8790759cef081ff562cff2b493e20a6a085f4b21 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Mon, 8 Mar 2021 17:19:51 -0500 Subject: [PATCH] notification-thread: add `GET_TRIGGER` command MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Francis Deslauriers Signed-off-by: Jérémie Galarneau Change-Id: Ifc94ea894999b9da796aa4fda0d929d237e12d3e --- .../notification-thread-commands.c | 26 +++++++ .../notification-thread-commands.h | 13 ++++ .../notification-thread-events.c | 75 +++++++++++++++++++ 3 files changed, 114 insertions(+) diff --git a/src/bin/lttng-sessiond/notification-thread-commands.c b/src/bin/lttng-sessiond/notification-thread-commands.c index b1b33343b..7f031e742 100644 --- a/src/bin/lttng-sessiond/notification-thread-commands.c +++ b/src/bin/lttng-sessiond/notification-thread-commands.c @@ -382,6 +382,32 @@ int notification_thread_client_communication_update( return run_command_no_wait(handle, &cmd); } +enum lttng_error_code notification_thread_command_get_trigger( + struct notification_thread_handle *handle, + const struct lttng_trigger *trigger, + struct lttng_trigger **real_trigger) +{ + int ret; + enum lttng_error_code ret_code; + struct notification_thread_command cmd = {}; + + init_notification_thread_command(&cmd); + + cmd.type = NOTIFICATION_COMMAND_TYPE_GET_TRIGGER; + cmd.parameters.get_trigger.trigger = trigger; + ret = run_command_wait(handle, &cmd); + if (ret) { + ret_code = LTTNG_ERR_UNK; + goto end; + } + + ret_code = cmd.reply_code; + *real_trigger = cmd.reply.get_trigger.trigger; + +end: + return ret_code; +} + /* * Takes ownership of the payload if present. */ diff --git a/src/bin/lttng-sessiond/notification-thread-commands.h b/src/bin/lttng-sessiond/notification-thread-commands.h index 50751a94d..882959a29 100644 --- a/src/bin/lttng-sessiond/notification-thread-commands.h +++ b/src/bin/lttng-sessiond/notification-thread-commands.h @@ -32,6 +32,7 @@ enum notification_thread_command_type { NOTIFICATION_COMMAND_TYPE_LIST_TRIGGERS, NOTIFICATION_COMMAND_TYPE_QUIT, NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE, + NOTIFICATION_COMMAND_TYPE_GET_TRIGGER, }; struct notification_thread_command { @@ -89,12 +90,19 @@ struct notification_thread_command { enum client_transmission_status status; } client_communication_update; + struct { + const struct lttng_trigger *trigger; + } get_trigger; + } parameters; union { struct { struct lttng_triggers *triggers; } list_triggers; + struct { + struct lttng_trigger *trigger; + } get_trigger; } reply; /* lttng_waiter on which to wait for command reply (optional). */ struct lttng_waiter reply_waiter; @@ -166,4 +174,9 @@ enum lttng_error_code notification_thread_command_remove_tracer_event_source( void notification_thread_command_quit( struct notification_thread_handle *handle); +enum lttng_error_code notification_thread_command_get_trigger( + struct notification_thread_handle *handle, + const struct lttng_trigger *trigger, + struct lttng_trigger **real_trigger); + #endif /* NOTIFICATION_THREAD_COMMANDS_H */ diff --git a/src/bin/lttng-sessiond/notification-thread-events.c b/src/bin/lttng-sessiond/notification-thread-events.c index ec4d56bce..28e553f44 100644 --- a/src/bin/lttng-sessiond/notification-thread-events.c +++ b/src/bin/lttng-sessiond/notification-thread-events.c @@ -353,6 +353,8 @@ const char *notification_command_type_str( return "REMOVE_TRACER_EVENT_SOURCE"; case NOTIFICATION_COMMAND_TYPE_LIST_TRIGGERS: return "LIST_TRIGGERS"; + case NOTIFICATION_COMMAND_TYPE_GET_TRIGGER: + return "GET_TRIGGER"; case NOTIFICATION_COMMAND_TYPE_QUIT: return "QUIT"; case NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE: @@ -2280,6 +2282,69 @@ end: return ret; } +static inline void get_trigger_info_for_log(const struct lttng_trigger *trigger, + const char **trigger_name, + uid_t *trigger_owner_uid) +{ + enum lttng_trigger_status trigger_status; + + trigger_status = lttng_trigger_get_name(trigger, trigger_name); + switch (trigger_status) { + case LTTNG_TRIGGER_STATUS_OK: + break; + case LTTNG_TRIGGER_STATUS_UNSET: + *trigger_name = "(unset)"; + break; + default: + abort(); + } + + trigger_status = lttng_trigger_get_owner_uid(trigger, + trigger_owner_uid); + assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); +} + +static int handle_notification_thread_command_get_trigger( + struct notification_thread_state *state, + const struct lttng_trigger *trigger, + struct lttng_trigger **registered_trigger, + enum lttng_error_code *_cmd_result) +{ + int ret = -1; + struct cds_lfht_iter iter; + struct lttng_trigger_ht_element *trigger_ht_element; + enum lttng_error_code cmd_result = LTTNG_ERR_TRIGGER_NOT_FOUND; + const char *trigger_name; + uid_t trigger_owner_uid; + + rcu_read_lock(); + + cds_lfht_for_each_entry( + state->triggers_ht, &iter, trigger_ht_element, node) { + if (lttng_trigger_is_equal( + trigger, trigger_ht_element->trigger)) { + /* Take one reference on the return trigger. */ + *registered_trigger = trigger_ht_element->trigger; + lttng_trigger_get(*registered_trigger); + ret = 0; + cmd_result = LTTNG_OK; + goto end; + } + } + + /* Not a fatal error if the trigger is not found. */ + get_trigger_info_for_log(trigger, &trigger_name, &trigger_owner_uid); + ERR("Failed to retrieve registered version of trigger: trigger name = '%s', trigger owner uid = %d", + trigger_name, (int) trigger_owner_uid); + + ret = 0; + +end: + rcu_read_unlock(); + *_cmd_result = cmd_result; + return ret; +} + static bool condition_is_supported(struct lttng_condition *condition) { @@ -3138,6 +3203,16 @@ int handle_notification_thread_command( cmd->reply_code = LTTNG_OK; ret = 1; goto end; + case NOTIFICATION_COMMAND_TYPE_GET_TRIGGER: + { + struct lttng_trigger *trigger = NULL; + + ret = handle_notification_thread_command_get_trigger(state, + cmd->parameters.get_trigger.trigger, &trigger, + &cmd->reply_code); + cmd->reply.get_trigger.trigger = trigger; + break; + } case NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE: { const enum client_transmission_status client_status = -- 2.34.1