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

Add a list of refcounted VMOD's we have loaded.

Add stats counter to keep track of how many vmods are on the list
mostly so the testcase can see that it works.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5184 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 3ab5f005
......@@ -699,6 +699,9 @@ void ESI_Deliver(struct sess *);
void ESI_Destroy(struct object *);
void ESI_Parse(struct sess *);
/* cache_vrt_vmod.c */
void VMOD_Init(void);
/* cache_ws.c */
void WS_Init(struct ws *ws, const char *id, void *space, unsigned len);
......
......@@ -129,6 +129,8 @@ child_main(void)
SMS_Init();
STV_open();
VMOD_Init();
BAN_Compile();
/* Wait for persistent storage to load if asked to */
......
......@@ -38,6 +38,7 @@ SVNID("$Id$")
#include <stdlib.h>
#include <dlfcn.h>
#include "cli_priv.h"
#include "vrt.h"
#include "cache.h"
......@@ -46,6 +47,13 @@ SVNID("$Id$")
*/
struct vmod {
unsigned magic;
#define VMOD_MAGIC 0xb750219c
VTAILQ_ENTRY(vmod) list;
int ref;
char *nm;
char *path;
void *hdl;
......@@ -53,6 +61,8 @@ struct vmod {
int funclen;
};
static VTAILQ_HEAD(,vmod) vmods = VTAILQ_HEAD_INITIALIZER(vmods);
void
VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm, const char *path)
{
......@@ -61,28 +71,41 @@ VRT_Vmod_Init(void **hdl, void *ptr, int len, const char *nm, const char *path)
const int *i;
const char *p;
v = calloc(sizeof *v, 1);
AN(v);
REPLACE(v->nm, nm);
REPLACE(v->path, path);
v->hdl = dlopen(v->path, RTLD_NOW | RTLD_LOCAL);
AN(v->hdl);
ASSERT_CLI();
VTAILQ_FOREACH(v, &vmods, list)
if (!strcmp(v->nm, nm))
break;
if (v == NULL) {
ALLOC_OBJ(v, VMOD_MAGIC);
AN(v);
VTAILQ_INSERT_TAIL(&vmods, v, list);
VSC_main->vmods++;
x = dlsym(v->hdl, "Vmod_Name");
AN(x);
p = x;
REPLACE(v->nm, nm);
REPLACE(v->path, path);
x = dlsym(v->hdl, "Vmod_Len");
AN(x);
i = x;
assert(len == *i);
v->hdl = dlopen(v->path, RTLD_NOW | RTLD_LOCAL);
AN(v->hdl);
x = dlsym(v->hdl, "Vmod_Func");
AN(x);
memcpy(ptr, x, len);
x = dlsym(v->hdl, "Vmod_Name");
AN(x);
p = x;
v->funcs = x;
v->funclen = *i;
x = dlsym(v->hdl, "Vmod_Len");
AN(x);
i = x;
assert(len == *i);
x = dlsym(v->hdl, "Vmod_Func");
AN(x);
memcpy(ptr, x, len);
v->funcs = x;
v->funclen = *i;
}
v->ref++;
*hdl = v;
}
......@@ -92,8 +115,44 @@ VRT_Vmod_Fini(void **hdl)
{
struct vmod *v;
ASSERT_CLI();
AN(*hdl);
v = *hdl;
free(*hdl);
CAST_OBJ_NOTNULL(v, *hdl, VMOD_MAGIC);
*hdl = NULL;
if (--v->ref != 0)
return;
dlclose(v->hdl);
free(v->nm);
free(v->path);
VTAILQ_REMOVE(&vmods, v, list);
VSC_main->vmods--;
FREE_OBJ(v);
}
/*---------------------------------------------------------------------*/
static void
ccf_debug_vmod(struct cli *cli, const char * const *av, void *priv)
{
struct vmod *v;
(void)av;
(void)priv;
ASSERT_CLI();
VTAILQ_FOREACH(v, &vmods, list)
cli_out(cli, "%5d %s (%s)\n", v->ref, v->nm, v->path);
}
static struct cli_proto vcl_cmds[] = {
{ "debug.vmod", "debug.vmod", "show loaded vmods", 0, 0,
"d", ccf_debug_vmod },
{ NULL }
};
void
VMOD_Init(void)
{
CLI_AddFuncs(vcl_cmds);
}
# $Id$
test "Test std vmod"
server s1 {
rxreq
txresp -hdr "foo: bAr" -hdr "bar: fOo" -bodylen 4
} -start
varnish v1 -vcl+backend {
import std from "${topsrc}/lib/libvmod_std/.libs/libvmod_std.so.1" ;
sub vcl_deliver {
set resp.http.foo = std.toupper(resp.http.foo);
set resp.http.bar = std.tolower(resp.http.bar);
}
} -start
client c1 {
txreq -url "/bar"
rxresp
expect resp.status == 200
expect resp.http.content-length == "4"
expect resp.http.foo == "BAR"
expect resp.http.bar == "foo"
} -run
varnish v1 -vcl+backend {
}
client c1 {
txreq -url "/bar"
rxresp
expect resp.status == 200
expect resp.http.content-length == "4"
expect resp.http.foo == "bAr"
expect resp.http.bar == "fOo"
} -run
client c1 -run
varnish v1 -expect vmods == 1
varnish v1 -cliok "debug.vmod"
varnish v1 -cliok "vcl.list"
varnish v1 -cliok "vcl.discard vcl1"
varnish v1 -cliok "vcl.list"
varnish v1 -cliok "debug.vmod"
varnish v1 -expect vmods == 0
......@@ -163,6 +163,8 @@ VSC_F_MAIN(dir_dns_cache_full, uint64_t, 0, 'a', "DNS director full dnscache")
VSC_F_MAIN(critbit_cooler, uint64_t, 0, 'i', "Objhdr's on cool list")
VSC_F_MAIN(vmods, uint64_t, 0, 'i', "Loaded VMODs")
#ifdef __VSC_F_MAIN
#undef VSC_F_MAIN
#undef __VSC_F_MAIN
......
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