# [master] 9b091b5 In the future we will need VCL also when we don't have a "struct req" at hand, most notably in the backend functions.

Poul-Henning Kamp phk at varnish-cache.org
Mon Apr 15 23:00:48 CEST 2013

```commit 9b091b5e83f9408cc1a794ceb3dc54fd27ec1807
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Apr 15 20:59:48 2013 +0000

In the future we will need VCL also when we don't have a "struct req"
at hand, most notably in the backend functions.

Pass also a struct worker pointer to all VCL methods.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 31b8384..1b2aaed 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1016,7 +1016,7 @@ void VCL_Rel(struct VCL_conf **vcc);
void VCL_Poll(void);
const char *VCL_Return_Name(unsigned method);

-#define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct req *);
+#define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct worker *, struct req *);
#include "tbl/vcl_returns.h"
#undef VCL_MET_MAC

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 5697481..49d5fa1 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -158,7 +158,7 @@ cnt_prepresp(struct worker *wrk, struct req *req)
HTTP_Setup(req->resp, req->ws, req->vsl, HTTP_Resp);
RES_BuildHttp(req);

-	VCL_deliver_method(req);
+	VCL_deliver_method(wrk, req);
switch (req->handling) {
case VCL_RET_DELIVER:
break;
@@ -308,7 +308,7 @@ cnt_error(struct worker *wrk, struct req *req)
http_PutResponse(h, req->err_reason);
else
http_PutResponse(h, http_StatusMessage(req->err_code));
-	VCL_error_method(req);
+	VCL_error_method(wrk, req);

if (req->handling == VCL_RET_RESTART &&
req->restarts <  cache_param->max_restarts) {
@@ -416,7 +416,7 @@ cnt_fetch(struct worker *wrk, struct req *req)
AZ(bo->do_esi);
AZ(bo->do_pass);

-		VCL_response_method(req);
+		VCL_response_method(wrk, req);

if (bo->do_pass)
req->objcore->flags |= OC_F_PASS;
@@ -845,7 +845,7 @@ VSLb(req->vsl, SLT_Debug, "XXXX HIT\n");
AZ(req->objcore);
AZ(req->busyobj);

-	VCL_lookup_method(req);
+	VCL_lookup_method(wrk, req);

if ((req->obj->objcore->flags & OC_F_PASS) &&
req->handling == VCL_RET_DELIVER) {
@@ -923,8 +923,8 @@ cnt_miss(struct worker *wrk, struct req *req)
}

-	VCL_fetch_method(req);
-	VCL_miss_method(req);
+	VCL_fetch_method(wrk, req);
+	VCL_miss_method(wrk, req);

if (req->handling == VCL_RET_FETCH) {
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
@@ -988,8 +988,8 @@ cnt_pass(struct worker *wrk, struct req *req)
HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq);
http_FilterReq(req, HTTPH_R_PASS);

-	VCL_fetch_method(req);
-	VCL_pass_method(req);
+	VCL_fetch_method(wrk, req);
+	VCL_pass_method(wrk, req);

if (req->handling == VCL_RET_ERROR) {
http_Teardown(bo->bereq);
@@ -1047,7 +1047,7 @@ cnt_pipe(struct worker *wrk, struct req *req)
HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq);
http_FilterReq(req, 0);

-	VCL_pipe_method(req);
+	VCL_pipe_method(wrk, req);

if (req->handling == VCL_RET_ERROR)
INCOMPL();
@@ -1119,7 +1119,7 @@ DOT hash -> lookup [label="hash",style=bold,color=green]
*/

static enum req_fsm_nxt
-cnt_recv(const struct worker *wrk, struct req *req)
+cnt_recv(struct worker *wrk, struct req *req)
{
unsigned recv_handling;
struct SHA256Context sha256ctx;
@@ -1153,7 +1153,7 @@ cnt_recv(const struct worker *wrk, struct req *req)

http_CollectHdr(req->http, H_Cache_Control);

-	VCL_recv_method(req);
+	VCL_recv_method(wrk, req);
recv_handling = req->handling;

if (cache_param->http_gzip_support &&
@@ -1169,7 +1169,7 @@ cnt_recv(const struct worker *wrk, struct req *req)

req->sha256ctx = &sha256ctx;	/* so HSH_AddString() can find it */
SHA256_Init(req->sha256ctx);
-	VCL_hash_method(req);
+	VCL_hash_method(wrk, req);
assert(req->handling == VCL_RET_HASH);
SHA256_Final(req->digest, req->sha256ctx);
req->sha256ctx = NULL;
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index 5c19997..8971550 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -191,7 +191,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
REPLACE(vcl->name, name);
VCLI_Out(cli, "Loaded \"%s\" as \"%s\"", fn , name);
-	(void)vcl->conf->init_func(NULL);
+	(void)vcl->conf->init_func(NULL, NULL);
Lck_Lock(&vcl_mtx);
if (vcl_active == NULL)
vcl_active = vcl;
@@ -215,7 +215,7 @@ VCL_Nuke(struct vcls *vcl)
assert(vcl->conf->busy == 0);
-	(void)vcl->conf->fini_func(NULL);
+	(void)vcl->conf->fini_func(NULL, NULL);
vcl->conf->fini_vcl(NULL);
free(vcl->name);
(void)dlclose(vcl->dlh);
@@ -336,7 +336,7 @@ ccf_config_use(struct cli *cli, const char * const *av, void *priv)

#define VCL_MET_MAC(func, upper, bitmap)				\
void									\
-VCL_##func##_method(struct req *req)					\
+VCL_##func##_method(struct worker *wrk, struct req *req)		\
{									\
char *aws;							\
\
@@ -347,7 +347,7 @@ VCL_##func##_method(struct req *req)					\
req->handling = 0;						\
req->cur_method = VCL_MET_ ## upper;				\
VSLb(req->vsl, SLT_VCL_call, "%s", #func);			\
-	(void)req->vcl->func##_func(req);				\
+	(void)req->vcl->func##_func(wrk, req);				\
VSLb(req->vsl, SLT_VCL_return, "%s",				\
VCL_Return_Name(req->handling));				\
req->cur_method = 0;						\
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index df86279..852ed6e 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -746,10 +746,11 @@ fo.write("""
struct sess;
struct req;
struct cli;
+struct worker;

typedef int vcl_init_f(struct cli *);
typedef void vcl_fini_f(struct cli *);
-typedef int vcl_func_f(struct req *req);
+typedef int vcl_func_f(struct worker *wrk, struct req *req);
""")

diff --git a/lib/libvcl/vcc_compile.c b/lib/libvcl/vcc_compile.c
index 6eca56c..3aa1916 100644
--- a/lib/libvcl/vcc_compile.c
+++ b/lib/libvcl/vcc_compile.c
@@ -692,7 +692,8 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp)
/* Emit method functions */
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(struct req *req)\n",
+		Fc(tl, 1,
+		    "VGC_function_%s(struct worker *wrk, struct req *req)\n",
method_tab[i].name);
AZ(VSB_finish(tl->fm[i]));
Fc(tl, 1, "{\n");

```