2 * Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: GPL-2.0-only
10 #include <lttng/trigger/trigger.h>
11 #include <common/error.hpp>
12 #include <common/config/session-config.hpp>
13 #include <common/defaults.hpp>
14 #include <common/utils.hpp>
15 #include <common/futex.hpp>
16 #include <common/align.hpp>
17 #include <common/time.hpp>
18 #include <common/hashtable/utils.hpp>
19 #include <common/kernel-ctl/kernel-ctl.hpp>
20 #include <common/credentials.hpp>
26 #include <lttng/notification/channel-internal.hpp>
27 #include <lttng/rotate-internal.hpp>
29 #include "session.hpp"
31 #include "rotation-thread.hpp"
32 #include "lttng-sessiond.hpp"
33 #include "health-sessiond.hpp"
36 #include "notification-thread-commands.hpp"
39 #include <urcu/list.h>
40 #include <urcu/rculfhash.h>
42 int subscribe_session_consumed_size_rotation(struct ltt_session
*session
, uint64_t size
,
43 struct notification_thread_handle
*notification_thread_handle
)
46 enum lttng_condition_status condition_status
;
47 enum lttng_notification_channel_status nc_status
;
48 struct lttng_action
*action
;
49 const struct lttng_credentials session_creds
= {
50 .uid
= LTTNG_OPTIONAL_INIT_VALUE(session
->uid
),
51 .gid
= LTTNG_OPTIONAL_INIT_VALUE(session
->gid
),
54 session
->rotate_condition
= lttng_condition_session_consumed_size_create();
55 if (!session
->rotate_condition
) {
56 ERR("Failed to create session consumed size condition object");
61 condition_status
= lttng_condition_session_consumed_size_set_threshold(
62 session
->rotate_condition
, size
);
63 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
64 ERR("Could not set session consumed size condition threshold (size = %" PRIu64
")",
71 lttng_condition_session_consumed_size_set_session_name(
72 session
->rotate_condition
, session
->name
);
73 if (condition_status
!= LTTNG_CONDITION_STATUS_OK
) {
74 ERR("Could not set session consumed size condition session name (name = %s)",
80 action
= lttng_action_notify_create();
82 ERR("Could not create notify action");
87 session
->rotate_trigger
= lttng_trigger_create(session
->rotate_condition
,
89 if (!session
->rotate_trigger
) {
90 ERR("Could not create size-based rotation trigger");
95 /* Ensure this trigger is not visible to external users. */
96 lttng_trigger_set_hidden(session
->rotate_trigger
);
97 lttng_trigger_set_credentials(
98 session
->rotate_trigger
, &session_creds
);
100 nc_status
= lttng_notification_channel_subscribe(
101 rotate_notification_channel
, session
->rotate_condition
);
102 if (nc_status
!= LTTNG_NOTIFICATION_CHANNEL_STATUS_OK
) {
103 ERR("Could not subscribe to session consumed size notification");
108 ret
= notification_thread_command_register_trigger(
109 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
);