2 * Copyright (C) 2017 - Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2018 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License, version 2 only, as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <lttng/trigger/trigger.h>
21 #include <common/error.h>
22 #include <common/config/session-config.h>
23 #include <common/defaults.h>
24 #include <common/utils.h>
25 #include <common/futex.h>
26 #include <common/align.h>
27 #include <common/time.h>
28 #include <common/hashtable/utils.h>
29 #include <common/kernel-ctl/kernel-ctl.h>
30 #include <sys/eventfd.h>
36 #include <lttng/notification/channel-internal.h>
37 #include <lttng/rotate-internal.h>
41 #include "rotation-thread.h"
42 #include "lttng-sessiond.h"
43 #include "health-sessiond.h"
46 #include "notification-thread-commands.h"
49 #include <urcu/list.h>
50 #include <urcu/rculfhash.h>
52 int subscribe_session_consumed_size_rotation(struct ltt_session
*session
, uint64_t size
,
53 struct notification_thread_handle
*notification_thread_handle
)
56 enum lttng_condition_status condition_status
;
57 enum lttng_notification_channel_status nc_status
;
58 struct lttng_action
*action
;
60 session
->rotate_condition
= lttng_condition_session_consumed_size_create();
61 if (!session
->rotate_condition
) {
62 ERR("Failed to create session consumed size condition object");
67 condition_status
= lttng_condition_session_consumed_size_set_threshold(
68 session
->rotate_condition
, size
);
69 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
70 ERR("Could not set session consumed size condition threshold (size = %" PRIu64
")",
77 lttng_condition_session_consumed_size_set_session_name(
78 session
->rotate_condition
, session
->name
);
79 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
80 ERR("Could not set session consumed size condition session name (name = %s)",
86 action
= lttng_action_notify_create();
88 ERR("Could not create notify action");
93 session
->rotate_trigger
= lttng_trigger_create(session
->rotate_condition
,
95 if (!session
->rotate_trigger
) {
96 ERR("Could not create size-based rotation trigger");
101 nc_status
= lttng_notification_channel_subscribe(
102 rotate_notification_channel
, session
->rotate_condition
);
103 if (nc_status
!= LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
) {
104 ERR("Could not subscribe to session consumed size notification");
109 ret
= notification_thread_command_register_trigger(
110 notification_thread_handle
, session
->rotate_trigger
);
111 if (ret
< 0 && ret
!= -LTTNG_ERR_TRIGGER_EXISTS
) {
112 ERR("Register trigger, %s", lttng_strerror(ret
));
123 int unsubscribe_session_consumed_size_rotation(struct ltt_session
*session
,
124 struct notification_thread_handle
*notification_thread_handle
)
127 enum lttng_notification_channel_status status
;
129 status
= lttng_notification_channel_unsubscribe(
130 rotate_notification_channel
,
131 session
->rotate_condition
);
132 if (status
!= LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
) {
133 ERR("Session unsubscribe error: %d", (int) status
);
138 ret
= notification_thread_command_unregister_trigger(
139 notification_thread_handle
, session
->rotate_trigger
);
140 if (ret
!= LTTNG_OK
) {
141 ERR("Session unregister trigger error: %d", ret
);