From phk at projects.linpro.no Tue Jul 1 19:23:56 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 1 Jul 2008 21:23:56 +0200 (CEST) Subject: r2872 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20080701192356.C41CB1EC0FD@projects.linpro.no> Author: phk Date: 2008-07-01 21:23:56 +0200 (Tue, 01 Jul 2008) New Revision: 2872 Modified: trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Fix a brain-o in the backend identification string: We need to explicitly and uniquely identify all backend stanzas because they have individual metrics. Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2008-06-30 09:08:01 UTC (rev 2871) +++ trunk/varnish-cache/include/vrt.h 2008-07-01 19:23:56 UTC (rev 2872) @@ -45,10 +45,10 @@ * A backend is a host+port somewhere on the network */ struct vrt_backend { - const char *portname; - const char *hostname; - const char *vcl_name; - const char *ident; + char *portname; + char *hostname; + char *vcl_name; + char *ident; double connect_timeout; }; Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-06-30 09:08:01 UTC (rev 2871) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-01 19:23:56 UTC (rev 2872) @@ -72,16 +72,14 @@ */ static void -vcc_EmitBeIdent(struct vsb *v, const struct token *qual, int serial, const struct token *first, const struct token *last) +vcc_EmitBeIdent(struct vsb *v, const struct token *name, const char *qual, int serial, const struct token *first, const struct token *last) { vsb_printf(v, "\t.ident ="); - if (serial != 0 && qual != NULL) { - vsb_printf(v, "\n\t \"%.*s \"", PF(qual)); - qual = VTAILQ_NEXT(qual, list); - vsb_printf(v, "\n\t \"%.*s \"", PF(qual)); - vsb_printf(v, "\n\t \":: %d :: \"", serial); - } + AN(qual); + vsb_printf(v, "\n\t \"%s %.*s\"", qual, PF(name)); + if (serial != 0) + vsb_printf(v, "\n\t \"[%d]\"", serial); while (first != last) { if (first->dec != NULL) vsb_printf(v, "\n\t \"\\\"\" %.*s \"\\\" \"", @@ -213,7 +211,7 @@ */ static void -vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *qual, int serial) +vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial) { struct token *t_field; struct token *t_first; @@ -274,6 +272,7 @@ t_host = tl->t; vcc_NextToken(tl); } else if (vcc_IdIs(t_field, "port")) { + ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_port = tl->t; vcc_NextToken(tl); @@ -330,8 +329,8 @@ } ExpectErr(tl, '}'); - vcc_EmitBeIdent(tl->fh, qual, serial, t_first, tl->t); - Fh(tl, 0, "\t.vcl_name = \"%.*s", PF(qual)); + vcc_EmitBeIdent(tl->fh, name, qual, serial, t_first, tl->t); + Fh(tl, 0, "\t.vcl_name = \"%.*s", PF(name)); if (serial) Fh(tl, 0, "[%d]", serial); Fh(tl, 0, "\"\n};\n"); @@ -356,7 +355,7 @@ h->name = tl->t; vcc_NextToken(tl); - vcc_ParseBackendHost(tl, &nbh, h->name, 0); + vcc_ParseBackendHost(tl, &nbh, h->name, "backend", 0); ERRCHK(tl); h->hnum = nbh; @@ -421,7 +420,8 @@ vcc_IsField(tl, &t_field, fs); ERRCHK(tl); if (vcc_IdIs(t_field, "backend")) { - vcc_ParseBackendHost(tl, &nbh, t_dir, nelem); + vcc_ParseBackendHost(tl, &nbh, + t_dir, "random", nelem); Fc(tl, 0, " .host = &bh_%d,", nbh); ERRCHK(tl); } else if (vcc_IdIs(t_field, "weight")) { Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-06-30 09:08:01 UTC (rev 2871) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-01 19:23:56 UTC (rev 2872) @@ -399,10 +399,10 @@ vsb_cat(sb, " * A backend is a host+port somewhere on the network\n"); vsb_cat(sb, " */\n"); vsb_cat(sb, "struct vrt_backend {\n"); - vsb_cat(sb, " const char *portname;\n"); - vsb_cat(sb, " const char *hostname;\n"); - vsb_cat(sb, " const char *vcl_name;\n"); - vsb_cat(sb, " const char *ident;\n"); + vsb_cat(sb, " char *portname;\n"); + vsb_cat(sb, " char *hostname;\n"); + vsb_cat(sb, " char *vcl_name;\n"); + vsb_cat(sb, " char *ident;\n"); vsb_cat(sb, " double connect_timeout;\n"); vsb_cat(sb, "};\n"); vsb_cat(sb, "\n"); From phk at projects.linpro.no Tue Jul 1 19:29:01 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 1 Jul 2008 21:29:01 +0200 (CEST) Subject: r2873 - trunk/varnish-cache/bin/varnishd Message-ID: <20080701192901.D2CA51EC04B@projects.linpro.no> Author: phk Date: 2008-07-01 21:29:01 +0200 (Tue, 01 Jul 2008) New Revision: 2873 Modified: trunk/varnish-cache/bin/varnishd/vclflint.sh Log: Make it possible to run custom VCL programs through flexelint. Modified: trunk/varnish-cache/bin/varnishd/vclflint.sh =================================================================== --- trunk/varnish-cache/bin/varnishd/vclflint.sh 2008-07-01 19:23:56 UTC (rev 2872) +++ trunk/varnish-cache/bin/varnishd/vclflint.sh 2008-07-01 19:29:01 UTC (rev 2873) @@ -2,6 +2,12 @@ # # Run flexelint on the VCL output -./varnishd -C -b localhost > /tmp/_.c +if [ "x$1" = "x" ] ; then + ./varnishd -C -b localhost > /tmp/_.c +elif [ -f $1 ] ; then + ./varnishd -C -f $1 > /tmp/_.c +else + echo "usage!" 1>&2 +fi flexelint vclflint.lnt /tmp/_.c From phk at projects.linpro.no Tue Jul 1 19:30:11 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 1 Jul 2008 21:30:11 +0200 (CEST) Subject: r2874 - trunk/varnish-cache/bin/varnishd Message-ID: <20080701193011.9429E1EC0FD@projects.linpro.no> Author: phk Date: 2008-07-01 21:30:11 +0200 (Tue, 01 Jul 2008) New Revision: 2874 Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c Log: Fix cleanup errors on random director: release all backends. Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-07-01 19:29:01 UTC (rev 2873) +++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-07-01 19:30:11 UTC (rev 2874) @@ -57,12 +57,14 @@ struct director dir; struct backend *backend; struct vdi_random_host *hosts; + unsigned nhosts; }; static struct backend * vdi_random_choose(struct sess *sp) { + int i; struct vdi_random *vs; uint32_t r; struct vdi_random_host *vh; @@ -72,7 +74,7 @@ r = random(); r &= 0x7fffffff; - for (vh = vs->hosts; ; vh++) + for (vh = vs->hosts; i < vs->nhosts; vh++) if (r < vh->weight) return (vh->backend); assert(0 == __LINE__); @@ -82,14 +84,19 @@ static void vdi_random_fini(struct director *d) { + int i; struct vdi_random *vs; + struct vdi_random_host *vh; CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CAST_OBJ_NOTNULL(vs, d->priv, VDI_RANDOM_MAGIC); - VBE_DropRef(vs->backend); + vh = vs->hosts; + for (i = 0; i < vs->nhosts; i++, vh++) + VBE_DropRef(vh->backend); free(vs->hosts); - free(vs); + vs->dir.magic = 0; + FREE_OBJ(vs); } void @@ -104,12 +111,11 @@ (void)cli; - vs = calloc(sizeof *vs, 1); + ALLOC_OBJ(vs, VDI_RANDOM_MAGIC); XXXAN(vs); vs->hosts = calloc(sizeof *vh, t->nmember); XXXAN(vs->hosts); - vs->magic = VDI_RANDOM_MAGIC; vs->dir.magic = DIRECTOR_MAGIC; vs->dir.priv = vs; vs->dir.name = "random"; @@ -124,6 +130,7 @@ s += te->weight; vh->backend = VBE_AddBackend(cli, te->host); } + vs->nhosts = t->nmember; /* Normalize weights */ i = 0; From phk at projects.linpro.no Tue Jul 1 19:30:54 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 1 Jul 2008 21:30:54 +0200 (CEST) Subject: r2875 - trunk/varnish-cache/bin/varnishd Message-ID: <20080701193054.A61121ED339@projects.linpro.no> Author: phk Date: 2008-07-01 21:30:54 +0200 (Tue, 01 Jul 2008) New Revision: 2875 Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c Log: Use mini_obj more. dlclose() VCL's when we throw them out. Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vcl.c 2008-07-01 19:30:11 UTC (rev 2874) +++ trunk/varnish-cache/bin/varnishd/cache_vcl.c 2008-07-01 19:30:54 UTC (rev 2875) @@ -48,6 +48,8 @@ #include "cache.h" struct vcls { + unsigned magic; +#define VCLS_MAGIC 0x214188f2 VTAILQ_ENTRY(vcls) list; char *name; void *dlh; @@ -73,7 +75,7 @@ if (*vcc == vcl_active->conf) return; if (*vcc != NULL) - VCL_Rel(vcc); + VCL_Rel(vcc); /* XXX: optimize locking */ VCL_Get(vcc); } @@ -137,33 +139,32 @@ return (1); } - vcl = calloc(sizeof *vcl, 1); + ALLOC_OBJ(vcl, VCLS_MAGIC); XXXAN(vcl); vcl->dlh = dlopen(fn, RTLD_NOW | RTLD_LOCAL); if (vcl->dlh == NULL) { cli_out(cli, "dlopen(%s): %s\n", fn, dlerror()); - free(vcl); + FREE_OBJ(vcl); return (1); } vcl->conf = dlsym(vcl->dlh, "VCL_conf"); if (vcl->conf == NULL) { cli_out(cli, "No VCL_conf symbol\n"); (void)dlclose(vcl->dlh); - free(vcl); + FREE_OBJ(vcl); return (1); } if (vcl->conf->magic != VCL_CONF_MAGIC) { cli_out(cli, "Wrong VCL_CONF_MAGIC\n"); (void)dlclose(vcl->dlh); - free(vcl); + FREE_OBJ(vcl); return (1); } vcl->conf->priv = vcl; - vcl->name = strdup(name); - XXXAN(vcl->name); + REPLACE(vcl->name, name); VTAILQ_INSERT_TAIL(&vcl_head, vcl, list); LOCK(&vcl_mtx); if (vcl_active == NULL) @@ -176,7 +177,7 @@ /*-------------------------------------------------------------------- * This function is polled from the CLI thread to dispose of any non-busy - * VCLs * which have been discarded. + * VCLs which have been discarded. */ static void @@ -190,7 +191,8 @@ VTAILQ_REMOVE(&vcl_head, vcl, list); vcl->conf->fini_func(NULL); free(vcl->name); - free(vcl); + (void)dlclose(vcl->dlh); + FREE_OBJ(vcl); } /*--------------------------------------------------------------------*/ From phk at projects.linpro.no Tue Jul 1 19:31:16 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 1 Jul 2008 21:31:16 +0200 (CEST) Subject: r2876 - trunk/varnish-cache/bin/varnishd Message-ID: <20080701193116.B2AA01EC0FD@projects.linpro.no> Author: phk Date: 2008-07-01 21:31:16 +0200 (Tue, 01 Jul 2008) New Revision: 2876 Modified: trunk/varnish-cache/bin/varnishd/cache_dir_simple.c Log: Polish: use mini_obj.h Modified: trunk/varnish-cache/bin/varnishd/cache_dir_simple.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_simple.c 2008-07-01 19:30:54 UTC (rev 2875) +++ trunk/varnish-cache/bin/varnishd/cache_dir_simple.c 2008-07-01 19:31:16 UTC (rev 2876) @@ -73,7 +73,8 @@ CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC); VBE_DropRef(vs->backend); - free(vs); + vs->dir.magic = 0; + FREE_OBJ(vs); } void @@ -83,9 +84,8 @@ (void)cli; - vs = calloc(sizeof *vs, 1); + ALLOC_OBJ(vs, VDI_SIMPLE_MAGIC); XXXAN(vs); - vs->magic = VDI_SIMPLE_MAGIC; vs->dir.magic = DIRECTOR_MAGIC; vs->dir.priv = vs; vs->dir.name = "simple"; From phk at projects.linpro.no Tue Jul 1 19:31:53 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 1 Jul 2008 21:31:53 +0200 (CEST) Subject: r2877 - trunk/varnish-cache/bin/varnishd Message-ID: <20080701193153.4DA551ED339@projects.linpro.no> Author: phk Date: 2008-07-01 21:31:53 +0200 (Tue, 01 Jul 2008) New Revision: 2877 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c Log: Polishing: use mini_obj.h Use a hash for faster backend list search Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-07-01 19:31:16 UTC (rev 2876) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-07-01 19:31:53 UTC (rev 2877) @@ -33,6 +33,8 @@ * * The data structures: * + * A vrt_backend is a definition of a backend in a VCL program. + * * A backend is a TCP destination, possibly multi-homed and it has a * number of associated properties and statistics. * @@ -88,6 +90,7 @@ #define BACKEND_MAGIC 0x64c4c7c6 struct vrt_backend vrt[1]; + uint32_t hash; VTAILQ_ENTRY(backend) list; int refcount; @@ -117,8 +120,7 @@ * The list of backends is not locked, it is only ever accessed from * the CLI thread, so there is no need. */ -static VTAILQ_HEAD(, backend) backends = - VTAILQ_HEAD_INITIALIZER(backends); +static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends); /*-------------------------------------------------------------------- * Create default Host: header for backend request @@ -601,48 +603,50 @@ /*-------------------------------------------------------------------- * Add a backend/director instance when loading a VCL. - * If an existing backend is matched, grab a refcount and return one. - * Else create a new backend structure with reference initialized to one - * and return zero. + * If an existing backend is matched, grab a refcount and return. + * Else create a new backend structure with reference initialized to one. */ struct backend * VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb) { struct backend *b; + uint32_t u; AN(vb->hostname); AN(vb->portname); AN(vb->ident); (void)cli; ASSERT_CLI(); + u = crc32_l(vb->ident, strlen(vb->ident)); VTAILQ_FOREACH(b, &backends, list) { CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + if (u != b->hash) + continue; if (strcmp(b->vrt->ident, vb->ident)) continue; b->refcount++; return (b); } - b = calloc(sizeof *b, 1); + ALLOC_OBJ(b, BACKEND_MAGIC); XXXAN(b); b->magic = BACKEND_MAGIC; + VTAILQ_INIT(&b->connlist); + b->hash = u; - memcpy(b->vrt, vb, sizeof *vb); /* * This backend may live longer than the VCL that instantiated it - * so we cannot simply reference the VCL's copy of the strings. + * so we cannot simply reference the VCL's copy of things. */ - b->vrt->ident = strdup(vb->ident); - XXXAN(b->vrt->ident); - b->vrt->hostname = strdup(vb->hostname); - XXXAN(b->vrt->hostname); - b->vrt->portname = strdup(vb->portname); - XXXAN(b->vrt->portname); - b->vrt->vcl_name = strdup(vb->vcl_name); - XXXAN(b->vrt->vcl_name); + REPLACE(b->vrt->ident, vb->ident); + REPLACE(b->vrt->hostname, vb->hostname); + REPLACE(b->vrt->portname, vb->portname); + REPLACE(b->vrt->vcl_name, vb->vcl_name); + b->vrt->connect_timeout = vb->connect_timeout; + MTX_INIT(&b->mtx); b->refcount = 1; From phk at projects.linpro.no Mon Jul 7 16:33:58 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 18:33:58 +0200 (CEST) Subject: r2878 - trunk/varnish-cache/bin/varnishd Message-ID: <20080707163358.05A931EC0FD@projects.linpro.no> Author: phk Date: 2008-07-07 18:33:57 +0200 (Mon, 07 Jul 2008) New Revision: 2878 Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c Log: White space fix Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2008-07-01 19:31:53 UTC (rev 2877) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2008-07-07 16:33:57 UTC (rev 2878) @@ -198,7 +198,7 @@ if (params->sess_timeout != tv_rcvtimeo.tv_sec) { need_test = 1; tv_rcvtimeo.tv_sec = params->sess_timeout; - VTAILQ_FOREACH(ls, &heritage.socks, list) { + VTAILQ_FOREACH(ls, &heritage.socks, list) { if (ls->sock < 0) continue; AZ(setsockopt(ls->sock, SOL_SOCKET, @@ -356,7 +356,7 @@ if (!strcmp(arg, "default")) { vca_act = NULL; return; - } + } for (i = 0; vca_acceptors[i]->name; i++) { if (!strcmp(arg, vca_acceptors[i]->name)) { vca_act = vca_acceptors[i]; From phk at projects.linpro.no Mon Jul 7 17:16:50 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 19:16:50 +0200 (CEST) Subject: r2879 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080707171650.EBF711ED288@projects.linpro.no> Author: phk Date: 2008-07-07 19:16:50 +0200 (Mon, 07 Jul 2008) New Revision: 2879 Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Add -badvcl for VCL code we expect the compiler to whine about. Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-07 16:33:57 UTC (rev 2878) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-07 17:16:50 UTC (rev 2879) @@ -310,7 +310,7 @@ */ static void -varnish_vcl(struct varnish *v, const char *vcl) +varnish_vcl(struct varnish *v, const char *vcl, enum cli_status_e expect) { struct vsb *vsb; enum cli_status_e u; @@ -343,13 +343,15 @@ AZ(vsb_overflowed(vsb)); u = varnish_ask_cli(v, vsb_data(vsb), NULL); - assert(u == CLIS_OK); - vsb_clear(vsb); - vsb_printf(vsb, "vcl.use vcl%d", v->vcl_nbr); - vsb_finish(vsb); - AZ(vsb_overflowed(vsb)); - u = varnish_ask_cli(v, vsb_data(vsb), NULL); - assert(u == CLIS_OK); + assert(u == expect); + if (u == CLIS_OK) { + vsb_clear(vsb); + vsb_printf(vsb, "vcl.use vcl%d", v->vcl_nbr); + vsb_finish(vsb); + AZ(vsb_overflowed(vsb)); + u = varnish_ask_cli(v, vsb_data(vsb), NULL); + assert(u == CLIS_OK); + } vsb_delete(vsb); } @@ -466,8 +468,13 @@ av++; continue; } + if (!strcmp(*av, "-badvcl")) { + varnish_vcl(v, av[1], CLIS_PARAM); + av++; + continue; + } if (!strcmp(*av, "-vcl")) { - varnish_vcl(v, av[1]); + varnish_vcl(v, av[1], CLIS_OK); av++; continue; } From phk at projects.linpro.no Mon Jul 7 17:19:10 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 19:19:10 +0200 (CEST) Subject: r2880 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080707171910.7F02B1EC202@projects.linpro.no> Author: phk Date: 2008-07-07 19:19:10 +0200 (Mon, 07 Jul 2008) New Revision: 2880 Added: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc Log: Add test-case or syntax-checks of backend decls. Added: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 17:19:10 UTC (rev 2880) @@ -0,0 +1,36 @@ +# $Id$ + +test "VCL: test syntax/semantic checks on backend decls." + +# Missing .host +varnish v1 -badvcl { + backend b1 { + .port = "http"; + } +} + +# Too many .host +varnish v1 -badvcl { + backend b1 { + .host = "foo"; + .host = "bar"; + } +} + +# Too many .port +varnish v1 -badvcl { + backend b1 { + .host = "foo"; + .port = "http"; + .port = "https"; + } +} + +# Too many .connect_timeout +varnish v1 -badvcl { + backend b1 { + .host = "foo"; + .connect_timeout = 1m; + .connect_timeout = 1m; + } +} From phk at projects.linpro.no Mon Jul 7 17:19:32 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 19:19:32 +0200 (CEST) Subject: r2881 - trunk/varnish-cache/lib/libvcl Message-ID: <20080707171932.EE1711EC0EA@projects.linpro.no> Author: phk Date: 2008-07-07 19:19:32 +0200 (Mon, 07 Jul 2008) New Revision: 2881 Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c Log: Improve error messages related to syntax check of backend decls. Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 17:19:10 UTC (rev 2880) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 17:19:32 UTC (rev 2881) @@ -172,7 +172,7 @@ return; } -static void +static int vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs) { int ok = 1; @@ -180,14 +180,11 @@ for (; fs->name != NULL; fs++) { if (*fs->name == '!' && fs->found == NULL) { vsb_printf(tl->sb, - "Mandatory field .'%s' missing.\n", fs->name + 1); + "Mandatory field '%s' missing.\n", fs->name + 1); ok = 0; } } - if (!ok) { - vcc_ErrWhere(tl, tl->t); - } - return; + return (ok); } @@ -291,9 +288,7 @@ ExpectErr(tl, ';'); vcc_NextToken(tl); } - if (!tl->err) - vcc_FieldsOk(tl, fs); - if (tl->err) { + if (tl->err || !vcc_FieldsOk(tl, fs)) { vsb_printf(tl->sb, "\nIn backend host specfication starting at:\n"); vcc_ErrWhere(tl, t_first); From phk at projects.linpro.no Mon Jul 7 17:21:58 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 19:21:58 +0200 (CEST) Subject: r2882 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080707172158.1A3421EC202@projects.linpro.no> Author: phk Date: 2008-07-07 19:21:57 +0200 (Mon, 07 Jul 2008) New Revision: 2882 Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Just to avoid misunderstandings: say that we expected the VCL compilation errors. Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-07 17:19:32 UTC (rev 2881) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-07 17:21:57 UTC (rev 2882) @@ -351,6 +351,8 @@ AZ(vsb_overflowed(vsb)); u = varnish_ask_cli(v, vsb_data(vsb), NULL); assert(u == CLIS_OK); + } else { + vtc_log(v->vl, 2, "VCL compilation failed (as expected)"); } vsb_delete(vsb); } From phk at projects.linpro.no Mon Jul 7 17:42:27 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 19:42:27 +0200 (CEST) Subject: r2883 - trunk/varnish-cache/lib/libvcl Message-ID: <20080707174227.D73181ED288@projects.linpro.no> Author: phk Date: 2008-07-07 19:42:27 +0200 (Mon, 07 Jul 2008) New Revision: 2883 Modified: trunk/varnish-cache/lib/libvcl/flint.sh trunk/varnish-cache/lib/libvcl/vcc_backend.c Log: Improve error messages in backend specifications Modified: trunk/varnish-cache/lib/libvcl/flint.sh =================================================================== --- trunk/varnish-cache/lib/libvcl/flint.sh 2008-07-07 17:21:57 UTC (rev 2882) +++ trunk/varnish-cache/lib/libvcl/flint.sh 2008-07-07 17:42:27 UTC (rev 2883) @@ -3,6 +3,7 @@ flexelint \ -I/usr/include \ -I. \ + -I../.. \ -I../../include \ -I../../contrib/libevent \ flint.lnt \ Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 17:21:57 UTC (rev 2882) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 17:42:27 UTC (rev 2883) @@ -187,15 +187,13 @@ return (ok); } - /*-------------------------------------------------------------------- - * Parse and emit a backend host specification. + * Parse and emit a backend host definition * * The syntax is the following: * - * backend_spec: - * name_of_backend # by reference - * '{' be_elements '}' # by specification + * backend_host_def: + * '{' be_elements '}' * * be_elements: * be_element @@ -208,38 +206,18 @@ */ static void -vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial) +vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial) { struct token *t_field; struct token *t_first; struct token *t_host = NULL; struct token *t_port = NULL; const char *ep; - struct host *h; struct fld_spec *fs; fs = vcc_FldSpec(tl, "!host", "?port", "?connect_timeout", NULL); t_first = tl->t; - if (tl->t->tok == ID) { - VTAILQ_FOREACH(h, &tl->hosts, list) { - if (vcc_Teq(h->name, tl->t)) - break; - } - if (h == NULL) { - vsb_printf(tl->sb, "Reference to unknown backend "); - vcc_ErrToken(tl, tl->t); - vsb_printf(tl->sb, " at\n"); - vcc_ErrWhere(tl, tl->t); - return; - } - vcc_AddRef(tl, h->name, R_BACKEND); - vcc_NextToken(tl); - ExpectErr(tl, ';'); - vcc_NextToken(tl); - *nbh = h->hnum; - return; - } ExpectErr(tl, '{'); vcc_NextToken(tl); @@ -333,6 +311,53 @@ } /*-------------------------------------------------------------------- + * Parse and emit a backend host specification. + * + * The syntax is the following: + * + * backend_spec: + * name_of_backend # by reference + * '{' be_elements '}' # by specification + * + * The struct vrt_backend is emitted to Fh(). + */ + +static void +vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial) +{ + struct host *h; + + if (tl->t->tok == ID) { + VTAILQ_FOREACH(h, &tl->hosts, list) { + if (vcc_Teq(h->name, tl->t)) + break; + } + if (h == NULL) { + vsb_printf(tl->sb, "Reference to unknown backend "); + vcc_ErrToken(tl, tl->t); + vsb_printf(tl->sb, " at\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + vcc_AddRef(tl, h->name, R_BACKEND); + vcc_NextToken(tl); + ExpectErr(tl, ';'); + vcc_NextToken(tl); + *nbh = h->hnum; + } else if (tl->t->tok == '{') { + vcc_ParseHostDef(tl, nbh, name, qual, serial); + } else { + vsb_printf(tl->sb, + "Expected a backend specification here, either by name " + "or by {...}\n"); + vcc_ErrToken(tl, tl->t); + vsb_printf(tl->sb, " at\n"); + vcc_ErrWhere(tl, tl->t); + return; + } +} + +/*-------------------------------------------------------------------- * Parse a plain backend */ @@ -383,7 +408,7 @@ static void vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir) { - struct token *t_field; + struct token *t_field, *t_be; int nbh, nelem; struct fld_spec *fs; unsigned u; @@ -404,6 +429,7 @@ PF(t_dir)); for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */ + t_be = tl->t; vcc_ResetFldSpec(fs); nbh = -1; @@ -438,8 +464,12 @@ ErrInternal(tl); } } - vcc_FieldsOk(tl, fs); - ERRCHK(tl); + if (!vcc_FieldsOk(tl, fs)) { + vsb_printf(tl->sb, + "\nIn member host specfication starting at:\n"); + vcc_ErrWhere(tl, t_be); + return; + } Fc(tl, 0, " },\n"); vcc_NextToken(tl); } From phk at projects.linpro.no Mon Jul 7 17:42:42 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 19:42:42 +0200 (CEST) Subject: r2884 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080707174242.AC3321EC202@projects.linpro.no> Author: phk Date: 2008-07-07 19:42:42 +0200 (Mon, 07 Jul 2008) New Revision: 2884 Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc Log: Add a test-case for backend reference errors. Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 17:42:27 UTC (rev 2883) +++ trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 17:42:42 UTC (rev 2884) @@ -34,3 +34,13 @@ .connect_timeout = 1m; } } + +# Check backend reference by name +varnish v1 -badvcl { + backend b1 { .host = "127.0.0.2"; } + director r1 random { + { .weight = 1; .backend = b1; } + { .weight = 1; .backend = { .host = "127.0.0.3"; } } + { .weight = 1; .backend = 3745; } // Brownie points for getting the joke + } +} From phk at projects.linpro.no Mon Jul 7 18:02:07 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 20:02:07 +0200 (CEST) Subject: r2885 - trunk/varnish-cache/lib/libvcl Message-ID: <20080707180207.117E61ED28D@projects.linpro.no> Author: phk Date: 2008-07-07 20:02:06 +0200 (Mon, 07 Jul 2008) New Revision: 2885 Added: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c Modified: trunk/varnish-cache/lib/libvcl/Makefile.am trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_priv.h Log: Move random director to separate source file. Modified: trunk/varnish-cache/lib/libvcl/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvcl/Makefile.am 2008-07-07 17:42:42 UTC (rev 2884) +++ trunk/varnish-cache/lib/libvcl/Makefile.am 2008-07-07 18:02:06 UTC (rev 2885) @@ -13,6 +13,7 @@ vcc_action.c \ vcc_backend.c \ vcc_compile.c \ + vcc_dir_random.c \ vcc_parse.c \ vcc_fixed_token.c \ vcc_obj.c \ Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 17:42:42 UTC (rev 2884) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 18:02:06 UTC (rev 2885) @@ -100,7 +100,7 @@ struct token *found; }; -static void +void vcc_ResetFldSpec(struct fld_spec *f) { @@ -108,7 +108,7 @@ f->found = NULL; } -static struct fld_spec * +struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...) { struct fld_spec f[100], *r; @@ -136,7 +136,7 @@ } -static void +void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs) { struct token *t_field; @@ -172,7 +172,7 @@ return; } -static int +int vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs) { int ok = 1; @@ -322,7 +322,7 @@ * The struct vrt_backend is emitted to Fh(). */ -static void +void vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial) { struct host *h; @@ -405,94 +405,6 @@ * Parse directors */ -static void -vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir) -{ - struct token *t_field, *t_be; - int nbh, nelem; - struct fld_spec *fs; - unsigned u; - - Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.director[%d])\n", - PF(t_dir), tl->nbackend); - vcc_AddDef(tl, t_dir, R_BACKEND); - - fs = vcc_FldSpec(tl, "!backend", "!weight", NULL); - - vcc_NextToken(tl); /* ID: policy (= random) */ - - ExpectErr(tl, '{'); - vcc_NextToken(tl); - - Fc(tl, 0, - "\nstatic const struct vrt_dir_random_entry vdre_%.*s[] = {\n", - PF(t_dir)); - - for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */ - t_be = tl->t; - vcc_ResetFldSpec(fs); - nbh = -1; - - ExpectErr(tl, '{'); - vcc_NextToken(tl); - Fc(tl, 0, "\t{"); - - while (tl->t->tok != '}') { /* Member fields */ - vcc_IsField(tl, &t_field, fs); - ERRCHK(tl); - if (vcc_IdIs(t_field, "backend")) { - vcc_ParseBackendHost(tl, &nbh, - t_dir, "random", nelem); - Fc(tl, 0, " .host = &bh_%d,", nbh); - ERRCHK(tl); - } else if (vcc_IdIs(t_field, "weight")) { - ExpectErr(tl, CNUM); - u = vcc_UintVal(tl); - if (u == 0) { - vsb_printf(tl->sb, - "The .weight must be higher than zero."); - vcc_ErrToken(tl, tl->t); - vsb_printf(tl->sb, " at\n"); - vcc_ErrWhere(tl, tl->t); - return; - } - Fc(tl, 0, " .weight = %u", u); - vcc_NextToken(tl); - ExpectErr(tl, ';'); - vcc_NextToken(tl); - } else { - ErrInternal(tl); - } - } - if (!vcc_FieldsOk(tl, fs)) { - vsb_printf(tl->sb, - "\nIn member host specfication starting at:\n"); - vcc_ErrWhere(tl, t_be); - return; - } - Fc(tl, 0, " },\n"); - vcc_NextToken(tl); - } - Fc(tl, 0, "\t{ .host = 0 }\n"); - Fc(tl, 0, "};\n"); - Fc(tl, 0, - "\nstatic const struct vrt_dir_random vdr_%.*s = {\n", - PF(t_dir)); - Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir)); - Fc(tl, 0, "\t.nmember = %d,\n", nelem); - Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(t_dir)); - Fc(tl, 0, "};\n"); - vcc_NextToken(tl); - Fi(tl, 0, - "\tVRT_init_dir_random(cli, &VGC_backend_%.*s , &vdr_%.*s);\n", - PF(t_dir), PF(t_dir)); - Ff(tl, 0, "\tVRT_fini_dir(cli, VGC_backend_%.*s);\n", PF(t_dir)); -} - -/*-------------------------------------------------------------------- - * Parse directors - */ - void vcc_ParseDirector(struct tokenlist *tl) { Copied: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c (from rev 2883, trunk/varnish-cache/lib/libvcl/vcc_backend.c) =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_dir_random.c (rev 0) +++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-07 18:02:06 UTC (rev 2885) @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2008 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +#include "config.h" + +#include +#include + +#include +#include +#include +#include + +#include "vsb.h" + +#include "vcc_priv.h" +#include "vcc_compile.h" +#include "libvarnish.h" + +/*-------------------------------------------------------------------- + * Parse directors + */ + +void +vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir) +{ + struct token *t_field, *t_be; + int nbh, nelem; + struct fld_spec *fs; + unsigned u; + + Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.director[%d])\n", + PF(t_dir), tl->nbackend); + vcc_AddDef(tl, t_dir, R_BACKEND); + + fs = vcc_FldSpec(tl, "!backend", "!weight", NULL); + + vcc_NextToken(tl); /* ID: policy (= random) */ + + ExpectErr(tl, '{'); + vcc_NextToken(tl); + + Fc(tl, 0, + "\nstatic const struct vrt_dir_random_entry vdre_%.*s[] = {\n", + PF(t_dir)); + + for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */ + t_be = tl->t; + vcc_ResetFldSpec(fs); + nbh = -1; + + ExpectErr(tl, '{'); + vcc_NextToken(tl); + Fc(tl, 0, "\t{"); + + while (tl->t->tok != '}') { /* Member fields */ + vcc_IsField(tl, &t_field, fs); + ERRCHK(tl); + if (vcc_IdIs(t_field, "backend")) { + vcc_ParseBackendHost(tl, &nbh, + t_dir, "random", nelem); + Fc(tl, 0, " .host = &bh_%d,", nbh); + ERRCHK(tl); + } else if (vcc_IdIs(t_field, "weight")) { + ExpectErr(tl, CNUM); + u = vcc_UintVal(tl); + if (u == 0) { + vsb_printf(tl->sb, + "The .weight must be higher than zero."); + vcc_ErrToken(tl, tl->t); + vsb_printf(tl->sb, " at\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + Fc(tl, 0, " .weight = %u", u); + vcc_NextToken(tl); + ExpectErr(tl, ';'); + vcc_NextToken(tl); + } else { + ErrInternal(tl); + } + } + if (!vcc_FieldsOk(tl, fs)) { + vsb_printf(tl->sb, + "\nIn member host specfication starting at:\n"); + vcc_ErrWhere(tl, t_be); + return; + } + Fc(tl, 0, " },\n"); + vcc_NextToken(tl); + } + Fc(tl, 0, "\t{ .host = 0 }\n"); + Fc(tl, 0, "};\n"); + Fc(tl, 0, + "\nstatic const struct vrt_dir_random vdr_%.*s = {\n", + PF(t_dir)); + Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir)); + Fc(tl, 0, "\t.nmember = %d,\n", nelem); + Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(t_dir)); + Fc(tl, 0, "};\n"); + vcc_NextToken(tl); + Fi(tl, 0, + "\tVRT_init_dir_random(cli, &VGC_backend_%.*s , &vdr_%.*s);\n", + PF(t_dir), PF(t_dir)); + Ff(tl, 0, "\tVRT_fini_dir(cli, VGC_backend_%.*s);\n", PF(t_dir)); +} Property changes on: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c ___________________________________________________________________ Name: svn:keywords + Id Name: svn:mergeinfo + Modified: trunk/varnish-cache/lib/libvcl/vcc_priv.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_priv.h 2008-07-07 17:42:42 UTC (rev 2884) +++ trunk/varnish-cache/lib/libvcl/vcc_priv.h 2008-07-07 18:02:06 UTC (rev 2885) @@ -34,6 +34,8 @@ #include "vcc_token_defs.h" struct vsb; +struct tokenlist; +struct token; #define isident1(c) (isalpha(c)) #define isident(c) (isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-') @@ -44,3 +46,18 @@ void vcl_output_lang_h(struct vsb *sb); #define PF(t) (int)((t)->e - (t)->b), (t)->b + +/* vcc_backend.c */ +struct fld_spec; +struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...); +void vcc_ResetFldSpec(struct fld_spec *f); +void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs); +int vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs); +void vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial); + + + + +/* vcc_dir_random.c */ +void vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir); + From phk at projects.linpro.no Mon Jul 7 18:21:06 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 20:21:06 +0200 (CEST) Subject: r2886 - trunk/varnish-cache/lib/libvcl Message-ID: <20080707182106.A0C7F1EC202@projects.linpro.no> Author: phk Date: 2008-07-07 20:21:06 +0200 (Mon, 07 Jul 2008) New Revision: 2886 Modified: 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_parse.c trunk/varnish-cache/lib/libvcl/vcc_token_defs.h Log: Redo toplevel parser to use table. Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-07 18:02:06 UTC (rev 2885) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-07 18:21:06 UTC (rev 2886) @@ -159,13 +159,6 @@ return ('>'); } return (0); - case 'a': - if (p[0] == 'a' && p[1] == 'c' && p[2] == 'l' - && !isvar(p[3])) { - *q = p + 3; - return (T_ACL); - } - return (0); case 'e': if (p[0] == 'e' && p[1] == 'l' && p[2] == 's' && p[3] == 'i' && p[4] == 'f' && !isvar(p[5])) { @@ -196,13 +189,6 @@ return (T_IF); } return (0); - case 's': - if (p[0] == 's' && p[1] == 'u' && p[2] == 'b' - && !isvar(p[3])) { - *q = p + 3; - return (T_SUB); - } - return (0); case '{': if (p[0] == '{') { *q = p + 1; @@ -265,7 +251,6 @@ vcl_tnames[CSTR] = "CSTR"; vcl_tnames[EOI] = "EOI"; vcl_tnames[ID] = "ID"; - vcl_tnames[T_ACL] = "acl"; vcl_tnames[T_CAND] = "&&"; vcl_tnames[T_COR] = "||"; vcl_tnames[T_DEC] = "--"; @@ -285,7 +270,6 @@ vcl_tnames[T_NEQ] = "!="; vcl_tnames[T_SHL] = "<<"; vcl_tnames[T_SHR] = ">>"; - vcl_tnames[T_SUB] = "sub"; vcl_tnames[VAR] = "VAR"; } Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2008-07-07 18:02:06 UTC (rev 2885) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2008-07-07 18:21:06 UTC (rev 2886) @@ -69,10 +69,6 @@ include if else elseif elsif - - sub - - acl } # Non-word tokens Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2008-07-07 18:02:06 UTC (rev 2885) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2008-07-07 18:21:06 UTC (rev 2886) @@ -552,19 +552,27 @@ * End of input */ +typedef void parse_f(struct tokenlist *tl); + +static struct toplev { + const char *name; + parse_f *func; +} toplev[] = { + { "acl", vcc_Acl }, + { "sub", Function }, + { "backend", vcc_ParseBackend }, + { "director", vcc_ParseDirector }, + { NULL, NULL } +}; + void vcc_Parse(struct tokenlist *tl) { + struct toplev *tp; while (tl->t->tok != EOI) { ERRCHK(tl); switch (tl->t->tok) { - case T_ACL: - vcc_Acl(tl); - break; - case T_SUB: - Function(tl); - break; case CSRC: Fc(tl, 0, "%.*s\n", tl->t->e - (tl->t->b + 4), tl->t->b + 2); @@ -573,18 +581,25 @@ case EOI: break; case ID: - if (vcc_IdIs(tl->t, "backend")) { - vcc_ParseBackend(tl); + for (tp = toplev; tp->name != NULL; tp++) { + if (!vcc_IdIs(tl->t, tp->name)) + continue; + tp->func(tl); break; } - if (vcc_IdIs(tl->t, "director")) { - vcc_ParseDirector(tl); + if (tp->name != NULL) break; - } /* FALLTHROUGH */ default: - vsb_printf(tl->sb, - "Expected 'acl', 'sub' or 'backend', found "); + vsb_printf(tl->sb, "Expected one of\n\t"); + for (tp = toplev; tp->name != NULL; tp++) { + if (tp[1].name == NULL) + vsb_printf(tl->sb, " or "); + vsb_printf(tl->sb, "'%s'", tp->name); + if (tp[1].name != NULL) + vsb_printf(tl->sb, ", "); + } + vsb_printf(tl->sb, "\nFound: "); vcc_ErrToken(tl, tl->t); vsb_printf(tl->sb, " at\n"); vcc_ErrWhere(tl, tl->t); Modified: trunk/varnish-cache/lib/libvcl/vcc_token_defs.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token_defs.h 2008-07-07 18:02:06 UTC (rev 2885) +++ trunk/varnish-cache/lib/libvcl/vcc_token_defs.h 2008-07-07 18:21:06 UTC (rev 2886) @@ -12,25 +12,23 @@ #define T_ELSE 130 #define T_ELSEIF 131 #define T_ELSIF 132 -#define T_SUB 133 -#define T_ACL 134 -#define T_INC 135 -#define T_DEC 136 -#define T_CAND 137 -#define T_COR 138 -#define T_LEQ 139 -#define T_EQ 140 -#define T_NEQ 141 -#define T_GEQ 142 -#define T_SHR 143 -#define T_SHL 144 -#define T_INCR 145 -#define T_DECR 146 -#define T_MUL 147 -#define T_DIV 148 -#define ID 149 -#define VAR 150 -#define CNUM 151 -#define CSTR 152 -#define EOI 153 -#define CSRC 154 +#define T_INC 133 +#define T_DEC 134 +#define T_CAND 135 +#define T_COR 136 +#define T_LEQ 137 +#define T_EQ 138 +#define T_NEQ 139 +#define T_GEQ 140 +#define T_SHR 141 +#define T_SHL 142 +#define T_INCR 143 +#define T_DECR 144 +#define T_MUL 145 +#define T_DIV 146 +#define ID 147 +#define VAR 148 +#define CNUM 149 +#define CSTR 150 +#define EOI 151 +#define CSRC 152 From phk at projects.linpro.no Mon Jul 7 18:26:15 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 20:26:15 +0200 (CEST) Subject: r2887 - trunk/varnish-cache/lib/libvcl Message-ID: <20080707182615.97AA81ED28D@projects.linpro.no> Author: phk Date: 2008-07-07 20:26:15 +0200 (Mon, 07 Jul 2008) New Revision: 2887 Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c Log: Don't allow the invisible simple director to reference backend defined by another simple director, it would be too hard to explain why they shared statistics and harder yet to make them not do so. Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 18:21:06 UTC (rev 2886) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 18:26:15 UTC (rev 2887) @@ -375,7 +375,7 @@ h->name = tl->t; vcc_NextToken(tl); - vcc_ParseBackendHost(tl, &nbh, h->name, "backend", 0); + vcc_ParseHostDef(tl, &nbh, h->name, "backend", 0); ERRCHK(tl); h->hnum = nbh; From phk at projects.linpro.no Mon Jul 7 20:26:59 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 22:26:59 +0200 (CEST) Subject: r2888 - trunk/varnish-cache/lib/libvcl Message-ID: <20080707202659.277E61EC202@projects.linpro.no> Author: phk Date: 2008-07-07 22:26:58 +0200 (Mon, 07 Jul 2008) New Revision: 2888 Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_priv.h Log: Move backend stuff to the correct .h file Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-07 18:26:15 UTC (rev 2887) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-07 20:26:58 UTC (rev 2888) @@ -158,8 +158,14 @@ void vcc_ParseAction(struct tokenlist *tl); /* vcc_backend.c */ +struct fld_spec; void vcc_ParseBackend(struct tokenlist *tl); void vcc_ParseDirector(struct tokenlist *tl); +struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...); +void vcc_ResetFldSpec(struct fld_spec *f); +void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs); +int vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs); +void vcc_ParseBackendHost(struct tokenlist *tl, int *nbr, const struct token *name, const char *qual, int serial); /* vcc_compile.c */ extern struct method method_tab[]; @@ -173,6 +179,9 @@ void TlFree(struct tokenlist *tl, void *p); void *TlAlloc(struct tokenlist *tl, unsigned len); +/* vcc_dir_random.c */ +void vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir); + /* vcc_obj.c */ extern struct var vcc_vars[]; Modified: trunk/varnish-cache/lib/libvcl/vcc_priv.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_priv.h 2008-07-07 18:26:15 UTC (rev 2887) +++ trunk/varnish-cache/lib/libvcl/vcc_priv.h 2008-07-07 20:26:58 UTC (rev 2888) @@ -34,8 +34,6 @@ #include "vcc_token_defs.h" struct vsb; -struct tokenlist; -struct token; #define isident1(c) (isalpha(c)) #define isident(c) (isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-') @@ -46,18 +44,3 @@ void vcl_output_lang_h(struct vsb *sb); #define PF(t) (int)((t)->e - (t)->b), (t)->b - -/* vcc_backend.c */ -struct fld_spec; -struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...); -void vcc_ResetFldSpec(struct fld_spec *f); -void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs); -int vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs); -void vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial); - - - - -/* vcc_dir_random.c */ -void vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir); - From phk at projects.linpro.no Mon Jul 7 21:01:25 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 23:01:25 +0200 (CEST) Subject: r2889 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl Message-ID: <20080707210125.B8F3C1EC203@projects.linpro.no> Author: phk Date: 2008-07-07 23:01:25 +0200 (Mon, 07 Jul 2008) New Revision: 2889 Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_dir_random.c trunk/varnish-cache/lib/libvcl/vcc_token.c trunk/varnish-cache/lib/libvcl/vcc_xref.c Log: More polishing of backend compilation. Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 20:26:58 UTC (rev 2888) +++ trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 21:01:25 UTC (rev 2889) @@ -2,6 +2,20 @@ test "VCL: test syntax/semantic checks on backend decls." +# Missing backend +varnish v1 -badvcl { +} + +# Reference to non-existent backend +varnish v1 -badvcl { + backend b1 { + .host = "localhost"; + } + sub vcl_recv { + set req.backend = b2; + } +} + # Missing .host varnish v1 -badvcl { backend b1 { @@ -44,3 +58,23 @@ { .weight = 1; .backend = 3745; } // Brownie points for getting the joke } } + +# Check backend reference by name +varnish v1 -badvcl { + backend b1 { .host = "127.0.0.2"; } + backend b2 b1; +} + +# Check backend reference by non-C-compat name +varnish v1 -badvcl { + backend b-1 { .host = "127.0.0.2"; } +} + +# Assign backend by non-C-compat name +# Check backend reference by non-C-compat name +varnish v1 -badvcl { + backend b1 { .host = "127.0.0.2"; } + sub vcl_recv { + set req.backend = b-1; + } +} Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-07 20:26:58 UTC (rev 2888) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-07 21:01:25 UTC (rev 2889) @@ -221,6 +221,8 @@ return; } vcc_NextToken(tl); + vcc_ExpectCid(tl); + ERRCHK(tl); vcc_AddRef(tl, tl->t, R_BACKEND); Fb(tl, 0, "VGC_backend_%.*s", PF(tl->t)); vcc_NextToken(tl); Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 20:26:58 UTC (rev 2888) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 21:01:25 UTC (rev 2889) @@ -27,6 +27,27 @@ * SUCH DAMAGE. * * $Id$ + * + * A necessary explanation of a convoluted policy: + * + * In VCL we have backends and directors. + * + * In VRT we have directors which reference (a number of) backend hosts. + * + * A VCL backend therefore has an implicit director of type "simple" created + * by the compiler, but not visible in VCL. + * + * A VCL backend is a "named host", these can be referenced by name form + * VCL directors, but not from VCL backends. + * + * The reason for this quasimadness is that we want to collect statistics + * for each actual kickable hardware backend machine, but we want to be + * able to refer to them multiple times in different directors. + * + * At the same time, we do not want to force users to declare each backend + * host with a name, if all they want to do is put it into a director, so + * backend hosts can be declared inline in the director, in which case + * its identity is the director and its numerical index therein. */ #include "config.h" @@ -45,6 +66,13 @@ #include "vcc_compile.h" #include "libvarnish.h" +struct host { + VTAILQ_ENTRY(host) list; + int hnum; + struct token *name; +}; + + static const char * CheckHostPort(const char *host, const char *port) { @@ -365,25 +393,24 @@ vcc_ParseBackend(struct tokenlist *tl) { struct host *h; - int nbh; h = TlAlloc(tl, sizeof *h); vcc_NextToken(tl); - ExpectErr(tl, ID); /* name */ + vcc_ExpectCid(tl); /* ID: name */ + ERRCHK(tl); h->name = tl->t; vcc_NextToken(tl); - vcc_ParseHostDef(tl, &nbh, h->name, "backend", 0); + vcc_ParseHostDef(tl, &h->hnum, h->name, "backend", 0); ERRCHK(tl); - h->hnum = nbh; VTAILQ_INSERT_TAIL(&tl->hosts, h, list); /* In the compiled vcl we use these macros to refer to backends */ Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.director[%d])\n", - PF(h->name), tl->nbackend); + PF(h->name), tl->ndirector); vcc_AddDef(tl, h->name, R_BACKEND); @@ -395,10 +422,10 @@ Fc(tl, 0, "\nstatic const struct vrt_dir_simple sbe_%.*s = {\n", PF(h->name)); Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(h->name)); - Fc(tl, 0, "\t.host = &bh_%d,\n", nbh); + Fc(tl, 0, "\t.host = &bh_%d,\n", h->hnum); Fc(tl, 0, "};\n"); - tl->nbackend++; + tl->ndirector++; } /*-------------------------------------------------------------------- @@ -413,7 +440,8 @@ t_first = tl->t; vcc_NextToken(tl); /* ID: director */ - ExpectErr(tl, ID); /* ID: name */ + vcc_ExpectCid(tl); /* ID: name */ + ERRCHK(tl); t_dir = tl->t; vcc_NextToken(tl); @@ -434,5 +462,5 @@ vcc_ErrWhere(tl, t_first); return; } - tl->nbackend++; + tl->ndirector++; } Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2008-07-07 20:26:58 UTC (rev 2888) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2008-07-07 21:01:25 UTC (rev 2889) @@ -341,13 +341,14 @@ } Fc(tl, 0, "};\n"); - Fc(tl, 0, "\nstatic struct director\t*directors[%d];\n", tl->nbackend); + Fc(tl, 0, "\nstatic struct director\t*directors[%d];\n", + tl->ndirector); Fc(tl, 0, "\nconst struct 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.ndirector = %d,\n", tl->nbackend); + Fc(tl, 0, "\t.ndirector = %d,\n", tl->ndirector); Fc(tl, 0, "\t.director = directors,\n"); Fc(tl, 0, "\t.ref = VGC_ref,\n"); Fc(tl, 0, "\t.nref = VGC_NREFS,\n"); @@ -596,9 +597,10 @@ return (vcc_DestroyTokenList(tl, NULL)); /* Check if we have any backends at all */ - if (tl->nbackend == 0) { + if (tl->ndirector == 0) { vsb_printf(tl->sb, - "No backends in VCL program, at least one is necessary.\n"); + "No backends or directors found in VCL program, " + "at least one is necessary.\n"); tl->err = 1; return (vcc_DestroyTokenList(tl, NULL)); } Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-07 20:26:58 UTC (rev 2888) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-07 21:01:25 UTC (rev 2889) @@ -59,12 +59,6 @@ char *dec; }; -struct host { - VTAILQ_ENTRY(host) list; - unsigned hnum; - struct token *name; -}; - VTAILQ_HEAD(tokenhead, token); struct tokenlist { @@ -86,7 +80,7 @@ struct vsb *sb; int err; int nbackend_host; - int nbackend; + int ndirector; VTAILQ_HEAD(, proc) procs; struct proc *curproc; struct proc *mprocs[N_METHODS]; @@ -205,6 +199,8 @@ void vcc__Expect(struct tokenlist *tl, unsigned tok, int line); int vcc_Teq(const struct token *t1, const struct token *t2); int vcc_IdIs(const struct token *t, const char *p); +int vcc_isCid(struct token *t); +void vcc_ExpectCid(struct tokenlist *tl); void vcc_Lexer(struct tokenlist *tl, struct source *sp); void vcc_NextToken(struct tokenlist *tl); void vcc__ErrInternal(struct tokenlist *tl, const char *func, unsigned line); Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-07 20:26:58 UTC (rev 2888) +++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-07 21:01:25 UTC (rev 2889) @@ -58,7 +58,7 @@ unsigned u; Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.director[%d])\n", - PF(t_dir), tl->nbackend); + PF(t_dir), tl->ndirector); vcc_AddDef(tl, t_dir, R_BACKEND); fs = vcc_FldSpec(tl, "!backend", "!weight", NULL); Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token.c 2008-07-07 20:26:58 UTC (rev 2888) +++ trunk/varnish-cache/lib/libvcl/vcc_token.c 2008-07-07 21:01:25 UTC (rev 2889) @@ -188,6 +188,38 @@ } /*-------------------------------------------------------------------- + * Check that we have a C-identifier + */ + +int +vcc_isCid(struct token *t) +{ + const char *q; + + assert(t->tok == ID); + for (q = t->b; q < t->e; q++) { + if (!isalnum(*q) && *q != '_') + return (0); + } + return (1); +} + +void +vcc_ExpectCid(struct tokenlist *tl) +{ + + ExpectErr(tl, ID); + ERRCHK(tl); + if (vcc_isCid(tl->t)) + return; + vsb_printf(tl->sb, "Identifier "); + vcc_ErrToken(tl, tl->t); + vsb_printf(tl->sb, + " contains illegal characters, use [0-9a-zA-Z_] only.\n"); + vcc_ErrWhere(tl, tl->t); +} + +/*-------------------------------------------------------------------- * Decode %xx in a string */ Modified: trunk/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_xref.c 2008-07-07 20:26:58 UTC (rev 2888) +++ trunk/varnish-cache/lib/libvcl/vcc_xref.c 2008-07-07 21:01:25 UTC (rev 2889) @@ -143,7 +143,7 @@ r->name = t; /* The first backend is the default and thus has an implicit ref */ - if (type == R_BACKEND && tl->nbackend == 0) + if (type == R_BACKEND && tl->ndirector == 0) r->refcnt++; } From phk at projects.linpro.no Mon Jul 7 21:06:55 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 23:06:55 +0200 (CEST) Subject: r2890 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl Message-ID: <20080707210655.8319C1EC202@projects.linpro.no> Author: phk Date: 2008-07-07 23:06:55 +0200 (Mon, 07 Jul 2008) New Revision: 2890 Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc trunk/varnish-cache/lib/libvcl/vcc_backend.c Log: Testcase for old backend syntax. Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 21:01:25 UTC (rev 2889) +++ trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 21:06:55 UTC (rev 2890) @@ -70,7 +70,6 @@ backend b-1 { .host = "127.0.0.2"; } } -# Assign backend by non-C-compat name # Check backend reference by non-C-compat name varnish v1 -badvcl { backend b1 { .host = "127.0.0.2"; } @@ -78,3 +77,11 @@ set req.backend = b-1; } } + +# Old backend syntax + +varnish v1 -badvcl { + backend b1 { + set host = "localhost"; + } +} Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 21:01:25 UTC (rev 2889) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 21:06:55 UTC (rev 2890) @@ -259,7 +259,7 @@ "Remove \"set\" and \"backend\" in front" " of backend fields.\n" ); vcc_ErrToken(tl, tl->t); - vsb_printf(tl->sb, " at\n"); + vsb_printf(tl->sb, " at "); vcc_ErrWhere(tl, tl->t); return; } From phk at projects.linpro.no Mon Jul 7 21:09:05 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 23:09:05 +0200 (CEST) Subject: r2891 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080707210905.5C1781EC202@projects.linpro.no> Author: phk Date: 2008-07-07 23:09:05 +0200 (Mon, 07 Jul 2008) New Revision: 2891 Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc Log: testcase for unknown backend field Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 21:06:55 UTC (rev 2890) +++ trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 21:09:05 UTC (rev 2891) @@ -49,6 +49,14 @@ } } +# unknown field +varnish v1 -badvcl { + backend b1 { + .host = "localhost"; + .foobar = 123; + } +} + # Check backend reference by name varnish v1 -badvcl { backend b1 { .host = "127.0.0.2"; } @@ -79,7 +87,6 @@ } # Old backend syntax - varnish v1 -badvcl { backend b1 { set host = "localhost"; From phk at projects.linpro.no Mon Jul 7 21:22:06 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 23:22:06 +0200 (CEST) Subject: r2892 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080707212206.6751E1EC0EA@projects.linpro.no> Author: phk Date: 2008-07-07 23:22:06 +0200 (Mon, 07 Jul 2008) New Revision: 2892 Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Fix an encoding bug that affects VCLs shorter than 1 char. Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-07 21:09:05 UTC (rev 2891) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-07 21:22:06 UTC (rev 2892) @@ -322,22 +322,7 @@ v->vcl_nbr++; vsb_printf(vsb, "vcl.inline vcl%d \"", v->vcl_nbr); - for (vcl++; vcl[1] != '\0'; vcl++) { - switch (*vcl) { - case '\\': - case '"': - vsb_printf(vsb, "\\%c", *vcl); break; - case '\n': - vsb_printf(vsb, "\\n"); break; - case '\t': - vsb_printf(vsb, "\\t"); break; - default: - if (isgraph(*vcl) || *vcl == ' ') - vsb_putc(vsb, *vcl); - else - vsb_printf(vsb, "\\x%02x", *vcl); - } - } + varnish_cli_encode(vsb, vcl); vsb_printf(vsb, "\"", *vcl); vsb_finish(vsb); AZ(vsb_overflowed(vsb)); From phk at projects.linpro.no Mon Jul 7 21:22:20 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 23:22:20 +0200 (CEST) Subject: r2893 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080707212220.550761EC203@projects.linpro.no> Author: phk Date: 2008-07-07 23:22:20 +0200 (Mon, 07 Jul 2008) New Revision: 2893 Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c Log: Nitpicking Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_log.c 2008-07-07 21:22:06 UTC (rev 2892) +++ trunk/varnish-cache/bin/varnishtest/vtc_log.c 2008-07-07 21:22:20 UTC (rev 2893) @@ -114,7 +114,7 @@ vsb_printf(vl->vsb, "%s %-4s %s(null)\n", lead[lvl], vl->id, pfx); else - for(; *str; str++) { + for(; *str != '\0'; str++) { if (nl) { vsb_printf(vl->vsb, "%s %-4s %s| ", lead[lvl], vl->id, pfx); From phk at projects.linpro.no Mon Jul 7 21:49:22 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 7 Jul 2008 23:49:22 +0200 (CEST) Subject: r2894 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl Message-ID: <20080707214922.367DB1EC0EA@projects.linpro.no> Author: phk Date: 2008-07-07 23:49:21 +0200 (Mon, 07 Jul 2008) New Revision: 2894 Added: trunk/varnish-cache/bin/varnishtest/tests/v00003.vtc Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_dir_random.c Log: More polishing of backend parsing/syntax error messages Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 21:22:20 UTC (rev 2893) +++ trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 21:49:21 UTC (rev 2894) @@ -92,3 +92,17 @@ set host = "localhost"; } } + +# Too many .connect_timeout +varnish v1 -badvcl { + backend b1 { + .host = k"foo"; + .connect_timeout = 1 q; + } +} + +# Two clashing backends +varnish v1 -badvcl { + backend b1 { .host = "127.0.0.1"; } + backend b1 { .host = "127.0.0.1"; } +} Added: trunk/varnish-cache/bin/varnishtest/tests/v00003.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00003.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00003.vtc 2008-07-07 21:49:21 UTC (rev 2894) @@ -0,0 +1,31 @@ +# $Id$ + +test "VCL: test syntax/semantic checks on director decls." + +# syntax in inline backend +varnish v1 -badvcl { + director r1 random { + { .backend = { .foo = 2; }; .weight = 1;} + } +} + +# reference to unknown backend host +varnish v1 -badvcl { + director r1 random { + { .backend = b2; .weight = 1; } + } +} + +# missing backend +varnish v1 -badvcl { + director r1 random { + { .weight = 1; } + } +} + +# invalid weight +varnish v1 -badvcl { + director r1 random { + { .backend = {.host = "127.0.0.1";} .weight = k; } + } +} Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 21:22:20 UTC (rev 2893) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 21:49:21 UTC (rev 2894) @@ -200,19 +200,17 @@ return; } -int +void vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs) { - int ok = 1; for (; fs->name != NULL; fs++) { if (*fs->name == '!' && fs->found == NULL) { vsb_printf(tl->sb, "Mandatory field '%s' missing.\n", fs->name + 1); - ok = 0; + tl->err = 1; } } - return (ok); } /*-------------------------------------------------------------------- @@ -267,6 +265,7 @@ while (tl->t->tok != '}') { vcc_IsField(tl, &t_field, fs); + ERRCHK(tl); if (tl->err) break; if (vcc_IdIs(t_field, "host")) { @@ -294,13 +293,10 @@ ExpectErr(tl, ';'); vcc_NextToken(tl); } - if (tl->err || !vcc_FieldsOk(tl, fs)) { - vsb_printf(tl->sb, - "\nIn backend host specfication starting at:\n"); - vcc_ErrWhere(tl, t_first); - return; - } + vcc_FieldsOk(tl, fs); + ERRCHK(tl); + /* Check that the hostname makes sense */ assert(t_host != NULL); ep = CheckHostPort(t_host->dec, "80"); @@ -354,6 +350,7 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial) { struct host *h; + struct token *t; if (tl->t->tok == ID) { VTAILQ_FOREACH(h, &tl->hosts, list) { @@ -373,11 +370,18 @@ vcc_NextToken(tl); *nbh = h->hnum; } else if (tl->t->tok == '{') { + t = tl->t; vcc_ParseHostDef(tl, nbh, name, qual, serial); + if (tl->err) { + vsb_printf(tl->sb, + "\nIn backend host specfication starting at:\n"); + vcc_ErrWhere(tl, t); + } + return; } else { vsb_printf(tl->sb, - "Expected a backend specification here, either by name " - "or by {...}\n"); + "Expected a backend host specification here, " + "either by name or by {...}\n"); vcc_ErrToken(tl, tl->t); vsb_printf(tl->sb, " at\n"); vcc_ErrWhere(tl, tl->t); @@ -404,7 +408,12 @@ vcc_NextToken(tl); vcc_ParseHostDef(tl, &h->hnum, h->name, "backend", 0); - ERRCHK(tl); + if (tl->err) { + vsb_printf(tl->sb, + "\nIn backend specfication starting at:\n"); + vcc_ErrWhere(tl, h->name); + return; + } VTAILQ_INSERT_TAIL(&tl->hosts, h, list); Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-07 21:22:20 UTC (rev 2893) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-07 21:49:21 UTC (rev 2894) @@ -158,7 +158,7 @@ struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...); void vcc_ResetFldSpec(struct fld_spec *f); void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs); -int vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs); +void vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs); void vcc_ParseBackendHost(struct tokenlist *tl, int *nbr, const struct token *name, const char *qual, int serial); /* vcc_compile.c */ Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-07 21:22:20 UTC (rev 2893) +++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-07 21:49:21 UTC (rev 2894) @@ -94,7 +94,8 @@ u = vcc_UintVal(tl); if (u == 0) { vsb_printf(tl->sb, - "The .weight must be higher than zero."); + "The .weight must be higher " + "than zero."); vcc_ErrToken(tl, tl->t); vsb_printf(tl->sb, " at\n"); vcc_ErrWhere(tl, tl->t); @@ -108,7 +109,8 @@ ErrInternal(tl); } } - if (!vcc_FieldsOk(tl, fs)) { + vcc_FieldsOk(tl, fs); + if (tl->err) { vsb_printf(tl->sb, "\nIn member host specfication starting at:\n"); vcc_ErrWhere(tl, t_be); From phk at projects.linpro.no Mon Jul 7 22:11:39 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 00:11:39 +0200 (CEST) Subject: r2895 - trunk/varnish-cache/bin/varnishd Message-ID: <20080707221139.E6ED11EC202@projects.linpro.no> Author: phk Date: 2008-07-08 00:11:39 +0200 (Tue, 08 Jul 2008) New Revision: 2895 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c Log: Dismantle directors and backends properly. Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-07-07 21:49:21 UTC (rev 2894) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-07-07 22:11:39 UTC (rev 2895) @@ -664,19 +664,45 @@ VRT_fini_dir(struct cli *cli, struct director *b) { + (void)cli; ASSERT_CLI(); -#if 0 - VBE_DropRef(b); -#else - (void)b; - (void)cli; -#endif + CHECK_OBJ_NOTNULL(b, DIRECTOR_MAGIC); + b->fini(b); } + /*--------------------------------------------------------------------*/ +static void +cli_debug_backend(struct cli *cli, const char * const *av, void *priv) +{ + struct backend *b; + + (void)av; + (void)priv; + ASSERT_CLI(); + VTAILQ_FOREACH(b, &backends, list) { + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + cli_out(cli, "%p %s/%s/%s %d\n", + b, + b->vrt->vcl_name, + b->vrt->hostname, + b->vrt->portname, + b->refcount); + } +} + +static struct cli_proto debug_cmds[] = { + { "debug.backend", "debug.backend", + "\tExamine Backend internals\n", 0, 0, cli_debug_backend }, + { NULL } +}; + +/*--------------------------------------------------------------------*/ + void VBE_Init(void) { MTX_INIT(&VBE_mtx); + CLI_AddFuncs(DEBUG_CLI, debug_cmds); } From phk at projects.linpro.no Mon Jul 7 22:15:13 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 00:15:13 +0200 (CEST) Subject: r2896 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080707221513.01AA41EC203@projects.linpro.no> Author: phk Date: 2008-07-08 00:15:12 +0200 (Tue, 08 Jul 2008) New Revision: 2896 Added: trunk/varnish-cache/bin/varnishtest/tests/v00004.vtc Log: Add testcase for creation and destruction of backends Added: trunk/varnish-cache/bin/varnishtest/tests/v00004.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00004.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00004.vtc 2008-07-07 22:15:12 UTC (rev 2896) @@ -0,0 +1,67 @@ +# $Id$ + +test "VCL: test creation/destruction of backends" + +varnish v1 -vcl { + backend b1 { + .host = "127.0.0.1"; + } +} -start + +varnish v1 -cli vcl.list +varnish v1 -cli debug.backend + +varnish v1 -vcl { + backend b1 { + .host = "127.0.0.1"; + } +} + +varnish v1 -cli vcl.list +varnish v1 -cli debug.backend + +varnish v1 -vcl { + backend b2 { + .host = "127.0.0.1"; + } +} + +varnish v1 -cli vcl.list +varnish v1 -cli debug.backend + +varnish v1 -cli "vcl.discard vcl1" + +varnish v1 -cli vcl.list +varnish v1 -cli debug.backend + +varnish v1 -cli "vcl.discard vcl2" + +varnish v1 -cli vcl.list +varnish v1 -cli debug.backend + +varnish v1 -vcl { + backend b2 { + .host = "127.0.0.1"; + } + director r1 random { + { .backend = { .host = "127.0.0.1"; } .weight = 1; } + { .backend = b2 ; .weight = 1; } + } + sub vcl_recv { + set req.backend = r1; + } +} + +varnish v1 -cli vcl.list +varnish v1 -cli debug.backend + +varnish v1 -cli "vcl.use vcl3" + +varnish v1 -cli vcl.list +varnish v1 -cli debug.backend + +varnish v1 -cli "vcl.discard vcl4" + +varnish v1 -cli vcl.list +varnish v1 -cli debug.backend + From phk at projects.linpro.no Mon Jul 7 22:19:06 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 00:19:06 +0200 (CEST) Subject: r2897 - trunk/varnish-cache/lib/libvcl Message-ID: <20080707221906.330A01EC202@projects.linpro.no> Author: phk Date: 2008-07-08 00:19:05 +0200 (Tue, 08 Jul 2008) New Revision: 2897 Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c Log: Don't create an unnecessary fencepost member. Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-07 22:15:12 UTC (rev 2896) +++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-07 22:19:05 UTC (rev 2897) @@ -119,7 +119,6 @@ Fc(tl, 0, " },\n"); vcc_NextToken(tl); } - Fc(tl, 0, "\t{ .host = 0 }\n"); Fc(tl, 0, "};\n"); Fc(tl, 0, "\nstatic const struct vrt_dir_random vdr_%.*s = {\n", From phk at projects.linpro.no Tue Jul 8 06:30:20 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 08:30:20 +0200 (CEST) Subject: r2898 - trunk/varnish-cache/lib/libvcl Message-ID: <20080708063020.A9D1C1EC0EA@projects.linpro.no> Author: phk Date: 2008-07-08 08:30:16 +0200 (Tue, 08 Jul 2008) New Revision: 2898 Modified: trunk/varnish-cache/lib/libvcl/flint.lnt trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_token.c Log: Flexelint nits Modified: trunk/varnish-cache/lib/libvcl/flint.lnt =================================================================== --- trunk/varnish-cache/lib/libvcl/flint.lnt 2008-07-07 22:19:05 UTC (rev 2897) +++ trunk/varnish-cache/lib/libvcl/flint.lnt 2008-07-08 06:30:16 UTC (rev 2898) @@ -12,6 +12,10 @@ -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) -sem(vcc_new_source, custodial(1)) +-emacro((???),va_arg) // the va_arg() macro can yield 415, 416, 661, 662 + // 796 and 797 (out-of-bounds errors). + + // -ffc // No automatic custody -esym(534, vsb_printf) // Ignoring return value of function Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-07 22:19:05 UTC (rev 2897) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-08 06:30:16 UTC (rev 2898) @@ -199,7 +199,7 @@ void vcc__Expect(struct tokenlist *tl, unsigned tok, int line); int vcc_Teq(const struct token *t1, const struct token *t2); int vcc_IdIs(const struct token *t, const char *p); -int vcc_isCid(struct token *t); +int vcc_isCid(const struct token *t); void vcc_ExpectCid(struct tokenlist *tl); void vcc_Lexer(struct tokenlist *tl, struct source *sp); void vcc_NextToken(struct tokenlist *tl); Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token.c 2008-07-07 22:19:05 UTC (rev 2897) +++ trunk/varnish-cache/lib/libvcl/vcc_token.c 2008-07-08 06:30:16 UTC (rev 2898) @@ -192,7 +192,7 @@ */ int -vcc_isCid(struct token *t) +vcc_isCid(const struct token *t) { const char *q; From phk at projects.linpro.no Tue Jul 8 07:10:44 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 09:10:44 +0200 (CEST) Subject: r2899 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080708071044.1F44E1ED249@projects.linpro.no> Author: phk Date: 2008-07-08 09:10:41 +0200 (Tue, 08 Jul 2008) New Revision: 2899 Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc Log: Add test for unknown director policy Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-08 06:30:16 UTC (rev 2898) +++ trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-08 07:10:41 UTC (rev 2899) @@ -106,3 +106,8 @@ backend b1 { .host = "127.0.0.1"; } backend b1 { .host = "127.0.0.1"; } } + +# Unknown director policy +varnish v1 -badvcl { + director r1 anarchy { .host = "127.0.0.1"; } +} From phk at projects.linpro.no Tue Jul 8 07:30:46 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 09:30:46 +0200 (CEST) Subject: r2900 - trunk/varnish-cache/lib/libvcl Message-ID: <20080708073046.2ACE21ED249@projects.linpro.no> Author: phk Date: 2008-07-08 09:30:42 +0200 (Tue, 08 Jul 2008) New Revision: 2900 Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_dir_random.c trunk/varnish-cache/lib/libvcl/vcc_parse.c Log: Unify parsing of backends and directors. Use table to dispatch director parsing. Get trailing '}' into backend host ident string. Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-08 07:10:41 UTC (rev 2899) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-08 07:30:42 UTC (rev 2900) @@ -72,7 +72,6 @@ struct token *name; }; - static const char * CheckHostPort(const char *host, const char *port) { @@ -100,21 +99,25 @@ */ static void -vcc_EmitBeIdent(struct vsb *v, const struct token *name, const char *qual, int serial, const struct token *first, const struct token *last) +vcc_EmitBeIdent(struct vsb *v, const struct token *name, const struct token *qual, int serial, const struct token *first, const struct token *last) { + AN(name); + AN(qual); + assert(first != last); vsb_printf(v, "\t.ident ="); - AN(qual); - vsb_printf(v, "\n\t \"%s %.*s\"", qual, PF(name)); - if (serial != 0) - vsb_printf(v, "\n\t \"[%d]\"", serial); - while (first != last) { + vsb_printf(v, "\n\t \"%.*s %.*s [%d] \"", + PF(qual), PF(name), serial); + while (1) { if (first->dec != NULL) vsb_printf(v, "\n\t \"\\\"\" %.*s \"\\\" \"", PF(first)); else vsb_printf(v, "\n\t \"%.*s \"", PF(first)); + if (first == last) + break; first = VTAILQ_NEXT(first, list); + AN(first); } vsb_printf(v, ",\n"); } @@ -232,7 +235,7 @@ */ static void -vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial) +vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const struct token *qual, int serial) { struct token *t_field; struct token *t_first; @@ -347,7 +350,7 @@ */ void -vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial) +vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const struct token *qual, int serial) { struct host *h; struct token *t; @@ -390,39 +393,22 @@ } /*-------------------------------------------------------------------- - * Parse a plain backend + * Parse a plain backend aka a simple director */ -void -vcc_ParseBackend(struct tokenlist *tl) +static void +vcc_ParseSimpleDirector(struct tokenlist *tl, const struct token *t_first, struct token *t_dir) { struct host *h; h = TlAlloc(tl, sizeof *h); + h->name = t_dir; - vcc_NextToken(tl); - - vcc_ExpectCid(tl); /* ID: name */ + vcc_ParseHostDef(tl, &h->hnum, h->name, t_first, 0); ERRCHK(tl); - h->name = tl->t; - vcc_NextToken(tl); - vcc_ParseHostDef(tl, &h->hnum, h->name, "backend", 0); - if (tl->err) { - vsb_printf(tl->sb, - "\nIn backend specfication starting at:\n"); - vcc_ErrWhere(tl, h->name); - return; - } - VTAILQ_INSERT_TAIL(&tl->hosts, h, list); - /* In the compiled vcl we use these macros to refer to backends */ - Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.director[%d])\n", - PF(h->name), tl->ndirector); - - vcc_AddDef(tl, h->name, R_BACKEND); - Fi(tl, 0, "\tVRT_init_dir_simple(cli, &VGC_backend_%.*s , &sbe_%.*s);\n", PF(h->name), PF(h->name)); @@ -434,42 +420,68 @@ Fc(tl, 0, "\t.host = &bh_%d,\n", h->hnum); Fc(tl, 0, "};\n"); - tl->ndirector++; } /*-------------------------------------------------------------------- - * Parse directors + * Parse directors and backends */ +static const struct dirlist { + const char *name; + parsedirector_f *func; +} dirlist[] = { + { "random", vcc_ParseRandomDirector }, + { NULL, NULL } +}; + void vcc_ParseDirector(struct tokenlist *tl) { - struct token *t_dir, *t_first; + struct token *t_dir, *t_first, *t_policy; + struct dirlist const *dl; t_first = tl->t; - vcc_NextToken(tl); /* ID: director */ + vcc_NextToken(tl); /* ID: director | backend */ vcc_ExpectCid(tl); /* ID: name */ ERRCHK(tl); t_dir = tl->t; vcc_NextToken(tl); - ExpectErr(tl, ID); /* ID: policy */ - if (vcc_IdIs(tl->t, "random")) - vcc_ParseRandomDirector(tl, t_dir); - else { - vsb_printf(tl->sb, "Unknown director policy: "); - vcc_ErrToken(tl, tl->t); - vsb_printf(tl->sb, " at\n"); - vcc_ErrWhere(tl, tl->t); - return; + Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.director[%d])\n", + PF(t_dir), tl->ndirector); + vcc_AddDef(tl, t_dir, R_BACKEND); + tl->ndirector++; + + if (vcc_IdIs(t_first, "backend")) { + vcc_ParseSimpleDirector(tl, t_first, t_dir); + } else { + ExpectErr(tl, ID); /* ID: policy */ + t_policy = tl->t; + vcc_NextToken(tl); + + for (dl = dirlist; dl->name != NULL; dl++) + if (vcc_IdIs(t_policy, dl->name)) + break; + if (dl->name == NULL) { + vsb_printf(tl->sb, "Unknown director policy: "); + vcc_ErrToken(tl, t_policy); + vsb_printf(tl->sb, " at\n"); + vcc_ErrWhere(tl, t_policy); + return; + } + ExpectErr(tl, '{'); + vcc_NextToken(tl); + dl->func(tl, t_policy, t_dir); + if (!tl->err) { + ExpectErr(tl, '}'); + vcc_NextToken(tl); + } } if (tl->err) { vsb_printf(tl->sb, - "\nIn director specfication starting at:\n", - PF(t_first)); + "\nIn %.*s specfication starting at:\n", PF(t_first)); vcc_ErrWhere(tl, t_first); return; } - tl->ndirector++; } Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-08 07:10:41 UTC (rev 2899) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-08 07:30:42 UTC (rev 2900) @@ -153,13 +153,14 @@ /* vcc_backend.c */ struct fld_spec; -void vcc_ParseBackend(struct tokenlist *tl); +typedef void parsedirector_f(struct tokenlist *tl, const struct token *t_policy, const struct token *t_dir); + void vcc_ParseDirector(struct tokenlist *tl); +void vcc_ParseBackendHost(struct tokenlist *tl, int *nbr, const struct token *name, const struct token *qual, int serial); struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...); void vcc_ResetFldSpec(struct fld_spec *f); void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs); void vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs); -void vcc_ParseBackendHost(struct tokenlist *tl, int *nbr, const struct token *name, const char *qual, int serial); /* vcc_compile.c */ extern struct method method_tab[]; @@ -174,7 +175,7 @@ void *TlAlloc(struct tokenlist *tl, unsigned len); /* vcc_dir_random.c */ -void vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir); +parsedirector_f vcc_ParseRandomDirector; /* vcc_obj.c */ extern struct var vcc_vars[]; Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-08 07:10:41 UTC (rev 2899) +++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-08 07:30:42 UTC (rev 2900) @@ -50,24 +50,15 @@ */ void -vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir) +vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, const struct token *t_dir) { struct token *t_field, *t_be; int nbh, nelem; struct fld_spec *fs; unsigned u; - Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.director[%d])\n", - PF(t_dir), tl->ndirector); - vcc_AddDef(tl, t_dir, R_BACKEND); - fs = vcc_FldSpec(tl, "!backend", "!weight", NULL); - vcc_NextToken(tl); /* ID: policy (= random) */ - - ExpectErr(tl, '{'); - vcc_NextToken(tl); - Fc(tl, 0, "\nstatic const struct vrt_dir_random_entry vdre_%.*s[] = {\n", PF(t_dir)); @@ -86,7 +77,7 @@ ERRCHK(tl); if (vcc_IdIs(t_field, "backend")) { vcc_ParseBackendHost(tl, &nbh, - t_dir, "random", nelem); + t_dir, t_policy, nelem); Fc(tl, 0, " .host = &bh_%d,", nbh); ERRCHK(tl); } else if (vcc_IdIs(t_field, "weight")) { @@ -127,7 +118,6 @@ Fc(tl, 0, "\t.nmember = %d,\n", nelem); Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(t_dir)); Fc(tl, 0, "};\n"); - vcc_NextToken(tl); Fi(tl, 0, "\tVRT_init_dir_random(cli, &VGC_backend_%.*s , &vdr_%.*s);\n", PF(t_dir), PF(t_dir)); Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2008-07-08 07:10:41 UTC (rev 2899) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2008-07-08 07:30:42 UTC (rev 2900) @@ -560,7 +560,7 @@ } toplev[] = { { "acl", vcc_Acl }, { "sub", Function }, - { "backend", vcc_ParseBackend }, + { "backend", vcc_ParseDirector }, { "director", vcc_ParseDirector }, { NULL, NULL } }; From phk at projects.linpro.no Tue Jul 8 08:53:38 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 10:53:38 +0200 (CEST) Subject: r2901 - trunk/varnish-cache/lib/libvcl Message-ID: <20080708085338.BC7591EC202@projects.linpro.no> Author: phk Date: 2008-07-08 10:53:37 +0200 (Tue, 08 Jul 2008) New Revision: 2901 Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c Log: assert !vsb_overflowed() Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2008-07-08 07:30:42 UTC (rev 2900) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2008-07-08 08:53:37 UTC (rev 2901) @@ -299,7 +299,7 @@ Fc(tl, 0, "\nstatic void\nVGC_Init(struct cli *cli)\n{\n\n"); vsb_finish(tl->fi); - /* XXX: check vsb_overflowed ? */ + AZ(vsb_overflowed(tl->fi)); vsb_cat(tl->fc, vsb_data(tl->fi)); Fc(tl, 0, "}\n"); } @@ -310,7 +310,7 @@ Fc(tl, 0, "\nstatic void\nVGC_Fini(struct cli *cli)\n{\n\n"); vsb_finish(tl->ff); - /* XXX: check vsb_overflowed ? */ + AZ(vsb_overflowed(tl->ff)); vsb_cat(tl->fc, vsb_data(tl->ff)); Fc(tl, 0, "}\n"); } @@ -625,7 +625,7 @@ Fc(tl, 1, "VGC_function_%s (struct sess *sp)\n", method_tab[i].name); vsb_finish(tl->fm[i]); - /* XXX: check vsb_overflowed ? */ + AZ(vsb_overflowed(tl->fm[i])); Fc(tl, 1, "{\n"); Fc(tl, 1, "%s", vsb_data(tl->fm[i])); Fc(tl, 1, "}\n"); @@ -641,9 +641,10 @@ /* Combine it all in the fh vsb */ vsb_finish(tl->fc); - /* XXX: check vsb_overflowed ? */ + AZ(vsb_overflowed(tl->fc)); vsb_cat(tl->fh, vsb_data(tl->fc)); vsb_finish(tl->fh); + AZ(vsb_overflowed(tl->fh)); of = strdup(vsb_data(tl->fh)); AN(of); From phk at projects.linpro.no Tue Jul 8 09:15:33 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 11:15:33 +0200 (CEST) Subject: r2902 - in trunk/varnish-cache: bin/varnishtest/tests include lib/libvcl Message-ID: <20080708091533.4DB7C1EC0EA@projects.linpro.no> Author: phk Date: 2008-07-08 11:15:32 +0200 (Tue, 08 Jul 2008) New Revision: 2902 Added: trunk/varnish-cache/bin/varnishtest/tests/v00005.vtc Modified: trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Add VCC support for backend probe specifications. It is possible to specify just the URL to be probed, or to specify the entire HTTP request: backend b0 { .host = "127.0.0.1"; .probe = { .url = "/test.jpg"; .timeout = 224 ms; } } backend b1 { .host = "127.0.0.1"; .probe = { # NB: \r\n automatically inserted after each string! .request = "GET / HTTP/1.1" "Host: www.foo.bar" "Connection: close"; .timeout = 0.3 s; } } If the full request has not been completed within the timeout, the backend will be set to down. Added: trunk/varnish-cache/bin/varnishtest/tests/v00005.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00005.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00005.vtc 2008-07-08 09:15:32 UTC (rev 2902) @@ -0,0 +1,51 @@ +# $Id$ + +test "VCL: test backend probe syntax" + +# Check url definition +varnish v1 -vcl { + backend b1 { + .host = "localhost"; + .probe = { + .url = "/"; + } + } +} + +# Check request definition +varnish v1 -vcl { + backend b1 { + .host = "localhost"; + .probe = { + .request = + "GET / HTTP/1.1" + "Host: foo.bar" ; + } + } +} + +# Check redefinition +varnish v1 -badvcl { + backend b1 { + .host = "localhost"; + .probe = { + .url = "/"; + .request = + "GET / HTTP/1.1" + "Host: foo.bar" ; + } + } +} + +# Check redefinition the other way +varnish v1 -badvcl { + backend b1 { + .host = "localhost"; + .probe = { + .request = + "GET / HTTP/1.1" + "Host: foo.bar" ; + .url = "/"; + } + } +} Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2008-07-08 08:53:37 UTC (rev 2901) +++ trunk/varnish-cache/include/vrt.h 2008-07-08 09:15:32 UTC (rev 2902) @@ -42,14 +42,24 @@ struct sockaddr; /* + * A backend probe specification + */ + +struct vrt_backend_probe { + char *request; + double timeout; +}; + +/* * A backend is a host+port somewhere on the network */ struct vrt_backend { - char *portname; - char *hostname; - char *vcl_name; - char *ident; - double connect_timeout; + char *portname; + char *hostname; + char *vcl_name; + char *ident; + double connect_timeout; + struct vrt_backend_probe probe; }; /* Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-08 08:53:37 UTC (rev 2901) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-08 09:15:32 UTC (rev 2902) @@ -217,6 +217,89 @@ } /*-------------------------------------------------------------------- + * Parse a backend probe specification + */ + +static void +vcc_ProbeRedef(struct tokenlist *tl, struct token **t_did, struct token *t_field) +{ + if (*t_did != NULL) { + vsb_printf(tl->sb, + "Probe request redefinition at:\n"); + vcc_ErrWhere(tl, t_field); + vsb_printf(tl->sb, + "Previous definition:\n"); + vcc_ErrWhere(tl, *t_did); + return; + } + *t_did = t_field; +} + +static void +vcc_ParseProbe(struct tokenlist *tl) +{ + struct fld_spec *fs; + struct token *t_field; + struct token *t_did = NULL; + + fs = vcc_FldSpec(tl, "?url", "?request", "?timeout", NULL); + + ExpectErr(tl, '{'); + vcc_NextToken(tl); + + Fh(tl, 0, "\t.probe = {\n"); + while (tl->t->tok != '}') { + + vcc_IsField(tl, &t_field, fs); + ERRCHK(tl); + if (tl->err) + break; + if (vcc_IdIs(t_field, "url")) { + vcc_ProbeRedef(tl, &t_did, t_field); + ERRCHK(tl); + ExpectErr(tl, CSTR); + Fh(tl, 0, "\t\t.request =\n"); + Fh(tl, 0, "\t\t\t\"GET \" "); + EncToken(tl->fh, tl->t); + Fh(tl, 0, " \" /HTTP/1.1\\r\\n\"\n"); + Fh(tl, 0, "\t\t\t\"Connection: close\\r\\n\"\n"); + Fh(tl, 0, "\t\t\t\"\\r\\n\",\n"); + vcc_NextToken(tl); + } else if (vcc_IdIs(t_field, "request")) { + vcc_ProbeRedef(tl, &t_did, t_field); + ERRCHK(tl); + ExpectErr(tl, CSTR); + Fh(tl, 0, "\t\t.request =\n"); + while (tl->t->tok == CSTR) { + Fh(tl, 0, "\t\t\t"); + EncToken(tl->fh, tl->t); + Fh(tl, 0, " \"\\r\\n\"\n"); + vcc_NextToken(tl); + } + Fh(tl, 0, "\t\t\t\"\\r\\n\",\n"); + } else if (vcc_IdIs(t_field, "timeout")) { + Fh(tl, 0, "\t\t.timeout = "); + tl->fb = tl->fh; + vcc_TimeVal(tl); + tl->fb = NULL; + ERRCHK(tl); + Fh(tl, 0, ",\n"); + } else { + vcc_ErrToken(tl, t_field); + vcc_ErrWhere(tl, t_field); + ErrInternal(tl); + return; + } + + ExpectErr(tl, ';'); + vcc_NextToken(tl); + } + Fh(tl, 0, "\t},\n"); + ExpectErr(tl, '}'); + vcc_NextToken(tl); +} + +/*-------------------------------------------------------------------- * Parse and emit a backend host definition * * The syntax is the following: @@ -244,7 +327,8 @@ const char *ep; struct fld_spec *fs; - fs = vcc_FldSpec(tl, "!host", "?port", "?connect_timeout", NULL); + fs = vcc_FldSpec(tl, + "!host", "?port", "?connect_timeout", "?probe", NULL); t_first = tl->t; ExpectErr(tl, '{'); @@ -276,11 +360,15 @@ assert(tl->t->dec != NULL); t_host = tl->t; vcc_NextToken(tl); + ExpectErr(tl, ';'); + vcc_NextToken(tl); } else if (vcc_IdIs(t_field, "port")) { ExpectErr(tl, CSTR); assert(tl->t->dec != NULL); t_port = tl->t; vcc_NextToken(tl); + ExpectErr(tl, ';'); + vcc_NextToken(tl); } else if (vcc_IdIs(t_field, "connect_timeout")) { Fh(tl, 0, "\t.connect_timeout = "); tl->fb = tl->fh; @@ -288,13 +376,16 @@ tl->fb = NULL; ERRCHK(tl); Fh(tl, 0, ",\n"); + ExpectErr(tl, ';'); + vcc_NextToken(tl); + } else if (vcc_IdIs(t_field, "probe")) { + vcc_ParseProbe(tl); + ERRCHK(tl); } else { ErrInternal(tl); return; } - ExpectErr(tl, ';'); - vcc_NextToken(tl); } vcc_FieldsOk(tl, fs); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-08 08:53:37 UTC (rev 2901) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-08 09:15:32 UTC (rev 2902) @@ -380,14 +380,24 @@ vsb_cat(sb, "struct sockaddr;\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/*\n"); + vsb_cat(sb, " * A backend probe specification\n"); + vsb_cat(sb, " */\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, "struct vrt_backend_probe {\n"); + vsb_cat(sb, " char *request;\n"); + vsb_cat(sb, " double timeout;\n"); + vsb_cat(sb, "};\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, "/*\n"); vsb_cat(sb, " * A backend is a host+port somewhere on the network\n"); vsb_cat(sb, " */\n"); vsb_cat(sb, "struct vrt_backend {\n"); - vsb_cat(sb, " char *portname;\n"); - vsb_cat(sb, " char *hostname;\n"); - vsb_cat(sb, " char *vcl_name;\n"); - vsb_cat(sb, " char *ident;\n"); - vsb_cat(sb, " double connect_timeout;\n"); + vsb_cat(sb, " char *portname;\n"); + vsb_cat(sb, " char *hostname;\n"); + vsb_cat(sb, " char *vcl_name;\n"); + vsb_cat(sb, " char *ident;\n"); + vsb_cat(sb, " double connect_timeout;\n"); + vsb_cat(sb, " struct vrt_backend_probe probe;\n"); vsb_cat(sb, "};\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/*\n"); From phk at projects.linpro.no Tue Jul 8 09:17:43 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 11:17:43 +0200 (CEST) Subject: r2903 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20080708091743.336591ED1C3@projects.linpro.no> Author: phk Date: 2008-07-08 11:17:42 +0200 (Tue, 08 Jul 2008) New Revision: 2903 Modified: trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Also make the backend probe rate (how often we probe) configurable in VCL. Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2008-07-08 09:15:32 UTC (rev 2902) +++ trunk/varnish-cache/include/vrt.h 2008-07-08 09:17:42 UTC (rev 2903) @@ -48,6 +48,7 @@ struct vrt_backend_probe { char *request; double timeout; + double rate; }; /* Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-08 09:15:32 UTC (rev 2902) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-08 09:17:42 UTC (rev 2903) @@ -242,7 +242,7 @@ struct token *t_field; struct token *t_did = NULL; - fs = vcc_FldSpec(tl, "?url", "?request", "?timeout", NULL); + fs = vcc_FldSpec(tl, "?url", "?request", "?timeout", "?rate", NULL); ExpectErr(tl, '{'); vcc_NextToken(tl); @@ -284,6 +284,13 @@ tl->fb = NULL; ERRCHK(tl); Fh(tl, 0, ",\n"); + } else if (vcc_IdIs(t_field, "rate")) { + Fh(tl, 0, "\t\t.rate = "); + tl->fb = tl->fh; + vcc_TimeVal(tl); + tl->fb = NULL; + ERRCHK(tl); + Fh(tl, 0, ",\n"); } else { vcc_ErrToken(tl, t_field); vcc_ErrWhere(tl, t_field); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-08 09:15:32 UTC (rev 2902) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-08 09:17:42 UTC (rev 2903) @@ -386,6 +386,7 @@ vsb_cat(sb, "struct vrt_backend_probe {\n"); vsb_cat(sb, " char *request;\n"); vsb_cat(sb, " double timeout;\n"); + vsb_cat(sb, " double rate;\n"); vsb_cat(sb, "};\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/*\n"); From phk at projects.linpro.no Tue Jul 8 09:48:06 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 11:48:06 +0200 (CEST) Subject: r2904 - trunk/varnish-cache/lib/libvcl Message-ID: <20080708094806.CE0791EC0EA@projects.linpro.no> Author: phk Date: 2008-07-08 11:48:05 +0200 (Tue, 08 Jul 2008) New Revision: 2904 Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c Log: Note an idea Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-08 09:17:42 UTC (rev 2903) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-08 09:48:05 UTC (rev 2904) @@ -124,6 +124,12 @@ /*-------------------------------------------------------------------- * Helper functions to complain about duplicate and missing fields + * + * XXX: idea: add groups to check for exclusivity, such that + * XXX: ("!foo", "?bar", "!{", "this", "that", "}", NULL) + * XXX: means exactly one of "this" or "that", and + * XXX: ("!foo", "?bar", "?{", "this", "that", "}", NULL) + * XXX: means at most one of "this" or "that". */ struct fld_spec { From phk at projects.linpro.no Tue Jul 8 10:09:03 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 12:09:03 +0200 (CEST) Subject: r2905 - trunk/varnish-cache/bin/varnishd Message-ID: <20080708100903.9ADEE1ED157@projects.linpro.no> Author: phk Date: 2008-07-08 12:09:03 +0200 (Tue, 08 Jul 2008) New Revision: 2905 Added: trunk/varnish-cache/bin/varnishd/cache_backend.h trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.c Log: Split the backend code into two files, the probe code will make it more complicated than a single file can carry. cache_backend_cfg.c now contains the configuration and selection of backends and directors. cache_backend.c contains the connection and request management against backends. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-08 09:48:05 UTC (rev 2904) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-08 10:09:03 UTC (rev 2905) @@ -12,6 +12,7 @@ cache_acceptor_poll.c \ cache_acceptor_kqueue.c \ cache_backend.c \ + cache_backend_cfg.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 2008-07-08 09:48:05 UTC (rev 2904) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-08 10:09:03 UTC (rev 2905) @@ -413,17 +413,19 @@ /* cache_backend.c */ -void VBE_Init(void); -struct vbe_conn *VBE_GetFd(struct sess *sp); +struct vbe_conn *VBE_GetFd(const struct sess *sp); 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); +void VBE_UpdateHealth(const struct sess *sp, const struct vbe_conn *, int); +void VBE_AddHostHeader(const struct sess *sp); + +/* cache_backend_cfg.c */ +void VBE_Init(void); void VBE_DropRef(struct backend *); +void VBE_SelectBackend(struct sess *sp); struct backend *VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb); -void VBE_UpdateHealth(const struct sess *sp, const struct vbe_conn *, int); -void VBE_AddHostHeader(struct sess *sp); -void VBE_SelectBackend(struct sess *sp); /* cache_ban.c */ int BAN_Add(struct cli *cli, const char *regexp, int hash); Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-07-08 09:48:05 UTC (rev 2904) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-07-08 10:09:03 UTC (rev 2905) @@ -28,44 +28,8 @@ * * $Id$ * - * This is the central switch-board for backend connections and it is - * slightly complicated by a number of optimizations. + * Handle backend connections and backend request structures. * - * The data structures: - * - * A vrt_backend is a definition of a backend in a VCL program. - * - * A backend is a TCP destination, possibly multi-homed and it has a - * number of associated properties and statistics. - * - * A vbe_conn is an open TCP connection to a backend. - * - * A bereq is a memory carrier for handling a HTTP transaction with - * a backend over a vbe_conn. - * - * A director is a piece of code that selects which backend to use, - * by whatever method or metric it chooses. - * - * The relationships: - * - * Backends and directors get instantiated when VCL's are loaded, - * and this always happen in the CLI thread. - * - * When a VCL tries to instantiate a backend, any existing backend - * with the same identity (== definition in VCL) will be used instead - * so that vbe_conn's can be reused across VCL changes. - * - * Directors disapper with the VCL that created them. - * - * Backends disappear when their reference count drop to zero. - * - * Backends have their host/port name looked up to addrinfo structures - * when they are instantiated, and we just cache that result and cycle - * through the entries (for multihomed backends) on failure only. - * XXX: add cli command to redo lookup. - * - * bereq is sort of a step-child here, we just manage the pool of them. - * */ #include "config.h" @@ -82,30 +46,8 @@ #include "shmlog.h" #include "cache.h" #include "vrt.h" -#include "cli_priv.h" +#include "cache_backend.h" -/* Backend indstance */ -struct backend { - unsigned magic; -#define BACKEND_MAGIC 0x64c4c7c6 - - struct vrt_backend vrt[1]; - uint32_t hash; - - VTAILQ_ENTRY(backend) list; - int refcount; - pthread_mutex_t mtx; - - struct addrinfo *ai; - struct addrinfo *last_ai; - - VTAILQ_HEAD(, vbe_conn) connlist; - - int health; -}; - -static MTX VBE_mtx; - /* * List of cached vbe_conns, used if enabled in params/heritage */ @@ -116,17 +58,11 @@ */ static VTAILQ_HEAD(,bereq) bereq_head = VTAILQ_HEAD_INITIALIZER(bereq_head); -/* - * The list of backends is not locked, it is only ever accessed from - * the CLI thread, so there is no need. - */ -static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends); - /*-------------------------------------------------------------------- * Create default Host: header for backend request */ void -VBE_AddHostHeader(struct sess *sp) +VBE_AddHostHeader(const struct sess *sp) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -299,7 +235,7 @@ return (vc); } -static void +void VBE_ReleaseConn(struct vbe_conn *vc) { @@ -319,52 +255,6 @@ } /*-------------------------------------------------------------------- - * Drop a reference to a backend. - * The last reference must come from the watcher in the CLI thread, - * as only that thread is allowed to clean up the backend list. - */ - -static void -VBE_DropRefLocked(struct backend *b) -{ - int i; - struct vbe_conn *vbe, *vbe2; - - CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - assert(b->refcount > 0); - - i = --b->refcount; - UNLOCK(&b->mtx); - if (i > 0) - return; - - ASSERT_CLI(); - VTAILQ_REMOVE(&backends, b, list); - VTAILQ_FOREACH_SAFE(vbe, &b->connlist, list, vbe2) { - VTAILQ_REMOVE(&b->connlist, vbe, list); - if (vbe->fd >= 0) - AZ(close(vbe->fd)); - VBE_ReleaseConn(vbe); - } - free(TRUST_ME(b->vrt->ident)); - free(TRUST_ME(b->vrt->hostname)); - free(TRUST_ME(b->vrt->portname)); - b->magic = 0; - free(b); - VSL_stats->n_backend--; -} - -void -VBE_DropRef(struct backend *b) -{ - - CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - - LOCK(&b->mtx); - VBE_DropRefLocked(b); -} - -/*-------------------------------------------------------------------- * Try to get a socket connected to one of the addresses on the list. * We start from the cached "last good" address and try all items on * the list exactly once. @@ -430,22 +320,8 @@ /*--------------------------------------------------------------------*/ -void -VBE_SelectBackend(struct sess *sp) -{ - struct backend *bp; - - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC); - bp = sp->director->choose(sp); - CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); - sp->backend = bp; -} - -/*--------------------------------------------------------------------*/ - struct vbe_conn * -VBE_GetFd(struct sess *sp) +VBE_GetFd(const struct sess *sp) { struct backend *bp; struct vbe_conn *vc; @@ -560,149 +436,3 @@ CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); #endif } - -/*-------------------------------------------------------------------- - * DNS lookup of backend host/port - */ - -static void -vbe_dns_lookup(struct cli *cli, struct backend *bp) -{ - int error; - struct addrinfo *res, hint, *old; - - CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); - - memset(&hint, 0, sizeof hint); - hint.ai_family = PF_UNSPEC; - hint.ai_socktype = SOCK_STREAM; - res = NULL; - error = getaddrinfo(bp->vrt->hostname, bp->vrt->portname, - &hint, &res); - if (error) { - if (res != NULL) - freeaddrinfo(res); - /* - * We cannot point to the source code any more, it may - * be long gone from memory. We already checked over in - * the VCL compiler, so this is only relevant for refreshes. - * XXX: which we do when exactly ? - */ - cli_out(cli, "DNS(/hosts) lookup failed for (%s/%s): %s", - bp->vrt->hostname, bp->vrt->portname, gai_strerror(error)); - return; - } - LOCK(&bp->mtx); - old = bp->ai; - bp->ai = res; - bp->last_ai = res; - UNLOCK(&bp->mtx); - if (old != NULL) - freeaddrinfo(old); -} - -/*-------------------------------------------------------------------- - * Add a backend/director instance when loading a VCL. - * If an existing backend is matched, grab a refcount and return. - * Else create a new backend structure with reference initialized to one. - */ - -struct backend * -VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb) -{ - struct backend *b; - uint32_t u; - - AN(vb->hostname); - AN(vb->portname); - AN(vb->ident); - (void)cli; - ASSERT_CLI(); - u = crc32_l(vb->ident, strlen(vb->ident)); - VTAILQ_FOREACH(b, &backends, list) { - CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - if (u != b->hash) - continue; - if (strcmp(b->vrt->ident, vb->ident)) - continue; - b->refcount++; - return (b); - } - - ALLOC_OBJ(b, BACKEND_MAGIC); - XXXAN(b); - b->magic = BACKEND_MAGIC; - - VTAILQ_INIT(&b->connlist); - b->hash = u; - - /* - * This backend may live longer than the VCL that instantiated it - * so we cannot simply reference the VCL's copy of things. - */ - REPLACE(b->vrt->ident, vb->ident); - REPLACE(b->vrt->hostname, vb->hostname); - REPLACE(b->vrt->portname, vb->portname); - REPLACE(b->vrt->vcl_name, vb->vcl_name); - - b->vrt->connect_timeout = vb->connect_timeout; - - MTX_INIT(&b->mtx); - b->refcount = 1; - - vbe_dns_lookup(cli, b); - - VTAILQ_INSERT_TAIL(&backends, b, list); - VSL_stats->n_backend++; - return (b); -} - - -/*--------------------------------------------------------------------*/ - -void -VRT_fini_dir(struct cli *cli, struct director *b) -{ - - (void)cli; - ASSERT_CLI(); - CHECK_OBJ_NOTNULL(b, DIRECTOR_MAGIC); - b->fini(b); -} - -/*--------------------------------------------------------------------*/ - -static void -cli_debug_backend(struct cli *cli, const char * const *av, void *priv) -{ - struct backend *b; - - (void)av; - (void)priv; - ASSERT_CLI(); - VTAILQ_FOREACH(b, &backends, list) { - CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - cli_out(cli, "%p %s/%s/%s %d\n", - b, - b->vrt->vcl_name, - b->vrt->hostname, - b->vrt->portname, - b->refcount); - } -} - -static struct cli_proto debug_cmds[] = { - { "debug.backend", "debug.backend", - "\tExamine Backend internals\n", 0, 0, cli_debug_backend }, - { NULL } -}; - -/*--------------------------------------------------------------------*/ - -void -VBE_Init(void) -{ - - MTX_INIT(&VBE_mtx); - CLI_AddFuncs(DEBUG_CLI, debug_cmds); -} Copied: trunk/varnish-cache/bin/varnishd/cache_backend.h (from rev 2895, trunk/varnish-cache/bin/varnishd/cache_backend.c) =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.h (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_backend.h 2008-07-08 10:09:03 UTC (rev 2905) @@ -0,0 +1,96 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2008 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$ + * + * This is the central switch-board for backend connections and it is + * slightly complicated by a number of optimizations. + * + * The data structures: + * + * A vrt_backend is a definition of a backend in a VCL program. + * + * A backend is a TCP destination, possibly multi-homed and it has a + * number of associated properties and statistics. + * + * A vbe_conn is an open TCP connection to a backend. + * + * A bereq is a memory carrier for handling a HTTP transaction with + * a backend over a vbe_conn. + * + * A director is a piece of code that selects which backend to use, + * by whatever method or metric it chooses. + * + * The relationships: + * + * Backends and directors get instantiated when VCL's are loaded, + * and this always happen in the CLI thread. + * + * When a VCL tries to instantiate a backend, any existing backend + * with the same identity (== definition in VCL) will be used instead + * so that vbe_conn's can be reused across VCL changes. + * + * Directors disapper with the VCL that created them. + * + * Backends disappear when their reference count drop to zero. + * + * Backends have their host/port name looked up to addrinfo structures + * when they are instantiated, and we just cache that result and cycle + * through the entries (for multihomed backends) on failure only. + * XXX: add cli command to redo lookup. + * + * bereq is sort of a step-child here, we just manage the pool of them. + * + */ + +/* Backend indstance */ +struct backend { + unsigned magic; +#define BACKEND_MAGIC 0x64c4c7c6 + + struct vrt_backend vrt[1]; + uint32_t hash; + + VTAILQ_ENTRY(backend) list; + int refcount; + pthread_mutex_t mtx; + + struct addrinfo *ai; + struct addrinfo *last_ai; + + VTAILQ_HEAD(, vbe_conn) connlist; + + int health; +}; + +/* cache_backend_cfg.c */ +extern MTX VBE_mtx; +void VBE_DropRefLocked(struct backend *b); + +/* cache_backend.c */ +void VBE_ReleaseConn(struct vbe_conn *vc); Property changes on: trunk/varnish-cache/bin/varnishd/cache_backend.h ___________________________________________________________________ Name: svn:keywords + Id Name: svn:mergeinfo + Copied: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c (from rev 2895, trunk/varnish-cache/bin/varnishd/cache_backend.c) =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2008-07-08 10:09:03 UTC (rev 2905) @@ -0,0 +1,264 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2008 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$ + * + * Handle configuration of backends from VCL programs. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include + +#include +#include + +#include "shmlog.h" +#include "cache.h" +#include "vrt.h" +#include "cache_backend.h" +#include "cli_priv.h" + +MTX VBE_mtx; + +/* + * The list of backends is not locked, it is only ever accessed from + * the CLI thread, so there is no need. + */ +static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends); + +/*--------------------------------------------------------------------*/ + +void +VBE_SelectBackend(struct sess *sp) +{ + struct backend *bp; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC); + bp = sp->director->choose(sp); + CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); + sp->backend = bp; +} + +/*-------------------------------------------------------------------- + * Drop a reference to a backend. + * The last reference must come from the watcher in the CLI thread, + * as only that thread is allowed to clean up the backend list. + */ + +void +VBE_DropRefLocked(struct backend *b) +{ + int i; + struct vbe_conn *vbe, *vbe2; + + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + assert(b->refcount > 0); + + i = --b->refcount; + UNLOCK(&b->mtx); + if (i > 0) + return; + + ASSERT_CLI(); + VTAILQ_REMOVE(&backends, b, list); + VTAILQ_FOREACH_SAFE(vbe, &b->connlist, list, vbe2) { + VTAILQ_REMOVE(&b->connlist, vbe, list); + if (vbe->fd >= 0) + AZ(close(vbe->fd)); + VBE_ReleaseConn(vbe); + } + free(TRUST_ME(b->vrt->ident)); + free(TRUST_ME(b->vrt->hostname)); + free(TRUST_ME(b->vrt->portname)); + b->magic = 0; + free(b); + VSL_stats->n_backend--; +} + +void +VBE_DropRef(struct backend *b) +{ + + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + + LOCK(&b->mtx); + VBE_DropRefLocked(b); +} + +/*-------------------------------------------------------------------- + * DNS lookup of backend host/port + */ + +static void +vbe_dns_lookup(const struct cli *cli, struct backend *bp) +{ + int error; + struct addrinfo *res, hint, *old; + + CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); + + memset(&hint, 0, sizeof hint); + hint.ai_family = PF_UNSPEC; + hint.ai_socktype = SOCK_STREAM; + res = NULL; + error = getaddrinfo(bp->vrt->hostname, bp->vrt->portname, + &hint, &res); + if (error) { + if (res != NULL) + freeaddrinfo(res); + /* + * We cannot point to the source code any more, it may + * be long gone from memory. We already checked over in + * the VCL compiler, so this is only relevant for refreshes. + * XXX: which we do when exactly ? + */ + cli_out(cli, "DNS(/hosts) lookup failed for (%s/%s): %s", + bp->vrt->hostname, bp->vrt->portname, gai_strerror(error)); + return; + } + LOCK(&bp->mtx); + old = bp->ai; + bp->ai = res; + bp->last_ai = res; + UNLOCK(&bp->mtx); + if (old != NULL) + freeaddrinfo(old); +} + +/*-------------------------------------------------------------------- + * Add a backend/director instance when loading a VCL. + * If an existing backend is matched, grab a refcount and return. + * Else create a new backend structure with reference initialized to one. + */ + +struct backend * +VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb) +{ + struct backend *b; + uint32_t u; + + AN(vb->hostname); + AN(vb->portname); + AN(vb->ident); + (void)cli; + ASSERT_CLI(); + u = crc32_l(vb->ident, strlen(vb->ident)); + VTAILQ_FOREACH(b, &backends, list) { + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + if (u != b->hash) + continue; + if (strcmp(b->vrt->ident, vb->ident)) + continue; + b->refcount++; + return (b); + } + + ALLOC_OBJ(b, BACKEND_MAGIC); + XXXAN(b); + b->magic = BACKEND_MAGIC; + + VTAILQ_INIT(&b->connlist); + b->hash = u; + + /* + * This backend may live longer than the VCL that instantiated it + * so we cannot simply reference the VCL's copy of things. + */ + REPLACE(b->vrt->ident, vb->ident); + REPLACE(b->vrt->hostname, vb->hostname); + REPLACE(b->vrt->portname, vb->portname); + REPLACE(b->vrt->vcl_name, vb->vcl_name); + + b->vrt->connect_timeout = vb->connect_timeout; + + MTX_INIT(&b->mtx); + b->refcount = 1; + + vbe_dns_lookup(cli, b); + + VTAILQ_INSERT_TAIL(&backends, b, list); + VSL_stats->n_backend++; + return (b); +} + + +/*--------------------------------------------------------------------*/ + +void +VRT_fini_dir(struct cli *cli, struct director *b) +{ + + (void)cli; + ASSERT_CLI(); + CHECK_OBJ_NOTNULL(b, DIRECTOR_MAGIC); + b->fini(b); +} + +/*--------------------------------------------------------------------*/ + +static void +cli_debug_backend(struct cli *cli, const char * const *av, void *priv) +{ + struct backend *b; + + (void)av; + (void)priv; + ASSERT_CLI(); + VTAILQ_FOREACH(b, &backends, list) { + CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); + cli_out(cli, "%p %s/%s/%s %d\n", + b, + b->vrt->vcl_name, + b->vrt->hostname, + b->vrt->portname, + b->refcount); + } +} + +static struct cli_proto debug_cmds[] = { + { "debug.backend", "debug.backend", + "\tExamine Backend internals\n", 0, 0, cli_debug_backend }, + { NULL } +}; + +/*--------------------------------------------------------------------*/ + +void +VBE_Init(void) +{ + + MTX_INIT(&VBE_mtx); + CLI_AddFuncs(DEBUG_CLI, debug_cmds); +} Property changes on: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c ___________________________________________________________________ Name: svn:keywords + Id Name: svn:mergeinfo + From phk at projects.linpro.no Tue Jul 8 10:29:09 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 8 Jul 2008 12:29:09 +0200 (CEST) Subject: r2906 - in trunk/varnish-cache: bin/varnishd bin/varnishtest bin/varnishtest/tests include lib/libvarnish Message-ID: <20080708102909.9B8771ED249@projects.linpro.no> Author: phk Date: 2008-07-08 12:29:07 +0200 (Tue, 08 Jul 2008) New Revision: 2906 Modified: trunk/varnish-cache/bin/varnishd/acct_fields.h trunk/varnish-cache/bin/varnishd/cache_dir_random.c trunk/varnish-cache/bin/varnishd/cache_dir_simple.c trunk/varnish-cache/bin/varnishd/cache_httpconn.c trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c trunk/varnish-cache/bin/varnishd/instance.c trunk/varnish-cache/bin/varnishtest/t001.vtc trunk/varnish-cache/bin/varnishtest/tests/a00000.vtc trunk/varnish-cache/bin/varnishtest/tests/a00001.vtc trunk/varnish-cache/bin/varnishtest/tests/a00002.vtc trunk/varnish-cache/bin/varnishtest/tests/a00003.vtc trunk/varnish-cache/bin/varnishtest/tests/a00004.vtc trunk/varnish-cache/bin/varnishtest/tests/a00005.vtc trunk/varnish-cache/bin/varnishtest/tests/a00006.vtc trunk/varnish-cache/bin/varnishtest/tests/a00007.vtc trunk/varnish-cache/bin/varnishtest/tests/b00000.vtc trunk/varnish-cache/bin/varnishtest/tests/b00001.vtc trunk/varnish-cache/bin/varnishtest/tests/b00002.vtc trunk/varnish-cache/bin/varnishtest/tests/b00003.vtc trunk/varnish-cache/bin/varnishtest/tests/b00004.vtc trunk/varnish-cache/bin/varnishtest/tests/b00005.vtc trunk/varnish-cache/bin/varnishtest/tests/b00006.vtc trunk/varnish-cache/bin/varnishtest/tests/b00007.vtc trunk/varnish-cache/bin/varnishtest/tests/b00008.vtc trunk/varnish-cache/bin/varnishtest/tests/b00009.vtc trunk/varnish-cache/bin/varnishtest/tests/b00010.vtc trunk/varnish-cache/bin/varnishtest/tests/b00011.vtc trunk/varnish-cache/bin/varnishtest/tests/b00012.vtc trunk/varnish-cache/bin/varnishtest/tests/b00013.vtc trunk/varnish-cache/bin/varnishtest/tests/c00001.vtc trunk/varnish-cache/bin/varnishtest/tests/c00002.vtc trunk/varnish-cache/bin/varnishtest/tests/c00003.vtc trunk/varnish-cache/bin/varnishtest/tests/c00004.vtc trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc trunk/varnish-cache/bin/varnishtest/tests/c00006.vtc trunk/varnish-cache/bin/varnishtest/tests/c00007.vtc trunk/varnish-cache/bin/varnishtest/tests/c00008.vtc trunk/varnish-cache/bin/varnishtest/tests/c00009.vtc trunk/varnish-cache/bin/varnishtest/tests/c00010.vtc trunk/varnish-cache/bin/varnishtest/tests/c00011.vtc trunk/varnish-cache/bin/varnishtest/tests/c00012.vtc trunk/varnish-cache/bin/varnishtest/tests/c00013.vtc trunk/varnish-cache/bin/varnishtest/tests/c00014.vtc trunk/varnish-cache/bin/varnishtest/tests/c00015.vtc trunk/varnish-cache/bin/varnishtest/tests/e00000.vtc trunk/varnish-cache/bin/varnishtest/tests/e00001.vtc trunk/varnish-cache/bin/varnishtest/tests/e00002.vtc trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc trunk/varnish-cache/bin/varnishtest/tests/r00102.vtc trunk/varnish-cache/bin/varnishtest/tests/r00251.vtc trunk/varnish-cache/bin/varnishtest/tests/r00255.vtc trunk/varnish-cache/bin/varnishtest/tests/r00262.vtc trunk/varnish-cache/bin/varnishtest/tests/r00263.vtc trunk/varnish-cache/bin/varnishtest/tests/s00000.vtc trunk/varnish-cache/bin/varnishtest/tests/s00001.vtc trunk/varnish-cache/bin/varnishtest/tests/v00000.vtc trunk/varnish-cache/bin/varnishtest/tests/v00001.vtc trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc trunk/varnish-cache/bin/varnishtest/tests/v00003.vtc trunk/varnish-cache/bin/varnishtest/tests/v00004.vtc trunk/varnish-cache/bin/varnishtest/tests/v00005.vtc trunk/varnish-cache/bin/varnishtest/vtc.c trunk/varnish-cache/bin/varnishtest/vtc.h trunk/varnish-cache/bin/varnishtest/vtc_client.c trunk/varnish-cache/bin/varnishtest/vtc_http.c trunk/varnish-cache/bin/varnishtest/vtc_log.c trunk/varnish-cache/bin/varnishtest/vtc_server.c trunk/varnish-cache/bin/varnishtest/vtc_stats.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/include/vbm.h trunk/varnish-cache/include/vlu.h trunk/varnish-cache/lib/libvarnish/num.c trunk/varnish-cache/lib/libvarnish/vct.c trunk/varnish-cache/lib/libvarnish/vlu.c Log: Set svn:keywords to Id Modified: trunk/varnish-cache/bin/varnishd/acct_fields.h =================================================================== --- trunk/varnish-cache/bin/varnishd/acct_fields.h 2008-07-08 10:09:03 UTC (rev 2905) +++ trunk/varnish-cache/bin/varnishd/acct_fields.h 2008-07-08 10:29:07 UTC (rev 2906) @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: steps.h 2415 2008-01-31 11:57:51Z des $ + * $Id$ */ ACCT(sess) Property changes on: trunk/varnish-cache/bin/varnishd/acct_fields.h ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishd/cache_dir_random.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishd/cache_dir_simple.c ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/bin/varnishd/cache_httpconn.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_httpconn.c 2008-07-08 10:09:03 UTC (rev 2905) +++ trunk/varnish-cache/bin/varnishd/cache_httpconn.c 2008-07-08 10:29:07 UTC (rev 2906) @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cache_http.c 2052 2007-09-28 11:07:14Z phk $ + * $Id$ * * HTTP protocol requests */ Property changes on: trunk/varnish-cache/bin/varnishd/cache_httpconn.c ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-08 10:09:03 UTC (rev 2905) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-08 10:29:07 UTC (rev 2906) @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cache_vrt.c 2067 2007-09-30 20:57:30Z phk $ + * $Id$ * * Runtime support for compiled VCL programs ESI processing. * Property changes on: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishd/instance.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/t001.vtc ___________________________________________________________________ Name: svn:keywords - vtc.c + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/a00000.vtc ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/a00001.vtc ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/a00002.vtc ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/a00003.vtc ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/a00004.vtc ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/a00005.vtc ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/a00006.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/a00007.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00000.vtc ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00001.vtc ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00002.vtc ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00003.vtc ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00004.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00005.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00006.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00007.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00008.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00009.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00010.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00011.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00012.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00013.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00001.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00002.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00003.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00004.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00006.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00007.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00008.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00009.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00010.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00011.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00012.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00013.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00014.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00015.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/e00000.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/e00001.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/e00002.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00102.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00251.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00255.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00262.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00263.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/s00000.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/s00001.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00000.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00001.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00003.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00004.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00005.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/vtc.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/vtc.h ___________________________________________________________________ Name: svn:keywords - vtc.c + Id Property changes on: trunk/varnish-cache/bin/varnishtest/vtc_client.c ___________________________________________________________________ Name: svn:keywords - vtc.c + Id Property changes on: trunk/varnish-cache/bin/varnishtest/vtc_http.c ___________________________________________________________________ Name: svn:keywords - vtc.c + Id Property changes on: trunk/varnish-cache/bin/varnishtest/vtc_log.c ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/vtc_server.c ___________________________________________________________________ Name: svn:keywords - vtc.c + Id Property changes on: trunk/varnish-cache/bin/varnishtest/vtc_stats.c ___________________________________________________________________ Name: svn:keywords - vtc.c + Id Property changes on: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c ___________________________________________________________________ Name: svn:keywords - vtc.c + Id Modified: trunk/varnish-cache/include/vbm.h =================================================================== --- trunk/varnish-cache/include/vbm.h 2008-07-08 10:09:03 UTC (rev 2905) +++ trunk/varnish-cache/include/vbm.h 2008-07-08 10:29:07 UTC (rev 2906) @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cache_acceptor_kqueue.c 2513 2008-02-18 17:04:30Z des $ + * $Id$ * * Self-sizeing bitmap operations */ Property changes on: trunk/varnish-cache/include/vbm.h ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/include/vlu.h =================================================================== --- trunk/varnish-cache/include/vlu.h 2008-07-08 10:09:03 UTC (rev 2905) +++ trunk/varnish-cache/include/vlu.h 2008-07-08 10:29:07 UTC (rev 2906) @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: vpf.h 1410 2007-05-11 11:17:09Z des $ + * $Id$ * * Functions for assembling a bytestream into text-lines and calling * a function on each. Property changes on: trunk/varnish-cache/include/vlu.h ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/lib/libvarnish/num.c ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/lib/libvarnish/vct.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vct.c 2008-07-08 10:09:03 UTC (rev 2905) +++ trunk/varnish-cache/lib/libvarnish/vct.c 2008-07-08 10:29:07 UTC (rev 2906) @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: vpf.h 1410 2007-05-11 11:17:09Z des $ + * $Id$ * * ctype(3) like functions, according to RFC2616 */ Property changes on: trunk/varnish-cache/lib/libvarnish/vct.c ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/lib/libvarnish/vlu.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vlu.c 2008-07-08 10:09:03 UTC (rev 2905) +++ trunk/varnish-cache/lib/libvarnish/vlu.c 2008-07-08 10:29:07 UTC (rev 2906) @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: vpf.h 1410 2007-05-11 11:17:09Z des $ + * $Id$ * * Functions for assembling a bytestream into text-lines and calling * a function on each. Property changes on: trunk/varnish-cache/lib/libvarnish/vlu.c ___________________________________________________________________ Name: svn:keywords + Id From phk at projects.linpro.no Wed Jul 9 08:14:25 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 9 Jul 2008 10:14:25 +0200 (CEST) Subject: r2907 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080709081425.7D01B1ED157@projects.linpro.no> Author: phk Date: 2008-07-09 10:14:25 +0200 (Wed, 09 Jul 2008) New Revision: 2907 Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c Log: Allow modification of the receive timeout Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2008-07-08 10:29:07 UTC (rev 2906) +++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2008-07-09 08:14:25 UTC (rev 2907) @@ -576,12 +576,28 @@ http_write(hp, 4, "chunked"); } +/********************************************************************** + * set the timeout + */ +static void +cmd_http_timeout(CMD_ARGS) +{ + struct http *hp; + + (void)cmd; + CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); + AN(av[1]); + AZ(av[2]); + hp->timeout = strtof(av[1], NULL) * 1000.0; +} + /********************************************************************** * Execute HTTP specifications */ static struct cmds http_cmds[] = { + { "timeout", cmd_http_timeout }, { "txreq", cmd_http_txreq }, { "rxreq", cmd_http_rxreq }, { "txresp", cmd_http_txresp }, From phk at projects.linpro.no Wed Jul 9 08:56:47 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 9 Jul 2008 10:56:47 +0200 (CEST) Subject: r2908 - trunk/varnish-cache/bin/varnishd Message-ID: <20080709085647.76ED81EC209@projects.linpro.no> Author: phk Date: 2008-07-09 10:56:46 +0200 (Wed, 09 Jul 2008) New Revision: 2908 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_cli.c trunk/varnish-cache/bin/varnishd/cache_vcl.c Log: The cachers CLI thread is responsible for garbage collecting dicarded VCL programs, but in practice it didn't happen because we fired the GC function VCL_Idle() after 5 seconds of silence on the CLI port and the manager pings every three (by default). Instead change the name of VCL_Idle() to VCL_Poll() and call it before every CLI command, so that any query command will get an up to date status. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-09 08:14:25 UTC (rev 2907) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-09 08:56:46 UTC (rev 2908) @@ -577,7 +577,7 @@ void VCL_Refresh(struct VCL_conf **vcc); void VCL_Rel(struct VCL_conf **vcc); void VCL_Get(struct VCL_conf **vcc); -void VCL_Idle(void); +void VCL_Poll(void); #define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *); Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_cli.c 2008-07-09 08:14:25 UTC (rev 2907) +++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2008-07-09 08:56:46 UTC (rev 2908) @@ -102,6 +102,7 @@ cli = priv; VSL(SLT_CLI, 0, "Rd %s", p); + VCL_Poll(); vsb_clear(cli->sb); LOCK(&cli_mtx); cli_dispatch(cli, ccf_master_cli, p); @@ -150,11 +151,8 @@ while (1) { pfd[0].fd = heritage.cli_in; pfd[0].events = POLLIN; - i = poll(pfd, 1, 5000); - if (i == 0) { - VCL_Idle(); - continue; - } + i = poll(pfd, 1, INFTIM); + assert(i == 1); if (pfd[0].revents & POLLHUP) { fprintf(stderr, "EOF on CLI connection, exiting\n"); Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vcl.c 2008-07-09 08:14:25 UTC (rev 2907) +++ trunk/varnish-cache/bin/varnishd/cache_vcl.c 2008-07-09 08:56:46 UTC (rev 2908) @@ -105,7 +105,7 @@ vc->busy--; /* * We do not garbage collect discarded VCL's here, that happens - * in VCL_Idle() which is called from the CLI thread. + * in VCL_Poll() which is called from the CLI thread. */ UNLOCK(&vcl_mtx); } @@ -198,7 +198,7 @@ /*--------------------------------------------------------------------*/ void -VCL_Idle(void) +VCL_Poll(void) { struct vcls *vcl, *vcl2; From phk at projects.linpro.no Wed Jul 9 09:06:57 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 9 Jul 2008 11:06:57 +0200 (CEST) Subject: r2909 - trunk/varnish-cache/bin/varnishd Message-ID: <20080709090657.909421ED288@projects.linpro.no> Author: phk Date: 2008-07-09 11:06:57 +0200 (Wed, 09 Jul 2008) New Revision: 2909 Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c Log: Change the layout of the "vcl.list" to explicitly say "active", "available" or "discarded". Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vcl.c 2008-07-09 08:56:46 UTC (rev 2908) +++ trunk/varnish-cache/bin/varnishd/cache_vcl.c 2008-07-09 09:06:57 UTC (rev 2909) @@ -214,13 +214,20 @@ ccf_config_list(struct cli *cli, const char * const *av, void *priv) { struct vcls *vcl; + const char *flg; (void)av; (void)priv; ASSERT_CLI(); VTAILQ_FOREACH(vcl, &vcl_head, list) { - cli_out(cli, "%s %6u %s\n", - vcl == vcl_active ? "* " : " ", + if (vcl == vcl_active) { + flg = "active"; + } else if (vcl->conf->discard) { + flg = "discarded"; + } else + flg = "available"; + cli_out(cli, "%-10s %6u %s\n", + flg, vcl->conf->busy, vcl->name); } From phk at projects.linpro.no Thu Jul 10 07:27:56 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 09:27:56 +0200 (CEST) Subject: r2910 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080710072756.AC0541ED0AC@projects.linpro.no> Author: phk Date: 2008-07-10 09:27:56 +0200 (Thu, 10 Jul 2008) New Revision: 2910 Removed: trunk/varnish-cache/bin/varnishtest/vtc_stats.c Modified: trunk/varnish-cache/bin/varnishtest/Makefile.am trunk/varnish-cache/bin/varnishtest/vtc.c Log: Remove global "stats", stats are per varnish instance. Modified: trunk/varnish-cache/bin/varnishtest/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishtest/Makefile.am 2008-07-09 09:06:57 UTC (rev 2909) +++ trunk/varnish-cache/bin/varnishtest/Makefile.am 2008-07-10 07:27:56 UTC (rev 2910) @@ -11,7 +11,6 @@ vtc_http.c \ vtc_log.c \ vtc_server.c \ - vtc_stats.c \ vtc_varnish.c varnishtest_LDADD = \ Modified: trunk/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.c 2008-07-09 09:06:57 UTC (rev 2909) +++ trunk/varnish-cache/bin/varnishtest/vtc.c 2008-07-10 07:27:56 UTC (rev 2910) @@ -279,7 +279,6 @@ static struct cmds cmds[] = { { "server", cmd_server }, { "client", cmd_client }, - { "stats", cmd_stats }, { "varnish", cmd_varnish }, { "delay", cmd_delay }, { "test", cmd_test }, Deleted: trunk/varnish-cache/bin/varnishtest/vtc_stats.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_stats.c 2008-07-09 09:06:57 UTC (rev 2909) +++ trunk/varnish-cache/bin/varnishtest/vtc_stats.c 2008-07-10 07:27:56 UTC (rev 2910) @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2006-2008 Linpro AS - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - */ - - -#include - -#include "vtc.h" - -void -cmd_stats(CMD_ARGS) -{ - - cmd_dump(av, priv, cmd); -} From phk at projects.linpro.no Thu Jul 10 07:32:07 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 09:32:07 +0200 (CEST) Subject: r2911 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080710073207.73B0D1ED30E@projects.linpro.no> Author: phk Date: 2008-07-10 09:32:07 +0200 (Thu, 10 Jul 2008) New Revision: 2911 Modified: trunk/varnish-cache/bin/varnishtest/Makefile.am trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Open the shm statistics when we launch a varnish Modified: trunk/varnish-cache/bin/varnishtest/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishtest/Makefile.am 2008-07-10 07:27:56 UTC (rev 2910) +++ trunk/varnish-cache/bin/varnishtest/Makefile.am 2008-07-10 07:32:07 UTC (rev 2911) @@ -16,6 +16,7 @@ varnishtest_LDADD = \ $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ + $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${PTHREAD_LIBS} EXTRA_DIST = $(top_srcdir)/bin/varnishtest/tests/*.vtc \ Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-10 07:27:56 UTC (rev 2910) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-10 07:32:07 UTC (rev 2911) @@ -43,6 +43,7 @@ #include "vqueue.h" #include "miniobj.h" #include "libvarnish.h" +#include "varnishapi.h" #include "cli.h" #include "cli_common.h" #include "vss.h" @@ -58,6 +59,8 @@ struct vtclog *vl1; VTAILQ_ENTRY(varnish) list; + struct varnish_stats *stats; + const char *args; int fds[4]; pid_t pid; @@ -217,6 +220,8 @@ vsb_delete(vsb); AZ(pthread_create(&v->tp, NULL, varnish_thread, v)); + v->stats = VSL_OpenStats(v->name); + vtc_log(v->vl, 3, "opening CLI connection"); for (i = 0; i < 10; i++) { (void)usleep(200000); From phk at projects.linpro.no Thu Jul 10 08:00:33 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 10:00:33 +0200 (CEST) Subject: r2912 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080710080033.9B3B71ED0AC@projects.linpro.no> Author: phk Date: 2008-07-10 10:00:33 +0200 (Thu, 10 Jul 2008) New Revision: 2912 Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Make it possible to check stats counter values for a varnish instance Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-10 07:32:07 UTC (rev 2911) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-10 08:00:33 UTC (rev 2912) @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -393,6 +394,47 @@ } /********************************************************************** + * Check statistics + */ + +static void +varnish_expect(struct varnish *v, char * const *av) { + uint64_t val, ref; + int good; + char *p; + +#define MAC_STAT(n, t, f, d) \ + if (!strcmp(av[0], #n)) { \ + val = v->stats->n; \ + } else +#include "stat_field.h" +#undef MAC_STAT + { + vtc_log(v->vl, 0, "stats field %s unknown", av[0]); + } + + ref = strtoumax(av[2], &p, 0); + if (ref == UINTMAX_MAX || *p) + vtc_log(v->vl, 0, "Syntax error in number (%s)", av[2]); + good = 0; + if (!strcmp(av[1], "==")) { if (val == ref) good = 1; } + else if (!strcmp(av[1], "!=")) { if (val != ref) good = 1; } + else if (!strcmp(av[1], ">")) { if (val > ref) good = 1; } + else if (!strcmp(av[1], "<")) { if (val < ref) good = 1; } + else if (!strcmp(av[1], ">=")) { if (val >= ref) good = 1; } + else if (!strcmp(av[1], "<=")) { if (val <= ref) good = 1; } + else { + vtc_log(v->vl, 0, "comparison %s unknown", av[1]); + } + if (good) + vtc_log(v->vl, 2, "as expected: %s (%ju) %s %s", + av[0], val, av[1], av[2]); + else + vtc_log(v->vl, 0, "Not true: %s (%ju) %s %s (%ju)", + av[0], val, av[1], av[2], ref); +} + +/********************************************************************** * Varnish server cmd dispatch */ @@ -478,6 +520,12 @@ varnish_wait(v); continue; } + if (!strcmp(*av, "-expect")) { + av++; + varnish_expect(v, av); + av += 2; + continue; + } vtc_log(v->vl, 0, "Unknown varnish argument: %s", *av); exit (1); } From phk at projects.linpro.no Thu Jul 10 08:09:15 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 10:09:15 +0200 (CEST) Subject: r2913 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20080710080915.6EFC31EC236@projects.linpro.no> Author: phk Date: 2008-07-10 10:09:15 +0200 (Thu, 10 Jul 2008) New Revision: 2913 Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c trunk/varnish-cache/include/stat_field.h Log: Add stats counters for tracking the number of vcls loaded. Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vcl.c 2008-07-10 08:00:33 UTC (rev 2912) +++ trunk/varnish-cache/bin/varnishd/cache_vcl.c 2008-07-10 08:09:15 UTC (rev 2913) @@ -172,6 +172,8 @@ UNLOCK(&vcl_mtx); cli_out(cli, "Loaded \"%s\" as \"%s\"\n", fn , name); vcl->conf->init_func(cli); + VSL_stats->n_vcl++; + VSL_stats->n_vcl_avail++; return (0); } @@ -193,6 +195,8 @@ free(vcl->name); (void)dlclose(vcl->dlh); FREE_OBJ(vcl); + VSL_stats->n_vcl--; + VSL_stats->n_vcl_discard--; } /*--------------------------------------------------------------------*/ @@ -266,6 +270,8 @@ cli_out(cli, "VCL %s is the active VCL", av[2]); return; } + VSL_stats->n_vcl_discard++; + VSL_stats->n_vcl_avail--; vcl->conf->discard = 1; UNLOCK(&vcl_mtx); if (vcl->conf->busy == 0) Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2008-07-10 08:00:33 UTC (rev 2912) +++ trunk/varnish-cache/include/stat_field.h 2008-07-10 08:09:15 UTC (rev 2913) @@ -105,3 +105,7 @@ MAC_STAT(sma_bfree, uint64_t, 'i', "SMA bytes free") MAC_STAT(backend_req, uint64_t, 'a', "Backend requests made") + +MAC_STAT(n_vcl, uint64_t, 'a', "N vcl total") +MAC_STAT(n_vcl_avail, uint64_t, 'a', "N vcl available") +MAC_STAT(n_vcl_discard, uint64_t, 'a', "N vcl discarded") From phk at projects.linpro.no Thu Jul 10 09:34:48 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 11:34:48 +0200 (CEST) Subject: r2914 - trunk/varnish-cache/bin/varnishd Message-ID: <20080710093448.0E6AF1EC0E1@projects.linpro.no> Author: phk Date: 2008-07-10 11:34:47 +0200 (Thu, 10 Jul 2008) New Revision: 2914 Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c Log: The emminently sensible INFTIM isn't portable, use -1 Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_cli.c 2008-07-10 08:09:15 UTC (rev 2913) +++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2008-07-10 09:34:47 UTC (rev 2914) @@ -151,7 +151,7 @@ while (1) { pfd[0].fd = heritage.cli_in; pfd[0].events = POLLIN; - i = poll(pfd, 1, INFTIM); + i = poll(pfd, 1, -1); assert(i == 1); if (pfd[0].revents & POLLHUP) { fprintf(stderr, From phk at projects.linpro.no Thu Jul 10 10:26:18 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 12:26:18 +0200 (CEST) Subject: r2915 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080710102618.C8D041ED0AC@projects.linpro.no> Author: phk Date: 2008-07-10 12:26:17 +0200 (Thu, 10 Jul 2008) New Revision: 2915 Added: trunk/varnish-cache/bin/varnishtest/vtc_sema.c Modified: trunk/varnish-cache/bin/varnishtest/Makefile.am trunk/varnish-cache/bin/varnishtest/vtc.c trunk/varnish-cache/bin/varnishtest/vtc.h trunk/varnish-cache/bin/varnishtest/vtc_http.c Log: Add Semaphore facility to synchronize different treads in the tester with each other. Modified: trunk/varnish-cache/bin/varnishtest/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishtest/Makefile.am 2008-07-10 09:34:47 UTC (rev 2914) +++ trunk/varnish-cache/bin/varnishtest/Makefile.am 2008-07-10 10:26:17 UTC (rev 2915) @@ -10,6 +10,7 @@ vtc_client.c \ vtc_http.c \ vtc_log.c \ + vtc_sema.c \ vtc_server.c \ vtc_varnish.c Modified: trunk/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.c 2008-07-10 09:34:47 UTC (rev 2914) +++ trunk/varnish-cache/bin/varnishtest/vtc.c 2008-07-10 10:26:17 UTC (rev 2915) @@ -283,6 +283,7 @@ { "delay", cmd_delay }, { "test", cmd_test }, { "shell", cmd_shell }, + { "sema", cmd_sema }, { NULL, NULL } }; @@ -328,6 +329,7 @@ } argc -= optind; argv += optind; + init_sema(); for (ch = 0; ch < argc; ch++) exec_file(argv[ch]); fok = fopen("_.ok", "w"); Modified: trunk/varnish-cache/bin/varnishtest/vtc.h =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.h 2008-07-10 09:34:47 UTC (rev 2914) +++ trunk/varnish-cache/bin/varnishtest/vtc.h 2008-07-10 10:26:17 UTC (rev 2915) @@ -46,7 +46,10 @@ cmd_f cmd_client; cmd_f cmd_stats; cmd_f cmd_varnish; +cmd_f cmd_sema; +void init_sema(void); + void http_process(struct vtclog *vl, const char *spec, int sock, int client); void cmd_server_genvcl(struct vsb *vsb); Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2008-07-10 09:34:47 UTC (rev 2914) +++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2008-07-10 10:26:17 UTC (rev 2915) @@ -606,6 +606,7 @@ { "send", cmd_http_send }, { "chunked", cmd_http_chunked }, { "delay", cmd_delay }, + { "sema", cmd_sema }, { NULL, NULL } }; Added: trunk/varnish-cache/bin/varnishtest/vtc_sema.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_sema.c (rev 0) +++ trunk/varnish-cache/bin/varnishtest/vtc_sema.c 2008-07-10 10:26:17 UTC (rev 2915) @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2006-2008 Linpro AS + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: vtc_sema.c 2906 2008-07-08 10:29:07Z phk $ + */ + +#include +#include +#include +#include +#include + +#include "vtc.h" + +#include "vqueue.h" +#include "miniobj.h" +#include "libvarnish.h" + +struct sema { + unsigned magic; +#define SEMA_MAGIC 0x29b64317 + char *name; + struct vtclog *vl; + VTAILQ_ENTRY(sema) list; + pthread_mutex_t mtx; + pthread_cond_t cond; + + unsigned waiters; + unsigned expected; +}; + +static pthread_mutex_t sema_mtx; +static VTAILQ_HEAD(, sema) semas = VTAILQ_HEAD_INITIALIZER(semas); + +/********************************************************************** + * Allocate and initialize a sema + */ + +static struct sema * +sema_new(char *name) +{ + struct sema *r; + + ALLOC_OBJ(r, SEMA_MAGIC); + AN(r); + r->vl = vtc_logopen(name); + AN(r->vl); + r->name = name; + if (*name != 'r') + vtc_log(r->vl, 0, "Sema name must start with 'r'"); + + AZ(pthread_mutex_init(&r->mtx, NULL)); + AZ(pthread_cond_init(&r->cond, NULL)); + r->waiters = 0; + r->expected = 0; + VTAILQ_INSERT_TAIL(&semas, r, list); + return (r); +} + +/********************************************************************** + * Sync a sema + */ + +static void +sema_sync(struct sema *r, const char *av) +{ + unsigned u; + + u = strtoul(av, NULL, 0); + + AZ(pthread_mutex_lock(&r->mtx)); + if (r->expected == 0) + r->expected = u; + assert(r->expected == u); + + if (++r->waiters == r->expected) { + vtc_log(r->vl, 4, "Wake %u", r->expected); + AZ(pthread_cond_broadcast(&r->cond)); + r->waiters = 0; + r->expected = 0; + } else + AZ(pthread_cond_wait(&r->cond, &r->mtx)); + AZ(pthread_mutex_unlock(&r->mtx)); +} + +/********************************************************************** + * Semaphore command dispatch + */ + +void +cmd_sema(CMD_ARGS) +{ + struct sema *r, *r2; + + (void)priv; + (void)cmd; + + if (av == NULL) { + AZ(pthread_mutex_lock(&sema_mtx)); + /* Reset and free */ + VTAILQ_FOREACH_SAFE(r, &semas, list, r2) { + VTAILQ_REMOVE(&semas, r, list); + FREE_OBJ(r); + /* XXX: MEMLEAK */ + } + AZ(pthread_mutex_unlock(&sema_mtx)); + return; + } + + assert(!strcmp(av[0], "sema")); + av++; + + AZ(pthread_mutex_lock(&sema_mtx)); + VTAILQ_FOREACH(r, &semas, list) + if (!strcmp(r->name, av[0])) + break; + if (r == NULL) + r = sema_new(av[0]); + AZ(pthread_mutex_unlock(&sema_mtx)); + av++; + + for (; *av != NULL; av++) { + if (!strcmp(*av, "sync")) { + av++; + AN(*av); + sema_sync(r, *av); + continue; + } + vtc_log(r->vl, 0, "Unknown sema argument: %s", *av); + } +} + +void +init_sema(void) +{ + AZ(pthread_mutex_init(&sema_mtx, NULL)); +} From phk at projects.linpro.no Thu Jul 10 10:27:43 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 12:27:43 +0200 (CEST) Subject: r2916 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080710102743.BFEEC1EC236@projects.linpro.no> Author: phk Date: 2008-07-10 12:27:43 +0200 (Thu, 10 Jul 2008) New Revision: 2916 Added: trunk/varnish-cache/bin/varnishtest/tests/a00008.vtc Log: Add a testcase for the sema operations Added: trunk/varnish-cache/bin/varnishtest/tests/a00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/a00008.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/a00008.vtc 2008-07-10 10:27:43 UTC (rev 2916) @@ -0,0 +1,51 @@ +# $Id: a00007.vtc 2906 2008-07-08 10:29:07Z phk $ + +test "Sema operations" + +server s1 -listen 127.0.0.1:9080 { + rxreq + sema r1 sync 4 + delay .9 + txresp +} -start + +server s2 -listen 127.0.0.1:9081 { + rxreq + sema r1 sync 4 + delay .6 + txresp +} -start + +server s3 -listen 127.0.0.1:9082 { + rxreq + sema r1 sync 4 + delay .2 + txresp +} -start + +client c1 -connect 127.0.0.1:9080 { + delay .2 + txreq + rxresp + sema r1 sync 4 +} -start + +client c2 -connect 127.0.0.1:9081 { + delay .6 + txreq + rxresp + sema r1 sync 4 +} -start + +client c3 -connect 127.0.0.1:9082 { + delay .9 + txreq + rxresp + sema r1 sync 4 +} -start + +# Wait for all servers to have received requests +sema r1 sync 4 + +# Wait for all clients to have received responses +sema r1 sync 4 From phk at projects.linpro.no Thu Jul 10 11:17:22 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 13:17:22 +0200 (CEST) Subject: r2917 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080710111722.BAAB71ED0AC@projects.linpro.no> Author: phk Date: 2008-07-10 13:17:22 +0200 (Thu, 10 Jul 2008) New Revision: 2917 Added: trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc Log: Add a testcase to show that we can in fact get rid of both VCL's and backend hosts. Added: trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc 2008-07-10 11:17:22 UTC (rev 2917) @@ -0,0 +1,74 @@ +# $Id: v00006.vtc 2906 2008-07-08 10:29:07Z phk $ + +test "VCL: Test backend retirement" + +# First do one request to get a work-thread that holds a VCL reference + +server s1 -listen 127.0.0.1:9080 { + rxreq + txresp +} -start + +# Only one pool, to avoid getting more than one work thread +varnish v1 -arg "-p thread_pools=1" -vcl { + backend b1 { + .host = "localhost"; + .port = "9080"; + } +} -start + +client c1 { + txreq + rxresp +} -start + +server s1 -wait +client c1 -wait + +varnish v1 -expect n_backend == 1 +varnish v1 -expect n_vcl_avail == 1 +varnish v1 -expect n_vcl_discard == 0 + +# Set up a new VCL and backend + +server s2 -listen 127.0.0.1:9180 { + rxreq + txresp +} -start + +varnish v1 -vcl { + backend b2 { + .host = "localhost"; + .port = "9180"; + } +} + +varnish v1 -expect n_backend == 2 +varnish v1 -expect n_vcl_avail == 2 +varnish v1 -expect n_vcl_discard == 0 + +varnish v1 -cli "debug.backend" -cli "vcl.list" + +# Discard the first VCL + +varnish v1 -cli "vcl.discard vcl1" + +# It won't go away as long as the workthread holds a VCL reference +varnish v1 -expect n_backend == 2 +varnish v1 -expect n_vcl_avail == 1 +varnish v1 -expect n_vcl_discard == 1 + +# Do another request through the new VCL to the new backend +client c1 { + txreq -url /foo + rxresp +} -start + +# The workthread should have released its VCL reference now +# but we need to tickle the CLI to notice + +varnish v1 -cli "debug.backend" -cli "vcl.list" + +varnish v1 -expect n_backend == 1 +varnish v1 -expect n_vcl_avail == 1 +varnish v1 -expect n_vcl_discard == 0 From phk at projects.linpro.no Thu Jul 10 18:08:42 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 20:08:42 +0200 (CEST) Subject: r2918 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080710180842.828EC1EC236@projects.linpro.no> Author: phk Date: 2008-07-10 20:08:42 +0200 (Thu, 10 Jul 2008) New Revision: 2918 Added: trunk/varnish-cache/bin/varnishtest/tests/v00007.vtc Log: Add a testcase for the random director doing actual work Added: trunk/varnish-cache/bin/varnishtest/tests/v00007.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00007.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00007.vtc 2008-07-10 18:08:42 UTC (rev 2918) @@ -0,0 +1,29 @@ +# $Id$ + +test "Test random director" + +server s1 { + rxreq + txresp -body "foo1" + rxreq + txresp -body "bar1" +} -start + +varnish v1 -vcl+backend { + director foo random { + { .backend = s1; .weight = 1; } + { .backend = s1; .weight = 1; } + } + + sub vcl_recv { + set req.backend = foo; + } +} -start + +client c1 { + timeout 10 + txreq -url "/foo" + rxresp + txreq -url "/bar" + rxresp +} -run From phk at projects.linpro.no Thu Jul 10 18:09:42 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 20:09:42 +0200 (CEST) Subject: r2919 - trunk/varnish-cache/bin/varnishd Message-ID: <20080710180942.EE4821EC114@projects.linpro.no> Author: phk Date: 2008-07-10 20:09:42 +0200 (Thu, 10 Jul 2008) New Revision: 2919 Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c Log: Fix an off-by one in the random director Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-07-10 18:08:42 UTC (rev 2918) +++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-07-10 18:09:42 UTC (rev 2919) @@ -35,6 +35,7 @@ #include #include +#include #include #include #include @@ -74,7 +75,7 @@ r = random(); r &= 0x7fffffff; - for (vh = vs->hosts; i < vs->nhosts; vh++) + for (i = 0, vh = vs->hosts; i < vs->nhosts; vh++) if (r < vh->weight) return (vh->backend); assert(0 == __LINE__); @@ -136,7 +137,7 @@ i = 0; a = 0.0; assert(s > 0.0); - for (te = t->members; te->host != NULL; te++, i++) { + for (te = t->members; i < t->nmember; te++, i++) { /* First normalize the specified weight in FP */ b = te->weight / s; /*lint !e795 not zero division */ /* Then accumulate to eliminate rounding errors */ @@ -145,5 +146,6 @@ v = (unsigned)((1U<<31) * a); vs->hosts[i].weight = v; } + assert(vs->hosts[t->nmember - 1].weight > 0x7fffffff); *bp = &vs->dir; } From phk at projects.linpro.no Thu Jul 10 19:40:18 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 21:40:18 +0200 (CEST) Subject: r2920 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080710194018.2E1F61EC236@projects.linpro.no> Author: phk Date: 2008-07-10 21:40:17 +0200 (Thu, 10 Jul 2008) New Revision: 2920 Added: trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc Log: Add a test for the -f argument Added: trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc 2008-07-10 19:40:17 UTC (rev 2920) @@ -0,0 +1,20 @@ +# $Id$ + +test "Check -f command line arg" + +shell "echo 'backend foo { .host = \"127.0.0.1\"; .port = \"9080\"; }' > /tmp/_b00013.vcl" +varnish v1 -arg "-h simple_list -f /tmp/_b00013.vcl" -start +shell "rm -f /tmp/_b00013.vcl" + +server s1 { + rxreq + expect req.url == "/foo" + txresp -body "foo" +} -start + +client c1 { + txreq -url /foo + rxresp +} + +client c1 -run From phk at projects.linpro.no Thu Jul 10 19:59:56 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 21:59:56 +0200 (CEST) Subject: r2921 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080710195956.B8D1B1ED1C3@projects.linpro.no> Author: phk Date: 2008-07-10 21:59:56 +0200 (Thu, 10 Jul 2008) New Revision: 2921 Modified: trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc Log: Test the vcl.load CLI command while we are at it. Modified: trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc 2008-07-10 19:40:17 UTC (rev 2920) +++ trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc 2008-07-10 19:59:56 UTC (rev 2921) @@ -4,17 +4,26 @@ shell "echo 'backend foo { .host = \"127.0.0.1\"; .port = \"9080\"; }' > /tmp/_b00013.vcl" varnish v1 -arg "-h simple_list -f /tmp/_b00013.vcl" -start -shell "rm -f /tmp/_b00013.vcl" server s1 { rxreq expect req.url == "/foo" txresp -body "foo" + rxreq + expect req.url == "/bar" + txresp -body "bar" } -start client c1 { txreq -url /foo rxresp -} +} -run -client c1 -run +varnish v1 -cli "vcl.load foo /tmp/_b00013.vcl" -cli "vcl.use foo" + +client c1 { + txreq -url /bar + rxresp +} -run + +shell "rm -f /tmp/_b00013.vcl" From phk at projects.linpro.no Thu Jul 10 20:08:57 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 22:08:57 +0200 (CEST) Subject: r2922 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080710200857.7C3D51EC236@projects.linpro.no> Author: phk Date: 2008-07-10 22:08:57 +0200 (Thu, 10 Jul 2008) New Revision: 2922 Added: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc Log: Test XML/ESI syntax errors etc. Added: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 20:08:57 UTC (rev 2922) @@ -0,0 +1,33 @@ +# $Id: e00004.vtc 2906 2008-07-08 10:29:07Z phk $ + +test "ESI parsing errors" + +server s1 { + rxreq + txresp -body { + Before include + + After include + + + } + rxreq + expect req.url == "/body" + txresp -body { + Included file + } +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + esi; + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} + +client c1 -run From phk at projects.linpro.no Thu Jul 10 20:25:41 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 22:25:41 +0200 (CEST) Subject: r2923 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080710202541.13CF61ED1C3@projects.linpro.no> Author: phk Date: 2008-07-10 22:25:40 +0200 (Thu, 10 Jul 2008) New Revision: 2923 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc Log: More XML/ESI errors Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 20:08:57 UTC (rev 2922) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 20:25:40 UTC (rev 2923) @@ -10,6 +10,22 @@ After include + + foo + + + + + + + + + + bar + + + + } rxreq expect req.url == "/body" From phk at projects.linpro.no Thu Jul 10 20:49:45 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 22:49:45 +0200 (CEST) Subject: r2924 - trunk/varnish-cache/bin/varnishd Message-ID: <20080710204945.8106F1EC236@projects.linpro.no> Author: phk Date: 2008-07-10 22:49:45 +0200 (Thu, 10 Jul 2008) New Revision: 2924 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Fix two bugs in esi parsing: Ignore unknown include attributes and Warn about src attributes without value Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-10 20:25:40 UTC (rev 2923) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-10 20:49:45 UTC (rev 2924) @@ -277,11 +277,14 @@ VSL(SLT_Debug, 0, "<%.*s> -> <%.*s>", tag.e - tag.b, tag.b, val.e - val.b, val.b); - if (Tlen(tag) != 3 && memcmp(tag.b, "src", 3)) + if (Tlen(tag) != 3 || memcmp(tag.b, "src", 3)) + continue; + if (Tlen(val) == 0) { + esi_error(ew, tag.b, Tlen(tag), + "ESI esi:include src attribute withou value"); continue; + } - assert(Tlen(val) > 0); /* XXX */ - if (Tlen(val) > 7 && !memcmp(val.b, "http://", 7)) { /* Rewrite to Host: header inplace */ eb->host.b = val.b; From phk at projects.linpro.no Thu Jul 10 20:50:04 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 22:50:04 +0200 (CEST) Subject: r2925 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080710205004.5D31E1EC10F@projects.linpro.no> Author: phk Date: 2008-07-10 22:50:04 +0200 (Thu, 10 Jul 2008) New Revision: 2925 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc Log: Trigger a couple more XML/ESI parser errors Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 20:49:45 UTC (rev 2924) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 20:50:04 UTC (rev 2925) @@ -26,6 +26,14 @@ + + + + + } rxreq expect req.url == "/body" From phk at projects.linpro.no Thu Jul 10 21:11:12 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 23:11:12 +0200 (CEST) Subject: r2926 - trunk/varnish-cache/bin/varnishd Message-ID: <20080710211112.6FAEF1ED157@projects.linpro.no> Author: phk Date: 2008-07-10 23:11:11 +0200 (Thu, 10 Jul 2008) New Revision: 2926 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Tackle another XML/ESI syntax error corner-case: would result in a NUL byte when looking for the next attribute. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-10 20:50:04 UTC (rev 2925) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-10 21:11:11 UTC (rev 2926) @@ -189,6 +189,7 @@ esi_attrib(const struct esi_work *ew, txt *in, txt *attrib, txt *val) { + AN(*in->b); /* Skip leading blanks */ while(in->b < in->e && isspace(*in->b)) in->b++; @@ -224,6 +225,13 @@ /* skip '=' */ in->b++; + if (isspace(*in->b)) { + val->e = val->b = in->b;; + *val->e = '\0'; + in->b++; + return (1); + } + /* Value, if any ? */ *val = *in; if (in->b >= in->e) From phk at projects.linpro.no Thu Jul 10 21:11:30 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 23:11:30 +0200 (CEST) Subject: r2927 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080710211130.ABB721EC236@projects.linpro.no> Author: phk Date: 2008-07-10 23:11:30 +0200 (Thu, 10 Jul 2008) New Revision: 2927 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc Log: More XML/ESI syntax checks Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 21:11:11 UTC (rev 2926) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 21:11:30 UTC (rev 2927) @@ -33,7 +33,10 @@ > - + + + + } rxreq expect req.url == "/body" From phk at projects.linpro.no Thu Jul 10 21:23:52 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 23:23:52 +0200 (CEST) Subject: r2928 - trunk/varnish-cache/bin/varnishd Message-ID: <20080710212352.4E0C71EC236@projects.linpro.no> Author: phk Date: 2008-07-10 23:23:52 +0200 (Thu, 10 Jul 2008) New Revision: 2928 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Yet another XML/ESI parse corner case: Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-10 21:11:30 UTC (rev 2927) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-10 21:23:52 UTC (rev 2928) @@ -260,6 +260,7 @@ while(in->b < in->e && !isspace(*in->b)) in->b++; val->e = in->b; + in->b++; } *val->e = '\0'; return (1); From phk at projects.linpro.no Thu Jul 10 21:24:07 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 10 Jul 2008 23:24:07 +0200 (CEST) Subject: r2929 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080710212407.83CD81EC10F@projects.linpro.no> Author: phk Date: 2008-07-10 23:24:07 +0200 (Thu, 10 Jul 2008) New Revision: 2929 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc Log: More XML/ESI testcases Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 21:23:52 UTC (rev 2928) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 21:24:07 UTC (rev 2929) @@ -37,12 +37,19 @@ + Author: phk Date: 2008-07-10 23:34:44 +0200 (Thu, 10 Jul 2008) New Revision: 2930 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc Log: Add more trouble Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 21:24:07 UTC (rev 2929) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 21:34:44 UTC (rev 2930) @@ -44,11 +44,15 @@ expect req.url == "/body" txresp -body { Included file + + Author: phk Date: 2008-07-10 23:43:44 +0200 (Thu, 10 Jul 2008) New Revision: 2931 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc Log: One more. Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 21:34:44 UTC (rev 2930) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-10 21:43:44 UTC (rev 2931) @@ -37,6 +37,7 @@ + Author: phk Date: 2008-07-10 23:55:48 +0200 (Thu, 10 Jul 2008) New Revision: 2933 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Make the vcl.list use the same layout in stopped mode as in started mode. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-07-10 21:51:19 UTC (rev 2932) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-07-10 21:55:48 UTC (rev 2933) @@ -674,6 +674,7 @@ { unsigned status; char *p; + const char *flg; struct vclprog *vp; (void)av; @@ -686,9 +687,12 @@ free(p); } else { VTAILQ_FOREACH(vp, &vclhead, list) { - cli_out(cli, "%s %6s %s\n", - vp->active ? "*" : " ", - "N/A", vp->name); + if (vp->active) { + flg = "active"; + } else + flg = "available"; + cli_out(cli, "%-10s %6s %s\n", + flg, "N/A", vp->name); } } } From phk at projects.linpro.no Fri Jul 11 10:12:53 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 11 Jul 2008 12:12:53 +0200 (CEST) Subject: r2934 - in trunk/varnish-cache: include lib/libvcl Message-ID: <20080711101253.7474A1EC114@projects.linpro.no> Author: phk Date: 2008-07-11 12:12:52 +0200 (Fri, 11 Jul 2008) New Revision: 2934 Modified: trunk/varnish-cache/include/vrt.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 Log: Reject backend hostnames that resolve to multiple IPv4 or multiple IPv6 addresses, but accept one of each. Emit a bytestring representation of the sockaddr we found for each of these, into the shared object, so we avoid doing a DNS lookup again in the cacher. Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2008-07-10 21:55:48 UTC (rev 2933) +++ trunk/varnish-cache/include/vrt.h 2008-07-11 10:12:52 UTC (rev 2934) @@ -57,6 +57,10 @@ struct vrt_backend { char *portname; char *hostname; + + const unsigned char *ipv4_sockaddr; + const unsigned char *ipv6_sockaddr; + char *vcl_name; char *ident; double connect_timeout; Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-10 21:55:48 UTC (rev 2933) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-11 10:12:52 UTC (rev 2934) @@ -89,6 +89,94 @@ } /*-------------------------------------------------------------------- + * Struct sockaddr is not really designed to be a compile time + * initialized data structure, so we encode it as a byte-string + * and put it in an official sockaddr when we load the VCL. + */ + +static void +Emit_Sockaddr(struct tokenlist *tl, const struct token *t_host, const char *port) +{ + struct addrinfo *res, *res0, hint; + int n4, n6, len, error, retval; + const char *emit, *multiple; + unsigned char *u; + char hbuf[NI_MAXHOST]; + + AN(t_host->dec); + retval = 0; + memset(&hint, 0, sizeof hint); + hint.ai_family = PF_UNSPEC; + hint.ai_socktype = SOCK_STREAM; + error = getaddrinfo(t_host->dec, port, &hint, &res0); + AZ(error); + n4 = n6 = 0; + multiple = NULL; + for (res = res0; res; res = res->ai_next) { + emit = NULL; + if (res->ai_family == PF_INET) { + if (n4++ == 0) + emit = "ipv4_sockaddr"; + else + multiple = "IPv4"; + } else if (res->ai_family == PF_INET6) { + if (n6++ == 0) + emit = "ipv6_sockaddr"; + else + multiple = "IPv6"; + } else + continue; + + if (multiple != NULL) { + vsb_printf(tl->sb, + "Backend host %.*s: resolves to " + "multiple %s addresses.\n" + "Only one address is allowed.\n" + "Please specify which exact address " + "you want to use, we found these:\n", + PF(t_host), multiple); + for (res = res0; res; res = res->ai_next) { + error = getnameinfo(res->ai_addr, + res->ai_addrlen, hbuf, sizeof hbuf, + NULL, 0, NI_NUMERICHOST); + AZ(error); + vsb_printf(tl->sb, "\t%s\n", hbuf); + } + vcc_ErrWhere(tl, t_host); + return; + } + AN(emit); + AN(res->ai_addr); + AN(res->ai_addrlen); + assert(res->ai_addrlen < 256); + Fh(tl, 0, "\nstatic const unsigned char sockaddr%u[%d] = {\n", + tl->nsockaddr, res->ai_addrlen + 1); + Fh(tl, 0, " %3u, /* Length */\n", res->ai_addrlen); + u = (void*)res->ai_addr; + for (len = 0; len < res->ai_addrlen; len++) { + if ((len % 8) == 0) + Fh(tl, 0, " "); + Fh(tl, 0, " %3u", u[len]); + if (len + 1 < res->ai_addrlen) + Fh(tl, 0, ","); + if ((len % 8) == 7) + Fh(tl, 0, "\n"); + } + Fh(tl, 0, "\n};\n"); + Fb(tl, 0, "\t.%s = sockaddr%u,\n", emit, tl->nsockaddr++); + retval++; + } + freeaddrinfo(res0); + if (retval == 0) { + vsb_printf(tl->sb, + "Backend host '%.*s': resolves to " + "neither IPv4 nor IPv6 addresses.\n", + PF(t_host) ); + vcc_ErrWhere(tl, t_host); + } +} + +/*-------------------------------------------------------------------- * When a new VCL is loaded, it is likely to contain backend declarations * identical to other loaded VCL programs, and we want to reuse the state * of those in order to not have to relearn statistics, DNS etc. @@ -266,7 +354,7 @@ ExpectErr(tl, CSTR); Fh(tl, 0, "\t\t.request =\n"); Fh(tl, 0, "\t\t\t\"GET \" "); - EncToken(tl->fh, tl->t); + EncToken(tl->fb, tl->t); Fh(tl, 0, " \" /HTTP/1.1\\r\\n\"\n"); Fh(tl, 0, "\t\t\t\"Connection: close\\r\\n\"\n"); Fh(tl, 0, "\t\t\t\"\\r\\n\",\n"); @@ -278,23 +366,19 @@ Fh(tl, 0, "\t\t.request =\n"); while (tl->t->tok == CSTR) { Fh(tl, 0, "\t\t\t"); - EncToken(tl->fh, tl->t); + EncToken(tl->fb, tl->t); Fh(tl, 0, " \"\\r\\n\"\n"); vcc_NextToken(tl); } Fh(tl, 0, "\t\t\t\"\\r\\n\",\n"); } else if (vcc_IdIs(t_field, "timeout")) { Fh(tl, 0, "\t\t.timeout = "); - tl->fb = tl->fh; vcc_TimeVal(tl); - tl->fb = NULL; ERRCHK(tl); Fh(tl, 0, ",\n"); } else if (vcc_IdIs(t_field, "rate")) { Fh(tl, 0, "\t\t.rate = "); - tl->fb = tl->fh; vcc_TimeVal(tl); - tl->fb = NULL; ERRCHK(tl); Fh(tl, 0, ",\n"); } else { @@ -339,6 +423,7 @@ struct token *t_port = NULL; const char *ep; struct fld_spec *fs; + struct vsb *vsb; fs = vcc_FldSpec(tl, "!host", "?port", "?connect_timeout", "?probe", NULL); @@ -347,8 +432,12 @@ ExpectErr(tl, '{'); vcc_NextToken(tl); + vsb = vsb_newauto(); + AN(vsb); + tl->fb = vsb; + *nbh = tl->nbackend_host++; - Fh(tl, 0, "\nstatic const struct vrt_backend bh_%d = {\n", *nbh); + Fb(tl, 0, "\nstatic const struct vrt_backend bh_%d = {\n", *nbh); /* Check for old syntax */ if (tl->t->tok == ID && vcc_IdIs(tl->t, "set")) { @@ -383,12 +472,10 @@ ExpectErr(tl, ';'); vcc_NextToken(tl); } else if (vcc_IdIs(t_field, "connect_timeout")) { - Fh(tl, 0, "\t.connect_timeout = "); - tl->fb = tl->fh; + Fb(tl, 0, "\t.connect_timeout = "); vcc_TimeVal(tl); - tl->fb = NULL; ERRCHK(tl); - Fh(tl, 0, ",\n"); + Fb(tl, 0, ",\n"); ExpectErr(tl, ';'); vcc_NextToken(tl); } else if (vcc_IdIs(t_field, "probe")) { @@ -412,33 +499,42 @@ vcc_ErrWhere(tl, t_host); return; } - Fh(tl, 0, "\t.hostname = "); - EncToken(tl->fh, t_host); - Fh(tl, 0, ",\n"); + Fb(tl, 0, "\t.hostname = "); + EncToken(tl->fb, t_host); + Fb(tl, 0, ",\n"); /* Check that the portname makes sense */ if (t_port != NULL) { - ep = CheckHostPort(t_host->dec, t_port->dec); + ep = CheckHostPort("localhost", t_port->dec); if (ep != NULL) { vsb_printf(tl->sb, "Backend port '%.*s': %s\n", PF(t_port), ep); vcc_ErrWhere(tl, t_port); return; } - Fh(tl, 0, "\t.portname = "); - EncToken(tl->fh, t_port); - Fh(tl, 0, ",\n"); + Fb(tl, 0, "\t.portname = "); + EncToken(tl->fb, t_port); + Fb(tl, 0, ",\n"); + Emit_Sockaddr(tl, t_host, t_port->dec); } else { - Fh(tl, 0, "\t.portname = \"80\",\n"); + Fb(tl, 0, "\t.portname = \"80\",\n"); + Emit_Sockaddr(tl, t_host, "80"); } + ERRCHK(tl); ExpectErr(tl, '}'); - vcc_EmitBeIdent(tl->fh, name, qual, serial, t_first, tl->t); - Fh(tl, 0, "\t.vcl_name = \"%.*s", PF(name)); + vcc_EmitBeIdent(tl->fb, name, qual, serial, t_first, tl->t); + Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(name)); if (serial) - Fh(tl, 0, "[%d]", serial); - Fh(tl, 0, "\"\n};\n"); + Fb(tl, 0, "[%d]", serial); + Fb(tl, 0, "\"\n};\n"); vcc_NextToken(tl); + + tl->fb = NULL; + vsb_finish(vsb); + AZ(vsb_overflowed(vsb)); + Fh(tl, 0, "%s", vsb_data(vsb)); + vsb_delete(vsb); } /*-------------------------------------------------------------------- Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-10 21:55:48 UTC (rev 2933) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-11 10:12:52 UTC (rev 2934) @@ -87,6 +87,7 @@ unsigned recnt; unsigned nhashcount; + unsigned nsockaddr; }; enum var_type { Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-10 21:55:48 UTC (rev 2933) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-11 10:12:52 UTC (rev 2934) @@ -395,6 +395,10 @@ vsb_cat(sb, "struct vrt_backend {\n"); vsb_cat(sb, " char *portname;\n"); vsb_cat(sb, " char *hostname;\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, " const unsigned char *ipv4_sockaddr;\n"); + vsb_cat(sb, " const unsigned char *ipv6_sockaddr;\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, " char *vcl_name;\n"); vsb_cat(sb, " char *ident;\n"); vsb_cat(sb, " double connect_timeout;\n"); From phk at projects.linpro.no Fri Jul 11 18:57:13 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 11 Jul 2008 20:57:13 +0200 (CEST) Subject: r2935 - trunk/varnish-cache/lib/libvcl Message-ID: <20080711185713.BB9C71EC209@projects.linpro.no> Author: phk Date: 2008-07-11 20:57:13 +0200 (Fri, 11 Jul 2008) New Revision: 2935 Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c Log: Emit backend probe data to ->fb. Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-11 10:12:52 UTC (rev 2934) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-11 18:57:13 UTC (rev 2935) @@ -341,7 +341,7 @@ ExpectErr(tl, '{'); vcc_NextToken(tl); - Fh(tl, 0, "\t.probe = {\n"); + Fb(tl, 0, "\t.probe = {\n"); while (tl->t->tok != '}') { vcc_IsField(tl, &t_field, fs); @@ -352,35 +352,35 @@ vcc_ProbeRedef(tl, &t_did, t_field); ERRCHK(tl); ExpectErr(tl, CSTR); - Fh(tl, 0, "\t\t.request =\n"); - Fh(tl, 0, "\t\t\t\"GET \" "); + Fb(tl, 0, "\t\t.request =\n"); + Fb(tl, 0, "\t\t\t\"GET \" "); EncToken(tl->fb, tl->t); - Fh(tl, 0, " \" /HTTP/1.1\\r\\n\"\n"); - Fh(tl, 0, "\t\t\t\"Connection: close\\r\\n\"\n"); - Fh(tl, 0, "\t\t\t\"\\r\\n\",\n"); + Fb(tl, 0, " \" /HTTP/1.1\\r\\n\"\n"); + Fb(tl, 0, "\t\t\t\"Connection: close\\r\\n\"\n"); + Fb(tl, 0, "\t\t\t\"\\r\\n\",\n"); vcc_NextToken(tl); } else if (vcc_IdIs(t_field, "request")) { vcc_ProbeRedef(tl, &t_did, t_field); ERRCHK(tl); ExpectErr(tl, CSTR); - Fh(tl, 0, "\t\t.request =\n"); + Fb(tl, 0, "\t\t.request =\n"); while (tl->t->tok == CSTR) { - Fh(tl, 0, "\t\t\t"); + Fb(tl, 0, "\t\t\t"); EncToken(tl->fb, tl->t); - Fh(tl, 0, " \"\\r\\n\"\n"); + Fb(tl, 0, " \"\\r\\n\"\n"); vcc_NextToken(tl); } - Fh(tl, 0, "\t\t\t\"\\r\\n\",\n"); + Fb(tl, 0, "\t\t\t\"\\r\\n\",\n"); } else if (vcc_IdIs(t_field, "timeout")) { - Fh(tl, 0, "\t\t.timeout = "); + Fb(tl, 0, "\t\t.timeout = "); vcc_TimeVal(tl); ERRCHK(tl); - Fh(tl, 0, ",\n"); + Fb(tl, 0, ",\n"); } else if (vcc_IdIs(t_field, "rate")) { - Fh(tl, 0, "\t\t.rate = "); + Fb(tl, 0, "\t\t.rate = "); vcc_TimeVal(tl); ERRCHK(tl); - Fh(tl, 0, ",\n"); + Fb(tl, 0, ",\n"); } else { vcc_ErrToken(tl, t_field); vcc_ErrWhere(tl, t_field); @@ -391,7 +391,7 @@ ExpectErr(tl, ';'); vcc_NextToken(tl); } - Fh(tl, 0, "\t},\n"); + Fb(tl, 0, "\t},\n"); ExpectErr(tl, '}'); vcc_NextToken(tl); } From phk at projects.linpro.no Fri Jul 11 19:49:21 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 11 Jul 2008 21:49:21 +0200 (CEST) Subject: r2936 - trunk/varnish-cache/bin/varnishd Message-ID: <20080711194921.22EF11EC10F@projects.linpro.no> Author: phk Date: 2008-07-11 21:49:20 +0200 (Fri, 11 Jul 2008) New Revision: 2936 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_backend.h trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Drop pseudo-automatic support for multihomed backends and require clear expression of intent in VCL. We now fail backend hostnames that resolve to multiple IPv4 or multiple IPv6 addresses, in other words, you cannot use "cnn.com" as a backend hostname specification without the compiler yelling at you: % ./varnishd -d -d -b cnn.com -a :8080 Backend host "cnn.com": resolves to multiple IPv4 addresses. Only one address is allowed. Please specify which exact address you want to use, we found these: 64.236.16.20 64.236.16.52 64.236.24.12 64.236.29.120 [...] VCL compilation failed However, you _can_ use a hostname that resolves to both an IPv4 and an IPv6 address, and the new paramter "prefer_ipv6" will determine which one we try first in such cases. The other part of this change is that we now do the DNS lookup at VCL compiletime, and only then. If your backend's DNS record (or /etc/hosts entry) changes IP#, you must reload your VCL code to notify varnish. Finer technical points: We build a bytestring representation of the sockaddr's in VCC and include them in the concept of backend identity, for an existing backend (+ connections) to be reused for a new VCL the backend must now be defined exactly the same way AND have the same resolved IPv4/IPv6 addresses. Since we never muck about with the address in the backend struct anymore, it's static for the life of the struct backend instance, we can simplify and eliminate the locking dance around our connection attempts. Also eliminate the struct vrt_backend inclusion in struct backend, and instead make the relevat fields full-blown members of struct backend. This eliminates a number of TRUST_ME() calls. This is the companion commit to #2934 which prepared the VCL compiler. Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-07-11 18:57:13 UTC (rev 2935) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-07-11 19:49:20 UTC (rev 2936) @@ -41,11 +41,9 @@ #include #include -#include #include "shmlog.h" #include "cache.h" -#include "vrt.h" #include "cache_backend.h" /* @@ -70,7 +68,7 @@ CHECK_OBJ_NOTNULL(sp->bereq->http, HTTP_MAGIC); CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); http_PrintfHeader(sp->wrk, sp->fd, sp->bereq->http, - "Host: %s", sp->backend->vrt->hostname); + "Host: %s", sp->backend->hosthdr); } /*-------------------------------------------------------------------- @@ -83,11 +81,8 @@ */ static int -VBE_TryConnect(const struct sess *sp, const struct addrinfo *ai) +VBE_TryConnect(const struct sess *sp, int pf, const struct sockaddr *sa, socklen_t salen) { - struct sockaddr_storage ss; - int fam, sockt, proto; - socklen_t alen; int s, i, tmo; char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE]; char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE]; @@ -95,47 +90,31 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC); - /* - * ai is only valid with the lock held, so copy out the bits - * we need to make the connection - */ - 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); - - /* release lock during stuff that can take a long time */ - UNLOCK(&sp->backend->mtx); - - s = socket(fam, sockt, proto); + s = socket(pf, SOCK_STREAM, 0); if (s < 0) { LOCK(&sp->backend->mtx); return (s); } tmo = params->connect_timeout; - if (sp->backend->vrt->connect_timeout > 10e-3) - tmo = sp->backend->vrt->connect_timeout * 1000; + if (sp->backend->connect_timeout > 10e-3) + tmo = sp->backend->connect_timeout * 1000; if (tmo > 0) - i = TCP_connect(s, (void *)&ss, alen, tmo); + i = TCP_connect(s, sa, salen, tmo); else - i = connect(s, (void *)&ss, alen); + i = connect(s, sa, salen); if (i != 0) { AZ(close(s)); - LOCK(&sp->backend->mtx); return (-1); } TCP_myname(s, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1); - TCP_name((void*)&ss, alen, abuf2, sizeof abuf2, pbuf2, sizeof pbuf2); + TCP_name(sa, salen, abuf2, sizeof abuf2, pbuf2, sizeof pbuf2); WSL(sp->wrk, SLT_BackendOpen, s, "%s %s %s %s %s", - sp->backend->vrt->vcl_name, abuf1, pbuf1, abuf2, pbuf2); + sp->backend->vcl_name, abuf1, pbuf1, abuf2, pbuf2); - LOCK(&sp->backend->mtx); return (s); } @@ -254,54 +233,6 @@ } } -/*-------------------------------------------------------------------- - * Try to get a socket connected to one of the addresses on the list. - * We start from the cached "last good" address and try all items on - * the list exactly once. - * - * Called with backend mutex held, but will release/acquire it. - * - * XXX: Not ready for DNS re-lookups - */ - -static int -bes_conn_try_list(const struct sess *sp, struct backend *bp) -{ - struct addrinfo *ai, *from; - int s, loops; - - CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); - - /* No addrinfo, no connection */ - if (bp->ai == NULL) - return (-1); - AN(bp->last_ai); - - /* Called with lock held */ - loops = 0; - ai = from = bp->last_ai; - while (loops == 0 || ai != from) { - - /* NB: releases/acquires backend lock */ - s = VBE_TryConnect(sp, ai); - - if (s >= 0) { - bp->last_ai = ai; - return (s); - } - - /* Try next one */ - ai = ai->ai_next; - if (ai == NULL) { - loops++; - ai = bp->ai; - } - } - /* We have tried them all, fail */ - return (-1); -} - - /*--------------------------------------------------------------------*/ static int @@ -311,10 +242,25 @@ LOCK(&bp->mtx); bp->refcount++; - s = bes_conn_try_list(sp, bp); /* releases/acquires backend lock */ - if (s < 0) + UNLOCK(&sp->backend->mtx); + + s = -1; + assert(bp->ipv6 != NULL || bp->ipv4 != NULL); + + /* release lock during stuff that can take a long time */ + + if (params->prefer_ipv6 && bp->ipv6 != NULL) + s = VBE_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len); + if (s == -1 && bp->ipv4 != NULL) + s = VBE_TryConnect(sp, PF_INET, bp->ipv4, bp->ipv4len); + if (s == -1 && !params->prefer_ipv6 && bp->ipv6 != NULL) + s = VBE_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len); + + if (s < 0) { + LOCK(&sp->backend->mtx); bp->refcount--; /* Only keep ref on success */ - UNLOCK(&bp->mtx); + UNLOCK(&bp->mtx); + } return (s); } @@ -377,7 +323,7 @@ CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); b = vc->backend; assert(vc->fd >= 0); - WSL(w, SLT_BackendClose, vc->fd, "%s", vc->backend->vrt->vcl_name); + WSL(w, SLT_BackendClose, vc->fd, "%s", vc->backend->vcl_name); i = close(vc->fd); assert(i == 0 || errno == ECONNRESET || errno == ENOTCONN); vc->fd = -1; @@ -398,7 +344,7 @@ CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC); assert(vc->fd >= 0); bp = vc->backend; - WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vrt->vcl_name); + WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); LOCK(&vc->backend->mtx); VSL_stats->backend_recycle++; VTAILQ_INSERT_HEAD(&bp->connlist, vc, list); Modified: trunk/varnish-cache/bin/varnishd/cache_backend.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.h 2008-07-11 18:57:13 UTC (rev 2935) +++ trunk/varnish-cache/bin/varnishd/cache_backend.h 2008-07-11 19:49:20 UTC (rev 2936) @@ -73,15 +73,21 @@ unsigned magic; #define BACKEND_MAGIC 0x64c4c7c6 - struct vrt_backend vrt[1]; + char *hosthdr; + char *ident; + char *vcl_name; + double connect_timeout; + uint32_t hash; VTAILQ_ENTRY(backend) list; int refcount; pthread_mutex_t mtx; - struct addrinfo *ai; - struct addrinfo *last_ai; + struct sockaddr *ipv4; + socklen_t ipv4len; + struct sockaddr *ipv6; + socklen_t ipv6len; VTAILQ_HEAD(, vbe_conn) connlist; Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2008-07-11 18:57:13 UTC (rev 2935) +++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2008-07-11 19:49:20 UTC (rev 2936) @@ -41,7 +41,6 @@ #include #include -#include #include "shmlog.h" #include "cache.h" @@ -99,9 +98,10 @@ AZ(close(vbe->fd)); VBE_ReleaseConn(vbe); } - free(TRUST_ME(b->vrt->ident)); - free(TRUST_ME(b->vrt->hostname)); - free(TRUST_ME(b->vrt->portname)); + free(b->ident); + free(b->hosthdr); + free(b->ipv4); + free(b->ipv6); b->magic = 0; free(b); VSL_stats->n_backend--; @@ -117,44 +117,17 @@ VBE_DropRefLocked(b); } -/*-------------------------------------------------------------------- - * DNS lookup of backend host/port - */ +/*--------------------------------------------------------------------*/ static void -vbe_dns_lookup(const struct cli *cli, struct backend *bp) +copy_sockaddr(struct sockaddr **sa, socklen_t *len, const unsigned char *src) { - int error; - struct addrinfo *res, hint, *old; - CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); - - memset(&hint, 0, sizeof hint); - hint.ai_family = PF_UNSPEC; - hint.ai_socktype = SOCK_STREAM; - res = NULL; - error = getaddrinfo(bp->vrt->hostname, bp->vrt->portname, - &hint, &res); - if (error) { - if (res != NULL) - freeaddrinfo(res); - /* - * We cannot point to the source code any more, it may - * be long gone from memory. We already checked over in - * the VCL compiler, so this is only relevant for refreshes. - * XXX: which we do when exactly ? - */ - cli_out(cli, "DNS(/hosts) lookup failed for (%s/%s): %s", - bp->vrt->hostname, bp->vrt->portname, gai_strerror(error)); - return; - } - LOCK(&bp->mtx); - old = bp->ai; - bp->ai = res; - bp->last_ai = res; - UNLOCK(&bp->mtx); - if (old != NULL) - freeaddrinfo(old); + assert(*src > 0); + *sa = malloc(*src); + AN(*sa); + memcpy(*sa, src + 1, *src); + *len = *src; } /*-------------------------------------------------------------------- @@ -169,25 +142,46 @@ struct backend *b; uint32_t u; - AN(vb->hostname); - AN(vb->portname); AN(vb->ident); + assert(vb->ipv4_sockaddr != NULL || vb->ipv6_sockaddr != NULL); (void)cli; ASSERT_CLI(); - u = crc32_l(vb->ident, strlen(vb->ident)); + + /* calculate a hash of (ident + ipv4_sockaddr + ipv6_sockaddr) */ + u = crc32(~0U, vb->ident, strlen(vb->ident)); + if (vb->ipv4_sockaddr != NULL) + u = crc32(u, vb->ipv4_sockaddr + 1, vb->ipv4_sockaddr[0]); + if (vb->ipv6_sockaddr != NULL) + u = crc32(u, vb->ipv6_sockaddr + 1, vb->ipv6_sockaddr[0]); + + /* Run through the list and see if we already have this backend */ VTAILQ_FOREACH(b, &backends, list) { CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); if (u != b->hash) continue; - if (strcmp(b->vrt->ident, vb->ident)) + if (strcmp(b->ident, vb->ident)) continue; + if (vb->ipv4_sockaddr != NULL && + b->ipv4len != vb->ipv4_sockaddr[0]) + continue; + if (vb->ipv6_sockaddr != NULL && + b->ipv6len != vb->ipv6_sockaddr[0]) + continue; + if (b->ipv4len != 0 && + memcmp(b->ipv4, vb->ipv4_sockaddr + 1, b->ipv4len)) + continue; + if (b->ipv6len != 0 && + memcmp(b->ipv6, vb->ipv6_sockaddr + 1, b->ipv6len)) + continue; b->refcount++; return (b); } + /* Create new backend */ ALLOC_OBJ(b, BACKEND_MAGIC); XXXAN(b); - b->magic = BACKEND_MAGIC; + MTX_INIT(&b->mtx); + b->refcount = 1; VTAILQ_INIT(&b->connlist); b->hash = u; @@ -196,17 +190,21 @@ * This backend may live longer than the VCL that instantiated it * so we cannot simply reference the VCL's copy of things. */ - REPLACE(b->vrt->ident, vb->ident); - REPLACE(b->vrt->hostname, vb->hostname); - REPLACE(b->vrt->portname, vb->portname); - REPLACE(b->vrt->vcl_name, vb->vcl_name); + REPLACE(b->ident, vb->ident); + REPLACE(b->vcl_name, vb->vcl_name); + REPLACE(b->hosthdr, vb->hostname); - b->vrt->connect_timeout = vb->connect_timeout; + b->connect_timeout = vb->connect_timeout; - MTX_INIT(&b->mtx); - b->refcount = 1; + /* + * Copy over the sockaddrs + */ + if (vb->ipv4_sockaddr != NULL) + copy_sockaddr(&b->ipv4, &b->ipv4len, vb->ipv4_sockaddr); + if (vb->ipv6_sockaddr != NULL) + copy_sockaddr(&b->ipv6, &b->ipv6len, vb->ipv6_sockaddr); - vbe_dns_lookup(cli, b); + assert(b->ipv4 != NULL || b->ipv6 != NULL); VTAILQ_INSERT_TAIL(&backends, b, list); VSL_stats->n_backend++; @@ -238,11 +236,9 @@ ASSERT_CLI(); VTAILQ_FOREACH(b, &backends, list) { CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - cli_out(cli, "%p %s/%s/%s %d\n", + cli_out(cli, "%p %s %d\n", b, - b->vrt->vcl_name, - b->vrt->hostname, - b->vrt->portname, + b->vcl_name, b->refcount); } } Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2008-07-11 18:57:13 UTC (rev 2935) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2008-07-11 19:49:20 UTC (rev 2936) @@ -166,6 +166,9 @@ /* Log local socket address to shm */ unsigned log_local_addr; + + /* Prefer IPv6 connections to backend*/ + unsigned prefer_ipv6; }; extern volatile struct params *params; Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-11 18:57:13 UTC (rev 2935) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-11 19:49:20 UTC (rev 2936) @@ -735,6 +735,11 @@ "VCL can override this default value for each backend.", 0, "400", "ms" }, + { "prefer_ipv6", tweak_bool, &master.prefer_ipv6, 0, 0, + "Prefer IPv6 address when connecting to backends which " + "have both IPv4 and IPv6 addresses.", + 0, + "off", "bool" }, { "session_linger", tweak_uint, &master.session_linger,0, UINT_MAX, "How long time the workerthread lingers on the session " From phk at projects.linpro.no Fri Jul 11 20:41:40 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 11 Jul 2008 22:41:40 +0200 (CEST) Subject: r2937 - trunk/varnish-cache/bin/varnishd Message-ID: <20080711204140.3987C1EC0B7@projects.linpro.no> Author: phk Date: 2008-07-11 22:41:39 +0200 (Fri, 11 Jul 2008) New Revision: 2937 Added: trunk/varnish-cache/bin/varnishd/cache_backend_poll.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.h trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c trunk/varnish-cache/bin/varnishd/cache_cli.c Log: Add scaffold code for backend polling. It doesn't actually do anything yet. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-11 19:49:20 UTC (rev 2936) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-11 20:41:39 UTC (rev 2937) @@ -13,6 +13,7 @@ cache_acceptor_kqueue.c \ cache_backend.c \ cache_backend_cfg.c \ + cache_backend_poll.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 2008-07-11 19:49:20 UTC (rev 2936) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-11 20:41:39 UTC (rev 2937) @@ -420,6 +420,7 @@ void VBE_free_bereq(struct bereq *bereq); void VBE_UpdateHealth(const struct sess *sp, const struct vbe_conn *, int); void VBE_AddHostHeader(const struct sess *sp); +void VBE_Poll(void); /* cache_backend_cfg.c */ void VBE_Init(void); Modified: trunk/varnish-cache/bin/varnishd/cache_backend.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.h 2008-07-11 19:49:20 UTC (rev 2936) +++ trunk/varnish-cache/bin/varnishd/cache_backend.h 2008-07-11 20:41:39 UTC (rev 2937) @@ -68,6 +68,9 @@ * */ +struct vbp_target; +struct vrt_backend_probe; + /* Backend indstance */ struct backend { unsigned magic; @@ -91,12 +94,17 @@ VTAILQ_HEAD(, vbe_conn) connlist; + struct vbp_target *probe; int health; }; +/* cache_backend.c */ +void VBE_ReleaseConn(struct vbe_conn *vc); + /* cache_backend_cfg.c */ extern MTX VBE_mtx; void VBE_DropRefLocked(struct backend *b); -/* cache_backend.c */ -void VBE_ReleaseConn(struct vbe_conn *vc); +/* cache_backend_poll.c */ +void VBP_Start(struct backend *b, struct vrt_backend_probe const *p); +void VBP_Stop(struct backend *b); Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2008-07-11 19:49:20 UTC (rev 2936) +++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2008-07-11 20:41:39 UTC (rev 2937) @@ -71,6 +71,37 @@ } /*-------------------------------------------------------------------- + */ + +static void +VBE_Nuke(struct backend *b) +{ + VTAILQ_REMOVE(&backends, b, list); + free(b->ident); + free(b->hosthdr); + free(b->ipv4); + free(b->ipv6); + b->magic = 0; + free(b); + VSL_stats->n_backend--; +} + +/*-------------------------------------------------------------------- + */ + +void +VBE_Poll(void) +{ + struct backend *b, *b2; + + ASSERT_CLI(); + VTAILQ_FOREACH_SAFE(b, &backends, list, b2) { + if (b->refcount == 0 && b->probe == NULL) + VBE_Nuke(b); + } +} + +/*-------------------------------------------------------------------- * Drop a reference to a backend. * The last reference must come from the watcher in the CLI thread, * as only that thread is allowed to clean up the backend list. @@ -91,20 +122,16 @@ return; ASSERT_CLI(); - VTAILQ_REMOVE(&backends, b, list); VTAILQ_FOREACH_SAFE(vbe, &b->connlist, list, vbe2) { VTAILQ_REMOVE(&b->connlist, vbe, list); if (vbe->fd >= 0) AZ(close(vbe->fd)); VBE_ReleaseConn(vbe); } - free(b->ident); - free(b->hosthdr); - free(b->ipv4); - free(b->ipv6); - b->magic = 0; - free(b); - VSL_stats->n_backend--; + if (b->probe != NULL) + VBP_Stop(b); + else + VBE_Nuke(b); } void @@ -206,6 +233,7 @@ assert(b->ipv4 != NULL || b->ipv6 != NULL); + VBP_Start(b, &vb->probe); VTAILQ_INSERT_TAIL(&backends, b, list); VSL_stats->n_backend++; return (b); Added: trunk/varnish-cache/bin/varnishd/cache_backend_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_poll.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2008-07-11 20:41:39 UTC (rev 2937) @@ -0,0 +1,114 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2008 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: cache_backend_cfg.c 2905 2008-07-08 10:09:03Z phk $ + * + * Poll backends for collection of health statistics + * + * We co-opt threads from the worker pool for probing the backends, + * but we want to avoid a potentially messy cleanup operation when we + * retire the backend, so the thread owns the health information, which + * the backend references, rather than the other way around. + * + */ + +#include "config.h" + +#include +#include +#include +#include +#include + +#include + +#include "shmlog.h" +#include "cache.h" +#include "mgt_event.h" +#include "vrt.h" +#include "cache_backend.h" + +struct vbp_target { + unsigned magic; +#define VBP_TARGET_MAGIC 0x6b7cb656 + + struct backend *backend; + struct workreq wrq; + int stop; +}; + +static void +vbp_wrk_poll_backend(struct worker *w, void *priv) +{ + struct vbp_target *vt; + + (void)w; + CAST_OBJ_NOTNULL(vt, priv, VBP_TARGET_MAGIC); + THR_Name("backend poll"); + + while (!vt->stop) { + printf("Poke backend %s\n", vt->backend->vcl_name); + sleep(1); + } + vt->backend->probe = NULL; + FREE_OBJ(vt); + THR_Name("cache-worker"); +} + +void +VBP_Start(struct backend *b, struct vrt_backend_probe const *p) +{ + struct vbp_target *vt; + + ASSERT_CLI(); + + /* Is probing even configured ? */ + if (p->request == NULL) + return; + + ALLOC_OBJ(vt, VBP_TARGET_MAGIC); + AN(vt); + vt->backend = b; + b->probe = vt; + + vt->wrq.func = vbp_wrk_poll_backend; + vt->wrq.priv = vt; + if (WRK_Queue(&vt->wrq) == 0) + return; + assert(0 == __LINE__); + b->probe = NULL; + FREE_OBJ(vt); +} + +void +VBP_Stop(struct backend *b) +{ + if (b->probe == NULL) + return; + b->probe->stop = 1; +} Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_cli.c 2008-07-11 19:49:20 UTC (rev 2936) +++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2008-07-11 20:41:39 UTC (rev 2937) @@ -103,6 +103,7 @@ cli = priv; VSL(SLT_CLI, 0, "Rd %s", p); VCL_Poll(); + VBE_Poll(); vsb_clear(cli->sb); LOCK(&cli_mtx); cli_dispatch(cli, ccf_master_cli, p); From phk at projects.linpro.no Fri Jul 11 21:02:06 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 11 Jul 2008 23:02:06 +0200 (CEST) Subject: r2938 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl Message-ID: <20080711210206.106A21EC209@projects.linpro.no> Author: phk Date: 2008-07-11 23:02:05 +0200 (Fri, 11 Jul 2008) New Revision: 2938 Added: trunk/varnish-cache/bin/varnishtest/tests/v00008.vtc Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Add a backend property ".host_header" to set default content of Host: header if client didn't provide one. If .host_header is not specified, it defaults to .host. Add testcase for this logic. (Incidental change: Use "interval" instead of "rate" for backend pollers.) Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2008-07-11 20:41:39 UTC (rev 2937) +++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2008-07-11 21:02:05 UTC (rev 2938) @@ -219,7 +219,7 @@ */ REPLACE(b->ident, vb->ident); REPLACE(b->vcl_name, vb->vcl_name); - REPLACE(b->hosthdr, vb->hostname); + REPLACE(b->hosthdr, vb->hosthdr); b->connect_timeout = vb->connect_timeout; Added: trunk/varnish-cache/bin/varnishtest/tests/v00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00008.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00008.vtc 2008-07-11 21:02:05 UTC (rev 2938) @@ -0,0 +1,44 @@ +# $Id$ + +test "Test host header specification" + +server s1 { + rxreq + expect req.url == "/foo" + expect req.http.host == "snafu" + txresp -body "foo1" + + rxreq + expect req.url == "/bar" + expect req.http.host == "127.0.0.1" + txresp -body "foo1" +} -start + +varnish v1 -vcl+backend { } -start + +client c1 { + txreq -url "/foo" -hdr "Host: snafu" + rxresp + txreq -url "/bar" + rxresp +} -run + +server s2 -listen 127.0.0.1:9180 { + rxreq + expect req.url == "/barf" + expect req.http.host == "FOObar" + txresp -body "foo1" +} -start + +varnish v1 -vcl { + backend b1 { + .host = "127.0.0.1"; + .port = "9180"; + .host_header = "FOObar"; + } +} + +client c1 { + txreq -url "/barf" + rxresp +} -run Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2008-07-11 20:41:39 UTC (rev 2937) +++ trunk/varnish-cache/include/vrt.h 2008-07-11 21:02:05 UTC (rev 2938) @@ -48,21 +48,21 @@ struct vrt_backend_probe { char *request; double timeout; - double rate; + double interval; }; /* * A backend is a host+port somewhere on the network */ struct vrt_backend { - char *portname; - char *hostname; + char *vcl_name; + char *ident; + char *hosthdr; + const unsigned char *ipv4_sockaddr; const unsigned char *ipv6_sockaddr; - char *vcl_name; - char *ident; double connect_timeout; struct vrt_backend_probe probe; }; Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-11 20:41:39 UTC (rev 2937) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-11 21:02:05 UTC (rev 2938) @@ -336,7 +336,12 @@ struct token *t_field; struct token *t_did = NULL; - fs = vcc_FldSpec(tl, "?url", "?request", "?timeout", "?rate", NULL); + fs = vcc_FldSpec(tl, + "?url", + "?request", + "?timeout", + "?interval", + NULL); ExpectErr(tl, '{'); vcc_NextToken(tl); @@ -376,8 +381,8 @@ vcc_TimeVal(tl); ERRCHK(tl); Fb(tl, 0, ",\n"); - } else if (vcc_IdIs(t_field, "rate")) { - Fb(tl, 0, "\t\t.rate = "); + } else if (vcc_IdIs(t_field, "interval")) { + Fb(tl, 0, "\t\t.interval = "); vcc_TimeVal(tl); ERRCHK(tl); Fb(tl, 0, ",\n"); @@ -421,12 +426,17 @@ struct token *t_first; struct token *t_host = NULL; struct token *t_port = NULL; + struct token *t_hosthdr = NULL; const char *ep; struct fld_spec *fs; struct vsb *vsb; fs = vcc_FldSpec(tl, - "!host", "?port", "?connect_timeout", "?probe", NULL); + "!host", + "?port", + "?host_header", + "?connect_timeout", + "?probe", NULL); t_first = tl->t; ExpectErr(tl, '{'); @@ -439,6 +449,11 @@ *nbh = tl->nbackend_host++; Fb(tl, 0, "\nstatic const struct vrt_backend bh_%d = {\n", *nbh); + Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(name)); + if (serial) + Fb(tl, 0, "[%d]", serial); + Fb(tl, 0, "\",\n"); + /* Check for old syntax */ if (tl->t->tok == ID && vcc_IdIs(tl->t, "set")) { vsb_printf(tl->sb, @@ -471,6 +486,13 @@ vcc_NextToken(tl); ExpectErr(tl, ';'); vcc_NextToken(tl); + } else if (vcc_IdIs(t_field, "host_header")) { + ExpectErr(tl, CSTR); + assert(tl->t->dec != NULL); + t_hosthdr = tl->t; + vcc_NextToken(tl); + ExpectErr(tl, ';'); + vcc_NextToken(tl); } else if (vcc_IdIs(t_field, "connect_timeout")) { Fb(tl, 0, "\t.connect_timeout = "); vcc_TimeVal(tl); @@ -499,9 +521,6 @@ vcc_ErrWhere(tl, t_host); return; } - Fb(tl, 0, "\t.hostname = "); - EncToken(tl->fb, t_host); - Fb(tl, 0, ",\n"); /* Check that the portname makes sense */ if (t_port != NULL) { @@ -512,22 +531,28 @@ vcc_ErrWhere(tl, t_port); return; } - Fb(tl, 0, "\t.portname = "); - EncToken(tl->fb, t_port); - Fb(tl, 0, ",\n"); Emit_Sockaddr(tl, t_host, t_port->dec); } else { - Fb(tl, 0, "\t.portname = \"80\",\n"); Emit_Sockaddr(tl, t_host, "80"); } ERRCHK(tl); ExpectErr(tl, '}'); + + /* We have parsed it all, emit the ident string */ vcc_EmitBeIdent(tl->fb, name, qual, serial, t_first, tl->t); - Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(name)); - if (serial) - Fb(tl, 0, "[%d]", serial); - Fb(tl, 0, "\"\n};\n"); + + /* Emit the hosthdr field, fall back to .host if not specified */ + Fb(tl, 0, "\t.hosthdr = "); + if (t_hosthdr != NULL) + EncToken(tl->fb, t_hosthdr); + else + EncToken(tl->fb, t_host); + Fb(tl, 0, ",\n"); + + /* Close the struct */ + Fb(tl, 0, "};\n"); + vcc_NextToken(tl); tl->fb = NULL; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-11 20:41:39 UTC (rev 2937) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-11 21:02:05 UTC (rev 2938) @@ -386,21 +386,21 @@ vsb_cat(sb, "struct vrt_backend_probe {\n"); vsb_cat(sb, " char *request;\n"); vsb_cat(sb, " double timeout;\n"); - vsb_cat(sb, " double rate;\n"); + vsb_cat(sb, " double interval;\n"); vsb_cat(sb, "};\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/*\n"); vsb_cat(sb, " * A backend is a host+port somewhere on the network\n"); vsb_cat(sb, " */\n"); vsb_cat(sb, "struct vrt_backend {\n"); - vsb_cat(sb, " char *portname;\n"); - vsb_cat(sb, " char *hostname;\n"); + vsb_cat(sb, " char *vcl_name;\n"); + vsb_cat(sb, " char *ident;\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, " char *hosthdr;\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, " const unsigned char *ipv4_sockaddr;\n"); vsb_cat(sb, " const unsigned char *ipv6_sockaddr;\n"); vsb_cat(sb, "\n"); - vsb_cat(sb, " char *vcl_name;\n"); - vsb_cat(sb, " char *ident;\n"); vsb_cat(sb, " double connect_timeout;\n"); vsb_cat(sb, " struct vrt_backend_probe probe;\n"); vsb_cat(sb, "};\n"); From phk at projects.linpro.no Fri Jul 11 21:33:27 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 11 Jul 2008 23:33:27 +0200 (CEST) Subject: r2939 - in trunk/varnish-cache: include lib/libvarnish Message-ID: <20080711213327.40DB41EC10F@projects.linpro.no> Author: phk Date: 2008-07-11 23:33:26 +0200 (Fri, 11 Jul 2008) New Revision: 2939 Added: trunk/varnish-cache/include/vev.h trunk/varnish-cache/lib/libvarnish/vev.c Modified: trunk/varnish-cache/include/Makefile.am trunk/varnish-cache/lib/libvarnish/Makefile.am Log: Copy mgt_event.[ch] from varnishd into libvarnish and give it the prefix "VEV". This is a general purpose eventmanager and as such should live in the library where other programs can get at it. Modified: trunk/varnish-cache/include/Makefile.am =================================================================== --- trunk/varnish-cache/include/Makefile.am 2008-07-11 21:02:05 UTC (rev 2938) +++ trunk/varnish-cache/include/Makefile.am 2008-07-11 21:33:26 UTC (rev 2939) @@ -32,6 +32,7 @@ vcl.h \ vcl_returns.h \ vct.h \ + vev.h \ vlu.h \ vbm.h \ vrt.h \ Copied: trunk/varnish-cache/include/vev.h (from rev 2913, trunk/varnish-cache/bin/varnishd/mgt_event.h) =================================================================== --- trunk/varnish-cache/include/vev.h (rev 0) +++ trunk/varnish-cache/include/vev.h 2008-07-11 21:33:26 UTC (rev 2939) @@ -0,0 +1,79 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2008 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +#include + +#include "vqueue.h" + +struct vev; +struct vev_base; + +typedef int vev_cb_f(const struct vev *, int what); + +struct vev { + unsigned magic; +#define VEV_MAGIC 0x46bbd419 + + /* pub */ + const char *name; + int fd; + unsigned fd_flags; +#define EV_RD POLLIN +#define EV_WR POLLOUT +#define EV_ERR POLLERR +#define EV_HUP POLLHUP +#define EV_GONE POLLNVAL +#define EV_SIG -1 + int sig; + unsigned sig_flags; + double timeout; + vev_cb_f *callback; + void *priv; + + /* priv */ + double __when; + VTAILQ_ENTRY(vev) __list; + unsigned __binheap_idx; + unsigned __privflags; + struct vev_base *__vevb; + int __poll_idx; +}; + +struct vev_base *vev_new_base(void); +void vev_destroy_base(struct vev_base *evb); + +struct vev *vev_new(void); + +int vev_add(struct vev_base *evb, struct vev *e); +void vev_del(struct vev_base *evb, struct vev *e); + +int vev_schedule_one(struct vev_base *evb); +int vev_schedule(struct vev_base *evb); Property changes on: trunk/varnish-cache/include/vev.h ___________________________________________________________________ Name: svn:keywords + Id Name: svn:mergeinfo + Modified: trunk/varnish-cache/lib/libvarnish/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnish/Makefile.am 2008-07-11 21:02:05 UTC (rev 2938) +++ trunk/varnish-cache/lib/libvarnish/Makefile.am 2008-07-11 21:33:26 UTC (rev 2939) @@ -16,6 +16,7 @@ time.c \ vct.c \ version.c \ + vev.c \ vlu.c \ vpf.c \ vsb.c \ Copied: trunk/varnish-cache/lib/libvarnish/vev.c (from rev 2913, trunk/varnish-cache/bin/varnishd/mgt_event.c) =================================================================== --- trunk/varnish-cache/lib/libvarnish/vev.c (rev 0) +++ trunk/varnish-cache/lib/libvarnish/vev.c 2008-07-11 21:33:26 UTC (rev 2939) @@ -0,0 +1,521 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2008 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libvarnish.h" +#include "vev.h" +#include "miniobj.h" +#include "binary_heap.h" + +#undef DEBUG_EVENTS + +/* INFTIM indicates an infinite timeout for poll(2) */ +#ifndef INFTIM +#define INFTIM -1 +#endif + +struct vevsig { + struct vev_base *vevb; + struct vev *vev; + struct sigaction sigact; + unsigned char happened; +}; + +static struct vevsig *vev_sigs; +static int vev_nsig; + +struct vev_base { + unsigned magic; +#define VEV_BASE_MAGIC 0x477bcf3d + VTAILQ_HEAD(,vev) events; + struct pollfd *pfd; + unsigned npfd; + unsigned lpfd; + struct binheap *binheap; + unsigned char compact_pfd; + unsigned char disturbed; + unsigned psig; + pthread_t thread; +#ifdef DEBUG_EVENTS + FILE *debug; +#endif +}; + +/*--------------------------------------------------------------------*/ + +#ifdef DEBUG_EVENTS +#define DBG(evb, ...) do { \ + if ((evb)->debug != NULL) \ + fprintf((evb)->debug, __VA_ARGS__); \ + } while (0); +#else +#define DBG(evb, ...) /* ... */ +#endif + +/*--------------------------------------------------------------------*/ + +static void +vev_bh_update(void *priv, void *a, unsigned u) +{ + struct vev_base *evb; + struct vev *e; + + CAST_OBJ_NOTNULL(evb, priv, VEV_BASE_MAGIC); + CAST_OBJ_NOTNULL(e, a, VEV_MAGIC); + e->__binheap_idx = u; +} + +static int +vev_bh_cmp(void *priv, void *a, void *b) +{ + struct vev_base *evb; + struct vev *ea, *eb; + + CAST_OBJ_NOTNULL(evb, priv, VEV_BASE_MAGIC); + CAST_OBJ_NOTNULL(ea, a, VEV_MAGIC); + CAST_OBJ_NOTNULL(eb, b, VEV_MAGIC); + return (ea->__when < eb->__when); +} + +/*--------------------------------------------------------------------*/ + +static int +vev_get_pfd(struct vev_base *evb) +{ + unsigned u; + void *p; + + if (evb->lpfd + 1 < evb->npfd) + return (0); + + if (evb->npfd < 8) + u = 8; + else if (evb->npfd > 256) + u = evb->npfd + 256; + else + u = evb->npfd * 2; + p = realloc(evb->pfd, sizeof *evb->pfd * u); + if (p == NULL) + return (1); + evb->npfd = u; + evb->pfd = p; + return (0); +} + +/*--------------------------------------------------------------------*/ + +static int +vev_get_sig(int sig) +{ + struct vevsig *os; + + if (sig < vev_nsig) + return (0); + + os = calloc(sizeof *os, (sig + 1)); + if (os == NULL) + return (ENOMEM); + + memcpy(os, vev_sigs, vev_nsig * sizeof *os); + + free(vev_sigs); + vev_sigs = os; + vev_nsig = sig + 1; + + return (0); +} + +/*--------------------------------------------------------------------*/ + +static void +vev_sighandler(int sig) +{ + struct vevsig *es; + + assert(sig < vev_nsig); + assert(vev_sigs != NULL); + es = &vev_sigs[sig]; + if (!es->happened) + es->vevb->psig++; + es->happened = 1; +} + +/*--------------------------------------------------------------------*/ + +struct vev_base * +vev_new_base(void) +{ + struct vev_base *evb; + + evb = calloc(sizeof *evb, 1); + if (evb == NULL) + return (evb); + if (vev_get_pfd(evb)) { + free(evb); + return (NULL); + } + evb->magic = VEV_BASE_MAGIC; + VTAILQ_INIT(&evb->events); + evb->binheap = binheap_new(evb, vev_bh_cmp, vev_bh_update); + evb->thread = pthread_self(); +#ifdef DEBUG_EVENTS + evb->debug = fopen("/tmp/_.events", "w"); + AN(evb->debug); + setbuf(evb->debug, NULL); + DBG(evb, "\n\nStart debugging\n"); +#endif + return (evb); +} + +/*--------------------------------------------------------------------*/ + +void +vev_destroy_base(struct vev_base *evb) +{ + CHECK_OBJ_NOTNULL(evb, VEV_BASE_MAGIC); + assert(evb->thread == pthread_self()); + evb->magic = 0; + free(evb); +} + +/*--------------------------------------------------------------------*/ + +struct vev * +vev_new(void) +{ + struct vev *e; + + e = calloc(sizeof *e, 1); + if (e != NULL) { + e->fd = -1; + } + return (e); +} + +/*--------------------------------------------------------------------*/ + +int +vev_add(struct vev_base *evb, struct vev *e) +{ + struct vevsig *es; + + CHECK_OBJ_NOTNULL(evb, VEV_BASE_MAGIC); + assert(e->magic != VEV_MAGIC); + assert(e->callback != NULL); + assert(e->sig >= 0); + assert(e->timeout >= 0.0); + assert(e->fd < 0 || e->fd_flags); + assert(evb->thread == pthread_self()); + DBG(evb, "ev_add(%p) fd = %d\n", e, e->fd); + + if (e->sig > 0 && vev_get_sig(e->sig)) + return (ENOMEM); + + if (e->fd >= 0 && vev_get_pfd(evb)) + return (ENOMEM); + + if (e->sig > 0) { + es = &vev_sigs[e->sig]; + if (es->vev != NULL) + return (EBUSY); + assert(es->happened == 0); + es->vev = e; + es->vevb = evb; + es->sigact.sa_flags = e->sig_flags; + es->sigact.sa_handler = vev_sighandler; + } else { + es = NULL; + } + + if (e->fd >= 0) { + assert(evb->lpfd < evb->npfd); + evb->pfd[evb->lpfd].fd = e->fd; + evb->pfd[evb->lpfd].events = + e->fd_flags & (EV_RD|EV_WR|EV_ERR|EV_HUP); + e->__poll_idx = evb->lpfd; + evb->lpfd++; + DBG(evb, "... pidx = %d lpfd = %d\n", + e->__poll_idx, evb->lpfd); + } else + e->__poll_idx = -1; + + e->magic = VEV_MAGIC; /* before binheap_insert() */ + + if (e->timeout != 0.0) { + e->__when += TIM_mono() + e->timeout; + binheap_insert(evb->binheap, e); + assert(e->__binheap_idx > 0); + DBG(evb, "... bidx = %d\n", e->__binheap_idx); + } else { + e->__when = 0.0; + e->__binheap_idx = 0; + } + + e->__vevb = evb; + e->__privflags = 0; + if (e->fd < 0) + VTAILQ_INSERT_TAIL(&evb->events, e, __list); + else + VTAILQ_INSERT_HEAD(&evb->events, e, __list); + + if (e->sig > 0) { + assert(es != NULL); + assert(sigaction(e->sig, &es->sigact, NULL) == 0); + } + + return (0); +} + +/*--------------------------------------------------------------------*/ + +void +vev_del(struct vev_base *evb, struct vev *e) +{ + struct vevsig *es; + + CHECK_OBJ_NOTNULL(evb, VEV_BASE_MAGIC); + CHECK_OBJ_NOTNULL(e, VEV_MAGIC); + DBG(evb, "ev_del(%p) fd = %d\n", e, e->fd); + assert(evb == e->__vevb); + assert(evb->thread == pthread_self()); + + if (e->__binheap_idx != 0) + binheap_delete(evb->binheap, e->__binheap_idx); + assert(e->__binheap_idx == 0); + + if (e->fd >= 0) { + DBG(evb, "... pidx = %d\n", e->__poll_idx); + evb->pfd[e->__poll_idx].fd = -1; + if (e->__poll_idx == evb->lpfd - 1) + evb->lpfd--; + else + evb->compact_pfd++; + e->fd = -1; + DBG(evb, "... lpfd = %d\n", evb->lpfd); + } + + if (e->sig > 0) { + assert(e->sig < vev_nsig); + es = &vev_sigs[e->sig]; + assert(es->vev == e); + es->vev = NULL; + es->vevb = NULL; + es->sigact.sa_flags = e->sig_flags; + es->sigact.sa_handler = SIG_DFL; + assert(sigaction(e->sig, &es->sigact, NULL) == 0); + es->happened = 0; + } + + VTAILQ_REMOVE(&evb->events, e, __list); + + e->magic = 0; + e->__vevb = NULL; + + evb->disturbed = 1; +} + +/*--------------------------------------------------------------------*/ + +int +vev_schedule(struct vev_base *evb) +{ + int i; + + CHECK_OBJ_NOTNULL(evb, VEV_BASE_MAGIC); + assert(evb->thread == pthread_self()); + do + i = vev_schedule_one(evb); + while (i == 1); + return (i); +} + +/*--------------------------------------------------------------------*/ + +static void +vev_compact_pfd(struct vev_base *evb) +{ + unsigned u; + struct pollfd *p; + struct vev *ep; + int lfd; + + DBG(evb, "compact_pfd() lpfd = %d\n", evb->lpfd); + p = evb->pfd; + for (u = 0; u < evb->lpfd; u++, p++) { + DBG(evb, "...[%d] fd = %d\n", u, p->fd); + if (p->fd >= 0) + continue; + if (u == evb->lpfd - 1) + break; + lfd = evb->pfd[evb->lpfd - 1].fd; + VTAILQ_FOREACH(ep, &evb->events, __list) + if (ep->fd == lfd) + break; + AN(ep); + DBG(evb, "...[%d] move %p pidx %d\n", u, ep, ep->__poll_idx); + *p = evb->pfd[--evb->lpfd]; + ep->__poll_idx = u; + } + evb->lpfd = u; + evb->compact_pfd = 0; + DBG(evb, "... lpfd = %d\n", evb->lpfd); +} + +/*--------------------------------------------------------------------*/ + +static int +vev_sched_timeout(struct vev_base *evb, struct vev *e, double t) +{ + int i; + + + i = e->callback(e, 0); + if (i) { + vev_del(evb, e); + free(e); + } else { + e->__when = t + e->timeout; + binheap_delete(evb->binheap, e->__binheap_idx); + binheap_insert(evb->binheap, e); + } + return (1); +} + +static int +vev_sched_signal(struct vev_base *evb) +{ + int i, j; + struct vevsig *es; + struct vev *e; + + es = vev_sigs; + for (j = 0; j < vev_nsig; j++, es++) { + if (!es->happened || es->vevb != evb) + continue; + evb->psig--; + es->happened = 0; + e = es->vev; + assert(e != NULL); + i = e->callback(e, EV_SIG); + if (i) { + vev_del(evb, e); + free(e); + } + } + return (1); +} + +int +vev_schedule_one(struct vev_base *evb) +{ + double t; + struct vev *e, *e2, *e3; + int i, j, tmo; + struct pollfd *pfd; + + CHECK_OBJ_NOTNULL(evb, VEV_BASE_MAGIC); + assert(evb->thread == pthread_self()); + e = binheap_root(evb->binheap); + if (e != NULL) { + CHECK_OBJ_NOTNULL(e, VEV_MAGIC); + assert(e->__binheap_idx == 1); + t = TIM_mono(); + if (e->__when <= t) + return (vev_sched_timeout(evb, e, t)); + tmo = (int)((e->__when - t) * 1e3); + if (tmo == 0) + tmo = 1; + } else + tmo = INFTIM; + + if (evb->compact_pfd) + vev_compact_pfd(evb); + + if (tmo == INFTIM && evb->lpfd == 0) + return (0); + + if (evb->psig) + return (vev_sched_signal(evb)); + assert(evb->lpfd < evb->npfd); + i = poll(evb->pfd, evb->lpfd, tmo); + if(i == -1 && errno == EINTR) + return (vev_sched_signal(evb)); + if (i == 0) { + assert(e != NULL); + t = TIM_mono(); + if (e->__when <= t) + return (vev_sched_timeout(evb, e, t)); + } + evb->disturbed = 0; + VTAILQ_FOREACH_SAFE(e, &evb->events, __list, e2) { + if (i == 0) + break; + if (e->fd < 0) + continue; + assert(e->__poll_idx < evb->lpfd); + pfd = &evb->pfd[e->__poll_idx]; + assert(pfd->fd == e->fd); + if (!pfd->revents) + continue; + DBG(evb, "callback(%p) fd = %d what = 0x%x pidx = %d\n", + e, e->fd, pfd->revents, e->__poll_idx); + j = e->callback(e, pfd->revents); + i--; + if (evb->disturbed) { + VTAILQ_FOREACH(e3, &evb->events, __list) { + if (e3 == e) { + e3 = VTAILQ_NEXT(e, __list); + break; + } else if (e3 == e2) + break; + } + e2 = e3; + evb->disturbed = 0; + } + if (j) { + vev_del(evb, e); + evb->disturbed = 0; + free(e); + } + } + assert(i == 0); + return (1); +} Property changes on: trunk/varnish-cache/lib/libvarnish/vev.c ___________________________________________________________________ Name: svn:keywords + Id Name: svn:mergeinfo + From phk at projects.linpro.no Fri Jul 11 21:34:18 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 11 Jul 2008 23:34:18 +0200 (CEST) Subject: r2940 - trunk/varnish-cache/bin/varnishd Message-ID: <20080711213418.D43D61EC0B7@projects.linpro.no> Author: phk Date: 2008-07-11 23:34:17 +0200 (Fri, 11 Jul 2008) New Revision: 2940 Removed: trunk/varnish-cache/bin/varnishd/mgt_event.c trunk/varnish-cache/bin/varnishd/mgt_event.h Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache_backend_poll.c trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/mgt_cli.c Log: Retire mgt_event.[ch] and use instead the (new) copy of it in libvarnish. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-11 21:33:26 UTC (rev 2939) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-11 21:34:17 UTC (rev 2940) @@ -43,7 +43,6 @@ instance.c \ mgt_child.c \ mgt_cli.c \ - mgt_event.c \ mgt_param.c \ mgt_vcc.c \ rfc2616.c \ @@ -63,7 +62,6 @@ heritage.h \ mgt.h \ mgt_cli.h \ - mgt_event.h \ steps.h \ stevedore.h Modified: trunk/varnish-cache/bin/varnishd/cache_backend_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2008-07-11 21:33:26 UTC (rev 2939) +++ trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2008-07-11 21:34:17 UTC (rev 2940) @@ -49,7 +49,6 @@ #include "shmlog.h" #include "cache.h" -#include "mgt_event.h" #include "vrt.h" #include "cache_backend.h" Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2008-07-11 21:33:26 UTC (rev 2939) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2008-07-11 21:34:17 UTC (rev 2940) @@ -36,7 +36,7 @@ struct cli; -extern struct evbase *mgt_evb; +extern struct vev_base *mgt_evb; /* mgt_child.c */ void mgt_run(int dflag, const char *T_arg); Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-07-11 21:33:26 UTC (rev 2939) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-07-11 21:34:17 UTC (rev 2940) @@ -54,7 +54,7 @@ #include "cli.h" #include "cli_priv.h" #include "mgt_cli.h" -#include "mgt_event.h" +#include "vev.h" #include "vlu.h" #include "vsb.h" #include "vss.h" @@ -85,9 +85,9 @@ [CH_DIED] = "died, (restarting)", }; -struct evbase *mgt_evb; -static struct ev *ev_poker; -static struct ev *ev_listen; +struct vev_base *mgt_evb; +static struct vev *ev_poker; +static struct vev *ev_listen; static struct vlu *vlu; /*-------------------------------------------------------------------- @@ -136,7 +136,7 @@ /*--------------------------------------------------------------------*/ static int -child_listener(const struct ev *e, int what) +child_listener(const struct vev *e, int what) { (void)e; @@ -154,7 +154,7 @@ /*--------------------------------------------------------------------*/ static int -child_poker(const struct ev *e, int what) +child_poker(const struct vev *e, int what) { (void)e; @@ -228,7 +228,7 @@ pid_t pid; unsigned u; char *p; - struct ev *e; + struct vev *e; int i, cp[2]; if (child_state != CH_STOPPED && child_state != CH_DIED) @@ -316,23 +316,23 @@ AN(vlu); AZ(ev_listen); - e = ev_new(); + e = vev_new(); XXXAN(e); e->fd = child_output; e->fd_flags = EV_RD; e->name = "Child listener"; e->callback = child_listener; - AZ(ev_add(mgt_evb, e)); + AZ(vev_add(mgt_evb, e)); ev_listen = e; AZ(ev_poker); if (params->ping_interval > 0) { - e = ev_new(); + e = vev_new(); XXXAN(e); e->timeout = params->ping_interval; e->callback = child_poker; e->name = "child poker"; - AZ(ev_add(mgt_evb, e)); + AZ(vev_add(mgt_evb, e)); ev_poker = e; } @@ -361,7 +361,7 @@ REPORT0(LOG_DEBUG, "Stopping Child"); if (ev_poker != NULL) { - ev_del(mgt_evb, ev_poker); + vev_del(mgt_evb, ev_poker); free(ev_poker); } ev_poker = NULL; @@ -376,7 +376,7 @@ /*--------------------------------------------------------------------*/ static int -mgt_sigchld(const struct ev *e, int what) +mgt_sigchld(const struct vev *e, int what) { int status; struct vsb *vsb; @@ -386,7 +386,7 @@ (void)what; if (ev_poker != NULL) { - ev_del(mgt_evb, ev_poker); + vev_del(mgt_evb, ev_poker); free(ev_poker); } ev_poker = NULL; @@ -421,7 +421,7 @@ } if (ev_listen != NULL) { - ev_del(mgt_evb, ev_listen); + vev_del(mgt_evb, ev_listen); free(ev_listen); ev_listen = NULL; } @@ -443,7 +443,7 @@ /*--------------------------------------------------------------------*/ static int -mgt_sigint(const struct ev *e, int what) +mgt_sigint(const struct vev *e, int what) { (void)e; @@ -465,12 +465,12 @@ mgt_run(int dflag, const char *T_arg) { struct sigaction sac; - struct ev *e; + struct vev *e; int i; mgt_pid = getpid(); - mgt_evb = ev_new_base(); + mgt_evb = vev_new_base(); XXXAN(mgt_evb); if (dflag) @@ -479,27 +479,27 @@ if (T_arg) mgt_cli_telnet(dflag, T_arg); - e = ev_new(); + e = vev_new(); XXXAN(e); e->sig = SIGTERM; e->callback = mgt_sigint; e->name = "mgt_sigterm"; - AZ(ev_add(mgt_evb, e)); + AZ(vev_add(mgt_evb, e)); - e = ev_new(); + e = vev_new(); XXXAN(e); e->sig = SIGINT; e->callback = mgt_sigint; e->name = "mgt_sigint"; - AZ(ev_add(mgt_evb, e)); + AZ(vev_add(mgt_evb, e)); - e = ev_new(); + e = vev_new(); XXXAN(e); e->sig = SIGCHLD; e->sig_flags = SA_NOCLDSTOP; e->callback = mgt_sigchld; e->name = "mgt_sigchild"; - AZ(ev_add(mgt_evb, e)); + AZ(vev_add(mgt_evb, e)); setproctitle("Varnish-Mgr %s", heritage.name); @@ -518,9 +518,9 @@ fprintf(stderr, "Debugging mode, enter \"start\" to start child\n"); - i = ev_schedule(mgt_evb); + i = vev_schedule(mgt_evb); if (i != 0) - REPORT(LOG_ERR, "ev_schedule() = %d", i); + REPORT(LOG_ERR, "vev_schedule() = %d", i); REPORT0(LOG_ERR, "manager dies"); exit(2); Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2008-07-11 21:33:26 UTC (rev 2939) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2008-07-11 21:34:17 UTC (rev 2940) @@ -56,7 +56,7 @@ #include "heritage.h" #include "mgt.h" #include "mgt_cli.h" -#include "mgt_event.h" +#include "vev.h" #include "shmlog.h" #include "vlu.h" @@ -66,7 +66,7 @@ struct telnet { int fd; - struct ev *ev; + struct vev *ev; VTAILQ_ENTRY(telnet) list; }; @@ -221,7 +221,7 @@ struct cli_port { unsigned magic; #define CLI_PORT_MAGIC 0x5791079f - struct ev *ev; + struct vev *ev; int fdi; int fdo; int verbose; @@ -335,7 +335,7 @@ */ static int -mgt_cli_callback(const struct ev *e, int what) +mgt_cli_callback(const struct vev *e, int what) { struct cli_port *cp; @@ -378,7 +378,7 @@ cp->ev->fd_flags = EV_RD; cp->ev->callback = mgt_cli_callback; cp->ev->priv = cp; - AZ(ev_add(mgt_evb, cp->ev)); + AZ(vev_add(mgt_evb, cp->ev)); } /*--------------------------------------------------------------------*/ @@ -424,7 +424,7 @@ } static int -telnet_accept(const struct ev *ev, int what) +telnet_accept(const struct vev *ev, int what) { struct sockaddr_storage addr; socklen_t addrlen; @@ -476,12 +476,12 @@ sock = VSS_listen(ta[i], 10); assert(sock >= 0); tn = telnet_new(sock); - tn->ev = ev_new(); + tn->ev = vev_new(); XXXAN(tn->ev); tn->ev->fd = sock; tn->ev->fd_flags = POLLIN; tn->ev->callback = telnet_accept; - AZ(ev_add(mgt_evb, tn->ev)); + AZ(vev_add(mgt_evb, tn->ev)); free(ta[i]); ta[i] = NULL; } Deleted: trunk/varnish-cache/bin/varnishd/mgt_event.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_event.c 2008-07-11 21:33:26 UTC (rev 2939) +++ trunk/varnish-cache/bin/varnishd/mgt_event.c 2008-07-11 21:34:17 UTC (rev 2940) @@ -1,521 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "mgt.h" -#include "mgt_event.h" -#include "miniobj.h" -#include "binary_heap.h" - -#undef DEBUG_EVENTS - -/* INFTIM indicates an infinite timeout for poll(2) */ -#ifndef INFTIM -#define INFTIM -1 -#endif - -struct evsig { - struct evbase *evb; - struct ev *ev; - struct sigaction sigact; - unsigned char happened; -}; - -static struct evsig *ev_sigs; -static int ev_nsig; - -struct evbase { - unsigned magic; -#define EVBASE_MAGIC 0x0cfd976f - VTAILQ_HEAD(,ev) events; - struct pollfd *pfd; - unsigned npfd; - unsigned lpfd; - struct binheap *binheap; - unsigned char compact_pfd; - unsigned char disturbed; - unsigned psig; - pthread_t thread; -#ifdef DEBUG_EVENTS - FILE *debug; -#endif -}; - -/*--------------------------------------------------------------------*/ - -#ifdef DEBUG_EVENTS -#define DBG(evb, ...) do { \ - if ((evb)->debug != NULL) \ - fprintf((evb)->debug, __VA_ARGS__); \ - } while (0); -#else -#define DBG(evb, ...) /* ... */ -#endif - -/*--------------------------------------------------------------------*/ - -static void -ev_bh_update(void *priv, void *a, unsigned u) -{ - struct evbase *evb; - struct ev *e; - - CAST_OBJ_NOTNULL(evb, priv, EVBASE_MAGIC); - CAST_OBJ_NOTNULL(e, a, EV_MAGIC); - e->__binheap_idx = u; -} - -static int -ev_bh_cmp(void *priv, void *a, void *b) -{ - struct evbase *evb; - struct ev *ea, *eb; - - CAST_OBJ_NOTNULL(evb, priv, EVBASE_MAGIC); - CAST_OBJ_NOTNULL(ea, a, EV_MAGIC); - CAST_OBJ_NOTNULL(eb, b, EV_MAGIC); - return (ea->__when < eb->__when); -} - -/*--------------------------------------------------------------------*/ - -static int -ev_get_pfd(struct evbase *evb) -{ - unsigned u; - void *p; - - if (evb->lpfd + 1 < evb->npfd) - return (0); - - if (evb->npfd < 8) - u = 8; - else if (evb->npfd > 256) - u = evb->npfd + 256; - else - u = evb->npfd * 2; - p = realloc(evb->pfd, sizeof *evb->pfd * u); - if (p == NULL) - return (1); - evb->npfd = u; - evb->pfd = p; - return (0); -} - -/*--------------------------------------------------------------------*/ - -static int -ev_get_sig(int sig) -{ - struct evsig *os; - - if (sig < ev_nsig) - return (0); - - os = calloc(sizeof *os, (sig + 1)); - if (os == NULL) - return (ENOMEM); - - memcpy(os, ev_sigs, ev_nsig * sizeof *os); - - free(ev_sigs); - ev_sigs = os; - ev_nsig = sig + 1; - - return (0); -} - -/*--------------------------------------------------------------------*/ - -static void -ev_sighandler(int sig) -{ - struct evsig *es; - - assert(sig < ev_nsig); - assert(ev_sigs != NULL); - es = &ev_sigs[sig]; - if (!es->happened) - es->evb->psig++; - es->happened = 1; -} - -/*--------------------------------------------------------------------*/ - -struct evbase * -ev_new_base(void) -{ - struct evbase *evb; - - evb = calloc(sizeof *evb, 1); - if (evb == NULL) - return (evb); - if (ev_get_pfd(evb)) { - free(evb); - return (NULL); - } - evb->magic = EVBASE_MAGIC; - VTAILQ_INIT(&evb->events); - evb->binheap = binheap_new(evb, ev_bh_cmp, ev_bh_update); - evb->thread = pthread_self(); -#ifdef DEBUG_EVENTS - evb->debug = fopen("/tmp/_.events", "w"); - AN(evb->debug); - setbuf(evb->debug, NULL); - DBG(evb, "\n\nStart debugging\n"); -#endif - return (evb); -} - -/*--------------------------------------------------------------------*/ - -void -ev_destroy_base(struct evbase *evb) -{ - CHECK_OBJ_NOTNULL(evb, EVBASE_MAGIC); - assert(evb->thread == pthread_self()); - evb->magic = 0; - free(evb); -} - -/*--------------------------------------------------------------------*/ - -struct ev * -ev_new(void) -{ - struct ev *e; - - e = calloc(sizeof *e, 1); - if (e != NULL) { - e->fd = -1; - } - return (e); -} - -/*--------------------------------------------------------------------*/ - -int -ev_add(struct evbase *evb, struct ev *e) -{ - struct evsig *es; - - CHECK_OBJ_NOTNULL(evb, EVBASE_MAGIC); - assert(e->magic != EV_MAGIC); - assert(e->callback != NULL); - assert(e->sig >= 0); - assert(e->timeout >= 0.0); - assert(e->fd < 0 || e->fd_flags); - assert(evb->thread == pthread_self()); - DBG(evb, "ev_add(%p) fd = %d\n", e, e->fd); - - if (e->sig > 0 && ev_get_sig(e->sig)) - return (ENOMEM); - - if (e->fd >= 0 && ev_get_pfd(evb)) - return (ENOMEM); - - if (e->sig > 0) { - es = &ev_sigs[e->sig]; - if (es->ev != NULL) - return (EBUSY); - assert(es->happened == 0); - es->ev = e; - es->evb = evb; - es->sigact.sa_flags = e->sig_flags; - es->sigact.sa_handler = ev_sighandler; - } else { - es = NULL; - } - - if (e->fd >= 0) { - assert(evb->lpfd < evb->npfd); - evb->pfd[evb->lpfd].fd = e->fd; - evb->pfd[evb->lpfd].events = - e->fd_flags & (EV_RD|EV_WR|EV_ERR|EV_HUP); - e->__poll_idx = evb->lpfd; - evb->lpfd++; - DBG(evb, "... pidx = %d lpfd = %d\n", - e->__poll_idx, evb->lpfd); - } else - e->__poll_idx = -1; - - e->magic = EV_MAGIC; /* before binheap_insert() */ - - if (e->timeout != 0.0) { - e->__when += TIM_mono() + e->timeout; - binheap_insert(evb->binheap, e); - assert(e->__binheap_idx > 0); - DBG(evb, "... bidx = %d\n", e->__binheap_idx); - } else { - e->__when = 0.0; - e->__binheap_idx = 0; - } - - e->__evb = evb; - e->__privflags = 0; - if (e->fd < 0) - VTAILQ_INSERT_TAIL(&evb->events, e, __list); - else - VTAILQ_INSERT_HEAD(&evb->events, e, __list); - - if (e->sig > 0) { - assert(es != NULL); - assert(sigaction(e->sig, &es->sigact, NULL) == 0); - } - - return (0); -} - -/*--------------------------------------------------------------------*/ - -void -ev_del(struct evbase *evb, struct ev *e) -{ - struct evsig *es; - - CHECK_OBJ_NOTNULL(evb, EVBASE_MAGIC); - CHECK_OBJ_NOTNULL(e, EV_MAGIC); - DBG(evb, "ev_del(%p) fd = %d\n", e, e->fd); - assert(evb == e->__evb); - assert(evb->thread == pthread_self()); - - if (e->__binheap_idx != 0) - binheap_delete(evb->binheap, e->__binheap_idx); - assert(e->__binheap_idx == 0); - - if (e->fd >= 0) { - DBG(evb, "... pidx = %d\n", e->__poll_idx); - evb->pfd[e->__poll_idx].fd = -1; - if (e->__poll_idx == evb->lpfd - 1) - evb->lpfd--; - else - evb->compact_pfd++; - e->fd = -1; - DBG(evb, "... lpfd = %d\n", evb->lpfd); - } - - if (e->sig > 0) { - assert(e->sig < ev_nsig); - es = &ev_sigs[e->sig]; - assert(es->ev == e); - es->ev = NULL; - es->evb = NULL; - es->sigact.sa_flags = e->sig_flags; - es->sigact.sa_handler = SIG_DFL; - assert(sigaction(e->sig, &es->sigact, NULL) == 0); - es->happened = 0; - } - - VTAILQ_REMOVE(&evb->events, e, __list); - - e->magic = 0; - e->__evb = NULL; - - evb->disturbed = 1; -} - -/*--------------------------------------------------------------------*/ - -int -ev_schedule(struct evbase *evb) -{ - int i; - - CHECK_OBJ_NOTNULL(evb, EVBASE_MAGIC); - assert(evb->thread == pthread_self()); - do - i = ev_schedule_one(evb); - while (i == 1); - return (i); -} - -/*--------------------------------------------------------------------*/ - -static void -ev_compact_pfd(struct evbase *evb) -{ - unsigned u; - struct pollfd *p; - struct ev *ep; - int lfd; - - DBG(evb, "compact_pfd() lpfd = %d\n", evb->lpfd); - p = evb->pfd; - for (u = 0; u < evb->lpfd; u++, p++) { - DBG(evb, "...[%d] fd = %d\n", u, p->fd); - if (p->fd >= 0) - continue; - if (u == evb->lpfd - 1) - break; - lfd = evb->pfd[evb->lpfd - 1].fd; - VTAILQ_FOREACH(ep, &evb->events, __list) - if (ep->fd == lfd) - break; - AN(ep); - DBG(evb, "...[%d] move %p pidx %d\n", u, ep, ep->__poll_idx); - *p = evb->pfd[--evb->lpfd]; - ep->__poll_idx = u; - } - evb->lpfd = u; - evb->compact_pfd = 0; - DBG(evb, "... lpfd = %d\n", evb->lpfd); -} - -/*--------------------------------------------------------------------*/ - -static int -ev_sched_timeout(struct evbase *evb, struct ev *e, double t) -{ - int i; - - - i = e->callback(e, 0); - if (i) { - ev_del(evb, e); - free(e); - } else { - e->__when = t + e->timeout; - binheap_delete(evb->binheap, e->__binheap_idx); - binheap_insert(evb->binheap, e); - } - return (1); -} - -static int -ev_sched_signal(struct evbase *evb) -{ - int i, j; - struct evsig *es; - struct ev *e; - - es = ev_sigs; - for (j = 0; j < ev_nsig; j++, es++) { - if (!es->happened || es->evb != evb) - continue; - evb->psig--; - es->happened = 0; - e = es->ev; - assert(e != NULL); - i = e->callback(e, EV_SIG); - if (i) { - ev_del(evb, e); - free(e); - } - } - return (1); -} - -int -ev_schedule_one(struct evbase *evb) -{ - double t; - struct ev *e, *e2, *e3; - int i, j, tmo; - struct pollfd *pfd; - - CHECK_OBJ_NOTNULL(evb, EVBASE_MAGIC); - assert(evb->thread == pthread_self()); - e = binheap_root(evb->binheap); - if (e != NULL) { - CHECK_OBJ_NOTNULL(e, EV_MAGIC); - assert(e->__binheap_idx == 1); - t = TIM_mono(); - if (e->__when <= t) - return (ev_sched_timeout(evb, e, t)); - tmo = (int)((e->__when - t) * 1e3); - if (tmo == 0) - tmo = 1; - } else - tmo = INFTIM; - - if (evb->compact_pfd) - ev_compact_pfd(evb); - - if (tmo == INFTIM && evb->lpfd == 0) - return (0); - - if (evb->psig) - return (ev_sched_signal(evb)); - assert(evb->lpfd < evb->npfd); - i = poll(evb->pfd, evb->lpfd, tmo); - if(i == -1 && errno == EINTR) - return (ev_sched_signal(evb)); - if (i == 0) { - assert(e != NULL); - t = TIM_mono(); - if (e->__when <= t) - return (ev_sched_timeout(evb, e, t)); - } - evb->disturbed = 0; - VTAILQ_FOREACH_SAFE(e, &evb->events, __list, e2) { - if (i == 0) - break; - if (e->fd < 0) - continue; - assert(e->__poll_idx < evb->lpfd); - pfd = &evb->pfd[e->__poll_idx]; - assert(pfd->fd == e->fd); - if (!pfd->revents) - continue; - DBG(evb, "callback(%p) fd = %d what = 0x%x pidx = %d\n", - e, e->fd, pfd->revents, e->__poll_idx); - j = e->callback(e, pfd->revents); - i--; - if (evb->disturbed) { - VTAILQ_FOREACH(e3, &evb->events, __list) { - if (e3 == e) { - e3 = VTAILQ_NEXT(e, __list); - break; - } else if (e3 == e2) - break; - } - e2 = e3; - evb->disturbed = 0; - } - if (j) { - ev_del(evb, e); - evb->disturbed = 0; - free(e); - } - } - assert(i == 0); - return (1); -} Deleted: trunk/varnish-cache/bin/varnishd/mgt_event.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_event.h 2008-07-11 21:33:26 UTC (rev 2939) +++ trunk/varnish-cache/bin/varnishd/mgt_event.h 2008-07-11 21:34:17 UTC (rev 2940) @@ -1,81 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - */ - -#include - -#include "vqueue.h" - -struct ev; -struct evbase; - -typedef int ev_cb_f(const struct ev *, int what); - -struct ev { - unsigned magic; -#define EV_MAGIC 0x15c8134b - - /* pub */ - const char *name; - int fd; - unsigned fd_flags; -#define EV_RD POLLIN -#define EV_WR POLLOUT -#define EV_ERR POLLERR -#define EV_HUP POLLHUP -#define EV_GONE POLLNVAL -#define EV_SIG -1 - int sig; - unsigned sig_flags; - double timeout; - ev_cb_f *callback; - void *priv; - - /* priv */ - double __when; - VTAILQ_ENTRY(ev) __list; - unsigned __binheap_idx; - unsigned __privflags; - struct evbase *__evb; - int __poll_idx; -}; - -struct evbase; - -struct evbase *ev_new_base(void); -void ev_destroy_base(struct evbase *evb); - -struct ev *ev_new(void); - -int ev_add(struct evbase *evb, struct ev *e); -void ev_del(struct evbase *evb, struct ev *e); - -int ev_schedule_one(struct evbase *evb); -int ev_schedule(struct evbase *evb); From phk at projects.linpro.no Fri Jul 11 22:07:10 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 12 Jul 2008 00:07:10 +0200 (CEST) Subject: r2941 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080711220710.8126B1EC10F@projects.linpro.no> Author: phk Date: 2008-07-12 00:07:10 +0200 (Sat, 12 Jul 2008) New Revision: 2941 Added: trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc Log: Test that "Connection:" header deletes http headers in both directions. Added: trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc 2008-07-11 22:07:10 UTC (rev 2941) @@ -0,0 +1,27 @@ +# $Id: c00015.vtc 2906 2008-07-08 10:29:07Z phk $ + +test "Test Connection header handling" + +server s1 { + rxreq + expect req.url == "/foo" + expect req.http.Foo == "bar" + txresp -hdr "Bar: foo" -body "foobar" + + rxreq + expect req.url == "/bar" + expect req.http.Foo == "req.http.Foo" + txresp -hdr "Bar: foo" -hdr "Connection: bar" -body "foobar" +} -start + +varnish v1 -vcl+backend { } -start + +client c1 { + txreq -url "/foo" -hdr "Foo: bar" + rxresp + expect resp.http.Bar == "foo" + + txreq -url "/bar" -hdr "Foo: bar2" -hdr "Connection: Foo" + rxresp + expect req.http.Bar == "req.http.Bar" +} -start From phk at projects.linpro.no Fri Jul 11 22:13:29 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 12 Jul 2008 00:13:29 +0200 (CEST) Subject: r2942 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080711221329.89CE41EC10F@projects.linpro.no> Author: phk Date: 2008-07-12 00:13:29 +0200 (Sat, 12 Jul 2008) New Revision: 2942 Modified: trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc Log: Add a bit of variation to the Connection header Modified: trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc 2008-07-11 22:07:10 UTC (rev 2941) +++ trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc 2008-07-11 22:13:29 UTC (rev 2942) @@ -11,7 +11,7 @@ rxreq expect req.url == "/bar" expect req.http.Foo == "req.http.Foo" - txresp -hdr "Bar: foo" -hdr "Connection: bar" -body "foobar" + txresp -hdr "Bar: fnry,glyf, FOO ,brok" -hdr "Connection: bar" -body "foobar" } -start varnish v1 -vcl+backend { } -start @@ -21,7 +21,7 @@ rxresp expect resp.http.Bar == "foo" - txreq -url "/bar" -hdr "Foo: bar2" -hdr "Connection: Foo" + txreq -url "/bar" -hdr "Foo: bar2" -hdr "Connection: foo, close" rxresp expect req.http.Bar == "req.http.Bar" } -start From petter at projects.linpro.no Mon Jul 14 12:59:10 2008 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Mon, 14 Jul 2008 14:59:10 +0200 (CEST) Subject: r2943 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl Message-ID: <20080714125910.AE3E41EC0B7@projects.linpro.no> Author: petter Date: 2008-07-14 14:59:10 +0200 (Mon, 14 Jul 2008) New Revision: 2943 Added: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c trunk/varnish-cache/bin/varnishtest/tests/v00009.vtc trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/Makefile.am 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 Log: Added a round robin director. The round robin director can be created like this: director batman round-robin { { .backend = b1; } { .backend = b2; } { .backend = b3; } } sub vcl_recv { set req.backend = batman; } The backend will then be chosen in a round robin fashion. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-11 22:13:29 UTC (rev 2942) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-14 12:59:10 UTC (rev 2943) @@ -18,6 +18,7 @@ cache_center.c \ cache_cli.c \ cache_dir_random.c \ + cache_dir_round_robin.c \ cache_dir_simple.c \ cache_expire.c \ cache_fetch.c \ Added: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-14 12:59:10 UTC (rev 2943) @@ -0,0 +1,127 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2008 Linpro AS + * All rights reserved. + * + * Author: Petter Knudsen + * + * 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: cache_dir_round_robin.c 2906 2008-07-08 10:29:07Z phk $ + * + */ + +#include "config.h" + +#include +#include + +#include +#include +#include +#include + +#include "shmlog.h" +#include "cache.h" +#include "vrt.h" + +/*--------------------------------------------------------------------*/ + +struct vdi_round_robin_host { + struct backend *backend; +}; + +struct vdi_round_robin { + unsigned magic; +#define VDI_ROUND_ROBIN_MAGIC 0x2114a178 + struct director dir; + struct backend *backend; + struct vdi_round_robin_host *hosts; + unsigned nhosts; + unsigned next_host; +}; + + +static struct backend * +vdi_round_robin_choose(struct sess *sp) +{ + struct vdi_round_robin *vs; + struct backend *backend; + + CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC); + CAST_OBJ_NOTNULL(vs, sp->director->priv, VDI_ROUND_ROBIN_MAGIC); + + backend = vs->hosts[ vs->next_host ].backend; + vs->next_host = (vs->next_host + 1) % vs->nhosts; + + return (backend); +} + +static void +vdi_round_robin_fini(struct director *d) +{ + int i; + struct vdi_round_robin *vs; + struct vdi_round_robin_host *vh; + + CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); + CAST_OBJ_NOTNULL(vs, d->priv, VDI_ROUND_ROBIN_MAGIC); + + vh = vs->hosts; + for (i = 0; i < vs->nhosts; i++, vh++) + VBE_DropRef(vh->backend); + free(vs->hosts); + vs->dir.magic = 0; + vs->next_host = 0; + FREE_OBJ(vs); +} + +void +VRT_init_dir_round_robin(struct cli *cli, struct director **bp, const struct vrt_dir_round_robin *t) +{ + struct vdi_round_robin *vs; + const struct vrt_dir_round_robin_entry *te; + struct vdi_round_robin_host *vh; + int i; + + (void)cli; + + ALLOC_OBJ(vs, VDI_ROUND_ROBIN_MAGIC); + XXXAN(vs); + vs->hosts = calloc(sizeof *vh, t->nmember); + XXXAN(vs->hosts); + + vs->dir.magic = DIRECTOR_MAGIC; + vs->dir.priv = vs; + vs->dir.name = "round_robin"; + vs->dir.choose = vdi_round_robin_choose; + vs->dir.fini = vdi_round_robin_fini; + + vh = vs->hosts; + te = t->members; + for (i = 0; i < t->nmember; i++, vh++, te++) + vh->backend = VBE_AddBackend(cli, te->host); + vs->nhosts = t->nmember; + vs->next_host = 0; + + *bp = &vs->dir; +} Added: trunk/varnish-cache/bin/varnishtest/tests/v00009.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00009.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00009.vtc 2008-07-14 12:59:10 UTC (rev 2943) @@ -0,0 +1,67 @@ +# $Id$ + +test "Test round robin director" + +server s1 -listen 127.0.0.1:2000 { + rxreq + txresp -body "1" +} -start + +server s2 -listen 127.0.0.1:3000 { + rxreq + txresp -body "22" +} -start + + +server s3 -listen 127.0.0.1:4000 { + rxreq + txresp -body "333" +} -start + +server s4 -listen 127.0.0.1:5000 { + rxreq + txresp -body "4444" +} -start + + +varnish v1 -vcl+backend { + director batman round-robin { + { .backend = s1; } + { .backend = s2; } + { .backend = s3; } + { .backend = s4; } + } + + sub vcl_recv { + set req.backend = batman; + } +} -start + +client c1 { + timeout 3 + txreq -url "/foo1" + rxresp + expect resp.http.content-length == 1 + txreq -url "/foo2" + rxresp + expect resp.http.content-length == 2 + txreq -url "/foo3" + rxresp + expect resp.http.content-length == 3 + txreq -url "/foo4" + rxresp + expect resp.http.content-length == 4 +} -run + +server s1 -start +server s2 -start + +client c2 { + timeout 3 + txreq -url "/foo11" + rxresp + expect resp.http.content-length == 1 + txreq -url "/foo22" + rxresp + expect resp.http.content-length == 2 +} -run Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2008-07-11 22:13:29 UTC (rev 2942) +++ trunk/varnish-cache/include/vrt.h 2008-07-14 12:59:10 UTC (rev 2943) @@ -92,6 +92,21 @@ }; /* + * A director with round robin selection + */ + +struct vrt_dir_round_robin_entry { + const struct vrt_backend *host; +}; + +struct vrt_dir_round_robin { + const char *name; + unsigned nmember; + const struct vrt_dir_round_robin_entry *members; +}; + + +/* * other stuff. * XXX: document when bored */ @@ -147,6 +162,7 @@ /* Backend related */ void VRT_init_dir_simple(struct cli *, struct director **, const struct vrt_dir_simple *); void VRT_init_dir_random(struct cli *, struct director **, const struct vrt_dir_random *); +void VRT_init_dir_round_robin(struct cli *, struct director **, const struct vrt_dir_round_robin *); void VRT_fini_dir(struct cli *, struct director *); char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa); Modified: trunk/varnish-cache/lib/libvcl/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvcl/Makefile.am 2008-07-11 22:13:29 UTC (rev 2942) +++ trunk/varnish-cache/lib/libvcl/Makefile.am 2008-07-14 12:59:10 UTC (rev 2943) @@ -14,6 +14,7 @@ vcc_backend.c \ vcc_compile.c \ vcc_dir_random.c \ + vcc_dir_round_robin.c \ vcc_parse.c \ vcc_fixed_token.c \ vcc_obj.c \ Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-11 22:13:29 UTC (rev 2942) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-14 12:59:10 UTC (rev 2943) @@ -656,6 +656,7 @@ parsedirector_f *func; } dirlist[] = { { "random", vcc_ParseRandomDirector }, + { "round-robin", vcc_ParseRoundRobinDirector }, { NULL, NULL } }; Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-11 22:13:29 UTC (rev 2942) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-14 12:59:10 UTC (rev 2943) @@ -178,6 +178,9 @@ /* vcc_dir_random.c */ parsedirector_f vcc_ParseRandomDirector; +/* vcc_dir_round_robin.c */ +parsedirector_f vcc_ParseRoundRobinDirector; + /* vcc_obj.c */ extern struct var vcc_vars[]; Added: trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c (rev 0) +++ trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2008-07-14 12:59:10 UTC (rev 2943) @@ -0,0 +1,108 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2008 Linpro AS + * All rights reserved. + * + * Author: Petter Knudsen + * + * 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: vcc_dir_random.c 2900 2008-07-08 07:30:42Z phk $ + */ + +#include "config.h" + +#include +#include + +#include +#include +#include +#include + +#include "vsb.h" + +#include "vcc_priv.h" +#include "vcc_compile.h" +#include "libvarnish.h" + +/*-------------------------------------------------------------------- + * Parse directors + */ + +void +vcc_ParseRoundRobinDirector(struct tokenlist *tl, const struct token *t_policy, const struct token *t_dir) +{ + struct token *t_field, *t_be; + int nbh, nelem; + struct fld_spec *fs; + + fs = vcc_FldSpec(tl, "!backend", NULL); + + Fc(tl, 0, + "\nstatic const struct vrt_dir_round_robin_entry vdrre_%.*s[] = {\n", + PF(t_dir)); + + for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */ + t_be = tl->t; + vcc_ResetFldSpec(fs); + nbh = -1; + + ExpectErr(tl, '{'); + vcc_NextToken(tl); + Fc(tl, 0, "\t{"); + + while (tl->t->tok != '}') { /* Member fields */ + vcc_IsField(tl, &t_field, fs); + ERRCHK(tl); + if (vcc_IdIs(t_field, "backend")) { + vcc_ParseBackendHost(tl, &nbh, + t_dir, t_policy, nelem); + Fc(tl, 0, " .host = &bh_%d,", nbh); + ERRCHK(tl); + } else { + ErrInternal(tl); + } + } + vcc_FieldsOk(tl, fs); + if (tl->err) { + vsb_printf(tl->sb, + "\nIn member host specfication starting at:\n"); + vcc_ErrWhere(tl, t_be); + return; + } + Fc(tl, 0, " },\n"); + vcc_NextToken(tl); + } + Fc(tl, 0, "};\n"); + Fc(tl, 0, + "\nstatic const struct vrt_dir_round_robin vdrr_%.*s = {\n", + PF(t_dir)); + Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir)); + Fc(tl, 0, "\t.nmember = %d,\n", nelem); + Fc(tl, 0, "\t.members = vdrre_%.*s,\n", PF(t_dir)); + Fc(tl, 0, "};\n"); + Fi(tl, 0, + "\tVRT_init_dir_round_robin(cli, &VGC_backend_%.*s , &vdrr_%.*s);\n", + PF(t_dir), PF(t_dir)); + Ff(tl, 0, "\tVRT_fini_dir(cli, VGC_backend_%.*s);\n", PF(t_dir)); +} Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-11 22:13:29 UTC (rev 2942) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-14 12:59:10 UTC (rev 2943) @@ -430,6 +430,21 @@ vsb_cat(sb, "};\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "/*\n"); + vsb_cat(sb, " * A director with round robin selection\n"); + vsb_cat(sb, " */\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, "struct vrt_dir_round_robin_entry {\n"); + vsb_cat(sb, " const struct vrt_backend *host;\n"); + vsb_cat(sb, "};\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, "struct vrt_dir_round_robin {\n"); + vsb_cat(sb, " const char *name;\n"); + vsb_cat(sb, " unsigned nmember;\n"); + vsb_cat(sb, " const struct vrt_dir_round_robin_entry *members;\n"); + vsb_cat(sb, "};\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, "\n"); + vsb_cat(sb, "/*\n"); vsb_cat(sb, " * other stuff.\n"); vsb_cat(sb, " * XXX: document when bored\n"); vsb_cat(sb, " */\n"); @@ -485,6 +500,7 @@ vsb_cat(sb, "/* Backend related */\n"); vsb_cat(sb, "void VRT_init_dir_simple(struct cli *, struct director **, const struct vrt_dir_simple *);\n"); vsb_cat(sb, "void VRT_init_dir_random(struct cli *, struct director **, const struct vrt_dir_random *);\n"); + vsb_cat(sb, "void VRT_init_dir_round_robin(struct cli *, struct director **, const struct vrt_dir_round_robin *);\n"); vsb_cat(sb, "void VRT_fini_dir(struct cli *, struct director *);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);\n"); From phk at projects.linpro.no Mon Jul 14 15:49:41 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 14 Jul 2008 17:49:41 +0200 (CEST) Subject: r2944 - trunk/varnish-cache/bin/varnishd Message-ID: <20080714154941.C7CF31EC236@projects.linpro.no> Author: phk Date: 2008-07-14 17:49:41 +0200 (Mon, 14 Jul 2008) New Revision: 2944 Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c Log: Three minor style nits from FlexeLint Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-14 12:59:10 UTC (rev 2943) +++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-14 15:49:41 UTC (rev 2944) @@ -54,7 +54,6 @@ unsigned magic; #define VDI_ROUND_ROBIN_MAGIC 0x2114a178 struct director dir; - struct backend *backend; struct vdi_round_robin_host *hosts; unsigned nhosts; unsigned next_host; @@ -62,7 +61,7 @@ static struct backend * -vdi_round_robin_choose(struct sess *sp) +vdi_round_robin_choose(const struct sess *sp) { struct vdi_round_robin *vs; struct backend *backend; @@ -77,7 +76,7 @@ } static void -vdi_round_robin_fini(struct director *d) +vdi_round_robin_fini(const struct director *d) { int i; struct vdi_round_robin *vs; From phk at projects.linpro.no Mon Jul 14 15:53:22 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 14 Jul 2008 17:53:22 +0200 (CEST) Subject: r2945 - trunk/varnish-cache/bin/varnishd Message-ID: <20080714155322.945B51EC0EA@projects.linpro.no> Author: phk Date: 2008-07-14 17:53:22 +0200 (Mon, 14 Jul 2008) New Revision: 2945 Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c Log: Ooops, FlexeLint was wrong, the consts are not possible. Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-14 15:49:41 UTC (rev 2944) +++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-14 15:53:22 UTC (rev 2945) @@ -61,7 +61,7 @@ static struct backend * -vdi_round_robin_choose(const struct sess *sp) +vdi_round_robin_choose(struct sess *sp) { struct vdi_round_robin *vs; struct backend *backend; @@ -76,7 +76,7 @@ } static void -vdi_round_robin_fini(const struct director *d) +vdi_round_robin_fini(struct director *d) { int i; struct vdi_round_robin *vs; From des at linpro.no Wed Jul 16 09:00:25 2008 From: des at linpro.no (=?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?=) Date: Wed, 16 Jul 2008 11:00:25 +0200 Subject: r2943 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl In-Reply-To: <20080714125910.AE3E41EC0B7@projects.linpro.no> References: <20080714125910.AE3E41EC0B7@projects.linpro.no> Message-ID: <87bq0yi4pi.fsf@des.linpro.no> petter at projects.linpro.no writes: > Added a round robin director. The round robin director can be created like this: > > director batman round-robin { > { .backend = b1; } > { .backend = b2; } > { .backend = b3; } > } We should avoid the use of non-word characters in VCL keywords (using Perl's definition of a word character, [0-9A-Za-z_]), so this should be "round_robin" or "roundrobin". > + * Copyright (c) 2006 Verdens Gang AS > + * Copyright (c) 2006-2008 Linpro AS > + * All rights reserved. This is a new file, it should have "Copyright (c) 2008 Linpro AS" and no VG copyright. > + for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */ Code comments go on separate lines This (and directors in general) should be documented in vcl(7). DES -- Dag-Erling Sm?rgrav Senior Software Developer Linpro AS - www.linpro.no From petter at projects.linpro.no Thu Jul 17 09:58:55 2008 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Thu, 17 Jul 2008 11:58:55 +0200 (CEST) Subject: r2946 - trunk/varnish-cache/bin/varnishstat Message-ID: <20080717095855.41D921EC236@projects.linpro.no> Author: petter Date: 2008-07-17 11:58:54 +0200 (Thu, 17 Jul 2008) New Revision: 2946 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.1 trunk/varnish-cache/bin/varnishstat/varnishstat.c Log: Added support for choosing what fields to show in varniststat. This is done by using the new -f option. To list avaialble fields, use the new -l option. Fixes #208. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.1 =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.1 2008-07-14 15:53:22 UTC (rev 2945) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.1 2008-07-17 09:58:54 UTC (rev 2946) @@ -37,6 +37,8 @@ .Sh SYNOPSIS .Nm .Op Fl 1 +.Op Fl f Ar field_list +.Op Fl l .Op Fl n Ar varnish_name .Op Fl V .Op Fl w Ar delay @@ -52,6 +54,13 @@ .It Fl 1 Instead of presenting of a continuously updated display, print the statistics once and exit. +.It Fl f +A comma separated list of the fields to display. +If it starts with '^' it is used as an exclusion list. +.It Fl l +Lists the available fields to use with the +.Fl f +option. .It Fl n Specifies the name of the .Nm varnishd Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2008-07-14 15:53:22 UTC (rev 2945) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2008-07-17 09:58:54 UTC (rev 2946) @@ -50,6 +50,8 @@ #include "shmlog.h" #include "varnishapi.h" +#define FIELD_EXCLUSION_CHARACTER '^' + static void myexp(double *acc, double val, unsigned *n, unsigned nmax) { @@ -59,8 +61,37 @@ (*acc) += (val - *acc) / (double)*n; } +static int +show_field(const char* field, const char *fields) +{ + char* field_start; + char* field_end; + int field_length; + int match_value = 1; + + if (fields[0] == FIELD_EXCLUSION_CHARACTER) { + match_value = 0; + fields++; + } + + field_start = strstr(fields, field); + if (field_start != NULL) { + field_length = strlen( field ); + + while (field_start != NULL) { + field_end = field_start + field_length; + if ((field_start == fields || *(field_start - 1) == ',') && + (*field_end == ',' || *field_end == '\0')) + return (match_value); + field_start = strstr( field_end, field ); + } + } + + return (!match_value); +} + static void -do_curses(struct varnish_stats *VSL_stats, int delay) +do_curses(struct varnish_stats *VSL_stats, int delay, const char *fields) { struct varnish_stats copy; intmax_t ju; @@ -112,7 +143,7 @@ line = 3; #define MAC_STAT(n, t, f, d) \ - if (++line < LINES) { \ + if ((fields == NULL || show_field( #n, fields )) && ++line < LINES) { \ ju = VSL_stats->n; \ if (f == 'a') { \ mvprintw(line, 0, "%12ju %12.2f %12.2f %s\n", \ @@ -172,7 +203,7 @@ } static void -do_once(struct varnish_stats *VSL_stats) +do_once(struct varnish_stats *VSL_stats, const char* fields) { struct timeval tv; double up; @@ -182,6 +213,7 @@ #define MAC_STAT(n, t, f, d) \ do { \ + if (fields != NULL && ! show_field( #n, fields )) break; \ intmax_t ju = VSL_stats->n; \ if (f == 'a') \ printf("%-16s %12ju %12.2f %s\n", #n, ju, ju / up, d); \ @@ -195,10 +227,77 @@ static void usage(void) { - fprintf(stderr, "usage: varnishstat [-1V] [-n varnish_name] [-w delay]\n"); +#define FMT " %-28s # %s\n" + fprintf(stderr, "usage: varnishstat [-1lV] [-f field_list] [-n varnish_name] [-w delay]\n"); + fprintf(stderr, FMT, "-1", "Print the statistics once and exit"); + fprintf(stderr, FMT, "-f field_list", "Comma separated list of fields to display. "); + fprintf(stderr, FMT, "", "If it starts with '^' it is used as an exclusion list"); + fprintf(stderr, FMT, "-l", "Lists the available fields to use with the -f option"); + fprintf(stderr, FMT, "-n varnish_name", "The varnishd instance to get logs from"); + fprintf(stderr, FMT, "-V", "Display the version number and exit"); + fprintf(stderr, FMT, "-w delay", "Wait delay seconds between updates. The default is 1."); +#undef FMT exit(1); } +static void +list_fields(void) +{ + fprintf(stderr, "Available fields to use with the varnishstat -f option:\n"); + fprintf(stderr, "Field name Description\n"); + fprintf(stderr, "---------- -----------\n"); +#define MAC_STAT(n, t, f, d) \ + do { \ + fprintf(stderr, "%-20s %s\n", #n, d);\ + } while (0); +#include "stat_field.h" +#undef MAC_STAT +} + +static int +valid_fields(const char* fields) +{ + int i, valid_field, field_length; + const char *all_fields[] = { +#define MAC_STAT(n, t, f, d) \ + #n, +#include "stat_field.h" +#undef MAC_STAT + NULL }; + const char *field_start, *field_end; + + if (fields[0] == FIELD_EXCLUSION_CHARACTER) + fields++; + + for (field_start = fields; ; field_start = field_end + 1) { + field_end = strchr(field_start, ','); + if (field_end != NULL) + field_length = field_end - field_start; + else + field_length = strlen(field_start); + + valid_field = 0; + for (i = 0; all_fields[i] != NULL; i++) { + if (strncmp(field_start, all_fields[i], field_length) == 0 && field_length == strlen( all_fields[i] )) { + valid_field = 1; + break; + } + } + + if (!valid_field) { + fputs("The field '", stderr); + fwrite(field_start, 1, field_length, stderr); + fputs("' is not a valid field\n", stderr); + return (0); + } + + if (field_end == NULL || *field_end == '\0') + break; + } + + return (1); +} + int main(int argc, char **argv) { @@ -206,12 +305,19 @@ struct varnish_stats *VSL_stats; int delay = 1, once = 0; const char *n_arg = NULL; + const char *fields = NULL; - while ((c = getopt(argc, argv, "1n:Vw:")) != -1) { + while ((c = getopt(argc, argv, "1f:ln:Vw:")) != -1) { switch (c) { case '1': once = 1; break; + case 'f': + fields = optarg; + break; + case 'l': + list_fields(); + exit(0); case 'n': n_arg = optarg; break; @@ -228,11 +334,16 @@ if ((VSL_stats = VSL_OpenStats(n_arg)) == NULL) exit(1); + + if (fields != NULL && !valid_fields(fields)) { + usage(); + exit(1); + } if (once) - do_once(VSL_stats); + do_once(VSL_stats, fields); else - do_curses(VSL_stats, delay); + do_curses(VSL_stats, delay, fields); exit(0); } From sky at projects.linpro.no Fri Jul 18 00:16:20 2008 From: sky at projects.linpro.no (sky at projects.linpro.no) Date: Fri, 18 Jul 2008 02:16:20 +0200 (CEST) Subject: r2947 - branches Message-ID: <20080718001620.7F19F1EC0E1@projects.linpro.no> Author: sky Date: 2008-07-18 02:16:20 +0200 (Fri, 18 Jul 2008) New Revision: 2947 Added: branches/nuke/ Log: branch for patches to support nuking objects Copied: branches/nuke (from rev 2946, trunk) From sky at projects.linpro.no Fri Jul 18 00:19:03 2008 From: sky at projects.linpro.no (sky at projects.linpro.no) Date: Fri, 18 Jul 2008 02:19:03 +0200 (CEST) Subject: r2948 - branches/nuke Message-ID: <20080718001903.373441EC0EA@projects.linpro.no> Author: sky Date: 2008-07-18 02:19:03 +0200 (Fri, 18 Jul 2008) New Revision: 2948 Modified: branches/nuke/ Log: init svnmerge Property changes on: branches/nuke ___________________________________________________________________ Name: svnmerge-integrated + /trunk:1-2946 From petter at projects.linpro.no Fri Jul 18 07:01:43 2008 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Fri, 18 Jul 2008 09:01:43 +0200 (CEST) Subject: r2949 - trunk/varnish-cache/bin/varnishd Message-ID: <20080718070143.CE4D81EC0E1@projects.linpro.no> Author: petter Date: 2008-07-18 09:01:42 +0200 (Fri, 18 Jul 2008) New Revision: 2949 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_synthetic.c trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/varnishd.1 Log: Added the parameter err_ttl, which sets the TTL for synthesized error pages. Default value is 0. Fixes #126. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-18 00:19:03 UTC (rev 2948) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-18 07:01:42 UTC (rev 2949) @@ -567,7 +567,7 @@ void RES_WriteObj(struct sess *sp); /* cache_synthetic.c */ -void SYN_ErrorPage(struct sess *sp, int status, const char *reason); +void SYN_ErrorPage(struct sess *sp, int status, const char *reason, int ttl); /* cache_vary.c */ void VRY_Create(const struct sess *sp); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-18 00:19:03 UTC (rev 2948) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-18 07:01:42 UTC (rev 2949) @@ -309,7 +309,7 @@ { AZ(sp->obj); - SYN_ErrorPage(sp, sp->err_code, sp->err_reason); + SYN_ErrorPage(sp, sp->err_code, sp->err_reason, params->err_ttl); sp->err_code = 0; sp->err_reason = NULL; sp->step = STP_DONE; @@ -878,7 +878,7 @@ *sp->http0 = *sp->http; if (done != 0) { - SYN_ErrorPage(sp, done, NULL); /* XXX: STP_ERROR ? */ + SYN_ErrorPage(sp, done, NULL, params->err_ttl); /* XXX: STP_ERROR ? */ sp->step = STP_DONE; return (0); } Modified: trunk/varnish-cache/bin/varnishd/cache_synthetic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2008-07-18 00:19:03 UTC (rev 2948) +++ trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2008-07-18 07:01:42 UTC (rev 2949) @@ -47,7 +47,7 @@ */ void -SYN_ErrorPage(struct sess *sp, int status, const char *reason) +SYN_ErrorPage(struct sess *sp, int status, const char *reason, int ttl) { struct http *h; struct worker *w; @@ -57,7 +57,6 @@ unsigned u; struct vsb vsb; int fd; - int ttl = 0; /* XXX: ?? */ WSL_Flush(sp->wrk, 0); assert(status >= 100 && status <= 999); Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2008-07-18 00:19:03 UTC (rev 2948) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2008-07-18 07:01:42 UTC (rev 2949) @@ -77,6 +77,9 @@ /* TTL used for lack of anything better */ unsigned default_ttl; + + /* TTL used for synthesized error pages */ + unsigned err_ttl; /* Worker threads and pool */ unsigned wthread_min; Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-18 00:19:03 UTC (rev 2948) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-18 07:01:42 UTC (rev 2949) @@ -784,6 +784,10 @@ "Use 0x notation and do the bitor in your head :-)\n", 0, "0", "bitmap" }, + { "err_ttl", tweak_uint, &master.err_ttl, 0, UINT_MAX, + "The TTL assigned to the synthesized error pages\n", + 0, + "0", "seconds" }, { NULL, NULL, NULL } }; Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2008-07-18 00:19:03 UTC (rev 2948) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2008-07-18 07:01:42 UTC (rev 2949) @@ -389,6 +389,10 @@ Note that changes to this parameter are not applied retroactively. .Pp The default is 120 seconds. +.It Va err_ttl +The default time-to-live assigned to the synthesized error pages. +.Pp +The default is 0 seconds. .It Va fetch_chunksize The default chunk size used when retrieving documents for which the backend server does not specify a content length. From petter at projects.linpro.no Fri Jul 18 07:16:46 2008 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Fri, 18 Jul 2008 09:16:46 +0200 (CEST) Subject: r2950 - trunk/varnish-cache/bin/varnishd Message-ID: <20080718071646.0B5C11EC874@projects.linpro.no> Author: petter Date: 2008-07-18 09:16:45 +0200 (Fri, 18 Jul 2008) New Revision: 2950 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_synthetic.c Log: There was no need to send the err_ttl as parameter as SYN_ErrorPage had access to the it directly. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-18 07:01:42 UTC (rev 2949) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-18 07:16:45 UTC (rev 2950) @@ -567,7 +567,7 @@ void RES_WriteObj(struct sess *sp); /* cache_synthetic.c */ -void SYN_ErrorPage(struct sess *sp, int status, const char *reason, int ttl); +void SYN_ErrorPage(struct sess *sp, int status, const char *reason); /* cache_vary.c */ void VRY_Create(const struct sess *sp); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-18 07:01:42 UTC (rev 2949) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-18 07:16:45 UTC (rev 2950) @@ -309,7 +309,7 @@ { AZ(sp->obj); - SYN_ErrorPage(sp, sp->err_code, sp->err_reason, params->err_ttl); + SYN_ErrorPage(sp, sp->err_code, sp->err_reason); sp->err_code = 0; sp->err_reason = NULL; sp->step = STP_DONE; @@ -878,7 +878,7 @@ *sp->http0 = *sp->http; if (done != 0) { - SYN_ErrorPage(sp, done, NULL, params->err_ttl); /* XXX: STP_ERROR ? */ + SYN_ErrorPage(sp, done, NULL); /* XXX: STP_ERROR ? */ sp->step = STP_DONE; return (0); } Modified: trunk/varnish-cache/bin/varnishd/cache_synthetic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2008-07-18 07:01:42 UTC (rev 2949) +++ trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2008-07-18 07:16:45 UTC (rev 2950) @@ -47,7 +47,7 @@ */ void -SYN_ErrorPage(struct sess *sp, int status, const char *reason, int ttl) +SYN_ErrorPage(struct sess *sp, int status, const char *reason) { struct http *h; struct worker *w; @@ -86,7 +86,7 @@ TIM_format(now, date); http_PrintfHeader(w, fd, h, "Date: %s", date); http_PrintfHeader(w, fd, h, "Server: Varnish"); - http_PrintfHeader(w, fd, h, "Retry-After: %d", ttl); + http_PrintfHeader(w, fd, h, "Retry-After: %d", params->err_ttl); http_PrintfHeader(w, fd, h, "Content-Type: text/html; charset=utf-8"); http_PrintfHeader(w, sp->fd, sp->http, "X-Varnish: %u", sp->xid); http_PrintfHeader(w, fd, h, "Connection: close"); From phk at projects.linpro.no Fri Jul 18 21:30:02 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 18 Jul 2008 23:30:02 +0200 (CEST) Subject: r2951 - trunk/varnish-cache/lib/libvcl Message-ID: <20080718213002.98F1B1EC0EA@projects.linpro.no> Author: phk Date: 2008-07-18 23:30:01 +0200 (Fri, 18 Jul 2008) New Revision: 2951 Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl Log: Polish the tokenizer Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-18 07:16:45 UTC (rev 2950) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-18 21:30:01 UTC (rev 2951) @@ -18,205 +18,148 @@ switch (p[0]) { case '!': - if (p[0] == '!' && p[1] == '=') { + if (p[1] == '=') { *q = p + 2; return (T_NEQ); } - if (p[0] == '!') { - *q = p + 1; - return ('!'); - } - return (0); + *q = p + 1; + return (p[0]); case '%': - if (p[0] == '%') { - *q = p + 1; - return ('%'); - } - return (0); + *q = p + 1; + return (p[0]); case '&': - if (p[0] == '&' && p[1] == '&') { + if (p[1] == '&') { *q = p + 2; return (T_CAND); } - if (p[0] == '&') { - *q = p + 1; - return ('&'); - } - return (0); + *q = p + 1; + return (p[0]); case '(': - if (p[0] == '(') { - *q = p + 1; - return ('('); - } - return (0); + *q = p + 1; + return (p[0]); case ')': - if (p[0] == ')') { - *q = p + 1; - return (')'); - } - return (0); + *q = p + 1; + return (p[0]); case '*': - if (p[0] == '*' && p[1] == '=') { + if (p[1] == '=') { *q = p + 2; return (T_MUL); } - if (p[0] == '*') { - *q = p + 1; - return ('*'); - } - return (0); + *q = p + 1; + return (p[0]); case '+': - if (p[0] == '+' && p[1] == '=') { + if (p[1] == '=') { *q = p + 2; return (T_INCR); } - if (p[0] == '+' && p[1] == '+') { + if (p[1] == '+') { *q = p + 2; return (T_INC); } - if (p[0] == '+') { - *q = p + 1; - return ('+'); - } - return (0); + *q = p + 1; + return (p[0]); case ',': - if (p[0] == ',') { - *q = p + 1; - return (','); - } - return (0); + *q = p + 1; + return (p[0]); case '-': - if (p[0] == '-' && p[1] == '=') { + if (p[1] == '=') { *q = p + 2; return (T_DECR); } - if (p[0] == '-' && p[1] == '-') { + if (p[1] == '-') { *q = p + 2; return (T_DEC); } - if (p[0] == '-') { - *q = p + 1; - return ('-'); - } - return (0); + *q = p + 1; + return (p[0]); case '.': - if (p[0] == '.') { - *q = p + 1; - return ('.'); - } - return (0); + *q = p + 1; + return (p[0]); case '/': - if (p[0] == '/' && p[1] == '=') { + if (p[1] == '=') { *q = p + 2; return (T_DIV); } - if (p[0] == '/') { - *q = p + 1; - return ('/'); - } - return (0); + *q = p + 1; + return (p[0]); case ';': - if (p[0] == ';') { - *q = p + 1; - return (';'); - } - return (0); + *q = p + 1; + return (p[0]); case '<': - if (p[0] == '<' && p[1] == '=') { + if (p[1] == '=') { *q = p + 2; return (T_LEQ); } - if (p[0] == '<' && p[1] == '<') { + if (p[1] == '<') { *q = p + 2; return (T_SHL); } - if (p[0] == '<') { - *q = p + 1; - return ('<'); - } - return (0); + *q = p + 1; + return (p[0]); case '=': - if (p[0] == '=' && p[1] == '=') { + if (p[1] == '=') { *q = p + 2; return (T_EQ); } - if (p[0] == '=') { - *q = p + 1; - return ('='); - } - return (0); + *q = p + 1; + return (p[0]); case '>': - if (p[0] == '>' && p[1] == '>') { + if (p[1] == '>') { *q = p + 2; return (T_SHR); } - if (p[0] == '>' && p[1] == '=') { + if (p[1] == '=') { *q = p + 2; return (T_GEQ); } - if (p[0] == '>') { - *q = p + 1; - return ('>'); - } - return (0); + *q = p + 1; + return (p[0]); case 'e': - if (p[0] == 'e' && p[1] == 'l' && p[2] == 's' && + if (p[1] == 'l' && p[2] == 's' && p[3] == 'i' && p[4] == 'f' && !isvar(p[5])) { *q = p + 5; return (T_ELSIF); } - if (p[0] == 'e' && p[1] == 'l' && p[2] == 's' && + if (p[1] == 'l' && p[2] == 's' && p[3] == 'e' && p[4] == 'i' && p[5] == 'f' && !isvar(p[6])) { *q = p + 6; return (T_ELSEIF); } - if (p[0] == 'e' && p[1] == 'l' && p[2] == 's' && + if (p[1] == 'l' && p[2] == 's' && p[3] == 'e' && !isvar(p[4])) { *q = p + 4; return (T_ELSE); } return (0); case 'i': - if (p[0] == 'i' && p[1] == 'n' && p[2] == 'c' && + if (p[1] == 'n' && p[2] == 'c' && p[3] == 'l' && p[4] == 'u' && p[5] == 'd' && p[6] == 'e' && !isvar(p[7])) { *q = p + 7; return (T_INCLUDE); } - if (p[0] == 'i' && p[1] == 'f' && !isvar(p[2])) { + if (p[1] == 'f' && !isvar(p[2])) { *q = p + 2; return (T_IF); } return (0); case '{': - if (p[0] == '{') { - *q = p + 1; - return ('{'); - } - return (0); + *q = p + 1; + return (p[0]); case '|': - if (p[0] == '|' && p[1] == '|') { + if (p[1] == '|') { *q = p + 2; return (T_COR); } - if (p[0] == '|') { - *q = p + 1; - return ('|'); - } - return (0); + *q = p + 1; + return (p[0]); case '}': - if (p[0] == '}') { - *q = p + 1; - return ('}'); - } - return (0); + *q = p + 1; + return (p[0]); case '~': - if (p[0] == '~') { - *q = p + 1; - return ('~'); - } - return (0); + *q = p + 1; + return (p[0]); default: return (0); } Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2008-07-18 07:16:45 UTC (rev 2950) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2008-07-18 21:30:01 UTC (rev 2951) @@ -260,8 +260,6 @@ } set seq [lsort [array names xx]] -set ll 0 - puts $fo { unsigned vcl_fixed_token(const char *p, const char **q)} @@ -280,19 +278,18 @@ # And do then in reverse order to match longest first set l [lsort -index 0 -decreasing $l] scan "$ch" "%c" cx - if {$cx != $ll} { - if {$ll} { - puts $fo " return (0);" - } - - puts $fo " case '$ch':" - set ll $cx - } + puts $fo " case '$ch':" + set retval "0" foreach tt $l { set k [lindex $tt 0] + if {[string length $k] == 1} { + puts $fo "\t\t*q = p + 1;" + set retval {p[0]} + continue; + } puts -nonewline $fo " if (" - for {set i 0} {$i < [string length $k]} {incr i} { - if {$i > 0} { + for {set i 1} {$i < [string length $k]} {incr i} { + if {$i > 1} { puts -nonewline $fo " && " if {![expr $i % 3]} { puts -nonewline $fo "\n\t\t " @@ -307,12 +304,13 @@ puts -nonewline $fo " && !isvar(p\[$i\])" } puts $fo ") {" - puts $fo " *q = p + [string length $k];" - puts $fo " return ([lindex $tt 1]);" - puts $fo " }" + puts $fo "\t\t\t*q = p + [string length $k];" + puts $fo "\t\t\treturn ([lindex $tt 1]);" + puts $fo "\t\t}" } + puts $fo "\t\treturn ($retval);" } -puts $fo " return (0);" + puts $fo " default:" puts $fo " return (0);" puts $fo " }" From phk at projects.linpro.no Sat Jul 19 06:43:35 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 08:43:35 +0200 (CEST) Subject: r2952 - trunk/varnish-cache/bin/varnishd Message-ID: <20080719064335.9D1821EC0E1@projects.linpro.no> Author: phk Date: 2008-07-19 08:43:34 +0200 (Sat, 19 Jul 2008) New Revision: 2952 Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c Log: typo. Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2008-07-18 21:30:01 UTC (rev 2951) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2008-07-19 06:43:34 UTC (rev 2952) @@ -113,7 +113,7 @@ if (q == NULL || q == buf || *q != '\n') { xxxassert(be > bp); /* - * The sematics we need here is "read until you have + * The semantics we need here is "read until you have * received at least one character, but feel free to * return up to (be-bp) if they are available, but do * not wait for those extra characters. From phk at projects.linpro.no Sat Jul 19 06:46:43 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 08:46:43 +0200 (CEST) Subject: r2953 - trunk/varnish-cache/bin/varnishd Message-ID: <20080719064643.10A771EC0EA@projects.linpro.no> Author: phk Date: 2008-07-19 08:46:42 +0200 (Sat, 19 Jul 2008) New Revision: 2953 Modified: trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/bin/varnishd/stevedore.h Log: Avoid home-rolled circular list in stevedore, use regular VTAILQ, the microoptimization does not justify the manual handling of ->prev and ->next. Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2008-07-19 06:43:34 UTC (rev 2952) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2008-07-19 06:46:42 UTC (rev 2953) @@ -37,16 +37,14 @@ #include "cache.h" #include "stevedore.h" -/* - * Stevedores are kept in a circular list with the head pointer - * continuously moving from one element to the next. - */ - extern struct stevedore sma_stevedore; extern struct stevedore smf_stevedore; -static struct stevedore * volatile stevedores; +static VTAILQ_HEAD(, stevedore) stevedores = + VTAILQ_HEAD_INITIALIZER(stevedores); +static struct stevedore * volatile stv_next; + struct storage * STV_alloc(struct sess *sp, size_t size) { @@ -56,9 +54,14 @@ for (;;) { /* pick a stevedore and bump the head along */ - /* XXX: only safe as long as pointer writes are atomic */ - stv = stevedores = stevedores->next; + stv = VTAILQ_NEXT(stv_next, list); + if (stv == NULL) + stv = VTAILQ_FIRST(&stevedores); + AN(stv); + /* XXX: only safe as long as pointer writes are atomic */ + stv_next = stv; + /* try to allocate from it */ st = stv->alloc(stv, size); if (st != NULL) @@ -134,15 +137,10 @@ if (stv->init != NULL) stv->init(stv, q); - if (!stevedores) { - stevedores = stv->next = stv->prev = stv; - } else { - stv->next = stevedores; - stv->prev = stevedores->prev; - stv->next->prev = stv; - stv->prev->next = stv; - stevedores = stv; - } + VTAILQ_INSERT_TAIL(&stevedores, stv, list); + + if (!stv_next) + stv_next = VTAILQ_FIRST(&stevedores); } void @@ -150,10 +148,8 @@ { struct stevedore *stv; - stv = stevedores; - do { + VTAILQ_FOREACH(stv, &stevedores, list) { if (stv->open != NULL) stv->open(stv); - stv = stv->next; - } while (stv != stevedores); + } } Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2008-07-19 06:43:34 UTC (rev 2952) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2008-07-19 06:46:42 UTC (rev 2953) @@ -52,7 +52,7 @@ /* private fields */ void *priv; - struct stevedore *next, *prev; + VTAILQ_ENTRY(stevedore) list; }; struct storage *STV_alloc(struct sess *sp, size_t size); From phk at projects.linpro.no Sat Jul 19 07:19:13 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 09:19:13 +0200 (CEST) Subject: r2954 - in trunk/varnish-cache: include lib/libvarnish Message-ID: <20080719071913.2ADF01EC10F@projects.linpro.no> Author: phk Date: 2008-07-19 09:19:12 +0200 (Sat, 19 Jul 2008) New Revision: 2954 Modified: trunk/varnish-cache/include/libvarnish.h trunk/varnish-cache/lib/libvarnish/argv.c Log: Augment ParseArgv() to also split comma separated lists. Modified: trunk/varnish-cache/include/libvarnish.h =================================================================== --- trunk/varnish-cache/include/libvarnish.h 2008-07-19 06:46:42 UTC (rev 2953) +++ trunk/varnish-cache/include/libvarnish.h 2008-07-19 07:19:12 UTC (rev 2954) @@ -39,7 +39,9 @@ /* from libvarnish/argv.c */ void FreeArgv(char **argv); -char **ParseArgv(const char *s, int comment); +char **ParseArgv(const char *s, int flag); +#define ARGV_COMMENT (1 << 0) +#define ARGV_COMMA (1 << 1) /* from libvarnish/crc32.c */ uint32_t crc32(uint32_t crc, const void *p1, unsigned l); Modified: trunk/varnish-cache/lib/libvarnish/argv.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/argv.c 2008-07-19 06:46:42 UTC (rev 2953) +++ trunk/varnish-cache/lib/libvarnish/argv.c 2008-07-19 07:19:12 UTC (rev 2954) @@ -124,8 +124,11 @@ return (p); } +static char err_invalid_backslash[] = "Invalid backslash sequence"; +static char err_missing_quote[] = "Missing '\"'"; + char ** -ParseArgv(const char *s, int comment) +ParseArgv(const char *s, int flag) { char **argv; const char *p; @@ -146,7 +149,7 @@ s++; continue; } - if (comment && *s == '#') + if ((flag & ARGV_COMMENT) && *s == '#') break; if (*s == '"') { p = ++s; @@ -159,7 +162,7 @@ if (*s == '\\') { i = BackSlash(s, NULL); if (i == 0) { - argv[0] = (void*)(uintptr_t)"Invalid backslash sequence"; + argv[0] = err_invalid_backslash; return (argv); } s += i; @@ -168,13 +171,15 @@ if (!quote) { if (*s == '\0' || isspace(*s)) break; + if ((flag & ARGV_COMMA) && *s == ',') + break; s++; continue; } if (*s == '"') break; if (*s == '\0') { - argv[0] = (void*)(uintptr_t)"Missing '\"'"; + argv[0] = err_missing_quote; return (argv); } s++; From phk at projects.linpro.no Sat Jul 19 09:24:08 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 11:24:08 +0200 (CEST) Subject: r2955 - trunk/varnish-cache/bin/varnishd Message-ID: <20080719092408.856E81EC0E1@projects.linpro.no> Author: phk Date: 2008-07-19 11:24:07 +0200 (Sat, 19 Jul 2008) New Revision: 2955 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/flint.lnt 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 trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/bin/varnishd/stevedore.h trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/storage_malloc.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Wash & cleaning of the -h and -s argument handling. No functional changes. Add ARGV_ERR() macro for reporting argument trouble. Do selection of method in varnishd.c, using generic choice function. Split subarguments into argc+argv at commans, and pass those down to avoid repetitive and bogus string munging. Catch more error conditions with respect to subarguments. Add mini_obj magics to stevedores and slingers. Generally tidy up along the way. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-19 09:24:07 UTC (rev 2955) @@ -464,7 +464,7 @@ int HSH_Compare(const struct sess *sp, const struct objhead *o); void HSH_Copy(const struct sess *sp, const struct objhead *o); struct object *HSH_Lookup(struct sess *sp); -void HSH_Unbusy(struct sess *sp); +void HSH_Unbusy(const struct sess *sp); void HSH_Ref(struct object *o); void HSH_Deref(struct object *o); double HSH_Grace(double g); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2008-07-19 09:24:07 UTC (rev 2955) @@ -302,7 +302,7 @@ } void -HSH_Unbusy(struct sess *sp) +HSH_Unbusy(const struct sess *sp) { struct object *o; struct objhead *oh; Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/common.h 2008-07-19 09:24:07 UTC (rev 2955) @@ -58,3 +58,9 @@ /* Really belongs in mgt.h, but storage_file chokes on both */ void mgt_child_inherit(int fd, const char *what); + +#define ARGV_ERR(...) \ + do { \ + fprintf(stderr, "Error: " __VA_ARGS__); \ + exit(2); \ + } while (0); Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2008-07-19 09:24:07 UTC (rev 2955) @@ -59,6 +59,7 @@ -emacro(827, assert) // loop not reachable -emacro(774, assert) // booelan always true -emacro(774, HTTPH) // always false +-emacro(527, ARGV_ERR) // unreachable // cache.h -emacro(506, INCOMPL) // Constant value Boolean Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_classic.c 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/hash_classic.c 2008-07-19 09:24:07 UTC (rev 2955) @@ -68,15 +68,19 @@ * The ->init method allows the management process to pass arguments */ -static int -hcl_init(const char *p) +static void +hcl_init(int ac, char * const *av) { int i; unsigned u; - i = sscanf(p, "%u", &u); + if (ac == 0) + return; + if (ac > 1) + ARGV_ERR("(-hclassic) too many arguments\n"); + i = sscanf(av[0], "%u", &u); if (i <= 0 || u == 0) - return (0); + return; if (u > 2 && !(u & (u - 1))) { fprintf(stderr, "NOTE:\n" @@ -88,7 +92,7 @@ } hcl_nhash = u; fprintf(stderr, "Classic hash: %u buckets\n", hcl_nhash); - return (0); + return; } /*-------------------------------------------------------------------- @@ -245,9 +249,10 @@ /*--------------------------------------------------------------------*/ struct hash_slinger hcl_slinger = { - "classic", - hcl_init, - hcl_start, - hcl_lookup, - hcl_deref, + .magic = SLINGER_MAGIC, + .name = "classic", + .init = hcl_init, + .start = hcl_start, + .lookup = hcl_lookup, + .deref = hcl_deref, }; Modified: trunk/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2008-07-19 09:24:07 UTC (rev 2955) @@ -139,9 +139,9 @@ /*--------------------------------------------------------------------*/ struct hash_slinger hsl_slinger = { - "simple_list", - NULL, - hsl_start, - hsl_lookup, - hsl_deref, + .magic = SLINGER_MAGIC, + .name = "simple", + .start = hsl_start, + .lookup = hsl_lookup, + .deref = hsl_deref, }; Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2008-07-19 09:24:07 UTC (rev 2955) @@ -31,12 +31,14 @@ struct sess; -typedef int hash_init_f(const char *); +typedef void hash_init_f(int ac, char * const *av); typedef void hash_start_f(void); typedef struct objhead *hash_lookup_f(const struct sess *sp, struct objhead *nobj); typedef int hash_deref_f(const struct objhead *obj); struct hash_slinger { + unsigned magic; +#define SLINGER_MAGIC 0x1b720cba const char *name; hash_init_f *init; hash_start_f *start; Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2008-07-19 09:24:07 UTC (rev 2955) @@ -63,11 +63,7 @@ int mgt_has_vcl(void); extern char *mgt_cc_cmd; -#include "hash_slinger.h" -extern struct hash_slinger hsl_slinger; -extern struct hash_slinger hcl_slinger; - #define REPORT0(pri, fmt) \ do { \ fprintf(stderr, fmt "\n"); \ Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2008-07-19 09:24:07 UTC (rev 2955) @@ -37,9 +37,6 @@ #include "cache.h" #include "stevedore.h" -extern struct stevedore sma_stevedore; -extern struct stevedore smf_stevedore; - static VTAILQ_HEAD(, stevedore) stevedores = VTAILQ_HEAD_INITIALIZER(stevedores); @@ -95,47 +92,21 @@ st->stevedore->free(st); } -static int -cmp_storage(const struct stevedore *s, const char *p, const char *q) -{ - unsigned u; - - u = pdiff(p, q); - if (strlen(s->name) != u) - return (1); - if (strncmp(s->name, p, u)) - return (1); - return (0); -} - void -STV_add(const char *spec) +STV_add(const struct stevedore *stv2, int ac, char * const *av) { - const char *p, *q; struct stevedore *stv; - p = strchr(spec, ','); - if (p == NULL) - q = p = strchr(spec, '\0'); - else - q = p + 1; - xxxassert(p != NULL); - xxxassert(q != NULL); - - stv = malloc(sizeof *stv); + CHECK_OBJ_NOTNULL(stv2, STEVEDORE_MAGIC); + ALLOC_OBJ(stv, STEVEDORE_MAGIC); AN(stv); - if (!cmp_storage(&sma_stevedore, spec, p)) { - *stv = sma_stevedore; - } else if (!cmp_storage(&smf_stevedore, spec, p)) { - *stv = smf_stevedore; - } else { - fprintf(stderr, "Unknown storage method \"%.*s\"\n", - (int)(p - spec), spec); - exit (2); - } + *stv = *stv2; + if (stv->init != NULL) - stv->init(stv, q); + stv->init(stv, ac, av); + else if (ac != 0) + ARGV_ERR("(-s%s) too many arguments\n", stv->name); VTAILQ_INSERT_TAIL(&stevedores, stv, list); Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2008-07-19 09:24:07 UTC (rev 2955) @@ -35,13 +35,15 @@ struct sess; struct iovec; -typedef void storage_init_f(struct stevedore *, const char *spec); +typedef void storage_init_f(struct stevedore *, int ac, char * const *av); typedef void storage_open_f(const struct stevedore *); typedef struct storage *storage_alloc_f(struct stevedore *, size_t size); typedef void storage_trim_f(const struct storage *, size_t size); typedef void storage_free_f(const struct storage *); struct stevedore { + unsigned magic; +#define STEVEDORE_MAGIC 0x4baf43db const char *name; storage_init_f *init; /* called by mgt process */ storage_open_f *open; /* called by cache process */ @@ -58,5 +60,5 @@ struct storage *STV_alloc(struct sess *sp, size_t size); void STV_trim(const struct storage *st, size_t size); void STV_free(const struct storage *st); -void STV_add(const char *spec); +void STV_add(const struct stevedore *stv, int ac, char * const *av); void STV_open(void); Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-19 09:24:07 UTC (rev 2955) @@ -108,7 +108,7 @@ }; struct smf_sc { - char *filename; + const char *filename; int fd; unsigned pagesize; uintmax_t filesize; @@ -172,11 +172,8 @@ } else { q = str2bytes(size, &l, fssize); - if (q != NULL) { - fprintf(stderr, - "Error: (-sfile) size \"%s\": %s\n", size, q); - exit (2); - } + if (q != NULL) + ARGV_ERR("(-sfile) size \"%s\": %s\n", size, q); } /* @@ -206,12 +203,9 @@ /* round down to multiple of filesystem blocksize or pagesize */ l -= (l % bs); - if (l < MINPAGES * (uintmax_t)sc->pagesize) { - fprintf(stderr, - "Error: size too small, at least %ju needed\n", + if (l < MINPAGES * (uintmax_t)sc->pagesize) + ARGV_ERR("size too small, at least %ju needed\n", (uintmax_t)MINPAGES * sc->pagesize); - exit (2); - } if (sizeof(void *) == 4 && l > INT32_MAX) { /*lint !e506 !e774 */ fprintf(stderr, @@ -238,15 +232,33 @@ /* XXX: force block allocation here or in open ? */ } +static char default_size[] = "50%"; +static char default_filename[] = "."; + static void -smf_init(struct stevedore *parent, const char *spec) +smf_init(struct stevedore *parent, int ac, char * const *av) { - char *size; - char *p, *q; + const char *size, *fn; + char *q, *p; struct stat st; struct smf_sc *sc; unsigned u; + AZ(av[ac]); + + fn = default_filename; + size = default_size; + + if (ac > 2) + ARGV_ERR("(-sfile) too many arguments\n"); + if (ac > 0 && *av[0] != '\0') + fn = av[0]; + if (ac > 1 && *av[1] != '\0') + size = av[1]; + + AN(fn); + AN(size); + sc = calloc(sizeof *sc, 1); XXXAN(sc); VTAILQ_INIT(&sc->order); @@ -257,82 +269,52 @@ parent->priv = sc; - /* If no size specified, use 50% of filesystem free space */ - if (spec == NULL || *spec == '\0') - asprintf(&p, ".,50%%"); - else if (strchr(spec, ',') == NULL) - asprintf(&p, "%s,", spec); - else - p = strdup(spec); - XXXAN(p); - size = strchr(p, ','); - XXXAN(size); - - *size++ = '\0'; - /* try to create a new file of this name */ - sc->fd = open(p, O_RDWR | O_CREAT | O_EXCL, 0600); + sc->fd = open(fn, O_RDWR | O_CREAT | O_EXCL, 0600); if (sc->fd >= 0) { - sc->filename = p; + sc->filename = fn; mgt_child_inherit(sc->fd, "storage_file"); smf_initfile(sc, size, 1); return; } /* it must exist then */ - if (stat(p, &st)) { - fprintf(stderr, - "Error: (-sfile) \"%s\" " - "does not exist and could not be created\n", p); - exit (2); - } + if (stat(fn, &st)) + ARGV_ERR("(-sfile) \"%s\" " + "does not exist and could not be created\n", fn); /* and it should be a file or directory */ - if (!(S_ISREG(st.st_mode) || S_ISDIR(st.st_mode))) { - fprintf(stderr, - "Error: (-sfile) \"%s\" " - "is neither file nor directory\n", p); - exit (2); - } + if (!(S_ISREG(st.st_mode) || S_ISDIR(st.st_mode))) + ARGV_ERR("(-sfile) \"%s\" is neither file nor directory\n", fn); if (S_ISREG(st.st_mode)) { - sc->fd = open(p, O_RDWR); - if (sc->fd < 0) { - fprintf(stderr, - "Error: (-sfile) \"%s\" " - "could not open (%s)\n", p, strerror(errno)); - exit (2); - } + sc->fd = open(fn, O_RDWR); + if (sc->fd < 0) + ARGV_ERR("(-sfile) \"%s\" could not open (%s)\n", + fn, strerror(errno)); AZ(fstat(sc->fd, &st)); - if (!S_ISREG(st.st_mode)) { - fprintf(stderr, - "Error: (-sfile) \"%s\" " - "was not a file after opening\n", p); - exit (2); - } - sc->filename = p; + if (!S_ISREG(st.st_mode)) + ARGV_ERR("(-sfile) \"%s\" " + "was not a file after opening\n", fn); + sc->filename = fn; mgt_child_inherit(sc->fd, "storage_file"); smf_initfile(sc, size, 0); return; } - - asprintf(&q, "%s/varnish.XXXXXX", p); + asprintf(&q, "%s/varnish.XXXXXX", fn); XXXAN(q); sc->fd = mkstemp(q); - if (sc->fd < 0) { - fprintf(stderr, - "Error: (-sfile) \"%s\" " - "mkstemp(%s) failed (%s)\n", p, q, strerror(errno)); - exit (2); - } + if (sc->fd < 0) + ARGV_ERR("(-sfile) \"%s\" " + "mkstemp(%s) failed (%s)\n", fn, q, strerror(errno)); AZ(unlink(q)); - asprintf(&sc->filename, "%s (unlinked)", q); - XXXAN(sc->filename); + asprintf(&p, "%s (unlinked)", q); + XXXAN(p); + sc->filename = p; free(q); smf_initfile(sc, size, 1); mgt_child_inherit(sc->fd, "storage_file"); - free(p); } /*-------------------------------------------------------------------- @@ -705,12 +687,13 @@ /*--------------------------------------------------------------------*/ struct stevedore smf_stevedore = { - .name = "file", - .init = smf_init, - .open = smf_open, - .alloc = smf_alloc, - .trim = smf_trim, - .free = smf_free, + .magic = STEVEDORE_MAGIC, + .name = "file", + .init = smf_init, + .open = smf_open, + .alloc = smf_alloc, + .trim = smf_trim, + .free = smf_free, }; #ifdef INCLUDE_TEST_DRIVER Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2008-07-19 09:24:07 UTC (rev 2955) @@ -123,26 +123,26 @@ } static void -sma_init(struct stevedore *parent, const char *spec) +sma_init(struct stevedore *parent, int ac, char * const *av) { const char *e; uintmax_t u; (void)parent; - if (spec != NULL && *spec != '\0') { - e = str2bytes(spec, &u, 0); - if (e != NULL) { - fprintf(stderr, - "Error: (-smalloc) size \"%s\": %s\n", spec, e); - exit(2); - } - if ((u != (uintmax_t)(size_t)u)) { - fprintf(stderr, - "Error: (-smalloc) size \"%s\": too big\n", spec); - exit(2); - } - sma_max = u; - } + + AZ(av[ac]); + if (ac > 1) + ARGV_ERR("(-smalloc) too many arguments\n"); + + if (ac == 0 || *av[0] == '\0') + return; + + e = str2bytes(av[0], &u, 0); + if (e != NULL) + ARGV_ERR("(-smalloc) size \"%s\": %s\n", av[0], e); + if ((u != (uintmax_t)(size_t)u)) + ARGV_ERR("(-smalloc) size \"%s\": too big\n", av[0]); + sma_max = u; } static void @@ -153,10 +153,11 @@ } struct stevedore sma_stevedore = { - .name = "malloc", - .init = sma_init, - .open = sma_open, - .alloc = sma_alloc, - .free = sma_free, - .trim = sma_trim, + .magic = STEVEDORE_MAGIC, + .name = "malloc", + .init = sma_init, + .open = sma_open, + .alloc = sma_alloc, + .free = sma_free, + .trim = sma_trim, }; Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2008-07-19 07:19:12 UTC (rev 2954) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2008-07-19 09:24:07 UTC (rev 2955) @@ -67,6 +67,7 @@ #include "shmlog.h" #include "heritage.h" #include "mgt.h" +#include "hash_slinger.h" #include "stevedore.h" /* INFTIM indicates an infinite timeout for poll(2) */ @@ -79,47 +80,97 @@ /*--------------------------------------------------------------------*/ -static int -cmp_hash(const struct hash_slinger *s, const char *p, const char *q) +struct choice { + const char *name; + void *ptr; +}; + +static void * +pick(const struct choice *cp, const char *which, const char *kind) { - if (strlen(s->name) != (q - p)) - return (1); - if (strncmp(s->name, p, (q - p))) - return (1); - return (0); + + for(; cp->name != NULL; cp++) { + if (!strcmp(cp->name, which)) + return (cp->ptr); + } + ARGV_ERR("Unknown %s method \"%s\"\n", kind, which); } +/*--------------------------------------------------------------------*/ + +extern struct stevedore sma_stevedore; +extern struct stevedore smf_stevedore; + +static struct choice stv_choice[] = { + { "file", &smf_stevedore }, + { "malloc", &sma_stevedore }, + { NULL, NULL } +}; + static void -setup_hash(const char *s_arg) +setup_storage(const char *spec) { - const char *p, *q; + char **av; + void *priv; + int ac; + + av = ParseArgv(spec, ARGV_COMMA); + + if (av[0] != NULL) + ARGV_ERR("%s\n", av[0]); + + if (av[1] == NULL) + ARGV_ERR("-s argument is empty\n"); + + for (ac = 0; av[ac + 2] != NULL; ac++) + continue; + + priv = pick(stv_choice, av[1], "storage"); + AN(priv); + + STV_add(priv, ac, av + 2); + + /* We do not free av, to make life simpler for stevedores */ +} + +/*--------------------------------------------------------------------*/ + +extern struct hash_slinger hsl_slinger; +extern struct hash_slinger hcl_slinger; + +static struct choice hsh_choice[] = { + { "classic", &hcl_slinger }, + { "simple", &hsl_slinger }, + { "simple_list", &hsl_slinger }, /* backwards compat */ + { NULL, NULL } +}; + +static void +setup_hash(const char *h_arg) +{ + char **av; + int ac; struct hash_slinger *hp; - p = strchr(s_arg, ','); - if (p == NULL) - q = p = strchr(s_arg, '\0'); - else - q = p + 1; - xxxassert(p != NULL); - xxxassert(q != NULL); - if (!cmp_hash(&hcl_slinger, s_arg, p)) { - hp = &hcl_slinger; - } else if (!cmp_hash(&hsl_slinger, s_arg, p)) { - hp = &hsl_slinger; - } else { - fprintf(stderr, "Unknown hash method \"%.*s\"\n", - (int)(p - s_arg), s_arg); - exit (2); - } + av = ParseArgv(h_arg, ARGV_COMMA); + + if (av[0] != NULL) + ARGV_ERR("%s\n", av[0]); + + if (av[1] == NULL) + ARGV_ERR("-h argument is empty\n"); + + for (ac = 0; av[ac + 2] != NULL; ac++) + continue; + + hp = pick(hsh_choice, av[1], "hash"); + CHECK_OBJ_NOTNULL(hp, SLINGER_MAGIC); heritage.hash = hp; - if (hp->init != NULL) { - if (hp->init(q)) - exit (1); - } else if (*q) { - fprintf(stderr, "Hash method \"%s\" takes no arguments\n", + if (hp->init != NULL) + hp->init(ac, av + 2); + else if (ac > 0) + ARGV_ERR("Hash method \"%s\" takes no arguments\n", hp->name); - exit (1); - } } /*--------------------------------------------------------------------*/ @@ -436,7 +487,7 @@ break; case 's': s_arg_given = 1; - STV_add(optarg); + setup_storage(optarg); break; case 't': MCF_ParamSet(cli, "default_ttl", optarg); @@ -538,7 +589,7 @@ exit (0); if (!s_arg_given) - STV_add(s_arg); + setup_storage(s_arg); setup_hash(h_arg); From phk at projects.linpro.no Sat Jul 19 09:44:41 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 11:44:41 +0200 (CEST) Subject: r2956 - in trunk/varnish-cache: include lib/libvarnish Message-ID: <20080719094441.488261EC0EA@projects.linpro.no> Author: phk Date: 2008-07-19 11:44:40 +0200 (Sat, 19 Jul 2008) New Revision: 2956 Modified: trunk/varnish-cache/include/cli_priv.h trunk/varnish-cache/lib/libvarnish/cli_common.c Log: Don't constify the cli argument to cli_out() Modified: trunk/varnish-cache/include/cli_priv.h =================================================================== --- trunk/varnish-cache/include/cli_priv.h 2008-07-19 09:24:07 UTC (rev 2955) +++ trunk/varnish-cache/include/cli_priv.h 2008-07-19 09:44:40 UTC (rev 2956) @@ -53,7 +53,7 @@ }; /* The implementation must provide these functions */ -void cli_out(const struct cli *cli, const char *fmt, ...); +void cli_out(struct cli *cli, const char *fmt, ...); void cli_param(struct cli *cli); void cli_result(struct cli *cli, unsigned r); Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-19 09:24:07 UTC (rev 2955) +++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-19 09:44:40 UTC (rev 2956) @@ -55,7 +55,7 @@ #include "cli_common.h" void -cli_out(const struct cli *cli, const char *fmt, ...) +cli_out(struct cli *cli, const char *fmt, ...) { va_list ap; From phk at projects.linpro.no Sat Jul 19 09:50:43 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 11:50:43 +0200 (CEST) Subject: r2957 - trunk/varnish-cache/bin/varnishd Message-ID: <20080719095043.155221EC0E1@projects.linpro.no> Author: phk Date: 2008-07-19 11:50:42 +0200 (Sat, 19 Jul 2008) New Revision: 2957 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c Log: Remove pointless volatile Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2008-07-19 09:44:40 UTC (rev 2956) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2008-07-19 09:50:42 UTC (rev 2957) @@ -201,7 +201,7 @@ static void ccf_purge_list(struct cli *cli, const char * const *av, void *priv) { - struct ban * volatile b0; + struct ban *b0; (void)av; (void)priv; From phk at projects.linpro.no Sat Jul 19 09:51:41 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 11:51:41 +0200 (CEST) Subject: r2958 - trunk/varnish-cache/bin/varnishd Message-ID: <20080719095141.84E9E1EC10F@projects.linpro.no> Author: phk Date: 2008-07-19 11:51:41 +0200 (Sat, 19 Jul 2008) New Revision: 2958 Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c Log: Unused struct member. Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-07-19 09:50:42 UTC (rev 2957) +++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-07-19 09:51:41 UTC (rev 2958) @@ -56,7 +56,6 @@ unsigned magic; #define VDI_RANDOM_MAGIC 0x3771ae23 struct director dir; - struct backend *backend; struct vdi_random_host *hosts; unsigned nhosts; }; From phk at projects.linpro.no Sat Jul 19 10:40:13 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 12:40:13 +0200 (CEST) Subject: r2959 - trunk/varnish-cache/lib/libvarnish Message-ID: <20080719104013.ED1681EC0E1@projects.linpro.no> Author: phk Date: 2008-07-19 12:40:13 +0200 (Sat, 19 Jul 2008) New Revision: 2959 Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c Log: Add a protocol version number ("1.0") to the ping response. Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-19 09:51:41 UTC (rev 2958) +++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-19 10:40:13 UTC (rev 2959) @@ -191,5 +191,5 @@ (void)priv; (void)av; t = time(NULL); - cli_out(cli, "PONG %ld", t); + cli_out(cli, "PONG %ld 1.0", t); } From phk at projects.linpro.no Sat Jul 19 11:33:25 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 13:33:25 +0200 (CEST) Subject: r2960 - trunk/varnish-cache/lib/libvarnish Message-ID: <20080719113325.3C8281EC0EA@projects.linpro.no> Author: phk Date: 2008-07-19 13:33:24 +0200 (Sat, 19 Jul 2008) New Revision: 2960 Modified: trunk/varnish-cache/lib/libvarnish/num.c Log: FlexeLint inspired polishing: Detect empty args. Handle 'b' suffix in switch. Modified: trunk/varnish-cache/lib/libvarnish/num.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/num.c 2008-07-19 10:40:13 UTC (rev 2959) +++ trunk/varnish-cache/lib/libvarnish/num.c 2008-07-19 11:33:24 UTC (rev 2960) @@ -45,6 +45,9 @@ double fval; char *end; + if (p == NULL || *p == '\0') + return ("missing number"); + fval = strtod(p, &end); if (end == p || !isfinite(fval)) return ("Invalid number"); @@ -88,12 +91,13 @@ fval *= (uintmax_t)1 << 60; ++end; break; + case 'b': case 'B': + ++end; + break; + default: + break; } - /* accept 'b' for 'bytes' */ - if (end[0] == 'b' || end[0] == 'B') - ++end; - if (end[0] != '\0') return ("Invalid suffix"); } From phk at projects.linpro.no Sat Jul 19 11:38:32 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 13:38:32 +0200 (CEST) Subject: r2961 - trunk/varnish-cache/lib/libvarnish Message-ID: <20080719113832.3B2CC1EC0E1@projects.linpro.no> Author: phk Date: 2008-07-19 13:38:31 +0200 (Sat, 19 Jul 2008) New Revision: 2961 Modified: trunk/varnish-cache/lib/libvarnish/argv.c Log: FlexeLint inspired polishing: Better choice of data types. Modified: trunk/varnish-cache/lib/libvarnish/argv.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/argv.c 2008-07-19 11:33:24 UTC (rev 2960) +++ trunk/varnish-cache/lib/libvarnish/argv.c 2008-07-19 11:38:31 UTC (rev 2961) @@ -48,32 +48,33 @@ #include "libvarnish.h" static int -BackSlash(const char *s, int *res) +BackSlash(const char *s, char *res) { - int i, r; + int r; + char c; unsigned u; assert(*s == '\\'); - r = i = 0; + r = c = 0; switch(s[1]) { case 'n': - i = '\n'; + c = '\n'; r = 2; break; case 'r': - i = '\r'; + c = '\r'; r = 2; break; case 't': - i = '\t'; + c = '\t'; r = 2; break; case '"': - i = '"'; + c = '"'; r = 2; break; case '\\': - i = '\\'; + c = '\\'; r = 2; break; case '0': case '1': case '2': case '3': @@ -83,13 +84,14 @@ break; if (s[r] - '0' > 7) break; - i <<= 3; - i |= s[r] - '0'; + c <<= 3; /*lint !e701 signed left shift */ + c |= s[r] - '0'; } break; case 'x': if (1 == sscanf(s + 1, "x%02x", &u)) { - i = u; + assert(!(u & ~0xff)); + c = u; /*lint !e734 loss of precision */ r = 4; } break; @@ -97,7 +99,7 @@ break; } if (res != NULL) - *res = i; + *res = c; return (r); } @@ -106,7 +108,7 @@ { const char *q; char *p, *r; - int i, j; + int i; p = calloc((e - s) + 1, 1); if (p == NULL) @@ -116,9 +118,9 @@ *r++ = *q++; continue; } - i = BackSlash(q, &j); + i = BackSlash(q, r); q += i; - *r++ = j; + r++; } *r = '\0'; return (p); From phk at projects.linpro.no Sat Jul 19 11:43:51 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 13:43:51 +0200 (CEST) Subject: r2962 - trunk/varnish-cache/lib/libvarnish Message-ID: <20080719114351.63CD21EC0EA@projects.linpro.no> Author: phk Date: 2008-07-19 13:43:51 +0200 (Sat, 19 Jul 2008) New Revision: 2962 Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c Log: Explicitly silence three FlexeLint complaints Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-19 11:38:31 UTC (rev 2961) +++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-19 11:43:51 UTC (rev 2962) @@ -54,6 +54,7 @@ #include "cli_priv.h" #include "cli_common.h" +/*lint -e{818} cli could be const */ void cli_out(struct cli *cli, const char *fmt, ...) { @@ -72,7 +73,7 @@ { if (cli != NULL) - cli->result = res; + cli->result = res; /*lint !e64 type mismatch */ else printf("CLI result = %d\n", res); } @@ -97,7 +98,7 @@ */ assert(cli->result >= 100); - assert(cli->result <= 999); + assert(cli->result <= 999); /*lint !e650 const out of range */ i = snprintf(res, sizeof res, "%-3d %-8d\n", cli->result, vsb_len(cli->sb)); assert(i == CLI_LINE0_LEN); From phk at projects.linpro.no Sat Jul 19 11:44:41 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 13:44:41 +0200 (CEST) Subject: r2963 - trunk/varnish-cache/bin/varnishd Message-ID: <20080719114441.4ECB41EC0E1@projects.linpro.no> Author: phk Date: 2008-07-19 13:44:41 +0200 (Sat, 19 Jul 2008) New Revision: 2963 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Deal appropriately with ParseArgv returning NULL Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-19 11:43:51 UTC (rev 2962) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-19 11:44:41 UTC (rev 2963) @@ -324,6 +324,11 @@ } av = ParseArgv(arg, 0); + if (av == NULL) { + cli_out(cli, "Parse error: out of memory"); + cli_result(cli, CLIS_PARAM); + return; + } if (av[0] != NULL) { cli_out(cli, "Parse error: %s", av[0]); cli_result(cli, CLIS_PARAM); Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2008-07-19 11:43:51 UTC (rev 2962) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2008-07-19 11:44:41 UTC (rev 2963) @@ -115,6 +115,7 @@ int ac; av = ParseArgv(spec, ARGV_COMMA); + AN(av); if (av[0] != NULL) ARGV_ERR("%s\n", av[0]); @@ -153,6 +154,7 @@ struct hash_slinger *hp; av = ParseArgv(h_arg, ARGV_COMMA); + AN(av); if (av[0] != NULL) ARGV_ERR("%s\n", av[0]); From phk at projects.linpro.no Sat Jul 19 11:49:43 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 13:49:43 +0200 (CEST) Subject: r2964 - trunk/varnish-cache/bin/varnishd Message-ID: <20080719114943.D9B7C1EC0EA@projects.linpro.no> Author: phk Date: 2008-07-19 13:49:43 +0200 (Sat, 19 Jul 2008) New Revision: 2964 Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c Log: Explicitly specify index in name array. Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-19 11:44:41 UTC (rev 2963) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-19 11:49:43 UTC (rev 2964) @@ -66,7 +66,7 @@ /* step names */ static const char *steps[] = { -#define STEP(l, u) "STP_" #u, +#define STEP(l, u) [STP_##u] = "STP_" #u, #include "steps.h" #undef STEP }; From phk at projects.linpro.no Sat Jul 19 11:50:10 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 13:50:10 +0200 (CEST) Subject: r2965 - trunk/varnish-cache/bin/varnishd Message-ID: <20080719115010.1D9441EC0E1@projects.linpro.no> Author: phk Date: 2008-07-19 13:50:09 +0200 (Sat, 19 Jul 2008) New Revision: 2965 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_ws.c Log: Constify WS_Free() Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-19 11:49:43 UTC (rev 2964) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-19 11:50:09 UTC (rev 2965) @@ -602,7 +602,7 @@ char *WS_Alloc(struct ws *ws, unsigned bytes); char *WS_Dup(struct ws *ws, const char *); char *WS_Snapshot(struct ws *ws); -unsigned WS_Free(struct ws *ws); +unsigned WS_Free(const struct ws *ws); /* rfc2616.c */ int RFC2616_cache_policy(const struct sess *sp, const struct http *hp); Modified: trunk/varnish-cache/bin/varnishd/cache_ws.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ws.c 2008-07-19 11:49:43 UTC (rev 2964) +++ trunk/varnish-cache/bin/varnishd/cache_ws.c 2008-07-19 11:50:09 UTC (rev 2965) @@ -130,7 +130,7 @@ } unsigned -WS_Free(struct ws *ws) +WS_Free(const struct ws *ws) { WS_Assert(ws); From phk at projects.linpro.no Sat Jul 19 12:03:16 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 14:03:16 +0200 (CEST) Subject: r2966 - trunk/varnish-cache/lib/libvarnish Message-ID: <20080719120316.8CE811EC0EA@projects.linpro.no> Author: phk Date: 2008-07-19 14:03:16 +0200 (Sat, 19 Jul 2008) New Revision: 2966 Modified: trunk/varnish-cache/lib/libvarnish/vss.c Log: Explain to FlexeLint that _storage is not referenced. Modified: trunk/varnish-cache/lib/libvarnish/vss.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vss.c 2008-07-19 11:50:09 UTC (rev 2965) +++ trunk/varnish-cache/lib/libvarnish/vss.c 2008-07-19 12:03:16 UTC (rev 2966) @@ -66,6 +66,8 @@ } va_addr; }; +/*lint -esym(754, _storage) not ref */ + /* * Take a string provided by the user and break it up into address and * port parts. Examples of acceptable input include: From phk at projects.linpro.no Sat Jul 19 12:04:25 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 14:04:25 +0200 (CEST) Subject: r2967 - trunk/varnish-cache/bin/varnishd Message-ID: <20080719120425.E11001EC0E1@projects.linpro.no> Author: phk Date: 2008-07-19 14:04:25 +0200 (Sat, 19 Jul 2008) New Revision: 2967 Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_vary.c trunk/varnish-cache/bin/varnishd/flint.lnt trunk/varnish-cache/bin/varnishd/flint.sh trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Technically speaking, vsb_len() could return -1, except it won't because of the vsb_overflow() assert. Make this explicit for FlexeLint. Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2008-07-19 12:03:16 UTC (rev 2966) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2008-07-19 12:04:25 UTC (rev 2967) @@ -40,7 +40,6 @@ #include "shmlog.h" #include "cache.h" #include "stevedore.h" -#include "cli.h" #include "cli_priv.h" static unsigned fetchfrag; @@ -204,7 +203,7 @@ /*--------------------------------------------------------------------*/ static void -dump_st(struct sess *sp, struct storage *st) +dump_st(const struct sess *sp, const struct storage *st) { txt t; @@ -247,7 +246,7 @@ st->len += i; sp->obj->len += i; } - if (st != NULL && fetchfrag > 0) + if (fetchfrag > 0) dump_st(sp, st); if (st->len == 0) { @@ -272,7 +271,7 @@ unsigned long content_length; char buf[8192]; char *ptr, *endp; - int read; + int rdcnt; if (http_GetHdr(sp->http, H_Content_Length, &ptr)) { @@ -280,16 +279,16 @@ /* XXX should check result of conversion */ while (content_length) { if (content_length > sizeof buf) - read = sizeof buf; + rdcnt = sizeof buf; else - read = content_length; - read = HTC_Read(sp->htc, buf, read); - if (read <= 0) + rdcnt = content_length; + rdcnt = HTC_Read(sp->htc, buf, rdcnt); + if (rdcnt <= 0) return (1); - content_length -= read; + content_length -= rdcnt; if (!sp->sendbody) continue; - WRK_Write(sp->wrk, buf, read); + WRK_Write(sp->wrk, buf, rdcnt); /* XXX: stats ? */ if (WRK_Flush(sp->wrk)) return (2); } @@ -342,7 +341,7 @@ return (__LINE__); TCP_blocking(vc->fd); /* XXX: we should timeout instead */ WRK_Reset(w, &vc->fd); - http_Write(w, hp, 0); + http_Write(w, hp, 0); /* XXX: stats ? */ /* Deal with any message-body the request might have */ i = FetchReqBody(sp); Modified: trunk/varnish-cache/bin/varnishd/cache_vary.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vary.c 2008-07-19 12:03:16 UTC (rev 2966) +++ trunk/varnish-cache/bin/varnishd/cache_vary.c 2008-07-19 12:04:25 UTC (rev 2967) @@ -67,7 +67,7 @@ { char *v, *p, *q, *h, *e; struct vsb *sb, *sbh; - unsigned l; + int l; /* No Vary: header, no worries */ if (!http_GetHdr(sp->obj->http, H_Vary, &v)) @@ -127,6 +127,7 @@ vsb_finish(sb); AZ(vsb_overflowed(sb)); l = vsb_len(sb); + assert(l >= 0); sp->obj->vary = malloc(l); AN(sp->obj->vary); memcpy(sp->obj->vary, vsb_data(sb), l); Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2008-07-19 12:03:16 UTC (rev 2966) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2008-07-19 12:04:25 UTC (rev 2967) @@ -53,7 +53,8 @@ -esym(534, strcpy) // Ignoring return value of function -esym(534, strlcpy) // Ignoring return value of function --emacro(506, isnan) // constant value boolean +-emacro(506, isnan, isfinite) // constant value boolean +-emacro(736, isfinite) // loss of precision -emacro(747, isnan) // significant coersion -emacro(506, assert) // constant value boolean -emacro(827, assert) // loop not reachable Modified: trunk/varnish-cache/bin/varnishd/flint.sh =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.sh 2008-07-19 12:03:16 UTC (rev 2966) +++ trunk/varnish-cache/bin/varnishd/flint.sh 2008-07-19 12:04:25 UTC (rev 2967) @@ -8,7 +8,7 @@ -I../.. \ -DVARNISH_STATE_DIR=\"foo\" \ flint.lnt \ - *.c > $T 2>&1 + *.c ../../lib/libvarnish/*.c > $T 2>&1 for t in Error Warning Info Note do Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-19 12:03:16 UTC (rev 2966) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-19 12:04:25 UTC (rev 2967) @@ -170,6 +170,7 @@ */ l = st.st_size; } else { + AN(size); q = str2bytes(size, &l, fssize); if (q != NULL) Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2008-07-19 12:03:16 UTC (rev 2966) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2008-07-19 12:04:25 UTC (rev 2967) @@ -401,7 +401,7 @@ /*--------------------------------------------------------------------*/ int -main(int argc, char *argv[]) +main(int argc, char * const *argv) { int o; unsigned C_flag = 0; From phk at projects.linpro.no Sat Jul 19 12:38:29 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 19 Jul 2008 14:38:29 +0200 (CEST) Subject: r2968 - trunk/varnish-cache/bin/varnishd Message-ID: <20080719123829.D66861EC0EA@projects.linpro.no> Author: phk Date: 2008-07-19 14:38:28 +0200 (Sat, 19 Jul 2008) New Revision: 2968 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_dir_random.c trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c trunk/varnish-cache/bin/varnishd/cache_dir_simple.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_vary.c Log: More assorted FlexeLint polishing Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-07-19 12:04:25 UTC (rev 2967) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-07-19 12:38:28 UTC (rev 2968) @@ -98,7 +98,7 @@ tmo = params->connect_timeout; if (sp->backend->connect_timeout > 10e-3) - tmo = sp->backend->connect_timeout * 1000; + tmo = (int)(sp->backend->connect_timeout * 1000); if (tmo > 0) i = TCP_connect(s, sa, salen, tmo); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-19 12:04:25 UTC (rev 2967) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-19 12:38:28 UTC (rev 2968) @@ -72,7 +72,6 @@ #include "shmlog.h" #include "vcl.h" -#include "cli.h" #include "cli_priv.h" #include "cache.h" Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-07-19 12:04:25 UTC (rev 2967) +++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2008-07-19 12:38:28 UTC (rev 2968) @@ -61,6 +61,7 @@ }; +/*lint -e{818} not const-able */ static struct backend * vdi_random_choose(struct sess *sp) { @@ -81,6 +82,7 @@ return (NULL); } +/*lint -e{818} not const-able */ static void vdi_random_fini(struct director *d) { Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-19 12:04:25 UTC (rev 2967) +++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-19 12:38:28 UTC (rev 2968) @@ -60,6 +60,7 @@ }; +/*lint -e{818} not const-able */ static struct backend * vdi_round_robin_choose(struct sess *sp) { @@ -75,6 +76,7 @@ return (backend); } +/*lint -e{818} not const-able */ static void vdi_round_robin_fini(struct director *d) { Modified: trunk/varnish-cache/bin/varnishd/cache_dir_simple.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_simple.c 2008-07-19 12:04:25 UTC (rev 2967) +++ trunk/varnish-cache/bin/varnishd/cache_dir_simple.c 2008-07-19 12:38:28 UTC (rev 2968) @@ -54,6 +54,7 @@ struct backend *backend; }; +/*lint -e{818} not const-able */ static struct backend * vdi_simple_choose(struct sess *sp) { @@ -64,6 +65,7 @@ return (vs->backend); } +/*lint -e{818} not const-able */ static void vdi_simple_fini(struct director *d) { Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2008-07-19 12:04:25 UTC (rev 2967) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2008-07-19 12:38:28 UTC (rev 2968) @@ -53,6 +53,7 @@ #include "http_headers.h" #undef HTTPH +/*lint -save -e773 not () */ #define LOGMTX2(ax, bx, cx) [bx] = SLT_##ax##cx #define LOGMTX1(ax) { \ @@ -69,6 +70,7 @@ [HTTP_Tx] = LOGMTX1(Tx), [HTTP_Obj] = LOGMTX1(Obj) }; +/*lint -restore */ static enum shmlogtag http2shmlog(const struct http *hp, int t) @@ -551,20 +553,20 @@ } static void -http_copyreq(struct http *to, const struct http *fm, int transparent) +http_copyreq(struct http *to, const struct http *fm, int how) { CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); - if (transparent) + + if ((how == HTTPH_R_PIPE) || (how == HTTPH_R_PASS)) { http_copyh(to, fm, HTTP_HDR_REQ); - else + http_copyh(to, fm, HTTP_HDR_PROTO); + } else { http_SetH(to, HTTP_HDR_REQ, "GET"); + http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1"); + } http_copyh(to, fm, HTTP_HDR_URL); - if (transparent) - http_copyh(to, fm, HTTP_HDR_PROTO); - else - http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1"); } void @@ -645,8 +647,7 @@ hp = bereq->http; hp->logtag = HTTP_Tx; - http_copyreq(hp, sp->http, - (how == HTTPH_R_PIPE) || (how == HTTPH_R_PASS)); + http_copyreq(hp, sp->http, how); http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how); http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid); http_PrintfHeader(sp->wrk, sp->fd, hp, Modified: trunk/varnish-cache/bin/varnishd/cache_vary.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vary.c 2008-07-19 12:04:25 UTC (rev 2967) +++ trunk/varnish-cache/bin/varnishd/cache_vary.c 2008-07-19 12:38:28 UTC (rev 2968) @@ -107,7 +107,8 @@ e--; /* Encode two byte length and contents */ l = e - h; - vsb_printf(sb, "%c%c", l >> 8, l & 0xff); + assert(!(l & ~0xffff)); + vsb_printf(sb, "%c%c", (unsigned)l >> 8, l & 0xff); vsb_bcat(sb, h, e - h); } else { /* Mark as "not present" */ From phk at projects.linpro.no Sun Jul 20 09:57:26 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 11:57:26 +0200 (CEST) Subject: r2969 - trunk/varnish-cache/bin/varnishd Message-ID: <20080720095726.343111EC0E1@projects.linpro.no> Author: phk Date: 2008-07-20 11:57:25 +0200 (Sun, 20 Jul 2008) New Revision: 2969 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_main.c trunk/varnish-cache/bin/varnishd/cache_pool.c Log: Store the current session in thread private data. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-19 12:38:28 UTC (rev 2968) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-20 09:57:25 UTC (rev 2969) @@ -511,6 +511,8 @@ /* cache_main.c */ void THR_Name(const char *name); +void THR_SetSession(const struct sess *sp); +const struct sess * THR_GetSession(void); /* cache_pipe.c */ void PipeSession(struct sess *sp); @@ -708,8 +710,6 @@ #ifdef WITHOUT_ASSERTS #define spassert(cond) ((void)(cond)) -#define SPAZ(val) ((void)(val) == 0) -#define SPAN(val) ((void)(val) != 0) #else void panic(const char *, int, const char *, const struct sess *, const char *, ...); @@ -720,6 +720,6 @@ panic(__FILE__, __LINE__, __func__, sp, \ "assertion failed: %s\n", #cond); \ } while (0) +#endif #define SPAZ(val) spassert((val) == 0) #define SPAN(val) spassert((val) != 0) -#endif Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2008-07-19 12:38:28 UTC (rev 2968) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2008-07-20 09:57:25 UTC (rev 2969) @@ -41,6 +41,27 @@ #include "stevedore.h" /*-------------------------------------------------------------------- + * Per thread storage for the session currently being processed by + * the thread. This is used for panic messages. + */ + +static pthread_key_t sp_key; + +void +THR_SetSession(const struct sess *sp) +{ + + AZ(pthread_setspecific(sp_key, sp)); +} + +const struct sess * +THR_GetSession(void) +{ + + return (pthread_getspecific(sp_key)); +} + +/*-------------------------------------------------------------------- * Name threads if our pthreads implementation supports it. */ @@ -69,6 +90,8 @@ setbuf(stderr, NULL); printf("Child starts\n"); + AZ(pthread_key_create(&sp_key, NULL)); + THR_Name("cache-main"); CLI_Init(); Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2008-07-19 12:38:28 UTC (rev 2968) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2008-07-20 09:57:25 UTC (rev 2969) @@ -323,6 +323,7 @@ struct sess *sess; CAST_OBJ_NOTNULL(sess, priv, SESS_MAGIC); + THR_SetSession(sess); sess->wrk = w; CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC); CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC); @@ -331,6 +332,7 @@ assert(!isnan(w->used)); CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC); CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC); + THR_SetSession(NULL); } /*--------------------------------------------------------------------*/ From phk at projects.linpro.no Sun Jul 20 10:03:42 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 12:03:42 +0200 (CEST) Subject: r2970 - in trunk/varnish-cache: include lib/libvarnish Message-ID: <20080720100342.B9AE71EC10F@projects.linpro.no> Author: phk Date: 2008-07-20 12:03:42 +0200 (Sun, 20 Jul 2008) New Revision: 2970 Modified: trunk/varnish-cache/include/libvarnish.h trunk/varnish-cache/lib/libvarnish/assert.c Log: Make the backend function of libvarnish' assert facilities pluggable. Modified: trunk/varnish-cache/include/libvarnish.h =================================================================== --- trunk/varnish-cache/include/libvarnish.h 2008-07-20 09:57:25 UTC (rev 2969) +++ trunk/varnish-cache/include/libvarnish.h 2008-07-20 10:03:42 UTC (rev 2970) @@ -72,25 +72,26 @@ * handle gracefully, such as malloc failure. */ +typedef void lbv_assert_f(const char *, const char *, int, const char *, int, int); + +extern lbv_assert_f *lbv_assert; + #ifdef WITHOUT_ASSERTS #define assert(e) ((void)(e)) #else /* WITH_ASSERTS */ #define assert(e) \ do { \ if (!(e)) \ - lbv_assert(__func__, __FILE__, __LINE__, #e, errno); \ + lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 0); \ } while (0) #endif #define xxxassert(e) \ do { \ if (!(e)) \ - lbv_xxxassert(__func__, __FILE__, __LINE__, #e, errno); \ + lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 1); \ } while (0) -void lbv_assert(const char *, const char *, int, const char *, int); -void lbv_xxxassert(const char *, const char *, int, const char *, int); - /* Assert zero return value */ #define AZ(foo) do { assert((foo) == 0); } while (0) #define AN(foo) do { assert((foo) != 0); } while (0) Modified: trunk/varnish-cache/lib/libvarnish/assert.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/assert.c 2008-07-20 09:57:25 UTC (rev 2969) +++ trunk/varnish-cache/lib/libvarnish/assert.c 2008-07-20 10:03:42 UTC (rev 2970) @@ -27,6 +27,8 @@ * SUCH DAMAGE. * * $Id$ + * + * This is the default backend function for libvarnish' assert facilities. */ #include "config.h" @@ -37,30 +39,25 @@ #include "libvarnish.h" -void -lbv_xxxassert(const char *func, const char *file, int line, const char *cond, int err) +static void +lbv_assert_default(const char *func, const char *file, int line, const char *cond, int err, int xxx) { - fprintf(stderr, - "Missing errorhandling code in %s(), %s line %d:\n" - " Condition(%s) not true.\n", - func, file, line, cond); - if (err) + if (xxx) { fprintf(stderr, - " errno = %d (%s)\n", err, strerror(err)); - abort(); -} - -void -lbv_assert(const char *func, const char *file, int line, const char *cond, int err) -{ - - fprintf(stderr, - "Assert error in %s(), %s line %d:\n" - " Condition(%s) not true.\n", - func, file, line, cond); + "Missing errorhandling code in %s(), %s line %d:\n" + " Condition(%s) not true.\n", + func, file, line, cond); + } else { + fprintf(stderr, + "Assert error in %s(), %s line %d:\n" + " Condition(%s) not true.\n", + func, file, line, cond); + } if (err) fprintf(stderr, " errno = %d (%s)\n", err, strerror(err)); abort(); } + +lbv_assert_f *lbv_assert = lbv_assert_default; From phk at projects.linpro.no Sun Jul 20 10:36:28 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 12:36:28 +0200 (CEST) Subject: r2971 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20080720103628.811FF1EC0E1@projects.linpro.no> Author: phk Date: 2008-07-20 12:36:28 +0200 (Sun, 20 Jul 2008) New Revision: 2971 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_main.c trunk/varnish-cache/bin/varnishd/cache_panic.c trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/shmlog.c trunk/varnish-cache/include/shmlog.h Log: Make room in the shared memory segment for a panic string buffer. Replace the default libvarnish assert handler with a child specific function. This function which fills the static panic string and copy the result to the shared memory panicstring. In the manager process, report the content of the panic string when the child dies. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-20 10:03:42 UTC (rev 2970) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-20 10:36:28 UTC (rev 2971) @@ -514,6 +514,9 @@ void THR_SetSession(const struct sess *sp); const struct sess * THR_GetSession(void); +/* cache_panic.c */ +void PAN_Init(void); + /* cache_pipe.c */ void PipeSession(struct sess *sp); @@ -537,7 +540,6 @@ void SES_Charge(struct sess *sp); /* cache_shmlog.c */ - void VSL_Init(void); #ifdef SHMLOGHEAD_MAGIC void VSL(enum shmlogtag tag, int id, const char *fmt, ...); Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2008-07-20 10:03:42 UTC (rev 2970) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2008-07-20 10:36:28 UTC (rev 2971) @@ -94,6 +94,7 @@ THR_Name("cache-main"); + PAN_Init(); CLI_Init(); Fetch_Init(); Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 10:03:42 UTC (rev 2970) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 10:36:28 UTC (rev 2971) @@ -48,6 +48,8 @@ * (gdb) printf "%s", panicstr */ char panicstr[65536]; +static struct vsb vsps, *vsp; + static char *pstr = panicstr; #define fp(...) \ @@ -240,3 +242,41 @@ } #endif + +static void +pan_ic(const char *func, const char *file, int line, const char *cond, int err, int xxx) +{ + int l; + char *p; + + if (xxx) { + vsb_printf(vsp, + "Missing errorhandling code in %s(), %s line %d:\n" + " Condition(%s) not true.\n", + func, file, line, cond); + } else { + vsb_printf(vsp, + "Assert error in %s(), %s line %d:\n" + " Condition(%s) not true.\n", + func, file, line, cond); + } + if (err) + vsb_printf(vsp, + " errno = %d (%s)\n", err, strerror(err)); + + VSL_Panic(&l, &p); + if (l < vsb_len(vsp)) + l = vsb_len(vsp); + memcpy(p, panicstr, l); + abort(); +} + + +void +PAN_Init(void) +{ + + lbv_assert = pan_ic; + vsp = &vsps; + AN(vsb_new(vsp, panicstr, sizeof panicstr, VSB_FIXEDLEN)); +} Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2008-07-20 10:03:42 UTC (rev 2970) +++ trunk/varnish-cache/bin/varnishd/common.h 2008-07-20 10:36:28 UTC (rev 2971) @@ -35,6 +35,8 @@ /* cache_acceptor.c */ void VCA_tweak_acceptor(struct cli *cli, const char *arg); +/* shmlog.c */ +void VSL_Panic(int *len, char **ptr); /* shmlog.c */ void VSL_MgtInit(const char *fn, unsigned size); Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-07-20 10:03:42 UTC (rev 2970) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-07-20 10:36:28 UTC (rev 2971) @@ -375,6 +375,20 @@ /*--------------------------------------------------------------------*/ +static void +mgt_report_panic(pid_t r) +{ + int l; + char *p; + + VSL_Panic(&l, &p); + if (*p == '\0') + return; + REPORT(LOG_ERR, "Child (%d) Panic message: %s", r, p); +} + +/*--------------------------------------------------------------------*/ + static int mgt_sigchld(const struct vev *e, int what) { @@ -411,6 +425,8 @@ REPORT(LOG_INFO, "%s", vsb_data(vsb)); vsb_delete(vsb); + mgt_report_panic(r); + child_pid = -1; if (child_state == CH_RUNNING) { Modified: trunk/varnish-cache/bin/varnishd/shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/shmlog.c 2008-07-20 10:03:42 UTC (rev 2970) +++ trunk/varnish-cache/bin/varnishd/shmlog.c 2008-07-20 10:36:28 UTC (rev 2971) @@ -265,6 +265,20 @@ /*--------------------------------------------------------------------*/ void +VSL_Panic(int *len, char **ptr) +{ + + AN(len); + AN(ptr); + assert(loghead->magic == SHMLOGHEAD_MAGIC); + assert(loghead->hdrsize == sizeof *loghead); + *len = sizeof(loghead->panicstr); + *ptr = loghead->panicstr; +} + +/*--------------------------------------------------------------------*/ + +void VSL_Init(void) { @@ -274,6 +288,7 @@ logstart = (unsigned char *)loghead + loghead->start; MTX_INIT(&vsl_mtx); loghead->starttime = TIM_real(); + loghead->panicstr[0] = '\0'; memset(VSL_stats, 0, sizeof *VSL_stats); } Modified: trunk/varnish-cache/include/shmlog.h =================================================================== --- trunk/varnish-cache/include/shmlog.h 2008-07-20 10:03:42 UTC (rev 2970) +++ trunk/varnish-cache/include/shmlog.h 2008-07-20 10:36:28 UTC (rev 2971) @@ -63,6 +63,9 @@ unsigned ptr; struct varnish_stats stats; + + /* Panic message buffer */ + char panicstr[64 * 1024]; }; /* From phk at projects.linpro.no Sun Jul 20 10:45:09 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 12:45:09 +0200 (CEST) Subject: r2972 - trunk/varnish-cache/bin/varnishd Message-ID: <20080720104509.B60A71EC236@projects.linpro.no> Author: phk Date: 2008-07-20 12:45:09 +0200 (Sun, 20 Jul 2008) New Revision: 2972 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_acceptor.c trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c trunk/varnish-cache/bin/varnishd/cache_backend_poll.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_main.c trunk/varnish-cache/bin/varnishd/cache_panic.c trunk/varnish-cache/bin/varnishd/cache_pool.c Log: Report thread name and thread session in panic messages. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-20 10:45:09 UTC (rev 2972) @@ -510,7 +510,8 @@ #undef HTTPH /* cache_main.c */ -void THR_Name(const char *name); +void THR_SetName(const char *name); +const char* THR_GetName(void); void THR_SetSession(const struct sess *sp); const struct sess * THR_GetSession(void); Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2008-07-20 10:45:09 UTC (rev 2972) @@ -162,7 +162,7 @@ unsigned u; double now; - THR_Name("cache-acceptor"); + THR_SetName("cache-acceptor"); (void)arg; /* Set up the poll argument */ Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2008-07-20 10:45:09 UTC (rev 2972) @@ -76,7 +76,7 @@ struct sess *sp, *sp2; int i; - THR_Name("cache-epoll"); + THR_SetName("cache-epoll"); (void)arg; epfd = epoll_create(16); Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2008-07-20 10:45:09 UTC (rev 2972) @@ -152,7 +152,7 @@ double deadline; struct sess *sp; - THR_Name("cache-kqueue"); + THR_SetName("cache-kqueue"); (void)arg; kq = kqueue(); Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2008-07-20 10:45:09 UTC (rev 2972) @@ -111,7 +111,7 @@ double deadline; int i, fd; - THR_Name("cache-poll"); + THR_SetName("cache-poll"); (void)arg; vca_poll(vca_pipes[0]); Modified: trunk/varnish-cache/bin/varnishd/cache_backend_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2008-07-20 10:45:09 UTC (rev 2972) @@ -68,7 +68,7 @@ (void)w; CAST_OBJ_NOTNULL(vt, priv, VBP_TARGET_MAGIC); - THR_Name("backend poll"); + THR_SetName("backend poll"); while (!vt->stop) { printf("Poke backend %s\n", vt->backend->vcl_name); @@ -76,7 +76,7 @@ } vt->backend->probe = NULL; FREE_OBJ(vt); - THR_Name("cache-worker"); + THR_SetName("cache-worker"); } void Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2008-07-20 10:45:09 UTC (rev 2972) @@ -263,7 +263,7 @@ struct sess *sp; unsigned char logbuf[1024]; /* XXX size ? */ - THR_Name("cache-timeout"); + THR_SetName("cache-timeout"); (void)arg; sp = SES_New(NULL, 0); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2008-07-20 10:45:09 UTC (rev 2972) @@ -317,6 +317,7 @@ struct http_conn htc[1]; int i; +AZ(sp); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2008-07-20 10:45:09 UTC (rev 2972) @@ -65,19 +65,25 @@ * Name threads if our pthreads implementation supports it. */ +static pthread_key_t name_key; + void -THR_Name(const char *name) +THR_SetName(const char *name) { + + AZ(pthread_setspecific(name_key, name)); #ifdef HAVE_PTHREAD_SET_NAME_NP pthread_set_name_np(pthread_self(), name); -#else - /* - * XXX: we could stash it somewhere else (TLS ?) - */ - (void)name; #endif } +const char * +THR_GetName(void) +{ + + return (pthread_getspecific(name_key)); +} + /*-------------------------------------------------------------------- * XXX: Think more about which order we start things */ @@ -91,8 +97,9 @@ printf("Child starts\n"); AZ(pthread_key_create(&sp_key, NULL)); + AZ(pthread_key_create(&name_key, NULL)); - THR_Name("cache-main"); + THR_SetName("cache-main"); PAN_Init(); CLI_Init(); Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 10:45:09 UTC (rev 2972) @@ -248,22 +248,30 @@ { int l; char *p; + const char *q; + const struct sess *sp; if (xxx) { vsb_printf(vsp, "Missing errorhandling code in %s(), %s line %d:\n" - " Condition(%s) not true.\n", + " Condition(%s) not true.", func, file, line, cond); } else { vsb_printf(vsp, "Assert error in %s(), %s line %d:\n" - " Condition(%s) not true.\n", + " Condition(%s) not true.", func, file, line, cond); } if (err) - vsb_printf(vsp, - " errno = %d (%s)\n", err, strerror(err)); + vsb_printf(vsp, " errno = %d (%s)", err, strerror(err)); + q = THR_GetName(); + if (q != NULL) + vsb_printf(vsp, " thread = (%s)", q); + sp = THR_GetSession(); + if (sp != NULL) + vsb_printf(vsp, " sess = (%p)", sp); + vsb_printf(vsp, "\n"); VSL_Panic(&l, &p); if (l < vsb_len(vsp)) l = vsb_len(vsp); Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2008-07-20 10:36:28 UTC (rev 2971) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2008-07-20 10:45:09 UTC (rev 2972) @@ -208,7 +208,7 @@ unsigned char wlog[8192]; /* XXX: size */ struct workreq *wrq; - THR_Name("cache-worker"); + THR_SetName("cache-worker"); w = &ww; CAST_OBJ_NOTNULL(qp, priv, WQ_MAGIC); memset(w, 0, sizeof *w); @@ -441,7 +441,7 @@ double t_idle; struct varnish_stats vsm, *vs; - THR_Name("wrk_herdtimer"); + THR_SetName("wrk_herdtimer"); memset(&vsm, 0, sizeof vsm); vs = &vsm; @@ -534,7 +534,7 @@ { unsigned u, w; - THR_Name("wrk_herder"); + THR_SetName("wrk_herder"); (void)priv; while (1) { for (u = 0 ; u < nwq; u++) { From phk at projects.linpro.no Sun Jul 20 10:46:01 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 12:46:01 +0200 (CEST) Subject: r2973 - trunk/varnish-cache/bin/varnishd Message-ID: <20080720104601.0AF381EC10F@projects.linpro.no> Author: phk Date: 2008-07-20 12:46:00 +0200 (Sun, 20 Jul 2008) New Revision: 2973 Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c Log: Remove debug hack which sneaked in. Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2008-07-20 10:45:09 UTC (rev 2972) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2008-07-20 10:46:00 UTC (rev 2973) @@ -317,7 +317,6 @@ struct http_conn htc[1]; int i; -AZ(sp); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); From phk at projects.linpro.no Sun Jul 20 11:24:57 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 13:24:57 +0200 (CEST) Subject: r2974 - trunk/varnish-cache/bin/varnishd Message-ID: <20080720112457.7E3791EC10F@projects.linpro.no> Author: phk Date: 2008-07-20 13:24:57 +0200 (Sun, 20 Jul 2008) New Revision: 2974 Modified: trunk/varnish-cache/bin/varnishd/flint.lnt Log: panicstr is deliberately not static Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2008-07-20 10:46:00 UTC (rev 2973) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2008-07-20 11:24:57 UTC (rev 2974) @@ -52,6 +52,7 @@ -esym(534, strcat) // Ignoring return value of function -esym(534, strcpy) // Ignoring return value of function -esym(534, strlcpy) // Ignoring return value of function +-esym(765, panicstr) // Could be static -emacro(506, isnan, isfinite) // constant value boolean -emacro(736, isfinite) // loss of precision From phk at projects.linpro.no Sun Jul 20 11:28:11 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 13:28:11 +0200 (CEST) Subject: r2975 - trunk/varnish-cache/bin/varnishd Message-ID: <20080720112811.0282E1EC0E1@projects.linpro.no> Author: phk Date: 2008-07-20 13:28:10 +0200 (Sun, 20 Jul 2008) New Revision: 2975 Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c Log: Reconstitute the dumping of sessions, objects &c &c, but now do it for all asserts from a thread with a registered session. Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 11:24:57 UTC (rev 2974) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 11:28:10 UTC (rev 2975) @@ -37,212 +37,199 @@ #include #include "cache.h" +#include "cache_backend.h" #include "vcl.h" -#ifndef WITHOUT_ASSERTS - /* - * The panic string is constructed in memory, then printed to stderr. It - * can be extracted post-mortem from a core dump using gdb: + * The panic string is constructed in memory, then copied to the + * shared memory. * + * It can be extracted post-mortem from a core dump using gdb: + * * (gdb) printf "%s", panicstr */ + char panicstr[65536]; static struct vsb vsps, *vsp; -static char *pstr = panicstr; +#if 0 -#define fp(...) \ - do { \ - pstr += snprintf(pstr, \ - (panicstr + sizeof panicstr) - pstr, \ - __VA_ARGS__); \ - } while (0) +void +panic(const char *file, int line, const char *func, + const struct sess *sp, const char *fmt, ...) +{ + va_list ap; -#define vfp(fmt, ap) \ - do { \ - pstr += vsnprintf(pstr, \ - (panicstr + sizeof panicstr) - pstr, \ - (fmt), (ap)); \ - } while (0) + vsb_printf(vsp, "panic in %s() at %s:%d\n", func, file, line); + va_start(ap, fmt); + vvsb_printf(vsp, fmt, ap); + va_end(ap); -/* step names */ -static const char *steps[] = { -#define STEP(l, u) [STP_##u] = "STP_" #u, -#include "steps.h" -#undef STEP -}; -static int nsteps = sizeof steps / sizeof *steps; + if (VALID_OBJ(sp, SESS_MAGIC)) + dump_sess(sp); -/* dump a struct VCL_conf */ + (void)fputs(panicstr, stderr); + + /* I wish there was a way to flush the log buffers... */ + (void)signal(SIGABRT, SIG_DFL); +#ifdef HAVE_ABORT2 + { + void *arg[1]; + char *p; + + for (p = panicstr; *p; p++) + if (*p == '\n') + *p = ' '; + arg[0] = panicstr; + abort2(panicstr, 1, arg); + } +#endif + (void)raise(SIGABRT); +} + +#endif + +/*--------------------------------------------------------------------*/ + static void -dump_vcl(const struct VCL_conf *vcl) +pan_backend(const struct backend *be) { - int i; - fp(" vcl = {\n"); - fp(" srcname = {\n"); - for (i = 0; i < vcl->nsrc; ++i) - fp(" \"%s\",\n", vcl->srcname[i]); - fp(" },\n"); - fp(" },\n"); + vsb_printf(vsp, " backend = %p {\n", be); + vsb_printf(vsp, " vcl_name = \"%s\",\n", be->vcl_name); + vsb_printf(vsp, " },\n"); } -/* dump a struct storage */ +/*--------------------------------------------------------------------*/ + static void -dump_storage(const struct storage *st) +pan_storage(const struct storage *st) { int i, j; #define MAX_BYTES (4*16) #define show(ch) (((ch) > 31 && (ch) < 127) ? (ch) : '.') - fp(" %u {\n", st->len); + vsb_printf(vsp, " %u {\n", st->len); for (i = 0; i < MAX_BYTES && i < st->len; i += 16) { - fp(" "); + vsb_printf(vsp, " "); for (j = 0; j < 16; ++j) { if (i + j < st->len) - fp("%02x ", st->ptr[i + j]); + vsb_printf(vsp, "%02x ", st->ptr[i + j]); else - fp(" "); + vsb_printf(vsp, " "); } - fp("|"); + vsb_printf(vsp, "|"); for (j = 0; j < 16; ++j) if (i + j < st->len) - fp("%c", show(st->ptr[i + j])); - fp("|\n"); + vsb_printf(vsp, "%c", show(st->ptr[i + j])); + vsb_printf(vsp, "|\n"); } if (st->len > MAX_BYTES) - fp(" [%u more]\n", st->len - MAX_BYTES); - fp(" },\n"); + vsb_printf(vsp, " [%u more]\n", st->len - MAX_BYTES); + vsb_printf(vsp, " },\n"); #undef show #undef MAX_BYTES } -/* dump a struct http */ +/*--------------------------------------------------------------------*/ + static void -dump_http(const struct http *h) +pan_http(const struct http *h) { int i; - fp(" http = {\n"); + vsb_printf(vsp, " http = {\n"); if (h->nhd > HTTP_HDR_FIRST) { - fp(" hd = {\n"); + vsb_printf(vsp, " hd = {\n"); for (i = HTTP_HDR_FIRST; i < h->nhd; ++i) - fp(" \"%.*s\",\n", + vsb_printf(vsp, " \"%.*s\",\n", (int)(h->hd[i].e - h->hd[i].b), h->hd[i].b); - fp(" },\n"); + vsb_printf(vsp, " },\n"); } - fp(" },\n"); + vsb_printf(vsp, " },\n"); } -/* dump a struct object */ + +/*--------------------------------------------------------------------*/ + static void -dump_object(const struct object *o) +pan_object(const struct object *o) { const struct storage *st; - fp(" obj = %p {\n", o); - fp(" refcnt = %u, xid = %u,\n", o->refcnt, o->xid); - dump_http(o->http); - fp(" len = %u,\n", o->len); - fp(" store = {\n"); - VTAILQ_FOREACH(st, &o->store, list) { - dump_storage(st); - } - fp(" },\n"); - fp(" },\n"); + vsb_printf(vsp, " obj = %p {\n", o); + vsb_printf(vsp, " refcnt = %u, xid = %u,\n", o->refcnt, o->xid); + pan_http(o->http); + vsb_printf(vsp, " len = %u,\n", o->len); + vsb_printf(vsp, " store = {\n"); + VTAILQ_FOREACH(st, &o->store, list) + pan_storage(st); + vsb_printf(vsp, " },\n"); + vsb_printf(vsp, " },\n"); } -#if 0 -/* dump a struct backend */ +/*--------------------------------------------------------------------*/ + static void -dump_backend(const struct backend *be) +pan_vcl(const struct VCL_conf *vcl) { + int i; - fp(" backend = %p {\n", be); - fp(" vcl_name = \"%s\",\n", - be->vcl_name ? be->vcl_name : "(null)"); - fp(" },\n"); + vsb_printf(vsp, " vcl = {\n"); + vsb_printf(vsp, " srcname = {\n"); + for (i = 0; i < vcl->nsrc; ++i) + vsb_printf(vsp, " \"%s\",\n", vcl->srcname[i]); + vsb_printf(vsp, " },\n"); + vsb_printf(vsp, " },\n"); } -#endif -/* dump a struct sess */ +/*--------------------------------------------------------------------*/ + static void -dump_sess(const struct sess *sp) +pan_sess(const struct sess *sp) { -#if 0 - const struct backend *be = sp->backend; -#endif - const struct object *obj = sp->obj; - const struct VCL_conf *vcl = sp->vcl; + const char *stp; - fp("sp = %p {\n", sp); - fp(" fd = %d, id = %d, xid = %u,\n", sp->fd, sp->id, sp->xid); - fp(" client = %s:%s,\n", + vsb_printf(vsp, "sp = %p {\n", sp); + vsb_printf(vsp, + " fd = %d, id = %d, xid = %u,\n", sp->fd, sp->id, sp->xid); + vsb_printf(vsp, " client = %s:%s,\n", sp->addr ? sp->addr : "?.?.?.?", sp->port ? sp->port : "?"); - if (sp->step < nsteps) - fp(" step = %s,\n", steps[sp->step]); + switch (sp->step) { +/*lint -save -e525 */ +#define STEP(l, u) case STP_##u: stp = "STP_" #u; break; +#include "steps.h" +#undef STEP +/*lint -restore */ + default: stp = NULL; + } + if (stp != NULL) + vsb_printf(vsp, " step = %s,\n", stp); else - fp(" step = %d,\n", sp->step); + vsb_printf(vsp, " step = 0x%x,\n", sp->step); if (sp->err_code) - fp(" err_code = %d, err_reason = %s,\n", sp->err_code, + vsb_printf(vsp, + " err_code = %d, err_reason = %s,\n", sp->err_code, sp->err_reason ? sp->err_reason : "(null)"); - if (VALID_OBJ(vcl, VCL_CONF_MAGIC)) - dump_vcl(vcl); + if (VALID_OBJ(sp->vcl, VCL_CONF_MAGIC)) + pan_vcl(sp->vcl); -#if 0 - if (VALID_OBJ(be, BACKEND_MAGIC)) - dump_backend(be); - INCOMPL(): -#endif + if (VALID_OBJ(sp->backend, BACKEND_MAGIC)) + pan_backend(sp->backend); - if (VALID_OBJ(obj, OBJECT_MAGIC)) - dump_object(obj); + if (VALID_OBJ(sp->obj, OBJECT_MAGIC)) + pan_object(sp->obj); - fp("},\n"); + vsb_printf(vsp, "},\n"); } -/* report as much information as we can before we croak */ -void -panic(const char *file, int line, const char *func, - const struct sess *sp, const char *fmt, ...) -{ - va_list ap; +/*--------------------------------------------------------------------*/ - fp("panic in %s() at %s:%d\n", func, file, line); - va_start(ap, fmt); - vfp(fmt, ap); - va_end(ap); - - if (VALID_OBJ(sp, SESS_MAGIC)) - dump_sess(sp); - - (void)fputs(panicstr, stderr); - - /* I wish there was a way to flush the log buffers... */ - (void)signal(SIGABRT, SIG_DFL); -#ifdef HAVE_ABORT2 - { - void *arg[1]; - char *p; - - for (p = panicstr; *p; p++) - if (*p == '\n') - *p = ' '; - arg[0] = panicstr; - abort2(panicstr, 1, arg); - } -#endif - (void)raise(SIGABRT); -} - -#endif - static void pan_ic(const char *func, const char *file, int line, const char *cond, int err, int xxx) { @@ -269,16 +256,17 @@ if (q != NULL) vsb_printf(vsp, " thread = (%s)", q); sp = THR_GetSession(); - if (sp != NULL) - vsb_printf(vsp, " sess = (%p)", sp); + if (sp != NULL) + pan_sess(sp); vsb_printf(vsp, "\n"); VSL_Panic(&l, &p); - if (l < vsb_len(vsp)) - l = vsb_len(vsp); + if (l < sizeof(panicstr)) + l = sizeof(panicstr); memcpy(p, panicstr, l); abort(); } +/*--------------------------------------------------------------------*/ void PAN_Init(void) From phk at projects.linpro.no Sun Jul 20 11:28:40 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 13:28:40 +0200 (CEST) Subject: r2976 - trunk/varnish-cache/bin/varnishd Message-ID: <20080720112840.CB3971EC10F@projects.linpro.no> Author: phk Date: 2008-07-20 13:28:40 +0200 (Sun, 20 Jul 2008) New Revision: 2976 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_response.c trunk/varnish-cache/bin/varnishd/cache_session.c Log: Remove the session-specific assert facility, the general assert facility dumps details now. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-20 11:28:10 UTC (rev 2975) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-20 11:28:40 UTC (rev 2976) @@ -710,19 +710,3 @@ t->b = t->e; } } - -#ifdef WITHOUT_ASSERTS -#define spassert(cond) ((void)(cond)) -#else -void panic(const char *, int, const char *, - const struct sess *, const char *, ...); -#define spassert(cond) \ - do { \ - int ok = !!(cond); \ - if (!ok) \ - panic(__FILE__, __LINE__, __func__, sp, \ - "assertion failed: %s\n", #cond); \ - } while (0) -#endif -#define SPAZ(val) spassert((val) == 0) -#define SPAN(val) spassert((val) != 0) Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2008-07-20 11:28:10 UTC (rev 2975) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2008-07-20 11:28:40 UTC (rev 2976) @@ -119,8 +119,8 @@ sp, (unsigned long)kp->data, kp->flags, (kp->flags & EV_EOF) ? " EOF" : ""); - spassert(sp->id == kp->ident); - spassert(sp->fd == sp->id); + assert(sp->id == kp->ident); + assert(sp->fd == sp->id); if (kp->data > 0) { i = HTC_Rx(sp->htc); if (i == 0) { Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-20 11:28:10 UTC (rev 2975) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-20 11:28:40 UTC (rev 2976) @@ -574,7 +574,7 @@ * We hit a busy object, disembark worker thread and expect * hash code to restart us, still in STP_LOOKUP, later. */ - spassert(sp->objhead != NULL); + assert(sp->objhead != NULL); if (params->diag_bitmap & 0x20) WSP(sp, SLT_Debug, "on waiting list <%s>", sp->objhead->hash); Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2008-07-20 11:28:10 UTC (rev 2975) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2008-07-20 11:28:40 UTC (rev 2976) @@ -169,7 +169,7 @@ VSL_stats->n_objwrite++; WRK_Write(sp->wrk, st->ptr, st->len); } - spassert(u == sp->obj->len); + assert(u == sp->obj->len); if (sp->esis > 0) WRK_Write(sp->wrk, "\r\n", -1); } Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2008-07-20 11:28:10 UTC (rev 2975) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2008-07-20 11:28:40 UTC (rev 2976) @@ -129,7 +129,7 @@ sp->srcaddr = NULL; return; } - SPAZ(sp->srcaddr); + AZ(sp->srcaddr); u = crc32_l(sp->addr, strlen(sp->addr)); v = u % nsrchash; ch = &srchash[v]; @@ -329,8 +329,8 @@ sm = sp->mem; CHECK_OBJ_NOTNULL(sm, SESSMEM_MAGIC); - SPAZ(sp->obj); - SPAZ(sp->vcl); + AZ(sp->obj); + AZ(sp->vcl); VSL_stats->n_sess--; ses_relsrcaddr(sp); assert(!isnan(b->first)); From phk at projects.linpro.no Sun Jul 20 11:40:30 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 13:40:30 +0200 (CEST) Subject: r2977 - trunk/varnish-cache/bin/varnishd Message-ID: <20080720114030.A89AE1EC0E1@projects.linpro.no> Author: phk Date: 2008-07-20 13:40:30 +0200 (Sun, 20 Jul 2008) New Revision: 2977 Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Add diag_bitmap controls for panic behaviour. Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 11:28:40 UTC (rev 2976) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 11:40:30 UTC (rev 2977) @@ -35,6 +35,7 @@ #include #include #include +#include #include "cache.h" #include "cache_backend.h" @@ -52,43 +53,6 @@ char panicstr[65536]; static struct vsb vsps, *vsp; -#if 0 - -void -panic(const char *file, int line, const char *func, - const struct sess *sp, const char *fmt, ...) -{ - va_list ap; - - vsb_printf(vsp, "panic in %s() at %s:%d\n", func, file, line); - va_start(ap, fmt); - vvsb_printf(vsp, fmt, ap); - va_end(ap); - - if (VALID_OBJ(sp, SESS_MAGIC)) - dump_sess(sp); - - (void)fputs(panicstr, stderr); - - /* I wish there was a way to flush the log buffers... */ - (void)signal(SIGABRT, SIG_DFL); -#ifdef HAVE_ABORT2 - { - void *arg[1]; - char *p; - - for (p = panicstr; *p; p++) - if (*p == '\n') - *p = ' '; - arg[0] = panicstr; - abort2(panicstr, 1, arg); - } -#endif - (void)raise(SIGABRT); -} - -#endif - /*--------------------------------------------------------------------*/ static void @@ -255,15 +219,35 @@ q = THR_GetName(); if (q != NULL) vsb_printf(vsp, " thread = (%s)", q); - sp = THR_GetSession(); - if (sp != NULL) - pan_sess(sp); + if (!(params->diag_bitmap & 0x2000)) { + sp = THR_GetSession(); + if (sp != NULL) + pan_sess(sp); + } vsb_printf(vsp, "\n"); + vsb_bcat(vsp, "", 1); /* NUL termination */ VSL_Panic(&l, &p); if (l < sizeof(panicstr)) l = sizeof(panicstr); memcpy(p, panicstr, l); - abort(); + if (params->diag_bitmap & 0x4000) + fputs(panicstr, stderr); + +#ifdef HAVE_ABORT2 + if (params->diag_bitmap & 0x8000) { + void *arg[1]; + + for (p = panicstr; *p; p++) + if (*p == '\n') + *p = ' '; + arg[0] = panicstr; + abort2(panicstr, 1, arg); + } +#endif + if (params->diag_bitmap & 0x1000) + kill(getpid(), SIGUSR1); + else + abort(); } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-20 11:28:40 UTC (rev 2976) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-20 11:40:30 UTC (rev 2977) @@ -786,6 +786,12 @@ " 0x00000010 - mutex contests.\n" " 0x00000020 - waiting list.\n" " 0x00000040 - object workspace.\n" + " 0x00001000 - do not core-dump child process.\n" + " 0x00002000 - only short panic message.\n" + " 0x00004000 - panic to stderr.\n" +#ifdef HAVE_ABORT2 + " 0x00008000 - panic to abort2().\n" +#endif "Use 0x notation and do the bitor in your head :-)\n", 0, "0", "bitmap" }, From phk at projects.linpro.no Sun Jul 20 11:44:29 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 13:44:29 +0200 (CEST) Subject: r2978 - trunk/varnish-cache/bin/varnishd Message-ID: <20080720114429.4AC5C1ED180@projects.linpro.no> Author: phk Date: 2008-07-20 13:44:29 +0200 (Sun, 20 Jul 2008) New Revision: 2978 Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c Log: Ignore a couple of return values Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 11:40:30 UTC (rev 2977) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 11:44:29 UTC (rev 2978) @@ -231,7 +231,7 @@ l = sizeof(panicstr); memcpy(p, panicstr, l); if (params->diag_bitmap & 0x4000) - fputs(panicstr, stderr); + (void)fputs(panicstr, stderr); #ifdef HAVE_ABORT2 if (params->diag_bitmap & 0x8000) { @@ -245,7 +245,7 @@ } #endif if (params->diag_bitmap & 0x1000) - kill(getpid(), SIGUSR1); + (void)kill(getpid(), SIGUSR1); else abort(); } From phk at projects.linpro.no Sun Jul 20 12:03:14 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 14:03:14 +0200 (CEST) Subject: r2979 - trunk/varnish-cache/bin/varnishd Message-ID: <20080720120314.9F51A1ECE33@projects.linpro.no> Author: phk Date: 2008-07-20 14:03:14 +0200 (Sun, 20 Jul 2008) New Revision: 2979 Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c Log: Also dump workspaces in panic. Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 11:44:29 UTC (rev 2978) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-20 12:03:14 UTC (rev 2979) @@ -56,6 +56,32 @@ /*--------------------------------------------------------------------*/ static void +pan_ws(const struct ws *ws, int indent) +{ + + vsb_printf(vsp, "%*sws = %p { %s\n", indent, "", + ws, ws->overflow ? "overflow" : ""); + vsb_printf(vsp, "%*sid = \"%s\",\n", indent + 2, "", ws->id); + vsb_printf(vsp, "%*s{s,f,r,e} = {%p,", indent + 2, "", ws->s); + if (ws->f > ws->s) + vsb_printf(vsp, ",+%d", ws->f - ws->s); + else + vsb_printf(vsp, ",%p", ws->f); + if (ws->r > ws->s) + vsb_printf(vsp, ",+%d", ws->r - ws->s); + else + vsb_printf(vsp, ",%p", ws->r); + if (ws->e > ws->s) + vsb_printf(vsp, ",+%d", ws->e - ws->s); + else + vsb_printf(vsp, ",%p", ws->e); + vsb_printf(vsp, "},\n"); + vsb_printf(vsp, "%*s},\n", indent, "" ); +} + +/*--------------------------------------------------------------------*/ + +static void pan_backend(const struct backend *be) { @@ -105,6 +131,7 @@ int i; vsb_printf(vsp, " http = {\n"); + pan_ws(h->ws, 6); if (h->nhd > HTTP_HDR_FIRST) { vsb_printf(vsp, " hd = {\n"); for (i = HTTP_HDR_FIRST; i < h->nhd; ++i) @@ -126,6 +153,7 @@ vsb_printf(vsp, " obj = %p {\n", o); vsb_printf(vsp, " refcnt = %u, xid = %u,\n", o->refcnt, o->xid); + pan_ws(o->ws_o, 4); pan_http(o->http); vsb_printf(vsp, " len = %u,\n", o->len); vsb_printf(vsp, " store = {\n"); @@ -150,9 +178,20 @@ vsb_printf(vsp, " },\n"); } + /*--------------------------------------------------------------------*/ static void +pan_wrk(const struct worker *wrk) +{ + + vsb_printf(vsp, " worker = %p {\n", wrk); + vsb_printf(vsp, " },\n"); +} + +/*--------------------------------------------------------------------*/ + +static void pan_sess(const struct sess *sp) { const char *stp; @@ -180,6 +219,11 @@ " err_code = %d, err_reason = %s,\n", sp->err_code, sp->err_reason ? sp->err_reason : "(null)"); + pan_ws(sp->ws, 2); + + if (sp->wrk != NULL) + pan_wrk(sp->wrk); + if (VALID_OBJ(sp->vcl, VCL_CONF_MAGIC)) pan_vcl(sp->vcl); From phk at projects.linpro.no Sun Jul 20 20:24:37 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 20 Jul 2008 22:24:37 +0200 (CEST) Subject: r2980 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080720202437.CB5B21EC203@projects.linpro.no> Author: phk Date: 2008-07-20 22:24:37 +0200 (Sun, 20 Jul 2008) New Revision: 2980 Modified: trunk/varnish-cache/bin/varnishtest/tests/b00008.vtc Log: Also check the "stats" command. Modified: trunk/varnish-cache/bin/varnishtest/tests/b00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/b00008.vtc 2008-07-20 12:03:14 UTC (rev 2979) +++ trunk/varnish-cache/bin/varnishtest/tests/b00008.vtc 2008-07-20 20:24:37 UTC (rev 2980) @@ -17,3 +17,5 @@ varnish v1 -start varnish v1 -cli "help" + +varnish v1 -cli "stats" From phk at projects.linpro.no Tue Jul 22 07:19:41 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 22 Jul 2008 09:19:41 +0200 (CEST) Subject: r2981 - trunk/varnish-cache/bin/varnishd Message-ID: <20080722071941.ADE281EC0EF@projects.linpro.no> Author: phk Date: 2008-07-22 09:19:40 +0200 (Tue, 22 Jul 2008) New Revision: 2981 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Accept comma separation for the -a subargs for consistency with -s and -h Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-20 20:24:37 UTC (rev 2980) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-22 07:19:40 UTC (rev 2981) @@ -323,7 +323,7 @@ return; } - av = ParseArgv(arg, 0); + av = ParseArgv(arg, ARGV_COMMA); if (av == NULL) { cli_out(cli, "Parse error: out of memory"); cli_result(cli, CLIS_PARAM); From phk at projects.linpro.no Tue Jul 22 07:37:33 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 22 Jul 2008 09:37:33 +0200 (CEST) Subject: r2982 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish Message-ID: <20080722073733.2534A1EC0B7@projects.linpro.no> Author: phk Date: 2008-07-22 09:37:32 +0200 (Tue, 22 Jul 2008) New Revision: 2982 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/include/cli_priv.h trunk/varnish-cache/lib/libvarnish/cli_common.c Log: Add a cli_quote() function for quoting a string properly when reporting it in the CLI. Use it for cc_command and listen_address parameters Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-22 07:19:40 UTC (rev 2981) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-22 07:37:32 UTC (rev 2982) @@ -315,11 +315,7 @@ (void)par; if (arg == NULL) { - /* Quote the string if we have more than one socket */ - if (heritage.nsocks > 1) - cli_out(cli, "\"%s\"", master.listen_address); - else - cli_out(cli, "%s", master.listen_address); + cli_quote(cli, master.listen_address); return; } @@ -348,7 +344,8 @@ int j, n; if (VSS_parse(av[i], &host, &port) != 0) { - cli_out(cli, "Invalid listen address \"%s\"", av[i]); + cli_out(cli, "Invalid listen address "); + cli_quote(cli, av[i]); cli_result(cli, CLIS_PARAM); break; } @@ -356,7 +353,8 @@ free(host); free(port); if (n == 0) { - cli_out(cli, "Invalid listen address \"%s\"", av[i]); + cli_out(cli, "Invalid listen address "); + cli_quote(cli, av[i]); cli_result(cli, CLIS_PARAM); break; } @@ -399,7 +397,7 @@ /* XXX should have tweak_generic_string */ (void)par; if (arg == NULL) { - cli_out(cli, "%s", mgt_cc_cmd); + cli_quote(cli, mgt_cc_cmd); } else { free(mgt_cc_cmd); mgt_cc_cmd = strdup(arg); Modified: trunk/varnish-cache/include/cli_priv.h =================================================================== --- trunk/varnish-cache/include/cli_priv.h 2008-07-22 07:19:40 UTC (rev 2981) +++ trunk/varnish-cache/include/cli_priv.h 2008-07-22 07:37:32 UTC (rev 2982) @@ -54,6 +54,7 @@ /* The implementation must provide these functions */ void cli_out(struct cli *cli, const char *fmt, ...); +void cli_quote(struct cli *cli, const char *str); void cli_param(struct cli *cli); void cli_result(struct cli *cli, unsigned r); Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-22 07:19:40 UTC (rev 2981) +++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-22 07:37:32 UTC (rev 2982) @@ -69,6 +69,53 @@ } void +cli_quote(struct cli *cli, const char *s) +{ + const char *q; + int quote = 0; + + for (q = s; *q != '\0'; q++) { + if (!isgraph(*q) || *q == '"') { + quote++; + break; + } + } + if (!quote) { + (void)vsb_cat(cli->sb, s); + return; + } + (void)vsb_putc(cli->sb, '"'); + for (q = s; *q != '\0'; q++) { + switch (*q) { + case ' ': + (void)vsb_putc(cli->sb, *q); + break; + case '\\': + case '"': + (void)vsb_putc(cli->sb, '\\'); + (void)vsb_putc(cli->sb, *q); + break; + case '\n': + (void)vsb_cat(cli->sb, "\\n"); + break; + case '\r': + (void)vsb_cat(cli->sb, "\\r"); + break; + case '\t': + (void)vsb_cat(cli->sb, "\\t"); + break; + default: + if (isgraph(*q)) + (void)vsb_putc(cli->sb, *q); + else + (void)vsb_printf(cli->sb, "\\%o", *q); + break; + } + } + (void)vsb_putc(cli->sb, '"'); +} + +void cli_result(struct cli *cli, unsigned res) { @@ -78,7 +125,6 @@ printf("CLI result = %d\n", res); } - void cli_param(struct cli *cli) { From petter at projects.linpro.no Tue Jul 22 07:52:00 2008 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Tue, 22 Jul 2008 09:52:00 +0200 (CEST) Subject: r2983 - in trunk/varnish-cache: bin/varnishd include lib/libvcl man Message-ID: <20080722075200.D4CFE1EC10A@projects.linpro.no> Author: petter Date: 2008-07-22 09:52:00 +0200 (Tue, 22 Jul 2008) New Revision: 2983 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c trunk/varnish-cache/man/vcl.7 Log: Added the variable server.port that holds the port on which the server has answered the request in the same way that server.ip holds the IP number. Fixes #264. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-22 07:37:32 UTC (rev 2982) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-22 07:52:00 UTC (rev 2983) @@ -478,6 +478,19 @@ return (sp->mysockaddr); } +int +VRT_r_server_port(struct sess *sp) +{ + char abuf[TCP_ADDRBUFSIZE]; + char pbuf[TCP_PORTBUFSIZE]; + + if (sp->mysockaddr->sa_family == AF_UNSPEC) + AZ(getsockname(sp->fd, sp->mysockaddr, &sp->mysockaddrlen)); + TCP_name(sp->mysockaddr, sp->mysockaddrlen, abuf, sizeof abuf, pbuf, sizeof pbuf); + + return (atoi(pbuf)); +} + /*-------------------------------------------------------------------- * Add an element to the array/list of hash bits. */ Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2008-07-22 07:37:32 UTC (rev 2982) +++ trunk/varnish-cache/include/vrt_obj.h 2008-07-22 07:52:00 UTC (rev 2983) @@ -8,6 +8,7 @@ struct sockaddr * VRT_r_client_ip(const struct sess *); struct sockaddr * VRT_r_server_ip(struct sess *); +int VRT_r_server_port(struct sess *); const char * VRT_r_req_request(const struct sess *); void VRT_l_req_request(const struct sess *, const char *, ...); const char * VRT_r_req_url(const struct sess *); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-22 07:37:32 UTC (rev 2982) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-22 07:52:00 UTC (rev 2983) @@ -465,6 +465,7 @@ vsb_cat(sb, "\n"); vsb_cat(sb, "struct sockaddr * VRT_r_client_ip(const struct sess *);\n"); vsb_cat(sb, "struct sockaddr * VRT_r_server_ip(struct sess *);\n"); + vsb_cat(sb, "int VRT_r_server_port(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_req_request(const struct sess *);\n"); vsb_cat(sb, "void VRT_l_req_request(const struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_req_url(const struct sess *);\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2008-07-22 07:37:32 UTC (rev 2982) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2008-07-22 07:52:00 UTC (rev 2983) @@ -1,4 +1,4 @@ -#!/usr/local/bin/tclsh8.4 +#!/usr/bin/tclsh8.4 #- # Copyright (c) 2006 Verdens Gang AS # Copyright (c) 2006-2008 Linpro AS @@ -51,7 +51,11 @@ {recv pipe pass hash miss hit fetch deliver } "struct sess *" } - + { server.port + RO INT + {recv pipe pass hash miss hit fetch deliver } + "struct sess *" + } # Request paramters { req.request RW STRING Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2008-07-22 07:37:32 UTC (rev 2982) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2008-07-22 07:52:00 UTC (rev 2983) @@ -25,6 +25,13 @@ 0, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER }, + { "server.port", INT, 11, + "VRT_r_server_port(sp)", + NULL, + V_RO, + 0, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + }, { "req.request", STRING, 11, "VRT_r_req_request(sp)", "VRT_l_req_request(sp, ", Modified: trunk/varnish-cache/man/vcl.7 =================================================================== --- trunk/varnish-cache/man/vcl.7 2008-07-22 07:37:32 UTC (rev 2982) +++ trunk/varnish-cache/man/vcl.7 2008-07-22 07:52:00 UTC (rev 2983) @@ -394,6 +394,9 @@ .It Va server.ip The IP address of the socket on which the client connection was received. +.It Va server.port +The port number of the socket on which the client connection was +received. .It Va req.request The request type (e.g. "GET", "HEAD"). .It Va req.url From phk at projects.linpro.no Tue Jul 22 08:06:16 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 22 Jul 2008 10:06:16 +0200 (CEST) Subject: r2984 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20080722080616.83DB11EC0EF@projects.linpro.no> Author: phk Date: 2008-07-22 10:06:16 +0200 (Tue, 22 Jul 2008) New Revision: 2984 Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Add a "panic" vcl command, which does what you would expect. Takes a string argument, so it is possible to do: panic "Trouble with " req.url " (not the way I expected it!); Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-22 07:52:00 UTC (rev 2983) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2008-07-22 08:06:16 UTC (rev 2984) @@ -246,16 +246,24 @@ const char *q; const struct sess *sp; - if (xxx) { + switch(xxx) { + case 2: vsb_printf(vsp, + "Panic from VCL:\n%s\n", cond); + break; + case 1: + vsb_printf(vsp, "Missing errorhandling code in %s(), %s line %d:\n" " Condition(%s) not true.", func, file, line, cond); - } else { + break; + default: + case 0: vsb_printf(vsp, "Assert error in %s(), %s line %d:\n" " Condition(%s) not true.", func, file, line, cond); + break; } if (err) vsb_printf(vsp, " errno = %d (%s)", err, strerror(err)); Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-22 07:52:00 UTC (rev 2983) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-22 08:06:16 UTC (rev 2984) @@ -627,6 +627,20 @@ /*--------------------------------------------------------------------*/ void +VRT_panic(struct sess *sp, const char *str, ...) +{ + va_list ap; + char *b; + + va_start(ap, str); + b = vrt_assemble_string(sp->http, "PANIC: ", str, ap); + va_end(ap); + lbv_assert("VCL", "", 0, b, 0, 2); +} + +/*--------------------------------------------------------------------*/ + +void VRT_purge(const char *regexp, int hash) { Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2008-07-22 07:52:00 UTC (rev 2983) +++ trunk/varnish-cache/include/vrt.h 2008-07-22 08:06:16 UTC (rev 2984) @@ -141,6 +141,7 @@ int VRT_re_test(struct vsb *, const char *, int sub); const char *VRT_regsub(const struct sess *sp, int all, const char *, void *, const char *); +void VRT_panic(struct sess *sp, const char *, ...); void VRT_purge(const char *, int hash); void VRT_count(const struct sess *, unsigned); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-22 07:52:00 UTC (rev 2983) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-22 08:06:16 UTC (rev 2984) @@ -355,6 +355,24 @@ /*--------------------------------------------------------------------*/ +static void +parse_panic(struct tokenlist *tl) +{ + vcc_NextToken(tl); + + Fb(tl, 1, "VRT_panic(sp, "); + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return; + } + do + Fb(tl, 0, ", "); + while (vcc_StringVal(tl)); + Fb(tl, 0, " 0);\n"); +} + +/*--------------------------------------------------------------------*/ + typedef void action_f(struct tokenlist *tl); static struct action_table { @@ -367,15 +385,17 @@ #include "vcl_returns.h" #undef VCL_RET_MAC #undef VCL_RET_MAC_E - { "call", parse_call }, - { "set", parse_set }, - { "unset", parse_unset }, - { "remove", parse_unset }, /* backward compatibility */ - { "purge_url", parse_purge_url }, - { "purge_hash", parse_purge_hash }, - { "esi", parse_esi }, - { NULL, NULL } + /* Keep list sorted from here */ + { "call", parse_call }, + { "esi", parse_esi }, + { "panic", parse_panic }, + { "purge_hash", parse_purge_hash }, + { "purge_url", parse_purge_url }, + { "remove", parse_unset }, /* backward compatibility */ + { "set", parse_set }, + { "unset", parse_unset }, + { NULL, NULL } }; void Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-22 07:52:00 UTC (rev 2983) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-22 08:06:16 UTC (rev 2984) @@ -422,6 +422,7 @@ vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); vsb_cat(sb, "const char *VRT_regsub(const struct sess *sp, int all, const char *, void *, const char *);\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "void VRT_panic(struct sess *sp, const char *, ...);\n"); vsb_cat(sb, "void VRT_purge(const char *, int hash);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "void VRT_count(const struct sess *, unsigned);\n"); From phk at projects.linpro.no Tue Jul 22 08:21:29 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 22 Jul 2008 10:21:29 +0200 (CEST) Subject: r2985 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080722082129.DE0371EC10A@projects.linpro.no> Author: phk Date: 2008-07-22 10:21:29 +0200 (Tue, 22 Jul 2008) New Revision: 2985 Added: trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc Log: Add a testcase which panics the child, see the manager restart it. Added: trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc 2008-07-22 08:21:29 UTC (rev 2985) @@ -0,0 +1,41 @@ +# $Id: v00005.vtc 2906 2008-07-08 10:29:07Z phk $ + +test "VCL: check panic and restart" + +server s1 { + rxreq + txresp -hdr "Foo: bar" -body "abcdef\n" + rxreq + txresp -hdr "Panic: please" -body "012345\n" + sema r1 sync 2 +} -start + +varnish v1 -vcl+backend { + + sub vcl_fetch { + if (obj.http.panic) { + panic "Had Panic header: " obj.http.panic; + } + } +} -start -cli "param.set diag_bitmap 0x00001000" + + +client c1 { + txreq -url "/" + rxresp + txreq -url "/foo" + # Don't expect answer, the server crashed. + sema r1 sync 2 + delay .5 +} -run + +server s1 { + rxreq + txresp -hdr "Foo: foo" -body "abcdef\n" +} -start + +client c1 { + txreq -url "/" + rxresp + expect resp.http.foo == "foo" +} -run From phk at projects.linpro.no Tue Jul 22 09:03:01 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 22 Jul 2008 11:03:01 +0200 (CEST) Subject: r2987 - in trunk/varnish-cache/bin/varnishtest: . tests Message-ID: <20080722090301.66F2D1EC10A@projects.linpro.no> Author: phk Date: 2008-07-22 11:02:17 +0200 (Tue, 22 Jul 2008) New Revision: 2987 Modified: trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc trunk/varnish-cache/bin/varnishtest/vtc.c Log: slightly more delay seems necessary for stability. Modified: trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc 2008-07-22 08:37:41 UTC (rev 2986) +++ trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc 2008-07-22 09:02:17 UTC (rev 2987) @@ -26,7 +26,7 @@ txreq -url "/foo" # Don't expect answer, the server crashed. sema r1 sync 2 - delay .5 + delay 1.5 } -run server s1 { Modified: trunk/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.c 2008-07-22 08:37:41 UTC (rev 2986) +++ trunk/varnish-cache/bin/varnishtest/vtc.c 2008-07-22 09:02:17 UTC (rev 2987) @@ -134,7 +134,7 @@ p++; } else { if (*p == '\n') - fprintf(stderr, "Unterminated quoted string\n"); + fprintf(stderr, "Unterminated quoted string in line:\n%s", p); assert(*p != '\n'); *q++ = *p; } From petter at projects.linpro.no Tue Jul 22 09:42:07 2008 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Tue, 22 Jul 2008 11:42:07 +0200 (CEST) Subject: r2988 - trunk/varnish-cache/bin/varnishd Message-ID: <20080722094207.1E5931EC201@projects.linpro.no> Author: petter Date: 2008-07-22 11:42:06 +0200 (Tue, 22 Jul 2008) New Revision: 2988 Modified: trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Added granularity as a subargument to the options for file storage: -s file,,, Fixes #244 Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-22 09:02:17 UTC (rev 2987) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-22 09:42:06 UTC (rev 2988) @@ -244,19 +244,27 @@ struct stat st; struct smf_sc *sc; unsigned u; + uintmax_t page_size; AZ(av[ac]); fn = default_filename; size = default_size; + page_size = getpagesize(); - if (ac > 2) + if (ac > 3) ARGV_ERR("(-sfile) too many arguments\n"); if (ac > 0 && *av[0] != '\0') fn = av[0]; if (ac > 1 && *av[1] != '\0') size = av[1]; + if (ac > 2 && *av[2] != '\0') { + q = str2bytes(av[2], &page_size, 0); + if (q != NULL) + ARGV_ERR("(-sfile) granularity \"%s\": %s\n", av[2], q); + } + AN(fn); AN(size); @@ -266,7 +274,7 @@ for (u = 0; u < NBUCKET; u++) VTAILQ_INIT(&sc->free[u]); VTAILQ_INIT(&sc->used); - sc->pagesize = getpagesize(); + sc->pagesize = page_size; parent->priv = sc; Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2008-07-22 09:02:17 UTC (rev 2987) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2008-07-22 09:42:06 UTC (rev 2988) @@ -204,6 +204,7 @@ fprintf(stderr, FMT, "", " -s file [default: use /tmp]"); fprintf(stderr, FMT, "", " -s file,"); fprintf(stderr, FMT, "", " -s file,,"); + fprintf(stderr, FMT, "", " -s file,,,"); fprintf(stderr, FMT, "-t", "Default TTL"); fprintf(stderr, FMT, "-T address:port", "Telnet listen address and port"); From phk at projects.linpro.no Tue Jul 22 09:57:11 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 22 Jul 2008 11:57:11 +0200 (CEST) Subject: r2989 - trunk/varnish-cache/bin/varnishd Message-ID: <20080722095712.06B171EC0B5@projects.linpro.no> Author: phk Date: 2008-07-22 11:57:11 +0200 (Tue, 22 Jul 2008) New Revision: 2989 Modified: trunk/varnish-cache/bin/varnishd/varnishd.c Log: renovate tackle_warg() Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2008-07-22 09:42:06 UTC (rev 2988) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2008-07-22 09:57:11 UTC (rev 2989) @@ -98,6 +98,19 @@ /*--------------------------------------------------------------------*/ +static unsigned long +arg_ul(const char *p) +{ + char *q; + unsigned long ul; + + ul = strtoul(p, &q, 0); + if (*q != '\0') + ARGV_ERR("Invalid number: \"%s\"\n", p); + return (ul); +} + +/*--------------------------------------------------------------------*/ extern struct stevedore sma_stevedore; extern struct stevedore smf_stevedore; @@ -224,47 +237,35 @@ static void tackle_warg(const char *argv) { + char **av; unsigned int u; - char *ep, *eq; - u = strtoul(argv, &ep, 0); - if (ep == argv) - usage(); - while (isspace(*ep)) - ep++; - if (u < 1) - usage(); - params->wthread_min = u; + av = ParseArgv(argv, ARGV_COMMA); + AN(av); - if (*ep == '\0') { - params->wthread_max = params->wthread_min; - return; - } + if (av[0] != NULL) + ARGV_ERR("%s\n", av[0]); - if (*ep != ',') + if (av[1] == NULL) usage(); - u = strtoul(++ep, &eq, 0); - if (eq == ep) + + u = arg_ul(av[1]); + if (u < 1) usage(); - if (u < params->wthread_min) - usage(); - while (isspace(*eq)) - eq++; - params->wthread_max = u; + params->wthread_max = params->wthread_min = u; - if (*eq == '\0') - return; + if (av[2] != NULL) { + u = arg_ul(av[2]); + if (u < params->wthread_min) + usage(); + params->wthread_max = u; - if (*eq != ',') - usage(); - u = strtoul(++eq, &ep, 0); - if (ep == eq) - usage(); - while (isspace(*ep)) - ep++; - if (*ep != '\0') - usage(); - params->wthread_timeout = u; + if (av[3] != NULL) { + u = arg_ul(av[3]); + params->wthread_timeout = u; + } + } + FreeArgv(av); } /*-------------------------------------------------------------------- From phk at projects.linpro.no Tue Jul 22 09:59:41 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 22 Jul 2008 11:59:41 +0200 (CEST) Subject: r2990 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080722095941.F1FF51EC201@projects.linpro.no> Author: phk Date: 2008-07-22 11:59:41 +0200 (Tue, 22 Jul 2008) New Revision: 2990 Modified: trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc Log: Force -w thread limits Modified: trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc 2008-07-22 09:57:11 UTC (rev 2989) +++ trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc 2008-07-22 09:59:41 UTC (rev 2990) @@ -10,7 +10,7 @@ } -start # Only one pool, to avoid getting more than one work thread -varnish v1 -arg "-p thread_pools=1" -vcl { +varnish v1 -arg "-p thread_pools=1 -w1,1,300" -vcl { backend b1 { .host = "localhost"; .port = "9080"; From petter at projects.linpro.no Tue Jul 22 11:12:52 2008 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Tue, 22 Jul 2008 13:12:52 +0200 (CEST) Subject: r2991 - trunk/varnish-cache/bin/varnishd Message-ID: <20080722111252.1816B1EC033@projects.linpro.no> Author: petter Date: 2008-07-22 13:12:51 +0200 (Tue, 22 Jul 2008) New Revision: 2991 Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 Log: Updated the man page with the granularity option for the file storage. Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2008-07-22 09:59:41 UTC (rev 2990) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2008-07-22 11:12:51 UTC (rev 2991) @@ -240,7 +240,7 @@ Storage for each object is allocated with .Xr malloc 3 . Not recommended for production use. -.It Cm file Ns Op Ns , Ns Ar path Ns Op Ns , Ns Ar size +.It Cm file Ns Op Ns , Ns Ar path Ns Op Ns , Ns Ar size Ns Op Ns , Ns Ar granularity Storage for each object is allocated from an arena backed by a file. This is the default. .Pp @@ -285,6 +285,15 @@ Pre-creating the storage file using .Xr dd 1 will reduce fragmentation to a minimum. +.Pp +The +.Ar granularity +parameter specifies the granularity of allocation. All allocations are rounded up to this size. +The size is assumed to be in bytes, unless followed by one of the suffixes described for +.Ar size +except for %. +.Pp +The default size is the VM page size. The size should be reduced if you have many small objects. .El .Ss Management Interface If the From phk at projects.linpro.no Tue Jul 22 14:40:13 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 22 Jul 2008 16:40:13 +0200 (CEST) Subject: r2992 - trunk/varnish-cache/bin/varnishd Message-ID: <20080722144013.7561A1EC201@projects.linpro.no> Author: phk Date: 2008-07-22 16:40:13 +0200 (Tue, 22 Jul 2008) New Revision: 2992 Modified: trunk/varnish-cache/bin/varnishd/storage_file.c Log: constage. Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-22 11:12:51 UTC (rev 2991) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-22 14:40:13 UTC (rev 2992) @@ -239,7 +239,7 @@ static void smf_init(struct stevedore *parent, int ac, char * const *av) { - const char *size, *fn; + const char *size, *fn, *r; char *q, *p; struct stat st; struct smf_sc *sc; @@ -260,9 +260,9 @@ size = av[1]; if (ac > 2 && *av[2] != '\0') { - q = str2bytes(av[2], &page_size, 0); - if (q != NULL) - ARGV_ERR("(-sfile) granularity \"%s\": %s\n", av[2], q); + r = str2bytes(av[2], &page_size, 0); + if (r != NULL) + ARGV_ERR("(-sfile) granularity \"%s\": %s\n", av[2], r); } AN(fn); From phk at projects.linpro.no Tue Jul 22 14:40:34 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 22 Jul 2008 16:40:34 +0200 (CEST) Subject: r2993 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20080722144034.128EB1EC114@projects.linpro.no> Author: phk Date: 2008-07-22 16:40:33 +0200 (Tue, 22 Jul 2008) New Revision: 2993 Modified: trunk/varnish-cache/bin/varnishd/shmlog.c trunk/varnish-cache/include/stat_field.h Log: Add a counter for shmlog wraparounds. Modified: trunk/varnish-cache/bin/varnishd/shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/shmlog.c 2008-07-22 14:40:13 UTC (rev 2992) +++ trunk/varnish-cache/bin/varnishd/shmlog.c 2008-07-22 14:40:33 UTC (rev 2993) @@ -74,6 +74,7 @@ *logstart = SLT_ENDMARKER; logstart[loghead->ptr] = SLT_WRAPMARKER; loghead->ptr = 0; + VSL_stats->shm_cycles++; } static void Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2008-07-22 14:40:13 UTC (rev 2992) +++ trunk/varnish-cache/include/stat_field.h 2008-07-22 14:40:33 UTC (rev 2993) @@ -92,6 +92,7 @@ MAC_STAT(shm_writes, uint64_t, 'a', "SHM writes") MAC_STAT(shm_flushes, uint64_t, 'a', "SHM flushes due to overflow") MAC_STAT(shm_cont, uint64_t, 'a', "SHM MTX contention") +MAC_STAT(shm_cycles, uint64_t, 'a', "SHM cycles through buffer") MAC_STAT(sm_nreq, uint64_t, 'a', "allocator requests") MAC_STAT(sm_nobj, uint64_t, 'i', "outstanding allocations") From petter at projects.linpro.no Wed Jul 23 09:07:25 2008 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Wed, 23 Jul 2008 11:07:25 +0200 (CEST) Subject: r2994 - in trunk/varnish-cache: etc man Message-ID: <20080723090725.1825F1EC201@projects.linpro.no> Author: petter Date: 2008-07-23 11:07:24 +0200 (Wed, 23 Jul 2008) New Revision: 2994 Modified: trunk/varnish-cache/etc/default.vcl trunk/varnish-cache/man/vcl.7 Log: Updated the default.vcl and man page with the latest config from mgt_vcc.c. The following perl one-liner is useful: perl -ne 'if( $print == 1 ) { exit if( /^$/ ); eval "print " . $_; } $print = 1 if /default_vcl/;' mgt_vcc.c Fixes #135 (for now) Modified: trunk/varnish-cache/etc/default.vcl =================================================================== --- trunk/varnish-cache/etc/default.vcl 2008-07-22 14:40:33 UTC (rev 2993) +++ trunk/varnish-cache/etc/default.vcl 2008-07-23 09:07:24 UTC (rev 2994) @@ -20,16 +20,25 @@ ## Called when a client request is received # #sub vcl_recv { -# if (req.request != "GET" && req.request != "HEAD") { -# pipe; -# } -# if (req.http.Expect) { -# pipe; -# } -# if (req.http.Authenticate || req.http.Cookie) { -# pass; -# } -# lookup; +# if (req.request != "GET" && +# req.request != "HEAD" && +# req.request != "PUT" && +# req.request != "POST" && +# req.request != "TRACE" && +# req.request != "OPTIONS" && +# req.request != "DELETE") { +# pipe; +# } +# if (req.http.Expect) { +# pipe; +# } +# if (req.request != "GET" && req.request != "HEAD") { +# pass; +# } +# if (req.http.Authorization || req.http.Cookie) { +# pass; +# } +# lookup; #} # ## Called when entering pipe mode @@ -47,9 +56,13 @@ ## Called when entering an object into the cache # #sub vcl_hash { -# set req.hash += req.url; -# set req.hash += req.http.host; -# hash; +# set req.hash += req.url; +# if (req.http.host) { +# set req.hash += req.http.host; +# } else { +# set req.hash += server.ip; +# } +# hash; #} # ## Called when the requested object was found in the cache @@ -71,19 +84,18 @@ ## backend, or the request to the backend has failed # #sub vcl_fetch { -# if (!obj.valid) { -# error; -# } -# if (!obj.cacheable) { -# pass; -# } -# if (obj.http.Set-Cookie) { -# pass; -# } -# insert; +# if (!obj.valid) { +# error obj.status; +# } +# if (!obj.cacheable) { +# pass; +# } +# if (obj.http.Set-Cookie) { +# pass; +# } +# set obj.prefetch = -30s; insert; #} # -# ## Called before a cached object is delivered to the client # #sub vcl_deliver { @@ -96,7 +108,7 @@ # discard; #} # -## Called when an object is about to be discarded +# 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 2008-07-22 14:40:33 UTC (rev 2993) +++ trunk/varnish-cache/man/vcl.7 2008-07-23 09:07:24 UTC (rev 2994) @@ -507,15 +507,24 @@ } sub vcl_recv { - if (req.request != "GET" && req.request != "HEAD") { + if (req.request != "GET" && + req.request != "HEAD" && + req.request != "PUT" && + req.request != "POST" && + req.request != "TRACE" && + req.request != "OPTIONS" && + req.request != "DELETE") { pipe; } if (req.http.Expect) { pipe; } - if (req.http.Authenticate || req.http.Cookie) { + if (req.request != "GET" && req.request != "HEAD") { pass; } + if (req.http.Authorization || req.http.Cookie) { + pass; + } lookup; } @@ -529,7 +538,11 @@ sub vcl_hash { set req.hash += req.url; - set req.hash += req.http.host; + if (req.http.host) { + set req.hash += req.http.host; + } else { + set req.hash += server.ip; + } hash; } @@ -546,7 +559,7 @@ sub vcl_fetch { if (!obj.valid) { - error; + error obj.status; } if (!obj.cacheable) { pass; @@ -554,18 +567,18 @@ if (obj.http.Set-Cookie) { pass; } - insert; + set obj.prefetch = -30s; insert; } sub vcl_deliver { deliver; } -sub vcl_timeout { +sub vcl_discard { discard; } -sub vcl_discard { +sub vcl_timeout { discard; } .Ed From phk at projects.linpro.no Wed Jul 23 15:01:54 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 17:01:54 +0200 (CEST) Subject: r2995 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl Message-ID: <20080723150154.7EF331ED0AC@projects.linpro.no> Author: phk Date: 2008-07-23 17:01:54 +0200 (Wed, 23 Jul 2008) New Revision: 2995 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c trunk/varnish-cache/bin/varnishd/flint.lnt trunk/varnish-cache/bin/varnishd/flint.sh trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/flint.lnt trunk/varnish-cache/lib/libvcl/vcc_acl.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: ACL code rewrite: Add IPv6 support (untested!) Implement evil-acls IPv6 support ------------ I have implemented IPv6 filtering support, but I have done so blindly as I have no IPv6 networks to test with. Please double check before relying on this to work, and please report your findings back to us. Syntax ------ The ACL rules still have the same syntax, but the sematics have expanded to handle IPv6 also: acl foo { "foohost"; // Match, if the address is one of the // ipv4 or ipv6 addresses of "foohost" ! "foohost"; // Fail, if... "192.168.1.7" / 24; // Use mask for comparison: The '7' is // ignored // Implicit masks: !"172.16"; // Fail 172.16.0.0 to 172.16.255.255 "10.0.0"; // Match 10.0.0.0 to 10.0.0.255 "www.freebsd.org" / 24; // This will give compile error, because // the "www.freebsd.org" has both ipv4 // and ipv6 addresses, and using the same // mask for both kinds do not make sense. ( ... ); // Ignore this rule if DNS lookup fails. ( ! "idiot.net" ); // If we can resolve "idiot.net", then // return Failure to match, if we see them. } Please notice that DNS lookup happens *only* on VCL compilation, if a DNS record changes you need to recompile (ie: vcl.load or vcl.inline) your VCL code again, it is not enough to just switch vcl (vcl.use). (This is the same as with backend DNS lookups) Evil-acls --------- Most firewall or ip-filtering facilities, compile the lists of networks and masks to a table, and matches proceed sequentially through that table until the table is exhausted or a match is found. Since we compile our ACLs into C-code, we might as well implement the "evil-acl" concept, and compile the rules directly into C-code instead. An ACL like this: acl foo { "172.16"; !"172.16.17"; "172.16.17.18"; "172.16"/18; } Compiles to: if (fam == 2) { if (a[0] == 172) { if (a[1] == 16) { if (a[2] == 17) { if (a[3] == 18) { VRT_acl_log(sp, "MATCH bar " "172.16.17.18"); return (1); } VRT_acl_log(sp, "NEG_MATCH bar " "172.16.17"); return (0); } else if ((a[3] & 0xc0) == 0) { VRT_acl_log(sp, "MATCH bar " "172.16" "/18" ); return (1); } VRT_acl_log(sp, "MATCH bar " "172.16"); return (1); } } } VRT_acl_log(sp, "NO_MATCH bar"); return (0); As can be seen, for example the comparison with "172" is now shared for all four rules in the ACL, instead of being carried out once for each of the four rules. In addition to this optimization, the C-compiler will of course use its usual (and unusual) tricks to speed things up, quite likely inlining the ACL code in the VCL functions where they are referenced. It will also be noticed, that the compiler sorts the rules in "most specific order". This means that: "172.16.17.18"; gets tested before !"172.16.17"; even though it is listed later in the ACL. Previously we tested the rules in the order given. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c 2008-07-23 09:07:24 UTC (rev 2994) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_acl.c 2008-07-23 15:01:54 UTC (rev 2995) @@ -30,139 +30,16 @@ * * Runtime support for compiled VCL programs, ACLs * - * XXX: getaddrinfo() does not return a TTL. We might want to add - * XXX: a refresh facility. */ #include "config.h" -#include - -#include -#include -#include - #include "shmlog.h" #include "vrt.h" -#include "vcl.h" #include "cache.h" -#include -#include -#include -#include - -static uint32_t ipv4mask[] = { - [0] = 0xffffffff, -#define M(n) [n] = (uint32_t)((uint64_t)0xffffffff << (32 - n)) - M( 1), M( 2), M( 3), M( 4), M( 5), M( 6), M( 7), M( 8), M( 9), M(10), - M(11), M(12), M(13), M(14), M(15), M(16), M(17), M(18), M(19), M(20), - M(21), M(22), M(23), M(24), M(25), M(26), M(27), M(28), M(29), M(30), - M(31), M(32) -}; - -static int -vrt_acl_vsl(const struct sess *sp, const char *acln, const struct vrt_acl *ap, int r) -{ - - AN(ap); - if (acln != NULL) { - if (ap->name == NULL) { - assert(r == 0); - WSP(sp, SLT_VCL_acl, "NO_MATCH %s", acln); - return (r); - } - if (ap->priv == NULL) { - assert(r == 0); - WSP(sp, SLT_VCL_acl, "FAIL %s %s", acln, ap->desc); - return (r); - } - - WSP(sp, SLT_VCL_acl, "%s %s %s", - r ? "MATCH" : "NEG_MATCH", acln, ap->desc); - } - return (r); -} - -int -VRT_acl_match(const struct sess *sp, struct sockaddr *sa, const char *acln, const struct vrt_acl *ap) -{ - struct addrinfo *a1; - struct sockaddr_in *sin1, *sin2; - - if (sa->sa_family == AF_INET) - sin1 = (void*)sa; - else - sin1 = NULL; - - for ( ; ap->name != NULL; ap++) { - if (ap->priv == NULL && ap->paren) - continue; - if (ap->priv == NULL && ap->not) { - return (vrt_acl_vsl(sp, acln, ap, 0)); - } - if (ap->priv == NULL) - continue; - for (a1 = ap->priv; a1 != NULL; a1 = a1->ai_next) { - - /* only match the right family */ - if (a1->ai_family != sp->sockaddr->sa_family) - continue; - - if (a1->ai_family == AF_INET) { - assert(sin1 != NULL); - assert(a1->ai_addrlen >= sizeof (*sin2)); - sin2 = (void*)a1->ai_addr; - if (0 == (( - htonl(sin1->sin_addr.s_addr) ^ - htonl(sin2->sin_addr.s_addr)) & - ipv4mask[ap->mask > 32 ? 32 : ap->mask])) - return ( - vrt_acl_vsl(sp, acln, ap, !ap->not)); - continue; - } - - /* Not rules for unknown protos match */ - if (ap->not) - return (vrt_acl_vsl(sp, acln, ap, 0)); - } - } - return (vrt_acl_vsl(sp, acln, ap, 0)); -} - void -VRT_acl_init(struct vrt_acl *ap) +VRT_acl_log(const struct sess *sp, const char *msg) { - struct addrinfo a0, *a1; - int i; - - memset(&a0, 0, sizeof a0); - a0.ai_socktype = SOCK_STREAM; - - for ( ; ap->name != NULL; ap++) { - a1 = NULL; - i = getaddrinfo(ap->name, NULL, &a0, &a1); - if (i != 0) { - fprintf(stderr, "getaddrinfo(%s) = %s\n", - ap->name, gai_strerror(i)); - if (a1 != NULL) - freeaddrinfo(a1); - a1 = NULL; - } - ap->priv = a1; - } + WSL(sp->wrk, SLT_VCL_acl, sp->fd, msg); } - -void -VRT_acl_fini(struct vrt_acl *ap) -{ - struct addrinfo *a1; - - for ( ; ap->name != NULL; ap++) { - if (ap->priv == NULL) - continue; - a1 = ap->priv; - ap->priv = NULL; - freeaddrinfo(a1); - } -} Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2008-07-23 09:07:24 UTC (rev 2994) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2008-07-23 15:01:54 UTC (rev 2995) @@ -8,6 +8,7 @@ -elib(123) // size is both a variable and a macro with args -emacro(736, isnan) // isnanf -efile(766, ../../config.h) +-emacro(413, offsetof) // likely null pointer // -header(../../config.h) @@ -46,6 +47,7 @@ -esym(534, memmove) // Ignoring return value of function -esym(534, strcpy) // Ignoring return value of function -esym(534, vsb_printf) // Ignoring return value of function +-esym(534, vsb_vprintf) // Ignoring return value of function -esym(534, vsb_cat) // Ignoring return value of function -esym(534, vsb_bcat) // Ignoring return value of function -esym(534, vsb_putc) // Ignoring return value of function @@ -63,6 +65,8 @@ -emacro(774, HTTPH) // always false -emacro(527, ARGV_ERR) // unreachable +-e788 // enum value not used in defaulted switch + // cache.h -emacro(506, INCOMPL) // Constant value Boolean Modified: trunk/varnish-cache/bin/varnishd/flint.sh =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.sh 2008-07-23 09:07:24 UTC (rev 2994) +++ trunk/varnish-cache/bin/varnishd/flint.sh 2008-07-23 15:01:54 UTC (rev 2995) @@ -8,7 +8,10 @@ -I../.. \ -DVARNISH_STATE_DIR=\"foo\" \ flint.lnt \ - *.c ../../lib/libvarnish/*.c > $T 2>&1 + *.c \ + ../../lib/libvarnish/*.c \ + ../../lib/libvcl/*.c \ + > $T 2>&1 for t in Error Warning Info Note do Modified: trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc 2008-07-23 09:07:24 UTC (rev 2994) +++ trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc 2008-07-23 15:01:54 UTC (rev 2995) @@ -33,7 +33,7 @@ varnish v1 -vcl+backend { acl acl1 { - "!127.0.0.1"; + ! "127.0.0.1"; } sub vcl_recv { Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2008-07-23 09:07:24 UTC (rev 2994) +++ trunk/varnish-cache/include/vrt.h 2008-07-23 15:01:54 UTC (rev 2995) @@ -120,20 +120,11 @@ const char *token; }; -struct vrt_acl { - unsigned char not; - unsigned char mask; - unsigned char paren; - const char *name; - const char *desc; - void *priv; -}; - /* ACL related */ -int VRT_acl_match(const struct sess *, struct sockaddr *, const char *, const struct vrt_acl *); -void VRT_acl_init(struct vrt_acl *); -void VRT_acl_fini(struct vrt_acl *); +#define VRT_ACL_MAXADDR 16 /* max(IPv4, IPv6) */ +void VRT_acl_log(const struct sess *, const char *msg); + /* Regexp related */ void VRT_re_init(void **, const char *, int sub); void VRT_re_fini(void *); Modified: trunk/varnish-cache/lib/libvcl/flint.lnt =================================================================== --- trunk/varnish-cache/lib/libvcl/flint.lnt 2008-07-23 09:07:24 UTC (rev 2994) +++ trunk/varnish-cache/lib/libvcl/flint.lnt 2008-07-23 15:01:54 UTC (rev 2995) @@ -16,6 +16,8 @@ // 796 and 797 (out-of-bounds errors). +-emacro(413, offsetof) // likely null pointer + // -ffc // No automatic custody -esym(534, vsb_printf) // Ignoring return value of function Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_acl.c 2008-07-23 09:07:24 UTC (rev 2994) +++ trunk/varnish-cache/lib/libvcl/vcc_acl.c 2008-07-23 15:01:54 UTC (rev 2995) @@ -33,81 +33,381 @@ #include #include +#include +#include +#include +#include +#include +#include +#include #include "vsb.h" +#include "vrt.h" #include "vcc_priv.h" #include "vcc_compile.h" #include "libvarnish.h" +struct acl_e { + VTAILQ_ENTRY(acl_e) list; + unsigned char data[VRT_ACL_MAXADDR + 1]; + unsigned mask; + unsigned not; + unsigned para; + struct token *t_addr; + struct token *t_mask; +}; + +/* Compare two acl rules for ordering */ + +static int +vcl_acl_cmp(struct tokenlist *tl, struct acl_e *ae1, struct acl_e *ae2) +{ + unsigned char *p1, *p2; + unsigned m; + + (void)tl; + p1 = ae1->data; + p2 = ae2->data; + m = ae1->mask; + if (ae2->mask < m) + m = ae2->mask; + for (; m >= 8; m -= 8) { + if (*p1 < *p2) + return (-1); + if (*p1 > *p2) + return (1); + p1++; + p2++; + } + if (m) { + m = 0xff00 >> m; + m &= 0xff; + if ((*p1 & m) < (*p2 & m)) + return (-1); + if ((*p1 & m) > (*p2 & m)) + return (1); + } + if (ae1->mask > ae2->mask) + return (-1); + if (ae1->mask < ae2->mask) + return (1); + + return (0); +} + + static void -vcc_acl_top(struct tokenlist *tl, const char *acln) +vcl_acl_add_entry(struct tokenlist *tl, struct acl_e *ae) { + struct acl_e *ae2; + int i; - Fh(tl, 1, "\nstatic struct vrt_acl acl_%s[] = {\n", acln); - tl->hindent += INDENT; + VTAILQ_FOREACH(ae2, &tl->acl, list) { + i = vcl_acl_cmp(tl, ae, ae2); + if (i == 0) { + /* If the two rules agree, silently ignore it */ + if (ae->not == ae2->not) + return; + vsb_printf(tl->sb, "Conflicting ACL entries:\n"); + vcc_ErrWhere(tl, ae2->t_addr); + vsb_printf(tl->sb, "vs:\n"); + vcc_ErrWhere(tl, ae->t_addr); + return; + } + /* + * We could eliminate pointless rules here, for instance in: + * "10.1.0.1"; + * "10.1"; + * The first rule is clearly pointless, as the second one + * covers it. + * + * We do not do this however, because the shmlog may + * be used to gather statistics. + */ + if (i < 0) { + VTAILQ_INSERT_BEFORE(ae2, ae, list); + return; + } + } + VTAILQ_INSERT_TAIL(&tl->acl, ae, list); +} +static void +vcc_acl_emit_entry(struct tokenlist *tl, const struct acl_e *ae, int l, const unsigned char *u, int fam) +{ + struct acl_e *ae2; + + if (fam == PF_INET && ae->mask > 32) { + vsb_printf(tl->sb, + "Too wide mask (%u) for IPv4 address", ae->mask); + vcc_ErrWhere(tl, ae->t_mask); + return; + } + if (fam == PF_INET6 && ae->mask > 128) { + vsb_printf(tl->sb, + "Too wide mask (%u) for IPv6 address", ae->mask); + vcc_ErrWhere(tl, ae->t_mask); + return; + } + + ae2 = TlAlloc(tl, sizeof *ae2); + AN(ae2); + *ae2 = *ae; + + ae2->data[0] = fam; + ae2->mask += 8; /* family matching */ + + memcpy(ae2->data + 1, u, l); + + vcl_acl_add_entry(tl, ae2); + } static void +vcc_acl_try_getaddrinfo(struct tokenlist *tl, struct acl_e *ae) +{ + struct addrinfo *res0, *res, hint; + struct sockaddr_in *sin4; + struct sockaddr_in6 *sin6; + unsigned char *u, i4, i6; + int error, l; + + memset(&hint, 0, sizeof hint); + hint.ai_family = PF_UNSPEC; + hint.ai_socktype = SOCK_STREAM; + error = getaddrinfo(ae->t_addr->dec, "0", &hint, &res0); + if (error) { + if (ae->para) { + vsb_printf(tl->sb, + "Warning: %s ignored\n -- %s\n", + ae->t_addr->dec, gai_strerror(error)); + Fh(tl, 1, "/* Ignored ACL entry: %s%s", + ae->para ? "\"(\" " : "", ae->not ? "\"!\" " : ""); + EncToken(tl->fh, ae->t_addr); + if (ae->t_mask) + Fh(tl, 0, "/%u", ae->mask); + Fh(tl, 0, "%s\n", ae->para ? " \")\"" : ""); + Fh(tl, 1, " * getaddrinfo: %s */\n", + gai_strerror(error)); + } else { + vsb_printf(tl->sb, + "DNS lookup(%s): %s\n", + ae->t_addr->dec, gai_strerror(error)); + vcc_ErrWhere(tl, ae->t_addr); + } + return; + } + + i4 = i6 = 0; + for(res = res0; res != NULL; res = res->ai_next) { + switch(res->ai_family) { + case PF_INET: + sin4 = (void*)res->ai_addr; + u = (void*)&sin4->sin_addr; + l = 4; + if (ae->t_mask == NULL) + ae->mask = 32; + i4++; + vcc_acl_emit_entry(tl, ae, l, u, res->ai_family); + break; + case PF_INET6: + sin6 = (void*)res->ai_addr; + u = (void*)&sin6->sin6_addr; + l = 16; + if (ae->t_mask == NULL) + ae->mask = 128; + i6++; + vcc_acl_emit_entry(tl, ae, l, u, res->ai_family); + break; + default: + vsb_printf(tl->sb, + "Ignoring unknown protocol family (%d) for %.*s\n", + res->ai_family, PF(ae->t_addr)); + continue; + } + ERRCHK(tl); + } + freeaddrinfo(res0); + + if (ae->t_mask != NULL && i4 > 0 && i6 > 0) { + vsb_printf(tl->sb, + "Mask (%u) specified, but string resolves to" + " both IPv4 and IPv6 addresses.\n", ae->mask); + vcc_ErrWhere(tl, ae->t_mask); + return; + } +} + +/*-------------------------------------------------------------------- + * Ancient stupidity on the part of X/Open and other standards orgs + * dictate that "192.168" be translated to 192.0.0.168. Ever since + * CIDR happened, "192.168/16" notation has been used, but appearantly + * no API supports parsing this, so roll our own. + */ + +static int +vcc_acl_try_netnotation(struct tokenlist *tl, struct acl_e *ae) +{ + unsigned char b[4]; + int i, j, k; + const char *p; + + memset(b, 0, sizeof b); + p = ae->t_addr->dec; + for (i = 0; i < 4; i++) { + j = sscanf(p, "%hhu%n", &b[i], &k); + if (j != 1) + return (0); + if (p[k] == '\0') + break; + if (p[k] != '.') + return (0); + p += k + 1; + } + if (ae->t_mask == NULL) + ae->mask = 8 + 8 * i; + vcc_acl_emit_entry(tl, ae, 4, b, AF_INET); + return (1); +} + +static void vcc_acl_entry(struct tokenlist *tl) { - unsigned mask, para, not; - struct token *t; + struct acl_e *ae; - not = para = mask = 0; + ae = TlAlloc(tl, sizeof *ae); + AN(ae); + if (tl->t->tok == '!') { + ae->not = 1; + vcc_NextToken(tl); + } + if (tl->t->tok == '(') { - para = 1; + ae->para = 1; vcc_NextToken(tl); } - if (tl->t->tok == '!') { - not = 1; + if (!ae->not && tl->t->tok == '!') { + ae->not = 1; vcc_NextToken(tl); } ExpectErr(tl, CSTR); - /* XXX: try to look it up, warn if failure */ - t = tl->t; + ae->t_addr = tl->t; vcc_NextToken(tl); + if (tl->t->tok == '/') { vcc_NextToken(tl); + ae->t_mask = tl->t; ExpectErr(tl, CNUM); - mask = vcc_UintVal(tl); + ae->mask = vcc_UintVal(tl); vcc_NextToken(tl); } - Fh(tl, 1, "{ %u, %u, %u, ", not, mask, para); - EncToken(tl->fh, t); - Fh(tl, 0, ", \""); - if (para) - Fh(tl, 0, "("); - if (not) - Fh(tl, 0, "!"); - Fh(tl, 0, "\\\"\" "); - EncToken(tl->fh, t); - Fh(tl, 0, " \"\\\""); - if (mask) - Fh(tl, 0, "/%u", mask); - if (para) - Fh(tl, 0, ")"); - Fh(tl, 0, "\" },\n"); - if (para) { + if (ae->para) { ExpectErr(tl, ')'); vcc_NextToken(tl); } + + if (!vcc_acl_try_netnotation(tl, ae)) { + ERRCHK(tl); + vcc_acl_try_getaddrinfo(tl, ae); + } + ERRCHK(tl); } static void -vcc_acl_bot(struct tokenlist *tl, const char *acln) +vcc_acl_bot(const struct tokenlist *tl, const char *acln, int silent) { + struct acl_e *ae; + int depth, l, m, i; + unsigned at[VRT_ACL_MAXADDR + 1]; + const char *oc; - Fh(tl, 1, "{ 0, 0, 0, (void*)0, ""}\n", 0, 0); - tl->hindent -= INDENT; - Fh(tl, 1, "};\n"); - Fi(tl, 1, "\tVRT_acl_init(acl_%s);\n", acln); - Ff(tl, 1, "\tVRT_acl_fini(acl_%s);\n", acln); + Fh(tl, 0, "\nstatic int\n"); + Fh(tl, 0, "match_acl_%s(const struct sess *sp, const void *p)\n", acln); + Fh(tl, 0, "{\n"); + Fh(tl, 0, "\tunsigned fam;\n"); + Fh(tl, 0, "\tconst unsigned char *a;\n"); + Fh(tl, 0, "\n"); + Fh(tl, 0, "\ta = p;\n"); + Fh(tl, 0, "\tfam = a[%d];\n", offsetof(struct sockaddr, sa_family)); + Fh(tl, 0, "\tif (fam == %d)\n", PF_INET); + Fh(tl, 0, "\t\ta += %d;\n", offsetof(struct sockaddr_in, sin_addr)); + Fh(tl, 0, "\telse if (fam == %d)\n", PF_INET6); + Fh(tl, 0, "\t\ta += %d;\n", offsetof(struct sockaddr_in6, sin6_addr)); + Fh(tl, 0, "\telse\n"); + Fh(tl, 0, "\t\treturn(0);\n"); + Fh(tl, 0, "\n"); + depth = -1; + oc = 0; + at[0] = 256; + VTAILQ_FOREACH(ae, &tl->acl, list) { + + /* Find how much common prefix we have */ + for (l = 0; l <= depth && l * 8 < ae->mask; l++) { + assert(l >= 0); + if (ae->data[l] != at[l]) + break; + } + + /* Back down, if necessary */ + oc = ""; + while (l <= depth) { + Fh(tl, 0, "\t%*s}\n", + -depth, ""); + depth--; + oc = "else "; + } + m = ae->mask; + m -= l * 8; + for (i = l; m >= 8; m -= 8, i++) { + if (i == 0) { + Fh(tl, 0, "\t%*s%sif (fam == %d) {\n", + -i, "", oc, ae->data[i]); + } else { + Fh(tl, 0, "\t%*s%sif (a[%d] == %d) {\n", + -i, "", oc, i - 1, ae->data[i]); + } + at[i] = ae->data[i]; + depth = i; + oc = ""; + } + if (m > 0) { + Fh(tl, 0, "\t%*s%sif ((a[%d] & 0x%x) == %d) {\n", + -i, "", + oc, + i, (0xff00 >> m) & 0xff, + ae->data[i] & ((0xff00 >> m) & 0xff)); + at[i] = 256; + depth = i; + oc = ""; + } + + i = (ae->mask + 7) / 8; + + if (!silent) { + Fh(tl, 0, "\t%*sVRT_acl_log(sp, \"%sMATCH %s \" ", + -i, "", + ae->not ? "NEG_" : "", + acln, + PF(ae->t_addr)); + EncToken(tl->fh, ae->t_addr); + if (ae->t_mask != NULL) + Fh(tl, 0, " \"/%.*s\" ", PF(ae->t_mask)); + Fh(tl, 0, ");\n"); + } + + Fh(tl, 0, "\t%*sreturn (%d);\n", -i, "", ae->not ? 0 : 1); + } + + for (; 0 <= depth; depth--) + Fh(tl, 0, "\t%*.*s}\n", depth, depth, ""); + if (!silent) + Fh(tl, 0, "\tVRT_acl_log(sp, \"NO_MATCH %s\");\n", acln); + Fh(tl, 0, "\treturn (0);\n}\n"); } void @@ -121,21 +421,21 @@ vcc_NextToken(tl); ExpectErr(tl, ID); vcc_AddRef(tl, tl->t, R_ACL); - Fb(tl, 1, "VRT_acl_match(sp, %s, \"%.*s\", acl_%.*s)\n", - vp->rname, PF(tl->t), PF(tl->t)); + Fb(tl, 1, "match_acl_%.*s(sp, %s)\n", PF(tl->t), vp->rname); vcc_NextToken(tl); break; case T_EQ: case T_NEQ: + + VTAILQ_INIT(&tl->acl); tcond = tl->t->tok; vcc_NextToken(tl); asprintf(&acln, "acl_%u", tl->cnt); assert(acln != NULL); - vcc_acl_top(tl, acln); vcc_acl_entry(tl); - vcc_acl_bot(tl, acln); - Fb(tl, 1, "%sVRT_acl_match(sp, %s, 0, acl_%s)\n", - (tcond == T_NEQ ? "!" : ""), vp->rname, acln); + vcc_acl_bot(tl, acln, 1); + Fb(tl, 1, "%smatch_acl_%s(sp, %s)\n", + (tcond == T_NEQ ? "!" : ""), acln, vp->rname); free(acln); break; default: @@ -155,6 +455,7 @@ char *acln; vcc_NextToken(tl); + VTAILQ_INIT(&tl->acl); ExpectErr(tl, ID); an = tl->t; @@ -164,8 +465,6 @@ asprintf(&acln, "%.*s", PF(an)); assert(acln != NULL); - vcc_acl_top(tl, acln); - ExpectErr(tl, '{'); vcc_NextToken(tl); @@ -178,7 +477,7 @@ ExpectErr(tl, '}'); vcc_NextToken(tl); - vcc_acl_bot(tl, acln); + vcc_acl_bot(tl, acln, 0); free(acln); } Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-23 09:07:24 UTC (rev 2994) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-23 15:01:54 UTC (rev 2995) @@ -35,6 +35,8 @@ #define INDENT 2 +struct acl_e; + struct membit { VTAILQ_ENTRY(membit) list; void *ptr; @@ -85,6 +87,8 @@ struct proc *curproc; struct proc *mprocs[N_METHODS]; + VTAILQ_HEAD(, acl_e) acl; + unsigned recnt; unsigned nhashcount; unsigned nsockaddr; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-23 09:07:24 UTC (rev 2994) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-23 15:01:54 UTC (rev 2995) @@ -401,20 +401,11 @@ vsb_cat(sb, " const char *token;\n"); vsb_cat(sb, "};\n"); vsb_cat(sb, "\n"); - vsb_cat(sb, "struct vrt_acl {\n"); - vsb_cat(sb, " unsigned char not;\n"); - vsb_cat(sb, " unsigned char mask;\n"); - vsb_cat(sb, " unsigned char paren;\n"); - vsb_cat(sb, " const char *name;\n"); - vsb_cat(sb, " const char *desc;\n"); - vsb_cat(sb, " void *priv;\n"); - vsb_cat(sb, "};\n"); - vsb_cat(sb, "\n"); vsb_cat(sb, "/* ACL related */\n"); - vsb_cat(sb, "int VRT_acl_match(const struct sess *, struct sockaddr *, const char *, const struct vrt_acl *);\n"); - vsb_cat(sb, "void VRT_acl_init(struct vrt_acl *);\n"); - vsb_cat(sb, "void VRT_acl_fini(struct vrt_acl *);\n"); + vsb_cat(sb, "#define VRT_ACL_MAXADDR 16 /* max(IPv4, IPv6) */\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "void VRT_acl_log(const struct sess *, const char *msg);\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, "/* Regexp related */\n"); vsb_cat(sb, "void VRT_re_init(void **, const char *, int sub);\n"); vsb_cat(sb, "void VRT_re_fini(void *);\n"); From phk at projects.linpro.no Wed Jul 23 15:19:38 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 17:19:38 +0200 (CEST) Subject: r2996 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080723151938.A08FC1ED0A4@projects.linpro.no> Author: phk Date: 2008-07-23 17:19:38 +0200 (Wed, 23 Jul 2008) New Revision: 2996 Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c Log: don't make assumptions about pthread_t Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_client.c 2008-07-23 15:01:54 UTC (rev 2995) +++ trunk/varnish-cache/bin/varnishtest/vtc_client.c 2008-07-23 15:19:38 UTC (rev 2996) @@ -140,7 +140,7 @@ vtc_log(c->vl, 0, "Client returned \"%s\"", (char *)res); exit (1); } - c->tp = NULL; + c->tp = 0; } /********************************************************************** @@ -172,7 +172,7 @@ /* Reset and free */ VTAILQ_FOREACH_SAFE(c, &clients, list, c2) { VTAILQ_REMOVE(&clients, c, list); - if (c->tp != NULL) + if (c->tp != 0) client_wait(c); FREE_OBJ(c); /* XXX: MEMLEAK */ From phk at projects.linpro.no Wed Jul 23 15:20:37 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 17:20:37 +0200 (CEST) Subject: r2997 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080723152037.7DD851EC033@projects.linpro.no> Author: phk Date: 2008-07-23 17:20:37 +0200 (Wed, 23 Jul 2008) New Revision: 2997 Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c Log: use strtod() instead of strtof() Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2008-07-23 15:19:38 UTC (rev 2996) +++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2008-07-23 15:20:37 UTC (rev 2997) @@ -589,7 +589,7 @@ CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); AN(av[1]); AZ(av[2]); - hp->timeout = strtof(av[1], NULL) * 1000.0; + hp->timeout = strtod(av[1], NULL) * 1000.0; } /********************************************************************** From phk at projects.linpro.no Wed Jul 23 15:21:48 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 17:21:48 +0200 (CEST) Subject: r2998 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080723152148.9DF5C1ED0AC@projects.linpro.no> Author: phk Date: 2008-07-23 17:21:48 +0200 (Wed, 23 Jul 2008) New Revision: 2998 Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c Log: Don't make assumptions about pthread_t Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_server.c 2008-07-23 15:20:37 UTC (rev 2997) +++ trunk/varnish-cache/bin/varnishtest/vtc_server.c 2008-07-23 15:21:48 UTC (rev 2998) @@ -175,7 +175,7 @@ (char *)res); exit (1); } - s->tp = NULL; + s->tp = 0; AZ(close(s->sock)); s->sock = -1; } From phk at projects.linpro.no Wed Jul 23 15:30:03 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 17:30:03 +0200 (CEST) Subject: r2999 - trunk/varnish-cache/lib/libvcl Message-ID: <20080723153003.381F61EC033@projects.linpro.no> Author: phk Date: 2008-07-23 17:30:02 +0200 (Wed, 23 Jul 2008) New Revision: 2999 Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c Log: Prefix acl functions with "named_" and "anon_" to avoid naming conflicts. Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_acl.c 2008-07-23 15:21:48 UTC (rev 2998) +++ trunk/varnish-cache/lib/libvcl/vcc_acl.c 2008-07-23 15:30:02 UTC (rev 2999) @@ -319,7 +319,7 @@ } static void -vcc_acl_bot(const struct tokenlist *tl, const char *acln, int silent) +vcc_acl_bot(const struct tokenlist *tl, const char *acln, int silent, const char *pfx) { struct acl_e *ae; int depth, l, m, i; @@ -327,7 +327,8 @@ const char *oc; Fh(tl, 0, "\nstatic int\n"); - Fh(tl, 0, "match_acl_%s(const struct sess *sp, const void *p)\n", acln); + Fh(tl, 0, "match_acl_%s_%s(const struct sess *sp, const void *p)\n", + pfx, acln); Fh(tl, 0, "{\n"); Fh(tl, 0, "\tunsigned fam;\n"); Fh(tl, 0, "\tconst unsigned char *a;\n"); @@ -421,7 +422,7 @@ vcc_NextToken(tl); ExpectErr(tl, ID); vcc_AddRef(tl, tl->t, R_ACL); - Fb(tl, 1, "match_acl_%.*s(sp, %s)\n", PF(tl->t), vp->rname); + Fb(tl, 1, "match_acl_named_%.*s(sp, %s)\n", PF(tl->t), vp->rname); vcc_NextToken(tl); break; case T_EQ: @@ -430,11 +431,11 @@ VTAILQ_INIT(&tl->acl); tcond = tl->t->tok; vcc_NextToken(tl); - asprintf(&acln, "acl_%u", tl->cnt); + asprintf(&acln, "%u", tl->cnt); assert(acln != NULL); vcc_acl_entry(tl); - vcc_acl_bot(tl, acln, 1); - Fb(tl, 1, "%smatch_acl_%s(sp, %s)\n", + vcc_acl_bot(tl, acln, 1, "anon"); + Fb(tl, 1, "%smatch_acl_anon_%s(sp, %s)\n", (tcond == T_NEQ ? "!" : ""), acln, vp->rname); free(acln); break; @@ -477,7 +478,7 @@ ExpectErr(tl, '}'); vcc_NextToken(tl); - vcc_acl_bot(tl, acln, 0); + vcc_acl_bot(tl, acln, 0, "named"); free(acln); } From phk at projects.linpro.no Wed Jul 23 15:34:40 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 17:34:40 +0200 (CEST) Subject: r3000 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080723153440.583211ED0A4@projects.linpro.no> Author: phk Date: 2008-07-23 17:34:40 +0200 (Wed, 23 Jul 2008) New Revision: 3000 Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: We should not open the shm file until we have a cli connection, it might not be there yet. Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-23 15:30:02 UTC (rev 2999) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-23 15:34:40 UTC (rev 3000) @@ -221,8 +221,6 @@ vsb_delete(vsb); AZ(pthread_create(&v->tp, NULL, varnish_thread, v)); - v->stats = VSL_OpenStats(v->name); - vtc_log(v->vl, 3, "opening CLI connection"); for (i = 0; i < 10; i++) { (void)usleep(200000); @@ -237,6 +235,8 @@ } vtc_log(v->vl, 3, "CLI connection fd = %d", v->cli_fd); assert(v->cli_fd >= 0); + v->stats = VSL_OpenStats(v->name); + } /********************************************************************** From phk at projects.linpro.no Wed Jul 23 15:44:46 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 17:44:46 +0200 (CEST) Subject: r3001 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080723154446.6A1561EC236@projects.linpro.no> Author: phk Date: 2008-07-23 17:44:46 +0200 (Wed, 23 Jul 2008) New Revision: 3001 Modified: trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc Log: Note that this testcase may fail on linux. The problem is that a TCP connection to 127.0.0.1 appearantly does not originate on the loopback interface, but on some other interface on the machine. Modified: trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc 2008-07-23 15:34:40 UTC (rev 3000) +++ trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc 2008-07-23 15:44:46 UTC (rev 3001) @@ -1,6 +1,6 @@ # $Id$ -test "Test simple ACL" +test "Test simple ACL (May fail on Linux)" server s1 { rxreq From phk at projects.linpro.no Wed Jul 23 17:04:54 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 19:04:54 +0200 (CEST) Subject: r3002 - trunk/varnish-cache/lib/libvcl Message-ID: <20080723170454.54F241ECEFC@projects.linpro.no> Author: phk Date: 2008-07-23 19:04:53 +0200 (Wed, 23 Jul 2008) New Revision: 3002 Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c Log: Add a missing error check. Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-23 15:44:46 UTC (rev 3001) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-23 17:04:53 UTC (rev 3002) @@ -108,7 +108,11 @@ vcc_NextToken(tl); } else if (tl->t->tok == VAR) { Fb(tl, 0, ", "); - vcc_StringVal(tl); + if (!vcc_StringVal(tl)) { + ERRCHK(tl); + vcc_ExpectedStringval(tl); + return; + } } else { Fb(tl, 0, ", (const char *)0"); } From phk at projects.linpro.no Wed Jul 23 17:09:53 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 19:09:53 +0200 (CEST) Subject: r3003 - trunk/varnish-cache/lib/libvcl Message-ID: <20080723170953.D529F1EC201@projects.linpro.no> Author: phk Date: 2008-07-23 19:09:53 +0200 (Wed, 23 Jul 2008) New Revision: 3003 Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c Log: Flexelint nits Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2008-07-23 17:04:53 UTC (rev 3002) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2008-07-23 17:09:53 UTC (rev 3003) @@ -415,7 +415,7 @@ assert(f != NULL); i = read(fd, f, st.st_size); assert(i == st.st_size); - close(fd); + AZ(close(fd)); f[i] = '\0'; sp = vcc_new_source(f, f + i, fn); sp->freeit = f; @@ -610,13 +610,11 @@ return (vcc_DestroyTokenList(tl, NULL)); /* Check that all action returns are legal */ - vcc_CheckAction(tl); - if (tl->err) + if (vcc_CheckAction(tl) || tl->err) return (vcc_DestroyTokenList(tl, NULL)); /* Check that all variable uses are legal */ - vcc_CheckUses(tl); - if (tl->err) + if (vcc_CheckUses(tl) || tl->err) return (vcc_DestroyTokenList(tl, NULL)); /* Emit method functions */ From phk at projects.linpro.no Wed Jul 23 17:37:45 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 19:37:45 +0200 (CEST) Subject: r3004 - in trunk/varnish-cache: bin/varnishd lib/libvarnish lib/libvcl Message-ID: <20080723173745.659E01EC033@projects.linpro.no> Author: phk Date: 2008-07-23 19:37:44 +0200 (Wed, 23 Jul 2008) New Revision: 3004 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/flint.lnt trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/lib/libvarnish/cli_common.c trunk/varnish-cache/lib/libvcl/vcc_acl.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_token.c trunk/varnish-cache/lib/libvcl/vcc_xref.c Log: More Flexelint nitpickery Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-23 17:09:53 UTC (rev 3003) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-23 17:37:44 UTC (rev 3004) @@ -118,6 +118,7 @@ /*--------------------------------------------------------------------*/ +/*lint -e{818} ap,hp could be const */ static char * vrt_assemble_string(struct http *hp, const char *h, const char *p, va_list ap) { @@ -419,6 +420,7 @@ sp->director = be; } +/*lint -e{818} sp could be const */ struct director * VRT_r_req_backend(struct sess *sp) { @@ -450,6 +452,7 @@ sp->grace = a; } +/*lint -e{818} sp could be const */ double VRT_r_req_grace(struct sess *sp) { @@ -626,6 +629,7 @@ /*--------------------------------------------------------------------*/ +/*lint -e{818} sp could be const */ void VRT_panic(struct sess *sp, const char *str, ...) { Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2008-07-23 17:09:53 UTC (rev 3003) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2008-07-23 17:37:44 UTC (rev 3004) @@ -10,7 +10,9 @@ -efile(766, ../../config.h) -emacro(413, offsetof) // likely null pointer +-emacro(702, WEXITSTATUS) // signed shift right + // -header(../../config.h) // Fix strchr() semtics, it can only return NULL if arg2 != 0 @@ -38,6 +40,10 @@ -emacro((826), VTAILQ_LAST) // Suspicious pointer-to-pointer conversion (area too small) -emacro(506, VTAILQ_FOREACH_SAFE) // constant value boolean +-esym(765, vcc_ProcAction) // could be made static +-esym(759, vcc_ProcAction) // could be moved to module +-esym(714, vcc_ProcAction) // not ref. + -esym(534, sprintf) // Ignoring return value of function -esym(534, asprintf) // Ignoring return value of function -esym(534, printf) // Ignoring return value of function Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-07-23 17:09:53 UTC (rev 3003) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-07-23 17:37:44 UTC (rev 3004) @@ -544,6 +544,7 @@ /*--------------------------------------------------------------------*/ +/*lint -e{818} priv could be const */ void mcf_server_startstop(struct cli *cli, const char * const *av, void *priv) { Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-23 17:09:53 UTC (rev 3003) +++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2008-07-23 17:37:44 UTC (rev 3004) @@ -68,6 +68,7 @@ va_end(ap); } +/*lint -e{818} cli could be const */ void cli_quote(struct cli *cli, const char *s) { Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_acl.c 2008-07-23 17:09:53 UTC (rev 3003) +++ trunk/varnish-cache/lib/libvcl/vcc_acl.c 2008-07-23 17:37:44 UTC (rev 3004) @@ -155,7 +155,7 @@ AN(ae2); *ae2 = *ae; - ae2->data[0] = fam; + ae2->data[0] = fam & 0xff; ae2->mask += 8; /* family matching */ memcpy(ae2->data + 1, u, l); @@ -171,7 +171,7 @@ struct sockaddr_in *sin4; struct sockaddr_in6 *sin6; unsigned char *u, i4, i6; - int error, l; + int error; memset(&hint, 0, sizeof hint); hint.ai_family = PF_UNSPEC; @@ -204,21 +204,23 @@ switch(res->ai_family) { case PF_INET: sin4 = (void*)res->ai_addr; + assert(sizeof(sin4->sin_family) == 1); + assert(sizeof(sin4->sin_addr) == 4); u = (void*)&sin4->sin_addr; - l = 4; if (ae->t_mask == NULL) ae->mask = 32; i4++; - vcc_acl_emit_entry(tl, ae, l, u, res->ai_family); + vcc_acl_emit_entry(tl, ae, 4, u, res->ai_family); break; case PF_INET6: sin6 = (void*)res->ai_addr; + assert(sizeof(sin4->sin_family) == 1); + assert(sizeof(sin4->sin_addr) == 16); u = (void*)&sin6->sin6_addr; - l = 16; if (ae->t_mask == NULL) ae->mask = 128; i6++; - vcc_acl_emit_entry(tl, ae, l, u, res->ai_family); + vcc_acl_emit_entry(tl, ae, 16, u, res->ai_family); break; default: vsb_printf(tl->sb, Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-23 17:09:53 UTC (rev 3003) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-23 17:37:44 UTC (rev 3004) @@ -208,7 +208,6 @@ void vcc__Expect(struct tokenlist *tl, unsigned tok, int line); int vcc_Teq(const struct token *t1, const struct token *t2); int vcc_IdIs(const struct token *t, const char *p); -int vcc_isCid(const struct token *t); void vcc_ExpectCid(struct tokenlist *tl); void vcc_Lexer(struct tokenlist *tl, struct source *sp); void vcc_NextToken(struct tokenlist *tl); Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token.c 2008-07-23 17:09:53 UTC (rev 3003) +++ trunk/varnish-cache/lib/libvcl/vcc_token.c 2008-07-23 17:37:44 UTC (rev 3004) @@ -191,7 +191,7 @@ * Check that we have a C-identifier */ -int +static int vcc_isCid(const struct token *t) { const char *q; @@ -266,7 +266,7 @@ vcc_ErrWhere(tl, tl->t); return(1); } - u = vcc_xdig(p[1]) * 16 + vcc_xdig(p[2]); + u = (vcc_xdig(p[1]) * 16 + vcc_xdig(p[2])) & 0xff; if (!isgraph(u)) { vcc_AddToken(tl, CSTR, p, p + 3); vsb_printf(tl->sb, @@ -301,12 +301,6 @@ else VTAILQ_INSERT_TAIL(&tl->tokens, t, list); tl->t = t; - if (0) { - fprintf(stderr, "[%s %.*s] ", - vcl_tnames[tok], PF(t)); - if (tok == EOI) - fprintf(stderr, "\n"); - } } /*-------------------------------------------------------------------- Modified: trunk/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_xref.c 2008-07-23 17:09:53 UTC (rev 3003) +++ trunk/varnish-cache/lib/libvcl/vcc_xref.c 2008-07-23 17:37:44 UTC (rev 3004) @@ -242,7 +242,7 @@ vcc_ProcAction(struct proc *p, unsigned returns, struct token *t) { - p->returns |= (1 << returns); + p->returns |= (1U << returns); /* Record the first instance of this return */ if (p->return_tok[returns] == NULL) p->return_tok[returns] = t; @@ -266,16 +266,15 @@ } u = p->returns & ~returns; if (u) { -/*lint -e525 */ +/*lint -save -e525 -e539 */ #define VCL_RET_MAC(a, b, c, d) \ if (u & VCL_RET_##b) { \ vsb_printf(tl->sb, "Invalid return \"%s\"\n", #a); \ vcc_ErrWhere(tl, p->return_tok[d]); \ } -/*lint -e525 */ #include "vcl_returns.h" -/*lint +e525 */ #undef VCL_RET_MAC +/*lint -restore */ vsb_printf(tl->sb, "\n...in function \"%.*s\"\n", PF(p->name)); vcc_ErrWhere(tl, p->name); return (1); @@ -314,11 +313,12 @@ if (m->returns & c) \ vsb_printf(tl->sb, " \"%s\"", #a); #define VCL_RET_MAC_E(a, b, c, d) VCL_RET_MAC(a, b, c, d) -/*lint -e525 */ +/*lint -save -e525 -e539 */ #include "vcl_returns.h" /*lint +e525 */ #undef VCL_RET_MAC #undef VCL_RET_MAC_E +/*lint -restore */ vsb_printf(tl->sb, "\n"); return (1); } From phk at projects.linpro.no Wed Jul 23 20:57:41 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 22:57:41 +0200 (CEST) Subject: r3005 - trunk/varnish-cache/lib/libvcl Message-ID: <20080723205741.056F11ED0A9@projects.linpro.no> Author: phk Date: 2008-07-23 22:57:40 +0200 (Wed, 23 Jul 2008) New Revision: 3005 Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c Log: Copy&Paste'o Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_acl.c 2008-07-23 17:37:44 UTC (rev 3004) +++ trunk/varnish-cache/lib/libvcl/vcc_acl.c 2008-07-23 20:57:40 UTC (rev 3005) @@ -214,8 +214,8 @@ break; case PF_INET6: sin6 = (void*)res->ai_addr; - assert(sizeof(sin4->sin_family) == 1); - assert(sizeof(sin4->sin_addr) == 16); + assert(sizeof(sin6->sin6_family) == 1); + assert(sizeof(sin6->sin6_addr) == 16); u = (void*)&sin6->sin6_addr; if (ae->t_mask == NULL) ae->mask = 128; From phk at projects.linpro.no Wed Jul 23 21:04:12 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 23:04:12 +0200 (CEST) Subject: r3006 - trunk/varnish-cache/bin/varnishd Message-ID: <20080723210412.F37CE1EC201@projects.linpro.no> Author: phk Date: 2008-07-23 23:04:12 +0200 (Wed, 23 Jul 2008) New Revision: 3006 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Prevent loading multiple VCL's with the same name if the client is not there to stop us. Fixes #281 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-07-23 20:57:40 UTC (rev 3005) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-07-23 21:04:12 UTC (rev 3006) @@ -393,16 +393,27 @@ free(vp); } +static struct vclprog * +mgt_vcc_byname(const char *name) +{ + struct vclprog *vp; + + VTAILQ_FOREACH(vp, &vclhead, list) + if (!strcmp(name, vp->name)) + return (vp); + return (NULL); +} + + static int mgt_vcc_delbyname(const char *name) { struct vclprog *vp; - VTAILQ_FOREACH(vp, &vclhead, list) { - if (!strcmp(name, vp->name)) { - mgt_vcc_del(vp); - return (0); - } + vp = mgt_vcc_byname(name); + if (vp != NULL) { + mgt_vcc_del(vp); + return (0); } return (1); } @@ -541,9 +552,17 @@ char *vf, *p = NULL; struct vsb *sb; unsigned status; + struct vclprog *vp; (void)priv; + vp = mgt_vcc_byname(av[2]); + if (vp != NULL) { + cli_out(cli, "Already a VCL program named %s", av[2]); + cli_result(cli, CLIS_PARAM); + return; + } + sb = vsb_newauto(); XXXAN(sb); vf = mgt_VccCompile(sb, av[3], NULL, 0); @@ -575,8 +594,15 @@ struct vsb *sb; unsigned status; char *p = NULL; + struct vclprog *vp; (void)priv; + vp = mgt_vcc_byname(av[2]); + if (vp != NULL) { + cli_out(cli, "Already a VCL program named %s", av[2]); + cli_result(cli, CLIS_PARAM); + return; + } sb = vsb_newauto(); XXXAN(sb); @@ -607,9 +633,9 @@ { struct vclprog *vp; - VTAILQ_FOREACH(vp, &vclhead, list) - if (!strcmp(vp->name, name)) - return (vp); + vp = mgt_vcc_byname(name); + if (vp != NULL) + return (vp); cli_result(cli, CLIS_PARAM); cli_out(cli, "No configuration named %s known.", name); return (NULL); From phk at projects.linpro.no Wed Jul 23 21:10:17 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 23 Jul 2008 23:10:17 +0200 (CEST) Subject: r3007 - trunk/varnish-cache/bin/varnishd Message-ID: <20080723211017.EBC331EC033@projects.linpro.no> Author: phk Date: 2008-07-23 23:10:17 +0200 (Wed, 23 Jul 2008) New Revision: 3007 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c Log: Make the manager respect the diag_bitmap for child core creation. Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-07-23 21:04:12 UTC (rev 3006) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-07-23 21:10:17 UTC (rev 3007) @@ -168,7 +168,10 @@ REPORT(LOG_ERR, "Child (%d) not responding to ping, killing it.", child_pid); - (void)kill(child_pid, SIGKILL); + if (params->diag_bitmap & 0x1000) + (void)kill(child_pid, SIGKILL); + else + (void)kill(child_pid, SIGQUIT); return (0); } From des at projects.linpro.no Thu Jul 24 11:04:46 2008 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 24 Jul 2008 13:04:46 +0200 (CEST) Subject: r3008 - trunk/varnish-cache/bin/varnishd Message-ID: <20080724110446.A877A1EC203@projects.linpro.no> Author: des Date: 2008-07-24 13:04:46 +0200 (Thu, 24 Jul 2008) New Revision: 3008 Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 Log: Markup Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2008-07-23 21:10:17 UTC (rev 3007) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2008-07-24 11:04:46 UTC (rev 3008) @@ -288,12 +288,15 @@ .Pp The .Ar granularity -parameter specifies the granularity of allocation. All allocations are rounded up to this size. -The size is assumed to be in bytes, unless followed by one of the suffixes described for +parameter specifies the granularity of allocation. +All allocations are rounded up to this size. +The size is assumed to be in bytes, unless followed by one of the +suffixes described for .Ar size except for %. .Pp -The default size is the VM page size. The size should be reduced if you have many small objects. +The default size is the VM page size. +The size should be reduced if you have many small objects. .El .Ss Management Interface If the From des at projects.linpro.no Thu Jul 24 11:21:35 2008 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 24 Jul 2008 13:21:35 +0200 (CEST) Subject: r3009 - trunk/varnish-cache/etc Message-ID: <20080724112135.818B51EC10A@projects.linpro.no> Author: des Date: 2008-07-24 13:21:35 +0200 (Thu, 24 Jul 2008) New Revision: 3009 Modified: trunk/varnish-cache/etc/default.vcl Log: Reindent Modified: trunk/varnish-cache/etc/default.vcl =================================================================== --- trunk/varnish-cache/etc/default.vcl 2008-07-24 11:04:46 UTC (rev 3008) +++ trunk/varnish-cache/etc/default.vcl 2008-07-24 11:21:35 UTC (rev 3009) @@ -20,25 +20,25 @@ ## Called when a client request is received # #sub vcl_recv { -# if (req.request != "GET" && -# req.request != "HEAD" && -# req.request != "PUT" && -# req.request != "POST" && -# req.request != "TRACE" && -# req.request != "OPTIONS" && -# req.request != "DELETE") { -# pipe; -# } -# if (req.http.Expect) { -# pipe; -# } -# if (req.request != "GET" && req.request != "HEAD") { -# pass; -# } -# if (req.http.Authorization || req.http.Cookie) { -# pass; -# } -# lookup; +# if (req.request != "GET" && +# req.request != "HEAD" && +# req.request != "PUT" && +# req.request != "POST" && +# req.request != "TRACE" && +# req.request != "OPTIONS" && +# req.request != "DELETE") { +# pipe; +# } +# if (req.http.Expect) { +# pipe; +# } +# if (req.request != "GET" && req.request != "HEAD") { +# pass; +# } +# if (req.http.Authorization || req.http.Cookie) { +# pass; +# } +# lookup; #} # ## Called when entering pipe mode @@ -56,13 +56,13 @@ ## Called when entering an object into the cache # #sub vcl_hash { -# set req.hash += req.url; -# if (req.http.host) { -# set req.hash += req.http.host; -# } else { -# set req.hash += server.ip; -# } -# hash; +# set req.hash += req.url; +# if (req.http.host) { +# set req.hash += req.http.host; +# } else { +# set req.hash += server.ip; +# } +# hash; #} # ## Called when the requested object was found in the cache @@ -84,22 +84,22 @@ ## backend, or the request to the backend has failed # #sub vcl_fetch { -# if (!obj.valid) { -# error obj.status; -# } -# if (!obj.cacheable) { -# pass; -# } -# if (obj.http.Set-Cookie) { -# pass; -# } -# set obj.prefetch = -30s; insert; +# if (!obj.valid) { +# error obj.status; +# } +# if (!obj.cacheable) { +# pass; +# } +# if (obj.http.Set-Cookie) { +# pass; +# } +# set obj.prefetch = -30s; insert; #} # ## Called before a cached object is delivered to the client # #sub vcl_deliver { -# deliver; +# deliver; #} # ## Called when an object nears its expiry time @@ -111,5 +111,5 @@ # Called when an object is about to be discarded # #sub vcl_discard { -# discard; +# discard; #} From des at projects.linpro.no Thu Jul 24 11:23:16 2008 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 24 Jul 2008 13:23:16 +0200 (CEST) Subject: r3010 - in trunk/varnish-cache: bin/varnishd lib/libvcl Message-ID: <20080724112316.DB5721EC203@projects.linpro.no> Author: des Date: 2008-07-24 13:23:16 +0200 (Thu, 24 Jul 2008) New Revision: 3010 Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c Log: Correct copyright statement. Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-24 11:21:35 UTC (rev 3009) +++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-24 11:23:16 UTC (rev 3010) @@ -1,6 +1,5 @@ /*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2008 Linpro AS * All rights reserved. * * Author: Petter Knudsen Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2008-07-24 11:21:35 UTC (rev 3009) +++ trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2008-07-24 11:23:16 UTC (rev 3010) @@ -1,6 +1,5 @@ /*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2008 Linpro AS * All rights reserved. * * Author: Petter Knudsen From des at projects.linpro.no Thu Jul 24 12:21:31 2008 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 24 Jul 2008 14:21:31 +0200 (CEST) Subject: r3011 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080724122131.36DE71EC10A@projects.linpro.no> Author: des Date: 2008-07-24 14:21:30 +0200 (Thu, 24 Jul 2008) New Revision: 3011 Modified: trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc Log: Fix temp file names Modified: trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc 2008-07-24 11:23:16 UTC (rev 3010) +++ trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc 2008-07-24 12:21:30 UTC (rev 3011) @@ -2,8 +2,8 @@ test "Check -f command line arg" -shell "echo 'backend foo { .host = \"127.0.0.1\"; .port = \"9080\"; }' > /tmp/_b00013.vcl" -varnish v1 -arg "-h simple_list -f /tmp/_b00013.vcl" -start +shell "echo 'backend foo { .host = \"127.0.0.1\"; .port = \"9080\"; }' > /tmp/_b00014.vcl" +varnish v1 -arg "-h simple_list -f /tmp/_b00014.vcl" -start server s1 { rxreq @@ -19,11 +19,11 @@ rxresp } -run -varnish v1 -cli "vcl.load foo /tmp/_b00013.vcl" -cli "vcl.use foo" +varnish v1 -cli "vcl.load foo /tmp/_b00014.vcl" -cli "vcl.use foo" client c1 { txreq -url /bar rxresp } -run -shell "rm -f /tmp/_b00013.vcl" +shell "rm -f /tmp/_b00014.vcl" From des at projects.linpro.no Thu Jul 24 12:22:36 2008 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 24 Jul 2008 14:22:36 +0200 (CEST) Subject: r3012 - in trunk/varnish-cache/bin/varnishtest: . tests Message-ID: <20080724122236.2D73E1EC203@projects.linpro.no> Author: des Date: 2008-07-24 14:22:35 +0200 (Thu, 24 Jul 2008) New Revision: 3012 Modified: trunk/varnish-cache/bin/varnishtest/Makefile.am trunk/varnish-cache/bin/varnishtest/flint.lnt trunk/varnish-cache/bin/varnishtest/flint.sh trunk/varnish-cache/bin/varnishtest/tests/README trunk/varnish-cache/bin/varnishtest/tests/a00008.vtc trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc trunk/varnish-cache/bin/varnishtest/tests/v00007.vtc trunk/varnish-cache/bin/varnishtest/tests/v00008.vtc trunk/varnish-cache/bin/varnishtest/tests/v00009.vtc trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc trunk/varnish-cache/bin/varnishtest/vtc_sema.c Log: Set svn:keywords on files that didn't already have it Property changes on: trunk/varnish-cache/bin/varnishtest/Makefile.am ___________________________________________________________________ Name: svn:keywords - vtc.c + Id Property changes on: trunk/varnish-cache/bin/varnishtest/flint.lnt ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/flint.sh ___________________________________________________________________ Name: svn:keywords - + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/README ___________________________________________________________________ Name: svn:keywords - + Id Modified: trunk/varnish-cache/bin/varnishtest/tests/a00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/a00008.vtc 2008-07-24 12:21:30 UTC (rev 3011) +++ trunk/varnish-cache/bin/varnishtest/tests/a00008.vtc 2008-07-24 12:22:35 UTC (rev 3012) @@ -1,4 +1,4 @@ -# $Id: a00007.vtc 2906 2008-07-08 10:29:07Z phk $ +# $Id$ test "Sema operations" Property changes on: trunk/varnish-cache/bin/varnishtest/tests/a00008.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00014.vtc ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc 2008-07-24 12:21:30 UTC (rev 3011) +++ trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc 2008-07-24 12:22:35 UTC (rev 3012) @@ -1,4 +1,4 @@ -# $Id: c00015.vtc 2906 2008-07-08 10:29:07Z phk $ +# $Id$ test "Test Connection header handling" Property changes on: trunk/varnish-cache/bin/varnishtest/tests/c00016.vtc ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-24 12:21:30 UTC (rev 3011) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-24 12:22:35 UTC (rev 3012) @@ -1,4 +1,4 @@ -# $Id: e00004.vtc 2906 2008-07-08 10:29:07Z phk $ +# $Id$ test "ESI parsing errors" Property changes on: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc 2008-07-24 12:21:30 UTC (rev 3011) +++ trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc 2008-07-24 12:22:35 UTC (rev 3012) @@ -1,4 +1,4 @@ -# $Id: v00006.vtc 2906 2008-07-08 10:29:07Z phk $ +# $Id$ test "VCL: Test backend retirement" Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00006.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00007.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00008.vtc ___________________________________________________________________ Name: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00009.vtc ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc 2008-07-24 12:21:30 UTC (rev 3011) +++ trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc 2008-07-24 12:22:35 UTC (rev 3012) @@ -1,4 +1,4 @@ -# $Id: v00005.vtc 2906 2008-07-08 10:29:07Z phk $ +# $Id$ test "VCL: check panic and restart" Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/bin/varnishtest/vtc_sema.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_sema.c 2008-07-24 12:21:30 UTC (rev 3011) +++ trunk/varnish-cache/bin/varnishtest/vtc_sema.c 2008-07-24 12:22:35 UTC (rev 3012) @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: vtc_sema.c 2906 2008-07-08 10:29:07Z phk $ + * $Id$ */ #include Property changes on: trunk/varnish-cache/bin/varnishtest/vtc_sema.c ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Thu Jul 24 12:24:17 2008 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 24 Jul 2008 14:24:17 +0200 (CEST) Subject: r3013 - in trunk/varnish-cache: bin/varnishd lib/libvcl Message-ID: <20080724122417.67B821EC111@projects.linpro.no> Author: des Date: 2008-07-24 14:24:17 +0200 (Thu, 24 Jul 2008) New Revision: 3013 Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c Log: Set svn:keywords Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-24 12:22:35 UTC (rev 3012) +++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2008-07-24 12:24:17 UTC (rev 3013) @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: cache_dir_round_robin.c 2906 2008-07-08 10:29:07Z phk $ + * $Id$ * */ Property changes on: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c ___________________________________________________________________ Name: svn:keywords + Id Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2008-07-24 12:22:35 UTC (rev 3012) +++ trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2008-07-24 12:24:17 UTC (rev 3013) @@ -25,7 +25,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: vcc_dir_random.c 2900 2008-07-08 07:30:42Z phk $ + * $Id$ */ #include "config.h" Property changes on: trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c ___________________________________________________________________ Name: svn:keywords + Id From des at projects.linpro.no Thu Jul 24 12:33:32 2008 From: des at projects.linpro.no (des at projects.linpro.no) Date: Thu, 24 Jul 2008 14:33:32 +0200 (CEST) Subject: r3014 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080724123332.725851EC10A@projects.linpro.no> Author: des Date: 2008-07-24 14:33:32 +0200 (Thu, 24 Jul 2008) New Revision: 3014 Added: trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc Log: Test caching of synthetic error pages (broken since 2266). This will need revisiting once caching has been reimplemented. Added: trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc 2008-07-24 12:33:32 UTC (rev 3014) @@ -0,0 +1,19 @@ +# $Id$ + +test "Check synthetic error page caching" + +server s1 { + rxreq + txresp -status 503 -msg "Server Error" +} -start + +varnish v1 -vcl+backend { } -start + +client c1 { + txreq -url "/" + rxresp + expect resp.status == 503 + txreq -url "/" + rxresp + expect resp.status == 503 +} -run Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc ___________________________________________________________________ Name: svn:keywords + Id From phk at projects.linpro.no Thu Jul 24 20:16:06 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 24 Jul 2008 22:16:06 +0200 (CEST) Subject: r3015 - trunk/varnish-cache/bin/varnishd Message-ID: <20080724201606.01E941EC111@projects.linpro.no> Author: phk Date: 2008-07-24 22:16:04 +0200 (Thu, 24 Jul 2008) New Revision: 3015 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Properly truncate bytes before hexdumping. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-24 12:33:32 UTC (rev 3014) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-24 20:16:04 UTC (rev 3015) @@ -117,7 +117,7 @@ *q++ = 't'; } else { /* XXX: use %%%02x instead ? */ - q += sprintf(q, "\\x%02x", *p); + q += sprintf(q, "\\x%02x", *p & 0xff); } p++; i--; From phk at projects.linpro.no Thu Jul 24 20:39:05 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 24 Jul 2008 22:39:05 +0200 (CEST) Subject: r3016 - trunk/varnish-cache/bin/varnishd Message-ID: <20080724203905.4ECD11EC111@projects.linpro.no> Author: phk Date: 2008-07-24 22:39:04 +0200 (Thu, 24 Jul 2008) New Revision: 3016 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Add a check to avoid doing ESI parsing of objects that do not look like XML. Our definition of "looks like XML" is that the first non-white-space character is '<'. Add a new parameter "esi_syntax" with bits to steer the ESI parser. Use the first bit to disable the "looks like XML" check. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-24 20:16:04 UTC (rev 3015) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2008-07-24 20:39:04 UTC (rev 3016) @@ -637,6 +637,26 @@ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + if (!(params->esi_syntax & 0x00000001)) { + /* + * By default, we will not ESI process an object where + * the first non-space character is different from '<' + */ + st = VTAILQ_FIRST(&sp->obj->store); + AN(st); + for (u = 0; u < st->len; u++) { + if (isspace(st->ptr[u])) + continue; + if (st->ptr[u] == '<') + break; + WSP(sp, SLT_ESI_xmlerror, + "No ESI processing, " + "binary object: 0x%02x at pos %u.", + st->ptr[u], u); + return; + } + } + /* XXX: only if GET ? */ ew = eww; memset(eww, 0, sizeof eww); Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2008-07-24 20:16:04 UTC (rev 3015) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2008-07-24 20:39:04 UTC (rev 3016) @@ -143,6 +143,9 @@ /* Maximum esi:include depth allowed */ unsigned max_esi_includes; + /* ESI parser hints */ + unsigned esi_syntax; + /* Rush exponent */ unsigned rush_exponent; Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-24 20:16:04 UTC (rev 3015) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-24 20:39:04 UTC (rev 3016) @@ -719,6 +719,13 @@ "the backend, so don't increase thoughtlessly.\n", 0, "4", "restarts" }, + { "esi_syntax", + tweak_uint, &master.esi_syntax, 0, UINT_MAX, + "Bitmap controlling ESI parsing code:\n" + " 0x00000001 - Don't check if it looks like XML\n" + "Use 0x notation and do the bitor in your head :-)\n", + 0, + "0", "restarts" }, { "max_esi_includes", tweak_uint, &master.max_esi_includes, 0, UINT_MAX, "Maximum depth of esi:include processing." From phk at projects.linpro.no Thu Jul 24 21:55:57 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 24 Jul 2008 23:55:57 +0200 (CEST) Subject: r3017 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080724215557.37D901EC10A@projects.linpro.no> Author: phk Date: 2008-07-24 23:55:56 +0200 (Thu, 24 Jul 2008) New Revision: 3017 Modified: trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc Log: Use "localhost" in our acls, so it works no matter which address it picks off your loopback interface. Modified: trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc 2008-07-24 20:39:04 UTC (rev 3016) +++ trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc 2008-07-24 21:55:56 UTC (rev 3017) @@ -13,7 +13,7 @@ varnish v1 -vcl+backend { acl acl1 { - "127.0.0.1"; + "localhost"; } sub vcl_recv { @@ -33,7 +33,7 @@ varnish v1 -vcl+backend { acl acl1 { - ! "127.0.0.1"; + ! "localhost"; } sub vcl_recv { From phk at projects.linpro.no Thu Jul 24 22:09:26 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 25 Jul 2008 00:09:26 +0200 (CEST) Subject: r3018 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080724220926.900C71EC114@projects.linpro.no> Author: phk Date: 2008-07-25 00:09:25 +0200 (Fri, 25 Jul 2008) New Revision: 3018 Added: trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc Modified: trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc Log: Make the ESI testcases start with an XML tag to satsify our new non-XML detector logic. Add a testcase to see if it works and that we can override it. Modified: trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc 2008-07-24 21:55:56 UTC (rev 3017) +++ trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc 2008-07-24 22:09:25 UTC (rev 3018) @@ -6,6 +6,7 @@ server s1 { rxreq txresp -body { + Before include After include Modified: trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc 2008-07-24 21:55:56 UTC (rev 3017) +++ trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc 2008-07-24 22:09:25 UTC (rev 3018) @@ -6,6 +6,7 @@ server s1 { rxreq txresp -body { + Before include After include Modified: trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc 2008-07-24 21:55:56 UTC (rev 3017) +++ trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc 2008-07-24 22:09:25 UTC (rev 3018) @@ -7,6 +7,7 @@ rxreq expect req.url == "/foo/bar" txresp -body { + Before include After include Modified: trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc 2008-07-24 21:55:56 UTC (rev 3017) +++ trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc 2008-07-24 22:09:25 UTC (rev 3018) @@ -7,6 +7,7 @@ rxreq expect req.url == "/foo/bar" txresp -body { + Before include After include Modified: trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc 2008-07-24 21:55:56 UTC (rev 3017) +++ trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc 2008-07-24 22:09:25 UTC (rev 3018) @@ -8,6 +8,7 @@ expect req.url == "/foo/bar" txresp -hdr "Connection: close" send { + This is before the test Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-24 21:55:56 UTC (rev 3017) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2008-07-24 22:09:25 UTC (rev 3018) @@ -5,6 +5,7 @@ server s1 { rxreq txresp -body { + Before include After include Added: trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc 2008-07-24 22:09:25 UTC (rev 3018) @@ -0,0 +1,44 @@ +# $Id: e00008.vtc 3012 2008-07-24 12:22:35Z des $ + +test "ESI binary detector" + +server s1 { + rxreq + txresp -body { + Before include + + bar + + + bar + + Author: phk Date: 2008-07-25 00:12:41 +0200 (Fri, 25 Jul 2008) New Revision: 3019 Modified: trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/rfc2616.c Log: Don my peril sensitive sun-glasses, and go over the TTL calculation routine. Follow RFC2616 more closely, and make relative (ie: max-age) specifications take precedence over absolute specifications (Expires:) Add an explicit clock-skew window (parameter: clock_skew) and only interpret Expires: in absolute terms if the Date: header is inside this window. Explicit check for the case where the backend sends an Expires: which is before the Date:, even if the Date: is out side our window. Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2008-07-24 22:09:25 UTC (rev 3018) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2008-07-24 22:12:41 UTC (rev 3019) @@ -175,6 +175,9 @@ /* Prefer IPv6 connections to backend*/ unsigned prefer_ipv6; + + /* Acceptable clockskew with backends */ + unsigned clock_skew; }; extern volatile struct params *params; Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-24 22:09:25 UTC (rev 3018) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-24 22:12:41 UTC (rev 3019) @@ -745,6 +745,11 @@ "VCL can override this default value for each backend.", 0, "400", "ms" }, + { "clock_skew", tweak_uint, &master.clock_skew, 0, UINT_MAX, + "How much clockskew we are willing to accept between the " + "backend and our own clock.", + 0, + "10", "s" }, { "prefer_ipv6", tweak_bool, &master.prefer_ipv6, 0, 0, "Prefer IPv6 address when connecting to backends which " "have both IPv4 and IPv6 addresses.", Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- trunk/varnish-cache/bin/varnishd/rfc2616.c 2008-07-24 22:09:25 UTC (rev 3018) +++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2008-07-24 22:12:41 UTC (rev 3019) @@ -60,106 +60,101 @@ * choice. * * Varnish implements a policy which is RFC2616 compliant when there - * is no clockskew, and falls back to a new "clockless cache" mode otherwise. + * is no clockskew, and falls as gracefully as possible otherwise. * Our "clockless cache" model is syntehsized from the bits of RFC2616 * that talks about how a cache should react to a clockless origin server, - * and more or uses the inverse logic for the opposite relationship. + * and more or less uses the inverse logic for the opposite relationship. * */ -#if PSEUDO_CODE - /* Marker for no retirement age determined */ - retirement_age = INT_MAX +static double +RFC2616_Ttl(const struct sess *sp, const struct http *hp, struct object *obj) +{ + int ttl; + unsigned max_age, age; + double h_date, h_expires, ttd; + char *p; - /* If we have a max-age directive, respect it */ - if (max-age) - retirement_age = max(0,min(retirement_age, max-age - Age:)) + /* If all else fails, cache using default ttl */ + ttl = params->default_ttl; - /* If Date: is not in future and Expires: looks sensible, use it */ - if ((!date || date < our_clock) && expires > our_clock) { - ttd = min(our_clock + retirement_age, Expires:) + max_age = age = 0; + ttd = 0; + h_expires = 0; + h_date = 0; - /* Otherwise we have clock-skew */ - } else { - /* If we have both date and expires, infer max-age */ - if (date && expires) - retirement_age = - max(0, min(retirement_age, Expires: - Date:) + do { /* Allows us to break when we want out */ - /* Apply default_ttl if nothing better found */ - if (retirement_age == INT_MAX) - retirement_age = default_ttl + /* + * First find any relative specification from the backend + * These take precedence according to RFC2616, 13.2.4 + */ - /* Apply the max-age we can up with */ - ttd = our_clock + retirement_age - } + if ((http_GetHdrField(hp, H_Cache_Control, "s-maxage", &p) || + http_GetHdrField(hp, H_Cache_Control, "max-age", &p)) && + p != NULL) { - /* Apply hard limits */ - ttd = max(ttd, our_clock + hard_lower_ttl) - ttd = min(ttd, our_clock + hard_upper_ttl) -#endif + max_age = strtoul(p, NULL, 0); + if (http_GetHdr(hp, H_Age, &p)) { + age = strtoul(p, NULL, 0); + obj->age = age; + } -static double -RFC2616_Ttl(const struct sess *sp, const struct http *hp, struct object *obj) -{ - int retirement_age; - unsigned u1, u2; - double h_date, h_expires, ttd; - char *p; + if (age > max_age) + ttl = 0; + else + ttl = max_age - age; + break; + } - retirement_age = INT_MAX; + /* Next look for absolute specifications from backend */ - u1 = u2 = 0; - if ((http_GetHdrField(hp, H_Cache_Control, "s-maxage", &p) || - http_GetHdrField(hp, H_Cache_Control, "max-age", &p)) && - p != NULL) { - u1 = strtoul(p, NULL, 0); - u2 = 0; - if (http_GetHdr(hp, H_Age, &p)) { - u2 = strtoul(p, NULL, 0); - obj->age = u2; - } - if (u2 <= u1) - retirement_age = u1 - u2; - } + if (http_GetHdr(hp, H_Expires, &p)) + h_expires = TIM_parse(p); + if (h_expires == 0) + break; - /* - * XXX: if the backends time is too skewed relative to our own - * XXX: we should blacklist the backend, to avoid getting totally - * XXX: bogus results further down. Exactly what "too skewed" means - * XXX: in this context is a good question. It could be determined - * XXX: out according to the backends headers, but a simple fixed - * XXX: tolerance of a minute either way would be more predictable. - */ - h_date = 0; - if (http_GetHdr(hp, H_Date, &p)) - h_date = TIM_parse(p); + if (http_GetHdr(hp, H_Date, &p)) + h_date = TIM_parse(p); - h_expires = 0; - if (http_GetHdr(hp, H_Expires, &p)) - h_expires = TIM_parse(p); + /* If backend told us it is expired already, don't cache. */ + if (h_expires < h_date) { + ttl = 0; + break; + } - if (h_date < obj->entered && h_expires > obj->entered) { - ttd = h_expires; - if (retirement_age != INT_MAX && - obj->entered + retirement_age < ttd) - ttd = obj->entered + retirement_age; - } else { - if (h_date != 0 && h_expires != 0) { - if (h_date < h_expires && - h_expires - h_date < retirement_age) - retirement_age = h_expires - h_date; + if (h_date == 0 || + (h_date < obj->entered + params->clock_skew && + h_date + params->clock_skew > obj->entered)) { + /* + * If we have no Date: header or if it is + * sufficiently close to our clock we will + * trust Expires: relative to our own clock. + */ + if (h_expires < obj->entered) + ttl = 0; + else + ttd = h_expires; + break; } - if (retirement_age == INT_MAX) - retirement_age = params->default_ttl; - ttd = obj->entered + retirement_age; - } + /* + * But even if the clocks are out of whack we can still + * derive a relative time from the two headers. + * (the negative ttl case is caught above) + */ + ttl = (h_expires - h_date); + } while (0); + + if (ttl > 0 && ttd == 0) + ttd = obj->entered + ttl; + /* calculated TTL, Our time, Date, Expires, max-age, age */ - WSP(sp, SLT_TTL, "%u RFC %d %d %d %d %d %d", sp->xid, - (int)(ttd - obj->entered), (int)obj->entered, (int)h_date, - (int)h_expires, (int)u1, (int)u2); + WSP(sp, SLT_TTL, "%u RFC %d %d %d %d %u %u", sp->xid, + ttd ? (int)(ttd - obj->entered) : 0, + (int)obj->entered, (int)h_date, + (int)h_expires, max_age, age); return (ttd); } @@ -194,9 +189,8 @@ } sp->obj->ttl = RFC2616_Ttl(sp, hp, sp->obj); - if (sp->obj->ttl == 0) { + if (sp->obj->ttl == 0) sp->obj->cacheable = 0; - } return (body); } From phk at projects.linpro.no Thu Jul 24 22:20:10 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 25 Jul 2008 00:20:10 +0200 (CEST) Subject: r3020 - trunk/varnish-cache/lib/libvcl Message-ID: <20080724222010.AD78A1EC114@projects.linpro.no> Author: phk Date: 2008-07-25 00:20:10 +0200 (Fri, 25 Jul 2008) New Revision: 3020 Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c Log: Relax an assert to only check what we really care about, and not the principle of the situation. Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_acl.c 2008-07-24 22:12:41 UTC (rev 3019) +++ trunk/varnish-cache/lib/libvcl/vcc_acl.c 2008-07-24 22:20:10 UTC (rev 3020) @@ -203,8 +203,8 @@ for(res = res0; res != NULL; res = res->ai_next) { switch(res->ai_family) { case PF_INET: + assert(PF_INET < 256); sin4 = (void*)res->ai_addr; - assert(sizeof(sin4->sin_family) == 1); assert(sizeof(sin4->sin_addr) == 4); u = (void*)&sin4->sin_addr; if (ae->t_mask == NULL) @@ -213,8 +213,8 @@ vcc_acl_emit_entry(tl, ae, 4, u, res->ai_family); break; case PF_INET6: + assert(PF_INET6 < 256); sin6 = (void*)res->ai_addr; - assert(sizeof(sin6->sin6_family) == 1); assert(sizeof(sin6->sin6_addr) == 16); u = (void*)&sin6->sin6_addr; if (ae->t_mask == NULL) From phk at projects.linpro.no Fri Jul 25 12:02:11 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 25 Jul 2008 14:02:11 +0200 (CEST) Subject: r3021 - in trunk/varnish-cache: . bin/varnishd bin/varnishlog Message-ID: <20080725120211.5578A1EC111@projects.linpro.no> Author: phk Date: 2008-07-25 14:02:11 +0200 (Fri, 25 Jul 2008) New Revision: 3021 Modified: trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/configure.ac Log: Figure out if we need O_LARGEFILE to be compatible with 1990 or later size disks. Submitted by: wichert Fixes ticket 283 Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-24 22:20:10 UTC (rev 3020) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-25 12:02:11 UTC (rev 3021) @@ -194,7 +194,7 @@ " to %ju due to system limitations\n", l); if (l < st.st_size) { - AZ(ftruncate(sc->fd, l)); + AZ(ftruncate(sc->fd, (off_t)l)); } else if (l - st.st_size > fssize) { l = fssize * 80 / 100; fprintf(stderr, "WARNING: storage file size reduced" @@ -228,7 +228,7 @@ { smf_calcsize(sc, size, newfile); - AZ(ftruncate(sc->fd, sc->filesize)); + AZ(ftruncate(sc->fd, (off_t)sc->filesize)); /* XXX: force block allocation here or in open ? */ } @@ -279,7 +279,11 @@ parent->priv = sc; /* try to create a new file of this name */ +#ifdef O_LARGEFILE + sc->fd = open(fn, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, 0600); +#else sc->fd = open(fn, O_RDWR | O_CREAT | O_EXCL, 0600); +#endif if (sc->fd >= 0) { sc->filename = fn; mgt_child_inherit(sc->fd, "storage_file"); Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2008-07-24 22:20:10 UTC (rev 3020) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2008-07-25 12:02:11 UTC (rev 3021) @@ -259,6 +259,9 @@ int fd, flags; flags = (a_flag ? O_APPEND : O_TRUNC) | O_WRONLY | O_CREAT; +#ifdef O_LARGEFILE + flags |= O_LARGEFILE; +#endif if (!strcmp(w_arg, "-")) fd = STDOUT_FILENO; else Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2008-07-24 22:20:10 UTC (rev 3020) +++ trunk/varnish-cache/configure.ac 2008-07-25 12:02:11 UTC (rev 3021) @@ -142,6 +142,7 @@ AC_CHECK_FUNCS([strndup]) AC_CHECK_FUNCS([vis strvis strvisx]) AC_CHECK_FUNCS([daemon]) +AC_SYS_LARGEFILE save_LIBS="${LIBS}" LIBS="${LIBS} ${RT_LIBS}" From phk at projects.linpro.no Fri Jul 25 13:39:02 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 25 Jul 2008 15:39:02 +0200 (CEST) Subject: r3022 - trunk/varnish-cache/bin/varnishd Message-ID: <20080725133902.6BDE91EC112@projects.linpro.no> Author: phk Date: 2008-07-25 15:39:01 +0200 (Fri, 25 Jul 2008) New Revision: 3022 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c Log: polish dot graph a bit. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-25 12:02:11 UTC (rev 3021) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-25 13:39:01 UTC (rev 3022) @@ -504,7 +504,6 @@ return (0); } - INCOMPL(); } @@ -625,16 +624,12 @@ DOT shape=record DOT label="vcl_miss()|req.\nbereq." DOT ] -DOT miss_ins [ -DOT label="obj.pass=true" -DOT ] DOT miss -> vcl_miss [style=bold,color=blue,weight=2] DOT } DOT vcl_miss -> err_miss [label="error"] DOT err_miss [label="ERROR",shape=plaintext] DOT vcl_miss -> fetch [label="fetch",style=bold,color=blue,weight=2] -DOT miss_ins -> pass -DOT vcl_miss -> miss_ins [label="pass"] +DOT vcl_miss -> pass [label="pass"] DOT */ @@ -684,8 +679,12 @@ DOT subgraph xcluster_pass { DOT pass [ DOT shape=ellipse -DOT label="deref obj\nfilter req.->bereq." +DOT label="deref obj." DOT ] +DOT pass2 [ +DOT shape=ellipse +DOT label="filter req.->bereq." +DOT ] DOT vcl_pass [ DOT shape=record DOT label="vcl_pass()|req.\nbereq." @@ -694,7 +693,8 @@ DOT shape=ellipse DOT label="create anon object\n" DOT ] -DOT pass -> vcl_pass +DOT pass -> pass2 +DOT pass2 -> vcl_pass DOT vcl_pass -> pass_do [label="pass"] DOT } DOT pass_do -> fetch @@ -785,7 +785,7 @@ DOT ] DOT } DOT recv -> pipe [label="pipe"] -DOT recv -> pass [label="pass"] +DOT recv -> pass2 [label="pass"] DOT recv -> err_recv [label="error"] DOT err_recv [label="ERROR",shape=plaintext] DOT recv -> hash [label="lookup",style=bold,color=green,weight=4] @@ -839,7 +839,7 @@ * Handle a request, wherever it came from recv/restart. * DOT start [shape=box,label="Dissect request"] -DOT start -> recv +DOT start -> recv [style=bold,color=green,weight=4] */ static int From phk at projects.linpro.no Fri Jul 25 14:52:09 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 25 Jul 2008 16:52:09 +0200 (CEST) Subject: r3023 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080725145209.A46601EC10A@projects.linpro.no> Author: phk Date: 2008-07-25 16:52:08 +0200 (Fri, 25 Jul 2008) New Revision: 3023 Modified: trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc Log: Neuter test b00015 so that automatic scripts don't trip on it all the time. To be reenabled when the code supports the desired functionality. Modified: trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc 2008-07-25 13:39:01 UTC (rev 3022) +++ trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc 2008-07-25 14:52:08 UTC (rev 3023) @@ -13,7 +13,8 @@ txreq -url "/" rxresp expect resp.status == 503 - txreq -url "/" - rxresp - expect resp.status == 503 + # Disable this for now to not upset automatic scripts + #txreq -url "/" + #rxresp + #expect resp.status == 503 } -run From phk at projects.linpro.no Fri Jul 25 14:53:08 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 25 Jul 2008 16:53:08 +0200 (CEST) Subject: r3024 - in trunk/varnish-cache: include lib/libvarnish Message-ID: <20080725145308.60C1B1EC201@projects.linpro.no> Author: phk Date: 2008-07-25 16:53:08 +0200 (Fri, 25 Jul 2008) New Revision: 3024 Modified: trunk/varnish-cache/include/vsb.h trunk/varnish-cache/lib/libvarnish/vsb.c Log: Give VSB's the mini-obj/magic treatment and enable asserts in general. Modified: trunk/varnish-cache/include/vsb.h =================================================================== --- trunk/varnish-cache/include/vsb.h 2008-07-25 14:52:08 UTC (rev 3023) +++ trunk/varnish-cache/include/vsb.h 2008-07-25 14:53:08 UTC (rev 3024) @@ -36,6 +36,7 @@ * Structure definition */ struct vsb { + unsigned s_magic; char *s_buf; /* storage buffer */ void *s_unused; /* binary compatibility. */ int s_size; /* size of storage buffer */ Modified: trunk/varnish-cache/lib/libvarnish/vsb.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vsb.c 2008-07-25 14:52:08 UTC (rev 3023) +++ trunk/varnish-cache/lib/libvarnish/vsb.c 2008-07-25 14:53:08 UTC (rev 3024) @@ -38,13 +38,16 @@ #include #include +#include "libvarnish.h" #include "vsb.h" +#include "miniobj.h" -#define KASSERT(e, m) +#define KASSERT(e, m) assert(e) #define SBMALLOC(size) malloc(size) #define SBFREE(buf) free(buf) #define min(x,y) (x < y ? x : y) +#define VSB_MAGIC 0x4a82dd8a /* * Predicates */ @@ -77,6 +80,8 @@ (void)s; KASSERT(s != NULL, ("%s called with a NULL vsb pointer", fun)); + KASSERT(s->s_magic == VSB_MAGIC, + ("%s called wih an unintialized vsb pointer", fun)); KASSERT(s->s_buf != NULL, ("%s called with uninitialized or corrupt vsb", fun)); KASSERT(s->s_len < s->s_size, @@ -163,10 +168,12 @@ return (NULL); bzero(s, sizeof *s); s->s_flags = flags; + s->s_magic = VSB_MAGIC; VSB_SETFLAG(s, VSB_DYNSTRUCT); } else { bzero(s, sizeof *s); s->s_flags = flags; + s->s_magic = VSB_MAGIC; } s->s_size = length; if (buf) { From phk at projects.linpro.no Fri Jul 25 15:27:04 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 25 Jul 2008 17:27:04 +0200 (CEST) Subject: r3025 - trunk/varnish-cache/bin/varnishd Message-ID: <20080725152704.8349A1EC10A@projects.linpro.no> Author: phk Date: 2008-07-25 17:27:04 +0200 (Fri, 25 Jul 2008) New Revision: 3025 Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache_main.c trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/bin/varnishd/stevedore.h trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/storage_malloc.c Log: Add a stevedore for synthetic pages. The storage from this stevedore is backed by an autoextending vsb, which can be used to generate synthetic pages into. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-25 14:53:08 UTC (rev 3024) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-25 15:27:04 UTC (rev 3025) @@ -51,6 +51,7 @@ stevedore.c \ storage_file.c \ storage_malloc.c \ + storage_synth.c \ tcp.c \ varnishd.c Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2008-07-25 14:53:08 UTC (rev 3024) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2008-07-25 15:27:04 UTC (rev 3025) @@ -121,6 +121,7 @@ VCA_Init(); + SMS_Init(); STV_open(); VSL_stats->start_time = (time_t)TIM_real(); Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2008-07-25 14:53:08 UTC (rev 3024) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2008-07-25 15:27:04 UTC (rev 3025) @@ -83,7 +83,7 @@ } void -STV_free(const struct storage *st) +STV_free(struct storage *st) { CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2008-07-25 14:53:08 UTC (rev 3024) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2008-07-25 15:27:04 UTC (rev 3025) @@ -39,7 +39,7 @@ typedef void storage_open_f(const struct stevedore *); typedef struct storage *storage_alloc_f(struct stevedore *, size_t size); typedef void storage_trim_f(const struct storage *, size_t size); -typedef void storage_free_f(const struct storage *); +typedef void storage_free_f(struct storage *); struct stevedore { unsigned magic; @@ -59,6 +59,9 @@ struct storage *STV_alloc(struct sess *sp, size_t size); void STV_trim(const struct storage *st, size_t size); -void STV_free(const struct storage *st); +void STV_free(struct storage *st); void STV_add(const struct stevedore *stv, int ac, char * const *av); void STV_open(void); + +/* Synthetic Storage */ +void SMS_Init(void); Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-25 14:53:08 UTC (rev 3024) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-25 15:27:04 UTC (rev 3025) @@ -681,7 +681,7 @@ /*--------------------------------------------------------------------*/ static void -smf_free(const struct storage *s) +smf_free(struct storage *s) { struct smf *smf; struct smf_sc *sc; Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2008-07-25 14:53:08 UTC (rev 3024) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2008-07-25 15:27:04 UTC (rev 3025) @@ -86,7 +86,7 @@ } static void -sma_free(const struct storage *s) +sma_free(struct storage *s) { struct sma *sma; From phk at projects.linpro.no Fri Jul 25 16:33:05 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 25 Jul 2008 18:33:05 +0200 (CEST) Subject: r3026 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20080725163305.3A1391ED180@projects.linpro.no> Author: phk Date: 2008-07-25 18:33:04 +0200 (Fri, 25 Jul 2008) New Revision: 3026 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/stat_field.h trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_token.c Log: Add a facility to constructing a synthetic object from VCL. This is just the initial version and it doesn't quite work the way we need it to yet, but the idea is to be able to say: sub vcl_fetch { if (obj.status == 503) { synthetic {"

Sorry, could not contact the backend server

Try again later.


			URL: "}  req.url {"
			User Agnet: "} req.http.user-agent {"
		    
"}; } } A new VCL syntactic element have been introduced to do this: "the long string". A long string is anything from {" to "}, newlines, controlcharacters and all. (Normal "..." strings cannot contain control characters. Technical details: Don't NULL terminate string sequences in VRT context, we may have NULL cropping up as a legal value if a header is missing, add the magic "vrt_magic_string_end" for terminating string contactenation. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-25 15:27:04 UTC (rev 3025) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-25 16:33:04 UTC (rev 3026) @@ -461,6 +461,7 @@ /* cache_hash.c */ void HSH_Prealloc(struct sess *sp); +void HSH_Freestore(struct object *o); int HSH_Compare(const struct sess *sp, const struct objhead *o); void HSH_Copy(const struct sess *sp, const struct objhead *o); struct object *HSH_Lookup(struct sess *sp); @@ -612,6 +613,10 @@ /* rfc2616.c */ int RFC2616_cache_policy(const struct sess *sp, const struct http *hp); +/* storage_synth.c */ +struct vsb *SMS_Makesynth(struct object *obj); +void SMS_Finish(struct object *obj); + #define MTX pthread_mutex_t #define MTX_INIT(foo) AZ(pthread_mutex_init(foo, NULL)) #define MTX_DESTROY(foo) AZ(pthread_mutex_destroy(foo)) Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2008-07-25 15:27:04 UTC (rev 3025) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2008-07-25 16:33:04 UTC (rev 3026) @@ -116,7 +116,7 @@ CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC); } -static void +void HSH_Freestore(struct object *o) { struct storage *st, *stn; Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-25 15:27:04 UTC (rev 3025) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-25 16:33:04 UTC (rev 3026) @@ -51,6 +51,9 @@ #include "vcl.h" #include "cache.h" + +void *vrt_magic_string_end = &vrt_magic_string_end; + /*--------------------------------------------------------------------*/ void @@ -136,7 +139,9 @@ if (b + 1 < e) *b++ = ' '; } - while (p != NULL) { + while (p != vrt_magic_string_end) { + if (p == NULL) + p = "(null)"; x = strlen(p); if (b + x < e) memcpy(b, p, x); @@ -644,7 +649,39 @@ /*--------------------------------------------------------------------*/ +/*lint -e{818} sp could be const */ void +VRT_synth_page(struct sess *sp, unsigned flags, const char *str, ...) +{ + va_list ap; + const char *p; + struct vsb *vsb; + + (void)flags; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + vsb = SMS_Makesynth(sp->obj); + AN(vsb); + + vsb_cat(vsb, str); + va_start(ap, str); + p = va_arg(ap, const char *); + while (p != vrt_magic_string_end) { + if (p == NULL) + p = "(null)"; + vsb_cat(vsb, p); + p = va_arg(ap, const char *); + } + va_end(ap); + SMS_Finish(sp->obj); + http_Unset(sp->obj->http, H_Content_Length); + http_PrintfHeader(sp->wrk, sp->fd, sp->obj->http, + "Content-Length: %d", sp->obj->len); +} + +/*--------------------------------------------------------------------*/ + +void VRT_purge(const char *regexp, int hash) { Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2008-07-25 15:27:04 UTC (rev 3025) +++ trunk/varnish-cache/include/stat_field.h 2008-07-25 16:33:04 UTC (rev 3026) @@ -105,6 +105,12 @@ MAC_STAT(sma_balloc, uint64_t, 'i', "SMA bytes allocated") MAC_STAT(sma_bfree, uint64_t, 'i', "SMA bytes free") +MAC_STAT(sms_nreq, uint64_t, 'a', "SMS allocator requests") +MAC_STAT(sms_nobj, uint64_t, 'i', "SMS outstanding allocations") +MAC_STAT(sms_nbytes, uint64_t, 'i', "SMS outstanding bytes") +MAC_STAT(sms_balloc, uint64_t, 'i', "SMS bytes allocated") +MAC_STAT(sms_bfree, uint64_t, 'i', "SMS bytes free") + MAC_STAT(backend_req, uint64_t, 'a', "Backend requests made") MAC_STAT(n_vcl, uint64_t, 'a', "N vcl total") Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2008-07-25 15:27:04 UTC (rev 3025) +++ trunk/varnish-cache/include/vrt.h 2008-07-25 16:33:04 UTC (rev 3026) @@ -45,6 +45,8 @@ * A backend probe specification */ +extern void *vrt_magic_string_end; + struct vrt_backend_probe { char *request; double timeout; @@ -151,6 +153,9 @@ void VRT_ESI(struct sess *sp); void VRT_Rollback(struct sess *sp); +/* Synthetic pages */ +void VRT_synth_page(struct sess *sp, unsigned flags, const char *, ...); + /* Backend related */ void VRT_init_dir_simple(struct cli *, struct director **, const struct vrt_dir_simple *); void VRT_init_dir_random(struct cli *, struct director **, const struct vrt_dir_random *); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-25 15:27:04 UTC (rev 3025) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-25 16:33:04 UTC (rev 3026) @@ -269,7 +269,7 @@ vcc_ErrWhere(tl, tl->t); return; } - Fb(tl, 0, "0);\n"); + Fb(tl, 0, "vrt_magic_string_end);\n"); break; default: vsb_printf(tl->sb, @@ -372,11 +372,29 @@ do Fb(tl, 0, ", "); while (vcc_StringVal(tl)); - Fb(tl, 0, " 0);\n"); + Fb(tl, 0, " vrt_magic_string_end);\n"); } /*--------------------------------------------------------------------*/ +static void +parse_synthetic(struct tokenlist *tl) +{ + vcc_NextToken(tl); + + Fb(tl, 1, "VRT_synth_page(sp, 0, "); + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return; + } + do + Fb(tl, 0, ", "); + while (vcc_StringVal(tl)); + Fb(tl, 0, " vrt_magic_string_end);\n"); +} + +/*--------------------------------------------------------------------*/ + typedef void action_f(struct tokenlist *tl); static struct action_table { @@ -398,6 +416,7 @@ { "purge_url", parse_purge_url }, { "remove", parse_unset }, /* backward compatibility */ { "set", parse_set }, + { "synthetic", parse_synthetic }, { "unset", parse_unset }, { NULL, NULL } }; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-25 15:27:04 UTC (rev 3025) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-25 16:33:04 UTC (rev 3026) @@ -326,6 +326,8 @@ vsb_cat(sb, " * A backend probe specification\n"); vsb_cat(sb, " */\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "extern void *vrt_magic_string_end;\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, "struct vrt_backend_probe {\n"); vsb_cat(sb, " char *request;\n"); vsb_cat(sb, " double timeout;\n"); @@ -432,6 +434,9 @@ vsb_cat(sb, "void VRT_ESI(struct sess *sp);\n"); vsb_cat(sb, "void VRT_Rollback(struct sess *sp);\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "/* Synthetic pages */\n"); + vsb_cat(sb, "void VRT_synth_page(struct sess *sp, unsigned flags, const char *, ...);\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, "/* Backend related */\n"); vsb_cat(sb, "void VRT_init_dir_simple(struct cli *, struct director **, const struct vrt_dir_simple *);\n"); vsb_cat(sb, "void VRT_init_dir_random(struct cli *, struct director **, const struct vrt_dir_random *);\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token.c 2008-07-25 15:27:04 UTC (rev 3025) +++ trunk/varnish-cache/lib/libvcl/vcc_token.c 2008-07-25 16:33:04 UTC (rev 3026) @@ -371,6 +371,29 @@ return; } + /* Recognize long-strings */ + if (*p == '{' && p[1] == '"') { + for (q = p + 2; q < sp->e; q++) { + if (*q == '"' && q[1] == '}') { + vcc_AddToken(tl, CSTR, p, q + 2); + p = q + 2; + break; + } + } + u = tl->t->e - tl->t->b; + u -= 4; /* {" ... "} */ + tl->t->dec = TlAlloc(tl, u + 1 ); + AN(tl->t->dec); + memcpy(tl->t->dec, tl->t->b + 2, u); + tl->t->dec[u] = '\0'; + if (q < sp->e) + continue; + vcc_AddToken(tl, EOI, p, p + 2); + vsb_printf(tl->sb, + "Unterminated long-string, starting at\n"); + vcc_ErrWhere(tl, tl->t); + return; + } /* Match for the fixed tokens (see token.tcl) */ u = vcl_fixed_token(p, &q); From phk at projects.linpro.no Fri Jul 25 18:20:36 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 25 Jul 2008 20:20:36 +0200 (CEST) Subject: r3027 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl Message-ID: <20080725182036.772C91EC111@projects.linpro.no> Author: phk Date: 2008-07-25 20:20:35 +0200 (Fri, 25 Jul 2008) New Revision: 3027 Removed: trunk/varnish-cache/bin/varnishd/cache_synthetic.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishtest/tests/v00001.vtc trunk/varnish-cache/include/vcl.h trunk/varnish-cache/include/vcl_returns.h trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: NB: Be careful with -trunk, this is a quite intrusive change. Continue the progress on synthetic/error pages The default "guru meditation" is now generated from the vcl_error {} function, which can be redefined to whatever suits your taste. Techinical: Add new vcl_error method and make variables available in it. Fix a bug in "error" action, where the numeric argument would not get interpreted correctly if it came from a variable like obj.status. Forbid "error" action in vcl_deliver since vcl_error now goes to vcl_deliver to send the error object. Fix test v00001 to reflect this. Move the obj->ws/http initialization to preallocation time to avoid duplication. Add read-only variable req.xid (a string!) Add default guru meditation to default vcl. Remove cache_synthetic.c which is now unecessary. Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-25 18:20:35 UTC (rev 3027) @@ -31,7 +31,6 @@ cache_pipe.c \ cache_response.c \ cache_session.c \ - cache_synthetic.c \ cache_vary.c \ cache_vcl.c \ cache_vrt.c \ Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-25 18:20:35 UTC (rev 3027) @@ -306,12 +306,40 @@ static int cnt_error(struct sess *sp) { + struct worker *w; + struct http *h; + time_t now; + char date[40]; - AZ(sp->obj); - SYN_ErrorPage(sp, sp->err_code, sp->err_reason); + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + w = sp->wrk; + if (sp->obj == NULL) { + HSH_Prealloc(sp); + sp->obj = sp->wrk->nobj; + sp->wrk->nobj = NULL; + } else { + /* XXX: Null the headers ? */ + } + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + h = sp->obj->http; + + http_PutProtocol(w, sp->fd, h, "HTTP/1.1"); + http_PutStatus(w, sp->fd, h, sp->err_code); + now = TIM_real(); + TIM_format(now, date); + http_PrintfHeader(w, sp->fd, h, "Date: %s", date); + http_PrintfHeader(w, sp->fd, h, "Server: Varnish"); + http_PrintfHeader(w, sp->fd, h, "Retry-After: %d", params->err_ttl); + + if (sp->err_reason != NULL) + http_PutResponse(w, sp->fd, h, sp->err_reason); + else + http_PutResponse(w, sp->fd, h, + http_StatusMessage(sp->err_code)); + VCL_error_method(sp); sp->err_code = 0; sp->err_reason = NULL; - sp->step = STP_DONE; + sp->step = STP_DELIVER; return (0); } @@ -877,8 +905,8 @@ *sp->http0 = *sp->http; if (done != 0) { - SYN_ErrorPage(sp, done, NULL); /* XXX: STP_ERROR ? */ - sp->step = STP_DONE; + sp->err_code = done; + sp->step = STP_ERROR; return (0); } Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2008-07-25 18:20:35 UTC (rev 3027) @@ -331,11 +331,7 @@ sp->obj->xid = sp->xid; /* Set up obj's workspace */ - st = sp->obj->objstore; - WS_Init(sp->obj->ws_o, "obj", st->ptr + st->len, st->space - st->len); - st->len = st->space; WS_Assert(sp->obj->ws_o); - http_Setup(sp->obj->http, sp->obj->ws_o); vc = VBE_GetFd(sp); if (vc == NULL) return (__LINE__); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2008-07-25 18:20:35 UTC (rev 3027) @@ -104,6 +104,11 @@ st->len = sizeof *w->nobj; memset(w->nobj, 0, sizeof *w->nobj); w->nobj->objstore = st; + WS_Init(w->nobj->ws_o, "obj", + st->ptr + st->len, st->space - st->len); + st->len = st->space; + WS_Assert(w->nobj->ws_o); + http_Setup(w->nobj->http, w->nobj->ws_o); w->nobj->magic = OBJECT_MAGIC; w->nobj->http->magic = HTTP_MAGIC; w->nobj->busy = 1; @@ -112,6 +117,7 @@ VTAILQ_INIT(&w->nobj->store); VTAILQ_INIT(&w->nobj->esibits); VSL_stats->n_object++; + } else CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC); } Deleted: trunk/varnish-cache/bin/varnishd/cache_synthetic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/bin/varnishd/cache_synthetic.c 2008-07-25 18:20:35 UTC (rev 3027) @@ -1,126 +0,0 @@ -/*- - * Copyright (c) 2007-2008 Linpro AS - * All rights reserved. - * - * Author: Dag-Erling Sm?rgrav - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - */ - -#include "config.h" - -#include -#include - -#include - -#include "shmlog.h" -#include "cache.h" -#include "stevedore.h" - -/* - * Synthesize an error page including headers. - * XXX: For now close the connection. Long term that should probably - * XXX: be either a paramter or VCL decision. - * XXX: VCL should get a shot at generating the page. - */ - -void -SYN_ErrorPage(struct sess *sp, int status, const char *reason) -{ - struct http *h; - struct worker *w; - const char *msg; - char date[40]; - double now; - unsigned u; - struct vsb vsb; - int fd; - - WSL_Flush(sp->wrk, 0); - assert(status >= 100 && status <= 999); - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); - - /* shortcuts */ - w = sp->wrk; - h = sp->http; - fd = sp->fd; - now = TIM_real(); /* XXX: use cached val ? */ - - WRK_Reset(w, &sp->fd); - - /* look up HTTP response */ - msg = http_StatusMessage(status); - AN(msg); - if (reason == NULL) - reason = msg; - - /* generate header */ - http_ClrHeader(h); - h->logtag = HTTP_Tx; - http_PutProtocol(w, fd, h, "HTTP/1.0"); /* XXX */ - http_PutStatus(w, fd, h, status); - http_PutResponse(w, fd, h, msg); - TIM_format(now, date); - http_PrintfHeader(w, fd, h, "Date: %s", date); - http_PrintfHeader(w, fd, h, "Server: Varnish"); - http_PrintfHeader(w, fd, h, "Retry-After: %d", params->err_ttl); - http_PrintfHeader(w, fd, h, "Content-Type: text/html; charset=utf-8"); - http_PrintfHeader(w, sp->fd, sp->http, "X-Varnish: %u", sp->xid); - http_PrintfHeader(w, fd, h, "Connection: close"); - - w->acct.hdrbytes += http_Write(w, h, 1); - - /* generate body */ - /* XXX: VCL should do this */ - u = WS_Reserve(h->ws, 0); - AN(vsb_new(&vsb, h->ws->f, u, VSB_FIXEDLEN)); - vsb_printf(&vsb, - "\n" - "\n" - "\n" - " \n" - " %03d %s\n", status, msg); - vsb_printf(&vsb, - " \n" - " \n" - "

Error %03d %s

\n", status, msg); - vsb_printf(&vsb, - "

%s

\n", reason); - vsb_printf(&vsb, - "

Guru Meditation:

\n" - "

XID: %u

\n", sp->xid); - vsb_printf(&vsb, - "
Varnish
\n" - " \n" - "\n"); - vsb_finish(&vsb); - AZ(vsb_overflowed(&vsb)); - w->acct.hdrbytes = WRK_Write(w, vsb_data(&vsb), vsb_len(&vsb)); - (void)WRK_Flush(w); - vsb_delete(&vsb); - vca_close_session(sp, "error returned"); -} Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-25 18:20:35 UTC (rev 3027) @@ -467,6 +467,24 @@ return (sp->grace); } +/*-------------------------------------------------------------------- + * req.xid + */ + +/*lint -e{818} sp could be const */ +const char * +VRT_r_req_xid(struct sess *sp) +{ + char *p; + int size; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + + size = snprintf(NULL, 0, "%u", sp->xid) + 1; + AN(p = WS_Alloc(sp->http->ws, size)); + assert(snprintf(p, size, "%d", sp->xid) < size); + return (p); +} + /*--------------------------------------------------------------------*/ struct sockaddr * Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-07-25 18:20:35 UTC (rev 3027) @@ -158,7 +158,29 @@ "}\n" "sub vcl_timeout {\n" " discard;\n" - "}\n"; + "}\n" + "sub vcl_error {\n" + " set obj.http.Content-Type = \"text/html; charset=utf-8\";" + " synthetic {\"\n" + "\n" + "\n" + "\n" + " \n" + " \"} obj.status \" \" obj.response {\"\n" + " \n" + " \n" + "

Error \"} obj.status \" \" obj.response {\"

\n" + "

\"} obj.response {\"

\n" + "

Guru Meditation:

\n" + "

XID: \"} req.xid {\"

\n" + "
Varnish
\n" + " \n" + "\n" + "\"};\n" + " deliver;\n" + "}\n" + "" ; /* * Prepare the compiler command line Modified: trunk/varnish-cache/bin/varnishtest/tests/v00001.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00001.vtc 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/bin/varnishtest/tests/v00001.vtc 2008-07-25 18:20:35 UTC (rev 3027) @@ -38,11 +38,10 @@ sub vcl_deliver { set resp.proto = "HTTP/1.2"; set resp.response = "Naah, lets fail it"; - set resp.status = 903; + set resp.status = 904; set resp.http.foobar = resp.proto resp.status; - error 904 "because I say so:"; } } -start Modified: trunk/varnish-cache/include/vcl.h =================================================================== --- trunk/varnish-cache/include/vcl.h 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/include/vcl.h 2008-07-25 18:20:35 UTC (rev 3027) @@ -46,4 +46,5 @@ vcl_func_f *prefetch_func; vcl_func_f *timeout_func; vcl_func_f *discard_func; + vcl_func_f *error_func; }; Modified: trunk/varnish-cache/include/vcl_returns.h =================================================================== --- trunk/varnish-cache/include/vcl_returns.h 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/include/vcl_returns.h 2008-07-25 18:20:35 UTC (rev 3027) @@ -43,10 +43,11 @@ VCL_MET_MAC(miss,MISS,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_FETCH)) VCL_MET_MAC(hit,HIT,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_DELIVER)) VCL_MET_MAC(fetch,FETCH,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_INSERT)) -VCL_MET_MAC(deliver,DELIVER,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_DELIVER)) +VCL_MET_MAC(deliver,DELIVER,(VCL_RET_RESTART|VCL_RET_DELIVER)) VCL_MET_MAC(prefetch,PREFETCH,(VCL_RET_FETCH|VCL_RET_PASS)) VCL_MET_MAC(timeout,TIMEOUT,(VCL_RET_FETCH|VCL_RET_DISCARD)) VCL_MET_MAC(discard,DISCARD,(VCL_RET_DISCARD|VCL_RET_KEEP)) +VCL_MET_MAC(error,ERROR,(VCL_RET_DELIVER)) #else #define VCL_MET_RECV (1 << 0) #define VCL_MET_PIPE (1 << 1) @@ -59,5 +60,6 @@ #define VCL_MET_PREFETCH (1 << 8) #define VCL_MET_TIMEOUT (1 << 9) #define VCL_MET_DISCARD (1 << 10) +#define VCL_MET_ERROR (1 << 11) #endif -#define N_METHODS 11 +#define N_METHODS 12 Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/include/vrt_obj.h 2008-07-25 18:20:35 UTC (rev 3027) @@ -21,6 +21,7 @@ int VRT_r_req_restarts(const struct sess *); double VRT_r_req_grace(struct sess *); void VRT_l_req_grace(struct sess *, double); +const char * VRT_r_req_xid(struct sess *); const char * VRT_r_bereq_request(const struct sess *); void VRT_l_bereq_request(const struct sess *, const char *, ...); const char * VRT_r_bereq_url(const struct sess *); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-25 18:20:35 UTC (rev 3027) @@ -94,15 +94,22 @@ static void parse_error(struct tokenlist *tl) { - unsigned a; + struct var *vp; vcc_NextToken(tl); - if (tl->t->tok == CNUM) { - a = vcc_UintVal(tl); + if (tl->t->tok == VAR) { + vp = vcc_FindVar(tl, tl->t, vcc_vars); + if (vp->fmt == INT) { + Fb(tl, 1, "VRT_error(sp, %s", vp->rname); + vcc_NextToken(tl); + } else { + Fb(tl, 1, "VRT_error(sp, 0"); + } + } else if (tl->t->tok == CNUM) { + Fb(tl, 1, "VRT_error(sp, %u", vcc_UintVal(tl)); vcc_NextToken(tl); } else - a = 0; - Fb(tl, 1, "VRT_error(sp, %u", a); + Fb(tl, 1, "VRT_error(sp, 0"); if (tl->t->tok == CSTR) { Fb(tl, 0, ", %.*s", PF(tl->t)); vcc_NextToken(tl); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-25 18:20:35 UTC (rev 3027) @@ -278,6 +278,7 @@ vsb_cat(sb, " vcl_func_f *prefetch_func;\n"); vsb_cat(sb, " vcl_func_f *timeout_func;\n"); vsb_cat(sb, " vcl_func_f *discard_func;\n"); + vsb_cat(sb, " vcl_func_f *error_func;\n"); vsb_cat(sb, "};\n"); vsb_cat(sb, "/*-\n"); vsb_cat(sb, " * Copyright (c) 2006 Verdens Gang AS\n"); @@ -475,6 +476,7 @@ vsb_cat(sb, "int VRT_r_req_restarts(const struct sess *);\n"); vsb_cat(sb, "double VRT_r_req_grace(struct sess *);\n"); vsb_cat(sb, "void VRT_l_req_grace(struct sess *, double);\n"); + vsb_cat(sb, "const char * VRT_r_req_xid(struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_bereq_request(const struct sess *);\n"); vsb_cat(sb, "void VRT_l_bereq_request(const struct sess *, const char *, ...);\n"); vsb_cat(sb, "const char * VRT_r_bereq_url(const struct sess *);\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2008-07-25 18:20:35 UTC (rev 3027) @@ -41,10 +41,11 @@ {miss {error restart pass fetch}} {hit {error restart pass deliver}} {fetch {error restart pass insert}} - {deliver {error restart deliver}} + {deliver {restart deliver}} {prefetch {fetch pass}} {timeout {fetch discard}} {discard {discard keep}} + {error {deliver}} } # These are the return actions Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2008-07-25 18:20:35 UTC (rev 3027) @@ -1,4 +1,4 @@ -#!/usr/bin/tclsh8.4 +#!/usr/local/bin/tclsh8.4 #- # Copyright (c) 2006 Verdens Gang AS # Copyright (c) 2006-2008 Linpro AS @@ -35,186 +35,192 @@ # Comments are stripped from #...\n set spobj { - # Connection related parameters - { client.ip - RO IP - {recv pipe pass hash miss hit fetch deliver } - "const struct sess *" - } - { client.bandwidth # Not implemented yet - NO - { } - "const struct sess *" - } - { server.ip - RO IP - {recv pipe pass hash miss hit fetch deliver } - "struct sess *" - } - { server.port - RO INT - {recv pipe pass hash miss hit fetch deliver } - "struct sess *" - } - # Request paramters - { req.request - RW STRING - {recv pipe pass hash miss hit fetch } - "const struct sess *" - } - { req.url - RW STRING - {recv pipe pass hash miss hit fetch } - "const struct sess *" - } - { req.proto - RW STRING - {recv pipe pass hash miss hit fetch } - "const struct sess *" - } - { req.http. - RW HDR_REQ - {recv pipe pass hash miss hit fetch } - "const struct sess *" - } + # Connection related parameters + { client.ip + RO IP + {recv pipe pass hash miss hit fetch deliver error } + "const struct sess *" + } + { client.bandwidth # Not implemented yet + NO + { } + "const struct sess *" + } + { server.ip + RO IP + {recv pipe pass hash miss hit fetch deliver error } + "struct sess *" + } + { server.port + RO INT + {recv pipe pass hash miss hit fetch deliver error } + "struct sess *" + } + # Request paramters + { req.request + RW STRING + {recv pipe pass hash miss hit fetch error } + "const struct sess *" + } + { req.url + RW STRING + {recv pipe pass hash miss hit fetch error } + "const struct sess *" + } + { req.proto + RW STRING + {recv pipe pass hash miss hit fetch error } + "const struct sess *" + } + { req.http. + RW HDR_REQ + {recv pipe pass hash miss hit fetch error } + "const struct sess *" + } - # Possibly misnamed, not really part of the request - { req.hash - WO HASH - { hash } - "struct sess *" - } - { req.backend - RW BACKEND - {recv pipe pass hash miss hit fetch } - "struct sess *" - } - { req.restarts - RO INT - {recv pipe pass hash miss hit fetch deliver } - "const struct sess *" - } - { req.grace - RW TIME - {recv pipe pass hash miss hit fetch deliver } - "struct sess *" - } + # Possibly misnamed, not really part of the request + { req.hash + WO HASH + { hash error } + "struct sess *" + } + { req.backend + RW BACKEND + {recv pipe pass hash miss hit fetch error } + "struct sess *" + } + { req.restarts + RO INT + {recv pipe pass hash miss hit fetch deliver error } + "const struct sess *" + } + { req.grace + RW TIME + {recv pipe pass hash miss hit fetch deliver error } + "struct sess *" + } - # Request sent to backend - { bereq.request - RW STRING - { pipe pass miss fetch } - "const struct sess *" - } - { bereq.url - RW STRING - { pipe pass miss fetch } - "const struct sess *" - } - { bereq.proto - RW STRING - { pipe pass miss fetch } - "const struct sess *" - } - { bereq.http. - RW HDR_BEREQ - { pipe pass miss fetch } - "const struct sess *" - } + { req.xid + RO STRING + {recv pipe pass hash miss hit fetch deliver error} + "struct sess *" + } - # The (possibly) cached object - { obj.proto - RW STRING - { hit fetch } - "const struct sess *" - } - { obj.status - RW INT - { fetch } - "const struct sess *" - } - { obj.response - RW STRING - { fetch } - "const struct sess *" - } - { obj.http. - RW HDR_OBJ - { hit fetch } - "const struct sess *" - } + # Request sent to backend + { bereq.request + RW STRING + { pipe pass miss fetch } + "const struct sess *" + } + { bereq.url + RW STRING + { pipe pass miss fetch } + "const struct sess *" + } + { bereq.proto + RW STRING + { pipe pass miss fetch } + "const struct sess *" + } + { bereq.http. + RW HDR_BEREQ + { pipe pass miss fetch } + "const struct sess *" + } - { obj.valid - RW BOOL - { hit fetch discard timeout} - "const struct sess *" - } - { obj.cacheable - RW BOOL - { hit fetch discard timeout} - "const struct sess *" - } - { obj.ttl - RW TIME - { hit fetch discard timeout} - "const struct sess *" - } - { obj.grace - RW TIME - { hit fetch discard timeout} - "const struct sess *" - } - { obj.prefetch - RW RTIME - { fetch prefetch } - "const struct sess *" - } - { obj.lastuse - RO TIME - { hit fetch deliver discard timeout} - "const struct sess *" - } - { obj.hash - RO STRING - { miss hit fetch deliver } - "const struct sess *" - } + # The (possibly) cached object + { obj.proto + RW STRING + { hit fetch error} + "const struct sess *" + } + { obj.status + RW INT + { fetch error} + "const struct sess *" + } + { obj.response + RW STRING + { fetch error} + "const struct sess *" + } + { obj.http. + RW HDR_OBJ + { hit fetch error} + "const struct sess *" + } - # The response we send back - { resp.proto - RW STRING - { deliver } - "const struct sess *" - } - { resp.status - RW INT - { deliver } - "const struct sess *" - } - { resp.response - RW STRING - { deliver } - "const struct sess *" - } - { resp.http. - RW HDR_RESP - { deliver } - "const struct sess *" - } + { obj.valid + RW BOOL + { hit fetch discard timeout error} + "const struct sess *" + } + { obj.cacheable + RW BOOL + { hit fetch discard timeout error} + "const struct sess *" + } + { obj.ttl + RW TIME + { hit fetch discard timeout error} + "const struct sess *" + } + { obj.grace + RW TIME + { hit fetch discard timeout error} + "const struct sess *" + } + { obj.prefetch + RW RTIME + { fetch prefetch } + "const struct sess *" + } + { obj.lastuse + RO TIME + { hit fetch deliver discard timeout error} + "const struct sess *" + } + { obj.hash + RO STRING + { miss hit fetch deliver error} + "const struct sess *" + } - # Miscellaneous - # XXX: I'm not happy about this one. All times should be relative - # XXX: or delta times in VCL programs, so this shouldn't be needed /phk - { now - RO TIME - {recv pipe pass hash miss hit fetch deliver discard timeout} - "const struct sess *" - } - { backend.health RO INT - {recv pipe pass hash miss hit fetch deliver discard timeout} - "const struct sess *" - } + # The response we send back + { resp.proto + RW STRING + { deliver } + "const struct sess *" + } + { resp.status + RW INT + { deliver } + "const struct sess *" + } + { resp.response + RW STRING + { deliver } + "const struct sess *" + } + { resp.http. + RW HDR_RESP + { deliver } + "const struct sess *" + } + # Miscellaneous + # XXX: I'm not happy about this one. All times should be relative + # XXX: or delta times in VCL programs, so this shouldn't be needed /phk + { now + RO TIME + {recv pipe pass hash miss hit fetch deliver discard timeout} + "const struct sess *" + } + { backend.health RO INT + {recv pipe pass hash miss hit fetch deliver discard timeout} + "const struct sess *" + } + } set tt(IP) "struct sockaddr *" Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2008-07-25 16:33:04 UTC (rev 3026) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2008-07-25 18:20:35 UTC (rev 3027) @@ -16,78 +16,85 @@ NULL, V_RO, 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR }, { "server.ip", IP, 9, "VRT_r_server_ip(sp)", NULL, V_RO, 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR }, { "server.port", INT, 11, "VRT_r_server_port(sp)", NULL, V_RO, 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR }, { "req.request", STRING, 11, "VRT_r_req_request(sp)", "VRT_l_req_request(sp, ", V_RW, 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_ERROR }, { "req.url", STRING, 7, "VRT_r_req_url(sp)", "VRT_l_req_url(sp, ", V_RW, 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_ERROR }, { "req.proto", STRING, 9, "VRT_r_req_proto(sp)", "VRT_l_req_proto(sp, ", V_RW, 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_ERROR }, { "req.http.", HEADER, 9, "VRT_r_req_http_(sp)", "VRT_l_req_http_(sp, ", V_RW, "HDR_REQ", - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_ERROR }, { "req.hash", HASH, 8, NULL, "VRT_l_req_hash(sp, ", V_WO, 0, - VCL_MET_HASH + VCL_MET_HASH | VCL_MET_ERROR }, { "req.backend", BACKEND, 11, "VRT_r_req_backend(sp)", "VRT_l_req_backend(sp, ", V_RW, 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_ERROR }, { "req.restarts", INT, 12, "VRT_r_req_restarts(sp)", NULL, V_RO, 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR }, { "req.grace", TIME, 9, "VRT_r_req_grace(sp)", "VRT_l_req_grace(sp, ", V_RW, 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR }, + { "req.xid", STRING, 7, + "VRT_r_req_xid(sp)", + NULL, + V_RO, + 0, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR + }, { "bereq.request", STRING, 13, "VRT_r_bereq_request(sp)", "VRT_l_bereq_request(sp, ", @@ -121,56 +128,56 @@ "VRT_l_obj_proto(sp, ", V_RW, 0, - VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_ERROR }, { "obj.status", INT, 10, "VRT_r_obj_status(sp)", "VRT_l_obj_status(sp, ", V_RW, 0, - VCL_MET_FETCH + VCL_MET_FETCH | VCL_MET_ERROR }, { "obj.response", STRING, 12, "VRT_r_obj_response(sp)", "VRT_l_obj_response(sp, ", V_RW, 0, - VCL_MET_FETCH + VCL_MET_FETCH | VCL_MET_ERROR }, { "obj.http.", HEADER, 9, "VRT_r_obj_http_(sp)", "VRT_l_obj_http_(sp, ", V_RW, "HDR_OBJ", - VCL_MET_HIT | VCL_MET_FETCH + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_ERROR }, { "obj.valid", BOOL, 9, "VRT_r_obj_valid(sp)", "VRT_l_obj_valid(sp, ", V_RW, 0, - VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT | VCL_MET_ERROR }, { "obj.cacheable", BOOL, 13, "VRT_r_obj_cacheable(sp)", "VRT_l_obj_cacheable(sp, ", V_RW, 0, - VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT | VCL_MET_ERROR }, { "obj.ttl", TIME, 7, "VRT_r_obj_ttl(sp)", "VRT_l_obj_ttl(sp, ", V_RW, 0, - VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT | VCL_MET_ERROR }, { "obj.grace", TIME, 9, "VRT_r_obj_grace(sp)", "VRT_l_obj_grace(sp, ", V_RW, 0, - VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT | VCL_MET_ERROR }, { "obj.prefetch", RTIME, 12, "VRT_r_obj_prefetch(sp)", @@ -184,14 +191,14 @@ NULL, V_RO, 0, - VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT + VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT | VCL_MET_ERROR }, { "obj.hash", STRING, 8, "VRT_r_obj_hash(sp)", NULL, V_RO, 0, - VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR }, { "resp.proto", STRING, 10, "VRT_r_resp_proto(sp)", From phk at projects.linpro.no Fri Jul 25 19:23:35 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 25 Jul 2008 21:23:35 +0200 (CEST) Subject: r3028 - trunk/varnish-cache/bin/varnishd Message-ID: <20080725192335.9A42A1EC111@projects.linpro.no> Author: phk Date: 2008-07-25 21:23:35 +0200 (Fri, 25 Jul 2008) New Revision: 3028 Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Change param thread_pool_min to be the minimum number of threads per pool, and don't be so stingy with them: default to five. Make sure we really do create the minimum complement of threads. Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2008-07-25 18:20:35 UTC (rev 3027) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2008-07-25 19:23:35 UTC (rev 3028) @@ -91,7 +91,6 @@ static unsigned nwq; static unsigned ovfl_max; static unsigned nthr_max; -static unsigned nthr_min; static pthread_cond_t herder_cond; static MTX herder_mtx; @@ -401,7 +400,7 @@ { struct worker *w; - if (qp->nthr <= nthr_min) + if (qp->nthr <= params->wthread_min) return; LOCK(&qp->mtx); @@ -454,14 +453,10 @@ wrk_addpools(u); /* Scale parameters */ - u = params->wthread_min / nwq; - if (u < 1) - u = 1; - nthr_min = u; u = params->wthread_max / nwq; - if (u < nthr_min) - u = nthr_min; + if (u < params->wthread_min) + u = params->wthread_min; nthr_max = u; ovfl_max = (nthr_max * params->overflow_max) / 100; @@ -497,7 +492,7 @@ * If we need more threads, and have space, create * one more thread. */ - if (qp->nthr < nthr_min || /* Not enough threads yet */ + if (qp->nthr < params->wthread_min || /* Not enough threads yet */ (qp->nqueue > params->wthread_add_threshold && /* more needed */ qp->nqueue > qp->lqueue)) { /* not getting better since last */ if (qp->nthr >= nthr_max) { @@ -541,10 +536,9 @@ /* * Make sure all pools have their minimum complement */ - for (w = 0 ; w < nwq; w++) { - if (wq[w]->nthr < nthr_min) + for (w = 0 ; w < nwq; w++) + while (wq[w]->nthr < params->wthread_min) wrk_breed_flock(wq[w]); - } /* * We cannot avoid getting a mutex, so we have a * bogo mutex just for POSIX_STUPIDITY Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-25 18:20:35 UTC (rev 3027) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-07-25 19:23:35 UTC (rev 3028) @@ -274,9 +274,8 @@ tweak_thread_pool_min(struct cli *cli, const struct parspec *par, const char *arg) { - (void)par; tweak_generic_uint(cli, &master.wthread_min, arg, - 0, master.wthread_max); + par->umin, master.wthread_max); } /*--------------------------------------------------------------------*/ @@ -500,15 +499,15 @@ "in the way of getting work done.\n", EXPERIMENTAL | DELAYED_EFFECT, "500", "threads" }, - { "thread_pool_min", tweak_thread_pool_min, NULL, 1, 0, - "The minimum number of threads in all worker pools combined.\n" + { "thread_pool_min", tweak_thread_pool_min, NULL, 2, 0, + "The minimum number of threads in each worker pool.\n" "\n" "Increasing this may help ramp up faster from low load " "situations where threads have expired.\n" "\n" - "Minimum is 1 thread.", + "Minimum is 2 threads.", EXPERIMENTAL | DELAYED_EFFECT, - "1", "threads" }, + "5", "threads" }, { "thread_pool_timeout", tweak_timeout, &master.wthread_timeout, 1, 0, "Thread idle threshold.\n" "\n" From phk at projects.linpro.no Sun Jul 27 14:36:03 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 27 Jul 2008 16:36:03 +0200 (CEST) Subject: r3029 - trunk/varnish-cache/bin/varnishd Message-ID: <20080727143603.C8A691EC10A@projects.linpro.no> Author: phk Date: 2008-07-27 16:36:03 +0200 (Sun, 27 Jul 2008) New Revision: 3029 Added: trunk/varnish-cache/bin/varnishd/storage_synth.c Log: Forgot to add this file. Added: trunk/varnish-cache/bin/varnishd/storage_synth.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_synth.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/storage_synth.c 2008-07-27 14:36:03 UTC (rev 3029) @@ -0,0 +1,126 @@ +/*- + * Copyright (c) 2008 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: storage_malloc.c 2955 2008-07-19 09:24:07Z phk $ + * + * Storage method for synthetic content, based on vsb. + */ + +#include "config.h" + +#include + +#include +#include +#include + +#include "shmlog.h" +#include "cache.h" +#include "vsb.h" +#include "stevedore.h" + +static MTX sms_mtx; + +static void +sms_free(struct storage *sto) +{ + + CHECK_OBJ_NOTNULL(sto, STORAGE_MAGIC); + LOCK(&sms_mtx); + VSL_stats->sms_nobj--; + VSL_stats->sms_nbytes -= sto->len; + VSL_stats->sms_bfree += sto->len; + UNLOCK(&sms_mtx); + vsb_delete(sto->priv); + free(sto); +} + +void +SMS_Init(void) +{ + + AZ(pthread_mutex_init(&sms_mtx, NULL)); +} + +struct stevedore sms_stevedore = { + .magic = STEVEDORE_MAGIC, + .name = "synth", + .free = sms_free, +}; + +struct vsb * +SMS_Makesynth(struct object *obj) +{ + struct storage *sto; + struct vsb *vsb; + + CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC); + HSH_Freestore(obj); + obj->len = 0; + + LOCK(&sms_mtx); + VSL_stats->sms_nreq++; + VSL_stats->sms_nobj++; + UNLOCK(&sms_mtx); + + sto = calloc(sizeof *sto, 1); + XXXAN(sto); + if (sto == NULL) + return (NULL); + vsb = vsb_newauto(); + XXXAN(vsb); + sto->priv = vsb; + sto->len = 0; + sto->space = 0; + sto->fd = -1; + sto->stevedore = &sms_stevedore; + sto->magic = STORAGE_MAGIC; + + VTAILQ_INSERT_TAIL(&obj->store, sto, list); + return (vsb); +} + +void +SMS_Finish(struct object *obj) +{ + struct storage *sto; + struct vsb *vsb; + + CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC); + sto = VTAILQ_FIRST(&obj->store); + assert(sto->stevedore == &sms_stevedore); + vsb = sto->priv; + vsb_finish(vsb); + AZ(vsb_overflowed(vsb)); + + sto->ptr = (void*)vsb_data(vsb); + sto->len = vsb_len(vsb); + sto->space = vsb_len(vsb); + obj->len = sto->len; + VSL_stats->sms_nbytes += sto->len; + VSL_stats->sms_balloc += sto->len; +} From tfheen at projects.linpro.no Wed Jul 30 10:53:39 2008 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 30 Jul 2008 12:53:39 +0200 (CEST) Subject: r3030 - trunk/varnish-cache/bin/varnishd Message-ID: <20080730105339.1CDCB1EC11B@projects.linpro.no> Author: tfheen Date: 2008-07-30 12:53:38 +0200 (Wed, 30 Jul 2008) New Revision: 3030 Modified: trunk/varnish-cache/bin/varnishd/Makefile.am Log: Add cache_backend.h to the list of headers that go in the tarball; fixes build failure Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-27 14:36:03 UTC (rev 3029) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2008-07-30 10:53:38 UTC (rev 3030) @@ -57,6 +57,7 @@ noinst_HEADERS = \ acct_fields.h \ cache.h \ + cache_backend.h \ cache_acceptor.h \ common.h \ hash_slinger.h \ From tfheen at projects.linpro.no Wed Jul 30 12:18:57 2008 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 30 Jul 2008 14:18:57 +0200 (CEST) Subject: r3031 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080730121857.B91A71ECC4B@projects.linpro.no> Author: tfheen Date: 2008-07-30 14:18:57 +0200 (Wed, 30 Jul 2008) New Revision: 3031 Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Try to connect to CLI 30 times rather than 10 to avoid some timeout errors. Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-30 10:53:38 UTC (rev 3030) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2008-07-30 12:18:57 UTC (rev 3031) @@ -222,7 +222,7 @@ AZ(pthread_create(&v->tp, NULL, varnish_thread, v)); vtc_log(v->vl, 3, "opening CLI connection"); - for (i = 0; i < 10; i++) { + for (i = 0; i < 30; i++) { (void)usleep(200000); v->cli_fd = VSS_open(v->telnet); if (v->cli_fd >= 0) From phk at projects.linpro.no Wed Jul 30 15:34:39 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 30 Jul 2008 17:34:39 +0200 (CEST) Subject: r3032 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20080730153439.5C0EA1EC11B@projects.linpro.no> Author: phk Date: 2008-07-30 17:34:38 +0200 (Wed, 30 Jul 2008) New Revision: 3032 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/include/stat_field.h Log: Add statistics about regexp purges. Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2008-07-30 12:18:57 UTC (rev 3031) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2008-07-30 15:34:38 UTC (rev 3032) @@ -95,7 +95,10 @@ LOCK(&ban_mtx); VTAILQ_INSERT_HEAD(&ban_head, b, list); ban_start = b; + VSL_stats->n_purge++; + VSL_stats->n_purge_add++; UNLOCK(&ban_mtx); + return (0); } @@ -126,10 +129,13 @@ /* Check if we can purge the last ban entry */ b = VTAILQ_LAST(&ban_head, banhead); - if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) + if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) { + VSL_stats->n_purge--; + VSL_stats->n_purge_retire++; VTAILQ_REMOVE(&ban_head, b, list); - else + } else { b = NULL; + } UNLOCK(&ban_mtx); if (b != NULL) { free(b->ban); @@ -144,6 +150,7 @@ { struct ban *b; struct ban * volatile b0; + unsigned tests; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o->ban, BAN_MAGIC); @@ -158,7 +165,9 @@ * a refcount on a ban somewhere in the list and we do not * inspect the list past that ban. */ + tests = 0; for (b = b0; b != o->ban; b = VTAILQ_NEXT(b, list)) { + tests++; if (!regexec(&b->regexp, b->hash ? hash : url, 0, NULL, 0)) break; } @@ -167,6 +176,7 @@ o->ban->refcount--; if (b == o->ban) /* not banned */ b0->refcount++; + VSL_stats->n_purge_test++; UNLOCK(&ban_mtx); if (b == o->ban) { /* not banned */ Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2008-07-30 12:18:57 UTC (rev 3031) +++ trunk/varnish-cache/include/stat_field.h 2008-07-30 15:34:38 UTC (rev 3032) @@ -116,3 +116,8 @@ MAC_STAT(n_vcl, uint64_t, 'a', "N vcl total") MAC_STAT(n_vcl_avail, uint64_t, 'a', "N vcl available") MAC_STAT(n_vcl_discard, uint64_t, 'a', "N vcl discarded") + +MAC_STAT(n_purge, uint64_t, 'i', "N total active purges") +MAC_STAT(n_purge_add, uint64_t, 'a', "N new purges added") +MAC_STAT(n_purge_retire, uint64_t, 'a', "N old purges deleted") +MAC_STAT(n_purge_test, uint64_t, 'a', "N purge record tests") From phk at projects.linpro.no Thu Jul 31 09:09:20 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 11:09:20 +0200 (CEST) Subject: r3033 - trunk/varnish-cache/bin/varnishd Message-ID: <20080731090920.9E3DD1EC11B@projects.linpro.no> Author: phk Date: 2008-07-31 11:09:20 +0200 (Thu, 31 Jul 2008) New Revision: 3033 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/storage_synth.c Log: FlexeLint polishing. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-30 15:34:38 UTC (rev 3032) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-31 09:09:20 UTC (rev 3033) @@ -572,9 +572,6 @@ void RES_BuildHttp(struct sess *sp); void RES_WriteObj(struct sess *sp); -/* cache_synthetic.c */ -void SYN_ErrorPage(struct sess *sp, int status, const char *reason); - /* cache_vary.c */ void VRY_Create(const struct sess *sp); int VRY_Match(const struct sess *sp, const unsigned char *vary); Modified: trunk/varnish-cache/bin/varnishd/storage_synth.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_synth.c 2008-07-30 15:34:38 UTC (rev 3032) +++ trunk/varnish-cache/bin/varnishd/storage_synth.c 2008-07-31 09:09:20 UTC (rev 3033) @@ -66,7 +66,7 @@ AZ(pthread_mutex_init(&sms_mtx, NULL)); } -struct stevedore sms_stevedore = { +static struct stevedore sms_stevedore = { .magic = STEVEDORE_MAGIC, .name = "synth", .free = sms_free, From phk at projects.linpro.no Thu Jul 31 09:22:46 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 11:22:46 +0200 (CEST) Subject: r3034 - trunk/varnish-cache/lib/libvarnish Message-ID: <20080731092246.978CA1EC112@projects.linpro.no> Author: phk Date: 2008-07-31 11:22:46 +0200 (Thu, 31 Jul 2008) New Revision: 3034 Modified: trunk/varnish-cache/lib/libvarnish/vsb.c Log: We don't actually use miniobj.h, we do the same thing internally. Modified: trunk/varnish-cache/lib/libvarnish/vsb.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vsb.c 2008-07-31 09:09:20 UTC (rev 3033) +++ trunk/varnish-cache/lib/libvarnish/vsb.c 2008-07-31 09:22:46 UTC (rev 3034) @@ -40,7 +40,6 @@ #include "libvarnish.h" #include "vsb.h" -#include "miniobj.h" #define KASSERT(e, m) assert(e) #define SBMALLOC(size) malloc(size) From phk at projects.linpro.no Thu Jul 31 09:23:28 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 11:23:28 +0200 (CEST) Subject: r3035 - trunk/varnish-cache/lib/libvcl Message-ID: <20080731092328.B1E421EC11B@projects.linpro.no> Author: phk Date: 2008-07-31 11:23:28 +0200 (Thu, 31 Jul 2008) New Revision: 3035 Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c Log: Check that we found a variable before using it. Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-31 09:22:46 UTC (rev 3034) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-31 09:23:28 UTC (rev 3035) @@ -99,6 +99,7 @@ vcc_NextToken(tl); if (tl->t->tok == VAR) { vp = vcc_FindVar(tl, tl->t, vcc_vars); + ERRCHK(tl); if (vp->fmt == INT) { Fb(tl, 1, "VRT_error(sp, %s", vp->rname); vcc_NextToken(tl); From phk at projects.linpro.no Thu Jul 31 09:24:25 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 11:24:25 +0200 (CEST) Subject: r3036 - trunk/varnish-cache/bin/varnishd Message-ID: <20080731092425.B77F41EC112@projects.linpro.no> Author: phk Date: 2008-07-31 11:24:25 +0200 (Thu, 31 Jul 2008) New Revision: 3036 Modified: trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/storage_malloc.c Log: Flexelint silencing Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-31 09:23:28 UTC (rev 3035) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2008-07-31 09:24:25 UTC (rev 3036) @@ -680,6 +680,7 @@ /*--------------------------------------------------------------------*/ +/*lint -e{818} not const-able */ static void smf_free(struct storage *s) { Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2008-07-31 09:23:28 UTC (rev 3035) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2008-07-31 09:24:25 UTC (rev 3036) @@ -85,6 +85,7 @@ return (&sma->s); } +/*lint -e{818} not const-able */ static void sma_free(struct storage *s) { From phk at projects.linpro.no Thu Jul 31 09:25:25 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 11:25:25 +0200 (CEST) Subject: r3037 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20080731092525.C208B1EC11B@projects.linpro.no> Author: phk Date: 2008-07-31 11:25:25 +0200 (Thu, 31 Jul 2008) New Revision: 3037 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/include/stat_field.h Log: Make separate stats counters for number of object checked against purges and number of regexps checked. Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2008-07-31 09:24:25 UTC (rev 3036) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2008-07-31 09:25:25 UTC (rev 3037) @@ -176,7 +176,8 @@ o->ban->refcount--; if (b == o->ban) /* not banned */ b0->refcount++; - VSL_stats->n_purge_test++; + VSL_stats->n_purge_obj_test++; + VSL_stats->n_purge_re_test += tests; UNLOCK(&ban_mtx); if (b == o->ban) { /* not banned */ Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2008-07-31 09:24:25 UTC (rev 3036) +++ trunk/varnish-cache/include/stat_field.h 2008-07-31 09:25:25 UTC (rev 3037) @@ -120,4 +120,5 @@ MAC_STAT(n_purge, uint64_t, 'i', "N total active purges") MAC_STAT(n_purge_add, uint64_t, 'a', "N new purges added") MAC_STAT(n_purge_retire, uint64_t, 'a', "N old purges deleted") -MAC_STAT(n_purge_test, uint64_t, 'a', "N purge record tests") +MAC_STAT(n_purge_obj_test, uint64_t, 'a', "N objects tested") +MAC_STAT(n_purge_re_test, uint64_t, 'a', "N regexps tested against") From phk at projects.linpro.no Thu Jul 31 09:52:27 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 11:52:27 +0200 (CEST) Subject: r3038 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080731095227.E0FC11ECEFC@projects.linpro.no> Author: phk Date: 2008-07-31 11:52:27 +0200 (Thu, 31 Jul 2008) New Revision: 3038 Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c Log: Accept ECONNRESET when closing sockets during cleanup. Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_server.c 2008-07-31 09:25:25 UTC (rev 3037) +++ trunk/varnish-cache/bin/varnishtest/vtc_server.c 2008-07-31 09:52:27 UTC (rev 3038) @@ -28,6 +28,7 @@ #include +#include #include #include #include @@ -97,7 +98,7 @@ http_process(vl, s->spec, fd, 0); vtc_log(vl, 3, "shutting fd %d", fd); AZ(shutdown(fd, SHUT_WR)); - AZ(close(fd)); + assert(close(fd) == 0 || errno == ECONNRESET); } vtc_log(vl, 2, "Ending"); return (NULL); From phk at projects.linpro.no Thu Jul 31 10:01:36 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 12:01:36 +0200 (CEST) Subject: r3039 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20080731100136.D6CCB1ECC4B@projects.linpro.no> Author: phk Date: 2008-07-31 12:01:36 +0200 (Thu, 31 Jul 2008) New Revision: 3039 Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c trunk/varnish-cache/include/vcl.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl Log: Don't write to read-only structure members in the shared object definition structure. Fixes ticket 285 Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vcl.c 2008-07-31 09:52:27 UTC (rev 3038) +++ trunk/varnish-cache/bin/varnishd/cache_vcl.c 2008-07-31 10:01:36 UTC (rev 3039) @@ -53,7 +53,7 @@ VTAILQ_ENTRY(vcls) list; char *name; void *dlh; - struct VCL_conf *conf; + struct VCL_conf conf[1]; }; /* @@ -131,6 +131,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) { struct vcls *vcl; + struct VCL_conf const *cnf; ASSERT_CLI(); vcl = vcl_find(name); @@ -149,13 +150,14 @@ FREE_OBJ(vcl); return (1); } - vcl->conf = dlsym(vcl->dlh, "VCL_conf"); - if (vcl->conf == NULL) { - cli_out(cli, "No VCL_conf symbol\n"); + cnf = dlsym(vcl->dlh, "VCL_conf"); + if (cnf == NULL) { + cli_out(cli, "Internal error: No VCL_conf symbol\n"); (void)dlclose(vcl->dlh); FREE_OBJ(vcl); return (1); } + memcpy(vcl->conf, cnf, sizeof *cnf); if (vcl->conf->magic != VCL_CONF_MAGIC) { cli_out(cli, "Wrong VCL_CONF_MAGIC\n"); @@ -163,7 +165,6 @@ FREE_OBJ(vcl); return (1); } - vcl->conf->priv = vcl; REPLACE(vcl->name, name); VTAILQ_INSERT_TAIL(&vcl_head, vcl, list); LOCK(&vcl_mtx); Modified: trunk/varnish-cache/include/vcl.h =================================================================== --- trunk/varnish-cache/include/vcl.h 2008-07-31 09:52:27 UTC (rev 3038) +++ trunk/varnish-cache/include/vcl.h 2008-07-31 10:01:36 UTC (rev 3039) @@ -30,8 +30,6 @@ unsigned nhashcount; - void *priv; - vcl_init_f *init_func; vcl_fini_f *fini_func; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-31 09:52:27 UTC (rev 3038) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-31 10:01:36 UTC (rev 3039) @@ -262,8 +262,6 @@ 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"); vsb_cat(sb, " vcl_fini_f *fini_func;\n"); vsb_cat(sb, "\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2008-07-31 09:52:27 UTC (rev 3038) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2008-07-31 10:01:36 UTC (rev 3039) @@ -143,8 +143,6 @@ unsigned nhashcount; - void *priv; - vcl_init_f *init_func; vcl_fini_f *fini_func; } From phk at projects.linpro.no Thu Jul 31 10:03:27 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 12:03:27 +0200 (CEST) Subject: r3040 - trunk/varnish-cache/lib/libvcl Message-ID: <20080731100327.7DACC1ECC4B@projects.linpro.no> Author: phk Date: 2008-07-31 12:03:27 +0200 (Thu, 31 Jul 2008) New Revision: 3040 Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c Log: An assert to convince FlexeLint that we have a variable. Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-31 10:01:36 UTC (rev 3039) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-31 10:03:27 UTC (rev 3040) @@ -100,6 +100,7 @@ if (tl->t->tok == VAR) { vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); + assert(vp != NULL); if (vp->fmt == INT) { Fb(tl, 1, "VRT_error(sp, %s", vp->rname); vcc_NextToken(tl); From tfheen at projects.linpro.no Thu Jul 31 10:19:44 2008 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 31 Jul 2008 12:19:44 +0200 (CEST) Subject: r3041 - trunk/varnish-cache/bin/varnishstat Message-ID: <20080731101944.6560D1EC112@projects.linpro.no> Author: tfheen Date: 2008-07-31 12:19:44 +0200 (Thu, 31 Jul 2008) New Revision: 3041 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c Log: Add uptime to varnishstat -1 output Make varnishstat -1 also output the uptime. Closes #68 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2008-07-31 10:03:27 UTC (rev 3040) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2008-07-31 10:19:44 UTC (rev 3041) @@ -211,6 +211,13 @@ gettimeofday(&tv, NULL); up = tv.tv_sec - VSL_stats->start_time; + do { + if (fields != NULL && ! show_field("uptime", fields )) + break; + printf("%-16s %12ju %12s %s\n", "uptime", + tv.tv_sec - VSL_stats->start_time, ". ", "Child uptime"); + } while (0); + #define MAC_STAT(n, t, f, d) \ do { \ if (fields != NULL && ! show_field( #n, fields )) break; \ @@ -246,6 +253,8 @@ fprintf(stderr, "Available fields to use with the varnishstat -f option:\n"); fprintf(stderr, "Field name Description\n"); fprintf(stderr, "---------- -----------\n"); + fprintf(stderr, "uptime Child uptime\n"); + #define MAC_STAT(n, t, f, d) \ do { \ fprintf(stderr, "%-20s %s\n", #n, d);\ @@ -259,6 +268,7 @@ { int i, valid_field, field_length; const char *all_fields[] = { + "uptime", #define MAC_STAT(n, t, f, d) \ #n, #include "stat_field.h" From phk at projects.linpro.no Thu Jul 31 10:24:19 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 12:24:19 +0200 (CEST) Subject: r3042 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080731102419.F0CCD1ECC4B@projects.linpro.no> Author: phk Date: 2008-07-31 12:24:19 +0200 (Thu, 31 Jul 2008) New Revision: 3042 Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c Log: Retry client connects once. Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_client.c 2008-07-31 10:19:44 UTC (rev 3041) +++ trunk/varnish-cache/bin/varnishtest/vtc_client.c 2008-07-31 10:24:19 UTC (rev 3042) @@ -78,6 +78,10 @@ vtc_log(vl, 2, "Started"); vtc_log(vl, 3, "Connect to %s", c->connect); fd = VSS_open(c->connect); + if (fd < 0) { + sleep(1); + fd = VSS_open(c->connect); + } assert(fd >= 0); vtc_log(vl, 3, "Connected to %s fd is %d", c->connect, fd); http_process(vl, c->spec, fd, 1); From phk at projects.linpro.no Thu Jul 31 10:35:36 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 12:35:36 +0200 (CEST) Subject: r3043 - trunk/varnish-cache/bin/varnishtest Message-ID: <20080731103536.0AE031EC112@projects.linpro.no> Author: phk Date: 2008-07-31 12:35:35 +0200 (Thu, 31 Jul 2008) New Revision: 3043 Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c Log: Ok, 3 retries then... Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_client.c 2008-07-31 10:24:19 UTC (rev 3042) +++ trunk/varnish-cache/bin/varnishtest/vtc_client.c 2008-07-31 10:35:35 UTC (rev 3043) @@ -69,6 +69,7 @@ struct client *c; struct vtclog *vl; int fd = -1; + int i; CAST_OBJ_NOTNULL(c, priv, CLIENT_MAGIC); AN(c->connect); @@ -78,7 +79,7 @@ vtc_log(vl, 2, "Started"); vtc_log(vl, 3, "Connect to %s", c->connect); fd = VSS_open(c->connect); - if (fd < 0) { + for (i = 0; fd < 0 && i < 3; i++) { sleep(1); fd = VSS_open(c->connect); } From phk at projects.linpro.no Thu Jul 31 12:50:37 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 14:50:37 +0200 (CEST) Subject: r3044 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl Message-ID: <20080731125037.477071ECEFC@projects.linpro.no> Author: phk Date: 2008-07-31 14:50:36 +0200 (Thu, 31 Jul 2008) New Revision: 3044 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishd/rfc2616.c trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: Complete the separation of synthetic from received objects. Any object, also errors, we receive from the backend will go to vcl_fetch(), and can be cached if desired. Any object we create, for instance if we cannot contact the backend, will go to vcl_error() and will not be cached. Technical details: Implement VCL variable setting for booleans like obj.cacheable. Remove obj.valid, only valid objects go to vcl_fetch now. On fetch failure, drop the object and go to STP_ERROR with 503 Update testcase b00015.vtc accordingly. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2008-07-31 10:35:35 UTC (rev 3043) +++ trunk/varnish-cache/bin/varnishd/cache.h 2008-07-31 12:50:36 UTC (rev 3044) @@ -258,7 +258,6 @@ unsigned response; - unsigned valid; unsigned cacheable; unsigned busy; Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-31 10:35:35 UTC (rev 3043) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-31 12:50:36 UTC (rev 3044) @@ -162,11 +162,6 @@ 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(); } @@ -316,6 +311,8 @@ if (sp->obj == NULL) { HSH_Prealloc(sp); sp->obj = sp->wrk->nobj; + sp->obj->xid = sp->xid; + sp->obj->entered = sp->t_req; sp->wrk->nobj = NULL; } else { /* XXX: Null the headers ? */ @@ -384,15 +381,22 @@ i = Fetch(sp); CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC); - if (!i) - RFC2616_cache_policy(sp, sp->obj->http); /* XXX -> VCL */ - else { - http_PutStatus(sp->wrk, sp->fd, sp->obj->http, 503); - http_PutProtocol(sp->wrk, sp->fd, sp->obj->http, "HTTP/1.1"); - http_PutResponse(sp->wrk, sp->fd, sp->obj->http, - "Backend error"); + if (i) { +VSL(SLT_Debug, sp->fd, "Fetch = %d", i); + sp->err_code = 503; + sp->step = STP_ERROR; + VBE_free_bereq(sp->bereq); + sp->bereq = NULL; + sp->obj->ttl = 0; + sp->obj->cacheable = 0; + HSH_Unbusy(sp); + HSH_Deref(sp->obj); + sp->obj = NULL; + return (0); } + RFC2616_cache_policy(sp, sp->obj->http); /* XXX -> VCL */ + sp->err_code = http_GetStatus(sp->obj->http); VCL_fetch_method(sp); Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-31 10:35:35 UTC (rev 3043) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-07-31 12:50:36 UTC (rev 3044) @@ -413,7 +413,6 @@ return (sp->obj->field); \ } -VOBJ(unsigned, valid, valid) VOBJ(unsigned, cacheable, cacheable) /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-07-31 10:35:35 UTC (rev 3043) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-07-31 12:50:36 UTC (rev 3044) @@ -135,9 +135,6 @@ "}\n" "\n" "sub vcl_fetch {\n" - " if (!obj.valid) {\n" - " error obj.status;\n" - " }\n" " if (!obj.cacheable) {\n" " pass;\n" " }\n" Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- trunk/varnish-cache/bin/varnishd/rfc2616.c 2008-07-31 10:35:35 UTC (rev 3043) +++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2008-07-31 12:50:36 UTC (rev 3044) @@ -178,12 +178,10 @@ case 410: /* Gone */ case 404: /* Not Found */ sp->obj->cacheable = 1; - sp->obj->valid = 1; body = 1; break; default: sp->obj->cacheable = 0; - sp->obj->valid = 1; /* XXX ? */ body = 0; break; } Modified: trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc 2008-07-31 10:35:35 UTC (rev 3043) +++ trunk/varnish-cache/bin/varnishtest/tests/b00015.vtc 2008-07-31 12:50:36 UTC (rev 3044) @@ -2,19 +2,82 @@ test "Check synthetic error page caching" + +# First test that an internally generated error is not cached + +varnish v1 -vcl { + backend foo { + .host = "127.0.0.2"; + } +} -start + +client c1 { + txreq -url "/" + rxresp + expect resp.status == 503 + expect resp.http.X-varnish == "1001" +} -run + +client c1 { + txreq -url "/" + rxresp + expect resp.status == 503 + expect resp.http.X-varnish == "1002" +} -run + +# Then check that an cacheable error from the backend is + server s1 { rxreq - txresp -status 503 -msg "Server Error" + txresp -status 302 } -start -varnish v1 -vcl+backend { } -start +varnish v1 -vcl+backend { } client c1 { txreq -url "/" rxresp - expect resp.status == 503 - # Disable this for now to not upset automatic scripts - #txreq -url "/" - #rxresp - #expect resp.status == 503 + expect resp.status == 302 + expect resp.http.X-varnish == "1003" } -run + +server s1 -wait + +client c1 { + txreq -url "/" + rxresp + expect resp.status == 302 + expect resp.http.X-varnish == "1004 1003" +} -run + +# Then check that a non-cacheable error from the backend can be + +server s1 { + rxreq + txresp -status 502 +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + if (obj.status == 502) { + set obj.cacheable = true; + set obj.ttl = 10m; + } + } + } + +client c1 { + txreq -url "/2" + rxresp + expect resp.status == 502 + expect resp.http.X-varnish == "1005" +} -run + +server s1 -wait + +client c1 { + txreq -url "/2" + rxresp + expect resp.status == 502 + expect resp.http.X-varnish == "1006 1005" +} -run Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2008-07-31 10:35:35 UTC (rev 3043) +++ trunk/varnish-cache/include/vrt_obj.h 2008-07-31 12:50:36 UTC (rev 3044) @@ -34,8 +34,6 @@ void VRT_l_obj_status(const struct sess *, int); const char * VRT_r_obj_response(const struct sess *); void VRT_l_obj_response(const struct sess *, const char *, ...); -unsigned VRT_r_obj_valid(const struct sess *); -void VRT_l_obj_valid(const struct sess *, unsigned); unsigned VRT_r_obj_cacheable(const struct sess *); void VRT_l_obj_cacheable(const struct sess *, unsigned); double VRT_r_obj_ttl(const struct sess *); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-31 10:35:35 UTC (rev 3043) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2008-07-31 12:50:36 UTC (rev 3044) @@ -280,9 +280,28 @@ } Fb(tl, 0, "vrt_magic_string_end);\n"); break; + case BOOL: + if (tl->t->tok != '=') { + illegal_assignment(tl, "boolean"); + return; + } + vcc_NextToken(tl); + ExpectErr(tl, ID); + if (vcc_IdIs(tl->t, "true")) { + Fb(tl, 0, " 1);\n", vp->lname); + } else if (vcc_IdIs(tl->t, "false")) { + Fb(tl, 0, " 0);\n", vp->lname); + } else { + vsb_printf(tl->sb, + "Expected true or false\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + vcc_NextToken(tl); + break; default: vsb_printf(tl->sb, - "Assignments not possible for '%s'\n", vp->name); + "Assignments not possible for type of '%s'\n", vp->name); vcc_ErrWhere(tl, tl->t); return; } Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2008-07-31 10:35:35 UTC (rev 3043) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2008-07-31 12:50:36 UTC (rev 3044) @@ -150,11 +150,6 @@ "const struct sess *" } - { obj.valid - RW BOOL - { hit fetch discard timeout error} - "const struct sess *" - } { obj.cacheable RW BOOL { hit fetch discard timeout error} Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2008-07-31 10:35:35 UTC (rev 3043) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2008-07-31 12:50:36 UTC (rev 3044) @@ -151,13 +151,6 @@ "HDR_OBJ", VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_ERROR }, - { "obj.valid", BOOL, 9, - "VRT_r_obj_valid(sp)", - "VRT_l_obj_valid(sp, ", - V_RW, - 0, - VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT | VCL_MET_ERROR - }, { "obj.cacheable", BOOL, 13, "VRT_r_obj_cacheable(sp)", "VRT_l_obj_cacheable(sp, ", From phk at projects.linpro.no Thu Jul 31 12:53:41 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 14:53:41 +0200 (CEST) Subject: r3045 - trunk/varnish-cache/bin/varnishd Message-ID: <20080731125341.2F5091EC1D3@projects.linpro.no> Author: phk Date: 2008-07-31 14:53:40 +0200 (Thu, 31 Jul 2008) New Revision: 3045 Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c Log: Explanation Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- trunk/varnish-cache/bin/varnishd/rfc2616.c 2008-07-31 12:50:36 UTC (rev 3044) +++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2008-07-31 12:53:40 UTC (rev 3045) @@ -159,6 +159,14 @@ return (ttd); } +/* + * We could move this policy to vcl_fetch{} now but I have decided to leave + * it here for the POLA principle. It is not credible to think that a + * majority of our uses will change the cacheability decision, so moving + * it to VCL would just make the average and median vcl_fetch{} implementation + * harder for people to write. Instead the minority who want to override + * the RFC2616 mandated behaviour, can do so in their vcl_fetch{} + */ int RFC2616_cache_policy(const struct sess *sp, const struct http *hp) { From phk at projects.linpro.no Thu Jul 31 14:59:06 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 16:59:06 +0200 (CEST) Subject: r3046 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080731145906.C09DD1EC112@projects.linpro.no> Author: phk Date: 2008-07-31 16:59:06 +0200 (Thu, 31 Jul 2008) New Revision: 3046 Added: trunk/varnish-cache/bin/varnishtest/tests/c00017.vtc Log: Add a test-case for VCL purging Added: trunk/varnish-cache/bin/varnishtest/tests/c00017.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00017.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/c00017.vtc 2008-07-31 14:59:06 UTC (rev 3046) @@ -0,0 +1,30 @@ +# $Id: c00016.vtc 3012 2008-07-24 12:22:35Z des $ + +test "Test vcl purging" + +server s1 { + rxreq + txresp -body "foo" + + rxreq + txresp -body "foo" +} -start + +varnish v1 -vcl+backend { + + sub vcl_fetch { + purge_url("^/$"); + } + +} -start + +client c1 { + txreq + rxresp + expect resp.http.X-Varnish == "1001" + + txreq + rxresp + expect resp.http.X-Varnish == "1002" + +} -start From phk at projects.linpro.no Thu Jul 31 14:59:59 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 31 Jul 2008 16:59:59 +0200 (CEST) Subject: r3047 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20080731145959.1D7D01EC11B@projects.linpro.no> Author: phk Date: 2008-07-31 16:59:58 +0200 (Thu, 31 Jul 2008) New Revision: 3047 Added: trunk/varnish-cache/bin/varnishtest/tests/v00011.vtc Removed: trunk/varnish-cache/bin/varnishtest/tests/c00017.vtc Log: That test rightfully is a v* test Deleted: trunk/varnish-cache/bin/varnishtest/tests/c00017.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00017.vtc 2008-07-31 14:59:06 UTC (rev 3046) +++ trunk/varnish-cache/bin/varnishtest/tests/c00017.vtc 2008-07-31 14:59:58 UTC (rev 3047) @@ -1,30 +0,0 @@ -# $Id: c00016.vtc 3012 2008-07-24 12:22:35Z des $ - -test "Test vcl purging" - -server s1 { - rxreq - txresp -body "foo" - - rxreq - txresp -body "foo" -} -start - -varnish v1 -vcl+backend { - - sub vcl_fetch { - purge_url("^/$"); - } - -} -start - -client c1 { - txreq - rxresp - expect resp.http.X-Varnish == "1001" - - txreq - rxresp - expect resp.http.X-Varnish == "1002" - -} -start Copied: trunk/varnish-cache/bin/varnishtest/tests/v00011.vtc (from rev 3046, trunk/varnish-cache/bin/varnishtest/tests/c00017.vtc) =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00011.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00011.vtc 2008-07-31 14:59:58 UTC (rev 3047) @@ -0,0 +1,30 @@ +# $Id: c00016.vtc 3012 2008-07-24 12:22:35Z des $ + +test "Test vcl purging" + +server s1 { + rxreq + txresp -body "foo" + + rxreq + txresp -body "foo" +} -start + +varnish v1 -vcl+backend { + + sub vcl_fetch { + purge_url("^/$"); + } + +} -start + +client c1 { + txreq + rxresp + expect resp.http.X-Varnish == "1001" + + txreq + rxresp + expect resp.http.X-Varnish == "1002" + +} -start Property changes on: trunk/varnish-cache/bin/varnishtest/tests/v00011.vtc ___________________________________________________________________ Name: svn:mergeinfo + From phk at projects.linpro.no Thu Jul 31 22:38:01 2008 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 1 Aug 2008 00:38:01 +0200 (CEST) Subject: r3048 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20080731223801.8697F1EC112@projects.linpro.no> Author: phk Date: 2008-08-01 00:38:01 +0200 (Fri, 01 Aug 2008) New Revision: 3048 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/include/vcl_returns.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl Log: Rename the vcl_fetch{} action "insert" to "deliver" as we may not insert (for instance on pass) but we certainly will deliver (unless error or restart actions are used instead). Update the dotgraph to 2.0 intent Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-31 14:59:58 UTC (rev 3047) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2008-07-31 22:38:01 UTC (rev 3048) @@ -53,6 +53,7 @@ DOT label="Request received" DOT ] DOT ERROR [shape=plaintext] +DOT RESTART [shape=plaintext] DOT acceptor -> start [style=bold,color=green,weight=4] */ @@ -122,12 +123,14 @@ DOT ] DOT deliver2 [ DOT shape=ellipse -DOT label="Send hdr + object" +DOT label="Send resp + body" DOT ] DOT deliver -> vcl_deliver [style=bold,color=green,weight=4] DOT vcl_deliver -> deliver2 [style=bold,color=green,weight=4,label=deliver] DOT vcl_deliver -> errdeliver [label="error"] DOT errdeliver [label="ERROR",shape=plaintext] +DOT vcl_deliver -> rstdeliver [label="restart",color=purple] +DOT rstdeliver [label="RESTART",shape=plaintext] DOT } DOT deliver2 -> DONE [style=bold,color=green,weight=4] * @@ -289,13 +292,13 @@ * Emit an error * DOT subgraph xcluster_error { -DOT error [ -DOT shape=ellipse -DOT label="Issue HTTP error" +DOT vcl_error [ +DOT shape=record +DOT label="vcl_error()|resp." DOT ] -DOT ERROR -> error +DOT ERROR -> vcl_error +DOT vcl_error-> deliver [label=deliver] DOT } -DOT error -> DONE */ static int @@ -359,11 +362,14 @@ DOT shape=ellipse DOT label="obj.pass=true" DOT ] -DOT vcl_fetch -> fetch_pass [label="pass"] +DOT vcl_fetch -> fetch_pass [label="pass",style=bold,color=red] DOT } -DOT fetch_pass -> deliver -DOT vcl_fetch -> deliver [label="insert",style=bold,color=blue,weight=2] +DOT fetch_pass -> deliver [style=bold,color=red] +DOT vcl_fetch -> deliver [label="deliver",style=bold,color=blue,weight=2] DOT vcl_fetch -> recv [label="restart"] +DOT vcl_fetch -> rstfetch [label="restart",color=purple] +DOT rstfetch [label="RESTART",shape=plaintext] +DOT fetch -> errfetch DOT vcl_fetch -> errfetch [label="error"] DOT errfetch [label="ERROR",shape=plaintext] */ @@ -422,7 +428,7 @@ case VCL_RET_PASS: sp->obj->pass = 1; break; - case VCL_RET_INSERT: + case VCL_RET_DELIVER: break; default: INCOMPL(); @@ -499,7 +505,9 @@ DOT } DOT hit -> err_hit [label="error"] DOT err_hit [label="ERROR",shape=plaintext] -DOT hit -> pass [label=pass] +DOT hit -> rst_hit [label="restart",color=purple] +DOT rst_hit [label="RESTART",shape=plaintext] +DOT hit -> pass [label=pass,style=bold,color=red] DOT hit -> deliver [label="deliver",style=bold,color=green,weight=4] */ @@ -564,7 +572,7 @@ DOT lookup -> lookup2 [label="yes",style=bold,color=green,weight=4] DOT } DOT lookup2 -> hit [label="no", style=bold,color=green,weight=4] -DOT lookup2 -> pass [label="yes"] +DOT lookup2 -> pass [label="yes",style=bold,color=red] DOT lookup -> miss [label="no",style=bold,color=blue,weight=2] */ @@ -658,10 +666,12 @@ DOT ] DOT miss -> vcl_miss [style=bold,color=blue,weight=2] DOT } +DOT vcl_miss -> rst_miss [label="restart",color=purple] +DOT rst_miss [label="RESTART",shape=plaintext] DOT vcl_miss -> err_miss [label="error"] DOT err_miss [label="ERROR",shape=plaintext] DOT vcl_miss -> fetch [label="fetch",style=bold,color=blue,weight=2] -DOT vcl_miss -> pass [label="pass"] +DOT vcl_miss -> pass [label="pass",style=bold,color=red] DOT */ @@ -725,11 +735,13 @@ DOT shape=ellipse DOT label="create anon object\n" DOT ] -DOT pass -> pass2 -DOT pass2 -> vcl_pass -DOT vcl_pass -> pass_do [label="pass"] +DOT pass -> pass2 [style=bold, color=red] +DOT pass2 -> vcl_pass [style=bold, color=red] +DOT vcl_pass -> pass_do [label="pass"] [style=bold, color=red] DOT } -DOT pass_do -> fetch +DOT pass_do -> fetch [style=bold, color=red] +DOT vcl_pass -> rst_pass [label="restart",color=purple] +DOT rst_pass [label="RESTART",shape=plaintext] DOT vcl_pass -> err_pass [label="error"] DOT err_pass [label="ERROR",shape=plaintext] */ @@ -776,10 +788,10 @@ DOT shape=ellipse DOT label="send bereq.\npipe until close" DOT ] -DOT vcl_pipe -> pipe_do [label="pipe"] -DOT pipe -> vcl_pipe +DOT vcl_pipe -> pipe_do [label="pipe",style=bold,color=orange] +DOT pipe -> vcl_pipe [style=bold,color=orange] DOT } -DOT pipe_do -> DONE +DOT pipe_do -> DONE [style=bold,color=orange] DOT vcl_pipe -> err_pipe [label="error"] DOT err_pipe [label="ERROR",shape=plaintext] */ @@ -816,8 +828,9 @@ DOT label="vcl_recv()|req." DOT ] DOT } -DOT recv -> pipe [label="pipe"] -DOT recv -> pass2 [label="pass"] +DOT RESTART -> recv +DOT recv -> pipe [label="pipe",style=bold,color=orange] +DOT recv -> pass2 [label="pass",style=bold,color=red] DOT recv -> err_recv [label="error"] DOT err_recv [label="ERROR",shape=plaintext] DOT recv -> hash [label="lookup",style=bold,color=green,weight=4] Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-07-31 14:59:58 UTC (rev 3047) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2008-07-31 22:38:01 UTC (rev 3048) @@ -142,7 +142,7 @@ " pass;\n" " }\n" " set obj.prefetch = -30s;" - " insert;\n" + " deliver;\n" "}\n" "sub vcl_deliver {\n" " deliver;\n" Modified: trunk/varnish-cache/include/vcl_returns.h =================================================================== --- trunk/varnish-cache/include/vcl_returns.h 2008-07-31 14:59:58 UTC (rev 3047) +++ trunk/varnish-cache/include/vcl_returns.h 2008-07-31 22:38:01 UTC (rev 3048) @@ -15,11 +15,10 @@ VCL_RET_MAC(pipe, PIPE, (1 << 3), 3) VCL_RET_MAC(pass, PASS, (1 << 4), 4) VCL_RET_MAC(fetch, FETCH, (1 << 5), 5) -VCL_RET_MAC(insert, INSERT, (1 << 6), 6) -VCL_RET_MAC(deliver, DELIVER, (1 << 7), 7) -VCL_RET_MAC(discard, DISCARD, (1 << 8), 8) -VCL_RET_MAC(keep, KEEP, (1 << 9), 9) -VCL_RET_MAC(restart, RESTART, (1 << 10), 10) +VCL_RET_MAC(deliver, DELIVER, (1 << 6), 6) +VCL_RET_MAC(discard, DISCARD, (1 << 7), 7) +VCL_RET_MAC(keep, KEEP, (1 << 8), 8) +VCL_RET_MAC(restart, RESTART, (1 << 9), 9) #else #define VCL_RET_ERROR (1 << 0) #define VCL_RET_LOOKUP (1 << 1) @@ -27,22 +26,21 @@ #define VCL_RET_PIPE (1 << 3) #define VCL_RET_PASS (1 << 4) #define VCL_RET_FETCH (1 << 5) -#define VCL_RET_INSERT (1 << 6) -#define VCL_RET_DELIVER (1 << 7) -#define VCL_RET_DISCARD (1 << 8) -#define VCL_RET_KEEP (1 << 9) -#define VCL_RET_RESTART (1 << 10) -#define VCL_RET_MAX 11 +#define VCL_RET_DELIVER (1 << 6) +#define VCL_RET_DISCARD (1 << 7) +#define VCL_RET_KEEP (1 << 8) +#define VCL_RET_RESTART (1 << 9) +#define VCL_RET_MAX 10 #endif #ifdef VCL_MET_MAC -VCL_MET_MAC(recv,RECV,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_PIPE|VCL_RET_LOOKUP)) -VCL_MET_MAC(pipe,PIPE,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PIPE)) +VCL_MET_MAC(recv,RECV,(VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_PIPE|VCL_RET_LOOKUP)) +VCL_MET_MAC(pipe,PIPE,(VCL_RET_ERROR|VCL_RET_PIPE)) VCL_MET_MAC(pass,PASS,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS)) VCL_MET_MAC(hash,HASH,(VCL_RET_HASH)) VCL_MET_MAC(miss,MISS,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_FETCH)) VCL_MET_MAC(hit,HIT,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_DELIVER)) -VCL_MET_MAC(fetch,FETCH,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_INSERT)) +VCL_MET_MAC(fetch,FETCH,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_DELIVER)) VCL_MET_MAC(deliver,DELIVER,(VCL_RET_RESTART|VCL_RET_DELIVER)) VCL_MET_MAC(prefetch,PREFETCH,(VCL_RET_FETCH|VCL_RET_PASS)) VCL_MET_MAC(timeout,TIMEOUT,(VCL_RET_FETCH|VCL_RET_DISCARD)) Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-31 14:59:58 UTC (rev 3047) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2008-07-31 22:38:01 UTC (rev 3048) @@ -225,11 +225,10 @@ vsb_cat(sb, "#define VCL_RET_PIPE (1 << 3)\n"); vsb_cat(sb, "#define VCL_RET_PASS (1 << 4)\n"); vsb_cat(sb, "#define VCL_RET_FETCH (1 << 5)\n"); - vsb_cat(sb, "#define VCL_RET_INSERT (1 << 6)\n"); - vsb_cat(sb, "#define VCL_RET_DELIVER (1 << 7)\n"); - vsb_cat(sb, "#define VCL_RET_DISCARD (1 << 8)\n"); - vsb_cat(sb, "#define VCL_RET_KEEP (1 << 9)\n"); - vsb_cat(sb, "#define VCL_RET_RESTART (1 << 10)\n"); + vsb_cat(sb, "#define VCL_RET_DELIVER (1 << 6)\n"); + vsb_cat(sb, "#define VCL_RET_DISCARD (1 << 7)\n"); + vsb_cat(sb, "#define VCL_RET_KEEP (1 << 8)\n"); + vsb_cat(sb, "#define VCL_RET_RESTART (1 << 9)\n"); vsb_cat(sb, "/*\n"); vsb_cat(sb, " * $Id$\n"); vsb_cat(sb, " *\n"); @@ -487,8 +486,6 @@ vsb_cat(sb, "void VRT_l_obj_status(const struct sess *, int);\n"); vsb_cat(sb, "const char * VRT_r_obj_response(const struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_response(const struct sess *, const char *, ...);\n"); - vsb_cat(sb, "unsigned VRT_r_obj_valid(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_valid(const struct sess *, unsigned);\n"); vsb_cat(sb, "unsigned VRT_r_obj_cacheable(const struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_cacheable(const struct sess *, unsigned);\n"); vsb_cat(sb, "double VRT_r_obj_ttl(const struct sess *);\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2008-07-31 14:59:58 UTC (rev 3047) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2008-07-31 22:38:01 UTC (rev 3048) @@ -34,13 +34,13 @@ # Second element is list of valid return actions. # set methods { - {recv {error restart pass pipe lookup}} - {pipe {error restart pipe}} + {recv {error pass pipe lookup}} + {pipe {error pipe}} {pass {error restart pass}} {hash {hash}} {miss {error restart pass fetch}} {hit {error restart pass deliver}} - {fetch {error restart pass insert}} + {fetch {error restart pass deliver}} {deliver {restart deliver}} {prefetch {fetch pass}} {timeout {fetch discard}} @@ -57,7 +57,6 @@ pipe pass fetch - insert deliver discard keep