Fix: tests: update rotation ust number of tests
[lttng-tools.git] / src / bin / lttng-sessiond / rotate.c
1 /*
2 * Copyright (C) 2017 - Julien Desfossez <jdesfossez@efficios.com>
3 * Copyright (C) 2018 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
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.
8 *
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
12 * more details.
13 *
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.
17 */
18
19 #define _LGPL_SOURCE
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>
31 #include <sys/stat.h>
32 #include <time.h>
33 #include <signal.h>
34 #include <inttypes.h>
35
36 #include <lttng/notification/channel-internal.h>
37 #include <lttng/rotate-internal.h>
38
39 #include "session.h"
40 #include "rotate.h"
41 #include "rotation-thread.h"
42 #include "lttng-sessiond.h"
43 #include "health-sessiond.h"
44 #include "cmd.h"
45 #include "utils.h"
46 #include "notification-thread-commands.h"
47
48 #include <urcu.h>
49 #include <urcu/list.h>
50 #include <urcu/rculfhash.h>
51
52 int subscribe_session_consumed_size_rotation(struct ltt_session *session, uint64_t size,
53 struct notification_thread_handle *notification_thread_handle)
54 {
55 int ret;
56 enum lttng_condition_status condition_status;
57 enum lttng_notification_channel_status nc_status;
58 struct lttng_action *action;
59
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");
63 ret = -1;
64 goto end;
65 }
66
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 ")",
71 size);
72 ret = -1;
73 goto end;
74 }
75
76 condition_status =
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)",
81 session->name);
82 ret = -1;
83 goto end;
84 }
85
86 action = lttng_action_notify_create();
87 if (!action) {
88 ERR("Could not create notify action");
89 ret = -1;
90 goto end;
91 }
92
93 session->rotate_trigger = lttng_trigger_create(session->rotate_condition,
94 action);
95 if (!session->rotate_trigger) {
96 ERR("Could not create size-based rotation trigger");
97 ret = -1;
98 goto end;
99 }
100
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");
105 ret = -1;
106 goto end;
107 }
108
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));
113 ret = -1;
114 goto end;
115 }
116
117 ret = 0;
118
119 end:
120 return ret;
121 }
122
123 int unsubscribe_session_consumed_size_rotation(struct ltt_session *session,
124 struct notification_thread_handle *notification_thread_handle)
125 {
126 int ret = 0;
127 enum lttng_notification_channel_status status;
128
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);
134 ret = -1;
135 goto end;
136 }
137
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);
142 goto end;
143 }
144
145 ret = 0;
146 end:
147 return ret;
148 }
This page took 0.034039 seconds and 4 git commands to generate.