Commit b6da2dc7 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Remove the wrk argument from VCL/VRT, now everything we need is

encapsulated in the vrt_ctx.
parent b3e1e100
...@@ -174,6 +174,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) ...@@ -174,6 +174,7 @@ 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; struct vrt_ctx ctx;
unsigned hand = 0;
ASSERT_CLI(); ASSERT_CLI();
...@@ -220,7 +221,10 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) ...@@ -220,7 +221,10 @@ 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(&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); Lck_Lock(&vcl_mtx);
if (vcl_active == NULL) if (vcl_active == NULL)
vcl_active = vcl; vcl_active = vcl;
...@@ -239,6 +243,7 @@ static void ...@@ -239,6 +243,7 @@ static void
VCL_Nuke(struct vcls *vcl) VCL_Nuke(struct vcls *vcl)
{ {
struct vrt_ctx ctx; struct vrt_ctx ctx;
unsigned hand = 0;
memset(&ctx, 0, sizeof ctx); memset(&ctx, 0, sizeof ctx);
ctx.magic = VRT_CTX_MAGIC; ctx.magic = VRT_CTX_MAGIC;
...@@ -247,7 +252,10 @@ VCL_Nuke(struct vcls *vcl) ...@@ -247,7 +252,10 @@ VCL_Nuke(struct vcls *vcl)
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(&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); vcl->conf->fini_vcl(NULL);
free(vcl->name); free(vcl->name);
(void)dlclose(vcl->dlh); (void)dlclose(vcl->dlh);
...@@ -416,12 +424,14 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo, ...@@ -416,12 +424,14 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
ctx.bo = bo; ctx.bo = bo;
} }
ctx.ws = ws; ctx.ws = ws;
ctx.method = method;
ctx.handling = &wrk->handling;
aws = WS_Snapshot(wrk->aws); aws = WS_Snapshot(wrk->aws);
wrk->handling = 0; wrk->handling = 0;
wrk->cur_method = method; wrk->cur_method = method;
AN(vsl); AN(vsl);
VSLb(vsl, SLT_VCL_call, "%s", VCL_Method_Name(method)); 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)); 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);
......
...@@ -264,16 +264,12 @@ VRT_SetHdr(const struct vrt_ctx *ctx , const struct gethdr_s *hs, ...@@ -264,16 +264,12 @@ VRT_SetHdr(const struct vrt_ctx *ctx , const struct gethdr_s *hs,
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void void
VRT_handling(struct worker *wrk, unsigned hand) VRT_handling(const struct vrt_ctx *ctx, unsigned hand)
{ {
if (wrk == NULL) { CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
assert(hand == VCL_RET_OK);
return;
}
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
assert(hand < VCL_RET_MAX); 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) ...@@ -516,17 +512,15 @@ VRT_CacheReqBody(const struct vrt_ctx *ctx, long long maxsize)
*/ */
void void
VRT_purge(const struct worker *wrk, const struct vrt_ctx *ctx, double ttl, VRT_purge(const struct vrt_ctx *ctx, double ttl, double grace)
double grace)
{ {
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_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, HSH_Purge(ctx->req, ctx->req->obj->objcore->objhead,
ttl, grace); 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, HSH_Purge(ctx->req, ctx->req->objcore->objhead,
ttl, grace); ttl, grace);
} }
......
...@@ -25,13 +25,13 @@ varnish v1 -vcl+backend { ...@@ -25,13 +25,13 @@ varnish v1 -vcl+backend {
sub vcl_lookup { sub vcl_lookup {
if (req.method == "PURGE") { if (req.method == "PURGE") {
C{ VRT_purge(wrk, ctx, 0, 0); }C C{ VRT_purge(ctx, 0, 0); }C
error 456 "got it"; error 456 "got it";
} }
} }
sub vcl_miss { sub vcl_miss {
if (req.method == "PURGE") { if (req.method == "PURGE") {
C{ VRT_purge(wrk, ctx, 0, 0); }C C{ VRT_purge(ctx, 0, 0); }C
error 456 "got it"; error 456 "got it";
} }
} }
......
...@@ -70,6 +70,9 @@ struct vrt_ctx { ...@@ -70,6 +70,9 @@ struct vrt_ctx {
unsigned magic; unsigned magic;
#define VRT_CTX_MAGIC 0x6bb8f0db #define VRT_CTX_MAGIC 0x6bb8f0db
unsigned method;
unsigned *handling;
struct vsl_log *vsl; struct vsl_log *vsl;
struct VCL_conf *vcl; struct VCL_conf *vcl;
struct ws *ws; struct ws *ws;
...@@ -82,6 +85,7 @@ struct vrt_ctx { ...@@ -82,6 +85,7 @@ struct vrt_ctx {
struct busyobj *bo; struct busyobj *bo;
struct http *http_bereq; struct http *http_bereq;
struct http *http_beresp; struct http *http_beresp;
}; };
/***********************************************************************/ /***********************************************************************/
...@@ -196,8 +200,7 @@ const char *VRT_regsub(const struct vrt_ctx *, int all, const char *, ...@@ -196,8 +200,7 @@ const char *VRT_regsub(const struct vrt_ctx *, int all, const char *,
void *, const char *); void *, const char *);
void VRT_ban_string(const char *); void VRT_ban_string(const char *);
void VRT_purge(const struct worker *, const struct vrt_ctx *, double ttl, void VRT_purge(const struct vrt_ctx *, double ttl, double grace);
double grace);
void VRT_count(const struct vrt_ctx *, unsigned); void VRT_count(const struct vrt_ctx *, unsigned);
int VRT_rewrite(const char *, const char *); int VRT_rewrite(const char *, const char *);
...@@ -208,7 +211,7 @@ const struct gethdr_s *VRT_MkGethdr(const struct vrt_ctx *,enum gethdr_e, ...@@ -208,7 +211,7 @@ const struct gethdr_s *VRT_MkGethdr(const struct vrt_ctx *,enum gethdr_e,
const char *); const char *);
char *VRT_GetHdr(const struct vrt_ctx *, const struct gethdr_s *); 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_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, ...); void VRT_hashdata(const struct vrt_ctx *, const char *str, ...);
......
...@@ -707,7 +707,7 @@ struct worker; ...@@ -707,7 +707,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(const struct vrt_ctx *ctx, struct worker *); typedef int vcl_func_f(const struct vrt_ctx *ctx);
""") """)
......
...@@ -79,7 +79,7 @@ parse_error(struct vcc *tl) ...@@ -79,7 +79,7 @@ parse_error(struct vcc *tl)
Fb(tl, 1, ", 0\n"); Fb(tl, 1, ", 0\n");
} }
Fb(tl, 1, ");\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"); Fb(tl, 1, "return(1);\n");
} }
...@@ -314,7 +314,7 @@ parse_return(struct vcc *tl) ...@@ -314,7 +314,7 @@ parse_return(struct vcc *tl)
#define VCL_RET_MAC(l, U, B) \ #define VCL_RET_MAC(l, U, B) \
do { \ do { \
if (vcc_IdIs(tl->t, #l)) { \ 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"); \ Fb(tl, 1, "return (1);\n"); \
vcc_ProcAction(tl->curproc, VCL_RET_##U, tl->t);\ vcc_ProcAction(tl->curproc, VCL_RET_##U, tl->t);\
retval = 1; \ retval = 1; \
...@@ -349,7 +349,7 @@ parse_purge(struct vcc *tl) ...@@ -349,7 +349,7 @@ parse_purge(struct vcc *tl)
{ {
vcc_NextToken(tl); vcc_NextToken(tl);
Fb(tl, 1, "VRT_purge(wrk, ctx, 0, 0);\n"); Fb(tl, 1, "VRT_purge(ctx, 0, 0);\n");
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
......
...@@ -693,8 +693,7 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp) ...@@ -693,8 +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(const struct vrt_ctx *ctx," "VGC_function_%s(const struct vrt_ctx *ctx)\n",
" struct worker *wrk)\n",
method_tab[i].name); method_tab[i].name);
AZ(VSB_finish(tl->fm[i])); AZ(VSB_finish(tl->fm[i]));
Fc(tl, 1, "{\n"); Fc(tl, 1, "{\n");
......
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