From des at projects.linpro.no Fri Aug 3 18:46:44 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 3 Aug 2007 20:46:44 +0200 (CEST) Subject: r1793 - in trunk/varnish-cache: etc man Message-ID: <20070803184644.7EEA31EC2AE@projects.linpro.no> Author: des Date: 2007-08-03 20:46:43 +0200 (Fri, 03 Aug 2007) New Revision: 1793 Modified: trunk/varnish-cache/etc/default.vcl trunk/varnish-cache/man/vcl.7 Log: Synchronize these two files. Modified: trunk/varnish-cache/etc/default.vcl =================================================================== --- trunk/varnish-cache/etc/default.vcl 2007-07-31 06:06:28 UTC (rev 1792) +++ trunk/varnish-cache/etc/default.vcl 2007-08-03 18:46:43 UTC (rev 1793) @@ -75,14 +75,27 @@ # if (!obj.cacheable) { # pass; # } -# if (resp.http.Set-Cookie) { +# if (obj.http.Set-Cookie) { # pass; # } # insert; #} # +# +## Called before a cached object is delivered to the client +# +#sub vcl_deliver { +# deliver; +#} +# ## Called when an object nears its expiry time # #sub vcl_timeout { # discard; #} +# +## Called when an object is about to be discarded +# +#sub vcl_discard { +# discard; +#} Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-07-31 06:06:28 UTC (rev 1792) +++ trunk/varnish-cache/man/vcl.7 2007-08-03 18:46:43 UTC (rev 1793) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd July 13, 2007 +.Dd August 3, 2007 .Dt VCL 7 .Os .Sh NAME @@ -474,7 +474,7 @@ The following code is the equivalent of the default configuration with the backend address set to "backend.example.com" and no backend port specified. -.\" Keep this in synch with bin/varnishd/mgt_vcc.c +.\" Keep this in synch with bin/varnishd/mgt_vcc.c and etc/default.vcl .Bd -literal -offset 4n backend default { set backend.host = "backend.example.com"; @@ -534,11 +534,11 @@ deliver; } -sub vcl_discard { +sub vcl_timeout { discard; } -sub vcl_timeout { +sub vcl_discard { discard; } .Ed From des at projects.linpro.no Fri Aug 3 18:50:06 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 3 Aug 2007 20:50:06 +0200 (CEST) Subject: r1794 - trunk/varnish-cache/bin/varnishd Message-ID: <20070803185006.145F31EC405@projects.linpro.no> Author: des Date: 2007-08-03 20:50:05 +0200 (Fri, 03 Aug 2007) New Revision: 1794 Modified: trunk/varnish-cache/bin/varnishd/storage_file.c Log: Try harder to avoid integer overflows in cache file size calculations on 32-bit platforms. Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2007-08-03 18:46:43 UTC (rev 1793) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-08-03 18:50:05 UTC (rev 1794) @@ -118,7 +118,7 @@ static void smf_calcsize(struct smf_sc *sc, const char *size, int newfile) { - uintmax_t l; + uintmax_t l, fssize; unsigned bs; char suff[2]; int i, explicit; @@ -127,6 +127,7 @@ AN(sc); AZ(fstat(sc->fd, &st)); + xxxassert(S_ISREG(st.st_mode)); #if defined(HAVE_SYS_MOUNT_H) || defined(HAVE_SYS_VFS_H) struct statfs fsst; @@ -137,9 +138,10 @@ bs = sc->pagesize; if (bs < fsst.f_bsize) bs = fsst.f_bsize; + xxxassert(bs % sc->pagesize == 0); + xxxassert(bs % fsst.f_bsize == 0); + fssize = fsst.f_bsize * fsst.f_bavail; - xxxassert(S_ISREG(st.st_mode)); - i = sscanf(size, "%ju%1s", &l, suff); /* can return -1, 0, 1 or 2 */ explicit = i; @@ -179,7 +181,7 @@ l *= (uintmax_t)(1024UL * 1024UL) * (uintmax_t)(1024UL * 1024UL); else if (suff[0] == '%') { - l *= fsst.f_bsize * fsst.f_bavail; + l *= fssize; l /= 100; } } @@ -200,14 +202,14 @@ if (l < st.st_size) { AZ(ftruncate(sc->fd, l)); - } else if (l - st.st_size > fsst.f_bsize * fsst.f_bavail) { - l = ((uintmax_t)fsst.f_bsize * fsst.f_bavail * 80) / 100; + } else if (l - st.st_size > fssize) { + l = fssize * 80 / 100; fprintf(stderr, "WARNING: storage file size reduced" " to %ju (80%% of available disk space)\n", l); } } - /* round down to of filesystem blocksize or pagesize */ + /* round down to multiple of filesystem blocksize or pagesize */ l -= (l % bs); if (l < MINPAGES * (uintmax_t)sc->pagesize) { From phk at projects.linpro.no Sun Aug 5 19:37:44 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 5 Aug 2007 21:37:44 +0200 (CEST) Subject: r1795 - trunk/varnish-cache/bin/varnishd Message-ID: <20070805193744.47F811EC471@projects.linpro.no> Author: phk Date: 2007-08-05 21:37:44 +0200 (Sun, 05 Aug 2007) New Revision: 1795 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Synchronize the paramters after we call their accessor functions rather than when we don't find one. This makes changing runtime paramters work again, without the need to ask for a nonexistent parameter to trigger the update. Ticket: 136 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-08-03 18:50:05 UTC (rev 1794) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-08-05 19:37:44 UTC (rev 1795) @@ -754,12 +754,12 @@ for (pp = parspec; pp->name != NULL; pp++) { if (!strcmp(pp->name, param)) { pp->func(cli, pp, val); + MCF_ParamSync(); return; } } cli_result(cli, CLIS_PARAM); cli_out(cli, "Unknown paramter \"%s\".", param); - MCF_ParamSync(); } From phk at projects.linpro.no Sun Aug 5 19:52:23 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 5 Aug 2007 21:52:23 +0200 (CEST) Subject: r1796 - trunk/varnish-cache/bin/varnishd Message-ID: <20070805195223.7A5321EC3F0@projects.linpro.no> Author: phk Date: 2007-08-05 21:52:23 +0200 (Sun, 05 Aug 2007) New Revision: 1796 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Introduce a "replace()" function to replace a malloc'ed string. Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-08-05 19:37:44 UTC (rev 1795) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-08-05 19:52:23 UTC (rev 1796) @@ -65,6 +65,18 @@ static struct params master; +/* XXX: Far too generic to live here ? */ +static void +replace(char **p, const char *q) +{ + + AN(*q); + if (*p != NULL) + free(*p); + *p = strdup(q); + AN(*p); +} + /*--------------------------------------------------------------------*/ static void @@ -156,21 +168,14 @@ cli_result(cli, CLIS_PARAM); return; } - if (master.user) - free(master.user); - master.user = strdup(pw->pw_name); - AN(master.user); + replace(&master.user, pw->pw_name); master.uid = pw->pw_uid; /* set group to user's primary group */ - if (master.group) - free(master.group); if ((gr = getgrgid(pw->pw_gid)) != NULL && (gr = getgrnam(gr->gr_name)) != NULL && - gr->gr_gid == pw->pw_gid) { - master.group = strdup(gr->gr_name); - AN(master.group); - } + gr->gr_gid == pw->pw_gid) + replace(&master.group, gr->gr_name); master.gid = pw->pw_gid; } else if (master.user) { cli_out(cli, "%s (%d)", master.user, (int)master.uid); @@ -193,10 +198,7 @@ cli_result(cli, CLIS_PARAM); return; } - if (master.group) - free(master.group); - master.group = strdup(gr->gr_name); - AN(master.group); + replace(&master.group, gr->gr_name); master.gid = gr->gr_gid; } else if (master.group) { cli_out(cli, "%s (%d)", master.group, (int)master.gid); @@ -428,9 +430,7 @@ return; } - free(master.listen_address); - master.listen_address = strdup(arg); - AN(master.listen_address); + replace(&master.listen_address, arg); clean_listen_sock_head(&heritage.socks); heritage.nsocks = 0; From phk at projects.linpro.no Sun Aug 5 20:17:49 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 5 Aug 2007 22:17:49 +0200 (CEST) Subject: r1797 - trunk/varnish-cache/bin/varnishd Message-ID: <20070805201749.900E21EC471@projects.linpro.no> Author: phk Date: 2007-08-05 22:17:49 +0200 (Sun, 05 Aug 2007) New Revision: 1797 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Make the nonexistence of "nobody" and "nogroup" users and groups nonfatal Ticket: 140 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-08-05 19:52:23 UTC (rev 1796) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-08-05 20:17:49 UTC (rev 1797) @@ -51,6 +51,8 @@ #include "vss.h" +#define MAGIC_INIT_STRING "\001" + struct parspec; typedef void tweak_t(struct cli *, struct parspec *, const char *arg); @@ -153,7 +155,13 @@ } } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * XXX: slightly magic. We want to initialize to "nobody" (XXX: shouldn't + * XXX: that be something autocrap found for us ?) but we don't want to + * XXX: fail initialization if that user doesn't exists, even though we + * XXX: do want to fail it, in subsequent sets. + * XXX: The magic init string is a hack for this. + */ static void tweak_user(struct cli *cli, struct parspec *par, const char *arg) @@ -163,20 +171,28 @@ (void)par; if (arg != NULL) { - if ((pw = getpwnam(arg)) == NULL) { + if (!strcmp(arg, MAGIC_INIT_STRING)) { + pw = getpwnam("nobody"); + if (pw == NULL) { + master.uid = getuid(); + return; + } + } else + pw = getpwnam(arg); + if (pw == NULL) { cli_out(cli, "Unknown user"); cli_result(cli, CLIS_PARAM); return; } replace(&master.user, pw->pw_name); master.uid = pw->pw_uid; + master.gid = pw->pw_gid; /* set group to user's primary group */ if ((gr = getgrgid(pw->pw_gid)) != NULL && (gr = getgrnam(gr->gr_name)) != NULL && gr->gr_gid == pw->pw_gid) replace(&master.group, gr->gr_name); - master.gid = pw->pw_gid; } else if (master.user) { cli_out(cli, "%s (%d)", master.user, (int)master.uid); } else { @@ -184,7 +200,9 @@ } } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * XXX: see comment for tweak_user, same thing here. + */ static void tweak_group(struct cli *cli, struct parspec *par, const char *arg) @@ -193,7 +211,17 @@ (void)par; if (arg != NULL) { - if ((gr = getgrnam(arg)) == NULL) { + if (!strcmp(arg, MAGIC_INIT_STRING)) { + gr = getgrnam("nogroup"); + if (gr == NULL) { + /* Only replace if tweak_user didn't */ + if (master.gid == 0) + master.gid = getgid(); + return; + } + } else + gr = getgrnam(arg); + if (gr == NULL) { cli_out(cli, "Unknown group"); cli_result(cli, CLIS_PARAM); return; @@ -524,11 +552,11 @@ "The unprivileged user to run as. Setting this will " "also set \"group\" to the specified user's primary group.\n" MUST_RESTART, - "nobody" }, + MAGIC_INIT_STRING }, { "group", tweak_group, "The unprivileged group to run as.\n" MUST_RESTART, - "nogroup" }, + MAGIC_INIT_STRING }, { "default_ttl", tweak_default_ttl, "The TTL assigned to objects if neither the backend nor " "the VCL code assigns one.\n" From phk at projects.linpro.no Sun Aug 5 20:26:09 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 5 Aug 2007 22:26:09 +0200 (CEST) Subject: r1798 - in trunk/varnish-cache: . bin/varnishd Message-ID: <20070805202609.DCD371EC3F0@projects.linpro.no> Author: phk Date: 2007-08-05 22:26:09 +0200 (Sun, 05 Aug 2007) New Revision: 1798 Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/configure.ac Log: We need the math library on some systems. Ticket 138 Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-08-05 20:17:49 UTC (rev 1797) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-08-05 20:26:09 UTC (rev 1798) @@ -68,4 +68,4 @@ $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libcompat/libcompat.a \ $(top_builddir)/lib/libvcl/libvcl.la \ - ${DL_LIBS} ${PTHREAD_LIBS} + ${DL_LIBS} ${PTHREAD_LIBS} ${LIBM} Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2007-08-05 20:17:49 UTC (rev 1797) +++ trunk/varnish-cache/configure.ac 2007-08-05 20:26:09 UTC (rev 1798) @@ -50,6 +50,9 @@ LIBS="${save_LIBS}" AC_SUBST(PTHREAD_LIBS) +AC_CHECK_LIBM +AC_SUBST(LIBM) + # Checks for header files. AC_HEADER_STDC AC_HEADER_SYS_WAIT From phk at projects.linpro.no Sun Aug 5 20:47:16 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 5 Aug 2007 22:47:16 +0200 (CEST) Subject: r1799 - trunk/varnish-cache/bin/varnishd Message-ID: <20070805204716.ABE851EC471@projects.linpro.no> Author: phk Date: 2007-08-05 22:47:16 +0200 (Sun, 05 Aug 2007) New Revision: 1799 Modified: trunk/varnish-cache/bin/varnishd/stevedore.c Log: Add missing assert Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2007-08-05 20:26:09 UTC (rev 1798) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2007-08-05 20:47:16 UTC (rev 1799) @@ -112,6 +112,7 @@ xxxassert(q != NULL); stv = malloc(sizeof *stv); + AN(stv); if (!cmp_storage(&sma_stevedore, spec, p)) { *stv = sma_stevedore; From phk at projects.linpro.no Sun Aug 5 20:57:20 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 5 Aug 2007 22:57:20 +0200 (CEST) Subject: r1800 - trunk/varnish-cache/lib/libvcl Message-ID: <20070805205720.712B11EC3F0@projects.linpro.no> Author: phk Date: 2007-08-05 22:57:20 +0200 (Sun, 05 Aug 2007) New Revision: 1800 Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c Log: Add a missing return: we always return after detecting the first error. Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-08-05 20:47:16 UTC (rev 1799) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-08-05 20:57:20 UTC (rev 1800) @@ -279,6 +279,7 @@ if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); + return; } Expect(tl, ')'); From phk at projects.linpro.no Sun Aug 5 20:57:32 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 5 Aug 2007 22:57:32 +0200 (CEST) Subject: r1801 - trunk/varnish-cache/lib/libvcl Message-ID: <20070805205732.46A561EC471@projects.linpro.no> Author: phk Date: 2007-08-05 22:57:32 +0200 (Sun, 05 Aug 2007) New Revision: 1801 Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c Log: vrt.h is not needed here. Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-08-05 20:57:20 UTC (rev 1800) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-08-05 20:57:32 UTC (rev 1801) @@ -38,8 +38,6 @@ #include "vcc_compile.h" #include "libvarnish.h" -#include "vrt.h" - /*--------------------------------------------------------------------*/ static void Compound(struct tokenlist *tl); From phk at projects.linpro.no Sun Aug 5 21:06:41 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 5 Aug 2007 23:06:41 +0200 (CEST) Subject: r1802 - trunk/varnish-cache/bin/varnishd Message-ID: <20070805210641.421EE1EC454@projects.linpro.no> Author: phk Date: 2007-08-05 23:06:41 +0200 (Sun, 05 Aug 2007) New Revision: 1802 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Add comment to remind myself. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-08-05 20:57:32 UTC (rev 1801) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-08-05 21:06:41 UTC (rev 1802) @@ -98,7 +98,7 @@ " if (req.http.host) {\n" " set req.hash += req.http.host;\n" " } else {\n" - " set req.hash += server.ip;\n" + " set req.hash += server.ip;\n" /* XXX: see ticket 137 */ " }\n" #endif " hash;\n" From phk at projects.linpro.no Mon Aug 6 08:07:18 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 6 Aug 2007 10:07:18 +0200 (CEST) Subject: r1803 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20070806080718.A47A91EC460@projects.linpro.no> Author: phk Date: 2007-08-06 10:07:18 +0200 (Mon, 06 Aug 2007) New Revision: 1803 Modified: trunk/varnish-cache/include/vcl.h 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_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl Log: Have the VCL compiler provide a hint about the worst case number of operations on the req.hash variable. It is only a hint, because it merely counts how many times the parser saw something being added to the req.hash variable. If the operation was in a subroutine which was called multiple times, the hint will not reflect the number of actual operations. For now we will deal with that at runtime, at the expense of a failed transaction every time we run short. If this becomes an issue, an extensive topological analysis of the VCL program can give us a definitive count. Modified: trunk/varnish-cache/include/vcl.h =================================================================== --- trunk/varnish-cache/include/vcl.h 2007-08-05 21:06:41 UTC (rev 1802) +++ trunk/varnish-cache/include/vcl.h 2007-08-06 08:07:18 UTC (rev 1803) @@ -26,6 +26,8 @@ const char **srcname; const char **srcbody; + unsigned nhashcount; + void *priv; vcl_init_f *init_func; Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-08-05 21:06:41 UTC (rev 1802) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-08-06 08:07:18 UTC (rev 1803) @@ -209,6 +209,12 @@ return; } Fb(tl, 0, ");\n"); + /* + * We count the number of operations on the req.hash + * variable, so that varnishd can preallocate the worst case + * number of slots for composing the hash string. + */ + tl->nhashcount++; break; case STRING: if (tl->t->tok != '=') { Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-08-05 21:06:41 UTC (rev 1802) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-08-06 08:07:18 UTC (rev 1803) @@ -348,6 +348,7 @@ Fc(tl, 0, "\t.nsrc = %u,\n", tl->nsources); Fc(tl, 0, "\t.srcname = srcname,\n"); Fc(tl, 0, "\t.srcbody = srcbody,\n"); + Fc(tl, 0, "\t.nhashcount = %u,\n", tl->nhashcount); #define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) \ Fc(tl, 0, "\t." #l "_func = VGC_function_vcl_" #l ",\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-08-05 21:06:41 UTC (rev 1802) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-08-06 08:07:18 UTC (rev 1803) @@ -83,6 +83,7 @@ struct proc *mprocs[N_METHODS]; unsigned recnt; + unsigned nhashcount; }; enum var_type { Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-08-05 21:06:41 UTC (rev 1802) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-08-06 08:07:18 UTC (rev 1803) @@ -338,6 +338,8 @@ vsb_cat(sb, " const char **srcname;\n"); vsb_cat(sb, " const char **srcbody;\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, " unsigned nhashcount;\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, " void *priv;\n"); vsb_cat(sb, "\n"); vsb_cat(sb, " vcl_init_f *init_func;\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-08-05 21:06:41 UTC (rev 1802) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-08-06 08:07:18 UTC (rev 1803) @@ -142,6 +142,8 @@ const char **srcname; const char **srcbody; + unsigned nhashcount; + void *priv; vcl_init_f *init_func; From phk at projects.linpro.no Mon Aug 6 09:19:20 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 6 Aug 2007 11:19:20 +0200 (CEST) Subject: r1804 - in trunk/varnish-cache: include lib/libvarnish Message-ID: <20070806091920.86A7C1EC2B4@projects.linpro.no> Author: phk Date: 2007-08-06 11:19:20 +0200 (Mon, 06 Aug 2007) New Revision: 1804 Modified: trunk/varnish-cache/include/libvarnish.h trunk/varnish-cache/lib/libvarnish/crc32.c Log: Add piecemal crc32 function back, we will need it for the scatter/gather hash string. Modified: trunk/varnish-cache/include/libvarnish.h =================================================================== --- trunk/varnish-cache/include/libvarnish.h 2007-08-06 08:07:18 UTC (rev 1803) +++ trunk/varnish-cache/include/libvarnish.h 2007-08-06 09:19:20 UTC (rev 1804) @@ -42,6 +42,7 @@ char **ParseArgv(const char *s, int comment); /* from libvarnish/crc32.c */ +uint32_t crc32(uint32_t crc, const void *p1, unsigned l); uint32_t crc32_l(const void *p1, unsigned l); /* from libvarnish/time.c */ Modified: trunk/varnish-cache/lib/libvarnish/crc32.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/crc32.c 2007-08-06 08:07:18 UTC (rev 1803) +++ trunk/varnish-cache/lib/libvarnish/crc32.c 2007-08-06 09:19:20 UTC (rev 1804) @@ -82,14 +82,21 @@ }; uint32_t -crc32_l(const void *p1, unsigned l) +crc32(uint32_t crc, const void *p1, unsigned l) { const unsigned char *p; - uint32_t crc; - crc = ~0U; - for (p = (const unsigned char*)p1; l-- > 0; p++) crc = (crc >> 8) ^ crc32bits[(crc ^ *p) & 0xff]; + return (crc); +} + +uint32_t +crc32_l(const void *p1, unsigned l) +{ + uint32_t crc; + + crc = crc32(~0U, p1, l); return (crc ^ ~0U); } + From phk at projects.linpro.no Mon Aug 6 09:25:21 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 6 Aug 2007 11:25:21 +0200 (CEST) Subject: r1805 - trunk/varnish-cache/bin/varnishd Message-ID: <20070806092521.295611EC2A3@projects.linpro.no> Author: phk Date: 2007-08-06 11:25:20 +0200 (Mon, 06 Aug 2007) New Revision: 1805 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/hash_classic.c trunk/varnish-cache/bin/varnishd/hash_simple_list.c trunk/varnish-cache/bin/varnishd/hash_slinger.h Log: Rewrite the req.hash implmentation: Instead of assembling the entire hash-string in the workspace, use a scatter gather approach, hinted by the VCL compiler. This eliminates the workspace reservation which prevented regsub() from working in vcl_hash, and reduces the size of the necessary workspace a fair bit as well, at the cost of a little bit of complexity in the hash implmentations. Closes ticket 137 and possibly 141 Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-06 09:19:20 UTC (rev 1804) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-06 09:25:20 UTC (rev 1805) @@ -315,8 +315,11 @@ struct workreq workreq; struct acct acct; - char *hash_b; /* Start of hash string */ - char *hash_e; /* End of hash string */ + /* pointers to hash string components */ + unsigned nhashptr; + unsigned ihashptr; + unsigned lhashptr; + const char **hashptr; }; struct backend { @@ -390,6 +393,8 @@ /* cache_hash.c */ void HSH_Prealloc(struct sess *sp); +int HSH_Compare(struct sess *sp, const char *b, const char *e); +void HSH_Copy(struct sess *sp, char *b, const char *e); struct object *HSH_Lookup(struct sess *sp); void HSH_Unbusy(struct object *o); void HSH_Ref(struct object *o); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-06 09:19:20 UTC (rev 1804) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-06 09:25:20 UTC (rev 1805) @@ -469,15 +469,26 @@ cnt_lookup(struct sess *sp) { struct object *o; + char *p; + uintptr_t u; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); if (sp->obj == NULL) { - WS_Reserve(sp->http->ws, 0); - sp->hash_b = sp->http->ws->f; - sp->hash_e = sp->hash_b; + + /* Allocate the pointers we need, align properly. */ + sp->lhashptr = 1; /* space for NUL */ + sp->ihashptr = 0; + sp->nhashptr = sp->vcl->nhashcount * 2; + p = WS_Alloc(sp->http->ws, + sizeof(const char *) * (sp->nhashptr + 1)); + u = (uintptr_t)p; + u &= sizeof(const char *) - 1; + if (u) + p += sizeof(const char *) - u; + sp->hashptr = (void*)p; + VCL_hash_method(sp); /* XXX: no-op for now */ - WS_ReleaseP(sp->http->ws, sp->hash_e); /* XXX check error */ } @@ -494,9 +505,6 @@ return (1); } - WS_Return(sp->http->ws, sp->hash_b, sp->hash_e); - sp->hash_b = sp->hash_e = NULL; - sp->obj = o; /* If we inserted a new object it's a miss */ Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-08-06 09:19:20 UTC (rev 1804) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-08-06 09:25:20 UTC (rev 1805) @@ -109,6 +109,47 @@ } } +int +HSH_Compare(struct sess *sp, const char *b, const char *e) +{ + int i; + unsigned u, v; + + i = sp->lhashptr - (e - b); + if (i) + return (i); + for (u = 0; u < sp->ihashptr; u += 2) { + v = sp->hashptr[u + 1] - sp->hashptr[u]; + i = memcmp(sp->hashptr[u], b, v); + if (i) + return (i); + b += v; + i = '#' - *b++; + if (i) + return (i); + } + assert(*b == '\0'); + b++; + assert(b == e); + return (0); +} + +void +HSH_Copy(struct sess *sp, char *b, const char *e) +{ + unsigned u, v; + + assert((e - b) >= sp->lhashptr); + for (u = 0; u < sp->ihashptr; u += 2) { + v = sp->hashptr[u + 1] - sp->hashptr[u]; + memcpy(b, sp->hashptr[u], v); + b += v; + *b++ = '#'; + } + *b++ = '\0'; + assert(b <= e); +} + struct object * HSH_Lookup(struct sess *sp) { @@ -133,9 +174,8 @@ LOCK(&oh->mtx); goto were_back; } -VSLR(SLT_Debug, sp->fd, sp->hash_b, sp->hash_e); - oh = hash->lookup(sp->hash_b, sp->hash_e, w->nobjhead); + oh = hash->lookup(sp, w->nobjhead); CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); if (oh == w->nobjhead) w->nobjhead = NULL; Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-06 09:19:20 UTC (rev 1804) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-06 09:25:20 UTC (rev 1805) @@ -456,7 +456,9 @@ return (sp->mysockaddr); } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * Add an element to the array/list of hash bits. + */ void VRT_l_req_hash(struct sess *sp, const char *str) @@ -466,10 +468,18 @@ if (str == NULL) str = ""; l = strlen(str); - xxxassert (sp->hash_e + l + 1 <= sp->http->ws->e); - memcpy(sp->hash_e, str, l); - sp->hash_e[l] = '#'; - sp->hash_e += l + 1; + + /* + * XXX: handle this by bouncing sp->vcl->nhashcount when it fails + * XXX: and dispose of this request either by reallocating the + * XXX: hashptr (if possible) or restarting/error the request + */ + xxxassert(sp->ihashptr < sp->nhashptr); + + sp->hashptr[sp->ihashptr] = str; + sp->hashptr[sp->ihashptr + 1] = str + l; + sp->ihashptr += 2; + sp->lhashptr += l + 1; } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_classic.c 2007-08-06 09:19:20 UTC (rev 1804) +++ trunk/varnish-cache/bin/varnishd/hash_classic.c 2007-08-06 09:25:20 UTC (rev 1805) @@ -121,36 +121,44 @@ */ static struct objhead * -hcl_lookup(const char *b, const char *e, struct objhead *noh) +hcl_lookup(struct sess *sp, struct objhead *noh) { struct hcl_entry *he, *he2; struct hcl_hd *hp; - unsigned u1, digest, kl, r; + unsigned u1, digest, r; + unsigned u, v; int i; CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC); - digest = crc32_l(b, e - b); + digest = ~0U; + for (u = 0; u < sp->ihashptr; u += 2) { + v = sp->hashptr[u + 1] - sp->hashptr[u]; + digest = crc32(digest, sp->hashptr[u], v); + } + digest ^= ~0U; u1 = digest % hcl_nhash; hp = &hcl_head[u1]; - kl = e - b; he2 = NULL; for (r = 0; r < 2; r++ ) { LOCK(&hp->mtx); TAILQ_FOREACH(he, &hp->head, list) { CHECK_OBJ_NOTNULL(he, HCL_ENTRY_MAGIC); - if (kl < he->klen) + if (sp->lhashptr < he->klen) continue; - if (kl > he->klen) + if (sp->lhashptr > he->klen) break; if (he->digest < digest) continue; if (he->digest > digest) break; - if (memcmp(he->key, b, kl)) + i = HSH_Compare(sp, he->key, he->key + he->klen); + if (i < 0) continue; + if (i > 0) + break; he->refcnt++; noh = he->oh; UNLOCK(&hp->mtx); @@ -174,7 +182,7 @@ } UNLOCK(&hp->mtx); - i = sizeof *he2 + kl; + i = sizeof *he2 + sp->lhashptr; he2 = calloc(i, 1); XXXAN(he2); he2->magic = HCL_ENTRY_MAGIC; @@ -182,11 +190,11 @@ he2->digest = digest; he2->hash = u1; he2->head = hp; - he2->klen = kl; + he2->klen = sp->lhashptr; noh->hashpriv = he2; he2->key = (void*)(he2 + 1); - memcpy(he2->key, b, kl); + HSH_Copy(sp, he2->key, he2->key + sp->lhashptr); } assert(he2 == NULL); /* FlexeLint */ INCOMPL(); Modified: trunk/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2007-08-06 09:19:20 UTC (rev 1804) +++ trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2007-08-06 09:25:20 UTC (rev 1805) @@ -73,26 +73,20 @@ */ static struct objhead * -hsl_lookup(const char *b, const char *e, struct objhead *nobj) +hsl_lookup(struct sess *sp, struct objhead *nobj) { struct hsl_entry *he, *he2; - int i, l; + int i; - l = e - b; LOCK(&hsl_mutex); TAILQ_FOREACH(he, &hsl_head, list) { - if (l > he->keylen) - continue; - if (l < he->keylen) - break;; - i = memcmp(b, he->key, l); + i = HSH_Compare(sp, he->key, he->key + he->keylen); if (i < 0) continue; if (i > 0) break; he->refcnt++; nobj = he->obj; - nobj->hashpriv = he; UNLOCK(&hsl_mutex); return (nobj); } @@ -100,13 +94,13 @@ UNLOCK(&hsl_mutex); return (NULL); } - he2 = calloc(sizeof *he2 + l, 1); + he2 = calloc(sizeof *he2 + sp->lhashptr, 1); XXXAN(he2); he2->obj = nobj; he2->refcnt = 1; he2->key = (void*)(he2 + 1); - he2->keylen = l; - memcpy(he2->key, b, l); + he2->keylen = sp->lhashptr; + HSH_Copy(sp, he2->key, he2->key + he2->keylen); nobj->hashpriv = he2; if (he != NULL) TAILQ_INSERT_BEFORE(he, he2, list); Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2007-08-06 09:19:20 UTC (rev 1804) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2007-08-06 09:25:20 UTC (rev 1805) @@ -29,9 +29,11 @@ * $Id$ */ +struct sess; + typedef int hash_init_f(const char *); typedef void hash_start_f(void); -typedef struct objhead *hash_lookup_f(const char *key1, const char *key2, struct objhead *nobj); +typedef struct objhead *hash_lookup_f(struct sess *sp, struct objhead *nobj); typedef int hash_deref_f(struct objhead *obj); struct hash_slinger { From phk at projects.linpro.no Mon Aug 6 09:28:44 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 6 Aug 2007 11:28:44 +0200 (CEST) Subject: r1806 - trunk/varnish-cache/bin/varnishd Message-ID: <20070806092844.535581EC2B4@projects.linpro.no> Author: phk Date: 2007-08-06 11:28:44 +0200 (Mon, 06 Aug 2007) New Revision: 1806 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_ws.c Log: Forgot an assert. WS_Return() is now unused, comment it out. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-06 09:25:20 UTC (rev 1805) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-06 09:28:44 UTC (rev 1806) @@ -95,7 +95,6 @@ void WS_Assert(struct ws *ws); void WS_Reset(struct ws *ws); char *WS_Alloc(struct ws *ws, unsigned bytes); -void WS_Return(struct ws *ws, char *b, char *e); /*-------------------------------------------------------------------- * HTTP Request/Response/Header handling structure. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-06 09:25:20 UTC (rev 1805) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-06 09:28:44 UTC (rev 1806) @@ -482,6 +482,7 @@ sp->nhashptr = sp->vcl->nhashcount * 2; p = WS_Alloc(sp->http->ws, sizeof(const char *) * (sp->nhashptr + 1)); + XXXAN(p); u = (uintptr_t)p; u &= sizeof(const char *) - 1; if (u) Modified: trunk/varnish-cache/bin/varnishd/cache_ws.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ws.c 2007-08-06 09:25:20 UTC (rev 1805) +++ trunk/varnish-cache/bin/varnishd/cache_ws.c 2007-08-06 09:28:44 UTC (rev 1806) @@ -129,6 +129,8 @@ ws->r = NULL; } +#if 0 +/* XXX: not used anywhere (yet) */ void WS_Return(struct ws *ws, char *s, char *e) { @@ -137,3 +139,4 @@ if (e == ws->f) ws->f = s; } +#endif From phk at projects.linpro.no Tue Aug 7 06:55:52 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 7 Aug 2007 08:55:52 +0200 (CEST) Subject: r1807 - trunk/varnish-cache/bin/varnishd Message-ID: <20070807065552.77AAE1EC2A3@projects.linpro.no> Author: phk Date: 2007-08-07 08:55:52 +0200 (Tue, 07 Aug 2007) New Revision: 1807 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c Log: When vcl_miss() take error action, remember to discard backend request. Ticket: 139 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-06 09:28:44 UTC (rev 1806) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-07 06:55:52 UTC (rev 1807) @@ -567,6 +567,8 @@ HSH_Unbusy(sp->obj); HSH_Deref(sp->obj); sp->obj = NULL; + vbe_free_bereq(sp->bereq); + sp->bereq = NULL; sp->step = STP_ERROR; return (0); } From phk at projects.linpro.no Tue Aug 7 07:23:11 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 7 Aug 2007 09:23:11 +0200 (CEST) Subject: r1808 - trunk/varnish-cache/bin/varnishd Message-ID: <20070807072311.0AF081EC3F0@projects.linpro.no> Author: phk Date: 2007-08-07 09:23:10 +0200 (Tue, 07 Aug 2007) New Revision: 1808 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c Log: Implement "error" action in vcl_fetch() and vcl_deliver() Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-07 06:55:52 UTC (rev 1807) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-07 07:23:10 UTC (rev 1808) @@ -149,8 +149,17 @@ sp->t_resp = TIM_real(); RES_BuildHttp(sp); VCL_deliver_method(sp); - if (sp->handling != VCL_RET_DELIVER) + switch (sp->handling) { + case VCL_RET_DELIVER: + break; + case VCL_RET_ERROR: + HSH_Deref(sp->obj); + sp->obj = NULL; + sp->step = STP_ERROR; + return (0); + default: INCOMPL(); + } RES_WriteObj(sp); HSH_Deref(sp->obj); @@ -323,11 +332,23 @@ VCL_fetch_method(sp); - if (sp->handling == VCL_RET_ERROR) + switch (sp->handling) { + case VCL_RET_ERROR: + sp->obj->ttl = 0; + sp->obj->cacheable = 0; + HSH_Unbusy(sp->obj); + HSH_Deref(sp->obj); + sp->obj = NULL; + sp->step = STP_ERROR; + return (0); + case VCL_RET_PASS: + sp->obj->pass = 1; + break; + case VCL_RET_INSERT: + break; + default: INCOMPL(); - - if (sp->handling == VCL_RET_PASS) - sp->obj->pass = 1; + } } sp->obj->cacheable = 1; From phk at projects.linpro.no Tue Aug 7 10:27:35 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 7 Aug 2007 12:27:35 +0200 (CEST) Subject: r1809 - trunk/varnish-cache/bin/varnishd Message-ID: <20070807102735.4119A1EC2A3@projects.linpro.no> Author: phk Date: 2007-08-07 12:27:34 +0200 (Tue, 07 Aug 2007) New Revision: 1809 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c Log: Minimize a race when looking up addresses for backends. The race is not closed however, proper locking needs to be thought out. An XXX comment documents this for now. Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-07 07:23:10 UTC (rev 1808) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-07 10:27:34 UTC (rev 1809) @@ -116,20 +116,20 @@ return (vbc); } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * XXX: There is a race here, we need to lock the replacement of the + * XXX: resolved addresses, or some other thread might try to access + * XXX: them while/during/after we changed them. + * XXX: preferably, we should make a copy to the vbe while we hold a + * XXX: lock anyway. + */ static void vbe_lookup(struct backend *bp) { - struct addrinfo *res, hint; + struct addrinfo *res, hint, *old; int error; - if (bp->addr != NULL) { - freeaddrinfo(bp->addr); - bp->addr = NULL; - bp->last_addr = NULL; - } - memset(&hint, 0, sizeof hint); hint.ai_family = PF_UNSPEC; hint.ai_socktype = SOCK_STREAM; @@ -144,8 +144,11 @@ printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */ return; } + old = bp->addr; bp->last_addr = res; bp->addr = res; + if (old != NULL) + freeaddrinfo(old); } /*--------------------------------------------------------------------*/ From phk at projects.linpro.no Wed Aug 8 08:49:11 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 8 Aug 2007 10:49:11 +0200 (CEST) Subject: r1810 - trunk/varnish-cache/bin/varnishd Message-ID: <20070808084911.D24571EC460@projects.linpro.no> Author: phk Date: 2007-08-08 10:49:11 +0200 (Wed, 08 Aug 2007) New Revision: 1810 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: Elminiate a spurious message when sigchild looses a race to popen(2). This fixed #143 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-08-07 10:27:34 UTC (rev 1809) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-08-08 08:49:11 UTC (rev 1810) @@ -305,6 +305,8 @@ ev_poker = NULL; r = wait4(-1, &status, WNOHANG, NULL); + if (r == 0) + return (0); if (r != child_pid || r == -1) { fprintf(stderr, "Unknown child died pid=%d status=0x%x\n", r, status); From des at projects.linpro.no Wed Aug 8 10:01:50 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 8 Aug 2007 12:01:50 +0200 (CEST) Subject: r1811 - trunk/varnish-cache Message-ID: <20070808100150.916211EC2A3@projects.linpro.no> Author: des Date: 2007-08-08 12:01:50 +0200 (Wed, 08 Aug 2007) New Revision: 1811 Modified: trunk/varnish-cache/autogen.sh Log: Remove FreeBSD workaround; the FreeBSD ports tree has had working autotools for two weeks now. Also fix inconsistent indentation. Modified: trunk/varnish-cache/autogen.sh =================================================================== --- trunk/varnish-cache/autogen.sh 2007-08-08 08:49:11 UTC (rev 1810) +++ trunk/varnish-cache/autogen.sh 2007-08-08 10:01:50 UTC (rev 1811) @@ -9,19 +9,17 @@ case `uname -s` in Darwin) - LIBTOOLIZE=glibtoolize - ;; + 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 - ;; + LIBTOOLIZE=libtoolize + ;; Linux) - LIBTOOLIZE=libtoolize - ;; + LIBTOOLIZE=libtoolize + ;; +*) + warn "unrecognized platform:" `uname -s` + LIBTOOLIZE=libtoolize esac automake_version=$(automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+') @@ -39,7 +37,7 @@ set -ex -aclocal ${FIX_BROKEN_FREEBSD_PORTS} +aclocal $LIBTOOLIZE --copy --force autoheader automake --add-missing --copy --foreign From des at projects.linpro.no Wed Aug 8 10:58:17 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 8 Aug 2007 12:58:17 +0200 (CEST) Subject: r1812 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070808105817.A6E291EC42F@projects.linpro.no> Author: des Date: 2007-08-08 12:58:17 +0200 (Wed, 08 Aug 2007) New Revision: 1812 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm Log: Improve request generation. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-08 10:01:50 UTC (rev 1811) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-08 10:58:17 UTC (rev 1812) @@ -197,7 +197,7 @@ my ($self, $server, $connection, $request) = @_; no strict 'refs'; - my $method = $request->method(); + my $method = lc($request->method()); my $handler; if ($self->can("server_$method")) { $handler = ref($self) . "::server_$method"; @@ -228,15 +228,26 @@ sub request($$$$;$$) { my ($self, $client, $method, $uri, $header, $content) = @_; - my $req = HTTP::Request->new($method, $uri, $header, $content); + my $req = HTTP::Request->new($method, $uri, $header); $req->protocol('HTTP/1.1'); + $req->header('Host' => 'varnish.example.com') + unless $req->header('Host'); + $req->header('User-Agent' => ref($self)) + unless $req->header('User-Agent'); + if (defined($content)) { + $req->header('Content-Type' => 'text/plain') + unless ($req->header('Content-Type')); + $req->header('Content-Length' => length($content)) + unless ($req->header('Content-Length')); + $req->content($content); + } $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 "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); @@ -260,8 +271,6 @@ $header = [] unless defined($header); - push(@{$header}, 'content-length', length($body)) - if defined($body); return $self->request($client, 'POST', $uri, $header, $body); } From des at projects.linpro.no Wed Aug 8 11:00:26 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 8 Aug 2007 13:00:26 +0200 (CEST) Subject: r1813 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070808110026.E7AA31EC2A3@projects.linpro.no> Author: des Date: 2007-08-08 13:00:26 +0200 (Wed, 08 Aug 2007) New Revision: 1813 Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm Log: Add three regression tests for POST request handling. All of them currently fail (see #47, #129). Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm (rev 0) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-08 11:00:26 UTC (rev 1813) @@ -0,0 +1,108 @@ +#!/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::POST; + +use strict; +use base 'Varnish::Test::Case'; + +our $DESCR = "Tests Varnish's ability to correctly pass POST requests" . + " to the backend, and their replies back to the client."; + +our $VCL = <new_client; + $self->post($client, "/pass_me", [], $MAGIC_WORDS); + $self->assert_ok(); + $self->assert_body(qr/\Q$MAGIC_WORDS\E/); + + return 'OK'; +} + +sub testPipePOST($) { + my ($self) = @_; + + my $client = $self->new_client; + $self->post($client, "/pipe_me", [], $MAGIC_WORDS); + $self->assert_ok(); + $self->assert_body(qr/\Q$MAGIC_WORDS\E/); + + return 'OK'; +} + +sub testCachePOST($) { + my ($self) = @_; + + my $client = $self->new_client; + + # Warm up the cache + $self->post($client, "/cache_me"); + $self->assert_ok(); + $self->assert_uncached(); + $self->assert_body(qr/\Q$NOTHING_HAPPENS\E/); + + # Verify that the request was cached + $self->post($client, "/cache_me"); + $self->assert_ok(); + $self->assert_cached(); + $self->assert_body(qr/\Q$NOTHING_HAPPENS\E/); + + return 'OK'; +} + +sub server_post($$$$) { + my ($self, $request, $response) = @_; + + if ($request->content()) { + $response->content("The Magic Words are " . $request->content()); + } else { + $response->content($NOTHING_HAPPENS); + } +} + +1; Property changes on: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm ___________________________________________________________________ Name: svn:keywords + Id Name: svn:eol-style + native From des at projects.linpro.no Wed Aug 8 12:08:25 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 8 Aug 2007 14:08:25 +0200 (CEST) Subject: r1814 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070808120825.334F61EC460@projects.linpro.no> Author: des Date: 2007-08-08 14:08:25 +0200 (Wed, 08 Aug 2007) New Revision: 1814 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Start varnishd with '-n regress'. Handle server failures gracefully. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-08-08 11:00:26 UTC (rev 1813) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-08-08 12:08:25 UTC (rev 1814) @@ -59,7 +59,8 @@ %config = ('server_address' => 'localhost:8081', 'varnish_address' => 'localhost:8080', - 'storage_spec' => 'file,/tmp/regress.bin,512k', + 'varnish_name' => 'regress', + 'storage_spec' => 'file,regress.bin,512k', %config); my $self = bless({ 'mux' => IO::Multiplex->new, @@ -107,9 +108,10 @@ $self->{'wait_for'} = \@wait_for; $self->{'in_loop'} = 1; - $self->{'mux'}->loop; + eval { $self->{'mux'}->loop; }; delete $self->{'in_loop'}; delete $self->{'wait_for'}; + die $@ if ($@); # Loop has now been paused due to the occurrence of an event we # were waiting for. This event is always found in the front of the Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-08 11:00:26 UTC (rev 1813) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-08 12:08:25 UTC (rev 1814) @@ -96,6 +96,7 @@ my @opts = ('-d', '-d', '-s', $engine->{'config'}->{'storage_spec'}, + '-n', $engine->{'config'}->{'varnish_name'}, '-a', $engine->{'config'}->{'varnish_address'}, '-b', $engine->{'config'}->{'server_address'}); From des at projects.linpro.no Wed Aug 8 12:10:17 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 8 Aug 2007 14:10:17 +0200 (CEST) Subject: r1815 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070808121017.7C6801EC2A3@projects.linpro.no> Author: des Date: 2007-08-08 14:10:17 +0200 (Wed, 08 Aug 2007) New Revision: 1815 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm Log: I'm not sure Varnish should GET from the backend when the client used POST but the VCL script decided to cache the request anyway. Treat it as an error for now. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-08 12:08:25 UTC (rev 1814) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-08 12:10:17 UTC (rev 1815) @@ -95,9 +95,15 @@ return 'OK'; } -sub server_post($$$$) { +sub server_get($$$) { my ($self, $request, $response) = @_; + die "Got GET request instead of POST\n"; +} + +sub server_post($$$) { + my ($self, $request, $response) = @_; + if ($request->content()) { $response->content("The Magic Words are " . $request->content()); } else { From phk at phk.freebsd.dk Wed Aug 8 13:34:22 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Wed, 08 Aug 2007 13:34:22 +0000 Subject: r1815 - trunk/varnish-tools/regress/lib/Varnish/Test/Case In-Reply-To: Your message of "Wed, 08 Aug 2007 14:10:17 +0200." <20070808121017.7C6801EC2A3@projects.linpro.no> Message-ID: <95053.1186580062@critter.freebsd.dk> In message <20070808121017.7C6801EC2A3 at projects.linpro.no>, des at projects.linpro .no writes: >Author: des >Date: 2007-08-08 14:10:17 +0200 (Wed, 08 Aug 2007) >New Revision: 1815 > >Modified: > trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm >Log: >I'm not sure Varnish should GET from the backend when the client used POST >but the VCL script decided to cache the request anyway. Treat it as an >error for now. POST should always be handled as pipe, unless we positively tell otherwise in VCL. > > >Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm >=================================================================== >--- trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-08 12:08:25 UTC (rev 1814) >+++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-08 12:10:17 UTC (rev 1815) >@@ -95,9 +95,15 @@ > return 'OK'; > } > >-sub server_post($$$$) { >+sub server_get($$$) { > my ($self, $request, $response) = @_; > >+ die "Got GET request instead of POST\n"; >+} >+ >+sub server_post($$$) { >+ my ($self, $request, $response) = @_; >+ > if ($request->content()) { > $response->content("The Magic Words are " . $request->content()); > } else { > _______________________________________________ >varnish-commit mailing list >varnish-commit at projects.linpro.no >http://projects.linpro.no/mailman/listinfo/varnish-commit > -- 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 Wed Aug 8 14:05:06 2007 From: des at linpro.no (=?iso-8859-1?Q?Dag-Erling_Sm=F8rgrav?=) Date: Wed, 08 Aug 2007 16:05:06 +0200 Subject: r1815 - trunk/varnish-tools/regress/lib/Varnish/Test/Case In-Reply-To: <95053.1186580062@critter.freebsd.dk> (Poul-Henning Kamp's message of "Wed, 08 Aug 2007 13:34:22 +0000") References: <95053.1186580062@critter.freebsd.dk> Message-ID: "Poul-Henning Kamp" writes: > POST should always be handled as pipe, unless we positively tell > otherwise in VCL. Yes. In this case we do (in one of three tests). There are good reasons for doing so under certain conditions. DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From phk at projects.linpro.no Wed Aug 8 19:43:52 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 8 Aug 2007 21:43:52 +0200 (CEST) Subject: r1816 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070808194352.390B21EC460@projects.linpro.no> Author: phk Date: 2007-08-08 21:43:51 +0200 (Wed, 08 Aug 2007) New Revision: 1816 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_cli.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/hash_classic.c trunk/varnish-cache/bin/varnishd/hash_simple_list.c trunk/varnish-cache/include/cli.h trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Implement purging on either of hash or url. In VCL: purge_url() purge_hash() (for an interrim period purge() will be the same as purge_url). In CLI url.purge hash.purge purge_hash operates on the hash-string which results from vcl_hash(), by default it is composed of: req.url "#" req.http.host "#" To purge everything on the virtual host foo.bar.com: In CLI: url.purge "#foo.bar.com#$" In VCL: purge_hash("#foo.bar.com#$"); The general format, if you have defined vcl_hash(), is: Each "req.hash +=" operator appends the right hand side of the += and a "#" separator. You'll have to figure out your own regexps. Under the hood: Move the hash string from object to objecthead and save space while we're at it. Fix indentation in generated source. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-08 19:43:51 UTC (rev 1816) @@ -262,6 +262,8 @@ pthread_mutex_t mtx; TAILQ_HEAD(,object) objects; + char *hash; + unsigned hashlen; }; /* -------------------------------------------------------------------*/ @@ -368,11 +370,12 @@ void vbe_free_bereq(struct bereq *bereq); /* cache_ban.c */ -void AddBan(const char *); +void AddBan(const char *, int hash); void BAN_Init(void); void cli_func_url_purge(struct cli *cli, char **av, void *priv); +void cli_func_hash_purge(struct cli *cli, char **av, void *priv); void BAN_NewObj(struct object *o); -int BAN_CheckObject(struct object *o, const char *url); +int BAN_CheckObject(struct object *o, const char *url, const char *hash); /* cache_center.c [CNT] */ void CNT_Session(struct sess *sp); @@ -392,8 +395,8 @@ /* cache_hash.c */ void HSH_Prealloc(struct sess *sp); -int HSH_Compare(struct sess *sp, const char *b, const char *e); -void HSH_Copy(struct sess *sp, char *b, const char *e); +int HSH_Compare(struct sess *sp, struct objhead *o); +void HSH_Copy(struct sess *sp, struct objhead *o); struct object *HSH_Lookup(struct sess *sp); void HSH_Unbusy(struct object *o); void HSH_Ref(struct object *o); Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2007-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2007-08-08 19:43:51 UTC (rev 1816) @@ -46,6 +46,7 @@ unsigned gen; regex_t regexp; char *ban; + int hash; }; static TAILQ_HEAD(,ban) ban_head = TAILQ_HEAD_INITIALIZER(ban_head); @@ -53,7 +54,7 @@ static struct ban *ban_start; void -AddBan(const char *regexp) +AddBan(const char *regexp, int hash) { struct ban *b; int i; @@ -68,6 +69,7 @@ (void)regerror(i, &b->regexp, buf, sizeof buf); VSL(SLT_Debug, 0, "REGEX: <%s>", buf); } + b->hash = hash; b->gen = ++ban_next; b->ban = strdup(regexp); TAILQ_INSERT_HEAD(&ban_head, b, list); @@ -82,7 +84,7 @@ } int -BAN_CheckObject(struct object *o, const char *url) +BAN_CheckObject(struct object *o, const char *url, const char *hash) { struct ban *b, *b0; int i; @@ -91,7 +93,7 @@ for (b = b0; b != NULL && b->gen > o->ban_seq; b = TAILQ_NEXT(b, list)) { - i = regexec(&b->regexp, url, 0, NULL, 0); + i = regexec(&b->regexp, b->hash ? hash : url, 0, NULL, 0); if (!i) return (1); } @@ -104,13 +106,22 @@ { (void)priv; - AddBan(av[2]); + AddBan(av[2], 0); cli_out(cli, "PURGE %s\n", av[2]); } void +cli_func_hash_purge(struct cli *cli, char **av, void *priv) +{ + + (void)priv; + AddBan(av[2], 1); + cli_out(cli, "PURGE %s\n", av[2]); +} + +void BAN_Init(void) { - AddBan("a"); + AddBan("\001", 0); } Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_cli.c 2007-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2007-08-08 19:43:51 UTC (rev 1816) @@ -67,6 +67,7 @@ { CLI_URL_QUERY, cli_func_url_query }, #endif { CLI_URL_PURGE, cli_func_url_purge }, + { CLI_HASH_PURGE, cli_func_hash_purge }, { CLI_VCL_LOAD, cli_func_config_load }, { CLI_VCL_LIST, cli_func_config_list }, { CLI_VCL_DISCARD, cli_func_config_discard }, Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2007-08-08 19:43:51 UTC (rev 1816) @@ -110,14 +110,16 @@ } int -HSH_Compare(struct sess *sp, const char *b, const char *e) +HSH_Compare(struct sess *sp, struct objhead *obj) { int i; unsigned u, v; + const char *b; - i = sp->lhashptr - (e - b); + i = sp->lhashptr - obj->hashlen; if (i) return (i); + b = obj->hash; for (u = 0; u < sp->ihashptr; u += 2) { v = sp->hashptr[u + 1] - sp->hashptr[u]; i = memcmp(sp->hashptr[u], b, v); @@ -130,16 +132,19 @@ } assert(*b == '\0'); b++; - assert(b == e); + assert(b == obj->hash + obj->hashlen); + VSL(SLT_Debug, sp->fd, "Hash Match: %s", obj->hash); return (0); } void -HSH_Copy(struct sess *sp, char *b, const char *e) +HSH_Copy(struct sess *sp, struct objhead *obj) { unsigned u, v; + char *b; - assert((e - b) >= sp->lhashptr); + assert(obj->hashlen >= sp->lhashptr); + b = obj->hash; for (u = 0; u < sp->ihashptr; u += 2) { v = sp->hashptr[u + 1] - sp->hashptr[u]; memcpy(b, sp->hashptr[u], v); @@ -147,7 +152,8 @@ *b++ = '#'; } *b++ = '\0'; - assert(b <= e); + VSL(SLT_Debug, sp->fd, "Hash: %s", obj->hash); + assert(b <= obj->hash + obj->hashlen); } struct object * @@ -195,7 +201,8 @@ /* Object banned but not reaped yet */ } else if (o->ttl <= sp->t_req) { /* Object expired */ - } else if (BAN_CheckObject(o, h->hd[HTTP_HDR_URL].b)) { + } else if (BAN_CheckObject(o, + h->hd[HTTP_HDR_URL].b, oh->hash)) { o->ttl = 0; VSL(SLT_ExpBan, 0, "%u was banned", o->xid); if (o->heap_idx != 0) Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-08 19:43:51 UTC (rev 1816) @@ -552,8 +552,8 @@ /*--------------------------------------------------------------------*/ void -VRT_purge(const char *regexp) +VRT_purge(const char *regexp, int hash) { - AddBan(regexp); + AddBan(regexp, hash); } Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_classic.c 2007-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/bin/varnishd/hash_classic.c 2007-08-08 19:43:51 UTC (rev 1816) @@ -46,8 +46,6 @@ #define HCL_ENTRY_MAGIC 0x0ba707bf TAILQ_ENTRY(hcl_entry) list; struct hcl_hd *head; - char *key; - unsigned klen; struct objhead *oh; unsigned refcnt; unsigned digest; @@ -146,15 +144,15 @@ LOCK(&hp->mtx); TAILQ_FOREACH(he, &hp->head, list) { CHECK_OBJ_NOTNULL(he, HCL_ENTRY_MAGIC); - if (sp->lhashptr < he->klen) + if (sp->lhashptr < he->oh->hashlen) continue; - if (sp->lhashptr > he->klen) + if (sp->lhashptr > he->oh->hashlen) break; if (he->digest < digest) continue; if (he->digest > digest) break; - i = HSH_Compare(sp, he->key, he->key + he->klen); + i = HSH_Compare(sp, he->oh); if (i < 0) continue; if (i > 0) @@ -182,19 +180,19 @@ } UNLOCK(&hp->mtx); - i = sizeof *he2 + sp->lhashptr; - he2 = calloc(i, 1); + he2 = calloc(sizeof *he2, 1); XXXAN(he2); he2->magic = HCL_ENTRY_MAGIC; he2->oh = noh; he2->digest = digest; he2->hash = u1; he2->head = hp; - he2->klen = sp->lhashptr; - noh->hashpriv = he2; - he2->key = (void*)(he2 + 1); - HSH_Copy(sp, he2->key, he2->key + sp->lhashptr); + noh->hashpriv = he2; + noh->hash = malloc(sp->lhashptr); + XXXAN(noh->hash); + noh->hashlen = sp->lhashptr; + HSH_Copy(sp, noh); } assert(he2 == NULL); /* FlexeLint */ INCOMPL(); Modified: trunk/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2007-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2007-08-08 19:43:51 UTC (rev 1816) @@ -44,8 +44,6 @@ struct hsl_entry { TAILQ_ENTRY(hsl_entry) list; - char *key; - int keylen; struct objhead *obj; unsigned refcnt; }; @@ -80,7 +78,7 @@ LOCK(&hsl_mutex); TAILQ_FOREACH(he, &hsl_head, list) { - i = HSH_Compare(sp, he->key, he->key + he->keylen); + i = HSH_Compare(sp, he->obj); if (i < 0) continue; if (i > 0) @@ -94,14 +92,17 @@ UNLOCK(&hsl_mutex); return (NULL); } - he2 = calloc(sizeof *he2 + sp->lhashptr, 1); + he2 = calloc(sizeof *he2, 1); XXXAN(he2); he2->obj = nobj; he2->refcnt = 1; - he2->key = (void*)(he2 + 1); - he2->keylen = sp->lhashptr; - HSH_Copy(sp, he2->key, he2->key + he2->keylen); + nobj->hashpriv = he2; + nobj->hash = malloc(sp->lhashptr); + XXXAN(nobj->hash); + nobj->hashlen = sp->lhashptr; + HSH_Copy(sp, nobj); + if (he != NULL) TAILQ_INSERT_BEFORE(he, he2, list); else Modified: trunk/varnish-cache/include/cli.h =================================================================== --- trunk/varnish-cache/include/cli.h 2007-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/include/cli.h 2007-08-08 19:43:51 UTC (rev 1816) @@ -63,10 +63,17 @@ #define CLI_URL_PURGE \ "url.purge", \ "url.purge ", \ - "\tAll urls matching regexp will consider currently cached\n" \ - "\tobjects obsolete", \ + "\tAll objects where the urls matches regexp will be " \ + "marked obsolete.", \ 1, 1 +#define CLI_HASH_PURGE \ + "hash.purge", \ + "hash.purge ", \ + "\tAll objects where the hash string matches regexp will be " \ + "marked obsolete.", \ + 1, 1 + #define CLI_URL_STATUS \ "url.status", \ "url.status ", \ Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/include/vrt.h 2007-08-08 19:43:51 UTC (rev 1816) @@ -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_purge(const char *); +void VRT_purge(const char *, int hash); 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-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-08-08 19:43:51 UTC (rev 1816) @@ -273,12 +273,12 @@ /*--------------------------------------------------------------------*/ static void -parse_purge(struct tokenlist *tl) +parse_purge_url(struct tokenlist *tl) { vcc_NextToken(tl); - Fb(tl, 0, "VRT_purge("); + Fb(tl, 1, "VRT_purge("); Expect(tl, '('); vcc_NextToken(tl); @@ -290,12 +290,36 @@ Expect(tl, ')'); vcc_NextToken(tl); - Fb(tl, 0, ");"); + Fb(tl, 0, ", 0);\n"); } /*--------------------------------------------------------------------*/ +static void +parse_purge_hash(struct tokenlist *tl) +{ + + vcc_NextToken(tl); + + Fb(tl, 1, "VRT_purge("); + + Expect(tl, '('); + vcc_NextToken(tl); + + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return; + } + + Expect(tl, ')'); + vcc_NextToken(tl); + Fb(tl, 0, ", 1);\n"); +} + + +/*--------------------------------------------------------------------*/ + typedef void action_f(struct tokenlist *tl); static struct action_table { @@ -310,7 +334,12 @@ { "call", parse_call }, { "set", parse_set }, { "remove", parse_remove }, - { "purge", parse_purge }, + { "purge_url", parse_purge_url }, + { "purge_hash", parse_purge_hash }, + + /* XXX: Compat remove in 1.2/2.0 */ + { "purge", parse_purge_url }, + { NULL, NULL } }; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-08-08 12:10:17 UTC (rev 1815) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-08-08 19:43:51 UTC (rev 1816) @@ -428,7 +428,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_purge(const char *);\n"); + vsb_cat(sb, "void VRT_purge(const char *, int hash);\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 des at projects.linpro.no Thu Aug 9 11:19:20 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 9 Aug 2007 13:19:20 +0200 (CEST) Subject: r1817 - in trunk/varnish-cache: . bin/varnishadm bin/varnishd bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishstat bin/varnishtop lib lib/libvarnishcompat Message-ID: <20070809111920.CC1D41EC2A3@projects.linpro.no> Author: des Date: 2007-08-09 13:19:20 +0200 (Thu, 09 Aug 2007) New Revision: 1817 Added: trunk/varnish-cache/lib/libvarnishcompat/ Removed: trunk/varnish-cache/lib/libcompat/ Modified: trunk/varnish-cache/bin/varnishadm/Makefile.am trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishhist/Makefile.am trunk/varnish-cache/bin/varnishlog/Makefile.am trunk/varnish-cache/bin/varnishncsa/Makefile.am trunk/varnish-cache/bin/varnishreplay/Makefile.am trunk/varnish-cache/bin/varnishstat/Makefile.am trunk/varnish-cache/bin/varnishtop/Makefile.am trunk/varnish-cache/configure.ac trunk/varnish-cache/lib/Makefile.am trunk/varnish-cache/lib/libvarnishcompat/Makefile.am Log: Rename libcompat to libvarnishcompat, and make it dynamic. Modified: trunk/varnish-cache/bin/varnishadm/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishadm/Makefile.am 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/bin/varnishadm/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) @@ -13,4 +13,4 @@ varnishadm_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) @@ -66,6 +66,6 @@ varnishd_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvcl/libvcl.la \ ${DL_LIBS} ${PTHREAD_LIBS} ${LIBM} Modified: trunk/varnish-cache/bin/varnishhist/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishhist/Makefile.am 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/bin/varnishhist/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) @@ -12,7 +12,7 @@ varnishhist_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ -lm \ ${CURSES_LIBS} ${PTHREAD_LIBS} Modified: trunk/varnish-cache/bin/varnishlog/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishlog/Makefile.am 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/bin/varnishlog/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) @@ -12,5 +12,5 @@ varnishlog_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la Modified: trunk/varnish-cache/bin/varnishncsa/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishncsa/Makefile.am 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/bin/varnishncsa/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) @@ -12,5 +12,5 @@ varnishncsa_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la Modified: trunk/varnish-cache/bin/varnishreplay/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishreplay/Makefile.am 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/bin/varnishreplay/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) @@ -13,7 +13,7 @@ varnishreplay_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${PTHREAD_LIBS} Modified: trunk/varnish-cache/bin/varnishstat/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishstat/Makefile.am 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/bin/varnishstat/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) @@ -12,6 +12,6 @@ varnishstat_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${CURSES_LIBS} ${RT_LIBS} Modified: trunk/varnish-cache/bin/varnishtop/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishtop/Makefile.am 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/bin/varnishtop/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) @@ -12,6 +12,6 @@ varnishtop_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${CURSES_LIBS} ${PTHREAD_LIBS} Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/configure.ac 2007-08-09 11:19:20 UTC (rev 1817) @@ -151,9 +151,9 @@ etc/Makefile include/Makefile lib/Makefile - lib/libcompat/Makefile lib/libvarnish/Makefile lib/libvarnishapi/Makefile + lib/libvarnishcompat/Makefile lib/libvcl/Makefile man/Makefile debian/Makefile Modified: trunk/varnish-cache/lib/Makefile.am =================================================================== --- trunk/varnish-cache/lib/Makefile.am 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/lib/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) @@ -1,7 +1,7 @@ # $Id$ SUBDIRS = \ - libcompat \ libvarnish \ libvarnishapi \ + libvarnishcompat \ libvcl Copied: trunk/varnish-cache/lib/libvarnishcompat (from rev 1816, trunk/varnish-cache/lib/libcompat) Modified: trunk/varnish-cache/lib/libvarnishcompat/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libcompat/Makefile.am 2007-08-08 19:43:51 UTC (rev 1816) +++ trunk/varnish-cache/lib/libvarnishcompat/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) @@ -2,9 +2,9 @@ INCLUDES = -I$(top_srcdir)/include -noinst_LIBRARIES = libcompat.a +lib_LTLIBRARIES = libvarnishcompat.la -libcompat_a_SOURCES = \ +libvarnishcompat_la_SOURCES = \ asprintf.c \ vasprintf.c \ setproctitle.c \ @@ -14,4 +14,4 @@ strndup.c \ vis.c -libcompat_a_CFLAGS = -include config.h +libvarnishcompat_la_CFLAGS = -include config.h From des at projects.linpro.no Thu Aug 9 12:12:12 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 9 Aug 2007 14:12:12 +0200 (CEST) Subject: r1818 - in branches/1.1: . bin/varnishadm bin/varnishd bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishstat bin/varnishtop debian etc include include/compat lib lib/libvarnish lib/libvarnishcompat lib/libvcl man Message-ID: <20070809121212.9E30F1ED925@projects.linpro.no> Author: des Date: 2007-08-09 14:12:12 +0200 (Thu, 09 Aug 2007) New Revision: 1818 Added: branches/1.1/debian/libvarnish-dev.dirs branches/1.1/debian/libvarnish-dev.install branches/1.1/debian/libvarnish.dirs branches/1.1/debian/libvarnish.install branches/1.1/debian/varnish.dirs branches/1.1/debian/varnish.install branches/1.1/lib/libvarnishcompat/ Removed: branches/1.1/lib/libcompat/ Modified: branches/1.1/ branches/1.1/autogen.sh branches/1.1/bin/varnishadm/Makefile.am branches/1.1/bin/varnishd/Makefile.am branches/1.1/bin/varnishd/cache.h branches/1.1/bin/varnishd/cache_ban.c branches/1.1/bin/varnishd/cache_center.c branches/1.1/bin/varnishd/cache_hash.c branches/1.1/bin/varnishd/cache_http.c branches/1.1/bin/varnishd/cache_synthetic.c branches/1.1/bin/varnishd/cache_vrt.c branches/1.1/bin/varnishd/cache_ws.c branches/1.1/bin/varnishd/hash_classic.c branches/1.1/bin/varnishd/hash_simple_list.c branches/1.1/bin/varnishd/hash_slinger.h branches/1.1/bin/varnishd/mgt_child.c branches/1.1/bin/varnishd/mgt_param.c branches/1.1/bin/varnishd/mgt_vcc.c branches/1.1/bin/varnishd/varnishd.c branches/1.1/bin/varnishhist/Makefile.am branches/1.1/bin/varnishlog/Makefile.am branches/1.1/bin/varnishncsa/Makefile.am branches/1.1/bin/varnishreplay/Makefile.am branches/1.1/bin/varnishstat/Makefile.am branches/1.1/bin/varnishtop/Makefile.am branches/1.1/configure.ac branches/1.1/debian/changelog branches/1.1/debian/control branches/1.1/debian/dirs branches/1.1/debian/rules branches/1.1/debian/varnish.default branches/1.1/debian/varnish.varnishlog.init branches/1.1/etc/default.vcl branches/1.1/include/compat/vis.h branches/1.1/include/libvarnish.h branches/1.1/include/vcl.h branches/1.1/include/vrt.h branches/1.1/include/vsb.h branches/1.1/lib/Makefile.am branches/1.1/lib/libvarnish/crc32.c branches/1.1/lib/libvarnish/flopen.c branches/1.1/lib/libvarnish/time.c branches/1.1/lib/libvarnish/vpf.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_fixed_token.tcl branches/1.1/lib/libvcl/vcc_parse.c branches/1.1/man/vcl.7 Log: Merged revisions 1743-1744,1746-1749,1755-1775,1777,1779-1793,1795,1797-1798,1800-1808,1810-1815,1817 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1743 | ssm | 2007-07-20 14:43:54 +0200 (Fri, 20 Jul 2007) | 1 line Split debian package into varnish, libvarnish and libvarnish-dev ........ r1748 | des | 2007-07-24 15:51:58 +0200 (Tue, 24 Jul 2007) | 2 lines Correct a comment ........ r1749 | des | 2007-07-24 15:52:40 +0200 (Tue, 24 Jul 2007) | 2 lines Use strlen() directly. ........ r1761 | cecilihf | 2007-07-25 10:39:10 +0200 (Wed, 25 Jul 2007) | 9 lines Implemented http purge with regexp. Example vcl usage: sub vcl_recv { if (req.request == "REPURGE") { purge(req.url); error 404 "Purged"; } } ........ r1762 | cecilihf | 2007-07-25 10:53:16 +0200 (Wed, 25 Jul 2007) | 2 lines Updated man page ........ r1765 | cecilihf | 2007-07-25 13:09:06 +0200 (Wed, 25 Jul 2007) | 2 lines Use purge in function names instead of repurge and move VRT_purge to cache_vrt.c. ........ r1766 | cecilihf | 2007-07-25 13:10:59 +0200 (Wed, 25 Jul 2007) | 2 lines Style... ........ r1780 | des | 2007-07-28 12:03:29 +0200 (Sat, 28 Jul 2007) | 5 lines 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. ........ r1783 | des | 2007-07-30 10:03:42 +0200 (Mon, 30 Jul 2007) | 4 lines Avoid referencing and __{BEGIN,END}_DECLS. Based on Theo Schlossnagle's Solaris portability patch. ........ r1784 | des | 2007-07-30 11:49:05 +0200 (Mon, 30 Jul 2007) | 2 lines Avoid using non-portable . ........ r1785 | des | 2007-07-30 15:50:16 +0200 (Mon, 30 Jul 2007) | 3 lines Use mktime() rather than the unportable timegm(). The downside is that we're at the mercy of the TZ environment variable. ........ r1786 | des | 2007-07-30 15:54:48 +0200 (Mon, 30 Jul 2007) | 2 lines Explicitly set TZ to GMT. ........ r1787 | des | 2007-07-30 16:16:23 +0200 (Mon, 30 Jul 2007) | 4 lines Use fcntl(2)-style locks instead of non-portable flock(2)-style locks. Based on Theo Schlossnagle's Solaris portability patch. ........ r1788 | des | 2007-07-30 16:19:45 +0200 (Mon, 30 Jul 2007) | 2 lines pid_t is not necessarily compatible with int. ........ r1789 | des | 2007-07-30 16:22:00 +0200 (Mon, 30 Jul 2007) | 2 lines Bogons in previous commit. Pass me the pointy hat... ........ r1790 | des | 2007-07-30 16:31:16 +0200 (Mon, 30 Jul 2007) | 3 lines I accidentally committed the wrong patch in r1787; this corrects the logic used to determine which lock type (shared or exclusive) to use. ........ r1791 | des | 2007-07-30 16:39:03 +0200 (Mon, 30 Jul 2007) | 2 lines Note that MAX_IOVS is intentionally not equal to IOV_MAX. ........ r1792 | des | 2007-07-31 08:06:28 +0200 (Tue, 31 Jul 2007) | 2 lines Fine-tune the vhost example. ........ r1793 | des | 2007-08-03 20:46:43 +0200 (Fri, 03 Aug 2007) | 2 lines Synchronize these two files. ........ r1795 | phk | 2007-08-05 21:37:44 +0200 (Sun, 05 Aug 2007) | 9 lines Synchronize the paramters after we call their accessor functions rather than when we don't find one. This makes changing runtime paramters work again, without the need to ask for a nonexistent parameter to trigger the update. Ticket: 136 ........ r1797 | phk | 2007-08-05 22:17:49 +0200 (Sun, 05 Aug 2007) | 4 lines Make the nonexistence of "nobody" and "nogroup" users and groups nonfatal Ticket: 140 ........ r1798 | phk | 2007-08-05 22:26:09 +0200 (Sun, 05 Aug 2007) | 5 lines We need the math library on some systems. Ticket 138 ........ r1800 | phk | 2007-08-05 22:57:20 +0200 (Sun, 05 Aug 2007) | 2 lines Add a missing return: we always return after detecting the first error. ........ r1801 | phk | 2007-08-05 22:57:32 +0200 (Sun, 05 Aug 2007) | 2 lines vrt.h is not needed here. ........ r1802 | phk | 2007-08-05 23:06:41 +0200 (Sun, 05 Aug 2007) | 2 lines Add comment to remind myself. ........ r1803 | phk | 2007-08-06 10:07:18 +0200 (Mon, 06 Aug 2007) | 14 lines Have the VCL compiler provide a hint about the worst case number of operations on the req.hash variable. It is only a hint, because it merely counts how many times the parser saw something being added to the req.hash variable. If the operation was in a subroutine which was called multiple times, the hint will not reflect the number of actual operations. For now we will deal with that at runtime, at the expense of a failed transaction every time we run short. If this becomes an issue, an extensive topological analysis of the VCL program can give us a definitive count. ........ r1804 | phk | 2007-08-06 11:19:20 +0200 (Mon, 06 Aug 2007) | 3 lines Add piecemal crc32 function back, we will need it for the scatter/gather hash string. ........ r1805 | phk | 2007-08-06 11:25:20 +0200 (Mon, 06 Aug 2007) | 13 lines Rewrite the req.hash implmentation: Instead of assembling the entire hash-string in the workspace, use a scatter gather approach, hinted by the VCL compiler. This eliminates the workspace reservation which prevented regsub() from working in vcl_hash, and reduces the size of the necessary workspace a fair bit as well, at the cost of a little bit of complexity in the hash implmentations. Closes ticket 137 and possibly 141 ........ r1806 | phk | 2007-08-06 11:28:44 +0200 (Mon, 06 Aug 2007) | 4 lines Forgot an assert. WS_Return() is now unused, comment it out. ........ r1807 | phk | 2007-08-07 08:55:52 +0200 (Tue, 07 Aug 2007) | 4 lines When vcl_miss() take error action, remember to discard backend request. Ticket: 139 ........ r1808 | phk | 2007-08-07 09:23:10 +0200 (Tue, 07 Aug 2007) | 3 lines Implement "error" action in vcl_fetch() and vcl_deliver() ........ r1810 | phk | 2007-08-08 10:49:11 +0200 (Wed, 08 Aug 2007) | 5 lines Elminiate a spurious message when sigchild looses a race to popen(2). This fixed #143 ........ r1811 | des | 2007-08-08 12:01:50 +0200 (Wed, 08 Aug 2007) | 3 lines Remove FreeBSD workaround; the FreeBSD ports tree has had working autotools for two weeks now. Also fix inconsistent indentation. ........ r1817 | des | 2007-08-09 13:19:20 +0200 (Thu, 09 Aug 2007) | 2 lines Rename libcompat to libvarnishcompat, and make it dynamic. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1745-1747,1750-1760,1763-1764,1767-1776 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1793,1795,1797-1798,1800-1808,1810-1815,1817 Modified: branches/1.1/autogen.sh =================================================================== --- branches/1.1/autogen.sh 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/autogen.sh 2007-08-09 12:12:12 UTC (rev 1818) @@ -9,19 +9,17 @@ case `uname -s` in Darwin) - LIBTOOLIZE=glibtoolize - ;; + 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 - ;; + LIBTOOLIZE=libtoolize + ;; Linux) - LIBTOOLIZE=libtoolize - ;; + LIBTOOLIZE=libtoolize + ;; +*) + warn "unrecognized platform:" `uname -s` + LIBTOOLIZE=libtoolize esac automake_version=$(automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+') @@ -39,7 +37,7 @@ set -ex -aclocal ${FIX_BROKEN_FREEBSD_PORTS} +aclocal $LIBTOOLIZE --copy --force autoheader automake --add-missing --copy --foreign Modified: branches/1.1/bin/varnishadm/Makefile.am =================================================================== --- branches/1.1/bin/varnishadm/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishadm/Makefile.am 2007-08-09 12:12:12 UTC (rev 1818) @@ -13,4 +13,4 @@ varnishadm_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la Modified: branches/1.1/bin/varnishd/Makefile.am =================================================================== --- branches/1.1/bin/varnishd/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/Makefile.am 2007-08-09 12:12:12 UTC (rev 1818) @@ -66,6 +66,6 @@ varnishd_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvcl/libvcl.la \ - ${DL_LIBS} ${PTHREAD_LIBS} + ${DL_LIBS} ${PTHREAD_LIBS} ${LIBM} Modified: branches/1.1/bin/varnishd/cache.h =================================================================== --- branches/1.1/bin/varnishd/cache.h 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/cache.h 2007-08-09 12:12:12 UTC (rev 1818) @@ -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 */ @@ -94,7 +95,6 @@ void WS_Assert(struct ws *ws); void WS_Reset(struct ws *ws); char *WS_Alloc(struct ws *ws, unsigned bytes); -void WS_Return(struct ws *ws, char *b, char *e); @@ -325,8 +325,11 @@ struct workreq workreq; struct acct acct; - char *hash_b; /* Start of hash string */ - char *hash_e; /* End of hash string */ + /* pointers to hash string components */ + unsigned nhashptr; + unsigned ihashptr; + unsigned lhashptr; + const char **hashptr; }; struct backend { @@ -371,6 +374,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); @@ -394,6 +398,8 @@ /* cache_hash.c */ void HSH_Prealloc(struct sess *sp); +int HSH_Compare(struct sess *sp, const char *b, const char *e); +void HSH_Copy(struct sess *sp, char *b, const char *e); struct object *HSH_Lookup(struct sess *sp); void HSH_Unbusy(struct object *o); void HSH_Ref(struct object *o); Modified: branches/1.1/bin/varnishd/cache_ban.c =================================================================== --- branches/1.1/bin/varnishd/cache_ban.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/cache_ban.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -52,7 +52,7 @@ static unsigned ban_next; static struct ban *ban_start; -static void +void AddBan(const char *regexp) { struct ban *b; Modified: branches/1.1/bin/varnishd/cache_center.c =================================================================== --- branches/1.1/bin/varnishd/cache_center.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/cache_center.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -149,8 +149,17 @@ sp->t_resp = TIM_real(); RES_BuildHttp(sp); VCL_deliver_method(sp); - if (sp->handling != VCL_RET_DELIVER) + switch (sp->handling) { + case VCL_RET_DELIVER: + break; + case VCL_RET_ERROR: + HSH_Deref(sp->obj); + sp->obj = NULL; + sp->step = STP_ERROR; + return (0); + default: INCOMPL(); + } RES_WriteObj(sp); HSH_Deref(sp->obj); @@ -298,11 +307,23 @@ VCL_fetch_method(sp); - if (sp->handling == VCL_RET_ERROR) + switch (sp->handling) { + case VCL_RET_ERROR: + sp->obj->ttl = 0; + sp->obj->cacheable = 0; + HSH_Unbusy(sp->obj); + HSH_Deref(sp->obj); + sp->obj = NULL; + sp->step = STP_ERROR; + return (0); + case VCL_RET_PASS: + sp->obj->pass = 1; + break; + case VCL_RET_INSERT: + break; + default: INCOMPL(); - - if (sp->handling == VCL_RET_PASS) - sp->obj->pass = 1; + } } sp->obj->cacheable = 1; @@ -433,15 +454,27 @@ cnt_lookup(struct sess *sp) { struct object *o; + char *p; + uintptr_t u; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); if (sp->obj == NULL) { - WS_Reserve(sp->http->ws, 0); - sp->hash_b = sp->http->ws->f; - sp->hash_e = sp->hash_b; + + /* Allocate the pointers we need, align properly. */ + sp->lhashptr = 1; /* space for NUL */ + sp->ihashptr = 0; + sp->nhashptr = sp->vcl->nhashcount * 2; + p = WS_Alloc(sp->http->ws, + sizeof(const char *) * (sp->nhashptr + 1)); + XXXAN(p); + u = (uintptr_t)p; + u &= sizeof(const char *) - 1; + if (u) + p += sizeof(const char *) - u; + sp->hashptr = (void*)p; + VCL_hash_method(sp); /* XXX: no-op for now */ - WS_ReleaseP(sp->http->ws, sp->hash_e); /* XXX check error */ } @@ -458,9 +491,6 @@ return (1); } - WS_Return(sp->http->ws, sp->hash_b, sp->hash_e); - sp->hash_b = sp->hash_e = NULL; - sp->obj = o; /* If we inserted a new object it's a miss */ @@ -522,6 +552,8 @@ HSH_Unbusy(sp->obj); HSH_Deref(sp->obj); sp->obj = NULL; + vbe_free_bereq(sp->bereq); + sp->bereq = NULL; sp->step = STP_ERROR; return (0); } @@ -690,8 +722,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 */ Modified: branches/1.1/bin/varnishd/cache_hash.c =================================================================== --- branches/1.1/bin/varnishd/cache_hash.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/cache_hash.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -108,6 +108,47 @@ } } +int +HSH_Compare(struct sess *sp, const char *b, const char *e) +{ + int i; + unsigned u, v; + + i = sp->lhashptr - (e - b); + if (i) + return (i); + for (u = 0; u < sp->ihashptr; u += 2) { + v = sp->hashptr[u + 1] - sp->hashptr[u]; + i = memcmp(sp->hashptr[u], b, v); + if (i) + return (i); + b += v; + i = '#' - *b++; + if (i) + return (i); + } + assert(*b == '\0'); + b++; + assert(b == e); + return (0); +} + +void +HSH_Copy(struct sess *sp, char *b, const char *e) +{ + unsigned u, v; + + assert((e - b) >= sp->lhashptr); + for (u = 0; u < sp->ihashptr; u += 2) { + v = sp->hashptr[u + 1] - sp->hashptr[u]; + memcpy(b, sp->hashptr[u], v); + b += v; + *b++ = '#'; + } + *b++ = '\0'; + assert(b <= e); +} + struct object * HSH_Lookup(struct sess *sp) { @@ -132,9 +173,8 @@ LOCK(&oh->mtx); goto were_back; } -VSLR(SLT_Debug, sp->fd, sp->hash_b, sp->hash_e); - oh = hash->lookup(sp->hash_b, sp->hash_e, w->nobjhead); + oh = hash->lookup(sp, w->nobjhead); CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); if (oh == w->nobjhead) w->nobjhead = NULL; Modified: branches/1.1/bin/varnishd/cache_http.c =================================================================== --- branches/1.1/bin/varnishd/cache_http.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/cache_http.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -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); Modified: branches/1.1/bin/varnishd/cache_synthetic.c =================================================================== --- branches/1.1/bin/varnishd/cache_synthetic.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/cache_synthetic.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -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 */ } Modified: branches/1.1/bin/varnishd/cache_vrt.c =================================================================== --- branches/1.1/bin/varnishd/cache_vrt.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/cache_vrt.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -452,7 +452,9 @@ return (sp->mysockaddr); } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * Add an element to the array/list of hash bits. + */ void VRT_l_req_hash(struct sess *sp, const char *str) @@ -462,10 +464,18 @@ if (str == NULL) str = ""; l = strlen(str); - xxxassert (sp->hash_e + l + 1 <= sp->http->ws->e); - memcpy(sp->hash_e, str, l); - sp->hash_e[l] = '#'; - sp->hash_e += l + 1; + + /* + * XXX: handle this by bouncing sp->vcl->nhashcount when it fails + * XXX: and dispose of this request either by reallocating the + * XXX: hashptr (if possible) or restarting/error the request + */ + xxxassert(sp->ihashptr < sp->nhashptr); + + sp->hashptr[sp->ihashptr] = str; + sp->hashptr[sp->ihashptr + 1] = str + l; + sp->ihashptr += 2; + sp->lhashptr += l + 1; } /*--------------------------------------------------------------------*/ @@ -513,3 +523,12 @@ strcat(q, p); return (q); } + +/*--------------------------------------------------------------------*/ + +void +VRT_purge(const char *regexp) +{ + + AddBan(regexp); +} Modified: branches/1.1/bin/varnishd/cache_ws.c =================================================================== --- branches/1.1/bin/varnishd/cache_ws.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/cache_ws.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -129,6 +129,8 @@ ws->r = NULL; } +#if 0 +/* XXX: not used anywhere (yet) */ void WS_Return(struct ws *ws, char *s, char *e) { @@ -137,3 +139,4 @@ if (e == ws->f) ws->f = s; } +#endif Modified: branches/1.1/bin/varnishd/hash_classic.c =================================================================== --- branches/1.1/bin/varnishd/hash_classic.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/hash_classic.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -121,36 +121,44 @@ */ static struct objhead * -hcl_lookup(const char *b, const char *e, struct objhead *noh) +hcl_lookup(struct sess *sp, struct objhead *noh) { struct hcl_entry *he, *he2; struct hcl_hd *hp; - unsigned u1, digest, kl, r; + unsigned u1, digest, r; + unsigned u, v; int i; CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC); - digest = crc32_l(b, e - b); + digest = ~0U; + for (u = 0; u < sp->ihashptr; u += 2) { + v = sp->hashptr[u + 1] - sp->hashptr[u]; + digest = crc32(digest, sp->hashptr[u], v); + } + digest ^= ~0U; u1 = digest % hcl_nhash; hp = &hcl_head[u1]; - kl = e - b; he2 = NULL; for (r = 0; r < 2; r++ ) { LOCK(&hp->mtx); TAILQ_FOREACH(he, &hp->head, list) { CHECK_OBJ_NOTNULL(he, HCL_ENTRY_MAGIC); - if (kl < he->klen) + if (sp->lhashptr < he->klen) continue; - if (kl > he->klen) + if (sp->lhashptr > he->klen) break; if (he->digest < digest) continue; if (he->digest > digest) break; - if (memcmp(he->key, b, kl)) + i = HSH_Compare(sp, he->key, he->key + he->klen); + if (i < 0) continue; + if (i > 0) + break; he->refcnt++; noh = he->oh; UNLOCK(&hp->mtx); @@ -174,7 +182,7 @@ } UNLOCK(&hp->mtx); - i = sizeof *he2 + kl; + i = sizeof *he2 + sp->lhashptr; he2 = calloc(i, 1); XXXAN(he2); he2->magic = HCL_ENTRY_MAGIC; @@ -182,11 +190,11 @@ he2->digest = digest; he2->hash = u1; he2->head = hp; - he2->klen = kl; + he2->klen = sp->lhashptr; noh->hashpriv = he2; he2->key = (void*)(he2 + 1); - memcpy(he2->key, b, kl); + HSH_Copy(sp, he2->key, he2->key + sp->lhashptr); } assert(he2 == NULL); /* FlexeLint */ INCOMPL(); Modified: branches/1.1/bin/varnishd/hash_simple_list.c =================================================================== --- branches/1.1/bin/varnishd/hash_simple_list.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/hash_simple_list.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -73,26 +73,20 @@ */ static struct objhead * -hsl_lookup(const char *b, const char *e, struct objhead *nobj) +hsl_lookup(struct sess *sp, struct objhead *nobj) { struct hsl_entry *he, *he2; - int i, l; + int i; - l = e - b; LOCK(&hsl_mutex); TAILQ_FOREACH(he, &hsl_head, list) { - if (l > he->keylen) - continue; - if (l < he->keylen) - break;; - i = memcmp(b, he->key, l); + i = HSH_Compare(sp, he->key, he->key + he->keylen); if (i < 0) continue; if (i > 0) break; he->refcnt++; nobj = he->obj; - nobj->hashpriv = he; UNLOCK(&hsl_mutex); return (nobj); } @@ -100,13 +94,13 @@ UNLOCK(&hsl_mutex); return (NULL); } - he2 = calloc(sizeof *he2 + l, 1); + he2 = calloc(sizeof *he2 + sp->lhashptr, 1); XXXAN(he2); he2->obj = nobj; he2->refcnt = 1; he2->key = (void*)(he2 + 1); - he2->keylen = l; - memcpy(he2->key, b, l); + he2->keylen = sp->lhashptr; + HSH_Copy(sp, he2->key, he2->key + he2->keylen); nobj->hashpriv = he2; if (he != NULL) TAILQ_INSERT_BEFORE(he, he2, list); Modified: branches/1.1/bin/varnishd/hash_slinger.h =================================================================== --- branches/1.1/bin/varnishd/hash_slinger.h 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/hash_slinger.h 2007-08-09 12:12:12 UTC (rev 1818) @@ -29,9 +29,11 @@ * $Id$ */ +struct sess; + typedef int hash_init_f(const char *); typedef void hash_start_f(void); -typedef struct objhead *hash_lookup_f(const char *key1, const char *key2, struct objhead *nobj); +typedef struct objhead *hash_lookup_f(struct sess *sp, struct objhead *nobj); typedef int hash_deref_f(struct objhead *obj); struct hash_slinger { Modified: branches/1.1/bin/varnishd/mgt_child.c =================================================================== --- branches/1.1/bin/varnishd/mgt_child.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/mgt_child.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -42,8 +42,6 @@ #include #include -#include /* XXX */ - #ifndef HAVE_SETPROCTITLE #include "compat/setproctitle.h" #endif @@ -168,7 +166,7 @@ static void start_child(void) { - int i; + pid_t pid; unsigned u; char *p; struct ev *e; @@ -187,10 +185,11 @@ AZ(pipe(&heritage.fds[2])); AZ(pipe(child_fds)); MCF_ParamSync(); - i = fork(); - if (i < 0) - errx(1, "Could not fork child"); - if (i == 0) { + if ((pid = fork()) < 0) { + perror("Could not fork child"); + exit(1); + } + if (pid == 0) { if (geteuid() == 0) { XXXAZ(setgid(params->gid)); XXXAZ(setuid(params->uid)); @@ -198,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])); @@ -214,10 +212,10 @@ signal(SIGTERM, SIG_DFL); child_main(); - exit (1); + 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; @@ -248,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); @@ -307,6 +305,8 @@ ev_poker = NULL; r = wait4(-1, &status, WNOHANG, NULL); + if (r == 0) + return (0); if (r != child_pid || r == -1) { fprintf(stderr, "Unknown child died pid=%d status=0x%x\n", r, status); Modified: branches/1.1/bin/varnishd/mgt_param.c =================================================================== --- branches/1.1/bin/varnishd/mgt_param.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/mgt_param.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -51,6 +51,8 @@ #include "vss.h" +#define MAGIC_INIT_STRING "\001" + struct parspec; typedef void tweak_t(struct cli *, struct parspec *, const char *arg); @@ -141,7 +143,13 @@ } } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * XXX: slightly magic. We want to initialize to "nobody" (XXX: shouldn't + * XXX: that be something autocrap found for us ?) but we don't want to + * XXX: fail initialization if that user doesn't exists, even though we + * XXX: do want to fail it, in subsequent sets. + * XXX: The magic init string is a hack for this. + */ static void tweak_user(struct cli *cli, struct parspec *par, const char *arg) @@ -151,7 +159,15 @@ (void)par; if (arg != NULL) { - if ((pw = getpwnam(arg)) == NULL) { + if (!strcmp(arg, MAGIC_INIT_STRING)) { + pw = getpwnam("nobody"); + if (pw == NULL) { + master.uid = getuid(); + return; + } + } else + pw = getpwnam(arg); + if (pw == NULL) { cli_out(cli, "Unknown user"); cli_result(cli, CLIS_PARAM); return; @@ -161,6 +177,7 @@ master.user = strdup(pw->pw_name); AN(master.user); master.uid = pw->pw_uid; + master.gid = pw->pw_gid; /* set group to user's primary group */ if (master.group) @@ -171,7 +188,6 @@ master.group = strdup(gr->gr_name); AN(master.group); } - master.gid = pw->pw_gid; } else if (master.user) { cli_out(cli, "%s (%d)", master.user, (int)master.uid); } else { @@ -179,7 +195,9 @@ } } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * XXX: see comment for tweak_user, same thing here. + */ static void tweak_group(struct cli *cli, struct parspec *par, const char *arg) @@ -188,7 +206,17 @@ (void)par; if (arg != NULL) { - if ((gr = getgrnam(arg)) == NULL) { + if (!strcmp(arg, MAGIC_INIT_STRING)) { + gr = getgrnam("nogroup"); + if (gr == NULL) { + /* Only replace if tweak_user didn't */ + if (master.gid == 0) + master.gid = getgid(); + return; + } + } else + gr = getgrnam(arg); + if (gr == NULL) { cli_out(cli, "Unknown group"); cli_result(cli, CLIS_PARAM); return; @@ -524,11 +552,11 @@ "The unprivileged user to run as. Setting this will " "also set \"group\" to the specified user's primary group.\n" MUST_RESTART, - "nobody" }, + MAGIC_INIT_STRING }, { "group", tweak_group, "The unprivileged group to run as.\n" MUST_RESTART, - "nogroup" }, + MAGIC_INIT_STRING }, { "default_ttl", tweak_default_ttl, "The TTL assigned to objects if neither the backend nor " "the VCL code assigns one.\n" @@ -754,12 +782,12 @@ for (pp = parspec; pp->name != NULL; pp++) { if (!strcmp(pp->name, param)) { pp->func(cli, pp, val); + MCF_ParamSync(); return; } } cli_result(cli, CLIS_PARAM); cli_out(cli, "Unknown paramter \"%s\".", param); - MCF_ParamSync(); } Modified: branches/1.1/bin/varnishd/mgt_vcc.c =================================================================== --- branches/1.1/bin/varnishd/mgt_vcc.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/mgt_vcc.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -98,7 +98,7 @@ " if (req.http.host) {\n" " set req.hash += req.http.host;\n" " } else {\n" - " set req.hash += server.ip;\n" + " set req.hash += server.ip;\n" /* XXX: see ticket 137 */ " }\n" #endif " hash;\n" Modified: branches/1.1/bin/varnishd/varnishd.c =================================================================== --- branches/1.1/bin/varnishd/varnishd.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishd/varnishd.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -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" @@ -425,6 +425,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); Modified: branches/1.1/bin/varnishhist/Makefile.am =================================================================== --- branches/1.1/bin/varnishhist/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishhist/Makefile.am 2007-08-09 12:12:12 UTC (rev 1818) @@ -12,7 +12,7 @@ varnishhist_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ -lm \ ${CURSES_LIBS} ${PTHREAD_LIBS} Modified: branches/1.1/bin/varnishlog/Makefile.am =================================================================== --- branches/1.1/bin/varnishlog/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishlog/Makefile.am 2007-08-09 12:12:12 UTC (rev 1818) @@ -12,5 +12,5 @@ varnishlog_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la Modified: branches/1.1/bin/varnishncsa/Makefile.am =================================================================== --- branches/1.1/bin/varnishncsa/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishncsa/Makefile.am 2007-08-09 12:12:12 UTC (rev 1818) @@ -12,5 +12,5 @@ varnishncsa_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la Modified: branches/1.1/bin/varnishreplay/Makefile.am =================================================================== --- branches/1.1/bin/varnishreplay/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishreplay/Makefile.am 2007-08-09 12:12:12 UTC (rev 1818) @@ -13,7 +13,7 @@ varnishreplay_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${PTHREAD_LIBS} Modified: branches/1.1/bin/varnishstat/Makefile.am =================================================================== --- branches/1.1/bin/varnishstat/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishstat/Makefile.am 2007-08-09 12:12:12 UTC (rev 1818) @@ -12,6 +12,6 @@ varnishstat_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${CURSES_LIBS} ${RT_LIBS} Modified: branches/1.1/bin/varnishtop/Makefile.am =================================================================== --- branches/1.1/bin/varnishtop/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/bin/varnishtop/Makefile.am 2007-08-09 12:12:12 UTC (rev 1818) @@ -12,6 +12,6 @@ varnishtop_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ - $(top_builddir)/lib/libcompat/libcompat.a \ + $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${CURSES_LIBS} ${PTHREAD_LIBS} Modified: branches/1.1/configure.ac =================================================================== --- branches/1.1/configure.ac 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/configure.ac 2007-08-09 12:12:12 UTC (rev 1818) @@ -50,6 +50,9 @@ LIBS="${save_LIBS}" AC_SUBST(PTHREAD_LIBS) +AC_CHECK_LIBM +AC_SUBST(LIBM) + # Checks for header files. AC_HEADER_STDC AC_HEADER_SYS_WAIT @@ -148,9 +151,9 @@ etc/Makefile include/Makefile lib/Makefile - lib/libcompat/Makefile lib/libvarnish/Makefile lib/libvarnishapi/Makefile + lib/libvarnishcompat/Makefile lib/libvcl/Makefile man/Makefile debian/Makefile Modified: branches/1.1/debian/changelog =================================================================== --- branches/1.1/debian/changelog 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/debian/changelog 2007-08-09 12:12:12 UTC (rev 1818) @@ -1,8 +1,9 @@ -varnish (1.1-1) unstable; urgency=low +varnish (1.1) unstable; urgency=low - * New upstream version + * New upstream release + * Split package into varnish, libvarnish and libvarnish-dev - -- des Thu, 5 Jul 2007 13:13:54 +0200 + -- Stig Sandbeck Mathisen Fri, 20 Jul 2007 14:37:36 +0200 varnish (1.0.4-1) unstable; urgency=low Modified: branches/1.1/debian/control =================================================================== --- branches/1.1/debian/control 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/debian/control 2007-08-09 12:12:12 UTC (rev 1818) @@ -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: branches/1.1/debian/dirs =================================================================== --- branches/1.1/debian/dirs 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/debian/dirs 2007-08-09 12:12:12 UTC (rev 1818) @@ -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/ Copied: branches/1.1/debian/libvarnish-dev.dirs (from rev 1743, trunk/varnish-cache/debian/libvarnish-dev.dirs) =================================================================== --- branches/1.1/debian/libvarnish-dev.dirs (rev 0) +++ branches/1.1/debian/libvarnish-dev.dirs 2007-08-09 12:12:12 UTC (rev 1818) @@ -0,0 +1 @@ +usr/lib Copied: branches/1.1/debian/libvarnish-dev.install (from rev 1743, trunk/varnish-cache/debian/libvarnish-dev.install) =================================================================== --- branches/1.1/debian/libvarnish-dev.install (rev 0) +++ branches/1.1/debian/libvarnish-dev.install 2007-08-09 12:12:12 UTC (rev 1818) @@ -0,0 +1,3 @@ +usr/include +usr/lib/*.a +usr/lib/*.la Copied: branches/1.1/debian/libvarnish.dirs (from rev 1743, trunk/varnish-cache/debian/libvarnish.dirs) =================================================================== --- branches/1.1/debian/libvarnish.dirs (rev 0) +++ branches/1.1/debian/libvarnish.dirs 2007-08-09 12:12:12 UTC (rev 1818) @@ -0,0 +1 @@ +usr/lib Copied: branches/1.1/debian/libvarnish.install (from rev 1743, trunk/varnish-cache/debian/libvarnish.install) =================================================================== --- branches/1.1/debian/libvarnish.install (rev 0) +++ branches/1.1/debian/libvarnish.install 2007-08-09 12:12:12 UTC (rev 1818) @@ -0,0 +1 @@ +usr/lib/lib*.so.* Modified: branches/1.1/debian/rules =================================================================== --- branches/1.1/debian/rules 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/debian/rules 2007-08-09 12:12:12 UTC (rev 1818) @@ -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: branches/1.1/debian/rules ___________________________________________________________________ Name: svn + executable Modified: branches/1.1/debian/varnish.default =================================================================== --- branches/1.1/debian/varnish.default 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/debian/varnish.default 2007-08-09 12:12:12 UTC (rev 1818) @@ -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}" # Copied: branches/1.1/debian/varnish.dirs (from rev 1743, trunk/varnish-cache/debian/varnish.dirs) =================================================================== --- branches/1.1/debian/varnish.dirs (rev 0) +++ branches/1.1/debian/varnish.dirs 2007-08-09 12:12:12 UTC (rev 1818) @@ -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/ Copied: branches/1.1/debian/varnish.install (from rev 1743, trunk/varnish-cache/debian/varnish.install) =================================================================== --- branches/1.1/debian/varnish.install (rev 0) +++ branches/1.1/debian/varnish.install 2007-08-09 12:12:12 UTC (rev 1818) @@ -0,0 +1,2 @@ +usr/bin +usr/sbin Modified: branches/1.1/debian/varnish.varnishlog.init =================================================================== --- branches/1.1/debian/varnish.varnishlog.init 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/debian/varnish.varnishlog.init 2007-08-09 12:12:12 UTC (rev 1818) @@ -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) Modified: branches/1.1/etc/default.vcl =================================================================== --- branches/1.1/etc/default.vcl 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/etc/default.vcl 2007-08-09 12:12:12 UTC (rev 1818) @@ -75,14 +75,27 @@ # if (!obj.cacheable) { # pass; # } -# if (resp.http.Set-Cookie) { +# if (obj.http.Set-Cookie) { # pass; # } # insert; #} # +# +## Called before a cached object is delivered to the client +# +#sub vcl_deliver { +# deliver; +#} +# ## Called when an object nears its expiry time # #sub vcl_timeout { # discard; #} +# +## Called when an object is about to be discarded +# +#sub vcl_discard { +# discard; +#} Modified: branches/1.1/include/compat/vis.h =================================================================== --- branches/1.1/include/compat/vis.h 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/include/compat/vis.h 2007-08-09 12:12:12 UTC (rev 1818) @@ -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: branches/1.1/include/libvarnish.h =================================================================== --- branches/1.1/include/libvarnish.h 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/include/libvarnish.h 2007-08-09 12:12:12 UTC (rev 1818) @@ -42,6 +42,7 @@ char **ParseArgv(const char *s, int comment); /* from libvarnish/crc32.c */ +uint32_t crc32(uint32_t crc, const void *p1, unsigned l); uint32_t crc32_l(const void *p1, unsigned l); /* from libvarnish/time.c */ Modified: branches/1.1/include/vcl.h =================================================================== --- branches/1.1/include/vcl.h 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/include/vcl.h 2007-08-09 12:12:12 UTC (rev 1818) @@ -26,6 +26,8 @@ const char **srcname; const char **srcbody; + unsigned nhashcount; + void *priv; vcl_init_f *init_func; Modified: branches/1.1/include/vrt.h =================================================================== --- branches/1.1/include/vrt.h 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/include/vrt.h 2007-08-09 12:12:12 UTC (rev 1818) @@ -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_purge(const char *); + void VRT_count(struct sess *, unsigned); int VRT_rewrite(const char *, const char *); void VRT_error(struct sess *, unsigned, const char *); Modified: branches/1.1/include/vsb.h =================================================================== --- branches/1.1/include/vsb.h 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/include/vsb.h 2007-08-09 12:12:12 UTC (rev 1818) @@ -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 Modified: branches/1.1/lib/Makefile.am =================================================================== --- branches/1.1/lib/Makefile.am 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/Makefile.am 2007-08-09 12:12:12 UTC (rev 1818) @@ -1,7 +1,7 @@ # $Id$ SUBDIRS = \ - libcompat \ libvarnish \ libvarnishapi \ + libvarnishcompat \ libvcl Modified: branches/1.1/lib/libvarnish/crc32.c =================================================================== --- branches/1.1/lib/libvarnish/crc32.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/libvarnish/crc32.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -82,14 +82,21 @@ }; uint32_t -crc32_l(const void *p1, unsigned l) +crc32(uint32_t crc, const void *p1, unsigned l) { const unsigned char *p; - uint32_t crc; - crc = ~0U; - for (p = (const unsigned char*)p1; l-- > 0; p++) crc = (crc >> 8) ^ crc32bits[(crc ^ *p) & 0xff]; + return (crc); +} + +uint32_t +crc32_l(const void *p1, unsigned l) +{ + uint32_t crc; + + crc = crc32(~0U, p1, l); return (crc ^ ~0U); } + Modified: branches/1.1/lib/libvarnish/flopen.c =================================================================== --- branches/1.1/lib/libvarnish/flopen.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/libvarnish/flopen.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -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_RDONLY) ? F_RDLCK : F_WRLCK; + 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: branches/1.1/lib/libvarnish/time.c =================================================================== --- branches/1.1/lib/libvarnish/time.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/libvarnish/time.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -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); } Modified: branches/1.1/lib/libvarnish/vpf.c =================================================================== --- branches/1.1/lib/libvarnish/vpf.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/libvarnish/vpf.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -32,13 +32,12 @@ #include #include +#include +#include #include #include +#include #include -#include -#include -#include -#include #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" @@ -223,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; @@ -233,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; } Copied: branches/1.1/lib/libvarnishcompat (from rev 1817, trunk/varnish-cache/lib/libvarnishcompat) Property changes on: branches/1.1/lib/libvarnishcompat ___________________________________________________________________ Name: svn:ignore + .deps .libs Makefile Makefile.in libcompat.a Modified: branches/1.1/lib/libvcl/vcc_action.c =================================================================== --- branches/1.1/lib/libvcl/vcc_action.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/libvcl/vcc_action.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -206,6 +206,12 @@ return; } Fb(tl, 0, ");\n"); + /* + * We count the number of operations on the req.hash + * variable, so that varnishd can preallocate the worst case + * number of slots for composing the hash string. + */ + tl->nhashcount++; break; case STRING: if (tl->t->tok != '=') { @@ -263,6 +269,30 @@ /*--------------------------------------------------------------------*/ +static void +parse_purge(struct tokenlist *tl) +{ + + vcc_NextToken(tl); + + Fb(tl, 0, "VRT_purge("); + + Expect(tl, '('); + vcc_NextToken(tl); + + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return; + } + + Expect(tl, ')'); + vcc_NextToken(tl); + Fb(tl, 0, ");"); +} + + +/*--------------------------------------------------------------------*/ + typedef void action_f(struct tokenlist *tl); static struct action_table { @@ -277,6 +307,7 @@ { "call", parse_call }, { "set", parse_set }, { "remove", parse_remove }, + { "purge", parse_purge }, { NULL, NULL } }; Modified: branches/1.1/lib/libvcl/vcc_compile.c =================================================================== --- branches/1.1/lib/libvcl/vcc_compile.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/libvcl/vcc_compile.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -348,6 +348,7 @@ Fc(tl, 0, "\t.nsrc = %u,\n", tl->nsources); Fc(tl, 0, "\t.srcname = srcname,\n"); Fc(tl, 0, "\t.srcbody = srcbody,\n"); + Fc(tl, 0, "\t.nhashcount = %u,\n", tl->nhashcount); #define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) \ Fc(tl, 0, "\t." #l "_func = VGC_function_vcl_" #l ",\n"); Modified: branches/1.1/lib/libvcl/vcc_compile.h =================================================================== --- branches/1.1/lib/libvcl/vcc_compile.h 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/libvcl/vcc_compile.h 2007-08-09 12:12:12 UTC (rev 1818) @@ -83,6 +83,7 @@ struct proc *mprocs[N_METHODS]; unsigned recnt; + unsigned nhashcount; }; enum var_type { Modified: branches/1.1/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/1.1/lib/libvcl/vcc_fixed_token.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/libvcl/vcc_fixed_token.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -338,6 +338,8 @@ vsb_cat(sb, " const char **srcname;\n"); vsb_cat(sb, " const char **srcbody;\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, " unsigned nhashcount;\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, " void *priv;\n"); vsb_cat(sb, "\n"); vsb_cat(sb, " vcl_init_f *init_func;\n"); @@ -426,6 +428,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_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"); vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n"); Modified: branches/1.1/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- branches/1.1/lib/libvcl/vcc_gen_fixed_token.tcl 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/libvcl/vcc_gen_fixed_token.tcl 2007-08-09 12:12:12 UTC (rev 1818) @@ -142,6 +142,8 @@ const char **srcname; const char **srcbody; + unsigned nhashcount; + void *priv; vcl_init_f *init_func; Modified: branches/1.1/lib/libvcl/vcc_parse.c =================================================================== --- branches/1.1/lib/libvcl/vcc_parse.c 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/lib/libvcl/vcc_parse.c 2007-08-09 12:12:12 UTC (rev 1818) @@ -38,8 +38,6 @@ #include "vcc_compile.h" #include "libvarnish.h" -#include "vrt.h" - /*--------------------------------------------------------------------*/ static void Compound(struct tokenlist *tl); Modified: branches/1.1/man/vcl.7 =================================================================== --- branches/1.1/man/vcl.7 2007-08-09 11:19:20 UTC (rev 1817) +++ branches/1.1/man/vcl.7 2007-08-09 12:12:12 UTC (rev 1818) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd July 13, 2007 +.Dd August 3, 2007 .Dt VCL 7 .Os .Sh NAME @@ -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: @@ -471,7 +474,7 @@ The following code is the equivalent of the default configuration with the backend address set to "backend.example.com" and no backend port specified. -.\" Keep this in synch with bin/varnishd/mgt_vcc.c +.\" Keep this in synch with bin/varnishd/mgt_vcc.c and etc/default.vcl .Bd -literal -offset 4n backend default { set backend.host = "backend.example.com"; @@ -531,11 +534,11 @@ deliver; } -sub vcl_discard { +sub vcl_timeout { discard; } -sub vcl_timeout { +sub vcl_discard { discard; } .Ed @@ -556,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"; From des at projects.linpro.no Thu Aug 9 14:58:57 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 9 Aug 2007 16:58:57 +0200 (CEST) Subject: r1819 - trunk/varnish-cache/man Message-ID: <20070809145857.059B81EC468@projects.linpro.no> Author: des Date: 2007-08-09 16:58:56 +0200 (Thu, 09 Aug 2007) New Revision: 1819 Modified: trunk/varnish-cache/man/vcl.7 Log: Explain the meaning of obj.valid and obj.cacheable. Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-08-09 12:12:12 UTC (rev 1818) +++ trunk/varnish-cache/man/vcl.7 2007-08-09 14:58:56 UTC (rev 1819) @@ -424,10 +424,17 @@ .It Va obj.response The HTTP status message returned by the server. .It Va obj.valid -True if the object was successfully retrieved. +True if the request resulted in a valid HTTP response. .It Va obj.cacheable -True if the object is cacheable. -.\" XXX what are the criteria? +True if the request resulted in a cacheable response. +.\" see cache_center.c and rfc2616.c for details +A response is considered cacheable if it is valid (see above), the +HTTP status code is 200, 203, 300, 301, 302, 404 or 410 and it has a +non-zero time-to-live when +.Cm Expires +and +.Cm Cache-Control +headers are taken into account. .It Va obj.ttl The object's remaining time to live, in seconds. .It Va obj.lastuse From des at projects.linpro.no Thu Aug 9 14:59:37 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 9 Aug 2007 16:59:37 +0200 (CEST) Subject: r1820 - in branches/1.1: . man Message-ID: <20070809145937.C1B3C1EC2A3@projects.linpro.no> Author: des Date: 2007-08-09 16:59:37 +0200 (Thu, 09 Aug 2007) New Revision: 1820 Modified: branches/1.1/ branches/1.1/man/vcl.7 Log: Merged revisions 1819 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1819 | des | 2007-08-09 16:58:56 +0200 (Thu, 09 Aug 2007) | 2 lines Explain the meaning of obj.valid and obj.cacheable. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1793,1795,1797-1798,1800-1808,1810-1815,1817 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1793,1795,1797-1798,1800-1808,1810-1815,1817,1819 Modified: branches/1.1/man/vcl.7 =================================================================== --- branches/1.1/man/vcl.7 2007-08-09 14:58:56 UTC (rev 1819) +++ branches/1.1/man/vcl.7 2007-08-09 14:59:37 UTC (rev 1820) @@ -424,10 +424,17 @@ .It Va obj.response The HTTP status message returned by the server. .It Va obj.valid -True if the object was successfully retrieved. +True if the request resulted in a valid HTTP response. .It Va obj.cacheable -True if the object is cacheable. -.\" XXX what are the criteria? +True if the request resulted in a cacheable response. +.\" see cache_center.c and rfc2616.c for details +A response is considered cacheable if it is valid (see above), the +HTTP status code is 200, 203, 300, 301, 302, 404 or 410 and it has a +non-zero time-to-live when +.Cm Expires +and +.Cm Cache-Control +headers are taken into account. .It Va obj.ttl The object's remaining time to live, in seconds. .It Va obj.lastuse From des at linpro.no Thu Aug 9 15:09:24 2007 From: des at linpro.no (=?iso-8859-1?Q?Dag-Erling_Sm=F8rgrav?=) Date: Thu, 09 Aug 2007 17:09:24 +0200 Subject: r1816 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: <20070808194352.390B21EC460@projects.linpro.no> (phk@projects.linpro.no's message of "Wed, 8 Aug 2007 21:43:52 +0200 (CEST)") References: <20070808194352.390B21EC460@projects.linpro.no> Message-ID: phk at projects.linpro.no writes: > Log: > Implement purging on either of hash or url. > > In VCL: > purge_url() > purge_hash() > (for an interrim period purge() will be the same as purge_url). > In CLI > url.purge > hash.purge I'm not entirely comfortable with this. If the goal is to allow purging to take the virtual host into account, I believe it would be better to implement URL normalization so the host name becomes part of the URL. That being said, there is no reason to provide backward compat with purge() since we never released it - it was added after 1.1. DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From des at projects.linpro.no Thu Aug 9 17:04:50 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 9 Aug 2007 19:04:50 +0200 (CEST) Subject: r1821 - trunk/varnish-doc/share Message-ID: <20070809170450.E13651EC468@projects.linpro.no> Author: des Date: 2007-08-09 19:04:50 +0200 (Thu, 09 Aug 2007) New Revision: 1821 Modified: trunk/varnish-doc/share/docbook-xml.css Log: Format , and in monospace. Modified: trunk/varnish-doc/share/docbook-xml.css =================================================================== --- trunk/varnish-doc/share/docbook-xml.css 2007-08-09 14:59:37 UTC (rev 1820) +++ trunk/varnish-doc/share/docbook-xml.css 2007-08-09 17:04:50 UTC (rev 1821) @@ -230,10 +230,22 @@ /* * Misc */ +command { + font-family: monospace; +} + filename { font-family: monospace; } +literal { + font-family: monospace; +} + +varname { + font-family: monospace; +} + function { font-family: monospace; } From des at projects.linpro.no Thu Aug 9 17:11:35 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 9 Aug 2007 19:11:35 +0200 (CEST) Subject: r1822 - trunk/varnish-doc/en/inside-varnish Message-ID: <20070809171135.602141EC2A3@projects.linpro.no> Author: des Date: 2007-08-09 19:11:35 +0200 (Thu, 09 Aug 2007) New Revision: 1822 Modified: trunk/varnish-doc/en/inside-varnish/article.xml Log: Add some text about the cli + the munin / nagios / webmin plugins, and some greek to help the document validate. Modified: trunk/varnish-doc/en/inside-varnish/article.xml =================================================================== --- trunk/varnish-doc/en/inside-varnish/article.xml 2007-08-09 17:04:50 UTC (rev 1821) +++ trunk/varnish-doc/en/inside-varnish/article.xml 2007-08-09 17:11:35 UTC (rev 1822) @@ -177,6 +177,9 @@ man + + Additional man pages. + @@ -206,16 +209,61 @@
Principles of operation + Lorem ipsum dolor sit amet
Subsystems +
+ The management interface + + The management interface allows a person or process to + control certain aspects of the accelerator while it is + running, such as inspecting and setting run-time parameters, + starting and stopping the child process, and purging + objects. + + The commands accepted by the management interface fall + in two categories: management commands and child commands. + The former are handled by the management (parent) process, + while the latter are passed unmodified to the child process + and handled there. + + The management interface uses an extremely simple + text-based protocol described below. + + The user sends a single line of text consisting of one + or more words separated by linear whitespace, terminated by a + newline character. Words which contain linear whitespace must + be placed in double quotes; newline characters must be sent as + \n, backslash characters as + \\ and double quote characters as + \". + + The first word sent by the client is the command name, + and subsequent words are command arguments. + + The management process responds with a line consisting + of a three-digit status code, linear whitespace, a byte count, + and a newline character. If the byte count is non-zero, this + line is followed by that many bytes of additional data, plus a + newline character. + + Status code 200 indicates success; all other codes + indicate some kind of failure. Status codes between 100 and + 199 indicate a syntax error, an unknown command, or issues + with the number or nature of the arguments. Status codes + between 300 and 399 indicate a failure to carry out the + requested operation. The status code 400 indicates a + communications error. +
Data structures + Lorem ipsum dolor sit amet
@@ -225,11 +273,13 @@
varnishlog + Lorem ipsum dolor sit amet
varnishncsa + Lorem ipsum dolor sit amet
@@ -239,44 +289,125 @@
varnishstat + Lorem ipsum dolor sit amet
varnishhist + Lorem ipsum dolor sit amet
varnishtop + Lorem ipsum dolor sit amet
The test framework + Lorem ipsum dolor sit amet
Plugins - The trunk/varnish-tools directory in + The trunk/varnish-tools/ directory in the Varnish repository contains Varnish plugins for several popular system monitoring and administration frameworks.
Munin + Munin, named for one of the two ravens that in Norse + tradition sit on the shoulders of Odin, father of the gods, is a + monitoring and graphing tool built on top of Tobi Oetiker's + RRDtool and maintained largely by Linpro. + + The Varnish Munin plugin is written in Perl and resides in + trunk/varnish-tools/munin/. It can report + on any statistic (called aspects) stored in + the shared memory log, and can easily be extended to also report + values computed from these statistics (derived + aspects). + + When run, the plugin first invokes + varnishstat. Using the first column as keys, + it registers each available statistic in the + %ASPECTS hash, and stores their values in the + %varnishstat hash. It then verifies that the + requested aspect matches one of the items in + %ASPECTS, i.e. one of the statistics reported + by varnishstat or a predefined derived + aspect. Finally, it either looks up or computes the requested + value, and prints it to stdout in the format + expected by Munin. + + Aspects are of one of three types: + count (a monotonically increasing counter), + gauge (an instantaneous measurement) and + percent (a fraction expressed as a + percentage). The first two are used for automatically created + aspects (i.e. everything varnishstat + reports), while the third is used only for predefined derived + aspects. + + A count or gauge + aspect has a value which is either a key in + %varnishstat or a reference to an array + representing an expression; the first element of the array is an + arithmetic operator, and subsequent elements are the terms + (which can themselves be references to expression + arrays). + + A percent aspect has one or more + values; if it has more than one, Munin will stack them. Each + value has a numerator and a + denominator, each of which is, as above, + either a key in %varnishstat or an + expression. + + When adding or modifying derived aspects, care should be + taken not to create unnecessary inconsistencies between this + plugin and the Nagios plugin described in the next + section.
Nagios + Nagios is a web-based host and network monitoring tool. + The major difference between Nagios and Munin is that while + Munin records statistics and creates graphs, Nagios primarily + wants to know whether a particular part of the system has failed + or is about to fail. + + The Varnish Nagios plugin is written in C and resides in + trunk/varnish-tools/nagios/. It can report + any statistic stored in the shared memory log. It can also + fairly easily be extended to report computed statistics. + + + + When adding or modifying parameters, care should be taken + not to create unnecessary inconsistencies between this plugin + and the Munin plugin described in the previous section.
Webmin + Webmin is a web-based system configuration and + administration tool for Unix-like systems. + + The Varnish Webmin plugin is written in Perl and resides + in trunk/varnish-tools/webmin/. It can + perform all of the functions that are available through the + management process's command-line interface. + +
@@ -286,16 +417,19 @@
varnishadm + Lorem ipsum dolor sit amet
varnishreplay + Lorem ipsum dolor sit amet
fetcher + Lorem ipsum dolor sit amet
From phk at phk.freebsd.dk Thu Aug 9 19:17:22 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Thu, 09 Aug 2007 19:17:22 +0000 Subject: r1816 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: Your message of "Thu, 09 Aug 2007 17:09:24 +0200." Message-ID: <907.1186687042@critter.freebsd.dk> In message , =?iso-8859-1?Q?Dag-Erling_Sm=F8rg rav?= writes: >I'm not entirely comfortable with this. If the goal is to allow >purging to take the virtual host into account, I believe it would be >better to implement URL normalization so the host name becomes part of >the URL. That was my original plan, however, upon thinking about it, I realized that it would accomplish less, require more code and run slower. We have no other need of a normalized URL, so the text-processing would be solely for the ability to purge, and would in all relevant cases mirror the necessary text-processing we do on the hash string. And once you boil it down to the essence, what you want to do with purge is nuke cached objects. >From our point of view, objects have only one relevant unique identity: their hash string. And once people start to put cookies or languages into their hash strings, those properties become valid targets for purges as well ("Purge all french documents"). Unless your VCL is really interesting, the obvious command will DTRT: hash.purge mypage.html or hash.purge foohost.com The one thing about this scheme I'm not sure about is the use of '#' as separator. It's my impression that it occurs infrequently in the relevant data (url, host, cookies &c) but it bothers me that it is a commom comment character, but I worked hard to find an alternative. I kept the purge_url around mostly for backwards compatibility, because you can do the exact same thing with purge_hash. The "real" solution, would be to have a vcl.purge and compile the conditional with VCC, so you could say things like: vcl.purge "obj.ttl > 1h && obj.http.cookie[FOO]" But I doubt we'll ever do that... >That being said, there is no reason to provide backward compat with >purge() since we never released it - it was added after 1.1. Ok, I'll yank that then. -- 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 Thu Aug 9 20:20:21 2007 From: des at linpro.no (=?iso-8859-1?Q?Dag-Erling_Sm=F8rgrav?=) Date: Thu, 09 Aug 2007 22:20:21 +0200 Subject: r1816 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: <907.1186687042@critter.freebsd.dk> (Poul-Henning Kamp's message of "Thu, 09 Aug 2007 19:17:22 +0000") References: <907.1186687042@critter.freebsd.dk> Message-ID: "Poul-Henning Kamp" writes: > The one thing about this scheme I'm not sure about is the use of '#' > as separator. It's my impression that it occurs infrequently in the > relevant data (url, host, cookies &c) but it bothers me that it is > a commom comment character, but I worked hard to find an alternative. \001? DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From des at projects.linpro.no Fri Aug 10 07:13:04 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 10 Aug 2007 09:13:04 +0200 (CEST) Subject: r1823 - in trunk/varnish-cache/bin: varnishadm varnishd Message-ID: <20070810071304.A48281ED941@projects.linpro.no> Author: des Date: 2007-08-10 09:13:02 +0200 (Fri, 10 Aug 2007) New Revision: 1823 Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c trunk/varnish-cache/bin/varnishd/storage_file.c Log: Avoid mixing statements and declarations (#147) Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.c 2007-08-09 17:11:35 UTC (rev 1822) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.c 2007-08-10 07:13:02 UTC (rev 1823) @@ -51,6 +51,7 @@ struct vss_addr **ta; char *addr, *port; int i, n; + int sock; long status, bytes; char *answer = NULL; char buf[13]; @@ -65,7 +66,7 @@ exit(2); } - int sock = VSS_connect(ta[0]); + sock = VSS_connect(ta[0]); for (i = 0; i < n; ++i) { free(ta[i]); Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2007-08-09 17:11:35 UTC (rev 1822) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-08-10 07:13:02 UTC (rev 1823) @@ -118,6 +118,7 @@ static void smf_calcsize(struct smf_sc *sc, const char *size, int newfile) { + struct statfs fsst; uintmax_t l, fssize; unsigned bs; char suff[2]; @@ -129,10 +130,7 @@ AZ(fstat(sc->fd, &st)); xxxassert(S_ISREG(st.st_mode)); -#if defined(HAVE_SYS_MOUNT_H) || defined(HAVE_SYS_VFS_H) - struct statfs fsst; AZ(fstatfs(sc->fd, &fsst)); -#endif /* We use units of the larger of filesystem blocksize and pagesize */ bs = sc->pagesize; From phk at projects.linpro.no Fri Aug 10 09:22:49 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 10 Aug 2007 11:22:49 +0200 (CEST) Subject: r1824 - trunk/varnish-cache/lib/libvcl Message-ID: <20070810092249.ECDA81EC2B4@projects.linpro.no> Author: phk Date: 2007-08-10 11:22:49 +0200 (Fri, 10 Aug 2007) New Revision: 1824 Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c Log: Remove the "purge" compat, we never shipped it in a release. Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-08-10 07:13:02 UTC (rev 1823) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2007-08-10 09:22:49 UTC (rev 1824) @@ -337,9 +337,6 @@ { "purge_url", parse_purge_url }, { "purge_hash", parse_purge_hash }, - /* XXX: Compat remove in 1.2/2.0 */ - { "purge", parse_purge_url }, - { NULL, NULL } }; From des at projects.linpro.no Fri Aug 10 09:30:07 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 10 Aug 2007 11:30:07 +0200 (CEST) Subject: r1825 - in branches/1.1: . bin/varnishadm bin/varnishd Message-ID: <20070810093007.800621EC6DB@projects.linpro.no> Author: des Date: 2007-08-10 11:30:07 +0200 (Fri, 10 Aug 2007) New Revision: 1825 Modified: branches/1.1/ branches/1.1/bin/varnishadm/varnishadm.c branches/1.1/bin/varnishd/storage_file.c Log: Merged revisions 1823 via svnmerge from file:///var/lib/svn/varnish/trunk/varnish-cache ........ r1823 | des | 2007-08-10 09:13:02 +0200 (Fri, 10 Aug 2007) | 2 lines Avoid mixing statements and declarations (#147) ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1793,1795,1797-1798,1800-1808,1810-1815,1817,1819 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1793,1795,1797-1798,1800-1808,1810-1815,1817,1819,1823 Modified: branches/1.1/bin/varnishadm/varnishadm.c =================================================================== --- branches/1.1/bin/varnishadm/varnishadm.c 2007-08-10 09:22:49 UTC (rev 1824) +++ branches/1.1/bin/varnishadm/varnishadm.c 2007-08-10 09:30:07 UTC (rev 1825) @@ -51,6 +51,7 @@ struct vss_addr **ta; char *addr, *port; int i, n; + int sock; long status, bytes; char *answer = NULL; char buf[13]; @@ -65,7 +66,7 @@ exit(2); } - int sock = VSS_connect(ta[0]); + sock = VSS_connect(ta[0]); for (i = 0; i < n; ++i) { free(ta[i]); Modified: branches/1.1/bin/varnishd/storage_file.c =================================================================== --- branches/1.1/bin/varnishd/storage_file.c 2007-08-10 09:22:49 UTC (rev 1824) +++ branches/1.1/bin/varnishd/storage_file.c 2007-08-10 09:30:07 UTC (rev 1825) @@ -116,7 +116,8 @@ static void smf_calcsize(struct smf_sc *sc, const char *size, int newfile) { - uintmax_t l; + struct statfs fsst; + uintmax_t l, fssize; unsigned bs; char suff[2]; int i, explicit; @@ -126,10 +127,7 @@ AN(sc); AZ(fstat(sc->fd, &st)); -#if defined(HAVE_SYS_MOUNT_H) || defined(HAVE_SYS_VFS_H) - struct statfs fsst; AZ(fstatfs(sc->fd, &fsst)); -#endif /* We use units of the larger of filesystem blocksize and pagesize */ bs = sc->pagesize; From des at projects.linpro.no Fri Aug 10 09:33:39 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 10 Aug 2007 11:33:39 +0200 (CEST) Subject: r1826 - in branches/1.1: . bin/varnishd Message-ID: <20070810093339.C86311EC6ED@projects.linpro.no> Author: des Date: 2007-08-10 11:33:39 +0200 (Fri, 10 Aug 2007) New Revision: 1826 Modified: branches/1.1/ branches/1.1/bin/varnishd/storage_file.c Log: Merged revisions 1794 via svnmerge from file:///var/lib/svn/varnish/trunk/varnish-cache ........ r1794 | des | 2007-08-03 20:50:05 +0200 (Fri, 03 Aug 2007) | 3 lines Try harder to avoid integer overflows in cache file size calculations on 32-bit platforms. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1793,1795,1797-1798,1800-1808,1810-1815,1817,1819,1823 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823 Modified: branches/1.1/bin/varnishd/storage_file.c =================================================================== --- branches/1.1/bin/varnishd/storage_file.c 2007-08-10 09:30:07 UTC (rev 1825) +++ branches/1.1/bin/varnishd/storage_file.c 2007-08-10 09:33:39 UTC (rev 1826) @@ -126,6 +126,7 @@ AN(sc); AZ(fstat(sc->fd, &st)); + xxxassert(S_ISREG(st.st_mode)); AZ(fstatfs(sc->fd, &fsst)); @@ -133,9 +134,10 @@ bs = sc->pagesize; if (bs < fsst.f_bsize) bs = fsst.f_bsize; + xxxassert(bs % sc->pagesize == 0); + xxxassert(bs % fsst.f_bsize == 0); + fssize = fsst.f_bsize * fsst.f_bavail; - xxxassert(S_ISREG(st.st_mode)); - i = sscanf(size, "%ju%1s", &l, suff); /* can return -1, 0, 1 or 2 */ explicit = i; @@ -175,7 +177,7 @@ l *= (uintmax_t)(1024UL * 1024UL) * (uintmax_t)(1024UL * 1024UL); else if (suff[0] == '%') { - l *= fsst.f_bsize * fsst.f_bavail; + l *= fssize; l /= 100; } } @@ -196,14 +198,14 @@ if (l < st.st_size) { AZ(ftruncate(sc->fd, l)); - } else if (l - st.st_size > fsst.f_bsize * fsst.f_bavail) { - l = ((uintmax_t)fsst.f_bsize * fsst.f_bavail * 80) / 100; + } else if (l - st.st_size > fssize) { + l = fssize * 80 / 100; fprintf(stderr, "WARNING: storage file size reduced" " to %ju (80%% of available disk space)\n", l); } } - /* round down to of filesystem blocksize or pagesize */ + /* round down to multiple of filesystem blocksize or pagesize */ l -= (l % bs); if (l < MINPAGES * (uintmax_t)sc->pagesize) { From des at projects.linpro.no Fri Aug 10 09:36:42 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 10 Aug 2007 11:36:42 +0200 (CEST) Subject: r1827 - in trunk/varnish-cache: bin/varnishd man Message-ID: <20070810093642.57F7D1EC2B2@projects.linpro.no> Author: des Date: 2007-08-10 11:36:42 +0200 (Fri, 10 Aug 2007) New Revision: 1827 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/man/vcl.7 Log: Document purge_url / purge_hash Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-08-10 09:33:39 UTC (rev 1826) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-08-10 09:36:42 UTC (rev 1827) @@ -182,7 +182,7 @@ 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", + "exec cc -dynamiclib -Wl,-undefined,dynamic_lookup -o %s -x c - < %s 2>&1", #else "exec cc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1", #endif Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-08-10 09:33:39 UTC (rev 1826) +++ trunk/varnish-cache/man/vcl.7 2007-08-10 09:36:42 UTC (rev 1827) @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd August 3, 2007 +.Dd August 10, 2007 .Dt VCL 7 .Os .Sh NAME @@ -136,9 +136,12 @@ is replaced with the contents of subgroup .Ar n in the matched string. -.It Fn purge "regex" -Purge all objects in cache matching +.It Fn purge_hash "regex" +Purge all objects in cache whose hash strings match .Fa regex . +.It Fn purge_url "regex" +Purge all objects in cache whose URLs match +.Fa regex . .El .Ss Subroutines A subroutine is used to group code for legibility or reusability: From des at projects.linpro.no Fri Aug 10 09:37:13 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 10 Aug 2007 11:37:13 +0200 (CEST) Subject: r1828 - in branches/1.1: lib/libvcl man Message-ID: <20070810093713.0B2351EC874@projects.linpro.no> Author: des Date: 2007-08-10 11:37:12 +0200 (Fri, 10 Aug 2007) New Revision: 1828 Modified: branches/1.1/lib/libvcl/vcc_action.c branches/1.1/man/vcl.7 Log: purge() -> purge_url() to match trunk. Modified: branches/1.1/lib/libvcl/vcc_action.c =================================================================== --- branches/1.1/lib/libvcl/vcc_action.c 2007-08-10 09:36:42 UTC (rev 1827) +++ branches/1.1/lib/libvcl/vcc_action.c 2007-08-10 09:37:12 UTC (rev 1828) @@ -270,7 +270,7 @@ /*--------------------------------------------------------------------*/ static void -parse_purge(struct tokenlist *tl) +parse_purge_url(struct tokenlist *tl) { vcc_NextToken(tl); @@ -307,7 +307,8 @@ { "call", parse_call }, { "set", parse_set }, { "remove", parse_remove }, - { "purge", parse_purge }, + { "purge_url", parse_purge_url }, + { NULL, NULL } }; Modified: branches/1.1/man/vcl.7 =================================================================== --- branches/1.1/man/vcl.7 2007-08-10 09:36:42 UTC (rev 1827) +++ branches/1.1/man/vcl.7 2007-08-10 09:37:12 UTC (rev 1828) @@ -136,8 +136,8 @@ is replaced with the contents of subgroup .Ar n in the matched string. -.It Fn purge "regex" -Purge all objects in cache matching +.It Fn purge_url "regex" +Purge all objects in cache whose URLs match .Fa regex . .El .Ss Subroutines From phk at projects.linpro.no Fri Aug 10 09:51:16 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 10 Aug 2007 11:51:16 +0200 (CEST) Subject: r1829 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070810095116.534921EC2B4@projects.linpro.no> Author: phk Date: 2007-08-10 11:51:16 +0200 (Fri, 10 Aug 2007) New Revision: 1829 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Fix an architectural mistake: What the compiled VCL code contains is not "a backend" but more like a specification of or a template of a backend. This matters because it controls the ownership of the backend structure, and to a lesser degree because it complicates the VRT api with a lot of pointless functions. When vcl.use switches to a different VCL program, the backends of the old VCL program may still be in use, and, provided the backend declarations of the two VCL programs are identical, should continue be carried over to the new VCL code. This requires the memory and state to be owned by the central backend code, and the VCL programs to just hold references and becomes even more important when we keep complex state for load balancing on individual backends. This commit changes the ownership of the backends to the central code, and moves the specification used in the compiled VCL program to a communication structure for just that. This also paves the way for introducing directors/policies for backend selection and for good measure, I have named the default (ie: current) backend policy "simple" for now. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-10 09:37:12 UTC (rev 1828) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-10 09:51:16 UTC (rev 1829) @@ -267,63 +267,6 @@ sp->handling = hand; } -/*--------------------------------------------------------------------*/ - -void -VRT_set_backend_name(struct backend *be, const char *p) -{ - CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); - be->vcl_name = p; -} - -void -VRT_alloc_backends(struct VCL_conf *cp) -{ - int i; - - cp->backend = calloc(sizeof *cp->backend, cp->nbackend); - XXXAN(cp->backend); - for (i = 0; i < cp->nbackend; i++) { - cp->backend[i] = calloc(sizeof *cp->backend[i], 1); - XXXAN(cp->backend[i]); - 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; - } -} - -void -VRT_free_backends(struct VCL_conf *cp) -{ - - (void)cp; /* XXX */ -} - -void -VRT_fini_backend(struct backend *be) -{ - - (void)be; /* XXX */ -} - -/*--------------------------------------------------------------------*/ - -#define VBACKEND(type,onm,field) \ -void \ -VRT_l_backend_##onm(struct backend *be, type a) \ -{ \ - CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); \ - be->field = a; \ -} \ - -VBACKEND(const char *, host, hostname) -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. @@ -557,3 +500,40 @@ AddBan(regexp, hash); } + +/*-------------------------------------------------------------------- + * Backend stuff, should probably move to its own file eventually + */ +void +VRT_init_simple_backend(struct backend **bp, struct vrt_simple_backend *t) +{ + struct backend *b; + + b = calloc(sizeof *b, 1); + XXXAN(b); + b->magic = BACKEND_MAGIC; + b->dnsttl = 300; + TAILQ_INIT(&b->connlist); + b->last_check = TIM_mono(); + b->minute_limit = 1; + + AN(t->name); + b->vcl_name = strdup(t->name); + XXXAN(b->vcl_name); + + AN(t->port); + b->portname = strdup(t->port); + XXXAN(b->portname); + + AN(t->host); + b->hostname = strdup(t->host); + XXXAN(b->hostname); + + *bp = b; +} + +void +VRT_fini_backend(struct backend *b) +{ + (void)b; +} Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-08-10 09:37:12 UTC (rev 1828) +++ trunk/varnish-cache/include/vrt.h 2007-08-10 09:51:16 UTC (rev 1829) @@ -40,6 +40,12 @@ struct VCL_conf; struct sockaddr; +struct vrt_simple_backend { + const char *name; + const char *port; + const char *host; +}; + struct vrt_ref { unsigned source; unsigned offset; @@ -83,10 +89,8 @@ void VRT_handling(struct sess *sp, unsigned hand); /* Backend related */ -void VRT_set_backend_name(struct backend *, const char *); -void VRT_alloc_backends(struct VCL_conf *cp); -void VRT_free_backends(struct VCL_conf *cp); -void VRT_fini_backend(struct backend *be); +void VRT_init_simple_backend(struct backend **, struct vrt_simple_backend *); +void VRT_fini_backend(struct backend *); char *VRT_IP_string(struct sess *sp, struct sockaddr *sa); char *VRT_int_string(struct sess *sp, int); Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2007-08-10 09:37:12 UTC (rev 1828) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2007-08-10 09:51:16 UTC (rev 1829) @@ -61,7 +61,6 @@ void vcc_ParseBackend(struct tokenlist *tl) { - unsigned a; struct var *vp; struct token *t_be = NULL; struct token *t_host = NULL; @@ -72,17 +71,17 @@ ExpectErr(tl, ID); t_be = tl->t; vcc_AddDef(tl, tl->t, R_BACKEND); + /* + * The first backend is always referenced because that is the default + * at the beginning of vcl_recv + */ if (tl->nbackend == 0) vcc_AddRef(tl, tl->t, R_BACKEND); + + /* In the compiled vcl we use these macros to refer to backends */ Fh(tl, 1, "#define VGC_backend_%.*s (VCL_conf.backend[%d])\n", PF(tl->t), tl->nbackend); - Fc(tl, 0, "\n"); - Fc(tl, 0, "static void\n"); - Fc(tl, 1, "VGC_init_backend_%.*s (void)\n", PF(tl->t)); - Fc(tl, 1, "{\n"); - Fc(tl, 1, "\tstruct backend *backend = VGC_backend_%.*s;\n", PF(tl->t)); - Fc(tl, 1, "\n"); - Fc(tl, 1, "\tVRT_set_backend_name(backend, \"%.*s\");\n", PF(tl->t)); + vcc_NextToken(tl); ExpectErr(tl, '{'); vcc_NextToken(tl); @@ -110,40 +109,13 @@ case HOSTNAME: ExpectErr(tl, CSTR); t_host = tl->t; - Fc(tl, 1, "\t%s ", vp->lname); - EncToken(tl->fc, t_host); - Fc(tl, 0, ");\n"); vcc_NextToken(tl); break; case PORTNAME: ExpectErr(tl, CSTR); t_port = tl->t; - Fc(tl, 1, "\t%s ", vp->lname); - EncToken(tl->fc, t_port); - Fc(tl, 0, ");\n"); vcc_NextToken(tl); break; -#if 0 - case INT: - case SIZE: - case RATE: - case FLOAT: -#endif - case TIME: - Fc(tl, 1, "\t%s ", vp->lname); - a = tl->t->tok; - if (a == T_MUL || a == T_DIV) - Fc(tl, 0, "%g", vcc_DoubleVal(tl)); - else if (vp->fmt == TIME) - vcc_TimeVal(tl); - else if (vp->fmt == SIZE) - vcc_SizeVal(tl); - else if (vp->fmt == RATE) - vcc_RateVal(tl); - else - Fc(tl, 0, "%g", vcc_DoubleVal(tl)); - Fc(tl, 0, ");\n"); - break; default: vsb_printf(tl->sb, "Assignments not possible for '%s'\n", vp->name); @@ -177,9 +149,14 @@ } vcc_NextToken(tl); - Fc(tl, 1, "}\n"); - Fc(tl, 0, "\n"); - Fi(tl, 0, "\tVGC_init_backend_%.*s();\n", PF(t_be)); + Fc(tl, 0, "\nstatic struct vrt_simple_backend sbe_%.*s = {\n", + PF(t_be)); + Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_be)); + Fc(tl, 0, "\t.port = %.*s,\n", PF(t_port)); + Fc(tl, 0, "\t.host = %.*s,\n", PF(t_host)); + Fc(tl, 0, "};\n"); + Fi(tl, 0, "\tVRT_init_simple_backend(&VGC_backend_%.*s , &sbe_%.*s);\n", + PF(t_be), PF(t_be)); Ff(tl, 0, "\tVRT_fini_backend(VGC_backend_%.*s);\n", PF(t_be)); tl->nbackend++; } Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-08-10 09:37:12 UTC (rev 1828) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-08-10 09:51:16 UTC (rev 1829) @@ -338,11 +338,14 @@ } Fc(tl, 0, "};\n"); + Fc(tl, 0, "\nstatic struct backend\t*backends[%d];\n", tl->nbackend); + Fc(tl, 0, "\nstruct VCL_conf VCL_conf = {\n"); Fc(tl, 0, "\t.magic = VCL_CONF_MAGIC,\n"); Fc(tl, 0, "\t.init_func = VGC_Init,\n"); Fc(tl, 0, "\t.fini_func = VGC_Fini,\n"); Fc(tl, 0, "\t.nbackend = %d,\n", tl->nbackend); + Fc(tl, 0, "\t.backend = backends,\n"); Fc(tl, 0, "\t.ref = VGC_ref,\n"); Fc(tl, 0, "\t.nref = VGC_NREFS,\n"); Fc(tl, 0, "\t.nsrc = %u,\n", tl->nsources); @@ -559,8 +562,6 @@ Fh(tl, 0, "\n/* ---===### VCC generated below here ###===---*/\n"); Fh(tl, 0, "\nextern struct VCL_conf VCL_conf;\n"); - Fi(tl, 0, "\tVRT_alloc_backends(&VCL_conf);\n"); - /* Register and lex the main source */ TAILQ_INSERT_TAIL(&tl->sources, sp, list); sp->idx = tl->nsources++; @@ -615,8 +616,6 @@ if (tl->err) return (vcc_DestroyTokenList(tl, NULL)); - Ff(tl, 0, "\tVRT_free_backends(&VCL_conf);\n"); - /* Emit method functions */ for (i = 0; i < N_METHODS; i++) { Fc(tl, 1, "\nstatic int\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-08-10 09:37:12 UTC (rev 1828) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-08-10 09:51:16 UTC (rev 1829) @@ -398,6 +398,12 @@ vsb_cat(sb, "struct VCL_conf;\n"); vsb_cat(sb, "struct sockaddr;\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "struct vrt_simple_backend {\n"); + vsb_cat(sb, " const char *name;\n"); + vsb_cat(sb, " const char *port;\n"); + vsb_cat(sb, " const char *host;\n"); + vsb_cat(sb, "};\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, "struct vrt_ref {\n"); vsb_cat(sb, " unsigned source;\n"); vsb_cat(sb, " unsigned offset;\n"); @@ -441,10 +447,8 @@ vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/* Backend related */\n"); - vsb_cat(sb, "void VRT_set_backend_name(struct backend *, const char *);\n"); - vsb_cat(sb, "void VRT_alloc_backends(struct VCL_conf *cp);\n"); - 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, "void VRT_init_simple_backend(struct backend **, struct vrt_simple_backend *);\n"); + vsb_cat(sb, "void VRT_fini_backend(struct backend *);\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"); From phk at projects.linpro.no Fri Aug 10 10:28:08 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 10 Aug 2007 12:28:08 +0200 (CEST) Subject: r1830 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070810102808.DE8951EC2B2@projects.linpro.no> Author: phk Date: 2007-08-10 12:28:08 +0200 (Fri, 10 Aug 2007) New Revision: 1830 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_parse.c Log: Don't call functions outside the VRT namespace, even if this means that we have to wrap strcmp(). Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-10 09:51:16 UTC (rev 1829) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-10 10:28:08 UTC (rev 1830) @@ -502,6 +502,17 @@ } /*-------------------------------------------------------------------- + * Simple stuff + */ + +int +VRT_strcmp(const char *s1, const char *s2) +{ + return (strcmp(s1, s2)); +} + + +/*-------------------------------------------------------------------- * Backend stuff, should probably move to its own file eventually */ void Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-08-10 09:51:16 UTC (rev 1829) +++ trunk/varnish-cache/include/vrt.h 2007-08-10 10:28:08 UTC (rev 1830) @@ -88,6 +88,10 @@ void VRT_SetHdr(struct sess *, enum gethdr_e where, const char *, const char *, ...); void VRT_handling(struct sess *sp, unsigned hand); +/* Simple stuff */ +int VRT_strcmp(const char *s1, const char *s2); + + /* Backend related */ void VRT_init_simple_backend(struct backend **, struct vrt_simple_backend *); void VRT_fini_backend(struct backend *); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-08-10 09:51:16 UTC (rev 1829) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-08-10 10:28:08 UTC (rev 1830) @@ -446,6 +446,10 @@ 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, "/* Simple stuff */\n"); + vsb_cat(sb, "int VRT_strcmp(const char *s1, const char *s2);\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, "/* Backend related */\n"); vsb_cat(sb, "void VRT_init_simple_backend(struct backend **, struct vrt_simple_backend *);\n"); vsb_cat(sb, "void VRT_fini_backend(struct backend *);\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-08-10 09:51:16 UTC (rev 1829) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-08-10 10:28:08 UTC (rev 1830) @@ -232,7 +232,7 @@ break; case T_EQ: case T_NEQ: - Fb(tl, 1, "%sstrcmp(%s, ", + Fb(tl, 1, "%sVRT_strcmp(%s, ", tl->t->tok == T_EQ ? "!" : "", vp->rname); vcc_NextToken(tl); ExpectErr(tl, CSTR); From des at linpro.no Fri Aug 10 10:41:02 2007 From: des at linpro.no (=?iso-8859-1?Q?Dag-Erling_Sm=F8rgrav?=) Date: Fri, 10 Aug 2007 12:41:02 +0200 Subject: r1830 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: <20070810102808.DE8951EC2B2@projects.linpro.no> (phk@projects.linpro.no's message of "Fri, 10 Aug 2007 12:28:08 +0200 (CEST)") References: <20070810102808.DE8951EC2B2@projects.linpro.no> Message-ID: phk at projects.linpro.no writes: > Log: > Don't call functions outside the VRT namespace, even if this means > that we have to wrap strcmp(). I believe there's a strndup() call in there somewhere as well? DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From ssm at projects.linpro.no Fri Aug 10 14:05:32 2007 From: ssm at projects.linpro.no (ssm at projects.linpro.no) Date: Fri, 10 Aug 2007 16:05:32 +0200 (CEST) Subject: r1831 - trunk/varnish-cache/debian Message-ID: <20070810140532.9425F1EC2B4@projects.linpro.no> Author: ssm Date: 2007-08-10 16:05:32 +0200 (Fri, 10 Aug 2007) New Revision: 1831 Modified: trunk/varnish-cache/debian/control Log: Added missing dependency on "libc6-dev | libc-dev" for vcl compilation Modified: trunk/varnish-cache/debian/control =================================================================== --- trunk/varnish-cache/debian/control 2007-08-10 10:28:08 UTC (rev 1830) +++ trunk/varnish-cache/debian/control 2007-08-10 14:05:32 UTC (rev 1831) @@ -8,7 +8,7 @@ Package: varnish Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, gcc ( >= 3.3), libvarnish +Depends: ${shlibs:Depends}, ${misc:Depends}, gcc ( >= 3.3), libvarnish, libc6-dev | libc-dev 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 From phk at phk.freebsd.dk Fri Aug 10 20:00:21 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Fri, 10 Aug 2007 20:00:21 +0000 Subject: r1830 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: Your message of "Fri, 10 Aug 2007 12:41:02 +0200." Message-ID: <692.1186776021@critter.freebsd.dk> In message , =?iso-8859-1?Q?Dag-Erling_Sm=F8rg rav?= writes: >phk at projects.linpro.no writes: >> Log: >> Don't call functions outside the VRT namespace, even if this means >> that we have to wrap strcmp(). > >I believe there's a strndup() call in there somewhere as well? Hopefully not in the compiled code ? -- 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 Fri Aug 10 20:13:15 2007 From: des at linpro.no (=?iso-8859-1?Q?Dag-Erling_Sm=F8rgrav?=) Date: Fri, 10 Aug 2007 22:13:15 +0200 Subject: r1830 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: <692.1186776021@critter.freebsd.dk> (Poul-Henning Kamp's message of "Fri, 10 Aug 2007 20:00:21 +0000") References: <692.1186776021@critter.freebsd.dk> Message-ID: "Poul-Henning Kamp" writes: > Dag-Erling Sm?rgrav writes: > > phk at projects.linpro.no writes: > > > Log: > > > Don't call functions outside the VRT namespace, even if this means > > > that we have to wrap strcmp(). > >I believe there's a strndup() call in there somewhere as well? > > Hopefully not in the compiled code ? Never mind, the strndup() issue (#118) was not related to VCL. DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From phk at phk.freebsd.dk Sat Aug 11 20:34:59 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Sat, 11 Aug 2007 20:34:59 +0000 Subject: r1816 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: Your message of "Thu, 09 Aug 2007 22:20:21 +0200." Message-ID: <87256.1186864499@critter.freebsd.dk> In message , =?iso-8859-1?Q?Dag-Erling_Sm=F8rg rav?= writes: >"Poul-Henning Kamp" writes: >> The one thing about this scheme I'm not sure about is the use of '#' >> as separator. It's my impression that it occurs infrequently in the >> relevant data (url, host, cookies &c) but it bothers me that it is >> a commom comment character, but I worked hard to find an alternative. > >\001? Yeah, only this might travel through the CLI a lot and a backslash isn't much fun quouting through scripts. The other thing I thought about was a space character, as it is neither legal in hostnames nor urls, but if people stick entire HTTP lines into the hash, then it's a bad idea, and it requires the regex to be quoted in the cli -- 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 Aug 13 13:52:29 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 15:52:29 +0200 (CEST) Subject: r1832 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070813135229.5C95B1EC2B2@projects.linpro.no> Author: des Date: 2007-08-13 15:52:29 +0200 (Mon, 13 Aug 2007) New Revision: 1832 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm Log: Improve timeout handling, and add a server timeout which starts running when the server gets a partial response. Similarly, on the client side, cancel the timeout as soon as we get data, but restart it if we have to wait for more. Also stop logging the full content of requests and responses; it clutters the output and can easily be obtained using varnishlog(1). Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-10 14:05:32 UTC (rev 1831) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-13 13:52:29 UTC (rev 1832) @@ -134,10 +134,12 @@ foreach my $method (@tests) { eval { $self->{'count'} += 1; + $self->log(sprintf("%d: TRY: %s", + $self->{'count'}, $method)); my $result = $self->$method(@args); $self->{'successful'} += 1; $self->log(sprintf("%d: PASS: %s: %s\n", - $self->{'count'}, $method, $result || '')); + $self->{'count'}, $method, $result || 'OK')); }; if ($@) { $self->{'failed'} += 1; @@ -189,7 +191,7 @@ sub ev_client_timeout($$) { my ($self, $client) = @_; - $client->shutdown(2); + $client->shutdown(); return $client; } @@ -221,6 +223,13 @@ $connection->send_response($response); } +sub ev_server_timeout($$) { + my ($self, $srvconn) = @_; + + $srvconn->shutdown(); + return $srvconn; +} + # # Client utilities # @@ -241,15 +250,21 @@ unless ($req->header('Content-Length')); $req->content($content); } - $client->send_request($req, 2); + $client->send_request($req, 4); my ($ev, $resp) = - $self->run_loop('ev_client_response', 'ev_client_timeout'); - die "Client time-out before receiving a (complete) response\n" + $self->run_loop('ev_server_timeout', + 'ev_client_timeout', + 'ev_client_response'); + die "Server timed out before receiving a complete request\n" + if $ev eq 'ev_server_timeout'; + die "Client timed out before receiving a complete response\n" if $ev eq 'ev_client_timeout'; die "Internal error\n" unless $resp && ref($resp) && $resp->isa('HTTP::Response'); die "No X-Varnish header\n" - unless $resp->header('X-Varnish'); + unless (!$resp->header('X-Varnish')); + die "Invalid X-Varnish header\n" + unless ($resp->header('X-Varnish') =~ m/^\d+(?: \d+)?$/); $resp->request($req); return $self->{'cached_response'} = $resp; } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-08-10 14:05:32 UTC (rev 1831) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-08-13 13:52:29 UTC (rev 1832) @@ -63,40 +63,51 @@ $self->{'engine'}->log($self, 'CLI: ' . ($extra_prefix || ''), $str); } +sub logf($$;@) { + my ($self, $fmt, @args) = @_; + + $self->{'engine'}->log($self, 'CLI: ', sprintf($fmt, @args)); +} + sub send_request($$;$) { my ($self, $request, $timeout) = @_; - my $fh = IO::Socket::INET->new('Proto' => 'tcp', - 'PeerAddr' => 'localhost', - 'PeerPort' => '8080') - or die "socket(): $!\n"; - - $self->{'fh'} = $fh; - $self->{'mux'}->add($fh); - $self->{'mux'}->set_timeout($fh, $timeout) if defined($timeout); - $self->{'mux'}->set_callback_object($self, $fh); - $self->{'mux'}->write($fh, $request->as_string); + if (!defined($self->{'fh'})) { + my $fh = IO::Socket::INET->new('Proto' => 'tcp', + 'PeerAddr' => 'localhost', + 'PeerPort' => '8080') + or die "socket(): $!\n"; + $self->{'fh'} = $fh; + $self->{'mux'}->add($fh); + $self->{'mux'}->set_callback_object($self, $fh); + } + $self->{'timeout'} = $timeout; + $self->{'mux'}->set_timeout($fh, $timeout); + $self->{'mux'}->write($self->{'fh'}, $request->as_string); $self->{'requests'} += 1; - $self->log($request->as_string, 'Tx| '); + $self->logf("%s %s %s", $request->method(), $request->uri(), $request->protocol()); } sub got_response($$) { my ($self, $response) = @_; $self->{'responses'} += 1; - $self->log($response->as_string, 'Rx| '); + $self->logf("%s %s", $response->code(), $response->message()); $self->{'engine'}->ev_client_response($self, $response); } sub shutdown($) { - my ($self) = @_; + my ($self, $how) = @_; - $self->{'mux'}->shutdown($self->{'fh'}, 1); + $self->{'mux'}->close($self->{'fh'}); + $self->{'fh'} = undef; } sub mux_input($$$$) { my ($self, $mux, $fh, $data) = @_; + $mux->set_timeout($fh, undef); + # Iterate through the input buffer ($$data) and identify HTTP # messages, one per iteration. Break out of the loop when there # are no complete HTTP messages left in the buffer, and let @@ -135,6 +146,7 @@ # so break out of loop and wait for more. $self->log("Partial body received" . " ($data_length of $content_length bytes)"); + $mux->set_timeout($fh, $self->{'timeout'}); last; } else { @@ -158,7 +170,9 @@ # out of loop and wait for EOF, in which case mux_eof will # reparse the input buffer as a HTTP message and send it # to event handling from there. - $self->log('Partial response. Content-Length unknown. Expecting CLOSE as end-of-response.'); + $self->log("Partial response. Content-Length unknown." . + " Expecting CLOSE as end-of-response."); + $mux->set_timeout($fh, $self->{'timeout'}); last; } } @@ -183,6 +197,7 @@ sub mux_timeout($$$) { my ($self, $mux, $fh) = @_; + $self->{'mux'}->set_timeout($fh, undef); $self->{'engine'}->ev_client_timeout($self); } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-08-10 14:05:32 UTC (rev 1831) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-08-13 13:52:29 UTC (rev 1832) @@ -79,6 +79,12 @@ $self->{'engine'}->log($self, 'SRV: ' . ($extra_prefix || ''), $str); } +sub logf($$;@) { + my ($self, $fmt, @args) = @_; + + $self->{'engine'}->log($self, 'SRV: ', sprintf($fmt, @args)); +} + sub shutdown($) { my ($self) = @_; @@ -104,19 +110,21 @@ my ($self, $connection, $request) = @_; $self->{'requests'} += 1; - $self->log($request->as_string, 'Rx| '); + $self->logf("%s %s %s", $request->method(), $request->uri(), $request->protocol()); $self->{'engine'}->ev_server_request($self, $connection, $request); } package Varnish::Test::Server::Connection; use strict; +use HTTP::Status; sub new($$) { my ($this, $server, $fh) = @_; my $class = ref($this) || $this; my $self = bless({ 'server' => $server, + 'engine' => $server->{'engine'}, 'fh' => $fh, 'mux' => $server->{'mux'}, 'data' => '' }, $class); @@ -127,26 +135,29 @@ sub send_response($$) { my ($self, $response) = @_; + $response->message(status_message($response->code())) + unless $response->message(); $self->{'mux'}->write($self->{'fh'}, $response->as_string); $self->{'server'}->{'responses'} += 1; - $self->{'server'}->log($response->as_string, 'Tx| '); + $self->{'server'}->logf("%s %s", $response->code(), $response->message()); } sub shutdown($) { my ($self) = @_; - $self->{'mux'}->shutdown($self->{'fh'}, 1); + $self->{'mux'}->close($self->{'fh'}); } sub mux_input($$$$) { my ($self, $mux, $fh, $data) = @_; + $mux->set_timeout($fh, undef); + # Iterate through the input buffer ($$data) and identify HTTP # messages, one per iteration. Break out of the loop when there # are no complete HTTP messages left in the buffer, and let # whatever data remains stay in the buffer, as we will get a new # chance to parse it next time we get more data ("mux_input"). - while ($$data =~ /\n\r?\n/) { # If we find a double (CR)LF in the input data, we have at # least a complete header section of a message, so look for @@ -168,6 +179,7 @@ elsif ($data_length < $content_length) { # We only received the first part of an HTTP message, # so break out of loop and wait for more. + $mux->set_timeout($fh, 2); last; } else { @@ -198,6 +210,13 @@ } } +sub mux_timeout($$$) { + my ($self, $mux, $fh) = @_; + + $self->{'mux'}->set_timeout($fh, undef); + $self->{'engine'}->ev_server_timeout($self); +} + sub mux_eof($$$$) { my ($self, $mux, $fh, $data) = @_; From des at projects.linpro.no Mon Aug 13 13:53:10 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 15:53:10 +0200 (CEST) Subject: r1833 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070813135310.C86371EC3F0@projects.linpro.no> Author: des Date: 2007-08-13 15:53:10 +0200 (Mon, 13 Aug 2007) New Revision: 1833 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm Log: Typo in previous commit. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-08-13 13:52:29 UTC (rev 1832) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-08-13 13:53:10 UTC (rev 1833) @@ -82,7 +82,7 @@ $self->{'mux'}->set_callback_object($self, $fh); } $self->{'timeout'} = $timeout; - $self->{'mux'}->set_timeout($fh, $timeout); + $self->{'mux'}->set_timeout($self->{'fh'}, $timeout); $self->{'mux'}->write($self->{'fh'}, $request->as_string); $self->{'requests'} += 1; $self->logf("%s %s %s", $request->method(), $request->uri(), $request->protocol()); From des at projects.linpro.no Mon Aug 13 16:33:46 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 18:33:46 +0200 (CEST) Subject: r1834 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070813163346.737271EC2B2@projects.linpro.no> Author: des Date: 2007-08-13 18:33:46 +0200 (Mon, 13 Aug 2007) New Revision: 1834 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Add set_param() Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-13 13:53:10 UTC (rev 1833) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-13 16:33:46 UTC (rev 1834) @@ -202,6 +202,12 @@ $self->send_command("stop"); } +sub set_param($$$) { + my ($self, $param, $value) = @_; + + $self->send_command('param.set', $param, $value); +} + sub shutdown($) { my ($self) = @_; From des at projects.linpro.no Mon Aug 13 16:34:06 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 18:34:06 +0200 (CEST) Subject: r1835 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070813163406.B287E1EC3F0@projects.linpro.no> Author: des Date: 2007-08-13 18:34:06 +0200 (Mon, 13 Aug 2007) New Revision: 1835 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm Log: Use set_param() to enable VCL tracing Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-13 16:33:46 UTC (rev 1834) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-13 16:34:06 UTC (rev 1835) @@ -88,6 +88,9 @@ $self->run_loop('ev_varnish_command_ok'); } + $varnish->set_param('vcl_trace' => 'on'); + $self->run_loop('ev_varnish_command_ok'); + # Start the child $varnish->start_child(); $self->run_loop('ev_varnish_child_started'); From des at projects.linpro.no Mon Aug 13 16:34:27 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 18:34:27 +0200 (CEST) Subject: r1836 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070813163427.24C211EC2B2@projects.linpro.no> Author: des Date: 2007-08-13 18:34:26 +0200 (Mon, 13 Aug 2007) New Revision: 1836 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm Log: Disable tests which we aren't entirely sure should succeed. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-13 16:34:06 UTC (rev 1835) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-13 16:34:26 UTC (rev 1836) @@ -36,6 +36,10 @@ our $DESCR = "Tests Varnish's ability to correctly pass POST requests" . " to the backend, and their replies back to the client."; +# testGetPOST and testPassPOST are known to fail, and it is not clear +# at this point whether that is a bug or a feature. +our @TESTS = qw(testPipePOST); + our $VCL = < Author: des Date: 2007-08-13 19:58:09 +0200 (Mon, 13 Aug 2007) New Revision: 1837 Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c Log: Readability nit Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2007-08-13 16:34:26 UTC (rev 1836) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2007-08-13 17:58:09 UTC (rev 1837) @@ -135,8 +135,9 @@ if (w->niov == MAX_IOVS) WRK_Flush(w); w->iov[w->niov].iov_base = (void*)(uintptr_t)ptr; - w->iov[w->niov++].iov_len = len; + w->iov[w->niov].iov_len = len; w->liov += len; + w->niov++; return (len); } From des at projects.linpro.no Mon Aug 13 18:00:50 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 20:00:50 +0200 (CEST) Subject: r1838 - trunk/varnish-cache/bin/varnishd Message-ID: <20070813180050.A565A1EC3F0@projects.linpro.no> Author: des Date: 2007-08-13 20:00:50 +0200 (Mon, 13 Aug 2007) New Revision: 1838 Modified: trunk/varnish-cache/bin/varnishd/cache_http.c Log: Correct three bits worth of line noise. This fixes #129. Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-08-13 17:58:09 UTC (rev 1837) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-08-13 18:00:50 UTC (rev 1838) @@ -326,7 +326,7 @@ return (0); if (len == 0) - len = hp->pl_e - hp->pl_e; + len = hp->pl_e - hp->pl_s; if (hp->pl_s + len > hp->pl_e) len = hp->pl_e - hp->pl_s; From des at projects.linpro.no Mon Aug 13 18:30:15 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 20:30:15 +0200 (CEST) Subject: r1839 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070813183015.B5B101EC2B2@projects.linpro.no> Author: des Date: 2007-08-13 20:30:15 +0200 (Mon, 13 Aug 2007) New Revision: 1839 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm Log: Not all responses have XIDs. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-13 18:00:50 UTC (rev 1838) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-13 18:30:15 UTC (rev 1839) @@ -264,10 +264,6 @@ if $ev eq 'ev_client_timeout'; die "Internal error\n" unless $resp && ref($resp) && $resp->isa('HTTP::Response'); - die "No X-Varnish header\n" - unless (!$resp->header('X-Varnish')); - die "Invalid X-Varnish header\n" - unless ($resp->header('X-Varnish') =~ m/^\d+(?: \d+)?$/); $resp->request($req); return $self->{'cached_response'} = $resp; } @@ -310,6 +306,18 @@ $self->assert_code(200, $resp); } +sub assert_xid($;$) { + my ($self, $resp) = @_; + + $resp = $self->{'cached_response'} + unless defined($resp); + + die "No X-Varnish header\n" + unless (!$resp->header('X-Varnish')); + die "Invalid X-Varnish header\n" + unless ($resp->header('X-Varnish') =~ m/^\d+(?: \d+)?$/); +} + sub assert_cached($;$) { my ($self, $resp) = @_; From des at projects.linpro.no Mon Aug 13 18:31:39 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 20:31:39 +0200 (CEST) Subject: r1840 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070813183139.BAD011EC3F0@projects.linpro.no> Author: des Date: 2007-08-13 20:31:39 +0200 (Mon, 13 Aug 2007) New Revision: 1840 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm Log: Document what seems to be a bug in the framework. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-13 18:30:15 UTC (rev 1839) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-13 18:31:39 UTC (rev 1840) @@ -36,9 +36,14 @@ our $DESCR = "Tests Varnish's ability to correctly pass POST requests" . " to the backend, and their replies back to the client."; -# testGetPOST and testPassPOST are known to fail, and it is not clear -# at this point whether that is a bug or a feature. -our @TESTS = qw(testPipePOST); +# testCachePOST and testPassPOST are known to fail, and it is not +# clear at this point whether that is a bug or a feature. +# +# More interestingly, if you run testPassPOST after testPipePOST, the +# latter receives the Varnish Guru Meditation intended for the former. +# This seems to be a bug in either IO::Multiplex or Varnish::Test. +# +our @TESTS = qw(testPipePOST testCachePOST testPassPOST); our $VCL = < Author: des Date: 2007-08-13 20:36:15 +0200 (Mon, 13 Aug 2007) New Revision: 1841 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm Log: Fix assert_xid() and add assert_no_xid() (useful for piped requests) Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-13 18:31:39 UTC (rev 1840) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-13 18:36:15 UTC (rev 1841) @@ -313,11 +313,21 @@ unless defined($resp); die "No X-Varnish header\n" - unless (!$resp->header('X-Varnish')); + unless (defined($resp->header('X-Varnish'))); die "Invalid X-Varnish header\n" unless ($resp->header('X-Varnish') =~ m/^\d+(?: \d+)?$/); } +sub assert_no_xid($;$) { + my ($self, $resp) = @_; + + $resp = $self->{'cached_response'} + unless defined($resp); + + die "X-Varnish header present where none expected\n" + if (defined($resp->header('X-Varnish'))); +} + sub assert_cached($;$) { my ($self, $resp) = @_; From des at projects.linpro.no Mon Aug 13 18:37:15 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 20:37:15 +0200 (CEST) Subject: r1842 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070813183715.77FDD1EC3F0@projects.linpro.no> Author: des Date: 2007-08-13 20:37:15 +0200 (Mon, 13 Aug 2007) New Revision: 1842 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm Log: Use assert_xid() in testPassPOST(). Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-13 18:36:15 UTC (rev 1841) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/POST.pm 2007-08-13 18:37:15 UTC (rev 1842) @@ -68,6 +68,7 @@ my $client = $self->new_client; $self->post($client, "/pass_me", [], $MAGIC_WORDS); $self->assert_ok(); + $self->assert_xid(); $self->assert_body(qr/\Q$MAGIC_WORDS\E/); return 'OK'; @@ -79,6 +80,7 @@ my $client = $self->new_client; $self->post($client, "/pipe_me", [], $MAGIC_WORDS); $self->assert_ok(); + $self->assert_no_xid(); $self->assert_body(qr/\Q$MAGIC_WORDS\E/); return 'OK'; From des at projects.linpro.no Mon Aug 13 18:37:26 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 20:37:26 +0200 (CEST) Subject: r1843 - trunk/varnish-tools/regress/lib/Varnish/Test/Case Message-ID: <20070813183726.C36531EC2B2@projects.linpro.no> Author: des Date: 2007-08-13 20:37:26 +0200 (Mon, 13 Aug 2007) New Revision: 1843 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm Log: The syntax has changed. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm 2007-08-13 18:37:15 UTC (rev 1842) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case/RePurge.pm 2007-08-13 18:37:26 UTC (rev 1843) @@ -40,10 +40,10 @@ our $VCL = < Author: des Date: 2007-08-13 21:20:58 +0200 (Mon, 13 Aug 2007) New Revision: 1844 Modified: branches/1.1/ branches/1.1/bin/varnishd/cache_http.c branches/1.1/bin/varnishd/cache_pool.c branches/1.1/debian/control Log: Merged revisions 1831-1838 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1831 | ssm | 2007-08-10 16:05:32 +0200 (Fri, 10 Aug 2007) | 1 line Added missing dependency on "libc6-dev | libc-dev" for vcl compilation ........ r1837 | des | 2007-08-13 19:58:09 +0200 (Mon, 13 Aug 2007) | 2 lines Readability nit ........ r1838 | des | 2007-08-13 20:00:50 +0200 (Mon, 13 Aug 2007) | 2 lines Correct three bits worth of line noise. This fixes #129. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838 Modified: branches/1.1/bin/varnishd/cache_http.c =================================================================== --- branches/1.1/bin/varnishd/cache_http.c 2007-08-13 18:37:26 UTC (rev 1843) +++ branches/1.1/bin/varnishd/cache_http.c 2007-08-13 19:20:58 UTC (rev 1844) @@ -326,7 +326,7 @@ return (0); if (len == 0) - len = hp->pl_e - hp->pl_e; + len = hp->pl_e - hp->pl_s; if (hp->pl_s + len > hp->pl_e) len = hp->pl_e - hp->pl_s; Modified: branches/1.1/bin/varnishd/cache_pool.c =================================================================== --- branches/1.1/bin/varnishd/cache_pool.c 2007-08-13 18:37:26 UTC (rev 1843) +++ branches/1.1/bin/varnishd/cache_pool.c 2007-08-13 19:20:58 UTC (rev 1844) @@ -135,8 +135,9 @@ if (w->niov == MAX_IOVS) WRK_Flush(w); w->iov[w->niov].iov_base = (void*)(uintptr_t)ptr; - w->iov[w->niov++].iov_len = len; + w->iov[w->niov].iov_len = len; w->liov += len; + w->niov++; return (len); } Modified: branches/1.1/debian/control =================================================================== --- branches/1.1/debian/control 2007-08-13 18:37:26 UTC (rev 1843) +++ branches/1.1/debian/control 2007-08-13 19:20:58 UTC (rev 1844) @@ -8,7 +8,7 @@ Package: varnish Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, gcc ( >= 3.3), libvarnish +Depends: ${shlibs:Depends}, ${misc:Depends}, gcc ( >= 3.3), libvarnish, libc6-dev | libc-dev 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 From des at projects.linpro.no Mon Aug 13 19:39:13 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 13 Aug 2007 21:39:13 +0200 (CEST) Subject: r1845 - trunk/varnish-doc/en/inside-varnish Message-ID: <20070813193913.06DC61EC2B2@projects.linpro.no> Author: des Date: 2007-08-13 21:39:12 +0200 (Mon, 13 Aug 2007) New Revision: 1845 Modified: trunk/varnish-doc/en/inside-varnish/article.xml Log: Add (as a comment for now) some information on the shared memory log that phk jotted down in #44. Modified: trunk/varnish-doc/en/inside-varnish/article.xml =================================================================== --- trunk/varnish-doc/en/inside-varnish/article.xml 2007-08-13 19:20:58 UTC (rev 1844) +++ trunk/varnish-doc/en/inside-varnish/article.xml 2007-08-13 19:39:12 UTC (rev 1845) @@ -258,6 +258,33 @@ requested operation. The status code 400 indicates a communications error. + +
+ The shared memory log + + + Lorem ipsum dolor sit amet +
From ingvar at projects.linpro.no Tue Aug 14 21:57:59 2007 From: ingvar at projects.linpro.no (ingvar at projects.linpro.no) Date: Tue, 14 Aug 2007 23:57:59 +0200 (CEST) Subject: r1846 - trunk/varnish-cache/redhat Message-ID: <20070814215759.437631EC2AE@projects.linpro.no> Author: ingvar Date: 2007-08-14 23:57:58 +0200 (Tue, 14 Aug 2007) New Revision: 1846 Modified: trunk/varnish-cache/redhat/varnish.spec trunk/varnish-cache/redhat/varnish.sysconfig Log: * Tue Aug 14 2007 Ingvar Hagelund - 1.1.svn - Update for 1.1 branch - Added the devel package for the header files and static library files - Added a varnish user, and fixed the init script accordingly Modified: trunk/varnish-cache/redhat/varnish.spec =================================================================== --- trunk/varnish-cache/redhat/varnish.spec 2007-08-13 19:39:12 UTC (rev 1845) +++ trunk/varnish-cache/redhat/varnish.spec 2007-08-14 21:57:58 UTC (rev 1846) @@ -1,7 +1,7 @@ Summary: Varnish is a high-performance HTTP accelerator Name: varnish -Version: 1.0.svn -Release: 20070529%{?dist} +Version: 1.1.svn +Release: 200708142344%{?dist} License: BSD-like Group: System Environment/Daemons URL: http://www.varnish-cache.org/ @@ -10,6 +10,7 @@ BuildRequires: ncurses-devel Requires: kernel >= 2.6.0 varnish-libs = %{version}-%{release} Requires: logrotate +Requires(pre): shadow-utils Requires(post): /sbin/chkconfig Requires(preun): /sbin/chkconfig Requires(preun): /sbin/service @@ -34,17 +35,16 @@ Libraries for %{name}. Varnish is a high-performance HTTP accelerator. -## Removed the -devel package for now -#%package devel -#Summary: Development libraries for %{name} -#Group: System Environment/Libraries -#BuildRequires: ncurses-devel -#Requires: kernel >= 2.6.0 varnish-libs = %{version}-%{release} -# -#%description devel -#Development libraries for %{name}. -#Varnish is a high-performance HTTP accelerator +%package libs-devel +Summary: Development files for %{name}-libs +Group: System Environment/Libraries +BuildRequires: ncurses-devel +Requires: kernel >= 2.6.0 varnish-libs = %{version}-%{release} +%description libs-devel +Development files for %{name}-libs +Varnish is a high-performance HTTP accelerator + %prep %setup -q @@ -55,8 +55,7 @@ %build # Remove "--disable static" if you want to build static libraries -# (ie for the devel package) -%configure --disable-static +%configure --disable-static --localstatedir=/var/lib # We have to remove rpath - not allowed in Fedora # (This problem only visible on 64 bit arches) @@ -82,8 +81,8 @@ # None of these for fedora find %{buildroot}/%{_libdir}/ -name '*.la' -exec rm -f {} ';' -# Remove this line to build the devel package -find %{buildroot}/%{_libdir}/ -name '*.so' -type l -exec rm -f {} ';' +# Remove this line to build a devel package with symlinks +#find %{buildroot}/%{_libdir}/ -name '*.so' -type l -exec rm -f {} ';' mkdir -p %{buildroot}/var/lib/varnish mkdir -p %{buildroot}/var/log/varnish @@ -118,13 +117,30 @@ %{_libdir}/*.so.* %doc LICENSE -## Removed the -devel package for now -#%files devel -#%defattr(-,root,root,-) -#%{_libdir}/libvarnish.so -#%{_libdir}/libvarnishapi.so -#%{_libdir}/libvcl.so +%files libs-devel +%defattr(-,root,root,-) +%{_libdir}/libvarnish.so +%{_libdir}/libvarnishapi.so +%{_libdir}/libvcl.so +%{_includedir}/varnish/shmlog.h +%{_includedir}/varnish/shmlog_tags.h +%{_includedir}/varnish/stat_field.h +%{_includedir}/varnish/stats.h +%{_includedir}/varnish/varnishapi.h +%{_libdir}/pkgconfig/varnishapi.pc +#%{_libdir}/libvarnish.a +#%{_libdir}/libvarnishapi.a +#%{_libdir}/libvarnishcompat.a +#%{_libdir}/libvcl.a +%doc LICENSE +%pre +getent group varnish >/dev/null || groupadd -r varnish +getent passwd varnish >/dev/null || \ +useradd -r -g varnish -d /var/lib/varnish -s /sbin/nologin \ + -c "Varnish http accelerator user" varnish +exit 0 + %post /sbin/chkconfig --add varnish /sbin/chkconfig --add varnishlog @@ -148,6 +164,11 @@ %postun libs -p /sbin/ldconfig %changelog +* Tue Aug 14 2007 Ingvar Hagelund - 1.1.svn +- Update for 1.1 branch +- Added the devel package for the header files and static library files +- Added a varnish user, and fixed the init script accordingly + * Mon May 28 2007 Ingvar Hagelund - 1.0.4-3 - Fixed initrc-script bug only visible on el4 (fixes #107) Modified: trunk/varnish-cache/redhat/varnish.sysconfig =================================================================== --- trunk/varnish-cache/redhat/varnish.sysconfig 2007-08-13 19:39:12 UTC (rev 1845) +++ trunk/varnish-cache/redhat/varnish.sysconfig 2007-08-14 21:57:58 UTC (rev 1846) @@ -17,6 +17,7 @@ #DAEMON_OPTS="-a :6081 \ # -T localhost:6082 \ # -b localhost:8080 \ +# -u varnish -g 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 \ + -u varnish -g varnish \ -s file,/var/lib/varnish/varnish_storage.bin,1G" @@ -78,6 +80,7 @@ # -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \ # -t ${VARNISH_TTL} \ # -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \ +# -u varnish -g varnish \ # -s ${VARNISH_STORAGE}" # From knutroy at projects.linpro.no Wed Aug 15 08:28:58 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Wed, 15 Aug 2007 10:28:58 +0200 (CEST) Subject: r1847 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070815082858.9768C1EC3F0@projects.linpro.no> Author: knutroy Date: 2007-08-15 10:28:58 +0200 (Wed, 15 Aug 2007) New Revision: 1847 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm Log: * Added handling of event handlers using die(), by queuing "die" events. * Issue warning when IO::Multiplex has been subject to die() which where not caught and queued. (This is known to happen e.g. when hitting die() in Varnish::Test::Server::Connection::mux_eof(), so a more complete, long-term die()-wrapping solution is needed.) Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-08-14 21:57:58 UTC (rev 1846) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-08-15 08:28:58 UTC (rev 1847) @@ -111,12 +111,22 @@ eval { $self->{'mux'}->loop; }; delete $self->{'in_loop'}; delete $self->{'wait_for'}; - die $@ if ($@); + if ($@) { + $self->log($self, 'ENG: ', 'IO::Multiplex INCONSISTENT AFTER UNCONTROLLED die().'); + # Maybe we should just exit() here, since we cannot do much + # useful with an inconsistent IO::Multiplex object. + die $@; + } # Loop has now been paused due to the occurrence of an event we - # were waiting for. This event is always found in the front of the - # pending events queue at this point, so return it. - return @{shift @{$self->{'pending'}}} if @{$self->{'pending'}} > 0; + # were waiting for, or a controlled die(). The event is always + # found in the front of the pending events queue at this point, so + # return it, or die() if we find a "die event". + if (@{$self->{'pending'}} > 0) { + my ($event, @args) = @{shift @{$self->{'pending'}}}; + die $args[0] if ($event eq 'die'); + return ($event, @args); + } # Hm... we should usually not reach this point. The pending queue # is empty. Either someone (erroneously) requested a loop pause by @@ -153,14 +163,26 @@ $self->log($self, 'ENG: ', sprintf('EVENT "%s"', $1)); - # Check to see if the active case object defines an event handler - # for this event. If so, call it and bring the event arguments - # along. This will also replace @args, which is significant if - # this event will pause and return. - @args = $self->{'case'}->$event(@args) - if (defined($self->{'case'}) and $self->{'case'}->can($event)); - - if (@{$self->{'pending'}} > 0) { + eval { + # Check to see if the active case object defines an event + # handler for this event. If so, call it and bring the event + # arguments along. This will also replace @args, which is + # significant if this event will pause and return. + @args = $self->{'case'}->$event(@args) + if (defined($self->{'case'}) and $self->{'case'}->can($event)); + }; + if ($@) { + # The event handler issued die(), which we want to control + # because we do not want the IO::Multiplex-loop to be subject + # to it. Hence, we queue it as a special event which will be + # recognized outside the loop and reissued there, using die(). + # We put this die-event in the front of the queue, using + # "unshift", so we get it through before any other events + # already in the queue. Then, signal pause of loop. + unshift(@{$self->{'pending'}}, [ 'die', $@ ]); + $self->{'mux'}->endloop; + } + elsif (@{$self->{'pending'}} > 0) { # Pending event queue is NOT empty, meaning this is an event # arriving after a pausing (wait_for) event, but before the # pause is in effect. We queue this event unconditionally From des at projects.linpro.no Wed Aug 15 12:27:55 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 15 Aug 2007 14:27:55 +0200 (CEST) Subject: r1848 - trunk/varnish-tools/regress/lib/Varnish/Test/Report Message-ID: <20070815122755.2468B1EC2AE@projects.linpro.no> Author: des Date: 2007-08-15 14:27:54 +0200 (Wed, 15 Aug 2007) New Revision: 1848 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html Log: Show elapsed time in milliseconds instead of microseconds, and shrink some columns to give the test description more space. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html 2007-08-15 08:28:58 UTC (rev 1847) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html 2007-08-15 12:27:54 UTC (rev 1848) @@ -11,15 +11,15 @@ thead, tfoot { background-color: #eeeeff; } tr.pass { background-color: #eeffee; } tr.fail { background-color: #ffeeee; } -.name { width: 15%; } +.name { width: 10%; } .count { width: 5%; } .pass { width: 5%; } .fail { width: 5%; } -.time { width: 10%; } -.descr { width: 60%; } +.time { width: 5%; text-align: right; } +.descr { width: 70%; } - +

Varnish test report

@@ -43,7 +43,7 @@ - + @@ -53,7 +53,7 @@ - + From des at projects.linpro.no Thu Aug 16 06:52:11 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 16 Aug 2007 08:52:11 +0200 (CEST) Subject: r1849 - in branches/1.1: . redhat Message-ID: <20070816065211.374B81EC2BA@projects.linpro.no> Author: des Date: 2007-08-16 08:52:08 +0200 (Thu, 16 Aug 2007) New Revision: 1849 Modified: branches/1.1/ branches/1.1/redhat/varnish.spec branches/1.1/redhat/varnish.sysconfig Log: Merged revisions 1846 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1846 | ingvar | 2007-08-14 23:57:58 +0200 (Tue, 14 Aug 2007) | 6 lines * Tue Aug 14 2007 Ingvar Hagelund - 1.1.svn - Update for 1.1 branch - Added the devel package for the header files and static library files - Added a varnish user, and fixed the init script accordingly ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846 Modified: branches/1.1/redhat/varnish.spec =================================================================== --- branches/1.1/redhat/varnish.spec 2007-08-15 12:27:54 UTC (rev 1848) +++ branches/1.1/redhat/varnish.spec 2007-08-16 06:52:08 UTC (rev 1849) @@ -10,6 +10,7 @@ BuildRequires: ncurses-devel Requires: kernel >= 2.6.0 varnish-libs = %{version}-%{release} Requires: logrotate +Requires(pre): shadow-utils Requires(post): /sbin/chkconfig Requires(preun): /sbin/chkconfig Requires(preun): /sbin/service @@ -34,17 +35,16 @@ Libraries for %{name}. Varnish is a high-performance HTTP accelerator. -## Removed the -devel package for now -#%package devel -#Summary: Development libraries for %{name} -#Group: System Environment/Libraries -#BuildRequires: ncurses-devel -#Requires: kernel >= 2.6.0 varnish-libs = %{version}-%{release} -# -#%description devel -#Development libraries for %{name}. -#Varnish is a high-performance HTTP accelerator +%package libs-devel +Summary: Development files for %{name}-libs +Group: System Environment/Libraries +BuildRequires: ncurses-devel +Requires: kernel >= 2.6.0 varnish-libs = %{version}-%{release} +%description libs-devel +Development files for %{name}-libs +Varnish is a high-performance HTTP accelerator + %prep %setup -q @@ -55,8 +55,7 @@ %build # Remove "--disable static" if you want to build static libraries -# (ie for the devel package) -%configure --disable-static +%configure --disable-static --localstatedir=/var/lib # We have to remove rpath - not allowed in Fedora # (This problem only visible on 64 bit arches) @@ -82,8 +81,8 @@ # None of these for fedora find %{buildroot}/%{_libdir}/ -name '*.la' -exec rm -f {} ';' -# Remove this line to build the devel package -find %{buildroot}/%{_libdir}/ -name '*.so' -type l -exec rm -f {} ';' +# Remove this line to build a devel package with symlinks +#find %{buildroot}/%{_libdir}/ -name '*.so' -type l -exec rm -f {} ';' mkdir -p %{buildroot}/var/lib/varnish mkdir -p %{buildroot}/var/log/varnish @@ -118,13 +117,30 @@ %{_libdir}/*.so.* %doc LICENSE -## Removed the -devel package for now -#%files devel -#%defattr(-,root,root,-) -#%{_libdir}/libvarnish.so -#%{_libdir}/libvarnishapi.so -#%{_libdir}/libvcl.so +%files libs-devel +%defattr(-,root,root,-) +%{_libdir}/libvarnish.so +%{_libdir}/libvarnishapi.so +%{_libdir}/libvcl.so +%{_includedir}/varnish/shmlog.h +%{_includedir}/varnish/shmlog_tags.h +%{_includedir}/varnish/stat_field.h +%{_includedir}/varnish/stats.h +%{_includedir}/varnish/varnishapi.h +%{_libdir}/pkgconfig/varnishapi.pc +#%{_libdir}/libvarnish.a +#%{_libdir}/libvarnishapi.a +#%{_libdir}/libvarnishcompat.a +#%{_libdir}/libvcl.a +%doc LICENSE +%pre +getent group varnish >/dev/null || groupadd -r varnish +getent passwd varnish >/dev/null || \ +useradd -r -g varnish -d /var/lib/varnish -s /sbin/nologin \ + -c "Varnish http accelerator user" varnish +exit 0 + %post /sbin/chkconfig --add varnish /sbin/chkconfig --add varnishlog @@ -148,9 +164,17 @@ %postun libs -p /sbin/ldconfig %changelog +<<<<<<< .working * Thu Jul 05 2007 Dag-Erling Sm?rgrav - 1.1-1 - Bump Version and Release for 1.1 +======= +* Tue Aug 14 2007 Ingvar Hagelund - 1.1.svn +- Update for 1.1 branch +- Added the devel package for the header files and static library files +- Added a varnish user, and fixed the init script accordingly + +>>>>>>> .merge-right.r1846 * Mon May 28 2007 Ingvar Hagelund - 1.0.4-3 - Fixed initrc-script bug only visible on el4 (fixes #107) Modified: branches/1.1/redhat/varnish.sysconfig =================================================================== --- branches/1.1/redhat/varnish.sysconfig 2007-08-15 12:27:54 UTC (rev 1848) +++ branches/1.1/redhat/varnish.sysconfig 2007-08-16 06:52:08 UTC (rev 1849) @@ -17,6 +17,7 @@ #DAEMON_OPTS="-a :6081 \ # -T localhost:6082 \ # -b localhost:8080 \ +# -u varnish -g 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 \ + -u varnish -g varnish \ -s file,/var/lib/varnish/varnish_storage.bin,1G" @@ -78,6 +80,7 @@ # -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \ # -t ${VARNISH_TTL} \ # -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \ +# -u varnish -g varnish \ # -s ${VARNISH_STORAGE}" # From cecilihf at linpro.no Thu Aug 16 09:27:29 2007 From: cecilihf at linpro.no (Cecilie Fritzvold) Date: Thu, 16 Aug 2007 11:27:29 +0200 Subject: r1830 - in trunk/varnish-cache: bin/varnishd include lib/libvcl In-Reply-To: <20070810102808.DE8951EC2B2@projects.linpro.no> References: <20070810102808.DE8951EC2B2@projects.linpro.no> Message-ID: <46C41881.4040808@linpro.no> phk at projects.linpro.no wrote: > > Modified: > trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Did you modify vcc_gen_fixed_token.tcl for this, but not commit it? -- cecilie.fritzvold at linpro.no Linpro AS http://www.linpro.no From knutroy at projects.linpro.no Thu Aug 16 13:07:55 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Thu, 16 Aug 2007 15:07:55 +0200 (CEST) Subject: r1850 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070816130755.91A3B1EC418@projects.linpro.no> Author: knutroy Date: 2007-08-16 15:07:55 +0200 (Thu, 16 Aug 2007) New Revision: 1850 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.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/Server.pm Log: * Added automatic shutdown of Client-objects used by a test. * Added more diagnostic messages wrt. left-over input data/junk. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-16 06:52:08 UTC (rev 1849) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-16 13:07:55 UTC (rev 1850) @@ -149,6 +149,11 @@ $self->log(sprintf("%d: FAIL: %s: %s", $self->{'count'}, $method, $@)); } + # Make sure all clients have closed their connections. + foreach my $client (@{$self->{'engine'}->{'clients'}}) { + $client->shutdown; + } + @{$self->{'engine'}->{'clients'}} = (); } $self->{'stop'} = [gettimeofday()]; } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-08-16 06:52:08 UTC (rev 1849) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-08-16 13:07:55 UTC (rev 1850) @@ -45,28 +45,33 @@ use IO::Socket::INET; +our $id_seq = 1; + sub new($$) { my ($this, $engine, $attrs) = @_; my $class = ref($this) || $this; my $self = bless({ 'engine' => $engine, 'mux' => $engine->{'mux'}, + 'id' => $id_seq++, 'requests' => 0, 'responses' => 0 }, $class); + push(@{$self->{'engine'}->{'clients'}}, $self); + return $self; } sub log($$;$) { my ($self, $str, $extra_prefix) = @_; - $self->{'engine'}->log($self, 'CLI: ' . ($extra_prefix || ''), $str); + $self->{'engine'}->log($self, sprintf('CLI[%d]: ', $self->{'id'}) . ($extra_prefix || ''), $str); } sub logf($$;@) { my ($self, $fmt, @args) = @_; - $self->{'engine'}->log($self, 'CLI: ', sprintf($fmt, @args)); + $self->{'engine'}->log($self, sprintf('CLI[%d]: ', $self->{'id'}), sprintf($fmt, @args)); } sub send_request($$;$) { @@ -97,10 +102,21 @@ } sub shutdown($) { - my ($self, $how) = @_; + my ($self) = @_; - $self->{'mux'}->close($self->{'fh'}); - $self->{'fh'} = undef; + if (defined($self->{'fh'})) { + my $inbuffer = $self->{'mux'}->inbuffer($self->{'fh'}); + + if ($inbuffer ne '') { + use Data::Dumper; + + $self->log('Discarding: ' . Dumper(\$inbuffer)); + $self->{'mux'}->inbuffer($self->{'fh'}, ''); + } + + $self->{'mux'}->close($self->{'fh'}); + $self->{'fh'} = undef; + } } sub mux_input($$$$) { @@ -204,7 +220,7 @@ sub mux_close($$) { my ($self, $mux, $fh) = @_; - delete $self->{'fh'}; + $self->{'fh'} = undef; } 1; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-08-16 06:52:08 UTC (rev 1849) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-08-16 13:07:55 UTC (rev 1850) @@ -66,6 +66,7 @@ my $self = bless({ 'mux' => IO::Multiplex->new, 'controller' => $controller, 'config' => \%config, + 'clients' => [], 'pending' => [] }, $class); $self->{'server'} = Varnish::Test::Server->new($self); Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-08-16 06:52:08 UTC (rev 1849) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-08-16 13:07:55 UTC (rev 1850) @@ -145,6 +145,15 @@ sub shutdown($) { my ($self) = @_; + my $inbuffer = $self->{'mux'}->inbuffer($self->{'fh'}); + + if ($inbuffer ne '') { + use Data::Dumper; + + $self->{'server'}->log('Junk or incomplete request. Discarding: ' . Dumper(\$inbuffer)); + $self->{'mux'}->inbuffer($self->{'fh'}, ''); + } + $self->{'mux'}->close($self->{'fh'}); } @@ -224,8 +233,12 @@ # of request, so if there is anything left in input buffer, it # must be incomplete because "mux_input" left it there. - die "Junk or incomplete request\n" - unless $$data eq ''; + if ($$data ne '') { + use Data::Dumper; + + $self->{'server'}->log('Junk or incomplete request. Discarding: ' . Dumper($data)); + $$data = ''; + } } 1; From des at linpro.no Thu Aug 16 13:16:19 2007 From: des at linpro.no (=?iso-8859-1?Q?Dag-Erling_Sm=F8rgrav?=) Date: Thu, 16 Aug 2007 15:16:19 +0200 Subject: r1850 - trunk/varnish-tools/regress/lib/Varnish/Test In-Reply-To: <20070816130755.91A3B1EC418@projects.linpro.no> (knutroy@projects.linpro.no's message of "Thu, 16 Aug 2007 15:07:55 +0200 (CEST)") References: <20070816130755.91A3B1EC418@projects.linpro.no> Message-ID: knutroy at projects.linpro.no writes: > Log: > * Added automatic shutdown of Client-objects used by a test. > * Added more diagnostic messages wrt. left-over input data/junk. Thanks, just one nit: > @@ -145,6 +145,15 @@ > sub shutdown($) { > my ($self) = @_; > > + my $inbuffer = $self->{'mux'}->inbuffer($self->{'fh'}); > + > + if ($inbuffer ne '') { > + use Data::Dumper; > + > + $self->{'server'}->log('Junk or incomplete request. Discarding: ' . Dumper(\$inbuffer)); > + $self->{'mux'}->inbuffer($self->{'fh'}, ''); > + } > + > $self->{'mux'}->close($self->{'fh'}); > } > > @@ -224,8 +233,12 @@ > # of request, so if there is anything left in input buffer, it > # must be incomplete because "mux_input" left it there. > > - die "Junk or incomplete request\n" > - unless $$data eq ''; > + if ($$data ne '') { > + use Data::Dumper; > + > + $self->{'server'}->log('Junk or incomplete request. Discarding: ' . Dumper($data)); > + $$data = ''; > + } > } might as well move use Data::Dumper to the top of the package... DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From knutroy at projects.linpro.no Fri Aug 17 12:23:46 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Fri, 17 Aug 2007 14:23:46 +0200 (CEST) Subject: r1851 - in trunk/varnish-tools/regress/lib/Varnish/Test: . Report Message-ID: <20070817122346.277011EC3F0@projects.linpro.no> Author: knutroy Date: 2007-08-17 14:23:45 +0200 (Fri, 17 Aug 2007) New Revision: 1851 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html Log: * Work-around for VCL-loading issue (apparently a race condition somewhere). Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-16 13:07:55 UTC (rev 1850) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-17 12:23:45 UTC (rev 1851) @@ -83,7 +83,11 @@ my $vcl = $varnish->backend_block('main') . ${ref($self)."::VCL"}; $varnish->send_vcl(ref($self), $vcl); - $self->run_loop('ev_varnish_command_ok'); + my ($ev, $resp) = $self->run_loop('ev_varnish_command_ok', 'ev_varnish_command_unknown'); + if ($ev eq 'ev_varnish_command_unknown') { + $self->{'failed'} += 1; + die "Unable to load VCL.\n" + } $varnish->use_vcl(ref($self)); $self->run_loop('ev_varnish_command_ok'); } @@ -182,7 +186,9 @@ 'count' => $self->{'count'}, 'pass' => $self->{'successful'}, 'fail' => $self->{'failed'}, - 'time' => tv_interval($self->{'start'}, $self->{'stop'}), + 'time' => ((defined($self->{'start'}) and defined($self->{'stop'})) + ? tv_interval($self->{'start'}, $self->{'stop'}) + : 0), }; } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html 2007-08-16 13:07:55 UTC (rev 1850) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Report/report.html 2007-08-17 12:23:45 UTC (rev 1851) @@ -34,7 +34,7 @@ - + From knutroy at projects.linpro.no Fri Aug 17 12:30:58 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Fri, 17 Aug 2007 14:30:58 +0200 (CEST) Subject: r1852 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070817123058.38CFF1EC2AE@projects.linpro.no> Author: knutroy Date: 2007-08-17 14:30:58 +0200 (Fri, 17 Aug 2007) New Revision: 1852 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm Log: * Use CRLF EOL-markers. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-08-17 12:23:45 UTC (rev 1851) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-08-17 12:30:58 UTC (rev 1852) @@ -88,7 +88,7 @@ } $self->{'timeout'} = $timeout; $self->{'mux'}->set_timeout($self->{'fh'}, $timeout); - $self->{'mux'}->write($self->{'fh'}, $request->as_string); + $self->{'mux'}->write($self->{'fh'}, $request->as_string("\r\n")); $self->{'requests'} += 1; $self->logf("%s %s %s", $request->method(), $request->uri(), $request->protocol()); } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-08-17 12:23:45 UTC (rev 1851) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-08-17 12:30:58 UTC (rev 1852) @@ -137,7 +137,7 @@ $response->message(status_message($response->code())) unless $response->message(); - $self->{'mux'}->write($self->{'fh'}, $response->as_string); + $self->{'mux'}->write($self->{'fh'}, $response->as_string("\r\n")); $self->{'server'}->{'responses'} += 1; $self->{'server'}->logf("%s %s", $response->code(), $response->message()); } From des at projects.linpro.no Sun Aug 19 17:17:58 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sun, 19 Aug 2007 19:17:58 +0200 (CEST) Subject: r1853 - trunk/varnish-cache/bin/varnishadm Message-ID: <20070819171758.DEE081EC6E9@projects.linpro.no> Author: des Date: 2007-08-19 19:17:58 +0200 (Sun, 19 Aug 2007) New Revision: 1853 Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c Log: Whitespace cleanup Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.c 2007-08-17 12:30:58 UTC (rev 1852) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.c 2007-08-19 17:17:58 UTC (rev 1853) @@ -56,7 +56,7 @@ char *answer = NULL; char buf[13]; char *p, *pp; - + XXXAZ(VSS_parse(T_arg, &addr, &port)); XXXAN(n = VSS_resolve(addr, port, &ta)); free(addr); @@ -65,22 +65,22 @@ fprintf(stderr, "Could not open TELNET port\n"); exit(2); } - + sock = VSS_connect(ta[0]); - + for (i = 0; i < n; ++i) { free(ta[i]); ta[i] = NULL; } free(ta); - + for (i=0; i 0) write(sock, " ", 1); write(sock, argv[i], strlen(argv[i])); } write(sock, "\n", 1); - + n = read(sock, buf, 13); if (n != 13) { fprintf(stderr, "An error occured in receiving status.\n"); @@ -99,7 +99,7 @@ } *p = '\0'; bytes = strtol(pp, &p, 10); - + answer = malloc(bytes+1); n = read(sock, answer, bytes); if (n != bytes) { @@ -108,14 +108,14 @@ } answer[bytes] = '\0'; close(sock); - + if (status == STATUS_OK) { printf("%s\n", answer); exit(0); } fprintf(stderr, "Command failed with error code %ld\n", status); exit(1); - + } static void @@ -131,7 +131,7 @@ int c; const char *address = NULL; int T_arg = 0; - + if (argc < 2) usage(); @@ -145,12 +145,12 @@ usage(); } } - + if (T_arg) { if (optind == argc) usage(); telnet_mgt(address, argc - optind, &argv[optind]); } - + exit(0); } From des at projects.linpro.no Sun Aug 19 17:26:45 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sun, 19 Aug 2007 19:26:45 +0200 (CEST) Subject: r1854 - trunk/varnish-cache/bin/varnishadm Message-ID: <20070819172645.3C8461EC418@projects.linpro.no> Author: des Date: 2007-08-19 19:26:45 +0200 (Sun, 19 Aug 2007) New Revision: 1854 Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.1 trunk/varnish-cache/bin/varnishadm/varnishadm.c Log: Improve style. Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.1 =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.1 2007-08-19 17:17:58 UTC (rev 1853) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.1 2007-08-19 17:26:45 UTC (rev 1854) @@ -28,45 +28,36 @@ .\" .\" $Id$ .\" -.Dd June 06, 2007 +.Dd August 19, 2007 .Dt VARNISHADM 1 .Os .Sh NAME .Nm varnishadm .Sh SYNOPSIS .Nm -.Fl T Ar address:port +.Fl T Ar address:port +.Cm Ar command +.Op Ar ... .Sh DESCRIPTION The .Nm -utility sends the given command to the +utility sends the given command and arguments to the .Xr varnishd 1 -instance at address:port and prints the results. 0 is returned on success, 1 -on failure. +instance at address:port and prints the results. .Pp The following options are available: .Bl -tag -width Fl .It Fl T Ar address:port -Connect via telnet to this address and port. -.Sh EXAMPLES -The following command lists all available commands provided by the -management interface of -.Ed -.Xr varnishd 1 -.Bd -literal -offset 4n -$ varnishadm -T 127.0.0.1:23 help -.Ed +Connect to the management interface at the specified address and port. +.El +.Sh EXIT STATUS +The exit status of the +.Nm +utility is zero if the command succeeded, and non-zero otherwise. .Sh SEE ALSO -.Xr varnishd 1 , -.Xr varnishhist 1 , -.Xr varnishncsa 1 , -.Xr varnishstat 1 , -.Xr varnishtop 1 +.Xr varnishd 1 .Sh HISTORY The .Nm -utility was developed by +utility and this manual page were written by .An Cecilie Fritzvold Aq cecilihf at linpro.no . - -This manual page was written by -.An Cecilie Fritzvold Aq cecilihf at linpro.no . Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.c 2007-08-19 17:17:58 UTC (rev 1853) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.c 2007-08-19 17:26:45 UTC (rev 1854) @@ -46,12 +46,12 @@ * returned */ static void -telnet_mgt(const char* T_arg, int argc, char* argv[]) +telnet_mgt(const char *T_arg, int argc, char *argv[]) { struct vss_addr **ta; char *addr, *port; int i, n; - int sock; + int sock; long status, bytes; char *answer = NULL; char buf[13]; @@ -62,11 +62,11 @@ free(addr); free(port); if (n == 0) { - fprintf(stderr, "Could not open TELNET port\n"); + fprintf(stderr, "Could not resolve '%s'\n", T_arg); exit(2); } - sock = VSS_connect(ta[0]); + sock = VSS_connect(ta[0]); for (i = 0; i < n; ++i) { free(ta[i]); @@ -121,36 +121,34 @@ static void usage(void) { - fprintf(stderr, "usage: varnishadm -T address:port \n"); + fprintf(stderr, + "usage: varnishadm -T [address]:port command [...]\n"); exit(1); } int main(int argc, char *argv[]) { - int c; - const char *address = NULL; - int T_arg = 0; + const char *T_arg = NULL; + int opt; - if (argc < 2) - usage(); - - while ((c = getopt(argc, argv, "T:")) != -1) { - switch (c) { + while ((opt = getopt(argc, argv, "T:")) != -1) { + switch (opt) { case 'T': - T_arg = 1; - address = optarg; + T_arg = optarg; break; default: usage(); } } - if (T_arg) { - if (optind == argc) - usage(); - telnet_mgt(address, argc - optind, &argv[optind]); - } + argc -= optind; + argv += optind; + if (T_arg == NULL || argc < 1) + usage(); + + telnet_mgt(T_arg, argc, argv); + exit(0); } From des at projects.linpro.no Sun Aug 19 18:12:04 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sun, 19 Aug 2007 20:12:04 +0200 (CEST) Subject: r1855 - trunk/varnish-cache/bin/varnishd Message-ID: <20070819181204.8456E1EC404@projects.linpro.no> Author: des Date: 2007-08-19 20:12:03 +0200 (Sun, 19 Aug 2007) New Revision: 1855 Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c Log: Restructure mgt_cli_callback(), and add comments to make it clear what's going on. Also take care of a bug where strchr() was used on a non-NUL- terminated buffer. This fixes #134. Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-08-19 17:26:45 UTC (rev 1854) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-08-19 18:12:03 UTC (rev 1855) @@ -284,8 +284,8 @@ int fdo; int verbose; char *buf; - unsigned nbuf; - unsigned lbuf; + int nbuf; /* next free position in buf */ + int lbuf; /* length of buf */ struct cli cli[1]; char name[30]; }; @@ -294,39 +294,53 @@ mgt_cli_callback(struct ev *e, int what) { struct cli_port *cp; - char *p; + char *p, *q; int i; CAST_OBJ_NOTNULL(cp, e->priv, CLI_PORT_MAGIC); - while (!(what & (EV_ERR | EV_HUP))) { - if (cp->nbuf == cp->lbuf) { - cp->lbuf += cp->lbuf; - cp->buf = realloc(cp->buf, cp->lbuf); - XXXAN(cp->buf); - } - i = read(cp->fdi, cp->buf + cp->nbuf, cp->lbuf - cp->nbuf); - if (i <= 0) - break; - cp->nbuf += i; - p = strchr(cp->buf, '\n'); - if (p == NULL) - return (0); - *p = '\0'; - fprintf(stderr, "CLI <%s>\n", cp->buf); + if (what & (EV_ERR | EV_HUP)) + goto cli_close; + + /* grow the buffer if it is full */ + if (cp->nbuf == cp->lbuf) { + cp->lbuf += cp->lbuf; + cp->buf = realloc(cp->buf, cp->lbuf); + XXXAN(cp->buf); + } + + /* read more data into the buffer */ + i = read(cp->fdi, cp->buf + cp->nbuf, cp->lbuf - cp->nbuf); + if (i <= 0) + goto cli_close; + cp->nbuf += i; + + for (p = q = cp->buf; q < cp->buf + cp->nbuf; ++q) { + if (*q != '\n') + continue; + /* got a newline == got a command */ + *q = '\0'; vsb_clear(cp->cli->sb); - cli_dispatch(cp->cli, cli_proto, cp->buf); + cli_dispatch(cp->cli, cli_proto, p); vsb_finish(cp->cli->sb); - /* XXX: cp->verbose */ + + /* send the result back */ if (cli_writeres(cp->fdo, cp->cli)) - break; - i = ++p - cp->buf; - assert(i <= cp->nbuf); - if (i < cp->nbuf) - memcpy(cp->buf, p, cp->nbuf - i); - cp->nbuf -= i; - return (0); + goto cli_close; + + /* ready for next command */ + p = q + 1; } + + /* see if there's any data left in the buffer */ + if (p != q) { + assert(q == cp->buf + cp->nbuf); + cp->nbuf -= (p - cp->buf); + memmove(cp->buf, p, cp->nbuf); + } + return (0); + +cli_close: vsb_delete(cp->cli->sb); free(cp->buf); close(cp->fdi); @@ -402,7 +416,7 @@ free(addr); free(port); if (n == 0) { - fprintf(stderr, "Could not open TELNET port\n"); + fprintf(stderr, "Could not open management port\n"); exit(2); } for (i = 0; i < n; ++i) { From des at projects.linpro.no Sun Aug 19 18:13:33 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sun, 19 Aug 2007 20:13:33 +0200 (CEST) Subject: r1856 - in branches/1.1: . bin/varnishadm bin/varnishd Message-ID: <20070819181333.D7DAD1EC404@projects.linpro.no> Author: des Date: 2007-08-19 20:13:33 +0200 (Sun, 19 Aug 2007) New Revision: 1856 Modified: branches/1.1/ branches/1.1/bin/varnishadm/varnishadm.1 branches/1.1/bin/varnishadm/varnishadm.c branches/1.1/bin/varnishd/mgt_cli.c Log: Merged revisions 1853-1855 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1853 | des | 2007-08-19 19:17:58 +0200 (Sun, 19 Aug 2007) | 2 lines Whitespace cleanup ........ r1854 | des | 2007-08-19 19:26:45 +0200 (Sun, 19 Aug 2007) | 2 lines Improve style. ........ r1855 | des | 2007-08-19 20:12:03 +0200 (Sun, 19 Aug 2007) | 4 lines Restructure mgt_cli_callback(), and add comments to make it clear what's going on. Also take care of a bug where strchr() was used on a non-NUL- terminated buffer. This fixes #134. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855 Modified: branches/1.1/bin/varnishadm/varnishadm.1 =================================================================== --- branches/1.1/bin/varnishadm/varnishadm.1 2007-08-19 18:12:03 UTC (rev 1855) +++ branches/1.1/bin/varnishadm/varnishadm.1 2007-08-19 18:13:33 UTC (rev 1856) @@ -28,45 +28,36 @@ .\" .\" $Id$ .\" -.Dd June 06, 2007 +.Dd August 19, 2007 .Dt VARNISHADM 1 .Os .Sh NAME .Nm varnishadm .Sh SYNOPSIS .Nm -.Fl T Ar address:port +.Fl T Ar address:port +.Cm Ar command +.Op Ar ... .Sh DESCRIPTION The .Nm -utility sends the given command to the +utility sends the given command and arguments to the .Xr varnishd 1 -instance at address:port and prints the results. 0 is returned on success, 1 -on failure. +instance at address:port and prints the results. .Pp The following options are available: .Bl -tag -width Fl .It Fl T Ar address:port -Connect via telnet to this address and port. -.Sh EXAMPLES -The following command lists all available commands provided by the -management interface of -.Ed -.Xr varnishd 1 -.Bd -literal -offset 4n -$ varnishadm -T 127.0.0.1:23 help -.Ed +Connect to the management interface at the specified address and port. +.El +.Sh EXIT STATUS +The exit status of the +.Nm +utility is zero if the command succeeded, and non-zero otherwise. .Sh SEE ALSO -.Xr varnishd 1 , -.Xr varnishhist 1 , -.Xr varnishncsa 1 , -.Xr varnishstat 1 , -.Xr varnishtop 1 +.Xr varnishd 1 .Sh HISTORY The .Nm -utility was developed by +utility and this manual page were written by .An Cecilie Fritzvold Aq cecilihf at linpro.no . - -This manual page was written by -.An Cecilie Fritzvold Aq cecilihf at linpro.no . Modified: branches/1.1/bin/varnishadm/varnishadm.c =================================================================== --- branches/1.1/bin/varnishadm/varnishadm.c 2007-08-19 18:12:03 UTC (rev 1855) +++ branches/1.1/bin/varnishadm/varnishadm.c 2007-08-19 18:13:33 UTC (rev 1856) @@ -46,41 +46,41 @@ * returned */ static void -telnet_mgt(const char* T_arg, int argc, char* argv[]) +telnet_mgt(const char *T_arg, int argc, char *argv[]) { struct vss_addr **ta; char *addr, *port; int i, n; - int sock; + int sock; long status, bytes; char *answer = NULL; char buf[13]; char *p, *pp; - + XXXAZ(VSS_parse(T_arg, &addr, &port)); XXXAN(n = VSS_resolve(addr, port, &ta)); free(addr); free(port); if (n == 0) { - fprintf(stderr, "Could not open TELNET port\n"); + fprintf(stderr, "Could not resolve '%s'\n", T_arg); exit(2); } - - sock = VSS_connect(ta[0]); - + + sock = VSS_connect(ta[0]); + for (i = 0; i < n; ++i) { free(ta[i]); ta[i] = NULL; } free(ta); - + for (i=0; i 0) write(sock, " ", 1); write(sock, argv[i], strlen(argv[i])); } write(sock, "\n", 1); - + n = read(sock, buf, 13); if (n != 13) { fprintf(stderr, "An error occured in receiving status.\n"); @@ -99,7 +99,7 @@ } *p = '\0'; bytes = strtol(pp, &p, 10); - + answer = malloc(bytes+1); n = read(sock, answer, bytes); if (n != bytes) { @@ -108,49 +108,47 @@ } answer[bytes] = '\0'; close(sock); - + if (status == STATUS_OK) { printf("%s\n", answer); exit(0); } fprintf(stderr, "Command failed with error code %ld\n", status); exit(1); - + } static void usage(void) { - fprintf(stderr, "usage: varnishadm -T address:port \n"); + fprintf(stderr, + "usage: varnishadm -T [address]:port command [...]\n"); exit(1); } int main(int argc, char *argv[]) { - int c; - const char *address = NULL; - int T_arg = 0; - - if (argc < 2) - usage(); + const char *T_arg = NULL; + int opt; - while ((c = getopt(argc, argv, "T:")) != -1) { - switch (c) { + while ((opt = getopt(argc, argv, "T:")) != -1) { + switch (opt) { case 'T': - T_arg = 1; - address = optarg; + T_arg = optarg; break; default: usage(); } } - - if (T_arg) { - if (optind == argc) - usage(); - telnet_mgt(address, argc - optind, &argv[optind]); - } - + + argc -= optind; + argv += optind; + + if (T_arg == NULL || argc < 1) + usage(); + + telnet_mgt(T_arg, argc, argv); + exit(0); } Modified: branches/1.1/bin/varnishd/mgt_cli.c =================================================================== --- branches/1.1/bin/varnishd/mgt_cli.c 2007-08-19 18:12:03 UTC (rev 1855) +++ branches/1.1/bin/varnishd/mgt_cli.c 2007-08-19 18:13:33 UTC (rev 1856) @@ -284,8 +284,8 @@ int fdo; int verbose; char *buf; - unsigned nbuf; - unsigned lbuf; + int nbuf; /* next free position in buf */ + int lbuf; /* length of buf */ struct cli cli[1]; char name[30]; }; @@ -294,39 +294,53 @@ mgt_cli_callback(struct ev *e, int what) { struct cli_port *cp; - char *p; + char *p, *q; int i; CAST_OBJ_NOTNULL(cp, e->priv, CLI_PORT_MAGIC); - while (!(what & (EV_ERR | EV_HUP))) { - if (cp->nbuf == cp->lbuf) { - cp->lbuf += cp->lbuf; - cp->buf = realloc(cp->buf, cp->lbuf); - XXXAN(cp->buf); - } - i = read(cp->fdi, cp->buf + cp->nbuf, cp->lbuf - cp->nbuf); - if (i <= 0) - break; - cp->nbuf += i; - p = strchr(cp->buf, '\n'); - if (p == NULL) - return (0); - *p = '\0'; - fprintf(stderr, "CLI <%s>\n", cp->buf); + if (what & (EV_ERR | EV_HUP)) + goto cli_close; + + /* grow the buffer if it is full */ + if (cp->nbuf == cp->lbuf) { + cp->lbuf += cp->lbuf; + cp->buf = realloc(cp->buf, cp->lbuf); + XXXAN(cp->buf); + } + + /* read more data into the buffer */ + i = read(cp->fdi, cp->buf + cp->nbuf, cp->lbuf - cp->nbuf); + if (i <= 0) + goto cli_close; + cp->nbuf += i; + + for (p = q = cp->buf; q < cp->buf + cp->nbuf; ++q) { + if (*q != '\n') + continue; + /* got a newline == got a command */ + *q = '\0'; vsb_clear(cp->cli->sb); - cli_dispatch(cp->cli, cli_proto, cp->buf); + cli_dispatch(cp->cli, cli_proto, p); vsb_finish(cp->cli->sb); - /* XXX: cp->verbose */ + + /* send the result back */ if (cli_writeres(cp->fdo, cp->cli)) - break; - i = ++p - cp->buf; - assert(i <= cp->nbuf); - if (i < cp->nbuf) - memcpy(cp->buf, p, cp->nbuf - i); - cp->nbuf -= i; - return (0); + goto cli_close; + + /* ready for next command */ + p = q + 1; } + + /* see if there's any data left in the buffer */ + if (p != q) { + assert(q == cp->buf + cp->nbuf); + cp->nbuf -= (p - cp->buf); + memmove(cp->buf, p, cp->nbuf); + } + return (0); + +cli_close: vsb_delete(cp->cli->sb); free(cp->buf); close(cp->fdi); @@ -402,7 +416,7 @@ free(addr); free(port); if (n == 0) { - fprintf(stderr, "Could not open TELNET port\n"); + fprintf(stderr, "Could not open management port\n"); exit(2); } for (i = 0; i < n; ++i) { From des at projects.linpro.no Sun Aug 19 18:18:11 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sun, 19 Aug 2007 20:18:11 +0200 (CEST) Subject: r1857 - trunk/varnish-cache/bin/varnishd Message-ID: <20070819181811.ED73D1EC2AE@projects.linpro.no> Author: des Date: 2007-08-19 20:18:11 +0200 (Sun, 19 Aug 2007) New Revision: 1857 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c Log: Whitespace cleanup. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-19 18:13:33 UTC (rev 1856) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-19 18:18:11 UTC (rev 1857) @@ -110,7 +110,7 @@ * We have a refcounted object on the session, now deliver it. * DOT subgraph xcluster_deliver { -DOT deliver [ +DOT deliver [ DOT shape=ellipse DOT label="Filter obj.->resp." DOT ] @@ -132,7 +132,7 @@ * 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 @@ -297,7 +297,7 @@ 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 @@ -314,8 +314,8 @@ sp->backend->health--; } } - - + + vbe_free_bereq(sp->bereq); sp->bereq = NULL; @@ -325,7 +325,7 @@ */ 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 */ @@ -422,7 +422,7 @@ 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; @@ -501,7 +501,7 @@ sp->lhashptr = 1; /* space for NUL */ sp->ihashptr = 0; sp->nhashptr = sp->vcl->nhashcount * 2; - p = WS_Alloc(sp->http->ws, + p = WS_Alloc(sp->http->ws, sizeof(const char *) * (sp->nhashptr + 1)); XXXAN(p); u = (uintptr_t)p; @@ -543,7 +543,7 @@ sp->obj = NULL; sp->step = STP_PASS; return (0); - } + } VSL_stats->cache_hit++; WSL(sp->wrk, SLT_Hit, sp->fd, "%u", sp->obj->xid); @@ -675,7 +675,7 @@ DOT label="send bereq.\npipe until close" DOT ] DOT vcl_pipe -> pipe_do [label="pipe"] -DOT pipe -> vcl_pipe +DOT pipe -> vcl_pipe DOT } DOT pipe_do -> DONE DOT vcl_pipe -> err_pipe [label="error"] From phk at projects.linpro.no Sun Aug 19 21:19:47 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 19 Aug 2007 23:19:47 +0200 (CEST) Subject: r1858 - trunk/varnish-cache/bin/varnishd Message-ID: <20070819211947.0C2531EC404@projects.linpro.no> Author: phk Date: 2007-08-19 23:19:46 +0200 (Sun, 19 Aug 2007) New Revision: 1858 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: Feed my virtual whitespace habbit. Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-08-19 18:18:11 UTC (rev 1857) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2007-08-19 21:19:46 UTC (rev 1858) @@ -438,7 +438,6 @@ mcf_server_startstop(struct cli *cli, char **av, void *priv) { - (void)cli; (void)av; if (priv != NULL && child_state == CH_RUNNING) stop_child(); From phk at projects.linpro.no Sun Aug 19 21:20:48 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 19 Aug 2007 23:20:48 +0200 (CEST) Subject: r1859 - trunk/varnish-cache/bin/varnishd Message-ID: <20070819212048.DFD601EC2AE@projects.linpro.no> Author: phk Date: 2007-08-19 23:20:48 +0200 (Sun, 19 Aug 2007) New Revision: 1859 Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c Log: Reset the cli buffer when we have soaked up all it contained. Otherwise we will for ever be repeating the same command over and over, no matter what the input to the cli might be. Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-08-19 21:19:46 UTC (rev 1858) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2007-08-19 21:20:48 UTC (rev 1859) @@ -337,7 +337,8 @@ assert(q == cp->buf + cp->nbuf); cp->nbuf -= (p - cp->buf); memmove(cp->buf, p, cp->nbuf); - } + } else + cp->nbuf = 0; return (0); cli_close: From des at projects.linpro.no Sun Aug 19 21:22:57 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sun, 19 Aug 2007 23:22:57 +0200 (CEST) Subject: r1860 - in branches/1.1: . bin/varnishd Message-ID: <20070819212257.5C8941EC429@projects.linpro.no> Author: des Date: 2007-08-19 23:22:57 +0200 (Sun, 19 Aug 2007) New Revision: 1860 Modified: branches/1.1/ branches/1.1/bin/varnishd/cache_center.c branches/1.1/bin/varnishd/mgt_child.c branches/1.1/bin/varnishd/mgt_cli.c Log: Merged revisions 1857-1859 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1857 | des | 2007-08-19 20:18:11 +0200 (Sun, 19 Aug 2007) | 2 lines Whitespace cleanup. ........ r1858 | phk | 2007-08-19 23:19:46 +0200 (Sun, 19 Aug 2007) | 2 lines Feed my virtual whitespace habbit. ........ r1859 | phk | 2007-08-19 23:20:48 +0200 (Sun, 19 Aug 2007) | 4 lines Reset the cli buffer when we have soaked up all it contained. Otherwise we will for ever be repeating the same command over and over, no matter what the input to the cli might be. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859 Modified: branches/1.1/bin/varnishd/cache_center.c =================================================================== --- branches/1.1/bin/varnishd/cache_center.c 2007-08-19 21:20:48 UTC (rev 1859) +++ branches/1.1/bin/varnishd/cache_center.c 2007-08-19 21:22:57 UTC (rev 1860) @@ -110,7 +110,7 @@ * We have a refcounted object on the session, now deliver it. * DOT subgraph xcluster_deliver { -DOT deliver [ +DOT deliver [ DOT shape=ellipse DOT label="Filter obj.->resp." DOT ] @@ -132,7 +132,7 @@ * 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 @@ -465,7 +465,7 @@ sp->lhashptr = 1; /* space for NUL */ sp->ihashptr = 0; sp->nhashptr = sp->vcl->nhashcount * 2; - p = WS_Alloc(sp->http->ws, + p = WS_Alloc(sp->http->ws, sizeof(const char *) * (sp->nhashptr + 1)); XXXAN(p); u = (uintptr_t)p; @@ -507,7 +507,7 @@ sp->obj = NULL; sp->step = STP_PASS; return (0); - } + } VSL_stats->cache_hit++; WSL(sp->wrk, SLT_Hit, sp->fd, "%u", sp->obj->xid); @@ -639,7 +639,7 @@ DOT label="send bereq.\npipe until close" DOT ] DOT vcl_pipe -> pipe_do [label="pipe"] -DOT pipe -> vcl_pipe +DOT pipe -> vcl_pipe DOT } DOT pipe_do -> DONE DOT vcl_pipe -> err_pipe [label="error"] Modified: branches/1.1/bin/varnishd/mgt_child.c =================================================================== --- branches/1.1/bin/varnishd/mgt_child.c 2007-08-19 21:20:48 UTC (rev 1859) +++ branches/1.1/bin/varnishd/mgt_child.c 2007-08-19 21:22:57 UTC (rev 1860) @@ -438,7 +438,6 @@ mcf_server_startstop(struct cli *cli, char **av, void *priv) { - (void)cli; (void)av; if (priv != NULL && child_state == CH_RUNNING) stop_child(); Modified: branches/1.1/bin/varnishd/mgt_cli.c =================================================================== --- branches/1.1/bin/varnishd/mgt_cli.c 2007-08-19 21:20:48 UTC (rev 1859) +++ branches/1.1/bin/varnishd/mgt_cli.c 2007-08-19 21:22:57 UTC (rev 1860) @@ -337,7 +337,8 @@ assert(q == cp->buf + cp->nbuf); cp->nbuf -= (p - cp->buf); memmove(cp->buf, p, cp->nbuf); - } + } else + cp->nbuf = 0; return (0); cli_close: From des at projects.linpro.no Mon Aug 20 06:57:03 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 08:57:03 +0200 (CEST) Subject: r1861 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070820065703.CD8C71EC2AE@projects.linpro.no> Author: des Date: 2007-08-20 08:57:03 +0200 (Mon, 20 Aug 2007) New Revision: 1861 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Use a TCP connection for management commands, rather than std{in,out,err}, as the latter is polluted with "Child said" and similar messages. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-08-19 21:22:57 UTC (rev 1860) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-08-20 06:57:03 UTC (rev 1861) @@ -57,8 +57,9 @@ my ($this, $controller, %config) = @_; my $class = ref($this) || $this; - %config = ('server_address' => 'localhost:8081', - 'varnish_address' => 'localhost:8080', + %config = ('varnish_address' => 'localhost:8080', + 'server_address' => 'localhost:8081', + 'telnet_address' => 'localhost:8082', 'varnish_name' => 'regress', 'storage_spec' => 'file,regress.bin,512k', %config); Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-19 21:22:57 UTC (rev 1860) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-20 06:57:03 UTC (rev 1861) @@ -47,6 +47,7 @@ use strict; +use IO::Socket::INET; use Socket; sub new($$;$) { @@ -98,7 +99,8 @@ '-s', $engine->{'config'}->{'storage_spec'}, '-n', $engine->{'config'}->{'varnish_name'}, '-a', $engine->{'config'}->{'varnish_address'}, - '-b', $engine->{'config'}->{'server_address'}); + '-b', $engine->{'config'}->{'server_address'}, + '-T', $engine->{'config'}->{'telnet_address'}); print STDERR sprintf("Starting Varnish with options: %s\n", join(' ', @opts)); @@ -133,6 +135,21 @@ $self->{'mux'}->set_callback_object($self, $self->{'stdout'}); $self->{'mux'}->add($self->{'stderr'}); $self->{'mux'}->set_callback_object($self, $self->{'stderr'}); + + # Wait up to 0.5 seconds for Varnish to accept our connection + # on the management port + for (my $i = 0; $i < 5; ++$i) { + last if $self->{'socket'} = IO::Socket::INET-> + new(Type => SOCK_STREAM, + PeerAddr => $engine->{'config'}->{'telnet_address'}); + select(undef, undef, undef, 0.1); + } + if (!defined($self->{'socket'})) { + kill(15, delete $self->{'pid'}); + die "Varnish did not start\n"; + } + $self->{'mux'}->add($self->{'socket'}); + $self->{'mux'}->set_callback_object($self, $self->{'socket'}); } return $self; @@ -166,7 +183,8 @@ } } my $command = join(' ', @args); - $self->{'mux'}->write($self->{'stdin'}, $command . "\n"); + $self->{'mux'}->write($self->{'socket'}, $command . "\n"); + $self->{'mux'}->set_timeout($self->{'socket'}, 2); $self->{'pending'} = $command; } @@ -211,7 +229,16 @@ sub shutdown($) { my ($self) = @_; - $self->{'mux'}->shutdown(delete $self->{'stdin'}, 1); + $self->{'mux'}->close(delete $self->{'stdin'}) + if $self->{'stdin'}; + $self->{'mux'}->close(delete $self->{'stdout'}) + if $self->{'stdout'}; + $self->{'mux'}->close(delete $self->{'stderr'}) + if $self->{'stderr'}; + $self->{'mux'}->close(delete $self->{'socket'}) + if $self->{'socket'}; + kill(15, delete $self->{'pid'}) + if $self->{'pid'}; } sub kill($;$) { @@ -229,26 +256,49 @@ $self->log($$data); - if ($$data =~ /^rolling\(2\)\.\.\./m) { - $self->{'state'} = 'stopped'; - $self->{'engine'}->ev_varnish_started; + $self->{'mux'}->set_timeout($fh, undef); + if ($fh == $self->{'socket'}) { + die "syntax error\n" + unless ($$data =~ m/^([1-5][0-9][0-9]) (\d+) *$/m); + my ($line, $code, $len) = ($&, $1, $2); + if (length($$data) < length($line) + $len) { + # we don't have the full response yet. + $self->{'mux'}->set_timeout($fh, 2); + return; + } + # extract the response text (if any), then remove from $$data + my $text = substr($$data, length($line), $len); + substr($$data, 0, length($line) + $len + 1, ''); + + $self->{'engine'}->ev_varnish_command_ok(delete $self->{'pending'}) + if ($code eq 200 and $self->{'pending'}); + + $self->{'engine'}->ev_varnish_command_unknown(delete $self->{'pending'}) + if ($code eq 300 and $self->{'pending'}); + } else { + if ($$data =~ /^rolling\(2\)\.\.\./m) { + $self->{'state'} = 'stopped'; + $self->{'engine'}->ev_varnish_started; + } + if ($$data =~ /Child starts/) { + $self->{'state'} = 'started'; + $self->{'engine'}->ev_varnish_child_started; + } + if ($$data =~ /Child dies/) { + $self->{'state'} = 'stopped'; + $self->{'engine'}->ev_varnish_child_stopped; + } + # XXX there might be more! + $$data = ''; } - if ($$data =~ /Child starts/) { - $self->{'state'} = 'started'; - $self->{'engine'}->ev_varnish_child_started; - } - if ($$data =~ /Child dies/) { - $self->{'state'} = 'stopped'; - $self->{'engine'}->ev_varnish_child_stopped; - } +} - $self->{'engine'}->ev_varnish_command_ok(delete $self->{'pending'}) - if ($$data =~ /^200 \d+/m and $self->{'pending'}); +sub mux_timeout($$$) { + my ($self, $mux, $fh) = @_; - $self->{'engine'}->ev_varnish_command_unknown(delete $self->{'pending'}) - if ($$data =~ /^300 \d+/m and $self->{'pending'}); - - $$data = ''; + $self->{'mux'}->set_timeout($fh, undef); + $self->shutdown(); + $self->{'engine'}->ev_varnish_timeout($self); } 1; From phk at projects.linpro.no Mon Aug 20 07:35:11 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 09:35:11 +0200 (CEST) Subject: r1862 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820073511.27AED1EC429@projects.linpro.no> Author: phk Date: 2007-08-20 09:35:10 +0200 (Mon, 20 Aug 2007) New Revision: 1862 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c Log: Add more asserts to try to find a cure for #150. Don't nuke t_end timestamp, we need it for StatSess logentry. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-20 06:57:03 UTC (rev 1861) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-20 07:35:10 UTC (rev 1862) @@ -211,12 +211,12 @@ 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); if (sp->fd < 0) { VSL_stats->sess_closed++; + assert(!isnan(sp->wrk->used)); sp->wrk = NULL; vca_return_session(sp); return (1); @@ -233,6 +233,7 @@ return (0); } VSL_stats->sess_herd++; + assert(!isnan(sp->wrk->used)); sp->wrk = NULL; vca_return_session(sp); return (1); @@ -523,6 +524,7 @@ */ WSL(sp->wrk, SLT_Debug, sp->fd, "on waiting list on obj %u", sp->obj->xid); + assert(!isnan(sp->wrk->used)); SES_Charge(sp); return (1); } @@ -822,6 +824,7 @@ if (w->nobjhead != NULL) CHECK_OBJ(w->nobjhead, OBJHEAD_MAGIC); } + assert(!isnan(w->used)); WSL_Flush(w); } From des at projects.linpro.no Mon Aug 20 07:51:03 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 09:51:03 +0200 (CEST) Subject: r1863 - in branches/1.1: . bin/varnishd Message-ID: <20070820075103.698F81EC2B1@projects.linpro.no> Author: des Date: 2007-08-20 09:51:03 +0200 (Mon, 20 Aug 2007) New Revision: 1863 Modified: branches/1.1/ branches/1.1/bin/varnishd/cache_center.c Log: Merged revisions 1862 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1862 | phk | 2007-08-20 09:35:10 +0200 (Mon, 20 Aug 2007) | 5 lines Add more asserts to try to find a cure for #150. Don't nuke t_end timestamp, we need it for StatSess logentry. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862 Modified: branches/1.1/bin/varnishd/cache_center.c =================================================================== --- branches/1.1/bin/varnishd/cache_center.c 2007-08-20 07:35:10 UTC (rev 1862) +++ branches/1.1/bin/varnishd/cache_center.c 2007-08-20 07:51:03 UTC (rev 1863) @@ -211,12 +211,12 @@ 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); if (sp->fd < 0) { VSL_stats->sess_closed++; + assert(!isnan(sp->wrk->used)); sp->wrk = NULL; vca_return_session(sp); return (1); @@ -233,6 +233,7 @@ return (0); } VSL_stats->sess_herd++; + assert(!isnan(sp->wrk->used)); sp->wrk = NULL; vca_return_session(sp); return (1); @@ -487,6 +488,7 @@ */ WSL(sp->wrk, SLT_Debug, sp->fd, "on waiting list on obj %u", sp->obj->xid); + assert(!isnan(sp->wrk->used)); SES_Charge(sp); return (1); } @@ -786,6 +788,7 @@ if (w->nobjhead != NULL) CHECK_OBJ(w->nobjhead, OBJHEAD_MAGIC); } + assert(!isnan(w->used)); WSL_Flush(w); } From des at projects.linpro.no Mon Aug 20 07:56:25 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 09:56:25 +0200 (CEST) Subject: r1864 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070820075625.591C01EC429@projects.linpro.no> Author: des Date: 2007-08-20 09:56:25 +0200 (Mon, 20 Aug 2007) New Revision: 1864 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Change the way the result from a command is reported. Instead of separate ev_varnish_command_ok and ev_varnish_command_unknown events, we now emit a single ev_varnish_result event accompanied by the result code and text. Furthermore, Varnish::Test::Varnish::send_command() will now wait for this event and return the code and text. Note that this reintroduces a race between ev_varnish_child_stopped and ev_varnish_result; this will be dealt with in a later commit. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-20 07:51:03 UTC (rev 1863) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-20 07:56:25 UTC (rev 1864) @@ -72,6 +72,7 @@ sub init($) { my ($self) = @_; + my ($code, $text); $self->{'engine'}->{'case'} = $self; @@ -82,21 +83,26 @@ if (${ref($self)."::VCL"}) { my $vcl = $varnish->backend_block('main') . ${ref($self)."::VCL"}; - $varnish->send_vcl(ref($self), $vcl); - my ($ev, $resp) = $self->run_loop('ev_varnish_command_ok', 'ev_varnish_command_unknown'); - if ($ev eq 'ev_varnish_command_unknown') { + ($code, $text) = $varnish->send_vcl(ref($self), $vcl); + if ($code != 200) { $self->{'failed'} += 1; - die "Unable to load VCL.\n" + die "Unable to load VCL\n"; } - $varnish->use_vcl(ref($self)); - $self->run_loop('ev_varnish_command_ok'); + ($code, $text) = $varnish->use_vcl(ref($self)); + if ($code != 200) { + $self->{'failed'} += 1; + die "Unable to load VCL\n"; + } } $varnish->set_param('vcl_trace' => 'on'); - $self->run_loop('ev_varnish_command_ok'); # Start the child - $varnish->start_child(); + ($code, $text) = $varnish->start_child(); + if ($code != 200) { + $self->{'failed'} += 1; + die "Unable to start child\n"; + } $self->run_loop('ev_varnish_child_started'); } @@ -107,16 +113,13 @@ # Stop the worker process $varnish->stop_child(); - # Wait for both events, the order is unpredictable, so wait for - # any of them both times. - $self->run_loop('ev_varnish_child_stopped', 'ev_varnish_command_ok'); - $self->run_loop('ev_varnish_child_stopped', 'ev_varnish_command_ok'); + $self->run_loop('ev_varnish_child_stopped'); # Revert to initial VCL script no strict 'refs'; if (${ref($self)."::VCL"}) { $varnish->use_vcl('boot'); - $self->run_loop('ev_varnish_command_ok', 'ev_varnish_command_unknown'); + $self->run_loop('ev_varnish_result'); } delete $self->{'engine'}->{'case'}; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-20 07:51:03 UTC (rev 1863) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-20 07:56:25 UTC (rev 1864) @@ -183,21 +183,27 @@ } } my $command = join(' ', @args); + $self->log("sending command: $command"); $self->{'mux'}->write($self->{'socket'}, $command . "\n"); $self->{'mux'}->set_timeout($self->{'socket'}, 2); $self->{'pending'} = $command; + my ($ev, $code, $text) = + $self->{'engine'}->run_loop('ev_varnish_result', + 'ev_varnish_timeout'); + delete $self->{'pending'}; + return ($code, $text); } sub send_vcl($$$) { my ($self, $config, $vcl) = @_; - $self->send_command('vcl.inline', $config, $vcl); + return $self->send_command('vcl.inline', $config, $vcl); } sub use_vcl($$) { my ($self, $config) = @_; - $self->send_command('vcl.use', $config); + return $self->send_command('vcl.use', $config); } sub start_child($) { @@ -207,7 +213,7 @@ die "already started\n" if $self->{'state'} eq "started"; - $self->send_command("start"); + return $self->send_command("start"); } sub stop_child($) { @@ -217,13 +223,13 @@ die "already stopped\n" if $self->{'state'} eq 'stopped'; - $self->send_command("stop"); + return $self->send_command("stop"); } sub set_param($$$) { my ($self, $param, $value) = @_; - $self->send_command('param.set', $param, $value); + return $self->send_command('param.set', $param, $value); } sub shutdown($) { @@ -270,11 +276,7 @@ my $text = substr($$data, length($line), $len); substr($$data, 0, length($line) + $len + 1, ''); - $self->{'engine'}->ev_varnish_command_ok(delete $self->{'pending'}) - if ($code eq 200 and $self->{'pending'}); - - $self->{'engine'}->ev_varnish_command_unknown(delete $self->{'pending'}) - if ($code eq 300 and $self->{'pending'}); + $self->{'engine'}->ev_varnish_result($code, $text); } else { if ($$data =~ /^rolling\(2\)\.\.\./m) { $self->{'state'} = 'stopped'; From bahner at projects.linpro.no Mon Aug 20 08:38:29 2007 From: bahner at projects.linpro.no (bahner at projects.linpro.no) Date: Mon, 20 Aug 2007 10:38:29 +0200 (CEST) Subject: r1865 - trunk/varnish-cache/debian Message-ID: <20070820083829.60C761EC2B1@projects.linpro.no> Author: bahner Date: 2007-08-20 10:38:29 +0200 (Mon, 20 Aug 2007) New Revision: 1865 Modified: trunk/varnish-cache/debian/README.Debian trunk/varnish-cache/debian/changelog trunk/varnish-cache/debian/varnish.default Log: Added -u and -g to default setup. Bumped release. Modified: trunk/varnish-cache/debian/README.Debian =================================================================== --- trunk/varnish-cache/debian/README.Debian 2007-08-20 07:56:25 UTC (rev 1864) +++ trunk/varnish-cache/debian/README.Debian 2007-08-20 08:38:29 UTC (rev 1865) @@ -1,3 +1,10 @@ +Important change for 1.1.1 +========================== + +Varnish now features use of ``-u'' and ``-g'' in the default +configuration. If you have customized the defaults you may wish to +make these changes yourself. + GCC === Varnish requires a GCC-compiler compatible with the compiler used to Modified: trunk/varnish-cache/debian/changelog =================================================================== --- trunk/varnish-cache/debian/changelog 2007-08-20 07:56:25 UTC (rev 1864) +++ trunk/varnish-cache/debian/changelog 2007-08-20 08:38:29 UTC (rev 1865) @@ -1,3 +1,10 @@ +varnish (1.1.1) unstable; urgency=low + + * New upstream release + * User and Group id added to default DAEMON_OPTS + + -- Lars Bahner Mon, 20 Aug 2007 10:32:00 +0200 + varnish (1.1) unstable; urgency=low * New upstream release Modified: trunk/varnish-cache/debian/varnish.default =================================================================== --- trunk/varnish-cache/debian/varnish.default 2007-08-20 07:56:25 UTC (rev 1864) +++ trunk/varnish-cache/debian/varnish.default 2007-08-20 08:38:29 UTC (rev 1865) @@ -17,6 +17,7 @@ DAEMON_OPTS="-a :6081 \ -T localhost:6082 \ -b localhost:8080 \ + -u varnish -g varnish \ -n /var/lib/varnish \ -s file,/var/lib/varnish/varnish_storage.bin,1G" From phk at projects.linpro.no Mon Aug 20 08:55:13 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 10:55:13 +0200 (CEST) Subject: r1866 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820085513.90E4D1EC2AE@projects.linpro.no> Author: phk Date: 2007-08-20 10:55:13 +0200 (Mon, 20 Aug 2007) New Revision: 1866 Modified: trunk/varnish-cache/bin/varnishd/cache_session.c Log: Assert that the timestats we need for VSL_StatSess are valid. Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2007-08-20 08:38:29 UTC (rev 1865) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2007-08-20 08:55:13 UTC (rev 1866) @@ -340,6 +340,8 @@ AZ(sp->vcl); VSL_stats->n_sess--; ses_relsrcaddr(sp); + assert(!isnan(b->first)); + assert(!isnan(sp->t_end)); 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, From bahner at projects.linpro.no Mon Aug 20 08:55:34 2007 From: bahner at projects.linpro.no (bahner at projects.linpro.no) Date: Mon, 20 Aug 2007 10:55:34 +0200 (CEST) Subject: r1867 - trunk/varnish-cache/debian Message-ID: <20070820085534.A85411EC429@projects.linpro.no> Author: bahner Date: 2007-08-20 10:55:34 +0200 (Mon, 20 Aug 2007) New Revision: 1867 Added: trunk/varnish-cache/debian/varnish.postinst Log: Added creation of varnish user and group to postinst Added: trunk/varnish-cache/debian/varnish.postinst =================================================================== --- trunk/varnish-cache/debian/varnish.postinst (rev 0) +++ trunk/varnish-cache/debian/varnish.postinst 2007-08-20 08:55:34 UTC (rev 1867) @@ -0,0 +1,28 @@ +# Automatically added by dh_installinit +if [ -x "/etc/init.d/varnish" ]; then + update-rc.d varnish defaults >/dev/null + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d varnish start || exit $? + else + /etc/init.d/varnish start || exit $? + fi +fi +# End automatically added section +# Automatically added by dh_installinit +if [ -x "/etc/init.d/varnishlog" ]; then + update-rc.d varnishlog defaults >/dev/null + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d varnishlog start || exit $? + else + /etc/init.d/varnishlog start || exit $? + fi +fi +# End automatically added section + +varnish_setup_user() { + if ! id varnish > /dev/null 2>&1 ; then + adduser --system --no-create-home varnish 2>&1 > /dev/null || exit 78 + fi +} + + From bahner at projects.linpro.no Mon Aug 20 08:56:40 2007 From: bahner at projects.linpro.no (bahner at projects.linpro.no) Date: Mon, 20 Aug 2007 10:56:40 +0200 (CEST) Subject: r1868 - trunk/varnish-cache/debian Message-ID: <20070820085640.B5A591EC2AE@projects.linpro.no> Author: bahner Date: 2007-08-20 10:56:40 +0200 (Mon, 20 Aug 2007) New Revision: 1868 Modified: trunk/varnish-cache/debian/changelog Log: Comment on postinst user-creation Modified: trunk/varnish-cache/debian/changelog =================================================================== --- trunk/varnish-cache/debian/changelog 2007-08-20 08:55:34 UTC (rev 1867) +++ trunk/varnish-cache/debian/changelog 2007-08-20 08:56:40 UTC (rev 1868) @@ -2,8 +2,9 @@ * New upstream release * User and Group id added to default DAEMON_OPTS + * Added user-creation to postinst - -- Lars Bahner Mon, 20 Aug 2007 10:32:00 +0200 + -- Lars Bahner Mon, 20 Aug 2007 10:55:55 +0200 varnish (1.1) unstable; urgency=low From phk at projects.linpro.no Mon Aug 20 08:57:42 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 10:57:42 +0200 (CEST) Subject: r1869 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820085742.E04DA1EC429@projects.linpro.no> Author: phk Date: 2007-08-20 10:57:42 +0200 (Mon, 20 Aug 2007) New Revision: 1869 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_pipe.c Log: Use uppercase VBE prefix for VBE_new_bereq() and VBE_free_bereq() Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 08:56:40 UTC (rev 1868) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 08:57:42 UTC (rev 1869) @@ -366,8 +366,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); +struct bereq * VBE_new_bereq(void); +void VBE_free_bereq(struct bereq *bereq); /* cache_ban.c */ void AddBan(const char *, int hash); Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-20 08:56:40 UTC (rev 1868) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-20 08:57:42 UTC (rev 1869) @@ -28,6 +28,12 @@ * * $Id$ * + * NB: This file is in transition: + * In the future it will contain the central part of the backend handling, + * refcounting, functions for DNS lookup and connection revalidation etc. + * The actual policies will be put in separate files, cache_backend_simple.c, + * cache_backend_round_robin.c etc etc. + * * Manage backend connections. * * XXX: When we switch VCL we can have vbe_conn's dangling from @@ -62,7 +68,7 @@ /*--------------------------------------------------------------------*/ struct bereq * -vbe_new_bereq(void) +VBE_new_bereq(void) { struct bereq *bereq; volatile unsigned len; @@ -91,7 +97,7 @@ /* XXX: no backpressure on pool size */ void -vbe_free_bereq(struct bereq *bereq) +VBE_free_bereq(struct bereq *bereq) { CHECK_OBJ_NOTNULL(bereq, BEREQ_MAGIC); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-20 08:56:40 UTC (rev 1868) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-20 08:57:42 UTC (rev 1869) @@ -317,7 +317,7 @@ } - vbe_free_bereq(sp->bereq); + VBE_free_bereq(sp->bereq); sp->bereq = NULL; if (i) { @@ -590,7 +590,7 @@ HSH_Unbusy(sp->obj); HSH_Deref(sp->obj); sp->obj = NULL; - vbe_free_bereq(sp->bereq); + VBE_free_bereq(sp->bereq); sp->bereq = NULL; sp->step = STP_ERROR; return (0); @@ -601,7 +601,7 @@ HSH_Deref(sp->obj); sp->obj = NULL; sp->step = STP_PASS; - vbe_free_bereq(sp->bereq); + VBE_free_bereq(sp->bereq); sp->bereq = NULL; return (0); } Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-08-20 08:56:40 UTC (rev 1868) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-08-20 08:57:42 UTC (rev 1869) @@ -787,7 +787,7 @@ struct http *hp; char *b; - bereq = vbe_new_bereq(); + bereq = VBE_new_bereq(); AN(bereq); hp = bereq->http; hp->logtag = HTTP_Tx; Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-08-20 08:56:40 UTC (rev 1868) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-08-20 08:57:42 UTC (rev 1869) @@ -102,7 +102,7 @@ return; } - vbe_free_bereq(bereq); + VBE_free_bereq(bereq); bereq = NULL; sp->t_resp = TIM_real(); From phk at projects.linpro.no Mon Aug 20 08:58:24 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 10:58:24 +0200 (CEST) Subject: r1870 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820085824.E2F0F1EC2AE@projects.linpro.no> Author: phk Date: 2007-08-20 10:58:24 +0200 (Mon, 20 Aug 2007) New Revision: 1870 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Isolate the C-compiler even more with env -i and -nostdinc Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-08-20 08:57:42 UTC (rev 1869) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-08-20 08:58:24 UTC (rev 1870) @@ -184,7 +184,7 @@ #ifdef __APPLE__ "exec cc -dynamiclib -Wl,-undefined,dynamic_lookup -o %s -x c - < %s 2>&1", #else - "exec cc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1", + "env -i cc -nostdinc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1", #endif sf, of, sf); xxxassert(len < sizeof buf); From ingvar at projects.linpro.no Mon Aug 20 09:09:28 2007 From: ingvar at projects.linpro.no (ingvar at projects.linpro.no) Date: Mon, 20 Aug 2007 11:09:28 +0200 (CEST) Subject: r1871 - branches/1.1/redhat Message-ID: <20070820090928.3D9491EC2B1@projects.linpro.no> Author: ingvar Date: 2007-08-20 11:09:26 +0200 (Mon, 20 Aug 2007) New Revision: 1871 Modified: branches/1.1/redhat/varnish.spec Log: reverting cosmetic changes caused by a failed diff-patch Modified: branches/1.1/redhat/varnish.spec =================================================================== --- branches/1.1/redhat/varnish.spec 2007-08-20 08:58:24 UTC (rev 1870) +++ branches/1.1/redhat/varnish.spec 2007-08-20 09:09:26 UTC (rev 1871) @@ -121,6 +121,7 @@ %defattr(-,root,root,-) %{_libdir}/libvarnish.so %{_libdir}/libvarnishapi.so +%{_libdir}/libvarnishcompat.so %{_libdir}/libvcl.so %{_includedir}/varnish/shmlog.h %{_includedir}/varnish/shmlog_tags.h @@ -164,17 +165,14 @@ %postun libs -p /sbin/ldconfig %changelog -<<<<<<< .working -* Thu Jul 05 2007 Dag-Erling Sm?rgrav - 1.1-1 -- Bump Version and Release for 1.1 - -======= * Tue Aug 14 2007 Ingvar Hagelund - 1.1.svn - Update for 1.1 branch - Added the devel package for the header files and static library files - Added a varnish user, and fixed the init script accordingly ->>>>>>> .merge-right.r1846 +* 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 - Fixed initrc-script bug only visible on el4 (fixes #107) From ingvar at projects.linpro.no Mon Aug 20 09:12:42 2007 From: ingvar at projects.linpro.no (ingvar at projects.linpro.no) Date: Mon, 20 Aug 2007 11:12:42 +0200 (CEST) Subject: r1872 - trunk/varnish-cache/redhat Message-ID: <20070820091242.0DA3D1EC2AE@projects.linpro.no> Author: ingvar Date: 2007-08-20 11:12:41 +0200 (Mon, 20 Aug 2007) New Revision: 1872 Modified: trunk/varnish-cache/redhat/varnish.spec Log: A svn trunk build needs automake, autoconf and libtool to build. A release tarball can remove these requirements. Modified: trunk/varnish-cache/redhat/varnish.spec =================================================================== --- trunk/varnish-cache/redhat/varnish.spec 2007-08-20 09:09:26 UTC (rev 1871) +++ trunk/varnish-cache/redhat/varnish.spec 2007-08-20 09:12:41 UTC (rev 1872) @@ -7,7 +7,7 @@ URL: http://www.varnish-cache.org/ Source0: http://downloads.sourceforge.net/varnish/varnish-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) -BuildRequires: ncurses-devel +BuildRequires: ncurses-devel automake autoconf libtool Requires: kernel >= 2.6.0 varnish-libs = %{version}-%{release} Requires: logrotate Requires(pre): shadow-utils From bahner at projects.linpro.no Mon Aug 20 09:33:50 2007 From: bahner at projects.linpro.no (bahner at projects.linpro.no) Date: Mon, 20 Aug 2007 11:33:50 +0200 (CEST) Subject: r1873 - trunk/varnish-cache/debian Message-ID: <20070820093350.4071E1EC2B1@projects.linpro.no> Author: bahner Date: 2007-08-20 11:33:50 +0200 (Mon, 20 Aug 2007) New Revision: 1873 Added: trunk/varnish-cache/debian/varnish.manpages Modified: trunk/varnish-cache/debian/changelog trunk/varnish-cache/debian/varnish.postinst Log: Add file to install man pages; call varnish_setup_user from postinst Modified: trunk/varnish-cache/debian/changelog =================================================================== --- trunk/varnish-cache/debian/changelog 2007-08-20 09:12:41 UTC (rev 1872) +++ trunk/varnish-cache/debian/changelog 2007-08-20 09:33:50 UTC (rev 1873) @@ -2,9 +2,10 @@ * New upstream release * User and Group id added to default DAEMON_OPTS - * Added user-creation to postinst + * Added user-creation to postinst + * Added missing man pages - -- Lars Bahner Mon, 20 Aug 2007 10:55:55 +0200 + -- Lars Bahner Mon, 20 Aug 2007 11:29:33 +0200 varnish (1.1) unstable; urgency=low Added: trunk/varnish-cache/debian/varnish.manpages =================================================================== --- trunk/varnish-cache/debian/varnish.manpages (rev 0) +++ trunk/varnish-cache/debian/varnish.manpages 2007-08-20 09:33:50 UTC (rev 1873) @@ -0,0 +1,9 @@ +bin/varnishncsa/varnishncsa.1 +bin/varnishhist/varnishhist.1 +bin/varnishstat/varnishstat.1 +bin/varnishreplay/varnishreplay.1 +bin/varnishadm/varnishadm.1 +bin/varnishlog/varnishlog.1 +bin/varnishtop/varnishtop.1 +bin/varnishd/varnishd.1 +man/vcl.7 Modified: trunk/varnish-cache/debian/varnish.postinst =================================================================== --- trunk/varnish-cache/debian/varnish.postinst 2007-08-20 09:12:41 UTC (rev 1872) +++ trunk/varnish-cache/debian/varnish.postinst 2007-08-20 09:33:50 UTC (rev 1873) @@ -25,4 +25,4 @@ fi } - +varnish_setup_user From bahner at projects.linpro.no Mon Aug 20 09:37:59 2007 From: bahner at projects.linpro.no (bahner at projects.linpro.no) Date: Mon, 20 Aug 2007 11:37:59 +0200 (CEST) Subject: r1874 - trunk/varnish-cache/debian Message-ID: <20070820093759.9EB921EC2AE@projects.linpro.no> Author: bahner Date: 2007-08-20 11:37:59 +0200 (Mon, 20 Aug 2007) New Revision: 1874 Modified: trunk/varnish-cache/debian/varnish.postinst Log: Added forgotten shebang to postinst Modified: trunk/varnish-cache/debian/varnish.postinst =================================================================== --- trunk/varnish-cache/debian/varnish.postinst 2007-08-20 09:33:50 UTC (rev 1873) +++ trunk/varnish-cache/debian/varnish.postinst 2007-08-20 09:37:59 UTC (rev 1874) @@ -1,3 +1,6 @@ +#!/bin/sh + + # Automatically added by dh_installinit if [ -x "/etc/init.d/varnish" ]; then update-rc.d varnish defaults >/dev/null From bahner at projects.linpro.no Mon Aug 20 09:40:54 2007 From: bahner at projects.linpro.no (bahner at projects.linpro.no) Date: Mon, 20 Aug 2007 11:40:54 +0200 (CEST) Subject: r1875 - trunk/varnish-cache/debian Message-ID: <20070820094054.B256B1EC37C@projects.linpro.no> Author: bahner Date: 2007-08-20 11:40:54 +0200 (Mon, 20 Aug 2007) New Revision: 1875 Modified: trunk/varnish-cache/debian/varnish.postinst Log: Fixed silly race Modified: trunk/varnish-cache/debian/varnish.postinst =================================================================== --- trunk/varnish-cache/debian/varnish.postinst 2007-08-20 09:37:59 UTC (rev 1874) +++ trunk/varnish-cache/debian/varnish.postinst 2007-08-20 09:40:54 UTC (rev 1875) @@ -1,6 +1,13 @@ #!/bin/sh +varnish_setup_user() { + if ! id varnish > /dev/null 2>&1 ; then + adduser --system --no-create-home varnish 2>&1 > /dev/null || exit 78 + fi +} +varnish_setup_user + # Automatically added by dh_installinit if [ -x "/etc/init.d/varnish" ]; then update-rc.d varnish defaults >/dev/null @@ -21,11 +28,3 @@ fi fi # End automatically added section - -varnish_setup_user() { - if ! id varnish > /dev/null 2>&1 ; then - adduser --system --no-create-home varnish 2>&1 > /dev/null || exit 78 - fi -} - -varnish_setup_user From des at projects.linpro.no Mon Aug 20 09:42:01 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 11:42:01 +0200 (CEST) Subject: r1876 - trunk/varnish-tools/regress Message-ID: <20070820094201.70E801EC2B1@projects.linpro.no> Author: des Date: 2007-08-20 11:42:01 +0200 (Mon, 20 Aug 2007) New Revision: 1876 Modified: trunk/varnish-tools/regress/varnish-regress.pl Log: If the first and only argument is 'list', list all available test cases. Modified: trunk/varnish-tools/regress/varnish-regress.pl =================================================================== --- trunk/varnish-tools/regress/varnish-regress.pl 2007-08-20 09:40:54 UTC (rev 1875) +++ trunk/varnish-tools/regress/varnish-regress.pl 2007-08-20 09:42:01 UTC (rev 1876) @@ -62,9 +62,15 @@ or usage(); my $controller = new Varnish::Test; + my @all_cases = $controller->cases(); + if (@ARGV == 1 && $ARGV[0] eq 'list') { + print join(' ', @all_cases), "\n"; + exit 0; + } + if (!@ARGV) { - @ARGV = $controller->cases(); + @ARGV = @all_cases; } else { map { s/^(\d+)$/sprintf('Ticket%03d', $1)/e } @ARGV; } From bahner at projects.linpro.no Mon Aug 20 09:42:56 2007 From: bahner at projects.linpro.no (bahner at projects.linpro.no) Date: Mon, 20 Aug 2007 11:42:56 +0200 (CEST) Subject: r1877 - trunk/varnish-cache/debian Message-ID: <20070820094256.E4A6E1EC37C@projects.linpro.no> Author: bahner Date: 2007-08-20 11:42:56 +0200 (Mon, 20 Aug 2007) New Revision: 1877 Modified: trunk/varnish-cache/debian/varnish.postinst Log: Added group Modified: trunk/varnish-cache/debian/varnish.postinst =================================================================== --- trunk/varnish-cache/debian/varnish.postinst 2007-08-20 09:42:01 UTC (rev 1876) +++ trunk/varnish-cache/debian/varnish.postinst 2007-08-20 09:42:56 UTC (rev 1877) @@ -2,7 +2,7 @@ varnish_setup_user() { if ! id varnish > /dev/null 2>&1 ; then - adduser --system --no-create-home varnish 2>&1 > /dev/null || exit 78 + adduser --system --no-create-home --group varnish 2>&1 > /dev/null || exit 78 fi } From des at projects.linpro.no Mon Aug 20 09:52:51 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 11:52:51 +0200 (CEST) Subject: r1878 - in trunk/varnish-tools/regress/lib/Varnish: . Test Message-ID: <20070820095251.E72071EC2B1@projects.linpro.no> Author: des Date: 2007-08-20 11:52:51 +0200 (Mon, 20 Aug 2007) New Revision: 1878 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/Varnish.pm Log: Use time-limited polling loops to verify parent and child startup and child shutdown, instead of relying on unordered events. Ignore anything that appears on varnishd's std{out,err} except for an unexpected "child died", which we handle by dying instead of emitting an event. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-20 09:42:56 UTC (rev 1877) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-08-20 09:52:51 UTC (rev 1878) @@ -103,7 +103,6 @@ $self->{'failed'} += 1; die "Unable to start child\n"; } - $self->run_loop('ev_varnish_child_started'); } sub fini($) { @@ -113,13 +112,11 @@ # Stop the worker process $varnish->stop_child(); - $self->run_loop('ev_varnish_child_stopped'); # Revert to initial VCL script no strict 'refs'; if (${ref($self)."::VCL"}) { $varnish->use_vcl('boot'); - $self->run_loop('ev_varnish_result'); } delete $self->{'engine'}->{'case'}; Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-20 09:42:56 UTC (rev 1877) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-20 09:52:51 UTC (rev 1878) @@ -113,44 +113,44 @@ exec('varnishd', @opts); exit(1); } - else { - # Parent - $self->log('PID: ' . $pid); - close STDIN_READ; - close STDOUT_WRITE; - close STDERR_WRITE; + # Parent + $self->log('PID: ' . $pid); - $self->{'pid'} = $pid; - $self->{'stdin'} = \*STDIN_WRITE; - $self->{'stdout'} = \*STDOUT_READ; - $self->{'stderr'} = \*STDERR_READ; + close STDIN_READ; + close STDOUT_WRITE; + close STDERR_WRITE; - # Register the Varnish I/O-channels with the IO::Multiplex - # loop object. + $self->{'pid'} = $pid; + $self->{'stdin'} = \*STDIN_WRITE; + $self->{'stdout'} = \*STDOUT_READ; + $self->{'stderr'} = \*STDERR_READ; - $self->{'mux'}->add($self->{'stdin'}); - $self->{'mux'}->set_callback_object($self, $self->{'stdin'}); - $self->{'mux'}->add($self->{'stdout'}); - $self->{'mux'}->set_callback_object($self, $self->{'stdout'}); - $self->{'mux'}->add($self->{'stderr'}); - $self->{'mux'}->set_callback_object($self, $self->{'stderr'}); + # Register the Varnish I/O-channels with the IO::Multiplex + # loop object. - # Wait up to 0.5 seconds for Varnish to accept our connection - # on the management port - for (my $i = 0; $i < 5; ++$i) { - last if $self->{'socket'} = IO::Socket::INET-> - new(Type => SOCK_STREAM, - PeerAddr => $engine->{'config'}->{'telnet_address'}); - select(undef, undef, undef, 0.1); - } - if (!defined($self->{'socket'})) { - kill(15, delete $self->{'pid'}); - die "Varnish did not start\n"; - } - $self->{'mux'}->add($self->{'socket'}); - $self->{'mux'}->set_callback_object($self, $self->{'socket'}); + $self->{'mux'}->add($self->{'stdin'}); + $self->{'mux'}->set_callback_object($self, $self->{'stdin'}); + $self->{'mux'}->add($self->{'stdout'}); + $self->{'mux'}->set_callback_object($self, $self->{'stdout'}); + $self->{'mux'}->add($self->{'stderr'}); + $self->{'mux'}->set_callback_object($self, $self->{'stderr'}); + + # Wait up to 0.5 seconds for Varnish to accept our connection + # on the management port + for (my $i = 0; $i < 5; ++$i) { + last if $self->{'socket'} = IO::Socket::INET-> + new(Type => SOCK_STREAM, + PeerAddr => $engine->{'config'}->{'telnet_address'}); + select(undef, undef, undef, 0.1); } + if (!defined($self->{'socket'})) { + kill(15, delete $self->{'pid'}); + die "Varnish did not start\n"; + } + $self->{'mux'}->add($self->{'socket'}); + $self->{'mux'}->set_callback_object($self, $self->{'socket'}); + $self->{'state'} = 'stopped'; return $self; } @@ -191,6 +191,8 @@ $self->{'engine'}->run_loop('ev_varnish_result', 'ev_varnish_timeout'); delete $self->{'pending'}; + $self->log("result code $code") + if ($ev eq 'ev_varnish_result'); return ($code, $text); } @@ -213,7 +215,22 @@ die "already started\n" if $self->{'state'} eq "started"; - return $self->send_command("start"); + $self->{'state'} = 'starting'; + my ($code, $text) = $self->send_command("start"); + return ($code, $text) + unless ($code == 200); + for (my $n = 0; $n < 10; ++$n) { + my ($code, $text) = $self->send_command('status'); + return ($code, $text) + unless ($code == 200); + if ($text =~ /state running/) { + $self->{'state'} = 'started'; + return ($code, $text); + } + select(undef, undef, undef, 0.5); + } + $self->shutdown(); + return (500, 'unable to start child'); } sub stop_child($) { @@ -223,7 +240,20 @@ die "already stopped\n" if $self->{'state'} eq 'stopped'; - return $self->send_command("stop"); + $self->{'state'} eq 'stopping'; + my ($code, $text) = $self->send_command("stop"); + for (my $n = 0; $n < 10; ++$n) { + my ($code, $text) = $self->send_command('status'); + return ($code, $text) + unless ($code == 200); + if ($text =~ /state stopped/) { + $self->{'state'} = 'stopped'; + return ($code, $text); + } + select(undef, undef, undef, 0.5); + } + $self->shutdown(); + return (500, 'unable to stop child'); } sub set_param($$$) { @@ -273,23 +303,23 @@ return; } # extract the response text (if any), then remove from $$data - my $text = substr($$data, length($line), $len); - substr($$data, 0, length($line) + $len + 1, ''); - - $self->{'engine'}->ev_varnish_result($code, $text); + $$data =~ s/^\Q$line\E\n(.{$len})\n// + or die "oops\n"; + $self->{'engine'}->ev_varnish_result($code, $1); } else { - if ($$data =~ /^rolling\(2\)\.\.\./m) { - $self->{'state'} = 'stopped'; - $self->{'engine'}->ev_varnish_started; + if ($$data =~ /Child died pid=(\d+) status=0x([0-9A-Fa-f]+)/) { + my ($pid, $status) = ($1, hex($2)); + if ($pid != $self->{'pid'}) { + # shouldn't happen, but sometimes it does + $self->log("stray child $pid died with status $status"); + } elsif ($self->{'state'} == 'stopping' || + $self->{'state'} == 'stopped') { + # ignore + } else { + $self->{'state'} = 'stopped'; + die "child died unexpectedly with status $status\n"; + } } - if ($$data =~ /Child starts/) { - $self->{'state'} = 'started'; - $self->{'engine'}->ev_varnish_child_started; - } - if ($$data =~ /Child dies/) { - $self->{'state'} = 'stopped'; - $self->{'engine'}->ev_varnish_child_stopped; - } # XXX there might be more! $$data = ''; } Modified: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-08-20 09:42:56 UTC (rev 1877) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-08-20 09:52:51 UTC (rev 1878) @@ -117,7 +117,6 @@ return if defined $self->{'engine'}; $self->{'engine'} = Varnish::Test::Engine->new(@args); - $self->{'engine'}->run_loop('ev_varnish_started'); } sub stop_engine($;$) { From des at linpro.no Mon Aug 20 09:55:03 2007 From: des at linpro.no (=?iso-8859-1?Q?Dag-Erling_Sm=F8rgrav?=) Date: Mon, 20 Aug 2007 11:55:03 +0200 Subject: r1870 - trunk/varnish-cache/bin/varnishd In-Reply-To: <20070820085824.E2F0F1EC2AE@projects.linpro.no> (phk@projects.linpro.no's message of "Mon, 20 Aug 2007 10:58:24 +0200 (CEST)") References: <20070820085824.E2F0F1EC2AE@projects.linpro.no> Message-ID: phk at projects.linpro.no writes: > Log: > Isolate the C-compiler even more with env -i and -nostdinc 'env -i' is a bad idea, as it blows away $PATH, which cc needs. DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From des at projects.linpro.no Mon Aug 20 10:10:20 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 12:10:20 +0200 (CEST) Subject: r1879 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070820101020.104901EC37C@projects.linpro.no> Author: des Date: 2007-08-20 12:10:19 +0200 (Mon, 20 Aug 2007) New Revision: 1879 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Nit in previous commit Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-20 09:52:51 UTC (rev 1878) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-20 10:10:19 UTC (rev 1879) @@ -240,7 +240,7 @@ die "already stopped\n" if $self->{'state'} eq 'stopped'; - $self->{'state'} eq 'stopping'; + $self->{'state'} = 'stopping'; my ($code, $text) = $self->send_command("stop"); for (my $n = 0; $n < 10; ++$n) { my ($code, $text) = $self->send_command('status'); From bahner at projects.linpro.no Mon Aug 20 10:13:16 2007 From: bahner at projects.linpro.no (bahner at projects.linpro.no) Date: Mon, 20 Aug 2007 12:13:16 +0200 (CEST) Subject: r1880 - trunk/varnish-cache/debian Message-ID: <20070820101316.7DF651EC37C@projects.linpro.no> Author: bahner Date: 2007-08-20 12:13:16 +0200 (Mon, 20 Aug 2007) New Revision: 1880 Modified: trunk/varnish-cache/debian/changelog Log: Clarified change Modified: trunk/varnish-cache/debian/changelog =================================================================== --- trunk/varnish-cache/debian/changelog 2007-08-20 10:10:19 UTC (rev 1879) +++ trunk/varnish-cache/debian/changelog 2007-08-20 10:13:16 UTC (rev 1880) @@ -2,7 +2,7 @@ * New upstream release * User and Group id added to default DAEMON_OPTS - * Added user-creation to postinst + * Added user and group creation to postinst * Added missing man pages -- Lars Bahner Mon, 20 Aug 2007 11:29:33 +0200 From phk at projects.linpro.no Mon Aug 20 10:20:09 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 12:20:09 +0200 (CEST) Subject: r1881 - trunk/varnish-cache Message-ID: <20070820102009.A04211EC2AE@projects.linpro.no> Author: phk Date: 2007-08-20 12:20:09 +0200 (Mon, 20 Aug 2007) New Revision: 1881 Modified: trunk/varnish-cache/configure.ac Log: Look for fmtcheck(3) function. Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2007-08-20 10:13:16 UTC (rev 1880) +++ trunk/varnish-cache/configure.ac 2007-08-20 10:20:09 UTC (rev 1881) @@ -84,6 +84,7 @@ AC_CHECK_FUNCS([socket]) AC_CHECK_FUNCS([strptime]) AC_CHECK_FUNCS([sendfile]) +AC_CHECK_FUNCS([fmtcheck]) # These functions are provided by libcompat on platforms where they # are not available From phk at projects.linpro.no Mon Aug 20 10:21:07 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 12:21:07 +0200 (CEST) Subject: r1882 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820102107.3D3E51EC429@projects.linpro.no> Author: phk Date: 2007-08-20 12:21:07 +0200 (Mon, 20 Aug 2007) New Revision: 1882 Modified: trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Make the C-compiler command a paramter, and generally clean up the code that invokes it. If fmtcheck(3) is available, we refuse pedal target practice. Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2007-08-20 10:20:09 UTC (rev 1881) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2007-08-20 10:21:07 UTC (rev 1882) @@ -60,6 +60,7 @@ void mgt_vcc_init(void); 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); +extern char *mgt_cc_cmd; #include "hash_slinger.h" Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-08-20 10:20:09 UTC (rev 1881) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-08-20 10:21:07 UTC (rev 1882) @@ -527,6 +527,30 @@ /*--------------------------------------------------------------------*/ +static void +tweak_cc_command(struct cli *cli, struct parspec *par, const char *arg) +{ + + (void)par; + if (arg == NULL) { + cli_out(cli, "%s", mgt_cc_cmd); + } else { +#if defined(HAVE_FMTCHECK) + if (arg != fmtcheck(arg, "%s %s")) { + cli_out(cli, + "Parameter has dangerous %%-string expansions."); + cli_result(cli, CLIS_PARAM); + return; + } +#endif + free(mgt_cc_cmd); + mgt_cc_cmd = strdup(arg); + XXXAN(mgt_cc_cmd); + } +} + +/*--------------------------------------------------------------------*/ + /* * Make sure to end all lines with either a space or newline of the * formatting will go haywire. @@ -539,6 +563,10 @@ "\nNB: This parameter will not take any effect until the " \ "child process has been restarted.\n" +#define MUST_RELOAD \ + "\nNB: This parameter will not take any effect until the " \ + "VCL programs have been reloaded.\n" + #define EXPERIMENTAL \ "\nNB: We don't know yet if it is a good idea to change " \ "this parameter. Caution advised.\n" @@ -700,6 +728,20 @@ "it possible to attach a debugger to the child.\n" MUST_RESTART, "3", "seconds" }, + { "cc_command", tweak_cc_command, + "Command used for compiling the C source code to a " + "dlopen(3) loadable object.\n" + "NB: The string must contain two %%s sequences which " + "will be replaced by the binary and source file names " + "respectively.\n" + MUST_RELOAD, +#ifdef __APPLE__ + "exec cc -dynamiclib -Wl,-undefined,dynamic_lookup -o %s -x c" + " - < %s" +#else + "exec cc -nostdinc -fpic -shared -Wl,-x -o %s -x c - < %s" +#endif + , NULL }, { NULL, NULL, NULL } }; Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-08-20 10:20:09 UTC (rev 1881) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-08-20 10:21:07 UTC (rev 1882) @@ -38,6 +38,7 @@ #include #include #include +#include #ifndef HAVE_ASPRINTF #include "compat/asprintf.h" @@ -65,6 +66,8 @@ static TAILQ_HEAD(, vclprog) vclhead = TAILQ_HEAD_INITIALIZER(vclhead); +char *mgt_cc_cmd; + /*--------------------------------------------------------------------*/ /* keep this in synch with man/vcl.7 */ @@ -148,8 +151,9 @@ FILE *fo, *fs; char sf[] = "./vcl.XXXXXXXX"; char *of; - char buf[BUFSIZ]; - int i, j, len, sfd; + struct vsb *cccmd; + char buf[128]; + int i, j, sfd; void *p; /* Create temporary C source file */ @@ -161,7 +165,7 @@ return (NULL); } fs = fdopen(sfd, "r+"); - AN(fs); + XXXAN(fs); if (fputs(source, fs) < 0 || fflush(fs)) { vsb_printf(sb, @@ -173,55 +177,92 @@ } rewind(fs); - /* Name the output shared library */ + /* Name the output shared library by brutally overwriting "./vcl." */ of = strdup(sf); - AN(of); + XXXAN(of); memcpy(of, "./bin", 5); - /* 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,-undefined,dynamic_lookup -o %s -x c - < %s 2>&1", -#else - "env -i cc -nostdinc -fpic -shared -Wl,-x -o %s -x c - < %s 2>&1", -#endif - sf, of, sf); - xxxassert(len < sizeof buf); + cccmd = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND); + XXXAN(cccmd); - fo = popen(buf, "r"); + /* + * Attempt to open a pipe to the system C-compiler. + * ------------------------------------------------ + * + * The arguments to the C-compiler must be whatever it takes to + * create a dlopen(3) compatible object file named $of from a + * source file named $sf. + * + * The source code is entirely selfcontained, so options should be + * specified to prevent the C-compiler from doing any DWITYW + * processing. For GCC this amounts to at least "-nostdinc". + * + * We wrap the entire command in a 'sh -c "..." 2>&1' to get any + * errors from popen(3)'s shell redirected to our stderr as well. + * + */ + vsb_printf(cccmd, "exec /bin/sh -c \"" ); + vsb_printf(cccmd, mgt_cc_cmd, of, sf); + vsb_printf(cccmd, "\" 2>&1"); + vsb_finish(cccmd); + /* XXX: check that vsb is happy about cccmd */ + + fo = popen(vsb_data(cccmd), "r"); if (fo == NULL) { vsb_printf(sb, - "Internal error: Cannot execute cc(1): %s\n", - strerror(errno)); + "System error: Cannot execute C-compiler: %s\n" + "\tcommand attempted: %s\n", + strerror(errno), vsb_data(cccmd)); free(of); unlink(sf); fclose(fs); + vsb_delete(cccmd); return (NULL); } - /* If we get any output, it's bad */ + /* Any output is considered fatal */ j = 0; while (1) { - if (fgets(buf, sizeof buf, fo) == NULL) + i = fread(buf, 1, sizeof buf, fo); + if (i == 0) break; if (!j) { - vsb_printf(sb, "Internal error: cc(1) complained:\n"); + vsb_printf(sb, + "System error:\n" + "C-compiler command complained.\n" + "Command attempted: %s\nMessage:\n", + vsb_data(cccmd)); j++; } - vsb_cat(sb, buf); + vsb_bcat(sb, buf, i); } i = pclose(fo); - if (j == 0 && i != 0) + + unlink(sf); + fclose(fs); + + if (j == 0 && i != 0) { vsb_printf(sb, - "Internal error: cc(1) exit status 0x%04x\n", i); + "System error:\n" + "C-compiler command failed"); + if (WIFEXITED(i)) + vsb_printf(sb, ", exit %d", WEXITSTATUS(i)); + if (WIFSIGNALED(i)) + vsb_printf(sb, ", signal %d", WTERMSIG(i)); + if (WCOREDUMP(i)) + vsb_printf(sb, ", core dumped"); + vsb_printf(sb, + "\nCommand attempted: %s\n", vsb_data(cccmd)); + } + vsb_delete(cccmd); + /* If the compiler complained, or exited non-zero, fail */ if (i || j) { unlink(of); free(of); - of = NULL; + return (NULL); } /* Next, try to load the object into the management process */ @@ -231,13 +272,10 @@ dlerror()); unlink(of); free(of); - of = NULL; - } else - (void)dlclose(p); + return (NULL); + } - /* clean up and return */ - unlink(sf); - fclose(fs); + (void)dlclose(p); return (of); } From phk at projects.linpro.no Mon Aug 20 10:36:17 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 12:36:17 +0200 (CEST) Subject: r1883 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820103617.0C1CC1EC2AE@projects.linpro.no> Author: phk Date: 2007-08-20 12:36:16 +0200 (Mon, 20 Aug 2007) New Revision: 1883 Modified: trunk/varnish-cache/bin/varnishd/cache.h Log: Make the new FlexeLint 8.00w happy again. It's a fine point of C-linguistics, but I have to admit that in certain universes it would have a point. Not this one though. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 10:21:07 UTC (rev 1882) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 10:36:16 UTC (rev 1883) @@ -105,6 +105,12 @@ char *e; }; +enum httpwhence { + HTTP_Rx, + HTTP_Tx, + HTTP_Obj +}; + struct http { unsigned magic; #define HTTP_MAGIC 0x6428b5c9 @@ -114,11 +120,7 @@ char *pl_s, *pl_e; /* Pipelined bytes */ unsigned char conds; /* If-* headers present */ - enum httpwhence { - HTTP_Rx, - HTTP_Tx, - HTTP_Obj - } logtag; + enum httpwhence logtag; struct http_hdr hd[HTTP_HDR_MAX]; unsigned char hdf[HTTP_HDR_MAX]; From phk at projects.linpro.no Mon Aug 20 10:39:05 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 12:39:05 +0200 (CEST) Subject: r1884 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820103905.6C6621EC37C@projects.linpro.no> Author: phk Date: 2007-08-20 12:39:05 +0200 (Mon, 20 Aug 2007) New Revision: 1884 Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c Log: remove debugging message Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-08-20 10:36:16 UTC (rev 1883) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2007-08-20 10:39:05 UTC (rev 1884) @@ -103,8 +103,6 @@ if (memcmp(&tv, &tv_rcvtimeo, l)) need_rcvtimeo = 1; need_test = 0; - printf("socktest: linger=%d sndtimeo=%d rcvtimeo=%d\n", - need_linger, need_sndtimeo, need_rcvtimeo); } void From phk at projects.linpro.no Mon Aug 20 10:41:17 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 12:41:17 +0200 (CEST) Subject: r1885 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820104117.564491EC2AE@projects.linpro.no> Author: phk Date: 2007-08-20 12:41:17 +0200 (Mon, 20 Aug 2007) New Revision: 1885 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Get number of '%' signs right in param.show message for cc_command. Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-08-20 10:39:05 UTC (rev 1884) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2007-08-20 10:41:17 UTC (rev 1885) @@ -731,7 +731,7 @@ { "cc_command", tweak_cc_command, "Command used for compiling the C source code to a " "dlopen(3) loadable object.\n" - "NB: The string must contain two %%s sequences which " + "NB: The string must contain two %s sequences which " "will be replaced by the binary and source file names " "respectively.\n" MUST_RELOAD, From phk at projects.linpro.no Mon Aug 20 10:53:00 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 12:53:00 +0200 (CEST) Subject: r1886 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820105300.10D151EC429@projects.linpro.no> Author: phk Date: 2007-08-20 12:52:59 +0200 (Mon, 20 Aug 2007) New Revision: 1886 Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c Log: polish Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-08-20 10:41:17 UTC (rev 1885) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-08-20 10:52:59 UTC (rev 1886) @@ -346,8 +346,7 @@ TAILQ_REMOVE(&sp->obj->store, st, list); STV_free(st); } - close(vc->fd); - VBE_ClosedFd(sp->wrk, vc, 1); + VBE_ClosedFd(sp->wrk, vc, 0); return (-1); } From bahner at projects.linpro.no Mon Aug 20 11:02:27 2007 From: bahner at projects.linpro.no (bahner at projects.linpro.no) Date: Mon, 20 Aug 2007 13:02:27 +0200 (CEST) Subject: r1887 - in branches/1.1: . debian Message-ID: <20070820110227.BDBB91EC37C@projects.linpro.no> Author: bahner Date: 2007-08-20 13:02:27 +0200 (Mon, 20 Aug 2007) New Revision: 1887 Added: branches/1.1/debian/varnish.manpages branches/1.1/debian/varnish.postinst Modified: branches/1.1/ branches/1.1/debian/README.Debian branches/1.1/debian/changelog branches/1.1/debian/varnish.default Log: Merged revisions 1865,1867-1868,1871,1873-1880 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1865 | bahner | 2007-08-20 10:38:29 +0200 (Mon, 20 Aug 2007) | 2 lines Added -u and -g to default setup. Bumped release. ........ r1867 | bahner | 2007-08-20 10:55:34 +0200 (Mon, 20 Aug 2007) | 2 lines Added creation of varnish user and group to postinst ........ r1868 | bahner | 2007-08-20 10:56:40 +0200 (Mon, 20 Aug 2007) | 2 lines Comment on postinst user-creation ........ r1873 | bahner | 2007-08-20 11:33:50 +0200 (Mon, 20 Aug 2007) | 2 lines Add file to install man pages; call varnish_setup_user from postinst ........ r1874 | bahner | 2007-08-20 11:37:59 +0200 (Mon, 20 Aug 2007) | 2 lines Added forgotten shebang to postinst ........ r1875 | bahner | 2007-08-20 11:40:54 +0200 (Mon, 20 Aug 2007) | 2 lines Fixed silly race ........ r1877 | bahner | 2007-08-20 11:42:56 +0200 (Mon, 20 Aug 2007) | 2 lines Added group ........ r1880 | bahner | 2007-08-20 12:13:16 +0200 (Mon, 20 Aug 2007) | 2 lines Clarified change ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880 Modified: branches/1.1/debian/README.Debian =================================================================== --- branches/1.1/debian/README.Debian 2007-08-20 10:52:59 UTC (rev 1886) +++ branches/1.1/debian/README.Debian 2007-08-20 11:02:27 UTC (rev 1887) @@ -1,3 +1,10 @@ +Important change for 1.1.1 +========================== + +Varnish now features use of ``-u'' and ``-g'' in the default +configuration. If you have customized the defaults you may wish to +make these changes yourself. + GCC === Varnish requires a GCC-compiler compatible with the compiler used to Modified: branches/1.1/debian/changelog =================================================================== --- branches/1.1/debian/changelog 2007-08-20 10:52:59 UTC (rev 1886) +++ branches/1.1/debian/changelog 2007-08-20 11:02:27 UTC (rev 1887) @@ -1,3 +1,12 @@ +varnish (1.1.1) unstable; urgency=low + + * New upstream release + * User and Group id added to default DAEMON_OPTS + * Added user and group creation to postinst + * Added missing man pages + + -- Lars Bahner Mon, 20 Aug 2007 11:29:33 +0200 + varnish (1.1) unstable; urgency=low * New upstream release Modified: branches/1.1/debian/varnish.default =================================================================== --- branches/1.1/debian/varnish.default 2007-08-20 10:52:59 UTC (rev 1886) +++ branches/1.1/debian/varnish.default 2007-08-20 11:02:27 UTC (rev 1887) @@ -17,6 +17,7 @@ DAEMON_OPTS="-a :6081 \ -T localhost:6082 \ -b localhost:8080 \ + -u varnish -g varnish \ -n /var/lib/varnish \ -s file,/var/lib/varnish/varnish_storage.bin,1G" Copied: branches/1.1/debian/varnish.manpages (from rev 1880, trunk/varnish-cache/debian/varnish.manpages) =================================================================== --- branches/1.1/debian/varnish.manpages (rev 0) +++ branches/1.1/debian/varnish.manpages 2007-08-20 11:02:27 UTC (rev 1887) @@ -0,0 +1,9 @@ +bin/varnishncsa/varnishncsa.1 +bin/varnishhist/varnishhist.1 +bin/varnishstat/varnishstat.1 +bin/varnishreplay/varnishreplay.1 +bin/varnishadm/varnishadm.1 +bin/varnishlog/varnishlog.1 +bin/varnishtop/varnishtop.1 +bin/varnishd/varnishd.1 +man/vcl.7 Copied: branches/1.1/debian/varnish.postinst (from rev 1868, trunk/varnish-cache/debian/varnish.postinst) =================================================================== --- branches/1.1/debian/varnish.postinst (rev 0) +++ branches/1.1/debian/varnish.postinst 2007-08-20 11:02:27 UTC (rev 1887) @@ -0,0 +1,30 @@ +#!/bin/sh + +varnish_setup_user() { + if ! id varnish > /dev/null 2>&1 ; then + adduser --system --no-create-home --group varnish 2>&1 > /dev/null || exit 78 + fi +} + +varnish_setup_user + +# Automatically added by dh_installinit +if [ -x "/etc/init.d/varnish" ]; then + update-rc.d varnish defaults >/dev/null + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d varnish start || exit $? + else + /etc/init.d/varnish start || exit $? + fi +fi +# End automatically added section +# Automatically added by dh_installinit +if [ -x "/etc/init.d/varnishlog" ]; then + update-rc.d varnishlog defaults >/dev/null + if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then + invoke-rc.d varnishlog start || exit $? + else + /etc/init.d/varnishlog start || exit $? + fi +fi +# End automatically added section From phk at projects.linpro.no Mon Aug 20 11:05:08 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 13:05:08 +0200 (CEST) Subject: r1888 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820110508.106B01EC429@projects.linpro.no> Author: phk Date: 2007-08-20 13:05:07 +0200 (Mon, 20 Aug 2007) New Revision: 1888 Modified: trunk/varnish-cache/bin/varnishd/cache_http.c Log: Fix a long-standing bug in pipe-mode: We must pass the protocol version across unchanged, otherwise the semantics of the Connection: header cannot be interpreted correctly by the server. wget(1) could trigger this problem and would have to wait for the server to close the (seemingly idle) connection before continuing. Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-08-20 11:02:27 UTC (rev 1887) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-08-20 11:05:07 UTC (rev 1888) @@ -701,17 +701,20 @@ } static void -http_copyreq(struct http *to, struct http *fm, int forceget) +http_copyreq(struct http *to, struct http *fm, int transparent) { CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - if (forceget) + if (transparent) + http_copyh(to, fm, HTTP_HDR_REQ); + else http_SetH(to, HTTP_HDR_REQ, "GET"); + http_copyh(to, fm, HTTP_HDR_URL); + if (transparent) + http_copyh(to, fm, HTTP_HDR_PROTO); 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 @@ -792,7 +795,7 @@ hp = bereq->http; hp->logtag = HTTP_Tx; - http_copyreq(hp, sp->http, how != HTTPH_R_PIPE); + 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 Aug 20 11:05:48 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 13:05:48 +0200 (CEST) Subject: r1889 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820110548.5C9C41EC37C@projects.linpro.no> Author: phk Date: 2007-08-20 13:05:48 +0200 (Mon, 20 Aug 2007) New Revision: 1889 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: Remove the unnecessary third argument to VBE_ClosedFd() and remove a couple of now pointless debugging messages in pipe mode. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 11:05:07 UTC (rev 1888) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 11:05:48 UTC (rev 1889) @@ -366,7 +366,7 @@ /* cache_backend.c */ void VBE_Init(void); struct vbe_conn *VBE_GetFd(struct sess *sp); -void VBE_ClosedFd(struct worker *w, struct vbe_conn *vc, int already); +void VBE_ClosedFd(struct worker *w, struct vbe_conn *vc); void VBE_RecycleFd(struct worker *w, struct vbe_conn *vc); struct bereq * VBE_new_bereq(void); void VBE_free_bereq(struct bereq *bereq); Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-20 11:05:07 UTC (rev 1888) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-20 11:05:48 UTC (rev 1889) @@ -290,7 +290,7 @@ reuse = 1; break; } - VBE_ClosedFd(sp->wrk, vc, 0); + VBE_ClosedFd(sp->wrk, vc); } if (vc == NULL) { @@ -352,15 +352,14 @@ /* Close a connection ------------------------------------------------*/ void -VBE_ClosedFd(struct worker *w, struct vbe_conn *vc, int already) +VBE_ClosedFd(struct worker *w, struct vbe_conn *vc) { CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); assert(vc->fd >= 0); AN(vc->backend); WSL(w, SLT_BackendClose, vc->fd, "%s", vc->backend->vcl_name); - if (!already) - AZ(close(vc->fd)); + AZ(close(vc->fd)); vc->fd = -1; vc->backend = NULL; LOCK(&vbemtx); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-08-20 11:05:07 UTC (rev 1888) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-08-20 11:05:48 UTC (rev 1889) @@ -346,7 +346,7 @@ TAILQ_REMOVE(&sp->obj->store, st, list); STV_free(st); } - VBE_ClosedFd(sp->wrk, vc, 0); + VBE_ClosedFd(sp->wrk, vc); return (-1); } @@ -364,7 +364,7 @@ cls = 1; if (cls) - VBE_ClosedFd(sp->wrk, vc, 0); + VBE_ClosedFd(sp->wrk, vc); else VBE_RecycleFd(sp->wrk, vc); Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-08-20 11:05:07 UTC (rev 1888) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2007-08-20 11:05:48 UTC (rev 1889) @@ -50,8 +50,6 @@ i = read(fds[idx].fd, buf, sizeof buf); if (i <= 0 || fds[1-idx].events == 0) { - VSL(SLT_Debug, fds[idx].fd, "Pipe Shut read(read)"); - VSL(SLT_Debug, fds[1-idx].fd, "Pipe Shut write(read)"); shutdown(fds[idx].fd, SHUT_RD); shutdown(fds[1-idx].fd, SHUT_WR); fds[idx].events = 0; @@ -59,9 +57,7 @@ } 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)"); + if (j != i) { shutdown(fds[idx].fd, SHUT_WR); shutdown(fds[1-idx].fd, SHUT_RD); fds[1-idx].events = 0; @@ -98,7 +94,7 @@ if (WRK_Flush(w)) { vca_close_session(sp, "pipe"); - VBE_ClosedFd(sp->wrk, vc, 0); + VBE_ClosedFd(sp->wrk, vc); return; } @@ -125,6 +121,5 @@ rdf(fds, 1); } vca_close_session(sp, "pipe"); - (void)close (vc->fd); - VBE_ClosedFd(sp->wrk, vc, 1); + VBE_ClosedFd(sp->wrk, vc); } From des at projects.linpro.no Mon Aug 20 11:08:08 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 13:08:08 +0200 (CEST) Subject: r1890 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070820110808.159C61EC475@projects.linpro.no> Author: des Date: 2007-08-20 13:08:07 +0200 (Mon, 20 Aug 2007) New Revision: 1890 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: Wait longer for Varnish to start. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-20 11:05:48 UTC (rev 1889) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-20 11:08:07 UTC (rev 1890) @@ -136,13 +136,13 @@ $self->{'mux'}->add($self->{'stderr'}); $self->{'mux'}->set_callback_object($self, $self->{'stderr'}); - # Wait up to 0.5 seconds for Varnish to accept our connection + # Wait up to 5 seconds for Varnish to accept our connection # on the management port - for (my $i = 0; $i < 5; ++$i) { + for (my $i = 0; $i < 10; ++$i) { last if $self->{'socket'} = IO::Socket::INET-> new(Type => SOCK_STREAM, PeerAddr => $engine->{'config'}->{'telnet_address'}); - select(undef, undef, undef, 0.1); + select(undef, undef, undef, 0.5); } if (!defined($self->{'socket'})) { kill(15, delete $self->{'pid'}); From ingvar at projects.linpro.no Mon Aug 20 11:37:11 2007 From: ingvar at projects.linpro.no (ingvar at projects.linpro.no) Date: Mon, 20 Aug 2007 13:37:11 +0200 (CEST) Subject: r1891 - branches/1.1/redhat Message-ID: <20070820113711.E25CD1EC37C@projects.linpro.no> Author: ingvar Date: 2007-08-20 13:37:11 +0200 (Mon, 20 Aug 2007) New Revision: 1891 Modified: branches/1.1/redhat/varnish.spec Log: Version number bumped to 1.1.1 in the redhat package Modified: branches/1.1/redhat/varnish.spec =================================================================== --- branches/1.1/redhat/varnish.spec 2007-08-20 11:08:07 UTC (rev 1890) +++ branches/1.1/redhat/varnish.spec 2007-08-20 11:37:11 UTC (rev 1891) @@ -1,6 +1,6 @@ Summary: Varnish is a high-performance HTTP accelerator Name: varnish -Version: 1.1 +Version: 1.1.1 Release: 1%{?dist} License: BSD-like Group: System Environment/Daemons @@ -165,6 +165,8 @@ %postun libs -p /sbin/ldconfig %changelog +* Mon Aug 20 2007 Ingvar Hagelund - 1.1.1-1 +- Bumped the version number to 1.1.1. * Tue Aug 14 2007 Ingvar Hagelund - 1.1.svn - Update for 1.1 branch - Added the devel package for the header files and static library files From phk at projects.linpro.no Mon Aug 20 11:46:26 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 13:46:26 +0200 (CEST) Subject: r1892 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820114626.6352C1EC514@projects.linpro.no> Author: phk Date: 2007-08-20 13:46:26 +0200 (Mon, 20 Aug 2007) New Revision: 1892 Added: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Separate the generic backend handling from the backend "method". For now all we have is a "simple" method, but we want more complex methods later on, round-robin, least-busy and so on. For now, fall into the other ditch and move everything to cache_backend_simple.c, we will move bits back as the gain generality. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-08-20 11:37:11 UTC (rev 1891) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-08-20 11:46:26 UTC (rev 1892) @@ -12,6 +12,7 @@ cache_acceptor_poll.c \ cache_acceptor_kqueue.c \ cache_backend.c \ + cache_backend_simple.c \ cache_ban.c \ cache_center.c \ cache_cli.c \ Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 11:37:11 UTC (rev 1891) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 11:46:26 UTC (rev 1892) @@ -178,7 +178,7 @@ #include "hash_slinger.h" -/* Backend Connection ------------------------------------------------*/ +/* Backend Request ---------------------------------------------------*/ struct bereq { unsigned magic; @@ -189,14 +189,6 @@ struct http http[1]; }; -struct vbe_conn { - unsigned magic; -#define VBE_CONN_MAGIC 0x0c5e6592 - TAILQ_ENTRY(vbe_conn) list; - struct backend *backend; - int fd; -}; - /* Storage -----------------------------------------------------------*/ struct storage { @@ -325,10 +317,40 @@ const char **hashptr; }; +/* -------------------------------------------------------------------*/ + +/* Backend connection */ +struct vbe_conn { + unsigned magic; +#define VBE_CONN_MAGIC 0x0c5e6592 + TAILQ_ENTRY(vbe_conn) list; + struct backend *backend; + int fd; +}; + + +/* Backend method */ +typedef struct vbe_conn *vbe_getfd_f(struct sess *sp); +typedef void vbe_close_f(struct worker *w, struct vbe_conn *vc); +typedef void vbe_recycle_f(struct worker *w, struct vbe_conn *vc); +typedef void vbe_init_f(void); + +struct backend_method { + const char *name; + vbe_getfd_f *getfd; + vbe_close_f *close; + vbe_recycle_f *recycle; + vbe_init_f *init; +}; + +/* Backend indstance */ struct backend { unsigned magic; #define BACKEND_MAGIC 0x64c4c7c6 const char *vcl_name; + + struct backend_method *method; + const char *hostname; const char *portname; @@ -364,6 +386,7 @@ extern int vca_pipes[2]; /* cache_backend.c */ + void VBE_Init(void); struct vbe_conn *VBE_GetFd(struct sess *sp); void VBE_ClosedFd(struct worker *w, struct vbe_conn *vc); @@ -371,6 +394,9 @@ struct bereq * VBE_new_bereq(void); void VBE_free_bereq(struct bereq *bereq); +/* cache_backend_simple.c */ +extern struct backend_method backend_method_simple; + /* cache_ban.c */ void AddBan(const char *, int hash); void BAN_Init(void); Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-20 11:37:11 UTC (rev 1891) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-20 11:46:26 UTC (rev 1892) @@ -28,44 +28,24 @@ * * $Id$ * - * NB: This file is in transition: - * In the future it will contain the central part of the backend handling, - * refcounting, functions for DNS lookup and connection revalidation etc. - * The actual policies will be put in separate files, cache_backend_simple.c, - * cache_backend_round_robin.c etc etc. + * Manage backend connections and requests. * - * Manage backend connections. - * - * XXX: When we switch VCL we can have vbe_conn's dangling from - * XXX: the backends no longer used. When the VCL's refcount - * XXX: drops to zero we should zap them. */ -#include -#include - -#include -#include -#include #include -#include #include -#include -#include -#include #include "heritage.h" #include "shmlog.h" #include "cache.h" -/* 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; -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * Get a http structure for talking to the backend. + */ struct bereq * VBE_new_bereq(void) @@ -108,245 +88,11 @@ /*--------------------------------------------------------------------*/ -static struct vbe_conn * -vbe_new_conn(void) -{ - struct vbe_conn *vbc; - - vbc = calloc(sizeof *vbc, 1); - if (vbc == NULL) - return (NULL); - VSL_stats->n_vbe_conn++; - vbc->magic = VBE_CONN_MAGIC; - vbc->fd = -1; - return (vbc); -} - -/*-------------------------------------------------------------------- - * XXX: There is a race here, we need to lock the replacement of the - * XXX: resolved addresses, or some other thread might try to access - * XXX: them while/during/after we changed them. - * XXX: preferably, we should make a copy to the vbe while we hold a - * XXX: lock anyway. - */ - -static void -vbe_lookup(struct backend *bp) -{ - struct addrinfo *res, hint, *old; - int error; - - memset(&hint, 0, sizeof hint); - hint.ai_family = PF_UNSPEC; - hint.ai_socktype = SOCK_STREAM; - res = NULL; - error = getaddrinfo(bp->hostname, - bp->portname == NULL ? "http" : bp->portname, - &hint, &res); - bp->dnstime = TIM_mono(); - if (error) { - if (res != NULL) - freeaddrinfo(res); - printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */ - return; - } - old = bp->addr; - bp->last_addr = res; - bp->addr = res; - if (old != NULL) - freeaddrinfo(old); -} - -/*--------------------------------------------------------------------*/ - -static int -vbe_sock_conn(const struct addrinfo *ai) -{ - int s; - - s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (s >= 0 && connect(s, ai->ai_addr, ai->ai_addrlen)) { - AZ(close(s)); - s = -1; - } - return (s); -} - -/*--------------------------------------------------------------------*/ - -static int -vbe_conn_try(struct backend *bp, struct addrinfo **pai) -{ - struct addrinfo *ai; - int s; - - /* First try the cached good address, and any following it */ - for (ai = bp->last_addr; ai != NULL; ai = ai->ai_next) { - s = vbe_sock_conn(ai); - if (s >= 0) { - bp->last_addr = ai; - *pai = ai; - return (s); - } - } - - /* Then try the list until the cached last good address */ - for (ai = bp->addr; ai != bp->last_addr; ai = ai->ai_next) { - s = vbe_sock_conn(ai); - if (s >= 0) { - bp->last_addr = ai; - *pai = ai; - return (s); - } - } - - if (bp->dnstime + bp->dnsttl >= TIM_mono()) - return (-1); - - /* Then do another lookup to catch DNS changes */ - vbe_lookup(bp); - - /* And try the entire list */ - for (ai = bp->addr; ai != NULL; ai = ai->ai_next) { - s = vbe_sock_conn(ai); - if (s >= 0) { - bp->last_addr = ai; - *pai = ai; - return (s); - } - } - - return (-1); -} - -static int -vbe_connect(struct sess *sp, struct backend *bp) -{ - int s; - char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE]; - char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE]; - struct addrinfo *ai; - - CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); - AN(bp->hostname); - - s = vbe_conn_try(bp, &ai); - if (s < 0) - return (s); - - TCP_myname(s, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1); - TCP_name(ai->ai_addr, ai->ai_addrlen, - abuf2, sizeof abuf2, pbuf2, sizeof pbuf2); - WSL(sp->wrk, SLT_BackendOpen, s, "%s %s %s %s %s", - bp->vcl_name, abuf1, pbuf1, abuf2, pbuf2); - return (s); -} - -/* Get a backend connection ------------------------------------------ - * - * Try all cached backend connections for this backend, and use the - * first one that is looks like it is still connected. - * If that fails to get us a connection, create a new one, reusing a - * connection from the freelist, if possible. - * - * This function is slightly complicated by optimizations on vbemtx. - */ - -static struct vbe_conn * -vbe_nextfd(struct sess *sp) -{ - struct vbe_conn *vc, *vc2; - struct pollfd pfd; - struct backend *bp; - int reuse = 0; - - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - bp = sp->backend; - CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); - vc2 = NULL; - while (1) { - LOCK(&vbemtx); - vc = TAILQ_FIRST(&bp->connlist); - if (vc != NULL) { - assert(vc->backend == bp); - assert(vc->fd >= 0); - TAILQ_REMOVE(&bp->connlist, vc, list); - } else { - vc2 = TAILQ_FIRST(&vbe_head); - if (vc2 != NULL) { - VSL_stats->backend_unused--; - TAILQ_REMOVE(&vbe_head, vc2, list); - } - } - UNLOCK(&vbemtx); - if (vc == NULL) - break; - - /* Test the connection for remote close before we use it */ - pfd.fd = vc->fd; - pfd.events = POLLIN; - pfd.revents = 0; - if (!poll(&pfd, 1, 0)) { - reuse = 1; - break; - } - VBE_ClosedFd(sp->wrk, vc); - } - - if (vc == NULL) { - if (vc2 == NULL) - vc = vbe_new_conn(); - else - vc = vc2; - if (vc != NULL) { - assert(vc->fd == -1); - AZ(vc->backend); - vc->fd = vbe_connect(sp, bp); - if (vc->fd < 0) { - LOCK(&vbemtx); - TAILQ_INSERT_HEAD(&vbe_head, vc, list); - VSL_stats->backend_unused++; - UNLOCK(&vbemtx); - vc = NULL; - } else { - vc->backend = bp; - } - } - } - LOCK(&vbemtx); - if (vc != NULL ) { - VSL_stats->backend_reuse += reuse; - VSL_stats->backend_conn++; - } else { - VSL_stats->backend_fail++; - } - UNLOCK(&vbemtx); - if (vc != NULL ) { - WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid); - assert(vc->fd >= 0); - assert(vc->backend == bp); - } - return (vc); -} - -/*--------------------------------------------------------------------*/ - struct vbe_conn * VBE_GetFd(struct sess *sp) { - struct vbe_conn *vc; - unsigned n; - for (n = 1; n < 5; n++) { - vc = vbe_nextfd(sp); - if (vc != NULL) { - WSL(sp->wrk, SLT_Backend, sp->fd, "%d %s", vc->fd, - sp->backend->vcl_name); - return (vc); - } - usleep(100000 * n); - } - return (NULL); + return(sp->backend->method->getfd(sp)); } /* Close a connection ------------------------------------------------*/ @@ -355,17 +101,7 @@ VBE_ClosedFd(struct worker *w, struct vbe_conn *vc) { - CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); - assert(vc->fd >= 0); - AN(vc->backend); - WSL(w, SLT_BackendClose, vc->fd, "%s", vc->backend->vcl_name); - AZ(close(vc->fd)); - vc->fd = -1; - vc->backend = NULL; - LOCK(&vbemtx); - TAILQ_INSERT_HEAD(&vbe_head, vc, list); - VSL_stats->backend_unused++; - UNLOCK(&vbemtx); + vc->backend->method->close(w, vc); } /* Recycle a connection ----------------------------------------------*/ @@ -374,14 +110,7 @@ VBE_RecycleFd(struct worker *w, struct vbe_conn *vc) { - CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); - assert(vc->fd >= 0); - AN(vc->backend); - WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); - LOCK(&vbemtx); - VSL_stats->backend_recycle++; - TAILQ_INSERT_HEAD(&vc->backend->connlist, vc, list); - UNLOCK(&vbemtx); + vc->backend->method->recycle(w, vc); } /*--------------------------------------------------------------------*/ @@ -391,4 +120,5 @@ { MTX_INIT(&vbemtx); + backend_method_simple.init(); } Added: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_simple.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2007-08-20 11:46:26 UTC (rev 1892) @@ -0,0 +1,352 @@ +/*- + * 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$ + * + * + * XXX: When we switch VCL we can have vbe_conn's dangling from + * XXX: the backends no longer used. When the VCL's refcount + * XXX: drops to zero we should zap them. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "shmlog.h" +#include "cache.h" + +static TAILQ_HEAD(,vbe_conn) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head); + +static MTX vbemtx; + +/*--------------------------------------------------------------------*/ + +static struct vbe_conn * +vbe_new_conn(void) +{ + struct vbe_conn *vbc; + + vbc = calloc(sizeof *vbc, 1); + if (vbc == NULL) + return (NULL); + VSL_stats->n_vbe_conn++; + vbc->magic = VBE_CONN_MAGIC; + vbc->fd = -1; + return (vbc); +} + +/*-------------------------------------------------------------------- + * XXX: There is a race here, we need to lock the replacement of the + * XXX: resolved addresses, or some other thread might try to access + * XXX: them while/during/after we changed them. + * XXX: preferably, we should make a copy to the vbe while we hold a + * XXX: lock anyway. + */ + +static void +vbe_lookup(struct backend *bp) +{ + struct addrinfo *res, hint, *old; + int error; + + memset(&hint, 0, sizeof hint); + hint.ai_family = PF_UNSPEC; + hint.ai_socktype = SOCK_STREAM; + res = NULL; + error = getaddrinfo(bp->hostname, + bp->portname == NULL ? "http" : bp->portname, + &hint, &res); + bp->dnstime = TIM_mono(); + if (error) { + if (res != NULL) + freeaddrinfo(res); + printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */ + return; + } + old = bp->addr; + bp->last_addr = res; + bp->addr = res; + if (old != NULL) + freeaddrinfo(old); +} + +/*--------------------------------------------------------------------*/ + +static int +vbe_sock_conn(const struct addrinfo *ai) +{ + int s; + + s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (s >= 0 && connect(s, ai->ai_addr, ai->ai_addrlen)) { + AZ(close(s)); + s = -1; + } + return (s); +} + +/*--------------------------------------------------------------------*/ + +static int +vbe_conn_try(struct backend *bp, struct addrinfo **pai) +{ + struct addrinfo *ai; + int s; + + /* First try the cached good address, and any following it */ + for (ai = bp->last_addr; ai != NULL; ai = ai->ai_next) { + s = vbe_sock_conn(ai); + if (s >= 0) { + bp->last_addr = ai; + *pai = ai; + return (s); + } + } + + /* Then try the list until the cached last good address */ + for (ai = bp->addr; ai != bp->last_addr; ai = ai->ai_next) { + s = vbe_sock_conn(ai); + if (s >= 0) { + bp->last_addr = ai; + *pai = ai; + return (s); + } + } + + if (bp->dnstime + bp->dnsttl >= TIM_mono()) + return (-1); + + /* Then do another lookup to catch DNS changes */ + vbe_lookup(bp); + + /* And try the entire list */ + for (ai = bp->addr; ai != NULL; ai = ai->ai_next) { + s = vbe_sock_conn(ai); + if (s >= 0) { + bp->last_addr = ai; + *pai = ai; + return (s); + } + } + + return (-1); +} + +static int +vbe_connect(struct sess *sp, struct backend *bp) +{ + int s; + char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE]; + char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE]; + struct addrinfo *ai; + + CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); + AN(bp->hostname); + + s = vbe_conn_try(bp, &ai); + if (s < 0) + return (s); + + TCP_myname(s, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1); + TCP_name(ai->ai_addr, ai->ai_addrlen, + abuf2, sizeof abuf2, pbuf2, sizeof pbuf2); + WSL(sp->wrk, SLT_BackendOpen, s, "%s %s %s %s %s", + bp->vcl_name, abuf1, pbuf1, abuf2, pbuf2); + return (s); +} + +/* Get a backend connection ------------------------------------------ + * + * Try all cached backend connections for this backend, and use the + * first one that is looks like it is still connected. + * If that fails to get us a connection, create a new one, reusing a + * connection from the freelist, if possible. + * + * This function is slightly complicated by optimizations on vbemtx. + */ + +static struct vbe_conn * +vbe_nextfd(struct sess *sp) +{ + struct vbe_conn *vc, *vc2; + struct pollfd pfd; + struct backend *bp; + int reuse = 0; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + bp = sp->backend; + CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); + vc2 = NULL; + while (1) { + LOCK(&vbemtx); + vc = TAILQ_FIRST(&bp->connlist); + if (vc != NULL) { + assert(vc->backend == bp); + assert(vc->fd >= 0); + TAILQ_REMOVE(&bp->connlist, vc, list); + } else { + vc2 = TAILQ_FIRST(&vbe_head); + if (vc2 != NULL) { + VSL_stats->backend_unused--; + TAILQ_REMOVE(&vbe_head, vc2, list); + } + } + UNLOCK(&vbemtx); + if (vc == NULL) + break; + + /* Test the connection for remote close before we use it */ + pfd.fd = vc->fd; + pfd.events = POLLIN; + pfd.revents = 0; + if (!poll(&pfd, 1, 0)) { + reuse = 1; + break; + } + VBE_ClosedFd(sp->wrk, vc); + } + + if (vc == NULL) { + if (vc2 == NULL) + vc = vbe_new_conn(); + else + vc = vc2; + if (vc != NULL) { + assert(vc->fd == -1); + AZ(vc->backend); + vc->fd = vbe_connect(sp, bp); + if (vc->fd < 0) { + LOCK(&vbemtx); + TAILQ_INSERT_HEAD(&vbe_head, vc, list); + VSL_stats->backend_unused++; + UNLOCK(&vbemtx); + vc = NULL; + } else { + vc->backend = bp; + } + } + } + LOCK(&vbemtx); + if (vc != NULL ) { + VSL_stats->backend_reuse += reuse; + VSL_stats->backend_conn++; + } else { + VSL_stats->backend_fail++; + } + UNLOCK(&vbemtx); + if (vc != NULL ) { + WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid); + assert(vc->fd >= 0); + assert(vc->backend == bp); + } + return (vc); +} + +/*--------------------------------------------------------------------*/ + +static struct vbe_conn * +bes_GetFd(struct sess *sp) +{ + struct vbe_conn *vc; + unsigned n; + + for (n = 1; n < 5; n++) { + vc = vbe_nextfd(sp); + if (vc != NULL) { + WSL(sp->wrk, SLT_Backend, sp->fd, "%d %s", vc->fd, + sp->backend->vcl_name); + return (vc); + } + usleep(100000 * n); + } + return (NULL); +} + +/* Close a connection ------------------------------------------------*/ + +static void +bes_ClosedFd(struct worker *w, struct vbe_conn *vc) +{ + + CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + assert(vc->fd >= 0); + AN(vc->backend); + WSL(w, SLT_BackendClose, vc->fd, "%s", vc->backend->vcl_name); + AZ(close(vc->fd)); + vc->fd = -1; + vc->backend = NULL; + LOCK(&vbemtx); + TAILQ_INSERT_HEAD(&vbe_head, vc, list); + VSL_stats->backend_unused++; + UNLOCK(&vbemtx); +} + +/* Recycle a connection ----------------------------------------------*/ + +static void +bes_RecycleFd(struct worker *w, struct vbe_conn *vc) +{ + + CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + assert(vc->fd >= 0); + AN(vc->backend); + WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); + LOCK(&vbemtx); + VSL_stats->backend_recycle++; + TAILQ_INSERT_HEAD(&vc->backend->connlist, vc, list); + UNLOCK(&vbemtx); +} + +/*--------------------------------------------------------------------*/ + +static void +bes_Init(void) +{ + + MTX_INIT(&vbemtx); +} + + +/*--------------------------------------------------------------------*/ + + +struct backend_method backend_method_simple = { + .name = "simple", + .getfd = bes_GetFd, + .close = bes_ClosedFd, + .recycle = bes_RecycleFd, + .init = bes_Init +}; Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-20 11:37:11 UTC (rev 1891) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-20 11:46:26 UTC (rev 1892) @@ -540,6 +540,8 @@ b->hostname = strdup(t->host); XXXAN(b->hostname); + b->method = &backend_method_simple; + *bp = b; } From phk at projects.linpro.no Mon Aug 20 12:18:16 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 14:18:16 +0200 (CEST) Subject: r1893 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820121816.2A97E1EC37C@projects.linpro.no> Author: phk Date: 2007-08-20 14:18:15 +0200 (Mon, 20 Aug 2007) New Revision: 1893 Modified: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c Log: prefix change vbe -> bes Modified: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2007-08-20 11:46:26 UTC (rev 1892) +++ trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2007-08-20 12:18:15 UTC (rev 1893) @@ -50,12 +50,12 @@ static TAILQ_HEAD(,vbe_conn) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head); -static MTX vbemtx; +static MTX besmtx; /*--------------------------------------------------------------------*/ static struct vbe_conn * -vbe_new_conn(void) +bes_new_conn(void) { struct vbe_conn *vbc; @@ -77,7 +77,7 @@ */ static void -vbe_lookup(struct backend *bp) +bes_lookup(struct backend *bp) { struct addrinfo *res, hint, *old; int error; @@ -106,7 +106,7 @@ /*--------------------------------------------------------------------*/ static int -vbe_sock_conn(const struct addrinfo *ai) +bes_sock_conn(const struct addrinfo *ai) { int s; @@ -121,14 +121,14 @@ /*--------------------------------------------------------------------*/ static int -vbe_conn_try(struct backend *bp, struct addrinfo **pai) +bes_conn_try(struct backend *bp, struct addrinfo **pai) { struct addrinfo *ai; int s; /* First try the cached good address, and any following it */ for (ai = bp->last_addr; ai != NULL; ai = ai->ai_next) { - s = vbe_sock_conn(ai); + s = bes_sock_conn(ai); if (s >= 0) { bp->last_addr = ai; *pai = ai; @@ -138,7 +138,7 @@ /* Then try the list until the cached last good address */ for (ai = bp->addr; ai != bp->last_addr; ai = ai->ai_next) { - s = vbe_sock_conn(ai); + s = bes_sock_conn(ai); if (s >= 0) { bp->last_addr = ai; *pai = ai; @@ -150,11 +150,11 @@ return (-1); /* Then do another lookup to catch DNS changes */ - vbe_lookup(bp); + bes_lookup(bp); /* And try the entire list */ for (ai = bp->addr; ai != NULL; ai = ai->ai_next) { - s = vbe_sock_conn(ai); + s = bes_sock_conn(ai); if (s >= 0) { bp->last_addr = ai; *pai = ai; @@ -166,7 +166,7 @@ } static int -vbe_connect(struct sess *sp, struct backend *bp) +bes_connect(struct sess *sp, struct backend *bp) { int s; char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE]; @@ -176,7 +176,7 @@ CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); AN(bp->hostname); - s = vbe_conn_try(bp, &ai); + s = bes_conn_try(bp, &ai); if (s < 0) return (s); @@ -195,11 +195,11 @@ * If that fails to get us a connection, create a new one, reusing a * connection from the freelist, if possible. * - * This function is slightly complicated by optimizations on vbemtx. + * This function is slightly complicated by optimizations on besmtx. */ static struct vbe_conn * -vbe_nextfd(struct sess *sp) +bes_nextfd(struct sess *sp) { struct vbe_conn *vc, *vc2; struct pollfd pfd; @@ -211,7 +211,7 @@ CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); vc2 = NULL; while (1) { - LOCK(&vbemtx); + LOCK(&besmtx); vc = TAILQ_FIRST(&bp->connlist); if (vc != NULL) { assert(vc->backend == bp); @@ -224,7 +224,7 @@ TAILQ_REMOVE(&vbe_head, vc2, list); } } - UNLOCK(&vbemtx); + UNLOCK(&besmtx); if (vc == NULL) break; @@ -241,32 +241,32 @@ if (vc == NULL) { if (vc2 == NULL) - vc = vbe_new_conn(); + vc = bes_new_conn(); else vc = vc2; if (vc != NULL) { assert(vc->fd == -1); AZ(vc->backend); - vc->fd = vbe_connect(sp, bp); + vc->fd = bes_connect(sp, bp); if (vc->fd < 0) { - LOCK(&vbemtx); + LOCK(&besmtx); TAILQ_INSERT_HEAD(&vbe_head, vc, list); VSL_stats->backend_unused++; - UNLOCK(&vbemtx); + UNLOCK(&besmtx); vc = NULL; } else { vc->backend = bp; } } } - LOCK(&vbemtx); + LOCK(&besmtx); if (vc != NULL ) { VSL_stats->backend_reuse += reuse; VSL_stats->backend_conn++; } else { VSL_stats->backend_fail++; } - UNLOCK(&vbemtx); + UNLOCK(&besmtx); if (vc != NULL ) { WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid); assert(vc->fd >= 0); @@ -284,7 +284,7 @@ unsigned n; for (n = 1; n < 5; n++) { - vc = vbe_nextfd(sp); + vc = bes_nextfd(sp); if (vc != NULL) { WSL(sp->wrk, SLT_Backend, sp->fd, "%d %s", vc->fd, sp->backend->vcl_name); @@ -308,10 +308,10 @@ AZ(close(vc->fd)); vc->fd = -1; vc->backend = NULL; - LOCK(&vbemtx); + LOCK(&besmtx); TAILQ_INSERT_HEAD(&vbe_head, vc, list); VSL_stats->backend_unused++; - UNLOCK(&vbemtx); + UNLOCK(&besmtx); } /* Recycle a connection ----------------------------------------------*/ @@ -324,10 +324,10 @@ assert(vc->fd >= 0); AN(vc->backend); WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); - LOCK(&vbemtx); + LOCK(&besmtx); VSL_stats->backend_recycle++; TAILQ_INSERT_HEAD(&vc->backend->connlist, vc, list); - UNLOCK(&vbemtx); + UNLOCK(&besmtx); } /*--------------------------------------------------------------------*/ @@ -336,7 +336,7 @@ bes_Init(void) { - MTX_INIT(&vbemtx); + MTX_INIT(&besmtx); } From phk at projects.linpro.no Mon Aug 20 12:19:16 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 14:19:16 +0200 (CEST) Subject: r1894 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820121916.EBB901EC2AE@projects.linpro.no> Author: phk Date: 2007-08-20 14:19:16 +0200 (Mon, 20 Aug 2007) New Revision: 1894 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Give backends a reference count and reuse any existing identical backend when a new VCL instantiates a backend. Drop backends when their reference count goes to zero. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 12:18:15 UTC (rev 1893) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 12:19:16 UTC (rev 1894) @@ -347,12 +347,15 @@ struct backend { unsigned magic; #define BACKEND_MAGIC 0x64c4c7c6 - const char *vcl_name; + char *vcl_name; + TAILQ_ENTRY(backend) list; + int refcount; + struct backend_method *method; - const char *hostname; - const char *portname; + char *hostname; + char *portname; struct addrinfo *addr; struct addrinfo *last_addr; @@ -375,6 +378,12 @@ }; +/* + * NB: This list is not locked, it is only ever manipulated from the + * cachers CLI thread. + */ +TAILQ_HEAD(backendlist, backend); + /* Prototypes etc ----------------------------------------------------*/ @@ -393,6 +402,9 @@ void VBE_RecycleFd(struct worker *w, struct vbe_conn *vc); struct bereq * VBE_new_bereq(void); void VBE_free_bereq(struct bereq *bereq); +extern struct backendlist backendlist; +void VBE_DropRef(struct backend *); +struct backend *VBE_NewBackend(struct backend_method *method); /* cache_backend_simple.c */ extern struct backend_method backend_method_simple; Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-20 12:18:15 UTC (rev 1893) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-20 12:19:16 UTC (rev 1894) @@ -41,8 +41,10 @@ static TAILQ_HEAD(,bereq) bereq_head = TAILQ_HEAD_INITIALIZER(bereq_head); -static MTX vbemtx; +static MTX VBE_mtx; +struct backendlist backendlist = TAILQ_HEAD_INITIALIZER(backendlist); + /*-------------------------------------------------------------------- * Get a http structure for talking to the backend. */ @@ -53,11 +55,11 @@ struct bereq *bereq; volatile unsigned len; - LOCK(&vbemtx); + LOCK(&VBE_mtx); bereq = TAILQ_FIRST(&bereq_head); if (bereq != NULL) TAILQ_REMOVE(&bereq_head, bereq, list); - UNLOCK(&vbemtx); + UNLOCK(&VBE_mtx); if (bereq != NULL) { CHECK_OBJ(bereq, BEREQ_MAGIC); } else { @@ -81,13 +83,48 @@ { CHECK_OBJ_NOTNULL(bereq, BEREQ_MAGIC); - LOCK(&vbemtx); + LOCK(&VBE_mtx); TAILQ_INSERT_HEAD(&bereq_head, bereq, list); - UNLOCK(&vbemtx); + UNLOCK(&VBE_mtx); } /*--------------------------------------------------------------------*/ +struct backend * +VBE_NewBackend(struct backend_method *method) +{ + struct backend *b; + + b = calloc(sizeof *b, 1); + XXXAN(b); + b->magic = BACKEND_MAGIC; + TAILQ_INIT(&b->connlist); + b->method = method; + b->refcount = 1; + TAILQ_INSERT_TAIL(&backendlist, b, list); + return (b); +} + +/*--------------------------------------------------------------------*/ + +void +VBE_DropRef(struct backend *b) +{ + + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + + b->refcount--; + if (b->refcount > 0) + return; + TAILQ_REMOVE(&backendlist, b, list); + free(b->vcl_name); + free(b->portname); + free(b->hostname); + free(b); +} + +/*--------------------------------------------------------------------*/ + struct vbe_conn * VBE_GetFd(struct sess *sp) { @@ -119,6 +156,6 @@ VBE_Init(void) { - MTX_INIT(&vbemtx); + MTX_INIT(&VBE_mtx); backend_method_simple.init(); } Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-20 12:18:15 UTC (rev 1893) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-20 12:19:16 UTC (rev 1894) @@ -520,11 +520,27 @@ { struct backend *b; - b = calloc(sizeof *b, 1); - XXXAN(b); - b->magic = BACKEND_MAGIC; + /* + * Scan existing backends to see if we can recycle one of them. + */ + TAILQ_FOREACH(b, &backendlist, list) { + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + if (b->method != &backend_method_simple) + continue; + if (strcmp(b->vcl_name, t->name)) + continue; + if (strcmp(b->portname, t->port)) + continue; + if (strcmp(b->hostname, t->host)) + continue; + b->refcount++; + *bp = b; + return; + } + + b = VBE_NewBackend(&backend_method_simple); + b->dnsttl = 300; - TAILQ_INIT(&b->connlist); b->last_check = TIM_mono(); b->minute_limit = 1; @@ -540,13 +556,12 @@ b->hostname = strdup(t->host); XXXAN(b->hostname); - b->method = &backend_method_simple; - *bp = b; } void VRT_fini_backend(struct backend *b) { - (void)b; + + VBE_DropRef(b); } From phk at projects.linpro.no Mon Aug 20 12:45:58 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 20 Aug 2007 14:45:58 +0200 (CEST) Subject: r1895 - trunk/varnish-cache/bin/varnishd Message-ID: <20070820124558.A3D031EC37C@projects.linpro.no> Author: phk Date: 2007-08-20 14:45:58 +0200 (Mon, 20 Aug 2007) New Revision: 1895 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_backend_simple.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Privatize the "simple" aspect of the simple backend. Move the VRT initializer for simple backends home. Add a backend method to get hostname. This may be a hack. Move fields private to "simple" to its private structure. Add cleanup method to backend, so we can collect the garbage. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 12:19:16 UTC (rev 1894) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-20 12:45:58 UTC (rev 1895) @@ -334,12 +334,16 @@ typedef void vbe_close_f(struct worker *w, struct vbe_conn *vc); typedef void vbe_recycle_f(struct worker *w, struct vbe_conn *vc); typedef void vbe_init_f(void); +typedef const char *vbe_gethostname_f(struct backend *); +typedef void vbe_cleanup_f(struct backend *); struct backend_method { const char *name; vbe_getfd_f *getfd; vbe_close_f *close; vbe_recycle_f *recycle; + vbe_cleanup_f *cleanup; + vbe_gethostname_f *gethostname; vbe_init_f *init; }; @@ -353,29 +357,11 @@ int refcount; struct backend_method *method; + void *priv; - char *hostname; - char *portname; - - struct addrinfo *addr; - struct addrinfo *last_addr; - - TAILQ_HEAD(,vbe_conn) connlist; - - double dnsttl; - double dnstime; - int health; double last_check; int minute_limit; - -#if 0 - double responsetime; - double timeout; - double bandwidth; - int down; -#endif - }; /* Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-20 12:19:16 UTC (rev 1894) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-20 12:45:58 UTC (rev 1895) @@ -98,9 +98,10 @@ b = calloc(sizeof *b, 1); XXXAN(b); b->magic = BACKEND_MAGIC; - TAILQ_INIT(&b->connlist); b->method = method; b->refcount = 1; + b->last_check = TIM_mono(); + b->minute_limit = 1; TAILQ_INSERT_TAIL(&backendlist, b, list); return (b); } @@ -117,9 +118,8 @@ if (b->refcount > 0) return; TAILQ_REMOVE(&backendlist, b, list); + b->method->cleanup(b); free(b->vcl_name); - free(b->portname); - free(b->hostname); free(b); } Modified: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2007-08-20 12:19:16 UTC (rev 1894) +++ trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2007-08-20 12:45:58 UTC (rev 1895) @@ -47,11 +47,24 @@ #include "shmlog.h" #include "cache.h" +#include "vrt.h" static TAILQ_HEAD(,vbe_conn) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head); static MTX besmtx; +struct bes { + unsigned magic; +#define BES_MAGIC 0x015e17ac + char *hostname; + char *portname; + struct addrinfo *addr; + struct addrinfo *last_addr; + double dnsttl; + double dnstime; + TAILQ_HEAD(, vbe_conn) connlist; +}; + /*--------------------------------------------------------------------*/ static struct vbe_conn * @@ -81,24 +94,27 @@ { struct addrinfo *res, hint, *old; int error; + struct bes *bes; + CAST_OBJ_NOTNULL(bes, bp->priv, BES_MAGIC); + memset(&hint, 0, sizeof hint); hint.ai_family = PF_UNSPEC; hint.ai_socktype = SOCK_STREAM; res = NULL; - error = getaddrinfo(bp->hostname, - bp->portname == NULL ? "http" : bp->portname, + error = getaddrinfo(bes->hostname, + bes->portname == NULL ? "http" : bes->portname, &hint, &res); - bp->dnstime = TIM_mono(); + bes->dnstime = TIM_mono(); if (error) { if (res != NULL) freeaddrinfo(res); printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */ return; } - old = bp->addr; - bp->last_addr = res; - bp->addr = res; + old = bes->addr; + bes->last_addr = res; + bes->addr = res; if (old != NULL) freeaddrinfo(old); } @@ -125,38 +141,41 @@ { struct addrinfo *ai; int s; + struct bes *bes; + CAST_OBJ_NOTNULL(bes, bp->priv, BES_MAGIC); + /* First try the cached good address, and any following it */ - for (ai = bp->last_addr; ai != NULL; ai = ai->ai_next) { + for (ai = bes->last_addr; ai != NULL; ai = ai->ai_next) { s = bes_sock_conn(ai); if (s >= 0) { - bp->last_addr = ai; + bes->last_addr = ai; *pai = ai; return (s); } } /* Then try the list until the cached last good address */ - for (ai = bp->addr; ai != bp->last_addr; ai = ai->ai_next) { + for (ai = bes->addr; ai != bes->last_addr; ai = ai->ai_next) { s = bes_sock_conn(ai); if (s >= 0) { - bp->last_addr = ai; + bes->last_addr = ai; *pai = ai; return (s); } } - if (bp->dnstime + bp->dnsttl >= TIM_mono()) + if (bes->dnstime + bes->dnsttl >= TIM_mono()) return (-1); /* Then do another lookup to catch DNS changes */ bes_lookup(bp); /* And try the entire list */ - for (ai = bp->addr; ai != NULL; ai = ai->ai_next) { + for (ai = bes->addr; ai != NULL; ai = ai->ai_next) { s = bes_sock_conn(ai); if (s >= 0) { - bp->last_addr = ai; + bes->last_addr = ai; *pai = ai; return (s); } @@ -172,9 +191,12 @@ char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE]; char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE]; struct addrinfo *ai; + struct bes *bes; + CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); - AN(bp->hostname); + CAST_OBJ_NOTNULL(bes, bp->priv, BES_MAGIC); + AN(bes->hostname); s = bes_conn_try(bp, &ai); if (s < 0) @@ -205,18 +227,20 @@ struct pollfd pfd; struct backend *bp; int reuse = 0; + struct bes *bes; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); bp = sp->backend; CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); + CAST_OBJ_NOTNULL(bes, bp->priv, BES_MAGIC); vc2 = NULL; while (1) { LOCK(&besmtx); - vc = TAILQ_FIRST(&bp->connlist); + vc = TAILQ_FIRST(&bes->connlist); if (vc != NULL) { assert(vc->backend == bp); assert(vc->fd >= 0); - TAILQ_REMOVE(&bp->connlist, vc, list); + TAILQ_REMOVE(&bes->connlist, vc, list); } else { vc2 = TAILQ_FIRST(&vbe_head); if (vc2 != NULL) { @@ -319,34 +343,126 @@ static void bes_RecycleFd(struct worker *w, struct vbe_conn *vc) { + struct bes *bes; CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); + CAST_OBJ_NOTNULL(bes, vc->backend->priv, BES_MAGIC); + assert(vc->fd >= 0); AN(vc->backend); WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); LOCK(&besmtx); VSL_stats->backend_recycle++; - TAILQ_INSERT_HEAD(&vc->backend->connlist, vc, list); + TAILQ_INSERT_HEAD(&bes->connlist, vc, list); UNLOCK(&besmtx); } /*--------------------------------------------------------------------*/ static void +bes_Cleanup(struct backend *b) +{ + struct bes *bes; + struct vbe_conn *vbe; + + CAST_OBJ_NOTNULL(bes, b->priv, BES_MAGIC); + free(bes->portname); + free(bes->hostname); + freeaddrinfo(bes->addr); + while (1) { + vbe = TAILQ_FIRST(&bes->connlist); + if (vbe == NULL) + break; + TAILQ_REMOVE(&bes->connlist, vbe, list); + if (vbe->fd >= 0) + close(vbe->fd); + free(vbe); + } + free(bes); +} + +/*--------------------------------------------------------------------*/ + +static const char * +bes_GetHostname(struct backend *b) +{ + struct bes *bes; + + CHECK_OBJ_NOTNULL(b, SESS_MAGIC); + CAST_OBJ_NOTNULL(bes, b->priv, BES_MAGIC); + return (bes->hostname); +} + +/*--------------------------------------------------------------------*/ + +static void bes_Init(void) { MTX_INIT(&besmtx); } - /*--------------------------------------------------------------------*/ - struct backend_method backend_method_simple = { .name = "simple", .getfd = bes_GetFd, .close = bes_ClosedFd, .recycle = bes_RecycleFd, + .gethostname = bes_GetHostname, + .cleanup = bes_Cleanup, .init = bes_Init }; + +/*--------------------------------------------------------------------*/ + +void +VRT_init_simple_backend(struct backend **bp, struct vrt_simple_backend *t) +{ + struct backend *b; + struct bes *bes; + + /* + * Scan existing backends to see if we can recycle one of them. + */ + TAILQ_FOREACH(b, &backendlist, list) { + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + if (b->method != &backend_method_simple) + continue; + if (strcmp(b->vcl_name, t->name)) + continue; + CAST_OBJ_NOTNULL(bes, b->priv, BES_MAGIC); + if (strcmp(bes->portname, t->port)) + continue; + if (strcmp(bes->hostname, t->host)) + continue; + b->refcount++; + *bp = b; + return; + } + + b = VBE_NewBackend(&backend_method_simple); + + bes = calloc(sizeof *bes, 1); + XXXAN(bes); + bes->magic = BES_MAGIC; + + b->priv = bes; + + bes->dnsttl = 300; + + AN(t->name); + b->vcl_name = strdup(t->name); + XXXAN(b->vcl_name); + + AN(t->port); + bes->portname = strdup(t->port); + XXXAN(bes->portname); + + AN(t->host); + bes->hostname = strdup(t->host); + XXXAN(bes->hostname); + + *bp = b; +} Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2007-08-20 12:19:16 UTC (rev 1894) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2007-08-20 12:45:58 UTC (rev 1895) @@ -800,9 +800,11 @@ 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: This really ought to go into the default VCL */ if (!http_GetHdr(hp, H_Host, &b)) { http_PrintfHeader(sp->wrk, sp->fd, hp, "Host: %s", - sp->backend->hostname); + sp->backend->method->gethostname(sp->backend)); } sp->bereq = bereq; } Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-20 12:19:16 UTC (rev 1894) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-08-20 12:45:58 UTC (rev 1895) @@ -513,52 +513,9 @@ /*-------------------------------------------------------------------- - * Backend stuff, should probably move to its own file eventually + * Backend stuff */ -void -VRT_init_simple_backend(struct backend **bp, struct vrt_simple_backend *t) -{ - struct backend *b; - - /* - * Scan existing backends to see if we can recycle one of them. - */ - TAILQ_FOREACH(b, &backendlist, list) { - CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - if (b->method != &backend_method_simple) - continue; - if (strcmp(b->vcl_name, t->name)) - continue; - if (strcmp(b->portname, t->port)) - continue; - if (strcmp(b->hostname, t->host)) - continue; - b->refcount++; - *bp = b; - return; - } - b = VBE_NewBackend(&backend_method_simple); - - b->dnsttl = 300; - b->last_check = TIM_mono(); - b->minute_limit = 1; - - AN(t->name); - b->vcl_name = strdup(t->name); - XXXAN(b->vcl_name); - - AN(t->port); - b->portname = strdup(t->port); - XXXAN(b->portname); - - AN(t->host); - b->hostname = strdup(t->host); - XXXAN(b->hostname); - - *bp = b; -} - void VRT_fini_backend(struct backend *b) { From des at projects.linpro.no Mon Aug 20 15:18:49 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 17:18:49 +0200 (CEST) Subject: r1896 - trunk/varnish-cache/lib/libvarnish Message-ID: <20070820151849.8D2351EC37C@projects.linpro.no> Author: des Date: 2007-08-20 17:18:49 +0200 (Mon, 20 Aug 2007) New Revision: 1896 Modified: trunk/varnish-cache/lib/libvarnish/flopen.c Log: Correct the lock.l_type logic for platforms where O_RDONLY is 0. Modified: trunk/varnish-cache/lib/libvarnish/flopen.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/flopen.c 2007-08-20 12:45:58 UTC (rev 1895) +++ trunk/varnish-cache/lib/libvarnish/flopen.c 2007-08-20 15:18:49 UTC (rev 1896) @@ -60,7 +60,7 @@ va_end(ap); } - lock.l_type = (flags & O_RDONLY) ? F_RDLCK : F_WRLCK; + lock.l_type = ((flags & O_ACCMODE) == 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 Aug 20 15:22:52 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 17:22:52 +0200 (CEST) Subject: r1897 - in branches/1.1: . lib/libvarnish Message-ID: <20070820152252.CD1FB1EC2AE@projects.linpro.no> Author: des Date: 2007-08-20 17:22:52 +0200 (Mon, 20 Aug 2007) New Revision: 1897 Modified: branches/1.1/ branches/1.1/lib/libvarnish/flopen.c Log: Merged revisions 1896 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1896 | des | 2007-08-20 17:18:49 +0200 (Mon, 20 Aug 2007) | 2 lines Correct the lock.l_type logic for platforms where O_RDONLY is 0. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896 Modified: branches/1.1/lib/libvarnish/flopen.c =================================================================== --- branches/1.1/lib/libvarnish/flopen.c 2007-08-20 15:18:49 UTC (rev 1896) +++ branches/1.1/lib/libvarnish/flopen.c 2007-08-20 15:22:52 UTC (rev 1897) @@ -60,7 +60,7 @@ va_end(ap); } - lock.l_type = (flags & O_RDONLY) ? F_RDLCK : F_WRLCK; + lock.l_type = ((flags & O_ACCMODE) == 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 Aug 20 16:59:16 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 18:59:16 +0200 (CEST) Subject: r1898 - trunk/varnish-cache/doc Message-ID: <20070820165916.953AC1EC37C@projects.linpro.no> Author: des Date: 2007-08-20 18:59:16 +0200 (Mon, 20 Aug 2007) New Revision: 1898 Modified: trunk/varnish-cache/doc/changes-1.1-1.1.1.xml Log: Catch up with recent commits. Modified: trunk/varnish-cache/doc/changes-1.1-1.1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.1-1.1.1.xml 2007-08-20 15:22:52 UTC (rev 1897) +++ trunk/varnish-cache/doc/changes-1.1-1.1.1.xml 2007-08-20 16:59:16 UTC (rev 1898) @@ -23,5 +23,117 @@ A bug that triggered an assertion failure when generating synthetic error documents has been corrected. + + + A new VCL function, purge_url, + provides the same functionality as the + url.purge management command. + + + + Previously, Varnish assumed that the response body should + be sent only if the request method was GET. + This was a problem for custom request methods (such as + PURGE), so the logic has been changed to + always send the response body except in the specific case of a + HEAD request. + + + + Changes to run-time parameters are now correctly + propagated to the child process. + + + + Due to the way run-time parameters are initialized at + startup, varnishd previously required the + nobody user and the + nogroup group to exist even if a different + user and group were specified on the command line. This has + been corrected. + + + + Under certain conditions, the VCL compiler would carry on + after a syntax error instead of exiting after reporting the + error. This has been corrected. + + + + The manner in which the hash string is assembled has been + modified to reduce memory usage and memory-to-memory + copying. + + + + Before calling vcl_miss, Varnish + assembles a tentative request object for the backend request + which will usually follow. This object would be leaked if + vcl_miss returned anything else than + fetch. This has been corrected. + + + + The code necessary to handle an error + return from vcl_fetch and + vcl_deliver had inadvertantly been left + out. This has been corrected. + + + + Varnish no longer prints a spurious "child died" message + (the result of reaping the compiler process) after compiling a + new VCL configuration. + + + + Under some circumstances, due to an error in the workspace + management code, Varnish would lose the "tail" of a request, + i.e. the part of the request that has been received from the + client but not yet processed. The most obvious symptom of this + was that POST requests would work with some browsers but not + others, depending on details of the browser's HTTP + implementation. This has been corrected. + + + + On some platforms, due to incorrect assumptions in the CLI + code, the management process would crash while processing + commands received over the management port. This has been + corrected. + + + + Build system + + + The top-level Makefile will now honor + $DESTDIR when creating the state + directory. + + + + The Debian and RedHat packages are now split into three + (main / lib / devel) as is customary. + + + + A number of compile-time and run-time portability issues + have been addressed. + + + + The autogen.sh script had workarounds + for problems with the GNU autotools on FreeBSD; these are no + longer needed and have been removed. + + + + The libcompat library has been + renamed to libvarnishcompat and is now + dynamic rather than static. This simplifies the build process + and resolves an issue with the Mac OS X linker. + + From des at projects.linpro.no Mon Aug 20 16:59:34 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 18:59:34 +0200 (CEST) Subject: r1899 - in branches/1.1: . doc Message-ID: <20070820165934.34E331EC2AE@projects.linpro.no> Author: des Date: 2007-08-20 18:59:34 +0200 (Mon, 20 Aug 2007) New Revision: 1899 Modified: branches/1.1/ branches/1.1/doc/changes-1.1-1.1.1.xml Log: Merged revisions 1898 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1898 | des | 2007-08-20 18:59:16 +0200 (Mon, 20 Aug 2007) | 2 lines Catch up with recent commits. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896,1898 Modified: branches/1.1/doc/changes-1.1-1.1.1.xml =================================================================== --- branches/1.1/doc/changes-1.1-1.1.1.xml 2007-08-20 16:59:16 UTC (rev 1898) +++ branches/1.1/doc/changes-1.1-1.1.1.xml 2007-08-20 16:59:34 UTC (rev 1899) @@ -23,5 +23,117 @@ A bug that triggered an assertion failure when generating synthetic error documents has been corrected. + + + A new VCL function, purge_url, + provides the same functionality as the + url.purge management command. + + + + Previously, Varnish assumed that the response body should + be sent only if the request method was GET. + This was a problem for custom request methods (such as + PURGE), so the logic has been changed to + always send the response body except in the specific case of a + HEAD request. + + + + Changes to run-time parameters are now correctly + propagated to the child process. + + + + Due to the way run-time parameters are initialized at + startup, varnishd previously required the + nobody user and the + nogroup group to exist even if a different + user and group were specified on the command line. This has + been corrected. + + + + Under certain conditions, the VCL compiler would carry on + after a syntax error instead of exiting after reporting the + error. This has been corrected. + + + + The manner in which the hash string is assembled has been + modified to reduce memory usage and memory-to-memory + copying. + + + + Before calling vcl_miss, Varnish + assembles a tentative request object for the backend request + which will usually follow. This object would be leaked if + vcl_miss returned anything else than + fetch. This has been corrected. + + + + The code necessary to handle an error + return from vcl_fetch and + vcl_deliver had inadvertantly been left + out. This has been corrected. + + + + Varnish no longer prints a spurious "child died" message + (the result of reaping the compiler process) after compiling a + new VCL configuration. + + + + Under some circumstances, due to an error in the workspace + management code, Varnish would lose the "tail" of a request, + i.e. the part of the request that has been received from the + client but not yet processed. The most obvious symptom of this + was that POST requests would work with some browsers but not + others, depending on details of the browser's HTTP + implementation. This has been corrected. + + + + On some platforms, due to incorrect assumptions in the CLI + code, the management process would crash while processing + commands received over the management port. This has been + corrected. + + + + Build system + + + The top-level Makefile will now honor + $DESTDIR when creating the state + directory. + + + + The Debian and RedHat packages are now split into three + (main / lib / devel) as is customary. + + + + A number of compile-time and run-time portability issues + have been addressed. + + + + The autogen.sh script had workarounds + for problems with the GNU autotools on FreeBSD; these are no + longer needed and have been removed. + + + + The libcompat library has been + renamed to libvarnishcompat and is now + dynamic rather than static. This simplifies the build process + and resolves an issue with the Mac OS X linker. + + From des at projects.linpro.no Mon Aug 20 19:04:17 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:04:17 +0200 (CEST) Subject: r1900 - branches/1.1 Message-ID: <20070820190417.0CA411EC37C@projects.linpro.no> Author: des Date: 2007-08-20 21:04:16 +0200 (Mon, 20 Aug 2007) New Revision: 1900 Modified: branches/1.1/configure.ac Log: Bump Modified: branches/1.1/configure.ac =================================================================== --- branches/1.1/configure.ac 2007-08-20 16:59:34 UTC (rev 1899) +++ branches/1.1/configure.ac 2007-08-20 19:04:16 UTC (rev 1900) @@ -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], [1.1], [varnish-dev at projects.linpro.no]) +AC_INIT([Varnish], [1.1.1], [varnish-dev at projects.linpro.no]) AC_CONFIG_SRCDIR(include/varnishapi.h) AM_CONFIG_HEADER(config.h) From des at projects.linpro.no Mon Aug 20 19:04:26 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:04:26 +0200 (CEST) Subject: r1901 - branches/1.1 Message-ID: <20070820190426.40DDA1EC2AE@projects.linpro.no> Author: des Date: 2007-08-20 21:04:26 +0200 (Mon, 20 Aug 2007) New Revision: 1901 Modified: branches/1.1/ChangeLog Log: Regenerate Modified: branches/1.1/ChangeLog =================================================================== --- branches/1.1/ChangeLog 2007-08-20 19:04:16 UTC (rev 1900) +++ branches/1.1/ChangeLog 2007-08-20 19:04:26 UTC (rev 1901) @@ -1,150 +1,77 @@ -Change log for Varnish 1.1 +Change log for Varnish 1.1.1 -Changes between 1.0.4 and 1.1 +Changes between 1.1 and 1.1.1 varnishd - ? Readability of the C source code generated from VCL code has been improved. + ? The code required to allow VCL to read obj.status, which had accidentally + been left out, has now been added. - ? Equality (==) and inequality (!=) operators have been implemented for IP - addresses (which previously could only be compared using ACLs). + ? Varnish will now always include a Connection: header in its reply to the + client, to avoid possible misunderstandings. - ? The address of the listening socket on which the client connection was - received is now available to VCL as the server.ip variable. + ? A bug that triggered an assertion failure when generating synthetic error + documents has been corrected. - ? 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). + ? A new VCL function, purge_url, provides the same functionality as the + url.purge management command. - ? 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. + ? Previously, Varnish assumed that the response body should be sent only if + the request method was GET. This was a problem for custom request methods + (such as PURGE), so the logic has been changed to always send the response + body except in the specific case of a HEAD request. - ? 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 + ? Changes to run-time parameters are now correctly propagated to 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. + ? Due to the way run-time parameters are initialized at startup, varnishd + previously required the nobody user and the nogroup group to exist even if + a different user and group were specified on the command line. This has + been corrected. - ? 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. + ? Under certain conditions, the VCL compiler would carry on after a syntax + error instead of exiting after reporting the error. This has been + corrected. - ? 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. + ? The manner in which the hash string is assembled has been modified to + reduce memory usage and memory-to-memory copying. - ? 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. + ? Before calling vcl_miss, Varnish assembles a tentative request object for + the backend request which will usually follow. This object would be leaked + if vcl_miss returned anything else than fetch. This has been corrected. - ? The new command-line option -F will make varnishd run in the foreground, - without enabling debugging. + ? The code necessary to handle an error return from vcl_fetch and vcl_deliver + had inadvertantly been left out. This has been corrected. - ? 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 no longer prints a spurious "child died" message (the result of + reaping the compiler process) after compiling a new VCL configuration. - ? 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. + ? Under some circumstances, due to an error in the workspace management code, + Varnish would lose the "tail" of a request, i.e. the part of the request + that has been received from the client but not yet processed. The most + obvious symptom of this was that POST requests would work with some + browsers but not others, depending on details of the browser's HTTP + implementation. This has been corrected. - ? 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. + ? On some platforms, due to incorrect assumptions in the CLI code, the + management process would crash while processing commands received over the + management port. This has been corrected. - ? A new VCL hook, vcl_deliver, provides a chance to adjust the response - before it is sent to the client. +Build system - ? A new management command, vcl.show, displays the VCL source code of any - loaded configuration. + ? The top-level Makefile will now honor $DESTDIR when creating the state + directory. - ? A new VCL variable, now, provides VCL scripts with the current time in - seconds since the epoch. + ? The Debian and RedHat packages are now split into three (main / lib / + devel) as is customary. - ? A new VCL variable, obj.lastuse, reflects the time in seconds since the - object in question was last used. + ? A number of compile-time and run-time portability issues have been + addressed. - ? 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. + ? The autogen.sh script had workarounds for problems with the GNU autotools + on FreeBSD; these are no longer needed and have been removed. - ? VCL scripts can now modify the HTTP status code of cached objects - (obj.status) and responses (resp.status) + ? The libcompat library has been renamed to libvarnishcompat and is now + dynamic rather than static. This simplifies the build process and resolves + an issue with the Mac OS X linker. - ? 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 - - ? In addition to client traffic, 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. - -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 (-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 Mon Aug 20 19:13:37 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:13:37 +0200 (CEST) Subject: r1902 - trunk/varnish-cache/doc Message-ID: <20070820191337.557031EC37C@projects.linpro.no> Author: des Date: 2007-08-20 21:13:37 +0200 (Mon, 20 Aug 2007) New Revision: 1902 Modified: trunk/varnish-cache/doc/changes-html.xsl trunk/varnish-cache/doc/changes.css Log: Render elements. Modified: trunk/varnish-cache/doc/changes-html.xsl =================================================================== --- trunk/varnish-cache/doc/changes-html.xsl 2007-08-20 19:04:26 UTC (rev 1901) +++ trunk/varnish-cache/doc/changes-html.xsl 2007-08-20 19:13:37 UTC (rev 1902) @@ -72,4 +72,18 @@ + + + + + + + + + Warning: no template for element + + + + Modified: trunk/varnish-cache/doc/changes.css =================================================================== --- trunk/varnish-cache/doc/changes.css 2007-08-20 19:04:26 UTC (rev 1901) +++ trunk/varnish-cache/doc/changes.css 2007-08-20 19:13:37 UTC (rev 1902) @@ -25,3 +25,7 @@ font-weight: bold; color: maroon; } + +code { + font-family: monospace; +} From des at projects.linpro.no Mon Aug 20 19:16:09 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:16:09 +0200 (CEST) Subject: r1903 - trunk/varnish-cache/doc Message-ID: <20070820191609.318E41EC2AE@projects.linpro.no> Author: des Date: 2007-08-20 21:16:08 +0200 (Mon, 20 Aug 2007) New Revision: 1903 Modified: trunk/varnish-cache/doc/changes-html.xsl trunk/varnish-cache/doc/changes.css Log: Really render elements correctly. Modified: trunk/varnish-cache/doc/changes-html.xsl =================================================================== --- trunk/varnish-cache/doc/changes-html.xsl 2007-08-20 19:13:37 UTC (rev 1902) +++ trunk/varnish-cache/doc/changes-html.xsl 2007-08-20 19:16:08 UTC (rev 1903) @@ -74,9 +74,12 @@ - + + + + - + Modified: trunk/varnish-cache/doc/changes.css =================================================================== --- trunk/varnish-cache/doc/changes.css 2007-08-20 19:13:37 UTC (rev 1902) +++ trunk/varnish-cache/doc/changes.css 2007-08-20 19:16:08 UTC (rev 1903) @@ -26,6 +26,6 @@ color: maroon; } -code { +.code { font-family: monospace; } From des at projects.linpro.no Mon Aug 20 19:17:49 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:17:49 +0200 (CEST) Subject: r1904 - trunk/varnish-cache/doc Message-ID: <20070820191749.B93451EC404@projects.linpro.no> Author: des Date: 2007-08-20 21:17:49 +0200 (Mon, 20 Aug 2007) New Revision: 1904 Modified: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml trunk/varnish-cache/doc/changes-1.1-1.1.1.xml Log: At some point along the line, I forgot that these files aren't actually DocBook, and that I don't have , , etc. - just . Modified: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.0.4-1.1.xml 2007-08-20 19:16:08 UTC (rev 1903) +++ trunk/varnish-cache/doc/changes-1.0.4-1.1.xml 2007-08-20 19:17:49 UTC (rev 1904) @@ -13,8 +13,8 @@ - Equality (==) and inequality - (!=) operators have been implemented for IP + Equality (==) and inequality + (!=) operators have been implemented for IP addresses (which previously could only be compared using ACLs). @@ -22,15 +22,15 @@ The address of the listening socket on which the client connection was received is now available to VCL as the - server.ip variable. + 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 + 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 + not to include the value of the Host: header in the hash). @@ -53,9 +53,9 @@ 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, + 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. @@ -63,9 +63,9 @@ Objects which are received from the backend with a - Vary: header are now stored separately + Vary: header are now stored separately according to the values of the headers specified in - Vary:. This allows Varnish to correctly + Vary:. This allows Varnish to correctly cache e.g. compressed and uncompressed versions of the same object. @@ -81,8 +81,8 @@ - When invoked with the option, - varnishd will now not just translate the VCL + 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. @@ -94,26 +94,26 @@ - The new command-line option will make - varnishd run in the foreground, without + The new command-line option -F 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). + (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 + varnishstat and other statistics-gathering tools. @@ -122,29 +122,29 @@ 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 + A VCL hook, vcl_discard, is allowed to inspect each object and determine its fate by returning either - keep or discard. + keep or discard. - A new VCL hook, vcl_deliver, provides + 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, + A new management command, vcl.show, displays the VCL source code of any loaded configuration. - A new VCL variable, now, provides VCL + A new VCL variable, now, provides VCL scripts with the current time in seconds since the epoch. - A new VCL variable, obj.lastuse, + A new VCL variable, obj.lastuse, reflects the time in seconds since the object in question was last used. @@ -153,13 +153,13 @@ 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. + remove keyword. VCL scripts can now modify the HTTP status code of cached - objects (obj.status) and responses - (resp.status) + objects (obj.status) and responses + (resp.status) @@ -170,12 +170,12 @@ VCL scripts can now apply regular expression substitutions - to textual variables using the regsub + to textual variables using the regsub function. - A new management command, status, + A new management command, status, returns the state of the child. @@ -190,7 +190,7 @@ 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 + stdout, greatly simplifying the use of the management port from scripts. @@ -213,12 +213,12 @@ In addition to client traffic, - varnishncsa can now also process log data + varnishncsa can now also process log data from backend traffic. - A bug that would cause varnishncsa to + A bug that would cause varnishncsa to segfault when it encountered an empty HTTP header in the log file has been fixed. @@ -241,12 +241,12 @@ 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. + of the varnishd process. The user interface has been greatly improved; - varnishstat will no longer print more than + 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, @@ -260,8 +260,8 @@ The user interface has been greatly improved; - varnishtop will now respond correctly to - window resize events, and one-shot mode () + 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. Modified: trunk/varnish-cache/doc/changes-1.1-1.1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.1-1.1.1.xml 2007-08-20 19:16:08 UTC (rev 1903) +++ trunk/varnish-cache/doc/changes-1.1-1.1.1.xml 2007-08-20 19:17:49 UTC (rev 1904) @@ -9,13 +9,13 @@ The code required to allow VCL to read - obj.status, which had accidentally been left + 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 + Connection: header in its reply to the client, to avoid possible misunderstandings. @@ -25,18 +25,18 @@ - A new VCL function, purge_url, + A new VCL function, purge_url, provides the same functionality as the - url.purge management command. + url.purge management command. Previously, Varnish assumed that the response body should - be sent only if the request method was GET. + be sent only if the request method was GET. This was a problem for custom request methods (such as - PURGE), so the logic has been changed to + PURGE), so the logic has been changed to always send the response body except in the specific case of a - HEAD request. + HEAD request. @@ -46,9 +46,9 @@ Due to the way run-time parameters are initialized at - startup, varnishd previously required the - nobody user and the - nogroup group to exist even if a different + startup, varnishd previously required the + nobody user and the + nogroup group to exist even if a different user and group were specified on the command line. This has been corrected. @@ -66,17 +66,17 @@ - Before calling vcl_miss, Varnish + Before calling vcl_miss, Varnish assembles a tentative request object for the backend request which will usually follow. This object would be leaked if - vcl_miss returned anything else than - fetch. This has been corrected. + vcl_miss returned anything else than + fetch. This has been corrected. - The code necessary to handle an error - return from vcl_fetch and - vcl_deliver had inadvertantly been left + The code necessary to handle an error + return from vcl_fetch and + vcl_deliver had inadvertantly been left out. This has been corrected. @@ -109,7 +109,7 @@ The top-level Makefile will now honor - $DESTDIR when creating the state + $DESTDIR when creating the state directory. @@ -124,14 +124,14 @@ - The autogen.sh script had workarounds + The autogen.sh script had workarounds for problems with the GNU autotools on FreeBSD; these are no longer needed and have been removed. - The libcompat library has been - renamed to libvarnishcompat and is now + The libcompat library has been + renamed to libvarnishcompat and is now dynamic rather than static. This simplifies the build process and resolves an issue with the Mac OS X linker. From des at projects.linpro.no Mon Aug 20 19:20:25 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:20:25 +0200 (CEST) Subject: r1905 - trunk/varnish-cache/doc Message-ID: <20070820192025.7EB231EC2AE@projects.linpro.no> Author: des Date: 2007-08-20 21:20:25 +0200 (Mon, 20 Aug 2007) New Revision: 1905 Modified: trunk/varnish-cache/doc/changes-1.0.4-1.1.xml trunk/varnish-cache/doc/changes-1.1-1.1.1.xml Log: Rewrap (no content 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-08-20 19:17:49 UTC (rev 1904) +++ trunk/varnish-cache/doc/changes-1.0.4-1.1.xml 2007-08-20 19:20:25 UTC (rev 1905) @@ -27,11 +27,11 @@ 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). + 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). @@ -53,21 +53,20 @@ 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. + 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. + 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. @@ -82,8 +81,8 @@ 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 + 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. @@ -95,18 +94,17 @@ The new command-line option -F will make - varnishd run in the foreground, without - enabling debugging. + 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 + bereq.proto and bereq.http) and the + response to the client (resp.proto, + resp.status, resp.response and resp.http). @@ -122,31 +120,31 @@ 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 + 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 + 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 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, 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. + A new VCL variable, obj.lastuse, reflects the + time in seconds since the object in question was last + used. @@ -175,8 +173,8 @@ - A new management command, status, - returns the state of the child. + A new management command, status, returns the + state of the child. @@ -212,9 +210,8 @@ varnishncsa - In addition to client traffic, - varnishncsa can now also process log data - from backend traffic. + In addition to client traffic, varnishncsa + can now also process log data from backend traffic. @@ -246,12 +243,12 @@ 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. + 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. @@ -260,10 +257,10 @@ 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 + 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. Modified: trunk/varnish-cache/doc/changes-1.1-1.1.1.xml =================================================================== --- trunk/varnish-cache/doc/changes-1.1-1.1.1.xml 2007-08-20 19:17:49 UTC (rev 1904) +++ trunk/varnish-cache/doc/changes-1.1-1.1.1.xml 2007-08-20 19:20:25 UTC (rev 1905) @@ -9,14 +9,14 @@ The code required to allow VCL to read - obj.status, which had accidentally been left - out, has now been added. + 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. + Varnish will now always include a Connection: + header in its reply to the client, to avoid possible + misunderstandings. @@ -25,17 +25,17 @@ - A new VCL function, purge_url, - provides the same functionality as the - url.purge management command. + A new VCL function, purge_url, provides the + same functionality as the url.purge management + command. Previously, Varnish assumed that the response body should - be sent only if the request method was GET. - This was a problem for custom request methods (such as - PURGE), so the logic has been changed to - always send the response body except in the specific case of a + be sent only if the request method was GET. This + was a problem for custom request methods (such as + PURGE), so the logic has been changed to always + send the response body except in the specific case of a HEAD request. @@ -47,10 +47,9 @@ Due to the way run-time parameters are initialized at startup, varnishd previously required the - nobody user and the - nogroup group to exist even if a different - user and group were specified on the command line. This has - been corrected. + nobody user and the nogroup group to + exist even if a different user and group were specified on the + command line. This has been corrected. @@ -66,18 +65,17 @@ - Before calling vcl_miss, Varnish - assembles a tentative request object for the backend request - which will usually follow. This object would be leaked if + Before calling vcl_miss, Varnish assembles a + tentative request object for the backend request which will + usually follow. This object would be leaked if vcl_miss returned anything else than fetch. This has been corrected. - The code necessary to handle an error - return from vcl_fetch and - vcl_deliver had inadvertantly been left - out. This has been corrected. + The code necessary to handle an error return + from vcl_fetch and vcl_deliver had + inadvertantly been left out. This has been corrected. @@ -109,8 +107,7 @@ The top-level Makefile will now honor - $DESTDIR when creating the state - directory. + $DESTDIR when creating the state directory. @@ -124,16 +121,16 @@ - The autogen.sh script had workarounds - for problems with the GNU autotools on FreeBSD; these are no - longer needed and have been removed. + The autogen.sh script had workarounds for + problems with the GNU autotools on FreeBSD; these are no longer + needed and have been removed. - The libcompat library has been - renamed to libvarnishcompat and is now - dynamic rather than static. This simplifies the build process - and resolves an issue with the Mac OS X linker. + The libcompat library has been renamed to + libvarnishcompat and is now dynamic rather than + static. This simplifies the build process and resolves an issue + with the Mac OS X linker. From des at projects.linpro.no Mon Aug 20 19:20:48 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:20:48 +0200 (CEST) Subject: r1906 - in branches/1.1: . doc Message-ID: <20070820192048.420CB1EC404@projects.linpro.no> Author: des Date: 2007-08-20 21:20:48 +0200 (Mon, 20 Aug 2007) New Revision: 1906 Modified: branches/1.1/ branches/1.1/doc/changes-1.0.4-1.1.xml branches/1.1/doc/changes-1.1-1.1.1.xml branches/1.1/doc/changes-html.xsl branches/1.1/doc/changes.css Log: Merged revisions 1902-1905 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1902 | des | 2007-08-20 21:13:37 +0200 (Mon, 20 Aug 2007) | 2 lines Render elements. ........ r1903 | des | 2007-08-20 21:16:08 +0200 (Mon, 20 Aug 2007) | 2 lines Really render elements correctly. ........ r1904 | des | 2007-08-20 21:17:49 +0200 (Mon, 20 Aug 2007) | 4 lines At some point along the line, I forgot that these files aren't actually DocBook, and that I don't have , , etc. - just . ........ r1905 | des | 2007-08-20 21:20:25 +0200 (Mon, 20 Aug 2007) | 2 lines Rewrap (no content changes) ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896,1898 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896,1898,1902-1905 Modified: branches/1.1/doc/changes-1.0.4-1.1.xml =================================================================== --- branches/1.1/doc/changes-1.0.4-1.1.xml 2007-08-20 19:20:25 UTC (rev 1905) +++ branches/1.1/doc/changes-1.0.4-1.1.xml 2007-08-20 19:20:48 UTC (rev 1906) @@ -13,8 +13,8 @@ - Equality (==) and inequality - (!=) operators have been implemented for IP + Equality (==) and inequality + (!=) operators have been implemented for IP addresses (which previously could only be compared using ACLs). @@ -22,16 +22,16 @@ The address of the listening socket on which the client connection was received is now available to VCL as the - server.ip variable. + 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). + 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). @@ -53,21 +53,20 @@ 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. + 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. + 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. @@ -81,9 +80,9 @@ - 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 + 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. @@ -94,26 +93,25 @@ - The new command-line option will make - varnishd run in the foreground, without - enabling debugging. + The new command-line option -F 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). + (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 + varnishstat and other statistics-gathering tools. @@ -122,44 +120,44 @@ 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 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 + 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 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, 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. + 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. + remove keyword. VCL scripts can now modify the HTTP status code of cached - objects (obj.status) and responses - (resp.status) + objects (obj.status) and responses + (resp.status) @@ -170,13 +168,13 @@ VCL scripts can now apply regular expression substitutions - to textual variables using the regsub + to textual variables using the regsub function. - A new management command, status, - returns the state of the child. + A new management command, status, returns the + state of the child. @@ -190,7 +188,7 @@ 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 + stdout, greatly simplifying the use of the management port from scripts. @@ -212,13 +210,12 @@ varnishncsa - In addition to client traffic, - varnishncsa can now also process log data - from backend traffic. + In addition to client traffic, varnishncsa + can now also process log data from backend traffic. - A bug that would cause varnishncsa to + A bug that would cause varnishncsa to segfault when it encountered an empty HTTP header in the log file has been fixed. @@ -241,17 +238,17 @@ 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. + 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. + 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. @@ -260,10 +257,10 @@ 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 + 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. Modified: branches/1.1/doc/changes-1.1-1.1.1.xml =================================================================== --- branches/1.1/doc/changes-1.1-1.1.1.xml 2007-08-20 19:20:25 UTC (rev 1905) +++ branches/1.1/doc/changes-1.1-1.1.1.xml 2007-08-20 19:20:48 UTC (rev 1906) @@ -9,14 +9,14 @@ The code required to allow VCL to read - obj.status, which had accidentally been left - out, has now been added. + 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. + Varnish will now always include a Connection: + header in its reply to the client, to avoid possible + misunderstandings. @@ -25,18 +25,18 @@ - A new VCL function, purge_url, - provides the same functionality as the - url.purge management command. + A new VCL function, purge_url, provides the + same functionality as the url.purge management + command. Previously, Varnish assumed that the response body should - be sent only if the request method was GET. - This was a problem for custom request methods (such as - PURGE), so the logic has been changed to - always send the response body except in the specific case of a - HEAD request. + be sent only if the request method was GET. This + was a problem for custom request methods (such as + PURGE), so the logic has been changed to always + send the response body except in the specific case of a + HEAD request. @@ -46,11 +46,10 @@ Due to the way run-time parameters are initialized at - startup, varnishd previously required the - nobody user and the - nogroup group to exist even if a different - user and group were specified on the command line. This has - been corrected. + startup, varnishd previously required the + nobody user and the nogroup group to + exist even if a different user and group were specified on the + command line. This has been corrected. @@ -66,18 +65,17 @@ - Before calling vcl_miss, Varnish - assembles a tentative request object for the backend request - which will usually follow. This object would be leaked if - vcl_miss returned anything else than - fetch. This has been corrected. + Before calling vcl_miss, Varnish assembles a + tentative request object for the backend request which will + usually follow. This object would be leaked if + vcl_miss returned anything else than + fetch. This has been corrected. - The code necessary to handle an error - return from vcl_fetch and - vcl_deliver had inadvertantly been left - out. This has been corrected. + The code necessary to handle an error return + from vcl_fetch and vcl_deliver had + inadvertantly been left out. This has been corrected. @@ -109,8 +107,7 @@ The top-level Makefile will now honor - $DESTDIR when creating the state - directory. + $DESTDIR when creating the state directory. @@ -124,16 +121,16 @@ - The autogen.sh script had workarounds - for problems with the GNU autotools on FreeBSD; these are no - longer needed and have been removed. + The autogen.sh script had workarounds for + problems with the GNU autotools on FreeBSD; these are no longer + needed and have been removed. - The libcompat library has been - renamed to libvarnishcompat and is now - dynamic rather than static. This simplifies the build process - and resolves an issue with the Mac OS X linker. + The libcompat library has been renamed to + libvarnishcompat and is now dynamic rather than + static. This simplifies the build process and resolves an issue + with the Mac OS X linker. Modified: branches/1.1/doc/changes-html.xsl =================================================================== --- branches/1.1/doc/changes-html.xsl 2007-08-20 19:20:25 UTC (rev 1905) +++ branches/1.1/doc/changes-html.xsl 2007-08-20 19:20:48 UTC (rev 1906) @@ -72,4 +72,21 @@ + + + + + + + + + + + + Warning: no template for element + + + + Modified: branches/1.1/doc/changes.css =================================================================== --- branches/1.1/doc/changes.css 2007-08-20 19:20:25 UTC (rev 1905) +++ branches/1.1/doc/changes.css 2007-08-20 19:20:48 UTC (rev 1906) @@ -25,3 +25,7 @@ font-weight: bold; color: maroon; } + +.code { + font-family: monospace; +} From des at projects.linpro.no Mon Aug 20 19:27:08 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:27:08 +0200 (CEST) Subject: r1907 - trunk/varnish-cache/doc Message-ID: <20070820192708.EE3941EC2AE@projects.linpro.no> Author: des Date: 2007-08-20 21:27:08 +0200 (Mon, 20 Aug 2007) New Revision: 1907 Modified: trunk/varnish-cache/doc/Makefile.am Log: Distribute all the files that are needed to recreate the change logs, and add an explicit dependency so the logs are regenerated if the stylesheet changes. Modified: trunk/varnish-cache/doc/Makefile.am =================================================================== --- trunk/varnish-cache/doc/Makefile.am 2007-08-20 19:20:48 UTC (rev 1906) +++ trunk/varnish-cache/doc/Makefile.am 2007-08-20 19:27:08 UTC (rev 1907) @@ -7,7 +7,7 @@ all: ${CHANGELOGS} -EXTRA_DIST = ${CHANGELOGS} +EXTRA_DIST = ${CHANGELOGS} changes.css changes-html.xsl CLEANFILES = ${CHANGELOGS} @@ -15,3 +15,5 @@ .xml.html: ${XSLTPROC} --xinclude -o $@ $< + +${CHANGELOGS}: changes-html.xsl From des at projects.linpro.no Mon Aug 20 19:27:26 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:27:26 +0200 (CEST) Subject: r1908 - in branches/1.1: . doc Message-ID: <20070820192726.D79BE1EC404@projects.linpro.no> Author: des Date: 2007-08-20 21:27:26 +0200 (Mon, 20 Aug 2007) New Revision: 1908 Modified: branches/1.1/ branches/1.1/doc/Makefile.am Log: Merged revisions 1907 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1907 | des | 2007-08-20 21:27:08 +0200 (Mon, 20 Aug 2007) | 4 lines Distribute all the files that are needed to recreate the change logs, and add an explicit dependency so the logs are regenerated if the stylesheet changes. ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896,1898,1902-1905 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896,1898,1902-1905,1907 Modified: branches/1.1/doc/Makefile.am =================================================================== --- branches/1.1/doc/Makefile.am 2007-08-20 19:27:08 UTC (rev 1907) +++ branches/1.1/doc/Makefile.am 2007-08-20 19:27:26 UTC (rev 1908) @@ -7,7 +7,7 @@ all: ${CHANGELOGS} -EXTRA_DIST = ${CHANGELOGS} +EXTRA_DIST = ${CHANGELOGS} changes.css changes-html.xsl CLEANFILES = ${CHANGELOGS} @@ -15,3 +15,5 @@ .xml.html: ${XSLTPROC} --xinclude -o $@ $< + +${CHANGELOGS}: changes-html.xsl From des at projects.linpro.no Mon Aug 20 19:49:38 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:49:38 +0200 (CEST) Subject: r1909 - trunk/varnish-cache/doc Message-ID: <20070820194938.BAB481EC2AE@projects.linpro.no> Author: des Date: 2007-08-20 21:49:38 +0200 (Mon, 20 Aug 2007) New Revision: 1909 Modified: trunk/varnish-cache/doc/Makefile.am Log: Even more files... Modified: trunk/varnish-cache/doc/Makefile.am =================================================================== --- trunk/varnish-cache/doc/Makefile.am 2007-08-20 19:27:26 UTC (rev 1908) +++ trunk/varnish-cache/doc/Makefile.am 2007-08-20 19:49:38 UTC (rev 1909) @@ -5,9 +5,16 @@ changes-1.1.html \ changes-1.1.1.html +XML = \ + changes-1.0.3-1.0.4.xml \ + changes-1.0.4-1.1.xml \ + changes-1.1-1.1.1.xml \ + ${CHANGELOGS:.html=.xml} + all: ${CHANGELOGS} -EXTRA_DIST = ${CHANGELOGS} changes.css changes-html.xsl +EXTRA_DIST = ${CHANGELOGS} ${XML} \ + changes.css changes-html.xsl CLEANFILES = ${CHANGELOGS} @@ -16,4 +23,4 @@ .xml.html: ${XSLTPROC} --xinclude -o $@ $< -${CHANGELOGS}: changes-html.xsl +${CHANGELOGS}: changes-html.xsl From des at projects.linpro.no Mon Aug 20 19:49:59 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 21:49:59 +0200 (CEST) Subject: r1910 - in branches/1.1: . doc Message-ID: <20070820194959.2B43C1EC37C@projects.linpro.no> Author: des Date: 2007-08-20 21:49:59 +0200 (Mon, 20 Aug 2007) New Revision: 1910 Modified: branches/1.1/ branches/1.1/doc/Makefile.am Log: Merged revisions 1909 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1909 | des | 2007-08-20 21:49:38 +0200 (Mon, 20 Aug 2007) | 2 lines Even more files... ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896,1898,1902-1905,1907 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896,1898,1902-1905,1907,1909 Modified: branches/1.1/doc/Makefile.am =================================================================== --- branches/1.1/doc/Makefile.am 2007-08-20 19:49:38 UTC (rev 1909) +++ branches/1.1/doc/Makefile.am 2007-08-20 19:49:59 UTC (rev 1910) @@ -5,9 +5,16 @@ changes-1.1.html \ changes-1.1.1.html +XML = \ + changes-1.0.3-1.0.4.xml \ + changes-1.0.4-1.1.xml \ + changes-1.1-1.1.1.xml \ + ${CHANGELOGS:.html=.xml} + all: ${CHANGELOGS} -EXTRA_DIST = ${CHANGELOGS} changes.css changes-html.xsl +EXTRA_DIST = ${CHANGELOGS} ${XML} \ + changes.css changes-html.xsl CLEANFILES = ${CHANGELOGS} @@ -16,4 +23,4 @@ .xml.html: ${XSLTPROC} --xinclude -o $@ $< -${CHANGELOGS}: changes-html.xsl +${CHANGELOGS}: changes-html.xsl From des at projects.linpro.no Mon Aug 20 20:05:29 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 22:05:29 +0200 (CEST) Subject: r1911 - tags Message-ID: <20070820200529.09C5D1EC2AE@projects.linpro.no> Author: des Date: 2007-08-20 22:05:28 +0200 (Mon, 20 Aug 2007) New Revision: 1911 Added: tags/varnish-1.1.1/ Log: Tag 1.1.1. Copied: tags/varnish-1.1.1 (from rev 1910, branches/1.1) From des at projects.linpro.no Mon Aug 20 21:11:16 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 20 Aug 2007 23:11:16 +0200 (CEST) Subject: r1912 - trunk/varnish-cache/doc Message-ID: <20070820211116.12DA81EC6DB@projects.linpro.no> Author: des Date: 2007-08-20 23:11:15 +0200 (Mon, 20 Aug 2007) New Revision: 1912 Added: trunk/varnish-cache/doc/changes-wiki.xsl Log: Add a stylesheet that does a pretty good job of generating Trac-compatible WikiText from a change log. Added: trunk/varnish-cache/doc/changes-wiki.xsl =================================================================== --- trunk/varnish-cache/doc/changes-wiki.xsl (rev 0) +++ trunk/varnish-cache/doc/changes-wiki.xsl 2007-08-20 21:11:15 UTC (rev 1912) @@ -0,0 +1,76 @@ + + +]> + + + + + + + + == + + ==&lf; + + + + + Change log for + + + + + + + === + Changes between + + and + + ===&lf; + + + + + ==== + + ====&lf; + + + + + * + + + + + + &lf; + + + + # + + + + + {{{ + + }}} + + + + + + + + Warning: no template for element + + + + + Property changes on: trunk/varnish-cache/doc/changes-wiki.xsl ___________________________________________________________________ Name: svn:keywords + Id From phk at projects.linpro.no Tue Aug 21 09:23:32 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 21 Aug 2007 11:23:32 +0200 (CEST) Subject: r1913 - trunk/varnish-cache/bin/varnishd Message-ID: <20070821092332.38F321EC37C@projects.linpro.no> Author: phk Date: 2007-08-21 11:23:31 +0200 (Tue, 21 Aug 2007) New Revision: 1913 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c Log: Make sure wrk->used is always set when we park on an object, we might be unlucky multiple times in which case the responsibility falls back to cnt_lookup(). Fixes 144. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-20 21:11:15 UTC (rev 1912) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-21 09:23:31 UTC (rev 1913) @@ -524,7 +524,12 @@ */ WSL(sp->wrk, SLT_Debug, sp->fd, "on waiting list on obj %u", sp->obj->xid); - assert(!isnan(sp->wrk->used)); + /* + * There is a non-zero risk that we come here more than once + * before we get through, in that case cnt_recv must be set + */ + if (isnan(sp->wrk->used)) + sp->wrk->used = TIM_real(); SES_Charge(sp); return (1); } From phk at phk.freebsd.dk Tue Aug 21 09:24:58 2007 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Tue, 21 Aug 2007 09:24:58 +0000 Subject: r1913 - trunk/varnish-cache/bin/varnishd In-Reply-To: Your message of "Tue, 21 Aug 2007 11:23:32 +0200." <20070821092332.38F321EC37C@projects.linpro.no> Message-ID: <85894.1187688298@critter.freebsd.dk> In message <20070821092332.38F321EC37C at projects.linpro.no>, phk at projects.linpro .no writes: >Author: phk >Date: 2007-08-21 11:23:31 +0200 (Tue, 21 Aug 2007) >New Revision: 1913 > >Modified: > trunk/varnish-cache/bin/varnishd/cache_center.c >Log: >Make sure wrk->used is always set when we park on an object, we might be >unlucky multiple times in which case the responsibility falls back to >cnt_lookup(). > >Fixes 144. More coffee: Fixes #150 -- 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 knutroy at projects.linpro.no Tue Aug 21 11:48:57 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Tue, 21 Aug 2007 13:48:57 +0200 (CEST) Subject: r1914 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070821114857.867C21EC460@projects.linpro.no> Author: knutroy Date: 2007-08-21 13:48:57 +0200 (Tue, 21 Aug 2007) New Revision: 1914 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm Log: * Connect to management socket after select-loop is started. * Removed Varnish::Test::Varnish::kill() which we do not use. (Varnish::Test::Varnish::shutdown() does kill() and more.) Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-08-21 09:23:31 UTC (rev 1913) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Engine.pm 2007-08-21 11:48:57 UTC (rev 1914) @@ -73,6 +73,13 @@ $self->{'server'} = Varnish::Test::Server->new($self); $self->{'varnish'} = Varnish::Test::Varnish->new($self); + my ($ev) = $self->run_loop('ev_varnish_started', 'ev_varnish_timeout'); + + if ($ev eq 'ev_varnish_timeout') { + $self->{'varnish'}->shutdown; + die "Varnish did not start\n"; + } + return $self; } Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-21 09:23:31 UTC (rev 1913) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Varnish.pm 2007-08-21 11:48:57 UTC (rev 1914) @@ -136,22 +136,12 @@ $self->{'mux'}->add($self->{'stderr'}); $self->{'mux'}->set_callback_object($self, $self->{'stderr'}); - # Wait up to 5 seconds for Varnish to accept our connection - # on the management port - for (my $i = 0; $i < 10; ++$i) { - last if $self->{'socket'} = IO::Socket::INET-> - new(Type => SOCK_STREAM, - PeerAddr => $engine->{'config'}->{'telnet_address'}); - select(undef, undef, undef, 0.5); - } - if (!defined($self->{'socket'})) { - kill(15, delete $self->{'pid'}); - die "Varnish did not start\n"; - } - $self->{'mux'}->add($self->{'socket'}); - $self->{'mux'}->set_callback_object($self, $self->{'socket'}); - $self->{'state'} = 'stopped'; + # If we don't hear "rolling(2)..." from Varnish's STDERR within 5 + # seconds, something must be wrong. + $self->{'mux'}->set_timeout($self->{'stderr'}, 5); + $self->{'state'} = 'init'; + return $self; } @@ -277,23 +267,26 @@ if $self->{'pid'}; } -sub kill($;$) { - my ($self, $signal) = @_; - - $signal ||= 15; - die "Not running\n" - unless defined($self->{'pid'}); - kill($signal, $self->{'pid'}); - delete $self->{'pid'}; -} - sub mux_input($$$$) { my ($self, $mux, $fh, $data) = @_; $self->log($$data); - $self->{'mux'}->set_timeout($fh, undef); - if ($fh == $self->{'socket'}) { + if ($fh == $self->{'stderr'} and $$data =~ s/^rolling\(2\)\.\.\.//m) { + # Varnish appears to have been started correctly, so connect + # to management socket. + $self->{'mux'}->set_timeout($fh, undef); + $self->{'state'} = 'stopped'; + $self->{'socket'} = IO::Socket::INET + ->new('Type' => SOCK_STREAM, + 'PeerAddr' => $self->{'engine'}->{'config'}->{'telnet_address'}); + die "Unable to connect to management socket\n" + unless defined($self->{'socket'}); + $self->{'mux'}->add($self->{'socket'}); + $self->{'mux'}->set_callback_object($self, $self->{'socket'}); + $self->{'engine'}->ev_varnish_started; + } elsif (exists($self->{'socket'}) and $fh == $self->{'socket'}) { + $self->{'mux'}->set_timeout($fh, undef); die "syntax error\n" unless ($$data =~ m/^([1-5][0-9][0-9]) (\d+) *$/m); my ($line, $code, $len) = ($&, $1, $2); From des at projects.linpro.no Tue Aug 21 15:36:59 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 21 Aug 2007 17:36:59 +0200 (CEST) Subject: r1915 - trunk/varnish-cache/bin/varnishd Message-ID: <20070821153659.A38C81EC2B1@projects.linpro.no> Author: des Date: 2007-08-21 17:36:59 +0200 (Tue, 21 Aug 2007) New Revision: 1915 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Try to make this comment a little more visible. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-08-21 11:48:57 UTC (rev 1914) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2007-08-21 15:36:59 UTC (rev 1915) @@ -70,7 +70,9 @@ /*--------------------------------------------------------------------*/ -/* keep this in synch with man/vcl.7 */ +/* + * Keep this in synch with man/vcl.7 and etc/default.vcl! + */ static const char *default_vcl = "sub vcl_recv {\n" " if (req.request != \"GET\" && req.request != \"HEAD\") {\n" From des at projects.linpro.no Tue Aug 21 15:37:17 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 21 Aug 2007 17:37:17 +0200 (CEST) Subject: r1916 - in trunk/varnish-cache: etc man Message-ID: <20070821153717.6245A1EC429@projects.linpro.no> Author: des Date: 2007-08-21 17:37:17 +0200 (Tue, 21 Aug 2007) New Revision: 1916 Modified: trunk/varnish-cache/etc/default.vcl trunk/varnish-cache/man/vcl.7 Log: Synchronize with bin/varnishd/mgt_vcc.c. Modified: trunk/varnish-cache/etc/default.vcl =================================================================== --- trunk/varnish-cache/etc/default.vcl 2007-08-21 15:36:59 UTC (rev 1915) +++ trunk/varnish-cache/etc/default.vcl 2007-08-21 15:37:17 UTC (rev 1916) @@ -47,6 +47,8 @@ ## Called when entering an object into the cache # #sub vcl_hash { +# set req.hash += req.url; +# set req.hash += req.http.host; # hash; #} # Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2007-08-21 15:36:59 UTC (rev 1915) +++ trunk/varnish-cache/man/vcl.7 2007-08-21 15:37:17 UTC (rev 1916) @@ -513,6 +513,8 @@ } sub vcl_hash { + set req.hash += req.url; + set req.hash += req.http.host; hash; } From phk at projects.linpro.no Tue Aug 21 16:48:00 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 21 Aug 2007 18:48:00 +0200 (CEST) Subject: r1917 - trunk/varnish-cache/bin/varnishd Message-ID: <20070821164800.7EB091EC2B1@projects.linpro.no> Author: phk Date: 2007-08-21 18:48:00 +0200 (Tue, 21 Aug 2007) New Revision: 1917 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c Log: Be much more paranoid about backends, now that they can go away. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-21 15:37:17 UTC (rev 1916) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2007-08-21 16:48:00 UTC (rev 1917) @@ -297,7 +297,9 @@ int i; AN(sp->bereq); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); i = Fetch(sp); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); /* Experimental. Set time for last check of backend health. * If the backend replied with 200, it is obviously up and running, @@ -426,6 +428,7 @@ /* Experimental. Reduce health parameter of backend towards zero * if it has been more than a minute since it was checked. */ + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); time_diff = TIM_mono() - sp->backend->last_check; minutes = time_diff / 60; if (minutes > sp->backend->minute_limit) { @@ -759,7 +762,9 @@ http_DoConnection(sp); /* By default we use the first backend */ + AZ(sp->backend); sp->backend = sp->vcl->backend[0]; + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); /* XXX: Handle TRACE & OPTIONS of Max-Forwards = 0 */ @@ -817,6 +822,8 @@ CHECK_OBJ(w->nobj, OBJECT_MAGIC); if (w->nobjhead != NULL) CHECK_OBJ(w->nobjhead, OBJHEAD_MAGIC); + if (sp->backend != NULL) + CHECK_OBJ(sp->backend, BACKEND_MAGIC); switch (sp->step) { #define STEP(l,u) case STP_##u: done = cnt_##l(sp); break; From phk at projects.linpro.no Tue Aug 21 18:57:14 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 21 Aug 2007 20:57:14 +0200 (CEST) Subject: r1918 - trunk/varnish-cache/bin/varnishd Message-ID: <20070821185714.669641EC429@projects.linpro.no> Author: phk Date: 2007-08-21 20:57:14 +0200 (Tue, 21 Aug 2007) New Revision: 1918 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.c Log: Move the connection (data structure pool) into the generic backend handling. Add more asserts. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-21 16:48:00 UTC (rev 1917) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-21 18:57:14 UTC (rev 1918) @@ -355,6 +355,7 @@ TAILQ_ENTRY(backend) list; int refcount; + pthread_mutex_t mtx; struct backend_method *method; void *priv; @@ -390,7 +391,10 @@ void VBE_free_bereq(struct bereq *bereq); extern struct backendlist backendlist; void VBE_DropRef(struct backend *); +void VBE_DropRefLocked(struct backend *); struct backend *VBE_NewBackend(struct backend_method *method); +struct vbe_conn *VBE_NewConn(void); +void VBE_ReleaseConn(struct vbe_conn *); /* cache_backend_simple.c */ extern struct backend_method backend_method_simple; Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-21 16:48:00 UTC (rev 1917) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-08-21 18:57:14 UTC (rev 1918) @@ -40,6 +40,7 @@ #include "cache.h" static TAILQ_HEAD(,bereq) bereq_head = TAILQ_HEAD_INITIALIZER(bereq_head); +static TAILQ_HEAD(,vbe_conn) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head); static MTX VBE_mtx; @@ -90,6 +91,50 @@ /*--------------------------------------------------------------------*/ +struct vbe_conn * +VBE_NewConn(void) +{ + struct vbe_conn *vc; + + vc = TAILQ_FIRST(&vbe_head); + if (vc != NULL) { + LOCK(&VBE_mtx); + vc = TAILQ_FIRST(&vbe_head); + if (vc != NULL) { + VSL_stats->backend_unused--; + TAILQ_REMOVE(&vbe_head, vc, list); + } else { + VSL_stats->n_vbe_conn++; + } + UNLOCK(&VBE_mtx); + } + if (vc != NULL) + return (vc); + + vc = calloc(sizeof *vc, 1); + XXXAN(vc); + vc->magic = VBE_CONN_MAGIC; + vc->fd = -1; + return (vc); +} + +/*--------------------------------------------------------------------*/ + +void +VBE_ReleaseConn(struct vbe_conn *vc) +{ + + CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + assert(vc->backend == NULL); + assert(vc->fd < 0); + LOCK(&VBE_mtx); + TAILQ_INSERT_HEAD(&vbe_head, vc, list); + VSL_stats->backend_unused++; + UNLOCK(&VBE_mtx); +} + +/*--------------------------------------------------------------------*/ + struct backend * VBE_NewBackend(struct backend_method *method) { @@ -99,9 +144,13 @@ XXXAN(b); b->magic = BACKEND_MAGIC; b->method = method; + + MTX_INIT(&b->mtx); b->refcount = 1; + b->last_check = TIM_mono(); b->minute_limit = 1; + TAILQ_INSERT_TAIL(&backendlist, b, list); return (b); } @@ -109,26 +158,44 @@ /*--------------------------------------------------------------------*/ void -VBE_DropRef(struct backend *b) +VBE_DropRefLocked(struct backend *b) { + int i; CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - b->refcount--; - if (b->refcount > 0) + i = --b->refcount; + if (i == 0) + TAILQ_REMOVE(&backendlist, b, list); + UNLOCK(&b->mtx); + if (i) return; - TAILQ_REMOVE(&backendlist, b, list); + b->magic = 0; b->method->cleanup(b); free(b->vcl_name); free(b); } +void +VBE_DropRef(struct backend *b) +{ + + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + + LOCK(&b->mtx); + VBE_DropRefLocked(b); +} + /*--------------------------------------------------------------------*/ struct vbe_conn * VBE_GetFd(struct sess *sp) { + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); + AN(sp->backend->method); + AN(sp->backend->method->getfd); return(sp->backend->method->getfd(sp)); } @@ -137,8 +204,15 @@ void VBE_ClosedFd(struct worker *w, struct vbe_conn *vc) { + struct backend *b; - vc->backend->method->close(w, vc); + CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); + b = vc->backend; + AN(b->method); + AN(b->method->close); + b->method->close(w, vc); + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); } /* Recycle a connection ----------------------------------------------*/ @@ -146,8 +220,15 @@ void VBE_RecycleFd(struct worker *w, struct vbe_conn *vc) { + struct backend *b; - vc->backend->method->recycle(w, vc); + CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); + b = vc->backend; + AN(b->method); + AN(b->method->recycle); + b->method->recycle(w, vc); + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); } /*--------------------------------------------------------------------*/ From phk at projects.linpro.no Tue Aug 21 18:59:35 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 21 Aug 2007 20:59:35 +0200 (CEST) Subject: r1919 - trunk/varnish-cache/bin/varnishd Message-ID: <20070821185935.C60DE1EC2B1@projects.linpro.no> Author: phk Date: 2007-08-21 20:59:35 +0200 (Tue, 21 Aug 2007) New Revision: 1919 Modified: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c trunk/varnish-cache/bin/varnishd/cache_fetch.c Log: Almost total rewrite, but same functionality, hopefully less the races in ticket #144. Use per backend mutex, do refcounts right, protect the address structures with a sequence number. Should close #144. Modified: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2007-08-21 18:57:14 UTC (rev 1918) +++ trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2007-08-21 18:59:35 UTC (rev 1919) @@ -49,10 +49,6 @@ #include "cache.h" #include "vrt.h" -static TAILQ_HEAD(,vbe_conn) vbe_head = TAILQ_HEAD_INITIALIZER(vbe_head); - -static MTX besmtx; - struct bes { unsigned magic; #define BES_MAGIC 0x015e17ac @@ -62,42 +58,100 @@ struct addrinfo *last_addr; double dnsttl; double dnstime; + unsigned dnsseq; TAILQ_HEAD(, vbe_conn) connlist; }; /*--------------------------------------------------------------------*/ -static struct vbe_conn * -bes_new_conn(void) + +static int +bes_conn_try_list(struct sess *sp, struct bes *bes) { - struct vbe_conn *vbc; + struct addrinfo *ai, *from; + struct sockaddr_storage ss; + int fam, sockt, proto; + socklen_t alen; + int s, loops; + char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE]; + char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE]; + unsigned myseq; - vbc = calloc(sizeof *vbc, 1); - if (vbc == NULL) - return (NULL); - VSL_stats->n_vbe_conn++; - vbc->magic = VBE_CONN_MAGIC; - vbc->fd = -1; - return (vbc); + /* Called with lock held */ + myseq = bes->dnsseq; + loops = 0; + from = bes->last_addr; + for (ai = from; ai != NULL && (loops != 1 || ai != from);) { + fam = ai->ai_family; + sockt = ai->ai_socktype; + proto = ai->ai_protocol; + alen = ai->ai_addrlen; + assert(alen <= sizeof ss); + memcpy(&ss, ai->ai_addr, alen); + UNLOCK(&sp->backend->mtx); + s = socket(fam, sockt, proto); + if (s >= 0 && connect(s, (void *)&ss, alen)) { + AZ(close(s)); + s = -1; + } + if (s >= 0) { + TCP_myname(s, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1); + TCP_name((void*)&ss, alen, + abuf2, sizeof abuf2, pbuf2, sizeof pbuf2); + WSL(sp->wrk, SLT_BackendOpen, s, "%s %s %s %s %s", + sp->backend->vcl_name, abuf1, pbuf1, abuf2, pbuf2); + } + LOCK(&sp->backend->mtx); + if (s >= 0) { + if (myseq == bes->dnsseq) + bes->last_addr = ai; + return (s); + } + if (myseq != bes->dnsseq) { + loops = 0; + from = bes->last_addr; + ai = from; + } else { + ai = ai->ai_next; + if (ai == NULL) { + loops++; + ai = bes->addr; + } + } + } + return (-1); } -/*-------------------------------------------------------------------- - * XXX: There is a race here, we need to lock the replacement of the - * XXX: resolved addresses, or some other thread might try to access - * XXX: them while/during/after we changed them. - * XXX: preferably, we should make a copy to the vbe while we hold a - * XXX: lock anyway. - */ +/*--------------------------------------------------------------------*/ -static void -bes_lookup(struct backend *bp) +static int +bes_conn_try(struct sess *sp, struct backend *bp) { + int s; + struct bes *bes; struct addrinfo *res, hint, *old; int error; - struct bes *bes; CAST_OBJ_NOTNULL(bes, bp->priv, BES_MAGIC); + LOCK(&bp->mtx); + + s = bes_conn_try_list(sp, bes); + if (s >= 0) { + bp->refcount++; + UNLOCK(&bp->mtx); + return (s); + } + + if (bes->dnstime + bes->dnsttl >= TIM_mono()) { + UNLOCK(&bp->mtx); + return (-1); + } + + /* Then do another lookup to catch DNS changes */ + bes->dnstime = TIM_mono(); + UNLOCK(&bp->mtx); + memset(&hint, 0, sizeof hint); hint.ai_family = PF_UNSPEC; hint.ai_socktype = SOCK_STREAM; @@ -105,111 +159,33 @@ error = getaddrinfo(bes->hostname, bes->portname == NULL ? "http" : bes->portname, &hint, &res); - bes->dnstime = TIM_mono(); if (error) { if (res != NULL) freeaddrinfo(res); printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */ - return; + LOCK(&bp->mtx); + } else { + LOCK(&bp->mtx); + bes->dnsseq++; + old = bes->addr; + bes->last_addr = res; + bes->addr = res; + if (old != NULL) + freeaddrinfo(old); } - old = bes->addr; - bes->last_addr = res; - bes->addr = res; - if (old != NULL) - freeaddrinfo(old); -} -/*--------------------------------------------------------------------*/ - -static int -bes_sock_conn(const struct addrinfo *ai) -{ - int s; - - s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (s >= 0 && connect(s, ai->ai_addr, ai->ai_addrlen)) { - AZ(close(s)); - s = -1; - } - return (s); -} - -/*--------------------------------------------------------------------*/ - -static int -bes_conn_try(struct backend *bp, struct addrinfo **pai) -{ - struct addrinfo *ai; - int s; - struct bes *bes; - - CAST_OBJ_NOTNULL(bes, bp->priv, BES_MAGIC); - - /* First try the cached good address, and any following it */ - for (ai = bes->last_addr; ai != NULL; ai = ai->ai_next) { - s = bes_sock_conn(ai); - if (s >= 0) { - bes->last_addr = ai; - *pai = ai; - return (s); - } - } - - /* Then try the list until the cached last good address */ - for (ai = bes->addr; ai != bes->last_addr; ai = ai->ai_next) { - s = bes_sock_conn(ai); - if (s >= 0) { - bes->last_addr = ai; - *pai = ai; - return (s); - } - } - - if (bes->dnstime + bes->dnsttl >= TIM_mono()) - return (-1); - - /* Then do another lookup to catch DNS changes */ - bes_lookup(bp); - /* And try the entire list */ - for (ai = bes->addr; ai != NULL; ai = ai->ai_next) { - s = bes_sock_conn(ai); - if (s >= 0) { - bes->last_addr = ai; - *pai = ai; - return (s); - } + s = bes_conn_try_list(sp, bes); + if (s >= 0) { + bp->refcount++; + UNLOCK(&bp->mtx); + return (s); } + UNLOCK(&bp->mtx); return (-1); } -static int -bes_connect(struct sess *sp, struct backend *bp) -{ - int s; - char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE]; - char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE]; - struct addrinfo *ai; - struct bes *bes; - - - CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); - CAST_OBJ_NOTNULL(bes, bp->priv, BES_MAGIC); - AN(bes->hostname); - - s = bes_conn_try(bp, &ai); - if (s < 0) - return (s); - - TCP_myname(s, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1); - TCP_name(ai->ai_addr, ai->ai_addrlen, - abuf2, sizeof abuf2, pbuf2, sizeof pbuf2); - WSL(sp->wrk, SLT_BackendOpen, s, "%s %s %s %s %s", - bp->vcl_name, abuf1, pbuf1, abuf2, pbuf2); - return (s); -} - /* Get a backend connection ------------------------------------------ * * Try all cached backend connections for this backend, and use the @@ -223,32 +199,26 @@ static struct vbe_conn * bes_nextfd(struct sess *sp) { - struct vbe_conn *vc, *vc2; + struct vbe_conn *vc; struct pollfd pfd; struct backend *bp; int reuse = 0; struct bes *bes; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); bp = sp->backend; - CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); CAST_OBJ_NOTNULL(bes, bp->priv, BES_MAGIC); - vc2 = NULL; while (1) { - LOCK(&besmtx); + LOCK(&bp->mtx); vc = TAILQ_FIRST(&bes->connlist); if (vc != NULL) { + bp->refcount++; assert(vc->backend == bp); assert(vc->fd >= 0); TAILQ_REMOVE(&bes->connlist, vc, list); - } else { - vc2 = TAILQ_FIRST(&vbe_head); - if (vc2 != NULL) { - VSL_stats->backend_unused--; - TAILQ_REMOVE(&vbe_head, vc2, list); - } } - UNLOCK(&besmtx); + UNLOCK(&bp->mtx); if (vc == NULL) break; @@ -257,45 +227,25 @@ pfd.events = POLLIN; pfd.revents = 0; if (!poll(&pfd, 1, 0)) { - reuse = 1; - break; + /* XXX locking of stats */ + VSL_stats->backend_reuse += reuse; + VSL_stats->backend_conn++; + return (vc); } VBE_ClosedFd(sp->wrk, vc); } - if (vc == NULL) { - if (vc2 == NULL) - vc = bes_new_conn(); - else - vc = vc2; - if (vc != NULL) { - assert(vc->fd == -1); - AZ(vc->backend); - vc->fd = bes_connect(sp, bp); - if (vc->fd < 0) { - LOCK(&besmtx); - TAILQ_INSERT_HEAD(&vbe_head, vc, list); - VSL_stats->backend_unused++; - UNLOCK(&besmtx); - vc = NULL; - } else { - vc->backend = bp; - } - } - } - LOCK(&besmtx); - if (vc != NULL ) { - VSL_stats->backend_reuse += reuse; - VSL_stats->backend_conn++; - } else { + vc = VBE_NewConn(); + assert(vc->fd == -1); + AZ(vc->backend); + vc->fd = bes_conn_try(sp, bp); + if (vc->fd < 0) { + VBE_ReleaseConn(vc); VSL_stats->backend_fail++; - } - UNLOCK(&besmtx); - if (vc != NULL ) { - WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid); - assert(vc->fd >= 0); - assert(vc->backend == bp); - } + return (NULL); + } + vc->backend = bp; + VSL_stats->backend_conn++; return (vc); } @@ -306,15 +256,18 @@ { struct vbe_conn *vc; unsigned n; - for (n = 1; n < 5; n++) { vc = bes_nextfd(sp); - if (vc != NULL) { - WSL(sp->wrk, SLT_Backend, sp->fd, "%d %s", vc->fd, - sp->backend->vcl_name); - return (vc); + if (vc == NULL) { + usleep(100000 * n); + continue; } - usleep(100000 * n); + assert(vc->fd >= 0); + assert(vc->backend == sp->backend); + WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid); + WSL(sp->wrk, SLT_Backend, sp->fd, "%d %s", vc->fd, + sp->backend->vcl_name); + return (vc); } return (NULL); } @@ -326,16 +279,14 @@ { CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); assert(vc->fd >= 0); - AN(vc->backend); WSL(w, SLT_BackendClose, vc->fd, "%s", vc->backend->vcl_name); AZ(close(vc->fd)); vc->fd = -1; + VBE_DropRef(vc->backend); vc->backend = NULL; - LOCK(&besmtx); - TAILQ_INSERT_HEAD(&vbe_head, vc, list); - VSL_stats->backend_unused++; - UNLOCK(&besmtx); + VBE_ReleaseConn(vc); } /* Recycle a connection ----------------------------------------------*/ @@ -350,12 +301,11 @@ CAST_OBJ_NOTNULL(bes, vc->backend->priv, BES_MAGIC); assert(vc->fd >= 0); - AN(vc->backend); WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); - LOCK(&besmtx); + LOCK(&vc->backend->mtx); VSL_stats->backend_recycle++; TAILQ_INSERT_HEAD(&bes->connlist, vc, list); - UNLOCK(&besmtx); + VBE_DropRefLocked(vc->backend); } /*--------------------------------------------------------------------*/ @@ -366,6 +316,7 @@ struct bes *bes; struct vbe_conn *vbe; + assert(b->refcount == 0); CAST_OBJ_NOTNULL(bes, b->priv, BES_MAGIC); free(bes->portname); free(bes->hostname); @@ -400,7 +351,6 @@ bes_Init(void) { - MTX_INIT(&besmtx); } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-08-21 18:57:14 UTC (rev 1918) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2007-08-21 18:59:35 UTC (rev 1919) @@ -276,11 +276,14 @@ sp->obj->xid = sp->xid; + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); vc = VBE_GetFd(sp); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); if (vc == NULL) return (1); WRK_Reset(w, &vc->fd); http_Write(w, hp, 0); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); if (WRK_Flush(w)) { /* XXX: cleanup */ @@ -294,6 +297,7 @@ CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); if (http_RecvHead(hp, vc->fd)) { /* XXX: cleanup */ return (1); @@ -302,6 +306,7 @@ /* XXX: cleanup */ return (1); } + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); @@ -311,23 +316,28 @@ assert(sp->obj->busy != 0); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); if (http_GetHdr(hp, H_Last_Modified, &b)) sp->obj->last_modified = TIM_parse(b); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); /* Filter into object */ hp2 = &sp->obj->http; len = hp->rx_e - hp->rx_s; len += 256; /* margin for content-length etc */ + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); b = malloc(len); AN(b); http_Setup(hp2, b, len); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); hp2->logtag = HTTP_Obj; http_CopyResp(hp2, hp); http_FilterFields(sp->wrk, sp->fd, hp2, hp, HTTPH_A_INS); http_CopyHome(sp->wrk, sp->fd, hp2); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); if (body) { if (http_GetHdr(hp, H_Content_Length, &b)) cls = fetch_straight(sp, vc->fd, hp, b); @@ -340,6 +350,7 @@ } else cls = 0; + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); if (cls < 0) { while (!TAILQ_EMPTY(&sp->obj->store)) { st = TAILQ_FIRST(&sp->obj->store); @@ -350,6 +361,7 @@ return (-1); } + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); { /* Sanity check fetch methods accounting */ unsigned uu; @@ -360,13 +372,16 @@ assert(uu == sp->obj->len); } + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); if (http_GetHdr(hp, H_Connection, &b) && !strcasecmp(b, "close")) cls = 1; + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); if (cls) VBE_ClosedFd(sp->wrk, vc); else VBE_RecycleFd(sp->wrk, vc); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); return (0); } From knutroy at projects.linpro.no Fri Aug 24 13:45:12 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Fri, 24 Aug 2007 15:45:12 +0200 (CEST) Subject: r1920 - in trunk/varnish-tools: . autobuild Message-ID: <20070824134512.1AE861EC2AE@projects.linpro.no> Author: knutroy Date: 2007-08-24 15:45:11 +0200 (Fri, 24 Aug 2007) New Revision: 1920 Added: trunk/varnish-tools/autobuild/ trunk/varnish-tools/autobuild/README trunk/varnish-tools/autobuild/autobuild.sh trunk/varnish-tools/autobuild/mksummary.pl trunk/varnish-tools/autobuild/summary.html Log: Added first release of automatic build and test utility. Added: trunk/varnish-tools/autobuild/README =================================================================== --- trunk/varnish-tools/autobuild/README (rev 0) +++ trunk/varnish-tools/autobuild/README 2007-08-24 13:45:11 UTC (rev 1920) @@ -0,0 +1,70 @@ +Automatic Build and Test Utility +================================ + +The tools found in this directory may be used to automate periodic +building and regression testing of Varnish. + + +Cron-based Invocation +--------------------- + +Start by installing autobuild.sh, mksummary.pl, and summary.html into +an empty directory and configure cron(8) to run this new copy of +autobuild.sh periodically. + +autobuild.sh will start by looking up the most recent revision number +on the Subversion server and compare this number to the revision +number of the last autobuild, which is kept in a file called +LAST_TESTED_REVISION. + +If the numbers are identical, autobuild.sh will exit and be done. + +If not, the new revision is checked out, configured, built, installed +into a directory tree under /tmp, and finally, tested using the +regression test framework. + +The test result is extracted and the summary file, index.html is +updated with the new result. + +A web-server may be used to make index.html and the sub-directories +(which are the working directories of the individual autobuild runs) +available to the world. + + +Manual Invocation +----------------- + +autobuild.sh may also be invoked manually and takes an optional +argument which will be interpreted as a Subversion revision number. +This revision will then be processed in the same way as described +above. + + +Working Directories +------------------- + +Each time autobuild.sh builds and tests a revision, a working +directory is created inside the directory where autobuild.sh is +located. This working directory is used to hold the checked-out +revision as well as log files generated during building and testing. +The name of the working directory indicates the time (UTC) of its +creation. + +In addition to the checked-out revision residing in the sub-directory +"trunk", the following files are stored in a working directory: + + svn.log - output to STDOUT and STDERR during Subversion checkout + build.log - output to STDOUT and STDERR during configure, build, and install + regress.log - output to STDOUT and STDERR during regression testing + regress.bin - Varnish's storage cache file during regression testing + regress.html - HTML-formatted result of regression testing + regress.status - summary of regress.html, used by mksummary.pl + + +Summary file +------------ + +Currently, the overall summary file, index.html, is generated from +scratch based on the currently present working directories, every time +autobuild.sh completes successfully. The summary file is generated by +the Perl script called mksummary.pl, using summary.html as template. Added: trunk/varnish-tools/autobuild/autobuild.sh =================================================================== --- trunk/varnish-tools/autobuild/autobuild.sh (rev 0) +++ trunk/varnish-tools/autobuild/autobuild.sh 2007-08-24 13:45:11 UTC (rev 1920) @@ -0,0 +1,101 @@ +#!/bin/sh -e + +# 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$ +# + +# Change to same directory as this script is located. +cd "`dirname "$0"`" + +if [ "$1" != "" ]; then + # Make and change to working directory. + DIR="`date -u +varnish-%Y%m%d-%H%M%SZ`" + mkdir "$DIR" + cd "$DIR" + + # Check out from Subversion. + svn co -r "$1" http://varnish.projects.linpro.no/svn/trunk > svn.log 2>&1 + + # Use most recent revision of regression test framework. + svn update trunk/varnish-tools/regress >> svn.log 2>&1 + + # Make status file. + echo "revision: $1" > regress.status +else + # What is the current revision? + CURR="`svn info http://varnish.projects.linpro.no/svn/trunk | grep 'Revision: ' | sed 's/Revision: //'`" + + # Compare to last tested revision and exit if we already tested + # this revision. + if [ -e LAST_TESTED_REVISION ]; then + LAST="`cat LAST_TESTED_REVISION`" + if [ "$CURR" = "$LAST" ]; then + exit 0; + fi + fi + + # Okay, new revision. Here we go... + + # Make and change to working directory. + DIR="`date -u +varnish-%Y%m%d-%H%M%SZ`" + mkdir "$DIR" + cd "$DIR" + + # Check out from Subversion. + svn co -r "$CURR" http://varnish.projects.linpro.no/svn/trunk > svn.log 2>&1 + + # Make status file. + echo "revision: $CURR" > regress.status + + # Update last revision status file. + echo "$CURR" > ../LAST_TESTED_REVISION +fi + +# Build. +( + cd trunk/varnish-cache + ./autogen.sh + ./configure --enable-debugging-symbols --enable-developer-warnings --enable-dependency-tracking --prefix=/tmp/"$DIR" + make + make install +) > build.log 2>&1 + +# Run regression test framework. +PATH=/tmp/"$DIR"/sbin:"$PATH" trunk/varnish-tools/regress/varnish-regress.pl > regress.html 2> regress.log + +# Update status file. +grep -A 4 '' regress.html \ + | sed 's/.*class="\([^"]*\)">\([^<]*\)<.*/\1: \2/' \ + | tail -n +2 >> regress.status + +cd .. + +# Make summary file. +./mksummary.pl varnish-*Z > index.html.new +mv -f index.html.new index.html + +exit 0 Property changes on: trunk/varnish-tools/autobuild/autobuild.sh ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Id Added: trunk/varnish-tools/autobuild/mksummary.pl =================================================================== --- trunk/varnish-tools/autobuild/mksummary.pl (rev 0) +++ trunk/varnish-tools/autobuild/mksummary.pl 2007-08-24 13:45:11 UTC (rev 1920) @@ -0,0 +1,58 @@ +#!/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$ +# + +use strict; + +use Template; + +my %cache = (); + +foreach my $dir (@ARGV) { + open(STATUS, $dir . '/regress.status') or next; + while () { + my ($name, $value) = split(/: /); + chomp($value) if defined($value); + $cache{$dir}{$name} = $value; + } + close(STATUS); +} + +my @tests = (); + +foreach my $dir (sort({ $b cmp $a } keys(%cache))) { + if ($dir =~ /^varnish-(\d\d\d\d)(\d\d)(\d\d)-(\d\d)(\d\d)(\d\d)Z$/) { + $cache{$dir}{'title'} = "$1-$2-$3 $4:$5:$6 UTC"; + $cache{$dir}{'link'} = $dir; + push(@tests, $cache{$dir}); + } +} + +my $template = new Template('TAG_STYLE' => 'html'); +$template->process('summary.html', { 'tests' => \@tests }); Property changes on: trunk/varnish-tools/autobuild/mksummary.pl ___________________________________________________________________ Name: svn:executable + * Name: svn:keywords + Id Added: trunk/varnish-tools/autobuild/summary.html =================================================================== --- trunk/varnish-tools/autobuild/summary.html (rev 0) +++ trunk/varnish-tools/autobuild/summary.html 2007-08-24 13:45:11 UTC (rev 1920) @@ -0,0 +1,48 @@ + + + + + Varnish automatic build and test summary + + + + +

Varnish automatic build and test summary

+
s s
s s  
Total
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Build and test timeRevisionTestsPassFailTest duration
working directory
+ + Property changes on: trunk/varnish-tools/autobuild/summary.html ___________________________________________________________________ Name: svn:keywords + Id From knutroy at projects.linpro.no Fri Aug 24 13:57:58 2007 From: knutroy at projects.linpro.no (knutroy at projects.linpro.no) Date: Fri, 24 Aug 2007 15:57:58 +0200 (CEST) Subject: r1921 - trunk/varnish-tools/regress/lib/Varnish/Test Message-ID: <20070824135758.B22151EC37C@projects.linpro.no> Author: knutroy Date: 2007-08-24 15:57:58 +0200 (Fri, 24 Aug 2007) New Revision: 1921 Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm Log: Minor fix to avoid some potential warnings. Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-08-24 13:45:11 UTC (rev 1920) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-08-24 13:57:58 UTC (rev 1921) @@ -107,7 +107,7 @@ if (defined($self->{'fh'})) { my $inbuffer = $self->{'mux'}->inbuffer($self->{'fh'}); - if ($inbuffer ne '') { + if (defined($inbuffer) and $inbuffer ne '') { use Data::Dumper; $self->log('Discarding: ' . Dumper(\$inbuffer)); Modified: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-08-24 13:45:11 UTC (rev 1920) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-08-24 13:57:58 UTC (rev 1921) @@ -147,7 +147,7 @@ my $inbuffer = $self->{'mux'}->inbuffer($self->{'fh'}); - if ($inbuffer ne '') { + if (defined($inbuffer) and $inbuffer ne '') { use Data::Dumper; $self->{'server'}->log('Junk or incomplete request. Discarding: ' . Dumper(\$inbuffer)); From des at projects.linpro.no Sat Aug 25 13:57:32 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sat, 25 Aug 2007 15:57:32 +0200 (CEST) Subject: r1922 - trunk/varnish-doc/share Message-ID: <20070825135732.ABF1F1EC2AE@projects.linpro.no> Author: des Date: 2007-08-25 15:57:32 +0200 (Sat, 25 Aug 2007) New Revision: 1922 Modified: trunk/varnish-doc/share/docbook-xml.css Log: Adjust title sizes. Modified: trunk/varnish-doc/share/docbook-xml.css =================================================================== --- trunk/varnish-doc/share/docbook-xml.css 2007-08-24 13:57:58 UTC (rev 1921) +++ trunk/varnish-doc/share/docbook-xml.css 2007-08-25 13:57:32 UTC (rev 1922) @@ -54,7 +54,7 @@ book > bibliography > title { font-weight: bold; - font-size: xx-large; + font-size: 150%; } /* level 1 */ @@ -87,7 +87,7 @@ book > bibliography > bibliodiv > title { font-weight: bold; - font-size: x-large; + font-size: 120%; } /* level 2 */ @@ -114,7 +114,7 @@ book > appendix > section > section > title { font-weight: bold; - font-size: large; + font-size: 100%; } /* From des at projects.linpro.no Sat Aug 25 19:38:57 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sat, 25 Aug 2007 21:38:57 +0200 (CEST) Subject: r1923 - trunk/varnish-doc/share Message-ID: <20070825193857.C288F1EC2AE@projects.linpro.no> Author: des Date: 2007-08-25 21:38:57 +0200 (Sat, 25 Aug 2007) New Revision: 1923 Modified: trunk/varnish-doc/share/docbook-html.css trunk/varnish-doc/share/docbook-html.xsl Log: Improve the rendering of titles. Modified: trunk/varnish-doc/share/docbook-html.css =================================================================== --- trunk/varnish-doc/share/docbook-html.css 2007-08-25 13:57:32 UTC (rev 1922) +++ trunk/varnish-doc/share/docbook-html.css 2007-08-25 19:38:57 UTC (rev 1923) @@ -7,40 +7,49 @@ font-family: sans-serif; } -h1.book-title { +.book-title { + color: maroon; font-size: 200%; font-weight: bold; + display: block; } -h1.article-title { +.article-title { + color: maroon; font-size: 200%; font-weight: bold; + display: block; } -span.title1 { +.title1 { color: maroon; font-weight: bold; - font-size: xx-large; + font-size: 200%; + display: block; } -span.title2 { +.title2 { color: maroon; font-weight: bold; - font-size: x-large; + font-size: 150%; + display: block; } -span.title3 { +.title3 { color: maroon; font-weight: bold; - font-size: large; + font-size: 120%; + display: block; } -span.title4 { +.title4 { color: maroon; font-weight: bold; + display: block; } -span.title5 { +.title5 { color: maroon; font-weight: bold; + display: block; } Modified: trunk/varnish-doc/share/docbook-html.xsl =================================================================== --- trunk/varnish-doc/share/docbook-html.xsl 2007-08-25 13:57:32 UTC (rev 1922) +++ trunk/varnish-doc/share/docbook-html.xsl 2007-08-25 19:38:57 UTC (rev 1923) @@ -11,7 +11,7 @@ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> @@ -115,7 +115,7 @@ - + From des at projects.linpro.no Sat Aug 25 21:35:12 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Sat, 25 Aug 2007 23:35:12 +0200 (CEST) Subject: r1924 - trunk/varnish-doc/share Message-ID: <20070825213512.37B7D1EC2A5@projects.linpro.no> Author: des Date: 2007-08-25 23:35:11 +0200 (Sat, 25 Aug 2007) New Revision: 1924 Modified: trunk/varnish-doc/share/docbook-xml.css Log: Add style information for , and fix marker placement for ordered lists. Modified: trunk/varnish-doc/share/docbook-xml.css =================================================================== --- trunk/varnish-doc/share/docbook-xml.css 2007-08-25 19:38:57 UTC (rev 1923) +++ trunk/varnish-doc/share/docbook-xml.css 2007-08-25 21:35:11 UTC (rev 1924) @@ -144,7 +144,7 @@ orderedlist > listitem { display: list-item; - list-style: decimal inside; + list-style: decimal outside; margin-left: 4em; } @@ -254,3 +254,15 @@ content: "()"; font-family: monospace; } + +/* + * Textual screenshot + */ +screen { + display: block; + margin-top: 1ex; + border: thin solid black; + background-color: #ccc; + font-family: monospace; + padding: 0.5ex; +} From des at linpro.no Sat Aug 25 21:58:29 2007 From: des at linpro.no (=?iso-8859-1?Q?Dag-Erling_Sm=F8rgrav?=) Date: Sat, 25 Aug 2007 23:58:29 +0200 Subject: r1924 - trunk/varnish-doc/share In-Reply-To: <20070825213512.37B7D1EC2A5@projects.linpro.no> (des@projects.linpro.no's message of "Sat, 25 Aug 2007 23:35:12 +0200 (CEST)") References: <20070825213512.37B7D1EC2A5@projects.linpro.no> Message-ID: des at projects.linpro.no writes: > Modified: > trunk/varnish-doc/share/docbook-xml.css > Log: > Add style information for , and fix marker placement for ordered > lists. Note that Firefox renders ordered lists incorrectly; see https://bugzilla.mozilla.org/show_bug.cgi?id=4522 DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From des at projects.linpro.no Wed Aug 29 15:21:59 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 29 Aug 2007 17:21:59 +0200 (CEST) Subject: r1925 - trunk/varnish-cache/debian Message-ID: <20070829152159.E14AB1EC2AE@projects.linpro.no> Author: des Date: 2007-08-29 17:21:59 +0200 (Wed, 29 Aug 2007) New Revision: 1925 Modified: trunk/varnish-cache/debian/Makefile.am Log: Improve readability. Modified: trunk/varnish-cache/debian/Makefile.am =================================================================== --- trunk/varnish-cache/debian/Makefile.am 2007-08-25 21:35:11 UTC (rev 1924) +++ trunk/varnish-cache/debian/Makefile.am 2007-08-29 15:21:59 UTC (rev 1925) @@ -1,7 +1,19 @@ # $Id$ -EXTRA_DIST = \ - changelog compat control copyright dirs docs lintian-override \ - README.Debian rules TODO varnish.default varnish.examples \ - varnish.init varnish.logrotate varnish.postrm \ +EXTRA_DIST = \ + README.Debian \ + TODO \ + changelog \ + compat \ + control \ + copyright \ + dirs \ + docs \ + lintian-override \ + rules \ + varnish.default \ + varnish.examples \ + varnish.init \ + varnish.logrotate \ + varnish.postrm \ varnish.varnishlog.init From des at projects.linpro.no Wed Aug 29 15:23:52 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 29 Aug 2007 17:23:52 +0200 (CEST) Subject: r1926 - trunk/varnish-cache/debian Message-ID: <20070829152352.51AB21EC2AE@projects.linpro.no> Author: des Date: 2007-08-29 17:23:52 +0200 (Wed, 29 Aug 2007) New Revision: 1926 Modified: trunk/varnish-cache/debian/Makefile.am Log: Tabify Modified: trunk/varnish-cache/debian/Makefile.am =================================================================== --- trunk/varnish-cache/debian/Makefile.am 2007-08-29 15:21:59 UTC (rev 1925) +++ trunk/varnish-cache/debian/Makefile.am 2007-08-29 15:23:52 UTC (rev 1926) @@ -1,19 +1,19 @@ # $Id$ EXTRA_DIST = \ - README.Debian \ - TODO \ - changelog \ - compat \ - control \ - copyright \ - dirs \ - docs \ + README.Debian \ + TODO \ + changelog \ + compat \ + control \ + copyright \ + dirs \ + docs \ lintian-override \ - rules \ - varnish.default \ + rules \ + varnish.default \ varnish.examples \ - varnish.init \ - varnish.logrotate \ + varnish.init \ + varnish.logrotate \ varnish.postrm \ varnish.varnishlog.init From des at projects.linpro.no Wed Aug 29 15:24:42 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 29 Aug 2007 17:24:42 +0200 (CEST) Subject: r1927 - trunk/varnish-cache/debian Message-ID: <20070829152442.7D2C51EC21C@projects.linpro.no> Author: des Date: 2007-08-29 17:24:42 +0200 (Wed, 29 Aug 2007) New Revision: 1927 Modified: trunk/varnish-cache/debian/Makefile.am Log: Add missing files. Modified: trunk/varnish-cache/debian/Makefile.am =================================================================== --- trunk/varnish-cache/debian/Makefile.am 2007-08-29 15:23:52 UTC (rev 1926) +++ trunk/varnish-cache/debian/Makefile.am 2007-08-29 15:24:42 UTC (rev 1927) @@ -9,11 +9,20 @@ copyright \ dirs \ docs \ + libvarnish-dev.dirs \ + libvarnish-dev.install \ + libvarnish.dirs \ + libvarnish.install \ lintian-override \ rules \ varnish.default \ + varnish.dirs \ varnish.examples \ varnish.init \ + varnish.install \ varnish.logrotate \ + varnish.manpages \ + varnish.postinst \ varnish.postrm \ - varnish.varnishlog.init + varnish.varnishlog.init \ + watch From des at projects.linpro.no Wed Aug 29 15:25:58 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 29 Aug 2007 17:25:58 +0200 (CEST) Subject: r1928 - trunk/varnish-cache/redhat Message-ID: <20070829152558.B757C1EC2AE@projects.linpro.no> Author: des Date: 2007-08-29 17:25:58 +0200 (Wed, 29 Aug 2007) New Revision: 1928 Modified: trunk/varnish-cache/redhat/Makefile.am Log: Readability Modified: trunk/varnish-cache/redhat/Makefile.am =================================================================== --- trunk/varnish-cache/redhat/Makefile.am 2007-08-29 15:24:42 UTC (rev 1927) +++ trunk/varnish-cache/redhat/Makefile.am 2007-08-29 15:25:58 UTC (rev 1928) @@ -1,5 +1,10 @@ # $Id$ -EXTRA_DIST = \ - README.redhat TODO varnish.initrc varnishlog.initrc \ - varnish.logrotate varnish.spec varnish.sysconfig +EXTRA_DIST = \ + README.redhat \ + TODO \ + varnish.initrc \ + varnish.logrotate \ + varnish.spec \ + varnish.sysconfig \ + varnishlog.initrc From des at projects.linpro.no Wed Aug 29 15:38:00 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 29 Aug 2007 17:38:00 +0200 (CEST) Subject: r1929 - in branches/1.1: . bin/varnishd debian etc man redhat Message-ID: <20070829153800.2D8151EC428@projects.linpro.no> Author: des Date: 2007-08-29 17:37:59 +0200 (Wed, 29 Aug 2007) New Revision: 1929 Modified: branches/1.1/ branches/1.1/bin/varnishd/cache_center.c branches/1.1/bin/varnishd/mgt_vcc.c branches/1.1/debian/Makefile.am branches/1.1/etc/default.vcl branches/1.1/man/vcl.7 branches/1.1/redhat/Makefile.am Log: Merged revisions 1913-1916,1920-1928 via svnmerge from svn+ssh://projects.linpro.no/svn/varnish/trunk/varnish-cache ........ r1913 | phk | 2007-08-21 11:23:31 +0200 (Tue, 21 Aug 2007) | 9 lines Make sure wrk->used is always set when we park on an object, we might be unlucky multiple times in which case the responsibility falls back to cnt_lookup(). Fixes 144. ........ r1915 | des | 2007-08-21 17:36:59 +0200 (Tue, 21 Aug 2007) | 2 lines Try to make this comment a little more visible. ........ r1916 | des | 2007-08-21 17:37:17 +0200 (Tue, 21 Aug 2007) | 2 lines Synchronize with bin/varnishd/mgt_vcc.c. ........ r1925 | des | 2007-08-29 17:21:59 +0200 (Wed, 29 Aug 2007) | 2 lines Improve readability. ........ r1926 | des | 2007-08-29 17:23:52 +0200 (Wed, 29 Aug 2007) | 1 line Tabify ........ r1927 | des | 2007-08-29 17:24:42 +0200 (Wed, 29 Aug 2007) | 2 lines Add missing files. ........ r1928 | des | 2007-08-29 17:25:58 +0200 (Wed, 29 Aug 2007) | 2 lines Readability ........ Property changes on: branches/1.1 ___________________________________________________________________ Name: svnmerge-integrated - /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896,1898,1902-1905,1907,1909 + /trunk/varnish-cache:1-1722,1727-1729,1738,1743-1777,1779-1795,1797-1798,1800-1808,1810-1815,1817,1819,1823,1831-1838,1846,1853-1855,1857-1859,1862,1865,1867-1868,1871,1873-1880,1896,1898,1902-1905,1907,1909,1913-1916,1920-1928 Modified: branches/1.1/bin/varnishd/cache_center.c =================================================================== --- branches/1.1/bin/varnishd/cache_center.c 2007-08-29 15:25:58 UTC (rev 1928) +++ branches/1.1/bin/varnishd/cache_center.c 2007-08-29 15:37:59 UTC (rev 1929) @@ -488,7 +488,12 @@ */ WSL(sp->wrk, SLT_Debug, sp->fd, "on waiting list on obj %u", sp->obj->xid); - assert(!isnan(sp->wrk->used)); + /* + * There is a non-zero risk that we come here more than once + * before we get through, in that case cnt_recv must be set + */ + if (isnan(sp->wrk->used)) + sp->wrk->used = TIM_real(); SES_Charge(sp); return (1); } Modified: branches/1.1/bin/varnishd/mgt_vcc.c =================================================================== --- branches/1.1/bin/varnishd/mgt_vcc.c 2007-08-29 15:25:58 UTC (rev 1928) +++ branches/1.1/bin/varnishd/mgt_vcc.c 2007-08-29 15:37:59 UTC (rev 1929) @@ -67,7 +67,9 @@ /*--------------------------------------------------------------------*/ -/* keep this in synch with man/vcl.7 */ +/* + * Keep this in synch with man/vcl.7 and etc/default.vcl! + */ static const char *default_vcl = "sub vcl_recv {\n" " if (req.request != \"GET\" && req.request != \"HEAD\") {\n" Modified: branches/1.1/debian/Makefile.am =================================================================== --- branches/1.1/debian/Makefile.am 2007-08-29 15:25:58 UTC (rev 1928) +++ branches/1.1/debian/Makefile.am 2007-08-29 15:37:59 UTC (rev 1929) @@ -1,7 +1,28 @@ # $Id$ -EXTRA_DIST = \ - changelog compat control copyright dirs docs lintian-override \ - README.Debian rules TODO varnish.default varnish.examples \ - varnish.init varnish.logrotate varnish.postrm \ - varnish.varnishlog.init +EXTRA_DIST = \ + README.Debian \ + TODO \ + changelog \ + compat \ + control \ + copyright \ + dirs \ + docs \ + libvarnish-dev.dirs \ + libvarnish-dev.install \ + libvarnish.dirs \ + libvarnish.install \ + lintian-override \ + rules \ + varnish.default \ + varnish.dirs \ + varnish.examples \ + varnish.init \ + varnish.install \ + varnish.logrotate \ + varnish.manpages \ + varnish.postinst \ + varnish.postrm \ + varnish.varnishlog.init \ + watch Modified: branches/1.1/etc/default.vcl =================================================================== --- branches/1.1/etc/default.vcl 2007-08-29 15:25:58 UTC (rev 1928) +++ branches/1.1/etc/default.vcl 2007-08-29 15:37:59 UTC (rev 1929) @@ -47,6 +47,8 @@ ## Called when entering an object into the cache # #sub vcl_hash { +# set req.hash += req.url; +# set req.hash += req.http.host; # hash; #} # Modified: branches/1.1/man/vcl.7 =================================================================== --- branches/1.1/man/vcl.7 2007-08-29 15:25:58 UTC (rev 1928) +++ branches/1.1/man/vcl.7 2007-08-29 15:37:59 UTC (rev 1929) @@ -510,6 +510,8 @@ } sub vcl_hash { + set req.hash += req.url; + set req.hash += req.http.host; hash; } Modified: branches/1.1/redhat/Makefile.am =================================================================== --- branches/1.1/redhat/Makefile.am 2007-08-29 15:25:58 UTC (rev 1928) +++ branches/1.1/redhat/Makefile.am 2007-08-29 15:37:59 UTC (rev 1929) @@ -1,5 +1,10 @@ # $Id$ -EXTRA_DIST = \ - README.redhat TODO varnish.initrc varnishlog.initrc \ - varnish.logrotate varnish.spec varnish.sysconfig +EXTRA_DIST = \ + README.redhat \ + TODO \ + varnish.initrc \ + varnish.logrotate \ + varnish.spec \ + varnish.sysconfig \ + varnishlog.initrc From phk at projects.linpro.no Fri Aug 31 07:03:32 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 31 Aug 2007 09:03:32 +0200 (CEST) Subject: r1930 - trunk/varnish-cache/bin/varnishd Message-ID: <20070831070332.E134D1EC429@projects.linpro.no> Author: phk Date: 2007-08-31 09:03:32 +0200 (Fri, 31 Aug 2007) New Revision: 1930 Modified: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c Log: Fix typo that made worker process panic whenever a request came in without a Host: header. Modified: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2007-08-29 15:37:59 UTC (rev 1929) +++ trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2007-08-31 07:03:32 UTC (rev 1930) @@ -340,7 +340,7 @@ { struct bes *bes; - CHECK_OBJ_NOTNULL(b, SESS_MAGIC); + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); CAST_OBJ_NOTNULL(bes, b->priv, BES_MAGIC); return (bes->hostname); } From cecilihf at projects.linpro.no Fri Aug 31 12:14:06 2007 From: cecilihf at projects.linpro.no (cecilihf at projects.linpro.no) Date: Fri, 31 Aug 2007 14:14:06 +0200 (CEST) Subject: r1931 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070831121406.ABF3E1EC307@projects.linpro.no> Author: cecilihf Date: 2007-08-31 14:14:06 +0200 (Fri, 31 Aug 2007) New Revision: 1931 Added: trunk/varnish-cache/bin/varnishd/cache_backend_random.c trunk/varnish-cache/bin/varnishd/cache_backend_round_robin.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/include/vrt.h trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c trunk/varnish-cache/lib/libvcl/vcc_parse.c trunk/varnish-cache/lib/libvcl/vcc_token_defs.h Log: Added support for load balancing among backends in varnish. It is still experimental and very basic, but it should be ready for testing. Two strategies for load balancing are implemented: a simple round robin, and a simple weighted random. The following is an example configuration in vcl. The weight parameter for random is optional. Default is equal weight. backend foo { set backend.host = "foo.bar.com"; set backend.port = "http"; } backend_round_robin rr { set backend.set = { { "foo1.bar.com", "http" } { "foo2.bar.com", "http" } { "foo3.bar.com", "http" } }; } backend_random rrr { set backend.set = { { "foo1.bar.com", "http", 0.3 } { "foo2.bar.com", "http", 0.6 } { "foo3.bar.com", "http", 0.1 } }; } sub vcl_recv { if {req.http.host ~ "foo"} { req.backend = foo; } elseif {req.http.host ~ "bar"} { req.backend = rr; } else { req.backend = rrr; } } Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2007-08-31 12:14:06 UTC (rev 1931) @@ -12,6 +12,8 @@ cache_acceptor_poll.c \ cache_acceptor_kqueue.c \ cache_backend.c \ + cache_backend_random.c \ + cache_backend_round_robin.c \ cache_backend_simple.c \ cache_ban.c \ cache_center.c \ Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-08-31 12:14:06 UTC (rev 1931) @@ -326,6 +326,7 @@ TAILQ_ENTRY(vbe_conn) list; struct backend *backend; int fd; + void *priv; }; Added: trunk/varnish-cache/bin/varnishd/cache_backend_random.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_random.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_backend_random.c 2007-08-31 12:14:06 UTC (rev 1931) @@ -0,0 +1,471 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * 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$ + * + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "shmlog.h" +#include "cache.h" +#include "vrt.h" + + +struct ber { + unsigned magic; +#define BER_MAGIC 0x66f05894 + struct brspec *blist; +#if 0 + /* Store a hash of the backend info given in + * vcl for comparison when a new vcl file is + * uploaded. Not in use yet. + */ + unsigned hash; +#endif +}; + +struct brspec { + unsigned magic; +#define BRSPEC_MAGIC 0x761d69c2 + struct brspec *next; + double limit; + char *hostname; + char *portname; + struct addrinfo *addr; + struct addrinfo *last_addr; + double dnsttl; + double dnstime; + unsigned dnsseq; + TAILQ_HEAD(, vbe_conn) connlist; +}; + +/*--------------------------------------------------------------------*/ + +static int +ber_conn_try_list(struct sess *sp, struct brspec *bs) +{ + struct addrinfo *ai, *from; + struct sockaddr_storage ss; + int fam, sockt, proto; + socklen_t alen; + int s, loops; + char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE]; + char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE]; + unsigned myseq; + + /* Called with lock held */ + myseq = bs->dnsseq; + loops = 0; + from = bs->last_addr; + for (ai = from; ai != NULL && (loops != 1 || ai != from);) { + fam = ai->ai_family; + sockt = ai->ai_socktype; + proto = ai->ai_protocol; + alen = ai->ai_addrlen; + assert(alen <= sizeof ss); + memcpy(&ss, ai->ai_addr, alen); + UNLOCK(&sp->backend->mtx); + s = socket(fam, sockt, proto); + if (s >= 0 && connect(s, (void *)&ss, alen)) { + AZ(close(s)); + s = -1; + } + if (s >= 0) { + TCP_myname(s, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1); + TCP_name((void*)&ss, alen, + abuf2, sizeof abuf2, pbuf2, sizeof pbuf2); + WSL(sp->wrk, SLT_BackendOpen, s, "%s %s %s %s %s", + sp->backend->vcl_name, abuf1, pbuf1, abuf2, pbuf2); + } + LOCK(&sp->backend->mtx); + if (s >= 0) { + if (myseq == bs->dnsseq) + bs->last_addr = ai; + return (s); + } + if (myseq != bs->dnsseq) { + loops = 0; + from = bs->last_addr; + ai = from; + } else { + ai = ai->ai_next; + if (ai == NULL) { + loops++; + ai = bs->addr; + } + } + } + return (-1); +} + +/*--------------------------------------------------------------------*/ + +static int +ber_conn_try(struct sess *sp, struct backend *bp, struct brspec *bs) +{ + int s; + struct addrinfo *res, hint, *old; + int error; + + LOCK(&bp->mtx); + + s = ber_conn_try_list(sp, bs); + if (s >= 0) { + bp->refcount++; + UNLOCK(&bp->mtx); + return (s); + } + + if (bs->dnstime + bs->dnsttl >= TIM_mono()) { + UNLOCK(&bp->mtx); + return (-1); + } + + /* Then do another lookup to catch DNS changes */ + bs->dnstime = TIM_mono(); + UNLOCK(&bp->mtx); + + memset(&hint, 0, sizeof hint); + hint.ai_family = PF_UNSPEC; + hint.ai_socktype = SOCK_STREAM; + res = NULL; + error = getaddrinfo(bs->hostname, + bs->portname == NULL ? "http" : bs->portname, + &hint, &res); + if (error) { + if (res != NULL) + freeaddrinfo(res); + printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */ + LOCK(&bp->mtx); + } else { + LOCK(&bp->mtx); + bs->dnsseq++; + old = bs->addr; + bs->last_addr = res; + bs->addr = res; + if (old != NULL) + freeaddrinfo(old); + } + + /* And try the entire list */ + s = ber_conn_try_list(sp, bs); + if (s >= 0) { + bp->refcount++; + UNLOCK(&bp->mtx); + return (s); + } + + UNLOCK(&bp->mtx); + return (-1); +} + + +/* Get a backend connection ------------------------------------------ + * + * Get the next backend in the round-robin list, and connect to this. + * + * Try all cached backend connections for this backend, and use the + * first one that is looks like it is still connected. + * If that fails to get us a connection, create a new one, reusing a + * connection from the freelist, if possible. + * + * This function is slightly complicated by optimizations on bermtx. + */ + +static struct vbe_conn * +ber_nextfd(struct sess *sp) +{ + struct vbe_conn *vc; + struct pollfd pfd; + struct backend *bp; + int reuse = 0; + struct ber *ber; + struct brspec *bs; + double r; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); + bp = sp->backend; + CAST_OBJ_NOTNULL(ber, bp->priv, BER_MAGIC); + + r = (double)rand() / ((double)(RAND_MAX)+1.0); + bs = ber->blist; + CHECK_OBJ_NOTNULL(bs, BRSPEC_MAGIC); + while (r > bs->limit) { + bs = bs->next; + CHECK_OBJ_NOTNULL(bs, BRSPEC_MAGIC); + } + while (1) { + LOCK(&bp->mtx); + vc = TAILQ_FIRST(&bs->connlist); + if (vc != NULL) { + bp->refcount++; + assert(vc->backend == bp); + assert(vc->fd >= 0); + TAILQ_REMOVE(&bs->connlist, vc, list); + vc->priv = bs; + } + UNLOCK(&bp->mtx); + if (vc == NULL) + break; + + /* Test the connection for remote close before we use it */ + pfd.fd = vc->fd; + pfd.events = POLLIN; + pfd.revents = 0; + if (!poll(&pfd, 1, 0)) { + /* XXX locking of stats */ + VSL_stats->backend_reuse += reuse; + VSL_stats->backend_conn++; + return (vc); + } + VBE_ClosedFd(sp->wrk, vc); + } + + vc = VBE_NewConn(); + assert(vc->fd == -1); + AZ(vc->backend); + vc->fd = ber_conn_try(sp, bp, bs); + if (vc->fd < 0) { + VBE_ReleaseConn(vc); + VSL_stats->backend_fail++; + return (NULL); + } + vc->backend = bp; + vc->priv = bs; + VSL_stats->backend_conn++; + return (vc); +} + +static struct vbe_conn * +ber_GetFd(struct sess *sp) +{ + struct vbe_conn *vc; + unsigned n; + for (n = 1; n < 5; n++) { + vc = ber_nextfd(sp); + if (vc == NULL) { + usleep(100000 * n); + continue; + } + assert(vc->fd >= 0); + assert(vc->backend == sp->backend); + WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid); + WSL(sp->wrk, SLT_Backend, sp->fd, "%d %s", vc->fd, + sp->backend->vcl_name); + return (vc); + } + return (NULL); +} + +/*--------------------------------------------------------------------*/ + +static void +ber_ClosedFd(struct worker *w, struct vbe_conn *vc) +{ + CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); + assert(vc->fd >= 0); + WSL(w, SLT_BackendClose, vc->fd, "%s", vc->backend->vcl_name); + AZ(close(vc->fd)); + vc->fd = -1; + VBE_DropRef(vc->backend); + vc->backend = NULL; + VBE_ReleaseConn(vc); +} + +/*--------------------------------------------------------------------*/ + +static void +ber_RecycleFd(struct worker *w, struct vbe_conn *vc) +{ + struct brspec *bs; + + CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); + CAST_OBJ_NOTNULL(bs, vc->priv, BRSPEC_MAGIC); + + assert(vc->fd >= 0); + WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); + LOCK(&vc->backend->mtx); + VSL_stats->backend_recycle++; + TAILQ_INSERT_HEAD(&bs->connlist, vc, list); + VBE_DropRefLocked(vc->backend); +} + +/*--------------------------------------------------------------------*/ + +static void +ber_Cleanup(struct backend *b) +{ + struct ber *ber; + struct vbe_conn *vbe; + struct brspec *bs, *bstmp; + + assert(b->refcount == 0); + CAST_OBJ_NOTNULL(ber, b->priv, BER_MAGIC); + + bs = ber->blist; + + do { + free(bs->portname); + free(bs->hostname); + freeaddrinfo(bs->addr); + while (1) { + vbe = TAILQ_FIRST(&bs->connlist); + if (vbe == NULL) + break; + TAILQ_REMOVE(&bs->connlist, vbe, list); + if (vbe->fd >= 0) + close(vbe->fd); + free(vbe); + } + bstmp = bs; + bs = bs->next; + free(bstmp); + } while (bs != ber->blist); + + free(ber); +} + +/*--------------------------------------------------------------------*/ + +/* Will return the hostname of the first backend in the list */ +static const char * +ber_GetHostname(struct backend *b) +{ + struct ber *ber; + + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + CAST_OBJ_NOTNULL(ber, b->priv, BER_MAGIC); + return (ber->blist->hostname); +} + +/*--------------------------------------------------------------------*/ + +static void +ber_Init(void) +{ + +} + +/*--------------------------------------------------------------------*/ + +struct backend_method backend_method_random = { + .name = "random", + .getfd = ber_GetFd, + .close = ber_ClosedFd, + .recycle = ber_RecycleFd, + .gethostname = ber_GetHostname, + .cleanup = ber_Cleanup, + .init = ber_Init +}; + +/*--------------------------------------------------------------------*/ + +void +VRT_init_random_backend(struct backend **bp, struct vrt_random_backend *t) +{ + struct backend *b; + struct ber *ber; + struct vrt_backend_entry *be; + struct brspec *bs = NULL; + struct brspec *bs_prev = NULL; + struct brspec *bs_first = NULL; + double limit = 0; + double default_weight; + + /* + * Scan existing backends to see if we can recycle one of them. + */ + + /* + * XXX: Do this by comparing a hash generated from this new + * XXX: backend with the earlier computed hashes from existing + * XXX: backends ? Should the hash be a parameter to this function, + * XXX: or computed here? + */ + + b = VBE_NewBackend(&backend_method_random); + + ber = calloc(sizeof *ber, 1); + XXXAN(ber); + ber->magic = BER_MAGIC; + + b->priv = ber; + + AN(t->name); + b->vcl_name = strdup(t->name); + XXXAN(b->vcl_name); + + default_weight = 1.0 / (double)t->count; + + be = t->bentry; + while (be != NULL) { + bs = calloc(sizeof *bs, 1); + bs->magic = BRSPEC_MAGIC; + AN(be->port); + bs->portname = strdup(be->port); + XXXAN(bs->portname); + + AN(be->host); + bs->hostname = strdup(be->host); + XXXAN(bs->hostname); + + if (!(t->weighted)) + be->weight = default_weight; + + limit += be->weight; + bs->limit = limit; + + bs->dnsttl = 300; + + if (bs_first == NULL) + bs_first = bs; + + bs->next = bs_prev; + bs_prev = bs; + be = be->next; + } + + bs_first->next = bs; + ber->blist = bs; + + *bp = b; +} + Property changes on: trunk/varnish-cache/bin/varnishd/cache_backend_random.c ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/varnish-cache/bin/varnishd/cache_backend_round_robin.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_round_robin.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_backend_round_robin.c 2007-08-31 12:14:06 UTC (rev 1931) @@ -0,0 +1,454 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * 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$ + * + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "shmlog.h" +#include "cache.h" +#include "vrt.h" + + +struct brr { + unsigned magic; +#define BRR_MAGIC 0x66f05894 + struct bspec *blist; +#if 0 + /* Store a hash of the backend info given in + * vcl for comparison when a new vcl file is + * uploaded. Not in use yet. + */ + unsigned hash; +#endif +}; + +struct bspec { + unsigned magic; +#define BSPEC_MAGIC 0x761d69c2 + struct bspec *next; + char *hostname; + char *portname; + struct addrinfo *addr; + struct addrinfo *last_addr; + double dnsttl; + double dnstime; + unsigned dnsseq; + TAILQ_HEAD(, vbe_conn) connlist; +}; + +/*--------------------------------------------------------------------*/ + +static int +brr_conn_try_list(struct sess *sp, struct bspec *bs) +{ + struct addrinfo *ai, *from; + struct sockaddr_storage ss; + int fam, sockt, proto; + socklen_t alen; + int s, loops; + char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE]; + char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE]; + unsigned myseq; + + /* Called with lock held */ + myseq = bs->dnsseq; + loops = 0; + from = bs->last_addr; + for (ai = from; ai != NULL && (loops != 1 || ai != from);) { + fam = ai->ai_family; + sockt = ai->ai_socktype; + proto = ai->ai_protocol; + alen = ai->ai_addrlen; + assert(alen <= sizeof ss); + memcpy(&ss, ai->ai_addr, alen); + UNLOCK(&sp->backend->mtx); + s = socket(fam, sockt, proto); + if (s >= 0 && connect(s, (void *)&ss, alen)) { + AZ(close(s)); + s = -1; + } + if (s >= 0) { + TCP_myname(s, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1); + TCP_name((void*)&ss, alen, + abuf2, sizeof abuf2, pbuf2, sizeof pbuf2); + WSL(sp->wrk, SLT_BackendOpen, s, "%s %s %s %s %s", + sp->backend->vcl_name, abuf1, pbuf1, abuf2, pbuf2); + } + LOCK(&sp->backend->mtx); + if (s >= 0) { + if (myseq == bs->dnsseq) + bs->last_addr = ai; + return (s); + } + if (myseq != bs->dnsseq) { + loops = 0; + from = bs->last_addr; + ai = from; + } else { + ai = ai->ai_next; + if (ai == NULL) { + loops++; + ai = bs->addr; + } + } + } + return (-1); +} + +/*--------------------------------------------------------------------*/ + +static int +brr_conn_try(struct sess *sp, struct backend *bp, struct bspec *bs) +{ + int s; + struct addrinfo *res, hint, *old; + int error; + + LOCK(&bp->mtx); + + s = brr_conn_try_list(sp, bs); + if (s >= 0) { + bp->refcount++; + UNLOCK(&bp->mtx); + return (s); + } + + if (bs->dnstime + bs->dnsttl >= TIM_mono()) { + UNLOCK(&bp->mtx); + return (-1); + } + + /* Then do another lookup to catch DNS changes */ + bs->dnstime = TIM_mono(); + UNLOCK(&bp->mtx); + + memset(&hint, 0, sizeof hint); + hint.ai_family = PF_UNSPEC; + hint.ai_socktype = SOCK_STREAM; + res = NULL; + error = getaddrinfo(bs->hostname, + bs->portname == NULL ? "http" : bs->portname, + &hint, &res); + if (error) { + if (res != NULL) + freeaddrinfo(res); + printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */ + LOCK(&bp->mtx); + } else { + LOCK(&bp->mtx); + bs->dnsseq++; + old = bs->addr; + bs->last_addr = res; + bs->addr = res; + if (old != NULL) + freeaddrinfo(old); + } + + /* And try the entire list */ + s = brr_conn_try_list(sp, bs); + if (s >= 0) { + bp->refcount++; + UNLOCK(&bp->mtx); + return (s); + } + + UNLOCK(&bp->mtx); + return (-1); +} + + +/* Get a backend connection ------------------------------------------ + * + * Get the next backend in the round-robin list, and connect to this. + * + * Try all cached backend connections for this backend, and use the + * first one that is looks like it is still connected. + * If that fails to get us a connection, create a new one, reusing a + * connection from the freelist, if possible. + * + * This function is slightly complicated by optimizations on brrmtx. + */ + +static struct vbe_conn * +brr_nextfd(struct sess *sp) +{ + struct vbe_conn *vc; + struct pollfd pfd; + struct backend *bp; + int reuse = 0; + struct brr *brr; + struct bspec *bs; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); + bp = sp->backend; + CAST_OBJ_NOTNULL(brr, bp->priv, BRR_MAGIC); + + bs = brr->blist = brr->blist->next; + + while (1) { + LOCK(&bp->mtx); + vc = TAILQ_FIRST(&bs->connlist); + if (vc != NULL) { + bp->refcount++; + assert(vc->backend == bp); + assert(vc->fd >= 0); + TAILQ_REMOVE(&bs->connlist, vc, list); + vc->priv = bs; + } + UNLOCK(&bp->mtx); + if (vc == NULL) + break; + + /* Test the connection for remote close before we use it */ + pfd.fd = vc->fd; + pfd.events = POLLIN; + pfd.revents = 0; + if (!poll(&pfd, 1, 0)) { + /* XXX locking of stats */ + VSL_stats->backend_reuse += reuse; + VSL_stats->backend_conn++; + return (vc); + } + VBE_ClosedFd(sp->wrk, vc); + } + + vc = VBE_NewConn(); + assert(vc->fd == -1); + AZ(vc->backend); + vc->fd = brr_conn_try(sp, bp, bs); + if (vc->fd < 0) { + VBE_ReleaseConn(vc); + VSL_stats->backend_fail++; + return (NULL); + } + vc->backend = bp; + vc->priv = bs; + VSL_stats->backend_conn++; + return (vc); +} + +static struct vbe_conn * +brr_GetFd(struct sess *sp) +{ + struct vbe_conn *vc; + unsigned n; + for (n = 1; n < 5; n++) { + vc = brr_nextfd(sp); + if (vc == NULL) { + usleep(100000 * n); + continue; + } + assert(vc->fd >= 0); + assert(vc->backend == sp->backend); + WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid); + WSL(sp->wrk, SLT_Backend, sp->fd, "%d %s", vc->fd, + sp->backend->vcl_name); + return (vc); + } + return (NULL); +} + +/*--------------------------------------------------------------------*/ + +static void +brr_ClosedFd(struct worker *w, struct vbe_conn *vc) +{ + CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); + assert(vc->fd >= 0); + WSL(w, SLT_BackendClose, vc->fd, "%s", vc->backend->vcl_name); + AZ(close(vc->fd)); + vc->fd = -1; + VBE_DropRef(vc->backend); + vc->backend = NULL; + VBE_ReleaseConn(vc); +} + +/*--------------------------------------------------------------------*/ + +static void +brr_RecycleFd(struct worker *w, struct vbe_conn *vc) +{ + struct bspec *bs; + + CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); + CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); + CAST_OBJ_NOTNULL(bs, vc->priv, BSPEC_MAGIC); + + assert(vc->fd >= 0); + WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); + LOCK(&vc->backend->mtx); + VSL_stats->backend_recycle++; + TAILQ_INSERT_HEAD(&bs->connlist, vc, list); + VBE_DropRefLocked(vc->backend); +} + +/*--------------------------------------------------------------------*/ + +static void +brr_Cleanup(struct backend *b) +{ + struct brr *brr; + struct vbe_conn *vbe; + struct bspec *bs, *bstmp; + + assert(b->refcount == 0); + CAST_OBJ_NOTNULL(brr, b->priv, BRR_MAGIC); + + bs = brr->blist; + + do { + free(bs->portname); + free(bs->hostname); + freeaddrinfo(bs->addr); + while (1) { + vbe = TAILQ_FIRST(&bs->connlist); + if (vbe == NULL) + break; + TAILQ_REMOVE(&bs->connlist, vbe, list); + if (vbe->fd >= 0) + close(vbe->fd); + free(vbe); + } + bstmp = bs; + bs = bs->next; + free(bstmp); + } while (bs != brr->blist); + + free(brr); +} + +/*--------------------------------------------------------------------*/ + +/* Will return the hostname of the first backend in the list */ +static const char * +brr_GetHostname(struct backend *b) +{ + struct brr *brr; + + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + CAST_OBJ_NOTNULL(brr, b->priv, BRR_MAGIC); + return (brr->blist->hostname); +} + +/*--------------------------------------------------------------------*/ + +static void +brr_Init(void) +{ + +} + +/*--------------------------------------------------------------------*/ + +struct backend_method backend_method_round_robin = { + .name = "round_robin", + .getfd = brr_GetFd, + .close = brr_ClosedFd, + .recycle = brr_RecycleFd, + .gethostname = brr_GetHostname, + .cleanup = brr_Cleanup, + .init = brr_Init +}; + +/*--------------------------------------------------------------------*/ + +void +VRT_init_round_robin_backend(struct backend **bp, struct vrt_round_robin_backend *t) +{ + struct backend *b; + struct brr *brr; + struct vrt_backend_entry *be; + struct bspec *bs = NULL; + struct bspec *bs_prev = NULL; + struct bspec *bs_first = NULL; + + /* + * Scan existing backends to see if we can recycle one of them. + */ + /* + * XXX: Do this by comparing a hash generated from this new + * XXX: backend with the earlier computed hashes from existing + * XXX: backends ? Should the hash be a parameter to this function, + * XXX: or computed here? + */ + + + b = VBE_NewBackend(&backend_method_round_robin); + + brr = calloc(sizeof *brr, 1); + XXXAN(brr); + brr->magic = BRR_MAGIC; + + b->priv = brr; + + AN(t->name); + b->vcl_name = strdup(t->name); + XXXAN(b->vcl_name); + + be = t->bentry; + while (be != NULL) { + bs = calloc(sizeof *bs, 1); + bs->magic = BSPEC_MAGIC; + AN(be->port); + bs->portname = strdup(be->port); + XXXAN(bs->portname); + + AN(be->host); + bs->hostname = strdup(be->host); + XXXAN(bs->hostname); + + bs->dnsttl = 300; + + if (bs_first == NULL) + bs_first = bs; + + bs->next = bs_prev; + bs_prev = bs; + be = be->next; + } + + bs_first->next = bs; + brr->blist = bs; + + *bp = b; +} + Property changes on: trunk/varnish-cache/bin/varnishd/cache_backend_round_robin.c ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/include/vrt.h 2007-08-31 12:14:06 UTC (rev 1931) @@ -46,6 +46,26 @@ const char *host; }; +struct vrt_backend_entry { + const char *port; + const char *host; + double weight; + struct vrt_backend_entry *next; +}; + +struct vrt_round_robin_backend { + const char *name; + struct vrt_backend_entry *bentry; +}; + +struct vrt_random_backend { + const char *name; + unsigned weighted; + unsigned count; + struct vrt_backend_entry *bentry; +}; + + struct vrt_ref { unsigned source; unsigned offset; @@ -94,6 +114,8 @@ /* Backend related */ void VRT_init_simple_backend(struct backend **, struct vrt_simple_backend *); +void VRT_init_round_robin_backend(struct backend **, struct vrt_round_robin_backend *); +void VRT_init_random_backend(struct backend **, struct vrt_random_backend *); void VRT_fini_backend(struct backend *); char *VRT_IP_string(struct sess *sp, struct sockaddr *sa); Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/include/vrt_obj.h 2007-08-31 12:14:06 UTC (rev 1931) @@ -9,6 +9,7 @@ void VRT_l_backend_host(struct backend *, const char *); void VRT_l_backend_port(struct backend *, const char *); void VRT_l_backend_dnsttl(struct backend *, double); +void VRT_l_backend_set(struct backend *, struct vrt_backend_entry *); struct sockaddr * VRT_r_client_ip(struct sess *); struct sockaddr * VRT_r_server_ip(struct sess *); const char * VRT_r_req_request(struct sess *); Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2007-08-31 12:14:06 UTC (rev 1931) @@ -59,7 +59,7 @@ } void -vcc_ParseBackend(struct tokenlist *tl) +vcc_ParseSimpleBackend(struct tokenlist *tl) { struct var *vp; struct token *t_be = NULL; @@ -85,6 +85,7 @@ vcc_NextToken(tl); ExpectErr(tl, '{'); vcc_NextToken(tl); + while (1) { if (tl->t->tok == '}') break; @@ -160,3 +161,177 @@ Ff(tl, 0, "\tVRT_fini_backend(VGC_backend_%.*s);\n", PF(t_be)); tl->nbackend++; } + +void +vcc_ParseBalancedBackend(struct tokenlist *tl) +{ + struct var *vp; + struct token *t_be = NULL; + struct token *t_host = NULL; + struct token *t_port = NULL; + double t_weight = 0; + const char *ep; + int cnt = 0; + int weighted = 0; + double weight = 0; + unsigned backend_type = tl->t->tok; + + vcc_NextToken(tl); + ExpectErr(tl, ID); + t_be = tl->t; + vcc_AddDef(tl, tl->t, R_BACKEND); + /* + * The first backend is always referenced because that is the default + * at the beginning of vcl_recv + */ + if (tl->nbackend == 0) + vcc_AddRef(tl, tl->t, R_BACKEND); + + /* In the compiled vcl we use these macros to refer to backends */ + Fh(tl, 1, "#define VGC_backend_%.*s (VCL_conf.backend[%d])\n", + PF(tl->t), tl->nbackend); + + vcc_NextToken(tl); + ExpectErr(tl, '{'); + vcc_NextToken(tl); + + while (1) { + if (tl->t->tok == '}') + break; + ExpectErr(tl, ID); + if (!vcc_IdIs(tl->t, "set")) { + vsb_printf(tl->sb, + "Expected 'set', found "); + vcc_ErrToken(tl, tl->t); + vsb_printf(tl->sb, " at\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + vcc_NextToken(tl); + ExpectErr(tl, VAR); + vp = vcc_FindVar(tl, tl->t, vcc_be_vars); + ERRCHK(tl); + assert(vp != NULL); + vcc_NextToken(tl); + ExpectErr(tl, '='); + vcc_NextToken(tl); + if (vp->fmt != SET) { + vsb_printf(tl->sb, + "Assignments not possible for '%s'\n", vp->name); + vcc_ErrWhere(tl, tl->t); + return; + } + + ExpectErr(tl, '{'); + vcc_NextToken(tl); + + while (1) { + if (tl->t->tok == '}') + break; + + ExpectErr(tl, '{'); + vcc_NextToken(tl); + + // Host + ExpectErr(tl, CSTR); + t_host = tl->t; + vcc_NextToken(tl); + + ep = CheckHostPort(t_host->dec, "80"); + if (ep != NULL) { + vsb_printf(tl->sb, "Backend '%.*s': %s\n", PF(t_be), ep); + vcc_ErrWhere(tl, t_host); + return; + } + + if (tl->t->tok == ',') { + vcc_NextToken(tl); + + // Port + + ExpectErr(tl, CSTR); + t_port = tl->t; + vcc_NextToken(tl); + + ep = CheckHostPort(t_host->dec, t_port->dec); + if (ep != NULL) { + vsb_printf(tl->sb, + "Backend '%.*s': %s\n", PF(t_be), ep); + vcc_ErrWhere(tl, t_port); + return; + } + + if (tl->t->tok == ',') { + + vcc_NextToken(tl); + + // Weight + t_weight = vcc_DoubleVal(tl); + weighted = 1; + weight += t_weight; + } + } + + ExpectErr(tl, '}'); + vcc_NextToken(tl); + + Fc(tl, 0, "\nstatic struct vrt_backend_entry bentry_%.*s_%d = {\n", + PF(t_be), cnt); + Fc(tl, 0, "\t.port = %.*s,\n", PF(t_port)); + Fc(tl, 0, "\t.host = %.*s,\n", PF(t_host)); + Fc(tl, 0, "\t.weight = %f,\n", t_weight); + if (cnt > 0) { + Fc(tl, 0, "\t.next = &bentry_%.*s_%d\n", PF(t_be), cnt-1); + } /*else { + Fc(tl, 0, "\t.next = NULL\n"); + }*/ + Fc(tl, 0, "};\n"); + t_weight = 0; + cnt++; + } + ExpectErr(tl, '}'); + vcc_NextToken(tl); + ExpectErr(tl, ';'); + vcc_NextToken(tl); + + if (t_host == NULL) { + vsb_printf(tl->sb, "Backend '%.*s' has no hostname\n", + PF(t_be)); + vcc_ErrWhere(tl, tl->t); + return; + } + + if (weighted && (int)weight != 1) { + vsb_printf(tl->sb, "Total weight must be 1\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + + if (backend_type == T_BACKEND_ROUND_ROBIN) { + Fc(tl, 0, "\nstatic struct vrt_round_robin_backend sbe_%.*s = {\n", + PF(t_be)); + Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_be)); + Fc(tl, 0, "\t.bentry = &bentry_%.*s_%d\n", PF(t_be), cnt-1); + Fc(tl, 0, "};\n"); + Fi(tl, 0, "\tVRT_init_round_robin_backend(&VGC_backend_%.*s , &sbe_%.*s);\n", + PF(t_be), PF(t_be)); + } else if (backend_type == T_BACKEND_RANDOM) { + Fc(tl, 0, "\nstatic struct vrt_random_backend sbe_%.*s = {\n", + PF(t_be)); + Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_be)); + Fc(tl, 0, "\t.weighted = %d,\n", weighted); + Fc(tl, 0, "\t.count = %d,\n", cnt); + Fc(tl, 0, "\t.bentry = &bentry_%.*s_%d\n", PF(t_be), cnt-1); + Fc(tl, 0, "};\n"); + Fi(tl, 0, "\tVRT_init_random_backend(&VGC_backend_%.*s , &sbe_%.*s);\n", + PF(t_be), PF(t_be)); + } + Ff(tl, 0, "\tVRT_fini_backend(VGC_backend_%.*s);\n", PF(t_be)); + + } + ExpectErr(tl, '}'); + + vcc_NextToken(tl); + tl->nbackend++; +} + Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2007-08-31 12:14:06 UTC (rev 1931) @@ -99,7 +99,8 @@ HOSTNAME, PORTNAME, HASH, - HEADER + HEADER, + SET }; enum ref_type { @@ -144,7 +145,8 @@ void vcc_ParseAction(struct tokenlist *tl); /* vcc_backend.c */ -void vcc_ParseBackend(struct tokenlist *tl); +void vcc_ParseSimpleBackend(struct tokenlist *tl); +void vcc_ParseBalancedBackend(struct tokenlist *tl); /* vcc_compile.c */ extern struct method method_tab[]; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2007-08-31 12:14:06 UTC (rev 1931) @@ -168,6 +168,24 @@ case 'b': if (p[0] == 'b' && p[1] == 'a' && p[2] == 'c' && p[3] == 'k' && p[4] == 'e' && p[5] == 'n' && + p[6] == 'd' && p[7] == '_' && p[8] == 'r' && + p[9] == 'o' && p[10] == 'u' && p[11] == 'n' && + p[12] == 'd' && p[13] == '_' && p[14] == 'r' && + p[15] == 'o' && p[16] == 'b' && p[17] == 'i' && + p[18] == 'n' && !isvar(p[19])) { + *q = p + 19; + return (T_BACKEND_ROUND_ROBIN); + } + if (p[0] == 'b' && p[1] == 'a' && p[2] == 'c' && + p[3] == 'k' && p[4] == 'e' && p[5] == 'n' && + p[6] == 'd' && p[7] == '_' && p[8] == 'r' && + p[9] == 'a' && p[10] == 'n' && p[11] == 'd' && + p[12] == 'o' && p[13] == 'm' && !isvar(p[14])) { + *q = p + 14; + return (T_BACKEND_RANDOM); + } + if (p[0] == 'b' && p[1] == 'a' && p[2] == 'c' && + p[3] == 'k' && p[4] == 'e' && p[5] == 'n' && p[6] == 'd' && !isvar(p[7])) { *q = p + 7; return (T_BACKEND); @@ -274,6 +292,8 @@ vcl_tnames[ID] = "ID"; vcl_tnames[T_ACL] = "acl"; vcl_tnames[T_BACKEND] = "backend"; + vcl_tnames[T_BACKEND_RANDOM] = "backend_random"; + vcl_tnames[T_BACKEND_ROUND_ROBIN] = "backend_round_robin"; vcl_tnames[T_CAND] = "&&"; vcl_tnames[T_COR] = "||"; vcl_tnames[T_DEC] = "--"; @@ -333,7 +353,7 @@ vsb_cat(sb, " struct vrt_ref *ref;\n"); vsb_cat(sb, " unsigned nref;\n"); vsb_cat(sb, " unsigned busy;\n"); - vsb_cat(sb, "\n"); + vsb_cat(sb, " \n"); vsb_cat(sb, " unsigned nsrc;\n"); vsb_cat(sb, " const char **srcname;\n"); vsb_cat(sb, " const char **srcbody;\n"); @@ -404,6 +424,26 @@ vsb_cat(sb, " const char *host;\n"); vsb_cat(sb, "};\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "struct vrt_backend_entry {\n"); + vsb_cat(sb, " const char *port;\n"); + vsb_cat(sb, " const char *host;\n"); + vsb_cat(sb, " double weight;\n"); + vsb_cat(sb, " struct vrt_backend_entry *next;\n"); + vsb_cat(sb, "};\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, "struct vrt_round_robin_backend {\n"); + vsb_cat(sb, " const char *name;\n"); + vsb_cat(sb, " struct vrt_backend_entry *bentry;\n"); + vsb_cat(sb, "};\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, "struct vrt_random_backend {\n"); + vsb_cat(sb, " const char *name;\n"); + vsb_cat(sb, " unsigned weighted;\n"); + vsb_cat(sb, " unsigned count;\n"); + vsb_cat(sb, " struct vrt_backend_entry *bentry;\n"); + vsb_cat(sb, "};\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, "struct vrt_ref {\n"); vsb_cat(sb, " unsigned source;\n"); vsb_cat(sb, " unsigned offset;\n"); @@ -452,6 +492,8 @@ vsb_cat(sb, "\n"); vsb_cat(sb, "/* Backend related */\n"); vsb_cat(sb, "void VRT_init_simple_backend(struct backend **, struct vrt_simple_backend *);\n"); + vsb_cat(sb, "void VRT_init_round_robin_backend(struct backend **, struct vrt_round_robin_backend *);\n"); + vsb_cat(sb, "void VRT_init_random_backend(struct backend **, struct vrt_random_backend *);\n"); vsb_cat(sb, "void VRT_fini_backend(struct backend *);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "char *VRT_IP_string(struct sess *sp, struct sockaddr *sa);\n"); @@ -473,6 +515,7 @@ vsb_cat(sb, "void VRT_l_backend_host(struct backend *, const char *);\n"); vsb_cat(sb, "void VRT_l_backend_port(struct backend *, const char *);\n"); vsb_cat(sb, "void VRT_l_backend_dnsttl(struct backend *, double);\n"); + vsb_cat(sb, "void VRT_l_backend_set(struct backend *, struct vrt_backend_entry *);\n"); 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"); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2007-08-31 12:14:06 UTC (rev 1931) @@ -73,6 +73,10 @@ acl backend + + backend_round_robin + + backend_random } # Non-word tokens @@ -137,7 +141,7 @@ struct vrt_ref *ref; unsigned nref; unsigned busy; - + unsigned nsrc; const char **srcname; const char **srcbody; Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-08-31 12:14:06 UTC (rev 1931) @@ -35,6 +35,7 @@ { backend.host WO HOSTNAME {} } { backend.port WO PORTNAME {} } { backend.dnsttl WO TIME {} } + { backend.set WO SET {} } } # Variables available in sessions @@ -180,6 +181,7 @@ set tt(HOSTNAME) "const char *" set tt(PORTNAME) "const char *" set tt(HASH) "const char *" +set tt(SET) "struct vrt_backend_entry *" #---------------------------------------------------------------------- # Boilerplate warning for all generated files. Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-08-31 12:14:06 UTC (rev 1931) @@ -31,6 +31,13 @@ 0, 0 }, + { "backend.set", SET, 11, + NULL, + "VRT_l_backend_set(backend, ", + V_WO, + 0, + 0 + }, { NULL } }; Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2007-08-31 12:14:06 UTC (rev 1931) @@ -545,8 +545,12 @@ Function(tl); break; case T_BACKEND: - vcc_ParseBackend(tl); + vcc_ParseSimpleBackend(tl); break; + case T_BACKEND_RANDOM: + case T_BACKEND_ROUND_ROBIN: + vcc_ParseBalancedBackend(tl); + break; case EOI: break; default: Modified: trunk/varnish-cache/lib/libvcl/vcc_token_defs.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token_defs.h 2007-08-31 07:03:32 UTC (rev 1930) +++ trunk/varnish-cache/lib/libvcl/vcc_token_defs.h 2007-08-31 12:14:06 UTC (rev 1931) @@ -15,23 +15,25 @@ #define T_SUB 133 #define T_ACL 134 #define T_BACKEND 135 -#define T_INC 136 -#define T_DEC 137 -#define T_CAND 138 -#define T_COR 139 -#define T_LEQ 140 -#define T_EQ 141 -#define T_NEQ 142 -#define T_GEQ 143 -#define T_SHR 144 -#define T_SHL 145 -#define T_INCR 146 -#define T_DECR 147 -#define T_MUL 148 -#define T_DIV 149 -#define ID 150 -#define VAR 151 -#define CNUM 152 -#define CSTR 153 -#define EOI 154 -#define CSRC 155 +#define T_BACKEND_ROUND_ROBIN 136 +#define T_BACKEND_RANDOM 137 +#define T_INC 138 +#define T_DEC 139 +#define T_CAND 140 +#define T_COR 141 +#define T_LEQ 142 +#define T_EQ 143 +#define T_NEQ 144 +#define T_GEQ 145 +#define T_SHR 146 +#define T_SHL 147 +#define T_INCR 148 +#define T_DECR 149 +#define T_MUL 150 +#define T_DIV 151 +#define ID 152 +#define VAR 153 +#define CNUM 154 +#define CSTR 155 +#define EOI 156 +#define CSRC 157