[master] 8ce440a39 Always report bodybytes as #bytes processed by bottom VFP.

Poul-Henning Kamp phk at FreeBSD.org
Tue Sep 29 09:43:06 UTC 2020


commit 8ce440a392c8874131ecf42a7fa2566ff28fec92
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Sep 29 09:42:09 2020 +0000

    Always report bodybytes as #bytes processed by bottom VFP.
    
    Fixes #3354

diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index b7243235a..065043871 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -101,7 +101,7 @@ vbf_cleanup(struct busyobj *bo)
 	vfc = bo->vfc;
 	CHECK_OBJ_NOTNULL(vfc, VFP_CTX_MAGIC);
 
-	VFP_Close(vfc);
+	bo->acct.beresp_bodybytes += VFP_Close(vfc);
 	bo->filter_list = NULL;
 
 	if (bo->director_state != DIR_S_NULL)
@@ -558,7 +558,6 @@ vbf_stp_fetchbody(struct worker *wrk, struct busyobj *bo)
 		AZ(vfc->failed);
 		vfps = VFP_Suck(vfc, ptr, &l);
 		if (l > 0 && vfps != VFP_ERROR) {
-			bo->acct.beresp_bodybytes += l;
 			VFP_Extend(vfc, l);
 			if (est >= l)
 				est -= l;
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index fdf4b70f1..760cc04a3 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -115,20 +115,24 @@ VFP_Setup(struct vfp_ctx *vc, struct worker *wrk)
 }
 
 /**********************************************************************
+ * Returns the number of bytes processed by the lowest VFP in the stack
  */
 
-void
+size_t
 VFP_Close(struct vfp_ctx *vc)
 {
 	struct vfp_entry *vfe, *tmp;
+	size_t rv = 0;
 
 	VTAILQ_FOREACH_SAFE(vfe, &vc->vfp, list, tmp) {
 		if (vfe->vfp->fini != NULL)
 			vfe->vfp->fini(vc, vfe);
+		rv = vfe->bytes_out;
 		VSLb(vc->wrk->vsl, SLT_VfpAcct, "%s %ju %ju", vfe->vfp->name,
-		    (uintmax_t)vfe->calls, (uintmax_t)vfe->bytes_out);
+		    (uintmax_t)vfe->calls, (uintmax_t)rv);
 		VTAILQ_REMOVE(&vc->vfp, vfe, list);
 	}
+	return (rv);
 }
 
 int
diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c
index 966526e22..0d417ab6c 100644
--- a/bin/varnishd/cache/cache_req_body.c
+++ b/bin/varnishd/cache/cache_req_body.c
@@ -117,7 +117,6 @@ vrb_pull(struct req *req, ssize_t maxsize, objiterate_f *func, void *priv)
 		vfps = VFP_Suck(vfc, ptr, &l);
 		if (l > 0 && vfps != VFP_ERROR) {
 			req_bodybytes += l;
-			req->acct.req_bodybytes += l;
 			if (yet >= l)
 				yet -= l;
 			if (func != NULL) {
@@ -130,7 +129,7 @@ vrb_pull(struct req *req, ssize_t maxsize, objiterate_f *func, void *priv)
 		}
 
 	} while (vfps == VFP_OK);
-	VFP_Close(vfc);
+	req->acct.req_bodybytes += VFP_Close(vfc);
 	VSLb_ts_req(req, "ReqBody", VTIM_real());
 	if (func != NULL) {
 		HSH_DerefBoc(req->wrk, req->body_oc);
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 9a68f4229..16c4aaaaa 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -251,7 +251,7 @@ enum vfp_status VFP_GetStorage(struct vfp_ctx *, ssize_t *sz, uint8_t **ptr);
 void VFP_Extend(const struct vfp_ctx *, ssize_t sz);
 void VFP_Setup(struct vfp_ctx *vc, struct worker *wrk);
 int VFP_Open(struct vfp_ctx *bo);
-void VFP_Close(struct vfp_ctx *bo);
+size_t VFP_Close(struct vfp_ctx *bo);
 
 extern const struct vfp VFP_gunzip;
 extern const struct vfp VFP_gzip;
diff --git a/bin/varnishtest/tests/r3354.vtc b/bin/varnishtest/tests/r3354.vtc
new file mode 100644
index 000000000..985c4b7d7
--- /dev/null
+++ b/bin/varnishtest/tests/r3354.vtc
@@ -0,0 +1,35 @@
+varnishtest "Bodybytes is #bytes in bottom VFP"
+
+server s1 {
+	rxreq
+	txresp -hdr "Foo: bar" -bodylen 1000
+	rxreq
+	txresp -bodylen 500
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_backend_response {
+		set beresp.do_gzip = true;
+		if (beresp.http.foo == "bar") {
+			set beresp.do_esi = true;
+		}
+	}
+} -start
+
+varnish v1 -cliok "param.set vsl_mask +VfpAcct"
+
+client c1 {
+	txreq -url /1
+	rxresp
+	expect resp.bodylen == 1000
+} -run
+
+varnish v1 -expect VBE.vcl1.s1.beresp_bodybytes == 1000
+
+client c1 {
+	txreq -url /2
+	rxresp
+	expect resp.bodylen == 500
+} -run
+
+varnish v1 -expect VBE.vcl1.s1.beresp_bodybytes == 1500


More information about the varnish-commit mailing list