- int ret;
-
- ret = ustctl_get_timestamp_begin(ustream, &index->timestamp_begin);
- if (ret < 0) {
- PERROR("ustctl_get_timestamp_begin");
- goto error;
- }
- index->timestamp_begin = htobe64(index->timestamp_begin);
-
- ret = ustctl_get_timestamp_end(ustream, &index->timestamp_end);
- if (ret < 0) {
- PERROR("ustctl_get_timestamp_end");
- goto error;
- }
- index->timestamp_end = htobe64(index->timestamp_end);
-
- ret = ustctl_get_events_discarded(ustream, &index->events_discarded);
- if (ret < 0) {
- PERROR("ustctl_get_events_discarded");
- goto error;
- }
- index->events_discarded = htobe64(index->events_discarded);
-
- ret = ustctl_get_content_size(ustream, &index->content_size);
- if (ret < 0) {
- PERROR("ustctl_get_content_size");
- goto error;
- }
- index->content_size = htobe64(index->content_size);
-
- ret = ustctl_get_packet_size(ustream, &index->packet_size);
- if (ret < 0) {
- PERROR("ustctl_get_packet_size");
- goto error;
- }
- index->packet_size = htobe64(index->packet_size);
-
- ret = ustctl_get_stream_id(ustream, &index->stream_id);
- if (ret < 0) {
- PERROR("ustctl_get_stream_id");
- goto error;
- }
- index->stream_id = htobe64(index->stream_id);
-
- ret = ustctl_get_instance_id(ustream, &index->stream_instance_id);
- if (ret < 0) {
- PERROR("ustctl_get_instance_id");
- goto error;
- }
- index->stream_instance_id = htobe64(index->stream_instance_id);
-
- ret = ustctl_get_sequence_number(ustream, &index->packet_seq_num);
- if (ret < 0) {
- PERROR("ustctl_get_sequence_number");
- goto error;
- }
- index->packet_seq_num = htobe64(index->packet_seq_num);
-
-error:
- return ret;
-}
-
-static
-void metadata_stream_reset_cache(struct lttng_consumer_stream *stream,
- struct consumer_metadata_cache *cache)
-{
- DBG("Metadata stream update to version %" PRIu64,
- cache->version);
- stream->ust_metadata_pushed = 0;
- stream->metadata_version = cache->version;
- stream->reset_metadata_flag = 1;
-}
-
-/*
- * Check if the version of the metadata stream and metadata cache match.
- * If the cache got updated, reset the metadata stream.
- * The stream lock and metadata cache lock MUST be held.
- * Return 0 on success, a negative value on error.
- */
-static
-int metadata_stream_check_version(struct lttng_consumer_stream *stream)
-{
- int ret = 0;
- struct consumer_metadata_cache *cache = stream->chan->metadata_cache;
-
- if (cache->version == stream->metadata_version) {
- goto end;
- }
- metadata_stream_reset_cache(stream, cache);
-
-end:
- return ret;
-}
-
-/*
- * Write up to one packet from the metadata cache to the channel.
- *
- * Returns the number of bytes pushed in the cache, or a negative value
- * on error.
- */
-static
-int commit_one_metadata_packet(struct lttng_consumer_stream *stream)
-{
- ssize_t write_len;