[master] fdf06b4 Let directors and backends do their own panic dumps.

Poul-Henning Kamp phk at FreeBSD.org
Wed Jun 24 22:45:12 CEST 2015


commit fdf06b4b3996dc495c27fc873e214029238a0621
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jun 24 17:40:30 2015 +0000

    Let directors and backends do their own panic dumps.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index c2668a9..ca40b75 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -277,6 +277,7 @@ vbe_dir_http1pipe(const struct director *d, struct req *req, struct busyobj *bo)
 	int i;
 	struct backend *bp;
 
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
@@ -294,6 +295,36 @@ vbe_dir_http1pipe(const struct director *d, struct req *req, struct busyobj *bo)
 
 /*--------------------------------------------------------------------*/
 
+static void
+vbe_panic(const struct director *d, struct vsb *vsb)
+{
+	struct backend *bp;
+
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+	CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
+
+	VSB_printf(vsb, "      display_name = %s\n", bp->display_name);
+	if (bp->ipv4_addr != NULL)
+		VSB_printf(vsb, "      ipv4 = %s\n", bp->ipv4_addr);
+	if (bp->ipv6_addr != NULL)
+		VSB_printf(vsb, "      ipv6 = %s\n", bp->ipv6_addr);
+	VSB_printf(vsb, "      port = %s\n", bp->port);
+	VSB_printf(vsb, "      hosthdr = %s\n", bp->hosthdr);
+	VSB_printf(vsb, "      health=%s, admin_health=",
+	    bp->healthy ? "healthy" : "sick");
+	if (bp->admin_health == ah_probe)
+		VSB_printf(vsb, "probe");
+	else if (bp->admin_health == ah_sick)
+		VSB_printf(vsb, "sick");
+	else if (bp->admin_health == ah_healthy)
+		VSB_printf(vsb, "healthy");
+	else
+		VSB_printf(vsb, "*invalid*");
+	VSB_printf(vsb, ", changed=%.1f\n", bp->health_changed);
+}
+
+/*--------------------------------------------------------------------*/
+
 void
 VBE_fill_director(struct backend *be)
 {
@@ -312,4 +343,5 @@ VBE_fill_director(struct backend *be)
 	d->getbody = vbe_dir_getbody;
 	d->getip = vbe_dir_getip;
 	d->finish = vbe_dir_finish;
+	d->panic = vbe_panic;
 }
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index 49a0405..f7e0479 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -178,3 +178,19 @@ VDI_Healthy(const struct director *d, const struct busyobj *bo)
 		return (1);
 	return (d->healthy(d, bo, NULL));
 }
