SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / src / common / kernel-ctl / kernel-ctl.c
CommitLineData
ee0326c0 1/*
ab5be9fa
MJ
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>
ee0326c0 5 *
ab5be9fa 6 * SPDX-License-Identifier: GPL-2.0-only
ee0326c0 7 *
ee0326c0 8 */
16421f6e 9
159b042f 10#include "lttng/tracker.h"
6c1c0768 11#define _LGPL_SOURCE
95ba0f2f 12#define __USE_LINUX_IOCTL_DEFS
16421f6e 13#include <sys/ioctl.h>
4dbc372b 14#include <string.h>
46820c8b 15#include <common/align.h>
8ff4109e 16#include <common/macros.h>
00a62084 17#include <errno.h>
a6bd6d9b
JG
18#include <stdarg.h>
19#include <assert.h>
e04b2181 20#include <common/time.h>
16421f6e 21
10a8a223 22#include "kernel-ctl.h"
16421f6e 23#include "kernel-ioctl.h"
16421f6e 24
5226f1bc 25#define LTTNG_IOCTL_CHECK(fildes, request, ...) ({ \
a6bd6d9b
JG
26 int ret = ioctl(fildes, request, ##__VA_ARGS__);\
27 assert(ret <= 0); \
5226f1bc
JG
28 !ret ? 0 : -errno; \
29})
30
31#define LTTNG_IOCTL_NO_CHECK(fildes, request, ...) ({ \
32 int ret = ioctl(fildes, request, ##__VA_ARGS__);\
33 ret >= 0 ? ret : -errno; \
a6bd6d9b
JG
34})
35
4dbc372b
JD
36/*
37 * This flag indicates which version of the kernel ABI to use. The old
38 * ABI (namespace _old) does not support a 32-bit user-space when the
39 * kernel is 64-bit. The old ABI is kept here for compatibility but is
40 * deprecated and will be removed eventually.
41 */
42static int lttng_kernel_use_old_abi = -1;
43
44/*
45 * Execute the new or old ioctl depending on the ABI version.
46 * If the ABI version is not determined yet (lttng_kernel_use_old_abi = -1),
47 * this function tests if the new ABI is available and otherwise fallbacks
48 * on the old one.
49 * This function takes the fd on which the ioctl must be executed and the old
50 * and new request codes.
51 * It returns the return value of the ioctl executed.
52 */
53static inline int compat_ioctl_no_arg(int fd, unsigned long oldname,
54 unsigned long newname)
55{
56 int ret;
57
58 if (lttng_kernel_use_old_abi == -1) {
5226f1bc 59 ret = LTTNG_IOCTL_NO_CHECK(fd, newname);
4dbc372b
JD
60 if (!ret) {
61 lttng_kernel_use_old_abi = 0;
62 goto end;
63 }
64 lttng_kernel_use_old_abi = 1;
65 }
66 if (lttng_kernel_use_old_abi) {
5226f1bc 67 ret = LTTNG_IOCTL_NO_CHECK(fd, oldname);
4dbc372b 68 } else {
5226f1bc 69 ret = LTTNG_IOCTL_NO_CHECK(fd, newname);
4dbc372b
JD
70 }
71
72end:
73 return ret;
74}
75
964ccb60 76int kernctl_create_session(int fd)
d65106b1 77{
4dbc372b
JD
78 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_SESSION,
79 LTTNG_KERNEL_SESSION);
d65106b1
DG
80}
81
964ccb60
MD
82/* open the metadata global channel */
83int kernctl_open_metadata(int fd, struct lttng_channel_attr *chops)
f3ed775e 84{
4dbc372b
JD
85 struct lttng_kernel_channel channel;
86
87 if (lttng_kernel_use_old_abi) {
10600be0
MD
88 struct lttng_kernel_old_channel old_channel;
89
90 memset(&old_channel, 0, sizeof(old_channel));
4dbc372b
JD
91 old_channel.overwrite = chops->overwrite;
92 old_channel.subbuf_size = chops->subbuf_size;
93 old_channel.num_subbuf = chops->num_subbuf;
94 old_channel.switch_timer_interval = chops->switch_timer_interval;
95 old_channel.read_timer_interval = chops->read_timer_interval;
96 old_channel.output = chops->output;
f853c53a
DG
97
98 memset(old_channel.padding, 0, sizeof(old_channel.padding));
99 /*
100 * The new channel padding is smaller than the old ABI so we use the
101 * new ABI padding size for the memcpy.
102 */
103 memcpy(old_channel.padding, chops->padding, sizeof(chops->padding));
4dbc372b 104
5226f1bc
JG
105 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_OLD_METADATA,
106 &old_channel);
4dbc372b
JD
107 }
108
10600be0 109 memset(&channel, 0, sizeof(channel));
4dbc372b
JD
110 channel.overwrite = chops->overwrite;
111 channel.subbuf_size = chops->subbuf_size;
112 channel.num_subbuf = chops->num_subbuf;
113 channel.switch_timer_interval = chops->switch_timer_interval;
114 channel.read_timer_interval = chops->read_timer_interval;
115 channel.output = chops->output;
ea207e3b 116 memcpy(channel.padding, chops->padding, sizeof(chops->padding));
4dbc372b 117
5226f1bc 118 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_METADATA, &channel);
f3ed775e
DG
119}
120
121int kernctl_create_channel(int fd, struct lttng_channel_attr *chops)
16421f6e 122{
4dbc372b
JD
123 struct lttng_kernel_channel channel;
124
c74101ef 125 memset(&channel, 0, sizeof(channel));
4dbc372b
JD
126 if (lttng_kernel_use_old_abi) {
127 struct lttng_kernel_old_channel old_channel;
128
129 old_channel.overwrite = chops->overwrite;
130 old_channel.subbuf_size = chops->subbuf_size;
131 old_channel.num_subbuf = chops->num_subbuf;
132 old_channel.switch_timer_interval = chops->switch_timer_interval;
133 old_channel.read_timer_interval = chops->read_timer_interval;
134 old_channel.output = chops->output;
f853c53a
DG
135
136 memset(old_channel.padding, 0, sizeof(old_channel.padding));
137 /*
138 * The new channel padding is smaller than the old ABI so we use the
139 * new ABI padding size for the memcpy.
140 */
141 memcpy(old_channel.padding, chops->padding, sizeof(chops->padding));
4dbc372b 142
5226f1bc
JG
143 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_OLD_CHANNEL,
144 &old_channel);
4dbc372b
JD
145 }
146
147 channel.overwrite = chops->overwrite;
148 channel.subbuf_size = chops->subbuf_size;
149 channel.num_subbuf = chops->num_subbuf;
150 channel.switch_timer_interval = chops->switch_timer_interval;
151 channel.read_timer_interval = chops->read_timer_interval;
152 channel.output = chops->output;
ea207e3b 153 memcpy(channel.padding, chops->padding, sizeof(chops->padding));
4dbc372b 154
5226f1bc 155 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_CHANNEL, &channel);
16421f6e
DG
156}
157
46820c8b
MD
158int kernctl_syscall_mask(int fd, char **syscall_mask, uint32_t *nr_bits)
159{
160 struct lttng_kernel_syscall_mask kmask_len, *kmask = NULL;
161 size_t array_alloc_len;
162 char *new_mask;
163 int ret = 0;
164
165 if (!syscall_mask) {
166 ret = -1;
167 goto end;
168 }
169
170 if (!nr_bits) {
171 ret = -1;
172 goto end;
173 }
174
175 kmask_len.len = 0;
5226f1bc 176 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SYSCALL_MASK, &kmask_len);
46820c8b
MD
177 if (ret) {
178 goto end;
179 }
180
181 array_alloc_len = ALIGN(kmask_len.len, 8) >> 3;
834978fd 182
46820c8b
MD
183 kmask = zmalloc(sizeof(*kmask) + array_alloc_len);
184 if (!kmask) {
185 ret = -1;
186 goto end;
187 }
188
189 kmask->len = kmask_len.len;
5226f1bc 190 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SYSCALL_MASK, kmask);
46820c8b
MD
191 if (ret) {
192 goto end;
193 }
194
834978fd 195 new_mask = realloc(*syscall_mask, array_alloc_len);
46820c8b
MD
196 if (!new_mask) {
197 ret = -1;
198 goto end;
199 }
200 memcpy(new_mask, kmask->mask, array_alloc_len);
201 *syscall_mask = new_mask;
202 *nr_bits = kmask->len;
203
204end:
205 free(kmask);
206 return ret;
207}
208
ccf10263
MD
209int kernctl_track_pid(int fd, int pid)
210{
5226f1bc 211 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_TRACK_PID, pid);
ccf10263
MD
212}
213
214int kernctl_untrack_pid(int fd, int pid)
215{
5226f1bc 216 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_UNTRACK_PID, pid);
ccf10263
MD
217}
218
a5dfbb9d
MD
219int kernctl_list_tracker_pids(int fd)
220{
5226f1bc 221 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS);
a5dfbb9d
MD
222}
223
d01c0e56 224static enum lttng_kernel_tracker_type get_kernel_tracker_type(
159b042f 225 enum lttng_process_attr process_attr)
d01c0e56 226{
159b042f
JG
227 switch (process_attr) {
228 case LTTNG_PROCESS_ATTR_PROCESS_ID:
d01c0e56 229 return LTTNG_KERNEL_TRACKER_PID;
159b042f 230 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
d01c0e56 231 return LTTNG_KERNEL_TRACKER_VPID;
159b042f 232 case LTTNG_PROCESS_ATTR_USER_ID:
d01c0e56 233 return LTTNG_KERNEL_TRACKER_UID;
159b042f 234 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID:
d01c0e56 235 return LTTNG_KERNEL_TRACKER_VUID;
159b042f 236 case LTTNG_PROCESS_ATTR_GROUP_ID:
d01c0e56 237 return LTTNG_KERNEL_TRACKER_GID;
159b042f 238 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID:
d01c0e56
MD
239 return LTTNG_KERNEL_TRACKER_VGID;
240 default:
241 return LTTNG_KERNEL_TRACKER_UNKNOWN;
242 }
243}
244
159b042f 245int kernctl_track_id(int fd, enum lttng_process_attr process_attr, int id)
d01c0e56
MD
246{
247 struct lttng_kernel_tracker_args args;
248
249 args.id = id;
159b042f 250 args.type = get_kernel_tracker_type(process_attr);
d01c0e56
MD
251 if (args.type == LTTNG_KERNEL_TRACKER_UNKNOWN) {
252 errno = EINVAL;
253 return -1;
254 }
255 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_TRACK_ID, &args);
256}
257
159b042f 258int kernctl_untrack_id(int fd, enum lttng_process_attr process_attr, int id)
d01c0e56
MD
259{
260 struct lttng_kernel_tracker_args args;
261
262 args.id = id;
159b042f 263 args.type = get_kernel_tracker_type(process_attr);
d01c0e56
MD
264 if (args.type == LTTNG_KERNEL_TRACKER_UNKNOWN) {
265 errno = EINVAL;
266 return -1;
267 }
268 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_UNTRACK_ID, &args);
269}
270
159b042f 271int kernctl_list_tracker_ids(int fd, enum lttng_process_attr process_attr)
d01c0e56
MD
272{
273 struct lttng_kernel_tracker_args args;
274
275 args.id = -1;
159b042f 276 args.type = get_kernel_tracker_type(process_attr);
d01c0e56
MD
277 if (args.type == LTTNG_KERNEL_TRACKER_UNKNOWN) {
278 errno = EINVAL;
279 return -1;
280 }
281 return LTTNG_IOCTL_NO_CHECK(
282 fd, LTTNG_KERNEL_SESSION_LIST_TRACKER_IDS, &args);
283}
284
eded6438 285int kernctl_session_regenerate_metadata(int fd)
93ec662e 286{
5226f1bc 287 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_METADATA_REGEN);
93ec662e
JD
288}
289
c2561365
JD
290int kernctl_session_regenerate_statedump(int fd)
291{
292 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_STATEDUMP);
293}
294
8ff4109e
JR
295int kernctl_session_set_name(int fd, const char *name)
296{
297 int ret;
298 struct lttng_kernel_session_name session_name;
299
300 ret = lttng_strncpy(session_name.name, name, sizeof(session_name.name));
301 if (ret) {
302 goto end;
303 }
304
305 ret = LTTNG_IOCTL_CHECK(
306 fd, LTTNG_KERNEL_SESSION_SET_NAME, &session_name);
307end:
308 return ret;
309}
310
e04b2181
JR
311int kernctl_session_set_creation_time(int fd, time_t time)
312{
313 int ret;
314 struct lttng_kernel_session_creation_time creation_time;
315
316 ret = time_to_iso8601_str(time, creation_time.iso8601,
317 sizeof(creation_time.iso8601));
318 if (ret) {
319 goto end;
320 }
321
322 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_SESSION_SET_CREATION_TIME,
323 &creation_time);
324end:
325 return ret;
326}
327
964ccb60 328int kernctl_create_stream(int fd)
16421f6e 329{
4dbc372b
JD
330 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_STREAM,
331 LTTNG_KERNEL_STREAM);
16421f6e
DG
332}
333
964ccb60 334int kernctl_create_event(int fd, struct lttng_kernel_event *ev)
16421f6e 335{
4dbc372b
JD
336 if (lttng_kernel_use_old_abi) {
337 struct lttng_kernel_old_event old_event;
338
10600be0 339 memset(&old_event, 0, sizeof(old_event));
4dbc372b
JD
340 memcpy(old_event.name, ev->name, sizeof(old_event.name));
341 old_event.instrumentation = ev->instrumentation;
342 switch (ev->instrumentation) {
343 case LTTNG_KERNEL_KPROBE:
344 old_event.u.kprobe.addr = ev->u.kprobe.addr;
345 old_event.u.kprobe.offset = ev->u.kprobe.offset;
346 memcpy(old_event.u.kprobe.symbol_name,
347 ev->u.kprobe.symbol_name,
348 sizeof(old_event.u.kprobe.symbol_name));
349 break;
350 case LTTNG_KERNEL_KRETPROBE:
351 old_event.u.kretprobe.addr = ev->u.kretprobe.addr;
352 old_event.u.kretprobe.offset = ev->u.kretprobe.offset;
353 memcpy(old_event.u.kretprobe.symbol_name,
354 ev->u.kretprobe.symbol_name,
355 sizeof(old_event.u.kretprobe.symbol_name));
356 break;
357 case LTTNG_KERNEL_FUNCTION:
358 memcpy(old_event.u.ftrace.symbol_name,
359 ev->u.ftrace.symbol_name,
360 sizeof(old_event.u.ftrace.symbol_name));
361 break;
362 default:
363 break;
364 }
365
5226f1bc
JG
366 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_OLD_EVENT,
367 &old_event);
4dbc372b 368 }
5226f1bc 369 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_EVENT, ev);
16421f6e
DG
370}
371
964ccb60 372int kernctl_add_context(int fd, struct lttng_kernel_context *ctx)
16421f6e 373{
4dbc372b
JD
374 if (lttng_kernel_use_old_abi) {
375 struct lttng_kernel_old_context old_ctx;
376
10600be0 377 memset(&old_ctx, 0, sizeof(old_ctx));
4dbc372b
JD
378 old_ctx.ctx = ctx->ctx;
379 /* only type that uses the union */
aa3514e9 380 if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER) {
4dbc372b
JD
381 old_ctx.u.perf_counter.type =
382 ctx->u.perf_counter.type;
383 old_ctx.u.perf_counter.config =
384 ctx->u.perf_counter.config;
385 memcpy(old_ctx.u.perf_counter.name,
386 ctx->u.perf_counter.name,
387 sizeof(old_ctx.u.perf_counter.name));
388 }
5226f1bc 389 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_OLD_CONTEXT, &old_ctx);
4dbc372b 390 }
5226f1bc 391 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_CONTEXT, ctx);
16421f6e
DG
392}
393
964ccb60 394
5226f1bc 395/* Enable event, channel and session LTTNG_IOCTL_CHECK */
f3ed775e
DG
396int kernctl_enable(int fd)
397{
4dbc372b
JD
398 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_ENABLE,
399 LTTNG_KERNEL_ENABLE);
f3ed775e
DG
400}
401
5226f1bc 402/* Disable event, channel and session LTTNG_IOCTL_CHECK */
f3ed775e
DG
403int kernctl_disable(int fd)
404{
4dbc372b
JD
405 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_DISABLE,
406 LTTNG_KERNEL_DISABLE);
f3ed775e
DG
407}
408
964ccb60 409int kernctl_start_session(int fd)
16421f6e 410{
4dbc372b
JD
411 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_SESSION_START,
412 LTTNG_KERNEL_SESSION_START);
964ccb60
MD
413}
414
415int kernctl_stop_session(int fd)
416{
4dbc372b
JD
417 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_SESSION_STOP,
418 LTTNG_KERNEL_SESSION_STOP);
16421f6e
DG
419}
420
2463b787
JR
421int kernctl_create_trigger_group(int fd)
422{
423 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_TRIGGER_GROUP_CREATE);
424}
425
426int kernctl_create_trigger_group_notification_fd(int group_fd)
427{
428 return LTTNG_IOCTL_NO_CHECK(group_fd, LTTNG_KERNEL_TRIGGER_GROUP_NOTIFICATION_FD);
429}
430
431int kernctl_create_trigger_group_error_counter(int group_fd, struct lttng_kernel_counter_conf *error_counter_conf)
432{
433 return LTTNG_IOCTL_NO_CHECK(group_fd, LTTNG_KERNEL_COUNTER, error_counter_conf);
434}
435
436int kernctl_counter_get_value(int counter_fd, struct lttng_kernel_counter_value *value)
437{
438 return LTTNG_IOCTL_NO_CHECK(counter_fd, LTTNG_KERNEL_COUNTER_VALUE, value);
439}
440
441int kernctl_create_trigger(int group_fd, struct lttng_kernel_trigger *trigger)
442{
443 return LTTNG_IOCTL_NO_CHECK(group_fd, LTTNG_KERNEL_TRIGGER_CREATE, trigger);
444}
445
446int kernctl_capture(int fd, const struct lttng_bytecode *capture)
447{
448 struct lttng_kernel_capture_bytecode *kb;
449 uint32_t len;
450 int ret;
451
452 /* Translate bytecode to kernel bytecode */
453 kb = zmalloc(sizeof(*kb) + capture->len);
454 if (!kb)
455 return -ENOMEM;
456 kb->len = len = capture->len;
457 kb->reloc_offset = capture->reloc_table_offset;
458 kb->seqnum = capture->seqnum;
459 memcpy(kb->data, capture->data, len);
460 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_CAPTURE, kb);
461 free(kb);
462 return ret;
463}
464
465int kernctl_filter(int fd, const struct lttng_bytecode *filter)
00a62084
MD
466{
467 struct lttng_kernel_filter_bytecode *kb;
468 uint32_t len;
469 int ret;
470
471 /* Translate bytecode to kernel bytecode */
472 kb = zmalloc(sizeof(*kb) + filter->len);
473 if (!kb)
474 return -ENOMEM;
475 kb->len = len = filter->len;
476 kb->reloc_offset = filter->reloc_table_offset;
477 kb->seqnum = filter->seqnum;
478 memcpy(kb->data, filter->data, len);
5226f1bc 479 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_FILTER, kb);
00a62084
MD
480 free(kb);
481 return ret;
482}
483
1ab8c2ad
FD
484int kernctl_add_callsite(int fd, struct lttng_kernel_event_callsite *callsite)
485{
486 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ADD_CALLSITE, callsite);
487}
488
964ccb60
MD
489int kernctl_tracepoint_list(int fd)
490{
4dbc372b
JD
491 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_TRACEPOINT_LIST,
492 LTTNG_KERNEL_TRACEPOINT_LIST);
964ccb60
MD
493}
494
d02666a9
MD
495int kernctl_syscall_list(int fd)
496{
5226f1bc 497 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_SYSCALL_LIST);
d02666a9
MD
498}
499
964ccb60
MD
500int kernctl_tracer_version(int fd, struct lttng_kernel_tracer_version *v)
501{
4dbc372b
JD
502 int ret;
503
504 if (lttng_kernel_use_old_abi == -1) {
5226f1bc 505 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_TRACER_VERSION, v);
4dbc372b
JD
506 if (!ret) {
507 lttng_kernel_use_old_abi = 0;
508 goto end;
509 }
510 lttng_kernel_use_old_abi = 1;
511 }
512 if (lttng_kernel_use_old_abi) {
513 struct lttng_kernel_old_tracer_version old_v;
514
5226f1bc 515 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_OLD_TRACER_VERSION, &old_v);
4dbc372b
JD
516 if (ret) {
517 goto end;
518 }
519 v->major = old_v.major;
520 v->minor = old_v.minor;
521 v->patchlevel = old_v.patchlevel;
522 } else {
5226f1bc 523 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_TRACER_VERSION, v);
4dbc372b
JD
524 }
525
526end:
527 return ret;
964ccb60
MD
528}
529
c052142c
MD
530int kernctl_tracer_abi_version(int fd,
531 struct lttng_kernel_tracer_abi_version *v)
532{
5226f1bc 533 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_TRACER_ABI_VERSION, v);
c052142c
MD
534}
535
964ccb60
MD
536int kernctl_wait_quiescent(int fd)
537{
4dbc372b
JD
538 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_WAIT_QUIESCENT,
539 LTTNG_KERNEL_WAIT_QUIESCENT);
964ccb60
MD
540}
541
964ccb60
MD
542int kernctl_buffer_flush(int fd)
543{
5226f1bc 544 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_FLUSH);
964ccb60
MD
545}
546
f22dd891
MD
547int kernctl_buffer_flush_empty(int fd)
548{
549 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_FLUSH_EMPTY);
550}
551
99930a9d
JR
552int kernctl_buffer_clear(int fd)
553{
554 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_CLEAR);
555}
556
41dc93d9
JG
557int kernctl_get_next_subbuf_metadata_check(int fd, bool *consistent)
558{
559 return LTTNG_IOCTL_NO_CHECK(fd,
560 RING_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK,
561 consistent);
562}
563
93ec662e
JD
564/* returns the version of the metadata. */
565int kernctl_get_metadata_version(int fd, uint64_t *version)
566{
5226f1bc 567 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_METADATA_VERSION, version);
93ec662e
JD
568}
569
8024cc8c
JD
570int kernctl_metadata_cache_dump(int fd)
571{
572 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_METADATA_CACHE_DUMP);
573}
964ccb60
MD
574
575/* Buffer operations */
576
577/* For mmap mode, readable without "get" operation */
578
16421f6e
DG
579/* returns the length to mmap. */
580int kernctl_get_mmap_len(int fd, unsigned long *len)
581{
5226f1bc 582 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_MMAP_LEN, len);
16421f6e
DG
583}
584
964ccb60
MD
585/* returns the maximum size for sub-buffers. */
586int kernctl_get_max_subbuf_size(int fd, unsigned long *len)
587{
5226f1bc 588 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_MAX_SUBBUF_SIZE, len);
964ccb60
MD
589}
590
591/*
592 * For mmap mode, operate on the current packet (between get/put or
593 * get_next/put_next).
594 */
595
16421f6e
DG
596/* returns the offset of the subbuffer belonging to the mmap reader. */
597int kernctl_get_mmap_read_offset(int fd, unsigned long *off)
598{
5226f1bc 599 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_MMAP_READ_OFFSET, off);
16421f6e
DG
600}
601
964ccb60
MD
602/* returns the size of the current sub-buffer, without padding (for mmap). */
603int kernctl_get_subbuf_size(int fd, unsigned long *len)
16421f6e 604{
5226f1bc 605 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_SUBBUF_SIZE, len);
16421f6e
DG
606}
607
608/* returns the size of the current sub-buffer, without padding (for mmap). */
609int kernctl_get_padded_subbuf_size(int fd, unsigned long *len)
610{
5226f1bc 611 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_PADDED_SUBBUF_SIZE, len);
16421f6e
DG
612}
613
964ccb60
MD
614/* Get exclusive read access to the next sub-buffer that can be read. */
615int kernctl_get_next_subbuf(int fd)
16421f6e 616{
5226f1bc 617 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_NEXT_SUBBUF);
16421f6e
DG
618}
619
d4a1283e 620
16421f6e
DG
621/* Release exclusive sub-buffer access, move consumer forward. */
622int kernctl_put_next_subbuf(int fd)
623{
5226f1bc 624 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_PUT_NEXT_SUBBUF);
16421f6e
DG
625}
626
964ccb60 627/* snapshot */
16421f6e
DG
628
629/* Get a snapshot of the current ring buffer producer and consumer positions */
630int kernctl_snapshot(int fd)
631{
5226f1bc 632 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_SNAPSHOT);
16421f6e
DG
633}
634
b007ec59
JG
635/*
636 * Get a snapshot of the current ring buffer producer and consumer positions,
637 * regardless of whether or not the two positions are contained within the
638 * same sub-buffer.
639 */
640int kernctl_snapshot_sample_positions(int fd)
641{
642 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS);
643}
644
16421f6e
DG
645/* Get the consumer position (iteration start) */
646int kernctl_snapshot_get_consumed(int fd, unsigned long *pos)
647{
5226f1bc 648 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_SNAPSHOT_GET_CONSUMED, pos);
16421f6e
DG
649}
650
651/* Get the producer position (iteration end) */
652int kernctl_snapshot_get_produced(int fd, unsigned long *pos)
653{
5226f1bc 654 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_SNAPSHOT_GET_PRODUCED, pos);
16421f6e
DG
655}
656
964ccb60
MD
657/* Get exclusive read access to the specified sub-buffer position */
658int kernctl_get_subbuf(int fd, unsigned long *len)
f3ed775e 659{
5226f1bc 660 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_SUBBUF, len);
f3ed775e 661}
d0254c7c 662
964ccb60
MD
663/* Release exclusive sub-buffer access */
664int kernctl_put_subbuf(int fd)
d0254c7c 665{
5226f1bc 666 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_PUT_SUBBUF);
d0254c7c 667}
309167d2
JD
668
669/* Returns the timestamp begin of the current sub-buffer. */
670int kernctl_get_timestamp_begin(int fd, uint64_t *timestamp_begin)
671{
5226f1bc 672 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN,
a6bd6d9b 673 timestamp_begin);
309167d2
JD
674}
675
676/* Returns the timestamp end of the current sub-buffer. */
677int kernctl_get_timestamp_end(int fd, uint64_t *timestamp_end)
678{
5226f1bc 679 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_TIMESTAMP_END,
a6bd6d9b 680 timestamp_end);
309167d2
JD
681}
682
683/* Returns the number of discarded events in the current sub-buffer. */
684int kernctl_get_events_discarded(int fd, uint64_t *events_discarded)
685{
5226f1bc 686 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED,
a6bd6d9b 687 events_discarded);
309167d2
JD
688}
689
690/* Returns the content size in the current sub-buffer. */
691int kernctl_get_content_size(int fd, uint64_t *content_size)
692{
5226f1bc 693 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_CONTENT_SIZE,
a6bd6d9b 694 content_size);
309167d2
JD
695}
696
697/* Returns the packet size in the current sub-buffer. */
698int kernctl_get_packet_size(int fd, uint64_t *packet_size)
699{
5226f1bc
JG
700 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_PACKET_SIZE,
701 packet_size);
309167d2
JD
702}
703
704/* Returns the stream id of the current sub-buffer. */
705int kernctl_get_stream_id(int fd, uint64_t *stream_id)
706{
5226f1bc
JG
707 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_STREAM_ID,
708 stream_id);
309167d2 709}
d3e2ba59
JD
710
711/* Returns the current timestamp. */
712int kernctl_get_current_timestamp(int fd, uint64_t *ts)
713{
5226f1bc
JG
714 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP,
715 ts);
d3e2ba59 716}
fb83fe64
JD
717
718/* Returns the packet sequence number of the current sub-buffer. */
719int kernctl_get_sequence_number(int fd, uint64_t *seq)
720{
5226f1bc 721 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_SEQ_NUM, seq);
fb83fe64 722}
000fa86f
JD
723
724/* Returns the stream instance id. */
725int kernctl_get_instance_id(int fd, uint64_t *id)
726{
5226f1bc 727 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_INSTANCE_ID, id);
000fa86f 728}
This page took 0.186468 seconds and 5 git commands to generate.