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