Cleanup: namespace 'align' macros
[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>
edf4b93e 17#include <common/compat/errno.h>
a6bd6d9b 18#include <stdarg.h>
e04b2181 19#include <common/time.h>
16421f6e 20
10a8a223 21#include "kernel-ctl.h"
16421f6e 22#include "kernel-ioctl.h"
16421f6e 23
9074be22
SM
24#define LTTNG_IOCTL_CHECK(fildes, request, ...) \
25 ({ \
26 int _ioctl_ret = ioctl(fildes, request, ##__VA_ARGS__); \
a0377dfe 27 LTTNG_ASSERT(_ioctl_ret <= 0); \
9074be22
SM
28 !_ioctl_ret ? 0 : -errno; \
29 })
5226f1bc 30
9074be22
SM
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 })
a6bd6d9b 36
4dbc372b
JD
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 */
b8e2fb80 43static int lttng_kernel_abi_use_old_abi = -1;
4dbc372b
JD
44
45/*
46 * Execute the new or old ioctl depending on the ABI version.
b8e2fb80 47 * If the ABI version is not determined yet (lttng_kernel_abi_use_old_abi = -1),
4dbc372b
JD
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 */
54static inline int compat_ioctl_no_arg(int fd, unsigned long oldname,
55 unsigned long newname)
56{
57 int ret;
58
b8e2fb80 59 if (lttng_kernel_abi_use_old_abi == -1) {
5226f1bc 60 ret = LTTNG_IOCTL_NO_CHECK(fd, newname);
4dbc372b 61 if (!ret) {
b8e2fb80 62 lttng_kernel_abi_use_old_abi = 0;
4dbc372b
JD
63 goto end;
64 }
b8e2fb80 65 lttng_kernel_abi_use_old_abi = 1;
4dbc372b 66 }
b8e2fb80 67 if (lttng_kernel_abi_use_old_abi) {
5226f1bc 68 ret = LTTNG_IOCTL_NO_CHECK(fd, oldname);
4dbc372b 69 } else {
5226f1bc 70 ret = LTTNG_IOCTL_NO_CHECK(fd, newname);
4dbc372b
JD
71 }
72
73end:
74 return ret;
75}
76
964ccb60 77int kernctl_create_session(int fd)
d65106b1 78{
b8e2fb80
FD
79 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_SESSION,
80 LTTNG_KERNEL_ABI_SESSION);
d65106b1
DG
81}
82
964ccb60
MD
83/* open the metadata global channel */
84int kernctl_open_metadata(int fd, struct lttng_channel_attr *chops)
f3ed775e 85{
b8e2fb80 86 struct lttng_kernel_abi_channel channel;
4dbc372b 87
b8e2fb80
FD
88 if (lttng_kernel_abi_use_old_abi) {
89 struct lttng_kernel_abi_old_channel old_channel;
10600be0
MD
90
91 memset(&old_channel, 0, sizeof(old_channel));
4dbc372b
JD
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;
f853c53a
DG
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));
4dbc372b 105
b8e2fb80 106 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_OLD_METADATA,
5226f1bc 107 &old_channel);
4dbc372b
JD
108 }
109
10600be0 110 memset(&channel, 0, sizeof(channel));
4dbc372b
JD
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;
ea207e3b 117 memcpy(channel.padding, chops->padding, sizeof(chops->padding));
4dbc372b 118
b8e2fb80 119 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_METADATA, &channel);
f3ed775e
DG
120}
121
122int kernctl_create_channel(int fd, struct lttng_channel_attr *chops)
16421f6e 123{
b8e2fb80 124 struct lttng_kernel_abi_channel channel;
4dbc372b 125
c74101ef 126 memset(&channel, 0, sizeof(channel));
b8e2fb80
FD
127 if (lttng_kernel_abi_use_old_abi) {
128 struct lttng_kernel_abi_old_channel old_channel;
4dbc372b
JD
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;
f853c53a
DG
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));
4dbc372b 143
b8e2fb80 144 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_OLD_CHANNEL,
5226f1bc 145 &old_channel);
4dbc372b
JD
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;
ea207e3b 154 memcpy(channel.padding, chops->padding, sizeof(chops->padding));
4dbc372b 155
b8e2fb80 156 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_CHANNEL, &channel);
16421f6e
DG
157}
158
46820c8b
MD
159int kernctl_syscall_mask(int fd, char **syscall_mask, uint32_t *nr_bits)
160{
b8e2fb80 161 struct lttng_kernel_abi_syscall_mask kmask_len, *kmask = NULL;
46820c8b
MD
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;
b8e2fb80 177 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SYSCALL_MASK, &kmask_len);
46820c8b
MD
178 if (ret) {
179 goto end;
180 }
181
1cbd136b 182 array_alloc_len = lttng_align_ceil(kmask_len.len, 8) >> 3;
834978fd 183
46820c8b
MD
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;
b8e2fb80 191 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SYSCALL_MASK, kmask);
46820c8b
MD
192 if (ret) {
193 goto end;
194 }
195
834978fd 196 new_mask = realloc(*syscall_mask, array_alloc_len);
46820c8b
MD
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
205end:
206 free(kmask);
207 return ret;
208}
209
ccf10263
MD
210int kernctl_track_pid(int fd, int pid)
211{
acbe1c12
FD
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;
ccf10263
MD
221}
222
223int kernctl_untrack_pid(int fd, int pid)
224{
acbe1c12
FD
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;
ccf10263
MD
234}
235
a5dfbb9d
MD
236int kernctl_list_tracker_pids(int fd)
237{
b8e2fb80 238 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_PIDS);
a5dfbb9d
MD
239}
240
b8e2fb80 241static enum lttng_kernel_abi_tracker_type get_kernel_tracker_type(
159b042f 242 enum lttng_process_attr process_attr)
d01c0e56 243{
159b042f
JG
244 switch (process_attr) {
245 case LTTNG_PROCESS_ATTR_PROCESS_ID:
b8e2fb80 246 return LTTNG_KERNEL_ABI_TRACKER_PID;
159b042f 247 case LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID:
b8e2fb80 248 return LTTNG_KERNEL_ABI_TRACKER_VPID;
159b042f 249 case LTTNG_PROCESS_ATTR_USER_ID:
b8e2fb80 250 return LTTNG_KERNEL_ABI_TRACKER_UID;
159b042f 251 case LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID:
b8e2fb80 252 return LTTNG_KERNEL_ABI_TRACKER_VUID;
159b042f 253 case LTTNG_PROCESS_ATTR_GROUP_ID:
b8e2fb80 254 return LTTNG_KERNEL_ABI_TRACKER_GID;
159b042f 255 case LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID:
b8e2fb80 256 return LTTNG_KERNEL_ABI_TRACKER_VGID;
d01c0e56 257 default:
b8e2fb80 258 return LTTNG_KERNEL_ABI_TRACKER_UNKNOWN;
d01c0e56
MD
259 }
260}
261
159b042f 262int kernctl_track_id(int fd, enum lttng_process_attr process_attr, int id)
d01c0e56 263{
b8e2fb80 264 struct lttng_kernel_abi_tracker_args args;
acbe1c12 265 int ret;
d01c0e56
MD
266
267 args.id = id;
159b042f 268 args.type = get_kernel_tracker_type(process_attr);
b8e2fb80 269 if (args.type == LTTNG_KERNEL_ABI_TRACKER_UNKNOWN) {
d01c0e56
MD
270 errno = EINVAL;
271 return -1;
272 }
acbe1c12
FD
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;
d01c0e56
MD
281}
282
159b042f 283int kernctl_untrack_id(int fd, enum lttng_process_attr process_attr, int id)
d01c0e56 284{
b8e2fb80 285 struct lttng_kernel_abi_tracker_args args;
acbe1c12 286 int ret;
d01c0e56
MD
287
288 args.id = id;
159b042f 289 args.type = get_kernel_tracker_type(process_attr);
b8e2fb80 290 if (args.type == LTTNG_KERNEL_ABI_TRACKER_UNKNOWN) {
d01c0e56
MD
291 errno = EINVAL;
292 return -1;
293 }
acbe1c12
FD
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;
d01c0e56
MD
302}
303
159b042f 304int kernctl_list_tracker_ids(int fd, enum lttng_process_attr process_attr)
d01c0e56 305{
b8e2fb80 306 struct lttng_kernel_abi_tracker_args args;
acbe1c12 307 int ret;
d01c0e56
MD
308
309 args.id = -1;
159b042f 310 args.type = get_kernel_tracker_type(process_attr);
b8e2fb80 311 if (args.type == LTTNG_KERNEL_ABI_TRACKER_UNKNOWN) {
d01c0e56
MD
312 errno = EINVAL;
313 return -1;
314 }
acbe1c12
FD
315
316 ret = LTTNG_IOCTL_NO_CHECK(
b8e2fb80 317 fd, LTTNG_KERNEL_ABI_SESSION_LIST_TRACKER_IDS, &args);
acbe1c12
FD
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;
d01c0e56
MD
325}
326
eded6438 327int kernctl_session_regenerate_metadata(int fd)
93ec662e 328{
b8e2fb80 329 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_METADATA_REGEN);
93ec662e
JD
330}
331
c2561365
JD
332int kernctl_session_regenerate_statedump(int fd)
333{
b8e2fb80 334 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_STATEDUMP);
c2561365
JD
335}
336
8ff4109e
JR
337int kernctl_session_set_name(int fd, const char *name)
338{
339 int ret;
b8e2fb80 340 struct lttng_kernel_abi_session_name session_name;
8ff4109e
JR
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(
b8e2fb80 348 fd, LTTNG_KERNEL_ABI_SESSION_SET_NAME, &session_name);
acbe1c12
FD
349 if (ret == -ENOSYS) {
350 ret = LTTNG_IOCTL_CHECK(fd,
351 LTTNG_KERNEL_ABI_OLD_SESSION_SET_NAME,
352 &session_name);
353 }
354
8ff4109e
JR
355end:
356 return ret;
357}
358
e04b2181
JR
359int kernctl_session_set_creation_time(int fd, time_t time)
360{
361 int ret;
b8e2fb80 362 struct lttng_kernel_abi_session_creation_time creation_time;
e04b2181
JR
363
364 ret = time_to_iso8601_str(time, creation_time.iso8601,
365 sizeof(creation_time.iso8601));
366 if (ret) {
367 goto end;
368 }
369
b8e2fb80 370 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_SESSION_SET_CREATION_TIME,
e04b2181 371 &creation_time);
acbe1c12
FD
372 if (ret == -ENOSYS) {
373 ret = LTTNG_IOCTL_CHECK(fd,
374 LTTNG_KERNEL_ABI_OLD_SESSION_SET_CREATION_TIME,
375 &creation_time);
376 }
377
e04b2181
JR
378end:
379 return ret;
380}
381
964ccb60 382int kernctl_create_stream(int fd)
16421f6e 383{
b8e2fb80
FD
384 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_STREAM,
385 LTTNG_KERNEL_ABI_STREAM);
16421f6e
DG
386}
387
b8e2fb80 388int kernctl_create_event(int fd, struct lttng_kernel_abi_event *ev)
16421f6e 389{
b8e2fb80
FD
390 if (lttng_kernel_abi_use_old_abi) {
391 struct lttng_kernel_abi_old_event old_event;
4dbc372b 392
10600be0 393 memset(&old_event, 0, sizeof(old_event));
4dbc372b
JD
394 memcpy(old_event.name, ev->name, sizeof(old_event.name));
395 old_event.instrumentation = ev->instrumentation;
396 switch (ev->instrumentation) {
b8e2fb80 397 case LTTNG_KERNEL_ABI_KPROBE:
4dbc372b
JD
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;
b8e2fb80 404 case LTTNG_KERNEL_ABI_KRETPROBE:
4dbc372b
JD
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;
b8e2fb80 411 case LTTNG_KERNEL_ABI_FUNCTION:
4dbc372b
JD
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
b8e2fb80 420 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_OLD_EVENT,
5226f1bc 421 &old_event);
4dbc372b 422 }
b8e2fb80 423 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_EVENT, ev);
16421f6e
DG
424}
425
b8e2fb80 426int kernctl_add_context(int fd, struct lttng_kernel_abi_context *ctx)
16421f6e 427{
b8e2fb80
FD
428 if (lttng_kernel_abi_use_old_abi) {
429 struct lttng_kernel_abi_old_context old_ctx;
4dbc372b 430
10600be0 431 memset(&old_ctx, 0, sizeof(old_ctx));
4dbc372b
JD
432 old_ctx.ctx = ctx->ctx;
433 /* only type that uses the union */
b8e2fb80 434 if (ctx->ctx == LTTNG_KERNEL_ABI_CONTEXT_PERF_CPU_COUNTER) {
4dbc372b
JD
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 }
b8e2fb80
FD
443 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_OLD_CONTEXT,
444 &old_ctx);
4dbc372b 445 }
b8e2fb80 446 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_CONTEXT, ctx);
16421f6e
DG
447}
448
964ccb60 449
5226f1bc 450/* Enable event, channel and session LTTNG_IOCTL_CHECK */
f3ed775e
DG
451int kernctl_enable(int fd)
452{
b8e2fb80
FD
453 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_ENABLE,
454 LTTNG_KERNEL_ABI_ENABLE);
f3ed775e
DG
455}
456
5226f1bc 457/* Disable event, channel and session LTTNG_IOCTL_CHECK */
f3ed775e
DG
458int kernctl_disable(int fd)
459{
b8e2fb80
FD
460 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_DISABLE,
461 LTTNG_KERNEL_ABI_DISABLE);
f3ed775e
DG
462}
463
964ccb60 464int kernctl_start_session(int fd)
16421f6e 465{
b8e2fb80
FD
466 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_SESSION_START,
467 LTTNG_KERNEL_ABI_SESSION_START);
964ccb60
MD
468}
469
470int kernctl_stop_session(int fd)
471{
b8e2fb80
FD
472 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_SESSION_STOP,
473 LTTNG_KERNEL_ABI_SESSION_STOP);
16421f6e
DG
474}
475
cfb1c9bc
JR
476int kernctl_create_event_notifier_group(int fd)
477{
478 return LTTNG_IOCTL_NO_CHECK(fd,
b8e2fb80 479 LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_CREATE);
cfb1c9bc
JR
480}
481
482int kernctl_create_event_notifier_group_notification_fd(int group_fd)
483{
484 return LTTNG_IOCTL_NO_CHECK(group_fd,
b8e2fb80 485 LTTNG_KERNEL_ABI_EVENT_NOTIFIER_GROUP_NOTIFICATION_FD);
cfb1c9bc
JR
486}
487
90aa04a1 488int kernctl_create_event_notifier_group_error_counter(int group_fd,
b8e2fb80 489 const struct lttng_kernel_abi_counter_conf *error_counter_conf)
90aa04a1 490{
b8e2fb80 491 return LTTNG_IOCTL_NO_CHECK(group_fd, LTTNG_KERNEL_ABI_COUNTER,
90aa04a1
FD
492 error_counter_conf);
493}
494
495int kernctl_counter_get_aggregate_value(int counter_fd,
b8e2fb80 496 struct lttng_kernel_abi_counter_aggregate *value)
90aa04a1 497{
b8e2fb80 498 return LTTNG_IOCTL_NO_CHECK(counter_fd, LTTNG_KERNEL_ABI_COUNTER_AGGREGATE,
90aa04a1
FD
499 value);
500}
501
502int kernctl_counter_clear(int counter_fd,
b8e2fb80 503 struct lttng_kernel_abi_counter_clear *clear)
90aa04a1 504{
b8e2fb80 505 return LTTNG_IOCTL_NO_CHECK(counter_fd, LTTNG_KERNEL_ABI_COUNTER_CLEAR,
90aa04a1
FD
506 clear);
507}
508
cfb1c9bc 509int kernctl_create_event_notifier(int group_fd,
b8e2fb80 510 const struct lttng_kernel_abi_event_notifier *event_notifier)
cfb1c9bc
JR
511{
512 return LTTNG_IOCTL_NO_CHECK(group_fd,
b8e2fb80 513 LTTNG_KERNEL_ABI_EVENT_NOTIFIER_CREATE, event_notifier);
cfb1c9bc
JR
514}
515
bbd6675c
JR
516int kernctl_capture(int fd, const struct lttng_bytecode *capture)
517{
518 int ret;
b8e2fb80 519 struct lttng_kernel_abi_capture_bytecode *kb;
bbd6675c
JR
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);
b8e2fb80 532 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_CAPTURE, kb);
bbd6675c
JR
533 free(kb);
534end:
535 return ret;
536}
537
2b00d462 538int kernctl_filter(int fd, const struct lttng_bytecode *filter)
00a62084 539{
b8e2fb80 540 struct lttng_kernel_abi_filter_bytecode *kb;
00a62084
MD
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);
b8e2fb80 552 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_FILTER, kb);
00a62084
MD
553 free(kb);
554 return ret;
555}
556
b8e2fb80 557int kernctl_add_callsite(int fd, struct lttng_kernel_abi_event_callsite *callsite)
1ab8c2ad 558{
b8e2fb80 559 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_ADD_CALLSITE, callsite);
1ab8c2ad
FD
560}
561
964ccb60
MD
562int kernctl_tracepoint_list(int fd)
563{
b8e2fb80
FD
564 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_TRACEPOINT_LIST,
565 LTTNG_KERNEL_ABI_TRACEPOINT_LIST);
964ccb60
MD
566}
567
d02666a9
MD
568int kernctl_syscall_list(int fd)
569{
b8e2fb80 570 return LTTNG_IOCTL_NO_CHECK(fd, LTTNG_KERNEL_ABI_SYSCALL_LIST);
d02666a9
MD
571}
572
b8e2fb80 573int kernctl_tracer_version(int fd, struct lttng_kernel_abi_tracer_version *v)
964ccb60 574{
4dbc372b
JD
575 int ret;
576
b8e2fb80
FD
577 if (lttng_kernel_abi_use_old_abi == -1) {
578 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_TRACER_VERSION, v);
4dbc372b 579 if (!ret) {
b8e2fb80 580 lttng_kernel_abi_use_old_abi = 0;
4dbc372b
JD
581 goto end;
582 }
b8e2fb80 583 lttng_kernel_abi_use_old_abi = 1;
4dbc372b 584 }
b8e2fb80
FD
585 if (lttng_kernel_abi_use_old_abi) {
586 struct lttng_kernel_abi_old_tracer_version old_v;
4dbc372b 587
b8e2fb80 588 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_OLD_TRACER_VERSION, &old_v);
4dbc372b
JD
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 {
b8e2fb80 596 ret = LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_TRACER_VERSION, v);
4dbc372b
JD
597 }
598
599end:
600 return ret;
964ccb60
MD
601}
602
c052142c 603int kernctl_tracer_abi_version(int fd,
b8e2fb80 604 struct lttng_kernel_abi_tracer_abi_version *v)
c052142c 605{
b8e2fb80 606 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_TRACER_ABI_VERSION, v);
c052142c
MD
607}
608
964ccb60
MD
609int kernctl_wait_quiescent(int fd)
610{
b8e2fb80
FD
611 return compat_ioctl_no_arg(fd, LTTNG_KERNEL_ABI_OLD_WAIT_QUIESCENT,
612 LTTNG_KERNEL_ABI_WAIT_QUIESCENT);
964ccb60
MD
613}
614
964ccb60
MD
615int kernctl_buffer_flush(int fd)
616{
b8e2fb80 617 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH);
964ccb60
MD
618}
619
f22dd891
MD
620int kernctl_buffer_flush_empty(int fd)
621{
b8e2fb80 622 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_FLUSH_EMPTY);
f22dd891
MD
623}
624
99930a9d
JR
625int kernctl_buffer_clear(int fd)
626{
b8e2fb80 627 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_CLEAR);
99930a9d
JR
628}
629
41dc93d9
JG
630int kernctl_get_next_subbuf_metadata_check(int fd, bool *consistent)
631{
632 return LTTNG_IOCTL_NO_CHECK(fd,
b8e2fb80 633 LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF_METADATA_CHECK,
41dc93d9
JG
634 consistent);
635}
636
93ec662e
JD
637/* returns the version of the metadata. */
638int kernctl_get_metadata_version(int fd, uint64_t *version)
639{
b8e2fb80
FD
640 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_METADATA_VERSION,
641 version);
93ec662e
JD
642}
643
8024cc8c
JD
644int kernctl_metadata_cache_dump(int fd)
645{
b8e2fb80 646 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_METADATA_CACHE_DUMP);
8024cc8c 647}
964ccb60
MD
648
649/* Buffer operations */
650
651/* For mmap mode, readable without "get" operation */
652
16421f6e
DG
653/* returns the length to mmap. */
654int kernctl_get_mmap_len(int fd, unsigned long *len)
655{
b8e2fb80
FD
656 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_MMAP_LEN,
657 len);
16421f6e
DG
658}
659
964ccb60
MD
660/* returns the maximum size for sub-buffers. */
661int kernctl_get_max_subbuf_size(int fd, unsigned long *len)
662{
b8e2fb80
FD
663 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_MAX_SUBBUF_SIZE,
664 len);
964ccb60
MD
665}
666
667/*
668 * For mmap mode, operate on the current packet (between get/put or
669 * get_next/put_next).
670 */
671
16421f6e
DG
672/* returns the offset of the subbuffer belonging to the mmap reader. */
673int kernctl_get_mmap_read_offset(int fd, unsigned long *off)
674{
b8e2fb80
FD
675 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_MMAP_READ_OFFSET,
676 off);
16421f6e
DG
677}
678
964ccb60
MD
679/* returns the size of the current sub-buffer, without padding (for mmap). */
680int kernctl_get_subbuf_size(int fd, unsigned long *len)
16421f6e 681{
b8e2fb80
FD
682 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF_SIZE,
683 len);
16421f6e
DG
684}
685
686/* returns the size of the current sub-buffer, without padding (for mmap). */
687int kernctl_get_padded_subbuf_size(int fd, unsigned long *len)
688{
b8e2fb80
FD
689 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_PADDED_SUBBUF_SIZE,
690 len);
16421f6e
DG
691}
692
964ccb60
MD
693/* Get exclusive read access to the next sub-buffer that can be read. */
694int kernctl_get_next_subbuf(int fd)
16421f6e 695{
b8e2fb80 696 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_NEXT_SUBBUF);
16421f6e
DG
697}
698
d4a1283e 699
16421f6e
DG
700/* Release exclusive sub-buffer access, move consumer forward. */
701int kernctl_put_next_subbuf(int fd)
702{
b8e2fb80 703 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_PUT_NEXT_SUBBUF);
16421f6e
DG
704}
705
964ccb60 706/* snapshot */
16421f6e
DG
707
708/* Get a snapshot of the current ring buffer producer and consumer positions */
709int kernctl_snapshot(int fd)
710{
b8e2fb80 711 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_SNAPSHOT);
16421f6e
DG
712}
713
b007ec59
JG
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 */
719int kernctl_snapshot_sample_positions(int fd)
720{
b8e2fb80 721 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS);
b007ec59
JG
722}
723
16421f6e
DG
724/* Get the consumer position (iteration start) */
725int kernctl_snapshot_get_consumed(int fd, unsigned long *pos)
726{
b8e2fb80
FD
727 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_SNAPSHOT_GET_CONSUMED,
728 pos);
16421f6e
DG
729}
730
731/* Get the producer position (iteration end) */
732int kernctl_snapshot_get_produced(int fd, unsigned long *pos)
733{
b8e2fb80
FD
734 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_SNAPSHOT_GET_PRODUCED,
735 pos);
16421f6e
DG
736}
737
964ccb60
MD
738/* Get exclusive read access to the specified sub-buffer position */
739int kernctl_get_subbuf(int fd, unsigned long *len)
f3ed775e 740{
b8e2fb80
FD
741 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_SUBBUF,
742 len);
f3ed775e 743}
d0254c7c 744
964ccb60
MD
745/* Release exclusive sub-buffer access */
746int kernctl_put_subbuf(int fd)
d0254c7c 747{
b8e2fb80 748 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_PUT_SUBBUF);
d0254c7c 749}
309167d2
JD
750
751/* Returns the timestamp begin of the current sub-buffer. */
752int kernctl_get_timestamp_begin(int fd, uint64_t *timestamp_begin)
753{
b8e2fb80 754 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_BEGIN,
a6bd6d9b 755 timestamp_begin);
309167d2
JD
756}
757
758/* Returns the timestamp end of the current sub-buffer. */
759int kernctl_get_timestamp_end(int fd, uint64_t *timestamp_end)
760{
b8e2fb80 761 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_TIMESTAMP_END,
a6bd6d9b 762 timestamp_end);
309167d2
JD
763}
764
765/* Returns the number of discarded events in the current sub-buffer. */
766int kernctl_get_events_discarded(int fd, uint64_t *events_discarded)
767{
b8e2fb80 768 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_EVENTS_DISCARDED,
a6bd6d9b 769 events_discarded);
309167d2
JD
770}
771
772/* Returns the content size in the current sub-buffer. */
773int kernctl_get_content_size(int fd, uint64_t *content_size)
774{
b8e2fb80 775 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_CONTENT_SIZE,
a6bd6d9b 776 content_size);
309167d2
JD
777}
778
779/* Returns the packet size in the current sub-buffer. */
780int kernctl_get_packet_size(int fd, uint64_t *packet_size)
781{
b8e2fb80 782 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_PACKET_SIZE,
5226f1bc 783 packet_size);
309167d2
JD
784}
785
786/* Returns the stream id of the current sub-buffer. */
787int kernctl_get_stream_id(int fd, uint64_t *stream_id)
788{
b8e2fb80 789 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_STREAM_ID,
5226f1bc 790 stream_id);
309167d2 791}
d3e2ba59
JD
792
793/* Returns the current timestamp. */
794int kernctl_get_current_timestamp(int fd, uint64_t *ts)
795{
b8e2fb80 796 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_CURRENT_TIMESTAMP,
5226f1bc 797 ts);
d3e2ba59 798}
fb83fe64
JD
799
800/* Returns the packet sequence number of the current sub-buffer. */
801int kernctl_get_sequence_number(int fd, uint64_t *seq)
802{
b8e2fb80
FD
803 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_GET_SEQ_NUM,
804 seq);
fb83fe64 805}
000fa86f
JD
806
807/* Returns the stream instance id. */
808int kernctl_get_instance_id(int fd, uint64_t *id)
809{
b8e2fb80
FD
810 return LTTNG_IOCTL_CHECK(fd, LTTNG_KERNEL_ABI_RING_BUFFER_INSTANCE_ID,
811 id);
000fa86f 812}
This page took 0.16835 seconds and 4 git commands to generate.