[master] 15c82a6 Clean up the cache_backend.h pollution caused by recent changes to FetchBody.

Poul-Henning Kamp phk at varnish-cache.org
Tue Oct 25 22:05:12 CEST 2011


commit 15c82a60ab3962d2b8291173d4b8fb10f3ab3215
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Oct 25 20:04:42 2011 +0000

    Clean up the cache_backend.h pollution caused by recent changes to
    FetchBody.

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index b92fd60..bce7377 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -712,8 +712,8 @@ void Fetch_Init(void);
 struct vgz;
 
 enum vgz_flag { VGZ_NORMAL, VGZ_ALIGN, VGZ_RESET, VGZ_FINISH };
-struct vgz *VGZ_NewUngzip(struct worker *wrk, int vsl_id, const char *id);
-struct vgz *VGZ_NewGzip(struct worker *wrk, int vsl_id, const char *id);
+struct vgz *VGZ_NewUngzip(struct worker *wrk, const char *id);
+struct vgz *VGZ_NewGzip(struct worker *wrk, const char *id);
 void VGZ_Ibuf(struct vgz *, const void *, ssize_t len);
 int VGZ_IbufEmpty(const struct vgz *vg);
 void VGZ_Obuf(struct vgz *, void *, ssize_t len);
@@ -721,7 +721,7 @@ int VGZ_ObufFull(const struct vgz *vg);
 int VGZ_ObufStorage(struct worker *w, struct vgz *vg);
 int VGZ_Gzip(struct vgz *, const void **, size_t *len, enum vgz_flag);
 int VGZ_Gunzip(struct vgz *, const void **, size_t *len);
-void VGZ_Destroy(struct vgz **);
+void VGZ_Destroy(struct vgz **, int vsl_id);
 void VGZ_UpdateObj(const struct vgz*, struct object *);
 int VGZ_WrwGunzip(struct worker *w, struct vgz *, const void *ibuf,
     ssize_t ibufl, char *obuf, ssize_t obufl, ssize_t *obufp);
@@ -864,12 +864,7 @@ void VSM_Free(const void *ptr);
 void VSL(enum VSL_tag_e tag, int id, const char *fmt, ...);
 void WSLR(struct worker *w, enum VSL_tag_e tag, int id, txt t);
 void WSL(struct worker *w, enum VSL_tag_e tag, int id, const char *fmt, ...);
-#define WSLB(w, tag, ...) 						\
-	do {								\
-		CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);			\
-		CHECK_OBJ_NOTNULL(w->vbc, VBC_MAGIC);			\
-		WSL(w, tag, (w)->vbc->vsl_id, __VA_ARGS__);	\
-	} while (0)
+void WSLB(struct worker *w, enum VSL_tag_e tag, const char *fmt, ...);
 
 void WSL_Flush(struct worker *w, int overflow);
 
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index 91ee652..fe7dae6 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -901,7 +901,7 @@ cnt_streambody(struct sess *sp)
 	sp->wrk->sctx = &sctx;
 
 	if (sp->wrk->res_mode & RES_GUNZIP) {
-		sctx.vgz = VGZ_NewUngzip(sp->wrk, sp->vsl_id, "U S -");
+		sctx.vgz = VGZ_NewUngzip(sp->wrk, "U S -");
 		sctx.obuf = obuf;
 		sctx.obuf_len = sizeof (obuf);
 	}
@@ -934,7 +934,7 @@ cnt_streambody(struct sess *sp)
 
 	RES_StreamEnd(sp);
 	if (sp->wrk->res_mode & RES_GUNZIP)
-		VGZ_Destroy(&sctx.vgz);
+		VGZ_Destroy(&sctx.vgz, sp->vsl_id);
 
 	sp->wrk->sctx = NULL;
 	assert(WRW_IsReleased(sp->wrk));
