From db95cf8bf1be068238f12e248f13ed103d86d1e5 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 10 Apr 2019 10:31:47 -0400 Subject: [PATCH] Fix: don't access packet header for stream_id and stream_instance_id getters The stream ID and stream instance ID are invariant for a stream, so there is no point reading them from the packet header currently owned by the consumer (between get/put subbuf). Actually, the consumer try to access the stream_id from the live timer when sending a live beacon without getting the reader subbuffer first. Doing so is racy against producers. In typical live scenarios (non-overwrite channels), the producers will always write the same stream id and stream instance id values at the same header offsets, which will "work", except for the initial state of an empty buffer: the value "0" will be returned (erroneously). For the less frequently used scenario of a live session with "overwrite" channels, this is handled by issuing a CHAN_WARN_ON, which disables tracing for the channel, and prints warning to the consumerd console when running consumerd with LTTNG_UST_DEBUG=1. In the case where a ring buffer does not have any data ready, it makes no sense to try to get a subbuffer for reading anyway, so the approach was broken. So return the stream id and stream instance id from the internal data structures rather than reading it from the ring buffer. Signed-off-by: Mathieu Desnoyers --- liblttng-ust/lttng-ring-buffer-client.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/liblttng-ust/lttng-ring-buffer-client.h b/liblttng-ust/lttng-ring-buffer-client.h index 0fae8878..ab472352 100644 --- a/liblttng-ust/lttng-ring-buffer-client.h +++ b/liblttng-ust/lttng-ring-buffer-client.h @@ -580,12 +580,11 @@ static int client_stream_id(struct lttng_ust_lib_ring_buffer *buf, struct lttng_ust_shm_handle *handle, uint64_t *stream_id) { - struct packet_header *header; + struct channel *chan = shmp(handle, buf->backend.chan); + struct lttng_channel *lttng_chan = channel_get_private(chan); + + *stream_id = lttng_chan->id; - header = client_packet_header(buf, handle); - if (!header) - return -1; - *stream_id = header->stream_id; return 0; } @@ -616,10 +615,8 @@ static int client_instance_id(struct lttng_ust_lib_ring_buffer *buf, struct lttng_ust_shm_handle *handle, uint64_t *id) { - struct packet_header *header; + *id = buf->backend.cpu; - header = client_packet_header(buf, handle); - *id = header->stream_instance_id; return 0; } -- 2.34.1