From 5a2f5f00f3444590bb1b237f55836f07edc9bef5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 19 Jun 2020 18:54:58 -0400 Subject: [PATCH] common: add lttng_payload_view fd count accessor and buffer init MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Allow the initialization of a payload view from a subset of a dynamic buffer (echoing the lttng_buffer_view API) and add an accessor for the fd count property. Signed-off-by: Jérémie Galarneau Change-Id: I647e955b625230010a8789df88f93cf19487ce58 --- src/common/payload-view.c | 36 ++++++++++++++++++++++++++++++++++++ src/common/payload-view.h | 29 ++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/common/payload-view.c b/src/common/payload-view.c index fdfef6150..f15fa8447 100644 --- a/src/common/payload-view.c +++ b/src/common/payload-view.c @@ -5,6 +5,7 @@ * */ +#include #include #include "payload-view.h" #include "payload.h" @@ -46,6 +47,41 @@ struct lttng_payload_view lttng_payload_view_from_dynamic_buffer( }; } +LTTNG_HIDDEN +struct lttng_payload_view lttng_payload_view_from_buffer_view( + const struct lttng_buffer_view *view, size_t offset, + ptrdiff_t len) +{ + return (struct lttng_payload_view) { + .buffer = lttng_buffer_view_from_view( + view, offset, len) + }; +} + +LTTNG_HIDDEN +int lttng_payload_view_get_fd_count(struct lttng_payload_view *payload_view) +{ + int ret; + size_t position; + + if (!payload_view) { + ret = -1; + goto end; + } + + ret = lttng_dynamic_array_get_count(&payload_view->_fds); + if (ret < 0) { + goto end; + } + + position = payload_view->_iterator.p_fds_position ? + *payload_view->_iterator.p_fds_position : + payload_view->_iterator.fds_position; + ret = ret - (int) position; +end: + return ret; +} + LTTNG_HIDDEN int lttng_payload_view_pop_fd(struct lttng_payload_view *view) { diff --git a/src/common/payload-view.h b/src/common/payload-view.h index f125e8890..c7501bcda 100644 --- a/src/common/payload-view.h +++ b/src/common/payload-view.h @@ -87,7 +87,7 @@ struct lttng_payload_view lttng_payload_view_from_view( * from an existing dynamic buffer. * * @src Source dynamic buffer to reference - * @offset Offset to apply to the payload's buffer + * @offset Offset to apply to the dynamic buffer * @len Length of the buffer contents to reference. Passing -1 will * cause the payload view to reference the whole payload from the * offset provided. @@ -96,6 +96,33 @@ LTTNG_HIDDEN struct lttng_payload_view lttng_payload_view_from_dynamic_buffer( const struct lttng_dynamic_buffer *buffer, size_t offset, ptrdiff_t len); +/** + * + * Return a payload view referencing a subset of a dynamic buffer. + * + * Meant as an adapter for code paths that need to create a payload view + * from an existing buffer view. + * + * @src Source buffer view to reference + * @offset Offset to apply to the buffer view + * @len Length of the buffer contents to reference. Passing -1 will + * cause the payload view to reference the whole payload from the + * offset provided. + */ +LTTNG_HIDDEN +struct lttng_payload_view lttng_payload_view_from_buffer_view( + const struct lttng_buffer_view *view, size_t offset, + ptrdiff_t len); + +/** + * Get the number of file descriptors left in a payload view. + * + * @payload Payload instance + * + * Returns the number of file descriptors left on success, -1 on error. + */ +LTTNG_HIDDEN +int lttng_payload_view_get_fd_count(struct lttng_payload_view *payload_view); /** * Pop an fd from a payload view. -- 2.34.1