| 1 | /* |
| 2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef NOTIFICATION_THREAD_COMMANDS_H |
| 9 | #define NOTIFICATION_THREAD_COMMANDS_H |
| 10 | |
| 11 | #include "notification-thread-events.hpp" |
| 12 | #include "notification-thread-internal.hpp" |
| 13 | #include "notification-thread.hpp" |
| 14 | |
| 15 | #include <common/waiter.hpp> |
| 16 | |
| 17 | #include <lttng/domain.h> |
| 18 | #include <lttng/lttng-error.h> |
| 19 | |
| 20 | #include <vendor/optional.hpp> |
| 21 | |
| 22 | #include <stdbool.h> |
| 23 | #include <urcu/rculfhash.h> |
| 24 | |
| 25 | struct notification_thread_data; |
| 26 | struct lttng_trigger; |
| 27 | |
| 28 | enum notification_thread_command_type { |
| 29 | NOTIFICATION_COMMAND_TYPE_REGISTER_TRIGGER, |
| 30 | NOTIFICATION_COMMAND_TYPE_UNREGISTER_TRIGGER, |
| 31 | NOTIFICATION_COMMAND_TYPE_ADD_CHANNEL, |
| 32 | NOTIFICATION_COMMAND_TYPE_REMOVE_CHANNEL, |
| 33 | NOTIFICATION_COMMAND_TYPE_ADD_SESSION, |
| 34 | NOTIFICATION_COMMAND_TYPE_REMOVE_SESSION, |
| 35 | NOTIFICATION_COMMAND_TYPE_SESSION_ROTATION_ONGOING, |
| 36 | NOTIFICATION_COMMAND_TYPE_SESSION_ROTATION_COMPLETED, |
| 37 | NOTIFICATION_COMMAND_TYPE_ADD_TRACER_EVENT_SOURCE, |
| 38 | NOTIFICATION_COMMAND_TYPE_REMOVE_TRACER_EVENT_SOURCE, |
| 39 | NOTIFICATION_COMMAND_TYPE_LIST_TRIGGERS, |
| 40 | NOTIFICATION_COMMAND_TYPE_QUIT, |
| 41 | NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE, |
| 42 | NOTIFICATION_COMMAND_TYPE_GET_TRIGGER, |
| 43 | }; |
| 44 | |
| 45 | struct notification_thread_command { |
| 46 | struct cds_list_head cmd_list_node = {}; |
| 47 | |
| 48 | notification_thread_command_type type = NOTIFICATION_COMMAND_TYPE_QUIT; |
| 49 | union { |
| 50 | /* Register trigger. */ |
| 51 | struct { |
| 52 | struct lttng_trigger *trigger; |
| 53 | bool is_trigger_anonymous; |
| 54 | } register_trigger; |
| 55 | /* Unregister trigger. */ |
| 56 | struct { |
| 57 | const struct lttng_trigger *trigger; |
| 58 | } unregister_trigger; |
| 59 | /* Add session. */ |
| 60 | struct { |
| 61 | uint64_t session_id; |
| 62 | const char *session_name; |
| 63 | uid_t session_uid; |
| 64 | gid_t session_gid; |
| 65 | } add_session; |
| 66 | /* Remove session. */ |
| 67 | struct { |
| 68 | uint64_t session_id; |
| 69 | } remove_session; |
| 70 | /* Add channel. */ |
| 71 | struct { |
| 72 | struct { |
| 73 | uint64_t id; |
| 74 | } session; |
| 75 | struct { |
| 76 | const char *name; |
| 77 | enum lttng_domain_type domain; |
| 78 | uint64_t key; |
| 79 | uint64_t capacity; |
| 80 | } channel; |
| 81 | } add_channel; |
| 82 | /* Remove channel. */ |
| 83 | struct { |
| 84 | uint64_t key; |
| 85 | enum lttng_domain_type domain; |
| 86 | } remove_channel; |
| 87 | struct { |
| 88 | uint64_t session_id; |
| 89 | uint64_t trace_archive_chunk_id; |
| 90 | /* Weak reference. */ |
| 91 | struct lttng_trace_archive_location *location; |
| 92 | } session_rotation; |
| 93 | /* Add/Remove tracer event source fd. */ |
| 94 | struct { |
| 95 | int tracer_event_source_fd; |
| 96 | enum lttng_domain_type domain; |
| 97 | } tracer_event_source; |
| 98 | /* List triggers. */ |
| 99 | struct { |
| 100 | /* Credentials of the requesting user. */ |
| 101 | uid_t uid; |
| 102 | } list_triggers; |
| 103 | /* Client communication update. */ |
| 104 | struct { |
| 105 | notification_client_id id; |
| 106 | enum client_transmission_status status; |
| 107 | } client_communication_update; |
| 108 | |
| 109 | struct { |
| 110 | const struct lttng_trigger *trigger; |
| 111 | } get_trigger; |
| 112 | |
| 113 | } parameters = {}; |
| 114 | |
| 115 | union { |
| 116 | struct { |
| 117 | struct lttng_triggers *triggers; |
| 118 | } list_triggers; |
| 119 | struct { |
| 120 | struct lttng_trigger *trigger; |
| 121 | } get_trigger; |
| 122 | } reply = {}; |
| 123 | |
| 124 | /* Used to wake origin thread for synchroneous commands. */ |
| 125 | nonstd::optional<lttng::synchro::waker> command_completed_waker = nonstd::nullopt; |
| 126 | lttng_error_code reply_code = LTTNG_ERR_UNK; |
| 127 | bool is_async = false; |
| 128 | }; |
| 129 | |
| 130 | enum lttng_error_code |
| 131 | notification_thread_command_register_trigger(struct notification_thread_handle *handle, |
| 132 | struct lttng_trigger *trigger, |
| 133 | bool is_anonymous_trigger); |
| 134 | |
| 135 | enum lttng_error_code |
| 136 | notification_thread_command_unregister_trigger(struct notification_thread_handle *handle, |
| 137 | const struct lttng_trigger *trigger); |
| 138 | |
| 139 | enum lttng_error_code |
| 140 | notification_thread_command_add_session(struct notification_thread_handle *handle, |
| 141 | uint64_t session_id, |
| 142 | const char *session_name, |
| 143 | uid_t session_uid, |
| 144 | gid_t session_gid); |
| 145 | |
| 146 | enum lttng_error_code |
| 147 | notification_thread_command_remove_session(struct notification_thread_handle *handle, |
| 148 | uint64_t session_id); |
| 149 | |
| 150 | enum lttng_error_code |
| 151 | notification_thread_command_add_channel(struct notification_thread_handle *handle, |
| 152 | uint64_t session_id, |
| 153 | char *channel_name, |
| 154 | uint64_t key, |
| 155 | enum lttng_domain_type domain, |
| 156 | uint64_t capacity); |
| 157 | |
| 158 | enum lttng_error_code notification_thread_command_remove_channel( |
| 159 | struct notification_thread_handle *handle, uint64_t key, enum lttng_domain_type domain); |
| 160 | |
| 161 | enum lttng_error_code |
| 162 | notification_thread_command_session_rotation_ongoing(struct notification_thread_handle *handle, |
| 163 | uint64_t session_id, |
| 164 | uint64_t trace_archive_chunk_id); |
| 165 | |
| 166 | /* Ownership of location is transferred. */ |
| 167 | enum lttng_error_code notification_thread_command_session_rotation_completed( |
| 168 | struct notification_thread_handle *handle, |
| 169 | uint64_t session_id, |
| 170 | uint64_t trace_archive_chunk_id, |
| 171 | struct lttng_trace_archive_location *location); |
| 172 | |
| 173 | /* |
| 174 | * Return the set of triggers visible to a given client. |
| 175 | * |
| 176 | * The trigger objects contained in the set are the actual trigger instances |
| 177 | * used by the notification subsystem (i.e. not a copy). Given that the command |
| 178 | * is only used to serialize the triggers, this is fine: the properties that |
| 179 | * are serialized are immutable over the lifetime of the triggers. |
| 180 | * |
| 181 | * Moreover, the lifetime of the trigger instances is protected through |
| 182 | * reference counting (references are held by the trigger set). |
| 183 | * |
| 184 | * The caller has the exclusive ownership of the returned trigger set. |
| 185 | */ |
| 186 | enum lttng_error_code |
| 187 | notification_thread_command_list_triggers(struct notification_thread_handle *handle, |
| 188 | uid_t client_uid, |
| 189 | struct lttng_triggers **triggers); |
| 190 | |
| 191 | /* |
| 192 | * The ownership of trigger_event_application_pipe is _not_ transferred to |
| 193 | * the notification thread. |
| 194 | */ |
| 195 | enum lttng_error_code |
| 196 | notification_thread_command_add_tracer_event_source(struct notification_thread_handle *handle, |
| 197 | int tracer_event_source_fd, |
| 198 | enum lttng_domain_type domain); |
| 199 | |
| 200 | enum lttng_error_code |
| 201 | notification_thread_command_remove_tracer_event_source(struct notification_thread_handle *handle, |
| 202 | int tracer_event_source_fd); |
| 203 | |
| 204 | void notification_thread_command_quit(struct notification_thread_handle *handle); |
| 205 | |
| 206 | enum lttng_error_code |
| 207 | notification_thread_command_get_trigger(struct notification_thread_handle *handle, |
| 208 | const struct lttng_trigger *trigger, |
| 209 | struct lttng_trigger **real_trigger); |
| 210 | |
| 211 | #endif /* NOTIFICATION_THREAD_COMMANDS_H */ |