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 20:25:31 +0000 (16:25 -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 64057c785f9512d734ccbd78649214125fad824d..d70a5d1d406b758e1b02cc61f22b440ee006a7b1 100644 (file)
@@ -1671,8 +1671,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)
 {
@@ -1682,6 +1681,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();
@@ -1699,7 +1700,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
@@ -1737,10 +1738,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) {
@@ -1754,7 +1755,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) {
@@ -1763,19 +1764,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.
@@ -1796,7 +1799,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;
        }
@@ -1805,9 +1809,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 3ff9dbf9937219a18037c3cc4d00e7cc6c786f9a..b7593d00182b23a4c604628ef372bd6a24ae861e 100644 (file)
@@ -26,6 +26,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 {
@@ -792,8 +793,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 275c963df2305dee886327378f0a6a78e977e8db..54314ec75a2c4d7758fd3c3ac2cd4d8492dee893 100644 (file)
@@ -7,6 +7,7 @@
  *
  */
 
+#include "common/buffer-view.h"
 #include <stdint.h>
 #define _LGPL_SOURCE
 #include <assert.h>
@@ -249,9 +250,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);
@@ -283,8 +284,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
@@ -1720,6 +1723,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);
@@ -1750,15 +1754,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 9055d0cf8baa82ef9a88257a3b002aa5823c1e5d..a6d8463a8ce2f6709da1de394e4b7729632af574 100644 (file)
@@ -1211,6 +1211,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();
 
@@ -1245,9 +1246,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;
@@ -2808,6 +2811,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);
@@ -2923,9 +2927,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.042903 seconds and 4 git commands to generate.