Author: mladen.turk(a)jboss.com
Date: 2008-05-30 03:23:54 -0400 (Fri, 30 May 2008)
New Revision: 1642
Removed:
sandbox/aloha/httpd/modules/manager/mm_node.c
Modified:
sandbox/aloha/httpd/modules/manager/mm_app.c
sandbox/aloha/httpd/modules/manager/mm_asmm.c
sandbox/aloha/httpd/modules/manager/mm_asmm.h
sandbox/aloha/httpd/modules/manager/mm_util.c
Log:
Some code cleanup
Modified: sandbox/aloha/httpd/modules/manager/mm_app.c
===================================================================
--- sandbox/aloha/httpd/modules/manager/mm_app.c 2008-05-29 14:34:51 UTC (rev 1641)
+++ sandbox/aloha/httpd/modules/manager/mm_app.c 2008-05-30 07:23:54 UTC (rev 1642)
@@ -41,6 +41,8 @@
static const char *memberapp_params[] = {
"",
+ "Member",
+ "Host",
"State",
/* Statistical data */
"Busy",
@@ -77,21 +79,30 @@
return NULL;
}
-static mmdb_app_pool_t *get_app_pool(const char *value, apr_uint32_t *id)
+static const char *get_member_name(apr_uint32_t id)
{
- apr_uint32_t next = 0;
- mmdb_app_pool_t *app_pool;
- asmm_slotmem_t *app_pool_db = mmdb_table_getn(MMDB_APP_POOL);
+ mmdb_member_t *member;
+ asmm_slotmem_t *member_db = mmdb_table_getn(MMDB_MEMBER);
- while ((app_pool = asmm_slot_next(app_pool_db, &next))) {
- if (strcasecmp(value, app_pool->name))
- continue;
- *id = next - 1;
- return app_pool;
+ if ((member = asmm_slot(member_db, id))) {
+ return member->name;
}
return NULL;
}
+static void del_app_members(apr_uint32_t app_id)
+{
+ apr_uint32_t next = 0;
+ mmdb_memberapp_t *memberapp;
+ asmm_slotmem_t *memberapp_db = mmdb_table_getn(MMDB_MEMBERAPP);
+
+ while ((memberapp = asmm_slot_next(memberapp_db, &next))) {
+ if (memberapp->app_id != app_id)
+ continue;
+ asmm_free(memberapp_db, memberapp);
+ }
+}
+
static void rdo_app_info_print(int pi, int pp,
mmdb_app_t *app,
request_rec *r)
@@ -117,31 +128,38 @@
static void rdo_memberapp_info_print(int pi, int pp,
mmdb_memberapp_t *mem,
+ mmdb_app_t *app,
request_rec *r)
{
if (pp) {
ap_rvputs(r, memberapp_params[pi], "=", NULL);
}
switch (pi) {
- case 1: /* State */
+ case 1: /* Member */
+ ap_rvputs(r, get_member_name(mem->member_id), NULL);
+ break;
+ case 2: /* Host */
+ ap_rvputs(r, get_host_name(app->host_id), NULL);
+ break;
+ case 3: /* State */
ap_rputs(mm_state_name_get(mem->state), r);
break;
- case 2: /* Busy */
+ case 4: /* Busy */
ap_rprintf(r, "%u", mem->busy);
break;
- case 3: /* Transactions */
+ case 5: /* Transactions */
ap_rprintf(r, "%u", mem->transactions);
break;
- case 4: /* ClientErrors */
+ case 6: /* ClientErrors */
ap_rprintf(r, "%u", mem->err_client);
break;
- case 5: /* NodeErrors */
+ case 7: /* NodeErrors */
ap_rprintf(r, "%u", mem->err_node);
break;
- case 6: /* Readed */
+ case 8: /* Readed */
ap_rprintf(r, "%" APR_UINT64_T_FMT, mem->readed);
break;
- case 7: /* Transferred */
+ case 9: /* Transferred */
ap_rprintf(r, "%" APR_UINT64_T_FMT, mem->transferred);
break;
}
@@ -230,6 +248,7 @@
int cmd_offset,
int wcm,
mmdb_memberapp_t *mem,
+ mmdb_app_t *app,
request_rec *r)
{
int cnt = 0;
@@ -267,7 +286,7 @@
}
else if (cnt == 1 && m) {
/* Single param */
- rdo_memberapp_info_print(m, wcm, mem, r);
+ rdo_memberapp_info_print(m, wcm, mem, app, r);
ap_rputs(CRLF, r);
}
else {
@@ -281,7 +300,7 @@
MM_FFNMATCH) == APR_SUCCESS) {
if (sep++)
ap_rputs("; ", r);
- rdo_memberapp_info_print(j, 1, mem, r);
+ rdo_memberapp_info_print(j, 1, mem, app, r);
}
j++;
}
@@ -291,7 +310,7 @@
if (!strcasecmp(ce[i].key, memberapp_params[j])) {
if (sep++)
ap_rputs("; ", r);
- rdo_memberapp_info_print(j, 1, mem, r);
+ rdo_memberapp_info_print(j, 1, mem, app, r);
break;
}
j++;
@@ -321,11 +340,16 @@
if (app_pool->applications)
app_pool->applications--;
}
- if ((app_pool = get_app_pool(value, &app_pool_id))) {
- app->state = mm_state_get(value);
+ if ((app_pool = asmm_slot_search(mmdb_table_getn(MMDB_APP_POOL),
+ value, 1,
+ offsetof(mmdb_app_pool_t, name),
+ &app_pool_id))) {
+ app->app_pool_id = app_pool_id;
if (app_pool_id)
app_pool->applications++;
}
+ else
+ return MME_ENODEV;
break;
case 3: /* State */
app->state = mm_state_get(value);
@@ -350,7 +374,7 @@
request_rec *r)
{
switch (pi) {
- case 1: /* State */
+ case 3: /* State */
mem->state = mm_state_get(value);
break;
default:
@@ -466,7 +490,10 @@
{
int wdone = 0;
int cblind = 0;
+ int cnt = 0;
int wcm;
+ const apr_array_header_t *ca = apr_table_elts(cmd_table);
+ apr_table_entry_t *ce = (apr_table_entry_t *)ca->elts;
apr_uint32_t next = 0;
apr_uint32_t mapp = 0;
@@ -524,6 +551,7 @@
if (*name != '~')
wcm = apr_fnmatch_test(name);
while ((app = asmm_slot_next(app_db, &next))) {
+ /* Count the number of matches */
if (wcm) {
if (apr_fnmatch(name, app->url,
cblind ? MM_FFNMATCH : 0) != APR_SUCCESS)
@@ -531,6 +559,17 @@
}
else if (cblind ? strcasecmp(name, app->url) : strcmp(name, app->url))
continue;
+ cnt++;
+ }
+ next = 0;
+ while ((app = asmm_slot_next(app_db, &next))) {
+ if (wcm) {
+ if (apr_fnmatch(name, app->url,
+ cblind ? MM_FFNMATCH : 0) != APR_SUCCESS)
+ continue;
+ }
+ else if (cblind ? strcasecmp(name, app->url) : strcmp(name, app->url))
+ continue;
if (host) {
if (prev_id != app->host_id)
continue;
@@ -538,10 +577,16 @@
*/
switch (cmd) {
case mm_mcmp_info:
- if (wcm)
+ if (cnt > 1) {
ap_rvputs(r, "@" MM_RES_APPLICATION "/",
- app->url, ": ", NULL);
- rdo_app_info(cmd_table, cmd_offset, wcm, app, r);
+ app->url, NULL);
+ if (cmd_offset < ca->nelts)
+ ap_rputs(": ", r);
+ else
+ ap_rputs(CRLF, r);
+ }
+ if (cmd_offset < ca->nelts)
+ rdo_app_info(cmd_table, cmd_offset, cnt - 1, app, r);
break;
case mm_mcmp_config:
if (rdo_app_config(cfg, cmd_table, cmd_offset,
@@ -558,6 +603,28 @@
app->state = mm_state_stopped;
break;
case mm_mcmp_delete:
+ if (app->state != mm_state_stopped) {
+ /* Application must be stopped before */
+ mm_send_response_ex(r, mm_response_error, MME_EBUSY, NULL);
+ ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
+ "mod_manager: Application not stopped:
%s",
+ app->url);
+ return APR_SUCCESS;
+ }
+ else {
+ /* Delete Application and MemberApplication entries */
+ if (app->app_pool_id > 0 ) {
+ /* Unreference from ApplicationPool */
+ if ((app_pool = asmm_slot(app_pool_db,
+ app->app_pool_id))) {
+ if (app_pool->applications)
+ app_pool->applications--;
+ }
+ }
+ del_app_members(next - 1);
+ asmm_free(app_db, app);
+ }
+ break;
default:
mm_send_response_ex(r, mm_response_error, MME_EPERM, NULL);
ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
@@ -585,11 +652,17 @@
}
switch (cmd) {
case mm_mcmp_info:
- if (wcm)
+ if (cnt > 1) {
ap_rvputs(r, "@" MM_RES_APPLICATION "/",
- app->url, ": ", NULL);
- rdo_memberapp_info(cmd_table, cmd_offset, wcm,
- memberapp, r);
+ app->url, NULL);
+ if (cmd_offset < ca->nelts)
+ ap_rputs(": ", r);
+ else
+ ap_rputs(CRLF, r);
+ }
+ if (cmd_offset < ca->nelts)
+ rdo_memberapp_info(cmd_table, cmd_offset, cnt - 1,
+ memberapp, app, r);
break;
case mm_mcmp_config:
if (rdo_memberapp_config(cfg, cmd_table, cmd_offset,
@@ -653,8 +726,12 @@
}
}
wdone++;
- if (!wcm)
- break;
+ /* Multiple Applications with the same name
+ * can exist in the database (belonging to different Hosts).
+ * Match them all instead breaking up on the first match.
+ * if (!wcm)
+ * break;
+ */
}
if (!wdone && host) {
if (cmd == mm_mcmp_config && !wcm) {
Modified: sandbox/aloha/httpd/modules/manager/mm_asmm.c
===================================================================
--- sandbox/aloha/httpd/modules/manager/mm_asmm.c 2008-05-29 14:34:51 UTC (rev 1641)
+++ sandbox/aloha/httpd/modules/manager/mm_asmm.c 2008-05-30 07:23:54 UTC (rev 1642)
@@ -1557,3 +1557,42 @@
apr_set_os_error(APR_EOF);
return NULL;
}
+
+void *asmm_slot_find(asmm_slotmem_t *mem,
+ const void *key,
+ int (*compare )(const void *, const void *),
+ apr_uint32_t *slot)
+{
+ apr_uint32_t i, section = 0;
+ apr_byte_t *data = NULL;
+ asmm_mem_node_t *node;
+ asmm_mem_data_t *bmp;
+
+ if (!mem) {
+ apr_set_os_error(APR_ENOMEM);
+ return NULL;
+ }
+ bmp = mem->sections;
+ if (bmp && bmp->hdr->flags & ASMM_DIRTY) {
+ apr_set_os_error(APR_EBADF);
+ return NULL;
+ }
+ while (bmp) {
+ for (i = 0; i < bmp->hdr->nblocks; i++) {
+ data = bmp->data + i * bmp->hdr->blksize;
+ node = (asmm_mem_node_t *)data;
+ if (node->size) {
+ void *sd = data + sizeof(asmm_mem_node_t);
+ if ((*compare)(key, sd) == 0) {
+ if (slot)
+ *slot = i + section * bmp->hdr->nblocks;
+ return sd;
+ }
+ }
+ }
+ bmp = bmp->next;
+ section++;
+ }
+ apr_set_os_error(APR_EOF);
+ return NULL;
+}
Modified: sandbox/aloha/httpd/modules/manager/mm_asmm.h
===================================================================
--- sandbox/aloha/httpd/modules/manager/mm_asmm.h 2008-05-29 14:34:51 UTC (rev 1641)
+++ sandbox/aloha/httpd/modules/manager/mm_asmm.h 2008-05-30 07:23:54 UTC (rev 1642)
@@ -275,6 +275,22 @@
apr_uint32_t *slot);
/**
+ * Search for memory slot
+ * @param mem The slotmem descriptor to use.
+ * @param key The memory key to find.
+ * @param compare Compare function used for search.
+ * The first parameter is a pointer to the key for the search
+ * and the second parameter is a pointer to the array element
+ * to be compared with the key. Compare function must return 0
+ * if there is a match.
+ * @param slot On success the slot number.
+ */
+void *asmm_slot_find(asmm_slotmem_t *mem,
+ const void *key,
+ int (*compare )(const void *, const void *),
+ apr_uint32_t *slot);
+
+/**
* Get memory address
* @param mem The slotmem descriptor to use.
* @param index Allocated memory index
Deleted: sandbox/aloha/httpd/modules/manager/mm_node.c
===================================================================
--- sandbox/aloha/httpd/modules/manager/mm_node.c 2008-05-29 14:34:51 UTC (rev 1641)
+++ sandbox/aloha/httpd/modules/manager/mm_node.c 2008-05-30 07:23:54 UTC (rev 1642)
@@ -1,766 +0,0 @@
-/*
- * ModManager - JBoss Aloha
- *
- * Copyright(c) 2008 Red Hat Middleware, LLC,
- * and individual contributors as indicated by the @authors tag.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * 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; either
- * version 2 of the License, or (at your option) any later version.
- *
- * 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 in the file COPYING.LIB;
- * if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *
- * @author Mladen Turk
- */
-
-/* Manager Node object resource routines */
-#include "mm_api.h"
-
-static mm_resource_provider_t *this_provider = NULL;
-static int server_limit = 0;
-static int thread_limit = 0;
-static int max_clients = 0;
-static int max_childs = 0;
-static int max_requests_per_child = 0;
-static int max_threads_per_child = 0;
-
-static const char *member_params[] = {
- "",
- "Balancer",
- "Type",
- "Address",
- "Port",
- "Route",
- "Domain",
- "Ping",
- "MaxConnections",
- "MinConnections",
- "MaxClients",
- "TTL",
- "LF",
- "Distance",
- "Activation",
- "FlushMode",
- "FlushTimeout",
- /* Statistical data */
- "State",
- "Error",
- "Busy",
- "Connected",
- "Elected",
- "StickySessions",
- "ClientErrors",
- "NodeErrors",
- "Trace",
- "TraceErrors",
- "Readed",
- "Transferred",
- NULL
-};
-
-static const char *get_balancer_name(apr_uint32_t id)
-{
- mmdb_balancer_t *balancer;
- asmm_slotmem_t *balancer_db = mmdb_table_getn(MMDB_BALANCER);
-
- if ((balancer = asmm_slot(balancer_db, id))) {
- return balancer->name;
- }
- return NULL;
-}
-
-static const char *get_flush_name(mm_flush_mode_e mode)
-{
- switch(mode) {
- case mm_flush_wait:
- return "T";
- break;
- case mm_flush_auto:
- return "A";
- break;
- }
- return "N";
-}
-
-static mm_flush_mode_e get_flush_mode(const char *mode)
-{
- switch(apr_toupper(*mode)) {
- case 'T':
- return mm_flush_wait;
- break;
- case 'A':
- return mm_flush_auto;
- break;
- }
- return mm_flush_none;
-}
-
-static apr_status_t add_app_members(apr_uint32_t member_id,
- apr_uint32_t balancer_id)
-{
- apr_uint32_t napp = 0;
- apr_uint32_t nhost = 0;
- mmdb_host_t *host;
- mmdb_app_t *app;
- mmdb_memberapp_t *memberapp;
- asmm_slotmem_t *host_db = mmdb_table_getn(MMDB_HOST);
- asmm_slotmem_t *app_db = mmdb_table_getn(MMDB_APPLICATION);
- asmm_slotmem_t *memberapp_db = mmdb_table_getn(MMDB_MEMBERAPP);
-
- while ((host = asmm_slot_next(host_db, &nhost))) {
- if (host->balancer_id != balancer_id)
- continue;
- napp = 0;
- while ((app = asmm_slot_next(app_db, &napp))) {
- if (app->host_id != (nhost - 1))
- continue;
- if (!(memberapp = asmm_salloc(memberapp_db)))
- return apr_get_os_error();
- memberapp->app_id = napp - 1;
- memberapp->member_id = member_id;
- memberapp->state = app->state;
- }
- }
- return APR_SUCCESS;
-}
-
-static void del_app_members(apr_uint32_t member_id)
-{
- apr_uint32_t next = 0;
- mmdb_memberapp_t *memberapp;
- asmm_slotmem_t *memberapp_db = mmdb_table_getn(MMDB_MEMBERAPP);
-
- while ((memberapp = asmm_slot_next(memberapp_db, &next))) {
- if (memberapp->member_id != member_id)
- continue;
- asmm_free(memberapp_db, memberapp);
- }
-}
-
-
-static void rdo_member_info_print(int pi, int pp,
- mmdb_member_t *mem,
- request_rec *r)
-{
- char buf[512];
- const char *p;
-
- if (pp) {
- ap_rvputs(r, member_params[pi], "=", NULL);
- }
- switch (pi) {
- case 1: /* Balancer */
- ap_rvputs(r, get_balancer_name(mem->balancer_id), NULL);
- break;
- case 2: /* Type */
- ap_rputs(mm_protocol_name_get(mem->type), r);
- break;
- case 3: /* Address */
- ap_rvputs(r, mem->address, NULL);
- break;
- case 4: /* Port */
- ap_rprintf(r, "%u", mem->port);
- break;
- case 5: /* Route */
- ap_rvputs(r, mem->route, NULL);
- break;
- case 6: /* Domain */
- ap_rvputs(r, mem->domain, NULL);
- break;
- case 7: /* Ping */
- ap_rprintf(r, "%u", mem->ping);
- break;
- case 8: /* MaxConnections */
- ap_rprintf(r, "%u", mem->max_conn);
- break;
- case 9: /* MinConnections */
- ap_rprintf(r, "%u", mem->min_conn);
- break;
- case 10: /* MaxClients */
- ap_rprintf(r, "%u", mem->max_clients);
- break;
- case 11: /* TTL */
- ap_rprintf(r, "%u", mem->ttl);
- break;
- case 12: /* LF */
- ap_rprintf(r, "%u", mem->lf);
- break;
- case 13: /* Distance */
- ap_rprintf(r, "%u", mem->distance);
- break;
- case 14: /* Activation */
- ap_rputs(mm_state_name_get(mem->activation), r);
- break;
- case 15: /* FlushMode */
- ap_rputs(get_flush_name(mem->flush), r);
- break;
- case 16: /* FlushTimeout */
- ap_rprintf(r, "%" APR_TIME_T_FMT,
apr_time_as_msec(mem->flush_wait));
- break;
- case 17: /* State */
- ap_rputs(mm_state_name_get(mem->state), r);
- break;
- case 18: /* Error */
- if (!(p = mm_strerror(mem->err))) {
- if (!(p = apr_strerror(mem->err, buf, sizeof(buf))))
- p = "Unknown Error";
- }
- if (pp)
- ap_rprintf(r, "\"%d: %s\"", mem->err, p);
- else
- ap_rprintf(r, "%d: %s", mem->err, p);
- break;
- case 19: /* Busy */
- ap_rprintf(r, "%u", mem->busy);
- break;
- case 20: /* Connected */
- ap_rprintf(r, "%u", mem->connected);
- break;
- case 21: /* Elected */
- ap_rprintf(r, "%u", mem->elected);
- break;
- case 22: /* StickySessions */
- ap_rprintf(r, "%u", mem->ssessions);
- break;
- case 23: /* ClientErrors */
- ap_rprintf(r, "%u", mem->err_client);
- break;
- case 24: /* NodeErrors */
- ap_rprintf(r, "%u", mem->err_node);
- break;
- case 25: /* Trace */
- ap_rprintf(r, "%u", mem->trace);
- break;
- case 26: /* TraceErrors */
- ap_rprintf(r, "%u", mem->err_trace);
- break;
- case 27: /* Readed */
- ap_rprintf(r, "%" APR_UINT64_T_FMT, mem->readed);
- break;
- case 28: /* Transferred */
- ap_rprintf(r, "%" APR_UINT64_T_FMT, mem->transferred);
- break;
- }
-}
-
-/* Dump Member info */
-static void rdo_member_info(apr_table_t *cmd_table,
- int cmd_offset,
- int wcm,
- mmdb_member_t *mem,
- request_rec *r)
-{
- int cnt = 0;
- int i, j, m = 0;
-
- const apr_array_header_t *ca = apr_table_elts(cmd_table);
- apr_table_entry_t *ce = (apr_table_entry_t *)ca->elts;
-
- /* Step 1: Figure out the number of requested params */
- for (i = cmd_offset; i < ca->nelts; i++) {
- j = 1;
- if (apr_fnmatch_test(ce[i].key)) {
- while (member_params[j]) {
- if (apr_fnmatch(ce[i].key, member_params[j],
- MM_FFNMATCH) == APR_SUCCESS) {
- cnt++;
- }
- j++;
- }
- }
- else {
- while (member_params[j]) {
- if (!strcasecmp(ce[i].key, member_params[j])) {
- m = j;
- cnt++;
- break;
- }
- j++;
- }
- }
- }
- if (!cnt) {
- /* No params. Just print OK */
- mm_send_response_ex(r, mm_response_ok, 0, NULL);
- }
- else if (cnt == 1 && m) {
- /* Single param */
- rdo_member_info_print(m, wcm, mem, r);
- ap_rputs(CRLF, r);
- }
- else {
- int sep = 0;
- /* Multiple params */
- for (i = cmd_offset; i < ca->nelts; i++) {
- j = 1;
- if (apr_fnmatch_test(ce[i].key)) {
- while (member_params[j]) {
- if (apr_fnmatch(ce[i].key, member_params[j],
- MM_FFNMATCH) == APR_SUCCESS) {
- if (sep++)
- ap_rputs("; ", r);
- rdo_member_info_print(j, 1, mem, r);
- }
- j++;
- }
- }
- else {
- while (member_params[j]) {
- if (!strcasecmp(ce[i].key, member_params[j])) {
- if (sep++)
- ap_rputs("; ", r);
- rdo_member_info_print(j, 1, mem, r);
- break;
- }
- j++;
- }
- }
- }
- if (sep)
- ap_rputs(CRLF, r);
- }
-}
-
-static apr_status_t rdo_member_config_do(int pi,
- const char *value,
- mmdb_member_t *mem,
- request_rec *r)
-{
- int i;
-
- switch (pi) {
- case 2: /* Type */
- if (mem->state == mm_state_stopped)
- mem->type = mm_protocol_get(value);
- else
- return MME_EPERM;
- break;
- case 3: /* Address */
- if (mem->state == mm_state_stopped)
- MM_SSAFE_COPY(mem->address, value);
- else
- return MME_EPERM;
- break;
- case 4: /* Port */
- if (mem->state == mm_state_stopped)
- mem->port = atoi(value);
- else
- return MME_EPERM;
- break;
- case 5: /* Route */
- MM_SSAFE_COPY(mem->route, value);
- break;
- case 6: /* Domain */
- MM_SSAFE_COPY(mem->domain, value);
- break;
- case 7: /* Ping */
- mem->ping = atoi(value);
- break;
- case 8: /* MaxConnections */
- i = atoi(value);
- if (i < 1 || i > max_threads_per_child)
- return MME_EINVAL;
- else
- mem->max_conn = i;
- break;
- case 9: /* MinConnections */
- i = atoi(value);
- if (i < 1 || i > (int)mem->max_conn)
- return MME_EINVAL;
- else
- mem->min_conn = i;
- break;
- case 10: /* MaxClients */
- i = atoi(value);
- if (i < 1 || i > max_clients)
- return MME_EINVAL;
- else
- mem->max_clients = i;
- break;
- case 11: /* TTL */
- mem->ttl = atoi(value);
- break;
- case 12: /* LF */
- mem->lf = atoi(value);
- break;
- case 13: /* Distance */
- mem->distance = atoi(value);
- break;
- case 14: /* Activation */
- mem->activation = mm_state_get(value);
- break;
- case 15: /* FlushMode */
- mem->flush = get_flush_mode(value);
- break;
- case 16: /* FlushTimeout */
- mem->flush_wait = atoi(value) * APR_TIME_C(1000);
- break;
- default:
- return MME_EPERM;
- break;
- }
- return APR_SUCCESS;
-}
-
-/* Configure Member */
-static int rdo_member_config(mm_server_conf_t *cfg,
- apr_table_t *cmd_table,
- int cmd_offset,
- apr_uint32_t member_id,
- mmdb_member_t *member,
- request_rec *r)
-{
- int cnt = 0;
- int i, j;
- apr_status_t rc;
-
- const apr_array_header_t *ca = apr_table_elts(cmd_table);
- apr_table_entry_t *ce = (apr_table_entry_t *)ca->elts;
-
- /* Step 1: Figure out the number of requested params */
- for (i = cmd_offset; i < ca->nelts; i++) {
- j = 1;
- if (apr_fnmatch_test(ce[i].key)) {
- /* Wildchar params not allowed for config */
- continue;
- }
- else {
- while (member_params[j]) {
- if (!strcasecmp(ce[i].key, member_params[j])) {
- if (!ce[i].val || !*(ce[i].val)) {
- /* Empty value */
- mm_send_response_ex(r, mm_response_error, MME_EINVAL,
- NULL);
- return 1;
- }
- if ((rc = rdo_member_config_do(j, ce[i].val,
- member, r)) != APR_SUCCESS) {
- /* Parameter value error */
- mm_send_response_ex(r, mm_response_error,
- rc, NULL);
- return 1;
- }
- cnt++;
- break;
- }
- j++;
- }
- }
- }
- return 0;
-}
-
-static apr_status_t rdo_member(mm_server_conf_t *cfg,
- mm_mcmp_command_e cmd,
- const char *name,
- mm_resource_provider_t *prev,
- apr_uint32_t prev_id,
- void *prev_rec,
- apr_table_t *cmd_table,
- int cmd_offset,
- request_rec *r)
-{
- int wdone = 0;
- int wcm;
- const apr_array_header_t *ca = apr_table_elts(cmd_table);
- apr_table_entry_t *ce = (apr_table_entry_t *)ca->elts;
- apr_uint32_t next = 0;
- mmdb_member_t *member;
-
- asmm_slotmem_t *member_db = mmdb_table_getn(MMDB_MEMBER);
-
- if (!member_db)
- return APR_ENOMEM;
- if (!name || !*name) {
- mm_send_response_ex(r, mm_response_error, MME_EINVAL, NULL);
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
- "mod_manager: [%s] empty member name",
- mm_mcmp_command_name_get(cmd));
- return APR_SUCCESS;
- }
- wcm = apr_fnmatch_test(name);
- while ((member = asmm_slot_next(member_db, &next))) {
- if (wcm) {
- if (apr_fnmatch(name, member->name,
- MM_FFNMATCH) != APR_SUCCESS)
- continue;
- }
- else if (strcasecmp(name, member->name))
- continue;
- if (cmd_offset < ca->nelts) {
- mm_resource_provider_t *mp =
mm_lookup_resource_provider(ce[cmd_offset].key);
- if (mp) {
- apr_status_t rc;
- if (mp == this_provider) {
- mm_send_response_ex(r, mm_response_error, MME_EINVAL, NULL);
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
- "mod_manager: [%s] recursion not allowed:
%s",
- mm_mcmp_command_name_get(cmd),
- this_provider->name);
- return APR_SUCCESS;
- }
- rc = (*mp->func)(cfg, cmd,
- ce[cmd_offset].val, this_provider,
- next - 1, member,
- cmd_table, cmd_offset + 1, r);
- if (rc != APR_SUCCESS) {
- }
- wdone++;
- if (wcm)
- continue;
- else
- break;
- }
- }
- switch (cmd) {
- case mm_mcmp_info:
- if (wcm) {
- ap_rvputs(r, MM_RES_MEMBER "/", member->name, NULL);
- if (cmd_offset < ca->nelts)
- ap_rputs(": ", r);
- else
- ap_rputs(CRLF, r);
- }
- if (cmd_offset < ca->nelts)
- rdo_member_info(cmd_table, cmd_offset, wcm, member, r);
- break;
- case mm_mcmp_enable:
- member->state = mm_state_active;
- member->activation = mm_state_active;
- break;
- case mm_mcmp_disable:
- member->state = mm_state_disabled;
- member->activation = mm_state_disabled;
- break;
- case mm_mcmp_stop:
- member->state = mm_state_stopped;
- member->activation = mm_state_stopped;
- break;
- case mm_mcmp_reset:
- /* Reset statistical data */
- member->elected = 0;
- member->ssessions = 0;
- member->err_client = 0;
- member->err_node = 0;
- member->err_trace = 0;
- member->trace = 0;
- member->readed = 0;
- member->transferred = 0;
- break;
- case mm_mcmp_delete:
- if (member->state != mm_state_stopped) {
- /* Member must be stopped before */
- mm_send_response_ex(r, mm_response_error, MME_EBUSY, NULL);
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
- "mod_manager: Member not stopped: %s",
- member->name);
- return APR_SUCCESS;
- }
- else {
- /* Delete Member entry */
- mmdb_balancer_t *pbal = NULL;
- if (member->balancer_id)
- pbal = asmm_slot(mmdb_table_getn(MMDB_MEMBER),
- member->balancer_id);
- del_app_members(next - 1);
- asmm_free(member_db, member);
- if (pbal && pbal->members)
- pbal->members--;
- }
- break;
- case mm_mcmp_config:
- if (prev && prev->id == MMDB_BALANCER) {
- mmdb_balancer_t *nbal = (mmdb_balancer_t *)prev_rec;
- if (prev_id != member->balancer_id) {
- mmdb_balancer_t *pbal = NULL;
- if (member->balancer_id)
- pbal = asmm_slot(mmdb_table_getn(MMDB_MEMBER),
- member->balancer_id);
- /* Attach the Member to another Balancer */
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
- "mod_manager: Member: %s assigned to "
- "Balancer: %s",
- member->name, nbal->name);
- member->balancer_id = prev_id;
- nbal->members++;
- if (pbal && pbal->members)
- pbal->members--;
- }
- }
- if (rdo_member_config(cfg, cmd_table, cmd_offset,
- next - 1, member, r))
- return APR_SUCCESS;
- break;
- default:
- mm_send_response_ex(r, mm_response_error, MME_EPERM, NULL);
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
- "mod_manager: [%s] not allowed for Balancer",
- mm_mcmp_command_name_get(cmd));
- return APR_SUCCESS;
- break;
-
- }
- wdone++;
- if (!wcm)
- break;
- }
- if (!wdone) {
- if (cmd == mm_mcmp_config && !wcm) {
- apr_uint32_t member_id;
- if (prev && prev->id != MMDB_BALANCER) {
- mm_send_response_ex(r, mm_response_utype, 0, prev->name, NULL);
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
- "mod_manager: type %s in not balancer for "
- "Member: %s",
- prev->name, name);
- return APR_SUCCESS;
- }
- if (!prev) {
- /* Use _default_ balancer */
- prev_id = 0;
- }
- /* Add new Member */
- if (!(member = asmm_salloc_ex(member_db, &member_id)))
- return apr_get_os_error();
- MM_SSAFE_COPY(member->name, name);
- member->balancer_id = prev_id;
- member->state = mm_state_stopped;
- member->activation = mm_state_stopped;
- member->lf = 1;
- member->max_conn = max_threads_per_child;
- member->min_conn = max_threads_per_child;
- member->max_clients = max_clients;
- /* Update Member from provided params */
- if (rdo_member_config(cfg, cmd_table, cmd_offset,
- member_id, member, r)) {
- /* There was an error during initial config
- * Delete member we created
- */
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
- "mod_manager: failed creating member: %s",
- name);
- asmm_free(member_db, member);
- return APR_SUCCESS;
- }
- if (!member->route[0])
- strcpy(member->route, member->name);
- if (!member->address[0])
- strcpy(member->address, MM_DEFAULT_ADDRESS);
- if (member->type == mm_protocol_unknown)
- member->type = MM_DEFAULT_PROTOCOL;
- if (!member->port) {
- switch (member->type) {
- case mm_protocol_ajp:
- member->port = MM_DEFAULT_AJP_PORT;
- break;
- case mm_protocol_http:
- member->port = MM_DEFAULT_HTTP_PORT;
- break;
- case mm_protocol_https:
- member->port = MM_DEFAULT_HTTPS_PORT;
- break;
- default:
- mm_send_response_ex(r, mm_response_error,
- MME_EINVAL, NULL);
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
- "mod_manager: Unknown protocol %d for "
- "Member: %s",
- member->type, member->name);
- asmm_free(member_db, member);
- return APR_SUCCESS;
- break;
- }
- }
- if (member->min_conn > member->max_conn)
- member->min_conn = member->max_conn;
- member->state = mm_state_stopped;
- /* Add Applications linked to the Member's Balancer */
- if (add_app_members(member_id, member->balancer_id) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, 0, r->server,
- "mod_manager: adding MemberApplication for: %s",
- member->name);
- del_app_members(member_id);
- asmm_free(member_db, member);
- return APR_SUCCESS;
- }
- if (prev_rec) {
- ((mmdb_balancer_t *)prev_rec)->members++;
- }
- }
- else {
- mm_send_response_ex(r, mm_response_utype, 0, MM_RES_MEMBER "/",
- name, NULL);
- ap_log_error(APLOG_MARK, APLOG_INFO, 0, r->server,
- "mod_manager: unknown member: %s", name);
- return APR_SUCCESS;
- }
- }
- switch (cmd) {
- case mm_mcmp_info:
- break;
- default:
- if (!prev)
- mm_send_response_ex(r, mm_response_ok, 0, NULL);
- break;
- }
- return APR_SUCCESS;
-}
-
-static apr_status_t rdo_member_init(mm_server_conf_t *cfg)
-{
-
- ap_mpm_query(AP_MPMQ_HARD_LIMIT_THREADS, &thread_limit);
- ap_mpm_query(AP_MPMQ_HARD_LIMIT_DAEMONS, &server_limit);
- ap_mpm_query(AP_MPMQ_MAX_REQUESTS_DAEMON, &max_requests_per_child);
- ap_mpm_query(AP_MPMQ_MAX_DAEMONS, &max_childs);
- if (max_childs < 1)
- max_childs = 1;
- ap_mpm_query(AP_MPMQ_MAX_THREADS, &max_threads_per_child);
- if (max_threads_per_child < 1)
- max_threads_per_child = 1;
- max_clients = max_childs * max_threads_per_child;
- return APR_SUCCESS;
-}
-
-static apr_status_t ini_member(mm_server_conf_t *cfg,
- mm_resource_op_e op,
- apr_pool_t *pool)
-{
- switch (op) {
- case mm_resource_init:
- case mm_resource_open:
- case mm_resource_child_init:
- return rdo_member_init(cfg);
- break;
- case mm_resource_close:
- /* Nothing to do for a Member */
- break;
- }
- return APR_SUCCESS;
-}
-
-static mm_resource_provider_t member_provider = {
- MMDB_MEMBER,
- MM_RES_MEMBER,
- rdo_member,
- ini_member,
- NULL
-};
-
-/* Exported register function */
-void mm_register_resource_member(apr_pool_t *pool)
-{
- this_provider = &member_provider;
- mm_register_resource_provider(pool, this_provider);
-}
Modified: sandbox/aloha/httpd/modules/manager/mm_util.c
===================================================================
--- sandbox/aloha/httpd/modules/manager/mm_util.c 2008-05-29 14:34:51 UTC (rev 1641)
+++ sandbox/aloha/httpd/modules/manager/mm_util.c 2008-05-30 07:23:54 UTC (rev 1642)
@@ -609,7 +609,7 @@
{ MMDB_MEMBER,
"Member",
sizeof(mmdb_member_t),
- 1,
+ 64,
ASMM_HAS_LOCK,
ASMM_UNLIMITED,
NULL,