trace chunk: allow associating an fd_tracker to a trace chunk
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 20 Dec 2019 04:49:28 +0000 (23:49 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 30 Jan 2020 06:55:34 +0000 (01:55 -0500)
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 <jeremie.galarneau@efficios.com>
Change-Id: I5b3302e26ace2babadba286ca8bd4a016014bdd8

src/common/trace-chunk.c
src/common/trace-chunk.h

index 7407f38f391ce60351d9746bfa0813a2429679be..326d42ce2c6656c02f5d00cbba6359915536e5ab 100644 (file)
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <lttng/constant.h>
-#include <common/string-utils/format.h>
-#include <common/trace-chunk.h>
-#include <common/trace-chunk-registry.h>
-#include <common/hashtable/utils.h>
-#include <common/hashtable/hashtable.h>
-#include <common/error.h>
-#include <common/utils.h>
-#include <common/time.h>
-#include <common/optional.h>
 #include <common/compat/directory-handle.h>
 #include <common/credentials.h>
 #include <common/defaults.h>
 #include <common/dynamic-array.h>
+#include <common/error.h>
+#include <common/fd-tracker/fd-tracker.h>
+#include <common/hashtable/hashtable.h>
+#include <common/hashtable/utils.h>
+#include <common/optional.h>
+#include <common/string-utils/format.h>
+#include <common/time.h>
+#include <common/trace-chunk-registry.h>
+#include <common/trace-chunk.h>
+#include <common/utils.h>
+#include <lttng/constant.h>
 
-#include <urcu/ref.h>
-#include <urcu/rculfhash.h>
-#include <sys/stat.h>
 #include <inttypes.h>
 #include <pthread.h>
 #include <stdio.h>
+#include <sys/stat.h>
+#include <urcu/rculfhash.h>
+#include <urcu/ref.h>
 
 /*
  * 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;
index 0f3dc678bfedcc92225069b0282d04035c19b51d..52fce996020ed5926b26d8f43c01fb5a4c8040be 100644 (file)
@@ -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
This page took 0.027504 seconds and 4 git commands to generate.