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 | { |
54012638 | 388 | struct ltt_kernel_metadata *lkm; |
f3ed775e | 389 | struct lttng_channel *chan; |
54012638 | 390 | |
ba7f0ae5 DG |
391 | lkm = zmalloc(sizeof(struct ltt_kernel_metadata)); |
392 | chan = zmalloc(sizeof(struct lttng_channel)); | |
f3ed775e | 393 | if (lkm == NULL || chan == NULL) { |
df0f840b | 394 | PERROR("kernel metadata zmalloc"); |
54012638 DG |
395 | goto error; |
396 | } | |
397 | ||
398 | /* Set default attributes */ | |
f3ed775e | 399 | chan->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE; |
3e230f92 | 400 | chan->attr.subbuf_size = default_get_metadata_subbuf_size(); |
b389abbe | 401 | chan->attr.num_subbuf = DEFAULT_METADATA_SUBBUF_NUM; |
6bb9e85f MD |
402 | chan->attr.switch_timer_interval = DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER; |
403 | chan->attr.read_timer_interval = DEFAULT_KERNEL_CHANNEL_READ_TIMER; | |
7d452e12 | 404 | chan->attr.output = DEFAULT_KERNEL_CHANNEL_OUTPUT; |
54012638 DG |
405 | |
406 | /* Init metadata */ | |
03550b58 | 407 | lkm->fd = -1; |
f3ed775e | 408 | lkm->conf = chan; |
54012638 DG |
409 | |
410 | return lkm; | |
411 | ||
412 | error: | |
a2c0da86 MD |
413 | free(lkm); |
414 | free(chan); | |
54012638 DG |
415 | return NULL; |
416 | } | |
417 | ||
418 | /* | |
050349bb DG |
419 | * Allocate and initialize a kernel stream. The stream is set to ACTIVE_FD by |
420 | * default. | |
54012638 | 421 | * |
050349bb | 422 | * Return pointer to structure or NULL. |
54012638 | 423 | */ |
00e2e675 DG |
424 | struct ltt_kernel_stream *trace_kernel_create_stream(const char *name, |
425 | unsigned int count) | |
54012638 | 426 | { |
00e2e675 | 427 | int ret; |
54012638 DG |
428 | struct ltt_kernel_stream *lks; |
429 | ||
0525e9ae DG |
430 | assert(name); |
431 | ||
ba7f0ae5 | 432 | lks = zmalloc(sizeof(struct ltt_kernel_stream)); |
54012638 | 433 | if (lks == NULL) { |
df0f840b | 434 | PERROR("kernel stream zmalloc"); |
54012638 DG |
435 | goto error; |
436 | } | |
437 | ||
00e2e675 | 438 | /* Set name */ |
535b8ff4 | 439 | ret = snprintf(lks->name, sizeof(lks->name), "%s_%u", name, count); |
00e2e675 DG |
440 | if (ret < 0) { |
441 | PERROR("snprintf stream name"); | |
442 | goto error; | |
443 | } | |
444 | lks->name[sizeof(lks->name) - 1] = '\0'; | |
445 | ||
54012638 | 446 | /* Init stream */ |
03550b58 | 447 | lks->fd = -1; |
54012638 | 448 | lks->state = 0; |
ffe60014 | 449 | lks->cpu = count; |
54012638 DG |
450 | |
451 | return lks; | |
452 | ||
453 | error: | |
454 | return NULL; | |
455 | } | |
c363b55d | 456 | |
050349bb DG |
457 | /* |
458 | * Cleanup kernel stream structure. | |
459 | */ | |
62499ad6 | 460 | void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream) |
c363b55d | 461 | { |
0525e9ae DG |
462 | assert(stream); |
463 | ||
33a2b854 | 464 | DBG("[trace] Closing stream fd %d", stream->fd); |
c363b55d | 465 | /* Close kernel fd */ |
03550b58 | 466 | if (stream->fd >= 0) { |
c617c0c6 MD |
467 | int ret; |
468 | ||
03550b58 MD |
469 | ret = close(stream->fd); |
470 | if (ret) { | |
471 | PERROR("close"); | |
472 | } | |
799e2c4f | 473 | } |
c363b55d DG |
474 | /* Remove from stream list */ |
475 | cds_list_del(&stream->list); | |
f9815039 | 476 | |
c363b55d DG |
477 | free(stream); |
478 | } | |
479 | ||
050349bb DG |
480 | /* |
481 | * Cleanup kernel event structure. | |
482 | */ | |
62499ad6 | 483 | void trace_kernel_destroy_event(struct ltt_kernel_event *event) |
c363b55d | 484 | { |
0525e9ae DG |
485 | assert(event); |
486 | ||
87eb4ab8 | 487 | if (event->fd >= 0) { |
c617c0c6 MD |
488 | int ret; |
489 | ||
87eb4ab8 MD |
490 | DBG("[trace] Closing event fd %d", event->fd); |
491 | /* Close kernel fd */ | |
799e2c4f MD |
492 | ret = close(event->fd); |
493 | if (ret) { | |
494 | PERROR("close"); | |
495 | } | |
87eb4ab8 MD |
496 | } else { |
497 | DBG("[trace] Tearing down event (no associated fd)"); | |
498 | } | |
c363b55d DG |
499 | |
500 | /* Remove from event list */ | |
501 | cds_list_del(&event->list); | |
f9815039 | 502 | |
00a62084 MD |
503 | free(event->filter_expression); |
504 | free(event->filter); | |
505 | ||
f9815039 | 506 | free(event->event); |
c363b55d DG |
507 | free(event); |
508 | } | |
509 | ||
645328ae DG |
510 | /* |
511 | * Cleanup kernel context structure. | |
512 | */ | |
513 | void trace_kernel_destroy_context(struct ltt_kernel_context *ctx) | |
514 | { | |
515 | assert(ctx); | |
516 | ||
9b09ad37 JG |
517 | if (ctx->in_list) { |
518 | cds_list_del(&ctx->list); | |
519 | } | |
645328ae DG |
520 | free(ctx); |
521 | } | |
522 | ||
050349bb DG |
523 | /* |
524 | * Cleanup kernel channel structure. | |
525 | */ | |
62499ad6 | 526 | void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel) |
c363b55d | 527 | { |
af9737e9 DG |
528 | struct ltt_kernel_stream *stream, *stmp; |
529 | struct ltt_kernel_event *event, *etmp; | |
645328ae | 530 | struct ltt_kernel_context *ctx, *ctmp; |
799e2c4f | 531 | int ret; |
c363b55d | 532 | |
0525e9ae DG |
533 | assert(channel); |
534 | ||
33a2b854 | 535 | DBG("[trace] Closing channel fd %d", channel->fd); |
c363b55d | 536 | /* Close kernel fd */ |
03550b58 MD |
537 | if (channel->fd >= 0) { |
538 | ret = close(channel->fd); | |
539 | if (ret) { | |
540 | PERROR("close"); | |
541 | } | |
799e2c4f | 542 | } |
c363b55d DG |
543 | |
544 | /* For each stream in the channel list */ | |
af9737e9 | 545 | cds_list_for_each_entry_safe(stream, stmp, &channel->stream_list.head, list) { |
62499ad6 | 546 | trace_kernel_destroy_stream(stream); |
c363b55d DG |
547 | } |
548 | ||
549 | /* For each event in the channel list */ | |
af9737e9 | 550 | cds_list_for_each_entry_safe(event, etmp, &channel->events_list.head, list) { |
62499ad6 | 551 | trace_kernel_destroy_event(event); |
c363b55d DG |
552 | } |
553 | ||
645328ae DG |
554 | /* For each context in the channel list */ |
555 | cds_list_for_each_entry_safe(ctx, ctmp, &channel->ctx_list, list) { | |
556 | trace_kernel_destroy_context(ctx); | |
557 | } | |
558 | ||
c363b55d DG |
559 | /* Remove from channel list */ |
560 | cds_list_del(&channel->list); | |
f9815039 | 561 | |
f9815039 | 562 | free(channel->channel); |
c363b55d DG |
563 | free(channel); |
564 | } | |
565 | ||
050349bb DG |
566 | /* |
567 | * Cleanup kernel metadata structure. | |
568 | */ | |
62499ad6 | 569 | void trace_kernel_destroy_metadata(struct ltt_kernel_metadata *metadata) |
c363b55d | 570 | { |
0525e9ae DG |
571 | assert(metadata); |
572 | ||
33a2b854 | 573 | DBG("[trace] Closing metadata fd %d", metadata->fd); |
c363b55d | 574 | /* Close kernel fd */ |
03550b58 | 575 | if (metadata->fd >= 0) { |
c617c0c6 MD |
576 | int ret; |
577 | ||
03550b58 MD |
578 | ret = close(metadata->fd); |
579 | if (ret) { | |
580 | PERROR("close"); | |
581 | } | |
799e2c4f | 582 | } |
c363b55d | 583 | |
f9815039 | 584 | free(metadata->conf); |
c363b55d DG |
585 | free(metadata); |
586 | } | |
587 | ||
050349bb | 588 | /* |
62499ad6 | 589 | * Cleanup kernel session structure |
36b588ed MD |
590 | * |
591 | * Should *NOT* be called with RCU read-side lock held. | |
050349bb | 592 | */ |
62499ad6 | 593 | void trace_kernel_destroy_session(struct ltt_kernel_session *session) |
c363b55d | 594 | { |
af9737e9 | 595 | struct ltt_kernel_channel *channel, *ctmp; |
799e2c4f | 596 | int ret; |
c363b55d | 597 | |
0525e9ae DG |
598 | assert(session); |
599 | ||
33a2b854 | 600 | DBG("[trace] Closing session fd %d", session->fd); |
c363b55d | 601 | /* Close kernel fds */ |
03550b58 MD |
602 | if (session->fd >= 0) { |
603 | ret = close(session->fd); | |
604 | if (ret) { | |
605 | PERROR("close"); | |
606 | } | |
799e2c4f | 607 | } |
f9815039 | 608 | |
03550b58 | 609 | if (session->metadata_stream_fd >= 0) { |
70dc1c34 | 610 | DBG("[trace] Closing metadata stream fd %d", session->metadata_stream_fd); |
799e2c4f MD |
611 | ret = close(session->metadata_stream_fd); |
612 | if (ret) { | |
613 | PERROR("close"); | |
614 | } | |
70dc1c34 | 615 | } |
c363b55d | 616 | |
d36b8583 | 617 | if (session->metadata != NULL) { |
62499ad6 | 618 | trace_kernel_destroy_metadata(session->metadata); |
d36b8583 | 619 | } |
c363b55d | 620 | |
af9737e9 | 621 | cds_list_for_each_entry_safe(channel, ctmp, &session->channel_list.head, list) { |
62499ad6 | 622 | trace_kernel_destroy_channel(channel); |
c363b55d DG |
623 | } |
624 | ||
00e2e675 | 625 | /* Wipe consumer output object */ |
6addfa37 | 626 | consumer_output_put(session->consumer); |
00e2e675 | 627 | |
c92af2a5 MD |
628 | lttng_tracker_list_destroy(session->tracker_list_pid); |
629 | lttng_tracker_list_destroy(session->tracker_list_vpid); | |
630 | lttng_tracker_list_destroy(session->tracker_list_uid); | |
631 | lttng_tracker_list_destroy(session->tracker_list_vuid); | |
632 | lttng_tracker_list_destroy(session->tracker_list_gid); | |
633 | lttng_tracker_list_destroy(session->tracker_list_vgid); | |
634 | ||
c363b55d DG |
635 | free(session); |
636 | } |