From: Jérémie Galarneau Date: Mon, 8 Feb 2021 23:04:20 +0000 (-0500) Subject: Clean-up: ust-consumer: pass metadata cache to its write method X-Git-Tag: v2.13.0-rc1~349 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a25d34bcf9a0d22f6814976ddb7376b464bd3e17;p=lttng-tools.git Clean-up: ust-consumer: pass metadata cache to its write method The consumer_metadata_cache_write function doesn't need access to the metadata channel; it can operate on the metadata cache itself and doesn't need to access its channel. Signed-off-by: Jérémie Galarneau Change-Id: I4350c034bbd4d89808e4153b21e7ff8a9ca04b2b --- diff --git a/src/common/consumer/consumer-metadata-cache.c b/src/common/consumer/consumer-metadata-cache.c index f712fa7f6..732a4687b 100644 --- a/src/common/consumer/consumer-metadata-cache.c +++ b/src/common/consumer/consumer-metadata-cache.c @@ -36,30 +36,32 @@ extern struct lttng_consumer_global_data consumer_data; * * Return 0 on success, a negative value on error. */ -static int extend_metadata_cache(struct lttng_consumer_channel *channel, +static int extend_metadata_cache(struct consumer_metadata_cache *cache, unsigned int size) { int ret = 0; char *tmp_data_ptr; unsigned int new_size, old_size; - assert(channel); - assert(channel->metadata_cache); + assert(cache); - old_size = channel->metadata_cache->cache_alloc_size; + old_size = cache->cache_alloc_size; new_size = max_t(unsigned int, old_size + size, old_size << 1); - DBG("Extending metadata cache to %u", new_size); - tmp_data_ptr = realloc(channel->metadata_cache->data, new_size); + DBG("Extending metadata cache: old size = %u, new size = %u", old_size, + new_size); + + tmp_data_ptr = realloc(cache->data, new_size); if (!tmp_data_ptr) { - ERR("Reallocating metadata cache"); - free(channel->metadata_cache->data); + ERR("Failed to re-allocate metadata cache"); + free(cache->data); ret = -1; goto end; } - /* Zero newly allocated memory */ + + /* Zero newly allocated memory. */ memset(tmp_data_ptr + old_size, 0, new_size - old_size); - channel->metadata_cache->data = tmp_data_ptr; - channel->metadata_cache->cache_alloc_size = new_size; + cache->data = tmp_data_ptr; + cache->cache_alloc_size = new_size; end: return ret; @@ -108,20 +110,16 @@ end: * various returned status codes. */ enum consumer_metadata_cache_write_status -consumer_metadata_cache_write(struct lttng_consumer_channel *channel, +consumer_metadata_cache_write(struct consumer_metadata_cache *cache, unsigned int offset, unsigned int len, uint64_t version, const char *data) { int ret = 0; - struct consumer_metadata_cache *cache; enum consumer_metadata_cache_write_status status; bool cache_is_invalidated = false; uint64_t original_max_offset; - assert(channel); - assert(channel->metadata_cache); - - cache = channel->metadata_cache; + assert(cache); ASSERT_LOCKED(cache->lock); original_max_offset = cache->max_offset; @@ -134,7 +132,7 @@ consumer_metadata_cache_write(struct lttng_consumer_channel *channel, DBG("Writing %u bytes from offset %u in metadata cache", len, offset); if (offset + len > cache->cache_alloc_size) { - ret = extend_metadata_cache(channel, + ret = extend_metadata_cache(cache, len - cache->cache_alloc_size + offset); if (ret < 0) { ERR("Extending metadata cache"); diff --git a/src/common/consumer/consumer-metadata-cache.h b/src/common/consumer/consumer-metadata-cache.h index 4c029b90e..303f5cd2a 100644 --- a/src/common/consumer/consumer-metadata-cache.h +++ b/src/common/consumer/consumer-metadata-cache.h @@ -57,7 +57,7 @@ struct consumer_metadata_cache { }; enum consumer_metadata_cache_write_status -consumer_metadata_cache_write(struct lttng_consumer_channel *channel, +consumer_metadata_cache_write(struct consumer_metadata_cache *cache, unsigned int offset, unsigned int len, uint64_t version, const char *data); int consumer_metadata_cache_allocate(struct lttng_consumer_channel *channel); diff --git a/src/common/ust-consumer/ust-consumer.c b/src/common/ust-consumer/ust-consumer.c index 5f1f93b0e..10c8f4e62 100644 --- a/src/common/ust-consumer/ust-consumer.c +++ b/src/common/ust-consumer/ust-consumer.c @@ -1333,7 +1333,8 @@ int lttng_ustconsumer_recv_metadata(int sock, uint64_t key, uint64_t offset, pthread_mutex_lock(&channel->metadata_cache->lock); cache_write_status = consumer_metadata_cache_write( - channel, offset, len, version, metadata_str); + channel->metadata_cache, offset, len, version, + metadata_str); pthread_mutex_unlock(&channel->metadata_cache->lock); switch (cache_write_status) { case CONSUMER_METADATA_CACHE_WRITE_STATUS_NO_CHANGE: