Commit | Line | Data |
---|---|---|
54d01ffb DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
bdf64013 | 3 | * Copyright (C) 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com> |
54d01ffb | 4 | * |
d14d33bf AM |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License, version 2 only, | |
7 | * as published by the Free Software Foundation. | |
54d01ffb | 8 | * |
d14d33bf AM |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
54d01ffb | 13 | * |
d14d33bf AM |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
54d01ffb DG |
17 | */ |
18 | ||
6c1c0768 | 19 | #define _LGPL_SOURCE |
7972aab2 | 20 | #include <inttypes.h> |
56fff090 | 21 | #include <string.h> |
54d01ffb DG |
22 | #include <unistd.h> |
23 | ||
990570ed DG |
24 | #include <common/common.h> |
25 | #include <common/defaults.h> | |
db758600 | 26 | #include <common/sessiond-comm/sessiond-comm.h> |
54d01ffb DG |
27 | |
28 | #include "channel.h" | |
12744796 | 29 | #include "lttng-sessiond.h" |
4771f025 | 30 | #include "kernel.h" |
c57c2c74 JG |
31 | #include "lttng-ust-ctl.h" |
32 | #include "lttng-ust-error.h" | |
54d01ffb | 33 | #include "utils.h" |
7885e399 | 34 | #include "ust-app.h" |
b63d638b | 35 | #include "agent.h" |
54d01ffb DG |
36 | |
37 | /* | |
38 | * Return allocated channel attributes. | |
39 | */ | |
0a9c6494 DG |
40 | struct lttng_channel *channel_new_default_attr(int dom, |
41 | enum lttng_buffer_type type) | |
54d01ffb DG |
42 | { |
43 | struct lttng_channel *chan; | |
bdf64013 | 44 | const char *channel_name = DEFAULT_CHANNEL_NAME; |
e9404c27 | 45 | struct lttng_channel_extended *extended_attr = NULL; |
54d01ffb DG |
46 | |
47 | chan = zmalloc(sizeof(struct lttng_channel)); | |
48 | if (chan == NULL) { | |
7885e399 | 49 | PERROR("zmalloc channel init"); |
54d01ffb DG |
50 | goto error_alloc; |
51 | } | |
52 | ||
e9404c27 JG |
53 | extended_attr = zmalloc(sizeof(struct lttng_channel_extended)); |
54 | if (!extended_attr) { | |
55 | PERROR("zmalloc channel extended init"); | |
56 | goto error; | |
57 | } | |
58 | ||
59 | chan->attr.extended.ptr = extended_attr; | |
60 | ||
0a9c6494 | 61 | /* Same for all domains. */ |
54d01ffb | 62 | chan->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE; |
0a9c6494 DG |
63 | chan->attr.tracefile_size = DEFAULT_CHANNEL_TRACEFILE_SIZE; |
64 | chan->attr.tracefile_count = DEFAULT_CHANNEL_TRACEFILE_COUNT; | |
54d01ffb DG |
65 | |
66 | switch (dom) { | |
1b1c65fa | 67 | case LTTNG_DOMAIN_KERNEL: |
0a9c6494 | 68 | assert(type == LTTNG_BUFFER_GLOBAL); |
3e230f92 SM |
69 | chan->attr.subbuf_size = |
70 | default_get_kernel_channel_subbuf_size(); | |
1b1c65fa MD |
71 | chan->attr.num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM; |
72 | chan->attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT; | |
6bb9e85f MD |
73 | chan->attr.switch_timer_interval = DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER; |
74 | chan->attr.read_timer_interval = DEFAULT_KERNEL_CHANNEL_READ_TIMER; | |
ecc48a90 | 75 | chan->attr.live_timer_interval = DEFAULT_KERNEL_CHANNEL_LIVE_TIMER; |
f515d318 | 76 | extended_attr->blocking_timeout = DEFAULT_KERNEL_CHANNEL_BLOCKING_TIMEOUT; |
e9404c27 JG |
77 | extended_attr->monitor_timer_interval = |
78 | DEFAULT_KERNEL_CHANNEL_MONITOR_TIMER; | |
1b1c65fa | 79 | break; |
bdf64013 JG |
80 | case LTTNG_DOMAIN_JUL: |
81 | channel_name = DEFAULT_JUL_CHANNEL_NAME; | |
82 | goto common_ust; | |
83 | case LTTNG_DOMAIN_LOG4J: | |
84 | channel_name = DEFAULT_LOG4J_CHANNEL_NAME; | |
85 | goto common_ust; | |
86 | case LTTNG_DOMAIN_PYTHON: | |
87 | channel_name = DEFAULT_PYTHON_CHANNEL_NAME; | |
88 | goto common_ust; | |
1b1c65fa | 89 | case LTTNG_DOMAIN_UST: |
bdf64013 | 90 | common_ust: |
0a9c6494 DG |
91 | switch (type) { |
92 | case LTTNG_BUFFER_PER_UID: | |
93 | chan->attr.subbuf_size = default_get_ust_uid_channel_subbuf_size(); | |
94 | chan->attr.num_subbuf = DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM; | |
95 | chan->attr.output = DEFAULT_UST_UID_CHANNEL_OUTPUT; | |
96 | chan->attr.switch_timer_interval = | |
97 | DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER; | |
98 | chan->attr.read_timer_interval = | |
99 | DEFAULT_UST_UID_CHANNEL_READ_TIMER; | |
ecc48a90 JD |
100 | chan->attr.live_timer_interval = |
101 | DEFAULT_UST_UID_CHANNEL_LIVE_TIMER; | |
f515d318 | 102 | extended_attr->blocking_timeout = DEFAULT_UST_UID_CHANNEL_BLOCKING_TIMEOUT; |
e9404c27 JG |
103 | extended_attr->monitor_timer_interval = |
104 | DEFAULT_UST_UID_CHANNEL_MONITOR_TIMER; | |
0a9c6494 DG |
105 | break; |
106 | case LTTNG_BUFFER_PER_PID: | |
107 | default: | |
108 | chan->attr.subbuf_size = default_get_ust_pid_channel_subbuf_size(); | |
109 | chan->attr.num_subbuf = DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM; | |
110 | chan->attr.output = DEFAULT_UST_PID_CHANNEL_OUTPUT; | |
111 | chan->attr.switch_timer_interval = | |
112 | DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER; | |
113 | chan->attr.read_timer_interval = | |
114 | DEFAULT_UST_PID_CHANNEL_READ_TIMER; | |
ecc48a90 | 115 | chan->attr.live_timer_interval = |
e9404c27 | 116 | DEFAULT_UST_PID_CHANNEL_LIVE_TIMER; |
f515d318 | 117 | extended_attr->blocking_timeout = DEFAULT_UST_PID_CHANNEL_BLOCKING_TIMEOUT; |
e9404c27 JG |
118 | extended_attr->monitor_timer_interval = |
119 | DEFAULT_UST_PID_CHANNEL_MONITOR_TIMER; | |
0a9c6494 DG |
120 | break; |
121 | } | |
1b1c65fa MD |
122 | break; |
123 | default: | |
124 | goto error; /* Not implemented */ | |
54d01ffb DG |
125 | } |
126 | ||
bdf64013 JG |
127 | if (snprintf(chan->name, sizeof(chan->name), "%s", |
128 | channel_name) < 0) { | |
129 | PERROR("snprintf default channel name"); | |
130 | goto error; | |
131 | } | |
54d01ffb DG |
132 | return chan; |
133 | ||
134 | error: | |
e9404c27 | 135 | free(extended_attr); |
54d01ffb DG |
136 | free(chan); |
137 | error_alloc: | |
138 | return NULL; | |
139 | } | |
140 | ||
e9404c27 JG |
141 | void channel_attr_destroy(struct lttng_channel *channel) |
142 | { | |
143 | if (!channel) { | |
144 | return; | |
145 | } | |
146 | free(channel->attr.extended.ptr); | |
147 | free(channel); | |
148 | } | |
149 | ||
54d01ffb DG |
150 | /* |
151 | * Disable kernel channel of the kernel session. | |
152 | */ | |
153 | int channel_kernel_disable(struct ltt_kernel_session *ksession, | |
154 | char *channel_name) | |
155 | { | |
156 | int ret; | |
157 | struct ltt_kernel_channel *kchan; | |
158 | ||
0525e9ae DG |
159 | assert(ksession); |
160 | assert(channel_name); | |
161 | ||
54d01ffb DG |
162 | kchan = trace_kernel_get_channel_by_name(channel_name, ksession); |
163 | if (kchan == NULL) { | |
f73fabfd | 164 | ret = LTTNG_ERR_KERN_CHAN_NOT_FOUND; |
54d01ffb | 165 | goto error; |
0525e9ae DG |
166 | } |
167 | ||
168 | /* Only if channel is enabled disable it. */ | |
169 | if (kchan->enabled == 1) { | |
54d01ffb | 170 | ret = kernel_disable_channel(kchan); |
7885e399 | 171 | if (ret < 0 && ret != -EEXIST) { |
f73fabfd | 172 | ret = LTTNG_ERR_KERN_CHAN_DISABLE_FAIL; |
54d01ffb DG |
173 | goto error; |
174 | } | |
175 | } | |
176 | ||
f73fabfd | 177 | ret = LTTNG_OK; |
54d01ffb DG |
178 | |
179 | error: | |
180 | return ret; | |
181 | } | |
182 | ||
183 | /* | |
184 | * Enable kernel channel of the kernel session. | |
185 | */ | |
186 | int channel_kernel_enable(struct ltt_kernel_session *ksession, | |
187 | struct ltt_kernel_channel *kchan) | |
188 | { | |
189 | int ret; | |
190 | ||
0525e9ae DG |
191 | assert(ksession); |
192 | assert(kchan); | |
193 | ||
54d01ffb DG |
194 | if (kchan->enabled == 0) { |
195 | ret = kernel_enable_channel(kchan); | |
196 | if (ret < 0) { | |
f73fabfd | 197 | ret = LTTNG_ERR_KERN_CHAN_ENABLE_FAIL; |
54d01ffb DG |
198 | goto error; |
199 | } | |
42224349 | 200 | } else { |
f73fabfd | 201 | ret = LTTNG_ERR_KERN_CHAN_EXIST; |
42224349 | 202 | goto error; |
54d01ffb DG |
203 | } |
204 | ||
f73fabfd | 205 | ret = LTTNG_OK; |
54d01ffb DG |
206 | |
207 | error: | |
208 | return ret; | |
209 | } | |
210 | ||
da9d9d9c MD |
211 | static int channel_validate(struct lttng_channel *attr) |
212 | { | |
213 | /* | |
214 | * The ringbuffer (both in user space and kernel) behaves badly | |
215 | * in overwrite mode and with less than 2 subbuffers so block it | |
216 | * right away and send back an invalid attribute error. | |
217 | */ | |
218 | if (attr->attr.overwrite && attr->attr.num_subbuf < 2) { | |
219 | return -1; | |
220 | } | |
221 | return 0; | |
222 | } | |
223 | ||
f515d318 MD |
224 | static int channel_validate_kernel(struct lttng_channel *attr) |
225 | { | |
226 | /* Kernel channels do not support blocking timeout. */ | |
227 | if (((struct lttng_channel_extended *)attr->attr.extended.ptr)->blocking_timeout) { | |
228 | return -1; | |
229 | } | |
230 | return 0; | |
231 | } | |
232 | ||
54d01ffb DG |
233 | /* |
234 | * Create kernel channel of the kernel session and notify kernel thread. | |
235 | */ | |
236 | int channel_kernel_create(struct ltt_kernel_session *ksession, | |
ff4d74e6 | 237 | struct lttng_channel *attr, int kernel_pipe) |
54d01ffb DG |
238 | { |
239 | int ret; | |
ff4d74e6 | 240 | struct lttng_channel *defattr = NULL; |
54d01ffb | 241 | |
0525e9ae DG |
242 | assert(ksession); |
243 | ||
54d01ffb DG |
244 | /* Creating channel attributes if needed */ |
245 | if (attr == NULL) { | |
0a9c6494 DG |
246 | defattr = channel_new_default_attr(LTTNG_DOMAIN_KERNEL, |
247 | LTTNG_BUFFER_GLOBAL); | |
ff4d74e6 | 248 | if (defattr == NULL) { |
f73fabfd | 249 | ret = LTTNG_ERR_FATAL; |
54d01ffb DG |
250 | goto error; |
251 | } | |
ff4d74e6 | 252 | attr = defattr; |
54d01ffb DG |
253 | } |
254 | ||
8d5841ea MD |
255 | /* |
256 | * Set the overwrite mode for this channel based on the session | |
257 | * type unless the client explicitly overrides the channel mode. | |
258 | */ | |
259 | if (attr->attr.overwrite == DEFAULT_CHANNEL_OVERWRITE) { | |
260 | attr->attr.overwrite = !!ksession->snapshot_mode; | |
261 | } | |
262 | ||
263 | /* Enforce mmap output for snapshot sessions. */ | |
27babd3a | 264 | if (ksession->snapshot_mode) { |
27babd3a DG |
265 | attr->attr.output = LTTNG_EVENT_MMAP; |
266 | } | |
267 | ||
da9d9d9c MD |
268 | /* Validate common channel properties. */ |
269 | if (channel_validate(attr) < 0) { | |
270 | ret = LTTNG_ERR_INVALID; | |
271 | goto error; | |
272 | } | |
273 | ||
f515d318 MD |
274 | if (channel_validate_kernel(attr) < 0) { |
275 | ret = LTTNG_ERR_INVALID; | |
276 | goto error; | |
277 | } | |
278 | ||
54d01ffb | 279 | /* Channel not found, creating it */ |
fdd9eb17 | 280 | ret = kernel_create_channel(ksession, attr); |
54d01ffb | 281 | if (ret < 0) { |
f73fabfd | 282 | ret = LTTNG_ERR_KERN_CHAN_FAIL; |
54d01ffb DG |
283 | goto error; |
284 | } | |
285 | ||
286 | /* Notify kernel thread that there is a new channel */ | |
287 | ret = notify_thread_pipe(kernel_pipe); | |
288 | if (ret < 0) { | |
f73fabfd | 289 | ret = LTTNG_ERR_FATAL; |
54d01ffb DG |
290 | goto error; |
291 | } | |
292 | ||
f73fabfd | 293 | ret = LTTNG_OK; |
54d01ffb | 294 | error: |
e9404c27 | 295 | channel_attr_destroy(defattr); |
54d01ffb DG |
296 | return ret; |
297 | } | |
7885e399 DG |
298 | |
299 | /* | |
300 | * Enable UST channel for session and domain. | |
301 | */ | |
7972aab2 | 302 | int channel_ust_enable(struct ltt_ust_session *usess, |
7885e399 DG |
303 | struct ltt_ust_channel *uchan) |
304 | { | |
f73fabfd | 305 | int ret = LTTNG_OK; |
7885e399 | 306 | |
0525e9ae DG |
307 | assert(usess); |
308 | assert(uchan); | |
309 | ||
7885e399 DG |
310 | /* If already enabled, everything is OK */ |
311 | if (uchan->enabled) { | |
312 | DBG3("Channel %s already enabled. Skipping", uchan->name); | |
f73fabfd | 313 | ret = LTTNG_ERR_UST_CHAN_EXIST; |
7885e399 DG |
314 | goto end; |
315 | } | |
316 | ||
7972aab2 DG |
317 | DBG2("Channel %s being enabled in UST domain", uchan->name); |
318 | ||
319 | /* | |
320 | * Enable channel for UST global domain on all applications. Ignore return | |
321 | * value here since whatever error we got, it means that the channel was | |
322 | * not created on one or many registered applications and we can not report | |
323 | * this to the user yet. However, at this stage, the channel was | |
324 | * successfully created on the session daemon side so the enable-channel | |
325 | * command is a success. | |
326 | */ | |
d54b4440 | 327 | (void) ust_app_enable_channel_glb(usess, uchan); |
7885e399 | 328 | |
7885e399 DG |
329 | uchan->enabled = 1; |
330 | DBG2("Channel %s enabled successfully", uchan->name); | |
331 | ||
332 | end: | |
7885e399 DG |
333 | return ret; |
334 | } | |
335 | ||
336 | /* | |
337 | * Create UST channel for session and domain. | |
338 | */ | |
7972aab2 DG |
339 | int channel_ust_create(struct ltt_ust_session *usess, |
340 | struct lttng_channel *attr, enum lttng_buffer_type type) | |
7885e399 | 341 | { |
f73fabfd | 342 | int ret = LTTNG_OK; |
7885e399 DG |
343 | struct ltt_ust_channel *uchan = NULL; |
344 | struct lttng_channel *defattr = NULL; | |
b63d638b | 345 | enum lttng_domain_type domain = LTTNG_DOMAIN_UST; |
5b46bedf | 346 | bool chan_published = false; |
7885e399 | 347 | |
0525e9ae DG |
348 | assert(usess); |
349 | ||
7885e399 DG |
350 | /* Creating channel attributes if needed */ |
351 | if (attr == NULL) { | |
0a9c6494 | 352 | defattr = channel_new_default_attr(LTTNG_DOMAIN_UST, type); |
7885e399 | 353 | if (defattr == NULL) { |
f73fabfd | 354 | ret = LTTNG_ERR_FATAL; |
7885e399 DG |
355 | goto error; |
356 | } | |
357 | attr = defattr; | |
b63d638b JG |
358 | } else { |
359 | /* | |
360 | * HACK: Set the channel's subdomain (JUL, Log4j, Python, etc.) | |
361 | * based on the default name. | |
362 | */ | |
363 | if (!strcmp(attr->name, DEFAULT_JUL_CHANNEL_NAME)) { | |
364 | domain = LTTNG_DOMAIN_JUL; | |
365 | } else if (!strcmp(attr->name, DEFAULT_LOG4J_CHANNEL_NAME)) { | |
366 | domain = LTTNG_DOMAIN_LOG4J; | |
367 | } else if (!strcmp(attr->name, DEFAULT_PYTHON_CHANNEL_NAME)) { | |
368 | domain = LTTNG_DOMAIN_PYTHON; | |
369 | } | |
7885e399 DG |
370 | } |
371 | ||
8d5841ea MD |
372 | /* |
373 | * Set the overwrite mode for this channel based on the session | |
374 | * type unless the client explicitly overrides the channel mode. | |
375 | */ | |
376 | if (attr->attr.overwrite == DEFAULT_CHANNEL_OVERWRITE) { | |
377 | attr->attr.overwrite = !!usess->snapshot_mode; | |
378 | } | |
379 | ||
380 | /* Enforce mmap output for snapshot sessions. */ | |
27babd3a | 381 | if (usess->snapshot_mode) { |
27babd3a DG |
382 | attr->attr.output = LTTNG_EVENT_MMAP; |
383 | } | |
384 | ||
da9d9d9c MD |
385 | /* Validate common channel properties. */ |
386 | if (channel_validate(attr) < 0) { | |
387 | ret = LTTNG_ERR_INVALID; | |
388 | goto error; | |
389 | } | |
390 | ||
b024d072 | 391 | /* |
0525e9ae DG |
392 | * Validate UST buffer size and number of buffers: must both be power of 2 |
393 | * and nonzero. We validate right here for UST, because applications will | |
394 | * not report the error to the user (unlike kernel tracing). | |
b024d072 | 395 | */ |
0525e9ae DG |
396 | if (!attr->attr.subbuf_size || |
397 | (attr->attr.subbuf_size & (attr->attr.subbuf_size - 1))) { | |
f73fabfd | 398 | ret = LTTNG_ERR_INVALID; |
b024d072 MD |
399 | goto error; |
400 | } | |
0525e9ae | 401 | |
12744796 DG |
402 | /* |
403 | * Invalid subbuffer size if it's lower then the page size. | |
404 | */ | |
405 | if (attr->attr.subbuf_size < page_size) { | |
406 | ret = LTTNG_ERR_INVALID; | |
407 | goto error; | |
408 | } | |
409 | ||
0525e9ae DG |
410 | if (!attr->attr.num_subbuf || |
411 | (attr->attr.num_subbuf & (attr->attr.num_subbuf - 1))) { | |
f73fabfd | 412 | ret = LTTNG_ERR_INVALID; |
b024d072 MD |
413 | goto error; |
414 | } | |
415 | ||
a79d84dd DG |
416 | if (attr->attr.output != LTTNG_EVENT_MMAP) { |
417 | ret = LTTNG_ERR_NOT_SUPPORTED; | |
418 | goto error; | |
419 | } | |
420 | ||
1624d5b7 JD |
421 | /* |
422 | * The tracefile_size should not be < to the subbuf_size, otherwise | |
423 | * we won't be able to write the packets on disk | |
424 | */ | |
425 | if ((attr->attr.tracefile_size > 0) && | |
426 | (attr->attr.tracefile_size < attr->attr.subbuf_size)) { | |
427 | ret = LTTNG_ERR_INVALID; | |
428 | goto error; | |
429 | } | |
430 | ||
2e8269f7 DG |
431 | /* Validate buffer type. */ |
432 | switch (type) { | |
433 | case LTTNG_BUFFER_PER_PID: | |
0a9c6494 | 434 | break; |
2e8269f7 DG |
435 | case LTTNG_BUFFER_PER_UID: |
436 | break; | |
437 | default: | |
438 | ret = LTTNG_ERR_BUFFER_NOT_SUPPORTED; | |
439 | goto error; | |
440 | } | |
441 | ||
7885e399 | 442 | /* Create UST channel */ |
b63d638b | 443 | uchan = trace_ust_create_channel(attr, domain); |
7885e399 | 444 | if (uchan == NULL) { |
f73fabfd | 445 | ret = LTTNG_ERR_FATAL; |
7885e399 DG |
446 | goto error; |
447 | } | |
51755dc8 | 448 | |
58f3ca76 | 449 | uchan->enabled = 1; |
7972aab2 DG |
450 | if (trace_ust_is_max_id(usess->used_channel_id)) { |
451 | ret = LTTNG_ERR_UST_CHAN_FAIL; | |
452 | goto error; | |
453 | } | |
454 | uchan->id = trace_ust_get_next_chan_id(usess); | |
455 | ||
456 | DBG2("Channel %s is being created for UST with buffer %d and id %" PRIu64, | |
457 | uchan->name, type, uchan->id); | |
458 | ||
459 | /* Flag session buffer type. */ | |
460 | if (!usess->buffer_type_changed) { | |
461 | usess->buffer_type = type; | |
462 | usess->buffer_type_changed = 1; | |
463 | } else if (usess->buffer_type != type) { | |
464 | /* Buffer type was already set. Refuse to create channel. */ | |
465 | ret = LTTNG_ERR_BUFFER_TYPE_MISMATCH; | |
7885e399 DG |
466 | goto error_free_chan; |
467 | } | |
468 | ||
7972aab2 DG |
469 | /* Enable channel for global domain */ |
470 | ret = ust_app_create_channel_glb(usess, uchan); | |
49c336c1 | 471 | if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) { |
f73fabfd | 472 | ret = LTTNG_ERR_UST_CHAN_FAIL; |
7885e399 DG |
473 | goto error_free_chan; |
474 | } | |
475 | ||
fc34caaa DG |
476 | /* Adding the channel to the channel hash table. */ |
477 | rcu_read_lock(); | |
ad7a9107 DG |
478 | if (strncmp(uchan->name, DEFAULT_METADATA_NAME, |
479 | sizeof(uchan->name))) { | |
480 | lttng_ht_add_unique_str(usess->domain_global.channels, &uchan->node); | |
5b46bedf | 481 | chan_published = true; |
84ad93e8 DG |
482 | } else { |
483 | /* | |
484 | * Copy channel attribute to session if this is metadata so if NO | |
485 | * application exists we can access that data in the shadow copy during | |
486 | * the global update of newly registered application. | |
487 | */ | |
488 | memcpy(&usess->metadata_attr, &uchan->attr, | |
489 | sizeof(usess->metadata_attr)); | |
ad7a9107 | 490 | } |
fc34caaa DG |
491 | rcu_read_unlock(); |
492 | ||
7885e399 | 493 | DBG2("Channel %s created successfully", uchan->name); |
b63d638b JG |
494 | if (domain != LTTNG_DOMAIN_UST) { |
495 | struct agent *agt = trace_ust_find_agent(usess, domain); | |
496 | ||
497 | if (!agt) { | |
498 | agt = agent_create(domain); | |
499 | if (!agt) { | |
500 | ret = LTTNG_ERR_NOMEM; | |
5b46bedf | 501 | goto error_remove_chan; |
b63d638b JG |
502 | } |
503 | agent_add(agt, usess->agents); | |
504 | } | |
505 | } | |
7885e399 | 506 | |
e9404c27 | 507 | channel_attr_destroy(defattr); |
f73fabfd | 508 | return LTTNG_OK; |
7885e399 | 509 | |
5b46bedf MD |
510 | error_remove_chan: |
511 | if (chan_published) { | |
512 | trace_ust_delete_channel(usess->domain_global.channels, uchan); | |
513 | } | |
7885e399 DG |
514 | error_free_chan: |
515 | trace_ust_destroy_channel(uchan); | |
516 | error: | |
e9404c27 | 517 | channel_attr_destroy(defattr); |
7885e399 DG |
518 | return ret; |
519 | } | |
520 | ||
521 | /* | |
522 | * Disable UST channel for session and domain. | |
523 | */ | |
7972aab2 | 524 | int channel_ust_disable(struct ltt_ust_session *usess, |
7885e399 DG |
525 | struct ltt_ust_channel *uchan) |
526 | { | |
f73fabfd | 527 | int ret = LTTNG_OK; |
7885e399 | 528 | |
0525e9ae DG |
529 | assert(usess); |
530 | assert(uchan); | |
531 | ||
7885e399 DG |
532 | /* Already disabled */ |
533 | if (uchan->enabled == 0) { | |
534 | DBG2("Channel UST %s already disabled", uchan->name); | |
535 | goto end; | |
536 | } | |
537 | ||
7972aab2 DG |
538 | DBG2("Channel %s being disabled in UST global domain", uchan->name); |
539 | /* Disable channel for global domain */ | |
540 | ret = ust_app_disable_channel_glb(usess, uchan); | |
49c336c1 | 541 | if (ret < 0 && ret != -LTTNG_UST_ERR_EXIST) { |
f73fabfd | 542 | ret = LTTNG_ERR_UST_CHAN_DISABLE_FAIL; |
7885e399 DG |
543 | goto error; |
544 | } | |
545 | ||
546 | uchan->enabled = 0; | |
547 | ||
548 | DBG2("Channel %s disabled successfully", uchan->name); | |
549 | ||
f73fabfd | 550 | return LTTNG_OK; |
7885e399 DG |
551 | |
552 | end: | |
553 | error: | |
554 | return ret; | |
555 | } |