diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-11-01 16:28:19 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-11-01 16:34:10 +0200 |
commit | fffbbfb089847644e2b0281faba2fa892df4f8b9 (patch) | |
tree | 83899ca03d92bdb4100c413904c83385ca0c7d6c /src | |
parent | c16de06862f9b2106dcb7810fc20856689ef2aa6 (diff) | |
download | vmod-binlog-fffbbfb089847644e2b0281faba2fa892df4f8b9.tar.gz vmod-binlog-fffbbfb089847644e2b0281faba2fa892df4f8b9.tar.bz2 |
Support for VCL 4.0
* configure.ac: Version 1.0.91
Detect varnish version and set variables and conditionals accordingly.
* NEWS: Update.
* src/.gitignore: Update.
* src/Makefile.am: Always build vcc_if.c and vcc_if.h. Don't
distribute them.
* src/binlog.c: Use VCL data type. Define them for VCL 3.0.
(vmod_init): Fix premature memory deallocation.
* src/vmod.vcc: Rewrite in VCL 4.0 syntax.
* tests/atlocal.in (ret_vcl_recv): New variable.
* tests/test01.at (vcl_recv): Return $ret_vcl_recv.
* tests/test02.at: Likewise.
Diffstat (limited to 'src')
-rw-r--r-- | src/.gitignore | 2 | ||||
-rw-r--r-- | src/Makefile.am | 37 | ||||
-rw-r--r-- | src/binlog.c | 66 | ||||
-rw-r--r-- | src/vmod-binlog.h | 3 | ||||
-rw-r--r-- | src/vmod.vcc | 111 |
5 files changed, 173 insertions, 46 deletions
diff --git a/src/.gitignore b/src/.gitignore index 8f5a6ab..bae35ac 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -4,2 +4,4 @@ parse-datetime.c vcc_if.c vcc_if.h +*.rst +*.vcc3 diff --git a/src/Makefile.am b/src/Makefile.am index a20f9cb..7917730 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ # This file is part of vmod-binlog -# Copyright (C) 2013 Sergey Poznyakoff +# Copyright (C) 2013-2014 Sergey Poznyakoff # # Vmod-binlog is free software; you can redistribute it and/or modify @@ -15,5 +15,8 @@ # along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>. -AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC) +AM_CPPFLAGS =\ + -I$(VARNISHSRC)/include\ + -I$(VARNISHSRC)/bin/varnishd\ + -I$(VARNISHSRC) noinst_LIBRARIES = libbinlog.a @@ -39,16 +42,32 @@ libvmod_binlog_la_SOURCES = \ binlog.c\ pack.c\ - vmod-binlog.h\ - vcc_if.c vcc_if.h - + vmod-binlog.h +nodist_libvmod_binlog_la_SOURCES = vcc_if.c vcc_if.h noinst_HEADERS = pack.h err.h parse-datetime.h xalloc.h -BUILT_SOURCES = vcc_if.c vcc_if.h +binlog.lo: vcc_if.c vcc_if.h + +CLEANFILES = vcc_if.c vcc_if.h *.rst + +if VARNISH4 + vmodtool = $(VARNISHSRC)/lib/libvcc/vmodtool.py + vmodtoolargs = --strict + vccfile = $(top_srcdir)/src/vmod.vcc +else + vmodtool = $(VARNISHSRC)/lib/libvmod_std/vmod.py + vmodtoolargs = + vccfile = vmod.vcc3 + +vmod.vcc3: $(top_srcdir)/src/vmod.vcc + CLEANFILES += vmod.vcc3 +endif + +.vcc.vcc3: + sed -n '/^\$$/{s///;s/\(Module *[^ ][^ ]*\).*/\1/;p}' $< > $@ -vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc - @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc +vcc_if.c vcc_if.h: $(vmodtool) $(vccfile) + @PYTHON@ $(vmodtool) $(vmodtoolargs) $(vccfile) EXTRA_DIST = vmod.vcc -CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h diff --git a/src/binlog.c b/src/binlog.c index 45299f2..e9fb16e 100644 --- a/src/binlog.c +++ b/src/binlog.c @@ -30,7 +30,18 @@ #include "vrt.h" #include "vcc_if.h" -#include "bin/varnishd/cache.h" +#if VARNISHVERSION == 3 +# include "bin/varnishd/cache.h" +# define VCL_VOID void +# define VCL_STRING const char * +# define MOD_CTX struct sess * +# define WSPTR(s) ((s)->wrk->ws) +#else +# include "bin/varnishd/cache/cache.h" +# define MOD_CTX const struct vrt_ctx * +# define WSPTR(s) ((s)->ws) +#endif #include "vmod-binlog.h" #include "pack.h" +#include "pthread.h" #ifndef O_SEARCH @@ -263,5 +274,5 @@ make_key() void -vmod_init(struct sess *sp, struct vmod_priv *priv, +vmod_init(MOD_CTX ctx, struct vmod_priv *priv, const char *dir, const char *format, const char *param) { @@ -353,5 +364,4 @@ vmod_init(struct sess *sp, struct vmod_priv *priv, abort(); } - free(p); switch (*q) { case 'g': @@ -370,4 +380,5 @@ vmod_init(struct sess *sp, struct vmod_priv *priv, } conf->size = u; + free(p); } else conf->size = BINLOG_SIZE; @@ -427,5 +438,5 @@ vmod_init(struct sess *sp, struct vmod_priv *priv, static char * -mkfilename(struct sess *sp, struct binlog_config *conf) +mkfilename(MOD_CTX ctx, struct binlog_config *conf) { time_t ts = time(NULL); @@ -435,14 +446,14 @@ mkfilename(struct sess *sp, struct binlog_config *conf) if (conf->flags & BLF_ROUNDTS) ts -= ts % conf->interval; - u = WS_Reserve(sp->wrk->ws, 0); - p = sp->wrk->ws->f; + u = WS_Reserve(WSPTR(ctx), 0); + p = WSPTR(ctx)->f; n = strftime(p, u, conf->pattern, gmtime(&ts)); if (n == 0) { - WS_Release(sp->wrk->ws, 0); + WS_Release(WSPTR(ctx), 0); return NULL; } q = strdup(p); AN(q); - WS_Release(sp->wrk->ws, 0); + WS_Release(WSPTR(ctx), 0); return q; } @@ -482,5 +493,5 @@ mkdir_p(struct binlog_config *conf, char *dir) static int -createfile(struct sess *sp, struct binlog_config *conf) +createfile(MOD_CTX ctx, struct binlog_config *conf) { char *fname; @@ -490,5 +501,5 @@ createfile(struct sess *sp, struct binlog_config *conf) conf->fd = -1; - fname = mkfilename(sp, conf); + fname = mkfilename(ctx, conf); if (!fname) return -1; @@ -592,5 +603,5 @@ checkheader(struct binlog_config *conf, size_t hdrsize) static int -newfile(struct sess *sp, struct binlog_config *conf) +newfile(MOD_CTX ctx, struct binlog_config *conf) { int c; @@ -602,5 +613,5 @@ newfile(struct sess *sp, struct binlog_config *conf) setstoptime(conf); - if (createfile(sp, conf)) + if (createfile(ctx, conf)) return -1; @@ -658,5 +669,6 @@ newfile(struct sess *sp, struct binlog_config *conf) conf->fname, (unsigned long)conf->base->recnum)); } else { - debug(conf,1,("created new log file %s",conf->fname)); + debug(conf,1,("created new log file %s, size %lu",conf->fname, + (unsigned long)conf->size)); memcpy(conf->base->magic, BINLOG_MAGIC_STR, BINLOG_MAGIC_LEN); conf->base->version = BINLOG_VERSION; @@ -675,5 +687,5 @@ newfile(struct sess *sp, struct binlog_config *conf) static void -closefile(struct sess *sp, struct binlog_config *conf) +closefile(MOD_CTX ctx, struct binlog_config *conf) { size_t size; @@ -692,6 +704,6 @@ closefile(struct sess *sp, struct binlog_config *conf) } -void -vmod_start(struct sess *sp, struct vmod_priv *priv) +VCL_VOID +vmod_start(MOD_CTX ctx, struct vmod_priv *priv) { struct binlog_config *conf = priv->priv; @@ -706,6 +718,6 @@ vmod_start(struct sess *sp, struct vmod_priv *priv) if (ts >= conf->stoptime) { AZ(pthread_mutex_lock(&conf->mutex)); - closefile(sp, conf); - newfile(sp, conf); + closefile(ctx, conf); + newfile(ctx, conf); AZ(pthread_mutex_unlock(&conf->mutex)); } @@ -715,6 +727,6 @@ vmod_start(struct sess *sp, struct vmod_priv *priv) } -void -vmod_pack(struct sess *sp, struct vmod_priv *priv, const char *str) +VCL_VOID +vmod_pack(MOD_CTX ctx, struct vmod_priv *priv, VCL_STRING str) { struct binlog_config *conf = priv->priv; @@ -750,6 +762,6 @@ vmod_pack(struct sess *sp, struct vmod_priv *priv, const char *str) } -void -vmod_commit(struct sess *sp, struct vmod_priv *priv) +VCL_VOID +vmod_commit(MOD_CTX ctx, struct vmod_priv *priv) { struct binlog_config *conf = priv->priv; @@ -790,6 +802,6 @@ vmod_commit(struct sess *sp, struct vmod_priv *priv) } -void -vmod_sync(struct sess *sp, struct vmod_priv *priv) +VCL_VOID +vmod_sync(MOD_CTX ctx, struct vmod_priv *priv) { struct binlog_config *conf = priv->priv; @@ -804,6 +816,6 @@ vmod_sync(struct sess *sp, struct vmod_priv *priv) } -void -vmod_close(struct sess *sp, struct vmod_priv *priv) +VCL_VOID +vmod_close(MOD_CTX ctx, struct vmod_priv *priv) { struct binlog_config *conf = priv->priv; @@ -814,5 +826,5 @@ vmod_close(struct sess *sp, struct vmod_priv *priv) mutex = conf->mutex; AZ(pthread_mutex_lock(&mutex)); - closefile(sp, conf); + closefile(ctx, conf); close(conf->dd); free(conf->dir); diff --git a/src/vmod-binlog.h b/src/vmod-binlog.h index d67f1cd..fec8d24 100644 --- a/src/vmod-binlog.h +++ b/src/vmod-binlog.h @@ -1,4 +1,4 @@ /* This file is part of vmod-binlog - Copyright (C) 2013 Sergey Poznyakoff + Copyright (C) 2013-2014 Sergey Poznyakoff Vmod-binlog is free software; you can redistribute it and/or modify @@ -15,5 +15,4 @@ along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>. */ - #include <stdint.h> diff --git a/src/vmod.vcc b/src/vmod.vcc index 45da354..b090797 100644 --- a/src/vmod.vcc +++ b/src/vmod.vcc @@ -1,8 +1,103 @@ -Module binlog -Init module_init -Function VOID init(PRIV_VCL, STRING, STRING, STRING) -Function VOID start(PRIV_VCL) -Function VOID commit(PRIV_VCL) -Function VOID pack(PRIV_VCL, STRING) -Function VOID sync(PRIV_VCL) -Function VOID close(PRIV_VCL) +# This file is part of vmod-binlog +# Copyright (C) 2013-2014 Sergey Poznyakoff +# +# Vmod-binlog is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# Vmod-binlog is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>. + +$Module binlog 3 Binary Log File Support + +COLOPHON +======== +This document provides a short description of the **vmod-binlog** module. +For a detailed documentation, please see the vmod-binlog(3) manual page. + +You will find documentation sources in subdirectory **doc** of the +**vmod-binlog** source tree. + +DESCRIPTION +=========== +This module adds binary log files support to Varnish Cache. + +Binary log file consists of an arbitrary number of equally sized +records. Each record contains a UNIX timestamp in binary form and +user-defined data. The file begins with a header containing auxiliary +information. + +Binary log files are rotated at preconfigured time intervals. In order +to speed up searches, their names follow the strftime(3) pattern: + +%Y%m%dT%H%M%S.log + +Binary logs can be viewed using the binlogcat(1) and binlogsel(1) utilities. + +$Init module_init +$Function VOID init(PRIV_VCL, STRING, STRING, STRING) + +Description + Initializes binary log engine. +Example + :: + + binlog.init("/var/lib/varnish/binlog", "LZ[64]L", + "size=1G;index=1;umask=027;roundts=1;debug=2"); + + +$Function VOID start(PRIV_VCL) + +Description + Initialize new binary record. It should be followed by one or + more calls to **binlog.pack** and a final call to **binlog.commit**. +Example + :: + binlog.start(); + +$Function VOID pack(PRIV_VCL, STRING) + +Description + Pack next data item into the binary log record. The item is + converted according to the second argument of **binlog.init**. + The conversion specifier is selected using the ordinal number + of this **pack** call after the latest **binlog.start**. + +$Function VOID commit(PRIV_VCL) + +Description + Finalize the binary log record and commit it. Any uninitialized + fields will be set to 0. + +Example + :: + + binlog.start(); + binlog.pack(http.X-Id); + binlog.pack(http.req.url); + binlog.pack(http.X-Node); + binlog.commit(); + +$Function VOID sync(PRIV_VCL) + +Description + Synchronize the binary log with the disk file. + +$Function VOID close(PRIV_VCL) + +Description + Close the log. This is supposed to be called from **vcl_fini**. + +SEE ALSO +======== + +* binlogcat(1) +* binlogsel(1) +* vcl(7) +* varnishd(1) |