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