Ema has submitted this change and it was merged. Change subject: New upstream version. Port to Varnish 4. ......................................................................
New upstream version. Port to Varnish 4. Version 1.3 of libvmod-netmapper features some autotools-related changes because of the way vmods are built in Varnish 4. It is now possible to build vmods out-of-tree. Further, architectural changes in Varnish 4 required minor modifcations to the module itself. Change-Id: I1a3facbd96b875c9f88e066092d59fc09bee2c37 --- M Makefile.am M NEWS M autogen.sh M configure.ac M src/Makefile.am M src/vmod_netmapper.c M src/vmod_netmapper.vcc M src/vnm.c 8 files changed, 74 insertions(+), 50 deletions(-) Approvals: Ema: Verified; Looks good to me, approved BBlack: Looks good to me, but someone else must approve diff --git a/Makefile.am b/Makefile.am index d7dcb2b..5b581e7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,6 +2,9 @@ SUBDIRS = src +DISTCHECK_CONFIGURE_FLAGS = \ + VMOD_DIR='$${libdir}/varnish/vmods' + EXTRA_DIST = README.rst dist_man_MANS = vmod_netmapper.3 diff --git a/NEWS b/NEWS index 2039f67..e64a29c 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +1.3 - 2016-02-02 + Use vrt_ctx pointers instead of a sess pointers in VMOD functions. + Use VSLb instead of WSP for logging. + Autotools-related changes because of the way vmods are built in Varnish 4. + 1.2 - 2013-09-12 Added vnm_validate cmdline tool. Exit status indicates JSON parse-ability. Accepts IP addr as extra argument for manual results debugging. diff --git a/autogen.sh b/autogen.sh index 9a12ef5..08d225b 100755 --- a/autogen.sh +++ b/autogen.sh @@ -35,8 +35,19 @@ esac fi -set -ex +# check for varnishapi.m4 in custom paths +dataroot=$(pkg-config --variable=datarootdir varnishapi 2>/dev/null) +if [ -z "$dataroot" ] ; then + cat >&2 <<'EOF' +Package varnishapi was not found in the pkg-config search path. +Perhaps you should add the directory containing `varnishapi.pc' +to the PKG_CONFIG_PATH environment variable +EOF + exit 1 +fi +set -ex +[ -d m4 ] || mkdir m4 aclocal -I m4 $LIBTOOLIZE --copy --force autoheader diff --git a/configure.ac b/configure.ac index aa0a8fd..c763247 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,8 @@ AC_PREREQ(2.59) -AC_COPYRIGHT([Copyright (c) 2013 Brandon Black <bbl...@wikimedia.org>]) -AC_INIT([libvmod-netmapper],[1.2],[bbl...@wikimedia.org],[libvmod-netmapper],[https://git.wikimedia.org/summary/operations%2Fsoftware%2Fvarnish%2Flibvmod-netmapper]) +AC_COPYRIGHT([Copyright (c) 2013-2016 Brandon Black <bbl...@wikimedia.org>]) +AC_INIT([libvmod-netmapper],[1.3],[bbl...@wikimedia.org],[libvmod-netmapper],[https://git.wikimedia.org/summary/operations%2Fsoftware%2Fvarnish%2Flibvmod-netmapper]) AC_CONFIG_MACRO_DIR([m4]) +m4_ifndef([VARNISH_VMOD_INCLUDES], AC_MSG_ERROR([Need varnish.m4])) AC_CONFIG_AUX_DIR([acaux]) AC_CONFIG_SRCDIR(src/vmod_netmapper.vcc) AM_CONFIG_HEADER(config.h) @@ -41,36 +42,35 @@ # Check for python AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 python], [AC_MSG_ERROR([Python is needed to build this vmod, please install python.])]) -# Varnish source tree -AC_ARG_VAR([VARNISHSRC], [path to Varnish source tree (mandatory)]) -if test "x$VARNISHSRC" = x; then - AC_MSG_ERROR([No Varnish source tree specified]) -fi -VARNISHSRC=`cd $VARNISHSRC && pwd` -AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h], - [], - [AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])] -) +PKG_CHECK_MODULES([libvarnishapi], [varnishapi]) +PKG_CHECK_VAR([LIBVARNISHAPI_PREFIX], [varnishapi], [prefix]) +PKG_CHECK_VAR([LIBVARNISHAPI_DATAROOTDIR], [varnishapi], [datarootdir]) +PKG_CHECK_VAR([LIBVARNISHAPI_BINDIR], [varnishapi], [bindir]) +PKG_CHECK_VAR([LIBVARNISHAPI_SBINDIR], [varnishapi], [sbindir]) +AC_SUBST([LIBVARNISHAPI_DATAROOTDIR]) -# varnishd and varnishtest locations (default from source tree) +# Varnish include files tree +VARNISH_VMOD_INCLUDES +VARNISH_VMOD_DIR +VARNISH_VMODTOOL +# AC_PREFIX_DEFAULT acts too early in the configure run, +# so we can't use it +ac_default_prefix=$LIBVARNISHAPI_PREFIX -AC_ARG_VAR([VARNISHD], [path to varnishd binary (default: used built copy in VARNISHSRC)]) -if test "x$VARNISHD" = x; then - VARNISHD="$VARNISHSRC/bin/varnishd/varnishd" -fi -AC_CHECK_FILE([$VARNISHD], - [], - [AC_MSG_FAILURE([varnishd binary "$VARNISHD" does not exist])] -) +AC_PATH_PROG([VARNISHTEST], [varnishtest], [], + [$LIBVARNISHAPI_BINDIR:$LIBVARNISHAPI_SBINDIR:$PATH]) +AC_PATH_PROG([VARNISHD], [varnishd], [], + [$LIBVARNISHAPI_SBINDIR:$LIBVARNISHAPI_BINDIR:$PATH]) -AC_ARG_VAR([VARNISHTEST], [path to varnishtest binary (default: used built copy in VARNISHSRC)]) -if test "x$VARNISHTEST" = x; then - VARNISHTEST="$VARNISHSRC/bin/varnishtest/varnishtest" -fi -AC_CHECK_FILE([$VARNISHTEST], - [], - [AC_MSG_FAILURE([varnishtest binary "$VARNISHTEST" does not exist])] -) +AC_CHECK_FILE([${VAPI_INCLUDE_DIR}/vmod_abi.h], + [ + AC_MSG_CHECKING([varnish ABI version]) + AC_SUBST([VMOD_ABI_VERSION], + [`cut -d ' ' -f 4 "${VAPI_INCLUDE_DIR}/vmod_abi.h"`]) + AC_MSG_RESULT([${VMOD_ABI_VERSION}]) + ], [ + AC_MSG_ERROR([Could not find vmod_abi.h. Need Varnish4 or higher]) + ]) XLIBS=$LIBS diff --git a/src/Makefile.am b/src/Makefile.am index 52591ed..17ab3ab 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,4 @@ -VARNISHSRC ?= $(top_srcdir) - -AM_CPPFLAGS = -I$(VARNISHSRC)/include -I$(VARNISHSRC) -I$(srcdir)/nlt +AM_CPPFLAGS = @VMOD_INCLUDES@ -I$(srcdir)/nlt COMMON_SRC = \ vnm.c \ @@ -12,10 +10,12 @@ nlt/ntree.c \ nlt/ntree.h -vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(srcdir)/vmod_netmapper.vcc - @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(srcdir)/vmod_netmapper.vcc +vcc_if.c: vcc_if.h -vmoddir = $(libdir)/varnish/vmods +vcc_if.h: @VMODTOOL@ $(srcdir)/vmod_netmapper.vcc + @VMODTOOL@ $(srcdir)/vmod_netmapper.vcc + +vmoddir = @VMOD_DIR@ vmod_LTLIBRARIES = libvmod_netmapper.la libvmod_netmapper_la_LDFLAGS = -module -export-dynamic -avoid-version -shared @@ -41,4 +41,4 @@ EXTRA_DIST = nlt/README vmod_netmapper.vcc $(VMOD_TESTS) $(VMOD_TDATA) -CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h +CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h $(builddir)/vmod_netmapper.rst $(builddir)/vmod_netmapper.man.rst diff --git a/src/vmod_netmapper.c b/src/vmod_netmapper.c index 91a88ce..aa02460 100644 --- a/src/vmod_netmapper.c +++ b/src/vmod_netmapper.c @@ -18,7 +18,8 @@ */ #include "vrt.h" -#include "bin/varnishd/cache.h" + +#include "cache/cache.h" #include "vcc_if.h" #include <stdbool.h> @@ -57,12 +58,16 @@ // Copy a str_t*'s data to a const char* in the session workspace, // so that after return we're not holding references to data in // the vnm db, so that it can be swapped for update between... -static const char* vnm_str_to_vcl(struct sess* sp, const vnm_str_t* str) { +static const char* vnm_str_to_vcl(const struct vrt_ctx *ctx, const vnm_str_t* str) { char* rv = NULL; + struct vsl_log *vsl; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + if(str->data) { - rv = WS_Alloc(sp->wrk->ws, str->len); + rv = WS_Alloc(ctx->ws, str->len); if(!rv) - WSP(sp, SLT_Error, "vmod_netmapper: no space for string retval!"); + VSLb(vsl, SLT_Error, "vmod_netmapper: no space for string retval!"); else memcpy(rv, str->data, str->len); } @@ -132,7 +137,7 @@ * Actual VMOD/VCL/VRT Hooks * *****************************/ -void vmod_init(struct sess *sp, struct vmod_priv *priv, const char* db_label, const char* json_path, const int reload_interval) { +VCL_VOID vmod_init(VRT_CTX, struct vmod_priv *priv, VCL_STRING db_label, VCL_STRING json_path, VCL_INT reload_interval) { vnm_priv_t* vp = priv->priv; if(!vp) { @@ -166,9 +171,9 @@ static void destruct_rcu(void* x) { pthread_setspecific(unreg_hack, NULL); rcu_unregister_thread(); } static void make_unreg_hack(void) { pthread_key_create(&unreg_hack, destruct_rcu); } -const char* vmod_map(struct sess *sp, struct vmod_priv* priv, const char* db_label, const char* ip_string) { - assert(sp); assert(priv); assert(priv->priv); assert(ip_string); - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); +const char* vmod_map(const struct vrt_ctx *ctx, struct vmod_priv* priv, const char* db_label, const char* ip_string) { + assert(ctx); assert(priv); assert(priv->priv); assert(ip_string); + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); // The rest of the rcu register/unregister hack static __thread bool rcu_registered = false; @@ -205,7 +210,7 @@ // string to a vcl string and return it... const vnm_str_t* str = vnm_lookup(dbptr, ip_string); if(str) - rv = vnm_str_to_vcl(sp, str); + rv = vnm_str_to_vcl(ctx, str); } else { VSL(SLT_Error, 0, "vmod_netmapper: JSON database label '%s' was never succesfully loaded!", db_label); diff --git a/src/vmod_netmapper.vcc b/src/vmod_netmapper.vcc index 1f33ea9..63102be 100644 --- a/src/vmod_netmapper.vcc +++ b/src/vmod_netmapper.vcc @@ -1,3 +1,3 @@ -Module netmapper -Function VOID init(PRIV_VCL, STRING, STRING, INT) -Function STRING map(PRIV_VCL, STRING, STRING) +$Module netmapper 3 +$Function VOID init(PRIV_VCL, STRING, STRING, INT) +$Function STRING map(PRIV_VCL, STRING, STRING) diff --git a/src/vnm.c b/src/vnm.c index a326fc8..262c006 100644 --- a/src/vnm.c +++ b/src/vnm.c @@ -20,7 +20,7 @@ #ifdef NO_VARNISH #define ERR(fmt,...) fprintf(stderr, fmt "\n", ##__VA_ARGS__) #else -#include "bin/varnishd/cache.h" +#include "cache/cache.h" #define ERR(fmt,...) VSL(SLT_Error, 0, "vmod_netmapper: " fmt, ##__VA_ARGS__) #endif -- To view, visit https://gerrit.wikimedia.org/r/267885 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I1a3facbd96b875c9f88e066092d59fc09bee2c37 Gerrit-PatchSet: 1 Gerrit-Project: operations/software/varnish/libvmod-netmapper Gerrit-Branch: master Gerrit-Owner: Ema <e...@wikimedia.org> Gerrit-Reviewer: BBlack <bbl...@wikimedia.org> Gerrit-Reviewer: Ema <e...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits