Installed headers relicensing and cleanup
[lttng-ust.git] / liblttng-ust-ctl / ustctl.c
1 /*
2 * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@polymtl.ca>
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; only version 2
8 * of the License.
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 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 #include <string.h>
21 #include <lttng/ust-ctl.h>
22 #include <lttng/ust-abi.h>
23 #include <lttng/usterr-signal-safe.h>
24 #include <lttng/ust-events.h>
25 #include <sys/mman.h>
26 #include <ust-comm.h>
27
28 #include "../libringbuffer/backend.h"
29 #include "../libringbuffer/frontend.h"
30
31 volatile enum ust_loglevel ust_loglevel;
32
33 static
34 void init_object(struct lttng_ust_object_data *data)
35 {
36 data->handle = -1;
37 data->shm_fd = -1;
38 data->wait_fd = -1;
39 data->memory_map_size = 0;
40 }
41
42 /*
43 * If sock is negative, it means we don't have to notify the other side
44 * (e.g. application has already vanished).
45 */
46 void ustctl_release_object(int sock, struct lttng_ust_object_data *data)
47 {
48 struct ustcomm_ust_msg lum;
49 struct ustcomm_ust_reply lur;
50 int ret;
51
52 if (data->shm_fd >= 0)
53 close(data->shm_fd);
54 if (data->wait_fd >= 0)
55 close(data->wait_fd);
56 if (sock >= 0) {
57 memset(&lum, 0, sizeof(lum));
58 lum.handle = data->handle;
59 lum.cmd = LTTNG_UST_RELEASE;
60 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
61 assert(!ret);
62 }
63 free(data);
64 }
65
66 /*
67 * Send registration done packet to the application.
68 */
69 int ustctl_register_done(int sock)
70 {
71 struct ustcomm_ust_msg lum;
72 struct ustcomm_ust_reply lur;
73 int ret;
74
75 DBG("Sending register done command to %d", sock);
76 memset(&lum, 0, sizeof(lum));
77 lum.handle = LTTNG_UST_ROOT_HANDLE;
78 lum.cmd = LTTNG_UST_REGISTER_DONE;
79 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
80 if (ret)
81 return ret;
82 if (lur.ret_code != USTCOMM_OK) {
83 DBG("Return code: %s", ustcomm_get_readable_code(lur.ret_code));
84 goto error;
85 }
86 return 0;
87
88 error:
89 return -1;
90 }
91
92 /*
93 * returns session handle.
94 */
95 int ustctl_create_session(int sock)
96 {
97 struct ustcomm_ust_msg lum;
98 struct ustcomm_ust_reply lur;
99 int ret, session_handle;
100
101 /* Create session */
102 memset(&lum, 0, sizeof(lum));
103 lum.handle = LTTNG_UST_ROOT_HANDLE;
104 lum.cmd = LTTNG_UST_SESSION;
105 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
106 if (ret)
107 return ret;
108 session_handle = lur.ret_val;
109 DBG("received session handle %u", session_handle);
110 return session_handle;
111 }
112
113 /* open the metadata global channel */
114 int ustctl_open_metadata(int sock, int session_handle,
115 struct lttng_ust_channel_attr *chops,
116 struct lttng_ust_object_data **_metadata_data)
117 {
118 struct ustcomm_ust_msg lum;
119 struct ustcomm_ust_reply lur;
120 struct lttng_ust_object_data *metadata_data;
121 int ret;
122
123 metadata_data = malloc(sizeof(*metadata_data));
124 if (!metadata_data)
125 return -ENOMEM;
126 init_object(metadata_data);
127 /* Create metadata channel */
128 memset(&lum, 0, sizeof(lum));
129 lum.handle = session_handle;
130 lum.cmd = LTTNG_UST_METADATA;
131 lum.u.channel.overwrite = chops->overwrite;
132 lum.u.channel.subbuf_size = chops->subbuf_size;
133 lum.u.channel.num_subbuf = chops->num_subbuf;
134 lum.u.channel.switch_timer_interval = chops->switch_timer_interval;
135 lum.u.channel.read_timer_interval = chops->read_timer_interval;
136 lum.u.channel.output = chops->output;
137 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
138 if (ret) {
139 free(metadata_data);
140 return ret;
141 }
142 if (lur.ret_code != USTCOMM_OK) {
143 free(metadata_data);
144 return lur.ret_code;
145 }
146 metadata_data->handle = lur.ret_val;
147 DBG("received metadata handle %u", metadata_data->handle);
148 metadata_data->memory_map_size = lur.u.channel.memory_map_size;
149 /* get shm fd */
150 ret = ustcomm_recv_fd(sock);
151 if (ret < 0)
152 goto error;
153 metadata_data->shm_fd = ret;
154 /* get wait fd */
155 ret = ustcomm_recv_fd(sock);
156 if (ret < 0)
157 goto error;
158 metadata_data->wait_fd = ret;
159 *_metadata_data = metadata_data;
160 return 0;
161
162 error:
163 ustctl_release_object(sock, metadata_data);
164 return -EINVAL;
165 }
166
167 int ustctl_create_channel(int sock, int session_handle,
168 struct lttng_ust_channel_attr *chops,
169 struct lttng_ust_object_data **_channel_data)
170 {
171 struct ustcomm_ust_msg lum;
172 struct ustcomm_ust_reply lur;
173 struct lttng_ust_object_data *channel_data;
174 int ret;
175
176 channel_data = malloc(sizeof(*channel_data));
177 if (!channel_data)
178 return -ENOMEM;
179 init_object(channel_data);
180 /* Create metadata channel */
181 memset(&lum, 0, sizeof(lum));
182 lum.handle = session_handle;
183 lum.cmd = LTTNG_UST_CHANNEL;
184 lum.u.channel.overwrite = chops->overwrite;
185 lum.u.channel.subbuf_size = chops->subbuf_size;
186 lum.u.channel.num_subbuf = chops->num_subbuf;
187 lum.u.channel.switch_timer_interval = chops->switch_timer_interval;
188 lum.u.channel.read_timer_interval = chops->read_timer_interval;
189 lum.u.channel.output = chops->output;
190 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
191 if (ret) {
192 free(channel_data);
193 return ret;
194 }
195 if (lur.ret_code != USTCOMM_OK) {
196 free(channel_data);
197 return lur.ret_code;
198 }
199 channel_data->handle = lur.ret_val;
200 DBG("received channel handle %u", channel_data->handle);
201 channel_data->memory_map_size = lur.u.channel.memory_map_size;
202 /* get shm fd */
203 ret = ustcomm_recv_fd(sock);
204 if (ret < 0)
205 goto error;
206 channel_data->shm_fd = ret;
207 /* get wait fd */
208 ret = ustcomm_recv_fd(sock);
209 if (ret < 0)
210 goto error;
211 channel_data->wait_fd = ret;
212 *_channel_data = channel_data;
213 return 0;
214
215 error:
216 ustctl_release_object(sock, channel_data);
217 return -EINVAL;
218 }
219
220 /*
221 * Return -ENOENT if no more stream is available for creation.
222 * Return 0 on success.
223 * Return negative error value on error.
224 */
225 int ustctl_create_stream(int sock, struct lttng_ust_object_data *channel_data,
226 struct lttng_ust_object_data **_stream_data)
227 {
228 struct ustcomm_ust_msg lum;
229 struct ustcomm_ust_reply lur;
230 struct lttng_ust_object_data *stream_data;
231 int ret, fd;
232
233 stream_data = malloc(sizeof(*stream_data));
234 if (!stream_data)
235 return -ENOMEM;
236 init_object(stream_data);
237 memset(&lum, 0, sizeof(lum));
238 lum.handle = channel_data->handle;
239 lum.cmd = LTTNG_UST_STREAM;
240 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
241 if (ret) {
242 free(stream_data);
243 return ret;
244 }
245 if (lur.ret_code != USTCOMM_OK) {
246 free(stream_data);
247 return lur.ret_code;
248 }
249
250 stream_data->handle = lur.ret_val;
251 DBG("received stream handle %u", stream_data->handle);
252 stream_data->memory_map_size = lur.u.stream.memory_map_size;
253 /* get shm fd */
254 fd = ustcomm_recv_fd(sock);
255 if (fd < 0)
256 goto error;
257 stream_data->shm_fd = fd;
258 /* get wait fd */
259 fd = ustcomm_recv_fd(sock);
260 if (fd < 0)
261 goto error;
262 stream_data->wait_fd = fd;
263 *_stream_data = stream_data;
264 return ret;
265
266 error:
267 ustctl_release_object(sock, stream_data);
268 return -EINVAL;
269 }
270
271 int ustctl_create_event(int sock, struct lttng_ust_event *ev,
272 struct lttng_ust_object_data *channel_data,
273 struct lttng_ust_object_data **_event_data)
274 {
275 struct ustcomm_ust_msg lum;
276 struct ustcomm_ust_reply lur;
277 struct lttng_ust_object_data *event_data;
278 int ret;
279
280 event_data = malloc(sizeof(*event_data));
281 if (!event_data)
282 return -ENOMEM;
283 init_object(event_data);
284 memset(&lum, 0, sizeof(lum));
285 lum.handle = channel_data->handle;
286 lum.cmd = LTTNG_UST_EVENT;
287 strncpy(lum.u.event.name, ev->name,
288 LTTNG_UST_SYM_NAME_LEN);
289 lum.u.event.instrumentation = ev->instrumentation;
290 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
291 if (ret) {
292 free(event_data);
293 return ret;
294 }
295 event_data->handle = lur.ret_val;
296 DBG("received event handle %u", event_data->handle);
297 *_event_data = event_data;
298 return 0;
299 }
300
301 int ustctl_add_context(int sock, struct lttng_ust_context *ctx,
302 struct lttng_ust_object_data *obj_data,
303 struct lttng_ust_object_data **_context_data)
304 {
305 struct ustcomm_ust_msg lum;
306 struct ustcomm_ust_reply lur;
307 struct lttng_ust_object_data *context_data;
308 int ret;
309
310 context_data = malloc(sizeof(*context_data));
311 if (!context_data)
312 return -ENOMEM;
313 init_object(context_data);
314 memset(&lum, 0, sizeof(lum));
315 lum.handle = obj_data->handle;
316 lum.cmd = LTTNG_UST_CONTEXT;
317 lum.u.context.ctx = ctx->ctx;
318 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
319 if (ret) {
320 free(context_data);
321 return ret;
322 }
323 context_data->handle = lur.ret_val;
324 DBG("received context handle %u", context_data->handle);
325 *_context_data = context_data;
326 return ret;
327 }
328
329 /* Enable event, channel and session ioctl */
330 int ustctl_enable(int sock, struct lttng_ust_object_data *object)
331 {
332 struct ustcomm_ust_msg lum;
333 struct ustcomm_ust_reply lur;
334 int ret;
335
336 memset(&lum, 0, sizeof(lum));
337 lum.handle = object->handle;
338 lum.cmd = LTTNG_UST_ENABLE;
339 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
340 if (ret)
341 return ret;
342 DBG("enabled handle %u", object->handle);
343 return 0;
344 }
345
346 /* Disable event, channel and session ioctl */
347 int ustctl_disable(int sock, struct lttng_ust_object_data *object)
348 {
349 struct ustcomm_ust_msg lum;
350 struct ustcomm_ust_reply lur;
351 int ret;
352
353 memset(&lum, 0, sizeof(lum));
354 lum.handle = object->handle;
355 lum.cmd = LTTNG_UST_DISABLE;
356 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
357 if (ret)
358 return ret;
359 DBG("disable handle %u", object->handle);
360 return 0;
361 }
362
363 int ustctl_start_session(int sock, int handle)
364 {
365 struct lttng_ust_object_data obj;
366
367 obj.handle = handle;
368 return ustctl_enable(sock, &obj);
369 }
370
371 int ustctl_stop_session(int sock, int handle)
372 {
373 struct lttng_ust_object_data obj;
374
375 obj.handle = handle;
376 return ustctl_disable(sock, &obj);
377 }
378
379 int ustctl_tracepoint_list(int sock)
380 {
381 struct ustcomm_ust_msg lum;
382 struct ustcomm_ust_reply lur;
383 int ret, tp_list_handle;
384
385 memset(&lum, 0, sizeof(lum));
386 lum.handle = LTTNG_UST_ROOT_HANDLE;
387 lum.cmd = LTTNG_UST_TRACEPOINT_LIST;
388 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
389 if (ret)
390 return ret;
391 tp_list_handle = lur.ret_val;
392 DBG("received tracepoint list handle %u", tp_list_handle);
393 return tp_list_handle;
394 }
395
396 int ustctl_tracepoint_list_get(int sock, int tp_list_handle,
397 char iter[LTTNG_UST_SYM_NAME_LEN])
398 {
399 struct ustcomm_ust_msg lum;
400 struct ustcomm_ust_reply lur;
401 int ret;
402
403 memset(&lum, 0, sizeof(lum));
404 lum.handle = tp_list_handle;
405 lum.cmd = LTTNG_UST_TRACEPOINT_LIST_GET;
406 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
407 if (ret)
408 return ret;
409 DBG("received tracepoint list entry %s", lur.u.tracepoint_list_entry);
410 memcpy(iter, lur.u.tracepoint_list_entry, LTTNG_UST_SYM_NAME_LEN);
411 return 0;
412 }
413
414 int ustctl_tracer_version(int sock, struct lttng_ust_tracer_version *v)
415 {
416 struct ustcomm_ust_msg lum;
417 struct ustcomm_ust_reply lur;
418 int ret;
419
420 memset(&lum, 0, sizeof(lum));
421 lum.handle = LTTNG_UST_ROOT_HANDLE;
422 lum.cmd = LTTNG_UST_TRACER_VERSION;
423 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
424 if (ret)
425 return ret;
426 memcpy(v, &lur.u.version, sizeof(*v));
427 DBG("received tracer version");
428 return 0;
429 }
430
431 int ustctl_wait_quiescent(int sock)
432 {
433 struct ustcomm_ust_msg lum;
434 struct ustcomm_ust_reply lur;
435 int ret;
436
437 memset(&lum, 0, sizeof(lum));
438 lum.handle = LTTNG_UST_ROOT_HANDLE;
439 lum.cmd = LTTNG_UST_WAIT_QUIESCENT;
440 ret = ustcomm_send_app_cmd(sock, &lum, &lur);
441 if (ret)
442 return ret;
443 DBG("waited for quiescent state");
444 return 0;
445 }
446
447 int ustctl_calibrate(int sock, struct lttng_ust_calibrate *calibrate)
448 {
449 return -ENOSYS;
450 }
451
452 /* Buffer operations */
453
454 /* Map channel shm into process memory */
455 struct lttng_ust_shm_handle *ustctl_map_channel(struct lttng_ust_object_data *chan_data)
456 {
457 struct lttng_ust_shm_handle *handle;
458 struct channel *chan;
459 size_t chan_size;
460 struct lttng_ust_lib_ring_buffer_config *config;
461 int ret;
462
463 handle = channel_handle_create(chan_data->shm_fd,
464 chan_data->wait_fd,
465 chan_data->memory_map_size);
466 if (!handle) {
467 ERR("create handle error");
468 return NULL;
469 }
470 /*
471 * Set to -1 because the lttng_ust_shm_handle destruction will take care
472 * of closing shm_fd and wait_fd.
473 */
474 chan_data->shm_fd = -1;
475 chan_data->wait_fd = -1;
476
477 /*
478 * TODO: add consistency checks to be resilient if the
479 * application try to feed us with incoherent channel structure
480 * values.
481 */
482 chan = shmp(handle, handle->chan);
483 /* chan is object 0. This is hardcoded. */
484 chan_size = handle->table->objects[0].allocated_len;
485 handle->shadow_chan = malloc(chan_size);
486 if (!handle->shadow_chan) {
487 channel_destroy(chan, handle, 1);
488 return NULL;
489 }
490 memcpy(handle->shadow_chan, chan, chan_size);
491 /*
492 * The callback pointers in the producer are invalid in the
493 * consumer. We need to look them up here.
494 */
495 config = &handle->shadow_chan->backend.config;
496 switch (config->client_type) {
497 case LTTNG_CLIENT_METADATA:
498 memcpy(&config->cb, lttng_client_callbacks_metadata,
499 sizeof(config->cb));
500 break;
501 case LTTNG_CLIENT_DISCARD:
502 memcpy(&config->cb, lttng_client_callbacks_discard,
503 sizeof(config->cb));
504 break;
505 case LTTNG_CLIENT_OVERWRITE:
506 memcpy(&config->cb, lttng_client_callbacks_overwrite,
507 sizeof(config->cb));
508 break;
509 default:
510 ERR("Unknown client type %d", config->client_type);
511 channel_destroy(chan, handle, 1);
512 return NULL;
513 }
514 /* Replace the object table pointer. */
515 ret = munmap(handle->table->objects[0].memory_map,
516 handle->table->objects[0].memory_map_size);
517 if (ret) {
518 perror("munmap");
519 assert(0);
520 }
521 handle->table->objects[0].memory_map = (char *) handle->shadow_chan;
522 handle->table->objects[0].is_shadow = 1;
523 return handle;
524 }
525
526 /* Add stream to channel shm and map its shm into process memory */
527 int ustctl_add_stream(struct lttng_ust_shm_handle *handle,
528 struct lttng_ust_object_data *stream_data)
529 {
530 int ret;
531
532 if (!stream_data->handle)
533 return -ENOENT;
534 /* map stream */
535 ret = channel_handle_add_stream(handle,
536 stream_data->shm_fd,
537 stream_data->wait_fd,
538 stream_data->memory_map_size);
539 if (ret) {
540 ERR("add stream error\n");
541 return ret;
542 }
543 /*
544 * Set to -1 because the lttng_ust_shm_handle destruction will take care
545 * of closing shm_fd and wait_fd.
546 */
547 stream_data->shm_fd = -1;
548 stream_data->wait_fd = -1;
549 return 0;
550 }
551
552 void ustctl_unmap_channel(struct lttng_ust_shm_handle *handle)
553 {
554 struct channel *chan;
555
556 chan = shmp(handle, handle->chan);
557 channel_destroy(chan, handle, 1);
558 }
559
560 struct lttng_ust_lib_ring_buffer *ustctl_open_stream_read(struct lttng_ust_shm_handle *handle,
561 int cpu)
562 {
563 struct channel *chan = handle->shadow_chan;
564 int shm_fd, wait_fd;
565 uint64_t memory_map_size;
566 struct lttng_ust_lib_ring_buffer *buf;
567 int ret;
568
569 buf = channel_get_ring_buffer(&chan->backend.config,
570 chan, cpu, handle, &shm_fd, &wait_fd, &memory_map_size);
571 if (!buf)
572 return NULL;
573 ret = lib_ring_buffer_open_read(buf, handle, 1);
574 if (ret)
575 return NULL;
576 return buf;
577 }
578
579 void ustctl_close_stream_read(struct lttng_ust_shm_handle *handle,
580 struct lttng_ust_lib_ring_buffer *buf)
581 {
582 lib_ring_buffer_release_read(buf, handle, 1);
583 }
584
585 /* For mmap mode, readable without "get" operation */
586
587 void *ustctl_get_mmap_base(struct lttng_ust_shm_handle *handle,
588 struct lttng_ust_lib_ring_buffer *buf)
589 {
590 return shmp(handle, buf->backend.memory_map);
591 }
592
593 /* returns the length to mmap. */
594 int ustctl_get_mmap_len(struct lttng_ust_shm_handle *handle,
595 struct lttng_ust_lib_ring_buffer *buf,
596 unsigned long *len)
597 {
598 unsigned long mmap_buf_len;
599 struct channel *chan = handle->shadow_chan;
600
601 if (chan->backend.config.output != RING_BUFFER_MMAP)
602 return -EINVAL;
603 mmap_buf_len = chan->backend.buf_size;
604 if (chan->backend.extra_reader_sb)
605 mmap_buf_len += chan->backend.subbuf_size;
606 if (mmap_buf_len > INT_MAX)
607 return -EFBIG;
608 *len = mmap_buf_len;
609 return 0;
610 }
611
612 /* returns the maximum size for sub-buffers. */
613 int ustctl_get_max_subbuf_size(struct lttng_ust_shm_handle *handle,
614 struct lttng_ust_lib_ring_buffer *buf,
615 unsigned long *len)
616 {
617 struct channel *chan = handle->shadow_chan;
618
619 *len = chan->backend.subbuf_size;
620 return 0;
621 }
622
623 /*
624 * For mmap mode, operate on the current packet (between get/put or
625 * get_next/put_next).
626 */
627
628 /* returns the offset of the subbuffer belonging to the mmap reader. */
629 int ustctl_get_mmap_read_offset(struct lttng_ust_shm_handle *handle,
630 struct lttng_ust_lib_ring_buffer *buf, unsigned long *off)
631 {
632 struct channel *chan = handle->shadow_chan;
633 unsigned long sb_bindex;
634
635 if (chan->backend.config.output != RING_BUFFER_MMAP)
636 return -EINVAL;
637 sb_bindex = subbuffer_id_get_index(&chan->backend.config,
638 buf->backend.buf_rsb.id);
639 *off = shmp(handle, shmp_index(handle, buf->backend.array, sb_bindex)->shmp)->mmap_offset;
640 return 0;
641 }
642
643 /* returns the size of the current sub-buffer, without padding (for mmap). */
644 int ustctl_get_subbuf_size(struct lttng_ust_shm_handle *handle,
645 struct lttng_ust_lib_ring_buffer *buf, unsigned long *len)
646 {
647 struct channel *chan = handle->shadow_chan;
648
649 *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf,
650 handle);
651 return 0;
652 }
653
654 /* returns the size of the current sub-buffer, without padding (for mmap). */
655 int ustctl_get_padded_subbuf_size(struct lttng_ust_shm_handle *handle,
656 struct lttng_ust_lib_ring_buffer *buf, unsigned long *len)
657 {
658 struct channel *chan = handle->shadow_chan;
659
660 *len = lib_ring_buffer_get_read_data_size(&chan->backend.config, buf,
661 handle);
662 *len = PAGE_ALIGN(*len);
663 return 0;
664 }
665
666 /* Get exclusive read access to the next sub-buffer that can be read. */
667 int ustctl_get_next_subbuf(struct lttng_ust_shm_handle *handle,
668 struct lttng_ust_lib_ring_buffer *buf)
669 {
670 return lib_ring_buffer_get_next_subbuf(buf, handle);
671 }
672
673
674 /* Release exclusive sub-buffer access, move consumer forward. */
675 int ustctl_put_next_subbuf(struct lttng_ust_shm_handle *handle,
676 struct lttng_ust_lib_ring_buffer *buf)
677 {
678 lib_ring_buffer_put_next_subbuf(buf, handle);
679 return 0;
680 }
681
682 /* snapshot */
683
684 /* Get a snapshot of the current ring buffer producer and consumer positions */
685 int ustctl_snapshot(struct lttng_ust_shm_handle *handle,
686 struct lttng_ust_lib_ring_buffer *buf)
687 {
688 return lib_ring_buffer_snapshot(buf, &buf->cons_snapshot,
689 &buf->prod_snapshot, handle);
690 }
691
692 /* Get the consumer position (iteration start) */
693 int ustctl_snapshot_get_consumed(struct lttng_ust_shm_handle *handle,
694 struct lttng_ust_lib_ring_buffer *buf, unsigned long *pos)
695 {
696 *pos = buf->cons_snapshot;
697 return 0;
698 }
699
700 /* Get the producer position (iteration end) */
701 int ustctl_snapshot_get_produced(struct lttng_ust_shm_handle *handle,
702 struct lttng_ust_lib_ring_buffer *buf, unsigned long *pos)
703 {
704 *pos = buf->prod_snapshot;
705 return 0;
706 }
707
708 /* Get exclusive read access to the specified sub-buffer position */
709 int ustctl_get_subbuf(struct lttng_ust_shm_handle *handle,
710 struct lttng_ust_lib_ring_buffer *buf, unsigned long *pos)
711 {
712 return lib_ring_buffer_get_subbuf(buf, *pos, handle);
713 }
714
715 /* Release exclusive sub-buffer access */
716 int ustctl_put_subbuf(struct lttng_ust_shm_handle *handle,
717 struct lttng_ust_lib_ring_buffer *buf)
718 {
719 lib_ring_buffer_put_subbuf(buf, handle);
720 return 0;
721 }
722
723 void ustctl_flush_buffer(struct lttng_ust_shm_handle *handle,
724 struct lttng_ust_lib_ring_buffer *buf,
725 int producer_active)
726 {
727 lib_ring_buffer_switch_slow(buf,
728 producer_active ? SWITCH_ACTIVE : SWITCH_FLUSH,
729 handle);
730 }
This page took 0.046315 seconds and 5 git commands to generate.