From: Jérémie Galarneau Date: Fri, 20 Dec 2019 04:49:28 +0000 (-0500) Subject: trace chunk: allow associating an fd_tracker to a trace chunk X-Git-Tag: v2.12.0-rc1~42 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b2621f79ae2fade4d2d7f21624dfe4649e5e3352;p=lttng-tools.git trace chunk: allow associating an fd_tracker to a trace chunk Introduce lttng_trace_chunk_set_fd_tracker() which may be used to associate an fd-tracker to a trace chunk instance. An fd-tracker must be set before any directory handle or files are created through the trace chunk. Signed-off-by: Jérémie Galarneau Change-Id: I5b3302e26ace2babadba286ca8bd4a016014bdd8 --- diff --git a/src/common/trace-chunk.c b/src/common/trace-chunk.c index 7407f38f3..326d42ce2 100644 --- a/src/common/trace-chunk.c +++ b/src/common/trace-chunk.c @@ -15,27 +15,28 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include -#include -#include #include #include #include +#include +#include +#include /* * Two ISO 8601-compatible timestamps, separated by a hypen, followed an @@ -110,6 +111,14 @@ struct lttng_trace_chunk { struct lttng_directory_handle *session_output_directory; struct lttng_directory_handle *chunk_directory; LTTNG_OPTIONAL(enum lttng_trace_chunk_command_type) close_command; + /* + * fd_tracker instance through which file descriptors should be + * created/closed. + * + * An fd_tracker always outlives any trace chunk; there is no + * need to perform any reference counting of that object. + */ + struct fd_tracker *fd_tracker; }; /* A trace chunk is uniquely identified by its (session id, chunk id) tuple. */ @@ -352,6 +361,16 @@ error: return NULL; } +LTTNG_HIDDEN +void lttng_trace_chunk_set_fd_tracker(struct lttng_trace_chunk *chunk, + struct fd_tracker *fd_tracker) +{ + assert(!chunk->session_output_directory); + assert(!chunk->chunk_directory); + assert(lttng_dynamic_pointer_array_get_count(&chunk->files) == 0); + chunk->fd_tracker = fd_tracker; +} + LTTNG_HIDDEN struct lttng_trace_chunk *lttng_trace_chunk_copy( struct lttng_trace_chunk *source_chunk) @@ -413,6 +432,7 @@ struct lttng_trace_chunk *lttng_trace_chunk_copy( new_chunk->chunk_directory = source_chunk->chunk_directory; } new_chunk->close_command = source_chunk->close_command; + new_chunk->fd_tracker = source_chunk->fd_tracker; pthread_mutex_unlock(&source_chunk->lock); end: return new_chunk; @@ -1746,6 +1766,7 @@ lttng_trace_chunk_registry_element_create_from_chunk( */ chunk->name = NULL; chunk->path = NULL; + element->chunk.fd_tracker = chunk->fd_tracker; element->chunk.in_registry_element = true; end: return element; diff --git a/src/common/trace-chunk.h b/src/common/trace-chunk.h index 0f3dc678b..52fce9960 100644 --- a/src/common/trace-chunk.h +++ b/src/common/trace-chunk.h @@ -61,6 +61,7 @@ */ struct lttng_trace_chunk; +struct fd_tracker; enum lttng_trace_chunk_status { LTTNG_TRACE_CHUNK_STATUS_OK, @@ -87,6 +88,10 @@ struct lttng_trace_chunk *lttng_trace_chunk_create( time_t chunk_creation_time, const char *path); +LTTNG_HIDDEN +void lttng_trace_chunk_set_fd_tracker(struct lttng_trace_chunk *chunk, + struct fd_tracker *fd_tracker); + /* * Copy a trace chunk. The copy that is returned is always a _user_ * mode chunk even if the source chunk was an _owner_ as there can never be