[lttng-dev] [PATCH lttng-tools 2/2] Fix: consumerd: add missing put_subbuf for ust and kernel errors

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Wed Jan 11 20:49:49 UTC 2017


While reading a sub-buffer, error handling need to put the sub-buffer,
else all future attempts to use the stream will trigger warnings.

The affects recent features added to UST and kernel tracing.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
---
 src/common/kernel-consumer/kernel-consumer.c | 22 ++++++++++++++++++++++
 src/common/ust-consumer/ust-consumer.c       |  4 ++++
 2 files changed, 26 insertions(+)

diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c
index bb5ba3b..d5418dc 100644
--- a/src/common/kernel-consumer/kernel-consumer.c
+++ b/src/common/kernel-consumer/kernel-consumer.c
@@ -1315,12 +1315,34 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
 		}
 		ret = update_stream_stats(stream);
 		if (ret < 0) {
+			err = kernctl_put_subbuf(infd);
+			if (err != 0) {
+				if (err == -EFAULT) {
+					PERROR("Error in unreserving sub buffer\n");
+				} else if (err == -EIO) {
+					/* Should never happen with newer LTTng versions */
+					PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
+				}
+				ret = err;
+				goto end;
+			}
 			goto end;
 		}
 	} else {
 		write_index = 0;
 		ret = metadata_stream_check_version(infd, stream);
 		if (ret < 0) {
+			err = kernctl_put_subbuf(infd);
+			if (err != 0) {
+				if (err == -EFAULT) {
+					PERROR("Error in unreserving sub buffer\n");
+				} else if (err == -EIO) {
+					/* Should never happen with newer LTTng versions */
+					PERROR("Reader has been pushed by the writer, last sub-buffer corrupted.");
+				}
+				ret = err;
+				goto end;
+			}
 			goto end;
 		}
 	}
diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c
index 7bbfa60..97f0497 100644
--- a/src/common/ust-consumer/ust-consumer.c
+++ b/src/common/ust-consumer/ust-consumer.c
@@ -2496,6 +2496,8 @@ retry:
 		index.offset = htobe64(stream->out_fd_offset);
 		ret = get_index_values(&index, ustream);
 		if (ret < 0) {
+			err = ustctl_put_subbuf(ustream);
+			assert(err == 0);
 			goto end;
 		}
 
@@ -2503,6 +2505,8 @@ retry:
 		ret = update_stream_stats(stream);
 		if (ret < 0) {
 			PERROR("kernctl_get_events_discarded");
+			err = ustctl_put_subbuf(ustream);
+			assert(err == 0);
 			goto end;
 		}
 	} else {
-- 
2.1.4



More information about the lttng-dev mailing list