[master] b6da2dc Remove the wrk argument from VCL/VRT, now everything we need is encapsulated in the vrt_ctx.

Poul-Henning Kamp phk at varnish-cache.org
Wed May 1 11:50:37 CEST 2013


commit b6da2dc74f48d6f2375d9025a21773b4a4a0c31c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed May 1 09:50:09 2013 +0000

    Remove the wrk argument from VCL/VRT, now everything we need is
    encapsulated in the vrt_ctx.

diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 3875326..c7f7002 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -174,6 +174,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
 	struct vcls *vcl;
 	struct VCL_conf const *cnf;
 	struct vrt_ctx ctx;
+	unsigned hand = 0;
 
 	ASSERT_CLI();
 
@@ -220,7 +221,10 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
 	REPLACE(vcl->name, name);
 	VCLI_Out(cli, "Loaded \"%s\" as \"%s\"", fn , name);
 	VTAILQ_INSERT_TAIL(&vcl_head, vcl, list);
-	(void)vcl->conf->init_func(&ctx, NULL);
+	ctx.method = VCL_MET_INIT;
+	ctx.handling = &hand;
+	(void)vcl->conf->init_func(&ctx);
+	assert(hand == VCL_RET_OK);
 	Lck_Lock(&vcl_mtx);
 	if (vcl_active == NULL)
 		vcl_active = vcl;
@@ -239,6 +243,7 @@ static void
 VCL_Nuke(struct vcls *vcl)
 {
 	struct vrt_ctx ctx;
+	unsigned hand = 0;
 
 	memset(&ctx, 0, sizeof ctx);
 	ctx.magic = VRT_CTX_MAGIC;
@@ -247,7 +252,10 @@ VCL_Nuke(struct vcls *vcl)
 	assert(vcl->conf->discard);
 	assert(vcl->conf->busy == 0);
 	VTAILQ_REMOVE(&vcl_head, vcl, list);
-	(void)vcl->conf->fini_func(&ctx, NULL);
+	ctx.method = VCL_MET_FINI;
+	ctx.handling = &hand;
+	(void)vcl->conf->fini_func(&ctx);
+	assert(hand == VCL_RET_OK);
 	vcl->conf->fini_vcl(NULL);
 	free(vcl->name);
 	(void)dlclose(vcl->dlh);
@@ -416,12 +424,14 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
 		ctx.bo = bo;
 	}
 	ctx.ws = ws;
+	ctx.method = method;
+	ctx.handling = &wrk->handling;
 	aws = WS_Snapshot(wrk->aws);
 	wrk->handling = 0;
 	wrk->cur_method = method;
 	AN(vsl);
 	VSLb(vsl, SLT_VCL_call, "%s", VCL_Method_Name(method));
