Add kernel and UST time namespace context
[lttng-tools.git] / src / bin / lttng-sessiond / rotate.c
CommitLineData
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>
20#include <sys/eventfd.h>
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
42int 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;
49
50 session->rotate_condition = lttng_condition_session_consumed_size_create();
51 if (!session->rotate_condition) {
52 ERR("Failed to create session consumed size condition object");
53 ret = -1;
54 goto end;
55 }
56
57 condition_status = lttng_condition_session_consumed_size_set_threshold(
58 session->rotate_condition, size);
59 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
60 ERR("Could not set session consumed size condition threshold (size = %" PRIu64 ")",
61 size);
62 ret = -1;
63 goto end;
64 }
65
66 condition_status =
67 lttng_condition_session_consumed_size_set_session_name(
68 session->rotate_condition, session->name);
69 if (condition_status != LTTNG_CONDITION_STATUS_OK) {
70 ERR("Could not set session consumed size condition session name (name = %s)",
71 session->name);
72 ret = -1;
73 goto end;
74 }
75
76 action = lttng_action_notify_create();
77 if (!action) {
78 ERR("Could not create notify action");
79 ret = -1;
80 goto end;
81 }
82
83 session->rotate_trigger = lttng_trigger_create(session->rotate_condition,
84 action);
85 if (!session->rotate_trigger) {
86 ERR("Could not create size-based rotation trigger");
87 ret = -1;
88 goto end;
89 }
90
91 nc_status = lttng_notification_channel_subscribe(
92 rotate_notification_channel, session->rotate_condition);
93 if (nc_status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) {
94 ERR("Could not subscribe to session consumed size notification");
95 ret = -1;
96 goto end;
97 }
98
99 ret = notification_thread_command_register_trigger(
100 notification_thread_handle, session->rotate_trigger);
101 if (ret < 0 && ret != -LTTNG_ERR_TRIGGER_EXISTS) {
102 ERR("Register trigger, %s", lttng_strerror(ret));
103 ret = -1;
104 goto end;
105 }
106
107 ret = 0;
108
109end:
110 return ret;
111}
112
113int unsubscribe_session_consumed_size_rotation(struct ltt_session *session,
114 struct notification_thread_handle *notification_thread_handle)
115{
116 int ret = 0;
117 enum lttng_notification_channel_status status;
118
119 status = lttng_notification_channel_unsubscribe(
120 rotate_notification_channel,
121 session->rotate_condition);
122 if (status != LTTNG_NOTIFICATION_CHANNEL_STATUS_OK) {
123 ERR("Session unsubscribe error: %d", (int) status);
124 ret = -1;
125 goto end;
126 }
127
128 ret = notification_thread_command_unregister_trigger(
129 notification_thread_handle, session->rotate_trigger);
130 if (ret != LTTNG_OK) {
131 ERR("Session unregister trigger error: %d", ret);
132 goto end;
133 }
134
135 ret = 0;
136end:
137 return ret;
138}
This page took 0.043334 seconds and 4 git commands to generate.