Add enable channel support for UST
[lttng-tools.git] / ltt-sessiond / channel.c
CommitLineData
54d01ffb
DG
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; only version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18#include <unistd.h>
19
20#include <lttng/lttng.h>
21#include <lttng-sessiond-comm.h>
22#include <lttngerr.h>
23
24#include "channel.h"
25#include "kernel-ctl.h"
44d3bd01 26#include "ust-ctl.h"
54d01ffb
DG
27#include "utils.h"
28
29/*
30 * Return allocated channel attributes.
31 */
44d3bd01 32static struct lttng_channel *init_default_attr(int dom)
54d01ffb
DG
33{
34 struct lttng_channel *chan;
35
36 chan = zmalloc(sizeof(struct lttng_channel));
37 if (chan == NULL) {
38 perror("malloc channel init");
39 goto error_alloc;
40 }
41
44d3bd01
DG
42 if (snprintf(chan->name, sizeof(chan->name), "%s",
43 DEFAULT_CHANNEL_NAME) < 0) {
44 perror("snprintf default channel name");
54d01ffb
DG
45 goto error;
46 }
47
48 chan->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE;
49 chan->attr.switch_timer_interval = DEFAULT_CHANNEL_SWITCH_TIMER;
50 chan->attr.read_timer_interval = DEFAULT_CHANNEL_READ_TIMER;
51
52 switch (dom) {
53 case LTTNG_DOMAIN_KERNEL:
54 chan->attr.subbuf_size = DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE;
55 chan->attr.num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM;
56 chan->attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT;
57 break;
44d3bd01
DG
58 case LTTNG_DOMAIN_UST_PID:
59 chan->attr.subbuf_size = DEFAULT_UST_CHANNEL_SUBBUF_SIZE;
60 chan->attr.num_subbuf = DEFAULT_UST_CHANNEL_SUBBUF_NUM;
61 chan->attr.output = DEFAULT_UST_CHANNEL_OUTPUT;
62 break;
54d01ffb
DG
63 default:
64 goto error; /* Not implemented */
65 }
66
67 return chan;
68
69error:
70 free(chan);
71error_alloc:
72 return NULL;
73}
74
75/*
76 * Disable kernel channel of the kernel session.
77 */
78int channel_kernel_disable(struct ltt_kernel_session *ksession,
79 char *channel_name)
80{
81 int ret;
82 struct ltt_kernel_channel *kchan;
83
84 kchan = trace_kernel_get_channel_by_name(channel_name, ksession);
85 if (kchan == NULL) {
86 ret = LTTCOMM_KERN_CHAN_NOT_FOUND;
87 goto error;
88 } else if (kchan->enabled == 1) {
89 ret = kernel_disable_channel(kchan);
90 if (ret < 0) {
91 if (ret != EEXIST) {
92 ret = LTTCOMM_KERN_CHAN_DISABLE_FAIL;
93 }
94 goto error;
95 }
96 }
97
98 ret = LTTCOMM_OK;
99
100error:
101 return ret;
102}
103
104/*
105 * Enable kernel channel of the kernel session.
106 */
107int channel_kernel_enable(struct ltt_kernel_session *ksession,
108 struct ltt_kernel_channel *kchan)
109{
110 int ret;
111
112 if (kchan->enabled == 0) {
113 ret = kernel_enable_channel(kchan);
114 if (ret < 0) {
115 ret = LTTCOMM_KERN_CHAN_ENABLE_FAIL;
116 goto error;
117 }
118 }
119
120 ret = LTTCOMM_OK;
121
122error:
123 return ret;
124}
125
126/*
127 * Create kernel channel of the kernel session and notify kernel thread.
128 */
129int channel_kernel_create(struct ltt_kernel_session *ksession,
44d3bd01 130 struct lttng_channel *chan, int kernel_pipe)
54d01ffb
DG
131{
132 int ret;
133 struct lttng_channel *attr = chan;
134
135 /* Creating channel attributes if needed */
136 if (attr == NULL) {
44d3bd01 137 attr = init_default_attr(LTTNG_DOMAIN_KERNEL);
54d01ffb
DG
138 if (attr == NULL) {
139 ret = LTTCOMM_FATAL;
140 goto error;
141 }
142 }
143
144 /* Channel not found, creating it */
145 ret = kernel_create_channel(ksession, attr, ksession->trace_path);
146 if (ret < 0) {
147 ret = LTTCOMM_KERN_CHAN_FAIL;
148 goto error;
149 }
150
151 /* Notify kernel thread that there is a new channel */
152 ret = notify_thread_pipe(kernel_pipe);
153 if (ret < 0) {
154 ret = LTTCOMM_FATAL;
155 goto error;
156 }
157
158 ret = LTTCOMM_OK;
159
160error:
161 return ret;
162}
44d3bd01
DG
163
164/*
165 * Create UST channel and enable it on the tracer.
166 */
167int channel_ust_create(struct ltt_ust_session *usession,
168 struct lttng_channel *chan, int sock)
169{
170 int ret;
171 struct lttng_channel *attr = chan;
172
173 /* Creating channel attributes if needed */
174 if (attr == NULL) {
175 attr = init_default_attr(LTTNG_DOMAIN_UST_PID);
176 if (attr == NULL) {
177 ret = LTTCOMM_FATAL;
178 goto error;
179 }
180 }
181
182 ret = ustctl_create_channel(sock, usession, attr);
183 if (ret < 0) {
184 ret = LTTCOMM_UST_CHAN_FAIL;
185 goto error;
186 }
187
188 DBG2("Channel %s UST create successfully for sock:%d", attr->name, sock);
189
190 ret = LTTCOMM_OK;
191
192error:
193 return ret;
194}
195
196/*
197 * Enable UST channel on the tracer.
198 */
199int channel_ust_enable(struct ltt_ust_session *usession,
200 struct ltt_ust_channel *uchan, int sock)
201{
202 int ret;
203 ret = LTTCOMM_OK;
204
205 ret = ustctl_enable_channel(sock, usession, uchan);
206 if (ret < 0) {
207 ret = LTTCOMM_UST_CHAN_FAIL;
208 goto error;
209 }
210
211 ret = LTTCOMM_OK;
212
213error:
214 return ret;
215}
216
217/*
218 * Disable UST channel on the tracer.
219 */
220int channel_ust_disable(struct ltt_ust_session *usession,
221 struct ltt_ust_channel *uchan, int sock)
222{
223 int ret;
224 ret = LTTCOMM_OK;
225
226 ret = ustctl_disable_channel(sock, usession, uchan);
227 if (ret < 0) {
228 ret = LTTCOMM_UST_CHAN_FAIL;
229 goto error;
230 }
231
232 ret = LTTCOMM_OK;
233
234error:
235 return ret;
236}
This page took 0.031246 seconds and 4 git commands to generate.