}
/*
- * Must be called with the server lock held, and will write-lock the proxy.
+ * Must be called with the server lock held. The server is first removed from
+ * the proxy tree if it was already attached. If <reattach> is true, the server
+ * will then be attached in the proxy tree. The proxy lock is held to
+ * manipulate the tree.
*/
-static void srv_set_addr_desc(struct server *s)
+static void srv_set_addr_desc(struct server *s, int reattach)
{
struct proxy *p = s->proxy;
char *key;
s->addr_node.key = key;
- if (s->addr_node.key) {
- HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock);
- ebis_insert(&p->used_server_addr, &s->addr_node);
- HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->lock);
+ if (reattach) {
+ if (s->addr_node.key) {
+ HA_RWLOCK_WRLOCK(PROXY_LOCK, &p->lock);
+ ebis_insert(&p->used_server_addr, &s->addr_node);
+ HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &p->lock);
+ }
}
}
newsrv->addr = *sk;
newsrv->svc_port = port;
- // we don't need to lock the server here, because
- // we are in the process of initializing
- srv_set_addr_desc(newsrv);
+ /*
+ * we don't need to lock the server here, because
+ * we are in the process of initializing.
+ *
+ * Note that the server is not attached into the proxy tree if
+ * this is a dynamic server.
+ */
+ srv_set_addr_desc(newsrv, !(parse_flags & SRV_PARSE_DYNAMIC));
if (!newsrv->srvrq && !newsrv->hostname && !protocol_by_family(newsrv->addr.ss_family)) {
ha_alert("Unknown protocol family %d '%s'\n",
break;
};
srv_set_dyncookie(s);
- srv_set_addr_desc(s);
+ srv_set_addr_desc(s, 1);
return 0;
}
/* force connection cleanup on the given server */
srv_cleanup_connections(s);
srv_set_dyncookie(s);
- srv_set_addr_desc(s);
+ srv_set_addr_desc(s, 1);
}
if (updater)
chunk_appendf(msg, " by '%s'", updater);
return return_code;
out:
srv_set_dyncookie(srv);
- srv_set_addr_desc(srv);
+ srv_set_addr_desc(srv, 1);
return return_code;
}
/* insert the server in the backend trees */
eb32_insert(&be->conf.used_server_id, &srv->conf.id);
ebis_insert(&be->conf.used_server_name, &srv->conf.name);
+ ebis_insert(&be->used_server_addr, &srv->addr_node);
thread_release();