2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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.
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
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.
22 #include <lttng/lttng.h>
23 #include <lttng-sessiond-comm.h>
27 #include "hashtable.h"
34 * Return allocated channel attributes.
36 struct lttng_channel
*channel_new_default_attr(int dom
)
38 struct lttng_channel
*chan
;
40 chan
= zmalloc(sizeof(struct lttng_channel
));
42 PERROR("zmalloc channel init");
46 if (snprintf(chan
->name
, sizeof(chan
->name
), "%s",
47 DEFAULT_CHANNEL_NAME
) < 0) {
48 PERROR("snprintf default channel name");
52 chan
->attr
.overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
53 chan
->attr
.switch_timer_interval
= DEFAULT_CHANNEL_SWITCH_TIMER
;
54 chan
->attr
.read_timer_interval
= DEFAULT_CHANNEL_READ_TIMER
;
57 case LTTNG_DOMAIN_KERNEL
:
58 chan
->attr
.subbuf_size
= DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE
;
59 chan
->attr
.num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
60 chan
->attr
.output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
62 case LTTNG_DOMAIN_UST
:
63 case LTTNG_DOMAIN_UST_PID
:
64 chan
->attr
.subbuf_size
= DEFAULT_UST_CHANNEL_SUBBUF_SIZE
;
65 chan
->attr
.num_subbuf
= DEFAULT_UST_CHANNEL_SUBBUF_NUM
;
66 chan
->attr
.output
= DEFAULT_UST_CHANNEL_OUTPUT
;
69 goto error
; /* Not implemented */
81 * Disable kernel channel of the kernel session.
83 int channel_kernel_disable(struct ltt_kernel_session
*ksession
,
87 struct ltt_kernel_channel
*kchan
;
89 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksession
);
91 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
93 } else if (kchan
->enabled
== 1) {
94 ret
= kernel_disable_channel(kchan
);
95 if (ret
< 0 && ret
!= -EEXIST
) {
96 ret
= LTTCOMM_KERN_CHAN_DISABLE_FAIL
;
108 * Enable kernel channel of the kernel session.
110 int channel_kernel_enable(struct ltt_kernel_session
*ksession
,
111 struct ltt_kernel_channel
*kchan
)
115 if (kchan
->enabled
== 0) {
116 ret
= kernel_enable_channel(kchan
);
118 ret
= LTTCOMM_KERN_CHAN_ENABLE_FAIL
;
130 * Create kernel channel of the kernel session and notify kernel thread.
132 int channel_kernel_create(struct ltt_kernel_session
*ksession
,
133 struct lttng_channel
*attr
, int kernel_pipe
)
136 struct lttng_channel
*defattr
= NULL
;
138 /* Creating channel attributes if needed */
140 defattr
= channel_new_default_attr(LTTNG_DOMAIN_KERNEL
);
141 if (defattr
== NULL
) {
148 /* Channel not found, creating it */
149 ret
= kernel_create_channel(ksession
, attr
, ksession
->trace_path
);
151 ret
= LTTCOMM_KERN_CHAN_FAIL
;
155 /* Notify kernel thread that there is a new channel */
156 ret
= notify_thread_pipe(kernel_pipe
);
169 * Enable UST channel for session and domain.
171 int channel_ust_enable(struct ltt_ust_session
*usess
, int domain
,
172 struct ltt_ust_channel
*uchan
)
174 int ret
= LTTCOMM_OK
;
176 /* If already enabled, everything is OK */
177 if (uchan
->enabled
) {
178 DBG3("Channel %s already enabled. Skipping", uchan
->name
);
183 case LTTNG_DOMAIN_UST
:
184 DBG2("Channel %s being enabled in UST global domain", uchan
->name
);
185 /* Enable channel for global domain */
186 ret
= ust_app_enable_channel_glb(usess
, uchan
);
188 case LTTNG_DOMAIN_UST_PID
:
189 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
190 case LTTNG_DOMAIN_UST_EXEC_NAME
:
191 ret
= LTTCOMM_NOT_IMPLEMENTED
;
196 if (ret
!= -EEXIST
) {
197 ret
= LTTCOMM_UST_CHAN_ENABLE_FAIL
;
205 DBG2("Channel %s enabled successfully", uchan
->name
);
213 * Create UST channel for session and domain.
215 int channel_ust_create(struct ltt_ust_session
*usess
, int domain
,
216 struct lttng_channel
*attr
)
218 int ret
= LTTCOMM_OK
;
219 struct cds_lfht
*chan_ht
;
220 struct ltt_ust_channel
*uchan
= NULL
;
221 struct lttng_channel
*defattr
= NULL
;
223 /* Creating channel attributes if needed */
225 defattr
= channel_new_default_attr(domain
);
226 if (defattr
== NULL
) {
233 /* Create UST channel */
234 uchan
= trace_ust_create_channel(attr
, usess
->pathname
);
241 case LTTNG_DOMAIN_UST
:
242 DBG2("Channel %s being created in UST global domain", uchan
->name
);
243 chan_ht
= usess
->domain_global
.channels
;
245 /* Enable channel for global domain */
246 ret
= ust_app_create_channel_glb(usess
, uchan
);
248 case LTTNG_DOMAIN_UST_PID
:
249 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
250 case LTTNG_DOMAIN_UST_EXEC_NAME
:
252 ret
= LTTCOMM_NOT_IMPLEMENTED
;
253 goto error_free_chan
;
256 if (ret
< 0 && ret
!= -EEXIST
) {
257 ret
= LTTCOMM_UST_CHAN_ENABLE_FAIL
;
258 goto error_free_chan
;
262 hashtable_add_unique(chan_ht
, &uchan
->node
);
263 DBG2("Channel %s created successfully", uchan
->name
);
269 trace_ust_destroy_channel(uchan
);
276 * Disable UST channel for session and domain.
278 int channel_ust_disable(struct ltt_ust_session
*usess
, int domain
,
279 struct ltt_ust_channel
*uchan
)
281 int ret
= LTTCOMM_OK
;
283 /* Already disabled */
284 if (uchan
->enabled
== 0) {
285 DBG2("Channel UST %s already disabled", uchan
->name
);
289 /* Get the right channel's hashtable */
291 case LTTNG_DOMAIN_UST
:
292 DBG2("Channel %s being disabled in UST global domain", uchan
->name
);
293 /* Disable channel for global domain */
294 ret
= ust_app_disable_channel_glb(usess
, uchan
);
296 case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN
:
297 case LTTNG_DOMAIN_UST_EXEC_NAME
:
298 case LTTNG_DOMAIN_UST_PID
:
299 ret
= LTTCOMM_NOT_IMPLEMENTED
;
303 if (ret
< 0 && ret
!= -EEXIST
) {
304 ret
= LTTCOMM_UST_DISABLE_FAIL
;
310 DBG2("Channel %s disabled successfully", uchan
->name
);