[master] 5f7eef6 Make two functions to get from req/bo to VRT_CTX

Poul-Henning Kamp phk at FreeBSD.org
Tue May 1 09:45:27 UTC 2018


commit 5f7eef62fdf542bd3e4cda21da102bf83a311367
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 1 07:37:27 2018 +0000

    Make two functions to get from req/bo to VRT_CTX

diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index 2c4012e..985d142 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -88,15 +88,7 @@ vdi_resolve(struct busyobj *bo)
 	CHECK_OBJ_ORNULL(bo->director_req, DIRECTOR_MAGIC);
 
 	INIT_OBJ(&ctx, VRT_CTX_MAGIC);
-	ctx.vcl = bo->vcl;
-	ctx.vsl = bo->vsl;
-	ctx.http_bereq = bo->bereq;
-	ctx.http_beresp = bo->beresp;
-	ctx.bo = bo;
-	ctx.sp = bo->sp;
-	ctx.now = bo->t_prev;
-	ctx.ws = bo->ws;
-	ctx.method = 0;
+	VCL_Bo2Ctx(&ctx, bo);
 
 	for (d = bo->director_req; d != NULL &&
 	    d->methods->resolve != NULL; d = d2) {
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index d80b347..1475686 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -389,6 +389,9 @@ void VCL_Refresh(struct vcl **);
 void VCL_Rel(struct vcl **);
 const char *VCL_Return_Name(unsigned);
 const char *VCL_Method_Name(unsigned);
+void VCL_Bo2Ctx(struct vrt_ctx *, struct busyobj *);
+void VCL_Req2Ctx(struct vrt_ctx *, struct req *);
+
 #define VCL_MET_MAC(l,u,t,b) \
     void VCL_##l##_method(struct vcl *, struct worker *, struct req *, \
 	struct busyobj *bo, void *specific);
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 178ae2c..ed57193 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -69,6 +69,42 @@ static uintptr_t ws_snapshot_cli;
 
 /*--------------------------------------------------------------------*/
 
+void
+VCL_Bo2Ctx(struct vrt_ctx *ctx, struct busyobj *bo)
+{
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+	ctx->vcl = bo->vcl;
+	ctx->vsl = bo->vsl;
+	ctx->http_bereq = bo->bereq;
+	ctx->http_beresp = bo->beresp;
+	ctx->bo = bo;
+	ctx->sp = bo->sp;
+	ctx->now = bo->t_prev;
+	ctx->ws = bo->ws;
+}
+
+void
+VCL_Req2Ctx(struct vrt_ctx *ctx, struct req *req)
+{
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+
+	ctx->vcl = req->vcl;
+	ctx->vsl = req->vsl;
+	ctx->http_req = req->http;
+	ctx->http_req_top = req->top->http;
+	ctx->http_resp = req->resp;
+	ctx->req = req;
+	ctx->sp = req->sp;
+	ctx->now = req->t_prev;
+	ctx->ws = req->ws;
+}
+
+/*--------------------------------------------------------------------*/
+
 static struct vrt_ctx *
 vcl_get_ctx(unsigned method, int msg)
 {
diff --git a/bin/varnishd/cache/cache_vcl_vrt.c b/bin/varnishd/cache/cache_vcl_vrt.c
index 6e45c9f..b97aae1 100644
--- a/bin/varnishd/cache/cache_vcl_vrt.c
+++ b/bin/varnishd/cache/cache_vcl_vrt.c
@@ -401,7 +401,6 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
     void *specific, unsigned method, vcl_func_f *func)
 {
 	uintptr_t aws;
-	struct vsl_log *vsl = NULL;
 	struct vrt_ctx ctx;
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -410,33 +409,17 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 		CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 		CHECK_OBJ_NOTNULL(req->sp, SESS_MAGIC);
 		CHECK_OBJ_NOTNULL(req->vcl, VCL_MAGIC);
-		vsl = req->vsl;
-		ctx.vcl = req->vcl;
-		ctx.http_req = req->http;
-		ctx.http_req_top = req->top->http;
-		ctx.http_resp = req->resp;
-		ctx.req = req;
-		ctx.sp = req->sp;
-		ctx.now = req->t_prev;
-		ctx.ws = req->ws;
+		VCL_Req2Ctx(&ctx, req);
 	}
 	if (bo != NULL) {
 		if (req)
 			assert(method == VCL_MET_PIPE);
 		CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 		CHECK_OBJ_NOTNULL(bo->vcl, VCL_MAGIC);
-		vsl = bo->vsl;
-		ctx.vcl = bo->vcl;
-		ctx.http_bereq = bo->bereq;
-		ctx.http_beresp = bo->beresp;
-		ctx.bo = bo;
-		ctx.sp = bo->sp;
-		ctx.now = bo->t_prev;
-		ctx.ws = bo->ws;
+		VCL_Bo2Ctx(&ctx, bo);
 	}
 	assert(ctx.now != 0);
 	ctx.syntax = ctx.vcl->conf->syntax;
-	ctx.vsl = vsl;
 	ctx.specific = specific;
 	ctx.method = method;
 	wrk->handling = 0;
@@ -444,10 +427,10 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 	aws = WS_Snapshot(wrk->aws);
 	wrk->cur_method = method;
 	wrk->seen_methods |= method;
-	AN(vsl);
-	VSLb(vsl, SLT_VCL_call, "%s", VCL_Method_Name(method));
+	AN(ctx.vsl);
+	VSLb(ctx.vsl, SLT_VCL_call, "%s", VCL_Method_Name(method));
 	func(&ctx);
-	VSLb(vsl, SLT_VCL_return, "%s", VCL_Return_Name(wrk->handling));
+	VSLb(ctx.vsl, SLT_VCL_return, "%s", VCL_Return_Name(wrk->handling));
 	wrk->cur_method |= 1;		// Magic marker
 	if (wrk->handling == VCL_RET_FAIL)
 		wrk->stats->vcl_fail++;


More information about the varnish-commit mailing list