[master] 7ccd8e607 Generally test on req-toppines rather than esi_level

Poul-Henning Kamp phk at FreeBSD.org
Thu Dec 13 10:13:11 UTC 2018


commit 7ccd8e60721012822f8654a2bf1afc73dbf6c725
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Dec 13 08:23:00 2018 +0000

    Generally test on req-toppines rather than esi_level

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index c202381d6..f6925ea82 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -538,6 +538,8 @@ struct req {
 	struct vrt_privs	privs[1];
 };
 
+#define IS_TOPREQ(req) ((req)->top == NULL || (req)->top->topreq == (req))
+
 /*--------------------------------------------------------------------
  * Struct sess is a high memory-load structure because sessions typically
  * hang around the waiter for relatively long time.
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index fdc3e798d..3169274a3 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -256,7 +256,7 @@ ved_vdp_esi_init(struct req *req, void **priv)
 	*priv = ecx;
 	RFC2616_Weaken_Etag(req->resp);
 
-	if (req->esi_level == 0) {
+	if (IS_TOPREQ(req)) {
 		Req_MakeTop(req);
 		if (req->top == NULL) {
 			VSLb(req->vsl, SLT_Error,
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index bc1f6152d..d2f3c2d31 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -63,16 +63,11 @@ Req_AcctLogCharge(struct VSC_main_wrk *ds, struct req *req)
 		    (uintmax_t)(a->resp_hdrbytes + a->resp_bodybytes));
 	}
 
-	/*
-	 * Charge to main byte counters, except for ESI subrequests
-	 * which are charged as they pass through the topreq.
-	 * XXX: make this test req->top instead
-	 */
-#define ACCT(foo)			\
-	if (req->esi_level == 0)	\
-		ds->s_##foo += a->foo;	\
-	a->foo = 0;
+	if (IS_TOPREQ(req)) {
+#define ACCT(foo) ds->s_##foo += a->foo;
 #include "tbl/acct_fields_req.h"
+	}
+	memset(a, 0, sizeof *a);
 }
 
 /*--------------------------------------------------------------------
@@ -216,7 +211,6 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req)
 
 	req->director_hint = NULL;
 	req->restarts = 0;
-	req->top = 0;
 
 	AZ(req->privs->magic);
 
@@ -244,6 +238,7 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req)
 	req->hash_ignore_busy = 0;
 	req->esi_level = 0;
 	req->is_hit = 0;
+	req->top = 0;
 
 	if (WS_Overflowed(req->ws))
 		wrk->stats->ws_client_overflow++;
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 7255cd63c..66b1d4fa1 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -182,7 +182,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 
 	assert(wrk->handling == VCL_RET_DELIVER);
 
-	if (req->esi_level == 0 &&
+	if (IS_TOPREQ(req) &&
 	    http_IsStatus(req->resp, 200) &&
 	    req->http->conds && RFC2616_Do_Cond(req))
 		http_PutResponse(req->resp, "HTTP/1.1", 304, NULL);
@@ -917,7 +917,7 @@ cnt_recv(struct worker *wrk, struct req *req)
 		req->req_step = R_STP_LOOKUP;
 		break;
 	case VCL_RET_PIPE:
-		if (req->esi_level > 0) {
+		if (!IS_TOPREQ(req)) {
 			VSLb(req->vsl, SLT_VCL_Error,
 			    "vcl_recv{} returns pipe for ESI included object."
 			    "  Doing pass.");
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index a12c5fea2..a141df54d 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -520,7 +520,7 @@ VRT_l_req_esi(VRT_CTX, VCL_BOOL process_esi)
 	 * Only allow you to turn of esi in the main request
 	 * else everything gets confused
 	 */
-	if (ctx->req->esi_level == 0)
+	if (IS_TOPREQ(ctx->req))
 		ctx->req->disable_esi = !process_esi;
 }
 


More information about the varnish-commit mailing list