Keep read-only copies of fields from the channel to the stream
authorJulien Desfossez <jdesfossez@efficios.com>
Mon, 11 Dec 2017 21:17:48 +0000 (16:17 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 8 Mar 2018 21:42:47 +0000 (16:42 -0500)
In the consumer, we sometimes need to read the channel pathname or
tracefile_size from a stream, but we cannot always access those values
safely. So we now keep a copy of those values when we add or allocate
streams.

Signed-off-by: Julien Desfossez <jdesfossez@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/consumer/consumer.c
src/common/consumer/consumer.h
src/common/kernel-consumer/kernel-consumer.c
src/common/ust-consumer/ust-consumer.c

index 6b920b6b1ef63ee5d6e50cc4092b89bc498b7a9d..2fa65f4d4e53666e18b0278cea052b20177a6158 100644 (file)
@@ -541,6 +541,16 @@ void consumer_del_stream_for_metadata(struct lttng_consumer_stream *stream)
        consumer_stream_destroy(stream, metadata_ht);
 }
 
+void consumer_stream_update_channel_attributes(
+               struct lttng_consumer_stream *stream,
+               struct lttng_consumer_channel *channel)
+{
+       stream->channel_read_only_attributes.tracefile_size =
+                       channel->tracefile_size;
+       memcpy(stream->channel_read_only_attributes.path, channel->pathname,
+                       sizeof(stream->channel_read_only_attributes.path));
+}
+
 struct lttng_consumer_stream *consumer_allocate_stream(uint64_t channel_key,
                uint64_t stream_key,
                enum lttng_consumer_stream_state state,
index eb2958e20669593ed4c8cb7b199c3c3f3fa06039..a7d0ee1a706cc719f6877b168a6819f97f72b0ac 100644 (file)
@@ -415,6 +415,17 @@ struct lttng_consumer_stream {
        pthread_cond_t metadata_rdv;
        pthread_mutex_t metadata_rdv_lock;
 
+       /*
+        * Read-only copies of channel values. We cannot safely access the
+        * channel from a stream, so we need to have a local copy of these
+        * fields in the stream object. These fields should be removed from
+        * the stream objects when we introduce refcounting.
+        */
+       struct {
+               char path[LTTNG_PATH_MAX];
+               uint64_t tracefile_size;
+       } channel_read_only_attributes;
+
        /* Indicate if the stream still has some data to be read. */
        unsigned int has_data:1;
        /*
@@ -662,6 +673,14 @@ void lttng_consumer_cleanup(void);
  */
 int lttng_consumer_poll_socket(struct pollfd *kconsumer_sockpoll);
 
+/*
+ * Copy the fields from the channel that need to be accessed (read-only)
+ * directly from the stream.
+ */
+void consumer_stream_update_channel_attributes(
+               struct lttng_consumer_stream *stream,
+               struct lttng_consumer_channel *channel);
+
 struct lttng_consumer_stream *consumer_allocate_stream(uint64_t channel_key,
                uint64_t stream_key,
                enum lttng_consumer_stream_state state,
index 103df665a78d73dd319a5a6566894f9279e1cb9e..539d80b0b4a32223054a08be4116fda25f7986eb 100644 (file)
@@ -658,6 +658,8 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
 
                new_stream->chan = channel;
                new_stream->wait_fd = fd;
+               consumer_stream_update_channel_attributes(new_stream,
+                               channel);
                switch (channel->output) {
                case CONSUMER_CHANNEL_SPLICE:
                        new_stream->output = LTTNG_EVENT_SPLICE;
index ec078fb477a39eec0988c3075d8f3d86cad91ea4..00937a44dd0172882e03c2ea21d361a1597449c8 100644 (file)
@@ -184,6 +184,7 @@ static struct lttng_consumer_stream *allocate_stream(int cpu, int key,
                goto error;
        }
 
+       consumer_stream_update_channel_attributes(stream, channel);
        stream->chan = channel;
 
 error:
This page took 0.0301 seconds and 5 git commands to generate.