r4413 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Wed Dec 16 12:58:47 CET 2009
Author: phk
Date: 2009-12-16 12:58:47 +0100 (Wed, 16 Dec 2009)
New Revision: 4413
Removed:
trunk/varnish-cache/bin/varnishd/cache_dir_simple.c
Modified:
trunk/varnish-cache/bin/varnishd/Makefile.am
trunk/varnish-cache/bin/varnishd/cache_backend.c
trunk/varnish-cache/bin/varnishd/cache_backend.h
trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
trunk/varnish-cache/bin/varnishd/cache_vrt.c
Log:
Shuffle things around:
Move the "simple" director into cache_backend.c, since it is what
is really dealing with backends now that directors are objectified.
Make a lot of stuff static as a result.
Collect both the init and fini VRT functins for directors in
cache_backend_cfg.c
Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am 2009-12-16 11:51:18 UTC (rev 4412)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am 2009-12-16 11:58:47 UTC (rev 4413)
@@ -20,7 +20,6 @@
cache_cli.c \
cache_dir_random.c \
cache_dir_round_robin.c \
- cache_dir_simple.c \
cache_esi.c \
cache_expire.c \
cache_fetch.c \
Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c 2009-12-16 11:51:18 UTC (rev 4412)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2009-12-16 11:58:47 UTC (rev 4413)
@@ -47,6 +47,7 @@
#include "shmlog.h"
#include "cache.h"
#include "cache_backend.h"
+#include "vrt.h"
/*
* List of cached vbe_conns, used if enabled in params/heritage
@@ -68,6 +69,7 @@
"Host: %s", sp->vbe->backend->hosthdr);
}
+/* Private interface from backend_cfg.c */
void
VBE_ReleaseConn(struct vbe_conn *vc)
{
@@ -97,7 +99,7 @@
*/
static int
-VBE_TryConnect(const struct sess *sp, int pf, const struct sockaddr *sa,
+vbe_TryConnect(const struct sess *sp, int pf, const struct sockaddr *sa,
socklen_t salen, const struct backend *bp)
{
int s, i, tmo;
@@ -150,11 +152,11 @@
/* release lock during stuff that can take a long time */
if (params->prefer_ipv6 && bp->ipv6 != NULL)
- s = VBE_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len, bp);
+ s = vbe_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len, bp);
if (s == -1 && bp->ipv4 != NULL)
- s = VBE_TryConnect(sp, PF_INET, bp->ipv4, bp->ipv4len, bp);
+ s = vbe_TryConnect(sp, PF_INET, bp->ipv4, bp->ipv4len, bp);
if (s == -1 && !params->prefer_ipv6 && bp->ipv6 != NULL)
- s = VBE_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len, bp);
+ s = vbe_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len, bp);
if (s < 0) {
Lck_Lock(&bp->mtx);
@@ -172,7 +174,7 @@
*/
static int
-VBE_CheckFd(int fd)
+vbe_CheckFd(int fd)
{
struct pollfd pfd;
@@ -189,7 +191,7 @@
*/
static struct vbe_conn *
-VBE_NewConn(void)
+vbe_NewConn(void)
{
struct vbe_conn *vc;
@@ -225,8 +227,8 @@
* items would never time out once the threshold is reached.
*/
-unsigned int
-VBE_Healthy(const struct sess *sp, struct backend *backend)
+static unsigned int
+vbe_Healthy(const struct sess *sp, struct backend *backend)
{
struct trouble *tr;
struct trouble *tr2;
@@ -292,8 +294,8 @@
* Get a connection to a particular backend.
*/
-struct vbe_conn *
-VBE_GetVbe(struct sess *sp, struct backend *bp)
+static struct vbe_conn *
+vbe_GetVbe(struct sess *sp, struct backend *bp)
{
struct vbe_conn *vc;
@@ -313,7 +315,7 @@
Lck_Unlock(&bp->mtx);
if (vc == NULL)
break;
- if (VBE_CheckFd(vc->fd)) {
+ if (vbe_CheckFd(vc->fd)) {
/* XXX locking of stats */
VSL_stats->backend_reuse += 1;
WSP(sp, SLT_Backend, "%d %s %s",
@@ -325,7 +327,7 @@
VBE_ClosedFd(sp);
}
- if (!VBE_Healthy(sp, bp)) {
+ if (!vbe_Healthy(sp, bp)) {
VSL_stats->backend_unhealthy++;
return (NULL);
}
@@ -335,7 +337,7 @@
return (NULL);
}
- vc = VBE_NewConn();
+ vc = vbe_NewConn();
assert(vc->fd == -1);
AZ(vc->backend);
vc->fd = bes_conn_try(sp, bp);
@@ -407,3 +409,80 @@
sp->vbe = NULL;
VBE_DropRefLocked(bp);
}
+
+
+/*--------------------------------------------------------------------
+ * The "simple" director really isn't, since thats where all the actual
+ * connections happen. Nontheless, pretend it is simple by sequestering
+ * the directoricity of it under this line.
+ */
+
+struct vdi_simple {
+ unsigned magic;
+#define VDI_SIMPLE_MAGIC 0x476d25b7
+ struct director dir;
+ struct backend *backend;
+};
+
+static struct vbe_conn *
+vdi_simple_getfd(struct director *d, struct sess *sp)
+{
+ struct vdi_simple *vs;
+
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+ CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
+ return (vbe_GetVbe(sp, vs->backend));
+}
+
+static unsigned
+vdi_simple_healthy(struct director *d, const struct sess *sp)
+{
+ struct vdi_simple *vs;
+
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+ CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
+ return (vbe_Healthy(sp, vs->backend));
+}
+
+/*lint -e{818} not const-able */
+static void
+vdi_simple_fini(struct director *d)
+{
+ struct vdi_simple *vs;
+
+ CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
+ CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
+
+ VBE_DropRef(vs->backend);
+ free(vs->dir.vcl_name);
+ vs->dir.magic = 0;
+ FREE_OBJ(vs);
+}
+
+void
+VRT_init_dir_simple(struct cli *cli, struct director **bp, int idx,
+ const void *priv)
+{
+ const struct vrt_backend *t;
+ struct vdi_simple *vs;
+
+ ASSERT_CLI();
+ (void)cli;
+ t = priv;
+
+ ALLOC_OBJ(vs, VDI_SIMPLE_MAGIC);
+ XXXAN(vs);
+ vs->dir.magic = DIRECTOR_MAGIC;
+ vs->dir.priv = vs;
+ vs->dir.name = "simple";
+ REPLACE(vs->dir.vcl_name, t->vcl_name);
+ vs->dir.getfd = vdi_simple_getfd;
+ vs->dir.fini = vdi_simple_fini;
+ vs->dir.healthy = vdi_simple_healthy;
+
+ vs->backend = VBE_AddBackend(cli, t);
+
+ bp[idx] = &vs->dir;
+}
Modified: trunk/varnish-cache/bin/varnishd/cache_backend.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.h 2009-12-16 11:51:18 UTC (rev 4412)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.h 2009-12-16 11:58:47 UTC (rev 4413)
@@ -160,8 +160,6 @@
/* cache_backend.c */
void VBE_ReleaseConn(struct vbe_conn *vc);
-struct vbe_conn *VBE_GetVbe(struct sess *sp, struct backend *bp);
-unsigned int VBE_Healthy(const struct sess *sp, struct backend *backend);
/* cache_backend_cfg.c */
extern struct lock VBE_mtx;
Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-12-16 11:51:18 UTC (rev 4412)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-12-16 11:58:47 UTC (rev 4413)
@@ -262,6 +262,22 @@
/*--------------------------------------------------------------------*/
void
+VRT_init_dir(struct cli *cli, struct director **dir, const char *name,
+ int idx, const void *priv)
+{
+
+ ASSERT_CLI();
+ if (!strcmp(name, "simple"))
+ VRT_init_dir_simple(cli, dir, idx, priv);
+ else if (!strcmp(name, "random"))
+ VRT_init_dir_random(cli, dir, idx, priv);
+ else if (!strcmp(name, "round-robin"))
+ VRT_init_dir_round_robin(cli, dir, idx, priv);
+ else
+ INCOMPL();
+}
+
+void
VRT_fini_dir(struct cli *cli, struct director *b)
{
Deleted: trunk/varnish-cache/bin/varnishd/cache_dir_simple.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_dir_simple.c 2009-12-16 11:51:18 UTC (rev 4412)
+++ trunk/varnish-cache/bin/varnishd/cache_dir_simple.c 2009-12-16 11:58:47 UTC (rev 4413)
@@ -1,121 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2009 Linpro AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-#include "config.h"
-
-#include "svnid.h"
-SVNID("$Id$")
-
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <poll.h>
-
-#include "shmlog.h"
-#include "cache.h"
-#include "cache_backend.h"
-#include "vrt.h"
-
-/*--------------------------------------------------------------------*/
-
-struct vdi_simple {
- unsigned magic;
-#define VDI_SIMPLE_MAGIC 0x476d25b7
- struct director dir;
- struct backend *backend;
-};
-
-static struct vbe_conn *
-vdi_simple_getfd(struct director *d, struct sess *sp)
-{
- struct vdi_simple *vs;
-
- CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
- CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
- return (VBE_GetVbe(sp, vs->backend));
-}
-
-static unsigned
-vdi_simple_healthy(struct director *d, const struct sess *sp)
-{
- struct vdi_simple *vs;
-
- CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
- CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
- return (VBE_Healthy(sp, vs->backend));
-}
-
-/*lint -e{818} not const-able */
-static void
-vdi_simple_fini(struct director *d)
-{
- struct vdi_simple *vs;
-
- CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
- CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
-
- VBE_DropRef(vs->backend);
- free(vs->dir.vcl_name);
- vs->dir.magic = 0;
- FREE_OBJ(vs);
-}
-
-void
-VRT_init_dir_simple(struct cli *cli, struct director **bp, int idx,
- const void *priv)
-{
- const struct vrt_backend *t;
- struct vdi_simple *vs;
-
- ASSERT_CLI();
- (void)cli;
- t = priv;
-
- ALLOC_OBJ(vs, VDI_SIMPLE_MAGIC);
- XXXAN(vs);
- vs->dir.magic = DIRECTOR_MAGIC;
- vs->dir.priv = vs;
- vs->dir.name = "simple";
- REPLACE(vs->dir.vcl_name, t->vcl_name);
- vs->dir.getfd = vdi_simple_getfd;
- vs->dir.fini = vdi_simple_fini;
- vs->dir.healthy = vdi_simple_healthy;
-
- vs->backend = VBE_AddBackend(cli, t);
-
- bp[idx] = &vs->dir;
-}
Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-12-16 11:51:18 UTC (rev 4412)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-12-16 11:58:47 UTC (rev 4413)
@@ -850,25 +850,7 @@
}
/*--------------------------------------------------------------------*/
-void
-VRT_init_dir(struct cli *cli, struct director **dir, const char *name,
- int idx, const void *priv)
-{
- ASSERT_CLI();
- if (!strcmp(name, "simple"))
- VRT_init_dir_simple(cli, dir, idx, priv);
- else if (!strcmp(name, "random"))
- VRT_init_dir_random(cli, dir, idx, priv);
- else if (!strcmp(name, "round-robin"))
- VRT_init_dir_round_robin(cli, dir, idx, priv);
- else
- INCOMPL();
-}
-
-
-/*--------------------------------------------------------------------*/
-
void
VRT_Rollback(struct sess *sp)
{
More information about the varnish-commit
mailing list