Permalink
Browse files

Collapse two source files to one.

  • Loading branch information...
bsdphk committed Nov 14, 2017
1 parent 08cea68 commit eaac49272089c0bf1f8ab3ed5a3c1689fe9ce267
View
@@ -11,7 +11,6 @@ sbin_PROGRAMS = varnishd
varnishd_SOURCES = \
cache/cache_acceptor.c \
cache/cache_backend.c \
cache/cache_backend_cfg.c \
cache/cache_backend_probe.c \
cache/cache_ban.c \
cache/cache_ban_build.c \
@@ -48,6 +48,17 @@
#include "VSC_vbe.h"
/*--------------------------------------------------------------------*/
static const char * const vbe_proto_ident = "HTTP Backend";
static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends);
static VTAILQ_HEAD(, backend) cool_backends =
VTAILQ_HEAD_INITIALIZER(cool_backends);
static struct lock backends_mtx;
/*--------------------------------------------------------------------*/
#define FIND_TMO(tmx, dst, bo, be) \
do { \
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); \
@@ -335,6 +346,39 @@ vbe_dir_event(const struct director *d, enum vcl_event_e ev)
}
}
/*---------------------------------------------------------------------*/
static void __match_proto__(vdi_destroy_f)
vbe_destroy(const struct director *d)
{
struct backend *be;
ASSERT_CLI();
CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
if (be->probe != NULL)
VBP_Remove(be);
Lck_Lock(&backends_mtx);
if (be->cooled > 0)
VTAILQ_REMOVE(&cool_backends, be, list);
else
VTAILQ_REMOVE(&backends, be, list);
VSC_C_main->n_backend--;
VTP_Rel(&be->tcp_pool);
Lck_Unlock(&backends_mtx);
#define DA(x) do { if (be->x != NULL) free(be->x); } while (0)
#define DN(x) /**/
VRT_BACKEND_HANDLE();
#undef DA
#undef DN
AZ(be->vsc);
Lck_Delete(&be->mtx);
FREE_OBJ(be);
}
/*--------------------------------------------------------------------*/
static void
@@ -360,17 +404,40 @@ vbe_panic(const struct director *d, struct vsb *vsb)
VSB_printf(vsb, "n_conn = %u,\n", bp->n_conn);
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------
* Create a new static or dynamic director::backend instance.
*/
void
VBE_fill_director(struct backend *be)
struct director *
VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt)
{
struct backend *be;
struct director *d;
struct vcl *vcl;
const struct vrt_backend_probe *vbp;
int retval;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC);
assert(vrt->ipv4_suckaddr != NULL || vrt->ipv6_suckaddr != NULL);
vcl = ctx->vcl;
AN(vcl);
AN(vrt->vcl_name);
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
/* Create new backend */
ALLOC_OBJ(be, BACKEND_MAGIC);
XXXAN(be);
Lck_New(&be->mtx, lck_backend);
#define DA(x) do { if (vrt->x != NULL) REPLACE((be->x), (vrt->x)); } while (0)
#define DN(x) do { be->x = vrt->x; } while (0)
VRT_BACKEND_HANDLE();
#undef DA
#undef DN
INIT_OBJ(be->director, DIRECTOR_MAGIC);
d = be->director;
INIT_OBJ(d, DIRECTOR_MAGIC);
d->priv = be;
d->name = "backend";
d->vcl_name = be->vcl_name;
@@ -380,6 +447,105 @@ VBE_fill_director(struct backend *be)
d->getip = vbe_dir_getip;
d->finish = vbe_dir_finish;
d->event = vbe_dir_event;
d->destroy = VBE_Delete;
d->panic = vbe_panic;
d->destroy = vbe_destroy;
d->health = 1;
d->health_changed = VTIM_real();
d->admin_health = VDI_AH_PROBE;
vbp = vrt->probe;
if (vbp == NULL)
vbp = VCL_DefaultProbe(vcl);
Lck_Lock(&backends_mtx);
VTAILQ_INSERT_TAIL(&backends, be, list);
VSC_C_main->n_backend++;
be->tcp_pool = VTP_Ref(vrt->ipv4_suckaddr, vrt->ipv6_suckaddr,
vbe_proto_ident);
Lck_Unlock(&backends_mtx);
if (vbp != NULL) {
VTP_AddRef(be->tcp_pool);
VBP_Insert(be, vbp, be->tcp_pool);
}
retval = VCL_AddDirector(ctx->vcl, d, vrt->vcl_name);
if (retval == 0)
return (d);
VRT_delete_backend(ctx, &d);
AZ(d);
return (NULL);
}
/*--------------------------------------------------------------------
* Delete a dynamic director::backend instance. Undeleted dynamic and
* static instances are GC'ed when the VCL is discarded (in cache_vcl.c)
*/
void
VRT_delete_backend(VRT_CTX, struct director **dp)
{
struct director *d;
struct backend *be;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
TAKE_OBJ_NOTNULL(d, dp, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
Lck_Lock(&be->mtx);
be->director->admin_health = VDI_AH_DELETED;
be->director->health_changed = VTIM_real();
be->cooled = VTIM_real() + 60.;
Lck_Unlock(&be->mtx);
Lck_Lock(&backends_mtx);
VTAILQ_REMOVE(&backends, be, list);
VTAILQ_INSERT_TAIL(&cool_backends, be, list);
Lck_Unlock(&backends_mtx);
// NB. The backend is still usable for the ongoing transactions,
// this is why we don't bust the director's magic number.
}
void
VBE_SetHappy(const struct backend *be, uint64_t happy)
{
Lck_Lock(&backends_mtx);
if (be->vsc != NULL)
be->vsc->happy = happy;
Lck_Unlock(&backends_mtx);
}
/*---------------------------------------------------------------------*/
void
VBE_Poll(void)
{
struct backend *be, *be2;
double now = VTIM_real();
ASSERT_CLI();
Lck_Lock(&backends_mtx);
VTAILQ_FOREACH_SAFE(be, &cool_backends, list, be2) {
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
if (be->cooled > now)
break;
if (be->n_conn > 0)
continue;
Lck_Unlock(&backends_mtx);
VCL_DelDirector(be->director);
Lck_Lock(&backends_mtx);
}
Lck_Unlock(&backends_mtx);
}
/*---------------------------------------------------------------------*/
void
VBE_InitCfg(void)
{
Lck_New(&backends_mtx, lck_vbe);
}
@@ -72,12 +72,8 @@ struct backend {
* Prototypes
*/
/* cache_backend.c */
void VBE_fill_director(struct backend *be);
/* cache_backend_cfg.c */
void VBE_SetHappy(const struct backend *, uint64_t);
void VBE_Delete(const struct director *);
/* cache_backend_probe.c */
void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p,
Oops, something went wrong.

0 comments on commit eaac492

Please sign in to comment.