MEDIUM: server: extend refcount for all servers

In a future patch, it will be possible to remove at runtime every
servers, both static and dynamic. This requires to extend the server
refcount for all instances.

First, refcount manipulation functions have been renamed to better
express the API usage.

* srv_refcount_use -> srv_take
The refcount is always initialize to 1 on the server creation in
new_server. It's also incremented for each check/agent configured on a
server instance.

* free_server -> srv_drop
This decrements the refcount and if null, the server is freed, so code
calling it must not use the server reference after it. As a bonus, this
function now returns the next server instance. This is useful when
calling on the server loop without having to save the next pointer
before each invocation.

In these functions, remove the checks that prevent refcount on
non-dynamic servers. Each reference to "dynamic" in variable/function
naming have been eliminated as well.
This commit is contained in:
Amaury Denoyelle
2021-08-25 15:34:53 +02:00
parent 0a8d05d31c
commit bc2ebfa5a4
8 changed files with 28 additions and 40 deletions

View File

@@ -1241,13 +1241,13 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
TRACE_LEAVE(CHK_EV_TASK_WAKE, check);
/* Free the check if set to PURGE. After this, the check instance may be
* freed via the free_server invocation, so it must not be accessed
* after this point.
* freed via the srv_drop invocation, so it must not be accessed after
* this point.
*/
if (unlikely(check->state & CHK_ST_PURGE)) {
free_check(check);
if (check->server)
free_server(check->server);
srv_drop(check->server);
t = NULL;
}
@@ -1688,6 +1688,7 @@ int init_srv_check(struct server *srv)
goto out;
}
srv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED;
srv_take(srv);
/* Only increment maxsock for servers from the configuration. Dynamic
* servers at the moment are not taken into account for the estimation
@@ -1743,6 +1744,7 @@ int init_srv_agent_check(struct server *srv)
srv->agent.inter = srv->check.inter;
srv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT;
srv_take(srv);
/* Only increment maxsock for servers from the configuration. Dynamic
* servers at the moment are not taken into account for the estimation