]> err.no Git - varnish/commitdiff
Add the missing bits to actually allow discards of VCL code.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 5 Feb 2008 11:19:22 +0000 (11:19 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 5 Feb 2008 11:19:22 +0000 (11:19 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2431 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_backend.c
varnish-cache/bin/varnishd/cache_cli.c
varnish-cache/bin/varnishd/cache_vcl.c
varnish-cache/bin/varnishd/cache_vrt.c

index 24cf10ea29d38cc43e4a6416f69a56042f185b48..0a73a81c7202602151b7fe68b4a1a3076a5a48f9 100644 (file)
@@ -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 *);
index 92fdacb54ffacef75e1d6dd6a739ed1dc780df44..77eda246b63cac2cd195e3549478a28b2828ceb3 100644 (file)
@@ -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;
index f678e074d61c3348ea4e5e099f0467270a6c2b49..0da5737ba484c00204ab6368f9198b2b31259827 100644 (file)
@@ -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);
index a9dfee3c3fcd622ee414c7f5351ee50a76fbc30d..eb563874edb550fba8ed70f1e0f0d5868a4b412d 100644 (file)
 
 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);
index c0078b790ae05494c451a3fe5bbf40eb9c037d7a..d4e8d1389296f62e60f9cefa31f3da332f93dc48 100644 (file)
@@ -630,5 +630,6 @@ void
 VRT_fini_backend(struct backend *b)
 {
 
+       ASSERT_CLI();
        VBE_DropRef(b); 
 }