};
struct extra_counters {
- char *data; /* heap containing counters allocated in a linear fashion */
+ char **datap; /* points to pointer to heap containing counters allocated in a linear fashion */
size_t size; /* size of allocated data */
enum counters_type type; /* type of object containing the counters */
};
/* Manipulation of extra_counters, for boot-time registrable modules */
#define EXTRA_COUNTERS_GET(counters, mod) \
(likely(counters) ? \
- ((void *)((counters)->data + (mod)->counters_off[(counters)->type])) : \
+ ((void *)(*(counters)->datap + (mod)->counters_off[(counters)->type])) : \
(trash_counters))
-#define EXTRA_COUNTERS_REGISTER(counters, ctype, alloc_failed_label) \
+#define EXTRA_COUNTERS_REGISTER(counters, ctype, alloc_failed_label, storage) \
do { \
typeof(*counters) _ctr; \
_ctr = calloc(1, sizeof(*_ctr)); \
if (!_ctr) \
goto alloc_failed_label; \
_ctr->type = (ctype); \
+ _ctr->datap = (storage); \
*(counters) = _ctr; \
} while (0)
#define EXTRA_COUNTERS_ALLOC(counters, alloc_failed_label) \
do { \
typeof(counters) _ctr = (counters); \
- _ctr->data = malloc((_ctr)->size); \
- if (!_ctr->data) \
+ *_ctr->datap = malloc((_ctr)->size); \
+ if (!*_ctr->datap) \
goto alloc_failed_label; \
} while (0)
#define EXTRA_COUNTERS_INIT(counters, mod, init_counters, init_counters_size) \
do { \
typeof(counters) _ctr = (counters); \
- memcpy(_ctr->data + mod->counters_off[_ctr->type], \
+ memcpy(*_ctr->datap + mod->counters_off[_ctr->type], \
(init_counters), (init_counters_size)); \
} while (0)
#define EXTRA_COUNTERS_FREE(counters) \
do { \
if (counters) { \
- free((counters)->data); \
+ ha_free((counters)->datap);\
free(counters); \
} \
} while (0)
struct dns_stream_server *stream; /* used for tcp dns */
EXTRA_COUNTERS(extra_counters);
+ char *extra_counters_storage; /* storage used for extra_counters above */
struct dns_counters *counters;
struct list list; /* nameserver chained list */
struct li_per_thread *per_thr; /* per-thread fields (one per thread in the group) */
+ char *extra_counters_storage; /* storage for extra_counters */
EXTRA_COUNTERS(extra_counters);
};
struct proxy_per_tgroup {
struct queue queue;
struct lbprm_per_tgrp lbprm;
+ char *extra_counters_fe_storage; /* storage for extra_counters_fe */
+ char *extra_counters_be_storage; /* storage for extra_counters_be */
} THREAD_ALIGNED();
struct proxy {
struct queue queue; /* pending connections */
struct server *server; /* pointer to the corresponding server */
struct eb32_node lb_node; /* node used for tree-based load balancing */
+ char *extra_counters_storage; /* storage for extra_counters */
struct server *next_full; /* next server in the temporary full list */
unsigned int last_other_tgrp_served; /* Last other tgrp we dequeued from */
unsigned int self_served; /* Number of connection we dequeued from our own queue */
}
int stats_allocate_proxy_counters_internal(struct extra_counters **counters,
- int type, int px_cap);
+ int type, int px_cap, char **storage);
int stats_allocate_proxy_counters(struct proxy *px);
void stats_register_module(struct stats_module *m);
if (!stats_allocate_proxy_counters_internal(&px->extra_counters_be,
COUNTERS_BE,
- STATS_PX_CAP_BE)) {
+ STATS_PX_CAP_BE,
+ &px->per_tgrp->extra_counters_be_storage)) {
memprintf(&msg, "failed to allocate extra counters");
goto err;
}
list_for_each_entry(resolvers, &sec_resolvers, list) {
list_for_each_entry(ns, &resolvers->nameservers, list) {
EXTRA_COUNTERS_REGISTER(&ns->extra_counters, COUNTERS_RSLV,
- alloc_failed);
+ alloc_failed, &ns->extra_counters_storage);
list_for_each_entry(mod, stat_modules, list) {
EXTRA_COUNTERS_ADD(mod,
EXTRA_COUNTERS_ALLOC(ns->extra_counters, alloc_failed);
list_for_each_entry(mod, stat_modules, list) {
- memcpy(ns->extra_counters->data + mod->counters_off[ns->extra_counters->type],
+ memcpy(*ns->extra_counters->datap + mod->counters_off[ns->extra_counters->type],
mod->counters, mod->counters_size);
/* Store the ns counters pointer */
if (strcmp(mod->name, "resolvers") == 0) {
- ns->counters = (struct dns_counters *)ns->extra_counters->data + mod->counters_off[COUNTERS_RSLV];
+ ns->counters = (struct dns_counters *)(*ns->extra_counters->datap) + mod->counters_off[COUNTERS_RSLV];
ns->counters->id = ns->id;
ns->counters->ns_puid = ns->puid;
ns->counters->pid = resolvers->id;
if (!stats_allocate_proxy_counters_internal(&srv->extra_counters,
COUNTERS_SV,
- STATS_PX_CAP_SRV)) {
+ STATS_PX_CAP_SRV,
+ &srv->per_tgrp->extra_counters_storage)) {
ha_alert("failed to allocate extra counters for server.\n");
goto out;
}
}
int stats_allocate_proxy_counters_internal(struct extra_counters **counters,
- int type, int px_cap)
+ int type, int px_cap, char **storage)
{
struct stats_module *mod;
- EXTRA_COUNTERS_REGISTER(counters, type, alloc_failed);
+ EXTRA_COUNTERS_REGISTER(counters, type, alloc_failed, storage);
list_for_each_entry(mod, &stats_module_list[STATS_DOMAIN_PROXY], list) {
if (!(stats_px_get_cap(mod->domain_flags) & px_cap))
if (px->cap & PR_CAP_FE) {
if (!stats_allocate_proxy_counters_internal(&px->extra_counters_fe,
COUNTERS_FE,
- STATS_PX_CAP_FE)) {
+ STATS_PX_CAP_FE,
+ &px->per_tgrp->extra_counters_fe_storage)) {
return 0;
}
}
if (px->cap & PR_CAP_BE) {
if (!stats_allocate_proxy_counters_internal(&px->extra_counters_be,
COUNTERS_BE,
- STATS_PX_CAP_BE)) {
+ STATS_PX_CAP_BE,
+ &px->per_tgrp->extra_counters_be_storage)) {
return 0;
}
}
for (sv = px->srv; sv; sv = sv->next) {
if (!stats_allocate_proxy_counters_internal(&sv->extra_counters,
COUNTERS_SV,
- STATS_PX_CAP_SRV)) {
+ STATS_PX_CAP_SRV,
+ &sv->per_tgrp->extra_counters_storage)) {
return 0;
}
}
list_for_each_entry(li, &px->conf.listeners, by_fe) {
if (!stats_allocate_proxy_counters_internal(&li->extra_counters,
COUNTERS_LI,
- STATS_PX_CAP_LI)) {
+ STATS_PX_CAP_LI,
+ &li->extra_counters_storage)) {
return 0;
}
}