SoW-2019-0002: Dynamic Snapshot
[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
1831ae68
FD
420int kernctl_create_trigger_group(int fd)
421{
422 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_TRIGGER_GROUP_CREATE);
423}
424
425int kernctl_create_trigger_group_notification_fd(int group_fd)
426{
427 return LTTNG_IOCTL_NO_CHECK(group_fd, LTTNG_KERNEL_TRIGGER_GROUP_NOTIFICATION_FD);
428}
429
430int kernctl_create_trigger(int group_fd, struct lttng_kernel_trigger *trigger)
431{
432 return LTTNG_IOCTL_NO_CHECK(group_fd, LTTNG_KERNEL_TRIGGER_CREATE, trigger);
433}
434
435int kernctl_filter(int fd, const struct lttng_filter_bytecode *filter)
00a62084
MD
436{
437 struct lttng_kernel_filter_bytecode *kb;
438 uint32_t len;
439 int ret;
440
441 /* Translate bytecode to kernel bytecode */
442 kb = zmalloc(sizeof(*kb) + filter->len);
443 if (!kb)
444 return -ENOMEM;
445 kb->len = len = filter->len;
446 kb->reloc_offset = filter->reloc_table_offset;
447 kb->seqnum = filter->seqnum;
448 memcpy(kb->data, filter->data, len);
5226f1bc 449 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_FILTER, kb);
00a62084
MD
450 free(kb);
451 return ret;
452}
453
1ab8c2ad
FD
454int kernctl_add_callsite(int fd, struct lttng_kernel_event_callsite *callsite)
455{
456 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ADD_CALLSITE, callsite);
457}
458
964ccb60
MD
459int kernctl_tracepoint_list(int fd)
460{
4dbc372b
JD
461 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_TRACEPOINT_LIST,
462 LTTNG_KERNEL_TRACEPOINT_LIST);
964ccb60
MD
463}
464
d02666a9
MD
465int kernctl_syscall_list(int fd)
466{
5226f1bc 467 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_SYSCALL_LIST);
d02666a9
MD
468}
469
964ccb60
MD
470int kernctl_tracer_version(int fd, struct lttng_kernel_tracer_version *v)
471{
4dbc372b
JD
472 int ret;
473
474 if (lttng_kernel_use_old_abi == -1) {
5226f1bc 475 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_TRACER_VERSION, v);
4dbc372b
JD
476 if (!ret) {
477 lttng_kernel_use_old_abi = 0;
478 goto end;
479 }
480 lttng_kernel_use_old_abi = 1;
481 }
482 if (lttng_kernel_use_old_abi) {
483 struct lttng_kernel_old_tracer_version old_v;
484
5226f1bc 485 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_OLD_TRACER_VERSION, &old_v);
4dbc372b
JD
486 if (ret) {
487 goto end;
488 }
489 v->major = old_v.major;
490 v->minor = old_v.minor;
491 v->patchlevel = old_v.patchlevel;
492 } else {
5226f1bc 493 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_TRACER_VERSION, v);
4dbc372b
JD
494 }
495
496end:
497 return ret;
964ccb60
MD
498}
499
c052142c
MD
500int kernctl_tracer_abi_version(int fd,
501 struct lttng_kernel_tracer_abi_version *v)
502{
5226f1bc 503 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_TRACER_ABI_VERSION, v);
c052142c
MD
504}
505
964ccb60
MD
506int kernctl_wait_quiescent(int fd)
507{
4dbc372b
JD
508 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_WAIT_QUIESCENT,
509 LTTNG_KERNEL_WAIT_QUIESCENT);
964ccb60
MD
510}
511
964ccb60
MD
512int kernctl_buffer_flush(int fd)
513{
5226f1bc 514 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_FLUSH);
964ccb60
MD
515}
516
f22dd891
MD
517int kernctl_buffer_flush_empty(int fd)
518{
519 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_FLUSH_EMPTY);
520}
521
99930a9d
JR
522int kernctl_buffer_clear(int fd)
523{
524 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_CLEAR);
525}
526
93ec662e
JD
527/* returns the version of the metadata. */
528int kernctl_get_metadata_version(int fd, uint64_t *version)
529{
5226f1bc 530 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_METADATA_VERSION, version);
93ec662e
JD
531}
532
8024cc8c
JD
533int kernctl_metadata_cache_dump(int fd)
534{
535 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_METADATA_CACHE_DUMP);
536}
964ccb60
MD
537
538/* Buffer operations */
539
540/* For mmap mode, readable without "get" operation */
541
16421f6e
DG
542/* returns the length to mmap. */
543int kernctl_get_mmap_len(int fd, unsigned long *len)
544{
5226f1bc 545 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_MMAP_LEN, len);
16421f6e
DG
546}
547
964ccb60
MD
548/* returns the maximum size for sub-buffers. */
549int kernctl_get_max_subbuf_size(int fd, unsigned long *len)
550{
5226f1bc 551 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_MAX_SUBBUF_SIZE, len);
964ccb60
MD
552}
553
554/*
555 * For mmap mode, operate on the current packet (between get/put or
556 * get_next/put_next).
557 */
558
16421f6e
DG
559/* returns the offset of the subbuffer belonging to the mmap reader. */
560int kernctl_get_mmap_read_offset(int fd, unsigned long *off)
561{
5226f1bc 562 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_MMAP_READ_OFFSET, off);
16421f6e
DG
563}
564
964ccb60
MD
565/* returns the size of the current sub-buffer, without padding (for mmap). */
566int kernctl_get_subbuf_size(int fd, unsigned long *len)
16421f6e 567{
5226f1bc 568 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_SUBBUF_SIZE, len);
16421f6e
DG
569}
570
571/* returns the size of the current sub-buffer, without padding (for mmap). */
572int kernctl_get_padded_subbuf_size(int fd, unsigned long *len)
573{
5226f1bc 574 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_PADDED_SUBBUF_SIZE, len);
16421f6e
DG
575}
576
964ccb60
MD
577/* Get exclusive read access to the next sub-buffer that can be read. */
578int kernctl_get_next_subbuf(int fd)
16421f6e 579{
5226f1bc 580 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_NEXT_SUBBUF);
16421f6e
DG
581}
582
d4a1283e 583
16421f6e
DG
584/* Release exclusive sub-buffer access, move consumer forward. */
585int kernctl_put_next_subbuf(int fd)
586{
5226f1bc 587 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_PUT_NEXT_SUBBUF);
16421f6e
DG
588}
589
964ccb60 590/* snapshot */
16421f6e
DG
591
592/* Get a snapshot of the current ring buffer producer and consumer positions */
593int kernctl_snapshot(int fd)
594{
5226f1bc 595 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_SNAPSHOT);
16421f6e
DG
596}
597
b007ec59
JG
598/*
599 * Get a snapshot of the current ring buffer producer and consumer positions,
600 * regardless of whether or not the two positions are contained within the
601 * same sub-buffer.
602 */
603int kernctl_snapshot_sample_positions(int fd)
604{
605 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS);
606}
607
16421f6e
DG
608/* Get the consumer position (iteration start) */
609int kernctl_snapshot_get_consumed(int fd, unsigned long *pos)
610{
5226f1bc 611 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_SNAPSHOT_GET_CONSUMED, pos);
16421f6e
DG
612}
613
614/* Get the producer position (iteration end) */
615int kernctl_snapshot_get_produced(int fd, unsigned long *pos)
616{
5226f1bc 617 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_SNAPSHOT_GET_PRODUCED, pos);
16421f6e
DG
618}
619
964ccb60
MD
620/* Get exclusive read access to the specified sub-buffer position */
621int kernctl_get_subbuf(int fd, unsigned long *len)
f3ed775e 622{
5226f1bc 623 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_GET_SUBBUF, len);
f3ed775e 624}
d0254c7c 625
964ccb60
MD
626/* Release exclusive sub-buffer access */
627int kernctl_put_subbuf(int fd)
d0254c7c 628{
5226f1bc 629 return LTTNG_IOCTL_CHECK(fd, RING_BUFFER_PUT_SUBBUF);
d0254c7c 630}
309167d2
JD
631
632/* Returns the timestamp begin of the current sub-buffer. */
633int kernctl_get_timestamp_begin(int fd, uint64_t *timestamp_begin)
634{
5226f1bc 635 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN,
a6bd6d9b 636 timestamp_begin);
309167d2
JD
637}
638
639/* Returns the timestamp end of the current sub-buffer. */
640int kernctl_get_timestamp_end(int fd, uint64_t *timestamp_end)
641{
5226f1bc 642 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_TIMESTAMP_END,
a6bd6d9b 643 timestamp_end);
309167d2
JD
644}
645
646/* Returns the number of discarded events in the current sub-buffer. */
647int kernctl_get_events_discarded(int fd, uint64_t *events_discarded)
648{
5226f1bc 649 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED,
a6bd6d9b 650 events_discarded);
309167d2
JD
651}
652
653/* Returns the content size in the current sub-buffer. */
654int kernctl_get_content_size(int fd, uint64_t *content_size)
655{
5226f1bc 656 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_CONTENT_SIZE,
a6bd6d9b 657 content_size);
309167d2
JD
658}
659
660/* Returns the packet size in the current sub-buffer. */
661int kernctl_get_packet_size(int fd, uint64_t *packet_size)
662{
5226f1bc
JG
663 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_PACKET_SIZE,
664 packet_size);
309167d2
JD
665}
666
667/* Returns the stream id of the current sub-buffer. */
668int kernctl_get_stream_id(int fd, uint64_t *stream_id)
669{
5226f1bc
JG
670 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_STREAM_ID,
671 stream_id);
309167d2 672}
d3e2ba59
JD
673
674/* Returns the current timestamp. */
675int kernctl_get_current_timestamp(int fd, uint64_t *ts)
676{
5226f1bc
JG
677 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP,
678 ts);
d3e2ba59 679}
fb83fe64
JD
680
681/* Returns the packet sequence number of the current sub-buffer. */
682int kernctl_get_sequence_number(int fd, uint64_t *seq)
683{
5226f1bc 684 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_GET_SEQ_NUM, seq);
fb83fe64 685}
000fa86f
JD
686
687/* Returns the stream instance id. */
688int kernctl_get_instance_id(int fd, uint64_t *id)
689{
5226f1bc 690 return LTTNG_IOCTL_CHECK(fd, LTTNG_RING_BUFFER_INSTANCE_ID, id);
000fa86f 691}
This page took 0.173755 seconds and 5 git commands to generate.