Fix: relayd metadata size
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 Jul 2012 21:39:12 +0000 (17:39 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 26 Jul 2012 16:25:19 +0000 (12:25 -0400)
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 <mathieu.desnoyers@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
src/bin/lttng-relayd/main.c
src/common/kernel-consumer/kernel-consumer.c
src/common/ust-consumer/ust-consumer.c

index f0663d10dd85ee1673dcfe79f561cd1102bb1f86..1ef6881c09f8c4e63efab37f257f5869e80ba1ab 100644 (file)
@@ -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) {
index 551d8579a21ad4c6e86bed6904df6290c4304d24..22bf1002097a1e33a846f2a5c04d6305f6308d69 100644 (file)
@@ -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;
index a57bf15987d28061bf56a994dfacc0ad882c6ecd..7ce03ad87dde9b442015f3dc5af9b05697e2d8a5 100644 (file)
@@ -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;
 
This page took 0.038229 seconds and 4 git commands to generate.