diff --git a/bin/varnishd/cache_esi_deliver.c b/bin/varnishd/cache_esi_deliver.c
index c10452e..a06bbb8 100644
--- a/bin/varnishd/cache_esi_deliver.c
+++ b/bin/varnishd/cache_esi_deliver.c
@@ -270,7 +270,7 @@ ESI_Deliver(struct sess *sp)
 	}
 
 	if (isgzip && !sp->wrk->gzip_resp) {
-		vgz = VGZ_NewUngzip(sp->wrk, sp->vsl_id, "U D E");
+		vgz = VGZ_NewUngzip(sp->wrk, "U D E");
 
 		/* Feed a gzip header to gunzip to make it happy */
 		VGZ_Ibuf(vgz, gzip_hdr, sizeof gzip_hdr);
@@ -406,7 +406,7 @@ ESI_Deliver(struct sess *sp)
 	if (vgz != NULL) {
 		if (obufl > 0)
 			(void)WRW_Write(sp->wrk, obuf, obufl);
-		VGZ_Destroy(&vgz);
+		VGZ_Destroy(&vgz, sp->vsl_id);
 	}
 	if (sp->wrk->gzip_resp && sp->esi_level == 0) {
 		/* Emit a gzip literal block with finish bit set */
diff --git a/bin/varnishd/cache_esi_fetch.c b/bin/varnishd/cache_esi_fetch.c
index 1713004..69896aa 100644
--- a/bin/varnishd/cache_esi_fetch.c
+++ b/bin/varnishd/cache_esi_fetch.c
@@ -34,7 +34,6 @@
 
 #include "cache.h"
 
-#include "cache_backend.h"		// for w->vbc
 #include "cache_esi.h"
 
 /*---------------------------------------------------------------------
@@ -302,7 +301,7 @@ vfp_esi_begin(struct worker *w, size_t estimate)
 
 	AZ(w->vgz_rx);
 	if (w->is_gzip && w->do_gunzip) {
-		w->vgz_rx = VGZ_NewUngzip(w, w->vbc->vsl_id, "U F E");
+		w->vgz_rx = VGZ_NewUngzip(w, "U F E");
 		VEP_Init(w, NULL);
 	} else if (w->is_gunzip && w->do_gzip) {
 		ALLOC_OBJ(vef, VEF_MAGIC);
@@ -310,18 +309,18 @@ vfp_esi_begin(struct worker *w, size_t estimate)
 		//vef = (void*)WS_Alloc(sp->ws, sizeof *vef);
 		//memset(vef, 0, sizeof *vef);
 		//vef->magic = VEF_MAGIC;
-		vef->vgz = VGZ_NewGzip(w, w->vbc->vsl_id, "G F E");
+		vef->vgz = VGZ_NewGzip(w, "G F E");
 		AZ(w->vef_priv);
 		w->vef_priv = vef;
 		VEP_Init(w, vfp_vep_callback);
 	} else if (w->is_gzip) {
-		w->vgz_rx = VGZ_NewUngzip(w, w->vbc->vsl_id, "U F E");
+		w->vgz_rx = VGZ_NewUngzip(w, "U F E");
 		ALLOC_OBJ(vef, VEF_MAGIC);
 		AN(vef);
 		//vef = (void*)WS_Alloc(sp->ws, sizeof *vef);
 		//memset(vef, 0, sizeof *vef);
 		//vef->magic = VEF_MAGIC;
-		vef->vgz = VGZ_NewGzip(w, w->vbc->vsl_id, "G F E");
+		vef->vgz = VGZ_NewGzip(w, "G F E");
 		AZ(w->vef_priv);
 		w->vef_priv = vef;
 		VEP_Init(w, vfp_vep_callback);
@@ -376,14 +375,14 @@ vfp_esi_end(struct worker *w)
 		VSB_delete(vsb);
 	}
 	if (w->vgz_rx != NULL)
-		VGZ_Destroy(&w->vgz_rx);
+		VGZ_Destroy(&w->vgz_rx, -1);
 
 	if (w->vef_priv != NULL) {
 		vef = w->vef_priv;
 		CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);
 		w->vef_priv = NULL;
 		VGZ_UpdateObj(vef->vgz, w->fetch_obj);
-		VGZ_Destroy(&vef->vgz);
+		VGZ_Destroy(&vef->vgz,  -1);
 		XXXAZ(vef->error);
 		FREE_OBJ(vef);
 	}
diff --git a/bin/varnishd/cache_esi_parse.c b/bin/varnishd/cache_esi_parse.c
index 24fbe8b..663894a 100644
--- a/bin/varnishd/cache_esi_parse.c
+++ b/bin/varnishd/cache_esi_parse.c
@@ -35,7 +35,6 @@
 
 #include "cache.h"
 
-#include "cache_backend.h"		// XXX: w->vbc for WSLB
 #include "cache_esi.h"
 #include "vct.h"
 #include "vend.h"
diff --git a/bin/varnishd/cache_gzip.c b/bin/varnishd/cache_gzip.c
index 01ccebc..7df69cd 100644
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -71,7 +71,6 @@
 
 #include "cache.h"
 
-#include "cache_backend.h"	// for w->vbc
 #include "vgz.h"
 
 struct vgz {
@@ -79,7 +78,6 @@ struct vgz {
 #define VGZ_MAGIC		0x162df0cb
 	enum {VGZ_GZ,VGZ_UN}	dir;
 	struct worker		*wrk;
-	int			vsl_id;
 	const char		*id;
 	struct ws		*tmp;
 	char			*tmp_snapshot;
@@ -116,7 +114,7 @@ vgz_free(voidpf opaque, voidpf address)
  */
 
 static struct vgz *
-vgz_alloc_vgz(struct worker *wrk, int vsl_id, const char *id)
+vgz_alloc_vgz(struct worker *wrk, const char *id)
 {
 	struct vgz *vg;
 	struct ws *ws;
@@ -131,7 +129,6 @@ vgz_alloc_vgz(struct worker *wrk, int vsl_id, const char *id)
 	memset(vg, 0, sizeof *vg);
 	vg->magic = VGZ_MAGIC;
 	vg->wrk = wrk;
-	vg->vsl_id = vsl_id;
 	vg->id = id;
 
 	switch (params->gzip_tmp_space) {
@@ -153,12 +150,12 @@ vgz_alloc_vgz(struct worker *wrk, int vsl_id, const char *id)
 }
 
 struct vgz *
-VGZ_NewUngzip(struct worker *wrk, int vsl_id, const char *id)
+VGZ_NewUngzip(struct worker *wrk, const char *id)
 {
 	struct vgz *vg;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
-	vg = vgz_alloc_vgz(wrk, vsl_id, id);
+	vg = vgz_alloc_vgz(wrk, id);
 	vg->dir = VGZ_UN;
 	VSC_C_main->n_gunzip++;
 
@@ -173,13 +170,13 @@ VGZ_NewUngzip(struct worker *wrk, int vsl_id, const char *id)
 }
 
 struct vgz *
-VGZ_NewGzip(struct worker *wrk, int vsl_id, const char *id)
+VGZ_NewGzip(struct worker *wrk, const char *id)
 {
 	struct vgz *vg;
 	int i;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
-	vg = vgz_alloc_vgz(wrk, vsl_id, id);
+	vg = vgz_alloc_vgz(wrk, id);
 	vg->dir = VGZ_GZ;
 	VSC_C_main->n_gzip++;
 
@@ -404,10 +401,12 @@ VGZ_UpdateObj(const struct vgz *vg, struct object *obj)
 	obj->gzip_stop	= vg->vz.stop_bit;
 }
 
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Passing a vsl_id of -1 means "use w->vbc->vsl_id"
+ */
 
 void
-VGZ_Destroy(struct vgz **vgp)
+VGZ_Destroy(struct vgz **vgp, int vsl_id)
 {
 	struct vgz *vg;
 	const char *err;
@@ -416,13 +415,22 @@ VGZ_Destroy(struct vgz **vgp)
 	CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
 	*vgp = NULL;
 
-	WSL(vg->wrk, SLT_Gzip, vg->vsl_id, "%s %jd %jd %jd %jd %jd",
-	    vg->id,
-	    (intmax_t)vg->vz.total_in,
-	    (intmax_t)vg->vz.total_out,
-	    (intmax_t)vg->vz.start_bit,
-	    (intmax_t)vg->vz.last_bit,
-	    (intmax_t)vg->vz.stop_bit);
+	if (vsl_id < 0)
+		WSLB(vg->wrk, SLT_Gzip, "%s %jd %jd %jd %jd %jd",
+		    vg->id,
+		    (intmax_t)vg->vz.total_in,
+		    (intmax_t)vg->vz.total_out,
+		    (intmax_t)vg->vz.start_bit,
+		    (intmax_t)vg->vz.last_bit,
+		    (intmax_t)vg->vz.stop_bit);
+	else
+		WSL(vg->wrk, SLT_Gzip, vsl_id, "%s %jd %jd %jd %jd %jd",
+		    vg->id,
+		    (intmax_t)vg->vz.total_in,
+		    (intmax_t)vg->vz.total_out,
+		    (intmax_t)vg->vz.start_bit,
+		    (intmax_t)vg->vz.last_bit,
+		    (intmax_t)vg->vz.stop_bit);
 	err = vg->error;
 	if (vg->tmp != NULL)
 		WS_Reset(vg->tmp, vg->tmp_snapshot);
@@ -444,7 +452,7 @@ vfp_gunzip_begin(struct worker *w, size_t estimate)
 {
 	(void)estimate;
 	AZ(w->vgz_rx);
-	w->vgz_rx = VGZ_NewUngzip(w, w->vbc->vsl_id, "U F -");
+	w->vgz_rx = VGZ_NewUngzip(w, "U F -");
 }
 
 static int __match_proto__()
@@ -497,7 +505,7 @@ vfp_gunzip_end(struct worker *w)
 	vg = w->vgz_rx;
 	w->vgz_rx = NULL;
 	CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
-	VGZ_Destroy(&vg);
+	VGZ_Destroy(&vg, -1);
 	return (0);
 }
 
@@ -520,7 +528,7 @@ vfp_gzip_begin(struct worker *w, size_t estimate)
 	(void)estimate;
 
 	AZ(w->vgz_rx);
-	w->vgz_rx = VGZ_NewGzip(w, w->vbc->vsl_id, "G F -");
+	w->vgz_rx = VGZ_NewGzip(w, "G F -");
 }
 
 static int __match_proto__()
@@ -583,7 +591,7 @@ vfp_gzip_end(struct worker *w)
 			RES_StreamPoll(w);
 		VGZ_UpdateObj(vg, w->fetch_obj);
 	}
-	VGZ_Destroy(&vg);
+	VGZ_Destroy(&vg, -1);
 	return (0);
 }
 