-	(void)func(&ctx, wrk);
+	(void)func(&ctx);
 	VSLb(vsl, SLT_VCL_return, "%s", VCL_Return_Name(wrk->handling));
 	wrk->cur_method = 0;
 	WS_Reset(wrk->aws, aws);
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 4c44959..32764fc 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -264,16 +264,12 @@ VRT_SetHdr(const struct vrt_ctx *ctx , const struct gethdr_s *hs,
 /*--------------------------------------------------------------------*/
 
 void
-VRT_handling(struct worker *wrk, unsigned hand)
+VRT_handling(const struct vrt_ctx *ctx, unsigned hand)
 {
 
-	if (wrk == NULL) {
-		assert(hand == VCL_RET_OK);
-		return;
-	}
-	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	assert(hand < VCL_RET_MAX);
-	wrk->handling = hand;
+	*ctx->handling = hand;
 }
 
 /*--------------------------------------------------------------------
@@ -516,17 +512,15 @@ VRT_CacheReqBody(const struct vrt_ctx *ctx, long long maxsize)
  */
 
 void
-VRT_purge(const struct worker *wrk, const struct vrt_ctx *ctx, double ttl,
-    double grace)
+VRT_purge(const struct vrt_ctx *ctx, double ttl, double grace)
 {
 
-	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
-	if (wrk->cur_method == VCL_MET_LOOKUP)
+	if (ctx->method == VCL_MET_LOOKUP)
 		HSH_Purge(ctx->req, ctx->req->obj->objcore->objhead,
 		    ttl, grace);
-	else if (wrk->cur_method == VCL_MET_MISS)
+	else if (ctx->method == VCL_MET_MISS)
 		HSH_Purge(ctx->req, ctx->req->objcore->objhead,
 		    ttl, grace);
 }
diff --git a/bin/varnishtest/tests/c00033.vtc b/bin/varnishtest/tests/c00033.vtc
index 809387d..7f0bda3 100644
--- a/bin/varnishtest/tests/c00033.vtc
+++ b/bin/varnishtest/tests/c00033.vtc
@@ -25,13 +25,13 @@ varnish v1 -vcl+backend {
 
 	sub vcl_lookup {
 		if (req.method == "PURGE") {
-			C{ VRT_purge(wrk, ctx, 0, 0); }C
+			C{ VRT_purge(ctx, 0, 0); }C
 			error 456 "got it";
 		}
 	}
 	sub vcl_miss {
 		if (req.method == "PURGE") {
-			C{ VRT_purge(wrk, ctx, 0, 0); }C
+			C{ VRT_purge(ctx, 0, 0); }C
 			error 456 "got it";
 		}
 	}
diff --git a/include/vrt.h b/include/vrt.h
index 063cf9a..0657e4d 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -70,6 +70,9 @@ struct vrt_ctx {
 	unsigned			magic;
 #define VRT_CTX_MAGIC			0x6bb8f0db
 
+	unsigned			method;
+	unsigned			*handling;
+
 	struct vsl_log			*vsl;
 	struct VCL_conf			*vcl;
 	struct ws			*ws;
@@ -82,6 +85,7 @@ struct vrt_ctx {
 	struct busyobj			*bo;
 	struct http			*http_bereq;
 	struct http			*http_beresp;
+
 };
 
 /***********************************************************************/
@@ -196,8 +200,7 @@ const char *VRT_regsub(const struct vrt_ctx *, int all, const char *,
     void *, const char *);
 
 void VRT_ban_string(const char *);
-void VRT_purge(const struct worker *, const struct vrt_ctx *, double ttl,
-    double grace);
+void VRT_purge(const struct vrt_ctx *, double ttl, double grace);
 
 void VRT_count(const struct vrt_ctx *, unsigned);
 int VRT_rewrite(const char *, const char *);
@@ -208,7 +211,7 @@ const struct gethdr_s *VRT_MkGethdr(const struct vrt_ctx *,enum gethdr_e,
     const char *);
 char *VRT_GetHdr(const struct vrt_ctx *, const struct gethdr_s *);
 void VRT_SetHdr(const struct vrt_ctx *, const struct gethdr_s *, const char *, ...);
-void VRT_handling(struct worker *, unsigned hand);
+void VRT_handling(const struct vrt_ctx *, unsigned hand);
 
 void VRT_hashdata(const struct vrt_ctx *, const char *str, ...);
 
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index 509141f..88b96fc 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -707,7 +707,7 @@ struct worker;
 
 typedef int vcl_init_f(struct cli *);
 typedef void vcl_fini_f(struct cli *);
-typedef int vcl_func_f(const struct vrt_ctx *ctx, struct worker *);
+typedef int vcl_func_f(const struct vrt_ctx *ctx);
 """)
 
 
diff --git a/lib/libvcl/vcc_action.c b/lib/libvcl/vcc_action.c
index a5bd769..b84df6f 100644
--- a/lib/libvcl/vcc_action.c
+++ b/lib/libvcl/vcc_action.c
@@ -79,7 +79,7 @@ parse_error(struct vcc *tl)
 			Fb(tl, 1, ", 0\n");
 	}
 	Fb(tl, 1, ");\n");
-	Fb(tl, 1, "VRT_handling(wrk, VCL_RET_ERROR);\n");
+	Fb(tl, 1, "VRT_handling(ctx, VCL_RET_ERROR);\n");
 	Fb(tl, 1, "return(1);\n");
 }
 
@@ -314,7 +314,7 @@ parse_return(struct vcc *tl)
 #define VCL_RET_MAC(l, U, B)						\
 	do {								\
 		if (vcc_IdIs(tl->t, #l)) {				\
-			Fb(tl, 1, "VRT_handling(wrk, VCL_RET_" #U ");\n"); \
+			Fb(tl, 1, "VRT_handling(ctx, VCL_RET_" #U ");\n"); \
 			Fb(tl, 1, "return (1);\n");			\
 			vcc_ProcAction(tl->curproc, VCL_RET_##U, tl->t);\
 			retval = 1;					\
@@ -349,7 +349,7 @@ parse_purge(struct vcc *tl)
 {
 
 	vcc_NextToken(tl);
-	Fb(tl, 1, "VRT_purge(wrk, ctx, 0, 0);\n");
+	Fb(tl, 1, "VRT_purge(ctx, 0, 0);\n");
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/lib/libvcl/vcc_compile.c b/lib/libvcl/vcc_compile.c
index a3de471..b04236f 100644
--- a/lib/libvcl/vcc_compile.c
+++ b/lib/libvcl/vcc_compile.c
@@ -693,8 +693,7 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp)
 	for (i = 0; i < VCL_MET_MAX; i++) {
 		Fc(tl, 1, "\nstatic int __match_proto__(vcl_func_f)\n");
 		Fc(tl, 1,
-		    "VGC_function_%s(const struct vrt_ctx *ctx,"
-		    " struct worker *wrk)\n",
+		    "VGC_function_%s(const struct vrt_ctx *ctx)\n",
 		    method_tab[i].name);
 		AZ(VSB_finish(tl->fm[i]));
 		Fc(tl, 1, "{\n");



More information about the varnish-commit mailing list