[master] 9765f1a Downgrade ESI parse from using struct sess to struct worker.

Poul-Henning Kamp phk at varnish-cache.org
Mon Oct 24 15:41:32 CEST 2011


commit 9765f1a846461820e8bcc628c1d1a1f843f4cf39
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Oct 24 13:41:06 2011 +0000

    Downgrade ESI parse from using struct sess to struct worker.

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 46d4067..298f820 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -717,7 +717,7 @@ 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);
 int VGZ_ObufFull(const struct vgz *vg);
-int VGZ_ObufStorage(const struct sess *sp, 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 **);
@@ -863,6 +863,13 @@ 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 WSL_Flush(struct worker *w, int overflow);
 
 #define DSL(flag, tag, id, ...)					\
diff --git a/bin/varnishd/cache_esi.h b/bin/varnishd/cache_esi.h
index 4110687..ff84d41 100644
--- a/bin/varnishd/cache_esi.h
+++ b/bin/varnishd/cache_esi.h
@@ -39,11 +39,10 @@
 #define	VEC_S8	(0x60 + 8)
 #define	VEC_INCL	'I'
 
-typedef ssize_t vep_callback_t(const struct sess *sp,
-    ssize_t l, enum vgz_flag flg);
+typedef ssize_t vep_callback_t(struct worker *w, ssize_t l, enum vgz_flag flg);
 
-void VEP_Init(const struct sess *sp, vep_callback_t *cb);
-void VEP_parse(const struct sess *sp, const char *p, size_t l);
-struct vsb *VEP_Finish(const struct sess *sp);
+void VEP_Init(struct worker *w, vep_callback_t *cb);
+void VEP_Parse(const struct worker *w, const char *p, size_t l);
+struct vsb *VEP_Finish(struct worker *w);
 
 
diff --git a/bin/varnishd/cache_esi_fetch.c b/bin/varnishd/cache_esi_fetch.c
index 00c7432..fab6513 100644
--- a/bin/varnishd/cache_esi_fetch.c
+++ b/bin/varnishd/cache_esi_fetch.c
@@ -78,7 +78,7 @@ vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 		    st->ptr + st->len, st->space - st->len, bytes);
 		if (w <= 0)
 			return (w);
-		VEP_parse(sp, (const char *)st->ptr + st->len, w);
+		VEP_Parse(sp->wrk, (const char *)st->ptr + st->len, w);
 		st->len += w;
 		sp->obj->len += w;
 		bytes -= w;
@@ -111,11 +111,11 @@ vfp_esi_bytes_gu(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 			VGZ_Ibuf(vg, ibuf, w);
 			bytes -= w;
 		}
-		if (VGZ_ObufStorage(sp, vg))
+		if (VGZ_ObufStorage(sp->wrk, vg))
 			return (-1);
 		i = VGZ_Gunzip(vg, &dp, &dl);
 		xxxassert(i == VGZ_OK || i == VGZ_END);
-		VEP_parse(sp, dp, dl);
+		VEP_Parse(sp->wrk, dp, dl);
 		sp->obj->len += dl;
 	}
 	return (1);
