server_rec *s,
apr_pool_t *p);
+/**
+ * Find the shm of the worker as needed
+ * @param storage slotmem provider
+ * @param slot slotmem instance
+ * @param worker worker to find
+ * @param index pointer to index within slotmem of worker
+ * @return pointer to shm of worker, or NULL
+ */
+PROXY_DECLARE(proxy_worker_shared *) ap_proxy_find_workershm(ap_slotmem_provider_t *storage,
+ ap_slotmem_instance_t *slot,
+ proxy_worker *worker,
+ unsigned int *index);
+
+/**
+ * Find the shm of the balancer as needed
+ * @param storage slotmem provider
+ * @param slot slotmem instance
+ * @param worker worker to find
+ * @param index pointer to index within slotmem of balancer
+ * @return pointer to shm of balancer, or NULL
+ */
+PROXY_DECLARE(proxy_balancer_shared *) ap_proxy_find_balancershm(ap_slotmem_provider_t *storage,
+ ap_slotmem_instance_t *slot,
+ proxy_balancer *balancer,
+ unsigned int *index);
+
/**
* Get the most suitable worker and/or balancer for the request
* @param worker worker used for processing request
proxy_worker *worker;
proxy_balancer_shared *bshm;
const char *sname;
+ unsigned int index;
/* now that we have the right id, we need to redo the sname field */
ap_pstr2_alnum(pconf, balancer->s->name + sizeof(BALANCER_PREFIX) - 1,
apr_pool_cleanup_null);
/* setup shm for balancers */
- if ((rv = storage->fgrab(conf->bslot, i)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01181) "balancer slotmem_grab failed");
- return !OK;
-
+ bshm = ap_proxy_find_balancershm(storage, conf->bslot, balancer, &index);
+ if (bshm) {
+ if ((rv = storage->fgrab(conf->bslot, index)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02408) "balancer slotmem_fgrab failed");
+ return !OK;
+ }
}
- if ((rv = storage->dptr(conf->bslot, i, (void *)&bshm)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01182) "balancer slotmem_dptr failed");
- return !OK;
+ else {
+ if ((rv = storage->grab(conf->bslot, &index)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01181) "balancer slotmem_grab failed");
+ return !OK;
+ }
+ if ((rv = storage->dptr(conf->bslot, index, (void *)&bshm)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01182) "balancer slotmem_dptr failed");
+ return !OK;
+ }
}
- if ((rv = ap_proxy_share_balancer(balancer, bshm, i)) != APR_SUCCESS) {
+ if ((rv = ap_proxy_share_balancer(balancer, bshm, index)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01183) "Cannot share balancer");
return !OK;
}
proxy_worker_shared *shm;
worker = *workers;
- if ((rv = storage->fgrab(balancer->wslot, j)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01186) "worker slotmem_grab failed");
- return !OK;
+ shm = ap_proxy_find_workershm(storage, balancer->wslot, worker, &index);
+ if (shm) {
+ if ((rv = storage->fgrab(balancer->wslot, index)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(02409) "worker slotmem_fgrab failed");
+ return !OK;
+ }
}
- if ((rv = storage->dptr(balancer->wslot, j, (void *)&shm)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01187) "worker slotmem_dptr failed");
- return !OK;
+ else {
+ if ((rv = storage->grab(balancer->wslot, &index)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01186) "worker slotmem_grab failed");
+ return !OK;
+
+ }
+ if ((rv = storage->dptr(balancer->wslot, index, (void *)&shm)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01187) "worker slotmem_dptr failed");
+ return !OK;
+ }
}
- if ((rv = ap_proxy_share_worker(worker, shm, j)) != APR_SUCCESS) {
+ if ((rv = ap_proxy_share_worker(worker, shm, index)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s, APLOGNO(01188) "Cannot share worker");
return !OK;
}
return APR_SUCCESS;
}
+PROXY_DECLARE(proxy_worker_shared *) ap_proxy_find_workershm(ap_slotmem_provider_t *storage,
+ ap_slotmem_instance_t *slot,
+ proxy_worker *worker,
+ unsigned int *index)
+{
+ proxy_worker_shared *shm;
+ unsigned int i, limit;
+ limit = storage->num_slots(slot);
+ for (i = 0; i < limit; i++) {
+ if (storage->dptr(slot, i, (void *)&shm) != APR_SUCCESS) {
+ return NULL;
+ }
+ if ((worker->s->hash.def == shm->hash.def) &&
+ (worker->s->hash.fnv == shm->hash.fnv)) {
+ *index = i;
+ return shm;
+ }
+ }
+ return NULL;
+}
+
+PROXY_DECLARE(proxy_balancer_shared *) ap_proxy_find_balancershm(ap_slotmem_provider_t *storage,
+ ap_slotmem_instance_t *slot,
+ proxy_balancer *balancer,
+ unsigned int *index)
+{
+ proxy_balancer_shared *shm;
+ unsigned int i, limit;
+ limit = storage->num_slots(slot);
+ for (i = 0; i < limit; i++) {
+ if (storage->dptr(slot, i, (void *)&shm) != APR_SUCCESS) {
+ return NULL;
+ }
+ if ((balancer->s->hash.def == shm->hash.def) &&
+ (balancer->s->hash.fnv == shm->hash.fnv)) {
+ *index = i;
+ return shm;
+ }
+ }
+ return NULL;
+}
+
void proxy_util_register_hooks(apr_pool_t *p)
{
APR_REGISTER_OPTIONAL_FN(ap_proxy_retry_worker);