From: Alexander Stephan Date: Thu, 25 Jun 2026 09:04:59 +0000 (+0000) Subject: MINOR: server: distinguish name references with new SRV_F_NAME_REFD flag X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/$%7BGITURL%7D$%7Bcid%7D?a=commitdiff_plain;h=47b20a72e204fbe5347ab270afdbef327642d4aa;p=haproxy.git MINOR: server: distinguish name references with new SRV_F_NAME_REFD flag Until now, every form of "this server is referenced by something in the running config" was collapsed onto a single flag, SRV_F_NON_PURGEABLE, which prevents the server from being removed via 'del server'. This catches everything but conflates two distinct properties: - the server object itself is pinned by another runtime structure (e.g. DNS resolution attached to it), versus - the server's *name* is referenced statically (use-server rules, track chains, sample-fetch arguments of type ARGT_SRV) These differ for any operation that touches the name but not the object identity, e.g. the runtime rename feature added next. Removing a name-referenced server is still forbidden (the rule text would dangle), but renaming such a server should also be forbidden for the same reason - while renaming a resolver-pinned server is fine, since the resolver holds the object pointer and doesn't care about the name. Introduce SRV_F_NAME_REFD for the name-reference case and move the three name-based setters (sample.c ARGT_SRV resolution, proxy.c use-server resolution, server.c track chain setup) from SRV_F_NON_PURGEABLE to SRV_F_NAME_REFD. The resolvers.c call site keeps SRV_F_NON_PURGEABLE since it is the object-pinned case. Adjust 'del server' to check both flags so the set of servers it refuses to remove is unchanged: same observable behavior, just a richer internal taxonomy. A subsequent patch introducing 'set server name' will gate on SRV_F_NAME_REFD only. --- diff --git a/include/haproxy/server-t.h b/include/haproxy/server-t.h index 74f206a92..ca332d4a1 100644 --- a/include/haproxy/server-t.h +++ b/include/haproxy/server-t.h @@ -174,6 +174,7 @@ enum srv_init_state { #define SRV_F_STRICT_MAXCONN 0x10000 /* maxconn is to be strictly enforced, as a limit of outbound connections */ #define SRV_F_CHK_NO_AUTO_SNI 0x20000 /* disable automatic SNI selection for healthcheck */ #define SRV_F_UDP_GSO_NOTSUPP 0x40000 /* UDP GSO is disabled due to a previous error encountered */ +#define SRV_F_NAME_REFD 0x80000 /* this server's name is statically referenced (use-server, track, sample arg) */ /* configured server options for send-proxy (server->pp_opts) */ #define SRV_PP_V1 0x0001 /* proxy protocol version 1 */ diff --git a/src/proxy.c b/src/proxy.c index 885ea679e..8592e409a 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -2119,7 +2119,7 @@ int proxy_finalize(struct proxy *px, int *err_code) } ha_free(&srule->srv.name); srule->srv.ptr = target; - target->flags |= SRV_F_NON_PURGEABLE; + target->flags |= SRV_F_NAME_REFD; } /* find the target table for 'stick' rules */ diff --git a/src/sample.c b/src/sample.c index fbe7e1afb..84ce15c80 100644 --- a/src/sample.c +++ b/src/sample.c @@ -1538,7 +1538,7 @@ int smp_resolve_args(struct proxy *p, char **err) } /* TODO CLI set-var should not prevent server deletion as var value is instantly resolved. */ - srv->flags |= SRV_F_NON_PURGEABLE; + srv->flags |= SRV_F_NAME_REFD; chunk_destroy(&arg->data.str); arg->unresolved = 0; diff --git a/src/server.c b/src/server.c index fa7e2583c..7f8422f75 100644 --- a/src/server.c +++ b/src/server.c @@ -6532,7 +6532,7 @@ int srv_check_for_deletion(const char *bename, const char *svname, struct proxy goto leave; } - if (srv->flags & SRV_F_NON_PURGEABLE) { + if (srv->flags & (SRV_F_NON_PURGEABLE | SRV_F_NAME_REFD)) { msg = "This server cannot be removed at runtime due to other configuration elements pointing to it."; goto leave; } @@ -6783,7 +6783,7 @@ int srv_apply_track(struct server *srv, struct proxy *curproxy) srv->track = strack; srv->tracknext = strack->trackers; strack->trackers = srv; - strack->flags |= SRV_F_NON_PURGEABLE; + strack->flags |= SRV_F_NAME_REFD; ha_free(&srv->trackit);