From: Aurelien DARRAGON Date: Tue, 6 May 2025 18:45:40 +0000 (+0200) Subject: MINOR: counters: add shared counters helpers to get and drop shared pointers X-Git-Tag: v3.3-dev1~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aa53887398982cce896956a5e0e50719c0dad06d;p=thirdparty%2Fhaproxy.git MINOR: counters: add shared counters helpers to get and drop shared pointers create include/haproxy/counters.h and src/counters.c files to anticipate for further helpers as some counters specific tasks needs to be carried out and since counters are shared between multiple object types (ie: listener, proxy, server..) we need generic helpers. Add some shared counters helper which are not yet used but will be updated in upcoming commits. --- diff --git a/Makefile b/Makefile index 1959ac479..9f5d3ffed 100644 --- a/Makefile +++ b/Makefile @@ -984,7 +984,7 @@ OBJS += src/mux_h2.o src/mux_h1.o src/mux_fcgi.o src/log.o \ src/lb_fas.o src/clock.o src/sock_inet.o src/ev_select.o \ src/lb_map.o src/shctx.o src/mworker-prog.o src/hpack-dec.o \ src/arg.o src/signal.o src/fix.o src/dynbuf.o src/guid.o \ - src/cfgparse-tcp.o src/lb_ss.o src/chunk.o \ + src/cfgparse-tcp.o src/lb_ss.o src/chunk.o src/counters.o \ src/cfgparse-unix.o src/regex.o src/fcgi.o src/uri_auth.o \ src/eb64tree.o src/eb32tree.o src/eb32sctree.o src/lru.o \ src/limits.o src/ebimtree.o src/wdt.o src/hpack-tbl.o \ diff --git a/include/haproxy/counters.h b/include/haproxy/counters.h new file mode 100644 index 000000000..526042743 --- /dev/null +++ b/include/haproxy/counters.h @@ -0,0 +1,34 @@ +/* + * include/haproxy/counters.h + * objects counters management + * + * Copyright 2025 HAProxy Technologies + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, version 2.1 + * exclusively. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _HAPROXY_COUNTERS_H +# define _HAPROXY_COUNTERS_H + +#include +#include + +struct fe_counters_shared *counters_fe_shared_get(const struct guid_node *guid); +struct be_counters_shared *counters_be_shared_get(const struct guid_node *guid); + +void counters_fe_shared_drop(struct fe_counters_shared *counters); +void counters_be_shared_drop(struct be_counters_shared *counters); + +#endif /* _HAPROXY_COUNTERS_H */ diff --git a/src/counters.c b/src/counters.c new file mode 100644 index 000000000..41d029350 --- /dev/null +++ b/src/counters.c @@ -0,0 +1,64 @@ +/* + * objects counters management + * + * Copyright 2025 HAProxy Technologies + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include + +/* retrieved shared counters pointer for a given object + * hint is expected to reflect the actual type size (fe/be) + * Returns the pointer on success or NULL on failure + */ +static void *_counters_shared_get(const struct guid_node *guid, size_t size) +{ + /* no shared memory for now, simply allocate a memory block + * for the counters (zero-initialized), ignore guid + */ + return calloc(1, size); +} + +/* retrieve shared fe counters pointer for a given object */ +struct fe_counters_shared *counters_fe_shared_get(const struct guid_node *guid) +{ + return _counters_shared_get(guid, sizeof(struct fe_counters_shared)); +} + +/* retrieve shared be counters pointer for a given object */ +struct be_counters_shared *counters_be_shared_get(const struct guid_node *guid) +{ + return _counters_shared_get(guid, sizeof(struct be_counters_shared)); +} + +static void _counters_shared_drop(void *counters) +{ + /* memory was allocated using calloc(), simply free it */ + free(counters); +} + +/* release a shared fe counters struct */ +void counters_fe_shared_drop(struct fe_counters_shared *counters) +{ + _counters_shared_drop(counters); +} + +/* release a shared be counters struct */ +void counters_be_shared_drop(struct be_counters_shared *counters) +{ + _counters_shared_drop(counters); +}