@@ -604,7 +612,7 @@ static void __match_proto__()
 vfp_testgzip_begin(struct worker *w, size_t estimate)
 {
 	(void)estimate;
-	w->vgz_rx = VGZ_NewUngzip(w, w->vbc->vsl_id, "u F -");
+	w->vgz_rx = VGZ_NewUngzip(w, "u F -");
 	CHECK_OBJ_NOTNULL(w->vgz_rx, VGZ_MAGIC);
 }
 
@@ -673,7 +681,7 @@ vfp_testgzip_end(struct worker *w)
 	w->vgz_rx = NULL;
 	CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
 	VGZ_UpdateObj(vg, w->fetch_obj);
-	VGZ_Destroy(&vg);
+	VGZ_Destroy(&vg, -1);
 	return (0);
 }
 
diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c
index 569f24f..84606b6 100644
--- a/bin/varnishd/cache_response.c
+++ b/bin/varnishd/cache_response.c
@@ -162,7 +162,7 @@ res_WriteGunzipObj(const struct sess *sp)
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 
-	vg = VGZ_NewUngzip(sp->wrk, sp->vsl_id, "U D -");
+	vg = VGZ_NewUngzip(sp->wrk, "U D -");
 
 	VGZ_Obuf(vg, obuf, sizeof obuf);
 	VTAILQ_FOREACH(st, &sp->obj->store, list) {
@@ -182,7 +182,7 @@ res_WriteGunzipObj(const struct sess *sp)
 		(void)WRW_Write(sp->wrk, obuf, obufl);
 		(void)WRW_Flush(sp->wrk);
 	}
