[master] a8e34499f Revert "Now that we have decided bump VRT_MAJOR, drop the reqtop struct"

Nils Goroll nils.goroll at uplex.de
Wed Nov 13 08:48:06 UTC 2019


commit a8e34499f295f20ca28c6c1b108c71e107c854cb
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue May 28 13:14:55 2019 +0200

    Revert "Now that we have decided bump VRT_MAJOR, drop the reqtop struct"
    
    This reverts commit d67993451bda7eeb7c0ea3c5528a8353f283a190.
    
    We will use struct reqtop for vcl0 and PRIV_TOP in follow-up commits.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 75bbbe4ad..689fe90df 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -441,6 +441,11 @@ struct busyobj {
 
 /*--------------------------------------------------------------------*/
 
+struct reqtop {
+	unsigned		magic;
+#define REQTOP_MAGIC		0x57fbda52
+	struct req		*topreq;
+};
 
 struct req {
 	unsigned		magic;
@@ -451,7 +456,7 @@ struct req {
 	enum sess_close		doclose;
 	unsigned		restarts;
 	unsigned		esi_level;
-	struct req		*topreq;	/* esi_level == 0 request */
+	struct reqtop		*top;	/* esi_level == 0 request */
 	struct vcl		*vcl0;
 
 #define REQ_FLAG(l, r, w, d) unsigned	l:1;
@@ -532,7 +537,7 @@ struct req {
 	struct vcf		*vcf;
 };
 
-#define IS_TOPREQ(req) ((req)->topreq == (req))
+#define IS_TOPREQ(req) ((req)->top == NULL || (req)->top->topreq == (req))
 
 /*--------------------------------------------------------------------
  * Struct sess is a high memory-load structure because sessions typically
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index f9fe82241..51413eaf4 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -113,7 +113,7 @@ ved_include(struct req *preq, const char *src, const char *host,
 	enum req_fsm_nxt s;
 
 	CHECK_OBJ_NOTNULL(preq, REQ_MAGIC);
-	CHECK_OBJ_NOTNULL(preq->topreq, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(preq->top, REQTOP_MAGIC);
 	sp = preq->sp;
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(ecx, ECX_MAGIC);
@@ -139,7 +139,7 @@ ved_include(struct req *preq, const char *src, const char *host,
 
 	req->esi_level = preq->esi_level + 1;
 
-	req->topreq = preq->topreq;
+	req->top = preq->top;
 
 	HTTP_Setup(req->http, req->ws, req->vsl, SLT_ReqMethod);
 	HTTP_Dup(req->http, preq->http0);
@@ -171,8 +171,8 @@ ved_include(struct req *preq, const char *src, const char *host,
 	req->req_body_status = REQ_BODY_NONE;
 
 	AZ(req->vcl);
-	if (req->topreq->vcl0)
-		req->vcl = req->topreq->vcl0;
+	if (req->vcl0)
+		req->vcl = req->vcl0;
 	else
 		req->vcl = preq->vcl;
 	VCL_Ref(req->vcl);
@@ -264,6 +264,16 @@ ved_vdp_esi_init(struct req *req, void **priv)
 	*priv = ecx;
 	RFC2616_Weaken_Etag(req->resp);
 
+	if (IS_TOPREQ(req)) {
+		Req_MakeTop(req);
+		if (req->top == NULL) {
+			VSLb(req->vsl, SLT_Error,
+			    "(top)request workspace overflow");
+			Req_Fail(req, SC_OVERLOAD);
+			return (-1);
+		}
+	}
+
 	req->res_mode |= RES_ESI;
 	if (req->resp_len != 0)
 		req->resp_len = -1;
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 343fc47dc..6d7391f44 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -485,6 +485,20 @@ pan_busyobj(struct vsb *vsb, const struct busyobj *bo)
 
 /*--------------------------------------------------------------------*/
 
+static void
+pan_top(struct vsb *vsb, const struct reqtop *top)
+{
+	VSB_printf(vsb, "top = %p {\n", top);
+	if (PAN_already(vsb, top))
+		return;
+	VSB_indent(vsb, 2);
+	pan_req(vsb, top->topreq);
+	VSB_indent(vsb, -2);
+	VSB_cat(vsb, "},\n");
+}
+
+/*--------------------------------------------------------------------*/
+
 static void
 pan_req(struct vsb *vsb, const struct req *req)
 {
@@ -561,11 +575,8 @@ pan_req(struct vsb *vsb, const struct req *req)
 
 	pan_privs(vsb, req->privs);
 
-	VSB_cat(vsb, "topreq = {\n");
-	VSB_indent(vsb, 2);
-	pan_req(vsb, req->topreq);
-	VSB_indent(vsb, -2);
-	VSB_cat(vsb, "},\n");
+	if (req->top != NULL)
+		pan_top(vsb, req->top);
 
 	VSB_indent(vsb, -2);
 	VSB_cat(vsb, "},\n");
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index 767903682..7812172de 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -63,7 +63,6 @@ Req_AcctLogCharge(struct VSC_main_wrk *ds, struct req *req)
 		    (uintmax_t)(a->resp_hdrbytes + a->resp_bodybytes));
 	}
 
-	AN(req->topreq);
 	if (IS_TOPREQ(req)) {
 #define ACCT(foo) ds->s_##foo += a->foo;
 #include "tbl/acct_fields_req.h"
@@ -146,8 +145,6 @@ Req_New(const struct worker *wrk, struct sess *sp)
 	req->t_prev = NAN;
 	req->t_req = NAN;
 
-	req->topreq = req;
-
 	return (req);
 }
 
@@ -173,7 +170,7 @@ Req_Release(struct req *req)
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	MPL_AssertSane(req);
 	VSL_Flush(req->vsl, 0);
-	req->topreq = NULL;
+	req->top = NULL;
 	MPL_Free(pp->mpl_req, req);
 }
 
@@ -192,6 +189,7 @@ Req_Rollback(struct req *req)
 	if (WS_Overflowed(req->ws))
 		req->wrk->stats->ws_client_overflow++;
 	WS_Reset(req->ws, req->ws_req);
+	req->top = NULL;
 }
 
 /*----------------------------------------------------------------------
@@ -205,7 +203,6 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req)
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	CHECK_OBJ_NOTNULL(req->topreq, REQ_MAGIC);
 	assert(sp == req->sp);
 	AZ(req->vcl0);
 
@@ -238,6 +235,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++;
@@ -256,3 +254,20 @@ Req_Fail(struct req *req, enum sess_close reason)
 	AN(req->transport->req_fail);
 	req->transport->req_fail(req, reason);
 }
+
+/*----------------------------------------------------------------------
+ */
+
+void
+Req_MakeTop(struct req *req)
+{
+
+	CHECK_OBJ_ORNULL(req->top, REQTOP_MAGIC);
+	if (req->top != NULL)
+		return;
+	req->top = WS_Alloc(req->ws, sizeof *req->top);
+	if (req->top != NULL) {
+		INIT_OBJ(req->top, REQTOP_MAGIC);
+		req->top->topreq = req;
+	}
+}
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 4fb23dd92..fe53f756e 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -1041,7 +1041,6 @@ CNT_Embark(struct worker *wrk, struct req *req)
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	CHECK_OBJ_NOTNULL(req->topreq, REQ_MAGIC);
 
 	/* wrk can have changed for restarts */
 	req->vfc->wrk = req->wrk = wrk;
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index b8ccb4704..b455600ca 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -351,6 +351,7 @@ void Req_Rollback(struct req *req);
 void Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req);
 void Req_Fail(struct req *req, enum sess_close reason);
 void Req_AcctLogCharge(struct VSC_main_wrk *, struct req *);
