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