2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include <lttng/trigger/trigger.h>
9 #include <lttng/lttng-error.h>
10 #include "notification-thread.h"
11 #include "notification-thread-commands.h"
12 #include <common/error.h>
18 void init_notification_thread_command(struct notification_thread_command
*cmd
)
20 memset(cmd
, 0, sizeof(*cmd
));
21 CDS_INIT_LIST_HEAD(&cmd
->cmd_list_node
);
22 lttng_waiter_init(&cmd
->reply_waiter
);
26 int run_command_wait(struct notification_thread_handle
*handle
,
27 struct notification_thread_command
*cmd
)
30 uint64_t notification_counter
= 1;
32 pthread_mutex_lock(&handle
->cmd_queue
.lock
);
34 cds_list_add_tail(&cmd
->cmd_list_node
,
35 &handle
->cmd_queue
.list
);
37 ret
= lttng_write(lttng_pipe_get_writefd(handle
->cmd_queue
.event_pipe
),
38 ¬ification_counter
, sizeof(notification_counter
));
39 if (ret
!= sizeof(notification_counter
)) {
40 PERROR("write to notification thread's queue event fd");
42 * Remove the command from the list so the notification
43 * thread does not process it.
45 cds_list_del(&cmd
->cmd_list_node
);
46 goto error_unlock_queue
;
48 pthread_mutex_unlock(&handle
->cmd_queue
.lock
);
50 lttng_waiter_wait(&cmd
->reply_waiter
);
53 pthread_mutex_unlock(&handle
->cmd_queue
.lock
);
57 enum lttng_error_code
notification_thread_command_register_trigger(
58 struct notification_thread_handle
*handle
,
59 struct lttng_trigger
*trigger
)
62 enum lttng_error_code ret_code
;
63 struct notification_thread_command cmd
;
65 init_notification_thread_command(&cmd
);
67 cmd
.type
= NOTIFICATION_COMMAND_TYPE_REGISTER_TRIGGER
;
68 cmd
.parameters
.trigger
= trigger
;
70 ret
= run_command_wait(handle
, &cmd
);
72 ret_code
= LTTNG_ERR_UNK
;
75 ret_code
= cmd
.reply_code
;
80 enum lttng_error_code
notification_thread_command_unregister_trigger(
81 struct notification_thread_handle
*handle
,
82 struct lttng_trigger
*trigger
)
85 enum lttng_error_code ret_code
;
86 struct notification_thread_command cmd
;
88 init_notification_thread_command(&cmd
);
90 cmd
.type
= NOTIFICATION_COMMAND_TYPE_UNREGISTER_TRIGGER
;
91 cmd
.parameters
.trigger
= trigger
;
93 ret
= run_command_wait(handle
, &cmd
);
95 ret_code
= LTTNG_ERR_UNK
;
98 ret_code
= cmd
.reply_code
;
103 enum lttng_error_code
notification_thread_command_add_channel(
104 struct notification_thread_handle
*handle
,
105 char *session_name
, uid_t uid
, gid_t gid
,
106 char *channel_name
, uint64_t key
,
107 enum lttng_domain_type domain
, uint64_t capacity
)
110 enum lttng_error_code ret_code
;
111 struct notification_thread_command cmd
;
113 init_notification_thread_command(&cmd
);
115 cmd
.type
= NOTIFICATION_COMMAND_TYPE_ADD_CHANNEL
;
116 cmd
.parameters
.add_channel
.session
.name
= session_name
;
117 cmd
.parameters
.add_channel
.session
.uid
= uid
;
118 cmd
.parameters
.add_channel
.session
.gid
= gid
;
119 cmd
.parameters
.add_channel
.channel
.name
= channel_name
;
120 cmd
.parameters
.add_channel
.channel
.key
= key
;
121 cmd
.parameters
.add_channel
.channel
.domain
= domain
;
122 cmd
.parameters
.add_channel
.channel
.capacity
= capacity
;
124 ret
= run_command_wait(handle
, &cmd
);
126 ret_code
= LTTNG_ERR_UNK
;
129 ret_code
= cmd
.reply_code
;
134 enum lttng_error_code
notification_thread_command_remove_channel(
135 struct notification_thread_handle
*handle
,
136 uint64_t key
, enum lttng_domain_type domain
)
139 enum lttng_error_code ret_code
;
140 struct notification_thread_command cmd
;
142 init_notification_thread_command(&cmd
);
144 cmd
.type
= NOTIFICATION_COMMAND_TYPE_REMOVE_CHANNEL
;
145 cmd
.parameters
.remove_channel
.key
= key
;
146 cmd
.parameters
.remove_channel
.domain
= domain
;
148 ret
= run_command_wait(handle
, &cmd
);
150 ret_code
= LTTNG_ERR_UNK
;
153 ret_code
= cmd
.reply_code
;
158 enum lttng_error_code
notification_thread_command_session_rotation_ongoing(
159 struct notification_thread_handle
*handle
,
160 const char *session_name
, uid_t uid
, gid_t gid
,
161 uint64_t trace_archive_chunk_id
)
164 enum lttng_error_code ret_code
;
165 struct notification_thread_command cmd
;
167 init_notification_thread_command(&cmd
);
169 cmd
.type
= NOTIFICATION_COMMAND_TYPE_SESSION_ROTATION_ONGOING
;
170 cmd
.parameters
.session_rotation
.session_name
= session_name
;
171 cmd
.parameters
.session_rotation
.uid
= uid
;
172 cmd
.parameters
.session_rotation
.gid
= gid
;
173 cmd
.parameters
.session_rotation
.trace_archive_chunk_id
=
174 trace_archive_chunk_id
;
176 ret
= run_command_wait(handle
, &cmd
);
178 ret_code
= LTTNG_ERR_UNK
;
181 ret_code
= cmd
.reply_code
;
186 enum lttng_error_code
notification_thread_command_session_rotation_completed(
187 struct notification_thread_handle
*handle
,
188 const char *session_name
, uid_t uid
, gid_t gid
,
189 uint64_t trace_archive_chunk_id
,
190 struct lttng_trace_archive_location
*location
)
193 enum lttng_error_code ret_code
;
194 struct notification_thread_command cmd
;
196 init_notification_thread_command(&cmd
);
198 cmd
.type
= NOTIFICATION_COMMAND_TYPE_SESSION_ROTATION_COMPLETED
;
199 cmd
.parameters
.session_rotation
.session_name
= session_name
;
200 cmd
.parameters
.session_rotation
.uid
= uid
;
201 cmd
.parameters
.session_rotation
.gid
= gid
;
202 cmd
.parameters
.session_rotation
.trace_archive_chunk_id
=
203 trace_archive_chunk_id
;
204 cmd
.parameters
.session_rotation
.location
= location
;
206 ret
= run_command_wait(handle
, &cmd
);
208 ret_code
= LTTNG_ERR_UNK
;
211 ret_code
= cmd
.reply_code
;
216 void notification_thread_command_quit(
217 struct notification_thread_handle
*handle
)
220 struct notification_thread_command cmd
;
222 init_notification_thread_command(&cmd
);
224 cmd
.type
= NOTIFICATION_COMMAND_TYPE_QUIT
;
225 ret
= run_command_wait(handle
, &cmd
);
226 assert(!ret
&& cmd
.reply_code
== LTTNG_OK
);