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"
29 * Return allocated channel attributes.
31 static struct lttng_channel
*init_default_attr(int dom
, char *name
)
33 struct lttng_channel
*chan
;
35 chan
= zmalloc(sizeof(struct lttng_channel
));
37 perror("malloc channel init");
41 if (snprintf(chan
->name
, sizeof(chan
->name
), "%s", name
) < 0) {
42 perror("snprintf channel name");
46 chan
->attr
.overwrite
= DEFAULT_CHANNEL_OVERWRITE
;
47 chan
->attr
.switch_timer_interval
= DEFAULT_CHANNEL_SWITCH_TIMER
;
48 chan
->attr
.read_timer_interval
= DEFAULT_CHANNEL_READ_TIMER
;
51 case LTTNG_DOMAIN_KERNEL
:
52 chan
->attr
.subbuf_size
= DEFAULT_KERNEL_CHANNEL_SUBBUF_SIZE
;
53 chan
->attr
.num_subbuf
= DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM
;
54 chan
->attr
.output
= DEFAULT_KERNEL_CHANNEL_OUTPUT
;
58 goto error
; /* Not implemented */
70 * Disable kernel channel of the kernel session.
72 int channel_kernel_disable(struct ltt_kernel_session
*ksession
,
76 struct ltt_kernel_channel
*kchan
;
78 kchan
= trace_kernel_get_channel_by_name(channel_name
, ksession
);
80 ret
= LTTCOMM_KERN_CHAN_NOT_FOUND
;
82 } else if (kchan
->enabled
== 1) {
83 ret
= kernel_disable_channel(kchan
);
86 ret
= LTTCOMM_KERN_CHAN_DISABLE_FAIL
;
99 * Enable kernel channel of the kernel session.
101 int channel_kernel_enable(struct ltt_kernel_session
*ksession
,
102 struct ltt_kernel_channel
*kchan
)
106 if (kchan
->enabled
== 0) {
107 ret
= kernel_enable_channel(kchan
);
109 ret
= LTTCOMM_KERN_CHAN_ENABLE_FAIL
;
121 * Create kernel channel of the kernel session and notify kernel thread.
123 int channel_kernel_create(struct ltt_kernel_session
*ksession
,
124 char *channel_name
, struct lttng_channel
*chan
, int kernel_pipe
)
127 struct lttng_channel
*attr
= chan
;
129 /* Creating channel attributes if needed */
131 attr
= init_default_attr(LTTNG_DOMAIN_KERNEL
, channel_name
);
138 /* Channel not found, creating it */
139 ret
= kernel_create_channel(ksession
, attr
, ksession
->trace_path
);
141 ret
= LTTCOMM_KERN_CHAN_FAIL
;
145 /* Notify kernel thread that there is a new channel */
146 ret
= notify_thread_pipe(kernel_pipe
);