Commit | Line | Data |
---|---|---|
db66e574 | 1 | /* |
ab5be9fa MJ |
2 | * Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com> |
3 | * Copyright (C) 2018 Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
db66e574 | 4 | * |
ab5be9fa | 5 | * SPDX-License-Identifier: GPL-2.0-only |
db66e574 | 6 | * |
db66e574 JD |
7 | */ |
8 | ||
9 | #define _LGPL_SOURCE | |
10 | #include <lttng/trigger/trigger.h> | |
11 | #include <common/error.h> | |
12 | #include <common/config/session-config.h> | |
13 | #include <common/defaults.h> | |
14 | #include <common/utils.h> | |
15 | #include <common/futex.h> | |
16 | #include <common/align.h> | |
17 | #include <common/time.h> | |
18 | #include <common/hashtable/utils.h> | |
19 | #include <common/kernel-ctl/kernel-ctl.h> | |
3da864a9 | 20 | #include <common/credentials.h> |
db66e574 JD |
21 | #include <sys/stat.h> |
22 | #include <time.h> | |
23 | #include <signal.h> | |
24 | #include <inttypes.h> | |
25 | ||
90936dcf | 26 | #include <lttng/notification/channel-internal.h> |
d88744a4 JD |
27 | #include <lttng/rotate-internal.h> |
28 | ||
db66e574 JD |
29 | #include "session.h" |
30 | #include "rotate.h" | |
31 | #include "rotation-thread.h" | |
32 | #include "lttng-sessiond.h" | |
33 | #include "health-sessiond.h" | |
34 | #include "cmd.h" | |
35 | #include "utils.h" | |
90936dcf | 36 | #include "notification-thread-commands.h" |
db66e574 JD |
37 | |
38 | #include <urcu.h> | |
39 | #include <urcu/list.h> | |
40 | #include <urcu/rculfhash.h> | |
41 | ||
90936dcf JD |
42 | int subscribe_session_consumed_size_rotation(struct ltt_session *session, uint64_t size, |
43 | struct notification_thread_handle *notification_thread_handle) | |
44 | { | |
45 | int ret; | |
46 | enum lttng_condition_status condition_status; | |
47 | enum lttng_notification_channel_status nc_status; | |
48 | struct lttng_action *action; | |
3da864a9 | 49 | const struct lttng_credentials session_creds = { |
ff588497 JR |
50 | .uid = LTTNG_OPTIONAL_INIT_VALUE(session->uid), |
51 | .gid = LTTNG_OPTIONAL_INIT_VALUE(session->gid), | |
3da864a9 | 52 | }; |
90936dcf JD |
53 | |
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"); | |
57 | ret = -1; | |
58 | goto end; | |
59 | } | |
60 | ||
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 ")", | |
65 | size); | |
66 | ret = -1; | |
67 | goto end; | |
68 | } | |
69 | ||
70 | condition_status = | |
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)", | |
75 | session->name); | |
76 | ret = -1; | |
77 | goto end; | |
78 | } | |
79 | ||
80 | action = lttng_action_notify_create(); | |
81 | if (!action) { | |
82 | ERR("Could not create notify action"); | |
83 | ret = -1; | |
84 | goto end; | |
85 | } | |
86 | ||
87 | session->rotate_trigger = lttng_trigger_create(session->rotate_condition, | |
88 | action); | |
89 | if (!session->rotate_trigger) { | |
90 | ERR("Could not create size-based rotation trigger"); | |
91 | ret = -1; | |
92 | goto end; | |
93 | } | |
94 | ||
3da864a9 JR |
95 | lttng_trigger_set_credentials( |
96 | session->rotate_trigger, &session_creds); | |
97 | ||
90936dcf JD |
98 | nc_status = lttng_notification_channel_subscribe( |
99 | rotate_notification_channel, session->rotate_condition); | |
100 | if (nc_status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { | |
101 | ERR("Could not subscribe to session consumed size notification"); | |
102 | ret = -1; | |
103 | goto end; | |
104 | } | |
105 | ||
106 | ret = notification_thread_command_register_trigger( | |
0efb2ad7 JG |
107 | notification_thread_handle, session->rotate_trigger, |
108 | true); | |
90936dcf JD |
109 | if (ret < 0 && ret != -LTTNG_ERR_TRIGGER_EXISTS) { |
110 | ERR("Register trigger, %s", lttng_strerror(ret)); | |
111 | ret = -1; | |
112 | goto end; | |
113 | } | |
114 | ||
115 | ret = 0; | |
116 | ||
117 | end: | |
118 | return ret; | |
119 | } | |
120 | ||
121 | int unsubscribe_session_consumed_size_rotation(struct ltt_session *session, | |
122 | struct notification_thread_handle *notification_thread_handle) | |
123 | { | |
124 | int ret = 0; | |
125 | enum lttng_notification_channel_status status; | |
126 | ||
127 | status = lttng_notification_channel_unsubscribe( | |
128 | rotate_notification_channel, | |
129 | session->rotate_condition); | |
130 | if (status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) { | |
131 | ERR("Session unsubscribe error: %d", (int) status); | |
132 | ret = -1; | |
133 | goto end; | |
134 | } | |
135 | ||
136 | ret = notification_thread_command_unregister_trigger( | |
137 | notification_thread_handle, session->rotate_trigger); | |
138 | if (ret != LTTNG_OK) { | |
139 | ERR("Session unregister trigger error: %d", ret); | |
140 | goto end; | |
141 | } | |
142 | ||
143 | ret = 0; | |
144 | end: | |
145 | return ret; | |
146 | } |