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.
20 #include <lttng/lttng.h>
21 #include <lttng-sessiond-comm.h>
25 #include "kernel-ctl.h"
30 * Return allocated channel attributes.
32 static struct lttng_channel
*init_default_attr(int dom
)
34 struct lttng_channel
*chan
;
36 chan
= zmalloc(sizeof(struct lttng_channel
));
38 perror("malloc channel init");
42 if (snprintf(chan
->name
, sizeof(chan
->name
), "%s",
43 DEFAULT_CHANNEL_NAME
) < 0) {
44 perror("snprintf default channel name");
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
;
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
;
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
;
64 goto error
; /* Not implemented */
76 * Disable kernel channel of the kernel session.
78 int channel_kernel_disable(struct ltt_kernel_session
*ksession
,
82 struct ltt_kernel_channel
*kchan
;
84 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksession
);
86 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
88 } else if (kchan
->enabled
== 1) {
89 ret
= kernel_disable_channel(kchan
);
92 ret
= LTTCOMM_KERN_CHAN_DISABLE_FAIL
;
105 * Enable kernel channel of the kernel session.
107 int channel_kernel_enable(struct ltt_kernel_session
*ksession
,
108 struct ltt_kernel_channel
*kchan
)
112 if (kchan
->enabled
== 0) {
113 ret
= kernel_enable_channel(kchan
);
115 ret
= LTTCOMM_KERN_CHAN_ENABLE_FAIL
;
127 * Create kernel channel of the kernel session and notify kernel thread.
129 int channel_kernel_create(struct ltt_kernel_session
*ksession
,
130 struct lttng_channel
*chan
, int kernel_pipe
)
133 struct lttng_channel
*attr
= chan
;
135 /* Creating channel attributes if needed */
137 attr
= init_default_attr(LTTNG_DOMAIN_KERNEL
);
144 /* Channel not found, creating it */
145 ret
= kernel_create_channel(ksession
, attr
, ksession
->trace_path
);
147 ret
= LTTCOMM_KERN_CHAN_FAIL
;
151 /* Notify kernel thread that there is a new channel */
152 ret
= notify_thread_pipe(kernel_pipe
);
165 * Create UST channel and enable it on the tracer.
167 int channel_ust_create(struct ltt_ust_session
*usession
,
168 struct lttng_channel
*chan
, int sock
)
171 struct lttng_channel
*attr
= chan
;
173 /* Creating channel attributes if needed */
175 attr
= init_default_attr(LTTNG_DOMAIN_UST_PID
);
182 ret
= ustctl_create_channel(sock
, usession
, attr
);
184 ret
= LTTCOMM_UST_CHAN_FAIL
;
188 DBG2("Channel %s UST create successfully for sock:%d", attr
->name
, sock
);
197 * Enable UST channel on the tracer.
199 int channel_ust_enable(struct ltt_ust_session
*usession
,
200 struct ltt_ust_channel
*uchan
, int sock
)
205 ret
= ustctl_enable_channel(sock
, usession
, uchan
);
207 ret
= LTTCOMM_UST_CHAN_FAIL
;
218 * Disable UST channel on the tracer.
220 int channel_ust_disable(struct ltt_ust_session
*usession
,
221 struct ltt_ust_channel
*uchan
, int sock
)
226 ret
= ustctl_disable_channel(sock
, usession
, uchan
);
228 ret
= LTTCOMM_UST_CHAN_FAIL
;