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