From cecilihf at projects.linpro.no Mon Jul 2 07:14:53 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Mon, 2 Jul 2007 09:14:53 +0200 (CEST) Subject: r1604 - in trunk/varnish-tools: . nagios Message-ID: <20070702071453.A60F11EC030@projects.linpro.no> Author: cecilihf Date: 2007-07-02 09:14:53 +0200 (Mon, 02 Jul 2007) New Revision: 1604 Added: trunk/varnish-tools/nagios/ trunk/varnish-tools/nagios/Makefile trunk/varnish-tools/nagios/check_varnish.c Log: Added nagios plugin for varnish. It is very basic, and still needs some more work. All parameters shown with the use of varnishstat -1 can be monitored. Added: trunk/varnish-tools/nagios/Makefile =================================================================== --- trunk/varnish-tools/nagios/Makefile (rev 0) +++ trunk/varnish-tools/nagios/Makefile 2007-07-02 07:14:53 UTC (rev 1604) @@ -0,0 +1,7 @@ +CFLAGS = -I ../../varnish-cache/include -O2 -Wall -pedantic -std=c99 -D_GNU_SOURCE +LDFLAGS = -L /opt/varnish/lib -lvarnishapi + +all: check_varnish + +clean: + -rm check_varnish \ No newline at end of file Added: trunk/varnish-tools/nagios/check_varnish.c =================================================================== --- trunk/varnish-tools/nagios/check_varnish.c (rev 0) +++ trunk/varnish-tools/nagios/check_varnish.c 2007-07-02 07:14:53 UTC (rev 1604) @@ -0,0 +1,162 @@ +/*- + * Copyright (c) 2006-2007 Linpro AS + * All rights reserved. + * + * Author: Cecilie Fritzvold + * + * 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. + * + * $Id$ + * + * Nagios plugin for Varnish + */ + +#include +#include +#include +#include +#include + +#include "shmlog.h" +#include "varnishapi.h" + + + +static int +check_treshold(int value, int warn, int crit, int less) +{ + if (!less) { + if (value < warn) + return 0; + else if (value < crit) + return 1; + } + else { + if (value > warn) + return 0; + else if (value > crit) + return 1; + } + return 2; + +} + +static void +message_and_exit(int level, int value, char *info) +{ + if (level == 0) + printf("OK: "); + else if (level == 1) + printf("Warning: "); + else if (level == 2) + printf("Critical: "); + else + printf("Uknown: "); + + printf("%d %s\n", value, info); + exit(level); +} + +static void +check_stats(struct varnish_stats *VSL_stats, char *param, int w, int c, int less) +{ +#define MAC_STAT(n, t, f, d) \ + do { \ + intmax_t ju = VSL_stats->n; \ + int level; \ + if (!strcmp(param, #n)) { \ + level = check_treshold(ju, w, c, less); \ + message_and_exit(level, ju, d); \ + } \ + } while (0); +#include "stat_field.h" +#undef MAC_STAT +} + +static void +help(void) +{ + fprintf(stderr, "usage: check_varnish -p param_name -c N -w N [-l] [-n varnish_name] [-v]\n" + "Valid options:\n" + "-c N\t\t warn as critical at treshold N\n" + "-l\t\t specify that values should be less than tresholds for warnings to be issued\n" + "-n varnish_name\t specify varnish instance name\n" + "-p param_name\t specify the parameter to check. See valid parameters\n" + "-v\t\t print verbose output. Can be specified up to three times\n" + "-w N\t\t warn as warning at treshold N\n" + ); + exit(0); +} + +static void +usage(void) +{ + fprintf(stderr, "usage: check_varnish -p param_name -c N -w N [-l] [-n varnish_name] [-v]\n"); + exit(3); +} + + +int +main(int argc, char **argv) +{ + int c; + struct varnish_stats *VSL_stats; + int critical = 0, warning = 0; + int verbose = 0; + const char *n_arg = NULL; + char *param = NULL; + int less = 0; + + while ((c = getopt(argc, argv, "c:hln:p:vw:")) != -1) { + switch (c) { + case 'c': + critical = atoi(optarg); + break; + case 'h': + help(); + case 'l': + less = 1; + break; + case 'n': + n_arg = optarg; + break; + case 'p': + param = strdup(optarg); + break; + case 'v': + verbose++; + break; + case 'w': + warning = atoi(optarg); + break; + default: + usage(); + } + } + + if ((VSL_stats = VSL_OpenStats(n_arg)) == NULL) + exit(1); + + check_stats(VSL_stats, param, warning, critical, less); + + exit(0); +} From des at projects.linpro.no Mon Jul 2 08:23:32 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 2 Jul 2007 10:23:32 +0200 (CEST) Subject: r1605 - in trunk/varnish-cache: . include Message-ID: <20070702082332.25B651EC37C@projects.linpro.no> Author: des Date: 2007-07-02 10:23:31 +0200 (Mon, 02 Jul 2007) New Revision: 1605 Added: trunk/varnish-cache/varnishapi.pc.in Modified: trunk/varnish-cache/ trunk/varnish-cache/Makefile.am trunk/varnish-cache/configure.ac trunk/varnish-cache/include/Makefile.am Log: Install headers, and register with pkg-config. Property changes on: trunk/varnish-cache ___________________________________________________________________ Name: svn:ignore - .deps Makefile Makefile.in aclocal.m4 autom4te.cache compile config.guess config.h config.h.in config.log config.status config.sub configure configure.lineno depcomp install-sh libtool ltmain.sh missing stamp-h1 + .deps Makefile Makefile.in aclocal.m4 autom4te.cache compile config.guess config.h config.h.in config.log config.status config.sub configure configure.lineno depcomp install-sh libtool ltmain.sh missing stamp-h1 varnishapi.pc Modified: trunk/varnish-cache/Makefile.am =================================================================== --- trunk/varnish-cache/Makefile.am 2007-07-02 07:14:53 UTC (rev 1604) +++ trunk/varnish-cache/Makefile.am 2007-07-02 08:23:31 UTC (rev 1605) @@ -4,7 +4,10 @@ SUBDIRS += debian redhat -EXTRA_DIST = LICENSE autogen.sh +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = varnishapi.pc +EXTRA_DIST = LICENSE autogen.sh varnishapi.pc.in + install-data-local: $(install_sh) -d -m 0755 $(localstatedir)/varnish Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2007-07-02 07:14:53 UTC (rev 1604) +++ trunk/varnish-cache/configure.ac 2007-07-02 08:23:31 UTC (rev 1605) @@ -155,5 +155,6 @@ man/Makefile debian/Makefile redhat/Makefile + varnishapi.pc ]) AC_OUTPUT Modified: trunk/varnish-cache/include/Makefile.am =================================================================== --- trunk/varnish-cache/include/Makefile.am 2007-07-02 07:14:53 UTC (rev 1604) +++ trunk/varnish-cache/include/Makefile.am 2007-07-02 08:23:31 UTC (rev 1605) @@ -1,5 +1,12 @@ # $Id$ +pkginclude_HEADERS = \ + shmlog.h \ + shmlog_tags.h \ + stat_field.h \ + stats.h \ + varnishapi.h + noinst_HEADERS = \ binary_heap.h \ cli.h \ @@ -22,11 +29,6 @@ queue.h \ vpf.h \ vsb.h \ - shmlog.h \ - shmlog_tags.h \ - stat_field.h \ - stats.h \ - varnishapi.h \ vcl.h \ vcl_returns.h \ vrt.h \ Added: trunk/varnish-cache/varnishapi.pc.in =================================================================== --- trunk/varnish-cache/varnishapi.pc.in (rev 0) +++ trunk/varnish-cache/varnishapi.pc.in 2007-07-02 08:23:31 UTC (rev 1605) @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: VarnishAPI +Description: Varnish API +Version: @PACKAGE_VERSION@ +Cflags: -I${includedir}/varnish +Libs: -L${libdir} -lvarnishapi From des at projects.linpro.no Mon Jul 2 08:24:52 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 2 Jul 2007 10:24:52 +0200 (CEST) Subject: r1606 - trunk/varnish-tools/nagios Message-ID: <20070702082452.BCE051EC030@projects.linpro.no> Author: des Date: 2007-07-02 10:24:52 +0200 (Mon, 02 Jul 2007) New Revision: 1606 Added: trunk/varnish-tools/nagios/Makefile.am trunk/varnish-tools/nagios/autogen.des trunk/varnish-tools/nagios/autogen.sh trunk/varnish-tools/nagios/configure.ac Removed: trunk/varnish-tools/nagios/Makefile Modified: trunk/varnish-tools/nagios/ Log: Autoconfuse. Property changes on: trunk/varnish-tools/nagios ___________________________________________________________________ Name: svn:ignore + .deps .libs Makefile.in aclocal.m4 autom4te.cache check_varnish check_varnish.1 config.guess config.h config.h.in config.log config.status config.sub configure configure.lineno depcomp install-sh libtool ltmain.sh missing stamp-h1 Deleted: trunk/varnish-tools/nagios/Makefile =================================================================== --- trunk/varnish-tools/nagios/Makefile 2007-07-02 08:23:31 UTC (rev 1605) +++ trunk/varnish-tools/nagios/Makefile 2007-07-02 08:24:52 UTC (rev 1606) @@ -1,7 +0,0 @@ -CFLAGS = -I ../../varnish-cache/include -O2 -Wall -pedantic -std=c99 -D_GNU_SOURCE -LDFLAGS = -L /opt/varnish/lib -lvarnishapi - -all: check_varnish - -clean: - -rm check_varnish \ No newline at end of file Added: trunk/varnish-tools/nagios/Makefile.am =================================================================== --- trunk/varnish-tools/nagios/Makefile.am (rev 0) +++ trunk/varnish-tools/nagios/Makefile.am 2007-07-02 08:24:52 UTC (rev 1606) @@ -0,0 +1,9 @@ +# $Id$ + +sbin_PROGRAMS = check_varnish + +check_varnish_SOURCES = check_varnish.c + +check_varnish_CFLAGS = -include config.h ${VARNISHAPI_CFLAGS} + +check_varnish_LDADD = ${VARNISHAPI_LIBS} Property changes on: trunk/varnish-tools/nagios/Makefile.am ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/varnish-tools/nagios/autogen.des =================================================================== --- trunk/varnish-tools/nagios/autogen.des (rev 0) +++ trunk/varnish-tools/nagios/autogen.des 2007-07-02 08:24:52 UTC (rev 1606) @@ -0,0 +1 @@ +link ../../varnish-cache/autogen.des \ No newline at end of file Property changes on: trunk/varnish-tools/nagios/autogen.des ___________________________________________________________________ Name: svn:special + * Added: trunk/varnish-tools/nagios/autogen.sh =================================================================== --- trunk/varnish-tools/nagios/autogen.sh (rev 0) +++ trunk/varnish-tools/nagios/autogen.sh 2007-07-02 08:24:52 UTC (rev 1606) @@ -0,0 +1 @@ +link ../../varnish-cache/autogen.sh \ No newline at end of file Property changes on: trunk/varnish-tools/nagios/autogen.sh ___________________________________________________________________ Name: svn:special + * Added: trunk/varnish-tools/nagios/configure.ac =================================================================== --- trunk/varnish-tools/nagios/configure.ac (rev 0) +++ trunk/varnish-tools/nagios/configure.ac 2007-07-02 08:24:52 UTC (rev 1606) @@ -0,0 +1,66 @@ +# $Id$ + +AC_PREREQ(2.59) +AC_COPYRIGHT([Copyright (c) 2007 Linpro AS]) +AC_REVISION([$Id$]) +AC_INIT([check_varnish], [trunk], [varnish-dev at projects.linpro.no]) +AC_CONFIG_SRCDIR(check_varnish.c) +AM_CONFIG_HEADER(config.h) + +AC_CANONICAL_SYSTEM +AC_LANG(C) + +AM_INIT_AUTOMAKE + +# Checks for programs. +AC_GNU_SOURCE +AC_PROG_CC +AC_PROG_CPP +AC_PROG_INSTALL +AC_PROG_LIBTOOL +AC_PROG_MAKE_SET + +# Checks for libraries. +PKG_CHECK_MODULES([VARNISHAPI], [varnishapi]) + +# Checks for header files. +AC_HEADER_STDC +AC_HEADER_SYS_WAIT +AC_HEADER_TIME + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST + +# Checks for library functions. +AC_TYPE_SIZE_T + +# Now that we're done using the compiler to look for functions and +# libraries, set CFLAGS to what we want them to be for our own code + +# This corresponds to FreeBSD's WARNS level 6 +DEVELOPER_CFLAGS="-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wformat" + +# Additional flags for GCC 4 +EXTRA_DEVELOPER_CFLAGS="-Wextra -Wno-missing-field-initializers -Wno-sign-compare" + +AC_ARG_ENABLE(developer-warnings, + AS_HELP_STRING([--enable-developer-warnings],[enable strict warnings (default is NO)]), + CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}") +AC_ARG_ENABLE(debugging-symbols, + AS_HELP_STRING([--enable-debugging-symbols],[enable debugging symbols (default is NO)]), + CFLAGS="${CFLAGS} -O0 -g -fno-inline") +AC_ARG_ENABLE(extra-developer-warnings, + AS_HELP_STRING([--enable-extra-developer-warnings],[enable even stricter warnings (default is NO)]), + CFLAGS="${CFLAGS} ${EXTRA_DEVELOPER_CFLAGS}") +AC_ARG_ENABLE(stack-protector, + AS_HELP_STRING([--enable-stack-protector],[enable stack protector (default is NO)]), + CFLAGS="${CFLAGS} -fstack-protector-all") +AC_ARG_ENABLE(werror, + AS_HELP_STRING([--enable-werror],[use -Werror (default is NO)]), + CFLAGS="${CFLAGS} -Werror") + +# Generate output +AC_CONFIG_FILES([ + Makefile +]) +AC_OUTPUT Property changes on: trunk/varnish-tools/nagios/configure.ac ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Mon Jul 2 10:07:55 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 2 Jul 2007 12:07:55 +0200 (CEST) Subject: r1607 - trunk/varnish-tools/nagios Message-ID: <20070702100755.DCC161EC37C@projects.linpro.no> Author: des Date: 2007-07-02 12:07:55 +0200 (Mon, 02 Jul 2007) New Revision: 1607 Modified: trunk/varnish-tools/nagios/ trunk/varnish-tools/nagios/check_varnish.c Log: Tweak props Property changes on: trunk/varnish-tools/nagios ___________________________________________________________________ Name: svn:ignore - .deps .libs Makefile.in aclocal.m4 autom4te.cache check_varnish check_varnish.1 config.guess config.h config.h.in config.log config.status config.sub configure configure.lineno depcomp install-sh libtool ltmain.sh missing stamp-h1 + .deps .libs Makefile Makefile.in aclocal.m4 autom4te.cache check_varnish check_varnish.1 config.guess config.h config.h.in config.log config.status config.sub configure configure.lineno depcomp install-sh libtool ltmain.sh missing stamp-h1 Property changes on: trunk/varnish-tools/nagios/check_varnish.c ___________________________________________________________________ Name: svn:keywords + Id From cecilihf at projects.linpro.no Mon Jul 2 11:09:29 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Mon, 2 Jul 2007 13:09:29 +0200 (CEST) Subject: r1608 - trunk/varnish-tools/nagios Message-ID: <20070702110929.587EE1EC404@projects.linpro.no> Author: cecilihf Date: 2007-07-02 13:09:29 +0200 (Mon, 02 Jul 2007) New Revision: 1608 Modified: trunk/varnish-tools/nagios/check_varnish.c Log: Some improvements to the nagios plugin. Default parameter is now hitrate. Modified: trunk/varnish-tools/nagios/check_varnish.c =================================================================== --- trunk/varnish-tools/nagios/check_varnish.c 2007-07-02 10:07:55 UTC (rev 1607) +++ trunk/varnish-tools/nagios/check_varnish.c 2007-07-02 11:09:29 UTC (rev 1608) @@ -41,6 +41,9 @@ +/* Check if the tresholds against the value and return the + * appropriate status code. + */ static int check_treshold(int value, int warn, int crit, int less) { @@ -60,8 +63,11 @@ } +/* Print the appriate message according to the status level. + * Exit with the correct return code. + */ static void -message_and_exit(int level, int value, char *info) +message_and_exit(int level, int value, const char *info) { if (level == 0) printf("OK: "); @@ -76,13 +82,24 @@ exit(level); } +/* Check the statistics for the requested parameter. + */ static void check_stats(struct varnish_stats *VSL_stats, char *param, int w, int c, int less) { + int level; + double ratio = 0; + int total; + if (!strcmp(param, "hitrate")) { + total = VSL_stats->cache_hit + VSL_stats->cache_miss; + if (total > 0) + ratio = VSL_stats->cache_hit / total; + level = check_treshold((int)ratio*100, w, c, less); + message_and_exit(level, ratio, "Hitrate ratio"); + } #define MAC_STAT(n, t, f, d) \ do { \ intmax_t ju = VSL_stats->n; \ - int level; \ if (!strcmp(param, #n)) { \ level = check_treshold(ju, w, c, less); \ message_and_exit(level, ju, d); \ @@ -90,19 +107,27 @@ } while (0); #include "stat_field.h" #undef MAC_STAT + printf("Invalid parameter: %s\n", param); + exit(3); } +/*-------------------------------------------------------------------------------*/ + static void help(void) { - fprintf(stderr, "usage: check_varnish -p param_name -c N -w N [-l] [-n varnish_name] [-v]\n" + fprintf(stderr, "usage: check_varnish [-p param_name -c N -w N] [-l] [-n varnish_name] [-v]\n" "Valid options:\n" "-c N\t\t warn as critical at treshold N\n" "-l\t\t specify that values should be less than tresholds for warnings to be issued\n" "-n varnish_name\t specify varnish instance name\n" - "-p param_name\t specify the parameter to check. See valid parameters\n" + "-p param_name\t specify the parameter to check. See valid parameters. Default is hitrate\n" "-v\t\t print verbose output. Can be specified up to three times\n" "-w N\t\t warn as warning at treshold N\n" + "Valid parameters\n" + "All names listed in the left column when running varnishstat -1 are valid parameters.\n" + "In addition, the following parameters are valid:\n" + "hitrate\t The hitrate ratio. Will be between 0 and 100. Default tresholds are 95 and 90.\n" ); exit(0); } @@ -110,7 +135,7 @@ static void usage(void) { - fprintf(stderr, "usage: check_varnish -p param_name -c N -w N [-l] [-n varnish_name] [-v]\n"); + fprintf(stderr, "usage: check_varnish [-p param_name -c N -w N] [-l] [-n varnish_name] [-v]\n"); exit(3); } @@ -156,6 +181,22 @@ if ((VSL_stats = VSL_OpenStats(n_arg)) == NULL) exit(1); + /* Default: if no param specified, check hitratio. + * If no warning and critical values are specified either, + * set these to default + */ + if (param == NULL) { + param = strdup("hitrate"); + if (!warning && !critical) { + warning = 95; + critical = 90; + less = 1; + } + } + + if (!param || (!critical && !warning)) + usage(); + check_stats(VSL_stats, param, warning, critical, less); exit(0); From des at projects.linpro.no Mon Jul 2 11:52:48 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 2 Jul 2007 13:52:48 +0200 (CEST) Subject: r1609 - trunk/varnish-tools/nagios Message-ID: <20070702115248.97A9D1EC37C@projects.linpro.no> Author: des Date: 2007-07-02 13:52:48 +0200 (Mon, 02 Jul 2007) New Revision: 1609 Modified: trunk/varnish-tools/nagios/Makefile.am Log: Install into libexec, not sbin. Modified: trunk/varnish-tools/nagios/Makefile.am =================================================================== --- trunk/varnish-tools/nagios/Makefile.am 2007-07-02 11:09:29 UTC (rev 1608) +++ trunk/varnish-tools/nagios/Makefile.am 2007-07-02 11:52:48 UTC (rev 1609) @@ -1,6 +1,6 @@ # $Id$ -sbin_PROGRAMS = check_varnish +libexec_PROGRAMS = check_varnish check_varnish_SOURCES = check_varnish.c From cecilihf at projects.linpro.no Mon Jul 2 12:01:56 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Mon, 2 Jul 2007 14:01:56 +0200 (CEST) Subject: r1610 - trunk/varnish-tools/nagios Message-ID: <20070702120156.13F491EC464@projects.linpro.no> Author: cecilihf Date: 2007-07-02 14:01:55 +0200 (Mon, 02 Jul 2007) New Revision: 1610 Modified: trunk/varnish-tools/nagios/check_varnish.c Log: Fixed some number conversion issues Modified: trunk/varnish-tools/nagios/check_varnish.c =================================================================== --- trunk/varnish-tools/nagios/check_varnish.c 2007-07-02 11:52:48 UTC (rev 1609) +++ trunk/varnish-tools/nagios/check_varnish.c 2007-07-02 12:01:55 UTC (rev 1610) @@ -45,7 +45,7 @@ * appropriate status code. */ static int -check_treshold(int value, int warn, int crit, int less) +check_treshold(intmax_t value, int warn, int crit, int less) { if (!less) { if (value < warn) @@ -67,7 +67,7 @@ * Exit with the correct return code. */ static void -message_and_exit(int level, int value, const char *info) +message_and_exit(int level, intmax_t value, const char *info) { if (level == 0) printf("OK: "); @@ -78,7 +78,7 @@ else printf("Uknown: "); - printf("%d %s\n", value, info); + printf("%ju %s\n", value, info); exit(level); } @@ -89,12 +89,12 @@ { int level; double ratio = 0; - int total; + int64_t total; if (!strcmp(param, "hitrate")) { total = VSL_stats->cache_hit + VSL_stats->cache_miss; if (total > 0) - ratio = VSL_stats->cache_hit / total; - level = check_treshold((int)ratio*100, w, c, less); + ratio = 100.0 * (double)VSL_stats->cache_hit / (double)total; + level = check_treshold(ratio, w, c, less); message_and_exit(level, ratio, "Hitrate ratio"); } #define MAC_STAT(n, t, f, d) \ From phk at projects.linpro.no Mon Jul 2 12:33:23 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 2 Jul 2007 14:33:23 +0200 (CEST) Subject: r1611 - trunk/varnish-cache/bin/varnishd Message-ID: <20070702123323.025441EC404@projects.linpro.no> Author: phk Date: 2007-07-02 14:33:22 +0200 (Mon, 02 Jul 2007) New Revision: 1611 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c Log: Update the embedded dot-graph to include request/object visibility in the various VCL methods. Loose the state names, they're obvious in the source code. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-02 12:01:55 UTC (rev 1610) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-02 12:33:22 UTC (rev 1611) @@ -52,16 +52,8 @@ DOT shape=hexagon DOT label="Request received" DOT ] -DOT RECV [shape=plaintext] -DOT PIPE [shape=plaintext] -DOT LOOKUP [shape=plaintext] -DOT HIT [shape=plaintext] -DOT MISS [shape=plaintext] -DOT PASS [shape=plaintext] -DOT FETCH [shape=plaintext] -DOT DELIVER [shape=plaintext] DOT ERROR [shape=plaintext] -DOT start -> RECV [style=bold,color=green,weight=4] +DOT start -> recv [style=bold,color=green,weight=4] */ #include @@ -123,14 +115,20 @@ DOT subgraph xcluster_deliver { DOT deliver [ DOT shape=ellipse -DOT label="Build & send header" +DOT label="Filter obj.->resp." DOT ] -DOT DELIVER -> deliver [style=bold,color=green,weight=4] +DOT vcl_deliver [ +DOT shape=record +DOT label="vcl_deliver()|req.\nresp." +DOT ] DOT deliver2 [ DOT shape=ellipse -DOT label="Send object" +DOT label="Send hdr + object" DOT ] -DOT deliver -> deliver2 [style=bold,color=green,weight=4] +DOT deliver -> vcl_deliver [style=bold,color=green,weight=4] +DOT vcl_deliver -> deliver2 [style=bold,color=green,weight=4,label=deliver] +DOT vcl_deliver -> errdeliver [label="error"] +DOT errdeliver [label="ERROR",shape=plaintext] DOT } DOT deliver2 -> DONE [style=bold,color=green,weight=4] */ @@ -260,10 +258,9 @@ DOT shape=ellipse DOT label="fetch from backend\n(find obj.ttl)" DOT ] -DOT FETCH -> fetch [style=bold,color=blue,weight=2] DOT vcl_fetch [ -DOT shape=box -DOT label="vcl_fetch()" +DOT shape=record +DOT label="vcl_fetch()|req.\nobj." DOT ] DOT fetch -> vcl_fetch [style=bold,color=blue,weight=2] DOT fetch_pass [ @@ -272,8 +269,8 @@ DOT ] DOT vcl_fetch -> fetch_pass [label="pass"] DOT } -DOT fetch_pass -> DELIVER -DOT vcl_fetch -> DELIVER [label="insert",style=bold,color=blue,weight=2] +DOT fetch_pass -> deliver +DOT vcl_fetch -> deliver [label="insert",style=bold,color=blue,weight=2] DOT vcl_fetch -> errfetch [label="error"] DOT errfetch [label="ERROR",shape=plaintext] */ @@ -350,15 +347,14 @@ * DOT subgraph xcluster_hit { DOT hit [ -DOT shape=box -DOT label="vcl_hit()" +DOT shape=record +DOT label="vcl_hit()|req.\nobj." DOT ] -DOT HIT -> hit [style=bold,color=green,weight=4] DOT } DOT hit -> err_hit [label="error"] DOT err_hit [label="ERROR",shape=plaintext] -DOT hit -> PASS [label=pass] -DOT hit -> DELIVER [label="deliver",style=bold,color=green,weight=4] +DOT hit -> pass [label=pass] +DOT hit -> deliver [label="deliver",style=bold,color=green,weight=4] */ static int @@ -402,24 +398,23 @@ * DOT subgraph xcluster_lookup { DOT hash [ -DOT shape=box -DOT label="vcl_hash()" +DOT shape=record +DOT label="vcl_hash()|req." DOT ] DOT lookup [ -DOT shape=ellipse -DOT label="obj in cache ?" +DOT shape=diamond +DOT label="obj in cache ?\ncreate if not" DOT ] DOT lookup2 [ -DOT shape=ellipse +DOT shape=diamond DOT label="obj.pass ?" DOT ] -DOT LOOKUP -> hash [style=bold,color=green,weight=4] DOT hash -> lookup [label="hash",style=bold,color=green,weight=4] DOT lookup -> lookup2 [label="yes",style=bold,color=green,weight=4] DOT } -DOT lookup2 -> HIT [label="no", style=bold,color=green,weight=4] -DOT lookup2 -> PASS [label="yes"] -DOT lookup -> MISS [label="no",style=bold,color=blue,weight=2] +DOT lookup2 -> hit [label="no", style=bold,color=green,weight=4] +DOT lookup2 -> pass [label="yes"] +DOT lookup -> miss [label="no",style=bold,color=blue,weight=2] */ static int @@ -427,6 +422,8 @@ { struct object *o; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + if (sp->obj == NULL) { WS_Reserve(sp->http->ws, 0); sp->hash_b = sp->http->ws->f; @@ -482,19 +479,23 @@ * DOT subgraph xcluster_miss { DOT miss [ -DOT shape=box -DOT label="vcl_miss()" +DOT shape=ellipse +DOT label="filter req.->bereq." DOT ] -DOT MISS -> miss [style=bold,color=blue,weight=2] +DOT vcl_miss [ +DOT shape=record +DOT label="vcl_miss()|req.\nbereq." +DOT ] DOT miss_ins [ -DOT label="insert new object" +DOT label="obj.pass=true" DOT ] -DOT miss -> miss_ins [label="fetch",style=bold,color=blue,weight=2] +DOT miss -> vcl_miss [style=bold,color=blue,weight=2] DOT } -DOT miss -> err_miss [label="error"] +DOT vcl_miss -> err_miss [label="error"] DOT err_miss [label="ERROR",shape=plaintext] -DOT miss_ins -> FETCH [style=bold,color=blue,weight=2] -DOT miss -> PASS [label="pass"] +DOT vcl_miss -> fetch [label="fetch",style=bold,color=blue,weight=2] +DOT miss_ins -> pass +DOT vcl_miss -> miss_ins [label="pass"] DOT */ @@ -533,18 +534,22 @@ * DOT subgraph xcluster_pass { DOT pass [ -DOT shape=box -DOT label="vcl_pass()" +DOT shape=ellipse +DOT label="deref obj\nfilter req.->bereq." DOT ] +DOT vcl_pass [ +DOT shape=record +DOT label="vcl_pass()|req.\nbereq." +DOT ] DOT pass_do [ DOT shape=ellipse -DOT label="create new object\n" +DOT label="create anon object\n" DOT ] -DOT PASS -> pass -DOT pass -> pass_do [label="pass"] +DOT pass -> vcl_pass +DOT vcl_pass -> pass_do [label="pass"] DOT } -DOT pass_do -> FETCH -DOT pass -> err_pass [label="error"] +DOT pass_do -> fetch +DOT vcl_pass -> err_pass [label="error"] DOT err_pass [label="ERROR",shape=plaintext] */ @@ -573,18 +578,22 @@ * DOT subgraph xcluster_pipe { DOT pipe [ -DOT shape=box -DOT label="vcl_pipe()" +DOT shape=ellipse +DOT label="Filter req.->bereq." DOT ] +DOT vcl_pipe [ +DOT shape=record +DOT label="vcl_pipe()|req.\nbereq\." +DOT ] DOT pipe_do [ DOT shape=ellipse -DOT label="build&send hdr\npipe until close" +DOT label="send bereq.\npipe until close" DOT ] -DOT PIPE -> pipe -DOT pipe -> pipe_do [label="pipe"] +DOT vcl_pipe -> pipe_do [label="pipe"] +DOT pipe -> vcl_pipe DOT } DOT pipe_do -> DONE -DOT pipe -> err_pipe [label="error"] +DOT vcl_pipe -> err_pipe [label="error"] DOT err_pipe [label="ERROR",shape=plaintext] */ @@ -606,16 +615,15 @@ * DOT subgraph xcluster_recv { DOT recv [ -DOT shape=box -DOT label="vcl_recv()" +DOT shape=record +DOT label="vcl_recv()|req." DOT ] -DOT RECV -> recv [style=bold,color=green,weight=4] DOT } -DOT recv -> PIPE [label="pipe"] -DOT recv -> PASS [label="pass"] +DOT recv -> pipe [label="pipe"] +DOT recv -> pass [label="pass"] DOT recv -> err_recv [label="error"] DOT err_recv [label="ERROR",shape=plaintext] -DOT recv -> LOOKUP [label="lookup",style=bold,color=green,weight=4] +DOT recv -> hash [label="lookup",style=bold,color=green,weight=4] */ static int From phk at projects.linpro.no Mon Jul 2 13:08:07 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 2 Jul 2007 15:08:07 +0200 (CEST) Subject: r1612 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070702130807.CE9EA1EC37C@projects.linpro.no> Author: phk Date: 2007-07-02 15:08:07 +0200 (Mon, 02 Jul 2007) New Revision: 1612 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/include/vcl.h trunk/varnish-cache/include/vcl_returns.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl Log: Add vcl_deliver() method where touch-up's to the returned reply can be performed. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-07-02 12:33:22 UTC (rev 1611) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-07-02 13:08:07 UTC (rev 1612) @@ -127,6 +127,9 @@ " }\n" " insert;\n" "}\n" + "sub vcl_deliver {\n" + " deliver;\n" + "}\n" "sub vcl_discard {\n" " discard;\n" "}\n" Modified: trunk/varnish-cache/include/vcl.h =================================================================== --- trunk/varnish-cache/include/vcl.h 2007-07-02 12:33:22 UTC (rev 1611) +++ trunk/varnish-cache/include/vcl.h 2007-07-02 13:08:07 UTC (rev 1612) @@ -38,6 +38,7 @@ vcl_func_f *miss_func; vcl_func_f *hit_func; vcl_func_f *fetch_func; + vcl_func_f *deliver_func; vcl_func_f *timeout_func; vcl_func_f *discard_func; }; Modified: trunk/varnish-cache/include/vcl_returns.h =================================================================== --- trunk/varnish-cache/include/vcl_returns.h 2007-07-02 12:33:22 UTC (rev 1611) +++ trunk/varnish-cache/include/vcl_returns.h 2007-07-02 13:08:07 UTC (rev 1612) @@ -41,6 +41,7 @@ VCL_MET_MAC(miss,MISS,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_FETCH)) VCL_MET_MAC(hit,HIT,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_DELIVER)) VCL_MET_MAC(fetch,FETCH,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_INSERT)) +VCL_MET_MAC(deliver,DELIVER,(VCL_RET_ERROR|VCL_RET_DELIVER)) VCL_MET_MAC(timeout,TIMEOUT,(VCL_RET_FETCH|VCL_RET_DISCARD)) VCL_MET_MAC(discard,DISCARD,(VCL_RET_DISCARD|VCL_RET_KEEP)) #else @@ -51,7 +52,8 @@ #define VCL_MET_MISS (1 << 4) #define VCL_MET_HIT (1 << 5) #define VCL_MET_FETCH (1 << 6) -#define VCL_MET_TIMEOUT (1 << 7) -#define VCL_MET_DISCARD (1 << 8) +#define VCL_MET_DELIVER (1 << 7) +#define VCL_MET_TIMEOUT (1 << 8) +#define VCL_MET_DISCARD (1 << 9) #endif -#define N_METHODS 9 +#define N_METHODS 10 Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-02 12:33:22 UTC (rev 1611) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-02 13:08:07 UTC (rev 1612) @@ -350,6 +350,7 @@ vsb_cat(sb, " vcl_func_f *miss_func;\n"); vsb_cat(sb, " vcl_func_f *hit_func;\n"); vsb_cat(sb, " vcl_func_f *fetch_func;\n"); + vsb_cat(sb, " vcl_func_f *deliver_func;\n"); vsb_cat(sb, " vcl_func_f *timeout_func;\n"); vsb_cat(sb, " vcl_func_f *discard_func;\n"); vsb_cat(sb, "};\n"); @@ -453,29 +454,17 @@ vsb_cat(sb, " * Edit vcc_gen_obj.tcl instead\n"); vsb_cat(sb, " */\n"); vsb_cat(sb, "\n"); - vsb_cat(sb, "const char * VRT_r_backend_host(struct backend *);\n"); vsb_cat(sb, "void VRT_l_backend_host(struct backend *, const char *);\n"); - vsb_cat(sb, "const char * VRT_r_backend_port(struct backend *);\n"); vsb_cat(sb, "void VRT_l_backend_port(struct backend *, const char *);\n"); - vsb_cat(sb, "double VRT_r_backend_dnsttl(struct backend *);\n"); vsb_cat(sb, "void VRT_l_backend_dnsttl(struct backend *, double);\n"); vsb_cat(sb, "struct sockaddr * VRT_r_client_ip(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_client_ip(struct sess *, struct sockaddr *);\n"); vsb_cat(sb, "struct sockaddr * VRT_r_server_ip(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_server_ip(struct sess *, struct sockaddr *);\n"); vsb_cat(sb, "const char * VRT_r_req_request(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_req_request(struct sess *, const char *);\n"); - vsb_cat(sb, "const char * VRT_r_req_host(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_req_host(struct sess *, const char *);\n"); vsb_cat(sb, "const char * VRT_r_req_url(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_req_url(struct sess *, const char *);\n"); vsb_cat(sb, "const char * VRT_r_req_proto(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_req_proto(struct sess *, const char *);\n"); vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n"); vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n"); vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_req_http_(struct sess *, const char *);\n"); - vsb_cat(sb, "const char * VRT_r_req_hash(struct sess *);\n"); vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n"); vsb_cat(sb, "unsigned VRT_r_obj_valid(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_valid(struct sess *, unsigned);\n"); @@ -484,11 +473,7 @@ vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n"); vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *);\n"); vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n"); vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *);\n"); vsb_cat(sb, "const char * VRT_r_resp_http_(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_http_(struct sess *, const char *);\n"); } Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-07-02 12:33:22 UTC (rev 1611) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-07-02 13:08:07 UTC (rev 1612) @@ -41,6 +41,7 @@ {miss {error pass fetch}} {hit {error pass deliver}} {fetch {error pass insert}} + {deliver {error deliver}} {timeout {fetch discard}} {discard {discard keep}} } From des at projects.linpro.no Mon Jul 2 13:16:05 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 2 Jul 2007 15:16:05 +0200 (CEST) Subject: r1613 - trunk/varnish-cache/man Message-ID: <20070702131605.03E461EC464@projects.linpro.no> Author: des Date: 2007-07-02 15:16:04 +0200 (Mon, 02 Jul 2007) New Revision: 1613 Modified: trunk/varnish-cache/man/vcl.7 Log: Update to reflect the latest changes to cache_center.c. Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-07-02 13:08:07 UTC (rev 1612) +++ trunk/varnish-cache/man/vcl.7 2007-07-02 13:16:04 UTC (rev 1613) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd June 25, 2007 +.Dd July 2, 2007 .Dt VCL 7 .Os .Sh NAME @@ -240,6 +240,8 @@ .Cm vcl_pass . .It Cm deliver Deliver the cached object to the client. +Control will eventually pass to +.Cm vcl_deliver . .El .\" vcl_miss .It Cm vcl_miss @@ -282,7 +284,23 @@ .Cm vcl_pass . .It Cm insert Insert the object into the cache, then deliver it to the client. +Control will eventually pass to +.Cm vcl_deliver . .El +.\" vcl_deliver +.It Cm vcl_deliver +Called before a cached object is delivered to the client. +.Pp +The +.Cm vcl_deliver +subroutine may terminate with one of the following keywords: +.Bl -tag -width "discard" +.It Cm error Ar code Op Ar reason +Return the specified error code to the client and abandon the +request. +.It Cm deliver +Deliver the object to the client. +.El .\" vcl_timeout .It Cm vcl_timeout Called by the reaper thread shortly before a cached document reaches @@ -423,6 +441,10 @@ insert; } +sub vcl_deliver { + deliver; +} + sub vcl_discard { discard; } From des at projects.linpro.no Mon Jul 2 13:16:28 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 2 Jul 2007 15:16:28 +0200 (CEST) Subject: r1614 - trunk/varnish-cache/man Message-ID: <20070702131628.863DB1EC404@projects.linpro.no> Author: des Date: 2007-07-02 15:16:28 +0200 (Mon, 02 Jul 2007) New Revision: 1614 Modified: trunk/varnish-cache/man/vcl.7 Log: Adjust props Property changes on: trunk/varnish-cache/man/vcl.7 ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Mon Jul 2 13:18:03 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 2 Jul 2007 15:18:03 +0200 (CEST) Subject: r1615 - in trunk/varnish-cache: bin/varnishadm bin/varnishd doc lib/libvcl man Message-ID: <20070702131803.B92D21EC464@projects.linpro.no> Author: des Date: 2007-07-02 15:18:03 +0200 (Mon, 02 Jul 2007) New Revision: 1615 Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.1 trunk/varnish-cache/bin/varnishadm/varnishadm.c trunk/varnish-cache/bin/varnishd/cache_synthetic.c trunk/varnish-cache/bin/varnishd/cache_vary.c trunk/varnish-cache/bin/varnishd/cache_ws.c trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/doc/changes-html.xsl trunk/varnish-cache/lib/libvcl/syntax.txt trunk/varnish-cache/lib/libvcl/vcc_var.c trunk/varnish-cache/man/Makefile.am Log: Adjust props. Property changes on: trunk/varnish-cache/bin/varnishadm/varnishadm.1 ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishadm/varnishadm.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishd/cache_synthetic.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishd/cache_vary.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishd/cache_ws.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishd/stevedore.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/doc/changes-html.xsl ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/lib/libvcl/syntax.txt ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/lib/libvcl/vcc_var.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/man/Makefile.am ___________________________________________________________________ Name: svn:keywords + Id From phk at projects.linpro.no Mon Jul 2 13:22:37 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 2 Jul 2007 15:22:37 +0200 (CEST) Subject: r1616 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20070702132237.173361EC404@projects.linpro.no> Author: phk Date: 2007-07-02 15:22:36 +0200 (Mon, 02 Jul 2007) New Revision: 1616 Modified: trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: Update the list of variables in accordance with the new scheme. Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2007-07-02 13:18:03 UTC (rev 1615) +++ trunk/varnish-cache/include/vrt_obj.h 2007-07-02 13:22:36 UTC (rev 1616) @@ -14,10 +14,21 @@ const char * VRT_r_req_request(struct sess *); const char * VRT_r_req_url(struct sess *); const char * VRT_r_req_proto(struct sess *); +void VRT_l_req_hash(struct sess *, const char *); struct backend * VRT_r_req_backend(struct sess *); void VRT_l_req_backend(struct sess *, struct backend *); -const char * VRT_r_req_http_(struct sess *); -void VRT_l_req_hash(struct sess *, const char *); +const char * VRT_r_bereq_request(struct sess *); +void VRT_l_bereq_request(struct sess *, const char *); +const char * VRT_r_bereq_url(struct sess *); +void VRT_l_bereq_url(struct sess *, const char *); +const char * VRT_r_bereq_proto(struct sess *); +void VRT_l_bereq_proto(struct sess *, const char *); +const char * VRT_r_obj_proto(struct sess *); +void VRT_l_obj_proto(struct sess *, const char *); +int VRT_r_obj_status(struct sess *); +void VRT_l_obj_status(struct sess *, int); +const char * VRT_r_obj_response(struct sess *); +void VRT_l_obj_response(struct sess *, const char *); unsigned VRT_r_obj_valid(struct sess *); void VRT_l_obj_valid(struct sess *, unsigned); unsigned VRT_r_obj_cacheable(struct sess *); @@ -25,6 +36,8 @@ double VRT_r_obj_ttl(struct sess *); void VRT_l_obj_ttl(struct sess *, double); const char * VRT_r_resp_proto(struct sess *); +void VRT_l_resp_proto(struct sess *, const char *); int VRT_r_resp_status(struct sess *); +void VRT_l_resp_status(struct sess *, int); const char * VRT_r_resp_response(struct sess *); -const char * VRT_r_resp_http_(struct sess *); +void VRT_l_resp_response(struct sess *, const char *); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-02 13:18:03 UTC (rev 1615) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-02 13:22:36 UTC (rev 1616) @@ -462,10 +462,21 @@ vsb_cat(sb, "const char * VRT_r_req_request(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_req_url(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_req_proto(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n"); vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n"); vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n"); - vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n"); + vsb_cat(sb, "const char * VRT_r_bereq_request(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_bereq_request(struct sess *, const char *);\n"); + vsb_cat(sb, "const char * VRT_r_bereq_url(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_bereq_url(struct sess *, const char *);\n"); + vsb_cat(sb, "const char * VRT_r_bereq_proto(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_bereq_proto(struct sess *, const char *);\n"); + vsb_cat(sb, "const char * VRT_r_obj_proto(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_proto(struct sess *, const char *);\n"); + vsb_cat(sb, "int VRT_r_obj_status(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_status(struct sess *, int);\n"); + vsb_cat(sb, "const char * VRT_r_obj_response(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_response(struct sess *, const char *);\n"); vsb_cat(sb, "unsigned VRT_r_obj_valid(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_valid(struct sess *, unsigned);\n"); vsb_cat(sb, "unsigned VRT_r_obj_cacheable(struct sess *);\n"); @@ -473,7 +484,9 @@ vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n"); vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *);\n"); vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n"); vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n"); - vsb_cat(sb, "const char * VRT_r_resp_http_(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *);\n"); } Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-02 13:18:03 UTC (rev 1615) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-02 13:22:36 UTC (rev 1616) @@ -30,75 +30,123 @@ # Generate various .c and .h files for the VCL compiler and the interfaces # for it. -# Objects which operate on backends +# Objects available in backends set beobj { { backend.host WO HOSTNAME } { backend.port WO PORTNAME } { backend.dnsttl WO TIME } } -# Objects which operate on sessions +# Variables available in sessions +# Comments are stripped from #...\n +set spobj { -set spobj { + # Connection related parameters { client.ip RO IP - {recv pipe pass hash miss hit fetch } + {recv pipe pass hash miss hit fetch } } + { client.bandwidth # Not implemented yet + NO + } { server.ip RO IP - {recv pipe pass hash miss hit fetch } + {recv pipe pass hash miss hit fetch } } + + # Request paramters { req.request RO STRING - {recv pipe pass hash miss hit fetch } + {recv pipe pass hash miss hit fetch } } { req.url RO STRING - {recv pipe pass hash miss hit fetch } + {recv pipe pass hash miss hit fetch } } { req.proto RO STRING - {recv pipe pass hash miss hit fetch } + {recv pipe pass hash miss hit fetch } } - { req.backend - RW BACKEND - {recv pipe pass hash miss hit fetch } - } { req.http. - RO HEADER - {recv pipe pass hash miss hit fetch } + RW HEADER + {recv pipe pass hash miss hit fetch } } + + # Possibly misnamed, not really part of the request { req.hash WO HASH - { hash } + { hash } } + { req.backend + RW BACKEND + {recv pipe pass hash miss hit fetch } + } + + # Request sent to backend + { bereq.request + RW STRING + { pipe pass miss } + } + { bereq.url + RW STRING + { pipe pass miss } + } + { bereq.proto + RW STRING + { pipe pass miss } + } + { bereq.http. + RW HEADER + { pipe pass miss } + } + + # The (possibly) cached object + { obj.proto + RW STRING + { hit fetch deliver } + } + { obj.status + RW INT + { fetch } + } + { obj.response + RW STRING + { fetch } + } + { obj.http. + RW HEADER + { hit fetch deliver } + } + { obj.valid RW BOOL - { hit fetch discard timeout} + { hit fetch discard timeout} } { obj.cacheable RW BOOL - { hit fetch discard timeout} + { hit fetch discard timeout} } { obj.ttl RW TIME - { hit fetch discard timeout} + { hit fetch discard timeout} } + + # The response we send back { resp.proto - RO STRING - { fetch } + RW STRING + { fetch } } { resp.status - RO INT - { fetch } + RW INT + { fetch } } { resp.response - RO STRING - { fetch } + RW STRING + { fetch } } { resp.http. - RO HEADER - { fetch } + RW HEADER + { fetch } } } @@ -146,21 +194,27 @@ proc vars {v ty pa} { global tt fo fp + regsub -all "#\[^\n\]*\n" $v "" v foreach v $v { set n [lindex $v 0] regsub -all {[.]} $n "_" m set a [lindex $v 1] + if {$a == "NO"} continue set t [lindex $v 2] puts $fo "\t\{ \"$n\", $t, [string length $n]," if {$a == "RO" || $a == "RW"} { puts $fo "\t \"VRT_r_${m}($pa)\"," - puts $fp "$tt($t) VRT_r_${m}($ty);" + if {$t != "HEADER"} { + puts $fp "$tt($t) VRT_r_${m}($ty);" + } } else { puts $fo "\t NULL," } if {$a == "WO" || $a == "RW"} { puts $fo "\t \"VRT_l_${m}($pa, \"," - puts $fp "void VRT_l_${m}($ty, $tt($t));" + if {$t != "HEADER"} { + puts $fp "void VRT_l_${m}($ty, $tt($t));" + } } else { puts $fo "\t NULL," } Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-02 13:18:03 UTC (rev 1615) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-02 13:22:36 UTC (rev 1616) @@ -62,16 +62,10 @@ V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, - { "req.backend", BACKEND, 11, - "VRT_r_req_backend(sp)", - "VRT_l_req_backend(sp, ", - V_RW, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH - }, { "req.http.", HEADER, 9, "VRT_r_req_http_(sp)", - NULL, - V_RO, + "VRT_l_req_http_(sp, ", + V_RW, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.hash", HASH, 8, @@ -80,6 +74,60 @@ V_WO, VCL_MET_HASH }, + { "req.backend", BACKEND, 11, + "VRT_r_req_backend(sp)", + "VRT_l_req_backend(sp, ", + V_RW, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH + }, + { "bereq.request", STRING, 13, + "VRT_r_bereq_request(sp)", + "VRT_l_bereq_request(sp, ", + V_RW, + VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS + }, + { "bereq.url", STRING, 9, + "VRT_r_bereq_url(sp)", + "VRT_l_bereq_url(sp, ", + V_RW, + VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS + }, + { "bereq.proto", STRING, 11, + "VRT_r_bereq_proto(sp)", + "VRT_l_bereq_proto(sp, ", + V_RW, + VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS + }, + { "bereq.http.", HEADER, 11, + "VRT_r_bereq_http_(sp)", + "VRT_l_bereq_http_(sp, ", + V_RW, + VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS + }, + { "obj.proto", STRING, 9, + "VRT_r_obj_proto(sp)", + "VRT_l_obj_proto(sp, ", + V_RW, + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + }, + { "obj.status", INT, 10, + "VRT_r_obj_status(sp)", + "VRT_l_obj_status(sp, ", + V_RW, + VCL_MET_FETCH + }, + { "obj.response", STRING, 12, + "VRT_r_obj_response(sp)", + "VRT_l_obj_response(sp, ", + V_RW, + VCL_MET_FETCH + }, + { "obj.http.", HEADER, 9, + "VRT_r_obj_http_(sp)", + "VRT_l_obj_http_(sp, ", + V_RW, + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + }, { "obj.valid", BOOL, 9, "VRT_r_obj_valid(sp)", "VRT_l_obj_valid(sp, ", @@ -100,26 +148,26 @@ }, { "resp.proto", STRING, 10, "VRT_r_resp_proto(sp)", - NULL, - V_RO, + "VRT_l_resp_proto(sp, ", + V_RW, VCL_MET_FETCH }, { "resp.status", INT, 11, "VRT_r_resp_status(sp)", - NULL, - V_RO, + "VRT_l_resp_status(sp, ", + V_RW, VCL_MET_FETCH }, { "resp.response", STRING, 13, "VRT_r_resp_response(sp)", - NULL, - V_RO, + "VRT_l_resp_response(sp, ", + V_RW, VCL_MET_FETCH }, { "resp.http.", HEADER, 10, "VRT_r_resp_http_(sp)", - NULL, - V_RO, + "VRT_l_resp_http_(sp, ", + V_RW, VCL_MET_FETCH }, { NULL } From phk at projects.linpro.no Mon Jul 2 13:28:03 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 2 Jul 2007 15:28:03 +0200 (CEST) Subject: r1617 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20070702132803.78AFF1EC464@projects.linpro.no> Author: phk Date: 2007-07-02 15:28:03 +0200 (Mon, 02 Jul 2007) New Revision: 1617 Modified: trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_var.c Log: Generate correct code for bereq.http and obj.http Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-07-02 13:22:36 UTC (rev 1616) +++ trunk/varnish-cache/include/vrt.h 2007-07-02 13:28:03 UTC (rev 1617) @@ -74,7 +74,7 @@ void VRT_error(struct sess *, unsigned, const char *); int VRT_switch_config(const char *); -enum gethdr_e { HDR_REQ, HDR_RESP }; +enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ }; char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *); void VRT_handling(struct sess *sp, unsigned hand); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-02 13:22:36 UTC (rev 1616) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-02 13:28:03 UTC (rev 1617) @@ -430,7 +430,7 @@ vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n"); vsb_cat(sb, "int VRT_switch_config(const char *);\n"); vsb_cat(sb, "\n"); - vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP };\n"); + vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ };\n"); vsb_cat(sb, "char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);\n"); vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n"); vsb_cat(sb, "\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-02 13:22:36 UTC (rev 1616) +++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-02 13:28:03 UTC (rev 1617) @@ -49,8 +49,11 @@ EncToken(tl->fb, tl->t); vcc_NextToken(tl); return; - } - ExpectErr(tl, VAR); + } else if (tl->t->tok != VAR) { + vsb_printf(tl->sb, "Expected string variable or constant\n"); + vcc_ErrWhere(tl, tl->t); + return; + } ERRCHK(tl); vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); @@ -88,18 +91,27 @@ memcpy(p, t->b, i); p[i] = '\0'; v->name = p; + v->access = V_RW; v->fmt = STRING; v->methods = vh->methods; if (!memcmp(vh->name, "req.", 4)) wh = "HDR_REQ"; else if (!memcmp(vh->name, "resp.", 5)) wh = "HDR_RESP"; + else if (!memcmp(vh->name, "obj.", 4)) + wh = "HDR_OBJ"; + else if (!memcmp(vh->name, "bereq.", 6)) + wh = "HDR_BEREQ"; else assert(0 == 1); asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", wh, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); - assert(p != NULL); + AN(p); v->rname = p; + asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\")", wh, + (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); + AN(p); + v->lname = p; return (v); } From phk at projects.linpro.no Mon Jul 2 13:30:06 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 2 Jul 2007 15:30:06 +0200 (CEST) Subject: r1618 - trunk/varnish-cache/lib/libvcl Message-ID: <20070702133006.7870C1EC404@projects.linpro.no> Author: phk Date: 2007-07-02 15:30:06 +0200 (Mon, 02 Jul 2007) New Revision: 1618 Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c Log: Improve assignments a bit Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-02 13:28:03 UTC (rev 1617) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-02 13:30:06 UTC (rev 1618) @@ -94,6 +94,16 @@ /*--------------------------------------------------------------------*/ static void +illegal_assignment(struct tokenlist *tl, const char *type) +{ + + vsb_printf(tl->sb, "Invalid assignment operator "); + vcc_ErrToken(tl, tl->t); + vsb_printf(tl->sb, + " only '=' is legal for %s\n", type); +} + +static void parse_set(struct tokenlist *tl) { struct var *vp; @@ -154,38 +164,31 @@ break; #if 0 /* XXX: enable if we find a legit use */ case IP: - if (tl->t->tok == '=') { - vcc_NextToken(tl); - u = vcc_vcc_IpVal(tl); - Fb(tl, 0, "= %uU; /* %u.%u.%u.%u */\n", - u, - (u >> 24) & 0xff, - (u >> 16) & 0xff, - (u >> 8) & 0xff, - u & 0xff); - break; + if (tl->t->tok != '=') { + illegal_assignment(tl, "IP numbers"); + return; } - vsb_printf(tl->sb, "Invalid assignment operator "); - vcc_ErrToken(tl, tl->t); - vsb_printf(tl->sb, - " only '=' is legal for IP numbers\n"); - vcc_ErrWhere(tl, tl->t); - return; + vcc_NextToken(tl); + u = vcc_vcc_IpVal(tl); + Fb(tl, 0, "= %uU; /* %u.%u.%u.%u */\n", + u, + (u >> 24) & 0xff, + (u >> 16) & 0xff, + (u >> 8) & 0xff, + u & 0xff); + break; #endif case BACKEND: - if (tl->t->tok == '=') { - vcc_NextToken(tl); - vcc_AddRef(tl, tl->t, R_BACKEND); - Fb(tl, 0, "VGC_backend_%.*s", PF(tl->t)); - vcc_NextToken(tl); - Fb(tl, 0, ");\n"); - break; + if (tl->t->tok != '=') { + illegal_assignment(tl, "backend"); + return; } - vsb_printf(tl->sb, "Invalid assignment operator "); - vcc_ErrToken(tl, tl->t); - vsb_printf(tl->sb, - " only '=' is legal for backend\n"); - vcc_ErrWhere(tl, tl->t); + vcc_NextToken(tl); + vcc_AddRef(tl, tl->t, R_BACKEND); + Fb(tl, 0, "VGC_backend_%.*s", PF(tl->t)); + vcc_NextToken(tl); + Fb(tl, 0, ");\n"); + break; return; case HASH: ExpectErr(tl, T_INCR); @@ -193,6 +196,15 @@ vcc_StringVal(tl); Fb(tl, 0, ");\n"); return; + case STRING: + if (tl->t->tok != '=') { + illegal_assignment(tl, "strings"); + return; + } + vcc_NextToken(tl); + vcc_StringVal(tl); + Fb(tl, 0, ");\n"); + break; default: vsb_printf(tl->sb, "Assignments not possible for '%s'\n", vp->name); From phk at projects.linpro.no Mon Jul 2 17:30:03 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 2 Jul 2007 19:30:03 +0200 (CEST) Subject: r1619 - trunk/varnish-cache/bin/varnishd Message-ID: <20070702173003.4EDDC1EC464@projects.linpro.no> Author: phk Date: 2007-07-02 19:30:03 +0200 (Mon, 02 Jul 2007) New Revision: 1619 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c Log: Also reset the workspaces when we do not reuse the backend connection, we still reuse the structure. Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-02 13:30:06 UTC (rev 1618) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-02 17:30:03 UTC (rev 1619) @@ -337,6 +337,8 @@ AZ(close(vc->fd)); vc->fd = -1; vc->backend = NULL; + WS_Reset(vc->http->ws); + WS_Reset(vc->http2->ws); LOCK(&vbemtx); TAILQ_INSERT_HEAD(&vbe_head, vc, list); VSL_stats->backend_unused++; From cecilihf at projects.linpro.no Tue Jul 3 08:07:09 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Tue, 3 Jul 2007 10:07:09 +0200 (CEST) Subject: r1620 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070703080709.B55721EC475@projects.linpro.no> Author: cecilihf Date: 2007-07-03 10:07:09 +0200 (Tue, 03 Jul 2007) New Revision: 1620 Modified: trunk/varnish-cache/bin/varnishreplay/Makefile.am trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Log: parellising varnishreplay. Work in progress. Modified: trunk/varnish-cache/bin/varnishreplay/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishreplay/Makefile.am 2007-07-02 17:30:03 UTC (rev 1619) +++ trunk/varnish-cache/bin/varnishreplay/Makefile.am 2007-07-03 08:07:09 UTC (rev 1620) @@ -14,4 +14,6 @@ varnishreplay_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ - $(top_builddir)/lib/libvarnishapi/libvarnishapi.la + $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ + ${PTHREAD_LIBS} + Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-07-02 17:30:03 UTC (rev 1619) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-07-03 08:07:09 UTC (rev 1620) @@ -30,32 +30,63 @@ #include #include +#include +#include #include #include #include #include -#include #include "libvarnish.h" +#include "queue.h" #include "varnishapi.h" #include "vss.h" -static struct request { - char *df_H; /* %H, Protocol version */ - char *df_Host; /* %{Host}i */ - char *df_Uq; /* %U%q, URL path and query string */ - char *df_m; /* %m, Request method*/ - char *df_c; /* Connection info (keep-alive, close) */ - int bogus; /* bogus request */ -} **req; +static struct thread { + pthread_t thread_id; + struct mailbox *mbox; +} **threads; + +struct mailbox { + pthread_mutex_t lock; + pthread_cond_t has_mail; + STAILQ_HEAD(msgq_head, message) messages; +}; -static size_t nreq; +struct message { + enum shmlogtag tag; + char *ptr; + unsigned len; + STAILQ_ENTRY(message) list; +}; +static size_t nthreads; + static struct vss_addr *adr_info; -static int sock; -static int reopen; static int debug; +static void +mailbox_put(struct mailbox *mbox, struct message *msg) +{ + pthread_mutex_lock(&mbox->lock); + STAILQ_INSERT_TAIL(&mbox->messages, msg, list); + pthread_cond_signal(&mbox->has_mail); + pthread_mutex_unlock(&mbox->lock); +} + +static struct message * +mailbox_get(struct mailbox *mbox) +{ + struct message *msg; + + pthread_mutex_lock(&mbox->lock); + while ((msg = STAILQ_FIRST(&mbox->messages)) == NULL) + pthread_cond_wait(&mbox->has_mail, &mbox->lock); + STAILQ_REMOVE_HEAD(&mbox->messages, list); + pthread_mutex_unlock(&mbox->lock); + return msg; +} + static int isprefix(const char *str, const char *prefix, const char *end, const char **next) { @@ -153,7 +184,7 @@ * A line is terminated by \r\n */ static int -read_line(char **line) +read_line(char **line, int sock) { char *buf; unsigned nbuf, lbuf; @@ -191,7 +222,7 @@ * the number of bytes read. */ static int -read_block(int length) +read_block(int length, int sock) { char *buf; int n, nbuf; @@ -214,7 +245,7 @@ /* Receive the response after sending a request. */ static int -receive_response(void) +receive_response(int sock) { char *line, *end; const char *next; @@ -229,7 +260,7 @@ /* Read header */ while (1) { - line_len = read_line(&line); + line_len = read_line(&line, sock); end = line + line_len; if (*line == '\r' && *(line + 1) == '\n') { @@ -260,7 +291,7 @@ /* Fixed body size, read content_length bytes */ if (debug) fprintf(stderr, "fixed length\n"); - n = read_block(content_length); + n = read_block(content_length, sock); if (debug) { fprintf(stderr, "size of body: %d\n", (int)content_length); fprintf(stderr, "bytes read: %d\n", n); @@ -270,22 +301,22 @@ if (debug) fprintf(stderr, "chunked encoding\n"); while (1) { - line_len = read_line(&line); + line_len = read_line(&line, sock); end = line + line_len; block_len = strtol(line, &end, 16); if (block_len == 0) { break; } - n = read_block(block_len); + n = read_block(block_len, sock); if (debug) { fprintf(stderr, "size of body: %d\n", (int)block_len); fprintf(stderr, "bytes read: %d\n", n); } free(line); - n = read_line(&line); + n = read_line(&line, sock); free(line); } - n = read_line(&line); + n = read_line(&line, sock); free(line); } else if ((content_length <= 0 && !chunked) || req_failed) { /* No body --> stop reading. */ @@ -302,155 +333,198 @@ return close_connection; } - -static int -gen_traffic(void *priv, enum shmlogtag tag, unsigned fd, - unsigned len, unsigned spec, const char *ptr) +static void * +pthread_main(void *arg) { + struct message *msg; + struct thread *th = (struct thread*)arg; + enum shmlogtag tag; + int len; + char *ptr; const char *end, *next; - FILE *fo; - struct request *rp; + + char *df_H = NULL; /* %H, Protocol version */ + char *df_Host = NULL; /* %{Host}i */ + char *df_Uq = NULL; /* %U%q, URL path and query string */ + char *df_m = NULL; /* %m, Request method*/ + char *df_c = NULL; /* Connection info (keep-alive, close) */ + int bogus = 0; /* bogus request */ - end = ptr + len; + int sock, reopen = 1; + + //fprintf(stderr, "thread started\n"); + + do { + msg = mailbox_get(th->mbox); + tag = msg->tag; + len = msg->len; + ptr = msg->ptr; + end = ptr + len; + + //fprintf(stderr, "%08x %s(%s)\n", (unsigned int)pthread_self(), VSL_tags[tag], msg->ptr); + + switch (tag) { + case SLT_RxRequest: + if (df_m != NULL) + bogus = 1; + else + df_m = trimline(ptr, end); + break; - if (!(spec & VSL_S_CLIENT)) - return (0); + case SLT_RxURL: + if (df_Uq != NULL) + bogus = 1; + else + df_Uq = trimline(ptr, end); + break; - if (fd >= nreq) { - struct request **newreq = req; - size_t newnreq = nreq; - - while (fd >= newnreq) - newnreq += newnreq + 1; - newreq = realloc(newreq, newnreq * sizeof *newreq); - assert(newreq != NULL); - memset(newreq + nreq, 0, (newnreq - nreq) * sizeof *newreq); - req = newreq; - nreq = newnreq; - } - if (req[fd] == NULL) { - req[fd] = calloc(sizeof *req[fd], 1); - assert(req[fd] != NULL); - } - rp = req[fd]; - - switch (tag) { - case SLT_RxRequest: - if (tag == SLT_RxRequest && (spec & VSL_S_BACKEND)) + case SLT_RxProtocol: + if (df_H != NULL) + bogus = 1; + else + df_H = trimline(ptr, end); break; - if (rp->df_m != NULL) - rp->bogus = 1; - else - rp->df_m = trimline(ptr, end); - break; - - case SLT_RxURL: - if (tag == SLT_RxURL && (spec & VSL_S_BACKEND)) + case SLT_RxHeader: + if (isprefix(ptr, "host:", end, &next)) + df_Host = trimline(next, end); + if (isprefix(ptr, "connection:", end, &next)) + df_c = trimline(next, end); break; - if (rp->df_Uq != NULL) - rp->bogus = 1; - else - rp->df_Uq = trimline(ptr, end); - break; - - case SLT_RxProtocol: - if (tag == SLT_RxProtocol && (spec & VSL_S_BACKEND)) + default: break; + } - if (rp->df_H != NULL) - rp->bogus = 1; - else - rp->df_H = trimline(ptr, end); - break; + if (tag != SLT_ReqEnd) + continue; + + //fprintf(stderr, "bogus: %d %s\n", bogus, df_m); - case SLT_RxHeader: - if (isprefix(ptr, "host:", end, &next)) - rp->df_Host = trimline(next, end); - if (isprefix(ptr, "connection:", end, &next)) - rp->df_c = trimline(next, end); - break; + if (!bogus) { + /* If the method is supported (GET or HEAD), send the request out + * on the socket. If the socket needs reopening, reopen it first. + * When the request is sent, call the function for receiving + * the answer. + */ + if (!(strncmp(df_m, "GET", 3) && strncmp(df_m, "HEAD", 4))) { + if (reopen) + sock = VSS_connect(adr_info); + reopen = 0; - default: - break; - } + if (debug) { + fprintf(stderr, "%s ", df_m); + fprintf(stderr, "%s ", df_Uq); + fprintf(stderr, "%s ", df_H); + fprintf(stderr, "\n"); + fprintf(stderr, "Host: "); + } + write(sock, df_m, strlen(df_m)); + write(sock, " ", 1); + write(sock, df_Uq, strlen(df_Uq)); + write(sock, " ", 1); + write(sock, df_H, strlen(df_H)); + write(sock, " ", 1); + write(sock, "\r\n", 2); - if ((spec & VSL_S_CLIENT) && tag != SLT_ReqEnd) - return (0); + if (strncmp(df_H, "HTTP/1.0", 8)) + reopen = 1; - if (!rp->bogus) { - fo = priv; - - /* If the method is supported (GET or HEAD), send the request out - * on the socket. If the socket needs reopening, reopen it first. - * When the request is sent, call the function for receiving - * the answer. - */ - if (!(strncmp(rp->df_m, "GET", 3) && strncmp(rp->df_m, "HEAD", 4))) { - if (reopen) - sock = VSS_connect(adr_info); - reopen = 0; - - if (debug) { - fprintf(fo, "%s ", rp->df_m); - fprintf(fo, "%s ", rp->df_Uq); - fprintf(fo, "%s ", rp->df_H); - fprintf(fo, "\n"); - fprintf(fo, "Host: "); - } - write(sock, rp->df_m, strlen(rp->df_m)); - write(sock, " ", 1); - write(sock, rp->df_Uq, strlen(rp->df_Uq)); - write(sock, " ", 1); - write(sock, rp->df_H, strlen(rp->df_H)); - write(sock, " ", 1); - write(sock, "\r\n", 2); - - if (strncmp(rp->df_H, "HTTP/1.0", 8)) - reopen = 1; - - write(sock, "Host: ", 6); - if (rp->df_Host) { + write(sock, "Host: ", 6); + if (df_Host) { + if (debug) + fprintf(stderr, df_Host); + write(sock, df_Host, strlen(df_Host)); + } if (debug) - fprintf(fo, rp->df_Host); - write(sock, rp->df_Host, strlen(rp->df_Host)); - } - if (debug) - fprintf(fo, "\n"); - write(sock, "\r\n", 2); - if (rp->df_c) { + fprintf(stderr, "\n"); + write(sock, "\r\n", 2); + if (df_c) { + if (debug) + fprintf(stderr, "Connection: %s\n", df_c); + write(sock, "Connection: ", 12); + write(sock, df_c, strlen(df_c)); + write(sock, "\r\n", 2); + if (isequal(df_c, "keep-alive", df_c + strlen(df_c))) + reopen = 0; + } if (debug) - fprintf(fo, "Connection: %s\n", rp->df_c); - write(sock, "Connection: ", 12); - write(sock, rp->df_c, strlen(rp->df_c)); + fprintf(stderr, "\n"); write(sock, "\r\n", 2); - if (isequal(rp->df_c, "keep-alive", rp->df_c + strlen(rp->df_c))) - reopen = 0; + if (!reopen) + reopen = receive_response(sock); + if (reopen) + close(sock); } - if (debug) - fprintf(fo, "\n"); - write(sock, "\r\n", 2); - if (!reopen) - reopen = receive_response(); - if (reopen) - close(sock); } - } - /* clean up */ + /* clean up */ #define freez(x) do { if (x) free(x); x = NULL; } while (0); - freez(rp->df_H); - freez(rp->df_Host); - freez(rp->df_Uq); - freez(rp->df_m); - freez(rp->df_c); + freez(df_H); + freez(df_Host); + freez(df_Uq); + freez(df_m); + freez(df_c); #undef freez - rp->bogus = 0; + bogus = 0; + } while (1); return (0); } + +static int +gen_traffic(void *priv, enum shmlogtag tag, unsigned fd, + unsigned len, unsigned spec, const char *ptr) +{ + const char *end; + struct message *msg; + int err; + + (void)priv; + + end = ptr + len; + + if (!(spec & VSL_S_CLIENT)) + return (0); + + //fprintf(stderr, "gen_traffic\n"); + + if (fd >= nthreads) { + struct thread **newthreads = threads; + size_t newnthreads = nthreads; + + while (fd >= newnthreads) + newnthreads += newnthreads + 1; + newthreads = realloc(newthreads, newnthreads * sizeof *newthreads); + assert(newthreads != NULL); + memset(newthreads + nthreads, 0, (newnthreads - nthreads) * sizeof *newthreads); + threads = newthreads; + nthreads = newnthreads; + } + if (threads[fd] == NULL) { + threads[fd] = malloc(sizeof *threads[fd]); + assert(threads[fd] != NULL); + threads[fd]->mbox = malloc(sizeof (struct mailbox)); + STAILQ_INIT(&threads[fd]->mbox->messages); + pthread_mutex_init(&threads[fd]->mbox->lock, NULL); + pthread_cond_init(&threads[fd]->mbox->has_mail, NULL); + err = pthread_create(&threads[fd]->thread_id, NULL, pthread_main, threads[fd]); + if (err) + fprintf(stderr, "thread creation failed\n"); + fprintf(stderr, "Ok, thread %08x created... %d\n", (unsigned int)threads[fd]->thread_id, err); + } + msg = malloc(sizeof (struct message)); + msg->tag = tag; + msg->ptr = strdup(ptr); + msg->len = len; + mailbox_put(threads[fd]->mbox, msg); + //fprintf(stderr, "message put\n"); + + return 0; +} + + /* This function is for testing only, and only sends * the raw data from the file to the address. * The receive function is called for each blank line. @@ -461,6 +535,8 @@ int fd = open(file, O_RDONLY); char buf[2]; char last = ' '; + int sock, reopen = 1; + adr_info = init_connection(address); sock = VSS_connect(adr_info); while (read(fd, buf, 1)) { @@ -468,7 +544,7 @@ fprintf(stderr, "%s", buf); if (*buf == '\n' && last == '\n'){ fprintf(stderr, "receive\n"); - reopen = receive_response(); + reopen = receive_response(sock); } last = *buf; } @@ -491,15 +567,14 @@ { int c; struct VSL_data *vd; - const char *ofn = NULL; const char *address = NULL; - FILE *of; char *test_file = NULL; vd = VSL_New(); debug = 0; + VSL_Arg(vd, 'c', NULL); while ((c = getopt(argc, argv, "a:Dr:t:")) != -1) { switch (c) { case 'a': @@ -534,18 +609,10 @@ if (VSL_OpenLog(vd, NULL)) exit(1); - ofn = "stdout"; - of = stdout; - adr_info = init_connection(address); - reopen = 1; - while (VSL_Dispatch(vd, gen_traffic, of) == 0) { - if (fflush(of) != 0) { - perror(ofn); - exit(1); - } - } + while (VSL_Dispatch(vd, gen_traffic, NULL) == 0) + /* nothing */ ; exit(0); } From phk at projects.linpro.no Tue Jul 3 08:11:18 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Jul 2007 10:11:18 +0200 (CEST) Subject: r1621 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703081118.0C4551EC2B1@projects.linpro.no> Author: phk Date: 2007-07-03 10:11:17 +0200 (Tue, 03 Jul 2007) New Revision: 1621 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_pipe.c Log: Rename the backend connections two http's "bereq" and "beresp" Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 08:07:09 UTC (rev 1620) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 08:11:17 UTC (rev 1621) @@ -185,8 +185,8 @@ TAILQ_ENTRY(vbe_conn) list; struct backend *backend; int fd; - struct http *http; - struct http *http2; + struct http *bereq; + struct http *beresp; struct http http_mem[2]; }; Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-03 08:07:09 UTC (rev 1620) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-03 08:11:17 UTC (rev 1621) @@ -89,13 +89,13 @@ return (NULL); VSL_stats->n_vbe_conn++; vbc->magic = VBE_CONN_MAGIC; - vbc->http = &vbc->http_mem[0]; - vbc->http2 = &vbc->http_mem[1]; + vbc->bereq = &vbc->http_mem[0]; + vbc->beresp = &vbc->http_mem[1]; vbc->fd = -1; p = (void *)(vbc + 1); - http_Setup(vbc->http, p, space); + http_Setup(vbc->bereq, p, space); p += space; - http_Setup(vbc->http2, p, space); + http_Setup(vbc->beresp, p, space); return (vbc); } @@ -337,8 +337,8 @@ AZ(close(vc->fd)); vc->fd = -1; vc->backend = NULL; - WS_Reset(vc->http->ws); - WS_Reset(vc->http2->ws); + WS_Reset(vc->bereq->ws); + WS_Reset(vc->beresp->ws); LOCK(&vbemtx); TAILQ_INSERT_HEAD(&vbe_head, vc, list); VSL_stats->backend_unused++; @@ -355,8 +355,8 @@ assert(vc->fd >= 0); AN(vc->backend); WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); - WS_Reset(vc->http->ws); - WS_Reset(vc->http2->ws); + WS_Reset(vc->bereq->ws); + WS_Reset(vc->beresp->ws); LOCK(&vbemtx); VSL_stats->backend_recycle++; TAILQ_INSERT_HEAD(&vc->backend->connlist, vc, list); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-03 08:07:09 UTC (rev 1620) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-03 08:11:17 UTC (rev 1621) @@ -275,20 +275,20 @@ if (vc == NULL) return (1); - http_ClrHeader(vc->http); - vc->http->logtag = HTTP_Tx; - http_GetReq(w, vc->fd, vc->http, sp->http); - http_FilterHeader(w, vc->fd, vc->http, sp->http, HTTPH_R_FETCH); - http_PrintfHeader(w, vc->fd, vc->http, "X-Varnish: %u", sp->xid); - http_PrintfHeader(w, vc->fd, vc->http, + http_ClrHeader(vc->bereq); + vc->bereq->logtag = HTTP_Tx; + http_GetReq(w, vc->fd, vc->bereq, sp->http); + http_FilterHeader(w, vc->fd, vc->bereq, sp->http, HTTPH_R_FETCH); + http_PrintfHeader(w, vc->fd, vc->bereq, "X-Varnish: %u", sp->xid); + http_PrintfHeader(w, vc->fd, vc->bereq, "X-Forwarded-for: %s", sp->addr); - if (!http_GetHdr(vc->http, H_Host, &b)) { - http_PrintfHeader(w, vc->fd, vc->http, "Host: %s", + if (!http_GetHdr(vc->bereq, H_Host, &b)) { + http_PrintfHeader(w, vc->fd, vc->bereq, "Host: %s", sp->backend->hostname); } WRK_Reset(w, &vc->fd); - http_Write(w, vc->http, 0); + http_Write(w, vc->bereq, 0); if (WRK_Flush(w)) { /* XXX: cleanup */ return (1); @@ -298,11 +298,11 @@ CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); - if (http_RecvHead(vc->http, vc->fd)) { + if (http_RecvHead(vc->bereq, vc->fd)) { /* XXX: cleanup */ return (1); } - if (http_DissectResponse(sp->wrk, vc->http, vc->fd)) { + if (http_DissectResponse(sp->wrk, vc->bereq, vc->fd)) { /* XXX: cleanup */ return (1); } @@ -315,22 +315,22 @@ assert(sp->obj->busy != 0); - if (http_GetHdr(vc->http, H_Last_Modified, &b)) + if (http_GetHdr(vc->bereq, H_Last_Modified, &b)) sp->obj->last_modified = TIM_parse(b); - hp = vc->http2; + hp = vc->beresp; http_ClrHeader(hp); hp->logtag = HTTP_Obj; - http_CopyResp(sp->wrk, sp->fd, hp, vc->http); - http_FilterHeader(sp->wrk, sp->fd, hp, vc->http, HTTPH_A_INS); + http_CopyResp(sp->wrk, sp->fd, hp, vc->bereq); + http_FilterHeader(sp->wrk, sp->fd, hp, vc->bereq, HTTPH_A_INS); if (body) { - if (http_GetHdr(vc->http, H_Content_Length, &b)) - cls = fetch_straight(sp, vc->fd, vc->http, b); - else if (http_HdrIs(vc->http, H_Transfer_Encoding, "chunked")) - cls = fetch_chunked(sp, vc->fd, vc->http); + if (http_GetHdr(vc->bereq, H_Content_Length, &b)) + cls = fetch_straight(sp, vc->fd, vc->bereq, b); + else if (http_HdrIs(vc->bereq, H_Transfer_Encoding, "chunked")) + cls = fetch_chunked(sp, vc->fd, vc->bereq); else - cls = fetch_eof(sp, vc->fd, vc->http); + cls = fetch_eof(sp, vc->fd, vc->bereq); http_PrintfHeader(sp->wrk, sp->fd, hp, "Content-Length: %u", sp->obj->len); } else @@ -359,7 +359,7 @@ http_CopyHttp(&sp->obj->http, hp); - if (http_GetHdr(vc->http, H_Connection, &b) && !strcasecmp(b, "close")) + if (http_GetHdr(vc->bereq, H_Connection, &b) && !strcasecmp(b, "close")) cls = 1; if (cls) Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-03 08:07:09 UTC (rev 1620) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-03 08:11:17 UTC (rev 1621) @@ -87,19 +87,19 @@ vc = VBE_GetFd(sp); if (vc == NULL) return; - vc->http->logtag = HTTP_Tx; + vc->bereq->logtag = HTTP_Tx; - http_CopyReq(w, vc->fd, vc->http, sp->http); - http_FilterHeader(w, vc->fd, vc->http, sp->http, HTTPH_R_PIPE); - http_PrintfHeader(w, vc->fd, vc->http, "X-Varnish: %u", sp->xid); - http_PrintfHeader(w, vc->fd, vc->http, + http_CopyReq(w, vc->fd, vc->bereq, sp->http); + http_FilterHeader(w, vc->fd, vc->bereq, sp->http, HTTPH_R_PIPE); + http_PrintfHeader(w, vc->fd, vc->bereq, "X-Varnish: %u", sp->xid); + http_PrintfHeader(w, vc->fd, vc->bereq, "X-Forwarded-for: %s", sp->addr); - if (!http_GetHdr(vc->http, H_Host, &b)) { - http_PrintfHeader(w, vc->fd, vc->http, "Host: %s", + if (!http_GetHdr(vc->bereq, H_Host, &b)) { + http_PrintfHeader(w, vc->fd, vc->bereq, "Host: %s", sp->backend->hostname); } WRK_Reset(w, &vc->fd); - http_Write(w, vc->http, 0); + http_Write(w, vc->bereq, 0); if (http_GetTail(sp->http, 0, &b, &e) && b != e) WRK_Write(w, b, e - b); From phk at projects.linpro.no Tue Jul 3 08:50:35 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Jul 2007 10:50:35 +0200 (CEST) Subject: r1622 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703085035.353551EC475@projects.linpro.no> Author: phk Date: 2007-07-03 10:50:34 +0200 (Tue, 03 Jul 2007) New Revision: 1622 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_pipe.c Log: Convert pipe mode to use the bereq in struct worker. (See architect notes on wiki for reasoning) Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 08:11:17 UTC (rev 1621) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 08:50:34 UTC (rev 1622) @@ -165,9 +165,14 @@ struct VCL_conf *vcl; struct srcaddr *srcaddr; struct acct acct; - unsigned char wlog[WLOGSPACE]; + + /* Backend connection space */ + struct http bereq[1]; + struct http beresp[1]; + unsigned char *wlp, *wle; unsigned wlr; + unsigned char wlog[WLOGSPACE]; }; struct workreq { Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-03 08:11:17 UTC (rev 1621) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-03 08:50:34 UTC (rev 1622) @@ -78,6 +78,7 @@ char *b, *e; struct worker *w; struct pollfd fds[2]; + char wsspc[8192]; int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -87,19 +88,29 @@ vc = VBE_GetFd(sp); if (vc == NULL) return; - vc->bereq->logtag = HTTP_Tx; + w->bereq->logtag = HTTP_Tx; - http_CopyReq(w, vc->fd, vc->bereq, sp->http); - http_FilterHeader(w, vc->fd, vc->bereq, sp->http, HTTPH_R_PIPE); - http_PrintfHeader(w, vc->fd, vc->bereq, "X-Varnish: %u", sp->xid); - http_PrintfHeader(w, vc->fd, vc->bereq, + http_Setup(w->bereq, wsspc, sizeof wsspc); + + http_CopyReq(w, vc->fd, w->bereq, sp->http); + http_FilterHeader(w, vc->fd, w->bereq, sp->http, HTTPH_R_PIPE); + http_PrintfHeader(w, vc->fd, w->bereq, "X-Varnish: %u", sp->xid); + http_PrintfHeader(w, vc->fd, w->bereq, "X-Forwarded-for: %s", sp->addr); - if (!http_GetHdr(vc->bereq, H_Host, &b)) { - http_PrintfHeader(w, vc->fd, vc->bereq, "Host: %s", + + /* XXX: does this belong in VCL ? */ + if (!http_GetHdr(w->bereq, H_Host, &b)) { + http_PrintfHeader(w, vc->fd, w->bereq, "Host: %s", sp->backend->hostname); } + + VCL_pipe_method(sp); + + if (sp->handling == VCL_RET_ERROR) + INCOMPL(); + WRK_Reset(w, &vc->fd); - http_Write(w, vc->bereq, 0); + http_Write(w, w->bereq, 0); if (http_GetTail(sp->http, 0, &b, &e) && b != e) WRK_Write(w, b, e - b); From des at projects.linpro.no Tue Jul 3 09:09:55 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 3 Jul 2007 11:09:55 +0200 (CEST) Subject: r1623 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070703090955.E0CA11EC2B1@projects.linpro.no> Author: des Date: 2007-07-03 11:09:55 +0200 (Tue, 03 Jul 2007) New Revision: 1623 Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Log: Reorganize the code a little, and add code to wait for all threads to finish processing pending messages before we exit. Note that VSL_Dispatch() will read in log data as fast as it can, so when working from a log file, varnishreplay will usually read in the entire file into memory within the first few seconds. Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-07-03 08:50:34 UTC (rev 1622) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-07-03 09:09:55 UTC (rev 1623) @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -42,32 +43,60 @@ #include "varnishapi.h" #include "vss.h" -static struct thread { - pthread_t thread_id; - struct mailbox *mbox; -} **threads; - -struct mailbox { - pthread_mutex_t lock; - pthread_cond_t has_mail; - STAILQ_HEAD(msgq_head, message) messages; -}; +#ifndef HAVE_STRNDUP +#include "compat/strndup.h" +#endif +#define freez(x) do { if (x) free(x); x = NULL; } while (0); + +static struct vss_addr *addr_info; +static int debug; + +/* + * mailbox toolkit + */ + struct message { enum shmlogtag tag; + size_t len; char *ptr; - unsigned len; STAILQ_ENTRY(message) list; }; -static size_t nthreads; +struct mailbox { + pthread_mutex_t lock; + pthread_cond_t has_mail; + int open; + STAILQ_HEAD(msgq_head, message) messages; +}; -static struct vss_addr *adr_info; -static int debug; +static void +mailbox_create(struct mailbox *mbox) +{ + STAILQ_INIT(&mbox->messages); + pthread_mutex_init(&mbox->lock, NULL); + pthread_cond_init(&mbox->has_mail, NULL); + mbox->open = 1; +} + static void +mailbox_destroy(struct mailbox *mbox) +{ + struct message *msg; + + while ((msg = STAILQ_FIRST(&mbox->messages))) { + STAILQ_REMOVE_HEAD(&mbox->messages, list); + free(msg); + } + pthread_cond_destroy(&mbox->has_mail); + pthread_mutex_destroy(&mbox->lock); +} + +static void mailbox_put(struct mailbox *mbox, struct message *msg) { + pthread_mutex_lock(&mbox->lock); STAILQ_INSERT_TAIL(&mbox->messages, msg, list); pthread_cond_signal(&mbox->has_mail); @@ -78,15 +107,113 @@ mailbox_get(struct mailbox *mbox) { struct message *msg; - + pthread_mutex_lock(&mbox->lock); - while ((msg = STAILQ_FIRST(&mbox->messages)) == NULL) + while ((msg = STAILQ_FIRST(&mbox->messages)) == NULL && mbox->open) pthread_cond_wait(&mbox->has_mail, &mbox->lock); - STAILQ_REMOVE_HEAD(&mbox->messages, list); + if (msg != NULL) + STAILQ_REMOVE_HEAD(&mbox->messages, list); pthread_mutex_unlock(&mbox->lock); return msg; } +static void +mailbox_close(struct mailbox *mbox) +{ + pthread_mutex_lock(&mbox->lock); + mbox->open = 0; + pthread_cond_signal(&mbox->has_mail); + pthread_mutex_unlock(&mbox->lock); +} + +/* + * thread toolkit + */ + +struct thread { + pthread_t thread_id; + struct mailbox mbox; +}; + +static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; + +static void +thread_log(int lvl, const char *fmt, ...) +{ + va_list ap; + + if (lvl > debug) + return; + pthread_mutex_lock(&log_mutex); + fprintf(stderr, "%08x ", (unsigned int)pthread_self()); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + pthread_mutex_unlock(&log_mutex); +} + +static struct thread **threads; +static size_t nthreads; + +static struct thread * +thread_get(int fd, void *(*thread_main)(void *)) +{ + + assert(fd != 0); + if (fd >= nthreads) { + struct thread **newthreads = threads; + size_t newnthreads = nthreads; + + while (fd >= newnthreads) + newnthreads += newnthreads + 1; + newthreads = realloc(newthreads, newnthreads * sizeof *newthreads); + assert(newthreads != NULL); + memset(newthreads + nthreads, 0, + (newnthreads - nthreads) * sizeof *newthreads); + threads = newthreads; + nthreads = newnthreads; + } + if (threads[fd] == NULL) { + threads[fd] = malloc(sizeof *threads[fd]); + assert(threads[fd] != NULL); + mailbox_create(&threads[fd]->mbox); + if (pthread_create(&threads[fd]->thread_id, NULL, + thread_main, threads[fd]) != 0) { + thread_log(0, "thread creation failed\n"); + mailbox_destroy(&threads[fd]->mbox); + freez(threads[fd]); + } + thread_log(1, "thread %08x started\n", + (unsigned int)threads[fd]->thread_id); + } + return (threads[fd]); +} + +static void +thread_close(int fd) +{ + + assert(fd < nthreads); + if (fd == 0) { + for (fd = 1; fd < nthreads; ++fd) + thread_close(fd); + return; + } + + if (threads[fd] == NULL) + return; + mailbox_close(&threads[fd]->mbox); + pthread_join(threads[fd]->thread_id, NULL); + thread_log(1, "thread %08x stopped\n", + (unsigned int)threads[fd]->thread_id); + mailbox_destroy(&threads[fd]->mbox); + freez(threads[fd]); +} + +/* + * ... + */ + static int isprefix(const char *str, const char *prefix, const char *end, const char **next) { @@ -159,14 +286,14 @@ int i, n; if (VSS_parse(address, &addr, &port) != 0) { - fprintf(stderr, "Invalid address\n"); + thread_log(0, "Invalid address\n"); exit(2); } n = VSS_resolve(addr, port, &ta); free(addr); free(port); if (n == 0) { - fprintf(stderr, "Could not connect to server\n"); + thread_log(0, "Could not connect to server\n"); exit(2); } for (i = 1; i < n; ++i) { @@ -200,12 +327,11 @@ buf = realloc(buf, lbuf); XXXAN(buf); } - //fprintf(stderr, "start reading\n"); i = read(sock, buf + nbuf, 1); if (i <= 0) { - perror("error in reading\n"); + thread_log(0, "read(): %s\n", strerror(errno)); free(buf); - exit(1); + return (-1); } nbuf += i; if (nbuf >= 2 && buf[nbuf-2] == '\r' && buf[nbuf-1] == '\n') @@ -233,8 +359,8 @@ n = read(sock, buf + nbuf, (2048 < length - nbuf ? 2048 : length - nbuf)); if (n <= 0) { - perror("failed reading the block\n"); - break; + thread_log(0, "failed reading the block\n"); + return (-1); } nbuf += n; } @@ -282,24 +408,20 @@ free(line); } - if (debug) - fprintf(stderr, "status: %d\n", status); + thread_log(1, "status: %d\n", status); /* Read body */ if (content_length > 0 && !chunked) { /* Fixed body size, read content_length bytes */ - if (debug) - fprintf(stderr, "fixed length\n"); - n = read_block(content_length, sock); - if (debug) { - fprintf(stderr, "size of body: %d\n", (int)content_length); - fprintf(stderr, "bytes read: %d\n", n); - } + thread_log(1, "fixed length\n"); + thread_log(1, "size of body: %ld\n", content_length); + if ((n = read_block(content_length, sock)) < 0) + return (1); + thread_log(1, "bytes read: %d\n", n); } else if (chunked) { /* Chunked encoding, read size and bytes until no more */ - if (debug) - fprintf(stderr, "chunked encoding\n"); + thread_log(1, "chunked encoding\n"); while (1) { line_len = read_line(&line, sock); end = line + line_len; @@ -308,10 +430,8 @@ break; } n = read_block(block_len, sock); - if (debug) { - fprintf(stderr, "size of body: %d\n", (int)block_len); - fprintf(stderr, "bytes read: %d\n", n); - } + thread_log(1, "size of body: %d\n", (int)block_len); + thread_log(1, "bytes read: %d\n", n); free(line); n = read_line(&line, sock); free(line); @@ -320,29 +440,27 @@ free(line); } else if ((content_length <= 0 && !chunked) || req_failed) { /* No body --> stop reading. */ - if (debug) - fprintf(stderr, "no body\n"); + thread_log(1, "no body\n"); + return (1); } else { /* Unhandled case. */ - fprintf(stderr, "An error occured\n"); - exit(1); + thread_log(0, "An error occured\n"); + return (1); } - if (debug) - fprintf(stderr, "\n"); return close_connection; } static void * -pthread_main(void *arg) +replay_thread(void *arg) { + struct thread *thr = arg; struct message *msg; - struct thread *th = (struct thread*)arg; enum shmlogtag tag; - int len; + size_t len; char *ptr; const char *end, *next; - + char *df_H = NULL; /* %H, Protocol version */ char *df_Host = NULL; /* %{Host}i */ char *df_Uq = NULL; /* %U%q, URL path and query string */ @@ -351,18 +469,15 @@ int bogus = 0; /* bogus request */ int sock, reopen = 1; - - //fprintf(stderr, "thread started\n"); - - do { - msg = mailbox_get(th->mbox); + + while ((msg = mailbox_get(&thr->mbox)) != NULL) { tag = msg->tag; len = msg->len; ptr = msg->ptr; end = ptr + len; - - //fprintf(stderr, "%08x %s(%s)\n", (unsigned int)pthread_self(), VSL_tags[tag], msg->ptr); - + + thread_log(2, "%s(%s)\n", VSL_tags[tag], msg->ptr); + switch (tag) { case SLT_RxRequest: if (df_m != NULL) @@ -398,10 +513,10 @@ if (tag != SLT_ReqEnd) continue; - - //fprintf(stderr, "bogus: %d %s\n", bogus, df_m); - if (!bogus) { + if (bogus) { + thread_log(1, "bogus\n"); + } else { /* If the method is supported (GET or HEAD), send the request out * on the socket. If the socket needs reopening, reopen it first. * When the request is sent, call the function for receiving @@ -409,16 +524,11 @@ */ if (!(strncmp(df_m, "GET", 3) && strncmp(df_m, "HEAD", 4))) { if (reopen) - sock = VSS_connect(adr_info); + sock = VSS_connect(addr_info); reopen = 0; - if (debug) { - fprintf(stderr, "%s ", df_m); - fprintf(stderr, "%s ", df_Uq); - fprintf(stderr, "%s ", df_H); - fprintf(stderr, "\n"); - fprintf(stderr, "Host: "); - } + thread_log(1, "%s %s %s\n", df_m, df_Uq, df_H); + write(sock, df_m, strlen(df_m)); write(sock, " ", 1); write(sock, df_Uq, strlen(df_Uq)); @@ -432,16 +542,12 @@ write(sock, "Host: ", 6); if (df_Host) { - if (debug) - fprintf(stderr, df_Host); + thread_log(1, "Host: %s\n", df_Host); write(sock, df_Host, strlen(df_Host)); } - if (debug) - fprintf(stderr, "\n"); write(sock, "\r\n", 2); if (df_c) { - if (debug) - fprintf(stderr, "Connection: %s\n", df_c); + thread_log(1, "Connection: %s\n", df_c); write(sock, "Connection: ", 12); write(sock, df_c, strlen(df_c)); write(sock, "\r\n", 2); @@ -449,7 +555,7 @@ reopen = 0; } if (debug) - fprintf(stderr, "\n"); + thread_log(0, "\n"); write(sock, "\r\n", 2); if (!reopen) reopen = receive_response(sock); @@ -459,16 +565,15 @@ } /* clean up */ -#define freez(x) do { if (x) free(x); x = NULL; } while (0); + freez(msg->ptr); + freez(msg); freez(df_H); freez(df_Host); freez(df_Uq); freez(df_m); freez(df_c); -#undef freez bogus = 0; - } while (1); - + } return (0); } @@ -477,50 +582,25 @@ gen_traffic(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) { + struct thread *thr; const char *end; struct message *msg; - int err; - + (void)priv; end = ptr + len; - if (!(spec & VSL_S_CLIENT)) + if (fd == 0 || !(spec & VSL_S_CLIENT)) return (0); - //fprintf(stderr, "gen_traffic\n"); - - if (fd >= nthreads) { - struct thread **newthreads = threads; - size_t newnthreads = nthreads; - - while (fd >= newnthreads) - newnthreads += newnthreads + 1; - newthreads = realloc(newthreads, newnthreads * sizeof *newthreads); - assert(newthreads != NULL); - memset(newthreads + nthreads, 0, (newnthreads - nthreads) * sizeof *newthreads); - threads = newthreads; - nthreads = newnthreads; - } - if (threads[fd] == NULL) { - threads[fd] = malloc(sizeof *threads[fd]); - assert(threads[fd] != NULL); - threads[fd]->mbox = malloc(sizeof (struct mailbox)); - STAILQ_INIT(&threads[fd]->mbox->messages); - pthread_mutex_init(&threads[fd]->mbox->lock, NULL); - pthread_cond_init(&threads[fd]->mbox->has_mail, NULL); - err = pthread_create(&threads[fd]->thread_id, NULL, pthread_main, threads[fd]); - if (err) - fprintf(stderr, "thread creation failed\n"); - fprintf(stderr, "Ok, thread %08x created... %d\n", (unsigned int)threads[fd]->thread_id, err); - } + thread_log(2, "%d %s\n", fd, VSL_tags[tag]); + thr = thread_get(fd, replay_thread); msg = malloc(sizeof (struct message)); msg->tag = tag; - msg->ptr = strdup(ptr); msg->len = len; - mailbox_put(threads[fd]->mbox, msg); - //fprintf(stderr, "message put\n"); - + msg->ptr = strndup(ptr, len); + mailbox_put(&thr->mbox, msg); + return 0; } @@ -536,14 +616,14 @@ char buf[2]; char last = ' '; int sock, reopen = 1; - - adr_info = init_connection(address); - sock = VSS_connect(adr_info); + + addr_info = init_connection(address); + sock = VSS_connect(addr_info); while (read(fd, buf, 1)) { write(sock, buf, 1); - fprintf(stderr, "%s", buf); + thread_log(0, "%s", buf); if (*buf == '\n' && last == '\n'){ - fprintf(stderr, "receive\n"); + thread_log(0, "receive\n"); reopen = receive_response(sock); } last = *buf; @@ -581,7 +661,7 @@ address = optarg; break; case 'D': - debug = 1; + ++debug; break; case 't': /* This option is for testing only. The test file must contain @@ -609,10 +689,10 @@ if (VSL_OpenLog(vd, NULL)) exit(1); - adr_info = init_connection(address); + addr_info = init_connection(address); while (VSL_Dispatch(vd, gen_traffic, NULL) == 0) /* nothing */ ; - + thread_close(0); exit(0); } From cecilihf at projects.linpro.no Tue Jul 3 09:20:51 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Tue, 3 Jul 2007 11:20:51 +0200 (CEST) Subject: r1624 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070703092051.2F0371EC030@projects.linpro.no> Author: cecilihf Date: 2007-07-03 11:20:50 +0200 (Tue, 03 Jul 2007) New Revision: 1624 Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Log: Use strcmp instead of strncmp Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-07-03 09:09:55 UTC (rev 1623) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-07-03 09:20:50 UTC (rev 1624) @@ -522,7 +522,7 @@ * When the request is sent, call the function for receiving * the answer. */ - if (!(strncmp(df_m, "GET", 3) && strncmp(df_m, "HEAD", 4))) { + if (!(strcmp(df_m, "GET") && strcmp(df_m, "HEAD"))) { if (reopen) sock = VSS_connect(addr_info); reopen = 0; From des at projects.linpro.no Tue Jul 3 11:34:16 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 3 Jul 2007 13:34:16 +0200 (CEST) Subject: r1625 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070703113416.F3ECA1EC484@projects.linpro.no> Author: des Date: 2007-07-03 13:34:16 +0200 (Tue, 03 Jul 2007) New Revision: 1625 Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Log: Additional paranoia. Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-07-03 09:20:50 UTC (rev 1624) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-07-03 11:34:16 UTC (rev 1625) @@ -385,12 +385,14 @@ int status; /* Read header */ - while (1) { + for (;;) { line_len = read_line(&line, sock); + if (line_len < 0) + return (-1); end = line + line_len; - if (*line == '\r' && *(line + 1) == '\n') { - free(line); + if (line_len >= 2 && line[0] == '\r' && line[1] == '\n') { + freez(line); break; } @@ -405,7 +407,7 @@ else if (isprefix(line, "connection:", end, &next)) close_connection = (strstr(next, "close") != NULL); - free(line); + freez(line); } thread_log(1, "status: %d\n", status); @@ -422,30 +424,32 @@ } else if (chunked) { /* Chunked encoding, read size and bytes until no more */ thread_log(1, "chunked encoding\n"); - while (1) { - line_len = read_line(&line, sock); + for (;;) { + if ((line_len = read_line(&line, sock)) < 0) + return (-1); end = line + line_len; block_len = strtol(line, &end, 16); - if (block_len == 0) { + freez(line); + if (block_len == 0) break; - } - n = read_block(block_len, sock); + if ((n = read_block(block_len, sock)) < 0) + return (-1); thread_log(1, "size of body: %d\n", (int)block_len); thread_log(1, "bytes read: %d\n", n); - free(line); - n = read_line(&line, sock); - free(line); + if ((n = read_line(&line, sock)) < 0) + return (-1); + freez(line); } n = read_line(&line, sock); - free(line); + freez(line); } else if ((content_length <= 0 && !chunked) || req_failed) { /* No body --> stop reading. */ thread_log(1, "no body\n"); - return (1); + return (-1); } else { /* Unhandled case. */ thread_log(0, "An error occured\n"); - return (1); + return (-1); } return close_connection; From des at projects.linpro.no Tue Jul 3 12:21:50 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 3 Jul 2007 14:21:50 +0200 (CEST) Subject: r1626 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20070703122150.C69811EC030@projects.linpro.no> Author: des Date: 2007-07-03 14:21:50 +0200 (Tue, 03 Jul 2007) New Revision: 1626 Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/mgt_cli.h trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/include/cli.h Log: Add a 'vcl.show' command which displays the source code for a given VCL script. Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-07-03 11:34:16 UTC (rev 1625) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-07-03 12:21:50 UTC (rev 1626) @@ -148,6 +148,7 @@ { CLI_VCL_USE, mcf_config_use, NULL }, { CLI_VCL_DISCARD, mcf_config_discard, NULL }, { CLI_VCL_LIST, mcf_config_list, NULL }, + { CLI_VCL_SHOW, mcf_config_show, NULL }, { CLI_PARAM_SHOW, mcf_param_show, NULL }, { CLI_PARAM_SET, mcf_param_set, NULL }, { CLI_HELP, cli_func_help, NULL }, Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.h 2007-07-03 11:34:16 UTC (rev 1625) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.h 2007-07-03 12:21:50 UTC (rev 1626) @@ -42,3 +42,4 @@ cli_func_t mcf_config_use; cli_func_t mcf_config_discard; cli_func_t mcf_config_list; +cli_func_t mcf_config_show; Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-07-03 11:34:16 UTC (rev 1625) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-07-03 12:21:50 UTC (rev 1626) @@ -573,3 +573,29 @@ } } +void +mcf_config_show(struct cli *cli, char **av, void *priv) +{ + struct vclprog *vp; + void *dlh, *sym; + const char **src; + + (void)priv; + if ((vp = mcf_find_vcl(cli, av[2])) != NULL) { + if ((dlh = dlopen(vp->fname, RTLD_NOW | RTLD_LOCAL)) == NULL) { + cli_out(cli, "failed to load %s: %s\n", + vp->name, dlerror()); + cli_result(cli, CLIS_CANT); + } else if ((sym = dlsym(dlh, "srcbody")) == NULL) { + cli_out(cli, "failed to locate source for %s: %s\n", + vp->name, dlerror()); + cli_result(cli, CLIS_CANT); + dlclose(dlh); + } else { + src = sym; + cli_out(cli, src[0]); + /* cli_out(cli, src[1]); */ + dlclose(dlh); + } + } +} Modified: trunk/varnish-cache/include/cli.h =================================================================== --- trunk/varnish-cache/include/cli.h 2007-07-03 11:34:16 UTC (rev 1625) +++ trunk/varnish-cache/include/cli.h 2007-07-03 12:21:50 UTC (rev 1626) @@ -79,14 +79,14 @@ "\tCompile and load the VCL file under the name provided.", \ 2, 2 -#define CLI_VCL_INLINE \ - "vcl.inline", \ - "vcl.inline ", \ +#define CLI_VCL_INLINE \ + "vcl.inline", \ + "vcl.inline ", \ "\tCompile and load the VCL data under the name provided.", \ 2, 2 -#define CLI_VCL_DISCARD \ - "vcl.discard", \ +#define CLI_VCL_DISCARD \ + "vcl.discard", \ "vcl.discard ", \ "\tUnload the named configuration (when possible).", \ 1, 1 @@ -97,9 +97,15 @@ "\tList all loaded configuration.", \ 0, 0 +#define CLI_VCL_SHOW \ + "vcl.show", \ + "vcl.show ", \ + "\tDisplay the source code for the specified configuration.", \ + 1, 1 + #define CLI_VCL_USE \ "vcl.use", \ - "vcl.use ", \ + "vcl.use ", \ "\tSwitch to the named configuration immediately.", \ 1, 1 From des at projects.linpro.no Tue Jul 3 12:22:42 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 3 Jul 2007 14:22:42 +0200 (CEST) Subject: r1627 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703122242.C87B21EC835@projects.linpro.no> Author: des Date: 2007-07-03 14:22:42 +0200 (Tue, 03 Jul 2007) New Revision: 1627 Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 Log: Document vcl.show. Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2007-07-03 12:21:50 UTC (rev 1626) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2007-07-03 12:22:42 UTC (rev 1627) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd June 26, 2007 +.Dd July 3, 2007 .Dt VARNISHD 1 .Os .Sh NAME @@ -336,6 +336,8 @@ Create a new configuration named .Ar configname with the contents of the specified file. +.It Cm vcl.show Ar configname +Display the source code for the specified configuration. .It Cm vcl.use Ar configname Start using the configuration specified by .Ar configname From des at projects.linpro.no Tue Jul 3 14:17:29 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 3 Jul 2007 16:17:29 +0200 (CEST) Subject: r1628 - trunk/varnish-cache/lib/libvcl Message-ID: <20070703141729.232D01EC030@projects.linpro.no> Author: des Date: 2007-07-03 16:17:28 +0200 (Tue, 03 Jul 2007) New Revision: 1628 Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl Log: Add two VCL variables, "now" and "obj.lastuse". The former returns the current time, the latter returns the number of seconds since an object was last requested. The exact semantics of both are slightly fluid at the moment, and will be revisited at a later date. Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-03 12:22:42 UTC (rev 1627) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-03 14:17:28 UTC (rev 1628) @@ -130,6 +130,10 @@ RW TIME { hit fetch discard timeout} } + { obj.lastuse + RO TIME + { hit fetch deliver discard timeout} + } # The response we send back { resp.proto @@ -148,6 +152,12 @@ RW HEADER { fetch } } + + # Miscellaneous + { now + RO TIME + {recv pipe pass hash miss hit fetch deliver discard timeout} + } } set tt(IP) "struct sockaddr *" From des at projects.linpro.no Tue Jul 3 14:18:24 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 3 Jul 2007 16:18:24 +0200 (CEST) Subject: r1629 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20070703141824.6CF081EC37C@projects.linpro.no> Author: des Date: 2007-07-03 16:18:24 +0200 (Tue, 03 Jul 2007) New Revision: 1629 Modified: trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: Regenerate. Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2007-07-03 14:17:28 UTC (rev 1628) +++ trunk/varnish-cache/include/vrt_obj.h 2007-07-03 14:18:24 UTC (rev 1629) @@ -35,9 +35,11 @@ void VRT_l_obj_cacheable(struct sess *, unsigned); double VRT_r_obj_ttl(struct sess *); void VRT_l_obj_ttl(struct sess *, double); +double VRT_r_obj_lastuse(struct sess *); const char * VRT_r_resp_proto(struct sess *); void VRT_l_resp_proto(struct sess *, const char *); int VRT_r_resp_status(struct sess *); void VRT_l_resp_status(struct sess *, int); const char * VRT_r_resp_response(struct sess *); void VRT_l_resp_response(struct sess *, const char *); +double VRT_r_now(struct sess *); Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-03 14:17:28 UTC (rev 1628) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-03 14:18:24 UTC (rev 1629) @@ -146,6 +146,12 @@ V_RW, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, + { "obj.lastuse", TIME, 11, + "VRT_r_obj_lastuse(sp)", + NULL, + V_RO, + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT + }, { "resp.proto", STRING, 10, "VRT_r_resp_proto(sp)", "VRT_l_resp_proto(sp, ", @@ -170,5 +176,11 @@ V_RW, VCL_MET_FETCH }, + { "now", TIME, 3, + "VRT_r_now(sp)", + NULL, + V_RO, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT + }, { NULL } }; From des at projects.linpro.no Tue Jul 3 14:19:40 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 3 Jul 2007 16:19:40 +0200 (CEST) Subject: r1630 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703141940.AB8771EC030@projects.linpro.no> Author: des Date: 2007-07-03 16:19:40 +0200 (Tue, 03 Jul 2007) New Revision: 1630 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Implement "now" and "obj.lastuse", with a note to the effect that the use of timestamps and clock_gettime() throughout Varnish needs reviewing (as per IRC discussion with phk) Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-03 14:18:24 UTC (rev 1629) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-03 14:19:40 UTC (rev 1630) @@ -304,3 +304,28 @@ sp->hash_e[l] = '#'; sp->hash_e += l + 1; } + +/*--------------------------------------------------------------------*/ + +double +VRT_r_now(struct sess *sp) +{ + struct timespec now; + + (void)sp; + /* XXX use of clock_gettime() needs review */ + clock_gettime(CLOCK_MONOTONIC, &now); + return (now.tv_sec); +} + +double +VRT_r_obj_lastuse(struct sess *sp) +{ + struct timespec now; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ + /* XXX use of clock_gettime() needs review */ + clock_gettime(CLOCK_MONOTONIC, &now); + return (now.tv_sec - sp->obj->lru_stamp); +} From phk at projects.linpro.no Tue Jul 3 19:32:21 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Jul 2007 21:32:21 +0200 (CEST) Subject: r1631 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703193221.E58671EC37C@projects.linpro.no> Author: phk Date: 2007-07-03 21:32:21 +0200 (Tue, 03 Jul 2007) New Revision: 1631 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.c Log: Add functions for allocating and freeing bereq structures. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 14:19:40 UTC (rev 1630) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 19:32:21 UTC (rev 1631) @@ -184,6 +184,14 @@ /* Backend Connection ------------------------------------------------*/ +struct bereq { + unsigned magic; +#define BEREQ_MAGIC 0x3b6d250c + TAILQ_ENTRY(bereq) list; + struct ws ws[1]; + struct http http[1]; +}; + struct vbe_conn { unsigned magic; #define VBE_CONN_MAGIC 0x0c5e6592 @@ -362,6 +370,8 @@ struct vbe_conn *VBE_GetFd(struct sess *sp); void VBE_ClosedFd(struct worker *w, struct vbe_conn *vc, int already); void VBE_RecycleFd(struct worker *w, struct vbe_conn *vc); +struct bereq *vbe_new_bereq(void); +void vbe_free_bereq(struct bereq *bereq); /* cache_ban.c */ void BAN_Init(void); Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-03 14:19:40 UTC (rev 1630) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-03 19:32:21 UTC (rev 1631) @@ -59,6 +59,7 @@ /* A backend IP */ static TAILQ_HEAD(,vbe_conn) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head); +static TAILQ_HEAD(,bereq) bereq_head = TAILQ_HEAD_INITIALIZER(bereq_head); static MTX vbemtx; @@ -76,6 +77,43 @@ /*--------------------------------------------------------------------*/ +struct bereq * +vbe_new_bereq(void) +{ + struct bereq *bereq; + volatile unsigned space; + + LOCK(&vbemtx); + bereq = TAILQ_FIRST(&bereq_head); + if (bereq != NULL) + TAILQ_REMOVE(&bereq_head, bereq, list); + UNLOCK(&vbemtx); + if (bereq == NULL) { + space = params->mem_workspace; + bereq = calloc(sizeof *bereq + space, 1); + if (bereq == NULL) + return (NULL); + bereq->magic = BEREQ_MAGIC; + WS_Init(bereq->ws, bereq + 1, space); + } + WS_Reset(bereq->ws); + return (bereq); +} + +/*--------------------------------------------------------------------*/ +/* XXX: no backpressure on pool size */ + +void +vbe_free_bereq(struct bereq *bereq) +{ + + LOCK(&vbemtx); + TAILQ_INSERT_HEAD(&bereq_head, bereq, list); + UNLOCK(&vbemtx); +} + +/*--------------------------------------------------------------------*/ + static struct vbe_conn * vbe_new_conn(void) { From phk at projects.linpro.no Tue Jul 3 20:38:38 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Jul 2007 22:38:38 +0200 (CEST) Subject: r1632 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703203838.8F1091EC37C@projects.linpro.no> Author: phk Date: 2007-07-03 22:38:38 +0200 (Tue, 03 Jul 2007) New Revision: 1632 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_pipe.c Log: Emply the new vbe_bereq structure for holding backend request and reply. There should be no functional change as a result of this. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 19:32:21 UTC (rev 1631) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 20:38:38 UTC (rev 1632) @@ -188,7 +188,8 @@ unsigned magic; #define BEREQ_MAGIC 0x3b6d250c TAILQ_ENTRY(bereq) list; - struct ws ws[1]; + void *space; + unsigned len; struct http http[1]; }; @@ -198,9 +199,6 @@ TAILQ_ENTRY(vbe_conn) list; struct backend *backend; int fd; - struct http *bereq; - struct http *beresp; - struct http http_mem[2]; }; /* Storage -----------------------------------------------------------*/ @@ -407,7 +405,6 @@ const char *http_StatusMessage(int); void HTTP_Init(void); void http_ClrHeader(struct http *to); -void http_CopyHttp(struct http *to, struct http *fm); unsigned http_Write(struct worker *w, struct http *hp, int resp); void http_GetReq(struct worker *w, int fd, struct http *to, struct http *fm); void http_CopyReq(struct worker *w, int fd, struct http *to, struct http *fm); @@ -433,7 +430,9 @@ int http_DissectRequest(struct worker *w, struct http *sp, int fd); int http_DissectResponse(struct worker *w, struct http *sp, int fd); void http_DoConnection(struct sess *sp); +void http_CopyHome(struct http *hp); + #define HTTPH(a, b, c, d, e, f, g) extern char b[]; #include "http_headers.h" #undef HTTPH Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-03 19:32:21 UTC (rev 1631) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-03 20:38:38 UTC (rev 1632) @@ -81,22 +81,25 @@ vbe_new_bereq(void) { struct bereq *bereq; - volatile unsigned space; + volatile unsigned len; LOCK(&vbemtx); bereq = TAILQ_FIRST(&bereq_head); if (bereq != NULL) TAILQ_REMOVE(&bereq_head, bereq, list); UNLOCK(&vbemtx); - if (bereq == NULL) { - space = params->mem_workspace; - bereq = calloc(sizeof *bereq + space, 1); + if (bereq != NULL) { + CHECK_OBJ(bereq, BEREQ_MAGIC); + } else { + len = params->mem_workspace; + bereq = calloc(sizeof *bereq + len, 1); if (bereq == NULL) return (NULL); bereq->magic = BEREQ_MAGIC; - WS_Init(bereq->ws, bereq + 1, space); + bereq->space = bereq + 1; + bereq->len = len; } - WS_Reset(bereq->ws); + http_Setup(bereq->http, bereq->space, bereq->len); return (bereq); } @@ -107,6 +110,7 @@ vbe_free_bereq(struct bereq *bereq) { + CHECK_OBJ_NOTNULL(bereq, BEREQ_MAGIC); LOCK(&vbemtx); TAILQ_INSERT_HEAD(&bereq_head, bereq, list); UNLOCK(&vbemtx); @@ -118,22 +122,13 @@ vbe_new_conn(void) { struct vbe_conn *vbc; - unsigned char *p; - volatile unsigned space; - space = params->mem_workspace; - vbc = calloc(sizeof *vbc + space * 2, 1); + vbc = calloc(sizeof *vbc, 1); if (vbc == NULL) return (NULL); VSL_stats->n_vbe_conn++; vbc->magic = VBE_CONN_MAGIC; - vbc->bereq = &vbc->http_mem[0]; - vbc->beresp = &vbc->http_mem[1]; vbc->fd = -1; - p = (void *)(vbc + 1); - http_Setup(vbc->bereq, p, space); - p += space; - http_Setup(vbc->beresp, p, space); return (vbc); } @@ -375,8 +370,6 @@ AZ(close(vc->fd)); vc->fd = -1; vc->backend = NULL; - WS_Reset(vc->bereq->ws); - WS_Reset(vc->beresp->ws); LOCK(&vbemtx); TAILQ_INSERT_HEAD(&vbe_head, vc, list); VSL_stats->backend_unused++; @@ -393,8 +386,6 @@ assert(vc->fd >= 0); AN(vc->backend); WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); - WS_Reset(vc->bereq->ws); - WS_Reset(vc->beresp->ws); LOCK(&vbemtx); VSL_stats->backend_recycle++; TAILQ_INSERT_HEAD(&vc->backend->connlist, vc, list); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-03 19:32:21 UTC (rev 1631) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-03 20:38:38 UTC (rev 1632) @@ -260,8 +260,10 @@ char *b; int cls; int body = 1; /* XXX */ - struct http *hp; + struct http *hp, *hp2; struct storage *st; + struct bereq *bereq; + int len; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); @@ -275,20 +277,23 @@ if (vc == NULL) return (1); - http_ClrHeader(vc->bereq); - vc->bereq->logtag = HTTP_Tx; - http_GetReq(w, vc->fd, vc->bereq, sp->http); - http_FilterHeader(w, vc->fd, vc->bereq, sp->http, HTTPH_R_FETCH); - http_PrintfHeader(w, vc->fd, vc->bereq, "X-Varnish: %u", sp->xid); - http_PrintfHeader(w, vc->fd, vc->bereq, + bereq = vbe_new_bereq(); + AN(bereq); + hp = bereq->http; + hp->logtag = HTTP_Tx; + + http_GetReq(w, vc->fd, hp, sp->http); + http_FilterHeader(w, vc->fd, hp, sp->http, HTTPH_R_FETCH); + http_PrintfHeader(w, vc->fd, hp, "X-Varnish: %u", sp->xid); + http_PrintfHeader(w, vc->fd, hp, "X-Forwarded-for: %s", sp->addr); - if (!http_GetHdr(vc->bereq, H_Host, &b)) { - http_PrintfHeader(w, vc->fd, vc->bereq, "Host: %s", + if (!http_GetHdr(hp, H_Host, &b)) { + http_PrintfHeader(w, vc->fd, hp, "Host: %s", sp->backend->hostname); } WRK_Reset(w, &vc->fd); - http_Write(w, vc->bereq, 0); + http_Write(w, hp, 0); if (WRK_Flush(w)) { /* XXX: cleanup */ return (1); @@ -298,11 +303,11 @@ CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); - if (http_RecvHead(vc->bereq, vc->fd)) { + if (http_RecvHead(hp, vc->fd)) { /* XXX: cleanup */ return (1); } - if (http_DissectResponse(sp->wrk, vc->bereq, vc->fd)) { + if (http_DissectResponse(sp->wrk, hp, vc->fd)) { /* XXX: cleanup */ return (1); } @@ -315,23 +320,31 @@ assert(sp->obj->busy != 0); - if (http_GetHdr(vc->bereq, H_Last_Modified, &b)) + if (http_GetHdr(hp, H_Last_Modified, &b)) sp->obj->last_modified = TIM_parse(b); - hp = vc->beresp; - http_ClrHeader(hp); - hp->logtag = HTTP_Obj; - http_CopyResp(sp->wrk, sp->fd, hp, vc->bereq); - http_FilterHeader(sp->wrk, sp->fd, hp, vc->bereq, HTTPH_A_INS); + /* Filter into object */ + hp2 = &sp->obj->http; + len = hp->rx_e - hp->rx_s; + len += 256; /* margin for content-length etc */ + b = malloc(len); + AN(b); + http_Setup(hp2, b, len); + + hp2->logtag = HTTP_Obj; + http_CopyResp(sp->wrk, sp->fd, hp2, hp); + http_FilterHeader(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS); + http_CopyHome(hp2); + if (body) { - if (http_GetHdr(vc->bereq, H_Content_Length, &b)) - cls = fetch_straight(sp, vc->fd, vc->bereq, b); - else if (http_HdrIs(vc->bereq, H_Transfer_Encoding, "chunked")) - cls = fetch_chunked(sp, vc->fd, vc->bereq); + if (http_GetHdr(hp, H_Content_Length, &b)) + cls = fetch_straight(sp, vc->fd, hp, b); + else if (http_HdrIs(hp, H_Transfer_Encoding, "chunked")) + cls = fetch_chunked(sp, vc->fd, hp); else - cls = fetch_eof(sp, vc->fd, vc->bereq); - http_PrintfHeader(sp->wrk, sp->fd, hp, + cls = fetch_eof(sp, vc->fd, hp); + http_PrintfHeader(sp->wrk, sp->fd, hp2, "Content-Length: %u", sp->obj->len); } else cls = 0; @@ -357,15 +370,14 @@ assert(uu == sp->obj->len); } - http_CopyHttp(&sp->obj->http, hp); - - if (http_GetHdr(vc->bereq, H_Connection, &b) && !strcasecmp(b, "close")) + if (http_GetHdr(hp, H_Connection, &b) && !strcasecmp(b, "close")) cls = 1; if (cls) VBE_ClosedFd(sp->wrk, vc, 0); else VBE_RecycleFd(sp->wrk, vc); + vbe_free_bereq(bereq); return (0); } Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-03 19:32:21 UTC (rev 1631) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-03 20:38:38 UTC (rev 1632) @@ -678,46 +678,6 @@ return (i); } -/*-------------------------------------------------------------------- - * Copy HTTP headers into malloc'ed space. - */ - -void -http_CopyHttp(struct http *to, struct http *fm) -{ - unsigned u, l; - char *p; - - CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); - l = 0; - for (u = 0; u < fm->nhd; u++) { - if (fm->hd[u].b == NULL) - continue; - AN(fm->hd[u].e); - l += (fm->hd[u].e - fm->hd[u].b) + 1; - } - p = malloc(l); - XXXAN(p); - WS_Init(to->ws, p, l); - WS_Reserve(to->ws, 0); - for (u = 0; u < fm->nhd; u++) { - if (fm->hd[u].b == NULL) - continue; - AN(fm->hd[u].e); - assert(*fm->hd[u].e == '\0'); - l = fm->hd[u].e - fm->hd[u].b; - assert(l == strlen(fm->hd[u].b)); - memcpy(p, fm->hd[u].b, l); - to->hd[u].b = p; - to->hd[u].e = p + l; - *to->hd[u].e = '\0'; - p += l + 1; - } - /* XXX: Leave to->ws reserved for now */ - to->nhd = fm->nhd; -} - /*--------------------------------------------------------------------*/ static void @@ -834,6 +794,30 @@ } } +/*-------------------------------------------------------------------- + * This function copies any header fields which reference foreign + * storage into our own WS. + */ + +void +http_CopyHome(struct http *hp) +{ + unsigned u, l; + char *p; + + for (u = 0; u < hp->nhd; u++) { + if (hp->hd[u].b == NULL) + continue; + if (hp->hd[u].b >= hp->ws->s && hp->hd[u].e <= hp->ws->e) + continue; + l = hp->hd[u].e - hp->hd[u].b; + p = WS_Alloc(hp->ws, l + 1); + memcpy(p, hp->hd[u].b, l + 1); + hp->hd[u].b = p; + hp->hd[u].e = p + l; + } +} + /*--------------------------------------------------------------------*/ void Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-03 19:32:21 UTC (rev 1631) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-03 20:38:38 UTC (rev 1632) @@ -78,7 +78,8 @@ char *b, *e; struct worker *w; struct pollfd fds[2]; - char wsspc[8192]; + struct bereq *bereq; + struct http *hp; int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -88,19 +89,21 @@ vc = VBE_GetFd(sp); if (vc == NULL) return; - w->bereq->logtag = HTTP_Tx; - http_Setup(w->bereq, wsspc, sizeof wsspc); + bereq = vbe_new_bereq(); + AN(bereq); + hp = bereq->http; + hp->logtag = HTTP_Tx; - http_CopyReq(w, vc->fd, w->bereq, sp->http); - http_FilterHeader(w, vc->fd, w->bereq, sp->http, HTTPH_R_PIPE); - http_PrintfHeader(w, vc->fd, w->bereq, "X-Varnish: %u", sp->xid); - http_PrintfHeader(w, vc->fd, w->bereq, + http_CopyReq(w, vc->fd, hp, sp->http); + http_FilterHeader(w, vc->fd, hp, sp->http, HTTPH_R_PIPE); + http_PrintfHeader(w, vc->fd, hp, "X-Varnish: %u", sp->xid); + http_PrintfHeader(w, vc->fd, hp, "X-Forwarded-for: %s", sp->addr); /* XXX: does this belong in VCL ? */ - if (!http_GetHdr(w->bereq, H_Host, &b)) { - http_PrintfHeader(w, vc->fd, w->bereq, "Host: %s", + if (!http_GetHdr(hp, H_Host, &b)) { + http_PrintfHeader(w, vc->fd, hp, "Host: %s", sp->backend->hostname); } @@ -110,7 +113,7 @@ INCOMPL(); WRK_Reset(w, &vc->fd); - http_Write(w, w->bereq, 0); + http_Write(w, hp, 0); if (http_GetTail(sp->http, 0, &b, &e) && b != e) WRK_Write(w, b, e - b); @@ -121,6 +124,10 @@ return; } + vbe_free_bereq(bereq); + bereq = NULL; + hp = NULL; + clock_gettime(CLOCK_REALTIME, &sp->t_resp); memset(fds, 0, sizeof fds); From phk at projects.linpro.no Tue Jul 3 20:49:43 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Jul 2007 22:49:43 +0200 (CEST) Subject: r1633 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703204943.02D651EC030@projects.linpro.no> Author: phk Date: 2007-07-03 22:49:42 +0200 (Tue, 03 Jul 2007) New Revision: 1633 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_pipe.c Log: Move VCL_pipe_method() processing into cache_center.c where it belongs. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 20:38:38 UTC (rev 1632) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 20:49:42 UTC (rev 1633) @@ -438,7 +438,7 @@ #undef HTTPH /* cache_pipe.c */ -void PipeSession(struct sess *sp); +void PipeSession(struct sess *sp, struct bereq *bereq); /* cache_pool.c */ void WRK_Init(void); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 20:38:38 UTC (rev 1632) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 20:49:42 UTC (rev 1633) @@ -600,9 +600,34 @@ static int cnt_pipe(struct sess *sp) { + struct bereq *bereq; + struct http *hp; + char *b; sp->wrk->acct.pipe++; - PipeSession(sp); + + bereq = vbe_new_bereq(); + XXXAN(bereq); + hp = bereq->http; + hp->logtag = HTTP_Tx; + + http_CopyReq(sp->wrk, sp->fd, hp, sp->http); + http_FilterHeader(sp->wrk, sp->fd, hp, sp->http, HTTPH_R_PIPE); + http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); + http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Forwarded-for: %s", sp->addr); + + /* XXX: does this belong in VCL ? */ + if (!http_GetHdr(hp, H_Host, &b)) { + http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s", + sp->backend->hostname); + } + + VCL_pipe_method(sp); + + if (sp->handling == VCL_RET_ERROR) + INCOMPL(); + + PipeSession(sp, bereq); sp->step = STP_DONE; return (0); } Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-03 20:38:38 UTC (rev 1632) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-03 20:49:42 UTC (rev 1633) @@ -72,14 +72,12 @@ } void -PipeSession(struct sess *sp) +PipeSession(struct sess *sp, struct bereq *bereq) { struct vbe_conn *vc; char *b, *e; struct worker *w; struct pollfd fds[2]; - struct bereq *bereq; - struct http *hp; int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -90,30 +88,8 @@ if (vc == NULL) return; - bereq = vbe_new_bereq(); - AN(bereq); - hp = bereq->http; - hp->logtag = HTTP_Tx; - - http_CopyReq(w, vc->fd, hp, sp->http); - http_FilterHeader(w, vc->fd, hp, sp->http, HTTPH_R_PIPE); - http_PrintfHeader(w, vc->fd, hp, "X-Varnish: %u", sp->xid); - http_PrintfHeader(w, vc->fd, hp, - "X-Forwarded-for: %s", sp->addr); - - /* XXX: does this belong in VCL ? */ - if (!http_GetHdr(hp, H_Host, &b)) { - http_PrintfHeader(w, vc->fd, hp, "Host: %s", - sp->backend->hostname); - } - - VCL_pipe_method(sp); - - if (sp->handling == VCL_RET_ERROR) - INCOMPL(); - WRK_Reset(w, &vc->fd); - http_Write(w, hp, 0); + http_Write(w, bereq->http, 0); if (http_GetTail(sp->http, 0, &b, &e) && b != e) WRK_Write(w, b, e - b); @@ -126,7 +102,6 @@ vbe_free_bereq(bereq); bereq = NULL; - hp = NULL; clock_gettime(CLOCK_REALTIME, &sp->t_resp); From phk at projects.linpro.no Tue Jul 3 20:59:27 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Jul 2007 22:59:27 +0200 (CEST) Subject: r1634 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703205927.6EBEE1EC37C@projects.linpro.no> Author: phk Date: 2007-07-03 22:59:27 +0200 (Tue, 03 Jul 2007) New Revision: 1634 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_fetch.c Log: Move bereq backwards into cache_center.c for Fetch cases (Pass, Miss) Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 20:49:42 UTC (rev 1633) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 20:59:27 UTC (rev 1634) @@ -318,6 +318,7 @@ TAILQ_ENTRY(sess) list; struct backend *backend; + struct bereq *bereq; struct object *obj; struct VCL_conf *vcl; Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 20:49:42 UTC (rev 1633) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 20:59:27 UTC (rev 1634) @@ -278,8 +278,32 @@ static int cnt_fetch(struct sess *sp) { + struct bereq *bereq; + struct http *hp; + char *b; + int i; - if (Fetch(sp)) { + bereq = vbe_new_bereq(); + AN(bereq); + hp = bereq->http; + hp->logtag = HTTP_Tx; + + http_GetReq(sp->wrk, sp->fd, hp, sp->http); + http_FilterHeader(sp->wrk, sp->fd, hp, sp->http, HTTPH_R_FETCH); + http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); + http_PrintfHeader(sp->wrk, sp->fd, hp, + "X-Forwarded-for: %s", sp->addr); + if (!http_GetHdr(hp, H_Host, &b)) { + http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s", + sp->backend->hostname); + } + sp->bereq = bereq; + + i = Fetch(sp); + vbe_free_bereq(sp->bereq); + sp->bereq = NULL; + + if (i) { SYN_ErrorPage(sp, 503, "Error talking to backend", 30); } else { RFC2616_cache_policy(sp, &sp->obj->http); /* XXX -> VCL */ Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-03 20:49:42 UTC (rev 1633) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-03 20:59:27 UTC (rev 1634) @@ -270,32 +270,19 @@ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); assert(sp->obj->busy != 0); w = sp->wrk; + bereq = sp->bereq; + hp = bereq->http; sp->obj->xid = sp->xid; vc = VBE_GetFd(sp); if (vc == NULL) return (1); - - bereq = vbe_new_bereq(); - AN(bereq); - hp = bereq->http; - hp->logtag = HTTP_Tx; - - http_GetReq(w, vc->fd, hp, sp->http); - http_FilterHeader(w, vc->fd, hp, sp->http, HTTPH_R_FETCH); - http_PrintfHeader(w, vc->fd, hp, "X-Varnish: %u", sp->xid); - http_PrintfHeader(w, vc->fd, hp, - "X-Forwarded-for: %s", sp->addr); - if (!http_GetHdr(hp, H_Host, &b)) { - http_PrintfHeader(w, vc->fd, hp, "Host: %s", - sp->backend->hostname); - } - WRK_Reset(w, &vc->fd); http_Write(w, hp, 0); if (WRK_Flush(w)) { /* XXX: cleanup */ + return (1); } @@ -377,7 +364,6 @@ VBE_ClosedFd(sp->wrk, vc, 0); else VBE_RecycleFd(sp->wrk, vc); - vbe_free_bereq(bereq); return (0); } From phk at projects.linpro.no Tue Jul 3 21:31:25 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Jul 2007 23:31:25 +0200 (CEST) Subject: r1635 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703213125.ACB991EC030@projects.linpro.no> Author: phk Date: 2007-07-03 23:31:25 +0200 (Tue, 03 Jul 2007) New Revision: 1635 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_response.c Log: Fix the SHMlogging of HTTP protocol fields to happen when they cross wires, rather than when they get manipulated in memory. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 20:59:27 UTC (rev 1634) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 21:31:25 UTC (rev 1635) @@ -407,10 +407,10 @@ void HTTP_Init(void); void http_ClrHeader(struct http *to); unsigned http_Write(struct worker *w, struct http *hp, int resp); -void http_GetReq(struct worker *w, int fd, struct http *to, struct http *fm); -void http_CopyReq(struct worker *w, int fd, struct http *to, struct http *fm); -void http_CopyResp(struct worker *w, int fd, struct http *to, struct http *fm); -void http_SetResp(struct worker *w, int fd, struct http *to, const char *proto, const char *status, const char *response); +void http_GetReq(struct http *to, struct http *fm); +void http_CopyReq(struct http *to, struct http *fm); +void http_CopyResp(struct http *to, struct http *fm); +void http_SetResp(struct http *to, const char *proto, const char *status, const char *response); void http_FilterHeader(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how); void http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol); void http_PutStatus(struct worker *w, int fd, struct http *to, int status); @@ -431,7 +431,7 @@ int http_DissectRequest(struct worker *w, struct http *sp, int fd); int http_DissectResponse(struct worker *w, struct http *sp, int fd); void http_DoConnection(struct sess *sp); -void http_CopyHome(struct http *hp); +void http_CopyHome(struct worker *w, int fd, struct http *hp); #define HTTPH(a, b, c, d, e, f, g) extern char b[]; Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 20:59:27 UTC (rev 1634) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 21:31:25 UTC (rev 1635) @@ -288,7 +288,7 @@ hp = bereq->http; hp->logtag = HTTP_Tx; - http_GetReq(sp->wrk, sp->fd, hp, sp->http); + http_GetReq(hp, sp->http); http_FilterHeader(sp->wrk, sp->fd, hp, sp->http, HTTPH_R_FETCH); http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); http_PrintfHeader(sp->wrk, sp->fd, hp, @@ -635,7 +635,7 @@ hp = bereq->http; hp->logtag = HTTP_Tx; - http_CopyReq(sp->wrk, sp->fd, hp, sp->http); + http_CopyReq(hp, sp->http); http_FilterHeader(sp->wrk, sp->fd, hp, sp->http, HTTPH_R_PIPE); http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Forwarded-for: %s", sp->addr); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-03 20:59:27 UTC (rev 1634) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-03 21:31:25 UTC (rev 1635) @@ -320,9 +320,9 @@ http_Setup(hp2, b, len); hp2->logtag = HTTP_Obj; - http_CopyResp(sp->wrk, sp->fd, hp2, hp); + http_CopyResp(hp2, hp); http_FilterHeader(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS); - http_CopyHome(hp2); + http_CopyHome(sp->wrk, sp->fd, hp2); if (body) { if (http_GetHdr(hp, H_Content_Length, &b)) Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-03 20:59:27 UTC (rev 1634) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-03 21:31:25 UTC (rev 1635) @@ -681,7 +681,7 @@ /*--------------------------------------------------------------------*/ static void -http_seth(struct worker *w, int fd, struct http *to, unsigned n, enum httptag tag, const char *fm) +http_seth(struct http *to, unsigned n, const char *fm) { assert(n < HTTP_HDR_MAX); @@ -689,11 +689,10 @@ to->hd[n].b = (void*)(uintptr_t)fm; to->hd[n].e = (void*)(uintptr_t)strchr(fm, '\0'); to->hdf[n] = 0; - WSLH(w, tag, fd, to, n); } static void -http_copyh(struct worker *w, int fd, struct http *to, struct http *fm, unsigned n, enum httptag tag) +http_copyh(struct http *to, struct http *fm, unsigned n) { assert(n < HTTP_HDR_MAX); @@ -701,56 +700,56 @@ to->hd[n].b = fm->hd[n].b; to->hd[n].e = fm->hd[n].e; to->hdf[n] = fm->hdf[n]; - WSLH(w, tag, fd, to, n); } void -http_GetReq(struct worker *w, int fd, struct http *to, struct http *fm) +http_GetReq(struct http *to, struct http *fm) { CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - http_seth(w, fd, to, HTTP_HDR_REQ, HTTP_T_Request, "GET"); - http_copyh(w, fd, to, fm, HTTP_HDR_URL, HTTP_T_URL); - http_seth(w, fd, to, HTTP_HDR_PROTO, HTTP_T_Protocol, "HTTP/1.1"); + http_seth(to, HTTP_HDR_REQ, "GET"); + http_copyh(to, fm, HTTP_HDR_URL); + http_seth(to, HTTP_HDR_PROTO, "HTTP/1.1"); } void -http_CopyReq(struct worker *w, int fd, struct http *to, struct http *fm) +http_CopyReq(struct http *to, struct http *fm) { CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - http_copyh(w, fd, to, fm, HTTP_HDR_REQ, HTTP_T_Request); - http_copyh(w, fd, to, fm, HTTP_HDR_URL, HTTP_T_URL); + http_copyh(to, fm, HTTP_HDR_REQ); + http_copyh(to, fm, HTTP_HDR_URL); if (params->backend_http11) - http_seth(w, fd, to, HTTP_HDR_PROTO, HTTP_T_Protocol, "HTTP/1.1"); + http_seth(to, HTTP_HDR_PROTO, "HTTP/1.1"); else - http_copyh(w, fd, to, fm, HTTP_HDR_PROTO, HTTP_T_Protocol); + http_copyh(to, fm, HTTP_HDR_PROTO); } void -http_CopyResp(struct worker *w, int fd, struct http *to, struct http *fm) +http_CopyResp(struct http *to, struct http *fm) { CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); if (params->client_http11) - http_seth(w, fd, to, HTTP_HDR_PROTO, HTTP_T_Protocol, "HTTP/1.1"); + http_seth(to, HTTP_HDR_PROTO, "HTTP/1.1"); else - http_copyh(w, fd, to, fm, HTTP_HDR_PROTO, HTTP_T_Protocol); - http_copyh(w, fd, to, fm, HTTP_HDR_STATUS, HTTP_T_Status); - http_copyh(w, fd, to, fm, HTTP_HDR_RESPONSE, HTTP_T_Response); + http_copyh(to, fm, HTTP_HDR_PROTO); + http_copyh(to, fm, HTTP_HDR_STATUS); + http_copyh(to, fm, HTTP_HDR_RESPONSE); } void -http_SetResp(struct worker *w, int fd, struct http *to, const char *proto, const char *status, const char *response) +http_SetResp(struct http *to, const char *proto, const char *status, const char *response) { + CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - http_seth(w, fd, to, HTTP_HDR_PROTO, HTTP_T_Protocol, proto); - http_seth(w, fd, to, HTTP_HDR_STATUS, HTTP_T_Status, status); - http_seth(w, fd, to, HTTP_HDR_RESPONSE, HTTP_T_Response, response); + http_seth(to, HTTP_HDR_PROTO, proto); + http_seth(to, HTTP_HDR_STATUS, status); + http_seth(to, HTTP_HDR_RESPONSE, response); } static void @@ -764,7 +763,6 @@ if (to->nhd < HTTP_HDR_MAX) { to->hd[to->nhd].b = fm->hd[n].b; to->hd[to->nhd].e = fm->hd[n].e; - WSLH(w, HTTP_T_Header, fd, to, to->nhd); to->nhd++; } else { VSL_stats->losthdr++; @@ -800,7 +798,7 @@ */ void -http_CopyHome(struct http *hp) +http_CopyHome(struct worker *w, int fd, struct http *hp) { unsigned u, l; char *p; @@ -808,6 +806,20 @@ for (u = 0; u < hp->nhd; u++) { if (hp->hd[u].b == NULL) continue; + switch (u) { + case HTTP_HDR_PROTO: + WSLH(w, HTTP_T_Protocol, fd, hp, u); + break; + case HTTP_HDR_STATUS: + WSLH(w, HTTP_T_Status, fd, hp, u); + break; + case HTTP_HDR_RESPONSE: + WSLH(w, HTTP_T_Response, fd, hp, u); + break; + default: + WSLH(w, HTTP_T_Header, fd, hp, u); + break; + } if (hp->hd[u].b >= hp->ws->s && hp->hd[u].e <= hp->ws->e) continue; l = hp->hd[u].e - hp->hd[u].b; @@ -842,7 +854,7 @@ WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", hdr); return; } - http_seth(w, fd, to, to->nhd++, HTTP_T_Header, hdr); + http_seth(to, to->nhd++, hdr); } /*--------------------------------------------------------------------*/ @@ -867,8 +879,9 @@ http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol) { + (void)w; /* should be used to report losthdr */ + (void)fd; /* should be used to report losthdr */ http_PutField(to, HTTP_HDR_PROTO, protocol); - WSLH(w, HTTP_T_Protocol, fd, to, HTTP_HDR_PROTO); } void @@ -876,18 +889,20 @@ { char stat[4]; + (void)w; /* should be used to report losthdr */ + (void)fd; /* should be used to report losthdr */ assert(status >= 0 && status <= 999); sprintf(stat, "%d", status); http_PutField(to, HTTP_HDR_STATUS, stat); - WSLH(w, HTTP_T_Status, fd, to, HTTP_HDR_STATUS); } void http_PutResponse(struct worker *w, int fd, struct http *to, const char *response) { + (void)w; /* should be used to report losthdr */ + (void)fd; /* should be used to report losthdr */ http_PutField(to, HTTP_HDR_RESPONSE, response); - WSLH(w, HTTP_T_Response, fd, to, HTTP_HDR_RESPONSE); } void @@ -909,7 +924,6 @@ to->hd[to->nhd].b = to->ws->f; to->hd[to->nhd].e = to->ws->f + n; WS_Release(to->ws, n + 1); - WSLH(w, HTTP_T_Header, fd, to, to->nhd); to->nhd++; } } @@ -924,18 +938,25 @@ if (resp) { AN(hp->hd[HTTP_HDR_STATUS].b); l = WRK_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " "); + WSLH(w, HTTP_T_Protocol, *w->wfd, hp, HTTP_HDR_PROTO); l += WRK_WriteH(w, &hp->hd[HTTP_HDR_STATUS], " "); + WSLH(w, HTTP_T_Status, *w->wfd, hp, HTTP_HDR_STATUS); l += WRK_WriteH(w, &hp->hd[HTTP_HDR_RESPONSE], "\r\n"); + WSLH(w, HTTP_T_Response, *w->wfd, hp, HTTP_HDR_RESPONSE); } else { AN(hp->hd[HTTP_HDR_URL].b); l = WRK_WriteH(w, &hp->hd[HTTP_HDR_REQ], " "); + WSLH(w, HTTP_T_Request, *w->wfd, hp, HTTP_HDR_REQ); l += WRK_WriteH(w, &hp->hd[HTTP_HDR_URL], " "); + WSLH(w, HTTP_T_URL, *w->wfd, hp, HTTP_HDR_URL); l += WRK_WriteH(w, &hp->hd[HTTP_HDR_PROTO], "\r\n"); + WSLH(w, HTTP_T_Protocol, *w->wfd, hp, HTTP_HDR_PROTO); } for (u = HTTP_HDR_FIRST; u < hp->nhd; u++) { AN(hp->hd[u].b); AN(hp->hd[u].e); l += WRK_WriteH(w, &hp->hd[u], "\r\n"); + WSLH(w, HTTP_T_Header, *w->wfd, hp, u); } l += WRK_Write(w, "\r\n", -1); return (l); Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-03 20:59:27 UTC (rev 1634) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-03 21:31:25 UTC (rev 1635) @@ -73,7 +73,7 @@ http_ClrHeader(sp->http); sp->http->logtag = HTTP_Tx; - http_SetResp(sp->wrk, sp->fd, sp->http, + http_SetResp(sp->http, "HTTP/1.1", "304", "Not Modified"); TIM_format(sp->t_req.tv_sec, lm); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Date: %s", lm); @@ -129,7 +129,7 @@ http_ClrHeader(sp->http); sp->http->logtag = HTTP_Tx; - http_CopyResp(sp->wrk, sp->fd, sp->http, &sp->obj->http); + http_CopyResp(sp->http, &sp->obj->http); http_FilterHeader(sp->wrk, sp->fd, sp->http, &sp->obj->http, HTTPH_A_DELIVER); if (sp->xid != sp->obj->xid) http_PrintfHeader(sp->wrk, sp->fd, sp->http, From phk at projects.linpro.no Tue Jul 3 21:38:32 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Jul 2007 23:38:32 +0200 (CEST) Subject: r1636 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703213832.D68581EC37C@projects.linpro.no> Author: phk Date: 2007-07-03 23:38:32 +0200 (Tue, 03 Jul 2007) New Revision: 1636 Modified: trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_ws.c Log: Do correct LostHeader processing on WS_Alloc() failure Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-03 21:31:25 UTC (rev 1635) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-03 21:38:32 UTC (rev 1636) @@ -801,6 +801,7 @@ http_CopyHome(struct worker *w, int fd, struct http *hp) { unsigned u, l; + enum httptag htt; char *p; for (u = 0; u < hp->nhd; u++) { @@ -808,25 +809,34 @@ continue; switch (u) { case HTTP_HDR_PROTO: - WSLH(w, HTTP_T_Protocol, fd, hp, u); + htt = HTTP_T_Protocol; break; case HTTP_HDR_STATUS: - WSLH(w, HTTP_T_Status, fd, hp, u); + htt = HTTP_T_Status; break; case HTTP_HDR_RESPONSE: - WSLH(w, HTTP_T_Response, fd, hp, u); + htt = HTTP_T_Response; break; default: - WSLH(w, HTTP_T_Header, fd, hp, u); + htt = HTTP_T_Header; break; } - if (hp->hd[u].b >= hp->ws->s && hp->hd[u].e <= hp->ws->e) + if (hp->hd[u].b >= hp->ws->s && hp->hd[u].e <= hp->ws->e) { + WSLH(w, htt, fd, hp, u); continue; + } l = hp->hd[u].e - hp->hd[u].b; p = WS_Alloc(hp->ws, l + 1); - memcpy(p, hp->hd[u].b, l + 1); - hp->hd[u].b = p; - hp->hd[u].e = p + l; + if (p != NULL) { + WSLH(w, htt, fd, hp, u); + memcpy(p, hp->hd[u].b, l + 1); + hp->hd[u].b = p; + hp->hd[u].e = p + l; + } else { + WSLH(w, HTTP_T_LostHeader, fd, hp, u); + hp->hd[u].b = NULL; + hp->hd[u].e = NULL; + } } } @@ -860,7 +870,7 @@ /*--------------------------------------------------------------------*/ static void -http_PutField(struct http *to, int field, const char *string) +http_PutField(struct worker *w, int fd, struct http *to, int field, const char *string) { const char *e; char *p; @@ -870,18 +880,22 @@ e = strchr(string, '\0'); l = (e - string); p = WS_Alloc(to->ws, l + 1); - memcpy(p, string, l + 1); - to->hd[field].b = p; - to->hd[field].e = p + l; + if (p == NULL) { + WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", string); + to->hd[field].b = NULL; + to->hd[field].e = NULL; + } else { + memcpy(p, string, l + 1); + to->hd[field].b = p; + to->hd[field].e = p + l; + } } void http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol) { - (void)w; /* should be used to report losthdr */ - (void)fd; /* should be used to report losthdr */ - http_PutField(to, HTTP_HDR_PROTO, protocol); + http_PutField(w, fd, to, HTTP_HDR_PROTO, protocol); } void @@ -889,20 +903,16 @@ { char stat[4]; - (void)w; /* should be used to report losthdr */ - (void)fd; /* should be used to report losthdr */ assert(status >= 0 && status <= 999); sprintf(stat, "%d", status); - http_PutField(to, HTTP_HDR_STATUS, stat); + http_PutField(w, fd, to, HTTP_HDR_STATUS, stat); } void http_PutResponse(struct worker *w, int fd, struct http *to, const char *response) { - (void)w; /* should be used to report losthdr */ - (void)fd; /* should be used to report losthdr */ - http_PutField(to, HTTP_HDR_RESPONSE, response); + http_PutField(w, fd, to, HTTP_HDR_RESPONSE, response); } void Modified: trunk/varnish-cache/bin/varnishd/cache_ws.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ws.c 2007-07-03 21:31:25 UTC (rev 1635) +++ trunk/varnish-cache/bin/varnishd/cache_ws.c 2007-07-03 21:38:32 UTC (rev 1636) @@ -89,7 +89,8 @@ WS_Assert(ws); assert(ws->r == NULL); - xxxassert(ws->f + bytes <= ws->e); + if (ws->f + bytes > ws->e) + return(NULL); r = ws->f; ws->f += bytes; return (r); From phk at projects.linpro.no Tue Jul 3 21:40:14 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Jul 2007 23:40:14 +0200 (CEST) Subject: r1637 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703214014.492E91EC030@projects.linpro.no> Author: phk Date: 2007-07-03 23:40:14 +0200 (Tue, 03 Jul 2007) New Revision: 1637 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_pipe.c Log: Use sp->bereq for handover to PipeSession Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 21:38:32 UTC (rev 1636) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 21:40:14 UTC (rev 1637) @@ -439,7 +439,7 @@ #undef HTTPH /* cache_pipe.c */ -void PipeSession(struct sess *sp, struct bereq *bereq); +void PipeSession(struct sess *sp); /* cache_pool.c */ void WRK_Init(void); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 21:38:32 UTC (rev 1636) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 21:40:14 UTC (rev 1637) @@ -651,7 +651,8 @@ if (sp->handling == VCL_RET_ERROR) INCOMPL(); - PipeSession(sp, bereq); + sp->bereq = bereq; + PipeSession(sp); sp->step = STP_DONE; return (0); } Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-03 21:38:32 UTC (rev 1636) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-03 21:40:14 UTC (rev 1637) @@ -72,17 +72,20 @@ } void -PipeSession(struct sess *sp, struct bereq *bereq) +PipeSession(struct sess *sp) { struct vbe_conn *vc; char *b, *e; struct worker *w; + struct bereq *bereq; struct pollfd fds[2]; int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); w = sp->wrk; + bereq = sp->bereq; + sp->bereq = NULL; vc = VBE_GetFd(sp); if (vc == NULL) From phk at projects.linpro.no Tue Jul 3 21:50:32 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Jul 2007 23:50:32 +0200 (CEST) Subject: r1638 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703215032.1D98A1EC475@projects.linpro.no> Author: phk Date: 2007-07-03 23:50:31 +0200 (Tue, 03 Jul 2007) New Revision: 1638 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_response.c Log: Move the header-filtering another step backwards, so it comes before the VCL methods vcl_miss and vcl_pass. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 21:40:14 UTC (rev 1637) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 21:50:31 UTC (rev 1638) @@ -411,7 +411,8 @@ void http_CopyReq(struct http *to, struct http *fm); void http_CopyResp(struct http *to, struct http *fm); void http_SetResp(struct http *to, const char *proto, const char *status, const char *response); -void http_FilterHeader(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how); +void http_FilterFields(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how); +void http_FilterHeader(struct sess *sp, unsigned how); void http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol); void http_PutStatus(struct worker *w, int fd, struct http *to, int status); void http_PutResponse(struct worker *w, int fd, struct http *to, const char *response); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 21:40:14 UTC (rev 1637) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 21:50:31 UTC (rev 1638) @@ -278,27 +278,9 @@ static int cnt_fetch(struct sess *sp) { - struct bereq *bereq; - struct http *hp; - char *b; int i; - bereq = vbe_new_bereq(); - AN(bereq); - hp = bereq->http; - hp->logtag = HTTP_Tx; - - http_GetReq(hp, sp->http); - http_FilterHeader(sp->wrk, sp->fd, hp, sp->http, HTTPH_R_FETCH); - http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); - http_PrintfHeader(sp->wrk, sp->fd, hp, - "X-Forwarded-for: %s", sp->addr); - if (!http_GetHdr(hp, H_Host, &b)) { - http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s", - sp->backend->hostname); - } - sp->bereq = bereq; - + AN(sp->bereq); i = Fetch(sp); vbe_free_bereq(sp->bereq); sp->bereq = NULL; @@ -527,6 +509,7 @@ cnt_miss(struct sess *sp) { + http_FilterHeader(sp, HTTPH_R_FETCH); VCL_miss_method(sp); if (sp->handling == VCL_RET_ERROR) { sp->obj->cacheable = 0; @@ -542,6 +525,8 @@ HSH_Deref(sp->obj); sp->obj = NULL; sp->step = STP_PASS; + vbe_free_bereq(sp->bereq); + sp->bereq = NULL; return (0); } if (sp->handling == VCL_RET_FETCH) { @@ -583,6 +568,8 @@ AZ(sp->obj); + http_FilterHeader(sp, HTTPH_R_PASS); + VCL_pass_method(sp); if (sp->handling == VCL_RET_ERROR) { sp->step = STP_ERROR; @@ -624,34 +611,15 @@ static int cnt_pipe(struct sess *sp) { - struct bereq *bereq; - struct http *hp; - char *b; sp->wrk->acct.pipe++; + http_FilterHeader(sp, HTTPH_R_PIPE); - bereq = vbe_new_bereq(); - XXXAN(bereq); - hp = bereq->http; - hp->logtag = HTTP_Tx; - - http_CopyReq(hp, sp->http); - http_FilterHeader(sp->wrk, sp->fd, hp, sp->http, HTTPH_R_PIPE); - http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); - http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Forwarded-for: %s", sp->addr); - - /* XXX: does this belong in VCL ? */ - if (!http_GetHdr(hp, H_Host, &b)) { - http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s", - sp->backend->hostname); - } - VCL_pipe_method(sp); if (sp->handling == VCL_RET_ERROR) INCOMPL(); - sp->bereq = bereq; PipeSession(sp); sp->step = STP_DONE; return (0); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-03 21:40:14 UTC (rev 1637) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-03 21:50:31 UTC (rev 1638) @@ -321,7 +321,7 @@ hp2->logtag = HTTP_Obj; http_CopyResp(hp2, hp); - http_FilterHeader(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS); + http_FilterFields(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS); http_CopyHome(sp->wrk, sp->fd, hp2); if (body) { Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-03 21:40:14 UTC (rev 1637) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-03 21:50:31 UTC (rev 1638) @@ -773,7 +773,7 @@ /*--------------------------------------------------------------------*/ void -http_FilterHeader(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how) +http_FilterFields(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how) { unsigned u; @@ -792,6 +792,32 @@ } } +/*--------------------------------------------------------------------*/ + +void +http_FilterHeader(struct sess *sp, unsigned how) +{ + struct bereq *bereq; + struct http *hp; + char *b; + + bereq = vbe_new_bereq(); + AN(bereq); + hp = bereq->http; + hp->logtag = HTTP_Tx; + + http_GetReq(hp, sp->http); + http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how); + http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); + http_PrintfHeader(sp->wrk, sp->fd, hp, + "X-Forwarded-for: %s", sp->addr); + if (!http_GetHdr(hp, H_Host, &b)) { + http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s", + sp->backend->hostname); + } + sp->bereq = bereq; +} + /*-------------------------------------------------------------------- * This function copies any header fields which reference foreign * storage into our own WS. Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-03 21:40:14 UTC (rev 1637) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-03 21:50:31 UTC (rev 1638) @@ -130,7 +130,8 @@ http_ClrHeader(sp->http); sp->http->logtag = HTTP_Tx; http_CopyResp(sp->http, &sp->obj->http); - http_FilterHeader(sp->wrk, sp->fd, sp->http, &sp->obj->http, HTTPH_A_DELIVER); + http_FilterFields(sp->wrk, sp->fd, sp->http, &sp->obj->http, + HTTPH_A_DELIVER); if (sp->xid != sp->obj->xid) http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u %u", sp->xid, sp->obj->xid); From phk at projects.linpro.no Tue Jul 3 22:00:26 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 4 Jul 2007 00:00:26 +0200 (CEST) Subject: r1639 - trunk/varnish-cache/bin/varnishd Message-ID: <20070703220026.3D6611EC37C@projects.linpro.no> Author: phk Date: 2007-07-04 00:00:26 +0200 (Wed, 04 Jul 2007) New Revision: 1639 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/flint.lnt Log: Run FlexeLint to catch fluff. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 21:50:31 UTC (rev 1638) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 22:00:26 UTC (rev 1639) @@ -166,10 +166,6 @@ struct srcaddr *srcaddr; struct acct acct; - /* Backend connection space */ - struct http bereq[1]; - struct http beresp[1]; - unsigned char *wlp, *wle; unsigned wlr; unsigned char wlog[WLOGSPACE]; @@ -407,8 +403,6 @@ void HTTP_Init(void); void http_ClrHeader(struct http *to); unsigned http_Write(struct worker *w, struct http *hp, int resp); -void http_GetReq(struct http *to, struct http *fm); -void http_CopyReq(struct http *to, struct http *fm); void http_CopyResp(struct http *to, struct http *fm); void http_SetResp(struct http *to, const char *proto, const char *status, const char *response); void http_FilterFields(struct worker *w, int fd, struct http *to, struct http *fm, unsigned how); Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-03 21:50:31 UTC (rev 1638) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-03 22:00:26 UTC (rev 1639) @@ -702,8 +702,8 @@ to->hdf[n] = fm->hdf[n]; } -void -http_GetReq(struct http *to, struct http *fm) +static void +http_getreq(struct http *to, struct http *fm) { CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); @@ -714,21 +714,6 @@ } void -http_CopyReq(struct http *to, struct http *fm) -{ - - CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); - CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - http_copyh(to, fm, HTTP_HDR_REQ); - http_copyh(to, fm, HTTP_HDR_URL); - if (params->backend_http11) - http_seth(to, HTTP_HDR_PROTO, "HTTP/1.1"); - else - http_copyh(to, fm, HTTP_HDR_PROTO); -} - - -void http_CopyResp(struct http *to, struct http *fm) { @@ -806,7 +791,7 @@ hp = bereq->http; hp->logtag = HTTP_Tx; - http_GetReq(hp, sp->http); + http_getreq(hp, sp->http); http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how); http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); http_PrintfHeader(sp->wrk, sp->fd, hp, Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2007-07-03 21:50:31 UTC (rev 1638) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2007-07-03 22:00:26 UTC (rev 1639) @@ -41,8 +41,8 @@ // cache_center.c -efunc(525, CNT_Session) // Negative indentation from line --efunc(525, http_FilterHeader) // Negative indentation from line --efunc(539, http_FilterHeader) // Positive indentation from line +-efunc(525, http_FilterFields) // Negative indentation from line +-efunc(539, http_FilterFields) // Positive indentation from line // cache_vcl.c -efunc(525, vcl_handlingname) // Negative indentation from line From phk at projects.linpro.no Tue Jul 3 22:24:09 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 4 Jul 2007 00:24:09 +0200 (CEST) Subject: r1640 - in trunk/varnish-cache: bin/varnishd lib/libvcl Message-ID: <20070703222409.E3C441EC37C@projects.linpro.no> Author: phk Date: 2007-07-04 00:24:09 +0200 (Wed, 04 Jul 2007) New Revision: 1640 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_response.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: Implement vcl_deliver() and change variable visibility to match. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 22:00:26 UTC (rev 1639) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-03 22:24:09 UTC (rev 1640) @@ -471,6 +471,7 @@ #endif /* cache_response.c */ +void RES_BuildHttp(struct sess *sp); void RES_Error(struct sess *sp, int code, const char *reason); void RES_WriteObj(struct sess *sp); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 22:00:26 UTC (rev 1639) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-03 22:24:09 UTC (rev 1640) @@ -119,7 +119,7 @@ DOT ] DOT vcl_deliver [ DOT shape=record -DOT label="vcl_deliver()|req.\nresp." +DOT label="vcl_deliver()|resp." DOT ] DOT deliver2 [ DOT shape=ellipse @@ -131,12 +131,29 @@ DOT errdeliver [label="ERROR",shape=plaintext] DOT } DOT deliver2 -> DONE [style=bold,color=green,weight=4] + * + * XXX: Ideally we should make the req. available in vcl_deliver() but for + * XXX: reasons of economy we don't, since that allows us to reuse the space + * XXX: in sp->req for the response. + * + * XXX: Rather than allocate two http's and workspaces for all sessions to + * XXX: address this deficiency, we could make the VCL compiler set a flag + * XXX: if req. is used in vcl_deliver(). When the flag is set we would + * XXX: take the memory overhead, for instance by borrowing a struct bereq + * XXX: or similar. + * + * XXX: For now, wait until somebody asks for it. */ static int cnt_deliver(struct sess *sp) { + RES_BuildHttp(sp); + VCL_deliver_method(sp); + if (sp->handling != VCL_RET_DELIVER) + INCOMPL(); + RES_WriteObj(sp); HSH_Deref(sp->obj); sp->obj = NULL; @@ -171,6 +188,7 @@ double dh, dp, da; AZ(sp->obj); + AZ(sp->bereq); sp->backend = NULL; if (sp->vcl != NULL) { if (sp->wrk->vcl != NULL) Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-03 22:00:26 UTC (rev 1639) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-03 22:24:09 UTC (rev 1640) @@ -114,13 +114,9 @@ /*--------------------------------------------------------------------*/ void -RES_WriteObj(struct sess *sp) +RES_BuildHttp(struct sess *sp) { - struct storage *st; - unsigned u = 0; - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - clock_gettime(CLOCK_REALTIME, &sp->t_resp); if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp)) return; @@ -136,12 +132,26 @@ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u %u", sp->xid, sp->obj->xid); else - http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid); + http_PrintfHeader(sp->wrk, sp->fd, sp->http, + "X-Varnish: %u", sp->xid); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %u", sp->obj->age + sp->t_resp.tv_sec - sp->obj->entered); http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish"); if (sp->doclose != NULL) http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); +} + +/*--------------------------------------------------------------------*/ + +void +RES_WriteObj(struct sess *sp) +{ + struct storage *st; + unsigned u = 0; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + + clock_gettime(CLOCK_REALTIME, &sp->t_resp); WRK_Reset(sp->wrk, &sp->fd); sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-03 22:00:26 UTC (rev 1639) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-03 22:24:09 UTC (rev 1640) @@ -483,10 +483,12 @@ vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n"); vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n"); + vsb_cat(sb, "double VRT_r_obj_lastuse(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n"); vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *);\n"); vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n"); vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n"); vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n"); vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *);\n"); + vsb_cat(sb, "double VRT_r_now(struct sess *);\n"); } Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-03 22:00:26 UTC (rev 1639) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-03 22:24:09 UTC (rev 1640) @@ -44,14 +44,14 @@ # Connection related parameters { client.ip RO IP - {recv pipe pass hash miss hit fetch } + {recv pipe pass hash miss hit fetch deliver } } { client.bandwidth # Not implemented yet NO } { server.ip RO IP - {recv pipe pass hash miss hit fetch } + {recv pipe pass hash miss hit fetch deliver } } # Request paramters @@ -103,7 +103,7 @@ # The (possibly) cached object { obj.proto RW STRING - { hit fetch deliver } + { hit fetch } } { obj.status RW INT @@ -115,7 +115,7 @@ } { obj.http. RW HEADER - { hit fetch deliver } + { hit fetch } } { obj.valid @@ -138,22 +138,24 @@ # The response we send back { resp.proto RW STRING - { fetch } + { deliver } } { resp.status RW INT - { fetch } + { deliver } } { resp.response RW STRING - { fetch } + { deliver } } { resp.http. RW HEADER - { fetch } + { deliver } } # Miscellaneous + # XXX: I'm not happy about this one. All times should be relative + # XXX: or delta times in VCL programs, so this shouldn't be needed /phk { now RO TIME {recv pipe pass hash miss hit fetch deliver discard timeout} Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-03 22:00:26 UTC (rev 1639) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-03 22:24:09 UTC (rev 1640) @@ -36,13 +36,13 @@ "VRT_r_client_ip(sp)", NULL, V_RO, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER }, { "server.ip", IP, 9, "VRT_r_server_ip(sp)", NULL, V_RO, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER }, { "req.request", STRING, 11, "VRT_r_req_request(sp)", @@ -108,7 +108,7 @@ "VRT_r_obj_proto(sp)", "VRT_l_obj_proto(sp, ", V_RW, - VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + VCL_MET_HIT | VCL_MET_FETCH }, { "obj.status", INT, 10, "VRT_r_obj_status(sp)", @@ -126,7 +126,7 @@ "VRT_r_obj_http_(sp)", "VRT_l_obj_http_(sp, ", V_RW, - VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + VCL_MET_HIT | VCL_MET_FETCH }, { "obj.valid", BOOL, 9, "VRT_r_obj_valid(sp)", @@ -156,25 +156,25 @@ "VRT_r_resp_proto(sp)", "VRT_l_resp_proto(sp, ", V_RW, - VCL_MET_FETCH + VCL_MET_DELIVER }, { "resp.status", INT, 11, "VRT_r_resp_status(sp)", "VRT_l_resp_status(sp, ", V_RW, - VCL_MET_FETCH + VCL_MET_DELIVER }, { "resp.response", STRING, 13, "VRT_r_resp_response(sp)", "VRT_l_resp_response(sp, ", V_RW, - VCL_MET_FETCH + VCL_MET_DELIVER }, { "resp.http.", HEADER, 10, "VRT_r_resp_http_(sp)", "VRT_l_resp_http_(sp, ", V_RW, - VCL_MET_FETCH + VCL_MET_DELIVER }, { "now", TIME, 3, "VRT_r_now(sp)", From des at projects.linpro.no Wed Jul 4 13:15:32 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 4 Jul 2007 15:15:32 +0200 (CEST) Subject: r1641 - trunk/varnish-tools/fetcher Message-ID: <20070704131532.AF8411EC030@projects.linpro.no> Author: des Date: 2007-07-04 15:15:32 +0200 (Wed, 04 Jul 2007) New Revision: 1641 Added: trunk/varnish-tools/fetcher/fetcher.pl Removed: trunk/varnish-tools/fetcher/fetcher.c Modified: trunk/varnish-tools/fetcher/Makefile Log: Replace the old C fetcher with a Perl script which recursively retrieves the specified URLs using multiple paralell clients. Modified: trunk/varnish-tools/fetcher/Makefile =================================================================== --- trunk/varnish-tools/fetcher/Makefile 2007-07-03 22:24:09 UTC (rev 1640) +++ trunk/varnish-tools/fetcher/Makefile 2007-07-04 13:15:32 UTC (rev 1641) @@ -2,8 +2,10 @@ # $Id$ # -PROG = fetcher -WARNS ?= 6 -MAN = +PREFIX?= ${HOME} +BINDIR?= ${DESTDIR}${PREFIX}/bin -.include +all: + +install: + install -m 0755 fetcher.pl ${BINDIR}/fetcher Deleted: trunk/varnish-tools/fetcher/fetcher.c =================================================================== --- trunk/varnish-tools/fetcher/fetcher.c 2007-07-03 22:24:09 UTC (rev 1640) +++ trunk/varnish-tools/fetcher/fetcher.c 2007-07-04 13:15:32 UTC (rev 1641) @@ -1,220 +0,0 @@ -/* - * $Id$ - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -static int random_order; -static int verbose; - -static char data[8192]; - -static const char * -read_line(FILE *f) -{ - static char *buf; - static size_t bufsz; - const char *line; - size_t len; - - if ((line = fgetln(f, &len)) == NULL) - return (NULL); - while (len && (line[len - 1] == '\r' || line[len - 1] == '\n')) - --len; - if (bufsz < len + 1) { - bufsz = len * 2; - if ((buf = realloc(buf, bufsz)) == NULL) - err(1, "realloc()"); - } - memcpy(buf, line, len); - buf[len] = '\0'; - if (verbose) - fprintf(stderr, "<<< [%s]\n", buf); - return (buf); -} - -static int -open_socket(const char *host, const char *port) -{ - struct addrinfo hints, *res; - int error, sd; - - /* connect to accelerator */ - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_INET; - hints.ai_socktype = SOCK_STREAM; - if ((error = getaddrinfo(host, port, &hints, &res)) != 0) - errx(1, "%s", gai_strerror(error)); - if ((sd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) - err(1, "socket()"); - if (connect(sd, res->ai_addr, res->ai_addrlen) < 0) - err(1, "connect()"); - return (sd); -} - -static const char HEAD[] = "HEAD"; -static const char GET[] = "GET"; - -static int reqcount; - -static void -send_request(FILE *f, const char *method, const char *host, const char *url) -{ - static const char *req_pattern = - "%s %s HTTP/1.1\r\n" - "Host: %s\r\n" - "Connection: Keep-Alive\r\n" - "\r\n"; - - reqcount++; - - /* send request */ - if (fprintf(f, req_pattern, method, url, host) < 0) - errx(1, "fprintf()"); - if (verbose) - fprintf(stderr, req_pattern, method, url, host); -} - -static int respcount; - -static void -receive_response(FILE *f, const char *method) -{ - const char *line; - size_t clen, rlen; - int code; - - respcount++; - - /* get response header */ - if ((line = read_line(f)) == NULL) - errx(1, "protocol error"); - if (sscanf(line, "HTTP/%*d.%*d %d %*s", &code) != 1) - errx(1, "protocol error"); - if (code != 200) - errx(1, "code %d", code); - - /* get content-length */ - clen = 0; - for (;;) { - if ((line = read_line(f)) == NULL) - errx(1, "protocol error"); - if (line[0] == '\0') - break; - sscanf(line, "Content-Length: %zu\n", &clen); - } - - /* eat contents */ - if (method == HEAD) - return; - while (clen > 0) { - rlen = clen > sizeof(data) ? sizeof(data) : clen; - rlen = fread(data, 1, rlen, f); - if (rlen == 0) - err(1, "fread()"); - if (verbose) - fprintf(stderr, "read %zu bytes\n", rlen); - clen -= rlen; - } -} - -static volatile sig_atomic_t got_sig; - -static void -handler(int sig) -{ - got_sig = sig; -} - -static void -usage(void) -{ - fprintf(stderr, "usage: fetcher [-h]\n"); - exit(1); -} - -#define MAX_CTR 100000 - -int -main(int argc, char *argv[]) -{ - struct timeval start, stop; - double elapsed; - char url[PATH_MAX]; - int opt, sd; - FILE *f; - - const char *method = GET; - const char *host = "varnish-test-1.linpro.no"; - const char *url_pattern = "/cgi-bin/recursor.pl?foo=%d"; - int ctr = MAX_CTR * 10; - int depth = 1; - - while ((opt = getopt(argc, argv, "c:d:hrv")) != -1) - switch (opt) { - case 'c': - ctr = atoi(optarg); - break; - case 'd': - depth = atoi(optarg); - break; - case 'h': - method = HEAD; - break; - case 'r': - random_order++; - break; - case 'v': - verbose++; - break; - default: - usage(); - } - - argc -= optind; - argv += optind; - - if (argc != 0) - usage(); - - if (random_order) - srandomdev(); - - sd = open_socket("varnish-test-2.linpro.no", "8080"); - if ((f = fdopen(sd, "w+")) == NULL) - err(1, "fdopen()"); - - got_sig = 0; - signal(SIGINT, handler); - signal(SIGTERM, handler); - gettimeofday(&start, NULL); - while (respcount < ctr && !got_sig) { - while (reqcount < ctr && reqcount - respcount < depth && !got_sig) { - int serial = (random_order ? random() : reqcount) % MAX_CTR; - if (!verbose && (random_order || (reqcount % 29) == 0)) - fprintf(stderr, "\r%d ", serial); - snprintf(url, sizeof url, url_pattern, serial); - send_request(f, method, host, url); - } - receive_response(f, method); - } - gettimeofday(&stop, NULL); - fclose(f); - - elapsed = (stop.tv_sec * 1000000.0 + stop.tv_usec) - - (start.tv_sec * 1000000.0 + start.tv_usec); - fprintf(stderr, "%d requests in %.3f seconds (%d rps)\n", - reqcount, elapsed / 1000000, (int)(reqcount / (elapsed / 1000000))); - - exit(got_sig); -} Added: trunk/varnish-tools/fetcher/fetcher.pl =================================================================== --- trunk/varnish-tools/fetcher/fetcher.pl (rev 0) +++ trunk/varnish-tools/fetcher/fetcher.pl 2007-07-04 13:15:32 UTC (rev 1641) @@ -0,0 +1,199 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2007 Linpro AS +# All rights reserved. +# +# 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 +# in this position and unchanged. +# 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 THE 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. +# +# $Id$ +# + +package Varnish::Fetcher; + +use strict; +use Getopt::Long; +use IO::Handle; +use IO::Multiplex; +use LWP::UserAgent; +use Socket; +use URI; + +our %TODO; +our %DONE; +our %CHILD; +our $BUSY; + +sub new($$) { + my ($this, $mux, $fh) = @_; + my $class = ref($this) || $this; + + bless { + 'mux' => $mux, + 'fh' => $fh, + 'url' => undef, + }; +} + +sub run($$) { + my ($self, $s) = @_; + + my $ua = new LWP::UserAgent(); + for (;;) { + $0 = "[fetcher] idle"; + my $url = <$s>; + exit(0) + unless defined($url); + chomp($url); + die "no more work\n" + if $url eq "done"; + $0 = "[fetcher] requesting $url"; + print STDERR "Retrieving $url\n"; + my $resp = $ua->get($url); + $0 = "[fetcher] checking $url"; + if ($resp->header('Content-Type') =~ m/^text\//) { + my %urls = map { $_ => 1 } + ($resp->content =~ m/\b(?:href|src)=[\'\"](.+?)[\'\"]/g); + foreach (keys(%urls)) { + $s->write("add $_\n"); + } + } + $0 = "[fetcher] ready"; + $s->write("ready\n"); + } +} + +sub send_url($) { + my ($child) = @_; + + die "child busy\n" + if $child->{'url'}; + return undef + unless (keys(%TODO)); + my $url = (keys(%TODO))[0]; + delete $TODO{$url}; + $DONE{$url} = 1; + $child->{'url'} = $url; + $child->{'mux'}->write($child->{'fh'}, "$url\n"); + ++$BUSY; +} + +sub get_url($$) { + my ($child, $url) = @_; + + die "child not busy\n" + unless $child->{'url'}; + my $uri = URI->new_abs($1, $child->{'url'}); + $url = $uri->canonical; + if ($uri->scheme() ne 'http' || + $uri->host_port() ne URI->new($child->{'url'})->host_port()) { + print STDERR "Rejected $url\n"; + return; + } + return if $TODO{$url} || $DONE{$url}; + $TODO{$url} = 1; +} + +sub mux_input($$$$) { + my ($child, $mux, $fh, $input) = @_; + + die "unknown child\n" + unless $child; + + while ($$input =~ s/^(.*?)\n//) { + my $line = $1; + if ($line eq "ready") { + $$child{'url'} = ''; + --$BUSY; + $mux->endloop(); + } elsif ($line =~ m/^add (.*?)$/) { + get_url($child, $1); + } else { + die "can't grok [$line]\n"; + } + } +} + +sub fetcher($@) { + my ($n, @urls) = @_; + + my $mux = new IO::Multiplex; + + # prepare work queue + foreach my $url (@urls) { + $TODO{URI->new($url)->canonical} = 1; + } + + # start children + $BUSY = 0; + for (my $i = 0; $i < $n; ++$i) { + my ($s1, $s2); + socketpair($s1, $s2, AF_UNIX, SOCK_STREAM, PF_UNSPEC); + $s1->autoflush(1); + $s2->autoflush(1); + my $child = __PACKAGE__->new($mux, $s1); + my $pid = fork(); + last unless defined($pid); + if ($pid == 0) { + close($s1); + $child->run($s2); + die "not reachable"; + } else { + close($s2); + $CHILD{$i} = $child; + $mux->add($s1); + $mux->set_callback_object($child, $s1); + } + } + + # main loop + for (;;) { + foreach my $child (values(%CHILD)) { + $child->send_url() + unless $child->{'url'}; + } + last unless $BUSY; + $mux->loop(); + } + + # done + foreach my $child (values(%CHILD)) { + $mux->close($$child{'fh'}); + } +} + +sub usage() { + + print STDERR "usage: $0 [-j n] URL ...\n"; + exit(1); +} + +MAIN:{ + my $jobs = 1; + GetOptions("j|jobs=i" => \$jobs) + or usage(); + $jobs > 0 + or usage(); + @ARGV + or usage(); + fetcher($jobs, @ARGV); +} Property changes on: trunk/varnish-tools/fetcher/fetcher.pl ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Id From des at projects.linpro.no Wed Jul 4 14:28:57 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 4 Jul 2007 16:28:57 +0200 (CEST) Subject: r1642 - trunk/varnish-doc/share Message-ID: <20070704142857.E5BAD1EC404@projects.linpro.no> Author: des Date: 2007-07-04 16:28:57 +0200 (Wed, 04 Jul 2007) New Revision: 1642 Modified: trunk/varnish-doc/share/docbook-xml.css Log: Implement , and . Modified: trunk/varnish-doc/share/docbook-xml.css =================================================================== --- trunk/varnish-doc/share/docbook-xml.css 2007-07-04 13:15:32 UTC (rev 1641) +++ trunk/varnish-doc/share/docbook-xml.css 2007-07-04 14:28:57 UTC (rev 1642) @@ -138,7 +138,7 @@ /* * Lists */ -orderedlist, itemizedlist { +orderedlist, itemizedlist, variablelist { display: block; } @@ -154,6 +154,21 @@ margin-left: 4em; } +variablelist > varlistentry { + display: list-item; + list-style: none; + margin-left: 4em; +} + +varlistentry > term { + display: inline; + margin-left: -1em; +} + +varlistentry > listitem { + display: inline; +} + /* * Tables */ @@ -211,3 +226,19 @@ xref:after { content: "]"; } + +/* + * Misc + */ +filename { + font-family: monospace; +} + +function { + font-family: monospace; +} + +function:after { + content: "()"; + font-family: monospace; +} From des at projects.linpro.no Wed Jul 4 14:30:22 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 4 Jul 2007 16:30:22 +0200 (CEST) Subject: r1643 - in trunk/varnish-doc/en: . inside-varnish Message-ID: <20070704143022.4738F1EC030@projects.linpro.no> Author: des Date: 2007-07-04 16:30:22 +0200 (Wed, 04 Jul 2007) New Revision: 1643 Added: trunk/varnish-doc/en/inside-varnish/ trunk/varnish-doc/en/inside-varnish/article.xml Log: The beginnings of "Inside the Varnish HTTP accelerator" Added: trunk/varnish-doc/en/inside-varnish/article.xml =================================================================== --- trunk/varnish-doc/en/inside-varnish/article.xml (rev 0) +++ trunk/varnish-doc/en/inside-varnish/article.xml 2007-07-04 14:30:22 UTC (rev 1643) @@ -0,0 +1,301 @@ + + + +
+ + $Id$ + Inside the Varnish HTTP Accelerator + + +
+ Repository organization + + The Varnish SVN repository is organized as follows: + + + + branches + + Branches of the main source tree, mainly for release + engineering purposes. + + + + tags + + Static copies of past releases. + + + + trunk + + This is where active development takes place. Code + is merged from here to a branch prior to a release. + + + varnish-cache + + Varnish itself, with its accompanying tools, + code libraries and man pages. + + + bin + + Programs, including Varnish itself. + + + varnishadm + + A command-line interface to the + management port. + + + + varnishd + + The Varnish HTTP accelerator + itself. + + + + varnishhist + + A tool that displays a histogram + of requests grouped by processing time, + using different symbols for hits and + misses. + + + + varnishlog + + An all-purpose log-watching and + log-saving tool. Mostly used to store + log data for later processing by the + other log-watching tools. + + + + varnishncsa + + A log-watching tool that displays + log data in the Apache / NCSA combined + log format, suitable for further + processing by standard log analysis + tools such as AWStats. + + + + varnishreplay + + A tool that reads Varnish log data + and attempts to recreate the HTTP + traffic that resulted in said data; + useful for debugging and + benchmarking. + + + + varnishstat + + A tool that displays statistics + from a running Varnish server. + + + + varnishtop + + A tool that reads Varnish log data + and displays an ordered list of the most + frequently reoccurring log + entries. + + + + + + + include + + Header files for the code libraries. + + + compat + + Header files for libcompat. + + + + + + + lib + + Code libraries. + + + libcompat + + Compatibility library which + implements a number of functions (such + as strlcpy and + vasprintf) which + are present on some but not all of the + platforms Varnish runs on. + + + + libvarnish + + Utility library which implements a + number of non-Varnish-specific functions + (including a CRC32 implementation and a + generic binary heap implementation) + which are used both by Varnish and some + of the accompanying tools. + + + + libvarnishapi + + Interface library, not used by + Varnish itself, but used by applications + which need to interface with + Varnish. + + + + libvcl + + VCL to C translator. + + + + + + + man + + + + + + varnish-doc + + The Varnish documentation, except man pages, + which are kept alongside the source code. + + + + varnish-tools + + Various development and testing tools. + + + + + + +
+ +
+ The accelerator + +
+ Principles of operation + +
+ +
+ Subsystems + +
+ +
+ Data structures + +
+
+ +
+ The log tailers + +
+ varnishlog + +
+ +
+ varnishncsa + +
+
+ +
+ The statistics gatherers + +
+ varnishstat + +
+ +
+ varnishhist + +
+ +
+ varnishtop + +
+
+ +
+ The test framework + +
+ +
+ Plugins + + The trunk/varnish-tools directory in + the Varnish repository contains Varnish plugins for several + popular system monitoring and administration frameworks. + +
+ Munin + +
+ +
+ Nagios + +
+ +
+ Webmin + +
+
+ +
+ Other tools + +
+ varnishadm + +
+ +
+ varnishreplay + +
+ +
+ fetcher + +
+
+
Property changes on: trunk/varnish-doc/en/inside-varnish/article.xml ___________________________________________________________________ Name: svn:mime-type + text/xml Name: svn:keywords + Id Name: svn:charset + utf-8 From phk at projects.linpro.no Thu Jul 5 08:42:08 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 5 Jul 2007 10:42:08 +0200 (CEST) Subject: r1644 - trunk/varnish-cache/bin/varnishd Message-ID: <20070705084208.8F2F31EC46A@projects.linpro.no> Author: phk Date: 2007-07-05 10:42:08 +0200 (Thu, 05 Jul 2007) New Revision: 1644 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Make varnishd actually work again after my last commit: Forgot to adjust default VCL Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-04 14:30:22 UTC (rev 1643) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-05 08:42:08 UTC (rev 1644) @@ -81,7 +81,13 @@ case HDR_REQ: hp = sp->http; break; + case HDR_BEREQ: + hp = sp->bereq->http; + break; case HDR_RESP: + hp = sp->http; + break; + case HDR_OBJ: hp = &sp->obj->http; break; default: Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-07-04 14:30:22 UTC (rev 1643) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-07-05 08:42:08 UTC (rev 1644) @@ -122,7 +122,7 @@ " if (!obj.cacheable) {\n" " pass;\n" " }\n" - " if (resp.http.Set-Cookie) {\n" + " if (obj.http.Set-Cookie) {\n" " pass;\n" " }\n" " insert;\n" From phk at projects.linpro.no Thu Jul 5 09:16:19 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 5 Jul 2007 11:16:19 +0200 (CEST) Subject: r1645 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070705091619.71E6A1EC2B1@projects.linpro.no> Author: phk Date: 2007-07-05 11:16:19 +0200 (Thu, 05 Jul 2007) New Revision: 1645 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_var.c Log: Add support for removing HTTP header lines: sub vcl_deliver { remove resp.http.etag ; remove resp.http.server ; } Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-05 08:42:08 UTC (rev 1644) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-05 09:16:19 UTC (rev 1645) @@ -427,6 +427,7 @@ int http_DissectResponse(struct worker *w, struct http *sp, int fd); void http_DoConnection(struct sess *sp); void http_CopyHome(struct worker *w, int fd, struct http *hp); +void http_Unset(struct http *hp, const char *hdr); #define HTTPH(a, b, c, d, e, f, g) extern char b[]; Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-05 08:42:08 UTC (rev 1644) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-05 09:16:19 UTC (rev 1645) @@ -176,7 +176,7 @@ static int -http_IsHdr(struct http_hdr *hh, char *hdr) +http_IsHdr(struct http_hdr *hh, const char *hdr) { unsigned l; @@ -948,7 +948,23 @@ to->nhd++; } } +/*--------------------------------------------------------------------*/ +void +http_Unset(struct http *hp, const char *hdr) +{ + unsigned u, v; + + for (v = u = HTTP_HDR_FIRST; u < hp->nhd; u++) { + if (http_IsHdr(&hp->hd[u], hdr)) + continue; + if (v != u) + memcpy(&hp->hd[v], &hp->hd[u], sizeof hp->hd[v]); + v++; + } + hp->nhd = v; +} + /*--------------------------------------------------------------------*/ unsigned Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-05 08:42:08 UTC (rev 1644) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-05 09:16:19 UTC (rev 1645) @@ -36,6 +36,7 @@ #include #include #include +#include #include "shmlog.h" #include "heritage.h" @@ -70,10 +71,9 @@ /*--------------------------------------------------------------------*/ -char * -VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n) +static struct http * +vrt_selecthttp(struct sess *sp, enum gethdr_e where) { - char *p; struct http *hp; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -94,6 +94,17 @@ INCOMPL(); } CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); + return (hp); +} + +char * +VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n) +{ + char *p; + struct http *hp; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + hp = vrt_selecthttp(sp, where); if (!http_GetHdr(hp, n, &p)) return (NULL); return (p); @@ -102,6 +113,27 @@ /*--------------------------------------------------------------------*/ void +VRT_SetHdr(struct sess *sp , enum gethdr_e where, const char *hdr, ...) +{ + struct http *hp; + va_list ap; + const char *p; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + hp = vrt_selecthttp(sp, where); + va_start(ap, hdr); + p = va_arg(ap, const char *); + if (p == NULL) { + http_Unset(hp, hdr); + } else { + INCOMPL(); + } + va_end(ap); +} + +/*--------------------------------------------------------------------*/ + +void VRT_handling(struct sess *sp, unsigned hand) { Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-07-05 08:42:08 UTC (rev 1644) +++ trunk/varnish-cache/include/vrt.h 2007-07-05 09:16:19 UTC (rev 1645) @@ -76,6 +76,7 @@ enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ }; char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *); +void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, ...); void VRT_handling(struct sess *sp, unsigned hand); /* Backend related */ Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-05 08:42:08 UTC (rev 1644) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-05 09:16:19 UTC (rev 1645) @@ -104,6 +104,16 @@ } static void +check_writebit(struct tokenlist *tl, struct var *vp) +{ + + if (vp->access == V_RW || vp->access == V_WO) + return; + vsb_printf(tl->sb, "Variable %.*s cannot be modified.\n", PF(tl->t)); + vcc_ErrWhere(tl, tl->t); +} + +static void parse_set(struct tokenlist *tl) { struct var *vp; @@ -115,12 +125,8 @@ vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); assert(vp != NULL); - if (vp->access != V_RW && vp->access != V_WO) { - vsb_printf(tl->sb, "Variable %.*s cannot be written.\n", - PF(vt)); - vcc_ErrWhere(tl, vt); - return; - } + check_writebit(tl, vp); + ERRCHK(tl); Fb(tl, 1, "%s", vp->lname); vcc_NextToken(tl); switch (vp->fmt) { @@ -215,6 +221,31 @@ /*--------------------------------------------------------------------*/ +static void +parse_remove(struct tokenlist *tl) +{ + struct var *vp; + struct token *vt; + + vcc_NextToken(tl); + ExpectErr(tl, VAR); + vt = tl->t; + vp = vcc_FindVar(tl, tl->t, vcc_vars); + if (vp->fmt != STRING) { + vsb_printf(tl->sb, + "Only STRING variables can be removed.\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + check_writebit(tl, vp); + ERRCHK(tl); + Fb(tl, 1, "%s, 0);\n", vp->lname); + vcc_NextToken(tl); + ExpectErr(tl, ';'); +} + +/*--------------------------------------------------------------------*/ + typedef void action_f(struct tokenlist *tl); static struct action_table { @@ -228,6 +259,7 @@ #undef VCL_RET_MAC_E { "call", parse_call }, { "set", parse_set }, + { "remove", parse_remove }, { NULL, NULL } }; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-05 08:42:08 UTC (rev 1644) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-05 09:16:19 UTC (rev 1645) @@ -432,6 +432,7 @@ vsb_cat(sb, "\n"); vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ };\n"); vsb_cat(sb, "char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);\n"); + vsb_cat(sb, "void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, ...);\n"); vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/* Backend related */\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-05 08:42:08 UTC (rev 1644) +++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-05 09:16:19 UTC (rev 1645) @@ -108,7 +108,7 @@ (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); v->rname = p; - asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\")", wh, + asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\"", wh, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); v->lname = p; From phk at projects.linpro.no Thu Jul 5 09:47:52 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 5 Jul 2007 11:47:52 +0200 (CEST) Subject: r1646 - in trunk/varnish-cache: bin/varnishd lib/libvcl Message-ID: <20070705094752.973521EC46A@projects.linpro.no> Author: phk Date: 2007-07-05 11:47:52 +0200 (Thu, 05 Jul 2007) New Revision: 1646 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c trunk/varnish-cache/lib/libvcl/vcc_var.c Log: Implement setting of HTTP headers: sub vcl_deliver { set resp.http.phk = "Beastie" "Rules"; } Would result in a new header line: phk: BeastieRules Notice that strings are concatenated directly, you add spaces, commas etc where you want them. Other variables which have STRING format (or which can be converted to STRING format) can also be used: sub vcl_deliver { set resp.http.phk = "Server is: " resp.http.server ; } Could result in: phk: Server is: Apache/1.3.x LaHonda (Unix) Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-05 09:16:19 UTC (rev 1645) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-05 09:47:52 UTC (rev 1646) @@ -428,6 +428,7 @@ void http_DoConnection(struct sess *sp); void http_CopyHome(struct worker *w, int fd, struct http *hp); void http_Unset(struct http *hp, const char *hdr); +void http_LogLostHeader(struct worker *w, int fd, struct http *hp, const char *hdr); #define HTTPH(a, b, c, d, e, f, g) extern char b[]; Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-05 09:16:19 UTC (rev 1645) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-05 09:47:52 UTC (rev 1646) @@ -91,12 +91,18 @@ } static void -WSLH(struct worker *w, enum httptag t, unsigned xid, struct http *hp, int hdr) +WSLH(struct worker *w, enum httptag t, unsigned fd, struct http *hp, int hdr) { - WSLR(w, http2shmlog(hp, t), xid, hp->hd[hdr].b, hp->hd[hdr].e); + WSLR(w, http2shmlog(hp, t), fd, hp->hd[hdr].b, hp->hd[hdr].e); } +void +http_LogLostHeader(struct worker *w, int fd, struct http *hp, const char *hdr) +{ + WSLR(w, http2shmlog(hp, HTTP_T_LostHeader), fd, hdr + 1, hdr + hdr[0]); +} + /*--------------------------------------------------------------------*/ /* List of canonical HTTP response code names from RFC2616 */ Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-05 09:16:19 UTC (rev 1645) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-05 09:47:52 UTC (rev 1646) @@ -118,6 +118,8 @@ struct http *hp; va_list ap; const char *p; + char *b, *e; + unsigned u, x; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); hp = vrt_selecthttp(sp, where); @@ -126,7 +128,32 @@ if (p == NULL) { http_Unset(hp, hdr); } else { - INCOMPL(); + u = WS_Reserve(hp->ws, 0); + e = b = hp->ws->f; + *e = '\0'; + x = strlen(hdr + 1); + if (x + 1 < u) + memcpy(e, hdr + 1, x); + e += x; + if (1 + 1 < u) + *e++ = ' '; + while (p != NULL) { + x = strlen(p); + if (x + 1 < u) + memcpy(e, p, x); + e += x; + p = va_arg(ap, const char *); + } + *e = '\0'; + if (e > b + u) { + http_LogLostHeader(sp->wrk, sp->fd, hp, hdr); + WS_Release(hp->ws, 0); + + } else { + WS_Release(hp->ws, 1 + e - b); + http_Unset(hp, hdr); + http_SetHeader(sp->wrk, sp->fd, hp, b); + } } va_end(ap); } Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-05 09:16:19 UTC (rev 1645) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-05 09:47:52 UTC (rev 1646) @@ -209,6 +209,13 @@ } vcc_NextToken(tl); vcc_StringVal(tl); + if (vp->ishdr) { + while (tl->t->tok != ';') { + Fb(tl, 0, ", "); + vcc_StringVal(tl); + } + Fb(tl, 0, ", 0"); + } Fb(tl, 0, ");\n"); break; default: @@ -231,17 +238,15 @@ ExpectErr(tl, VAR); vt = tl->t; vp = vcc_FindVar(tl, tl->t, vcc_vars); - if (vp->fmt != STRING) { - vsb_printf(tl->sb, - "Only STRING variables can be removed.\n"); + if (vp->fmt != STRING || !vp->ishdr) { + vsb_printf(tl->sb, "Only http header lines can be removed.\n"); vcc_ErrWhere(tl, tl->t); return; } check_writebit(tl, vp); ERRCHK(tl); - Fb(tl, 1, "%s, 0);\n", vp->lname); + Fb(tl, 1, "%s0);\n", vp->lname); vcc_NextToken(tl); - ExpectErr(tl, ';'); } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-05 09:16:19 UTC (rev 1645) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-05 09:47:52 UTC (rev 1646) @@ -121,6 +121,7 @@ const char *rname; const char *lname; enum {V_RO, V_RW, V_WO} access; + char ishdr; unsigned methods; }; Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-05 09:16:19 UTC (rev 1645) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-05 09:47:52 UTC (rev 1646) @@ -231,6 +231,7 @@ puts $fo "\t NULL," } puts $fo "\t V_$a," + puts $fo "\t 0," puts $fo "\t [method_map [lindex $v 3]]" puts $fo "\t\}," Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-05 09:16:19 UTC (rev 1645) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-05 09:47:52 UTC (rev 1646) @@ -14,18 +14,21 @@ NULL, "VRT_l_backend_host(backend, ", V_WO, + 0, }, { "backend.port", PORTNAME, 12, NULL, "VRT_l_backend_port(backend, ", V_WO, + 0, }, { "backend.dnsttl", TIME, 14, NULL, "VRT_l_backend_dnsttl(backend, ", V_WO, + 0, }, { NULL } @@ -36,150 +39,175 @@ "VRT_r_client_ip(sp)", NULL, V_RO, + 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER }, { "server.ip", IP, 9, "VRT_r_server_ip(sp)", NULL, V_RO, + 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER }, { "req.request", STRING, 11, "VRT_r_req_request(sp)", NULL, V_RO, + 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.url", STRING, 7, "VRT_r_req_url(sp)", NULL, V_RO, + 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.proto", STRING, 9, "VRT_r_req_proto(sp)", NULL, V_RO, + 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.http.", HEADER, 9, "VRT_r_req_http_(sp)", "VRT_l_req_http_(sp, ", V_RW, + 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.hash", HASH, 8, NULL, "VRT_l_req_hash(sp, ", V_WO, + 0, VCL_MET_HASH }, { "req.backend", BACKEND, 11, "VRT_r_req_backend(sp)", "VRT_l_req_backend(sp, ", V_RW, + 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "bereq.request", STRING, 13, "VRT_r_bereq_request(sp)", "VRT_l_bereq_request(sp, ", V_RW, + 0, VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS }, { "bereq.url", STRING, 9, "VRT_r_bereq_url(sp)", "VRT_l_bereq_url(sp, ", V_RW, + 0, VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS }, { "bereq.proto", STRING, 11, "VRT_r_bereq_proto(sp)", "VRT_l_bereq_proto(sp, ", V_RW, + 0, VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS }, { "bereq.http.", HEADER, 11, "VRT_r_bereq_http_(sp)", "VRT_l_bereq_http_(sp, ", V_RW, + 0, VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS }, { "obj.proto", STRING, 9, "VRT_r_obj_proto(sp)", "VRT_l_obj_proto(sp, ", V_RW, + 0, VCL_MET_HIT | VCL_MET_FETCH }, { "obj.status", INT, 10, "VRT_r_obj_status(sp)", "VRT_l_obj_status(sp, ", V_RW, + 0, VCL_MET_FETCH }, { "obj.response", STRING, 12, "VRT_r_obj_response(sp)", "VRT_l_obj_response(sp, ", V_RW, + 0, VCL_MET_FETCH }, { "obj.http.", HEADER, 9, "VRT_r_obj_http_(sp)", "VRT_l_obj_http_(sp, ", V_RW, + 0, VCL_MET_HIT | VCL_MET_FETCH }, { "obj.valid", BOOL, 9, "VRT_r_obj_valid(sp)", "VRT_l_obj_valid(sp, ", V_RW, + 0, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "obj.cacheable", BOOL, 13, "VRT_r_obj_cacheable(sp)", "VRT_l_obj_cacheable(sp, ", V_RW, + 0, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "obj.ttl", TIME, 7, "VRT_r_obj_ttl(sp)", "VRT_l_obj_ttl(sp, ", V_RW, + 0, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "obj.lastuse", TIME, 11, "VRT_r_obj_lastuse(sp)", NULL, V_RO, + 0, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "resp.proto", STRING, 10, "VRT_r_resp_proto(sp)", "VRT_l_resp_proto(sp, ", V_RW, + 0, VCL_MET_DELIVER }, { "resp.status", INT, 11, "VRT_r_resp_status(sp)", "VRT_l_resp_status(sp, ", V_RW, + 0, VCL_MET_DELIVER }, { "resp.response", STRING, 13, "VRT_r_resp_response(sp)", "VRT_l_resp_response(sp, ", V_RW, + 0, VCL_MET_DELIVER }, { "resp.http.", HEADER, 10, "VRT_r_resp_http_(sp)", "VRT_l_resp_http_(sp, ", V_RW, + 0, VCL_MET_DELIVER }, { "now", TIME, 3, "VRT_r_now(sp)", NULL, V_RO, + 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { NULL } Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-05 09:16:19 UTC (rev 1645) +++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-05 09:47:52 UTC (rev 1646) @@ -93,6 +93,7 @@ v->name = p; v->access = V_RW; v->fmt = STRING; + v->ishdr = 1; v->methods = vh->methods; if (!memcmp(vh->name, "req.", 4)) wh = "HDR_REQ"; @@ -108,7 +109,7 @@ (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); v->rname = p; - asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\"", wh, + asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", wh, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); v->lname = p; From des at projects.linpro.no Thu Jul 5 10:30:49 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 5 Jul 2007 12:30:49 +0200 (CEST) Subject: r1647 - trunk/varnish-tools/regress Message-ID: <20070705103049.954B51EC2B1@projects.linpro.no> Author: des Date: 2007-07-05 12:30:49 +0200 (Thu, 05 Jul 2007) New Revision: 1647 Added: trunk/varnish-tools/regress/README Log: Document the prerequisites Added: trunk/varnish-tools/regress/README =================================================================== --- trunk/varnish-tools/regress/README (rev 0) +++ trunk/varnish-tools/regress/README 2007-07-05 10:30:49 UTC (rev 1647) @@ -0,0 +1,7 @@ +You will need the following Perl modules to run the test framework: + +Perl module Debian package FreeBSD port +============================================================================ +LWP::UserAgent libwww-perl www/p5-libwww +IO::Multiplex libio-multiplex-perl devel/p5-IO-Multiplex +Template libtemplate-perl www/p5-Template-Toolkit From des at projects.linpro.no Thu Jul 5 11:28:09 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 5 Jul 2007 13:28:09 +0200 (CEST) Subject: r1648 - trunk/varnish-cache/man Message-ID: <20070705112809.9E1C21EC518@projects.linpro.no> Author: des Date: 2007-07-05 13:28:09 +0200 (Thu, 05 Jul 2007) New Revision: 1648 Modified: trunk/varnish-cache/man/vcl.7 Log: Document header rewriting. Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-07-05 10:30:49 UTC (rev 1647) +++ trunk/varnish-cache/man/vcl.7 2007-07-05 11:28:09 UTC (rev 1648) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd July 2, 2007 +.Dd July 5, 2007 .Dt VCL 7 .Os .Sh NAME @@ -342,6 +342,12 @@ Although subroutines take no arguments, the necessary information is made available to the handler subroutines through global variables. .Pp +The following variables are always available: +.Bl -tag -width 4n +.It Va now +The current time, in seconds since the epoch. +.El +.Pp The following variables are available in backend declarations: .Bl -tag -width 4n .It Va backend.host @@ -363,24 +369,80 @@ .It Va req.backend The backend to use to service the request. .It Va req.http. Ns Ar header -The corresponding -.Ar header -from the HTTP request. +The corresponding HTTP +.Ar header . .El .Pp +The following variables are available while preparing a backend +request (either for a cache miss or for pass or pipe mode): +.Bl -tag -width 4n +.It Va bereq.request +The request type (e.g. "GET", "HEAD"). +.It Va bereq.url +The requested URL. +.It Va bereq.proto +The HTTP protocol version used to talk to the server. +.It Va bereq.http. Ns Ar header +The corresponding HTTP +.Ar header . +.El +.Pp The following variables are available after the requested object has been retrieved from cache or from the backend: .Bl -tag -width 4n +.It Va obj.proto +The HTTP protocol version used when the object was retrieved. +.It Va obj.status +The HTTP status code returned by the server. +.It Va obj.response +The HTTP status message returned by the server. .It Va obj.valid True if the object was successfully retrieved. .It Va obj.cacheable True if the object is cacheable. .\" XXX what are the criteria? .It Va obj.ttl -The object's time to live. -.\" .It Va resp.http. Ns Ar header -.\" XXX not implemented? +The object's remaining time to live, in seconds. +.It Va obj.lastuse +The approximate time elapsed since the object was last requests, in +seconds. .El +.Pp +The following variables are available while preparing a response to +the client: +.Bl -tag -width 4n +.It Va resp.proto +The HTTP protocol version to use for the response. +.It Va resp.status +The HTTP status code that will be returned. +.It Va resp.response +The HTTP status message that will be returned. +.It Va resp.http. Ns Ar header +The corresponding HTTP +.Ar header . +.El +.Pp +Values may be assigned to variables using the +.Cm set +keyword: +.Bd -literal -offset 4n +sub vcl_recv { + # Normalize the Host: header + if (req.http.host ~ "^(www\.)?example\.com$") { + set req.http.host = "www.example.com"; + } +} +.Ed +.Pp +HTTP headers can be removed entirely using the +.Cm remove +keyword: +.Bd -literal -offset 4n +sub vcl_fetch { + # Don't cache cookies + remove obj.http.Set-Cookie; +} +.Ed .Sh EXAMPLES The following code is the equivalent of the default configuration with the backend address set to "backend.example.com" and no backend port @@ -435,7 +497,7 @@ if (!obj.cacheable) { pass; } - if (resp.http.Set-Cookie) { + if (obj.http.Set-Cookie) { pass; } insert; @@ -503,7 +565,7 @@ } sub vcl_fetch { - if (resp.http.Set-Cookie) { + if (obj.http.Set-Cookie) { insert; } } From des at projects.linpro.no Thu Jul 5 12:10:35 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 5 Jul 2007 14:10:35 +0200 (CEST) Subject: r1649 - branches Message-ID: <20070705121035.4B09A1EC2B1@projects.linpro.no> Author: des Date: 2007-07-05 14:10:35 +0200 (Thu, 05 Jul 2007) New Revision: 1649 Added: branches/1.1/ Log: Create the 1.1 branch. Copied: branches/1.1 (from rev 1648, trunk/varnish-cache) From des at projects.linpro.no Thu Jul 5 12:14:27 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 5 Jul 2007 14:14:27 +0200 (CEST) Subject: r1650 - in branches/1.1: . debian redhat Message-ID: <20070705121427.CEA871EC2B1@projects.linpro.no> Author: des Date: 2007-07-05 14:14:27 +0200 (Thu, 05 Jul 2007) New Revision: 1650 Modified: branches/1.1/configure.ac branches/1.1/debian/changelog branches/1.1/redhat/varnish.spec Log: Bump Modified: branches/1.1/configure.ac =================================================================== --- branches/1.1/configure.ac 2007-07-05 12:10:35 UTC (rev 1649) +++ branches/1.1/configure.ac 2007-07-05 12:14:27 UTC (rev 1650) @@ -3,7 +3,7 @@ AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2006-2007 Linpro AS / Verdens Gang AS]) AC_REVISION([$Id$]) -AC_INIT([Varnish], [trunk], [varnish-dev at projects.linpro.no]) +AC_INIT([Varnish], [1.1], [varnish-dev at projects.linpro.no]) AC_CONFIG_SRCDIR(include/varnishapi.h) AM_CONFIG_HEADER(config.h) Modified: branches/1.1/debian/changelog =================================================================== --- branches/1.1/debian/changelog 2007-07-05 12:10:35 UTC (rev 1649) +++ branches/1.1/debian/changelog 2007-07-05 12:14:27 UTC (rev 1650) @@ -1,3 +1,9 @@ +varnish (1.1-1) unstable; urgency=low + + * New upstream version + + -- des Thu, 5 Jul 2007 13:13:54 +0200 + varnish (1.0.4-1) unstable; urgency=low * New upstream version (Closes: #424560) Modified: branches/1.1/redhat/varnish.spec =================================================================== --- branches/1.1/redhat/varnish.spec 2007-07-05 12:10:35 UTC (rev 1649) +++ branches/1.1/redhat/varnish.spec 2007-07-05 12:14:27 UTC (rev 1650) @@ -1,7 +1,7 @@ Summary: Varnish is a high-performance HTTP accelerator Name: varnish -Version: 1.0.svn -Release: 20070529%{?dist} +Version: 1.1 +Release: 1%{?dist} License: BSD-like Group: System Environment/Daemons URL: http://www.varnish-cache.org/ @@ -148,6 +148,9 @@ %postun libs -p /sbin/ldconfig %changelog +* Thu Jul 05 2006 Dag-Erling Sm?rgrav - 1.1-1 +- Bump Version and Release for 1.1 + * Mon May 28 2007 Ingvar Hagelund - 1.0.4-3 - Fixed initrc-script bug only visible on el4 (fixes #107) From des at projects.linpro.no Thu Jul 5 14:28:48 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 5 Jul 2007 16:28:48 +0200 (CEST) Subject: r1651 - trunk/varnish-cache/man Message-ID: <20070705142848.6B04F1EC030@projects.linpro.no> Author: des Date: 2007-07-05 16:28:48 +0200 (Thu, 05 Jul 2007) New Revision: 1651 Modified: trunk/varnish-cache/man/vcl.7 Log: Document server.ip. Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-07-05 12:14:27 UTC (rev 1650) +++ trunk/varnish-cache/man/vcl.7 2007-07-05 14:28:48 UTC (rev 1651) @@ -360,6 +360,9 @@ .Bl -tag -width 4n .It Va client.ip The client's IP address. +.It Va server.ip +The IP address of the socket on which the client connection was +received. .It Va req.request The request type (e.g. "GET", "HEAD"). .It Va req.url From des at projects.linpro.no Thu Jul 5 14:54:50 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 5 Jul 2007 16:54:50 +0200 (CEST) Subject: r1652 - trunk/varnish-cache/doc Message-ID: <20070705145450.3DFC91EC2B1@projects.linpro.no> Author: des Date: 2007-07-05 16:54:50 +0200 (Thu, 05 Jul 2007) New Revision: 1652 Added: trunk/varnish-cache/doc/changes.css Modified: trunk/varnish-cache/doc/changes-html.xsl Log: Add a CSS stylesheet. Modified: trunk/varnish-cache/doc/changes-html.xsl =================================================================== --- trunk/varnish-cache/doc/changes-html.xsl 2007-07-05 14:28:48 UTC (rev 1651) +++ trunk/varnish-cache/doc/changes-html.xsl 2007-07-05 14:54:50 UTC (rev 1652) @@ -15,6 +15,7 @@ <xsl:call-template name="title"/> +

Added: trunk/varnish-cache/doc/changes.css =================================================================== --- trunk/varnish-cache/doc/changes.css (rev 0) +++ trunk/varnish-cache/doc/changes.css 2007-07-05 14:54:50 UTC (rev 1652) @@ -0,0 +1,27 @@ +/* $Id$ */ + +body { + background-color: white; + color: black; + font-family: sans-serif; + max-width: 40em; + margin: 1in auto 1in auto; +} + +h1 { + font-size: 200%; + font-weight: bold; + color: maroon; +} + +h2 { + font-size: 160%; + font-weight: bold; + color: maroon; +} + +h3 { + font-size: 120%; + font-weight: bold; + color: maroon; +} Property changes on: trunk/varnish-cache/doc/changes.css ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Thu Jul 5 15:31:25 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 5 Jul 2007 17:31:25 +0200 (CEST) Subject: r1653 - trunk/varnish-cache/bin/varnishd Message-ID: <20070705153125.7CC131EC030@projects.linpro.no> Author: des Date: 2007-07-05 17:31:25 +0200 (Thu, 05 Jul 2007) New Revision: 1653 Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 Log: Document the -F option (introduced in r1557) Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2007-07-05 14:54:50 UTC (rev 1652) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2007-07-05 15:31:25 UTC (rev 1653) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd July 3, 2007 +.Dd July 5, 2007 .Dt VARNISHD 1 .Os .Sh NAME @@ -39,6 +39,7 @@ .Op Fl a Ar addrss Ns Op : Ns Ar port .Op Fl b Ar host Ns Op : Ns Ar port .Op Fl d +.Op Fl F .Op Fl f Ar config .Op Fl g Ar group .Op Fl h Ar type Ns Op , Ns Ar options @@ -111,6 +112,8 @@ .Fl d flag is specified twice, the child process will not daemonize, and terminating the parent process will also terminate the child. +.It Fl F +Run in the foreground. .It Fl f Ar config Use the specified VCL configuration file instead of the builtin default. From des at projects.linpro.no Thu Jul 5 16:09:46 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 5 Jul 2007 18:09:46 +0200 (CEST) Subject: r1654 - trunk/varnish-cache/doc Message-ID: <20070705160946.27C661EC2B1@projects.linpro.no> Author: des Date: 2007-07-05 18:09:45 +0200 (Thu, 05 Jul 2007) New Revision: 1654 Added: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml trunk/varnish-cache/doc/changes-1.1.xml Modified: trunk/varnish-cache/doc/Makefile.am Log: Change log for 1.1. Modified: trunk/varnish-cache/doc/Makefile.am =================================================================== --- trunk/varnish-cache/doc/Makefile.am 2007-07-05 15:31:25 UTC (rev 1653) +++ trunk/varnish-cache/doc/Makefile.am 2007-07-05 16:09:45 UTC (rev 1654) @@ -1,6 +1,6 @@ # $Id$ -CHANGELOGS = changes-1.0.4.html +CHANGELOGS = changes-1.0.4.html changes-1.1.html EXTRA_DIST = ${CHANGELOGS} Added: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.0.4-1.1.xml (rev 0) +++ trunk/varnish-cache/doc/changes-1.0.4-1.1.xml 2007-07-05 16:09:45 UTC (rev 1654) @@ -0,0 +1,237 @@ + + +]> + + + + varnishd + + + Readability of the C source code generated from VCL code + has been improved. + + + + Equality (==) and inequality + (!=) operators have been implemented for IP + addresses (which previously could only be compared using + ACLs). + + + + The address of the listening socket on which the client + connection was received is now available to VCL as the + server.ip variable. + + + + Each object's hash key is now computed based on a string + which is available to VCL as req.hash. A VCL + hook named vcl_hash has been added to allow + VCL scripts to control hash generation (for instance, whether or + not to include the value of the Host: header + in the hash). + + + + The setup code for listening sockets has been modified to + detect and handle situations where a host name resolves to + multiple IP addresses. It will now attempt to bind to each IP + address separately, and report a failure only if none of them + worked. + + + + Network or protocol errors that occur while retrieving an + object from a backend server now result in a synthetic error + page being inserted into the cache with a 30-second TTL. This + should help avoid driving an overburdened backend server into + the ground by repeatedly requesting the same object. + + + + The child process will now drop root privileges + immediately upon startup. The user and group to use are + specified with the user and + group run-time parameters, which default to + nobody and nogroup, + respectively. Other changes have been made in an effort to + increase the isolation between parent and child, and reduce the + impact of a compromise of the child process. + + + + Objects which are received from the backend with a + Vary: header are now stored separately + according to the values of the headers specified in + Vary:. This allows Varnish to correctly + cache e.g. compressed and uncompressed versions of the same + object. + + + + Each Varnish instance now has a name, which by default is + the host name of the machine it runs on, but can be any string + that would be valid as a relative or absolute directory name. + It is used to construct the name of a directory in which the + server state as well as all temporary files are stored. This + makes it possible to run multiple Varnish instances on the same + machine without conflict. + + + + When invoked with the option, + varnishd will now not just translate the VCL + code to C, but also compile the C code and attempt to load the + resulting shared object. + + + + Attempts by VCL code to reference a variable outside its + scope or to assign a value to a read-only variable will now + result in compile-time rather than run-time errors. + + + + The new command-line option will make + varnishd run in the foreground, without + enabling debugging. + + + + New VCL variables have been introduced to allow inspection + and manipulation of the request sent to the backend + (bereq.request, bereq.url, + bereq.proto and + bereq.http) and the response to the client + (resp.proto, resp.status, + resp.response and + resp.http). + + + + Statistics from the storage code (including the amount of + data and free space in the cache) are now available to + varnishstat and other statistics-gathering + tools. + + + + Objects are now kept on an LRU list which is kept loosely + up-to-date (to within a few seconds). When cache runs out, the + objects at the tail end of the LRU list are discarded one by one + until there is enough space for the freshly requested object(s). + A VCL hook, vcl_discard, is allowed to + inspect each object and determine its fate by returning either + keep or discard. + + + + A new VCL hook, vcl_deliver, provides + a chance to adjust the response before it is sent to the + client. + + + + A new management command, vcl.show, + displays the VCL source code of any loaded configuration. + + + + A new VCL variable, now, provides VCL + scripts with the current time in seconds since the epoch. + + + + A new VCL variable, obj.lastuse, + reflects the time in seconds since the object in question was + last used. + + + + VCL scripts can now add an HTTP header (or modify the + value of an existing one) by assigning a value to the + corresponding variable, and strip an HTTP header by using the + remove keyword. + + + + + varnishadm + + + This is a new utility which sends a single command to a + Varnish server's management port and prints the result to + stdout, greatly simplifying the use of the + management port from scripts. + + + + + varnishhist + + + The user interface has been greatly improved; the + histogram will be automatically rescaled and redrawn when the + window size changes, and it is updated regularly rather than at + a rate dependent on the amount of log data gathered. In + addition, the name of the Varnish instance being watched is + displayed in the upper right corner. + + + + + varnishncsa + + + In addition to client traffic, + varnishncsa can now also process log data + from backend traffic. + + + + + varnishreplay + + + This new utility will attempt to recreate the HTTP traffic + which resulted in the raw Varnish log data which it is + fed. + + + + + varnishstat + + + Don't print lifetime averages when it doesn't make any + sense—for instance, there is no point in dividing the + amount in bytes of free cache space by the lifetime in seconds + of the varnishd process. + + + + The user interface has been greatly improved; + varnishstat will no longer print more than + fits in the terminal, and will respond correctly to window + resize events. The output produced in one-shot mode has been + modified to include symbolic names for each entry. In addition, + the name of the Varnish instance being watched is displayed in + the upper right corner in curses mode. + + + + + varnishtop + + + The user interface has been greatly improved; + varnishtop will now respond correctly to + window resize events, and one-shot mode () + actually works. In addition, the name of the Varnish instance + being watched is displayed in the upper right corner in curses + mode. + + + Property changes on: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/varnish-cache/doc/changes-1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.1.xml (rev 0) +++ trunk/varnish-cache/doc/changes-1.1.xml 2007-07-05 16:09:45 UTC (rev 1654) @@ -0,0 +1,12 @@ + + + +]> + + + Varnish + 1.1 + + + Property changes on: trunk/varnish-cache/doc/changes-1.1.xml ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Thu Jul 5 16:10:46 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 5 Jul 2007 18:10:46 +0200 (CEST) Subject: r1655 - branches/1.1 Message-ID: <20070705161046.DB4BF1EC030@projects.linpro.no> Author: des Date: 2007-07-05 18:10:46 +0200 (Thu, 05 Jul 2007) New Revision: 1655 Modified: branches/1.1/ Log: svnmerge init Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated + /trunk/varnish-cache:1-1648 From des at projects.linpro.no Thu Jul 5 16:11:14 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 5 Jul 2007 18:11:14 +0200 (CEST) Subject: r1656 - in branches/1.1: . bin/varnishd doc man Message-ID: <20070705161114.308F61EC2B1@projects.linpro.no> Author: des Date: 2007-07-05 18:11:13 +0200 (Thu, 05 Jul 2007) New Revision: 1656 Added: branches/1.1/doc/changes-1.0.4-1.1.xml branches/1.1/doc/changes-1.1.xml branches/1.1/doc/changes.css Modified: branches/1.1/ branches/1.1/bin/varnishd/varnishd.1 branches/1.1/doc/Makefile.am branches/1.1/doc/changes-html.xsl branches/1.1/man/vcl.7 Log: Merged revisions 1651-1654 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1651 | des | 2007-07-05 16:28:48 +0200 (Thu, 05 Jul 2007) | 2 lines Document server.ip. ........ r1652 | des | 2007-07-05 16:54:50 +0200 (Thu, 05 Jul 2007) | 2 lines Add a CSS stylesheet. ........ r1653 | des | 2007-07-05 17:31:25 +0200 (Thu, 05 Jul 2007) | 2 lines Document the -F option (introduced in r1557) ........ r1654 | des | 2007-07-05 18:09:45 +0200 (Thu, 05 Jul 2007) | 2 lines Change log for 1.1. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1648 + /trunk/varnish-cache:1-1648,1651-1654 Modified: branches/1.1/bin/varnishd/varnishd.1 =================================================================== --- branches/1.1/bin/varnishd/varnishd.1 2007-07-05 16:10:46 UTC (rev 1655) +++ branches/1.1/bin/varnishd/varnishd.1 2007-07-05 16:11:13 UTC (rev 1656) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd July 3, 2007 +.Dd July 5, 2007 .Dt VARNISHD 1 .Os .Sh NAME @@ -39,6 +39,7 @@ .Op Fl a Ar addrss Ns Op : Ns Ar port .Op Fl b Ar host Ns Op : Ns Ar port .Op Fl d +.Op Fl F .Op Fl f Ar config .Op Fl g Ar group .Op Fl h Ar type Ns Op , Ns Ar options @@ -111,6 +112,8 @@ .Fl d flag is specified twice, the child process will not daemonize, and terminating the parent process will also terminate the child. +.It Fl F +Run in the foreground. .It Fl f Ar config Use the specified VCL configuration file instead of the builtin default. Modified: branches/1.1/doc/Makefile.am =================================================================== --- branches/1.1/doc/Makefile.am 2007-07-05 16:10:46 UTC (rev 1655) +++ branches/1.1/doc/Makefile.am 2007-07-05 16:11:13 UTC (rev 1656) @@ -1,6 +1,6 @@ # $Id$ -CHANGELOGS = changes-1.0.4.html +CHANGELOGS = changes-1.0.4.html changes-1.1.html EXTRA_DIST = ${CHANGELOGS} Copied: branches/1.1/doc/changes-1.0.4-1.1.xml (from rev 1654, trunk/varnish-cache/doc/changes-1.0.4-1.1.xml) =================================================================== --- branches/1.1/doc/changes-1.0.4-1.1.xml (rev 0) +++ branches/1.1/doc/changes-1.0.4-1.1.xml 2007-07-05 16:11:13 UTC (rev 1656) @@ -0,0 +1,237 @@ + + +]> + + + + varnishd + + + Readability of the C source code generated from VCL code + has been improved. + + + + Equality (==) and inequality + (!=) operators have been implemented for IP + addresses (which previously could only be compared using + ACLs). + + + + The address of the listening socket on which the client + connection was received is now available to VCL as the + server.ip variable. + + + + Each object's hash key is now computed based on a string + which is available to VCL as req.hash. A VCL + hook named vcl_hash has been added to allow + VCL scripts to control hash generation (for instance, whether or + not to include the value of the Host: header + in the hash). + + + + The setup code for listening sockets has been modified to + detect and handle situations where a host name resolves to + multiple IP addresses. It will now attempt to bind to each IP + address separately, and report a failure only if none of them + worked. + + + + Network or protocol errors that occur while retrieving an + object from a backend server now result in a synthetic error + page being inserted into the cache with a 30-second TTL. This + should help avoid driving an overburdened backend server into + the ground by repeatedly requesting the same object. + + + + The child process will now drop root privileges + immediately upon startup. The user and group to use are + specified with the user and + group run-time parameters, which default to + nobody and nogroup, + respectively. Other changes have been made in an effort to + increase the isolation between parent and child, and reduce the + impact of a compromise of the child process. + + + + Objects which are received from the backend with a + Vary: header are now stored separately + according to the values of the headers specified in + Vary:. This allows Varnish to correctly + cache e.g. compressed and uncompressed versions of the same + object. + + + + Each Varnish instance now has a name, which by default is + the host name of the machine it runs on, but can be any string + that would be valid as a relative or absolute directory name. + It is used to construct the name of a directory in which the + server state as well as all temporary files are stored. This + makes it possible to run multiple Varnish instances on the same + machine without conflict. + + + + When invoked with the option, + varnishd will now not just translate the VCL + code to C, but also compile the C code and attempt to load the + resulting shared object. + + + + Attempts by VCL code to reference a variable outside its + scope or to assign a value to a read-only variable will now + result in compile-time rather than run-time errors. + + + + The new command-line option will make + varnishd run in the foreground, without + enabling debugging. + + + + New VCL variables have been introduced to allow inspection + and manipulation of the request sent to the backend + (bereq.request, bereq.url, + bereq.proto and + bereq.http) and the response to the client + (resp.proto, resp.status, + resp.response and + resp.http). + + + + Statistics from the storage code (including the amount of + data and free space in the cache) are now available to + varnishstat and other statistics-gathering + tools. + + + + Objects are now kept on an LRU list which is kept loosely + up-to-date (to within a few seconds). When cache runs out, the + objects at the tail end of the LRU list are discarded one by one + until there is enough space for the freshly requested object(s). + A VCL hook, vcl_discard, is allowed to + inspect each object and determine its fate by returning either + keep or discard. + + + + A new VCL hook, vcl_deliver, provides + a chance to adjust the response before it is sent to the + client. + + + + A new management command, vcl.show, + displays the VCL source code of any loaded configuration. + + + + A new VCL variable, now, provides VCL + scripts with the current time in seconds since the epoch. + + + + A new VCL variable, obj.lastuse, + reflects the time in seconds since the object in question was + last used. + + + + VCL scripts can now add an HTTP header (or modify the + value of an existing one) by assigning a value to the + corresponding variable, and strip an HTTP header by using the + remove keyword. + + + + + varnishadm + + + This is a new utility which sends a single command to a + Varnish server's management port and prints the result to + stdout, greatly simplifying the use of the + management port from scripts. + + + + + varnishhist + + + The user interface has been greatly improved; the + histogram will be automatically rescaled and redrawn when the + window size changes, and it is updated regularly rather than at + a rate dependent on the amount of log data gathered. In + addition, the name of the Varnish instance being watched is + displayed in the upper right corner. + + + + + varnishncsa + + + In addition to client traffic, + varnishncsa can now also process log data + from backend traffic. + + + + + varnishreplay + + + This new utility will attempt to recreate the HTTP traffic + which resulted in the raw Varnish log data which it is + fed. + + + + + varnishstat + + + Don't print lifetime averages when it doesn't make any + sense—for instance, there is no point in dividing the + amount in bytes of free cache space by the lifetime in seconds + of the varnishd process. + + + + The user interface has been greatly improved; + varnishstat will no longer print more than + fits in the terminal, and will respond correctly to window + resize events. The output produced in one-shot mode has been + modified to include symbolic names for each entry. In addition, + the name of the Varnish instance being watched is displayed in + the upper right corner in curses mode. + + + + + varnishtop + + + The user interface has been greatly improved; + varnishtop will now respond correctly to + window resize events, and one-shot mode () + actually works. In addition, the name of the Varnish instance + being watched is displayed in the upper right corner in curses + mode. + + + Copied: branches/1.1/doc/changes-1.1.xml (from rev 1654, trunk/varnish-cache/doc/changes-1.1.xml) =================================================================== --- branches/1.1/doc/changes-1.1.xml (rev 0) +++ branches/1.1/doc/changes-1.1.xml 2007-07-05 16:11:13 UTC (rev 1656) @@ -0,0 +1,12 @@ + + + +]> + + + Varnish + 1.1 + + + Modified: branches/1.1/doc/changes-html.xsl =================================================================== --- branches/1.1/doc/changes-html.xsl 2007-07-05 16:10:46 UTC (rev 1655) +++ branches/1.1/doc/changes-html.xsl 2007-07-05 16:11:13 UTC (rev 1656) @@ -15,6 +15,7 @@ <xsl:call-template name="title"/> +

Copied: branches/1.1/doc/changes.css (from rev 1654, trunk/varnish-cache/doc/changes.css) =================================================================== --- branches/1.1/doc/changes.css (rev 0) +++ branches/1.1/doc/changes.css 2007-07-05 16:11:13 UTC (rev 1656) @@ -0,0 +1,27 @@ +/* $Id$ */ + +body { + background-color: white; + color: black; + font-family: sans-serif; + max-width: 40em; + margin: 1in auto 1in auto; +} + +h1 { + font-size: 200%; + font-weight: bold; + color: maroon; +} + +h2 { + font-size: 160%; + font-weight: bold; + color: maroon; +} + +h3 { + font-size: 120%; + font-weight: bold; + color: maroon; +} Modified: branches/1.1/man/vcl.7 =================================================================== --- branches/1.1/man/vcl.7 2007-07-05 16:10:46 UTC (rev 1655) +++ branches/1.1/man/vcl.7 2007-07-05 16:11:13 UTC (rev 1656) @@ -360,6 +360,9 @@ .Bl -tag -width 4n .It Va client.ip The client's IP address. +.It Va server.ip +The IP address of the socket on which the client connection was +received. .It Va req.request The request type (e.g. "GET", "HEAD"). .It Va req.url From phk at projects.linpro.no Thu Jul 5 21:08:15 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 5 Jul 2007 23:08:15 +0200 (CEST) Subject: r1657 - trunk/varnish-cache/lib/libvcl Message-ID: <20070705210815.CDFAA1EC030@projects.linpro.no> Author: phk Date: 2007-07-05 23:08:15 +0200 (Thu, 05 Jul 2007) New Revision: 1657 Modified: trunk/varnish-cache/lib/libvcl/syntax.txt trunk/varnish-cache/lib/libvcl/vcc_acl.c trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c trunk/varnish-cache/lib/libvcl/vcc_var.c trunk/varnish-cache/lib/libvcl/vcc_xref.c Log: Clean up FlexeLint fluff. Modified: trunk/varnish-cache/lib/libvcl/syntax.txt =================================================================== --- trunk/varnish-cache/lib/libvcl/syntax.txt 2007-07-05 16:11:13 UTC (rev 1656) +++ trunk/varnish-cache/lib/libvcl/syntax.txt 2007-07-05 21:08:15 UTC (rev 1657) @@ -128,6 +128,7 @@ 'call' ident ';' 'rewrite' cstr cstr ';' 'set' assignment ';' + 'remove' variable ';' # see variable 'returns' in vcc_gen_fixed_token.tcl return_action: @@ -162,6 +163,7 @@ '-=' cnum '=' cnum + ratio: '*=' double '/=' double Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_acl.c 2007-07-05 16:11:13 UTC (rev 1656) +++ trunk/varnish-cache/lib/libvcl/vcc_acl.c 2007-07-05 21:08:15 UTC (rev 1657) @@ -30,13 +30,13 @@ */ #include -#include #include #include "vsb.h" #include "vcc_priv.h" #include "vcc_compile.h" +#include "libvarnish.h" static void vcc_acl_top(struct tokenlist *tl, const char *acln) @@ -108,7 +108,7 @@ } void -vcc_Cond_Ip(struct var *vp, struct tokenlist *tl) +vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl) { unsigned tcond; char *acln; Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-05 16:11:13 UTC (rev 1656) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-05 21:08:15 UTC (rev 1657) @@ -94,7 +94,7 @@ /*--------------------------------------------------------------------*/ static void -illegal_assignment(struct tokenlist *tl, const char *type) +illegal_assignment(const struct tokenlist *tl, const char *type) { vsb_printf(tl->sb, "Invalid assignment operator "); @@ -104,7 +104,7 @@ } static void -check_writebit(struct tokenlist *tl, struct var *vp) +check_writebit(struct tokenlist *tl, const struct var *vp) { if (vp->access == V_RW || vp->access == V_WO) @@ -195,13 +195,12 @@ vcc_NextToken(tl); Fb(tl, 0, ");\n"); break; - return; case HASH: ExpectErr(tl, T_INCR); vcc_NextToken(tl); vcc_StringVal(tl); Fb(tl, 0, ");\n"); - return; + break; case STRING: if (tl->t->tok != '=') { illegal_assignment(tl, "strings"); @@ -209,7 +208,7 @@ } vcc_NextToken(tl); vcc_StringVal(tl); - if (vp->ishdr) { + if (vp->hdr != NULL) { while (tl->t->tok != ';') { Fb(tl, 0, ", "); vcc_StringVal(tl); @@ -232,13 +231,13 @@ parse_remove(struct tokenlist *tl) { struct var *vp; - struct token *vt; vcc_NextToken(tl); ExpectErr(tl, VAR); - vt = tl->t; vp = vcc_FindVar(tl, tl->t, vcc_vars); - if (vp->fmt != STRING || !vp->ishdr) { + ERRCHK(tl); + assert(vp != NULL); + if (vp->fmt != STRING || vp->hdr == NULL) { vsb_printf(tl->sb, "Only http header lines can be removed.\n"); vcc_ErrWhere(tl, tl->t); return; Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-07-05 16:11:13 UTC (rev 1656) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-07-05 21:08:15 UTC (rev 1657) @@ -86,7 +86,7 @@ #include "vcl_returns.h" #undef VCL_MET_MAC #undef VCL_RET_MAC - { NULL, 0U } + { NULL, 0U, 0} }; /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-05 16:11:13 UTC (rev 1656) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-05 21:08:15 UTC (rev 1657) @@ -121,7 +121,7 @@ const char *rname; const char *lname; enum {V_RO, V_RW, V_WO} access; - char ishdr; + const char *hdr; unsigned methods; }; @@ -136,7 +136,7 @@ /* vcc_acl.c */ void vcc_Acl(struct tokenlist *tl); -void vcc_Cond_Ip(struct var *vp, struct tokenlist *tl); +void vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl); /* vcc_action.c */ void vcc_ParseAction(struct tokenlist *tl); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-05 16:11:13 UTC (rev 1656) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-05 21:08:15 UTC (rev 1657) @@ -32,9 +32,9 @@ # Objects available in backends set beobj { - { backend.host WO HOSTNAME } - { backend.port WO PORTNAME } - { backend.dnsttl WO TIME } + { backend.host WO HOSTNAME {} } + { backend.port WO PORTNAME {} } + { backend.dnsttl WO TIME {} } } # Variables available in sessions @@ -70,6 +70,7 @@ { req.http. RW HEADER {recv pipe pass hash miss hit fetch } + HDR_REQ } # Possibly misnamed, not really part of the request @@ -98,6 +99,7 @@ { bereq.http. RW HEADER { pipe pass miss } + HDR_BEREQ } # The (possibly) cached object @@ -116,6 +118,7 @@ { obj.http. RW HEADER { hit fetch } + HDR_OBJ } { obj.valid @@ -151,6 +154,7 @@ { resp.http. RW HEADER { deliver } + HDR_RESP } # Miscellaneous @@ -200,6 +204,9 @@ append l " | " append l VCL_MET_[string toupper $i] } + if {$l == ""} { + return "0" + } return [string range $l 3 end] } @@ -231,7 +238,11 @@ puts $fo "\t NULL," } puts $fo "\t V_$a," - puts $fo "\t 0," + if {$t != "HEADER"} { + puts $fo "\t 0," + } else { + puts $fo "\t \"[lindex $v 4]\"," + } puts $fo "\t [method_map [lindex $v 3]]" puts $fo "\t\}," Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-05 16:11:13 UTC (rev 1656) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-05 21:08:15 UTC (rev 1657) @@ -15,21 +15,21 @@ "VRT_l_backend_host(backend, ", V_WO, 0, - + 0 }, { "backend.port", PORTNAME, 12, NULL, "VRT_l_backend_port(backend, ", V_WO, 0, - + 0 }, { "backend.dnsttl", TIME, 14, NULL, "VRT_l_backend_dnsttl(backend, ", V_WO, 0, - + 0 }, { NULL } }; @@ -74,7 +74,7 @@ "VRT_r_req_http_(sp)", "VRT_l_req_http_(sp, ", V_RW, - 0, + "HDR_REQ", VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.hash", HASH, 8, @@ -116,7 +116,7 @@ "VRT_r_bereq_http_(sp)", "VRT_l_bereq_http_(sp, ", V_RW, - 0, + "HDR_BEREQ", VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS }, { "obj.proto", STRING, 9, @@ -144,7 +144,7 @@ "VRT_r_obj_http_(sp)", "VRT_l_obj_http_(sp, ", V_RW, - 0, + "HDR_OBJ", VCL_MET_HIT | VCL_MET_FETCH }, { "obj.valid", BOOL, 9, @@ -200,7 +200,7 @@ "VRT_r_resp_http_(sp)", "VRT_l_resp_http_(sp, ", V_RW, - 0, + "HDR_RESP", VCL_MET_DELIVER }, { "now", TIME, 3, Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-05 16:11:13 UTC (rev 1656) +++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-05 21:08:15 UTC (rev 1657) @@ -57,6 +57,7 @@ ERRCHK(tl); vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); + assert(vp != NULL); switch (vp->fmt) { case STRING: Fb(tl, 0, "%s", vp->rname); @@ -77,7 +78,6 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh) { char *p; - const char *wh; struct var *v; int i; @@ -93,23 +93,13 @@ v->name = p; v->access = V_RW; v->fmt = STRING; - v->ishdr = 1; + v->hdr = vh->hdr; v->methods = vh->methods; - if (!memcmp(vh->name, "req.", 4)) - wh = "HDR_REQ"; - else if (!memcmp(vh->name, "resp.", 5)) - wh = "HDR_RESP"; - else if (!memcmp(vh->name, "obj.", 4)) - wh = "HDR_OBJ"; - else if (!memcmp(vh->name, "bereq.", 6)) - wh = "HDR_BEREQ"; - else - assert(0 == 1); - asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", wh, + asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); v->rname = p; - asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", wh, + asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); v->lname = p; Modified: trunk/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_xref.c 2007-07-05 16:11:13 UTC (rev 1656) +++ trunk/varnish-cache/lib/libvcl/vcc_xref.c 2007-07-05 21:08:15 UTC (rev 1657) @@ -328,7 +328,7 @@ } static struct procuse * -vcc_FindIllegalUse(struct proc *p, struct method *m) +vcc_FindIllegalUse(const struct proc *p, const struct method *m) { struct procuse *pu; @@ -339,7 +339,7 @@ } static int -vcc_CheckUseRecurse(struct tokenlist *tl, struct proc *p, struct method *m) +vcc_CheckUseRecurse(struct tokenlist *tl, const struct proc *p, struct method *m) { struct proccall *pc; struct procuse *pu; From phk at projects.linpro.no Fri Jul 6 10:07:30 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 6 Jul 2007 12:07:30 +0200 (CEST) Subject: r1658 - trunk/varnish-cache/bin/varnishd Message-ID: <20070706100730.AEAE41EC1F5@projects.linpro.no> Author: phk Date: 2007-07-06 12:07:30 +0200 (Fri, 06 Jul 2007) New Revision: 1658 Modified: trunk/varnish-cache/bin/varnishd/cache_http.c Log: Don't rewrite pipe'ed requests to "GET". Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-05 21:08:15 UTC (rev 1657) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-06 10:07:30 UTC (rev 1658) @@ -709,12 +709,15 @@ } static void -http_getreq(struct http *to, struct http *fm) +http_copyreq(struct http *to, struct http *fm, int forceget) { CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - http_seth(to, HTTP_HDR_REQ, "GET"); + if (forceget) + http_seth(to, HTTP_HDR_REQ, "GET"); + else + http_copyh(to, fm, HTTP_HDR_REQ); http_copyh(to, fm, HTTP_HDR_URL); http_seth(to, HTTP_HDR_PROTO, "HTTP/1.1"); } @@ -797,7 +800,7 @@ hp = bereq->http; hp->logtag = HTTP_Tx; - http_getreq(hp, sp->http); + http_copyreq(hp, sp->http, how != HTTPH_R_PIPE); http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how); http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); http_PrintfHeader(sp->wrk, sp->fd, hp, From phk at projects.linpro.no Mon Jul 9 20:23:41 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 9 Jul 2007 22:23:41 +0200 (CEST) Subject: r1659 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070709202341.628001EC1F5@projects.linpro.no> Author: phk Date: 2007-07-09 22:23:41 +0200 (Mon, 09 Jul 2007) New Revision: 1659 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/shmlog_tags.h trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: Make all protocol header fields writable, except obj.status and resp.status (which are numeric, they'll follow shortly) Unify the shmemlog tag used for failure to rewrite something, the Rx/Tx/Obj distinction is not helpful enough to warrant the complexity of it. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-06 10:07:30 UTC (rev 1658) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-09 20:23:41 UTC (rev 1659) @@ -412,6 +412,7 @@ void http_PutResponse(struct worker *w, int fd, struct http *to, const char *response); void http_PrintfHeader(struct worker *w, int fd, struct http *to, const char *fmt, ...); void http_SetHeader(struct worker *w, int fd, struct http *to, const char *hdr); +void http_SetH(struct http *to, unsigned n, const char *fm); void http_Setup(struct http *ht, void *space, unsigned len); int http_GetHdr(struct http *hp, const char *hdr, char **ptr); int http_GetHdrField(struct http *hp, const char *hdr, const char *field, char **ptr); @@ -428,7 +429,6 @@ void http_DoConnection(struct sess *sp); void http_CopyHome(struct worker *w, int fd, struct http *hp); void http_Unset(struct http *hp, const char *hdr); -void http_LogLostHeader(struct worker *w, int fd, struct http *hp, const char *hdr); #define HTTPH(a, b, c, d, e, f, g) extern char b[]; Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-06 10:07:30 UTC (rev 1658) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-09 20:23:41 UTC (rev 1659) @@ -58,7 +58,6 @@ HTTP_T_URL, HTTP_T_Protocol, HTTP_T_Header, - HTTP_T_LostHeader, }; #define LOGMTX2(ax, bx) \ @@ -71,7 +70,6 @@ LOGMTX2(ax, URL), \ LOGMTX2(ax, Protocol), \ LOGMTX2(ax, Header), \ - LOGMTX2(ax, LostHeader) \ } static enum shmlogtag logmtx[3][7] = { @@ -86,7 +84,7 @@ CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); assert(/* hp->logtag >= HTTP_Rx && */hp->logtag <= HTTP_Obj); - assert(/* t >= HTTP_T_Request && */t <= HTTP_T_LostHeader); + assert(/* t >= HTTP_T_Request && */t <= HTTP_T_Header); return (logmtx[hp->logtag][t]); } @@ -97,12 +95,6 @@ WSLR(w, http2shmlog(hp, t), fd, hp->hd[hdr].b, hp->hd[hdr].e); } -void -http_LogLostHeader(struct worker *w, int fd, struct http *hp, const char *hdr) -{ - WSLR(w, http2shmlog(hp, HTTP_T_LostHeader), fd, hdr + 1, hdr + hdr[0]); -} - /*--------------------------------------------------------------------*/ /* List of canonical HTTP response code names from RFC2616 */ @@ -430,7 +422,7 @@ hp->nhd++; } else { VSL_stats->losthdr++; - WSLR(w, http2shmlog(hp, HTTP_T_LostHeader), fd, p, q); + WSLR(w, SLT_LostHeader, fd, p, q); } } return (0); @@ -686,8 +678,8 @@ /*--------------------------------------------------------------------*/ -static void -http_seth(struct http *to, unsigned n, const char *fm) +void +http_SetH(struct http *to, unsigned n, const char *fm) { assert(n < HTTP_HDR_MAX); @@ -715,11 +707,11 @@ CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); if (forceget) - http_seth(to, HTTP_HDR_REQ, "GET"); + http_SetH(to, HTTP_HDR_REQ, "GET"); else http_copyh(to, fm, HTTP_HDR_REQ); http_copyh(to, fm, HTTP_HDR_URL); - http_seth(to, HTTP_HDR_PROTO, "HTTP/1.1"); + http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1"); } void @@ -729,7 +721,7 @@ CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); if (params->client_http11) - http_seth(to, HTTP_HDR_PROTO, "HTTP/1.1"); + http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1"); else http_copyh(to, fm, HTTP_HDR_PROTO); http_copyh(to, fm, HTTP_HDR_STATUS); @@ -741,9 +733,9 @@ { CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - http_seth(to, HTTP_HDR_PROTO, proto); - http_seth(to, HTTP_HDR_STATUS, status); - http_seth(to, HTTP_HDR_RESPONSE, response); + http_SetH(to, HTTP_HDR_PROTO, proto); + http_SetH(to, HTTP_HDR_STATUS, status); + http_SetH(to, HTTP_HDR_RESPONSE, response); } static void @@ -760,7 +752,7 @@ to->nhd++; } else { VSL_stats->losthdr++; - WSLH(w, HTTP_T_LostHeader, fd, fm, n); + WSLH(w, SLT_LostHeader, fd, fm, n); } } @@ -853,7 +845,7 @@ hp->hd[u].b = p; hp->hd[u].e = p + l; } else { - WSLH(w, HTTP_T_LostHeader, fd, hp, u); + WSLH(w, SLT_LostHeader, fd, hp, u); hp->hd[u].b = NULL; hp->hd[u].e = NULL; } @@ -881,10 +873,10 @@ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); if (to->nhd >= HTTP_HDR_MAX) { VSL_stats->losthdr++; - WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", hdr); + WSL(w, SLT_LostHeader, fd, "%s", hdr); return; } - http_seth(to, to->nhd++, hdr); + http_SetH(to, to->nhd++, hdr); } /*--------------------------------------------------------------------*/ @@ -901,7 +893,7 @@ l = (e - string); p = WS_Alloc(to->ws, l + 1); if (p == NULL) { - WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", string); + WSL(w, SLT_LostHeader, fd, "%s", string); to->hd[field].b = NULL; to->hd[field].e = NULL; } else { @@ -948,7 +940,7 @@ va_end(ap); if (n + 1 >= l || to->nhd >= HTTP_HDR_MAX) { VSL_stats->losthdr++; - WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", to->ws->f); + WSL(w, SLT_LostHeader, fd, "%s", to->ws->f); WS_Release(to->ws, 0); } else { to->hd[to->nhd].b = to->ws->f; Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-06 10:07:30 UTC (rev 1658) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-09 20:23:41 UTC (rev 1659) @@ -112,14 +112,41 @@ /*--------------------------------------------------------------------*/ +static char * +vrt_assemble_string(struct http *hp, const char *p, va_list ap) +{ + char *b, *e; + unsigned u, x; + + u = WS_Reserve(hp->ws, 0); + e = b = hp->ws->f; + *e = '\0'; + while (p != NULL) { + x = strlen(p); + if (x + 1 < u) + memcpy(e, p, x); + e += x; + p = va_arg(ap, const char *); + } + *e = '\0'; + if (e > b + u) { + WS_Release(hp->ws, 0); + return (NULL); + } else { + WS_Release(hp->ws, 1 + e - b); + return (b); + } +} + +/*--------------------------------------------------------------------*/ + void VRT_SetHdr(struct sess *sp , enum gethdr_e where, const char *hdr, ...) { struct http *hp; va_list ap; const char *p; - char *b, *e; - unsigned u, x; + char *b; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); hp = vrt_selecthttp(sp, where); @@ -128,29 +155,10 @@ if (p == NULL) { http_Unset(hp, hdr); } else { - u = WS_Reserve(hp->ws, 0); - e = b = hp->ws->f; - *e = '\0'; - x = strlen(hdr + 1); - if (x + 1 < u) - memcpy(e, hdr + 1, x); - e += x; - if (1 + 1 < u) - *e++ = ' '; - while (p != NULL) { - x = strlen(p); - if (x + 1 < u) - memcpy(e, p, x); - e += x; - p = va_arg(ap, const char *); - } - *e = '\0'; - if (e > b + u) { - http_LogLostHeader(sp->wrk, sp->fd, hp, hdr); - WS_Release(hp->ws, 0); - + b = vrt_assemble_string(hp, p, ap); + if (b == NULL) { + VSL(SLT_LostHeader, sp->fd, hdr + 1); } else { - WS_Release(hp->ws, 1 + e - b); http_Unset(hp, hdr); http_SetHeader(sp->wrk, sp->fd, hp, b); } @@ -160,6 +168,52 @@ /*--------------------------------------------------------------------*/ +static void +vrt_do_string(struct worker *w, int fd, struct http *hp, int fld, const char *err, const char *p, va_list ap) +{ + char *b; + + AN(p); + AN(hp); + b = vrt_assemble_string(hp, p, ap); + if (b == NULL) { + WSL(w, SLT_LostHeader, fd, err); + } else { + http_SetH(hp, fld, b); + } + va_end(ap); +} + +#define VRT_DO_HDR(obj, hdr, http, fld) \ +void \ +VRT_l_##obj##_##hdr(struct sess *sp, const char *p, ...) \ +{ \ + va_list ap; \ + \ + AN(p); \ + va_start(ap, p); \ + vrt_do_string(sp->wrk, sp->fd, \ + http, fld, #obj "." #hdr, p, ap); \ + va_end(ap); \ +} + +VRT_DO_HDR(req, request, sp->http, HTTP_HDR_REQ) +VRT_DO_HDR(req, url, sp->http, HTTP_HDR_URL) +VRT_DO_HDR(req, proto, sp->http, HTTP_HDR_PROTO) +VRT_DO_HDR(bereq, request, sp->bereq->http, HTTP_HDR_REQ) +VRT_DO_HDR(bereq, url, sp->bereq->http, HTTP_HDR_URL) +VRT_DO_HDR(bereq, proto, sp->bereq->http, HTTP_HDR_PROTO) +VRT_DO_HDR(obj, proto, &sp->obj->http, HTTP_HDR_PROTO) +VRT_DO_HDR(obj, response, &sp->obj->http, HTTP_HDR_RESPONSE) +VRT_DO_HDR(resp, proto, sp->bereq->http, HTTP_HDR_PROTO) +VRT_DO_HDR(resp, response, sp->bereq->http, HTTP_HDR_RESPONSE) + +#if 0 +VRT_DO_HDR(obj, status, &sp->obj->http, HTTP_HDR_STATUS) +VRT_DO_HDR(resp, status, sp->bereq->http, HTTP_HDR_STATUS) +#endif +/*--------------------------------------------------------------------*/ + void VRT_handling(struct sess *sp, unsigned hand) { Modified: trunk/varnish-cache/include/shmlog_tags.h =================================================================== --- trunk/varnish-cache/include/shmlog_tags.h 2007-07-06 10:07:30 UTC (rev 1658) +++ trunk/varnish-cache/include/shmlog_tags.h 2007-07-09 20:23:41 UTC (rev 1659) @@ -62,7 +62,6 @@ SLTM(RxURL) SLTM(RxProtocol) SLTM(RxHeader) -SLTM(RxLostHeader) SLTM(TxRequest) SLTM(TxResponse) @@ -70,7 +69,6 @@ SLTM(TxURL) SLTM(TxProtocol) SLTM(TxHeader) -SLTM(TxLostHeader) SLTM(ObjRequest) SLTM(ObjResponse) @@ -78,8 +76,9 @@ SLTM(ObjURL) SLTM(ObjProtocol) SLTM(ObjHeader) -SLTM(ObjLostHeader) +SLTM(LostHeader) + SLTM(TTL) SLTM(VCL_acl) SLTM(VCL_call) Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2007-07-06 10:07:30 UTC (rev 1658) +++ trunk/varnish-cache/include/vrt_obj.h 2007-07-09 20:23:41 UTC (rev 1659) @@ -12,23 +12,26 @@ struct sockaddr * VRT_r_client_ip(struct sess *); struct sockaddr * VRT_r_server_ip(struct sess *); const char * VRT_r_req_request(struct sess *); +void VRT_l_req_request(struct sess *, const char *, ...); const char * VRT_r_req_url(struct sess *); +void VRT_l_req_url(struct sess *, const char *, ...); const char * VRT_r_req_proto(struct sess *); +void VRT_l_req_proto(struct sess *, const char *, ...); void VRT_l_req_hash(struct sess *, const char *); struct backend * VRT_r_req_backend(struct sess *); void VRT_l_req_backend(struct sess *, struct backend *); const char * VRT_r_bereq_request(struct sess *); -void VRT_l_bereq_request(struct sess *, const char *); +void VRT_l_bereq_request(struct sess *, const char *, ...); const char * VRT_r_bereq_url(struct sess *); -void VRT_l_bereq_url(struct sess *, const char *); +void VRT_l_bereq_url(struct sess *, const char *, ...); const char * VRT_r_bereq_proto(struct sess *); -void VRT_l_bereq_proto(struct sess *, const char *); +void VRT_l_bereq_proto(struct sess *, const char *, ...); const char * VRT_r_obj_proto(struct sess *); -void VRT_l_obj_proto(struct sess *, const char *); +void VRT_l_obj_proto(struct sess *, const char *, ...); int VRT_r_obj_status(struct sess *); void VRT_l_obj_status(struct sess *, int); const char * VRT_r_obj_response(struct sess *); -void VRT_l_obj_response(struct sess *, const char *); +void VRT_l_obj_response(struct sess *, const char *, ...); unsigned VRT_r_obj_valid(struct sess *); void VRT_l_obj_valid(struct sess *, unsigned); unsigned VRT_r_obj_cacheable(struct sess *); @@ -37,9 +40,9 @@ void VRT_l_obj_ttl(struct sess *, double); double VRT_r_obj_lastuse(struct sess *); const char * VRT_r_resp_proto(struct sess *); -void VRT_l_resp_proto(struct sess *, const char *); +void VRT_l_resp_proto(struct sess *, const char *, ...); int VRT_r_resp_status(struct sess *); void VRT_l_resp_status(struct sess *, int); const char * VRT_r_resp_response(struct sess *); -void VRT_l_resp_response(struct sess *, const char *); +void VRT_l_resp_response(struct sess *, const char *, ...); double VRT_r_now(struct sess *); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-06 10:07:30 UTC (rev 1658) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-09 20:23:41 UTC (rev 1659) @@ -208,14 +208,11 @@ } vcc_NextToken(tl); vcc_StringVal(tl); - if (vp->hdr != NULL) { - while (tl->t->tok != ';') { - Fb(tl, 0, ", "); - vcc_StringVal(tl); - } - Fb(tl, 0, ", 0"); + while (tl->t->tok != ';') { + Fb(tl, 0, ", "); + vcc_StringVal(tl); } - Fb(tl, 0, ");\n"); + Fb(tl, 0, ", 0);\n"); break; default: vsb_printf(tl->sb, Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-06 10:07:30 UTC (rev 1658) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-09 20:23:41 UTC (rev 1659) @@ -461,23 +461,26 @@ vsb_cat(sb, "struct sockaddr * VRT_r_client_ip(struct sess *);\n"); vsb_cat(sb, "struct sockaddr * VRT_r_server_ip(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_req_request(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_req_request(struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_req_url(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_req_url(struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_req_proto(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_req_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n"); vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n"); vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n"); vsb_cat(sb, "const char * VRT_r_bereq_request(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_bereq_request(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_bereq_request(struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_bereq_url(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_bereq_url(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_bereq_url(struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_bereq_proto(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_bereq_proto(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_bereq_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_obj_proto(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_proto(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_obj_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "int VRT_r_obj_status(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_status(struct sess *, int);\n"); vsb_cat(sb, "const char * VRT_r_obj_response(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_response(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_obj_response(struct sess *, const char *, ...);\n"); vsb_cat(sb, "unsigned VRT_r_obj_valid(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_valid(struct sess *, unsigned);\n"); vsb_cat(sb, "unsigned VRT_r_obj_cacheable(struct sess *);\n"); @@ -486,10 +489,10 @@ vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n"); vsb_cat(sb, "double VRT_r_obj_lastuse(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n"); vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n"); vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *, ...);\n"); vsb_cat(sb, "double VRT_r_now(struct sess *);\n"); } Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-06 10:07:30 UTC (rev 1658) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-09 20:23:41 UTC (rev 1659) @@ -56,15 +56,15 @@ # Request paramters { req.request - RO STRING + RW STRING {recv pipe pass hash miss hit fetch } } { req.url - RO STRING + RW STRING {recv pipe pass hash miss hit fetch } } { req.proto - RO STRING + RW STRING {recv pipe pass hash miss hit fetch } } { req.http. @@ -231,7 +231,10 @@ } if {$a == "WO" || $a == "RW"} { puts $fo "\t \"VRT_l_${m}($pa, \"," - if {$t != "HEADER"} { + if {$t == "HEADER"} { + } elseif {$t == "STRING"} { + puts $fp "void VRT_l_${m}($ty, $tt($t), ...);" + } else { puts $fp "void VRT_l_${m}($ty, $tt($t));" } } else { Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-06 10:07:30 UTC (rev 1658) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-09 20:23:41 UTC (rev 1659) @@ -51,22 +51,22 @@ }, { "req.request", STRING, 11, "VRT_r_req_request(sp)", - NULL, - V_RO, + "VRT_l_req_request(sp, ", + V_RW, 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.url", STRING, 7, "VRT_r_req_url(sp)", - NULL, - V_RO, + "VRT_l_req_url(sp, ", + V_RW, 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.proto", STRING, 9, "VRT_r_req_proto(sp)", - NULL, - V_RO, + "VRT_l_req_proto(sp, ", + V_RW, 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, From phk at projects.linpro.no Mon Jul 9 20:34:59 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 9 Jul 2007 22:34:59 +0200 (CEST) Subject: r1660 - trunk/varnish-cache/lib/libvcl Message-ID: <20070709203459.A87121EC45F@projects.linpro.no> Author: phk Date: 2007-07-09 22:34:59 +0200 (Mon, 09 Jul 2007) New Revision: 1660 Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c Log: Allow assignment to INT type variables Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-09 20:23:41 UTC (rev 1659) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-09 20:34:59 UTC (rev 1660) @@ -155,6 +155,8 @@ vcc_RateVal(tl); else if (vp->fmt == FLOAT) Fb(tl, 0, "%g", vcc_DoubleVal(tl)); + else if (vp->fmt == INT) + Fb(tl, 0, "%u", vcc_UintVal(tl)); else { vsb_printf(tl->sb, "Cannot assign this variable type.\n"); vcc_ErrWhere(tl, vt); From phk at projects.linpro.no Mon Jul 9 20:35:21 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 9 Jul 2007 22:35:21 +0200 (CEST) Subject: r1661 - trunk/varnish-cache/bin/varnishd Message-ID: <20070709203521.1140F1EC1F5@projects.linpro.no> Author: phk Date: 2007-07-09 22:35:20 +0200 (Mon, 09 Jul 2007) New Revision: 1661 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Allow assignment to obj.status and resp.status Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-09 20:34:59 UTC (rev 1660) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-09 20:35:20 UTC (rev 1661) @@ -205,13 +205,37 @@ VRT_DO_HDR(bereq, proto, sp->bereq->http, HTTP_HDR_PROTO) VRT_DO_HDR(obj, proto, &sp->obj->http, HTTP_HDR_PROTO) VRT_DO_HDR(obj, response, &sp->obj->http, HTTP_HDR_RESPONSE) -VRT_DO_HDR(resp, proto, sp->bereq->http, HTTP_HDR_PROTO) -VRT_DO_HDR(resp, response, sp->bereq->http, HTTP_HDR_RESPONSE) +VRT_DO_HDR(resp, proto, sp->http, HTTP_HDR_PROTO) +VRT_DO_HDR(resp, response, sp->http, HTTP_HDR_RESPONSE) -#if 0 -VRT_DO_HDR(obj, status, &sp->obj->http, HTTP_HDR_STATUS) -VRT_DO_HDR(resp, status, sp->bereq->http, HTTP_HDR_STATUS) -#endif +void +VRT_l_obj_status(struct sess *sp, int num) +{ + char *p; + + assert(num >= 100 && num <= 999); + p = WS_Alloc(sp->obj->http.ws, 4); + if (p == NULL) + WSL(sp->wrk, SLT_LostHeader, sp->fd, "obj.status"); + else + sprintf(p, "%d", num); + http_SetH(&sp->obj->http, HTTP_HDR_STATUS, p); +} + +void +VRT_l_resp_status(struct sess *sp, int num) +{ + char *p; + + assert(num >= 100 && num <= 999); + p = WS_Alloc(sp->http->ws, 4); + if (p == NULL) + WSL(sp->wrk, SLT_LostHeader, sp->fd, "resp.status"); + else + sprintf(p, "%d", num); + http_SetH(sp->http, HTTP_HDR_STATUS, p); +} + /*--------------------------------------------------------------------*/ void From phk at projects.linpro.no Tue Jul 10 19:46:17 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 10 Jul 2007 21:46:17 +0200 (CEST) Subject: r1662 - trunk/varnish-cache/lib/libvcl Message-ID: <20070710194617.42F2C1EC45F@projects.linpro.no> Author: phk Date: 2007-07-10 21:46:16 +0200 (Tue, 10 Jul 2007) New Revision: 1662 Added: trunk/varnish-cache/lib/libvcl/vcc_string.c Modified: trunk/varnish-cache/lib/libvcl/Makefile.am trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_var.c Log: Move string stuff to vcc_string.c, there's going to be a fair bit of it. Give vcc_StringVal() a return value to say if it did anything so we can emit better error messages when confused. Modified: trunk/varnish-cache/lib/libvcl/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvcl/Makefile.am 2007-07-09 20:35:20 UTC (rev 1661) +++ trunk/varnish-cache/lib/libvcl/Makefile.am 2007-07-10 19:46:16 UTC (rev 1662) @@ -16,6 +16,7 @@ vcc_parse.c \ vcc_fixed_token.c \ vcc_obj.c \ + vcc_string.c \ vcc_token.c \ vcc_var.c \ vcc_xref.c Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-09 20:35:20 UTC (rev 1661) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-10 19:46:16 UTC (rev 1662) @@ -200,7 +200,11 @@ case HASH: ExpectErr(tl, T_INCR); vcc_NextToken(tl); - vcc_StringVal(tl); + if (!vcc_StringVal(tl)) { + ERRCHK(tl); + vcc_ExpectedStringval(tl); + return; + } Fb(tl, 0, ");\n"); break; case STRING: @@ -209,12 +213,22 @@ return; } vcc_NextToken(tl); - vcc_StringVal(tl); - while (tl->t->tok != ';') { + if (!vcc_StringVal(tl)) { + ERRCHK(tl); + vcc_ExpectedStringval(tl); + return; + } + do Fb(tl, 0, ", "); - vcc_StringVal(tl); + while (vcc_StringVal(tl)); + if (tl->t->tok != ';') { + ERRCHK(tl); + vsb_printf(tl->sb, + "Expected variable, string or semicolon\n"); + vcc_ErrWhere(tl, tl->t); + return; } - Fb(tl, 0, ", 0);\n"); + Fb(tl, 0, "0);\n"); break; default: vsb_printf(tl->sb, Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-09 20:35:20 UTC (rev 1661) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-10 19:46:16 UTC (rev 1662) @@ -167,6 +167,10 @@ unsigned vcc_UintVal(struct tokenlist *tl); double vcc_DoubleVal(struct tokenlist *tl); +/* vcc_string.c */ +int vcc_StringVal(struct tokenlist *tl); +void vcc_ExpectedStringval(struct tokenlist *tl); + /* vcc_token.c */ void vcc_ErrToken(const struct tokenlist *tl, const struct token *t); void vcc_ErrWhere(struct tokenlist *tl, const struct token *t); @@ -180,7 +184,6 @@ void vcc_FreeToken(struct token *t); /* vcc_var.c */ -void vcc_StringVal(struct tokenlist *tl); struct var *vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl); /* vcc_xref.c */ Copied: trunk/varnish-cache/lib/libvcl/vcc_string.c (from rev 1658, trunk/varnish-cache/lib/libvcl/vcc_var.c) =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_string.c (rev 0) +++ trunk/varnish-cache/lib/libvcl/vcc_string.c 2007-07-10 19:46:16 UTC (rev 1662) @@ -0,0 +1,90 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2007 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * 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. + * + * $Id$ + */ + +#include +#include + +#include "vsb.h" + +#include "vcc_priv.h" +#include "vcc_compile.h" +#include "libvarnish.h" + +/*-------------------------------------------------------------------- + * Parse a string value and emit something that results in a usable + * "const char *". + * There are three possible outcomes: + * tl->err != 0 means something bad happened and a message is emitted. + * return (0) means "could not use this token" + * return (1) means "done" + */ + +int +vcc_StringVal(struct tokenlist *tl) +{ + struct var *vp; + + if (tl->t->tok == CSTR) { + EncToken(tl->fb, tl->t); + vcc_NextToken(tl); + return (1); + } + if (tl->t->tok == VAR) { + vp = vcc_FindVar(tl, tl->t, vcc_vars); + if (tl->err) + return (0); + assert(vp != NULL); + switch (vp->fmt) { + case STRING: + Fb(tl, 0, "%s", vp->rname); + break; + default: + vsb_printf(tl->sb, + "String representation of '%s' not implemented yet.\n", + vp->name); + vcc_ErrWhere(tl, tl->t); + return (0); + } + vcc_NextToken(tl); + return (1); + } + return (0); +} + +void +vcc_ExpectedStringval(struct tokenlist *tl) +{ + + if (!tl->err) { + vsb_printf(tl->sb, "Expected string variable or constant\n"); + vcc_ErrWhere(tl, tl->t); + } +} Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-09 20:35:20 UTC (rev 1661) +++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-10 19:46:16 UTC (rev 1662) @@ -40,40 +40,6 @@ /*--------------------------------------------------------------------*/ -void -vcc_StringVal(struct tokenlist *tl) -{ - struct var *vp; - - if (tl->t->tok == CSTR) { - EncToken(tl->fb, tl->t); - vcc_NextToken(tl); - return; - } else if (tl->t->tok != VAR) { - vsb_printf(tl->sb, "Expected string variable or constant\n"); - vcc_ErrWhere(tl, tl->t); - return; - } - ERRCHK(tl); - vp = vcc_FindVar(tl, tl->t, vcc_vars); - ERRCHK(tl); - assert(vp != NULL); - switch (vp->fmt) { - case STRING: - Fb(tl, 0, "%s", vp->rname); - break; - default: - vsb_printf(tl->sb, - "String representation of '%s' not implemented yet.\n", - vp->name); - vcc_ErrWhere(tl, tl->t); - return; - } - vcc_NextToken(tl); -} - -/*--------------------------------------------------------------------*/ - static struct var * HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh) { From phk at projects.linpro.no Tue Jul 10 19:59:39 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 10 Jul 2007 21:59:39 +0200 (CEST) Subject: r1663 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070710195939.4B0AB1EC2B1@projects.linpro.no> Author: phk Date: 2007-07-10 21:59:39 +0200 (Tue, 10 Jul 2007) New Revision: 1663 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_string.c Log: Add conversion from IP to string format to allow things like: set bereq.http.HeyYou = client.ip " asked for " req.url; Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-10 19:46:16 UTC (rev 1662) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-10 19:59:39 UTC (rev 1663) @@ -472,3 +472,19 @@ clock_gettime(CLOCK_MONOTONIC, &now); return (now.tv_sec - sp->obj->lru_stamp); } + +/*--------------------------------------------------------------------*/ + +char * +VRT_IP_string(struct sess *sp, struct sockaddr *sa) +{ + char h[64], p[8], *q; + + TCP_name(sa, sa->sa_len, h, sizeof h, p, sizeof p); + q = WS_Alloc(sp->http->ws, strlen(h) + strlen(p) + 2); + AN(q); + strcpy(q, h); + strcat(q, ":"); + strcat(q, p); + return (q); +} Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-07-10 19:46:16 UTC (rev 1662) +++ trunk/varnish-cache/include/vrt.h 2007-07-10 19:59:39 UTC (rev 1663) @@ -85,6 +85,7 @@ void VRT_free_backends(struct VCL_conf *cp); void VRT_fini_backend(struct backend *be); +char *VRT_IP_string(struct sess *sp, struct sockaddr *sa); #define VRT_done(sp, hand) \ do { \ Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-10 19:46:16 UTC (rev 1662) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-10 19:59:39 UTC (rev 1663) @@ -441,6 +441,7 @@ vsb_cat(sb, "void VRT_free_backends(struct VCL_conf *cp);\n"); vsb_cat(sb, "void VRT_fini_backend(struct backend *be);\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "char *VRT_IP_string(struct sess *sp, struct sockaddr *sa);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "#define VRT_done(sp, hand) \\\n"); vsb_cat(sb, " do { \\\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_string.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_string.c 2007-07-10 19:46:16 UTC (rev 1662) +++ trunk/varnish-cache/lib/libvcl/vcc_string.c 2007-07-10 19:59:39 UTC (rev 1663) @@ -66,6 +66,9 @@ case STRING: Fb(tl, 0, "%s", vp->rname); break; + case IP: + Fb(tl, 0, "VRT_IP_string(sp, %s)", vp->rname); + break; default: vsb_printf(tl->sb, "String representation of '%s' not implemented yet.\n", From phk at projects.linpro.no Tue Jul 10 20:07:07 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 10 Jul 2007 22:07:07 +0200 (CEST) Subject: r1664 - trunk/varnish-cache/bin/varnishd Message-ID: <20070710200707.F3DD71EC030@projects.linpro.no> Author: phk Date: 2007-07-10 22:07:07 +0200 (Tue, 10 Jul 2007) New Revision: 1664 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Properly emit the header name in VRT_SetHdr(); Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-10 19:59:39 UTC (rev 1663) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-10 20:07:07 UTC (rev 1664) @@ -113,7 +113,7 @@ /*--------------------------------------------------------------------*/ static char * -vrt_assemble_string(struct http *hp, const char *p, va_list ap) +vrt_assemble_string(struct http *hp, const char *h, const char *p, va_list ap) { char *b, *e; unsigned u, x; @@ -121,6 +121,15 @@ u = WS_Reserve(hp->ws, 0); e = b = hp->ws->f; *e = '\0'; + if (h != NULL) { + x = strlen(h); + if (x + 2 < u) { + memcpy(e, h, x); + e[x] = ' '; + e[x + 1] = '\0'; + } + e += x + 1; + } while (p != NULL) { x = strlen(p); if (x + 1 < u) @@ -141,21 +150,19 @@ /*--------------------------------------------------------------------*/ void -VRT_SetHdr(struct sess *sp , enum gethdr_e where, const char *hdr, ...) +VRT_SetHdr(struct sess *sp , enum gethdr_e where, const char *hdr, const char *p, ...) { struct http *hp; va_list ap; - const char *p; char *b; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); hp = vrt_selecthttp(sp, where); - va_start(ap, hdr); - p = va_arg(ap, const char *); + va_start(ap, p); if (p == NULL) { http_Unset(hp, hdr); } else { - b = vrt_assemble_string(hp, p, ap); + b = vrt_assemble_string(hp, hdr + 1, p, ap); if (b == NULL) { VSL(SLT_LostHeader, sp->fd, hdr + 1); } else { @@ -175,7 +182,7 @@ AN(p); AN(hp); - b = vrt_assemble_string(hp, p, ap); + b = vrt_assemble_string(hp, NULL, p, ap); if (b == NULL) { WSL(w, SLT_LostHeader, fd, err); } else { From phk at projects.linpro.no Tue Jul 10 20:08:39 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 10 Jul 2007 22:08:39 +0200 (CEST) Subject: r1665 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20070710200839.90D6B1EC471@projects.linpro.no> Author: phk Date: 2007-07-10 22:08:39 +0200 (Tue, 10 Jul 2007) New Revision: 1665 Modified: trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Fix VRT_SetHdr() prototype Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-07-10 20:07:07 UTC (rev 1664) +++ trunk/varnish-cache/include/vrt.h 2007-07-10 20:08:39 UTC (rev 1665) @@ -76,7 +76,7 @@ enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ }; char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *); -void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, ...); +void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, const char *, ...); void VRT_handling(struct sess *sp, unsigned hand); /* Backend related */ Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-10 20:07:07 UTC (rev 1664) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-10 20:08:39 UTC (rev 1665) @@ -432,7 +432,7 @@ vsb_cat(sb, "\n"); vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ };\n"); vsb_cat(sb, "char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);\n"); - vsb_cat(sb, "void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, ...);\n"); + vsb_cat(sb, "void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, const char *, ...);\n"); vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/* Backend related */\n"); From phk at projects.linpro.no Tue Jul 10 20:43:25 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 10 Jul 2007 22:43:25 +0200 (CEST) Subject: r1666 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070710204325.1508D1EC45F@projects.linpro.no> Author: phk Date: 2007-07-10 22:43:24 +0200 (Tue, 10 Jul 2007) New Revision: 1666 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_re.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_parse.c trunk/varnish-cache/lib/libvcl/vcc_string.c Log: Add compiler side support for regsub() but only a dummy function in VRT. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_re.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_re.c 2007-07-10 20:08:39 UTC (rev 1665) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_re.c 2007-07-10 20:43:24 UTC (rev 1666) @@ -45,14 +45,14 @@ #include "cache.h" void -VRT_re_init(void **rep, const char *re) +VRT_re_init(void **rep, const char *re, int sub) { regex_t *t; t = calloc(sizeof *t, 1); XXXAN(t); /* This was already check-compiled by the VCL compiler */ - AZ(regcomp(t, re, REG_EXTENDED | REG_NOSUB)); + AZ(regcomp(t, re, REG_EXTENDED | (sub ? 0 : REG_NOSUB))); *rep = t; } @@ -82,14 +82,14 @@ } int -VRT_re_test(struct vsb *sb, const char *re) +VRT_re_test(struct vsb *sb, const char *re, int sub) { int i; regex_t t; char buf[BUFSIZ]; memset(&t, 0, sizeof t); - i = regcomp(&t, re, REG_EXTENDED | REG_NOSUB); + i = regcomp(&t, re, REG_EXTENDED | (sub ? 0 : REG_NOSUB)); if (i == 0) { regfree(&t); return (0); @@ -99,3 +99,14 @@ regfree(&t); return (1); } + +char * +VRT_regsub(struct sess *sp, const char *str, void *re, const char *sub) +{ + static char foo[4] = "FOO"; + (void)sp; + (void)str; + (void)re; + (void)sub; + return (foo); +} Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-07-10 20:08:39 UTC (rev 1665) +++ trunk/varnish-cache/include/vrt.h 2007-07-10 20:43:24 UTC (rev 1666) @@ -64,10 +64,11 @@ void VRT_acl_fini(struct vrt_acl *); /* Regexp related */ -void VRT_re_init(void **, const char *); +void VRT_re_init(void **, const char *, int sub); void VRT_re_fini(void *); int VRT_re_match(const char *, void *re); -int VRT_re_test(struct vsb *, const char *); +int VRT_re_test(struct vsb *, const char *, int sub); +char *VRT_regsub(struct sess *sp, const char *, void *, const char *); void VRT_count(struct sess *, unsigned); int VRT_rewrite(const char *, const char *); Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-10 20:08:39 UTC (rev 1665) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-10 20:43:24 UTC (rev 1666) @@ -168,6 +168,7 @@ double vcc_DoubleVal(struct tokenlist *tl); /* vcc_string.c */ +char *vcc_regexp(struct tokenlist *tl, int sub); int vcc_StringVal(struct tokenlist *tl); void vcc_ExpectedStringval(struct tokenlist *tl); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-10 20:08:39 UTC (rev 1665) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-10 20:43:24 UTC (rev 1666) @@ -420,10 +420,11 @@ vsb_cat(sb, "void VRT_acl_fini(struct vrt_acl *);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/* Regexp related */\n"); - vsb_cat(sb, "void VRT_re_init(void **, const char *);\n"); + vsb_cat(sb, "void VRT_re_init(void **, const char *, int sub);\n"); vsb_cat(sb, "void VRT_re_fini(void *);\n"); vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n"); - vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *);\n"); + vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); + vsb_cat(sb, "char *VRT_regsub(struct sess *sp, const char *, void *, const char *);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "void VRT_count(struct sess *, unsigned);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-07-10 20:08:39 UTC (rev 1665) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-07-10 20:43:24 UTC (rev 1666) @@ -221,38 +221,16 @@ /*--------------------------------------------------------------------*/ static void -vcc_re(struct tokenlist *tl, const char *str, const struct token *re) -{ - char buf[32]; - - assert(re->tok == CSTR); - if (VRT_re_test(tl->sb, re->dec)) { - vcc_ErrWhere(tl, re); - return; - } - sprintf(buf, "VGC_re_%u", tl->recnt++); - - Fb(tl, 1, "VRT_re_match(%s, %s)\n", str, buf); - Fh(tl, 0, "void *%s;\n", buf); - Fi(tl, 0, "\tVRT_re_init(&%s, ",buf); - EncToken(tl->fi, re); - Fi(tl, 0, ");\n"); - Ff(tl, 0, "\tVRT_re_fini(%s);\n", buf); -} - - -/*--------------------------------------------------------------------*/ - -static void Cond_String(const struct var *vp, struct tokenlist *tl) { + char *p; switch (tl->t->tok) { case '~': vcc_NextToken(tl); - ExpectErr(tl, CSTR); - vcc_re(tl, vp->rname, tl->t); + p = vcc_regexp(tl, 0); vcc_NextToken(tl); + Fb(tl, 1, "VRT_re_match(%s, %s)\n", vp->rname, p); break; case T_EQ: case T_NEQ: Modified: trunk/varnish-cache/lib/libvcl/vcc_string.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_string.c 2007-07-10 20:08:39 UTC (rev 1665) +++ trunk/varnish-cache/lib/libvcl/vcc_string.c 2007-07-10 20:43:24 UTC (rev 1666) @@ -38,6 +38,75 @@ #include "vcc_compile.h" #include "libvarnish.h" +#include "vrt.h" + +/*--------------------------------------------------------------------*/ + +char * +vcc_regexp(struct tokenlist *tl, int sub) +{ + char buf[32], *p; + + Expect(tl, CSTR); + if (VRT_re_test(tl->sb, tl->t->dec, sub)) { + vcc_ErrWhere(tl, tl->t); + return (NULL); + } + sprintf(buf, "VGC_re_%u", tl->recnt++); + p = TlAlloc(tl, strlen(buf) + 1); + strcpy(p, buf); + + Fh(tl, 0, "void *%s;\n", buf); + Fi(tl, 0, "\tVRT_re_init(&%s, ",buf); + EncToken(tl->fi, tl->t); + Fi(tl, 0, ", %d);\n", sub); + Ff(tl, 0, "\tVRT_re_fini(%s);\n", buf); + return (p); +} + +/*--------------------------------------------------------------------*/ + +static int +vcc_regsub(struct tokenlist *tl) +{ + char *p; + + vcc_NextToken(tl); + + Fb(tl, 0, "VRT_regsub(sp, "); + + Expect(tl, '('); + vcc_NextToken(tl); + + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return (0); + } + + Expect(tl, ','); + vcc_NextToken(tl); + + Expect(tl, CSTR); + p = vcc_regexp(tl, 1); + vcc_NextToken(tl); + Fb(tl, 0, ", %s, ", p); + + Expect(tl, ','); + vcc_NextToken(tl); + + Expect(tl, CSTR); + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return (0); + } + + Expect(tl, ')'); + vcc_NextToken(tl); + Fb(tl, 0, ")"); + + return (1); +} + /*-------------------------------------------------------------------- * Parse a string value and emit something that results in a usable * "const char *". @@ -57,6 +126,8 @@ vcc_NextToken(tl); return (1); } + if (tl->t->tok == ID && vcc_IdIs(tl->t, "regsub")) + return (vcc_regsub(tl)); if (tl->t->tok == VAR) { vp = vcc_FindVar(tl, tl->t, vcc_vars); if (tl->err) From phk at projects.linpro.no Tue Jul 10 21:30:47 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 10 Jul 2007 23:30:47 +0200 (CEST) Subject: r1667 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070710213047.DC6F71EC464@projects.linpro.no> Author: phk Date: 2007-07-10 23:30:47 +0200 (Tue, 10 Jul 2007) New Revision: 1667 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_re.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Add "regsub" support for string manipulation. Notice this facility is subject to change! "regsub" is short for regular expression substitution and it is probably easiest to explain with some examples: sub vcl_recv { set req.url = regsub(req.url, "#.*", ""); } This will replace the requests URL with the output of the regsub() function regsub() takes three arguments: the string to be examined, a regular expression and a replacement string. In this case, everything after the first '#' is removed (replaced with nothing). The replacement string recognizes the following magic sequences: & - insert everything matched by the regexp $0 - ditto. $1 - replace with the first submatch of the regexp $2 - replace with the second submatch of the regexp ... $9 - replace with the ninth submatch of the regexp (The $0..$9 syntax was chosen over the \0...\9 syntax in order to avoid a nightmare of escape characters in the VCL source code. Arguments and suggestions are welcome). A more advanced example: set bereq.http.ClientIP = regsub(client.ip, "(.*):(.*)", "$2 $1"); The client.ip variable expands to IP:port number, for instance 127.0.0.1:54662 The regular expression "(.*):(.*)" results in the the following matches: & + $0 "127.0.0.1:54662" $1 "127.0.0.1" $2 "54662" So the replacement string "$2 $1" results in "54662 127.0.0.1" And the completed header which is sent to the backend will look like: "ClientIP: 54662 127.0.0.1" An even more advanced example would be: set bereq.http.magic = "Client IP = " regsub(client.ip, ":", " port = "); Where we also exploint the string concatenation ability of the "set" statement. The result string is built in the request workspace, so you may need to increase the workspace size if you do a lot of regsub()'s. Currently there is no decent error handling for running out of workspace. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_re.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_re.c 2007-07-10 20:43:24 UTC (rev 1666) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_re.c 2007-07-10 21:30:47 UTC (rev 1667) @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -100,13 +101,72 @@ return (1); } -char * +const char * VRT_regsub(struct sess *sp, const char *str, void *re, const char *sub) { - static char foo[4] = "FOO"; - (void)sp; - (void)str; - (void)re; - (void)sub; - return (foo); + regmatch_t pm[10]; + regex_t *t; + int i, l; + char *b, *p, *e; + unsigned u, x; + + AN(re); + t = re; + i = regexec(t, str, 10, pm, 0); + + /* If it didn't match, we can return the original string */ + if (i == REG_NOMATCH) + return(str); + + u = WS_Reserve(sp->http->ws, 0); + e = p = b = sp->http->ws->f; + e += u; + + /* Copy prefix to match */ + if (pm[0].rm_so > 0) { + if (p + pm[0].rm_so < e) + memcpy(p, str, pm[0].rm_so); + p += pm[0].rm_so; + } + + for ( ; *sub != '\0'; sub++ ) { + if (*sub == '&') { + l = pm[0].rm_eo - pm[0].rm_so; + if (l > 0) { + if (p + l < e) + memcpy(p, str + pm[0].rm_so, l); + p += l; + } + } else if (*sub == '$' && isdigit(sub[1])) { + x = sub[1] - '0'; + sub++; + l = pm[x].rm_eo - pm[x].rm_so; + if (l > 0) { + if (p + l < e) + memcpy(p, str + pm[x].rm_so, l); + p += l; + } + } else { + if (p + 1 < e) + *p = *sub; + p++; + } + } + + /* Copy suffix to match */ + l = strlen(str + pm[0].rm_eo); + if (l > 0) { + if (p + l < e) + memcpy(p, str + pm[0].rm_eo, l); + p += l; + } + if (p + 1 < e) + *p++ = '\0'; + xxxassert(p <= e); + if (p > e) { + WS_Release(sp->http->ws, 0); + return (str); + } + WS_Release(sp->http->ws, p - b); + return (b); } Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-07-10 20:43:24 UTC (rev 1666) +++ trunk/varnish-cache/include/vrt.h 2007-07-10 21:30:47 UTC (rev 1667) @@ -68,7 +68,7 @@ void VRT_re_fini(void *); int VRT_re_match(const char *, void *re); int VRT_re_test(struct vsb *, const char *, int sub); -char *VRT_regsub(struct sess *sp, const char *, void *, const char *); +const char *VRT_regsub(struct sess *sp, const char *, void *, const char *); void VRT_count(struct sess *, unsigned); int VRT_rewrite(const char *, const char *); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-10 20:43:24 UTC (rev 1666) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-10 21:30:47 UTC (rev 1667) @@ -424,7 +424,7 @@ vsb_cat(sb, "void VRT_re_fini(void *);\n"); vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n"); vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); - vsb_cat(sb, "char *VRT_regsub(struct sess *sp, const char *, void *, const char *);\n"); + vsb_cat(sb, "const char *VRT_regsub(struct sess *sp, const char *, void *, const char *);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "void VRT_count(struct sess *, unsigned);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); From phk at projects.linpro.no Thu Jul 12 09:04:55 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 12 Jul 2007 11:04:55 +0200 (CEST) Subject: r1668 - in trunk/varnish-cache: include lib/libvarnish Message-ID: <20070712090455.1CFA21EC1F6@projects.linpro.no> Author: phk Date: 2007-07-12 11:04:54 +0200 (Thu, 12 Jul 2007) New Revision: 1668 Modified: trunk/varnish-cache/include/libvarnish.h trunk/varnish-cache/lib/libvarnish/time.c Log: Add TIM_mono() and TIM_real() which return double representations of timestamps on a monotonic and the UTC timescales respectively. Doubles are much more convenient than timespecs for comparisons etc. Modified: trunk/varnish-cache/include/libvarnish.h =================================================================== --- trunk/varnish-cache/include/libvarnish.h 2007-07-10 21:30:47 UTC (rev 1667) +++ trunk/varnish-cache/include/libvarnish.h 2007-07-12 09:04:54 UTC (rev 1668) @@ -47,6 +47,8 @@ /* from libvarnish/time.c */ void TIM_format(time_t t, char *p); time_t TIM_parse(const char *p); +double TIM_mono(void); +double TIM_real(void); /* from libvarnish/version.c */ void varnish_version(const char *); Modified: trunk/varnish-cache/lib/libvarnish/time.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/time.c 2007-07-10 21:30:47 UTC (rev 1667) +++ trunk/varnish-cache/lib/libvarnish/time.c 2007-07-12 09:04:54 UTC (rev 1668) @@ -50,8 +50,30 @@ #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "libvarnish.h" +double +TIM_mono(void) +{ + struct timespec ts; + + assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); + return (ts.tv_sec + 1e-9 * ts.tv_nsec); +} + +double +TIM_real(void) +{ + struct timespec ts; + + assert(clock_gettime(CLOCK_REALTIME, &ts) == 0); + return (ts.tv_sec + 1e-9 * ts.tv_nsec); +} + void TIM_format(time_t t, char *p) { From phk at projects.linpro.no Thu Jul 12 09:25:07 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 12 Jul 2007 11:25:07 +0200 (CEST) Subject: r1669 - trunk/varnish-cache/bin/varnishd Message-ID: <20070712092507.D9C421EC030@projects.linpro.no> Author: phk Date: 2007-07-12 11:25:07 +0200 (Thu, 12 Jul 2007) New Revision: 1669 Modified: trunk/varnish-cache/bin/varnishd/mgt_event.c Log: Replace ev_now() with TIM_mono(). Modified: trunk/varnish-cache/bin/varnishd/mgt_event.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_event.c 2007-07-12 09:04:54 UTC (rev 1668) +++ trunk/varnish-cache/bin/varnishd/mgt_event.c 2007-07-12 09:25:07 UTC (rev 1669) @@ -37,10 +37,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "mgt.h" #include "mgt_event.h" #include "miniobj.h" @@ -76,19 +72,6 @@ /*--------------------------------------------------------------------*/ -static double -ev_now(void) -{ - double t; - struct timespec ts; - - assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); - t = ts.tv_sec + ts.tv_nsec * 1e-9; - return (t); -} - -/*--------------------------------------------------------------------*/ - static void ev_bh_update(void *priv, void *a, unsigned u) { @@ -265,7 +248,7 @@ e->magic = EV_MAGIC; /* before binheap_insert() */ if (e->timeout != 0.0) { - e->__when += ev_now() + e->timeout; + e->__when += TIM_mono() + e->timeout; binheap_insert(evb->binheap, e); assert(e->__binheap_idx > 0); } else { @@ -430,7 +413,7 @@ if (e != NULL) { CHECK_OBJ_NOTNULL(e, EV_MAGIC); assert(e->__binheap_idx == 1); - t = ev_now(); + t = TIM_mono(); if (e->__when <= t) return (ev_sched_timeout(evb, e, t)); tmo = (int)((e->__when - t) * 1e3); @@ -453,7 +436,7 @@ return (ev_sched_signal(evb)); if (i == 0) { assert(e != NULL); - t = ev_now(); + t = TIM_mono(); if (e->__when <= t) return (ev_sched_timeout(evb, e, t)); } From phk at projects.linpro.no Thu Jul 12 09:25:46 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 12 Jul 2007 11:25:46 +0200 (CEST) Subject: r1670 - trunk/varnish-cache/bin/varnishd Message-ID: <20070712092546.1344B1EC1F6@projects.linpro.no> Author: phk Date: 2007-07-12 11:25:45 +0200 (Thu, 12 Jul 2007) New Revision: 1670 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c Log: Replace Uptime() with TIM_mono() Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-12 09:25:07 UTC (rev 1669) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-07-12 09:25:45 UTC (rev 1670) @@ -48,10 +48,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "heritage.h" #include "shmlog.h" #include "cache.h" @@ -64,19 +60,7 @@ static MTX vbemtx; /*--------------------------------------------------------------------*/ -/* XXX: belongs a more general place */ -static double -Uptime(void) -{ - struct timespec ts; - - assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); - return (ts.tv_sec + ts.tv_nsec * 1e-9); -} - -/*--------------------------------------------------------------------*/ - struct bereq * vbe_new_bereq(void) { @@ -153,7 +137,7 @@ error = getaddrinfo(bp->hostname, bp->portname == NULL ? "http" : bp->portname, &hint, &res); - bp->dnstime = Uptime(); + bp->dnstime = TIM_mono(); if (error) { if (res != NULL) freeaddrinfo(res); @@ -207,7 +191,7 @@ } } - if (bp->dnstime + bp->dnsttl >= Uptime()) + if (bp->dnstime + bp->dnsttl >= TIM_mono()) return (-1); /* Then do another lookup to catch DNS changes */ From phk at projects.linpro.no Thu Jul 12 09:49:26 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 12 Jul 2007 11:49:26 +0200 (CEST) Subject: r1671 - trunk/varnish-cache/bin/varnishd Message-ID: <20070712094926.C19621EC030@projects.linpro.no> Author: phk Date: 2007-07-12 11:49:26 +0200 (Thu, 12 Jul 2007) New Revision: 1671 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_acceptor.c trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_lru.c trunk/varnish-cache/bin/varnishd/cache_pipe.c trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/cache_response.c trunk/varnish-cache/bin/varnishd/cache_session.c trunk/varnish-cache/bin/varnishd/cache_synthetic.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/rfc2616.c Log: Change all timekeeping to use doubles instead of time_t and struct timespec. Eliminate all direct calls to time(2) and clockgettime(2) and use TIM_real() and TIM_mono() exclusively. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-12 09:49:26 UTC (rev 1671) @@ -131,7 +131,7 @@ /*--------------------------------------------------------------------*/ struct acct { - time_t first; + double first; uint64_t sess; uint64_t req; uint64_t pipe; @@ -149,7 +149,7 @@ struct objhead *nobjhead; struct object *nobj; - time_t idle; + double idle; int pipe[2]; @@ -247,11 +247,11 @@ unsigned busy; unsigned len; - time_t age; - time_t entered; - time_t ttl; + double age; + double entered; + double ttl; - time_t last_modified; + double last_modified; struct http http; TAILQ_ENTRY(object) list; @@ -262,7 +262,7 @@ TAILQ_HEAD(, sess) waitinglist; - time_t lru_stamp; + double lru_stamp; TAILQ_ENTRY(object) lru; }; @@ -300,10 +300,10 @@ const char *doclose; struct http *http; - struct timespec t_open; - struct timespec t_req; - struct timespec t_resp; - struct timespec t_end; + double t_open; + double t_req; + double t_resp; + double t_end; enum step step; unsigned handling; @@ -492,11 +492,11 @@ /* cache_lru.c */ // void LRU_Init(void); -void LRU_Enter(struct object *o, time_t stamp); +void LRU_Enter(struct object *o, double stamp); void LRU_Remove(struct object *o); int LRU_DiscardOne(void); int LRU_DiscardSpace(int64_t quota); -int LRU_DiscardTime(time_t cutoff); +int LRU_DiscardTime(double cutoff); #define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *); Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -44,10 +44,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #ifndef HAVE_SRANDOMDEV #include "compat/srandomdev.h" #endif @@ -116,7 +112,7 @@ TCP_name(sp->sockaddr, sp->sockaddrlen, sp->addr, sizeof sp->addr, sp->port, sizeof sp->port); VSL(SLT_SessionOpen, sp->fd, "%s %s", sp->addr, sp->port); - sp->acct.first = sp->t_open.tv_sec; + sp->acct.first = sp->t_open; if (need_test) sock_test(sp->fd); if (need_linger) @@ -195,7 +191,7 @@ sp->fd = i; sp->id = i; - (void)clock_gettime(CLOCK_REALTIME, &sp->t_open); + sp->t_open = TIM_real(); http_RecvPrep(sp->http); sp->step = STP_FIRST; Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -41,10 +41,6 @@ #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "heritage.h" #include "shmlog.h" #include "cache.h" @@ -74,7 +70,7 @@ vca_main(void *arg) { struct epoll_event ev; - struct timespec ts; + double deadline; struct sess *sp, *sp2; int i; @@ -108,15 +104,11 @@ } } /* check for timeouts */ - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec -= params->sess_timeout; + deadline = TIM_real() - params->sess_timeout TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - if (sp->t_open.tv_sec > ts.tv_sec) + if (sp->t_open > deadline) continue; - if (sp->t_open.tv_sec == ts.tv_sec && - sp->t_open.tv_nsec > ts.tv_nsec) - continue; TAILQ_REMOVE(&sesshead, sp, list); vca_del(sp->fd); vca_close_session(sp, "timeout"); Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -43,10 +43,6 @@ #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "heritage.h" #include "shmlog.h" #include "cache.h" @@ -129,7 +125,7 @@ { struct kevent ke[NKEV], *kp; int j, n, dotimer; - struct timespec ts; + double deadline; struct sess *sp; (void)arg; @@ -160,17 +156,13 @@ } if (!dotimer) continue; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec -= params->sess_timeout; + deadline = TIM_real() - params->sess_timeout; for (;;) { sp = TAILQ_FIRST(&sesshead); if (sp == NULL) break; - if (sp->t_open.tv_sec > ts.tv_sec) + if (sp->t_open > deadline) break; - if (sp->t_open.tv_sec == ts.tv_sec && - sp->t_open.tv_nsec > ts.tv_nsec) - break; TAILQ_REMOVE(&sesshead, sp, list); vca_close_session(sp, "timeout"); SES_Delete(sp); Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -42,10 +42,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "heritage.h" #include "shmlog.h" #include "cache.h" @@ -108,7 +104,7 @@ { unsigned v; struct sess *sp, *sp2; - struct timespec ts; + double deadline; int i, fd; (void)arg; @@ -125,8 +121,7 @@ TAILQ_INSERT_TAIL(&sesshead, sp, list); vca_poll(sp->fd); } - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec -= params->sess_timeout; + deadline = TIM_real() - params->sess_timeout; TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) { if (v == 0) break; @@ -145,11 +140,8 @@ SES_Delete(sp); continue; } - if (sp->t_open.tv_sec > ts.tv_sec) + if (sp->t_open > deadline) continue; - if (sp->t_open.tv_sec == ts.tv_sec && - sp->t_open.tv_nsec > ts.tv_nsec) - continue; TAILQ_REMOVE(&sesshead, sp, list); vca_unpoll(fd); vca_close_session(sp, "timeout"); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -62,10 +62,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #ifndef HAVE_SRANDOMDEV #include "compat/srandomdev.h" #endif @@ -172,16 +168,6 @@ DOT ] */ -static double -cnt_dt(struct timespec *t1, struct timespec *t2) -{ - double dt; - - dt = (t2->tv_sec - t1->tv_sec); - dt += (t2->tv_nsec - t1->tv_nsec) * 1e-9; - return (dt); -} - static int cnt_done(struct sess *sp) { @@ -197,20 +183,17 @@ sp->vcl = NULL; } - clock_gettime(CLOCK_REALTIME, &sp->t_end); - sp->wrk->idle = sp->t_end.tv_sec; + sp->t_end = TIM_real(); + sp->wrk->idle = sp->t_end; if (sp->xid == 0) { sp->t_req = sp->t_end; sp->t_resp = sp->t_end; } - dp = cnt_dt(&sp->t_req, &sp->t_resp); - da = cnt_dt(&sp->t_resp, &sp->t_end); - dh = cnt_dt(&sp->t_open, &sp->t_req); - WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %ld.%09ld %ld.%09ld %.9f %.9f %.9f", - sp->xid, - (long)sp->t_req.tv_sec, (long)sp->t_req.tv_nsec, - (long)sp->t_end.tv_sec, (long)sp->t_end.tv_nsec, - dh, dp, da); + dp = sp->t_resp - sp->t_req; + da = sp->t_end - sp->t_resp; + dh = sp->t_req - sp->t_open; + WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %.9f %.9f %.9f %.9f %.9f", + sp->xid, sp->t_req, sp->t_end, dh, dp, da); sp->xid = 0; sp->t_open = sp->t_end; @@ -345,7 +328,7 @@ assert(sp->xid == 0); VCA_Prep(sp); - sp->wrk->idle = sp->t_open.tv_sec; + sp->wrk->idle = sp->t_open; sp->wrk->acct.sess++; SES_RefSrcAddr(sp); do @@ -672,8 +655,8 @@ /* Update stats of various sorts */ VSL_stats->client_req++; /* XXX not locked */ - clock_gettime(CLOCK_REALTIME, &sp->t_req); - sp->wrk->idle = sp->t_req.tv_sec; + sp->t_req = TIM_real(); + sp->wrk->idle = sp->t_req; sp->wrk->acct.req++; /* Assign XID and log */ Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -103,11 +103,11 @@ exp_hangman(void *arg) { struct object *o; - time_t t; + double t; (void)arg; - t = time(NULL); + t = TIM_real(); while (1) { LOCK(&exp_mtx); TAILQ_FOREACH(o, &exp_deathrow, deathrow) { @@ -153,7 +153,7 @@ { struct worker ww; struct object *o; - time_t t; + double t; struct sess *sp; struct object *o2; @@ -168,7 +168,7 @@ sleep(10); /* Takes time for VCL to arrive */ VCL_Get(&sp->vcl); - t = time(NULL); + t = TIM_real(); while (1) { LOCK(&exp_mtx); o = binheap_root(exp_heap); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -152,7 +152,7 @@ /* ignore */ } else if (o->ttl == 0) { /* Object banned but not reaped yet */ - } else if (o->ttl <= sp->t_req.tv_sec) { + } else if (o->ttl <= sp->t_req) { /* Object expired */ } else if (BAN_CheckObject(o, h->hd[HTTP_HDR_URL].b)) { o->ttl = 0; @@ -166,7 +166,7 @@ if (o != NULL) { UNLOCK(&oh->mtx); (void)hash->deref(oh); - LRU_Enter(o, sp->t_req.tv_sec); + LRU_Enter(o, sp->t_req); return (o); } @@ -178,7 +178,7 @@ /* NB: do not deref objhead the new object inherits our reference */ UNLOCK(&oh->mtx); BAN_NewObj(o); - LRU_Enter(o, sp->t_req.tv_sec); + LRU_Enter(o, sp->t_req); return (o); } Modified: trunk/varnish-cache/bin/varnishd/cache_lru.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_lru.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_lru.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -71,7 +71,7 @@ * if it's already in it and hasn't moved in a while. */ void -LRU_Enter(struct object *o, time_t stamp) +LRU_Enter(struct object *o, double stamp) { CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); @@ -199,7 +199,7 @@ * number of objects that were discarded. */ int -LRU_DiscardTime(time_t cutoff) +LRU_DiscardTime(double cutoff) { struct object *first = TAILQ_FIRST(&lru_list); struct object *o; Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -38,10 +38,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "shmlog.h" #include "heritage.h" #include "cache.h" @@ -106,7 +102,7 @@ vbe_free_bereq(bereq); bereq = NULL; - clock_gettime(CLOCK_REALTIME, &sp->t_resp); + sp->t_resp = TIM_real(); memset(fds, 0, sizeof fds); fds[0].fd = vc->fd; Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -381,7 +381,7 @@ static void * wrk_reaperthread(void *priv) { - time_t now; + double now; struct worker *w; struct wq *qp; unsigned u; @@ -392,7 +392,7 @@ sleep(1); if (VSL_stats->n_wrk <= params->wthread_min) continue; - now = time(NULL); + now = TIM_real(); for (u = 0; u < nwq; u++) { qp = wq[u]; LOCK(&qp->mtx); Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -32,10 +32,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "shmlog.h" #include "heritage.h" #include "cache.h" @@ -75,7 +71,7 @@ sp->http->logtag = HTTP_Tx; http_SetResp(sp->http, "HTTP/1.1", "304", "Not Modified"); - TIM_format(sp->t_req.tv_sec, lm); + TIM_format(sp->t_req, lm); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Date: %s", lm); http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish"); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid); @@ -95,12 +91,12 @@ res_do_conds(struct sess *sp) { char *p; - time_t ims; + double ims; if (sp->obj->last_modified > 0 && http_GetHdr(sp->http, H_If_Modified_Since, &p)) { ims = TIM_parse(p); - if (ims > sp->t_req.tv_sec) /* [RFC2616 14.25] */ + if (ims > sp->t_req) /* [RFC2616 14.25] */ return (0); if (sp->obj->last_modified > ims) { return (0); @@ -134,8 +130,8 @@ else http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid); - http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %u", - sp->obj->age + sp->t_resp.tv_sec - sp->obj->entered); + http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %.0f", + sp->obj->age + sp->t_resp - sp->obj->entered); http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish"); if (sp->doclose != NULL) http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); @@ -151,7 +147,7 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - clock_gettime(CLOCK_REALTIME, &sp->t_resp); + sp->t_resp = TIM_real(); WRK_Reset(sp->wrk, &sp->fd); sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -91,7 +91,7 @@ char addr[TCP_ADDRBUFSIZE]; unsigned nref; - time_t ttl; + double ttl; struct acct acct; }; @@ -120,7 +120,7 @@ unsigned u, v; struct srcaddr *c, *c2, *c3; struct srcaddrhead *ch; - time_t now; + double now; if (params->srcaddr_ttl == 0) { sp->srcaddr = NULL; @@ -131,7 +131,7 @@ v = u % nsrchash; ch = &srchash[v]; CHECK_OBJ(ch, SRCADDRHEAD_MAGIC); - now = sp->t_open.tv_sec; + now = sp->t_open; if (sp->wrk->srcaddr == NULL) { sp->wrk->srcaddr = calloc(sizeof *sp->wrk->srcaddr, 1); XXXAN(sp->wrk->srcaddr); @@ -233,8 +233,8 @@ b = sp->srcaddr->acct; UNLOCK(&sp->srcaddr->sah->mtx); WSL(sp->wrk, SLT_StatAddr, 0, - "%s 0 %d %ju %ju %ju %ju %ju %ju %ju", - sp->srcaddr->addr, sp->t_end.tv_sec - b.first, + "%s 0 %.0f %ju %ju %ju %ju %ju %ju %ju", + sp->srcaddr->addr, sp->t_end - b.first, b.sess, b.req, b.pipe, b.pass, b.fetch, b.hdrbytes, b.bodybytes); } @@ -333,8 +333,8 @@ AZ(sp->vcl); VSL_stats->n_sess--; ses_relsrcaddr(sp); - VSL(SLT_StatSess, sp->id, "%s %s %d %ju %ju %ju %ju %ju %ju %ju", - sp->addr, sp->port, sp->t_end.tv_sec - b->first, + VSL(SLT_StatSess, sp->id, "%s %s %.0f %ju %ju %ju %ju %ju %ju %ju", + sp->addr, sp->port, sp->t_end - b->first, b->sess, b->req, b->pipe, b->pass, b->fetch, b->hdrbytes, b->bodybytes); if (sm->workspace != params->mem_workspace) { Modified: trunk/varnish-cache/bin/varnishd/cache_synthetic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -33,10 +33,6 @@ #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "shmlog.h" #include "heritage.h" #include "cache.h" @@ -56,7 +52,7 @@ struct vsb vsb; const char *msg; char date[40]; - time_t now; + double now; int fd; assert(status >= 100 && status <= 999); @@ -71,7 +67,7 @@ fd = sp->fd; o = sp->obj; h = &o->http; - time(&now); + now = TIM_real(); /* look up HTTP response */ msg = http_StatusMessage(status); Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -324,11 +324,11 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ - WSL(sp->wrk, SLT_TTL, sp->fd, "%u VCL %.0f %u", - sp->obj->xid, a, sp->t_req.tv_sec); + WSL(sp->wrk, SLT_TTL, sp->fd, "%u VCL %.0f %.0f", + sp->obj->xid, a, sp->t_req); if (a < 0) a = 0; - sp->obj->ttl = sp->t_req.tv_sec + (int)a; + sp->obj->ttl = sp->t_req + a; if (sp->obj->heap_idx != 0) EXP_TTLchange(sp->obj); } @@ -338,7 +338,7 @@ { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ - return (sp->obj->ttl - sp->t_req.tv_sec); + return (sp->obj->ttl - sp->t_req); } /*--------------------------------------------------------------------*/ @@ -460,24 +460,18 @@ double VRT_r_now(struct sess *sp) { - struct timespec now; (void)sp; - /* XXX use of clock_gettime() needs review */ - clock_gettime(CLOCK_MONOTONIC, &now); - return (now.tv_sec); + return (TIM_mono()); } double VRT_r_obj_lastuse(struct sess *sp) { - struct timespec now; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ - /* XXX use of clock_gettime() needs review */ - clock_gettime(CLOCK_MONOTONIC, &now); - return (now.tv_sec - sp->obj->lru_stamp); + return (TIM_mono() - sp->obj->lru_stamp); } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- trunk/varnish-cache/bin/varnishd/rfc2616.c 2007-07-12 09:25:45 UTC (rev 1670) +++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2007-07-12 09:49:26 UTC (rev 1671) @@ -98,12 +98,12 @@ ttd = min(ttd, our_clock + hard_upper_ttl) #endif -static time_t +static double RFC2616_Ttl(struct sess *sp, struct http *hp, struct object *obj) { int retirement_age; unsigned u1, u2; - time_t h_date, h_expires, ttd; + double h_date, h_expires, ttd; char *p; retirement_age = INT_MAX; From phk at projects.linpro.no Thu Jul 12 10:00:13 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 12 Jul 2007 12:00:13 +0200 (CEST) Subject: r1672 - trunk/varnish-cache/bin/varnishd Message-ID: <20070712100013.7D1BB1EC1F5@projects.linpro.no> Author: phk Date: 2007-07-12 12:00:13 +0200 (Thu, 12 Jul 2007) New Revision: 1672 Modified: trunk/varnish-cache/bin/varnishd/cache_session.c Log: Document timescale of srcaddr->ttl Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2007-07-12 09:49:26 UTC (rev 1671) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2007-07-12 10:00:13 UTC (rev 1672) @@ -91,6 +91,7 @@ char addr[TCP_ADDRBUFSIZE]; unsigned nref; + /* How long to keep entry around. Inherits timescale from t_open */ double ttl; struct acct acct; From phk at projects.linpro.no Thu Jul 12 10:13:29 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 12 Jul 2007 12:13:29 +0200 (CEST) Subject: r1673 - trunk/varnish-cache/bin/varnishd Message-ID: <20070712101329.AD9881EC1F5@projects.linpro.no> Author: phk Date: 2007-07-12 12:13:29 +0200 (Thu, 12 Jul 2007) New Revision: 1673 Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_main.c trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/shmlog.c Log: Convert the last time(2) calls to TIM_real() Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-07-12 10:00:13 UTC (rev 1672) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-07-12 10:13:29 UTC (rev 1673) @@ -127,7 +127,7 @@ if (o == NULL) { UNLOCK(&exp_mtx); AZ(sleep(1)); - t = time(NULL); + t = TIM_real(); continue; } TAILQ_REMOVE(&exp_deathrow, o, deathrow); @@ -178,7 +178,7 @@ UNLOCK(&exp_mtx); AZ(sleep(1)); VCL_Refresh(&sp->vcl); - t = time(NULL); + t = TIM_real(); continue; } binheap_delete(exp_heap, o->heap_idx); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-12 10:00:13 UTC (rev 1672) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-12 10:13:29 UTC (rev 1673) @@ -303,7 +303,7 @@ CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); - sp->obj->entered = time(NULL); + sp->obj->entered = TIM_real(); assert(sp->obj->busy != 0); Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2007-07-12 10:00:13 UTC (rev 1672) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2007-07-12 10:13:29 UTC (rev 1673) @@ -71,7 +71,7 @@ stevedore->open(stevedore); printf("Ready\n"); - VSL_stats->start_time = time(NULL); + VSL_stats->start_time = TIM_real(); CLI_Init(); Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2007-07-12 10:00:13 UTC (rev 1672) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2007-07-12 10:13:29 UTC (rev 1673) @@ -207,7 +207,7 @@ w = &ww; memset(w, 0, sizeof *w); w->magic = WORKER_MAGIC; - w->idle = time(NULL); + w->idle = TIM_real(); w->wlp = w->wlog; w->wle = w->wlog + sizeof w->wlog; AZ(pipe(w->pipe)); Modified: trunk/varnish-cache/bin/varnishd/shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/shmlog.c 2007-07-12 10:00:13 UTC (rev 1672) +++ trunk/varnish-cache/bin/varnishd/shmlog.c 2007-07-12 10:13:29 UTC (rev 1673) @@ -289,7 +289,7 @@ /* XXX more check sanity of loghead ? */ logstart = (unsigned char *)loghead + loghead->start; MTX_INIT(&vsl_mtx); - loghead->starttime = time(NULL); + loghead->starttime = TIM_real(); memset(VSL_stats, 0, sizeof *VSL_stats); } From cecilihf at projects.linpro.no Thu Jul 12 10:20:34 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Thu, 12 Jul 2007 12:20:34 +0200 (CEST) Subject: r1674 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20070712102034.2C5B21EC030@projects.linpro.no> Author: cecilihf Date: 2007-07-12 12:20:33 +0200 (Thu, 12 Jul 2007) New Revision: 1674 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/mgt_cli.h trunk/varnish-cache/bin/varnishd/varnishd.1 trunk/varnish-cache/include/cli.h Log: Added a new cli option, status, for checking the status of the varnish child process. This is for use in the webmin plugin. Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-12 10:13:29 UTC (rev 1673) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-12 10:20:33 UTC (rev 1674) @@ -445,3 +445,13 @@ cli_out(cli, "Child in state %s", ch_state[child_state]); } } + +/*--------------------------------------------------------------------*/ + +void +mcf_server_status(struct cli *cli, char **av, void *priv) +{ + (void)av; + (void)priv; + cli_out(cli, "Child is state %s", ch_state[child_state]); +} Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-07-12 10:13:29 UTC (rev 1673) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-07-12 10:20:33 UTC (rev 1674) @@ -140,6 +140,7 @@ /* XXX: what order should this list be in ? */ static struct cli_proto mgt_cli_proto[] = { { CLI_PING, cli_func_ping }, + { CLI_SERVER_STATUS, mcf_server_status, NULL }, { CLI_SERVER_START, mcf_server_startstop, NULL }, { CLI_SERVER_STOP, mcf_server_startstop, &cli_proto }, { CLI_STATS, mcf_stats, NULL }, Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.h 2007-07-12 10:13:29 UTC (rev 1673) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.h 2007-07-12 10:20:33 UTC (rev 1674) @@ -31,6 +31,7 @@ /* mgt_child.c */ cli_func_t mcf_server_startstop; +cli_func_t mcf_server_status; /* mgt_param.c */ cli_func_t mcf_param_show; Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2007-07-12 10:13:29 UTC (rev 1673) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2007-07-12 10:20:33 UTC (rev 1674) @@ -316,6 +316,8 @@ better idea of the current situation, use the .Xr varnishstat 1 utility. +.It Cm status +Check the status of the child process. .It Cm stop Stop the child process. .It Cm url.purge Ar regexp Modified: trunk/varnish-cache/include/cli.h =================================================================== --- trunk/varnish-cache/include/cli.h 2007-07-12 10:13:29 UTC (rev 1673) +++ trunk/varnish-cache/include/cli.h 2007-07-12 10:20:33 UTC (rev 1674) @@ -211,6 +211,12 @@ "\tClose connection", \ 0, 0 +# define CLI_SERVER_STATUS \ + "status", \ + "status", \ + "\tCheck status of Varnish cache process.", \ + 0, 0 + /* * Status/return codes in the CLI protocol */ From cecilihf at projects.linpro.no Thu Jul 12 10:27:37 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Thu, 12 Jul 2007 12:27:37 +0200 (CEST) Subject: r1675 - trunk/varnish-cache/bin/varnishd Message-ID: <20070712102737.946C11EC469@projects.linpro.no> Author: cecilihf Date: 2007-07-12 12:27:37 +0200 (Thu, 12 Jul 2007) New Revision: 1675 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: Fixed typo Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-12 10:20:33 UTC (rev 1674) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-12 10:27:37 UTC (rev 1675) @@ -453,5 +453,5 @@ { (void)av; (void)priv; - cli_out(cli, "Child is state %s", ch_state[child_state]); + cli_out(cli, "Child in state %s", ch_state[child_state]); } From des at projects.linpro.no Thu Jul 12 16:00:05 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 12 Jul 2007 18:00:05 +0200 (CEST) Subject: r1676 - in trunk/varnish-cache: bin/varnishd lib/libvarnish Message-ID: <20070712160005.4C0B51EC1F5@projects.linpro.no> Author: des Date: 2007-07-12 18:00:04 +0200 (Thu, 12 Jul 2007) New Revision: 1676 Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/lib/libvarnish/Makefile.am Log: RT_LIBS dependency has moved from varnishd to libvarnish. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-07-12 10:27:37 UTC (rev 1675) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-07-12 16:00:04 UTC (rev 1676) @@ -68,4 +68,4 @@ $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ $(top_builddir)/lib/libvcl/libvcl.la \ - ${DL_LIBS} ${RT_LIBS} ${PTHREAD_LIBS} + ${DL_LIBS} ${PTHREAD_LIBS} Modified: trunk/varnish-cache/lib/libvarnish/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnish/Makefile.am 2007-07-12 10:27:37 UTC (rev 1675) +++ trunk/varnish-cache/lib/libvarnish/Makefile.am 2007-07-12 16:00:04 UTC (rev 1676) @@ -19,3 +19,5 @@ vss.c libvarnish_la_CFLAGS = -include config.h + +libvarnish_la_LIBADD = ${RT_LIBS} From des at projects.linpro.no Thu Jul 12 16:02:47 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 12 Jul 2007 18:02:47 +0200 (CEST) Subject: r1677 - trunk/varnish-cache/bin/varnishd Message-ID: <20070712160247.E94D61EC46F@projects.linpro.no> Author: des Date: 2007-07-12 18:02:47 +0200 (Thu, 12 Jul 2007) New Revision: 1677 Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c Log: Add missing semicolon. Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2007-07-12 16:00:04 UTC (rev 1676) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2007-07-12 16:02:47 UTC (rev 1677) @@ -104,7 +104,7 @@ } } /* check for timeouts */ - deadline = TIM_real() - params->sess_timeout + deadline = TIM_real() - params->sess_timeout; TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); if (sp->t_open > deadline) From des at projects.linpro.no Thu Jul 12 17:37:44 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 12 Jul 2007 19:37:44 +0200 (CEST) Subject: r1678 - trunk/varnish-cache/bin/varnishd Message-ID: <20070712173744.723DA1EC1F5@projects.linpro.no> Author: des Date: 2007-07-12 19:37:44 +0200 (Thu, 12 Jul 2007) New Revision: 1678 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: sockaddr.sa_len is not portable. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-12 16:02:47 UTC (rev 1677) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-12 17:37:44 UTC (rev 1678) @@ -32,7 +32,10 @@ */ #include +#include +#include + #include #include #include @@ -480,8 +483,19 @@ VRT_IP_string(struct sess *sp, struct sockaddr *sa) { char h[64], p[8], *q; + socklen_t len = 0; - TCP_name(sa, sa->sa_len, h, sizeof h, p, sizeof p); + /* XXX can't rely on sockaddr.sa_len */ + switch (sa->sa_family) { + case AF_INET: + len = sizeof(struct sockaddr_in); + break; + case AF_INET6: + len = sizeof(struct sockaddr_in6); + break; + } + XXXAN(len); + TCP_name(sa, len, h, sizeof h, p, sizeof p); q = WS_Alloc(sp->http->ws, strlen(h) + strlen(p) + 2); AN(q); strcpy(q, h); From des at projects.linpro.no Thu Jul 12 22:38:25 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 13 Jul 2007 00:38:25 +0200 (CEST) Subject: r1679 - trunk/varnish-tools/munin Message-ID: <20070712223825.43AD61EC468@projects.linpro.no> Author: des Date: 2007-07-13 00:38:24 +0200 (Fri, 13 Jul 2007) New Revision: 1679 Added: trunk/varnish-tools/munin/Makefile.am trunk/varnish-tools/munin/autogen.sh trunk/varnish-tools/munin/configure.ac trunk/varnish-tools/munin/varnish_munin_plugin.pl Removed: trunk/varnish-tools/munin/README trunk/varnish-tools/munin/varnish_cachehitratio trunk/varnish-tools/munin/varnish_hitrate trunk/varnish-tools/munin/varnish_varnishstat_ Modified: trunk/varnish-tools/munin/ Log: I got bored and wrote an all-singing, all-dancing Munin plugin to replace the ones contributed by Anders and Bj?\195?\184rn. Property changes on: trunk/varnish-tools/munin ___________________________________________________________________ Name: svn:ignore + Makefile Makefile.in aclocal.m4 autom4te.cache config.guess config.log config.status config.sub configure install-sh missing Added: trunk/varnish-tools/munin/Makefile.am =================================================================== --- trunk/varnish-tools/munin/Makefile.am (rev 0) +++ trunk/varnish-tools/munin/Makefile.am 2007-07-12 22:38:24 UTC (rev 1679) @@ -0,0 +1,10 @@ +# $Id$ + +EXTRA_DIST = varnish_munin_plugin.pl + +install-exec-local: + ${install_sh} -m 0755 -c varnish_munin_plugin.pl \ + ${DESTDIR}${bindir}/varnish_ +# for aspect in `${DESTDIR}${bindir}/varnish_ aspects` ; do \ +# ln -fs varnish_ ${DESTDIR}${bindir}/varnish_$$aspect ; \ +# done Property changes on: trunk/varnish-tools/munin/Makefile.am ___________________________________________________________________ Name: svn:keywords + Id Deleted: trunk/varnish-tools/munin/README =================================================================== --- trunk/varnish-tools/munin/README 2007-07-12 17:37:44 UTC (rev 1678) +++ trunk/varnish-tools/munin/README 2007-07-12 22:38:24 UTC (rev 1679) @@ -1,23 +0,0 @@ -The scripts in this directory are munin plugins for monitoring varnish. -varnish_cachehitratio and varnish_hitrate are written by Anders -Nordby, while varnish_varnishstat_ is written by Bj?rn -Ruberg. All three scripts uses varnishstat to acquire information. - -* varnish_cachehitratio shows the cache hit/miss ratio. -* varnish_hitrate shows the rate of requests. -* varnish_varnishstat_ shows the cache usage. - -To work with named varnish instances, these scripts will have to be modified -so they can call varnishstat with the appropriate parameter. As of today, -the scripts only call 'varnishstat -1', and thus, will only work if varnishd -was started without the -n parameter. A solution to this problem could be to -let the scripts read a filename from an environment variable (this must then -be set in the munin-plugin configuration), and have this file contain the -name (or names?) to the varnish server(s) to monitor. If the environment -variable is not set, varnishstat will be called without the -n parameter, -and work with the default name. - -Dependencies: -* varnish_cachehitration needs the CPAN module Date::Format -* varnish_varnishstart_ needs the CPAN module Net::Telnet -(but does it really? It doesn't seem to use it for anything.) Added: trunk/varnish-tools/munin/autogen.sh =================================================================== --- trunk/varnish-tools/munin/autogen.sh (rev 0) +++ trunk/varnish-tools/munin/autogen.sh 2007-07-12 22:38:24 UTC (rev 1679) @@ -0,0 +1,32 @@ +#!/bin/sh +# +# $Id$ +# + +if [ -d /usr/local/gnu-autotools/bin ] ; then + PATH=/usr/local/gnu-autotools/bin:${PATH} + export PATH + FIX_BROKEN_FREEBSD_PORTS="-I /usr/local/share/aclocal" +fi + +automake_version=$(automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+') +if [ -z "$automake_version" ] ; then + echo "unable to determine automake version" + exit 1 +else + case $automake_version in + 0.*|1.[0-8]|1.[0-8][.-]*) + echo "your version of automake ($automake_version) is too old;" \ + "you need 1.9 or newer." + exit 1 + ;; + *) + ;; + esac +fi + +set -ex + +aclocal ${FIX_BROKEN_FREEBSD_PORTS} +automake --add-missing --copy --foreign +autoconf Property changes on: trunk/varnish-tools/munin/autogen.sh ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Id Added: trunk/varnish-tools/munin/configure.ac =================================================================== --- trunk/varnish-tools/munin/configure.ac (rev 0) +++ trunk/varnish-tools/munin/configure.ac 2007-07-12 22:38:24 UTC (rev 1679) @@ -0,0 +1,19 @@ +# $Id$ + +AC_PREREQ(2.59) +AC_COPYRIGHT([Copyright (c) 2007 Linpro AS / Verdens Gang AS]) +AC_REVISION([$Id$]) +AC_INIT([Varnish Munin plugin], [trunk], [varnish-dev at projects.linpro.no]) +AC_CONFIG_SRCDIR(varnish_munin_plugin.pl) + +AC_CANONICAL_SYSTEM + +AM_INIT_AUTOMAKE + +AC_PROG_INSTALL +AC_PROG_MAKE_SET +AC_CHECK_PROGS(PERL, [perl]) +AC_CHECK_PROGS(VARNISHSTAT, [varnishstat]) + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT Property changes on: trunk/varnish-tools/munin/configure.ac ___________________________________________________________________ Name: svn:keywords + Id Deleted: trunk/varnish-tools/munin/varnish_cachehitratio =================================================================== --- trunk/varnish-tools/munin/varnish_cachehitratio 2007-07-12 17:37:44 UTC (rev 1678) +++ trunk/varnish-tools/munin/varnish_cachehitratio 2007-07-12 22:38:24 UTC (rev 1679) @@ -1,124 +0,0 @@ -#! /usr/bin/perl -# Varnish cache hit ratio logger/plugin -# anders at aftenposten.no, 2007-05-07 - -# Log/data file -# These must be created with write permission to the user the plugin runs as -# On FreeBSD, that is nobody -# Comment $mylog out to skip logging - -$mydat = "/var/tmp/varnish_cachehitratio.dat"; -#$mylog = "/var/log/varnish_cachehitratio.log"; - -%stat = (); -$ENV{PATH} = "/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin"; - -use Date::Format; - -sub popstat { - foreach $line (`varnishstat -1`) { - chomp($line); - if ($line =~ /^\s+(\d+)\s+(.*)$/) { - $val = $1; - $key = $2; - $key =~ s@\s at _@g; - $key =~ tr at A-Z@a-z@; - - $stat{"$key"} = $val; - } - } -} - -sub printconfig { - print "graph_title Cache hit/miss ratio\n"; - print "graph_args --upper-limit 100 -l 0\n"; - print "graph_vlabel % of requests\n"; - print "graph_category varnish\n"; - print "graph_info This graph shows the ratio of requests found in the cache and not\n"; - print "graph_order hitratio missratio unknownratio\n"; - print "graph_scale no\n"; - - print "hitratio.label hits\n"; - print "hitratio.type GAUGE\n"; - print "hitratio.graph yes\n"; - print "hitratio.min 0\n"; - print "hitratio.max 100\n"; - print "hitratio.draw AREA\n"; - - print "missratio.label misses\n"; - print "missratio.type GAUGE\n"; - print "missratio.graph yes\n"; - print "missratio.min 0\n"; - print "missratio.max 100\n"; - print "missratio.draw STACK\n"; - - print "unknownratio.label unknown\n"; - print "unknownratio.type GAUGE\n"; - print "unknownratio.graph yes\n"; - print "unknownratio.min 0\n"; - print "unknownratio.max 100\n"; - print "unknownratio.draw STACK\n"; -} - -sub findvalues { - $nrequests = $stat{"client_requests_received"}; - $nhits = $stat{"cache_hits"}; - $nmisses = $stat{"cache_misses"}; - - open(OVAL, $mydat); - $tmpstr = ; - close(OVAL); - chomp($tmpstr); - - ($orequests,$ohits,$omisses) = split(/ /, $tmpstr, 3); - - $hits = $nhits - $ohits; - $requests = $nrequests - $orequests; - $misses = $nmisses - $omisses; -} - -sub printvalues { - if ($requests > 0) { - $hitratio = sprintf("%.2f", $hits / $requests * 100); - $missratio = sprintf("%.2f", $misses / $requests * 100); - } else { - # Assume cache hit ratio = 100% if requests < 0 - $hitratio = sprintf("%.2f", 100); - $missratio = sprintf("%.2f", 0); - } - - if (($hitratio + $missratio) > 100) { - # Rounding foo, hit+miss ratio is higher than 100 - $missratio = sprintf("%.2f", 100 - $hitratio); - $unknownratio = sprintf("%.2f", 0); - } else { - # Unknown = rest, hit+miss ratio is upto or 100 - $unknownratio = sprintf("%.2f", 100 - ($hitratio + $missratio)); - } - - print "hitratio.value $hitratio\n"; - print "missratio.value $missratio\n"; - print "unknownratio.value $unknownratio\n"; - if ($mylog ne "") { - open(LOG, ">>$mylog"); - print LOG "hitratio=$hitratio missratio=$missratio unknown=$unknownratio hits=$hits misses=$misses requests=$requests [" . time2str("%Y-%m-%d %H:%M:%S", time) . "]\n"; - close(LOG); - } -} - -sub writevalues { - open(OVAL, ">$mydat"); - print OVAL "$nrequests $nhits $nmisses\n"; - close(OVAL); -} - -if ($ARGV[0] eq "autoconf") { - print "yes\n"; -} elsif ($ARGV[0] eq "config") { - printconfig; -} else { - popstat; - findvalues; - printvalues; - writevalues; -} Deleted: trunk/varnish-tools/munin/varnish_hitrate =================================================================== --- trunk/varnish-tools/munin/varnish_hitrate 2007-07-12 17:37:44 UTC (rev 1678) +++ trunk/varnish-tools/munin/varnish_hitrate 2007-07-12 22:38:24 UTC (rev 1679) @@ -1,29 +0,0 @@ -#! /bin/sh -# anders at aftenposten.no, 2007-05-07 -# Shows the rate of requests (per second) for Varnish - -PATH="$PATH:/usr/local/bin" -export PATH - -pvstat() { - # $1: vname $2: grabstat - printf "$1.value " - varnishstat -1 | egrep "$2" | awk '{print $1}' -} - -case $1 in -autoconf) echo yes;; -config) - echo 'graph_title Hitrate' - echo 'graph_vlabel hits per second' - echo 'graph_category varnish' - echo 'graph_info This graph shows the rate of requests, hits per second' - - echo 'requests.label requests' - echo 'requests.type COUNTER' - echo 'requests.graph yes' - ;; -*) - pvstat requests 'Client requests received$' - ;; -esac Added: trunk/varnish-tools/munin/varnish_munin_plugin.pl =================================================================== --- trunk/varnish-tools/munin/varnish_munin_plugin.pl (rev 0) +++ trunk/varnish-tools/munin/varnish_munin_plugin.pl 2007-07-12 22:38:24 UTC (rev 1679) @@ -0,0 +1,207 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2007 Linpro AS +# All rights reserved. +# +# Author: Dag-Erling Sm??rgrav +# +# 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. +# +# $Id$ +# + +use strict; + +our %varnishstat; + +our %ASPECTS = ( + 'ratio' => { + 'title' => 'Hit / miss ratio', + 'type' => 'percent', + 'values' => { + 'hit' => { + 'label' => 'hits', + 'numerator' => 'cache_hit', + 'denominator' => 'client_req', + }, + 'miss' => { + 'label' => 'misses', + 'numerator' => 'cache_miss', + 'denominator' => 'client_req', + }, + }, + }, +); + +sub varnishstat($) { + my $field = shift; + + die "no such field: $field\n" + unless defined($varnishstat{$field}); + return $varnishstat{$field}; +} + +sub value($$) { + my $value = shift; + my $type = shift; + + defined($value) || die "oops"; + if ($type eq 'count') { + return varnishstat($value->{'field'}); + } elsif ($type eq 'gauge') { + return varnishstat($value->{'field'}); + } elsif ($type eq 'percent') { + return sprintf("%.1f", varnishstat($value->{'numerator'}) * 100.0 / + varnishstat($value->{'denominator'})); + } elsif ($type eq 'ratio') { + return sprintf("%.3f", varnishstat($value->{'numerator'}) / + varnishstat($value->{'denominator'})); + } else { + die "oops"; + } +} + +sub measure($) { + my $aspect = shift; + + defined($aspect) || die "oops"; + my @order = $aspect->{'order'} || sort(keys(%{$aspect->{'values'}})); + foreach (@order) { + print "$_.value ", + value($aspect->{'values'}->{$_}, $aspect->{'type'}), + "\n"; + } +} + +sub config($) { + my $aspect = shift; + + defined($aspect) || die "oops"; + print "graph_category Varnish\n"; + print "graph_title $aspect->{'title'}\n"; + if ($aspect->{'type'} eq 'percent') { + print "graph_scale no\n"; + } + my @order = $aspect->{'order'} || sort(keys(%{$aspect->{'values'}})); + print "graph_order ", join(' ', @order), "\n"; + foreach (@order) { + my $value = $aspect->{'values'}->{$_}; + print "$_.label $value->{'label'}\n"; + print "$_.graph yes\n"; + if ($aspect->{'type'} eq 'count') { + print "$_.type COUNTER\n"; + } elsif ($aspect->{'type'} eq 'gauge') { + print "$_.type GAUGE\n"; + } elsif ($aspect->{'type'} eq 'percent') { + print "$_.type GAUGE\n"; + print "$_.min 0\n"; + print "$_.max 100\n"; + if ($_ eq $order[0]) { + print "$_.draw AREA\n"; + } else { + print "$_.draw STACK\n"; + } + } + } +} + +sub read_varnishstat($) { + my $name = shift; + my ($rh, $wh); + my $pid; + + pipe($rh, $wh) + or die "pipe(): $!\n"; + defined($pid = fork()) + or die "fork(): $!\n"; + if ($pid == 0) { + close($rh); + open(STDOUT, ">&", $wh); + exec "varnishstat", "-1", $name ? ("-n", $name) : () + or die "exec(): $!\n"; + die "not reachable\n"; + } + close($wh); + while (<$rh>) { + if (m/^(\w+)\s+(\d+)\s+(\d*\.\d*)\s+(\w.*)$/) { + $varnishstat{$1} = $2; + $ASPECTS{$1} = { + 'title' => $4, + 'type' => ($3 eq ".") ? 'gauge' : 'count', + 'values' => { + $1 => { + 'label' => $1, + 'field' => $1, + } + } + }; + } + } + close($rh); + waitpid($pid, 0) + or die "waitpid(): $!\n"; + if ($? & 0x80) { + die "varnishstat received signal ", $? && 0x7f, "\n"; + } elsif ($?) { + die "varnishstat returned exit code ", $? >> 8, "\n"; + } +} + +sub usage() { + + print STDERR "usage: varnish_ [config]\n"; + print STDERR "aspects: ", join(', ', sort keys %ASPECTS), "\n"; + exit 1; +} + +MAIN:{ + read_varnishstat($ENV{'VARNISH_NAME'}); + + my $aspect; + ($aspect = $0) =~ s|^(?:.*/)varnish_(\w+)$|$1|; + + # XXX bug in munin-node + shift @ARGV + if (@ARGV && $ARGV[0] eq ''); + + if (@ARGV == 0) { + defined($ASPECTS{$aspect}) + or usage(); + measure($ASPECTS{$aspect}); + } elsif (@ARGV == 1) { + if ($ARGV[0] eq 'autoconf') { + print "yes\n"; + } elsif ($ARGV[0] eq 'aspects') { + foreach (sort keys %ASPECTS) { + print "$_\n"; + } + } elsif ($ARGV[0] eq 'config') { + defined($ASPECTS{$aspect}) + or usage(); + config($ASPECTS{$aspect}); + } else { + usage(); + } + } else { + usage(); + } +} Deleted: trunk/varnish-tools/munin/varnish_varnishstat_ =================================================================== --- trunk/varnish-tools/munin/varnish_varnishstat_ 2007-07-12 17:37:44 UTC (rev 1678) +++ trunk/varnish-tools/munin/varnish_varnishstat_ 2007-07-12 22:38:24 UTC (rev 1679) @@ -1,71 +0,0 @@ -#!/usr/bin/perl -use Net::Telnet (); -use Data::Dumper; - -$arg = shift @ARGV; - -%aspects = ( - 'cache' => 'Cache', - 'backend' => 'Backend', - 'shm' => 'SHM' - ); - -(my $whut = $0) =~ s/^.*\_//; - -# Hvis $whut IKKE fins, men $arg fins OG er noe annet enn blabla -# s?? skal den trigge - -if (!$whut && $arg && $arg !~ /^(suggest|autoconf)$/) { - print "Only 'suggest' and 'autoconf' may be used w/o symlinked name\n"; - exit 2; -} elsif (!$whut && !$arg) { - print "Uh. Bugger.\n"; - exit 2; -} - -if ($arg eq 'autoconf') { - print "Autoconf starting...\n"; - exit 0; -} elsif ($arg eq 'suggest') { - print "Suggest starting...\n"; - exit 0; -} elsif ($arg eq 'config') { - $config = 1; -} - -$grepfor = $aspects{$whut}; -# print "Looking for $grepfor\n"; - -if ($config) { - print "graph_title Varnish $grepfor usage\n"; - print "graph_args --base 1000\n"; - print "graph_vlabel Activity / \${graph_period}\n"; - print "graph_category Varnish\n"; -} - -$i = 0; -foreach $line (`varnishstat -1`) { - chomp $line; - if ($line =~ /^\s+(\d+)\s+($grepfor.*)$/) { - $val = $1; - $key = $2; - ($printkey = lc ($key)) =~ s/\s/_/g; - if ($config) { - print "$printkey\.label $key\n"; - print "$printkey\.type DERIVE\n"; - print "$printkey\.min 0\n"; - print "$printkey\.draw "; - if ($i == 0) { - print "AREA\n"; - } else { - print "STACK\n"; - } - $i++; - } else { - print "$printkey\.value $val\n"; - } - } -} - -exit; - From des at projects.linpro.no Thu Jul 12 22:40:02 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 13 Jul 2007 00:40:02 +0200 (CEST) Subject: r1680 - trunk/varnish-tools/munin Message-ID: <20070712224002.D92321EC030@projects.linpro.no> Author: des Date: 2007-07-13 00:40:02 +0200 (Fri, 13 Jul 2007) New Revision: 1680 Modified: trunk/varnish-tools/munin/varnish_munin_plugin.pl Log: Fix props Property changes on: trunk/varnish-tools/munin/varnish_munin_plugin.pl ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Thu Jul 12 22:41:08 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 13 Jul 2007 00:41:08 +0200 (CEST) Subject: r1681 - trunk/varnish-tools/fetcher Message-ID: <20070712224108.F3CDE1EC46F@projects.linpro.no> Author: des Date: 2007-07-13 00:41:08 +0200 (Fri, 13 Jul 2007) New Revision: 1681 Modified: trunk/varnish-tools/fetcher/fetcher.pl Log: Allow a delay to be specified. Note that the delay is applied individually by each child. Modified: trunk/varnish-tools/fetcher/fetcher.pl =================================================================== --- trunk/varnish-tools/fetcher/fetcher.pl 2007-07-12 22:40:02 UTC (rev 1680) +++ trunk/varnish-tools/fetcher/fetcher.pl 2007-07-12 22:41:08 UTC (rev 1681) @@ -43,6 +43,9 @@ our %CHILD; our $BUSY; +our $jobs = 1; +our $delay = 0; + sub new($$) { my ($this, $mux, $fh) = @_; my $class = ref($this) || $this; @@ -77,6 +80,8 @@ $s->write("add $_\n"); } } + select(undef, undef, undef, $delay) + if $delay; $0 = "[fetcher] ready"; $s->write("ready\n"); } @@ -133,8 +138,8 @@ } } -sub fetcher($@) { - my ($n, @urls) = @_; +sub fetcher(@) { + my (@urls) = @_; my $mux = new IO::Multiplex; @@ -145,7 +150,7 @@ # start children $BUSY = 0; - for (my $i = 0; $i < $n; ++$i) { + for (my $i = 0; $i < $jobs; ++$i) { my ($s1, $s2); socketpair($s1, $s2, AF_UNIX, SOCK_STREAM, PF_UNSPEC); $s1->autoflush(1); @@ -183,17 +188,17 @@ sub usage() { - print STDERR "usage: $0 [-j n] URL ...\n"; + print STDERR "usage: $0 [-d n] [-j n] URL ...\n"; exit(1); } MAIN:{ - my $jobs = 1; - GetOptions("j|jobs=i" => \$jobs) + GetOptions("j|jobs=i" => \$jobs, + "d|delay=i" => \$delay) or usage(); $jobs > 0 or usage(); @ARGV or usage(); - fetcher($jobs, @ARGV); + fetcher(@ARGV); } From phk at projects.linpro.no Fri Jul 13 07:11:55 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Jul 2007 09:11:55 +0200 (CEST) Subject: r1682 - trunk/varnish-cache/bin/varnishd Message-ID: <20070713071155.4216B1EC030@projects.linpro.no> Author: phk Date: 2007-07-13 09:11:54 +0200 (Fri, 13 Jul 2007) New Revision: 1682 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_session.c Log: Initialize all timestamps in the session to NAN Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-12 22:41:08 UTC (rev 1681) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-13 07:11:54 UTC (rev 1682) @@ -300,6 +300,7 @@ const char *doclose; struct http *http; + /* Timestamps, all on TIM_real() timescale */ double t_open; double t_req; double t_resp; Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2007-07-12 22:41:08 UTC (rev 1681) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2007-07-13 07:11:54 UTC (rev 1682) @@ -50,6 +50,7 @@ #include #include +#include #include #include @@ -308,6 +309,10 @@ sp->mysockaddr = (void*)(&sm->sockaddr[1]); sp->mysockaddrlen = sizeof(sm->sockaddr[1]); sp->sockaddr->sa_family = sp->mysockaddr->sa_family = PF_UNSPEC; + sp->t_open = NAN; + sp->t_req = NAN; + sp->t_resp = NAN; + sp->t_end = NAN; assert(len <= sp->sockaddrlen); if (addr != NULL) { From phk at projects.linpro.no Fri Jul 13 07:21:46 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Jul 2007 09:21:46 +0200 (CEST) Subject: r1683 - trunk/varnish-cache/bin/varnishd Message-ID: <20070713072146.88BAF1EC418@projects.linpro.no> Author: phk Date: 2007-07-13 09:21:46 +0200 (Fri, 13 Jul 2007) New Revision: 1683 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_acceptor.c trunk/varnish-cache/bin/varnishd/cache_acceptor.h trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c Log: Unify the recycle functionality of the acceptors, all three used the same method. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-13 07:11:54 UTC (rev 1682) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-13 07:21:46 UTC (rev 1683) @@ -360,6 +360,7 @@ void vca_close_session(struct sess *sp, const char *why); void VCA_Prep(struct sess *sp); void VCA_Init(void); +extern int vca_pipes[2]; /* cache_backend.c */ void VBE_Init(void); Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-07-13 07:11:54 UTC (rev 1682) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-07-13 07:21:46 UTC (rev 1683) @@ -76,6 +76,8 @@ static unsigned char need_sndtimeo, need_rcvtimeo, need_linger, need_test; +int vca_pipes[2]; + static void sock_test(int fd) { @@ -255,7 +257,10 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); AZ(sp->obj); AZ(sp->vcl); - vca_act->recycle(sp); + if (sp->fd < 0) + SES_Delete(sp); + else + assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp)); } @@ -273,6 +278,7 @@ fprintf(stderr, "No acceptor in program\n"); exit (2); } + AZ(pipe(vca_pipes)); vca_act->init(); AZ(pthread_create(&vca_thread_acct, NULL, vca_acct, NULL)); } Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.h 2007-07-13 07:11:54 UTC (rev 1682) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.h 2007-07-13 07:21:46 UTC (rev 1683) @@ -32,12 +32,10 @@ struct sess; typedef void acceptor_init_f(void); -typedef void acceptor_recycle_f(struct sess *); struct acceptor { const char *name; acceptor_init_f *init; - acceptor_recycle_f *recycle; }; #if defined(HAVE_EPOLL_CTL) Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2007-07-13 07:11:54 UTC (rev 1682) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2007-07-13 07:21:46 UTC (rev 1683) @@ -48,7 +48,6 @@ static pthread_t vca_epoll_thread; static int epfd = -1; -static int pipes[2]; static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead); @@ -79,12 +78,12 @@ epfd = epoll_create(16); assert(epfd >= 0); - vca_add(pipes[0], pipes); + vca_add(vca_pipes[0], vca_pipes); while (1) { if (epoll_wait(epfd, &ev, 1, 100) > 0) { - if (ev.data.ptr == pipes) { - i = read(pipes[0], &sp, sizeof sp); + if (ev.data.ptr == vca_pipes) { + i = read(vca_pipes[0], &sp, sizeof sp); assert(i == sizeof sp); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); TAILQ_INSERT_TAIL(&sesshead, sp, list); @@ -120,27 +119,15 @@ /*--------------------------------------------------------------------*/ static void -vca_epoll_recycle(struct sess *sp) -{ - - if (sp->fd < 0) - SES_Delete(sp); - else - assert(sizeof sp == write(pipes[1], &sp, sizeof sp)); -} - -static void vca_epoll_init(void) { - AZ(pipe(pipes)); AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL)); } struct acceptor acceptor_epoll = { .name = "epoll", .init = vca_epoll_init, - .recycle = vca_epoll_recycle, }; #endif /* defined(HAVE_EPOLL_CTL) */ Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2007-07-13 07:11:54 UTC (rev 1682) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2007-07-13 07:21:46 UTC (rev 1683) @@ -52,7 +52,6 @@ static int kq = -1; static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead); -static int pipes[2]; #define NKEV 100 @@ -81,9 +80,9 @@ struct sess *ss[NKEV]; AN(kp->udata); - if (kp->udata == pipes) { + if (kp->udata == vca_pipes) { j = 0; - i = read(pipes[0], ss, sizeof ss); + i = read(vca_pipes[0], ss, sizeof ss); if (i == -1 && errno == EAGAIN) return; while (i >= sizeof ss[0]) { @@ -135,7 +134,7 @@ j = 0; EV_SET(&ke[j++], 0, EVFILT_TIMER, EV_ADD, 0, 100, NULL); - EV_SET(&ke[j++], pipes[0], EVFILT_READ, EV_ADD, 0, 0, pipes); + EV_SET(&ke[j++], vca_pipes[0], EVFILT_READ, EV_ADD, 0, 0, vca_pipes); AZ(kevent(kq, ke, j, NULL, 0, NULL)); nki = 0; @@ -173,24 +172,13 @@ /*--------------------------------------------------------------------*/ static void -vca_kqueue_recycle(struct sess *sp) -{ - - if (sp->fd < 0) - SES_Delete(sp); - else - assert(write(pipes[1], &sp, sizeof sp) == sizeof sp); -} - -static void vca_kqueue_init(void) { int i; - AZ(pipe(pipes)); - i = fcntl(pipes[0], F_GETFL); + i = fcntl(vca_pipes[0], F_GETFL); i |= O_NONBLOCK; - i = fcntl(pipes[0], F_SETFL, i); + i = fcntl(vca_pipes[0], F_SETFL, i); AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL)); } @@ -198,7 +186,6 @@ struct acceptor acceptor_kqueue = { .name = "kqueue", .init = vca_kqueue_init, - .recycle = vca_kqueue_recycle, }; #endif /* defined(HAVE_KQUEUE) */ Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2007-07-13 07:11:54 UTC (rev 1682) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2007-07-13 07:21:46 UTC (rev 1683) @@ -51,8 +51,6 @@ static struct pollfd *pollfd; static unsigned npoll; -static int pipes[2]; - static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead); /*--------------------------------------------------------------------*/ @@ -109,13 +107,13 @@ (void)arg; - vca_poll(pipes[0]); + vca_poll(vca_pipes[0]); while (1) { v = poll(pollfd, npoll, 100); - if (v && pollfd[pipes[0]].revents) { + if (v && pollfd[vca_pipes[0]].revents) { v--; - i = read(pipes[0], &sp, sizeof sp); + i = read(vca_pipes[0], &sp, sizeof sp); assert(i == sizeof sp); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); TAILQ_INSERT_TAIL(&sesshead, sp, list); @@ -153,26 +151,15 @@ /*--------------------------------------------------------------------*/ static void -vca_poll_recycle(struct sess *sp) -{ - - if (sp->fd < 0) - SES_Delete(sp); - else - assert(sizeof sp == write(pipes[1], &sp, sizeof sp)); -} - -static void vca_poll_init(void) { - AZ(pipe(pipes)); + AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL)); } struct acceptor acceptor_poll = { .name = "poll", .init = vca_poll_init, - .recycle = vca_poll_recycle, }; #endif /* defined(HAVE_POLL) */ From phk at projects.linpro.no Fri Jul 13 07:27:51 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Jul 2007 09:27:51 +0200 (CEST) Subject: r1684 - trunk/varnish-cache/bin/varnishd Message-ID: <20070713072751.1E8391EC1F5@projects.linpro.no> Author: phk Date: 2007-07-13 09:27:50 +0200 (Fri, 13 Jul 2007) New Revision: 1684 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_session.c Log: Clean all but t_open timestamps to NAN at end of transaction. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-13 07:21:46 UTC (rev 1683) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-13 07:27:50 UTC (rev 1684) @@ -58,6 +58,7 @@ #include #include +#include #include #include #include @@ -196,8 +197,11 @@ sp->xid, sp->t_req, sp->t_end, dh, dp, da); sp->xid = 0; + SES_Charge(sp); sp->t_open = sp->t_end; - SES_Charge(sp); + sp->t_req = NAN; + sp->t_resp = NAN; + sp->t_end = NAN; WSL_Flush(sp->wrk); if (sp->fd >= 0 && sp->doclose != NULL) vca_close_session(sp, sp->doclose); Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2007-07-13 07:21:46 UTC (rev 1683) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2007-07-13 07:27:50 UTC (rev 1684) @@ -229,6 +229,7 @@ ses_sum_acct(&sp->acct, a); if (sp->srcaddr != NULL) { + /* XXX: only report once per second ? */ CHECK_OBJ(sp->srcaddr, SRCADDR_MAGIC); LOCK(&sp->srcaddr->sah->mtx); ses_sum_acct(&sp->srcaddr->acct, a); From phk at projects.linpro.no Fri Jul 13 07:47:45 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Jul 2007 09:47:45 +0200 (CEST) Subject: r1685 - trunk/varnish-cache/bin/varnishd Message-ID: <20070713074745.79CDC1EC418@projects.linpro.no> Author: phk Date: 2007-07-13 09:47:45 +0200 (Fri, 13 Jul 2007) New Revision: 1685 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_pool.c Log: Rename the "idle" field of struct worker to "used", which is more precise. Don't use the "used" field to signal suicide for worker threads, use the "wrq" field which is much more natural. Set the "used" field to NAN before doing anything and assert that somebody updated during the task. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-13 07:27:50 UTC (rev 1684) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-13 07:47:45 UTC (rev 1685) @@ -149,7 +149,7 @@ struct objhead *nobjhead; struct object *nobj; - double idle; + double used; int pipe[2]; Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-13 07:27:50 UTC (rev 1684) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-13 07:47:45 UTC (rev 1685) @@ -185,7 +185,7 @@ } sp->t_end = TIM_real(); - sp->wrk->idle = sp->t_end; + sp->wrk->used = sp->t_end; if (sp->xid == 0) { sp->t_req = sp->t_end; sp->t_resp = sp->t_end; @@ -332,7 +332,7 @@ assert(sp->xid == 0); VCA_Prep(sp); - sp->wrk->idle = sp->t_open; + sp->wrk->used = sp->t_open; sp->wrk->acct.sess++; SES_RefSrcAddr(sp); do @@ -660,7 +660,7 @@ /* Update stats of various sorts */ VSL_stats->client_req++; /* XXX not locked */ sp->t_req = TIM_real(); - sp->wrk->idle = sp->t_req; + sp->wrk->used = sp->t_req; sp->wrk->acct.req++; /* Assign XID and log */ Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2007-07-13 07:27:50 UTC (rev 1684) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2007-07-13 07:47:45 UTC (rev 1685) @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -181,6 +182,7 @@ struct workreq *wrq; AN(w->wrq); + w->used = NAN; wrq = w->wrq; CHECK_OBJ_NOTNULL(wrq->sess, SESS_MAGIC); wrq->sess->wrk = w; @@ -193,6 +195,7 @@ CHECK_OBJ(w->nobj, OBJECT_MAGIC); if (w->nobjhead != NULL) CHECK_OBJ(w->nobjhead, OBJHEAD_MAGIC); + assert(!isnan(w->used)); w->wrq = NULL; } @@ -207,7 +210,7 @@ w = &ww; memset(w, 0, sizeof *w); w->magic = WORKER_MAGIC; - w->idle = TIM_real(); + w->used = TIM_real(); w->wlp = w->wlog; w->wle = w->wlog + sizeof w->wlog; AZ(pipe(w->pipe)); @@ -236,10 +239,10 @@ LOCK(&qp->mtx); TAILQ_INSERT_HEAD(&qp->idle, w, list); - assert(w->idle != 0); + assert(!isnan(w->used)); UNLOCK(&qp->mtx); assert(1 == read(w->pipe[0], &c, 1)); - if (w->idle == 0) + if (w->wrq == NULL) break; wrk_do_one(w); } @@ -398,7 +401,7 @@ LOCK(&qp->mtx); w = TAILQ_LAST(&qp->idle, workerhead); if (w != NULL && - (w->idle + params->wthread_timeout < now || + (w->used + params->wthread_timeout < now || VSL_stats->n_wrk > params->wthread_max)) TAILQ_REMOVE(&qp->idle, w, list); else @@ -406,7 +409,7 @@ UNLOCK(&qp->mtx); if (w == NULL) continue; - w->idle = 0; + AZ(w->wrq); assert(1 == write(w->pipe[1], w, 1)); } } From phk at projects.linpro.no Fri Jul 13 07:53:08 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Jul 2007 09:53:08 +0200 (CEST) Subject: r1686 - trunk/varnish-cache/bin/varnishd Message-ID: <20070713075308.C0BF41EC1F5@projects.linpro.no> Author: phk Date: 2007-07-13 09:53:08 +0200 (Fri, 13 Jul 2007) New Revision: 1686 Modified: trunk/varnish-cache/bin/varnishd/cache_http.c Log: Clarify XXX comment Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-13 07:47:45 UTC (rev 1685) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-13 07:53:08 UTC (rev 1686) @@ -859,7 +859,7 @@ { CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - /* XXX ??? to->f = to->v; Not sure this is valid */ + /* XXX: don't to->f = to->v; it would kill pipelining */ to->nhd = HTTP_HDR_FIRST; memset(to->hd, 0, sizeof to->hd); } From phk at projects.linpro.no Fri Jul 13 07:58:11 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Jul 2007 09:58:11 +0200 (CEST) Subject: r1687 - trunk/varnish-cache/bin/varnishd Message-ID: <20070713075811.DA68A1EC1F5@projects.linpro.no> Author: phk Date: 2007-07-13 09:58:11 +0200 (Fri, 13 Jul 2007) New Revision: 1687 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_response.c Log: Move setting of t_resp up to before we build the response. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-13 07:53:08 UTC (rev 1686) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-13 07:58:11 UTC (rev 1687) @@ -146,6 +146,7 @@ cnt_deliver(struct sess *sp) { + sp->t_resp = TIM_real(); RES_BuildHttp(sp); VCL_deliver_method(sp); if (sp->handling != VCL_RET_DELIVER) Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-13 07:53:08 UTC (rev 1686) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-13 07:58:11 UTC (rev 1687) @@ -147,7 +147,6 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - sp->t_resp = TIM_real(); WRK_Reset(sp->wrk, &sp->fd); sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); From phk at projects.linpro.no Fri Jul 13 08:05:14 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Jul 2007 10:05:14 +0200 (CEST) Subject: r1688 - trunk/varnish-cache/bin/varnishd Message-ID: <20070713080514.38CEB1EC030@projects.linpro.no> Author: phk Date: 2007-07-13 10:05:14 +0200 (Fri, 13 Jul 2007) New Revision: 1688 Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c Log: Add an XXX comment Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- trunk/varnish-cache/bin/varnishd/rfc2616.c 2007-07-13 07:58:11 UTC (rev 1687) +++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2007-07-13 08:05:14 UTC (rev 1688) @@ -121,6 +121,14 @@ retirement_age = u1 - u2; } + /* + * XXX: if the backends time is too skewed relative to our own + * XXX: we should blacklist the backend, to avoid getting totally + * XXX: bogus results further down. Exactly what "too skewed" means + * XXX: in this context is a good question. It could be determined + * XXX: out according to the backends headers, but a simple fixed + * XXX: tolerance of a minute either way would be more predictable. + */ h_date = 0; if (http_GetHdr(hp, H_Date, &p)) h_date = TIM_parse(p); From des at projects.linpro.no Fri Jul 13 11:31:36 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 13 Jul 2007 13:31:36 +0200 (CEST) Subject: r1689 - trunk/varnish-tools/fetcher Message-ID: <20070713113136.5F33E1EC404@projects.linpro.no> Author: des Date: 2007-07-13 13:31:36 +0200 (Fri, 13 Jul 2007) New Revision: 1689 Modified: trunk/varnish-tools/fetcher/fetcher.pl Log: Strip fragments and query strings. Modified: trunk/varnish-tools/fetcher/fetcher.pl =================================================================== --- trunk/varnish-tools/fetcher/fetcher.pl 2007-07-13 08:05:14 UTC (rev 1688) +++ trunk/varnish-tools/fetcher/fetcher.pl 2007-07-13 11:31:36 UTC (rev 1689) @@ -75,7 +75,7 @@ $0 = "[fetcher] checking $url"; if ($resp->header('Content-Type') =~ m/^text\//) { my %urls = map { $_ => 1 } - ($resp->content =~ m/\b(?:href|src)=[\'\"](.+?)[\'\"]/g); + ($resp->content =~ m/\b(?:href|src)=[\'\"]([^\'\"\?\#]+)(?:[\?\#][^\'\"]*)?[\'\"]/g); foreach (keys(%urls)) { $s->write("add $_\n"); } From des at projects.linpro.no Fri Jul 13 11:42:02 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 13 Jul 2007 13:42:02 +0200 (CEST) Subject: r1690 - trunk/varnish-cache/doc Message-ID: <20070713114202.5E5421EC1F6@projects.linpro.no> Author: des Date: 2007-07-13 13:42:02 +0200 (Fri, 13 Jul 2007) New Revision: 1690 Modified: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml Log: Add an entry for r1531. Modified: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.0.4-1.1.xml 2007-07-13 11:31:36 UTC (rev 1689) +++ trunk/varnish-cache/doc/changes-1.0.4-1.1.xml 2007-07-13 11:42:02 UTC (rev 1690) @@ -189,6 +189,12 @@ varnishncsa can now also process log data from backend traffic. + + + A bug that would cause varnishncsa to + segfault when it encountered an empty HTTP header in the log + file has been fixed. + From des at projects.linpro.no Fri Jul 13 14:27:55 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 13 Jul 2007 16:27:55 +0200 (CEST) Subject: r1691 - trunk/varnish-cache/man Message-ID: <20070713142755.C07C31EC418@projects.linpro.no> Author: des Date: 2007-07-13 16:27:55 +0200 (Fri, 13 Jul 2007) New Revision: 1691 Modified: trunk/varnish-cache/man/vcl.7 Log: Document regsub(). Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-07-13 11:42:02 UTC (rev 1690) +++ trunk/varnish-cache/man/vcl.7 2007-07-13 14:27:55 UTC (rev 1691) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd July 5, 2007 +.Dd July 13, 2007 .Dt VCL 7 .Os .Sh NAME @@ -116,6 +116,27 @@ pipe; } .Ed +.Ss Functions +The following built-in functions are available: +.Bl -tag -width indent +.It Fn regsub "str" "regex" "sub" +Returns a copy of +.Fa str +with all occurrences of the regular expression +.Fa regex +replaced with +.Fa sub . +Within +.Fa sub , +.Va $0 +(which can also be spelled +.Va & ) +is replaced with the entire matched string, and +.Va $n +is replaced with the contents of subgroup +.Ar n +in the matched string. +.El .Ss Subroutines A subroutine is used to group code for legibility or reusability: .Bd -literal -offset 4n @@ -145,7 +166,7 @@ request should be handled. Each subroutine terminates by calling one of a small number of keywords which indicates the desired outcome. -.Bl -tag -width "vcl_timeout" +.Bl -tag -width indent .\" vcl_recv .It Cm vcl_recv Called at the beginning of a request, after the complete request has @@ -156,7 +177,7 @@ The .Cm vcl_recv subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -186,7 +207,7 @@ The .Cm vcl_pipe subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -205,7 +226,7 @@ The .Cm vcl_pass subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -218,7 +239,7 @@ The .Cm vcl_hash subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm hash Proceed. .El @@ -230,7 +251,7 @@ The .Cm vcl_hit subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -253,7 +274,7 @@ The .Cm vcl_miss subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -274,7 +295,7 @@ The .Cm vcl_fetch subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -294,7 +315,7 @@ The .Cm vcl_deliver subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -309,7 +330,7 @@ The .Cm vcl_timeout subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm fetch Request a fresh copy of the object from the backend. .It Cm discard @@ -324,7 +345,7 @@ The .Cm vcl_discard subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm discard Discard the object. .It Cm keep From phk at phk.freebsd.dk Fri Jul 13 14:32:32 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Fri, 13 Jul 2007 14:32:32 +0000 Subject: r1691 - trunk/varnish-cache/man In-Reply-To: Your message of "Fri, 13 Jul 2007 16:27:55 +0200." <20070713142755.C07C31EC418@projects.linpro.no> Message-ID: <80840.1184337152@critter.freebsd.dk> In message <20070713142755.C07C31EC418 at projects.linpro.no>, des at projects.linpro .no writes: >Document regsub(). We should probably mention the limitations: We should probably mention that regsub() is not a general subroutine, it is only available in "set" statements that set string variables. Similarly, the string concatenation is also only available in set of string variables. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk at FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From des at projects.linpro.no Fri Jul 13 14:53:48 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 13 Jul 2007 16:53:48 +0200 (CEST) Subject: r1692 - trunk/varnish-cache/doc Message-ID: <20070713145348.EEE441EC1F6@projects.linpro.no> Author: des Date: 2007-07-13 16:53:48 +0200 (Fri, 13 Jul 2007) New Revision: 1692 Modified: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml Log: Document recent changes. Modified: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.0.4-1.1.xml 2007-07-13 14:27:55 UTC (rev 1691) +++ trunk/varnish-cache/doc/changes-1.0.4-1.1.xml 2007-07-13 14:53:48 UTC (rev 1692) @@ -155,6 +155,29 @@ corresponding variable, and strip an HTTP header by using the remove keyword. + + + VCL scripts can now modify the HTTP status code of cached + objects (obj.status) and responses + (resp.status) + + + + Numeric and other non-textual variables in VCL can now be + assigned to textual variables; they will be converted as + needed. + + + + VCL scripts can now apply regular expression substitutions + to textual variables using the regsub + function. + + + + A new management command, status, + returns the state of the child. + From des at projects.linpro.no Fri Jul 13 14:54:51 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 13 Jul 2007 16:54:51 +0200 (CEST) Subject: r1693 - in branches/1.1: . bin/varnishd doc include lib/libvarnish lib/libvcl man Message-ID: <20070713145451.DDD001EC45F@projects.linpro.no> Author: des Date: 2007-07-13 16:54:51 +0200 (Fri, 13 Jul 2007) New Revision: 1693 Added: branches/1.1/lib/libvcl/vcc_string.c Modified: branches/1.1/ branches/1.1/bin/varnishd/Makefile.am branches/1.1/bin/varnishd/cache.h branches/1.1/bin/varnishd/cache_acceptor.c branches/1.1/bin/varnishd/cache_acceptor.h branches/1.1/bin/varnishd/cache_acceptor_epoll.c branches/1.1/bin/varnishd/cache_acceptor_kqueue.c branches/1.1/bin/varnishd/cache_acceptor_poll.c branches/1.1/bin/varnishd/cache_backend.c branches/1.1/bin/varnishd/cache_center.c branches/1.1/bin/varnishd/cache_expire.c branches/1.1/bin/varnishd/cache_fetch.c branches/1.1/bin/varnishd/cache_hash.c branches/1.1/bin/varnishd/cache_http.c branches/1.1/bin/varnishd/cache_lru.c branches/1.1/bin/varnishd/cache_main.c branches/1.1/bin/varnishd/cache_pipe.c branches/1.1/bin/varnishd/cache_pool.c branches/1.1/bin/varnishd/cache_response.c branches/1.1/bin/varnishd/cache_session.c branches/1.1/bin/varnishd/cache_synthetic.c branches/1.1/bin/varnishd/cache_vrt.c branches/1.1/bin/varnishd/cache_vrt_re.c branches/1.1/bin/varnishd/mgt_child.c branches/1.1/bin/varnishd/mgt_cli.c branches/1.1/bin/varnishd/mgt_cli.h branches/1.1/bin/varnishd/mgt_event.c branches/1.1/bin/varnishd/rfc2616.c branches/1.1/bin/varnishd/shmlog.c branches/1.1/bin/varnishd/varnishd.1 branches/1.1/doc/changes-1.0.4-1.1.xml branches/1.1/include/cli.h branches/1.1/include/libvarnish.h branches/1.1/include/shmlog_tags.h branches/1.1/include/vrt.h branches/1.1/include/vrt_obj.h branches/1.1/lib/libvarnish/Makefile.am branches/1.1/lib/libvarnish/time.c branches/1.1/lib/libvcl/Makefile.am branches/1.1/lib/libvcl/syntax.txt branches/1.1/lib/libvcl/vcc_acl.c branches/1.1/lib/libvcl/vcc_action.c branches/1.1/lib/libvcl/vcc_compile.c branches/1.1/lib/libvcl/vcc_compile.h branches/1.1/lib/libvcl/vcc_fixed_token.c branches/1.1/lib/libvcl/vcc_gen_obj.tcl branches/1.1/lib/libvcl/vcc_obj.c branches/1.1/lib/libvcl/vcc_parse.c branches/1.1/lib/libvcl/vcc_var.c branches/1.1/lib/libvcl/vcc_xref.c branches/1.1/man/vcl.7 Log: Merged revisions 1649-1650,1655-1692 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1657 | phk | 2007-07-05 23:08:15 +0200 (Thu, 05 Jul 2007) | 2 lines Clean up FlexeLint fluff. ........ r1658 | phk | 2007-07-06 12:07:30 +0200 (Fri, 06 Jul 2007) | 3 lines Don't rewrite pipe'ed requests to "GET". ........ r1659 | phk | 2007-07-09 22:23:41 +0200 (Mon, 09 Jul 2007) | 10 lines Make all protocol header fields writable, except obj.status and resp.status (which are numeric, they'll follow shortly) Unify the shmemlog tag used for failure to rewrite something, the Rx/Tx/Obj distinction is not helpful enough to warrant the complexity of it. ........ r1660 | phk | 2007-07-09 22:34:59 +0200 (Mon, 09 Jul 2007) | 2 lines Allow assignment to INT type variables ........ r1661 | phk | 2007-07-09 22:35:20 +0200 (Mon, 09 Jul 2007) | 2 lines Allow assignment to obj.status and resp.status ........ r1662 | phk | 2007-07-10 21:46:16 +0200 (Tue, 10 Jul 2007) | 6 lines Move string stuff to vcc_string.c, there's going to be a fair bit of it. Give vcc_StringVal() a return value to say if it did anything so we can emit better error messages when confused. ........ r1663 | phk | 2007-07-10 21:59:39 +0200 (Tue, 10 Jul 2007) | 5 lines Add conversion from IP to string format to allow things like: set bereq.http.HeyYou = client.ip " asked for " req.url; ........ r1664 | phk | 2007-07-10 22:07:07 +0200 (Tue, 10 Jul 2007) | 3 lines Properly emit the header name in VRT_SetHdr(); ........ r1665 | phk | 2007-07-10 22:08:39 +0200 (Tue, 10 Jul 2007) | 2 lines Fix VRT_SetHdr() prototype ........ r1666 | phk | 2007-07-10 22:43:24 +0200 (Tue, 10 Jul 2007) | 2 lines Add compiler side support for regsub() but only a dummy function in VRT. ........ r1667 | phk | 2007-07-10 23:30:47 +0200 (Tue, 10 Jul 2007) | 60 lines Add "regsub" support for string manipulation. Notice this facility is subject to change! "regsub" is short for regular expression substitution and it is probably easiest to explain with some examples: sub vcl_recv { set req.url = regsub(req.url, "#.*", ""); } This will replace the requests URL with the output of the regsub() function regsub() takes three arguments: the string to be examined, a regular expression and a replacement string. In this case, everything after the first '#' is removed (replaced with nothing). The replacement string recognizes the following magic sequences: & - insert everything matched by the regexp $0 - ditto. $1 - replace with the first submatch of the regexp $2 - replace with the second submatch of the regexp ... $9 - replace with the ninth submatch of the regexp (The $0..$9 syntax was chosen over the \0...\9 syntax in order to avoid a nightmare of escape characters in the VCL source code. Arguments and suggestions are welcome). A more advanced example: set bereq.http.ClientIP = regsub(client.ip, "(.*):(.*)", "$2 $1"); The client.ip variable expands to IP:port number, for instance 127.0.0.1:54662 The regular expression "(.*):(.*)" results in the the following matches: & + $0 "127.0.0.1:54662" $1 "127.0.0.1" $2 "54662" So the replacement string "$2 $1" results in "54662 127.0.0.1" And the completed header which is sent to the backend will look like: "ClientIP: 54662 127.0.0.1" An even more advanced example would be: set bereq.http.magic = "Client IP = " regsub(client.ip, ":", " port = "); Where we also exploint the string concatenation ability of the "set" statement. The result string is built in the request workspace, so you may need to increase the workspace size if you do a lot of regsub()'s. Currently there is no decent error handling for running out of workspace. ........ r1668 | phk | 2007-07-12 11:04:54 +0200 (Thu, 12 Jul 2007) | 6 lines Add TIM_mono() and TIM_real() which return double representations of timestamps on a monotonic and the UTC timescales respectively. Doubles are much more convenient than timespecs for comparisons etc. ........ r1669 | phk | 2007-07-12 11:25:07 +0200 (Thu, 12 Jul 2007) | 2 lines Replace ev_now() with TIM_mono(). ........ r1670 | phk | 2007-07-12 11:25:45 +0200 (Thu, 12 Jul 2007) | 2 lines Replace Uptime() with TIM_mono() ........ r1671 | phk | 2007-07-12 11:49:26 +0200 (Thu, 12 Jul 2007) | 6 lines Change all timekeeping to use doubles instead of time_t and struct timespec. Eliminate all direct calls to time(2) and clockgettime(2) and use TIM_real() and TIM_mono() exclusively. ........ r1672 | phk | 2007-07-12 12:00:13 +0200 (Thu, 12 Jul 2007) | 2 lines Document timescale of srcaddr->ttl ........ r1673 | phk | 2007-07-12 12:13:29 +0200 (Thu, 12 Jul 2007) | 2 lines Convert the last time(2) calls to TIM_real() ........ r1674 | cecilihf | 2007-07-12 12:20:33 +0200 (Thu, 12 Jul 2007) | 2 lines Added a new cli option, status, for checking the status of the varnish child process. This is for use in the webmin plugin. ........ r1675 | cecilihf | 2007-07-12 12:27:37 +0200 (Thu, 12 Jul 2007) | 2 lines Fixed typo ........ r1676 | des | 2007-07-12 18:00:04 +0200 (Thu, 12 Jul 2007) | 2 lines RT_LIBS dependency has moved from varnishd to libvarnish. ........ r1677 | des | 2007-07-12 18:02:47 +0200 (Thu, 12 Jul 2007) | 2 lines Add missing semicolon. ........ r1678 | des | 2007-07-12 19:37:44 +0200 (Thu, 12 Jul 2007) | 2 lines sockaddr.sa_len is not portable. ........ r1682 | phk | 2007-07-13 09:11:54 +0200 (Fri, 13 Jul 2007) | 2 lines Initialize all timestamps in the session to NAN ........ r1683 | phk | 2007-07-13 09:21:46 +0200 (Fri, 13 Jul 2007) | 4 lines Unify the recycle functionality of the acceptors, all three used the same method. ........ r1684 | phk | 2007-07-13 09:27:50 +0200 (Fri, 13 Jul 2007) | 2 lines Clean all but t_open timestamps to NAN at end of transaction. ........ r1685 | phk | 2007-07-13 09:47:45 +0200 (Fri, 13 Jul 2007) | 9 lines Rename the "idle" field of struct worker to "used", which is more precise. Don't use the "used" field to signal suicide for worker threads, use the "wrq" field which is much more natural. Set the "used" field to NAN before doing anything and assert that somebody updated during the task. ........ r1686 | phk | 2007-07-13 09:53:08 +0200 (Fri, 13 Jul 2007) | 2 lines Clarify XXX comment ........ r1687 | phk | 2007-07-13 09:58:11 +0200 (Fri, 13 Jul 2007) | 3 lines Move setting of t_resp up to before we build the response. ........ r1688 | phk | 2007-07-13 10:05:14 +0200 (Fri, 13 Jul 2007) | 2 lines Add an XXX comment ........ r1690 | des | 2007-07-13 13:42:02 +0200 (Fri, 13 Jul 2007) | 2 lines Add an entry for r1531. ........ r1691 | des | 2007-07-13 16:27:55 +0200 (Fri, 13 Jul 2007) | 2 lines Document regsub(). ........ r1692 | des | 2007-07-13 16:53:48 +0200 (Fri, 13 Jul 2007) | 2 lines Document recent changes. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1648,1651-1654 + /trunk/varnish-cache:1-1692 Modified: branches/1.1/bin/varnishd/Makefile.am =================================================================== --- branches/1.1/bin/varnishd/Makefile.am 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/Makefile.am 2007-07-13 14:54:51 UTC (rev 1693) @@ -68,4 +68,4 @@ $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ $(top_builddir)/lib/libvcl/libvcl.la \ - ${DL_LIBS} ${RT_LIBS} ${PTHREAD_LIBS} + ${DL_LIBS} ${PTHREAD_LIBS} Modified: branches/1.1/bin/varnishd/cache.h =================================================================== --- branches/1.1/bin/varnishd/cache.h 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache.h 2007-07-13 14:54:51 UTC (rev 1693) @@ -131,7 +131,7 @@ /*--------------------------------------------------------------------*/ struct acct { - time_t first; + double first; uint64_t sess; uint64_t req; uint64_t pipe; @@ -149,7 +149,7 @@ struct objhead *nobjhead; struct object *nobj; - time_t idle; + double used; int pipe[2]; @@ -247,11 +247,11 @@ unsigned busy; unsigned len; - time_t age; - time_t entered; - time_t ttl; + double age; + double entered; + double ttl; - time_t last_modified; + double last_modified; struct http http; TAILQ_ENTRY(object) list; @@ -262,7 +262,7 @@ TAILQ_HEAD(, sess) waitinglist; - time_t lru_stamp; + double lru_stamp; TAILQ_ENTRY(object) lru; }; @@ -300,10 +300,11 @@ const char *doclose; struct http *http; - struct timespec t_open; - struct timespec t_req; - struct timespec t_resp; - struct timespec t_end; + /* Timestamps, all on TIM_real() timescale */ + double t_open; + double t_req; + double t_resp; + double t_end; enum step step; unsigned handling; @@ -359,6 +360,7 @@ void vca_close_session(struct sess *sp, const char *why); void VCA_Prep(struct sess *sp); void VCA_Init(void); +extern int vca_pipes[2]; /* cache_backend.c */ void VBE_Init(void); @@ -412,6 +414,7 @@ void http_PutResponse(struct worker *w, int fd, struct http *to, const char *response); void http_PrintfHeader(struct worker *w, int fd, struct http *to, const char *fmt, ...); void http_SetHeader(struct worker *w, int fd, struct http *to, const char *hdr); +void http_SetH(struct http *to, unsigned n, const char *fm); void http_Setup(struct http *ht, void *space, unsigned len); int http_GetHdr(struct http *hp, const char *hdr, char **ptr); int http_GetHdrField(struct http *hp, const char *hdr, const char *field, char **ptr); @@ -428,7 +431,6 @@ void http_DoConnection(struct sess *sp); void http_CopyHome(struct worker *w, int fd, struct http *hp); void http_Unset(struct http *hp, const char *hdr); -void http_LogLostHeader(struct worker *w, int fd, struct http *hp, const char *hdr); #define HTTPH(a, b, c, d, e, f, g) extern char b[]; @@ -492,11 +494,11 @@ /* cache_lru.c */ // void LRU_Init(void); -void LRU_Enter(struct object *o, time_t stamp); +void LRU_Enter(struct object *o, double stamp); void LRU_Remove(struct object *o); int LRU_DiscardOne(void); int LRU_DiscardSpace(int64_t quota); -int LRU_DiscardTime(time_t cutoff); +int LRU_DiscardTime(double cutoff); #define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *); Modified: branches/1.1/bin/varnishd/cache_acceptor.c =================================================================== --- branches/1.1/bin/varnishd/cache_acceptor.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_acceptor.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -44,10 +44,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #ifndef HAVE_SRANDOMDEV #include "compat/srandomdev.h" #endif @@ -80,6 +76,8 @@ static unsigned char need_sndtimeo, need_rcvtimeo, need_linger, need_test; +int vca_pipes[2]; + static void sock_test(int fd) { @@ -116,7 +114,7 @@ TCP_name(sp->sockaddr, sp->sockaddrlen, sp->addr, sizeof sp->addr, sp->port, sizeof sp->port); VSL(SLT_SessionOpen, sp->fd, "%s %s", sp->addr, sp->port); - sp->acct.first = sp->t_open.tv_sec; + sp->acct.first = sp->t_open; if (need_test) sock_test(sp->fd); if (need_linger) @@ -195,7 +193,7 @@ sp->fd = i; sp->id = i; - (void)clock_gettime(CLOCK_REALTIME, &sp->t_open); + sp->t_open = TIM_real(); http_RecvPrep(sp->http); sp->step = STP_FIRST; @@ -259,7 +257,10 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); AZ(sp->obj); AZ(sp->vcl); - vca_act->recycle(sp); + if (sp->fd < 0) + SES_Delete(sp); + else + assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp)); } @@ -277,6 +278,7 @@ fprintf(stderr, "No acceptor in program\n"); exit (2); } + AZ(pipe(vca_pipes)); vca_act->init(); AZ(pthread_create(&vca_thread_acct, NULL, vca_acct, NULL)); } Modified: branches/1.1/bin/varnishd/cache_acceptor.h =================================================================== --- branches/1.1/bin/varnishd/cache_acceptor.h 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_acceptor.h 2007-07-13 14:54:51 UTC (rev 1693) @@ -32,12 +32,10 @@ struct sess; typedef void acceptor_init_f(void); -typedef void acceptor_recycle_f(struct sess *); struct acceptor { const char *name; acceptor_init_f *init; - acceptor_recycle_f *recycle; }; #if defined(HAVE_EPOLL_CTL) Modified: branches/1.1/bin/varnishd/cache_acceptor_epoll.c =================================================================== --- branches/1.1/bin/varnishd/cache_acceptor_epoll.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_acceptor_epoll.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -41,10 +41,6 @@ #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "heritage.h" #include "shmlog.h" #include "cache.h" @@ -52,7 +48,6 @@ static pthread_t vca_epoll_thread; static int epfd = -1; -static int pipes[2]; static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead); @@ -74,7 +69,7 @@ vca_main(void *arg) { struct epoll_event ev; - struct timespec ts; + double deadline; struct sess *sp, *sp2; int i; @@ -83,12 +78,12 @@ epfd = epoll_create(16); assert(epfd >= 0); - vca_add(pipes[0], pipes); + vca_add(vca_pipes[0], vca_pipes); while (1) { if (epoll_wait(epfd, &ev, 1, 100) > 0) { - if (ev.data.ptr == pipes) { - i = read(pipes[0], &sp, sizeof sp); + if (ev.data.ptr == vca_pipes) { + i = read(vca_pipes[0], &sp, sizeof sp); assert(i == sizeof sp); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); TAILQ_INSERT_TAIL(&sesshead, sp, list); @@ -108,15 +103,11 @@ } } /* check for timeouts */ - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec -= params->sess_timeout; + deadline = TIM_real() - params->sess_timeout; TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - if (sp->t_open.tv_sec > ts.tv_sec) + if (sp->t_open > deadline) continue; - if (sp->t_open.tv_sec == ts.tv_sec && - sp->t_open.tv_nsec > ts.tv_nsec) - continue; TAILQ_REMOVE(&sesshead, sp, list); vca_del(sp->fd); vca_close_session(sp, "timeout"); @@ -128,27 +119,15 @@ /*--------------------------------------------------------------------*/ static void -vca_epoll_recycle(struct sess *sp) -{ - - if (sp->fd < 0) - SES_Delete(sp); - else - assert(sizeof sp == write(pipes[1], &sp, sizeof sp)); -} - -static void vca_epoll_init(void) { - AZ(pipe(pipes)); AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL)); } struct acceptor acceptor_epoll = { .name = "epoll", .init = vca_epoll_init, - .recycle = vca_epoll_recycle, }; #endif /* defined(HAVE_EPOLL_CTL) */ Modified: branches/1.1/bin/varnishd/cache_acceptor_kqueue.c =================================================================== --- branches/1.1/bin/varnishd/cache_acceptor_kqueue.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_acceptor_kqueue.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -43,10 +43,6 @@ #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "heritage.h" #include "shmlog.h" #include "cache.h" @@ -56,7 +52,6 @@ static int kq = -1; static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead); -static int pipes[2]; #define NKEV 100 @@ -85,9 +80,9 @@ struct sess *ss[NKEV]; AN(kp->udata); - if (kp->udata == pipes) { + if (kp->udata == vca_pipes) { j = 0; - i = read(pipes[0], ss, sizeof ss); + i = read(vca_pipes[0], ss, sizeof ss); if (i == -1 && errno == EAGAIN) return; while (i >= sizeof ss[0]) { @@ -129,7 +124,7 @@ { struct kevent ke[NKEV], *kp; int j, n, dotimer; - struct timespec ts; + double deadline; struct sess *sp; (void)arg; @@ -139,7 +134,7 @@ j = 0; EV_SET(&ke[j++], 0, EVFILT_TIMER, EV_ADD, 0, 100, NULL); - EV_SET(&ke[j++], pipes[0], EVFILT_READ, EV_ADD, 0, 0, pipes); + EV_SET(&ke[j++], vca_pipes[0], EVFILT_READ, EV_ADD, 0, 0, vca_pipes); AZ(kevent(kq, ke, j, NULL, 0, NULL)); nki = 0; @@ -160,17 +155,13 @@ } if (!dotimer) continue; - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec -= params->sess_timeout; + deadline = TIM_real() - params->sess_timeout; for (;;) { sp = TAILQ_FIRST(&sesshead); if (sp == NULL) break; - if (sp->t_open.tv_sec > ts.tv_sec) + if (sp->t_open > deadline) break; - if (sp->t_open.tv_sec == ts.tv_sec && - sp->t_open.tv_nsec > ts.tv_nsec) - break; TAILQ_REMOVE(&sesshead, sp, list); vca_close_session(sp, "timeout"); SES_Delete(sp); @@ -181,24 +172,13 @@ /*--------------------------------------------------------------------*/ static void -vca_kqueue_recycle(struct sess *sp) -{ - - if (sp->fd < 0) - SES_Delete(sp); - else - assert(write(pipes[1], &sp, sizeof sp) == sizeof sp); -} - -static void vca_kqueue_init(void) { int i; - AZ(pipe(pipes)); - i = fcntl(pipes[0], F_GETFL); + i = fcntl(vca_pipes[0], F_GETFL); i |= O_NONBLOCK; - i = fcntl(pipes[0], F_SETFL, i); + i = fcntl(vca_pipes[0], F_SETFL, i); AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL)); } @@ -206,7 +186,6 @@ struct acceptor acceptor_kqueue = { .name = "kqueue", .init = vca_kqueue_init, - .recycle = vca_kqueue_recycle, }; #endif /* defined(HAVE_KQUEUE) */ Modified: branches/1.1/bin/varnishd/cache_acceptor_poll.c =================================================================== --- branches/1.1/bin/varnishd/cache_acceptor_poll.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_acceptor_poll.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -42,10 +42,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "heritage.h" #include "shmlog.h" #include "cache.h" @@ -55,8 +51,6 @@ static struct pollfd *pollfd; static unsigned npoll; -static int pipes[2]; - static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead); /*--------------------------------------------------------------------*/ @@ -108,25 +102,24 @@ { unsigned v; struct sess *sp, *sp2; - struct timespec ts; + double deadline; int i, fd; (void)arg; - vca_poll(pipes[0]); + vca_poll(vca_pipes[0]); while (1) { v = poll(pollfd, npoll, 100); - if (v && pollfd[pipes[0]].revents) { + if (v && pollfd[vca_pipes[0]].revents) { v--; - i = read(pipes[0], &sp, sizeof sp); + i = read(vca_pipes[0], &sp, sizeof sp); assert(i == sizeof sp); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); TAILQ_INSERT_TAIL(&sesshead, sp, list); vca_poll(sp->fd); } - clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_sec -= params->sess_timeout; + deadline = TIM_real() - params->sess_timeout; TAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) { if (v == 0) break; @@ -145,11 +138,8 @@ SES_Delete(sp); continue; } - if (sp->t_open.tv_sec > ts.tv_sec) + if (sp->t_open > deadline) continue; - if (sp->t_open.tv_sec == ts.tv_sec && - sp->t_open.tv_nsec > ts.tv_nsec) - continue; TAILQ_REMOVE(&sesshead, sp, list); vca_unpoll(fd); vca_close_session(sp, "timeout"); @@ -161,26 +151,15 @@ /*--------------------------------------------------------------------*/ static void -vca_poll_recycle(struct sess *sp) -{ - - if (sp->fd < 0) - SES_Delete(sp); - else - assert(sizeof sp == write(pipes[1], &sp, sizeof sp)); -} - -static void vca_poll_init(void) { - AZ(pipe(pipes)); + AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL)); } struct acceptor acceptor_poll = { .name = "poll", .init = vca_poll_init, - .recycle = vca_poll_recycle, }; #endif /* defined(HAVE_POLL) */ Modified: branches/1.1/bin/varnishd/cache_backend.c =================================================================== --- branches/1.1/bin/varnishd/cache_backend.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_backend.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -48,10 +48,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "heritage.h" #include "shmlog.h" #include "cache.h" @@ -64,19 +60,7 @@ static MTX vbemtx; /*--------------------------------------------------------------------*/ -/* XXX: belongs a more general place */ -static double -Uptime(void) -{ - struct timespec ts; - - assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); - return (ts.tv_sec + ts.tv_nsec * 1e-9); -} - -/*--------------------------------------------------------------------*/ - struct bereq * vbe_new_bereq(void) { @@ -153,7 +137,7 @@ error = getaddrinfo(bp->hostname, bp->portname == NULL ? "http" : bp->portname, &hint, &res); - bp->dnstime = Uptime(); + bp->dnstime = TIM_mono(); if (error) { if (res != NULL) freeaddrinfo(res); @@ -207,7 +191,7 @@ } } - if (bp->dnstime + bp->dnsttl >= Uptime()) + if (bp->dnstime + bp->dnsttl >= TIM_mono()) return (-1); /* Then do another lookup to catch DNS changes */ Modified: branches/1.1/bin/varnishd/cache_center.c =================================================================== --- branches/1.1/bin/varnishd/cache_center.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_center.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -58,14 +58,11 @@ #include #include +#include #include #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #ifndef HAVE_SRANDOMDEV #include "compat/srandomdev.h" #endif @@ -149,6 +146,7 @@ cnt_deliver(struct sess *sp) { + sp->t_resp = TIM_real(); RES_BuildHttp(sp); VCL_deliver_method(sp); if (sp->handling != VCL_RET_DELIVER) @@ -172,16 +170,6 @@ DOT ] */ -static double -cnt_dt(struct timespec *t1, struct timespec *t2) -{ - double dt; - - dt = (t2->tv_sec - t1->tv_sec); - dt += (t2->tv_nsec - t1->tv_nsec) * 1e-9; - return (dt); -} - static int cnt_done(struct sess *sp) { @@ -197,24 +185,24 @@ sp->vcl = NULL; } - clock_gettime(CLOCK_REALTIME, &sp->t_end); - sp->wrk->idle = sp->t_end.tv_sec; + sp->t_end = TIM_real(); + sp->wrk->used = sp->t_end; if (sp->xid == 0) { sp->t_req = sp->t_end; sp->t_resp = sp->t_end; } - dp = cnt_dt(&sp->t_req, &sp->t_resp); - da = cnt_dt(&sp->t_resp, &sp->t_end); - dh = cnt_dt(&sp->t_open, &sp->t_req); - WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %ld.%09ld %ld.%09ld %.9f %.9f %.9f", - sp->xid, - (long)sp->t_req.tv_sec, (long)sp->t_req.tv_nsec, - (long)sp->t_end.tv_sec, (long)sp->t_end.tv_nsec, - dh, dp, da); + dp = sp->t_resp - sp->t_req; + da = sp->t_end - sp->t_resp; + dh = sp->t_req - sp->t_open; + WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %.9f %.9f %.9f %.9f %.9f", + sp->xid, sp->t_req, sp->t_end, dh, dp, da); sp->xid = 0; - sp->t_open = sp->t_end; SES_Charge(sp); + sp->t_open = sp->t_end; + sp->t_req = NAN; + sp->t_resp = NAN; + sp->t_end = NAN; WSL_Flush(sp->wrk); if (sp->fd >= 0 && sp->doclose != NULL) vca_close_session(sp, sp->doclose); @@ -345,7 +333,7 @@ assert(sp->xid == 0); VCA_Prep(sp); - sp->wrk->idle = sp->t_open.tv_sec; + sp->wrk->used = sp->t_open; sp->wrk->acct.sess++; SES_RefSrcAddr(sp); do @@ -672,8 +660,8 @@ /* Update stats of various sorts */ VSL_stats->client_req++; /* XXX not locked */ - clock_gettime(CLOCK_REALTIME, &sp->t_req); - sp->wrk->idle = sp->t_req.tv_sec; + sp->t_req = TIM_real(); + sp->wrk->used = sp->t_req; sp->wrk->acct.req++; /* Assign XID and log */ Modified: branches/1.1/bin/varnishd/cache_expire.c =================================================================== --- branches/1.1/bin/varnishd/cache_expire.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_expire.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -103,11 +103,11 @@ exp_hangman(void *arg) { struct object *o; - time_t t; + double t; (void)arg; - t = time(NULL); + t = TIM_real(); while (1) { LOCK(&exp_mtx); TAILQ_FOREACH(o, &exp_deathrow, deathrow) { @@ -127,7 +127,7 @@ if (o == NULL) { UNLOCK(&exp_mtx); AZ(sleep(1)); - t = time(NULL); + t = TIM_real(); continue; } TAILQ_REMOVE(&exp_deathrow, o, deathrow); @@ -153,7 +153,7 @@ { struct worker ww; struct object *o; - time_t t; + double t; struct sess *sp; struct object *o2; @@ -168,7 +168,7 @@ sleep(10); /* Takes time for VCL to arrive */ VCL_Get(&sp->vcl); - t = time(NULL); + t = TIM_real(); while (1) { LOCK(&exp_mtx); o = binheap_root(exp_heap); @@ -178,7 +178,7 @@ UNLOCK(&exp_mtx); AZ(sleep(1)); VCL_Refresh(&sp->vcl); - t = time(NULL); + t = TIM_real(); continue; } binheap_delete(exp_heap, o->heap_idx); Modified: branches/1.1/bin/varnishd/cache_fetch.c =================================================================== --- branches/1.1/bin/varnishd/cache_fetch.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_fetch.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -303,7 +303,7 @@ CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); - sp->obj->entered = time(NULL); + sp->obj->entered = TIM_real(); assert(sp->obj->busy != 0); Modified: branches/1.1/bin/varnishd/cache_hash.c =================================================================== --- branches/1.1/bin/varnishd/cache_hash.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_hash.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -152,7 +152,7 @@ /* ignore */ } else if (o->ttl == 0) { /* Object banned but not reaped yet */ - } else if (o->ttl <= sp->t_req.tv_sec) { + } else if (o->ttl <= sp->t_req) { /* Object expired */ } else if (BAN_CheckObject(o, h->hd[HTTP_HDR_URL].b)) { o->ttl = 0; @@ -166,7 +166,7 @@ if (o != NULL) { UNLOCK(&oh->mtx); (void)hash->deref(oh); - LRU_Enter(o, sp->t_req.tv_sec); + LRU_Enter(o, sp->t_req); return (o); } @@ -178,7 +178,7 @@ /* NB: do not deref objhead the new object inherits our reference */ UNLOCK(&oh->mtx); BAN_NewObj(o); - LRU_Enter(o, sp->t_req.tv_sec); + LRU_Enter(o, sp->t_req); return (o); } Modified: branches/1.1/bin/varnishd/cache_http.c =================================================================== --- branches/1.1/bin/varnishd/cache_http.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_http.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -58,7 +58,6 @@ HTTP_T_URL, HTTP_T_Protocol, HTTP_T_Header, - HTTP_T_LostHeader, }; #define LOGMTX2(ax, bx) \ @@ -71,7 +70,6 @@ LOGMTX2(ax, URL), \ LOGMTX2(ax, Protocol), \ LOGMTX2(ax, Header), \ - LOGMTX2(ax, LostHeader) \ } static enum shmlogtag logmtx[3][7] = { @@ -86,7 +84,7 @@ CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); assert(/* hp->logtag >= HTTP_Rx && */hp->logtag <= HTTP_Obj); - assert(/* t >= HTTP_T_Request && */t <= HTTP_T_LostHeader); + assert(/* t >= HTTP_T_Request && */t <= HTTP_T_Header); return (logmtx[hp->logtag][t]); } @@ -97,12 +95,6 @@ WSLR(w, http2shmlog(hp, t), fd, hp->hd[hdr].b, hp->hd[hdr].e); } -void -http_LogLostHeader(struct worker *w, int fd, struct http *hp, const char *hdr) -{ - WSLR(w, http2shmlog(hp, HTTP_T_LostHeader), fd, hdr + 1, hdr + hdr[0]); -} - /*--------------------------------------------------------------------*/ /* List of canonical HTTP response code names from RFC2616 */ @@ -430,7 +422,7 @@ hp->nhd++; } else { VSL_stats->losthdr++; - WSLR(w, http2shmlog(hp, HTTP_T_LostHeader), fd, p, q); + WSLR(w, SLT_LostHeader, fd, p, q); } } return (0); @@ -686,8 +678,8 @@ /*--------------------------------------------------------------------*/ -static void -http_seth(struct http *to, unsigned n, const char *fm) +void +http_SetH(struct http *to, unsigned n, const char *fm) { assert(n < HTTP_HDR_MAX); @@ -709,14 +701,17 @@ } static void -http_getreq(struct http *to, struct http *fm) +http_copyreq(struct http *to, struct http *fm, int forceget) { CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - http_seth(to, HTTP_HDR_REQ, "GET"); + if (forceget) + http_SetH(to, HTTP_HDR_REQ, "GET"); + else + http_copyh(to, fm, HTTP_HDR_REQ); http_copyh(to, fm, HTTP_HDR_URL); - http_seth(to, HTTP_HDR_PROTO, "HTTP/1.1"); + http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1"); } void @@ -726,7 +721,7 @@ CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); if (params->client_http11) - http_seth(to, HTTP_HDR_PROTO, "HTTP/1.1"); + http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1"); else http_copyh(to, fm, HTTP_HDR_PROTO); http_copyh(to, fm, HTTP_HDR_STATUS); @@ -738,9 +733,9 @@ { CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - http_seth(to, HTTP_HDR_PROTO, proto); - http_seth(to, HTTP_HDR_STATUS, status); - http_seth(to, HTTP_HDR_RESPONSE, response); + http_SetH(to, HTTP_HDR_PROTO, proto); + http_SetH(to, HTTP_HDR_STATUS, status); + http_SetH(to, HTTP_HDR_RESPONSE, response); } static void @@ -757,7 +752,7 @@ to->nhd++; } else { VSL_stats->losthdr++; - WSLH(w, HTTP_T_LostHeader, fd, fm, n); + WSLH(w, SLT_LostHeader, fd, fm, n); } } @@ -797,7 +792,7 @@ hp = bereq->http; hp->logtag = HTTP_Tx; - http_getreq(hp, sp->http); + http_copyreq(hp, sp->http, how != HTTPH_R_PIPE); http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how); http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); http_PrintfHeader(sp->wrk, sp->fd, hp, @@ -850,7 +845,7 @@ hp->hd[u].b = p; hp->hd[u].e = p + l; } else { - WSLH(w, HTTP_T_LostHeader, fd, hp, u); + WSLH(w, SLT_LostHeader, fd, hp, u); hp->hd[u].b = NULL; hp->hd[u].e = NULL; } @@ -864,7 +859,7 @@ { CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - /* XXX ??? to->f = to->v; Not sure this is valid */ + /* XXX: don't to->f = to->v; it would kill pipelining */ to->nhd = HTTP_HDR_FIRST; memset(to->hd, 0, sizeof to->hd); } @@ -878,10 +873,10 @@ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); if (to->nhd >= HTTP_HDR_MAX) { VSL_stats->losthdr++; - WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", hdr); + WSL(w, SLT_LostHeader, fd, "%s", hdr); return; } - http_seth(to, to->nhd++, hdr); + http_SetH(to, to->nhd++, hdr); } /*--------------------------------------------------------------------*/ @@ -898,7 +893,7 @@ l = (e - string); p = WS_Alloc(to->ws, l + 1); if (p == NULL) { - WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", string); + WSL(w, SLT_LostHeader, fd, "%s", string); to->hd[field].b = NULL; to->hd[field].e = NULL; } else { @@ -945,7 +940,7 @@ va_end(ap); if (n + 1 >= l || to->nhd >= HTTP_HDR_MAX) { VSL_stats->losthdr++; - WSL(w, http2shmlog(to, HTTP_T_LostHeader), fd, "%s", to->ws->f); + WSL(w, SLT_LostHeader, fd, "%s", to->ws->f); WS_Release(to->ws, 0); } else { to->hd[to->nhd].b = to->ws->f; Modified: branches/1.1/bin/varnishd/cache_lru.c =================================================================== --- branches/1.1/bin/varnishd/cache_lru.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_lru.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -71,7 +71,7 @@ * if it's already in it and hasn't moved in a while. */ void -LRU_Enter(struct object *o, time_t stamp) +LRU_Enter(struct object *o, double stamp) { CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); @@ -199,7 +199,7 @@ * number of objects that were discarded. */ int -LRU_DiscardTime(time_t cutoff) +LRU_DiscardTime(double cutoff) { struct object *first = TAILQ_FIRST(&lru_list); struct object *o; Modified: branches/1.1/bin/varnishd/cache_main.c =================================================================== --- branches/1.1/bin/varnishd/cache_main.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_main.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -71,7 +71,7 @@ stevedore->open(stevedore); printf("Ready\n"); - VSL_stats->start_time = time(NULL); + VSL_stats->start_time = TIM_real(); CLI_Init(); Modified: branches/1.1/bin/varnishd/cache_pipe.c =================================================================== --- branches/1.1/bin/varnishd/cache_pipe.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_pipe.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -38,10 +38,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "shmlog.h" #include "heritage.h" #include "cache.h" @@ -106,7 +102,7 @@ vbe_free_bereq(bereq); bereq = NULL; - clock_gettime(CLOCK_REALTIME, &sp->t_resp); + sp->t_resp = TIM_real(); memset(fds, 0, sizeof fds); fds[0].fd = vc->fd; Modified: branches/1.1/bin/varnishd/cache_pool.c =================================================================== --- branches/1.1/bin/varnishd/cache_pool.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_pool.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -181,6 +182,7 @@ struct workreq *wrq; AN(w->wrq); + w->used = NAN; wrq = w->wrq; CHECK_OBJ_NOTNULL(wrq->sess, SESS_MAGIC); wrq->sess->wrk = w; @@ -193,6 +195,7 @@ CHECK_OBJ(w->nobj, OBJECT_MAGIC); if (w->nobjhead != NULL) CHECK_OBJ(w->nobjhead, OBJHEAD_MAGIC); + assert(!isnan(w->used)); w->wrq = NULL; } @@ -207,7 +210,7 @@ w = &ww; memset(w, 0, sizeof *w); w->magic = WORKER_MAGIC; - w->idle = time(NULL); + w->used = TIM_real(); w->wlp = w->wlog; w->wle = w->wlog + sizeof w->wlog; AZ(pipe(w->pipe)); @@ -236,10 +239,10 @@ LOCK(&qp->mtx); TAILQ_INSERT_HEAD(&qp->idle, w, list); - assert(w->idle != 0); + assert(!isnan(w->used)); UNLOCK(&qp->mtx); assert(1 == read(w->pipe[0], &c, 1)); - if (w->idle == 0) + if (w->wrq == NULL) break; wrk_do_one(w); } @@ -381,7 +384,7 @@ static void * wrk_reaperthread(void *priv) { - time_t now; + double now; struct worker *w; struct wq *qp; unsigned u; @@ -392,13 +395,13 @@ sleep(1); if (VSL_stats->n_wrk <= params->wthread_min) continue; - now = time(NULL); + now = TIM_real(); for (u = 0; u < nwq; u++) { qp = wq[u]; LOCK(&qp->mtx); w = TAILQ_LAST(&qp->idle, workerhead); if (w != NULL && - (w->idle + params->wthread_timeout < now || + (w->used + params->wthread_timeout < now || VSL_stats->n_wrk > params->wthread_max)) TAILQ_REMOVE(&qp->idle, w, list); else @@ -406,7 +409,7 @@ UNLOCK(&qp->mtx); if (w == NULL) continue; - w->idle = 0; + AZ(w->wrq); assert(1 == write(w->pipe[1], w, 1)); } } Modified: branches/1.1/bin/varnishd/cache_response.c =================================================================== --- branches/1.1/bin/varnishd/cache_response.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_response.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -32,10 +32,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "shmlog.h" #include "heritage.h" #include "cache.h" @@ -75,7 +71,7 @@ sp->http->logtag = HTTP_Tx; http_SetResp(sp->http, "HTTP/1.1", "304", "Not Modified"); - TIM_format(sp->t_req.tv_sec, lm); + TIM_format(sp->t_req, lm); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Date: %s", lm); http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish"); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid); @@ -95,12 +91,12 @@ res_do_conds(struct sess *sp) { char *p; - time_t ims; + double ims; if (sp->obj->last_modified > 0 && http_GetHdr(sp->http, H_If_Modified_Since, &p)) { ims = TIM_parse(p); - if (ims > sp->t_req.tv_sec) /* [RFC2616 14.25] */ + if (ims > sp->t_req) /* [RFC2616 14.25] */ return (0); if (sp->obj->last_modified > ims) { return (0); @@ -134,8 +130,8 @@ else http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid); - http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %u", - sp->obj->age + sp->t_resp.tv_sec - sp->obj->entered); + http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %.0f", + sp->obj->age + sp->t_resp - sp->obj->entered); http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish"); if (sp->doclose != NULL) http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); @@ -151,7 +147,6 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - clock_gettime(CLOCK_REALTIME, &sp->t_resp); WRK_Reset(sp->wrk, &sp->fd); sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); Modified: branches/1.1/bin/varnishd/cache_session.c =================================================================== --- branches/1.1/bin/varnishd/cache_session.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_session.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -50,6 +50,7 @@ #include #include +#include #include #include @@ -91,7 +92,8 @@ char addr[TCP_ADDRBUFSIZE]; unsigned nref; - time_t ttl; + /* How long to keep entry around. Inherits timescale from t_open */ + double ttl; struct acct acct; }; @@ -120,7 +122,7 @@ unsigned u, v; struct srcaddr *c, *c2, *c3; struct srcaddrhead *ch; - time_t now; + double now; if (params->srcaddr_ttl == 0) { sp->srcaddr = NULL; @@ -131,7 +133,7 @@ v = u % nsrchash; ch = &srchash[v]; CHECK_OBJ(ch, SRCADDRHEAD_MAGIC); - now = sp->t_open.tv_sec; + now = sp->t_open; if (sp->wrk->srcaddr == NULL) { sp->wrk->srcaddr = calloc(sizeof *sp->wrk->srcaddr, 1); XXXAN(sp->wrk->srcaddr); @@ -227,14 +229,15 @@ ses_sum_acct(&sp->acct, a); if (sp->srcaddr != NULL) { + /* XXX: only report once per second ? */ CHECK_OBJ(sp->srcaddr, SRCADDR_MAGIC); LOCK(&sp->srcaddr->sah->mtx); ses_sum_acct(&sp->srcaddr->acct, a); b = sp->srcaddr->acct; UNLOCK(&sp->srcaddr->sah->mtx); WSL(sp->wrk, SLT_StatAddr, 0, - "%s 0 %d %ju %ju %ju %ju %ju %ju %ju", - sp->srcaddr->addr, sp->t_end.tv_sec - b.first, + "%s 0 %.0f %ju %ju %ju %ju %ju %ju %ju", + sp->srcaddr->addr, sp->t_end - b.first, b.sess, b.req, b.pipe, b.pass, b.fetch, b.hdrbytes, b.bodybytes); } @@ -307,6 +310,10 @@ sp->mysockaddr = (void*)(&sm->sockaddr[1]); sp->mysockaddrlen = sizeof(sm->sockaddr[1]); sp->sockaddr->sa_family = sp->mysockaddr->sa_family = PF_UNSPEC; + sp->t_open = NAN; + sp->t_req = NAN; + sp->t_resp = NAN; + sp->t_end = NAN; assert(len <= sp->sockaddrlen); if (addr != NULL) { @@ -333,8 +340,8 @@ AZ(sp->vcl); VSL_stats->n_sess--; ses_relsrcaddr(sp); - VSL(SLT_StatSess, sp->id, "%s %s %d %ju %ju %ju %ju %ju %ju %ju", - sp->addr, sp->port, sp->t_end.tv_sec - b->first, + VSL(SLT_StatSess, sp->id, "%s %s %.0f %ju %ju %ju %ju %ju %ju %ju", + sp->addr, sp->port, sp->t_end - b->first, b->sess, b->req, b->pipe, b->pass, b->fetch, b->hdrbytes, b->bodybytes); if (sm->workspace != params->mem_workspace) { Modified: branches/1.1/bin/varnishd/cache_synthetic.c =================================================================== --- branches/1.1/bin/varnishd/cache_synthetic.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_synthetic.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -33,10 +33,6 @@ #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "shmlog.h" #include "heritage.h" #include "cache.h" @@ -56,7 +52,7 @@ struct vsb vsb; const char *msg; char date[40]; - time_t now; + double now; int fd; assert(status >= 100 && status <= 999); @@ -71,7 +67,7 @@ fd = sp->fd; o = sp->obj; h = &o->http; - time(&now); + now = TIM_real(); /* look up HTTP response */ msg = http_StatusMessage(status); Modified: branches/1.1/bin/varnishd/cache_vrt.c =================================================================== --- branches/1.1/bin/varnishd/cache_vrt.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_vrt.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -32,7 +32,10 @@ */ #include +#include +#include + #include #include #include @@ -112,45 +115,60 @@ /*--------------------------------------------------------------------*/ +static char * +vrt_assemble_string(struct http *hp, const char *h, const char *p, va_list ap) +{ + char *b, *e; + unsigned u, x; + + u = WS_Reserve(hp->ws, 0); + e = b = hp->ws->f; + *e = '\0'; + if (h != NULL) { + x = strlen(h); + if (x + 2 < u) { + memcpy(e, h, x); + e[x] = ' '; + e[x + 1] = '\0'; + } + e += x + 1; + } + while (p != NULL) { + x = strlen(p); + if (x + 1 < u) + memcpy(e, p, x); + e += x; + p = va_arg(ap, const char *); + } + *e = '\0'; + if (e > b + u) { + WS_Release(hp->ws, 0); + return (NULL); + } else { + WS_Release(hp->ws, 1 + e - b); + return (b); + } +} + +/*--------------------------------------------------------------------*/ + void -VRT_SetHdr(struct sess *sp , enum gethdr_e where, const char *hdr, ...) +VRT_SetHdr(struct sess *sp , enum gethdr_e where, const char *hdr, const char *p, ...) { struct http *hp; va_list ap; - const char *p; - char *b, *e; - unsigned u, x; + char *b; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); hp = vrt_selecthttp(sp, where); - va_start(ap, hdr); - p = va_arg(ap, const char *); + va_start(ap, p); if (p == NULL) { http_Unset(hp, hdr); } else { - u = WS_Reserve(hp->ws, 0); - e = b = hp->ws->f; - *e = '\0'; - x = strlen(hdr + 1); - if (x + 1 < u) - memcpy(e, hdr + 1, x); - e += x; - if (1 + 1 < u) - *e++ = ' '; - while (p != NULL) { - x = strlen(p); - if (x + 1 < u) - memcpy(e, p, x); - e += x; - p = va_arg(ap, const char *); - } - *e = '\0'; - if (e > b + u) { - http_LogLostHeader(sp->wrk, sp->fd, hp, hdr); - WS_Release(hp->ws, 0); - + b = vrt_assemble_string(hp, hdr + 1, p, ap); + if (b == NULL) { + VSL(SLT_LostHeader, sp->fd, hdr + 1); } else { - WS_Release(hp->ws, 1 + e - b); http_Unset(hp, hdr); http_SetHeader(sp->wrk, sp->fd, hp, b); } @@ -160,7 +178,77 @@ /*--------------------------------------------------------------------*/ +static void +vrt_do_string(struct worker *w, int fd, struct http *hp, int fld, const char *err, const char *p, va_list ap) +{ + char *b; + + AN(p); + AN(hp); + b = vrt_assemble_string(hp, NULL, p, ap); + if (b == NULL) { + WSL(w, SLT_LostHeader, fd, err); + } else { + http_SetH(hp, fld, b); + } + va_end(ap); +} + +#define VRT_DO_HDR(obj, hdr, http, fld) \ +void \ +VRT_l_##obj##_##hdr(struct sess *sp, const char *p, ...) \ +{ \ + va_list ap; \ + \ + AN(p); \ + va_start(ap, p); \ + vrt_do_string(sp->wrk, sp->fd, \ + http, fld, #obj "." #hdr, p, ap); \ + va_end(ap); \ +} + +VRT_DO_HDR(req, request, sp->http, HTTP_HDR_REQ) +VRT_DO_HDR(req, url, sp->http, HTTP_HDR_URL) +VRT_DO_HDR(req, proto, sp->http, HTTP_HDR_PROTO) +VRT_DO_HDR(bereq, request, sp->bereq->http, HTTP_HDR_REQ) +VRT_DO_HDR(bereq, url, sp->bereq->http, HTTP_HDR_URL) +VRT_DO_HDR(bereq, proto, sp->bereq->http, HTTP_HDR_PROTO) +VRT_DO_HDR(obj, proto, &sp->obj->http, HTTP_HDR_PROTO) +VRT_DO_HDR(obj, response, &sp->obj->http, HTTP_HDR_RESPONSE) +VRT_DO_HDR(resp, proto, sp->http, HTTP_HDR_PROTO) +VRT_DO_HDR(resp, response, sp->http, HTTP_HDR_RESPONSE) + void +VRT_l_obj_status(struct sess *sp, int num) +{ + char *p; + + assert(num >= 100 && num <= 999); + p = WS_Alloc(sp->obj->http.ws, 4); + if (p == NULL) + WSL(sp->wrk, SLT_LostHeader, sp->fd, "obj.status"); + else + sprintf(p, "%d", num); + http_SetH(&sp->obj->http, HTTP_HDR_STATUS, p); +} + +void +VRT_l_resp_status(struct sess *sp, int num) +{ + char *p; + + assert(num >= 100 && num <= 999); + p = WS_Alloc(sp->http->ws, 4); + if (p == NULL) + WSL(sp->wrk, SLT_LostHeader, sp->fd, "resp.status"); + else + sprintf(p, "%d", num); + http_SetH(sp->http, HTTP_HDR_STATUS, p); +} + +/*--------------------------------------------------------------------*/ + +void VRT_handling(struct sess *sp, unsigned hand) { @@ -239,11 +327,11 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ - WSL(sp->wrk, SLT_TTL, sp->fd, "%u VCL %.0f %u", - sp->obj->xid, a, sp->t_req.tv_sec); + WSL(sp->wrk, SLT_TTL, sp->fd, "%u VCL %.0f %.0f", + sp->obj->xid, a, sp->t_req); if (a < 0) a = 0; - sp->obj->ttl = sp->t_req.tv_sec + (int)a; + sp->obj->ttl = sp->t_req + a; if (sp->obj->heap_idx != 0) EXP_TTLchange(sp->obj); } @@ -253,7 +341,7 @@ { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ - return (sp->obj->ttl - sp->t_req.tv_sec); + return (sp->obj->ttl - sp->t_req); } /*--------------------------------------------------------------------*/ @@ -375,22 +463,43 @@ double VRT_r_now(struct sess *sp) { - struct timespec now; (void)sp; - /* XXX use of clock_gettime() needs review */ - clock_gettime(CLOCK_MONOTONIC, &now); - return (now.tv_sec); + return (TIM_mono()); } double VRT_r_obj_lastuse(struct sess *sp) { - struct timespec now; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ - /* XXX use of clock_gettime() needs review */ - clock_gettime(CLOCK_MONOTONIC, &now); - return (now.tv_sec - sp->obj->lru_stamp); + return (TIM_mono() - sp->obj->lru_stamp); } + +/*--------------------------------------------------------------------*/ + +char * +VRT_IP_string(struct sess *sp, struct sockaddr *sa) +{ + char h[64], p[8], *q; + socklen_t len = 0; + + /* XXX can't rely on sockaddr.sa_len */ + switch (sa->sa_family) { + case AF_INET: + len = sizeof(struct sockaddr_in); + break; + case AF_INET6: + len = sizeof(struct sockaddr_in6); + break; + } + XXXAN(len); + TCP_name(sa, len, h, sizeof h, p, sizeof p); + q = WS_Alloc(sp->http->ws, strlen(h) + strlen(p) + 2); + AN(q); + strcpy(q, h); + strcat(q, ":"); + strcat(q, p); + return (q); +} Modified: branches/1.1/bin/varnishd/cache_vrt_re.c =================================================================== --- branches/1.1/bin/varnishd/cache_vrt_re.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/cache_vrt_re.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -45,14 +46,14 @@ #include "cache.h" void -VRT_re_init(void **rep, const char *re) +VRT_re_init(void **rep, const char *re, int sub) { regex_t *t; t = calloc(sizeof *t, 1); XXXAN(t); /* This was already check-compiled by the VCL compiler */ - AZ(regcomp(t, re, REG_EXTENDED | REG_NOSUB)); + AZ(regcomp(t, re, REG_EXTENDED | (sub ? 0 : REG_NOSUB))); *rep = t; } @@ -82,14 +83,14 @@ } int -VRT_re_test(struct vsb *sb, const char *re) +VRT_re_test(struct vsb *sb, const char *re, int sub) { int i; regex_t t; char buf[BUFSIZ]; memset(&t, 0, sizeof t); - i = regcomp(&t, re, REG_EXTENDED | REG_NOSUB); + i = regcomp(&t, re, REG_EXTENDED | (sub ? 0 : REG_NOSUB)); if (i == 0) { regfree(&t); return (0); @@ -99,3 +100,73 @@ regfree(&t); return (1); } + +const char * +VRT_regsub(struct sess *sp, const char *str, void *re, const char *sub) +{ + regmatch_t pm[10]; + regex_t *t; + int i, l; + char *b, *p, *e; + unsigned u, x; + + AN(re); + t = re; + i = regexec(t, str, 10, pm, 0); + + /* If it didn't match, we can return the original string */ + if (i == REG_NOMATCH) + return(str); + + u = WS_Reserve(sp->http->ws, 0); + e = p = b = sp->http->ws->f; + e += u; + + /* Copy prefix to match */ + if (pm[0].rm_so > 0) { + if (p + pm[0].rm_so < e) + memcpy(p, str, pm[0].rm_so); + p += pm[0].rm_so; + } + + for ( ; *sub != '\0'; sub++ ) { + if (*sub == '&') { + l = pm[0].rm_eo - pm[0].rm_so; + if (l > 0) { + if (p + l < e) + memcpy(p, str + pm[0].rm_so, l); + p += l; + } + } else if (*sub == '$' && isdigit(sub[1])) { + x = sub[1] - '0'; + sub++; + l = pm[x].rm_eo - pm[x].rm_so; + if (l > 0) { + if (p + l < e) + memcpy(p, str + pm[x].rm_so, l); + p += l; + } + } else { + if (p + 1 < e) + *p = *sub; + p++; + } + } + + /* Copy suffix to match */ + l = strlen(str + pm[0].rm_eo); + if (l > 0) { + if (p + l < e) + memcpy(p, str + pm[0].rm_eo, l); + p += l; + } + if (p + 1 < e) + *p++ = '\0'; + xxxassert(p <= e); + if (p > e) { + WS_Release(sp->http->ws, 0); + return (str); + } + WS_Release(sp->http->ws, p - b); + return (b); +} Modified: branches/1.1/bin/varnishd/mgt_child.c =================================================================== --- branches/1.1/bin/varnishd/mgt_child.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/mgt_child.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -445,3 +445,13 @@ cli_out(cli, "Child in state %s", ch_state[child_state]); } } + +/*--------------------------------------------------------------------*/ + +void +mcf_server_status(struct cli *cli, char **av, void *priv) +{ + (void)av; + (void)priv; + cli_out(cli, "Child in state %s", ch_state[child_state]); +} Modified: branches/1.1/bin/varnishd/mgt_cli.c =================================================================== --- branches/1.1/bin/varnishd/mgt_cli.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/mgt_cli.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -140,6 +140,7 @@ /* XXX: what order should this list be in ? */ static struct cli_proto mgt_cli_proto[] = { { CLI_PING, cli_func_ping }, + { CLI_SERVER_STATUS, mcf_server_status, NULL }, { CLI_SERVER_START, mcf_server_startstop, NULL }, { CLI_SERVER_STOP, mcf_server_startstop, &cli_proto }, { CLI_STATS, mcf_stats, NULL }, Modified: branches/1.1/bin/varnishd/mgt_cli.h =================================================================== --- branches/1.1/bin/varnishd/mgt_cli.h 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/mgt_cli.h 2007-07-13 14:54:51 UTC (rev 1693) @@ -31,6 +31,7 @@ /* mgt_child.c */ cli_func_t mcf_server_startstop; +cli_func_t mcf_server_status; /* mgt_param.c */ cli_func_t mcf_param_show; Modified: branches/1.1/bin/varnishd/mgt_event.c =================================================================== --- branches/1.1/bin/varnishd/mgt_event.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/mgt_event.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -37,10 +37,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "mgt.h" #include "mgt_event.h" #include "miniobj.h" @@ -76,19 +72,6 @@ /*--------------------------------------------------------------------*/ -static double -ev_now(void) -{ - double t; - struct timespec ts; - - assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); - t = ts.tv_sec + ts.tv_nsec * 1e-9; - return (t); -} - -/*--------------------------------------------------------------------*/ - static void ev_bh_update(void *priv, void *a, unsigned u) { @@ -265,7 +248,7 @@ e->magic = EV_MAGIC; /* before binheap_insert() */ if (e->timeout != 0.0) { - e->__when += ev_now() + e->timeout; + e->__when += TIM_mono() + e->timeout; binheap_insert(evb->binheap, e); assert(e->__binheap_idx > 0); } else { @@ -430,7 +413,7 @@ if (e != NULL) { CHECK_OBJ_NOTNULL(e, EV_MAGIC); assert(e->__binheap_idx == 1); - t = ev_now(); + t = TIM_mono(); if (e->__when <= t) return (ev_sched_timeout(evb, e, t)); tmo = (int)((e->__when - t) * 1e3); @@ -453,7 +436,7 @@ return (ev_sched_signal(evb)); if (i == 0) { assert(e != NULL); - t = ev_now(); + t = TIM_mono(); if (e->__when <= t) return (ev_sched_timeout(evb, e, t)); } Modified: branches/1.1/bin/varnishd/rfc2616.c =================================================================== --- branches/1.1/bin/varnishd/rfc2616.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/rfc2616.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -98,12 +98,12 @@ ttd = min(ttd, our_clock + hard_upper_ttl) #endif -static time_t +static double RFC2616_Ttl(struct sess *sp, struct http *hp, struct object *obj) { int retirement_age; unsigned u1, u2; - time_t h_date, h_expires, ttd; + double h_date, h_expires, ttd; char *p; retirement_age = INT_MAX; @@ -121,6 +121,14 @@ retirement_age = u1 - u2; } + /* + * XXX: if the backends time is too skewed relative to our own + * XXX: we should blacklist the backend, to avoid getting totally + * XXX: bogus results further down. Exactly what "too skewed" means + * XXX: in this context is a good question. It could be determined + * XXX: out according to the backends headers, but a simple fixed + * XXX: tolerance of a minute either way would be more predictable. + */ h_date = 0; if (http_GetHdr(hp, H_Date, &p)) h_date = TIM_parse(p); Modified: branches/1.1/bin/varnishd/shmlog.c =================================================================== --- branches/1.1/bin/varnishd/shmlog.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/shmlog.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -289,7 +289,7 @@ /* XXX more check sanity of loghead ? */ logstart = (unsigned char *)loghead + loghead->start; MTX_INIT(&vsl_mtx); - loghead->starttime = time(NULL); + loghead->starttime = TIM_real(); memset(VSL_stats, 0, sizeof *VSL_stats); } Modified: branches/1.1/bin/varnishd/varnishd.1 =================================================================== --- branches/1.1/bin/varnishd/varnishd.1 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/bin/varnishd/varnishd.1 2007-07-13 14:54:51 UTC (rev 1693) @@ -316,6 +316,8 @@ better idea of the current situation, use the .Xr varnishstat 1 utility. +.It Cm status +Check the status of the child process. .It Cm stop Stop the child process. .It Cm url.purge Ar regexp Modified: branches/1.1/doc/changes-1.0.4-1.1.xml =================================================================== --- branches/1.1/doc/changes-1.0.4-1.1.xml 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/doc/changes-1.0.4-1.1.xml 2007-07-13 14:54:51 UTC (rev 1693) @@ -155,6 +155,29 @@ corresponding variable, and strip an HTTP header by using the remove keyword. + + + VCL scripts can now modify the HTTP status code of cached + objects (obj.status) and responses + (resp.status) + + + + Numeric and other non-textual variables in VCL can now be + assigned to textual variables; they will be converted as + needed. + + + + VCL scripts can now apply regular expression substitutions + to textual variables using the regsub + function. + + + + A new management command, status, + returns the state of the child. + @@ -189,6 +212,12 @@ varnishncsa can now also process log data from backend traffic. + + + A bug that would cause varnishncsa to + segfault when it encountered an empty HTTP header in the log + file has been fixed. + Modified: branches/1.1/include/cli.h =================================================================== --- branches/1.1/include/cli.h 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/include/cli.h 2007-07-13 14:54:51 UTC (rev 1693) @@ -211,6 +211,12 @@ "\tClose connection", \ 0, 0 +# define CLI_SERVER_STATUS \ + "status", \ + "status", \ + "\tCheck status of Varnish cache process.", \ + 0, 0 + /* * Status/return codes in the CLI protocol */ Modified: branches/1.1/include/libvarnish.h =================================================================== --- branches/1.1/include/libvarnish.h 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/include/libvarnish.h 2007-07-13 14:54:51 UTC (rev 1693) @@ -47,6 +47,8 @@ /* from libvarnish/time.c */ void TIM_format(time_t t, char *p); time_t TIM_parse(const char *p); +double TIM_mono(void); +double TIM_real(void); /* from libvarnish/version.c */ void varnish_version(const char *); Modified: branches/1.1/include/shmlog_tags.h =================================================================== --- branches/1.1/include/shmlog_tags.h 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/include/shmlog_tags.h 2007-07-13 14:54:51 UTC (rev 1693) @@ -62,7 +62,6 @@ SLTM(RxURL) SLTM(RxProtocol) SLTM(RxHeader) -SLTM(RxLostHeader) SLTM(TxRequest) SLTM(TxResponse) @@ -70,7 +69,6 @@ SLTM(TxURL) SLTM(TxProtocol) SLTM(TxHeader) -SLTM(TxLostHeader) SLTM(ObjRequest) SLTM(ObjResponse) @@ -78,8 +76,9 @@ SLTM(ObjURL) SLTM(ObjProtocol) SLTM(ObjHeader) -SLTM(ObjLostHeader) +SLTM(LostHeader) + SLTM(TTL) SLTM(VCL_acl) SLTM(VCL_call) Modified: branches/1.1/include/vrt.h =================================================================== --- branches/1.1/include/vrt.h 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/include/vrt.h 2007-07-13 14:54:51 UTC (rev 1693) @@ -64,10 +64,11 @@ void VRT_acl_fini(struct vrt_acl *); /* Regexp related */ -void VRT_re_init(void **, const char *); +void VRT_re_init(void **, const char *, int sub); void VRT_re_fini(void *); int VRT_re_match(const char *, void *re); -int VRT_re_test(struct vsb *, const char *); +int VRT_re_test(struct vsb *, const char *, int sub); +const char *VRT_regsub(struct sess *sp, const char *, void *, const char *); void VRT_count(struct sess *, unsigned); int VRT_rewrite(const char *, const char *); @@ -76,7 +77,7 @@ enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ }; char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *); -void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, ...); +void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, const char *, ...); void VRT_handling(struct sess *sp, unsigned hand); /* Backend related */ @@ -85,6 +86,7 @@ void VRT_free_backends(struct VCL_conf *cp); void VRT_fini_backend(struct backend *be); +char *VRT_IP_string(struct sess *sp, struct sockaddr *sa); #define VRT_done(sp, hand) \ do { \ Modified: branches/1.1/include/vrt_obj.h =================================================================== --- branches/1.1/include/vrt_obj.h 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/include/vrt_obj.h 2007-07-13 14:54:51 UTC (rev 1693) @@ -12,23 +12,26 @@ struct sockaddr * VRT_r_client_ip(struct sess *); struct sockaddr * VRT_r_server_ip(struct sess *); const char * VRT_r_req_request(struct sess *); +void VRT_l_req_request(struct sess *, const char *, ...); const char * VRT_r_req_url(struct sess *); +void VRT_l_req_url(struct sess *, const char *, ...); const char * VRT_r_req_proto(struct sess *); +void VRT_l_req_proto(struct sess *, const char *, ...); void VRT_l_req_hash(struct sess *, const char *); struct backend * VRT_r_req_backend(struct sess *); void VRT_l_req_backend(struct sess *, struct backend *); const char * VRT_r_bereq_request(struct sess *); -void VRT_l_bereq_request(struct sess *, const char *); +void VRT_l_bereq_request(struct sess *, const char *, ...); const char * VRT_r_bereq_url(struct sess *); -void VRT_l_bereq_url(struct sess *, const char *); +void VRT_l_bereq_url(struct sess *, const char *, ...); const char * VRT_r_bereq_proto(struct sess *); -void VRT_l_bereq_proto(struct sess *, const char *); +void VRT_l_bereq_proto(struct sess *, const char *, ...); const char * VRT_r_obj_proto(struct sess *); -void VRT_l_obj_proto(struct sess *, const char *); +void VRT_l_obj_proto(struct sess *, const char *, ...); int VRT_r_obj_status(struct sess *); void VRT_l_obj_status(struct sess *, int); const char * VRT_r_obj_response(struct sess *); -void VRT_l_obj_response(struct sess *, const char *); +void VRT_l_obj_response(struct sess *, const char *, ...); unsigned VRT_r_obj_valid(struct sess *); void VRT_l_obj_valid(struct sess *, unsigned); unsigned VRT_r_obj_cacheable(struct sess *); @@ -37,9 +40,9 @@ void VRT_l_obj_ttl(struct sess *, double); double VRT_r_obj_lastuse(struct sess *); const char * VRT_r_resp_proto(struct sess *); -void VRT_l_resp_proto(struct sess *, const char *); +void VRT_l_resp_proto(struct sess *, const char *, ...); int VRT_r_resp_status(struct sess *); void VRT_l_resp_status(struct sess *, int); const char * VRT_r_resp_response(struct sess *); -void VRT_l_resp_response(struct sess *, const char *); +void VRT_l_resp_response(struct sess *, const char *, ...); double VRT_r_now(struct sess *); Modified: branches/1.1/lib/libvarnish/Makefile.am =================================================================== --- branches/1.1/lib/libvarnish/Makefile.am 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvarnish/Makefile.am 2007-07-13 14:54:51 UTC (rev 1693) @@ -19,3 +19,5 @@ vss.c libvarnish_la_CFLAGS = -include config.h + +libvarnish_la_LIBADD = ${RT_LIBS} Modified: branches/1.1/lib/libvarnish/time.c =================================================================== --- branches/1.1/lib/libvarnish/time.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvarnish/time.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -50,8 +50,30 @@ #include #include +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + #include "libvarnish.h" +double +TIM_mono(void) +{ + struct timespec ts; + + assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); + return (ts.tv_sec + 1e-9 * ts.tv_nsec); +} + +double +TIM_real(void) +{ + struct timespec ts; + + assert(clock_gettime(CLOCK_REALTIME, &ts) == 0); + return (ts.tv_sec + 1e-9 * ts.tv_nsec); +} + void TIM_format(time_t t, char *p) { Modified: branches/1.1/lib/libvcl/Makefile.am =================================================================== --- branches/1.1/lib/libvcl/Makefile.am 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/Makefile.am 2007-07-13 14:54:51 UTC (rev 1693) @@ -16,6 +16,7 @@ vcc_parse.c \ vcc_fixed_token.c \ vcc_obj.c \ + vcc_string.c \ vcc_token.c \ vcc_var.c \ vcc_xref.c Modified: branches/1.1/lib/libvcl/syntax.txt =================================================================== --- branches/1.1/lib/libvcl/syntax.txt 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/syntax.txt 2007-07-13 14:54:51 UTC (rev 1693) @@ -128,6 +128,7 @@ 'call' ident ';' 'rewrite' cstr cstr ';' 'set' assignment ';' + 'remove' variable ';' # see variable 'returns' in vcc_gen_fixed_token.tcl return_action: @@ -162,6 +163,7 @@ '-=' cnum '=' cnum + ratio: '*=' double '/=' double Modified: branches/1.1/lib/libvcl/vcc_acl.c =================================================================== --- branches/1.1/lib/libvcl/vcc_acl.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/vcc_acl.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -30,13 +30,13 @@ */ #include -#include #include #include "vsb.h" #include "vcc_priv.h" #include "vcc_compile.h" +#include "libvarnish.h" static void vcc_acl_top(struct tokenlist *tl, const char *acln) @@ -108,7 +108,7 @@ } void -vcc_Cond_Ip(struct var *vp, struct tokenlist *tl) +vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl) { unsigned tcond; char *acln; Modified: branches/1.1/lib/libvcl/vcc_action.c =================================================================== --- branches/1.1/lib/libvcl/vcc_action.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/vcc_action.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -94,7 +94,7 @@ /*--------------------------------------------------------------------*/ static void -illegal_assignment(struct tokenlist *tl, const char *type) +illegal_assignment(const struct tokenlist *tl, const char *type) { vsb_printf(tl->sb, "Invalid assignment operator "); @@ -104,7 +104,7 @@ } static void -check_writebit(struct tokenlist *tl, struct var *vp) +check_writebit(struct tokenlist *tl, const struct var *vp) { if (vp->access == V_RW || vp->access == V_WO) @@ -155,6 +155,8 @@ vcc_RateVal(tl); else if (vp->fmt == FLOAT) Fb(tl, 0, "%g", vcc_DoubleVal(tl)); + else if (vp->fmt == INT) + Fb(tl, 0, "%u", vcc_UintVal(tl)); else { vsb_printf(tl->sb, "Cannot assign this variable type.\n"); vcc_ErrWhere(tl, vt); @@ -195,28 +197,38 @@ vcc_NextToken(tl); Fb(tl, 0, ");\n"); break; - return; case HASH: ExpectErr(tl, T_INCR); vcc_NextToken(tl); - vcc_StringVal(tl); + if (!vcc_StringVal(tl)) { + ERRCHK(tl); + vcc_ExpectedStringval(tl); + return; + } Fb(tl, 0, ");\n"); - return; + break; case STRING: if (tl->t->tok != '=') { illegal_assignment(tl, "strings"); return; } vcc_NextToken(tl); - vcc_StringVal(tl); - if (vp->ishdr) { - while (tl->t->tok != ';') { - Fb(tl, 0, ", "); - vcc_StringVal(tl); - } - Fb(tl, 0, ", 0"); + if (!vcc_StringVal(tl)) { + ERRCHK(tl); + vcc_ExpectedStringval(tl); + return; } - Fb(tl, 0, ");\n"); + do + Fb(tl, 0, ", "); + while (vcc_StringVal(tl)); + if (tl->t->tok != ';') { + ERRCHK(tl); + vsb_printf(tl->sb, + "Expected variable, string or semicolon\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + Fb(tl, 0, "0);\n"); break; default: vsb_printf(tl->sb, @@ -232,13 +244,13 @@ parse_remove(struct tokenlist *tl) { struct var *vp; - struct token *vt; vcc_NextToken(tl); ExpectErr(tl, VAR); - vt = tl->t; vp = vcc_FindVar(tl, tl->t, vcc_vars); - if (vp->fmt != STRING || !vp->ishdr) { + ERRCHK(tl); + assert(vp != NULL); + if (vp->fmt != STRING || vp->hdr == NULL) { vsb_printf(tl->sb, "Only http header lines can be removed.\n"); vcc_ErrWhere(tl, tl->t); return; Modified: branches/1.1/lib/libvcl/vcc_compile.c =================================================================== --- branches/1.1/lib/libvcl/vcc_compile.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/vcc_compile.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -86,7 +86,7 @@ #include "vcl_returns.h" #undef VCL_MET_MAC #undef VCL_RET_MAC - { NULL, 0U } + { NULL, 0U, 0} }; /*--------------------------------------------------------------------*/ Modified: branches/1.1/lib/libvcl/vcc_compile.h =================================================================== --- branches/1.1/lib/libvcl/vcc_compile.h 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/vcc_compile.h 2007-07-13 14:54:51 UTC (rev 1693) @@ -121,7 +121,7 @@ const char *rname; const char *lname; enum {V_RO, V_RW, V_WO} access; - char ishdr; + const char *hdr; unsigned methods; }; @@ -136,7 +136,7 @@ /* vcc_acl.c */ void vcc_Acl(struct tokenlist *tl); -void vcc_Cond_Ip(struct var *vp, struct tokenlist *tl); +void vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl); /* vcc_action.c */ void vcc_ParseAction(struct tokenlist *tl); @@ -167,6 +167,11 @@ unsigned vcc_UintVal(struct tokenlist *tl); double vcc_DoubleVal(struct tokenlist *tl); +/* vcc_string.c */ +char *vcc_regexp(struct tokenlist *tl, int sub); +int vcc_StringVal(struct tokenlist *tl); +void vcc_ExpectedStringval(struct tokenlist *tl); + /* vcc_token.c */ void vcc_ErrToken(const struct tokenlist *tl, const struct token *t); void vcc_ErrWhere(struct tokenlist *tl, const struct token *t); @@ -180,7 +185,6 @@ void vcc_FreeToken(struct token *t); /* vcc_var.c */ -void vcc_StringVal(struct tokenlist *tl); struct var *vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl); /* vcc_xref.c */ Modified: branches/1.1/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/1.1/lib/libvcl/vcc_fixed_token.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/vcc_fixed_token.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -420,10 +420,11 @@ vsb_cat(sb, "void VRT_acl_fini(struct vrt_acl *);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/* Regexp related */\n"); - vsb_cat(sb, "void VRT_re_init(void **, const char *);\n"); + vsb_cat(sb, "void VRT_re_init(void **, const char *, int sub);\n"); vsb_cat(sb, "void VRT_re_fini(void *);\n"); vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n"); - vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *);\n"); + vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); + vsb_cat(sb, "const char *VRT_regsub(struct sess *sp, const char *, void *, const char *);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "void VRT_count(struct sess *, unsigned);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); @@ -432,7 +433,7 @@ vsb_cat(sb, "\n"); vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ };\n"); vsb_cat(sb, "char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);\n"); - vsb_cat(sb, "void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, ...);\n"); + vsb_cat(sb, "void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, const char *, ...);\n"); vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/* Backend related */\n"); @@ -441,6 +442,7 @@ vsb_cat(sb, "void VRT_free_backends(struct VCL_conf *cp);\n"); vsb_cat(sb, "void VRT_fini_backend(struct backend *be);\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "char *VRT_IP_string(struct sess *sp, struct sockaddr *sa);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "#define VRT_done(sp, hand) \\\n"); vsb_cat(sb, " do { \\\n"); @@ -461,23 +463,26 @@ vsb_cat(sb, "struct sockaddr * VRT_r_client_ip(struct sess *);\n"); vsb_cat(sb, "struct sockaddr * VRT_r_server_ip(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_req_request(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_req_request(struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_req_url(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_req_url(struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_req_proto(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_req_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n"); vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n"); vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n"); vsb_cat(sb, "const char * VRT_r_bereq_request(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_bereq_request(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_bereq_request(struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_bereq_url(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_bereq_url(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_bereq_url(struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_bereq_proto(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_bereq_proto(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_bereq_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_obj_proto(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_proto(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_obj_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "int VRT_r_obj_status(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_status(struct sess *, int);\n"); vsb_cat(sb, "const char * VRT_r_obj_response(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_response(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_obj_response(struct sess *, const char *, ...);\n"); vsb_cat(sb, "unsigned VRT_r_obj_valid(struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_valid(struct sess *, unsigned);\n"); vsb_cat(sb, "unsigned VRT_r_obj_cacheable(struct sess *);\n"); @@ -486,10 +491,10 @@ vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n"); vsb_cat(sb, "double VRT_r_obj_lastuse(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *, ...);\n"); vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n"); vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n"); vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *);\n"); + vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *, ...);\n"); vsb_cat(sb, "double VRT_r_now(struct sess *);\n"); } Modified: branches/1.1/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- branches/1.1/lib/libvcl/vcc_gen_obj.tcl 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/vcc_gen_obj.tcl 2007-07-13 14:54:51 UTC (rev 1693) @@ -32,9 +32,9 @@ # Objects available in backends set beobj { - { backend.host WO HOSTNAME } - { backend.port WO PORTNAME } - { backend.dnsttl WO TIME } + { backend.host WO HOSTNAME {} } + { backend.port WO PORTNAME {} } + { backend.dnsttl WO TIME {} } } # Variables available in sessions @@ -56,20 +56,21 @@ # Request paramters { req.request - RO STRING + RW STRING {recv pipe pass hash miss hit fetch } } { req.url - RO STRING + RW STRING {recv pipe pass hash miss hit fetch } } { req.proto - RO STRING + RW STRING {recv pipe pass hash miss hit fetch } } { req.http. RW HEADER {recv pipe pass hash miss hit fetch } + HDR_REQ } # Possibly misnamed, not really part of the request @@ -98,6 +99,7 @@ { bereq.http. RW HEADER { pipe pass miss } + HDR_BEREQ } # The (possibly) cached object @@ -116,6 +118,7 @@ { obj.http. RW HEADER { hit fetch } + HDR_OBJ } { obj.valid @@ -151,6 +154,7 @@ { resp.http. RW HEADER { deliver } + HDR_RESP } # Miscellaneous @@ -200,6 +204,9 @@ append l " | " append l VCL_MET_[string toupper $i] } + if {$l == ""} { + return "0" + } return [string range $l 3 end] } @@ -224,14 +231,21 @@ } if {$a == "WO" || $a == "RW"} { puts $fo "\t \"VRT_l_${m}($pa, \"," - if {$t != "HEADER"} { + if {$t == "HEADER"} { + } elseif {$t == "STRING"} { + puts $fp "void VRT_l_${m}($ty, $tt($t), ...);" + } else { puts $fp "void VRT_l_${m}($ty, $tt($t));" } } else { puts $fo "\t NULL," } puts $fo "\t V_$a," - puts $fo "\t 0," + if {$t != "HEADER"} { + puts $fo "\t 0," + } else { + puts $fo "\t \"[lindex $v 4]\"," + } puts $fo "\t [method_map [lindex $v 3]]" puts $fo "\t\}," Modified: branches/1.1/lib/libvcl/vcc_obj.c =================================================================== --- branches/1.1/lib/libvcl/vcc_obj.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/vcc_obj.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -15,21 +15,21 @@ "VRT_l_backend_host(backend, ", V_WO, 0, - + 0 }, { "backend.port", PORTNAME, 12, NULL, "VRT_l_backend_port(backend, ", V_WO, 0, - + 0 }, { "backend.dnsttl", TIME, 14, NULL, "VRT_l_backend_dnsttl(backend, ", V_WO, 0, - + 0 }, { NULL } }; @@ -51,22 +51,22 @@ }, { "req.request", STRING, 11, "VRT_r_req_request(sp)", - NULL, - V_RO, + "VRT_l_req_request(sp, ", + V_RW, 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.url", STRING, 7, "VRT_r_req_url(sp)", - NULL, - V_RO, + "VRT_l_req_url(sp, ", + V_RW, 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.proto", STRING, 9, "VRT_r_req_proto(sp)", - NULL, - V_RO, + "VRT_l_req_proto(sp, ", + V_RW, 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, @@ -74,7 +74,7 @@ "VRT_r_req_http_(sp)", "VRT_l_req_http_(sp, ", V_RW, - 0, + "HDR_REQ", VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.hash", HASH, 8, @@ -116,7 +116,7 @@ "VRT_r_bereq_http_(sp)", "VRT_l_bereq_http_(sp, ", V_RW, - 0, + "HDR_BEREQ", VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS }, { "obj.proto", STRING, 9, @@ -144,7 +144,7 @@ "VRT_r_obj_http_(sp)", "VRT_l_obj_http_(sp, ", V_RW, - 0, + "HDR_OBJ", VCL_MET_HIT | VCL_MET_FETCH }, { "obj.valid", BOOL, 9, @@ -200,7 +200,7 @@ "VRT_r_resp_http_(sp)", "VRT_l_resp_http_(sp, ", V_RW, - 0, + "HDR_RESP", VCL_MET_DELIVER }, { "now", TIME, 3, Modified: branches/1.1/lib/libvcl/vcc_parse.c =================================================================== --- branches/1.1/lib/libvcl/vcc_parse.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/vcc_parse.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -221,38 +221,16 @@ /*--------------------------------------------------------------------*/ static void -vcc_re(struct tokenlist *tl, const char *str, const struct token *re) -{ - char buf[32]; - - assert(re->tok == CSTR); - if (VRT_re_test(tl->sb, re->dec)) { - vcc_ErrWhere(tl, re); - return; - } - sprintf(buf, "VGC_re_%u", tl->recnt++); - - Fb(tl, 1, "VRT_re_match(%s, %s)\n", str, buf); - Fh(tl, 0, "void *%s;\n", buf); - Fi(tl, 0, "\tVRT_re_init(&%s, ",buf); - EncToken(tl->fi, re); - Fi(tl, 0, ");\n"); - Ff(tl, 0, "\tVRT_re_fini(%s);\n", buf); -} - - -/*--------------------------------------------------------------------*/ - -static void Cond_String(const struct var *vp, struct tokenlist *tl) { + char *p; switch (tl->t->tok) { case '~': vcc_NextToken(tl); - ExpectErr(tl, CSTR); - vcc_re(tl, vp->rname, tl->t); + p = vcc_regexp(tl, 0); vcc_NextToken(tl); + Fb(tl, 1, "VRT_re_match(%s, %s)\n", vp->rname, p); break; case T_EQ: case T_NEQ: Copied: branches/1.1/lib/libvcl/vcc_string.c (from rev 1692, trunk/varnish-cache/lib/libvcl/vcc_string.c) =================================================================== --- branches/1.1/lib/libvcl/vcc_string.c (rev 0) +++ branches/1.1/lib/libvcl/vcc_string.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -0,0 +1,164 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2007 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * 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. + * + * $Id$ + */ + +#include +#include + +#include "vsb.h" + +#include "vcc_priv.h" +#include "vcc_compile.h" +#include "libvarnish.h" + +#include "vrt.h" + +/*--------------------------------------------------------------------*/ + +char * +vcc_regexp(struct tokenlist *tl, int sub) +{ + char buf[32], *p; + + Expect(tl, CSTR); + if (VRT_re_test(tl->sb, tl->t->dec, sub)) { + vcc_ErrWhere(tl, tl->t); + return (NULL); + } + sprintf(buf, "VGC_re_%u", tl->recnt++); + p = TlAlloc(tl, strlen(buf) + 1); + strcpy(p, buf); + + Fh(tl, 0, "void *%s;\n", buf); + Fi(tl, 0, "\tVRT_re_init(&%s, ",buf); + EncToken(tl->fi, tl->t); + Fi(tl, 0, ", %d);\n", sub); + Ff(tl, 0, "\tVRT_re_fini(%s);\n", buf); + return (p); +} + +/*--------------------------------------------------------------------*/ + +static int +vcc_regsub(struct tokenlist *tl) +{ + char *p; + + vcc_NextToken(tl); + + Fb(tl, 0, "VRT_regsub(sp, "); + + Expect(tl, '('); + vcc_NextToken(tl); + + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return (0); + } + + Expect(tl, ','); + vcc_NextToken(tl); + + Expect(tl, CSTR); + p = vcc_regexp(tl, 1); + vcc_NextToken(tl); + Fb(tl, 0, ", %s, ", p); + + Expect(tl, ','); + vcc_NextToken(tl); + + Expect(tl, CSTR); + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return (0); + } + + Expect(tl, ')'); + vcc_NextToken(tl); + Fb(tl, 0, ")"); + + return (1); +} + +/*-------------------------------------------------------------------- + * Parse a string value and emit something that results in a usable + * "const char *". + * There are three possible outcomes: + * tl->err != 0 means something bad happened and a message is emitted. + * return (0) means "could not use this token" + * return (1) means "done" + */ + +int +vcc_StringVal(struct tokenlist *tl) +{ + struct var *vp; + + if (tl->t->tok == CSTR) { + EncToken(tl->fb, tl->t); + vcc_NextToken(tl); + return (1); + } + if (tl->t->tok == ID && vcc_IdIs(tl->t, "regsub")) + return (vcc_regsub(tl)); + if (tl->t->tok == VAR) { + vp = vcc_FindVar(tl, tl->t, vcc_vars); + if (tl->err) + return (0); + assert(vp != NULL); + switch (vp->fmt) { + case STRING: + Fb(tl, 0, "%s", vp->rname); + break; + case IP: + Fb(tl, 0, "VRT_IP_string(sp, %s)", vp->rname); + break; + default: + vsb_printf(tl->sb, + "String representation of '%s' not implemented yet.\n", + vp->name); + vcc_ErrWhere(tl, tl->t); + return (0); + } + vcc_NextToken(tl); + return (1); + } + return (0); +} + +void +vcc_ExpectedStringval(struct tokenlist *tl) +{ + + if (!tl->err) { + vsb_printf(tl->sb, "Expected string variable or constant\n"); + vcc_ErrWhere(tl, tl->t); + } +} Modified: branches/1.1/lib/libvcl/vcc_var.c =================================================================== --- branches/1.1/lib/libvcl/vcc_var.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/vcc_var.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -40,44 +40,10 @@ /*--------------------------------------------------------------------*/ -void -vcc_StringVal(struct tokenlist *tl) -{ - struct var *vp; - - if (tl->t->tok == CSTR) { - EncToken(tl->fb, tl->t); - vcc_NextToken(tl); - return; - } else if (tl->t->tok != VAR) { - vsb_printf(tl->sb, "Expected string variable or constant\n"); - vcc_ErrWhere(tl, tl->t); - return; - } - ERRCHK(tl); - vp = vcc_FindVar(tl, tl->t, vcc_vars); - ERRCHK(tl); - switch (vp->fmt) { - case STRING: - Fb(tl, 0, "%s", vp->rname); - break; - default: - vsb_printf(tl->sb, - "String representation of '%s' not implemented yet.\n", - vp->name); - vcc_ErrWhere(tl, tl->t); - return; - } - vcc_NextToken(tl); -} - -/*--------------------------------------------------------------------*/ - static struct var * HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh) { char *p; - const char *wh; struct var *v; int i; @@ -93,23 +59,13 @@ v->name = p; v->access = V_RW; v->fmt = STRING; - v->ishdr = 1; + v->hdr = vh->hdr; v->methods = vh->methods; - if (!memcmp(vh->name, "req.", 4)) - wh = "HDR_REQ"; - else if (!memcmp(vh->name, "resp.", 5)) - wh = "HDR_RESP"; - else if (!memcmp(vh->name, "obj.", 4)) - wh = "HDR_OBJ"; - else if (!memcmp(vh->name, "bereq.", 6)) - wh = "HDR_BEREQ"; - else - assert(0 == 1); - asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", wh, + asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); v->rname = p; - asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", wh, + asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); v->lname = p; Modified: branches/1.1/lib/libvcl/vcc_xref.c =================================================================== --- branches/1.1/lib/libvcl/vcc_xref.c 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/lib/libvcl/vcc_xref.c 2007-07-13 14:54:51 UTC (rev 1693) @@ -328,7 +328,7 @@ } static struct procuse * -vcc_FindIllegalUse(struct proc *p, struct method *m) +vcc_FindIllegalUse(const struct proc *p, const struct method *m) { struct procuse *pu; @@ -339,7 +339,7 @@ } static int -vcc_CheckUseRecurse(struct tokenlist *tl, struct proc *p, struct method *m) +vcc_CheckUseRecurse(struct tokenlist *tl, const struct proc *p, struct method *m) { struct proccall *pc; struct procuse *pu; Modified: branches/1.1/man/vcl.7 =================================================================== --- branches/1.1/man/vcl.7 2007-07-13 14:53:48 UTC (rev 1692) +++ branches/1.1/man/vcl.7 2007-07-13 14:54:51 UTC (rev 1693) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd July 5, 2007 +.Dd July 13, 2007 .Dt VCL 7 .Os .Sh NAME @@ -116,6 +116,27 @@ pipe; } .Ed +.Ss Functions +The following built-in functions are available: +.Bl -tag -width indent +.It Fn regsub "str" "regex" "sub" +Returns a copy of +.Fa str +with all occurrences of the regular expression +.Fa regex +replaced with +.Fa sub . +Within +.Fa sub , +.Va $0 +(which can also be spelled +.Va & ) +is replaced with the entire matched string, and +.Va $n +is replaced with the contents of subgroup +.Ar n +in the matched string. +.El .Ss Subroutines A subroutine is used to group code for legibility or reusability: .Bd -literal -offset 4n @@ -145,7 +166,7 @@ request should be handled. Each subroutine terminates by calling one of a small number of keywords which indicates the desired outcome. -.Bl -tag -width "vcl_timeout" +.Bl -tag -width indent .\" vcl_recv .It Cm vcl_recv Called at the beginning of a request, after the complete request has @@ -156,7 +177,7 @@ The .Cm vcl_recv subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -186,7 +207,7 @@ The .Cm vcl_pipe subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -205,7 +226,7 @@ The .Cm vcl_pass subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -218,7 +239,7 @@ The .Cm vcl_hash subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm hash Proceed. .El @@ -230,7 +251,7 @@ The .Cm vcl_hit subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -253,7 +274,7 @@ The .Cm vcl_miss subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -274,7 +295,7 @@ The .Cm vcl_fetch subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -294,7 +315,7 @@ The .Cm vcl_deliver subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm error Ar code Op Ar reason Return the specified error code to the client and abandon the request. @@ -309,7 +330,7 @@ The .Cm vcl_timeout subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm fetch Request a fresh copy of the object from the backend. .It Cm discard @@ -324,7 +345,7 @@ The .Cm vcl_discard subroutine may terminate with one of the following keywords: -.Bl -tag -width "discard" +.Bl -tag -width indent .It Cm discard Discard the object. .It Cm keep From phk at projects.linpro.no Fri Jul 13 15:31:37 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Jul 2007 17:31:37 +0200 (CEST) Subject: r1694 - trunk/varnish-cache/bin/varnishd Message-ID: <20070713153137.E97621EC1F6@projects.linpro.no> Author: phk Date: 2007-07-13 17:31:37 +0200 (Fri, 13 Jul 2007) New Revision: 1694 Modified: trunk/varnish-cache/bin/varnishd/cache_response.c Log: Fix 304 responses, they got messed up in the vcl_deliver() addition. Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-13 14:54:51 UTC (rev 1693) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-13 15:31:37 UTC (rev 1694) @@ -69,8 +69,7 @@ http_ClrHeader(sp->http); sp->http->logtag = HTTP_Tx; - http_SetResp(sp->http, - "HTTP/1.1", "304", "Not Modified"); + http_SetResp(sp->http, "HTTP/1.1", "304", "Not Modified"); TIM_format(sp->t_req, lm); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Date: %s", lm); http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish"); @@ -81,8 +80,7 @@ http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); WRK_Reset(sp->wrk, &sp->fd); sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); - if (WRK_Flush(sp->wrk)) - vca_close_session(sp, "remote closed"); + sp->wantbody = 0; } /*--------------------------------------------------------------------*/ From phk at projects.linpro.no Fri Jul 13 19:36:39 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Jul 2007 21:36:39 +0200 (CEST) Subject: r1695 - trunk/varnish-cache/bin/varnishd Message-ID: <20070713193639.2785E1EC418@projects.linpro.no> Author: phk Date: 2007-07-13 21:36:38 +0200 (Fri, 13 Jul 2007) New Revision: 1695 Modified: trunk/varnish-cache/bin/varnishd/cache_response.c Log: Shave the previos commit a bit closer: don't write the HTTP response only to throw it away later and then rewrite it again after giving vcl_deliver() the chance to munge it. Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-13 15:31:37 UTC (rev 1694) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-13 19:36:38 UTC (rev 1695) @@ -78,8 +78,6 @@ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Last-Modified: %s", lm); if (sp->doclose != NULL) http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); - WRK_Reset(sp->wrk, &sp->fd); - sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); sp->wantbody = 0; } From phk at projects.linpro.no Sun Jul 15 07:51:36 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 15 Jul 2007 09:51:36 +0200 (CEST) Subject: r1696 - trunk/varnish-cache/bin/varnishd Message-ID: <20070715075136.9889B1EC1F6@projects.linpro.no> Author: phk Date: 2007-07-15 09:51:36 +0200 (Sun, 15 Jul 2007) New Revision: 1696 Modified: trunk/varnish-cache/bin/varnishd/flint.lnt Log: Tune a couple of library warnings out Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2007-07-13 19:36:38 UTC (rev 1695) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2007-07-15 07:51:36 UTC (rev 1696) @@ -3,6 +3,12 @@ +libh mgt_event.h +libh ../../config.h +-emacro((???),va_arg) // the va_arg() macro can yield 415, 416, 661, 662 + // 796 and 797 (out-of-bounds errors). +-elib(123) // size is both a variable and a macro with args +-emacro(736, isnan) // isnanf + + -header(../../config.h) // Fix strchr() semtics, it can only return NULL if arg2 != 0 From phk at projects.linpro.no Sun Jul 15 07:52:11 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 15 Jul 2007 09:52:11 +0200 (CEST) Subject: r1697 - trunk/varnish-cache/bin/varnishd Message-ID: <20070715075211.4A6E41EC2A3@projects.linpro.no> Author: phk Date: 2007-07-15 09:52:11 +0200 (Sun, 15 Jul 2007) New Revision: 1697 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Make the header-gluing code more readable. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-15 07:51:36 UTC (rev 1696) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-15 07:52:11 UTC (rev 1697) @@ -123,28 +123,30 @@ u = WS_Reserve(hp->ws, 0); e = b = hp->ws->f; - *e = '\0'; + e += u; if (h != NULL) { x = strlen(h); - if (x + 2 < u) { - memcpy(e, h, x); - e[x] = ' '; - e[x + 1] = '\0'; - } - e += x + 1; + if (b + x < e) + memcpy(b, h, x); + b += x; + if (b + 1 < e) + *b++ = ' '; } while (p != NULL) { x = strlen(p); - if (x + 1 < u) - memcpy(e, p, x); - e += x; + if (b + x < e) + memcpy(b, p, x); + b += x; p = va_arg(ap, const char *); } - *e = '\0'; - if (e > b + u) { + if (b + 1 < e) + *b++ = '\0'; + if (b > e) { WS_Release(hp->ws, 0); return (NULL); } else { + e = b; + b = hp->ws->f; WS_Release(hp->ws, 1 + e - b); return (b); } From phk at projects.linpro.no Sun Jul 15 07:52:30 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 15 Jul 2007 09:52:30 +0200 (CEST) Subject: r1698 - trunk/varnish-cache/bin/varnishd Message-ID: <20070715075230.BA55C1EC1F6@projects.linpro.no> Author: phk Date: 2007-07-15 09:52:30 +0200 (Sun, 15 Jul 2007) New Revision: 1698 Modified: trunk/varnish-cache/bin/varnishd/cache_main.c Log: A cast to make flexelint happy. Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2007-07-15 07:52:11 UTC (rev 1697) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2007-07-15 07:52:30 UTC (rev 1698) @@ -71,7 +71,7 @@ stevedore->open(stevedore); printf("Ready\n"); - VSL_stats->start_time = TIM_real(); + VSL_stats->start_time = (time_t)TIM_real(); CLI_Init(); From phk at projects.linpro.no Sun Jul 15 10:22:06 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 15 Jul 2007 12:22:06 +0200 (CEST) Subject: r1699 - trunk/varnish-cache/bin/varnishd Message-ID: <20070715102206.220A81EC2A3@projects.linpro.no> Author: phk Date: 2007-07-15 12:22:05 +0200 (Sun, 15 Jul 2007) New Revision: 1699 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: Initialize all bits in the sigaction. Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-15 07:52:30 UTC (rev 1698) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-15 10:22:05 UTC (rev 1699) @@ -410,6 +410,7 @@ setproctitle("Varnish-Mgr %s", heritage.name); + memset(&sac, 0, sizeof sac); sac.sa_handler = SIG_IGN; sac.sa_flags = SA_RESTART; From phk at projects.linpro.no Sun Jul 15 10:22:39 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 15 Jul 2007 12:22:39 +0200 (CEST) Subject: r1700 - trunk/varnish-cache/lib/libvcl Message-ID: <20070715102239.C81CF1EC1F6@projects.linpro.no> Author: phk Date: 2007-07-15 12:22:39 +0200 (Sun, 15 Jul 2007) New Revision: 1700 Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_var.c Log: Plug a memory-leak in the VCL compiler. Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-07-15 10:22:05 UTC (rev 1699) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-07-15 10:22:39 UTC (rev 1700) @@ -95,18 +95,26 @@ /*--------------------------------------------------------------------*/ +void +TlFree(struct tokenlist *tl, void *p) +{ + struct membit *mb; + + mb = calloc(sizeof *mb, 1); + assert(mb != NULL); + mb->ptr = p; + TAILQ_INSERT_TAIL(&tl->membits, mb, list); +} + + void * TlAlloc(struct tokenlist *tl, unsigned len) { - struct membit *mb; void *p; p = calloc(len, 1); assert(p != NULL); - mb = calloc(sizeof *mb, 1); - assert(mb != NULL); - mb->ptr = p; - TAILQ_INSERT_TAIL(&tl->membits, mb, list); + TlFree(tl, p); return (p); } Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-15 10:22:05 UTC (rev 1699) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-15 10:22:39 UTC (rev 1700) @@ -153,6 +153,7 @@ void Ff(const struct tokenlist *tl, int indent, const char *fmt, ...); void EncToken(struct vsb *sb, const struct token *t); int IsMethod(const struct token *t); +void TlFree(struct tokenlist *tl, void *p); void *TlAlloc(struct tokenlist *tl, unsigned len); /* vcc_obj.c */ Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-15 10:22:05 UTC (rev 1699) +++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2007-07-15 10:22:39 UTC (rev 1700) @@ -64,10 +64,12 @@ asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); + TlFree(tl, p); v->rname = p; asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); + TlFree(tl, p); v->lname = p; return (v); } From phk at projects.linpro.no Sun Jul 15 10:57:55 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 15 Jul 2007 12:57:55 +0200 (CEST) Subject: r1701 - trunk/varnish-cache/lib/libvcl Message-ID: <20070715105755.9B62B1EC2A3@projects.linpro.no> Author: phk Date: 2007-07-15 12:57:55 +0200 (Sun, 15 Jul 2007) New Revision: 1701 Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c Log: Don't leak all the tokens. Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token.c 2007-07-15 10:22:39 UTC (rev 1700) +++ trunk/varnish-cache/lib/libvcl/vcc_token.c 2007-07-15 10:57:55 UTC (rev 1701) @@ -255,7 +255,7 @@ { struct token *t; - t = calloc(sizeof *t, 1); + t = TlAlloc(tl, sizeof *t); assert(t != NULL); t->tok = tok; t->b = b; From phk at projects.linpro.no Sun Jul 15 10:58:11 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 15 Jul 2007 12:58:11 +0200 (CEST) Subject: r1702 - trunk/varnish-cache/bin/varnishd Message-ID: <20070715105811.9FD6B1EC1F6@projects.linpro.no> Author: phk Date: 2007-07-15 12:58:11 +0200 (Sun, 15 Jul 2007) New Revision: 1702 Modified: trunk/varnish-cache/bin/varnishd/storage_file.c Log: Plug minor memory leak. Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2007-07-15 10:57:55 UTC (rev 1701) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-07-15 10:58:11 UTC (rev 1702) @@ -317,6 +317,7 @@ return; } + asprintf(&q, "%s/varnish.XXXXXX", p); XXXAN(q); sc->fd = mkstemp(q); @@ -331,6 +332,7 @@ XXXAN(sc->filename); free(q); smf_initfile(sc, size, 1); + free(p); } /*-------------------------------------------------------------------- From phk at projects.linpro.no Sun Jul 15 11:04:53 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 15 Jul 2007 13:04:53 +0200 (CEST) Subject: r1703 - trunk/varnish-cache/lib/libvcl Message-ID: <20070715110453.1F9B51EC030@projects.linpro.no> Author: phk Date: 2007-07-15 13:04:52 +0200 (Sun, 15 Jul 2007) New Revision: 1703 Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h Log: Don't leak the file contents either. Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-07-15 10:58:11 UTC (rev 1702) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-07-15 11:04:52 UTC (rev 1703) @@ -378,6 +378,8 @@ vcc_destroy_source(struct source *sp) { + if (sp->freeit != NULL) + free(sp->freeit); free(sp->name); free(sp); } @@ -390,6 +392,7 @@ char *f; int i; struct stat st; + struct source *sp; if (fd < 0) { fd = open(fn, O_RDONLY); @@ -406,7 +409,9 @@ assert(i == st.st_size); close(fd); f[i] = '\0'; - return (vcc_new_source(f, f + i, fn)); + sp = vcc_new_source(f, f + i, fn); + sp->freeit = f; + return (sp); } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-15 10:58:11 UTC (rev 1702) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-07-15 11:04:52 UTC (rev 1703) @@ -45,6 +45,7 @@ const char *b; const char *e; unsigned idx; + char *freeit; }; struct token { From phk at projects.linpro.no Sun Jul 15 11:08:49 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 15 Jul 2007 13:08:49 +0200 (CEST) Subject: r1704 - trunk/varnish-cache/lib/libvcl Message-ID: <20070715110849.0C8271EC1F6@projects.linpro.no> Author: phk Date: 2007-07-15 13:08:48 +0200 (Sun, 15 Jul 2007) New Revision: 1704 Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_token.c Log: Plug even more memory leaks in the VCL compiler. Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-07-15 11:04:52 UTC (rev 1703) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-07-15 11:08:48 UTC (rev 1704) @@ -514,6 +514,7 @@ vcc_DestroyTokenList(struct tokenlist *tl, char *ret) { struct membit *mb; + struct source *sp; int i; while (!TAILQ_EMPTY(&tl->membits)) { @@ -522,6 +523,11 @@ free(mb->ptr); free(mb); } + while (!TAILQ_EMPTY(&tl->sources)) { + sp = TAILQ_FIRST(&tl->sources); + TAILQ_REMOVE(&tl->sources, sp, list); + vcc_destroy_source(sp); + } vsb_delete(tl->fh); vsb_delete(tl->fc); @@ -658,7 +664,6 @@ if (sp == NULL) return (NULL); r = vcc_CompileSource(sb, sp); - vcc_destroy_source(sp); return (r); } @@ -677,7 +682,6 @@ if (sp == NULL) return (NULL); r = vcc_CompileSource(sb, sp); - vcc_destroy_source(sp); return (r); } Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token.c 2007-07-15 11:04:52 UTC (rev 1703) +++ trunk/varnish-cache/lib/libvcl/vcc_token.c 2007-07-15 11:08:48 UTC (rev 1704) @@ -209,7 +209,7 @@ unsigned char u; assert(tl->t->tok == CSTR); - tl->t->dec = malloc((tl->t->e - tl->t->b) - 1); + tl->t->dec = TlAlloc(tl, (tl->t->e - tl->t->b) - 1); assert(tl->t->dec != NULL); q = tl->t->dec; for (p = tl->t->b + 1; p < tl->t->e - 1; ) { From phk at projects.linpro.no Sun Jul 15 11:25:27 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 15 Jul 2007 13:25:27 +0200 (CEST) Subject: r1705 - trunk/varnish-cache/lib/libvarnish Message-ID: <20070715112527.8A0FF1EC030@projects.linpro.no> Author: phk Date: 2007-07-15 13:25:27 +0200 (Sun, 15 Jul 2007) New Revision: 1705 Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c Log: >From the "What has the world come to ?" department: It used to be that sscanf(3) would walk along the proffered string and do what the format string was told, and as long as the format terminated before the input string, the NUL termination was not relevant. Sometime in the last 20 years, sscanf started doing a strlen on the passed argument changing this behaviour. Give sscanf the NUL it wants. Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/cli_common.c 2007-07-15 11:08:48 UTC (rev 1704) +++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2007-07-15 11:25:27 UTC (rev 1705) @@ -154,6 +154,7 @@ assert(i == CLI_LINE0_LEN); assert(res[3] == ' '); assert(res[CLI_LINE0_LEN - 1] == '\n'); + res[CLI_LINE0_LEN - 1] = '\0'; j = sscanf(res, "%u %u\n", &u, &v); assert(j == 2); if (status != NULL) From cecilihf at projects.linpro.no Mon Jul 16 08:39:50 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Mon, 16 Jul 2007 10:39:50 +0200 (CEST) Subject: r1706 - in trunk/varnish-tools: . webmin webmin/Varnish webmin/images Message-ID: <20070716083950.CF7841EC2A3@projects.linpro.no> Author: cecilihf Date: 2007-07-16 10:39:50 +0200 (Mon, 16 Jul 2007) New Revision: 1706 Added: trunk/varnish-tools/webmin/ trunk/varnish-tools/webmin/Varnish/ trunk/varnish-tools/webmin/Varnish/CLI.pm trunk/varnish-tools/webmin/config.info trunk/varnish-tools/webmin/images/ trunk/varnish-tools/webmin/images/icon.gif trunk/varnish-tools/webmin/images/params_icon.gif trunk/varnish-tools/webmin/images/purge_icon.gif trunk/varnish-tools/webmin/images/status_icon.gif trunk/varnish-tools/webmin/images/vcl_icon.gif trunk/varnish-tools/webmin/index.cgi trunk/varnish-tools/webmin/module.info trunk/varnish-tools/webmin/varnish_params.cgi trunk/varnish-tools/webmin/varnish_purge.cgi trunk/varnish-tools/webmin/varnish_start.cgi trunk/varnish-tools/webmin/varnish_status.cgi trunk/varnish-tools/webmin/varnish_stop.cgi trunk/varnish-tools/webmin/varnish_vcl.cgi trunk/varnish-tools/webmin/varnish_vcl_upload.cgi trunk/varnish-tools/webmin/varnish_vcl_use.cgi trunk/varnish-tools/webmin/varnish_vcl_view.cgi trunk/varnish-tools/webmin/varnishadm-lib.pl Log: Webmin plugin for varnish Added: trunk/varnish-tools/webmin/Varnish/CLI.pm =================================================================== --- trunk/varnish-tools/webmin/Varnish/CLI.pm (rev 0) +++ trunk/varnish-tools/webmin/Varnish/CLI.pm 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,60 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +package Varnish::CLI; + +use IO::Socket; + +# Send a command to varnish over telnet. +# This function takes a hash as parameter. +# Valid keys for the hash are: +# * address : Address of varnish +# * port: port where varnish listens for telnet connections +# * command : the command to send +# * params : parameters to the command as a string. (optional) +# The function returns a tuple with the return code and the result. +# If missing or invalid parameters, 0 is returned. +sub send_command { + my ($args) = shift; + my $sock; + my $line; + my $status, $size, $read; + my $response = ""; + + if (!$args->{'address'} || !$args->{'port'} || !$args->{'command'}) { + return 0; + } + + $sock = IO::Socket::INET->new( + Proto => "tcp", + PeerAddr => $args->{'address'}, + PeerPort => $args->{'port'}, + ) or return 0; + + if ($args->{'params'}) { + $args->{'command'} .= " $args->{'params'}"; + } + print $sock "$args->{'command'}\r\n"; + + if (!($line = <$sock>)) { + return 0; + } + $line =~ /^(\d+) (\d+)/; + $status = $1; + $size = $2; + + while ($line = <$sock>) { + $response .= $line; + $read += length($line); + if ($read >= $size) { + last; + } + } + + close $sock; + + return ($status, $response); +} + +return 1; \ No newline at end of file Property changes on: trunk/varnish-tools/webmin/Varnish/CLI.pm ___________________________________________________________________ Name: svn:executable + * Added: trunk/varnish-tools/webmin/config.info =================================================================== --- trunk/varnish-tools/webmin/config.info (rev 0) +++ trunk/varnish-tools/webmin/config.info 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,2 @@ +address=Address to varnish,3,localhost +port=Port number varnish listens for telnet connections on,3,23 Added: trunk/varnish-tools/webmin/images/icon.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-tools/webmin/images/icon.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/varnish-tools/webmin/images/params_icon.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-tools/webmin/images/params_icon.gif ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Added: trunk/varnish-tools/webmin/images/purge_icon.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-tools/webmin/images/purge_icon.gif ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Added: trunk/varnish-tools/webmin/images/status_icon.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-tools/webmin/images/status_icon.gif ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Added: trunk/varnish-tools/webmin/images/vcl_icon.gif =================================================================== (Binary files differ) Property changes on: trunk/varnish-tools/webmin/images/vcl_icon.gif ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Added: trunk/varnish-tools/webmin/index.cgi =================================================================== --- trunk/varnish-tools/webmin/index.cgi (rev 0) +++ trunk/varnish-tools/webmin/index.cgi 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,13 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +require './varnishadm-lib.pl'; + +&ui_print_header(undef, $module_info{'name'}, "", undef, 1, 1); + + at olinks = ("varnish_vcl.cgi", "varnish_params.cgi", "varnish_status.cgi", "varnish_purge.cgi"); + at otitles = ("VCL", "Params", "Start/Stop", "Purge"); + at oicons = ("images/vcl_icon.gif", "images/params_icon.gif", "images/status_icon.gif", "images/purge_icon.gif"); + +&icons_table(\@olinks, \@otitles, \@oicons); Added: trunk/varnish-tools/webmin/module.info =================================================================== --- trunk/varnish-tools/webmin/module.info (rev 0) +++ trunk/varnish-tools/webmin/module.info 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,3 @@ +name=Varnish Admin +desc=Varnish Admin + Added: trunk/varnish-tools/webmin/varnish_params.cgi =================================================================== --- trunk/varnish-tools/webmin/varnish_params.cgi (rev 0) +++ trunk/varnish-tools/webmin/varnish_params.cgi 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,71 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +require './varnishadm-lib.pl'; +use Varnish::CLI; + +&ui_print_header(undef, "Params", "", undef, 1, 1); +&ReadParse(); +&error_setup("Failed"); + +my %attrs = ('address' => $config{'address'}, 'port' => $config{'port'}, + 'command' => 'param.show'); +my ($status, $res) = Varnish::CLI::send_command(\%attrs); + +if (!($status eq '200')) { + &error("$status - $res"); +} + +my @params = (); +foreach my $line (split(/\n/, $res)) { + if ($line =~ /(\w+)\s+([a-zA-z0-9.:]+)(\s+(\[|\()(\w+|%)(\]|\)))?/) { + push @params, {'name' => $1, 'value' => $2, 'unit' => $5}; + } +} +if ($in{'save'}) { + foreach $param (@params) { + if ($in{$param->{'name'}} && !($in{$param->{'name'}} eq $param->{'value'})) { + $attrs{'command'} = 'param.set'; + $attrs{'params'} = "$param->{'name'} $in{$param->{'name'}}"; + $status, $res = Varnish::CLI::send_command(\%attrs); + if (!($status eq '200')) { + &error("$status - $res"); + } + $param->{'value'} = $in{$param->{'name'}}; + } + } +} + +my $cmd_num = 0; +print "
"; +print "\n"; +print "\n"; +print "
params
\n"; +foreach $param (@params) { + if (($cmd_num % 2) == 0) { + print "\n"; + } + print "\n"; + if (($cmd_num % 2) != 0) { + print "\n"; + } + $cmd_num++; +} +print "
$param->{'name'}"; + if ($param->{'unit'} eq 'bool') { + print "{'name'} value=on " . + (($param->{'value'} eq 'on') ? "checked" : "") . " /> On\n"; + print "{'name'} value=off " . + (($param->{'value'} eq 'off') ? "checked" : "") . " /> Off\n"; + + } + else { + print "{'name'} value=$param->{'value'} size=25 /> $param->{'unit'}"; + } + print "
"; +print "
"; +print ""; +print "
"; + +&ui_print_footer("", 'module index'); Added: trunk/varnish-tools/webmin/varnish_purge.cgi =================================================================== --- trunk/varnish-tools/webmin/varnish_purge.cgi (rev 0) +++ trunk/varnish-tools/webmin/varnish_purge.cgi 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,34 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +require './varnishadm-lib.pl'; +use Varnish::CLI; + +&ui_print_header(undef, "Purge", "", undef, 1, 1); + +&ReadParse(); +&error_setup("Purge failed"); + +my %attrs = ('address' => $config{'address'}, 'port' => $config{'port'}, + 'command' => 'url.purge'); +if ($in{'regexp'}) { + $attrs{'params'} = $in{'regexp'}; + my ($status, $res) = Varnish::CLI::send_command(\%attrs); + + if ($status eq '200') { + print "Purging succesful
"; + print "$res
"; + print "
"; + } + else { + &error("$status - $res"); + } +} + +print "
\n"; +print "What to purge (regexp):
\n"; +print "
\n"; +print "
"; + +&ui_print_footer("", 'module index'); Added: trunk/varnish-tools/webmin/varnish_start.cgi =================================================================== --- trunk/varnish-tools/webmin/varnish_start.cgi (rev 0) +++ trunk/varnish-tools/webmin/varnish_start.cgi 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,19 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +require './varnishadm-lib.pl'; +use Varnish::CLI; + +&ReadParse(); +&error_setup("Start command failed: "); + +my %attrs = ('address' => $config{'address'}, 'port' => $config{'port'}, + 'command' => 'start'); +my ($status, $res) = Varnish::CLI::send_command(\%attrs); +if (!($status eq 200)) { + &error("$status - $res"); +} +&webmin_log("start"); +&redirect("varnish_status.cgi"); + Added: trunk/varnish-tools/webmin/varnish_status.cgi =================================================================== --- trunk/varnish-tools/webmin/varnish_status.cgi (rev 0) +++ trunk/varnish-tools/webmin/varnish_status.cgi 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,43 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +require './varnishadm-lib.pl'; +use Varnish::CLI; + +&ui_print_header(undef, "Status", "", undef, 1, 1); +&error_setup("Could not get status"); + +my %attrs = ('address' => $config{'address'}, 'port' => $config{'port'}, + 'command' => 'ping'); +my ($status, $res) = Varnish::CLI::send_command(\%attrs); +if ($status eq '200') { + if ($res =~ /^PONG/) { + print "Varnish is up
"; + } + else { + print "Varnish is down
"; + } +} +else { + &error("$status - $res"); +} + +$attrs{'command'} = 'status'; +$status, $res = Varnish::CLI::send_command(\%attrs); +if ($status eq '200') { + print "$res
"; +} +else { + &error("$status - $res"); +} + +print "
\n"; +print &ui_buttons_start(); + +print &ui_buttons_row("varnish_stop.cgi","Stop varnish child"); +print &ui_buttons_row("varnish_start.cgi", "Start varnish child"); + +print &ui_buttons_end(); + +&ui_print_footer("", 'module index'); Added: trunk/varnish-tools/webmin/varnish_stop.cgi =================================================================== --- trunk/varnish-tools/webmin/varnish_stop.cgi (rev 0) +++ trunk/varnish-tools/webmin/varnish_stop.cgi 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,19 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +require './varnishadm-lib.pl'; +use Varnish::CLI; + +&ReadParse(); +&error_setup("Stop command failed: "); + +my %attrs = ('address' => $config{'address'}, 'port' => $config{'port'}, + 'command' => 'stop'); +my ($status, $res) = Varnish::CLI::send_command(\%attrs); +if (!($status eq 200)) { + &error("$status - $res"); +} +&webmin_log("stop"); +&redirect("varnish_status.cgi"); + Added: trunk/varnish-tools/webmin/varnish_vcl.cgi =================================================================== --- trunk/varnish-tools/webmin/varnish_vcl.cgi (rev 0) +++ trunk/varnish-tools/webmin/varnish_vcl.cgi 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,60 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +require './varnishadm-lib.pl'; +use Varnish::CLI; + +&ui_print_header(undef, "VCL Admin", "", undef, 1, 1); +&error_setup("Failed"); + +my %attrs = ('address' => $config{'address'}, 'port' => $config{'port'}, + 'command' => 'vcl.list'); +my ($status, $res) = Varnish::CLI::send_command(\%attrs); + +if (!($status eq '200')) { + &error("$status - $res"); +} + +print ""; +print "\n"; +print ""; +print "\n"; +print ""; +print "
Available vcl files
"; +print "
"; +my $confname = ""; +my $set = 0; +foreach my $line (split(/\n/, $res)) { + if ($line =~ /\*?\s+\d\s+(\w+)/) { + $confname = $1; + if ($line =~ /^\*/) { + $set = 1; + } + } + print "\n"; + print "$confname"; + print "
\n"; + $set = 0; +} + +print "\n"; +print "
"; + +print "
Upload new vcl file
"; +print ""; +print ""; +print "
"; +print "Config name: "; +print "
"; +print "VCL file: "; +print &ui_upload("vcl_file", 25); +print "
"; +print "\n"; +print "
"; +print ""; + +print "
"; + +&ui_print_footer("", 'module index'); Added: trunk/varnish-tools/webmin/varnish_vcl_upload.cgi =================================================================== --- trunk/varnish-tools/webmin/varnish_vcl_upload.cgi (rev 0) +++ trunk/varnish-tools/webmin/varnish_vcl_upload.cgi 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,30 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +require './varnishadm-lib.pl'; +use Varnish::CLI; +use File::Temp qw (mkstemp); +use Fcntl qw (F_SETFD F_GETFD :mode); + +&ReadParseMime(); +&error_setup("Failed"); + +my %attrs = ('address' => $config{'address'}, 'port' => $config{'port'}, + 'command' => 'vcl.load'); + +my ($fh, $file) = mkstemp("/tmp/tmp.vcl.XXXXXXX"); +print $fh $in{'vcl_file'}; +close($fh); + +chmod S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, $file; + +$attrs{'params'} = "$in{'vcl_name'} $file"; + +my ($status, $res) = Varnish::CLI::send_command(\%attrs); + +if (!($status eq '200')) { + &error("$status - $res"); +} + +&redirect("varnish_vcl.cgi"); Added: trunk/varnish-tools/webmin/varnish_vcl_use.cgi =================================================================== --- trunk/varnish-tools/webmin/varnish_vcl_use.cgi (rev 0) +++ trunk/varnish-tools/webmin/varnish_vcl_use.cgi 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,22 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +require './varnishadm-lib.pl'; +use Varnish::CLI; + +&ReadParse(); +&error_setup("Failed"); + +my %attrs = ('address' => $config{'address'}, 'port' => $config{'port'}, + 'command' => 'vcl.use'); + +$attrs{'params'} = "$in{'vcl_name'}"; + +my ($status, $res) = Varnish::CLI::send_command(\%attrs); + +if (!($status eq '200')) { + &error("$status - $res"); +} + +&redirect("varnish_vcl.cgi"); \ No newline at end of file Added: trunk/varnish-tools/webmin/varnish_vcl_view.cgi =================================================================== --- trunk/varnish-tools/webmin/varnish_vcl_view.cgi (rev 0) +++ trunk/varnish-tools/webmin/varnish_vcl_view.cgi 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,29 @@ +#!/usr/local/bin/perl + +# Author: Cecilie Fritzvold + +require './varnishadm-lib.pl'; +use Varnish::CLI; + +&ReadParse(); +&error_setup("Failed"); + +&ui_print_header(undef, "vcl file: $in{'vcl_file'}", "", undef, 1, 1); + +my %attrs = ('address' => $config{'address'}, 'port' => $config{'port'}, + 'command' => 'vcl.show'); + +$attrs{'params'} = "$in{'vcl_file'}"; + +my ($status, $res) = Varnish::CLI::send_command(\%attrs); + +if (!($status eq '200')) { + &error("$status - $res"); +} + +$res =~ s/ / /g; +$res =~ s/\n/
/g; + +print $res; + +&ui_print_footer("varnish_vcl.cgi", 'vcl index'); Added: trunk/varnish-tools/webmin/varnishadm-lib.pl =================================================================== --- trunk/varnish-tools/webmin/varnishadm-lib.pl (rev 0) +++ trunk/varnish-tools/webmin/varnishadm-lib.pl 2007-07-16 08:39:50 UTC (rev 1706) @@ -0,0 +1,14 @@ +#!/usr/local/bin/perl + +do '../web-lib.pl'; +&init_config(); +do '../ui-lib.pl'; + +if (!$config{'address'}) { + $config{'address'} = 'localhost'; +} +if (!$config{'port'}) { + $config{'port'} = 23; +} + +return 1; From cecilihf at projects.linpro.no Mon Jul 16 11:21:45 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Mon, 16 Jul 2007 13:21:45 +0200 (CEST) Subject: r1707 - trunk/varnish-tools/webmin Message-ID: <20070716112145.F28491EC1F6@projects.linpro.no> Author: cecilihf Date: 2007-07-16 13:21:45 +0200 (Mon, 16 Jul 2007) New Revision: 1707 Modified: trunk/varnish-tools/webmin/module.info trunk/varnish-tools/webmin/varnish_vcl.cgi Log: Moved the plugin from "others" to "servers" in the menu Minor "stylistic" changes in VCL part of webmin plugin Modified: trunk/varnish-tools/webmin/module.info =================================================================== --- trunk/varnish-tools/webmin/module.info 2007-07-16 08:39:50 UTC (rev 1706) +++ trunk/varnish-tools/webmin/module.info 2007-07-16 11:21:45 UTC (rev 1707) @@ -1,3 +1,3 @@ name=Varnish Admin desc=Varnish Admin - +category=servers Modified: trunk/varnish-tools/webmin/varnish_vcl.cgi =================================================================== --- trunk/varnish-tools/webmin/varnish_vcl.cgi 2007-07-16 08:39:50 UTC (rev 1706) +++ trunk/varnish-tools/webmin/varnish_vcl.cgi 2007-07-16 11:21:45 UTC (rev 1707) @@ -17,7 +17,7 @@ } print ""; -print "\n"; +print "\n"; print ""; -print "\n"; +print "\n"; print "
Available vcl files
Available VCL scripts
"; print "
"; my $confname = ""; @@ -36,11 +36,11 @@ $set = 0; } -print "\n"; +print "\n"; print "
"; print "
Upload new vcl file
Upload new VCL file
"; print ""; print "
"; From cecilihf at projects.linpro.no Mon Jul 16 13:06:42 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Mon, 16 Jul 2007 15:06:42 +0200 (CEST) Subject: r1708 - trunk/varnish-tools/webmin Message-ID: <20070716130642.C9F601EC3F0@projects.linpro.no> Author: cecilihf Date: 2007-07-16 15:06:42 +0200 (Mon, 16 Jul 2007) New Revision: 1708 Modified: trunk/varnish-tools/webmin/module.info Log: Changed name/description Modified: trunk/varnish-tools/webmin/module.info =================================================================== --- trunk/varnish-tools/webmin/module.info 2007-07-16 11:21:45 UTC (rev 1707) +++ trunk/varnish-tools/webmin/module.info 2007-07-16 13:06:42 UTC (rev 1708) @@ -1,3 +1,3 @@ -name=Varnish Admin -desc=Varnish Admin +name=Varnish HTTP accelerator +desc=Varnish HTTP accelerator category=servers From des at projects.linpro.no Tue Jul 17 10:15:44 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 17 Jul 2007 12:15:44 +0200 (CEST) Subject: r1709 - in branches/1.1: . bin/varnishd lib/libvarnish lib/libvcl Message-ID: <20070717101544.BE8DA1EC2A3@projects.linpro.no> Author: des Date: 2007-07-17 12:15:44 +0200 (Tue, 17 Jul 2007) New Revision: 1709 Modified: branches/1.1/ branches/1.1/bin/varnishd/cache_main.c branches/1.1/bin/varnishd/cache_response.c branches/1.1/bin/varnishd/cache_vrt.c branches/1.1/bin/varnishd/flint.lnt branches/1.1/bin/varnishd/mgt_child.c branches/1.1/bin/varnishd/storage_file.c branches/1.1/lib/libvarnish/cli_common.c branches/1.1/lib/libvcl/vcc_compile.c branches/1.1/lib/libvcl/vcc_compile.h branches/1.1/lib/libvcl/vcc_token.c branches/1.1/lib/libvcl/vcc_var.c Log: Merged revisions 1693-1708 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1694 | phk | 2007-07-13 17:31:37 +0200 (Fri, 13 Jul 2007) | 3 lines Fix 304 responses, they got messed up in the vcl_deliver() addition. ........ r1695 | phk | 2007-07-13 21:36:38 +0200 (Fri, 13 Jul 2007) | 4 lines Shave the previos commit a bit closer: don't write the HTTP response only to throw it away later and then rewrite it again after giving vcl_deliver() the chance to munge it. ........ r1696 | phk | 2007-07-15 09:51:36 +0200 (Sun, 15 Jul 2007) | 2 lines Tune a couple of library warnings out ........ r1697 | phk | 2007-07-15 09:52:11 +0200 (Sun, 15 Jul 2007) | 2 lines Make the header-gluing code more readable. ........ r1698 | phk | 2007-07-15 09:52:30 +0200 (Sun, 15 Jul 2007) | 2 lines A cast to make flexelint happy. ........ r1699 | phk | 2007-07-15 12:22:05 +0200 (Sun, 15 Jul 2007) | 2 lines Initialize all bits in the sigaction. ........ r1700 | phk | 2007-07-15 12:22:39 +0200 (Sun, 15 Jul 2007) | 2 lines Plug a memory-leak in the VCL compiler. ........ r1701 | phk | 2007-07-15 12:57:55 +0200 (Sun, 15 Jul 2007) | 2 lines Don't leak all the tokens. ........ r1702 | phk | 2007-07-15 12:58:11 +0200 (Sun, 15 Jul 2007) | 2 lines Plug minor memory leak. ........ r1703 | phk | 2007-07-15 13:04:52 +0200 (Sun, 15 Jul 2007) | 2 lines Don't leak the file contents either. ........ r1704 | phk | 2007-07-15 13:08:48 +0200 (Sun, 15 Jul 2007) | 2 lines Plug even more memory leaks in the VCL compiler. ........ r1705 | phk | 2007-07-15 13:25:27 +0200 (Sun, 15 Jul 2007) | 13 lines From the "What has the world come to ?" department: It used to be that sscanf(3) would walk along the proffered string and do what the format string was told, and as long as the format terminated before the input string, the NUL termination was not relevant. Sometime in the last 20 years, sscanf started doing a strlen on the passed argument changing this behaviour. Give sscanf the NUL it wants. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1692 + /trunk/varnish-cache:1-1708 Modified: branches/1.1/bin/varnishd/cache_main.c =================================================================== --- branches/1.1/bin/varnishd/cache_main.c 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/bin/varnishd/cache_main.c 2007-07-17 10:15:44 UTC (rev 1709) @@ -71,7 +71,7 @@ stevedore->open(stevedore); printf("Ready\n"); - VSL_stats->start_time = TIM_real(); + VSL_stats->start_time = (time_t)TIM_real(); CLI_Init(); Modified: branches/1.1/bin/varnishd/cache_response.c =================================================================== --- branches/1.1/bin/varnishd/cache_response.c 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/bin/varnishd/cache_response.c 2007-07-17 10:15:44 UTC (rev 1709) @@ -69,8 +69,7 @@ http_ClrHeader(sp->http); sp->http->logtag = HTTP_Tx; - http_SetResp(sp->http, - "HTTP/1.1", "304", "Not Modified"); + http_SetResp(sp->http, "HTTP/1.1", "304", "Not Modified"); TIM_format(sp->t_req, lm); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Date: %s", lm); http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish"); @@ -79,10 +78,7 @@ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Last-Modified: %s", lm); if (sp->doclose != NULL) http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); - WRK_Reset(sp->wrk, &sp->fd); - sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); - if (WRK_Flush(sp->wrk)) - vca_close_session(sp, "remote closed"); + sp->wantbody = 0; } /*--------------------------------------------------------------------*/ Modified: branches/1.1/bin/varnishd/cache_vrt.c =================================================================== --- branches/1.1/bin/varnishd/cache_vrt.c 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/bin/varnishd/cache_vrt.c 2007-07-17 10:15:44 UTC (rev 1709) @@ -123,28 +123,30 @@ u = WS_Reserve(hp->ws, 0); e = b = hp->ws->f; - *e = '\0'; + e += u; if (h != NULL) { x = strlen(h); - if (x + 2 < u) { - memcpy(e, h, x); - e[x] = ' '; - e[x + 1] = '\0'; - } - e += x + 1; + if (b + x < e) + memcpy(b, h, x); + b += x; + if (b + 1 < e) + *b++ = ' '; } while (p != NULL) { x = strlen(p); - if (x + 1 < u) - memcpy(e, p, x); - e += x; + if (b + x < e) + memcpy(b, p, x); + b += x; p = va_arg(ap, const char *); } - *e = '\0'; - if (e > b + u) { + if (b + 1 < e) + *b++ = '\0'; + if (b > e) { WS_Release(hp->ws, 0); return (NULL); } else { + e = b; + b = hp->ws->f; WS_Release(hp->ws, 1 + e - b); return (b); } Modified: branches/1.1/bin/varnishd/flint.lnt =================================================================== --- branches/1.1/bin/varnishd/flint.lnt 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/bin/varnishd/flint.lnt 2007-07-17 10:15:44 UTC (rev 1709) @@ -3,6 +3,12 @@ +libh mgt_event.h +libh ../../config.h +-emacro((???),va_arg) // the va_arg() macro can yield 415, 416, 661, 662 + // 796 and 797 (out-of-bounds errors). +-elib(123) // size is both a variable and a macro with args +-emacro(736, isnan) // isnanf + + -header(../../config.h) // Fix strchr() semtics, it can only return NULL if arg2 != 0 Modified: branches/1.1/bin/varnishd/mgt_child.c =================================================================== --- branches/1.1/bin/varnishd/mgt_child.c 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/bin/varnishd/mgt_child.c 2007-07-17 10:15:44 UTC (rev 1709) @@ -410,6 +410,7 @@ setproctitle("Varnish-Mgr %s", heritage.name); + memset(&sac, 0, sizeof sac); sac.sa_handler = SIG_IGN; sac.sa_flags = SA_RESTART; Modified: branches/1.1/bin/varnishd/storage_file.c =================================================================== --- branches/1.1/bin/varnishd/storage_file.c 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/bin/varnishd/storage_file.c 2007-07-17 10:15:44 UTC (rev 1709) @@ -317,6 +317,7 @@ return; } + asprintf(&q, "%s/varnish.XXXXXX", p); XXXAN(q); sc->fd = mkstemp(q); @@ -331,6 +332,7 @@ XXXAN(sc->filename); free(q); smf_initfile(sc, size, 1); + free(p); } /*-------------------------------------------------------------------- Modified: branches/1.1/lib/libvarnish/cli_common.c =================================================================== --- branches/1.1/lib/libvarnish/cli_common.c 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/lib/libvarnish/cli_common.c 2007-07-17 10:15:44 UTC (rev 1709) @@ -154,6 +154,7 @@ assert(i == CLI_LINE0_LEN); assert(res[3] == ' '); assert(res[CLI_LINE0_LEN - 1] == '\n'); + res[CLI_LINE0_LEN - 1] = '\0'; j = sscanf(res, "%u %u\n", &u, &v); assert(j == 2); if (status != NULL) Modified: branches/1.1/lib/libvcl/vcc_compile.c =================================================================== --- branches/1.1/lib/libvcl/vcc_compile.c 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/lib/libvcl/vcc_compile.c 2007-07-17 10:15:44 UTC (rev 1709) @@ -95,18 +95,26 @@ /*--------------------------------------------------------------------*/ +void +TlFree(struct tokenlist *tl, void *p) +{ + struct membit *mb; + + mb = calloc(sizeof *mb, 1); + assert(mb != NULL); + mb->ptr = p; + TAILQ_INSERT_TAIL(&tl->membits, mb, list); +} + + void * TlAlloc(struct tokenlist *tl, unsigned len) { - struct membit *mb; void *p; p = calloc(len, 1); assert(p != NULL); - mb = calloc(sizeof *mb, 1); - assert(mb != NULL); - mb->ptr = p; - TAILQ_INSERT_TAIL(&tl->membits, mb, list); + TlFree(tl, p); return (p); } @@ -370,6 +378,8 @@ vcc_destroy_source(struct source *sp) { + if (sp->freeit != NULL) + free(sp->freeit); free(sp->name); free(sp); } @@ -382,6 +392,7 @@ char *f; int i; struct stat st; + struct source *sp; if (fd < 0) { fd = open(fn, O_RDONLY); @@ -398,7 +409,9 @@ assert(i == st.st_size); close(fd); f[i] = '\0'; - return (vcc_new_source(f, f + i, fn)); + sp = vcc_new_source(f, f + i, fn); + sp->freeit = f; + return (sp); } /*--------------------------------------------------------------------*/ @@ -501,6 +514,7 @@ vcc_DestroyTokenList(struct tokenlist *tl, char *ret) { struct membit *mb; + struct source *sp; int i; while (!TAILQ_EMPTY(&tl->membits)) { @@ -509,6 +523,11 @@ free(mb->ptr); free(mb); } + while (!TAILQ_EMPTY(&tl->sources)) { + sp = TAILQ_FIRST(&tl->sources); + TAILQ_REMOVE(&tl->sources, sp, list); + vcc_destroy_source(sp); + } vsb_delete(tl->fh); vsb_delete(tl->fc); @@ -645,7 +664,6 @@ if (sp == NULL) return (NULL); r = vcc_CompileSource(sb, sp); - vcc_destroy_source(sp); return (r); } @@ -664,7 +682,6 @@ if (sp == NULL) return (NULL); r = vcc_CompileSource(sb, sp); - vcc_destroy_source(sp); return (r); } Modified: branches/1.1/lib/libvcl/vcc_compile.h =================================================================== --- branches/1.1/lib/libvcl/vcc_compile.h 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/lib/libvcl/vcc_compile.h 2007-07-17 10:15:44 UTC (rev 1709) @@ -45,6 +45,7 @@ const char *b; const char *e; unsigned idx; + char *freeit; }; struct token { @@ -153,6 +154,7 @@ void Ff(const struct tokenlist *tl, int indent, const char *fmt, ...); void EncToken(struct vsb *sb, const struct token *t); int IsMethod(const struct token *t); +void TlFree(struct tokenlist *tl, void *p); void *TlAlloc(struct tokenlist *tl, unsigned len); /* vcc_obj.c */ Modified: branches/1.1/lib/libvcl/vcc_token.c =================================================================== --- branches/1.1/lib/libvcl/vcc_token.c 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/lib/libvcl/vcc_token.c 2007-07-17 10:15:44 UTC (rev 1709) @@ -209,7 +209,7 @@ unsigned char u; assert(tl->t->tok == CSTR); - tl->t->dec = malloc((tl->t->e - tl->t->b) - 1); + tl->t->dec = TlAlloc(tl, (tl->t->e - tl->t->b) - 1); assert(tl->t->dec != NULL); q = tl->t->dec; for (p = tl->t->b + 1; p < tl->t->e - 1; ) { @@ -255,7 +255,7 @@ { struct token *t; - t = calloc(sizeof *t, 1); + t = TlAlloc(tl, sizeof *t); assert(t != NULL); t->tok = tok; t->b = b; Modified: branches/1.1/lib/libvcl/vcc_var.c =================================================================== --- branches/1.1/lib/libvcl/vcc_var.c 2007-07-16 13:06:42 UTC (rev 1708) +++ branches/1.1/lib/libvcl/vcc_var.c 2007-07-17 10:15:44 UTC (rev 1709) @@ -64,10 +64,12 @@ asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); + TlFree(tl, p); v->rname = p; asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr, (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len); AN(p); + TlFree(tl, p); v->lname = p; return (v); } From des at projects.linpro.no Tue Jul 17 10:33:46 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 17 Jul 2007 12:33:46 +0200 (CEST) Subject: r1710 - trunk/varnish-cache/bin/varnishd Message-ID: <20070717103346.822B31EC2A3@projects.linpro.no> Author: des Date: 2007-07-17 12:33:46 +0200 (Tue, 17 Jul 2007) New Revision: 1710 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: Fix child restart by always calling close_sockets() when the child dies; otherwise open_sockets() fails, which causes start_child() to fail silently. Furthermore, if open_sockets() fails and child_state is CH_DIED, it will not be possible to start it manually later; therefore, set child_state to CH_STOPPED when open_sockets() fails. Note: it wouldn't hurt if open_sockets() were a little more talkative. Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-17 10:15:44 UTC (rev 1709) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-17 10:33:46 UTC (rev 1710) @@ -174,8 +174,10 @@ if (child_state != CH_STOPPED && child_state != CH_DIED) return; - if (open_sockets()) + if (open_sockets()) { + child_state = CH_STOPPED; return; /* XXX ?? */ + } child_state = CH_STARTING; @@ -336,12 +338,11 @@ child_fds[0] = -1; fprintf(stderr, "Child cleaned\n"); + close_sockets(); if (child_state == CH_DIED && params->auto_restart) start_child(); - else if (child_state == CH_DIED) { - close_sockets(); + else if (child_state == CH_DIED) child_state = CH_STOPPED; - } else if (child_state == CH_STOPPING) child_state = CH_STOPPED; return (0); From des at projects.linpro.no Tue Jul 17 13:05:08 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 17 Jul 2007 15:05:08 +0200 (CEST) Subject: r1711 - trunk/varnish-cache/bin/varnishd Message-ID: <20070717130508.8120D1EC1F6@projects.linpro.no> Author: des Date: 2007-07-17 15:05:08 +0200 (Tue, 17 Jul 2007) New Revision: 1711 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: Amend previous commit. The problem was that when a socket was already open, open_sockets() did not count it as "good". Having fixed this, revert to the previous behaviour of keeping the sockets open if auto_restart is on; this avoids having a brief window (until they are reopened) during which client connections are refused. Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-17 10:33:46 UTC (rev 1710) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-17 13:05:08 UTC (rev 1711) @@ -130,8 +130,10 @@ int good = 0; TAILQ_FOREACH_SAFE(ls, &heritage.socks, list, ls2) { - if (ls->sock >= 0) + if (ls->sock >= 0) { + good++; continue; + } ls->sock = VSS_listen(ls->addr, params->listen_depth); if (ls->sock < 0) { TAILQ_REMOVE(&heritage.socks, ls, list); @@ -174,7 +176,7 @@ if (child_state != CH_STOPPED && child_state != CH_DIED) return; - if (open_sockets()) { + if (open_sockets() != 0) { child_state = CH_STOPPED; return; /* XXX ?? */ } @@ -338,12 +340,12 @@ child_fds[0] = -1; fprintf(stderr, "Child cleaned\n"); - close_sockets(); if (child_state == CH_DIED && params->auto_restart) start_child(); - else if (child_state == CH_DIED) + else if (child_state == CH_DIED) { + close_sockets(); child_state = CH_STOPPED; - else if (child_state == CH_STOPPING) + } else if (child_state == CH_STOPPING) child_state = CH_STOPPED; return (0); } From des at projects.linpro.no Tue Jul 17 16:56:21 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 17 Jul 2007 18:56:21 +0200 (CEST) Subject: r1712 - trunk/varnish-cache/bin/varnishd Message-ID: <20070717165621.EDF943BC01E@projects.linpro.no> Author: des Date: 2007-07-17 18:56:21 +0200 (Tue, 17 Jul 2007) New Revision: 1712 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c Log: Remove object from LRU list before freeing it; this does not entirely eliminate races between the LRU code and the expiry code, but it does make them a lot less likely. Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-07-17 13:05:08 UTC (rev 1711) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-07-17 16:56:21 UTC (rev 1712) @@ -259,6 +259,7 @@ if (o->vary != NULL) free(o->vary); + LRU_Remove(o); HSH_Freestore(o); FREE_OBJ(o); VSL_stats->n_object--; From des at projects.linpro.no Tue Jul 17 16:58:40 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 17 Jul 2007 18:58:40 +0200 (CEST) Subject: r1713 - trunk/varnish-cache/bin/varnishd Message-ID: <20070717165840.333AF1EC2A3@projects.linpro.no> Author: des Date: 2007-07-17 18:58:40 +0200 (Tue, 17 Jul 2007) New Revision: 1713 Modified: trunk/varnish-cache/bin/varnishd/cache_lru.c Log: Return count like the comment says we do. Modified: trunk/varnish-cache/bin/varnishd/cache_lru.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_lru.c 2007-07-17 16:56:21 UTC (rev 1712) +++ trunk/varnish-cache/bin/varnishd/cache_lru.c 2007-07-17 16:58:40 UTC (rev 1713) @@ -161,7 +161,7 @@ } } UNLOCK(&lru_mtx); - return (0); + return (count); } /* From des at projects.linpro.no Tue Jul 17 17:06:12 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 17 Jul 2007 19:06:12 +0200 (CEST) Subject: r1714 - trunk/varnish-cache/bin/varnishd Message-ID: <20070717170612.F0C8A1EC1F6@projects.linpro.no> Author: des Date: 2007-07-17 19:06:12 +0200 (Tue, 17 Jul 2007) New Revision: 1714 Modified: trunk/varnish-cache/bin/varnishd/stevedore.c Log: Assert that LRU_DiscardOne() returns 1, to avoid an unlikely but possible scenario where multiple clients each require different objects such that the sum of the sizes of the objects is larger than the cache (or, in the extreme case, one client requests an object which is larger than the cache) causing STV_alloc() to enter an infinite loop. This is not ideal - a better solution would be return NULL and have the caller deal with the problem, possibly by returning a 503 result, or by stalling the request for some time. Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-17 16:58:40 UTC (rev 1713) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-17 17:06:12 UTC (rev 1714) @@ -39,7 +39,7 @@ AN(stevedore->alloc); do { if ((st = stevedore->alloc(stevedore, size)) == NULL) - LRU_DiscardOne(); + AN(LRU_DiscardOne()); } while (st == NULL); return (st); } From des at projects.linpro.no Thu Jul 19 10:58:32 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 19 Jul 2007 12:58:32 +0200 (CEST) Subject: r1715 - trunk/varnish-cache/bin/varnishstat Message-ID: <20070719105832.063D61EC21D@projects.linpro.no> Author: des Date: 2007-07-19 12:58:31 +0200 (Thu, 19 Jul 2007) New Revision: 1715 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c Log: gettimeofday() is good enough for varnishstat. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-07-17 17:06:12 UTC (rev 1714) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-07-19 10:58:31 UTC (rev 1715) @@ -32,6 +32,8 @@ * Log tailer for Varnish */ +#include + #include #include #include @@ -42,10 +44,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "libvarnish.h" #include "shmlog.h" #include "varnishapi.h" @@ -64,7 +62,7 @@ { struct varnish_stats copy; intmax_t ju; - struct timespec ts; + struct timeval tv; double tt, lt, hit, miss, ratio, up; double a1, a2, a3; unsigned n1, n2, n3; @@ -86,11 +84,11 @@ lt = 0; while (1) { - clock_gettime(CLOCK_REALTIME, &ts); - tt = ts.tv_nsec * 1e-9 + ts.tv_sec; + gettimeofday(&tv, NULL); + tt = tv.tv_usec * 1e-6 + tv.tv_sec; lt = tt - lt; - rt = ts.tv_sec - VSL_stats->start_time; + rt = tv.tv_sec - VSL_stats->start_time; up = rt; mvprintw(0, 0, "%*s", COLS - 1, VSL_Name()); From des at projects.linpro.no Thu Jul 19 11:01:36 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 19 Jul 2007 13:01:36 +0200 (CEST) Subject: r1716 - trunk/varnish-cache/lib/libvarnish Message-ID: <20070719110136.EAA731EC1F6@projects.linpro.no> Author: des Date: 2007-07-19 13:01:36 +0200 (Thu, 19 Jul 2007) New Revision: 1716 Modified: trunk/varnish-cache/lib/libvarnish/time.c Log: If clock_gettime() is not available, use gettimeofday() directly. Modified: trunk/varnish-cache/lib/libvarnish/time.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/time.c 2007-07-19 10:58:31 UTC (rev 1715) +++ trunk/varnish-cache/lib/libvarnish/time.c 2007-07-19 11:01:36 UTC (rev 1716) @@ -46,32 +46,44 @@ * */ +#include + #include #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "libvarnish.h" double TIM_mono(void) { +#ifdef HAVE_CLOCK_GETTIME struct timespec ts; assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); return (ts.tv_sec + 1e-9 * ts.tv_nsec); +#else + struct timeval tv; + + assert(gettimeofday(&tv, NULL) == 0); + return (tv.tv_sec + 1e-6 * tv.tv_usec); +#endif } double TIM_real(void) { +#ifdef HAVE_CLOCK_GETTIME struct timespec ts; assert(clock_gettime(CLOCK_REALTIME, &ts) == 0); return (ts.tv_sec + 1e-9 * ts.tv_nsec); +#else + struct timeval tv; + + assert(gettimeofday(&tv, NULL) == 0); + return (tv.tv_sec + 1e-6 * tv.tv_usec); +#endif } void @@ -85,9 +97,10 @@ /* XXX: add statistics ? */ static const char *fmts[] = { - "%a, %d %b %Y %T GMT", /* RFC 822 & RFC1123 */ - "%A, %d-%b-%y %T GMT", /* RFC850 */ + "%a, %d %b %Y %T GMT", /* RFC 822 & RFC 1123 */ + "%A, %d-%b-%y %T GMT", /* RFC 850 */ "%a %b %d %T %Y", /* ANSI-C asctime() */ + "%F %T", /* ISO 8601 */ NULL }; From des at projects.linpro.no Thu Jul 19 11:02:57 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 19 Jul 2007 13:02:57 +0200 (CEST) Subject: r1717 - in trunk/varnish-cache: include include/compat lib/libcompat Message-ID: <20070719110257.ED0421EC429@projects.linpro.no> Author: des Date: 2007-07-19 13:02:57 +0200 (Thu, 19 Jul 2007) New Revision: 1717 Removed: trunk/varnish-cache/include/compat/clock_gettime.h trunk/varnish-cache/lib/libcompat/clock_gettime.c Modified: trunk/varnish-cache/include/Makefile.am trunk/varnish-cache/lib/libcompat/Makefile.am Log: Retire libcompat's clock_gettime(). Modified: trunk/varnish-cache/include/Makefile.am =================================================================== --- trunk/varnish-cache/include/Makefile.am 2007-07-19 11:01:36 UTC (rev 1716) +++ trunk/varnish-cache/include/Makefile.am 2007-07-19 11:02:57 UTC (rev 1717) @@ -13,7 +13,6 @@ cli_common.h \ cli_priv.h \ compat/asprintf.h \ - compat/clock_gettime.h \ compat/setproctitle.h \ compat/srandomdev.h \ compat/strlcat.h \ Deleted: trunk/varnish-cache/include/compat/clock_gettime.h =================================================================== --- trunk/varnish-cache/include/compat/clock_gettime.h 2007-07-19 11:01:36 UTC (rev 1716) +++ trunk/varnish-cache/include/compat/clock_gettime.h 2007-07-19 11:02:57 UTC (rev 1717) @@ -1,44 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2007 Linpro AS - * All rights reserved. - * - * Author: Dag-Erling Sm?rgrav - * - * 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. - * - * $Id$ - */ - -#ifndef COMPAT_CLOCK_GETTIME_H_INCLUDED -#define COMPAT_CLOCK_GETTIME_H_INCLUDED - -#ifndef HAVE_CLOCK_GETTIME -typedef enum { - CLOCK_REALTIME, - CLOCK_MONOTONIC, -} clockid_t; - -int clock_gettime(clockid_t clk_id, struct timespec *tp); -#endif - -#endif Modified: trunk/varnish-cache/lib/libcompat/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libcompat/Makefile.am 2007-07-19 11:01:36 UTC (rev 1716) +++ trunk/varnish-cache/lib/libcompat/Makefile.am 2007-07-19 11:02:57 UTC (rev 1717) @@ -6,7 +6,6 @@ libcompat_a_SOURCES = \ asprintf.c \ - clock_gettime.c \ vasprintf.c \ setproctitle.c \ srandomdev.c \ Deleted: trunk/varnish-cache/lib/libcompat/clock_gettime.c =================================================================== --- trunk/varnish-cache/lib/libcompat/clock_gettime.c 2007-07-19 11:01:36 UTC (rev 1716) +++ trunk/varnish-cache/lib/libcompat/clock_gettime.c 2007-07-19 11:02:57 UTC (rev 1717) @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2007 Linpro AS - * All rights reserved. - * - * Author: Dag-Erling Sm?rgrav - * - * 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. - * - * $Id$ - * - */ - -#ifndef HAVE_CLOCK_GETTIME - -#include - -#include -#include - -#include "compat/clock_gettime.h" - -int -clock_gettime(clockid_t clk_id, struct timespec *tp) -{ - struct timeval tv; - - switch (clk_id) { - case CLOCK_REALTIME: - case CLOCK_MONOTONIC: - if (gettimeofday(&tv, NULL) != 0) - return (-1); - tp->tv_sec = tv.tv_sec; - tp->tv_nsec = tv.tv_usec * 1000; - return (0); - default: - errno = EINVAL; - return (-1); - } -} -#endif From des at projects.linpro.no Thu Jul 19 11:03:55 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 19 Jul 2007 13:03:55 +0200 (CEST) Subject: r1718 - trunk/varnish-cache/bin/varnishstat Message-ID: <20070719110355.AF8B51EC1F6@projects.linpro.no> Author: des Date: 2007-07-19 13:03:55 +0200 (Thu, 19 Jul 2007) New Revision: 1718 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c Log: Missed one occurrence of clock_gettime(). Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-07-19 11:02:57 UTC (rev 1717) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-07-19 11:03:55 UTC (rev 1718) @@ -158,11 +158,11 @@ static void do_once(struct varnish_stats *VSL_stats) { - struct timespec ts; + struct timeval tv; double up; - clock_gettime(CLOCK_REALTIME, &ts); - up = ts.tv_sec - VSL_stats->start_time; + gettimeofday(&tv, NULL); + up = tv.tv_sec - VSL_stats->start_time; #define MAC_STAT(n, t, f, d) \ do { \ From des at projects.linpro.no Thu Jul 19 11:11:20 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 19 Jul 2007 13:11:20 +0200 (CEST) Subject: r1719 - trunk/varnish-cache/lib/libvcl Message-ID: <20070719111120.AE9E91EC21D@projects.linpro.no> Author: des Date: 2007-07-19 13:11:20 +0200 (Thu, 19 Jul 2007) New Revision: 1719 Modified: trunk/varnish-cache/lib/libvcl/vcc_string.c Log: Make regexp variables static. This has the side effect of replacing tentative definitions with non-tentative ones, thus sidestepping one of the issues we have on MacOS X. Modified: trunk/varnish-cache/lib/libvcl/vcc_string.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_string.c 2007-07-19 11:03:55 UTC (rev 1718) +++ trunk/varnish-cache/lib/libvcl/vcc_string.c 2007-07-19 11:11:20 UTC (rev 1719) @@ -56,7 +56,7 @@ p = TlAlloc(tl, strlen(buf) + 1); strcpy(p, buf); - Fh(tl, 0, "void *%s;\n", buf); + Fh(tl, 0, "static void *%s;\n", buf); Fi(tl, 0, "\tVRT_re_init(&%s, ",buf); EncToken(tl->fi, tl->t); Fi(tl, 0, ", %d);\n", sub); From des at projects.linpro.no Thu Jul 19 11:17:59 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 19 Jul 2007 13:17:59 +0200 (CEST) Subject: r1720 - trunk/varnish-cache Message-ID: <20070719111759.B37111EC429@projects.linpro.no> Author: des Date: 2007-07-19 13:17:59 +0200 (Thu, 19 Jul 2007) New Revision: 1720 Modified: trunk/varnish-cache/autogen.sh Log: Adapt for use on MacOS X / Darwin, which has GNU libtool installed as glibtool, and has a version of automake 1.6 which does not exhibit the bug I've observed on other platforms. Modified: trunk/varnish-cache/autogen.sh =================================================================== --- trunk/varnish-cache/autogen.sh 2007-07-19 11:11:20 UTC (rev 1719) +++ trunk/varnish-cache/autogen.sh 2007-07-19 11:17:59 UTC (rev 1720) @@ -3,22 +3,34 @@ # $Id$ # -if [ -d /usr/local/gnu-autotools/bin ] ; then - PATH=/usr/local/gnu-autotools/bin:${PATH} - export PATH - FIX_BROKEN_FREEBSD_PORTS="-I /usr/local/share/aclocal" -fi +warn() { + echo "WARNING: $@" 1>&2 +} +case `uname -s` in +Darwin) + LIBTOOLIZE=glibtoolize + ;; +FreeBSD) + LIBTOOLIZE=libtoolize + if [ -d /usr/local/gnu-autotools/bin ] ; then + PATH=/usr/local/gnu-autotools/bin:${PATH} + export PATH + FIX_BROKEN_FREEBSD_PORTS="-I /usr/local/share/aclocal" + fi + ;; +Linux) + LIBTOOLIZE=libtoolize + ;; +esac + automake_version=$(automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+') if [ -z "$automake_version" ] ; then - echo "unable to determine automake version" - exit 1 + warn "unable to determine automake version" else case $automake_version in 0.*|1.[0-8]|1.[0-8][.-]*) - echo "your version of automake ($automake_version) is too old;" \ - "you need 1.9 or newer." - exit 1 + warn "automake ($automake_version) detected; 1.9 or newer recommended" ;; *) ;; @@ -28,7 +40,7 @@ set -ex aclocal ${FIX_BROKEN_FREEBSD_PORTS} -libtoolize --copy --force +$LIBTOOLIZE --copy --force autoheader automake --add-missing --copy --foreign autoconf From des at projects.linpro.no Thu Jul 19 11:49:43 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 19 Jul 2007 13:49:43 +0200 (CEST) Subject: r1721 - trunk/varnish-cache/bin/varnishd Message-ID: <20070719114943.5C0A41EC21D@projects.linpro.no> Author: des Date: 2007-07-19 13:49:43 +0200 (Thu, 19 Jul 2007) New Revision: 1721 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Use the correct cc command line on MacOS. This is a gross hack. Also, ignore the result of dlclose(). Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-07-19 11:17:59 UTC (rev 1720) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-07-19 11:49:43 UTC (rev 1721) @@ -181,7 +181,11 @@ /* Attempt to open a pipe to the system C-compiler */ len = snprintf(buf, sizeof buf, "ln -f %s _.c ;" /* XXX: for debugging */ +#ifdef __APPLE__ + "exec cc -dynamiclib -Wl,-flat_namespace,-undefined,suppress -o %s -x c - < %s 2>&1", +#else "exec cc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1", +#endif sf, of, sf); xxxassert(len < sizeof buf); @@ -229,7 +233,7 @@ free(of); of = NULL; } else - AZ(dlclose(p)); + (void)dlclose(p); /* clean up and return */ unlink(sf); From des at projects.linpro.no Thu Jul 19 12:18:57 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 19 Jul 2007 14:18:57 +0200 (CEST) Subject: r1722 - trunk/varnish-cache/doc Message-ID: <20070719121857.33DE51EC1F6@projects.linpro.no> Author: des Date: 2007-07-19 14:18:57 +0200 (Thu, 19 Jul 2007) New Revision: 1722 Modified: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml Log: Document Mac OS X compatibility. Modified: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.0.4-1.1.xml 2007-07-19 11:49:43 UTC (rev 1721) +++ trunk/varnish-cache/doc/changes-1.0.4-1.1.xml 2007-07-19 12:18:57 UTC (rev 1722) @@ -178,6 +178,10 @@ A new management command, status, returns the state of the child. + + + Varnish will now build and run on Mac OS X. + From des at projects.linpro.no Thu Jul 19 12:20:28 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 19 Jul 2007 14:20:28 +0200 (CEST) Subject: r1723 - in branches/1.1: . bin/varnishd bin/varnishstat doc include include/compat lib/libcompat lib/libvarnish lib/libvcl Message-ID: <20070719122028.BBC621EC21D@projects.linpro.no> Author: des Date: 2007-07-19 14:20:28 +0200 (Thu, 19 Jul 2007) New Revision: 1723 Removed: branches/1.1/include/compat/clock_gettime.h branches/1.1/lib/libcompat/clock_gettime.c Modified: branches/1.1/ branches/1.1/autogen.sh branches/1.1/bin/varnishd/cache_hash.c branches/1.1/bin/varnishd/cache_lru.c branches/1.1/bin/varnishd/mgt_child.c branches/1.1/bin/varnishd/mgt_vcc.c branches/1.1/bin/varnishd/stevedore.c branches/1.1/bin/varnishstat/varnishstat.c branches/1.1/doc/changes-1.0.4-1.1.xml branches/1.1/include/Makefile.am branches/1.1/lib/libcompat/Makefile.am branches/1.1/lib/libvarnish/time.c branches/1.1/lib/libvcl/vcc_string.c Log: Merged revisions 1709-1722 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1710 | des | 2007-07-17 12:33:46 +0200 (Tue, 17 Jul 2007) | 9 lines Fix child restart by always calling close_sockets() when the child dies; otherwise open_sockets() fails, which causes start_child() to fail silently. Furthermore, if open_sockets() fails and child_state is CH_DIED, it will not be possible to start it manually later; therefore, set child_state to CH_STOPPED when open_sockets() fails. Note: it wouldn't hurt if open_sockets() were a little more talkative. ........ r1711 | des | 2007-07-17 15:05:08 +0200 (Tue, 17 Jul 2007) | 6 lines Amend previous commit. The problem was that when a socket was already open, open_sockets() did not count it as "good". Having fixed this, revert to the previous behaviour of keeping the sockets open if auto_restart is on; this avoids having a brief window (until they are reopened) during which client connections are refused. ........ r1712 | des | 2007-07-17 18:56:21 +0200 (Tue, 17 Jul 2007) | 4 lines Remove object from LRU list before freeing it; this does not entirely eliminate races between the LRU code and the expiry code, but it does make them a lot less likely. ........ r1713 | des | 2007-07-17 18:58:40 +0200 (Tue, 17 Jul 2007) | 2 lines Return count like the comment says we do. ........ r1714 | des | 2007-07-17 19:06:12 +0200 (Tue, 17 Jul 2007) | 10 lines Assert that LRU_DiscardOne() returns 1, to avoid an unlikely but possible scenario where multiple clients each require different objects such that the sum of the sizes of the objects is larger than the cache (or, in the extreme case, one client requests an object which is larger than the cache) causing STV_alloc() to enter an infinite loop. This is not ideal - a better solution would be return NULL and have the caller deal with the problem, possibly by returning a 503 result, or by stalling the request for some time. ........ r1715 | des | 2007-07-19 12:58:31 +0200 (Thu, 19 Jul 2007) | 2 lines gettimeofday() is good enough for varnishstat. ........ r1716 | des | 2007-07-19 13:01:36 +0200 (Thu, 19 Jul 2007) | 2 lines If clock_gettime() is not available, use gettimeofday() directly. ........ r1717 | des | 2007-07-19 13:02:57 +0200 (Thu, 19 Jul 2007) | 2 lines Retire libcompat's clock_gettime(). ........ r1718 | des | 2007-07-19 13:03:55 +0200 (Thu, 19 Jul 2007) | 2 lines Missed one occurrence of clock_gettime(). ........ r1719 | des | 2007-07-19 13:11:20 +0200 (Thu, 19 Jul 2007) | 4 lines Make regexp variables static. This has the side effect of replacing tentative definitions with non-tentative ones, thus sidestepping one of the issues we have on MacOS X. ........ r1720 | des | 2007-07-19 13:17:59 +0200 (Thu, 19 Jul 2007) | 4 lines Adapt for use on MacOS X / Darwin, which has GNU libtool installed as glibtool, and has a version of automake 1.6 which does not exhibit the bug I've observed on other platforms. ........ r1721 | des | 2007-07-19 13:49:43 +0200 (Thu, 19 Jul 2007) | 3 lines Use the correct cc command line on MacOS. This is a gross hack. Also, ignore the result of dlclose(). ........ r1722 | des | 2007-07-19 14:18:57 +0200 (Thu, 19 Jul 2007) | 2 lines Document Mac OS X compatibility. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1708 + /trunk/varnish-cache:1-1722 Modified: branches/1.1/autogen.sh =================================================================== --- branches/1.1/autogen.sh 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/autogen.sh 2007-07-19 12:20:28 UTC (rev 1723) @@ -3,22 +3,34 @@ # $Id$ # -if [ -d /usr/local/gnu-autotools/bin ] ; then - PATH=/usr/local/gnu-autotools/bin:${PATH} - export PATH - FIX_BROKEN_FREEBSD_PORTS="-I /usr/local/share/aclocal" -fi +warn() { + echo "WARNING: $@" 1>&2 +} +case `uname -s` in +Darwin) + LIBTOOLIZE=glibtoolize + ;; +FreeBSD) + LIBTOOLIZE=libtoolize + if [ -d /usr/local/gnu-autotools/bin ] ; then + PATH=/usr/local/gnu-autotools/bin:${PATH} + export PATH + FIX_BROKEN_FREEBSD_PORTS="-I /usr/local/share/aclocal" + fi + ;; +Linux) + LIBTOOLIZE=libtoolize + ;; +esac + automake_version=$(automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+') if [ -z "$automake_version" ] ; then - echo "unable to determine automake version" - exit 1 + warn "unable to determine automake version" else case $automake_version in 0.*|1.[0-8]|1.[0-8][.-]*) - echo "your version of automake ($automake_version) is too old;" \ - "you need 1.9 or newer." - exit 1 + warn "automake ($automake_version) detected; 1.9 or newer recommended" ;; *) ;; @@ -28,7 +40,7 @@ set -ex aclocal ${FIX_BROKEN_FREEBSD_PORTS} -libtoolize --copy --force +$LIBTOOLIZE --copy --force autoheader automake --add-missing --copy --foreign autoconf Modified: branches/1.1/bin/varnishd/cache_hash.c =================================================================== --- branches/1.1/bin/varnishd/cache_hash.c 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/bin/varnishd/cache_hash.c 2007-07-19 12:20:28 UTC (rev 1723) @@ -259,6 +259,7 @@ if (o->vary != NULL) free(o->vary); + LRU_Remove(o); HSH_Freestore(o); FREE_OBJ(o); VSL_stats->n_object--; Modified: branches/1.1/bin/varnishd/cache_lru.c =================================================================== --- branches/1.1/bin/varnishd/cache_lru.c 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/bin/varnishd/cache_lru.c 2007-07-19 12:20:28 UTC (rev 1723) @@ -161,7 +161,7 @@ } } UNLOCK(&lru_mtx); - return (0); + return (count); } /* Modified: branches/1.1/bin/varnishd/mgt_child.c =================================================================== --- branches/1.1/bin/varnishd/mgt_child.c 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/bin/varnishd/mgt_child.c 2007-07-19 12:20:28 UTC (rev 1723) @@ -130,8 +130,10 @@ int good = 0; TAILQ_FOREACH_SAFE(ls, &heritage.socks, list, ls2) { - if (ls->sock >= 0) + if (ls->sock >= 0) { + good++; continue; + } ls->sock = VSS_listen(ls->addr, params->listen_depth); if (ls->sock < 0) { TAILQ_REMOVE(&heritage.socks, ls, list); @@ -174,8 +176,10 @@ if (child_state != CH_STOPPED && child_state != CH_DIED) return; - if (open_sockets()) + if (open_sockets() != 0) { + child_state = CH_STOPPED; return; /* XXX ?? */ + } child_state = CH_STARTING; @@ -341,8 +345,7 @@ else if (child_state == CH_DIED) { close_sockets(); child_state = CH_STOPPED; - } - else if (child_state == CH_STOPPING) + } else if (child_state == CH_STOPPING) child_state = CH_STOPPED; return (0); } Modified: branches/1.1/bin/varnishd/mgt_vcc.c =================================================================== --- branches/1.1/bin/varnishd/mgt_vcc.c 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/bin/varnishd/mgt_vcc.c 2007-07-19 12:20:28 UTC (rev 1723) @@ -181,7 +181,11 @@ /* Attempt to open a pipe to the system C-compiler */ len = snprintf(buf, sizeof buf, "ln -f %s _.c ;" /* XXX: for debugging */ +#ifdef __APPLE__ + "exec cc -dynamiclib -Wl,-flat_namespace,-undefined,suppress -o %s -x c - < %s 2>&1", +#else "exec cc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1", +#endif sf, of, sf); xxxassert(len < sizeof buf); @@ -229,7 +233,7 @@ free(of); of = NULL; } else - AZ(dlclose(p)); + (void)dlclose(p); /* clean up and return */ unlink(sf); Modified: branches/1.1/bin/varnishd/stevedore.c =================================================================== --- branches/1.1/bin/varnishd/stevedore.c 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/bin/varnishd/stevedore.c 2007-07-19 12:20:28 UTC (rev 1723) @@ -39,7 +39,7 @@ AN(stevedore->alloc); do { if ((st = stevedore->alloc(stevedore, size)) == NULL) - LRU_DiscardOne(); + AN(LRU_DiscardOne()); } while (st == NULL); return (st); } Modified: branches/1.1/bin/varnishstat/varnishstat.c =================================================================== --- branches/1.1/bin/varnishstat/varnishstat.c 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/bin/varnishstat/varnishstat.c 2007-07-19 12:20:28 UTC (rev 1723) @@ -32,6 +32,8 @@ * Log tailer for Varnish */ +#include + #include #include #include @@ -42,10 +44,6 @@ #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "libvarnish.h" #include "shmlog.h" #include "varnishapi.h" @@ -64,7 +62,7 @@ { struct varnish_stats copy; intmax_t ju; - struct timespec ts; + struct timeval tv; double tt, lt, hit, miss, ratio, up; double a1, a2, a3; unsigned n1, n2, n3; @@ -86,11 +84,11 @@ lt = 0; while (1) { - clock_gettime(CLOCK_REALTIME, &ts); - tt = ts.tv_nsec * 1e-9 + ts.tv_sec; + gettimeofday(&tv, NULL); + tt = tv.tv_usec * 1e-6 + tv.tv_sec; lt = tt - lt; - rt = ts.tv_sec - VSL_stats->start_time; + rt = tv.tv_sec - VSL_stats->start_time; up = rt; mvprintw(0, 0, "%*s", COLS - 1, VSL_Name()); @@ -160,11 +158,11 @@ static void do_once(struct varnish_stats *VSL_stats) { - struct timespec ts; + struct timeval tv; double up; - clock_gettime(CLOCK_REALTIME, &ts); - up = ts.tv_sec - VSL_stats->start_time; + gettimeofday(&tv, NULL); + up = tv.tv_sec - VSL_stats->start_time; #define MAC_STAT(n, t, f, d) \ do { \ Modified: branches/1.1/doc/changes-1.0.4-1.1.xml =================================================================== --- branches/1.1/doc/changes-1.0.4-1.1.xml 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/doc/changes-1.0.4-1.1.xml 2007-07-19 12:20:28 UTC (rev 1723) @@ -178,6 +178,10 @@ A new management command, status, returns the state of the child. + + + Varnish will now build and run on Mac OS X. + Modified: branches/1.1/include/Makefile.am =================================================================== --- branches/1.1/include/Makefile.am 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/include/Makefile.am 2007-07-19 12:20:28 UTC (rev 1723) @@ -13,7 +13,6 @@ cli_common.h \ cli_priv.h \ compat/asprintf.h \ - compat/clock_gettime.h \ compat/setproctitle.h \ compat/srandomdev.h \ compat/strlcat.h \ Deleted: branches/1.1/include/compat/clock_gettime.h =================================================================== --- branches/1.1/include/compat/clock_gettime.h 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/include/compat/clock_gettime.h 2007-07-19 12:20:28 UTC (rev 1723) @@ -1,44 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2007 Linpro AS - * All rights reserved. - * - * Author: Dag-Erling Sm?rgrav - * - * 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. - * - * $Id$ - */ - -#ifndef COMPAT_CLOCK_GETTIME_H_INCLUDED -#define COMPAT_CLOCK_GETTIME_H_INCLUDED - -#ifndef HAVE_CLOCK_GETTIME -typedef enum { - CLOCK_REALTIME, - CLOCK_MONOTONIC, -} clockid_t; - -int clock_gettime(clockid_t clk_id, struct timespec *tp); -#endif - -#endif Modified: branches/1.1/lib/libcompat/Makefile.am =================================================================== --- branches/1.1/lib/libcompat/Makefile.am 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/lib/libcompat/Makefile.am 2007-07-19 12:20:28 UTC (rev 1723) @@ -6,7 +6,6 @@ libcompat_a_SOURCES = \ asprintf.c \ - clock_gettime.c \ vasprintf.c \ setproctitle.c \ srandomdev.c \ Deleted: branches/1.1/lib/libcompat/clock_gettime.c =================================================================== --- branches/1.1/lib/libcompat/clock_gettime.c 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/lib/libcompat/clock_gettime.c 2007-07-19 12:20:28 UTC (rev 1723) @@ -1,60 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2007 Linpro AS - * All rights reserved. - * - * Author: Dag-Erling Sm?rgrav - * - * 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. - * - * $Id$ - * - */ - -#ifndef HAVE_CLOCK_GETTIME - -#include - -#include -#include - -#include "compat/clock_gettime.h" - -int -clock_gettime(clockid_t clk_id, struct timespec *tp) -{ - struct timeval tv; - - switch (clk_id) { - case CLOCK_REALTIME: - case CLOCK_MONOTONIC: - if (gettimeofday(&tv, NULL) != 0) - return (-1); - tp->tv_sec = tv.tv_sec; - tp->tv_nsec = tv.tv_usec * 1000; - return (0); - default: - errno = EINVAL; - return (-1); - } -} -#endif Modified: branches/1.1/lib/libvarnish/time.c =================================================================== --- branches/1.1/lib/libvarnish/time.c 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/lib/libvarnish/time.c 2007-07-19 12:20:28 UTC (rev 1723) @@ -46,32 +46,44 @@ * */ +#include + #include #include #include -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - #include "libvarnish.h" double TIM_mono(void) { +#ifdef HAVE_CLOCK_GETTIME struct timespec ts; assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); return (ts.tv_sec + 1e-9 * ts.tv_nsec); +#else + struct timeval tv; + + assert(gettimeofday(&tv, NULL) == 0); + return (tv.tv_sec + 1e-6 * tv.tv_usec); +#endif } double TIM_real(void) { +#ifdef HAVE_CLOCK_GETTIME struct timespec ts; assert(clock_gettime(CLOCK_REALTIME, &ts) == 0); return (ts.tv_sec + 1e-9 * ts.tv_nsec); +#else + struct timeval tv; + + assert(gettimeofday(&tv, NULL) == 0); + return (tv.tv_sec + 1e-6 * tv.tv_usec); +#endif } void @@ -85,9 +97,10 @@ /* XXX: add statistics ? */ static const char *fmts[] = { - "%a, %d %b %Y %T GMT", /* RFC 822 & RFC1123 */ - "%A, %d-%b-%y %T GMT", /* RFC850 */ + "%a, %d %b %Y %T GMT", /* RFC 822 & RFC 1123 */ + "%A, %d-%b-%y %T GMT", /* RFC 850 */ "%a %b %d %T %Y", /* ANSI-C asctime() */ + "%F %T", /* ISO 8601 */ NULL }; Modified: branches/1.1/lib/libvcl/vcc_string.c =================================================================== --- branches/1.1/lib/libvcl/vcc_string.c 2007-07-19 12:18:57 UTC (rev 1722) +++ branches/1.1/lib/libvcl/vcc_string.c 2007-07-19 12:20:28 UTC (rev 1723) @@ -56,7 +56,7 @@ p = TlAlloc(tl, strlen(buf) + 1); strcpy(p, buf); - Fh(tl, 0, "void *%s;\n", buf); + Fh(tl, 0, "static void *%s;\n", buf); Fi(tl, 0, "\tVRT_re_init(&%s, ",buf); EncToken(tl->fi, tl->t); Fi(tl, 0, ", %d);\n", sub); From cecilihf at projects.linpro.no Fri Jul 20 08:16:44 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Fri, 20 Jul 2007 10:16:44 +0200 (CEST) Subject: r1724 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720081644.930F71EC429@projects.linpro.no> Author: cecilihf Date: 2007-07-20 10:16:44 +0200 (Fri, 20 Jul 2007) New Revision: 1724 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_main.c trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/bin/varnishd/stevedore.h trunk/varnish-cache/bin/varnishd/varnishd.c Log: Support for multiple cache files. The selecting of a cache file is done by a simple round-robin that selects the first file in the list, and then moves it to the end. If the selected file hasn't got enough space, the next one is tried. If no file has enough space, the LRU discarding is applied to the first file in the list. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-19 12:20:28 UTC (rev 1723) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-20 08:16:44 UTC (rev 1724) @@ -221,7 +221,7 @@ * XXX: selected by some kind of heuristics based on size, lifetime * XXX: etc etc. For now we support only one. */ -extern struct stevedore *stevedore; +extern struct stevedore_head *stevedore_h; /* -------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2007-07-19 12:20:28 UTC (rev 1723) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2007-07-20 08:16:44 UTC (rev 1724) @@ -38,7 +38,7 @@ #include "shmlog.h" #include "cache.h" -struct stevedore *stevedore; +struct stevedore_head *stevedore_h; /*-------------------------------------------------------------------- * XXX: Think more about which order we start things @@ -47,6 +47,7 @@ void child_main(void) { + struct stevedore *st; setbuf(stdout, NULL); setbuf(stderr, NULL); @@ -66,9 +67,11 @@ HSH_Init(); BAN_Init(); - stevedore = heritage.stevedore; - if (stevedore->open != NULL) - stevedore->open(stevedore); + stevedore_h = &heritage.stevedore_h; + TAILQ_FOREACH(st, stevedore_h, stevedore_list) { + if (st->open != NULL) + st->open(st); + } printf("Ready\n"); VSL_stats->start_time = (time_t)TIM_real(); Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-07-19 12:20:28 UTC (rev 1723) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-07-20 08:16:44 UTC (rev 1724) @@ -40,6 +40,7 @@ }; TAILQ_HEAD(listen_sock_head, listen_sock); +TAILQ_HEAD(stevedore_head, stevedore); struct heritage { @@ -58,7 +59,7 @@ unsigned vsl_size; /* Storage method */ - struct stevedore *stevedore; + struct stevedore_head stevedore_h; /* Hash method */ struct hash_slinger *hash; Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-19 12:20:28 UTC (rev 1723) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 08:16:44 UTC (rev 1724) @@ -28,19 +28,48 @@ * $Id$ */ +#include +#include +#include + #include "cache.h" +#include "heritage.h" +extern struct stevedore sma_stevedore; +extern struct stevedore smf_stevedore; + + struct storage * STV_alloc(size_t size) { struct storage *st; + struct stevedore *stv, *stv_first; - AN(stevedore); - AN(stevedore->alloc); + /* Simple round robin selecting of a stevedore. + */ + stv_first = TAILQ_FIRST(stevedore_h); + stv = stv_first; do { - if ((st = stevedore->alloc(stevedore, size)) == NULL) + AN(stv->alloc); + st = stv->alloc(stv, size); + TAILQ_REMOVE(stevedore_h, stv, stevedore_list); + TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list); + if (st != NULL) + return (st); + } while ((stv = TAILQ_FIRST(stevedore_h)) != stv_first); + + /* No stevedore with enough space is found. Make room in the first + * one in the list, and move it to the end. Ensuring the round-robin. + */ + stv = TAILQ_FIRST(stevedore_h); + TAILQ_REMOVE(stevedore_h, stv, stevedore_list); + TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list); + + do { + if ((st = stv->alloc(stv, size)) == NULL) AN(LRU_DiscardOne()); } while (st == NULL); + return (st); } @@ -58,6 +87,47 @@ { AN(st->stevedore); - AN(stevedore->free); + AN(st->stevedore->free); st->stevedore->free(st); } + +static int +cmp_storage(struct stevedore *s, const char *p, const char *q) +{ + if (strlen(s->name) != q - p) + return (1); + if (strncmp(s->name, p, q - p)) + return (1); + return (0); +} + + +void +STV_add(const char *spec) +{ + const char *p, *q; + struct stevedore *stp; + + p = strchr(spec, ','); + if (p == NULL) + q = p = strchr(spec, '\0'); + else + q = p + 1; + xxxassert(p != NULL); + xxxassert(q != NULL); + + stp = malloc(sizeof *stp); + + if (!cmp_storage(&sma_stevedore, spec, p)) { + *stp = sma_stevedore; + } else if (!cmp_storage(&smf_stevedore, spec, p)) { + *stp = smf_stevedore; + } else { + fprintf(stderr, "Unknown storage method \"%.*s\"\n", + (int)(p - spec), spec); + exit (2); + } + TAILQ_INSERT_HEAD(&heritage.stevedore_h, stp, stevedore_list); + if (stp->init != NULL) + stp->init(stp, q); +} Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2007-07-19 12:20:28 UTC (rev 1723) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2007-07-20 08:16:44 UTC (rev 1724) @@ -28,7 +28,10 @@ * * $Id$ */ + +#include "queue.h" + struct stevedore; struct sess; struct iovec; @@ -49,8 +52,10 @@ /* private fields */ void *priv; + TAILQ_ENTRY(stevedore) stevedore_list; }; struct storage *STV_alloc(size_t size); void STV_trim(struct storage *st, size_t size); void STV_free(struct storage *st); +void STV_add(const char *spec); Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-07-19 12:20:28 UTC (rev 1723) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-07-20 08:16:44 UTC (rev 1724) @@ -120,47 +120,7 @@ /*--------------------------------------------------------------------*/ -static int -cmp_storage(struct stevedore *s, const char *p, const char *q) -{ - if (strlen(s->name) != q - p) - return (1); - if (strncmp(s->name, p, q - p)) - return (1); - return (0); -} - static void -setup_storage(const char *s_arg) -{ - const char *p, *q; - struct stevedore *stp; - - p = strchr(s_arg, ','); - if (p == NULL) - q = p = strchr(s_arg, '\0'); - else - q = p + 1; - xxxassert(p != NULL); - xxxassert(q != NULL); - if (!cmp_storage(&sma_stevedore, s_arg, p)) { - stp = &sma_stevedore; - } else if (!cmp_storage(&smf_stevedore, s_arg, p)) { - stp = &smf_stevedore; - } else { - fprintf(stderr, "Unknown storage method \"%.*s\"\n", - (int)(p - s_arg), s_arg); - exit (2); - } - heritage.stevedore = malloc(sizeof *heritage.stevedore); - *heritage.stevedore = *stp; - if (stp->init != NULL) - stp->init(heritage.stevedore, q); -} - -/*--------------------------------------------------------------------*/ - -static void usage(void) { fprintf(stderr, "usage: varnishd [options]\n"); @@ -416,6 +376,7 @@ const char *n_arg = NULL; const char *P_arg = NULL; const char *s_arg = "file"; + int s_arg_given = 0; const char *T_arg = NULL; char *p; struct cli cli[1]; @@ -431,6 +392,8 @@ cli[0].result = CLIS_OK; TAILQ_INIT(&heritage.socks); + TAILQ_INIT(&heritage.stevedore_h); + mgt_vcc_init(); MCF_ParamInit(cli); @@ -479,7 +442,8 @@ cli_check(cli); break; case 's': - s_arg = optarg; + s_arg_given = 1; + STV_add(optarg); break; case 't': MCF_ParamSet(cli, "default_ttl", optarg); @@ -570,7 +534,9 @@ if (C_flag) exit (0); - setup_storage(s_arg); + if (!s_arg_given) + STV_add(s_arg); + setup_hash(h_arg); VSL_MgtInit(SHMLOG_FILENAME, 8*1024*1024); From cecilihf at projects.linpro.no Fri Jul 20 08:20:59 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Fri, 20 Jul 2007 10:20:59 +0200 (CEST) Subject: r1725 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720082059.C79F91EC418@projects.linpro.no> Author: cecilihf Date: 2007-07-20 10:20:59 +0200 (Fri, 20 Jul 2007) New Revision: 1725 Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 Log: Updated man-page Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2007-07-20 08:16:44 UTC (rev 1724) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2007-07-20 08:20:59 UTC (rev 1725) @@ -155,7 +155,8 @@ Use the specified storage backend. See .Sx Storage Types -for a list of supported storage types. +for a list of supported storage types. Multiple files can be specified +by using this flag for each file. .It Fl T Ar address Ns Op : Ns Ar port Offer a management interface on the specified .Ar address From des at projects.linpro.no Fri Jul 20 08:32:04 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 10:32:04 +0200 (CEST) Subject: r1726 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720083204.3F6CE1EC3F0@projects.linpro.no> Author: des Date: 2007-07-20 10:32:04 +0200 (Fri, 20 Jul 2007) New Revision: 1726 Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 Log: Reword, bump date. Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2007-07-20 08:20:59 UTC (rev 1725) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2007-07-20 08:32:04 UTC (rev 1726) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd July 5, 2007 +.Dd July 20, 2007 .Dt VARNISHD 1 .Os .Sh NAME @@ -155,8 +155,9 @@ Use the specified storage backend. See .Sx Storage Types -for a list of supported storage types. Multiple files can be specified -by using this flag for each file. +for a list of supported storage types. +This option can be used multiple times to specify multiple storage +files. .It Fl T Ar address Ns Op : Ns Ar port Offer a management interface on the specified .Ar address From des at projects.linpro.no Fri Jul 20 08:38:22 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 10:38:22 +0200 (CEST) Subject: r1727 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720083822.3D4B41EC3F0@projects.linpro.no> Author: des Date: 2007-07-20 10:38:22 +0200 (Fri, 20 Jul 2007) New Revision: 1727 Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c Log: Let the LRU code worry about this. Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-07-20 08:32:04 UTC (rev 1726) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2007-07-20 08:38:22 UTC (rev 1727) @@ -82,8 +82,7 @@ EXP_Terminate(struct object *o) { LOCK(&exp_mtx); - if (o->lru_stamp) - LRU_Remove(o); + LRU_Remove(o); if (o->heap_idx) binheap_delete(exp_heap, o->heap_idx); if (o->deathrow.tqe_next) { From des at projects.linpro.no Fri Jul 20 08:39:46 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 10:39:46 +0200 (CEST) Subject: r1728 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720083946.210521EC1F6@projects.linpro.no> Author: des Date: 2007-07-20 10:39:45 +0200 (Fri, 20 Jul 2007) New Revision: 1728 Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c Log: Paranoia. Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-20 08:38:22 UTC (rev 1727) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-07-20 08:39:45 UTC (rev 1728) @@ -46,7 +46,7 @@ rdf(struct pollfd *fds, int idx) { int i, j; - char buf[BUFSIZ]; + char buf[BUFSIZ], *p; i = read(fds[idx].fd, buf, sizeof buf); if (i <= 0 || fds[1-idx].events == 0) { @@ -55,14 +55,17 @@ shutdown(fds[idx].fd, SHUT_RD); shutdown(fds[1-idx].fd, SHUT_WR); fds[idx].events = 0; - } else { - j = write(fds[1-idx].fd, buf, i); - if (i != j) { + return; + } + for (p = buf; i > 0; i -= j, p += j) { + j = write(fds[1-idx].fd, p, i); + if (j < 0) { VSL(SLT_Debug, fds[idx].fd, "Pipe Shut write(write)"); VSL(SLT_Debug, fds[1-idx].fd, "Pipe Shut read(write)"); shutdown(fds[idx].fd, SHUT_WR); shutdown(fds[1-idx].fd, SHUT_RD); fds[1-idx].events = 0; + return; } } } From des at projects.linpro.no Fri Jul 20 08:40:33 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 10:40:33 +0200 (CEST) Subject: r1729 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20070720084033.6C7601EC3F0@projects.linpro.no> Author: des Date: 2007-07-20 10:40:33 +0200 (Fri, 20 Jul 2007) New Revision: 1729 Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/include/stat_field.h Log: Count backend requests. Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-20 08:39:45 UTC (rev 1728) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-20 08:40:33 UTC (rev 1729) @@ -286,6 +286,9 @@ return (1); } + /* XXX is this the right place? */ + VSL_stats->backend_req++; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2007-07-20 08:39:45 UTC (rev 1728) +++ trunk/varnish-cache/include/stat_field.h 2007-07-20 08:40:33 UTC (rev 1729) @@ -89,3 +89,5 @@ MAC_STAT(sm_nobj, uint64_t, 'i', "outstanding allocations") MAC_STAT(sm_balloc, uint64_t, 'i', "bytes allocated") MAC_STAT(sm_bfree, uint64_t, 'i', "bytes free") + +MAC_STAT(backend_req, uint64_t, 'a', "Backend requests made") From cecilihf at projects.linpro.no Fri Jul 20 09:06:42 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Fri, 20 Jul 2007 11:06:42 +0200 (CEST) Subject: r1730 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720090642.882D51EC429@projects.linpro.no> Author: cecilihf Date: 2007-07-20 11:06:42 +0200 (Fri, 20 Jul 2007) New Revision: 1730 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_main.c trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/bin/varnishd/stevedore.h Log: Move all use of the stevedore list to stevedore.c Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-20 08:40:33 UTC (rev 1729) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-20 09:06:42 UTC (rev 1730) @@ -216,13 +216,6 @@ #include "stevedore.h" -/* - * XXX: in the longer term, we want to support multiple stevedores, - * XXX: selected by some kind of heuristics based on size, lifetime - * XXX: etc etc. For now we support only one. - */ -extern struct stevedore_head *stevedore_h; - /* -------------------------------------------------------------------*/ struct object { Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2007-07-20 08:40:33 UTC (rev 1729) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2007-07-20 09:06:42 UTC (rev 1730) @@ -38,7 +38,6 @@ #include "shmlog.h" #include "cache.h" -struct stevedore_head *stevedore_h; /*-------------------------------------------------------------------- * XXX: Think more about which order we start things @@ -47,8 +46,6 @@ void child_main(void) { - struct stevedore *st; - setbuf(stdout, NULL); setbuf(stderr, NULL); printf("Child starts\n"); @@ -67,12 +64,8 @@ HSH_Init(); BAN_Init(); - stevedore_h = &heritage.stevedore_h; - TAILQ_FOREACH(st, stevedore_h, stevedore_list) { - if (st->open != NULL) - st->open(st); - } - + STV_open(); + printf("Ready\n"); VSL_stats->start_time = (time_t)TIM_real(); Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 08:40:33 UTC (rev 1729) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 09:06:42 UTC (rev 1730) @@ -44,6 +44,7 @@ { struct storage *st; struct stevedore *stv, *stv_first; + struct stevedore_head *stevedore_h = &heritage.stevedore_h; /* Simple round robin selecting of a stevedore. */ @@ -101,7 +102,6 @@ return (0); } - void STV_add(const char *spec) { @@ -131,3 +131,16 @@ if (stp->init != NULL) stp->init(stp, q); } + +void +STV_open(void) +{ + struct stevedore_head *stevedore_h; + struct stevedore *st; + + stevedore_h = &heritage.stevedore_h; + TAILQ_FOREACH(st, stevedore_h, stevedore_list) { + if (st->open != NULL) + st->open(st); + } +} Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2007-07-20 08:40:33 UTC (rev 1729) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2007-07-20 09:06:42 UTC (rev 1730) @@ -59,3 +59,4 @@ void STV_trim(struct storage *st, size_t size); void STV_free(struct storage *st); void STV_add(const char *spec); +void STV_open(void); From cecilihf at projects.linpro.no Fri Jul 20 09:19:36 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Fri, 20 Jul 2007 11:19:36 +0200 (CEST) Subject: r1731 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720091936.D43251EC3F0@projects.linpro.no> Author: cecilihf Date: 2007-07-20 11:19:36 +0200 (Fri, 20 Jul 2007) New Revision: 1731 Modified: trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/stevedore.c Log: Added locking on the list manipulation. Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-07-20 09:06:42 UTC (rev 1730) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-07-20 09:19:36 UTC (rev 1731) @@ -31,6 +31,7 @@ * This file contains the heritage passed when mgt forks cache */ +#include #include "queue.h" struct listen_sock { @@ -60,6 +61,7 @@ /* Storage method */ struct stevedore_head stevedore_h; + pthread_mutex_t stevedore_lock; /* Hash method */ struct hash_slinger *hash; Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 09:06:42 UTC (rev 1730) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 09:19:36 UTC (rev 1731) @@ -46,8 +46,8 @@ struct stevedore *stv, *stv_first; struct stevedore_head *stevedore_h = &heritage.stevedore_h; - /* Simple round robin selecting of a stevedore. - */ + /* Simple round robin selecting of a stevedore. */ + pthread_mutex_lock(&heritage.stevedore_lock); stv_first = TAILQ_FIRST(stevedore_h); stv = stv_first; do { @@ -55,8 +55,10 @@ st = stv->alloc(stv, size); TAILQ_REMOVE(stevedore_h, stv, stevedore_list); TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list); - if (st != NULL) + if (st != NULL) { + pthread_mutex_unlock(&heritage.stevedore_lock); return (st); + } } while ((stv = TAILQ_FIRST(stevedore_h)) != stv_first); /* No stevedore with enough space is found. Make room in the first @@ -65,6 +67,7 @@ stv = TAILQ_FIRST(stevedore_h); TAILQ_REMOVE(stevedore_h, stv, stevedore_list); TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list); + pthread_mutex_unlock(&heritage.stevedore_lock); do { if ((st = stv->alloc(stv, size)) == NULL) @@ -143,4 +146,5 @@ if (st->open != NULL) st->open(st); } + pthread_mutex_init(&heritage.stevedore_lock, NULL); } From des at projects.linpro.no Fri Jul 20 09:44:21 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 11:44:21 +0200 (CEST) Subject: r1732 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720094421.CBD721EC1F6@projects.linpro.no> Author: des Date: 2007-07-20 11:44:21 +0200 (Fri, 20 Jul 2007) New Revision: 1732 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_main.c trunk/varnish-cache/bin/varnishd/cache_response.c trunk/varnish-cache/bin/varnishd/cache_synthetic.c trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/storage_malloc.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Additional style cleanup; remove stevedore list from heritage; revert locking, which introduces a choke point. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-20 09:44:21 UTC (rev 1732) @@ -214,8 +214,6 @@ off_t where; }; -#include "stevedore.h" - /* -------------------------------------------------------------------*/ struct object { Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-07-20 09:44:21 UTC (rev 1732) @@ -44,6 +44,7 @@ #include "shmlog.h" #include "cache.h" #include "heritage.h" +#include "stevedore.h" /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-07-20 09:44:21 UTC (rev 1732) @@ -59,8 +59,9 @@ #include #include "shmlog.h" +#include "cache.h" #include "heritage.h" -#include "cache.h" +#include "stevedore.h" static struct hash_slinger *hash; Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2007-07-20 09:44:21 UTC (rev 1732) @@ -34,11 +34,11 @@ #include #include -#include "heritage.h" #include "shmlog.h" #include "cache.h" +#include "heritage.h" +#include "stevedore.h" - /*-------------------------------------------------------------------- * XXX: Think more about which order we start things */ @@ -46,6 +46,7 @@ void child_main(void) { + setbuf(stdout, NULL); setbuf(stderr, NULL); printf("Child starts\n"); @@ -65,7 +66,7 @@ BAN_Init(); STV_open(); - + printf("Ready\n"); VSL_stats->start_time = (time_t)TIM_real(); Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-20 09:44:21 UTC (rev 1732) @@ -151,7 +151,6 @@ TAILQ_FOREACH(st, &sp->obj->store, list) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); - AN(st->stevedore); u += st->len; sp->wrk->acct.bodybytes += st->len; #ifdef HAVE_SENDFILE Modified: trunk/varnish-cache/bin/varnishd/cache_synthetic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2007-07-20 09:44:21 UTC (rev 1732) @@ -34,8 +34,9 @@ #include #include "shmlog.h" +#include "cache.h" #include "heritage.h" -#include "cache.h" +#include "stevedore.h" /* * Synthesize an error page. This assumes the session already has an @@ -87,7 +88,6 @@ /* allocate space for body */ /* XXX what if the object already has a body? */ st = STV_alloc(1024); - XXXAN(st->stevedore); TAILQ_INSERT_TAIL(&sp->obj->store, st, list); /* generate body */ Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-07-20 09:44:21 UTC (rev 1732) @@ -41,7 +41,6 @@ }; TAILQ_HEAD(listen_sock_head, listen_sock); -TAILQ_HEAD(stevedore_head, stevedore); struct heritage { @@ -59,10 +58,6 @@ int vsl_fd; unsigned vsl_size; - /* Storage method */ - struct stevedore_head stevedore_h; - pthread_mutex_t stevedore_lock; - /* Hash method */ struct hash_slinger *hash; Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2007-07-20 09:44:21 UTC (rev 1732) @@ -61,13 +61,7 @@ int mgt_vcc_default(const char *bflag, const char *fflag, int f_fd, int Cflag); int mgt_push_vcls_and_start(unsigned *status, char **p); -#include "stevedore.h" - -extern struct stevedore sma_stevedore; -extern struct stevedore smf_stevedore; - #include "hash_slinger.h" extern struct hash_slinger hsl_slinger; extern struct hash_slinger hcl_slinger; - Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 09:44:21 UTC (rev 1732) @@ -34,46 +34,43 @@ #include "cache.h" #include "heritage.h" +#include "stevedore.h" extern struct stevedore sma_stevedore; extern struct stevedore smf_stevedore; +static TAILQ_HEAD(stevedore_head, stevedore) stevedores; struct storage * STV_alloc(size_t size) { struct storage *st; struct stevedore *stv, *stv_first; - struct stevedore_head *stevedore_h = &heritage.stevedore_h; /* Simple round robin selecting of a stevedore. */ - pthread_mutex_lock(&heritage.stevedore_lock); - stv_first = TAILQ_FIRST(stevedore_h); + stv_first = TAILQ_FIRST(&stevedores); stv = stv_first; do { AN(stv->alloc); st = stv->alloc(stv, size); - TAILQ_REMOVE(stevedore_h, stv, stevedore_list); - TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list); - if (st != NULL) { - pthread_mutex_unlock(&heritage.stevedore_lock); + TAILQ_REMOVE(&stevedores, stv, stevedore_list); + TAILQ_INSERT_TAIL(&stevedores, stv, stevedore_list); + if (st != NULL) return (st); - } - } while ((stv = TAILQ_FIRST(stevedore_h)) != stv_first); - + } while ((stv = TAILQ_FIRST(&stevedores)) != stv_first); + /* No stevedore with enough space is found. Make room in the first * one in the list, and move it to the end. Ensuring the round-robin. */ - stv = TAILQ_FIRST(stevedore_h); - TAILQ_REMOVE(stevedore_h, stv, stevedore_list); - TAILQ_INSERT_TAIL(stevedore_h, stv, stevedore_list); - pthread_mutex_unlock(&heritage.stevedore_lock); - + stv = TAILQ_FIRST(&stevedores); + TAILQ_REMOVE(&stevedores, stv, stevedore_list); + TAILQ_INSERT_TAIL(&stevedores, stv, stevedore_list); + do { if ((st = stv->alloc(stv, size)) == NULL) AN(LRU_DiscardOne()); } while (st == NULL); - + return (st); } @@ -118,9 +115,9 @@ q = p + 1; xxxassert(p != NULL); xxxassert(q != NULL); - + stp = malloc(sizeof *stp); - + if (!cmp_storage(&sma_stevedore, spec, p)) { *stp = sma_stevedore; } else if (!cmp_storage(&smf_stevedore, spec, p)) { @@ -130,21 +127,18 @@ (int)(p - spec), spec); exit (2); } - TAILQ_INSERT_HEAD(&heritage.stevedore_h, stp, stevedore_list); + TAILQ_INSERT_HEAD(&stevedores, stp, stevedore_list); if (stp->init != NULL) stp->init(stp, q); } -void +void STV_open(void) { - struct stevedore_head *stevedore_h; struct stevedore *st; - - stevedore_h = &heritage.stevedore_h; - TAILQ_FOREACH(st, stevedore_h, stevedore_list) { + + TAILQ_FOREACH(st, &stevedores, stevedore_list) { if (st->open != NULL) st->open(st); } - pthread_mutex_init(&heritage.stevedore_lock, NULL); } Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-07-20 09:44:21 UTC (rev 1732) @@ -57,8 +57,10 @@ #ifndef HAVE_ASPRINTF #include "compat/asprintf.h" #endif + #include "shmlog.h" #include "cache.h" +#include "stevedore.h" #ifndef MAP_NOCORE #define MAP_NOCORE 0 /* XXX Linux */ Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2007-07-20 09:44:21 UTC (rev 1732) @@ -37,6 +37,7 @@ #include "shmlog.h" #include "cache.h" +#include "stevedore.h" struct sma { struct storage s; Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-07-20 09:19:36 UTC (rev 1731) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-07-20 09:44:21 UTC (rev 1732) @@ -61,9 +61,10 @@ #include "cli_priv.h" #include "cli_common.h" +#include "shmlog.h" +#include "heritage.h" #include "mgt.h" -#include "heritage.h" -#include "shmlog.h" +#include "stevedore.h" /* INFTIM indicates an infinite timeout for poll(2) */ #ifndef INFTIM @@ -392,8 +393,7 @@ cli[0].result = CLIS_OK; TAILQ_INIT(&heritage.socks); - TAILQ_INIT(&heritage.stevedore_h); - + mgt_vcc_init(); MCF_ParamInit(cli); @@ -536,7 +536,7 @@ if (!s_arg_given) STV_add(s_arg); - + setup_hash(h_arg); VSL_MgtInit(SHMLOG_FILENAME, 8*1024*1024); From des at projects.linpro.no Fri Jul 20 10:14:43 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 12:14:43 +0200 (CEST) Subject: r1733 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720101443.D30771EC3F0@projects.linpro.no> Author: des Date: 2007-07-20 12:14:43 +0200 (Fri, 20 Jul 2007) New Revision: 1733 Modified: trunk/varnish-cache/bin/varnishd/cache.h Log: Style nit. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-20 09:44:21 UTC (rev 1732) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-20 10:14:43 UTC (rev 1733) @@ -96,8 +96,6 @@ char *WS_Alloc(struct ws *ws, unsigned bytes); void WS_Return(struct ws *ws, char *b, char *e); - - /*-------------------------------------------------------------------- * HTTP Request/Response/Header handling structure. */ From des at projects.linpro.no Fri Jul 20 10:23:13 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 12:23:13 +0200 (CEST) Subject: r1734 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720102313.04A1F1EC1F6@projects.linpro.no> Author: des Date: 2007-07-20 12:23:12 +0200 (Fri, 20 Jul 2007) New Revision: 1734 Modified: trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/bin/varnishd/stevedore.h Log: Store stevedores in a circular list. The head pointer keeps moving from one stevedore to the next. The LRU code is invoked as soon as any of the stevedores fills up. This algorithm is far from ideal, and will not work well with differently sized stevedores, but it has the advantage of being simple and lock-free. Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 10:14:43 UTC (rev 1733) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 10:23:12 UTC (rev 1734) @@ -36,48 +36,42 @@ #include "heritage.h" #include "stevedore.h" +/* + * Stevedores are kept in a circular list with the head pointer + * continuously moving from one element to the next. + */ + extern struct stevedore sma_stevedore; extern struct stevedore smf_stevedore; -static TAILQ_HEAD(stevedore_head, stevedore) stevedores; +static struct stevedore * volatile stevedores; struct storage * STV_alloc(size_t size) { struct storage *st; - struct stevedore *stv, *stv_first; + struct stevedore *stv; - /* Simple round robin selecting of a stevedore. */ - stv_first = TAILQ_FIRST(&stevedores); - stv = stv_first; - do { - AN(stv->alloc); - st = stv->alloc(stv, size); - TAILQ_REMOVE(&stevedores, stv, stevedore_list); - TAILQ_INSERT_TAIL(&stevedores, stv, stevedore_list); - if (st != NULL) + for (;;) { + /* pick a stevedore and bump the head along */ + stv = stevedores = stevedores->next; + + /* try to allocate from it */ + if ((st = stv->alloc(stv, size)) != NULL) { + CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); return (st); - } while ((stv = TAILQ_FIRST(&stevedores)) != stv_first); + } - /* No stevedore with enough space is found. Make room in the first - * one in the list, and move it to the end. Ensuring the round-robin. - */ - stv = TAILQ_FIRST(&stevedores); - TAILQ_REMOVE(&stevedores, stv, stevedore_list); - TAILQ_INSERT_TAIL(&stevedores, stv, stevedore_list); - - do { - if ((st = stv->alloc(stv, size)) == NULL) - AN(LRU_DiscardOne()); - } while (st == NULL); - - return (st); + /* no luck; free some space and keep trying */ + AN(LRU_DiscardOne()); + } } void STV_trim(struct storage *st, size_t size) { + CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); AN(st->stevedore); if (st->stevedore->trim) st->stevedore->trim(st, size); @@ -87,6 +81,7 @@ STV_free(struct storage *st) { + CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); AN(st->stevedore); AN(st->stevedore->free); st->stevedore->free(st); @@ -106,7 +101,7 @@ STV_add(const char *spec) { const char *p, *q; - struct stevedore *stp; + struct stevedore *stv; p = strchr(spec, ','); if (p == NULL) @@ -116,29 +111,42 @@ xxxassert(p != NULL); xxxassert(q != NULL); - stp = malloc(sizeof *stp); + stv = malloc(sizeof *stv); if (!cmp_storage(&sma_stevedore, spec, p)) { - *stp = sma_stevedore; + *stv = sma_stevedore; } else if (!cmp_storage(&smf_stevedore, spec, p)) { - *stp = smf_stevedore; + *stv = smf_stevedore; } else { fprintf(stderr, "Unknown storage method \"%.*s\"\n", (int)(p - spec), spec); exit (2); } - TAILQ_INSERT_HEAD(&stevedores, stp, stevedore_list); - if (stp->init != NULL) - stp->init(stp, q); + if (stv->init != NULL) + stv->init(stv, q); + + if (!stevedores) { + fprintf(stderr, "first stevedore\n"); + stevedores = stv->next = stv->prev = stv; + } else { + fprintf(stderr, "additional stevedore\n"); + stv->next = stevedores; + stv->prev = stevedores->prev; + stv->next->prev = stv; + stv->prev->next = stv; + stevedores = stv; + } } void STV_open(void) { - struct stevedore *st; + struct stevedore *stv; - TAILQ_FOREACH(st, &stevedores, stevedore_list) { - if (st->open != NULL) - st->open(st); - } + stv = stevedores; + do { + if (stv->open != NULL) + stv->open(stv); + stv = stv->next; + } while (stv != stevedores); } Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2007-07-20 10:14:43 UTC (rev 1733) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2007-07-20 10:23:12 UTC (rev 1734) @@ -28,7 +28,6 @@ * * $Id$ */ - #include "queue.h" @@ -52,7 +51,8 @@ /* private fields */ void *priv; - TAILQ_ENTRY(stevedore) stevedore_list; + + struct stevedore *next, *prev; }; struct storage *STV_alloc(size_t size); From des at projects.linpro.no Fri Jul 20 10:24:03 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 12:24:03 +0200 (CEST) Subject: r1735 - trunk/varnish-cache/bin/varnishd Message-ID: <20070720102403.310F01EC3F0@projects.linpro.no> Author: des Date: 2007-07-20 12:24:03 +0200 (Fri, 20 Jul 2007) New Revision: 1735 Modified: trunk/varnish-cache/bin/varnishd/stevedore.c Log: Remove debugging output. Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 10:23:12 UTC (rev 1734) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2007-07-20 10:24:03 UTC (rev 1735) @@ -126,10 +126,8 @@ stv->init(stv, q); if (!stevedores) { - fprintf(stderr, "first stevedore\n"); stevedores = stv->next = stv->prev = stv; } else { - fprintf(stderr, "additional stevedore\n"); stv->next = stevedores; stv->prev = stevedores->prev; stv->next->prev = stv; From des at projects.linpro.no Fri Jul 20 11:03:11 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 13:03:11 +0200 (CEST) Subject: r1736 - in branches/1.1: . bin/varnishd include Message-ID: <20070720110311.E36271EC1F6@projects.linpro.no> Author: des Date: 2007-07-20 13:03:11 +0200 (Fri, 20 Jul 2007) New Revision: 1736 Modified: branches/1.1/ branches/1.1/bin/varnishd/cache_expire.c branches/1.1/bin/varnishd/cache_fetch.c branches/1.1/bin/varnishd/cache_pipe.c branches/1.1/include/stat_field.h Log: Merged revisions 1727-1729 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1727 | des | 2007-07-20 10:38:22 +0200 (Fri, 20 Jul 2007) | 2 lines Let the LRU code worry about this. ........ r1728 | des | 2007-07-20 10:39:45 +0200 (Fri, 20 Jul 2007) | 2 lines Paranoia. ........ r1729 | des | 2007-07-20 10:40:33 +0200 (Fri, 20 Jul 2007) | 2 lines Count backend requests. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722 + /trunk/varnish-cache:1-1722,1727-1729 Modified: branches/1.1/bin/varnishd/cache_expire.c =================================================================== --- branches/1.1/bin/varnishd/cache_expire.c 2007-07-20 10:24:03 UTC (rev 1735) +++ branches/1.1/bin/varnishd/cache_expire.c 2007-07-20 11:03:11 UTC (rev 1736) @@ -82,8 +82,7 @@ EXP_Terminate(struct object *o) { LOCK(&exp_mtx); - if (o->lru_stamp) - LRU_Remove(o); + LRU_Remove(o); if (o->heap_idx) binheap_delete(exp_heap, o->heap_idx); if (o->deathrow.tqe_next) { Modified: branches/1.1/bin/varnishd/cache_fetch.c =================================================================== --- branches/1.1/bin/varnishd/cache_fetch.c 2007-07-20 10:24:03 UTC (rev 1735) +++ branches/1.1/bin/varnishd/cache_fetch.c 2007-07-20 11:03:11 UTC (rev 1736) @@ -286,6 +286,9 @@ return (1); } + /* XXX is this the right place? */ + VSL_stats->backend_req++; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); Modified: branches/1.1/bin/varnishd/cache_pipe.c =================================================================== --- branches/1.1/bin/varnishd/cache_pipe.c 2007-07-20 10:24:03 UTC (rev 1735) +++ branches/1.1/bin/varnishd/cache_pipe.c 2007-07-20 11:03:11 UTC (rev 1736) @@ -46,7 +46,7 @@ rdf(struct pollfd *fds, int idx) { int i, j; - char buf[BUFSIZ]; + char buf[BUFSIZ], *p; i = read(fds[idx].fd, buf, sizeof buf); if (i <= 0 || fds[1-idx].events == 0) { @@ -55,14 +55,17 @@ shutdown(fds[idx].fd, SHUT_RD); shutdown(fds[1-idx].fd, SHUT_WR); fds[idx].events = 0; - } else { - j = write(fds[1-idx].fd, buf, i); - if (i != j) { + return; + } + for (p = buf; i > 0; i -= j, p += j) { + j = write(fds[1-idx].fd, p, i); + if (j < 0) { VSL(SLT_Debug, fds[idx].fd, "Pipe Shut write(write)"); VSL(SLT_Debug, fds[1-idx].fd, "Pipe Shut read(write)"); shutdown(fds[idx].fd, SHUT_WR); shutdown(fds[1-idx].fd, SHUT_RD); fds[1-idx].events = 0; + return; } } } Modified: branches/1.1/include/stat_field.h =================================================================== --- branches/1.1/include/stat_field.h 2007-07-20 10:24:03 UTC (rev 1735) +++ branches/1.1/include/stat_field.h 2007-07-20 11:03:11 UTC (rev 1736) @@ -89,3 +89,5 @@ MAC_STAT(sm_nobj, uint64_t, 'i', "outstanding allocations") MAC_STAT(sm_balloc, uint64_t, 'i', "bytes allocated") MAC_STAT(sm_bfree, uint64_t, 'i', "bytes free") + +MAC_STAT(backend_req, uint64_t, 'a', "Backend requests made") From des at projects.linpro.no Fri Jul 20 11:10:56 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 13:10:56 +0200 (CEST) Subject: r1737 - branches/1.1/redhat Message-ID: <20070720111056.0F8CD1EC3F0@projects.linpro.no> Author: des Date: 2007-07-20 13:10:55 +0200 (Fri, 20 Jul 2007) New Revision: 1737 Modified: branches/1.1/redhat/varnish.spec Log: Correct date. Modified: branches/1.1/redhat/varnish.spec =================================================================== --- branches/1.1/redhat/varnish.spec 2007-07-20 11:03:11 UTC (rev 1736) +++ branches/1.1/redhat/varnish.spec 2007-07-20 11:10:55 UTC (rev 1737) @@ -148,7 +148,7 @@ %postun libs -p /sbin/ldconfig %changelog -* Thu Jul 05 2006 Dag-Erling Sm?rgrav - 1.1-1 +* Thu Jul 05 2007 Dag-Erling Sm?rgrav - 1.1-1 - Bump Version and Release for 1.1 * Mon May 28 2007 Ingvar Hagelund - 1.0.4-3 From des at projects.linpro.no Fri Jul 20 11:25:21 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 13:25:21 +0200 (CEST) Subject: r1738 - trunk/varnish-cache/debian Message-ID: <20070720112521.77BF91EC475@projects.linpro.no> Author: des Date: 2007-07-20 13:25:21 +0200 (Fri, 20 Jul 2007) New Revision: 1738 Modified: trunk/varnish-cache/debian/rules Log: Set localstatedir explicitly, otherwise it ends up as /usr/var. Modified: trunk/varnish-cache/debian/rules =================================================================== --- trunk/varnish-cache/debian/rules 2007-07-20 11:10:55 UTC (rev 1737) +++ trunk/varnish-cache/debian/rules 2007-07-20 11:25:21 UTC (rev 1738) @@ -32,7 +32,7 @@ # The boilerplate linker flags won't allow varnish to compile :( # There are circular dependencies in the varnish libraries, but # the core developers have OK'ed that we don't check. - ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" + ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" --localstatedir=/var build: build-stamp From des at projects.linpro.no Fri Jul 20 11:26:01 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 13:26:01 +0200 (CEST) Subject: r1739 - in branches/1.1: . debian Message-ID: <20070720112601.3EE421EC429@projects.linpro.no> Author: des Date: 2007-07-20 13:26:01 +0200 (Fri, 20 Jul 2007) New Revision: 1739 Modified: branches/1.1/ branches/1.1/debian/rules Log: Merged revisions 1738 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1738 | des | 2007-07-20 13:25:21 +0200 (Fri, 20 Jul 2007) | 2 lines Set localstatedir explicitly, otherwise it ends up as /usr/var. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729 + /trunk/varnish-cache:1-1722,1727-1729,1738 Modified: branches/1.1/debian/rules =================================================================== --- branches/1.1/debian/rules 2007-07-20 11:25:21 UTC (rev 1738) +++ branches/1.1/debian/rules 2007-07-20 11:26:01 UTC (rev 1739) @@ -32,7 +32,7 @@ # The boilerplate linker flags won't allow varnish to compile :( # There are circular dependencies in the varnish libraries, but # the core developers have OK'ed that we don't check. - ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" + ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" --localstatedir=/var build: build-stamp From des at projects.linpro.no Fri Jul 20 11:27:42 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 13:27:42 +0200 (CEST) Subject: r1740 - tags Message-ID: <20070720112742.21A581EC3F0@projects.linpro.no> Author: des Date: 2007-07-20 13:27:41 +0200 (Fri, 20 Jul 2007) New Revision: 1740 Added: tags/varnish-1.1/ Log: Tag 1.1. Copied: tags/varnish-1.1 (from rev 1739, branches/1.1) From des at projects.linpro.no Fri Jul 20 11:29:26 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 13:29:26 +0200 (CEST) Subject: r1741 - branches/1.1 Message-ID: <20070720112926.1B7D61EC3F0@projects.linpro.no> Author: des Date: 2007-07-20 13:29:25 +0200 (Fri, 20 Jul 2007) New Revision: 1741 Modified: branches/1.1/ChangeLog Log: Regenerate Modified: branches/1.1/ChangeLog =================================================================== --- branches/1.1/ChangeLog 2007-07-20 11:27:41 UTC (rev 1740) +++ branches/1.1/ChangeLog 2007-07-20 11:29:25 UTC (rev 1741) @@ -1,114 +1,150 @@ -Change log for Varnish 1.0.4 +Change log for Varnish 1.1 -Changes between 1.0.3 and 1.0.4 +Changes between 1.0.4 and 1.1 varnishd - ? The request workflow has been redesigned to simplify request processing and - eliminate code duplication. All codepaths which need to speak HTTP now - share a single implementation of the protocol. Some new VCL hooks have been - added, though they aren't much use yet. The only real user-visible change - should be that Varnish now handles persistent backend connections correctly - (see ticket #56). + ? Readability of the C source code generated from VCL code has been improved. - ? Support for multiple listen addresses has been added. + ? Equality (==) and inequality (!=) operators have been implemented for IP + addresses (which previously could only be compared using ACLs). - ? An "include" facility has been added to VCL, allowing VCL code to pull in - code fragments from multiple files. + ? The address of the listening socket on which the client connection was + received is now available to VCL as the server.ip variable. - ? Multiple definitions of the same VCL function are now concatenated into one - in the order in which they appear in the source. This simplifies the - mechanism for falling back to the built-in default for cases which aren't - handled in custom code, and facilitates modularization. + ? Each object's hash key is now computed based on a string which is available + to VCL as req.hash. A VCL hook named vcl_hash has been added to allow VCL + scripts to control hash generation (for instance, whether or not to include + the value of the Host: header in the hash). - ? The code used to format management command arguments before passing them on - to the child process would underestimate the amount of space needed to hold - each argument once quotes and special characters were properly escaped, - resulting in a buffer overflow. This has been corrected. + ? The setup code for listening sockets has been modified to detect and handle + situations where a host name resolves to multiple IP addresses. It will now + attempt to bind to each IP address separately, and report a failure only if + none of them worked. - ? The VCL compiler has been overhauled. Several memory leaks have been - plugged, and error detection and reporting has been improved throughout. - Parts of the compiler have been refactored to simplify future extension of - the language. + ? Network or protocol errors that occur while retrieving an object from a + backend server now result in a synthetic error page being inserted into the + cache with a 30-second TTL. This should help avoid driving an overburdened + backend server into the ground by repeatedly requesting the same object. - ? A bug in the VCL compiler which resulted in incorrect parsing of the - decrement (-=) operator has been fixed. + ? The child process will now drop root privileges immediately upon startup. + The user and group to use are specified with the user and group run-time + parameters, which default to nobody and nogroup, respectively. Other + changes have been made in an effort to increase the isolation between + parent and child, and reduce the impact of a compromise of the child + process. - ? A new -C command-line option has been added which causes varnishd to - compile the VCL code (either from a file specified with -f or the built-in - default), print the resulting C code and exit. + ? Objects which are received from the backend with a Vary: header are now + stored separately according to the values of the headers specified in + Vary:. This allows Varnish to correctly cache e.g. compressed and + uncompressed versions of the same object. - ? When processing a backend response using chunked encoding, if a chunk - header crosses a read buffer boundary, read additional bytes from the - backend connection until the chunk header is complete. + ? Each Varnish instance now has a name, which by default is the host name of + the machine it runs on, but can be any string that would be valid as a + relative or absolute directory name. It is used to construct the name of a + directory in which the server state as well as all temporary files are + stored. This makes it possible to run multiple Varnish instances on the + same machine without conflict. - ? A new ping_interval run-time parameter controls how often the management - process checks that the worker process is alive. + ? When invoked with the -C option, varnishd will now not just translate the + VCL code to C, but also compile the C code and attempt to load the + resulting shared object. - ? A bug which would cause the worker process to dereference a NULL pointer - and crash if the backend did not respond has been fixed. + ? Attempts by VCL code to reference a variable outside its scope or to assign + a value to a read-only variable will now result in compile-time rather than + run-time errors. - ? In some cases, such as when they are used by AJAX applications to - circumvent Internet Explorer's over-eager disk cache, it may be desirable - to cache POST requests. However, the code path responsible for delivering - objects from cache would only transmit the response body when replying to a - GET request. This has been extended to also apply to POST. + ? The new command-line option -F will make varnishd run in the foreground, + without enabling debugging. - This should be revisited at a later date to allow VCL code to control - whether the body is delivered. + ? New VCL variables have been introduced to allow inspection and manipulation + of the request sent to the backend (bereq.request, bereq.url, bereq.proto + and bereq.http) and the response to the client (resp.proto, resp.status, + resp.response and resp.http). - ? Varnish now respects Cache-control: s-maxage, and prefers it to - Cache-control: max-age if both are present. + ? Statistics from the storage code (including the amount of data and free + space in the cache) are now available to varnishstat and other + statistics-gathering tools. - This should be revisited at a later date to allow VCL code to control which - headers are used and how they are interpreted. + ? Objects are now kept on an LRU list which is kept loosely up-to-date (to + within a few seconds). When cache runs out, the objects at the tail end of + the LRU list are discarded one by one until there is enough space for the + freshly requested object(s). A VCL hook, vcl_discard, is allowed to inspect + each object and determine its fate by returning either keep or discard. - ? When loading a new VCL script, the management process will now load the - compiled object to verify that it links correctly before instructing the - worker process to load it. + ? A new VCL hook, vcl_deliver, provides a chance to adjust the response + before it is sent to the client. - ? A new -P command-line options has been added which causes varnishd to - create a PID file. + ? A new management command, vcl.show, displays the VCL source code of any + loaded configuration. - ? The sendfile_threshold run-time parameter's default value has been set to - infinity after a variety of sendfile()-related bugs were discovered on - several platforms. + ? A new VCL variable, now, provides VCL scripts with the current time in + seconds since the epoch. -varnishlog + ? A new VCL variable, obj.lastuse, reflects the time in seconds since the + object in question was last used. - ? When grouping log entries by request, varnishlog attempts to collapse the - log entry for a call to a VCL function with the log entry for the - corresponding return from VCL. When two VCL calls were made in succession, - varnishlog would incorrectly omit the newline between the two calls (see - ticket #95). + ? VCL scripts can now add an HTTP header (or modify the value of an existing + one) by assigning a value to the corresponding variable, and strip an HTTP + header by using the remove keyword. - ? New -D and -P command-line options have been added to daemonize and create - a pidfile, respectively. + ? VCL scripts can now modify the HTTP status code of cached objects + (obj.status) and responses (resp.status) + ? Numeric and other non-textual variables in VCL can now be assigned to + textual variables; they will be converted as needed. + + ? VCL scripts can now apply regular expression substitutions to textual + variables using the regsub function. + + ? A new management command, status, returns the state of the child. + + ? Varnish will now build and run on Mac OS X. + +varnishadm + + ? This is a new utility which sends a single command to a Varnish server's + management port and prints the result to stdout, greatly simplifying the + use of the management port from scripts. + +varnishhist + + ? The user interface has been greatly improved; the histogram will be + automatically rescaled and redrawn when the window size changes, and it is + updated regularly rather than at a rate dependent on the amount of log data + gathered. In addition, the name of the Varnish instance being watched is + displayed in the upper right corner. + varnishncsa - ? The formatting callback has been largely rewritten for clarity, robustness - and efficiency. + ? In addition to client traffic, varnishncsa can now also process log data + from backend traffic. - If a request included a Host: header, construct and output an absolute URL. - This makes varnishncsa output from servers which handle multiple virtual - hosts far more useful. + ? A bug that would cause varnishncsa to segfault when it encountered an empty + HTTP header in the log file has been fixed. -Documentation +varnishreplay - ? The documentation?especially the VCL documentation?has been greatly - extended and improved. + ? This new utility will attempt to recreate the HTTP traffic which resulted + in the raw Varnish log data which it is fed. -Build system +varnishstat - ? The name and location of the curses or ncurses library is now correctly - detected by the configure script instead of being hardcoded into affected - Makefiles. This allows Varnish to build correctly on a wider range of - platforms. + ? Don't print lifetime averages when it doesn't make any sense?for instance, + there is no point in dividing the amount in bytes of free cache space by + the lifetime in seconds of the varnishd process. - ? Compatibility shims for clock_gettime() are now correctly applied where - needed, allowing Varnish to build on MacOS X. + ? The user interface has been greatly improved; varnishstat will no longer + print more than fits in the terminal, and will respond correctly to window + resize events. The output produced in one-shot mode has been modified to + include symbolic names for each entry. In addition, the name of the Varnish + instance being watched is displayed in the upper right corner in curses + mode. - ? The autogen.sh script will now correctly detect and warn about automake - versions which are known not to work correctly. +varnishtop + ? The user interface has been greatly improved; varnishtop will now respond + correctly to window resize events, and one-shot mode (-1) actually works. + In addition, the name of the Varnish instance being watched is displayed in + the upper right corner in curses mode. + From des at projects.linpro.no Fri Jul 20 11:32:27 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 20 Jul 2007 13:32:27 +0200 (CEST) Subject: r1742 - tags/varnish-1.1 Message-ID: <20070720113227.B51991EC1F6@projects.linpro.no> Author: des Date: 2007-07-20 13:32:27 +0200 (Fri, 20 Jul 2007) New Revision: 1742 Modified: tags/varnish-1.1/ChangeLog Log: Slide the change log. I wish Subversion had proper tags... Modified: tags/varnish-1.1/ChangeLog =================================================================== --- tags/varnish-1.1/ChangeLog 2007-07-20 11:29:25 UTC (rev 1741) +++ tags/varnish-1.1/ChangeLog 2007-07-20 11:32:27 UTC (rev 1742) @@ -1,114 +1,150 @@ -Change log for Varnish 1.0.4 +Change log for Varnish 1.1 -Changes between 1.0.3 and 1.0.4 +Changes between 1.0.4 and 1.1 varnishd - ? The request workflow has been redesigned to simplify request processing and - eliminate code duplication. All codepaths which need to speak HTTP now - share a single implementation of the protocol. Some new VCL hooks have been - added, though they aren't much use yet. The only real user-visible change - should be that Varnish now handles persistent backend connections correctly - (see ticket #56). + ? Readability of the C source code generated from VCL code has been improved. - ? Support for multiple listen addresses has been added. + ? Equality (==) and inequality (!=) operators have been implemented for IP + addresses (which previously could only be compared using ACLs). - ? An "include" facility has been added to VCL, allowing VCL code to pull in - code fragments from multiple files. + ? The address of the listening socket on which the client connection was + received is now available to VCL as the server.ip variable. - ? Multiple definitions of the same VCL function are now concatenated into one - in the order in which they appear in the source. This simplifies the - mechanism for falling back to the built-in default for cases which aren't - handled in custom code, and facilitates modularization. + ? Each object's hash key is now computed based on a string which is available + to VCL as req.hash. A VCL hook named vcl_hash has been added to allow VCL + scripts to control hash generation (for instance, whether or not to include + the value of the Host: header in the hash). - ? The code used to format management command arguments before passing them on - to the child process would underestimate the amount of space needed to hold - each argument once quotes and special characters were properly escaped, - resulting in a buffer overflow. This has been corrected. + ? The setup code for listening sockets has been modified to detect and handle + situations where a host name resolves to multiple IP addresses. It will now + attempt to bind to each IP address separately, and report a failure only if + none of them worked. - ? The VCL compiler has been overhauled. Several memory leaks have been - plugged, and error detection and reporting has been improved throughout. - Parts of the compiler have been refactored to simplify future extension of - the language. + ? Network or protocol errors that occur while retrieving an object from a + backend server now result in a synthetic error page being inserted into the + cache with a 30-second TTL. This should help avoid driving an overburdened + backend server into the ground by repeatedly requesting the same object. - ? A bug in the VCL compiler which resulted in incorrect parsing of the - decrement (-=) operator has been fixed. + ? The child process will now drop root privileges immediately upon startup. + The user and group to use are specified with the user and group run-time + parameters, which default to nobody and nogroup, respectively. Other + changes have been made in an effort to increase the isolation between + parent and child, and reduce the impact of a compromise of the child + process. - ? A new -C command-line option has been added which causes varnishd to - compile the VCL code (either from a file specified with -f or the built-in - default), print the resulting C code and exit. + ? Objects which are received from the backend with a Vary: header are now + stored separately according to the values of the headers specified in + Vary:. This allows Varnish to correctly cache e.g. compressed and + uncompressed versions of the same object. - ? When processing a backend response using chunked encoding, if a chunk - header crosses a read buffer boundary, read additional bytes from the - backend connection until the chunk header is complete. + ? Each Varnish instance now has a name, which by default is the host name of + the machine it runs on, but can be any string that would be valid as a + relative or absolute directory name. It is used to construct the name of a + directory in which the server state as well as all temporary files are + stored. This makes it possible to run multiple Varnish instances on the + same machine without conflict. - ? A new ping_interval run-time parameter controls how often the management - process checks that the worker process is alive. + ? When invoked with the -C option, varnishd will now not just translate the + VCL code to C, but also compile the C code and attempt to load the + resulting shared object. - ? A bug which would cause the worker process to dereference a NULL pointer - and crash if the backend did not respond has been fixed. + ? Attempts by VCL code to reference a variable outside its scope or to assign + a value to a read-only variable will now result in compile-time rather than + run-time errors. - ? In some cases, such as when they are used by AJAX applications to - circumvent Internet Explorer's over-eager disk cache, it may be desirable - to cache POST requests. However, the code path responsible for delivering - objects from cache would only transmit the response body when replying to a - GET request. This has been extended to also apply to POST. + ? The new command-line option -F will make varnishd run in the foreground, + without enabling debugging. - This should be revisited at a later date to allow VCL code to control - whether the body is delivered. + ? New VCL variables have been introduced to allow inspection and manipulation + of the request sent to the backend (bereq.request, bereq.url, bereq.proto + and bereq.http) and the response to the client (resp.proto, resp.status, + resp.response and resp.http). - ? Varnish now respects Cache-control: s-maxage, and prefers it to - Cache-control: max-age if both are present. + ? Statistics from the storage code (including the amount of data and free + space in the cache) are now available to varnishstat and other + statistics-gathering tools. - This should be revisited at a later date to allow VCL code to control which - headers are used and how they are interpreted. + ? Objects are now kept on an LRU list which is kept loosely up-to-date (to + within a few seconds). When cache runs out, the objects at the tail end of + the LRU list are discarded one by one until there is enough space for the + freshly requested object(s). A VCL hook, vcl_discard, is allowed to inspect + each object and determine its fate by returning either keep or discard. - ? When loading a new VCL script, the management process will now load the - compiled object to verify that it links correctly before instructing the - worker process to load it. + ? A new VCL hook, vcl_deliver, provides a chance to adjust the response + before it is sent to the client. - ? A new -P command-line options has been added which causes varnishd to - create a PID file. + ? A new management command, vcl.show, displays the VCL source code of any + loaded configuration. - ? The sendfile_threshold run-time parameter's default value has been set to - infinity after a variety of sendfile()-related bugs were discovered on - several platforms. + ? A new VCL variable, now, provides VCL scripts with the current time in + seconds since the epoch. -varnishlog + ? A new VCL variable, obj.lastuse, reflects the time in seconds since the + object in question was last used. - ? When grouping log entries by request, varnishlog attempts to collapse the - log entry for a call to a VCL function with the log entry for the - corresponding return from VCL. When two VCL calls were made in succession, - varnishlog would incorrectly omit the newline between the two calls (see - ticket #95). + ? VCL scripts can now add an HTTP header (or modify the value of an existing + one) by assigning a value to the corresponding variable, and strip an HTTP + header by using the remove keyword. - ? New -D and -P command-line options have been added to daemonize and create - a pidfile, respectively. + ? VCL scripts can now modify the HTTP status code of cached objects + (obj.status) and responses (resp.status) + ? Numeric and other non-textual variables in VCL can now be assigned to + textual variables; they will be converted as needed. + + ? VCL scripts can now apply regular expression substitutions to textual + variables using the regsub function. + + ? A new management command, status, returns the state of the child. + + ? Varnish will now build and run on Mac OS X. + +varnishadm + + ? This is a new utility which sends a single command to a Varnish server's + management port and prints the result to stdout, greatly simplifying the + use of the management port from scripts. + +varnishhist + + ? The user interface has been greatly improved; the histogram will be + automatically rescaled and redrawn when the window size changes, and it is + updated regularly rather than at a rate dependent on the amount of log data + gathered. In addition, the name of the Varnish instance being watched is + displayed in the upper right corner. + varnishncsa - ? The formatting callback has been largely rewritten for clarity, robustness - and efficiency. + ? In addition to client traffic, varnishncsa can now also process log data + from backend traffic. - If a request included a Host: header, construct and output an absolute URL. - This makes varnishncsa output from servers which handle multiple virtual - hosts far more useful. + ? A bug that would cause varnishncsa to segfault when it encountered an empty + HTTP header in the log file has been fixed. -Documentation +varnishreplay - ? The documentation?especially the VCL documentation?has been greatly - extended and improved. + ? This new utility will attempt to recreate the HTTP traffic which resulted + in the raw Varnish log data which it is fed. -Build system +varnishstat - ? The name and location of the curses or ncurses library is now correctly - detected by the configure script instead of being hardcoded into affected - Makefiles. This allows Varnish to build correctly on a wider range of - platforms. + ? Don't print lifetime averages when it doesn't make any sense?for instance, + there is no point in dividing the amount in bytes of free cache space by + the lifetime in seconds of the varnishd process. - ? Compatibility shims for clock_gettime() are now correctly applied where - needed, allowing Varnish to build on MacOS X. + ? The user interface has been greatly improved; varnishstat will no longer + print more than fits in the terminal, and will respond correctly to window + resize events. The output produced in one-shot mode has been modified to + include symbolic names for each entry. In addition, the name of the Varnish + instance being watched is displayed in the upper right corner in curses + mode. - ? The autogen.sh script will now correctly detect and warn about automake - versions which are known not to work correctly. +varnishtop + ? The user interface has been greatly improved; varnishtop will now respond + correctly to window resize events, and one-shot mode (-1) actually works. + In addition, the name of the Varnish instance being watched is displayed in + the upper right corner in curses mode. + From ssm at projects.linpro.no Fri Jul 20 12:43:55 2007 From: ssm at projects.linpro.no (ssm at projects.linpro.no) Date: Fri, 20 Jul 2007 14:43:55 +0200 (CEST) Subject: r1743 - trunk/varnish-cache/debian Message-ID: <20070720124355.70FA01EC429@projects.linpro.no> Author: ssm Date: 2007-07-20 14:43:54 +0200 (Fri, 20 Jul 2007) New Revision: 1743 Added: trunk/varnish-cache/debian/libvarnish-dev.dirs trunk/varnish-cache/debian/libvarnish-dev.install trunk/varnish-cache/debian/libvarnish.dirs trunk/varnish-cache/debian/libvarnish.install trunk/varnish-cache/debian/varnish.dirs trunk/varnish-cache/debian/varnish.install Modified: trunk/varnish-cache/debian/changelog trunk/varnish-cache/debian/control trunk/varnish-cache/debian/dirs trunk/varnish-cache/debian/rules trunk/varnish-cache/debian/varnish.default trunk/varnish-cache/debian/varnish.varnishlog.init Log: Split debian package into varnish, libvarnish and libvarnish-dev Modified: trunk/varnish-cache/debian/changelog =================================================================== --- trunk/varnish-cache/debian/changelog 2007-07-20 11:32:27 UTC (rev 1742) +++ trunk/varnish-cache/debian/changelog 2007-07-20 12:43:54 UTC (rev 1743) @@ -1,3 +1,10 @@ +varnish (1.1) unstable; urgency=low + + * New upstream release + * Split package into varnish, libvarnish and libvarnish-dev + + -- Stig Sandbeck Mathisen Fri, 20 Jul 2007 14:37:36 +0200 + varnish (1.0.4-1) unstable; urgency=low * New upstream version (Closes: #424560) Modified: trunk/varnish-cache/debian/control =================================================================== --- trunk/varnish-cache/debian/control 2007-07-20 11:32:27 UTC (rev 1742) +++ trunk/varnish-cache/debian/control 2007-07-20 12:43:54 UTC (rev 1743) @@ -8,7 +8,7 @@ Package: varnish Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, gcc ( >= 3.3) +Depends: ${shlibs:Depends}, ${misc:Depends}, gcc ( >= 3.3), libvarnish Description: A state-of-the-art, high-performance HTTP accelerator varnish is the server-side alternative to Squid, written primarily with speed in mind, and with a look to implementing full ESI-support in @@ -20,3 +20,27 @@ Varnish is targeted primarily at the FreeBSD 6 and Linux 2.6 platforms, and will take full advantage of the advanced I/O features offered by these operating systems. + +Package: libvarnish +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Shared library for Varnish + Shared library for Varnish. + . + Varnish is the server-side alternative to Squid, written primarily + with speed in mind. + . + The goal of the Varnish project is to develop a state-of-the-art, + high-performance HTTP accelerator. + +Package: libvarnish-dev +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, libvarnish +Description: Shared library for Varnish + Development files for the Varnish library. + . + Varnish is the server-side alternative to Squid, written primarily + with speed in mind. + . + The goal of the Varnish project is to develop a state-of-the-art, + high-performance HTTP accelerator. Modified: trunk/varnish-cache/debian/dirs =================================================================== --- trunk/varnish-cache/debian/dirs 2007-07-20 11:32:27 UTC (rev 1742) +++ trunk/varnish-cache/debian/dirs 2007-07-20 12:43:54 UTC (rev 1743) @@ -1,9 +0,0 @@ -etc/varnish -etc/logrotate.d -usr/bin -usr/lib -usr/sbin -var/log -var/log/varnish -var/lib/varnish -usr/share/lintian/overrides/ Added: trunk/varnish-cache/debian/libvarnish-dev.dirs =================================================================== --- trunk/varnish-cache/debian/libvarnish-dev.dirs (rev 0) +++ trunk/varnish-cache/debian/libvarnish-dev.dirs 2007-07-20 12:43:54 UTC (rev 1743) @@ -0,0 +1 @@ +usr/lib Added: trunk/varnish-cache/debian/libvarnish-dev.install =================================================================== --- trunk/varnish-cache/debian/libvarnish-dev.install (rev 0) +++ trunk/varnish-cache/debian/libvarnish-dev.install 2007-07-20 12:43:54 UTC (rev 1743) @@ -0,0 +1,3 @@ +usr/include +usr/lib/*.a +usr/lib/*.la Added: trunk/varnish-cache/debian/libvarnish.dirs =================================================================== --- trunk/varnish-cache/debian/libvarnish.dirs (rev 0) +++ trunk/varnish-cache/debian/libvarnish.dirs 2007-07-20 12:43:54 UTC (rev 1743) @@ -0,0 +1 @@ +usr/lib Added: trunk/varnish-cache/debian/libvarnish.install =================================================================== --- trunk/varnish-cache/debian/libvarnish.install (rev 0) +++ trunk/varnish-cache/debian/libvarnish.install 2007-07-20 12:43:54 UTC (rev 1743) @@ -0,0 +1 @@ +usr/lib/lib*.so.* Modified: trunk/varnish-cache/debian/rules =================================================================== --- trunk/varnish-cache/debian/rules 2007-07-20 11:32:27 UTC (rev 1742) +++ trunk/varnish-cache/debian/rules 2007-07-20 12:43:54 UTC (rev 1743) @@ -66,7 +66,9 @@ dh_clean -k dh_installdirs - $(MAKE) install DESTDIR=$(CURDIR)/debian/varnish + $(MAKE) install DESTDIR=$(CURDIR)/debian/tmp + dh_install --sourcedir=$(CURDIR)/debian/tmp + install -m 644 $(CURDIR)/etc/default.vcl $(CURDIR)/debian/varnish/etc/varnish/ install -m 644 $(CURDIR)/debian/lintian-override $(CURDIR)/debian/varnish/usr/share/lintian/overrides/varnish install -m 644 $(CURDIR)/debian/varnish.logrotate $(CURDIR)/debian/varnish/etc/logrotate.d/varnish Property changes on: trunk/varnish-cache/debian/rules ___________________________________________________________________ Name: svn + executable Modified: trunk/varnish-cache/debian/varnish.default =================================================================== --- trunk/varnish-cache/debian/varnish.default 2007-07-20 11:32:27 UTC (rev 1742) +++ trunk/varnish-cache/debian/varnish.default 2007-07-20 12:43:54 UTC (rev 1743) @@ -17,6 +17,7 @@ DAEMON_OPTS="-a :6081 \ -T localhost:6082 \ -b localhost:8080 \ + -n /var/lib/varnish \ -s file,/var/lib/varnish/varnish_storage.bin,1G" @@ -29,6 +30,7 @@ # DAEMON_OPTS="-a :6081 \ # -T localhost:6082 \ # -f /etc/varnish/default.vcl \ +# -n /var/lib/varnish \ # -s file,/var/lib/varnish/varnish_storage.bin,1G" @@ -58,6 +60,9 @@ # # Idle timeout for worker threads # VARNISH_THREAD_TIMEOUT=120 # +# # Home dir for this varnish instance +# VARNISH_HOMEDIR=/var/lib/varnish +# # # Cache file location # VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin # @@ -78,6 +83,7 @@ # -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \ # -t ${VARNISH_TTL} \ # -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \ +# -n ${VARNISH_HOMEDIR} \ # -s ${VARNISH_STORAGE}" # Added: trunk/varnish-cache/debian/varnish.dirs =================================================================== --- trunk/varnish-cache/debian/varnish.dirs (rev 0) +++ trunk/varnish-cache/debian/varnish.dirs 2007-07-20 12:43:54 UTC (rev 1743) @@ -0,0 +1,8 @@ +etc/varnish +etc/logrotate.d +usr/bin +usr/sbin +var/log +var/log/varnish +var/lib/varnish +usr/share/lintian/overrides/ Added: trunk/varnish-cache/debian/varnish.install =================================================================== --- trunk/varnish-cache/debian/varnish.install (rev 0) +++ trunk/varnish-cache/debian/varnish.install 2007-07-20 12:43:54 UTC (rev 1743) @@ -0,0 +1,2 @@ +usr/bin +usr/sbin Modified: trunk/varnish-cache/debian/varnish.varnishlog.init =================================================================== --- trunk/varnish-cache/debian/varnish.varnishlog.init 2007-07-20 11:32:27 UTC (rev 1742) +++ trunk/varnish-cache/debian/varnish.varnishlog.init 2007-07-20 12:43:54 UTC (rev 1743) @@ -24,7 +24,7 @@ test -x $DAEMON || exit 0 -DAEMON_OPTS="-a -w ${LOGFILE} -D -P $PIDFILE" +DAEMON_OPTS="-a -n /var/lib/varnish -w ${LOGFILE} -D -P $PIDFILE" case "$1" in start) From des at projects.linpro.no Tue Jul 24 11:10:23 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 13:10:23 +0200 (CEST) Subject: r1744 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070724111023.264A81EC1F6@projects.linpro.no> Author: des Date: 2007-07-24 13:10:22 +0200 (Tue, 24 Jul 2007) New Revision: 1744 Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm Log: Regression test for #128 (currently fails with both trunk and 1.1) Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm 2007-07-24 11:10:22 UTC (rev 1744) @@ -0,0 +1,67 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# 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 +# in this position and unchanged. +# 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 THE 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. +# +# $Id$ +# + +package Varnish::Test::Case::Ticket128; + +use strict; +use base 'Varnish::Test::Case'; + +our $CODE = 400; +our $MESSAGE = "These are not the droids you are looking for"; + +our $VCL = <new_client; + my $request = HTTP::Request->new('GET', '/'); + $request->protocol('HTTP/1.0'); + $client->send_request($request, 2); + + my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Incorrect response code\n" + if $response->code != $CODE; + die "Incorrect response message\n" + if $response->message ne $MESSAGE; + + $client->shutdown(); + + return 'OK'; +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Tue Jul 24 11:39:55 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 13:39:55 +0200 (CEST) Subject: r1745 - trunk/varnish-cache/bin/varnishd Message-ID: <20070724113955.EF5221EC1F6@projects.linpro.no> Author: des Date: 2007-07-24 13:39:55 +0200 (Tue, 24 Jul 2007) New Revision: 1745 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Implement VRT_r_obj_status(), without which obj.status can't be read. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-24 11:10:22 UTC (rev 1744) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-24 11:39:55 UTC (rev 1745) @@ -234,6 +234,14 @@ http_SetH(&sp->obj->http, HTTP_HDR_STATUS, p); } +int +VRT_r_obj_status(struct sess *sp) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + return (atoi(sp->obj->http.hd[HTTP_HDR_STATUS].b)); +} + void VRT_l_resp_status(struct sess *sp, int num) { From des at projects.linpro.no Tue Jul 24 13:50:12 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 15:50:12 +0200 (CEST) Subject: r1746 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070724135012.52BE51EC030@projects.linpro.no> Author: des Date: 2007-07-24 15:50:12 +0200 (Tue, 24 Jul 2007) New Revision: 1746 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm Log: Actually, the message will be in the body. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm 2007-07-24 11:39:55 UTC (rev 1745) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm 2007-07-24 13:50:12 UTC (rev 1746) @@ -57,7 +57,7 @@ die "Incorrect response code\n" if $response->code != $CODE; die "Incorrect response message\n" - if $response->message ne $MESSAGE; + unless index($response->content, $MESSAGE); $client->shutdown(); From des at projects.linpro.no Tue Jul 24 13:51:29 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 15:51:29 +0200 (CEST) Subject: r1747 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070724135129.610DE1EC2A3@projects.linpro.no> Author: des Date: 2007-07-24 15:51:29 +0200 (Tue, 24 Jul 2007) New Revision: 1747 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm Log: Use a regexp search instead of index() Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm 2007-07-24 13:50:12 UTC (rev 1746) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm 2007-07-24 13:51:29 UTC (rev 1747) @@ -57,7 +57,7 @@ die "Incorrect response code\n" if $response->code != $CODE; die "Incorrect response message\n" - unless index($response->content, $MESSAGE); + unless $response->content =~ m/\Q$MESSAGE\E/o; $client->shutdown(); From des at projects.linpro.no Tue Jul 24 13:51:58 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 15:51:58 +0200 (CEST) Subject: r1748 - trunk/varnish-cache/bin/varnishd Message-ID: <20070724135158.F30091EC030@projects.linpro.no> Author: des Date: 2007-07-24 15:51:58 +0200 (Tue, 24 Jul 2007) New Revision: 1748 Modified: trunk/varnish-cache/bin/varnishd/cache_synthetic.c Log: Correct a comment Modified: trunk/varnish-cache/bin/varnishd/cache_synthetic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2007-07-24 13:51:29 UTC (rev 1747) +++ trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2007-07-24 13:51:58 UTC (rev 1748) @@ -131,5 +131,5 @@ http_PrintfHeader(w, fd, h, "Retry-After: %ju", (uintmax_t)ttl); http_PrintfHeader(w, fd, h, "Content-Type: text/html; charset=utf-8"); http_PrintfHeader(w, fd, h, "Content-Length: %u", o->len); - /* DO NOT generate X-Varnish header, RES_WriteObj will */ + /* DO NOT generate X-Varnish header, RES_BuildHttp will */ } From des at projects.linpro.no Tue Jul 24 13:52:40 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 15:52:40 +0200 (CEST) Subject: r1749 - trunk/varnish-cache/bin/varnishd Message-ID: <20070724135240.B55121EC2A3@projects.linpro.no> Author: des Date: 2007-07-24 15:52:40 +0200 (Tue, 24 Jul 2007) New Revision: 1749 Modified: trunk/varnish-cache/bin/varnishd/cache_http.c Log: Use strlen() directly. Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-24 13:51:58 UTC (rev 1748) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-07-24 13:52:40 UTC (rev 1749) @@ -884,13 +884,11 @@ static void http_PutField(struct worker *w, int fd, struct http *to, int field, const char *string) { - const char *e; char *p; int l; CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - e = strchr(string, '\0'); - l = (e - string); + l = strlen(string); p = WS_Alloc(to->ws, l + 1); if (p == NULL) { WSL(w, SLT_LostHeader, fd, "%s", string); From des at projects.linpro.no Tue Jul 24 13:54:21 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 15:54:21 +0200 (CEST) Subject: r1750 - trunk/varnish-cache/bin/varnishd Message-ID: <20070724135421.25AEF1EC030@projects.linpro.no> Author: des Date: 2007-07-24 15:54:20 +0200 (Tue, 24 Jul 2007) New Revision: 1750 Modified: trunk/varnish-cache/bin/varnishd/cache_response.c Log: Always generate a Connection: header, in case the client makes an incorrect assumption about which is the default. Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-24 13:52:40 UTC (rev 1749) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-24 13:54:20 UTC (rev 1750) @@ -76,8 +76,8 @@ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid); TIM_format(sp->obj->last_modified, lm); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Last-Modified: %s", lm); - if (sp->doclose != NULL) - http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); + http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Connection: %s", + sp->doclose ? "close" : "keep-alive"); sp->wantbody = 0; } @@ -129,8 +129,8 @@ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %.0f", sp->obj->age + sp->t_resp - sp->obj->entered); http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish"); - if (sp->doclose != NULL) - http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); + http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Connection: %s", + sp->doclose ? "close" : "keep-alive"); } /*--------------------------------------------------------------------*/ From des at projects.linpro.no Tue Jul 24 13:56:44 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 15:56:44 +0200 (CEST) Subject: r1751 - trunk/varnish-cache/bin/varnishd Message-ID: <20070724135644.745E01EC033@projects.linpro.no> Author: des Date: 2007-07-24 15:56:44 +0200 (Tue, 24 Jul 2007) New Revision: 1751 Modified: trunk/varnish-cache/bin/varnishd/cache_response.c Log: RES_BuildHttp() must be called before RES_WriteObj() to prepare the response headers. This fixes #128. Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-24 13:54:20 UTC (rev 1750) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2007-07-24 13:56:44 UTC (rev 1751) @@ -50,6 +50,7 @@ /* synthesize error page and send it */ SYN_ErrorPage(sp, code, reason, 0); + RES_BuildHttp(sp); RES_WriteObj(sp); /* GC the error page */ From des at projects.linpro.no Tue Jul 24 14:02:20 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 16:02:20 +0200 (CEST) Subject: r1752 - trunk/varnish-cache Message-ID: <20070724140220.D73041EC2A3@projects.linpro.no> Author: des Date: 2007-07-24 16:02:20 +0200 (Tue, 24 Jul 2007) New Revision: 1752 Modified: trunk/varnish-cache/Makefile.am Log: #131: Honor DESTDIR when creating the state directory. Modified: trunk/varnish-cache/Makefile.am =================================================================== --- trunk/varnish-cache/Makefile.am 2007-07-24 13:56:44 UTC (rev 1751) +++ trunk/varnish-cache/Makefile.am 2007-07-24 14:02:20 UTC (rev 1752) @@ -10,4 +10,4 @@ EXTRA_DIST = LICENSE autogen.sh varnishapi.pc.in install-data-local: - $(install_sh) -d -m 0755 $(localstatedir)/varnish + $(install_sh) -d -m 0755 $(DESTDIR)$(localstatedir)/varnish From des at projects.linpro.no Tue Jul 24 14:10:28 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 16:10:28 +0200 (CEST) Subject: r1753 - in trunk/varnish-cache/bin: varnishhist varnishstat varnishtop Message-ID: <20070724141028.5CBEA1EC033@projects.linpro.no> Author: des Date: 2007-07-24 16:10:28 +0200 (Tue, 24 Jul 2007) New Revision: 1753 Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishtop/varnishtop.c Log: #130: false is spelles FALSE in curses-land. Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2007-07-24 14:02:20 UTC (rev 1752) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2007-07-24 14:10:28 UTC (rev 1753) @@ -247,7 +247,7 @@ raw(); noecho(); nonl(); - intrflush(stdscr, false); + intrflush(stdscr, FALSE); curs_set(0); erase(); for (;;) { Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-07-24 14:02:20 UTC (rev 1752) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2007-07-24 14:10:28 UTC (rev 1753) @@ -78,7 +78,7 @@ raw(); noecho(); nonl(); - intrflush(stdscr, false); + intrflush(stdscr, FALSE); curs_set(0); erase(); Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-07-24 14:02:20 UTC (rev 1752) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2007-07-24 14:10:28 UTC (rev 1753) @@ -201,7 +201,7 @@ raw(); noecho(); nonl(); - intrflush(stdscr, false); + intrflush(stdscr, FALSE); curs_set(0); erase(); for (;;) { From des at projects.linpro.no Tue Jul 24 14:25:54 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 16:25:54 +0200 (CEST) Subject: r1754 - trunk/varnish-cache/bin/varnishreplay Message-ID: <20070724142554.333B11EC2A3@projects.linpro.no> Author: des Date: 2007-07-24 16:25:54 +0200 (Tue, 24 Jul 2007) New Revision: 1754 Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c Log: Instead of incorrectly assuming that a pthread_t can be meaningfully cast to an unsigned int (which triggered warnings on some 64-bit platforms) and printed with %08lx, incorrectly assume that it can be meaningfully cast to a void * and printed with %p. While still incorrect in general terms, the latter turns out to be correct on the specific systems that we care about. Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-07-24 14:10:28 UTC (rev 1753) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2007-07-24 14:25:54 UTC (rev 1754) @@ -145,7 +145,7 @@ if (lvl > debug) return; pthread_mutex_lock(&log_mutex); - fprintf(stderr, "%08x ", (unsigned int)pthread_self()); + fprintf(stderr, "%p ", (void *)pthread_self()); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); @@ -183,8 +183,8 @@ mailbox_destroy(&threads[fd]->mbox); freez(threads[fd]); } - thread_log(1, "thread %08x started\n", - (unsigned int)threads[fd]->thread_id); + thread_log(1, "thread %p started\n", + (void *)threads[fd]->thread_id); } return (threads[fd]); } @@ -204,8 +204,8 @@ return; mailbox_close(&threads[fd]->mbox); pthread_join(threads[fd]->thread_id, NULL); - thread_log(1, "thread %08x stopped\n", - (unsigned int)threads[fd]->thread_id); + thread_log(1, "thread %p stopped\n", + (void *)threads[fd]->thread_id); mailbox_destroy(&threads[fd]->mbox); freez(threads[fd]); } From des at projects.linpro.no Tue Jul 24 16:17:21 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 18:17:21 +0200 (CEST) Subject: r1755 - trunk/varnish-tools/nagios Message-ID: <20070724161721.86C771EC033@projects.linpro.no> Author: des Date: 2007-07-24 18:17:21 +0200 (Tue, 24 Jul 2007) New Revision: 1755 Modified: trunk/varnish-tools/nagios/configure.ac Log: Give this package a proper name and a version number. Modified: trunk/varnish-tools/nagios/configure.ac =================================================================== --- trunk/varnish-tools/nagios/configure.ac 2007-07-24 14:25:54 UTC (rev 1754) +++ trunk/varnish-tools/nagios/configure.ac 2007-07-24 16:17:21 UTC (rev 1755) @@ -3,7 +3,7 @@ AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2007 Linpro AS]) AC_REVISION([$Id$]) -AC_INIT([check_varnish], [trunk], [varnish-dev at projects.linpro.no]) +AC_INIT([nagios-varnish-plugin], [1.0], [varnish-dev at projects.linpro.no]) AC_CONFIG_SRCDIR(check_varnish.c) AM_CONFIG_HEADER(config.h) From des at projects.linpro.no Tue Jul 24 16:19:25 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 18:19:25 +0200 (CEST) Subject: r1756 - trunk/varnish-tools/nagios Message-ID: <20070724161925.03D691EC033@projects.linpro.no> Author: des Date: 2007-07-24 18:19:24 +0200 (Tue, 24 Jul 2007) New Revision: 1756 Removed: trunk/varnish-tools/nagios/autogen.des trunk/varnish-tools/nagios/autogen.sh Log: Remove symlinks Deleted: trunk/varnish-tools/nagios/autogen.des =================================================================== --- trunk/varnish-tools/nagios/autogen.des 2007-07-24 16:17:21 UTC (rev 1755) +++ trunk/varnish-tools/nagios/autogen.des 2007-07-24 16:19:24 UTC (rev 1756) @@ -1 +0,0 @@ -link ../../varnish-cache/autogen.des \ No newline at end of file Deleted: trunk/varnish-tools/nagios/autogen.sh =================================================================== --- trunk/varnish-tools/nagios/autogen.sh 2007-07-24 16:17:21 UTC (rev 1755) +++ trunk/varnish-tools/nagios/autogen.sh 2007-07-24 16:19:24 UTC (rev 1756) @@ -1 +0,0 @@ -link ../../varnish-cache/autogen.sh \ No newline at end of file From des at projects.linpro.no Tue Jul 24 16:20:04 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 18:20:04 +0200 (CEST) Subject: r1757 - trunk/varnish-tools/nagios Message-ID: <20070724162004.94BB71EC030@projects.linpro.no> Author: des Date: 2007-07-24 18:20:04 +0200 (Tue, 24 Jul 2007) New Revision: 1757 Added: trunk/varnish-tools/nagios/autogen.des trunk/varnish-tools/nagios/autogen.sh Log: Re-add as files Added: trunk/varnish-tools/nagios/autogen.des =================================================================== --- trunk/varnish-tools/nagios/autogen.des (rev 0) +++ trunk/varnish-tools/nagios/autogen.des 2007-07-24 16:20:04 UTC (rev 1757) @@ -0,0 +1,20 @@ +#!/bin/sh +# +# $Id$ +# + +set -ex + +. ./autogen.sh + +# autoconf prior to 2.62 has issues with zsh 4.2 and newer +export CONFIG_SHELL=/bin/sh + +./configure \ + --enable-developer-warnings \ + --enable-debugging-symbols \ + --enable-dependency-tracking \ + --enable-extra-developer-warnings \ + --enable-stack-protector \ + --enable-werror \ + --prefix=/opt/varnish Property changes on: trunk/varnish-tools/nagios/autogen.des ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Id Added: trunk/varnish-tools/nagios/autogen.sh =================================================================== --- trunk/varnish-tools/nagios/autogen.sh (rev 0) +++ trunk/varnish-tools/nagios/autogen.sh 2007-07-24 16:20:04 UTC (rev 1757) @@ -0,0 +1,46 @@ +#!/bin/sh +# +# $Id$ +# + +warn() { + echo "WARNING: $@" 1>&2 +} + +case `uname -s` in +Darwin) + LIBTOOLIZE=glibtoolize + ;; +FreeBSD) + LIBTOOLIZE=libtoolize + if [ -d /usr/local/gnu-autotools/bin ] ; then + PATH=/usr/local/gnu-autotools/bin:${PATH} + export PATH + FIX_BROKEN_FREEBSD_PORTS="-I /usr/local/share/aclocal" + fi + ;; +Linux) + LIBTOOLIZE=libtoolize + ;; +esac + +automake_version=$(automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+') +if [ -z "$automake_version" ] ; then + warn "unable to determine automake version" +else + case $automake_version in + 0.*|1.[0-8]|1.[0-8][.-]*) + warn "automake ($automake_version) detected; 1.9 or newer recommended" + ;; + *) + ;; + esac +fi + +set -ex + +aclocal ${FIX_BROKEN_FREEBSD_PORTS} +$LIBTOOLIZE --copy --force +autoheader +automake --add-missing --copy --foreign +autoconf Property changes on: trunk/varnish-tools/nagios/autogen.sh ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Id From des at projects.linpro.no Tue Jul 24 16:26:37 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 18:26:37 +0200 (CEST) Subject: r1758 - trunk/varnish-tools/nagios Message-ID: <20070724162637.DA7CA1EC2A3@projects.linpro.no> Author: des Date: 2007-07-24 18:26:36 +0200 (Tue, 24 Jul 2007) New Revision: 1758 Added: trunk/varnish-tools/nagios/LICENSE Log: License. Added: trunk/varnish-tools/nagios/LICENSE =================================================================== --- trunk/varnish-tools/nagios/LICENSE (rev 0) +++ trunk/varnish-tools/nagios/LICENSE 2007-07-24 16:26:36 UTC (rev 1758) @@ -0,0 +1,23 @@ +Copyright (c) 2007 Linpro AS +All rights reserved. + +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. From des at projects.linpro.no Tue Jul 24 16:42:37 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 18:42:37 +0200 (CEST) Subject: r1759 - trunk/varnish-tools/nagios Message-ID: <20070724164237.408481EC2A3@projects.linpro.no> Author: des Date: 2007-07-24 18:42:36 +0200 (Tue, 24 Jul 2007) New Revision: 1759 Modified: trunk/varnish-tools/nagios/Makefile.am trunk/varnish-tools/nagios/check_varnish.c Log: Cleanup, rename "hitrate" to "ratio" as in Munin plugin. Modified: trunk/varnish-tools/nagios/Makefile.am =================================================================== --- trunk/varnish-tools/nagios/Makefile.am 2007-07-24 16:26:36 UTC (rev 1758) +++ trunk/varnish-tools/nagios/Makefile.am 2007-07-24 16:42:36 UTC (rev 1759) @@ -7,3 +7,5 @@ check_varnish_CFLAGS = -include config.h ${VARNISHAPI_CFLAGS} check_varnish_LDADD = ${VARNISHAPI_LIBS} + +EXTRA_DIST = LICENSE autogen.sh Modified: trunk/varnish-tools/nagios/check_varnish.c =================================================================== --- trunk/varnish-tools/nagios/check_varnish.c 2007-07-24 16:26:36 UTC (rev 1758) +++ trunk/varnish-tools/nagios/check_varnish.c 2007-07-24 16:42:36 UTC (rev 1759) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2006-2007 Linpro AS + * Copyright (c) 2007 Linpro AS * All rights reserved. * * Author: Cecilie Fritzvold @@ -41,34 +41,36 @@ -/* Check if the tresholds against the value and return the - * appropriate status code. +/* + * Check if the tresholds against the value and return the appropriate + * status code. */ static int check_treshold(intmax_t value, int warn, int crit, int less) { + if (!less) { if (value < warn) - return 0; + return (0); else if (value < crit) - return 1; - } - else { + return (1); + } else { if (value > warn) - return 0; + return (0); else if (value > crit) - return 1; + return (1); } - return 2; - + return (2); } -/* Print the appriate message according to the status level. - * Exit with the correct return code. +/* + * Print the appriate message according to the status level. Exit with + * the correct return code. */ static void message_and_exit(int level, intmax_t value, const char *info) { + if (level == 0) printf("OK: "); else if (level == 1) @@ -77,25 +79,27 @@ printf("Critical: "); else printf("Uknown: "); - + printf("%ju %s\n", value, info); exit(level); } -/* Check the statistics for the requested parameter. +/* + * Check the statistics for the requested parameter. */ static void check_stats(struct varnish_stats *VSL_stats, char *param, int w, int c, int less) { int level; - double ratio = 0; - int64_t total; - if (!strcmp(param, "hitrate")) { - total = VSL_stats->cache_hit + VSL_stats->cache_miss; + + if (!strcmp(param, "ratio")) { + int64_t total = VSL_stats->cache_hit + VSL_stats->cache_miss; + double ratio = 0; + if (total > 0) - ratio = 100.0 * (double)VSL_stats->cache_hit / (double)total; + ratio = 100.0 * VSL_stats->cache_hit / total; level = check_treshold(ratio, w, c, less); - message_and_exit(level, ratio, "Hitrate ratio"); + message_and_exit(level, ratio, "Cache hit ratio"); } #define MAC_STAT(n, t, f, d) \ do { \ @@ -116,18 +120,23 @@ static void help(void) { - fprintf(stderr, "usage: check_varnish [-p param_name -c N -w N] [-l] [-n varnish_name] [-v]\n" - "Valid options:\n" - "-c N\t\t warn as critical at treshold N\n" - "-l\t\t specify that values should be less than tresholds for warnings to be issued\n" - "-n varnish_name\t specify varnish instance name\n" - "-p param_name\t specify the parameter to check. See valid parameters. Default is hitrate\n" - "-v\t\t print verbose output. Can be specified up to three times\n" - "-w N\t\t warn as warning at treshold N\n" - "Valid parameters\n" - "All names listed in the left column when running varnishstat -1 are valid parameters.\n" - "In addition, the following parameters are valid:\n" - "hitrate\t The hitrate ratio. Will be between 0 and 100. Default tresholds are 95 and 90.\n" + fprintf(stderr, "usage: " + "check_varnish [-l] [-n varnish_name] [-p param_name [-c N] [-w N]]\n" + "\n" + "-l Warn when the measured value is less, not more,\n" + " than the configured threshold.\n" + "-n varnish_name Specify the Varnish instance name\n" + "-p param_name Specify the parameter to check (see below).\n" + " Default is 'ratio'.\n" + "-c N Set critical treshold to N\n" + "-w N Set warning threshold to N\n" + "\n" + "All items reported by varnishstat(1) are available - use the\n" + "identifier listed in the left column by 'varnishstat -l'. In\n" + "addition, the following parameters are available:\n" + "\n" + "ratio The cache hit ratio expressed as a percentage of hits to\n" + " hits + misses. Default thresholds are 95 and 90.\n" ); exit(0); } @@ -135,7 +144,9 @@ static void usage(void) { - fprintf(stderr, "usage: check_varnish [-p param_name -c N -w N] [-l] [-n varnish_name] [-v]\n"); + + fprintf(stderr, "usage: " + "check_varnish [-l] [-n varnish_name] [-p param_name [-c N] [-w N]]\n"); exit(3); } @@ -143,21 +154,21 @@ int main(int argc, char **argv) { - int c; struct varnish_stats *VSL_stats; int critical = 0, warning = 0; - int verbose = 0; const char *n_arg = NULL; char *param = NULL; int less = 0; + int opt; - while ((c = getopt(argc, argv, "c:hln:p:vw:")) != -1) { - switch (c) { + while ((opt = getopt(argc, argv, "c:hln:p:w:")) != -1) { + switch (opt) { case 'c': critical = atoi(optarg); break; case 'h': help(); + break; case 'l': less = 1; break; @@ -167,9 +178,6 @@ case 'p': param = strdup(optarg); break; - case 'v': - verbose++; - break; case 'w': warning = atoi(optarg); break; @@ -181,22 +189,21 @@ if ((VSL_stats = VSL_OpenStats(n_arg)) == NULL) exit(1); - /* Default: if no param specified, check hitratio. - * If no warning and critical values are specified either, - * set these to default + /* Default: if no param specified, check hit ratio. If no warning + * and critical values are specified either, set these to default. */ if (param == NULL) { - param = strdup("hitrate"); + param = strdup("ratio"); if (!warning && !critical) { warning = 95; critical = 90; less = 1; } } - + if (!param || (!critical && !warning)) usage(); - + check_stats(VSL_stats, param, warning, critical, less); exit(0); From des at projects.linpro.no Tue Jul 24 16:44:11 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 24 Jul 2007 18:44:11 +0200 (CEST) Subject: r1760 - tags Message-ID: <20070724164411.CD9F31EC033@projects.linpro.no> Author: des Date: 2007-07-24 18:44:11 +0200 (Tue, 24 Jul 2007) New Revision: 1760 Added: tags/nagios-varnish-plugin-1.0/ Log: Tag our Nagios plugin for release. Copied: tags/nagios-varnish-plugin-1.0 (from rev 1759, trunk/varnish-tools/nagios) From cecilihf at projects.linpro.no Wed Jul 25 08:39:10 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Wed, 25 Jul 2007 10:39:10 +0200 (CEST) Subject: r1761 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070725083910.DA3791EC030@projects.linpro.no> Author: cecilihf Date: 2007-07-25 10:39:10 +0200 (Wed, 25 Jul 2007) New Revision: 1761 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Implemented http purge with regexp. Example vcl usage: sub vcl_recv { if (req.request == "REPURGE") { purge(req.url); error 404 "Purged"; } } Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2007-07-24 16:44:11 UTC (rev 1760) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2007-07-25 08:39:10 UTC (rev 1761) @@ -40,6 +40,7 @@ #include "shmlog.h" #include "cli_priv.h" #include "cache.h" +#include "vrt.h" struct ban { TAILQ_ENTRY(ban) list; @@ -114,3 +115,9 @@ AddBan("a"); } + +void +VRT_repurge(const char *regexp) +{ + AddBan(regexp); +} Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-07-24 16:44:11 UTC (rev 1760) +++ trunk/varnish-cache/include/vrt.h 2007-07-25 08:39:10 UTC (rev 1761) @@ -70,6 +70,8 @@ int VRT_re_test(struct vsb *, const char *, int sub); const char *VRT_regsub(struct sess *sp, const char *, void *, const char *); +void VRT_repurge(const char *); + void VRT_count(struct sess *, unsigned); int VRT_rewrite(const char *, const char *); void VRT_error(struct sess *, unsigned, const char *); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-24 16:44:11 UTC (rev 1760) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-25 08:39:10 UTC (rev 1761) @@ -263,6 +263,28 @@ /*--------------------------------------------------------------------*/ +static void +parse_repurge(struct tokenlist *tl) +{ + vcc_NextToken(tl); + + Fb(tl, 0, "VRT_repurge("); + + Expect(tl, '('); + vcc_NextToken(tl); + + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + } + + Expect(tl, ')'); + vcc_NextToken(tl); + Fb(tl, 0, ");"); +} + + +/*--------------------------------------------------------------------*/ + typedef void action_f(struct tokenlist *tl); static struct action_table { @@ -277,6 +299,7 @@ { "call", parse_call }, { "set", parse_set }, { "remove", parse_remove }, + { "purge", parse_repurge }, { NULL, NULL } }; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-24 16:44:11 UTC (rev 1760) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-25 08:39:10 UTC (rev 1761) @@ -426,6 +426,8 @@ vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); vsb_cat(sb, "const char *VRT_regsub(struct sess *sp, const char *, void *, const char *);\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "void VRT_repurge(const char *);\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, "void VRT_count(struct sess *, unsigned);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n"); From cecilihf at projects.linpro.no Wed Jul 25 08:53:16 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Wed, 25 Jul 2007 10:53:16 +0200 (CEST) Subject: r1762 - trunk/varnish-cache/man Message-ID: <20070725085316.8241E1EC2A3@projects.linpro.no> Author: cecilihf Date: 2007-07-25 10:53:16 +0200 (Wed, 25 Jul 2007) New Revision: 1762 Modified: trunk/varnish-cache/man/vcl.7 Log: Updated man page Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-07-25 08:39:10 UTC (rev 1761) +++ trunk/varnish-cache/man/vcl.7 2007-07-25 08:53:16 UTC (rev 1762) @@ -136,6 +136,9 @@ is replaced with the contents of subgroup .Ar n in the matched string. +.It Fn purge "regex" +Purge all objects in cache matching +.Fa regex . .El .Ss Subroutines A subroutine is used to group code for legibility or reusability: From des at projects.linpro.no Wed Jul 25 11:04:50 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 25 Jul 2007 13:04:50 +0200 (CEST) Subject: r1763 - trunk/varnish-tools/nagios Message-ID: <20070725110450.631491EC033@projects.linpro.no> Author: des Date: 2007-07-25 13:04:50 +0200 (Wed, 25 Jul 2007) New Revision: 1763 Modified: trunk/varnish-tools/nagios/check_varnish.c Log: Style fixes Modified: trunk/varnish-tools/nagios/check_varnish.c =================================================================== --- trunk/varnish-tools/nagios/check_varnish.c 2007-07-25 08:53:16 UTC (rev 1762) +++ trunk/varnish-tools/nagios/check_varnish.c 2007-07-25 11:04:50 UTC (rev 1763) @@ -92,8 +92,8 @@ { int level; - if (!strcmp(param, "ratio")) { - int64_t total = VSL_stats->cache_hit + VSL_stats->cache_miss; + if (strcmp(param, "ratio") == 0) { + intmax_t total = VSL_stats->cache_hit + VSL_stats->cache_miss; double ratio = 0; if (total > 0) @@ -102,16 +102,15 @@ message_and_exit(level, ratio, "Cache hit ratio"); } #define MAC_STAT(n, t, f, d) \ - do { \ - intmax_t ju = VSL_stats->n; \ - if (!strcmp(param, #n)) { \ - level = check_treshold(ju, w, c, less); \ - message_and_exit(level, ju, d); \ - } \ - } while (0); + else if (strcmp(param, #n) == 0) { \ + intmax_t val = VSL_stats->n; \ + level = check_treshold(val, w, c, less); \ + message_and_exit(level, val, d); \ + } #include "stat_field.h" #undef MAC_STAT - printf("Invalid parameter: %s\n", param); + else + printf("Unknown parameter '%s'\n", param); exit(3); } @@ -120,6 +119,7 @@ static void help(void) { + fprintf(stderr, "usage: " "check_varnish [-l] [-n varnish_name] [-p param_name [-c N] [-w N]]\n" "\n" From des at projects.linpro.no Wed Jul 25 11:08:24 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 25 Jul 2007 13:08:24 +0200 (CEST) Subject: r1764 - trunk/varnish-tools/nagios Message-ID: <20070725110824.543941EC030@projects.linpro.no> Author: des Date: 2007-07-25 13:08:24 +0200 (Wed, 25 Jul 2007) New Revision: 1764 Modified: trunk/varnish-tools/nagios/check_varnish.c Log: Typo. Modified: trunk/varnish-tools/nagios/check_varnish.c =================================================================== --- trunk/varnish-tools/nagios/check_varnish.c 2007-07-25 11:04:50 UTC (rev 1763) +++ trunk/varnish-tools/nagios/check_varnish.c 2007-07-25 11:08:24 UTC (rev 1764) @@ -39,14 +39,12 @@ #include "shmlog.h" #include "varnishapi.h" - - /* - * Check if the tresholds against the value and return the appropriate + * Check if the thresholds against the value and return the appropriate * status code. */ static int -check_treshold(intmax_t value, int warn, int crit, int less) +check_threshold(intmax_t value, int warn, int crit, int less) { if (!less) { @@ -98,13 +96,13 @@ if (total > 0) ratio = 100.0 * VSL_stats->cache_hit / total; - level = check_treshold(ratio, w, c, less); + level = check_threshold(ratio, w, c, less); message_and_exit(level, ratio, "Cache hit ratio"); } #define MAC_STAT(n, t, f, d) \ else if (strcmp(param, #n) == 0) { \ intmax_t val = VSL_stats->n; \ - level = check_treshold(val, w, c, less); \ + level = check_threshold(val, w, c, less); \ message_and_exit(level, val, d); \ } #include "stat_field.h" @@ -128,7 +126,7 @@ "-n varnish_name Specify the Varnish instance name\n" "-p param_name Specify the parameter to check (see below).\n" " Default is 'ratio'.\n" - "-c N Set critical treshold to N\n" + "-c N Set critical threshold to N\n" "-w N Set warning threshold to N\n" "\n" "All items reported by varnishstat(1) are available - use the\n" From cecilihf at projects.linpro.no Wed Jul 25 11:09:06 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Wed, 25 Jul 2007 13:09:06 +0200 (CEST) Subject: r1765 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070725110906.39A541EC033@projects.linpro.no> Author: cecilihf Date: 2007-07-25 13:09:06 +0200 (Wed, 25 Jul 2007) New Revision: 1765 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Use purge in function names instead of repurge and move VRT_purge to cache_vrt.c. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-25 11:08:24 UTC (rev 1764) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-25 11:09:06 UTC (rev 1765) @@ -360,6 +360,7 @@ void vbe_free_bereq(struct bereq *bereq); /* cache_ban.c */ +void AddBan(const char *); void BAN_Init(void); void cli_func_url_purge(struct cli *cli, char **av, void *priv); void BAN_NewObj(struct object *o); Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2007-07-25 11:08:24 UTC (rev 1764) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2007-07-25 11:09:06 UTC (rev 1765) @@ -40,7 +40,6 @@ #include "shmlog.h" #include "cli_priv.h" #include "cache.h" -#include "vrt.h" struct ban { TAILQ_ENTRY(ban) list; @@ -53,7 +52,7 @@ static unsigned ban_next; static struct ban *ban_start; -static void +void AddBan(const char *regexp) { struct ban *b; @@ -115,9 +114,3 @@ AddBan("a"); } - -void -VRT_repurge(const char *regexp) -{ - AddBan(regexp); -} Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-25 11:08:24 UTC (rev 1764) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-25 11:09:06 UTC (rev 1765) @@ -513,3 +513,12 @@ strcat(q, p); return (q); } + +/*--------------------------------------------------------------------*/ + +void +VRT_purge(const char *regexp) +{ + + AddBan(regexp); +} Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-07-25 11:08:24 UTC (rev 1764) +++ trunk/varnish-cache/include/vrt.h 2007-07-25 11:09:06 UTC (rev 1765) @@ -70,7 +70,7 @@ int VRT_re_test(struct vsb *, const char *, int sub); const char *VRT_regsub(struct sess *sp, const char *, void *, const char *); -void VRT_repurge(const char *); +void VRT_purge(const char *); void VRT_count(struct sess *, unsigned); int VRT_rewrite(const char *, const char *); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-25 11:08:24 UTC (rev 1764) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-25 11:09:06 UTC (rev 1765) @@ -264,11 +264,11 @@ /*--------------------------------------------------------------------*/ static void -parse_repurge(struct tokenlist *tl) +parse_purge(struct tokenlist *tl) { vcc_NextToken(tl); - Fb(tl, 0, "VRT_repurge("); + Fb(tl, 0, "VRT_purge("); Expect(tl, '('); vcc_NextToken(tl); @@ -299,7 +299,7 @@ { "call", parse_call }, { "set", parse_set }, { "remove", parse_remove }, - { "purge", parse_repurge }, + { "purge", parse_purge }, { NULL, NULL } }; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-25 11:08:24 UTC (rev 1764) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-25 11:09:06 UTC (rev 1765) @@ -426,7 +426,7 @@ vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); vsb_cat(sb, "const char *VRT_regsub(struct sess *sp, const char *, void *, const char *);\n"); vsb_cat(sb, "\n"); - vsb_cat(sb, "void VRT_repurge(const char *);\n"); + vsb_cat(sb, "void VRT_purge(const char *);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "void VRT_count(struct sess *, unsigned);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); From cecilihf at projects.linpro.no Wed Jul 25 11:10:59 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Wed, 25 Jul 2007 13:10:59 +0200 (CEST) Subject: r1766 - trunk/varnish-cache/lib/libvcl Message-ID: <20070725111059.4AEA91EC030@projects.linpro.no> Author: cecilihf Date: 2007-07-25 13:10:59 +0200 (Wed, 25 Jul 2007) New Revision: 1766 Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c Log: Style... Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-25 11:09:06 UTC (rev 1765) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-25 11:10:59 UTC (rev 1766) @@ -266,6 +266,7 @@ static void parse_purge(struct tokenlist *tl) { + vcc_NextToken(tl); Fb(tl, 0, "VRT_purge("); From des at projects.linpro.no Wed Jul 25 11:13:32 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 25 Jul 2007 13:13:32 +0200 (CEST) Subject: r1767 - trunk/varnish-tools/nagios Message-ID: <20070725111332.81F751EC033@projects.linpro.no> Author: des Date: 2007-07-25 13:13:32 +0200 (Wed, 25 Jul 2007) New Revision: 1767 Modified: trunk/varnish-tools/nagios/check_varnish.c Log: Add a "usage" parameter which reports cache file usage. Modified: trunk/varnish-tools/nagios/check_varnish.c =================================================================== --- trunk/varnish-tools/nagios/check_varnish.c 2007-07-25 11:10:59 UTC (rev 1766) +++ trunk/varnish-tools/nagios/check_varnish.c 2007-07-25 11:13:32 UTC (rev 1767) @@ -99,6 +99,15 @@ level = check_threshold(ratio, w, c, less); message_and_exit(level, ratio, "Cache hit ratio"); } + if (strcmp(param, "usage") == 0) { + intmax_t total = VSL_stats->sm_balloc + VSL_stats->sm_bfree; + double ratio = 0; + + if (total > 0) + ratio = 100.0 * VSL_stats->sm_balloc / total; + level = check_threshold(ratio, w, c, less); + message_and_exit(level, ratio, "Cache file usage"); + } #define MAC_STAT(n, t, f, d) \ else if (strcmp(param, #n) == 0) { \ intmax_t val = VSL_stats->n; \ @@ -135,6 +144,7 @@ "\n" "ratio The cache hit ratio expressed as a percentage of hits to\n" " hits + misses. Default thresholds are 95 and 90.\n" + "usage Cache file usage as a percentage of the total cache space.\n" ); exit(0); } From des at projects.linpro.no Wed Jul 25 11:16:43 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 25 Jul 2007 13:16:43 +0200 (CEST) Subject: r1768 - trunk/varnish-tools/munin Message-ID: <20070725111643.2011A1EC030@projects.linpro.no> Author: des Date: 2007-07-25 13:16:42 +0200 (Wed, 25 Jul 2007) New Revision: 1768 Modified: trunk/varnish-tools/munin/varnish_munin_plugin.pl Log: Set x bit. Property changes on: trunk/varnish-tools/munin/varnish_munin_plugin.pl ___________________________________________________________________ Name: svn:executable + * From des at projects.linpro.no Wed Jul 25 11:52:51 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 25 Jul 2007 13:52:51 +0200 (CEST) Subject: r1769 - trunk/varnish-tools/munin Message-ID: <20070725115251.77CBB1EC3E3@projects.linpro.no> Author: des Date: 2007-07-25 13:52:51 +0200 (Wed, 25 Jul 2007) New Revision: 1769 Modified: trunk/varnish-tools/munin/varnish_munin_plugin.pl Log: Allow values to be specified as arithmetic expressions written in Lisp-like prefix notation. Use this to compute the cache hit ratio in the same manner as the Nagios plugin does, and to compute cache file usage. Modified: trunk/varnish-tools/munin/varnish_munin_plugin.pl =================================================================== --- trunk/varnish-tools/munin/varnish_munin_plugin.pl 2007-07-25 11:16:42 UTC (rev 1768) +++ trunk/varnish-tools/munin/varnish_munin_plugin.pl 2007-07-25 11:52:51 UTC (rev 1769) @@ -37,24 +37,63 @@ 'ratio' => { 'title' => 'Hit / miss ratio', 'type' => 'percent', + 'order' => [ 'hit', 'miss' ], 'values' => { 'hit' => { 'label' => 'hits', 'numerator' => 'cache_hit', - 'denominator' => 'client_req', + 'denominator' => [ '+', 'cache_hit', 'cache_miss' ], }, 'miss' => { 'label' => 'misses', 'numerator' => 'cache_miss', - 'denominator' => 'client_req', + 'denominator' => [ '+', 'cache_hit', 'cache_miss' ], }, }, }, + 'usage' => { + 'title' => 'Cache file usage', + 'type' => 'percent', + 'order' => [ 'used', 'free' ], + 'values' => { + 'used' => { + 'label' => 'used', + 'numerator' => 'sm_balloc', + 'denominator' => [ '+', 'sm_balloc', 'sm_bfree' ], + }, + 'free' => { + 'label' => 'free', + 'numerator' => 'sm_bfree', + 'denominator' => [ '+', 'sm_balloc', 'sm_bfree' ], + }, + }, + }, ); +sub varnishstat($); sub varnishstat($) { my $field = shift; + if (ref($field) eq 'ARRAY') { + die "Too few terms in $field" + if @$field < 2; + my $acc = varnishstat($$field[1]); + + foreach (@$field[2..$#$field]) { + if ($$field[0] eq '+') { + $acc += varnishstat($_); + } elsif ($$field[0] eq '-') { + $acc -= varnishstat($_); + } elsif ($$field[0] eq '*') { + $acc *= varnishstat($_); + } elsif ($$field[0] eq '/') { + $acc /= varnishstat($_); + } else { + die "Invalid spec for $field\n"; + } + } + return $acc; + } die "no such field: $field\n" unless defined($varnishstat{$field}); return $varnishstat{$field}; @@ -80,11 +119,19 @@ } } +sub order($) { + my $aspect = shift; + + return (@{$aspect->{'order'}}) + if (defined($aspect->{'order'})); + return (sort(keys(%{$aspect->{'values'}}))); +} + sub measure($) { my $aspect = shift; defined($aspect) || die "oops"; - my @order = $aspect->{'order'} || sort(keys(%{$aspect->{'values'}})); + my @order = order($aspect); foreach (@order) { print "$_.value ", value($aspect->{'values'}->{$_}, $aspect->{'type'}), @@ -101,7 +148,7 @@ if ($aspect->{'type'} eq 'percent') { print "graph_scale no\n"; } - my @order = $aspect->{'order'} || sort(keys(%{$aspect->{'values'}})); + my @order = order($aspect); print "graph_order ", join(' ', @order), "\n"; foreach (@order) { my $value = $aspect->{'values'}->{$_}; From des at projects.linpro.no Wed Jul 25 12:49:21 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 25 Jul 2007 14:49:21 +0200 (CEST) Subject: r1770 - trunk/varnish-tools/nagios Message-ID: <20070725124921.A1F331EC3E3@projects.linpro.no> Author: des Date: 2007-07-25 14:49:21 +0200 (Wed, 25 Jul 2007) New Revision: 1770 Modified: trunk/varnish-tools/nagios/check_varnish.c Log: Implement the full range syntax, eliminating the need for -l. Also reintroduce -v, which is required by the spec (though we do not use it). Modified: trunk/varnish-tools/nagios/check_varnish.c =================================================================== --- trunk/varnish-tools/nagios/check_varnish.c 2007-07-25 11:52:51 UTC (rev 1769) +++ trunk/varnish-tools/nagios/check_varnish.c 2007-07-25 12:49:21 UTC (rev 1770) @@ -30,6 +30,9 @@ * Nagios plugin for Varnish */ +#include +#include +#include #include #include #include @@ -39,86 +42,157 @@ #include "shmlog.h" #include "varnishapi.h" +static int verbose = 0; + +struct range { + intmax_t lo; + intmax_t hi; + int inverted:1; + int defined:1; +}; + +static struct range critical; +static struct range warning; + +enum { + NAGIOS_OK = 0, + NAGIOS_WARNING = 1, + NAGIOS_CRITICAL = 2, + NAGIOS_UNKNOWN = 3, +}; + +static const char *status_text[] = { + [NAGIOS_OK] = "OK", + [NAGIOS_WARNING] = "WARNING", + [NAGIOS_CRITICAL] = "CRITICAL", + [NAGIOS_UNKNOWN] = "UNKNOWN", +}; + /* - * Check if the thresholds against the value and return the appropriate - * status code. + * Parse a range specification */ static int -check_threshold(intmax_t value, int warn, int crit, int less) +parse_range(const char *spec, struct range *range) { + const char *delim; + char *end; - if (!less) { - if (value < warn) - return (0); - else if (value < crit) - return (1); + /* @ means invert the range */ + if (*spec == '@') { + ++spec; + range->inverted = 1; } else { - if (value > warn) - return (0); - else if (value > crit) - return (1); + range->inverted = 0; } - return (2); + + /* empty spec... */ + if (*spec == '\0') + return (-1); + + if ((delim = strchr(spec, ':')) != NULL) { + /* + * The Nagios plugin documentation says nothing about how + * to interpret ":N", so we disallow it. Allowed forms + * are "~:N", "~:", "M:" and "M:N". + */ + if (delim - spec == 1 && *spec == '~') { + range->lo = INTMAX_MIN; + } else { + range->lo = strtoimax(spec, &end, 10); + if (end != delim) + return (-1); + } + if (*(delim + 1) != '\0') { + range->hi = strtoimax(delim + 1, &end, 10); + if (*end != '\0') + return (-1); + } else { + range->hi = INTMAX_MAX; + } + } else { + /* + * Allowed forms are N + */ + range->lo = 0; + range->hi = strtol(spec, &end, 10); + if (*end != '\0') + return (-1); + } + + /* + * Sanity + */ + if (range->lo > range->hi) + return (-1); + + range->defined = 1; + return (0); } /* - * Print the appriate message according to the status level. Exit with - * the correct return code. + * Check if a given value is within a given range. */ -static void -message_and_exit(int level, intmax_t value, const char *info) +static int +inside_range(intmax_t value, const struct range *range) { - if (level == 0) - printf("OK: "); - else if (level == 1) - printf("Warning: "); - else if (level == 2) - printf("Critical: "); - else - printf("Uknown: "); + if (range->inverted) + return (value < range->lo || value > range->hi); + return (value >= range->lo && value <= range->hi); +} - printf("%ju %s\n", value, info); - exit(level); +/* + * Check if the thresholds against the value and return the appropriate + * status code. + */ +static int +check_thresholds(intmax_t value) +{ + + if (!warning.defined && !critical.defined) + return (NAGIOS_UNKNOWN); + if (critical.defined && !inside_range(value, &critical)) + return (NAGIOS_CRITICAL); + if (warning.defined && !inside_range(value, &warning)) + return (NAGIOS_WARNING); + return (NAGIOS_OK); } /* * Check the statistics for the requested parameter. */ static void -check_stats(struct varnish_stats *VSL_stats, char *param, int w, int c, int less) +check_stats(struct varnish_stats *VSL_stats, char *param) { - int level; + const char *info; + intmax_t value; + int status; if (strcmp(param, "ratio") == 0) { intmax_t total = VSL_stats->cache_hit + VSL_stats->cache_miss; - double ratio = 0; - if (total > 0) - ratio = 100.0 * VSL_stats->cache_hit / total; - level = check_threshold(ratio, w, c, less); - message_and_exit(level, ratio, "Cache hit ratio"); + value = total ? (100 * VSL_stats->cache_hit / total) : 0; + info = "Cache hit ratio"; } - if (strcmp(param, "usage") == 0) { + else if (strcmp(param, "usage") == 0) { intmax_t total = VSL_stats->sm_balloc + VSL_stats->sm_bfree; - double ratio = 0; - if (total > 0) - ratio = 100.0 * VSL_stats->sm_balloc / total; - level = check_threshold(ratio, w, c, less); - message_and_exit(level, ratio, "Cache file usage"); + value = total ? (100 * VSL_stats->sm_balloc / total) : 0; + info = "Cache file usage"; } #define MAC_STAT(n, t, f, d) \ else if (strcmp(param, #n) == 0) { \ - intmax_t val = VSL_stats->n; \ - level = check_threshold(val, w, c, less); \ - message_and_exit(level, val, d); \ + value = VSL_stats->n; \ + info = d; \ } #include "stat_field.h" #undef MAC_STAT else printf("Unknown parameter '%s'\n", param); - exit(3); + + status = check_thresholds(value); + printf("VARNISH %s: %s|%s=%jd\n", status_text[status], info, param, value); + exit(status); } /*-------------------------------------------------------------------------------*/ @@ -128,15 +202,14 @@ { fprintf(stderr, "usage: " - "check_varnish [-l] [-n varnish_name] [-p param_name [-c N] [-w N]]\n" + "check_varnish [-lv] [-n varnish_name] [-p param_name [-c N] [-w N]]\n" "\n" - "-l Warn when the measured value is less, not more,\n" - " than the configured threshold.\n" + "-v Increase verbosity.\n" "-n varnish_name Specify the Varnish instance name\n" "-p param_name Specify the parameter to check (see below).\n" - " Default is 'ratio'.\n" - "-c N Set critical threshold to N\n" - "-w N Set warning threshold to N\n" + " The default is 'ratio'.\n" + "-c [@][lo:]hi Set critical threshold\n" + "-w [@][lo:]hi Set warning threshold\n" "\n" "All items reported by varnishstat(1) are available - use the\n" "identifier listed in the left column by 'varnishstat -l'. In\n" @@ -154,7 +227,7 @@ { fprintf(stderr, "usage: " - "check_varnish [-l] [-n varnish_name] [-p param_name [-c N] [-w N]]\n"); + "check_varnish [-lv] [-n varnish_name] [-p param_name [-c N] [-w N]]\n"); exit(3); } @@ -163,31 +236,31 @@ main(int argc, char **argv) { struct varnish_stats *VSL_stats; - int critical = 0, warning = 0; const char *n_arg = NULL; char *param = NULL; - int less = 0; int opt; - while ((opt = getopt(argc, argv, "c:hln:p:w:")) != -1) { + while ((opt = getopt(argc, argv, "c:hn:p:vw:")) != -1) { switch (opt) { case 'c': - critical = atoi(optarg); + if (parse_range(optarg, &critical) != 0) + usage(); break; case 'h': help(); break; - case 'l': - less = 1; - break; case 'n': n_arg = optarg; break; case 'p': param = strdup(optarg); break; + case 'v': + ++verbose; + break; case 'w': - warning = atoi(optarg); + if (parse_range(optarg, &warning) != 0) + usage(); break; default: usage(); @@ -202,17 +275,16 @@ */ if (param == NULL) { param = strdup("ratio"); - if (!warning && !critical) { - warning = 95; - critical = 90; - less = 1; - } + if (!warning.defined) + parse_range("95:", &warning); + if (!critical.defined) + parse_range("90:", &critical); } - if (!param || (!critical && !warning)) + if (!param) usage(); - check_stats(VSL_stats, param, warning, critical, less); + check_stats(VSL_stats, param); exit(0); } From cecilihf at projects.linpro.no Thu Jul 26 07:02:21 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Thu, 26 Jul 2007 09:02:21 +0200 (CEST) Subject: r1771 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070726070221.4BDBC1EC030@projects.linpro.no> Author: cecilihf Date: 2007-07-26 09:02:20 +0200 (Thu, 26 Jul 2007) New Revision: 1771 Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm Log: Regression test for http purge with regexp Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm 2007-07-26 07:02:20 UTC (rev 1771) @@ -0,0 +1,146 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# 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 +# in this position and unchanged. +# 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 THE 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. +# +# $Id$ +# + +package Varnish::Test::Case::HTTPregexPurge; + +use strict; +use base 'Varnish::Test::Case'; + +use Data::Dumper; + +our $VCL = <new_client; + #for (my $i = 0; $i < 2; $i++) { + my $get_p_request = HTTP::Request->new('GET', '/purge'); + $get_p_request->protocol('HTTP/1.1'); + my $get_k_request = HTTP::Request->new('GET', '/keep'); + $get_k_request->protocol('HTTP/1.1'); + my $purge_request = HTTP::Request->new('REPURGE', '/purge'); + $purge_request->protocol('HTTP/1.1'); + + + # Fetch the two pages, so they'll get cached + $client->send_request($get_p_request, 2); + my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + + $client->send_request($get_k_request, 2); + my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + + + # Check that the purge page is cached + $client->send_request($get_p_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + die "Not cached\n" + if $response->header('x-varnish') !~ /\d+ \d+/; + + + # Purge the purge page + $client->send_request($purge_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + # For some reason it times out on the first attempt, so we have to run the + # loop an extra time to get the response. Could this be a bug in the framework? + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout') + if $event eq 'ev_client_timeout'; + + + # Check that the purge page is no longer cached + $client->send_request($get_p_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + die "Still Cached\n" + if $response->header('x-varnish') =~ /\d+ \d+/; + + + # Check that the keep page is still cached + $client->send_request($get_k_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + die "Still Cached\n" + if $response->header('x-varnish') !~ /\d+ \d+/; + + + $client->shutdown(); + + return 'OK'; +} + +sub ev_server_request($$$$) { + my ($self, $server, $connection, $request) = @_; + my $body = ""; + + # Return the right content + if ($request->uri =~ /purge/) { + $body = $body_p; + } + elsif ($request->uri =~ /keep/) { + $body = $body_k; + } + + my $response = HTTP::Response->new(200, undef, + [ 'Content-Length', length($body), + 'Connection', 'Keep-Alive' ], + $body); + $response->protocol('HTTP/1.1'); + $connection->send_response($response); +} + +1; From des at projects.linpro.no Thu Jul 26 07:43:37 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 26 Jul 2007 09:43:37 +0200 (CEST) Subject: r1772 - in trunk/varnish-tools/regress/lib/Varnish: . Test Test/Case Test/Report Message-ID: <20070726074337.929D41EC033@projects.linpro.no> Author: des Date: 2007-07-26 09:43:37 +0200 (Thu, 26 Jul 2007) New Revision: 1772 Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Correct copyright years. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2006-2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2006-2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2006-2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Report/HTML.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Report.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2006-2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2006-2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-07-26 07:02:20 UTC (rev 1771) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-07-26 07:43:37 UTC (rev 1772) @@ -1,6 +1,6 @@ #!/usr/bin/perl -w #- -# Copyright (c) 2006 Linpro AS +# Copyright (c) 2006-2007 Linpro AS # All rights reserved. # # Redistribution and use in source and binary forms, with or without From des at projects.linpro.no Thu Jul 26 07:45:24 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 26 Jul 2007 09:45:24 +0200 (CEST) Subject: r1773 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070726074524.3599D1EC030@projects.linpro.no> Author: des Date: 2007-07-26 09:45:23 +0200 (Thu, 26 Jul 2007) New Revision: 1773 Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm Removed: trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm Log: Rename to a more easily remembered (and typed) name. Deleted: trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm 2007-07-26 07:43:37 UTC (rev 1772) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm 2007-07-26 07:45:23 UTC (rev 1773) @@ -1,146 +0,0 @@ -#!/usr/bin/perl -w -#- -# Copyright (c) 2007 Linpro AS -# All rights reserved. -# -# 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 -# in this position and unchanged. -# 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 THE 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. -# -# $Id$ -# - -package Varnish::Test::Case::HTTPregexPurge; - -use strict; -use base 'Varnish::Test::Case'; - -use Data::Dumper; - -our $VCL = <new_client; - #for (my $i = 0; $i < 2; $i++) { - my $get_p_request = HTTP::Request->new('GET', '/purge'); - $get_p_request->protocol('HTTP/1.1'); - my $get_k_request = HTTP::Request->new('GET', '/keep'); - $get_k_request->protocol('HTTP/1.1'); - my $purge_request = HTTP::Request->new('REPURGE', '/purge'); - $purge_request->protocol('HTTP/1.1'); - - - # Fetch the two pages, so they'll get cached - $client->send_request($get_p_request, 2); - my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - - $client->send_request($get_k_request, 2); - my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - - - # Check that the purge page is cached - $client->send_request($get_p_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - die "Not cached\n" - if $response->header('x-varnish') !~ /\d+ \d+/; - - - # Purge the purge page - $client->send_request($purge_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - # For some reason it times out on the first attempt, so we have to run the - # loop an extra time to get the response. Could this be a bug in the framework? - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout') - if $event eq 'ev_client_timeout'; - - - # Check that the purge page is no longer cached - $client->send_request($get_p_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - die "Still Cached\n" - if $response->header('x-varnish') =~ /\d+ \d+/; - - - # Check that the keep page is still cached - $client->send_request($get_k_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - die "Still Cached\n" - if $response->header('x-varnish') !~ /\d+ \d+/; - - - $client->shutdown(); - - return 'OK'; -} - -sub ev_server_request($$$$) { - my ($self, $server, $connection, $request) = @_; - my $body = ""; - - # Return the right content - if ($request->uri =~ /purge/) { - $body = $body_p; - } - elsif ($request->uri =~ /keep/) { - $body = $body_k; - } - - my $response = HTTP::Response->new(200, undef, - [ 'Content-Length', length($body), - 'Connection', 'Keep-Alive' ], - $body); - $response->protocol('HTTP/1.1'); - $connection->send_response($response); -} - -1; Copied: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm (from rev 1772, trunk/varnish-tools/regress/lib/Varnish/Test/Case/HTTPregexPurge.pm) =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm 2007-07-26 07:45:23 UTC (rev 1773) @@ -0,0 +1,146 @@ +#!/usr/bin/perl -w +#- +# Copyright (c) 2007 Linpro AS +# All rights reserved. +# +# 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 +# in this position and unchanged. +# 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 THE 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. +# +# $Id$ +# + +package Varnish::Test::Case::RePurge; + +use strict; +use base 'Varnish::Test::Case'; + +use Data::Dumper; + +our $VCL = <new_client; + #for (my $i = 0; $i < 2; $i++) { + my $get_p_request = HTTP::Request->new('GET', '/purge'); + $get_p_request->protocol('HTTP/1.1'); + my $get_k_request = HTTP::Request->new('GET', '/keep'); + $get_k_request->protocol('HTTP/1.1'); + my $purge_request = HTTP::Request->new('REPURGE', '/purge'); + $purge_request->protocol('HTTP/1.1'); + + + # Fetch the two pages, so they'll get cached + $client->send_request($get_p_request, 2); + my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + + $client->send_request($get_k_request, 2); + my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + + + # Check that the purge page is cached + $client->send_request($get_p_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + die "Not cached\n" + if $response->header('x-varnish') !~ /\d+ \d+/; + + + # Purge the purge page + $client->send_request($purge_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + # For some reason it times out on the first attempt, so we have to run the + # loop an extra time to get the response. Could this be a bug in the framework? + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout') + if $event eq 'ev_client_timeout'; + + + # Check that the purge page is no longer cached + $client->send_request($get_p_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + die "Still Cached\n" + if $response->header('x-varnish') =~ /\d+ \d+/; + + + # Check that the keep page is still cached + $client->send_request($get_k_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + die "Still Cached\n" + if $response->header('x-varnish') !~ /\d+ \d+/; + + + $client->shutdown(); + + return 'OK'; +} + +sub ev_server_request($$$$) { + my ($self, $server, $connection, $request) = @_; + my $body = ""; + + # Return the right content + if ($request->uri =~ /purge/) { + $body = $body_p; + } + elsif ($request->uri =~ /keep/) { + $body = $body_k; + } + + my $response = HTTP::Response->new(200, undef, + [ 'Content-Length', length($body), + 'Connection', 'Keep-Alive' ], + $body); + $response->protocol('HTTP/1.1'); + $connection->send_response($response); +} + +1; From des at projects.linpro.no Thu Jul 26 07:45:37 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 26 Jul 2007 09:45:37 +0200 (CEST) Subject: r1774 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070726074537.876841EC2A5@projects.linpro.no> Author: des Date: 2007-07-26 09:45:37 +0200 (Thu, 26 Jul 2007) New Revision: 1774 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm Log: fix props Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Thu Jul 26 07:51:09 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 26 Jul 2007 09:51:09 +0200 (CEST) Subject: r1775 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070726075109.920361EC030@projects.linpro.no> Author: des Date: 2007-07-26 09:51:09 +0200 (Thu, 26 Jul 2007) New Revision: 1775 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm Log: Whitespace & indentation Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm 2007-07-26 07:45:37 UTC (rev 1774) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm 2007-07-26 07:51:09 UTC (rev 1775) @@ -51,73 +51,72 @@ my ($self) = @_; my $client = $self->new_client; - #for (my $i = 0; $i < 2; $i++) { - my $get_p_request = HTTP::Request->new('GET', '/purge'); - $get_p_request->protocol('HTTP/1.1'); - my $get_k_request = HTTP::Request->new('GET', '/keep'); - $get_k_request->protocol('HTTP/1.1'); - my $purge_request = HTTP::Request->new('REPURGE', '/purge'); - $purge_request->protocol('HTTP/1.1'); - - - # Fetch the two pages, so they'll get cached - $client->send_request($get_p_request, 2); - my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; + my $get_p_request = HTTP::Request->new('GET', '/purge'); + $get_p_request->protocol('HTTP/1.1'); + my $get_k_request = HTTP::Request->new('GET', '/keep'); + $get_k_request->protocol('HTTP/1.1'); + my $purge_request = HTTP::Request->new('REPURGE', '/purge'); + $purge_request->protocol('HTTP/1.1'); - $client->send_request($get_k_request, 2); - my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - - # Check that the purge page is cached - $client->send_request($get_p_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - die "Not cached\n" - if $response->header('x-varnish') !~ /\d+ \d+/; - - - # Purge the purge page - $client->send_request($purge_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - # For some reason it times out on the first attempt, so we have to run the - # loop an extra time to get the response. Could this be a bug in the framework? - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout') - if $event eq 'ev_client_timeout'; + # Fetch the two pages, so they'll get cached + $client->send_request($get_p_request, 2); + my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; - - # Check that the purge page is no longer cached - $client->send_request($get_p_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - die "Still Cached\n" - if $response->header('x-varnish') =~ /\d+ \d+/; - - - # Check that the keep page is still cached - $client->send_request($get_k_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - die "Still Cached\n" - if $response->header('x-varnish') !~ /\d+ \d+/; - + $client->send_request($get_k_request, 2); + my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + + # Check that the purge page is cached + $client->send_request($get_p_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + die "Not cached\n" + if $response->header('x-varnish') !~ /\d+ \d+/; + + + # Purge the purge page + $client->send_request($purge_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + # For some reason it times out on the first attempt, so we have to run the + # loop an extra time to get the response. Could this be a bug in the framework? + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout') + if $event eq 'ev_client_timeout'; + + + # Check that the purge page is no longer cached + $client->send_request($get_p_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + die "Still Cached\n" + if $response->header('x-varnish') =~ /\d+ \d+/; + + + # Check that the keep page is still cached + $client->send_request($get_k_request, 2); + ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $event eq 'ev_client_timeout'; + die "Empty body\n" + if $response->content eq ''; + die "Still Cached\n" + if $response->header('x-varnish') !~ /\d+ \d+/; + + $client->shutdown(); return 'OK'; @@ -129,10 +128,10 @@ # Return the right content if ($request->uri =~ /purge/) { - $body = $body_p; + $body = $body_p; } elsif ($request->uri =~ /keep/) { - $body = $body_k; + $body = $body_k; } my $response = HTTP::Response->new(200, undef, From des at projects.linpro.no Thu Jul 26 13:53:42 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 26 Jul 2007 15:53:42 +0200 (CEST) Subject: r1776 - trunk/varnish-cache/doc Message-ID: <20070726135342.0909A1EC2A5@projects.linpro.no> Author: des Date: 2007-07-26 15:53:41 +0200 (Thu, 26 Jul 2007) New Revision: 1776 Added: trunk/varnish-cache/doc/changes-1.1-1.1.1.xml trunk/varnish-cache/doc/changes-1.1.1.xml Modified: trunk/varnish-cache/doc/Makefile.am trunk/varnish-cache/doc/changes-1.0.4-1.1.xml trunk/varnish-cache/doc/changes-1.1.xml Log: Add change log for 1.1.1 + various prop fixes Modified: trunk/varnish-cache/doc/Makefile.am =================================================================== --- trunk/varnish-cache/doc/Makefile.am 2007-07-26 07:51:09 UTC (rev 1775) +++ trunk/varnish-cache/doc/Makefile.am 2007-07-26 13:53:41 UTC (rev 1776) @@ -1,7 +1,12 @@ # $Id$ -CHANGELOGS = changes-1.0.4.html changes-1.1.html +CHANGELOGS = \ + changes-1.0.4.html \ + changes-1.1.html \ + changes-1.1.1.html +all: ${CHANGELOGS} + EXTRA_DIST = ${CHANGELOGS} CLEANFILES = ${CHANGELOGS} Property changes on: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml ___________________________________________________________________ Name: svn:mime-type + text/xml Added: trunk/varnish-cache/doc/changes-1.1-1.1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.1-1.1.1.xml (rev 0) +++ trunk/varnish-cache/doc/changes-1.1-1.1.1.xml 2007-07-26 13:53:41 UTC (rev 1776) @@ -0,0 +1,27 @@ + + +]> + + + + varnishd + + + The code required to allow VCL to read + obj.status, which had accidentally been left + out, has now been added. + + + + Varnish will now always include a + Connection: header in its reply to the + client, to avoid possible misunderstandings. + + + + A bug that triggered an assertion failure when generating + synthetic error documents has been corrected. + + + Property changes on: trunk/varnish-cache/doc/changes-1.1-1.1.1.xml ___________________________________________________________________ Name: svn:mime-type + text/xml Name: svn:keywords + Id Added: trunk/varnish-cache/doc/changes-1.1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.1.1.xml (rev 0) +++ trunk/varnish-cache/doc/changes-1.1.1.xml 2007-07-26 13:53:41 UTC (rev 1776) @@ -0,0 +1,12 @@ + + + +]> + + + Varnish + 1.1.1 + + + Property changes on: trunk/varnish-cache/doc/changes-1.1.1.xml ___________________________________________________________________ Name: svn:mime-type + text/xml Name: svn:keywords + Id Property changes on: trunk/varnish-cache/doc/changes-1.1.xml ___________________________________________________________________ Name: svn:mime-type + text/xml From des at projects.linpro.no Thu Jul 26 13:54:14 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 26 Jul 2007 15:54:14 +0200 (CEST) Subject: r1777 - in branches/1.1: . bin/varnishd bin/varnishhist bin/varnishreplay bin/varnishstat bin/varnishtop doc Message-ID: <20070726135414.AE0F01EC030@projects.linpro.no> Author: des Date: 2007-07-26 15:54:14 +0200 (Thu, 26 Jul 2007) New Revision: 1777 Added: branches/1.1/doc/changes-1.1-1.1.1.xml branches/1.1/doc/changes-1.1.1.xml Modified: branches/1.1/ branches/1.1/Makefile.am branches/1.1/bin/varnishd/cache_response.c branches/1.1/bin/varnishd/cache_vrt.c branches/1.1/bin/varnishhist/varnishhist.c branches/1.1/bin/varnishreplay/varnishreplay.c branches/1.1/bin/varnishstat/varnishstat.c branches/1.1/bin/varnishtop/varnishtop.c branches/1.1/doc/Makefile.am branches/1.1/doc/changes-1.0.4-1.1.xml branches/1.1/doc/changes-1.1.xml Log: Merged revisions 1745-1747,1750-1760,1763-1764,1767-1776 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1745 | des | 2007-07-24 13:39:55 +0200 (Tue, 24 Jul 2007) | 2 lines Implement VRT_r_obj_status(), without which obj.status can't be read. ........ r1750 | des | 2007-07-24 15:54:20 +0200 (Tue, 24 Jul 2007) | 3 lines Always generate a Connection: header, in case the client makes an incorrect assumption about which is the default. ........ r1751 | des | 2007-07-24 15:56:44 +0200 (Tue, 24 Jul 2007) | 3 lines RES_BuildHttp() must be called before RES_WriteObj() to prepare the response headers. This fixes #128. ........ r1752 | des | 2007-07-24 16:02:20 +0200 (Tue, 24 Jul 2007) | 2 lines #131: Honor DESTDIR when creating the state directory. ........ r1753 | des | 2007-07-24 16:10:28 +0200 (Tue, 24 Jul 2007) | 2 lines #130: false is spelles FALSE in curses-land. ........ r1754 | des | 2007-07-24 16:25:54 +0200 (Tue, 24 Jul 2007) | 6 lines Instead of incorrectly assuming that a pthread_t can be meaningfully cast to an unsigned int (which triggered warnings on some 64-bit platforms) and printed with %08lx, incorrectly assume that it can be meaningfully cast to a void * and printed with %p. While still incorrect in general terms, the latter turns out to be correct on the specific systems that we care about. ........ r1776 | des | 2007-07-26 15:53:41 +0200 (Thu, 26 Jul 2007) | 2 lines Add change log for 1.1.1 + various prop fixes ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738 + /trunk/varnish-cache:1-1722,1727-1729,1738,1745-1747,1750-1760,1763-1764,1767-1776 Modified: branches/1.1/Makefile.am =================================================================== --- branches/1.1/Makefile.am 2007-07-26 13:53:41 UTC (rev 1776) +++ branches/1.1/Makefile.am 2007-07-26 13:54:14 UTC (rev 1777) @@ -10,4 +10,4 @@ EXTRA_DIST = LICENSE autogen.sh varnishapi.pc.in install-data-local: - $(install_sh) -d -m 0755 $(localstatedir)/varnish + $(install_sh) -d -m 0755 $(DESTDIR)$(localstatedir)/varnish Modified: branches/1.1/bin/varnishd/cache_response.c =================================================================== --- branches/1.1/bin/varnishd/cache_response.c 2007-07-26 13:53:41 UTC (rev 1776) +++ branches/1.1/bin/varnishd/cache_response.c 2007-07-26 13:54:14 UTC (rev 1777) @@ -50,6 +50,7 @@ /* synthesize error page and send it */ SYN_ErrorPage(sp, code, reason, 0); + RES_BuildHttp(sp); RES_WriteObj(sp); /* GC the error page */ @@ -76,8 +77,8 @@ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid); TIM_format(sp->obj->last_modified, lm); http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Last-Modified: %s", lm); - if (sp->doclose != NULL) - http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); + http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Connection: %s", + sp->doclose ? "close" : "keep-alive"); sp->wantbody = 0; } @@ -129,8 +130,8 @@ http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %.0f", sp->obj->age + sp->t_resp - sp->obj->entered); http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish"); - if (sp->doclose != NULL) - http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close"); + http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Connection: %s", + sp->doclose ? "close" : "keep-alive"); } /*--------------------------------------------------------------------*/ Modified: branches/1.1/bin/varnishd/cache_vrt.c =================================================================== --- branches/1.1/bin/varnishd/cache_vrt.c 2007-07-26 13:53:41 UTC (rev 1776) +++ branches/1.1/bin/varnishd/cache_vrt.c 2007-07-26 13:54:14 UTC (rev 1777) @@ -234,6 +234,14 @@ http_SetH(&sp->obj->http, HTTP_HDR_STATUS, p); } +int +VRT_r_obj_status(struct sess *sp) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + return (atoi(sp->obj->http.hd[HTTP_HDR_STATUS].b)); +} + void VRT_l_resp_status(struct sess *sp, int num) { Modified: branches/1.1/bin/varnishhist/varnishhist.c =================================================================== --- branches/1.1/bin/varnishhist/varnishhist.c 2007-07-26 13:53:41 UTC (rev 1776) +++ branches/1.1/bin/varnishhist/varnishhist.c 2007-07-26 13:54:14 UTC (rev 1777) @@ -247,7 +247,7 @@ raw(); noecho(); nonl(); - intrflush(stdscr, false); + intrflush(stdscr, FALSE); curs_set(0); erase(); for (;;) { Modified: branches/1.1/bin/varnishreplay/varnishreplay.c =================================================================== --- branches/1.1/bin/varnishreplay/varnishreplay.c 2007-07-26 13:53:41 UTC (rev 1776) +++ branches/1.1/bin/varnishreplay/varnishreplay.c 2007-07-26 13:54:14 UTC (rev 1777) @@ -145,7 +145,7 @@ if (lvl > debug) return; pthread_mutex_lock(&log_mutex); - fprintf(stderr, "%08x ", (unsigned int)pthread_self()); + fprintf(stderr, "%p ", (void *)pthread_self()); va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); @@ -183,8 +183,8 @@ mailbox_destroy(&threads[fd]->mbox); freez(threads[fd]); } - thread_log(1, "thread %08x started\n", - (unsigned int)threads[fd]->thread_id); + thread_log(1, "thread %p started\n", + (void *)threads[fd]->thread_id); } return (threads[fd]); } @@ -204,8 +204,8 @@ return; mailbox_close(&threads[fd]->mbox); pthread_join(threads[fd]->thread_id, NULL); - thread_log(1, "thread %08x stopped\n", - (unsigned int)threads[fd]->thread_id); + thread_log(1, "thread %p stopped\n", + (void *)threads[fd]->thread_id); mailbox_destroy(&threads[fd]->mbox); freez(threads[fd]); } Modified: branches/1.1/bin/varnishstat/varnishstat.c =================================================================== --- branches/1.1/bin/varnishstat/varnishstat.c 2007-07-26 13:53:41 UTC (rev 1776) +++ branches/1.1/bin/varnishstat/varnishstat.c 2007-07-26 13:54:14 UTC (rev 1777) @@ -78,7 +78,7 @@ raw(); noecho(); nonl(); - intrflush(stdscr, false); + intrflush(stdscr, FALSE); curs_set(0); erase(); Modified: branches/1.1/bin/varnishtop/varnishtop.c =================================================================== --- branches/1.1/bin/varnishtop/varnishtop.c 2007-07-26 13:53:41 UTC (rev 1776) +++ branches/1.1/bin/varnishtop/varnishtop.c 2007-07-26 13:54:14 UTC (rev 1777) @@ -201,7 +201,7 @@ raw(); noecho(); nonl(); - intrflush(stdscr, false); + intrflush(stdscr, FALSE); curs_set(0); erase(); for (;;) { Modified: branches/1.1/doc/Makefile.am =================================================================== --- branches/1.1/doc/Makefile.am 2007-07-26 13:53:41 UTC (rev 1776) +++ branches/1.1/doc/Makefile.am 2007-07-26 13:54:14 UTC (rev 1777) @@ -1,7 +1,12 @@ # $Id$ -CHANGELOGS = changes-1.0.4.html changes-1.1.html +CHANGELOGS = \ + changes-1.0.4.html \ + changes-1.1.html \ + changes-1.1.1.html +all: ${CHANGELOGS} + EXTRA_DIST = ${CHANGELOGS} CLEANFILES = ${CHANGELOGS} Property changes on: branches/1.1/doc/changes-1.0.4-1.1.xml ___________________________________________________________________ Name: svn:mime-type + text/xml Copied: branches/1.1/doc/changes-1.1-1.1.1.xml (from rev 1776, trunk/varnish-cache/doc/changes-1.1-1.1.1.xml) =================================================================== --- branches/1.1/doc/changes-1.1-1.1.1.xml (rev 0) +++ branches/1.1/doc/changes-1.1-1.1.1.xml 2007-07-26 13:54:14 UTC (rev 1777) @@ -0,0 +1,27 @@ + + +]> + + + + varnishd + + + The code required to allow VCL to read + obj.status, which had accidentally been left + out, has now been added. + + + + Varnish will now always include a + Connection: header in its reply to the + client, to avoid possible misunderstandings. + + + + A bug that triggered an assertion failure when generating + synthetic error documents has been corrected. + + + Copied: branches/1.1/doc/changes-1.1.1.xml (from rev 1776, trunk/varnish-cache/doc/changes-1.1.1.xml) =================================================================== --- branches/1.1/doc/changes-1.1.1.xml (rev 0) +++ branches/1.1/doc/changes-1.1.1.xml 2007-07-26 13:54:14 UTC (rev 1777) @@ -0,0 +1,12 @@ + + + +]> + + + Varnish + 1.1.1 + + + Property changes on: branches/1.1/doc/changes-1.1.xml ___________________________________________________________________ Name: svn:mime-type + text/xml From cecilihf at projects.linpro.no Fri Jul 27 14:16:39 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Fri, 27 Jul 2007 16:16:39 +0200 (CEST) Subject: r1778 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070727141639.79A171EC2A5@projects.linpro.no> Author: cecilihf Date: 2007-07-27 16:16:39 +0200 (Fri, 27 Jul 2007) New Revision: 1778 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c trunk/varnish-cache/lib/libvcl/vcc_string.c Log: Added a health parameter for the backend. This is readable in vcl with backend.health. Made it possible to pass a vcl variable to error (error 200 backend.health). Implemented a first attempt at an algorithm for checking the health of a backend. Negative values means the backend has problems, positive values means it is ok. 0 is neutral, and could mean that it has been a while since the backend was asked for anything. See the code for details. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-26 13:54:14 UTC (rev 1777) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-27 14:16:39 UTC (rev 1778) @@ -332,6 +332,11 @@ double dnsttl; double dnstime; + + int health; + double last_check; + int minute_limit; + #if 0 double responsetime; double timeout; Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-26 13:54:14 UTC (rev 1777) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-27 14:16:39 UTC (rev 1778) @@ -288,10 +288,35 @@ AN(sp->bereq); i = Fetch(sp); + + /* Experimental. Set time for last check of backend health. + * If the backend replied with 200, it is obviously up and running, + * increase health parameter. If we got a 504 back, it would imply + * that the backend is not reachable. Decrease health parameter. + */ + sp->backend->last_check = TIM_mono(); + sp->backend->minute_limit = 1; + if (!i){ + if (http_GetStatus(sp->bereq->http) == 200) { + if (sp->backend->health < 10000) + sp->backend->health++; + } else if(http_GetStatus(sp->bereq->http) == 504) { + if (sp->backend->health > -10000) + sp->backend->health--; + } + } + + vbe_free_bereq(sp->bereq); sp->bereq = NULL; if (i) { + /* Experimental. If the fetch failed, it would also seem + * to be a backend problem, so decrease the health parameter. + */ + if (sp->backend->health > -10000) + sp->backend->health--; + SYN_ErrorPage(sp, 503, "Error talking to backend", 30); } else { RFC2616_cache_policy(sp, &sp->obj->http); /* XXX -> VCL */ @@ -372,8 +397,19 @@ static int cnt_hit(struct sess *sp) { + double time_diff; + double minutes; assert(!sp->obj->pass); + + /* Experimental. Reduce health parameter of backend towards zero + * if it has been more than a minute since it was checked. */ + time_diff = TIM_mono() - sp->backend->last_check; + minutes = time_diff / 60; + if (minutes > sp->backend->minute_limit) { + sp->backend->minute_limit++; + sp->backend->health = (int)((double)sp->backend->health / 2); + } VCL_hit_method(sp); Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-26 13:54:14 UTC (rev 1777) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-07-27 14:16:39 UTC (rev 1778) @@ -289,6 +289,9 @@ cp->backend[i]->magic = BACKEND_MAGIC; cp->backend[i]->dnsttl = 30; TAILQ_INIT(&cp->backend[i]->connlist); + cp->backend[i]->health = 0; + cp->backend[i]->last_check = TIM_mono(); + cp->backend[i]->minute_limit = 1; } } @@ -320,6 +323,7 @@ VBACKEND(const char *, port, portname) VBACKEND(double, dnsttl, dnsttl) + /*-------------------------------------------------------------------- * XXX: Working relative to t_req is maybe not the right thing, we could * XXX: have spent a long time talking to the backend since then. @@ -487,6 +491,15 @@ return (TIM_mono() - sp->obj->lru_stamp); } +int +VRT_r_backend_health(struct sess *sp) +{ + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); + return sp->backend->health; +} + /*--------------------------------------------------------------------*/ char * @@ -514,6 +527,18 @@ return (q); } +char * +VRT_int_string(struct sess *sp, int num) +{ + char *p; + int size = 10; + + p = WS_Alloc(sp->http->ws, size); + AN(p); + snprintf(p, size, "%d", num); + return (p); +} + /*--------------------------------------------------------------------*/ void Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-07-26 13:54:14 UTC (rev 1777) +++ trunk/varnish-cache/include/vrt.h 2007-07-27 14:16:39 UTC (rev 1778) @@ -89,6 +89,7 @@ void VRT_fini_backend(struct backend *be); char *VRT_IP_string(struct sess *sp, struct sockaddr *sa); +char *VRT_int_string(struct sess *sp, int); #define VRT_done(sp, hand) \ do { \ Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2007-07-26 13:54:14 UTC (rev 1777) +++ trunk/varnish-cache/include/vrt_obj.h 2007-07-27 14:16:39 UTC (rev 1778) @@ -46,3 +46,4 @@ const char * VRT_r_resp_response(struct sess *); void VRT_l_resp_response(struct sess *, const char *, ...); double VRT_r_now(struct sess *); +int VRT_r_backend_health(struct sess *); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-26 13:54:14 UTC (rev 1777) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-07-27 14:16:39 UTC (rev 1778) @@ -84,6 +84,9 @@ if (tl->t->tok == CSTR) { Fb(tl, 0, ", %.*s", PF(tl->t)); vcc_NextToken(tl); + } else if (tl->t->tok == VAR) { + Fb(tl, 0, ", "); + vcc_StringVal(tl); } else { Fb(tl, 0, ", (const char *)0"); } Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-26 13:54:14 UTC (rev 1777) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-07-27 14:16:39 UTC (rev 1778) @@ -445,6 +445,7 @@ vsb_cat(sb, "void VRT_fini_backend(struct backend *be);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "char *VRT_IP_string(struct sess *sp, struct sockaddr *sa);\n"); + vsb_cat(sb, "char *VRT_int_string(struct sess *sp, int);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "#define VRT_done(sp, hand) \\\n"); vsb_cat(sb, " do { \\\n"); @@ -499,4 +500,5 @@ vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n"); vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *, ...);\n"); vsb_cat(sb, "double VRT_r_now(struct sess *);\n"); + vsb_cat(sb, "int VRT_r_backend_health(struct sess *);\n"); } Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-26 13:54:14 UTC (rev 1777) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-07-27 14:16:39 UTC (rev 1778) @@ -164,6 +164,10 @@ RO TIME {recv pipe pass hash miss hit fetch deliver discard timeout} } + { backend.health RO INT + {recv pipe pass hash miss hit fetch deliver discard timeout} + } + } set tt(IP) "struct sockaddr *" Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-26 13:54:14 UTC (rev 1777) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-07-27 14:16:39 UTC (rev 1778) @@ -210,5 +210,12 @@ 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, + { "backend.health", INT, 14, + "VRT_r_backend_health(sp)", + NULL, + V_RO, + 0, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT + }, { NULL } }; Modified: trunk/varnish-cache/lib/libvcl/vcc_string.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_string.c 2007-07-26 13:54:14 UTC (rev 1777) +++ trunk/varnish-cache/lib/libvcl/vcc_string.c 2007-07-27 14:16:39 UTC (rev 1778) @@ -140,6 +140,9 @@ case IP: Fb(tl, 0, "VRT_IP_string(sp, %s)", vp->rname); break; + case INT: + Fb(tl, 0, "VRT_int_string(sp, %s)", vp->rname); + break; default: vsb_printf(tl->sb, "String representation of '%s' not implemented yet.\n", From des at projects.linpro.no Sat Jul 28 09:23:52 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sat, 28 Jul 2007 11:23:52 +0200 (CEST) Subject: r1779 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070728092352.4BE101EC2A3@projects.linpro.no> Author: des Date: 2007-07-28 11:23:52 +0200 (Sat, 28 Jul 2007) New Revision: 1779 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm Log: Refactor this test case. Note that it still fails; there seems to be something wrong with the synthetic response code in varnishd. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm 2007-07-27 14:16:39 UTC (rev 1778) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm 2007-07-28 09:23:52 UTC (rev 1779) @@ -44,79 +44,74 @@ } EOVCL -our $body_p = "Hello World! -> purge\n"; -our $body_k = "Hello World! -> keep\n"; +our $KEEP_URL = '/will-be-kept'; +our $PURGE_URL = '/will-be-purged'; +our $PURGE_RE = 'purge'; -sub testPagePurged($) { - my ($self) = @_; +sub get($$$) { + my ($self, $client, $url) = @_; - my $client = $self->new_client; - my $get_p_request = HTTP::Request->new('GET', '/purge'); - $get_p_request->protocol('HTTP/1.1'); - my $get_k_request = HTTP::Request->new('GET', '/keep'); - $get_k_request->protocol('HTTP/1.1'); - my $purge_request = HTTP::Request->new('REPURGE', '/purge'); - $purge_request->protocol('HTTP/1.1'); + my $req = HTTP::Request->new('GET', $url); + $req->protocol('HTTP/1.1'); + $client->send_request($req, 2); + my ($ev, $resp) = + $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Client time-out before receiving a (complete) response\n" + if $ev eq 'ev_client_timeout'; + die "Request failed\n" + unless $resp->code == 200; + return $resp; +} +sub get_cached($$$) { + my ($self, $client, $url) = @_; - # Fetch the two pages, so they'll get cached - $client->send_request($get_p_request, 2); - my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; + my $resp = $self->get($client, $url); + die "$url should be cached but isn't\n" + unless $resp->header('x-varnish') =~ /^\d+ \d+$/; +} - $client->send_request($get_k_request, 2); - my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; +sub get_uncached($$$) { + my ($self, $client, $url) = @_; + my $resp = $self->get($client, $url); + die "$url shouldn't be cached but is\n" + if $resp->header('x-varnish') =~ /^\d+ \d+$/; +} - # Check that the purge page is cached - $client->send_request($get_p_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); +sub purge($$$) { + my ($self, $client, $re) = @_; + + my $req = HTTP::Request->new('REPURGE', $re); + $req->protocol('HTTP/1.1'); + $client->send_request($req, 2); + my ($ev, $resp) = + $self->run_loop('ev_client_response', 'ev_client_timeout'); die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - die "Not cached\n" - if $response->header('x-varnish') !~ /\d+ \d+/; + if $ev eq 'ev_client_timeout'; +} +sub testPagePurged($) { + my ($self) = @_; - # Purge the purge page - $client->send_request($purge_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - # For some reason it times out on the first attempt, so we have to run the - # loop an extra time to get the response. Could this be a bug in the framework? - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout') - if $event eq 'ev_client_timeout'; + my $client = $self->new_client; + my $resp; + # Warm up the cache + $self->get($client, $KEEP_URL); + $self->get($client, $PURGE_URL); - # Check that the purge page is no longer cached - $client->send_request($get_p_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - die "Still Cached\n" - if $response->header('x-varnish') =~ /\d+ \d+/; + # Verify the state of the cache + $self->get_cached($client, $KEEP_URL); + $self->get_cached($client, $PURGE_URL); + # Send the purge request + $self->purge($client, $PURGE_RE); - # Check that the keep page is still cached - $client->send_request($get_k_request, 2); - ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - die "Still Cached\n" - if $response->header('x-varnish') !~ /\d+ \d+/; + # Verify the state of the cache + $self->get_cached($client, $KEEP_URL); + $self->get_uncached($client, $PURGE_URL); - $client->shutdown(); return 'OK'; @@ -124,16 +119,8 @@ sub ev_server_request($$$$) { my ($self, $server, $connection, $request) = @_; - my $body = ""; - # Return the right content - if ($request->uri =~ /purge/) { - $body = $body_p; - } - elsif ($request->uri =~ /keep/) { - $body = $body_k; - } - + my $body = $request->url; my $response = HTTP::Response->new(200, undef, [ 'Content-Length', length($body), 'Connection', 'Keep-Alive' ], From des at projects.linpro.no Sat Jul 28 10:03:29 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sat, 28 Jul 2007 12:03:29 +0200 (CEST) Subject: r1780 - trunk/varnish-cache/bin/varnishd Message-ID: <20070728100329.71A0E1EC030@projects.linpro.no> Author: des Date: 2007-07-28 12:03:29 +0200 (Sat, 28 Jul 2007) New Revision: 1780 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c Log: Reverse the logic for sp->wantbody: assume it is always wanted unless req.request is "HEAD". This is what broke the RePurge test case. Ideally, sp->wantbody would be controllable by VCL. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-28 09:23:52 UTC (rev 1779) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-07-28 10:03:29 UTC (rev 1780) @@ -726,8 +726,7 @@ VCL_recv_method(sp); - sp->wantbody = (!strcmp(sp->http->hd[HTTP_HDR_REQ].b, "GET") || - !strcmp(sp->http->hd[HTTP_HDR_REQ].b, "POST")); + sp->wantbody = (strcmp(sp->http->hd[HTTP_HDR_REQ].b, "HEAD") != 0); switch(sp->handling) { case VCL_RET_LOOKUP: /* XXX: discard req body, if any */ From des at projects.linpro.no Sat Jul 28 11:41:35 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sat, 28 Jul 2007 13:41:35 +0200 (CEST) Subject: r1781 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070728114135.AC3161EC2A3@projects.linpro.no> Author: des Date: 2007-07-28 13:41:35 +0200 (Sat, 28 Jul 2007) New Revision: 1781 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm Log: Empty responses are not necessarily incorrect, even if Content-Length is non-zero. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-07-28 10:03:29 UTC (rev 1780) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-07-28 11:41:35 UTC (rev 1781) @@ -122,11 +122,19 @@ $$data = ''; $self->got_response($response); } + elsif ($data_length == 0) { + # We got a body-less response, which may or may not + # be correct; leave it to the test case to decide. + $self->log("No body received despite" . + " Content-Length $content_length"); + $$data = ''; + $self->got_response($response); + } elsif ($data_length < $content_length) { # We only received the first part of an HTTP message, # so break out of loop and wait for more. - $self->log(sprintf('Partial response. Bytes in body: %d received, %d expected, %d remaining', - $data_length, $content_length, $content_length - $data_length)); + $self->log("Partial body received" . + " ($data_length of $content_length bytes)"); last; } else { From des at projects.linpro.no Sat Jul 28 15:29:32 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sat, 28 Jul 2007 17:29:32 +0200 (CEST) Subject: r1782 - in trunk/varnish-tools/regress/lib/Varnish/Test: . Case Message-ID: <20070728152932.2235A1EC416@projects.linpro.no> Author: des Date: 2007-07-28 17:29:31 +0200 (Sat, 28 Jul 2007) New Revision: 1782 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm Log: Add a slew of utilities to simplify the writing of test cases. Rewrite the existing test cases to take advantage of these utilities. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm 2007-07-28 11:41:35 UTC (rev 1781) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/LRU.pm 2007-07-28 15:29:31 UTC (rev 1782) @@ -51,19 +51,8 @@ my $client = $self->new_client(); my $uri = __PACKAGE__ . "::$n"; - my $request = HTTP::Request->new('GET', $uri); - $request->protocol('HTTP/1.1'); - $client->send_request($request, 2); - my ($event, $response) = - $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Timed out\n" - if ($event eq 'ev_client_timeout'); - die "No (complete) response received\n" - unless defined($response); - die "Empty body\n" - if $response->content() eq ''; - die "Incorrect body\n" - if $response->content() !~ m/^(?:\Q$uri\E){$repeat}$/; + my $response = $self->get($client, $uri); + $self->assert_body(qr/^(?:\Q$uri\E){$repeat}$/); $client->shutdown(); return $response; } @@ -107,17 +96,11 @@ return 'OK'; } -sub ev_server_request($$$$) { - my ($self, $server, $connection, $request) = @_; +sub server($$$) { + my ($self, $request, $response) = @_; - my $body = $request->uri() x $repeat; - my $response = HTTP::Response->new(200, undef, - [ 'Content-Type', 'text/plain', - 'Content-Length', length($body), - 'Cache-Control', 'max-age=3600', ], - $body); - $response->protocol('HTTP/1.1'); - $connection->send_response($response); + $response->content($request->uri() x $repeat); + $response->header('Cache-Control' => 'max-age=3600'); } 1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm 2007-07-28 11:41:35 UTC (rev 1781) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm 2007-07-28 15:29:31 UTC (rev 1782) @@ -33,7 +33,10 @@ use strict; use base 'Varnish::Test::Case'; -use Data::Dumper; +our $DESCR = "Tests the VCL purge() function by warming up the cache," . + " then submitting a request that causes part of it to be purged," . + " before finally verifying that the objects that should have been" . + " purged were and those that shouldn't weren't."; our $VCL = <new('GET', $url); - $req->protocol('HTTP/1.1'); - $client->send_request($req, 2); - my ($ev, $resp) = - $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $ev eq 'ev_client_timeout'; - die "Request failed\n" - unless $resp->code == 200; - return $resp; -} - -sub get_cached($$$) { - my ($self, $client, $url) = @_; - - my $resp = $self->get($client, $url); - die "$url should be cached but isn't\n" - unless $resp->header('x-varnish') =~ /^\d+ \d+$/; -} - -sub get_uncached($$$) { - my ($self, $client, $url) = @_; - - my $resp = $self->get($client, $url); - die "$url shouldn't be cached but is\n" - if $resp->header('x-varnish') =~ /^\d+ \d+$/; -} - -sub purge($$$) { - my ($self, $client, $re) = @_; - - my $req = HTTP::Request->new('REPURGE', $re); - $req->protocol('HTTP/1.1'); - $client->send_request($req, 2); - my ($ev, $resp) = - $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" - if $ev eq 'ev_client_timeout'; -} - sub testPagePurged($) { my ($self) = @_; my $client = $self->new_client; - my $resp; # Warm up the cache $self->get($client, $KEEP_URL); + $self->assert_ok(); $self->get($client, $PURGE_URL); + $self->assert_ok(); # Verify the state of the cache - $self->get_cached($client, $KEEP_URL); - $self->get_cached($client, $PURGE_URL); + $self->get($client, $KEEP_URL); + $self->assert_ok(); + $self->assert_cached(); + $self->get($client, $PURGE_URL); + $self->assert_ok(); + $self->assert_cached(); # Send the purge request - $self->purge($client, $PURGE_RE); + $self->request($client, 'REPURGE', $PURGE_RE); # Verify the state of the cache - $self->get_cached($client, $KEEP_URL); - $self->get_uncached($client, $PURGE_URL); + $self->get($client, $KEEP_URL); + $self->assert_ok(); + $self->assert_cached(); + $self->get($client, $PURGE_URL); + $self->assert_ok(); + $self->assert_uncached(); $client->shutdown(); Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-07-28 11:41:35 UTC (rev 1781) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket056.pm 2007-07-28 15:29:31 UTC (rev 1782) @@ -33,6 +33,9 @@ use strict; use base 'Varnish::Test::Case'; +our $DESCR = "Checks that Varnish passes the correct HTTP version" . + " to both server and client in pass mode."; + our $VCL = " sub vcl_recv { pass; @@ -53,7 +56,8 @@ $request->protocol($cv); $client->send_request($request, 2); - my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + my ($event, $response) = + $self->run_loop('ev_client_response', 'ev_client_timeout'); die "Client time-out before receiving a (complete) response\n" if $event eq 'ev_client_timeout'; @@ -82,14 +86,12 @@ delete $self->{'cv', 'sv'}; } -sub ev_server_request($$$$) { - my ($self, $server, $connection, $request) = @_; +sub server($$$) { + my ($self, $request, $response) = @_; - my $response = HTTP::Response->new(404, undef, undef, - sprintf ("%s not found\n", $request->uri)); + $response->code(404); + $response->content(sprintf("%s not found\n", $request->uri)); $response->protocol($self->{'sv'}); - $connection->send_response($response); - $connection->shutdown; } 1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-07-28 11:41:35 UTC (rev 1781) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket102.pm 2007-07-28 15:29:31 UTC (rev 1782) @@ -33,6 +33,9 @@ use strict; use base 'Varnish::Test::Case'; +our $DESCR = "Checks that Varnish includes the response body when" . + " handling GET and POST, but not when handling HEAD."; + our $VCL = <new_client; - for (my $i = 0; $i < 2; $i++) { - my $request = HTTP::Request->new('POST', '/'); - $request->protocol('HTTP/1.1'); - $client->send_request($request, 2); - my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); + $self->get($client, '/'); + $self->assert_body($BODY); + $self->assert_uncached(); - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Empty body\n" - if $response->content eq ''; - die "Incorrect body\n" - if $response->content ne $body; - } + $self->post($client, '/'); + $self->assert_body($BODY); + $self->assert_cached(); + $self->head($client, '/'); + $self->assert_no_body(); + $self->assert_cached(); + $client->shutdown(); return 'OK'; } -sub ev_server_request($$$$) { - my ($self, $server, $connection, $request) = @_; +sub server($$$) { + my ($self, $request, $response) = @_; - my $response = HTTP::Response->new(200, undef, - [ 'Content-Length', length($body), - 'Connection', 'Keep-Alive' ], - $body); - $response->protocol('HTTP/1.1'); - $connection->send_response($response); + $response->content($BODY); } 1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm 2007-07-28 11:41:35 UTC (rev 1781) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Ticket128.pm 2007-07-28 15:29:31 UTC (rev 1782) @@ -33,6 +33,8 @@ use strict; use base 'Varnish::Test::Case'; +our $DESCR = "Tests the synthetic error response code."; + our $CODE = 400; our $MESSAGE = "These are not the droids you are looking for"; @@ -46,19 +48,9 @@ my ($self) = @_; my $client = $self->new_client; - my $request = HTTP::Request->new('GET', '/'); - $request->protocol('HTTP/1.0'); - $client->send_request($request, 2); - - my ($event, $response) = $self->run_loop('ev_client_response', 'ev_client_timeout'); - - die "Client time-out before receiving a (complete) response\n" - if $event eq 'ev_client_timeout'; - die "Incorrect response code\n" - if $response->code != $CODE; - die "Incorrect response message\n" - unless $response->content =~ m/\Q$MESSAGE\E/o; - + $self->get($client, '/'); + $self->assert_code($CODE); + $self->assert_body(qr/\Q$MESSAGE\E/); $client->shutdown(); return 'OK'; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-07-28 11:41:35 UTC (rev 1781) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/Vary.pm 2007-07-28 15:29:31 UTC (rev 1782) @@ -33,6 +33,10 @@ use strict; use base 'Varnish::Test::Case'; +our $DESCR = "Tests Vary: support by requesting the same document" . + " in different languages and verifying that the correct version" . + " is returned and cached."; + our %languages = ( 'en' => "Hello World!\n", 'no' => "Hallo Verden!\n", @@ -41,48 +45,36 @@ sub testVary($) { my ($self) = @_; - my $client = $self->new_client; - my $request = HTTP::Request->new('GET', '/'); + my $client = $self->new_client(); foreach my $lang (keys %languages) { - $request->header('Accept-Language', $lang); - $request->protocol('HTTP/1.1'); - $client->send_request($request, 2); - my ($event, $response) = - $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "No (complete) response received\n" - unless defined($response); - die "Empty body\n" - if $response->content() eq ''; - die "Incorrect body\n" - if $response->content() ne $languages{$lang}; + $self->get($client, '/', [ 'Accept-Language', $lang]); + # $self->assert_uncached(); + $self->assert_header('Language', $lang); + $self->assert_body($languages{$lang}); } + foreach my $lang (keys %languages) { + $self->get($client, '/', [ 'Accept-Language', $lang]); + $self->assert_cached(); + $self->assert_body($languages{$lang}); + } $client->shutdown(); return 'OK'; } -sub ev_server_request($$$$) { - my ($self, $server, $connection, $request) = @_; +sub server($$$) { + my ($self, $request, $response) = @_; - my $body; - my @headers; if (my $lang = $request->header("Accept-Language")) { $lang = 'en' unless ($lang && $languages{$lang}); - $body = $languages{$lang}; - push(@headers, ('Language', $lang)); + $response->content($languages{$lang}); + $response->header('Language' => $lang); + $response->header('Vary' => 'Accept-Language'); } else { die 'Not ready for this!'; } - - my $response = HTTP::Response->new(200, undef, - [ 'Content-Length', length($body), - 'Vary', 'Accept-Language', - @headers ], - $body); - $response->protocol('HTTP/1.1'); - $connection->send_response($response); } 1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-07-28 11:41:35 UTC (rev 1781) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-07-28 15:29:31 UTC (rev 1782) @@ -51,6 +51,7 @@ use Varnish::Test::Client; use HTTP::Request; use HTTP::Response; +use POSIX qw(strftime); use Time::HiRes qw(gettimeofday tv_interval); sub new($$) { @@ -175,6 +176,10 @@ }; } +# +# Default event handlers +# + sub ev_client_response($$$) { my ($self, $client, $response) = @_; @@ -188,6 +193,159 @@ return $client; } +sub ev_server_request($$$$) { + my ($self, $server, $connection, $request) = @_; + + no strict 'refs'; + my $method = $request->method(); + my $handler; + if ($self->can("server_$method")) { + $handler = ref($self) . "::server_$method"; + } elsif ($self->can("server")) { + $handler = ref($self) . "::server"; + } else { + die "No server callback defined\n"; + } + + my $response = HTTP::Response->new(); + $response->code(200); + $response->header('Date' => + strftime("%a, %d %b %Y %T GMT", gmtime(time()))); + $response->header('Server' => ref($self)); + $response->header('Connection' => 'keep-alive'); + $response->content(''); + $response->protocol('HTTP/1.1'); + $self->$handler($request, $response); + $response->header('Content-Length' => + length($response->content())); + $connection->send_response($response); +} + +# +# Client utilities +# + +sub request($$$$;$$) { + my ($self, $client, $method, $uri, $header, $content) = @_; + + my $req = HTTP::Request->new($method, $uri, $header, $content); + $req->protocol('HTTP/1.1'); + $client->send_request($req, 2); + my ($ev, $resp) = + $self->run_loop('ev_client_response', 'ev_client_timeout'); + die "Internal error\n" + unless $resp && ref($resp) && $resp->isa('HTTP::Response'); + die "Client time-out before receiving a (complete) response\n" + if $ev eq 'ev_client_timeout'; + die "No X-Varnish header\n" + unless $resp->header('X-Varnish'); + $resp->request($req); + return $self->{'cached_response'} = $resp; +} + +sub head($$$;$) { + my ($self, $client, $uri, $header) = @_; + + return $self->request($client, 'HEAD', $uri, $header); +} + +sub get($$$;$) { + my ($self, $client, $uri, $header) = @_; + + return $self->request($client, 'GET', $uri, $header); +} + +sub post($$$;$$) { + my ($self, $client, $uri, $header, $body) = @_; + + $header = [] + unless defined($header); + push(@{$header}, 'content-length', length($body)) + if defined($body); + return $self->request($client, 'POST', $uri, $header, $body); +} + +sub assert_code($$;$) { + my ($self, $code, $resp) = @_; + + $resp = $self->{'cached_response'} + unless defined($resp); + die "Expected $code, got @{[$resp->code]}\n" + unless $resp->code == $code; +} + +sub assert_ok($;$) { + my ($self, $resp) = @_; + + $resp = $self->{'cached_response'} + unless defined($resp); + + $self->assert_code(200, $resp); +} + +sub assert_cached($;$) { + my ($self, $resp) = @_; + + $resp = $self->{'cached_response'} + unless defined($resp); + + my $uri = $resp->request->uri; + die "$uri should be cached but isn't\n" + unless $resp->header('X-Varnish') =~ /^\d+ \d+$/; +} + +sub assert_uncached($;$) { + my ($self, $resp) = @_; + + $resp = $self->{'cached_response'} + unless defined($resp); + + my $uri = $resp->request->uri; + die "$uri shouldn't be cached but is\n" + if $resp->header('X-Varnish') =~ /^\d+ \d+$/; +} + +sub assert_header($$;$$) { + my ($self, $header, $re, $resp) = @_; + + $resp = $self->{'cached_response'} + unless defined($resp); + + die "$header: header missing\n" + unless defined($resp->header($header)); + if (defined($re)) { + die "$header: header does not match\n" + unless $resp->header($header) =~ m/$re/; + } +} + +sub assert_body($;$$) { + my ($self, $re, $resp) = @_; + + $resp = $self->{'cached_response'} + unless defined($resp); + + die "Response has no body\n" + unless defined($resp->content()); + if (defined($re)) { + die "Response body does not match\n" + unless $resp->content() =~ m/$re/; + } +} + +sub assert_no_body($;$) { + my ($self, $resp) = @_; + + $resp = $self->{'cached_response'} + unless defined($resp); + die "Response shouldn't have a body, but does\n" + if defined($resp->content()) && length($resp->content()); +} + +# +# Miscellaneous +# + sub usleep($$) { my ($self, $usec) = @_; From des at projects.linpro.no Mon Jul 30 08:03:42 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 30 Jul 2007 10:03:42 +0200 (CEST) Subject: r1783 - in trunk/varnish-cache/include: . compat Message-ID: <20070730080342.E9B4B1EC030@projects.linpro.no> Author: des Date: 2007-07-30 10:03:42 +0200 (Mon, 30 Jul 2007) New Revision: 1783 Modified: trunk/varnish-cache/include/compat/vis.h trunk/varnish-cache/include/vsb.h Log: Avoid referencing and __{BEGIN,END}_DECLS. Based on Theo Schlossnagle's Solaris portability patch. Modified: trunk/varnish-cache/include/compat/vis.h =================================================================== --- trunk/varnish-cache/include/compat/vis.h 2007-07-28 15:29:31 UTC (rev 1782) +++ trunk/varnish-cache/include/compat/vis.h 2007-07-30 08:03:42 UTC (rev 1783) @@ -71,15 +71,17 @@ */ #define UNVIS_END 1 /* no more characters */ -#include - -__BEGIN_DECLS +#ifdef __cplusplus +extern "C" { +#endif char *vis(char *, int, int, int); int strvis(char *, const char *, int); int strvisx(char *, const char *, size_t, int); int strunvis(char *, const char *); int strunvisx(char *, const char *, int); int unvis(char *, int, int *, int); -__END_DECLS +#ifdef __cplusplus +}; +#endif #endif /* !_VIS_H_ */ Modified: trunk/varnish-cache/include/vsb.h =================================================================== --- trunk/varnish-cache/include/vsb.h 2007-07-28 15:29:31 UTC (rev 1782) +++ trunk/varnish-cache/include/vsb.h 2007-07-30 08:03:42 UTC (rev 1783) @@ -50,7 +50,9 @@ int s_flags; /* flags */ }; -__BEGIN_DECLS +#ifdef __cplusplus +extern "C" { +#endif /* * API functions */ @@ -73,6 +75,8 @@ int vsb_len(struct vsb *); int vsb_done(struct vsb *); void vsb_delete(struct vsb *); -__END_DECLS +#ifdef __cplusplus +}; +#endif #endif From des at projects.linpro.no Mon Jul 30 09:49:06 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 30 Jul 2007 11:49:06 +0200 (CEST) Subject: r1784 - in trunk/varnish-cache: bin/varnishd lib/libvarnish Message-ID: <20070730094906.07C3D1EC2A3@projects.linpro.no> Author: des Date: 2007-07-30 11:49:05 +0200 (Mon, 30 Jul 2007) New Revision: 1784 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/lib/libvarnish/vpf.c Log: Avoid using non-portable . Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-30 08:03:42 UTC (rev 1783) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-30 09:49:05 UTC (rev 1784) @@ -42,8 +42,6 @@ #include #include -#include /* XXX */ - #ifndef HAVE_SETPROCTITLE #include "compat/setproctitle.h" #endif @@ -188,8 +186,10 @@ AZ(pipe(child_fds)); MCF_ParamSync(); i = fork(); - if (i < 0) - errx(1, "Could not fork child"); + if (i < 0) { + perror("Could not fork child"); + exit(1); + } if (i == 0) { if (geteuid() == 0) { XXXAZ(setgid(params->gid)); Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-07-30 08:03:42 UTC (rev 1783) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-07-30 09:49:05 UTC (rev 1784) @@ -31,7 +31,8 @@ * The management process and CLI handling */ -#include +#include + #include #include #include @@ -44,7 +45,6 @@ #include #include #include -#include #ifndef HAVE_DAEMON #include "compat/daemon.h" Modified: trunk/varnish-cache/lib/libvarnish/vpf.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vpf.c 2007-07-30 08:03:42 UTC (rev 1783) +++ trunk/varnish-cache/lib/libvarnish/vpf.c 2007-07-30 09:49:05 UTC (rev 1784) @@ -37,7 +37,6 @@ #include #include #include -#include #include #ifndef HAVE_STRLCPY From des at projects.linpro.no Mon Jul 30 13:50:17 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 30 Jul 2007 15:50:17 +0200 (CEST) Subject: r1785 - trunk/varnish-cache/lib/libvarnish Message-ID: <20070730135017.034F51EC429@projects.linpro.no> Author: des Date: 2007-07-30 15:50:16 +0200 (Mon, 30 Jul 2007) New Revision: 1785 Modified: trunk/varnish-cache/lib/libvarnish/time.c Log: Use mktime() rather than the unportable timegm(). The downside is that we're at the mercy of the TZ environment variable. Modified: trunk/varnish-cache/lib/libvarnish/time.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/time.c 2007-07-30 09:49:05 UTC (rev 1784) +++ trunk/varnish-cache/lib/libvarnish/time.c 2007-07-30 13:50:16 UTC (rev 1785) @@ -113,7 +113,7 @@ for (r = fmts; *r != NULL; r++) { memset(&tm, 0, sizeof tm); if (strptime(p, *r, &tm) != NULL) - return(timegm(&tm)); + return (mktime(&tm)); } return (0); } From phk at phk.freebsd.dk Mon Jul 30 13:52:57 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Mon, 30 Jul 2007 13:52:57 +0000 Subject: r1785 - trunk/varnish-cache/lib/libvarnish In-Reply-To: Your message of "Mon, 30 Jul 2007 15:50:17 +0200." <20070730135017.034F51EC429@projects.linpro.no> Message-ID: <14423.1185803577@critter.freebsd.dk> In message <20070730135017.034F51EC429 at projects.linpro.no>, des at projects.linpro.no writes: >Author: des >Date: 2007-07-30 15:50:16 +0200 (Mon, 30 Jul 2007) >New Revision: 1785 > >Modified: > trunk/varnish-cache/lib/libvarnish/time.c >Log: >Use mktime() rather than the unportable timegm(). The downside is that we're >at the mercy of the TZ environment variable. Which OS doesn't have timegm() ? Lack of timegm() is so bogus that it should be handled in compat IMO. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk at FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From des at projects.linpro.no Mon Jul 30 13:54:48 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 30 Jul 2007 15:54:48 +0200 (CEST) Subject: r1786 - trunk/varnish-cache/bin/varnishd Message-ID: <20070730135448.E14DB1EC2A3@projects.linpro.no> Author: des Date: 2007-07-30 15:54:48 +0200 (Mon, 30 Jul 2007) New Revision: 1786 Modified: trunk/varnish-cache/bin/varnishd/varnishd.c Log: Explicitly set TZ to GMT. Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-07-30 13:50:16 UTC (rev 1785) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-07-30 13:54:48 UTC (rev 1786) @@ -387,6 +387,9 @@ setbuf(stdout, NULL); setbuf(stderr, NULL); + setenv("TZ", "GMT", 1); + tzset(); + memset(cli, 0, sizeof cli); cli[0].sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND); XXXAN(cli[0].sb); From des at linpro.no Mon Jul 30 14:16:10 2007 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Mon, 30 Jul 2007 16:16:10 +0200 Subject: r1785 - trunk/varnish-cache/lib/libvarnish In-Reply-To: <14423.1185803577@critter.freebsd.dk> (Poul-Henning Kamp's message of "Mon\, 30 Jul 2007 13\:52\:57 +0000") References: <14423.1185803577@critter.freebsd.dk> Message-ID: <87ps2a0yfp.fsf@des.linpro.no> "Poul-Henning Kamp" writes: > Which OS doesn't have timegm() ? timegm() is a BSDism. Solaris doesn't have it, and I suspect other SysV derivatives (Tru64 etc.) don't either. > Lack of timegm() is so bogus that it should be handled in compat IMO. There is no reliable way to emulate it. DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From des at projects.linpro.no Mon Jul 30 14:16:24 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 30 Jul 2007 16:16:24 +0200 (CEST) Subject: r1787 - trunk/varnish-cache/lib/libvarnish Message-ID: <20070730141624.13A4C1EC030@projects.linpro.no> Author: des Date: 2007-07-30 16:16:23 +0200 (Mon, 30 Jul 2007) New Revision: 1787 Modified: trunk/varnish-cache/lib/libvarnish/flopen.c trunk/varnish-cache/lib/libvarnish/vpf.c Log: Use fcntl(2)-style locks instead of non-portable flock(2)-style locks. Based on Theo Schlossnagle's Solaris portability patch. Modified: trunk/varnish-cache/lib/libvarnish/flopen.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/flopen.c 2007-07-30 13:54:48 UTC (rev 1786) +++ trunk/varnish-cache/lib/libvarnish/flopen.c 2007-07-30 14:16:23 UTC (rev 1787) @@ -44,6 +44,7 @@ { int fd, operation, serrno, trunc; struct stat sb, fsb; + struct flock lock; mode_t mode; #ifdef O_EXLOCK @@ -59,9 +60,11 @@ va_end(ap); } - operation = LOCK_EX; - if (flags & O_NONBLOCK) - operation |= LOCK_NB; + lock.l_type = (flags & O_WRONLY || flags & O_RDWR) ? F_WRLCK : F_RDLCK; + lock.l_start = 0; + lock.l_whence = SEEK_SET; + lock.l_len = 0; + operation = (flags & O_NONBLOCK) ? F_SETLK : F_SETLKW; trunc = (flags & O_TRUNC); flags &= ~O_TRUNC; @@ -70,7 +73,7 @@ if ((fd = open(path, flags, mode)) == -1) /* non-existent or no access */ return (-1); - if (flock(fd, operation) == -1) { + if (fcntl(fd, operation, &lock) == -1) { /* unsupported or interrupted */ serrno = errno; close(fd); Modified: trunk/varnish-cache/lib/libvarnish/vpf.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vpf.c 2007-07-30 13:54:48 UTC (rev 1786) +++ trunk/varnish-cache/lib/libvarnish/vpf.c 2007-07-30 14:16:23 UTC (rev 1787) @@ -32,12 +32,12 @@ #include #include +#include +#include #include #include +#include #include -#include -#include -#include #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" @@ -222,8 +222,14 @@ static int _vpf_remove(struct pidfh *pfh, int freeit) { + struct flock lock; int error; + lock.l_type = F_UNLCK; + lock.l_start = 0; + lock.l_whence = SEEK_SET; + lock.l_len = 0; + error = vpf_verify(pfh); if (error != 0) { errno = error; @@ -232,7 +238,7 @@ if (unlink(pfh->pf_path) == -1) error = errno; - if (flock(pfh->pf_fd, LOCK_UN) == -1) { + if (fcntl(pfh->pf_fd, F_SETLK, &lock) == -1) { if (error == 0) error = errno; } From phk at phk.freebsd.dk Mon Jul 30 14:19:33 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Mon, 30 Jul 2007 14:19:33 +0000 Subject: r1785 - trunk/varnish-cache/lib/libvarnish In-Reply-To: Your message of "Mon, 30 Jul 2007 16:16:10 +0200." <87ps2a0yfp.fsf@des.linpro.no> Message-ID: <14572.1185805173@critter.freebsd.dk> In message <87ps2a0yfp.fsf at des.linpro.no>, =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= writes: >"Poul-Henning Kamp" writes: >> Which OS doesn't have timegm() ? > >timegm() is a BSDism. Solaris doesn't have it, and I suspect other SysV >derivatives (Tru64 etc.) don't either. > >> Lack of timegm() is so bogus that it should be handled in compat IMO. > >There is no reliable way to emulate it. There is, force libc to live in UTC/GMT by setting env variables etc. But this is a mess, which is why I want us to handle it in compat. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk at FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From des at projects.linpro.no Mon Jul 30 14:19:45 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 30 Jul 2007 16:19:45 +0200 (CEST) Subject: r1788 - trunk/varnish-cache/bin/varnishd Message-ID: <20070730141945.CE4411EC2A3@projects.linpro.no> Author: des Date: 2007-07-30 16:19:45 +0200 (Mon, 30 Jul 2007) New Revision: 1788 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: pid_t is not necessarily compatible with int. Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-30 14:16:23 UTC (rev 1787) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-30 14:19:45 UTC (rev 1788) @@ -166,7 +166,7 @@ static void start_child(void) { - int i; + pid_t pid; unsigned u; char *p; struct ev *e; @@ -185,12 +185,11 @@ AZ(pipe(&heritage.fds[2])); AZ(pipe(child_fds)); MCF_ParamSync(); - i = fork(); - if (i < 0) { + if ((pid = fork()) < 0) { perror("Could not fork child"); exit(1); } - if (i == 0) { + if (pid == 0) { if (geteuid() == 0) { XXXAZ(setgid(params->gid)); XXXAZ(setuid(params->uid)); @@ -217,7 +216,7 @@ exit (1); } - fprintf(stderr, "start child pid %d\n", i); + fprintf(stderr, "start child pid %jd\n", (intmax_t)pid); AZ(close(child_fds[1])); child_fds[1] = -1; From des at projects.linpro.no Mon Jul 30 14:22:01 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 30 Jul 2007 16:22:01 +0200 (CEST) Subject: r1789 - trunk/varnish-cache/bin/varnishd Message-ID: <20070730142201.211721EC030@projects.linpro.no> Author: des Date: 2007-07-30 16:22:00 +0200 (Mon, 30 Jul 2007) New Revision: 1789 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: Bogons in previous commit. Pass me the pointy hat... Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-30 14:19:45 UTC (rev 1788) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-07-30 14:22:00 UTC (rev 1789) @@ -197,8 +197,7 @@ /* Redirect stdin/out/err */ AZ(close(0)); - i = open("/dev/null", O_RDONLY); - xxxassert(i == 0); + assert(open("/dev/null", O_RDONLY) == 0); assert(dup2(child_fds[1], 1) == 1); assert(dup2(child_fds[1], 2) == 2); AZ(close(child_fds[0])); @@ -213,7 +212,7 @@ signal(SIGTERM, SIG_DFL); child_main(); - exit (1); + exit(1); } fprintf(stderr, "start child pid %jd\n", (intmax_t)pid); @@ -247,7 +246,7 @@ heritage.fds[1] = -1; AZ(close(heritage.fds[2])); heritage.fds[2] = -1; - child_pid = i; + child_pid = pid; if (mgt_push_vcls_and_start(&u, &p)) { fprintf(stderr, "Pushing vcls failed:\n%s\n", p); free(p); From phk at phk.freebsd.dk Mon Jul 30 14:22:23 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Mon, 30 Jul 2007 14:22:23 +0000 Subject: r1786 - trunk/varnish-cache/bin/varnishd In-Reply-To: Your message of "Mon, 30 Jul 2007 15:54:48 +0200." <20070730135448.E14DB1EC2A3@projects.linpro.no> Message-ID: <14615.1185805343@critter.freebsd.dk> In message <20070730135448.E14DB1EC2A3 at projects.linpro.no>, des at projects.linpro.no writes: >Author: des >Date: 2007-07-30 15:54:48 +0200 (Mon, 30 Jul 2007) >New Revision: 1786 > >Modified: > trunk/varnish-cache/bin/varnishd/varnishd.c >Log: >Explicitly set TZ to GMT. I am not happy about this, it forces all timestamps we may generate, including syslog &c to be GMT. We should only use this hack on deficient OS's. btw: on sysV derivatives, check libbsd. >+ setenv("TZ", "GMT", 1); >+ tzset(); >+ -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk at FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From des at linpro.no Mon Jul 30 14:25:56 2007 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Mon, 30 Jul 2007 16:25:56 +0200 Subject: r1785 - trunk/varnish-cache/lib/libvarnish In-Reply-To: <14572.1185805173@critter.freebsd.dk> (Poul-Henning Kamp's message of "Mon\, 30 Jul 2007 14\:19\:33 +0000") References: <14572.1185805173@critter.freebsd.dk> Message-ID: <87lkcy0xzf.fsf@des.linpro.no> "Poul-Henning Kamp" writes: > "Dag-Erling Sm?rgrav" writes: > > "Poul-Henning Kamp" writes: > > > Lack of timegm() is so bogus that it should be handled in compat IMO. > > There is no reliable way to emulate it. > There is, force libc to live in UTC/GMT by setting env variables etc. First, it wouldn't be thread-safe since the environment is shared between threads. Second, setenv() etc. can potentially call malloc(), which is expensive. Third, setenv() etc. can potentially leak memory. I know the C / POSIX time-keeping API is rotten, but it's all we have. DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From des at linpro.no Mon Jul 30 14:28:14 2007 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Mon, 30 Jul 2007 16:28:14 +0200 Subject: r1786 - trunk/varnish-cache/bin/varnishd In-Reply-To: <14615.1185805343@critter.freebsd.dk> (Poul-Henning Kamp's message of "Mon\, 30 Jul 2007 14\:22\:23 +0000") References: <14615.1185805343@critter.freebsd.dk> Message-ID: <87hcnm0xvl.fsf@des.linpro.no> "Poul-Henning Kamp" writes: > "Dag-Erling Sm?rgrav" writes: > > Explicitly set TZ to GMT. > I am not happy about this, it forces all timestamps we may generate, > including syslog &c to be GMT. No, syslog timestamps are generated by syslogd(8). time.c already assumes that all timestamps it handles are in GMT. DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From des at projects.linpro.no Mon Jul 30 14:31:16 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 30 Jul 2007 16:31:16 +0200 (CEST) Subject: r1790 - trunk/varnish-cache/lib/libvarnish Message-ID: <20070730143116.96F801EC429@projects.linpro.no> Author: des Date: 2007-07-30 16:31:16 +0200 (Mon, 30 Jul 2007) New Revision: 1790 Modified: trunk/varnish-cache/lib/libvarnish/flopen.c Log: I accidentally committed the wrong patch in r1787; this corrects the logic used to determine which lock type (shared or exclusive) to use. Modified: trunk/varnish-cache/lib/libvarnish/flopen.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/flopen.c 2007-07-30 14:22:00 UTC (rev 1789) +++ trunk/varnish-cache/lib/libvarnish/flopen.c 2007-07-30 14:31:16 UTC (rev 1790) @@ -60,7 +60,7 @@ va_end(ap); } - lock.l_type = (flags & O_WRONLY || flags & O_RDWR) ? F_WRLCK : F_RDLCK; + lock.l_type = (flags & O_RDONLY) ? F_RDLCK : F_WRLCK; lock.l_start = 0; lock.l_whence = SEEK_SET; lock.l_len = 0; From des at projects.linpro.no Mon Jul 30 14:39:04 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 30 Jul 2007 16:39:04 +0200 (CEST) Subject: r1791 - trunk/varnish-cache/bin/varnishd Message-ID: <20070730143904.01F0D1EC2A3@projects.linpro.no> Author: des Date: 2007-07-30 16:39:03 +0200 (Mon, 30 Jul 2007) New Revision: 1791 Modified: trunk/varnish-cache/bin/varnishd/cache.h Log: Note that MAX_IOVS is intentionally not equal to IOV_MAX. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-07-30 14:31:16 UTC (rev 1790) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-07-30 14:39:03 UTC (rev 1791) @@ -56,6 +56,7 @@ HTTP_HDR_MAX = 32 }; +/* Note: intentionally not IOV_MAX */ #define MAX_IOVS (HTTP_HDR_MAX * 2) /* Amount of per-worker logspace */ From des at projects.linpro.no Tue Jul 31 06:06:28 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 31 Jul 2007 08:06:28 +0200 (CEST) Subject: r1792 - trunk/varnish-cache/man Message-ID: <20070731060628.97A461EC030@projects.linpro.no> Author: des Date: 2007-07-31 08:06:28 +0200 (Tue, 31 Jul 2007) New Revision: 1792 Modified: trunk/varnish-cache/man/vcl.7 Log: Fine-tune the vhost example. Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-07-30 14:39:03 UTC (rev 1791) +++ trunk/varnish-cache/man/vcl.7 2007-07-31 06:06:28 UTC (rev 1792) @@ -559,8 +559,9 @@ sub vcl_recv { if (req.http.host ~ "^(www\.)?example\.com$") { + set req.http.host = "www.example.com"; set req.backend = www; - } elsif (req.http.host ~ "^images\.example\.com") { + } elsif (req.http.host ~ "^images\.example\.com$") { set req.backend = images; } else { error 404 "Unknown virtual host";