Skip to content

Commit f64aa03

Browse files
committed
MEDIUM: proxy: add lock for global accesses during default free
This patch is similar to the previous one, but this time it deals with functions related to defaults proxies instances. Lock PROXIES_DEL_LOCK is used to protect accesses on global collections. This patch will be necessary to implement dynamic backend deletion, even if defaults won't be use as direct target of a "del backend" CLI. However, a backend may have a reference on a default instance. When the backend is freed, this references is released, which can in turn cause the freeing of the default proxy instance. All of this will occur at runtime, outside of thread isolation.
1 parent f58b269 commit f64aa03

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/proxy.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,21 +2980,27 @@ static void defaults_px_free(struct proxy *defproxy)
29802980

29812981
/* Removes <px> defaults instance from the name tree, free its content and
29822982
* storage. This must only be used if <px> is unreferenced.
2983+
*
2984+
* Uses PROXIES_DEL_LOCK to protect global tree/list accesses.
29832985
*/
29842986
void defaults_px_destroy(struct proxy *px)
29852987
{
29862988
BUG_ON(!(px->cap & PR_CAP_DEF));
29872989
BUG_ON(px->conf.def_ref != 0);
29882990

2991+
HA_SPIN_LOCK(PROXIES_DEL_LOCK, &proxies_del_lock);
29892992
cebis_item_delete(&defproxy_by_name, conf.name_node, id, px);
29902993
LIST_DELETE(&px->el);
2994+
HA_SPIN_UNLOCK(PROXIES_DEL_LOCK, &proxies_del_lock);
29912995

29922996
defaults_px_free(px);
29932997
free(px);
29942998
}
29952999

29963000
/* delete all unreferenced default proxies. A default proxy is unreferenced if
29973001
* its <def_ref> count is equal to zero.
3002+
*
3003+
* Not thread safe - currently only used during init.
29983004
*/
29993005
void defaults_px_destroy_all_unref(void)
30003006
{
@@ -3011,6 +3017,8 @@ void defaults_px_destroy_all_unref(void)
30113017
/* Removes <px> defaults from the name tree. This operation is useful when a
30123018
* section is made invisible by a newer instance with the same name. If <px> is
30133019
* not referenced it is freed immediately, else it is kept in defaults_list.
3020+
*
3021+
* Not thread safe - currently only used during parsing.
30143022
*/
30153023
void defaults_px_detach(struct proxy *px)
30163024
{
@@ -3021,7 +3029,10 @@ void defaults_px_detach(struct proxy *px)
30213029
/* If not destroyed, <px> can still be accessed in <defaults_list>. */
30223030
}
30233031

3024-
/* Increments by one defaults proxy reference of all defaults stored in tree name. */
3032+
/* Increments by one defaults proxy reference of all defaults stored in tree name.
3033+
*
3034+
* Not thread safe - currently only used during init.
3035+
*/
30253036
void defaults_px_ref_all(void)
30263037
{
30273038
struct proxy *px;
@@ -3033,7 +3044,11 @@ void defaults_px_ref_all(void)
30333044
}
30343045
}
30353046

3036-
/* Decrements defaults proxy ref of all defaults. This is the reverse of defaults_px_ref_all(). */
3047+
/* Decrements defaults proxy ref of all defaults. This is the reverse of
3048+
* defaults_px_ref_all().
3049+
*
3050+
* Not thread safe - currently only used during deinit.
3051+
*/
30373052
void defaults_px_unref_all(void)
30383053
{
30393054
struct proxy *px, *nx;

0 commit comments

Comments
 (0)