[master] 58064f342 Split the panic function into conn/tcp pool layers.

Poul-Henning Kamp phk at FreeBSD.org
Thu Jan 7 13:00:09 UTC 2021


commit 58064f342ab7d1984600c232b55d57a8a2c23d35
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jan 7 12:09:25 2021 +0000

    Split the panic function into conn/tcp pool layers.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 1a91c2753..3f6d4afa6 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -462,7 +462,7 @@ vbe_panic(const struct director *d, struct vsb *vsb)
 	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
 
-	VTP_panic(vsb, bp->tcp_pool);
+	VTP_Panic(vsb, bp->tcp_pool);
 	VSB_printf(vsb, "hosthdr = %s,\n", bp->hosthdr);
 	VSB_printf(vsb, "n_conn = %u,\n", bp->n_conn);
 }
diff --git a/bin/varnishd/cache/cache_tcp_pool.c b/bin/varnishd/cache/cache_tcp_pool.c
index 660c6f4d0..a649e7e25 100644
--- a/bin/varnishd/cache/cache_tcp_pool.c
+++ b/bin/varnishd/cache/cache_tcp_pool.c
@@ -73,6 +73,7 @@ typedef int cp_open_f(const struct conn_pool *, vtim_dur tmo, VCL_IP *ap);
 typedef void cp_close_f(struct pfd *);
 typedef void cp_name_f(const struct pfd *, char *, unsigned, char *, unsigned);
 typedef void cp_free_f(void *);
+typedef void cp_panic_f(struct vsb *, const void *);
 
 struct cp_methods {
 	cp_open_f				*open;
@@ -80,6 +81,7 @@ struct cp_methods {
 	cp_name_f				*local_name;
 	cp_name_f				*remote_name;
 	cp_free_f				*free;
+	cp_panic_f				*panic;
 };
 
 struct conn_pool {
@@ -612,6 +614,54 @@ vtp_open(const struct conn_pool *cp, vtim_dur tmo, VCL_IP *ap)
 	return (s);
 }
 
+static void
+vtp_panic(struct vsb *vsb, const void *priv)
+{
+	const struct tcp_pool *tp;
+
+	char h[VTCP_ADDRBUFSIZE];
+	char p[VTCP_PORTBUFSIZE];
+
+	tp = priv;
+	if (PAN_dump_struct(vsb, tp, TCP_POOL_MAGIC, "tcp_pool"))
+		return;
+	if (tp->uds)
+		VSB_printf(vsb, "uds = %s,\n", tp->uds);
+	if (tp->ip4 && VSA_Sane(tp->ip4)) {
+		VTCP_name(tp->ip4, h, sizeof h, p, sizeof p);
+		VSB_printf(vsb, "ipv4 = %s, ", h);
+		VSB_printf(vsb, "port = %s,\n", p);
+	}
+	if (tp->ip6 && VSA_Sane(tp->ip6)) {
+		VTCP_name(tp->ip6, h, sizeof h, p, sizeof p);
+		VSB_printf(vsb, "ipv6 = %s, ", h);
+		VSB_printf(vsb, "port = %s,\n", p);
+	}
+	VSB_indent(vsb, -2);
+	VSB_cat(vsb, "},\n");
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+VTP_Panic(struct vsb *vsb, struct tcp_pool *tp)
+{
+	struct conn_pool *cp;
+
+	cp = tp->cp;
+
+	if (PAN_dump_struct(vsb, cp, CONN_POOL_MAGIC, "conn_pool"))
+		return;
+	VSB_printf(vsb, "ident = ");
+	VSB_quote(vsb, cp->ident, VSHA256_DIGEST_LENGTH, VSB_QUOTE_HEX);
+	VSB_printf(vsb, ",\n");
+	cp->methods->panic(vsb, cp->priv);
+	VSB_indent(vsb, -2);
+	VSB_cat(vsb, "},\n");
+}
+
+/*--------------------------------------------------------------------*/
+
 static void v_matchproto_(cp_close_f)
 vtp_close(struct pfd *pfd)
 {
@@ -642,6 +692,7 @@ static const struct cp_methods vtp_methods = {
 	.local_name = vtp_local_name,
 	.remote_name = vtp_remote_name,
 	.free = vtp_free,
+	.panic = vtp_panic,
 };
 
 /*--------------------------------------------------------------------
@@ -681,6 +732,7 @@ static const struct cp_methods vus_methods = {
 	.local_name = vus_name,
 	.remote_name = vus_name,
 	.free = vtp_free,
+	.panic = vtp_panic,
 };
 
 /*--------------------------------------------------------------------
@@ -834,34 +886,6 @@ VTP_GetIp(struct pfd *pfd)
 	return (pfd->addr);
 }
 
-/*--------------------------------------------------------------------*/
-
-void
-VTP_panic(struct vsb *vsb, struct tcp_pool *tp)
-{
-	char h[VTCP_ADDRBUFSIZE];
-	char p[VTCP_PORTBUFSIZE];
-
-	if (PAN_dump_struct(vsb, tp, TCP_POOL_MAGIC, "tcp_pool"))
-		return;
-	VSB_printf(vsb, "ident = ");
-	VSB_quote(vsb, tp->cp->ident, VSHA256_DIGEST_LENGTH, VSB_QUOTE_HEX);
-	VSB_printf(vsb, ",\n");
-	if (tp->uds)
-		VSB_printf(vsb, "uds = %s,\n", tp->uds);
-	if (tp->ip4 && VSA_Sane(tp->ip4)) {
-		VTCP_name(tp->ip4, h, sizeof h, p, sizeof p);
-		VSB_printf(vsb, "ipv4 = %s, ", h);
-		VSB_printf(vsb, "port = %s,\n", p);
-	}
-	if (tp->ip6 && VSA_Sane(tp->ip6)) {
-		VTCP_name(tp->ip6, h, sizeof h, p, sizeof p);
-		VSB_printf(vsb, "ipv6 = %s, ", h);
-		VSB_printf(vsb, "port = %s,\n", p);
-	}
-	VSB_indent(vsb, -2);
-	VSB_cat(vsb, "},\n");
-}
 
 /*--------------------------------------------------------------------*/
 
diff --git a/bin/varnishd/cache/cache_tcp_pool.h b/bin/varnishd/cache/cache_tcp_pool.h
index 01fc952cb..42dddb941 100644
--- a/bin/varnishd/cache/cache_tcp_pool.h
+++ b/bin/varnishd/cache/cache_tcp_pool.h
@@ -102,7 +102,7 @@ int VTP_Wait(struct worker *, struct pfd *, vtim_real tmo);
 	 * function before attempting to receive on the connection.
 	 */
 
-void VTP_panic(struct vsb *, struct tcp_pool *);
+void VTP_Panic(struct vsb *, struct tcp_pool *);
 
 VCL_IP VTP_GetIp(struct pfd *);
 


More information about the varnish-commit mailing list