From: Mathieu Desnoyers Date: Wed, 25 Jul 2012 21:39:12 +0000 (-0400) Subject: Fix: relayd metadata size X-Git-Tag: v2.1.0-rc1~44 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f64161251bd649abe5b6a473531adfa3af9bd6b6;p=lttng-tools.git Fix: relayd metadata size Trying to see better how the metadata size was handled, I ended up doing a couple of modifications to the size value sent by the sender: given that this header contains a size value that should cover both the metadata packet header size, and the following payload size (this is how kernel splice sent behaves), I modified kernel/UST mmap to do the same. I therefore changed the recently updated recv_metadata payload size calculation to match the encoded size, which should hopefully work for all kernel splice/mmap and UST mmap cases. Signed-off-by: Mathieu Desnoyers Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index f0663d10d..1ef6881c0 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -1070,13 +1070,14 @@ int relay_recv_metadata(struct lttcomm_relayd_hdr *recv_hdr, goto end; } - data_size = be64toh(recv_hdr->data_size); - payload_size = data_size; - /* - * Add 8 bytes (uint64_t) to the data size which is the value of the - * stream_id and the payload size. - */ - data_size += sizeof(uint64_t); + data_size = payload_size = be64toh(recv_hdr->data_size); + if (data_size < sizeof(struct lttcomm_relayd_metadata_payload)) { + ERR("Incorrect data size"); + ret = -1; + goto end; + } + payload_size -= sizeof(struct lttcomm_relayd_metadata_payload); + if (data_buffer_size < data_size) { data_buffer = realloc(data_buffer, data_size); if (!data_buffer) { diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index 551d8579a..22bf10020 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -81,6 +81,8 @@ ssize_t lttng_kconsumer_on_read_subbuffer_mmap( /* Handle stream on the relayd if the output is on the network */ if (relayd) { + unsigned long netlen = len; + /* * Lock the control socket for the complete duration of the function * since from this point on we will use the socket. @@ -88,9 +90,10 @@ ssize_t lttng_kconsumer_on_read_subbuffer_mmap( if (stream->metadata_flag) { /* Metadata requires the control socket. */ pthread_mutex_lock(&relayd->ctrl_sock_mutex); + netlen += sizeof(stream->relayd_stream_id); } - ret = consumer_handle_stream_before_relayd(stream, len); + ret = consumer_handle_stream_before_relayd(stream, netlen); if (ret >= 0) { /* Use the returned socket. */ outfd = ret; diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index a57bf1598..7ce03ad87 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -81,12 +81,15 @@ ssize_t lttng_ustconsumer_on_read_subbuffer_mmap( /* Handle stream on the relayd if the output is on the network */ if (relayd) { + unsigned long netlen = len; + if (stream->metadata_flag) { /* Only lock if metadata since we use the control socket. */ pthread_mutex_lock(&relayd->ctrl_sock_mutex); + netlen += sizeof(stream->relayd_stream_id); } - ret = consumer_handle_stream_before_relayd(stream, len); + ret = consumer_handle_stream_before_relayd(stream, netlen); if (ret >= 0) { outfd = ret;