From: Graham Leggett Date: Sun, 16 Dec 2012 14:13:49 +0000 (+0000) Subject: mod_slotmem_*: Add in new fgrab() function which forces a grab and X-Git-Tag: 2.4.4~275 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=76149a7fdd6a7e484df9602a6e445ce14bf9b8a5;p=apache mod_slotmem_*: Add in new fgrab() function which forces a grab and slot allocation on a specified slot. Allow for clearing of inuse array. trunk patch: http://svn.apache.org/viewvc?view=revision&revision=1386880 http://svn.apache.org/viewvc?view=revision&revision=1387389 http://svn.apache.org/viewvc?view=revision&revision=1388445 http://svn.apache.org/viewvc?view=revision&revision=1394079 Submitted by: jim Reviewed by: rjung, minfrin git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1422580 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 00d908d32f..f53a23f499 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,10 @@ Changes with Apache 2.4.4 + *) mod_slotmem_*: Add in new fgrab() function which forces a grab and + slot allocation on a specified slot. Allow for clearing of inuse + array. [Jim Jagielski] + *) mod_proxy_ftp: Fix segfaults on IPv4 requests to hosts with DNS AAAA records. PR 40841. [Andrew Rucker Jones , , Jim Jagielski] diff --git a/STATUS b/STATUS index 1d25391edc..3fca2c2a5b 100644 --- a/STATUS +++ b/STATUS @@ -91,17 +91,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - * mod_slotmem_*: Add in new fgrab() function which forces a grab and - slot allocation on a specified slot. Allow for clearing of inuse - array. - trunk patch: http://svn.apache.org/viewvc?view=revision&revision=1386880 - http://svn.apache.org/viewvc?view=revision&revision=1387389 - http://svn.apache.org/viewvc?view=revision&revision=1388445 - http://svn.apache.org/viewvc?view=revision&revision=1394079 - 2.4.x patch: trunk patch works - +1: jim, rjung - +1: minfrin (with MMN bump) - * ap_expr: Add req_novary function that allows HTTP header lookups without adding the name to the Vary header Not critical for 2.4.4. diff --git a/docs/manual/mod/mod_slotmem_plain.xml b/docs/manual/mod/mod_slotmem_plain.xml index d5f9d232c4..6cd8fe5842 100644 --- a/docs/manual/mod/mod_slotmem_plain.xml +++ b/docs/manual/mod/mod_slotmem_plain.xml @@ -67,10 +67,13 @@
apr_size_t slot_size(ap_slotmem_instance_t *s)
return the total data size, in bytes, of a slot in the segment
-
apr_status_t grab(ap_slotmem_instance_t *s, unsigned int item_id);
-
grab or allocate a slot and mark as in-use (does not do any data copying)
+
apr_status_t grab(ap_slotmem_instance_t *s, unsigned int *item_id);
+
grab or allocate the first free slot and mark as in-use (does not do any data copying)
-
apr_status_t release(ap_slotmem_instance_t *s, unsigned int item_id);
+
apr_status_t fgrab(ap_slotmem_instance_t *s, unsigned int item_id);
+
forced grab or allocate the specified slot and mark as in-use (does not do any data copying)
+ +
apr_status_t release(ap_slotmem_instance_t *s, unsigned int item_id);
release or free a slot and mark as not in-use (does not do any data copying)
diff --git a/docs/manual/mod/mod_slotmem_shm.xml b/docs/manual/mod/mod_slotmem_shm.xml index 12b94f2688..4c45aa2c65 100644 --- a/docs/manual/mod/mod_slotmem_shm.xml +++ b/docs/manual/mod/mod_slotmem_shm.xml @@ -80,8 +80,11 @@
apr_size_t slot_size(ap_slotmem_instance_t *s)
return the total data size, in bytes, of a slot in the segment
-
apr_status_t grab(ap_slotmem_instance_t *s, unsigned int item_id);
-
grab or allocate a slot and mark as in-use (does not do any data copying)
+
apr_status_t grab(ap_slotmem_instance_t *s, unsigned int *item_id);
+
grab or allocate the first free slot and mark as in-use (does not do any data copying)
+ +
apr_status_t fgrab(ap_slotmem_instance_t *s, unsigned int item_id);
+
forced grab or allocate the specified slot and mark as in-use (does not do any data copying)
apr_status_t release(ap_slotmem_instance_t *s, unsigned int item_id);
release or free a slot and mark as not in-use (does not do any data copying)
diff --git a/include/ap_mmn.h b/include/ap_mmn.h index 81e9f8813f..e76f1dc2e8 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -398,6 +398,7 @@ * 20120211.6 (2.4.3-dev) Add ap_proxy_checkproxyblock2. * 20120211.7 (2.4.3-dev) Add ap_get_loadavg() * 20120211.8 (2.4.3-dev) Add sticky_separator to proxy_balancer_shared struct. + * 20120211.9 (2.4.3-dev) Add fgrab() to ap_slotmem_provider_t. */ #define MODULE_MAGIC_COOKIE 0x41503234UL /* "AP24" */ @@ -405,7 +406,7 @@ #ifndef MODULE_MAGIC_NUMBER_MAJOR #define MODULE_MAGIC_NUMBER_MAJOR 20120211 #endif -#define MODULE_MAGIC_NUMBER_MINOR 8 /* 0...n */ +#define MODULE_MAGIC_NUMBER_MINOR 9 /* 0...n */ /** * Determine if the server's current MODULE_MAGIC_NUMBER is at least a diff --git a/include/ap_slotmem.h b/include/ap_slotmem.h index 3d4eafd419..b9c810366d 100644 --- a/include/ap_slotmem.h +++ b/include/ap_slotmem.h @@ -179,6 +179,13 @@ struct ap_slotmem_provider_t { * @return APR_SUCCESS if all went well */ apr_status_t (* release)(ap_slotmem_instance_t *s, unsigned int item_id); + /** + * forced grab (or alloc) a slot associated with this item_id + * @param s ap_slotmem_instance_t to use. + * @param item_id to the specified slot id and marked as in-use + * @return APR_SUCCESS if all went well + */ + apr_status_t (* fgrab)(ap_slotmem_instance_t *s, unsigned int item_id); }; typedef struct ap_slotmem_provider_t ap_slotmem_provider_t; diff --git a/modules/slotmem/mod_slotmem_plain.c b/modules/slotmem/mod_slotmem_plain.c index dc62f46f85..4c2b19b61d 100644 --- a/modules/slotmem/mod_slotmem_plain.c +++ b/modules/slotmem/mod_slotmem_plain.c @@ -154,7 +154,7 @@ static apr_status_t slotmem_dptr(ap_slotmem_instance_t *score, unsigned int id, if (!score) return APR_ENOSHMAVAIL; if (id >= score->num) - return APR_ENOSHMAVAIL; + return APR_EINVAL; ptr = (char *)score->base + score->size * id; if (!ptr) @@ -174,7 +174,10 @@ static apr_status_t slotmem_get(ap_slotmem_instance_t *slot, unsigned int id, un } inuse = slot->inuse + id; - if (id >= slot->num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) { + if (id >= slot->num) { + return APR_EINVAL; + } + if (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse) { return APR_NOTFOUND; } ret = slotmem_dptr(slot, id, &ptr); @@ -197,7 +200,10 @@ static apr_status_t slotmem_put(ap_slotmem_instance_t *slot, unsigned int id, un } inuse = slot->inuse + id; - if (id >= slot->num || (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse)) { + if (id >= slot->num) { + return APR_EINVAL; + } + if (AP_SLOTMEM_IS_PREGRAB(slot) && !*inuse) { return APR_NOTFOUND; } ret = slotmem_dptr(slot, id, &ptr); @@ -251,13 +257,29 @@ static apr_status_t slotmem_grab(ap_slotmem_instance_t *slot, unsigned int *id) } } if (i >= slot->num) { - return APR_ENOSHMAVAIL; + return APR_EINVAL; } *inuse = 1; *id = i; return APR_SUCCESS; } +static apr_status_t slotmem_fgrab(ap_slotmem_instance_t *slot, unsigned int id) +{ + char *inuse; + + if (!slot) { + return APR_ENOSHMAVAIL; + } + + if (id >= slot->num) { + return APR_EINVAL; + } + inuse = slot->inuse + id; + *inuse = 1; + return APR_SUCCESS; +} + static apr_status_t slotmem_release(ap_slotmem_instance_t *slot, unsigned int id) { char *inuse; @@ -268,7 +290,10 @@ static apr_status_t slotmem_release(ap_slotmem_instance_t *slot, unsigned int id inuse = slot->inuse; - if (id >= slot->num || !inuse[id] ) { + if (id >= slot->num) { + return APR_EINVAL; + } + if (!inuse[id] ) { return APR_NOTFOUND; } inuse[id] = 0; @@ -287,7 +312,8 @@ static const ap_slotmem_provider_t storage = { &slotmem_num_free_slots, &slotmem_slot_size, &slotmem_grab, - &slotmem_release + &slotmem_release, + &slotmem_fgrab }; static int pre_config(apr_pool_t *p, apr_pool_t *plog, diff --git a/modules/slotmem/mod_slotmem_shm.c b/modules/slotmem/mod_slotmem_shm.c index 8ecab09847..e5be2448c4 100644 --- a/modules/slotmem/mod_slotmem_shm.c +++ b/modules/slotmem/mod_slotmem_shm.c @@ -634,6 +634,30 @@ static apr_status_t slotmem_grab(ap_slotmem_instance_t *slot, unsigned int *id) return APR_SUCCESS; } +static apr_status_t slotmem_fgrab(ap_slotmem_instance_t *slot, unsigned int id) +{ + char *inuse; + + if (!slot) { + return APR_ENOSHMAVAIL; + } + + if (id >= slot->desc.num) { + ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02236) + "slotmem(%s) fgrab failed. Num %u/num_free %u", + slot->name, slotmem_num_slots(slot), + slotmem_num_free_slots(slot)); + return APR_EINVAL; + } + inuse = slot->inuse + id; + + if (!*inuse) { + *inuse = 1; + (*slot->num_free)--; + } + return APR_SUCCESS; +} + static apr_status_t slotmem_release(ap_slotmem_instance_t *slot, unsigned int id) { @@ -673,7 +697,8 @@ static const ap_slotmem_provider_t storage = { &slotmem_num_free_slots, &slotmem_slot_size, &slotmem_grab, - &slotmem_release + &slotmem_release, + &slotmem_fgrab }; /* make the storage usuable from outside */