Commit 8a3dfdf3 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

The arguments we pass to the VCL and VRT code is getting out of hand

and I've already forgot about them one important place already.

Introduce a "VRT_context", which is a container holding all the
bits we want to pass to VCL and VRT.

Implement it first for VRT_count(), which is, BTW, how I realized I
had forgotten to pass all the new arguments to user defined
functions.
parent 860d7de5
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "cache.h" #include "cache.h"
#include "vcl.h" #include "vcl.h"
#include "vrt.h"
#include "vcli.h" #include "vcli.h"
#include "vcli_priv.h" #include "vcli_priv.h"
...@@ -172,8 +173,13 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) ...@@ -172,8 +173,13 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
{ {
struct vcls *vcl; struct vcls *vcl;
struct VCL_conf const *cnf; struct VCL_conf const *cnf;
struct vrt_ctx ctx;
ASSERT_CLI(); ASSERT_CLI();
memset(&ctx, 0, sizeof ctx);
ctx.magic = VRT_CTX_MAGIC;
vcl = vcl_find(name); vcl = vcl_find(name);
if (vcl != NULL) { if (vcl != NULL) {
VCLI_Out(cli, "Config '%s' already loaded", name); VCLI_Out(cli, "Config '%s' already loaded", name);
...@@ -214,7 +220,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) ...@@ -214,7 +220,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
REPLACE(vcl->name, name); REPLACE(vcl->name, name);
VCLI_Out(cli, "Loaded \"%s\" as \"%s\"", fn , name); VCLI_Out(cli, "Loaded \"%s\" as \"%s\"", fn , name);
VTAILQ_INSERT_TAIL(&vcl_head, vcl, list); VTAILQ_INSERT_TAIL(&vcl_head, vcl, list);
(void)vcl->conf->init_func(NULL, NULL, NULL, NULL); (void)vcl->conf->init_func(&ctx, NULL, NULL, NULL, NULL);
Lck_Lock(&vcl_mtx); Lck_Lock(&vcl_mtx);
if (vcl_active == NULL) if (vcl_active == NULL)
vcl_active = vcl; vcl_active = vcl;
...@@ -232,13 +238,16 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) ...@@ -232,13 +238,16 @@ VCL_Load(const char *fn, const char *name, struct cli *cli)
static void static void
VCL_Nuke(struct vcls *vcl) VCL_Nuke(struct vcls *vcl)
{ {
struct vrt_ctx ctx;
memset(&ctx, 0, sizeof ctx);
ctx.magic = VRT_CTX_MAGIC;
ASSERT_CLI(); ASSERT_CLI();
assert(vcl != vcl_active); assert(vcl != vcl_active);
assert(vcl->conf->discard); assert(vcl->conf->discard);
assert(vcl->conf->busy == 0); assert(vcl->conf->busy == 0);
VTAILQ_REMOVE(&vcl_head, vcl, list); VTAILQ_REMOVE(&vcl_head, vcl, list);
(void)vcl->conf->fini_func(NULL, NULL, NULL, NULL); (void)vcl->conf->fini_func(&ctx, NULL, NULL, NULL, NULL);
vcl->conf->fini_vcl(NULL); vcl->conf->fini_vcl(NULL);
free(vcl->name); free(vcl->name);
(void)dlclose(vcl->dlh); (void)dlclose(vcl->dlh);
...@@ -368,18 +377,26 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo, ...@@ -368,18 +377,26 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
{ {
char *aws; char *aws;
struct vsl_log *vsl; struct vsl_log *vsl;
struct vrt_ctx ctx;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
memset(&ctx, 0, sizeof ctx);
ctx.magic = VRT_CTX_MAGIC;
if (req != NULL) { if (req != NULL) {
AZ(bo); AZ(bo);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC); CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(req->sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(req->sp, SESS_MAGIC);
vsl = req->vsl; vsl = req->vsl;
ctx.vsl = vsl;
ctx.vcl = req->vcl;
} else { } else {
AZ(req); AZ(req);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
vsl = bo->vsl; vsl = bo->vsl;
ctx.vsl = vsl;
ctx.vcl = bo->vcl;
} }
ctx.ws = ws;
if (method == VCL_MET_BACKEND_FETCH || if (method == VCL_MET_BACKEND_FETCH ||
method == VCL_MET_PASS || method == VCL_MET_PASS ||
method == VCL_MET_MISS || method == VCL_MET_MISS ||
...@@ -394,7 +411,7 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo, ...@@ -394,7 +411,7 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
wrk->handling = 0; wrk->handling = 0;
wrk->cur_method = method; wrk->cur_method = method;
VSLb(vsl, SLT_VCL_call, "%s", VCL_Method_Name(method)); VSLb(vsl, SLT_VCL_call, "%s", VCL_Method_Name(method));
(void)func(wrk, req, bo, ws); (void)func(&ctx, wrk, req, bo, ws);
VSLb(vsl, SLT_VCL_return, "%s", VCL_Return_Name(wrk->handling)); VSLb(vsl, SLT_VCL_return, "%s", VCL_Return_Name(wrk->handling));
wrk->cur_method = 0; wrk->cur_method = 0;
WS_Reset(wrk->aws, aws); WS_Reset(wrk->aws, aws);
......
...@@ -86,14 +86,13 @@ VRT_error(struct req *req, unsigned code, const char *reason) ...@@ -86,14 +86,13 @@ VRT_error(struct req *req, unsigned code, const char *reason)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void void
VRT_count(struct req *req, unsigned u) VRT_count(const struct vrt_ctx *ctx, unsigned u)
{ {
if (req == NULL) CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
return; if (ctx->vsl != NULL)
CHECK_OBJ_NOTNULL(req, REQ_MAGIC); VSLb(ctx->vsl, SLT_VCL_trace, "%u %u.%u", u,
VSLb(req->vsl, SLT_VCL_trace, "%u %u.%u", u, ctx->vcl->ref[u].line, ctx->vcl->ref[u].pos);
req->vcl->ref[u].line, req->vcl->ref[u].pos);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
......
...@@ -32,7 +32,10 @@ ...@@ -32,7 +32,10 @@
*/ */
struct req; struct req;
struct busyobj;
struct worker; struct worker;
struct vsl_log;
struct http;
struct ws; struct ws;
struct vsb; struct vsb;
struct cli; struct cli;
...@@ -58,6 +61,29 @@ typedef const char * VCL_STRING; ...@@ -58,6 +61,29 @@ typedef const char * VCL_STRING;
typedef double VCL_TIME; typedef double VCL_TIME;
typedef void VCL_VOID; typedef void VCL_VOID;
/***********************************************************************
* This is the composite argument we pass to compiled VCL and VRT
* functions.
*/
struct vrt_ctx {
unsigned magic;
#define VRT_CTX_MAGIC 0x6bb8f0db
struct vsl_log *vsl;
struct VCL_conf *vcl;
struct ws *ws;
struct req *req;
struct http *http_req;
struct http *http_obj;
struct http *http_resp;
struct busyobj *bo;
struct http *http_bereq;
struct http *http_beresp;
};
/***********************************************************************/ /***********************************************************************/
enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ, HDR_BERESP }; enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ, HDR_BERESP };
...@@ -172,7 +198,7 @@ const char *VRT_regsub(struct req *, int all, const char *, ...@@ -172,7 +198,7 @@ const char *VRT_regsub(struct req *, int all, const char *,
void VRT_ban_string(const char *); void VRT_ban_string(const char *);
void VRT_purge(const struct worker *, struct req *, double ttl, double grace); void VRT_purge(const struct worker *, struct req *, double ttl, double grace);
void VRT_count(struct req *, unsigned); void VRT_count(const struct vrt_ctx *, unsigned);
int VRT_rewrite(const char *, const char *); int VRT_rewrite(const char *, const char *);
void VRT_error(struct req *, unsigned, const char *); void VRT_error(struct req *, unsigned, const char *);
int VRT_switch_config(const char *); int VRT_switch_config(const char *);
......
...@@ -765,6 +765,7 @@ file_header(fo) ...@@ -765,6 +765,7 @@ file_header(fo)
fo.write(""" fo.write("""
struct sess; struct sess;
struct vrt_ctx;
struct req; struct req;
struct busyobj; struct busyobj;
struct ws; struct ws;
...@@ -773,7 +774,7 @@ struct worker; ...@@ -773,7 +774,7 @@ struct worker;
typedef int vcl_init_f(struct cli *); typedef int vcl_init_f(struct cli *);
typedef void vcl_fini_f(struct cli *); typedef void vcl_fini_f(struct cli *);
typedef int vcl_func_f(struct worker *, struct req *, struct busyobj *, typedef int vcl_func_f(struct vrt_ctx *ctx, struct worker *, struct req *, struct busyobj *,
struct ws *); struct ws *);
""") """)
......
...@@ -46,7 +46,7 @@ parse_call(struct vcc *tl) ...@@ -46,7 +46,7 @@ parse_call(struct vcc *tl)
ExpectErr(tl, ID); ExpectErr(tl, ID);
vcc_AddCall(tl, tl->t); vcc_AddCall(tl, tl->t);
vcc_AddRef(tl, tl->t, SYM_SUB); vcc_AddRef(tl, tl->t, SYM_SUB);
Fb(tl, 1, "if (VGC_function_%.*s(req))\n", PF(tl->t)); Fb(tl, 1, "if (VGC_function_%.*s(ctx, req))\n", PF(tl->t));
Fb(tl, 1, "\treturn (1);\n"); Fb(tl, 1, "\treturn (1);\n");
vcc_NextToken(tl); vcc_NextToken(tl);
return; return;
......
...@@ -693,7 +693,7 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp) ...@@ -693,7 +693,7 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp)
for (i = 0; i < VCL_MET_MAX; i++) { for (i = 0; i < VCL_MET_MAX; i++) {
Fc(tl, 1, "\nstatic int __match_proto__(vcl_func_f)\n"); Fc(tl, 1, "\nstatic int __match_proto__(vcl_func_f)\n");
Fc(tl, 1, Fc(tl, 1,
"VGC_function_%s(struct worker *wrk," "VGC_function_%s(struct vrt_ctx *ctx, struct worker *wrk,"
" struct req *req, struct busyobj *bo, struct ws *ws)\n", " struct req *req, struct busyobj *bo, struct ws *ws)\n",
method_tab[i].name); method_tab[i].name);
AZ(VSB_finish(tl->fm[i])); AZ(VSB_finish(tl->fm[i]));
......
...@@ -47,7 +47,7 @@ static void vcc_Compound(struct vcc *tl); ...@@ -47,7 +47,7 @@ static void vcc_Compound(struct vcc *tl);
} while (0) } while (0)
#define C(tl, sep) do { \ #define C(tl, sep) do { \
Fb(tl, 1, "VRT_count(req, %u)%s\n", ++tl->cnt, sep); \ Fb(tl, 1, "VRT_count(ctx, %u)%s\n", ++tl->cnt, sep); \
tl->t->cnt = tl->cnt; \ tl->t->cnt = tl->cnt; \
} while (0) } while (0)
...@@ -237,10 +237,10 @@ vcc_Function(struct vcc *tl) ...@@ -237,10 +237,10 @@ vcc_Function(struct vcc *tl)
} }
tl->curproc = vcc_AddProc(tl, tl->t); tl->curproc = vcc_AddProc(tl, tl->t);
Fh(tl, 0, "static int VGC_function_%.*s " Fh(tl, 0, "static int VGC_function_%.*s "
"(struct req *);\n", PF(tl->t)); "(struct vrt_ctx *ctx, struct req *);\n", PF(tl->t));
Fc(tl, 1, "\nstatic int __match_proto__(vcl_func_t)\n"); Fc(tl, 1, "\nstatic int __match_proto__(vcl_func_t)\n");
Fc(tl, 1, "VGC_function_%.*s(struct req *req)\n", Fc(tl, 1, "VGC_function_%.*s(struct vrt_ctx *ctx, "
PF(tl->t)); "struct req *req)\n", PF(tl->t));
} }
vcc_NextToken(tl); vcc_NextToken(tl);
tl->indent += INDENT; tl->indent += INDENT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment