+/*
+ * Reset the metadata cache.
+ */
+static
+void metadata_cache_reset(struct consumer_metadata_cache *cache)
+{
+ memset(cache->data, 0, cache->cache_alloc_size);
+ cache->max_offset = 0;
+}
+
+/*
+ * Check if the metadata cache version changed.
+ * If it did, reset the metadata cache.
+ * The metadata cache lock MUST be held.
+ *
+ * Returns 0 on success, a negative value on error.
+ */
+static
+int metadata_cache_check_version(struct consumer_metadata_cache *cache,
+ struct lttng_consumer_channel *channel, uint64_t version)
+{
+ int ret = 0;
+
+ if (cache->version == version) {
+ goto end;
+ }
+
+ DBG("Metadata cache version update to %" PRIu64, version);
+ metadata_cache_reset(cache);
+ cache->version = version;
+
+end:
+ return ret;
+}
+
+/*
+ * Write a character on the metadata poll pipe to wake the metadata thread.
+ * Returns 0 on success, -1 on error.
+ */
+int consumer_metadata_wakeup_pipe(const struct lttng_consumer_channel *channel)
+{
+ int ret = 0;
+ const char dummy = 'c';
+
+ if (channel->monitor && channel->metadata_stream) {
+ ssize_t write_ret;
+
+ write_ret = lttng_write(channel->metadata_stream->ust_metadata_poll_pipe[1],
+ &dummy, 1);
+ if (write_ret < 1) {
+ PERROR("Wake-up UST metadata pipe");
+ ret = -1;
+ goto end;
+ }
+ }
+
+end:
+ return ret;
+}
+