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.
diff --git a/src/check.c b/src/check.c
index 4a4e4c7..55f0793 100644
--- a/src/check.c
+++ b/src/check.c
@@ -1241,13 +1241,13 @@
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 @@
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 @@
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