- 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;
- int ret;
-
- pthread_mutex_lock(&stream->chan->metadata_cache->lock);
- ret = metadata_stream_check_version(stream);
- if (ret < 0) {
- goto end;
- }
- if (stream->chan->metadata_cache->max_offset
- == stream->ust_metadata_pushed) {
- ret = 0;
- goto end;
- }
-
- write_len = ustctl_write_one_packet_to_channel(stream->chan->uchan,
- &stream->chan->metadata_cache->data[stream->ust_metadata_pushed],
- stream->chan->metadata_cache->max_offset
- - stream->ust_metadata_pushed);
- assert(write_len != 0);
- if (write_len < 0) {
- ERR("Writing one metadata packet");
- ret = -1;
- goto end;
- }
- stream->ust_metadata_pushed += write_len;
-
- assert(stream->chan->metadata_cache->max_offset >=
- stream->ust_metadata_pushed);
- ret = write_len;
-
-end:
- pthread_mutex_unlock(&stream->chan->metadata_cache->lock);
- return ret;
-}