Clean-up: sessiond: change space to tabs
[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 * SPDX-License-Identifier: GPL-2.0-only
6 *
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>
20 #include <common/credentials.h>
21 #include <sys/eventfd.h>
22 #include <sys/stat.h>
23 #include <time.h>
24 #include <signal.h>
25 #include <inttypes.h>
26
27 #include <lttng/notification/channel-internal.h>
28 #include <lttng/rotate-internal.h>
29
30 #include "session.h"
31 #include "rotate.h"
32 #include "rotation-thread.h"
33 #include "lttng-sessiond.h"
34 #include "health-sessiond.h"
35 #include "cmd.h"
36 #include "utils.h"
37 #include "notification-thread-commands.h"
38
39 #include <urcu.h>
40 #include <urcu/list.h>
41 #include <urcu/rculfhash.h>
42
43 int subscribe_session_consumed_size_rotation(struct ltt_session *session, uint64_t size,
44 struct notification_thread_handle *notification_thread_handle)
45 {
46 int ret;
47 enum lttng_condition_status condition_status;
48 enum lttng_notification_channel_status nc_status;
49 struct lttng_action *action;
50 const struct lttng_credentials session_creds = {
51 .uid = session->uid,
52 .gid = session->gid,
53 };
54
55 session->rotate_condition = lttng_condition_session_consumed_size_create();
56 if (!session->rotate_condition) {
57 ERR("Failed to create session consumed size condition object");
58 ret = -1;
59 goto end;
60 }
61
62 condition_status = lttng_condition_session_consumed_size_set_threshold(
63 session->rotate_condition, size);
64 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
65 ERR("Could not set session consumed size condition threshold (size = %" PRIu64 ")",
66 size);
67 ret = -1;
68 goto end;
69 }
70
71 condition_status =
72 lttng_condition_session_consumed_size_set_session_name(
73 session->rotate_condition, session->name);
74 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
75 ERR("Could not set session consumed size condition session name (name = %s)",
76 session->name);
77 ret = -1;
78 goto end;
79 }
80
81 action = lttng_action_notify_create();
82 if (!action) {
83 ERR("Could not create notify action");
84 ret = -1;
85 goto end;
86 }
87
88 session->rotate_trigger = lttng_trigger_create(session->rotate_condition,
89 action);
90 if (!session->rotate_trigger) {
91 ERR("Could not create size-based rotation trigger");
92 ret = -1;
93 goto end;
94 }
95
96 lttng_trigger_set_credentials(
97 session->rotate_trigger, &session_creds);
98
99 nc_status = lttng_notification_channel_subscribe(
100 rotate_notification_channel, session->rotate_condition);
101 if (nc_status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) {
102 ERR("Could not subscribe to session consumed size notification");
103 ret = -1;
104 goto end;
105 }
106
107 ret = notification_thread_command_register_trigger(
108 notification_thread_handle, session->rotate_trigger);
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 }
This page took 0.03158 seconds and 4 git commands to generate.