ret_read = lttng_consumer_read_subbuffer(metadata_stream, ctx, true);
if (ret_read < 0) {
- if (ret_read != -EAGAIN) {
- ERR("Kernel snapshot reading metadata subbuffer (ret: %zd)",
- ret_read);
- ret = ret_read;
- goto error_snapshot;
- }
- /* ret_read is negative at this point so we will exit the loop. */
- continue;
+ ERR("Kernel snapshot reading metadata subbuffer (ret: %zd)",
+ ret_read);
+ ret = ret_read;
+ goto error_snapshot;
}
- } while (ret_read >= 0);
+ } while (ret_read > 0);
if (use_relayd) {
close_relayd_stream(metadata_stream);
}
static
-int get_subbuffer_common(struct lttng_consumer_stream *stream,
+enum get_next_subbuffer_status get_subbuffer_common(
+ struct lttng_consumer_stream *stream,
struct stream_subbuffer *subbuffer)
{
int ret;
+ enum get_next_subbuffer_status status;
ret = kernctl_get_next_subbuf(stream->wait_fd);
- if (ret) {
+ switch (ret) {
+ case 0:
+ status = GET_NEXT_SUBBUFFER_STATUS_OK;
+ break;
+ case -ENODATA:
+ case -EAGAIN:
+ /*
+ * The caller only expects -ENODATA when there is no data to
+ * read, but the kernel tracer returns -EAGAIN when there is
+ * currently no data for a non-finalized stream, and -ENODATA
+ * when there is no data for a finalized stream. Those can be
+ * combined into a -ENODATA return value.
+ */
+ status = GET_NEXT_SUBBUFFER_STATUS_NO_DATA;
+ goto end;
+ default:
+ status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
goto end;
}
ret = stream->read_subbuffer_ops.extract_subbuffer_info(
- stream, subbuffer);
+ stream, subbuffer);
+ if (ret) {
+ status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
+ }
end:
- return ret;
+ return status;
}
static
-int get_next_subbuffer_splice(struct lttng_consumer_stream *stream,
+enum get_next_subbuffer_status get_next_subbuffer_splice(
+ struct lttng_consumer_stream *stream,
struct stream_subbuffer *subbuffer)
{
- int ret;
+ const enum get_next_subbuffer_status status =
+ get_subbuffer_common(stream, subbuffer);
- ret = get_subbuffer_common(stream, subbuffer);
- if (ret) {
+ if (status != GET_NEXT_SUBBUFFER_STATUS_OK) {
goto end;
}
subbuffer->buffer.fd = stream->wait_fd;
end:
- return ret;
+ return status;
}
static
-int get_next_subbuffer_mmap(struct lttng_consumer_stream *stream,
+enum get_next_subbuffer_status get_next_subbuffer_mmap(
+ struct lttng_consumer_stream *stream,
struct stream_subbuffer *subbuffer)
{
int ret;
+ enum get_next_subbuffer_status status;
const char *addr;
- ret = get_subbuffer_common(stream, subbuffer);
- if (ret) {
+ status = get_subbuffer_common(stream, subbuffer);
+ if (status != GET_NEXT_SUBBUFFER_STATUS_OK) {
goto end;
}
ret = get_current_subbuf_addr(stream, &addr);
if (ret) {
+ status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
goto end;
}
subbuffer->buffer.buffer = lttng_buffer_view_init(
addr, 0, subbuffer->info.data.padded_subbuf_size);
end:
- return ret;
+ return status;
}
static
-int get_next_subbuffer_metadata_check(struct lttng_consumer_stream *stream,
+enum get_next_subbuffer_status get_next_subbuffer_metadata_check(struct lttng_consumer_stream *stream,
struct stream_subbuffer *subbuffer)
{
int ret;
const char *addr;
bool coherent;
+ enum get_next_subbuffer_status status;
ret = kernctl_get_next_subbuf_metadata_check(stream->wait_fd,
&coherent);
subbuffer->info.metadata.padded_subbuf_size,
coherent ? "true" : "false");
end:
- return ret;
+ /*
+ * The caller only expects -ENODATA when there is no data to read, but
+ * the kernel tracer returns -EAGAIN when there is currently no data
+ * for a non-finalized stream, and -ENODATA when there is no data for a
+ * finalized stream. Those can be combined into a -ENODATA return value.
+ */
+ switch (ret) {
+ case 0:
+ status = GET_NEXT_SUBBUFFER_STATUS_OK;
+ break;
+ case -ENODATA:
+ case -EAGAIN:
+ /*
+ * The caller only expects -ENODATA when there is no data to
+ * read, but the kernel tracer returns -EAGAIN when there is
+ * currently no data for a non-finalized stream, and -ENODATA
+ * when there is no data for a finalized stream. Those can be
+ * combined into a -ENODATA return value.
+ */
+ status = GET_NEXT_SUBBUFFER_STATUS_NO_DATA;
+ break;
+ default:
+ status = GET_NEXT_SUBBUFFER_STATUS_ERROR;
+ break;
+ }
+
+ return status;
}
static
static
bool is_get_next_check_metadata_available(int tracer_fd)
{
- return kernctl_get_next_subbuf_metadata_check(tracer_fd, NULL) !=
- -ENOTTY;
+ const int ret = kernctl_get_next_subbuf_metadata_check(tracer_fd, NULL);
+ const bool available = ret != -ENOTTY;
+
+ if (ret == 0) {
+ /* get succeeded, make sure to put the subbuffer. */
+ kernctl_put_subbuf(tracer_fd);
+ }
+
+ return available;
+}
+
+static
+int signal_metadata(struct lttng_consumer_stream *stream,
+ struct lttng_consumer_local_data *ctx)
+{
+ ASSERT_LOCKED(stream->metadata_rdv_lock);
+ return pthread_cond_broadcast(&stream->metadata_rdv) ? -errno : 0;
}
static
metadata_bucket_destroy(stream->metadata_bucket);
stream->metadata_bucket = NULL;
}
+
+ stream->read_subbuffer_ops.on_sleep = signal_metadata;
}
if (!stream->read_subbuffer_ops.get_next_subbuffer) {