From: Jérémie Galarneau Date: Mon, 4 May 2020 23:04:02 +0000 (-0400) Subject: consumerd: cleanup: use buffer view interface for mmap read subbuf X-Git-Tag: v2.11.5~32 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=b770aa7ff007d18a53a3293a396880ad7ce42c8e;p=lttng-tools.git consumerd: cleanup: use buffer view interface for mmap read subbuf Replace explicit pointer + size parameters by an lttng_buffer_view in lttng_consumer_on_read_subbuffer_mmap(). Signed-off-by: Jérémie Galarneau Change-Id: I76f35b3e295c596cdf4bbb8a6d01168a850a721a --- diff --git a/src/common/consumer/consumer.c b/src/common/consumer/consumer.c index 2eccee5cb..6525a7203 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -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, buffer, len); - 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); } diff --git a/src/common/consumer/consumer.h b/src/common/consumer/consumer.h index 16b9487cd..2bd45f2e1 100644 --- a/src/common/consumer/consumer.h +++ b/src/common/consumer/consumer.h @@ -36,6 +36,7 @@ #include #include #include +#include /* 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( diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index 2878355a5..d6cefe4e5 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -17,6 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "common/buffer-view.h" #include #define _LGPL_SOURCE #include @@ -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)) { diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 0e24f8c8c..d1b04438b 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -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_