Clean-up: ust-consumer: pass metadata cache to its write method
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 8 Feb 2021 23:04:20 +0000 (18:04 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 9 Feb 2021 03:03:43 +0000 (22:03 -0500)
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 <jeremie.galarneau@efficios.com>
Change-Id: I4350c034bbd4d89808e4153b21e7ff8a9ca04b2b

src/common/consumer/consumer-metadata-cache.c
src/common/consumer/consumer-metadata-cache.h
src/common/ust-consumer/ust-consumer.c

index f712fa7f65043aeff6d688b06f9b22867683c8cc..732a4687b82cd335284402cd4b5108be9d4e346b 100644 (file)
@@ -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");
index 4c029b90e9208fdf74b1e8a6745028de49bb340a..303f5cd2a1aeb7d71968b74c7c13876a82b32992 100644 (file)
@@ -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);
index 5f1f93b0e1024c6c1eee422d80930b71ccaaf1a8..10c8f4e62c5c343984260a72a9e29b6b9b3976e7 100644 (file)
@@ -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:
This page took 0.060566 seconds and 4 git commands to generate.