Commit | Line | Data |
---|---|---|
54012638 DG |
1 | /* |
2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> | |
3 | * | |
d14d33bf AM |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License, version 2 only, | |
6 | * as published by the Free Software Foundation. | |
54012638 DG |
7 | * |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
d14d33bf AM |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., | |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
54012638 DG |
16 | */ |
17 | ||
6c1c0768 | 18 | #define _LGPL_SOURCE |
54012638 DG |
19 | #include <stdio.h> |
20 | #include <stdlib.h> | |
21 | #include <string.h> | |
c363b55d | 22 | #include <unistd.h> |
54012638 | 23 | |
990570ed DG |
24 | #include <common/common.h> |
25 | #include <common/defaults.h> | |
1e307fab | 26 | |
00e2e675 | 27 | #include "consumer.h" |
62499ad6 | 28 | #include "trace-kernel.h" |
54012638 | 29 | |
19e70852 | 30 | /* |
050349bb | 31 | * Find the channel name for the given kernel session. |
19e70852 | 32 | */ |
62499ad6 | 33 | struct ltt_kernel_channel *trace_kernel_get_channel_by_name( |
19e70852 DG |
34 | char *name, struct ltt_kernel_session *session) |
35 | { | |
36 | struct ltt_kernel_channel *chan; | |
37 | ||
0525e9ae DG |
38 | assert(session); |
39 | assert(name); | |
19e70852 | 40 | |
85076754 MD |
41 | /* |
42 | * If we receive an empty string for channel name, it means the | |
43 | * default channel name is requested. | |
44 | */ | |
45 | if (name[0] == '\0') | |
46 | name = DEFAULT_CHANNEL_NAME; | |
47 | ||
54d01ffb DG |
48 | DBG("Trying to find channel %s", name); |
49 | ||
19e70852 DG |
50 | cds_list_for_each_entry(chan, &session->channel_list.head, list) { |
51 | if (strcmp(name, chan->channel->name) == 0) { | |
52 | DBG("Found channel by name %s", name); | |
53 | return chan; | |
54 | } | |
55 | } | |
56 | ||
19e70852 DG |
57 | return NULL; |
58 | } | |
59 | ||
00a62084 MD |
60 | /* |
61 | * Find the event for the given channel. | |
62 | */ | |
63 | struct ltt_kernel_event *trace_kernel_find_event( | |
64 | char *name, struct ltt_kernel_channel *channel, | |
65 | enum lttng_event_type type, | |
66 | struct lttng_filter_bytecode *filter) | |
67 | { | |
68 | struct ltt_kernel_event *ev; | |
69 | int found = 0; | |
70 | ||
71 | assert(name); | |
72 | assert(channel); | |
73 | ||
74 | cds_list_for_each_entry(ev, &channel->events_list.head, list) { | |
75 | if (type != LTTNG_EVENT_ALL && ev->type != type) { | |
76 | continue; | |
77 | } | |
78 | if (strcmp(name, ev->event->name)) { | |
79 | continue; | |
80 | } | |
81 | if ((ev->filter && !filter) || (!ev->filter && filter)) { | |
82 | continue; | |
83 | } | |
84 | if (ev->filter && filter) { | |
85 | if (ev->filter->len != filter->len || | |
86 | memcmp(ev->filter->data, filter->data, | |
87 | filter->len) != 0) { | |
88 | continue; | |
89 | } | |
90 | } | |
91 | found = 1; | |
92 | break; | |
93 | } | |
94 | if (found) { | |
95 | DBG("Found event %s for channel %s", name, | |
96 | channel->channel->name); | |
97 | return ev; | |
98 | } else { | |
99 | return NULL; | |
100 | } | |
101 | } | |
102 | ||
19e70852 | 103 | /* |
050349bb | 104 | * Find the event name for the given channel. |
19e70852 | 105 | */ |
62499ad6 | 106 | struct ltt_kernel_event *trace_kernel_get_event_by_name( |
d0ae4ea8 MD |
107 | char *name, struct ltt_kernel_channel *channel, |
108 | enum lttng_event_type type) | |
19e70852 DG |
109 | { |
110 | struct ltt_kernel_event *ev; | |
00a62084 | 111 | int found = 0; |
19e70852 | 112 | |
0525e9ae DG |
113 | assert(name); |
114 | assert(channel); | |
19e70852 DG |
115 | |
116 | cds_list_for_each_entry(ev, &channel->events_list.head, list) { | |
00a62084 | 117 | if (type != LTTNG_EVENT_ALL && ev->type != type) { |
d0ae4ea8 | 118 | continue; |
19e70852 | 119 | } |
00a62084 MD |
120 | if (strcmp(name, ev->event->name)) { |
121 | continue; | |
122 | } | |
123 | found = 1; | |
124 | break; | |
125 | } | |
126 | if (found) { | |
127 | DBG("Found event %s for channel %s", name, | |
128 | channel->channel->name); | |
129 | return ev; | |
130 | } else { | |
131 | return NULL; | |
19e70852 | 132 | } |
19e70852 DG |
133 | } |
134 | ||
54012638 | 135 | /* |
050349bb | 136 | * Allocate and initialize a kernel session data structure. |
54012638 | 137 | * |
050349bb | 138 | * Return pointer to structure or NULL. |
54012638 | 139 | */ |
dec56f6c | 140 | struct ltt_kernel_session *trace_kernel_create_session(void) |
54012638 | 141 | { |
a4b92340 | 142 | struct ltt_kernel_session *lks = NULL; |
54012638 DG |
143 | |
144 | /* Allocate a new ltt kernel session */ | |
ba7f0ae5 | 145 | lks = zmalloc(sizeof(struct ltt_kernel_session)); |
54012638 | 146 | if (lks == NULL) { |
df0f840b | 147 | PERROR("create kernel session zmalloc"); |
a4b92340 | 148 | goto alloc_error; |
54012638 DG |
149 | } |
150 | ||
151 | /* Init data structure */ | |
03550b58 MD |
152 | lks->fd = -1; |
153 | lks->metadata_stream_fd = -1; | |
54012638 DG |
154 | lks->channel_count = 0; |
155 | lks->stream_count_global = 0; | |
156 | lks->metadata = NULL; | |
157 | CDS_INIT_LIST_HEAD(&lks->channel_list.head); | |
158 | ||
c92af2a5 MD |
159 | lks->tracker_list_pid = lttng_tracker_list_create(); |
160 | if (!lks->tracker_list_pid) { | |
161 | goto error; | |
162 | } | |
163 | lks->tracker_list_vpid = lttng_tracker_list_create(); | |
164 | if (!lks->tracker_list_vpid) { | |
165 | goto error; | |
166 | } | |
167 | lks->tracker_list_uid = lttng_tracker_list_create(); | |
168 | if (!lks->tracker_list_uid) { | |
169 | goto error; | |
170 | } | |
171 | lks->tracker_list_vuid = lttng_tracker_list_create(); | |
172 | if (!lks->tracker_list_vuid) { | |
173 | goto error; | |
174 | } | |
175 | lks->tracker_list_gid = lttng_tracker_list_create(); | |
176 | if (!lks->tracker_list_gid) { | |
177 | goto error; | |
178 | } | |
179 | lks->tracker_list_vgid = lttng_tracker_list_create(); | |
180 | if (!lks->tracker_list_vgid) { | |
181 | goto error; | |
182 | } | |
00e2e675 DG |
183 | lks->consumer = consumer_create_output(CONSUMER_DST_LOCAL); |
184 | if (lks->consumer == NULL) { | |
185 | goto error; | |
186 | } | |
187 | ||
54012638 DG |
188 | return lks; |
189 | ||
190 | error: | |
c92af2a5 MD |
191 | lttng_tracker_list_destroy(lks->tracker_list_pid); |
192 | lttng_tracker_list_destroy(lks->tracker_list_vpid); | |
193 | lttng_tracker_list_destroy(lks->tracker_list_uid); | |
194 | lttng_tracker_list_destroy(lks->tracker_list_vuid); | |
195 | lttng_tracker_list_destroy(lks->tracker_list_gid); | |
196 | lttng_tracker_list_destroy(lks->tracker_list_vgid); | |
a4b92340 DG |
197 | free(lks); |
198 | ||
199 | alloc_error: | |
54012638 DG |
200 | return NULL; |
201 | } | |
202 | ||
203 | /* | |
050349bb | 204 | * Allocate and initialize a kernel channel data structure. |
54012638 | 205 | * |
050349bb | 206 | * Return pointer to structure or NULL. |
54012638 | 207 | */ |
00e2e675 | 208 | struct ltt_kernel_channel *trace_kernel_create_channel( |
fdd9eb17 | 209 | struct lttng_channel *chan) |
54012638 | 210 | { |
54012638 | 211 | struct ltt_kernel_channel *lkc; |
54012638 | 212 | |
0525e9ae DG |
213 | assert(chan); |
214 | ||
ba7f0ae5 | 215 | lkc = zmalloc(sizeof(struct ltt_kernel_channel)); |
f3ed775e | 216 | if (lkc == NULL) { |
df0f840b | 217 | PERROR("ltt_kernel_channel zmalloc"); |
54012638 DG |
218 | goto error; |
219 | } | |
220 | ||
ba7f0ae5 | 221 | lkc->channel = zmalloc(sizeof(struct lttng_channel)); |
f3ed775e | 222 | if (lkc->channel == NULL) { |
df0f840b | 223 | PERROR("lttng_channel zmalloc"); |
ed594980 | 224 | free(lkc); |
f3ed775e DG |
225 | goto error; |
226 | } | |
227 | memcpy(lkc->channel, chan, sizeof(struct lttng_channel)); | |
54012638 | 228 | |
85076754 MD |
229 | /* |
230 | * If we receive an empty string for channel name, it means the | |
231 | * default channel name is requested. | |
232 | */ | |
233 | if (chan->name[0] == '\0') { | |
234 | strncpy(lkc->channel->name, DEFAULT_CHANNEL_NAME, | |
235 | sizeof(lkc->channel->name)); | |
236 | } | |
bd722d76 | 237 | lkc->channel->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; |
85076754 | 238 | |
03550b58 | 239 | lkc->fd = -1; |
54012638 | 240 | lkc->stream_count = 0; |
cbbbb275 | 241 | lkc->event_count = 0; |
d36b8583 | 242 | lkc->enabled = 1; |
54012638 DG |
243 | /* Init linked list */ |
244 | CDS_INIT_LIST_HEAD(&lkc->events_list.head); | |
245 | CDS_INIT_LIST_HEAD(&lkc->stream_list.head); | |
645328ae | 246 | CDS_INIT_LIST_HEAD(&lkc->ctx_list); |
54012638 DG |
247 | |
248 | return lkc; | |
249 | ||
250 | error: | |
251 | return NULL; | |
252 | } | |
253 | ||
645328ae DG |
254 | /* |
255 | * Allocate and init a kernel context object. | |
256 | * | |
257 | * Return the allocated object or NULL on error. | |
258 | */ | |
259 | struct ltt_kernel_context *trace_kernel_create_context( | |
260 | struct lttng_kernel_context *ctx) | |
261 | { | |
262 | struct ltt_kernel_context *kctx; | |
263 | ||
264 | kctx = zmalloc(sizeof(*kctx)); | |
265 | if (!kctx) { | |
266 | PERROR("zmalloc kernel context"); | |
267 | goto error; | |
268 | } | |
269 | ||
270 | if (ctx) { | |
271 | memcpy(&kctx->ctx, ctx, sizeof(kctx->ctx)); | |
272 | } | |
da23da06 JG |
273 | error: |
274 | return kctx; | |
275 | } | |
645328ae | 276 | |
da23da06 JG |
277 | /* |
278 | * Allocate and init a kernel context object from an existing kernel context | |
279 | * object. | |
280 | * | |
281 | * Return the allocated object or NULL on error. | |
282 | */ | |
283 | struct ltt_kernel_context *trace_kernel_copy_context( | |
284 | struct ltt_kernel_context *kctx) | |
285 | { | |
286 | struct ltt_kernel_context *kctx_copy; | |
287 | ||
288 | assert(kctx); | |
289 | kctx_copy = zmalloc(sizeof(*kctx_copy)); | |
290 | if (!kctx_copy) { | |
291 | PERROR("zmalloc ltt_kernel_context"); | |
292 | goto error; | |
293 | } | |
294 | ||
295 | memcpy(kctx_copy, kctx, sizeof(*kctx_copy)); | |
296 | memset(&kctx_copy->list, 0, sizeof(kctx_copy->list)); | |
7b9445b3 | 297 | |
645328ae | 298 | error: |
da23da06 | 299 | return kctx_copy; |
645328ae DG |
300 | } |
301 | ||
54012638 | 302 | /* |
050349bb | 303 | * Allocate and initialize a kernel event. Set name and event type. |
a969e101 | 304 | * We own filter_expression, and filter. |
54012638 | 305 | * |
050349bb | 306 | * Return pointer to structure or NULL. |
54012638 | 307 | */ |
00a62084 MD |
308 | struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev, |
309 | char *filter_expression, struct lttng_filter_bytecode *filter) | |
54012638 DG |
310 | { |
311 | struct ltt_kernel_event *lke; | |
312 | struct lttng_kernel_event *attr; | |
313 | ||
0525e9ae DG |
314 | assert(ev); |
315 | ||
ba7f0ae5 DG |
316 | lke = zmalloc(sizeof(struct ltt_kernel_event)); |
317 | attr = zmalloc(sizeof(struct lttng_kernel_event)); | |
54012638 | 318 | if (lke == NULL || attr == NULL) { |
df0f840b | 319 | PERROR("kernel event zmalloc"); |
54012638 DG |
320 | goto error; |
321 | } | |
322 | ||
f3ed775e | 323 | switch (ev->type) { |
7d29a247 | 324 | case LTTNG_EVENT_PROBE: |
e6ddca71 | 325 | attr->instrumentation = LTTNG_KERNEL_KPROBE; |
7d29a247 DG |
326 | attr->u.kprobe.addr = ev->attr.probe.addr; |
327 | attr->u.kprobe.offset = ev->attr.probe.offset; | |
f3ed775e | 328 | strncpy(attr->u.kprobe.symbol_name, |
dbbb3ec5 DG |
329 | ev->attr.probe.symbol_name, LTTNG_KERNEL_SYM_NAME_LEN); |
330 | attr->u.kprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
f3ed775e DG |
331 | break; |
332 | case LTTNG_EVENT_FUNCTION: | |
8f0d098b MD |
333 | attr->instrumentation = LTTNG_KERNEL_KRETPROBE; |
334 | attr->u.kretprobe.addr = ev->attr.probe.addr; | |
335 | attr->u.kretprobe.offset = ev->attr.probe.offset; | |
8f0d098b | 336 | strncpy(attr->u.kretprobe.symbol_name, |
dbbb3ec5 DG |
337 | ev->attr.probe.symbol_name, LTTNG_KERNEL_SYM_NAME_LEN); |
338 | attr->u.kretprobe.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
8f0d098b MD |
339 | break; |
340 | case LTTNG_EVENT_FUNCTION_ENTRY: | |
f3ed775e DG |
341 | attr->instrumentation = LTTNG_KERNEL_FUNCTION; |
342 | strncpy(attr->u.ftrace.symbol_name, | |
dbbb3ec5 DG |
343 | ev->attr.ftrace.symbol_name, LTTNG_KERNEL_SYM_NAME_LEN); |
344 | attr->u.ftrace.symbol_name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
f3ed775e | 345 | break; |
e6ddca71 DG |
346 | case LTTNG_EVENT_TRACEPOINT: |
347 | attr->instrumentation = LTTNG_KERNEL_TRACEPOINT; | |
f3ed775e | 348 | break; |
a54bd42d MD |
349 | case LTTNG_EVENT_SYSCALL: |
350 | attr->instrumentation = LTTNG_KERNEL_SYSCALL; | |
0133c199 | 351 | break; |
7a3d1328 MD |
352 | case LTTNG_EVENT_ALL: |
353 | attr->instrumentation = LTTNG_KERNEL_ALL; | |
354 | break; | |
f3ed775e DG |
355 | default: |
356 | ERR("Unknown kernel instrumentation type (%d)", ev->type); | |
357 | goto error; | |
358 | } | |
359 | ||
360 | /* Copy event name */ | |
dbbb3ec5 DG |
361 | strncpy(attr->name, ev->name, LTTNG_KERNEL_SYM_NAME_LEN); |
362 | attr->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0'; | |
f3ed775e | 363 | |
54012638 | 364 | /* Setting up a kernel event */ |
03550b58 | 365 | lke->fd = -1; |
54012638 | 366 | lke->event = attr; |
d36b8583 | 367 | lke->enabled = 1; |
00a62084 MD |
368 | lke->filter_expression = filter_expression; |
369 | lke->filter = filter; | |
54012638 DG |
370 | |
371 | return lke; | |
372 | ||
373 | error: | |
a969e101 MD |
374 | free(filter_expression); |
375 | free(filter); | |
a2c0da86 MD |
376 | free(lke); |
377 | free(attr); | |
54012638 DG |
378 | return NULL; |
379 | } | |
380 | ||
381 | /* | |
050349bb | 382 | * Allocate and initialize a kernel metadata. |
54012638 | 383 | * |
050349bb | 384 | * Return pointer to structure or NULL. |
54012638 | 385 | */ |
a4b92340 | 386 | struct ltt_kernel_metadata *trace_kernel_create_metadata(void) |
54012638 | 387 | { |
038abe40 | 388 | int ret; |
54012638 | 389 | struct ltt_kernel_metadata *lkm; |
f3ed775e | 390 | struct lttng_channel *chan; |
54012638 | 391 | |
ba7f0ae5 DG |
392 | lkm = zmalloc(sizeof(struct ltt_kernel_metadata)); |
393 | chan = zmalloc(sizeof(struct lttng_channel)); | |
f3ed775e | 394 | if (lkm == NULL || chan == NULL) { |
df0f840b | 395 | PERROR("kernel metadata zmalloc"); |
54012638 DG |
396 | goto error; |
397 | } | |
398 | ||
038abe40 JG |
399 | ret = lttng_strncpy( |
400 | chan->name, DEFAULT_METADATA_NAME, sizeof(chan->name)); | |
401 | if (ret) { | |
402 | ERR("Failed to initialize metadata channel name to `%s`", | |
403 | DEFAULT_METADATA_NAME); | |
404 | goto error; | |
405 | } | |
406 | ||
54012638 | 407 | /* Set default attributes */ |
038abe40 | 408 | chan->attr.overwrite = DEFAULT_METADATA_OVERWRITE; |
3e230f92 | 409 | chan->attr.subbuf_size = default_get_metadata_subbuf_size(); |
b389abbe | 410 | chan->attr.num_subbuf = DEFAULT_METADATA_SUBBUF_NUM; |
038abe40 JG |
411 | chan->attr.switch_timer_interval = DEFAULT_METADATA_SWITCH_TIMER; |
412 | chan->attr.read_timer_interval = DEFAULT_METADATA_READ_TIMER;; | |
413 | ||
414 | ||
415 | /* | |
416 | * The metadata channel of kernel sessions must use the "mmap" | |
417 | * back-end since the consumer daemon accumulates complete | |
418 | * metadata units before sending them to the relay daemon in | |
419 | * live mode. The consumer daemon also needs to extract the contents | |
420 | * of the metadata cache when computing a rotation position. | |
421 | * | |
422 | * In both cases, it is not possible to rely on the splice | |
423 | * back-end as the consumer daemon may need to accumulate more | |
424 | * content than can be backed by the ring buffer's underlying | |
425 | * pages. | |
426 | */ | |
427 | chan->attr.output = LTTNG_EVENT_MMAP; | |
428 | chan->attr.tracefile_size = 0; | |
429 | chan->attr.tracefile_count = 0; | |
430 | chan->attr.live_timer_interval = 0; | |
54012638 DG |
431 | |
432 | /* Init metadata */ | |
03550b58 | 433 | lkm->fd = -1; |
f3ed775e | 434 | lkm->conf = chan; |
54012638 DG |
435 | |
436 | return lkm; | |
437 | ||
438 | error: | |
a2c0da86 MD |
439 | free(lkm); |
440 | free(chan); | |
54012638 DG |
441 | return NULL; |
442 | } | |
443 | ||
444 | /* | |
050349bb DG |
445 | * Allocate and initialize a kernel stream. The stream is set to ACTIVE_FD by |
446 | * default. | |
54012638 | 447 | * |
050349bb | 448 | * Return pointer to structure or NULL. |
54012638 | 449 | */ |
00e2e675 DG |
450 | struct ltt_kernel_stream *trace_kernel_create_stream(const char *name, |
451 | unsigned int count) | |
54012638 | 452 | { |
00e2e675 | 453 | int ret; |
54012638 DG |
454 | struct ltt_kernel_stream *lks; |
455 | ||
0525e9ae DG |
456 | assert(name); |
457 | ||
ba7f0ae5 | 458 | lks = zmalloc(sizeof(struct ltt_kernel_stream)); |
54012638 | 459 | if (lks == NULL) { |
df0f840b | 460 | PERROR("kernel stream zmalloc"); |
54012638 DG |
461 | goto error; |
462 | } | |
463 | ||
00e2e675 | 464 | /* Set name */ |
535b8ff4 | 465 | ret = snprintf(lks->name, sizeof(lks->name), "%s_%u", name, count); |
00e2e675 DG |
466 | if (ret < 0) { |
467 | PERROR("snprintf stream name"); | |
468 | goto error; | |
469 | } | |
470 | lks->name[sizeof(lks->name) - 1] = '\0'; | |
471 | ||
54012638 | 472 | /* Init stream */ |
03550b58 | 473 | lks->fd = -1; |
54012638 | 474 | lks->state = 0; |
ffe60014 | 475 | lks->cpu = count; |
54012638 DG |
476 | |
477 | return lks; | |
478 | ||
479 | error: | |
480 | return NULL; | |
481 | } | |
c363b55d | 482 | |
050349bb DG |
483 | /* |
484 | * Cleanup kernel stream structure. | |
485 | */ | |
62499ad6 | 486 | void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream) |
c363b55d | 487 | { |
0525e9ae DG |
488 | assert(stream); |
489 | ||
33a2b854 | 490 | DBG("[trace] Closing stream fd %d", stream->fd); |
c363b55d | 491 | /* Close kernel fd */ |
03550b58 | 492 | if (stream->fd >= 0) { |
c617c0c6 MD |
493 | int ret; |
494 | ||
03550b58 MD |
495 | ret = close(stream->fd); |
496 | if (ret) { | |
497 | PERROR("close"); | |
498 | } | |
799e2c4f | 499 | } |
c363b55d DG |
500 | /* Remove from stream list */ |
501 | cds_list_del(&stream->list); | |
f9815039 | 502 | |
c363b55d DG |
503 | free(stream); |
504 | } | |
505 | ||
050349bb DG |
506 | /* |
507 | * Cleanup kernel event structure. | |
508 | */ | |
62499ad6 | 509 | void trace_kernel_destroy_event(struct ltt_kernel_event *event) |
c363b55d | 510 | { |
0525e9ae DG |
511 | assert(event); |
512 | ||
87eb4ab8 | 513 | if (event->fd >= 0) { |
c617c0c6 MD |
514 | int ret; |
515 | ||
87eb4ab8 MD |
516 | DBG("[trace] Closing event fd %d", event->fd); |
517 | /* Close kernel fd */ | |
799e2c4f MD |
518 | ret = close(event->fd); |
519 | if (ret) { | |
520 | PERROR("close"); | |
521 | } | |
87eb4ab8 MD |
522 | } else { |
523 | DBG("[trace] Tearing down event (no associated fd)"); | |
524 | } | |
c363b55d DG |
525 | |
526 | /* Remove from event list */ | |
527 | cds_list_del(&event->list); | |
f9815039 | 528 | |
00a62084 MD |
529 | free(event->filter_expression); |
530 | free(event->filter); | |
531 | ||
f9815039 | 532 | free(event->event); |
c363b55d DG |
533 | free(event); |
534 | } | |
535 | ||
645328ae DG |
536 | /* |
537 | * Cleanup kernel context structure. | |
538 | */ | |
539 | void trace_kernel_destroy_context(struct ltt_kernel_context *ctx) | |
540 | { | |
541 | assert(ctx); | |
542 | ||
9b09ad37 JG |
543 | if (ctx->in_list) { |
544 | cds_list_del(&ctx->list); | |
545 | } | |
645328ae DG |
546 | free(ctx); |
547 | } | |
548 | ||
050349bb DG |
549 | /* |
550 | * Cleanup kernel channel structure. | |
551 | */ | |
62499ad6 | 552 | void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel) |
c363b55d | 553 | { |
af9737e9 DG |
554 | struct ltt_kernel_stream *stream, *stmp; |
555 | struct ltt_kernel_event *event, *etmp; | |
645328ae | 556 | struct ltt_kernel_context *ctx, *ctmp; |
799e2c4f | 557 | int ret; |
c363b55d | 558 | |
0525e9ae DG |
559 | assert(channel); |
560 | ||
33a2b854 | 561 | DBG("[trace] Closing channel fd %d", channel->fd); |
c363b55d | 562 | /* Close kernel fd */ |
03550b58 MD |
563 | if (channel->fd >= 0) { |
564 | ret = close(channel->fd); | |
565 | if (ret) { | |
566 | PERROR("close"); | |
567 | } | |
799e2c4f | 568 | } |
c363b55d DG |
569 | |
570 | /* For each stream in the channel list */ | |
af9737e9 | 571 | cds_list_for_each_entry_safe(stream, stmp, &channel->stream_list.head, list) { |
62499ad6 | 572 | trace_kernel_destroy_stream(stream); |
c363b55d DG |
573 | } |
574 | ||
575 | /* For each event in the channel list */ | |
af9737e9 | 576 | cds_list_for_each_entry_safe(event, etmp, &channel->events_list.head, list) { |
62499ad6 | 577 | trace_kernel_destroy_event(event); |
c363b55d DG |
578 | } |
579 | ||
645328ae DG |
580 | /* For each context in the channel list */ |
581 | cds_list_for_each_entry_safe(ctx, ctmp, &channel->ctx_list, list) { | |
582 | trace_kernel_destroy_context(ctx); | |
583 | } | |
584 | ||
c363b55d DG |
585 | /* Remove from channel list */ |
586 | cds_list_del(&channel->list); | |
f9815039 | 587 | |
f9815039 | 588 | free(channel->channel); |
c363b55d DG |
589 | free(channel); |
590 | } | |
591 | ||
050349bb DG |
592 | /* |
593 | * Cleanup kernel metadata structure. | |
594 | */ | |
62499ad6 | 595 | void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata) |
c363b55d | 596 | { |
0525e9ae DG |
597 | assert(metadata); |
598 | ||
33a2b854 | 599 | DBG("[trace] Closing metadata fd %d", metadata->fd); |
c363b55d | 600 | /* Close kernel fd */ |
03550b58 | 601 | if (metadata->fd >= 0) { |
c617c0c6 MD |
602 | int ret; |
603 | ||
03550b58 MD |
604 | ret = close(metadata->fd); |
605 | if (ret) { | |
606 | PERROR("close"); | |
607 | } | |
799e2c4f | 608 | } |
c363b55d | 609 | |
f9815039 | 610 | free(metadata->conf); |
c363b55d DG |
611 | free(metadata); |
612 | } | |
613 | ||
050349bb | 614 | /* |
62499ad6 | 615 | * Cleanup kernel session structure |
36b588ed MD |
616 | * |
617 | * Should *NOT* be called with RCU read-side lock held. | |
050349bb | 618 | */ |
62499ad6 | 619 | void trace_kernel_destroy_session(struct ltt_kernel_session *session) |
c363b55d | 620 | { |
af9737e9 | 621 | struct ltt_kernel_channel *channel, *ctmp; |
799e2c4f | 622 | int ret; |
c363b55d | 623 | |
0525e9ae DG |
624 | assert(session); |
625 | ||
33a2b854 | 626 | DBG("[trace] Closing session fd %d", session->fd); |
c363b55d | 627 | /* Close kernel fds */ |
03550b58 MD |
628 | if (session->fd >= 0) { |
629 | ret = close(session->fd); | |
630 | if (ret) { | |
631 | PERROR("close"); | |
632 | } | |
799e2c4f | 633 | } |
f9815039 | 634 | |
03550b58 | 635 | if (session->metadata_stream_fd >= 0) { |
70dc1c34 | 636 | DBG("[trace] Closing metadata stream fd %d", session->metadata_stream_fd); |
799e2c4f MD |
637 | ret = close(session->metadata_stream_fd); |
638 | if (ret) { | |
639 | PERROR("close"); | |
640 | } | |
70dc1c34 | 641 | } |
c363b55d | 642 | |
d36b8583 | 643 | if (session->metadata != NULL) { |
62499ad6 | 644 | trace_kernel_destroy_metadata(session->metadata); |
d36b8583 | 645 | } |
c363b55d | 646 | |
af9737e9 | 647 | cds_list_for_each_entry_safe(channel, ctmp, &session->channel_list.head, list) { |
62499ad6 | 648 | trace_kernel_destroy_channel(channel); |
c363b55d DG |
649 | } |
650 | ||
00e2e675 | 651 | /* Wipe consumer output object */ |
6addfa37 | 652 | consumer_output_put(session->consumer); |
00e2e675 | 653 | |
c92af2a5 MD |
654 | lttng_tracker_list_destroy(session->tracker_list_pid); |
655 | lttng_tracker_list_destroy(session->tracker_list_vpid); | |
656 | lttng_tracker_list_destroy(session->tracker_list_uid); | |
657 | lttng_tracker_list_destroy(session->tracker_list_vuid); | |
658 | lttng_tracker_list_destroy(session->tracker_list_gid); | |
659 | lttng_tracker_list_destroy(session->tracker_list_vgid); | |
660 | ||
c363b55d DG |
661 | free(session); |
662 | } |