+void Req_MakeTop(struct req *req);
 
 /* cache_req_body.c */
 int VRB_Ignore(struct req *);
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index f9072c068..51cc21430 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -97,13 +97,15 @@ VCL_Req2Ctx(struct vrt_ctx *ctx, struct req *req)
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	CHECK_OBJ_ORNULL(req->topreq, REQ_MAGIC);
-	CHECK_OBJ_NOTNULL(req->wrk, WORKER_MAGIC);
 
 	ctx->vcl = req->vcl;
 	ctx->vsl = req->vsl;
 	ctx->http_req = req->http;
-	ctx->http_req_top = req->topreq->http;
+	CHECK_OBJ_ORNULL(req->top, REQTOP_MAGIC);
+	if (req->top != NULL)
+		ctx->http_req_top = req->top->topreq->http;
+	else
+		ctx->http_req_top = req->http;
 	ctx->http_resp = req->resp;
 	ctx->req = req;
 	ctx->sp = req->sp;
diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c
index 33bfc4926..d8b2988d0 100644
--- a/bin/varnishd/cache/cache_vrt_priv.c
+++ b/bin/varnishd/cache/cache_vrt_priv.c
@@ -171,7 +171,12 @@ VRT_priv_top(VRT_CTX, const void *vmod_id)
 		NEEDLESS(return (NULL));
 	}
 	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
-	req = ctx->req->topreq;
+	req = ctx->req;
+	if (req->top != NULL) {
+		CHECK_OBJ_NOTNULL(req->top, REQTOP_MAGIC);
+		CHECK_OBJ_NOTNULL(req->top->topreq, REQ_MAGIC);
+		req = req->top->topreq;
+	}
 	return (vrt_priv_dynamic(
 	    req->ws,
 	    req->privs,
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 2617db9e1..453499b99 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -428,6 +428,7 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 		CHECK_OBJ(req, REQ_MAGIC);
 		CHECK_OBJ_NOTNULL(req->sp, SESS_MAGIC);
 		CHECK_OBJ_NOTNULL(req->vcl, VCL_MAGIC);
+		CHECK_OBJ_ORNULL(req->top, REQTOP_MAGIC);
 		VCL_Req2Ctx(&ctx, req);
 	}
 	if (bo != NULL) {


More information about the varnish-commit mailing list