Commit 81b988c1 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Create a new vmod "directors" and move the demo-rr director into it,

it is no longer a demo, it is going to replace the "built-in" rr
director.

Other directors will follow as time permits.
parent 7f501a1c
......@@ -26,6 +26,7 @@ flexelint \
../../lib/libvcl/*.c \
../../lib/libvmod_std/*.c \
../../lib/libvmod_debug/*.c \
../../lib/libvmod_directors/*.c \
2>&1 | tee _.fl
if [ -f _.fl.old ] ; then
......
varnishtest "Test vmod.debug round robin director"
varnishtest "Test vmod.directors round robin director"
server s1 {
......@@ -25,9 +25,9 @@ server s4 {
varnish v1 -vcl+backend {
import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
import directors from "${topbuild}/lib/libvmod_directors/.libs/libvmod_directors.so" ;
sub vcl_init {
new rr = debug.rr();
new rr = directors.round_robin();
rr.add_backend(s1);
rr.add_backend(s2);
rr.add_backend(s3);
......
varnishtest "Test vmod.debug round robin director"
varnishtest "Test vmod.directors round robin director in stacked fashion"
server s1 {
......@@ -25,17 +25,17 @@ server s4 {
varnish v1 -vcl+backend {
import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
import directors from "${topbuild}/lib/libvmod_directors/.libs/libvmod_directors.so" ;
sub vcl_init {
new rr1 = debug.rr();
new rr1 = directors.round_robin();
rr1.add_backend(s1);
rr1.add_backend(s3);
new rr2 = debug.rr();
new rr2 = directors.round_robin();
rr2.add_backend(s2);
rr2.add_backend(s4);
new rr3 = debug.rr();
new rr3 = directors.round_robin();
rr3.add_backend(rr1.backend());
rr3.add_backend(rr2.backend());
}
......
......@@ -607,6 +607,7 @@ AC_CONFIG_FILES([
lib/libvgz/Makefile
lib/libvmod_debug/Makefile
lib/libvmod_std/Makefile
lib/libvmod_directors/Makefile
lib/libjemalloc/Makefile
man/Makefile
redhat/Makefile
......
......@@ -8,6 +8,7 @@ SUBDIRS = \
libvgz \
libvmod_debug \
libvmod_std \
libvmod_directors \
@JEMALLOC_SUBDIR@
DIST_SUBDIRS = \
......
......@@ -15,8 +15,7 @@ libvmod_debug_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version
libvmod_debug_la_SOURCES = \
vmod_debug.c \
vmod_debug_obj.c \
vmod_debug_rr.c
vmod_debug_obj.c
nodist_libvmod_debug_la_SOURCES = \
vcc_if.c \
......
......@@ -35,8 +35,3 @@ Object obj(STRING) {
Method STRING .foo(STRING why)
Method TIME .date()
}
Object rr() {
Method VOID .add_backend(BACKEND)
Method BACKEND .backend()
}
#
AM_LDFLAGS = $(AM_LT_LDFLAGS)
AM_CPPFLAGS = \
-I$(top_srcdir)/include \
-I$(top_srcdir)/bin/varnishd \
-I$(top_builddir)/include
vmoddir = $(pkglibdir)/vmods
vmod_srcdir = $(top_srcdir)/lib/libvmod_directors
vmodtool = $(top_srcdir)/lib/libvcl/vmodtool.py
noinst_LTLIBRARIES = libvmod_directors.la
libvmod_directors_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version -shared -rpath /nowhere
libvmod_directors_la_SOURCES = \
round_robin.c
nodist_libvmod_directors_la_SOURCES = \
vcc_if.c \
vcc_if.h
# BUILT_SOURCES is only a hack and dependency tracking does not help for the first build
vmod_directors.lo: vcc_if.h
vcc_if.c vcc_if.h: $(vmodtool) $(vmod_srcdir)/vmod.vcc
@PYTHON@ $(vmodtool) $(vmod_srcdir)/vmod.vcc
EXTRA_DIST = vmod.vcc
CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
......@@ -36,17 +36,17 @@
#include "vrt.h"
#include "vcc_if.h"
struct vmod_debug_rr_entry {
struct rr_entry {
unsigned magic;
#define VMOD_DEBUG_RR_ENTRY_MAGIC 0xa80970cf
VTAILQ_ENTRY(vmod_debug_rr_entry) list;
#define RR_ENTRY_MAGIC 0xa80970cf
VTAILQ_ENTRY(rr_entry) list;
VCL_BACKEND be;
};
struct vmod_debug_rr {
struct vmod_directors_round_robin {
unsigned magic;
#define VMOD_DEBUG_RR_MAGIC 0x99f4b726
VTAILQ_HEAD(, vmod_debug_rr_entry) listhead;
VTAILQ_HEAD(, rr_entry) listhead;
int nbe;
pthread_mutex_t mtx;
struct director *dir;
......@@ -55,8 +55,8 @@ struct vmod_debug_rr {
static unsigned
vmod_rr_healthy(const struct director *dir, const struct req *req)
{
struct vmod_debug_rr_entry *ep;
struct vmod_debug_rr *rr;
struct rr_entry *ep;
struct vmod_directors_round_robin *rr;
unsigned retval = 0;
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DEBUG_RR_MAGIC);
......@@ -74,8 +74,8 @@ vmod_rr_healthy(const struct director *dir, const struct req *req)
static struct vbc *
vmod_rr_getfd(const struct director *dir, struct req *req)
{
struct vmod_debug_rr_entry *ep = NULL;
struct vmod_debug_rr *rr;
struct rr_entry *ep = NULL;
struct vmod_directors_round_robin *rr;
int i;
CAST_OBJ_NOTNULL(rr, dir->priv, VMOD_DEBUG_RR_MAGIC);
......@@ -94,9 +94,10 @@ vmod_rr_getfd(const struct director *dir, struct req *req)
}
VCL_VOID
vmod_rr__init(struct req *req, struct vmod_debug_rr **rrp, const char *vcl_name)
vmod_round_robin__init(struct req *req, struct vmod_directors_round_robin **rrp,
const char *vcl_name)
{
struct vmod_debug_rr *rr;
struct vmod_directors_round_robin *rr;
(void)req;
......@@ -116,10 +117,10 @@ vmod_rr__init(struct req *req, struct vmod_debug_rr **rrp, const char *vcl_name)
}
VCL_VOID
vmod_rr__fini(struct req *req, struct vmod_debug_rr **rrp)
vmod_round_robin__fini(struct req *req, struct vmod_directors_round_robin **rrp)
{
struct vmod_debug_rr *rr;
struct vmod_debug_rr_entry *ep;
struct vmod_directors_round_robin *rr;
struct rr_entry *ep;
(void)req;
......@@ -139,12 +140,13 @@ vmod_rr__fini(struct req *req, struct vmod_debug_rr **rrp)
}
VCL_VOID
vmod_rr_add_backend(struct req *req, struct vmod_debug_rr * rr, VCL_BACKEND be)
vmod_round_robin_add_backend(struct req *req, struct vmod_directors_round_robin * rr,
VCL_BACKEND be)
{
struct vmod_debug_rr_entry *ep;
struct rr_entry *ep;
(void)req;
ALLOC_OBJ(ep, VMOD_DEBUG_RR_ENTRY_MAGIC);
ALLOC_OBJ(ep, RR_ENTRY_MAGIC);
AN(ep);
ep->be = be;
AZ(pthread_mutex_lock(&rr->mtx));
......@@ -154,7 +156,7 @@ vmod_rr_add_backend(struct req *req, struct vmod_debug_rr * rr, VCL_BACKEND be)
}
VCL_BACKEND __match_proto__()
vmod_rr_backend(struct req *req, struct vmod_debug_rr *rr)
vmod_round_robin_backend(struct req *req, struct vmod_directors_round_robin *rr)
{
(void)req;
return (rr->dir);
......
#-
# Copyright (c) 2013 Varnish Software AS
# All rights reserved.
#
# Author: Poul-Henning Kamp <phk@FreeBSD.org>
#
# 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.
Module directors
Object round_robin() {
Method VOID .add_backend(BACKEND)
Method BACKEND .backend()
}
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