From: phk Date: Tue, 5 Feb 2008 11:19:22 +0000 (+0000) Subject: Add the missing bits to actually allow discards of VCL code. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98e7ec555310e3e87710481bae731ef85bc091c5;p=varnish Add the missing bits to actually allow discards of VCL code. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2431 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 24cf10ea..0a73a81c 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -595,6 +595,7 @@ void VCL_Init(void); void VCL_Refresh(struct VCL_conf **vcc); void VCL_Rel(struct VCL_conf **vcc); void VCL_Get(struct VCL_conf **vcc); +void VCL_Idle(void); #define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *); diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index 92fdacb5..77eda246 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -51,7 +51,6 @@ static MTX VBE_mtx; struct backendlist backendlist = VTAILQ_HEAD_INITIALIZER(backendlist); - /*-------------------------------------------------------------------- * Attempt to connect to a given addrinfo entry. * @@ -222,8 +221,10 @@ VBE_DropRefLocked(struct backend *b) CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); i = --b->refcount; - if (i == 0) + if (i == 0) { + ASSERT_CLI(); /* XXX: ?? */ VTAILQ_REMOVE(&backendlist, b, list); + } UNLOCK(&b->mtx); if (i) return; diff --git a/varnish-cache/bin/varnishd/cache_cli.c b/varnish-cache/bin/varnishd/cache_cli.c index f678e074..0da5737b 100644 --- a/varnish-cache/bin/varnishd/cache_cli.c +++ b/varnish-cache/bin/varnishd/cache_cli.c @@ -106,8 +106,10 @@ CLI_Init(void) pfd[0].fd = heritage.fds[2]; pfd[0].events = POLLIN; i = poll(pfd, 1, 5000); - if (i == 0) + if (i == 0) { + VCL_Idle(); continue; + } if ((nbuf + 2) >= lbuf) { lbuf += lbuf; buf = realloc(buf, lbuf); diff --git a/varnish-cache/bin/varnishd/cache_vcl.c b/varnish-cache/bin/varnishd/cache_vcl.c index a9dfee3c..eb563874 100644 --- a/varnish-cache/bin/varnishd/cache_vcl.c +++ b/varnish-cache/bin/varnishd/cache_vcl.c @@ -47,10 +47,9 @@ struct vcls { VTAILQ_ENTRY(vcls) list; - const char *name; + char *name; void *dlh; struct VCL_conf *conf; - int discard; }; /* @@ -61,9 +60,8 @@ static VTAILQ_HEAD(, vcls) vcl_head = VTAILQ_HEAD_INITIALIZER(vcl_head); -static struct vcls *vcl_active; /* protected by vcl_mtx */ - static MTX vcl_mtx; +static struct vcls *vcl_active; /* protected by vcl_mtx */ /*--------------------------------------------------------------------*/ @@ -85,6 +83,7 @@ VCL_Get(struct VCL_conf **vcc) AN(vcl_active); *vcc = vcl_active->conf; AN(*vcc); + AZ((*vcc)->discard); (*vcc)->busy++; UNLOCK(&vcl_mtx); } @@ -92,7 +91,6 @@ VCL_Get(struct VCL_conf **vcc) void VCL_Rel(struct VCL_conf **vcc) { - struct vcls *vcl; struct VCL_conf *vc; vc = *vcc; @@ -101,19 +99,11 @@ VCL_Rel(struct VCL_conf **vcc) LOCK(&vcl_mtx); assert(vc->busy > 0); vc->busy--; - vcl = vc->priv; /* XXX miniobj */ - if (vc->busy == 0 && vcl_active != vcl) { - /* XXX: purge backends */ - } - if (vc->busy == 0 && vcl->discard) { - VTAILQ_REMOVE(&vcl_head, vcl, list); - } else { - vcl = NULL; - } + /* + * We do not garbage collect discarded VCL's here, that happens + * in VCL_Idle() which is called from the CLI thread. + */ UNLOCK(&vcl_mtx); - if (vcl != NULL) { - /* XXX: dispose of vcl */ - } } /*--------------------------------------------------------------------*/ @@ -123,9 +113,13 @@ vcl_find(const char *name) { struct vcls *vcl; - VTAILQ_FOREACH(vcl, &vcl_head, list) + ASSERT_CLI(); + VTAILQ_FOREACH(vcl, &vcl_head, list) { + if (vcl->conf->discard) + continue; if (!strcmp(vcl->name, name)) return (vcl); + } return (NULL); } @@ -134,6 +128,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) { struct vcls *vcl; + ASSERT_CLI(); vcl = vcl_find(name); if (vcl != NULL) { cli_out(cli, "Config '%s' already loaded", name); @@ -177,6 +172,38 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) return (0); } +/*-------------------------------------------------------------------- + * This function is polled from the CLI thread to dispose of any non-busy + * VCLs * which have been discarded. + */ + +static void +VCL_Nuke(struct vcls *vcl) +{ + + ASSERT_CLI(); + assert(vcl != vcl_active); + assert(vcl->conf->discard); + assert(vcl->conf->busy == 0); + VTAILQ_REMOVE(&vcl_head, vcl, list); + vcl->conf->fini_func(); + free(vcl->name); + free(vcl); +} + +/*--------------------------------------------------------------------*/ + +void +VCL_Idle(void) +{ + struct vcls *vcl, *vcl2; + + ASSERT_CLI(); + VTAILQ_FOREACH_SAFE(vcl, &vcl_head, list, vcl2) + if (vcl->conf->discard && vcl->conf->busy == 0) + VCL_Nuke(vcl); +} + /*--------------------------------------------------------------------*/ void @@ -186,6 +213,7 @@ cli_func_config_list(struct cli *cli, const char * const *av, void *priv) (void)av; (void)priv; + ASSERT_CLI(); VTAILQ_FOREACH(vcl, &vcl_head, list) { cli_out(cli, "%s %6u %s\n", vcl == vcl_active ? "* " : " ", @@ -200,6 +228,7 @@ cli_func_config_load(struct cli *cli, const char * const *av, void *priv) (void)av; (void)priv; + ASSERT_CLI(); if (VCL_Load(av[3], av[2], cli)) cli_result(cli, CLIS_PARAM); return; @@ -210,6 +239,7 @@ cli_func_config_discard(struct cli *cli, const char * const *av, void *priv) { struct vcls *vcl; + ASSERT_CLI(); (void)av; (void)priv; vcl = vcl_find(av[2]); @@ -218,11 +248,6 @@ cli_func_config_discard(struct cli *cli, const char * const *av, void *priv) cli_out(cli, "VCL '%s' unknown", av[2]); return; } - if (vcl->discard) { - cli_result(cli, CLIS_PARAM); - cli_out(cli, "VCL %s already discarded", av[2]); - return; - } LOCK(&vcl_mtx); if (vcl == vcl_active) { UNLOCK(&vcl_mtx); @@ -230,15 +255,10 @@ cli_func_config_discard(struct cli *cli, const char * const *av, void *priv) cli_out(cli, "VCL %s is the active VCL", av[2]); return; } - vcl->discard = 1; - if (vcl->conf->busy == 0) - VTAILQ_REMOVE(&vcl_head, vcl, list); - else - vcl = NULL; + vcl->conf->discard = 1; UNLOCK(&vcl_mtx); - if (vcl != NULL) { - /* XXX dispose of vcl */ - } + if (vcl->conf->busy == 0) + VCL_Nuke(vcl); } void @@ -254,11 +274,6 @@ cli_func_config_use(struct cli *cli, const char * const *av, void *priv) cli_result(cli, CLIS_PARAM); return; } - if (vcl->discard) { - cli_out(cli, "VCL '%s' has been discarded", av[2]); - cli_result(cli, CLIS_PARAM); - return; - } LOCK(&vcl_mtx); vcl_active = vcl; UNLOCK(&vcl_mtx); diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index c0078b79..d4e8d138 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -630,5 +630,6 @@ void VRT_fini_backend(struct backend *b) { + ASSERT_CLI(); VBE_DropRef(b); }