[master] c613a53 Make range and gunzip VDP's manage their own private data.

Poul-Henning Kamp phk at FreeBSD.org
Tue Oct 21 23:37:08 CEST 2014


commit c613a535a05338e4f56d858e4058c1abf9e65f71
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Oct 21 21:36:51 2014 +0000

    Make range and gunzip VDP's manage their own private data.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 01d3ce8..4031ada 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -619,14 +619,6 @@ struct req {
 	void			*vdpp[N_VDPS];
 	int			vdp_nxt;
 
-	/* Range */
-	ssize_t			range_low;
-	ssize_t			range_high;
-	ssize_t			range_off;
-
-	/* Gunzip */
-	struct vgz		*vgz;
-
 	/* Transaction VSL buffer */
 	struct vsl_log		vsl[1];
 
@@ -766,13 +758,13 @@ VDP_bytes(struct req *req, enum vdp_action act, const void *ptr, ssize_t len)
 	/* Call the present layer, while pointing to the next layer down */
 	i = req->vdp_nxt--;
 	assert(i >= 0 && i < N_VDPS);
-	retval = req->vdps[i](req, act, req->vdpp[i], ptr, len);
+	retval = req->vdps[i](req, act, &req->vdpp[i], ptr, len);
 	req->vdp_nxt++;
 	return (retval);
 }
 
 static inline void
-VDP_push(struct req *req, vdp_bytes *func)
+VDP_push(struct req *req, vdp_bytes *func, void *priv)
 {
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	AN(func);
@@ -781,7 +773,7 @@ VDP_push(struct req *req, vdp_bytes *func)
 	assert(req->vdp_nxt >= 0);
 	assert(req->vdp_nxt + 1 < N_VDPS);
 	req->vdps[++req->vdp_nxt] = func;
-	req->vdpp[req->vdp_nxt] = NULL;
+	req->vdpp[req->vdp_nxt] = priv;
 	AZ(req->vdps[req->vdp_nxt](req, VDP_INIT,
 	   &req->vdpp[req->vdp_nxt], NULL, 0));
 }
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index a126b53..7c347b8 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -206,7 +206,7 @@ ved_decode_len(uint8_t **pp)
  */
 
 int __match_proto__(vdp_bytes)
