]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: support creating a pool from a pool registration
authorWilly Tarreau <w@1wt.eu>
Tue, 5 Aug 2025 16:40:21 +0000 (18:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 6 Aug 2025 17:20:22 +0000 (19:20 +0200)
We've recently introduced pool registrations to be able to enumerate
all pool creation requests with their respective parameters, but till
now they were only used for debugging ("show pools detailed"). Let's
go a step further and split create_pool() in two:
  - the first half only allocates and sets the pool registration
  - the second half creates the pool from the registration

This is what this patch does. This now opens the ability to pre-create
registrations and create pools directly from there.

include/haproxy/pool.h
src/pool.c

index c60869475555460c30faed99a97d411086e3efba..963e5b6aee2c0a477520d7d1ca0b757916d5026c 100644 (file)
@@ -124,6 +124,7 @@ unsigned long long pool_total_used(void);
 void pool_flush(struct pool_head *pool);
 void pool_gc(struct pool_head *pool_ctx);
 struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags);
+struct pool_head *create_pool_from_reg(char *name, struct pool_registration *reg);
 void create_pool_callback(struct pool_head **ptr, char *name, unsigned int size);
 void *pool_destroy(struct pool_head *pool);
 void pool_destroy_all(void);
index 507aec2d89f5943007d8a8f04c0deaefbe48fb88..159a28a1b2c31adbddc025f3247ac84a1b3bcace 100644 (file)
@@ -293,25 +293,39 @@ static int mem_should_fail(const struct pool_head *pool)
  */
 struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags)
 {
-       unsigned int extra_mark, extra_caller, extra;
        struct pool_registration *reg;
        struct pool_head *pool;
-       struct pool_head *entry;
-       struct list *start;
-       unsigned int align;
-       unsigned int best_diff;
-       int thr __maybe_unused;
 
-       pool = NULL;
        reg = calloc(1, sizeof(*reg));
        if (!reg)
-               goto fail;
+               return NULL;
 
        strlcpy2(reg->name, name, sizeof(reg->name));
        reg->size = size;
        reg->flags = flags;
        reg->align = 0;
 
+       pool = create_pool_from_reg(name, reg);
+       if (!pool)
+               free(reg);
+       return pool;
+}
+
+/* create a pool from a pool registration. All configuration is taken from
+ * there.
+ */
+struct pool_head *create_pool_from_reg(char *name, struct pool_registration *reg)
+{
+       unsigned int extra_mark, extra_caller, extra;
+       unsigned int flags = reg->flags;
+       unsigned int size = reg->size;
+       struct pool_head *pool = NULL;
+       struct pool_head *entry;
+       struct list *start;
+       unsigned int align;
+       unsigned int best_diff;
+       int thr __maybe_unused;
+
        extra_mark = (pool_debugging & POOL_DBG_TAG) ? POOL_EXTRA_MARK : 0;
        extra_caller = (pool_debugging & POOL_DBG_CALLER) ? POOL_EXTRA_CALLER : 0;
        extra = extra_mark + extra_caller;
@@ -433,10 +447,8 @@ struct pool_head *create_pool(char *name, unsigned int size, unsigned int flags)
        pool->users++;
        pool->sum_size += size;
 
-       return pool;
  fail:
-       free(reg);
-       return NULL;
+       return pool;
 }
 
 /* Tries to allocate an object for the pool <pool> using the system's allocator