From: Willy Tarreau Date: Tue, 5 Aug 2025 16:40:21 +0000 (+0200) Subject: MINOR: pools: support creating a pool from a pool registration X-Git-Tag: v3.3-dev6~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=18505f9718e25028d64780be10dbb7288d21296a;p=thirdparty%2Fhaproxy.git MINOR: pools: support creating a pool from a pool registration 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. --- diff --git a/include/haproxy/pool.h b/include/haproxy/pool.h index c60869475..963e5b6ae 100644 --- a/include/haproxy/pool.h +++ b/include/haproxy/pool.h @@ -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); diff --git a/src/pool.c b/src/pool.c index 507aec2d8..159a28a1b 100644 --- a/src/pool.c +++ b/src/pool.c @@ -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 using the system's allocator