| 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_LIST_TRIGGERS, |
| 31 | NOTIFICATION_COMMAND_TYPE_QUIT, |
| 32 | NOTIFICATION_COMMAND_TYPE_CLIENT_COMMUNICATION_UPDATE, |
| 33 | }; |
| 34 | |
| 35 | struct notification_thread_command { |
| 36 | struct cds_list_head cmd_list_node; |
| 37 | |
| 38 | enum notification_thread_command_type type; |
| 39 | union { |
| 40 | /* Register/Unregister trigger. */ |
| 41 | struct lttng_trigger *trigger; |
| 42 | /* Add channel. */ |
| 43 | struct { |
| 44 | struct { |
| 45 | const char *name; |
| 46 | uid_t uid; |
| 47 | gid_t gid; |
| 48 | } session; |
| 49 | struct { |
| 50 | const char *name; |
| 51 | enum lttng_domain_type domain; |
| 52 | uint64_t key; |
| 53 | uint64_t capacity; |
| 54 | } channel; |
| 55 | } add_channel; |
| 56 | /* Remove channel. */ |
| 57 | struct { |
| 58 | uint64_t key; |
| 59 | enum lttng_domain_type domain; |
| 60 | } remove_channel; |
| 61 | struct { |
| 62 | const char *session_name; |
| 63 | uid_t uid; |
| 64 | gid_t gid; |
| 65 | uint64_t trace_archive_chunk_id; |
| 66 | struct lttng_trace_archive_location *location; |
| 67 | } session_rotation; |
| 68 | /* List triggers. */ |
| 69 | struct { |
| 70 | /* Credentials of the requesting user. */ |
| 71 | uid_t uid; |
| 72 | } list_triggers; |
| 73 | /* Client communication update. */ |
| 74 | struct { |
| 75 | notification_client_id id; |
| 76 | enum client_transmission_status status; |
| 77 | } client_communication_update; |
| 78 | |
| 79 | } parameters; |
| 80 | |
| 81 | union { |
| 82 | struct { |
| 83 | struct lttng_triggers *triggers; |
| 84 | } list_triggers; |
| 85 | } reply; |
| 86 | /* lttng_waiter on which to wait for command reply (optional). */ |
| 87 | struct lttng_waiter reply_waiter; |
| 88 | enum lttng_error_code reply_code; |
| 89 | bool is_async; |
| 90 | }; |
| 91 | |
| 92 | enum lttng_error_code notification_thread_command_register_trigger( |
| 93 | struct notification_thread_handle *handle, |
| 94 | struct lttng_trigger *trigger); |
| 95 | |
| 96 | enum lttng_error_code notification_thread_command_unregister_trigger( |
| 97 | struct notification_thread_handle *handle, |
| 98 | struct lttng_trigger *trigger); |
| 99 | |
| 100 | enum lttng_error_code notification_thread_command_add_channel( |
| 101 | struct notification_thread_handle *handle, |
| 102 | char *session_name, uid_t session_uid, gid_t session_gid, |
| 103 | char *channel_name, uint64_t key, |
| 104 | enum lttng_domain_type domain, uint64_t capacity); |
| 105 | |
| 106 | enum lttng_error_code notification_thread_command_remove_channel( |
| 107 | struct notification_thread_handle *handle, |
| 108 | uint64_t key, enum lttng_domain_type domain); |
| 109 | |
| 110 | enum lttng_error_code notification_thread_command_session_rotation_ongoing( |
| 111 | struct notification_thread_handle *handle, |
| 112 | const char *session_name, uid_t session_uid, gid_t session_gid, |
| 113 | uint64_t trace_archive_chunk_id); |
| 114 | |
| 115 | /* Ownership of location is transferred. */ |
| 116 | enum lttng_error_code notification_thread_command_session_rotation_completed( |
| 117 | struct notification_thread_handle *handle, |
| 118 | const char *session_name, uid_t session_uid, gid_t session_gid, |
| 119 | uint64_t trace_archive_chunk_id, |
| 120 | struct lttng_trace_archive_location *location); |
| 121 | |
| 122 | /* |
| 123 | * Return the set of triggers visible to a given client. |
| 124 | * |
| 125 | * The trigger objects contained in the set are the actual trigger instances |
| 126 | * used by the notification subsystem (i.e. not a copy). Given that the command |
| 127 | * is only used to serialize the triggers, this is fine: the properties that |
| 128 | * are serialized are immutable over the lifetime of the triggers. |
| 129 | * |
| 130 | * Moreover, the lifetime of the trigger instances is protected through |
| 131 | * reference counting (references are held by the trigger set). |
| 132 | * |
| 133 | * The caller has the exclusive ownership of the returned trigger set. |
| 134 | */ |
| 135 | enum lttng_error_code notification_thread_command_list_triggers( |
| 136 | struct notification_thread_handle *handle, |
| 137 | uid_t client_uid, |
| 138 | struct lttng_triggers **triggers); |
| 139 | |
| 140 | void notification_thread_command_quit( |
| 141 | struct notification_thread_handle *handle); |
| 142 | |
| 143 | #endif /* NOTIFICATION_THREAD_COMMANDS_H */ |