[6.0] 02052778b Split INIT/FINI into separate VDP methods
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Feb 6 10:11:09 UTC 2019
commit 02052778b8f87c2c4c2064f5b4b7f387491cee72
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Oct 10 09:01:11 2018 +0000
Split INIT/FINI into separate VDP methods
diff --git a/bin/varnishd/cache/cache_deliver_proc.c b/bin/varnishd/cache/cache_deliver_proc.c
index e3cdcee5c..6d603ad77 100644
--- a/bin/varnishd/cache/cache_deliver_proc.c
+++ b/bin/varnishd/cache/cache_deliver_proc.c
@@ -66,7 +66,7 @@ VDP_bytes(struct req *req, enum vdp_action act, const void *ptr, ssize_t len)
assert(act > VDP_NULL || len > 0);
/* Call the present layer, while pointing to the next layer down */
- retval = vdpe->vdp->func(req, act, &vdpe->priv, ptr, len);
+ retval = vdpe->vdp->bytes(req, act, &vdpe->priv, ptr, len);
if (retval && (vdc->retval == 0 || retval < vdc->retval))
vdc->retval = retval; /* Latch error value */
vdc->nxt = vdpe;
@@ -83,7 +83,7 @@ VDP_push(struct req *req, const struct vdp *vdp, void *priv, int bottom)
vdc = req->vdc;
AN(vdp);
AN(vdp->name);
- AN(vdp->func);
+ AN(vdp->bytes);
if (vdc->retval)
return (vdc->retval);
@@ -107,7 +107,8 @@ VDP_push(struct req *req, const struct vdp *vdp, void *priv, int bottom)
vdc->nxt = VTAILQ_FIRST(&vdc->vdp);
AZ(vdc->retval);
- vdc->retval = vdpe->vdp->func(req, VDP_INIT, &vdpe->priv, NULL, 0);
+ if (vdpe->vdp->init != NULL)
+ vdc->retval = vdpe->vdp->init(req, &vdpe->priv);
return (vdc->retval);
}
@@ -126,8 +127,8 @@ VDP_close(struct req *req)
if (vdpe != NULL) {
CHECK_OBJ_NOTNULL(vdpe, VDP_ENTRY_MAGIC);
VTAILQ_REMOVE(&vdc->vdp, vdpe, list);
- AZ(vdpe->vdp->func(req, VDP_FINI, &vdpe->priv,
- NULL, 0));
+ if (vdpe->vdp->fini != NULL)
+ AZ(vdpe->vdp->fini(req, &vdpe->priv));
AZ(vdpe->priv);
}
vdc->nxt = VTAILQ_FIRST(&vdc->vdp);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 1ce7ea4ca..e73663896 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -251,8 +251,38 @@ ved_decode_len(struct req *req, const uint8_t **pp)
/*---------------------------------------------------------------------
*/
-static int v_matchproto_(vdp_bytes)
-ved_vdp(struct req *req, enum vdp_action act, void **priv,
+static int v_matchproto_(vdp_init_f)
+ved_vdp_esi_init(struct req *req, void **priv)
+{
+ struct ecx *ecx;
+
+ AZ(*priv);
+ ALLOC_OBJ(ecx, ECX_MAGIC);
+ AN(ecx);
+ assert(sizeof gzip_hdr == 10);
+ ecx->preq = req;
+ *priv = ecx;
+ RFC2616_Weaken_Etag(req->resp);
+ req->res_mode |= RES_ESI;
+ if (req->resp_len != 0)
+ req->resp_len = -1;
+ return (0);
+}
+
+static int v_matchproto_(vdp_fini_f)
+ved_vdp_esi_fini(struct req *req, void **priv)
+{
+ struct ecx *ecx;
+
+ (void)req;
+ CAST_OBJ_NOTNULL(ecx, *priv, ECX_MAGIC);
+ FREE_OBJ(ecx);
+ *priv = NULL;
+ return (0);
+}
+
+static int v_matchproto_(vdp_bytes_f)
+ved_vdp_esi_bytes(struct req *req, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
uint8_t *q, *r;
@@ -263,25 +293,7 @@ ved_vdp(struct req *req, enum vdp_action act, void **priv,
struct ecx *ecx, *pecx = NULL;
int retval = 0;
- if (act == VDP_INIT) {
- AZ(*priv);
- ALLOC_OBJ(ecx, ECX_MAGIC);
- AN(ecx);
- assert(sizeof gzip_hdr == 10);
- ecx->preq = req;
- *priv = ecx;
- RFC2616_Weaken_Etag(req->resp);
- req->res_mode |= RES_ESI;
- if (req->resp_len != 0)
- req->resp_len = -1;
- return (0);
- }
CAST_OBJ_NOTNULL(ecx, *priv, ECX_MAGIC);
- if (act == VDP_FINI) {
- FREE_OBJ(ecx);
- *priv = NULL;
- return (0);
- }
pp = ptr;
if (req->esi_level > 0) {
@@ -435,7 +447,9 @@ ved_vdp(struct req *req, enum vdp_action act, void **priv,
const struct vdp VDP_esi = {
.name = "esi",
- .func = ved_vdp,
+ .init = ved_vdp_esi_init,
+ .bytes = ved_vdp_esi_bytes,
+ .fini = ved_vdp_esi_fini,
};
/*
@@ -468,8 +482,16 @@ ved_bytes(struct req *req, struct req *preq, enum vdp_action act,
* the stream with a bit more overhead.
*/
-static int v_matchproto_(vdp_bytes)
-ved_pretend_gzip(struct req *req, enum vdp_action act, void **priv,
+static int v_matchproto_(vdp_fini_f)
+ved_pretend_gzip_fini(struct req *req, void **priv)
+{
+ (void)req;
+ *priv = NULL;
+ return (0);
+}
+
+static int v_matchproto_(vdp_bytes_f)
+ved_pretend_gzip_bytes(struct req *req, enum vdp_action act, void **priv,
const void *pv, ssize_t l)
{
uint8_t buf1[5], buf2[5];
@@ -483,12 +505,6 @@ ved_pretend_gzip(struct req *req, enum vdp_action act, void **priv,
preq = ecx->preq;
(void)priv;
- if (act == VDP_INIT)
- return (0);
- if (act == VDP_FINI) {
- *priv = NULL;
- return (0);
- }
if (l == 0)
return (ved_bytes(req, ecx->preq, act, pv, l));
@@ -527,7 +543,8 @@ ved_pretend_gzip(struct req *req, enum vdp_action act, void **priv,
static const struct vdp ved_vdp_pgz = {
.name = "PGZ",
- .func = ved_pretend_gzip,
+ .bytes = ved_pretend_gzip_bytes,
+ .fini = ved_pretend_gzip_fini,
};
/*---------------------------------------------------------------------
@@ -769,26 +786,29 @@ ved_stripgzip(struct req *req, const struct boc *boc)
/*--------------------------------------------------------------------*/
-static int v_matchproto_(vdp_bytes)
+static int v_matchproto_(vdp_fini_f)
+ved_vdp_fini(struct req *req, void **priv)
+{
+ (void)req;
+ *priv = NULL;
+ return (0);
+}
+
+static int v_matchproto_(vdp_bytes_f)
ved_vdp_bytes(struct req *req, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
struct req *preq;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- if (act == VDP_INIT)
- return (0);
- if (act == VDP_FINI) {
- *priv = NULL;
- return (0);
- }
CAST_OBJ_NOTNULL(preq, *priv, REQ_MAGIC);
return (ved_bytes(req, preq, act, ptr, len));
}
static const struct vdp ved_ved = {
.name = "VED",
- .func = ved_vdp_bytes,
+ .bytes = ved_vdp_bytes,
+ .fini = ved_vdp_fini,
};
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
index 0bf90732d..2c31a3c7b 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -92,18 +92,20 @@ enum vfp_status VFP_Error(struct vfp_ctx *, const char *fmt, ...)
/* Deliver processors ------------------------------------------------*/
enum vdp_action {
- VDP_INIT, /* Happens on VDP_push() */
- VDP_FINI, /* Happens on VDP_pop() */
VDP_NULL, /* Input buffer valid after call */
VDP_FLUSH, /* Input buffer will be invalidated */
};
-typedef int vdp_bytes(struct req *, enum vdp_action, void **priv,
+typedef int vdp_init_f(struct req *, void **priv);
+typedef int vdp_fini_f(struct req *, void **priv);
+typedef int vdp_bytes_f(struct req *, enum vdp_action, void **priv,
const void *ptr, ssize_t len);
struct vdp {
const char *name;
- vdp_bytes *func;
+ vdp_init_f *init;
+ vdp_bytes_f *bytes;
+ vdp_fini_f *fini;
};
struct vdp_entry {
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index d5d256d56..bfe2f6279 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -284,62 +284,73 @@ VGZ_Gzip(struct vgz *vg, const void **pptr, ssize_t *plen, enum vgz_flag flags)
* VDP for gunzip'ing
*/
-static int v_matchproto_(vdp_bytes)
-vdp_gunzip(struct req *req, enum vdp_action act, void **priv,
- const void *ptr, ssize_t len)
+static int v_matchproto_(vdp_init_f)
+vdp_gunzip_init(struct req *req, void **priv)
{
- enum vgzret_e vr;
- ssize_t dl;
- const void *dp;
- struct worker *wrk;
struct vgz *vg;
const char *p;
+ ssize_t dl;
uint64_t u;
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- wrk = req->wrk;
- CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
-
- if (act == VDP_INIT) {
- vg = VGZ_NewGunzip(req->vsl, "U D -");
- AN(vg);
- if (vgz_getmbuf(vg)) {
- (void)VGZ_Destroy(&vg);
- return (-1);
- }
+ vg = VGZ_NewGunzip(req->vsl, "U D -");
+ AN(vg);
+ if (vgz_getmbuf(vg)) {
+ (void)VGZ_Destroy(&vg);
+ return (-1);
+ }
- req->res_mode |= RES_GUNZIP;
- VGZ_Obuf(vg, vg->m_buf, vg->m_sz);
- *priv = vg;
+ req->res_mode |= RES_GUNZIP;
+ VGZ_Obuf(vg, vg->m_buf, vg->m_sz);
+ *priv = vg;
- http_Unset(req->resp, H_Content_Encoding);
+ http_Unset(req->resp, H_Content_Encoding);
- req->resp_len = -1;
+ req->resp_len = -1;
- p = ObjGetAttr(req->wrk, req->objcore, OA_GZIPBITS, &dl);
- if (p != NULL && dl == 32) {
- u = vbe64dec(p + 24);
- /*
- * If the size is non-zero AND we are the top VDP
- * (ie: no ESI), we know what size the output will be.
- */
- if (u != 0 &&
- VTAILQ_FIRST(&req->vdc->vdp)->vdp == &VDP_gunzip)
- req->resp_len = u;
- }
- return (0);
+ p = ObjGetAttr(req->wrk, req->objcore, OA_GZIPBITS, &dl);
+ if (p != NULL && dl == 32) {
+ u = vbe64dec(p + 24);
+ /*
+ * If the size is non-zero AND we are the top VDP
+ * (ie: no ESI), we know what size the output will be.
+ */
+ if (u != 0 &&
+ VTAILQ_FIRST(&req->vdc->vdp)->vdp == &VDP_gunzip)
+ req->resp_len = u;
}
+ return (0);
+}
+
+static int v_matchproto_(vdp_fini_f)
+vdp_gunzip_fini(struct req *req, void **priv)
+{
+ struct vgz *vg;
+ (void)req;
CAST_OBJ_NOTNULL(vg, *priv, VGZ_MAGIC);
AN(vg->m_buf);
+ (void)VGZ_Destroy(&vg);
+ *priv = NULL;
+ return (0);
+}
- if (act == VDP_FINI) {
- /* NB: Gunzip'ing may or may not have completed successfully. */
- AZ(len);
- (void)VGZ_Destroy(&vg);
- *priv = NULL;
- return (0);
- }
+static int v_matchproto_(vdp_bytes_f)
+vdp_gunzip_bytes(struct req *req, enum vdp_action act, void **priv,
+ const void *ptr, ssize_t len)
+{
+ enum vgzret_e vr;
+ ssize_t dl;
+ const void *dp;
+ struct worker *wrk;
+ struct vgz *vg;
+
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ wrk = req->wrk;
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ (void)act;
+
+ CAST_OBJ_NOTNULL(vg, *priv, VGZ_MAGIC);
+ AN(vg->m_buf);
if (len == 0)
return (0);
@@ -363,7 +374,9 @@ vdp_gunzip(struct req *req, enum vdp_action act, void **priv,
const struct vdp VDP_gunzip = {
.name = "gunzip",
- .func = vdp_gunzip,
+ .init = vdp_gunzip_init,
+ .bytes = vdp_gunzip_bytes,
+ .fini = vdp_gunzip_fini,
};
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c
index 373d1f676..c6cf1fd3c 100644
--- a/bin/varnishd/cache/cache_range.c
+++ b/bin/varnishd/cache/cache_range.c
@@ -44,7 +44,20 @@ struct vrg_priv {
ssize_t range_off;
};
-static int v_matchproto_(vdp_bytes)
+static int v_matchproto_(vdp_fini_f)
+vrg_range_fini(struct req *req, void **priv)
+{
+ struct vrg_priv *vrg_priv;
+
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ CAST_OBJ_NOTNULL(vrg_priv, *priv, VRG_PRIV_MAGIC);
+ if (vrg_priv->range_off < vrg_priv->range_high)
+ Req_Fail(req, SC_RANGE_SHORT);
+ *priv = NULL; /* struct on ws, no need to free */
+ return (0);
+}
+
+static int v_matchproto_(vdp_bytes_f)
vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
@@ -54,15 +67,7 @@ vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
struct vrg_priv *vrg_priv;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- if (act == VDP_INIT)
- return (0);
CAST_OBJ_NOTNULL(vrg_priv, *priv, VRG_PRIV_MAGIC);
- if (act == VDP_FINI) {
- if (vrg_priv->range_off < vrg_priv->range_high)
- Req_Fail(req, SC_RANGE_SHORT);
- *priv = NULL; /* struct on ws, no need to free */
- return (0);
- }
l = vrg_priv->range_low - vrg_priv->range_off;
if (l > 0) {
@@ -86,7 +91,8 @@ vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
static const struct vdp vrg_vdp = {
.name = "RNG",
- .func = vrg_range_bytes,
+ .bytes = vrg_range_bytes,
+ .fini = vrg_range_fini,
};
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index 88447b5a6..03c5f3ba8 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -35,7 +35,7 @@
/*--------------------------------------------------------------------*/
-static int v_matchproto_(vdp_bytes)
+static int v_matchproto_(vdp_bytes_f)
v1d_bytes(struct req *req, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
@@ -43,8 +43,6 @@ v1d_bytes(struct req *req, enum vdp_action act, void **priv,
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
(void)priv;
- if (act == VDP_INIT || act == VDP_FINI)
- return (0);
AZ(req->vdc->nxt); /* always at the bottom of the pile */
@@ -59,7 +57,7 @@ v1d_bytes(struct req *req, enum vdp_action act, void **priv,
static const struct vdp v1d_vdp = {
.name = "V1B",
- .func = v1d_bytes,
+ .bytes = v1d_bytes,
};
static void
diff --git a/bin/varnishd/http2/cache_http2_deliver.c b/bin/varnishd/http2/cache_http2_deliver.c
index 2ec67a60b..60d35bc40 100644
--- a/bin/varnishd/http2/cache_http2_deliver.c
+++ b/bin/varnishd/http2/cache_http2_deliver.c
@@ -72,7 +72,21 @@ V2D_Init(void)
/**********************************************************************/
-static int v_matchproto_(vdp_bytes)
+static int v_matchproto_(vdp_fini_f)
+h2_fini(struct req *req, void **priv)
+{
+ struct h2_req *r2;
+
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ (void)priv;
+ CAST_OBJ_NOTNULL(r2, req->transport_priv, H2_REQ_MAGIC);
+ H2_Send_Get(req->wrk, r2->h2sess, r2);
+ H2_Send(req->wrk, r2, H2_F_DATA, H2FF_DATA_END_STREAM, 0, "");
+ H2_Send_Rel(r2->h2sess, r2);
+ return (0);
+}
+
+static int v_matchproto_(vdp_bytes_f)
h2_bytes(struct req *req, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
@@ -80,17 +94,13 @@ h2_bytes(struct req *req, enum vdp_action act, void **priv,
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CAST_OBJ_NOTNULL(r2, req->transport_priv, H2_REQ_MAGIC);
+ (void)act;
(void)priv;
- if (act == VDP_INIT)
- return (0);
- if ((r2->h2sess->error || r2->error) && act != VDP_FINI)
+ if ((r2->h2sess->error || r2->error))
return (-1);
H2_Send_Get(req->wrk, r2->h2sess, r2);
- H2_Send(req->wrk, r2,
- H2_F_DATA,
- act == VDP_FINI ? H2FF_DATA_END_STREAM : H2FF_NONE,
- len, ptr);
+ H2_Send(req->wrk, r2, H2_F_DATA, H2FF_NONE, len, ptr);
H2_Send_Rel(r2->h2sess, r2);
req->acct.resp_bodybytes += len;
return (0);
@@ -98,7 +108,8 @@ h2_bytes(struct req *req, enum vdp_action act, void **priv,
static const struct vdp h2_vdp = {
.name = "H2B",
- .func = h2_bytes,
+ .bytes = h2_bytes,
+ .fini = h2_fini,
};
static inline size_t
More information about the varnish-commit
mailing list