[master] 6ed750d Eliminate some trival VFP uses of busyobj.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Jul 15 11:07:32 CEST 2014
commit 6ed750d674871e41248281468e572fa75804e564
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Jul 15 09:07:11 2014 +0000
Eliminate some trival VFP uses of busyobj.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 5215775..b8ca57f 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -459,6 +459,10 @@ struct vfp_ctx {
struct vfp_entry_s vfp;
struct vfp_entry *vfp_nxt;
+
+ struct vsl_log *vsl;
+ struct http *http;
+ uint64_t bodybytes;
};
struct busyobj {
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 3c367be..cc5f8d6 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -154,7 +154,7 @@ vfp_esi_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe)
ALLOC_OBJ(vef, VEF_MAGIC);
if (vef == NULL)
return (VFP_ERROR);
- vef->vgz = VGZ_NewGzip(vc->bo->vsl, "G F E");
+ vef->vgz = VGZ_NewGzip(vc->vsl, "G F E");
vef->vep = VEP_Init(vc->bo, vfp_vep_callback, vef);
vef->ibuf_sz = cache_param->gzip_buffer;
vef->ibuf = calloc(1L, vef->ibuf_sz);
@@ -164,10 +164,10 @@ vfp_esi_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe)
vef->ibuf_o = vef->ibuf;
vfe->priv1 = vef;
- RFC2616_Weaken_Etag(vc->bo->beresp);
- http_Unset(vc->bo->beresp, H_Content_Length);
- http_Unset(vc->bo->beresp, H_Content_Encoding);
- http_SetHeader(vc->bo->beresp, "Content-Encoding: gzip");
+ RFC2616_Weaken_Etag(vc->http);
+ http_Unset(vc->http, H_Content_Length);
+ http_Unset(vc->http, H_Content_Encoding);
+ http_SetHeader(vc->http, "Content-Encoding: gzip");
return (VFP_OK);
}
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index d3153a9..32cd3da 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -367,9 +367,10 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
} else
do_ims = 0;
- bo->vfc.magic = VFP_CTX_MAGIC;
- VTAILQ_INIT(&bo->vfc.vfp);
+ VFP_Setup(&bo->vfc);
bo->vfc.bo = bo;
+ bo->vfc.http = bo->beresp;
+ bo->vfc.vsl = bo->vsl;
VCL_backend_response_method(bo->vcl, wrk, NULL, bo, bo->beresp->ws);
@@ -519,6 +520,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
if (bo->htc.body_status != BS_NONE) {
assert(bo->htc.body_status != BS_ERROR);
VFP_Fetch_Body(bo);
+ bo->acct.beresp_bodybytes = bo->vfc.bodybytes;
}
if (bo->failed && !bo->do_stream) {
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index 10525b2..a49a58a 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -62,7 +62,7 @@ VFP_Error(const struct vfp_ctx *vc, const char *fmt, ...)
assert(vc->bo->state >= BOS_REQ_DONE);
if (!vc->bo->failed) {
va_start(ap, fmt);
- VSLbv(vc->bo->vsl, SLT_FetchError, fmt, ap);
+ VSLbv(vc->vsl, SLT_FetchError, fmt, ap);
va_end(ap);
vc->bo->failed = 1;
}
@@ -109,6 +109,17 @@ VFP_GetStorage(struct busyobj *bo, ssize_t sz)
/**********************************************************************
*/
+void
+VFP_Setup(struct vfp_ctx *vc)
+{
+ memset(vc, 0, sizeof *vc);
+ vc->magic = VFP_CTX_MAGIC;
+ VTAILQ_INIT(&vc->vfp);
+}
+
+/**********************************************************************
+ */
+
static void
vfp_suck_fini(struct vfp_ctx *vc)
{
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
index 9ef68ea..4065cc7 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -62,6 +62,7 @@ extern const struct vfp vfp_esi;
extern const struct vfp vfp_esi_gzip;
struct vfp_entry *VFP_Push(struct vfp_ctx *, const struct vfp *, int top);
+void VFP_Setup(struct vfp_ctx *vc);
int VFP_Open(struct vfp_ctx *bo);
enum vfp_status VFP_Suck(struct vfp_ctx *, void *p, ssize_t *lp);
enum vfp_status VFP_Error(const struct vfp_ctx *, const char *fmt, ...)
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 48da134..5abefbb 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -460,18 +460,18 @@ vfp_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe)
CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
if (vc->bo->content_length == 0) {
- http_Unset(vc->bo->beresp, H_Content_Encoding);
+ http_Unset(vc->http, H_Content_Encoding);
return (VFP_NULL);
}
if (vfe->vfp->priv2 == VFP_GZIP) {
- if (http_GetHdr(vc->bo->beresp, H_Content_Encoding, NULL))
+ if (http_GetHdr(vc->http, H_Content_Encoding, NULL))
return (VFP_NULL);
- vg = VGZ_NewGzip(vc->bo->vsl, vfe->vfp->priv1);
+ vg = VGZ_NewGzip(vc->vsl, vfe->vfp->priv1);
} else {
- if (!http_HdrIs(vc->bo->beresp, H_Content_Encoding, "gzip"))
+ if (!http_HdrIs(vc->http, H_Content_Encoding, "gzip"))
return (VFP_NULL);
- vg = VGZ_NewUngzip(vc->bo->vsl, vfe->vfp->priv1);
+ vg = VGZ_NewUngzip(vc->vsl, vfe->vfp->priv1);
}
if (vg == NULL)
return (VFP_ERROR);
@@ -482,13 +482,13 @@ vfp_gzip_init(struct vfp_ctx *vc, struct vfp_entry *vfe)
AZ(vg->m_len);
if (vfe->vfp->priv2 == VFP_GUNZIP || vfe->vfp->priv2 == VFP_GZIP) {
- http_Unset(vc->bo->beresp, H_Content_Encoding);
- http_Unset(vc->bo->beresp, H_Content_Length);
- RFC2616_Weaken_Etag(vc->bo->beresp);
+ http_Unset(vc->http, H_Content_Encoding);
+ http_Unset(vc->http, H_Content_Length);
+ RFC2616_Weaken_Etag(vc->http);
}
if (vfe->vfp->priv2 == VFP_GZIP)
- http_SetHeader(vc->bo->beresp, "Content-Encoding: gzip");
+ http_SetHeader(vc->http, "Content-Encoding: gzip");
return (VFP_OK);
}
diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c
index 233267c..1f53747 100644
--- a/bin/varnishd/cache/cache_http1_fetch.c
+++ b/bin/varnishd/cache/cache_http1_fetch.c
@@ -52,7 +52,6 @@ v1f_pull_straight(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
struct http_conn *htc;
CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
- CHECK_OBJ_NOTNULL(vc->bo, BUSYOBJ_MAGIC);
CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
CAST_OBJ_NOTNULL(htc, vfe->priv1, HTTP_CONN_MAGIC);
AN(p);
@@ -66,7 +65,7 @@ v1f_pull_straight(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
if (vfe->priv2 < l)
l = vfe->priv2;
lr = HTTP1_Read(htc, p, l);
- vc->bo->acct.beresp_bodybytes += lr;
+ vc->bodybytes += lr;
if (lr <= 0)
return (VFP_Error(vc, "straight insufficient bytes"));
*lp = lr;
@@ -95,14 +94,12 @@ v1f_pull_chunked(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
struct http_conn *htc;
CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
- CHECK_OBJ_NOTNULL(vc->bo, BUSYOBJ_MAGIC);
CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
CAST_OBJ_NOTNULL(htc, vfe->priv1, HTTP_CONN_MAGIC);
AN(p);
AN(lp);
- switch (HTTP1_Chunked(htc, &vfe->priv2, &err,
- &vc->bo->acct.beresp_bodybytes, p, lp)) {
+ switch (HTTP1_Chunked(htc, &vfe->priv2, &err, &vc->bodybytes, p, lp)) {
case H1CR_ERROR:
return (VFP_Error(vc, "%s", err));
case H1CR_MORE:
@@ -133,8 +130,6 @@ v1f_pull_eof(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
CAST_OBJ_NOTNULL(htc, vfe->priv1, HTTP_CONN_MAGIC);
AN(p);
- // XXX: update vc->bo->acct.beresp_bodybytes ?
-
AN(lp);
l = *lp;
@@ -145,6 +140,7 @@ v1f_pull_eof(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
if (lr == 0)
return (VFP_END);
*lp = lr;
+ vc->bodybytes += lr;
return (VFP_OK);
}
@@ -153,7 +149,6 @@ static const struct vfp v1f_eof = {
.pull = v1f_pull_eof,
};
-
/*--------------------------------------------------------------------
*/
More information about the varnish-commit
mailing list