From e59304164a184b321de3e06be328d06c2443edbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Chlup?= Date: Fri, 16 Aug 2024 11:58:58 +0200 Subject: [PATCH] Remove offset from node structure, use macro instead --- native/include/node.h | 2 +- native/mod_manager/mod_manager.c | 6 +----- native/mod_manager/node.c | 13 ------------- native/mod_proxy_cluster/mod_proxy_cluster.c | 16 ++++++++-------- 4 files changed, 10 insertions(+), 27 deletions(-) diff --git a/native/include/node.h b/native/include/node.h index 968cfe84d..442be26ff 100644 --- a/native/include/node.h +++ b/native/include/node.h @@ -68,6 +68,7 @@ struct nodemess typedef struct nodemess nodemess_t; #define SIZEOFSCORE 1700 /* at least size of the proxy_worker_stat structure */ +#define NODEOFFSET (APR_ALIGN_DEFAULT(sizeof(nodemess_t) + sizeof(apr_time_t))) /** * Status of the node as read/store in httpd @@ -78,7 +79,6 @@ struct nodeinfo nodemess_t mess; /* filled by httpd */ apr_time_t updatetime; /* time of last received message */ - unsigned long offset; /* offset to the proxy_worker_stat structure */ char stat[SIZEOFSCORE]; /* to store the status */ }; typedef struct nodeinfo nodeinfo_t; diff --git a/native/mod_manager/mod_manager.c b/native/mod_manager/mod_manager.c index 87ec62522..76abafab9 100644 --- a/native/mod_manager/mod_manager.c +++ b/native/mod_manager/mod_manager.c @@ -1437,7 +1437,6 @@ static char *process_config(request_rec *r, char **ptr, int *errtype) } else { /* Here that is the tricky part, we will insert_update the whole node including proxy_worker_shared */ char *pptr; - unsigned long offset; ap_log_error(APLOG_MARK, APLOG_WARNING, 0, r->server, "process_config: worker %d (%s) exists and IS NOT OK!!!", id, nodeinfo.mess.JVMRoute); @@ -1466,10 +1465,7 @@ static char *process_config(request_rec *r, char **ptr, int *errtype) ap_assert(worker->s->port != 0); /* XXX: really needed? offset logic OK here, we save the worker information (see mod_proxy_cluster) */ pptr = (char *)&nodeinfo; - offset = sizeof(nodemess_t) + sizeof(apr_time_t) + - sizeof(unsigned long); /* nodeinfo.offset doesn't contain the information */ - offset = APR_ALIGN_DEFAULT(offset); - pptr = pptr + offset; + pptr = pptr + NODEOFFSET; memcpy(pptr, worker->s, sizeof(proxy_worker_shared)); /* restore the information we are going to reuse */ ap_assert(the_conf); } diff --git a/native/mod_manager/node.c b/native/mod_manager/node.c index d522fce04..c6586eedd 100644 --- a/native/mod_manager/node.c +++ b/native/mod_manager/node.c @@ -78,18 +78,9 @@ static apr_status_t update(void *mem, void *data, apr_pool_t *pool) (void)pool; if (strcmp(in->mess.JVMRoute, ou->mess.JVMRoute) == 0) { - /* - * The node information is made of several pieces: - * Information from the cluster (nodemess_t). - * updatetime (time of last received message). - * offset (of the area shared with the proxy logic). - * stat (shared area with the proxy logic we shouldn't modify it here). - */ in->mess.id = ou->mess.id; memcpy(ou, in, sizeof(nodemess_t)); ou->updatetime = apr_time_now(); - ou->offset = sizeof(nodemess_t) + sizeof(apr_time_t) + sizeof(unsigned long); - ou->offset = APR_ALIGN_DEFAULT(ou->offset); return APR_EEXIST; /* it exists so we are done */ } return APR_SUCCESS; @@ -135,10 +126,6 @@ apr_status_t insert_update_node(mem_t *s, nodeinfo_t *node, int *id, int clean) ou->mess.id = *id; ou->updatetime = now; - /* set of offset to the proxy_worker_stat */ - ou->offset = sizeof(nodemess_t) + sizeof(apr_time_t) + sizeof(unsigned long); - ou->offset = APR_ALIGN_DEFAULT(ou->offset); - /* blank the proxy status information */ if (clean) { memset(&(ou->stat), '\0', SIZEOFSCORE); diff --git a/native/mod_proxy_cluster/mod_proxy_cluster.c b/native/mod_proxy_cluster/mod_proxy_cluster.c index 37e5c039c..9f16b7e82 100644 --- a/native/mod_proxy_cluster/mod_proxy_cluster.c +++ b/native/mod_proxy_cluster/mod_proxy_cluster.c @@ -315,7 +315,7 @@ static apr_status_t create_worker_reuse(proxy_server_conf *conf, const char *ptr } /* Check if the shared memory goes to the right place */ - ptr = ptr_node + node->offset; + ptr = ptr_node + NODEOFFSET; ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, server, "create_worker: reusing worker (id %d) for %s", node->mess.id, url); if (helper->index == node->mess.id && worker->s == (proxy_worker_shared *)ptr) { @@ -363,7 +363,7 @@ static apr_status_t create_worker_reuse(proxy_server_conf *conf, const char *ptr #else worker->s->name); #endif - ptr = ptr_node + node->offset; + ptr = ptr_node + NODEOFFSET; *shared = worker->s; worker->s = (proxy_worker_shared *)ptr; worker->s->was_malloced = 0; /* Prevent mod_proxy to free it */ @@ -542,7 +542,7 @@ static apr_status_t create_worker(proxy_server_conf *conf, proxy_balancer *balan * 1 - the worker was created. * 2 - we are reusing a removed worker. */ - ptr = ptr_node + node->offset; + ptr = ptr_node + NODEOFFSET; shared = worker->s; worker->s = (proxy_worker_shared *)ptr; helper->isinnodes = 1; @@ -836,7 +836,7 @@ static void remove_workers_node(nodeinfo_t *node, proxy_server_conf *conf, apr_p int i; proxy_cluster_helper *helper; proxy_worker_shared *stat; - char *pptr = (char *)node + node->offset; + char *pptr = (char *)node + NODEOFFSET; proxy_worker *worker = get_worker_from_id_stat(conf, node->mess.id, (proxy_worker_shared *)pptr, node); (void)pool; @@ -1481,7 +1481,7 @@ static void update_workers_lbstatus(proxy_server_conf *conf, apr_pool_t *pool, s proxy_worker_shared *stat; char *ptr = (char *)ou; - ptr = ptr + ou->offset; + ptr = ptr + NODEOFFSET; stat = (proxy_worker_shared *)ptr; elected = stat->elected; read = stat->read; @@ -1664,7 +1664,7 @@ static proxy_worker *internal_process_worker(proxy_worker *worker, int checking_ if (read_node_worker(worker->s->index, &node, worker) != APR_SUCCESS) { return NULL; /* Can't read node */ } - if (worker->s != (proxy_worker_shared *)((char *)node + node->offset)) { + if (worker->s != (proxy_worker_shared *)((char *)node + NODEOFFSET)) { return NULL; /* wrong shared memory address */ } @@ -1852,7 +1852,7 @@ static int proxy_node_isup(request_rec *r, int id, int load) /* Calculate the address of our shared memory that corresponds to the stat info of the worker */ ptr = (char *)node; - stat = (proxy_worker_shared *)(ptr + node->offset); + stat = (proxy_worker_shared *)(ptr + NODEOFFSET); /* create the balancers and workers (that could be the first time) */ ap_assert(node_storage->lock_nodes() == APR_SUCCESS); @@ -2131,7 +2131,7 @@ static void reenable_proxy_worker(server_rec *server, nodeinfo_t *node, proxy_wo helper->isinnodes = 1; /* XXX: BAD IDEA!! helper->index = node->mess.id; */ ptr = (char *)node; - worker->s = (proxy_worker_shared *)(ptr + node->offset); + worker->s = (proxy_worker_shared *)(ptr + NODEOFFSET); /* merge the "new" node information */ init_proxy_worker(server, nodeinfo, worker, the_conf); }