@@ -141,15 +141,15 @@ struct vef_priv {
  */
 
 static ssize_t
-vfp_vep_callback(const struct sess *sp, ssize_t l, enum vgz_flag flg)
+vfp_vep_callback(struct worker *w, ssize_t l, enum vgz_flag flg)
 {
 	struct vef_priv *vef;
 	size_t dl, px;
 	const void *dp;
 	int i;
 
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	vef = sp->wrk->vef_priv;
+	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
+	vef = w->vef_priv;
 	CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);
 	assert(l >= 0);
 
@@ -179,14 +179,14 @@ vfp_vep_callback(const struct sess *sp, ssize_t l, enum vgz_flag flg)
 			l = 0;
 		}
 		do {
-			if (VGZ_ObufStorage(sp, vef->vgz)) {
+			if (VGZ_ObufStorage(w, vef->vgz)) {
 				vef->error = errno;
 				vef->tot += l;
 				return (vef->tot);
 			}
 			i = VGZ_Gzip(vef->vgz, &dp, &dl, flg);
 			vef->tot += dl;
-			sp->obj->len += dl;
+			w->fetch_obj->len += dl;
 		} while (!VGZ_IbufEmpty(vef->vgz) ||
 		    (flg != VGZ_NORMAL && VGZ_ObufFull(vef->vgz)));
 		if (px != 0) {
@@ -219,7 +219,7 @@ vfp_esi_bytes_ug(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 			return (w);
 		bytes -= w;
 		vef->bufp = ibuf;
-		VEP_parse(sp, ibuf, w);
+		VEP_Parse(sp->wrk, ibuf, w);
 		assert(vef->bufp >= ibuf && vef->bufp <= ibuf + w);
 		if (vef->error) {
 			errno = vef->error;
@@ -271,7 +271,7 @@ vfp_esi_bytes_gg(struct sess *sp, struct http_conn *htc, size_t bytes)
 			assert(i >= VGZ_OK);
 			vef->bufp = ibuf2;
 			if (dl > 0)
-				VEP_parse(sp, ibuf2, dl);
+				VEP_Parse(sp->wrk, ibuf2, dl);
 			if (vef->error) {
 				errno = vef->error;
 				return (-1);
@@ -302,7 +302,7 @@ vfp_esi_begin(struct sess *sp, size_t estimate)
 	AZ(sp->wrk->vgz_rx);
 	if (sp->wrk->is_gzip && sp->wrk->do_gunzip) {
 		sp->wrk->vgz_rx = VGZ_NewUngzip(sp->wrk, sp->vsl_id, "U F E");
-		VEP_Init(sp, NULL);
+		VEP_Init(sp->wrk, NULL);
 	} else if (sp->wrk->is_gunzip && sp->wrk->do_gzip) {
 		ALLOC_OBJ(vef, VEF_MAGIC);
 		AN(vef);
@@ -312,7 +312,7 @@ vfp_esi_begin(struct sess *sp, size_t estimate)
 		vef->vgz = VGZ_NewGzip(sp->wrk, sp->vsl_id, "G F E");
 		AZ(sp->wrk->vef_priv);
 		sp->wrk->vef_priv = vef;
-		VEP_Init(sp, vfp_vep_callback);
+		VEP_Init(sp->wrk, vfp_vep_callback);
 	} else if (sp->wrk->is_gzip) {
 		sp->wrk->vgz_rx = VGZ_NewUngzip(sp->wrk, sp->vsl_id, "U F E");
 		ALLOC_OBJ(vef, VEF_MAGIC);
@@ -323,10 +323,10 @@ vfp_esi_begin(struct sess *sp, size_t estimate)
 		vef->vgz = VGZ_NewGzip(sp->wrk, sp->vsl_id, "G F E");
 		AZ(sp->wrk->vef_priv);
 		sp->wrk->vef_priv = vef;
-		VEP_Init(sp, vfp_vep_callback);
+		VEP_Init(sp->wrk, vfp_vep_callback);
 	} else {
 		AZ(sp->wrk->vef_priv);
-		VEP_Init(sp, NULL);
+		VEP_Init(sp->wrk, NULL);
 	}
 
 	(void)estimate;
@@ -362,7 +362,7 @@ vfp_esi_end(struct sess *sp)
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	AN(sp->wrk->vep);
 
-	vsb = VEP_Finish(sp);
+	vsb = VEP_Finish(sp->wrk);
 
 	if (vsb != NULL) {
 		l = VSB_len(vsb);
diff --git a/bin/varnishd/cache_esi_parse.c b/bin/varnishd/cache_esi_parse.c
index 37c20e7..24fbe8b 100644
--- a/bin/varnishd/cache_esi_parse.c
+++ b/bin/varnishd/cache_esi_parse.c
@@ -35,6 +35,7 @@
 
 #include "cache.h"
 
+#include "cache_backend.h"		// XXX: w->vbc for WSLB
 #include "cache_esi.h"
 #include "vct.h"
 #include "vend.h"
@@ -60,7 +61,7 @@ struct vep_state {
 #define VEP_MAGIC		0x55cb9b82
 	struct vsb		*vsb;
 
-	const struct sess	*sp;
+	struct worker		*wrk;
 	int			dogzip;
 	vep_callback_t		*cb;
 
@@ -186,7 +187,7 @@ vep_error(const struct vep_state *vep, const char *p)
 
 	VSC_C_main->esi_errors++;
 	l = (intmax_t)(vep->ver_p - vep->hack_p);
-	WSP(vep->sp, SLT_ESI_xmlerror, "ERR at %jd %s", l, p);
+	WSLB(vep->wrk, SLT_ESI_xmlerror, "ERR at %jd %s", l, p);
 
 }
 
@@ -202,7 +203,7 @@ vep_warn(const struct vep_state *vep, const char *p)
 	VSC_C_main->esi_warnings++;
 	l = (intmax_t)(vep->ver_p - vep->hack_p);
 	printf("WARNING at %jd %s\n", l, p);
-	WSP(vep->sp, SLT_ESI_xmlerror, "WARN at %jd %s", l, p);
+	WSLB(vep->wrk, SLT_ESI_xmlerror, "WARN at %jd %s", l, p);
 
 }
 
@@ -328,7 +329,7 @@ vep_mark_common(struct vep_state *vep, const char *p, enum vep_mark mark)
 	 */
 
 	if (vep->last_mark != mark && (vep->o_wait > 0 || vep->startup)) {
-		lcb = vep->cb(vep->sp, 0,
+		lcb = vep->cb(vep->wrk, 0,
 		    mark == VERBATIM ? VGZ_RESET : VGZ_ALIGN);
 		if (lcb - vep->o_last > 0)
 			vep_emit_common(vep, lcb - vep->o_last, vep->last_mark);
@@ -338,7 +339,7 @@ vep_mark_common(struct vep_state *vep, const char *p, enum vep_mark mark)
 
 	/* Transfer pending bytes CRC into active mode CRC */
 	if (vep->o_pending) {
-		(void)vep->cb(vep->sp, vep->o_pending, VGZ_NORMAL);
+		(void)vep->cb(vep->wrk, vep->o_pending, VGZ_NORMAL);
 		if (vep->o_crc == 0) {
 			vep->crc = vep->crcp;
 			vep->o_crc = vep->o_pending;
@@ -362,7 +363,7 @@ vep_mark_common(struct vep_state *vep, const char *p, enum vep_mark mark)
 
 	vep->o_wait += l;
 	vep->last_mark = mark;
-	(void)vep->cb(vep->sp, l, VGZ_NORMAL);
+	(void)vep->cb(vep->wrk, l, VGZ_NORMAL);
 }
 
 static void
@@ -499,7 +500,7 @@ vep_do_include(struct vep_state *vep, enum dowhat what)
 		VSB_printf(vep->vsb, "%c", 0);
 	} else {
 		VSB_printf(vep->vsb, "%c", 0);
-		url = vep->sp->wrk->bereq->hd[HTTP_HDR_URL];
+		url = vep->wrk->bereq->hd[HTTP_HDR_URL];
 		/* Look for the last / before a '?' */
 		h = NULL;
 		for (q = url.b; q < url.e && *q != '?'; q++)
@@ -548,15 +549,15 @@ vep_do_include(struct vep_state *vep, enum dowhat what)
  */
 
 void
-VEP_parse(const struct sess *sp, const char *p, size_t l)
+VEP_Parse(const struct worker *w, const char *p, size_t l)
 {
 	struct vep_state *vep;
 	const char *e;
 	struct vep_match *vm;
 	int i;
 
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	vep = sp->wrk->vep;
+	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
+	vep = w->vep;
 	CHECK_OBJ_NOTNULL(vep, VEP_MAGIC);
 	assert(l > 0);
 
@@ -601,7 +602,7 @@ VEP_parse(const struct sess *sp, const char *p, size_t l)
 				p++;
 				vep->state = VEP_STARTTAG;
 			} else if (p < e) {
-				WSP(vep->sp, SLT_ESI_xmlerror,
+				WSLB(vep->wrk, SLT_ESI_xmlerror,
 				    "No ESI processing, first char not '<'");
 				vep->state = VEP_NOTXML;
 			}
@@ -978,33 +979,34 @@ VEP_parse(const struct sess *sp, const char *p, size_t l)
 /*---------------------------------------------------------------------
  */
 
-static ssize_t
-vep_default_cb(const struct sess *sp, ssize_t l, enum vgz_flag flg)
+static ssize_t __match_proto__()
+vep_default_cb(struct worker *w, ssize_t l, enum vgz_flag flg)
 {
 
 	(void)flg;
-	AN(sp->wrk->vep);
-	sp->wrk->vep->cb_x += l;
-Debug("CB(%jd,%d) = %jd\n", (intmax_t)l, flg, (intmax_t)sp->wrk->vep->cb_x);
-	return (sp->wrk->vep->cb_x);
+	AN(w->vep);
+	w->vep->cb_x += l;
+Debug("CB(%jd,%d) = %jd\n", (intmax_t)l, flg, (intmax_t)w->vep->cb_x);
+	return (w->vep->cb_x);
 }
 
 /*---------------------------------------------------------------------
  */
 
 void
-VEP_Init(const struct sess *sp, vep_callback_t *cb)
+VEP_Init(struct worker *w, vep_callback_t *cb)
 {
 	struct vep_state *vep;
 
-	AZ(sp->wrk->vep);
-	sp->wrk->vep = (void*)WS_Alloc(sp->wrk->ws, sizeof *vep);
-	AN(sp->wrk->vep);
+	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
+	AZ(w->vep);
+	w->vep = (void*)WS_Alloc(w->ws, sizeof *vep);
+	AN(w->vep);
 
-	vep = sp->wrk->vep;
+	vep = w->vep;
 	memset(vep, 0, sizeof *vep);
 	vep->magic = VEP_MAGIC;
-	vep->sp = sp;
+	vep->wrk = w;
 	vep->vsb = VSB_new_auto();
 	AN(vep->vsb);
 
@@ -1037,24 +1039,24 @@ VEP_Init(const struct sess *sp, vep_callback_t *cb)
  */
 
 struct vsb *
-VEP_Finish(const struct sess *sp)
+VEP_Finish(struct worker *w)
 {
 	struct vep_state *vep;
 	ssize_t l, lcb;
 
-	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	vep = sp->wrk->vep;
+	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
+	vep = w->vep;
 	CHECK_OBJ_NOTNULL(vep, VEP_MAGIC);
 
 	if (vep->o_pending)
 		vep_mark_common(vep, vep->ver_p, vep->last_mark);
 	if (vep->o_wait > 0) {
-		lcb = vep->cb(vep->sp, 0, VGZ_ALIGN);
+		lcb = vep->cb(vep->wrk, 0, VGZ_ALIGN);
 		vep_emit_common(vep, lcb - vep->o_last, vep->last_mark);
 	}
-	(void)vep->cb(vep->sp, 0, VGZ_FINISH);
+	(void)vep->cb(vep->wrk, 0, VGZ_FINISH);
 
-	sp->wrk->vep = NULL;
+	w->vep = NULL;
 
 	AZ(VSB_finish(vep->vsb));
 	l = VSB_len(vep->vsb);
diff --git a/bin/varnishd/cache_gzip.c b/bin/varnishd/cache_gzip.c
index e40676c..68dc04b 100644
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -255,11 +255,11 @@ VGZ_ObufFull(const struct vgz *vg)
  */
 
 int
-VGZ_ObufStorage(const struct sess *sp, struct vgz *vg)
+VGZ_ObufStorage(struct worker *w, struct vgz *vg)
 {
 	struct storage *st;
 
-	st = FetchStorage(sp->wrk, 0);
+	st = FetchStorage(w, 0);
 	if (st == NULL)
 		return (-1);
 
@@ -466,7 +466,7 @@ vfp_gunzip_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 			bytes -= w;
 		}
 
-		if (VGZ_ObufStorage(sp, vg)) {
+		if (VGZ_ObufStorage(sp->wrk, vg)) {
 			htc->error = "Could not get storage";
 			return (-1);
 		}
@@ -541,7 +541,7 @@ vfp_gzip_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 			VGZ_Ibuf(vg, ibuf, w);
 			bytes -= w;
 		}
-		if (VGZ_ObufStorage(sp, vg)) {
+		if (VGZ_ObufStorage(sp->wrk, vg)) {
 			htc->error = "Could not get storage";
 			return (-1);
 		}
@@ -567,7 +567,7 @@ vfp_gzip_end(struct sess *sp)
 	CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
 	do {
 		VGZ_Ibuf(vg, "", 0);
-		if (VGZ_ObufStorage(sp, vg))
+		if (VGZ_ObufStorage(sp->wrk, vg))
 			return (-1);
 		i = VGZ_Gzip(vg, &dp, &dl, VGZ_FINISH);
 		sp->obj->len += dl;



More information about the varnish-commit mailing list