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.13.0-rc1~637 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=fd424d99bfddf3581bc55fdf14799a50661beddd;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 64057c785..d70a5d1d4 100644 --- a/src/common/consumer/consumer.c +++ b/src/common/consumer/consumer.c @@ -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, 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. @@ -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); } diff --git a/src/common/consumer/consumer.h b/src/common/consumer/consumer.h index 3ff9dbf99..b7593d001 100644 --- a/src/common/consumer/consumer.h +++ b/src/common/consumer/consumer.h @@ -26,6 +26,7 @@ #include #include #include +#include /* 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( diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index 275c963df..54314ec75 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -7,6 +7,7 @@ * */ +#include "common/buffer-view.h" #include #define _LGPL_SOURCE #include @@ -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)) { diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 9055d0cf8..a6d8463a8 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -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_