Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [lttng-dev] [PATCH lttng-tools] Fix: consumer data pending for empty streams
@ 2013-08-29  2:47 Mathieu Desnoyers
  2013-08-29 16:54 ` David Goulet
  0 siblings, 1 reply; 2+ messages in thread
From: Mathieu Desnoyers @ 2013-08-29  2:47 UTC (permalink / raw)


We should at least output one packet before a stream can be considered
as readable. So far, for PID buffers, if an application exits at the
wrong timing before a stop waiting for data pending, empty streams could
be visible by a babeltrace executed after data pending incorrectly
returned false.

Fix it by considering a stream for which the consumerd has written 0
bytes to the output as having data pending.

This applies to 2.3-rc and stable-2.2.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
---
diff --git a/src/common/consumer.c b/src/common/consumer.c
index 59207da..e64e2e2 100644
--- a/src/common/consumer.c
+++ b/src/common/consumer.c
@@ -498,6 +498,7 @@ struct lttng_consumer_stream *consumer_allocate_stream(uint64_t channel_key,
 	stream->key = stream_key;
 	stream->out_fd = -1;
 	stream->out_fd_offset = 0;
+	stream->output_written = 0;
 	stream->state = state;
 	stream->uid = uid;
 	stream->gid = gid;
@@ -1475,6 +1476,7 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
 					SYNC_FILE_RANGE_WRITE);
 			stream->out_fd_offset += ret;
 		}
+		stream->output_written += ret;
 		written += ret;
 	}
 	lttng_consumer_sync_trace_file(stream, orig_offset);
@@ -1688,6 +1690,7 @@ ssize_t lttng_consumer_on_read_subbuffer_splice(
 					SYNC_FILE_RANGE_WRITE);
 			stream->out_fd_offset += ret_splice;
 		}
+		stream->output_written += ret_splice;
 		written += ret_splice;
 	}
 	lttng_consumer_sync_trace_file(stream, orig_offset);
@@ -3400,6 +3403,16 @@ int consumer_data_pending(uint64_t id)
 		 */
 		ret = cds_lfht_is_node_deleted(&stream->node.node);
 		if (!ret) {
+			/*
+			 * An empty output file is not valid. We need at
+			 * least one packet generated per stream, even
+			 * if it contains no event, so it contains at
+			 * least one packet header.
+			 */
+			if (stream->output_written == 0) {
+				pthread_mutex_unlock(&stream->lock);
+				goto data_pending;
+			}
 			/* Check the stream if there is data in the buffers. */
 			ret = data_pending(stream);
 			if (ret == 1) {
diff --git a/src/common/consumer.h b/src/common/consumer.h
index 2003cbe..91f6b5c 100644
--- a/src/common/consumer.h
+++ b/src/common/consumer.h
@@ -221,6 +221,8 @@ struct lttng_consumer_stream {
 	int out_fd; /* output file to write the data */
 	/* Write position in the output file descriptor */
 	off_t out_fd_offset;
+	/* Amount of bytes written to the output */
+	uint64_t output_written;
 	enum lttng_consumer_stream_state state;
 	int shm_fd_is_copy;
 	int data_read;

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [lttng-dev] [PATCH lttng-tools] Fix: consumer data pending for empty streams
  2013-08-29  2:47 [lttng-dev] [PATCH lttng-tools] Fix: consumer data pending for empty streams Mathieu Desnoyers
@ 2013-08-29 16:54 ` David Goulet
  0 siblings, 0 replies; 2+ messages in thread
From: David Goulet @ 2013-08-29 16:54 UTC (permalink / raw)


Merged!

Mathieu Desnoyers:
> We should at least output one packet before a stream can be considered
> as readable. So far, for PID buffers, if an application exits at the
> wrong timing before a stop waiting for data pending, empty streams could
> be visible by a babeltrace executed after data pending incorrectly
> returned false.
> 
> Fix it by considering a stream for which the consumerd has written 0
> bytes to the output as having data pending.
> 
> This applies to 2.3-rc and stable-2.2.
> 
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
> ---
> diff --git a/src/common/consumer.c b/src/common/consumer.c
> index 59207da..e64e2e2 100644
> --- a/src/common/consumer.c
> +++ b/src/common/consumer.c
> @@ -498,6 +498,7 @@ struct lttng_consumer_stream *consumer_allocate_stream(uint64_t channel_key,
>  	stream->key = stream_key;
>  	stream->out_fd = -1;
>  	stream->out_fd_offset = 0;
> +	stream->output_written = 0;
>  	stream->state = state;
>  	stream->uid = uid;
>  	stream->gid = gid;
> @@ -1475,6 +1476,7 @@ ssize_t lttng_consumer_on_read_subbuffer_mmap(
>  					SYNC_FILE_RANGE_WRITE);
>  			stream->out_fd_offset += ret;
>  		}
> +		stream->output_written += ret;
>  		written += ret;
>  	}
>  	lttng_consumer_sync_trace_file(stream, orig_offset);
> @@ -1688,6 +1690,7 @@ ssize_t lttng_consumer_on_read_subbuffer_splice(
>  					SYNC_FILE_RANGE_WRITE);
>  			stream->out_fd_offset += ret_splice;
>  		}
> +		stream->output_written += ret_splice;
>  		written += ret_splice;
>  	}
>  	lttng_consumer_sync_trace_file(stream, orig_offset);
> @@ -3400,6 +3403,16 @@ int consumer_data_pending(uint64_t id)
>  		 */
>  		ret = cds_lfht_is_node_deleted(&stream->node.node);
>  		if (!ret) {
> +			/*
> +			 * An empty output file is not valid. We need at
> +			 * least one packet generated per stream, even
> +			 * if it contains no event, so it contains at
> +			 * least one packet header.
> +			 */
> +			if (stream->output_written == 0) {
> +				pthread_mutex_unlock(&stream->lock);
> +				goto data_pending;
> +			}
>  			/* Check the stream if there is data in the buffers. */
>  			ret = data_pending(stream);
>  			if (ret == 1) {
> diff --git a/src/common/consumer.h b/src/common/consumer.h
> index 2003cbe..91f6b5c 100644
> --- a/src/common/consumer.h
> +++ b/src/common/consumer.h
> @@ -221,6 +221,8 @@ struct lttng_consumer_stream {
>  	int out_fd; /* output file to write the data */
>  	/* Write position in the output file descriptor */
>  	off_t out_fd_offset;
> +	/* Amount of bytes written to the output */
> +	uint64_t output_written;
>  	enum lttng_consumer_stream_state state;
>  	int shm_fd_is_copy;
>  	int data_read;
> 



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-08-29 16:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-29  2:47 [lttng-dev] [PATCH lttng-tools] Fix: consumer data pending for empty streams Mathieu Desnoyers
2013-08-29 16:54 ` David Goulet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox