return ret;
}
+static
+void metadata_stream_reset_cache_consumed_position(
+ struct lttng_consumer_stream *stream)
+{
+ ASSERT_LOCKED(stream->lock);
+
+ DBG("Reset metadata cache of session %" PRIu64,
+ stream->chan->session_id);
+ stream->ust_metadata_pushed = 0;
+}
+
/*
* Receive the metadata updates from the sessiond. Supports receiving
* overlapping metadata, but is needs to always belong to a contiguous
{
int ret, ret_code = LTTCOMM_CONSUMERD_SUCCESS;
char *metadata_str;
+ enum consumer_metadata_cache_write_status cache_write_status;
DBG("UST consumer push metadata key %" PRIu64 " of len %" PRIu64, key, len);
health_code_update();
pthread_mutex_lock(&channel->metadata_cache->lock);
- ret = consumer_metadata_cache_write(channel, offset, len, version,
+ cache_write_status = consumer_metadata_cache_write(
+ channel->metadata_cache, offset, len, version,
metadata_str);
pthread_mutex_unlock(&channel->metadata_cache->lock);
- if (ret < 0) {
+ switch (cache_write_status) {
+ case CONSUMER_METADATA_CACHE_WRITE_STATUS_NO_CHANGE:
+ /*
+ * The write entirely overlapped with existing contents of the
+ * same metadata version (same content); there is nothing to do.
+ */
+ break;
+ case CONSUMER_METADATA_CACHE_WRITE_STATUS_INVALIDATED:
+ /*
+ * The metadata cache was invalidated (previously pushed
+ * content has been overwritten). Reset the stream's consumed
+ * metadata position to ensure the metadata poll thread consumes
+ * the whole cache.
+ */
+ pthread_mutex_lock(&channel->metadata_stream->lock);
+ metadata_stream_reset_cache_consumed_position(
+ channel->metadata_stream);
+ pthread_mutex_unlock(&channel->metadata_stream->lock);
+ /* Fall-through. */
+ case CONSUMER_METADATA_CACHE_WRITE_STATUS_APPENDED_CONTENT:
+ /*
+ * In both cases, the metadata poll thread has new data to
+ * consume.
+ */
+ ret = consumer_metadata_wakeup_pipe(channel);
+ if (ret) {
+ ret_code = LTTCOMM_CONSUMERD_ERROR_METADATA;
+ goto end_free;
+ }
+ break;
+ case CONSUMER_METADATA_CACHE_WRITE_STATUS_ERROR:
/* Unable to handle metadata. Notify session daemon. */
ret_code = LTTCOMM_CONSUMERD_ERROR_METADATA;
/*
* waiting for the metadata cache to be flushed.
*/
goto end_free;
+ default:
+ abort();
}
if (!wait) {
switch (msg.u.ask_channel.output) {
case LTTNG_EVENT_MMAP:
default:
- attr.output = LTTNG_UST_MMAP;
+ attr.output = LTTNG_UST_ABI_MMAP;
break;
}
/* Translate and save channel type. */
switch (msg.u.ask_channel.type) {
- case LTTNG_UST_CHAN_PER_CPU:
+ case LTTNG_UST_ABI_CHAN_PER_CPU:
channel->type = CONSUMER_CHANNEL_TYPE_DATA;
- attr.type = LTTNG_UST_CHAN_PER_CPU;
+ attr.type = LTTNG_UST_ABI_CHAN_PER_CPU;
/*
* Set refcount to 1 for owner. Below, we will
* pass ownership to the
*/
channel->refcount = 1;
break;
- case LTTNG_UST_CHAN_METADATA:
+ case LTTNG_UST_ABI_CHAN_METADATA:
channel->type = CONSUMER_CHANNEL_TYPE_METADATA;
- attr.type = LTTNG_UST_CHAN_METADATA;
+ attr.type = LTTNG_UST_ABI_CHAN_METADATA;
break;
default:
assert(0);
goto end_channel_error;
}
- if (msg.u.ask_channel.type == LTTNG_UST_CHAN_METADATA) {
+ if (msg.u.ask_channel.type == LTTNG_UST_ABI_CHAN_METADATA) {
ret = consumer_metadata_cache_allocate(channel);
if (ret < 0) {
ERR("Allocating metadata cache");
*/
ret = add_channel(channel, ctx);
if (ret < 0) {
- if (msg.u.ask_channel.type == LTTNG_UST_CHAN_METADATA) {
+ if (msg.u.ask_channel.type == LTTNG_UST_ABI_CHAN_METADATA) {
if (channel->switch_timer_enabled == 1) {
consumer_timer_switch_stop(channel);
}
return ustctl_stream_close_wakeup_fd(stream->ustream);
}
-static
-void metadata_stream_reset_cache_consumed_position(
- struct lttng_consumer_stream *stream)
-{
- DBG("Reset metadata cache of session %" PRIu64,
- stream->chan->session_id);
- stream->ust_metadata_pushed = 0;
-}
-
/*
* Write up to one packet from the metadata cache to the channel.
*
int ret;
pthread_mutex_lock(&stream->chan->metadata_cache->lock);
- if (stream->chan->metadata_cache->max_offset ==
- stream->ust_metadata_pushed) {
+ if (stream->chan->metadata_cache->contents.size ==
+ stream->ust_metadata_pushed) {
/*
* In the context of a user space metadata channel, a
* change in version can be detected in two ways:
}
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);
+ &stream->chan->metadata_cache->contents.data[stream->ust_metadata_pushed],
+ stream->chan->metadata_cache->contents.size -
+ stream->ust_metadata_pushed);
assert(write_len != 0);
if (write_len < 0) {
ERR("Writing one metadata packet");
}
stream->ust_metadata_pushed += write_len;
- assert(stream->chan->metadata_cache->max_offset >=
+ assert(stream->chan->metadata_cache->contents.size >=
stream->ust_metadata_pushed);
ret = write_len;
}
} else {
pthread_mutex_lock(&stream->chan->metadata_cache->lock);
- cache_empty = stream->chan->metadata_cache->max_offset ==
- stream->ust_metadata_pushed;
+ cache_empty = stream->chan->metadata_cache->contents.size ==
+ stream->ust_metadata_pushed;
pthread_mutex_unlock(&stream->chan->metadata_cache->lock);
}
} while (!got_subbuffer);
assert(stream);
assert(stream->ustream);
+ ASSERT_LOCKED(stream->lock);
DBG("UST consumer checking data pending");
/* Ease our life a bit. */
pthread_mutex_lock(&stream->chan->metadata_cache->lock);
- contiguous = stream->chan->metadata_cache->max_offset;
+ contiguous = stream->chan->metadata_cache->contents.size;
pthread_mutex_unlock(&stream->chan->metadata_cache->lock);
pushed = stream->ust_metadata_pushed;