Commit cc4455d0 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move VPI stuff out of VRT

parent df178b49
......@@ -44,6 +44,7 @@ varnishd_SOURCES = \
cache/cache_tcp_pool.c \
cache/cache_vary.c \
cache/cache_vcl.c \
cache/cache_vpi.c \
cache/cache_vrt.c \
cache/cache_vrt_filter.c \
cache/cache_vrt_priv.c \
......
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2019 Varnish Software 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 "cache_varnishd.h"
#include "vcl.h"
#include "vcc_interface.h"
#include "cache_vcl.h"
/*--------------------------------------------------------------------
* Private & exclusive interfaces between VCC and varnishd
*/
void
VPI_count(VRT_CTX, unsigned u)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
CHECK_OBJ_NOTNULL(ctx->vcl->conf, VCL_CONF_MAGIC);
assert(u < ctx->vcl->conf->nref);
if (ctx->vsl != NULL)
VSLb(ctx->vsl, SLT_VCL_trace, "%s %u %u.%u.%u",
ctx->vcl->loaded_name, u, ctx->vcl->conf->ref[u].source,
ctx->vcl->conf->ref[u].line, ctx->vcl->conf->ref[u].pos);
else
VSL(SLT_VCL_trace, 0, "%s %u %u.%u.%u",
ctx->vcl->loaded_name, u, ctx->vcl->conf->ref[u].source,
ctx->vcl->conf->ref[u].line, ctx->vcl->conf->ref[u].pos);
}
VCL_VCL
VPI_vcl_get(VRT_CTX, const char *name)
{
VCL_VCL vcl;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
vcl = vcl_find(name);
AN(vcl);
Lck_Lock(&vcl_mtx);
vcl->nrefs++;
Lck_Unlock(&vcl_mtx);
return (vcl);
}
void
VPI_vcl_rel(VRT_CTX, VCL_VCL vcl)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(vcl);
Lck_Lock(&vcl_mtx);
vcl->nrefs--;
Lck_Unlock(&vcl_mtx);
}
void
VPI_vcl_select(VRT_CTX, VCL_VCL vcl)
{
struct req *req = ctx->req;
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
if (IS_TOPREQ(req) && req->vcl0 != NULL)
return; // Illega, req-FSM will fail this later.
VCL_TaskLeave(req->vcl, req->privs);
if (IS_TOPREQ(req)) {
req->vcl0 = req->vcl;
req->vcl = NULL;
} else {
VCL_Rel(&req->vcl);
}
vcl_get(&req->vcl, vcl);
VSLb(ctx->req->vsl, SLT_VCL_use, "%s via %s",
req->vcl->loaded_name, vcl->loaded_name);
VCL_TaskEnter(req->vcl, req->privs);
}
......@@ -38,8 +38,6 @@
#include "vcl.h"
#include "vtim.h"
#include "vcc_interface.h"
#include "cache_director.h"
#include "cache_vcl.h"
......@@ -324,75 +322,6 @@ VCL_DefaultProbe(const struct vcl *vcl)
return (vcl->conf->default_probe);
}
/*--------------------------------------------------------------------
* VRT apis relating to VCL's as VCLS.
*/
void
VRT_count(VRT_CTX, unsigned u)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->vcl, VCL_MAGIC);
CHECK_OBJ_NOTNULL(ctx->vcl->conf, VCL_CONF_MAGIC);
assert(u < ctx->vcl->conf->nref);
if (ctx->vsl != NULL)
VSLb(ctx->vsl, SLT_VCL_trace, "%s %u %u.%u.%u",
ctx->vcl->loaded_name, u, ctx->vcl->conf->ref[u].source,
ctx->vcl->conf->ref[u].line, ctx->vcl->conf->ref[u].pos);
else
VSL(SLT_VCL_trace, 0, "%s %u %u.%u.%u",
ctx->vcl->loaded_name, u, ctx->vcl->conf->ref[u].source,
ctx->vcl->conf->ref[u].line, ctx->vcl->conf->ref[u].pos);
}
VCL_VCL
VPI_vcl_get(VRT_CTX, const char *name)
{
VCL_VCL vcl;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
vcl = vcl_find(name);
AN(vcl);
Lck_Lock(&vcl_mtx);
vcl->nrefs++;
Lck_Unlock(&vcl_mtx);
return (vcl);
}
void
VPI_vcl_rel(VRT_CTX, VCL_VCL vcl)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(vcl);
Lck_Lock(&vcl_mtx);
vcl->nrefs--;
Lck_Unlock(&vcl_mtx);
}
void
VPI_vcl_select(VRT_CTX, VCL_VCL vcl)
{
struct req *req = ctx->req;
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
if (IS_TOPREQ(req) && req->vcl0 != NULL)
return; // Illega, req-FSM will fail this later.
VCL_TaskLeave(req->vcl, req->privs);
if (IS_TOPREQ(req)) {
req->vcl0 = req->vcl;
req->vcl = NULL;
} else {
VCL_Rel(&req->vcl);
}
vcl_get(&req->vcl, vcl);
VSLb(ctx->req->vsl, SLT_VCL_use, "%s via %s",
req->vcl->loaded_name, vcl->loaded_name);
VCL_TaskEnter(req->vcl, req->privs);
}
struct vclref *
VRT_ref_vcl(VRT_CTX, const char *desc)
{
......
......@@ -36,3 +36,17 @@
VCL_VCL VPI_vcl_get(VRT_CTX, const char *);
void VPI_vcl_rel(VRT_CTX, VCL_VCL);
void VPI_vcl_select(VRT_CTX, VCL_VCL);
/***********************************************************************
* VPI_count() refers to this structure for coordinates into the VCL source.
*/
struct vpi_ref {
unsigned source;
unsigned offset;
unsigned line;
unsigned pos;
const char *token;
};
void VPI_count(VRT_CTX, unsigned);
......@@ -376,19 +376,6 @@ struct vrt_backend_probe {
VRT_BACKEND_PROBE_FIELDS(const)
};
/***********************************************************************
* VRT_count() refers to this structure for coordinates into the VCL source.
*/
struct vrt_ref {
unsigned source;
unsigned offset;
unsigned line;
unsigned pos;
const char *token;
};
void VRT_count(VRT_CTX, unsigned);
/***********************************************************************
* Implementation details of ACLs
......
......@@ -42,8 +42,10 @@ dist_pkgdata_SCRIPTS = \
## keep in sync with include/Makefile.am
vcc_obj.c: \
$(top_srcdir)/lib/libvcc/generate.py \
$(top_srcdir)/include/vcc_interface.h \
$(top_srcdir)/include/vdef.h \
$(top_srcdir)/include/vrt.h
$(top_srcdir)/include/vrt.h \
$(top_srcdir)/include/vrt_obj.h
mkdir -p $(top_builddir)/include/tbl
@PYTHON@ $(top_srcdir)/lib/libvcc/generate.py \
$(top_srcdir) $(top_builddir)
......
......@@ -651,8 +651,8 @@ struct VCL_conf {
unsigned syntax;
VCL_BACKEND *default_director;
VCL_PROBE default_probe;
int nref;
const struct vrt_ref *ref;
unsigned nref;
const struct vpi_ref *ref;
int nsrc;
const char **srcname;
......
......@@ -243,7 +243,7 @@ EmitCoordinates(const struct vcc *tl, struct vsb *vsb)
VSB_printf(vsb, "\n#define VGC_NREFS %u\n\n", tl->cnt + 1);
VSB_printf(vsb, "static const struct vrt_ref VGC_ref[VGC_NREFS] = {\n");
VSB_printf(vsb, "static const struct vpi_ref VGC_ref[VGC_NREFS] = {\n");
lin = 1;
pos = 0;
sp = 0;
......
......@@ -46,7 +46,7 @@ static void vcc_Compound(struct vcc *tl);
} while (0)
#define C(tl, sep) do { \
Fb(tl, 1, "VRT_count(ctx, %u)%s\n", ++tl->cnt, sep); \
Fb(tl, 1, "VPI_count(ctx, %u)%s\n", ++tl->cnt, sep); \
tl->t->cnt = tl->cnt; \
} while (0)
......
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