Commit 8ce92cec authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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



git-svn-id: http://www.varnish-cache.org/svn/trunk@4413 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 4378af19
...@@ -20,7 +20,6 @@ varnishd_SOURCES = \ ...@@ -20,7 +20,6 @@ varnishd_SOURCES = \
cache_cli.c \ cache_cli.c \
cache_dir_random.c \ cache_dir_random.c \
cache_dir_round_robin.c \ cache_dir_round_robin.c \
cache_dir_simple.c \
cache_esi.c \ cache_esi.c \
cache_expire.c \ cache_expire.c \
cache_fetch.c \ cache_fetch.c \
......
...@@ -47,6 +47,7 @@ SVNID("$Id$") ...@@ -47,6 +47,7 @@ SVNID("$Id$")
#include "shmlog.h" #include "shmlog.h"
#include "cache.h" #include "cache.h"
#include "cache_backend.h" #include "cache_backend.h"
#include "vrt.h"
/* /*
* List of cached vbe_conns, used if enabled in params/heritage * List of cached vbe_conns, used if enabled in params/heritage
...@@ -68,6 +69,7 @@ VBE_AddHostHeader(const struct sess *sp) ...@@ -68,6 +69,7 @@ VBE_AddHostHeader(const struct sess *sp)
"Host: %s", sp->vbe->backend->hosthdr); "Host: %s", sp->vbe->backend->hosthdr);
} }
/* Private interface from backend_cfg.c */
void void
VBE_ReleaseConn(struct vbe_conn *vc) VBE_ReleaseConn(struct vbe_conn *vc)
{ {
...@@ -97,7 +99,7 @@ VBE_ReleaseConn(struct vbe_conn *vc) ...@@ -97,7 +99,7 @@ VBE_ReleaseConn(struct vbe_conn *vc)
*/ */
static int 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) socklen_t salen, const struct backend *bp)
{ {
int s, i, tmo; int s, i, tmo;
...@@ -150,11 +152,11 @@ bes_conn_try(const struct sess *sp, struct backend *bp) ...@@ -150,11 +152,11 @@ bes_conn_try(const struct sess *sp, struct backend *bp)
/* release lock during stuff that can take a long time */ /* release lock during stuff that can take a long time */
if (params->prefer_ipv6 && bp->ipv6 != NULL) 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) 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) 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) { if (s < 0) {
Lck_Lock(&bp->mtx); Lck_Lock(&bp->mtx);
...@@ -172,7 +174,7 @@ bes_conn_try(const struct sess *sp, struct backend *bp) ...@@ -172,7 +174,7 @@ bes_conn_try(const struct sess *sp, struct backend *bp)
*/ */
static int static int
VBE_CheckFd(int fd) vbe_CheckFd(int fd)
{ {
struct pollfd pfd; struct pollfd pfd;
...@@ -189,7 +191,7 @@ VBE_CheckFd(int fd) ...@@ -189,7 +191,7 @@ VBE_CheckFd(int fd)
*/ */
static struct vbe_conn * static struct vbe_conn *
VBE_NewConn(void) vbe_NewConn(void)
{ {
struct vbe_conn *vc; struct vbe_conn *vc;
...@@ -225,8 +227,8 @@ VBE_NewConn(void) ...@@ -225,8 +227,8 @@ VBE_NewConn(void)
* items would never time out once the threshold is reached. * items would never time out once the threshold is reached.
*/ */
unsigned int static unsigned int
VBE_Healthy(const struct sess *sp, struct backend *backend) vbe_Healthy(const struct sess *sp, struct backend *backend)
{ {
struct trouble *tr; struct trouble *tr;
struct trouble *tr2; struct trouble *tr2;
...@@ -292,8 +294,8 @@ VBE_Healthy(const struct sess *sp, struct backend *backend) ...@@ -292,8 +294,8 @@ VBE_Healthy(const struct sess *sp, struct backend *backend)
* Get a connection to a particular backend. * Get a connection to a particular backend.
*/ */
struct vbe_conn * static struct vbe_conn *
VBE_GetVbe(struct sess *sp, struct backend *bp) vbe_GetVbe(struct sess *sp, struct backend *bp)
{ {
struct vbe_conn *vc; struct vbe_conn *vc;
...@@ -313,7 +315,7 @@ VBE_GetVbe(struct sess *sp, struct backend *bp) ...@@ -313,7 +315,7 @@ VBE_GetVbe(struct sess *sp, struct backend *bp)
Lck_Unlock(&bp->mtx); Lck_Unlock(&bp->mtx);
if (vc == NULL) if (vc == NULL)
break; break;
if (VBE_CheckFd(vc->fd)) { if (vbe_CheckFd(vc->fd)) {
/* XXX locking of stats */ /* XXX locking of stats */
VSL_stats->backend_reuse += 1; VSL_stats->backend_reuse += 1;
WSP(sp, SLT_Backend, "%d %s %s", WSP(sp, SLT_Backend, "%d %s %s",
...@@ -325,7 +327,7 @@ VBE_GetVbe(struct sess *sp, struct backend *bp) ...@@ -325,7 +327,7 @@ VBE_GetVbe(struct sess *sp, struct backend *bp)
VBE_ClosedFd(sp); VBE_ClosedFd(sp);
} }
if (!VBE_Healthy(sp, bp)) { if (!vbe_Healthy(sp, bp)) {
VSL_stats->backend_unhealthy++; VSL_stats->backend_unhealthy++;
return (NULL); return (NULL);
} }
...@@ -335,7 +337,7 @@ VBE_GetVbe(struct sess *sp, struct backend *bp) ...@@ -335,7 +337,7 @@ VBE_GetVbe(struct sess *sp, struct backend *bp)
return (NULL); return (NULL);
} }
vc = VBE_NewConn(); vc = vbe_NewConn();
assert(vc->fd == -1); assert(vc->fd == -1);
AZ(vc->backend); AZ(vc->backend);
vc->fd = bes_conn_try(sp, bp); vc->fd = bes_conn_try(sp, bp);
...@@ -407,3 +409,80 @@ VBE_RecycleFd(struct sess *sp) ...@@ -407,3 +409,80 @@ VBE_RecycleFd(struct sess *sp)
sp->vbe = NULL; sp->vbe = NULL;
VBE_DropRefLocked(bp); 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;
}
...@@ -160,8 +160,6 @@ struct backend { ...@@ -160,8 +160,6 @@ struct backend {
/* cache_backend.c */ /* cache_backend.c */
void VBE_ReleaseConn(struct vbe_conn *vc); 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 */ /* cache_backend_cfg.c */
extern struct lock VBE_mtx; extern struct lock VBE_mtx;
......
...@@ -261,6 +261,22 @@ VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb) ...@@ -261,6 +261,22 @@ VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
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 void
VRT_fini_dir(struct cli *cli, struct director *b) VRT_fini_dir(struct cli *cli, struct director *b)
{ {
......
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2009 Linpro AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@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;
}
...@@ -849,24 +849,6 @@ VRT_backend_string(struct sess *sp) ...@@ -849,24 +849,6 @@ VRT_backend_string(struct sess *sp)
return (sp->director->vcl_name); return (sp->director->vcl_name);
} }
/*--------------------------------------------------------------------*/
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 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