+
+/* Dump panic info -----------------------------------------------------
+ */
+
+void
+VDI_Panic(const struct director *d, struct vsb *vsb, const char *nm)
+{
+	if (d == NULL)
+		return;
+	VSB_printf(vsb, "    %s = %p {\n", nm, d);
+	VSB_printf(vsb, "      vcl_name = %s\n", d->vcl_name);
+	VSB_printf(vsb, "      name = %s\n", d->name);
+	if (d->panic != NULL)
+		d->panic(d, vsb);
+	VSB_printf(vsb, "    }\n");
+}
diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index cf7af4b..cf20dc1 100644
--- a/bin/varnishd/cache/cache_director.h
+++ b/bin/varnishd/cache/cache_director.h
@@ -61,6 +61,8 @@ typedef void vdi_finish_f(const struct director *, struct worker *,
 typedef void vdi_http1pipe_f(const struct director *, struct req *,
     struct busyobj *);
 
+typedef void vdi_panic_f(const struct director *, struct vsb *);
+
 struct director {
 	unsigned		magic;
 #define DIRECTOR_MAGIC		0x3336351d
@@ -73,6 +75,7 @@ struct director {
 	vdi_getbody_f		*getbody;
 	vdi_getip_f		*getip;
 	vdi_finish_f		*finish;
+	vdi_panic_f		*panic;
 	void			*priv;
 	const void		*priv2;
 };
@@ -88,3 +91,4 @@ void VDI_Finish(struct worker *wrk, struct busyobj *bo);
 int VDI_Http1Pipe(struct req *, struct busyobj *);
 
 int VDI_Healthy(const struct director *, const struct busyobj *);
+void VDI_Panic(const struct director *, struct vsb *, const char *nm);
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 8412d30..bfe3e70 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -46,7 +46,6 @@
 
 #include "vrt.h"
 #include "cache_director.h"
-#include "cache_backend.h"
 #include "storage/storage.h"
 #include "vcli_priv.h"
 
@@ -145,16 +144,12 @@ pan_ws(const struct ws *ws, int indent)
 /*--------------------------------------------------------------------*/
 
 static void
-pan_vbc(const struct vbc *vbc)
+pan_htc(const struct http_conn *htc)
 {
 
-	struct backend *be;
-
-	be = vbc->backend;
-
-	VSB_printf(pan_vsp, "  backend = %p fd = %d {\n", be, vbc->fd);
-	VSB_printf(pan_vsp, "    display_name = \"%s\",\n", be->display_name);
-	VSB_printf(pan_vsp, "  },\n");
+	VSB_printf(pan_vsp, "    http_conn = %p {\n", htc);
+	VSB_printf(pan_vsp, "      fd = %d,\n", htc->fd);
+	VSB_printf(pan_vsp, "    },\n");
 }
 
 /*--------------------------------------------------------------------*/
@@ -309,15 +304,15 @@ pan_busyobj(const struct busyobj *bo)
 
 	VSB_printf(pan_vsp, "  busyobj = %p {\n", bo);
 	pan_ws(bo->ws, 4);
-	VSB_printf(pan_vsp, "  refcnt = %u\n", bo->refcount);
-	VSB_printf(pan_vsp, "  retries = %d\n", bo->retries);
-	VSB_printf(pan_vsp, "  failed = %d\n", bo->vfc->failed);
-	VSB_printf(pan_vsp, "  state = %d\n", (int)bo->state);
-	VSB_printf(pan_vsp, "  flags = {\n");
-#define BO_FLAG(l, r, w, d) if(bo->l) VSB_printf(pan_vsp, "    " #l "\n");
+	VSB_printf(pan_vsp, "    refcnt = %u\n", bo->refcount);
+	VSB_printf(pan_vsp, "    retries = %d\n", bo->retries);
+	VSB_printf(pan_vsp, "    failed = %d\n", bo->vfc->failed);
+	VSB_printf(pan_vsp, "    state = %d\n", (int)bo->state);
+	VSB_printf(pan_vsp, "    flags = {\n");
+#define BO_FLAG(l, r, w, d) if(bo->l) VSB_printf(pan_vsp, "      " #l "\n");
 #include "tbl/bo_flags.h"
 #undef BO_FLAG
-	VSB_printf(pan_vsp, "  }\n");
+	VSB_printf(pan_vsp, "    }\n");
 
 	if (bo->htc != NULL) {
 		VSB_printf(pan_vsp, "    bodystatus = %d (%s),\n",
@@ -331,11 +326,14 @@ pan_busyobj(const struct busyobj *bo)
 			    vfe->vfp->name, (int)vfe->closed);
 		VSB_printf(pan_vsp, "\n");
 	}
-	VSB_printf(pan_vsp, "    },\n");
 
-	if (bo->htc != NULL && bo->htc->vbc != NULL &&
-	    VALID_OBJ(bo->htc->vbc, BACKEND_MAGIC))
-		pan_vbc(bo->htc->vbc);
+	if (VALID_OBJ(bo->htc, HTTP_CONN_MAGIC))
+		pan_htc(bo->htc);
+	VDI_Panic(bo->director_req, pan_vsp, "director_req");
+	if (bo->director_resp == bo->director_req)
+		VSB_printf(pan_vsp, "    director_resp = director_req\n");
+	else
+		VDI_Panic(bo->director_resp, pan_vsp, "director_resp");
 	if (bo->bereq != NULL && bo->bereq->ws != NULL)
 		pan_http("bereq", bo->bereq, 4);
 	if (bo->beresp != NULL && bo->beresp->ws != NULL)



More information about the varnish-commit mailing list