[master] 8b73891 Give VDPs a describing structure like VFPs have it. Saves workspace too.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Sep 25 18:20:06 UTC 2017
commit 8b73891e1d3d07f016a2fe5c4108065699f0fb27
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Sep 25 18:19:20 2017 +0000
Give VDPs a describing structure like VFPs have it. Saves workspace too.
diff --git a/bin/varnishd/cache/cache_deliver_proc.c b/bin/varnishd/cache/cache_deliver_proc.c
index ad8f46f..c1b079e 100644
--- a/bin/varnishd/cache/cache_deliver_proc.c
+++ b/bin/varnishd/cache/cache_deliver_proc.c
@@ -64,7 +64,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->func(req, act, &vdpe->priv, ptr, len);
+ retval = vdpe->vdp->func(req, act, &vdpe->priv, ptr, len);
if (retval && (req->vdpe_retval == 0 || retval < req->vdpe_retval))
req->vdpe_retval = retval; /* Latch error value */
req->vdpe_nxt = vdpe;
@@ -72,52 +72,44 @@ VDP_bytes(struct req *req, enum vdp_action act, const void *ptr, ssize_t len)
}
void
-VDP_push(struct req *req, vdp_bytes *func, void *priv, int bottom,
- const char *id)
+VDP_push(struct req *req, const struct vdp *vdp, void *priv, int bottom)
{
struct vdp_entry *vdpe;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- AN(func);
+ AN(vdp);
+ AN(vdp->name);
+ AN(vdp->func);
vdpe = WS_Alloc(req->ws, sizeof *vdpe);
if (vdpe == NULL)
return;
INIT_OBJ(vdpe, VDP_ENTRY_MAGIC);
- vdpe->func = func;
+ vdpe->vdp = vdp;
vdpe->priv = priv;
- vdpe->id = id;
if (bottom)
VTAILQ_INSERT_TAIL(&req->vdpe, vdpe, list);
else
VTAILQ_INSERT_HEAD(&req->vdpe, vdpe, list);
req->vdpe_nxt = VTAILQ_FIRST(&req->vdpe);
- AZ(vdpe->func(req, VDP_INIT, &vdpe->priv, NULL, 0));
-}
-
-static void
-vdp_pop(struct req *req, vdp_bytes *func)
-{
- struct vdp_entry *vdpe;
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-
- vdpe = VTAILQ_FIRST(&req->vdpe);
- CHECK_OBJ_NOTNULL(vdpe, VDP_ENTRY_MAGIC);
- assert(vdpe->func == func);
- VTAILQ_REMOVE(&req->vdpe, vdpe, list);
- AZ(vdpe->func(req, VDP_FINI, &vdpe->priv, NULL, 0));
- AZ(vdpe->priv);
- req->vdpe_nxt = VTAILQ_FIRST(&req->vdpe);
+ AZ(vdpe->vdp->func(req, VDP_INIT, &vdpe->priv, NULL, 0));
}
void
VDP_close(struct req *req)
{
+ struct vdp_entry *vdpe;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- while (!VTAILQ_EMPTY(&req->vdpe))
- vdp_pop(req, VTAILQ_FIRST(&req->vdpe)->func);
+ while (!VTAILQ_EMPTY(&req->vdpe)) {
+ vdpe = VTAILQ_FIRST(&req->vdpe);
+ CHECK_OBJ_NOTNULL(vdpe, VDP_ENTRY_MAGIC);
+ VTAILQ_REMOVE(&req->vdpe, vdpe, list);
+ AZ(vdpe->vdp->func(req, VDP_FINI, &vdpe->priv, NULL, 0));
+ AZ(vdpe->priv);
+ req->vdpe_nxt = VTAILQ_FIRST(&req->vdpe);
+ }
}
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index d5fd97a..d9ec496 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -254,8 +254,8 @@ ved_decode_len(struct req *req, const uint8_t **pp)
/*---------------------------------------------------------------------
*/
-int __match_proto__(vdp_bytes)
-VDP_ESI(struct req *req, enum vdp_action act, void **priv,
+static int __match_proto__(vdp_bytes)
+ved_vdp(struct req *req, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
uint8_t *q, *r;
@@ -436,6 +436,11 @@ VDP_ESI(struct req *req, enum vdp_action act, void **priv,
}
}
+const struct vdp VDP_esi = {
+ .name = "esi",
+ .func = ved_vdp,
+};
+
/*
* Account body bytes on req
* Push bytes to preq
@@ -523,6 +528,11 @@ ved_pretend_gzip(struct req *req, enum vdp_action act, void **priv,
return (ved_bytes(req, preq, VDP_FLUSH, NULL, 0));
}
+static const struct vdp ved_vdp_pgz = {
+ .name = "PGZ",
+ .func = ved_pretend_gzip,
+};
+
/*---------------------------------------------------------------------
* Include an object in a gzip'ed ESI object delivery
*
@@ -779,6 +789,11 @@ ved_vdp_bytes(struct req *req, enum vdp_action act, void **priv,
return (ved_bytes(req, preq, act, ptr, len));
}
+static const struct vdp ved_ved = {
+ .name = "VED",
+ .func = ved_vdp_bytes,
+};
+
/*--------------------------------------------------------------------*/
static void __match_proto__(vtr_deliver_f)
@@ -805,9 +820,9 @@ ved_deliver(struct req *req, struct boc *boc, int wantbody)
ved_stripgzip(req, boc);
} else {
if (ecx->isgzip && !i)
- VDP_push(req, ved_pretend_gzip, ecx, 1, "PGZ");
+ VDP_push(req, &ved_vdp_pgz, ecx, 1);
else
- VDP_push(req, ved_vdp_bytes, ecx->preq, 1, "VED");
+ VDP_push(req, &ved_ved, ecx->preq, 1);
(void)VDP_DeliverObj(req);
(void)VDP_bytes(req, VDP_FLUSH, NULL, 0);
}
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
index 2556a07..459c9fb 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -47,12 +47,12 @@ typedef enum vfp_status
typedef void vfp_fini_f(struct vfp_ctx *, struct vfp_entry *);
struct vfp {
- const char *name;
- vfp_init_f *init;
- vfp_pull_f *pull;
- vfp_fini_f *fini;
- const void *priv1;
- intptr_t priv2;
+ const char *name;
+ vfp_init_f *init;
+ vfp_pull_f *pull;
+ vfp_fini_f *fini;
+ const void *priv1;
+ intptr_t priv2;
};
struct vfp_entry {
@@ -83,18 +83,18 @@ enum vdp_action {
typedef int vdp_bytes(struct req *, enum vdp_action, void **priv,
const void *ptr, ssize_t len);
+struct vdp {
+ const char *name;
+ vdp_bytes *func;
+};
+
struct vdp_entry {
unsigned magic;
#define VDP_ENTRY_MAGIC 0x353eb781
- vdp_bytes *func;
+ const struct vdp *vdp;
void *priv;
- const char *id;
VTAILQ_ENTRY(vdp_entry) list;
};
int VDP_bytes(struct req *, enum vdp_action act, const void *ptr, ssize_t len);
-void VDP_push(struct req *, vdp_bytes *func, void *priv, int bottom,
- const char *id);
-
-vdp_bytes VDP_gunzip;
-vdp_bytes VDP_ESI;
+void VDP_push(struct req *, const struct vdp *, void *priv, int bottom);
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 4c24e4b..0eb086d 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -284,8 +284,8 @@ VGZ_Gzip(struct vgz *vg, const void **pptr, ssize_t *plen, enum vgz_flag flags)
* VDP for gunzip'ing
*/
-int __match_proto__(vdp_bytes)
-VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
+static int __match_proto__(vdp_bytes)
+vdp_gunzip(struct req *req, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
enum vgzret_e vr;
@@ -327,7 +327,7 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
* 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->vdpe)->func == VDP_gunzip)
+ if (u != 0 && VTAILQ_FIRST(&req->vdpe)->vdp == &VDP_gunzip)
req->resp_len = u;
return (0);
@@ -364,6 +364,11 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
return (0);
}
+const struct vdp VDP_gunzip = {
+ .name = "gunzip",
+ .func = vdp_gunzip,
+};
+
/*--------------------------------------------------------------------*/
void
diff --git a/bin/varnishd/cache/cache_priv.h b/bin/varnishd/cache/cache_priv.h
index 3434ce9..197510d 100644
--- a/bin/varnishd/cache/cache_priv.h
+++ b/bin/varnishd/cache/cache_priv.h
@@ -78,6 +78,9 @@ void CLI_AddFuncs(struct cli_proto *p);
void VDP_close(struct req *req);
int VDP_DeliverObj(struct req *req);
+extern const struct vdp VDP_gunzip;
+extern const struct vdp VDP_esi;
+
/* cache_expire.c */
void EXP_Init(void);
diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c
index 0af1a08..ced39c7 100644
--- a/bin/varnishd/cache/cache_range.c
+++ b/bin/varnishd/cache/cache_range.c
@@ -84,6 +84,11 @@ vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
vrg_priv->range_off >= vrg_priv->range_high ? 1 : 0);
}
+static const struct vdp vrg_vdp = {
+ .name = "RNG",
+ .func = vrg_range_bytes,
+};
+
/*--------------------------------------------------------------------*/
static const char *
@@ -170,7 +175,7 @@ vrg_dorange(struct req *req, const char *r)
vrg_priv->range_off = 0;
vrg_priv->range_low = low;
vrg_priv->range_high = high + 1;
- VDP_push(req, vrg_range_bytes, vrg_priv, 1, "RNG");
+ VDP_push(req, &vrg_vdp, vrg_priv, 1);
http_PutResponse(req->resp, "HTTP/1.1", 206, NULL);
return (NULL);
}
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index a0caba3..c96430b 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -370,12 +370,12 @@ cnt_transmit(struct worker *wrk, struct req *req)
if (sendbody >= 0) {
if (!req->disable_esi && req->resp_len != 0 &&
ObjHasAttr(wrk, req->objcore, OA_ESIDATA))
- VDP_push(req, VDP_ESI, NULL, 0, "ESI");
+ VDP_push(req, &VDP_esi, NULL, 0);
if (cache_param->http_gzip_support &&
ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED) &&
!RFC2616_Req_Gzip(req->http))
- VDP_push(req, VDP_gunzip, NULL, 1, "GUZ");
+ VDP_push(req, &VDP_gunzip, NULL, 1);
if (cache_param->http_range_support &&
http_IsStatus(req->resp, 200)) {
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index b335471..96174a9 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -58,6 +58,11 @@ v1d_bytes(struct req *req, enum vdp_action act, void **priv,
return (0);
}
+static const struct vdp v1d_vdp = {
+ .name = "V1B",
+ .func = v1d_bytes,
+};
+
static void
v1d_error(struct req *req, const char *msg)
{
@@ -110,7 +115,7 @@ V1D_Deliver(struct req *req, struct boc *boc, int sendbody)
http_SetHeader(req->resp, "Connection: keep-alive");
if (sendbody && req->resp_len != 0)
- VDP_push(req, v1d_bytes, NULL, 1, "V1B");
+ VDP_push(req, &v1d_vdp, NULL, 1);
AZ(req->wrk->v1l);
V1L_Reserve(req->wrk, req->ws, &req->sp->fd, req->vsl, req->t_prev);
diff --git a/bin/varnishd/http2/cache_http2_deliver.c b/bin/varnishd/http2/cache_http2_deliver.c
index a9d4ad5..11ca12b 100644
--- a/bin/varnishd/http2/cache_http2_deliver.c
+++ b/bin/varnishd/http2/cache_http2_deliver.c
@@ -96,6 +96,11 @@ h2_bytes(struct req *req, enum vdp_action act, void **priv,
return (0);
}
+static const struct vdp h2_vdp = {
+ .name = "H2B",
+ .func = h2_bytes,
+};
+
static inline size_t
h2_status(uint8_t *p, uint16_t status) {
size_t l = 1;
@@ -261,7 +266,7 @@ h2_deliver(struct req *req, struct boc *boc, int sendbody)
WS_Release(req->ws, 0);
if (sendbody) {
- VDP_push(req, h2_bytes, NULL, 1, "H2");
+ VDP_push(req, &h2_vdp, NULL, 1);
err = VDP_DeliverObj(req);
/*XXX*/(void)err;
}
More information about the varnish-commit
mailing list