[master] eaebe01 Untangle the esi delivery and make it almost a set of plain VDPs.
Poul-Henning Kamp
phk at FreeBSD.org
Wed Oct 22 02:05:14 CEST 2014
commit eaebe011b5ac0aceb841a929d26cc5f464613492
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Oct 22 00:04:47 2014 +0000
Untangle the esi delivery and make it almost a set of plain VDPs.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index bcf2903..63fbcf4 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -781,7 +781,7 @@ enum vgzret_e {
};
enum vgz_flag { VGZ_NORMAL, VGZ_ALIGN, VGZ_RESET, VGZ_FINISH };
-struct vgz *VGZ_NewUngzip(struct vsl_log *vsl, const char *id);
+// struct vgz *VGZ_NewUngzip(struct vsl_log *vsl, const char *id);
struct vgz *VGZ_NewGzip(struct vsl_log *vsl, const char *id);
void VGZ_Ibuf(struct vgz *, const void *, ssize_t len);
int VGZ_IbufEmpty(const struct vgz *vg);
@@ -789,15 +789,10 @@ void VGZ_Obuf(struct vgz *, void *, ssize_t len);
int VGZ_ObufFull(const struct vgz *vg);
enum vgzret_e VGZ_Gzip(struct vgz *, const void **, ssize_t *len,
enum vgz_flag);
-enum vgzret_e VGZ_Gunzip(struct vgz *, const void **, ssize_t *len);
+// enum vgzret_e VGZ_Gunzip(struct vgz *, const void **, ssize_t *len);
enum vgzret_e VGZ_Destroy(struct vgz **);
void VGZ_UpdateObj(const struct vfp_ctx *, const struct vgz*);
-int VGZ_WrwInit(struct vgz *vg);
-enum vgzret_e VGZ_WrwGunzip(struct req *, struct vgz *, const void *ibuf,
- ssize_t ibufl);
-void VGZ_WrwFlush(struct req *, struct vgz *vg);
-
/* cache_http.c */
unsigned HTTP_estimate(unsigned nhttp);
void HTTP_Copy(struct http *to, const struct http * const fm);
@@ -958,7 +953,6 @@ void Pool_Sumstat(struct worker *w);
void Pool_PurgeStat(unsigned nobj);
#define WRW_IsReleased(w) ((w)->wrw == NULL)
-int WRW_Error(const struct worker *w);
void WRW_Chunked(const struct worker *w);
void WRW_EndChunk(const struct worker *w);
void WRW_Reserve(struct worker *w, int *fd, struct vsl_log *, double t0);
diff --git a/bin/varnishd/cache/cache_deliver_proc.c b/bin/varnishd/cache/cache_deliver_proc.c
index 921ea65..1346898 100644
--- a/bin/varnishd/cache/cache_deliver_proc.c
+++ b/bin/varnishd/cache/cache_deliver_proc.c
@@ -67,7 +67,7 @@ VDP_push(struct req *req, vdp_bytes *func, void *priv)
VTAILQ_INSERT_HEAD(&req->vdp, vdp, list);
req->vdp_nxt = vdp;
- AZ(func(req, VDP_INIT, &vdp->priv, NULL, 0));
+ AZ(vdp->func(req, VDP_INIT, &vdp->priv, NULL, 0));
}
void
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 056db1e..06e2570 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -111,6 +111,10 @@ ved_include(struct req *preq, const char *src, const char *host)
req->crc = preq->crc;
req->l_crc = preq->l_crc;
+
+ req->vdp = preq->vdp;
+ req->vdp_nxt = preq->vdp_nxt;
+
THR_SetRequest(req);
VSLb_ts_req(req, "Start", W_TIM_real(wrk));
@@ -267,10 +271,6 @@ ESI_Deliver(struct req *req)
uint32_t icrc = 0;
uint8_t tailbuf[8 + 5];
int isgzip;
- struct vgz *vgz = NULL;
- ssize_t dl;
- const void *dp;
- int i;
void *oi;
enum objiter_status ois;
void *sp;
@@ -296,7 +296,7 @@ ESI_Deliver(struct req *req)
* Only the top level document gets to decide this.
*/
req->gzip_resp = 0;
- if (isgzip && !(req->res_mode & RES_GUNZIP)) {
+ if (isgzip) {
assert(sizeof gzip_hdr == 10);
/* Send out the gzip header */
(void)VDP_bytes(req, VDP_NULL, gzip_hdr, 10);
@@ -306,18 +306,6 @@ ESI_Deliver(struct req *req)
}
}
- if (isgzip && !req->gzip_resp) {
- vgz = VGZ_NewUngzip(req->vsl, "U D E");
- AZ(VGZ_WrwInit(vgz));
-
- /* Feed a gzip header to gunzip to make it happy */
- VGZ_Ibuf(vgz, gzip_hdr, sizeof gzip_hdr);
- i = VGZ_Gunzip(vgz, &dp, &dl);
- assert(i == VGZ_OK);
- assert(VGZ_IbufEmpty(vgz));
- AZ(dl);
- }
-
oi = ObjIterBegin(req->wrk, req->objcore);
ois = ObjIter(req->objcore, oi, &sp, &sl);
assert(ois != OIS_ERROR);
@@ -366,24 +354,7 @@ ESI_Deliver(struct req *req)
*/
(void)VED_pretend_gzip(req, VDP_NULL,
NULL, pp, l2);
- } else if (isgzip) {
- /*
- * A gzip'ed VEC, but ungzip'ed ESI
- * response
- */
- AN(vgz);
- i = VGZ_WrwGunzip(req, vgz, pp, l2);
- if (WRW_Error(req->wrk)) {
- SES_Close(req->sp,
- SC_REM_CLOSE);
- p = e;
- break;
- }
- assert(i == VGZ_OK || i == VGZ_END);
} else {
- /*
- * Ungzip'ed VEC, ungzip'ed ESI response
- */
(void)VDP_bytes(req, VDP_NULL, pp, l2);
}
pp += l2;
@@ -427,8 +398,6 @@ ESI_Deliver(struct req *req)
q++;
r = (void*)strchr((const char*)q, '\0');
AN(r);
- if (vgz != NULL)
- VGZ_WrwFlush(req, vgz);
if (VDP_bytes(req, VDP_FLUSH, NULL, 0)) {
SES_Close(req->sp, SC_REM_CLOSE);
p = e;
@@ -444,10 +413,6 @@ ESI_Deliver(struct req *req)
INCOMPL();
}
}
- if (vgz != NULL) {
- VGZ_WrwFlush(req, vgz);
- (void)VGZ_Destroy(&vgz);
- }
if (req->gzip_resp && req->esi_level == 0) {
/* Emit a gzip literal block with finish bit set */
tailbuf[0] = 0x01;
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 574bcf3..93b16dd 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -56,7 +56,6 @@ struct vgz {
int last_i;
enum vgz_flag flag;
- /* Wrw stuff */
char *m_buf;
ssize_t m_sz;
ssize_t m_len;
@@ -80,7 +79,7 @@ vgz_alloc_vgz(struct vsl_log *vsl, const char *id)
return (vg);
}
-struct vgz *
+static struct vgz *
VGZ_NewUngzip(struct vsl_log *vsl, const char *id)
{
struct vgz *vg;
@@ -193,7 +192,7 @@ VGZ_ObufFull(const struct vgz *vg)
/*--------------------------------------------------------------------*/
-enum vgzret_e
+static enum vgzret_e
VGZ_Gunzip(struct vgz *vg, const void **pptr, ssize_t *plen)
{
int i;
@@ -266,22 +265,6 @@ VGZ_Gzip(struct vgz *vg, const void **pptr, ssize_t *plen, enum vgz_flag flags)
}
/*--------------------------------------------------------------------
- */
-
-int
-VGZ_WrwInit(struct vgz *vg)
-{
-
- CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
-
- if (vgz_getmbuf(vg))
- return (-1);
-
- VGZ_Obuf(vg, vg->m_buf, vg->m_sz);
- return (0);
-}
-
-/*--------------------------------------------------------------------
* VDP for gunzip'ing
*/
@@ -294,6 +277,7 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
const void *dp;
struct worker *wrk;
struct vgz *vg;
+ int retval;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
wrk = req->wrk;
@@ -301,7 +285,9 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
if (act == VDP_INIT) {
vg = VGZ_NewUngzip(req->vsl, "U D -");
AN(vg);
- AZ(VGZ_WrwInit(vg));
+ if (vgz_getmbuf(vg))
+ return (-1);
+ VGZ_Obuf(vg, vg->m_buf, vg->m_sz);
*priv = vg;
return (0);
}
@@ -315,7 +301,10 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
if (len == 0) {
AN(act > VDP_NULL);
- return (VDP_bytes(req, act, vg->m_buf, vg->m_len));
+ retval = VDP_bytes(req, act, vg->m_buf, vg->m_len);
+ vg->m_len = 0;
+ VGZ_Obuf(vg, vg->m_buf, vg->m_sz);
+ return (retval);
}
VGZ_Ibuf(vg, ptr, len);
@@ -339,68 +328,6 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
return (0);
}
-/*--------------------------------------------------------------------
- * Gunzip ibuf into outb, if it runs full, emit it with WRW.
- * Leave flushing to caller, more data may be coming.
- */
-
-enum vgzret_e
-VGZ_WrwGunzip(struct req *req, struct vgz *vg, const void *ibuf,
- ssize_t ibufl)
-{
- enum vgzret_e vr;
- ssize_t dl;
- const void *dp;
- struct worker *wrk;
-
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- wrk = req->wrk;
- CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
- CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
- AN(vg->m_buf);
- VGZ_Ibuf(vg, ibuf, ibufl);
- if (ibufl == 0)
- return (VGZ_OK);
- do {
- if (vg->m_len == vg->m_sz)
- vr = VGZ_STUCK;
- else {
- vr = VGZ_Gunzip(vg, &dp, &dl);
- vg->m_len += dl;
- }
- if (vr < VGZ_OK)
- return (vr);
- if (vg->m_len == vg->m_sz || vr == VGZ_STUCK) {
- (void)VDP_bytes(req, VDP_FLUSH, vg->m_buf, vg->m_len);
- vg->m_len = 0;
- VGZ_Obuf(vg, vg->m_buf, vg->m_sz);
- }
- } while (!VGZ_IbufEmpty(vg));
- if (vr == VGZ_STUCK)
- vr = VGZ_OK;
- return (vr);
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-VGZ_WrwFlush(struct req *req, struct vgz *vg)
-{
- struct worker *wrk;
-
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- wrk = req->wrk;
- CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
- CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
-
- if (vg->m_len == 0)
- return;
-
- (void)VDP_bytes(req, VDP_FLUSH, vg->m_buf, vg->m_len);
- vg->m_len = 0;
- VGZ_Obuf(vg, vg->m_buf, vg->m_sz);
-}
-
/*--------------------------------------------------------------------*/
void
diff --git a/bin/varnishd/cache/cache_wrw.c b/bin/varnishd/cache/cache_wrw.c
index 814a791..948c562 100644
--- a/bin/varnishd/cache/cache_wrw.c
+++ b/bin/varnishd/cache/cache_wrw.c
@@ -64,13 +64,6 @@ struct wrw {
/*--------------------------------------------------------------------
*/
-int
-WRW_Error(const struct worker *wrk)
-{
-
- return (wrk->wrw->werr);
-}
-
void
WRW_Reserve(struct worker *wrk, int *fd, struct vsl_log *vsl, double t0)
{
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index e4c026a..5ed5be5 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -255,6 +255,8 @@ V1D_FlushReleaseAcct(struct req *req)
return (u);
}
+/*--------------------------------------------------------------------
+ */
void
V1D_Deliver(struct req *req, struct busyobj *bo)
{
@@ -337,9 +339,11 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
http_SetHeader(req->resp,
req->doclose ? "Connection: close" : "Connection: keep-alive");
- req->vdp_nxt = 0;
- VTAILQ_INIT(&req->vdp);
- VDP_push(req, v1d_bytes, NULL);
+ if (req->esi_level == 0) {
+ req->vdp_nxt = 0;
+ VTAILQ_INIT(&req->vdp);
+ VDP_push(req, v1d_bytes, NULL);
+ }
if (
req->wantbody &&
@@ -367,20 +371,32 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
if (!req->wantbody) {
/* This was a HEAD or conditional request */
} else if (req->res_mode & RES_ESI) {
+ if (req->esi_level == 0 && req->res_mode & RES_GUNZIP)
+ VDP_push(req, VDP_gunzip, NULL);
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, NULL);
- ois = v1d_WriteDirObj(req);
- VDP_pop(req, VED_pretend_gzip);
- } else if (req->res_mode & RES_ESI_CHILD && req->gzip_resp) {
- if (bo != NULL)
- VBO_waitstate(bo, BOS_FINISHED);
- ESI_DeliverChild(req);
- } else if (req->res_mode & RES_GUNZIP ||
- (req->res_mode & RES_ESI_CHILD &&
- !req->gzip_resp &&
- ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED))) {
+ if (req->esi_level == 0 && req->res_mode & RES_GUNZIP)
+ VDP_pop(req, VDP_gunzip);
+ } else if (req->res_mode & RES_ESI_CHILD) {
+ if (req->gzip_resp &&
+ !ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED)) {
+ VDP_push(req, VED_pretend_gzip, NULL);
+ ois = v1d_WriteDirObj(req);
+ VDP_pop(req, VED_pretend_gzip);
+ } else if (req->gzip_resp) {
+ if (bo != NULL)
+ VBO_waitstate(bo, BOS_FINISHED);
+ ESI_DeliverChild(req);
+ } else if (!req->gzip_resp &&
+ ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED)) {
+ VDP_push(req, VDP_gunzip, NULL);
+ ois = v1d_WriteDirObj(req);
+ VDP_pop(req, VDP_gunzip);
+ } else {
+ /* The toplevel will gunzip if needed */
+ ois = v1d_WriteDirObj(req);
+ }
+ } else if ((req->res_mode & RES_GUNZIP) &&
+ ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED)) {
VDP_push(req, VDP_gunzip, NULL);
ois = v1d_WriteDirObj(req);
VDP_pop(req, VDP_gunzip);
More information about the varnish-commit
mailing list