[master] 30be1c800 Start changing the calling convention for VDP to make it usable on bereq.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Oct 5 09:32:07 UTC 2020
commit 30be1c800c36c7f48f10a9eaaf750f72f31d0861
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Oct 5 09:13:11 2020 +0000
Start changing the calling convention for VDP to make it usable on bereq.
diff --git a/bin/varnishd/cache/cache_deliver_proc.c b/bin/varnishd/cache/cache_deliver_proc.c
index ea186be28..0e5bdd737 100644
--- a/bin/varnishd/cache/cache_deliver_proc.c
+++ b/bin/varnishd/cache/cache_deliver_proc.c
@@ -58,17 +58,16 @@
* r > 0: Stop, breaks out early without error condition
*/
int
-VDP_bytes(struct req *req, enum vdp_action act, const void *ptr, ssize_t len)
+VDP_bytes(struct vdp_ctx *vdx, enum vdp_action act, const void *ptr, ssize_t len)
{
int retval;
struct vdp_entry *vdpe;
- struct vdp_ctx *vdc;
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- vdc = req->vdc;
- if (vdc->retval)
- return (vdc->retval);
- vdpe = vdc->nxt;
+ CHECK_OBJ_NOTNULL(vdx, VDP_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(vdx->req, REQ_MAGIC);
+ if (vdx->retval)
+ return (vdx->retval);
+ vdpe = vdx->nxt;
CHECK_OBJ_NOTNULL(vdpe, VDP_ENTRY_MAGIC);
/* at most one VDP_END call */
@@ -82,14 +81,14 @@ VDP_bytes(struct req *req, enum vdp_action act, const void *ptr, ssize_t len)
assert(act == VDP_FLUSH);
/* Call the present layer, while pointing to the next layer down */
- vdc->nxt = VTAILQ_NEXT(vdpe, list);
+ vdx->nxt = VTAILQ_NEXT(vdpe, list);
vdpe->calls++;
vdpe->bytes_in += 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;
- return (vdc->retval);
+ retval = vdpe->vdp->bytes(vdx, act, &vdpe->priv, ptr, len);
+ if (retval && (vdx->retval == 0 || retval < vdx->retval))
+ vdx->retval = retval; /* Latch error value */
+ vdx->nxt = vdpe;
+ return (vdx->retval);
}
int
@@ -177,11 +176,14 @@ VDP_DeliverObj(struct req *req)
int r, final;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ req->vdc->req = req;
+ req->vdc->vsl = req->vsl;
+ req->vdc->wrk = req->wrk;
final = req->objcore->flags & (OC_F_PRIVATE | OC_F_HFM | OC_F_HFP)
? 1 : 0;
- r = ObjIterate(req->wrk, req->objcore, req, vdp_objiterator, final);
+ r = ObjIterate(req->wrk, req->objcore, req->vdc, vdp_objiterator, final);
if (r == 0)
- r = VDP_bytes(req, VDP_END, NULL, 0);
+ r = VDP_bytes(req->vdc, VDP_END, NULL, 0);
if (r < 0)
return (r);
return (0);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 80bcca5c9..ff9cf8d29 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -222,7 +222,7 @@ ved_include(struct req *preq, const char *src, const char *host,
#define Debug(fmt, ...) /**/
static ssize_t
-ved_decode_len(struct req *req, const uint8_t **pp)
+ved_decode_len(struct vsl_log *vsl, const uint8_t **pp)
{
const uint8_t *p;
ssize_t l;
@@ -242,7 +242,7 @@ ved_decode_len(struct req *req, const uint8_t **pp)
p += 9;
break;
default:
- VSLb(req->vsl, SLT_Error,
+ VSLb(vsl, SLT_Error,
"ESI-corruption: Illegal Length %d %d\n", *p, (*p & 15));
WRONG("ESI-codes: illegal length");
}
@@ -300,7 +300,7 @@ ved_vdp_esi_fini(struct req *req, void **priv)
}
static int v_matchproto_(vdp_bytes_f)
-ved_vdp_esi_bytes(struct req *req, enum vdp_action act, void **priv,
+ved_vdp_esi_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
uint8_t *q, *r;
@@ -312,13 +312,14 @@ ved_vdp_esi_bytes(struct req *req, enum vdp_action act, void **priv,
int retval = 0;
AN(priv);
+ CHECK_OBJ_NOTNULL(vdx, VDP_CTX_MAGIC);
CAST_OBJ_NOTNULL(ecx, *priv, ECX_MAGIC);
pp = ptr;
while (1) {
switch (ecx->state) {
case 0:
- ecx->p = ObjGetAttr(req->wrk, req->objcore,
+ ecx->p = ObjGetAttr(vdx->wrk, vdx->req->objcore,
OA_ESIDATA, &l);
AN(ecx->p);
assert(l > 0);
@@ -326,7 +327,7 @@ ved_vdp_esi_bytes(struct req *req, enum vdp_action act, void **priv,
if (*ecx->p == VEC_GZ) {
if (ecx->pecx == NULL)
- retval = VDP_bytes(req, VDP_NULL,
+ retval = VDP_bytes(vdx, VDP_NULL,
gzip_hdr, 10);
ecx->l_crc = 0;
ecx->crc = crc32(0L, Z_NULL, 0);
@@ -344,14 +345,14 @@ ved_vdp_esi_bytes(struct req *req, enum vdp_action act, void **priv,
case VEC_V1:
case VEC_V2:
case VEC_V8:
- ecx->l = ved_decode_len(req, &ecx->p);
+ ecx->l = ved_decode_len(vdx->vsl, &ecx->p);
if (ecx->l < 0)
return (-1);
if (ecx->isgzip) {
assert(*ecx->p == VEC_C1 ||
*ecx->p == VEC_C2 ||
*ecx->p == VEC_C8);
- l = ved_decode_len(req, &ecx->p);
+ l = ved_decode_len(vdx->vsl, &ecx->p);
if (l < 0)
return (-1);
icrc = vbe32dec(ecx->p);
@@ -365,7 +366,7 @@ ved_vdp_esi_bytes(struct req *req, enum vdp_action act, void **priv,
case VEC_S1:
case VEC_S2:
case VEC_S8:
- ecx->l = ved_decode_len(req, &ecx->p);
+ ecx->l = ved_decode_len(vdx->vsl, &ecx->p);
if (ecx->l < 0)
return (-1);
Debug("SKIP1(%d)\n", (int)ecx->l);
@@ -378,18 +379,18 @@ ved_vdp_esi_bytes(struct req *req, enum vdp_action act, void **priv,
q++;
r = (void*)strchr((const char*)q, '\0');
AN(r);
- if (VDP_bytes(req, VDP_FLUSH, NULL, 0)) {
+ if (VDP_bytes(vdx, VDP_FLUSH, NULL, 0)) {
ecx->p = ecx->e;
break;
}
Debug("INCL [%s][%s] BEGIN\n", q, ecx->p);
- ved_include(req,
+ ved_include(vdx->req,
(const char*)q, (const char*)ecx->p, ecx);
Debug("INCL [%s][%s] END\n", q, ecx->p);
ecx->p = r + 1;
break;
default:
- VSLb(req->vsl, SLT_Error,
+ VSLb(vdx->vsl, SLT_Error,
"ESI corruption line %d 0x%02x [%s]\n",
__LINE__, *ecx->p, ecx->p);
WRONG("ESI-codes: Illegal code");
@@ -413,14 +414,14 @@ ved_vdp_esi_bytes(struct req *req, enum vdp_action act, void **priv,
/* MOD(2^32) length */
vle32enc(tailbuf + 9, ecx->l_crc);
- retval = VDP_bytes(req, VDP_END, tailbuf, 13);
+ retval = VDP_bytes(vdx, VDP_END, tailbuf, 13);
} else if (ecx->pecx != NULL) {
ecx->pecx->crc = crc32_combine(ecx->pecx->crc,
ecx->crc, ecx->l_crc);
ecx->pecx->l_crc += ecx->l_crc;
- retval = VDP_bytes(req, VDP_FLUSH, NULL, 0);
+ retval = VDP_bytes(vdx, VDP_FLUSH, NULL, 0);
} else {
- retval = VDP_bytes(req, VDP_END, NULL, 0);
+ retval = VDP_bytes(vdx, VDP_END, NULL, 0);
}
ecx->state = 99;
return (retval);
@@ -434,7 +435,7 @@ ved_vdp_esi_bytes(struct req *req, enum vdp_action act, void **priv,
*/
if (ecx->l <= len) {
if (ecx->state == 3)
- retval = VDP_bytes(req, act,
+ retval = VDP_bytes(vdx, act,
pp, ecx->l);
len -= ecx->l;
pp += ecx->l;
@@ -442,7 +443,7 @@ ved_vdp_esi_bytes(struct req *req, enum vdp_action act, void **priv,
break;
}
if (ecx->state == 3 && len > 0)
- retval = VDP_bytes(req, act, pp, len);
+ retval = VDP_bytes(vdx, act, pp, len);
ecx->l -= len;
return (retval);
case 99:
@@ -477,7 +478,7 @@ ved_bytes(struct ecx *ecx, enum vdp_action act,
{
if (act == VDP_END)
act = VDP_FLUSH;
- return (VDP_bytes(ecx->preq, act, ptr, len));
+ return (VDP_bytes(ecx->preq->vdc, act, ptr, len));
}
/*---------------------------------------------------------------------
@@ -507,7 +508,7 @@ ved_pretend_gzip_fini(struct req *req, void **priv)
}
static int v_matchproto_(vdp_bytes_f)
-ved_pretend_gzip_bytes(struct req *req, enum vdp_action act, void **priv,
+ved_pretend_gzip_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
const void *pv, ssize_t l)
{
uint8_t buf1[5], buf2[5];
@@ -515,7 +516,8 @@ ved_pretend_gzip_bytes(struct req *req, enum vdp_action act, void **priv,
uint16_t lx;
struct ecx *ecx;
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ CHECK_OBJ_NOTNULL(vdx, VDP_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(vdx->req, REQ_MAGIC);
CAST_OBJ_NOTNULL(ecx, *priv, ECX_MAGIC);
(void)priv;
@@ -614,7 +616,7 @@ ved_gzgz_init(struct req *req, void **priv)
}
static int v_matchproto_(vdp_bytes_f)
-ved_gzgz_bytes(struct req *req, enum vdp_action act, void **priv,
+ved_gzgz_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
struct ved_foo *foo;
@@ -622,7 +624,7 @@ ved_gzgz_bytes(struct req *req, enum vdp_action act, void **priv,
ssize_t dl;
ssize_t l;
- (void)req;
+ (void)vdx;
CAST_OBJ_NOTNULL(foo, *priv, VED_FOO_MAGIC);
pp = ptr;
if (len > 0) {
@@ -799,12 +801,12 @@ ved_vdp_fini(struct req *req, void **priv)
}
static int v_matchproto_(vdp_bytes_f)
-ved_vdp_bytes(struct req *req, enum vdp_action act, void **priv,
+ved_vdp_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
struct ecx *ecx;
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ (void)vdx;
CAST_OBJ_NOTNULL(ecx, *priv, ECX_MAGIC);
return (ved_bytes(ecx, act, ptr, len));
}
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
index 483147196..4a190f6dc 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -110,8 +110,10 @@ typedef int vdp_init_f(struct req *, void **priv);
* positive: Don't push this VDP anyway
*/
+struct vdp_ctx;
+
typedef int vdp_fini_f(struct req *, void **priv);
-typedef int vdp_bytes_f(struct req *, enum vdp_action, void **priv,
+typedef int vdp_bytes_f(struct vdp_ctx *, enum vdp_action, void **priv,
const void *ptr, ssize_t len);
struct vdp {
@@ -140,9 +142,12 @@ struct vdp_ctx {
int retval;
struct vdp_entry_s vdp;
struct vdp_entry *nxt;
+ struct worker *wrk;
+ struct vsl_log *vsl;
+ struct req *req;
};
-int VDP_bytes(struct req *, enum vdp_action act, const void *ptr, ssize_t len);
+int VDP_bytes(struct vdp_ctx *, enum vdp_action act, const void *ptr, ssize_t len);
int VDP_Push(struct req *, const struct vdp *, void *priv);
void VRT_AddVDP(VRT_CTX, const struct vdp *);
void VRT_RemoveVDP(VRT_CTX, const struct vdp *);
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 569ca1e56..b5c04db83 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -354,7 +354,7 @@ vdp_gunzip_fini(struct req *req, void **priv)
}
static int v_matchproto_(vdp_bytes_f)
-vdp_gunzip_bytes(struct req *req, enum vdp_action act, void **priv,
+vdp_gunzip_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
enum vgzret_e vr;
@@ -363,8 +363,8 @@ vdp_gunzip_bytes(struct req *req, enum vdp_action act, void **priv,
struct worker *wrk;
struct vgz *vg;
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- wrk = req->wrk;
+ CHECK_OBJ_NOTNULL(vdx, VDP_CTX_MAGIC);
+ wrk = vdx->wrk;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
(void)act;
@@ -386,8 +386,8 @@ vdp_gunzip_bytes(struct req *req, enum vdp_action act, void **priv,
if (vr < VGZ_OK)
return (-1);
if (vg->m_len == vg->m_sz || vr != VGZ_OK) {
- if (VDP_bytes(req, VDP_FLUSH, vg->m_buf, vg->m_len))
- return (req->vdc->retval);
+ if (VDP_bytes(vdx, VDP_FLUSH, vg->m_buf, vg->m_len))
+ return (vdx->retval);
vg->m_len = 0;
VGZ_Obuf(vg, vg->m_buf, vg->m_sz);
}
diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c
index 970e75a75..fe9943718 100644
--- a/bin/varnishd/cache/cache_range.c
+++ b/bin/varnishd/cache/cache_range.c
@@ -61,7 +61,7 @@ vrg_range_fini(struct req *req, void **priv)
}
static int v_matchproto_(vdp_bytes_f)
-vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
+vrg_range_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
int retval = 0;
@@ -69,7 +69,7 @@ vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
const char *p = ptr;
struct vrg_priv *vrg_priv;
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ CHECK_OBJ_NOTNULL(vdx, VDP_CTX_MAGIC);
AN(priv);
CAST_OBJ_NOTNULL(vrg_priv, *priv, VRG_PRIV_MAGIC);
@@ -88,9 +88,9 @@ vrg_range_bytes(struct req *req, enum vdp_action act, void **priv,
if (vrg_priv->range_off >= vrg_priv->range_high)
act = VDP_END;
if (l > 0)
- retval = VDP_bytes(req, act, p, l);
+ retval = VDP_bytes(vdx, act, p, l);
else if (l == 0 && act > VDP_NULL)
- retval = VDP_bytes(req, act, p, 0);
+ retval = VDP_bytes(vdx, act, p, 0);
return (retval || act == VDP_END ? 1 : 0);
}
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index 9ab9ad711..42262d384 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -38,19 +38,19 @@
/*--------------------------------------------------------------------*/
static int v_matchproto_(vdp_bytes_f)
-v1d_bytes(struct req *req, enum vdp_action act, void **priv,
+v1d_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
ssize_t wl = 0;
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ CHECK_OBJ_NOTNULL(vdx, VDP_CTX_MAGIC);
(void)priv;
- AZ(req->vdc->nxt); /* always at the bottom of the pile */
+ AZ(vdx->nxt); /* always at the bottom of the pile */
if (len > 0)
- wl = V1L_Write(req->wrk, ptr, len);
- if (act > VDP_NULL && V1L_Flush(req->wrk))
+ wl = V1L_Write(vdx->wrk, ptr, len);
+ if (act > VDP_NULL && V1L_Flush(vdx->wrk))
return (-1);
if (len != wl)
return (-1);
diff --git a/bin/varnishd/http2/cache_http2_deliver.c b/bin/varnishd/http2/cache_http2_deliver.c
index 190356d5d..24e462564 100644
--- a/bin/varnishd/http2/cache_http2_deliver.c
+++ b/bin/varnishd/http2/cache_http2_deliver.c
@@ -100,12 +100,13 @@ h2_fini(struct req *req, void **priv)
}
static int v_matchproto_(vdp_bytes_f)
-h2_bytes(struct req *req, enum vdp_action act, void **priv,
+h2_bytes(struct vdp_ctx *vdx, enum vdp_action act, void **priv,
const void *ptr, ssize_t len)
{
struct h2_req *r2;
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ CHECK_OBJ_NOTNULL(vdx, VDP_CTX_MAGIC);
+ CHECK_OBJ_NOTNULL(vdx->req, REQ_MAGIC);
CAST_OBJ_NOTNULL(r2, *priv, H2_REQ_MAGIC);
(void)act;
@@ -113,9 +114,9 @@ h2_bytes(struct req *req, enum vdp_action act, void **priv,
return (-1);
if (len == 0)
return (0);
- H2_Send_Get(req->wrk, r2->h2sess, r2);
- H2_Send(req->wrk, r2, H2_F_DATA, H2FF_NONE, len, ptr,
- &req->acct.resp_bodybytes);
+ H2_Send_Get(vdx->wrk, r2->h2sess, r2);
+ H2_Send(vdx->wrk, r2, H2_F_DATA, H2FF_NONE, len, ptr,
+ &vdx->req->acct.resp_bodybytes);
H2_Send_Rel(r2->h2sess, r2);
return (0);
}
More information about the varnish-commit
mailing list