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

Implement new VRT functions for VCL switching

parent c3909ca6
...@@ -89,6 +89,23 @@ static struct vcl *vcl_active; /* protected by vcl_mtx */ ...@@ -89,6 +89,23 @@ static struct vcl *vcl_active; /* protected by vcl_mtx */
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static struct vcl *
vcl_find(const char *name)
{
struct vcl *vcl;
ASSERT_CLI();
VTAILQ_FOREACH(vcl, &vcl_head, list) {
if (vcl->discard)
continue;
if (!strcmp(vcl->loaded_name, name))
return (vcl);
}
return (NULL);
}
/*--------------------------------------------------------------------*/
void void
VCL_Panic(struct vsb *vsb, const struct vcl *vcl) VCL_Panic(struct vsb *vsb, const struct vcl *vcl)
{ {
...@@ -155,27 +172,34 @@ VCL_Method_Name(unsigned m) ...@@ -155,27 +172,34 @@ VCL_Method_Name(unsigned m)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static void static void
VCL_Get(struct vcl **vcc) vcl_get(struct vcl **vcc, struct vcl *vcl)
{ {
while (vcl_active == NULL)
(void)usleep(100000);
CHECK_OBJ_NOTNULL(vcl_active, VCL_MAGIC); CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
assert(vcl_active->temp == VCL_TEMP_WARM); assert(vcl->temp == VCL_TEMP_WARM);
Lck_Lock(&vcl_mtx); Lck_Lock(&vcl_mtx);
AN(vcl_active); AN(vcl);
if (vcl_active->label == NULL) if (vcl->label == NULL)
*vcc = vcl_active; *vcc = vcl;
else if (strcmp(vcl_active->state, VCL_TEMP_LABEL)) else if (strcmp(vcl->state, VCL_TEMP_LABEL))
*vcc = vcl_active; *vcc = vcl;
else else
*vcc = vcl_active->label; *vcc = vcl->label;
AN(*vcc); AN(*vcc);
AZ((*vcc)->discard); AZ((*vcc)->discard);
(*vcc)->busy++; (*vcc)->busy++;
Lck_Unlock(&vcl_mtx); Lck_Unlock(&vcl_mtx);
} }
static void
vcl_get_active(struct vcl **vcc)
{
while (vcl_active == NULL)
(void)usleep(100000);
vcl_get(vcc, vcl_active);
}
void void
VCL_Refresh(struct vcl **vcc) VCL_Refresh(struct vcl **vcc)
{ {
...@@ -185,7 +209,7 @@ VCL_Refresh(struct vcl **vcc) ...@@ -185,7 +209,7 @@ VCL_Refresh(struct vcl **vcc)
return; return;
if (*vcc != NULL) if (*vcc != NULL)
VCL_Rel(vcc); /* XXX: optimize locking */ VCL_Rel(vcc); /* XXX: optimize locking */
VCL_Get(vcc); vcl_get_active(vcc);
} }
void void
...@@ -411,6 +435,26 @@ VRT_count(VRT_CTX, unsigned u) ...@@ -411,6 +435,26 @@ VRT_count(VRT_CTX, unsigned u)
ctx->vcl->conf->ref[u].line, ctx->vcl->conf->ref[u].pos); ctx->vcl->conf->ref[u].line, ctx->vcl->conf->ref[u].pos);
} }
VCL_VCL
VRT_vcl_lookup(const char *name)
{
VCL_VCL vcl;
vcl = vcl_find(name);
AN(vcl);
return (vcl);
}
void
VRT_vcl_select(VRT_CTX, VCL_VCL vcl)
{
struct req *req = ctx->req;
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
VCL_Rel(&req->vcl);
vcl_get(&req->vcl, vcl);
}
struct vclref * struct vclref *
VRT_ref_vcl(VRT_CTX, const char *desc) VRT_ref_vcl(VRT_CTX, const char *desc)
{ {
...@@ -468,21 +512,6 @@ VRT_rel_vcl(VRT_CTX, struct vclref **refp) ...@@ -468,21 +512,6 @@ VRT_rel_vcl(VRT_CTX, struct vclref **refp)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static struct vcl *
vcl_find(const char *name)
{
struct vcl *vcl;
ASSERT_CLI();
VTAILQ_FOREACH(vcl, &vcl_head, list) {
if (vcl->discard)
continue;
if (!strcmp(vcl->loaded_name, name))
return (vcl);
}
return (NULL);
}
static int static int
vcl_setup_event(VRT_CTX, enum vcl_event_e ev) vcl_setup_event(VRT_CTX, enum vcl_event_e ev)
{ {
......
...@@ -98,6 +98,7 @@ typedef double VCL_REAL; ...@@ -98,6 +98,7 @@ typedef double VCL_REAL;
typedef const struct stevedore * VCL_STEVEDORE; typedef const struct stevedore * VCL_STEVEDORE;
typedef const char * VCL_STRING; typedef const char * VCL_STRING;
typedef double VCL_TIME; typedef double VCL_TIME;
typedef struct vcl * VCL_VCL;
typedef void VCL_VOID; typedef void VCL_VOID;
/*********************************************************************** /***********************************************************************
...@@ -313,6 +314,10 @@ int VRT_Vmod_Init(struct vmod **hdl, void *ptr, int len, const char *nm, ...@@ -313,6 +314,10 @@ int VRT_Vmod_Init(struct vmod **hdl, void *ptr, int len, const char *nm,
const char *path, const char *file_id, VRT_CTX); const char *path, const char *file_id, VRT_CTX);
void VRT_Vmod_Fini(struct vmod **hdl); void VRT_Vmod_Fini(struct vmod **hdl);
/* VCL program related */
VCL_VCL VRT_vcl_lookup(const char *);
void VRT_vcl_select(VRT_CTX, VCL_VCL);
struct vmod_priv; struct vmod_priv;
typedef void vmod_priv_free_f(void *); typedef void vmod_priv_free_f(void *);
struct vmod_priv { struct vmod_priv {
......
...@@ -150,6 +150,11 @@ const struct type TIME[1] = {{ ...@@ -150,6 +150,11 @@ const struct type TIME[1] = {{
.tostring = "VRT_TIME_string(ctx, \v1)", .tostring = "VRT_TIME_string(ctx, \v1)",
}}; }};
const struct type VCL[1] = {{
.magic = TYPE_MAGIC,
.name = "VCL",
}};
const struct type VOID[1] = {{ const struct type VOID[1] = {{
.magic = TYPE_MAGIC, .magic = TYPE_MAGIC,
.name = "VOID", .name = "VOID",
......
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