Cleanup: namespace 'align' macros
[lttng-tools.git] / src / common / kernel-ctl / kernel-ctl.c
1 /*
2 * Copyright (C) 2011 Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * Copyright (C) 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-only
7 *
8 */
9
10 #include "lttng/tracker.h"
11 #define _LGPL_SOURCE
12 #define __USE_LINUX_IOCTL_DEFS
13 #include <sys/ioctl.h>
14 #include <string.h>
15 #include <common/align.h>
16 #include <common/macros.h>
17 #include <common/compat/errno.h>
18 #include <stdarg.h>
19 #include <common/time.h>
20
21 #include "kernel-ctl.h"
22 #include "kernel-ioctl.h"
23
24 #define LTTNG_IOCTL_CHECK(fildes, request, ...) \
25 ({ \
26 int _ioctl_ret = ioctl(fildes, request, ##__VA_ARGS__); \
27 LTTNG_ASSERT(_ioctl_ret <= 0); \
28 !_ioctl_ret ? 0 : -errno; \
29 })
30
31 #define LTTNG_IOCTL_NO_CHECK(fildes, request, ...) \
32 ({ \
33 int _ioctl_ret = ioctl(fildes, request, ##__VA_ARGS__); \
34 _ioctl_ret >= 0 ? _ioctl_ret : -errno; \
35 })
36
37 /*
38 * This flag indicates which version of the kernel ABI to use. The old
39 * ABI (namespace _old) does not support a 32-bit user-space when the
40 * kernel is 64-bit. The old ABI is kept here for compatibility but is
41 * deprecated and will be removed eventually.
42 */
43 static int lttng_kernel_abi_use_old_abi = -1;
44
45 /*
46 * Execute the new or old ioctl depending on the ABI version.
47 * If the ABI version is not determined yet (lttng_kernel_abi_use_old_abi = -1),
48 * this function tests if the new ABI is available and otherwise fallbacks
49 * on the old one.
50 * This function takes the fd on which the ioctl must be executed and the old
51 * and new request codes.
52 * It returns the return value of the ioctl executed.
53 */
54 static inline int compat_ioctl_no_arg(int fd, unsigned long oldname,
55 unsigned long newname)
56 {
57 int ret;
58
59 if (lttng_kernel_abi_use_old_abi == -1) {
60 ret = LTTNG_IOCTL_NO_CHECK(fd, newname);
61 if (!ret) {
62 lttng_kernel_abi_use_old_abi = 0;
63 goto end;
64 }
65 lttng_kernel_abi_use_old_abi = 1;
66 }
67 if (lttng_kernel_abi_use_old_abi) {
68 ret = LTTNG_IOCTL_NO_CHECK(fd, oldname);
69 } else {
70 ret = LTTNG_IOCTL_NO_CHECK(fd, newname);
71 }
72
73 end:
74 return ret;
75 }
76
77 int kernctl_create_session(int fd)
78 {
79 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_SESSION,
80 LTTNG_KERNEL_ABI_SESSION);
81 }
82
83 /* open the metadata global channel */
84 int kernctl_open_metadata(int fd, struct lttng_channel_attr *chops)
85 {
86 struct lttng_kernel_abi_channel channel;
87
88 if (lttng_kernel_abi_use_old_abi) {
89 struct lttng_kernel_abi_old_channel old_channel;
90
91 memset(&old_channel, 0, sizeof(old_channel));
92 old_channel.overwrite = chops->overwrite;
93 old_channel.subbuf_size = chops->subbuf_size;
94 old_channel.num_subbuf = chops->num_subbuf;
95 old_channel.switch_timer_interval = chops->switch_timer_interval;
96 old_channel.read_timer_interval = chops->read_timer_interval;
97 old_channel.output = chops->output;
98
99 memset(old_channel.padding, 0, sizeof(old_channel.padding));
100 /*
101 * The new channel padding is smaller than the old ABI so we use the
102 * new ABI padding size for the memcpy.
103 */
104 memcpy(old_channel.padding, chops->padding, sizeof(chops->padding));
105
106 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_OLD_METADATA,
107 &old_channel);
108 }
109
110 memset(&channel, 0, sizeof(channel));
111 channel.overwrite = chops->overwrite;
112 channel.subbuf_size = chops->subbuf_size;
113 channel.num_subbuf = chops->num_subbuf;
114 channel.switch_timer_interval = chops->switch_timer_interval;
115 channel.read_timer_interval = chops->read_timer_interval;
116 channel.output = chops->output;
117 memcpy(channel.padding, chops->padding, sizeof(chops->padding));
118
119 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_METADATA, &channel);
120 }
121
122 int kernctl_create_channel(int fd, struct lttng_channel_attr *chops)
123 {
124 struct lttng_kernel_abi_channel channel;
125
126 memset(&channel, 0, sizeof(channel));
127 if (lttng_kernel_abi_use_old_abi) {
128 struct lttng_kernel_abi_old_channel old_channel;
129
130 old_channel.overwrite = chops->overwrite;
131 old_channel.subbuf_size = chops->subbuf_size;
132 old_channel.num_subbuf = chops->num_subbuf;
133 old_channel.switch_timer_interval = chops->switch_timer_interval;
134 old_channel.read_timer_interval = chops->read_timer_interval;
135 old_channel.output = chops->output;
136
137 memset(old_channel.padding, 0, sizeof(old_channel.padding));
138 /*
139 * The new channel padding is smaller than the old ABI so we use the
140 * new ABI padding size for the memcpy.
141 */
142 memcpy(old_channel.padding, chops->padding, sizeof(chops->padding));
143
144 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_OLD_CHANNEL,
145 &old_channel);
146 }
147
148 channel.overwrite = chops->overwrite;
149 channel.subbuf_size = chops->subbuf_size;
150 channel.num_subbuf = chops->num_subbuf;
151 channel.switch_timer_interval = chops->switch_timer_interval;
152 channel.read_timer_interval = chops->read_timer_interval;
153 channel.output = chops->output;
154 memcpy(channel.padding, chops->padding, sizeof(chops->padding));
155
156 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_CHANNEL, &channel);
157 }
158
159 int kernctl_syscall_mask(int fd, char **syscall_mask, uint32_t *nr_bits)
160 {
161 struct lttng_kernel_abi_syscall_mask kmask_len, *kmask = NULL;
162 size_t array_alloc_len;
163 char *new_mask;
164 int ret = 0;
165
166 if (!syscall_mask) {
167 ret = -1;
168 goto end;
169 }
170
171 if (!nr_bits) {
172 ret = -1;
173 goto end;
174 }
175
176 kmask_len.len = 0;
177 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SYSCALL_MASK, &kmask_len);
178 if (ret) {
179 goto end;
180 }
181
182 array_alloc_len = lttng_align_ceil(kmask_len.len, 8) >> 3;
183
184 kmask = zmalloc(sizeof(*kmask) + array_alloc_len);
185 if (!kmask) {
186 ret = -1;
187 goto end;
188 }
189
190 kmask->len = kmask_len.len;
191 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SYSCALL_MASK, kmask);
192 if (ret) {
193 goto end;
194 }
195
196 new_mask = realloc(*syscall_mask, array_alloc_len);
197 if (!new_mask) {
198 ret = -1;
199 goto end;
200 }
201 memcpy(new_mask, kmask->mask, array_alloc_len);
202 *syscall_mask = new_mask;
203 *nr_bits = kmask->len;
204
205 end:
206 free(kmask);
207 return ret;
208 }
209
210 int kernctl_track_pid(int fd, int pid)
211 {
212 int ret = LTTNG_IOCTL_CHECK(
213 fd, LTTNG_KERNEL_ABI_SESSION_TRACK_PID, pid);
214
215 if (ret == -ENOSYS) {
216 ret = LTTNG_IOCTL_CHECK(fd,
217 LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_PID, pid);
218 }
219
220 return ret;
221 }
222
223 int kernctl_untrack_pid(int fd, int pid)
224 {
225 int ret = LTTNG_IOCTL_CHECK(
226 fd, LTTNG_KERNEL_ABI_SESSION_UNTRACK_PID, pid);
227
228 if (ret == -ENOSYS) {
229 ret = LTTNG_IOCTL_CHECK(fd,
230 LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_PID, pid);
231 }
232
233 return ret;
234 }
235
236 int kernctl_list_tracker_pids(int fd)
237 {
238 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_PIDS);
239 }
240
241 static enum lttng_kernel_abi_tracker_type get_kernel_tracker_type(
242 enum lttng_process_attr process_attr)
243 {
244 switch (process_attr) {
245 case LTTNG_PROCESS_ATTR_PROCESS_ID:
246 return LTTNG_KERNEL_ABI_TRACKER_PID;
247 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
248 return LTTNG_KERNEL_ABI_TRACKER_VPID;
249 case LTTNG_PROCESS_ATTR_USER_ID:
250 return LTTNG_KERNEL_ABI_TRACKER_UID;
251 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID:
252 return LTTNG_KERNEL_ABI_TRACKER_VUID;
253 case LTTNG_PROCESS_ATTR_GROUP_ID:
254 return LTTNG_KERNEL_ABI_TRACKER_GID;
255 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID:
256 return LTTNG_KERNEL_ABI_TRACKER_VGID;
257 default:
258 return LTTNG_KERNEL_ABI_TRACKER_UNKNOWN;
259 }
260 }
261
262 int kernctl_track_id(int fd, enum lttng_process_attr process_attr, int id)
263 {
264 struct lttng_kernel_abi_tracker_args args;
265 int ret;
266
267 args.id = id;
268 args.type = get_kernel_tracker_type(process_attr);
269 if (args.type == LTTNG_KERNEL_ABI_TRACKER_UNKNOWN) {
270 errno = EINVAL;
271 return -1;
272 }
273
274 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_TRACK_ID, &args);
275 if (ret == -ENOSYS) {
276 ret = LTTNG_IOCTL_CHECK(fd,
277 LTTNG_KERNEL_ABI_OLD_SESSION_TRACK_ID, &args);
278 }
279
280 return ret;
281 }
282
283 int kernctl_untrack_id(int fd, enum lttng_process_attr process_attr, int id)
284 {
285 struct lttng_kernel_abi_tracker_args args;
286 int ret;
287
288 args.id = id;
289 args.type = get_kernel_tracker_type(process_attr);
290 if (args.type == LTTNG_KERNEL_ABI_TRACKER_UNKNOWN) {
291 errno = EINVAL;
292 return -1;
293 }
294
295 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_UNTRACK_ID, &args);
296 if (ret == -ENOSYS) {
297 ret = LTTNG_IOCTL_CHECK(fd,
298 LTTNG_KERNEL_ABI_OLD_SESSION_UNTRACK_ID, &args);
299 }
300
301 return ret;
302 }
303
304 int kernctl_list_tracker_ids(int fd, enum lttng_process_attr process_attr)
305 {
306 struct lttng_kernel_abi_tracker_args args;
307 int ret;
308
309 args.id = -1;
310 args.type = get_kernel_tracker_type(process_attr);
311 if (args.type == LTTNG_KERNEL_ABI_TRACKER_UNKNOWN) {
312 errno = EINVAL;
313 return -1;
314 }
315
316 ret = LTTNG_IOCTL_NO_CHECK(
317 fd, LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS, &args);
318 if (ret == -ENOSYS) {
319 ret = LTTNG_IOCTL_NO_CHECK(fd,
320 LTTNG_KERNEL_ABI_OLD_SESSION_LIST_TRACKER_IDS,
321 &args);
322 }
323
324 return ret;
325 }
326
327 int kernctl_session_regenerate_metadata(int fd)
328 {
329 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_METADATA_REGEN);
330 }
331
332 int kernctl_session_regenerate_statedump(int fd)
333 {
334 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_STATEDUMP);
335 }
336
337 int kernctl_session_set_name(int fd, const char *name)
338 {
339 int ret;
340 struct lttng_kernel_abi_session_name session_name;
341
342 ret = lttng_strncpy(session_name.name, name, sizeof(session_name.name));
343 if (ret) {
344 goto end;
345 }
346
347 ret = LTTNG_IOCTL_CHECK(
348 fd, LTTNG_KERNEL_ABI_SESSION_SET_NAME, &session_name);
349 if (ret == -ENOSYS) {
350 ret = LTTNG_IOCTL_CHECK(fd,
351 LTTNG_KERNEL_ABI_OLD_SESSION_SET_NAME,
352 &session_name);
353 }
354
355 end:
356 return ret;
357 }
358
359 int kernctl_session_set_creation_time(int fd, time_t time)
360 {
361 int ret;
362 struct lttng_kernel_abi_session_creation_time creation_time;
363
364 ret = time_to_iso8601_str(time, creation_time.iso8601,
365 sizeof(creation_time.iso8601));
366 if (ret) {
367 goto end;
368 }
369
370 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME,
371 &creation_time);
372 if (ret == -ENOSYS) {
373 ret = LTTNG_IOCTL_CHECK(fd,
374 LTTNG_KERNEL_ABI_OLD_SESSION_SET_CREATION_TIME,
375 &creation_time);
376 }
377
378 end:
379 return ret;
380 }
381
382 int kernctl_create_stream(int fd)
383 {
384 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_STREAM,
385 LTTNG_KERNEL_ABI_STREAM);
386 }
387
388 int kernctl_create_event(int fd, struct lttng_kernel_abi_event *ev)
389 {
390 if (lttng_kernel_abi_use_old_abi) {
391 struct lttng_kernel_abi_old_event old_event;
392
393 memset(&old_event, 0, sizeof(old_event));
394 memcpy(old_event.name, ev->name, sizeof(old_event.name));
395 old_event.instrumentation = ev->instrumentation;
396 switch (ev->instrumentation) {
397 case LTTNG_KERNEL_ABI_KPROBE:
398 old_event.u.kprobe.addr = ev->u.kprobe.addr;
399 old_event.u.kprobe.offset = ev->u.kprobe.offset;
400 memcpy(old_event.u.kprobe.symbol_name,
401 ev->u.kprobe.symbol_name,
402 sizeof(old_event.u.kprobe.symbol_name));
403 break;
404 case LTTNG_KERNEL_ABI_KRETPROBE:
405 old_event.u.kretprobe.addr = ev->u.kretprobe.addr;
406 old_event.u.kretprobe.offset = ev->u.kretprobe.offset;
407 memcpy(old_event.u.kretprobe.symbol_name,
408 ev->u.kretprobe.symbol_name,
409 sizeof(old_event.u.kretprobe.symbol_name));
410 break;
411 case LTTNG_KERNEL_ABI_FUNCTION:
412 memcpy(old_event.u.ftrace.symbol_name,
413 ev->u.ftrace.symbol_name,
414 sizeof(old_event.u.ftrace.symbol_name));
415 break;
416 default:
417 break;
418 }
419
420 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_OLD_EVENT,
421 &old_event);
422 }
423 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_EVENT, ev);
424 }
425
426 int kernctl_add_context(int fd, struct lttng_kernel_abi_context *ctx)
427 {
428 if (lttng_kernel_abi_use_old_abi) {
429 struct lttng_kernel_abi_old_context old_ctx;
430
431 memset(&old_ctx, 0, sizeof(old_ctx));
432 old_ctx.ctx = ctx->ctx;
433 /* only type that uses the union */
434 if (ctx->ctx == LTTNG_KERNEL_ABI_CONTEXT_PERF_CPU_COUNTER) {
435 old_ctx.u.perf_counter.type =
436 ctx->u.perf_counter.type;
437 old_ctx.u.perf_counter.config =
438 ctx->u.perf_counter.config;
439 memcpy(old_ctx.u.perf_counter.name,
440 ctx->u.perf_counter.name,
441 sizeof(old_ctx.u.perf_counter.name));
442 }
443 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_OLD_CONTEXT,
444 &old_ctx);
445 }
446 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_CONTEXT, ctx);
447 }
448
449
450 /* Enable event, channel and session LTTNG_IOCTL_CHECK */
451 int kernctl_enable(int fd)
452 {
453 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_ENABLE,
454 LTTNG_KERNEL_ABI_ENABLE);
455 }
456
457 /* Disable event, channel and session LTTNG_IOCTL_CHECK */
458 int kernctl_disable(int fd)
459 {
460 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_DISABLE,
461 LTTNG_KERNEL_ABI_DISABLE);
462 }
463
464 int kernctl_start_session(int fd)
465 {
466 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_SESSION_START,
467 LTTNG_KERNEL_ABI_SESSION_START);
468 }
469
470 int kernctl_stop_session(int fd)
471 {
472 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_SESSION_STOP,
473 LTTNG_KERNEL_ABI_SESSION_STOP);
474 }
475
476 int kernctl_create_event_notifier_group(int fd)
477 {
478 return LTTNG_IOCTL_NO_CHECK(fd,
479 LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_CREATE);
480 }
481
482 int kernctl_create_event_notifier_group_notification_fd(int group_fd)
483 {
484 return LTTNG_IOCTL_NO_CHECK(group_fd,
485 LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD);
486 }
487
488 int kernctl_create_event_notifier_group_error_counter(int group_fd,
489 const struct lttng_kernel_abi_counter_conf *error_counter_conf)
490 {
491 return LTTNG_IOCTL_NO_CHECK(group_fd, LTTNG_KERNEL_ABI_COUNTER,
492 error_counter_conf);
493 }
494
495 int kernctl_counter_get_aggregate_value(int counter_fd,
496 struct lttng_kernel_abi_counter_aggregate *value)
497 {
498 return LTTNG_IOCTL_NO_CHECK(counter_fd, LTTNG_KERNEL_ABI_COUNTER_AGGREGATE,
499 value);
500 }
501
502 int kernctl_counter_clear(int counter_fd,
503 struct lttng_kernel_abi_counter_clear *clear)
504 {
505 return LTTNG_IOCTL_NO_CHECK(counter_fd, LTTNG_KERNEL_ABI_COUNTER_CLEAR,
506 clear);
507 }
508
509 int kernctl_create_event_notifier(int group_fd,
510 const struct lttng_kernel_abi_event_notifier *event_notifier)
511 {
512 return LTTNG_IOCTL_NO_CHECK(group_fd,
513 LTTNG_KERNEL_ABI_EVENT_NOTIFIER_CREATE, event_notifier);
514 }
515
516 int kernctl_capture(int fd, const struct lttng_bytecode *capture)
517 {
518 int ret;
519 struct lttng_kernel_abi_capture_bytecode *kb;
520
521 /* Translate bytecode to kernel bytecode. */
522 kb = zmalloc(sizeof(*kb) + capture->len);
523 if (!kb) {
524 ret = -ENOMEM;
525 goto end;
526 }
527
528 kb->len = capture->len;
529 kb->reloc_offset = capture->reloc_table_offset;
530 kb->seqnum = capture->seqnum;
531 memcpy(kb->data, capture->data, capture->len);
532 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_CAPTURE, kb);
533 free(kb);
534 end:
535 return ret;
536 }
537
538 int kernctl_filter(int fd, const struct lttng_bytecode *filter)
539 {
540 struct lttng_kernel_abi_filter_bytecode *kb;
541 uint32_t len;
542 int ret;
543
544 /* Translate bytecode to kernel bytecode */
545 kb = zmalloc(sizeof(*kb) + filter->len);
546 if (!kb)
547 return -ENOMEM;
548 kb->len = len = filter->len;
549 kb->reloc_offset = filter->reloc_table_offset;
550 kb->seqnum = filter->seqnum;
551 memcpy(kb->data, filter->data, len);
552 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_FILTER, kb);
553 free(kb);
554 return ret;
555 }
556
557 int kernctl_add_callsite(int fd, struct lttng_kernel_abi_event_callsite *callsite)
558 {
559 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_ADD_CALLSITE, callsite);
560 }
561
562 int kernctl_tracepoint_list(int fd)
563 {
564 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_TRACEPOINT_LIST,
565 LTTNG_KERNEL_ABI_TRACEPOINT_LIST);
566 }
567
568 int kernctl_syscall_list(int fd)
569 {
570 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_SYSCALL_LIST);
571 }
572
573 int kernctl_tracer_version(int fd, struct lttng_kernel_abi_tracer_version *v)
574 {
575 int ret;
576
577 if (lttng_kernel_abi_use_old_abi == -1) {
578 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_TRACER_VERSION, v);
579 if (!ret) {
580 lttng_kernel_abi_use_old_abi = 0;
581 goto end;
582 }
583 lttng_kernel_abi_use_old_abi = 1;
584 }
585 if (lttng_kernel_abi_use_old_abi) {
586 struct lttng_kernel_abi_old_tracer_version old_v;
587
588 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_OLD_TRACER_VERSION, &old_v);
589 if (ret) {
590 goto end;
591 }
592 v->major = old_v.major;
593 v->minor = old_v.minor;
594 v->patchlevel = old_v.patchlevel;
595 } else {
596 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_TRACER_VERSION, v);
597 }
598
599 end:
600 return ret;
601 }
602
603 int kernctl_tracer_abi_version(int fd,
604 struct lttng_kernel_abi_tracer_abi_version *v)
605 {
606 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_TRACER_ABI_VERSION, v);
607 }
608
609 int kernctl_wait_quiescent(int fd)
610 {
611 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_WAIT_QUIESCENT,
612 LTTNG_KERNEL_ABI_WAIT_QUIESCENT);
613 }
614
615 int kernctl_buffer_flush(int fd)
616 {
617 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH);
618 }
619
620 int kernctl_buffer_flush_empty(int fd)
621 {
622 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY);
623 }
624
625 int kernctl_buffer_clear(int fd)
626 {
627 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_CLEAR);
628 }
629
630 int kernctl_get_next_subbuf_metadata_check(int fd, bool *consistent)
631 {
632 return LTTNG_IOCTL_NO_CHECK(fd,
633 LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK,
634 consistent);
635 }
636
637 /* returns the version of the metadata. */
638 int kernctl_get_metadata_version(int fd, uint64_t *version)
639 {
640 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION,
641 version);
642 }
643
644 int kernctl_metadata_cache_dump(int fd)
645 {
646 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP);
647 }
648
649 /* Buffer operations */
650
651 /* For mmap mode, readable without "get" operation */
652
653 /* returns the length to mmap. */
654 int kernctl_get_mmap_len(int fd, unsigned long *len)
655 {
656 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_MMAP_LEN,
657 len);
658 }
659
660 /* returns the maximum size for sub-buffers. */
661 int kernctl_get_max_subbuf_size(int fd, unsigned long *len)
662 {
663 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_MAX_SUBBUF_SIZE,
664 len);
665 }
666
667 /*
668 * For mmap mode, operate on the current packet (between get/put or
669 * get_next/put_next).
670 */
671
672 /* returns the offset of the subbuffer belonging to the mmap reader. */
673 int kernctl_get_mmap_read_offset(int fd, unsigned long *off)
674 {
675 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_MMAP_READ_OFFSET,
676 off);
677 }
678
679 /* returns the size of the current sub-buffer, without padding (for mmap). */
680 int kernctl_get_subbuf_size(int fd, unsigned long *len)
681 {
682 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF_SIZE,
683 len);
684 }
685
686 /* returns the size of the current sub-buffer, without padding (for mmap). */
687 int kernctl_get_padded_subbuf_size(int fd, unsigned long *len)
688 {
689 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_PADDED_SUBBUF_SIZE,
690 len);
691 }
692
693 /* Get exclusive read access to the next sub-buffer that can be read. */
694 int kernctl_get_next_subbuf(int fd)
695 {
696 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF);
697 }
698
699
700 /* Release exclusive sub-buffer access, move consumer forward. */
701 int kernctl_put_next_subbuf(int fd)
702 {
703 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF);
704 }
705
706 /* snapshot */
707
708 /* Get a snapshot of the current ring buffer producer and consumer positions */
709 int kernctl_snapshot(int fd)
710 {
711 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_SNAPSHOT);
712 }
713
714 /*
715 * Get a snapshot of the current ring buffer producer and consumer positions,
716 * regardless of whether or not the two positions are contained within the
717 * same sub-buffer.
718 */
719 int kernctl_snapshot_sample_positions(int fd)
720 {
721 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS);
722 }
723
724 /* Get the consumer position (iteration start) */
725 int kernctl_snapshot_get_consumed(int fd, unsigned long *pos)
726 {
727 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_SNAPSHOT_GET_CONSUMED,
728 pos);
729 }
730
731 /* Get the producer position (iteration end) */
732 int kernctl_snapshot_get_produced(int fd, unsigned long *pos)
733 {
734 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_SNAPSHOT_GET_PRODUCED,
735 pos);
736 }
737
738 /* Get exclusive read access to the specified sub-buffer position */
739 int kernctl_get_subbuf(int fd, unsigned long *len)
740 {
741 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF,
742 len);
743 }
744
745 /* Release exclusive sub-buffer access */
746 int kernctl_put_subbuf(int fd)
747 {
748 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_PUT_SUBBUF);
749 }
750
751 /* Returns the timestamp begin of the current sub-buffer. */
752 int kernctl_get_timestamp_begin(int fd, uint64_t *timestamp_begin)
753 {
754 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_BEGIN,
755 timestamp_begin);
756 }
757
758 /* Returns the timestamp end of the current sub-buffer. */
759 int kernctl_get_timestamp_end(int fd, uint64_t *timestamp_end)
760 {
761 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_END,
762 timestamp_end);
763 }
764
765 /* Returns the number of discarded events in the current sub-buffer. */
766 int kernctl_get_events_discarded(int fd, uint64_t *events_discarded)
767 {
768 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_EVENTS_DISCARDED,
769 events_discarded);
770 }
771
772 /* Returns the content size in the current sub-buffer. */
773 int kernctl_get_content_size(int fd, uint64_t *content_size)
774 {
775 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_CONTENT_SIZE,
776 content_size);
777 }
778
779 /* Returns the packet size in the current sub-buffer. */
780 int kernctl_get_packet_size(int fd, uint64_t *packet_size)
781 {
782 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_PACKET_SIZE,
783 packet_size);
784 }
785
786 /* Returns the stream id of the current sub-buffer. */
787 int kernctl_get_stream_id(int fd, uint64_t *stream_id)
788 {
789 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_STREAM_ID,
790 stream_id);
791 }
792
793 /* Returns the current timestamp. */
794 int kernctl_get_current_timestamp(int fd, uint64_t *ts)
795 {
796 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP,
797 ts);
798 }
799
800 /* Returns the packet sequence number of the current sub-buffer. */
801 int kernctl_get_sequence_number(int fd, uint64_t *seq)
802 {
803 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_SEQ_NUM,
804 seq);
805 }
806
807 /* Returns the stream instance id. */
808 int kernctl_get_instance_id(int fd, uint64_t *id)
809 {
810 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_INSTANCE_ID,
811 id);
812 }
This page took 0.0743 seconds and 4 git commands to generate.