-	VGZ_Destroy(&vg);
+	VGZ_Destroy(&vg, sp->vsl_id);
 	assert(u == sp->obj->len);
 }
 
diff --git a/bin/varnishd/cache_shmlog.c b/bin/varnishd/cache_shmlog.c
index da39e2d..5601463 100644
--- a/bin/varnishd/cache_shmlog.c
+++ b/bin/varnishd/cache_shmlog.c
@@ -33,6 +33,8 @@
 
 #include "cache.h"
 
+#include "cache_backend.h"	// For w->vbc
+
 #include "vapi/vsm_int.h"
 #include "vmb.h"
 #include "vtim.h"
@@ -229,16 +231,14 @@ WSLR(struct worker *w, enum VSL_tag_e tag, int id, txt t)
 
 /*--------------------------------------------------------------------*/
 
-void
-WSL(struct worker *w, enum VSL_tag_e tag, int id, const char *fmt, ...)
+static void
+wsl(struct worker *w, enum VSL_tag_e tag, int id, const char *fmt, va_list ap)
 {
-	va_list ap;
 	char *p;
 	unsigned n, mlen;
 	txt t;
 
 	AN(fmt);
-	va_start(ap, fmt);
 	mlen = params->shm_reclen;
 
 	if (strchr(fmt, '%') == NULL) {
@@ -261,7 +261,6 @@ WSL(struct worker *w, enum VSL_tag_e tag, int id, const char *fmt, ...)
 		assert(w->wlp < w->wle);
 		w->wlr++;
 	}
-	va_end(ap);
 	if (params->diag_bitmap & 0x10000)
 		WSL_Flush(w, 0);
 }
@@ -269,6 +268,36 @@ WSL(struct worker *w, enum VSL_tag_e tag, int id, const char *fmt, ...)
 /*--------------------------------------------------------------------*/
 
 void
+WSL(struct worker *w, enum VSL_tag_e tag, int id, const char *fmt, ...)
+{
+	va_list ap;
+
+	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
+	AN(fmt);
+	va_start(ap, fmt);
+	wsl(w, tag, id, fmt, ap);
+	va_end(ap);
+}
+
+
+/*--------------------------------------------------------------------*/
+
+void
+WSLB(struct worker *w, enum VSL_tag_e tag, const char *fmt, ...)
+{
+	va_list ap;
+
+	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(w->vbc, VBC_MAGIC);
+	AN(fmt);
+	va_start(ap, fmt);
+	wsl(w, tag, w->vbc->vsl_id, fmt, ap);
+	va_end(ap);
+}
+
+/*--------------------------------------------------------------------*/
+
+void
 VSL_Init(void)
 {
 	struct VSM_chunk *vsc;



More information about the varnish-commit mailing list