-VED_pretend_gzip(struct req *req, enum vdp_action act, void *priv,
+VED_pretend_gzip(struct req *req, enum vdp_action act, void **priv,
     const void *pv, ssize_t l)
 {
 	uint8_t buf1[5], buf2[5];
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
index 9377a89..b2e1ddd 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -78,5 +78,5 @@ enum vdp_action {
 	VDP_FINISH,
 	VDP_FINI,
 };
-typedef int vdp_bytes(struct req *, enum vdp_action, void *priv,
+typedef int vdp_bytes(struct req *, enum vdp_action, void **priv,
     const void *ptr, ssize_t len);
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 9e437bb..2087c00 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -285,7 +285,7 @@ VGZ_WrwInit(struct vgz *vg)
  */
 
 int __match_proto__(vdp_bytes)
-VDP_gunzip(struct req *req, enum vdp_action act, void *priv,
+VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
     const void *ptr, ssize_t len)
 {
 	enum vgzret_e vr;
@@ -297,11 +297,19 @@ VDP_gunzip(struct req *req, enum vdp_action act, void *priv,
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	wrk = req->wrk;
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
-	(void)priv;
-	if (act == VDP_INIT || act == VDP_FINI)
+	if (act == VDP_INIT) {
+		vg = VGZ_NewUngzip(req->vsl, "U D -");
+		AN(vg);
+		AZ(VGZ_WrwInit(vg));
+		*priv = vg;
 		return (0);
-	vg = req->vgz;
-	CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
+	}
+	CAST_OBJ_NOTNULL(vg, *priv, VGZ_MAGIC);
+	if (act == VDP_FINI) {
+		(void)VGZ_Destroy(&vg);
+		*priv = NULL;
+		return (0);
+	}
 	AN(vg->m_buf);
 
 	if (len == 0) {
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index b744350..3ab930e 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -36,7 +36,7 @@
 /*--------------------------------------------------------------------*/
 
 static int __match_proto__(vdp_bytes)
-v1d_bytes(struct req *req, enum vdp_action act, void *priv,
+v1d_bytes(struct req *req, enum vdp_action act, void **priv,
     const void *ptr, ssize_t len)
 {
 	ssize_t wl = 0;
@@ -60,43 +60,58 @@ v1d_bytes(struct req *req, enum vdp_action act, void *priv,
 
 /*--------------------------------------------------------------------*/
 
+struct v1rp {
+	unsigned		magic;
+#define V1RP_MAGIC		0xb886e711
+	ssize_t			range_low;
+	ssize_t			range_high;
+	ssize_t			range_off;
+};
+
 static int __match_proto__(vdp_bytes)
-v1d_range_bytes(struct req *req, enum vdp_action act, void *priv,
+v1d_range_bytes(struct req *req, enum vdp_action act, void **priv,
     const void *ptr, ssize_t len)
 {
 	int retval = 0;
 	ssize_t l;
 	const char *p = ptr;
+	struct v1rp *v1rp;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	(void)priv;
-	if (act == VDP_INIT || act == VDP_FINI)
+	if (act == VDP_INIT)
 		return (0);
-	l = req->range_low - req->range_off;
+	if (act == VDP_FINI) {
+		*priv = NULL;
+		return (0);
+	}
+	CAST_OBJ_NOTNULL(v1rp, *priv, V1RP_MAGIC);
+	l = v1rp->range_low - v1rp->range_off;
 	if (l > 0) {
 		if (l > len)
 			l = len;
-		req->range_off += l;
+		v1rp->range_off += l;
 		p += l;
 		len -= l;
 	}
-	l = req->range_high - req->range_off;
+	l = v1rp->range_high - v1rp->range_off;
 	if (l > len)
 		l = len;
 	if (l > 0)
 		retval = VDP_bytes(req, act, p, l);
 	else if (act > VDP_NULL)
 		retval = VDP_bytes(req, act, p, 0);
-	req->range_off += len;
+	v1rp->range_off += len;
 	return (retval);
 }
 
 /*--------------------------------------------------------------------*/
 
+
 static void
 v1d_dorange(struct req *req, struct busyobj *bo, const char *r)
 {
 	ssize_t len, low, high, has_low;
+	struct v1rp *v1rp;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
@@ -163,10 +178,14 @@ v1d_dorange(struct req *req, struct busyobj *bo, const char *r)
 		    (intmax_t)(1 + high - low));
 	http_PutResponse(req->resp, "HTTP/1.1", 206, NULL);
 
-	req->range_off = 0;
-	req->range_low = low;
-	req->range_high = high + 1;
-	VDP_push(req, v1d_range_bytes);
+	v1rp = WS_Alloc(req->ws, sizeof *v1rp);
+	XXXAN(v1rp);
+	memset(v1rp, 0, sizeof *v1rp);
+	v1rp->magic = V1RP_MAGIC;
+	v1rp->range_off = 0;
+	v1rp->range_low = low;
+	v1rp->range_high = high + 1;
+	VDP_push(req, v1d_range_bytes, v1rp);
 }
 
 /*--------------------------------------------------------------------*/
@@ -349,7 +368,7 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 		ESI_Deliver(req);
 	} else if (req->res_mode & RES_ESI_CHILD && req->gzip_resp &&
 	    !ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED)) {
-		VDP_push(req, VED_pretend_gzip);
+		VDP_push(req, VED_pretend_gzip, NULL);
 		ois = v1d_WriteDirObj(req);
 		VDP_pop(req, VED_pretend_gzip);
 	} else if (req->res_mode & RES_ESI_CHILD && req->gzip_resp) {
@@ -360,11 +379,8 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 	    (req->res_mode & RES_ESI_CHILD &&
 	    !req->gzip_resp &&
 	    ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED))) {
-		VDP_push(req, VDP_gunzip);
-		req->vgz = VGZ_NewUngzip(req->vsl, "U D -");
-		AZ(VGZ_WrwInit(req->vgz));
+		VDP_push(req, VDP_gunzip, NULL);
 		ois = v1d_WriteDirObj(req);
-		(void)VGZ_Destroy(&req->vgz);
 		VDP_pop(req, VDP_gunzip);
 	} else {
 		ois = v1d_WriteDirObj(req);



More information about the varnish-commit mailing list