From: Jean-Frederic Clere Date: Sun, 30 Jul 2006 17:15:34 +0000 (+0000) Subject: Allow anonymous shared memory. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39f9634921daa49109f6c0cf3b1f3950baba5fbb;p=thirdparty%2Fapache%2Fhttpd.git Allow anonymous shared memory. Arrange the mixing of checker size and proper httpd workers status in proxy_util. Make slotmem.h multi times includable. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/httpd-proxy-scoreboard@426900 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/mem/mod_plainmem.c b/modules/mem/mod_plainmem.c index da1b93cb533..d3a814d9e43 100644 --- a/modules/mem/mod_plainmem.c +++ b/modules/mem/mod_plainmem.c @@ -60,24 +60,30 @@ static apr_status_t ap_slotmem_create(ap_slotmem_t **new, const char *name, apr_ void *slotmem = NULL; ap_slotmem_t *res; ap_slotmem_t *next = globallistmem; - char *fname; + const char *fname; apr_status_t rv; - fname = ap_server_root_relative(pool, name); - - /* first try to attach to existing slotmem */ - if (next) { - for (;;) { - if (strcmp(next->name, fname) == 0) { - /* we already have it */ - *new = next; - return APR_SUCCESS; + if (name) { + if (name[0] == ':') + fname = name; + else + fname = ap_server_root_relative(pool, name); + + /* first try to attach to existing slotmem */ + if (next) { + for (;;) { + if (strcmp(next->name, fname) == 0) { + /* we already have it */ + *new = next; + return APR_SUCCESS; + } + if (!next->next) + break; + next = next->next; } - if (!next->next) - break; - next = next->next; } - } + } else + fname = "anonymous"; /* create the memory using the globalpool */ res = (ap_slotmem_t *) apr_pcalloc(globalpool, sizeof(ap_slotmem_t)); @@ -104,10 +110,16 @@ static apr_status_t ap_slotmem_attach(ap_slotmem_t **new, const char *name, apr_ void *slotmem = NULL; ap_slotmem_t *res; ap_slotmem_t *next = globallistmem; - char *fname; + const char *fname; apr_status_t rv; - fname = ap_server_root_relative(pool, name); + if (name) { + if (name[0] == ':') + fname = name; + else + fname = ap_server_root_relative(pool, name); + } else + return APR_ENOSHMAVAIL; /* first try to attach to existing slotmem */ if (next) { diff --git a/modules/mem/sharedmem_util.c b/modules/mem/sharedmem_util.c index 2cf12817c8b..677f0444888 100644 --- a/modules/mem/sharedmem_util.c +++ b/modules/mem/sharedmem_util.c @@ -87,28 +87,37 @@ static apr_status_t ap_slotmem_create(ap_slotmem_t **new, const char *name, apr_ struct sharedslotdesc desc; ap_slotmem_t *res; ap_slotmem_t *next = globallistmem; - char *fname; + const char *fname; apr_status_t rv; - fname = ap_server_root_relative(pool, name); + if (name) { + if (name[0] == ':') + fname = name; + else + fname = ap_server_root_relative(pool, name); - /* first try to attach to existing slotmem */ - if (next) { - for (;;) { - if (strcmp(next->name, fname) == 0) { - /* we already have it */ - *new = next; - return APR_SUCCESS; + /* first try to attach to existing slotmem */ + if (next) { + for (;;) { + if (strcmp(next->name, fname) == 0) { + /* we already have it */ + *new = next; + return APR_SUCCESS; + } + if (!next->next) + break; + next = next->next; } - if (!next->next) - break; - next = next->next; } - } + } else + fname = "anonymous"; /* first try to attach to existing shared memory */ res = (ap_slotmem_t *) apr_pcalloc(globalpool, sizeof(ap_slotmem_t)); - rv = apr_shm_attach(&res->shm, fname, globalpool); + if (name && name[0] != ':') + rv = apr_shm_attach(&res->shm, fname, globalpool); + else + rv = APR_EINVAL; if (rv == APR_SUCCESS) { /* check size */ if (apr_shm_size_get(res->shm) != item_size * item_num + sizeof(struct sharedslotdesc)) { @@ -125,7 +134,10 @@ static apr_status_t ap_slotmem_create(ap_slotmem_t **new, const char *name, apr_ } ptr = ptr + sizeof(desc); } else { - rv = apr_shm_create(&res->shm, item_size * item_num + sizeof(struct sharedslotdesc), fname, globalpool); + if (name && name[0] != ':') + rv = apr_shm_create(&res->shm, item_size * item_num + sizeof(struct sharedslotdesc), fname, globalpool); + else + rv = apr_shm_create(&res->shm, item_size * item_num + sizeof(struct sharedslotdesc), NULL, globalpool); if (rv != APR_SUCCESS) return rv; ptr = apr_shm_baseaddr_get(res->shm); @@ -158,10 +170,16 @@ static apr_status_t ap_slotmem_attach(ap_slotmem_t **new, const char *name, apr_ ap_slotmem_t *res; ap_slotmem_t *next = globallistmem; struct sharedslotdesc desc; - char *fname; + const char *fname; apr_status_t rv; - fname = ap_server_root_relative(pool, name); + if (name) { + if (name[0] == ':') + fname = name; + else + fname = ap_server_root_relative(pool, name); + } else + return APR_ENOSHMAVAIL; /* first try to attach to existing slotmem */ if (next) { diff --git a/modules/mem/slotmem.h b/modules/mem/slotmem.h index 30c85af728e..e5d1f046d4b 100644 --- a/modules/mem/slotmem.h +++ b/modules/mem/slotmem.h @@ -14,6 +14,7 @@ * limitations under the License. */ +#ifndef SLOTMEM_H #define SLOTMEM_H /* Memory handler for a shared memory divided in slot. @@ -27,6 +28,14 @@ * @{ */ +#include "apr.h" +#include "apr_strings.h" +#include "apr_pools.h" +#include "apr_shm.h" + +#include "httpd.h" +#include "http_config.h" +#include "http_log.h" #define SLOTMEM_STORAGE "slotmem" @@ -86,3 +95,5 @@ AP_DECLARE(apr_status_t) (* ap_slotmem_mem)(ap_slotmem_t *s, int item_id, void** }; typedef struct slotmem_storage_method slotmem_storage_method; + +#endif /*SLOTMEM_H*/ diff --git a/modules/proxy/mod_proxy.c b/modules/proxy/mod_proxy.c index 38a60707bcc..c4ceca37347 100644 --- a/modules/proxy/mod_proxy.c +++ b/modules/proxy/mod_proxy.c @@ -17,7 +17,6 @@ #define CORE_PRIVATE #include "mod_proxy.h" -#include "slotmem.h" #include "mod_core.h" #include "apr_optional.h" #include "scoreboard.h" @@ -1863,8 +1862,6 @@ PROXY_DECLARE(const char *) ap_proxy_ssl_val(apr_pool_t *p, server_rec *s, static int proxy_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { - proxy_server_conf *sconf = ap_get_module_config(s->module_config, - &proxy_module); proxy_ssl_enable = APR_RETRIEVE_OPTIONAL_FN(ssl_proxy_enable); proxy_ssl_disable = APR_RETRIEVE_OPTIONAL_FN(ssl_engine_disable); @@ -1872,7 +1869,7 @@ static int proxy_post_config(apr_pool_t *pconf, apr_pool_t *plog, proxy_ssl_val = APR_RETRIEVE_OPTIONAL_FN(ssl_var_lookup); /* if we have a memory provider create the comarea here */ - proxy_create_comarea(pconf, sconf->slotmem_loc); + proxy_create_comarea(pconf, s); /* Also fill the comarea of the health-checker */ proxy_checkstorage_add_workers(pconf, s); diff --git a/modules/proxy/mod_proxy.h b/modules/proxy/mod_proxy.h index cd0860057e6..961f263386b 100644 --- a/modules/proxy/mod_proxy.h +++ b/modules/proxy/mod_proxy.h @@ -74,6 +74,7 @@ #include "util_filter.h" #include "util_ebcdic.h" #include "ap_provider.h" +#include "slotmem.h" #if APR_HAVE_NETINET_IN_H #include @@ -447,7 +448,7 @@ APR_DECLARE_EXTERNAL_HOOK(proxy, PROXY, int, request_status, /* proxy_util.c */ -PROXY_DECLARE(void) proxy_create_comarea(apr_pool_t *pconf, char *name); +PROXY_DECLARE(ap_slotmem_t *) proxy_create_comarea(apr_pool_t *pconf, server_rec *s); PROXY_DECLARE(void) proxy_checkstorage_add_workers(apr_pool_t *pconf, server_rec *s); PROXY_DECLARE(void) proxy_lookup_storage_provider(); diff --git a/modules/proxy/proxy_util.c b/modules/proxy/proxy_util.c index 16087b99f67..e7bec294384 100644 --- a/modules/proxy/proxy_util.c +++ b/modules/proxy/proxy_util.c @@ -16,7 +16,6 @@ /* Utility routines for Apache proxy */ #include "mod_proxy.h" -#include "slotmem.h" #include "mod_proxy_health_checker.h" #include "ap_mpm.h" #include "apr_version.h" @@ -1633,7 +1632,6 @@ PROXY_DECLARE(void) ap_proxy_initialize_worker_share(proxy_server_conf *conf, void *score = NULL; ap_slotmem_t *myscore; apr_status_t rv; - apr_size_t item_size = sizeof(proxy_worker_stat); proxy_server_conf *sconf = ap_get_module_config(s->module_config, &proxy_module); @@ -1645,16 +1643,11 @@ PROXY_DECLARE(void) ap_proxy_initialize_worker_share(proxy_server_conf *conf, return; } - /* Health checker handler: to create the correct size. */ - if (checkstorage) { - item_size = checkstorage->getentrysize(); - } - /* Use storage provider when a storage is existing */ if (storage) { + myscore = proxy_create_comarea(conf->pool, s); - rv = storage->ap_slotmem_create(&myscore, sconf->slotmem_loc, item_size, ap_proxy_lb_workers(), conf->pool); - if (rv == APR_SUCCESS) + if (myscore) rv = storage->ap_slotmem_mem(myscore, worker->id, &score); if (rv != APR_SUCCESS) score = NULL; @@ -2232,14 +2225,19 @@ PROXY_DECLARE(void) ap_proxy_backend_broke(request_rec *r, } /* Create shared area (comarea) called from mod_proxy post_config */ -PROXY_DECLARE(void) proxy_create_comarea(apr_pool_t *pconf, char *name) +PROXY_DECLARE(ap_slotmem_t *) proxy_create_comarea(apr_pool_t *pconf, server_rec *s) { - ap_slotmem_t *myscore; - apr_size_t item_size = sizeof(proxy_worker_stat); - if (checkstorage) - item_size = checkstorage->getentrysize(); - if (storage) - storage->ap_slotmem_create(&myscore, name, item_size, ap_proxy_lb_workers(), pconf); + ap_slotmem_t *myscore = NULL; + proxy_server_conf *sconf = ap_get_module_config(s->module_config, + &proxy_module); + char *slotmem_loc = sconf->slotmem_loc; + + if (storage) { + if (!slotmem_loc) + slotmem_loc = apr_pstrcat(pconf, ":", proxy_module.name, NULL); + storage->ap_slotmem_create(&myscore, slotmem_loc, sizeof(proxy_worker_stat), ap_proxy_lb_workers(), pconf); + } + return(myscore); } /* get the storage provider for the shared area called from mod_proxy pre_config */ PROXY_DECLARE(void) proxy_lookup_storage_provider()