consumerd: cleanup: use buffer view interface for mmap read subbuf
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 4 May 2020 23:04:02 +0000 (19:04 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 26 May 2020 21:28:41 +0000 (17:28 -0400)
Replace explicit pointer + size parameters by an lttng_buffer_view
in lttng_consumer_on_read_subbuffer_mmap().

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I76f35b3e295c596cdf4bbb8a6d01168a850a721a

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 2eccee5cb9295fd84001a7f7cd39c009b423e92c..6525a7203130e7bbf3ce3a97cba489735029a61b 100644 (file)
@@ -1672,8 +1672,7 @@ end:
 ssize_t lttng_consumer_on_read_subbuffer_mmap(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream,
-               const char *buffer,
-               unsigned long len,
+               const struct lttng_buffer_view *buffer,
                unsigned long padding,
                struct ctf_packet_index *index)
 {
@@ -1683,6 +1682,8 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
        int outfd = stream->out_fd;
        struct consumer_relayd_sock_pair *relayd = NULL;
        unsigned int relayd_hang_up = 0;
+       const size_t subbuf_content_size = buffer->size - padding;
+       size_t write_len;
 
        /* RCU lock for the relayd pointer */
        rcu_read_lock();
@@ -1700,7 +1701,7 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
 
        /* Handle stream on the relayd if the output is on the network */
        if (relayd) {
-               unsigned long netlen = len;
+               unsigned long netlen = subbuf_content_size;
 
                /*
                 * Lock the control socket for the complete duration of the function
@@ -1738,10 +1739,10 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
                                goto write_error;
                        }
                }
-       } else {
-               /* No streaming, we have to set the len with the full padding */
-               len += padding;
 
+               write_len = subbuf_content_size;
+       } else {
+               /* No streaming; we have to write the full padding. */
                if (stream->metadata_flag && stream->reset_metadata_flag) {
                        ret = utils_truncate_stream_file(stream->out_fd, 0);
                        if (ret < 0) {
@@ -1755,7 +1756,7 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
                 * Check if we need to change the tracefile before writing the packet.
                 */
                if (stream->chan->tracefile_size > 0 &&
-                               (stream->tracefile_size_current + len) >
+                               (stream->tracefile_size_current + buffer->size) >
                                stream->chan->tracefile_size) {
                        ret = consumer_stream_rotate_output_files(stream);
                        if (ret) {
@@ -1764,19 +1765,21 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
                        outfd = stream->out_fd;
                        orig_offset = 0;
                }
-               stream->tracefile_size_current += len;
+               stream->tracefile_size_current += buffer->size;
                if (index) {
                        index->offset = htobe64(stream->out_fd_offset);
                }
+
+               write_len = buffer->size;
        }
 
        /*
         * This call guarantee that len or less is returned. It's impossible to
         * receive a ret value that is bigger than len.
         */
-       ret = lttng_write(outfd, bufferlen);
-       DBG("Consumer mmap write() ret %zd (len %lu)", ret, len);
-       if (ret < 0 || ((size_t) ret != len)) {
+       ret = lttng_write(outfd, buffer->data, write_len);
+       DBG("Consumer mmap write() ret %zd (len %lu)", ret, write_len);
+       if (ret < 0 || ((size_t) ret != write_len)) {
                /*
                 * Report error to caller if nothing was written else at least send the
                 * amount written.
@@ -1797,7 +1800,8 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
                        DBG("Consumer mmap write detected relayd hang up");
                } else {
                        /* Unhandled error, print it and stop function right now. */
-                       PERROR("Error in write mmap (ret %zd != len %lu)", ret, len);
+                       PERROR("Error in write mmap (ret %zd != write_len %zu)", ret,
+                                       write_len);
                }
                goto write_error;
        }
@@ -1806,9 +1810,9 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
        /* This call is useless on a socket so better save a syscall. */
        if (!relayd) {
                /* This won't block, but will start writeout asynchronously */
-               lttng_sync_file_range(outfd, stream->out_fd_offset, len,
+               lttng_sync_file_range(outfd, stream->out_fd_offset, write_len,
                                SYNC_FILE_RANGE_WRITE);
-               stream->out_fd_offset += len;
+               stream->out_fd_offset += write_len;
                lttng_consumer_sync_trace_file(stream, orig_offset);
        }
 
index 16b9487cd3ed48b5b81c87256a8797b762231756..2bd45f2e1de9c0457c1e2b6fd41224b12b2dc91b 100644 (file)
@@ -36,6 +36,7 @@
 #include <common/index/ctf-index.h>
 #include <common/trace-chunk-registry.h>
 #include <common/credentials.h>
+#include <common/buffer-view.h>
 
 /* Commands for consumer */
 enum lttng_consumer_command {
@@ -801,8 +802,7 @@ void lttng_consumer_destroy(struct lttng_consumer_local_data *ctx);
 ssize_t lttng_consumer_on_read_subbuffer_mmap(
                struct lttng_consumer_local_data *ctx,
                struct lttng_consumer_stream *stream,
-               const char *buffer,
-               unsigned long len,
+               const struct lttng_buffer_view *buffer,
                unsigned long padding,
                struct ctf_packet_index *index);
 ssize_t lttng_consumer_on_read_subbuffer_splice(
index 2878355a563623eefad9dc0fb56af89d86cbebc7..d6cefe4e54bdc144b6e810e5641aef052b4a5b9f 100644 (file)
@@ -17,6 +17,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include "common/buffer-view.h"
 #include <stdint.h>
 #define _LGPL_SOURCE
 #include <assert.h>
@@ -259,9 +260,9 @@ static int lttng_kconsumer_snapshot_channel(
                        ssize_t read_len;
                        unsigned long len, padded_len;
                        const char *subbuf_addr;
+                       struct lttng_buffer_view subbuf_view;
 
                        health_code_update();
-
                        DBG("Kernel consumer taking snapshot at pos %lu", consumed_pos);
 
                        ret = kernctl_get_subbuf(stream->wait_fd, &consumed_pos);
@@ -293,8 +294,10 @@ static int lttng_kconsumer_snapshot_channel(
                                goto error_put_subbuf;
                        }
 
+                       subbuf_view = lttng_buffer_view_init(
+                                       subbuf_addr, 0, padded_len);
                        read_len = lttng_consumer_on_read_subbuffer_mmap(ctx,
-                                       stream, subbuf_addr, len,
+                                       stream, &subbuf_view,
                                        padded_len - len, NULL);
                        /*
                         * We write the padded len in local tracefiles but the data len
@@ -1713,6 +1716,7 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
        case CONSUMER_CHANNEL_MMAP:
        {
                const char *subbuf_addr;
+               struct lttng_buffer_view subbuf_view;
 
                /* Get subbuffer size without padding */
                err = kernctl_get_subbuf_size(infd, &subbuf_size);
@@ -1743,15 +1747,15 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
 
                padding = len - subbuf_size;
 
+               subbuf_view = lttng_buffer_view_init(subbuf_addr, 0, len);
+
                /* write the subbuffer to the tracefile */
-               ret = lttng_consumer_on_read_subbuffer_mmap(ctx, stream,
-                               subbuf_addr,
-                               subbuf_size,
-                               padding, &index);
+               ret = lttng_consumer_on_read_subbuffer_mmap(
+                               ctx, stream, &subbuf_view, padding, &index);
                /*
-                * The mmap operation should write subbuf_size amount of data when
-                * network streaming or the full padding (len) size when we are _not_
-                * streaming.
+                * The mmap operation should write subbuf_size amount of data
+                * when network streaming or the full padding (len) size when we
+                * are _not_ streaming.
                 */
                if ((ret != subbuf_size && stream->net_seq_idx != (uint64_t) -1ULL) ||
                                (ret != len && stream->net_seq_idx == (uint64_t) -1ULL)) {
index 0e24f8c8c73053f58c85439f788049567938b599..d1b04438b0d76956bd74ff2c8ddb2d8acb777418 100644 (file)
@@ -1221,6 +1221,7 @@ static int snapshot_channel(struct lttng_consumer_channel *channel,
                        ssize_t read_len;
                        unsigned long len, padded_len;
                        const char *subbuf_addr;
+                       struct lttng_buffer_view subbuf_view;
 
                        health_code_update();
 
@@ -1255,9 +1256,11 @@ static int snapshot_channel(struct lttng_consumer_channel *channel,
                                goto error_put_subbuf;
                        }
 
+                       subbuf_view = lttng_buffer_view_init(
+                                       subbuf_addr, 0, padded_len);
                        read_len = lttng_consumer_on_read_subbuffer_mmap(ctx,
-                                       stream, subbuf_addr, len,
-                                       padded_len - len, NULL);
+                                       stream, &subbuf_view, padded_len - len,
+                                       NULL);
                        if (use_relayd) {
                                if (read_len != len) {
                                        ret = -EPERM;
@@ -2791,6 +2794,7 @@ int lttng_ustconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
        struct ustctl_consumer_stream *ustream;
        struct ctf_packet_index index;
        const char *subbuf_addr;
+       struct lttng_buffer_view subbuf_view;
 
        assert(stream);
        assert(stream->ustream);
@@ -2906,9 +2910,11 @@ retry:
                goto error_put_subbuf;
        }
 
+       subbuf_view = lttng_buffer_view_init(subbuf_addr, 0, len);
+
        /* write the subbuffer to the tracefile */
        ret = lttng_consumer_on_read_subbuffer_mmap(
-                       ctx, stream, subbuf_addr, subbuf_size, padding, &index);
+                       ctx, stream, &subbuf_view, padding, &index);
        /*
         * The mmap operation should write subbuf_size amount of data when
         * network streaming or the full padding (len) size when we are _not_
This page took 0.030854 seconds and 4 git commands to generate.