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