| 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_APPLICATION, |
| 31 | NOTIFICATION_COMMAND_TYPE_REMOVE_APPLICATION, |
| 32 | NOTIFICATION_COMMAND_TYPE_GET_TOKENS, |
| 33 | NOTIFICATION_COMMAND_TYPE_LIST_TRIGGERS, |
| 34 | NOTIFICATION_COMMAND_TYPE_QUIT, |
| 35 | NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE, |
| 36 | }; |
| 37 | |
| 38 | struct notification_thread_command { |
| 39 | struct cds_list_head cmd_list_node; |
| 40 | |
| 41 | enum notification_thread_command_type type; |
| 42 | union { |
| 43 | /* Register/Unregister trigger. */ |
| 44 | struct lttng_trigger *trigger; |
| 45 | /* Add channel. */ |
| 46 | struct { |
| 47 | struct { |
| 48 | const char *name; |
| 49 | uid_t uid; |
| 50 | gid_t gid; |
| 51 | } session; |
| 52 | struct { |
| 53 | const char *name; |
| 54 | enum lttng_domain_type domain; |
| 55 | uint64_t key; |
| 56 | uint64_t capacity; |
| 57 | } channel; |
| 58 | } add_channel; |
| 59 | /* Remove channel. */ |
| 60 | struct { |
| 61 | uint64_t key; |
| 62 | enum lttng_domain_type domain; |
| 63 | } remove_channel; |
| 64 | struct { |
| 65 | const char *session_name; |
| 66 | uid_t uid; |
| 67 | gid_t gid; |
| 68 | uint64_t trace_archive_chunk_id; |
| 69 | struct lttng_trace_archive_location *location; |
| 70 | } session_rotation; |
| 71 | /* Add/Remove application */ |
| 72 | struct { |
| 73 | int read_side_trigger_event_application_pipe; |
| 74 | enum lttng_domain_type domain; |
| 75 | } application; |
| 76 | /* List triggers */ |
| 77 | struct { |
| 78 | /* Credential */ |
| 79 | uid_t uid; |
| 80 | } list_triggers; |
| 81 | /* Client communication update. */ |
| 82 | struct { |
| 83 | notification_client_id id; |
| 84 | enum client_transmission_status status; |
| 85 | } client_communication_update; |
| 86 | |
| 87 | } parameters; |
| 88 | |
| 89 | union { |
| 90 | struct { |
| 91 | struct lttng_triggers *triggers; |
| 92 | } get_tokens; |
| 93 | struct { |
| 94 | struct lttng_triggers *triggers; |
| 95 | } list_triggers; |
| 96 | } reply; |
| 97 | |
| 98 | /* lttng_waiter on which to wait for command reply (optional). */ |
| 99 | struct lttng_waiter reply_waiter; |
| 100 | enum lttng_error_code reply_code; |
| 101 | bool is_async; |
| 102 | }; |
| 103 | |
| 104 | enum lttng_error_code notification_thread_command_register_trigger( |
| 105 | struct notification_thread_handle *handle, |
| 106 | struct lttng_trigger *trigger); |
| 107 | |
| 108 | enum lttng_error_code notification_thread_command_unregister_trigger( |
| 109 | struct notification_thread_handle *handle, |
| 110 | struct lttng_trigger *trigger); |
| 111 | |
| 112 | enum lttng_error_code notification_thread_command_add_channel( |
| 113 | struct notification_thread_handle *handle, |
| 114 | char *session_name, uid_t session_uid, gid_t session_gid, |
| 115 | char *channel_name, uint64_t key, |
| 116 | enum lttng_domain_type domain, uint64_t capacity); |
| 117 | |
| 118 | enum lttng_error_code notification_thread_command_remove_channel( |
| 119 | struct notification_thread_handle *handle, |
| 120 | uint64_t key, enum lttng_domain_type domain); |
| 121 | |
| 122 | enum lttng_error_code notification_thread_command_session_rotation_ongoing( |
| 123 | struct notification_thread_handle *handle, |
| 124 | const char *session_name, uid_t session_uid, gid_t session_gid, |
| 125 | uint64_t trace_archive_chunk_id); |
| 126 | |
| 127 | /* Ownership of location is transferred. */ |
| 128 | enum lttng_error_code notification_thread_command_session_rotation_completed( |
| 129 | struct notification_thread_handle *handle, |
| 130 | const char *session_name, uid_t session_uid, gid_t session_gid, |
| 131 | uint64_t trace_archive_chunk_id, |
| 132 | struct lttng_trace_archive_location *location); |
| 133 | |
| 134 | enum lttng_error_code notification_thread_command_add_application( |
| 135 | struct notification_thread_handle *handle, |
| 136 | int fd, |
| 137 | enum lttng_domain_type domain |
| 138 | ); |
| 139 | |
| 140 | enum lttng_error_code notification_thread_command_remove_application( |
| 141 | struct notification_thread_handle *handle, |
| 142 | int trigger_event_application_pipe); |
| 143 | |
| 144 | /* Must hold the notification_trigger_tokens_ht_lock to protect against |
| 145 | * insertion removal of triggers TODO: is it the case even with refcounting? */ |
| 146 | /* todo find a better way....*/ |
| 147 | enum lttng_error_code notification_thread_command_get_tokens( |
| 148 | struct notification_thread_handle *handle, |
| 149 | struct lttng_triggers **triggers); |
| 150 | |
| 151 | enum lttng_error_code notification_thread_command_list_triggers( |
| 152 | struct notification_thread_handle *handle, |
| 153 | uid_t uid, |
| 154 | struct lttng_triggers **triggers); |
| 155 | |
| 156 | void notification_thread_command_quit( |
| 157 | struct notification_thread_handle *handle); |
| 158 | |
| 159 | #endif /* NOTIFICATION_THREAD_COMMANDS_H */ |