From phk at projects.linpro.no Mon Feb 2 16:48:29 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 2 Feb 2009 17:48:29 +0100 (CET) Subject: r3565 - trunk/varnish-cache/bin/varnishd Message-ID: <20090202164829.3DDAA1F74B6@projects.linpro.no> Author: phk Date: 2009-02-02 17:48:28 +0100 (Mon, 02 Feb 2009) New Revision: 3565 Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c Log: Close a race where VCL tries to modify the obj.ttl at the same moment the grim reaper has taken the object off the binheap to inspect it. Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-01-30 14:40:32 UTC (rev 3564) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-02 16:48:28 UTC (rev 3565) @@ -143,6 +143,7 @@ CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oe = o->objexp; CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); + Lck_AssertHeld(&exp_mtx); if (o->prefetch < 0.0) { when = o->ttl + o->prefetch; @@ -184,8 +185,9 @@ assert(o->entered != 0 && !isnan(o->entered)); oe->lru_stamp = o->entered; + Lck_Lock(&exp_mtx); + assert(oe->timer_idx == BINHEAP_NOIDX); (void)update_object_when(o); - Lck_Lock(&exp_mtx); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); VTAILQ_INSERT_TAIL(&lru, oe, list); @@ -245,7 +247,11 @@ return; CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); Lck_Lock(&exp_mtx); - if (update_object_when(o)) { + /* + * The hang-man might have this object of the binheap while + * tending to a timer. If so, we do not muck with it here. + */ + if (oe->timer_idx != BINHEAP_NOIDX && update_object_when(o)) { /* * XXX: this could possibly be optimized by shuffling * XXX: up or down, but that leaves some very nasty @@ -332,8 +338,9 @@ WSL(&ww, SLT_Debug, 0, "Attempt Prefetch %u", o->xid); } + Lck_Lock(&exp_mtx); + assert(oe->timer_idx == BINHEAP_NOIDX); (void)update_object_when(o); - Lck_Lock(&exp_mtx); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); Lck_Unlock(&exp_mtx); @@ -347,6 +354,7 @@ WSL(&ww, SLT_ExpKill, 0, "%u %d", o->xid, (int)(o->ttl - t)); Lck_Lock(&exp_mtx); + assert(oe->timer_idx == BINHEAP_NOIDX); VTAILQ_REMOVE(&lru, o->objexp, list); oe->on_lru = 0; VSL_stats->n_expired++; From phk at projects.linpro.no Tue Feb 3 10:26:02 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Feb 2009 11:26:02 +0100 (CET) Subject: r3566 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include Message-ID: <20090203102602.E87191F7470@projects.linpro.no> Author: phk Date: 2009-02-03 11:26:02 +0100 (Tue, 03 Feb 2009) New Revision: 3566 Added: trunk/varnish-cache/bin/varnishtest/tests/e00013.vtc trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc trunk/varnish-cache/include/stat_field.h Log: Add an (unlocked) counter for number of ESI objects we have parsed. Add two test-cases for objects we should not esi parse. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-02 16:48:28 UTC (rev 3565) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-03 10:26:02 UTC (rev 3566) @@ -630,6 +630,59 @@ return (p); } +/*-------------------------------------------------------------------- + * See if this looks like XML: first non-white char must be '<' + */ + +static int +looks_like_xml(struct object *obj) { + struct storage *st; + unsigned u; + + VTAILQ_FOREACH(st, &obj->store, list) { + AN(st); + for (u = 0; u < st->len; u++) { + if (isspace(st->ptr[u])) + continue; + if (st->ptr[u] == '<') + return (1); + else + return (0); + } + } + return (0); +} + +/*-------------------------------------------------------------------- + * A quick stroll through the object, to find out if it contains any + * esi sequences at all. + */ + +static int +contain_esi(struct object *obj) { + struct storage *st; + unsigned u; + const char *r; + static const char *wanted = "store, list) { + AN(st); + for (u = 0; u < st->len; u++) { + if (st->ptr[u] != *r) { + r = wanted; + continue; + } + if (*++r == '\0') + return (1); + } + } + return (0); +} + /*--------------------------------------------------------------------*/ void @@ -642,6 +695,8 @@ char *p, *q; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + assert(sp->obj->busy); if (sp->cur_method != VCL_MET_FETCH) { /* XXX: we should catch this at compile time */ @@ -653,28 +708,25 @@ if (VTAILQ_EMPTY(&sp->obj->store)) return; - 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; + if (!looks_like_xml(sp->obj)) { WSP(sp, SLT_ESI_xmlerror, - "No ESI processing, " - "binary object: 0x%02x at pos %u.", - st->ptr[u], u); + "No ESI processing, first char not '<'"); return; } } + /* + * Do a fast check to see if there is any 'obj)) + return; + + VSL_stats->esi_parse++; /* XXX: only if GET ? */ ew = eww; memset(eww, 0, sizeof eww); Modified: trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-02 16:48:28 UTC (rev 3565) +++ trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-03 10:26:02 UTC (rev 3566) @@ -22,8 +22,10 @@ sub vcl_fetch { esi; } -} -start -cli "debug.fragfetch 32" +} -start +varnish v1 -cliok "debug.fragfetch 32" + client c1 { txreq -url /foo/bar -hdr "Host: froboz" rxresp Added: trunk/varnish-cache/bin/varnishtest/tests/e00013.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00013.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/e00013.vtc 2009-02-03 10:26:02 UTC (rev 3566) @@ -0,0 +1,25 @@ +# $Id$ + +test "All white-space object, in multiple storage segments" + +server s1 { + rxreq + expect req.url == "/foo" + txresp -hdr "Connection: close" + send { } +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + esi; + } +} -start + +varnish v1 -cliok "debug.fragfetch 4" + +client c1 { + txreq -url /foo + rxresp +} -run + +varnish v1 -expect esi_parse == 0 Added: trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc 2009-02-03 10:26:02 UTC (rev 3566) @@ -0,0 +1,25 @@ +# $Id$ + +test "Check } +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + esi; + } +} -start + +varnish v1 -cliok "debug.fragfetch 4" + +client c1 { + txreq -url /foo + rxresp +} -run + +varnish v1 -expect esi_parse == 0 Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2009-02-02 16:48:28 UTC (rev 3565) +++ trunk/varnish-cache/include/stat_field.h 2009-02-03 10:26:02 UTC (rev 3566) @@ -130,3 +130,5 @@ MAC_STAT(hcb_nolock, uint64_t, 'a', "HCB Lookups without lock") MAC_STAT(hcb_lock, uint64_t, 'a', "HCB Lookups with lock") MAC_STAT(hcb_insert, uint64_t, 'a', "HCB Inserts") + +MAC_STAT(esi_parse, uint64_t, 'a', "Objects ESI parsed (unlock)") From phk at projects.linpro.no Tue Feb 3 10:47:29 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Feb 2009 11:47:29 +0100 (CET) Subject: r3567 - trunk/varnish-cache/bin/varnishd Message-ID: <20090203104729.DBE4A1F70A2@projects.linpro.no> Author: phk Date: 2009-02-03 11:47:29 +0100 (Tue, 03 Feb 2009) New Revision: 3567 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: The esi detector should also spot esi comments. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-03 10:26:02 UTC (rev 3566) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-03 10:47:29 UTC (rev 3567) @@ -615,6 +615,8 @@ { char *p; +printf("{%.*s}\n", Tlen(ew->t), ew->t.b); +usleep(100000); if (params->esi_syntax & 0x4) VSL(SLT_Debug, ew->sp->fd, "Parse: %d <%.*s>", Tlen(ew->t), Tlen(ew->t), ew->t.b); @@ -662,22 +664,26 @@ contain_esi(struct object *obj) { struct storage *st; unsigned u; - const char *r; + const char *r, *r2; static const char *wanted = "store, list) { AN(st); for (u = 0; u < st->len; u++) { if (st->ptr[u] != *r) { r = wanted; - continue; - } - if (*++r == '\0') + } else if (*++r == '\0') return (1); + if (st->ptr[u] != *r2) { + r2 = wanted2; + } else if (*++r2 == '\0') + return (1); } } return (0); From phk at projects.linpro.no Tue Feb 3 10:48:21 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Feb 2009 11:48:21 +0100 (CET) Subject: r3568 - trunk/varnish-cache/bin/varnishd Message-ID: <20090203104821.1D9771F7470@projects.linpro.no> Author: phk Date: 2009-02-03 11:48:20 +0100 (Tue, 03 Feb 2009) New Revision: 3568 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Opps, debugging hack leaked in. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-03 10:47:29 UTC (rev 3567) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-03 10:48:20 UTC (rev 3568) @@ -615,8 +615,6 @@ { char *p; -printf("{%.*s}\n", Tlen(ew->t), ew->t.b); -usleep(100000); if (params->esi_syntax & 0x4) VSL(SLT_Debug, ew->sp->fd, "Parse: %d <%.*s>", Tlen(ew->t), Tlen(ew->t), ew->t.b); From phk at projects.linpro.no Tue Feb 3 12:42:40 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Feb 2009 13:42:40 +0100 (CET) Subject: r3569 - trunk/varnish-cache/bin/varnishd Message-ID: <20090203124240.25AC01F747D@projects.linpro.no> Author: phk Date: 2009-02-03 13:42:39 +0100 (Tue, 03 Feb 2009) New Revision: 3569 Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c Log: Mark that we do limited segment size fetches for debugging Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-03 10:48:20 UTC (rev 3568) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-03 12:42:39 UTC (rev 3569) @@ -221,6 +221,9 @@ struct storage *st; unsigned v; + if (fetchfrag > 0) + WSL(sp->wrk, SLT_Debug, sp->fd, + "Fetch %d byte segments:", fetchfrag); p = NULL; v = 0; st = NULL; From phk at projects.linpro.no Tue Feb 3 12:45:07 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Feb 2009 13:45:07 +0100 (CET) Subject: r3570 - trunk/varnish-cache/bin/varnishd Message-ID: <20090203124507.40A8A1F747D@projects.linpro.no> Author: phk Date: 2009-02-03 13:45:06 +0100 (Tue, 03 Feb 2009) New Revision: 3570 Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/shmlog.c Log: Make it possible (at great performance loss) to force straight time sequencing of shmlog records for debugging purposes. Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2009-02-03 12:42:39 UTC (rev 3569) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2009-02-03 12:45:06 UTC (rev 3570) @@ -745,6 +745,7 @@ #ifdef HAVE_ABORT2 " 0x00008000 - panic to abort2().\n" #endif + " 0x00010000 - synchronize shmlog.\n" "Use 0x notation and do the bitor in your head :-)\n", 0, "0", "bitmap" }, Modified: trunk/varnish-cache/bin/varnishd/shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/shmlog.c 2009-02-03 12:42:39 UTC (rev 3569) +++ trunk/varnish-cache/bin/varnishd/shmlog.c 2009-02-03 12:45:06 UTC (rev 3570) @@ -231,6 +231,8 @@ memcpy(p + SHMLOG_DATA, t.b, l); vsl_hdr(tag, p, l, id); w->wlr++; + if (params->diag_bitmap & 0x10000) + WSL_Flush(w, 0); } /*--------------------------------------------------------------------*/ @@ -269,6 +271,8 @@ w->wlr++; } va_end(ap); + if (params->diag_bitmap & 0x10000) + WSL_Flush(w, 0); } /*--------------------------------------------------------------------*/ From phk at projects.linpro.no Tue Feb 3 12:59:13 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Feb 2009 13:59:13 +0100 (CET) Subject: r3571 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20090203125913.9BCB71F747D@projects.linpro.no> Author: phk Date: 2009-02-03 13:59:13 +0100 (Tue, 03 Feb 2009) New Revision: 3571 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc Log: Update this test to actually test what it should. I suspect a white-space cleanup got it at some point. Modified: trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-03 12:45:06 UTC (rev 3570) +++ trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-03 12:59:13 UTC (rev 3571) @@ -2,17 +2,30 @@ test "ESI spanning storage bits" +# NB! The layout of the body in the response is very carefully +# NB! tuned to give the desired code coverage. +# NB! It should look like this in the varnishlog: +# NB! 7 Debug c "Fetch 32 byte segments:" +# NB! 7 Debug c "%0a%09%09filler%0a%09%09This is before" +# NB! 7 Debug c " the test%0a%09%09%0a%09%09filler%0a%09%09This is a test: Unseen Un" +# NB! 7 Debug c "iversity%0a%09%09Department of cruel a" +# NB! 7 Debug c "nd unjust geography%0a%09%09%0a%09%09This is a test: Hello worl" +# NB! 7 Debug c "d%0a%09" server s1 { rxreq expect req.url == "/foo/bar" txresp -hdr "Connection: close" send { - + filler This is before the test - - + + filler This is a test: Unseen University + Department of cruel and unjust geography This is a test: Hello world } @@ -30,6 +43,7 @@ txreq -url /foo/bar -hdr "Host: froboz" rxresp expect resp.status == 200 + expect resp.bodylen == 120 } client c1 -run From phk at projects.linpro.no Tue Feb 3 17:34:08 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Feb 2009 18:34:08 +0100 (CET) Subject: r3572 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20090203173408.8616697BD1@projects.linpro.no> Author: phk Date: 2009-02-03 18:34:08 +0100 (Tue, 03 Feb 2009) New Revision: 3572 Modified: 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/e00008.vtc trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc Log: Add bodylen expects to the ESI test cases Modified: trunk/varnish-cache/bin/varnishtest/tests/e00001.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00001.vtc 2009-02-03 12:59:13 UTC (rev 3571) +++ trunk/varnish-cache/bin/varnishtest/tests/e00001.vtc 2009-02-03 17:34:08 UTC (rev 3572) @@ -17,12 +17,13 @@ sub vcl_fetch { esi; } -} -start +} -start -cliok "param.set esi_syntax 4" client c1 { txreq rxresp expect resp.status == 200 + expect resp.bodylen == 35 } client c1 -run Modified: trunk/varnish-cache/bin/varnishtest/tests/e00002.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00002.vtc 2009-02-03 12:59:13 UTC (rev 3571) +++ trunk/varnish-cache/bin/varnishtest/tests/e00002.vtc 2009-02-03 17:34:08 UTC (rev 3572) @@ -24,6 +24,7 @@ txreq rxresp expect resp.status == 200 + expect resp.bodylen == 35 } client c1 -run Modified: trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc 2009-02-03 12:59:13 UTC (rev 3571) +++ trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc 2009-02-03 17:34:08 UTC (rev 3572) @@ -27,6 +27,7 @@ client c1 { txreq rxresp + expect resp.bodylen == 65 expect resp.status == 200 } Modified: trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc 2009-02-03 12:59:13 UTC (rev 3571) +++ trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc 2009-02-03 17:34:08 UTC (rev 3572) @@ -28,6 +28,7 @@ txreq rxresp expect resp.status == 200 + expect resp.bodylen == 67 } client c1 -run Modified: trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc 2009-02-03 12:59:13 UTC (rev 3571) +++ trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc 2009-02-03 17:34:08 UTC (rev 3572) @@ -29,6 +29,7 @@ txreq -url /foo/bar rxresp expect resp.status == 200 + expect resp.bodylen == 67 } client c1 -run Modified: trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc 2009-02-03 12:59:13 UTC (rev 3571) +++ trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc 2009-02-03 17:34:08 UTC (rev 3572) @@ -40,6 +40,7 @@ txreq -url /foo/bar -hdr "Host: froboz" rxresp expect resp.status == 200 + expect resp.bodylen == 67 } client c1 -run Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-03 12:59:13 UTC (rev 3571) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-03 17:34:08 UTC (rev 3572) @@ -68,6 +68,7 @@ txreq rxresp expect resp.status == 200 + expect resp.bodylen == 231 } client c1 -run Modified: trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc 2009-02-03 12:59:13 UTC (rev 3571) +++ trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc 2009-02-03 17:34:08 UTC (rev 3572) @@ -31,6 +31,7 @@ txreq rxresp expect resp.status == 200 + expect resp.bodylen == 72 expect resp.http.content-length == 72 } -run @@ -40,5 +41,6 @@ txreq -url bar rxresp expect resp.status == 200 + expect resp.bodylen == 37 expect resp.http.transfer-encoding == "chunked" } -run Modified: trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc 2009-02-03 12:59:13 UTC (rev 3571) +++ trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc 2009-02-03 17:34:08 UTC (rev 3572) @@ -20,6 +20,7 @@ client c1 { txreq -url /foo rxresp + expect resp.bodylen == 49 } -run varnish v1 -expect esi_parse == 0 From phk at projects.linpro.no Tue Feb 3 18:44:21 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Feb 2009 19:44:21 +0100 (CET) Subject: r3573 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include Message-ID: <20090203184421.A85601F7470@projects.linpro.no> Author: phk Date: 2009-02-03 19:44:21 +0100 (Tue, 03 Feb 2009) New Revision: 3573 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 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/e00008.vtc trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc trunk/varnish-cache/bin/varnishtest/tests/e00010.vtc trunk/varnish-cache/bin/varnishtest/tests/e00011.vtc trunk/varnish-cache/bin/varnishtest/tests/e00012.vtc trunk/varnish-cache/bin/varnishtest/tests/e00013.vtc trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc trunk/varnish-cache/include/stat_field.h Log: Add a counter for esi parse errors and test it in all ESI related tests cases. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-03 18:44:21 UTC (rev 3573) @@ -95,6 +95,7 @@ char buf[256], *q; txt t; + VSL_stats->esi_errors++; if (i == 0) i = p - ew->t.b; if (i > 20) { Modified: trunk/varnish-cache/bin/varnishtest/tests/e00000.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00000.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00000.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -24,3 +24,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00001.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00001.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00001.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -27,3 +27,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00002.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00002.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00002.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -28,3 +28,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00003.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -32,3 +32,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00004.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -32,3 +32,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00005.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -33,3 +33,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00006.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -44,3 +44,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -47,3 +47,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -72,3 +72,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 15 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00009.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -44,3 +44,4 @@ expect resp.bodylen == 37 expect resp.http.transfer-encoding == "chunked" } -run +varnish v1 -expect esi_errors == 1 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00010.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00010.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00010.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -25,3 +25,4 @@ expect resp.status == 200 expect resp.bodylen == 21 } -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00011.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00011.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00011.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -34,3 +34,4 @@ expect resp.status == 200 expect resp.bodylen == 31 } -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00012.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00012.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00012.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -44,3 +44,4 @@ expect resp.status == 200 expect resp.bodylen == 151 } -run +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00013.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00013.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00013.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -23,3 +23,4 @@ } -run varnish v1 -expect esi_parse == 0 +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc 2009-02-03 18:44:21 UTC (rev 3573) @@ -24,3 +24,4 @@ } -run varnish v1 -expect esi_parse == 0 +varnish v1 -expect esi_errors == 0 Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2009-02-03 17:34:08 UTC (rev 3572) +++ trunk/varnish-cache/include/stat_field.h 2009-02-03 18:44:21 UTC (rev 3573) @@ -132,3 +132,4 @@ MAC_STAT(hcb_insert, uint64_t, 'a', "HCB Inserts") MAC_STAT(esi_parse, uint64_t, 'a', "Objects ESI parsed (unlock)") +MAC_STAT(esi_errors, uint64_t, 'a', "ESI parse errors (unlock)") From phk at projects.linpro.no Tue Feb 3 21:22:53 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Feb 2009 22:22:53 +0100 (CET) Subject: r3574 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20090203212253.115091F747D@projects.linpro.no> Author: phk Date: 2009-02-03 22:22:52 +0100 (Tue, 03 Feb 2009) New Revision: 3574 Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc Log: Add line numbers to this test, so we can see where it croaks, when it does. Modified: trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-03 18:44:21 UTC (rev 3573) +++ trunk/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-03 21:22:52 UTC (rev 3574) @@ -5,42 +5,42 @@ server s1 { rxreq txresp -body { - - Before include - - After include - - - - foo - - - - - - - - - - bar - - - - - - 1 + Before include 2 + 3 + After include 4 + 5 + 6 + 7 + foo 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + bar 18 + 19 + 20 + 21 + 22 + 23 + - - - - - - - - 33 + 34 } rxreq expect req.url == "/body" @@ -62,14 +62,18 @@ sub vcl_fetch { esi; } -} -start +} -start +varnish v1 -cliok "param.set esi_syntax 6" + +varnish v1 -cliok "param.set diag_bitmap 0x10000" + client c1 { txreq rxresp expect resp.status == 200 - expect resp.bodylen == 231 + expect resp.bodylen == 385 } client c1 -run -varnish v1 -expect esi_errors == 15 +varnish v1 -expect esi_errors == 14 From phk at projects.linpro.no Tue Feb 3 21:49:26 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 3 Feb 2009 22:49:26 +0100 (CET) Subject: r3575 - trunk/varnish-cache/bin/varnishd Message-ID: <20090203214926.ACEFD1F7470@projects.linpro.no> Author: phk Date: 2009-02-03 22:49:26 +0100 (Tue, 03 Feb 2009) New Revision: 3575 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Overhaul the ESI parser in light of #433 and the prospect of future addition of features to the ESI code. The particular situation in #433 arises because a XML comment is not bounded in length, the same way as an element naturally is. This opens the window for trouble when large sections of XML is commented out for some reason or another. Bite the bullet and create a "storage-pointer" consisting of a pointer to a storage segment and a pointer into that segment. Add a main-loop which uses these pointers to walks over the entire object, looking for stuff we care about, and handle each appropriately. In addition to coping properly with the situation in #433, this code is also close to 100 lines shorter and has a more logical structure. The downside is that it is isn't quite as memory-access-alergic as the previous version. (I challenge anybody to measure the effect of this.) Fixes: #433 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-03 21:22:52 UTC (rev 3574) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-03 21:49:26 UTC (rev 3575) @@ -69,23 +69,83 @@ VTAILQ_HEAD(esibithead, esi_bit); +struct esi_ptr { + const char *p; + struct storage *st; +}; + struct esi_work { struct sess *sp; size_t off; + + struct esi_ptr s; + struct esi_ptr p; + + txt tag; + txt t; - txt o; - txt dst; struct esi_bit *eb; struct esi_bit *ebl; /* list of */ int neb; - int is_esi; int remflg; /* inside */ int incmt; /* inside comment */ - int incdata; /* inside */ }; /*-------------------------------------------------------------------- + * Move the parse-pointer forward. + */ + +static void +Nep(struct esi_ptr *ep) +{ + static const char * const finis = ""; + + if (ep->p == finis) + return; + ep->p++; + if (ep->p < (char*)ep->st->ptr + ep->st->len) + return; + ep->st = VTAILQ_NEXT(ep->st, list); + if (ep->st != NULL) { + ep->p = (char *)ep->st->ptr; + return; + } + ep->p = finis; + return; +} + +static void +N(struct esi_work *ew) +{ + + if (*ew->p.p != '\0') + ew->off++; + Nep(&ew->p); +} + +/*-------------------------------------------------------------------- + * Strcmp for objects pointers + */ + +static int +CMP(const struct esi_ptr *ep, const char *str) +{ + struct esi_ptr p2; + + for (p2 = *ep; *str == *p2.p; str++) + Nep(&p2); + return (*str); +} + + +/*-------------------------------------------------------------------- * Report a parsing error + * + * XXX: The "at xxx" count is usually the tail of the sequence. Since we + * XXX: wander over the storage in an oderly manner now, we could keep + * XXX: track of line+pos and record the beginning of the stuff that + * XXX: offends os in the central dispatch loop. + * XXX: This is left a an excercise for the reader. */ static void @@ -103,7 +163,7 @@ ellipsis = 1; } q = buf; - q += sprintf(buf, "at %zd: %s \"", ew->off + (p - ew->t.b), err); + q += sprintf(buf, "at %zu: %s \"", ew->off, err); while (i > 0) { if (*p >= ' ' && *p <= '~') { *q++ = *p; @@ -141,8 +201,8 @@ * Add ESI bit to object */ -static struct esi_bit * -esi_addbit(struct esi_work *ew) +static void +esi_addbit(struct esi_work *ew, const char *verbatim, unsigned len) { if (ew->neb == 0) { @@ -157,29 +217,41 @@ VTAILQ_INSERT_TAIL(&ew->sp->obj->esibits, ew->eb, list); - ew->eb->verbatim = ew->dst; - sprintf(ew->eb->chunk_length, "%x\r\n", Tlen(ew->dst)); - if (params->esi_syntax & 0x4) - VSL(SLT_Debug, ew->sp->fd, "AddBit: %d <%.*s>", - Tlen(ew->dst), Tlen(ew->dst), ew->dst.b); - return(ew->eb); + if (verbatim != NULL) { + ew->eb->verbatim.b = TRUST_ME(verbatim); + if (len > 0) + ew->eb->verbatim.e = TRUST_ME(verbatim + len); + sprintf(ew->eb->chunk_length, "%x\r\n", Tlen(ew->eb->verbatim)); + if (params->esi_syntax & 0x4) + VSL(SLT_Debug, ew->sp->fd, "AddBit: %d <%.*s>", + Tlen(ew->eb->verbatim), + Tlen(ew->eb->verbatim), + ew->eb->verbatim.b); + } else + ew->eb->verbatim.b = ew->eb->verbatim.e = (void*)ew->eb; } +/*--------------------------------------------------------------------*/ -/*-------------------------------------------------------------------- - * Add verbatim piece to output - */ - static void -esi_addverbatim(struct esi_work *ew) +esi_addpfx(struct esi_work *ew) { + const char *ep; - if (params->esi_syntax & 0x4) - VSL(SLT_Debug, ew->sp->fd, "AddVer: %d <%.*s>", - Tlen(ew->o), Tlen(ew->o), ew->o.b); - if (ew->o.b != ew->dst.e) - memmove(ew->dst.e, ew->o.b, Tlen(ew->o)); - ew->dst.e += Tlen(ew->o); + if (ew->remflg) { + /* In don't add anything */ + ew->s = ew->p; + return; + } + while (ew->s.st != ew->p.st) { + ep = (const char *)(ew->s.st->ptr + ew->s.st->len); + esi_addbit(ew, ew->s.p, ep - ew->s.p); + ew->s.p = ep; + Nep(&ew->s); + } + if (ew->s.st != NULL && ew->p.p != ew->s.p) + esi_addbit(ew, ew->s.p, ew->p.p - ew->s.p); + ew->s.p = ew->p.p; } /*-------------------------------------------------------------------- @@ -274,17 +346,20 @@ */ static void -esi_addinclude(struct esi_work *ew, txt t) +esi_handle_include(struct esi_work *ew) { struct esi_bit *eb; char *p, *q; + txt t = ew->tag; txt tag; txt val; unsigned u, v; struct ws *ws; + if (ew->eb == NULL || ew->eb->include.b != NULL) + esi_addbit(ew, NULL, 0); + eb = ew->eb; VSL(SLT_Debug, ew->sp->fd, "Incl \"%.*s\"", t.e - t.b, t.b); - eb = esi_addbit(ew); while (esi_attrib(ew, &t, &tag, &val) == 1) { if (params->esi_syntax & 0x4) VSL(SLT_Debug, ew->sp->fd, "<%.*s> -> <%.*s>", @@ -353,290 +428,11 @@ } /*-------------------------------------------------------------------- - * Zoom over a piece of object and dike out all releveant esi: pieces. - * The entire txt may not be processed because an interesting part - * could possibly span into the next chunk of storage. - * Return value: number of bytes processed. - */ - -static char * -esi_parse2(struct esi_work *ew) -{ - char *p, *q, *r; - txt t; - int celem; /* closing element */ - int i; - - t = ew->t; - ew->dst.b = t.b; - ew->dst.e = t.b; - ew->o.b = t.b; - ew->o.e = t.b; - for (p = t.b; p < t.e; ) { - assert(p >= t.b); - assert(p < t.e); - if (ew->incdata) { - /* - * We are inside an . - */ - if (*p != ']') { - p++; - } else { - if (p + 2 >= t.e) - return (p); - if (!memcmp(p, "]]>", 3)) { - ew->incdata = 0; - p += 3; - } else - p++; - } - continue; - } - if (ew->incmt && *p == '-') { - /* - * We are inside an when we see it. - */ - if (p + 2 >= t.e) - return (p); - if (!memcmp(p, "-->", 3)) { - ew->incmt = 0; - ew->o.e = p; - esi_addverbatim(ew); - p += 3; - ew->o.b = p; - } else - p++; - continue; - } - - if (*p != '<') { - /* nothing happens until next element or comment */ - p++; - continue; - } - - i = t.e - p; - - if (i < 2) - return (p); - - if (ew->remflg == 0 && !memcmp(p, " - * at least 10 char, but we only test on the - * first seven because the tail is handled - * by the ew->incmt flag. - */ - ew->is_esi++; - if (i < 7) - return (p); - - ew->o.e = p; - esi_addverbatim(ew); - - p += 7; - ew->o.b = p; - ew->incmt = 1; - continue; - } - - if (!memcmp(p, " at least 7 char - */ - if (i < 7) - return (p); - for (q = p + 4; ; q++) { - if (q + 2 >= t.e) - return (p); - if (!memcmp(q, "-->", 3)) - break; - } - p = q + 3; - continue; - } - - if (!memcmp(p, " 9 ? 9 : i)) { - /* - * cdata incdata = 1; - p += 9; - continue; - } - - /* Ignore non esi elements, if so instructed */ - if ((params->esi_syntax & 0x02)) { - if (memcmp(p, " 5 ? 5 : i) && - memcmp(p, " 6 ? 6 : i)) { - p += 1; - continue; - } - if (i < 6) - return (p); - } - - /* Find end of this element */ - for (q = p + 1; q < t.e && *q != '>'; q++) - continue; - if (q >= t.e || *q != '>') - return (p); - - /* Opening/empty or closing element ? */ - if (p[1] == '/') { - celem = 1; - r = p + 2; - if (q[-1] == '/') { - esi_error(ew, p, 1 + q - p, - "XML 1.0 empty and closing element"); - } - } else { - celem = 0; - r = p + 1; - } - - if (params->esi_syntax & 0x4) - VSL(SLT_Debug, ew->sp->fd, "Element: clos=%d [%.*s]", - celem, q - r, r); - - if (r + 9 < q && !memcmp(r, "esi:remove", 10)) { - - ew->is_esi++; - - if (celem != ew->remflg) { - /* - * ESI 1.0 violation, ignore element - */ - esi_error(ew, p, 1 + q - p, ew->remflg ? - "ESI 1.0 forbids nested esi:remove" - : "ESI 1.0 esi:remove not opened"); - - if (!ew->remflg) { - ew->o.e = p; - esi_addverbatim(ew); - } - } else if (!celem && q[-1] == '/') { - /* empty element */ - ew->o.e = p; - esi_addverbatim(ew); - } else if (!celem) { - /* open element */ - ew->o.e = p; - esi_addverbatim(ew); - ew->remflg = !celem; - } else { - /* close element */ - ew->remflg = !celem; - } - p = q + 1; - ew->o.b = p; - continue; - } - - if (ew->remflg && r + 3 < q && !memcmp(r, "esi:", 4)) { - /* - * ESI 1.0 violation, no esi: elements in esi:remove - */ - esi_error(ew, p, 1 + q - p, - "ESI 1.0 forbids esi: elements inside esi:remove"); - p = q + 1; - continue; - } - ew->is_esi++; - - if (r + 10 < q && !memcmp(r, "esi:comment", 11)) { - - ew->o.e = p; - esi_addverbatim(ew); - - if (celem == 1) { - esi_error(ew, p, 1 + q - p, - "ESI 1.0 closing esi:comment illegal"); - } else if (q[-1] != '/') { - esi_error(ew, p, 1 + q - p, - "ESI 1.0 wants empty esi:comment"); - } - p = q + 1; - ew->o.b = p; - continue; - } - if (r + 10 < q && !memcmp(r, "esi:include", 11)) { - - ew->o.e = p; - esi_addverbatim(ew); - - if (celem == 0) { - ew->o.b = r + 11; - if (q[-1] != '/') { - esi_error(ew, p, 1 + q - p, - "ESI 1.0 wants empty esi:include"); - ew->o.e = q; - } else { - ew->o.e = q - 1; - } - esi_addinclude(ew, ew->o); - ew->dst.b = q + 1; - ew->dst.e = q + 1; - } else { - esi_error(ew, p, 1 + q - p, - "ESI 1.0 closing esi:include illegal"); - } - p = q + 1; - ew->o.b = p; - continue; - } - - if (r + 3 < q && !memcmp(r, "esi:", 4)) { - /* - * Unimplemented ESI element, ignore - */ - esi_error(ew, p, 1 + q - p, - "ESI 1.0 unimplemented element"); - ew->o.e = p; - esi_addverbatim(ew); - p = q + 1; - ew->o.b = p; - continue; - } - - /* Not an element we care about */ - assert(q < t.e); - p = q + 1; - } - assert(p == t.e); - return (p); -} - -static char * -esi_parse(struct esi_work *ew) -{ - char *p; - - if (params->esi_syntax & 0x4) - VSL(SLT_Debug, ew->sp->fd, "Parse: %d <%.*s>", - Tlen(ew->t), Tlen(ew->t), ew->t.b); - p = esi_parse2(ew); - assert(ew->o.b >= ew->t.b); - assert(ew->o.e <= ew->t.e); - ew->o.e = p; - if (Tlen(ew->o) && !ew->remflg) - esi_addverbatim(ew); - if (Tlen(ew->dst)) - esi_addbit(ew); - ew->off += (p - ew->t.b); - return (p); -} - -/*-------------------------------------------------------------------- * See if this looks like XML: first non-white char must be '<' */ static int -looks_like_xml(struct object *obj) { +looks_like_xml(const struct object *obj) { struct storage *st; unsigned u; @@ -660,12 +456,12 @@ */ static int -contain_esi(struct object *obj) { +contain_esi(const struct object *obj) { struct storage *st; unsigned u; const char *r, *r2; - static const char *wanted = "incmt); + ew->incmt = 1; + ew->s.p = ew->p.p; +} + +/*--------------------------------------------------------------------*/ + +static void +parse_comment(struct esi_work *ew) +{ + + do { + N(ew); + if (*ew->p.p == '-' && !CMP(&ew->p, "-->")) { + N(ew); + N(ew); + N(ew); + break; + } + } while (*ew->p.p != '\0'); +} + +/*--------------------------------------------------------------------*/ + +static void +parse_cdata(struct esi_work *ew) +{ + + esi_addpfx(ew); + + do { + N(ew); + if (*ew->p.p == ']' && !CMP(&ew->p, "]]>")) { + N(ew); + N(ew); + N(ew); + break; + } + } while (*ew->p.p != '\0'); +} + +/*--------------------------------------------------------------------*/ + +static void +parse_esi_tag(struct esi_work *ew, int closing) +{ + int l, ll, empty; + struct esi_ptr px; + char *q; + + esi_addpfx(ew); + + do + N(ew); + while (*ew->p.p != '>' && *ew->p.p != '\0'); + if (*ew->p.p == '\0') { + esi_addpfx(ew); + esi_error(ew, ew->s.p, 0, + "XML 1.0 incomplete language element"); + return; + } + N(ew); + + if (ew->p.st == ew->s.st) { + ew->tag.b = TRUST_ME(ew->s.p); + ew->tag.e = TRUST_ME(ew->p.p); + } else { + /* + * The element is spread over more than one storage + * segment, pull it together in the object workspace + * XXX: Ideally, we should only pull together the bits + * XXX: we need, like the filename. + */ + ew->tag.b = ew->sp->obj->ws_o->f; + ew->tag.e = ew->tag.b + WS_Reserve(ew->sp->obj->ws_o, 0); + px = ew->s; + q = ew->tag.b; + while (px.p != ew->p.p) { + xxxassert(q < ew->tag.e); + *q++ = *px.p; + Nep(&px); + } + ew->tag.e = q; + WS_Release(ew->sp->obj->ws_o, Tlen(ew->tag)); + } + ll = Tlen(ew->tag); + ew->tag.b++; + ew->tag.e--; + empty = (ew->tag.e[-1] == '/') ? 1 : 0; + if (empty) + ew->tag.e--; + + if (empty && closing) + esi_error(ew, ew->s.p, ll, + "XML 1.0 empty and closing element"); + + ew->tag.b += 4 + (closing ? 1 : 0); + l = Tlen(ew->tag); + VSL(SLT_Debug, ew->sp->fd, + "tag {%.*s} %d %d %d", l, ew->tag.b, ew->remflg, empty, closing); + if (l >= 6 && !memcmp(ew->tag.b, "remove", 6)) { + if (empty) { + /* XXX ?? */ + } else if (closing) { + if (!ew->remflg) + esi_error(ew, ew->s.p, ll, + "ESI 1.0 esi:remove not opened"); + ew->remflg = 0; + } else { + if (ew->remflg) + esi_error(ew, ew->s.p, ll, + "ESI 1.0 forbids nested esi:remove"); + ew->remflg = 1; + } + } else if (ew->remflg) { + esi_error(ew, ew->s.p, ll, + "ESI 1.0 forbids esi: elements inside esi:remove"); + } else if (l >= 7 && !memcmp(ew->tag.b, "comment", 7)) { + if (closing) + esi_error(ew, ew->s.p, ll, + "ESI 1.0 closing esi:comment illegal"); + else if (!empty) + esi_error(ew, ew->s.p, ll, + "ESI 1.0 wants empty esi:comment"); + } else if (l >= 7 && !memcmp(ew->tag.b, "include", 7)) { + if (closing) { + esi_error(ew, ew->s.p, ll, + "ESI 1.0 closing esi:include illegal"); + } else if (!empty) { + esi_error(ew, ew->s.p, ll, + "ESI 1.0 wants empty esi:include"); + } + ew->tag.b += 7; + esi_handle_include(ew); + } else { + esi_error(ew, ew->s.p, ll, + "ESI 1.0 unimplemented element"); + } + ew->s = ew->p; +} + +/*--------------------------------------------------------------------*/ + void VRT_ESI(struct sess *sp) { - struct storage *st, *st2; struct esi_work *ew, eww[1]; - txt t; - unsigned u; - char *p, *q; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); @@ -738,87 +680,55 @@ ew->sp = sp; ew->off = 1; - p = NULL; - VTAILQ_FOREACH(st, &sp->obj->store, list) { - if (p != NULL) { - assert ((void*)p > (void *)st->ptr); - assert ((void*)p <= (void *)(st->ptr + st->len)); - if (p == (void*)(st->ptr + st->len)) - break; - ew->t.b = p; - p = NULL; - } else - ew->t.b = (void *)st->ptr; - ew->t.e = (void *)(st->ptr + st->len); - p = esi_parse(ew); - if (p == ew->t.e) { - p = NULL; - continue; - } + ew->p.st = VTAILQ_FIRST(&sp->obj->store); + AN(ew->p.st); + ew->p.p = (char *)ew->p.st->ptr; - if (VTAILQ_NEXT(st, list) == NULL) { - /* - * XXX: illegal XML input, but did we handle - * XXX: all of it, or do we leave the final - * XXX: element dangling ? - */ - esi_error(ew, p, ew->t.e -p, - "XML 1.0 incomplete language element"); - ew->dst.b = p; - ew->dst.e = ew->t.e; - esi_addbit(ew); - break; - } + /* ->s points to the first un-dealt-with byte */ + ew->s = ew->p; - /* Move remainder to workspace */ - u = ew->t.e - p; - t.b = sp->obj->ws_o->f; - t.e = t.b + WS_Reserve(sp->obj->ws_o, 0); - if (t.b + u >= t.e) { - esi_error(ew, p, ew->t.e - p, - "XML 1.0 unreasonably long element"); - WS_Release(sp->obj->ws_o, 0); - ew->dst.b = p; - ew->dst.e = ew->t.e; - esi_addbit(ew); - p = NULL; + while (*ew->p.p != '\0') { + + if (ew->incmt && *ew->p.p == '-' && !CMP(&ew->p, "-->")) { + /* End of ESI comment */ + esi_addpfx(ew); + N(ew); + N(ew); + N(ew); + ew->s = ew->p; + ew->incmt = 0; continue; } - assert(t.e > t.b + u); /* XXX incredibly long element ? */ - memcpy(t.b, p, u); + /* Skip forward to the first '<' */ + if (*ew->p.p != '<') { + N(ew); + continue; + } - /* Peel start off next chunk, until and including '<' */ - st2 = VTAILQ_NEXT(st, list); - AN(st2); - q = t.b + u; - p = (void*)st2->ptr; - while (1) { - if (p >= (char *)st2->ptr + st2->len || q >= t.e) { - esi_error(ew, t.b, q - t.b, - "XML 1.0 unreasonably long element"); - WS_Release(sp->obj->ws_o, 0); - ew->dst.b = t.b; - ew->dst.e = q; - esi_addbit(ew); - p = NULL; - break; + if (!CMP(&ew->p, " +The end. +} + +} -start + +server s2 -listen 127.0.0.1:9082 { + rxreq + expect req.url == "/bar" + txresp -body "bar" +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.url == "/foo") { + set req.backend = s1; + } else { + set req.backend = s2; + } + } + + sub vcl_fetch { + esi; + } +} -start + +varnish v1 -cliok "param.set esi_syntax 4" +varnish v1 -cliok "param.set diag_bitmap 0x10000" +varnish v1 -cliok "debug.fragfetch 32" + +client c1 { + txreq -url /foo + rxresp +} -run From tfheen at projects.linpro.no Thu Feb 5 08:25:16 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 09:25:16 +0100 (CET) Subject: r3577 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205082516.545841F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-05 09:25:16 +0100 (Thu, 05 Feb 2009) New Revision: 3577 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c Log: Merge r3312: Allow "true" and "false" as settings for booleans Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-03 21:49:47 UTC (rev 3576) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 08:25:16 UTC (rev 3577) @@ -122,12 +122,16 @@ *dest = 0; else if (!strcasecmp(arg, "no")) *dest = 0; + else if (!strcasecmp(arg, "false")) + *dest = 0; else if (!strcasecmp(arg, "on")) *dest = 1; else if (!strcasecmp(arg, "enable")) *dest = 1; else if (!strcasecmp(arg, "yes")) *dest = 1; + else if (!strcasecmp(arg, "true")) + *dest = 1; else { cli_out(cli, "use \"on\" or \"off\"\n"); cli_result(cli, CLIS_PARAM); From tfheen at projects.linpro.no Thu Feb 5 08:33:14 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 09:33:14 +0100 (CET) Subject: r3578 - branches/2.0/varnish-cache/redhat Message-ID: <20090205083314.BA9F01F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-05 09:33:14 +0100 (Thu, 05 Feb 2009) New Revision: 3578 Modified: branches/2.0/varnish-cache/redhat/varnish.spec Log: Merge r3313: spec file updates Fix up the spec file so it actually includes the workaround for make check on ppc64. Original commit message: * Thu Oct 16 2008 Ingvar Hagelund - 2.0-2 - Readded the debugflag patch. It's so practical - Added a strange workaround for make check on ppc64 Modified: branches/2.0/varnish-cache/redhat/varnish.spec =================================================================== --- branches/2.0/varnish-cache/redhat/varnish.spec 2009-02-05 08:25:16 UTC (rev 3577) +++ branches/2.0/varnish-cache/redhat/varnish.spec 2009-02-05 08:33:14 UTC (rev 3578) @@ -122,6 +122,13 @@ %endif %check +# rhel5 on ppc64 is just too strange +%ifarch ppc64 + %if 0%{?rhel} > 4 + cp bin/varnishd/.libs/varnishd bin/varnishd/lt-varnishd + %endif +%endif + LD_LIBRARY_PATH="lib/libvarnish/.libs:lib/libvarnishcompat/.libs:lib/libvarnishapi/.libs:lib/libvcl/.libs" bin/varnishd/varnishd -b 127.0.0.1:80 -C -n /tmp/foo %{__make} check LD_LIBRARY_PATH="../../lib/libvarnish/.libs:../../lib/libvarnishcompat/.libs:../../lib/libvarnishapi/.libs:../../lib/libvcl/.libs" From tfheen at projects.linpro.no Thu Feb 5 08:37:41 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 09:37:41 +0100 (CET) Subject: r3579 - branches/2.0/varnish-cache/lib/libvcl Message-ID: <20090205083741.539B61F74BE@projects.linpro.no> Author: tfheen Date: 2009-02-05 09:37:41 +0100 (Thu, 05 Feb 2009) New Revision: 3579 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c Log: Merge r3318: Check that regexps are constant strings. Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-05 08:33:14 UTC (rev 3578) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-05 08:37:41 UTC (rev 3579) @@ -250,6 +250,7 @@ switch (tl->t->tok) { case '~': vcc_NextToken(tl); + ExpectErr(tl, CSTR); p = vcc_regexp(tl, 0); ERRCHK(tl); vcc_NextToken(tl); From tfheen at projects.linpro.no Thu Feb 5 08:45:26 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 09:45:26 +0100 (CET) Subject: r3580 - in branches/2.0/varnish-cache: bin/varnishadm bin/varnishd bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishstat bin/varnishtest bin/varnishtop include lib/libvarnish lib/libvarnishapi lib/libvcl Message-ID: <20090205084526.0585597BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 09:45:25 +0100 (Thu, 05 Feb 2009) New Revision: 3580 Modified: branches/2.0/varnish-cache/bin/varnishadm/varnishadm.c branches/2.0/varnish-cache/bin/varnishd/Makefile.am branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.h branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_ports.c branches/2.0/varnish-cache/bin/varnishd/cache_backend.c branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/cache_cli.c branches/2.0/varnish-cache/bin/varnishd/cache_dir_random.c branches/2.0/varnish-cache/bin/varnishd/cache_dir_round_robin.c branches/2.0/varnish-cache/bin/varnishd/cache_dir_simple.c branches/2.0/varnish-cache/bin/varnishd/cache_expire.c branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/cache_http.c branches/2.0/varnish-cache/bin/varnishd/cache_httpconn.c branches/2.0/varnish-cache/bin/varnishd/cache_panic.c branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c branches/2.0/varnish-cache/bin/varnishd/cache_pool.c branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c branches/2.0/varnish-cache/bin/varnishd/default.vcl branches/2.0/varnish-cache/bin/varnishd/hash_classic.c branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h branches/2.0/varnish-cache/bin/varnishd/heritage.h branches/2.0/varnish-cache/bin/varnishd/mgt_child.c branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c branches/2.0/varnish-cache/bin/varnishd/mgt_param.c branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c branches/2.0/varnish-cache/bin/varnishd/shmlog.c branches/2.0/varnish-cache/bin/varnishd/stevedore.c branches/2.0/varnish-cache/bin/varnishd/storage_file.c branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c branches/2.0/varnish-cache/bin/varnishd/storage_umem.c branches/2.0/varnish-cache/bin/varnishd/varnishd.c branches/2.0/varnish-cache/bin/varnishhist/varnishhist.c branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c branches/2.0/varnish-cache/bin/varnishncsa/varnishncsa.c branches/2.0/varnish-cache/bin/varnishreplay/varnishreplay.c branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c branches/2.0/varnish-cache/bin/varnishtest/vtc.c branches/2.0/varnish-cache/bin/varnishtest/vtc.h branches/2.0/varnish-cache/bin/varnishtest/vtc_client.c branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c branches/2.0/varnish-cache/bin/varnishtest/vtc_log.c branches/2.0/varnish-cache/bin/varnishtest/vtc_sema.c branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c branches/2.0/varnish-cache/bin/varnishtest/vtc_varnish.c branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c branches/2.0/varnish-cache/include/cli.h branches/2.0/varnish-cache/include/http_headers.h branches/2.0/varnish-cache/include/libvarnish.h branches/2.0/varnish-cache/include/stat_field.h branches/2.0/varnish-cache/include/varnishapi.h branches/2.0/varnish-cache/include/vcl.h branches/2.0/varnish-cache/include/vcl_returns.h branches/2.0/varnish-cache/include/vct.h branches/2.0/varnish-cache/include/vev.h branches/2.0/varnish-cache/include/vqueue.h branches/2.0/varnish-cache/include/vrt.h branches/2.0/varnish-cache/include/vsb.h branches/2.0/varnish-cache/lib/libvarnish/assert.c branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c branches/2.0/varnish-cache/lib/libvarnish/cli_common.c branches/2.0/varnish-cache/lib/libvarnish/num.c branches/2.0/varnish-cache/lib/libvarnish/tcp.c branches/2.0/varnish-cache/lib/libvarnish/vct.c branches/2.0/varnish-cache/lib/libvarnish/version.c branches/2.0/varnish-cache/lib/libvarnish/vlu.c branches/2.0/varnish-cache/lib/libvarnish/vss.c branches/2.0/varnish-cache/lib/libvarnishapi/instance.c branches/2.0/varnish-cache/lib/libvarnishapi/shmlog.c branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c branches/2.0/varnish-cache/lib/libvcl/vcc_action.c branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h branches/2.0/varnish-cache/lib/libvcl/vcc_dir_random.c branches/2.0/varnish-cache/lib/libvcl/vcc_dir_round_robin.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c branches/2.0/varnish-cache/lib/libvcl/vcc_priv.h branches/2.0/varnish-cache/lib/libvcl/vcc_string.c branches/2.0/varnish-cache/lib/libvcl/vcc_token.c branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c Log: Merge r3324: White-space commit from hell. I need a printout for a code-walkthrough and this commit wraps lines, removes trailing space, space before TAB and other iregularities. Some generated files have been compacted a bit. A few changes to comments along the way. Modified: branches/2.0/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishadm/varnishadm.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishadm/varnishadm.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -90,14 +90,16 @@ exit(1); } if (!(p = strchr(buf, ' '))) { - fprintf(stderr, "An error occured in parsing of status code.\n"); + fprintf(stderr, + "An error occured in parsing of status code.\n"); exit(1); } *p = '\0'; status = strtol(buf, &p, 10); pp = p+1; if (!(p = strchr(pp, '\n'))) { - fprintf(stderr, "An error occured in parsing of number of bytes returned.\n"); + fprintf(stderr, "An error occured " + "in parsing of number of bytes returned.\n"); exit(1); } *p = '\0'; Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-05 08:45:25 UTC (rev 3580) @@ -89,7 +89,7 @@ # Turn the default.vcl file into a C-string we can include in the program. # default_vcl.h: default.vcl Makefile - sed -e 's/"/\\"/g' -e 's/$$/\\n"/' -e 's/^/ "/' $(srcdir)/default.vcl > $@ + sed -e 's/"/\\"/g' -e 's/$$/\\n"/' -e 's/^/ "/' $(srcdir)/default.vcl > $@ # Explicitly record dependency mgt_vcc.c: default_vcl.h Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -135,11 +135,11 @@ struct ws *ws; unsigned char conds; /* If-* headers present */ - enum httpwhence logtag; + enum httpwhence logtag; int status; double protover; - txt hd[HTTP_HDR_MAX]; + txt hd[HTTP_HDR_MAX]; unsigned char hdf[HTTP_HDR_MAX]; #define HDF_FILTER (1 << 0) /* Filtered by Connection */ unsigned nhd; @@ -246,7 +246,7 @@ struct object { unsigned magic; #define OBJECT_MAGIC 0x32851d42 - unsigned refcnt; + unsigned refcnt; unsigned xid; struct objhead *objhead; struct storage *objstore; @@ -349,7 +349,7 @@ enum step step; unsigned cur_method; - unsigned handling; + unsigned handling; unsigned char sendbody; unsigned char wantbody; int err_code; @@ -465,25 +465,32 @@ void http_ClrHeader(struct http *to); unsigned http_Write(struct worker *w, const struct http *hp, int resp); void http_CopyResp(struct http *to, const struct http *fm); -void http_SetResp(struct http *to, const char *proto, const char *status, const char *response); -void http_FilterFields(struct worker *w, int fd, struct http *to, const struct http *fm, unsigned how); +void http_SetResp(struct http *to, const char *proto, const char *status, + const char *response); +void http_FilterFields(struct worker *w, int fd, struct http *to, + const struct http *fm, unsigned how); void http_FilterHeader(struct sess *sp, unsigned how); -void http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol); +void http_PutProtocol(struct worker *w, int fd, struct http *to, + const char *protocol); void http_PutStatus(struct worker *w, int fd, struct http *to, int status); -void http_PutResponse(struct worker *w, int fd, struct http *to, const char *response); -void http_PrintfHeader(struct worker *w, int fd, struct http *to, const char *fmt, ...); +void http_PutResponse(struct worker *w, int fd, struct http *to, + const char *response); +void http_PrintfHeader(struct worker *w, int fd, struct http *to, + const char *fmt, ...); void http_SetHeader(struct worker *w, int fd, struct http *to, const char *hdr); void http_SetH(struct http *to, unsigned n, const char *fm); void http_ForceGet(struct http *to); void http_Setup(struct http *ht, struct ws *ws); int http_GetHdr(const struct http *hp, const char *hdr, char **ptr); -int http_GetHdrField(const struct http *hp, const char *hdr, const char *field, char **ptr); +int http_GetHdrField(const struct http *hp, const char *hdr, + const char *field, char **ptr); int http_GetStatus(const struct http *hp); const char *http_GetReq(const struct http *hp); const char *http_GetProto(const struct http *hp); int http_HdrIs(const struct http *hp, const char *hdr, const char *val); int http_DissectRequest(struct sess *sp); -int http_DissectResponse(struct worker *w, const struct http_conn *htc, struct http *sp); +int http_DissectResponse(struct worker *w, const struct http_conn *htc, + struct http *sp); const char *http_DoConnection(struct http *hp); void http_CopyHome(struct worker *w, int fd, struct http *hp); void http_Unset(struct http *hp, const char *hdr); @@ -538,21 +545,23 @@ void WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...); void WSL_Flush(struct worker *w, int overflow); -#define DSL(flag, tag, id, ...) \ +#define DSL(flag, tag, id, ...) \ do { \ if (params->diag_bitmap & (flag)) \ VSL((tag), (id), __VA_ARGS__); \ } while (0) -#define WSP(sess, tag, ...) \ +#define WSP(sess, tag, ...) \ WSL((sess)->wrk, tag, (sess)->fd, __VA_ARGS__) -#define WSPR(sess, tag, txt) \ +#define WSPR(sess, tag, txt) \ WSLR((sess)->wrk, tag, (sess)->fd, txt) #define INCOMPL() do { \ VSL(SLT_Debug, 0, "INCOMPLETE AT: %s(%d)", __func__, __LINE__); \ - fprintf(stderr,"INCOMPLETE AT: %s(%d)\n", (const char *)__func__, __LINE__); \ + fprintf(stderr, \ + "INCOMPLETE AT: %s(%d)\n", \ + (const char *)__func__, __LINE__); \ abort(); \ } while (0) #endif @@ -616,10 +625,10 @@ __func__, __FILE__, __LINE__, (r)); \ } \ } while (0) -#define LOCK(foo) \ -do { \ +#define LOCK(foo) \ +do { \ if (!(params->diag_bitmap & 0x18)) { \ - AZ(pthread_mutex_lock(foo)); \ + AZ(pthread_mutex_lock(foo)); \ } else { \ int ixjd = pthread_mutex_trylock(foo); \ assert(ixjd == 0 || ixjd == EBUSY); \ @@ -627,11 +636,11 @@ VSL(SLT_Debug, 0, \ "MTX_CONTEST(%s,%s,%d," #foo ")", \ __func__, __FILE__, __LINE__); \ - AZ(pthread_mutex_lock(foo)); \ + AZ(pthread_mutex_lock(foo)); \ } else if (params->diag_bitmap & 0x8) { \ VSL(SLT_Debug, 0, \ "MTX_LOCK(%s,%s,%d," #foo ")", \ - __func__, __FILE__, __LINE__); \ + __func__, __FILE__, __LINE__); \ } \ } \ } while (0) Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -28,9 +28,6 @@ * * $Id$ * - * XXX: We need to pass sessions back into the event engine when they are - * reused. Not sure what the most efficient way is for that. For now - * write the session pointer to a pipe which the event engine monitors. */ #include "config.h" @@ -68,7 +65,7 @@ static struct acceptor *vca_act; -static pthread_t vca_thread_acct; +static pthread_t vca_thread_acct; static struct timeval tv_sndtimeo; static struct timeval tv_rcvtimeo; static struct linger linger; @@ -227,12 +224,15 @@ break; case EMFILE: VSL(SLT_Debug, ls->sock, - "Too many open files when accept(2)ing. Sleeping."); - TIM_sleep(params->accept_fd_holdoff * 1000.0); + "Too many open files " + "when accept(2)ing. Sleeping."); + TIM_sleep( + params->accept_fd_holdoff * 1000.0); break; default: VSL(SLT_Debug, ls->sock, - "Accept failed: %s", strerror(errno)); + "Accept failed: %s", + strerror(errno)); /* XXX: stats ? */ break; } @@ -320,7 +320,7 @@ (void)cli; (void)av; (void)priv; - + if (vca_act == NULL) vca_act = vca_acceptors[0]; @@ -356,7 +356,7 @@ cli_out(cli, "default"); else cli_out(cli, "%s", vca_act->name); - + cli_out(cli, " ("); for (i = 0; vca_acceptors[i] != NULL; i++) cli_out(cli, "%s%s", i == 0 ? "" : ", ", Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -35,7 +35,7 @@ typedef void acceptor_pass_f(struct sess *); struct acceptor { - const char *name; + const char *name; acceptor_init_f *init; acceptor_pass_f *pass; }; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -85,7 +85,7 @@ assert(sp->fd >= 0); DSL(0x04, SLT_Debug, sp->fd, "KQ: EV_SET sp %p arm %x", sp, arm); EV_SET(&ki[nki], sp->fd, EVFILT_READ, arm, 0, 0, sp); - if (++nki == NKEV) + if (++nki == NKEV) vca_kq_flush(); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_ports.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_ports.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_ports.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -61,7 +61,8 @@ static void vca_add(int fd, void *data) { - AZ(port_associate(solaris_dport, PORT_SOURCE_FD, fd, POLLIN | POLLERR | POLLPRI, data)); + AZ(port_associate(solaris_dport, PORT_SOURCE_FD, fd, + POLLIN | POLLERR | POLLPRI, data)); } static void @@ -120,7 +121,8 @@ ts.tv_sec = 0L; ts.tv_nsec = 50L /*ms*/ * 1000L /*us*/ * 1000L /*ns*/; nevents = 1; - if (port_getn(solaris_dport, ev, MAX_EVENTS, &nevents, &ts) == 0) { + if (port_getn(solaris_dport, ev, MAX_EVENTS, &nevents, &ts) + == 0) { for (ei=0; eiconnect_timeout; @@ -257,7 +258,7 @@ if (s < 0) { LOCK(&bp->mtx); - bp->n_conn--; + bp->n_conn--; bp->refcount--; /* Only keep ref on success */ UNLOCK(&bp->mtx); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -227,9 +227,9 @@ /* * Copy over the sockaddrs */ - if (vb->ipv4_sockaddr != NULL) + if (vb->ipv4_sockaddr != NULL) copy_sockaddr(&b->ipv4, &b->ipv4len, vb->ipv4_sockaddr); - if (vb->ipv6_sockaddr != NULL) + if (vb->ipv6_sockaddr != NULL) copy_sockaddr(&b->ipv6, &b->ipv6len, vb->ipv6_sockaddr); assert(b->ipv4 != NULL || b->ipv6 != NULL); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -62,14 +62,14 @@ #define VBP_TARGET_MAGIC 0x6b7cb656 struct backend *backend; - struct vrt_backend_probe probe; + struct vrt_backend_probe probe; int stop; char *req; int req_len; char resp_buf[128]; unsigned good; - + /* Collected statistics */ #define BITMAP(n, c, t, b) uint64_t n; #include "cache_backend_poll.h" @@ -86,7 +86,7 @@ static VTAILQ_HEAD(, vbp_target) vbp_list = VTAILQ_HEAD_INITIALIZER(vbp_list); -static char default_request[] = +static char default_request[] = "GET / HTTP/1.1\r\n" "Connection: close\r\n" "\r\n"; @@ -324,7 +324,7 @@ vt->backend->vcl_name, logmsg, bits, vt->good, vt->probe.threshold, vt->probe.window, vt->last, vt->avg, vt->resp_buf); - + if (!vt->stop) TIM_sleep(vt->probe.interval); } @@ -363,15 +363,15 @@ cli_out(cli, "Current states good: %2u threshold: %2u window: %2u\n", vt->good, vt->probe.threshold, vt->probe.window); cli_out(cli, "Average responsetime of good probes: %.6f\n", vt->avg); - cli_out(cli, + cli_out(cli, "Oldest " " Newest\n"); - cli_out(cli, + cli_out(cli, "=============================" "===================================\n"); #define BITMAP(n, c, t, b) \ - if ((vt->n != 0) || (b)) \ + if ((vt->n != 0) || (b)) \ vbp_bitmap(cli, (c), vt->n, (t)); #include "cache_backend_poll.h" #undef BITMAP @@ -391,10 +391,10 @@ } static struct cli_proto debug_cmds[] = { - { "debug.health", "debug.health", - "\tDump backend health stuff\n", - 0, 0, vbp_health }, - { NULL } + { "debug.health", "debug.health", + "\tDump backend health stuff\n", + 0, 0, vbp_health }, + { NULL } }; /*-------------------------------------------------------------------- Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -250,10 +250,10 @@ (void)av; (void)priv; /* - * XXX: Strictly speaking, this loop traversal is not lock-safe + * XXX: Strictly speaking, this loop traversal is not lock-safe * XXX: because we might inspect the last ban while it gets * XXX: destroyed. To properly fix this, we would need to either - * XXX: hold the lock over the entire loop, or grab refcounts + * XXX: hold the lock over the entire loop, or grab refcounts * XXX: under lock for each element of the list. * XXX: We do neither, and hope for the best. */ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -109,7 +109,6 @@ return (0); } - /*-------------------------------------------------------------------- * We have a refcounted object on the session, now deliver it. * @@ -175,7 +174,7 @@ sp->director = NULL; sp->restarts = 0; - + RES_WriteObj(sp); HSH_Deref(sp->obj); sp->obj = NULL; @@ -183,7 +182,6 @@ return (0); } - /*-------------------------------------------------------------------- * This is the final state, figure out if we should close or recycle * the client connection @@ -209,7 +207,7 @@ AZ(sp->bereq); sp->director = NULL; sp->restarts = 0; - + if (sp->vcl != NULL && sp->esis == 0) { if (sp->wrk->vcl != NULL) VCL_Rel(&sp->wrk->vcl); @@ -282,7 +280,6 @@ return (1); } - /*-------------------------------------------------------------------- * Emit an error * @@ -327,9 +324,9 @@ 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); + 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); @@ -344,7 +341,6 @@ return (0); } - /*-------------------------------------------------------------------- * We have fetched the headers from the backend, ask the VCL code what * to do next, then head off in that direction. @@ -370,7 +366,7 @@ DOT vcl_fetch -> recv [label="restart"] DOT vcl_fetch -> rstfetch [label="restart",color=purple] DOT rstfetch [label="RESTART",shape=plaintext] -DOT fetch -> errfetch +DOT fetch -> errfetch DOT vcl_fetch -> errfetch [label="error"] DOT errfetch [label="ERROR",shape=plaintext] */ @@ -558,7 +554,6 @@ } } - /*-------------------------------------------------------------------- * LOOKUP * Hash things together and look object up in hash-table. @@ -656,7 +651,6 @@ return (0); } - /*-------------------------------------------------------------------- * We had a miss, ask VCL, proceed as instructed * @@ -721,7 +715,6 @@ } } - /*-------------------------------------------------------------------- * Start pass processing by getting headers from backend, then * continue in passbody. @@ -826,7 +819,6 @@ return (0); } - /*-------------------------------------------------------------------- * RECV * We have a complete request, set everything up and start it. @@ -1008,14 +1000,14 @@ sp->step == STP_START || sp->step == STP_LOOKUP || sp->step == STP_RECV); - + /* * Whenever we come in from the acceptor we need to set blocking * mode, but there is no point in setting it when we come from * ESI or when a parked sessions returns. * It would be simpler to do this in the acceptor, but we'd rather * do the syscall in the worker thread. - */ + */ if (sp->step == STP_FIRST || sp->step == STP_START) TCP_blocking(sp->fd); @@ -1060,8 +1052,8 @@ static void cli_debug_xid(struct cli *cli, const char * const *av, void *priv) { - (void)priv; - if (av[2] != NULL) + (void)priv; + if (av[2] != NULL) xids = strtoul(av[2], NULL, 0); cli_out(cli, "XID is %u", xids); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_cli.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_cli.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -90,7 +90,7 @@ } /*-------------------------------------------------------------------- - * Called when we have a full line, look through all three command + * Called when we have a full line, look through all three command * lists to find it. */ @@ -182,19 +182,19 @@ #define SZOF(foo) cli_out(cli, \ "sizeof(%s) = %zd = 0x%zx\n", #foo, sizeof(foo), sizeof(foo)); - SZOF(struct ws); - SZOF(struct http); - SZOF(struct http_conn); - SZOF(struct acct); - SZOF(struct worker); - SZOF(struct workreq); - SZOF(struct bereq); - SZOF(struct storage); - SZOF(struct object); - SZOF(struct objhead); - SZOF(struct sess); - SZOF(struct vbe_conn); - SZOF(struct varnish_stats); + SZOF(struct ws); + SZOF(struct http); + SZOF(struct http_conn); + SZOF(struct acct); + SZOF(struct worker); + SZOF(struct workreq); + SZOF(struct bereq); + SZOF(struct storage); + SZOF(struct object); + SZOF(struct objhead); + SZOF(struct sess); + SZOF(struct vbe_conn); + SZOF(struct varnish_stats); } /*--------------------------------------------------------------------*/ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_dir_random.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_dir_random.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_dir_random.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -136,7 +136,7 @@ CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CAST_OBJ_NOTNULL(vs, d->priv, VDI_RANDOM_MAGIC); - + vh = vs->hosts; for (i = 0; i < vs->nhosts; i++, vh++) VBE_DropRef(vh->backend); @@ -147,13 +147,14 @@ } void -VRT_init_dir_random(struct cli *cli, struct director **bp, const struct vrt_dir_random *t) +VRT_init_dir_random(struct cli *cli, struct director **bp, + const struct vrt_dir_random *t) { struct vdi_random *vs; const struct vrt_dir_random_entry *te; struct vdi_random_host *vh; int i; - + (void)cli; ALLOC_OBJ(vs, VDI_RANDOM_MAGIC); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_dir_round_robin.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -111,7 +111,7 @@ 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); @@ -123,13 +123,14 @@ } void -VRT_init_dir_round_robin(struct cli *cli, struct director **bp, const struct vrt_dir_round_robin *t) +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); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_dir_simple.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_dir_simple.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_dir_simple.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -85,7 +85,7 @@ CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC); - + VBE_DropRef(vs->backend); free(vs->dir.vcl_name); vs->dir.magic = 0; @@ -93,10 +93,11 @@ } void -VRT_init_dir_simple(struct cli *cli, struct director **bp, const struct vrt_dir_simple *t) +VRT_init_dir_simple(struct cli *cli, struct director **bp, + const struct vrt_dir_simple *t) { struct vdi_simple *vs; - + (void)cli; ALLOC_OBJ(vs, VDI_SIMPLE_MAGIC); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -65,7 +65,7 @@ * Objects have sideways references in the binary heap and the LRU list * and we want to avoid paging in a lot of objects just to move them up * or down the binheap or to move a unrelated object on the LRU list. - * To avoid this we use a proxy object, objexp, to hold the relevant + * To avoid this we use a proxy object, objexp, to hold the relevant * housekeeping fields parts of an object. */ @@ -219,7 +219,7 @@ } /*-------------------------------------------------------------------- - * We have changed one or more of the object timers, shuffle it + * We have changed one or more of the object timers, shuffle it * accordingly in the binheap * * The VCL code can send us here on a non-cached object, just return. @@ -289,7 +289,7 @@ t = TIM_real(); continue; } - + o = oe->obj; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); assert(oe->timer_idx != BINHEAP_NOIDX); @@ -364,7 +364,7 @@ * with active references, likely means that it is already in core. An * object with no active references will be prodded further anyway. * - * NB: Checking refcount here is no guarantee that it does not gain + * NB: Checking refcount here is no guarantee that it does not gain * another ref while we ponder its destiny without the lock held. */ LOCK(&exp_mtx); @@ -415,7 +415,7 @@ /* Insert in binheap and lru again */ LOCK(&exp_mtx); - VSL_stats->n_lru_nuked--; /* It was premature */ + VSL_stats->n_lru_nuked--; /* It was premature */ VSL_stats->n_lru_saved++; binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -342,7 +342,7 @@ * header if one is necessary. * XXX: This possibly ought to go into the default VCL */ - if (!http_GetHdr(hp, H_Host, &b)) + if (!http_GetHdr(hp, H_Host, &b)) VBE_AddHostHeader(sp); TCP_blocking(vc->fd); /* XXX: we should timeout instead */ @@ -469,8 +469,8 @@ static void debug_fragfetch(struct cli *cli, const char * const *av, void *priv) { - (void)priv; - (void)cli; + (void)priv; + (void)cli; fetchfrag = strtoul(av[2], NULL, 0); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -119,7 +119,7 @@ VTAILQ_INIT(&w->nobj->store); VTAILQ_INIT(&w->nobj->esibits); VSL_stats->n_object++; - + } else CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC); } @@ -223,7 +223,7 @@ } if (!o->cacheable) continue; - if (o->ttl == 0) + if (o->ttl == 0) continue; if (BAN_CheckObject(o, h->hd[HTTP_HDR_URL].b, oh->hash)) { o->ttl = 0; @@ -327,9 +327,9 @@ if (o->ws_o->overflow) VSL_stats->n_objoverflow++; if (params->diag_bitmap & 0x40) - WSP(sp, SLT_Debug, + WSP(sp, SLT_Debug, "Object %u workspace free %u", o->xid, WS_Free(o->ws_o)); - + oh = o->objhead; if (oh != NULL) { CHECK_OBJ(oh, OBJHEAD_MAGIC); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -55,9 +55,9 @@ #undef HTTPH /*lint -save -e773 not () */ -#define LOGMTX2(ax, bx, cx) [bx] = SLT_##ax##cx +#define LOGMTX2(ax, bx, cx) [bx] = SLT_##ax##cx -#define LOGMTX1(ax) { \ +#define LOGMTX1(ax) { \ LOGMTX2(ax, HTTP_HDR_REQ, Request), \ LOGMTX2(ax, HTTP_HDR_RESPONSE, Response), \ LOGMTX2(ax, HTTP_HDR_STATUS, Status), \ @@ -229,12 +229,13 @@ } /*-------------------------------------------------------------------- - * Find a given headerfield, and if present and wanted, the beginning + * Find a given headerfield, and if present and wanted, the beginning * of its value. */ int -http_GetHdrField(const struct http *hp, const char *hdr, const char *field, char **ptr) +http_GetHdrField(const struct http *hp, const char *hdr, + const char *field, char **ptr) { char *h, *e; unsigned fl; @@ -271,7 +272,7 @@ return (1); } /* Skip token */ - while (*h && !vct_issepctl(*h)) + while (*h && !vct_issepctl(*h)) h++; } return (0); @@ -410,7 +411,8 @@ */ static int -http_splitline(struct worker *w, int fd, struct http *hp, const struct http_conn *htc, int h1, int h2, int h3) +http_splitline(struct worker *w, int fd, struct http *hp, + const struct http_conn *htc, int h1, int h2, int h3) { char *p; @@ -513,7 +515,8 @@ /*--------------------------------------------------------------------*/ int -http_DissectResponse(struct worker *w, const struct http_conn *htc, struct http *hp) +http_DissectResponse(struct worker *w, const struct http_conn *htc, + struct http *hp) { int i; @@ -530,13 +533,13 @@ if (hp->status == 0) hp->status = i; } else { - hp->status = + hp->status = strtoul(hp->hd[HTTP_HDR_STATUS].b, NULL /* XXX */, 10); } if (hp->hd[HTTP_HDR_RESPONSE].b == NULL || !Tlen(hp->hd[HTTP_HDR_RESPONSE])) { /* Backend didn't send a response string, use the standard */ - hp->hd[HTTP_HDR_RESPONSE].b = + hp->hd[HTTP_HDR_RESPONSE].b = TRUST_ME(http_StatusMessage(hp->status)); hp->hd[HTTP_HDR_RESPONSE].e = strchr(hp->hd[HTTP_HDR_RESPONSE].b, '\0'); @@ -606,7 +609,8 @@ } void -http_SetResp(struct http *to, const char *proto, const char *status, const char *response) +http_SetResp(struct http *to, const char *proto, const char *status, + const char *response) { CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); @@ -616,7 +620,8 @@ } static void -http_copyheader(struct worker *w, int fd, struct http *to, const struct http *fm, unsigned n) +http_copyheader(struct worker *w, int fd, struct http *to, + const struct http *fm, unsigned n) { CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC); @@ -636,7 +641,8 @@ /*--------------------------------------------------------------------*/ void -http_FilterFields(struct worker *w, int fd, struct http *to, const struct http *fm, unsigned how) +http_FilterFields(struct worker *w, int fd, struct http *to, + const struct http *fm, unsigned how) { unsigned u; @@ -664,10 +670,10 @@ struct bereq *bereq; struct http *hp; - bereq = VBE_new_bereq(); - AN(bereq); - hp = bereq->http; - hp->logtag = HTTP_Tx; + bereq = VBE_new_bereq(); + AN(bereq); + hp = bereq->http; + hp->logtag = HTTP_Tx; http_copyreq(hp, sp->http, how); http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how); @@ -741,7 +747,8 @@ /*--------------------------------------------------------------------*/ static void -http_PutField(struct worker *w, int fd, struct http *to, int field, const char *string) +http_PutField(struct worker *w, int fd, struct http *to, int field, + const char *string) { char *p; unsigned l; @@ -763,7 +770,8 @@ } void -http_PutProtocol(struct worker *w, int fd, struct http *to, const char *protocol) +http_PutProtocol(struct worker *w, int fd, struct http *to, + const char *protocol) { http_PutField(w, fd, to, HTTP_HDR_PROTO, protocol); @@ -781,14 +789,16 @@ } void -http_PutResponse(struct worker *w, int fd, struct http *to, const char *response) +http_PutResponse(struct worker *w, int fd, struct http *to, + const char *response) { http_PutField(w, fd, to, HTTP_HDR_RESPONSE, response); } void -http_PrintfHeader(struct worker *w, int fd, struct http *to, const char *fmt, ...) +http_PrintfHeader(struct worker *w, int fd, struct http *to, + const char *fmt, ...) { va_list ap; unsigned l, n; @@ -818,7 +828,7 @@ unsigned u, v; for (v = u = HTTP_HDR_FIRST; u < hp->nhd; u++) { - if (http_IsHdr(&hp->hd[u], hdr)) + if (http_IsHdr(&hp->hd[u], hdr)) continue; if (v != u) { memcpy(&hp->hd[v], &hp->hd[u], sizeof hp->hd[v]); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_httpconn.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_httpconn.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_httpconn.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -133,7 +133,7 @@ CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); i = htc_header_complete(&htc->rxbuf); - if (i < 0) + if (i < 0) htc->rxbuf.e = htc->rxbuf.b; if (i <= 0) return (0); @@ -195,7 +195,7 @@ p += l; len -= l; htc->pipeline.b += l; - if (htc->pipeline.b == htc->pipeline.e) + if (htc->pipeline.b == htc->pipeline.e) htc->pipeline.b = htc->pipeline.e = NULL; } if (len == 0) Modified: branches/2.0/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_panic.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_panic.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -64,15 +64,15 @@ 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) + 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) + 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) + if (ws->e > ws->s) vsb_printf(vsp, ",+%d", ws->e - ws->s); else vsb_printf(vsp, ",%p", ws->e); @@ -258,7 +258,8 @@ /*--------------------------------------------------------------------*/ static void -pan_ic(const char *func, const char *file, int line, const char *cond, int err, int xxx) +pan_ic(const char *func, const char *file, int line, const char *cond, + int err, int xxx) { int l; char *p; @@ -296,7 +297,7 @@ vsb_printf(vsp, " thread = (%s)", q); if (!(params->diag_bitmap & 0x2000)) { sp = THR_GetSession(); - if (sp != NULL) + if (sp != NULL) pan_sess(sp); } vsb_printf(vsp, "\n"); @@ -307,7 +308,7 @@ memcpy(p, panicstr, l); if (params->diag_bitmap & 0x4000) (void)fputs(panicstr, stderr); - + #ifdef HAVE_ABORT2 if (params->diag_bitmap & 0x8000) { void *arg[1]; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -111,7 +111,7 @@ fds[0].revents = 0; fds[1].revents = 0; i = poll(fds, 2, params->pipe_timeout * 1000); - if (i < 1) + if (i < 1) break; if (fds[0].revents && rdf(vc->fd, sp->fd)) { (void)shutdown(vc->fd, SHUT_RD); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -79,7 +79,7 @@ struct wq { unsigned magic; #define WQ_MAGIC 0x606658fa - MTX mtx; + MTX mtx; struct workerhead idle; VTAILQ_HEAD(, workreq) overflow; unsigned nthr; @@ -456,7 +456,7 @@ /*-------------------------------------------------------------------- * Periodic pool herding thread - * + * * Do things which we can do at our leisure: * Add pools * Scale constants Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -208,8 +208,8 @@ struct vcls *vcl, *vcl2; ASSERT_CLI(); - VTAILQ_FOREACH_SAFE(vcl, &vcl_head, list, vcl2) - if (vcl->conf->discard && vcl->conf->busy == 0) + VTAILQ_FOREACH_SAFE(vcl, &vcl_head, list, vcl2) + if (vcl->conf->discard && vcl->conf->busy == 0) VCL_Nuke(vcl); } @@ -323,7 +323,7 @@ \ sp->handling = 0; \ sp->cur_method = VCL_MET_ ## upper; \ - WSP(sp, SLT_VCL_call, "%s", #func); \ + WSP(sp, SLT_VCL_call, "%s", #func); \ sp->vcl->func##_func(sp); \ WSP(sp, SLT_VCL_return, "%s", vcl_handlingname(sp->handling)); \ sp->cur_method = 0; \ @@ -342,7 +342,7 @@ { CLI_VCL_LIST, ccf_config_list }, { CLI_VCL_DISCARD, ccf_config_discard }, { CLI_VCL_USE, ccf_config_use }, - { NULL } + { NULL } }; void Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -136,7 +136,7 @@ if (b + x < e) memcpy(b, h, x); b += x; - if (b + 1 < e) + if (b + 1 < e) *b++ = ' '; } while (p != vrt_magic_string_end) { @@ -148,7 +148,7 @@ b += x; p = va_arg(ap, const char *); } - if (b + 1 < e) + if (b + 1 < e) *b++ = '\0'; if (b > e) { WS_Release(hp->ws, 0); @@ -164,7 +164,8 @@ /*--------------------------------------------------------------------*/ void -VRT_SetHdr(const struct sess *sp , enum gethdr_e where, const char *hdr, const char *p, ...) +VRT_SetHdr(const struct sess *sp , enum gethdr_e where, const char *hdr, + const char *p, ...) { struct http *hp; va_list ap; @@ -190,7 +191,8 @@ /*--------------------------------------------------------------------*/ static void -vrt_do_string(struct worker *w, int fd, struct http *hp, int fld, const char *err, const char *p, va_list ap) +vrt_do_string(struct worker *w, int fd, struct http *hp, int fld, + const char *err, const char *p, va_list ap) { char *b; @@ -519,7 +521,8 @@ 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); + TCP_name(sp->mysockaddr, sp->mysockaddrlen, + abuf, sizeof abuf, pbuf, sizeof pbuf); return (atoi(pbuf)); } @@ -672,7 +675,7 @@ *sp->http = *sp->http0; WS_Reset(sp->ws, sp->ws_req); } - + /*--------------------------------------------------------------------*/ /*lint -e{818} sp could be const */ @@ -725,7 +728,7 @@ void VRT_purge(const char *regexp, int hash) { - + if (regexp != NULL) (void)BAN_Add(NULL, regexp, hash); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -95,7 +95,7 @@ char buf[256], *q; txt t; - if (i == 0) + if (i == 0) i = p - ew->t.b; if (i > 20) { i = 20; @@ -234,7 +234,7 @@ /* Value, if any ? */ *val = *in; - if (in->b >= in->e) + if (in->b >= in->e) return (1); if (*in->b == '"') { @@ -287,7 +287,7 @@ tag.e - tag.b, tag.b, val.e - val.b, val.b); if (Tlen(tag) != 3 || memcmp(tag.b, "src", 3)) - continue; + continue; if (Tlen(val) == 0) { esi_error(ew, tag.b, Tlen(tag), "ESI esi:include src attribute withou value"); @@ -351,7 +351,7 @@ /*-------------------------------------------------------------------- * Zoom over a piece of object and dike out all releveant esi: pieces. - * The entire txt may not be processed because an interesting part + * The entire txt may not be processed because an interesting part * could possibly span into the next chunk of storage. * Return value: number of bytes processed. */ @@ -385,7 +385,7 @@ if (!memcmp(p, "]]>", 3)) { ew->incdata = 0; p += 3; - } else + } else p++; } continue; @@ -464,7 +464,7 @@ ew->incdata = 1; p += 9; continue; - } + } /* Ignore non esi elements, if so instructed */ if ((params->esi_syntax & 0x02)) { @@ -510,7 +510,7 @@ esi_error(ew, p, 1 + q - p, ew->remflg ? "ESI 1.0 forbids nested esi:remove" : "ESI 1.0 esi:remove not opened"); - + if (!ew->remflg) { ew->o.e = p; esi_addverbatim(ew); @@ -561,7 +561,7 @@ continue; } if (r + 10 < q && !memcmp(r, "esi:include", 11)) { - + ew->o.e = p; esi_addverbatim(ew); @@ -723,7 +723,7 @@ p = NULL; continue; } - assert(t.e > t.b + u); /* XXX incredibly long element ? */ + assert(t.e > t.b + u); /* XXX incredibly long element ? */ memcpy(t.b, p, u); /* Peel start off next chunk, until and including '<' */ @@ -755,7 +755,7 @@ ew->t = t; q = esi_parse(ew); assert(q == ew->t.e); /* XXX */ - + /* 'p' is cached starting point for next storage part */ } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -104,7 +104,8 @@ } const char * -VRT_regsub(const struct sess *sp, int all, const char *str, void *re, const char *sub) +VRT_regsub(const struct sess *sp, int all, const char *str, void *re, + const char *sub) { regmatch_t pm[10]; regex_t *t; @@ -161,7 +162,7 @@ if (res.b >= res.e) { WS_Release(sp->http->ws, 0); return (str); - } + } Tcheck(res); WS_ReleaseP(sp->http->ws, res.b); return (b0); Modified: branches/2.0/varnish-cache/bin/varnishd/default.vcl =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/default.vcl 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/default.vcl 2009-02-05 08:45:25 UTC (rev 3580) @@ -16,23 +16,24 @@ * * 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. + * 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$ * * The default VCL code. * - * NB! You do NOT need to copy & paste all of this into your won vcl code, - * if you do not handle one of the functions, the compiler will automaticall - * fall back to the default code. + * NB! You do NOT need to copy & paste all of these functions into your + * own vcl code, if you do not provide a definition of one of these + * functions, the compiler will automatically fall back to the default + * code from this file. * * This code will be prefixed with a backend declaration built from the * -b argument. @@ -134,7 +135,9 @@

"} obj.response {"

Guru Meditation:

XID: "} req.xid {"

-
Varnish
+
+ Varnish +
"}; Modified: branches/2.0/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -249,7 +249,7 @@ /*--------------------------------------------------------------------*/ struct hash_slinger hcl_slinger = { - .magic = SLINGER_MAGIC, + .magic = SLINGER_MAGIC, .name = "classic", .init = hcl_init, .start = hcl_start, Modified: branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -90,25 +90,23 @@ UNLOCK(&hsl_mutex); return (nobj); } - if (nobj == NULL) { - UNLOCK(&hsl_mutex); - return (NULL); - } - he2 = calloc(sizeof *he2, 1); - XXXAN(he2); - he2->obj = nobj; - he2->refcnt = 1; + if (nobj != NULL) { + he2 = calloc(sizeof *he2, 1); + XXXAN(he2); + he2->obj = nobj; + he2->refcnt = 1; - nobj->hashpriv = he2; - nobj->hash = malloc(sp->lhashptr); - XXXAN(nobj->hash); - nobj->hashlen = sp->lhashptr; - HSH_Copy(sp, nobj); + nobj->hashpriv = he2; + nobj->hash = malloc(sp->lhashptr); + XXXAN(nobj->hash); + nobj->hashlen = sp->lhashptr; + HSH_Copy(sp, nobj); - if (he != NULL) - VTAILQ_INSERT_BEFORE(he, he2, list); - else - VTAILQ_INSERT_TAIL(&hsl_head, he2, list); + if (he != NULL) + VTAILQ_INSERT_BEFORE(he, he2, list); + else + VTAILQ_INSERT_TAIL(&hsl_head, he2, list); + } UNLOCK(&hsl_mutex); return (nobj); } @@ -143,5 +141,5 @@ .name = "simple", .start = hsl_start, .lookup = hsl_lookup, - .deref = hsl_deref, + .deref = hsl_deref, }; Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -33,7 +33,8 @@ 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 struct objhead * + hash_lookup_f(const struct sess *sp, struct objhead *nobj); typedef int hash_deref_f(const struct objhead *obj); struct hash_slinger { Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -77,7 +77,7 @@ /* TTL used for lack of anything better */ unsigned default_ttl; - + /* TTL used for synthesized error pages */ unsigned err_ttl; @@ -193,4 +193,5 @@ void child_main(void); -int varnish_instance(const char *n_arg, char *name, size_t namelen, char *dir, size_t dirlen); +int varnish_instance(const char *n_arg, char *name, size_t namelen, + char *dir, size_t dirlen); Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_child.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_child.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -194,7 +194,7 @@ continue; } ls->sock = VSS_bind(ls->addr); - if (ls->sock < 0) + if (ls->sock < 0) continue; mgt_child_inherit(ls->sock, "sock"); @@ -269,7 +269,7 @@ child_cli_in = cp[0]; /* - * Open pipe for child stdout/err + * Open pipe for child stdout/err * NB: not inherited, because we dup2() it to stdout/stderr in child */ AZ(pipe(cp)); @@ -548,7 +548,7 @@ AZ(sigaction(SIGPIPE, &sac, NULL)); AZ(sigaction(SIGHUP, &sac, NULL)); - if (!dflag && !mgt_has_vcl()) + if (!dflag && !mgt_has_vcl()) REPORT0(LOG_ERR, "No VCL loaded yet"); else if (!dflag) { start_child(NULL); Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -66,8 +66,8 @@ static int cli_i = -1, cli_o = -1; struct telnet { - int fd; - struct vev *ev; + int fd; + struct vev *ev; VTAILQ_ENTRY(telnet) list; }; @@ -108,7 +108,7 @@ "help %s\n", av[2] != NULL ? av[2] : "")) { cli_out(cli, "%s", p); cli_result(cli, u); - } + } free(p); } } @@ -144,7 +144,7 @@ { CLI_PARAM_SHOW, mcf_param_show, NULL }, { CLI_PARAM_SET, mcf_param_set, NULL }, - { CLI_QUIT, mcf_close, NULL}, + { CLI_QUIT, mcf_close, NULL}, #if 0 { CLI_SERVER_RESTART }, { CLI_ZERO }, Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -155,7 +155,8 @@ /*--------------------------------------------------------------------*/ static void -tweak_generic_uint(struct cli *cli, volatile unsigned *dest, const char *arg, unsigned min, unsigned max) +tweak_generic_uint(struct cli *cli, volatile unsigned *dest, const char *arg, + unsigned min, unsigned max) { unsigned u; @@ -215,7 +216,7 @@ master.uid = getuid(); return; } - } else + } else pw = getpwnam(arg); if (pw == NULL) { cli_out(cli, "Unknown user"); @@ -229,7 +230,7 @@ /* set group to user's primary group */ if ((gr = getgrgid(pw->pw_gid)) != NULL && (gr = getgrnam(gr->gr_name)) != NULL && - gr->gr_gid == pw->pw_gid) + gr->gr_gid == pw->pw_gid) REPLACE(master.group, gr->gr_name); } else if (master.user) { cli_out(cli, "%s (%d)", master.user, (int)master.uid); @@ -276,7 +277,8 @@ /*--------------------------------------------------------------------*/ static void -tweak_thread_pool_min(struct cli *cli, const struct parspec *par, const char *arg) +tweak_thread_pool_min(struct cli *cli, const struct parspec *par, + const char *arg) { tweak_generic_uint(cli, &master.wthread_min, arg, @@ -286,7 +288,8 @@ /*--------------------------------------------------------------------*/ static void -tweak_thread_pool_max(struct cli *cli, const struct parspec *par, const char *arg) +tweak_thread_pool_max(struct cli *cli, const struct parspec *par, + const char *arg) { (void)par; @@ -310,7 +313,8 @@ } static void -tweak_listen_address(struct cli *cli, const struct parspec *par, const char *arg) +tweak_listen_address(struct cli *cli, const struct parspec *par, + const char *arg) { char **av; int i; Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -65,7 +65,7 @@ struct vclprog { VTAILQ_ENTRY(vclprog) list; - char *name; + char *name; char *fname; int active; }; @@ -487,7 +487,7 @@ cli_result(cli, CLIS_PARAM); return; } - + sb = vsb_newauto(); XXXAN(sb); vf = mgt_VccCompile(sb, av[3], NULL, 0); @@ -577,7 +577,7 @@ vp = mcf_find_vcl(cli, av[2]); if (vp == NULL) return; - if (vp->active != 0) + if (vp->active != 0) return; if (child_pid >= 0 && mgt_cli_askchild(&status, &p, "vcl.use %s\n", av[2])) { Modified: branches/2.0/varnish-cache/bin/varnishd/shmlog.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/shmlog.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/shmlog.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -86,7 +86,7 @@ p[__SHMLOG_ID_HIGH] = (id >> 8) & 0xff; p[__SHMLOG_ID_LOW] = id & 0xff; p[SHMLOG_DATA + len] = '\0'; - p[SHMLOG_NEXTTAG + len] = SLT_ENDMARKER; + p[SHMLOG_NEXTTAG + len] = SLT_ENDMARKER; /* XXX: Write barrier here */ p[SHMLOG_TAG] = tag; } @@ -159,7 +159,7 @@ p = logstart + loghead->ptr; n = vsnprintf((char *)(p + SHMLOG_DATA), 256, fmt, ap); if (n > 255) - n = 255; /* we truncate long fields */ + n = 255; /* we truncate long fields */ vsl_hdr(tag, p, n, id); loghead->ptr += SHMLOG_NEXTTAG + n; assert(loghead->ptr < loghead->size); @@ -254,7 +254,7 @@ p = w->wlp; n = vsnprintf((char *)(p + SHMLOG_DATA), 256, fmt, ap); if (n > 255) - n = 255; /* we truncate long fields */ + n = 255; /* we truncate long fields */ vsl_hdr(tag, p, n, id); w->wlp += SHMLOG_NEXTTAG + n; assert(w->wlp < w->wle); Modified: branches/2.0/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/stevedore.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/stevedore.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -105,7 +105,7 @@ if (stv->init != NULL) stv->init(stv, ac, av); - else if (ac != 0) + else if (ac != 0) ARGV_ERR("(-s%s) too many arguments\n", stv->name); VTAILQ_INSERT_TAIL(&stevedores, stv, list); Modified: branches/2.0/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_file.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/storage_file.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -185,7 +185,7 @@ i = 0; while(1) { o = l; - if (o == l && o > 0) + if (o == l && o > 0) break; l >>= 1; i++; @@ -303,7 +303,7 @@ if (S_ISREG(st.st_mode)) { sc->fd = open(fn, O_RDWR); - if (sc->fd < 0) + if (sc->fd < 0) ARGV_ERR("(-sfile) \"%s\" could not open (%s)\n", fn, strerror(errno)); AZ(fstat(sc->fd, &st)); Modified: branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -132,7 +132,7 @@ (void)parent; AZ(av[ac]); - if (ac > 1) + if (ac > 1) ARGV_ERR("(-smalloc) too many arguments\n"); if (ac == 0 || *av[0] == '\0') @@ -141,7 +141,7 @@ 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)) + if ((u != (uintmax_t)(size_t)u)) ARGV_ERR("(-smalloc) size \"%s\": too big\n", av[0]); printf("storage_malloc: max size %ju MB.\n", Modified: branches/2.0/varnish-cache/bin/varnishd/storage_umem.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_umem.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/storage_umem.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -139,7 +139,7 @@ (void)parent; AZ(av[ac]); - if (ac > 1) + if (ac > 1) ARGV_ERR("(-sumem) too many arguments\n"); if (ac == 0 || *av[0] == '\0') @@ -148,7 +148,7 @@ e = str2bytes(av[0], &u, 0); if (e != NULL) ARGV_ERR("(-sumem) size \"%s\": %s\n", av[0], e); - if ((u != (uintmax_t)(size_t)u)) + if ((u != (uintmax_t)(size_t)u)) ARGV_ERR("(-sumem) size \"%s\": too big\n", av[0]); smu_max = u; } Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -136,7 +136,7 @@ av = ParseArgv(spec, ARGV_COMMA); AN(av); - if (av[0] != NULL) + if (av[0] != NULL) ARGV_ERR("%s\n", av[0]); if (av[1] == NULL) @@ -175,7 +175,7 @@ av = ParseArgv(h_arg, ARGV_COMMA); AN(av); - if (av[0] != NULL) + if (av[0] != NULL) ARGV_ERR("%s\n", av[0]); if (av[1] == NULL) @@ -226,7 +226,8 @@ 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, "", + " -s file,,,"); fprintf(stderr, FMT, "-t", "Default TTL"); fprintf(stderr, FMT, "-T address:port", "Telnet listen address and port"); @@ -252,10 +253,10 @@ av = ParseArgv(argv, ARGV_COMMA); AN(av); - if (av[0] != NULL) + if (av[0] != NULL) ARGV_ERR("%s\n", av[0]); - if (av[1] == NULL) + if (av[1] == NULL) usage(); u = arg_ul(av[1]); @@ -462,7 +463,8 @@ MCF_ParamInit(cli); cli_check(cli); - while ((o = getopt(argc, argv, "a:b:Cdf:Fg:h:l:n:P:p:s:T:t:u:Vw:")) != -1) + while ((o = getopt(argc, argv, + "a:b:Cdf:Fg:h:l:n:P:p:s:T:t:u:Vw:")) != -1) switch (o) { case 'a': MCF_ParamSet(cli, "listen_address", optarg); @@ -580,7 +582,7 @@ exit(1); } - if (n_arg != NULL) + if (n_arg != NULL) openlog(n_arg, LOG_PID, LOG_LOCAL0); else openlog("varnishd", LOG_PID, LOG_LOCAL0); @@ -624,7 +626,7 @@ if (d_flag == 1) printf("%d\n", getpid()); - if (pfh != NULL && vpf_write(pfh)) + if (pfh != NULL && vpf_write(pfh)) fprintf(stderr, "NOTE: Could not write PID file\n"); mgt_run(d_flag, T_arg); Modified: branches/2.0/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishhist/varnishhist.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishhist/varnishhist.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -147,7 +147,8 @@ } static int -h_hist(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) +h_hist(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, + unsigned spec, const char *ptr) { double b; int i, j; @@ -308,8 +309,8 @@ static void usage(void) { - fprintf(stderr, - "usage: varnishhist %s [-n varnish_name] [-V] [-w delay]\n", VSL_USAGE); + fprintf(stderr, "usage: varnishhist " + "%s [-n varnish_name] [-V] [-w delay]\n", VSL_USAGE); exit(1); } Modified: branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -120,7 +120,8 @@ } static int -h_order(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) +h_order(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, + unsigned spec, const char *ptr) { char type; @@ -261,7 +262,7 @@ flags = (a_flag ? O_APPEND : O_TRUNC) | O_WRONLY | O_CREAT; #ifdef O_LARGEFILE - flags |= O_LARGEFILE; + flags |= O_LARGEFILE; #endif if (!strcmp(w_arg, "-")) fd = STDOUT_FILENO; @@ -308,8 +309,8 @@ static void usage(void) { - fprintf(stderr, - "usage: varnishlog %s [-aDoV] [-n varnish_name] [-P file] [-w file]\n", VSL_USAGE); + fprintf(stderr, "usage: varnishlog " + "%s [-aDoV] [-n varnish_name] [-P file] [-w file]\n", VSL_USAGE); exit(1); } Modified: branches/2.0/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishncsa/varnishncsa.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishncsa/varnishncsa.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -105,7 +105,8 @@ static int prefer_x_forwarded_for = 0; static int -isprefix(const char *str, const char *prefix, const char *end, const char **next) +isprefix(const char *str, const char *prefix, const char *end, + const char **next) { while (str < end && *str && *prefix && @@ -511,7 +512,9 @@ usage(void) { - fprintf(stderr, "usage: varnishncsa %s [-aDV] [-n varnish_name] [-P file] [-w file]\n", VSL_USAGE); + fprintf(stderr, + "usage: varnishncsa %s [-aDV] [-n varnish_name] " + "[-P file] [-w file]\n", VSL_USAGE); exit(1); } Modified: branches/2.0/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishreplay/varnishreplay.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishreplay/varnishreplay.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -251,7 +251,8 @@ while (fd >= newnthreads) newnthreads += newnthreads + 1; - newthreads = realloc(newthreads, newnthreads * sizeof *newthreads); + newthreads = realloc(newthreads, + newnthreads * sizeof *newthreads); XXXAN(newthreads != NULL); memset(newthreads + nthreads, 0, (newnthreads - nthreads) * sizeof *newthreads); @@ -557,12 +558,15 @@ if (!thr->method || !thr->url || !thr->proto) { thr->bogus = 1; - } else if (strcmp(thr->method, "GET") != 0 && strcmp(thr->method, "HEAD") != 0) { + } else if (strcmp(thr->method, "GET") != 0 && + strcmp(thr->method, "HEAD") != 0) { thr->bogus = 1; } else if (strcmp(thr->proto, "HTTP/1.0") == 0) { - reopen = !(thr->conn && strcasecmp(thr->conn, "keep-alive") == 0); + reopen = !(thr->conn && + strcasecmp(thr->conn, "keep-alive") == 0); } else if (strcmp(thr->proto, "HTTP/1.1") == 0) { - reopen = (thr->conn && strcasecmp(thr->conn, "close") == 0); + reopen = (thr->conn && + strcasecmp(thr->conn, "close") == 0); } else { thr->bogus = 1; } @@ -701,7 +705,8 @@ usage(void) { - fprintf(stderr, "usage: varnishreplay [-D] -a address:port -r logfile\n"); + fprintf(stderr, + "usage: varnishreplay [-D] -a address:port -r logfile\n"); exit(1); } @@ -743,7 +748,11 @@ signal(SIGPIPE, SIG_IGN); pthread_attr_init(&thread_attr); - /* XXX: seting the stack size manually reduces the memory usasage and increases speed */ + + /* + * XXX: seting the stack size manually reduces the memory usage + * XXX: (allowing more threads) and increases speed (?) + */ pthread_attr_setstacksize(&thread_attr, 32768); while (VSL_Dispatch(vd, gen_traffic, NULL) == 0) Modified: branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -81,9 +81,10 @@ 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); + if ((field_start == fields || + *(field_start - 1) == ',') && + (*field_end == ',' || *field_end == '\0')) + return (match_value); field_start = strstr( field_end, field ); } } @@ -237,14 +238,20 @@ usage(void) { #define FMT " %-28s # %s\n" - fprintf(stderr, "usage: varnishstat [-1lV] [-f field_list] [-n varnish_name] [-w delay]\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, "-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."); + fprintf(stderr, FMT, "-w delay", + "Wait delay seconds between updates. The default is 1."); #undef FMT exit(1); } @@ -252,7 +259,7 @@ static void list_fields(void) { - fprintf(stderr, "Available fields to use with the varnishstat -f option:\n"); + fprintf(stderr, "Varnishstat -f option fields:\n"); fprintf(stderr, "Field name Description\n"); fprintf(stderr, "---------- -----------\n"); fprintf(stderr, "uptime Child uptime\n"); @@ -290,7 +297,8 @@ 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] )) { + if (strncmp(field_start, all_fields[i], field_length) + == 0 && field_length == strlen( all_fields[i])) { valid_field = 1; break; } @@ -346,7 +354,7 @@ if ((VSL_stats = VSL_OpenStats(n_arg)) == NULL) exit(1); - + if (fields != NULL && !valid_fields(fields)) { usage(); exit(1); Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -1,7 +1,7 @@ /* * 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: @@ -10,7 +10,7 @@ * 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 @@ -140,7 +140,8 @@ p++; } else { if (*p == '\n') - fprintf(stderr, "Unterminated quoted string in line:\n%s", p); + fprintf(stderr, + "Unterminated quoted string in line:\n%s", p); assert(*p != '\n'); *q++ = *p; } @@ -184,7 +185,7 @@ fprintf(stderr, "Unknown command: \"%s\"", token_s[0]); exit (1); } - + assert(cp->cmd != NULL); cp->cmd(token_s, priv, cmd, vl); if (stop) @@ -377,7 +378,7 @@ } /********************************************************************** - * Main + * Main */ int Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -1,7 +1,7 @@ /* * 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: @@ -10,7 +10,7 @@ * 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 @@ -22,7 +22,7 @@ * 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$ */ @@ -30,7 +30,9 @@ struct vtclog; struct cmds; -#define CMD_ARGS char * const *av, void *priv, const struct cmds *cmd, struct vtclog *vl +#define CMD_ARGS \ + char * const *av, void *priv, const struct cmds *cmd, struct vtclog *vl + typedef void cmd_f(CMD_ARGS); struct cmds { @@ -38,7 +40,8 @@ cmd_f *cmd; }; -void parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl); +void parse_string(char *buf, const struct cmds *cmd, void *priv, + struct vtclog *vl); cmd_f cmd_dump; cmd_f cmd_delay; @@ -60,4 +63,5 @@ struct vtclog *vtc_logopen(const char *id); void vtc_logclose(struct vtclog *vl); void vtc_log(struct vtclog *vl, unsigned lvl, const char *fmt, ...); -void vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, const char *str); +void vtc_dump(struct vtclog *vl, unsigned lvl, const char *pfx, + const char *str); Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_client.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_client.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_client.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -1,7 +1,7 @@ /* * 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: @@ -10,7 +10,7 @@ * 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 @@ -50,7 +50,7 @@ VTAILQ_ENTRY(client) list; char *spec; - + char *connect; pthread_t tp; @@ -208,7 +208,7 @@ VTAILQ_FOREACH(c, &clients, list) if (!strcmp(c->name, av[0])) break; - if (c == NULL) + if (c == NULL) c = client_new(av[0]); av++; Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -1,7 +1,7 @@ /* * 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: @@ -10,7 +10,7 @@ * 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 @@ -75,8 +75,8 @@ { int i, j, k, l; char *b; - - + + AN(len); i = strtoul(len, NULL, 0); assert(i > 0); @@ -347,8 +347,8 @@ { char *p, *q; int i, l, ll; - + ll = 0; p = http_find_header(hh, "content-length"); if (p != NULL) { @@ -397,7 +397,7 @@ ll += i; } while (i > 0); vtc_dump(hp->vl, 4, "rxeof", hp->body); - } + } sprintf(hp->bodylen, "%d", ll); } @@ -419,7 +419,7 @@ p = hp->rxbuf + hp->prxbuf - 1; i = 0; for (i = 0; p > hp->rxbuf; p--) { - if (*p != '\n') + if (*p != '\n') break; if (p - 1 > hp->rxbuf && p[-1] == '\r') p--; @@ -456,7 +456,7 @@ vtc_log(hp->vl, 3, "rxresp"); http_rxhdr(hp); http_splitheader(hp, 0); - if (!strcmp(hp->resp[1], "200")) + if (!strcmp(hp->resp[1], "200")) http_swallow_body(hp, hp->resp, 1); else http_swallow_body(hp, hp->resp, 0); @@ -506,7 +506,7 @@ if (!strcmp(*av, "-hdr")) { vsb_printf(hp->vsb, "%s%s", av[1], nl); av++; - } else + } else break; } for(; *av != NULL; av++) { @@ -525,7 +525,7 @@ fprintf(stderr, "Unknown http txresp spec: %s\n", *av); exit (1); } - if (body != NULL) + if (body != NULL) vsb_printf(hp->vsb, "Content-Length: %d%s", strlen(body), nl); vsb_cat(hp->vsb, nl); if (body != NULL) { @@ -621,7 +621,7 @@ fprintf(stderr, "Unknown http txreq spec: %s\n", *av); exit (1); } - if (body != NULL) + if (body != NULL) vsb_printf(hp->vsb, "Content-Length: %d%s", strlen(body), nl); vsb_cat(hp->vsb, nl); if (body != NULL) { Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_log.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_log.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_log.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -1,7 +1,7 @@ /* * 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: @@ -10,7 +10,7 @@ * 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 @@ -56,7 +56,7 @@ struct vtclog *vl; ALLOC_OBJ(vl, VTCLOG_MAGIC); - AN(vl); + AN(vl); vl->id = id; vl->vsb = vsb_newauto(); return (vl); @@ -125,7 +125,7 @@ vsb_clear(vl->vsb); if (pfx == NULL) pfx = ""; - if (str == NULL) + if (str == NULL) vsb_printf(vl->vsb, "%s %-4s %s(null)\n", lead[lvl], vl->id, pfx); else Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_sema.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_sema.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_sema.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -1,7 +1,7 @@ /* * 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: @@ -10,7 +10,7 @@ * 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 @@ -141,7 +141,7 @@ VTAILQ_FOREACH(r, &semas, list) if (!strcmp(r->name, av[0])) break; - if (r == NULL) + if (r == NULL) r = sema_new(av[0], vl); AZ(pthread_mutex_unlock(&sema_mtx)); av++; Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -1,7 +1,7 @@ /* * 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: @@ -10,7 +10,7 @@ * 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 @@ -54,7 +54,7 @@ unsigned repeat; char *spec; - + int depth; int sock; char *listen; @@ -234,7 +234,7 @@ /* Reset and free */ VTAILQ_FOREACH_SAFE(s, &servers, list, s2) { VTAILQ_REMOVE(&servers, s, list); - if (s->sock >= 0) + if (s->sock >= 0) server_wait(s); server_delete(s); } @@ -247,7 +247,7 @@ VTAILQ_FOREACH(s, &servers, list) if (!strcmp(s->name, av[0])) break; - if (s == NULL) + if (s == NULL) s = server_new(av[0]); av++; Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -1,7 +1,7 @@ /* * 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: @@ -10,7 +10,7 @@ * 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 @@ -446,7 +446,7 @@ for (i = 0; i < 10; i++, usleep(100000)) { -#define MAC_STAT(n, t, f, d) \ +#define MAC_STAT(n, t, f, d) \ if (!strcmp(av[0], #n)) { \ val = v->stats->n; \ } else @@ -510,7 +510,7 @@ VTAILQ_FOREACH(v, &varnishes, list) if (!strcmp(v->name, av[0])) break; - if (v == NULL) + if (v == NULL) v = varnish_new(av[0]); av++; Modified: branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -286,7 +286,8 @@ static void usage(void) { - fprintf(stderr, "usage: varnishtop %s [-1fV] [-n varnish_name]\n", VSL_USAGE); + fprintf(stderr, + "usage: varnishtop %s [-1fV] [-n varnish_name]\n", VSL_USAGE); exit(1); } Modified: branches/2.0/varnish-cache/include/cli.h =================================================================== --- branches/2.0/varnish-cache/include/cli.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/cli.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -57,7 +57,7 @@ "url.query", \ "url.query ", \ "\tQuery the cache status of a specific URL.\n" \ - "\tReturns the TTL, size and checksum of the object.", \ + "\tReturns the TTL, size and checksum of the object.", \ 1, 1 #define CLI_PURGE_URL \ Modified: branches/2.0/varnish-cache/include/http_headers.h =================================================================== --- branches/2.0/varnish-cache/include/http_headers.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/http_headers.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -28,6 +28,8 @@ * * $Id$ * + * Argument list: + * --------------------------------------- * a Http header name * b session field name * c Request(1)/Response(2) bitfield @@ -38,8 +40,6 @@ * * see [RFC2616 13.5.1 End-to-end and Hop-by-hop Headers] * - * a b c d e f g - *-------------------------------------------------------------------- */ #ifndef HTTPH_R_PASS @@ -51,52 +51,51 @@ #define HTTPH_A_DELIVER (1 << 5) /* Response (o->c) for deliver */ #endif -HTTPH("Keep-Alive", H_Keep_Alive, 3, 3, HTTPH_R_PASS|HTTPH_A_PASS|HTTPH_R_FETCH, 0, 0) /* RFC2068 */ - -HTTPH("Accept", H_Accept, 1, 0, 0, 0, 0) /* RFC2616 14.1 */ -HTTPH("Accept-Charset", H_Accept_Charset, 1, 0, 0, 0, 0) /* RFC2616 14.2 */ -HTTPH("Accept-Encoding", H_Accept_Encoding, 1, 0, 0, 0, 0) /* RFC2616 14.3 */ -HTTPH("Accept-Language", H_Accept_Language, 1, 0, 0, 0, 0) /* RFC2616 14.4 */ -HTTPH("Accept-Ranges", H_Accept_Ranges, 2, 3, HTTPH_R_PASS|HTTPH_A_PASS|HTTPH_R_FETCH|HTTPH_A_INS, 0, 0) /* RFC2616 14.5 */ -HTTPH("Age", H_Age, 2, 0, HTTPH_A_INS, 0, 0) /* RFC2616 14.6 */ -HTTPH("Allow", H_Allow, 2, 0, 0, 0, 0) /* RFC2616 14.7 */ -HTTPH("Authorization", H_Authorization, 1, 0, 0, 0, 0) /* RFC2616 14.8 */ -HTTPH("Cache-Control", H_Cache_Control, 3, 3, HTTPH_R_PASS|HTTPH_R_FETCH, 0, 0) /* RFC2616 14.9 */ -HTTPH("Connection", H_Connection, 3, 3, HTTPH_R_PASS|HTTPH_A_PASS|HTTPH_R_FETCH|HTTPH_A_INS, 0, 0) /* RFC2616 14.10 */ -HTTPH("Content-Encoding", H_Content_Encoding, 2, 0, 0, 0, 0) /* RFC2616 14.11 */ -HTTPH("Content-Langugae", H_Content_Language, 2, 0, 0, 0, 0) /* RFC2616 14.12 */ -HTTPH("Content-Length", H_Content_Length, 2, 2, HTTPH_R_FETCH|HTTPH_A_INS, 0, 0) /* RFC2616 14.13 */ -HTTPH("Content-Location", H_Content_Location, 2, 0, 0, 0, 0) /* RFC2616 14.14 */ -HTTPH("Content-MD5", H_Content_MD5, 2, 0, 0, 0, 0) /* RFC2616 14.15 */ -HTTPH("Content-Range", H_Content_Range, 2, 3, HTTPH_R_PASS|HTTPH_A_PASS|HTTPH_R_FETCH|HTTPH_A_INS, 0, 0) /* RFC2616 14.16 */ -HTTPH("Content-Type", H_Content_Type, 2, 0, 0, 0, 0) /* RFC2616 14.17 */ -HTTPH("Date", H_Date, 2, 0, HTTPH_A_DELIVER, 0, 0) /* RFC2616 14.18 */ -HTTPH("ETag", H_ETag, 2, 0, 0, 0, 0) /* RFC2616 14.19 */ -HTTPH("Expect", H_Expect, 1, 0, 0, 0, 0) /* RFC2616 14.20 */ -HTTPH("Expires", H_Expires, 2, 0, 0, 0, 0) /* RFC2616 14.21 */ -HTTPH("From", H_From, 1, 0, 0, 0, 0) /* RFC2616 14.22 */ -HTTPH("Host", H_Host, 1, 0, 0, 0, 0) /* RFC2616 14.23 */ -HTTPH("If-Match", H_If_Match, 1, 1, HTTPH_R_FETCH, 0, 0) /* RFC2616 14.24 */ -HTTPH("If-Modified-Since", H_If_Modified_Since, 1, 1, HTTPH_R_FETCH, 0, 0) /* RFC2616 14.25 */ -HTTPH("If-None-Match", H_If_None_Match, 1, 1, HTTPH_R_FETCH, 0, 0) /* RFC2616 14.26 */ -HTTPH("If-Range", H_If_Range, 1, 1, HTTPH_R_FETCH, 0, 0) /* RFC2616 14.27 */ -HTTPH("If-Unmodified-Since", H_If_Unmodifed_Since, 1, 1, HTTPH_R_FETCH, 0, 0) /* RFC2616 14.28 */ -HTTPH("Last-Modified", H_Last_Modified, 2, 0, 0, 0, 0) /* RFC2616 14.29 */ -HTTPH("Location", H_Location, 2, 0, 0, 0, 0) /* RFC2616 14.30 */ -HTTPH("Max-Forwards", H_Max_Forwards, 1, 0, 0, 0, 0) /* RFC2616 14.31 */ -HTTPH("Pragma", H_Pragma, 1, 0, 0, 0, 0) /* RFC2616 14.32 */ -HTTPH("Proxy-Authenticate", H_Proxy_Authenticate, 2, 3, HTTPH_R_FETCH|HTTPH_A_INS, 0, 0) /* RFC2616 14.33 */ -HTTPH("Proxy-Authorization", H_Proxy_Authorization, 1, 3, HTTPH_R_FETCH|HTTPH_A_INS, 0, 0) /* RFC2616 14.34 */ -HTTPH("Range", H_Range, 1, 0, 0, 0, 0) /* RFC2616 14.35 */ -HTTPH("Referer", H_Referer, 1, 0, 0, 0, 0) /* RFC2616 14.36 */ -HTTPH("Retry-After", H_Retry_After, 2, 0, 0, 0, 0) /* RFC2616 14.37 */ -HTTPH("Server", H_Server, 2, 0, 0, 0, 0) /* RFC2616 14.38 */ -HTTPH("TE", H_TE, 1, 3, HTTPH_R_PASS|HTTPH_A_PASS|HTTPH_R_FETCH|HTTPH_A_INS, 0, 0) /* RFC2616 14.39 */ -HTTPH("Trailer", H_Trailer, 1, 3, HTTPH_R_PASS|HTTPH_A_PASS|HTTPH_R_FETCH|HTTPH_A_INS, 0, 0) /* RFC2616 14.40 */ -HTTPH("Transfer-Encoding", H_Transfer_Encoding, 2, 3, HTTPH_R_PASS|HTTPH_A_PASS|HTTPH_R_FETCH|HTTPH_A_INS, 0, 0) /* RFC2616 14.41 */ -HTTPH("Upgrade", H_Upgrade, 2, 3, HTTPH_R_PASS|HTTPH_A_PASS|HTTPH_R_FETCH|HTTPH_A_INS, 0, 0) /* RFC2616 14.42 */ -HTTPH("User-Agent", H_User_Agent, 1, 0, 0, 0, 0) /* RFC2616 14.43 */ -HTTPH("Vary", H_Vary, 2, 0, 0, 0, 0) /* RFC2616 14.44 */ -HTTPH("Via", H_Via, 2, 0, 0, 0, 0) /* RFC2616 14.45 */ -HTTPH("Warning", H_Warning, 2, 0, 0, 0, 0) /* RFC2616 14.46 */ -HTTPH("WWW-Authenticate", H_WWW_Authenticate, 2, 0, 0, 0, 0) /* RFC2616 14.47 */ +HTTPH("Keep-Alive", H_Keep_Alive, 3, 3, HTTPH_R_PASS | HTTPH_A_PASS | HTTPH_R_FETCH, 0, 0) /* RFC2068 */ +HTTPH("Accept", H_Accept, 1, 0, 0, 0, 0) /* RFC2616 14.1 */ +HTTPH("Accept-Charset", H_Accept_Charset, 1, 0, 0, 0, 0) /* RFC2616 14.2 */ +HTTPH("Accept-Encoding", H_Accept_Encoding, 1, 0, 0, 0, 0) /* RFC2616 14.3 */ +HTTPH("Accept-Language", H_Accept_Language, 1, 0, 0, 0, 0) /* RFC2616 14.4 */ +HTTPH("Accept-Ranges", H_Accept_Ranges, 2, 3, HTTPH_R_PASS | HTTPH_A_PASS | HTTPH_R_FETCH | HTTPH_A_INS, 0, 0) /* RFC2616 14.5 */ +HTTPH("Age", H_Age, 2, 0, HTTPH_A_INS, 0, 0) /* RFC2616 14.6 */ +HTTPH("Allow", H_Allow, 2, 0, 0, 0, 0) /* RFC2616 14.7 */ +HTTPH("Authorization", H_Authorization, 1, 0, 0, 0, 0) /* RFC2616 14.8 */ +HTTPH("Cache-Control", H_Cache_Control, 3, 3, HTTPH_R_PASS | HTTPH_R_FETCH, 0, 0) /* RFC2616 14.9 */ +HTTPH("Connection", H_Connection, 3, 3, HTTPH_R_PASS | HTTPH_A_PASS | HTTPH_R_FETCH | HTTPH_A_INS, 0, 0) /* RFC2616 14.10 */ +HTTPH("Content-Encoding", H_Content_Encoding, 2, 0, 0, 0, 0) /* RFC2616 14.11 */ +HTTPH("Content-Langugae", H_Content_Language, 2, 0, 0, 0, 0) /* RFC2616 14.12 */ +HTTPH("Content-Length", H_Content_Length, 2, 2, HTTPH_R_FETCH | HTTPH_A_INS, 0, 0) /* RFC2616 14.13 */ +HTTPH("Content-Location", H_Content_Location, 2, 0, 0, 0, 0) /* RFC2616 14.14 */ +HTTPH("Content-MD5", H_Content_MD5, 2, 0, 0, 0, 0) /* RFC2616 14.15 */ +HTTPH("Content-Range", H_Content_Range, 2, 3, HTTPH_R_PASS | HTTPH_A_PASS | HTTPH_R_FETCH | HTTPH_A_INS, 0, 0) /* RFC2616 14.16 */ +HTTPH("Content-Type", H_Content_Type, 2, 0, 0, 0, 0) /* RFC2616 14.17 */ +HTTPH("Date", H_Date, 2, 0, HTTPH_A_DELIVER, 0, 0) /* RFC2616 14.18 */ +HTTPH("ETag", H_ETag, 2, 0, 0, 0, 0) /* RFC2616 14.19 */ +HTTPH("Expect", H_Expect, 1, 0, 0, 0, 0) /* RFC2616 14.20 */ +HTTPH("Expires", H_Expires, 2, 0, 0, 0, 0) /* RFC2616 14.21 */ +HTTPH("From", H_From, 1, 0, 0, 0, 0) /* RFC2616 14.22 */ +HTTPH("Host", H_Host, 1, 0, 0, 0, 0) /* RFC2616 14.23 */ +HTTPH("If-Match", H_If_Match, 1, 1, HTTPH_R_FETCH, 0, 0) /* RFC2616 14.24 */ +HTTPH("If-Modified-Since", H_If_Modified_Since, 1, 1, HTTPH_R_FETCH, 0, 0) /* RFC2616 14.25 */ +HTTPH("If-None-Match", H_If_None_Match, 1, 1, HTTPH_R_FETCH, 0, 0) /* RFC2616 14.26 */ +HTTPH("If-Range", H_If_Range, 1, 1, HTTPH_R_FETCH, 0, 0) /* RFC2616 14.27 */ +HTTPH("If-Unmodified-Since", H_If_Unmodifed_Since, 1, 1, HTTPH_R_FETCH, 0, 0) /* RFC2616 14.28 */ +HTTPH("Last-Modified", H_Last_Modified, 2, 0, 0, 0, 0) /* RFC2616 14.29 */ +HTTPH("Location", H_Location, 2, 0, 0, 0, 0) /* RFC2616 14.30 */ +HTTPH("Max-Forwards", H_Max_Forwards, 1, 0, 0, 0, 0) /* RFC2616 14.31 */ +HTTPH("Pragma", H_Pragma, 1, 0, 0, 0, 0) /* RFC2616 14.32 */ +HTTPH("Proxy-Authenticate", H_Proxy_Authenticate, 2, 3, HTTPH_R_FETCH | HTTPH_A_INS, 0, 0) /* RFC2616 14.33 */ +HTTPH("Proxy-Authorization", H_Proxy_Authorization, 1, 3, HTTPH_R_FETCH | HTTPH_A_INS, 0, 0) /* RFC2616 14.34 */ +HTTPH("Range", H_Range, 1, 0, 0, 0, 0) /* RFC2616 14.35 */ +HTTPH("Referer", H_Referer, 1, 0, 0, 0, 0) /* RFC2616 14.36 */ +HTTPH("Retry-After", H_Retry_After, 2, 0, 0, 0, 0) /* RFC2616 14.37 */ +HTTPH("Server", H_Server, 2, 0, 0, 0, 0) /* RFC2616 14.38 */ +HTTPH("TE", H_TE, 1, 3, HTTPH_R_PASS | HTTPH_A_PASS | HTTPH_R_FETCH | HTTPH_A_INS, 0, 0) /* RFC2616 14.39 */ +HTTPH("Trailer", H_Trailer, 1, 3, HTTPH_R_PASS | HTTPH_A_PASS | HTTPH_R_FETCH | HTTPH_A_INS, 0, 0) /* RFC2616 14.40 */ +HTTPH("Transfer-Encoding", H_Transfer_Encoding, 2, 3, HTTPH_R_PASS | HTTPH_A_PASS | HTTPH_R_FETCH | HTTPH_A_INS, 0, 0) /* RFC2616 14.41 */ +HTTPH("Upgrade", H_Upgrade, 2, 3, HTTPH_R_PASS | HTTPH_A_PASS | HTTPH_R_FETCH | HTTPH_A_INS, 0, 0) /* RFC2616 14.42 */ +HTTPH("User-Agent", H_User_Agent, 1, 0, 0, 0, 0) /* RFC2616 14.43 */ +HTTPH("Vary", H_Vary, 2, 0, 0, 0, 0) /* RFC2616 14.44 */ +HTTPH("Via", H_Via, 2, 0, 0, 0, 0) /* RFC2616 14.45 */ +HTTPH("Warning", H_Warning, 2, 0, 0, 0, 0) /* RFC2616 14.46 */ +HTTPH("WWW-Authenticate", H_WWW_Authenticate, 2, 0, 0, 0, 0) /* RFC2616 14.47 */ Modified: branches/2.0/varnish-cache/include/libvarnish.h =================================================================== --- branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -60,8 +60,10 @@ void TCP_blocking(int sock); void TCP_nonblocking(int sock); #ifdef SOL_SOCKET -void TCP_name(const struct sockaddr *addr, unsigned l, char *abuf, unsigned alen, char *pbuf, unsigned plen); -int TCP_connect(int s, const struct sockaddr *name, socklen_t namelen, int msec); +void TCP_name(const struct sockaddr *addr, unsigned l, char *abuf, + unsigned alen, char *pbuf, unsigned plen); +int TCP_connect(int s, const struct sockaddr *name, socklen_t namelen, + int msec); void TCP_close(int *s); #endif @@ -88,7 +90,8 @@ * handle gracefully, such as malloc failure. */ -typedef void lbv_assert_f(const char *, const char *, int, const char *, int, int); +typedef void lbv_assert_f(const char *, const char *, int, const char *, + int, int); extern lbv_assert_f *lbv_assert; @@ -96,14 +99,14 @@ #define assert(e) ((void)(e)) #else /* WITH_ASSERTS */ #define assert(e) \ -do { \ +do { \ if (!(e)) \ lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 0); \ } while (0) #endif #define xxxassert(e) \ -do { \ +do { \ if (!(e)) \ lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 1); \ } while (0) @@ -114,7 +117,7 @@ #define XXXAZ(foo) do { xxxassert((foo) == 0); } while (0) #define XXXAN(foo) do { xxxassert((foo) != 0); } while (0) #define diagnostic(foo) assert(foo) -#define WRONG(expl) \ +#define WRONG(expl) \ do { \ lbv_assert(__func__, __FILE__, __LINE__, expl, errno, 3); \ } while (0) Modified: branches/2.0/varnish-cache/include/stat_field.h =================================================================== --- branches/2.0/varnish-cache/include/stat_field.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/stat_field.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -37,7 +37,8 @@ MAC_STAT(cache_miss, uint64_t, 'a', "Cache misses") MAC_STAT(backend_conn, uint64_t, 'a', "Backend connections success") -MAC_STAT(backend_unhealthy, uint64_t, 'a', "Backend connections not attempted") +MAC_STAT(backend_unhealthy, uint64_t, 'a', + "Backend connections not attempted") MAC_STAT(backend_busy, uint64_t, 'a', "Backend connections too many") MAC_STAT(backend_fail, uint64_t, 'a', "Backend connections failures") MAC_STAT(backend_reuse, uint64_t, 'a', "Backend connections reuses") Modified: branches/2.0/varnish-cache/include/varnishapi.h =================================================================== --- branches/2.0/varnish-cache/include/varnishapi.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/varnishapi.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -41,11 +41,13 @@ int base64_decode(char *d, unsigned dlen, const char *s); /* shmlog.c */ -typedef int vsl_handler(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr); +typedef int vsl_handler(void *priv, enum shmlogtag tag, unsigned fd, + unsigned len, unsigned spec, const char *ptr); #define VSL_S_CLIENT (1 << 0) #define VSL_S_BACKEND (1 << 1) #define VSL_ARGS "bCcdI:i:k:r:s:X:x:" -#define VSL_USAGE "[-bCcd] [-i tag] [-I regexp] [-k keep] [-r file] [-s skip] [-X regexp] [-x tag]" +#define VSL_USAGE "[-bCcd] [-i tag] [-I regexp] [-k keep]" \ + " [-r file] [-s skip] [-X regexp] [-x tag]" vsl_handler VSL_H_Print; struct VSL_data; struct VSL_data *VSL_New(void); @@ -60,6 +62,6 @@ extern const char *VSL_tags[256]; /* instance.c */ -int varnish_instance(const char *n_arg, char *name, size_t namelen, char *dir, size_t dirlen); - +int varnish_instance(const char *n_arg, char *name, size_t namelen, char *dir, + size_t dirlen); #endif Modified: branches/2.0/varnish-cache/include/vcl.h =================================================================== --- branches/2.0/varnish-cache/include/vcl.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/vcl.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -23,7 +23,7 @@ unsigned nref; unsigned busy; unsigned discard; - + unsigned nsrc; const char **srcname; const char **srcbody; Modified: branches/2.0/varnish-cache/include/vcl_returns.h =================================================================== --- branches/2.0/varnish-cache/include/vcl_returns.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/vcl_returns.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -34,18 +34,30 @@ #endif #ifdef VCL_MET_MAC -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_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)) +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_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) Modified: branches/2.0/varnish-cache/include/vct.h =================================================================== --- branches/2.0/varnish-cache/include/vct.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/vct.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -31,10 +31,10 @@ /* from libvarnish/vct.c */ -#define VCT_SP (1<<0) -#define VCT_CRLF (1<<1) -#define VCT_LWS (VCT_CRLF | VCT_SP) -#define VCT_CTL (1<<2) +#define VCT_SP (1<<0) +#define VCT_CRLF (1<<1) +#define VCT_LWS (VCT_CRLF | VCT_SP) +#define VCT_CTL (1<<2) #define VCT_ALPHA (1<<3) #define VCT_SEPARATOR (1<<4) #define VCT_DIGIT (1<<5) @@ -45,8 +45,8 @@ static inline int vct_is(unsigned char x, unsigned char y) { - - return (vct_typtab[x] & (y)); + + return (vct_typtab[x] & (y)); } #define vct_issp(x) vct_is(x, VCT_SP) Modified: branches/2.0/varnish-cache/include/vev.h =================================================================== --- branches/2.0/varnish-cache/include/vev.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/vev.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -40,7 +40,7 @@ struct vev { unsigned magic; -#define VEV_MAGIC 0x46bbd419 +#define VEV_MAGIC 0x46bbd419 /* pub */ const char *name; Modified: branches/2.0/varnish-cache/include/vqueue.h =================================================================== --- branches/2.0/varnish-cache/include/vqueue.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/vqueue.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -220,7 +220,8 @@ } while (0) #define VSTAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ - if ((VSTAILQ_NEXT((elm), field) = VSTAILQ_NEXT((tqelm), field)) == NULL)\ + if ((VSTAILQ_NEXT((elm), field) = \ + VSTAILQ_NEXT((tqelm), field)) == NULL) \ (head)->vstqh_last = &VSTAILQ_NEXT((elm), field); \ VSTAILQ_NEXT((tqelm), field) = (elm); \ } while (0) @@ -241,7 +242,8 @@ (VSTAILQ_EMPTY((head)) ? \ NULL : \ ((struct type *)(void *) \ - ((char *)((head)->vstqh_last) - __offsetof(struct type, field)))) + ((char *)((head)->vstqh_last) - \ + __offsetof(struct type, field)))) #define VSTAILQ_NEXT(elm, field) ((elm)->field.vstqe_next) @@ -320,7 +322,8 @@ #define VLIST_INSERT_HEAD(head, elm, field) do { \ if ((VLIST_NEXT((elm), field) = VLIST_FIRST((head))) != NULL) \ - VLIST_FIRST((head))->field.vle_prev = &VLIST_NEXT((elm), field);\ + VLIST_FIRST((head))->field.vle_prev = \ + &VLIST_NEXT((elm), field); \ VLIST_FIRST((head)) = (elm); \ (elm)->field.vle_prev = &VLIST_FIRST((head)); \ } while (0) @@ -329,7 +332,7 @@ #define VLIST_REMOVE(elm, field) do { \ if (VLIST_NEXT((elm), field) != NULL) \ - VLIST_NEXT((elm), field)->field.vle_prev = \ + VLIST_NEXT((elm), field)->field.vle_prev = \ (elm)->field.vle_prev; \ *(elm)->field.vle_prev = VLIST_NEXT((elm), field); \ } while (0) @@ -394,8 +397,9 @@ } while (0) #define VTAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ - if ((VTAILQ_NEXT((elm), field) = VTAILQ_NEXT((listelm), field)) != NULL)\ - VTAILQ_NEXT((elm), field)->field.vtqe_prev = \ + if ((VTAILQ_NEXT((elm), field) = \ + VTAILQ_NEXT((listelm), field)) != NULL) \ + VTAILQ_NEXT((elm), field)->field.vtqe_prev = \ &VTAILQ_NEXT((elm), field); \ else { \ (head)->vtqh_last = &VTAILQ_NEXT((elm), field); \ @@ -438,7 +442,7 @@ #define VTAILQ_REMOVE(head, elm, field) do { \ if ((VTAILQ_NEXT((elm), field)) != NULL) \ - VTAILQ_NEXT((elm), field)->field.vtqe_prev = \ + VTAILQ_NEXT((elm), field)->field.vtqe_prev = \ (elm)->field.vtqe_prev; \ else { \ (head)->vtqh_last = (elm)->field.vtqe_prev; \ Modified: branches/2.0/varnish-cache/include/vrt.h =================================================================== --- branches/2.0/varnish-cache/include/vrt.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/vrt.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -70,7 +70,7 @@ double connect_timeout; unsigned max_connections; - struct vrt_backend_probe probe; + struct vrt_backend_probe probe; }; /* @@ -92,9 +92,9 @@ }; struct vrt_dir_random { - const char *name; + const char *name; unsigned retries; - unsigned nmember; + unsigned nmember; const struct vrt_dir_random_entry *members; }; @@ -108,7 +108,7 @@ struct vrt_dir_round_robin { const char *name; - unsigned nmember; + unsigned nmember; const struct vrt_dir_round_robin_entry *members; }; @@ -137,7 +137,8 @@ void VRT_re_fini(void *); int VRT_re_match(const char *, void *re); 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 *); +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); @@ -149,7 +150,8 @@ enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ }; char *VRT_GetHdr(const struct sess *, enum gethdr_e where, const char *); -void VRT_SetHdr(const struct sess *, enum gethdr_e where, const char *, const char *, ...); +void VRT_SetHdr(const struct sess *, enum gethdr_e where, const char *, + const char *, ...); void VRT_handling(struct sess *sp, unsigned hand); /* Simple stuff */ @@ -163,9 +165,12 @@ 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 *); -void VRT_init_dir_round_robin(struct cli *, struct director **, const struct vrt_dir_round_robin *); +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: branches/2.0/varnish-cache/include/vsb.h =================================================================== --- branches/2.0/varnish-cache/include/vsb.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/include/vsb.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -63,9 +63,11 @@ int vsb_bcpy(struct vsb *, const void *, size_t); int vsb_cat(struct vsb *, const char *); int vsb_cpy(struct vsb *, const char *); -int vsb_printf(struct vsb *, const char *, ...) /* __printflike(2, 3) */; +int vsb_printf(struct vsb *, const char *, ...) + /* __printflike(2, 3) */; #ifdef va_start -int vsb_vprintf(struct vsb *, const char *, va_list) /* __printflike(2, 0) */; +int vsb_vprintf(struct vsb *, const char *, va_list) + /* __printflike(2, 0) */; #endif int vsb_putc(struct vsb *, int); int vsb_trim(struct vsb *); Modified: branches/2.0/varnish-cache/lib/libvarnish/assert.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/assert.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnish/assert.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -41,7 +41,8 @@ #include "libvarnish.h" static void -lbv_assert_default(const char *func, const char *file, int line, const char *cond, int err, int xxx) +lbv_assert_default(const char *func, const char *file, int line, + const char *cond, int err, int xxx) { if (xxx) { Modified: branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -225,11 +225,9 @@ #ifdef TEST_DRIVER /* Test driver -------------------------------------------------------*/ - #include #if 0 - static int cmp(void *priv, void *a, void *b) { @@ -295,11 +293,9 @@ dump(bh, "Delete", u); } printf("Deletes done\n"); - return (0); } #else - struct foo { unsigned idx; unsigned key; @@ -310,7 +306,6 @@ struct foo ff[N]; - static int cmp(void *priv, void *a, void *b) { @@ -359,12 +354,12 @@ struct binheap *bh; unsigned u, v; -#if 0 - srandomdev(); - u = random(); - printf("Seed %u\n", u); - srandom(u); -#endif + if (0) { + srandomdev(); + u = random(); + printf("Seed %u\n", u); + srandom(u); + } bh = binheap_new(NULL, cmp, update); for (u = 0; u < M; u++) { v = random() % N; Modified: branches/2.0/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/cli_common.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnish/cli_common.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -132,7 +132,8 @@ { cli_result(cli, CLIS_PARAM); - cli_out(cli, "Parameter error, use \"help [command]\" for more info.\n"); + cli_out(cli, + "Parameter error, use \"help [command]\" for more info.\n"); } int Modified: branches/2.0/varnish-cache/lib/libvarnish/num.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/num.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnish/num.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -125,45 +125,45 @@ uintmax_t val; const char *err; } test_cases[] = { - { "1", (uintmax_t)0, (uintmax_t)1 }, - { "1B", (uintmax_t)0, (uintmax_t)1<<0 }, - { "1 B", (uintmax_t)0, (uintmax_t)1<<0 }, - { "1.3B", (uintmax_t)0, (uintmax_t)1 }, - { "1.7B", (uintmax_t)0, (uintmax_t)2 }, + { "1", (uintmax_t)0, (uintmax_t)1 }, + { "1B", (uintmax_t)0, (uintmax_t)1<<0 }, + { "1 B", (uintmax_t)0, (uintmax_t)1<<0 }, + { "1.3B", (uintmax_t)0, (uintmax_t)1 }, + { "1.7B", (uintmax_t)0, (uintmax_t)2 }, - { "1024", (uintmax_t)0, (uintmax_t)1024 }, - { "1k", (uintmax_t)0, (uintmax_t)1<<10 }, - { "1kB", (uintmax_t)0, (uintmax_t)1<<10 }, - { "1.3kB", (uintmax_t)0, (uintmax_t)1331 }, - { "1.7kB", (uintmax_t)0, (uintmax_t)1741 }, + { "1024", (uintmax_t)0, (uintmax_t)1024 }, + { "1k", (uintmax_t)0, (uintmax_t)1<<10 }, + { "1kB", (uintmax_t)0, (uintmax_t)1<<10 }, + { "1.3kB", (uintmax_t)0, (uintmax_t)1331 }, + { "1.7kB", (uintmax_t)0, (uintmax_t)1741 }, - { "1048576", (uintmax_t)0, (uintmax_t)1048576 }, - { "1M", (uintmax_t)0, (uintmax_t)1<<20 }, - { "1MB", (uintmax_t)0, (uintmax_t)1<<20 }, - { "1.3MB", (uintmax_t)0, (uintmax_t)1363149 }, - { "1.7MB", (uintmax_t)0, (uintmax_t)1782579 }, + { "1048576", (uintmax_t)0, (uintmax_t)1048576 }, + { "1M", (uintmax_t)0, (uintmax_t)1<<20 }, + { "1MB", (uintmax_t)0, (uintmax_t)1<<20 }, + { "1.3MB", (uintmax_t)0, (uintmax_t)1363149 }, + { "1.7MB", (uintmax_t)0, (uintmax_t)1782579 }, - { "1073741824", (uintmax_t)0, (uintmax_t)1073741824 }, - { "1G", (uintmax_t)0, (uintmax_t)1<<30 }, - { "1GB", (uintmax_t)0, (uintmax_t)1<<30 }, - { "1.3GB", (uintmax_t)0, (uintmax_t)1395864371 }, - { "1.7GB", (uintmax_t)0, (uintmax_t)1825361101 }, + { "1073741824", (uintmax_t)0, (uintmax_t)1073741824 }, + { "1G", (uintmax_t)0, (uintmax_t)1<<30 }, + { "1GB", (uintmax_t)0, (uintmax_t)1<<30 }, + { "1.3GB", (uintmax_t)0, (uintmax_t)1395864371 }, + { "1.7GB", (uintmax_t)0, (uintmax_t)1825361101 }, - { "1099511627776", (uintmax_t)0, (uintmax_t)1099511627776ULL }, - { "1T", (uintmax_t)0, (uintmax_t)1<<40 }, - { "1TB", (uintmax_t)0, (uintmax_t)1<<40 }, - { "1.3TB", (uintmax_t)0, (uintmax_t)1429365116109ULL }, - { "1.7TB", (uintmax_t)0, (uintmax_t)1869169767219ULL }, + { "1099511627776", (uintmax_t)0, (uintmax_t)1099511627776ULL }, + { "1T", (uintmax_t)0, (uintmax_t)1<<40 }, + { "1TB", (uintmax_t)0, (uintmax_t)1<<40 }, + { "1.3TB", (uintmax_t)0, (uintmax_t)1429365116109ULL }, + { "1.7TB", (uintmax_t)0, (uintmax_t)1869169767219ULL }, { "1%", (uintmax_t)1024, (uintmax_t)10 }, { "2%", (uintmax_t)1024, (uintmax_t)20 }, { "3%", (uintmax_t)1024, (uintmax_t)31 }, /* Check the error checks */ - { "", 0, 0, err_miss_num }, - { "m", 0, 0, err_invalid_num }, - { "4%", 0, 0, err_abs_req }, - { "3*", 0, 0, err_invalid_suff }, + { "", 0, 0, err_miss_num }, + { "m", 0, 0, err_invalid_num }, + { "4%", 0, 0, err_abs_req }, + { "3*", 0, 0, err_invalid_suff }, /* TODO: add more */ Modified: branches/2.0/varnish-cache/lib/libvarnish/tcp.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/tcp.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnish/tcp.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -58,7 +58,8 @@ /*--------------------------------------------------------------------*/ void -TCP_name(const struct sockaddr *addr, unsigned l, char *abuf, unsigned alen, char *pbuf, unsigned plen) +TCP_name(const struct sockaddr *addr, unsigned l, char *abuf, unsigned alen, + char *pbuf, unsigned plen) { int i; @@ -119,7 +120,7 @@ /*-------------------------------------------------------------------- * Functions for controlling NONBLOCK mode. - * + * * We use FIONBIO because it is cheaper than fcntl(2), which requires * us to do two syscalls, one to get and one to set, the latter of * which mucks about a bit before it ends up calling ioctl(FIONBIO), Modified: branches/2.0/varnish-cache/lib/libvarnish/vct.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vct.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnish/vct.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -70,12 +70,12 @@ [0x1d] = VCT_CTL, [0x1e] = VCT_CTL, [0x1f] = VCT_CTL, - [0x20] = VCT_SP | VCT_SEPARATOR, - [0x22] = VCT_SEPARATOR, - [0x28] = VCT_SEPARATOR, - [0x29] = VCT_SEPARATOR, - [0x2c] = VCT_SEPARATOR, - [0x2f] = VCT_SEPARATOR, + [0x20] = VCT_SP | VCT_SEPARATOR, + [0x22] = VCT_SEPARATOR, + [0x28] = VCT_SEPARATOR, + [0x29] = VCT_SEPARATOR, + [0x2c] = VCT_SEPARATOR, + [0x2f] = VCT_SEPARATOR, [0x30] = VCT_DIGIT | VCT_HEX, [0x31] = VCT_DIGIT | VCT_HEX, [0x32] = VCT_DIGIT | VCT_HEX, @@ -86,13 +86,13 @@ [0x37] = VCT_DIGIT | VCT_HEX, [0x38] = VCT_DIGIT | VCT_HEX, [0x39] = VCT_DIGIT | VCT_HEX, - [0x3a] = VCT_SEPARATOR, - [0x3b] = VCT_SEPARATOR, - [0x3c] = VCT_SEPARATOR, - [0x3d] = VCT_SEPARATOR, - [0x3e] = VCT_SEPARATOR, - [0x3f] = VCT_SEPARATOR, - [0x40] = VCT_SEPARATOR, + [0x3a] = VCT_SEPARATOR, + [0x3b] = VCT_SEPARATOR, + [0x3c] = VCT_SEPARATOR, + [0x3d] = VCT_SEPARATOR, + [0x3e] = VCT_SEPARATOR, + [0x3f] = VCT_SEPARATOR, + [0x40] = VCT_SEPARATOR, [0x41] = VCT_UPALPHA | VCT_HEX, [0x42] = VCT_UPALPHA | VCT_HEX, [0x43] = VCT_UPALPHA | VCT_HEX, @@ -119,9 +119,9 @@ [0x58] = VCT_UPALPHA, [0x59] = VCT_UPALPHA, [0x5a] = VCT_UPALPHA, - [0x5b] = VCT_SEPARATOR, - [0x5c] = VCT_SEPARATOR, - [0x5d] = VCT_SEPARATOR, + [0x5b] = VCT_SEPARATOR, + [0x5c] = VCT_SEPARATOR, + [0x5d] = VCT_SEPARATOR, [0x61] = VCT_LOALPHA | VCT_HEX, [0x62] = VCT_LOALPHA | VCT_HEX, [0x63] = VCT_LOALPHA | VCT_HEX, @@ -148,7 +148,7 @@ [0x78] = VCT_LOALPHA, [0x79] = VCT_LOALPHA, [0x7a] = VCT_LOALPHA, - [0x7b] = VCT_SEPARATOR, - [0x7d] = VCT_SEPARATOR, + [0x7b] = VCT_SEPARATOR, + [0x7d] = VCT_SEPARATOR, [0x7f] = VCT_CTL, }; Modified: branches/2.0/varnish-cache/lib/libvarnish/version.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/version.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnish/version.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -43,5 +43,6 @@ { fprintf(stderr, "%s (%s-%s)\n", progname, PACKAGE_TARNAME, PACKAGE_VERSION); - fprintf(stderr, "Copyright (c) 2006-2008 Linpro AS / Verdens Gang AS\n"); + fprintf(stderr, + "Copyright (c) 2006-2008 Linpro AS / Verdens Gang AS\n"); } Modified: branches/2.0/varnish-cache/lib/libvarnish/vlu.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vlu.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnish/vlu.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -63,7 +63,7 @@ if (l->buf == NULL) { FREE_OBJ(l); l = NULL; - } + } } return (l); } Modified: branches/2.0/varnish-cache/lib/libvarnish/vss.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vss.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnish/vss.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -283,7 +283,7 @@ if (retval >= 0) break; } - for (n = 0; n < nvaddr; n++) + for (n = 0; n < nvaddr; n++) free(vaddr[n]); free(vaddr); free(addr); Modified: branches/2.0/varnish-cache/lib/libvarnishapi/instance.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnishapi/instance.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnishapi/instance.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -39,8 +39,7 @@ int varnish_instance(const char *n_arg, - char *name, size_t namelen, - char *dir, size_t dirlen) + char *name, size_t namelen, char *dir, size_t dirlen) { size_t len; Modified: branches/2.0/varnish-cache/lib/libvarnishapi/shmlog.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnishapi/shmlog.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvarnishapi/shmlog.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -362,7 +362,8 @@ /*--------------------------------------------------------------------*/ int -VSL_H_Print(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) +VSL_H_Print(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, + unsigned spec, const char *ptr) { FILE *fo = priv; int type; Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -52,7 +52,7 @@ struct acl_e { VTAILQ_ENTRY(acl_e) list; unsigned char data[VRT_ACL_MAXADDR + 1]; - unsigned mask; + unsigned mask; unsigned not; unsigned para; struct token *t_addr; @@ -74,9 +74,9 @@ if (ae2->mask < m) m = ae2->mask; for (; m >= 8; m -= 8) { - if (*p1 < *p2) + if (*p1 < *p2) return (-1); - if (*p1 > *p2) + if (*p1 > *p2) return (1); p1++; p2++; @@ -135,7 +135,8 @@ } static void -vcc_acl_emit_entry(struct tokenlist *tl, const struct acl_e *ae, int l, const unsigned char *u, int fam) +vcc_acl_emit_entry(struct tokenlist *tl, const struct acl_e *ae, int l, + const unsigned char *u, int fam) { struct acl_e *ae2; @@ -186,7 +187,7 @@ Fh(tl, 1, "/* Ignored ACL entry: %s%s", ae->para ? "\"(\" " : "", ae->not ? "\"!\" " : ""); EncToken(tl->fh, ae->t_addr); - if (ae->t_mask) + if (ae->t_mask) Fh(tl, 0, "/%u", ae->mask); Fh(tl, 0, "%s\n", ae->para ? " \")\"" : ""); Fh(tl, 1, " * getaddrinfo: %s */\n", @@ -322,7 +323,8 @@ } static void -vcc_acl_bot(const struct tokenlist *tl, const char *acln, int silent, const char *pfx) +vcc_acl_bot(const struct tokenlist *tl, const char *acln, int silent, + const char *pfx) { struct acl_e *ae; int depth, l, m, i; @@ -346,7 +348,7 @@ Fh(tl, 0, "\tunsigned int fam;\n"); else assert(0 == __LINE__); - + Fh(tl, 0, "\n"); Fh(tl, 0, "\ta = p;\n"); Fh(tl, 0, "\tVRT_memmove(&fam, a + %d, sizeof fam);\n", @@ -421,7 +423,7 @@ Fh(tl, 0, "\t%*sreturn (%d);\n", -i, "", ae->not ? 0 : 1); } - for (; 0 <= depth; depth--) + 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); @@ -439,7 +441,8 @@ vcc_NextToken(tl); ExpectErr(tl, ID); vcc_AddRef(tl, tl->t, R_ACL); - Fb(tl, 1, "match_acl_named_%.*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: Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -42,13 +42,13 @@ /*--------------------------------------------------------------------*/ -#define VCL_RET_MAC(l,u,b,i) \ +#define VCL_RET_MAC(l,u,b,i) \ static void \ parse_##l(struct tokenlist *tl) \ { \ \ - Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #u); \ - vcc_ProcAction(tl->curproc, i, tl->t); \ + Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #u); \ + vcc_ProcAction(tl->curproc, i, tl->t); \ vcc_NextToken(tl); \ } @@ -61,7 +61,7 @@ parse_restart_real(struct tokenlist *tl) { struct token *t1; - + t1 = VTAILQ_NEXT(tl->t, list); if (t1->tok == ID && vcc_IdIs(t1, "rollback")) { Fb(tl, 1, "VRT_Rollback(sp);\n"); @@ -201,7 +201,8 @@ Fb(tl, 0, "%u", vcc_UintVal(tl)); vcc_NextToken(tl); } else { - vsb_printf(tl->sb, "Cannot assign this variable type.\n"); + vsb_printf(tl->sb, + "Cannot assign this variable type.\n"); vcc_ErrWhere(tl, vt); return; } @@ -269,7 +270,7 @@ vcc_ExpectedStringval(tl); return; } - do + do Fb(tl, 0, ", "); while (vcc_StringVal(tl)); if (tl->t->tok != ';') { @@ -338,17 +339,17 @@ { vcc_NextToken(tl); - + Fb(tl, 1, "VRT_purge("); - + Expect(tl, '('); vcc_NextToken(tl); - + if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return; } - + Expect(tl, ')'); vcc_NextToken(tl); Fb(tl, 0, ", 0);\n"); @@ -362,17 +363,17 @@ { vcc_NextToken(tl); - + Fb(tl, 1, "VRT_purge("); - + Expect(tl, '('); vcc_NextToken(tl); - + if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return; } - + Expect(tl, ')'); vcc_NextToken(tl); Fb(tl, 0, ", 1);\n"); @@ -392,13 +393,13 @@ parse_panic(struct tokenlist *tl) { vcc_NextToken(tl); - + Fb(tl, 1, "VRT_panic(sp, "); if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return; } - do + do Fb(tl, 0, ", "); while (vcc_StringVal(tl)); Fb(tl, 0, " vrt_magic_string_end);\n"); @@ -410,13 +411,13 @@ 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 + do Fb(tl, 0, ", "); while (vcc_StringVal(tl)); Fb(tl, 0, " vrt_magic_string_end);\n"); @@ -432,21 +433,21 @@ } action_table[] = { { "restart", parse_restart_real }, #define VCL_RET_MAC(l, u, b, i) { #l, parse_##l }, -#define VCL_RET_MAC_E(l, u, b, i) VCL_RET_MAC(l, u, b, i) +#define VCL_RET_MAC_E(l, u, b, i) VCL_RET_MAC(l, u, b, i) #include "vcl_returns.h" #undef VCL_RET_MAC #undef VCL_RET_MAC_E /* Keep list sorted from here */ - { "call", parse_call }, + { "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 }, - { "synthetic", parse_synthetic }, - { "unset", parse_unset }, + { "remove", parse_unset }, /* backward compatibility */ + { "set", parse_set }, + { "synthetic", parse_synthetic }, + { "unset", parse_unset }, { NULL, NULL } }; Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -37,7 +37,7 @@ * 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 + * A VCL backend is a "named host", these can be referenced by name from * VCL directors, but not from VCL backends. * * The reason for this quasimadness is that we want to collect statistics @@ -90,13 +90,14 @@ } /*-------------------------------------------------------------------- - * Struct sockaddr is not really designed to be a compile time + * 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) +Emit_Sockaddr(struct tokenlist *tl, const struct token *t_host, + const char *port) { struct addrinfo *res, *res0, hint; int n4, n6, len, error, retval; @@ -118,7 +119,7 @@ if (res->ai_family == PF_INET) { if (n4++ == 0) emit = "ipv4_sockaddr"; - else + else multiple = "IPv4"; } else if (res->ai_family == PF_INET6) { if (n6++ == 0) @@ -155,12 +156,12 @@ 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) + 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) + if ((len % 8) == 7) Fh(tl, 0, "\n"); } Fh(tl, 0, "\n};\n"); @@ -188,7 +189,9 @@ */ static void -vcc_EmitBeIdent(struct vsb *v, const struct token *name, const struct token *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); @@ -276,7 +279,7 @@ vcc_NextToken(tl); for (; fs->name != NULL; fs++) { - if (!vcc_IdIs(t_field, fs->name + 1)) + if (!vcc_IdIs(t_field, fs->name + 1)) continue; if (fs->found == NULL) { fs->found = t_field; @@ -315,7 +318,8 @@ */ static void -vcc_ProbeRedef(struct tokenlist *tl, struct token **t_did, struct token *t_field) +vcc_ProbeRedef(struct tokenlist *tl, struct token **t_did, + struct token *t_field) { /* .url and .request are mutually exclusive */ @@ -446,25 +450,14 @@ } /*-------------------------------------------------------------------- - * Parse and emit a backend host definition + * Parse and emit a backend host definition * - * The syntax is the following: - * - * backend_host_def: - * '{' be_elements '}' - * - * be_elements: - * be_element - * be_element be_elements - * - * be_element: - * '.' name '=' value ';' - * * The struct vrt_backend is emitted to Fh(). */ static void -vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const struct token *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; @@ -627,7 +620,8 @@ */ void -vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const struct token *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; @@ -674,7 +668,8 @@ */ static void -vcc_ParseSimpleDirector(struct tokenlist *tl, const struct token *t_first, struct token *t_dir) +vcc_ParseSimpleDirector(struct tokenlist *tl, const struct token *t_first, + struct token *t_dir) { struct host *h; @@ -707,8 +702,8 @@ const char *name; parsedirector_f *func; } dirlist[] = { - { "random", vcc_ParseRandomDirector }, - { "round-robin", vcc_ParseRoundRobinDirector }, + { "random", vcc_ParseRandomDirector }, + { "round-robin", vcc_ParseRoundRobinDirector }, { NULL, NULL } }; @@ -738,7 +733,7 @@ t_policy = tl->t; vcc_NextToken(tl); - for (dl = dirlist; dl->name != NULL; dl++) + for (dl = dirlist; dl->name != NULL; dl++) if (vcc_IdIs(t_policy, dl->name)) break; if (dl->name == NULL) { Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -704,6 +704,4 @@ vcc_default_vcl_b = default_vcl; vcc_default_vcl_e = strchr(default_vcl, '\0'); assert(vcc_default_vcl_e != NULL); - - vcl_init_tnames(); } Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -158,10 +158,12 @@ /* vcc_backend.c */ struct fld_spec; -typedef void parsedirector_f(struct tokenlist *tl, const struct token *t_policy, const struct token *t_dir); +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); +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); @@ -203,7 +205,8 @@ void vcc_ExpectedStringval(struct tokenlist *tl); /* vcc_token.c */ -void vcc_Coord(const struct tokenlist *tl, struct vsb *vsb, const struct token *t); +void vcc_Coord(const struct tokenlist *tl, struct vsb *vsb, + const struct token *t); void vcc_ErrToken(const struct tokenlist *tl, const struct token *t); void vcc_ErrWhere(struct tokenlist *tl, const struct token *t); void vcc__Expect(struct tokenlist *tl, unsigned tok, int line); @@ -212,11 +215,14 @@ 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); -void vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char *e); +void vcc__ErrInternal(struct tokenlist *tl, const char *func, + unsigned line); +void vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, + const char *e); /* vcc_var.c */ -struct var *vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl); +struct var *vcc_FindVar(struct tokenlist *tl, const struct token *t, + struct var *vl); /* vcc_xref.c */ void vcc_AddDef(struct tokenlist *tl, struct token *t, enum ref_type type); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_dir_random.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_dir_random.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_dir_random.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -50,7 +50,8 @@ */ void -vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_policy, const 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; @@ -91,7 +92,7 @@ ExpectErr(tl, '{'); vcc_NextToken(tl); Fc(tl, 0, "\t{"); - + while (tl->t->tok != '}') { /* Member fields */ vcc_IsField(tl, &t_field, mfs); ERRCHK(tl); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_dir_round_robin.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -49,7 +49,8 @@ */ void -vcc_ParseRoundRobinDirector(struct tokenlist *tl, const struct token *t_policy, const struct token *t_dir) +vcc_ParseRoundRobinDirector(struct tokenlist *tl, const struct token *t_policy, + const struct token *t_dir) { struct token *t_field, *t_be; int nbh, nelem; @@ -58,9 +59,8 @@ fs = vcc_FldSpec(tl, "!backend", NULL); - Fc(tl, 0, - "\nstatic const struct vrt_dir_round_robin_entry vdrre_%.*s[] = {\n", - PF(t_dir)); + 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 */ first = ""; @@ -71,7 +71,7 @@ ExpectErr(tl, '{'); vcc_NextToken(tl); Fc(tl, 0, "\t{"); - + while (tl->t->tok != '}') { /* Member fields */ vcc_IsField(tl, &t_field, fs); ERRCHK(tl); @@ -103,8 +103,7 @@ 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)); + 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: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -13,211 +13,145 @@ #include "vcc_priv.h" #include "vsb.h" +#define M1() do {*q = p + 1; return (p[0]); } while (0) +#define M2(c, t) do {if (p[1] == (c)) { *q = p + 2; return (t); }} while (0) + unsigned vcl_fixed_token(const char *p, const char **q) { switch (p[0]) { case '!': - if (p[1] == '=') { - *q = p + 2; - return (T_NEQ); - } - *q = p + 1; - return (p[0]); + M2('=', T_NEQ); + M1(); case '%': - *q = p + 1; - return (p[0]); + M1(); case '&': - if (p[1] == '&') { - *q = p + 2; - return (T_CAND); - } - *q = p + 1; - return (p[0]); + M2('&', T_CAND); + M1(); case '(': - *q = p + 1; - return (p[0]); + M1(); case ')': - *q = p + 1; - return (p[0]); + M1(); case '*': - if (p[1] == '=') { - *q = p + 2; - return (T_MUL); - } - *q = p + 1; - return (p[0]); + M2('=', T_MUL); + M1(); case '+': - if (p[1] == '=') { - *q = p + 2; - return (T_INCR); - } - if (p[1] == '+') { - *q = p + 2; - return (T_INC); - } - *q = p + 1; - return (p[0]); + M2('=', T_INCR); + M2('+', T_INC); + M1(); case ',': - *q = p + 1; - return (p[0]); + M1(); case '-': - if (p[1] == '=') { - *q = p + 2; - return (T_DECR); - } - if (p[1] == '-') { - *q = p + 2; - return (T_DEC); - } - *q = p + 1; - return (p[0]); + M2('=', T_DECR); + M2('-', T_DEC); + M1(); case '.': - *q = p + 1; - return (p[0]); + M1(); case '/': - if (p[1] == '=') { - *q = p + 2; - return (T_DIV); - } - *q = p + 1; - return (p[0]); + M2('=', T_DIV); + M1(); case ';': - *q = p + 1; - return (p[0]); + M1(); case '<': - if (p[1] == '=') { - *q = p + 2; - return (T_LEQ); - } - if (p[1] == '<') { - *q = p + 2; - return (T_SHL); - } - *q = p + 1; - return (p[0]); + M2('=', T_LEQ); + M2('<', T_SHL); + M1(); case '=': - if (p[1] == '=') { - *q = p + 2; - return (T_EQ); - } - *q = p + 1; - return (p[0]); + M2('=', T_EQ); + M1(); case '>': - if (p[1] == '>') { - *q = p + 2; - return (T_SHR); - } - if (p[1] == '=') { - *q = p + 2; - return (T_GEQ); - } - *q = p + 1; - return (p[0]); + M2('>', T_SHR); + M2('=', T_GEQ); + M1(); case 'e': - if (p[1] == 'l' && p[2] == 's' && - p[3] == 'i' && p[4] == 'f' && !isvar(p[5])) { + if (p[1] == 'l' && p[2] == 's' && p[3] == 'i' && + p[4] == 'f' && !isvar(p[5])) { *q = p + 5; return (T_ELSIF); } - if (p[1] == 'l' && p[2] == 's' && - p[3] == 'e' && p[4] == 'i' && p[5] == 'f' - && !isvar(p[6])) { + 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[1] == 'l' && p[2] == 's' && - p[3] == 'e' && !isvar(p[4])) { + 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[1] == 'n' && p[2] == 'c' && - p[3] == 'l' && p[4] == 'u' && p[5] == 'd' && - p[6] == 'e' && !isvar(p[7])) { + 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[1] == 'f' && !isvar(p[2])) { - *q = p + 2; - return (T_IF); - } + M2('f', T_IF); return (0); case '{': - *q = p + 1; - return (p[0]); + M1(); case '|': - if (p[1] == '|') { - *q = p + 2; - return (T_COR); - } - *q = p + 1; - return (p[0]); + M2('|', T_COR); + M1(); case '}': - *q = p + 1; - return (p[0]); + M1(); case '~': - *q = p + 1; - return (p[0]); + M1(); default: return (0); } } -const char *vcl_tnames[256]; +const char *vcl_tnames[256] = { + ['!'] = "'!'", + ['%'] = "'%'", + ['&'] = "'&'", + ['('] = "'('", + [')'] = "')'", + ['*'] = "'*'", + ['+'] = "'+'", + [','] = "','", + ['-'] = "'-'", + ['.'] = "'.'", + ['/'] = "'/'", + ['<'] = "'<'", + ['='] = "'='", + ['>'] = "'>'", + ['{'] = "'{'", + ['}'] = "'}'", + ['|'] = "'|'", + ['~'] = "'~'", + [';'] = "';'", + [CNUM] = "CNUM", + [CSRC] = "CSRC", + [CSTR] = "CSTR", + [EOI] = "EOI", + [ID] = "ID", + [T_CAND] = "&&", + [T_COR] = "||", + [T_DEC] = "--", + [T_DECR] = "-=", + [T_DIV] = "/=", + [T_ELSE] = "else", + [T_ELSEIF] = "elseif", + [T_ELSIF] = "elsif", + [T_EQ] = "==", + [T_GEQ] = ">=", + [T_IF] = "if", + [T_INC] = "++", + [T_INCLUDE] = "include", + [T_INCR] = "+=", + [T_LEQ] = "<=", + [T_MUL] = "*=", + [T_NEQ] = "!=", + [T_SHL] = "<<", + [T_SHR] = ">>", + [VAR] = "VAR", +}; void -vcl_init_tnames(void) -{ - vcl_tnames['!'] = "'!'"; - vcl_tnames['%'] = "'%'"; - vcl_tnames['&'] = "'&'"; - vcl_tnames['('] = "'('"; - vcl_tnames[')'] = "')'"; - vcl_tnames['*'] = "'*'"; - vcl_tnames['+'] = "'+'"; - vcl_tnames[','] = "','"; - vcl_tnames['-'] = "'-'"; - vcl_tnames['.'] = "'.'"; - vcl_tnames['/'] = "'/'"; - vcl_tnames['<'] = "'<'"; - vcl_tnames['='] = "'='"; - vcl_tnames['>'] = "'>'"; - vcl_tnames['{'] = "'{'"; - vcl_tnames['}'] = "'}'"; - vcl_tnames['|'] = "'|'"; - vcl_tnames['~'] = "'~'"; - vcl_tnames[';'] = "';'"; - vcl_tnames[CNUM] = "CNUM"; - vcl_tnames[CSRC] = "CSRC"; - vcl_tnames[CSTR] = "CSTR"; - vcl_tnames[EOI] = "EOI"; - vcl_tnames[ID] = "ID"; - vcl_tnames[T_CAND] = "&&"; - vcl_tnames[T_COR] = "||"; - vcl_tnames[T_DEC] = "--"; - vcl_tnames[T_DECR] = "-="; - vcl_tnames[T_DIV] = "/="; - vcl_tnames[T_ELSE] = "else"; - vcl_tnames[T_ELSEIF] = "elseif"; - vcl_tnames[T_ELSIF] = "elsif"; - vcl_tnames[T_EQ] = "=="; - vcl_tnames[T_GEQ] = ">="; - vcl_tnames[T_IF] = "if"; - vcl_tnames[T_INC] = "++"; - vcl_tnames[T_INCLUDE] = "include"; - vcl_tnames[T_INCR] = "+="; - vcl_tnames[T_LEQ] = "<="; - vcl_tnames[T_MUL] = "*="; - vcl_tnames[T_NEQ] = "!="; - vcl_tnames[T_SHL] = "<<"; - vcl_tnames[T_SHR] = ">>"; - vcl_tnames[VAR] = "VAR"; -} - -void vcl_output_lang_h(struct vsb *sb) { vsb_cat(sb, "#define VCL_RET_ERROR (1 << 0)\n"); @@ -230,287 +164,185 @@ 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"); - vsb_cat(sb, " * NB: This file is machine generated, DO NOT EDIT!\n"); - vsb_cat(sb, " *\n"); - vsb_cat(sb, " * Edit vcc_gen_fixed_token.tcl instead\n"); - vsb_cat(sb, " */\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "struct sess;\n"); - vsb_cat(sb, "struct cli;\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "typedef void vcl_init_f(struct cli *);\n"); - vsb_cat(sb, "typedef void vcl_fini_f(struct cli *);\n"); - vsb_cat(sb, "typedef int vcl_func_f(struct sess *sp);\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "struct VCL_conf {\n"); - vsb_cat(sb, " unsigned magic;\n"); - vsb_cat(sb, "#define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, " struct director **director;\n"); - vsb_cat(sb, " unsigned ndirector;\n"); - vsb_cat(sb, " struct vrt_ref *ref;\n"); - vsb_cat(sb, " unsigned nref;\n"); - vsb_cat(sb, " unsigned busy;\n"); - vsb_cat(sb, " unsigned discard;\n"); - vsb_cat(sb, " \n"); - vsb_cat(sb, " unsigned nsrc;\n"); - vsb_cat(sb, " const char **srcname;\n"); - vsb_cat(sb, " const char **srcbody;\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, " unsigned nhashcount;\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"); - vsb_cat(sb, " vcl_func_f *recv_func;\n"); - vsb_cat(sb, " vcl_func_f *pipe_func;\n"); - vsb_cat(sb, " vcl_func_f *pass_func;\n"); - vsb_cat(sb, " vcl_func_f *hash_func;\n"); - vsb_cat(sb, " vcl_func_f *miss_func;\n"); - vsb_cat(sb, " vcl_func_f *hit_func;\n"); - vsb_cat(sb, " vcl_func_f *fetch_func;\n"); - vsb_cat(sb, " vcl_func_f *deliver_func;\n"); - vsb_cat(sb, " vcl_func_f *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"); - vsb_cat(sb, " * Copyright (c) 2006-2008 Linpro AS\n"); - vsb_cat(sb, " * All rights reserved.\n"); - vsb_cat(sb, " *\n"); - vsb_cat(sb, " * Author: Poul-Henning Kamp \n"); - vsb_cat(sb, " *\n"); - vsb_cat(sb, " * Redistribution and use in source and binary forms, with or without\n"); - vsb_cat(sb, " * modification, are permitted provided that the following conditions\n"); - vsb_cat(sb, " * are met:\n"); - vsb_cat(sb, " * 1. Redistributions of source code must retain the above copyright\n"); - vsb_cat(sb, " * notice, this list of conditions and the following disclaimer.\n"); - vsb_cat(sb, " * 2. Redistributions in binary form must reproduce the above copyright\n"); - vsb_cat(sb, " * notice, this list of conditions and the following disclaimer in the\n"); - vsb_cat(sb, " * documentation and/or other materials provided with the distribution.\n"); - vsb_cat(sb, " *\n"); - vsb_cat(sb, " * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\n"); - vsb_cat(sb, " * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n"); - vsb_cat(sb, " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n"); - vsb_cat(sb, " * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE\n"); - vsb_cat(sb, " * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n"); - vsb_cat(sb, " * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n"); - vsb_cat(sb, " * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n"); - vsb_cat(sb, " * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n"); - vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n"); - vsb_cat(sb, " * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"); - vsb_cat(sb, " * SUCH DAMAGE.\n"); - vsb_cat(sb, " *\n"); - vsb_cat(sb, " * $Id$\n"); - vsb_cat(sb, " *\n"); - vsb_cat(sb, " * Runtime support for compiled VCL programs.\n"); - vsb_cat(sb, " *\n"); - vsb_cat(sb, " * XXX: When this file is changed, lib/libvcl/vcc_gen_fixed_token.tcl\n"); - vsb_cat(sb, " * XXX: *MUST* be rerun.\n"); - vsb_cat(sb, " */\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "struct sess;\n"); - vsb_cat(sb, "struct vsb;\n"); - vsb_cat(sb, "struct cli;\n"); - vsb_cat(sb, "struct director;\n"); - vsb_cat(sb, "struct VCL_conf;\n"); - 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, "extern void *vrt_magic_string_end;\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "struct vrt_backend_probe {\n"); - vsb_cat(sb, " const char *url;\n"); - vsb_cat(sb, " const char *request;\n"); - vsb_cat(sb, " double timeout;\n"); - vsb_cat(sb, " double interval;\n"); - vsb_cat(sb, " unsigned window;\n"); - vsb_cat(sb, " unsigned threshold;\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, " const char *vcl_name;\n"); - vsb_cat(sb, " const char *ident;\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, " const 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, " double connect_timeout;\n"); - vsb_cat(sb, " unsigned max_connections;\n"); - vsb_cat(sb, " struct vrt_backend_probe probe;\n"); - vsb_cat(sb, "};\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "/*\n"); - vsb_cat(sb, " * A director with a predictable reply\n"); - vsb_cat(sb, " */\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "struct vrt_dir_simple {\n"); - vsb_cat(sb, " const char *name;\n"); - vsb_cat(sb, " const struct vrt_backend *host;\n"); - vsb_cat(sb, "};\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "/*\n"); - vsb_cat(sb, " * A director with an unpredictable reply\n"); - vsb_cat(sb, " */\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "struct vrt_dir_random_entry {\n"); - vsb_cat(sb, " const struct vrt_backend *host;\n"); - vsb_cat(sb, " double weight;\n"); - vsb_cat(sb, "};\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "struct vrt_dir_random {\n"); - vsb_cat(sb, " const char *name;\n"); - vsb_cat(sb, " unsigned retries;\n"); - vsb_cat(sb, " unsigned nmember;\n"); - vsb_cat(sb, " const struct vrt_dir_random_entry *members;\n"); - 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"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "struct vrt_ref {\n"); - vsb_cat(sb, " unsigned source;\n"); - vsb_cat(sb, " unsigned offset;\n"); - vsb_cat(sb, " unsigned line;\n"); - vsb_cat(sb, " unsigned pos;\n"); - vsb_cat(sb, " unsigned count;\n"); - vsb_cat(sb, " const char *token;\n"); - vsb_cat(sb, "};\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "/* ACL related */\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"); - vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n"); - vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); - vsb_cat(sb, "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"); - vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); - vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n"); - vsb_cat(sb, "int VRT_switch_config(const char *);\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BEREQ };\n"); - vsb_cat(sb, "char *VRT_GetHdr(const struct sess *, enum gethdr_e where, const char *);\n"); - vsb_cat(sb, "void VRT_SetHdr(const struct sess *, enum gethdr_e where, const char *, const char *, ...);\n"); - vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "/* Simple stuff */\n"); - vsb_cat(sb, "int VRT_strcmp(const char *s1, const char *s2);\n"); - vsb_cat(sb, "void VRT_memmove(void *dst, const void *src, unsigned len);\n"); - vsb_cat(sb, "\n"); - 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"); - 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"); - vsb_cat(sb, "char *VRT_int_string(const struct sess *sp, int);\n"); - vsb_cat(sb, "char *VRT_double_string(const struct sess *sp, double);\n"); - vsb_cat(sb, "const char *VRT_backend_string(struct sess *sp);\n"); - vsb_cat(sb, "\n"); - vsb_cat(sb, "#define VRT_done(sp, hand) \\\n"); - vsb_cat(sb, " do { \\\n"); - vsb_cat(sb, " VRT_handling(sp, hand); \\\n"); - vsb_cat(sb, " return (1); \\\n"); - vsb_cat(sb, " } while (0)\n"); - vsb_cat(sb, "/*\n"); - vsb_cat(sb, " * $Id$\n"); - vsb_cat(sb, " *\n"); - vsb_cat(sb, " * NB: This file is machine generated, DO NOT EDIT!\n"); - vsb_cat(sb, " *\n"); - vsb_cat(sb, " * Edit vcc_gen_obj.tcl instead\n"); - vsb_cat(sb, " */\n"); - 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"); - vsb_cat(sb, "void VRT_l_req_url(const struct sess *, const char *, ...);\n"); - vsb_cat(sb, "const char * VRT_r_req_proto(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_req_proto(const struct sess *, const char *, ...);\n"); - vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n"); - vsb_cat(sb, "struct director * VRT_r_req_backend(struct sess *);\n"); - vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct director *);\n"); - 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"); - vsb_cat(sb, "void VRT_l_bereq_url(const struct sess *, const char *, ...);\n"); - vsb_cat(sb, "const char * VRT_r_bereq_proto(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_bereq_proto(const struct sess *, const char *, ...);\n"); - vsb_cat(sb, "const char * VRT_r_obj_proto(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_proto(const struct sess *, const char *, ...);\n"); - vsb_cat(sb, "int VRT_r_obj_status(const struct sess *);\n"); - 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, "int VRT_r_obj_hits(const struct sess *);\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"); - vsb_cat(sb, "void VRT_l_obj_ttl(const struct sess *, double);\n"); - vsb_cat(sb, "double VRT_r_obj_grace(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_grace(const struct sess *, double);\n"); - vsb_cat(sb, "double VRT_r_obj_prefetch(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_prefetch(const struct sess *, double);\n"); - vsb_cat(sb, "double VRT_r_obj_lastuse(const struct sess *);\n"); - vsb_cat(sb, "const char * VRT_r_obj_hash(const struct sess *);\n"); - vsb_cat(sb, "const char * VRT_r_resp_proto(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_proto(const struct sess *, const char *, ...);\n"); - vsb_cat(sb, "int VRT_r_resp_status(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_status(const struct sess *, int);\n"); - vsb_cat(sb, "const char * VRT_r_resp_response(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_resp_response(const struct sess *, const char *, ...);\n"); - vsb_cat(sb, "double VRT_r_now(const struct sess *);\n"); - vsb_cat(sb, "unsigned VRT_r_req_backend_healthy(const struct sess *);\n"); + + /* ../../include/vcl.h */ + + vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3098 2008-08-18 08"); + vsb_cat(sb, ":18:43Z phk $\n *\n * NB: This file is machine genera"); + vsb_cat(sb, "ted, DO NOT EDIT!\n *\n * Edit vcc_gen_fixed_token.tcl"); + vsb_cat(sb, " instead\n */\n\nstruct sess;\nstruct cli;\n\ntypedef "); + vsb_cat(sb, "void vcl_init_f(struct cli *);\ntypedef void vcl_fini_"); + vsb_cat(sb, "f(struct cli *);\ntypedef int vcl_func_f(struct sess *"); + vsb_cat(sb, "sp);\n\nstruct VCL_conf {\n\tunsigned magic;\n#"); + vsb_cat(sb, "define VCL_CONF_MAGIC 0x7406c509 /* from /dev/ra"); + vsb_cat(sb, "ndom */\n\n struct director **director;\n "); + vsb_cat(sb, " unsigned ndirector;\n struct vrt_ref "); + vsb_cat(sb, " *ref;\n unsigned nref;\n unsigne"); + vsb_cat(sb, "d busy;\n unsigned discard;\n\n\t"); + vsb_cat(sb, "unsigned\tnsrc;\n\tconst char\t**srcname;\n\tconst cha"); + vsb_cat(sb, "r\t**srcbody;\n\n\tunsigned\tnhashcount;\n\n vc"); + vsb_cat(sb, "l_init_f *init_func;\n vcl_fini_f *fi"); + vsb_cat(sb, "ni_func;\n\n\tvcl_func_f\t*recv_func;\n\tvcl_func_f\t*"); + vsb_cat(sb, "pipe_func;\n\tvcl_func_f\t*pass_func;\n\tvcl_func_f\t*"); + vsb_cat(sb, "hash_func;\n\tvcl_func_f\t*miss_func;\n\tvcl_func_f\t*"); + vsb_cat(sb, "hit_func;\n\tvcl_func_f\t*fetch_func;\n\tvcl_func_f\t*"); + vsb_cat(sb, "deliver_func;\n\tvcl_func_f\t*prefetch_func;\n\tvcl_fu"); + vsb_cat(sb, "nc_f\t*timeout_func;\n\tvcl_func_f\t*discard_func;\n\t"); + vsb_cat(sb, "vcl_func_f\t*error_func;\n};\n"); + + /* ../../include/vrt.h */ + + vsb_cat(sb, "/*-\n * Copyright (c) 2006 Verdens Gang AS\n * Copyrig"); + vsb_cat(sb, "ht (c) 2006-2008 Linpro AS\n * All rights reserved.\n "); + vsb_cat(sb, "*\n * Author: Poul-Henning Kamp \n"); + vsb_cat(sb, " *\n * Redistribution and use in source and binary for"); + vsb_cat(sb, "ms, with or without\n * modification, are permitted pr"); + vsb_cat(sb, "ovided that the following conditions\n * are met:\n * "); + vsb_cat(sb, "1. Redistributions of source code must retain the abov"); + vsb_cat(sb, "e copyright\n * notice, this list of conditions and"); + vsb_cat(sb, " the following disclaimer.\n * 2. Redistributions in b"); + vsb_cat(sb, "inary form must reproduce the above copyright\n * n"); + vsb_cat(sb, "otice, this list of conditions and the following discl"); + vsb_cat(sb, "aimer in the\n * documentation and/or other materia"); + vsb_cat(sb, "ls provided with the distribution.\n *\n * THIS SOFTWA"); + vsb_cat(sb, "RE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'"); + vsb_cat(sb, "' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING"); + vsb_cat(sb, ", BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF ME"); + vsb_cat(sb, "RCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n *"); + vsb_cat(sb, " ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBU"); + vsb_cat(sb, "TORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTA"); + vsb_cat(sb, "L, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (I"); + vsb_cat(sb, "NCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUT"); + vsb_cat(sb, "E GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS"); + vsb_cat(sb, "; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON "); + vsb_cat(sb, "ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n"); + vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI"); + vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT"); + vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH D"); + vsb_cat(sb, "AMAGE.\n *\n * $Id: vrt.h 3234 2008-09-29 07:32:26Z ph"); + vsb_cat(sb, "k $\n *\n * Runtime support for compiled VCL programs."); + vsb_cat(sb, "\n *\n * XXX: When this file is changed, lib/libvcl/vc"); + vsb_cat(sb, "c_gen_fixed_token.tcl\n * XXX: *MUST* be rerun.\n */\n"); + vsb_cat(sb, "\nstruct sess;\nstruct vsb;\nstruct cli;\nstruct direc"); + vsb_cat(sb, "tor;\nstruct VCL_conf;\nstruct sockaddr;\n\n/*\n * A b"); + vsb_cat(sb, "ackend probe specification\n */\n\nextern void *vrt_ma"); + vsb_cat(sb, "gic_string_end;\n\nstruct vrt_backend_probe {\n\tconst"); + vsb_cat(sb, " char\t*url;\n\tconst char\t*request;\n\tdouble\t\ttim"); + vsb_cat(sb, "eout;\n\tdouble\t\tinterval;\n\tunsigned\twindow;\n\tu"); + vsb_cat(sb, "nsigned\tthreshold;\n};\n\n/*\n * A backend is a host+"); + vsb_cat(sb, "port somewhere on the network\n */\nstruct vrt_backend"); + vsb_cat(sb, " {\n\tconst char\t\t\t*vcl_name;\n\tconst char\t\t\t*i"); + vsb_cat(sb, "dent;\n\n\tconst char\t\t\t*hosthdr;\n\n\tconst unsign"); + vsb_cat(sb, "ed char\t\t*ipv4_sockaddr;\n\tconst unsigned char\t\t*"); + vsb_cat(sb, "ipv6_sockaddr;\n\n\tdouble\t\t\t\tconnect_timeout;\n\t"); + vsb_cat(sb, "unsigned\t\t\tmax_connections;\n\tstruct vrt_backend_p"); + vsb_cat(sb, "robe\tprobe;\n};\n\n/*\n * A director with a predictab"); + vsb_cat(sb, "le reply\n */\n\nstruct vrt_dir_simple {\n\tconst char"); + vsb_cat(sb, "\t\t\t\t*name;\n\tconst struct vrt_backend\t\t*host;\n"); + vsb_cat(sb, "};\n\n/*\n * A director with an unpredictable reply\n "); + vsb_cat(sb, "*/\n\nstruct vrt_dir_random_entry {\n\tconst struct vr"); + vsb_cat(sb, "t_backend\t\t*host;\n\tdouble\t\t\t\t\tweight;\n};\n\n"); + vsb_cat(sb, "struct vrt_dir_random {\n\tconst char\t\t\t\t*name;\n\t"); + vsb_cat(sb, "unsigned\t\t\t\tretries;\n\tunsigned\t\t\t\tnmember;\n"); + vsb_cat(sb, "\tconst struct vrt_dir_random_entry\t*members;\n};\n\n"); + vsb_cat(sb, "/*\n * A director with round robin selection\n */\n\ns"); + vsb_cat(sb, "truct vrt_dir_round_robin_entry {\n\tconst struct vrt_"); + vsb_cat(sb, "backend\t\t*host;\n};\n\nstruct vrt_dir_round_robin {\n"); + vsb_cat(sb, "\tconst char\t\t\t\t*name;\n\tunsigned\t\t\t\tnmember;"); + vsb_cat(sb, "\n\tconst struct vrt_dir_round_robin_entry\t*members;\n"); + vsb_cat(sb, "};\n\n\n/*\n * other stuff.\n * XXX: document when bor"); + vsb_cat(sb, "ed\n */\n\nstruct vrt_ref {\n\tunsigned\tsource;\n\tun"); + vsb_cat(sb, "signed\toffset;\n\tunsigned\tline;\n\tunsigned\tpos;\n"); + vsb_cat(sb, "\tunsigned\tcount;\n\tconst char\t*token;\n};\n\n/* AC"); + vsb_cat(sb, "L related */\n#define VRT_ACL_MAXADDR\t\t16\t/* max(IP"); + vsb_cat(sb, "v4, IPv6) */\n\nvoid VRT_acl_log(const struct sess *, "); + vsb_cat(sb, "const char *msg);\n\n/* Regexp related */\nvoid VRT_re"); + vsb_cat(sb, "_init(void **, const char *, int sub);\nvoid VRT_re_fi"); + vsb_cat(sb, "ni(void *);\nint VRT_re_match(const char *, void *re);"); + vsb_cat(sb, "\nint VRT_re_test(struct vsb *, const char *, int sub)"); + vsb_cat(sb, ";\nconst char *VRT_regsub(const struct sess *sp, int a"); + vsb_cat(sb, "ll, const char *,\n void *, const char *);\n\nvoid "); + vsb_cat(sb, "VRT_panic(struct sess *sp, const char *, ...);\nvoid "); + vsb_cat(sb, "VRT_purge(const char *, int hash);\n\nvoid VRT_count(c"); + vsb_cat(sb, "onst struct sess *, unsigned);\nint VRT_rewrite(const "); + vsb_cat(sb, "char *, const char *);\nvoid VRT_error(struct sess *, "); + vsb_cat(sb, "unsigned, const char *);\nint VRT_switch_config(const "); + vsb_cat(sb, "char *);\n\nenum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ"); + vsb_cat(sb, ", HDR_BEREQ };\nchar *VRT_GetHdr(const struct sess *, "); + vsb_cat(sb, "enum gethdr_e where, const char *);\nvoid VRT_SetHdr(c"); + vsb_cat(sb, "onst struct sess *, enum gethdr_e where, const char *,"); + vsb_cat(sb, "\n const char *, ...);\nvoid VRT_handling(struct se"); + vsb_cat(sb, "ss *sp, unsigned hand);\n\n/* Simple stuff */\nint VRT"); + vsb_cat(sb, "_strcmp(const char *s1, const char *s2);\nvoid VRT_mem"); + vsb_cat(sb, "move(void *dst, const void *src, unsigned len);\n\nvoi"); + vsb_cat(sb, "d VRT_ESI(struct sess *sp);\nvoid VRT_Rollback(struct "); + vsb_cat(sb, "sess *sp);\n\n/* Synthetic pages */\nvoid VRT_synth_pa"); + vsb_cat(sb, "ge(struct sess *sp, unsigned flags, const char *, ...)"); + vsb_cat(sb, ";\n\n/* Backend related */\nvoid VRT_init_dir_simple(s"); + vsb_cat(sb, "truct cli *, struct director **,\n const struct vrt"); + vsb_cat(sb, "_dir_simple *);\nvoid VRT_init_dir_random(struct cli *"); + vsb_cat(sb, ", struct director **,\n const struct vrt_dir_random"); + vsb_cat(sb, " *);\nvoid VRT_init_dir_round_robin(struct cli *, stru"); + vsb_cat(sb, "ct director **,\n const struct vrt_dir_round_robin "); + vsb_cat(sb, "*);\nvoid VRT_fini_dir(struct cli *, struct director *"); + vsb_cat(sb, ");\n\nchar *VRT_IP_string(const struct sess *sp, const"); + vsb_cat(sb, " struct sockaddr *sa);\nchar *VRT_int_string(const str"); + vsb_cat(sb, "uct sess *sp, int);\nchar *VRT_double_string(const str"); + vsb_cat(sb, "uct sess *sp, double);\nconst char *VRT_backend_string"); + vsb_cat(sb, "(struct sess *sp);\n\n#define VRT_done(sp, hand)\t\t\t"); + vsb_cat(sb, "\\\n\tdo {\t\t\t\t\t\\\n\t\tVRT_handling(sp, hand);\t\t"); + vsb_cat(sb, "\\\n\t\treturn (1);\t\t\t\\\n\t} while (0)\n"); + + /* ../../include/vrt_obj.h */ + + vsb_cat(sb, "/*\n * $Id: vrt_obj.h 3169 2008-09-08 09:49:01Z tfheen"); + vsb_cat(sb, " $\n *\n * NB: This file is machine generated, DO NOT"); + vsb_cat(sb, " EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n */\n\nst"); + vsb_cat(sb, "ruct sockaddr * VRT_r_client_ip(const struct sess *);\n"); + vsb_cat(sb, "struct sockaddr * VRT_r_server_ip(struct sess *);\nint"); + vsb_cat(sb, " VRT_r_server_port(struct sess *);\nconst char * VRT_r"); + vsb_cat(sb, "_req_request(const struct sess *);\nvoid VRT_l_req_req"); + vsb_cat(sb, "uest(const struct sess *, const char *, ...);\nconst c"); + vsb_cat(sb, "har * VRT_r_req_url(const struct sess *);\nvoid VRT_l_"); + vsb_cat(sb, "req_url(const struct sess *, const char *, ...);\ncons"); + vsb_cat(sb, "t char * VRT_r_req_proto(const struct sess *);\nvoid V"); + vsb_cat(sb, "RT_l_req_proto(const struct sess *, const char *, ...)"); + vsb_cat(sb, ";\nvoid VRT_l_req_hash(struct sess *, const char *);\n"); + vsb_cat(sb, "struct director * VRT_r_req_backend(struct sess *);\nv"); + vsb_cat(sb, "oid VRT_l_req_backend(struct sess *, struct director *"); + vsb_cat(sb, ");\nint VRT_r_req_restarts(const struct sess *);\ndoub"); + vsb_cat(sb, "le VRT_r_req_grace(struct sess *);\nvoid VRT_l_req_gra"); + vsb_cat(sb, "ce(struct sess *, double);\nconst char * VRT_r_req_xid"); + vsb_cat(sb, "(struct sess *);\nconst char * VRT_r_bereq_request(con"); + vsb_cat(sb, "st struct sess *);\nvoid VRT_l_bereq_request(const str"); + vsb_cat(sb, "uct sess *, const char *, ...);\nconst char * VRT_r_be"); + vsb_cat(sb, "req_url(const struct sess *);\nvoid VRT_l_bereq_url(co"); + vsb_cat(sb, "nst struct sess *, const char *, ...);\nconst char * V"); + vsb_cat(sb, "RT_r_bereq_proto(const struct sess *);\nvoid VRT_l_ber"); + vsb_cat(sb, "eq_proto(const struct sess *, const char *, ...);\ncon"); + vsb_cat(sb, "st char * VRT_r_obj_proto(const struct sess *);\nvoid "); + vsb_cat(sb, "VRT_l_obj_proto(const struct sess *, const char *, ..."); + vsb_cat(sb, ");\nint VRT_r_obj_status(const struct sess *);\nvoid V"); + vsb_cat(sb, "RT_l_obj_status(const struct sess *, int);\nconst char"); + vsb_cat(sb, " * VRT_r_obj_response(const struct sess *);\nvoid VRT_"); + vsb_cat(sb, "l_obj_response(const struct sess *, const char *, ...)"); + vsb_cat(sb, ";\nint VRT_r_obj_hits(const struct sess *);\nunsigned "); + vsb_cat(sb, "VRT_r_obj_cacheable(const struct sess *);\nvoid VRT_l_"); + vsb_cat(sb, "obj_cacheable(const struct sess *, unsigned);\ndouble "); + vsb_cat(sb, "VRT_r_obj_ttl(const struct sess *);\nvoid VRT_l_obj_tt"); + vsb_cat(sb, "l(const struct sess *, double);\ndouble VRT_r_obj_grac"); + vsb_cat(sb, "e(const struct sess *);\nvoid VRT_l_obj_grace(const st"); + vsb_cat(sb, "ruct sess *, double);\ndouble VRT_r_obj_prefetch(const"); + vsb_cat(sb, " struct sess *);\nvoid VRT_l_obj_prefetch(const struct"); + vsb_cat(sb, " sess *, double);\ndouble VRT_r_obj_lastuse(const stru"); + vsb_cat(sb, "ct sess *);\nconst char * VRT_r_obj_hash(const struct "); + vsb_cat(sb, "sess *);\nconst char * VRT_r_resp_proto(const struct s"); + vsb_cat(sb, "ess *);\nvoid VRT_l_resp_proto(const struct sess *, co"); + vsb_cat(sb, "nst char *, ...);\nint VRT_r_resp_status(const struct "); + vsb_cat(sb, "sess *);\nvoid VRT_l_resp_status(const struct sess *, "); + vsb_cat(sb, "int);\nconst char * VRT_r_resp_response(const struct s"); + vsb_cat(sb, "ess *);\nvoid VRT_l_resp_response(const struct sess *,"); + vsb_cat(sb, " const char *, ...);\ndouble VRT_r_now(const struct se"); + vsb_cat(sb, "ss *);\nunsigned VRT_r_req_backend_healthy(const struc"); + vsb_cat(sb, "t sess *);\n"); } Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-05 08:45:25 UTC (rev 3580) @@ -30,7 +30,7 @@ # Generate various .c and .h files for the VCL compiler and the interfaces # for it. -# These are the metods which can be called in the VCL program. +# These are the metods which can be called in the VCL program. # Second element is list of valid return actions. # set methods { @@ -66,7 +66,7 @@ # Language keywords # set keywords { - include + include if else elseif elsif } @@ -104,7 +104,8 @@ proc warns {fd} { puts $fd "/*" - puts $fd { * $Id$} + puts $fd \ + { * $Id$} puts $fd " *" puts $fd " * NB: This file is machine generated, DO NOT EDIT!" puts $fd " *" @@ -135,7 +136,7 @@ unsigned nref; unsigned busy; unsigned discard; - + unsigned nsrc; const char **srcname; const char **srcbody; @@ -160,12 +161,13 @@ puts $for "#ifdef VCL_RET_MAC" set i 0 foreach k $returns { + set u [string toupper $k] if {$k == "error"} { puts $for "#ifdef VCL_RET_MAC_E" - puts $for "VCL_RET_MAC_E($k, [string toupper $k], (1 << $i), $i)" + puts $for "VCL_RET_MAC_E($k, $u, (1 << $i), $i)" puts $for "#endif" } else { - puts $for "VCL_RET_MAC($k, [string toupper $k], (1 << $i), $i)" + puts $for "VCL_RET_MAC($k, $u, (1 << $i), $i)" } incr i } @@ -184,7 +186,7 @@ puts -nonewline $for "VCL_MET_MAC([lindex $m 0]" puts -nonewline $for ",[string toupper [lindex $m 0]]" set l [lindex $m 1] - puts -nonewline $for ",(VCL_RET_[string toupper [lindex $l 0]]" + puts -nonewline $for ",(\n VCL_RET_[string toupper [lindex $l 0]]" foreach r [lrange $l 1 end] { puts -nonewline $for "|VCL_RET_[string toupper $r]" } @@ -260,6 +262,9 @@ set seq [lsort [array names xx]] puts $fo { +#define M1() do {*q = p + 1; return (p[0]); } while (0) +#define M2(c, t) do {if (p[1] == (c)) { *q = p + 2; return (t); }} while (0) + unsigned vcl_fixed_token(const char *p, const char **q)} puts $fo "{" @@ -279,25 +284,33 @@ scan "$ch" "%c" cx puts $fo " case '$ch':" set retval "0" + set m1 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]} + puts $fo "\t\tM1();" + set m1 1 continue; } + if {[string length $k] == 2} { + puts -nonewline $fo " M2(" + puts -nonewline $fo "'[string index $k 1]'" + puts $fo ", [lindex $tt 1]);" + continue; + } puts -nonewline $fo " if (" 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 " + puts -nonewline $fo " &&" + if {[expr $i % 3] == 1} { + puts -nonewline $fo "\n\t\t " } + puts -nonewline $fo " " } puts -nonewline $fo "p\[$i\] == '[string index $k $i]'" } if {[lindex $tt 2]} { - if {![expr $i % 3]} { + if {[expr $i % 3] == 1} { puts -nonewline $fo "\n\t\t " } puts -nonewline $fo " && !isvar(p\[$i\])" @@ -307,8 +320,10 @@ puts $fo "\t\t\treturn ([lindex $tt 1]);" puts $fo "\t\t}" } - puts $fo "\t\treturn ($retval);" -} + if {$m1 == 0} { + puts $fo "\t\treturn ($retval);" + } +} puts $fo " default:" puts $fo " return (0);" @@ -316,17 +331,14 @@ puts $fo "}" puts $fo "" -puts $fo "const char *vcl_tnames\[256\];\n" -puts $fo "void" -puts $fo "vcl_init_tnames(void)" -puts $fo "{" +puts $fo "const char *vcl_tnames\[256\] = {" foreach i $token2 { - puts $fo "\tvcl_tnames\[[lindex $i 0]\] = \"[lindex $i 0]\";" + puts $fo "\t\[[lindex $i 0]\] = \"[lindex $i 0]\"," } foreach i $tokens { - puts $fo "\tvcl_tnames\[[lindex $i 0]\] = \"[lindex $i 1]\";" + puts $fo "\t\[[lindex $i 0]\] = \"[lindex $i 1]\"," } -puts $fo "}" +puts $fo "};" #---------------------------------------------------------------------- # Create the C-code which emits the boilerplate definitions for the @@ -335,11 +347,43 @@ proc copy_include {n} { global fo + puts $fo "\n\t/* $n */\n" set fi [open $n] + set n 0 while {[gets $fi a] >= 0} { - regsub -all {\\} $a {\\\\} a - puts $fo "\tvsb_cat(sb, \"$a\\n\");" + for {set b 0} {$b < [string length $a]} {incr b} { + if {$n == 0} { + puts -nonewline $fo "\tvsb_cat(sb, \"" + } + set c [string index $a $b] + if {"$c" == "\\"} { + puts -nonewline $fo "\\\\" + incr n + } elseif {"$c" == "\t"} { + puts -nonewline $fo "\\t" + incr n + } else { + puts -nonewline $fo "$c" + } + incr n + if {$n > 53} { + puts $fo "\");" + set n 0 + } + } + if {$n == 0} { + puts -nonewline $fo "\tvsb_cat(sb, \"" + } + puts -nonewline $fo "\\n" + incr n 2 + if {$n > 53} { + puts $fo "\");" + set n 0 + } } + if {$n > 0} { + puts $fo "\");" + } close $fi } @@ -349,7 +393,8 @@ puts $fo "{" set i 0 foreach k $returns { - puts $fo "\tvsb_cat(sb, \"#define VCL_RET_[string toupper $k] (1 << $i)\\n\");" + set u [string toupper $k] + puts $fo "\tvsb_cat(sb, \"#define VCL_RET_$u (1 << $i)\\n\");" incr i } Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2009-02-05 08:45:25 UTC (rev 3580) @@ -261,15 +261,31 @@ proc method_map {m} { - set l "" + set l1 "" + set l2 "" foreach i $m { - append l " | " - append l VCL_MET_[string toupper $i] + if {[string length $l2] > 55} { + if {$l1 != ""} { + append l1 "\n\t " + } + append l1 "$l2" + set l2 "" + } + if {$l2 != "" || $l1 != ""} { + append l2 " | " + } + append l2 VCL_MET_[string toupper $i] } - if {$l == ""} { + if {$l2 != ""} { + if {$l1 != ""} { + append l1 "\n\t " + } + append l1 "$l2" + } + if {$l1 == ""} { return "0" } - return [string range $l 3 end] + return $l1 } proc vars {v pa} { @@ -289,12 +305,12 @@ puts $fo "\t\{ \"$n\", $t, [string length $n]," } if {$a == "RO" || $a == "RW"} { - puts $fo "\t \"VRT_r_${m}($pa)\"," + puts -nonewline $fo "\t \"VRT_r_${m}($pa)\"," if {![regexp HDR_ $t]} { puts $fp "$tt($t) VRT_r_${m}($ty);" } } else { - puts $fo "\t NULL," + puts -nonewline $fo "\t NULL," } if {$a == "WO" || $a == "RW"} { puts $fo "\t \"VRT_l_${m}($pa, \"," @@ -307,7 +323,7 @@ } else { puts $fo "\t NULL," } - puts $fo "\t V_$a," + puts -nonewline $fo "\t V_$a," if {![regexp HDR_ $t]} { puts $fo "\t 0," } else { Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -12,235 +12,195 @@ struct var vcc_vars[] = { { "client.ip", IP, 9, - "VRT_r_client_ip(sp)", - NULL, - V_RO, - 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_ERROR + "VRT_r_client_ip(sp)", NULL, + V_RO, 0, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH + | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + | 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_ERROR + "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_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_ERROR + "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_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_ERROR + "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_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_ERROR + "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_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_ERROR + "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_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_ERROR + "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_ERROR }, { "req.hash", HASH, 8, - NULL, - "VRT_l_req_hash(sp, ", - V_WO, - 0, + NULL, "VRT_l_req_hash(sp, ", + V_WO, 0, 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_ERROR + "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_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_ERROR + "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_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_ERROR + "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_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 + "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, ", - V_RW, - 0, + "VRT_r_bereq_request(sp)", "VRT_l_bereq_request(sp, ", + V_RW, 0, VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS | VCL_MET_FETCH }, { "bereq.url", STRING, 9, - "VRT_r_bereq_url(sp)", - "VRT_l_bereq_url(sp, ", - V_RW, - 0, + "VRT_r_bereq_url(sp)", "VRT_l_bereq_url(sp, ", + V_RW, 0, VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS | VCL_MET_FETCH }, { "bereq.proto", STRING, 11, - "VRT_r_bereq_proto(sp)", - "VRT_l_bereq_proto(sp, ", - V_RW, - 0, + "VRT_r_bereq_proto(sp)", "VRT_l_bereq_proto(sp, ", + V_RW, 0, VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS | VCL_MET_FETCH }, { "bereq.http.", HEADER, 11, - "VRT_r_bereq_http_(sp)", - "VRT_l_bereq_http_(sp, ", - V_RW, - "HDR_BEREQ", + "VRT_r_bereq_http_(sp)", "VRT_l_bereq_http_(sp, ", + V_RW, "HDR_BEREQ", VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS | VCL_MET_FETCH }, { "obj.proto", STRING, 9, - "VRT_r_obj_proto(sp)", - "VRT_l_obj_proto(sp, ", - V_RW, - 0, + "VRT_r_obj_proto(sp)", "VRT_l_obj_proto(sp, ", + V_RW, 0, 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, + "VRT_r_obj_status(sp)", "VRT_l_obj_status(sp, ", + V_RW, 0, VCL_MET_FETCH | VCL_MET_ERROR }, { "obj.response", STRING, 12, - "VRT_r_obj_response(sp)", - "VRT_l_obj_response(sp, ", - V_RW, - 0, + "VRT_r_obj_response(sp)", "VRT_l_obj_response(sp, ", + V_RW, 0, VCL_MET_FETCH | VCL_MET_ERROR }, { "obj.hits", INT, 8, - "VRT_r_obj_hits(sp)", - NULL, - V_RO, - 0, + "VRT_r_obj_hits(sp)", NULL, + V_RO, 0, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER }, { "obj.http.", HEADER, 9, - "VRT_r_obj_http_(sp)", - "VRT_l_obj_http_(sp, ", - V_RW, - "HDR_OBJ", + "VRT_r_obj_http_(sp)", "VRT_l_obj_http_(sp, ", + V_RW, "HDR_OBJ", VCL_MET_HIT | VCL_MET_FETCH | 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_ERROR + "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_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_ERROR + "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_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_ERROR + "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_ERROR }, { "obj.prefetch", RTIME, 12, - "VRT_r_obj_prefetch(sp)", - "VRT_l_obj_prefetch(sp, ", - V_RW, - 0, + "VRT_r_obj_prefetch(sp)", "VRT_l_obj_prefetch(sp, ", + V_RW, 0, VCL_MET_FETCH | VCL_MET_PREFETCH }, { "obj.lastuse", TIME, 11, - "VRT_r_obj_lastuse(sp)", - NULL, - V_RO, - 0, - VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT | VCL_MET_ERROR + "VRT_r_obj_lastuse(sp)", NULL, + V_RO, 0, + 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_ERROR + "VRT_r_obj_hash(sp)", NULL, + V_RO, 0, + VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + | VCL_MET_ERROR }, { "resp.proto", STRING, 10, - "VRT_r_resp_proto(sp)", - "VRT_l_resp_proto(sp, ", - V_RW, - 0, + "VRT_r_resp_proto(sp)", "VRT_l_resp_proto(sp, ", + V_RW, 0, VCL_MET_DELIVER }, { "resp.status", INT, 11, - "VRT_r_resp_status(sp)", - "VRT_l_resp_status(sp, ", - V_RW, - 0, + "VRT_r_resp_status(sp)", "VRT_l_resp_status(sp, ", + V_RW, 0, VCL_MET_DELIVER }, { "resp.response", STRING, 13, - "VRT_r_resp_response(sp)", - "VRT_l_resp_response(sp, ", - V_RW, - 0, + "VRT_r_resp_response(sp)", "VRT_l_resp_response(sp, ", + V_RW, 0, VCL_MET_DELIVER }, { "resp.http.", HEADER, 10, - "VRT_r_resp_http_(sp)", - "VRT_l_resp_http_(sp, ", - V_RW, - "HDR_RESP", + "VRT_r_resp_http_(sp)", "VRT_l_resp_http_(sp, ", + V_RW, "HDR_RESP", VCL_MET_DELIVER }, { "now", TIME, 3, - "VRT_r_now(sp)", - NULL, - V_RO, - 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT + "VRT_r_now(sp)", NULL, + V_RO, 0, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH + | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "req.backend.healthy", BOOL, 19, - "VRT_r_req_backend_healthy(sp)", - NULL, - V_RO, - 0, - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER | VCL_MET_DISCARD | VCL_MET_TIMEOUT + "VRT_r_req_backend_healthy(sp)", NULL, + V_RO, 0, + VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH + | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER + | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { NULL } }; Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -56,7 +56,7 @@ #define C(tl, sep) do { \ Fb(tl, 1, "VRT_count(sp, %u)%s\n", ++tl->cnt, sep); \ - tl->t->cnt = tl->cnt; \ + tl->t->cnt = tl->cnt; \ } while (0) /*-------------------------------------------------------------------- @@ -615,7 +615,7 @@ break; case ID: for (tp = toplev; tp->name != NULL; tp++) { - if (!vcc_IdIs(tl->t, tp->name)) + if (!vcc_IdIs(tl->t, tp->name)) continue; tp->func(tl); break; Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_priv.h =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_priv.h 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_priv.h 2009-02-05 08:45:25 UTC (rev 3580) @@ -40,7 +40,6 @@ #define isvar(c) (isident(c) || (c) == '.') unsigned vcl_fixed_token(const char *p, const char **q); extern const char *vcl_tnames[256]; -void vcl_init_tnames(void); void vcl_output_lang_h(struct vsb *sb); #define PF(t) (int)((t)->e - (t)->b), (t)->b Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_string.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_string.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_string.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -88,7 +88,7 @@ Expect(tl, ','); vcc_NextToken(tl); - + Expect(tl, CSTR); p = vcc_regexp(tl, 1); vcc_NextToken(tl); @@ -96,7 +96,7 @@ Expect(tl, ','); vcc_NextToken(tl); - + if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return (0); @@ -119,7 +119,7 @@ */ int -vcc_StringVal(struct tokenlist *tl) +vcc_StringVal(struct tokenlist *tl) { struct var *vp; @@ -154,9 +154,8 @@ Fb(tl, 0, "VRT_backend_string(sp)"); break; default: - vsb_printf(tl->sb, - "String representation of '%s' not implemented yet.\n", - vp->name); + vsb_printf(tl->sb, "String representation of '%s'" + " not implemented yet.\n", vp->name); vcc_ErrWhere(tl, tl->t); return (0); } Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_token.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_token.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -113,7 +113,7 @@ vcc_icoord(tl->sb, t, &l); vsb_printf(tl->sb, "\n"); - + x = y = 0; e = t->src->e; for (p = l; p < e && *p != '\n'; p++) { @@ -221,7 +221,7 @@ assert(t->tok == ID); for (q = t->b; q < t->e; q++) { - if (!isalnum(*q) && *q != '_') + if (!isalnum(*q) && *q != '_') return (0); } return (1); @@ -394,7 +394,7 @@ vcc_ErrWhere(tl, tl->t); return; } - + /* Recognize long-strings */ if (*p == '{' && p[1] == '"') { for (q = p + 2; q < sp->e; q++) { @@ -406,7 +406,7 @@ if (q < sp->e) { p = q + 2; u = tl->t->e - tl->t->b; - u -= 4; /* {" ... "} */ + u -= 4; /* {" ... "} */ tl->t->dec = TlAlloc(tl, u + 1 ); AN(tl->t->dec); memcpy(tl->t->dec, tl->t->b + 2, u); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c 2009-02-05 08:37:41 UTC (rev 3579) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c 2009-02-05 08:45:25 UTC (rev 3580) @@ -340,13 +340,14 @@ struct procuse *pu; VTAILQ_FOREACH(pu, &p->uses, list) - if (!(pu->v->methods & m->bitval)) + if (!(pu->v->methods & m->bitval)) return (pu); return (NULL); } static int -vcc_CheckUseRecurse(struct tokenlist *tl, const struct proc *p, struct method *m) +vcc_CheckUseRecurse(struct tokenlist *tl, const struct proc *p, + struct method *m) { struct proccall *pc; struct procuse *pu; @@ -356,7 +357,7 @@ vsb_printf(tl->sb, "Variable \"%.*s\" is not available in %s\n", PF(pu->t), m->name); - vcc_ErrWhere(tl, pu->t); + vcc_ErrWhere(tl, pu->t); vsb_printf(tl->sb, "\n...in function \"%.*s\"\n", PF(p->name)); vcc_ErrWhere(tl, p->name); From tfheen at projects.linpro.no Thu Feb 5 08:50:14 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 09:50:14 +0100 (CET) Subject: r3581 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090205085014.8811F97BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 09:50:13 +0100 (Thu, 05 Feb 2009) New Revision: 3581 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/b00001.vtc Log: Merge r3328: No need to delay for varnishd to update stats, varnishtest does this for us Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/b00001.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00001.vtc 2009-02-05 08:45:25 UTC (rev 3580) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00001.vtc 2009-02-05 08:50:13 UTC (rev 3581) @@ -19,9 +19,6 @@ expect resp.status == 200 } -run -# Give varnish a chance to update stats -delay .1 - varnish v1 -expect n_object == 0 varnish v1 -expect client_conn == 1 varnish v1 -expect client_req == 1 From tfheen at projects.linpro.no Thu Feb 5 08:59:23 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 09:59:23 +0100 (CET) Subject: r3582 - in branches/2.0/varnish-cache/bin/varnishtest: . tests Message-ID: <20090205085923.48DE797BD8@projects.linpro.no> Author: tfheen Date: 2009-02-05 09:59:22 +0100 (Thu, 05 Feb 2009) New Revision: 3582 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc Removed: branches/2.0/varnish-cache/bin/varnishtest/c00019.vtc Log: Merge r3331: OOps, wrong directory Deleted: branches/2.0/varnish-cache/bin/varnishtest/c00019.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/c00019.vtc 2009-02-05 08:50:13 UTC (rev 3581) +++ branches/2.0/varnish-cache/bin/varnishtest/c00019.vtc 2009-02-05 08:59:22 UTC (rev 3582) @@ -1,83 +0,0 @@ -# $Id$ - -test "Check purge counters and duplicate purge elimination" - -server s1 { - rxreq - txresp -hdr "foo: 1" -body "foo1" - rxreq - txresp -hdr "foo: 2" -body "foo2" - rxreq - txresp -hdr "foo: 3" -body "foo3" -} -start - -varnish v1 -vcl+backend {} -start - -varnish v1 -cliok "purge.url FOO" - -# There is one "magic" purge from boot -varnish v1 -expect n_purge_add == 2 -varnish v1 -cliok "purge.list" - -# Our fetch is not affected by the purge -# as the FOO-purge was preexisting -client c1 { - txreq -url /FOO - rxresp - expect resp.http.foo == 1 -} -run - -varnish v1 -cliok "purge.list" -varnish v1 -expect n_purge_obj_test == 0 -varnish v1 -expect n_purge_re_test == 0 - -# Add another purge -varnish v1 -cliok "purge.url FOO" -varnish v1 -expect n_purge_add == 3 -varnish v1 -cliok "purge.list" - -# The cached object will be purged, and a new -# fetched from the backend -client c1 { - txreq -url /FOO - rxresp - expect resp.http.foo == 2 -} -run - -varnish v1 -expect n_purge_obj_test == 1 -varnish v1 -expect n_purge_re_test == 1 -varnish v1 -cliok "purge.list" - -# Fetch the cached copy, just for grins -client c1 { - txreq -url /FOO - rxresp - expect resp.http.foo == 2 -} -run - - -# Now add another purge -varnish v1 -cliok "purge.url FOO" -varnish v1 -expect n_purge_add == 4 - -# Enable dup removal of purges -varnish v1 -cliok "param.set purge_dups on" - -# This should incapacitate the to previous FOO purges. -varnish v1 -cliok "purge.url FOO" -varnish v1 -expect n_purge_add == 5 -varnish v1 -expect n_purge_dups == 3 -varnish v1 -cliok "purge.list" - -# And we should get a fresh object from backend -client c1 { - txreq -url /FOO - rxresp - expect resp.http.foo == 3 -} -run - -# With only two objects having ever been compared -varnish v1 -expect n_purge_obj_test == 2 -varnish v1 -expect n_purge_re_test == 2 -varnish v1 -cliok "purge.list" - Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc (from rev 3331, trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-02-05 08:59:22 UTC (rev 3582) @@ -0,0 +1,83 @@ +# $Id$ + +test "Check purge counters and duplicate purge elimination" + +server s1 { + rxreq + txresp -hdr "foo: 1" -body "foo1" + rxreq + txresp -hdr "foo: 2" -body "foo2" + rxreq + txresp -hdr "foo: 3" -body "foo3" +} -start + +varnish v1 -vcl+backend {} -start + +varnish v1 -cliok "purge.url FOO" + +# There is one "magic" purge from boot +varnish v1 -expect n_purge_add == 2 +varnish v1 -cliok "purge.list" + +# Our fetch is not affected by the purge +# as the FOO-purge was preexisting +client c1 { + txreq -url /FOO + rxresp + expect resp.http.foo == 1 +} -run + +varnish v1 -cliok "purge.list" +varnish v1 -expect n_purge_obj_test == 0 +varnish v1 -expect n_purge_re_test == 0 + +# Add another purge +varnish v1 -cliok "purge.url FOO" +varnish v1 -expect n_purge_add == 3 +varnish v1 -cliok "purge.list" + +# The cached object will be purged, and a new +# fetched from the backend +client c1 { + txreq -url /FOO + rxresp + expect resp.http.foo == 2 +} -run + +varnish v1 -expect n_purge_obj_test == 1 +varnish v1 -expect n_purge_re_test == 1 +varnish v1 -cliok "purge.list" + +# Fetch the cached copy, just for grins +client c1 { + txreq -url /FOO + rxresp + expect resp.http.foo == 2 +} -run + + +# Now add another purge +varnish v1 -cliok "purge.url FOO" +varnish v1 -expect n_purge_add == 4 + +# Enable dup removal of purges +varnish v1 -cliok "param.set purge_dups on" + +# This should incapacitate the to previous FOO purges. +varnish v1 -cliok "purge.url FOO" +varnish v1 -expect n_purge_add == 5 +varnish v1 -expect n_purge_dups == 3 +varnish v1 -cliok "purge.list" + +# And we should get a fresh object from backend +client c1 { + txreq -url /FOO + rxresp + expect resp.http.foo == 3 +} -run + +# With only two objects having ever been compared +varnish v1 -expect n_purge_obj_test == 2 +varnish v1 -expect n_purge_re_test == 2 +varnish v1 -cliok "purge.list" + From tfheen at projects.linpro.no Thu Feb 5 09:03:41 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:03:41 +0100 (CET) Subject: r3583 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090205090341.26D6297BD8@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:03:40 +0100 (Thu, 05 Feb 2009) New Revision: 3583 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc Log: Merge r3332: Add a bit more coverage to this test. Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-02-05 08:59:22 UTC (rev 3582) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-02-05 09:03:40 UTC (rev 3583) @@ -56,16 +56,17 @@ } -run -# Now add another purge +# Now add another two purge, the hash should not be hit. +varnish v1 -cliok "purge.hash FOO" varnish v1 -cliok "purge.url FOO" -varnish v1 -expect n_purge_add == 4 +varnish v1 -expect n_purge_add == 5 # Enable dup removal of purges varnish v1 -cliok "param.set purge_dups on" # This should incapacitate the to previous FOO purges. varnish v1 -cliok "purge.url FOO" -varnish v1 -expect n_purge_add == 5 +varnish v1 -expect n_purge_add == 6 varnish v1 -expect n_purge_dups == 3 varnish v1 -cliok "purge.list" @@ -81,3 +82,6 @@ varnish v1 -expect n_purge_re_test == 2 varnish v1 -cliok "purge.list" +# Test a bogus regexp + +varnish v1 -clierr 106 "purge.url [[[" From tfheen at projects.linpro.no Thu Feb 5 09:07:26 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:07:26 +0100 (CET) Subject: r3584 - branches/2.0/varnish-cache Message-ID: <20090205090726.826811F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:07:26 +0100 (Thu, 05 Feb 2009) New Revision: 3584 Modified: branches/2.0/varnish-cache/configure.ac Log: Merge r3334: Check $target, not $host Strictly speaking, we should test $target, not $host - although in practice, varnish is not cross-buildable anyway due to the SO_RCVTIMEO / SO_SNDTIMEO tests. Modified: branches/2.0/varnish-cache/configure.ac =================================================================== --- branches/2.0/varnish-cache/configure.ac 2009-02-05 09:03:40 UTC (rev 3583) +++ branches/2.0/varnish-cache/configure.ac 2009-02-05 09:07:26 UTC (rev 3584) @@ -110,7 +110,7 @@ LIBS="${save_LIBS}" ## This one is tricky, there are multiple versions -case $host in +case $target in *-*-freebsd*) AC_CACHE_CHECK([whether sendfile works], [ac_cv_so_sendfile_works], @@ -144,7 +144,7 @@ fi ;; *) - AC_MSG_WARN([won't look for sendfile() on $host]) + AC_MSG_WARN([won't look for sendfile() on $target]) ;; esac @@ -178,13 +178,13 @@ [enable_kqueue=yes]) if test "$enable_kqueue" = yes; then - case $host in + case $target in *-*-freebsd* | *-*-darwin9* ) AC_CHECK_FUNCS([kqueue]) ;; *-*-bsd*) # No other BSD has a sufficiently recent implementation - AC_MSG_WARN([won't look for kqueue() on $host]) + AC_MSG_WARN([won't look for kqueue() on $target]) ac_cv_func_kqueue=no ;; esac @@ -330,7 +330,7 @@ if test "$ac_cv_env_VCC_CC_set" = "set"; then VCC_CC="$ac_cv_env_VCC_CC_value" else - case $host in + case $target in *-*-solaris*) VCC_CC="cc -Kpic -G -o %o %s" ;; @@ -353,7 +353,7 @@ JEMALLOC_SUBDIR=libjemalloc JEMALLOC_LDADD='$(top_builddir)/lib/libjemalloc/libjemalloc_mt.la' fi], -[case $host in #( +[case $target in #( *-*-linux*) JEMALLOC_SUBDIR=libjemalloc JEMALLOC_LDADD='$(top_builddir)/lib/libjemalloc/libjemalloc_mt.la' From tfheen at projects.linpro.no Thu Feb 5 09:12:16 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:12:16 +0100 (CET) Subject: r3585 - branches/2.0/varnish-cache/lib/libvarnish Message-ID: <20090205091216.3792B1F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:12:15 +0100 (Thu, 05 Feb 2009) New Revision: 3585 Modified: branches/2.0/varnish-cache/lib/libvarnish/flopen.c branches/2.0/varnish-cache/lib/libvarnish/vpf.c Log: Merge r3335: Sync with FreeBSD Modified: branches/2.0/varnish-cache/lib/libvarnish/flopen.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/flopen.c 2009-02-05 09:07:26 UTC (rev 3584) +++ branches/2.0/varnish-cache/lib/libvarnish/flopen.c 2009-02-05 09:12:15 UTC (rev 3585) @@ -26,17 +26,17 @@ * * $Id$ * Derived from: - * $FreeBSD: src/lib/libutil/flopen.c,v 1.7 2007/05/23 12:09:33 des Exp $ + * $FreeBSD: head/lib/libutil/flopen.c 184094 2008-10-20 18:11:30Z des $ */ #include "config.h" -#include #include #include #include #include +#include #include #include "config.h" @@ -46,8 +46,8 @@ flopen(const char *path, int flags, ...) { int fd, operation, serrno, trunc; - struct stat sb, fsb; struct flock lock; + struct stat sb, fsb; mode_t mode; #ifdef O_EXLOCK @@ -63,10 +63,9 @@ va_end(ap); } + memset(&lock, 0, sizeof lock); lock.l_type = ((flags & O_ACCMODE) == O_RDONLY) ? F_RDLCK : F_WRLCK; - lock.l_start = 0; lock.l_whence = SEEK_SET; - lock.l_len = 0; operation = (flags & O_NONBLOCK) ? F_SETLK : F_SETLKW; trunc = (flags & O_TRUNC); Modified: branches/2.0/varnish-cache/lib/libvarnish/vpf.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vpf.c 2009-02-05 09:07:26 UTC (rev 3584) +++ branches/2.0/varnish-cache/lib/libvarnish/vpf.c 2009-02-05 09:12:15 UTC (rev 3585) @@ -25,7 +25,7 @@ * * $Id$ * Derived from: - * $FreeBSD: src/lib/libutil/pidfile.c,v 1.5 2007/05/11 11:10:05 des Exp $ + * $FreeBSD: head/lib/libutil/pidfile.c 184091 2008-10-20 17:41:08Z des $ */ #include "config.h" @@ -230,14 +230,8 @@ static int _vpf_remove(struct pidfh *pfh, int freeit) { - struct flock lock; int error; - lock.l_type = F_UNLCK; - lock.l_start = 0; - lock.l_whence = SEEK_SET; - lock.l_len = 0; - error = vpf_verify(pfh); if (error != 0) { errno = error; @@ -246,10 +240,6 @@ if (unlink(pfh->pf_path) == -1) error = errno; - if (fcntl(pfh->pf_fd, F_SETLK, &lock) == -1) { - if (error == 0) - error = errno; - } if (close(pfh->pf_fd) == -1) { if (error == 0) error = errno; From tfheen at projects.linpro.no Thu Feb 5 09:17:39 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:17:39 +0100 (CET) Subject: r3586 - in branches/2.0/varnish-cache: bin/varnishadm bin/varnishd bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishstat bin/varnishtest bin/varnishtop lib/libvarnish lib/libvarnishapi lib/libvcl Message-ID: <20090205091739.507DD28370@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:17:38 +0100 (Thu, 05 Feb 2009) New Revision: 3586 Modified: branches/2.0/varnish-cache/bin/varnishadm/varnishadm.c branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/cache_http.c branches/2.0/varnish-cache/bin/varnishd/cache_panic.c branches/2.0/varnish-cache/bin/varnishd/mgt_child.c branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c branches/2.0/varnish-cache/bin/varnishd/mgt_param.c branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c branches/2.0/varnish-cache/bin/varnishd/storage_file.c branches/2.0/varnish-cache/bin/varnishhist/varnishhist.c branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c branches/2.0/varnish-cache/bin/varnishncsa/varnishncsa.c branches/2.0/varnish-cache/bin/varnishreplay/varnishreplay.c branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c branches/2.0/varnish-cache/bin/varnishtest/vtc.c branches/2.0/varnish-cache/bin/varnishtest/vtc_client.c branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c branches/2.0/varnish-cache/bin/varnishtest/vtc_log.c branches/2.0/varnish-cache/bin/varnishtest/vtc_sema.c branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c branches/2.0/varnish-cache/bin/varnishtest/vtc_varnish.c branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c branches/2.0/varnish-cache/lib/libvarnish/argv.c branches/2.0/varnish-cache/lib/libvarnish/assert.c branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c branches/2.0/varnish-cache/lib/libvarnish/cli_common.c branches/2.0/varnish-cache/lib/libvarnish/flopen.c branches/2.0/varnish-cache/lib/libvarnish/time.c branches/2.0/varnish-cache/lib/libvarnish/vct.c branches/2.0/varnish-cache/lib/libvarnish/version.c branches/2.0/varnish-cache/lib/libvarnish/vlu.c branches/2.0/varnish-cache/lib/libvarnish/vpf.c branches/2.0/varnish-cache/lib/libvarnish/vss.c branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c branches/2.0/varnish-cache/lib/libvarnishapi/base64.c branches/2.0/varnish-cache/lib/libvarnishapi/instance.c branches/2.0/varnish-cache/lib/libvarnishapi/shmlog.c branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c branches/2.0/varnish-cache/lib/libvcl/vcc_action.c branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c branches/2.0/varnish-cache/lib/libvcl/vcc_string.c branches/2.0/varnish-cache/lib/libvcl/vcc_token.c branches/2.0/varnish-cache/lib/libvcl/vcc_var.c branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c Log: Merge r3336: Revert r3072, which was a no-op. Add "config.h" where it's missing. Modified: branches/2.0/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishadm/varnishadm.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishadm/varnishadm.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -36,7 +36,6 @@ #include #include -#include "config.h" #include "libvarnish.h" #include "vss.h" Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -67,7 +67,6 @@ #include #include -#include "config.h" #ifndef HAVE_SRANDOMDEV #include "compat/srandomdev.h" #endif Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -41,7 +41,6 @@ #include #include -#include "config.h" #include "shmlog.h" #include "vct.h" #include "cache.h" Modified: branches/2.0/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_panic.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishd/cache_panic.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -37,7 +37,6 @@ #include #include -#include "config.h" #include "cache.h" #include "cache_backend.h" #include "vcl.h" Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_child.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_child.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -45,7 +45,6 @@ #include #include -#include "config.h" #ifndef HAVE_SETPROCTITLE #include "compat/setproctitle.h" #endif Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -45,7 +45,6 @@ #include #include -#include "config.h" #ifndef HAVE_VASPRINTF #include "compat/vasprintf.h" #endif Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -43,7 +43,6 @@ #include #include -#include "config.h" #include "cli.h" #include "cli_priv.h" #include "cli_common.h" Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -43,7 +43,6 @@ #include #include -#include "config.h" #ifndef HAVE_ASPRINTF #include "compat/asprintf.h" #endif Modified: branches/2.0/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_file.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishd/storage_file.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -38,7 +38,6 @@ #include #include -#include "config.h" #ifdef HAVE_SYS_MOUNT_H #include #endif Modified: branches/2.0/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishhist/varnishhist.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishhist/varnishhist.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -46,7 +46,6 @@ #include #include -#include "config.h" #include "libvarnish.h" #include "shmlog.h" #include "varnishapi.h" Modified: branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -43,7 +43,6 @@ #include #include -#include "config.h" #ifndef HAVE_DAEMON #include "compat/daemon.h" #endif Modified: branches/2.0/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishncsa/varnishncsa.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishncsa/varnishncsa.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -71,7 +71,6 @@ #include #include -#include "config.h" #ifndef HAVE_DAEMON #include "compat/daemon.h" #endif Modified: branches/2.0/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishreplay/varnishreplay.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishreplay/varnishreplay.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -43,7 +43,6 @@ #include #include -#include "config.h" #include "vqueue.h" #include "libvarnish.h" Modified: branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -46,7 +46,6 @@ #include #include -#include "config.h" #include "libvarnish.h" #include "shmlog.h" #include "varnishapi.h" Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -26,6 +26,8 @@ * $Id$ */ +#include "config.h" + #include #include #include Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_client.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_client.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_client.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -26,6 +26,8 @@ * $Id$ */ +#include "config.h" + #include #include #include Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -26,9 +26,12 @@ * $Id$ */ +#include "config.h" #include #include +#include +#include #include #include #include Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_log.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_log.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_log.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -26,6 +26,8 @@ * $Id$ */ +#include "config.h" + #include #include #include Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_sema.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_sema.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_sema.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -26,6 +26,8 @@ * $Id$ */ +#include "config.h" + #include #include #include Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -26,6 +26,7 @@ * $Id$ */ +#include "config.h" #include #include Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -26,6 +26,7 @@ * $Id$ */ +#include "config.h" #include Modified: branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/bin/varnishtop/varnishtop.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -45,7 +45,6 @@ #include #include -#include "config.h" #include "vqueue.h" #include "vsb.h" Modified: branches/2.0/varnish-cache/lib/libvarnish/argv.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/argv.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/argv.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -45,7 +45,6 @@ #include #include -#include "config.h" #include "libvarnish.h" static int Modified: branches/2.0/varnish-cache/lib/libvarnish/assert.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/assert.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/assert.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -37,7 +37,6 @@ #include #include -#include "config.h" #include "libvarnish.h" static void Modified: branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -41,7 +41,6 @@ #include #include -#include "config.h" #include "binary_heap.h" #include "libvarnish.h" Modified: branches/2.0/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/cli_common.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/cli_common.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -46,7 +46,6 @@ #include #include -#include "config.h" #include "vsb.h" #include "libvarnish.h" Modified: branches/2.0/varnish-cache/lib/libvarnish/flopen.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/flopen.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/flopen.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -39,7 +39,6 @@ #include #include -#include "config.h" #include "flopen.h" int Modified: branches/2.0/varnish-cache/lib/libvarnish/time.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/time.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/time.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -56,7 +56,6 @@ #include #include -#include "config.h" #include "libvarnish.h" double Modified: branches/2.0/varnish-cache/lib/libvarnish/vct.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vct.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/vct.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -30,6 +30,8 @@ * ctype(3) like functions, according to RFC2616 */ +#include "config.h" + #include /* NB: VCT always operate in ASCII, don't replace 0x0d with \r etc. */ Modified: branches/2.0/varnish-cache/lib/libvarnish/version.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/version.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/version.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -35,7 +35,6 @@ #include -#include "config.h" #include "libvarnish.h" void Modified: branches/2.0/varnish-cache/lib/libvarnish/vlu.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vlu.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/vlu.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -29,6 +29,8 @@ * a function on each. */ +#include "config.h" + #include #include #include Modified: branches/2.0/varnish-cache/lib/libvarnish/vpf.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vpf.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/vpf.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -41,7 +41,6 @@ #include #include -#include "config.h" #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" #endif Modified: branches/2.0/varnish-cache/lib/libvarnish/vss.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vss.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/vss.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -44,7 +44,6 @@ #include #include -#include "config.h" #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" #endif Modified: branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -36,7 +36,6 @@ #include #include -#include "config.h" #include "libvarnish.h" int Modified: branches/2.0/varnish-cache/lib/libvarnishapi/base64.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnishapi/base64.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnishapi/base64.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -10,7 +10,6 @@ #include #include -#include "config.h" #include "varnishapi.h" static const char *b64 = Modified: branches/2.0/varnish-cache/lib/libvarnishapi/instance.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnishapi/instance.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnishapi/instance.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -34,7 +34,6 @@ #include #include -#include "config.h" #include "varnishapi.h" int Modified: branches/2.0/varnish-cache/lib/libvarnishapi/shmlog.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnishapi/shmlog.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvarnishapi/shmlog.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -45,7 +45,6 @@ #include #include -#include "config.h" #include "shmlog.h" #include "miniobj.h" #include "varnishapi.h" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -41,7 +41,6 @@ #include #include -#include "config.h" #include "vsb.h" #include "vrt.h" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -33,7 +33,6 @@ #include -#include "config.h" #include "vsb.h" #include "vcc_priv.h" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -60,7 +60,6 @@ #include #include -#include "config.h" #include "vsb.h" #include "vcc_priv.h" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -73,7 +73,6 @@ #include #include -#include "config.h" #include "vqueue.h" #include "vsb.h" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -9,7 +9,6 @@ #include "config.h" #include #include -#include "config.h" #include "vcc_priv.h" #include "vsb.h" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -34,7 +34,6 @@ #include #include -#include "config.h" #include "vsb.h" #include "vcc_priv.h" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_string.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_string.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_string.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -34,7 +34,6 @@ #include #include -#include "config.h" #include "vsb.h" #include "vcc_priv.h" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_token.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_token.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -36,7 +36,6 @@ #include #include -#include "config.h" #include "vqueue.h" #include "vsb.h" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_var.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_var.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -34,7 +34,6 @@ #include #include -#include "config.h" #include "vsb.h" #include "vcc_priv.h" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c 2009-02-05 09:12:15 UTC (rev 3585) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c 2009-02-05 09:17:38 UTC (rev 3586) @@ -43,7 +43,6 @@ #include -#include "config.h" #include "vsb.h" #include "libvarnish.h" From tfheen at projects.linpro.no Thu Feb 5 09:24:49 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:24:49 +0100 (CET) Subject: r3587 - in branches/2.0/varnish-cache: . bin/varnishd Message-ID: <20090205092449.A0C2F1F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:24:49 +0100 (Thu, 05 Feb 2009) New Revision: 3587 Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am branches/2.0/varnish-cache/bin/varnishd/cache_pool.c branches/2.0/varnish-cache/bin/varnishd/storage_umem.c branches/2.0/varnish-cache/configure.ac Log: Merge r3338: Solaris fallout Clean up some of the fallout from the Solaris patch - mostly configure script breakage. In particular, disable the sendfile() check, as Solaris doesn't have a working sendfile() any more than Linux does. Actually, the Solaris sendfile code was never compiled or used, because the #ifdefs in cache_pool.c were all wrong. Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-05 09:17:38 UTC (rev 3586) +++ branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-05 09:24:49 UTC (rev 3587) @@ -80,7 +80,7 @@ $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvcl/libvcl.la \ @JEMALLOC_LDADD@ \ - ${DL_LIBS} ${PTHREAD_LIBS} ${NET_LIBS} ${LIBM} + ${DL_LIBS} ${PTHREAD_LIBS} ${NET_LIBS} ${LIBM} ${LIBUMEM} EXTRA_DIST = default.vcl DISTCLEANFILES = default_vcl.h @@ -93,4 +93,3 @@ # Explicitly record dependency mgt_vcc.c: default_vcl.h - Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 09:17:38 UTC (rev 3586) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 09:24:49 UTC (rev 3587) @@ -193,8 +193,7 @@ sendfile(*w->wfd, fd, &off, len) != len) w->werr++; } while (0); -#elif defined(__sun) -#ifdef HAVE_SENDFILEV +#elif defined(__sun) && defined(HAVE_SENDFILEV) do { sendfilevec_t svvec[HTTP_HDR_MAX * 2 + 1]; size_t xferred = 0, expected = 0; @@ -217,13 +216,12 @@ w->liov = 0; w->niov = 0; } while (0); -#else +#elif defined(__sun) && defined(HAVE_SENDFILE) do { if (WRK_Flush(w) == 0 && sendfile(*w->wfd, fd, &off, len) != len) w->werr++; } while (0); -#endif #else #error Unknown sendfile() implementation #endif Modified: branches/2.0/varnish-cache/bin/varnishd/storage_umem.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_umem.c 2009-02-05 09:17:38 UTC (rev 3586) +++ branches/2.0/varnish-cache/bin/varnishd/storage_umem.c 2009-02-05 09:24:49 UTC (rev 3587) @@ -33,7 +33,7 @@ #include "config.h" -#ifdef HAVE_UMEM_H +#ifdef HAVE_LIBUMEM #include Modified: branches/2.0/varnish-cache/configure.ac =================================================================== --- branches/2.0/varnish-cache/configure.ac 2009-02-05 09:17:38 UTC (rev 3586) +++ branches/2.0/varnish-cache/configure.ac 2009-02-05 09:24:49 UTC (rev 3587) @@ -70,8 +70,9 @@ AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_HEADER_TIME +AC_CHECK_HEADERS([sys/filio.h]) +AC_CHECK_HEADERS([sys/mount.h]) AC_CHECK_HEADERS([sys/socket.h]) -AC_CHECK_HEADERS([sys/mount.h]) AC_CHECK_HEADERS([sys/statvfs.h]) AC_CHECK_HEADERS([sys/vfs.h]) AC_CHECK_HEADERS([netinet/in.h]) @@ -109,7 +110,8 @@ AC_CHECK_FUNCS([pthread_mutex_isowned_np]) LIBS="${save_LIBS}" -## This one is tricky, there are multiple versions +# sendfile is tricky: there are multiple versions, and most of them +# don't work. case $target in *-*-freebsd*) AC_CACHE_CHECK([whether sendfile works], @@ -125,28 +127,37 @@ [ac_cv_so_sendfile_works=yes], [ac_cv_so_sendfile_works=no]) ]) - if test "$ac_cv_so_sendfile_works" = yes; then - AC_DEFINE([SENDFILE_WORKS], [1], [Define if SENDFILE works]) - fi - ;; + ;; +#*-*-solaris*) +# save_LIBS="${LIBS}" +# LIBS="${NET_LIBS}" +# AC_CHECK_LIB(sendfile, sendfile) +# AC_CHECK_FUNCS([sendfile]) +# AC_CHECK_FUNCS([sendfilev]) +# NET_LIBS="${LIBS}" +# LIBS="${save_LIBS}" +*) + AC_MSG_WARN([won't look for sendfile() on $target]) + ;; +esac +if test "$ac_cv_so_sendfile_works" = yes; then + AC_DEFINE([SENDFILE_WORKS], [1], [Define if SENDFILE works]) +fi + +# Userland slab allocator, available only on Solaris +case $target in *-*-solaris*) - AC_CHECK_HEADERS([sys/filio.h]) - AC_CHECK_LIB(sendfile, sendfile) - AC_CHECK_LIB(umem, malloc) AC_CHECK_HEADERS([umem.h]) - - if test "$ac_cv_lib_sendfile_sendfile" = yes; then + if test "$ac_cv_have_umem_h" = yes; then save_LIBS="${LIBS}" - LIBS="${NET_LIBS}" - AC_CHECK_FUNCS([sendfile]) - AC_CHECK_FUNCS([sendfilev]) + LIBS="" + AC_CHECK_LIB(umem, umem_alloc) + LIBUMEM="${LIBS}" LIBS="${save_LIBS}" fi ;; -*) - AC_MSG_WARN([won't look for sendfile() on $target]) - ;; esac +AC_SUBST(LIBUMEM) # These functions are provided by libcompat on platforms where they # are not available From tfheen at projects.linpro.no Thu Feb 5 09:34:34 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:34:34 +0100 (CET) Subject: r3588 - branches/2.0/varnish-cache/lib/libvcl Message-ID: <20090205093434.F1A401F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:34:34 +0100 (Thu, 05 Feb 2009) New Revision: 3588 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl Log: Merge r3339: Break the encoded .h files up at convenient newlines, to avoid minor edits to bases from generating huge diffs. Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-05 09:24:49 UTC (rev 3587) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-05 09:34:34 UTC (rev 3588) @@ -127,15 +127,15 @@ typedef int vcl_func_f(struct sess *sp); } puts $fo "struct VCL_conf {" -puts $fo { unsigned magic; -#define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */ +puts $fo { unsigned magic; +#define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */ - struct director **director; - unsigned ndirector; - struct vrt_ref *ref; - unsigned nref; - unsigned busy; - unsigned discard; + struct director **director; + unsigned ndirector; + struct vrt_ref *ref; + unsigned nref; + unsigned busy; + unsigned discard; unsigned nsrc; const char **srcname; @@ -143,8 +143,8 @@ unsigned nhashcount; - vcl_init_f *init_func; - vcl_fini_f *fini_func; + vcl_init_f *init_func; + vcl_fini_f *fini_func; } foreach m $methods { puts $fo "\tvcl_func_f\t*[lindex $m 0]_func;" @@ -376,7 +376,7 @@ } puts -nonewline $fo "\\n" incr n 2 - if {$n > 53} { + if {$n > 30} { puts $fo "\");" set n 0 } From tfheen at projects.linpro.no Thu Feb 5 09:37:00 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:37:00 +0100 (CET) Subject: r3589 - in branches/2.0/varnish-cache: include lib/libvcl Message-ID: <20090205093700.10EAE1F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:36:59 +0100 (Thu, 05 Feb 2009) New Revision: 3589 Modified: branches/2.0/varnish-cache/include/vcl.h branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Regenerate generated files with new .tcl script. Modified: branches/2.0/varnish-cache/include/vcl.h =================================================================== --- branches/2.0/varnish-cache/include/vcl.h 2009-02-05 09:34:34 UTC (rev 3588) +++ branches/2.0/varnish-cache/include/vcl.h 2009-02-05 09:36:59 UTC (rev 3589) @@ -14,15 +14,15 @@ typedef int vcl_func_f(struct sess *sp); struct VCL_conf { - unsigned magic; -#define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */ + unsigned magic; +#define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */ - struct director **director; - unsigned ndirector; - struct vrt_ref *ref; - unsigned nref; - unsigned busy; - unsigned discard; + struct director **director; + unsigned ndirector; + struct vrt_ref *ref; + unsigned nref; + unsigned busy; + unsigned discard; unsigned nsrc; const char **srcname; @@ -30,8 +30,8 @@ unsigned nhashcount; - vcl_init_f *init_func; - vcl_fini_f *fini_func; + vcl_init_f *init_func; + vcl_fini_f *fini_func; vcl_func_f *recv_func; vcl_func_f *pipe_func; Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 09:34:34 UTC (rev 3588) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 09:36:59 UTC (rev 3589) @@ -9,6 +9,7 @@ #include "config.h" #include #include +#include "config.h" #include "vcc_priv.h" #include "vsb.h" @@ -166,182 +167,199 @@ /* ../../include/vcl.h */ - vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3098 2008-08-18 08"); - vsb_cat(sb, ":18:43Z phk $\n *\n * NB: This file is machine genera"); - vsb_cat(sb, "ted, DO NOT EDIT!\n *\n * Edit vcc_gen_fixed_token.tcl"); - vsb_cat(sb, " instead\n */\n\nstruct sess;\nstruct cli;\n\ntypedef "); - vsb_cat(sb, "void vcl_init_f(struct cli *);\ntypedef void vcl_fini_"); - vsb_cat(sb, "f(struct cli *);\ntypedef int vcl_func_f(struct sess *"); - vsb_cat(sb, "sp);\n\nstruct VCL_conf {\n\tunsigned magic;\n#"); - vsb_cat(sb, "define VCL_CONF_MAGIC 0x7406c509 /* from /dev/ra"); - vsb_cat(sb, "ndom */\n\n struct director **director;\n "); - vsb_cat(sb, " unsigned ndirector;\n struct vrt_ref "); - vsb_cat(sb, " *ref;\n unsigned nref;\n unsigne"); - vsb_cat(sb, "d busy;\n unsigned discard;\n\n\t"); - vsb_cat(sb, "unsigned\tnsrc;\n\tconst char\t**srcname;\n\tconst cha"); - vsb_cat(sb, "r\t**srcbody;\n\n\tunsigned\tnhashcount;\n\n vc"); - vsb_cat(sb, "l_init_f *init_func;\n vcl_fini_f *fi"); - vsb_cat(sb, "ni_func;\n\n\tvcl_func_f\t*recv_func;\n\tvcl_func_f\t*"); - vsb_cat(sb, "pipe_func;\n\tvcl_func_f\t*pass_func;\n\tvcl_func_f\t*"); - vsb_cat(sb, "hash_func;\n\tvcl_func_f\t*miss_func;\n\tvcl_func_f\t*"); - vsb_cat(sb, "hit_func;\n\tvcl_func_f\t*fetch_func;\n\tvcl_func_f\t*"); - vsb_cat(sb, "deliver_func;\n\tvcl_func_f\t*prefetch_func;\n\tvcl_fu"); - vsb_cat(sb, "nc_f\t*timeout_func;\n\tvcl_func_f\t*discard_func;\n\t"); - vsb_cat(sb, "vcl_func_f\t*error_func;\n};\n"); + vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3588 2009-02-05 09"); + vsb_cat(sb, ":34:34Z tfheen $\n *\n * NB: This file is machine gen"); + vsb_cat(sb, "erated, DO NOT EDIT!\n *\n * Edit vcc_gen_fixed_token."); + vsb_cat(sb, "tcl instead\n */\n\nstruct sess;\n"); + vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n"); + vsb_cat(sb, "typedef void vcl_fini_f(struct cli *);\n"); + vsb_cat(sb, "typedef int vcl_func_f(struct sess *sp);\n"); + vsb_cat(sb, "\nstruct VCL_conf {\n\tunsigned\tmagic;\n"); + vsb_cat(sb, "#define VCL_CONF_MAGIC\t0x7406c509\t/* from /dev/rando"); + vsb_cat(sb, "m */\n\n\tstruct director\t**director;\n"); + vsb_cat(sb, "\tunsigned\tndirector;\n\tstruct vrt_ref\t*ref;\n"); + vsb_cat(sb, "\tunsigned\tnref;\n\tunsigned\tbusy;\n"); + vsb_cat(sb, "\tunsigned\tdiscard;\n\n\tunsigned\tnsrc;\n"); + vsb_cat(sb, "\tconst char\t**srcname;\n\tconst char\t**srcbody;\n"); + vsb_cat(sb, "\n\tunsigned\tnhashcount;\n\n\tvcl_init_f\t*init_func;"); + vsb_cat(sb, "\n\tvcl_fini_f\t*fini_func;\n\n"); + vsb_cat(sb, "\tvcl_func_f\t*recv_func;\n\tvcl_func_f\t*pipe_func;\n"); + vsb_cat(sb, "\tvcl_func_f\t*pass_func;\n\tvcl_func_f\t*hash_func;\n"); + vsb_cat(sb, "\tvcl_func_f\t*miss_func;\n\tvcl_func_f\t*hit_func;\n"); + vsb_cat(sb, "\tvcl_func_f\t*fetch_func;\n\tvcl_func_f\t*deliver_fun"); + vsb_cat(sb, "c;\n\tvcl_func_f\t*prefetch_func;\n"); + vsb_cat(sb, "\tvcl_func_f\t*timeout_func;\n\tvcl_func_f\t*discard_f"); + vsb_cat(sb, "unc;\n\tvcl_func_f\t*error_func;\n"); + vsb_cat(sb, "};\n"); /* ../../include/vrt.h */ - vsb_cat(sb, "/*-\n * Copyright (c) 2006 Verdens Gang AS\n * Copyrig"); - vsb_cat(sb, "ht (c) 2006-2008 Linpro AS\n * All rights reserved.\n "); - vsb_cat(sb, "*\n * Author: Poul-Henning Kamp \n"); - vsb_cat(sb, " *\n * Redistribution and use in source and binary for"); - vsb_cat(sb, "ms, with or without\n * modification, are permitted pr"); - vsb_cat(sb, "ovided that the following conditions\n * are met:\n * "); - vsb_cat(sb, "1. Redistributions of source code must retain the abov"); - vsb_cat(sb, "e copyright\n * notice, this list of conditions and"); - vsb_cat(sb, " the following disclaimer.\n * 2. Redistributions in b"); - vsb_cat(sb, "inary form must reproduce the above copyright\n * n"); - vsb_cat(sb, "otice, this list of conditions and the following discl"); - vsb_cat(sb, "aimer in the\n * documentation and/or other materia"); - vsb_cat(sb, "ls provided with the distribution.\n *\n * THIS SOFTWA"); - vsb_cat(sb, "RE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'"); - vsb_cat(sb, "' AND\n * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING"); - vsb_cat(sb, ", BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF ME"); - vsb_cat(sb, "RCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n *"); - vsb_cat(sb, " ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBU"); - vsb_cat(sb, "TORS BE LIABLE\n * FOR ANY DIRECT, INDIRECT, INCIDENTA"); - vsb_cat(sb, "L, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n * DAMAGES (I"); - vsb_cat(sb, "NCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUT"); - vsb_cat(sb, "E GOODS\n * OR SERVICES; LOSS OF USE, DATA, OR PROFITS"); - vsb_cat(sb, "; OR BUSINESS INTERRUPTION)\n * HOWEVER CAUSED AND ON "); - vsb_cat(sb, "ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\n"); + vsb_cat(sb, "/*-\n * Copyright (c) 2006 Verdens Gang AS\n"); + vsb_cat(sb, " * Copyright (c) 2006-2008 Linpro AS\n"); + vsb_cat(sb, " * All rights reserved.\n *\n * Author: Poul-Henning K"); + vsb_cat(sb, "amp \n *\n * Redistribution and us"); + vsb_cat(sb, "e in source and binary forms, with or without\n"); + vsb_cat(sb, " * modification, are permitted provided that the follo"); + vsb_cat(sb, "wing conditions\n * are met:\n * 1. Redistributions of"); + vsb_cat(sb, " source code must retain the above copyright\n"); + vsb_cat(sb, " * notice, this list of conditions and the followin"); + vsb_cat(sb, "g disclaimer.\n * 2. Redistributions in binary form mu"); + vsb_cat(sb, "st reproduce the above copyright\n"); + vsb_cat(sb, " * notice, this list of conditions and the followin"); + vsb_cat(sb, "g disclaimer in the\n * documentation and/or other "); + vsb_cat(sb, "materials provided with the distribution.\n"); + vsb_cat(sb, " *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CON"); + vsb_cat(sb, "TRIBUTORS ``AS IS'' AND\n * ANY EXPRESS OR IMPLIED WAR"); + vsb_cat(sb, "RANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n"); + vsb_cat(sb, " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS F"); + vsb_cat(sb, "OR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVE"); + vsb_cat(sb, "NT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE\n"); + vsb_cat(sb, " * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEM"); + vsb_cat(sb, "PLARY, OR CONSEQUENTIAL\n * DAMAGES (INCLUDING, BUT NO"); + vsb_cat(sb, "T LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\n"); + vsb_cat(sb, " * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSI"); + vsb_cat(sb, "NESS INTERRUPTION)\n * HOWEVER CAUSED AND ON ANY THEOR"); + vsb_cat(sb, "Y OF LIABILITY, WHETHER IN CONTRACT, STRICT\n"); vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI"); vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT"); - vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n * SUCH D"); - vsb_cat(sb, "AMAGE.\n *\n * $Id: vrt.h 3234 2008-09-29 07:32:26Z ph"); - vsb_cat(sb, "k $\n *\n * Runtime support for compiled VCL programs."); - vsb_cat(sb, "\n *\n * XXX: When this file is changed, lib/libvcl/vc"); - vsb_cat(sb, "c_gen_fixed_token.tcl\n * XXX: *MUST* be rerun.\n */\n"); - vsb_cat(sb, "\nstruct sess;\nstruct vsb;\nstruct cli;\nstruct direc"); - vsb_cat(sb, "tor;\nstruct VCL_conf;\nstruct sockaddr;\n\n/*\n * A b"); - vsb_cat(sb, "ackend probe specification\n */\n\nextern void *vrt_ma"); - vsb_cat(sb, "gic_string_end;\n\nstruct vrt_backend_probe {\n\tconst"); - vsb_cat(sb, " char\t*url;\n\tconst char\t*request;\n\tdouble\t\ttim"); - vsb_cat(sb, "eout;\n\tdouble\t\tinterval;\n\tunsigned\twindow;\n\tu"); - vsb_cat(sb, "nsigned\tthreshold;\n};\n\n/*\n * A backend is a host+"); - vsb_cat(sb, "port somewhere on the network\n */\nstruct vrt_backend"); - vsb_cat(sb, " {\n\tconst char\t\t\t*vcl_name;\n\tconst char\t\t\t*i"); - vsb_cat(sb, "dent;\n\n\tconst char\t\t\t*hosthdr;\n\n\tconst unsign"); - vsb_cat(sb, "ed char\t\t*ipv4_sockaddr;\n\tconst unsigned char\t\t*"); - vsb_cat(sb, "ipv6_sockaddr;\n\n\tdouble\t\t\t\tconnect_timeout;\n\t"); - vsb_cat(sb, "unsigned\t\t\tmax_connections;\n\tstruct vrt_backend_p"); - vsb_cat(sb, "robe\tprobe;\n};\n\n/*\n * A director with a predictab"); - vsb_cat(sb, "le reply\n */\n\nstruct vrt_dir_simple {\n\tconst char"); - vsb_cat(sb, "\t\t\t\t*name;\n\tconst struct vrt_backend\t\t*host;\n"); - vsb_cat(sb, "};\n\n/*\n * A director with an unpredictable reply\n "); - vsb_cat(sb, "*/\n\nstruct vrt_dir_random_entry {\n\tconst struct vr"); - vsb_cat(sb, "t_backend\t\t*host;\n\tdouble\t\t\t\t\tweight;\n};\n\n"); - vsb_cat(sb, "struct vrt_dir_random {\n\tconst char\t\t\t\t*name;\n\t"); - vsb_cat(sb, "unsigned\t\t\t\tretries;\n\tunsigned\t\t\t\tnmember;\n"); - vsb_cat(sb, "\tconst struct vrt_dir_random_entry\t*members;\n};\n\n"); - vsb_cat(sb, "/*\n * A director with round robin selection\n */\n\ns"); - vsb_cat(sb, "truct vrt_dir_round_robin_entry {\n\tconst struct vrt_"); - vsb_cat(sb, "backend\t\t*host;\n};\n\nstruct vrt_dir_round_robin {\n"); + vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"); + vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3580 2009-02-05 08:"); + vsb_cat(sb, "45:25Z tfheen $\n *\n * Runtime support for compiled V"); + vsb_cat(sb, "CL programs.\n *\n * XXX: When this file is changed, l"); + vsb_cat(sb, "ib/libvcl/vcc_gen_fixed_token.tcl\n"); + vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n"); + vsb_cat(sb, "\nstruct sess;\nstruct vsb;\nstruct cli;\n"); + vsb_cat(sb, "struct director;\nstruct VCL_conf;\n"); + vsb_cat(sb, "struct sockaddr;\n\n/*\n * A backend probe specificati"); + vsb_cat(sb, "on\n */\n\nextern void *vrt_magic_string_end;\n"); + vsb_cat(sb, "\nstruct vrt_backend_probe {\n\tconst char\t*url;\n"); + vsb_cat(sb, "\tconst char\t*request;\n\tdouble\t\ttimeout;\n"); + vsb_cat(sb, "\tdouble\t\tinterval;\n\tunsigned\twindow;\n"); + vsb_cat(sb, "\tunsigned\tthreshold;\n};\n\n/*\n"); + vsb_cat(sb, " * A backend is a host+port somewhere on the network\n"); + vsb_cat(sb, " */\nstruct vrt_backend {\n\tconst char\t\t\t*vcl_name"); + vsb_cat(sb, ";\n\tconst char\t\t\t*ident;\n\n"); + vsb_cat(sb, "\tconst char\t\t\t*hosthdr;\n\n"); + vsb_cat(sb, "\tconst unsigned char\t\t*ipv4_sockaddr;\n"); + vsb_cat(sb, "\tconst unsigned char\t\t*ipv6_sockaddr;\n"); + vsb_cat(sb, "\n\tdouble\t\t\t\tconnect_timeout;\n"); + vsb_cat(sb, "\tunsigned\t\t\tmax_connections;\n"); + vsb_cat(sb, "\tstruct vrt_backend_probe\tprobe;\n"); + vsb_cat(sb, "};\n\n/*\n * A director with a predictable reply\n"); + vsb_cat(sb, " */\n\nstruct vrt_dir_simple {\n"); + vsb_cat(sb, "\tconst char\t\t\t\t*name;\n\tconst struct vrt_backend"); + vsb_cat(sb, "\t\t*host;\n};\n\n/*\n * A director with an unpredicta"); + vsb_cat(sb, "ble reply\n */\n\nstruct vrt_dir_random_entry {\n"); + vsb_cat(sb, "\tconst struct vrt_backend\t\t*host;\n"); + vsb_cat(sb, "\tdouble\t\t\t\t\tweight;\n};\n"); + vsb_cat(sb, "\nstruct vrt_dir_random {\n\tconst char\t\t\t\t*name;\n"); + vsb_cat(sb, "\tunsigned\t\t\t\tretries;\n\tunsigned\t\t\t\tnmember;"); + vsb_cat(sb, "\n\tconst struct vrt_dir_random_entry\t*members;\n"); + vsb_cat(sb, "};\n\n/*\n * A director with round robin selection\n"); + vsb_cat(sb, " */\n\nstruct vrt_dir_round_robin_entry {\n"); + vsb_cat(sb, "\tconst struct vrt_backend\t\t*host;\n"); + vsb_cat(sb, "};\n\nstruct vrt_dir_round_robin {\n"); vsb_cat(sb, "\tconst char\t\t\t\t*name;\n\tunsigned\t\t\t\tnmember;"); vsb_cat(sb, "\n\tconst struct vrt_dir_round_robin_entry\t*members;\n"); vsb_cat(sb, "};\n\n\n/*\n * other stuff.\n * XXX: document when bor"); - vsb_cat(sb, "ed\n */\n\nstruct vrt_ref {\n\tunsigned\tsource;\n\tun"); - vsb_cat(sb, "signed\toffset;\n\tunsigned\tline;\n\tunsigned\tpos;\n"); - vsb_cat(sb, "\tunsigned\tcount;\n\tconst char\t*token;\n};\n\n/* AC"); - vsb_cat(sb, "L related */\n#define VRT_ACL_MAXADDR\t\t16\t/* max(IP"); - vsb_cat(sb, "v4, IPv6) */\n\nvoid VRT_acl_log(const struct sess *, "); - vsb_cat(sb, "const char *msg);\n\n/* Regexp related */\nvoid VRT_re"); - vsb_cat(sb, "_init(void **, const char *, int sub);\nvoid VRT_re_fi"); - vsb_cat(sb, "ni(void *);\nint VRT_re_match(const char *, void *re);"); - vsb_cat(sb, "\nint VRT_re_test(struct vsb *, const char *, int sub)"); - vsb_cat(sb, ";\nconst char *VRT_regsub(const struct sess *sp, int a"); - vsb_cat(sb, "ll, const char *,\n void *, const char *);\n\nvoid "); - vsb_cat(sb, "VRT_panic(struct sess *sp, const char *, ...);\nvoid "); - vsb_cat(sb, "VRT_purge(const char *, int hash);\n\nvoid VRT_count(c"); - vsb_cat(sb, "onst struct sess *, unsigned);\nint VRT_rewrite(const "); - vsb_cat(sb, "char *, const char *);\nvoid VRT_error(struct sess *, "); - vsb_cat(sb, "unsigned, const char *);\nint VRT_switch_config(const "); - vsb_cat(sb, "char *);\n\nenum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ"); - vsb_cat(sb, ", HDR_BEREQ };\nchar *VRT_GetHdr(const struct sess *, "); - vsb_cat(sb, "enum gethdr_e where, const char *);\nvoid VRT_SetHdr(c"); - vsb_cat(sb, "onst struct sess *, enum gethdr_e where, const char *,"); - vsb_cat(sb, "\n const char *, ...);\nvoid VRT_handling(struct se"); - vsb_cat(sb, "ss *sp, unsigned hand);\n\n/* Simple stuff */\nint VRT"); - vsb_cat(sb, "_strcmp(const char *s1, const char *s2);\nvoid VRT_mem"); - vsb_cat(sb, "move(void *dst, const void *src, unsigned len);\n\nvoi"); - vsb_cat(sb, "d VRT_ESI(struct sess *sp);\nvoid VRT_Rollback(struct "); - vsb_cat(sb, "sess *sp);\n\n/* Synthetic pages */\nvoid VRT_synth_pa"); - vsb_cat(sb, "ge(struct sess *sp, unsigned flags, const char *, ...)"); - vsb_cat(sb, ";\n\n/* Backend related */\nvoid VRT_init_dir_simple(s"); - vsb_cat(sb, "truct cli *, struct director **,\n const struct vrt"); - vsb_cat(sb, "_dir_simple *);\nvoid VRT_init_dir_random(struct cli *"); - vsb_cat(sb, ", struct director **,\n const struct vrt_dir_random"); - vsb_cat(sb, " *);\nvoid VRT_init_dir_round_robin(struct cli *, stru"); - vsb_cat(sb, "ct director **,\n const struct vrt_dir_round_robin "); - vsb_cat(sb, "*);\nvoid VRT_fini_dir(struct cli *, struct director *"); - vsb_cat(sb, ");\n\nchar *VRT_IP_string(const struct sess *sp, const"); - vsb_cat(sb, " struct sockaddr *sa);\nchar *VRT_int_string(const str"); - vsb_cat(sb, "uct sess *sp, int);\nchar *VRT_double_string(const str"); - vsb_cat(sb, "uct sess *sp, double);\nconst char *VRT_backend_string"); - vsb_cat(sb, "(struct sess *sp);\n\n#define VRT_done(sp, hand)\t\t\t"); - vsb_cat(sb, "\\\n\tdo {\t\t\t\t\t\\\n\t\tVRT_handling(sp, hand);\t\t"); - vsb_cat(sb, "\\\n\t\treturn (1);\t\t\t\\\n\t} while (0)\n"); + vsb_cat(sb, "ed\n */\n\nstruct vrt_ref {\n\tunsigned\tsource;\n"); + vsb_cat(sb, "\tunsigned\toffset;\n\tunsigned\tline;\n"); + vsb_cat(sb, "\tunsigned\tpos;\n\tunsigned\tcount;\n"); + vsb_cat(sb, "\tconst char\t*token;\n};\n\n/* ACL related */\n"); + vsb_cat(sb, "#define VRT_ACL_MAXADDR\t\t16\t/* max(IPv4, IPv6) */\n"); + vsb_cat(sb, "\nvoid VRT_acl_log(const struct sess *, const char *ms"); + vsb_cat(sb, "g);\n\n/* Regexp related */\nvoid VRT_re_init(void **,"); + vsb_cat(sb, " const char *, int sub);\nvoid VRT_re_fini(void *);\n"); + vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n"); + vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); + vsb_cat(sb, "const char *VRT_regsub(const struct sess *sp, int all,"); + vsb_cat(sb, " const char *,\n void *, const char *);\n"); + vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);"); + vsb_cat(sb, "\nvoid VRT_purge(const char *, int hash);\n"); + vsb_cat(sb, "\nvoid VRT_count(const struct sess *, unsigned);\n"); + vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); + vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);"); + vsb_cat(sb, "\nint VRT_switch_config(const char *);\n"); + vsb_cat(sb, "\nenum gethdr_e { HDR_REQ, HDR_RESP, HDR_OBJ, HDR_BERE"); + vsb_cat(sb, "Q };\nchar *VRT_GetHdr(const struct sess *, enum gethd"); + vsb_cat(sb, "r_e where, const char *);\nvoid VRT_SetHdr(const struc"); + vsb_cat(sb, "t sess *, enum gethdr_e where, const char *,\n"); + vsb_cat(sb, " const char *, ...);\nvoid VRT_handling(struct sess"); + vsb_cat(sb, " *sp, unsigned hand);\n\n/* Simple stuff */\n"); + vsb_cat(sb, "int VRT_strcmp(const char *s1, const char *s2);\n"); + vsb_cat(sb, "void VRT_memmove(void *dst, const void *src, unsigned "); + vsb_cat(sb, "len);\n\nvoid VRT_ESI(struct sess *sp);\n"); + vsb_cat(sb, "void VRT_Rollback(struct sess *sp);\n"); + vsb_cat(sb, "\n/* Synthetic pages */\nvoid VRT_synth_page(struct se"); + vsb_cat(sb, "ss *sp, unsigned flags, const char *, ...);\n"); + vsb_cat(sb, "\n/* Backend related */\nvoid VRT_init_dir_simple(stru"); + vsb_cat(sb, "ct cli *, struct director **,\n"); + vsb_cat(sb, " const struct vrt_dir_simple *);\n"); + vsb_cat(sb, "void VRT_init_dir_random(struct cli *, struct director"); + vsb_cat(sb, " **,\n const struct vrt_dir_random *);\n"); + vsb_cat(sb, "void VRT_init_dir_round_robin(struct cli *, struct dir"); + vsb_cat(sb, "ector **,\n const struct vrt_dir_round_robin *);\n"); + vsb_cat(sb, "void VRT_fini_dir(struct cli *, struct director *);\n"); + vsb_cat(sb, "\nchar *VRT_IP_string(const struct sess *sp, const str"); + vsb_cat(sb, "uct sockaddr *sa);\nchar *VRT_int_string(const struct "); + vsb_cat(sb, "sess *sp, int);\nchar *VRT_double_string(const struct "); + vsb_cat(sb, "sess *sp, double);\nconst char *VRT_backend_string(str"); + vsb_cat(sb, "uct sess *sp);\n\n#define VRT_done(sp, hand)\t\t\t\\\n"); + vsb_cat(sb, "\tdo {\t\t\t\t\t\\\n\t\tVRT_handling(sp, hand);\t\t\\\n"); + vsb_cat(sb, "\t\treturn (1);\t\t\t\\\n\t} while (0)\n"); /* ../../include/vrt_obj.h */ vsb_cat(sb, "/*\n * $Id: vrt_obj.h 3169 2008-09-08 09:49:01Z tfheen"); vsb_cat(sb, " $\n *\n * NB: This file is machine generated, DO NOT"); - vsb_cat(sb, " EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n */\n\nst"); - vsb_cat(sb, "ruct sockaddr * VRT_r_client_ip(const struct sess *);\n"); - vsb_cat(sb, "struct sockaddr * VRT_r_server_ip(struct sess *);\nint"); - vsb_cat(sb, " VRT_r_server_port(struct sess *);\nconst char * VRT_r"); - vsb_cat(sb, "_req_request(const struct sess *);\nvoid VRT_l_req_req"); - vsb_cat(sb, "uest(const struct sess *, const char *, ...);\nconst c"); - vsb_cat(sb, "har * VRT_r_req_url(const struct sess *);\nvoid VRT_l_"); - vsb_cat(sb, "req_url(const struct sess *, const char *, ...);\ncons"); - vsb_cat(sb, "t char * VRT_r_req_proto(const struct sess *);\nvoid V"); - vsb_cat(sb, "RT_l_req_proto(const struct sess *, const char *, ...)"); - vsb_cat(sb, ";\nvoid VRT_l_req_hash(struct sess *, const char *);\n"); - vsb_cat(sb, "struct director * VRT_r_req_backend(struct sess *);\nv"); - vsb_cat(sb, "oid VRT_l_req_backend(struct sess *, struct director *"); - vsb_cat(sb, ");\nint VRT_r_req_restarts(const struct sess *);\ndoub"); - vsb_cat(sb, "le VRT_r_req_grace(struct sess *);\nvoid VRT_l_req_gra"); - vsb_cat(sb, "ce(struct sess *, double);\nconst char * VRT_r_req_xid"); - vsb_cat(sb, "(struct sess *);\nconst char * VRT_r_bereq_request(con"); - vsb_cat(sb, "st struct sess *);\nvoid VRT_l_bereq_request(const str"); - vsb_cat(sb, "uct sess *, const char *, ...);\nconst char * VRT_r_be"); - vsb_cat(sb, "req_url(const struct sess *);\nvoid VRT_l_bereq_url(co"); - vsb_cat(sb, "nst struct sess *, const char *, ...);\nconst char * V"); - vsb_cat(sb, "RT_r_bereq_proto(const struct sess *);\nvoid VRT_l_ber"); - vsb_cat(sb, "eq_proto(const struct sess *, const char *, ...);\ncon"); - vsb_cat(sb, "st char * VRT_r_obj_proto(const struct sess *);\nvoid "); - vsb_cat(sb, "VRT_l_obj_proto(const struct sess *, const char *, ..."); - vsb_cat(sb, ");\nint VRT_r_obj_status(const struct sess *);\nvoid V"); - vsb_cat(sb, "RT_l_obj_status(const struct sess *, int);\nconst char"); - vsb_cat(sb, " * VRT_r_obj_response(const struct sess *);\nvoid VRT_"); - vsb_cat(sb, "l_obj_response(const struct sess *, const char *, ...)"); - vsb_cat(sb, ";\nint VRT_r_obj_hits(const struct sess *);\nunsigned "); - vsb_cat(sb, "VRT_r_obj_cacheable(const struct sess *);\nvoid VRT_l_"); - vsb_cat(sb, "obj_cacheable(const struct sess *, unsigned);\ndouble "); - vsb_cat(sb, "VRT_r_obj_ttl(const struct sess *);\nvoid VRT_l_obj_tt"); - vsb_cat(sb, "l(const struct sess *, double);\ndouble VRT_r_obj_grac"); - vsb_cat(sb, "e(const struct sess *);\nvoid VRT_l_obj_grace(const st"); - vsb_cat(sb, "ruct sess *, double);\ndouble VRT_r_obj_prefetch(const"); - vsb_cat(sb, " struct sess *);\nvoid VRT_l_obj_prefetch(const struct"); - vsb_cat(sb, " sess *, double);\ndouble VRT_r_obj_lastuse(const stru"); - vsb_cat(sb, "ct sess *);\nconst char * VRT_r_obj_hash(const struct "); - vsb_cat(sb, "sess *);\nconst char * VRT_r_resp_proto(const struct s"); - vsb_cat(sb, "ess *);\nvoid VRT_l_resp_proto(const struct sess *, co"); - vsb_cat(sb, "nst char *, ...);\nint VRT_r_resp_status(const struct "); - vsb_cat(sb, "sess *);\nvoid VRT_l_resp_status(const struct sess *, "); - vsb_cat(sb, "int);\nconst char * VRT_r_resp_response(const struct s"); - vsb_cat(sb, "ess *);\nvoid VRT_l_resp_response(const struct sess *,"); - vsb_cat(sb, " const char *, ...);\ndouble VRT_r_now(const struct se"); - vsb_cat(sb, "ss *);\nunsigned VRT_r_req_backend_healthy(const struc"); - vsb_cat(sb, "t sess *);\n"); + vsb_cat(sb, " EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); + vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct "); + vsb_cat(sb, "sess *);\nstruct sockaddr * VRT_r_server_ip(struct ses"); + vsb_cat(sb, "s *);\nint 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"); + vsb_cat(sb, " *, ...);\nconst char * VRT_r_req_url(const struct ses"); + vsb_cat(sb, "s *);\nvoid VRT_l_req_url(const struct sess *, const c"); + vsb_cat(sb, "har *, ...);\nconst char * VRT_r_req_proto(const struc"); + vsb_cat(sb, "t sess *);\nvoid VRT_l_req_proto(const struct sess *, "); + vsb_cat(sb, "const char *, ...);\nvoid VRT_l_req_hash(struct sess *"); + vsb_cat(sb, ", const char *);\nstruct director * VRT_r_req_backend("); + vsb_cat(sb, "struct sess *);\nvoid VRT_l_req_backend(struct sess *,"); + vsb_cat(sb, " struct director *);\nint VRT_r_req_restarts(const str"); + vsb_cat(sb, "uct sess *);\ndouble 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 *);"); + vsb_cat(sb, "\nvoid VRT_l_bereq_request(const struct sess *, const "); + vsb_cat(sb, "char *, ...);\nconst char * VRT_r_bereq_url(const stru"); + vsb_cat(sb, "ct sess *);\nvoid VRT_l_bereq_url(const struct sess *,"); + vsb_cat(sb, " const char *, ...);\nconst char * VRT_r_bereq_proto(c"); + vsb_cat(sb, "onst struct sess *);\nvoid VRT_l_bereq_proto(const str"); + vsb_cat(sb, "uct sess *, const char *, ...);\n"); + vsb_cat(sb, "const char * VRT_r_obj_proto(const struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_proto(const struct sess *, const char *"); + vsb_cat(sb, ", ...);\nint VRT_r_obj_status(const struct sess *);\n"); + 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 cha"); + vsb_cat(sb, "r *, ...);\nint VRT_r_obj_hits(const struct sess *);\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"); + vsb_cat(sb, ");\ndouble VRT_r_obj_ttl(const struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_ttl(const struct sess *, double);\n"); + vsb_cat(sb, "double VRT_r_obj_grace(const struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_grace(const struct sess *, double);\n"); + vsb_cat(sb, "double VRT_r_obj_prefetch(const struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_prefetch(const struct sess *, double);\n"); + vsb_cat(sb, "double VRT_r_obj_lastuse(const struct sess *);\n"); + vsb_cat(sb, "const char * VRT_r_obj_hash(const struct sess *);\n"); + vsb_cat(sb, "const char * VRT_r_resp_proto(const struct sess *);\n"); + vsb_cat(sb, "void VRT_l_resp_proto(const struct sess *, const char "); + vsb_cat(sb, "*, ...);\nint VRT_r_resp_status(const struct sess *);\n"); + vsb_cat(sb, "void VRT_l_resp_status(const struct sess *, int);\n"); + vsb_cat(sb, "const char * VRT_r_resp_response(const struct sess *);"); + vsb_cat(sb, "\nvoid VRT_l_resp_response(const struct sess *, const "); + vsb_cat(sb, "char *, ...);\ndouble VRT_r_now(const struct sess *);\n"); + vsb_cat(sb, "unsigned VRT_r_req_backend_healthy(const struct sess *"); + vsb_cat(sb, ");\n"); } From tfheen at projects.linpro.no Thu Feb 5 09:40:21 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:40:21 +0100 (CET) Subject: r3590 - in branches/2.0/varnish-cache: bin/varnishd lib/libvcl Message-ID: <20090205094021.DB8C11F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:40:21 +0100 (Thu, 05 Feb 2009) New Revision: 3590 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Merge r3333: Change default to always use HTTP/1.1 with the backend Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 09:36:59 UTC (rev 3589) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 09:40:21 UTC (rev 3590) @@ -689,7 +689,7 @@ "By default we copy the protocol version from the " "incoming client request.", EXPERIMENTAL, - "off", "bool" }, + "on", "bool" }, { "client_http11", tweak_bool, &master.client_http11, 0, 0, "Force all client responses to be HTTP/1.1.\n" "By default we copy the protocol version from the " Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 09:36:59 UTC (rev 3589) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 09:40:21 UTC (rev 3590) @@ -310,9 +310,9 @@ /* ../../include/vrt_obj.h */ - vsb_cat(sb, "/*\n * $Id: vrt_obj.h 3169 2008-09-08 09:49:01Z tfheen"); - vsb_cat(sb, " $\n *\n * NB: This file is machine generated, DO NOT"); - vsb_cat(sb, " EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); + vsb_cat(sb, "/*\n * $Id: vcc_gen_obj.tcl 3580 2009-02-05 08:45:25Z "); + vsb_cat(sb, "tfheen $\n *\n * NB: This file is machine generated, "); + vsb_cat(sb, "DO NOT EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct "); vsb_cat(sb, "sess *);\nstruct sockaddr * VRT_r_server_ip(struct ses"); vsb_cat(sb, "s *);\nint VRT_r_server_port(struct sess *);\n"); From tfheen at projects.linpro.no Thu Feb 5 09:43:31 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:43:31 +0100 (CET) Subject: r3591 - branches/2.0/varnish-cache Message-ID: <20090205094331.8633197BD8@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:43:31 +0100 (Thu, 05 Feb 2009) New Revision: 3591 Modified: branches/2.0/varnish-cache/autogen.des Log: Merge r3341: config-cache is more trouble than it's worth. Modified: branches/2.0/varnish-cache/autogen.des =================================================================== --- branches/2.0/varnish-cache/autogen.des 2009-02-05 09:40:21 UTC (rev 3590) +++ branches/2.0/varnish-cache/autogen.des 2009-02-05 09:43:31 UTC (rev 3591) @@ -11,7 +11,6 @@ export CONFIG_SHELL=/bin/sh ./configure \ - --config-cache \ --enable-developer-warnings \ --enable-debugging-symbols \ --enable-dependency-tracking \ From tfheen at projects.linpro.no Thu Feb 5 09:46:55 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:46:55 +0100 (CET) Subject: r3592 - in branches/2.0/varnish-cache: bin/varnishd bin/varnishtest etc lib/libjemalloc lib/libvarnish man Message-ID: <20090205094655.89AEF1F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:46:55 +0100 (Thu, 05 Feb 2009) New Revision: 3592 Modified: branches/2.0/varnish-cache/bin/varnishd/ branches/2.0/varnish-cache/bin/varnishtest/ branches/2.0/varnish-cache/etc/ branches/2.0/varnish-cache/lib/libjemalloc/ branches/2.0/varnish-cache/lib/libvarnish/ branches/2.0/varnish-cache/man/ Log: Merge r3342: svn:ignore Property changes on: branches/2.0/varnish-cache/bin/varnishd ___________________________________________________________________ Name: svn:ignore - .deps .libs Makefile Makefile.in varnishd + .deps .libs Makefile Makefile.in default_vcl.h varnishd Property changes on: branches/2.0/varnish-cache/bin/varnishtest ___________________________________________________________________ Name: svn:ignore + .deps .libs Makefile Makefile.in varnishtest Property changes on: branches/2.0/varnish-cache/etc ___________________________________________________________________ Name: svn:ignore - Makefile Makefile.in + Makefile Makefile.in default.vcl Property changes on: branches/2.0/varnish-cache/lib/libjemalloc ___________________________________________________________________ Name: svn:ignore + .deps .libs Makefile Makefile.in Property changes on: branches/2.0/varnish-cache/lib/libvarnish ___________________________________________________________________ Name: svn:ignore - .deps .libs Makefile Makefile.in + .deps .libs Makefile Makefile.in num_c_test Property changes on: branches/2.0/varnish-cache/man ___________________________________________________________________ Name: svn:ignore - Makefile Makefile.in + Makefile Makefile.in default.vcl vcl.7 From tfheen at projects.linpro.no Thu Feb 5 09:50:34 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:50:34 +0100 (CET) Subject: r3593 - branches/2.0/varnish-cache/lib/libjemalloc Message-ID: <20090205095034.9E0E81F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:50:34 +0100 (Thu, 05 Feb 2009) New Revision: 3593 Modified: branches/2.0/varnish-cache/lib/libjemalloc/jemalloc_linux.c Log: Merge r3343: Fix warnings on Linux Modified: branches/2.0/varnish-cache/lib/libjemalloc/jemalloc_linux.c =================================================================== --- branches/2.0/varnish-cache/lib/libjemalloc/jemalloc_linux.c 2009-02-05 09:46:55 UTC (rev 3592) +++ branches/2.0/varnish-cache/lib/libjemalloc/jemalloc_linux.c 2009-02-05 09:50:34 UTC (rev 3593) @@ -2029,6 +2029,7 @@ { void *ret; + (void)zero; /* XXX */ assert(size != 0); assert((size & chunksize_mask) == 0); @@ -3045,6 +3046,7 @@ { void *ret; + (void)arena; /* XXX */ assert(run->magic == ARENA_RUN_MAGIC); assert(run->nfree > 0); From tfheen at projects.linpro.no Thu Feb 5 09:53:24 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:53:24 +0100 (CET) Subject: r3594 - in branches/2.0/varnish-cache/lib: libvarnish libvarnishcompat Message-ID: <20090205095324.548111F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:53:24 +0100 (Thu, 05 Feb 2009) New Revision: 3594 Modified: branches/2.0/varnish-cache/lib/libvarnish/tcp.c branches/2.0/varnish-cache/lib/libvarnish/vsb.c branches/2.0/varnish-cache/lib/libvarnishcompat/strndup.c Log: Merge r3345: Get rid of . Modified: branches/2.0/varnish-cache/lib/libvarnish/tcp.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/tcp.c 2009-02-05 09:50:34 UTC (rev 3593) +++ branches/2.0/varnish-cache/lib/libvarnish/tcp.c 2009-02-05 09:53:24 UTC (rev 3594) @@ -102,7 +102,7 @@ struct accept_filter_arg afa; int i; - bzero(&afa, sizeof(afa)); + memset(&afa, 0, sizeof(afa)); strcpy(afa.af_name, "httpready"); errno = 0; i = setsockopt(sock, SOL_SOCKET, SO_ACCEPTFILTER, Modified: branches/2.0/varnish-cache/lib/libvarnish/vsb.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vsb.c 2009-02-05 09:50:34 UTC (rev 3593) +++ branches/2.0/varnish-cache/lib/libvarnish/vsb.c 2009-02-05 09:53:24 UTC (rev 3594) @@ -34,7 +34,6 @@ #include #include #include -#include #include "libvarnish.h" #include "vsb.h" @@ -135,7 +134,7 @@ newbuf = (char *)SBMALLOC(newsize); if (newbuf == NULL) return (-1); - bcopy(s->s_buf, newbuf, s->s_size); + memcpy(newbuf, s->s_buf, s->s_size); if (VSB_ISDYNAMIC(s)) SBFREE(s->s_buf); else @@ -163,12 +162,12 @@ s = (struct vsb *)SBMALLOC(sizeof *s); if (s == NULL) return (NULL); - bzero(s, sizeof *s); + memset(s, 0, sizeof *s); s->s_flags = flags; s->s_magic = VSB_MAGIC; VSB_SETFLAG(s, VSB_DYNSTRUCT); } else { - bzero(s, sizeof *s); + memset(s, 0, sizeof *s); s->s_flags = flags; s->s_magic = VSB_MAGIC; } @@ -464,7 +463,7 @@ if (VSB_ISDYNAMIC(s)) SBFREE(s->s_buf); isdyn = VSB_ISDYNSTRUCT(s); - bzero(s, sizeof *s); + memset(s, 0, sizeof *s); if (isdyn) SBFREE(s); } Modified: branches/2.0/varnish-cache/lib/libvarnishcompat/strndup.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnishcompat/strndup.c 2009-02-05 09:50:34 UTC (rev 3593) +++ branches/2.0/varnish-cache/lib/libvarnishcompat/strndup.c 2009-02-05 09:53:24 UTC (rev 3594) @@ -36,7 +36,6 @@ #include #include -#include #ifndef HAVE_STRLCPY #include "compat/strlcpy.h" From tfheen at projects.linpro.no Thu Feb 5 09:56:55 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 10:56:55 +0100 (CET) Subject: r3595 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090205095655.60A501F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-05 10:56:55 +0100 (Thu, 05 Feb 2009) New Revision: 3595 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/v00017.vtc Log: Merge r3352/r3350: make tests fail if you have a long and correct search list; which my laptop has Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/v00017.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/v00017.vtc 2009-02-05 09:53:24 UTC (rev 3594) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/v00017.vtc 2009-02-05 09:56:55 UTC (rev 3595) @@ -34,7 +34,7 @@ varnish v1 -badvcl { backend b { .host = "127.0.0.1"; } - acl a { "en.lille.nisse.rejste"; } + acl a { "en.lille.nisse.rejste."; } sub vcl_recv { if (client.ip ~ a) { pass; } } } @@ -60,8 +60,8 @@ backend b { .host = "127.0.0.1"; } acl a { ! "10.1.3"; - ("en.lille.nisse.rejste" / 22); - (!"en.lille.nisse.rejste"); + ("en.lille.nisse.rejste." / 22); + (!"en.lille.nisse.rejste."); } sub vcl_recv { if (client.ip ~ a) { pass; } } } From tfheen at projects.linpro.no Thu Feb 5 10:04:13 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 11:04:13 +0100 (CET) Subject: r3596 - in branches/2.0/varnish-cache: bin/varnishd include Message-ID: <20090205100413.4403E1F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-05 11:04:12 +0100 (Thu, 05 Feb 2009) New Revision: 3596 Added: branches/2.0/varnish-cache/include/http_response.h Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c Log: Merge r3355: Factor the HTTP responsecodes into a file where we can find them. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-05 09:56:55 UTC (rev 3595) +++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-05 10:04:12 UTC (rev 3596) @@ -98,46 +98,8 @@ unsigned nbr; const char *txt; } http_msg[] = { - { 101, "Switching Protocols" }, - { 200, "OK" }, - { 201, "Created" }, - { 202, "Accepted" }, - { 203, "Non-Authoritative Information" }, - { 204, "No Content" }, - { 205, "Reset Content" }, - { 206, "Partial Content" }, - { 300, "Multiple Choices" }, - { 301, "Moved Permanently" }, - { 302, "Found" }, - { 303, "See Other" }, - { 304, "Not Modified" }, - { 305, "Use Proxy" }, - { 306, "(Unused)" }, - { 307, "Temporary Redirect" }, - { 400, "Bad Request" }, - { 401, "Unauthorized" }, - { 402, "Payment Required" }, - { 403, "Forbidden" }, - { 404, "Not Found" }, - { 405, "Method Not Allowed" }, - { 406, "Not Acceptable" }, - { 407, "Proxy Authentication Required" }, - { 408, "Request Timeout" }, - { 409, "Conflict" }, - { 410, "Gone" }, - { 411, "Length Required" }, - { 412, "Precondition Failed" }, - { 413, "Request Entity Too Large" }, - { 414, "Request-URI Too Long" }, - { 415, "Unsupported Media Type" }, - { 416, "Requested Range Not Satisfiable" }, - { 417, "Expectation Failed" }, - { 500, "Internal Server Error" }, - { 501, "Not Implemented" }, - { 502, "Bad Gateway" }, - { 503, "Service Unavailable" }, - { 504, "Gateway Timeout" }, - { 505, "HTTP Version Not Supported" }, +#define HTTP_RESP(n, t) { n, t}, +#include "http_response.h" { 0, NULL } }; Copied: branches/2.0/varnish-cache/include/http_response.h (from rev 3355, trunk/varnish-cache/include/http_response.h) =================================================================== --- branches/2.0/varnish-cache/include/http_response.h (rev 0) +++ branches/2.0/varnish-cache/include/http_response.h 2009-02-05 10:04:12 UTC (rev 3596) @@ -0,0 +1,71 @@ +/*- + * 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$ + */ + +HTTP_RESP(101, "Switching Protocols") +HTTP_RESP(200, "OK") +HTTP_RESP(201, "Created") +HTTP_RESP(202, "Accepted") +HTTP_RESP(203, "Non-Authoritative Information") +HTTP_RESP(204, "No Content") +HTTP_RESP(205, "Reset Content") +HTTP_RESP(206, "Partial Content") +HTTP_RESP(300, "Multiple Choices") +HTTP_RESP(301, "Moved Permanently") +HTTP_RESP(302, "Found") +HTTP_RESP(303, "See Other") +HTTP_RESP(304, "Not Modified") +HTTP_RESP(305, "Use Proxy") +HTTP_RESP(306, "(Unused)") +HTTP_RESP(307, "Temporary Redirect") +HTTP_RESP(400, "Bad Request") +HTTP_RESP(401, "Unauthorized") +HTTP_RESP(402, "Payment Required") +HTTP_RESP(403, "Forbidden") +HTTP_RESP(404, "Not Found") +HTTP_RESP(405, "Method Not Allowed") +HTTP_RESP(406, "Not Acceptable") +HTTP_RESP(407, "Proxy Authentication Required") +HTTP_RESP(408, "Request Timeout") +HTTP_RESP(409, "Conflict") +HTTP_RESP(410, "Gone") +HTTP_RESP(411, "Length Required") +HTTP_RESP(412, "Precondition Failed") +HTTP_RESP(413, "Request Entity Too Large") +HTTP_RESP(414, "Request-URI Too Long") +HTTP_RESP(415, "Unsupported Media Type") +HTTP_RESP(416, "Requested Range Not Satisfiable") +HTTP_RESP(417, "Expectation Failed") +HTTP_RESP(500, "Internal Server Error") +HTTP_RESP(501, "Not Implemented") +HTTP_RESP(502, "Bad Gateway") +HTTP_RESP(503, "Service Unavailable") +HTTP_RESP(504, "Gateway Timeout") +HTTP_RESP(505, "HTTP Version Not Supported") From tfheen at projects.linpro.no Thu Feb 5 10:07:47 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 11:07:47 +0100 (CET) Subject: r3597 - in branches/2.0/varnish-cache: . lib/libvcl Message-ID: <20090205100747.DDD0F1F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-05 11:07:47 +0100 (Thu, 05 Feb 2009) New Revision: 3597 Modified: branches/2.0/varnish-cache/configure.ac branches/2.0/varnish-cache/lib/libvcl/Makefile.am Log: Merre r3360: Fix up tclsh invocation (again) Move the || true bit of invoking tclsh to the Makefile, since missing would otherwise not pass the file name to tclsh. Thanks to des for spotting this. Modified: branches/2.0/varnish-cache/configure.ac =================================================================== --- branches/2.0/varnish-cache/configure.ac 2009-02-05 10:04:12 UTC (rev 3596) +++ branches/2.0/varnish-cache/configure.ac 2009-02-05 10:07:47 UTC (rev 3597) @@ -232,7 +232,7 @@ AM_MISSING_HAS_RUN AC_CHECK_PROGS(TCLSH, [tclsh tclsh8.4 tclsh8.5], :) if test "$TCLSH" = :; then - TCLSH="${am_missing_run}tclsh || true" + TCLSH="${am_missing_run}tclsh" fi # Solaris defines SO_{RCV,SND}TIMEO, but does not implement them. Modified: branches/2.0/varnish-cache/lib/libvcl/Makefile.am =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/Makefile.am 2009-02-05 10:04:12 UTC (rev 3596) +++ branches/2.0/varnish-cache/lib/libvcl/Makefile.am 2009-02-05 10:07:47 UTC (rev 3597) @@ -29,10 +29,10 @@ vcc_gen_fixed_token.tcl $(srcdir)/vcc_obj.c: $(srcdir)/vcc_gen_obj.tcl - cd $(srcdir) && @TCLSH@ vcc_gen_obj.tcl + cd $(srcdir) && @TCLSH@ vcc_gen_obj.tcl || true $(srcdir)/vcc_fixed_token.c: $(srcdir)/vcc_gen_fixed_token.tcl $(top_srcdir)/include/vcl.h $(top_srcdir)/include/vrt.h $(top_srcdir)/include/vrt_obj.h - cd $(srcdir) && @TCLSH@ vcc_gen_fixed_token.tcl + cd $(srcdir) && @TCLSH@ vcc_gen_fixed_token.tcl || true $(srcdir)/vcc_token_defs.h: $(srcdir)/vcc_gen_fixed_token.tcl $(top_srcdir)/include/vcl.h $(top_srcdir)/include/vrt.h $(top_srcdir)/include/vrt_obj.h - cd $(srcdir) && @TCLSH@ vcc_gen_fixed_token.tcl + cd $(srcdir) && @TCLSH@ vcc_gen_fixed_token.tcl || true From tfheen at projects.linpro.no Thu Feb 5 10:10:59 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 11:10:59 +0100 (CET) Subject: r3598 - in branches/2.0/varnish-cache: bin/varnishd lib/libvcl Message-ID: <20090205101059.02C121F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-05 11:10:58 +0100 (Thu, 05 Feb 2009) New Revision: 3598 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/cache_http.c branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c branches/2.0/varnish-cache/bin/varnishd/stevedore.c branches/2.0/varnish-cache/bin/varnishd/storage_file.c branches/2.0/varnish-cache/lib/libvcl/vcc_token.c Log: Merge r3363: Constifications requested by FlexeLint v9 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c 2009-02-05 10:07:47 UTC (rev 3597) +++ branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.c 2009-02-05 10:10:58 UTC (rev 3598) @@ -49,7 +49,7 @@ #include "cache.h" #include "cache_acceptor.h" -static struct acceptor *vca_acceptors[] = { +static struct acceptor * const vca_acceptors[] = { #if defined(HAVE_KQUEUE) &acceptor_kqueue, #endif @@ -63,7 +63,7 @@ NULL, }; -static struct acceptor *vca_act; +static struct acceptor const *vca_act; static pthread_t vca_thread_acct; static struct timeval tv_sndtimeo; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c 2009-02-05 10:07:47 UTC (rev 3597) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c 2009-02-05 10:10:58 UTC (rev 3598) @@ -86,7 +86,7 @@ static VTAILQ_HEAD(, vbp_target) vbp_list = VTAILQ_HEAD_INITIALIZER(vbp_list); -static char default_request[] = +static const char default_request[] = "GET / HTTP/1.1\r\n" "Connection: close\r\n" "\r\n"; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-05 10:07:47 UTC (rev 3597) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-05 10:10:58 UTC (rev 3598) @@ -66,7 +66,7 @@ #include "cache.h" #include "stevedore.h" -static struct hash_slinger *hash; +static const struct hash_slinger *hash; double HSH_Grace(double g) Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-05 10:07:47 UTC (rev 3597) +++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-05 10:10:58 UTC (rev 3598) @@ -65,7 +65,7 @@ LOGMTX2(ax, HTTP_HDR_FIRST, Header), \ } -static enum shmlogtag logmtx[][HTTP_HDR_FIRST + 1] = { +static const enum shmlogtag logmtx[][HTTP_HDR_FIRST + 1] = { [HTTP_Rx] = LOGMTX1(Rx), [HTTP_Tx] = LOGMTX1(Tx), [HTTP_Obj] = LOGMTX1(Obj) Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 10:07:47 UTC (rev 3597) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 10:10:58 UTC (rev 3598) @@ -78,7 +78,7 @@ /* * Keep this in synch with man/vcl.7 and etc/default.vcl! */ -static const char *default_vcl = +static const char * const default_vcl = #include "default_vcl.h" "" ; Modified: branches/2.0/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/stevedore.c 2009-02-05 10:07:47 UTC (rev 3597) +++ branches/2.0/varnish-cache/bin/varnishd/stevedore.c 2009-02-05 10:10:58 UTC (rev 3598) @@ -40,7 +40,7 @@ static VTAILQ_HEAD(, stevedore) stevedores = VTAILQ_HEAD_INITIALIZER(stevedores); -static struct stevedore * volatile stv_next; +static const struct stevedore * volatile stv_next; struct storage * STV_alloc(struct sess *sp, size_t size) Modified: branches/2.0/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_file.c 2009-02-05 10:07:47 UTC (rev 3597) +++ branches/2.0/varnish-cache/bin/varnishd/storage_file.c 2009-02-05 10:10:58 UTC (rev 3598) @@ -233,8 +233,8 @@ /* XXX: force block allocation here or in open ? */ } -static char default_size[] = "50%"; -static char default_filename[] = "."; +static const char default_size[] = "50%"; +static const char default_filename[] = "."; static void smf_init(struct stevedore *parent, int ac, char * const *av) Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_token.c 2009-02-05 10:07:47 UTC (rev 3597) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_token.c 2009-02-05 10:10:58 UTC (rev 3598) @@ -248,7 +248,7 @@ static int8_t vcc_xdig(const char c) { - static const char *xdigit = + static const char * const xdigit = "0123456789abcdef" "0123456789ABCDEF"; const char *p; From tfheen at projects.linpro.no Thu Feb 5 10:13:52 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 11:13:52 +0100 (CET) Subject: r3599 - in branches/2.0/varnish-cache: bin/varnishd lib/libvarnish lib/libvcl Message-ID: <20090205101352.C6E011F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-05 11:13:52 +0100 (Thu, 05 Feb 2009) New Revision: 3599 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c branches/2.0/varnish-cache/bin/varnishd/mgt_child.c branches/2.0/varnish-cache/bin/varnishd/varnishd.c branches/2.0/varnish-cache/lib/libvarnish/crc32.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c branches/2.0/varnish-cache/lib/libvcl/vcc_priv.h Log: Merge r3364: More FlexeLint v9 consts Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-05 10:10:58 UTC (rev 3598) +++ branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-05 10:13:52 UTC (rev 3599) @@ -69,8 +69,8 @@ * housekeeping fields parts of an object. */ -static const char *tmr_prefetch = "prefetch"; -static const char *tmr_ttl = "ttl"; +static const char * const tmr_prefetch = "prefetch"; +static const char * const tmr_ttl = "ttl"; struct objexp { unsigned magic; Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_child.c 2009-02-05 10:10:58 UTC (rev 3598) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_child.c 2009-02-05 10:13:52 UTC (rev 3599) @@ -81,7 +81,7 @@ CH_DIED = 4 } child_state = CH_STOPPED; -static const char *ch_state[] = { +static const char * const ch_state[] = { [CH_STOPPED] = "stopped", [CH_STARTING] = "starting", [CH_RUNNING] = "running", Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-05 10:10:58 UTC (rev 3598) +++ branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-05 10:13:52 UTC (rev 3599) @@ -117,7 +117,7 @@ extern struct stevedore smu_stevedore; #endif -static struct choice stv_choice[] = { +static const struct choice stv_choice[] = { { "file", &smf_stevedore }, { "malloc", &sma_stevedore }, #ifdef HAVE_LIBUMEM @@ -158,7 +158,7 @@ extern struct hash_slinger hsl_slinger; extern struct hash_slinger hcl_slinger; -static struct choice hsh_choice[] = { +static const struct choice hsh_choice[] = { { "classic", &hcl_slinger }, { "simple", &hsl_slinger }, { "simple_list", &hsl_slinger }, /* backwards compat */ Modified: branches/2.0/varnish-cache/lib/libvarnish/crc32.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/crc32.c 2009-02-05 10:10:58 UTC (rev 3598) +++ branches/2.0/varnish-cache/lib/libvarnish/crc32.c 2009-02-05 10:13:52 UTC (rev 3599) @@ -37,7 +37,7 @@ /*--------------------------------------------------------------------*/ -static uint32_t crc32bits[] = { +static const uint32_t crc32bits[] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 10:10:58 UTC (rev 3598) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 10:13:52 UTC (rev 3599) @@ -104,7 +104,7 @@ } } -const char *vcl_tnames[256] = { +const char * const vcl_tnames[256] = { ['!'] = "'!'", ['%'] = "'%'", ['&'] = "'&'", Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_priv.h =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_priv.h 2009-02-05 10:10:58 UTC (rev 3598) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_priv.h 2009-02-05 10:13:52 UTC (rev 3599) @@ -39,7 +39,7 @@ #define isident(c) (isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-') #define isvar(c) (isident(c) || (c) == '.') unsigned vcl_fixed_token(const char *p, const char **q); -extern const char *vcl_tnames[256]; +extern const char * const vcl_tnames[256]; void vcl_output_lang_h(struct vsb *sb); #define PF(t) (int)((t)->e - (t)->b), (t)->b From tfheen at projects.linpro.no Thu Feb 5 10:16:46 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 11:16:46 +0100 (CET) Subject: r3600 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205101646.544C31F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-05 11:16:46 +0100 (Thu, 05 Feb 2009) New Revision: 3600 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_poll.c branches/2.0/varnish-cache/bin/varnishd/flint.lnt Log: Merge r3365: A couple of stylistisc FlexeLint v9 nits, and some additions to the .lnt file. Unfortunately the thread support in FlexeLint is not quite up to our standards of creative locking. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 10:13:52 UTC (rev 3599) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 10:16:46 UTC (rev 3600) @@ -615,9 +615,25 @@ #define MTX pthread_mutex_t #define MTX_INIT(foo) AZ(pthread_mutex_init(foo, NULL)) #define MTX_DESTROY(foo) AZ(pthread_mutex_destroy(foo)) + +#ifdef __flexelint_v9__ #define TRYLOCK(foo, r) \ do { \ (r) = pthread_mutex_trylock(foo); \ +} while (0) +#define LOCK(foo) \ +do { \ + AZ(pthread_mutex_lock(foo)); \ +} while (0) +#define UNLOCK(foo) \ +do { \ + AZ(pthread_mutex_unlock(foo)); \ +} while (0) + +#else +#define TRYLOCK(foo, r) \ +do { \ + (r) = pthread_mutex_trylock(foo); \ assert(r == 0 || r == EBUSY); \ if (params->diag_bitmap & 0x8) { \ VSL(SLT_Debug, 0, \ @@ -652,6 +668,7 @@ "MTX_UNLOCK(%s,%s,%d," #foo ")", \ __func__, __FILE__, __LINE__); \ } while (0) +#endif #if defined(HAVE_PTHREAD_MUTEX_ISOWNED_NP) #define ALOCKED(mutex) AN(pthread_mutex_isowned_np((mutex))) @@ -693,8 +710,7 @@ { Tcheck(t); - return - ((unsigned)(t.e - t.b)); + return ((unsigned)(t.e - t.b)); } static inline void Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_poll.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2009-02-05 10:13:52 UTC (rev 3599) +++ branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2009-02-05 10:16:46 UTC (rev 3600) @@ -55,7 +55,7 @@ vca_pollspace(unsigned fd) { struct pollfd *newpollfd = pollfd; - unsigned newnpoll = npoll; + unsigned newnpoll; if (fd < npoll) return; Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-05 10:13:52 UTC (rev 3599) +++ branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-05 10:16:46 UTC (rev 3600) @@ -1,5 +1,47 @@ --passes=3 +-d__flexelint_v9__=1 + +//-sem (pthread_mutex_lock, thread_lock) +-sem (pthread_mutex_trylock, thread_lock) +-sem (VBE_DropRefLocked, thread_unlock) +-e459 // unlocked access from func-ptr +-e454 // mutex not released (...ReleaseLocked) +-e457 // unprotected access + +-esym(458, lbv_assert) // unlocked access +-esym(458, params) // unlocked access + +-emacro(835, HTTPH) // Info 835: A zero has been given as left argument to operator '&' +-emacro(845, HTTPH) // Info 845: The left argument to operator '&&' is certain to be 0 +////////////// +-efunc(1791, pdiff) // return last on line +////////////// +-efile(451, "sys/*.h") // No include guard +-efile(451, "machine/*.h") // No include guard +-efile(451, "vcl_returns.h") // No include guard +-efile(451, "cache_backend_poll.h") // No include guard +-efile(451, "steps.h") // No include guard +-efile(451, "http_headers.h") // No include guard +-efile(451, "stat_field.h") // No include guard +-efile(451, "acct_fields.h") // No include guard +-efile(451, "config.h") // No include guard +////////////// +// -e458 // unprotected access +// -e456 // merged locking paths +-sem(vca_thread_acct, thread_mono) +-sem(vca_epoll_thread, thread_mono) +-sem(vca_kqueue_thread, thread_mono) +-sem(vca_poll_thread, thread_mono) +-sem(vca_ports_thread, thread_mono) +-sem(exp_timer, thread_mono) +-sem(wrk_herdtimer_thread, thread_mono) +-sem(wrk_herder_thread, thread_mono) +-esym(458, VSL_stats) +-esym(458, heritage) +-esym(458, name_key) +////////////// +-passes=1 + +libh mgt_event.h +libh ../../config.h From tfheen at projects.linpro.no Thu Feb 5 10:21:48 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 11:21:48 +0100 (CET) Subject: r3601 - branches/2.0/varnish-cache/lib/libvcl Message-ID: <20090205102148.B863B1F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-05 11:21:48 +0100 (Thu, 05 Feb 2009) New Revision: 3601 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl Log: Merge r3377: Constify vcl_tnames in .tcl script too Change the .tcl script corresponding to r3364, fixes build failure Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-05 10:16:46 UTC (rev 3600) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-05 10:21:48 UTC (rev 3601) @@ -331,7 +331,7 @@ puts $fo "}" puts $fo "" -puts $fo "const char *vcl_tnames\[256\] = {" +puts $fo "const char * const vcl_tnames\[256\] = {" foreach i $token2 { puts $fo "\t\[[lindex $i 0]\] = \"[lindex $i 0]\"," } From tfheen at projects.linpro.no Thu Feb 5 10:29:18 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 11:29:18 +0100 (CET) Subject: r3602 - in branches/2.0/varnish-cache: bin/varnishtest/tests lib/libvcl Message-ID: <20090205102918.6901B28370@projects.linpro.no> Author: tfheen Date: 2009-02-05 11:29:18 +0100 (Thu, 05 Feb 2009) New Revision: 3602 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/v00016.vtc branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Merge r3378 + 3389: Make sure the VCL we try to load is a regular file Fixes #368 r3389 | phk | 2008-11-11 21:40:37 +0100 (ti., 11 nov. 2008) | 4 lines Fix this test-case to not rely on being able to compile /dev/null now that this is no longer possible. Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/v00016.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/v00016.vtc 2009-02-05 10:21:48 UTC (rev 3601) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/v00016.vtc 2009-02-05 10:29:18 UTC (rev 3602) @@ -2,16 +2,20 @@ test "Various VCL compiler coverage tests" +shell "true > /tmp/_varnishtest_empty_file" + varnish v1 -vcl { backend b { .host = "127.0.0.1"; } - include "/dev/null" ; + include "/tmp/_varnishtest_empty_file" ; } varnish v1 -badvcl { backend b { .host = "127.0.0.1"; } - include "/dev/null" | + include "/tmp/_varnishtest_empty_file" | } +shell "rm -f /tmp/_varnishtest_empty_file" + varnish v1 -badvcl { backend b { .host = "127.0.0.1"; } include << Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 10:21:48 UTC (rev 3601) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 10:29:18 UTC (rev 3602) @@ -415,6 +415,11 @@ } } assert(0 == fstat(fd, &st)); + if (! S_ISREG(st.st_mode)) { + vsb_printf(sb, "File '%s' is not a regular file\n", fn); + AZ(close(fd)); + return (NULL); + } f = malloc(st.st_size + 1); assert(f != NULL); i = read(fd, f, st.st_size); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 10:21:48 UTC (rev 3601) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 10:29:18 UTC (rev 3602) @@ -167,8 +167,8 @@ /* ../../include/vcl.h */ - vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3588 2009-02-05 09"); - vsb_cat(sb, ":34:34Z tfheen $\n *\n * NB: This file is machine gen"); + vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3601 2009-02-05 10"); + vsb_cat(sb, ":21:48Z tfheen $\n *\n * NB: This file is machine gen"); vsb_cat(sb, "erated, DO NOT EDIT!\n *\n * Edit vcc_gen_fixed_token."); vsb_cat(sb, "tcl instead\n */\n\nstruct sess;\n"); vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n"); From tfheen at projects.linpro.no Thu Feb 5 10:34:00 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 11:34:00 +0100 (CET) Subject: r3603 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205103400.5E22E28370@projects.linpro.no> Author: tfheen Date: 2009-02-05 11:34:00 +0100 (Thu, 05 Feb 2009) New Revision: 3603 Added: branches/2.0/varnish-cache/bin/varnishd/cache_lck.c Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_backend.c branches/2.0/varnish-cache/bin/varnishd/cache_backend.h branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/bin/varnishd/cache_cli.c branches/2.0/varnish-cache/bin/varnishd/cache_expire.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/cache_main.c branches/2.0/varnish-cache/bin/varnishd/cache_pool.c branches/2.0/varnish-cache/bin/varnishd/cache_session.c branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c branches/2.0/varnish-cache/bin/varnishd/hash_classic.c branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c branches/2.0/varnish-cache/bin/varnishd/shmlog.c branches/2.0/varnish-cache/bin/varnishd/storage_file.c branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c branches/2.0/varnish-cache/bin/varnishd/storage_synth.c branches/2.0/varnish-cache/bin/varnishd/storage_umem.c Log: Merge r3381+r3382: Wrap mutex ops in proper C functions Take the full step and wrap all our mutex operations in proper C functions instead of increasingly unwieldy macros. Amongst other things, this will make it much easier to do lock profiling, contest statistics, asserts etc. This commit is largely mechanically generated and should not result in any changed functionality. Locks retain the "mtx" monicker, as a reminder that they are mutexes. No performance impact expected. Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-05 10:34:00 UTC (rev 3603) @@ -27,6 +27,7 @@ cache_http.c \ cache_httpconn.c \ cache_main.c \ + cache_lck.c \ cache_panic.c \ cache_pipe.c \ cache_pool.c \ Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 10:34:00 UTC (rev 3603) @@ -87,6 +87,7 @@ struct vrt_backend; struct cli_proto; struct ban; +struct lock { void *priv; }; // Opaque /*--------------------------------------------------------------------*/ @@ -295,7 +296,7 @@ #define OBJHEAD_MAGIC 0x1b96615d void *hashpriv; - pthread_mutex_t mtx; + struct lock mtx; VTAILQ_HEAD(,object) objects; char *hash; unsigned hashlen; @@ -512,6 +513,27 @@ void THR_SetSession(const struct sess *sp); const struct sess * THR_GetSession(void); +/* cache_lck.c */ + +/* Internal functions, call only through macros below */ +void Lck__Lock(struct lock *lck, const char *p, const char *f, int l); +void Lck__Unlock(struct lock *lck, const char *p, const char *f, int l); +int Lck__Trylock(struct lock *lck, const char *p, const char *f, int l); +void Lck__New(struct lock *lck, const char *w); +void Lck__Assert(struct lock *lck, int held); + +/* public interface: */ +void LCK_Init(void); +void Lck_Delete(struct lock *lck); +void Lck_CondWait(pthread_cond_t *cond, struct lock *lck); + +#define Lck_New(a) Lck__New(a, #a); +#define Lck_Lock(a) Lck__Lock(a, __func__, __FILE__, __LINE__) +#define Lck_Unlock(a) Lck__Unlock(a, __func__, __FILE__, __LINE__) +#define Lck_Trylock(a) Lck__Trylock(a, __func__, __FILE__, __LINE__) +#define Lck_AssertHeld(a) Lck__Assert(a, 1) +#define Lck_AssertNotHeld(a) Lck__Assert(a, 0) + /* cache_panic.c */ void PAN_Init(void); @@ -612,72 +634,6 @@ 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)) - -#ifdef __flexelint_v9__ -#define TRYLOCK(foo, r) \ -do { \ - (r) = pthread_mutex_trylock(foo); \ -} while (0) -#define LOCK(foo) \ -do { \ - AZ(pthread_mutex_lock(foo)); \ -} while (0) -#define UNLOCK(foo) \ -do { \ - AZ(pthread_mutex_unlock(foo)); \ -} while (0) - -#else -#define TRYLOCK(foo, r) \ -do { \ - (r) = pthread_mutex_trylock(foo); \ - assert(r == 0 || r == EBUSY); \ - if (params->diag_bitmap & 0x8) { \ - VSL(SLT_Debug, 0, \ - "MTX_TRYLOCK(%s,%s,%d," #foo ") = %d", \ - __func__, __FILE__, __LINE__, (r)); \ - } \ -} while (0) -#define LOCK(foo) \ -do { \ - if (!(params->diag_bitmap & 0x18)) { \ - AZ(pthread_mutex_lock(foo)); \ - } else { \ - int ixjd = pthread_mutex_trylock(foo); \ - assert(ixjd == 0 || ixjd == EBUSY); \ - if (ixjd) { \ - VSL(SLT_Debug, 0, \ - "MTX_CONTEST(%s,%s,%d," #foo ")", \ - __func__, __FILE__, __LINE__); \ - AZ(pthread_mutex_lock(foo)); \ - } else if (params->diag_bitmap & 0x8) { \ - VSL(SLT_Debug, 0, \ - "MTX_LOCK(%s,%s,%d," #foo ")", \ - __func__, __FILE__, __LINE__); \ - } \ - } \ -} while (0) -#define UNLOCK(foo) \ -do { \ - AZ(pthread_mutex_unlock(foo)); \ - if (params->diag_bitmap & 0x8) \ - VSL(SLT_Debug, 0, \ - "MTX_UNLOCK(%s,%s,%d," #foo ")", \ - __func__, __FILE__, __LINE__); \ -} while (0) -#endif - -#if defined(HAVE_PTHREAD_MUTEX_ISOWNED_NP) -#define ALOCKED(mutex) AN(pthread_mutex_isowned_np((mutex))) -#elif defined(DIAGNOSTICS) -#define ALOCKED(mutex) AN(pthread_mutex_trylock((mutex))) -#else -#define ALOCKED(mutex) (void)(mutex) -#endif - /* * A normal pointer difference is signed, but we never want a negative value * so this little tool will make sure we don't get that. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -147,11 +147,11 @@ struct bereq *bereq; volatile unsigned len; - LOCK(&VBE_mtx); + Lck_Lock(&VBE_mtx); bereq = VTAILQ_FIRST(&bereq_head); if (bereq != NULL) VTAILQ_REMOVE(&bereq_head, bereq, list); - UNLOCK(&VBE_mtx); + Lck_Unlock(&VBE_mtx); if (bereq != NULL) { CHECK_OBJ(bereq, BEREQ_MAGIC); } else { @@ -177,9 +177,9 @@ CHECK_OBJ_NOTNULL(bereq, BEREQ_MAGIC); WS_Reset(bereq->ws, NULL); - LOCK(&VBE_mtx); + Lck_Lock(&VBE_mtx); VTAILQ_INSERT_HEAD(&bereq_head, bereq, list); - UNLOCK(&VBE_mtx); + Lck_Unlock(&VBE_mtx); } /*-------------------------------------------------------------------- @@ -195,13 +195,13 @@ vc = VTAILQ_FIRST(&vbe_conns); if (vc != NULL) { - LOCK(&VBE_mtx); + Lck_Lock(&VBE_mtx); vc = VTAILQ_FIRST(&vbe_conns); if (vc != NULL) { VSL_stats->backend_unused--; VTAILQ_REMOVE(&vbe_conns, vc, list); } - UNLOCK(&VBE_mtx); + Lck_Unlock(&VBE_mtx); } if (vc != NULL) return (vc); @@ -222,10 +222,10 @@ assert(vc->fd < 0); if (params->cache_vbe_conns) { - LOCK(&VBE_mtx); + Lck_Lock(&VBE_mtx); VTAILQ_INSERT_HEAD(&vbe_conns, vc, list); VSL_stats->backend_unused++; - UNLOCK(&VBE_mtx); + Lck_Unlock(&VBE_mtx); } else { VSL_stats->n_vbe_conn--; free(vc); @@ -239,10 +239,10 @@ { int s; - LOCK(&bp->mtx); + Lck_Lock(&bp->mtx); bp->refcount++; bp->n_conn++; /* It mostly works */ - UNLOCK(&bp->mtx); + Lck_Unlock(&bp->mtx); s = -1; assert(bp->ipv6 != NULL || bp->ipv4 != NULL); @@ -257,10 +257,10 @@ s = VBE_TryConnect(sp, PF_INET6, bp->ipv6, bp->ipv6len, bp); if (s < 0) { - LOCK(&bp->mtx); + Lck_Lock(&bp->mtx); bp->n_conn--; bp->refcount--; /* Only keep ref on success */ - UNLOCK(&bp->mtx); + Lck_Unlock(&bp->mtx); } return (s); } @@ -295,7 +295,7 @@ /* first look for vbe_conn's we can recycle */ while (1) { - LOCK(&bp->mtx); + Lck_Lock(&bp->mtx); vc = VTAILQ_FIRST(&bp->connlist); if (vc != NULL) { bp->refcount++; @@ -303,7 +303,7 @@ assert(vc->fd >= 0); VTAILQ_REMOVE(&bp->connlist, vc, list); } - UNLOCK(&bp->mtx); + Lck_Unlock(&bp->mtx); if (vc == NULL) break; if (VBE_CheckFd(vc->fd)) { @@ -379,7 +379,7 @@ bp = sp->vbe->backend; WSL(sp->wrk, SLT_BackendReuse, sp->vbe->fd, "%s", bp->vcl_name); - LOCK(&bp->mtx); + Lck_Lock(&bp->mtx); VSL_stats->backend_recycle++; VTAILQ_INSERT_HEAD(&bp->connlist, sp->vbe, list); sp->vbe = NULL; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend.h 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend.h 2009-02-05 10:34:00 UTC (rev 3603) @@ -109,7 +109,7 @@ VTAILQ_ENTRY(backend) list; int refcount; - pthread_mutex_t mtx; + struct lock mtx; struct sockaddr *ipv4; socklen_t ipv4len; @@ -129,7 +129,7 @@ struct vbe_conn *VBE_GetVbe(struct sess *sp, struct backend *bp); /* cache_backend_cfg.c */ -extern MTX VBE_mtx; +extern struct lock VBE_mtx; void VBE_DropRefConn(struct backend *); void VBE_DropRef(struct backend *); void VBE_DropRefLocked(struct backend *b); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -48,7 +48,7 @@ #include "cache_backend.h" #include "cli_priv.h" -MTX VBE_mtx; +struct lock VBE_mtx; /* * The list of backends is not locked, it is only ever accessed from @@ -105,7 +105,7 @@ assert(b->refcount > 0); i = --b->refcount; - UNLOCK(&b->mtx); + Lck_Unlock(&b->mtx); if (i > 0) return; @@ -128,7 +128,7 @@ CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - LOCK(&b->mtx); + Lck_Lock(&b->mtx); VBE_DropRefLocked(b); } @@ -138,7 +138,7 @@ CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - LOCK(&b->mtx); + Lck_Lock(&b->mtx); assert(b->n_conn > 0); b->n_conn--; VBE_DropRefLocked(b); @@ -207,7 +207,7 @@ /* Create new backend */ ALLOC_OBJ(b, BACKEND_MAGIC); XXXAN(b); - MTX_INIT(&b->mtx); + Lck_New(&b->mtx); b->refcount = 1; VTAILQ_INIT(&b->connlist); @@ -283,6 +283,6 @@ VBE_Init(void) { - MTX_INIT(&VBE_mtx); + Lck_New(&VBE_mtx); CLI_AddFuncs(DEBUG_CLI, debug_cmds); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -57,7 +57,7 @@ }; static VTAILQ_HEAD(banhead,ban) ban_head = VTAILQ_HEAD_INITIALIZER(ban_head); -static MTX ban_mtx; +static struct lock ban_mtx; /* * We maintain ban_start as a pointer to the first element of the list @@ -95,7 +95,7 @@ b->hash = hash; b->ban = strdup(regexp); AN(b->ban); - LOCK(&ban_mtx); + Lck_Lock(&ban_mtx); VTAILQ_INSERT_HEAD(&ban_head, b, list); ban_start = b; VSL_stats->n_purge++; @@ -106,7 +106,7 @@ be->refcount++; } else be = NULL; - UNLOCK(&ban_mtx); + Lck_Unlock(&ban_mtx); if (be == NULL) return (0); @@ -125,11 +125,11 @@ bi->flags |= BAN_F_GONE; pcount++; } - LOCK(&ban_mtx); + Lck_Lock(&ban_mtx); be->refcount--; /* XXX: We should check if the tail can be removed */ VSL_stats->n_purge_dups += pcount; - UNLOCK(&ban_mtx); + Lck_Unlock(&ban_mtx); return (0); } @@ -140,10 +140,10 @@ CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); AZ(o->ban); - LOCK(&ban_mtx); + Lck_Lock(&ban_mtx); o->ban = ban_start; ban_start->refcount++; - UNLOCK(&ban_mtx); + Lck_Unlock(&ban_mtx); } void @@ -155,7 +155,7 @@ if (o->ban == NULL) return; CHECK_OBJ_NOTNULL(o->ban, BAN_MAGIC); - LOCK(&ban_mtx); + Lck_Lock(&ban_mtx); o->ban->refcount--; o->ban = NULL; @@ -168,7 +168,7 @@ } else { b = NULL; } - UNLOCK(&ban_mtx); + Lck_Unlock(&ban_mtx); if (b != NULL) { free(b->ban); regfree(&b->regexp); @@ -205,13 +205,13 @@ break; } - LOCK(&ban_mtx); + Lck_Lock(&ban_mtx); o->ban->refcount--; if (b == o->ban) /* not banned */ b0->refcount++; VSL_stats->n_purge_obj_test++; VSL_stats->n_purge_re_test += tests; - UNLOCK(&ban_mtx); + Lck_Unlock(&ban_mtx); if (b == o->ban) { /* not banned */ o->ban = b0; @@ -285,7 +285,7 @@ BAN_Init(void) { - MTX_INIT(&ban_mtx); + Lck_New(&ban_mtx); CLI_AddFuncs(PUBLIC_CLI, ban_cmds); /* Add an initial ban, since the list can never be empty */ (void)BAN_Add(NULL, ".", 0); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_cli.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_cli.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -53,8 +53,8 @@ #include "vlu.h" #include "vsb.h" -pthread_t cli_thread; -static MTX cli_mtx; +pthread_t cli_thread; +static struct lock cli_mtx; /* * The CLI commandlist is split in three: @@ -81,12 +81,12 @@ case DEBUG_CLI: cp = &ccf_debug_cli; break; default: INCOMPL(); } - LOCK(&cli_mtx); + Lck_Lock(&cli_mtx); c = cli_concat(*cp, p); AN(c); free(*cp); *cp = c; - UNLOCK(&cli_mtx); + Lck_Unlock(&cli_mtx); } /*-------------------------------------------------------------------- @@ -105,7 +105,7 @@ VCL_Poll(); VBE_Poll(); vsb_clear(cli->sb); - LOCK(&cli_mtx); + Lck_Lock(&cli_mtx); cli_dispatch(cli, ccf_master_cli, p); if (cli->result == CLIS_UNKNOWN) { vsb_clear(cli->sb); @@ -117,7 +117,7 @@ cli->result = CLIS_OK; cli_dispatch(cli, ccf_debug_cli, p); } - UNLOCK(&cli_mtx); + Lck_Unlock(&cli_mtx); vsb_finish(cli->sb); AZ(vsb_overflowed(cli->sb)); i = cli_writeres(heritage.cli_out, cli); @@ -242,7 +242,7 @@ CLI_Init(void) { - MTX_INIT(&cli_mtx); + Lck_New(&cli_mtx); cli_thread = pthread_self(); CLI_AddFuncs(MASTER_CLI, master_cmds); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -86,7 +86,7 @@ static pthread_t exp_thread; static struct binheap *exp_heap; -static MTX exp_mtx; +static struct lock exp_mtx; static VTAILQ_HEAD(,objexp) lru = VTAILQ_HEAD_INITIALIZER(lru); /* @@ -176,12 +176,12 @@ assert(o->entered != 0 && !isnan(o->entered)); oe->lru_stamp = o->entered; update_object_when(o); - LOCK(&exp_mtx); + Lck_Lock(&exp_mtx); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); VTAILQ_INSERT_TAIL(&lru, oe, list); oe->on_lru = 1; - UNLOCK(&exp_mtx); + Lck_Unlock(&exp_mtx); } /*-------------------------------------------------------------------- @@ -196,7 +196,6 @@ void EXP_Touch(const struct object *o, double now) { - int i; struct objexp *oe; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); @@ -206,8 +205,7 @@ CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); if (oe->lru_stamp + params->lru_timeout > now) return; - TRYLOCK(&exp_mtx, i); - if (i) + if (Lck_Trylock(&exp_mtx)) return; if (oe->on_lru) { VTAILQ_REMOVE(&lru, oe, list); @@ -215,7 +213,7 @@ oe->lru_stamp = now; VSL_stats->n_lru_moved++; } - UNLOCK(&exp_mtx); + Lck_Unlock(&exp_mtx); } /*-------------------------------------------------------------------- @@ -238,13 +236,13 @@ return; CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); update_object_when(o); - LOCK(&exp_mtx); + Lck_Lock(&exp_mtx); assert(oe->timer_idx != BINHEAP_NOIDX); binheap_delete(exp_heap, oe->timer_idx); /* XXX: binheap_shuffle() ? */ assert(oe->timer_idx == BINHEAP_NOIDX); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); - UNLOCK(&exp_mtx); + Lck_Unlock(&exp_mtx); } @@ -278,11 +276,11 @@ VCL_Get(&sp->vcl); t = TIM_real(); while (1) { - LOCK(&exp_mtx); + Lck_Lock(&exp_mtx); oe = binheap_root(exp_heap); CHECK_OBJ_ORNULL(oe, OBJEXP_MAGIC); if (oe == NULL || oe->timer_when > t) { /* XXX: > or >= ? */ - UNLOCK(&exp_mtx); + Lck_Unlock(&exp_mtx); WSL_Flush(&ww, 0); AZ(sleep(1)); VCL_Refresh(&sp->vcl); @@ -305,7 +303,7 @@ } assert(oe->on_lru); - UNLOCK(&exp_mtx); + Lck_Unlock(&exp_mtx); WSL(&ww, SLT_ExpPick, 0, "%u %s", o->xid, oe->timer_what); @@ -319,10 +317,10 @@ o->xid); } update_object_when(o); - LOCK(&exp_mtx); + Lck_Lock(&exp_mtx); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); - UNLOCK(&exp_mtx); + Lck_Unlock(&exp_mtx); } else { assert(oe->timer_what == tmr_ttl); sp->obj = o; @@ -332,11 +330,11 @@ assert(sp->handling == VCL_RET_DISCARD); WSL(&ww, SLT_ExpKill, 0, "%u %d", o->xid, (int)(o->ttl - t)); - LOCK(&exp_mtx); + Lck_Lock(&exp_mtx); VTAILQ_REMOVE(&lru, o->objexp, list); oe->on_lru = 0; VSL_stats->n_expired++; - UNLOCK(&exp_mtx); + Lck_Unlock(&exp_mtx); del_objexp(o); HSH_Deref(o); } @@ -367,7 +365,7 @@ * NB: Checking refcount here is no guarantee that it does not gain * another ref while we ponder its destiny without the lock held. */ - LOCK(&exp_mtx); + Lck_Lock(&exp_mtx); VTAILQ_FOREACH(oe, &lru, list) { CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); if (oe->timer_idx == BINHEAP_NOIDX) /* exp_timer has it */ @@ -388,7 +386,7 @@ assert(oe->timer_idx == BINHEAP_NOIDX); VSL_stats->n_lru_nuked++; } - UNLOCK(&exp_mtx); + Lck_Unlock(&exp_mtx); if (oe == NULL) return (-1); @@ -414,14 +412,14 @@ assert(sp->handling == VCL_RET_KEEP); /* Insert in binheap and lru again */ - LOCK(&exp_mtx); + Lck_Lock(&exp_mtx); VSL_stats->n_lru_nuked--; /* It was premature */ VSL_stats->n_lru_saved++; binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); VTAILQ_INSERT_TAIL(&lru, oe, list); oe->on_lru = 1; - UNLOCK(&exp_mtx); + Lck_Unlock(&exp_mtx); return (0); } @@ -456,7 +454,7 @@ EXP_Init(void) { - MTX_INIT(&exp_mtx); + Lck_New(&exp_mtx); exp_heap = binheap_new(NULL, object_cmp, object_update); XXXAN(exp_heap); AZ(pthread_create(&exp_thread, NULL, exp_timer, NULL)); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -93,7 +93,7 @@ w->nobjhead->magic = OBJHEAD_MAGIC; VTAILQ_INIT(&w->nobjhead->objects); VTAILQ_INIT(&w->nobjhead->waitinglist); - MTX_INIT(&w->nobjhead->mtx); + Lck_New(&w->nobjhead->mtx); VSL_stats->n_objecthead++; } else CHECK_OBJ_NOTNULL(w->nobjhead, OBJHEAD_MAGIC); @@ -205,13 +205,13 @@ oh = sp->objhead; sp->objhead = NULL; CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); - LOCK(&oh->mtx); + Lck_Lock(&oh->mtx); } else { oh = hash->lookup(sp, w->nobjhead); CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); if (oh == w->nobjhead) w->nobjhead = NULL; - LOCK(&oh->mtx); + Lck_Lock(&oh->mtx); } busy_o = NULL; @@ -257,7 +257,7 @@ o->refcnt++; if (o->hits < INT_MAX) o->hits++; - UNLOCK(&oh->mtx); + Lck_Unlock(&oh->mtx); if (params->log_hash) WSP(sp, SLT_Hash, "%s", oh->hash); (void)hash->deref(oh); @@ -269,7 +269,7 @@ if (sp->esis == 0) VTAILQ_INSERT_TAIL(&oh->waitinglist, sp, list); sp->objhead = oh; - UNLOCK(&oh->mtx); + Lck_Unlock(&oh->mtx); return (NULL); } @@ -285,7 +285,7 @@ o->parent = grace_o; grace_o->refcnt++; } - UNLOCK(&oh->mtx); + Lck_Unlock(&oh->mtx); if (params->log_hash) WSP(sp, SLT_Hash, "%s", oh->hash); /* @@ -333,7 +333,7 @@ oh = o->objhead; if (oh != NULL) { CHECK_OBJ(oh, OBJHEAD_MAGIC); - LOCK(&oh->mtx); + Lck_Lock(&oh->mtx); } o->busy = 0; if (oh != NULL) @@ -343,7 +343,7 @@ if (parent != NULL) parent->child = NULL; if (oh != NULL) - UNLOCK(&oh->mtx); + Lck_Unlock(&oh->mtx); if (parent != NULL) HSH_Deref(parent); } @@ -357,12 +357,12 @@ oh = o->objhead; if (oh != NULL) { CHECK_OBJ(oh, OBJHEAD_MAGIC); - LOCK(&oh->mtx); + Lck_Lock(&oh->mtx); } assert(o->refcnt > 0); o->refcnt++; if (oh != NULL) - UNLOCK(&oh->mtx); + Lck_Unlock(&oh->mtx); } void @@ -377,7 +377,7 @@ CHECK_OBJ(oh, OBJHEAD_MAGIC); /* drop ref on object */ - LOCK(&oh->mtx); + Lck_Lock(&oh->mtx); } assert(o->refcnt > 0); r = --o->refcnt; @@ -386,7 +386,7 @@ if (oh != NULL) { if (!r) VTAILQ_REMOVE(&oh->objects, o, list); - UNLOCK(&oh->mtx); + Lck_Unlock(&oh->mtx); } /* If still referenced, done */ @@ -411,7 +411,7 @@ if (hash->deref(oh)) return; assert(VTAILQ_EMPTY(&oh->objects)); - MTX_DESTROY(&oh->mtx); + Lck_Delete(&oh->mtx); VSL_stats->n_objecthead--; free(oh->hash); FREE_OBJ(oh); Copied: branches/2.0/varnish-cache/bin/varnishd/cache_lck.c (from rev 3382, trunk/varnish-cache/bin/varnishd/cache_lck.c) =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_lck.c (rev 0) +++ branches/2.0/varnish-cache/bin/varnishd/cache_lck.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -0,0 +1,183 @@ +/*- + * 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$ + * + * The geniuses who came up with pthreads did not think operations like + * pthread_assert_mutex_held() were important enough to include them in + * the API. + * + * Build our own locks on top of pthread mutexes and hope that the next + * civilization is better at such crucial details than this one. + */ + +#include "config.h" + +#include + +#include +#ifdef HAVE_PTHREAD_NP_H +#include +#endif +#include + +#include "shmlog.h" +#include "cache.h" + +struct ilck { + unsigned magic; +#define ILCK_MAGIC 0x7b86c8a5 + pthread_mutex_t mtx; + pthread_t owner; + VTAILQ_ENTRY(ilck) list; + const char *w; +}; + +static VTAILQ_HEAD(, ilck) ilck_head = + VTAILQ_HEAD_INITIALIZER(ilck_head); + +static pthread_mutex_t lck_mtx; + +void +Lck__Lock(struct lock *lck, const char *p, const char *f, int l) +{ + struct ilck *ilck; + int r; + + CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); + if (!(params->diag_bitmap & 0x18)) { + AZ(pthread_mutex_lock(&ilck->mtx)); + AZ(ilck->owner); + ilck->owner = pthread_self(); + return; + } + r = pthread_mutex_trylock(&ilck->mtx); + assert(r == 0 || errno == EBUSY); + if (r) { + VSL(SLT_Debug, 0, "MTX_CONTEST(%s,%s,%d,%s)", p, f, l, ilck->w); + AZ(pthread_mutex_lock(&ilck->mtx)); + } else if (params->diag_bitmap & 0x8) { + VSL(SLT_Debug, 0, "MTX_LOCK(%s,%s,%d,%s)", p, f, l, ilck->w); + } + AZ(ilck->owner); + ilck->owner = pthread_self(); +} + +void +Lck__Unlock(struct lock *lck, const char *p, const char *f, int l) +{ + struct ilck *ilck; + + CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); + assert(ilck->owner == pthread_self()); + ilck->owner = NULL; + AZ(pthread_mutex_unlock(&ilck->mtx)); + if (params->diag_bitmap & 0x8) + VSL(SLT_Debug, 0, "MTX_UNLOCK(%s,%s,%d,%s)", p, f, l, ilck->w); +} + +int +Lck__Trylock(struct lock *lck, const char *p, const char *f, int l) +{ + struct ilck *ilck; + int r; + + CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); + r = pthread_mutex_lock(&ilck->mtx); + assert(r == 0 || errno == EBUSY); + if (params->diag_bitmap & 0x8) + VSL(SLT_Debug, 0, + "MTX_TRYLOCK(%s,%s,%d,%s) = %d", p, f, l, ilck->w); + if (r == 0) { + AZ(ilck->owner); + ilck->owner = pthread_self(); + } + return (r); +} + +void +Lck__Assert(struct lock *lck, int held) +{ + struct ilck *ilck; + + CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); + if (held) + assert(ilck->owner == pthread_self()); + else + assert(ilck->owner != pthread_self()); +} + +void +Lck_CondWait(pthread_cond_t *cond, struct lock *lck) +{ + struct ilck *ilck; + + CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); + assert(ilck->owner == pthread_self()); + ilck->owner = NULL; + AZ(pthread_cond_wait(cond, &ilck->mtx)); + AZ(ilck->owner); + ilck->owner = pthread_self(); +} + +void +Lck__New(struct lock *lck, const char *w) +{ + struct ilck *ilck; + + AZ(lck->priv); + ALLOC_OBJ(ilck, ILCK_MAGIC); + AN(ilck); + ilck->w = w; + AZ(pthread_mutex_init(&ilck->mtx, NULL)); + AZ(pthread_mutex_lock(&lck_mtx)); + VTAILQ_INSERT_TAIL(&ilck_head, ilck, list); + AZ(pthread_mutex_unlock(&lck_mtx)); + lck->priv = ilck; +} + +void +Lck_Delete(struct lock *lck) +{ + struct ilck *ilck; + + CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); + lck->priv = NULL; + AZ(pthread_mutex_lock(&lck_mtx)); + VTAILQ_REMOVE(&ilck_head, ilck, list); + AZ(pthread_mutex_unlock(&lck_mtx)); + AZ(pthread_mutex_destroy(&ilck->mtx)); + FREE_OBJ(ilck); +} + + +void +LCK_Init(void) +{ + + AZ(pthread_mutex_init(&lck_mtx, NULL)); +} Modified: branches/2.0/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_main.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_main.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -101,6 +101,10 @@ THR_SetName("cache-main"); + VSL_Init(); /* First, LCK needs it. */ + + LCK_Init(); /* Locking, must be first */ + PAN_Init(); CLI_Init(); Fetch_Init(); @@ -113,7 +117,6 @@ VBE_Init(); VBP_Init(); - VSL_Init(); WRK_Init(); EXP_Init(); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -79,7 +79,7 @@ struct wq { unsigned magic; #define WQ_MAGIC 0x606658fa - MTX mtx; + struct lock mtx; struct workerhead idle; VTAILQ_HEAD(, workreq) overflow; unsigned nthr; @@ -95,7 +95,7 @@ static unsigned nthr_max; static pthread_cond_t herder_cond; -static MTX herder_mtx; +static struct lock herder_mtx; /*-------------------------------------------------------------------- * Write data to fd @@ -249,7 +249,7 @@ VSL(SLT_WorkThread, 0, "%p start", w); - LOCK(&qp->mtx); + Lck_Lock(&qp->mtx); qp->nthr++; while (1) { CHECK_OBJ_NOTNULL(w, WORKER_MAGIC); @@ -263,20 +263,20 @@ if (isnan(w->lastused)) w->lastused = TIM_real(); VTAILQ_INSERT_HEAD(&qp->idle, w, list); - AZ(pthread_cond_wait(&w->cond, &qp->mtx)); + Lck_CondWait(&w->cond, &qp->mtx); } if (w->wrq == NULL) break; - UNLOCK(&qp->mtx); + Lck_Unlock(&qp->mtx); AN(w->wrq); AN(w->wrq->func); w->lastused = NAN; w->wrq->func(w, w->wrq->priv); w->wrq = NULL; - LOCK(&qp->mtx); + Lck_Lock(&qp->mtx); } qp->nthr--; - UNLOCK(&qp->mtx); + Lck_Unlock(&qp->mtx); VSL(SLT_WorkThread, 0, "%p end", w); if (w->vcl != NULL) @@ -285,7 +285,7 @@ if (w->srcaddr != NULL) free(w->srcaddr); if (w->nobjhead != NULL) { - MTX_DESTROY(&w->nobjhead->mtx); + Lck_Delete(&w->nobjhead->mtx); FREE_OBJ(w->nobjhead); } if (w->nobj!= NULL) @@ -318,13 +318,13 @@ qp = wq[onq]; nq = onq; - LOCK(&qp->mtx); + Lck_Lock(&qp->mtx); /* If there are idle threads, we tickle the first one into action */ w = VTAILQ_FIRST(&qp->idle); if (w != NULL) { VTAILQ_REMOVE(&qp->idle, w, list); - UNLOCK(&qp->mtx); + Lck_Unlock(&qp->mtx); w->wrq = wrq; AZ(pthread_cond_signal(&w->cond)); return (0); @@ -333,14 +333,14 @@ /* If we have too much in the overflow already, refuse. */ if (qp->nqueue > ovfl_max) { qp->ndrop++; - UNLOCK(&qp->mtx); + Lck_Unlock(&qp->mtx); return (-1); } VTAILQ_INSERT_TAIL(&qp->overflow, wrq, list); qp->noverflow++; qp->nqueue++; - UNLOCK(&qp->mtx); + Lck_Unlock(&qp->mtx); AZ(pthread_cond_signal(&herder_cond)); return (0); } @@ -412,7 +412,7 @@ wq[u] = calloc(sizeof *wq[u], 1); XXXAN(wq[u]); wq[u]->magic = WQ_MAGIC; - MTX_INIT(&wq[u]->mtx); + Lck_New(&wq[u]->mtx); VTAILQ_INIT(&wq[u]->overflow); VTAILQ_INIT(&wq[u]->idle); } @@ -429,7 +429,7 @@ { struct worker *w = NULL; - LOCK(&qp->mtx); + Lck_Lock(&qp->mtx); vs->n_wrk += qp->nthr; vs->n_wrk_queue += qp->nqueue; vs->n_wrk_drop += qp->ndrop; @@ -442,7 +442,7 @@ else w = NULL; } - UNLOCK(&qp->mtx); + Lck_Unlock(&qp->mtx); /* And give it a kiss on the cheek... */ if (w != NULL) { @@ -572,9 +572,9 @@ * We cannot avoid getting a mutex, so we have a * bogo mutex just for POSIX_STUPIDITY */ - AZ(pthread_mutex_lock(&herder_mtx)); - AZ(pthread_cond_wait(&herder_cond, &herder_mtx)); - AZ(pthread_mutex_unlock(&herder_mtx)); + Lck_Lock(&herder_mtx); + Lck_CondWait(&herder_cond, &herder_mtx); + Lck_Unlock(&herder_mtx); wrk_breed_flock(wq[u]); } } @@ -588,7 +588,7 @@ pthread_t tp; AZ(pthread_cond_init(&herder_cond, NULL)); - AZ(pthread_mutex_init(&herder_mtx, NULL)); + Lck_New(&herder_mtx); wrk_addpools(params->wthread_pools); AZ(pthread_create(&tp, NULL, wrk_herdtimer_thread, NULL)); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_session.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_session.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -78,7 +78,7 @@ }; static unsigned ses_qp; -static MTX ses_mem_mtx; +static struct lock ses_mem_mtx; /*--------------------------------------------------------------------*/ @@ -103,11 +103,11 @@ unsigned magic; #define SRCADDRHEAD_MAGIC 0x38231a8b VTAILQ_HEAD(,srcaddr) head; - MTX mtx; + struct lock mtx; } *srchash; static unsigned nsrchash; -static MTX stat_mtx; +static struct lock stat_mtx; /*-------------------------------------------------------------------- * Assign a srcaddr to this session. @@ -140,7 +140,7 @@ XXXAN(sp->wrk->srcaddr); } - LOCK(&ch->mtx); + Lck_Lock(&ch->mtx); c3 = NULL; VTAILQ_FOREACH_SAFE(c, &ch->head, list, c2) { if (c->hash == u && !strcmp(c->addr, sp->addr)) { @@ -155,7 +155,7 @@ VTAILQ_REMOVE(&ch->head, c3, list); VSL_stats->n_srcaddr--; } - UNLOCK(&ch->mtx); + Lck_Unlock(&ch->mtx); if (c3 != NULL) free(c3); return; @@ -183,7 +183,7 @@ VSL_stats->n_srcaddr_act++; VTAILQ_INSERT_TAIL(&ch->head, c3, list); sp->srcaddr = c3; - UNLOCK(&ch->mtx); + Lck_Unlock(&ch->mtx); } /*--------------------------------------------------------------------*/ @@ -198,13 +198,13 @@ CHECK_OBJ(sp->srcaddr, SRCADDR_MAGIC); ch = sp->srcaddr->sah; CHECK_OBJ(ch, SRCADDRHEAD_MAGIC); - LOCK(&ch->mtx); + Lck_Lock(&ch->mtx); assert(sp->srcaddr->nref > 0); sp->srcaddr->nref--; if (sp->srcaddr->nref == 0) VSL_stats->n_srcaddr_act--; sp->srcaddr = NULL; - UNLOCK(&ch->mtx); + Lck_Unlock(&ch->mtx); } /*--------------------------------------------------------------------*/ @@ -228,21 +228,21 @@ if (sp->srcaddr != NULL) { /* XXX: only report once per second ? */ CHECK_OBJ(sp->srcaddr, SRCADDR_MAGIC); - LOCK(&sp->srcaddr->sah->mtx); + Lck_Lock(&sp->srcaddr->sah->mtx); ses_sum_acct(&sp->srcaddr->acct, a); b = sp->srcaddr->acct; - UNLOCK(&sp->srcaddr->sah->mtx); + Lck_Unlock(&sp->srcaddr->sah->mtx); WSL(sp->wrk, SLT_StatAddr, 0, "%s 0 %.0f %ju %ju %ju %ju %ju %ju %ju", sp->srcaddr->addr, sp->t_end - b.first, b.sess, b.req, b.pipe, b.pass, b.fetch, b.hdrbytes, b.bodybytes); } - LOCK(&stat_mtx); + Lck_Lock(&stat_mtx); #define ACCT(foo) VSL_stats->s_##foo += a->foo; #include "acct_fields.h" #undef ACCT - UNLOCK(&stat_mtx); + Lck_Unlock(&stat_mtx); memset(a, 0, sizeof *a); } @@ -266,9 +266,9 @@ * If that queue is empty, flip queues holding the lock * and try the new unlocked queue. */ - LOCK(&ses_mem_mtx); + Lck_Lock(&ses_mem_mtx); ses_qp = 1 - ses_qp; - UNLOCK(&ses_mem_mtx); + Lck_Unlock(&ses_mem_mtx); sm = VTAILQ_FIRST(&ses_free_mem[ses_qp]); } if (sm != NULL) { @@ -343,9 +343,9 @@ VSL_stats->n_sess_mem--; free(sm); } else { - LOCK(&ses_mem_mtx); + Lck_Lock(&ses_mem_mtx); VTAILQ_INSERT_HEAD(&ses_free_mem[1 - ses_qp], sm, list); - UNLOCK(&ses_mem_mtx); + Lck_Unlock(&ses_mem_mtx); } } @@ -362,8 +362,8 @@ for (i = 0; i < nsrchash; i++) { srchash[i].magic = SRCADDRHEAD_MAGIC; VTAILQ_INIT(&srchash[i].head); - MTX_INIT(&srchash[i].mtx); + Lck_New(&srchash[i].mtx); } - MTX_INIT(&stat_mtx); - MTX_INIT(&ses_mem_mtx); + Lck_New(&stat_mtx); + Lck_New(&ses_mem_mtx); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -64,7 +64,7 @@ VTAILQ_HEAD_INITIALIZER(vcl_head); -static MTX vcl_mtx; +static struct lock vcl_mtx; static struct vcls *vcl_active; /* protected by vcl_mtx */ /*--------------------------------------------------------------------*/ @@ -83,13 +83,13 @@ VCL_Get(struct VCL_conf **vcc) { - LOCK(&vcl_mtx); + Lck_Lock(&vcl_mtx); AN(vcl_active); *vcc = vcl_active->conf; AN(*vcc); AZ((*vcc)->discard); (*vcc)->busy++; - UNLOCK(&vcl_mtx); + Lck_Unlock(&vcl_mtx); } void @@ -100,14 +100,14 @@ vc = *vcc; *vcc = NULL; - LOCK(&vcl_mtx); + Lck_Lock(&vcl_mtx); assert(vc->busy > 0); vc->busy--; /* * We do not garbage collect discarded VCL's here, that happens * in VCL_Poll() which is called from the CLI thread. */ - UNLOCK(&vcl_mtx); + Lck_Unlock(&vcl_mtx); } /*--------------------------------------------------------------------*/ @@ -167,10 +167,10 @@ } REPLACE(vcl->name, name); VTAILQ_INSERT_TAIL(&vcl_head, vcl, list); - LOCK(&vcl_mtx); + Lck_Lock(&vcl_mtx); if (vcl_active == NULL) vcl_active = vcl; - UNLOCK(&vcl_mtx); + Lck_Unlock(&vcl_mtx); cli_out(cli, "Loaded \"%s\" as \"%s\"", fn , name); vcl->conf->init_func(cli); VSL_stats->n_vcl++; @@ -264,9 +264,9 @@ cli_out(cli, "VCL '%s' unknown", av[2]); return; } - LOCK(&vcl_mtx); + Lck_Lock(&vcl_mtx); if (vcl == vcl_active) { - UNLOCK(&vcl_mtx); + Lck_Unlock(&vcl_mtx); cli_result(cli, CLIS_PARAM); cli_out(cli, "VCL %s is the active VCL", av[2]); return; @@ -274,7 +274,7 @@ VSL_stats->n_vcl_discard++; VSL_stats->n_vcl_avail--; vcl->conf->discard = 1; - UNLOCK(&vcl_mtx); + Lck_Unlock(&vcl_mtx); if (vcl->conf->busy == 0) VCL_Nuke(vcl); } @@ -292,9 +292,9 @@ cli_result(cli, CLIS_PARAM); return; } - LOCK(&vcl_mtx); + Lck_Lock(&vcl_mtx); vcl_active = vcl; - UNLOCK(&vcl_mtx); + Lck_Unlock(&vcl_mtx); } /*--------------------------------------------------------------------*/ @@ -350,5 +350,5 @@ { CLI_AddFuncs(MASTER_CLI, vcl_cmds); - MTX_INIT(&vcl_mtx); + Lck_New(&vcl_mtx); } Modified: branches/2.0/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -58,7 +58,7 @@ unsigned magic; #define HCL_HEAD_MAGIC 0x0f327016 VTAILQ_HEAD(, hcl_entry) head; - MTX mtx; + struct lock mtx; }; static unsigned hcl_nhash = 16383; @@ -110,7 +110,7 @@ for (u = 0; u < hcl_nhash; u++) { VTAILQ_INIT(&hcl_head[u].head); - MTX_INIT(&hcl_head[u].mtx); + Lck_New(&hcl_head[u].mtx); hcl_head[u].magic = HCL_HEAD_MAGIC; } } @@ -151,7 +151,7 @@ he2 = NULL; for (r = 0; r < 2; r++ ) { - LOCK(&hp->mtx); + Lck_Lock(&hp->mtx); VTAILQ_FOREACH(he, &hp->head, list) { CHECK_OBJ_NOTNULL(he, HCL_ENTRY_MAGIC); if (sp->lhashptr < he->oh->hashlen) @@ -169,7 +169,7 @@ break; he->refcnt++; roh = he->oh; - UNLOCK(&hp->mtx); + Lck_Unlock(&hp->mtx); /* * If we loose the race, we need to clean up * the work we did for our second attempt. @@ -183,7 +183,7 @@ return (roh); } if (noh == NULL) { - UNLOCK(&hp->mtx); + Lck_Unlock(&hp->mtx); return (NULL); } if (he2 != NULL) { @@ -193,10 +193,10 @@ VTAILQ_INSERT_TAIL(&hp->head, he2, list); he2->refcnt++; noh = he2->oh; - UNLOCK(&hp->mtx); + Lck_Unlock(&hp->mtx); return (noh); } - UNLOCK(&hp->mtx); + Lck_Unlock(&hp->mtx); he2 = calloc(sizeof *he2, 1); XXXAN(he2); @@ -234,12 +234,12 @@ assert(he->refcnt > 0); assert(he->hash < hcl_nhash); assert(hp == &hcl_head[he->hash]); - LOCK(&hp->mtx); + Lck_Lock(&hp->mtx); if (--he->refcnt == 0) VTAILQ_REMOVE(&hp->head, he, list); else he = NULL; - UNLOCK(&hp->mtx); + Lck_Unlock(&hp->mtx); if (he == NULL) return (1); free(he); Modified: branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -51,7 +51,7 @@ }; static VTAILQ_HEAD(, hsl_entry) hsl_head = VTAILQ_HEAD_INITIALIZER(hsl_head); -static MTX hsl_mutex; +static struct lock hsl_mtx; /*-------------------------------------------------------------------- * The ->init method is called during process start and allows @@ -62,7 +62,7 @@ hsl_start(void) { - MTX_INIT(&hsl_mutex); + Lck_New(&hsl_mtx); } /*-------------------------------------------------------------------- @@ -78,7 +78,7 @@ struct hsl_entry *he, *he2; int i; - LOCK(&hsl_mutex); + Lck_Lock(&hsl_mtx); VTAILQ_FOREACH(he, &hsl_head, list) { i = HSH_Compare(sp, he->obj); if (i < 0) @@ -87,7 +87,7 @@ break; he->refcnt++; nobj = he->obj; - UNLOCK(&hsl_mutex); + Lck_Unlock(&hsl_mtx); return (nobj); } if (nobj != NULL) { @@ -107,7 +107,7 @@ else VTAILQ_INSERT_TAIL(&hsl_head, he2, list); } - UNLOCK(&hsl_mutex); + Lck_Unlock(&hsl_mtx); return (nobj); } @@ -123,14 +123,14 @@ AN(obj->hashpriv); he = obj->hashpriv; - LOCK(&hsl_mutex); + Lck_Lock(&hsl_mtx); if (--he->refcnt == 0) { VTAILQ_REMOVE(&hsl_head, he, list); free(he); ret = 0; } else ret = 1; - UNLOCK(&hsl_mutex); + Lck_Unlock(&hsl_mtx); return (ret); } Modified: branches/2.0/varnish-cache/bin/varnishd/shmlog.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/shmlog.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/shmlog.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -64,7 +64,7 @@ struct varnish_stats *VSL_stats; static struct shmloghead *loghead; static unsigned char *logstart; -static MTX vsl_mtx; +static pthread_mutex_t vsl_mtx; static void @@ -287,7 +287,7 @@ assert(loghead->hdrsize == sizeof *loghead); /* XXX more check sanity of loghead ? */ logstart = (unsigned char *)loghead + loghead->start; - MTX_INIT(&vsl_mtx); + AZ(pthread_mutex_init(&vsl_mtx, NULL)); loghead->starttime = TIM_real(); loghead->panicstr[0] = '\0'; memset(VSL_stats, 0, sizeof *VSL_stats); Modified: branches/2.0/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_file.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/storage_file.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -115,7 +115,7 @@ struct smfhead order; struct smfhead free[NBUCKET]; struct smfhead used; - MTX mtx; + struct lock mtx; }; /*--------------------------------------------------------------------*/ @@ -609,7 +609,7 @@ /* XXX */ if (sum < MINPAGES * (off_t)getpagesize()) exit (2); - MTX_INIT(&sc->mtx); + Lck_New(&sc->mtx); VSL_stats->sm_bfree += sc->filesize; } @@ -625,18 +625,18 @@ assert(size > 0); size += (sc->pagesize - 1); size &= ~(sc->pagesize - 1); - LOCK(&sc->mtx); + Lck_Lock(&sc->mtx); VSL_stats->sm_nreq++; smf = alloc_smf(sc, size); if (smf == NULL) { - UNLOCK(&sc->mtx); + Lck_Unlock(&sc->mtx); return (NULL); } CHECK_OBJ_NOTNULL(smf, SMF_MAGIC); VSL_stats->sm_nobj++; VSL_stats->sm_balloc += smf->size; VSL_stats->sm_bfree -= smf->size; - UNLOCK(&sc->mtx); + Lck_Unlock(&sc->mtx); CHECK_OBJ_NOTNULL(&smf->s, STORAGE_MAGIC); /*lint !e774 */ XXXAN(smf); assert(smf->size == size); @@ -668,12 +668,12 @@ size += (sc->pagesize - 1); size &= ~(sc->pagesize - 1); if (smf->size > size) { - LOCK(&sc->mtx); + Lck_Lock(&sc->mtx); VSL_stats->sm_balloc -= (smf->size - size); VSL_stats->sm_bfree += (smf->size - size); trim_smf(smf, size); assert(smf->size == size); - UNLOCK(&sc->mtx); + Lck_Unlock(&sc->mtx); smf->s.space = size; } } @@ -690,12 +690,12 @@ CHECK_OBJ_NOTNULL(s, STORAGE_MAGIC); CAST_OBJ_NOTNULL(smf, s->priv, SMF_MAGIC); sc = smf->sc; - LOCK(&sc->mtx); + Lck_Lock(&sc->mtx); VSL_stats->sm_nobj--; VSL_stats->sm_balloc -= smf->size; VSL_stats->sm_bfree += smf->size; free_smf(smf); - UNLOCK(&sc->mtx); + Lck_Unlock(&sc->mtx); } /*--------------------------------------------------------------------*/ Modified: branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -44,7 +44,7 @@ #include "stevedore.h" static size_t sma_max = SIZE_MAX; -static MTX sma_mtx; +static struct lock sma_mtx; struct sma { struct storage s; @@ -56,7 +56,7 @@ { struct sma *sma; - LOCK(&sma_mtx); + Lck_Lock(&sma_mtx); VSL_stats->sma_nreq++; if (VSL_stats->sma_nbytes + size > sma_max) size = 0; @@ -65,7 +65,7 @@ VSL_stats->sma_nbytes += size; VSL_stats->sma_balloc += size; } - UNLOCK(&sma_mtx); + Lck_Unlock(&sma_mtx); if (size == 0) return (NULL); @@ -94,11 +94,11 @@ CHECK_OBJ_NOTNULL(s, STORAGE_MAGIC); sma = s->priv; assert(sma->sz == sma->s.space); - LOCK(&sma_mtx); + Lck_Lock(&sma_mtx); VSL_stats->sma_nobj--; VSL_stats->sma_nbytes -= sma->sz; VSL_stats->sma_bfree += sma->sz; - UNLOCK(&sma_mtx); + Lck_Unlock(&sma_mtx); free(sma->s.ptr); free(sma); } @@ -113,11 +113,11 @@ sma = s->priv; assert(sma->sz == sma->s.space); if ((p = realloc(sma->s.ptr, size)) != NULL) { - LOCK(&sma_mtx); + Lck_Lock(&sma_mtx); VSL_stats->sma_nbytes -= (sma->sz - size); VSL_stats->sma_bfree += sma->sz - size; sma->sz = size; - UNLOCK(&sma_mtx); + Lck_Unlock(&sma_mtx); sma->s.ptr = p; sma->s.space = size; } @@ -153,7 +153,7 @@ sma_open(const struct stevedore *st) { (void)st; - AZ(pthread_mutex_init(&sma_mtx, NULL)); + Lck_New(&sma_mtx); } struct stevedore sma_stevedore = { Modified: branches/2.0/varnish-cache/bin/varnishd/storage_synth.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_synth.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/storage_synth.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -43,18 +43,18 @@ #include "vsb.h" #include "stevedore.h" -static MTX sms_mtx; +static struct lock sms_mtx; static void sms_free(struct storage *sto) { CHECK_OBJ_NOTNULL(sto, STORAGE_MAGIC); - LOCK(&sms_mtx); + Lck_Lock(&sms_mtx); VSL_stats->sms_nobj--; VSL_stats->sms_nbytes -= sto->len; VSL_stats->sms_bfree += sto->len; - UNLOCK(&sms_mtx); + Lck_Unlock(&sms_mtx); vsb_delete(sto->priv); free(sto); } @@ -63,7 +63,7 @@ SMS_Init(void) { - AZ(pthread_mutex_init(&sms_mtx, NULL)); + Lck_New(&sms_mtx); } static struct stevedore sms_stevedore = { @@ -82,10 +82,10 @@ HSH_Freestore(obj); obj->len = 0; - LOCK(&sms_mtx); + Lck_Lock(&sms_mtx); VSL_stats->sms_nreq++; VSL_stats->sms_nobj++; - UNLOCK(&sms_mtx); + Lck_Unlock(&sms_mtx); sto = calloc(sizeof *sto, 1); XXXAN(sto); Modified: branches/2.0/varnish-cache/bin/varnishd/storage_umem.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_umem.c 2009-02-05 10:29:18 UTC (rev 3602) +++ branches/2.0/varnish-cache/bin/varnishd/storage_umem.c 2009-02-05 10:34:00 UTC (rev 3603) @@ -61,7 +61,7 @@ { struct smu *smu; - LOCK(&smu_mtx); + Lck_Lock(&smu_mtx); VSL_stats->sma_nreq++; if (VSL_stats->sma_nbytes + size > smu_max) size = 0; @@ -70,7 +70,7 @@ VSL_stats->sma_nbytes += size; VSL_stats->sma_balloc += size; } - UNLOCK(&smu_mtx); + Lck_Unlock(&smu_mtx); if (size == 0) return (NULL); @@ -99,11 +99,11 @@ CHECK_OBJ_NOTNULL(s, STORAGE_MAGIC); smu = s->priv; assert(smu->sz == smu->s.space); - LOCK(&smu_mtx); + Lck_Lock(&smu_mtx); VSL_stats->sma_nobj--; VSL_stats->sma_nbytes -= smu->sz; VSL_stats->sma_bfree += smu->sz; - UNLOCK(&smu_mtx); + Lck_Unlock(&smu_mtx); umem_free(smu->s.ptr, smu->s.space); umem_free(smu, sizeof *smu); } @@ -120,11 +120,11 @@ if ((p = umem_alloc(size, UMEM_DEFAULT)) != NULL) { memcpy(p, smu->s.ptr, size); umem_free(smu->s.ptr, smu->s.space); - LOCK(&smu_mtx); + Lck_Lock(&smu_mtx); VSL_stats->sma_nbytes -= (smu->sz - size); VSL_stats->sma_bfree += smu->sz - size; smu->sz = size; - UNLOCK(&smu_mtx); + Lck_Unlock(&smu_mtx); smu->s.ptr = p; smu->s.space = size; } From tfheen at projects.linpro.no Thu Feb 5 10:37:46 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 11:37:46 +0100 (CET) Subject: r3604 - branches/2.0/varnish-cache/lib/libvarnish Message-ID: <20090205103746.E96EF28370@projects.linpro.no> Author: tfheen Date: 2009-02-05 11:37:46 +0100 (Thu, 05 Feb 2009) New Revision: 3604 Modified: branches/2.0/varnish-cache/lib/libvarnish/vlu.c Log: Merge r3383: React to both NL and CR in VLU Modified: branches/2.0/varnish-cache/lib/libvarnish/vlu.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vlu.c 2009-02-05 10:34:00 UTC (rev 3603) +++ branches/2.0/varnish-cache/lib/libvarnish/vlu.c 2009-02-05 10:37:46 UTC (rev 3604) @@ -87,8 +87,11 @@ l->buf[l->bufp] = '\0'; for (p = l->buf; *p != '\0'; p = q) { - q = strchr(p, '\n'); - if (q == NULL) + /* Find first CR or NL */ + for (q = p; *q != '\0'; q++) + if (*q == '\n' || *q == '\r') + break; + if (*q == '\0') break; *q++ = '\0'; i = l->func(l->priv, p); From tfheen at projects.linpro.no Thu Feb 5 10:59:02 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 11:59:02 +0100 (CET) Subject: r3605 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205105902.045271F74B8@projects.linpro.no> Author: tfheen Date: 2009-02-05 11:59:01 +0100 (Thu, 05 Feb 2009) New Revision: 3605 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_lck.c Log: Merge r3384+r3385: Have I mentioned that I think POSIX is a bunch of amateurs ? There is no NULL value for pthread_t and you have to call a function to compare them. Remember to set lock "held" in CondWait Modified: branches/2.0/varnish-cache/bin/varnishd/cache_lck.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_lck.c 2009-02-05 10:37:46 UTC (rev 3604) +++ branches/2.0/varnish-cache/bin/varnishd/cache_lck.c 2009-02-05 10:59:01 UTC (rev 3605) @@ -52,6 +52,7 @@ unsigned magic; #define ILCK_MAGIC 0x7b86c8a5 pthread_mutex_t mtx; + int held; pthread_t owner; VTAILQ_ENTRY(ilck) list; const char *w; @@ -71,8 +72,9 @@ CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); if (!(params->diag_bitmap & 0x18)) { AZ(pthread_mutex_lock(&ilck->mtx)); - AZ(ilck->owner); + AZ(ilck->held); ilck->owner = pthread_self(); + ilck->held = 1; return; } r = pthread_mutex_trylock(&ilck->mtx); @@ -83,8 +85,9 @@ } else if (params->diag_bitmap & 0x8) { VSL(SLT_Debug, 0, "MTX_LOCK(%s,%s,%d,%s)", p, f, l, ilck->w); } - AZ(ilck->owner); + AZ(ilck->held); ilck->owner = pthread_self(); + ilck->held = 1; } void @@ -93,8 +96,9 @@ struct ilck *ilck; CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); - assert(ilck->owner == pthread_self()); - ilck->owner = NULL; + assert(pthread_equal(ilck->owner, pthread_self())); + AN(ilck->held); + ilck->held = 0; AZ(pthread_mutex_unlock(&ilck->mtx)); if (params->diag_bitmap & 0x8) VSL(SLT_Debug, 0, "MTX_UNLOCK(%s,%s,%d,%s)", p, f, l, ilck->w); @@ -113,7 +117,8 @@ VSL(SLT_Debug, 0, "MTX_TRYLOCK(%s,%s,%d,%s) = %d", p, f, l, ilck->w); if (r == 0) { - AZ(ilck->owner); + AZ(ilck->held); + ilck->held = 1; ilck->owner = pthread_self(); } return (r); @@ -126,9 +131,11 @@ CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); if (held) - assert(ilck->owner == pthread_self()); + assert(ilck->held && + pthread_equal(ilck->owner, pthread_self())); else - assert(ilck->owner != pthread_self()); + assert(!ilck->held || + !pthread_equal(ilck->owner, pthread_self())); } void @@ -137,10 +144,12 @@ struct ilck *ilck; CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); - assert(ilck->owner == pthread_self()); - ilck->owner = NULL; + AN(ilck->held); + assert(pthread_equal(ilck->owner, pthread_self())); + ilck->held = 0; AZ(pthread_cond_wait(cond, &ilck->mtx)); - AZ(ilck->owner); + AZ(ilck->held); + ilck->held = 1; ilck->owner = pthread_self(); } From tfheen at projects.linpro.no Thu Feb 5 11:02:45 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:02:45 +0100 (CET) Subject: r3606 - branches/2.0/varnish-cache/lib/libvarnish Message-ID: <20090205110245.18AAB28370@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:02:44 +0100 (Thu, 05 Feb 2009) New Revision: 3606 Modified: branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c Log: Merge r3390: Rework the binary heap we use for expiry processing Rework the binary heap, we use for expiry processing, to deal more gracefully with large number of objects. Previously we kept all objects in a single array which resultined in increasingly infrequent but increasingly demanding calls to calloc(3) with the consequent massive memory copies. We also did not release memory again if unused. Now we stripe the array into rows of 64k objects each. This number is a compromise between space wastage, max 1MB on a 64bit machine, and the desire to not add and delete rows all the time. With 64k objects in a row, even on a very busy server would only add a new row every 5...10 seconds during ramp up. Delete unused rows, but keep a hysteresis of an entire empty row to avoid silly add-delete-add-delete-add-delete behaviour at row boundaries. Streamline some of the functions a bit. Fixes #210 Modified: branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c 2009-02-05 10:59:01 UTC (rev 3605) +++ branches/2.0/varnish-cache/lib/libvarnish/binary_heap.c 2009-02-05 11:02:44 UTC (rev 3606) @@ -32,8 +32,6 @@ * * We use a malloc(3)/realloc(3) array to store the pointers using the * classical FORTRAN strategy. - * - * XXX: the array is not scaled back when items are deleted. */ #include "config.h" @@ -44,38 +42,71 @@ #include "binary_heap.h" #include "libvarnish.h" +/* Paramters ---------------------------------------------------------*/ + +/* + * The number of elements in a row has to be a compromise between + * wasted space and number of memory allocations. + * With 64k objects per row, there will be at least 5...10 seconds + * between row additions on a very busy server. + * At the same time, the worst case amount of wasted memory is kept + * at a reasonable 1 MB -- two rows on 64bit system. + * Finally, but without practical significance: 16 bits should be + * easier for the compiler to optimize. + */ +#define ROW_SHIFT 16 + /* Private definitions -----------------------------------------------*/ -#define MIN_LENGTH 16 - #define ROOT_IDX 1 +#define ROW_WIDTH (1 << ROW_SHIFT) + +/*lint -emacro(572, ROW) shift 0 >> by 16 */ +/*lint -emacro(835, ROW) 0 left of >> */ +/*lint -emacro(778, ROW) const >> evaluates to zero */ +#define ROW(b, n) ((b)->array[(n) >> ROW_SHIFT]) + +/*lint -emacro(835, A) 0 left of & */ +#define A(b, n) ROW(b, n)[(n) & (ROW_WIDTH - 1)] + struct binheap { unsigned magic; #define BINHEAP_MAGIC 0xf581581aU /* from /dev/random */ void *priv; binheap_cmp_t *cmp; binheap_update_t *update; - void **array; + void ***array; + unsigned rows; unsigned length; unsigned next; - unsigned granularity; }; #define PARENT(u) ((u) / 2) +/*lint -emacro(835, CHILD) 0 right of + */ #define CHILD(u,n) ((u) * 2 + (n)) /* Implementation ----------------------------------------------------*/ static void -binheap_update(const struct binheap *bh, unsigned u) +binheap_addrow(struct binheap *bh) { - assert(bh->magic == BINHEAP_MAGIC); - assert(u < bh->next); - assert(bh->array[u] != NULL); - if (bh->update == NULL) - return; - bh->update(bh->priv, bh->array[u], u); + unsigned u; + + /* First make sure we have space for another row */ + if (&ROW(bh, bh->length) >= bh->array + bh->rows) { + u = bh->rows * 2; + bh->array = realloc(bh->array, sizeof(*bh->array) * u); + assert(bh->array != NULL); + + /* NULL out new pointers */ + while (bh->rows < u) + bh->array[bh->rows++] = NULL; + } + assert(ROW(bh, bh->length) == NULL); + ROW(bh, bh->length) = malloc(sizeof(**bh->array) * ROW_WIDTH); + assert(ROW(bh, bh->length)); + bh->length += ROW_WIDTH; } struct binheap * @@ -90,15 +121,27 @@ bh->cmp = cmp_f; bh->update = update_f; bh->next = ROOT_IDX; - bh->length = MIN_LENGTH; - bh->array = calloc(sizeof *bh->array, bh->length); + bh->rows = 16; /* A tiny-ish number */ + bh->array = calloc(sizeof *bh->array, bh->rows); assert(bh->array != NULL); - bh->granularity = getpagesize() / sizeof *bh->array; + binheap_addrow(bh); + A(bh, ROOT_IDX) = NULL; bh->magic = BINHEAP_MAGIC; return (bh); } static void +binheap_update(const struct binheap *bh, unsigned u) +{ + assert(bh->magic == BINHEAP_MAGIC); + assert(u < bh->next); + assert(A(bh, u) != NULL); + if (bh->update == NULL) + return; + bh->update(bh->priv, A(bh, u), u); +} + +static void binhead_swap(const struct binheap *bh, unsigned u, unsigned v) { void *p; @@ -106,9 +149,9 @@ assert(bh->magic == BINHEAP_MAGIC); assert(u < bh->next); assert(v < bh->next); - p = bh->array[u]; - bh->array[u] = bh->array[v]; - bh->array[v] = p; + p = A(bh, u); + A(bh, u) = A(bh, v); + A(bh, v) = p; binheap_update(bh, u); binheap_update(bh, v); } @@ -121,11 +164,10 @@ assert(bh->magic == BINHEAP_MAGIC); while (u > ROOT_IDX) { v = PARENT(u); - if (bh->cmp(bh->priv, bh->array[u], bh->array[v])) { - binhead_swap(bh, u, v); - u = v; - } else + if (!bh->cmp(bh->priv, A(bh, u), A(bh, v))) break; + binhead_swap(bh, u, v); + u = v; } return (u); } @@ -138,28 +180,15 @@ assert(bh->magic == BINHEAP_MAGIC); while (1) { v1 = CHILD(u, 0); - v2 = CHILD(u, 1); if (v1 >= bh->next) return; - if (v2 >= bh->next) { - if (!bh->cmp(bh->priv, bh->array[u], bh->array[v1])) - binhead_swap(bh, u, v1); + v2 = CHILD(u, 1); + if (v2 < bh->next && bh->cmp(bh->priv, A(bh, v2), A(bh, v1))) + v1 = v2; + if (bh->cmp(bh->priv, A(bh, u), A(bh, v1))) return; - } - if (bh->cmp(bh->priv, bh->array[v1], bh->array[v2])) { - if (!bh->cmp(bh->priv, bh->array[u], bh->array[v1])) { - binhead_swap(bh, u, v1); - u = v1; - continue; - } - } else { - if (!bh->cmp(bh->priv, bh->array[u], bh->array[v2])) { - binhead_swap(bh, u, v2); - u = v2; - continue; - } - } - return; + binhead_swap(bh, u, v1); + u = v1; } } @@ -171,18 +200,10 @@ assert(bh != NULL); assert(bh->magic == BINHEAP_MAGIC); assert(bh->length >= bh->next); - if (bh->length == bh->next) { - if (bh->length >= bh->granularity * 32) - bh->length += bh->granularity * 32; - else if (bh->length > bh->granularity) - bh->length += bh->granularity; - else - bh->length += bh->length; - bh->array = realloc(bh->array, bh->length * sizeof *bh->array); - assert(bh->array != NULL); - } + if (bh->length == bh->next) + binheap_addrow(bh); u = bh->next++; - bh->array[u] = p; + A(bh, u) = p; binheap_update(bh, u); (void)binheap_trickleup(bh, u); } @@ -193,11 +214,33 @@ assert(bh != NULL); assert(bh->magic == BINHEAP_MAGIC); - if (bh->next == ROOT_IDX) - return (NULL); - return (bh->array[ROOT_IDX]); + return (A(bh, ROOT_IDX)); } +/* + * It may seem counter-intuitive that we delete by replacement with + * the tail object. "That's almost certain to not belong there, in + * particular when we delete the root ?" is the typical reaction. + * + * If we tried to trickle up into the empty position, we would, + * eventually, end up with a hole in the bottom row, at which point + * we would move the tail object there. + * But there is no guarantee that the tail object would not need to + * trickle up from that position, in fact, it might be the new root + * of this half of the subtree. + * The total number of operations is guaranteed to be at least + * N{height} downward selections, because we have to get the hole + * all the way down, but in addition to that, we may get up to + * N{height}-1 upward trickles. + * + * When we fill the hole with the tail object, the worst case is + * that it trickles all the way down to become the tail object + * again. + * In other words worst case is N{height} downward trickles. + * But there is a pretty decent chance that it does not make + * it all the way down. + */ + void binheap_delete(struct binheap *bh, unsigned idx) { @@ -207,18 +250,28 @@ assert(bh->next > ROOT_IDX); assert(idx < bh->next); assert(idx > 0); - assert(bh->array[idx] != NULL); - bh->update(bh->priv, bh->array[idx], 0); + assert(A(bh, idx) != NULL); + bh->update(bh->priv, A(bh, idx), 0); if (idx == --bh->next) { - bh->array[bh->next] = NULL; + A(bh, bh->next) = NULL; return; } - bh->array[idx] = bh->array[bh->next]; - bh->array[bh->next] = NULL; + A(bh, idx) = A(bh, bh->next); + A(bh, bh->next) = NULL; binheap_update(bh, idx); idx = binheap_trickleup(bh, idx); binheap_trickledown(bh, idx); - /* XXX: free part of array ? */ + + /* + * We keep a hysteresis of one full row before we start to + * return space to the OS to avoid silly behaviour around + * row boundaries. + */ + if (bh->next + 2 * ROW_WIDTH <= bh->length) { + free(ROW(bh, bh->length - 1)); + ROW(bh, bh->length - 1) = NULL; + bh->length -= ROW_WIDTH; + } } @@ -226,7 +279,10 @@ /* Test driver -------------------------------------------------------*/ #include -#if 0 +#if 1 + +#define N 23 + static int cmp(void *priv, void *a, void *b) { @@ -247,14 +303,14 @@ unsigned u, *up; printf("dump\n"); - f = popen("dot -Tps >> /tmp/_.ps", "w"); + f = popen("dot -Tps >> /tmp/_.ps 2>/dev/null", "w"); assert(f != NULL); fprintf(f, "digraph binheap {\n"); fprintf(f, "size=\"7,10\"\n"); fprintf(f, "ptr [label=\"%s\"]\n", what); fprintf(f, "ptr -> node_%u\n", ptr); for (u = 1; u < bh->next; u++) { - up = bh->array[u]; + up = A(bh, u); fprintf(f, "node_%u [label=\"%u\"];\n", u, *up); if (u > 0) fprintf(f, "node_%u -> node_%u\n", PARENT(u), u); @@ -263,7 +319,6 @@ pclose(f); } -#define N 31 int main(int argc, char **argv) { @@ -286,7 +341,7 @@ break; assert(*up >= lu); lu = *up; - u = random() % bh->next; + u = (random() % (bh->next - 1)) + 1; binheap_delete(bh, u); if (1) dump(bh, "Delete", u); @@ -301,7 +356,7 @@ }; #define M 1311191 -#define N 131 +#define N 1311 struct foo ff[N]; @@ -332,8 +387,8 @@ for (u = 2; u < bh->next; u++) { v = PARENT(u); - fa = bh->array[u]; - fb = bh->array[v]; + fa = A(bh, u); + fb = A(bh, v); assert(fa->key > fb->key); continue; printf("[%2u/%2u] %10u > [%2u/%2u] %10u %s\n", @@ -363,11 +418,17 @@ for (u = 0; u < M; u++) { v = random() % N; if (ff[v].idx > 0) { - printf("Delete [%u] %'u\n", v, ff[v].key); + if (0) + printf("Delete [%u] %'u\n", v, ff[v].key); + else + printf("-%u", v); binheap_delete(bh, ff[v].idx); } else { ff[v].key = random(); - printf("Insert [%u] %'u\n", v, ff[v].key); + if (0) + printf("Insert [%u] %'u\n", v, ff[v].key); + else + printf("+%u", v); binheap_insert(bh, &ff[v]); } chk(bh); From tfheen at projects.linpro.no Thu Feb 5 11:07:27 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:07:27 +0100 (CET) Subject: r3607 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205110727.4ED0028370@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:07:27 +0100 (Thu, 05 Feb 2009) New Revision: 3607 Removed: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_acl.c Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c Log: Merge r3391: Merge cache_vrt_acl.c into cache_vrt.c Merge cache_vrt_acl.c into cache_vrt.c, one one-line function is silly in a source-file. (All the work is done by vcc generated code now) Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-05 11:02:44 UTC (rev 3606) +++ branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-05 11:07:27 UTC (rev 3607) @@ -36,7 +36,6 @@ cache_vary.c \ cache_vcl.c \ cache_vrt.c \ - cache_vrt_acl.c \ cache_vrt_esi.c \ cache_vrt_re.c \ cache_ws.c \ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-05 11:02:44 UTC (rev 3606) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-05 11:07:27 UTC (rev 3607) @@ -80,6 +80,14 @@ /*--------------------------------------------------------------------*/ +void +VRT_acl_log(const struct sess *sp, const char *msg) +{ + WSL(sp->wrk, SLT_VCL_acl, sp->fd, msg); +} + +/*--------------------------------------------------------------------*/ + static struct http * vrt_selecthttp(const struct sess *sp, enum gethdr_e where) { Deleted: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_acl.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_acl.c 2009-02-05 11:02:44 UTC (rev 3606) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_acl.c 2009-02-05 11:07:27 UTC (rev 3607) @@ -1,45 +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$ - * - * Runtime support for compiled VCL programs, ACLs - * - */ - -#include "config.h" - -#include "shmlog.h" -#include "vrt.h" -#include "cache.h" - -void -VRT_acl_log(const struct sess *sp, const char *msg) -{ - WSL(sp->wrk, SLT_VCL_acl, sp->fd, msg); -} From tfheen at projects.linpro.no Thu Feb 5 11:10:59 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:10:59 +0100 (CET) Subject: r3608 - branches/2.0/varnish-cache/lib/libvcl Message-ID: <20090205111059.D0F6897BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:10:59 +0100 (Thu, 05 Feb 2009) New Revision: 3608 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_string.c Log: Merge r3392: Inline VRT_re_test() Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_string.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_string.c 2009-02-05 11:07:27 UTC (rev 3607) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_string.c 2009-02-05 11:10:59 UTC (rev 3608) @@ -33,6 +33,7 @@ #include #include +#include #include "vsb.h" @@ -47,13 +48,22 @@ char * vcc_regexp(struct tokenlist *tl, int sub) { - char buf[32], *p; + char buf[BUFSIZ], *p; + regex_t t; + int i; Expect(tl, CSTR); - if (VRT_re_test(tl->sb, tl->t->dec, sub)) { + memset(&t, 0, sizeof t); + i = regcomp(&t, tl->t->dec, REG_EXTENDED | (sub ? 0 : REG_NOSUB)); + if (i != 0) { + (void)regerror(i, &t, buf, sizeof buf); + vsb_printf(tl->sb, + "Regexp compilation error:\n\n%s\n\n", buf); vcc_ErrWhere(tl, tl->t); + regfree(&t); return (NULL); } + regfree(&t); sprintf(buf, "VGC_re_%u", tl->recnt++); p = TlAlloc(tl, strlen(buf) + 1); strcpy(p, buf); From tfheen at projects.linpro.no Thu Feb 5 11:14:28 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:14:28 +0100 (CET) Subject: r3609 - in branches/2.0/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20090205111428.81CB097BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:14:28 +0100 (Thu, 05 Feb 2009) New Revision: 3609 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c branches/2.0/varnish-cache/include/vrt.h branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Merge r3393: Retire VRT_re_test() Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c 2009-02-05 11:10:59 UTC (rev 3608) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c 2009-02-05 11:14:28 UTC (rev 3609) @@ -84,25 +84,6 @@ return (0); } -int -VRT_re_test(struct vsb *sb, const char *re, int sub) -{ - int i; - regex_t t; - char buf[BUFSIZ]; - - memset(&t, 0, sizeof t); - i = regcomp(&t, re, REG_EXTENDED | (sub ? 0 : REG_NOSUB)); - if (i == 0) { - regfree(&t); - return (0); - } - (void)regerror(i, &t, buf, sizeof buf); - vsb_printf(sb, "Regexp compilation error:\n\n%s\n\n", buf); - regfree(&t); - return (1); -} - const char * VRT_regsub(const struct sess *sp, int all, const char *str, void *re, const char *sub) Modified: branches/2.0/varnish-cache/include/vrt.h =================================================================== --- branches/2.0/varnish-cache/include/vrt.h 2009-02-05 11:10:59 UTC (rev 3608) +++ branches/2.0/varnish-cache/include/vrt.h 2009-02-05 11:14:28 UTC (rev 3609) @@ -136,7 +136,6 @@ void VRT_re_init(void **, const char *, int sub); void VRT_re_fini(void *); int VRT_re_match(const char *, void *re); -int VRT_re_test(struct vsb *, const char *, int sub); const char *VRT_regsub(const struct sess *sp, int all, const char *, void *, const char *); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 11:10:59 UTC (rev 3608) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 11:14:28 UTC (rev 3609) @@ -271,7 +271,6 @@ vsb_cat(sb, "g);\n\n/* Regexp related */\nvoid VRT_re_init(void **,"); vsb_cat(sb, " const char *, int sub);\nvoid VRT_re_fini(void *);\n"); vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n"); - vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); vsb_cat(sb, "const char *VRT_regsub(const struct sess *sp, int all,"); vsb_cat(sb, " const char *,\n void *, const char *);\n"); vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);"); From tfheen at projects.linpro.no Thu Feb 5 11:17:44 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:17:44 +0100 (CET) Subject: r3610 - in branches/2.0/varnish-cache/lib: libvarnish libvcl Message-ID: <20090205111744.793241F74C8@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:17:44 +0100 (Thu, 05 Feb 2009) New Revision: 3610 Modified: branches/2.0/varnish-cache/lib/libvarnish/flint.lnt branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Merge r3395: silence config.h noise Modified: branches/2.0/varnish-cache/lib/libvarnish/flint.lnt =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/flint.lnt 2009-02-05 11:14:28 UTC (rev 3609) +++ branches/2.0/varnish-cache/lib/libvarnish/flint.lnt 2009-02-05 11:17:44 UTC (rev 3610) @@ -11,6 +11,8 @@ -header(../../config.h) +-efile(451, "../../config.h") + // Fix strchr() semtics, it can only return NULL if arg2 != 0 -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 11:14:28 UTC (rev 3609) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 11:17:44 UTC (rev 3610) @@ -223,8 +223,8 @@ vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI"); vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT"); vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"); - vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3580 2009-02-05 08:"); - vsb_cat(sb, "45:25Z tfheen $\n *\n * Runtime support for compiled V"); + vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3609 2009-02-05 11:"); + vsb_cat(sb, "14:28Z tfheen $\n *\n * Runtime support for compiled V"); vsb_cat(sb, "CL programs.\n *\n * XXX: When this file is changed, l"); vsb_cat(sb, "ib/libvcl/vcc_gen_fixed_token.tcl\n"); vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n"); From tfheen at projects.linpro.no Thu Feb 5 11:23:44 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:23:44 +0100 (CET) Subject: r3611 - branches/2.0/varnish-cache/lib/libjemalloc Message-ID: <20090205112344.F0ACC97BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:23:44 +0100 (Thu, 05 Feb 2009) New Revision: 3611 Modified: branches/2.0/varnish-cache/lib/libjemalloc/jemalloc_linux.c Log: Merge r3399+3430: Fixed compiling on Linux with -Werror set. Fixed compiling on Linux with -Werror set. Added mising prototypes, removed an unused function and added the ATTRIBUTE_UNUSED to the attribute list for the rb_wrap() macro which generated unused functions. r3430 | tfheen | 2008-11-24 20:08:36 +0100 (ma., 24 nov. 2008) | 4 lines Include relevant bit of ansidecl.h directly Avoids build-dependency on binutils-dev Modified: branches/2.0/varnish-cache/lib/libjemalloc/jemalloc_linux.c =================================================================== --- branches/2.0/varnish-cache/lib/libjemalloc/jemalloc_linux.c 2009-02-05 11:17:44 UTC (rev 3610) +++ branches/2.0/varnish-cache/lib/libjemalloc/jemalloc_linux.c 2009-02-05 11:23:44 UTC (rev 3611) @@ -200,6 +200,17 @@ #include "rb.h" +/* Prevent -Werror to complain about unused parameters when compiling + with non-ancient GCC. Added directly here instead of grabbed from + ansidecl.h to save a build dependency on binutils-dev */ +#if __GNUC__ >= 3 +#ifndef ATTRIBUTE_UNUSED +#define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) +#endif /* ATTRIBUTE_UNUSED */ +#else +#define ATTRIBUTE_UNUSED +#endif + #ifdef MALLOC_DEBUG /* Disable inlining to make debugging easier. */ # define inline @@ -1113,7 +1124,6 @@ static bool base_pages_alloc_mmap(size_t minsize); static bool base_pages_alloc(size_t minsize); static void *base_alloc(size_t size); -static void *base_calloc(size_t number, size_t size); static extent_node_t *base_node_alloc(void); static void base_node_dealloc(extent_node_t *node); #ifdef MALLOC_STATS @@ -1200,6 +1210,14 @@ */ /******************************************************************************/ +/* + * Functions missing prototypes which caused -Werror to fail. + * Not sure if it has any side effects. + * */ +size_t malloc_usable_size(const void *ptr); +void _malloc_thread_cleanup(void); + + static void wrtmessage(const char *p1, const char *p2, const char *p3, const char *p4) { @@ -1625,17 +1643,6 @@ return (ret); } -static void * -base_calloc(size_t number, size_t size) -{ - void *ret; - - ret = base_alloc(number * size); - memset(ret, 0, number * size); - - return (ret); -} - static extent_node_t * base_node_alloc(void) { @@ -1779,7 +1786,7 @@ } /* Wrap red-black tree macros in functions. */ -rb_wrap(static, extent_tree_szad_, extent_tree_t, extent_node_t, +rb_wrap(static ATTRIBUTE_UNUSED, extent_tree_szad_, extent_tree_t, extent_node_t, link_szad, extent_szad_comp) #endif @@ -1793,7 +1800,7 @@ } /* Wrap red-black tree macros in functions. */ -rb_wrap(static, extent_tree_ad_, extent_tree_t, extent_node_t, link_ad, +rb_wrap(static ATTRIBUTE_UNUSED, extent_tree_ad_, extent_tree_t, extent_node_t, link_ad, extent_ad_comp) /* @@ -2347,7 +2354,7 @@ } /* Wrap red-black tree macros in functions. */ -rb_wrap(static, arena_chunk_tree_dirty_, arena_chunk_tree_t, +rb_wrap(static ATTRIBUTE_UNUSED, arena_chunk_tree_dirty_, arena_chunk_tree_t, arena_chunk_t, link_dirty, arena_chunk_comp) static inline int @@ -2363,7 +2370,7 @@ } /* Wrap red-black tree macros in functions. */ -rb_wrap(static, arena_run_tree_, arena_run_tree_t, arena_chunk_map_t, +rb_wrap(static ATTRIBUTE_UNUSED, arena_run_tree_, arena_run_tree_t, arena_chunk_map_t, link, arena_run_comp) static inline int @@ -2395,7 +2402,7 @@ } /* Wrap red-black tree macros in functions. */ -rb_wrap(static, arena_avail_tree_, arena_avail_tree_t, +rb_wrap(static ATTRIBUTE_UNUSED, arena_avail_tree_, arena_avail_tree_t, arena_chunk_map_t, link, arena_avail_comp) static inline void * From tfheen at projects.linpro.no Thu Feb 5 11:27:00 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:27:00 +0100 (CET) Subject: r3612 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205112700.B74C897BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:27:00 +0100 (Thu, 05 Feb 2009) New Revision: 3612 Modified: branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c Log: Merge r3400: Rename variables to reflect that they are object heads, not objects. Modified: branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 11:23:44 UTC (rev 3611) +++ branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 11:27:00 UTC (rev 3612) @@ -46,7 +46,7 @@ struct hsl_entry { VTAILQ_ENTRY(hsl_entry) list; - struct objhead *obj; + struct objhead *oh; unsigned refcnt; }; @@ -73,34 +73,34 @@ */ static struct objhead * -hsl_lookup(const struct sess *sp, struct objhead *nobj) +hsl_lookup(const struct sess *sp, struct objhead *noh) { struct hsl_entry *he, *he2; int i; Lck_Lock(&hsl_mtx); VTAILQ_FOREACH(he, &hsl_head, list) { - i = HSH_Compare(sp, he->obj); + i = HSH_Compare(sp, he->oh); if (i < 0) continue; if (i > 0) break; he->refcnt++; - nobj = he->obj; + noh = he->oh; Lck_Unlock(&hsl_mtx); - return (nobj); + return (noh); } - if (nobj != NULL) { + if (noh != NULL) { he2 = calloc(sizeof *he2, 1); XXXAN(he2); - he2->obj = nobj; + he2->oh = noh; he2->refcnt = 1; - nobj->hashpriv = he2; - nobj->hash = malloc(sp->lhashptr); - XXXAN(nobj->hash); - nobj->hashlen = sp->lhashptr; - HSH_Copy(sp, nobj); + noh->hashpriv = he2; + noh->hash = malloc(sp->lhashptr); + XXXAN(noh->hash); + noh->hashlen = sp->lhashptr; + HSH_Copy(sp, noh); if (he != NULL) VTAILQ_INSERT_BEFORE(he, he2, list); @@ -108,7 +108,7 @@ VTAILQ_INSERT_TAIL(&hsl_head, he2, list); } Lck_Unlock(&hsl_mtx); - return (nobj); + return (noh); } /*-------------------------------------------------------------------- From tfheen at projects.linpro.no Thu Feb 5 11:31:24 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:31:24 +0100 (CET) Subject: r3613 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205113124.B062097BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:31:24 +0100 (Thu, 05 Feb 2009) New Revision: 3613 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c Log: Merge r3403: Rename some objhead pointers from obj to oh for consistency. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-05 11:27:00 UTC (rev 3612) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-05 11:31:24 UTC (rev 3613) @@ -137,7 +137,7 @@ } int -HSH_Compare(const struct sess *sp, const struct objhead *obj) +HSH_Compare(const struct sess *sp, const struct objhead *oh) { int i; unsigned u, v; @@ -145,11 +145,11 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); - CHECK_OBJ_NOTNULL(obj, OBJHEAD_MAGIC); - i = sp->lhashptr - obj->hashlen; + CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); + i = sp->lhashptr - oh->hashlen; if (i) return (i); - b = obj->hash; + b = oh->hash; for (u = 0; u < sp->ihashptr; u += 2) { v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); i = memcmp(sp->hashptr[u], b, v); @@ -162,18 +162,21 @@ } assert(*b == '\0'); b++; - assert(b == obj->hash + obj->hashlen); + assert(b == oh->hash + oh->hashlen); return (0); } void -HSH_Copy(const struct sess *sp, const struct objhead *obj) +HSH_Copy(const struct sess *sp, const struct objhead *oh) { unsigned u, v; char *b; - assert(obj->hashlen >= sp->lhashptr); - b = obj->hash; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); + + assert(oh->hashlen >= sp->lhashptr); + b = oh->hash; for (u = 0; u < sp->ihashptr; u += 2) { v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); memcpy(b, sp->hashptr[u], v); @@ -181,7 +184,7 @@ *b++ = '#'; } *b++ = '\0'; - assert(b <= obj->hash + obj->hashlen); + assert(b <= oh->hash + oh->hashlen); } struct object * Modified: branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 11:27:00 UTC (rev 3612) +++ branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 11:31:24 UTC (rev 3613) @@ -116,13 +116,13 @@ */ static int -hsl_deref(const struct objhead *obj) +hsl_deref(const struct objhead *oh) { struct hsl_entry *he; int ret; - AN(obj->hashpriv); - he = obj->hashpriv; + AN(oh->hashpriv); + he = oh->hashpriv; Lck_Lock(&hsl_mtx); if (--he->refcnt == 0) { VTAILQ_REMOVE(&hsl_head, he, list); From tfheen at projects.linpro.no Thu Feb 5 11:35:20 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:35:20 +0100 (CET) Subject: r3614 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205113520.9D08497BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:35:20 +0100 (Thu, 05 Feb 2009) New Revision: 3614 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/hash_classic.c branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c Log: Merge r3404: Move the hash'ers refcount up to objhead, it is generic. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 11:31:24 UTC (rev 3613) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 11:35:20 UTC (rev 3614) @@ -297,6 +297,7 @@ void *hashpriv; struct lock mtx; + unsigned refcnt; VTAILQ_HEAD(,object) objects; char *hash; unsigned hashlen; Modified: branches/2.0/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-05 11:31:24 UTC (rev 3613) +++ branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-05 11:35:20 UTC (rev 3614) @@ -49,7 +49,6 @@ VTAILQ_ENTRY(hcl_entry) list; struct hcl_hd *head; struct objhead *oh; - unsigned refcnt; unsigned digest; unsigned hash; }; @@ -167,7 +166,7 @@ continue; if (i > 0) break; - he->refcnt++; + he->oh->refcnt++; roh = he->oh; Lck_Unlock(&hp->mtx); /* @@ -191,7 +190,7 @@ VTAILQ_INSERT_BEFORE(he, he2, list); else VTAILQ_INSERT_TAIL(&hp->head, he2, list); - he2->refcnt++; + he2->oh->refcnt++; noh = he2->oh; Lck_Unlock(&hp->mtx); return (noh); @@ -231,11 +230,11 @@ CAST_OBJ_NOTNULL(he, oh->hashpriv, HCL_ENTRY_MAGIC); hp = he->head; CHECK_OBJ_NOTNULL(hp, HCL_HEAD_MAGIC); - assert(he->refcnt > 0); + assert(he->oh->refcnt > 0); assert(he->hash < hcl_nhash); assert(hp == &hcl_head[he->hash]); Lck_Lock(&hp->mtx); - if (--he->refcnt == 0) + if (--he->oh->refcnt == 0) VTAILQ_REMOVE(&hp->head, he, list); else he = NULL; Modified: branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 11:31:24 UTC (rev 3613) +++ branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 11:35:20 UTC (rev 3614) @@ -47,7 +47,6 @@ struct hsl_entry { VTAILQ_ENTRY(hsl_entry) list; struct objhead *oh; - unsigned refcnt; }; static VTAILQ_HEAD(, hsl_entry) hsl_head = VTAILQ_HEAD_INITIALIZER(hsl_head); @@ -85,7 +84,7 @@ continue; if (i > 0) break; - he->refcnt++; + he->oh->refcnt++; noh = he->oh; Lck_Unlock(&hsl_mtx); return (noh); @@ -94,7 +93,7 @@ he2 = calloc(sizeof *he2, 1); XXXAN(he2); he2->oh = noh; - he2->refcnt = 1; + he2->oh->refcnt = 1; noh->hashpriv = he2; noh->hash = malloc(sp->lhashptr); @@ -124,7 +123,7 @@ AN(oh->hashpriv); he = oh->hashpriv; Lck_Lock(&hsl_mtx); - if (--he->refcnt == 0) { + if (--he->oh->refcnt == 0) { VTAILQ_REMOVE(&hsl_head, he, list); free(he); ret = 0; From tfheen at projects.linpro.no Thu Feb 5 11:38:45 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:38:45 +0100 (CET) Subject: r3615 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205113845.9E46E97BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:38:45 +0100 (Thu, 05 Feb 2009) New Revision: 3615 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/cache_cli.c branches/2.0/varnish-cache/bin/varnishd/cache_expire.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/cache_main.c branches/2.0/varnish-cache/bin/varnishd/cache_pool.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c branches/2.0/varnish-cache/bin/varnishd/hash_classic.c branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h branches/2.0/varnish-cache/bin/varnishd/storage_synth.c Log: Merge r3405: Kick the hash_slinger interface around a bit Kick the hash_slinger interface around a bit: Isolate more stuff in hash_slinger.h. Remove hash_slinger from cache.h, include in .c's as necessary. Save a malloc per objhead by putting a few fields into the objhead for the hash_slingers to use. Preinitialize the refcount when we precreate the objhead. Move the hash-string allocation into HSH_Copy(), no point in duplication of mandatory step. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 11:38:45 UTC (rev 3615) @@ -29,6 +29,12 @@ * $Id$ */ +/* + * This macro can be used in .h files to isolate bits that the manager + * should not (need to) see, such as pthread mutexes etc. + */ +#define VARNISH_CACHE_CHILD 1 + #include #include #include @@ -213,8 +219,6 @@ void *priv; }; -#include "hash_slinger.h" - /* Backend Request ---------------------------------------------------*/ struct bereq { @@ -291,19 +295,6 @@ int hits; }; -struct objhead { - unsigned magic; -#define OBJHEAD_MAGIC 0x1b96615d - void *hashpriv; - - struct lock mtx; - unsigned refcnt; - VTAILQ_HEAD(,object) objects; - char *hash; - unsigned hashlen; - VTAILQ_HEAD(, sess) waitinglist; -}; - /* -------------------------------------------------------------------*/ struct sess { @@ -449,18 +440,6 @@ int FetchReqBody(struct sess *sp); void Fetch_Init(void); -/* 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); -void HSH_Unbusy(const struct sess *sp); -void HSH_Ref(struct object *o); -void HSH_Deref(struct object *o); -double HSH_Grace(double g); -void HSH_Init(void); - /* cache_http.c */ const char *http_StatusMessage(unsigned); void HTTP_Init(void); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-05 11:38:45 UTC (rev 3615) @@ -75,6 +75,7 @@ #include "vcl.h" #include "cli_priv.h" #include "cache.h" +#include "hash_slinger.h" static unsigned xids; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_cli.c 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/cache_cli.c 2009-02-05 11:38:45 UTC (rev 3615) @@ -52,6 +52,7 @@ #include "cache.h" #include "vlu.h" #include "vsb.h" +#include "hash_slinger.h" pthread_t cli_thread; static struct lock cli_mtx; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-05 11:38:45 UTC (rev 3615) @@ -60,6 +60,7 @@ #include "shmlog.h" #include "binary_heap.h" #include "cache.h" +#include "hash_slinger.h" /* * Objects have sideways references in the binary heap and the LRU list Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-05 11:38:45 UTC (rev 3615) @@ -65,6 +65,7 @@ #include "shmlog.h" #include "cache.h" #include "stevedore.h" +#include "hash_slinger.h" static const struct hash_slinger *hash; @@ -91,12 +92,23 @@ w->nobjhead = calloc(sizeof *w->nobjhead, 1); XXXAN(w->nobjhead); w->nobjhead->magic = OBJHEAD_MAGIC; + w->nobjhead->refcnt = 1; VTAILQ_INIT(&w->nobjhead->objects); VTAILQ_INIT(&w->nobjhead->waitinglist); Lck_New(&w->nobjhead->mtx); VSL_stats->n_objecthead++; } else CHECK_OBJ_NOTNULL(w->nobjhead, OBJHEAD_MAGIC); + +#if 0 + /* Make sure there is space enough for the hash-string */ + if (w->nobjhead->hashlen < sp->lhashptr) { + w->objhead->hash = realloc(w->objhead->hash, sp->lhashptr); + w->objhead->hashlen = sp->lhashptr; + AN(w->objhead->hash); + } +#endif + if (w->nobj == NULL) { st = STV_alloc(sp, params->obj_workspace); XXXAN(st); @@ -167,7 +179,7 @@ } void -HSH_Copy(const struct sess *sp, const struct objhead *oh) +HSH_Copy(const struct sess *sp, struct objhead *oh) { unsigned u, v; char *b; @@ -175,7 +187,9 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); - assert(oh->hashlen >= sp->lhashptr); + oh->hash = malloc(sp->lhashptr); + XXXAN(oh->hash); + oh->hashlen = sp->lhashptr; b = oh->hash; for (u = 0; u < sp->ihashptr; u += 2) { v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); @@ -210,6 +224,7 @@ CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); Lck_Lock(&oh->mtx); } else { + AN(w->nobjhead); oh = hash->lookup(sp, w->nobjhead); CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); if (oh == w->nobjhead) Modified: branches/2.0/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_main.c 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/cache_main.c 2009-02-05 11:38:45 UTC (rev 3615) @@ -39,6 +39,7 @@ #include "shmlog.h" #include "cache.h" #include "stevedore.h" +#include "hash_slinger.h" /*-------------------------------------------------------------------- * Per thread storage for the session currently being processed by Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 11:38:45 UTC (rev 3615) @@ -71,6 +71,7 @@ #include "cli_priv.h" #include "cache.h" #include "stevedore.h" +#include "hash_slinger.h" VTAILQ_HEAD(workerhead, worker); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-05 11:38:45 UTC (rev 3615) @@ -50,6 +50,7 @@ #include "vrt_obj.h" #include "vcl.h" #include "cache.h" +#include "hash_slinger.h" #include "cache_backend.h" void *vrt_magic_string_end = &vrt_magic_string_end; Modified: branches/2.0/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-05 11:38:45 UTC (rev 3615) @@ -40,23 +40,14 @@ #include "shmlog.h" #include "cache.h" +#include "hash_slinger.h" /*--------------------------------------------------------------------*/ -struct hcl_entry { - unsigned magic; -#define HCL_ENTRY_MAGIC 0x0ba707bf - VTAILQ_ENTRY(hcl_entry) list; - struct hcl_hd *head; - struct objhead *oh; - unsigned digest; - unsigned hash; -}; - struct hcl_hd { unsigned magic; #define HCL_HEAD_MAGIC 0x0f327016 - VTAILQ_HEAD(, hcl_entry) head; + VTAILQ_HEAD(, objhead) head; struct lock mtx; }; @@ -126,16 +117,13 @@ static struct objhead * hcl_lookup(const struct sess *sp, struct objhead *noh) { - struct objhead *roh; - struct hcl_entry *he, *he2; + struct objhead *oh; struct hcl_hd *hp; - unsigned u1, digest, r; + unsigned u1, digest; unsigned u, v; int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); - CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC); CHECK_OBJ_ORNULL(noh, OBJHEAD_MAGIC); digest = ~0U; @@ -147,73 +135,39 @@ u1 = digest % hcl_nhash; hp = &hcl_head[u1]; - he2 = NULL; - for (r = 0; r < 2; r++ ) { - Lck_Lock(&hp->mtx); - VTAILQ_FOREACH(he, &hp->head, list) { - CHECK_OBJ_NOTNULL(he, HCL_ENTRY_MAGIC); - if (sp->lhashptr < he->oh->hashlen) - continue; - if (sp->lhashptr > he->oh->hashlen) - break; - if (he->digest < digest) - continue; - if (he->digest > digest) - break; - i = HSH_Compare(sp, he->oh); - if (i < 0) - continue; - if (i > 0) - break; - he->oh->refcnt++; - roh = he->oh; - Lck_Unlock(&hp->mtx); - /* - * If we loose the race, we need to clean up - * the work we did for our second attempt. - */ - if (he2 != NULL) - free(he2); - if (noh != NULL && noh->hash != NULL) { - free(noh->hash); - noh->hash = NULL; - } - return (roh); - } - if (noh == NULL) { - Lck_Unlock(&hp->mtx); - return (NULL); - } - if (he2 != NULL) { - if (he != NULL) - VTAILQ_INSERT_BEFORE(he, he2, list); - else - VTAILQ_INSERT_TAIL(&hp->head, he2, list); - he2->oh->refcnt++; - noh = he2->oh; - Lck_Unlock(&hp->mtx); - return (noh); - } + Lck_Lock(&hp->mtx); + VTAILQ_FOREACH(oh, &hp->head, hoh_list) { + if (sp->lhashptr < oh->hashlen) + continue; + if (sp->lhashptr > oh->hashlen) + break; + if (oh->hoh_digest < digest) + continue; + if (oh->hoh_digest > digest) + break; + i = HSH_Compare(sp, oh); + if (i < 0) + continue; + if (i > 0) + break; + oh->refcnt++; Lck_Unlock(&hp->mtx); + return (oh); + } - he2 = calloc(sizeof *he2, 1); - XXXAN(he2); - he2->magic = HCL_ENTRY_MAGIC; - he2->oh = noh; - he2->digest = digest; - he2->hash = u1; - he2->head = hp; + if (oh != NULL) + VTAILQ_INSERT_BEFORE(oh, noh, hoh_list); + else + VTAILQ_INSERT_TAIL(&hp->head, noh, hoh_list); - noh->hashpriv = he2; - AZ(noh->hash); - noh->hash = malloc(sp->lhashptr); - XXXAN(noh->hash); - noh->hashlen = sp->lhashptr; - HSH_Copy(sp, noh); - } - assert(he2 == NULL); /* FlexeLint */ - INCOMPL(); + noh->hoh_digest = digest; + noh->hoh_head = hp; + + HSH_Copy(sp, noh); + + Lck_Unlock(&hp->mtx); + return (noh); } /*-------------------------------------------------------------------- @@ -221,28 +175,22 @@ */ static int -hcl_deref(const struct objhead *oh) +hcl_deref(struct objhead *oh) { - struct hcl_entry *he; struct hcl_hd *hp; + int ret; CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); - CAST_OBJ_NOTNULL(he, oh->hashpriv, HCL_ENTRY_MAGIC); - hp = he->head; - CHECK_OBJ_NOTNULL(hp, HCL_HEAD_MAGIC); - assert(he->oh->refcnt > 0); - assert(he->hash < hcl_nhash); - assert(hp == &hcl_head[he->hash]); + CAST_OBJ_NOTNULL(hp, oh->hoh_head, HCL_HEAD_MAGIC); + assert(oh->refcnt > 0); Lck_Lock(&hp->mtx); - if (--he->oh->refcnt == 0) - VTAILQ_REMOVE(&hp->head, he, list); - else - he = NULL; + if (--oh->refcnt == 0) { + VTAILQ_REMOVE(&hp->head, oh, hoh_list); + ret = 0; + } else + ret = 1; Lck_Unlock(&hp->mtx); - if (he == NULL) - return (1); - free(he); - return (0); + return (ret); } /*--------------------------------------------------------------------*/ Modified: branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-05 11:38:45 UTC (rev 3615) @@ -33,23 +33,17 @@ #include "config.h" -#include - #include #include #include #include "shmlog.h" #include "cache.h" +#include "hash_slinger.h" /*--------------------------------------------------------------------*/ -struct hsl_entry { - VTAILQ_ENTRY(hsl_entry) list; - struct objhead *oh; -}; - -static VTAILQ_HEAD(, hsl_entry) hsl_head = VTAILQ_HEAD_INITIALIZER(hsl_head); +static VTAILQ_HEAD(, objhead) hsl_head = VTAILQ_HEAD_INITIALIZER(hsl_head); static struct lock hsl_mtx; /*-------------------------------------------------------------------- @@ -74,38 +68,28 @@ static struct objhead * hsl_lookup(const struct sess *sp, struct objhead *noh) { - struct hsl_entry *he, *he2; + struct objhead *oh; int i; Lck_Lock(&hsl_mtx); - VTAILQ_FOREACH(he, &hsl_head, list) { - i = HSH_Compare(sp, he->oh); + VTAILQ_FOREACH(oh, &hsl_head, hoh_list) { + i = HSH_Compare(sp, oh); if (i < 0) continue; if (i > 0) break; - he->oh->refcnt++; - noh = he->oh; + oh->refcnt++; Lck_Unlock(&hsl_mtx); - return (noh); + return (oh); } - if (noh != NULL) { - he2 = calloc(sizeof *he2, 1); - XXXAN(he2); - he2->oh = noh; - he2->oh->refcnt = 1; - noh->hashpriv = he2; - noh->hash = malloc(sp->lhashptr); - XXXAN(noh->hash); - noh->hashlen = sp->lhashptr; - HSH_Copy(sp, noh); + if (oh != NULL) + VTAILQ_INSERT_BEFORE(oh, noh, hoh_list); + else + VTAILQ_INSERT_TAIL(&hsl_head, noh, hoh_list); - if (he != NULL) - VTAILQ_INSERT_BEFORE(he, he2, list); - else - VTAILQ_INSERT_TAIL(&hsl_head, he2, list); - } + HSH_Copy(sp, noh); + Lck_Unlock(&hsl_mtx); return (noh); } @@ -115,17 +99,13 @@ */ static int -hsl_deref(const struct objhead *oh) +hsl_deref(struct objhead *oh) { - struct hsl_entry *he; int ret; - AN(oh->hashpriv); - he = oh->hashpriv; Lck_Lock(&hsl_mtx); - if (--he->oh->refcnt == 0) { - VTAILQ_REMOVE(&hsl_head, he, list); - free(he); + if (--oh->refcnt == 0) { + VTAILQ_REMOVE(&hsl_head, oh, hoh_list); ret = 0; } else ret = 1; Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-05 11:38:45 UTC (rev 3615) @@ -30,12 +30,13 @@ */ struct sess; +struct object; 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); +typedef int hash_deref_f(struct objhead *obj); struct hash_slinger { unsigned magic; @@ -46,3 +47,38 @@ hash_lookup_f *lookup; hash_deref_f *deref; }; + +/* 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, struct objhead *o); +struct object *HSH_Lookup(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); +void HSH_Init(void); + + +#ifdef VARNISH_CACHE_CHILD +struct objhead { + unsigned magic; +#define OBJHEAD_MAGIC 0x1b96615d + + struct lock mtx; + unsigned refcnt; + VTAILQ_HEAD(,object) objects; + char *hash; + unsigned hashlen; + VTAILQ_HEAD(, sess) waitinglist; + + /*------------------------------------------------------------ + * The fields below are for the sole private use of the hash + * implementation. + */ + VTAILQ_ENTRY(objhead) hoh_list; + void *hoh_head; + unsigned hoh_digest; +}; +#endif /* VARNISH_CACHE_CHILD */ Modified: branches/2.0/varnish-cache/bin/varnishd/storage_synth.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_synth.c 2009-02-05 11:35:20 UTC (rev 3614) +++ branches/2.0/varnish-cache/bin/varnishd/storage_synth.c 2009-02-05 11:38:45 UTC (rev 3615) @@ -42,6 +42,7 @@ #include "cache.h" #include "vsb.h" #include "stevedore.h" +#include "hash_slinger.h" static struct lock sms_mtx; From tfheen at projects.linpro.no Thu Feb 5 11:43:21 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:43:21 +0100 (CET) Subject: r3616 - in branches/2.0/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvarnish lib/libvcl Message-ID: <20090205114321.303E628370@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:43:20 +0100 (Thu, 05 Feb 2009) New Revision: 3616 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/b00020.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/b00021.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/b00022.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/b00024.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/b00025.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/b00026.vtc Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_backend.c branches/2.0/varnish-cache/bin/varnishd/cache_backend.h branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c branches/2.0/varnish-cache/bin/varnishd/cache_session.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c branches/2.0/varnish-cache/bin/varnishd/heritage.h branches/2.0/varnish-cache/bin/varnishd/mgt_param.c branches/2.0/varnish-cache/include/libvarnish.h branches/2.0/varnish-cache/include/vrt.h branches/2.0/varnish-cache/include/vrt_obj.h branches/2.0/varnish-cache/lib/libvarnish/tcp.c branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c Log: Merge r3406: Added support for setting read timeouts for backend requests Added support for setting read timeouts for backend requests (first_byte_timeout and between_bytes_timeout), in addition to make the connect_timeout available for the bereq object in vcl_miss and vcl_fetch. first_byte_timeout is a read timeout from the connection to the backend is created to when the first byte arrives. It can be set as a parameter to varnish, as a field in the backend declaration or as bereq.first_byte_timeout in vcl_miss and vcl_pass. between_bytes_timeout is a read timeout between each read from the backend. It can be set as a parameter to varnish, as a field in the backend declaration or as bereq.between_bytes_timeout in vcl_miss and vcl_pass. The time unit for these timeout values are seconds. NOTE: The connect_timeout previously used milliseconds as time unit, so beware. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 11:43:20 UTC (rev 3616) @@ -337,6 +337,11 @@ double t_resp; double t_end; + /* Timeouts */ + double connect_timeout; + double first_byte_timeout; + double between_bytes_timeout; + /* Acceptable grace period */ double grace; @@ -538,6 +543,8 @@ void SES_Delete(struct sess *sp); void SES_RefSrcAddr(struct sess *sp); void SES_Charge(struct sess *sp); +void SES_ResetBackendTimeouts(struct sess *sp); +void SES_InheritBackendTimeouts(struct sess *sp); /* cache_shmlog.c */ void VSL_Init(void); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -95,7 +95,7 @@ if (s < 0) return (s); - tmo = params->connect_timeout; + tmo = (int)(sp->connect_timeout * 1000); if (bp->connect_timeout > 10e-3) tmo = (int)(bp->connect_timeout * 1000); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend.h 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend.h 2009-02-05 11:43:20 UTC (rev 3616) @@ -104,6 +104,8 @@ char *ident; char *vcl_name; double connect_timeout; + double first_byte_timeout; + double between_bytes_timeout; uint32_t hash; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -222,6 +222,8 @@ REPLACE(b->hosthdr, vb->hosthdr); b->connect_timeout = vb->connect_timeout; + b->first_byte_timeout = vb->first_byte_timeout; + b->between_bytes_timeout = vb->between_bytes_timeout; b->max_conn = vb->max_connections; /* Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -845,6 +845,8 @@ CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); AZ(sp->obj); + SES_ResetBackendTimeouts(sp); + /* By default we use the first backend */ AZ(sp->director); sp->director = sp->vcl->director[0]; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -336,6 +336,8 @@ if (sp->vbe == NULL) return (__LINE__); vc = sp->vbe; + /* Inherit the backend timeouts from the selected backend */ + SES_InheritBackendTimeouts(sp); /* * Now that we know our backend, we can set a default Host: @@ -369,8 +371,11 @@ VSL_stats->backend_req++; HTC_Init(htc, bereq->ws, vc->fd); - do + TCP_set_read_timeout(vc->fd, sp->first_byte_timeout); + do { i = HTC_Rx(htc); + TCP_set_read_timeout(vc->fd, sp->between_bytes_timeout); + } while (i == 0); if (i < 0) { Modified: branches/2.0/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_session.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/bin/varnishd/cache_session.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -58,6 +58,7 @@ #include "shmlog.h" #include "cache.h" +#include "cache_backend.h" /*--------------------------------------------------------------------*/ @@ -316,6 +317,8 @@ sp->http = &sm->http[0]; sp->http0 = &sm->http[1]; + SES_ResetBackendTimeouts(sp); + return (sp); } @@ -367,3 +370,38 @@ Lck_New(&stat_mtx); Lck_New(&ses_mem_mtx); } + +void +SES_ResetBackendTimeouts(struct sess *sp) +{ + sp->connect_timeout = params->connect_timeout; + sp->first_byte_timeout = params->first_byte_timeout; + sp->between_bytes_timeout = params->between_bytes_timeout; +} + +void +SES_InheritBackendTimeouts(struct sess *sp) +{ + struct backend *be = NULL; + + AN(sp); + AN(sp->vbe); + AN(sp->vbe->backend); + + be = sp->vbe->backend; + /* + * We only inherit the backend's timeout if the session timeout + * has not already been set in the VCL, as the order of precedence + * is parameter < backend definition < VCL. + */ + if (be->connect_timeout > 1e-3 && + sp->connect_timeout == params->connect_timeout) + sp->connect_timeout = be->connect_timeout; + if (be->first_byte_timeout > 1e-3 && + sp->first_byte_timeout == params->first_byte_timeout) + sp->first_byte_timeout = be->first_byte_timeout; + if (be->between_bytes_timeout > 1e-3 + && sp->between_bytes_timeout == params->between_bytes_timeout) + sp->between_bytes_timeout = be->between_bytes_timeout; +} + Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -299,6 +299,48 @@ return (atoi(sp->http->hd[HTTP_HDR_STATUS].b)); } +void +VRT_l_bereq_connect_timeout(struct sess *sp, double num) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + sp->connect_timeout = (num > 0 ? num : 0); +} + +double +VRT_r_bereq_connect_timeout(struct sess *sp) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + return sp->connect_timeout; +} + +void +VRT_l_bereq_first_byte_timeout(struct sess *sp, double num) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + sp->first_byte_timeout = (num > 0 ? num : 0); +} + +double +VRT_r_bereq_first_byte_timeout(struct sess *sp) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + return sp->first_byte_timeout; +} + +void +VRT_l_bereq_between_bytes_timeout(struct sess *sp, double num) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + sp->between_bytes_timeout = (num > 0 ? num : 0); +} + +double +VRT_r_bereq_between_bytes_timeout(struct sess *sp) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + return sp->between_bytes_timeout; +} + /*--------------------------------------------------------------------*/ void Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-05 11:43:20 UTC (rev 3616) @@ -154,8 +154,12 @@ unsigned cache_vbe_conns; /* Default connection_timeout */ - unsigned connect_timeout; + double connect_timeout; + /* Read timeouts for backend */ + double first_byte_timeout; + double between_bytes_timeout; + /* How long to linger on sessions */ unsigned session_linger; Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -97,6 +97,24 @@ cli_out(cli, "%u", *dst); } +static void +tweak_generic_timeout_double(struct cli *cli, volatile double *dst, const char *arg) +{ + double u; + + if (arg != NULL) { + u = strtod(arg, NULL); + if (u < 0) { + cli_out(cli, "Timeout must be greater or equal to zero\n"); + cli_result(cli, CLIS_PARAM); + return; + } + *dst = u; + } else + cli_out(cli, "%f", *dst); +} + + /*--------------------------------------------------------------------*/ static void @@ -108,7 +126,14 @@ tweak_generic_timeout(cli, dest, arg); } +static void +tweak_timeout_double(struct cli *cli, const struct parspec *par, const char *arg) +{ + volatile double *dest; + dest = par->priv; + tweak_generic_timeout_double(cli, dest, arg); +} /*--------------------------------------------------------------------*/ static void @@ -746,14 +771,31 @@ "Cache vbe_conn's or rely on malloc, that's the question.", EXPERIMENTAL, "off", "bool" }, - { "connect_timeout", tweak_uint, + { "connect_timeout", tweak_timeout_double, &master.connect_timeout,0, UINT_MAX, "Default connection timeout for backend connections. " "We only try to connect to the backend for this many " - "milliseconds before giving up. " - "VCL can override this default value for each backend.", + "seconds before giving up. " + "VCL can override this default value for each backend. " + "This does not apply to pipe. ", 0, - "400", "ms" }, + "0.4", "s" }, + { "first_byte_timeout", tweak_timeout_double, + &master.first_byte_timeout,0, UINT_MAX, + "Default timeout for receiving first byte from backend. " + "We only wait for this many seconds for the first " + "byte before giving up. A value of 0 means it will never time out. " + "VCL can override this default value for each backend request.", + 0, + "60", "s" }, + { "between_bytes_timeout", tweak_timeout_double, + &master.between_bytes_timeout,0, UINT_MAX, + "Default timeout between bytes when receiving data from backend. " + "We only wait for this many seconds between bytes " + "before giving up. A value of 0 means it will never time out. " + "VCL can override this default value for each backend request.", + 0, + "60", "s" }, { "accept_fd_holdoff", tweak_timeout, &master.accept_fd_holdoff, 0, 3600*1000, "If we run out of file descriptors, the accept thread will " Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00020.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00020.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00020.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00020.vtc 2009-02-05 11:43:20 UTC (rev 3616) @@ -0,0 +1,34 @@ +# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $ + +test "Check the between_bytes_timeout behaves from parameters" + +server s1 { + rxreq + send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n" + delay 1.5 + send "Baba\n" +} -start + +varnish v1 -vcl+backend {} -start +varnish v1 -cliok "param.set between_bytes_timeout 1" + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run + +server s1 { + rxreq + send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n" + delay 0.5 + send "Baba\n" + delay 0.5 + send "Baba\n" +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00021.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00021.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00021.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00021.vtc 2009-02-05 11:43:20 UTC (rev 3616) @@ -0,0 +1,37 @@ +# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $ + +test "Check the between_bytes_timeout behaves from vcl" + +server s1 { + rxreq + send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n" + delay 1.5 + send "Baba\n" +} -start + +varnish v1 -vcl+backend { + sub vcl_miss { + set bereq.between_bytes_timeout = 1s; + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run + +server s1 { + rxreq + send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n" + delay 0.5 + send "Baba\n" + delay 0.5 + send "Baba\n" +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00022.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00022.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00022.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00022.vtc 2009-02-05 11:43:20 UTC (rev 3616) @@ -0,0 +1,39 @@ +# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $ + +test "Check the between_bytes_timeout behaves from backend definition" + +server s1 { + rxreq + send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n" + delay 1.5 + send "Baba\n" +} -start + +varnish v1 -vcl { + backend b1 { + .host = "127.0.0.1"; + .port = "9080"; + .between_bytes_timeout = 1s; + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run + +server s1 { + rxreq + send "HTTP/1.1 200 Ok\r\nConnection: close\r\n\r\n" + delay 0.5 + send "Baba\n" + delay 0.5 + send "Baba\n" +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00023.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc 2009-02-05 11:43:20 UTC (rev 3616) @@ -0,0 +1,31 @@ +# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $ + +test "Check that the first_byte_timeout works from parameters" + +server s1 { + rxreq + delay 1.5 + txresp +} -start + +varnish v1 -vcl+backend {} -start +varnish v1 -cliok "param.set first_byte_timeout 1" + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run + + +server s1 { + rxreq + delay 0.5 + txresp +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00024.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00024.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00024.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00024.vtc 2009-02-05 11:43:20 UTC (rev 3616) @@ -0,0 +1,34 @@ +# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $ + +test "Check that the first_byte_timeout works from vcl" + +server s1 { + rxreq + delay 1.5 + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_miss { + set bereq.first_byte_timeout = 1s; + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run + + +server s1 { + rxreq + delay 0.5 + txresp +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00025.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00025.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00025.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00025.vtc 2009-02-05 11:43:20 UTC (rev 3616) @@ -0,0 +1,36 @@ +# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $ + +test "Check that the first_byte_timeout works from backend definition" + +server s1 { + rxreq + delay 1.5 + txresp +} -start + +varnish v1 -vcl { + backend b1 { + .host = "127.0.0.1"; + .port = "9080"; + .first_byte_timeout = 1s; + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run + + +server s1 { + rxreq + delay 0.5 + txresp +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00026.vtc (from rev 3406, trunk/varnish-cache/bin/varnishtest/tests/b00026.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00026.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00026.vtc 2009-02-05 11:43:20 UTC (rev 3616) @@ -0,0 +1,50 @@ +# $Id: b00019.vtc 3300 2008-10-15 09:52:15Z tfheen $ + +test "Check the precedence for timeouts" + +server s1 -listen 127.0.0.1:9080 { + rxreq + expect req.url == "from_backend" + delay 1; + txresp +} -start +server s2 -listen 127.0.0.1:9180 { + rxreq + expect req.url == "from_vcl" + delay 1.5; + txresp +} -start + +varnish v1 -vcl { + backend b1 { + .host = "127.0.0.1"; + .port = "9080"; + .first_byte_timeout = 2s; + } + backend b2 { + .host = "127.0.0.1"; + .port = "9180"; + .first_byte_timeout = 1s; + } + + sub vcl_recv { + if (req.url == "from_backend") { + set req.backend = b1; + pass; + } + set req.backend = b2; + } + sub vcl_miss { + set bereq.first_byte_timeout = 2s; + } +} -start +varnish v1 -cliok "param.set first_byte_timeout 0.5" + +client c1 { + txreq -url "from_backend" + rxresp + expect resp.status == 200 + txreq -url "from_vcl" + rxresp + expect resp.status == 200 +} -run Modified: branches/2.0/varnish-cache/include/libvarnish.h =================================================================== --- branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 11:43:20 UTC (rev 3616) @@ -65,6 +65,7 @@ int TCP_connect(int s, const struct sockaddr *name, socklen_t namelen, int msec); void TCP_close(int *s); +void TCP_set_read_timeout(int socket, double seconds); #endif /* from libvarnish/time.c */ Modified: branches/2.0/varnish-cache/include/vrt.h =================================================================== --- branches/2.0/varnish-cache/include/vrt.h 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/include/vrt.h 2009-02-05 11:43:20 UTC (rev 3616) @@ -69,6 +69,8 @@ const unsigned char *ipv6_sockaddr; double connect_timeout; + double first_byte_timeout; + double between_bytes_timeout; unsigned max_connections; struct vrt_backend_probe probe; }; Modified: branches/2.0/varnish-cache/include/vrt_obj.h =================================================================== --- branches/2.0/varnish-cache/include/vrt_obj.h 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/include/vrt_obj.h 2009-02-05 11:43:20 UTC (rev 3616) @@ -28,6 +28,12 @@ void VRT_l_bereq_url(const struct sess *, const char *, ...); const char * VRT_r_bereq_proto(const struct sess *); void VRT_l_bereq_proto(const struct sess *, const char *, ...); +double VRT_r_bereq_connect_timeout(struct sess *); +void VRT_l_bereq_connect_timeout(struct sess *, double); +double VRT_r_bereq_first_byte_timeout(struct sess *); +void VRT_l_bereq_first_byte_timeout(struct sess *, double); +double VRT_r_bereq_between_bytes_timeout(struct sess *); +void VRT_l_bereq_between_bytes_timeout(struct sess *, double); const char * VRT_r_obj_proto(const struct sess *); void VRT_l_obj_proto(const struct sess *, const char *, ...); int VRT_r_obj_status(const struct sess *); Modified: branches/2.0/varnish-cache/lib/libvarnish/tcp.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/tcp.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/lib/libvarnish/tcp.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -47,6 +47,7 @@ #include #include #include +#include #include "config.h" #ifndef HAVE_STRLCPY @@ -210,3 +211,14 @@ errno == ENOTCONN); *s = -1; } + +void +TCP_set_read_timeout(int s, double seconds) +{ + struct timeval timeout; + timeout.tv_sec = floor(seconds); + timeout.tv_usec = 1e6 * (seconds - timeout.tv_sec); +#ifdef SO_RCVTIMEO_WORKS + AZ(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout)); +#endif +} Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_backend.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -473,6 +473,8 @@ "?port", "?host_header", "?connect_timeout", + "?first_byte_timeout", + "?between_bytes_timeout", "?probe", "?max_connections", NULL); @@ -537,6 +539,20 @@ Fb(tl, 0, ",\n"); ExpectErr(tl, ';'); vcc_NextToken(tl); + } else if (vcc_IdIs(t_field, "first_byte_timeout")) { + Fb(tl, 0, "\t.first_byte_timeout = "); + vcc_TimeVal(tl); + ERRCHK(tl); + Fb(tl, 0, ",\n"); + ExpectErr(tl, ';'); + vcc_NextToken(tl); + } else if (vcc_IdIs(t_field, "between_bytes_timeout")) { + Fb(tl, 0, "\t.between_bytes_timeout = "); + vcc_TimeVal(tl); + ERRCHK(tl); + Fb(tl, 0, ",\n"); + ExpectErr(tl, ';'); + vcc_NextToken(tl); } else if (vcc_IdIs(t_field, "max_connections")) { u = vcc_UintVal(tl); vcc_NextToken(tl); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -243,6 +243,8 @@ vsb_cat(sb, "\tconst unsigned char\t\t*ipv4_sockaddr;\n"); vsb_cat(sb, "\tconst unsigned char\t\t*ipv6_sockaddr;\n"); vsb_cat(sb, "\n\tdouble\t\t\t\tconnect_timeout;\n"); + vsb_cat(sb, "\tdouble\t\t\t\tfirst_byte_timeout;\n"); + vsb_cat(sb, "\tdouble\t\t\t\tbetween_bytes_timeout;\n"); vsb_cat(sb, "\tunsigned\t\t\tmax_connections;\n"); vsb_cat(sb, "\tstruct vrt_backend_probe\tprobe;\n"); vsb_cat(sb, "};\n\n/*\n * A director with a predictable reply\n"); @@ -309,9 +311,9 @@ /* ../../include/vrt_obj.h */ - vsb_cat(sb, "/*\n * $Id: vcc_gen_obj.tcl 3580 2009-02-05 08:45:25Z "); - vsb_cat(sb, "tfheen $\n *\n * NB: This file is machine generated, "); - vsb_cat(sb, "DO NOT EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); + vsb_cat(sb, "/*\n * $Id: vrt_obj.h 3169 2008-09-08 09:49:01Z tfheen"); + vsb_cat(sb, " $\n *\n * NB: This file is machine generated, DO NOT"); + vsb_cat(sb, " EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct "); vsb_cat(sb, "sess *);\nstruct sockaddr * VRT_r_server_ip(struct ses"); vsb_cat(sb, "s *);\nint VRT_r_server_port(struct sess *);\n"); @@ -335,9 +337,16 @@ vsb_cat(sb, " const char *, ...);\nconst char * VRT_r_bereq_proto(c"); vsb_cat(sb, "onst struct sess *);\nvoid VRT_l_bereq_proto(const str"); vsb_cat(sb, "uct sess *, const char *, ...);\n"); - vsb_cat(sb, "const char * VRT_r_obj_proto(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_proto(const struct sess *, const char *"); - vsb_cat(sb, ", ...);\nint VRT_r_obj_status(const struct sess *);\n"); + vsb_cat(sb, "double VRT_r_bereq_connect_timeout(struct sess *);\n"); + vsb_cat(sb, "void VRT_l_bereq_connect_timeout(struct sess *, double"); + vsb_cat(sb, ");\ndouble VRT_r_bereq_first_byte_timeout(struct sess "); + vsb_cat(sb, "*);\nvoid VRT_l_bereq_first_byte_timeout(struct sess *"); + vsb_cat(sb, ", double);\ndouble VRT_r_bereq_between_bytes_timeout(s"); + vsb_cat(sb, "truct sess *);\nvoid VRT_l_bereq_between_bytes_timeout"); + vsb_cat(sb, "(struct sess *, double);\nconst char * VRT_r_obj_proto"); + vsb_cat(sb, "(const struct sess *);\nvoid VRT_l_obj_proto(const str"); + vsb_cat(sb, "uct sess *, const char *, ...);\n"); + vsb_cat(sb, "int VRT_r_obj_status(const struct sess *);\n"); 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 cha"); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2009-02-05 11:43:20 UTC (rev 3616) @@ -127,6 +127,21 @@ { pipe pass miss fetch } "const struct sess *" } + { bereq.connect_timeout + RW TIME + { pass miss } + "struct sess *" + } + { bereq.first_byte_timeout + RW TIME + { pass miss } + "struct sess *" + } + { bereq.between_bytes_timeout + RW TIME + { pass miss } + "struct sess *" + } # The (possibly) cached object { obj.proto Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c 2009-02-05 11:38:45 UTC (rev 3615) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_obj.c 2009-02-05 11:43:20 UTC (rev 3616) @@ -108,6 +108,21 @@ V_RW, "HDR_BEREQ", VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS | VCL_MET_FETCH }, + { "bereq.connect_timeout", TIME, 21, + "VRT_r_bereq_connect_timeout(sp)", "VRT_l_bereq_connect_timeout(sp, ", + V_RW, 0, + VCL_MET_PASS | VCL_MET_MISS + }, + { "bereq.first_byte_timeout", TIME, 24, + "VRT_r_bereq_first_byte_timeout(sp)", "VRT_l_bereq_first_byte_timeout(sp, ", + V_RW, 0, + VCL_MET_PASS | VCL_MET_MISS + }, + { "bereq.between_bytes_timeout", TIME, 27, + "VRT_r_bereq_between_bytes_timeout(sp)", "VRT_l_bereq_between_bytes_timeout(sp, ", + V_RW, 0, + VCL_MET_PASS | VCL_MET_MISS + }, { "obj.proto", STRING, 9, "VRT_r_obj_proto(sp)", "VRT_l_obj_proto(sp, ", V_RW, 0, From tfheen at projects.linpro.no Thu Feb 5 11:47:18 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:47:18 +0100 (CET) Subject: r3617 - branches/2.0/varnish-cache/lib/libvcl Message-ID: <20090205114718.BC2F328370@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:47:18 +0100 (Thu, 05 Feb 2009) New Revision: 3617 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Merge r3409: Clean up the ACL generation code a bit. Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c 2009-02-05 11:43:20 UTC (rev 3616) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c 2009-02-05 11:47:18 UTC (rev 3617) @@ -60,59 +60,87 @@ /* Compare two acl rules for ordering */ +#define CMP(a, b) \ + do { \ + if ((a) < (b)) \ + return (-1); \ + else if ((b) < (a)) \ + return (1); \ + } while (0) + static int -vcl_acl_cmp(struct tokenlist *tl, struct acl_e *ae1, struct acl_e *ae2) +vcl_acl_cmp(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); + CMP(*p1, *p2); p1++; p2++; } if (m) { m = 0xff00 >> m; m &= 0xff; - if ((*p1 & m) < (*p2 & m)) - return (-1); - if ((*p1 & m) > (*p2 & m)) - return (1); + CMP(*p1 & m, *p2 & m); } - if (ae1->mask > ae2->mask) - return (-1); - if (ae1->mask < ae2->mask) - return (1); + /* Long mask is less than short mask */ + CMP(ae2->mask, ae1->mask); return (0); } static void -vcl_acl_add_entry(struct tokenlist *tl, struct acl_e *ae) +vcc_acl_add_entry(struct tokenlist *tl, const struct acl_e *ae, int l, + const unsigned char *u, int fam) { - struct acl_e *ae2; + struct acl_e *ae2, *aen; int i; + 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; + } + + /* Make a copy from the template */ + aen = TlAlloc(tl, sizeof *ae2); + AN(aen); + *aen = *ae; + + /* We treat family as part of address, it saves code */ + assert(fam <= 0xff); + aen->data[0] = fam & 0xff; + aen->mask += 8; + + memcpy(aen->data + 1, u, l); + VTAILQ_FOREACH(ae2, &tl->acl, list) { - i = vcl_acl_cmp(tl, ae, ae2); + i = vcl_acl_cmp(aen, ae2); if (i == 0) { - /* If the two rules agree, silently ignore it */ - if (ae->not == ae2->not) + /* + * If the two rules agree, silently ignore it + * XXX: is that counter intuitive ? + */ + if (aen->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); + vcc_ErrWhere(tl, aen->t_addr); return; } /* @@ -126,46 +154,14 @@ * be used to gather statistics. */ if (i < 0) { - VTAILQ_INSERT_BEFORE(ae2, ae, list); + VTAILQ_INSERT_BEFORE(ae2, aen, list); return; } } - VTAILQ_INSERT_TAIL(&tl->acl, ae, list); + VTAILQ_INSERT_TAIL(&tl->acl, aen, 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 & 0xff; - 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; @@ -211,7 +207,7 @@ if (ae->t_mask == NULL) ae->mask = 32; i4++; - vcc_acl_emit_entry(tl, ae, 4, u, res->ai_family); + vcc_acl_add_entry(tl, ae, 4, u, res->ai_family); break; case PF_INET6: assert(PF_INET6 < 256); @@ -221,7 +217,7 @@ if (ae->t_mask == NULL) ae->mask = 128; i6++; - vcc_acl_emit_entry(tl, ae, 16, u, res->ai_family); + vcc_acl_add_entry(tl, ae, 16, u, res->ai_family); break; default: vsb_printf(tl->sb, @@ -270,7 +266,7 @@ } if (ae->t_mask == NULL) ae->mask = 8 + 8 * i; - vcc_acl_emit_entry(tl, ae, 4, b, AF_INET); + vcc_acl_add_entry(tl, ae, 4, b, AF_INET); return (1); } @@ -321,9 +317,12 @@ ERRCHK(tl); } +/********************************************************************* + * Emit a function to match the ACL we have collected + */ + static void -vcc_acl_bot(const struct tokenlist *tl, const char *acln, int silent, - const char *pfx) +vcc_acl_emit(const struct tokenlist *tl, const char *acln, int anon) { struct acl_e *ae; int depth, l, m, i; @@ -333,7 +332,7 @@ Fh(tl, 0, "\nstatic int\n"); Fh(tl, 0, "match_acl_%s_%s(const struct sess *sp, const void *p)\n", - pfx, acln); + anon ? "anon" : "named", acln); Fh(tl, 0, "{\n"); Fh(tl, 0, "\tconst unsigned char *a;\n"); assert(sizeof (unsigned char) == 1); @@ -375,30 +374,31 @@ /* Back down, if necessary */ oc = ""; while (l <= depth) { - Fh(tl, 0, "\t%*s}\n", - -depth, ""); + Fh(tl, 0, "\t%*s}\n", -depth, ""); depth--; oc = "else "; } + m = ae->mask; m -= l * 8; + + /* Do whole byte compares */ for (i = l; m >= 8; m -= 8, i++) { - if (i == 0) { + if (i == 0) Fh(tl, 0, "\t%*s%sif (fam == %d) {\n", -i, "", oc, ae->data[i]); - } else { + 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) { + /* Do fractional byte compares */ Fh(tl, 0, "\t%*s%sif ((a[%d] & 0x%x) == %d) {\n", - -i, "", - oc, - i - 1, (0xff00 >> m) & 0xff, + -i, "", oc, i - 1, (0xff00 >> m) & 0xff, ae->data[i] & ((0xff00 >> m) & 0xff)); at[i] = 256; depth = i; @@ -407,11 +407,9 @@ i = (ae->mask + 7) / 8; - if (!silent) { + if (!anon) { Fh(tl, 0, "\t%*sVRT_acl_log(sp, \"%sMATCH %s \" ", - -i, "", - ae->not ? "NEG_" : "", - acln, + -i, "", ae->not ? "NEG_" : "", acln, PF(ae->t_addr)); EncToken(tl->fh, ae->t_addr); if (ae->t_mask != NULL) @@ -422,9 +420,12 @@ Fh(tl, 0, "\t%*sreturn (%d);\n", -i, "", ae->not ? 0 : 1); } + /* Unwind */ for (; 0 <= depth; depth--) Fh(tl, 0, "\t%*.*s}\n", depth, depth, ""); - if (!silent) + + /* Deny by default */ + if (!anon) Fh(tl, 0, "\tVRT_acl_log(sp, \"NO_MATCH %s\");\n", acln); Fh(tl, 0, "\treturn (0);\n}\n"); } @@ -453,7 +454,7 @@ asprintf(&acln, "%u", tl->cnt); assert(acln != NULL); vcc_acl_entry(tl); - vcc_acl_bot(tl, acln, 1, "anon"); + vcc_acl_emit(tl, acln, 1); Fb(tl, 1, "%smatch_acl_anon_%s(sp, %s)\n", (tcond == T_NEQ ? "!" : ""), acln, vp->rname); free(acln); @@ -497,7 +498,7 @@ ExpectErr(tl, '}'); vcc_NextToken(tl); - vcc_acl_bot(tl, acln, 0, "named"); + vcc_acl_emit(tl, acln, 0); free(acln); } Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 11:43:20 UTC (rev 3616) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-05 11:47:18 UTC (rev 3617) @@ -223,8 +223,8 @@ vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI"); vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT"); vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"); - vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3609 2009-02-05 11:"); - vsb_cat(sb, "14:28Z tfheen $\n *\n * Runtime support for compiled V"); + vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3616 2009-02-05 11:"); + vsb_cat(sb, "43:20Z tfheen $\n *\n * Runtime support for compiled V"); vsb_cat(sb, "CL programs.\n *\n * XXX: When this file is changed, l"); vsb_cat(sb, "ib/libvcl/vcc_gen_fixed_token.tcl\n"); vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n"); @@ -311,7 +311,7 @@ /* ../../include/vrt_obj.h */ - vsb_cat(sb, "/*\n * $Id: vrt_obj.h 3169 2008-09-08 09:49:01Z tfheen"); + vsb_cat(sb, "/*\n * $Id: vrt_obj.h 3616 2009-02-05 11:43:20Z tfheen"); vsb_cat(sb, " $\n *\n * NB: This file is machine generated, DO NOT"); vsb_cat(sb, " EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct "); From tfheen at projects.linpro.no Thu Feb 5 11:51:21 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:51:21 +0100 (CET) Subject: r3618 - in branches/2.0/varnish-cache/lib: libvarnish libvcl Message-ID: <20090205115121.1C0811F747D@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:51:20 +0100 (Thu, 05 Feb 2009) New Revision: 3618 Modified: branches/2.0/varnish-cache/lib/libvarnish/vss.c branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c Log: Merge r3410: Various nits. Modified: branches/2.0/varnish-cache/lib/libvarnish/vss.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vss.c 2009-02-05 11:47:18 UTC (rev 3617) +++ branches/2.0/varnish-cache/lib/libvarnish/vss.c 2009-02-05 11:51:20 UTC (rev 3618) @@ -155,7 +155,7 @@ XXXAN(va); *vap = va; for (res = res0, i = 0; res != NULL; res = res->ai_next, ++i) { - va[i] = calloc(1, sizeof *va[i]); + va[i] = calloc(1, sizeof(*va[i])); XXXAN(va[i]); va[i]->va_family = res->ai_family; va[i]->va_socktype = res->ai_socktype; Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-05 11:47:18 UTC (rev 3617) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-05 11:51:20 UTC (rev 3618) @@ -127,7 +127,7 @@ static double RateUnit(struct tokenlist *tl) { - double sc = 1.0; + double sc; assert(tl->t->tok == ID); sc = SizeUnit(tl); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c 2009-02-05 11:47:18 UTC (rev 3617) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c 2009-02-05 11:51:20 UTC (rev 3618) @@ -28,7 +28,7 @@ * * $Id$ * - * This fine contains code for two cross-reference or consistency checks. + * This file contains code for two cross-reference or consistency checks. * * The first check is simply that all functions, acls and backends are * both defined and referenced. Complaints about referenced but undefined @@ -90,7 +90,7 @@ vcc_ErrToken(tl, r->name); vsb_printf(tl->sb, " has unknown type %d\n", r->type); - return "???"; + return "?"; } } From tfheen at projects.linpro.no Thu Feb 5 11:57:13 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 12:57:13 +0100 (CET) Subject: r3619 - in branches/2.0/varnish-cache: bin/varnishd man Message-ID: <20090205115713.AFF491F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-05 12:57:13 +0100 (Thu, 05 Feb 2009) New Revision: 3619 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c branches/2.0/varnish-cache/bin/varnishd/varnishd.1 branches/2.0/varnish-cache/man/vcl.7so Log: Merge r3411+r3412: Added documentaiton on the timeouts Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 11:51:20 UTC (rev 3618) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 11:57:13 UTC (rev 3619) @@ -773,11 +773,11 @@ "off", "bool" }, { "connect_timeout", tweak_timeout_double, &master.connect_timeout,0, UINT_MAX, - "Default connection timeout for backend connections. " + "Default connection timeout for backend connections. " "We only try to connect to the backend for this many " "seconds before giving up. " - "VCL can override this default value for each backend. " - "This does not apply to pipe. ", + "VCL can override this default value for each backend and " + "backend request.", 0, "0.4", "s" }, { "first_byte_timeout", tweak_timeout_double, @@ -785,7 +785,8 @@ "Default timeout for receiving first byte from backend. " "We only wait for this many seconds for the first " "byte before giving up. A value of 0 means it will never time out. " - "VCL can override this default value for each backend request.", + "VCL can override this default value for each backend and " + "backend request. This parameter does not apply to pipe.", 0, "60", "s" }, { "between_bytes_timeout", tweak_timeout_double, @@ -793,7 +794,8 @@ "Default timeout between bytes when receiving data from backend. " "We only wait for this many seconds between bytes " "before giving up. A value of 0 means it will never time out. " - "VCL can override this default value for each backend request.", + "VCL can override this default value for each backend request and " + "backend request. This parameter does not apply to pipe.", 0, "60", "s" }, { "accept_fd_holdoff", tweak_timeout, Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/varnishd.1 2009-02-05 11:51:20 UTC (rev 3618) +++ branches/2.0/varnish-cache/bin/varnishd/varnishd.1 2009-02-05 11:57:13 UTC (rev 3619) @@ -405,6 +405,15 @@ .Pp The default is .Dv off . +.It Va between_bytes_timeout +Default timeout between bytes when receiving data from backend. +We only wait for this many seconds between bytes before giving up. +A value of 0 means it will never time out. +VCL can override this default value for each backend and backend request. +This parameter does not apply to pipe. +.Pp +The default is +.Dv 60 seconds .It Va client_http11 Whether to force the use of HTTP/1.1 when responding to client requests, or just use the same protocol version as that used by the @@ -412,6 +421,13 @@ .Pp The default is .Dv off . +.It Va connect_timeout +Default connection timeout for backend connections. +We only try to connect to the backend for this many seconds before giving up. +VCL can override this default value for each backend and backend request. +.Pp +The default is +.Dv 0.4 seconds .It Va default_ttl The default time-to-live assigned to objects if neither the backend nor the configuration assign one. @@ -427,6 +443,15 @@ backend server does not specify a content length. .Pp The default is 128 kilobytes. +.It Va first_byte_timeout +Default timeout for receiving first byte from backend. +We only wait for this many seconds for the first byte before giving up. +A value of 0 means it will never time out. +VCL can override this default value for each backend and backend request. +This parameter does not apply to pipe. +.Pp +The default is +.Dv 60 seconds .It Va group The name of an unprivileged group to which the child process should switch before it starts accepting connections. Modified: branches/2.0/varnish-cache/man/vcl.7so =================================================================== --- branches/2.0/varnish-cache/man/vcl.7so 2009-02-05 11:51:20 UTC (rev 3618) +++ branches/2.0/varnish-cache/man/vcl.7so 2009-02-05 11:57:13 UTC (rev 3619) @@ -92,6 +92,26 @@ set req.backend = www; } .Ed +.Pp +The timeout parameters can be overridden in the backend declaration. +The timeout parameters are +.Fa .connect_timeout +for the time to wait for a backend connection, +.Fa .first_byte_timeout +for the time to wait for the first byte from the backend and +.Fa .between_bytes_timeout +for time to wait between each received byte. +.Pp +These can be set in the declaration like this: +.Bd -literal -offset 4n +backend www { + .host = "www.example.com"; + .port = "http"; + .connect_timeout = 1s; + .first_byte_timeout = 5s; + .between_bytes_timeout = 2s; +} +.Ed .Ss Directors Directors choose from different backends based on health status and a per-director algorithm. @@ -516,6 +536,14 @@ .It Va bereq.http. Ns Ar header The corresponding HTTP .Ar header . +.It Va bereq.connect_timeout +The time in seconds to wait for a backend connection. +.It Va bereq.first_byte_timeout +The time in seconds to wait for the first byte from the backend. +Not available in pipe mode. +.It Va bereq.between_bytes_timeout +The time in seconds to wait between each received byte from the backend. +Not available in pipe mode. .El .Pp The following variables are available after the requested object has From tfheen at projects.linpro.no Thu Feb 5 12:14:59 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 13:14:59 +0100 (CET) Subject: r3620 - in branches/2.0/varnish-cache: bin/varnishd include lib/libvarnish Message-ID: <20090205121459.BE8E297BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 13:14:59 +0100 (Thu, 05 Feb 2009) New Revision: 3620 Added: branches/2.0/varnish-cache/lib/libvarnish/subproc.c Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c branches/2.0/varnish-cache/include/libvarnish.h branches/2.0/varnish-cache/lib/libvarnish/Makefile.am Log: Merge r3413: Move subprocess code into a library function Move the code for running stuff in a sub-process out to a library function, and give it the ability to limit how many lines of output we get back from the subprocess, in order to muzzle the C-compiler somewhat. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 11:57:13 UTC (rev 3619) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 12:14:59 UTC (rev 3620) @@ -47,7 +47,6 @@ #include "compat/asprintf.h" #endif #include "vsb.h" -#include "vlu.h" #include "vqueue.h" @@ -124,16 +123,13 @@ * Errors goes in sb; */ -static int -mgt_cc_vlu(void *priv, const char *str) +static void +run_cc(void *priv) { - struct vsb *vsb; - - vsb = priv; - vsb_printf(vsb, "C-compiler said: %s\n", str); - return (0); + (void)execl("/bin/sh", "/bin/sh", "-c", priv, NULL); } + static char * mgt_run_cc(const char *source, struct vsb *sb) { @@ -142,10 +138,8 @@ char sf[] = "./vcl.########.c"; char of[sizeof sf + 1]; char *retval; - int rv, p[2], sfd, srclen, status; - pid_t pid; + int sfd, srclen; void *dlh; - struct vlu *vlu; /* Create temporary C source file */ sfd = vtmpfile(sf); @@ -178,57 +172,8 @@ AZ(vsb_overflowed(&cmdsb)); /* XXX check vsb state */ - if (pipe(p) < 0) { - vsb_printf(sb, "%s(): pipe() failed: %s", - __func__, strerror(errno)); + if (SUB_run(sb, run_cc, cmdline, "C-compiler", 10)) { (void)unlink(sf); - return (NULL); - } - assert(p[0] > STDERR_FILENO); - assert(p[1] > STDERR_FILENO); - if ((pid = fork()) < 0) { - vsb_printf(sb, "%s(): fork() failed: %s", - __func__, strerror(errno)); - AZ(close(p[0])); - AZ(close(p[1])); - (void)unlink(sf); - return (NULL); - } - if (pid == 0) { - AZ(close(STDIN_FILENO)); - assert(open("/dev/null", O_RDONLY) == STDIN_FILENO); - assert(dup2(p[1], STDOUT_FILENO) == STDOUT_FILENO); - assert(dup2(p[1], STDERR_FILENO) == STDERR_FILENO); - /* Close all other fds */ - for (sfd = STDERR_FILENO + 1; sfd < 100; sfd++) - (void)close(sfd); - (void)execl("/bin/sh", "/bin/sh", "-c", cmdline, NULL); - _exit(1); - } - AZ(close(p[1])); - vlu = VLU_New(sb, mgt_cc_vlu, 0); - while (!VLU_Fd(p[0], vlu)) - continue; - AZ(close(p[0])); - VLU_Destroy(vlu); - (void)unlink(sf); - do { - rv = waitpid(pid, &status, 0); - if (rv < 0 && errno != EINTR) { - vsb_printf(sb, "%s(): waitpid() failed: %s", - __func__, strerror(errno)); - (void)unlink(of); - return (NULL); - } - } while (rv < 0); - if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { - vsb_printf(sb, "%s(): Compiler failed", __func__); - if (WIFEXITED(status)) - vsb_printf(sb, ", exit %d", WEXITSTATUS(status)); - if (WIFSIGNALED(status)) - vsb_printf(sb, ", signal %d", WTERMSIG(status)); - if (WCOREDUMP(status)) - vsb_printf(sb, ", core dumped"); (void)unlink(of); return (NULL); } Modified: branches/2.0/varnish-cache/include/libvarnish.h =================================================================== --- branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 11:57:13 UTC (rev 3619) +++ branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 12:14:59 UTC (rev 3620) @@ -37,6 +37,8 @@ #define NULL ((void*)0) #endif +struct vsb; + /* from libvarnish/argv.c */ void FreeArgv(char **argv); char **ParseArgv(const char *s, int flag); @@ -50,6 +52,10 @@ /* from libvarnish/num.c */ const char *str2bytes(const char *p, uintmax_t *r, uintmax_t rel); +/* from libvarnish/subproc.c */ +typedef void sub_func_f(void*); +int SUB_run(struct vsb *sb, sub_func_f *func, void *priv, const char *name, int maxlines); + /* from libvarnish/tcp.c */ /* NI_MAXHOST and NI_MAXSERV are ridiculously long for numeric format */ #define TCP_ADDRBUFSIZE 64 Modified: branches/2.0/varnish-cache/lib/libvarnish/Makefile.am =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/Makefile.am 2009-02-05 11:57:13 UTC (rev 3619) +++ branches/2.0/varnish-cache/lib/libvarnish/Makefile.am 2009-02-05 12:14:59 UTC (rev 3620) @@ -10,6 +10,7 @@ argv.c \ assert.c \ binary_heap.c \ + subproc.c \ cli.c \ cli_common.c \ crc32.c \ Copied: branches/2.0/varnish-cache/lib/libvarnish/subproc.c (from rev 3413, trunk/varnish-cache/lib/libvarnish/subproc.c) =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/subproc.c (rev 0) +++ branches/2.0/varnish-cache/lib/libvarnish/subproc.c 2009-02-05 12:14:59 UTC (rev 3620) @@ -0,0 +1,133 @@ +/*- + * 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$ + * + * Run stuff in a child process + */ + +#include "config.h" + +#include +#include +#include +#include + +#include + +#include "vsb.h" +#include "vlu.h" +#include "libvarnish.h" + +struct sub_priv { + const char *name; + struct vsb *sb; + int lines; + int maxlines; +}; + +static int +sub_vlu(void *priv, const char *str) +{ + struct sub_priv *sp; + + sp = priv; + if (!sp->lines++) + vsb_printf(sp->sb, "Message from %s:\n", sp->name); + if (sp->maxlines > 0 && sp->lines <= sp->maxlines) + vsb_printf(sp->sb, "%s\n", str); + return (0); +} + +int +SUB_run(struct vsb *sb, sub_func_f *func, void *priv, const char *name, int maxlines) +{ + int rv, p[2], sfd, status; + pid_t pid; + struct vlu *vlu; + struct sub_priv sp; + + sp.sb = sb; + sp.name = name; + sp.lines = 0; + sp.maxlines = maxlines; + + if (pipe(p) < 0) { + vsb_printf(sb, "Starting %s: pipe() failed: %s", + name, strerror(errno)); + return (-1); + } + assert(p[0] > STDERR_FILENO); + assert(p[1] > STDERR_FILENO); + if ((pid = fork()) < 0) { + vsb_printf(sb, "Starting %s: fork() failed: %s", + name, strerror(errno)); + AZ(close(p[0])); + AZ(close(p[1])); + return (-1); + } + if (pid == 0) { + AZ(close(STDIN_FILENO)); + assert(open("/dev/null", O_RDONLY) == STDIN_FILENO); + assert(dup2(p[1], STDOUT_FILENO) == STDOUT_FILENO); + assert(dup2(p[1], STDERR_FILENO) == STDERR_FILENO); + /* Close all other fds */ + for (sfd = STDERR_FILENO + 1; sfd < 100; sfd++) + (void)close(sfd); + func(priv); + _exit(1); + } + AZ(close(p[1])); + vlu = VLU_New(&sp, sub_vlu, 0); + while (!VLU_Fd(p[0], vlu)) + continue; + AZ(close(p[0])); + VLU_Destroy(vlu); + if (sp.lines > sp.maxlines) + vsb_printf(sb, "[%d lines truncated]\n", + sp.lines - sp.maxlines); + do { + rv = waitpid(pid, &status, 0); + if (rv < 0 && errno != EINTR) { + vsb_printf(sb, "Running %s: waitpid() failed: %s", + name, strerror(errno)); + return (-1); + } + } while (rv < 0); + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + vsb_printf(sb, "Running %s failed", name); + if (WIFEXITED(status)) + vsb_printf(sb, ", exit %d", WEXITSTATUS(status)); + if (WIFSIGNALED(status)) + vsb_printf(sb, ", signal %d", WTERMSIG(status)); + if (WCOREDUMP(status)) + vsb_printf(sb, ", core dumped"); + return (-1); + } + return (0); +} From tfheen at projects.linpro.no Thu Feb 5 12:19:36 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 13:19:36 +0100 (CET) Subject: r3621 - in branches/2.0/varnish-cache: include lib/libvarnish lib/libvcl Message-ID: <20090205121936.1B0281F7470@projects.linpro.no> Author: tfheen Date: 2009-02-05 13:19:35 +0100 (Thu, 05 Feb 2009) New Revision: 3621 Modified: branches/2.0/varnish-cache/include/libvarnish.h branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c Log: Merge r3414: Add a vreadfile() utility function, which reads a file into malloc'ed memory Modified: branches/2.0/varnish-cache/include/libvarnish.h =================================================================== --- branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 12:14:59 UTC (rev 3620) +++ branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 12:19:35 UTC (rev 3621) @@ -86,6 +86,7 @@ /* from libvarnish/vtmpfile.c */ int vtmpfile(char *); +char *vreadfile(int fd); /* * assert(), AN() and AZ() are static checks that should not happen. Modified: branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c 2009-02-05 12:14:59 UTC (rev 3620) +++ branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c 2009-02-05 12:19:35 UTC (rev 3621) @@ -35,7 +35,10 @@ #include #include #include +#include +#include + #include "libvarnish.h" int @@ -74,3 +77,21 @@ } /* not reached */ } + +char * +vreadfile(int fd) +{ + struct stat st; + char *f; + int i; + + assert(0 == fstat(fd, &st)); + if (!S_ISREG(st.st_mode)) + return (NULL); + f = malloc(st.st_size + 1); + assert(f != NULL); + i = read(fd, f, st.st_size); + assert(i == st.st_size); + f[i] = '\0'; + return (f); +} Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 12:14:59 UTC (rev 3620) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 12:19:35 UTC (rev 3621) @@ -402,8 +402,6 @@ vcc_file_source(struct vsb *sb, const char *fn, int fd) { char *f; - int i; - struct stat st; struct source *sp; if (fd < 0) { @@ -414,19 +412,10 @@ return (NULL); } } - assert(0 == fstat(fd, &st)); - if (! S_ISREG(st.st_mode)) { - vsb_printf(sb, "File '%s' is not a regular file\n", fn); - AZ(close(fd)); - return (NULL); - } - f = malloc(st.st_size + 1); - assert(f != NULL); - i = read(fd, f, st.st_size); - assert(i == st.st_size); + f = vreadfile(fd); + AN(f); AZ(close(fd)); - f[i] = '\0'; - sp = vcc_new_source(f, f + i, fn); + sp = vcc_new_source(f, NULL, fn); sp->freeit = f; return (sp); } From tfheen at projects.linpro.no Thu Feb 5 12:23:06 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 13:23:06 +0100 (CET) Subject: r3622 - in branches/2.0/varnish-cache: bin/varnishd include lib/libvarnish lib/libvcl Message-ID: <20090205122306.89A221F7470@projects.linpro.no> Author: tfheen Date: 2009-02-05 13:23:06 +0100 (Thu, 05 Feb 2009) New Revision: 3622 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt.h branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c branches/2.0/varnish-cache/bin/varnishd/varnishd.c branches/2.0/varnish-cache/include/libvarnish.h branches/2.0/varnish-cache/include/libvcl.h branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c Log: Merge r3415: Simplify how we manage the -f argument: The VCL file specified to -f must be read relative to the directory from which varnishd is started, before we chdir to the workdir. We used to deal with this by opening the file and passing the file handle down. It's simpler to just read the file and pass the actual VCL code down. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt.h 2009-02-05 12:19:35 UTC (rev 3621) +++ branches/2.0/varnish-cache/bin/varnishd/mgt.h 2009-02-05 12:23:06 UTC (rev 3622) @@ -58,7 +58,7 @@ /* mgt_vcc.c */ void mgt_vcc_init(void); -int mgt_vcc_default(const char *bflag, const char *fflag, int f_fd, int Cflag); +int mgt_vcc_default(const char *bflag, char *vcl, int Cflag); int mgt_push_vcls_and_start(unsigned *status, char **p); int mgt_has_vcl(void); extern char *mgt_cc_cmd; Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 12:19:35 UTC (rev 3621) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 12:23:06 UTC (rev 3622) @@ -201,40 +201,27 @@ /*--------------------------------------------------------------------*/ static char * -mgt_VccCompile(struct vsb *sb, const char *b, const char *e, int C_flag) +mgt_VccCompile(struct vsb **sb, const char *b, int C_flag) { char *csrc, *vf = NULL; - csrc = VCC_Compile(sb, b, e); - if (csrc != NULL) { - if (C_flag) - (void)fputs(csrc, stdout); - vf = mgt_run_cc(csrc, sb); - if (C_flag && vf != NULL) - AZ(unlink(vf)); - free(csrc); - } - return (vf); -} + *sb = vsb_newauto(); + XXXAN(*sb); + csrc = VCC_Compile(*sb, b, NULL); -static char * -mgt_VccCompileFile(struct vsb *sb, const char *fn, int C_flag, int fd) -{ - char *csrc, *vf = NULL; - - csrc = VCC_CompileFile(sb, fn, fd); if (csrc != NULL) { if (C_flag) (void)fputs(csrc, stdout); - vf = mgt_run_cc(csrc, sb); + vf = mgt_run_cc(csrc, *sb); if (C_flag && vf != NULL) AZ(unlink(vf)); free(csrc); } + vsb_finish(*sb); + AZ(vsb_overflowed(*sb)); return (vf); } - /*--------------------------------------------------------------------*/ static struct vclprog * @@ -290,16 +277,15 @@ /*--------------------------------------------------------------------*/ int -mgt_vcc_default(const char *b_arg, const char *f_arg, int f_fd, int C_flag) +mgt_vcc_default(const char *b_arg, char *vcl, int C_flag) { char *addr, *port; - char *buf, *vf; + char *vf; struct vsb *sb; struct vclprog *vp; - sb = vsb_newauto(); - XXXAN(sb); if (b_arg != NULL) { + AZ(vcl); /* * XXX: should do a "HEAD /" on the -b argument to see that * XXX: it even works. On the other hand, we should do that @@ -318,26 +304,21 @@ */ free(port); fprintf(stderr, "invalid backend address\n"); - vsb_delete(sb); return (1); } - buf = NULL; - asprintf(&buf, + asprintf(&vcl, "backend default {\n" " .host = \"%s\";\n" " .port = \"%s\";\n" "}\n", addr, port ? port : "http"); free(addr); free(port); - AN(buf); - vf = mgt_VccCompile(sb, buf, NULL, C_flag); - free(buf); - } else { - vf = mgt_VccCompileFile(sb, f_arg, C_flag, f_fd); + AN(vcl); } - vsb_finish(sb); - AZ(vsb_overflowed(sb)); + + vf = mgt_VccCompile(&sb, vcl, C_flag); + free(vcl); if (vsb_len(sb) > 0) fprintf(stderr, "%s", vsb_data(sb)); vsb_delete(sb); @@ -432,11 +413,7 @@ return; } - sb = vsb_newauto(); - XXXAN(sb); - vf = mgt_VccCompile(sb, av[3], NULL, 0); - vsb_finish(sb); - AZ(vsb_overflowed(sb)); + vf = mgt_VccCompile(&sb, av[3], 0); if (vsb_len(sb) > 0) cli_out(cli, "%s", vsb_data(sb)); vsb_delete(sb); @@ -459,7 +436,7 @@ void mcf_config_load(struct cli *cli, const char * const *av, void *priv) { - char *vf; + char *vf, *vcl; struct vsb *sb; unsigned status; char *p = NULL; @@ -473,11 +450,16 @@ return; } - sb = vsb_newauto(); - XXXAN(sb); - vf = mgt_VccCompileFile(sb, av[3], 0, -1); - vsb_finish(sb); - AZ(vsb_overflowed(sb)); + vcl = vreadfile(av[3]); + if (vcl == NULL) { + cli_out(cli, "Cannot open '%s'", av[3]); + cli_result(cli, CLIS_PARAM); + return; + } + + vf = mgt_VccCompile(&sb, vcl, 0); + free(vcl); + if (vsb_len(sb) > 0) cli_out(cli, "%s", vsb_data(sb)); vsb_delete(sb); Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-05 12:19:35 UTC (rev 3621) +++ branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-05 12:23:06 UTC (rev 3622) @@ -424,14 +424,13 @@ const char *l_arg = "80m"; uintmax_t l_size; const char *q; - int f_fd = -1; const char *h_arg = "classic"; const char *n_arg = NULL; const char *P_arg = NULL; const char *s_arg = "file"; int s_arg_given = 0; const char *T_arg = NULL; - char *p; + char *p, *vcl = NULL; struct cli cli[1]; struct pidfh *pfh = NULL; char dirname[1024]; @@ -567,9 +566,9 @@ } if (f_arg != NULL) { - f_fd = open(f_arg, O_RDONLY); - if (f_fd < 0) { - fprintf(stderr, "Cannot open '%s': %s\n", + vcl = vreadfile(f_arg); + if (vcl == NULL) { + fprintf(stderr, "Cannot read '%s': %s\n", f_arg, strerror(errno)); exit(1); } @@ -606,7 +605,7 @@ } if (b_arg != NULL || f_arg != NULL) - if (mgt_vcc_default(b_arg, f_arg, f_fd, C_flag)) + if (mgt_vcc_default(b_arg, vcl, C_flag)) exit (2); if (C_flag) Modified: branches/2.0/varnish-cache/include/libvarnish.h =================================================================== --- branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 12:19:35 UTC (rev 3621) +++ branches/2.0/varnish-cache/include/libvarnish.h 2009-02-05 12:23:06 UTC (rev 3622) @@ -86,7 +86,7 @@ /* from libvarnish/vtmpfile.c */ int vtmpfile(char *); -char *vreadfile(int fd); +char *vreadfile(const char *fn); /* * assert(), AN() and AZ() are static checks that should not happen. Modified: branches/2.0/varnish-cache/include/libvcl.h =================================================================== --- branches/2.0/varnish-cache/include/libvcl.h 2009-02-05 12:19:35 UTC (rev 3621) +++ branches/2.0/varnish-cache/include/libvcl.h 2009-02-05 12:23:06 UTC (rev 3622) @@ -30,7 +30,6 @@ */ char *VCC_Compile(struct vsb *sb, const char *b, const char *e); -char *VCC_CompileFile(struct vsb *sb, const char *fn, int fd); void VCC_InitCompile(const char *default_vcl); Modified: branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c 2009-02-05 12:19:35 UTC (rev 3621) +++ branches/2.0/varnish-cache/lib/libvarnish/vtmpfile.c 2009-02-05 12:23:06 UTC (rev 3622) @@ -78,8 +78,8 @@ /* not reached */ } -char * -vreadfile(int fd) +static char * +vreadfd(int fd) { struct stat st; char *f; @@ -95,3 +95,19 @@ f[i] = '\0'; return (f); } + +char * +vreadfile(const char *fn) +{ + int fd, err; + char *r; + + fd = open(fn, O_RDONLY); + if (fd < 0) + return (NULL); + r = vreadfd(fd); + err = errno; + AZ(close(fd)); + errno = err; + return (r); +} Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 12:19:35 UTC (rev 3621) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-05 12:23:06 UTC (rev 3622) @@ -399,22 +399,17 @@ /*--------------------------------------------------------------------*/ static struct source * -vcc_file_source(struct vsb *sb, const char *fn, int fd) +vcc_file_source(struct vsb *sb, const char *fn) { char *f; struct source *sp; - if (fd < 0) { - fd = open(fn, O_RDONLY); - if (fd < 0) { - vsb_printf(sb, "Cannot open file '%s': %s\n", - fn, strerror(errno)); - return (NULL); - } + f = vreadfile(fn); + if (f == NULL) { + vsb_printf(sb, "Cannot read file '%s': %s\n", + fn, strerror(errno)); + return (NULL); } - f = vreadfile(fd); - AN(f); - AZ(close(fd)); sp = vcc_new_source(f, NULL, fn); sp->freeit = f; return (sp); @@ -450,7 +445,7 @@ } assert(t2 != NULL); - sp = vcc_file_source(tl->sb, t1->dec, -1); + sp = vcc_file_source(tl->sb, t1->dec); if (sp == NULL) { vcc_ErrWhere(tl, t1); return; @@ -668,24 +663,6 @@ } /*-------------------------------------------------------------------- - * Compile the VCL code from the file named. Error messages, if any - * are formatted into the vsb. - */ - -char * -VCC_CompileFile(struct vsb *sb, const char *fn, int fd) -{ - struct source *sp; - char *r; - - sp = vcc_file_source(sb, fn, fd); - if (sp == NULL) - return (NULL); - r = vcc_CompileSource(sb, sp); - return (r); -} - -/*-------------------------------------------------------------------- * Initialize the compiler and register the default VCL code for later * compilation runs. */ From tfheen at projects.linpro.no Thu Feb 5 12:26:37 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 13:26:37 +0100 (CET) Subject: r3623 - branches/2.0/varnish-cache/lib/libvarnish Message-ID: <20090205122637.205B697C25@projects.linpro.no> Author: tfheen Date: 2009-02-05 13:26:36 +0100 (Thu, 05 Feb 2009) New Revision: 3623 Modified: branches/2.0/varnish-cache/lib/libvarnish/subproc.c Log: Merge r3416: Make it possible to supress all or no lines of output Modified: branches/2.0/varnish-cache/lib/libvarnish/subproc.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/subproc.c 2009-02-05 12:23:06 UTC (rev 3622) +++ branches/2.0/varnish-cache/lib/libvarnish/subproc.c 2009-02-05 12:26:36 UTC (rev 3623) @@ -59,7 +59,7 @@ sp = priv; if (!sp->lines++) vsb_printf(sp->sb, "Message from %s:\n", sp->name); - if (sp->maxlines > 0 && sp->lines <= sp->maxlines) + if (sp->maxlines < 0 || sp->lines <= sp->maxlines) vsb_printf(sp->sb, "%s\n", str); return (0); } @@ -108,7 +108,7 @@ continue; AZ(close(p[0])); VLU_Destroy(vlu); - if (sp.lines > sp.maxlines) + if (sp.maxlines >= 0 && sp.lines > sp.maxlines) vsb_printf(sb, "[%d lines truncated]\n", sp.lines - sp.maxlines); do { From tfheen at projects.linpro.no Thu Feb 5 12:32:47 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 13:32:47 +0100 (CET) Subject: r3624 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205123247.1497497C25@projects.linpro.no> Author: tfheen Date: 2009-02-05 13:32:46 +0100 (Thu, 05 Feb 2009) New Revision: 3624 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c Log: Merge r3417: Also run the VCL->C compiler stage in a sub-process. This isolates the mangement process from the compilers bugs and memory usage. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 12:26:36 UTC (rev 3623) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-05 12:32:46 UTC (rev 3624) @@ -84,12 +84,15 @@ /* * Prepare the compiler command line */ -static void -mgt_make_cc_cmd(struct vsb *sb, const char *sf, const char *of) +static struct vsb * +mgt_make_cc_cmd(const char *sf, const char *of) { + struct vsb *sb; int pct; char *p; + sb = vsb_newauto(); + XXXAN(sb); for (p = mgt_cc_cmd, pct = 0; *p; ++p) { if (pct) { switch (*p) { @@ -116,11 +119,13 @@ } if (pct) vsb_putc(sb, '%'); + vsb_finish(sb); + AZ(vsb_overflowed(sb)); + return (sb); } /*-------------------------------------------------------------------- - * Invoke system C compiler on source and return resulting dlfile. - * Errors goes in sb; + * Invoke system C compiler in a sub-process */ static void @@ -129,60 +134,114 @@ (void)execl("/bin/sh", "/bin/sh", "-c", priv, NULL); } +/*-------------------------------------------------------------------- + * Invoke system VCC compiler in a sub-process + */ +struct vcc_priv { + char *sf; + const char *vcl; +}; + +static void +run_vcc(void *priv) +{ + char *csrc; + struct vsb *sb; + struct vcc_priv *vp; + int fd, i, l; + + vp = priv; + sb = vsb_newauto(); + XXXAN(sb); + csrc = VCC_Compile(sb, vp->vcl, NULL); + vsb_finish(sb); + AZ(vsb_overflowed(sb)); + if (vsb_len(sb)) + printf("%s", vsb_data(sb)); + vsb_delete(sb); + if (csrc == NULL) + exit (1); + + fd = open(vp->sf, O_WRONLY); + if (fd < 0) { + fprintf(stderr, "Cannot open %s", vp->sf); + exit (1); + } + l = strlen(csrc); + i = write(fd, csrc, l); + if (i != l) { + fprintf(stderr, "Cannot write %s", vp->sf); + exit (1); + } + close(fd); + free(csrc); + exit (0); +} + +/*-------------------------------------------------------------------- + * Compile a VCL program, return shared object, errors in sb. + */ + static char * -mgt_run_cc(const char *source, struct vsb *sb) +mgt_run_cc(const char *vcl, struct vsb *sb, int C_flag) { - char cmdline[1024]; - struct vsb cmdsb; + char *csrc; + struct vsb *cmdsb; char sf[] = "./vcl.########.c"; char of[sizeof sf + 1]; char *retval; - int sfd, srclen; + int sfd, i; void *dlh; + struct vcc_priv vp; /* Create temporary C source file */ sfd = vtmpfile(sf); if (sfd < 0) { - vsb_printf(sb, - "%s(): failed to create %s: %s", - __func__, sf, strerror(errno)); + vsb_printf(sb, "Failed to create %s: %s", sf, strerror(errno)); return (NULL); } - srclen = strlen(source); - if (write(sfd, source, srclen) != srclen) { - vsb_printf(sb, - "Failed to write C source to file: %s", - strerror(errno)); - AZ(unlink(sf)); - AZ(close(sfd)); + AZ(close(sfd)); + + /* Run the VCC compiler in a sub-process */ + vp.sf = sf; + vp.vcl = vcl; + if (SUB_run(sb, run_vcc, &vp, "VCC-compiler", -1)) { + (void)unlink(sf); return (NULL); } - AZ(close(sfd)); - /* Name the output shared library by overwriting the final 'c' */ + if (C_flag) { + csrc = vreadfile(sf); + (void)fputs(csrc, stdout); + free(csrc); + } + + /* Name the output shared library by "s/[.]c$/[.]so/" */ memcpy(of, sf, sizeof sf); assert(sf[sizeof sf - 2] == 'c'); of[sizeof sf - 2] = 's'; of[sizeof sf - 1] = 'o'; of[sizeof sf] = '\0'; - AN(vsb_new(&cmdsb, cmdline, sizeof cmdline, 0)); - mgt_make_cc_cmd(&cmdsb, sf, of); - vsb_finish(&cmdsb); - AZ(vsb_overflowed(&cmdsb)); - /* XXX check vsb state */ - if (SUB_run(sb, run_cc, cmdline, "C-compiler", 10)) { - (void)unlink(sf); + /* Build the C-compiler command line */ + cmdsb = mgt_make_cc_cmd(sf, of); + + /* Run the C-compiler in a sub-shell */ + i = SUB_run(sb, run_cc, vsb_data(cmdsb), "C-compiler", 10); + + (void)unlink(sf); + vsb_delete(cmdsb); + + if (i) { (void)unlink(of); return (NULL); } - /* Next, try to load the object into the management process */ + /* Try to load the object into the management process */ if ((dlh = dlopen(of, RTLD_NOW | RTLD_LOCAL)) == NULL) { vsb_printf(sb, - "%s(): failed to load compiled VCL program:\n %s", - __func__, dlerror()); + "Compiled VCL program failed to load:\n %s", dlerror()); (void)unlink(of); return (NULL); } @@ -203,20 +262,11 @@ static char * mgt_VccCompile(struct vsb **sb, const char *b, int C_flag) { - char *csrc, *vf = NULL; + char *vf = NULL; *sb = vsb_newauto(); XXXAN(*sb); - csrc = VCC_Compile(*sb, b, NULL); - - if (csrc != NULL) { - if (C_flag) - (void)fputs(csrc, stdout); - vf = mgt_run_cc(csrc, *sb); - if (C_flag && vf != NULL) - AZ(unlink(vf)); - free(csrc); - } + vf = mgt_run_cc(b, *sb, C_flag); vsb_finish(*sb); AZ(vsb_overflowed(*sb)); return (vf); @@ -322,8 +372,11 @@ if (vsb_len(sb) > 0) fprintf(stderr, "%s", vsb_data(sb)); vsb_delete(sb); - if (C_flag) + if (C_flag) { + if (vf != NULL) + AZ(unlink(vf)); return (0); + } if (vf == NULL) { fprintf(stderr, "\nVCL compilation failed\n"); return (1); From tfheen at projects.linpro.no Thu Feb 5 12:36:41 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 13:36:41 +0100 (CET) Subject: r3625 - in branches/2.0/varnish-cache: . bin/varnishlog include include/compat lib/libvarnishcompat Message-ID: <20090205123641.EA97C97C25@projects.linpro.no> Author: tfheen Date: 2009-02-05 13:36:41 +0100 (Thu, 05 Feb 2009) New Revision: 3625 Removed: branches/2.0/varnish-cache/include/compat/vis.h branches/2.0/varnish-cache/lib/libvarnishcompat/vis.c Modified: branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c branches/2.0/varnish-cache/configure.ac branches/2.0/varnish-cache/include/Makefile.am branches/2.0/varnish-cache/lib/libvarnishcompat/Makefile.am Log: Merge r3421: Eliminate and its compat version, it is unused. Modified: branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c 2009-02-05 12:32:46 UTC (rev 3624) +++ branches/2.0/varnish-cache/bin/varnishlog/varnishlog.c 2009-02-05 12:36:41 UTC (rev 3625) @@ -47,12 +47,6 @@ #include "compat/daemon.h" #endif -#ifdef HAVE_VIS_H -#include -#else -#include "compat/vis.h" -#endif - #include "vsb.h" #include "vpf.h" Modified: branches/2.0/varnish-cache/configure.ac =================================================================== --- branches/2.0/varnish-cache/configure.ac 2009-02-05 12:32:46 UTC (rev 3624) +++ branches/2.0/varnish-cache/configure.ac 2009-02-05 12:36:41 UTC (rev 3625) @@ -80,7 +80,6 @@ AC_CHECK_HEADERS([stddef.h]) AC_CHECK_HEADERS([stdlib.h]) AC_CHECK_HEADERS([unistd.h]) -AC_CHECK_HEADERS([vis.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -166,7 +165,6 @@ AC_CHECK_FUNCS([srandomdev]) AC_CHECK_FUNCS([strlcat strlcpy]) AC_CHECK_FUNCS([strndup]) -AC_CHECK_FUNCS([vis strvis strvisx]) AC_CHECK_FUNCS([daemon]) AC_SYS_LARGEFILE Modified: branches/2.0/varnish-cache/include/Makefile.am =================================================================== --- branches/2.0/varnish-cache/include/Makefile.am 2009-02-05 12:32:46 UTC (rev 3624) +++ branches/2.0/varnish-cache/include/Makefile.am 2009-02-05 12:36:41 UTC (rev 3625) @@ -20,7 +20,6 @@ compat/strlcpy.h \ compat/strndup.h \ compat/vasprintf.h \ - compat/vis.h \ flopen.h \ http_headers.h \ libvarnish.h \ Deleted: branches/2.0/varnish-cache/include/compat/vis.h =================================================================== --- branches/2.0/varnish-cache/include/compat/vis.h 2009-02-05 12:32:46 UTC (rev 3624) +++ branches/2.0/varnish-cache/include/compat/vis.h 2009-02-05 12:36:41 UTC (rev 3625) @@ -1,87 +0,0 @@ -/*- - * Copyright (c) 1990, 1993 - * The Regents of the University of California. 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS 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. - * - * @(#)vis.h 8.1 (Berkeley) 6/2/93 - * $FreeBSD: src/include/vis.h,v 1.11 2003/10/30 10:40:49 phk Exp $ - * $Id$ - */ - -#ifndef _VIS_H_ -#define _VIS_H_ - -/* - * to select alternate encoding format - */ -#define VIS_OCTAL 0x01 /* use octal \ddd format */ -#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */ - -/* - * to alter set of characters encoded (default is to encode all - * non-graphic except space, tab, and newline). - */ -#define VIS_SP 0x04 /* also encode space */ -#define VIS_TAB 0x08 /* also encode tab */ -#define VIS_NL 0x10 /* also encode newline */ -#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) -#define VIS_SAFE 0x20 /* only encode "unsafe" characters */ - -/* - * other - */ -#define VIS_NOSLASH 0x40 /* inhibit printing '\' */ -#define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */ -#define VIS_GLOB 0x100 /* encode glob(3) magics */ - -/* - * unvis return codes - */ -#define UNVIS_VALID 1 /* character valid */ -#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ -#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ -#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ -#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ - -/* - * unvis flags - */ -#define UNVIS_END 1 /* no more characters */ - -#ifdef __cplusplus -extern "C" { -#endif -char *vis(char *, int, int, int); -int strvis(char *, const char *, int); -int strvisx(char *, const char *, size_t, int); -int strunvis(char *, const char *); -int strunvisx(char *, const char *, int); -int unvis(char *, int, int *, int); -#ifdef __cplusplus -}; -#endif - -#endif /* !_VIS_H_ */ Modified: branches/2.0/varnish-cache/lib/libvarnishcompat/Makefile.am =================================================================== --- branches/2.0/varnish-cache/lib/libvarnishcompat/Makefile.am 2009-02-05 12:32:46 UTC (rev 3624) +++ branches/2.0/varnish-cache/lib/libvarnishcompat/Makefile.am 2009-02-05 12:36:41 UTC (rev 3625) @@ -14,5 +14,4 @@ srandomdev.c \ strlcat.c \ strlcpy.c \ - strndup.c \ - vis.c + strndup.c Deleted: branches/2.0/varnish-cache/lib/libvarnishcompat/vis.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnishcompat/vis.c 2009-02-05 12:32:46 UTC (rev 3624) +++ branches/2.0/varnish-cache/lib/libvarnishcompat/vis.c 2009-02-05 12:36:41 UTC (rev 3625) @@ -1,212 +0,0 @@ -/*- - * Copyright (c) 1989, 1993 - * The Regents of the University of California. 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS 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. - * - * @(#)vis.c 8.1 (Berkeley) 7/19/93 - * $FreeBSD: src/lib/libc/gen/vis.c,v 1.13 2003/10/30 12:41:50 phk Exp $ - * $Id$ - */ - -#include "config.h" - -#if !defined(HAVE_VIS) || !defined(HAVE_STRVIS) || !defined(HAVE_STRVISX) - -#include -#include -#include -#include - -#include "compat/vis.h" - -#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') - -/* - * vis - visually encode characters - */ -#ifndef HAVE_VIS -char * -vis(dst, c, flag, nextc) - char *dst; - int c, nextc; - int flag; -{ - c = (unsigned char)c; - - if (flag & VIS_HTTPSTYLE) { - /* Described in RFC 1808 */ - if (!(isalnum(c) /* alpha-numeric */ - /* safe */ - || c == '$' || c == '-' || c == '_' || c == '.' || c == '+' - /* extra */ - || c == '!' || c == '*' || c == '\'' || c == '(' - || c == ')' || c == ',')) { - *dst++ = '%'; - snprintf(dst, 4, (c < 16 ? "0%X" : "%X"), c); - dst += 2; - goto done; - } - } - - if ((flag & VIS_GLOB) && - (c == '*' || c == '?' || c == '[' || c == '#')) - ; - else if (isgraph(c) || - ((flag & VIS_SP) == 0 && c == ' ') || - ((flag & VIS_TAB) == 0 && c == '\t') || - ((flag & VIS_NL) == 0 && c == '\n') || - ((flag & VIS_SAFE) && (c == '\b' || c == '\007' || c == '\r'))) { - *dst++ = c; - if (c == '\\' && (flag & VIS_NOSLASH) == 0) - *dst++ = '\\'; - *dst = '\0'; - return (dst); - } - - if (flag & VIS_CSTYLE) { - switch(c) { - case '\n': - *dst++ = '\\'; - *dst++ = 'n'; - goto done; - case '\r': - *dst++ = '\\'; - *dst++ = 'r'; - goto done; - case '\b': - *dst++ = '\\'; - *dst++ = 'b'; - goto done; - case '\a': - *dst++ = '\\'; - *dst++ = 'a'; - goto done; - case '\v': - *dst++ = '\\'; - *dst++ = 'v'; - goto done; - case '\t': - *dst++ = '\\'; - *dst++ = 't'; - goto done; - case '\f': - *dst++ = '\\'; - *dst++ = 'f'; - goto done; - case ' ': - *dst++ = '\\'; - *dst++ = 's'; - goto done; - case '\0': - *dst++ = '\\'; - *dst++ = '0'; - if (isoctal(nextc)) { - *dst++ = '0'; - *dst++ = '0'; - } - goto done; - } - } - if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) { - *dst++ = '\\'; - *dst++ = ((u_char)c >> 6 & 07) + '0'; - *dst++ = ((u_char)c >> 3 & 07) + '0'; - *dst++ = ((u_char)c & 07) + '0'; - goto done; - } - if ((flag & VIS_NOSLASH) == 0) - *dst++ = '\\'; - if (c & 0200) { - c &= 0177; - *dst++ = 'M'; - } - if (iscntrl(c)) { - *dst++ = '^'; - if (c == 0177) - *dst++ = '?'; - else - *dst++ = c + '@'; - } else { - *dst++ = '-'; - *dst++ = c; - } -done: - *dst = '\0'; - return (dst); -} -#endif - -/* - * strvis, strvisx - visually encode characters from src into dst - * - * Dst must be 4 times the size of src to account for possible - * expansion. The length of dst, not including the trailing NUL, - * is returned. - * - * Strvisx encodes exactly len bytes from src into dst. - * This is useful for encoding a block of data. - */ -#ifndef HAVE_STRVIS -int -strvis(dst, src, flag) - char *dst; - const char *src; - int flag; -{ - char c; - char *start; - - for (start = dst; (c = *src); ) - dst = vis(dst, c, flag, *++src); - *dst = '\0'; - return (dst - start); -} -#endif - -#ifndef HAVE_STRVISX -int -strvisx(dst, src, len, flag) - char *dst; - const char *src; - size_t len; - int flag; -{ - int c; - char *start; - - for (start = dst; len > 1; len--) { - c = *src; - dst = vis(dst, c, flag, *++src); - } - if (len) - dst = vis(dst, *src, flag, '\0'); - *dst = '\0'; - - return (dst - start); -} -#endif - -#endif From tfheen at projects.linpro.no Thu Feb 5 12:40:54 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 13:40:54 +0100 (CET) Subject: r3626 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205124054.9C5BF1F74BE@projects.linpro.no> Author: tfheen Date: 2009-02-05 13:40:54 +0100 (Thu, 05 Feb 2009) New Revision: 3626 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_response.c Log: Merge r3422: Do not count chunked encoding headers in stat.hdrbytes. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_response.c 2009-02-05 12:36:41 UTC (rev 3625) +++ branches/2.0/varnish-cache/bin/varnishd/cache_response.c 2009-02-05 12:40:54 UTC (rev 3626) @@ -146,8 +146,7 @@ } else if (sp->wantbody) { if (sp->esis > 0 && sp->http->protover >= 1.1) { sprintf(lenbuf, "%x\r\n", sp->obj->len); - sp->wrk->acct.hdrbytes += - WRK_Write(sp->wrk, lenbuf, -1); + (void)WRK_Write(sp->wrk, lenbuf, -1); } VTAILQ_FOREACH(st, &sp->obj->store, list) { @@ -171,11 +170,11 @@ } #endif /* SENDFILE_WORKS */ VSL_stats->n_objwrite++; - WRK_Write(sp->wrk, st->ptr, st->len); + (void)WRK_Write(sp->wrk, st->ptr, st->len); } assert(u == sp->obj->len); if (sp->esis > 0 && sp->http->protover >= 1.1) - WRK_Write(sp->wrk, "\r\n", -1); + (void)WRK_Write(sp->wrk, "\r\n", -1); } if (WRK_Flush(sp->wrk)) vca_close_session(sp, "remote closed"); From tfheen at projects.linpro.no Thu Feb 5 12:44:21 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 13:44:21 +0100 (CET) Subject: r3627 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205124421.9C23A1F74BE@projects.linpro.no> Author: tfheen Date: 2009-02-05 13:44:21 +0100 (Thu, 05 Feb 2009) New Revision: 3627 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Merge r3423: Count ESI processed objects in acct.bodybytes Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-05 12:40:54 UTC (rev 3626) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-05 12:44:21 UTC (rev 3627) @@ -800,12 +800,14 @@ struct object *obj; VTAILQ_FOREACH(eb, &sp->obj->esibits, list) { + assert(sp->wrk->wfd = &sp->fd); if (Tlen(eb->verbatim)) { if (sp->http->protover >= 1.1) - WRK_Write(sp->wrk, eb->chunk_length, -1); - WRK_Write(sp->wrk, eb->verbatim.b, Tlen(eb->verbatim)); + (void)WRK_Write(sp->wrk, eb->chunk_length, -1); + sp->wrk->acct.bodybytes += WRK_Write(sp->wrk, + eb->verbatim.b, Tlen(eb->verbatim)); if (sp->http->protover >= 1.1) - WRK_Write(sp->wrk, "\r\n", -1); + (void)WRK_Write(sp->wrk, "\r\n", -1); } if (eb->include.b == NULL || sp->esis >= params->max_esi_includes) @@ -814,9 +816,10 @@ /* * We flush here, because the next transaction is * quite likely to take some time, so we should get - * as many bits to the client as we can already + * as many bits to the client as we can already. */ - WRK_Flush(sp->wrk); + if (WRK_Flush(sp->wrk)) + break; sp->esis++; obj = sp->obj; @@ -859,8 +862,9 @@ sp->obj = obj; } + assert(sp->wrk->wfd = &sp->fd); if (sp->esis == 0 && sp->http->protover >= 1.1) - WRK_Write(sp->wrk, "0\r\n\r\n", -1); + (void)WRK_Write(sp->wrk, "0\r\n\r\n", -1); } /*--------------------------------------------------------------------*/ From tfheen at projects.linpro.no Thu Feb 5 12:47:35 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 13:47:35 +0100 (CET) Subject: r3628 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205124735.0366A1F74BE@projects.linpro.no> Author: tfheen Date: 2009-02-05 13:47:34 +0100 (Thu, 05 Feb 2009) New Revision: 3628 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Merge r3424: Use == for comparison. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-05 12:44:21 UTC (rev 3627) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-05 12:47:34 UTC (rev 3628) @@ -800,7 +800,7 @@ struct object *obj; VTAILQ_FOREACH(eb, &sp->obj->esibits, list) { - assert(sp->wrk->wfd = &sp->fd); + assert(sp->wrk->wfd == &sp->fd); if (Tlen(eb->verbatim)) { if (sp->http->protover >= 1.1) (void)WRK_Write(sp->wrk, eb->chunk_length, -1); @@ -862,7 +862,7 @@ sp->obj = obj; } - assert(sp->wrk->wfd = &sp->fd); + assert(sp->wrk->wfd == &sp->fd); if (sp->esis == 0 && sp->http->protover >= 1.1) (void)WRK_Write(sp->wrk, "0\r\n\r\n", -1); } From tfheen at projects.linpro.no Thu Feb 5 12:50:51 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 13:50:51 +0100 (CET) Subject: r3629 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205125051.1F5781F74C8@projects.linpro.no> Author: tfheen Date: 2009-02-05 13:50:50 +0100 (Thu, 05 Feb 2009) New Revision: 3629 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c Log: Merge r3425: Log write errors under SLT_Debug. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 12:47:34 UTC (rev 3628) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 12:50:50 UTC (rev 3629) @@ -126,6 +126,9 @@ i = writev(*w->wfd, w->iov, w->niov); if (i != w->liov) w->werr++; + WSL(w, SLT_Debug, *w->wfd, + "Write error, len = %d/%d, errno = %s", + i, w->liov, strerror(errno)); } w->liov = 0; w->niov = 0; From tfheen at projects.linpro.no Thu Feb 5 13:03:15 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 14:03:15 +0100 (CET) Subject: r3630 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205130315.4B4671F74BE@projects.linpro.no> Author: tfheen Date: 2009-02-05 14:03:15 +0100 (Thu, 05 Feb 2009) New Revision: 3630 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c Log: Merge r3427: Only emit debug message for writes that fail Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 12:50:50 UTC (rev 3629) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 13:03:15 UTC (rev 3630) @@ -124,11 +124,12 @@ CHECK_OBJ_NOTNULL(w, WORKER_MAGIC); if (*w->wfd >= 0 && w->niov > 0 && w->werr == 0) { i = writev(*w->wfd, w->iov, w->niov); - if (i != w->liov) + if (i != w->liov) { w->werr++; - WSL(w, SLT_Debug, *w->wfd, - "Write error, len = %d/%d, errno = %s", - i, w->liov, strerror(errno)); + WSL(w, SLT_Debug, *w->wfd, + "Write error, len = %d/%d, errno = %s", + i, w->liov, strerror(errno)); + } } w->liov = 0; w->niov = 0; From tfheen at projects.linpro.no Thu Feb 5 13:06:15 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 14:06:15 +0100 (CET) Subject: r3631 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205130615.C592D97BFC@projects.linpro.no> Author: tfheen Date: 2009-02-05 14:06:15 +0100 (Thu, 05 Feb 2009) New Revision: 3631 Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h branches/2.0/varnish-cache/bin/varnishd/mgt_param.c branches/2.0/varnish-cache/bin/varnishd/shmlog.c Log: Merge r3428: Make the maximum record length in the shm log a paramter "shm_reclen". Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-05 13:03:15 UTC (rev 3630) +++ branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-05 13:06:15 UTC (rev 3631) @@ -98,6 +98,8 @@ unsigned obj_workspace; unsigned shm_workspace; + unsigned shm_reclen; + /* Acceptor hints */ unsigned sess_timeout; unsigned pipe_timeout; Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 13:03:15 UTC (rev 3630) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 13:06:15 UTC (rev 3631) @@ -636,6 +636,11 @@ "Minimum is 4096 bytes.", DELAYED_EFFECT, "8192", "bytes" }, + { "shm_reclen", tweak_uint, &master.shm_reclen, 16, 65535, + "Maximum number of bytes in SHM log record.\n" + "Maximum is 65535 bytes.", + 0, + "255", "bytes" }, { "default_grace", tweak_uint, &master.default_grace, 0, UINT_MAX, "Default grace period. We will deliver an object " "this long after it has expired, provided another thread " Modified: branches/2.0/varnish-cache/bin/varnishd/shmlog.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/shmlog.c 2009-02-05 13:03:15 UTC (rev 3630) +++ branches/2.0/varnish-cache/bin/varnishd/shmlog.c 2009-02-05 13:06:15 UTC (rev 3631) @@ -81,6 +81,8 @@ vsl_hdr(enum shmlogtag tag, unsigned char *p, unsigned len, unsigned id) { + assert(len < 0x10000); + assert(id < 0x10000); p[__SHMLOG_LEN_HIGH] = (len >> 8) & 0xff; p[__SHMLOG_LEN_LOW] = len & 0xff; p[__SHMLOG_ID_HIGH] = (id >> 8) & 0xff; @@ -100,14 +102,15 @@ VSLR(enum shmlogtag tag, int id, txt t) { unsigned char *p; - unsigned l; + unsigned l, mlen; Tcheck(t); + mlen = params->shm_reclen; /* Truncate */ l = Tlen(t); - if (l > 255) { - l = 255; + if (l > mlen) { + l = mlen; t.e = t.b + l; } @@ -136,11 +139,12 @@ { va_list ap; unsigned char *p; - unsigned n; + unsigned n, mlen; txt t; AN(fmt); va_start(ap, fmt); + mlen = params->shm_reclen; if (strchr(fmt, '%') == NULL) { t.b = TRUST_ME(fmt); @@ -153,13 +157,14 @@ assert(loghead->ptr < loghead->size); /* Wrap if we cannot fit a full size record */ - if (loghead->ptr + SHMLOG_NEXTTAG + 255 + 1 >= loghead->size) + if (loghead->ptr + SHMLOG_NEXTTAG + mlen + 1 >= loghead->size) vsl_wrap(); p = logstart + loghead->ptr; - n = vsnprintf((char *)(p + SHMLOG_DATA), 256, fmt, ap); - if (n > 255) - n = 255; /* we truncate long fields */ + /* +1 for the NUL */ + n = vsnprintf((char *)(p + SHMLOG_DATA), mlen + 1, fmt, ap); + if (n > mlen) + n = mlen; /* we truncate long fields */ vsl_hdr(tag, p, n, id); loghead->ptr += SHMLOG_NEXTTAG + n; assert(loghead->ptr < loghead->size); @@ -203,14 +208,15 @@ WSLR(struct worker *w, enum shmlogtag tag, int id, txt t) { unsigned char *p; - unsigned l; + unsigned l, mlen; Tcheck(t); + mlen = params->shm_reclen; /* Truncate */ l = Tlen(t); - if (l > 255) { - l = 255; + if (l > mlen) { + l = mlen; t.e = t.b + l; } @@ -234,11 +240,12 @@ { va_list ap; unsigned char *p; - unsigned n; + unsigned n, mlen; txt t; AN(fmt); va_start(ap, fmt); + mlen = params->shm_reclen; if (strchr(fmt, '%') == NULL) { t.b = TRUST_ME(fmt); @@ -248,13 +255,14 @@ assert(w->wlp < w->wle); /* Wrap if we cannot fit a full size record */ - if (w->wlp + SHMLOG_NEXTTAG + 255 + 1 >= w->wle) + if (w->wlp + SHMLOG_NEXTTAG + mlen + 1 >= w->wle) WSL_Flush(w, 1); p = w->wlp; - n = vsnprintf((char *)(p + SHMLOG_DATA), 256, fmt, ap); - if (n > 255) - n = 255; /* we truncate long fields */ + /* +1 for the NUL */ + n = vsnprintf((char *)(p + SHMLOG_DATA), mlen + 1, fmt, ap); + if (n > mlen) + n = mlen; /* we truncate long fields */ vsl_hdr(tag, p, n, id); w->wlp += SHMLOG_NEXTTAG + n; assert(w->wlp < w->wle); From tfheen at projects.linpro.no Thu Feb 5 13:09:22 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 5 Feb 2009 14:09:22 +0100 (CET) Subject: r3632 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090205130922.2212F1F74BE@projects.linpro.no> Author: tfheen Date: 2009-02-05 14:09:21 +0100 (Thu, 05 Feb 2009) New Revision: 3632 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c branches/2.0/varnish-cache/bin/varnishd/cache_http.c branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c branches/2.0/varnish-cache/bin/varnishd/cache_pool.c branches/2.0/varnish-cache/bin/varnishd/cache_response.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Merge r3429: Rename the write-buffering functions to WRW_*(). Make reservation and release explicit. Add asserts that this it happens. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 13:06:15 UTC (rev 3631) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-05 13:09:21 UTC (rev 3632) @@ -529,12 +529,15 @@ void WRK_Init(void); int WRK_Queue(struct workreq *wrq); void WRK_QueueSession(struct sess *sp); -void WRK_Reset(struct worker *w, int *fd); -unsigned WRK_Flush(struct worker *w); -unsigned WRK_Write(struct worker *w, const void *ptr, int len); -unsigned WRK_WriteH(struct worker *w, const txt *hh, const char *suf); + +void WRW_Reserve(struct worker *w, int *fd); +void WRW_Release(struct worker *w); +unsigned WRW_Flush(struct worker *w); +unsigned WRW_FlushRelease(struct worker *w); +unsigned WRW_Write(struct worker *w, const void *ptr, int len); +unsigned WRW_WriteH(struct worker *w, const txt *hh, const char *suf); #ifdef SENDFILE_WORKS -void WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len); +void WRW_Sendfile(struct worker *w, int fd, off_t off, unsigned len); #endif /* SENDFILE_WORKS */ /* cache_session.c [SES] */ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-05 13:06:15 UTC (rev 3631) +++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-05 13:09:21 UTC (rev 3632) @@ -288,8 +288,8 @@ content_length -= rdcnt; if (!sp->sendbody) continue; - WRK_Write(sp->wrk, buf, rdcnt); /* XXX: stats ? */ - if (WRK_Flush(sp->wrk)) + (void)WRW_Write(sp->wrk, buf, rdcnt); /* XXX: stats ? */ + if (WRW_Flush(sp->wrk)) return (2); } } @@ -348,7 +348,7 @@ VBE_AddHostHeader(sp); TCP_blocking(vc->fd); /* XXX: we should timeout instead */ - WRK_Reset(w, &vc->fd); + WRW_Reserve(w, &vc->fd); http_Write(w, hp, 0); /* XXX: stats ? */ /* Deal with any message-body the request might have */ @@ -358,7 +358,7 @@ return (__LINE__); } - if (WRK_Flush(w)) { + if (WRW_FlushRelease(w)) { VBE_ClosedFd(sp); /* XXX: other cleanup ? */ return (__LINE__); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-05 13:06:15 UTC (rev 3631) +++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-05 13:09:21 UTC (rev 3632) @@ -809,28 +809,28 @@ if (resp) { AN(hp->hd[HTTP_HDR_STATUS].b); - l = WRK_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " "); + l = WRW_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " "); WSLH(w, *w->wfd, hp, HTTP_HDR_PROTO); - l += WRK_WriteH(w, &hp->hd[HTTP_HDR_STATUS], " "); + l += WRW_WriteH(w, &hp->hd[HTTP_HDR_STATUS], " "); WSLH(w, *w->wfd, hp, HTTP_HDR_STATUS); - l += WRK_WriteH(w, &hp->hd[HTTP_HDR_RESPONSE], "\r\n"); + l += WRW_WriteH(w, &hp->hd[HTTP_HDR_RESPONSE], "\r\n"); WSLH(w, *w->wfd, hp, HTTP_HDR_RESPONSE); } else { AN(hp->hd[HTTP_HDR_URL].b); - l = WRK_WriteH(w, &hp->hd[HTTP_HDR_REQ], " "); + l = WRW_WriteH(w, &hp->hd[HTTP_HDR_REQ], " "); WSLH(w, *w->wfd, hp, HTTP_HDR_REQ); - l += WRK_WriteH(w, &hp->hd[HTTP_HDR_URL], " "); + l += WRW_WriteH(w, &hp->hd[HTTP_HDR_URL], " "); WSLH(w, *w->wfd, hp, HTTP_HDR_URL); - l += WRK_WriteH(w, &hp->hd[HTTP_HDR_PROTO], "\r\n"); + l += WRW_WriteH(w, &hp->hd[HTTP_HDR_PROTO], "\r\n"); WSLH(w, *w->wfd, hp, HTTP_HDR_PROTO); } for (u = HTTP_HDR_FIRST; u < hp->nhd; u++) { AN(hp->hd[u].b); AN(hp->hd[u].e); - l += WRK_WriteH(w, &hp->hd[u], "\r\n"); + l += WRW_WriteH(w, &hp->hd[u], "\r\n"); WSLH(w, *w->wfd, hp, u); } - l += WRK_Write(w, "\r\n", -1); + l += WRW_Write(w, "\r\n", -1); return (l); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c 2009-02-05 13:06:15 UTC (rev 3631) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c 2009-02-05 13:09:21 UTC (rev 3632) @@ -83,14 +83,14 @@ vc = sp->vbe; TCP_blocking(vc->fd); - WRK_Reset(w, &vc->fd); + WRW_Reserve(w, &vc->fd); w->acct.hdrbytes += http_Write(w, bereq->http, 0); if (sp->htc->pipeline.b != NULL) w->acct.bodybytes += - WRK_Write(w, sp->htc->pipeline.b, Tlen(sp->htc->pipeline)); + WRW_Write(w, sp->htc->pipeline.b, Tlen(sp->htc->pipeline)); - if (WRK_Flush(w)) { + if (WRW_FlushRelease(w)) { vca_close_session(sp, "pipe"); VBE_ClosedFd(sp); return; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 13:06:15 UTC (rev 3631) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-05 13:09:21 UTC (rev 3632) @@ -106,22 +106,35 @@ */ void -WRK_Reset(struct worker *w, int *fd) +WRW_Reserve(struct worker *w, int *fd) { CHECK_OBJ_NOTNULL(w, WORKER_MAGIC); + AZ(w->wfd); w->werr = 0; w->liov = 0; w->niov = 0; w->wfd = fd; } +void +WRW_Release(struct worker *w) +{ + + CHECK_OBJ_NOTNULL(w, WORKER_MAGIC); + w->werr = 0; + w->liov = 0; + w->niov = 0; + w->wfd = NULL; +} + unsigned -WRK_Flush(struct worker *w) +WRW_Flush(struct worker *w) { ssize_t i; CHECK_OBJ_NOTNULL(w, WORKER_MAGIC); + AN(w->wfd); if (*w->wfd >= 0 && w->niov > 0 && w->werr == 0) { i = writev(*w->wfd, w->iov, w->niov); if (i != w->liov) { @@ -137,32 +150,46 @@ } unsigned -WRK_WriteH(struct worker *w, const txt *hh, const char *suf) +WRW_FlushRelease(struct worker *w) { unsigned u; CHECK_OBJ_NOTNULL(w, WORKER_MAGIC); + AN(w->wfd); + u = WRW_Flush(w); + WRW_Release(w); + return (u); +} + +unsigned +WRW_WriteH(struct worker *w, const txt *hh, const char *suf) +{ + unsigned u; + + CHECK_OBJ_NOTNULL(w, WORKER_MAGIC); + AN(w->wfd); AN(w); AN(hh); AN(hh->b); AN(hh->e); - u = WRK_Write(w, hh->b, hh->e - hh->b); + u = WRW_Write(w, hh->b, hh->e - hh->b); if (suf != NULL) - u += WRK_Write(w, suf, -1); + u += WRW_Write(w, suf, -1); return (u); } unsigned -WRK_Write(struct worker *w, const void *ptr, int len) +WRW_Write(struct worker *w, const void *ptr, int len) { CHECK_OBJ_NOTNULL(w, WORKER_MAGIC); + AN(w->wfd); if (len == 0 || *w->wfd < 0) return (0); if (len == -1) len = strlen(ptr); if (w->niov == MAX_IOVS) - (void)WRK_Flush(w); + (void)WRW_Flush(w); w->iov[w->niov].iov_base = TRUST_ME(ptr); w->iov[w->niov].iov_len = len; w->liov += len; @@ -172,10 +199,11 @@ #ifdef SENDFILE_WORKS void -WRK_Sendfile(struct worker *w, int fd, off_t off, unsigned len) +WRW_Sendfile(struct worker *w, int fd, off_t off, unsigned len) { CHECK_OBJ_NOTNULL(w, WORKER_MAGIC); + AN(w->wfd); assert(fd >= 0); assert(len > 0); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_response.c 2009-02-05 13:06:15 UTC (rev 3631) +++ branches/2.0/varnish-cache/bin/varnishd/cache_response.c 2009-02-05 13:09:21 UTC (rev 3632) @@ -137,16 +137,24 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - WRK_Reset(sp->wrk, &sp->fd); + WRW_Reserve(sp->wrk, &sp->fd); + if (sp->esis == 0) sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); if (sp->wantbody && !VTAILQ_EMPTY(&sp->obj->esibits)) { + if (WRW_FlushRelease(sp->wrk)) { + vca_close_session(sp, "remote closed"); + return; + } ESI_Deliver(sp); - } else if (sp->wantbody) { + return; + } + + if (sp->wantbody) { if (sp->esis > 0 && sp->http->protover >= 1.1) { sprintf(lenbuf, "%x\r\n", sp->obj->len); - (void)WRK_Write(sp->wrk, lenbuf, -1); + (void)WRW_Write(sp->wrk, lenbuf, -1); } VTAILQ_FOREACH(st, &sp->obj->store, list) { @@ -164,18 +172,18 @@ if (st->fd >= 0 && st->len >= params->sendfile_threshold) { VSL_stats->n_objsendfile++; - WRK_Sendfile(sp->wrk, st->fd, + WRW_Sendfile(sp->wrk, st->fd, st->where, st->len); continue; } #endif /* SENDFILE_WORKS */ VSL_stats->n_objwrite++; - (void)WRK_Write(sp->wrk, st->ptr, st->len); + (void)WRW_Write(sp->wrk, st->ptr, st->len); } assert(u == sp->obj->len); if (sp->esis > 0 && sp->http->protover >= 1.1) - (void)WRK_Write(sp->wrk, "\r\n", -1); + (void)WRW_Write(sp->wrk, "\r\n", -1); } - if (WRK_Flush(sp->wrk)) + if (WRW_FlushRelease(sp->wrk)) vca_close_session(sp, "remote closed"); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-05 13:06:15 UTC (rev 3631) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-05 13:09:21 UTC (rev 3632) @@ -799,27 +799,24 @@ struct esi_bit *eb; struct object *obj; + WRW_Reserve(sp->wrk, &sp->fd); VTAILQ_FOREACH(eb, &sp->obj->esibits, list) { - assert(sp->wrk->wfd == &sp->fd); if (Tlen(eb->verbatim)) { if (sp->http->protover >= 1.1) - (void)WRK_Write(sp->wrk, eb->chunk_length, -1); - sp->wrk->acct.bodybytes += WRK_Write(sp->wrk, + (void)WRW_Write(sp->wrk, eb->chunk_length, -1); + sp->wrk->acct.bodybytes += WRW_Write(sp->wrk, eb->verbatim.b, Tlen(eb->verbatim)); if (sp->http->protover >= 1.1) - (void)WRK_Write(sp->wrk, "\r\n", -1); + (void)WRW_Write(sp->wrk, "\r\n", -1); } if (eb->include.b == NULL || sp->esis >= params->max_esi_includes) continue; - /* - * We flush here, because the next transaction is - * quite likely to take some time, so we should get - * as many bits to the client as we can already. - */ - if (WRK_Flush(sp->wrk)) - break; + if (WRW_FlushRelease(sp->wrk)) { + vca_close_session(sp, "remote closed"); + return; + } sp->esis++; obj = sp->obj; @@ -860,11 +857,12 @@ assert(sp->step == STP_DONE); sp->esis--; sp->obj = obj; - + WRW_Reserve(sp->wrk, &sp->fd); } - assert(sp->wrk->wfd == &sp->fd); if (sp->esis == 0 && sp->http->protover >= 1.1) - (void)WRK_Write(sp->wrk, "0\r\n\r\n", -1); + (void)WRW_Write(sp->wrk, "0\r\n\r\n", -1); + if (WRW_FlushRelease(sp->wrk)) + vca_close_session(sp, "remote closed"); } /*--------------------------------------------------------------------*/ From tfheen at projects.linpro.no Fri Feb 6 08:44:49 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 09:44:49 +0100 (CET) Subject: r3633 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206084449.233411F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 09:44:48 +0100 (Fri, 06 Feb 2009) New Revision: 3633 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c branches/2.0/varnish-cache/bin/varnishd/mgt_param.c Log: Merge r3431: Control the ESI parsing debug records with the esi_syntax bitmap parameter. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-05 13:09:21 UTC (rev 3632) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-06 08:44:48 UTC (rev 3633) @@ -158,8 +158,9 @@ VTAILQ_INSERT_TAIL(&ew->sp->obj->esibits, ew->eb, list); ew->eb->verbatim = ew->dst; sprintf(ew->eb->chunk_length, "%x\r\n", Tlen(ew->dst)); - VSL(SLT_Debug, ew->sp->fd, "AddBit: %d <%.*s>", - Tlen(ew->dst), Tlen(ew->dst), ew->dst.b); + if (params->esi_syntax & 0x4) + VSL(SLT_Debug, ew->sp->fd, "AddBit: %d <%.*s>", + Tlen(ew->dst), Tlen(ew->dst), ew->dst.b); return(ew->eb); } @@ -172,8 +173,9 @@ esi_addverbatim(struct esi_work *ew) { - VSL(SLT_Debug, ew->sp->fd, "AddVer: %d <%.*s>", - Tlen(ew->o), Tlen(ew->o), ew->o.b); + if (params->esi_syntax & 0x4) + VSL(SLT_Debug, ew->sp->fd, "AddVer: %d <%.*s>", + Tlen(ew->o), Tlen(ew->o), ew->o.b); if (ew->o.b != ew->dst.e) memmove(ew->dst.e, ew->o.b, Tlen(ew->o)); ew->dst.e += Tlen(ew->o); @@ -283,9 +285,9 @@ VSL(SLT_Debug, 0, "Incl \"%.*s\"", t.e - t.b, t.b); eb = esi_addbit(ew); while (esi_attrib(ew, &t, &tag, &val) == 1) { - VSL(SLT_Debug, 0, "<%.*s> -> <%.*s>", - tag.e - tag.b, tag.b, - val.e - val.b, val.b); + if (params->esi_syntax & 0x4) + 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)) continue; if (Tlen(val) == 0) { @@ -496,8 +498,9 @@ r = p + 1; } - VSL(SLT_Debug, ew->sp->fd, "Element: clos=%d [%.*s]", - celem, q - r, r); + if (params->esi_syntax & 0x4) + VSL(SLT_Debug, ew->sp->fd, "Element: clos=%d [%.*s]", + celem, q - r, r); if (r + 9 < q && !memcmp(r, "esi:remove", 10)) { @@ -612,8 +615,9 @@ { char *p; - VSL(SLT_Debug, ew->sp->fd, "Parse: %d <%.*s>", - Tlen(ew->t), Tlen(ew->t), ew->t.b); + if (params->esi_syntax & 0x4) + VSL(SLT_Debug, ew->sp->fd, "Parse: %d <%.*s>", + Tlen(ew->t), Tlen(ew->t), ew->t.b); p = esi_parse2(ew); assert(ew->o.b >= ew->t.b); assert(ew->o.e <= ew->t.e); Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-05 13:09:21 UTC (rev 3632) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 08:44:48 UTC (rev 3633) @@ -764,6 +764,7 @@ "Bitmap controlling ESI parsing code:\n" " 0x00000001 - Don't check if it looks like XML\n" " 0x00000002 - Ignore non-esi elements\n" + " 0x00000004 - Emit parsing debug records\n" "Use 0x notation and do the bitor in your head :-)\n", 0, "0", "bitmap" }, From tfheen at projects.linpro.no Fri Feb 6 09:03:59 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 10:03:59 +0100 (CET) Subject: r3634 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206090359.748E11F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 10:03:59 +0100 (Fri, 06 Feb 2009) New Revision: 3634 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Merge r3432: Log debugs with correct id Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-06 08:44:48 UTC (rev 3633) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-06 09:03:59 UTC (rev 3634) @@ -282,11 +282,11 @@ unsigned u, v; struct ws *ws; - VSL(SLT_Debug, 0, "Incl \"%.*s\"", t.e - t.b, t.b); + VSL(SLT_Debug, ew->sp->fd, "Incl \"%.*s\"", t.e - t.b, t.b); eb = esi_addbit(ew); while (esi_attrib(ew, &t, &tag, &val) == 1) { if (params->esi_syntax & 0x4) - VSL(SLT_Debug, 0, "<%.*s> -> <%.*s>", + VSL(SLT_Debug, ew->sp->fd, "<%.*s> -> <%.*s>", tag.e - tag.b, tag.b, val.e - val.b, val.b); if (Tlen(tag) != 3 || memcmp(tag.b, "src", 3)) continue; From tfheen at projects.linpro.no Fri Feb 6 09:08:01 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 10:08:01 +0100 (CET) Subject: r3635 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206090801.9F16C1F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 10:08:01 +0100 (Fri, 06 Feb 2009) New Revision: 3635 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h Log: Merge r3434: Isolate some hash-string building nastyness in cache_hash.c Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-06 09:03:59 UTC (rev 3634) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-06 09:08:01 UTC (rev 3635) @@ -586,28 +586,12 @@ cnt_lookup(struct sess *sp) { struct object *o; - char *p; - uintptr_t u; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); if (sp->obj == NULL) { - - /* Allocate the pointers we need, align properly. */ - sp->lhashptr = 1; /* space for NUL */ - sp->ihashptr = 0; - sp->nhashptr = sp->vcl->nhashcount * 2; - p = WS_Alloc(sp->http->ws, - sizeof(const char *) * (sp->nhashptr + 1)); - XXXAN(p); - /* Align pointer properly (?) */ - u = (uintptr_t)p; - u &= sizeof(const char *) - 1; - if (u) - p += sizeof(const char *) - u; - sp->hashptr = (void*)p; - + HSH_Prepare(sp, sp->vcl->nhashcount); VCL_hash_method(sp); assert(sp->handling == VCL_RET_HASH); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 09:03:59 UTC (rev 3634) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 09:08:01 UTC (rev 3635) @@ -201,6 +201,48 @@ assert(b <= oh->hash + oh->hashlen); } +void +HSH_Prepare(struct sess *sp, unsigned nhashcount) +{ + char *p; + unsigned u; + + /* Allocate the pointers we need, align properly. */ + sp->lhashptr = 1; /* space for NUL */ + sp->ihashptr = 0; + sp->nhashptr = nhashcount * 2; + p = WS_Alloc(sp->http->ws, sizeof(const char *) * (sp->nhashptr + 1)); + XXXAN(p); + /* Align pointer properly (?) */ + u = (uintptr_t)p; + u &= sizeof(const char *) - 1; + if (u) + p += sizeof(const char *) - u; + sp->hashptr = (void*)p; +} + +void +HSH_AddString(struct sess *sp, const char *str) +{ + int l; + + if (str == NULL) + str = ""; + l = strlen(str); + + /* + * XXX: handle this by bouncing sp->vcl->nhashcount when it fails + * XXX: and dispose of this request either by reallocating the + * XXX: hashptr (if possible) or restarting/error the request + */ + xxxassert(sp->ihashptr < sp->nhashptr); + + sp->hashptr[sp->ihashptr] = str; + sp->hashptr[sp->ihashptr + 1] = str + l; + sp->ihashptr += 2; + sp->lhashptr += l + 1; +} + struct object * HSH_Lookup(struct sess *sp) { Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-06 09:03:59 UTC (rev 3634) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-06 09:08:01 UTC (rev 3635) @@ -585,23 +585,8 @@ void VRT_l_req_hash(struct sess *sp, const char *str) { - int l; - if (str == NULL) - str = ""; - l = strlen(str); - - /* - * XXX: handle this by bouncing sp->vcl->nhashcount when it fails - * XXX: and dispose of this request either by reallocating the - * XXX: hashptr (if possible) or restarting/error the request - */ - xxxassert(sp->ihashptr < sp->nhashptr); - - sp->hashptr[sp->ihashptr] = str; - sp->hashptr[sp->ihashptr + 1] = str + l; - sp->ihashptr += 2; - sp->lhashptr += l + 1; + HSH_AddString(sp, str); } /*--------------------------------------------------------------------*/ Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-06 09:03:59 UTC (rev 3634) +++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-06 09:08:01 UTC (rev 3635) @@ -59,6 +59,8 @@ void HSH_Deref(struct object *o); double HSH_Grace(double g); void HSH_Init(void); +void HSH_AddString(struct sess *sp, const char *str); +void HSH_Prepare(struct sess *sp, unsigned hashcount); #ifdef VARNISH_CACHE_CHILD From tfheen at projects.linpro.no Fri Feb 6 09:29:17 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 10:29:17 +0100 (CET) Subject: r3636 - in branches/2.0/varnish-cache: include lib/libvarnish Message-ID: <20090206092917.C7AE71F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 10:29:17 +0100 (Fri, 06 Feb 2009) New Revision: 3636 Added: branches/2.0/varnish-cache/include/vsha256.h branches/2.0/varnish-cache/lib/libvarnish/vsha256.c Log: Merge r3435: Add SHA256 hashing code. This code was written by Colin Percival for the FreeBSD project. Copied: branches/2.0/varnish-cache/include/vsha256.h (from rev 3435, trunk/varnish-cache/include/vsha256.h) =================================================================== --- branches/2.0/varnish-cache/include/vsha256.h (rev 0) +++ branches/2.0/varnish-cache/include/vsha256.h 2009-02-06 09:29:17 UTC (rev 3636) @@ -0,0 +1,50 @@ +/*- + * Copyright 2005 Colin Percival + * 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 THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: head/lib/libmd/sha256.h 154479 2006-01-17 15:35:57Z phk $ + */ + +#ifndef _SHA256_H_ +#define _SHA256_H_ + +#include + +typedef struct SHA256Context { + uint32_t state[8]; + uint32_t count[2]; + unsigned char buf[64]; +} SHA256_CTX; + +__BEGIN_DECLS +void SHA256_Init(SHA256_CTX *); +void SHA256_Update(SHA256_CTX *, const void *, size_t); +void SHA256_Final(unsigned char [32], SHA256_CTX *); +char *SHA256_End(SHA256_CTX *, char *); +char *SHA256_File(const char *, char *); +char *SHA256_FileChunk(const char *, char *, off_t, off_t); +char *SHA256_Data(const void *, unsigned int, char *); +__END_DECLS + +#endif /* !_SHA256_H_ */ Copied: branches/2.0/varnish-cache/lib/libvarnish/vsha256.c (from rev 3435, trunk/varnish-cache/lib/libvarnish/vsha256.c) =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vsha256.c (rev 0) +++ branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-06 09:29:17 UTC (rev 3636) @@ -0,0 +1,300 @@ +/*- + * Copyright 2005 Colin Percival + * 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 THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD: head/lib/libmd/sha256c.c 154479 2006-01-17 15:35:57Z phk $"); + +#include +#include + +#include + +#include "vsha256.h" + +#if BYTE_ORDER == BIG_ENDIAN + +/* Copy a vector of big-endian uint32_t into a vector of bytes */ +#define be32enc_vect(dst, src, len) \ + memcpy((void *)dst, (const void *)src, (size_t)len) + +/* Copy a vector of bytes into a vector of big-endian uint32_t */ +#define be32dec_vect(dst, src, len) \ + memcpy((void *)dst, (const void *)src, (size_t)len) + +#else /* BYTE_ORDER != BIG_ENDIAN */ + +/* + * Encode a length len/4 vector of (uint32_t) into a length len vector of + * (unsigned char) in big-endian form. Assumes len is a multiple of 4. + */ +static void +be32enc_vect(unsigned char *dst, const uint32_t *src, size_t len) +{ + size_t i; + + for (i = 0; i < len / 4; i++) + be32enc(dst + i * 4, src[i]); +} + +/* + * Decode a big-endian length len vector of (unsigned char) into a length + * len/4 vector of (uint32_t). Assumes len is a multiple of 4. + */ +static void +be32dec_vect(uint32_t *dst, const unsigned char *src, size_t len) +{ + size_t i; + + for (i = 0; i < len / 4; i++) + dst[i] = be32dec(src + i * 4); +} + +#endif /* BYTE_ORDER != BIG_ENDIAN */ + +/* Elementary functions used by SHA256 */ +#define Ch(x, y, z) ((x & (y ^ z)) ^ z) +#define Maj(x, y, z) ((x & (y | z)) | (y & z)) +#define SHR(x, n) (x >> n) +#define ROTR(x, n) ((x >> n) | (x << (32 - n))) +#define S0(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define S1(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) +#define s0(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHR(x, 3)) +#define s1(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHR(x, 10)) + +/* SHA256 round function */ +#define RND(a, b, c, d, e, f, g, h, k) \ + t0 = h + S1(e) + Ch(e, f, g) + k; \ + t1 = S0(a) + Maj(a, b, c); \ + d += t0; \ + h = t0 + t1; + +/* Adjusted round function for rotating state */ +#define RNDr(S, W, i, k) \ + RND(S[(64 - i) % 8], S[(65 - i) % 8], \ + S[(66 - i) % 8], S[(67 - i) % 8], \ + S[(68 - i) % 8], S[(69 - i) % 8], \ + S[(70 - i) % 8], S[(71 - i) % 8], \ + W[i] + k) + +/* + * SHA256 block compression function. The 256-bit state is transformed via + * the 512-bit input block to produce a new state. + */ +static void +SHA256_Transform(uint32_t * state, const unsigned char block[64]) +{ + uint32_t W[64]; + uint32_t S[8]; + uint32_t t0, t1; + int i; + + /* 1. Prepare message schedule W. */ + be32dec_vect(W, block, 64); + for (i = 16; i < 64; i++) + W[i] = s1(W[i - 2]) + W[i - 7] + s0(W[i - 15]) + W[i - 16]; + + /* 2. Initialize working variables. */ + memcpy(S, state, 32); + + /* 3. Mix. */ + RNDr(S, W, 0, 0x428a2f98); + RNDr(S, W, 1, 0x71374491); + RNDr(S, W, 2, 0xb5c0fbcf); + RNDr(S, W, 3, 0xe9b5dba5); + RNDr(S, W, 4, 0x3956c25b); + RNDr(S, W, 5, 0x59f111f1); + RNDr(S, W, 6, 0x923f82a4); + RNDr(S, W, 7, 0xab1c5ed5); + RNDr(S, W, 8, 0xd807aa98); + RNDr(S, W, 9, 0x12835b01); + RNDr(S, W, 10, 0x243185be); + RNDr(S, W, 11, 0x550c7dc3); + RNDr(S, W, 12, 0x72be5d74); + RNDr(S, W, 13, 0x80deb1fe); + RNDr(S, W, 14, 0x9bdc06a7); + RNDr(S, W, 15, 0xc19bf174); + RNDr(S, W, 16, 0xe49b69c1); + RNDr(S, W, 17, 0xefbe4786); + RNDr(S, W, 18, 0x0fc19dc6); + RNDr(S, W, 19, 0x240ca1cc); + RNDr(S, W, 20, 0x2de92c6f); + RNDr(S, W, 21, 0x4a7484aa); + RNDr(S, W, 22, 0x5cb0a9dc); + RNDr(S, W, 23, 0x76f988da); + RNDr(S, W, 24, 0x983e5152); + RNDr(S, W, 25, 0xa831c66d); + RNDr(S, W, 26, 0xb00327c8); + RNDr(S, W, 27, 0xbf597fc7); + RNDr(S, W, 28, 0xc6e00bf3); + RNDr(S, W, 29, 0xd5a79147); + RNDr(S, W, 30, 0x06ca6351); + RNDr(S, W, 31, 0x14292967); + RNDr(S, W, 32, 0x27b70a85); + RNDr(S, W, 33, 0x2e1b2138); + RNDr(S, W, 34, 0x4d2c6dfc); + RNDr(S, W, 35, 0x53380d13); + RNDr(S, W, 36, 0x650a7354); + RNDr(S, W, 37, 0x766a0abb); + RNDr(S, W, 38, 0x81c2c92e); + RNDr(S, W, 39, 0x92722c85); + RNDr(S, W, 40, 0xa2bfe8a1); + RNDr(S, W, 41, 0xa81a664b); + RNDr(S, W, 42, 0xc24b8b70); + RNDr(S, W, 43, 0xc76c51a3); + RNDr(S, W, 44, 0xd192e819); + RNDr(S, W, 45, 0xd6990624); + RNDr(S, W, 46, 0xf40e3585); + RNDr(S, W, 47, 0x106aa070); + RNDr(S, W, 48, 0x19a4c116); + RNDr(S, W, 49, 0x1e376c08); + RNDr(S, W, 50, 0x2748774c); + RNDr(S, W, 51, 0x34b0bcb5); + RNDr(S, W, 52, 0x391c0cb3); + RNDr(S, W, 53, 0x4ed8aa4a); + RNDr(S, W, 54, 0x5b9cca4f); + RNDr(S, W, 55, 0x682e6ff3); + RNDr(S, W, 56, 0x748f82ee); + RNDr(S, W, 57, 0x78a5636f); + RNDr(S, W, 58, 0x84c87814); + RNDr(S, W, 59, 0x8cc70208); + RNDr(S, W, 60, 0x90befffa); + RNDr(S, W, 61, 0xa4506ceb); + RNDr(S, W, 62, 0xbef9a3f7); + RNDr(S, W, 63, 0xc67178f2); + + /* 4. Mix local working variables into global state */ + for (i = 0; i < 8; i++) + state[i] += S[i]; +} + +static unsigned char PAD[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* Add padding and terminating bit-count. */ +static void +SHA256_Pad(SHA256_CTX * ctx) +{ + unsigned char len[8]; + uint32_t r, plen; + + /* + * Convert length to a vector of bytes -- we do this now rather + * than later because the length will change after we pad. + */ + be32enc_vect(len, ctx->count, 8); + + /* Add 1--64 bytes so that the resulting length is 56 mod 64 */ + r = (ctx->count[1] >> 3) & 0x3f; + plen = (r < 56) ? (56 - r) : (120 - r); + SHA256_Update(ctx, PAD, (size_t)plen); + + /* Add the terminating bit-count */ + SHA256_Update(ctx, len, 8); +} + +/* SHA-256 initialization. Begins a SHA-256 operation. */ +void +SHA256_Init(SHA256_CTX * ctx) +{ + + /* Zero bits processed so far */ + ctx->count[0] = ctx->count[1] = 0; + + /* Magic initialization constants */ + ctx->state[0] = 0x6A09E667; + ctx->state[1] = 0xBB67AE85; + ctx->state[2] = 0x3C6EF372; + ctx->state[3] = 0xA54FF53A; + ctx->state[4] = 0x510E527F; + ctx->state[5] = 0x9B05688C; + ctx->state[6] = 0x1F83D9AB; + ctx->state[7] = 0x5BE0CD19; +} + +/* Add bytes into the hash */ +void +SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) +{ + uint32_t bitlen[2]; + uint32_t r; + const unsigned char *src = in; + + /* Number of bytes left in the buffer from previous updates */ + r = (ctx->count[1] >> 3) & 0x3f; + + /* Convert the length into a number of bits */ + bitlen[1] = ((uint32_t)len) << 3; + bitlen[0] = (uint32_t)(len >> 29); + + /* Update number of bits */ + if ((ctx->count[1] += bitlen[1]) < bitlen[1]) + ctx->count[0]++; + ctx->count[0] += bitlen[0]; + + /* Handle the case where we don't need to perform any transforms */ + if (len < 64 - r) { + memcpy(&ctx->buf[r], src, len); + return; + } + + /* Finish the current block */ + memcpy(&ctx->buf[r], src, 64 - r); + SHA256_Transform(ctx->state, ctx->buf); + src += 64 - r; + len -= 64 - r; + + /* Perform complete blocks */ + while (len >= 64) { + SHA256_Transform(ctx->state, src); + src += 64; + len -= 64; + } + + /* Copy left over data into buffer */ + memcpy(ctx->buf, src, len); +} + +/* + * SHA-256 finalization. Pads the input data, exports the hash value, + * and clears the context state. + */ +void +SHA256_Final(unsigned char digest[32], SHA256_CTX * ctx) +{ + + /* Add padding */ + SHA256_Pad(ctx); + + /* Write the hash */ + be32enc_vect(digest, ctx->state, 32); + + /* Clear the context state */ + memset((void *)ctx, 0, sizeof(*ctx)); +} From tfheen at projects.linpro.no Fri Feb 6 09:48:41 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 10:48:41 +0100 (CET) Subject: r3637 - in branches/2.0/varnish-cache: include lib/libvarnish Message-ID: <20090206094841.2BA1C1F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 10:48:40 +0100 (Fri, 06 Feb 2009) New Revision: 3637 Modified: branches/2.0/varnish-cache/include/vsha256.h branches/2.0/varnish-cache/lib/libvarnish/Makefile.am branches/2.0/varnish-cache/lib/libvarnish/vsha256.c Log: Merge r3436 + r3438: Hook SHA256 into the build Hook SHA256 into the build Neuter the FreeBSD specifics of SHA256 implementation. In the end, it comes down to lack of POSIX definition of a way to find out byte-endianess, sigh... Modified: branches/2.0/varnish-cache/include/vsha256.h =================================================================== --- branches/2.0/varnish-cache/include/vsha256.h 2009-02-06 09:29:17 UTC (rev 3636) +++ branches/2.0/varnish-cache/include/vsha256.h 2009-02-06 09:48:40 UTC (rev 3637) @@ -29,7 +29,7 @@ #ifndef _SHA256_H_ #define _SHA256_H_ -#include +#include typedef struct SHA256Context { uint32_t state[8]; @@ -41,10 +41,6 @@ void SHA256_Init(SHA256_CTX *); void SHA256_Update(SHA256_CTX *, const void *, size_t); void SHA256_Final(unsigned char [32], SHA256_CTX *); -char *SHA256_End(SHA256_CTX *, char *); -char *SHA256_File(const char *, char *); -char *SHA256_FileChunk(const char *, char *, off_t, off_t); -char *SHA256_Data(const void *, unsigned int, char *); __END_DECLS #endif /* !_SHA256_H_ */ Modified: branches/2.0/varnish-cache/lib/libvarnish/Makefile.am =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/Makefile.am 2009-02-06 09:29:17 UTC (rev 3636) +++ branches/2.0/varnish-cache/lib/libvarnish/Makefile.am 2009-02-06 09:48:40 UTC (rev 3637) @@ -24,6 +24,7 @@ vlu.c \ vpf.c \ vsb.c \ + vsha256.c \ vss.c \ vtmpfile.c Modified: branches/2.0/varnish-cache/lib/libvarnish/vsha256.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-06 09:29:17 UTC (rev 3636) +++ branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-06 09:48:40 UTC (rev 3637) @@ -22,19 +22,17 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * From: $FreeBSD: head/lib/libmd/sha256c.c 154479 2006-01-17 15:35:57Z phk $ */ -#include -__FBSDID("$FreeBSD: head/lib/libmd/sha256c.c 154479 2006-01-17 15:35:57Z phk $"); +#include -#include -#include - #include #include "vsha256.h" -#if BYTE_ORDER == BIG_ENDIAN +#if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN /* Copy a vector of big-endian uint32_t into a vector of bytes */ #define be32enc_vect(dst, src, len) \ @@ -44,8 +42,27 @@ #define be32dec_vect(dst, src, len) \ memcpy((void *)dst, (const void *)src, (size_t)len) -#else /* BYTE_ORDER != BIG_ENDIAN */ +#else /* BYTE_ORDER != BIG_ENDIAN or in doubt... */ +static __inline uint32_t +mybe32dec(const void *pp) +{ + unsigned char const *p = (unsigned char const *)pp; + + return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); +} + +static __inline void +mybe32enc(void *pp, uint32_t u) +{ + unsigned char *p = (unsigned char *)pp; + + p[0] = (u >> 24) & 0xff; + p[1] = (u >> 16) & 0xff; + p[2] = (u >> 8) & 0xff; + p[3] = u & 0xff; +} + /* * Encode a length len/4 vector of (uint32_t) into a length len vector of * (unsigned char) in big-endian form. Assumes len is a multiple of 4. @@ -56,7 +73,7 @@ size_t i; for (i = 0; i < len / 4; i++) - be32enc(dst + i * 4, src[i]); + mybe32enc(dst + i * 4, src[i]); } /* @@ -69,10 +86,10 @@ size_t i; for (i = 0; i < len / 4; i++) - dst[i] = be32dec(src + i * 4); + dst[i] = mybe32dec(src + i * 4); } -#endif /* BYTE_ORDER != BIG_ENDIAN */ +#endif /* Elementary functions used by SHA256 */ #define Ch(x, y, z) ((x & (y ^ z)) ^ z) From tfheen at projects.linpro.no Fri Feb 6 09:51:51 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 10:51:51 +0100 (CET) Subject: r3638 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206095151.E4DAA1F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 10:51:51 +0100 (Fri, 06 Feb 2009) New Revision: 3638 Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h branches/2.0/varnish-cache/bin/varnishd/mgt_param.c Log: Merge r3437: Add a parameter to enable SHA256 hashing. This does not do anything yet. Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-06 09:48:40 UTC (rev 3637) +++ branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-06 09:51:51 UTC (rev 3638) @@ -174,6 +174,9 @@ /* Default grace period */ unsigned default_grace; + /* Use sha256 hasing */ + unsigned hash_sha256; + /* Log hash string to shm */ unsigned log_hash; Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 09:48:40 UTC (rev 3637) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 09:51:51 UTC (rev 3638) @@ -839,6 +839,10 @@ "NB: Must be specified with -p to have effect.\n", 0, "8192", "bytes" }, + { "hash_sha256", tweak_bool, &master.hash_sha256, 0, 0, + "Use SHA256 compression of hash-strings", + 0, + "off", "bool" }, { "log_hashstring", tweak_bool, &master.log_hash, 0, 0, "Log the hash string to shared memory log.\n", 0, From tfheen at projects.linpro.no Fri Feb 6 09:55:39 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 10:55:39 +0100 (CET) Subject: r3639 - in branches/2.0/varnish-cache: . lib/libvarnish Message-ID: <20090206095539.C3DC61F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 10:55:39 +0100 (Fri, 06 Feb 2009) New Revision: 3639 Modified: branches/2.0/varnish-cache/configure.ac branches/2.0/varnish-cache/lib/libvarnish/vsha256.c Log: Merge r3439: Endianness optimisation Try to get the endianess optimization working, by including an assortment of possibly relevant headers and only go with the fast path if we have credible information that this is a big-endian platform. Modified: branches/2.0/varnish-cache/configure.ac =================================================================== --- branches/2.0/varnish-cache/configure.ac 2009-02-06 09:51:51 UTC (rev 3638) +++ branches/2.0/varnish-cache/configure.ac 2009-02-06 09:55:39 UTC (rev 3639) @@ -70,11 +70,13 @@ AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_HEADER_TIME +AC_CHECK_HEADERS([sys/endian.h]) AC_CHECK_HEADERS([sys/filio.h]) AC_CHECK_HEADERS([sys/mount.h]) AC_CHECK_HEADERS([sys/socket.h]) AC_CHECK_HEADERS([sys/statvfs.h]) AC_CHECK_HEADERS([sys/vfs.h]) +AC_CHECK_HEADERS([endian.h]) AC_CHECK_HEADERS([netinet/in.h]) AC_CHECK_HEADERS([pthread_np.h]) AC_CHECK_HEADERS([stddef.h]) Modified: branches/2.0/varnish-cache/lib/libvarnish/vsha256.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-06 09:51:51 UTC (rev 3638) +++ branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-06 09:55:39 UTC (rev 3639) @@ -26,10 +26,22 @@ * From: $FreeBSD: head/lib/libmd/sha256c.c 154479 2006-01-17 15:35:57Z phk $ */ +#include "config.h" + #include - #include +#ifdef HAVE_ENDIAN_H +#include +#define BYTE_ORDER __BYTE_ORDER +#define BIG_ENDIAN __BIG_ENDIAN +#endif +#ifdef HAVE_SYS_ENDIAN_H +#include +#define BYTE_ORDER _BYTE_ORDER +#define BIG_ENDIAN _BIG_ENDIAN +#endif + #include "vsha256.h" #if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN From tfheen at projects.linpro.no Fri Feb 6 10:00:15 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 11:00:15 +0100 (CET) Subject: r3640 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206100015.B65851F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-06 11:00:15 +0100 (Fri, 06 Feb 2009) New Revision: 3640 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c Log: Merge r3440: Sort the parameters alphabetically, it's too hard to find anything right now. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 09:55:39 UTC (rev 3639) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 10:00:15 UTC (rev 3640) @@ -77,6 +77,8 @@ }; static struct params master; +static int nparspec; +static struct parspec const ** parspec; /*--------------------------------------------------------------------*/ @@ -402,7 +404,7 @@ free(ta); } FreeArgv(av); - if (cli->result != CLIS_OK) { + if (cli != NULL && cli->result != CLIS_OK) { clean_listen_sock_head(&lsh); return; } @@ -492,7 +494,7 @@ * change its default value. * XXX: we should generate the relevant section of varnishd.1 from here. */ -static const struct parspec parspec[] = { +static const struct parspec input_parspec[] = { { "user", tweak_user, NULL, 0, 0, "The unprivileged user to run as. Setting this will " "also set \"group\" to the specified user's primary group.", @@ -915,6 +917,7 @@ void mcf_param_show(struct cli *cli, const char * const *av, void *priv) { + int i; const struct parspec *pp; int lfmt; @@ -923,7 +926,8 @@ lfmt = 0; else lfmt = 1; - for (pp = parspec; pp->name != NULL; pp++) { + for (i = 0; i < nparspec; i++) { + pp = parspec[i]; if (av[2] != NULL && !lfmt && strcmp(pp->name, av[2])) continue; cli_out(cli, "%-*s ", margin, pp->name); @@ -977,9 +981,11 @@ void MCF_ParamSet(struct cli *cli, const char *param, const char *val) { + int i; const struct parspec *pp; - for (pp = parspec; pp->name != NULL; pp++) { + for (i = 0; i < nparspec; i++) { + pp = parspec[i]; if (!strcmp(pp->name, param)) { pp->func(cli, pp, val); if (cli->result != CLIS_OK) { @@ -1009,20 +1015,69 @@ MCF_ParamSet(cli, av[2], av[3]); } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * Add a group of parameters to the global set and sort by name. + */ -void -MCF_ParamInit(struct cli *cli) +static int +parspec_cmp(const void *a, const void *b) { + struct parspec * const * pa = a; + struct parspec * const * pb = b; + return (strcmp((*pa)->name, (*pb)->name)); +} + +static void +MCF_AddParams(const struct parspec *ps) +{ const struct parspec *pp; + int n; - for (pp = parspec; pp->name != NULL; pp++) { - cli_out(cli, "Set Default for %s = %s\n", pp->name, pp->def); + n = 0; + for (pp = ps; pp->name != NULL; pp++) { if (strlen(pp->name) + 1 > margin) margin = strlen(pp->name) + 1; + n++; + } + parspec = realloc(parspec, (nparspec + n + 1) * sizeof *parspec); + for (pp = ps; pp->name != NULL; pp++) + parspec[nparspec++] = pp; + parspec[nparspec] = NULL; + qsort (parspec, nparspec, sizeof parspec[0], parspec_cmp); +} + +/*-------------------------------------------------------------------- + * Set defaults for all parameters + */ + +static void +MCF_SetDefaults(struct cli *cli) +{ + const struct parspec *pp; + int i; + + for (i = 0; i < nparspec; i++) { + pp = parspec[i]; + if (cli != NULL) + cli_out(cli, + "Set Default for %s = %s\n", pp->name, pp->def); pp->func(cli, pp, pp->def); - if (cli->result != CLIS_OK) + if (cli != NULL && cli->result != CLIS_OK) return; } +} + +/*--------------------------------------------------------------------*/ + +void +MCF_ParamInit(struct cli *cli) +{ + + MCF_AddParams(input_parspec); + + /* XXX: We do this twice, to get past any interdependencies */ + MCF_SetDefaults(NULL); + MCF_SetDefaults(cli); + params = &master; } From tfheen at projects.linpro.no Fri Feb 6 10:13:34 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 11:13:34 +0100 (CET) Subject: r3641 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206101334.168E21F74C5@projects.linpro.no> Author: tfheen Date: 2009-02-06 11:13:33 +0100 (Fri, 06 Feb 2009) New Revision: 3641 Added: branches/2.0/varnish-cache/bin/varnishd/param.h Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c Log: Merge r3441: Move parameter declaration into a .h file of its own. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 10:00:15 UTC (rev 3640) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 10:13:33 UTC (rev 3641) @@ -50,35 +50,15 @@ #include "mgt_cli.h" #include "heritage.h" +#include "param.h" #include "vss.h" #define MAGIC_INIT_STRING "\001" - -struct parspec; -static int margin; - -typedef void tweak_t(struct cli *, const struct parspec *, const char *arg); - -struct parspec { - const char *name; - tweak_t *func; - volatile void *priv; - unsigned umin; - unsigned umax; - const char *descr; - int flags; -#define DELAYED_EFFECT 1 -#define EXPERIMENTAL 2 -#define MUST_RESTART 4 -#define MUST_RELOAD 8 - const char *def; - const char *units; -}; - static struct params master; static int nparspec; static struct parspec const ** parspec; +static int margin; /*--------------------------------------------------------------------*/ Copied: branches/2.0/varnish-cache/bin/varnishd/param.h (from rev 3441, trunk/varnish-cache/bin/varnishd/param.h) =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/param.h (rev 0) +++ branches/2.0/varnish-cache/bin/varnishd/param.h 2009-02-06 10:13:33 UTC (rev 3641) @@ -0,0 +1,50 @@ +/*- + * 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: mgt_param.c 3440 2008-11-25 13:39:15Z phk $ + */ + +struct parspec; + +typedef void tweak_t(struct cli *, const struct parspec *, const char *arg); + +struct parspec { + const char *name; + tweak_t *func; + volatile void *priv; + unsigned umin; + unsigned umax; + const char *descr; + int flags; +#define DELAYED_EFFECT 1 +#define EXPERIMENTAL 2 +#define MUST_RESTART 4 +#define MUST_RELOAD 8 + const char *def; + const char *units; +}; From tfheen at projects.linpro.no Fri Feb 6 10:17:12 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 11:17:12 +0100 (CET) Subject: r3642 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206101712.A43FF1F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-06 11:17:12 +0100 (Fri, 06 Feb 2009) New Revision: 3642 Added: branches/2.0/varnish-cache/bin/varnishd/vparam.h Removed: branches/2.0/varnish-cache/bin/varnishd/param.h Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c Log: Merge r3442: Rename param.h to vparam.h Name that file "vparam.h" instead of "param.h" which is just too generic for comfort. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 10:13:33 UTC (rev 3641) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 10:17:12 UTC (rev 3642) @@ -50,7 +50,7 @@ #include "mgt_cli.h" #include "heritage.h" -#include "param.h" +#include "vparam.h" #include "vss.h" Deleted: branches/2.0/varnish-cache/bin/varnishd/param.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/param.h 2009-02-06 10:13:33 UTC (rev 3641) +++ branches/2.0/varnish-cache/bin/varnishd/param.h 2009-02-06 10:17:12 UTC (rev 3642) @@ -1,50 +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: mgt_param.c 3440 2008-11-25 13:39:15Z phk $ - */ - -struct parspec; - -typedef void tweak_t(struct cli *, const struct parspec *, const char *arg); - -struct parspec { - const char *name; - tweak_t *func; - volatile void *priv; - unsigned umin; - unsigned umax; - const char *descr; - int flags; -#define DELAYED_EFFECT 1 -#define EXPERIMENTAL 2 -#define MUST_RESTART 4 -#define MUST_RELOAD 8 - const char *def; - const char *units; -}; Copied: branches/2.0/varnish-cache/bin/varnishd/vparam.h (from rev 3442, trunk/varnish-cache/bin/varnishd/vparam.h) =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/vparam.h (rev 0) +++ branches/2.0/varnish-cache/bin/varnishd/vparam.h 2009-02-06 10:17:12 UTC (rev 3642) @@ -0,0 +1,50 @@ +/*- + * 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: mgt_param.c 3440 2008-11-25 13:39:15Z phk $ + */ + +struct parspec; + +typedef void tweak_t(struct cli *, const struct parspec *, const char *arg); + +struct parspec { + const char *name; + tweak_t *func; + volatile void *priv; + unsigned umin; + unsigned umax; + const char *descr; + int flags; +#define DELAYED_EFFECT 1 +#define EXPERIMENTAL 2 +#define MUST_RESTART 4 +#define MUST_RELOAD 8 + const char *def; + const char *units; +}; From tfheen at projects.linpro.no Fri Feb 6 10:20:54 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 11:20:54 +0100 (CET) Subject: r3643 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206102054.3A37B97C3A@projects.linpro.no> Author: tfheen Date: 2009-02-06 11:20:53 +0100 (Fri, 06 Feb 2009) New Revision: 3643 Added: branches/2.0/varnish-cache/bin/varnishd/mgt_pool.c Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am branches/2.0/varnish-cache/bin/varnishd/cache_pool.c branches/2.0/varnish-cache/bin/varnishd/mgt_param.c branches/2.0/varnish-cache/bin/varnishd/vparam.h Log: Merge r3443: Make it possible to declare paramters in other source files, and move the thread-pool related params into a new file mgt_pool.c as proof. The paramters happen in management process context, and should therefore not end up in cache_* files for namespace and sanity reasons. Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-06 10:17:12 UTC (rev 3642) +++ branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-06 10:20:53 UTC (rev 3643) @@ -45,6 +45,7 @@ mgt_child.c \ mgt_cli.c \ mgt_param.c \ + mgt_pool.c \ mgt_vcc.c \ rfc2616.c \ shmlog.c \ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-06 10:17:12 UTC (rev 3642) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-06 10:20:53 UTC (rev 3643) @@ -629,3 +629,5 @@ AZ(pthread_create(&tp, NULL, wrk_herder_thread, NULL)); AZ(pthread_detach(tp)); } + +/*--------------------------------------------------------------------*/ Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 10:17:12 UTC (rev 3642) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 10:20:53 UTC (rev 3643) @@ -55,13 +55,26 @@ #include "vss.h" #define MAGIC_INIT_STRING "\001" -static struct params master; +struct params master; static int nparspec; static struct parspec const ** parspec; static int margin; /*--------------------------------------------------------------------*/ +static const struct parspec * +mcf_findpar(const char *name) +{ + int i; + + for (i = 0; i < nparspec; i++) + if (!strcmp(parspec[i]->name, name)) + return (parspec[i]); + return (NULL); +} + +/*--------------------------------------------------------------------*/ + static void tweak_generic_timeout(struct cli *cli, volatile unsigned *dst, const char *arg) { @@ -99,7 +112,7 @@ /*--------------------------------------------------------------------*/ -static void +void tweak_timeout(struct cli *cli, const struct parspec *par, const char *arg) { volatile unsigned *dest; @@ -160,7 +173,7 @@ /*--------------------------------------------------------------------*/ -static void +void tweak_generic_uint(struct cli *cli, volatile unsigned *dest, const char *arg, unsigned min, unsigned max) { @@ -191,7 +204,7 @@ /*--------------------------------------------------------------------*/ -static void +void tweak_uint(struct cli *cli, const struct parspec *par, const char *arg) { volatile unsigned *dest; @@ -283,29 +296,6 @@ /*--------------------------------------------------------------------*/ static void -tweak_thread_pool_min(struct cli *cli, const struct parspec *par, - const char *arg) -{ - - tweak_generic_uint(cli, &master.wthread_min, arg, - par->umin, master.wthread_max); -} - -/*--------------------------------------------------------------------*/ - -static void -tweak_thread_pool_max(struct cli *cli, const struct parspec *par, - const char *arg) -{ - - (void)par; - tweak_generic_uint(cli, &master.wthread_max, arg, - master.wthread_min, UINT_MAX); -} - -/*--------------------------------------------------------------------*/ - -static void clean_listen_sock_head(struct listen_sock_head *lsh) { struct listen_sock *ls, *ls2; @@ -493,107 +483,6 @@ "flush of the cache use \"url.purge .\"", 0, "120", "seconds" }, - { "thread_pools", tweak_uint, &master.wthread_pools, 1, UINT_MAX, - "Number of worker thread pools.\n" - "\n" - "Increasing number of worker pools decreases lock " - "contention.\n" - "\n" - "Too many pools waste CPU and RAM resources, and more than " - "one pool for each CPU is probably detrimal to performance.\n" - "\n" - "Can be increased on the fly, but decreases require a " - "restart to take effect.", - EXPERIMENTAL | DELAYED_EFFECT, - "2", "pools" }, - { "thread_pool_max", tweak_thread_pool_max, NULL, 1, 0, - "The maximum number of worker threads in all pools combined.\n" - "\n" - "Do not set this higher than you have to, since excess " - "worker threads soak up RAM and CPU and generally just get " - "in the way of getting work done.\n", - EXPERIMENTAL | DELAYED_EFFECT, - "500", "threads" }, - { "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 2 threads.", - EXPERIMENTAL | DELAYED_EFFECT, - "5", "threads" }, - { "thread_pool_timeout", tweak_timeout, &master.wthread_timeout, 1, 0, - "Thread idle threshold.\n" - "\n" - "Threads in excess of thread_pool_min, which have been idle " - "for at least this long are candidates for purging.\n" - "\n" - "Minimum is 1 second.", - EXPERIMENTAL | DELAYED_EFFECT, - "300", "seconds" }, - { "thread_pool_purge_delay", - tweak_timeout, &master.wthread_purge_delay, 100, 0, - "Wait this long between purging threads.\n" - "\n" - "This controls the decay of thread pools when idle(-ish).\n" - "\n" - "Minimum is 100 milliseconds.", - EXPERIMENTAL | DELAYED_EFFECT, - "1000", "milliseconds" }, - { "thread_pool_add_threshold", - tweak_uint, &master.wthread_add_threshold, 0, UINT_MAX, - "Overflow threshold for worker thread creation.\n" - "\n" - "Setting this too low, will result in excess worker threads, " - "which is generally a bad idea.\n" - "\n" - "Setting it too high results in insuffient worker threads.\n", - EXPERIMENTAL, - "2", "requests" }, - { "thread_pool_add_delay", - tweak_timeout, &master.wthread_add_delay, 0, UINT_MAX, - "Wait at least this long between creating threads.\n" - "\n" - "Setting this too long results in insuffient worker threads.\n" - "\n" - "Setting this too short increases the risk of worker " - "thread pile-up.\n", - EXPERIMENTAL, - "20", "milliseconds" }, - { "thread_pool_fail_delay", - tweak_timeout, &master.wthread_fail_delay, 100, UINT_MAX, - "Wait at least this long after a failed thread creation " - "before trying to create another thread.\n" - "\n" - "Failure to create a worker thread is often a sign that " - " the end is near, because the process is running out of " - "RAM resources for thread stacks.\n" - "This delay tries to not rush it on needlessly.\n" - "\n" - "If thread creation failures are a problem, check that " - "thread_pool_max is not too high.\n" - "\n" - "It may also help to increase thread_pool_timeout and " - "thread_pool_min, to reduce the rate at which treads are " - "destroyed and later recreated.\n", - EXPERIMENTAL, - "200", "milliseconds" }, - { "overflow_max", tweak_uint, &master.overflow_max, 0, UINT_MAX, - "Percentage permitted overflow queue length.\n" - "\n" - "This sets the ratio of queued requests to worker threads, " - "above which sessions will be dropped instead of queued.\n", - EXPERIMENTAL, - "100", "%" }, - { "rush_exponent", tweak_uint, &master.rush_exponent, 2, UINT_MAX, - "How many parked request we start for each completed " - "request on the object.\n" - "NB: Even with the implict delay of delivery, " - "this parameter controls an exponential increase in " - "number of worker threads. ", - EXPERIMENTAL, - "3", "requests per request" }, { "sess_workspace", tweak_uint, &master.sess_workspace, 1024, UINT_MAX, "Bytes of HTTP protocol workspace allocated for sessions. " "This space must be big enough for the entire HTTP protocol " @@ -961,24 +850,21 @@ void MCF_ParamSet(struct cli *cli, const char *param, const char *val) { - int i; const struct parspec *pp; - for (i = 0; i < nparspec; i++) { - pp = parspec[i]; - if (!strcmp(pp->name, param)) { - pp->func(cli, pp, val); - if (cli->result != CLIS_OK) { - } else if (child_pid >= 0 && pp->flags & MUST_RESTART) { - cli_out(cli, "Change will take effect" - " when child is restarted"); - } else if (pp->flags & MUST_RELOAD) { - cli_out(cli, "Change will take effect" - " when VCL script is reloaded"); - } - MCF_ParamSync(); - return; + pp = mcf_findpar(param); + if (pp != NULL) { + pp->func(cli, pp, val); + if (cli->result != CLIS_OK) { + } else if (child_pid >= 0 && pp->flags & MUST_RESTART) { + cli_out(cli, "Change will take effect" + " when child is restarted"); + } else if (pp->flags & MUST_RELOAD) { + cli_out(cli, "Change will take effect" + " when VCL script is reloaded"); } + MCF_ParamSync(); + return; } cli_result(cli, CLIS_PARAM); cli_out(cli, "Unknown parameter \"%s\".", param); @@ -1015,6 +901,8 @@ n = 0; for (pp = ps; pp->name != NULL; pp++) { + if (mcf_findpar(pp->name) != NULL) + fprintf(stderr, "Duplicate param: %s\n", pp->name); if (strlen(pp->name) + 1 > margin) margin = strlen(pp->name) + 1; n++; @@ -1054,6 +942,7 @@ { MCF_AddParams(input_parspec); + MCF_AddParams(WRK_parspec); /* XXX: We do this twice, to get past any interdependencies */ MCF_SetDefaults(NULL); Copied: branches/2.0/varnish-cache/bin/varnishd/mgt_pool.c (from rev 3443, trunk/varnish-cache/bin/varnishd/mgt_pool.c) =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_pool.c (rev 0) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_pool.c 2009-02-06 10:20:53 UTC (rev 3643) @@ -0,0 +1,184 @@ +/*- + * 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_pool.c 3429 2008-11-24 17:47:21Z phk $ + * + * We maintain a number of worker thread pools, to spread lock contention. + * + * Pools can be added on the fly, as a means to mitigate lock contention, + * but can only be removed again by a restart. (XXX: we could fix that) + * + * Two threads herd the pools, one eliminates idle threads and aggregates + * statistics for all the pools, the other thread creates new threads + * on demand, subject to various numerical constraints. + * + * The algorithm for when to create threads needs to be reactive enough + * to handle startup spikes, but sufficiently attenuated to not cause + * thread pileups. This remains subject for improvement. + */ + +#include "config.h" +#include +#include + +#include "cli_priv.h" +#include "mgt.h" + +#include "vparam.h" +#include "heritage.h" + +/*--------------------------------------------------------------------*/ + +static void +tweak_thread_pool_min(struct cli *cli, const struct parspec *par, + const char *arg) +{ + + tweak_generic_uint(cli, &master.wthread_min, arg, + par->umin, master.wthread_max); +} + +/*--------------------------------------------------------------------*/ + +static void +tweak_thread_pool_max(struct cli *cli, const struct parspec *par, + const char *arg) +{ + + (void)par; + tweak_generic_uint(cli, &master.wthread_max, arg, + master.wthread_min, UINT_MAX); +} + +/*--------------------------------------------------------------------*/ + +const struct parspec WRK_parspec[] = { + { "thread_pools", tweak_uint, &master.wthread_pools, 1, UINT_MAX, + "Number of worker thread pools.\n" + "\n" + "Increasing number of worker pools decreases lock " + "contention.\n" + "\n" + "Too many pools waste CPU and RAM resources, and more than " + "one pool for each CPU is probably detrimal to performance.\n" + "\n" + "Can be increased on the fly, but decreases require a " + "restart to take effect.", + EXPERIMENTAL | DELAYED_EFFECT, + "2", "pools" }, + { "thread_pool_max", tweak_thread_pool_max, NULL, 1, 0, + "The maximum number of worker threads in all pools combined.\n" + "\n" + "Do not set this higher than you have to, since excess " + "worker threads soak up RAM and CPU and generally just get " + "in the way of getting work done.\n", + EXPERIMENTAL | DELAYED_EFFECT, + "500", "threads" }, + { "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 2 threads.", + EXPERIMENTAL | DELAYED_EFFECT, + "5", "threads" }, + { "thread_pool_timeout", tweak_timeout, &master.wthread_timeout, 1, 0, + "Thread idle threshold.\n" + "\n" + "Threads in excess of thread_pool_min, which have been idle " + "for at least this long are candidates for purging.\n" + "\n" + "Minimum is 1 second.", + EXPERIMENTAL | DELAYED_EFFECT, + "300", "seconds" }, + { "thread_pool_purge_delay", + tweak_timeout, &master.wthread_purge_delay, 100, 0, + "Wait this long between purging threads.\n" + "\n" + "This controls the decay of thread pools when idle(-ish).\n" + "\n" + "Minimum is 100 milliseconds.", + EXPERIMENTAL | DELAYED_EFFECT, + "1000", "milliseconds" }, + { "thread_pool_add_threshold", + tweak_uint, &master.wthread_add_threshold, 0, UINT_MAX, + "Overflow threshold for worker thread creation.\n" + "\n" + "Setting this too low, will result in excess worker threads, " + "which is generally a bad idea.\n" + "\n" + "Setting it too high results in insuffient worker threads.\n", + EXPERIMENTAL, + "2", "requests" }, + { "thread_pool_add_delay", + tweak_timeout, &master.wthread_add_delay, 0, UINT_MAX, + "Wait at least this long between creating threads.\n" + "\n" + "Setting this too long results in insuffient worker threads.\n" + "\n" + "Setting this too short increases the risk of worker " + "thread pile-up.\n", + EXPERIMENTAL, + "20", "milliseconds" }, + { "thread_pool_fail_delay", + tweak_timeout, &master.wthread_fail_delay, 100, UINT_MAX, + "Wait at least this long after a failed thread creation " + "before trying to create another thread.\n" + "\n" + "Failure to create a worker thread is often a sign that " + " the end is near, because the process is running out of " + "RAM resources for thread stacks.\n" + "This delay tries to not rush it on needlessly.\n" + "\n" + "If thread creation failures are a problem, check that " + "thread_pool_max is not too high.\n" + "\n" + "It may also help to increase thread_pool_timeout and " + "thread_pool_min, to reduce the rate at which treads are " + "destroyed and later recreated.\n", + EXPERIMENTAL, + "200", "milliseconds" }, + { "overflow_max", tweak_uint, &master.overflow_max, 0, UINT_MAX, + "Percentage permitted overflow queue length.\n" + "\n" + "This sets the ratio of queued requests to worker threads, " + "above which sessions will be dropped instead of queued.\n", + EXPERIMENTAL, + "100", "%" }, + { "rush_exponent", tweak_uint, &master.rush_exponent, 2, UINT_MAX, + "How many parked request we start for each completed " + "request on the object.\n" + "NB: Even with the implict delay of delivery, " + "this parameter controls an exponential increase in " + "number of worker threads. ", + EXPERIMENTAL, + "3", "requests per request" }, + { NULL, NULL, NULL } +}; + Modified: branches/2.0/varnish-cache/bin/varnishd/vparam.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/vparam.h 2009-02-06 10:17:12 UTC (rev 3642) +++ branches/2.0/varnish-cache/bin/varnishd/vparam.h 2009-02-06 10:20:53 UTC (rev 3643) @@ -48,3 +48,14 @@ const char *def; const char *units; }; + +void tweak_generic_uint(struct cli *cli, + volatile unsigned *dest, const char *arg, unsigned min, unsigned max); +void tweak_uint(struct cli *cli, const struct parspec *par, const char *arg); +void tweak_timeout(struct cli *cli, + const struct parspec *par, const char *arg); + +extern struct params master; + +/* mgt_pool.c */ +extern const struct parspec WRK_parspec[]; From tfheen at projects.linpro.no Fri Feb 6 10:25:20 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 11:25:20 +0100 (CET) Subject: r3644 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206102520.CFB6D97C3A@projects.linpro.no> Author: tfheen Date: 2009-02-06 11:25:20 +0100 (Fri, 06 Feb 2009) New Revision: 3644 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/cache_pool.c Log: Merge r3444: Add code to calculate a SHA256 over the hash string if param hash_sha256 is set. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 10:20:53 UTC (rev 3643) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 10:25:20 UTC (rev 3644) @@ -93,6 +93,8 @@ struct vrt_backend; struct cli_proto; struct ban; +struct SHA256Context; + struct lock { void *priv; }; // Opaque /*--------------------------------------------------------------------*/ @@ -202,6 +204,8 @@ unsigned char *wlb, *wlp, *wle; unsigned wlr; + + struct SHA256Context *sha256ctx; }; /* Work Request for worker thread ------------------------------------*/ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 10:20:53 UTC (rev 3643) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 10:25:20 UTC (rev 3644) @@ -66,6 +66,7 @@ #include "cache.h" #include "stevedore.h" #include "hash_slinger.h" +#include "vsha256.h" static const struct hash_slinger *hash; @@ -219,6 +220,8 @@ if (u) p += sizeof(const char *) - u; sp->hashptr = (void*)p; + if (params->hash_sha256) + SHA256_Init(sp->wrk->sha256ctx); } void @@ -241,6 +244,10 @@ sp->hashptr[sp->ihashptr + 1] = str + l; sp->ihashptr += 2; sp->lhashptr += l + 1; + if (params->hash_sha256) { + SHA256_Update(sp->wrk->sha256ctx, str, l); + SHA256_Update(sp->wrk->sha256ctx, "#", 1); + } } struct object * @@ -250,6 +257,7 @@ struct http *h; struct objhead *oh; struct object *o, *busy_o, *grace_o; + unsigned char sha256[32]; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); @@ -257,6 +265,10 @@ AN(hash); w = sp->wrk; h = sp->http; + if (params->hash_sha256) { + SHA256_Final(sha256, sp->wrk->sha256ctx); + /* WSP(sp, SLT_Debug, "SHA256: <%.32s>", sha256); */ + } HSH_Prealloc(sp); if (sp->objhead != NULL) { Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-06 10:20:53 UTC (rev 3643) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-06 10:25:20 UTC (rev 3644) @@ -72,6 +72,7 @@ #include "cache.h" #include "stevedore.h" #include "hash_slinger.h" +#include "vsha256.h" VTAILQ_HEAD(workerhead, worker); @@ -269,6 +270,7 @@ struct worker *w, ww; struct wq *qp; unsigned char wlog[params->shm_workspace]; + struct SHA256Context sha256; THR_SetName("cache-worker"); w = &ww; @@ -278,6 +280,7 @@ w->lastused = NAN; w->wlb = w->wlp = wlog; w->wle = wlog + sizeof wlog; + w->sha256ctx = &sha256; AZ(pthread_cond_init(&w->cond, NULL)); VSL(SLT_WorkThread, 0, "%p start", w); From tfheen at projects.linpro.no Fri Feb 6 10:28:55 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 11:28:55 +0100 (CET) Subject: r3645 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206102855.3C90D97C3A@projects.linpro.no> Author: tfheen Date: 2009-02-06 11:28:54 +0100 (Fri, 06 Feb 2009) New Revision: 3645 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/cache_pool.c Log: Merge r3445: Add asserts to find where WRW is leaking in ticket 390 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-06 10:25:20 UTC (rev 3644) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-06 10:28:54 UTC (rev 3645) @@ -176,6 +176,7 @@ sp->restarts = 0; RES_WriteObj(sp); + AZ(sp->wrk->wfd); HSH_Deref(sp->obj); sp->obj = NULL; sp->step = STP_DONE; @@ -383,6 +384,7 @@ AN(sp->director); AZ(sp->vbe); i = Fetch(sp); + AZ(sp->wrk->wfd); AZ(sp->vbe); AN(sp->director); @@ -799,6 +801,7 @@ assert(sp->handling == VCL_RET_PIPE); PipeSession(sp); + AZ(sp->wrk->wfd); sp->step = STP_DONE; return (0); } @@ -1025,6 +1028,7 @@ CHECK_OBJ_ORNULL(w->nobjhead, OBJHEAD_MAGIC); } WSL_Flush(w, 0); + AZ(w->wfd); } /* Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-06 10:25:20 UTC (rev 3644) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pool.c 2009-02-06 10:28:54 UTC (rev 3645) @@ -308,6 +308,8 @@ AN(w->wrq->func); w->lastused = NAN; w->wrq->func(w, w->wrq->priv); + AZ(w->wfd); + assert(w->wlp == w->wlb); w->wrq = NULL; Lck_Lock(&qp->mtx); } From tfheen at projects.linpro.no Fri Feb 6 10:33:42 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 11:33:42 +0100 (CET) Subject: r3646 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206103342.16CE997C3A@projects.linpro.no> Author: tfheen Date: 2009-02-06 11:33:41 +0100 (Fri, 06 Feb 2009) New Revision: 3646 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c Log: Merge r3446: Always release WRW, also on error. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-06 10:28:54 UTC (rev 3645) +++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-06 10:33:41 UTC (rev 3646) @@ -353,13 +353,8 @@ /* Deal with any message-body the request might have */ i = FetchReqBody(sp); - if (i > 0) { + if (WRW_FlushRelease(w) || i > 0) { VBE_ClosedFd(sp); - return (__LINE__); - } - - if (WRW_FlushRelease(w)) { - VBE_ClosedFd(sp); /* XXX: other cleanup ? */ return (__LINE__); } From tfheen at projects.linpro.no Fri Feb 6 10:39:34 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 11:39:34 +0100 (CET) Subject: r3647 - branches/2.0/varnish-cache/bin/varnishstat Message-ID: <20090206103934.8B78D1F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-06 11:39:34 +0100 (Fri, 06 Feb 2009) New Revision: 3647 Modified: branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c Log: Merge r3447: Supress stats in the curses mode until we have see a non-zero value. Modified: branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c 2009-02-06 10:33:41 UTC (rev 3646) +++ branches/2.0/varnish-cache/bin/varnishstat/varnishstat.c 2009-02-06 10:39:34 UTC (rev 3647) @@ -52,6 +52,7 @@ #define FIELD_EXCLUSION_CHARACTER '^' + static void myexp(double *acc, double val, unsigned *n, unsigned nmax) { @@ -95,6 +96,7 @@ do_curses(struct varnish_stats *VSL_stats, int delay, const char *fields) { struct varnish_stats copy; + struct varnish_stats seen; intmax_t ju; struct timeval tv; double tt, lt, hit, miss, ratio, up; @@ -104,6 +106,7 @@ int ch, line; memset(©, 0, sizeof copy); + memset(&seen, 0, sizeof seen); a1 = a2 = a3 = 0.0; n1 = n2 = n3 = 0; @@ -144,13 +147,18 @@ line = 3; #define MAC_STAT(n, t, f, d) \ - if ((fields == NULL || show_field( #n, fields )) && ++line < LINES) { \ + if ((fields == NULL || show_field( #n, fields )) && line < LINES) { \ ju = VSL_stats->n; \ - if (f == 'a') { \ + if (ju == 0 && !seen.n) { \ + } else if (f == 'a') { \ + seen.n = 1; \ + line++; \ mvprintw(line, 0, "%12ju %12.2f %12.2f %s\n", \ ju, (ju - (intmax_t)copy.n)/lt, ju / up, d); \ copy.n = ju; \ } else { \ + seen.n = 1; \ + line++; \ mvprintw(line, 0, "%12ju %12s %12s %s\n", \ ju, ". ", ". ", d); \ } \ From tfheen at projects.linpro.no Fri Feb 6 10:42:40 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 11:42:40 +0100 (CET) Subject: r3648 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206104240.3FE7F1F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-06 11:42:40 +0100 (Fri, 06 Feb 2009) New Revision: 3648 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c Log: Merge r3448: Assert objhead We cannot gain a reference to an object unless it has an objhead, assert that we have one. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 10:39:34 UTC (rev 3647) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 10:42:40 UTC (rev 3648) @@ -427,14 +427,11 @@ CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oh = o->objhead; - if (oh != NULL) { - CHECK_OBJ(oh, OBJHEAD_MAGIC); - Lck_Lock(&oh->mtx); - } + CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); + Lck_Lock(&oh->mtx); assert(o->refcnt > 0); o->refcnt++; - if (oh != NULL) - Lck_Unlock(&oh->mtx); + Lck_Unlock(&oh->mtx); } void From tfheen at projects.linpro.no Fri Feb 6 11:16:08 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 12:16:08 +0100 (CET) Subject: r3649 - in branches/2.0/varnish-cache: include lib/libvarnish Message-ID: <20090206111608.618871F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 12:16:08 +0100 (Fri, 06 Feb 2009) New Revision: 3649 Modified: branches/2.0/varnish-cache/include/vsha256.h branches/2.0/varnish-cache/lib/libvarnish/vsha256.c Log: Merge r3449+3451: Shut FlexeLint up about SHA256 implementation. Modified: branches/2.0/varnish-cache/include/vsha256.h =================================================================== --- branches/2.0/varnish-cache/include/vsha256.h 2009-02-06 10:42:40 UTC (rev 3648) +++ branches/2.0/varnish-cache/include/vsha256.h 2009-02-06 11:16:08 UTC (rev 3649) @@ -33,7 +33,7 @@ typedef struct SHA256Context { uint32_t state[8]; - uint32_t count[2]; + uint64_t count; unsigned char buf[64]; } SHA256_CTX; Modified: branches/2.0/varnish-cache/lib/libvarnish/vsha256.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-06 10:42:40 UTC (rev 3648) +++ branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-06 11:16:08 UTC (rev 3649) @@ -33,18 +33,19 @@ #ifdef HAVE_ENDIAN_H #include -#define BYTE_ORDER __BYTE_ORDER -#define BIG_ENDIAN __BIG_ENDIAN +#define VBYTE_ORDER __BYTE_ORDER +#define VBIG_ENDIAN __BIG_ENDIAN #endif #ifdef HAVE_SYS_ENDIAN_H #include -#define BYTE_ORDER _BYTE_ORDER -#define BIG_ENDIAN _BIG_ENDIAN +#define VBYTE_ORDER _BYTE_ORDER +#define VBIG_ENDIAN _BIG_ENDIAN #endif +#include "libvarnish.h" #include "vsha256.h" -#if defined(BYTE_ORDER) && BYTE_ORDER == BIG_ENDIAN +#if defined(VBYTE_ORDER) && VBYTE_ORDER == VBIG_ENDIAN /* Copy a vector of big-endian uint32_t into a vector of bytes */ #define be32enc_vect(dst, src, len) \ @@ -61,7 +62,7 @@ { unsigned char const *p = (unsigned char const *)pp; - return ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); + return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); } static __inline void @@ -75,6 +76,15 @@ p[3] = u & 0xff; } +static __inline void +mybe64enc(void *pp, uint64_t u) +{ + unsigned char *p = (unsigned char *)pp; + + mybe32enc(p, u >> 32); + mybe32enc(p + 4, u & 0xffffffff); +} + /* * Encode a length len/4 vector of (uint32_t) into a length len vector of * (unsigned char) in big-endian form. Assumes len is a multiple of 4. @@ -126,7 +136,7 @@ S[(66 - i) % 8], S[(67 - i) % 8], \ S[(68 - i) % 8], S[(69 - i) % 8], \ S[(70 - i) % 8], S[(71 - i) % 8], \ - W[i] + k) + (W[i] + k)) /* * SHA256 block compression function. The 256-bit state is transformed via @@ -219,7 +229,7 @@ state[i] += S[i]; } -static unsigned char PAD[64] = { +static const unsigned char PAD[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -234,14 +244,20 @@ uint32_t r, plen; /* + * Rescale from bytes to bits + */ + ctx->count <<= 3; + + /* * Convert length to a vector of bytes -- we do this now rather * than later because the length will change after we pad. */ - be32enc_vect(len, ctx->count, 8); + mybe64enc(len, ctx->count); /* Add 1--64 bytes so that the resulting length is 56 mod 64 */ - r = (ctx->count[1] >> 3) & 0x3f; + r = ctx->count & 0x3f; plen = (r < 56) ? (56 - r) : (120 - r); + assert(plen <= sizeof PAD); SHA256_Update(ctx, PAD, (size_t)plen); /* Add the terminating bit-count */ @@ -254,7 +270,7 @@ { /* Zero bits processed so far */ - ctx->count[0] = ctx->count[1] = 0; + ctx->count = 0; /* Magic initialization constants */ ctx->state[0] = 0x6A09E667; @@ -271,43 +287,23 @@ void SHA256_Update(SHA256_CTX * ctx, const void *in, size_t len) { - uint32_t bitlen[2]; - uint32_t r; + uint32_t r, l; const unsigned char *src = in; /* Number of bytes left in the buffer from previous updates */ - r = (ctx->count[1] >> 3) & 0x3f; - - /* Convert the length into a number of bits */ - bitlen[1] = ((uint32_t)len) << 3; - bitlen[0] = (uint32_t)(len >> 29); - - /* Update number of bits */ - if ((ctx->count[1] += bitlen[1]) < bitlen[1]) - ctx->count[0]++; - ctx->count[0] += bitlen[0]; - - /* Handle the case where we don't need to perform any transforms */ - if (len < 64 - r) { - memcpy(&ctx->buf[r], src, len); - return; + r = ctx->count & 0x3f; + while (len > 0) { + l = 64 - r; + if (l > len) + l = len; + memcpy(&ctx->buf[r], src, l); + len -= l; + src += l; + ctx->count += l; + r = ctx->count & 0x3f; + if (r == 0) + SHA256_Transform(ctx->state, ctx->buf); } - - /* Finish the current block */ - memcpy(&ctx->buf[r], src, 64 - r); - SHA256_Transform(ctx->state, ctx->buf); - src += 64 - r; - len -= 64 - r; - - /* Perform complete blocks */ - while (len >= 64) { - SHA256_Transform(ctx->state, src); - src += 64; - len -= 64; - } - - /* Copy left over data into buffer */ - memcpy(ctx->buf, src, len); } /* From tfheen at projects.linpro.no Fri Feb 6 11:27:55 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 12:27:55 +0100 (CET) Subject: r3650 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206112755.ACE0F1F74B2@projects.linpro.no> Author: tfheen Date: 2009-02-06 12:27:55 +0100 (Fri, 06 Feb 2009) New Revision: 3650 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/cache_lck.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c branches/2.0/varnish-cache/bin/varnishd/hash_classic.c branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c Log: Merge r3450: Various minor cleanups while we wait... Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 11:16:08 UTC (rev 3649) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 11:27:55 UTC (rev 3650) @@ -509,7 +509,7 @@ void Lck__Unlock(struct lock *lck, const char *p, const char *f, int l); int Lck__Trylock(struct lock *lck, const char *p, const char *f, int l); void Lck__New(struct lock *lck, const char *w); -void Lck__Assert(struct lock *lck, int held); +void Lck__Assert(const struct lock *lck, int held); /* public interface: */ void LCK_Init(void); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 11:16:08 UTC (rev 3649) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 11:27:55 UTC (rev 3650) @@ -83,6 +83,8 @@ HSH_Prealloc(struct sess *sp) { struct worker *w; + struct objhead *oh; + struct object *o; struct storage *st; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -90,47 +92,39 @@ w = sp->wrk; if (w->nobjhead == NULL) { - w->nobjhead = calloc(sizeof *w->nobjhead, 1); - XXXAN(w->nobjhead); - w->nobjhead->magic = OBJHEAD_MAGIC; - w->nobjhead->refcnt = 1; - VTAILQ_INIT(&w->nobjhead->objects); - VTAILQ_INIT(&w->nobjhead->waitinglist); - Lck_New(&w->nobjhead->mtx); + ALLOC_OBJ(oh, OBJHEAD_MAGIC); + XXXAN(oh); + oh->refcnt = 1; + VTAILQ_INIT(&oh->objects); + VTAILQ_INIT(&oh->waitinglist); + Lck_New(&oh->mtx); + w->nobjhead = oh; VSL_stats->n_objecthead++; } else CHECK_OBJ_NOTNULL(w->nobjhead, OBJHEAD_MAGIC); -#if 0 - /* Make sure there is space enough for the hash-string */ - if (w->nobjhead->hashlen < sp->lhashptr) { - w->objhead->hash = realloc(w->objhead->hash, sp->lhashptr); - w->objhead->hashlen = sp->lhashptr; - AN(w->objhead->hash); - } -#endif - if (w->nobj == NULL) { st = STV_alloc(sp, params->obj_workspace); XXXAN(st); assert(st->space > sizeof *w->nobj); - w->nobj = (void *)st->ptr; /* XXX: align ? */ - st->len = sizeof *w->nobj; - memset(w->nobj, 0, sizeof *w->nobj); - w->nobj->objstore = st; - WS_Init(w->nobj->ws_o, "obj", + o = (void *)st->ptr; /* XXX: align ? */ + st->len = sizeof *o; + memset(o, 0, sizeof *o); + o->objstore = st; + WS_Init(o->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; - w->nobj->refcnt = 1; - w->nobj->grace = NAN; - w->nobj->entered = NAN; - VTAILQ_INIT(&w->nobj->store); - VTAILQ_INIT(&w->nobj->esibits); + WS_Assert(o->ws_o); + http_Setup(o->http, o->ws_o); + o->magic = OBJECT_MAGIC; + o->http->magic = HTTP_MAGIC; + o->busy = 1; + o->refcnt = 1; + o->grace = NAN; + o->entered = NAN; + VTAILQ_INIT(&o->store); + VTAILQ_INIT(&o->esibits); + w->nobj = o; VSL_stats->n_object++; } else Modified: branches/2.0/varnish-cache/bin/varnishd/cache_lck.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_lck.c 2009-02-06 11:16:08 UTC (rev 3649) +++ branches/2.0/varnish-cache/bin/varnishd/cache_lck.c 2009-02-06 11:27:55 UTC (rev 3650) @@ -125,7 +125,7 @@ } void -Lck__Assert(struct lock *lck, int held) +Lck__Assert(const struct lock *lck, int held) { struct ilck *ilck; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c 2009-02-06 11:16:08 UTC (rev 3649) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_re.c 2009-02-06 11:27:55 UTC (rev 3650) @@ -43,7 +43,6 @@ #include "shmlog.h" #include "vrt.h" -#include "vsb.h" #include "vcl.h" #include "cache.h" Modified: branches/2.0/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-06 11:16:08 UTC (rev 3649) +++ branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-06 11:27:55 UTC (rev 3650) @@ -124,7 +124,7 @@ int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_ORNULL(noh, OBJHEAD_MAGIC); + CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC); digest = ~0U; for (u = 0; u < sp->ihashptr; u += 2) { Modified: branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-06 11:16:08 UTC (rev 3649) +++ branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-06 11:27:55 UTC (rev 3650) @@ -71,6 +71,8 @@ struct objhead *oh; int i; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC); Lck_Lock(&hsl_mtx); VTAILQ_FOREACH(oh, &hsl_head, hoh_list) { i = HSH_Compare(sp, oh); From tfheen at projects.linpro.no Fri Feb 6 11:31:02 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 12:31:02 +0100 (CET) Subject: r3651 - in branches/2.0/varnish-cache: include lib/libvarnish Message-ID: <20090206113102.A069097C3A@projects.linpro.no> Author: tfheen Date: 2009-02-06 12:31:02 +0100 (Fri, 06 Feb 2009) New Revision: 3651 Modified: branches/2.0/varnish-cache/include/vsha256.h branches/2.0/varnish-cache/lib/libvarnish/vsha256.c Log: Merge r3452: Fix an embarrasing bug in my Flexlinting of this code yesterday, and add a couple of test-vectors to avoid it happening again. And now for the funny and educational story: In july of 1994, I added the "libmd" to FreeBSD, containing the MD2, MD4 and MD5 functions from RFC 1319, RFC 1186 and RFC1321. I meticulously replicated the test-vectors from the RFCs, so that "make test" would validate the result. Duing the intermediate 14 years, various slight shifts and adjustments to things like the make(1) programs defaults, the shared library resolution algorithm and other totally unrelated things, meant that "make test" now tests the installed version of the library, rather than the version you just built with "make all". Needless to say, when I tested my patch yesterday, I didn't install the built version, wanting first to hear what Colin Percival, FreeBSD Security Wiz, generally swell fella and the guy who wrote this SHA256 implementation, thought of these "stylistic" patches. Modified: branches/2.0/varnish-cache/include/vsha256.h =================================================================== --- branches/2.0/varnish-cache/include/vsha256.h 2009-02-06 11:27:55 UTC (rev 3650) +++ branches/2.0/varnish-cache/include/vsha256.h 2009-02-06 11:31:02 UTC (rev 3651) @@ -41,6 +41,7 @@ void SHA256_Init(SHA256_CTX *); void SHA256_Update(SHA256_CTX *, const void *, size_t); void SHA256_Final(unsigned char [32], SHA256_CTX *); +void SHA256_Test(void); __END_DECLS #endif /* !_SHA256_H_ */ Modified: branches/2.0/varnish-cache/lib/libvarnish/vsha256.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-06 11:27:55 UTC (rev 3650) +++ branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-06 11:31:02 UTC (rev 3651) @@ -244,20 +244,15 @@ uint32_t r, plen; /* - * Rescale from bytes to bits + * Convert length to bits and encode as a vector of bytes + * -- we do this now rather than later because the length + * will change after we pad. */ - ctx->count <<= 3; + mybe64enc(len, ctx->count << 3); - /* - * Convert length to a vector of bytes -- we do this now rather - * than later because the length will change after we pad. - */ - mybe64enc(len, ctx->count); - /* Add 1--64 bytes so that the resulting length is 56 mod 64 */ r = ctx->count & 0x3f; plen = (r < 56) ? (56 - r) : (120 - r); - assert(plen <= sizeof PAD); SHA256_Update(ctx, PAD, (size_t)plen); /* Add the terminating bit-count */ @@ -323,3 +318,43 @@ /* Clear the context state */ memset((void *)ctx, 0, sizeof(*ctx)); } + +/* + * A few test-vectors, just in case + */ + +static const struct sha256test { + const char *input; + const unsigned char output[32]; +} sha256test[] = { + { "", + {0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, + 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, + 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55} }, + { "message digest", + {0xf7, 0x84, 0x6f, 0x55, 0xcf, 0x23, 0xe1, 0x4e, 0xeb, 0xea, 0xb5, + 0xb4, 0xe1, 0x55, 0x0c, 0xad, 0x5b, 0x50, 0x9e, 0x33, 0x48, 0xfb, + 0xc4, 0xef, 0xa3, 0xa1, 0x41, 0x3d, 0x39, 0x3c, 0xb6, 0x50} }, + { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + {0xdb, 0x4b, 0xfc, 0xbd, 0x4d, 0xa0, 0xcd, 0x85, 0xa6, 0x0c, 0x3c, + 0x37, 0xd3, 0xfb, 0xd8, 0x80, 0x5c, 0x77, 0xf1, 0x5f, 0xc6, 0xb1, + 0xfd, 0xfe, 0x61, 0x4e, 0xe0, 0xa7, 0xc8, 0xfd, 0xb4, 0xc0} }, + { NULL } +}; + + +void +SHA256_Test(void) +{ + struct SHA256Context c; + const struct sha256test *p; + unsigned char o[32]; + + for (p = sha256test; p->input != NULL; p++) { + SHA256_Init(&c); + SHA256_Update(&c, p->input, strlen(p->input)); + SHA256_Final(o, &c); + assert(!memcmp(o, p->output, 32)); + } +} + From tfheen at projects.linpro.no Fri Feb 6 11:38:07 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 12:38:07 +0100 (CET) Subject: r3652 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090206113807.E53541F74B2@projects.linpro.no> Author: tfheen Date: 2009-02-06 12:38:07 +0100 (Fri, 06 Feb 2009) New Revision: 3652 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00008.vtc Log: Merge r3453: Wrap some long lines Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00008.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00008.vtc 2009-02-06 11:31:02 UTC (rev 3651) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00008.vtc 2009-02-06 11:38:07 UTC (rev 3652) @@ -5,7 +5,8 @@ server s1 { rxreq expect req.url == "/foo" - txresp -hdr "Last-Modified: Thu, 26 Jun 2008 12:00:01 GMT" -body "11111\n" + txresp -hdr "Last-Modified: Thu, 26 Jun 2008 12:00:01 GMT" \ + -body "11111\n" } -start varnish v1 -vcl+backend { } -start @@ -16,15 +17,18 @@ expect resp.status == 200 expect resp.http.content-length == 6 - txreq -url "/foo" -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:00 GMT" + txreq -url "/foo" \ + -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:00 GMT" rxresp expect resp.status == 200 - txreq -url "/foo" -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:01 GMT" + txreq -url "/foo" \ + -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:01 GMT" rxresp expect resp.status == 304 - txreq -url "/foo" -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:02 GMT" + txreq -url "/foo" \ + -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:02 GMT" rxresp expect resp.status == 304 } From tfheen at projects.linpro.no Fri Feb 6 11:47:25 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 12:47:25 +0100 (CET) Subject: r3653 - in branches/2.0/varnish-cache: bin/varnishd include Message-ID: <20090206114725.3CB7A1F7499@projects.linpro.no> Author: tfheen Date: 2009-02-06 12:47:24 +0100 (Fri, 06 Feb 2009) New Revision: 3653 Added: branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h branches/2.0/varnish-cache/bin/varnishd/mgt_param.c branches/2.0/varnish-cache/bin/varnishd/varnishd.c branches/2.0/varnish-cache/include/stat_field.h Log: Merge r3454+r3455: Add preliminary version of lock-less tree based lookup (see below) Enable SHA256 digests by default, and put it in the objhead. This increases the size of the objhead by 32 bytes, but may drop a bit again later, when other now unnecessary fields go away. Test SHA256 for correct operation on startup. About the "critbit" lookup: To enable this, use "-hcritbit" argument. "Crit Bit" trees, are also known under various other names, the original version of the idea is probably the PATRICIA tree. The basic concept is a tree structure which has nodes only where necessary to tell the indices apart. Our version of it, has some additional bells and whistles. First lookups do not require any locks until we reach the objhead we were looking for, or until we need to insert one which wasn't there. Second, the branch nodes are part of the objhead, as all but the very first will need one, this saves malloc operations big time. Now the down-sides: There are still missing bits, amongst these the "cooling off" list, for objheads that have been dereferenced, but where the branch-node is not. Currently we just leak that memory. There is a race relating to node deref and unlocked lookup that is not closed, weird things may happen until I fix it. I'd be interested to hear how long it survives before it croaks, but apart from that, would not advocate that you use it, until I fix those remaining issues. Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-06 11:38:07 UTC (rev 3652) +++ branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-06 11:47:24 UTC (rev 3653) @@ -40,6 +40,7 @@ cache_vrt_re.c \ cache_ws.c \ hash_classic.c \ + hash_critbit.c \ hash_simple_list.c \ instance.c \ mgt_child.c \ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 11:38:07 UTC (rev 3652) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 11:47:24 UTC (rev 3653) @@ -251,7 +251,6 @@ struct http *h; struct objhead *oh; struct object *o, *busy_o, *grace_o; - unsigned char sha256[32]; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); @@ -259,12 +258,14 @@ AN(hash); w = sp->wrk; h = sp->http; + + HSH_Prealloc(sp); if (params->hash_sha256) { - SHA256_Final(sha256, sp->wrk->sha256ctx); + SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); + sp->wrk->nobjhead->digest_len = 32; /* WSP(sp, SLT_Debug, "SHA256: <%.32s>", sha256); */ } - - HSH_Prealloc(sp); + if (sp->objhead != NULL) { CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC); oh = sp->objhead; Copied: branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c (from rev 3455, trunk/varnish-cache/bin/varnishd/hash_critbit.c) =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c (rev 0) +++ branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-06 11:47:24 UTC (rev 3653) @@ -0,0 +1,418 @@ +/*- + * 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$ + * + * A Crit Bit tree based hash + */ + +#include "config.h" + +#include +#include +#include + +#include "shmlog.h" +#include "cache.h" +#include "hash_slinger.h" + +static struct lock hcb_mtx; + +/********************************************************************** + * Table for finding out how many bits two bytes have in common, + * counting from the MSB towards the LSB. + * ie: + * hcb_bittbl[0x01 ^ 0x22] == 2 + * hcb_bittbl[0x10 ^ 0x0b] == 3 + * + */ + +static unsigned char hcb_bittbl[256]; + +static unsigned char +hcb_bits(unsigned char x, unsigned char y) +{ + return hcb_bittbl[x ^ y]; +} + +static void +hcb_build_bittbl(void) +{ + unsigned x, y; + + y = 0; + for (x = 0; x < 8; x++) + for (; y < (1U << x); y++) + hcb_bittbl[y] = 8 - x; + + /* Quick asserts for sanity check */ + assert(hcb_bits(0x34, 0x34) == 8); + assert(hcb_bits(0xaa, 0x55) == 0); + assert(hcb_bits(0x01, 0x22) == 2); + assert(hcb_bits(0x10, 0x0b) == 3); +} + +/********************************************************************** + * For space reasons we overload the two pointers with two different + * kinds of of pointers. We cast them to uintptr_t's and abuse the + * low two bits to tell them apart, assuming that Varnish will never + * run on machines with less than 32bit alignment. + * + * Asserts will explode if these assumptions are not met. + */ + +struct hcb_y { + unsigned short critbit; + unsigned char ptr; + unsigned char bitmask; + uintptr_t leaf[2]; +}; + +#define HCB_BIT_NODE (1<<0) +#define HCB_BIT_Y (1<<1) + +struct hcb_root { + uintptr_t origo; + unsigned cmps; +}; + +static struct hcb_root hcb_root; + +/********************************************************************** + * Pointer accessor functions + */ +static int +hcb_is_node(uintptr_t u) +{ + + return (u & HCB_BIT_NODE); +} + +static int +hcb_is_y(uintptr_t u) +{ + + return (u & HCB_BIT_Y); +} + +static uintptr_t +hcb_r_node(struct objhead *n) +{ + + assert(!((uintptr_t)n & (HCB_BIT_NODE|HCB_BIT_Y))); + return (HCB_BIT_NODE | (uintptr_t)n); +} + +static struct objhead * +hcb_l_node(uintptr_t u) +{ + + assert(u & HCB_BIT_NODE); + assert(!(u & HCB_BIT_Y)); + return ((struct objhead *)(u & ~HCB_BIT_NODE)); +} + +static uintptr_t +hcb_r_y(struct hcb_y *y) +{ + + assert(!((uintptr_t)y & (HCB_BIT_NODE|HCB_BIT_Y))); + return (HCB_BIT_Y | (uintptr_t)y); +} + +static struct hcb_y * +hcb_l_y(uintptr_t u) +{ + + assert(!(u & HCB_BIT_NODE)); + assert(u & HCB_BIT_Y); + return ((struct hcb_y *)(u & ~HCB_BIT_Y)); +} + +/**********************************************************************/ + +static unsigned +hcb_crit_bit(const struct objhead *oh1, const struct objhead *oh2, struct hcb_y *y) +{ + unsigned u, r; + + for (u = 0; u < oh1->digest_len && oh1->digest[u] == oh2->digest[u]; u++) + ; + r = hcb_bits(oh1->digest[u], oh2->digest[u]); + y->ptr = u; + y->bitmask = 0x80 >> r; + y->critbit = u * 8 + r; + return (y->critbit); +} + +/**********************************************************************/ + +static struct objhead * +hcb_insert(struct hcb_root *root, struct objhead *oh, int has_lock) +{ + uintptr_t *p; + struct hcb_y *y, *y2; + struct objhead *oh2; + unsigned s, s2; + + + p = &root->origo; + if (*p == 0) { + if (!has_lock) + return (NULL); + *p = hcb_r_node(oh); + return (oh); + } + + while(hcb_is_y(*p)) { + y = hcb_l_y(*p); + if (y->ptr > oh->digest_len) + s = 0; + else + s = (oh->digest[y->ptr] & y->bitmask) != 0; + assert(s < 2); + root->cmps++; + p = &y->leaf[s]; + } + + assert(hcb_is_node(*p)); + + /* We found a node, does it match ? */ + oh2 = hcb_l_node(*p); + if (oh2->digest_len == oh->digest_len && + !memcmp(oh2->digest, oh->digest, oh->digest_len)) + return (oh2); + + if (!has_lock) + return (NULL); + + /* Insert */ + + y2 = (void*)&oh->u; + memset(y2, 0, sizeof *y2); + (void)hcb_crit_bit(oh, hcb_l_node(*p), y2); + s2 = (oh->digest[y2->ptr] & y2->bitmask) != 0; + assert(s2 < 2); + y2->leaf[s2] = hcb_r_node(oh); + s2 = 1-s2; + + p = &root->origo; + assert(*p != 0); + + while(hcb_is_y(*p)) { + y = hcb_l_y(*p); + if (y->critbit > y2->critbit) + break; + if (y->ptr > oh->digest_len) + s = 0; + else + s = (oh->digest[y->ptr] & y->bitmask) != 0; + assert(s < 2); + root->cmps++; + p = &y->leaf[s]; + } + y2->leaf[s2] = *p; + *p = hcb_r_y(y2); + return(oh); +} + +/**********************************************************************/ + +static void +hcb_delete(struct hcb_root *r, struct objhead *oh) +{ + struct hcb_y *y; + uintptr_t *p; + unsigned s; + + if (r->origo == hcb_r_node(oh)) { + r->origo = 0; + return; + } + p = &r->origo; + assert(hcb_is_y(*p)); + + y = NULL; + while(hcb_is_y(*p)) { + y = hcb_l_y(*p); + if (y->ptr > oh->digest_len) + s = 0; + else + s = (oh->digest[y->ptr] & y->bitmask) != 0; + assert(s < 2); + if (y->leaf[s] == hcb_r_node(oh)) { + *p = y->leaf[1 - s]; + y->leaf[0] = 0; + y->leaf[1] = 0; + return; + } + r->cmps++; + p = &y->leaf[s]; + } +abort(); + *p = y->leaf[1 - s]; +} + +/**********************************************************************/ + +static void +dumptree(uintptr_t p, int indent, FILE *fd) +{ + int i; + const struct objhead *oh; + const struct hcb_y *y; + + if (p == 0) + return; + if (hcb_is_node(p)) { + oh = hcb_l_node(p); + fprintf(fd, "%*.*sN %u %u r%d <%02x%02x%02x...> <%s>\n", + indent, indent, "", oh->digest_len, indent / 2, + oh->refcnt, + oh->digest[0], oh->digest[1], oh->digest[2], + oh->hash); + return; + } + assert(hcb_is_y(p)); + y = hcb_l_y(p); + fprintf(fd, "%*.*sY c %u p %u b %02x i %d\n", + indent, indent, "", + y->critbit, y->ptr, y->bitmask, indent / 2); + indent += 2; + for (i = 0; i < 2; i++) + dumptree(y->leaf[i], indent, fd); +} + +static void +dump(const struct hcb_root *root, FILE *fd) +{ + fprintf(fd, "-------------\n"); + dumptree(root->origo, 0, fd); + fprintf(fd, "-------------\n"); + fflush(fd); +} + + +/**********************************************************************/ + +static void +hcb_start(void) +{ + struct objhead *oh = NULL; + + (void)oh; + assert(params->hash_sha256); + assert(sizeof(struct hcb_y) <= sizeof(oh->u)); + memset(&hcb_root, 0, sizeof hcb_root); + hcb_build_bittbl(); + Lck_New(&hcb_mtx); +} + +static int +hcb_deref(struct objhead *oh) +{ + int r; + struct hcb_y *y; + + r = 1; + CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); + Lck_Lock(&oh->mtx); + if (--oh->refcnt == 0) { + Lck_Lock(&hcb_mtx); + hcb_delete(&hcb_root, oh); + y = (void*)&oh->u; + if (y->leaf[0] == 0 && y->leaf[1] == 0) + r = 0; + else { + /* XXX: on waiting list */ + } + Lck_Unlock(&hcb_mtx); + } + Lck_Unlock(&oh->mtx); + if (0) { + fprintf(stderr, "%s %d %d <%s>\n", __func__, __LINE__, r, oh->hash); + dump(&hcb_root, stderr); + } + return (r); +} + +static struct objhead * +hcb_lookup(const struct sess *sp, struct objhead *noh) +{ + struct objhead *oh; + + assert(params->hash_sha256); + oh = hcb_insert(&hcb_root, noh, 0); + if (oh != NULL) { + /* Assert that we didn't muck with the tree without lock */ + assert(oh != noh); + Lck_Lock(&oh->mtx); + oh->refcnt++; + Lck_Unlock(&oh->mtx); + VSL_stats->hcb_nolock++; + if (0) { + fprintf(stderr, "%s %d\n", __func__, __LINE__); + dump(&hcb_root, stderr); + } + return (oh); + } + + /* + * Try again, holding lock and fully ready objhead, so that if + * somebody else beats us back, they do not get surprised. + */ + HSH_Copy(sp, noh); + Lck_Lock(&hcb_mtx); + oh = hcb_insert(&hcb_root, noh, 1); + if (oh == noh) { + VSL_stats->hcb_insert++; + if (0) { + fprintf(stderr, "%s %d\n", __func__, __LINE__); + dump(&hcb_root, stderr); + } + } else { + free(noh->hash); + noh->hash = NULL; + noh->hashlen = 0; + VSL_stats->hcb_lock++; + if (0) { + fprintf(stderr, "%s %d\n", __func__, __LINE__); + dump(&hcb_root, stderr); + } + } + Lck_Unlock(&hcb_mtx); + return (oh); +} + + +struct hash_slinger hcb_slinger = { + .magic = SLINGER_MAGIC, + .name = "critbit", + .start = hcb_start, + .lookup = hcb_lookup, + .deref = hcb_deref, +}; Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-06 11:38:07 UTC (rev 3652) +++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-06 11:47:24 UTC (rev 3653) @@ -73,14 +73,24 @@ VTAILQ_HEAD(,object) objects; char *hash; unsigned hashlen; + unsigned char digest[32]; + unsigned char digest_len; VTAILQ_HEAD(, sess) waitinglist; - /*------------------------------------------------------------ - * The fields below are for the sole private use of the hash - * implementation. + /*---------------------------------------------------- + * The fields below are for the sole private use of + * the hash implementation(s). */ - VTAILQ_ENTRY(objhead) hoh_list; - void *hoh_head; - unsigned hoh_digest; + union { + void *filler[3]; + struct { + VTAILQ_ENTRY(objhead) u_n_hoh_list; + void *u_n_hoh_head; + unsigned u_n_hoh_digest; + } n; + } u; +#define hoh_list u.n.u_n_hoh_list +#define hoh_head u.n.u_n_hoh_head +#define hoh_digest u.n.u_n_hoh_digest }; #endif /* VARNISH_CACHE_CHILD */ Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 11:38:07 UTC (rev 3652) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 11:47:24 UTC (rev 3653) @@ -713,7 +713,7 @@ { "hash_sha256", tweak_bool, &master.hash_sha256, 0, 0, "Use SHA256 compression of hash-strings", 0, - "off", "bool" }, + "on", "bool" }, { "log_hashstring", tweak_bool, &master.log_hash, 0, 0, "Log the hash string to shared memory log.\n", 0, Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-06 11:38:07 UTC (rev 3652) +++ branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-06 11:47:24 UTC (rev 3653) @@ -59,6 +59,7 @@ #include "vsb.h" #include "vpf.h" +#include "vsha256.h" #include "cli.h" #include "cli_priv.h" @@ -157,11 +158,13 @@ extern struct hash_slinger hsl_slinger; extern struct hash_slinger hcl_slinger; +extern struct hash_slinger hcb_slinger; static const struct choice hsh_choice[] = { { "classic", &hcl_slinger }, { "simple", &hsl_slinger }, { "simple_list", &hsl_slinger }, /* backwards compat */ + { "critbit", &hcb_slinger }, { NULL, NULL } }; @@ -450,6 +453,11 @@ assert(TIM_parse("Sunday, 06-Nov-94 08:49:37 GMT") == 784111777); assert(TIM_parse("Sun Nov 6 08:49:37 1994") == 784111777); + /* + * Check that our SHA256 works + */ + SHA256_Test(); + memset(cli, 0, sizeof cli); cli[0].sb = vsb_newauto(); XXXAN(cli[0].sb); Modified: branches/2.0/varnish-cache/include/stat_field.h =================================================================== --- branches/2.0/varnish-cache/include/stat_field.h 2009-02-06 11:38:07 UTC (rev 3652) +++ branches/2.0/varnish-cache/include/stat_field.h 2009-02-06 11:47:24 UTC (rev 3653) @@ -126,3 +126,7 @@ 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") MAC_STAT(n_purge_dups, uint64_t, 'a', "N duplicate purges removed") + +MAC_STAT(hcb_nolock, uint64_t, 'a', "HCB Lookups without lock") +MAC_STAT(hcb_lock, uint64_t, 'a', "HCB Lookups with lock") +MAC_STAT(hcb_insert, uint64_t, 'a', "HCB Inserts") From tfheen at projects.linpro.no Fri Feb 6 11:51:05 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 12:51:05 +0100 (CET) Subject: r3654 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206115105.5315B1F7499@projects.linpro.no> Author: tfheen Date: 2009-02-06 12:51:05 +0100 (Fri, 06 Feb 2009) New Revision: 3654 Modified: branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c Log: Merge r3456: Resolve the remove/lookup race the simple way. Modified: branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-06 11:47:24 UTC (rev 3653) +++ branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-06 11:51:05 UTC (rev 3654) @@ -364,6 +364,7 @@ hcb_lookup(const struct sess *sp, struct objhead *noh) { struct objhead *oh; + unsigned u; assert(params->hash_sha256); oh = hcb_insert(&hcb_root, noh, 0); @@ -371,14 +372,14 @@ /* Assert that we didn't muck with the tree without lock */ assert(oh != noh); Lck_Lock(&oh->mtx); - oh->refcnt++; + u = oh->refcnt; + if (u) + oh->refcnt++; Lck_Unlock(&oh->mtx); - VSL_stats->hcb_nolock++; - if (0) { - fprintf(stderr, "%s %d\n", __func__, __LINE__); - dump(&hcb_root, stderr); + if (u) { + VSL_stats->hcb_nolock++; + return (oh); } - return (oh); } /* From tfheen at projects.linpro.no Fri Feb 6 11:57:45 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 12:57:45 +0100 (CET) Subject: r3655 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206115745.64A3A1F7499@projects.linpro.no> Author: tfheen Date: 2009-02-06 12:57:45 +0100 (Fri, 06 Feb 2009) New Revision: 3655 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h Log: Merge r3457+r3458: Implement the cooling period before objhead's are deleted in the critbit hasher. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 11:51:05 UTC (rev 3654) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 11:57:45 UTC (rev 3655) @@ -262,7 +262,6 @@ HSH_Prealloc(sp); if (params->hash_sha256) { SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); - sp->wrk->nobjhead->digest_len = 32; /* WSP(sp, SLT_Debug, "SHA256: <%.32s>", sha256); */ } Modified: branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-06 11:51:05 UTC (rev 3654) +++ branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-06 11:57:45 UTC (rev 3655) @@ -30,6 +30,8 @@ * A Crit Bit tree based hash */ +#define PHK 1 + #include "config.h" #include @@ -42,6 +44,8 @@ static struct lock hcb_mtx; +static VTAILQ_HEAD(,objhead) laylow = VTAILQ_HEAD_INITIALIZER(laylow); + /********************************************************************** * Table for finding out how many bits two bytes have in common, * counting from the MSB towards the LSB. @@ -160,7 +164,7 @@ { unsigned u, r; - for (u = 0; u < oh1->digest_len && oh1->digest[u] == oh2->digest[u]; u++) + for (u = 0; u < DIGEST_LEN && oh1->digest[u] == oh2->digest[u]; u++) ; r = hcb_bits(oh1->digest[u], oh2->digest[u]); y->ptr = u; @@ -190,7 +194,7 @@ while(hcb_is_y(*p)) { y = hcb_l_y(*p); - if (y->ptr > oh->digest_len) + if (y->ptr > DIGEST_LEN) s = 0; else s = (oh->digest[y->ptr] & y->bitmask) != 0; @@ -203,8 +207,7 @@ /* We found a node, does it match ? */ oh2 = hcb_l_node(*p); - if (oh2->digest_len == oh->digest_len && - !memcmp(oh2->digest, oh->digest, oh->digest_len)) + if (!memcmp(oh2->digest, oh->digest, DIGEST_LEN)) return (oh2); if (!has_lock) @@ -227,7 +230,7 @@ y = hcb_l_y(*p); if (y->critbit > y2->critbit) break; - if (y->ptr > oh->digest_len) + if (y->ptr > DIGEST_LEN) s = 0; else s = (oh->digest[y->ptr] & y->bitmask) != 0; @@ -259,7 +262,7 @@ y = NULL; while(hcb_is_y(*p)) { y = hcb_l_y(*p); - if (y->ptr > oh->digest_len) + if (y->ptr > DIGEST_LEN) s = 0; else s = (oh->digest[y->ptr] & y->bitmask) != 0; @@ -291,7 +294,7 @@ if (hcb_is_node(p)) { oh = hcb_l_node(p); fprintf(fd, "%*.*sN %u %u r%d <%02x%02x%02x...> <%s>\n", - indent, indent, "", oh->digest_len, indent / 2, + indent, indent, "", DIGEST_LEN, indent / 2, oh->refcnt, oh->digest[0], oh->digest[1], oh->digest[2], oh->hash); @@ -319,12 +322,49 @@ /**********************************************************************/ +#define COOL_DURATION 15 /* seconds */ + +static void * +hcb_cleaner(void *priv) +{ + struct objhead *oh, *oh2; + struct hcb_y *y; + + THR_SetName("hcb_cleaner"); + (void)priv; + while (1) { + sleep(1); + Lck_Lock(&hcb_mtx); + VTAILQ_FOREACH_SAFE(oh, &laylow, coollist, oh2) { + if (oh->hash != NULL) { + free(oh->hash); + oh->hash = NULL; + } + y = (void *)&oh->u; + if (y->leaf[0] || y->leaf[1]) + continue; + if (++oh->refcnt > COOL_DURATION) { + VTAILQ_REMOVE(&laylow, oh, coollist); + if (PHK) + fprintf(stderr, "OH %p is cold enough\n", oh); + free(oh); + VSL_stats->n_objecthead--; + } + } + Lck_Unlock(&hcb_mtx); + } +} + +/**********************************************************************/ + static void hcb_start(void) { struct objhead *oh = NULL; + pthread_t tp; (void)oh; + AZ(pthread_create(&tp, NULL, hcb_cleaner, NULL)); assert(params->hash_sha256); assert(sizeof(struct hcb_y) <= sizeof(oh->u)); memset(&hcb_root, 0, sizeof hcb_root); @@ -336,7 +376,6 @@ hcb_deref(struct objhead *oh) { int r; - struct hcb_y *y; r = 1; CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); @@ -344,16 +383,11 @@ if (--oh->refcnt == 0) { Lck_Lock(&hcb_mtx); hcb_delete(&hcb_root, oh); - y = (void*)&oh->u; - if (y->leaf[0] == 0 && y->leaf[1] == 0) - r = 0; - else { - /* XXX: on waiting list */ - } + VTAILQ_INSERT_TAIL(&laylow, oh, coollist); Lck_Unlock(&hcb_mtx); } Lck_Unlock(&oh->mtx); - if (0) { + if (PHK) { fprintf(stderr, "%s %d %d <%s>\n", __func__, __LINE__, r, oh->hash); dump(&hcb_root, stderr); } @@ -391,7 +425,7 @@ oh = hcb_insert(&hcb_root, noh, 1); if (oh == noh) { VSL_stats->hcb_insert++; - if (0) { + if (PHK) { fprintf(stderr, "%s %d\n", __func__, __LINE__); dump(&hcb_root, stderr); } @@ -400,7 +434,7 @@ noh->hash = NULL; noh->hashlen = 0; VSL_stats->hcb_lock++; - if (0) { + if (PHK) { fprintf(stderr, "%s %d\n", __func__, __LINE__); dump(&hcb_root, stderr); } Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-06 11:51:05 UTC (rev 3654) +++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-06 11:57:45 UTC (rev 3655) @@ -64,6 +64,9 @@ #ifdef VARNISH_CACHE_CHILD + +#define DIGEST_LEN 32 + struct objhead { unsigned magic; #define OBJHEAD_MAGIC 0x1b96615d @@ -73,9 +76,13 @@ VTAILQ_HEAD(,object) objects; char *hash; unsigned hashlen; - unsigned char digest[32]; - unsigned char digest_len; - VTAILQ_HEAD(, sess) waitinglist; + unsigned char digest[DIGEST_LEN]; + union { + VTAILQ_HEAD(, sess) __u_waitinglist; + VTAILQ_ENTRY(objhead) __u_coollist; + } __u; +#define waitinglist __u.__u_waitinglist +#define coollist __u.__u_coollist /*---------------------------------------------------- * The fields below are for the sole private use of From tfheen at projects.linpro.no Fri Feb 6 12:01:31 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 13:01:31 +0100 (CET) Subject: r3656 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206120131.EEEB01F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 13:01:31 +0100 (Fri, 06 Feb 2009) New Revision: 3656 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c Log: Merge r3459: Increase session workspace to 16k Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 11:57:45 UTC (rev 3655) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 12:01:31 UTC (rev 3656) @@ -489,7 +489,7 @@ "header and any edits done to it in the VCL code.\n" "Minimum is 1024 bytes.", DELAYED_EFFECT, - "8192", "bytes" }, + "16384", "bytes" }, { "obj_workspace", tweak_uint, &master.obj_workspace, 1024, UINT_MAX, "Bytes of HTTP protocol workspace allocated for objects. " "This space must be big enough for the entire HTTP protocol " From tfheen at projects.linpro.no Fri Feb 6 12:05:00 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 13:05:00 +0100 (CET) Subject: r3657 - in branches/2.0/varnish-cache: bin/varnishd lib/libvcl Message-ID: <20090206120500.19DD91F7499@projects.linpro.no> Author: tfheen Date: 2009-02-06 13:04:59 +0100 (Fri, 06 Feb 2009) New Revision: 3657 Modified: branches/2.0/varnish-cache/bin/varnishd/default.vcl branches/2.0/varnish-cache/lib/libvcl/vcc_action.c Log: Merge r3460: New return syntax Add support for, and use a new syntax for terminating actions in VCL, basically "return(action)" instead of just "action". The previous syntax is still available. Modified: branches/2.0/varnish-cache/bin/varnishd/default.vcl =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/default.vcl 2009-02-06 12:01:31 UTC (rev 3656) +++ branches/2.0/varnish-cache/bin/varnishd/default.vcl 2009-02-06 12:04:59 UTC (rev 3657) @@ -48,25 +48,25 @@ req.request != "OPTIONS" && req.request != "DELETE") { /* Non-RFC2616 or CONNECT which is weird. */ - pipe; + return (pipe); } if (req.request != "GET" && req.request != "HEAD") { /* We only deal with GET and HEAD by default */ - pass; + return (pass); } if (req.http.Authorization || req.http.Cookie) { /* Not cacheable by default */ - pass; + return (pass); } - lookup; + return (lookup); } sub vcl_pipe { - pipe; + return (pipe); } sub vcl_pass { - pass; + return (pass); } sub vcl_hash { @@ -76,48 +76,48 @@ } else { set req.hash += server.ip; } - hash; + return (hash); } sub vcl_hit { if (!obj.cacheable) { - pass; + return (pass); } - deliver; + return (deliver); } sub vcl_miss { - fetch; + return (fetch); } sub vcl_fetch { if (!obj.cacheable) { - pass; + return (pass); } if (obj.http.Set-Cookie) { - pass; + return (pass); } set obj.prefetch = -30s; - deliver; + return (deliver); } sub vcl_deliver { - deliver; + return (deliver); } sub vcl_discard { /* XXX: Do not redefine vcl_discard{}, it is not yet supported */ - discard; + return (discard); } sub vcl_prefetch { /* XXX: Do not redefine vcl_prefetch{}, it is not yet supported */ - fetch; + return (fetch); } sub vcl_timeout { /* XXX: Do not redefine vcl_timeout{}, it is not yet supported */ - discard; + return (discard); } sub vcl_error { @@ -141,5 +141,5 @@ "}; - deliver; + return (deliver); } Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-06 12:01:31 UTC (rev 3656) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-06 12:04:59 UTC (rev 3657) @@ -41,23 +41,37 @@ /*--------------------------------------------------------------------*/ -#define VCL_RET_MAC(l,u,b,i) \ -static void \ -parse_##l(struct tokenlist *tl) \ -{ \ - \ - Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #u); \ - vcc_ProcAction(tl->curproc, i, tl->t); \ - vcc_NextToken(tl); \ -} +static void +parse_action(struct tokenlist *tl) +{ + int retval = 0; + Expect(tl, ID); + +#define VCL_RET_MAC(l, u, b, i) \ + do { \ + if (vcc_IdIs(tl->t, #l)) { \ + Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #u); \ + vcc_ProcAction(tl->curproc, i, tl->t); \ + retval = 1; \ + } \ + } while (0); +#define VCL_RET_MAC_E(l, u, b, i) VCL_RET_MAC(l, u, b, i) #include "vcl_returns.h" #undef VCL_RET_MAC +#undef VCL_RET_MAC_E + if (!retval) { + vsb_printf(tl->sb, "Expected action name.\n"); + vcc_ErrWhere(tl, tl->t); + ERRCHK(tl); + } + vcc_NextToken(tl); +} /*--------------------------------------------------------------------*/ static void -parse_restart_real(struct tokenlist *tl) +parse_restart(struct tokenlist *tl) { struct token *t1; @@ -70,7 +84,9 @@ vcc_ErrWhere(tl, t1); ERRCHK(tl); } - parse_restart(tl); + Fb(tl, 1, "VRT_done(sp, VCL_RET_RESTART);\n"); + vcc_ProcAction(tl->curproc, VCL_RET_RESTART, tl->t); + vcc_NextToken(tl); } /*--------------------------------------------------------------------*/ @@ -407,6 +423,22 @@ /*--------------------------------------------------------------------*/ static void +parse_return(struct tokenlist *tl) +{ + vcc_NextToken(tl); + Expect(tl, '('); + vcc_NextToken(tl); + Expect(tl, ID); + + parse_action(tl); + ERRCHK(tl); + Expect(tl, ')'); + vcc_NextToken(tl); +} + +/*--------------------------------------------------------------------*/ + +static void parse_synthetic(struct tokenlist *tl) { vcc_NextToken(tl); @@ -430,12 +462,11 @@ const char *name; action_f *func; } action_table[] = { - { "restart", parse_restart_real }, -#define VCL_RET_MAC(l, u, b, i) { #l, parse_##l }, -#define VCL_RET_MAC_E(l, u, b, i) VCL_RET_MAC(l, u, b, i) + { "restart", parse_restart }, + { "error", parse_error }, +#define VCL_RET_MAC(l, u, b, i) { #l, parse_action }, #include "vcl_returns.h" #undef VCL_RET_MAC -#undef VCL_RET_MAC_E /* Keep list sorted from here */ { "call", parse_call }, @@ -447,6 +478,7 @@ { "set", parse_set }, { "synthetic", parse_synthetic }, { "unset", parse_unset }, + { "return", parse_return }, { NULL, NULL } }; From tfheen at projects.linpro.no Fri Feb 6 12:08:44 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 13:08:44 +0100 (CET) Subject: r3658 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206120844.B72A61F7499@projects.linpro.no> Author: tfheen Date: 2009-02-06 13:08:44 +0100 (Fri, 06 Feb 2009) New Revision: 3658 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_backend.c branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/cache_expire.c branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h Log: Merge r3464: Cleanup A bit of cleanup while I ponder ticket 412: make VBE_free_bereq() and HSH_Deref() null their argument pointer. Add HSH_Drop() for deorbiting unwanted busy objects. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 12:04:59 UTC (rev 3657) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 12:08:44 UTC (rev 3658) @@ -407,7 +407,7 @@ void VBE_ClosedFd(struct sess *sp); void VBE_RecycleFd(struct sess *sp); struct bereq * VBE_new_bereq(void); -void VBE_free_bereq(struct bereq *bereq); +void VBE_free_bereq(struct bereq **bereq); void VBE_AddHostHeader(const struct sess *sp); void VBE_Poll(void); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend.c 2009-02-06 12:04:59 UTC (rev 3657) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend.c 2009-02-06 12:08:44 UTC (rev 3658) @@ -172,9 +172,14 @@ */ void -VBE_free_bereq(struct bereq *bereq) +VBE_free_bereq(struct bereq **bereqp) { + struct bereq *bereq; + AN(bereqp); + bereq = *bereqp; + *bereqp = NULL; + CHECK_OBJ_NOTNULL(bereq, BEREQ_MAGIC); WS_Reset(bereq->ws, NULL); Lck_Lock(&VBE_mtx); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-06 12:04:59 UTC (rev 3657) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-06 12:08:44 UTC (rev 3658) @@ -177,8 +177,7 @@ RES_WriteObj(sp); AZ(sp->wrk->wfd); - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Deref(&sp->obj); sp->step = STP_DONE; return (0); } @@ -391,13 +390,9 @@ if (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; + VBE_free_bereq(&sp->bereq); + HSH_Drop(sp); + AZ(sp->obj); return (0); } @@ -406,16 +401,11 @@ sp->err_code = http_GetStatus(sp->obj->http); VCL_fetch_method(sp); - VBE_free_bereq(sp->bereq); - sp->bereq = NULL; + VBE_free_bereq(&sp->bereq); switch (sp->handling) { case VCL_RET_RESTART: - sp->obj->ttl = 0; - sp->obj->cacheable = 0; - HSH_Unbusy(sp); - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Drop(sp); sp->director = NULL; sp->restarts++; sp->step = STP_RECV; @@ -427,11 +417,7 @@ break; case VCL_RET_ERROR: sp->step = STP_ERROR; - sp->obj->ttl = 0; - sp->obj->cacheable = 0; - HSH_Unbusy(sp); - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Drop(sp); return (0); default: WRONG("Illegal action in vcl_fetch{}"); @@ -535,8 +521,7 @@ } /* Drop our object, we won't need it */ - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Deref(&sp->obj); switch(sp->handling) { case VCL_RET_PASS: @@ -625,8 +610,7 @@ if (sp->obj->pass) { VSL_stats->cache_hitpass++; WSP(sp, SLT_HitPass, "%u", sp->obj->xid); - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Deref(&sp->obj); sp->step = STP_PASS; return (0); } @@ -670,24 +654,17 @@ http_FilterHeader(sp, HTTPH_R_FETCH); VCL_miss_method(sp); + AZ(sp->obj->cacheable); switch(sp->handling) { case VCL_RET_ERROR: - sp->obj->cacheable = 0; - HSH_Unbusy(sp); - HSH_Deref(sp->obj); - sp->obj = NULL; - VBE_free_bereq(sp->bereq); - sp->bereq = NULL; + HSH_Drop(sp); + VBE_free_bereq(&sp->bereq); sp->step = STP_ERROR; return (0); case VCL_RET_PASS: - sp->obj->cacheable = 0; - HSH_Unbusy(sp); - HSH_Deref(sp->obj); - sp->obj = NULL; + HSH_Drop(sp); + VBE_free_bereq(&sp->bereq); sp->step = STP_PASS; - VBE_free_bereq(sp->bereq); - sp->bereq = NULL; return (0); case VCL_RET_FETCH: sp->step = STP_FETCH; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-06 12:04:59 UTC (rev 3657) +++ branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-06 12:08:44 UTC (rev 3658) @@ -337,7 +337,7 @@ VSL_stats->n_expired++; Lck_Unlock(&exp_mtx); del_objexp(o); - HSH_Deref(o); + HSH_Deref(&o); } } } @@ -406,7 +406,7 @@ if (sp->handling == VCL_RET_DISCARD) { WSL(sp->wrk, SLT_ExpKill, 0, "%u LRU", o->xid); del_objexp(o); - HSH_Deref(o); + HSH_Deref(&o); return (1); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-06 12:04:59 UTC (rev 3657) +++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-06 12:08:44 UTC (rev 3658) @@ -322,7 +322,7 @@ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC); AN(sp->director); - assert(sp->obj->busy != 0); + AN(sp->obj->busy); w = sp->wrk; bereq = sp->bereq; hp = bereq->http; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 12:04:59 UTC (rev 3657) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 12:08:44 UTC (rev 3658) @@ -379,6 +379,22 @@ } void +HSH_Drop(struct sess *sp) +{ + struct object *o; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + o = sp->obj; + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + assert(o->busy); + assert(o->refcnt > 0); + o->ttl = 0; + o->cacheable = 0; + HSH_Unbusy(sp); + HSH_Deref(&sp->obj); +} + +void HSH_Unbusy(const struct sess *sp) { struct object *o; @@ -411,7 +427,7 @@ if (oh != NULL) Lck_Unlock(&oh->mtx); if (parent != NULL) - HSH_Deref(parent); + HSH_Deref(&parent); } void @@ -429,11 +445,15 @@ } void -HSH_Deref(struct object *o) +HSH_Deref(struct object **oo) { + struct object *o; struct objhead *oh; unsigned r; + AN(oo); + o = *oo; + *oo = NULL; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oh = o->objhead; if (oh != NULL) { Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c 2009-02-06 12:04:59 UTC (rev 3657) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c 2009-02-06 12:08:44 UTC (rev 3658) @@ -96,8 +96,7 @@ return; } - VBE_free_bereq(bereq); - bereq = NULL; + VBE_free_bereq(&bereq); sp->t_resp = TIM_real(); Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-06 12:04:59 UTC (rev 3657) +++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-06 12:08:44 UTC (rev 3658) @@ -56,7 +56,8 @@ struct object *HSH_Lookup(struct sess *sp); void HSH_Unbusy(const struct sess *sp); void HSH_Ref(struct object *o); -void HSH_Deref(struct object *o); +void HSH_Deref(struct object **o); +void HSH_Drop(struct sess *sp); double HSH_Grace(double g); void HSH_Init(void); void HSH_AddString(struct sess *sp, const char *str); From tfheen at projects.linpro.no Fri Feb 6 12:16:25 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 13:16:25 +0100 (CET) Subject: r3659 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090206121625.D977F1F7499@projects.linpro.no> Author: tfheen Date: 2009-02-06 13:16:25 +0100 (Fri, 06 Feb 2009) New Revision: 3659 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/r00412.vtc Log: Merge r3465: Add regression test for ticket 412 Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/r00412.vtc (from rev 3465, trunk/varnish-cache/bin/varnishtest/tests/r00412.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/r00412.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/r00412.vtc 2009-02-06 12:16:25 UTC (rev 3659) @@ -0,0 +1,36 @@ +# $Id$ + +test "Regression test for ticket 412" + +server s1 { + rxreq + expect req.url == "/" + txresp -status 303 -hdr "Location: /foo" + rxreq + expect req.url == "/foo" + txresp -body "12345" +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + if (obj.status == 303) { + set obj.cacheable = true; + set obj.ttl = 60 s; + set obj.http.X-Magic-Redirect = "1"; + set req.url = obj.http.Location; + restart; + } + } + sub vcl_hit { + if (obj.http.X-Magic-Redirect == "1") { + set req.url = obj.http.Location; + restart; + } + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run From tfheen at projects.linpro.no Fri Feb 6 12:23:50 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 13:23:50 +0100 (CET) Subject: r3660 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206122350.100031F7499@projects.linpro.no> Author: tfheen Date: 2009-02-06 13:23:49 +0100 (Fri, 06 Feb 2009) New Revision: 3660 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c Log: Merge r3467: Add a missing newline Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-06 12:16:25 UTC (rev 3659) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-06 12:23:49 UTC (rev 3660) @@ -468,7 +468,7 @@ vf = mgt_VccCompile(&sb, av[3], 0); if (vsb_len(sb) > 0) - cli_out(cli, "%s", vsb_data(sb)); + cli_out(cli, "%s\n", vsb_data(sb)); vsb_delete(sb); if (vf == NULL) { cli_out(cli, "VCL compilation failed"); From tfheen at projects.linpro.no Fri Feb 6 12:41:17 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 13:41:17 +0100 (CET) Subject: r3661 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090206124117.4D09A1F7499@projects.linpro.no> Author: tfheen Date: 2009-02-06 13:41:16 +0100 (Fri, 06 Feb 2009) New Revision: 3661 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/r00409.vtc Log: Merge r3468: Add regression test for #409 Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/r00409.vtc (from rev 3468, trunk/varnish-cache/bin/varnishtest/tests/r00409.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/r00409.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/r00409.vtc 2009-02-06 12:41:16 UTC (rev 3661) @@ -0,0 +1,11 @@ +# $Id$ + +test "Regression test for ticket 409" + +varnish v1 -badvcl { + sub vcl_recv { + if ( req.url ~ ! "\.(png|jpg|gif|js|css)$" ) { + return (pass); + } + } +} From tfheen at projects.linpro.no Fri Feb 6 12:51:01 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 13:51:01 +0100 (CET) Subject: r3662 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090206125101.3493A1F7499@projects.linpro.no> Author: tfheen Date: 2009-02-06 13:51:00 +0100 (Fri, 06 Feb 2009) New Revision: 3662 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc Log: Merge r3469: We should have a body length on a 200 reply Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc 2009-02-06 12:41:16 UTC (rev 3661) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00023.vtc 2009-02-06 12:51:00 UTC (rev 3662) @@ -5,7 +5,7 @@ server s1 { rxreq delay 1.5 - txresp + txresp -body "foo" } -start varnish v1 -vcl+backend {} -start @@ -21,7 +21,7 @@ server s1 { rxreq delay 0.5 - txresp + txresp -body "foo" } -start client c1 { From tfheen at projects.linpro.no Fri Feb 6 12:54:33 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 13:54:33 +0100 (CET) Subject: r3663 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206125433.EB2D41F74B6@projects.linpro.no> Author: tfheen Date: 2009-02-06 13:54:33 +0100 (Fri, 06 Feb 2009) New Revision: 3663 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c branches/2.0/varnish-cache/bin/varnishd/cache_http.c Log: Merge r3470: Change the logic that decides when we attempt EOF fetches from the backend. The new logic is: If (HEAD) /* happens only on pass */ do not fetch body. else if (Content-Length) fetch body according to length else if (chunked) fetch body as chunked else if (other transfer-encoding) fail else if (Connection: keep-alive) fetch no body, set Length = 0 else if (Connection: close) fetch body until EOF else if (HTTP < 1.1) fetch body until EOF else fetch no body, set Length = 0 let me know if this breaks anything that should work. Fixes #400 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-06 12:51:00 UTC (rev 3662) +++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-06 12:54:33 UTC (rev 3663) @@ -414,15 +414,31 @@ WSL(sp->wrk, SLT_Debug, vc->fd, "Invalid Transfer-Encoding"); VBE_ClosedFd(sp); return (__LINE__); + } else if (http_HdrIs(hp, H_Connection, "keep-alive")) { + /* + * If we have Connection: keep-alive, it cannot possibly be + * EOF encoded, and since it is neither length nor chunked + * it must be zero length. + */ + mklen = 1; + } else if (http_HdrIs(hp, H_Connection, "close")) { + /* + * If we have connection closed, it is safe to read what + * comes in any case. + */ + cls = fetch_eof(sp, htc); + mklen = 1; + } else if (hp->protover < 1.1) { + /* + * With no Connection header, assume EOF + */ + cls = fetch_eof(sp, htc); + mklen = 1; } else { - switch (http_GetStatus(hp)) { - case 200: - cls = fetch_eof(sp, htc); - mklen = 1; - break; - default: - break; - } + /* + * Assume zero length + */ + mklen = 1; } if (cls < 0) { @@ -451,7 +467,7 @@ http_PrintfHeader(sp->wrk, sp->fd, hp2, "Content-Length: %u", sp->obj->len); - if (http_GetHdr(hp, H_Connection, &b) && !strcasecmp(b, "close")) + if (http_HdrIs(hp, H_Connection, "close")) cls = 1; if (cls) Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-06 12:51:00 UTC (rev 3662) +++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-06 12:54:33 UTC (rev 3663) @@ -251,7 +251,7 @@ unsigned u; if (!http_GetHdr(hp, H_Connection, &p)) { - if (strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.1")) + if (hp->protover < 1.1) return ("not HTTP/1.1"); return (NULL); } @@ -442,6 +442,21 @@ /*--------------------------------------------------------------------*/ +static void +http_ProtoVer(struct http *hp) +{ + + if (!strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.0")) + hp->protover = 1.0; + else if (!strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.1")) + hp->protover = 1.1; + else + hp->protover = 0.9; +} + + +/*--------------------------------------------------------------------*/ + int http_DissectRequest(struct sess *sp) { @@ -463,13 +478,7 @@ WSPR(sp, SLT_HttpGarbage, htc->rxbuf); return (i); } - - if (!strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.0")) - hp->protover = 1.0; - else if (!strcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.1")) - hp->protover = 1.1; - else - hp->protover = 0.9; + http_ProtoVer(hp); return (i); } @@ -497,6 +506,7 @@ hp->status = strtoul(hp->hd[HTTP_HDR_STATUS].b, NULL /* XXX */, 10); } + http_ProtoVer(hp); if (hp->hd[HTTP_HDR_RESPONSE].b == NULL || !Tlen(hp->hd[HTTP_HDR_RESPONSE])) { /* Backend didn't send a response string, use the standard */ From tfheen at projects.linpro.no Fri Feb 6 12:58:00 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 13:58:00 +0100 (CET) Subject: r3664 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090206125800.AE75D97C24@projects.linpro.no> Author: tfheen Date: 2009-02-06 13:58:00 +0100 (Fri, 06 Feb 2009) New Revision: 3664 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/r00400.vtc Log: Merge r3471: Add regression test for #400 Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/r00400.vtc (from rev 3471, trunk/varnish-cache/bin/varnishtest/tests/r00400.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/r00400.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/r00400.vtc 2009-02-06 12:58:00 UTC (rev 3664) @@ -0,0 +1,21 @@ +# $Id$ + +test "Regression test for ticket 409" + +server s1 { + rxreq + expect req.url == "/" + send "HTTP/1.0 400 Not funny\r\n" + send "\r\n" + send "12345\r\n" +} -start + +varnish v1 -vcl+backend { +} -start + +client c1 { + txreq + rxresp + expect resp.status == 400 + expect resp.bodylen == 7 +} -run From tfheen at projects.linpro.no Fri Feb 6 13:17:49 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 14:17:49 +0100 (CET) Subject: r3665 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090206131749.764591F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 14:17:49 +0100 (Fri, 06 Feb 2009) New Revision: 3665 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/b00027.vtc Log: Merge r3472: Add test for two corner cases in backend body determination. Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00027.vtc (from rev 3472, trunk/varnish-cache/bin/varnishtest/tests/b00027.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00027.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00027.vtc 2009-02-06 13:17:49 UTC (rev 3665) @@ -0,0 +1,28 @@ +# $Id$ + +test "test backend transmission corner cases" + +server s1 { + rxreq + txresp + rxreq + txresp -proto HTTP/1.0 -hdr "Connection: keep-alive" + rxreq + txresp -hdr "Transfer-encoding: foobar" +} -start + +varnish v1 -vcl+backend {} -start + +client c1 { + txreq -url /foo + rxresp + expect resp.status == 200 + expect resp.bodylen == 0 + txreq -url /bar + rxresp + expect resp.status == 200 + expect resp.bodylen == 0 + txreq -url /barf + rxresp + expect resp.status == 503 +} -run From tfheen at projects.linpro.no Fri Feb 6 13:22:01 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 14:22:01 +0100 (CET) Subject: r3666 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206132201.933021F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 14:22:01 +0100 (Fri, 06 Feb 2009) New Revision: 3666 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c Log: Merge r3473: Only fail -T argument if none of the addresses it resolves to can be listend on. Fixes #97 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-06 13:17:49 UTC (rev 3665) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-06 13:22:01 UTC (rev 3666) @@ -459,22 +459,23 @@ { struct vss_addr **ta; char *addr, *port; - int i, n, sock; + int i, n, sock, good; struct telnet *tn; dflag_copy = dflag; XXXAZ(VSS_parse(T_arg, &addr, &port)); n = VSS_resolve(addr, port, &ta); - free(addr); - free(port); if (n == 0) { fprintf(stderr, "Could not open management port\n"); exit(2); } + good = 0; for (i = 0; i < n; ++i) { sock = VSS_listen(ta[i], 10); - assert(sock >= 0); + if (sock < 0) + continue; + good++; tn = telnet_new(sock); tn->ev = vev_new(); XXXAN(tn->ev); @@ -486,5 +487,12 @@ ta[i] = NULL; } free(ta); + if (good == 0) { + REPORT(LOG_ERR, "-T %s:%s could not be listened on.", + addr, port); + exit(2); + } + free(addr); + free(port); return (0); } From tfheen at projects.linpro.no Fri Feb 6 13:25:03 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 14:25:03 +0100 (CET) Subject: r3667 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206132503.21B381F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 14:25:02 +0100 (Fri, 06 Feb 2009) New Revision: 3667 Modified: branches/2.0/varnish-cache/bin/varnishd/storage_file.c Log: Merge r3474: Assert lock properly held, inspired by unease about #378. Modified: branches/2.0/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_file.c 2009-02-06 13:22:01 UTC (rev 3666) +++ branches/2.0/varnish-cache/bin/varnishd/storage_file.c 2009-02-06 13:25:02 UTC (rev 3667) @@ -343,6 +343,7 @@ assert(sp->alloc == 0); assert(sp->flist == NULL); + Lck_AssertHeld(&sc->mtx); b = sp->size / sc->pagesize; if (b >= NBUCKET) { b = NBUCKET - 1; @@ -372,6 +373,7 @@ assert(sp->alloc == 0); assert(sp->flist != NULL); + Lck_AssertHeld(&sc->mtx); b = sp->size / sc->pagesize; if (b >= NBUCKET) { b = NBUCKET - 1; @@ -602,14 +604,16 @@ sc = st->priv; + Lck_New(&sc->mtx); + Lck_Lock(&sc->mtx); smf_open_chunk(sc, sc->filesize, 0, &fail, &sum); + Lck_Unlock(&sc->mtx); printf("managed to mmap %ju bytes of %ju\n", (uintmax_t)sum, sc->filesize); /* XXX */ if (sum < MINPAGES * (off_t)getpagesize()) exit (2); - Lck_New(&sc->mtx); VSL_stats->sm_bfree += sc->filesize; } From tfheen at projects.linpro.no Fri Feb 6 13:28:02 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 14:28:02 +0100 (CET) Subject: r3668 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206132802.11A761F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 14:28:01 +0100 (Fri, 06 Feb 2009) New Revision: 3668 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_http.c Log: Merge r3475: Remove http_GetProto(), it's unused. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 13:25:02 UTC (rev 3667) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 13:28:01 UTC (rev 3668) @@ -476,7 +476,6 @@ const char *field, char **ptr); int http_GetStatus(const struct http *hp); const char *http_GetReq(const struct http *hp); -const char *http_GetProto(const struct http *hp); int http_HdrIs(const struct http *hp, const char *hdr, const char *val); int http_DissectRequest(struct sess *sp); int http_DissectResponse(struct worker *w, const struct http_conn *htc, Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-06 13:25:02 UTC (rev 3667) +++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-06 13:28:01 UTC (rev 3668) @@ -303,14 +303,6 @@ } const char * -http_GetProto(const struct http *hp) -{ - - Tcheck(hp->hd[HTTP_HDR_PROTO]); - return (hp->hd[HTTP_HDR_PROTO].b); -} - -const char * http_GetReq(const struct http *hp) { From tfheen at projects.linpro.no Fri Feb 6 13:37:42 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 14:37:42 +0100 (CET) Subject: r3669 - branches/2.0/varnish-cache/lib/libvcl Message-ID: <20090206133742.CC0361F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 14:37:42 +0100 (Fri, 06 Feb 2009) New Revision: 3669 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c Log: Merge r3476: This is a bandaid for a pointer dereference when "restart" is used. Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-06 13:28:01 UTC (rev 3668) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-06 13:37:42 UTC (rev 3669) @@ -85,7 +85,8 @@ ERRCHK(tl); } Fb(tl, 1, "VRT_done(sp, VCL_RET_RESTART);\n"); - vcc_ProcAction(tl->curproc, VCL_RET_RESTART, tl->t); + assert(VCL_RET_RESTART == (1 << 9)); /* XXX: BANDAID FIXME! */ + vcc_ProcAction(tl->curproc, 9, tl->t); vcc_NextToken(tl); } From tfheen at projects.linpro.no Fri Feb 6 13:41:00 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 14:41:00 +0100 (CET) Subject: r3670 - branches/2.0/varnish-cache/include Message-ID: <20090206134100.5B6911F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 14:41:00 +0100 (Fri, 06 Feb 2009) New Revision: 3670 Modified: branches/2.0/varnish-cache/include/libvarnish.h Log: Merge r3477: Make it entirely clear to the compiler that the WRONG() macro stops Modified: branches/2.0/varnish-cache/include/libvarnish.h =================================================================== --- branches/2.0/varnish-cache/include/libvarnish.h 2009-02-06 13:37:42 UTC (rev 3669) +++ branches/2.0/varnish-cache/include/libvarnish.h 2009-02-06 13:41:00 UTC (rev 3670) @@ -128,4 +128,5 @@ #define WRONG(expl) \ do { \ lbv_assert(__func__, __FILE__, __LINE__, expl, errno, 3); \ + abort(); \ } while (0) From tfheen at projects.linpro.no Fri Feb 6 13:44:13 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 14:44:13 +0100 (CET) Subject: r3671 - in branches/2.0/varnish-cache: include lib/libvcl Message-ID: <20090206134413.7294197C24@projects.linpro.no> Author: tfheen Date: 2009-02-06 14:44:13 +0100 (Fri, 06 Feb 2009) New Revision: 3671 Modified: branches/2.0/varnish-cache/include/libvcl.h branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c Log: Merge r3478: Add a VCC_Return_Name() function to convert a return action to a string. Modified: branches/2.0/varnish-cache/include/libvcl.h =================================================================== --- branches/2.0/varnish-cache/include/libvcl.h 2009-02-06 13:41:00 UTC (rev 3670) +++ branches/2.0/varnish-cache/include/libvcl.h 2009-02-06 13:44:13 UTC (rev 3671) @@ -31,5 +31,5 @@ char *VCC_Compile(struct vsb *sb, const char *b, const char *e); void VCC_InitCompile(const char *default_vcl); +const char *VCC_Return_Name(unsigned action); - Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-06 13:41:00 UTC (rev 3670) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-06 13:44:13 UTC (rev 3671) @@ -662,6 +662,23 @@ return (r); } +/*--------------------------------------------------------------------*/ + +const char * +VCC_Return_Name(unsigned method) +{ + + switch (method) { + case 0: return (""); +#define VCL_RET_MAC(l, u, b, i) case b: return(#u); +#define VCL_RET_MAC_E(l, u, b, i) case b: return(#u); +#include "vcl_returns.h" +#undef VCL_RET_MAC_E +#undef VCL_RET_MAC + } + return (NULL); +} + /*-------------------------------------------------------------------- * Initialize the compiler and register the default VCL code for later * compilation runs. From tfheen at projects.linpro.no Fri Feb 6 13:47:53 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 14:47:53 +0100 (CET) Subject: r3672 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206134753.F024797C24@projects.linpro.no> Author: tfheen Date: 2009-02-06 14:47:53 +0100 (Fri, 06 Feb 2009) New Revision: 3672 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_panic.c Log: Merge r3479: Use VCC_Return_Name() instead of rolling our own. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_panic.c 2009-02-06 13:44:13 UTC (rev 3671) +++ branches/2.0/varnish-cache/bin/varnishd/cache_panic.c 2009-02-06 13:47:53 UTC (rev 3672) @@ -40,6 +40,7 @@ #include "cache.h" #include "cache_backend.h" #include "vcl.h" +#include "libvcl.h" /* * The panic string is constructed in memory, then copied to the @@ -214,16 +215,7 @@ /*lint -restore */ default: stp = NULL; } - switch (sp->handling) { -/*lint -save -e525 */ -#define VCL_RET_MAC(l, u, b, v) case VCL_RET_##u: hand = #u; break; -#define VCL_RET_MAC_E(l, u, b, v) case VCL_RET_##u: hand = #u; break; -#include "vcl_returns.h" -#undef VCL_RET_MAC -#undef VCL_RET_MAC_E -/*lint -restore */ - default: hand = NULL; - } + hand = VCC_Return_Name(sp->handling); if (stp != NULL) vsb_printf(vsp, " step = %s,\n", stp); else From tfheen at projects.linpro.no Fri Feb 6 13:51:11 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 14:51:11 +0100 (CET) Subject: r3673 - in branches/2.0/varnish-cache: bin/varnishd lib/libvcl Message-ID: <20090206135111.A494597C24@projects.linpro.no> Author: tfheen Date: 2009-02-06 14:51:11 +0100 (Fri, 06 Feb 2009) New Revision: 3673 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c Log: Merge r3480: Make VCC_Return_Name() return lower case, and use it also for the SMH logging. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c 2009-02-06 13:47:53 UTC (rev 3672) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c 2009-02-06 13:51:11 UTC (rev 3673) @@ -46,6 +46,7 @@ #include "shmlog.h" #include "vcl.h" #include "cache.h" +#include "libvcl.h" struct vcls { unsigned magic; @@ -299,21 +300,6 @@ /*--------------------------------------------------------------------*/ -static const char * -vcl_handlingname(unsigned u) -{ - - switch (u) { -#define VCL_RET_MAC(a, b, c,d) case VCL_RET_##b: return(#a); -#define VCL_RET_MAC_E(a, b, c,d) case VCL_RET_##b: return(#a); -#include "vcl_returns.h" -#undef VCL_RET_MAC -#undef VCL_RET_MAC_E - default: - return (NULL); - } -} - #define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(func, upper, bitmap) \ @@ -325,7 +311,7 @@ sp->cur_method = VCL_MET_ ## upper; \ WSP(sp, SLT_VCL_call, "%s", #func); \ sp->vcl->func##_func(sp); \ - WSP(sp, SLT_VCL_return, "%s", vcl_handlingname(sp->handling)); \ + WSP(sp, SLT_VCL_return, "%s", VCC_Return_Name(sp->handling)); \ sp->cur_method = 0; \ assert(sp->handling & bitmap); \ assert(!(sp->handling & ~bitmap)); \ Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-06 13:47:53 UTC (rev 3672) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-06 13:51:11 UTC (rev 3673) @@ -670,8 +670,8 @@ switch (method) { case 0: return (""); -#define VCL_RET_MAC(l, u, b, i) case b: return(#u); -#define VCL_RET_MAC_E(l, u, b, i) case b: return(#u); +#define VCL_RET_MAC(l, u, b, i) case b: return(#l); +#define VCL_RET_MAC_E(l, u, b, i) case b: return(#l); #include "vcl_returns.h" #undef VCL_RET_MAC_E #undef VCL_RET_MAC From tfheen at projects.linpro.no Fri Feb 6 13:55:45 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 14:55:45 +0100 (CET) Subject: r3674 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206135545.B8C3B97C24@projects.linpro.no> Author: tfheen Date: 2009-02-06 14:55:45 +0100 (Fri, 06 Feb 2009) New Revision: 3674 Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt branches/2.0/varnish-cache/bin/varnishd/flint.sh Log: Merge r3481: Flexelint adjustments Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-06 13:51:11 UTC (rev 3673) +++ branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-06 13:55:45 UTC (rev 3674) @@ -69,6 +69,8 @@ -ffc // No automatic custody +-e455 // thread lock +-e458 // unprotected read -e763 // Redundant declaration for symbol '...' previously declared -e726 // Extraneous comma ignored -e728 // Symbol ... not explicitly initialized Modified: branches/2.0/varnish-cache/bin/varnishd/flint.sh =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/flint.sh 2009-02-06 13:51:11 UTC (rev 3673) +++ branches/2.0/varnish-cache/bin/varnishd/flint.sh 2009-02-06 13:55:45 UTC (rev 3674) @@ -10,25 +10,4 @@ flint.lnt \ *.c \ ../../lib/libvarnish/*.c \ - ../../lib/libvcl/*.c \ - > $T 2>&1 - -for t in Error Warning Info Note -do - sed -n "/$t [0-9][0-9][0-9]:/s/.*\($t [0-9][0-9][0-9]\).*/\1/p" $T -done | awk ' -$2 == 830 { next } -$2 == 831 { next } - { - i=$2"_"$1 - h[i]++ - n++ - } -END { - printf "%5d %s\n", n, "Total" - for (i in h) - printf "%5d %s\n", h[i], i - } -' | sort -rn - -cat $T + ../../lib/libvcl/*.c From tfheen at projects.linpro.no Fri Feb 6 14:04:08 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:04:08 +0100 (CET) Subject: r3675 - in branches/2.0/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20090206140408.80C1A97C24@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:04:08 +0100 (Fri, 06 Feb 2009) New Revision: 3675 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_expire.c branches/2.0/varnish-cache/include/vcl.h branches/2.0/varnish-cache/include/vcl_returns.h branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c branches/2.0/varnish-cache/lib/libvcl/vcc_token_defs.h Log: Merge r3482+r3483: Move the enum MET/RET macros to vcl.h Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 13:55:45 UTC (rev 3674) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 14:04:08 UTC (rev 3675) @@ -54,7 +54,6 @@ #include "libvarnish.h" -#include "vcl_returns.h" #include "common.h" #include "heritage.h" #include "miniobj.h" Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-06 13:55:45 UTC (rev 3674) +++ branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-06 14:04:08 UTC (rev 3675) @@ -60,6 +60,7 @@ #include "shmlog.h" #include "binary_heap.h" #include "cache.h" +#include "vcl.h" #include "hash_slinger.h" /* Modified: branches/2.0/varnish-cache/include/vcl.h =================================================================== --- branches/2.0/varnish-cache/include/vcl.h 2009-02-06 13:55:45 UTC (rev 3674) +++ branches/2.0/varnish-cache/include/vcl.h 2009-02-06 14:04:08 UTC (rev 3675) @@ -3,7 +3,7 @@ * * NB: This file is machine generated, DO NOT EDIT! * - * Edit vcc_gen_fixed_token.tcl instead + * Edit and run vcc_gen_fixed_token.tcl instead */ struct sess; @@ -13,6 +13,36 @@ typedef void vcl_fini_f(struct cli *); typedef int vcl_func_f(struct sess *sp); +/* VCL Methods */ +#define VCL_MET_RECV (1 << 0) +#define VCL_MET_PIPE (1 << 1) +#define VCL_MET_PASS (1 << 2) +#define VCL_MET_HASH (1 << 3) +#define VCL_MET_MISS (1 << 4) +#define VCL_MET_HIT (1 << 5) +#define VCL_MET_FETCH (1 << 6) +#define VCL_MET_DELIVER (1 << 7) +#define VCL_MET_PREFETCH (1 << 8) +#define VCL_MET_TIMEOUT (1 << 9) +#define VCL_MET_DISCARD (1 << 10) +#define VCL_MET_ERROR (1 << 11) + +#define VCL_MET_MAX 12 + +/* VCL Returns */ +#define VCL_RET_ERROR (1 << 0) +#define VCL_RET_LOOKUP (1 << 1) +#define VCL_RET_HASH (1 << 2) +#define VCL_RET_PIPE (1 << 3) +#define VCL_RET_PASS (1 << 4) +#define VCL_RET_FETCH (1 << 5) +#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 + struct VCL_conf { unsigned magic; #define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */ Modified: branches/2.0/varnish-cache/include/vcl_returns.h =================================================================== --- branches/2.0/varnish-cache/include/vcl_returns.h 2009-02-06 13:55:45 UTC (rev 3674) +++ branches/2.0/varnish-cache/include/vcl_returns.h 2009-02-06 14:04:08 UTC (rev 3675) @@ -3,7 +3,7 @@ * * NB: This file is machine generated, DO NOT EDIT! * - * Edit vcc_gen_fixed_token.tcl instead + * Edit and run vcc_gen_fixed_token.tcl instead */ #ifdef VCL_RET_MAC @@ -19,57 +19,31 @@ 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) -#define VCL_RET_HASH (1 << 2) -#define VCL_RET_PIPE (1 << 3) -#define VCL_RET_PASS (1 << 4) -#define VCL_RET_FETCH (1 << 5) -#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_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_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) -#define VCL_MET_PASS (1 << 2) -#define VCL_MET_HASH (1 << 3) -#define VCL_MET_MISS (1 << 4) -#define VCL_MET_HIT (1 << 5) -#define VCL_MET_FETCH (1 << 6) -#define VCL_MET_DELIVER (1 << 7) -#define VCL_MET_PREFETCH (1 << 8) -#define VCL_MET_TIMEOUT (1 << 9) -#define VCL_MET_DISCARD (1 << 10) -#define VCL_MET_ERROR (1 << 11) +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_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)) #endif -#define N_METHODS 12 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-06 13:55:45 UTC (rev 3674) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-06 14:04:08 UTC (rev 3675) @@ -500,7 +500,7 @@ assert(tl->ff != NULL); /* body code of methods */ - for (i = 0; i < N_METHODS; i++) { + for (i = 0; i < VCL_MET_MAX; i++) { tl->fm[i] = vsb_newauto(); assert(tl->fm[i] != NULL); } @@ -532,7 +532,7 @@ vsb_delete(tl->fc); vsb_delete(tl->fi); vsb_delete(tl->ff); - for (i = 0; i < N_METHODS; i++) + for (i = 0; i < VCL_MET_MAX; i++) vsb_delete(tl->fm[i]); free(tl); @@ -611,7 +611,7 @@ return (vcc_DestroyTokenList(tl, NULL)); /* Emit method functions */ - for (i = 0; i < N_METHODS; i++) { + for (i = 0; i < VCL_MET_MAX; i++) { Fc(tl, 1, "\nstatic int\n"); Fc(tl, 1, "VGC_function_%s (struct sess *sp)\n", method_tab[i].name); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h 2009-02-06 13:55:45 UTC (rev 3674) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h 2009-02-06 14:04:08 UTC (rev 3675) @@ -31,7 +31,7 @@ #include "vqueue.h" -#include "vcl_returns.h" +#include "vcl.h" #define INDENT 2 @@ -77,7 +77,7 @@ int findent; unsigned cnt; struct vsb *fc, *fh, *fi, *ff, *fb; - struct vsb *fm[N_METHODS]; + struct vsb *fm[VCL_MET_MAX]; VTAILQ_HEAD(, ref) refs; struct vsb *sb; int err; @@ -85,7 +85,7 @@ int ndirector; VTAILQ_HEAD(, proc) procs; struct proc *curproc; - struct proc *mprocs[N_METHODS]; + struct proc *mprocs[VCL_MET_MAX]; VTAILQ_HEAD(, acl_e) acl; Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-06 13:55:45 UTC (rev 3674) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-06 14:04:08 UTC (rev 3675) @@ -3,7 +3,7 @@ * * NB: This file is machine generated, DO NOT EDIT! * - * Edit vcc_gen_fixed_token.tcl instead + * Edit and run vcc_gen_fixed_token.tcl instead */ #include "config.h" @@ -169,12 +169,36 @@ vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3601 2009-02-05 10"); vsb_cat(sb, ":21:48Z tfheen $\n *\n * NB: This file is machine gen"); - vsb_cat(sb, "erated, DO NOT EDIT!\n *\n * Edit vcc_gen_fixed_token."); - vsb_cat(sb, "tcl instead\n */\n\nstruct sess;\n"); + vsb_cat(sb, "erated, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixe"); + vsb_cat(sb, "d_token.tcl instead\n */\n\nstruct sess;\n"); vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n"); vsb_cat(sb, "typedef void vcl_fini_f(struct cli *);\n"); vsb_cat(sb, "typedef int vcl_func_f(struct sess *sp);\n"); - vsb_cat(sb, "\nstruct VCL_conf {\n\tunsigned\tmagic;\n"); + vsb_cat(sb, "\n/* VCL Methods */\n#define VCL_MET_RECV\t\t(1 << 0)\n"); + vsb_cat(sb, "#define VCL_MET_PIPE\t\t(1 << 1)\n"); + vsb_cat(sb, "#define VCL_MET_PASS\t\t(1 << 2)\n"); + vsb_cat(sb, "#define VCL_MET_HASH\t\t(1 << 3)\n"); + vsb_cat(sb, "#define VCL_MET_MISS\t\t(1 << 4)\n"); + vsb_cat(sb, "#define VCL_MET_HIT\t\t(1 << 5)\n"); + vsb_cat(sb, "#define VCL_MET_FETCH\t\t(1 << 6)\n"); + vsb_cat(sb, "#define VCL_MET_DELIVER\t\t(1 << 7)\n"); + vsb_cat(sb, "#define VCL_MET_PREFETCH\t(1 << 8)\n"); + vsb_cat(sb, "#define VCL_MET_TIMEOUT\t\t(1 << 9)\n"); + vsb_cat(sb, "#define VCL_MET_DISCARD\t\t(1 << 10)\n"); + vsb_cat(sb, "#define VCL_MET_ERROR\t\t(1 << 11)\n"); + vsb_cat(sb, "\n#define VCL_MET_MAX\t\t12\n\n"); + vsb_cat(sb, "/* VCL Returns */\n#define VCL_RET_ERROR\t\t(1 << 0)\n"); + vsb_cat(sb, "#define VCL_RET_LOOKUP\t\t(1 << 1)\n"); + vsb_cat(sb, "#define VCL_RET_HASH\t\t(1 << 2)\n"); + vsb_cat(sb, "#define VCL_RET_PIPE\t\t(1 << 3)\n"); + vsb_cat(sb, "#define VCL_RET_PASS\t\t(1 << 4)\n"); + vsb_cat(sb, "#define VCL_RET_FETCH\t\t(1 << 5)\n"); + vsb_cat(sb, "#define VCL_RET_DELIVER\t\t(1 << 6)\n"); + vsb_cat(sb, "#define VCL_RET_DISCARD\t\t(1 << 7)\n"); + vsb_cat(sb, "#define VCL_RET_KEEP\t\t(1 << 8)\n"); + vsb_cat(sb, "#define VCL_RET_RESTART\t\t(1 << 9)\n"); + vsb_cat(sb, "\n#define VCL_RET_MAX\t\t10\n\n"); + vsb_cat(sb, "struct VCL_conf {\n\tunsigned\tmagic;\n"); vsb_cat(sb, "#define VCL_CONF_MAGIC\t0x7406c509\t/* from /dev/rando"); vsb_cat(sb, "m */\n\n\tstruct director\t**director;\n"); vsb_cat(sb, "\tunsigned\tndirector;\n\tstruct vrt_ref\t*ref;\n"); @@ -311,9 +335,9 @@ /* ../../include/vrt_obj.h */ - vsb_cat(sb, "/*\n * $Id: vrt_obj.h 3616 2009-02-05 11:43:20Z tfheen"); - vsb_cat(sb, " $\n *\n * NB: This file is machine generated, DO NOT"); - vsb_cat(sb, " EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); + vsb_cat(sb, "/*\n * $Id: vcc_gen_obj.tcl 3616 2009-02-05 11:43:20Z "); + vsb_cat(sb, "tfheen $\n *\n * NB: This file is machine generated, "); + vsb_cat(sb, "DO NOT EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct "); vsb_cat(sb, "sess *);\nstruct sockaddr * VRT_r_server_ip(struct ses"); vsb_cat(sb, "s *);\nint VRT_r_server_port(struct sess *);\n"); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-06 13:55:45 UTC (rev 3674) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-06 14:04:08 UTC (rev 3675) @@ -109,7 +109,7 @@ puts $fd " *" puts $fd " * NB: This file is machine generated, DO NOT EDIT!" puts $fd " *" - puts $fd " * Edit vcc_gen_fixed_token.tcl instead" + puts $fd " * Edit and run vcc_gen_fixed_token.tcl instead" puts $fd " */" puts $fd "" } @@ -126,6 +126,29 @@ typedef void vcl_fini_f(struct cli *); typedef int vcl_func_f(struct sess *sp); } + +puts $fo "/* VCL Methods */" +set u 0 +foreach m $methods { + if {[string length [lindex $m 0]] < 8} { + set sp "\t" + } else { + set sp "" + } + puts $fo "#define VCL_MET_[string toupper [lindex $m 0]]\t${sp}(1 << $u)" + incr u +} + +puts $fo "\n#define VCL_MET_MAX\t\t$u\n" + +puts $fo "/* VCL Returns */" +set i 0 +foreach k $returns { + puts $fo "#define VCL_RET_[string toupper $k]\t\t(1 << $i)" + incr i +} +puts $fo "\n#define VCL_RET_MAX\t\t$i\n" + puts $fo "struct VCL_conf {" puts $fo { unsigned magic; #define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */ @@ -171,13 +194,6 @@ } incr i } -puts $for "#else" -set i 0 -foreach k $returns { - puts $for "#define VCL_RET_[string toupper $k] (1 << $i)" - incr i -} -puts $for "#define VCL_RET_MAX $i" puts $for "#endif" puts $for "" puts $for "#ifdef VCL_MET_MAC" @@ -186,7 +202,7 @@ puts -nonewline $for "VCL_MET_MAC([lindex $m 0]" puts -nonewline $for ",[string toupper [lindex $m 0]]" set l [lindex $m 1] - puts -nonewline $for ",(\n VCL_RET_[string toupper [lindex $l 0]]" + puts -nonewline $for ",\n (VCL_RET_[string toupper [lindex $l 0]]" foreach r [lrange $l 1 end] { puts -nonewline $for "|VCL_RET_[string toupper $r]" } @@ -194,14 +210,7 @@ puts $for ")" incr u } -puts $for "#else" -set u 0 -foreach m $methods { - puts $for "#define VCL_MET_[string toupper [lindex $m 0]]\t(1 << $u)" - incr u -} puts $for "#endif" -puts $for "#define N_METHODS $u" close $for #---------------------------------------------------------------------- Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-06 13:55:45 UTC (rev 3674) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-06 14:04:08 UTC (rev 3675) @@ -540,7 +540,7 @@ m = IsMethod(tl->t); if (m != -1) { - assert(m < N_METHODS); + assert(m < VCL_MET_MAX); tl->fb = tl->fm[m]; if (tl->mprocs[m] == NULL) { tl->mprocs[m] = vcc_AddProc(tl, tl->t); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_token_defs.h =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_token_defs.h 2009-02-06 13:55:45 UTC (rev 3674) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_token_defs.h 2009-02-06 14:04:08 UTC (rev 3675) @@ -3,7 +3,7 @@ * * NB: This file is machine generated, DO NOT EDIT! * - * Edit vcc_gen_fixed_token.tcl instead + * Edit and run vcc_gen_fixed_token.tcl instead */ #define LOW_TOKEN 128 From tfheen at projects.linpro.no Fri Feb 6 14:18:21 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:18:21 +0100 (CET) Subject: r3676 - in branches/2.0/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20090206141821.BF6281F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:18:21 +0100 (Fri, 06 Feb 2009) New Revision: 3676 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c branches/2.0/varnish-cache/include/vcl.h branches/2.0/varnish-cache/include/vcl_returns.h branches/2.0/varnish-cache/lib/libvcl/vcc_action.c branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c Log: Merge r3484+r3485: Generate VCL_RET_* as enumbering instead of bitmap, compensate elsewhere as required. Remove unecessary args to VCL_[RM]ET_MAC(). Rely on VCL_RET_* definition in vcl.h Adjust to VCL_RET_* being enum instead of bitmap. This solves the "restart" procaction issue in a non-hackish way and looks better overall. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-06 14:18:21 UTC (rev 3676) @@ -595,11 +595,9 @@ void VCL_Get(struct VCL_conf **vcc); 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 *); #include "vcl_returns.h" #undef VCL_MET_MAC -#undef VCL_RET_MAC /* cache_vrt_esi.c */ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vcl.c 2009-02-06 14:18:21 UTC (rev 3676) @@ -300,8 +300,6 @@ /*--------------------------------------------------------------------*/ -#define VCL_RET_MAC(l,u,b,n) - #define VCL_MET_MAC(func, upper, bitmap) \ void \ VCL_##func##_method(struct sess *sp) \ @@ -313,13 +311,12 @@ sp->vcl->func##_func(sp); \ WSP(sp, SLT_VCL_return, "%s", VCC_Return_Name(sp->handling)); \ sp->cur_method = 0; \ - assert(sp->handling & bitmap); \ - assert(!(sp->handling & ~bitmap)); \ + assert((1 << sp->handling) & bitmap); \ + assert(!((1 << sp->handling) & ~bitmap)); \ } #include "vcl_returns.h" #undef VCL_MET_MAC -#undef VCL_RET_MAC /*--------------------------------------------------------------------*/ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-06 14:18:21 UTC (rev 3676) @@ -348,7 +348,7 @@ { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - assert(!(hand & (hand -1))); /* must be power of two */ + assert(hand < VCL_RET_MAX); sp->handling = hand; } Modified: branches/2.0/varnish-cache/include/vcl.h =================================================================== --- branches/2.0/varnish-cache/include/vcl.h 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/include/vcl.h 2009-02-06 14:18:21 UTC (rev 3676) @@ -30,16 +30,16 @@ #define VCL_MET_MAX 12 /* VCL Returns */ -#define VCL_RET_ERROR (1 << 0) -#define VCL_RET_LOOKUP (1 << 1) -#define VCL_RET_HASH (1 << 2) -#define VCL_RET_PIPE (1 << 3) -#define VCL_RET_PASS (1 << 4) -#define VCL_RET_FETCH (1 << 5) -#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_ERROR 0 +#define VCL_RET_LOOKUP 1 +#define VCL_RET_HASH 2 +#define VCL_RET_PIPE 3 +#define VCL_RET_PASS 4 +#define VCL_RET_FETCH 5 +#define VCL_RET_DELIVER 6 +#define VCL_RET_DISCARD 7 +#define VCL_RET_KEEP 8 +#define VCL_RET_RESTART 9 #define VCL_RET_MAX 10 Modified: branches/2.0/varnish-cache/include/vcl_returns.h =================================================================== --- branches/2.0/varnish-cache/include/vcl_returns.h 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/include/vcl_returns.h 2009-02-06 14:18:21 UTC (rev 3676) @@ -7,43 +7,72 @@ */ #ifdef VCL_RET_MAC -#ifdef VCL_RET_MAC_E -VCL_RET_MAC_E(error, ERROR, (1 << 0), 0) +VCL_RET_MAC(error, ERROR) +VCL_RET_MAC(lookup, LOOKUP) +VCL_RET_MAC(hash, HASH) +VCL_RET_MAC(pipe, PIPE) +VCL_RET_MAC(pass, PASS) +VCL_RET_MAC(fetch, FETCH) +VCL_RET_MAC(deliver, DELIVER) +VCL_RET_MAC(discard, DISCARD) +VCL_RET_MAC(keep, KEEP) +VCL_RET_MAC(restart, RESTART) #endif -VCL_RET_MAC(lookup, LOOKUP, (1 << 1), 1) -VCL_RET_MAC(hash, HASH, (1 << 2), 2) -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(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) -#endif #ifdef VCL_MET_MAC VCL_MET_MAC(recv,RECV, - (VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_PIPE|VCL_RET_LOOKUP)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_PASS) + | (1 << VCL_RET_PIPE) + | (1 << VCL_RET_LOOKUP) +)) VCL_MET_MAC(pipe,PIPE, - (VCL_RET_ERROR|VCL_RET_PIPE)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_PIPE) +)) VCL_MET_MAC(pass,PASS, - (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_RESTART) + | (1 << VCL_RET_PASS) +)) VCL_MET_MAC(hash,HASH, - (VCL_RET_HASH)) + ((1 << VCL_RET_HASH) +)) VCL_MET_MAC(miss,MISS, - (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_FETCH)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_RESTART) + | (1 << VCL_RET_PASS) + | (1 << VCL_RET_FETCH) +)) VCL_MET_MAC(hit,HIT, - (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_DELIVER)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_RESTART) + | (1 << VCL_RET_PASS) + | (1 << VCL_RET_DELIVER) +)) VCL_MET_MAC(fetch,FETCH, - (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_DELIVER)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_RESTART) + | (1 << VCL_RET_PASS) + | (1 << VCL_RET_DELIVER) +)) VCL_MET_MAC(deliver,DELIVER, - (VCL_RET_RESTART|VCL_RET_DELIVER)) + ((1 << VCL_RET_RESTART) + | (1 << VCL_RET_DELIVER) +)) VCL_MET_MAC(prefetch,PREFETCH, - (VCL_RET_FETCH|VCL_RET_PASS)) + ((1 << VCL_RET_FETCH) + | (1 << VCL_RET_PASS) +)) VCL_MET_MAC(timeout,TIMEOUT, - (VCL_RET_FETCH|VCL_RET_DISCARD)) + ((1 << VCL_RET_FETCH) + | (1 << VCL_RET_DISCARD) +)) VCL_MET_MAC(discard,DISCARD, - (VCL_RET_DISCARD|VCL_RET_KEEP)) + ((1 << VCL_RET_DISCARD) + | (1 << VCL_RET_KEEP) +)) VCL_MET_MAC(error,ERROR, - (VCL_RET_DELIVER)) + ((1 << VCL_RET_DELIVER) +)) #endif Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-06 14:18:21 UTC (rev 3676) @@ -48,18 +48,16 @@ Expect(tl, ID); -#define VCL_RET_MAC(l, u, b, i) \ +#define VCL_RET_MAC(l, U) \ do { \ if (vcc_IdIs(tl->t, #l)) { \ - Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #u); \ - vcc_ProcAction(tl->curproc, i, tl->t); \ + Fb(tl, 1, "VRT_done(sp, VCL_RET_" #U ");\n"); \ + vcc_ProcAction(tl->curproc, VCL_RET_##U, tl->t);\ retval = 1; \ } \ } while (0); -#define VCL_RET_MAC_E(l, u, b, i) VCL_RET_MAC(l, u, b, i) #include "vcl_returns.h" #undef VCL_RET_MAC -#undef VCL_RET_MAC_E if (!retval) { vsb_printf(tl->sb, "Expected action name.\n"); vcc_ErrWhere(tl, tl->t); @@ -85,8 +83,7 @@ ERRCHK(tl); } Fb(tl, 1, "VRT_done(sp, VCL_RET_RESTART);\n"); - assert(VCL_RET_RESTART == (1 << 9)); /* XXX: BANDAID FIXME! */ - vcc_ProcAction(tl->curproc, 9, tl->t); + vcc_ProcAction(tl->curproc, VCL_RET_RESTART, tl->t); vcc_NextToken(tl); } @@ -465,7 +462,7 @@ } action_table[] = { { "restart", parse_restart }, { "error", parse_error }, -#define VCL_RET_MAC(l, u, b, i) { #l, parse_action }, +#define VCL_RET_MAC(l, U) { #l, parse_action }, #include "vcl_returns.h" #undef VCL_RET_MAC Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-06 14:18:21 UTC (rev 3676) @@ -84,11 +84,9 @@ #include "libvarnish.h" struct method method_tab[] = { -#define VCL_RET_MAC(l,U,b,n) #define VCL_MET_MAC(l,U,m) { "vcl_"#l, m, VCL_MET_##U }, #include "vcl_returns.h" #undef VCL_MET_MAC -#undef VCL_RET_MAC { NULL, 0U, 0} }; @@ -360,12 +358,10 @@ Fc(tl, 0, "\t.srcname = srcname,\n"); Fc(tl, 0, "\t.srcbody = srcbody,\n"); Fc(tl, 0, "\t.nhashcount = %u,\n", tl->nhashcount); -#define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) \ Fc(tl, 0, "\t." #l "_func = VGC_function_vcl_" #l ",\n"); #include "vcl_returns.h" #undef VCL_MET_MAC -#undef VCL_RET_MAC Fc(tl, 0, "};\n"); } @@ -669,11 +665,8 @@ { switch (method) { - case 0: return (""); -#define VCL_RET_MAC(l, u, b, i) case b: return(#l); -#define VCL_RET_MAC_E(l, u, b, i) case b: return(#l); +#define VCL_RET_MAC(l, U) case VCL_RET_##U: return(#l); #include "vcl_returns.h" -#undef VCL_RET_MAC_E #undef VCL_RET_MAC } return (NULL); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.h 2009-02-06 14:18:21 UTC (rev 3676) @@ -142,7 +142,7 @@ struct method { const char *name; - unsigned returns; + unsigned ret_bitmap; unsigned bitval; }; Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-06 14:18:21 UTC (rev 3676) @@ -154,21 +154,11 @@ void vcl_output_lang_h(struct vsb *sb) { - vsb_cat(sb, "#define VCL_RET_ERROR (1 << 0)\n"); - vsb_cat(sb, "#define VCL_RET_LOOKUP (1 << 1)\n"); - vsb_cat(sb, "#define VCL_RET_HASH (1 << 2)\n"); - 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_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"); /* ../../include/vcl.h */ - vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3601 2009-02-05 10"); - vsb_cat(sb, ":21:48Z tfheen $\n *\n * NB: This file is machine gen"); + vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3675 2009-02-06 14"); + vsb_cat(sb, ":04:08Z tfheen $\n *\n * NB: This file is machine gen"); vsb_cat(sb, "erated, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixe"); vsb_cat(sb, "d_token.tcl instead\n */\n\nstruct sess;\n"); vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n"); @@ -187,18 +177,14 @@ vsb_cat(sb, "#define VCL_MET_DISCARD\t\t(1 << 10)\n"); vsb_cat(sb, "#define VCL_MET_ERROR\t\t(1 << 11)\n"); vsb_cat(sb, "\n#define VCL_MET_MAX\t\t12\n\n"); - vsb_cat(sb, "/* VCL Returns */\n#define VCL_RET_ERROR\t\t(1 << 0)\n"); - vsb_cat(sb, "#define VCL_RET_LOOKUP\t\t(1 << 1)\n"); - vsb_cat(sb, "#define VCL_RET_HASH\t\t(1 << 2)\n"); - vsb_cat(sb, "#define VCL_RET_PIPE\t\t(1 << 3)\n"); - vsb_cat(sb, "#define VCL_RET_PASS\t\t(1 << 4)\n"); - vsb_cat(sb, "#define VCL_RET_FETCH\t\t(1 << 5)\n"); - vsb_cat(sb, "#define VCL_RET_DELIVER\t\t(1 << 6)\n"); - vsb_cat(sb, "#define VCL_RET_DISCARD\t\t(1 << 7)\n"); - vsb_cat(sb, "#define VCL_RET_KEEP\t\t(1 << 8)\n"); - vsb_cat(sb, "#define VCL_RET_RESTART\t\t(1 << 9)\n"); - vsb_cat(sb, "\n#define VCL_RET_MAX\t\t10\n\n"); - vsb_cat(sb, "struct VCL_conf {\n\tunsigned\tmagic;\n"); + vsb_cat(sb, "/* VCL Returns */\n#define VCL_RET_ERROR\t\t0\n"); + vsb_cat(sb, "#define VCL_RET_LOOKUP\t\t1\n#define VCL_RET_HASH\t\t2"); + vsb_cat(sb, "\n#define VCL_RET_PIPE\t\t3\n#define VCL_RET_PASS\t\t4"); + vsb_cat(sb, "\n#define VCL_RET_FETCH\t\t5\n#define VCL_RET_DELIVER\t"); + vsb_cat(sb, "\t6\n#define VCL_RET_DISCARD\t\t7\n"); + vsb_cat(sb, "#define VCL_RET_KEEP\t\t8\n#define VCL_RET_RESTART\t\t"); + vsb_cat(sb, "9\n\n#define VCL_RET_MAX\t\t10\n"); + vsb_cat(sb, "\nstruct VCL_conf {\n\tunsigned\tmagic;\n"); vsb_cat(sb, "#define VCL_CONF_MAGIC\t0x7406c509\t/* from /dev/rando"); vsb_cat(sb, "m */\n\n\tstruct director\t**director;\n"); vsb_cat(sb, "\tunsigned\tndirector;\n\tstruct vrt_ref\t*ref;\n"); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-06 14:18:21 UTC (rev 3676) @@ -144,7 +144,7 @@ puts $fo "/* VCL Returns */" set i 0 foreach k $returns { - puts $fo "#define VCL_RET_[string toupper $k]\t\t(1 << $i)" + puts $fo "#define VCL_RET_[string toupper $k]\t\t$i" incr i } puts $fo "\n#define VCL_RET_MAX\t\t$i\n" @@ -186,11 +186,9 @@ foreach k $returns { set u [string toupper $k] if {$k == "error"} { - puts $for "#ifdef VCL_RET_MAC_E" - puts $for "VCL_RET_MAC_E($k, $u, (1 << $i), $i)" - puts $for "#endif" + puts $for "VCL_RET_MAC($k, $u)" } else { - puts $for "VCL_RET_MAC($k, $u, (1 << $i), $i)" + puts $for "VCL_RET_MAC($k, $u)" } incr i } @@ -202,12 +200,12 @@ puts -nonewline $for "VCL_MET_MAC([lindex $m 0]" puts -nonewline $for ",[string toupper [lindex $m 0]]" set l [lindex $m 1] - puts -nonewline $for ",\n (VCL_RET_[string toupper [lindex $l 0]]" + puts $for "," + puts $for " ((1 << VCL_RET_[string toupper [lindex $l 0]])" foreach r [lrange $l 1 end] { - puts -nonewline $for "|VCL_RET_[string toupper $r]" + puts $for " | (1 << VCL_RET_[string toupper $r])" } - puts -nonewline $for ")" - puts $for ")" + puts $for "))" incr u } puts $for "#endif" @@ -400,12 +398,6 @@ puts $fo "void" puts $fo "vcl_output_lang_h(struct vsb *sb)" puts $fo "{" -set i 0 -foreach k $returns { - set u [string toupper $k] - puts $fo "\tvsb_cat(sb, \"#define VCL_RET_$u (1 << $i)\\n\");" - incr i -} copy_include ../../include/vcl.h copy_include ../../include/vrt.h Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c 2009-02-06 14:04:08 UTC (rev 3675) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_xref.c 2009-02-06 14:18:21 UTC (rev 3676) @@ -68,7 +68,7 @@ VTAILQ_HEAD(,proccall) calls; VTAILQ_HEAD(,procuse) uses; struct token *name; - unsigned returns; + unsigned ret_bitmap; unsigned exists; unsigned called; unsigned active; @@ -242,14 +242,15 @@ vcc_ProcAction(struct proc *p, unsigned returns, struct token *t) { - p->returns |= (1U << returns); + assert(returns < VCL_RET_MAX); + p->ret_bitmap |= (1U << returns); /* Record the first instance of this return */ if (p->return_tok[returns] == NULL) p->return_tok[returns] = t; } static int -vcc_CheckActionRecurse(struct tokenlist *tl, struct proc *p, unsigned returns) +vcc_CheckActionRecurse(struct tokenlist *tl, struct proc *p, unsigned bitmap) { unsigned u; struct proccall *pc; @@ -264,13 +265,13 @@ vcc_ErrWhere(tl, p->name); return (1); } - u = p->returns & ~returns; + u = p->ret_bitmap & ~bitmap; if (u) { /*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]); \ +#define VCL_RET_MAC(l, U) \ + if (u & (1 << (VCL_RET_##U))) { \ + vsb_printf(tl->sb, "Invalid return \"" #l "\"\n");\ + vcc_ErrWhere(tl, p->return_tok[VCL_RET_##U]); \ } #include "vcl_returns.h" #undef VCL_RET_MAC @@ -281,7 +282,7 @@ } p->active = 1; VTAILQ_FOREACH(pc, &p->calls, list) { - if (vcc_CheckActionRecurse(tl, pc->p, returns)) { + if (vcc_CheckActionRecurse(tl, pc->p, bitmap)) { vsb_printf(tl->sb, "\n...called from \"%.*s\"\n", PF(p->name)); vcc_ErrWhere(tl, pc->t); @@ -305,19 +306,17 @@ if (i < 0) continue; m = method_tab + i; - if (vcc_CheckActionRecurse(tl, p, m->returns)) { + if (vcc_CheckActionRecurse(tl, p, m->ret_bitmap)) { vsb_printf(tl->sb, "\n...which is the \"%s\" method\n", m->name); vsb_printf(tl->sb, "Legal returns are:"); -#define VCL_RET_MAC(a, b, c, d) \ - 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) +#define VCL_RET_MAC(l, U) \ + if (m->ret_bitmap & ((1 << VCL_RET_##U))) \ + vsb_printf(tl->sb, " \"%s\"", #l); /*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 tfheen at projects.linpro.no Fri Feb 6 14:23:50 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:23:50 +0100 (CET) Subject: r3677 - in branches/2.0/varnish-cache: bin/varnishd lib/libvcl Message-ID: <20090206142350.EC7BE1F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:23:50 +0100 (Fri, 06 Feb 2009) New Revision: 3677 Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Merge r3486: Flexelint'ing Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-06 14:18:21 UTC (rev 3676) +++ branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-06 14:23:50 UTC (rev 3677) @@ -51,6 +51,7 @@ -emacro(736, isnan) // isnanf -efile(766, ../../config.h) -emacro(413, offsetof) // likely null pointer +-emacro(527, WRONG) // unreachable code -emacro(702, WEXITSTATUS) // signed shift right Modified: branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-06 14:18:21 UTC (rev 3676) +++ branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-06 14:23:50 UTC (rev 3677) @@ -30,7 +30,7 @@ * A Crit Bit tree based hash */ -#define PHK 1 +#undef PHK #include "config.h" @@ -66,7 +66,8 @@ static void hcb_build_bittbl(void) { - unsigned x, y; + unsigned char x; + unsigned y; y = 0; for (x = 0; x < 8; x++) @@ -162,10 +163,11 @@ static unsigned hcb_crit_bit(const struct objhead *oh1, const struct objhead *oh2, struct hcb_y *y) { - unsigned u, r; + unsigned char u, r; for (u = 0; u < DIGEST_LEN && oh1->digest[u] == oh2->digest[u]; u++) ; + assert(u < DIGEST_LEN); r = hcb_bits(oh1->digest[u], oh2->digest[u]); y->ptr = u; y->bitmask = 0x80 >> r; @@ -260,7 +262,8 @@ assert(hcb_is_y(*p)); y = NULL; - while(hcb_is_y(*p)) { + while(1) { + assert(hcb_is_y(*p)); y = hcb_l_y(*p); if (y->ptr > DIGEST_LEN) s = 0; @@ -276,12 +279,10 @@ r->cmps++; p = &y->leaf[s]; } -abort(); - *p = y->leaf[1 - s]; } /**********************************************************************/ - +#ifdef PHK static void dumptree(uintptr_t p, int indent, FILE *fd) { @@ -293,9 +294,8 @@ return; if (hcb_is_node(p)) { oh = hcb_l_node(p); - fprintf(fd, "%*.*sN %u %u r%d <%02x%02x%02x...> <%s>\n", - indent, indent, "", DIGEST_LEN, indent / 2, - oh->refcnt, + fprintf(fd, "%*.*sN %d r%u <%02x%02x%02x...> <%s>\n", + indent, indent, "", indent / 2, oh->refcnt, oh->digest[0], oh->digest[1], oh->digest[2], oh->hash); return; @@ -316,8 +316,9 @@ fprintf(fd, "-------------\n"); dumptree(root->origo, 0, fd); fprintf(fd, "-------------\n"); - fflush(fd); + (void)fflush(fd); } +#endif /**********************************************************************/ @@ -333,7 +334,7 @@ THR_SetName("hcb_cleaner"); (void)priv; while (1) { - sleep(1); + (void)sleep(1); Lck_Lock(&hcb_mtx); VTAILQ_FOREACH_SAFE(oh, &laylow, coollist, oh2) { if (oh->hash != NULL) { @@ -345,8 +346,9 @@ continue; if (++oh->refcnt > COOL_DURATION) { VTAILQ_REMOVE(&laylow, oh, coollist); - if (PHK) - fprintf(stderr, "OH %p is cold enough\n", oh); +#ifdef PHK + fprintf(stderr, "OH %p is cold enough\n", oh); +#endif free(oh); VSL_stats->n_objecthead--; } @@ -387,10 +389,10 @@ Lck_Unlock(&hcb_mtx); } Lck_Unlock(&oh->mtx); - if (PHK) { - fprintf(stderr, "%s %d %d <%s>\n", __func__, __LINE__, r, oh->hash); - dump(&hcb_root, stderr); - } +#ifdef PHK + fprintf(stderr, "hcb_defef %d %d <%s>\n", __LINE__, r, oh->hash); + dump(&hcb_root, stderr); +#endif return (r); } @@ -425,19 +427,19 @@ oh = hcb_insert(&hcb_root, noh, 1); if (oh == noh) { VSL_stats->hcb_insert++; - if (PHK) { - fprintf(stderr, "%s %d\n", __func__, __LINE__); - dump(&hcb_root, stderr); - } +#ifdef PHK + fprintf(stderr, "hcb_lookup %d\n", __LINE__); + dump(&hcb_root, stderr); +#endif } else { free(noh->hash); noh->hash = NULL; noh->hashlen = 0; VSL_stats->hcb_lock++; - if (PHK) { - fprintf(stderr, "%s %d\n", __func__, __LINE__); - dump(&hcb_root, stderr); - } +#ifdef PHK + fprintf(stderr, "hcb_lookup %d\n", __LINE__); + dump(&hcb_root, stderr); +#endif } Lck_Unlock(&hcb_mtx); return (oh); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-06 14:18:21 UTC (rev 3676) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-06 14:23:50 UTC (rev 3677) @@ -157,8 +157,8 @@ /* ../../include/vcl.h */ - vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3675 2009-02-06 14"); - vsb_cat(sb, ":04:08Z tfheen $\n *\n * NB: This file is machine gen"); + vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3676 2009-02-06 14"); + vsb_cat(sb, ":18:21Z tfheen $\n *\n * NB: This file is machine gen"); vsb_cat(sb, "erated, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixe"); vsb_cat(sb, "d_token.tcl instead\n */\n\nstruct sess;\n"); vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n"); From tfheen at projects.linpro.no Fri Feb 6 14:27:47 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:27:47 +0100 (CET) Subject: r3678 - in branches/2.0/varnish-cache: bin/varnishd lib/libvcl Message-ID: <20090206142747.9E5841F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:27:47 +0100 (Fri, 06 Feb 2009) New Revision: 3678 Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c Log: Merge r3487: More flexelinting. Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-06 14:23:50 UTC (rev 3677) +++ branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-06 14:27:47 UTC (rev 3678) @@ -40,7 +40,7 @@ -esym(458, heritage) -esym(458, name_key) ////////////// --passes=1 +-passes=3 +libh mgt_event.h +libh ../../config.h @@ -54,6 +54,7 @@ -emacro(527, WRONG) // unreachable code -emacro(702, WEXITSTATUS) // signed shift right +-efunc(525, VCC_Return_Name) // Negative indent // -header(../../config.h) Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-06 14:23:50 UTC (rev 3677) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_compile.c 2009-02-06 14:27:47 UTC (rev 3678) @@ -668,8 +668,9 @@ #define VCL_RET_MAC(l, U) case VCL_RET_##U: return(#l); #include "vcl_returns.h" #undef VCL_RET_MAC + default: + return (NULL); } - return (NULL); } /*-------------------------------------------------------------------- From tfheen at projects.linpro.no Fri Feb 6 14:31:33 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:31:33 +0100 (CET) Subject: r3679 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206143133.CC9E297C24@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:31:33 +0100 (Fri, 06 Feb 2009) New Revision: 3679 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_dir_random.c Log: Merge r3489: remove pointless assignment Modified: branches/2.0/varnish-cache/bin/varnishd/cache_dir_random.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_dir_random.c 2009-02-06 14:27:47 UTC (rev 3678) +++ branches/2.0/varnish-cache/bin/varnishd/cache_dir_random.c 2009-02-06 14:31:33 UTC (rev 3679) @@ -75,7 +75,6 @@ CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC); CAST_OBJ_NOTNULL(vs, sp->director->priv, VDI_RANDOM_MAGIC); - k = 0; for (k = 0; k < vs->retries; ) { /* Sum up the weights of healty backends */ From tfheen at projects.linpro.no Fri Feb 6 14:34:37 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:34:37 +0100 (CET) Subject: r3680 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206143437.8ABC71F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:34:37 +0100 (Fri, 06 Feb 2009) New Revision: 3680 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c Log: Merge r3490: Assert that realloc() did. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 14:31:33 UTC (rev 3679) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 14:34:37 UTC (rev 3680) @@ -908,6 +908,7 @@ n++; } parspec = realloc(parspec, (nparspec + n + 1) * sizeof *parspec); + XXXAN(parspec); for (pp = ps; pp->name != NULL; pp++) parspec[nparspec++] = pp; parspec[nparspec] = NULL; From tfheen at projects.linpro.no Fri Feb 6 14:37:50 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:37:50 +0100 (CET) Subject: r3681 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206143750.A342C1F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:37:50 +0100 (Fri, 06 Feb 2009) New Revision: 3681 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c Log: Merge r3491: Check close(2) status. Assert that we read the C-source file. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-06 14:34:37 UTC (rev 3680) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-06 14:37:50 UTC (rev 3681) @@ -174,7 +174,7 @@ fprintf(stderr, "Cannot write %s", vp->sf); exit (1); } - close(fd); + AZ(close(fd)); free(csrc); exit (0); } @@ -213,6 +213,7 @@ if (C_flag) { csrc = vreadfile(sf); + XXXAN(csrc); (void)fputs(csrc, stdout); free(csrc); } From tfheen at projects.linpro.no Fri Feb 6 14:41:34 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:41:34 +0100 (CET) Subject: r3682 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206144134.D224B1F74B5@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:41:34 +0100 (Fri, 06 Feb 2009) New Revision: 3682 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_session.c Log: Merge r3493: Remove pointless initialization. Fix indentation. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_session.c 2009-02-06 14:37:50 UTC (rev 3681) +++ branches/2.0/varnish-cache/bin/varnishd/cache_session.c 2009-02-06 14:41:34 UTC (rev 3682) @@ -382,7 +382,7 @@ void SES_InheritBackendTimeouts(struct sess *sp) { - struct backend *be = NULL; + struct backend *be; AN(sp); AN(sp->vbe); @@ -395,13 +395,12 @@ * is parameter < backend definition < VCL. */ if (be->connect_timeout > 1e-3 && - sp->connect_timeout == params->connect_timeout) + sp->connect_timeout == params->connect_timeout) sp->connect_timeout = be->connect_timeout; if (be->first_byte_timeout > 1e-3 && - sp->first_byte_timeout == params->first_byte_timeout) + sp->first_byte_timeout == params->first_byte_timeout) sp->first_byte_timeout = be->first_byte_timeout; - if (be->between_bytes_timeout > 1e-3 - && sp->between_bytes_timeout == params->between_bytes_timeout) + if (be->between_bytes_timeout > 1e-3 && + sp->between_bytes_timeout == params->between_bytes_timeout) sp->between_bytes_timeout = be->between_bytes_timeout; } - From tfheen at projects.linpro.no Fri Feb 6 14:46:21 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:46:21 +0100 (CET) Subject: r3683 - branches/2.0/varnish-cache/lib/libvarnish Message-ID: <20090206144621.4525897C24@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:46:21 +0100 (Fri, 06 Feb 2009) New Revision: 3683 Modified: branches/2.0/varnish-cache/lib/libvarnish/cli_common.c Log: Merge r3494: Set the status to CLIS_COMMS if we fal to read the body. Modified: branches/2.0/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/cli_common.c 2009-02-06 14:41:34 UTC (rev 3682) +++ branches/2.0/varnish-cache/lib/libvarnish/cli_common.c 2009-02-06 14:46:21 UTC (rev 3683) @@ -123,7 +123,7 @@ if (cli != NULL) cli->result = res; /*lint !e64 type mismatch */ else - printf("CLI result = %d\n", res); + printf("CLI result = %u\n", res); } void @@ -192,15 +192,16 @@ { char res[CLI_LINE0_LEN]; /* For NUL */ int i, j; - unsigned u, v; + unsigned u, v, s; char *p; + if (status == NULL) + status = &s; if (ptr != NULL) *ptr = NULL; i = read_tmo(fd, res, CLI_LINE0_LEN, tmo); if (i != CLI_LINE0_LEN) { - if (status != NULL) - *status = CLIS_COMMS; + *status = CLIS_COMMS; if (ptr != NULL) *ptr = strdup("CLI communication error"); return (1); @@ -211,12 +212,12 @@ res[CLI_LINE0_LEN - 1] = '\0'; j = sscanf(res, "%u %u\n", &u, &v); assert(j == 2); - if (status != NULL) - *status = u; + *status = u; p = malloc(v + 1); assert(p != NULL); i = read_tmo(fd, p, v + 1, tmo); if (i < 0) { + *status = CLIS_COMMS; free(p); return (i); } From tfheen at projects.linpro.no Fri Feb 6 14:50:45 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:50:45 +0100 (CET) Subject: r3684 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206145045.C2FC21F74B8@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:50:45 +0100 (Fri, 06 Feb 2009) New Revision: 3684 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c Log: Merge r3495: Properly ignore the return value from cli_readres(), we get it in status. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-06 14:46:21 UTC (rev 3683) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-06 14:50:45 UTC (rev 3684) @@ -189,7 +189,7 @@ return (CLIS_COMMS); } - i = cli_readres(cli_i, &u, resp, params->cli_timeout); + (void)cli_readres(cli_i, &u, resp, params->cli_timeout); if (status != NULL) *status = u; return (u == CLIS_OK ? 0 : u); @@ -270,7 +270,7 @@ xxxassert(i == strlen(p)); i = write(cli_o, "\n", 1); xxxassert(i == 1); - i = cli_readres(cli_i, &u, &q, params->cli_timeout); + (void)cli_readres(cli_i, &u, &q, params->cli_timeout); cli_result(cp->cli, u); cli_out(cp->cli, "%s", q); free(q); From tfheen at projects.linpro.no Fri Feb 6 14:54:28 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:54:28 +0100 (CET) Subject: r3685 - in branches/2.0/varnish-cache: bin/varnishd lib/libvarnish Message-ID: <20090206145428.28EFA1F74B8@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:54:27 +0100 (Fri, 06 Feb 2009) New Revision: 3685 Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt branches/2.0/varnish-cache/lib/libvarnish/vsb.c Log: Merge r3496: Make vsb_new() a tad easier for FlexeLint to figure out. Give it proper semantics Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-06 14:50:45 UTC (rev 3684) +++ branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-06 14:54:27 UTC (rev 3685) @@ -56,13 +56,12 @@ -emacro(702, WEXITSTATUS) // signed shift right -efunc(525, VCC_Return_Name) // Negative indent - // -header(../../config.h) // Fix strchr() semtics, it can only return NULL if arg2 != 0 -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) --sem(vsb_new, @p == malloc(1)) +-sem(vsb_new, @p == (1p ? 1p : malloc(1))) -sem(vsb_delete, custodial(1)) -sem(lbv_assert, r_no) -sem(lbv_xxxassert, r_no) Modified: branches/2.0/varnish-cache/lib/libvarnish/vsb.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vsb.c 2009-02-06 14:50:45 UTC (rev 3684) +++ branches/2.0/varnish-cache/lib/libvarnish/vsb.c 2009-02-06 14:54:27 UTC (rev 3685) @@ -162,15 +162,17 @@ s = (struct vsb *)SBMALLOC(sizeof *s); if (s == NULL) return (NULL); - memset(s, 0, sizeof *s); - s->s_flags = flags; - s->s_magic = VSB_MAGIC; + if (vsb_new(s, buf, length, flags) == NULL) { + free(s); + return (NULL); + } VSB_SETFLAG(s, VSB_DYNSTRUCT); - } else { - memset(s, 0, sizeof *s); - s->s_flags = flags; - s->s_magic = VSB_MAGIC; + return (s); } + + memset(s, 0, sizeof *s); + s->s_flags = flags; + s->s_magic = VSB_MAGIC; s->s_size = length; if (buf) { s->s_buf = buf; @@ -179,11 +181,8 @@ if (flags & VSB_AUTOEXTEND) s->s_size = vsb_extendsize(s->s_size); s->s_buf = (char *)SBMALLOC(s->s_size); - if (s->s_buf == NULL) { - if (VSB_ISDYNSTRUCT(s)) - SBFREE(s); + if (s->s_buf == NULL) return (NULL); - } VSB_SETFLAG(s, VSB_DYNAMIC); return (s); } From tfheen at projects.linpro.no Fri Feb 6 14:58:27 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 15:58:27 +0100 (CET) Subject: r3686 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206145827.95C991F74B8@projects.linpro.no> Author: tfheen Date: 2009-02-06 15:58:26 +0100 (Fri, 06 Feb 2009) New Revision: 3686 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/varnishd.c Log: Merge r3497: Minor polishing for the benefit of Glorius Checker of Code FlexeLint. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-06 14:54:27 UTC (rev 3685) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-06 14:58:26 UTC (rev 3686) @@ -298,7 +298,6 @@ { struct worker *w; struct http *h; - time_t now; char date[40]; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -322,8 +321,7 @@ 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); + TIM_format(TIM_real(), 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); @@ -537,7 +535,6 @@ return (0); default: WRONG("Illegal action in vcl_hit{}"); - return (0); } } @@ -671,10 +668,8 @@ return (0); case VCL_RET_RESTART: INCOMPL(); - return (0); default: WRONG("Illegal action in vcl_miss{}"); - return (0); } } @@ -849,7 +844,6 @@ return (0); default: WRONG("Illegal action in vcl_recv{}"); - return (0); } } @@ -1025,11 +1019,15 @@ cli_out(cli, "XID is %u", xids); } +/* + * Default to seed=1, this is the only seed value POSIXl guarantees will + * result in a reproducible random number sequence. + */ static void cli_debug_srandom(struct cli *cli, const char * const *av, void *priv) { (void)priv; - unsigned long seed; + unsigned seed = 1; if (av[2] != NULL) seed = strtoul(av[2], NULL, 0); Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-06 14:54:27 UTC (rev 3685) +++ branches/2.0/varnish-cache/bin/varnishd/varnishd.c 2009-02-06 14:58:26 UTC (rev 3686) @@ -543,7 +543,7 @@ argv += optind; if (argc != 0) { - fprintf(stderr, "Too many arguments\n"); + fprintf(stderr, "Too many arguments (%s...)\n", argv[0]); usage(); } From tfheen at projects.linpro.no Fri Feb 6 15:03:21 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 16:03:21 +0100 (CET) Subject: r3687 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090206150321.CEDCF97C4D@projects.linpro.no> Author: tfheen Date: 2009-02-06 16:03:21 +0100 (Fri, 06 Feb 2009) New Revision: 3687 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/v00416.vtc Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c Log: Merge r3498: Handle too many headers more gracefully If we get more HTTP headers than we have room for (default: 28) we used to ignore the rest. This is not a bright solution if crucial HTTP headers like "Content-Length" or "Transfer-Encoding" are last and get ignored. In general, it is highly suspect to randomly ignore HTTP headers, as opposed to deliberately ignoring them, either by having first looked at them and found them uninteresting, or by having looked for the headers we care about, and having not matched some others. Change too many headers to firm error condition: 400 if from the client, and 503 (like every other trouble) if from the backend. Fixes #416 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-06 14:58:26 UTC (rev 3686) +++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-06 15:03:21 UTC (rev 3687) @@ -354,6 +354,7 @@ } else { VSL_stats->losthdr++; WSL(w, SLT_LostHeader, fd, "%.*s", q - p, p); + return (400); } } return (0); Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/v00416.vtc (from rev 3498, trunk/varnish-cache/bin/varnishtest/tests/v00416.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/v00416.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/v00416.vtc 2009-02-06 15:03:21 UTC (rev 3687) @@ -0,0 +1,102 @@ +# $Id$ + +test "Regression test for #416: a surplus of HTTP headers" + +server s1 { + rxreq + txresp \ + -hdr hdr00=00 \ + -hdr hdr01=01 \ + -hdr hdr02=02 \ + -hdr hdr03=03 \ + -hdr hdr04=04 \ + -hdr hdr05=05 \ + -hdr hdr06=06 \ + -hdr hdr07=07 \ + -hdr hdr08=08 \ + -hdr hdr09=09 \ + -hdr hdr10=10 \ + -hdr hdr11=11 \ + -hdr hdr12=12 \ + -hdr hdr13=13 \ + -hdr hdr14=14 \ + -hdr hdr15=15 \ + -hdr hdr16=16 \ + -hdr hdr17=17 \ + -hdr hdr18=18 \ + -hdr hdr19=19 \ + -hdr hdr20=20 \ + -hdr hdr21=21 \ + -hdr hdr22=22 \ + -hdr hdr23=23 \ + -hdr hdr24=24 \ + -hdr hdr25=25 \ + -hdr hdr26=26 \ + -hdr hdr27=27 \ + -hdr hdr28=28 \ + -hdr hdr29=29 \ + -hdr hdr30=30 \ + -hdr hdr31=31 \ + -hdr hdr32=32 \ + -hdr hdr33=33 \ + -hdr hdr34=34 \ + -hdr hdr35=35 \ + -hdr hdr36=36 \ + -hdr hdr37=37 \ + -hdr hdr38=38 \ + -hdr hdr39=39 \ + -body "foo" +} -start + +varnish v1 -vcl+backend {} -start + +client c1 { + txreq \ + -hdr hdr00=00 \ + -hdr hdr01=01 \ + -hdr hdr02=02 \ + -hdr hdr03=03 \ + -hdr hdr04=04 \ + -hdr hdr05=05 \ + -hdr hdr06=06 \ + -hdr hdr07=07 \ + -hdr hdr08=08 \ + -hdr hdr09=09 \ + -hdr hdr10=10 \ + -hdr hdr11=11 \ + -hdr hdr12=12 \ + -hdr hdr13=13 \ + -hdr hdr14=14 \ + -hdr hdr15=15 \ + -hdr hdr16=16 \ + -hdr hdr17=17 \ + -hdr hdr18=18 \ + -hdr hdr19=19 \ + -hdr hdr20=20 \ + -hdr hdr21=21 \ + -hdr hdr22=22 \ + -hdr hdr23=23 \ + -hdr hdr24=24 \ + -hdr hdr25=25 \ + -hdr hdr26=26 \ + -hdr hdr27=27 \ + -hdr hdr28=28 \ + -hdr hdr29=29 \ + -hdr hdr30=30 \ + -hdr hdr31=31 \ + -hdr hdr32=32 \ + -hdr hdr33=33 \ + -hdr hdr34=34 \ + -hdr hdr35=35 \ + -hdr hdr36=36 \ + -hdr hdr37=37 \ + -hdr hdr38=38 \ + -hdr hdr39=39 + rxresp +} -run + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run From tfheen at projects.linpro.no Fri Feb 6 15:06:50 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 16:06:50 +0100 (CET) Subject: r3688 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090206150650.C92CC1F74B8@projects.linpro.no> Author: tfheen Date: 2009-02-06 16:06:50 +0100 (Fri, 06 Feb 2009) New Revision: 3688 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/r00416.vtc Removed: branches/2.0/varnish-cache/bin/varnishtest/tests/v00416.vtc Log: Merge r3499: This is a regression test Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/r00416.vtc (from rev 3499, trunk/varnish-cache/bin/varnishtest/tests/r00416.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/r00416.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/r00416.vtc 2009-02-06 15:06:50 UTC (rev 3688) @@ -0,0 +1,102 @@ +# $Id$ + +test "Regression test for #416: a surplus of HTTP headers" + +server s1 { + rxreq + txresp \ + -hdr hdr00=00 \ + -hdr hdr01=01 \ + -hdr hdr02=02 \ + -hdr hdr03=03 \ + -hdr hdr04=04 \ + -hdr hdr05=05 \ + -hdr hdr06=06 \ + -hdr hdr07=07 \ + -hdr hdr08=08 \ + -hdr hdr09=09 \ + -hdr hdr10=10 \ + -hdr hdr11=11 \ + -hdr hdr12=12 \ + -hdr hdr13=13 \ + -hdr hdr14=14 \ + -hdr hdr15=15 \ + -hdr hdr16=16 \ + -hdr hdr17=17 \ + -hdr hdr18=18 \ + -hdr hdr19=19 \ + -hdr hdr20=20 \ + -hdr hdr21=21 \ + -hdr hdr22=22 \ + -hdr hdr23=23 \ + -hdr hdr24=24 \ + -hdr hdr25=25 \ + -hdr hdr26=26 \ + -hdr hdr27=27 \ + -hdr hdr28=28 \ + -hdr hdr29=29 \ + -hdr hdr30=30 \ + -hdr hdr31=31 \ + -hdr hdr32=32 \ + -hdr hdr33=33 \ + -hdr hdr34=34 \ + -hdr hdr35=35 \ + -hdr hdr36=36 \ + -hdr hdr37=37 \ + -hdr hdr38=38 \ + -hdr hdr39=39 \ + -body "foo" +} -start + +varnish v1 -vcl+backend {} -start + +client c1 { + txreq \ + -hdr hdr00=00 \ + -hdr hdr01=01 \ + -hdr hdr02=02 \ + -hdr hdr03=03 \ + -hdr hdr04=04 \ + -hdr hdr05=05 \ + -hdr hdr06=06 \ + -hdr hdr07=07 \ + -hdr hdr08=08 \ + -hdr hdr09=09 \ + -hdr hdr10=10 \ + -hdr hdr11=11 \ + -hdr hdr12=12 \ + -hdr hdr13=13 \ + -hdr hdr14=14 \ + -hdr hdr15=15 \ + -hdr hdr16=16 \ + -hdr hdr17=17 \ + -hdr hdr18=18 \ + -hdr hdr19=19 \ + -hdr hdr20=20 \ + -hdr hdr21=21 \ + -hdr hdr22=22 \ + -hdr hdr23=23 \ + -hdr hdr24=24 \ + -hdr hdr25=25 \ + -hdr hdr26=26 \ + -hdr hdr27=27 \ + -hdr hdr28=28 \ + -hdr hdr29=29 \ + -hdr hdr30=30 \ + -hdr hdr31=31 \ + -hdr hdr32=32 \ + -hdr hdr33=33 \ + -hdr hdr34=34 \ + -hdr hdr35=35 \ + -hdr hdr36=36 \ + -hdr hdr37=37 \ + -hdr hdr38=38 \ + -hdr hdr39=39 + rxresp +} -run + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run Deleted: branches/2.0/varnish-cache/bin/varnishtest/tests/v00416.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/v00416.vtc 2009-02-06 15:03:21 UTC (rev 3687) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/v00416.vtc 2009-02-06 15:06:50 UTC (rev 3688) @@ -1,102 +0,0 @@ -# $Id$ - -test "Regression test for #416: a surplus of HTTP headers" - -server s1 { - rxreq - txresp \ - -hdr hdr00=00 \ - -hdr hdr01=01 \ - -hdr hdr02=02 \ - -hdr hdr03=03 \ - -hdr hdr04=04 \ - -hdr hdr05=05 \ - -hdr hdr06=06 \ - -hdr hdr07=07 \ - -hdr hdr08=08 \ - -hdr hdr09=09 \ - -hdr hdr10=10 \ - -hdr hdr11=11 \ - -hdr hdr12=12 \ - -hdr hdr13=13 \ - -hdr hdr14=14 \ - -hdr hdr15=15 \ - -hdr hdr16=16 \ - -hdr hdr17=17 \ - -hdr hdr18=18 \ - -hdr hdr19=19 \ - -hdr hdr20=20 \ - -hdr hdr21=21 \ - -hdr hdr22=22 \ - -hdr hdr23=23 \ - -hdr hdr24=24 \ - -hdr hdr25=25 \ - -hdr hdr26=26 \ - -hdr hdr27=27 \ - -hdr hdr28=28 \ - -hdr hdr29=29 \ - -hdr hdr30=30 \ - -hdr hdr31=31 \ - -hdr hdr32=32 \ - -hdr hdr33=33 \ - -hdr hdr34=34 \ - -hdr hdr35=35 \ - -hdr hdr36=36 \ - -hdr hdr37=37 \ - -hdr hdr38=38 \ - -hdr hdr39=39 \ - -body "foo" -} -start - -varnish v1 -vcl+backend {} -start - -client c1 { - txreq \ - -hdr hdr00=00 \ - -hdr hdr01=01 \ - -hdr hdr02=02 \ - -hdr hdr03=03 \ - -hdr hdr04=04 \ - -hdr hdr05=05 \ - -hdr hdr06=06 \ - -hdr hdr07=07 \ - -hdr hdr08=08 \ - -hdr hdr09=09 \ - -hdr hdr10=10 \ - -hdr hdr11=11 \ - -hdr hdr12=12 \ - -hdr hdr13=13 \ - -hdr hdr14=14 \ - -hdr hdr15=15 \ - -hdr hdr16=16 \ - -hdr hdr17=17 \ - -hdr hdr18=18 \ - -hdr hdr19=19 \ - -hdr hdr20=20 \ - -hdr hdr21=21 \ - -hdr hdr22=22 \ - -hdr hdr23=23 \ - -hdr hdr24=24 \ - -hdr hdr25=25 \ - -hdr hdr26=26 \ - -hdr hdr27=27 \ - -hdr hdr28=28 \ - -hdr hdr29=29 \ - -hdr hdr30=30 \ - -hdr hdr31=31 \ - -hdr hdr32=32 \ - -hdr hdr33=33 \ - -hdr hdr34=34 \ - -hdr hdr35=35 \ - -hdr hdr36=36 \ - -hdr hdr37=37 \ - -hdr hdr38=38 \ - -hdr hdr39=39 - rxresp -} -run - -client c1 { - txreq - rxresp - expect resp.status == 503 -} -run From tfheen at projects.linpro.no Fri Feb 6 15:10:33 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 16:10:33 +0100 (CET) Subject: r3689 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090206151033.963F01F74B8@projects.linpro.no> Author: tfheen Date: 2009-02-06 16:10:33 +0100 (Fri, 06 Feb 2009) New Revision: 3689 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/r00387.vtc Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c Log: Merge r3500: Fail long chunked transactions, don't panic Don't panic if the chunked header is ridiculously long, just fail the transaction. Fixes #387 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-06 15:06:50 UTC (rev 3688) +++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-06 15:10:33 UTC (rev 3689) @@ -110,7 +110,8 @@ /* If we didn't succeed, add to buffer, try again */ if (q == NULL || q == buf || *q != '\n') { - xxxassert(be > bp); + if (bp >= be) + return (-1); /* * The semantics we need here is "read until you have * received at least one character, but feel free to Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/r00387.vtc (from rev 3500, trunk/varnish-cache/bin/varnishtest/tests/r00387.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/r00387.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/r00387.vtc 2009-02-06 15:10:33 UTC (rev 3689) @@ -0,0 +1,22 @@ +# $Id$ + +test "Regression test for #387: too long chunk header" + +server s1 { + rxreq + send "HTTP/1.1 200 Ok\r\n" + send "Transfer-encoding: chunked\r\n" + send "\r\n" + send "004\r\n1234\r\n" + send "000000000000000000001\r\n@\r\n" + send "00000000\r\n" +} -start + +varnish v1 -vcl+backend {} -start + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run + From tfheen at projects.linpro.no Fri Feb 6 15:27:35 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 16:27:35 +0100 (CET) Subject: r3690 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090206152735.3E4BD1F74B8@projects.linpro.no> Author: tfheen Date: 2009-02-06 16:27:34 +0100 (Fri, 06 Feb 2009) New Revision: 3690 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c Log: Merge r3501+r3502: Don't panic if we fail to delete shared objects in atexit(). Fixes #376 Addendum to r3501: remove the file from the list. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-06 15:10:33 UTC (rev 3689) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-06 15:27:34 UTC (rev 3690) @@ -436,7 +436,8 @@ vp = VTAILQ_FIRST(&vclhead); if (vp == NULL) break; - mgt_vcc_del(vp); + (void)unlink(vp->fname); + VTAILQ_REMOVE(&vclhead, vp, list); } } From tfheen at projects.linpro.no Fri Feb 6 15:31:03 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 6 Feb 2009 16:31:03 +0100 (CET) Subject: r3691 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090206153103.617D597C24@projects.linpro.no> Author: tfheen Date: 2009-02-06 16:31:03 +0100 (Fri, 06 Feb 2009) New Revision: 3691 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/c00020.vtc Log: Merge r3503: Add a minimal testcase of critbit Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/c00020.vtc (from rev 3503, trunk/varnish-cache/bin/varnishtest/tests/c00020.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00020.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00020.vtc 2009-02-06 15:31:03 UTC (rev 3691) @@ -0,0 +1,32 @@ +# $Id$ + +test "Test -h critbit a bit" + +server s1 { + rxreq + txresp -hdr "Connection: close" -body "012345\n" +} -start + +varnish v1 -arg "-hcritbit" -vcl+backend { } -start + +client c1 { + txreq -url "/" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1001" +} -run + +client c2 { + txreq -url "/" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1002 1001" +} -run + +varnish v1 -expect client_conn == 2 +varnish v1 -expect cache_hit == 1 +varnish v1 -expect cache_miss == 1 +varnish v1 -expect client_req == 2 +varnish v1 -expect s_sess == 2 +varnish v1 -expect s_req == 2 +varnish v1 -expect s_fetch == 1 From des at projects.linpro.no Fri Feb 6 21:12:47 2009 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 6 Feb 2009 22:12:47 +0100 (CET) Subject: r3692 - trunk/varnish-cache/man Message-ID: <20090206211247.2A9F01F74B6@projects.linpro.no> Author: des Date: 2009-02-06 22:12:46 +0100 (Fri, 06 Feb 2009) New Revision: 3692 Modified: trunk/varnish-cache/man/vcl.7so Log: Whitespace cleanup Modified: trunk/varnish-cache/man/vcl.7so =================================================================== --- trunk/varnish-cache/man/vcl.7so 2009-02-06 15:31:03 UTC (rev 3691) +++ trunk/varnish-cache/man/vcl.7so 2009-02-06 21:12:46 UTC (rev 3692) @@ -115,7 +115,7 @@ .Ss Directors Directors choose from different backends based on health status and a per-director algorithm. -There currently exists a round-robin and a random director. +There currently exists a round-robin and a random director. .Pp Directors are defined using: .Bd -literal -offset 4n @@ -148,7 +148,7 @@ The round-robin does not take any options. .Ss Backend probes Backends can be probed to see whether they should be considered -healthy or not. The return status can also be checked by using +healthy or not. The return status can also be checked by using .Fa req.backend.healthy . .Fa .window @@ -206,7 +206,7 @@ pipe; } .Ed -.Ss Grace +.Ss Grace If the backend takes a long time to generate an object there is a risk of a thread pile up. In order to prevent this you can enable grace. From des at projects.linpro.no Fri Feb 6 21:21:50 2009 From: des at projects.linpro.no (des at projects.linpro.no) Date: Fri, 6 Feb 2009 22:21:50 +0100 (CET) Subject: r3693 - trunk/varnish-cache/man Message-ID: <20090206212150.5E8E71F74B6@projects.linpro.no> Author: des Date: 2009-02-06 22:21:50 +0100 (Fri, 06 Feb 2009) New Revision: 3693 Modified: trunk/varnish-cache/man/vcl.7so Log: Fix backslashes. Modified: trunk/varnish-cache/man/vcl.7so =================================================================== --- trunk/varnish-cache/man/vcl.7so 2009-02-06 21:12:46 UTC (rev 3692) +++ trunk/varnish-cache/man/vcl.7so 2009-02-06 21:21:50 UTC (rev 3693) @@ -56,7 +56,7 @@ (!, && and ||) operators, VCL supports regular expression and ACL matching using the ~ operator. .Pp -Unlike C and Perl, the backslash (\\) character has no special meaning +Unlike C and Perl, the backslash (\e) character has no special meaning in strings in VCL, which use the (%xx) escape mechanism just like URLs, so it can be freely used in regular expressions without doubling. .Pp @@ -174,7 +174,7 @@ .host = "www.example.com"; .port = "http"; .probe = { - # NB: \\r\\n automatically inserted after each string! + # NB: \er\en automatically inserted after each string! .request = "GET / HTTP/1.1" "Host: www.foo.bar" @@ -236,11 +236,11 @@ .Fa sub . Within .Fa sub , -.Va \\0 +.Va \e0 (which can also be spelled .Va & ) is replaced with the entire matched string, and -.Va \\n +.Va \en is replaced with the contents of subgroup .Ar n in the matched string. From tfheen at projects.linpro.no Mon Feb 9 11:33:59 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 12:33:59 +0100 (CET) Subject: r3694 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209113359.910BE2842C@projects.linpro.no> Author: tfheen Date: 2009-02-09 12:33:59 +0100 (Mon, 09 Feb 2009) New Revision: 3694 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/hash_classic.c branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c branches/2.0/varnish-cache/bin/varnishd/heritage.h branches/2.0/varnish-cache/bin/varnishd/mgt_param.c Log: Merge r3504: Make SHA256 digest standard and use it in hash_classic.c Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-06 21:21:50 UTC (rev 3693) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 11:33:59 UTC (rev 3694) @@ -214,8 +214,7 @@ if (u) p += sizeof(const char *) - u; sp->hashptr = (void*)p; - if (params->hash_sha256) - SHA256_Init(sp->wrk->sha256ctx); + SHA256_Init(sp->wrk->sha256ctx); } void @@ -238,10 +237,8 @@ sp->hashptr[sp->ihashptr + 1] = str + l; sp->ihashptr += 2; sp->lhashptr += l + 1; - if (params->hash_sha256) { - SHA256_Update(sp->wrk->sha256ctx, str, l); - SHA256_Update(sp->wrk->sha256ctx, "#", 1); - } + SHA256_Update(sp->wrk->sha256ctx, str, l); + SHA256_Update(sp->wrk->sha256ctx, "#", 1); } struct object * @@ -260,10 +257,7 @@ h = sp->http; HSH_Prealloc(sp); - if (params->hash_sha256) { - SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); - /* WSP(sp, SLT_Debug, "SHA256: <%.32s>", sha256); */ - } + SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); if (sp->objhead != NULL) { CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC); Modified: branches/2.0/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-06 21:21:50 UTC (rev 3693) +++ branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-09 11:33:59 UTC (rev 3694) @@ -120,19 +120,13 @@ struct objhead *oh; struct hcl_hd *hp; unsigned u1, digest; - unsigned u, v; int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC); - digest = ~0U; - for (u = 0; u < sp->ihashptr; u += 2) { - v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); - digest = crc32(digest, sp->hashptr[u], v); - } - digest ^= ~0U; - + assert(sizeof noh->digest > sizeof digest); + memcpy(&digest, noh->digest, sizeof digest); u1 = digest % hcl_nhash; hp = &hcl_head[u1]; Modified: branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-06 21:21:50 UTC (rev 3693) +++ branches/2.0/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-09 11:33:59 UTC (rev 3694) @@ -367,7 +367,6 @@ (void)oh; AZ(pthread_create(&tp, NULL, hcb_cleaner, NULL)); - assert(params->hash_sha256); assert(sizeof(struct hcb_y) <= sizeof(oh->u)); memset(&hcb_root, 0, sizeof hcb_root); hcb_build_bittbl(); @@ -402,7 +401,6 @@ struct objhead *oh; unsigned u; - assert(params->hash_sha256); oh = hcb_insert(&hcb_root, noh, 0); if (oh != NULL) { /* Assert that we didn't muck with the tree without lock */ Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-06 21:21:50 UTC (rev 3693) +++ branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-09 11:33:59 UTC (rev 3694) @@ -174,9 +174,6 @@ /* Default grace period */ unsigned default_grace; - /* Use sha256 hasing */ - unsigned hash_sha256; - /* Log hash string to shm */ unsigned log_hash; Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-06 21:21:50 UTC (rev 3693) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-09 11:33:59 UTC (rev 3694) @@ -710,10 +710,6 @@ "NB: Must be specified with -p to have effect.\n", 0, "8192", "bytes" }, - { "hash_sha256", tweak_bool, &master.hash_sha256, 0, 0, - "Use SHA256 compression of hash-strings", - 0, - "on", "bool" }, { "log_hashstring", tweak_bool, &master.log_hash, 0, 0, "Log the hash string to shared memory log.\n", 0, From tfheen at projects.linpro.no Mon Feb 9 12:06:18 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:06:18 +0100 (CET) Subject: r3695 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090209120618.9657C28440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:06:18 +0100 (Mon, 09 Feb 2009) New Revision: 3695 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00020.vtc Log: Merge r3505: Expand critbit test for more coverage Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00020.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00020.vtc 2009-02-09 11:33:59 UTC (rev 3694) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00020.vtc 2009-02-09 12:06:18 UTC (rev 3695) @@ -4,6 +4,7 @@ server s1 { rxreq + expect req.url == "/" txresp -hdr "Connection: close" -body "012345\n" } -start @@ -23,10 +24,38 @@ expect resp.http.X-Varnish == "1002 1001" } -run -varnish v1 -expect client_conn == 2 -varnish v1 -expect cache_hit == 1 -varnish v1 -expect cache_miss == 1 -varnish v1 -expect client_req == 2 -varnish v1 -expect s_sess == 2 -varnish v1 -expect s_req == 2 -varnish v1 -expect s_fetch == 1 +server s1 { + rxreq + expect req.url == "/foo" + txresp -body "012345\n" + rxreq + expect req.url == "/bar" + txresp -body "012345\n" +} -start + +client c2 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1003" + txreq -url "/" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1004 1001" + txreq -url "/bar" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1005" + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1006 1003" +} -run + +varnish v1 -expect client_conn == 3 +varnish v1 -expect cache_hit == 3 +varnish v1 -expect cache_miss == 3 +varnish v1 -expect client_req == 6 +varnish v1 -expect s_sess == 3 +varnish v1 -expect s_req == 6 +varnish v1 -expect s_fetch == 3 From tfheen at projects.linpro.no Mon Feb 9 12:10:36 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:10:36 +0100 (CET) Subject: r3696 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209121036.6288728440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:10:36 +0100 (Mon, 09 Feb 2009) New Revision: 3696 Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h Log: Merge r3506: don't overload the waiting list (yet), I suspect it causes #414b Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-09 12:06:18 UTC (rev 3695) +++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-09 12:10:36 UTC (rev 3696) @@ -78,12 +78,17 @@ char *hash; unsigned hashlen; unsigned char digest[DIGEST_LEN]; +#ifdef NOT_YET union { VTAILQ_HEAD(, sess) __u_waitinglist; VTAILQ_ENTRY(objhead) __u_coollist; } __u; #define waitinglist __u.__u_waitinglist #define coollist __u.__u_coollist +#else + VTAILQ_HEAD(, sess) waitinglist; + VTAILQ_ENTRY(objhead) coollist; +#endif /*---------------------------------------------------- * The fields below are for the sole private use of From tfheen at projects.linpro.no Mon Feb 9 12:13:38 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:13:38 +0100 (CET) Subject: r3697 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209121338.BAA9228440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:13:38 +0100 (Mon, 09 Feb 2009) New Revision: 3697 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/hash_classic.c branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h Log: Merge r3507: Ditch HSH_Compare() and just check the digest with memcmp() Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 12:10:36 UTC (rev 3696) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 12:13:38 UTC (rev 3697) @@ -143,36 +143,6 @@ } } -int -HSH_Compare(const struct sess *sp, const struct objhead *oh) -{ - int i; - unsigned u, v; - const char *b; - - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); - CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); - i = sp->lhashptr - oh->hashlen; - if (i) - return (i); - b = oh->hash; - for (u = 0; u < sp->ihashptr; u += 2) { - v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); - i = memcmp(sp->hashptr[u], b, v); - if (i) - return (i); - b += v; - i = '#' - *b++; - if (i) - return (i); - } - assert(*b == '\0'); - b++; - assert(b == oh->hash + oh->hashlen); - return (0); -} - void HSH_Copy(const struct sess *sp, struct objhead *oh) { Modified: branches/2.0/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-09 12:10:36 UTC (rev 3696) +++ branches/2.0/varnish-cache/bin/varnishd/hash_classic.c 2009-02-09 12:13:38 UTC (rev 3697) @@ -132,15 +132,7 @@ Lck_Lock(&hp->mtx); VTAILQ_FOREACH(oh, &hp->head, hoh_list) { - if (sp->lhashptr < oh->hashlen) - continue; - if (sp->lhashptr > oh->hashlen) - break; - if (oh->hoh_digest < digest) - continue; - if (oh->hoh_digest > digest) - break; - i = HSH_Compare(sp, oh); + i = memcmp(oh->digest, noh->digest, sizeof oh->digest); if (i < 0) continue; if (i > 0) Modified: branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-09 12:10:36 UTC (rev 3696) +++ branches/2.0/varnish-cache/bin/varnishd/hash_simple_list.c 2009-02-09 12:13:38 UTC (rev 3697) @@ -75,7 +75,7 @@ CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC); Lck_Lock(&hsl_mtx); VTAILQ_FOREACH(oh, &hsl_head, hoh_list) { - i = HSH_Compare(sp, oh); + i = memcmp(oh->digest, noh->digest, sizeof oh->digest); if (i < 0) continue; if (i > 0) Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-09 12:10:36 UTC (rev 3696) +++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-09 12:13:38 UTC (rev 3697) @@ -51,7 +51,6 @@ /* 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, struct objhead *o); struct object *HSH_Lookup(struct sess *sp); void HSH_Unbusy(const struct sess *sp); From tfheen at projects.linpro.no Mon Feb 9 12:18:32 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:18:32 +0100 (CET) Subject: r3698 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209121832.5805028440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:18:32 +0100 (Mon, 09 Feb 2009) New Revision: 3698 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c Log: Merge r3508: Change the way bans/purges are stored Change the way bans/purges are stored, so that each ban has a list of conditions to test. This paves the way for a much more expressive ban/purge syntax where things like: purge req.http.host ~ "web1.com" && req.url ~ "\.png" purge obj.age > 1w && obj.size > 1MB purge obj.http.set-cookie ~ "USER=838339" && req.url ~ "\.html" become possible. Not quite there yet though. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-09 12:13:38 UTC (rev 3697) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-09 12:18:32 UTC (rev 3698) @@ -422,7 +422,7 @@ void BAN_Init(void); void BAN_NewObj(struct object *o); void BAN_DestroyObj(struct object *o); -int BAN_CheckObject(struct object *o, const char *url, const char *hash); +int BAN_CheckObject(struct object *o, const struct sess *sp); /* cache_center.c [CNT] */ void CNT_Session(struct sess *sp); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:13:38 UTC (rev 3697) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:18:32 UTC (rev 3698) @@ -29,6 +29,17 @@ * $Id$ * * Ban ("purge") processing + * + * A ban consists of a number of conditions (or tests), all of which must be + * satisfied. Here are some potential bans we could support: + * + * req.url == "/foo" + * req.url ~ ".iso" && obj.size > 10MB + * req.http.host ~ "web1.com" && obj.set-cookie ~ "USER=29293" + * + * We make the "&&" mandatory from the start, leaving the syntax space + * for latter handling of "||" as well. + * */ #include "config.h" @@ -43,7 +54,23 @@ #include "cli.h" #include "cli_priv.h" #include "cache.h" +#include "hash_slinger.h" +struct ban_test; + +/* A ban-testing function */ +typedef int ban_cond_f(const struct ban_test *bt, const struct object *o, const struct sess *sp); + +/* Each individual test to be performed on a ban */ +struct ban_test { + unsigned magic; +#define BAN_TEST_MAGIC 0x54feec67 + VTAILQ_ENTRY(ban_test) list; + int cost; + ban_cond_f *func; + regex_t re; +}; + struct ban { unsigned magic; #define BAN_MAGIC 0x700b08ea @@ -51,14 +78,104 @@ unsigned refcount; int flags; #define BAN_F_GONE (1 << 0) - regex_t regexp; char *ban; int hash; + VTAILQ_HEAD(,ban_test) tests; }; static VTAILQ_HEAD(banhead,ban) ban_head = VTAILQ_HEAD_INITIALIZER(ban_head); static struct lock ban_mtx; +/*-------------------------------------------------------------------- + * Manipulation of bans + */ + +static struct ban * +ban_new_ban(void) +{ + struct ban *b; + ALLOC_OBJ(b, BAN_MAGIC); + if (b == NULL) + return (b); + VTAILQ_INIT(&b->tests); + return (b); +} + +static struct ban_test * +ban_add_test(struct ban *b) +{ + struct ban_test *bt; + + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + ALLOC_OBJ(bt, BAN_TEST_MAGIC); + if (bt == NULL) + return (bt); + VTAILQ_INSERT_TAIL(&b->tests, bt, list); + return (bt); +} + +static void +ban_sort_by_cost(struct ban *b) +{ + struct ban_test *bt, *btn; + int i; + + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + + do { + i = 0; + VTAILQ_FOREACH(bt, &b->tests, list) { + btn = VTAILQ_NEXT(bt, list); + if (btn != NULL && btn->cost < bt->cost) { + VTAILQ_REMOVE(&b->tests, bt, list); + VTAILQ_INSERT_AFTER(&b->tests, btn, bt, list); + i++; + } + } + } while (i); +} + +static void +ban_free_ban(struct ban *b) +{ + struct ban_test *bt; + + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + while (!VTAILQ_EMPTY(&b->tests)) { + bt = VTAILQ_FIRST(&b->tests); + VTAILQ_REMOVE(&b->tests, bt, list); + FREE_OBJ(bt); + } + FREE_OBJ(b); +} + +/*-------------------------------------------------------------------- + * Test functions -- return 0 if the test does not match + */ + +static int +ban_cond_url_regexp(const struct ban_test *bt, const struct object *o, + const struct sess *sp) +{ + (void)o; + return (!regexec(&bt->re, sp->http->hd[HTTP_HDR_URL].b, 0, NULL, 0)); +} + +static int +ban_cond_hash_regexp(const struct ban_test *bt, const struct object *o, + const struct sess *sp) +{ + (void)sp; + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + CHECK_OBJ_NOTNULL(o->objhead, OBJHEAD_MAGIC); + AN(o->objhead->hash); + return (!regexec(&bt->re, o->objhead->hash, 0, NULL, 0)); +} + +/*-------------------------------------------------------------------- + */ + + /* * We maintain ban_start as a pointer to the first element of the list * as a separate variable from the VTAILQ, to avoid depending on the @@ -71,25 +188,41 @@ BAN_Add(struct cli *cli, const char *regexp, int hash) { struct ban *b, *bi, *be; + struct ban_test *bt; char buf[512]; unsigned pcount; int i; - ALLOC_OBJ(b, BAN_MAGIC); + b = ban_new_ban(); if (b == NULL) { cli_out(cli, "Out of Memory"); cli_result(cli, CLIS_CANT); return (-1); } - i = regcomp(&b->regexp, regexp, REG_EXTENDED | REG_ICASE | REG_NOSUB); + bt = ban_add_test(b); + if (bt == NULL) { + cli_out(cli, "Out of Memory"); + cli_result(cli, CLIS_CANT); + ban_free_ban(b); + return (-1); + } + + ban_sort_by_cost(b); + + if (hash) + bt->func = ban_cond_hash_regexp; + else + bt->func = ban_cond_url_regexp; + + i = regcomp(&bt->re, regexp, REG_EXTENDED | REG_ICASE | REG_NOSUB); if (i) { - (void)regerror(i, &b->regexp, buf, sizeof buf); - regfree(&b->regexp); + (void)regerror(i, &bt->re, buf, sizeof buf); + regfree(&bt->re); VSL(SLT_Debug, 0, "REGEX: <%s>", buf); cli_out(cli, "%s", buf); cli_result(cli, CLIS_PARAM); - FREE_OBJ(b); + ban_free_ban(b); return (-1); } b->hash = hash; @@ -169,21 +302,20 @@ b = NULL; } Lck_Unlock(&ban_mtx); - if (b != NULL) { - free(b->ban); - regfree(&b->regexp); - FREE_OBJ(b); - } + if (b != NULL) + ban_free_ban(b); } int -BAN_CheckObject(struct object *o, const char *url, const char *hash) +BAN_CheckObject(struct object *o, const struct sess *sp) { struct ban *b; + struct ban_test *bt; struct ban * volatile b0; unsigned tests; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o->ban, BAN_MAGIC); @@ -199,9 +331,14 @@ */ tests = 0; for (b = b0; b != o->ban; b = VTAILQ_NEXT(b, list)) { - tests++; - if (!(b->flags & BAN_F_GONE) && - !regexec(&b->regexp, b->hash ? hash : url, 0, NULL, 0)) + if (b->flags & BAN_F_GONE) + continue; + VTAILQ_FOREACH(bt, &b->tests, list) { + tests++; + if (bt->func(bt, o, sp)) + break; + } + if (bt != NULL) break; } @@ -226,7 +363,18 @@ * CLI functions to add bans */ +#if 0 static void +ccf_purge(struct cli *cli, const char * const *av, void *priv) +{ + + (void)priv; + (void)av; + (void)cli; +} +#endif + +static void ccf_purge_url(struct cli *cli, const char * const *av, void *priv) { @@ -277,6 +425,9 @@ { CLI_PURGE_URL, ccf_purge_url }, { CLI_PURGE_HASH, ccf_purge_hash }, +#if 0 + { CLI_PURGE, ccf_purge }, +#endif { CLI_PURGE_LIST, ccf_purge_list }, { NULL } }; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 12:13:38 UTC (rev 3697) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 12:18:32 UTC (rev 3698) @@ -255,7 +255,7 @@ continue; if (o->ttl == 0) continue; - if (BAN_CheckObject(o, h->hd[HTTP_HDR_URL].b, oh->hash)) { + if (BAN_CheckObject(o, sp)) { o->ttl = 0; WSP(sp, SLT_ExpBan, "%u was banned", o->xid); EXP_Rearm(o); From tfheen at projects.linpro.no Mon Feb 9 12:24:18 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:24:18 +0100 (CET) Subject: r3699 - in branches/2.0/varnish-cache: bin/varnishd include Message-ID: <20090209122418.4304E28440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:24:17 +0100 (Mon, 09 Feb 2009) New Revision: 3699 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/include/cli.h Log: Merge r3509+r3510: Commit the old purge facilities to the new world order. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:18:32 UTC (rev 3698) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:24:17 UTC (rev 3699) @@ -46,6 +46,7 @@ #include +#include #include #include #include @@ -67,6 +68,7 @@ #define BAN_TEST_MAGIC 0x54feec67 VTAILQ_ENTRY(ban_test) list; int cost; + char *test; ban_cond_f *func; regex_t re; }; @@ -78,8 +80,6 @@ unsigned refcount; int flags; #define BAN_F_GONE (1 << 0) - char *ban; - int hash; VTAILQ_HEAD(,ban_test) tests; }; @@ -144,11 +144,45 @@ while (!VTAILQ_EMPTY(&b->tests)) { bt = VTAILQ_FIRST(&b->tests); VTAILQ_REMOVE(&b->tests, bt, list); + free(bt->test); + regfree(&bt->re); FREE_OBJ(bt); } FREE_OBJ(b); } +/* + * Return zero of the two bans have the same components + * + * XXX: Looks too expensive for my taste. + */ + +static int +ban_compare(const struct ban *b1, const struct ban *b2) +{ + struct ban_test *bt1, *bt2; + int n, m; + + CHECK_OBJ_NOTNULL(b1, BAN_MAGIC); + CHECK_OBJ_NOTNULL(b2, BAN_MAGIC); + + n = 0; + VTAILQ_FOREACH(bt1, &b1->tests, list) { + n++; + VTAILQ_FOREACH(bt2, &b2->tests, list) + if (!strcmp(bt1->test, bt2->test)) + break; + if (bt2 == NULL) + return (1); + } + m = 0; + VTAILQ_FOREACH(bt2, &b2->tests, list) + m++; + if (m != n) + return (1); + return (0); +} + /*-------------------------------------------------------------------- * Test functions -- return 0 if the test does not match */ @@ -173,61 +207,78 @@ } /*-------------------------------------------------------------------- + * Parse and add a ban test specification */ - -/* - * We maintain ban_start as a pointer to the first element of the list - * as a separate variable from the VTAILQ, to avoid depending on the - * internals of the VTAILQ macros. We tacitly assume that a pointer - * write is always atomic in doing so. - */ -static struct ban * volatile ban_start; - -int -BAN_Add(struct cli *cli, const char *regexp, int hash) +static int +ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) { - struct ban *b, *bi, *be; struct ban_test *bt; char buf[512]; - unsigned pcount; int i; - b = ban_new_ban(); - if (b == NULL) { + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + bt = ban_add_test(b); + if (bt == NULL) { cli_out(cli, "Out of Memory"); cli_result(cli, CLIS_CANT); return (-1); } - bt = ban_add_test(b); - if (bt == NULL) { - cli_out(cli, "Out of Memory"); - cli_result(cli, CLIS_CANT); - ban_free_ban(b); + if (strcmp(a2, "~")) { + /* XXX: Add more conditionals */ + cli_out(cli, "expected \"~\" got \"%s\"", a2); + cli_result(cli, CLIS_PARAM); return (-1); } - ban_sort_by_cost(b); - - if (hash) - bt->func = ban_cond_hash_regexp; - else - bt->func = ban_cond_url_regexp; - - i = regcomp(&bt->re, regexp, REG_EXTENDED | REG_ICASE | REG_NOSUB); + i = regcomp(&bt->re, a3, REG_EXTENDED | REG_ICASE | REG_NOSUB); if (i) { (void)regerror(i, &bt->re, buf, sizeof buf); regfree(&bt->re); VSL(SLT_Debug, 0, "REGEX: <%s>", buf); cli_out(cli, "%s", buf); cli_result(cli, CLIS_PARAM); - ban_free_ban(b); return (-1); } - b->hash = hash; - b->ban = strdup(regexp); - AN(b->ban); + + if (!strcmp(a1, "req.url")) + bt->func = ban_cond_url_regexp; + else if (!strcmp(a1, "obj.hash")) + bt->func = ban_cond_hash_regexp; + else { + cli_out(cli, "unknown or unsupported field \"%s\"", a1); + cli_result(cli, CLIS_PARAM); + return (-1); + } + + /* XXX: proper quoting */ + asprintf(&bt->test, "%s %s \"%s\"", a1, a2, a3); + + return (0); +} + +/*-------------------------------------------------------------------- + */ + + +/* + * We maintain ban_start as a pointer to the first element of the list + * as a separate variable from the VTAILQ, to avoid depending on the + * internals of the VTAILQ macros. We tacitly assume that a pointer + * write is always atomic in doing so. + */ +static struct ban * volatile ban_start; + +static void +BAN_Insert(struct ban *b) +{ + struct ban *bi, *be; + unsigned pcount; + + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + ban_sort_by_cost(b); + Lck_Lock(&ban_mtx); VTAILQ_INSERT_HEAD(&ban_head, b, list); ban_start = b; @@ -242,7 +293,7 @@ Lck_Unlock(&ban_mtx); if (be == NULL) - return (0); + return; /* Hunt down duplicates, and mark them as gone */ bi = b; @@ -251,10 +302,8 @@ bi = VTAILQ_NEXT(bi, list); if (bi->flags & BAN_F_GONE) continue; - if (b->hash != bi->hash) + if (ban_compare(b, bi)) continue; - if (strcmp(b->ban, bi->ban)) - continue; bi->flags |= BAN_F_GONE; pcount++; } @@ -263,8 +312,6 @@ /* XXX: We should check if the tail can be removed */ VSL_stats->n_purge_dups += pcount; Lck_Unlock(&ban_mtx); - - return (0); } void @@ -363,37 +410,97 @@ * CLI functions to add bans */ -#if 0 static void ccf_purge(struct cli *cli, const char * const *av, void *priv) { + int narg, i; + struct ban *b; (void)priv; - (void)av; - (void)cli; + + /* First do some cheap checks on the arguments */ + for (narg = 0; av[narg + 2] != NULL; narg++) + continue; + if ((narg % 4) != 3) { + cli_out(cli, "Wrong number of arguments"); + cli_result(cli, CLIS_PARAM); + return; + } + for (i = 3; i < narg; i += 4) { + if (strcmp(av[i + 2], "&&")) { + cli_out(cli, "Found \"%s\" expected &&", av[i + 2]); + cli_result(cli, CLIS_PARAM); + return; + } + } + + b = ban_new_ban(); + if (b == NULL) { + cli_out(cli, "Out of Memory"); + cli_result(cli, CLIS_CANT); + return; + } + for (i = 0; i < narg; i += 4) + if (ban_parse_test(cli, b, av[i + 2], av[i + 3], av[i + 4])) { + ban_free_ban(b); + return; + } + BAN_Insert(b); } -#endif +int +BAN_Add(struct cli *cli, const char *regexp, int hash) +{ + const char *aav[6]; + + aav[0] = NULL; + aav[1] = "purge"; + if (hash) + aav[2] = "obj.hash"; + else + aav[2] = "req.url"; + aav[3] = "~"; + aav[4] = regexp; + aav[5] = NULL; + ccf_purge(cli, aav, NULL); + return (0); +} + static void ccf_purge_url(struct cli *cli, const char * const *av, void *priv) { + const char *aav[6]; (void)priv; - (void)BAN_Add(cli, av[2], 0); + aav[0] = NULL; + aav[1] = "purge"; + aav[2] = "req.url"; + aav[3] = "~"; + aav[4] = av[2]; + aav[5] = NULL; + ccf_purge(cli, aav, priv); } static void ccf_purge_hash(struct cli *cli, const char * const *av, void *priv) { + const char *aav[6]; (void)priv; - (void)BAN_Add(cli, av[2], 1); + aav[0] = NULL; + aav[1] = "purge"; + aav[2] = "obj.hash"; + aav[3] = "~"; + aav[4] = av[2]; + aav[5] = NULL; + ccf_purge(cli, aav, priv); } static void ccf_purge_list(struct cli *cli, const char * const *av, void *priv) { struct ban *b0; + struct ban_test *bt; (void)av; (void)priv; @@ -408,10 +515,10 @@ for (b0 = ban_start; b0 != NULL; b0 = VTAILQ_NEXT(b0, list)) { if (b0->refcount == 0 && VTAILQ_NEXT(b0, list) == NULL) break; - cli_out(cli, "%5u %d %s \"%s\"\n", - b0->refcount, b0->flags, - b0->hash ? "hash" : "url ", - b0->ban); + VTAILQ_FOREACH(bt, &b0->tests, list) + cli_out(cli, "%5u %d \"%s\"\n", + b0->refcount, b0->flags, + bt->test); } } @@ -425,9 +532,7 @@ { CLI_PURGE_URL, ccf_purge_url }, { CLI_PURGE_HASH, ccf_purge_hash }, -#if 0 { CLI_PURGE, ccf_purge }, -#endif { CLI_PURGE_LIST, ccf_purge_list }, { NULL } }; Modified: branches/2.0/varnish-cache/include/cli.h =================================================================== --- branches/2.0/varnish-cache/include/cli.h 2009-02-09 12:18:32 UTC (rev 3698) +++ branches/2.0/varnish-cache/include/cli.h 2009-02-09 12:24:17 UTC (rev 3699) @@ -74,6 +74,13 @@ "marked obsolete.", \ 1, 1 +#define CLI_PURGE \ + "purge", \ + "purge [&& ]...", \ + "\tAll objects where the all the conditions match will be " \ + "marked obsolete.", \ + 3, UINT_MAX + #define CLI_PURGE_LIST \ "purge.list", \ "purge.list", \ From tfheen at projects.linpro.no Mon Feb 9 12:28:16 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:28:16 +0100 (CET) Subject: r3700 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090209122816.9D80128440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:28:16 +0100 (Mon, 09 Feb 2009) New Revision: 3700 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc Log: Merge r3511: Add testcase for cli:purge Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc (from rev 3511, trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-02-09 12:28:16 UTC (rev 3700) @@ -0,0 +1,41 @@ +# $Id: c00006.vtc 2906 2008-07-08 10:29:07Z phk $ + +test "Test banning a url with cli:purge" + +server s1 { + rxreq + expect req.url == "/foo" + txresp -body "1111\n" + rxreq + expect req.url == "/foo" + txresp -body "11111\n" +} -start + +varnish v1 -vcl+backend { } -start + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.content-length == 5 +} + +client c1 -run + +varnish v1 -clierr 104 "purge" +varnish v1 -clierr 104 "purge foo" +varnish v1 -clierr 104 "purge foo bar" +varnish v1 -clierr 106 "purge a b c && a" +varnish v1 -clierr 106 "purge a b c && a b" +varnish v1 -clierr 106 "purge a b c || a b c" +varnish v1 -cli "purge req.url ~ foo" +# varnish v1 -cli "purge req.url ~ foo && req.url ~ bar" + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.content-length == 6 +} + +client c1 -run From tfheen at projects.linpro.no Mon Feb 9 12:32:54 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:32:54 +0100 (CET) Subject: r3701 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209123254.7CED41F74CA@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:32:54 +0100 (Mon, 09 Feb 2009) New Revision: 3701 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c branches/2.0/varnish-cache/bin/varnishd/cache_response.c branches/2.0/varnish-cache/bin/varnishd/cache_session.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Merge r3512: Originally we shaved 64 bytes from the session to the worker thread by keeping the current requests accounting stats in the worker thread. For reasons which will be explained in the next commit, this is no longer a good idea, and this commit moves these counters from the worker thread to the session at a slight but all in all trivial cost in memory footprint. Remove the call to SES_Charge() when we hit a busy object, it is not necessary to clean the worker thread counters here now. Move these counters from the worker thread to the see Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-09 12:28:16 UTC (rev 3700) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-09 12:32:54 UTC (rev 3701) @@ -199,7 +199,6 @@ struct VCL_conf *vcl; struct srcaddr *srcaddr; - struct acct acct; unsigned char *wlb, *wlp, *wle; unsigned wlr; @@ -370,6 +369,7 @@ struct workreq workreq; struct acct acct; + struct acct acct_req; /* pointers to hash string components */ unsigned nhashptr; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-09 12:28:16 UTC (rev 3700) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-09 12:32:54 UTC (rev 3701) @@ -427,7 +427,7 @@ EXP_Insert(sp->obj); HSH_Unbusy(sp); } - sp->wrk->acct.fetch++; + sp->acct_req.fetch++; sp->step = STP_DELIVER; return (0); } @@ -457,7 +457,7 @@ /* Receive a HTTP protocol request */ HTC_Init(sp->htc, sp->ws, sp->fd); sp->wrk->lastused = sp->t_open; - sp->wrk->acct.sess++; + sp->acct_req.sess++; SES_RefSrcAddr(sp); do i = HTC_Rx(sp->htc); @@ -591,7 +591,6 @@ if (params->diag_bitmap & 0x20) WSP(sp, SLT_Debug, "on waiting list <%s>", sp->objhead->hash); - SES_Charge(sp); return (1); } @@ -721,7 +720,7 @@ return (0); } assert(sp->handling == VCL_RET_PASS); - sp->wrk->acct.pass++; + sp->acct_req.pass++; HSH_Prealloc(sp); sp->obj = sp->wrk->nobj; sp->wrk->nobj = NULL; @@ -763,7 +762,7 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); - sp->wrk->acct.pipe++; + sp->acct_req.pipe++; http_FilterHeader(sp, HTTPH_R_PIPE); VCL_pipe_method(sp); @@ -871,7 +870,7 @@ VSL_stats->client_req++; /* XXX not locked */ sp->t_req = TIM_real(); sp->wrk->lastused = sp->t_req; - sp->wrk->acct.req++; + sp->acct_req.req++; /* Assign XID and log */ sp->xid = ++xids; /* XXX not locked */ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c 2009-02-09 12:28:16 UTC (rev 3700) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c 2009-02-09 12:32:54 UTC (rev 3701) @@ -84,10 +84,10 @@ TCP_blocking(vc->fd); WRW_Reserve(w, &vc->fd); - w->acct.hdrbytes += http_Write(w, bereq->http, 0); + sp->acct_req.hdrbytes += http_Write(w, bereq->http, 0); if (sp->htc->pipeline.b != NULL) - w->acct.bodybytes += + sp->acct_req.bodybytes += WRW_Write(w, sp->htc->pipeline.b, Tlen(sp->htc->pipeline)); if (WRW_FlushRelease(w)) { Modified: branches/2.0/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_response.c 2009-02-09 12:28:16 UTC (rev 3700) +++ branches/2.0/varnish-cache/bin/varnishd/cache_response.c 2009-02-09 12:32:54 UTC (rev 3701) @@ -140,7 +140,7 @@ WRW_Reserve(sp->wrk, &sp->fd); if (sp->esis == 0) - sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); + sp->acct_req.hdrbytes += http_Write(sp->wrk, sp->http, 1); if (sp->wantbody && !VTAILQ_EMPTY(&sp->obj->esibits)) { if (WRW_FlushRelease(sp->wrk)) { @@ -161,7 +161,7 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); u += st->len; - sp->wrk->acct.bodybytes += st->len; + sp->acct_req.bodybytes += st->len; #ifdef SENDFILE_WORKS /* * XXX: the overhead of setting up sendfile is not Modified: branches/2.0/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_session.c 2009-02-09 12:28:16 UTC (rev 3700) +++ branches/2.0/varnish-cache/bin/varnishd/cache_session.c 2009-02-09 12:32:54 UTC (rev 3701) @@ -222,7 +222,7 @@ void SES_Charge(struct sess *sp) { - struct acct *a = &sp->wrk->acct; + struct acct *a = &sp->acct_req; struct acct b; ses_sum_acct(&sp->acct, a); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-09 12:28:16 UTC (rev 3700) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-09 12:32:54 UTC (rev 3701) @@ -808,7 +808,7 @@ if (Tlen(eb->verbatim)) { if (sp->http->protover >= 1.1) (void)WRW_Write(sp->wrk, eb->chunk_length, -1); - sp->wrk->acct.bodybytes += WRW_Write(sp->wrk, + sp->acct_req.bodybytes += WRW_Write(sp->wrk, eb->verbatim.b, Tlen(eb->verbatim)); if (sp->http->protover >= 1.1) (void)WRW_Write(sp->wrk, "\r\n", -1); From tfheen at projects.linpro.no Mon Feb 9 12:36:03 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:36:03 +0100 (CET) Subject: r3702 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209123603.E8B7728440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:36:03 +0100 (Mon, 09 Feb 2009) New Revision: 3702 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c Log: Merge r3513: After HSH_Lookup() returns NULL indicating a busy object, we diddled the session a bit to transfer the per-request stats to the session counters with SES_Charge(). Not only was it inconsistent to charge accounting data in the middle of a request, it was also illegal because after the hash lock was released we no longer owned the session. Once a system is under sufficient load that there is a queue for the CPU, a race could happen where upon hitting a busy object, the hash lock was released, another thread would schedule, finish the busy object, start the sessions on the waiting list, finish off the request we had and then when we get the cpu again and access it, it's gone. The previous commit (r3512) eliminated the need to call SES_Charge, this commit removes the (option) shmlog message inside the hash lock thus, hopefully, eliminating the race that caused #418. Fixes: #418 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-09 12:32:54 UTC (rev 3701) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-09 12:36:03 UTC (rev 3702) @@ -584,13 +584,10 @@ if (o == NULL) { /* - * We hit a busy object, disembark worker thread and expect - * hash code to restart us, still in STP_LOOKUP, later. + * We lost the session to a busy object, disembark the + * worker thread. The hash code to restart the session, + * still in STP_LOOKUP, later when the busy object isn't. */ - assert(sp->objhead != NULL); - if (params->diag_bitmap & 0x20) - WSP(sp, SLT_Debug, - "on waiting list <%s>", sp->objhead->hash); return (1); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 12:32:54 UTC (rev 3701) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 12:36:03 UTC (rev 3702) @@ -298,6 +298,9 @@ /* There are one or more busy objects, wait for them */ if (sp->esis == 0) VTAILQ_INSERT_TAIL(&oh->waitinglist, sp, list); + if (params->diag_bitmap & 0x20) + WSP(sp, SLT_Debug, + "on waiting list <%s>", oh->hash); sp->objhead = oh; Lck_Unlock(&oh->mtx); return (NULL); From tfheen at projects.linpro.no Mon Feb 9 12:39:32 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:39:32 +0100 (CET) Subject: r3703 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209123932.2631A28440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:39:31 +0100 (Mon, 09 Feb 2009) New Revision: 3703 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c Log: Merge r3514: redo the purge.list function with proper locking Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:36:03 UTC (rev 3702) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:39:31 UTC (rev 3703) @@ -499,27 +499,30 @@ static void ccf_purge_list(struct cli *cli, const char * const *av, void *priv) { - struct ban *b0; + struct ban *b; struct ban_test *bt; (void)av; (void)priv; - /* - * XXX: Strictly speaking, this loop traversal is not lock-safe - * XXX: because we might inspect the last ban while it gets - * XXX: destroyed. To properly fix this, we would need to either - * XXX: hold the lock over the entire loop, or grab refcounts - * XXX: under lock for each element of the list. - * XXX: We do neither, and hope for the best. - */ - for (b0 = ban_start; b0 != NULL; b0 = VTAILQ_NEXT(b0, list)) { - if (b0->refcount == 0 && VTAILQ_NEXT(b0, list) == NULL) - break; - VTAILQ_FOREACH(bt, &b0->tests, list) - cli_out(cli, "%5u %d \"%s\"\n", - b0->refcount, b0->flags, - bt->test); + + Lck_Lock(&ban_mtx); + VTAILQ_LAST(&ban_head, banhead)->refcount++; + Lck_Unlock(&ban_mtx); + + VTAILQ_FOREACH(b, &ban_head, list) { + bt = VTAILQ_FIRST(&b->tests); + cli_out(cli, "%5u %4s\t%s\n", + b->refcount, b->flags ? "Gone" : "", bt->test); + do { + bt = VTAILQ_NEXT(bt, list); + if (bt != NULL) + cli_out(cli, "\t\t%s\n", bt->test); + } while (bt != NULL); } + + Lck_Lock(&ban_mtx); + VTAILQ_LAST(&ban_head, banhead)->refcount--; + Lck_Unlock(&ban_mtx); } static struct cli_proto ban_cmds[] = { From tfheen at projects.linpro.no Mon Feb 9 12:43:02 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:43:02 +0100 (CET) Subject: r3704 - in branches/2.0/varnish-cache: include lib/libvarnish Message-ID: <20090209124302.772EA28440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:43:02 +0100 (Mon, 09 Feb 2009) New Revision: 3704 Modified: branches/2.0/varnish-cache/include/vsb.h branches/2.0/varnish-cache/lib/libvarnish/cli_common.c branches/2.0/varnish-cache/lib/libvarnish/vsb.c Log: Merge r3515: Move the body of cli_quote() to vsb_quote() and give it a, presently unused, "how" argument flag. We currently have far too many "quote this string properly" implementations in varnish, hopefully, this will replace most of them. Once this stabilizes, vsb_quote() will be contributed back to FreeBSD. Modified: branches/2.0/varnish-cache/include/vsb.h =================================================================== --- branches/2.0/varnish-cache/include/vsb.h 2009-02-09 12:39:31 UTC (rev 3703) +++ branches/2.0/varnish-cache/include/vsb.h 2009-02-09 12:43:02 UTC (rev 3704) @@ -77,6 +77,7 @@ int vsb_len(struct vsb *); int vsb_done(const struct vsb *); void vsb_delete(struct vsb *); +void vsb_quote(struct vsb *s, const char *p, int how); #ifdef __cplusplus }; #endif Modified: branches/2.0/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/cli_common.c 2009-02-09 12:39:31 UTC (rev 3703) +++ branches/2.0/varnish-cache/lib/libvarnish/cli_common.c 2009-02-09 12:43:02 UTC (rev 3704) @@ -72,48 +72,8 @@ 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, '"'); + vsb_quote(cli->sb, s, 0); } void Modified: branches/2.0/varnish-cache/lib/libvarnish/vsb.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vsb.c 2009-02-09 12:39:31 UTC (rev 3703) +++ branches/2.0/varnish-cache/lib/libvarnish/vsb.c 2009-02-09 12:43:02 UTC (rev 3704) @@ -476,3 +476,55 @@ return(VSB_ISFINISHED(s)); } + +/* + * Quote a string + */ +void +vsb_quote(struct vsb *s, const char *p, int how) +{ + const char *q; + int quote = 0; + + (void)how; /* For future enhancements */ + + for (q = p; *q != '\0'; q++) { + if (!isgraph(*q) || *q == '"') { + quote++; + break; + } + } + if (!quote) { + (void)vsb_cat(s, p); + return; + } + (void)vsb_putc(s, '"'); + for (q = p; *q != '\0'; q++) { + switch (*q) { + case ' ': + (void)vsb_putc(s, *q); + break; + case '\\': + case '"': + (void)vsb_putc(s, '\\'); + (void)vsb_putc(s, *q); + break; + case '\n': + (void)vsb_cat(s, "\\n"); + break; + case '\r': + (void)vsb_cat(s, "\\r"); + break; + case '\t': + (void)vsb_cat(s, "\\t"); + break; + default: + if (isgraph(*q)) + (void)vsb_putc(s, *q); + else + (void)vsb_printf(s, "\\%o", *q); + break; + } + } + (void)vsb_putc(s, '"'); +} From tfheen at projects.linpro.no Mon Feb 9 12:46:48 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:46:48 +0100 (CET) Subject: r3705 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090209124648.8744228440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:46:48 +0100 (Mon, 09 Feb 2009) New Revision: 3705 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc Log: Merge r3516: Properly quote the ban descriptions. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:43:02 UTC (rev 3704) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:46:48 UTC (rev 3705) @@ -215,6 +215,7 @@ { struct ban_test *bt; char buf[512]; + struct vsb *sb; int i; CHECK_OBJ_NOTNULL(b, BAN_MAGIC); @@ -253,8 +254,15 @@ } /* XXX: proper quoting */ - asprintf(&bt->test, "%s %s \"%s\"", a1, a2, a3); - + sb = vsb_newauto(); + XXXAN(sb); + vsb_printf(sb, "%s %s ", a1, a2); + vsb_quote(sb, a3, 0); + vsb_finish(sb); + AZ(vsb_overflowed(sb)); + bt->test = strdup(vsb_data(sb)); + XXXAN(bt->test); + vsb_delete(sb); return (0); } Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-02-09 12:43:02 UTC (rev 3704) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-02-09 12:46:48 UTC (rev 3705) @@ -28,8 +28,8 @@ varnish v1 -clierr 106 "purge a b c && a" varnish v1 -clierr 106 "purge a b c && a b" varnish v1 -clierr 106 "purge a b c || a b c" -varnish v1 -cli "purge req.url ~ foo" -# varnish v1 -cli "purge req.url ~ foo && req.url ~ bar" +varnish v1 -cliok "purge req.url ~ foo && req.url ~ \"[ o]\"" +varnish v1 -cliok "purge.list" client c1 { txreq -url "/foo" From tfheen at projects.linpro.no Mon Feb 9 12:50:43 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:50:43 +0100 (CET) Subject: r3706 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209125043.4543E28440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:50:42 +0100 (Mon, 09 Feb 2009) New Revision: 3706 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c Log: Merge r3517: Don't list gone bans. Emit && \ for line continuation. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:46:48 UTC (rev 3705) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:50:42 UTC (rev 3706) @@ -518,14 +518,16 @@ Lck_Unlock(&ban_mtx); VTAILQ_FOREACH(b, &ban_head, list) { + if (b->flags & BAN_F_GONE) + continue; bt = VTAILQ_FIRST(&b->tests); - cli_out(cli, "%5u %4s\t%s\n", - b->refcount, b->flags ? "Gone" : "", bt->test); + cli_out(cli, "%5u\t%s", b->refcount, bt->test); do { bt = VTAILQ_NEXT(bt, list); if (bt != NULL) - cli_out(cli, "\t\t%s\n", bt->test); + cli_out(cli, " && \\\n\t%s", bt->test); } while (bt != NULL); + cli_out(cli, "\n"); } Lck_Lock(&ban_mtx); From tfheen at projects.linpro.no Mon Feb 9 12:55:03 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:55:03 +0100 (CET) Subject: r3707 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090209125503.EF54E28440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:55:03 +0100 (Mon, 09 Feb 2009) New Revision: 3707 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc Log: Merge r3518: Implement exact matching and negatives for bans. You can now purge using these four conditionals: purge req.url == "/diediedie.html" purge req.url != "/index.html" purge req.url !~ "\.html$" purge req.url ~ "\.jpg$" Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:50:42 UTC (rev 3706) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:55:03 UTC (rev 3707) @@ -70,7 +70,11 @@ int cost; char *test; ban_cond_f *func; + int flags; +#define BAN_T_REGEXP (1 << 0) +#define BAN_T_NOT (1 << 1) regex_t re; + char *dst; }; struct ban { @@ -145,7 +149,10 @@ bt = VTAILQ_FIRST(&b->tests); VTAILQ_REMOVE(&b->tests, bt, list); free(bt->test); - regfree(&bt->re); + if (bt->flags & BAN_T_REGEXP) + regfree(&bt->re); + if (bt->dst != NULL) + free(bt->dst); FREE_OBJ(bt); } FREE_OBJ(b); @@ -188,22 +195,38 @@ */ static int -ban_cond_url_regexp(const struct ban_test *bt, const struct object *o, +ban_cond_str(const struct ban_test *bt, const char *p) +{ + int i; + + if (bt->flags & BAN_T_REGEXP) + i = regexec(&bt->re, p, 0, NULL, 0); + else + i = strcmp(bt->dst, p); + if (bt->flags & BAN_T_NOT) + return (i); + return (!i); +} + +static int +ban_cond_url(const struct ban_test *bt, const struct object *o, const struct sess *sp) { (void)o; - return (!regexec(&bt->re, sp->http->hd[HTTP_HDR_URL].b, 0, NULL, 0)); + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + return(ban_cond_str(bt, sp->http->hd[HTTP_HDR_URL].b)); } static int -ban_cond_hash_regexp(const struct ban_test *bt, const struct object *o, +ban_cond_hash(const struct ban_test *bt, const struct object *o, const struct sess *sp) { (void)sp; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o->objhead, OBJHEAD_MAGIC); AN(o->objhead->hash); - return (!regexec(&bt->re, o->objhead->hash, 0, NULL, 0)); + return(ban_cond_str(bt, o->objhead->hash)); } /*-------------------------------------------------------------------- @@ -211,10 +234,28 @@ */ static int +ban_parse_regexp(struct cli *cli, struct ban_test *bt, const char *a3) +{ + int i; + char buf[512]; + + i = regcomp(&bt->re, a3, REG_EXTENDED | REG_ICASE | REG_NOSUB); + if (i) { + (void)regerror(i, &bt->re, buf, sizeof buf); + regfree(&bt->re); + VSL(SLT_Debug, 0, "REGEX: <%s>", buf); + cli_out(cli, "%s", buf); + cli_result(cli, CLIS_PARAM); + return (-1); + } + bt->flags |= BAN_T_REGEXP; + return (0); +} + +static int ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) { struct ban_test *bt; - char buf[512]; struct vsb *sb; int i; @@ -226,27 +267,32 @@ return (-1); } - if (strcmp(a2, "~")) { - /* XXX: Add more conditionals */ - cli_out(cli, "expected \"~\" got \"%s\"", a2); + if (!strcmp(a2, "~")) { + i = ban_parse_regexp(cli, bt, a3); + if (i) + return (i); + } else if (!strcmp(a2, "!~")) { + bt->flags |= BAN_T_NOT; + i = ban_parse_regexp(cli, bt, a3); + if (i) + return (i); + } else if (!strcmp(a2, "==")) { + bt->dst = strdup(a3); + XXXAN(bt->dst); + } else if (!strcmp(a2, "!=")) { + bt->flags |= BAN_T_NOT; + bt->dst = strdup(a3); + XXXAN(bt->dst); + } else { + cli_out(cli, + "expected conditional (~, !~, == or !=) got \"%s\"", a2); cli_result(cli, CLIS_PARAM); return (-1); } - - i = regcomp(&bt->re, a3, REG_EXTENDED | REG_ICASE | REG_NOSUB); - if (i) { - (void)regerror(i, &bt->re, buf, sizeof buf); - regfree(&bt->re); - VSL(SLT_Debug, 0, "REGEX: <%s>", buf); - cli_out(cli, "%s", buf); - cli_result(cli, CLIS_PARAM); - return (-1); - } - if (!strcmp(a1, "req.url")) - bt->func = ban_cond_url_regexp; + bt->func = ban_cond_url; else if (!strcmp(a1, "obj.hash")) - bt->func = ban_cond_hash_regexp; + bt->func = ban_cond_hash; else { cli_out(cli, "unknown or unsupported field \"%s\"", a1); cli_result(cli, CLIS_PARAM); Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-02-09 12:50:42 UTC (rev 3706) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-02-09 12:55:03 UTC (rev 3707) @@ -28,6 +28,14 @@ varnish v1 -clierr 106 "purge a b c && a" varnish v1 -clierr 106 "purge a b c && a b" varnish v1 -clierr 106 "purge a b c || a b c" +varnish v1 -cliok "purge req.url == foo" +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.content-length == 5 +} + varnish v1 -cliok "purge req.url ~ foo && req.url ~ \"[ o]\"" varnish v1 -cliok "purge.list" From tfheen at projects.linpro.no Mon Feb 9 12:58:29 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 13:58:29 +0100 (CET) Subject: r3708 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090209125829.2028F28440@projects.linpro.no> Author: tfheen Date: 2009-02-09 13:58:27 +0100 (Mon, 09 Feb 2009) New Revision: 3708 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc Log: Merge r3519: Add the ability to purge on random request or object headers. For instance: purge req.http.host ~ www.foo.com && req.url ~ "\.png$" purge obj.http.set-cookie ~ USER=383839 Now, why would you want purge on request headers and not object headers ? Simple, some information the object does not have, the Host: header is a good example. Assuming that the Host: header is part of the hash we use to lookup an object (as is the default), we can avoid copying that field into the object (saving memory: O(nObjects)) by using the request value to purge against. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:55:03 UTC (rev 3707) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:58:27 UTC (rev 3708) @@ -75,6 +75,7 @@ #define BAN_T_NOT (1 << 1) regex_t re; char *dst; + char *src; }; struct ban { @@ -191,7 +192,7 @@ } /*-------------------------------------------------------------------- - * Test functions -- return 0 if the test does not match + * Test functions -- return 0 if the test matches */ static int @@ -199,13 +200,15 @@ { int i; + if (p == NULL) + return(!(bt->flags & BAN_T_NOT)); if (bt->flags & BAN_T_REGEXP) i = regexec(&bt->re, p, 0, NULL, 0); else i = strcmp(bt->dst, p); if (bt->flags & BAN_T_NOT) - return (i); - return (!i); + return (!i); + return (i); } static int @@ -229,6 +232,30 @@ return(ban_cond_str(bt, o->objhead->hash)); } +static int +ban_cond_req_http(const struct ban_test *bt, const struct object *o, + const struct sess *sp) +{ + char *s; + + (void)o; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + http_GetHdr(sp->http, bt->src, &s); + return (ban_cond_str(bt, s)); +} + +static int +ban_cond_obj_http(const struct ban_test *bt, const struct object *o, + const struct sess *sp) +{ + char *s; + + (void)sp; + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + http_GetHdr(o->http, bt->src, &s); + return (ban_cond_str(bt, s)); +} + /*-------------------------------------------------------------------- * Parse and add a ban test specification */ @@ -252,6 +279,20 @@ return (0); } +static void +ban_parse_http(struct ban_test *bt, const char *a1) +{ + int l; + + l = strlen(a1); + bt->src = malloc(l + 3); + XXXAN(bt->src); + bt->src[0] = l + 1; + memcpy(bt->src + 1, a1, l); + bt->src[l + 1] = ':'; + bt->src[l + 2] = '\0'; +} + static int ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) { @@ -289,11 +330,19 @@ cli_result(cli, CLIS_PARAM); return (-1); } + + if (!strcmp(a1, "req.url")) bt->func = ban_cond_url; else if (!strcmp(a1, "obj.hash")) bt->func = ban_cond_hash; - else { + else if (!strncmp(a1, "req.http.", 9)) { + bt->func = ban_cond_req_http; + ban_parse_http(bt, a1 + 9); + } else if (!strncmp(a1, "obj.http.", 9)) { + bt->func = ban_cond_obj_http; + ban_parse_http(bt, a1 + 9); + } else { cli_out(cli, "unknown or unsupported field \"%s\"", a1); cli_result(cli, CLIS_PARAM); return (-1); @@ -439,7 +488,7 @@ if (bt->func(bt, o, sp)) break; } - if (bt != NULL) + if (bt == NULL) break; } Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-02-09 12:55:03 UTC (rev 3707) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-02-09 12:58:27 UTC (rev 3708) @@ -5,10 +5,19 @@ server s1 { rxreq expect req.url == "/foo" - txresp -body "1111\n" + txresp -hdr "foo: bar5" -body "1111\n" + rxreq expect req.url == "/foo" - txresp -body "11111\n" + txresp -hdr "foo: bar6" -body "11111\n" + + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar7" -body "111111\n" + + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar8" -body "1111111\n" } -start varnish v1 -vcl+backend { } -start @@ -17,33 +26,101 @@ txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 5 -} + expect resp.http.foo == bar5 + expect resp.bodylen == 5 +} -run -client c1 -run - +# syntax checks varnish v1 -clierr 104 "purge" varnish v1 -clierr 104 "purge foo" varnish v1 -clierr 104 "purge foo bar" varnish v1 -clierr 106 "purge a b c && a" varnish v1 -clierr 106 "purge a b c && a b" varnish v1 -clierr 106 "purge a b c || a b c" +varnish v1 -cliok "purge.list" + +# exact match, not matching varnish v1 -cliok "purge req.url == foo" +varnish v1 -cliok "purge.list" + client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 5 -} + expect resp.http.foo == bar5 + expect resp.bodylen == 5 +} -run -varnish v1 -cliok "purge req.url ~ foo && req.url ~ \"[ o]\"" +# exact match, matching +varnish v1 -cliok "purge req.url == /foo" varnish v1 -cliok "purge.list" +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar6 + expect resp.bodylen == 6 +} -run +# regexp nonmatch +varnish v1 -cliok "purge req.url ~ bar" +varnish v1 -cliok "purge.list" + client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 -} + expect resp.http.foo == bar6 + expect resp.bodylen == 6 +} -run -client c1 -run + +# regexp match +varnish v1 -cliok "purge req.url ~ foo" +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar7 + expect resp.bodylen == 7 +} -run + +# header check, nonmatch +varnish v1 -cliok "purge obj.http.foo != bar7" +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar7 + expect resp.bodylen == 7 +} -run + +# header check, match +varnish v1 -cliok "purge req.http.foo == barcheck" +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" -hdr "foo: barcheck" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar8 + expect resp.bodylen == 8 +} -run + +# header check, no header +varnish v1 -cliok "purge obj.http.bar == barcheck" +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar8 + expect resp.bodylen == 8 +} -run + + From tfheen at projects.linpro.no Mon Feb 9 13:10:35 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 14:10:35 +0100 (CET) Subject: r3709 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090209131035.377EE97C5A@projects.linpro.no> Author: tfheen Date: 2009-02-09 14:10:34 +0100 (Mon, 09 Feb 2009) New Revision: 3709 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc Log: Merge r3520+r3521: Set cost 10 on regexp tests. Let purge.list prune the tail of the list before dumping. Add a protective object to prevent purge.list from pruning our purges before we test their numbers. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 12:58:27 UTC (rev 3708) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 13:10:34 UTC (rev 3709) @@ -154,6 +154,8 @@ regfree(&bt->re); if (bt->dst != NULL) free(bt->dst); + if (bt->src != NULL) + free(bt->src); FREE_OBJ(bt); } FREE_OBJ(b); @@ -276,6 +278,7 @@ return (-1); } bt->flags |= BAN_T_REGEXP; + bt->cost = 10; return (0); } @@ -429,6 +432,23 @@ Lck_Unlock(&ban_mtx); } +static struct ban * +BAN_CheckLast(void) +{ + struct ban *b; + + Lck_AssertHeld(&ban_mtx); + b = VTAILQ_LAST(&ban_head, banhead); + 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 { + b = NULL; + } + return (b); +} + void BAN_DestroyObj(struct object *o) { @@ -442,21 +462,15 @@ o->ban->refcount--; o->ban = NULL; - /* Check if we can purge the last ban entry */ - b = VTAILQ_LAST(&ban_head, banhead); - 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 { - b = NULL; - } + /* Attempt to purge last ban entry */ + b = BAN_CheckLast(); Lck_Unlock(&ban_mtx); if (b != NULL) ban_free_ban(b); } + int BAN_CheckObject(struct object *o, const struct sess *sp) { @@ -608,9 +622,16 @@ (void)av; (void)priv; - Lck_Lock(&ban_mtx); - VTAILQ_LAST(&ban_head, banhead)->refcount++; - Lck_Unlock(&ban_mtx); + do { + /* Attempt to purge last ban entry */ + Lck_Lock(&ban_mtx); + b = BAN_CheckLast(); + if (b == NULL) + VTAILQ_LAST(&ban_head, banhead)->refcount++; + Lck_Unlock(&ban_mtx); + if (b != NULL) + ban_free_ban(b); + } while (b != NULL); VTAILQ_FOREACH(b, &ban_head, list) { if (b->flags & BAN_F_GONE) Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-02-09 12:58:27 UTC (rev 3708) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-02-09 13:10:34 UTC (rev 3709) @@ -4,6 +4,8 @@ server s1 { rxreq + txresp -hdr "foo: 0" -body "foo0" + rxreq txresp -hdr "foo: 1" -body "foo1" rxreq txresp -hdr "foo: 2" -body "foo2" @@ -22,6 +24,9 @@ # Our fetch is not affected by the purge # as the FOO-purge was preexisting client c1 { + txreq -url /BAR + rxresp + expect resp.http.foo == 0 txreq -url /FOO rxresp expect resp.http.foo == 1 @@ -64,7 +69,7 @@ # Enable dup removal of purges varnish v1 -cliok "param.set purge_dups on" -# This should incapacitate the to previous FOO purges. +# This should incapacitate the two previous FOO purges. varnish v1 -cliok "purge.url FOO" varnish v1 -expect n_purge_add == 6 varnish v1 -expect n_purge_dups == 3 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-02-09 12:58:27 UTC (rev 3708) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-02-09 13:10:34 UTC (rev 3709) @@ -112,7 +112,7 @@ } -run # header check, no header -varnish v1 -cliok "purge obj.http.bar == barcheck" +varnish v1 -cliok "purge req.url ~ foo && obj.http.bar == barcheck" varnish v1 -cliok "purge.list" client c1 { From tfheen at projects.linpro.no Mon Feb 9 13:15:50 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 14:15:50 +0100 (CET) Subject: r3710 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209131550.EFF8297C5A@projects.linpro.no> Author: tfheen Date: 2009-02-09 14:15:50 +0100 (Mon, 09 Feb 2009) New Revision: 3710 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c Log: Merge r3522: List referenced, but gone purges, mark them with a "G" Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 13:10:34 UTC (rev 3709) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 13:15:50 UTC (rev 3710) @@ -415,7 +415,6 @@ } Lck_Lock(&ban_mtx); be->refcount--; - /* XXX: We should check if the tail can be removed */ VSL_stats->n_purge_dups += pcount; Lck_Unlock(&ban_mtx); } @@ -634,10 +633,12 @@ } while (b != NULL); VTAILQ_FOREACH(b, &ban_head, list) { - if (b->flags & BAN_F_GONE) + if (b->refcount == 0 && (b->flags & BAN_F_GONE)) continue; bt = VTAILQ_FIRST(&b->tests); - cli_out(cli, "%5u\t%s", b->refcount, bt->test); + cli_out(cli, "%5u%s\t%s", b->refcount, + b->flags & BAN_F_GONE ? "G" : " ", + bt->test); do { bt = VTAILQ_NEXT(bt, list); if (bt != NULL) From tfheen at projects.linpro.no Mon Feb 9 13:18:50 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 14:18:50 +0100 (CET) Subject: r3711 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209131850.9F97F97C5A@projects.linpro.no> Author: tfheen Date: 2009-02-09 14:18:50 +0100 (Mon, 09 Feb 2009) New Revision: 3711 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c Log: Merge r3523: A couple of FlexeLint nits Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 13:15:50 UTC (rev 3710) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 13:18:50 UTC (rev 3711) @@ -242,7 +242,7 @@ (void)o; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - http_GetHdr(sp->http, bt->src, &s); + (void)http_GetHdr(sp->http, bt->src, &s); return (ban_cond_str(bt, s)); } @@ -254,7 +254,7 @@ (void)sp; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - http_GetHdr(o->http, bt->src, &s); + (void)http_GetHdr(o->http, bt->src, &s); return (ban_cond_str(bt, s)); } @@ -288,9 +288,10 @@ int l; l = strlen(a1); + assert(l < 127); bt->src = malloc(l + 3); XXXAN(bt->src); - bt->src[0] = l + 1; + bt->src[0] = (char)l + 1; memcpy(bt->src + 1, a1, l); bt->src[l + 1] = ':'; bt->src[l + 2] = '\0'; From tfheen at projects.linpro.no Mon Feb 9 13:22:00 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 14:22:00 +0100 (CET) Subject: r3712 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209132200.E4D8497C54@projects.linpro.no> Author: tfheen Date: 2009-02-09 14:22:00 +0100 (Mon, 09 Feb 2009) New Revision: 3712 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c Log: Merge r3524: Move the fiddling of banned objects to cache_ban.c Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 13:18:50 UTC (rev 3711) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 13:22:00 UTC (rev 3712) @@ -518,6 +518,9 @@ o->ban = b0; return (0); } else { + o->ttl = 0; + WSP(sp, SLT_ExpBan, "%u was banned", o->xid); + EXP_Rearm(o); o->ban = NULL; return (1); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 13:18:50 UTC (rev 3711) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 13:22:00 UTC (rev 3712) @@ -255,12 +255,8 @@ continue; if (o->ttl == 0) continue; - if (BAN_CheckObject(o, sp)) { - o->ttl = 0; - WSP(sp, SLT_ExpBan, "%u was banned", o->xid); - EXP_Rearm(o); + if (BAN_CheckObject(o, sp)) continue; - } if (o->vary != NULL && !VRY_Match(sp, o->vary)) continue; From tfheen at projects.linpro.no Mon Feb 9 13:25:00 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 9 Feb 2009 14:25:00 +0100 (CET) Subject: r3713 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090209132500.A959497C54@projects.linpro.no> Author: tfheen Date: 2009-02-09 14:25:00 +0100 (Mon, 09 Feb 2009) New Revision: 3713 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.h Log: Merge r3525: Move the vca_pipes to a more proper header file Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-09 13:22:00 UTC (rev 3712) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-09 13:25:00 UTC (rev 3713) @@ -398,7 +398,6 @@ void vca_close_session(struct sess *sp, const char *why); void VCA_Prep(struct sess *sp); void VCA_Init(void); -extern int vca_pipes[2]; /* cache_backend.c */ Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.h 2009-02-09 13:22:00 UTC (rev 3712) +++ branches/2.0/varnish-cache/bin/varnishd/cache_acceptor.h 2009-02-09 13:25:00 UTC (rev 3713) @@ -34,6 +34,8 @@ typedef void acceptor_init_f(void); typedef void acceptor_pass_f(struct sess *); +extern int vca_pipes[2]; + struct acceptor { const char *name; acceptor_init_f *init; From tfheen at projects.linpro.no Tue Feb 10 13:33:28 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 14:33:28 +0100 (CET) Subject: r3714 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090210133328.7E8A728433@projects.linpro.no> Author: tfheen Date: 2009-02-10 14:33:28 +0100 (Tue, 10 Feb 2009) New Revision: 3714 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h branches/2.0/varnish-cache/bin/varnishd/heritage.h branches/2.0/varnish-cache/bin/varnishd/mgt_param.c branches/2.0/varnish-cache/bin/varnishtest/tests/c00007.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc Log: Merge r3526: Add a new paramter "purge_hash" which defaults to "off". Only save the hash-string in the session workspace and objects when this paramter is set to "on". For sites with many small objects, this will save significant VM. When this paramter is set to "off", the "purge.hash" facility will not work, but this should not be a problem, because the new purging facility allow much more expressive purging, the typical case being: purge req.http.host ~ www.foo.com && req.url ~ "article2383" Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 13:25:00 UTC (rev 3713) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-10 13:33:28 UTC (rev 3714) @@ -607,6 +607,14 @@ const char *aav[6]; (void)priv; + if (!save_hash) { + cli_out(cli, + "purge.hash not possible.\n" + "Set the \"purge_hash\" parameter to on\n" + "and restart the varnish worker process to enable.\n"); + cli_result(cli, CLIS_CANT); + return; + } aav[0] = NULL; aav[1] = "purge"; aav[2] = "obj.hash"; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 13:25:00 UTC (rev 3713) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-10 13:33:28 UTC (rev 3714) @@ -69,6 +69,7 @@ #include "vsha256.h" static const struct hash_slinger *hash; +unsigned save_hash; double HSH_Grace(double g) @@ -151,6 +152,8 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); + if (!save_hash) + return; oh->hash = malloc(sp->lhashptr); XXXAN(oh->hash); @@ -172,6 +175,10 @@ char *p; unsigned u; + SHA256_Init(sp->wrk->sha256ctx); + if (!save_hash) + return; + /* Allocate the pointers we need, align properly. */ sp->lhashptr = 1; /* space for NUL */ sp->ihashptr = 0; @@ -184,7 +191,6 @@ if (u) p += sizeof(const char *) - u; sp->hashptr = (void*)p; - SHA256_Init(sp->wrk->sha256ctx); } void @@ -196,6 +202,15 @@ str = ""; l = strlen(str); + SHA256_Update(sp->wrk->sha256ctx, str, l); + SHA256_Update(sp->wrk->sha256ctx, "#", 1); + + if (params->log_hash) + WSP(sp, SLT_Hash, "%s", str); + + if (!save_hash) + return; + /* * XXX: handle this by bouncing sp->vcl->nhashcount when it fails * XXX: and dispose of this request either by reallocating the @@ -207,8 +222,6 @@ sp->hashptr[sp->ihashptr + 1] = str + l; sp->ihashptr += 2; sp->lhashptr += l + 1; - SHA256_Update(sp->wrk->sha256ctx, str, l); - SHA256_Update(sp->wrk->sha256ctx, "#", 1); } struct object * @@ -284,8 +297,6 @@ if (o->hits < INT_MAX) o->hits++; Lck_Unlock(&oh->mtx); - if (params->log_hash) - WSP(sp, SLT_Hash, "%s", oh->hash); (void)hash->deref(oh); return (o); } @@ -315,8 +326,6 @@ grace_o->refcnt++; } Lck_Unlock(&oh->mtx); - if (params->log_hash) - WSP(sp, SLT_Hash, "%s", oh->hash); /* * XXX: This may be too early, relative to pass objects. * XXX: possibly move to when we commit to have it in the cache. @@ -467,6 +476,7 @@ HSH_Init(void) { + save_hash = params->save_hash; hash = heritage.hash; if (hash->start != NULL) hash->start(); Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-09 13:25:00 UTC (rev 3713) +++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-10 13:33:28 UTC (rev 3714) @@ -105,4 +105,6 @@ #define hoh_head u.n.u_n_hoh_head #define hoh_digest u.n.u_n_hoh_digest }; + +extern unsigned save_hash; #endif /* VARNISH_CACHE_CHILD */ Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-09 13:25:00 UTC (rev 3713) +++ branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-10 13:33:28 UTC (rev 3714) @@ -177,6 +177,9 @@ /* Log hash string to shm */ unsigned log_hash; + /* Log hash string to shm */ + unsigned save_hash; + /* Log local socket address to shm */ unsigned log_local_addr; Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-09 13:25:00 UTC (rev 3713) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-10 13:33:28 UTC (rev 3714) @@ -100,7 +100,8 @@ if (arg != NULL) { u = strtod(arg, NULL); if (u < 0) { - cli_out(cli, "Timeout must be greater or equal to zero\n"); + cli_out(cli, + "Timeout must be greater or equal to zero\n"); cli_result(cli, CLIS_PARAM); return; } @@ -714,6 +715,12 @@ "Log the hash string to shared memory log.\n", 0, "off", "bool" }, + { "purge_hash", tweak_bool, &master.save_hash, 0, 0, + "Enable purge.hash command.\n" + "NB: this increases storage requirement per object " + "by the length of the hash string.\n", + MUST_RESTART, + "off", "bool" }, { "log_local_address", tweak_bool, &master.log_local_addr, 0, 0, "Log the local address on the TCP connection in the " "SessionOpen shared memory record.\n", Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00007.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00007.vtc 2009-02-09 13:25:00 UTC (rev 3713) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00007.vtc 2009-02-10 13:33:28 UTC (rev 3714) @@ -11,7 +11,11 @@ txresp -body "11111\n" } -start -varnish v1 -vcl+backend { } -start +varnish v1 -arg "-ppurge_hash=off" -vcl+backend { } -start +varnish v1 -clierr 300 "purge.hash foo" +varnish v1 -stop +varnish v1 -cliok "param.set purge_hash on" +varnish v1 -start client c1 { txreq -url "/foo" @@ -22,7 +26,7 @@ client c1 -run -varnish v1 -cli "purge.hash foo" +varnish v1 -cliok "purge.hash foo" client c1 { txreq -url "/foo" Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-02-09 13:25:00 UTC (rev 3713) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-02-10 13:33:28 UTC (rev 3714) @@ -13,7 +13,7 @@ txresp -hdr "foo: 3" -body "foo3" } -start -varnish v1 -vcl+backend {} -start +varnish v1 -arg "-p purge_hash=on" -vcl+backend {} -start varnish v1 -cliok "purge.url FOO" From tfheen at projects.linpro.no Tue Feb 10 13:39:53 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 14:39:53 +0100 (CET) Subject: r3715 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090210133953.51C7E28433@projects.linpro.no> Author: tfheen Date: 2009-02-10 14:39:53 +0100 (Tue, 10 Feb 2009) New Revision: 3715 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c Log: Set purge_hash to on by default in the 2.0 branch. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-10 13:33:28 UTC (rev 3714) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-10 13:39:53 UTC (rev 3715) @@ -720,7 +720,7 @@ "NB: this increases storage requirement per object " "by the length of the hash string.\n", MUST_RESTART, - "off", "bool" }, + "on", "bool" }, { "log_local_address", tweak_bool, &master.log_local_addr, 0, 0, "Log the local address on the TCP connection in the " "SessionOpen shared memory record.\n", From tfheen at projects.linpro.no Tue Feb 10 14:11:16 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 15:11:16 +0100 (CET) Subject: r3716 - in branches/2.0/varnish-cache: bin/varnishd include Message-ID: <20090210141116.AFE6228433@projects.linpro.no> Author: tfheen Date: 2009-02-10 15:11:16 +0100 (Tue, 10 Feb 2009) New Revision: 3716 Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am branches/2.0/varnish-cache/include/Makefile.am Log: Merge r3527: Make make dist happier; distribute the files we need Modified: branches/2.0/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-10 13:39:53 UTC (rev 3715) +++ branches/2.0/varnish-cache/bin/varnishd/Makefile.am 2009-02-10 14:11:16 UTC (rev 3716) @@ -70,7 +70,8 @@ mgt.h \ mgt_cli.h \ steps.h \ - stevedore.h + stevedore.h \ + vparam.h varnishd_CFLAGS = \ -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' Modified: branches/2.0/varnish-cache/include/Makefile.am =================================================================== --- branches/2.0/varnish-cache/include/Makefile.am 2009-02-10 13:39:53 UTC (rev 3715) +++ branches/2.0/varnish-cache/include/Makefile.am 2009-02-10 14:11:16 UTC (rev 3716) @@ -22,9 +22,11 @@ compat/vasprintf.h \ flopen.h \ http_headers.h \ + http_response.h \ libvarnish.h \ libvcl.h \ miniobj.h \ + vsha256.h \ vqueue.h \ vpf.h \ vsb.h \ From tfheen at projects.linpro.no Tue Feb 10 14:20:30 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 15:20:30 +0100 (CET) Subject: r3717 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090210142030.2D9B31F74D6@projects.linpro.no> Author: tfheen Date: 2009-02-10 15:20:29 +0100 (Tue, 10 Feb 2009) New Revision: 3717 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c branches/2.0/varnish-cache/bin/varnishd/cache_http.c branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c Log: Merge r3530: More asserts Be much more BOFH about bereq, more asserts, free them where they obviously should be freed. This could fix 421 or make it much worse, but give us more info. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-10 14:11:16 UTC (rev 3716) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-10 14:20:29 UTC (rev 3717) @@ -155,6 +155,8 @@ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); + AZ(sp->bereq); + sp->t_resp = TIM_real(); if (sp->obj->objhead != NULL) { sp->obj->last_use = sp->t_resp; /* XXX: locking ? */ @@ -301,6 +303,7 @@ char date[40]; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + AZ(sp->bereq); /* We always close when we take this path */ sp->doclose = "error"; @@ -663,6 +666,7 @@ sp->step = STP_FETCH; return (0); case VCL_RET_RESTART: + VBE_free_bereq(&sp->bereq); INCOMPL(); default: WRONG("Illegal action in vcl_miss{}"); @@ -713,6 +717,7 @@ VCL_pass_method(sp); if (sp->handling == VCL_RET_ERROR) { + VBE_free_bereq(&sp->bereq); sp->step = STP_ERROR; return (0); } @@ -769,6 +774,7 @@ assert(sp->handling == VCL_RET_PIPE); PipeSession(sp); + AZ(sp->bereq); AZ(sp->wrk->wfd); sp->step = STP_DONE; return (0); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-10 14:11:16 UTC (rev 3716) +++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-10 14:20:29 UTC (rev 3717) @@ -324,6 +324,7 @@ CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC); AN(sp->director); AN(sp->obj->busy); + AN(sp->bereq); w = sp->wrk; bereq = sp->bereq; hp = bereq->http; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-10 14:11:16 UTC (rev 3716) +++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-10 14:20:29 UTC (rev 3717) @@ -634,6 +634,7 @@ struct bereq *bereq; struct http *hp; + AZ(sp->bereq); bereq = VBE_new_bereq(); AN(bereq); hp = bereq->http; Modified: branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c 2009-02-10 14:11:16 UTC (rev 3716) +++ branches/2.0/varnish-cache/bin/varnishd/cache_pipe.c 2009-02-10 14:20:29 UTC (rev 3717) @@ -90,14 +90,15 @@ sp->acct_req.bodybytes += WRW_Write(w, sp->htc->pipeline.b, Tlen(sp->htc->pipeline)); - if (WRW_FlushRelease(w)) { + i = WRW_FlushRelease(w); + VBE_free_bereq(&bereq); + + if (i) { vca_close_session(sp, "pipe"); VBE_ClosedFd(sp); return; } - VBE_free_bereq(&bereq); - sp->t_resp = TIM_real(); memset(fds, 0, sizeof fds); From tfheen at projects.linpro.no Tue Feb 10 14:25:50 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 15:25:50 +0100 (CET) Subject: r3718 - in branches/2.0/varnish-cache: bin/varnishtest/tests lib/libvcl Message-ID: <20090210142550.4216F28433@projects.linpro.no> Author: tfheen Date: 2009-02-10 15:25:49 +0100 (Tue, 10 Feb 2009) New Revision: 3718 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/b00028.vtc Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c branches/2.0/varnish-cache/lib/libvcl/vcc_token_defs.h Log: Merge r3534: Add "no match" operator !~ to VCL regexps Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/b00028.vtc (from rev 3534, trunk/varnish-cache/bin/varnishtest/tests/b00028.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/b00028.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/b00028.vtc 2009-02-10 14:25:49 UTC (rev 3718) @@ -0,0 +1,28 @@ +# $Id$ + +test "regexp match and no-match" + +server s1 { + rxreq + txresp -hdr "Foo: bar" -hdr "Bar: foo" -body "1111\n" +} -start + +varnish v1 -vcl+backend { + + sub vcl_fetch { + if (obj.http.foo ~ "bar") { + set obj.http.foo1 = "1"; + } + if (obj.http.bar !~ "bar") { + set obj.http.bar1 = "1"; + } + } + +} -start + +client c1 { + txreq + rxresp + expect resp.http.foo1 == "1" + expect resp.http.bar1 == "1" +} -run Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:20:29 UTC (rev 3717) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:25:49 UTC (rev 3718) @@ -22,6 +22,7 @@ switch (p[0]) { case '!': + M2('~', T_NOMATCH); M2('=', T_NEQ); M1(); case '%': @@ -146,6 +147,7 @@ [T_LEQ] = "<=", [T_MUL] = "*=", [T_NEQ] = "!=", + [T_NOMATCH] = "!~", [T_SHL] = "<<", [T_SHR] = ">>", [VAR] = "VAR", Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-10 14:20:29 UTC (rev 3717) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-10 14:25:49 UTC (rev 3718) @@ -88,6 +88,7 @@ {"-=" DECR} {"*=" MUL} {"/=" DIV} + {"!~" NOMATCH} } # Single char tokens Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-10 14:20:29 UTC (rev 3717) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-02-10 14:25:49 UTC (rev 3718) @@ -248,12 +248,15 @@ switch (tl->t->tok) { case '~': + case T_NOMATCH: + Fb(tl, 1, "%sVRT_re_match(", + tl->t->tok == '~' ? "" : "!"); vcc_NextToken(tl); ExpectErr(tl, CSTR); p = vcc_regexp(tl, 0); ERRCHK(tl); vcc_NextToken(tl); - Fb(tl, 1, "VRT_re_match(%s, %s)\n", vp->rname, p); + Fb(tl, 1, "%s, %s)\n", vp->rname, p); break; case T_EQ: case T_NEQ: Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_token_defs.h =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_token_defs.h 2009-02-10 14:20:29 UTC (rev 3717) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_token_defs.h 2009-02-10 14:25:49 UTC (rev 3718) @@ -26,9 +26,10 @@ #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 +#define T_NOMATCH 147 +#define ID 148 +#define VAR 149 +#define CNUM 150 +#define CSTR 151 +#define EOI 152 +#define CSRC 153 From tfheen at projects.linpro.no Tue Feb 10 14:32:11 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 15:32:11 +0100 (CET) Subject: r3719 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090210143211.043C128433@projects.linpro.no> Author: tfheen Date: 2009-02-10 15:32:10 +0100 (Tue, 10 Feb 2009) New Revision: 3719 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/r00425.vtc Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c Log: Merge r3537: Enforce a minimum ttl for "hit for pass" objects to prevent a value of zero from serializing access to an object with very draconian backend cache-control headers. We could get far even with a one second TTL, but following our general "there is a reason people put Varnish there in the first place" logic we use the default_ttl parameter (default: 120 s) for this value. If another value is desired, this can be set in vcl_fetch, even if it looks somewhat counter-intuitive: sub vcl_fetch { if (obj.http.set-cookie) { set obj.ttl = 10s; pass; } } Fixes #425 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-10 14:25:49 UTC (rev 3718) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-02-10 14:32:10 UTC (rev 3719) @@ -413,6 +413,8 @@ return (0); case VCL_RET_PASS: sp->obj->pass = 1; + if (sp->obj->ttl - sp->t_req < params->default_ttl) + sp->obj->ttl = sp->t_req + params->default_ttl; break; case VCL_RET_DELIVER: break; Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/r00425.vtc (from rev 3537, trunk/varnish-cache/bin/varnishtest/tests/r00425.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/r00425.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/r00425.vtc 2009-02-10 14:32:10 UTC (rev 3719) @@ -0,0 +1,34 @@ +# $Id$ + +test "check late pass stalling" + +server s1 { + rxreq + txresp \ + -hdr "Set-Cookie: foo=bar" \ + -hdr "Expires: Thu, 19 Nov 1981 08:52:00 GMT" \ + -body "1111\n" + rxreq + txresp \ + -hdr "Set-Cookie: foo=bar" \ + -hdr "Expires: Thu, 19 Nov 1981 08:52:00 GMT" \ + -body "22222n" + rxreq + txresp \ + -hdr "Set-Cookie: foo=bar" \ + -hdr "Expires: Thu, 19 Nov 1981 08:52:00 GMT" \ + -body "33333n" +} -start + +varnish v1 -vcl+backend { } -start + +client c1 { + txreq + rxresp + txreq + rxresp + txreq + rxresp +} -run + +varnish v1 -expect cache_hitpass == 2 From tfheen at projects.linpro.no Tue Feb 10 14:35:50 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 15:35:50 +0100 (CET) Subject: r3720 - in branches/2.0/varnish-cache: bin/varnishd include Message-ID: <20090210143550.E04F328433@projects.linpro.no> Author: tfheen Date: 2009-02-10 15:35:50 +0100 (Tue, 10 Feb 2009) New Revision: 3720 Added: branches/2.0/varnish-cache/include/purge_vars.h Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c Log: Merge r3538: Move the purgable variables into a CPP table, so we can share them with the VCL compiler Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-10 14:32:10 UTC (rev 3719) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-10 14:35:50 UTC (rev 3720) @@ -297,11 +297,23 @@ bt->src[l + 2] = '\0'; } +static const struct pvar { + const char *name; + unsigned flag; + ban_cond_f *func; +} pvars[] = { +#define PVAR(a, b, c) { a, b, c }, +#include "purge_vars.h" +#undef PVAR + { 0, 0, 0} +}; + static int ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) { struct ban_test *bt; struct vsb *sb; + const struct pvar *pv; int i; CHECK_OBJ_NOTNULL(b, BAN_MAGIC); @@ -336,17 +348,15 @@ } - if (!strcmp(a1, "req.url")) - bt->func = ban_cond_url; - else if (!strcmp(a1, "obj.hash")) - bt->func = ban_cond_hash; - else if (!strncmp(a1, "req.http.", 9)) { - bt->func = ban_cond_req_http; - ban_parse_http(bt, a1 + 9); - } else if (!strncmp(a1, "obj.http.", 9)) { - bt->func = ban_cond_obj_http; - ban_parse_http(bt, a1 + 9); - } else { + for (pv = pvars; pv->name != NULL; pv++) { + if (strncmp(a1, pv->name, strlen(pv->name))) + continue; + bt->func = pv->func; + if (pv->flag & 1) + ban_parse_http(bt, a1 + strlen(pv->name)); + break; + } + if (pv->name == NULL) { cli_out(cli, "unknown or unsupported field \"%s\"", a1); cli_result(cli, CLIS_PARAM); return (-1); Copied: branches/2.0/varnish-cache/include/purge_vars.h (from rev 3538, trunk/varnish-cache/include/purge_vars.h) =================================================================== --- branches/2.0/varnish-cache/include/purge_vars.h (rev 0) +++ branches/2.0/varnish-cache/include/purge_vars.h 2009-02-10 14:35:50 UTC (rev 3720) @@ -0,0 +1,36 @@ +/*- + * 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$ + * + * Define which variables we can purge on, and which function does it. + */ + +PVAR("req.url", 0, ban_cond_url) +PVAR("obj.hash", 0, ban_cond_hash) +PVAR("req.http.", 1, ban_cond_req_http) +PVAR("obj.http.", 1, ban_cond_obj_http) From tfheen at projects.linpro.no Tue Feb 10 14:43:31 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 15:43:31 +0100 (CET) Subject: r3721 - branches/2.0/varnish-cache/redhat Message-ID: <20090210144331.BC10428433@projects.linpro.no> Author: tfheen Date: 2009-02-10 15:43:31 +0100 (Tue, 10 Feb 2009) New Revision: 3721 Modified: branches/2.0/varnish-cache/redhat/varnish.spec Log: Merge r3539: Don't need debug patch outside fedora package Modified: branches/2.0/varnish-cache/redhat/varnish.spec =================================================================== --- branches/2.0/varnish-cache/redhat/varnish.spec 2009-02-10 14:35:50 UTC (rev 3720) +++ branches/2.0/varnish-cache/redhat/varnish.spec 2009-02-10 14:43:31 UTC (rev 3721) @@ -6,6 +6,7 @@ Group: System Environment/Daemons URL: http://www.varnish-cache.org/ Source0: http://downloads.sourceforge.net/varnish/varnish-%{version}.tar.gz +#Patch0: varnish.varnishtest_debugflag.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) # The svn sources needs autoconf, automake and libtool to generate a suitable # configure script. Release tarballs would not need this @@ -63,6 +64,8 @@ %setup -q #%setup -q -n varnish-cache +#%patch0 -p0 + # The svn sources needs to generate a suitable configure script # Release tarballs would not need this #./autogen.sh From tfheen at projects.linpro.no Tue Feb 10 14:47:37 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 15:47:37 +0100 (CET) Subject: r3722 - branches/2.0/varnish-cache/bin/varnishtest Message-ID: <20090210144737.6AC0828433@projects.linpro.no> Author: tfheen Date: 2009-02-10 15:47:36 +0100 (Tue, 10 Feb 2009) New Revision: 3722 Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c Log: Merge r3540: Don't append a CRNL to the body. And add separate rxhdrs and rxbody primitives. Submitted by: Yonatan Broza & Dmitry Rubinstein Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c 2009-02-10 14:43:31 UTC (rev 3721) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_http.c 2009-02-10 14:47:36 UTC (rev 3722) @@ -531,10 +531,8 @@ if (body != NULL) vsb_printf(hp->vsb, "Content-Length: %d%s", strlen(body), nl); vsb_cat(hp->vsb, nl); - if (body != NULL) { + if (body != NULL) vsb_cat(hp->vsb, body); - vsb_cat(hp->vsb, nl); - } http_write(hp, 4, "txresp"); } @@ -565,6 +563,48 @@ vtc_log(hp->vl, 4, "bodylen = %s", hp->bodylen); } +static void +cmd_http_rxhdrs(CMD_ARGS) +{ + struct http *hp; + + (void)cmd; + (void)vl; + CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); + AZ(hp->client); + assert(!strcmp(av[0], "rxhdrs")); + av++; + + for(; *av != NULL; av++) { + fprintf(stderr, "Unknown http rxreq spec: %s\n", *av); + exit (1); + } + vtc_log(hp->vl, 3, "rxhdrs"); + http_rxhdr(hp); + http_splitheader(hp, 1); +} + +static void +cmd_http_rxbody(CMD_ARGS) +{ + struct http *hp; + + (void)cmd; + (void)vl; + CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); + AZ(hp->client); + assert(!strcmp(av[0], "rxbody")); + av++; + + for(; *av != NULL; av++) { + fprintf(stderr, "Unknown http rxreq spec: %s\n", *av); + exit (1); + } + vtc_log(hp->vl, 3, "rxbody"); + http_swallow_body(hp, hp->req, 0); + vtc_log(hp->vl, 4, "bodylen = %s", hp->bodylen); +} + /********************************************************************** * Transmit a request */ @@ -698,7 +738,11 @@ static struct cmds http_cmds[] = { { "timeout", cmd_http_timeout }, { "txreq", cmd_http_txreq }, + { "rxreq", cmd_http_rxreq }, + { "rxhdrs", cmd_http_rxhdrs }, + { "rxbody", cmd_http_rxbody }, + { "txresp", cmd_http_txresp }, { "rxresp", cmd_http_rxresp }, { "expect", cmd_http_expect }, From tfheen at projects.linpro.no Tue Feb 10 14:50:53 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 15:50:53 +0100 (CET) Subject: r3723 - in branches/2.0/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20090210145053.71D2B2846D@projects.linpro.no> Author: tfheen Date: 2009-02-10 15:50:53 +0100 (Tue, 10 Feb 2009) New Revision: 3723 Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h branches/2.0/varnish-cache/bin/varnishd/cache_ban.c branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c branches/2.0/varnish-cache/include/vrt.h branches/2.0/varnish-cache/lib/libvcl/vcc_action.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Merge r3541: First cut at VCL support for new-purge. Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-10 14:47:36 UTC (rev 3722) +++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-10 14:50:53 UTC (rev 3723) @@ -417,7 +417,10 @@ void VBP_Init(void); /* cache_ban.c */ -int BAN_Add(struct cli *cli, const char *regexp, int hash); +struct ban *BAN_New(void); +int BAN_AddTest(struct cli *, struct ban *, const char *, const char *, const char *); +void BAN_Free(struct ban *b); +void BAN_Insert(struct ban *b); void BAN_Init(void); void BAN_NewObj(struct object *o); void BAN_DestroyObj(struct object *o); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-10 14:47:36 UTC (rev 3722) +++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-10 14:50:53 UTC (rev 3723) @@ -95,8 +95,8 @@ * Manipulation of bans */ -static struct ban * -ban_new_ban(void) +struct ban * +BAN_New(void) { struct ban *b; ALLOC_OBJ(b, BAN_MAGIC); @@ -140,8 +140,8 @@ } while (i); } -static void -ban_free_ban(struct ban *b) +void +BAN_Free(struct ban *b) { struct ban_test *bt; @@ -308,8 +308,8 @@ { 0, 0, 0} }; -static int -ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) +int +BAN_AddTest(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) { struct ban_test *bt; struct vsb *sb; @@ -387,7 +387,7 @@ */ static struct ban * volatile ban_start; -static void +void BAN_Insert(struct ban *b) { struct ban *bi, *be; @@ -476,7 +476,7 @@ b = BAN_CheckLast(); Lck_Unlock(&ban_mtx); if (b != NULL) - ban_free_ban(b); + BAN_Free(b); } @@ -564,38 +564,20 @@ } } - b = ban_new_ban(); + b = BAN_New(); if (b == NULL) { cli_out(cli, "Out of Memory"); cli_result(cli, CLIS_CANT); return; } for (i = 0; i < narg; i += 4) - if (ban_parse_test(cli, b, av[i + 2], av[i + 3], av[i + 4])) { - ban_free_ban(b); + if (BAN_AddTest(cli, b, av[i + 2], av[i + 3], av[i + 4])) { + BAN_Free(b); return; } BAN_Insert(b); } -int -BAN_Add(struct cli *cli, const char *regexp, int hash) -{ - const char *aav[6]; - - aav[0] = NULL; - aav[1] = "purge"; - if (hash) - aav[2] = "obj.hash"; - else - aav[2] = "req.url"; - aav[3] = "~"; - aav[4] = regexp; - aav[5] = NULL; - ccf_purge(cli, aav, NULL); - return (0); -} - static void ccf_purge_url(struct cli *cli, const char * const *av, void *priv) { @@ -651,7 +633,7 @@ VTAILQ_LAST(&ban_head, banhead)->refcount++; Lck_Unlock(&ban_mtx); if (b != NULL) - ban_free_ban(b); + BAN_Free(b); } while (b != NULL); VTAILQ_FOREACH(b, &ban_head, list) { @@ -692,9 +674,17 @@ void BAN_Init(void) { + const char *aav[6]; Lck_New(&ban_mtx); CLI_AddFuncs(PUBLIC_CLI, ban_cmds); + /* Add an initial ban, since the list can never be empty */ - (void)BAN_Add(NULL, ".", 0); + aav[0] = NULL; + aav[1] = "purge"; + aav[2] = "req.url"; + aav[3] = "~"; + aav[4] = "."; + aav[5] = NULL; + ccf_purge(NULL, aav, NULL); } Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-10 14:47:36 UTC (rev 3722) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-10 14:50:53 UTC (rev 3723) @@ -762,11 +762,35 @@ /*--------------------------------------------------------------------*/ void -VRT_purge(const char *regexp, int hash) +VRT_purge(struct sess *sp, char *cmds, ...) { + char *a1, *a2, *a3; + va_list ap; + struct ban *b; + int good; - if (regexp != NULL) - (void)BAN_Add(NULL, regexp, hash); + (void)sp; + b = BAN_New(); + va_start(ap, cmds); + a1 = cmds; + good = 0; + while (a1 != NULL) { + good = 0; + a2 = va_arg(ap, char *); + if (a2 == NULL) + break; + a3 = va_arg(ap, char *); + if (a3 == NULL) + break; + if (BAN_AddTest(NULL, b, a1, a2, a3)) + break; + a1 = va_arg(ap, char *); + good = 1; + } + if (!good) + BAN_Free(b); + else + BAN_Insert(b); } /*-------------------------------------------------------------------- Modified: branches/2.0/varnish-cache/include/vrt.h =================================================================== --- branches/2.0/varnish-cache/include/vrt.h 2009-02-10 14:47:36 UTC (rev 3722) +++ branches/2.0/varnish-cache/include/vrt.h 2009-02-10 14:50:53 UTC (rev 3723) @@ -141,8 +141,8 @@ 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_panic(struct sess *sp, const char *, ...); +void VRT_purge(struct sess *sp, char *, ...); void VRT_count(const struct sess *, unsigned); int VRT_rewrite(const char *, const char *); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-10 14:47:36 UTC (rev 3722) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-10 14:50:53 UTC (rev 3723) @@ -348,27 +348,86 @@ /*--------------------------------------------------------------------*/ static void -parse_purge_url(struct tokenlist *tl) +parse_purge(struct tokenlist *tl) { vcc_NextToken(tl); - Fb(tl, 1, "VRT_purge("); Expect(tl, '('); vcc_NextToken(tl); + if (tl->t->tok == VAR) { + Fb(tl, 1, "VRT_purge(sp,\n"); + tl->indent += INDENT; + while (1) { + ExpectErr(tl, VAR); + Fb(tl, 1, " \"%.*s\",\n", PF(tl->t)); + vcc_NextToken(tl); + switch(tl->t->tok) { + case '~': + case T_NOMATCH: + case T_EQ: + case T_NEQ: + Fb(tl, 1, " \"%.*s\",\n", PF(tl->t)); + break; + default: + vsb_printf(tl->sb, + "Expected ~, !~, == or !=.\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + vcc_NextToken(tl); + Fb(tl, 1, " "); + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return; + } + Fb(tl, 0, ",\n"); + if (tl->t->tok == ')') + break; + ExpectErr(tl, T_CAND); + Fb(tl, 1, "\"%.*s\",\n", PF(tl->t)); + vcc_NextToken(tl); + } + Fb(tl, 1, "0);\n"); + tl->indent -= INDENT; + } else { + Fb(tl, 1, "VRT_purge_string(sp, "); + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return; + } + do + Fb(tl, 0, ", "); + while (vcc_StringVal(tl)); + Fb(tl, 0, ", 0);\n"); + } + + Expect(tl, ')'); + vcc_NextToken(tl); +} + +/*--------------------------------------------------------------------*/ + +static void +parse_purge_url(struct tokenlist *tl) +{ + + vcc_NextToken(tl); + Expect(tl, '('); + vcc_NextToken(tl); + + Fb(tl, 1, "VRT_purge(sp, \"req.url\", \"~\", "); if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return; } - Expect(tl, ')'); vcc_NextToken(tl); Fb(tl, 0, ", 0);\n"); } - /*--------------------------------------------------------------------*/ static void @@ -376,22 +435,21 @@ { vcc_NextToken(tl); - - Fb(tl, 1, "VRT_purge("); - Expect(tl, '('); vcc_NextToken(tl); + Fb(tl, 1, "VRT_purge(sp, \"obj.hash\", \"~\", "); if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return; } - Expect(tl, ')'); vcc_NextToken(tl); - Fb(tl, 0, ", 1);\n"); + Fb(tl, 0, ", 0);\n"); } +/*--------------------------------------------------------------------*/ + static void parse_esi(struct tokenlist *tl) { @@ -470,6 +528,7 @@ { "call", parse_call }, { "esi", parse_esi }, { "panic", parse_panic }, + { "purge", parse_purge }, { "purge_hash", parse_purge_hash }, { "purge_url", parse_purge_url }, { "remove", parse_unset }, /* backward compatibility */ Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:47:36 UTC (rev 3722) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:50:53 UTC (rev 3723) @@ -159,8 +159,8 @@ /* ../../include/vcl.h */ - vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3676 2009-02-06 14"); - vsb_cat(sb, ":18:21Z tfheen $\n *\n * NB: This file is machine gen"); + vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3718 2009-02-10 14"); + vsb_cat(sb, ":25:49Z tfheen $\n *\n * NB: This file is machine gen"); vsb_cat(sb, "erated, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixe"); vsb_cat(sb, "d_token.tcl instead\n */\n\nstruct sess;\n"); vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n"); @@ -287,8 +287,8 @@ vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n"); vsb_cat(sb, "const char *VRT_regsub(const struct sess *sp, int all,"); vsb_cat(sb, " const char *,\n void *, const char *);\n"); - vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);"); - vsb_cat(sb, "\nvoid VRT_purge(const char *, int hash);\n"); + vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);\n"); + vsb_cat(sb, "void VRT_purge(struct sess *sp, char *, ...);\n"); vsb_cat(sb, "\nvoid VRT_count(const struct sess *, unsigned);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);"); From tfheen at projects.linpro.no Tue Feb 10 14:58:18 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 15:58:18 +0100 (CET) Subject: r3724 - in branches/2.0/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl Message-ID: <20090210145818.0BB032846D@projects.linpro.no> Author: tfheen Date: 2009-02-10 15:58:17 +0100 (Tue, 10 Feb 2009) New Revision: 3724 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c branches/2.0/varnish-cache/include/vrt.h branches/2.0/varnish-cache/lib/libvcl/vcc_action.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Merge r3542: Implement the new-purge case where the entire expression comes from VCL. It is possible to instigate purges two ways from VCL now: sub vcl_recv { # Purge the req.url if (req.request == "PURGE") { purge (req.url == req.url); error 410; } # Take entire purge instruction from "Purge:" header if (req.request == "PURGESTR") { purge ("" req.http.purge); error 410; } Testcase for this. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-10 14:50:53 UTC (rev 3723) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-10 14:58:17 UTC (rev 3724) @@ -788,11 +788,61 @@ good = 1; } if (!good) + /* XXX: report error how ? */ BAN_Free(b); else BAN_Insert(b); } +/*--------------------------------------------------------------------*/ + +void +VRT_purge_string(struct sess *sp, char *str, ...) +{ + char *p, *a1, *a2, *a3; + char **av; + va_list ap; + struct ban *b; + int good; + int i; + + va_start(ap, str); + p = vrt_assemble_string(sp->http, NULL, str, ap); + if (p == NULL) + /* XXX: report error how ? */ + return; + + av = ParseArgv(p, 0); + if (av[0] != NULL) { + /* XXX: report error how ? */ + FreeArgv(av); + return; + } + b = BAN_New(); + good = 0; + for (i = 1; ; i += 3) { + a1 = av[i]; + if (a1 == NULL) + break; + good = 0; + a2 = av[i + 1]; + if (a2 == NULL) + break; + a3 = av[i + 2]; + if (a3 == NULL) + break; + if (BAN_AddTest(NULL, b, a1, a2, a3)) + break; + good = 1; + } + if (!good) + /* XXX: report error how ? */ + BAN_Free(b); + else + BAN_Insert(b); + FreeArgv(av); +} + /*-------------------------------------------------------------------- * Simple stuff */ Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc (from rev 3542, trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc 2009-02-10 14:58:17 UTC (rev 3724) @@ -0,0 +1,162 @@ +# $Id$ + +test "Test banning a url with VCL purge" + +server s1 { + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar5" -body "1111\n" + + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar6" -body "11111\n" + + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar7" -body "111111\n" + + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar8" -body "1111111\n" +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.request == "PURGE") { + purge (req.url == req.url); + error 410; + } + if (req.request == "PURGESTR") { + purge ("" req.http.purge); + error 410; + } + } +} -start + +# Fetch into cache +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar5 + expect resp.bodylen == 5 +} -run + +# Purge something else +client c1 { + txreq -req PURGE -url /foox + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +# Still in cache +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar5 + expect resp.bodylen == 5 +} -run + +# Purge it +client c1 { + txreq -req PURGE -url /foo + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +# New obj +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar6 + expect resp.bodylen == 6 +} -run + +# Purge everything else +client c1 { + txreq -req PURGESTR -hdr "purge=req.url != /foo" + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +# still there +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar6 + expect resp.bodylen == 6 +} -run + +# Purge it +client c1 { + txreq -req PURGESTR -hdr "Purge: obj.http.foo == \"bar6\"" + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +# New one +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar7 + expect resp.bodylen == 7 +} -run + +# Purge something else +client c1 { + txreq -req PURGESTR -hdr "Purge: obj.http.foo == \"bar6\"" + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +# Still there +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar7 + expect resp.bodylen == 7 +} -run + +# Header match +client c1 { + txreq -req PURGESTR -hdr "Purge: req.http.foo == \"barcheck\"" + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" -hdr "foo: barcheck" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar8 + expect resp.bodylen == 8 +} -run + +# Header match +client c1 { + txreq -req PURGESTR -hdr "Purge: obj.http.foo == \"barcheck\"" + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar8 + expect resp.bodylen == 8 +} -run + + Modified: branches/2.0/varnish-cache/include/vrt.h =================================================================== --- branches/2.0/varnish-cache/include/vrt.h 2009-02-10 14:50:53 UTC (rev 3723) +++ branches/2.0/varnish-cache/include/vrt.h 2009-02-10 14:58:17 UTC (rev 3724) @@ -143,6 +143,7 @@ void VRT_panic(struct sess *sp, const char *, ...); void VRT_purge(struct sess *sp, char *, ...); +void VRT_purge_string(struct sess *sp, char *, ...); void VRT_count(const struct sess *, unsigned); int VRT_rewrite(const char *, const char *); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-10 14:50:53 UTC (rev 3723) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-10 14:58:17 UTC (rev 3724) @@ -401,7 +401,7 @@ do Fb(tl, 0, ", "); while (vcc_StringVal(tl)); - Fb(tl, 0, ", 0);\n"); + Fb(tl, 0, "vrt_magic_string_end);\n"); } Expect(tl, ')'); Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:50:53 UTC (rev 3723) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:58:17 UTC (rev 3724) @@ -235,8 +235,8 @@ vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI"); vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT"); vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"); - vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3616 2009-02-05 11:"); - vsb_cat(sb, "43:20Z tfheen $\n *\n * Runtime support for compiled V"); + vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3723 2009-02-10 14:"); + vsb_cat(sb, "50:53Z tfheen $\n *\n * Runtime support for compiled V"); vsb_cat(sb, "CL programs.\n *\n * XXX: When this file is changed, l"); vsb_cat(sb, "ib/libvcl/vcc_gen_fixed_token.tcl\n"); vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n"); @@ -289,6 +289,7 @@ vsb_cat(sb, " const char *,\n void *, const char *);\n"); vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);\n"); vsb_cat(sb, "void VRT_purge(struct sess *sp, char *, ...);\n"); + vsb_cat(sb, "void VRT_purge_string(struct sess *sp, char *, ...);\n"); vsb_cat(sb, "\nvoid VRT_count(const struct sess *, unsigned);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);"); From tfheen at projects.linpro.no Tue Feb 10 15:01:28 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 16:01:28 +0100 (CET) Subject: r3725 - in branches/2.0/varnish-cache: bin/varnishtest/tests lib/libvcl Message-ID: <20090210150128.D450B2846D@projects.linpro.no> Author: tfheen Date: 2009-02-10 16:01:28 +0100 (Tue, 10 Feb 2009) New Revision: 3725 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc branches/2.0/varnish-cache/lib/libvcl/vcc_action.c branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Merge r3543: Test that we know the purge variable when it is compiled in. Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc 2009-02-10 14:58:17 UTC (rev 3724) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc 2009-02-10 15:01:28 UTC (rev 3725) @@ -33,6 +33,26 @@ } } -start +# Trigger syntax check +varnish v1 -badvcl { + backend foo { + .host = "127.0.0.1"; + } + sub vcl_recv { + purge (req.foo == req.url); + } +} + +# Trigger syntax check +varnish v1 -badvcl { + backend foo { + .host = "127.0.0.1"; + } + sub vcl_recv { + purge (req.http. == req.url); + } +} + # Fetch into cache client c1 { txreq -url "/foo" Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-10 14:58:17 UTC (rev 3724) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-10 15:01:28 UTC (rev 3725) @@ -32,6 +32,7 @@ #include "config.h" #include +#include #include "vsb.h" @@ -347,13 +348,23 @@ /*--------------------------------------------------------------------*/ +static const struct purge_var { + const char *name; + unsigned flag; +} purge_var[] = { +#define PVAR(a, b, c) { a, b }, +#include "purge_vars.h" +#undef PVAR + { 0, 0 } +}; + static void parse_purge(struct tokenlist *tl) { + const struct purge_var *pv; vcc_NextToken(tl); - Expect(tl, '('); vcc_NextToken(tl); @@ -362,6 +373,25 @@ tl->indent += INDENT; while (1) { ExpectErr(tl, VAR); + + /* Check valididity of purge variable */ + for (pv = purge_var; pv->name != NULL; pv++) { + if (!strncmp(pv->name, tl->t->b, + strlen(pv->name))) + break; + } + if (pv->name == NULL) { + vsb_printf(tl->sb, "Unknown purge variable."); + vcc_ErrWhere(tl, tl->t); + return; + } + if (pv->flag && + tl->t->b + strlen(pv->name) >= tl->t->e) { + vsb_printf(tl->sb, "Missing header name."); + vcc_ErrWhere(tl, tl->t); + return; + } + Fb(tl, 1, " \"%.*s\",\n", PF(tl->t)); vcc_NextToken(tl); switch(tl->t->tok) { Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:58:17 UTC (rev 3724) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 15:01:28 UTC (rev 3725) @@ -235,8 +235,8 @@ vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI"); vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT"); vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"); - vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3723 2009-02-10 14:"); - vsb_cat(sb, "50:53Z tfheen $\n *\n * Runtime support for compiled V"); + vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3724 2009-02-10 14:"); + vsb_cat(sb, "58:17Z tfheen $\n *\n * Runtime support for compiled V"); vsb_cat(sb, "CL programs.\n *\n * XXX: When this file is changed, l"); vsb_cat(sb, "ib/libvcl/vcc_gen_fixed_token.tcl\n"); vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n"); From tfheen at projects.linpro.no Tue Feb 10 15:06:32 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 16:06:32 +0100 (CET) Subject: r3726 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090210150632.2594F2846D@projects.linpro.no> Author: tfheen Date: 2009-02-10 16:06:31 +0100 (Tue, 10 Feb 2009) New Revision: 3726 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c Log: Merge r3544: Lack of a backend name is no reasonable cause for a panic. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-10 15:01:28 UTC (rev 3725) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-10 15:06:31 UTC (rev 3726) @@ -697,9 +697,10 @@ const char * VRT_backend_string(struct sess *sp) { - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC); - return (sp->director->vcl_name); + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + if (sp->director == NULL) + return (NULL); + return (sp->director->vcl_name); } /*--------------------------------------------------------------------*/ From tfheen at projects.linpro.no Tue Feb 10 15:10:04 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 10 Feb 2009 16:10:04 +0100 (CET) Subject: r3727 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090210151004.EA4382846D@projects.linpro.no> Author: tfheen Date: 2009-02-10 16:10:04 +0100 (Tue, 10 Feb 2009) New Revision: 3727 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c Log: Merge r3545: Don't modify the obj_timer_when field outside the binheap lock. This hopefully finaly lays the sporadic assert(oe2->timer_when >= oe->timer_when); panics to rest. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-10 15:06:31 UTC (rev 3726) +++ branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-10 15:10:04 UTC (rev 3727) @@ -133,27 +133,34 @@ * When & why does the timer fire for this object ? */ -static void +static int update_object_when(const struct object *o) { struct objexp *oe; + double when; + const char *what; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oe = o->objexp; CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); if (o->prefetch < 0.0) { - oe->timer_when = o->ttl + o->prefetch; - oe->timer_what = tmr_prefetch; + when = o->ttl + o->prefetch; + what = tmr_prefetch; } else if (o->prefetch > 0.0) { assert(o->prefetch <= o->ttl); - oe->timer_when = o->prefetch; - oe->timer_what = tmr_prefetch; + when = o->prefetch; + what = tmr_prefetch; } else { - oe->timer_when = o->ttl + HSH_Grace(o->grace); - oe->timer_what = tmr_ttl; + when = o->ttl + HSH_Grace(o->grace); + what = tmr_ttl; } - assert(!isnan(oe->timer_when)); + assert(!isnan(when)); + oe->timer_what = what; + if (when == oe->timer_when) + return (0); + oe->timer_when = when; + return (1); } /*-------------------------------------------------------------------- @@ -237,13 +244,20 @@ if (oe == NULL) return; CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); - update_object_when(o); Lck_Lock(&exp_mtx); - assert(oe->timer_idx != BINHEAP_NOIDX); - binheap_delete(exp_heap, oe->timer_idx); /* XXX: binheap_shuffle() ? */ - assert(oe->timer_idx == BINHEAP_NOIDX); - binheap_insert(exp_heap, oe); - assert(oe->timer_idx != BINHEAP_NOIDX); + if (update_object_when(o)) { + /* + * XXX: this could possibly be optimized by shuffling + * XXX: up or down, but that leaves some very nasty + * XXX: corner cases, such as shuffling all the way + * XXX: down the left half, then back up the right half. + */ + assert(oe->timer_idx != BINHEAP_NOIDX); + binheap_delete(exp_heap, oe->timer_idx); + assert(oe->timer_idx == BINHEAP_NOIDX); + binheap_insert(exp_heap, oe); + assert(oe->timer_idx != BINHEAP_NOIDX); + } Lck_Unlock(&exp_mtx); } From tfheen at projects.linpro.no Wed Feb 11 06:55:23 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 07:55:23 +0100 (CET) Subject: r3728 - branches/2.0/varnish-cache/lib/libvcl Message-ID: <20090211065523.7F2B31F74AC@projects.linpro.no> Author: tfheen Date: 2009-02-11 07:55:23 +0100 (Wed, 11 Feb 2009) New Revision: 3728 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_string.c Log: Merge r3546: proper errorchecks for regsub syntax. (The recent change that moved the compiler into its own subprocess eliminates risk that a compiler error causes the management process to die, you just do not get a sensible syntax error). Fixes: #417 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_string.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_string.c 2009-02-10 15:10:04 UTC (rev 3727) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_string.c 2009-02-11 06:55:23 UTC (rev 3728) @@ -53,6 +53,8 @@ int i; Expect(tl, CSTR); + if (tl->err) + return (NULL); memset(&t, 0, sizeof t); i = regcomp(&t, tl->t->dec, REG_EXTENDED | (sub ? 0 : REG_NOSUB)); if (i != 0) { @@ -88,6 +90,8 @@ Fb(tl, 0, "VRT_regsub(sp, %d, ", all); Expect(tl, '('); + if (tl->err) + return (0); vcc_NextToken(tl); if (!vcc_StringVal(tl)) { @@ -96,14 +100,20 @@ } Expect(tl, ','); + if (tl->err) + return (0); vcc_NextToken(tl); Expect(tl, CSTR); + if (tl->err) + return (0); p = vcc_regexp(tl, 1); vcc_NextToken(tl); Fb(tl, 0, ", %s, ", p); Expect(tl, ','); + if (tl->err) + return (0); vcc_NextToken(tl); if (!vcc_StringVal(tl)) { @@ -112,6 +122,8 @@ } Expect(tl, ')'); + if (tl->err) + return (0); vcc_NextToken(tl); Fb(tl, 0, ")"); From tfheen at projects.linpro.no Wed Feb 11 06:58:38 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 07:58:38 +0100 (CET) Subject: r3729 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090211065838.E69E62844F@projects.linpro.no> Author: tfheen Date: 2009-02-11 07:58:38 +0100 (Wed, 11 Feb 2009) New Revision: 3729 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/r00427.vtc Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Merge r3547: Stop processing ESI elements as soon as we discover that the client has closed the connection on us. Fixes #427 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 06:55:23 UTC (rev 3728) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 06:58:38 UTC (rev 3729) @@ -862,6 +862,8 @@ sp->esis--; sp->obj = obj; WRW_Reserve(sp->wrk, &sp->fd); + if (sp->fd < 0) + break; } if (sp->esis == 0 && sp->http->protover >= 1.1) (void)WRW_Write(sp->wrk, "0\r\n\r\n", -1); Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/r00427.vtc (from rev 3547, trunk/varnish-cache/bin/varnishtest/tests/r00427.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/r00427.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/r00427.vtc 2009-02-11 06:58:38 UTC (rev 3729) @@ -0,0 +1,43 @@ +# $Id$ + +test "client close in ESI delivery" + +server s1 { + rxreq + txresp -body { + + + + } + + rxreq + expect req.url == "/foo" + sema r1 sync 2 + sema r1 sync 2 + txresp -body "[foo]" + + rxreq + expect req.url == "/bar" + txresp -body "[bar]" + + rxreq + expect req.url == "/barf" + txresp -body "[barf]" +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + esi; + } +} -start + +client c1 { + txreq + sema r1 sync 2 +} -run + +client c1 { + sema r1 sync 2 + txreq + rxresp +} -run From tfheen at projects.linpro.no Wed Feb 11 07:02:43 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:02:43 +0100 (CET) Subject: r3730 - in branches/2.0/varnish-cache/lib: libvarnish libvcl Message-ID: <20090211070243.D08A62844F@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:02:43 +0100 (Wed, 11 Feb 2009) New Revision: 3730 Modified: branches/2.0/varnish-cache/lib/libvarnish/tcp.c branches/2.0/varnish-cache/lib/libvarnish/vss.c branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c Log: Merge r3548: silence a couple of Flexelint complaints. Modified: branches/2.0/varnish-cache/lib/libvarnish/tcp.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/tcp.c 2009-02-11 06:58:38 UTC (rev 3729) +++ branches/2.0/varnish-cache/lib/libvarnish/tcp.c 2009-02-11 07:02:43 UTC (rev 3730) @@ -216,8 +216,8 @@ TCP_set_read_timeout(int s, double seconds) { struct timeval timeout; - timeout.tv_sec = floor(seconds); - timeout.tv_usec = 1e6 * (seconds - timeout.tv_sec); + timeout.tv_sec = (int)floor(seconds); + timeout.tv_usec = (int)(1e6 * (seconds - timeout.tv_sec)); #ifdef SO_RCVTIMEO_WORKS AZ(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout)); #endif Modified: branches/2.0/varnish-cache/lib/libvarnish/vss.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vss.c 2009-02-11 06:58:38 UTC (rev 3729) +++ branches/2.0/varnish-cache/lib/libvarnish/vss.c 2009-02-11 07:02:43 UTC (rev 3730) @@ -155,7 +155,7 @@ XXXAN(va); *vap = va; for (res = res0, i = 0; res != NULL; res = res->ai_next, ++i) { - va[i] = calloc(1, sizeof(*va[i])); + va[i] = calloc(1, sizeof(**va)); XXXAN(va[i]); va[i]->va_family = res->ai_family; va[i]->va_socktype = res->ai_socktype; Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c 2009-02-11 06:58:38 UTC (rev 3729) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_acl.c 2009-02-11 07:02:43 UTC (rev 3730) @@ -321,20 +321,20 @@ * Emit a function to match the ACL we have collected */ +/* + * XXX: this is semi-silly. We try really hard to not depend in the + * XXX: systems include files while compiling VCL, but we need to know + * XXX: the size of the sa_familiy member. + * XXX: FlexeLint complains about these antics, so isolate it in a + * XXX: separate function. + */ + +/*lint -save -e506 -e774 -e550 */ static void -vcc_acl_emit(const struct tokenlist *tl, const char *acln, int anon) +c_is_a_silly_language(const struct tokenlist *tl) { - struct acl_e *ae; - int depth, l, m, i; - unsigned at[VRT_ACL_MAXADDR + 1]; - const char *oc; struct sockaddr sa; - Fh(tl, 0, "\nstatic int\n"); - Fh(tl, 0, "match_acl_%s_%s(const struct sess *sp, const void *p)\n", - anon ? "anon" : "named", acln); - Fh(tl, 0, "{\n"); - Fh(tl, 0, "\tconst unsigned char *a;\n"); assert(sizeof (unsigned char) == 1); assert(sizeof (unsigned short) == 2); assert(sizeof (unsigned int) == 4); @@ -346,7 +346,24 @@ Fh(tl, 0, "\tunsigned int fam;\n"); else assert(0 == __LINE__); +} +/*lint -restore */ +static void +vcc_acl_emit(const struct tokenlist *tl, const char *acln, int anon) +{ + struct acl_e *ae; + int depth, l, m, i; + unsigned at[VRT_ACL_MAXADDR + 1]; + const char *oc; + + Fh(tl, 0, "\nstatic int\n"); + Fh(tl, 0, "match_acl_%s_%s(const struct sess *sp, const void *p)\n", + anon ? "anon" : "named", acln); + Fh(tl, 0, "{\n"); + Fh(tl, 0, "\tconst unsigned char *a;\n"); + c_is_a_silly_language(tl); + Fh(tl, 0, "\n"); Fh(tl, 0, "\ta = p;\n"); Fh(tl, 0, "\tVRT_memmove(&fam, a + %d, sizeof fam);\n", From tfheen at projects.linpro.no Wed Feb 11 07:06:03 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:06:03 +0100 (CET) Subject: r3731 - branches/2.0/varnish-cache/include Message-ID: <20090211070603.9C2D52844F@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:06:03 +0100 (Wed, 11 Feb 2009) New Revision: 3731 Modified: branches/2.0/varnish-cache/include/Makefile.am Log: Merge r3549: Add missing header file to tarball Fixes build failure Modified: branches/2.0/varnish-cache/include/Makefile.am =================================================================== --- branches/2.0/varnish-cache/include/Makefile.am 2009-02-11 07:02:43 UTC (rev 3730) +++ branches/2.0/varnish-cache/include/Makefile.am 2009-02-11 07:06:03 UTC (rev 3731) @@ -26,6 +26,7 @@ libvarnish.h \ libvcl.h \ miniobj.h \ + purge_vars.h \ vsha256.h \ vqueue.h \ vpf.h \ From tfheen at projects.linpro.no Wed Feb 11 07:13:12 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:13:12 +0100 (CET) Subject: r3732 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090211071312.721912844F@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:13:12 +0100 (Wed, 11 Feb 2009) New Revision: 3732 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c branches/2.0/varnish-cache/bin/varnishd/cache_hash.c branches/2.0/varnish-cache/bin/varnishd/cache_http.c branches/2.0/varnish-cache/bin/varnishd/flint.lnt branches/2.0/varnish-cache/bin/varnishd/mgt.h branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c branches/2.0/varnish-cache/bin/varnishd/rfc2616.c Log: Merge r3550: More FlexeLint silencing. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-11 07:06:03 UTC (rev 3731) +++ branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-11 07:13:12 UTC (rev 3732) @@ -184,7 +184,7 @@ assert(o->entered != 0 && !isnan(o->entered)); oe->lru_stamp = o->entered; - update_object_when(o); + (void)update_object_when(o); Lck_Lock(&exp_mtx); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); @@ -332,7 +332,7 @@ WSL(&ww, SLT_Debug, 0, "Attempt Prefetch %u", o->xid); } - update_object_when(o); + (void)update_object_when(o); Lck_Lock(&exp_mtx); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-11 07:06:03 UTC (rev 3731) +++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-11 07:13:12 UTC (rev 3732) @@ -351,7 +351,7 @@ TCP_blocking(vc->fd); /* XXX: we should timeout instead */ WRW_Reserve(w, &vc->fd); - http_Write(w, hp, 0); /* XXX: stats ? */ + (void)http_Write(w, hp, 0); /* XXX: stats ? */ /* Deal with any message-body the request might have */ i = FetchReqBody(sp); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-11 07:06:03 UTC (rev 3731) +++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-11 07:13:12 UTC (rev 3732) @@ -228,7 +228,6 @@ HSH_Lookup(struct sess *sp) { struct worker *w; - struct http *h; struct objhead *oh; struct object *o, *busy_o, *grace_o; @@ -237,7 +236,6 @@ CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC); AN(hash); w = sp->wrk; - h = sp->http; HSH_Prealloc(sp); SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); Modified: branches/2.0/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-11 07:06:03 UTC (rev 3731) +++ branches/2.0/varnish-cache/bin/varnishd/cache_http.c 2009-02-11 07:13:12 UTC (rev 3732) @@ -796,8 +796,8 @@ if (http_IsHdr(&hp->hd[u], hdr)) continue; if (v != u) { - memcpy(&hp->hd[v], &hp->hd[u], sizeof hp->hd[v]); - memcpy(&hp->hdf[v], &hp->hdf[u], sizeof hp->hdf[v]); + memcpy(&hp->hd[v], &hp->hd[u], sizeof *hp->hd); + memcpy(&hp->hdf[v], &hp->hdf[u], sizeof *hp->hdf); } v++; } Modified: branches/2.0/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-11 07:06:03 UTC (rev 3731) +++ branches/2.0/varnish-cache/bin/varnishd/flint.lnt 2009-02-11 07:13:12 UTC (rev 3732) @@ -7,6 +7,7 @@ -e459 // unlocked access from func-ptr -e454 // mutex not released (...ReleaseLocked) -e457 // unprotected access +-e777 // float equality comparison -esym(458, lbv_assert) // unlocked access -esym(458, params) // unlocked access @@ -56,6 +57,8 @@ -emacro(702, WEXITSTATUS) // signed shift right -efunc(525, VCC_Return_Name) // Negative indent + + // -header(../../config.h) // Fix strchr() semtics, it can only return NULL if arg2 != 0 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt.h 2009-02-11 07:06:03 UTC (rev 3731) +++ branches/2.0/varnish-cache/bin/varnishd/mgt.h 2009-02-11 07:13:12 UTC (rev 3732) @@ -49,7 +49,7 @@ int mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...); void mgt_cli_start_child(int fdi, int fdo); void mgt_cli_stop_child(void); -int mgt_cli_telnet(int dflag, const char *T_arg); +void mgt_cli_telnet(int dflag, const char *T_arg); /* mgt_param.c */ void MCF_ParamSync(void); Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-11 07:06:03 UTC (rev 3731) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-11 07:13:12 UTC (rev 3732) @@ -454,7 +454,7 @@ return (0); } -int +void mgt_cli_telnet(int dflag, const char *T_arg) { struct vss_addr **ta; @@ -494,5 +494,4 @@ } free(addr); free(port); - return (0); } Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-11 07:06:03 UTC (rev 3731) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_vcc.c 2009-02-11 07:13:12 UTC (rev 3732) @@ -263,7 +263,7 @@ static char * mgt_VccCompile(struct vsb **sb, const char *b, int C_flag) { - char *vf = NULL; + char *vf; *sb = vsb_newauto(); XXXAN(*sb); Modified: branches/2.0/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/rfc2616.c 2009-02-11 07:06:03 UTC (rev 3731) +++ branches/2.0/varnish-cache/bin/varnishd/rfc2616.c 2009-02-11 07:13:12 UTC (rev 3732) @@ -145,7 +145,7 @@ * derive a relative time from the two headers. * (the negative ttl case is caught above) */ - ttl = (h_expires - h_date); + ttl = (int)(h_expires - h_date); } while (0); From tfheen at projects.linpro.no Wed Feb 11 07:17:45 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:17:45 +0100 (CET) Subject: r3733 - branches/2.0/varnish-cache/lib/libvarnish Message-ID: <20090211071745.EEC451F74CE@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:17:45 +0100 (Wed, 11 Feb 2009) New Revision: 3733 Modified: branches/2.0/varnish-cache/lib/libvarnish/vsha256.c Log: Merge r3564: Move mybe{32,64}enc definitions outside of ifdef so we work on 64 bit BE platforms too. Modified: branches/2.0/varnish-cache/lib/libvarnish/vsha256.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-11 07:13:12 UTC (rev 3732) +++ branches/2.0/varnish-cache/lib/libvarnish/vsha256.c 2009-02-11 07:17:45 UTC (rev 3733) @@ -45,6 +45,26 @@ #include "libvarnish.h" #include "vsha256.h" +static __inline void +mybe32enc(void *pp, uint32_t u) +{ + unsigned char *p = (unsigned char *)pp; + + p[0] = (u >> 24) & 0xff; + p[1] = (u >> 16) & 0xff; + p[2] = (u >> 8) & 0xff; + p[3] = u & 0xff; +} + +static __inline void +mybe64enc(void *pp, uint64_t u) +{ + unsigned char *p = (unsigned char *)pp; + + mybe32enc(p, u >> 32); + mybe32enc(p + 4, u & 0xffffffff); +} + #if defined(VBYTE_ORDER) && VBYTE_ORDER == VBIG_ENDIAN /* Copy a vector of big-endian uint32_t into a vector of bytes */ @@ -65,26 +85,6 @@ return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); } -static __inline void -mybe32enc(void *pp, uint32_t u) -{ - unsigned char *p = (unsigned char *)pp; - - p[0] = (u >> 24) & 0xff; - p[1] = (u >> 16) & 0xff; - p[2] = (u >> 8) & 0xff; - p[3] = u & 0xff; -} - -static __inline void -mybe64enc(void *pp, uint64_t u) -{ - unsigned char *p = (unsigned char *)pp; - - mybe32enc(p, u >> 32); - mybe32enc(p + 4, u & 0xffffffff); -} - /* * Encode a length len/4 vector of (uint32_t) into a length len vector of * (unsigned char) in big-endian form. Assumes len is a multiple of 4. From tfheen at projects.linpro.no Wed Feb 11 07:21:07 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:21:07 +0100 (CET) Subject: r3734 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090211072107.6E4EA1F74D1@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:21:07 +0100 (Wed, 11 Feb 2009) New Revision: 3734 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c Log: Merge r3565: Close a race where VCL tries to modify the obj.ttl at the same moment the grim reaper has taken the object off the binheap to inspect it. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-11 07:17:45 UTC (rev 3733) +++ branches/2.0/varnish-cache/bin/varnishd/cache_expire.c 2009-02-11 07:21:07 UTC (rev 3734) @@ -143,6 +143,7 @@ CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oe = o->objexp; CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); + Lck_AssertHeld(&exp_mtx); if (o->prefetch < 0.0) { when = o->ttl + o->prefetch; @@ -184,8 +185,9 @@ assert(o->entered != 0 && !isnan(o->entered)); oe->lru_stamp = o->entered; + Lck_Lock(&exp_mtx); + assert(oe->timer_idx == BINHEAP_NOIDX); (void)update_object_when(o); - Lck_Lock(&exp_mtx); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); VTAILQ_INSERT_TAIL(&lru, oe, list); @@ -245,7 +247,11 @@ return; CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); Lck_Lock(&exp_mtx); - if (update_object_when(o)) { + /* + * The hang-man might have this object of the binheap while + * tending to a timer. If so, we do not muck with it here. + */ + if (oe->timer_idx != BINHEAP_NOIDX && update_object_when(o)) { /* * XXX: this could possibly be optimized by shuffling * XXX: up or down, but that leaves some very nasty @@ -332,8 +338,9 @@ WSL(&ww, SLT_Debug, 0, "Attempt Prefetch %u", o->xid); } + Lck_Lock(&exp_mtx); + assert(oe->timer_idx == BINHEAP_NOIDX); (void)update_object_when(o); - Lck_Lock(&exp_mtx); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); Lck_Unlock(&exp_mtx); @@ -347,6 +354,7 @@ WSL(&ww, SLT_ExpKill, 0, "%u %d", o->xid, (int)(o->ttl - t)); Lck_Lock(&exp_mtx); + assert(oe->timer_idx == BINHEAP_NOIDX); VTAILQ_REMOVE(&lru, o->objexp, list); oe->on_lru = 0; VSL_stats->n_expired++; From tfheen at projects.linpro.no Wed Feb 11 07:25:54 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:25:54 +0100 (CET) Subject: r3735 - in branches/2.0/varnish-cache: bin/varnishd bin/varnishtest/tests include Message-ID: <20090211072554.A271B2844F@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:25:54 +0100 (Wed, 11 Feb 2009) New Revision: 3735 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/e00013.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc branches/2.0/varnish-cache/include/stat_field.h Log: Merge r3566: Add an (unlocked) counter for number of ESI objects we have parsed. Add two test-cases for objects we should not esi parse. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 07:21:07 UTC (rev 3734) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 07:25:54 UTC (rev 3735) @@ -630,6 +630,59 @@ return (p); } +/*-------------------------------------------------------------------- + * See if this looks like XML: first non-white char must be '<' + */ + +static int +looks_like_xml(struct object *obj) { + struct storage *st; + unsigned u; + + VTAILQ_FOREACH(st, &obj->store, list) { + AN(st); + for (u = 0; u < st->len; u++) { + if (isspace(st->ptr[u])) + continue; + if (st->ptr[u] == '<') + return (1); + else + return (0); + } + } + return (0); +} + +/*-------------------------------------------------------------------- + * A quick stroll through the object, to find out if it contains any + * esi sequences at all. + */ + +static int +contain_esi(struct object *obj) { + struct storage *st; + unsigned u; + const char *r; + static const char *wanted = "store, list) { + AN(st); + for (u = 0; u < st->len; u++) { + if (st->ptr[u] != *r) { + r = wanted; + continue; + } + if (*++r == '\0') + return (1); + } + } + return (0); +} + /*--------------------------------------------------------------------*/ void @@ -642,6 +695,8 @@ char *p, *q; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); + assert(sp->obj->busy); if (sp->cur_method != VCL_MET_FETCH) { /* XXX: we should catch this at compile time */ @@ -653,28 +708,25 @@ if (VTAILQ_EMPTY(&sp->obj->store)) return; - 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; + if (!looks_like_xml(sp->obj)) { WSP(sp, SLT_ESI_xmlerror, - "No ESI processing, " - "binary object: 0x%02x at pos %u.", - st->ptr[u], u); + "No ESI processing, first char not '<'"); return; } } + /* + * Do a fast check to see if there is any 'obj)) + return; + + VSL_stats->esi_parse++; /* XXX: only if GET ? */ ew = eww; memset(eww, 0, sizeof eww); Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-11 07:21:07 UTC (rev 3734) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-11 07:25:54 UTC (rev 3735) @@ -22,8 +22,10 @@ sub vcl_fetch { esi; } -} -start -cli "debug.fragfetch 32" +} -start +varnish v1 -cliok "debug.fragfetch 32" + client c1 { txreq -url /foo/bar -hdr "Host: froboz" rxresp Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/e00013.vtc (from rev 3566, trunk/varnish-cache/bin/varnishtest/tests/e00013.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00013.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00013.vtc 2009-02-11 07:25:54 UTC (rev 3735) @@ -0,0 +1,25 @@ +# $Id$ + +test "All white-space object, in multiple storage segments" + +server s1 { + rxreq + expect req.url == "/foo" + txresp -hdr "Connection: close" + send { } +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + esi; + } +} -start + +varnish v1 -cliok "debug.fragfetch 4" + +client c1 { + txreq -url /foo + rxresp +} -run + +varnish v1 -expect esi_parse == 0 Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc (from rev 3566, trunk/varnish-cache/bin/varnishtest/tests/e00014.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc 2009-02-11 07:25:54 UTC (rev 3735) @@ -0,0 +1,25 @@ +# $Id$ + +test "Check } +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + esi; + } +} -start + +varnish v1 -cliok "debug.fragfetch 4" + +client c1 { + txreq -url /foo + rxresp +} -run + +varnish v1 -expect esi_parse == 0 Modified: branches/2.0/varnish-cache/include/stat_field.h =================================================================== --- branches/2.0/varnish-cache/include/stat_field.h 2009-02-11 07:21:07 UTC (rev 3734) +++ branches/2.0/varnish-cache/include/stat_field.h 2009-02-11 07:25:54 UTC (rev 3735) @@ -130,3 +130,5 @@ MAC_STAT(hcb_nolock, uint64_t, 'a', "HCB Lookups without lock") MAC_STAT(hcb_lock, uint64_t, 'a', "HCB Lookups with lock") MAC_STAT(hcb_insert, uint64_t, 'a', "HCB Inserts") + +MAC_STAT(esi_parse, uint64_t, 'a', "Objects ESI parsed (unlock)") From tfheen at projects.linpro.no Wed Feb 11 07:29:12 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:29:12 +0100 (CET) Subject: r3736 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090211072912.8F9E22844F@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:29:12 +0100 (Wed, 11 Feb 2009) New Revision: 3736 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Merge r3567: The esi detector should also spot esi comments. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 07:25:54 UTC (rev 3735) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 07:29:12 UTC (rev 3736) @@ -615,6 +615,8 @@ { char *p; +printf("{%.*s}\n", Tlen(ew->t), ew->t.b); +usleep(100000); if (params->esi_syntax & 0x4) VSL(SLT_Debug, ew->sp->fd, "Parse: %d <%.*s>", Tlen(ew->t), Tlen(ew->t), ew->t.b); @@ -662,22 +664,26 @@ contain_esi(struct object *obj) { struct storage *st; unsigned u; - const char *r; + const char *r, *r2; static const char *wanted = "store, list) { AN(st); for (u = 0; u < st->len; u++) { if (st->ptr[u] != *r) { r = wanted; - continue; - } - if (*++r == '\0') + } else if (*++r == '\0') return (1); + if (st->ptr[u] != *r2) { + r2 = wanted2; + } else if (*++r2 == '\0') + return (1); } } return (0); From tfheen at projects.linpro.no Wed Feb 11 07:32:25 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:32:25 +0100 (CET) Subject: r3737 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090211073225.210DC2844F@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:32:24 +0100 (Wed, 11 Feb 2009) New Revision: 3737 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Merge r3568: Opps, debugging hack leaked in. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 07:29:12 UTC (rev 3736) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 07:32:24 UTC (rev 3737) @@ -615,8 +615,6 @@ { char *p; -printf("{%.*s}\n", Tlen(ew->t), ew->t.b); -usleep(100000); if (params->esi_syntax & 0x4) VSL(SLT_Debug, ew->sp->fd, "Parse: %d <%.*s>", Tlen(ew->t), Tlen(ew->t), ew->t.b); From tfheen at projects.linpro.no Wed Feb 11 07:36:03 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:36:03 +0100 (CET) Subject: r3738 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090211073603.868142844F@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:36:03 +0100 (Wed, 11 Feb 2009) New Revision: 3738 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c Log: Merge r3569: Mark that we do limited segment size fetches for debugging Modified: branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-11 07:32:24 UTC (rev 3737) +++ branches/2.0/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-11 07:36:03 UTC (rev 3738) @@ -221,6 +221,9 @@ struct storage *st; unsigned v; + if (fetchfrag > 0) + WSL(sp->wrk, SLT_Debug, sp->fd, + "Fetch %d byte segments:", fetchfrag); p = NULL; v = 0; st = NULL; From tfheen at projects.linpro.no Wed Feb 11 07:41:41 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:41:41 +0100 (CET) Subject: r3739 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090211074142.011D597C5D@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:41:41 +0100 (Wed, 11 Feb 2009) New Revision: 3739 Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c branches/2.0/varnish-cache/bin/varnishd/shmlog.c Log: Merge r3570: Make it possible (at great performance loss) to force straight time sequencing of shmlog records for debugging purposes. Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-11 07:36:03 UTC (rev 3738) +++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-11 07:41:41 UTC (rev 3739) @@ -745,6 +745,7 @@ #ifdef HAVE_ABORT2 " 0x00008000 - panic to abort2().\n" #endif + " 0x00010000 - synchronize shmlog.\n" "Use 0x notation and do the bitor in your head :-)\n", 0, "0", "bitmap" }, Modified: branches/2.0/varnish-cache/bin/varnishd/shmlog.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/shmlog.c 2009-02-11 07:36:03 UTC (rev 3738) +++ branches/2.0/varnish-cache/bin/varnishd/shmlog.c 2009-02-11 07:41:41 UTC (rev 3739) @@ -231,6 +231,8 @@ memcpy(p + SHMLOG_DATA, t.b, l); vsl_hdr(tag, p, l, id); w->wlr++; + if (params->diag_bitmap & 0x10000) + WSL_Flush(w, 0); } /*--------------------------------------------------------------------*/ @@ -269,6 +271,8 @@ w->wlr++; } va_end(ap); + if (params->diag_bitmap & 0x10000) + WSL_Flush(w, 0); } /*--------------------------------------------------------------------*/ From tfheen at projects.linpro.no Wed Feb 11 07:46:11 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:46:11 +0100 (CET) Subject: r3740 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090211074611.A45FA97C5D@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:46:11 +0100 (Wed, 11 Feb 2009) New Revision: 3740 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc Log: Merge r3571: Update this test to actually test what it should. I suspect a white-space cleanup got it at some point. Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-11 07:41:41 UTC (rev 3739) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-11 07:46:11 UTC (rev 3740) @@ -2,17 +2,30 @@ test "ESI spanning storage bits" +# NB! The layout of the body in the response is very carefully +# NB! tuned to give the desired code coverage. +# NB! It should look like this in the varnishlog: +# NB! 7 Debug c "Fetch 32 byte segments:" +# NB! 7 Debug c "%0a%09%09filler%0a%09%09This is before" +# NB! 7 Debug c " the test%0a%09%09%0a%09%09filler%0a%09%09This is a test: Unseen Un" +# NB! 7 Debug c "iversity%0a%09%09Department of cruel a" +# NB! 7 Debug c "nd unjust geography%0a%09%09%0a%09%09This is a test: Hello worl" +# NB! 7 Debug c "d%0a%09" server s1 { rxreq expect req.url == "/foo/bar" txresp -hdr "Connection: close" send { - + filler This is before the test - - + + filler This is a test: Unseen University + Department of cruel and unjust geography This is a test: Hello world } @@ -30,6 +43,7 @@ txreq -url /foo/bar -hdr "Host: froboz" rxresp expect resp.status == 200 + expect resp.bodylen == 120 } client c1 -run From tfheen at projects.linpro.no Wed Feb 11 07:49:21 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:49:21 +0100 (CET) Subject: r3741 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090211074921.6A1A497C5D@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:49:21 +0100 (Wed, 11 Feb 2009) New Revision: 3741 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00001.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00002.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00003.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00004.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00005.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00006.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00009.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc Log: Merge r3572: Add bodylen expects to the ESI test cases Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00001.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00001.vtc 2009-02-11 07:46:11 UTC (rev 3740) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00001.vtc 2009-02-11 07:49:21 UTC (rev 3741) @@ -17,12 +17,13 @@ sub vcl_fetch { esi; } -} -start +} -start -cliok "param.set esi_syntax 4" client c1 { txreq rxresp expect resp.status == 200 + expect resp.bodylen == 35 } client c1 -run Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00002.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00002.vtc 2009-02-11 07:46:11 UTC (rev 3740) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00002.vtc 2009-02-11 07:49:21 UTC (rev 3741) @@ -24,6 +24,7 @@ txreq rxresp expect resp.status == 200 + expect resp.bodylen == 35 } client c1 -run Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00003.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00003.vtc 2009-02-11 07:46:11 UTC (rev 3740) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00003.vtc 2009-02-11 07:49:21 UTC (rev 3741) @@ -27,6 +27,7 @@ client c1 { txreq rxresp + expect resp.bodylen == 65 expect resp.status == 200 } Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00004.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00004.vtc 2009-02-11 07:46:11 UTC (rev 3740) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00004.vtc 2009-02-11 07:49:21 UTC (rev 3741) @@ -28,6 +28,7 @@ txreq rxresp expect resp.status == 200 + expect resp.bodylen == 67 } client c1 -run Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00005.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00005.vtc 2009-02-11 07:46:11 UTC (rev 3740) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00005.vtc 2009-02-11 07:49:21 UTC (rev 3741) @@ -29,6 +29,7 @@ txreq -url /foo/bar rxresp expect resp.status == 200 + expect resp.bodylen == 67 } client c1 -run Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00006.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00006.vtc 2009-02-11 07:46:11 UTC (rev 3740) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00006.vtc 2009-02-11 07:49:21 UTC (rev 3741) @@ -40,6 +40,7 @@ txreq -url /foo/bar -hdr "Host: froboz" rxresp expect resp.status == 200 + expect resp.bodylen == 67 } client c1 -run Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-11 07:46:11 UTC (rev 3740) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-11 07:49:21 UTC (rev 3741) @@ -68,6 +68,7 @@ txreq rxresp expect resp.status == 200 + expect resp.bodylen == 231 } client c1 -run Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00009.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00009.vtc 2009-02-11 07:46:11 UTC (rev 3740) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00009.vtc 2009-02-11 07:49:21 UTC (rev 3741) @@ -31,6 +31,7 @@ txreq rxresp expect resp.status == 200 + expect resp.bodylen == 72 expect resp.http.content-length == 72 } -run @@ -40,5 +41,6 @@ txreq -url bar rxresp expect resp.status == 200 + expect resp.bodylen == 37 expect resp.http.transfer-encoding == "chunked" } -run Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc 2009-02-11 07:46:11 UTC (rev 3740) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc 2009-02-11 07:49:21 UTC (rev 3741) @@ -20,6 +20,7 @@ client c1 { txreq -url /foo rxresp + expect resp.bodylen == 49 } -run varnish v1 -expect esi_parse == 0 From tfheen at projects.linpro.no Wed Feb 11 07:53:47 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:53:47 +0100 (CET) Subject: r3742 - in branches/2.0/varnish-cache: bin/varnishd bin/varnishtest/tests include Message-ID: <20090211075347.7954A97C71@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:53:47 +0100 (Wed, 11 Feb 2009) New Revision: 3742 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c branches/2.0/varnish-cache/bin/varnishtest/tests/e00000.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00001.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00002.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00003.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00004.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00005.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00006.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00009.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00010.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00011.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00012.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00013.vtc branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc branches/2.0/varnish-cache/include/stat_field.h Log: Merge r3573: Add a counter for esi parse errors and test it in all ESI related tests cases. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 07:53:47 UTC (rev 3742) @@ -95,6 +95,7 @@ char buf[256], *q; txt t; + VSL_stats->esi_errors++; if (i == 0) i = p - ew->t.b; if (i > 20) { Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00000.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00000.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00000.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -24,3 +24,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00001.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00001.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00001.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -27,3 +27,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00002.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00002.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00002.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -28,3 +28,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00003.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00003.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00003.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -32,3 +32,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00004.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00004.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00004.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -32,3 +32,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00005.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00005.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00005.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -33,3 +33,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00006.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00006.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00006.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -44,3 +44,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00007.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -47,3 +47,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -72,3 +72,4 @@ } client c1 -run +varnish v1 -expect esi_errors == 15 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00009.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00009.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00009.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -44,3 +44,4 @@ expect resp.bodylen == 37 expect resp.http.transfer-encoding == "chunked" } -run +varnish v1 -expect esi_errors == 1 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00010.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00010.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00010.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -25,3 +25,4 @@ expect resp.status == 200 expect resp.bodylen == 21 } -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00011.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00011.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00011.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -34,3 +34,4 @@ expect resp.status == 200 expect resp.bodylen == 31 } -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00012.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00012.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00012.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -44,3 +44,4 @@ expect resp.status == 200 expect resp.bodylen == 151 } -run +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00013.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00013.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00013.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -23,3 +23,4 @@ } -run varnish v1 -expect esi_parse == 0 +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00014.vtc 2009-02-11 07:53:47 UTC (rev 3742) @@ -24,3 +24,4 @@ } -run varnish v1 -expect esi_parse == 0 +varnish v1 -expect esi_errors == 0 Modified: branches/2.0/varnish-cache/include/stat_field.h =================================================================== --- branches/2.0/varnish-cache/include/stat_field.h 2009-02-11 07:49:21 UTC (rev 3741) +++ branches/2.0/varnish-cache/include/stat_field.h 2009-02-11 07:53:47 UTC (rev 3742) @@ -132,3 +132,4 @@ MAC_STAT(hcb_insert, uint64_t, 'a', "HCB Inserts") MAC_STAT(esi_parse, uint64_t, 'a', "Objects ESI parsed (unlock)") +MAC_STAT(esi_errors, uint64_t, 'a', "ESI parse errors (unlock)") From tfheen at projects.linpro.no Wed Feb 11 07:58:37 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 08:58:37 +0100 (CET) Subject: r3743 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090211075837.2EC4997C5D@projects.linpro.no> Author: tfheen Date: 2009-02-11 08:58:36 +0100 (Wed, 11 Feb 2009) New Revision: 3743 Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc Log: Merge r3574: Add line numbers to this test, so we can see where it croaks, when it does. Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-11 07:53:47 UTC (rev 3742) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/e00008.vtc 2009-02-11 07:58:36 UTC (rev 3743) @@ -5,42 +5,42 @@ server s1 { rxreq txresp -body { - - Before include - - After include - - - - foo - - - - - - - - - - bar - - - - - - 1 + Before include 2 + 3 + After include 4 + 5 + 6 + 7 + foo 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + bar 18 + 19 + 20 + 21 + 22 + 23 + - - - - - - - - 33 + 34 } rxreq expect req.url == "/body" @@ -62,14 +62,18 @@ sub vcl_fetch { esi; } -} -start +} -start +varnish v1 -cliok "param.set esi_syntax 6" + +varnish v1 -cliok "param.set diag_bitmap 0x10000" + client c1 { txreq rxresp expect resp.status == 200 - expect resp.bodylen == 231 + expect resp.bodylen == 385 } client c1 -run -varnish v1 -expect esi_errors == 15 +varnish v1 -expect esi_errors == 14 From tfheen at projects.linpro.no Wed Feb 11 08:02:31 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 09:02:31 +0100 (CET) Subject: r3744 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090211080231.E00E297C5D@projects.linpro.no> Author: tfheen Date: 2009-02-11 09:02:31 +0100 (Wed, 11 Feb 2009) New Revision: 3744 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Merge r3575: Overhaul the ESI parser Overhaul the ESI parser in light of #433 and the prospect of future addition of features to the ESI code. The particular situation in #433 arises because a XML comment is not bounded in length, the same way as an element naturally is. This opens the window for trouble when large sections of XML is commented out for some reason or another. Bite the bullet and create a "storage-pointer" consisting of a pointer to a storage segment and a pointer into that segment. Add a main-loop which uses these pointers to walks over the entire object, looking for stuff we care about, and handle each appropriately. In addition to coping properly with the situation in #433, this code is also close to 100 lines shorter and has a more logical structure. The downside is that it is isn't quite as memory-access-alergic as the previous version. (I challenge anybody to measure the effect of this.) Fixes: #433 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 07:58:36 UTC (rev 3743) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-11 08:02:31 UTC (rev 3744) @@ -69,23 +69,83 @@ VTAILQ_HEAD(esibithead, esi_bit); +struct esi_ptr { + const char *p; + struct storage *st; +}; + struct esi_work { struct sess *sp; size_t off; + + struct esi_ptr s; + struct esi_ptr p; + + txt tag; + txt t; - txt o; - txt dst; struct esi_bit *eb; struct esi_bit *ebl; /* list of */ int neb; - int is_esi; int remflg; /* inside */ int incmt; /* inside comment */ - int incdata; /* inside */ }; /*-------------------------------------------------------------------- + * Move the parse-pointer forward. + */ + +static void +Nep(struct esi_ptr *ep) +{ + static const char * const finis = ""; + + if (ep->p == finis) + return; + ep->p++; + if (ep->p < (char*)ep->st->ptr + ep->st->len) + return; + ep->st = VTAILQ_NEXT(ep->st, list); + if (ep->st != NULL) { + ep->p = (char *)ep->st->ptr; + return; + } + ep->p = finis; + return; +} + +static void +N(struct esi_work *ew) +{ + + if (*ew->p.p != '\0') + ew->off++; + Nep(&ew->p); +} + +/*-------------------------------------------------------------------- + * Strcmp for objects pointers + */ + +static int +CMP(const struct esi_ptr *ep, const char *str) +{ + struct esi_ptr p2; + + for (p2 = *ep; *str == *p2.p; str++) + Nep(&p2); + return (*str); +} + + +/*-------------------------------------------------------------------- * Report a parsing error + * + * XXX: The "at xxx" count is usually the tail of the sequence. Since we + * XXX: wander over the storage in an oderly manner now, we could keep + * XXX: track of line+pos and record the beginning of the stuff that + * XXX: offends os in the central dispatch loop. + * XXX: This is left a an excercise for the reader. */ static void @@ -103,7 +163,7 @@ ellipsis = 1; } q = buf; - q += sprintf(buf, "at %zd: %s \"", ew->off + (p - ew->t.b), err); + q += sprintf(buf, "at %zu: %s \"", ew->off, err); while (i > 0) { if (*p >= ' ' && *p <= '~') { *q++ = *p; @@ -141,8 +201,8 @@ * Add ESI bit to object */ -static struct esi_bit * -esi_addbit(struct esi_work *ew) +static void +esi_addbit(struct esi_work *ew, const char *verbatim, unsigned len) { if (ew->neb == 0) { @@ -157,29 +217,41 @@ VTAILQ_INSERT_TAIL(&ew->sp->obj->esibits, ew->eb, list); - ew->eb->verbatim = ew->dst; - sprintf(ew->eb->chunk_length, "%x\r\n", Tlen(ew->dst)); - if (params->esi_syntax & 0x4) - VSL(SLT_Debug, ew->sp->fd, "AddBit: %d <%.*s>", - Tlen(ew->dst), Tlen(ew->dst), ew->dst.b); - return(ew->eb); + if (verbatim != NULL) { + ew->eb->verbatim.b = TRUST_ME(verbatim); + if (len > 0) + ew->eb->verbatim.e = TRUST_ME(verbatim + len); + sprintf(ew->eb->chunk_length, "%x\r\n", Tlen(ew->eb->verbatim)); + if (params->esi_syntax & 0x4) + VSL(SLT_Debug, ew->sp->fd, "AddBit: %d <%.*s>", + Tlen(ew->eb->verbatim), + Tlen(ew->eb->verbatim), + ew->eb->verbatim.b); + } else + ew->eb->verbatim.b = ew->eb->verbatim.e = (void*)ew->eb; } +/*--------------------------------------------------------------------*/ -/*-------------------------------------------------------------------- - * Add verbatim piece to output - */ - static void -esi_addverbatim(struct esi_work *ew) +esi_addpfx(struct esi_work *ew) { + const char *ep; - if (params->esi_syntax & 0x4) - VSL(SLT_Debug, ew->sp->fd, "AddVer: %d <%.*s>", - Tlen(ew->o), Tlen(ew->o), ew->o.b); - if (ew->o.b != ew->dst.e) - memmove(ew->dst.e, ew->o.b, Tlen(ew->o)); - ew->dst.e += Tlen(ew->o); + if (ew->remflg) { + /* In don't add anything */ + ew->s = ew->p; + return; + } + while (ew->s.st != ew->p.st) { + ep = (const char *)(ew->s.st->ptr + ew->s.st->len); + esi_addbit(ew, ew->s.p, ep - ew->s.p); + ew->s.p = ep; + Nep(&ew->s); + } + if (ew->s.st != NULL && ew->p.p != ew->s.p) + esi_addbit(ew, ew->s.p, ew->p.p - ew->s.p); + ew->s.p = ew->p.p; } /*-------------------------------------------------------------------- @@ -274,17 +346,20 @@ */ static void -esi_addinclude(struct esi_work *ew, txt t) +esi_handle_include(struct esi_work *ew) { struct esi_bit *eb; char *p, *q; + txt t = ew->tag; txt tag; txt val; unsigned u, v; struct ws *ws; + if (ew->eb == NULL || ew->eb->include.b != NULL) + esi_addbit(ew, NULL, 0); + eb = ew->eb; VSL(SLT_Debug, ew->sp->fd, "Incl \"%.*s\"", t.e - t.b, t.b); - eb = esi_addbit(ew); while (esi_attrib(ew, &t, &tag, &val) == 1) { if (params->esi_syntax & 0x4) VSL(SLT_Debug, ew->sp->fd, "<%.*s> -> <%.*s>", @@ -353,290 +428,11 @@ } /*-------------------------------------------------------------------- - * Zoom over a piece of object and dike out all releveant esi: pieces. - * The entire txt may not be processed because an interesting part - * could possibly span into the next chunk of storage. - * Return value: number of bytes processed. - */ - -static char * -esi_parse2(struct esi_work *ew) -{ - char *p, *q, *r; - txt t; - int celem; /* closing element */ - int i; - - t = ew->t; - ew->dst.b = t.b; - ew->dst.e = t.b; - ew->o.b = t.b; - ew->o.e = t.b; - for (p = t.b; p < t.e; ) { - assert(p >= t.b); - assert(p < t.e); - if (ew->incdata) { - /* - * We are inside an . - */ - if (*p != ']') { - p++; - } else { - if (p + 2 >= t.e) - return (p); - if (!memcmp(p, "]]>", 3)) { - ew->incdata = 0; - p += 3; - } else - p++; - } - continue; - } - if (ew->incmt && *p == '-') { - /* - * We are inside an when we see it. - */ - if (p + 2 >= t.e) - return (p); - if (!memcmp(p, "-->", 3)) { - ew->incmt = 0; - ew->o.e = p; - esi_addverbatim(ew); - p += 3; - ew->o.b = p; - } else - p++; - continue; - } - - if (*p != '<') { - /* nothing happens until next element or comment */ - p++; - continue; - } - - i = t.e - p; - - if (i < 2) - return (p); - - if (ew->remflg == 0 && !memcmp(p, " - * at least 10 char, but we only test on the - * first seven because the tail is handled - * by the ew->incmt flag. - */ - ew->is_esi++; - if (i < 7) - return (p); - - ew->o.e = p; - esi_addverbatim(ew); - - p += 7; - ew->o.b = p; - ew->incmt = 1; - continue; - } - - if (!memcmp(p, " at least 7 char - */ - if (i < 7) - return (p); - for (q = p + 4; ; q++) { - if (q + 2 >= t.e) - return (p); - if (!memcmp(q, "-->", 3)) - break; - } - p = q + 3; - continue; - } - - if (!memcmp(p, " 9 ? 9 : i)) { - /* - * cdata incdata = 1; - p += 9; - continue; - } - - /* Ignore non esi elements, if so instructed */ - if ((params->esi_syntax & 0x02)) { - if (memcmp(p, " 5 ? 5 : i) && - memcmp(p, " 6 ? 6 : i)) { - p += 1; - continue; - } - if (i < 6) - return (p); - } - - /* Find end of this element */ - for (q = p + 1; q < t.e && *q != '>'; q++) - continue; - if (q >= t.e || *q != '>') - return (p); - - /* Opening/empty or closing element ? */ - if (p[1] == '/') { - celem = 1; - r = p + 2; - if (q[-1] == '/') { - esi_error(ew, p, 1 + q - p, - "XML 1.0 empty and closing element"); - } - } else { - celem = 0; - r = p + 1; - } - - if (params->esi_syntax & 0x4) - VSL(SLT_Debug, ew->sp->fd, "Element: clos=%d [%.*s]", - celem, q - r, r); - - if (r + 9 < q && !memcmp(r, "esi:remove", 10)) { - - ew->is_esi++; - - if (celem != ew->remflg) { - /* - * ESI 1.0 violation, ignore element - */ - esi_error(ew, p, 1 + q - p, ew->remflg ? - "ESI 1.0 forbids nested esi:remove" - : "ESI 1.0 esi:remove not opened"); - - if (!ew->remflg) { - ew->o.e = p; - esi_addverbatim(ew); - } - } else if (!celem && q[-1] == '/') { - /* empty element */ - ew->o.e = p; - esi_addverbatim(ew); - } else if (!celem) { - /* open element */ - ew->o.e = p; - esi_addverbatim(ew); - ew->remflg = !celem; - } else { - /* close element */ - ew->remflg = !celem; - } - p = q + 1; - ew->o.b = p; - continue; - } - - if (ew->remflg && r + 3 < q && !memcmp(r, "esi:", 4)) { - /* - * ESI 1.0 violation, no esi: elements in esi:remove - */ - esi_error(ew, p, 1 + q - p, - "ESI 1.0 forbids esi: elements inside esi:remove"); - p = q + 1; - continue; - } - ew->is_esi++; - - if (r + 10 < q && !memcmp(r, "esi:comment", 11)) { - - ew->o.e = p; - esi_addverbatim(ew); - - if (celem == 1) { - esi_error(ew, p, 1 + q - p, - "ESI 1.0 closing esi:comment illegal"); - } else if (q[-1] != '/') { - esi_error(ew, p, 1 + q - p, - "ESI 1.0 wants empty esi:comment"); - } - p = q + 1; - ew->o.b = p; - continue; - } - if (r + 10 < q && !memcmp(r, "esi:include", 11)) { - - ew->o.e = p; - esi_addverbatim(ew); - - if (celem == 0) { - ew->o.b = r + 11; - if (q[-1] != '/') { - esi_error(ew, p, 1 + q - p, - "ESI 1.0 wants empty esi:include"); - ew->o.e = q; - } else { - ew->o.e = q - 1; - } - esi_addinclude(ew, ew->o); - ew->dst.b = q + 1; - ew->dst.e = q + 1; - } else { - esi_error(ew, p, 1 + q - p, - "ESI 1.0 closing esi:include illegal"); - } - p = q + 1; - ew->o.b = p; - continue; - } - - if (r + 3 < q && !memcmp(r, "esi:", 4)) { - /* - * Unimplemented ESI element, ignore - */ - esi_error(ew, p, 1 + q - p, - "ESI 1.0 unimplemented element"); - ew->o.e = p; - esi_addverbatim(ew); - p = q + 1; - ew->o.b = p; - continue; - } - - /* Not an element we care about */ - assert(q < t.e); - p = q + 1; - } - assert(p == t.e); - return (p); -} - -static char * -esi_parse(struct esi_work *ew) -{ - char *p; - - if (params->esi_syntax & 0x4) - VSL(SLT_Debug, ew->sp->fd, "Parse: %d <%.*s>", - Tlen(ew->t), Tlen(ew->t), ew->t.b); - p = esi_parse2(ew); - assert(ew->o.b >= ew->t.b); - assert(ew->o.e <= ew->t.e); - ew->o.e = p; - if (Tlen(ew->o) && !ew->remflg) - esi_addverbatim(ew); - if (Tlen(ew->dst)) - esi_addbit(ew); - ew->off += (p - ew->t.b); - return (p); -} - -/*-------------------------------------------------------------------- * See if this looks like XML: first non-white char must be '<' */ static int -looks_like_xml(struct object *obj) { +looks_like_xml(const struct object *obj) { struct storage *st; unsigned u; @@ -660,12 +456,12 @@ */ static int -contain_esi(struct object *obj) { +contain_esi(const struct object *obj) { struct storage *st; unsigned u; const char *r, *r2; - static const char *wanted = "incmt); + ew->incmt = 1; + ew->s.p = ew->p.p; +} + +/*--------------------------------------------------------------------*/ + +static void +parse_comment(struct esi_work *ew) +{ + + do { + N(ew); + if (*ew->p.p == '-' && !CMP(&ew->p, "-->")) { + N(ew); + N(ew); + N(ew); + break; + } + } while (*ew->p.p != '\0'); +} + +/*--------------------------------------------------------------------*/ + +static void +parse_cdata(struct esi_work *ew) +{ + + esi_addpfx(ew); + + do { + N(ew); + if (*ew->p.p == ']' && !CMP(&ew->p, "]]>")) { + N(ew); + N(ew); + N(ew); + break; + } + } while (*ew->p.p != '\0'); +} + +/*--------------------------------------------------------------------*/ + +static void +parse_esi_tag(struct esi_work *ew, int closing) +{ + int l, ll, empty; + struct esi_ptr px; + char *q; + + esi_addpfx(ew); + + do + N(ew); + while (*ew->p.p != '>' && *ew->p.p != '\0'); + if (*ew->p.p == '\0') { + esi_addpfx(ew); + esi_error(ew, ew->s.p, 0, + "XML 1.0 incomplete language element"); + return; + } + N(ew); + + if (ew->p.st == ew->s.st) { + ew->tag.b = TRUST_ME(ew->s.p); + ew->tag.e = TRUST_ME(ew->p.p); + } else { + /* + * The element is spread over more than one storage + * segment, pull it together in the object workspace + * XXX: Ideally, we should only pull together the bits + * XXX: we need, like the filename. + */ + ew->tag.b = ew->sp->obj->ws_o->f; + ew->tag.e = ew->tag.b + WS_Reserve(ew->sp->obj->ws_o, 0); + px = ew->s; + q = ew->tag.b; + while (px.p != ew->p.p) { + xxxassert(q < ew->tag.e); + *q++ = *px.p; + Nep(&px); + } + ew->tag.e = q; + WS_Release(ew->sp->obj->ws_o, Tlen(ew->tag)); + } + ll = Tlen(ew->tag); + ew->tag.b++; + ew->tag.e--; + empty = (ew->tag.e[-1] == '/') ? 1 : 0; + if (empty) + ew->tag.e--; + + if (empty && closing) + esi_error(ew, ew->s.p, ll, + "XML 1.0 empty and closing element"); + + ew->tag.b += 4 + (closing ? 1 : 0); + l = Tlen(ew->tag); + VSL(SLT_Debug, ew->sp->fd, + "tag {%.*s} %d %d %d", l, ew->tag.b, ew->remflg, empty, closing); + if (l >= 6 && !memcmp(ew->tag.b, "remove", 6)) { + if (empty) { + /* XXX ?? */ + } else if (closing) { + if (!ew->remflg) + esi_error(ew, ew->s.p, ll, + "ESI 1.0 esi:remove not opened"); + ew->remflg = 0; + } else { + if (ew->remflg) + esi_error(ew, ew->s.p, ll, + "ESI 1.0 forbids nested esi:remove"); + ew->remflg = 1; + } + } else if (ew->remflg) { + esi_error(ew, ew->s.p, ll, + "ESI 1.0 forbids esi: elements inside esi:remove"); + } else if (l >= 7 && !memcmp(ew->tag.b, "comment", 7)) { + if (closing) + esi_error(ew, ew->s.p, ll, + "ESI 1.0 closing esi:comment illegal"); + else if (!empty) + esi_error(ew, ew->s.p, ll, + "ESI 1.0 wants empty esi:comment"); + } else if (l >= 7 && !memcmp(ew->tag.b, "include", 7)) { + if (closing) { + esi_error(ew, ew->s.p, ll, + "ESI 1.0 closing esi:include illegal"); + } else if (!empty) { + esi_error(ew, ew->s.p, ll, + "ESI 1.0 wants empty esi:include"); + } + ew->tag.b += 7; + esi_handle_include(ew); + } else { + esi_error(ew, ew->s.p, ll, + "ESI 1.0 unimplemented element"); + } + ew->s = ew->p; +} + +/*--------------------------------------------------------------------*/ + void VRT_ESI(struct sess *sp) { - struct storage *st, *st2; struct esi_work *ew, eww[1]; - txt t; - unsigned u; - char *p, *q; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); @@ -738,87 +680,55 @@ ew->sp = sp; ew->off = 1; - p = NULL; - VTAILQ_FOREACH(st, &sp->obj->store, list) { - if (p != NULL) { - assert ((void*)p > (void *)st->ptr); - assert ((void*)p <= (void *)(st->ptr + st->len)); - if (p == (void*)(st->ptr + st->len)) - break; - ew->t.b = p; - p = NULL; - } else - ew->t.b = (void *)st->ptr; - ew->t.e = (void *)(st->ptr + st->len); - p = esi_parse(ew); - if (p == ew->t.e) { - p = NULL; - continue; - } + ew->p.st = VTAILQ_FIRST(&sp->obj->store); + AN(ew->p.st); + ew->p.p = (char *)ew->p.st->ptr; - if (VTAILQ_NEXT(st, list) == NULL) { - /* - * XXX: illegal XML input, but did we handle - * XXX: all of it, or do we leave the final - * XXX: element dangling ? - */ - esi_error(ew, p, ew->t.e -p, - "XML 1.0 incomplete language element"); - ew->dst.b = p; - ew->dst.e = ew->t.e; - esi_addbit(ew); - break; - } + /* ->s points to the first un-dealt-with byte */ + ew->s = ew->p; - /* Move remainder to workspace */ - u = ew->t.e - p; - t.b = sp->obj->ws_o->f; - t.e = t.b + WS_Reserve(sp->obj->ws_o, 0); - if (t.b + u >= t.e) { - esi_error(ew, p, ew->t.e - p, - "XML 1.0 unreasonably long element"); - WS_Release(sp->obj->ws_o, 0); - ew->dst.b = p; - ew->dst.e = ew->t.e; - esi_addbit(ew); - p = NULL; + while (*ew->p.p != '\0') { + + if (ew->incmt && *ew->p.p == '-' && !CMP(&ew->p, "-->")) { + /* End of ESI comment */ + esi_addpfx(ew); + N(ew); + N(ew); + N(ew); + ew->s = ew->p; + ew->incmt = 0; continue; } - assert(t.e > t.b + u); /* XXX incredibly long element ? */ - memcpy(t.b, p, u); + /* Skip forward to the first '<' */ + if (*ew->p.p != '<') { + N(ew); + continue; + } - /* Peel start off next chunk, until and including '<' */ - st2 = VTAILQ_NEXT(st, list); - AN(st2); - q = t.b + u; - p = (void*)st2->ptr; - while (1) { - if (p >= (char *)st2->ptr + st2->len || q >= t.e) { - esi_error(ew, t.b, q - t.b, - "XML 1.0 unreasonably long element"); - WS_Release(sp->obj->ws_o, 0); - ew->dst.b = t.b; - ew->dst.e = q; - esi_addbit(ew); - p = NULL; - break; + if (!CMP(&ew->p, " +The end. +} + +} -start + +server s2 -listen 127.0.0.1:9082 { + rxreq + expect req.url == "/bar" + txresp -body "bar" +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.url == "/foo") { + set req.backend = s1; + } else { + set req.backend = s2; + } + } + + sub vcl_fetch { + esi; + } +} -start + +varnish v1 -cliok "param.set esi_syntax 4" +varnish v1 -cliok "param.set diag_bitmap 0x10000" +varnish v1 -cliok "debug.fragfetch 32" + +client c1 { + txreq -url /foo + rxresp +} -run From tfheen at projects.linpro.no Wed Feb 11 08:17:19 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 09:17:19 +0100 (CET) Subject: r3746 - branches/2.0/varnish-cache/man Message-ID: <20090211081719.5047628433@projects.linpro.no> Author: tfheen Date: 2009-02-11 09:17:19 +0100 (Wed, 11 Feb 2009) New Revision: 3746 Modified: branches/2.0/varnish-cache/man/vcl.7so Log: Merge r3692: Whitespace cleanup Modified: branches/2.0/varnish-cache/man/vcl.7so =================================================================== --- branches/2.0/varnish-cache/man/vcl.7so 2009-02-11 08:13:11 UTC (rev 3745) +++ branches/2.0/varnish-cache/man/vcl.7so 2009-02-11 08:17:19 UTC (rev 3746) @@ -115,7 +115,7 @@ .Ss Directors Directors choose from different backends based on health status and a per-director algorithm. -There currently exists a round-robin and a random director. +There currently exists a round-robin and a random director. .Pp Directors are defined using: .Bd -literal -offset 4n @@ -148,7 +148,7 @@ The round-robin does not take any options. .Ss Backend probes Backends can be probed to see whether they should be considered -healthy or not. The return status can also be checked by using +healthy or not. The return status can also be checked by using .Fa req.backend.healthy . .Fa .window @@ -206,7 +206,7 @@ pipe; } .Ed -.Ss Grace +.Ss Grace If the backend takes a long time to generate an object there is a risk of a thread pile up. In order to prevent this you can enable grace. From tfheen at projects.linpro.no Wed Feb 11 08:21:49 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 09:21:49 +0100 (CET) Subject: r3747 - branches/2.0/varnish-cache/man Message-ID: <20090211082149.63D0028433@projects.linpro.no> Author: tfheen Date: 2009-02-11 09:21:49 +0100 (Wed, 11 Feb 2009) New Revision: 3747 Modified: branches/2.0/varnish-cache/man/vcl.7so Log: Merge r3693: Fix backslashes. Modified: branches/2.0/varnish-cache/man/vcl.7so =================================================================== --- branches/2.0/varnish-cache/man/vcl.7so 2009-02-11 08:17:19 UTC (rev 3746) +++ branches/2.0/varnish-cache/man/vcl.7so 2009-02-11 08:21:49 UTC (rev 3747) @@ -56,7 +56,7 @@ (!, && and ||) operators, VCL supports regular expression and ACL matching using the ~ operator. .Pp -Unlike C and Perl, the backslash (\\) character has no special meaning +Unlike C and Perl, the backslash (\e) character has no special meaning in strings in VCL, which use the (%xx) escape mechanism just like URLs, so it can be freely used in regular expressions without doubling. .Pp @@ -174,7 +174,7 @@ .host = "www.example.com"; .port = "http"; .probe = { - # NB: \\r\\n automatically inserted after each string! + # NB: \er\en automatically inserted after each string! .request = "GET / HTTP/1.1" "Host: www.foo.bar" @@ -236,11 +236,11 @@ .Fa sub . Within .Fa sub , -.Va \\0 +.Va \e0 (which can also be spelled .Va & ) is replaced with the entire matched string, and -.Va \\n +.Va \en is replaced with the contents of subgroup .Ar n in the matched string. From tfheen at projects.linpro.no Wed Feb 11 09:30:54 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 10:30:54 +0100 (CET) Subject: r3748 - in branches/2.0/varnish-cache: . doc redhat Message-ID: <20090211093054.7A51C2844F@projects.linpro.no> Author: tfheen Date: 2009-02-11 10:30:54 +0100 (Wed, 11 Feb 2009) New Revision: 3748 Added: branches/2.0/varnish-cache/doc/changes-2.0.1-2.0.2.xml branches/2.0/varnish-cache/doc/changes-2.0.2-2.0.3.xml branches/2.0/varnish-cache/doc/changes-2.0.2.xml branches/2.0/varnish-cache/doc/changes-2.0.3.xml Modified: branches/2.0/varnish-cache/configure.ac branches/2.0/varnish-cache/doc/Makefile.am branches/2.0/varnish-cache/redhat/varnish.spec Log: Update changelog, configure.ac and spec file for 2.0.3 Modified: branches/2.0/varnish-cache/configure.ac =================================================================== --- branches/2.0/varnish-cache/configure.ac 2009-02-11 08:21:49 UTC (rev 3747) +++ branches/2.0/varnish-cache/configure.ac 2009-02-11 09:30:54 UTC (rev 3748) @@ -3,7 +3,7 @@ AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2006-2008 Linpro AS / Verdens Gang AS]) AC_REVISION([$Id$]) -AC_INIT([Varnish], [2.0.2], [varnish-dev at projects.linpro.no]) +AC_INIT([Varnish], [2.0.3], [varnish-dev at projects.linpro.no]) AC_CONFIG_SRCDIR(include/varnishapi.h) AM_CONFIG_HEADER(config.h) Modified: branches/2.0/varnish-cache/doc/Makefile.am =================================================================== --- branches/2.0/varnish-cache/doc/Makefile.am 2009-02-11 08:21:49 UTC (rev 3747) +++ branches/2.0/varnish-cache/doc/Makefile.am 2009-02-11 09:30:54 UTC (rev 3748) @@ -1,6 +1,8 @@ # $Id$ CHANGELOGS = \ + changes-2.0.3.html \ + changes-2.0.2.html \ changes-2.0.1.html \ changes-2.0.html \ changes-1.1.2.html \ @@ -9,6 +11,8 @@ changes-1.0.4.html XML = \ + changes-2.0.2-2.0.3.xml \ + changes-2.0.1-2.0.2.xml \ changes-2.0-2.0.1.xml \ changes-1.1.2-2.0.xml \ changes-1.1.1-1.1.2.xml \ Added: branches/2.0/varnish-cache/doc/changes-2.0.1-2.0.2.xml =================================================================== --- branches/2.0/varnish-cache/doc/changes-2.0.1-2.0.2.xml (rev 0) +++ branches/2.0/varnish-cache/doc/changes-2.0.1-2.0.2.xml 2009-02-11 09:30:54 UTC (rev 3748) @@ -0,0 +1,25 @@ + + +]> + + + + varnishd + + + In high-load situations, when using + ESI, varnishd would sometimes mishandle objects and + crash. This has been worked around. + + + + + varnishreplay + + + varnishreplay did not work correctly on + Linux, due to a too small stack. This has now been fixed. + + + Added: branches/2.0/varnish-cache/doc/changes-2.0.2-2.0.3.xml =================================================================== --- branches/2.0/varnish-cache/doc/changes-2.0.2-2.0.3.xml (rev 0) +++ branches/2.0/varnish-cache/doc/changes-2.0.2-2.0.3.xml 2009-02-11 09:30:54 UTC (rev 3748) @@ -0,0 +1,225 @@ + + +]> + + + + varnishd + + + Handle If-Modified-Since and ESI sub-objects better, + fixing a problem where we sometimes neglected to insert + included objects. + + + + restart in vcl_hit is now supported. + + + + Setting the TTL of an object to 0 seconds would sometimes + cause it to be delivered for up to one second - epsilon. This + has been corrected and we should now never deliver those + objects to other clients. + + + + The malloc storage backend now prints the maximum storage + size, just like the file backend. + + + + Various small documentation bugs have been fixed. + + + + Varnish did not set a default interval for backend + probes, causing it to poll the backend continuously. This has + been corrected. + + + + Allow "true" and "false" when setting boolean parameters, + in addition to on/off, enable/disable and yes/no. + + + + Default to always talking HTTP 1.1 with the backend. + + + + Varnish did not make sure the file it was loading was a + regular file. This could cause Varnish to crash if it was + asked to load a directory or other non-regular file. We now + check that the file is a regular file before loading it. + + + + The binary heap used for expiry processing had + scalability problems. Work around this by using stripes of a + fixed size, which should make this scale better, particularly + when starting up and having lots of objects. + + + + When we imported the jemalloc library into + the Varnish tree, it did not compile without warnings. This + has now been fixed. + + + + Varnish took a very long time to detect that the backend + did not respond. To remedy this, we now have read timeouts in + addition to the connect timeout. Both + the first_byte_timeout and + the between_bytes_timeout defaults to 60 seconds. + The connect timeout is no longer in milliseconds, but rather in + seconds. + + + + Previously, the VCL to C conversion as well as the + invocation of the C compiler was done in the management + process. This is now done in a separate sub-process. This + prevents any bugs in the VCL compiler from affecting the + management process. + + + + Chunked encoding headers were counted in the statistics + for header bytes. They no longer are. + + + + ESI processed objects were not counted in the statistics + for body bytes. They now are. + + + + It is now possible to adjust the maximum record length of + log entries in the shmlog by tuning the shm_reclen + parameter. + + + + The management parameters listed in the CLI were not + sorted, which made it hard to find the parameter you were + looking for. They are now sorted, which should make this + easier. + + + + Add a new hashing type, "critbit", which uses a lock-less + tree based lookup algorithm. This is experimental and should + not be enabled in production environments without proper + testing. + + + + The session workspace had a default size of 8k. It is + now 16k, which should make VCLs where many headers are + processed less prone to panics. + + + + We have seen that people seem to be confused as to which + actions in the different VCL functions return and which ones + don't. Add a new syntax return(action) to make + this more explicit. The old syntax is still supported. + + + + Varnish would return an error if any of the management + IPs listed in the -T parameter could not be + listened to. We now only return an error if none of them can + be listened to. + + + + In the case of the backend or client giving us too many + parameters, we used to just ignore the overflowing headers. + This is problematic if you end up ignoreing Content-Length, + Transfer-Encoding and similar headers. We now give out a 400 + error to the client if it sends us too many and 503 if we get + too many from the backend. + + + + We used panic if we got a too large chunked header. + This behaviour has been changed into just failing the + transaction. + + + + Varnish now supports an extended purge method where it is + possible to do purge req.http.host ~ "web1.com" && req.url ~ "\.png" + and similar. See the documentation for details. + + + + Under heavy load, Varnish would sometimes crash when + trying to update the per-request statistics. This has now been + fixed. + + + + It is now possible to not save the hash string in the + session and object workspace. This will save a lot of memory + on sites with many small objects. Disabling + the purge_hash parameter also disables + the purge.hash facility. + + + + Varnish now supports !~ as a "no match" + regular expression matcher. + + + + In some cases, you could get serialised access to "pass" + objects. We now make it default to the default_ttl value; this + can be overridden in vcl_fetch. + + + + Varnish did not check the syntax of regsub + calls properly. More checking has been added. + + + + If the client closed the connection while Varnish was + processing ESI elements, Varnish would crash while trying to + write the object to the client. We now check if the client has + closed the connection. + + + + The ESI parser had a bug where it would crash if an XML + comment would span storage segments. This has been + fixed. + + + + + VCL Manual page + + + The documentation on how capturing parentheses work was + wrong. This has been corrected. + + + + Grace has now been documented. + + + + + varnishreplay + + + varnishreplay did not work correctly on + Linux, due to a too small stack. This has now been fixed. + + + Added: branches/2.0/varnish-cache/doc/changes-2.0.2.xml =================================================================== --- branches/2.0/varnish-cache/doc/changes-2.0.2.xml (rev 0) +++ branches/2.0/varnish-cache/doc/changes-2.0.2.xml 2009-02-11 09:30:54 UTC (rev 3748) @@ -0,0 +1,12 @@ + + + +]> + + + Varnish + 2.0.2 + + + Added: branches/2.0/varnish-cache/doc/changes-2.0.3.xml =================================================================== --- branches/2.0/varnish-cache/doc/changes-2.0.3.xml (rev 0) +++ branches/2.0/varnish-cache/doc/changes-2.0.3.xml 2009-02-11 09:30:54 UTC (rev 3748) @@ -0,0 +1,12 @@ + + + +]> + + + Varnish + 2.0.3 + + + Modified: branches/2.0/varnish-cache/redhat/varnish.spec =================================================================== --- branches/2.0/varnish-cache/redhat/varnish.spec 2009-02-11 08:21:49 UTC (rev 3747) +++ branches/2.0/varnish-cache/redhat/varnish.spec 2009-02-11 09:30:54 UTC (rev 3748) @@ -1,6 +1,6 @@ Summary: High-performance HTTP accelerator Name: varnish -Version: 2.0.2 +Version: 2.0.3 Release: 1%{?dist} License: BSD Group: System Environment/Daemons From tfheen at projects.linpro.no Wed Feb 11 10:46:47 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 11:46:47 +0100 (CET) Subject: r3749 - branches/2.0/varnish-cache/doc Message-ID: <20090211104647.93C831F74E0@projects.linpro.no> Author: tfheen Date: 2009-02-11 11:46:47 +0100 (Wed, 11 Feb 2009) New Revision: 3749 Modified: branches/2.0/varnish-cache/doc/changes-2.0.2-2.0.3.xml Log: Fix up & vs & Modified: branches/2.0/varnish-cache/doc/changes-2.0.2-2.0.3.xml =================================================================== --- branches/2.0/varnish-cache/doc/changes-2.0.2-2.0.3.xml 2009-02-11 09:30:54 UTC (rev 3748) +++ branches/2.0/varnish-cache/doc/changes-2.0.2-2.0.3.xml 2009-02-11 10:46:47 UTC (rev 3749) @@ -153,7 +153,7 @@ Varnish now supports an extended purge method where it is - possible to do purge req.http.host ~ "web1.com" && req.url ~ "\.png" + possible to do purge req.http.host ~ "web1.com" && req.url ~ "\.png" and similar. See the documentation for details. From phk at projects.linpro.no Wed Feb 11 11:24:12 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 11 Feb 2009 12:24:12 +0100 (CET) Subject: r3750 - trunk/varnish-cache/bin/varnishd Message-ID: <20090211112412.D61991F74CB@projects.linpro.no> Author: phk Date: 2009-02-11 12:24:12 +0100 (Wed, 11 Feb 2009) New Revision: 3750 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_cli.c trunk/varnish-cache/bin/varnishd/cache_expire.c Log: Pull struct objexp out of the closet and call it objcore. In the future, this will be the bits of a cached object we cannot realistically expect to stay paged out for any period of time. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-11 10:46:47 UTC (rev 3749) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-11 11:24:12 UTC (rev 3750) @@ -85,7 +85,7 @@ struct director; struct object; struct objhead; -struct objexp; +struct objcore; struct workreq; struct addrinfo; struct esi_bit; @@ -248,6 +248,26 @@ off_t where; }; +/* Object core structure --------------------------------------------- + * Objects have sideways references in the binary heap and the LRU list + * and we want to avoid paging in a lot of objects just to move them up + * or down the binheap or to move a unrelated object on the LRU list. + * To avoid this we use a proxy object, objcore, to hold the relevant + * housekeeping fields parts of an object. + */ + +struct objcore { + unsigned magic; +#define OBJCORE_MAGIC 0x4d301302 + struct object *obj; + double timer_when; + const char *timer_what; + unsigned timer_idx; + VTAILQ_ENTRY(objcore) list; + int on_lru; + double lru_stamp; +}; + /* Object structure --------------------------------------------------*/ struct object { @@ -257,7 +277,7 @@ unsigned xid; struct objhead *objhead; struct storage *objstore; - struct objexp *objexp; + struct objcore *objcore; struct ws ws_o[1]; unsigned char *vary; Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_cli.c 2009-02-11 10:46:47 UTC (rev 3749) +++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2009-02-11 11:24:12 UTC (rev 3750) @@ -192,6 +192,7 @@ SZOF(struct bereq); SZOF(struct storage); SZOF(struct object); + SZOF(struct objcore); SZOF(struct objhead); SZOF(struct sess); SZOF(struct vbe_conn); Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-11 10:46:47 UTC (rev 3749) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-11 11:24:12 UTC (rev 3750) @@ -63,33 +63,13 @@ #include "vcl.h" #include "hash_slinger.h" -/* - * Objects have sideways references in the binary heap and the LRU list - * and we want to avoid paging in a lot of objects just to move them up - * or down the binheap or to move a unrelated object on the LRU list. - * To avoid this we use a proxy object, objexp, to hold the relevant - * housekeeping fields parts of an object. - */ - static const char * const tmr_prefetch = "prefetch"; static const char * const tmr_ttl = "ttl"; -struct objexp { - unsigned magic; -#define OBJEXP_MAGIC 0x4d301302 - struct object *obj; - double timer_when; - const char *timer_what; - unsigned timer_idx; - VTAILQ_ENTRY(objexp) list; - int on_lru; - double lru_stamp; -}; - static pthread_t exp_thread; static struct binheap *exp_heap; static struct lock exp_mtx; -static VTAILQ_HEAD(,objexp) lru = VTAILQ_HEAD_INITIALIZER(lru); +static VTAILQ_HEAD(,objcore) lru = VTAILQ_HEAD_INITIALIZER(lru); /* * This is a magic marker for the objects currently on the SIOP [look it up] @@ -99,34 +79,34 @@ #define BINHEAP_NOIDX 0 /*-------------------------------------------------------------------- - * Add and Remove objexp's from objects. + * Add and Remove objcore's from objects. */ static void -add_objexp(struct object *o) +add_objcore(struct object *o) { CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - AZ(o->objexp); + AZ(o->objcore); assert(o->busy); assert(o->cacheable); - o->objexp = calloc(sizeof *o->objexp, 1); - AN(o->objexp); - o->objexp->magic = OBJEXP_MAGIC; - o->objexp->obj = o; + o->objcore = calloc(sizeof *o->objcore, 1); + AN(o->objcore); + o->objcore->magic = OBJCORE_MAGIC; + o->objcore->obj = o; } static void -del_objexp(struct object *o) +del_objcore(struct object *o) { - struct objexp *oe; + struct objcore *oc; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - oe = o->objexp; - o->objexp = NULL; - CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); - assert(oe->timer_idx == BINHEAP_NOIDX); - free(oe); + oc = o->objcore; + o->objcore = NULL; + CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); + assert(oc->timer_idx == BINHEAP_NOIDX); + free(oc); } /*-------------------------------------------------------------------- @@ -136,13 +116,13 @@ static int update_object_when(const struct object *o) { - struct objexp *oe; + struct objcore *oc; double when; const char *what; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - oe = o->objexp; - CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); + oc = o->objcore; + CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); Lck_AssertHeld(&exp_mtx); if (o->prefetch < 0.0) { @@ -157,10 +137,10 @@ what = tmr_ttl; } assert(!isnan(when)); - oe->timer_what = what; - if (when == oe->timer_when) + oc->timer_what = what; + if (when == oc->timer_when) return (0); - oe->timer_when = when; + oc->timer_when = when; return (1); } @@ -174,24 +154,24 @@ void EXP_Insert(struct object *o) { - struct objexp *oe; + struct objcore *oc; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); assert(o->busy); assert(o->cacheable); HSH_Ref(o); - add_objexp(o); - oe = o->objexp; + add_objcore(o); + oc = o->objcore; assert(o->entered != 0 && !isnan(o->entered)); - oe->lru_stamp = o->entered; + oc->lru_stamp = o->entered; Lck_Lock(&exp_mtx); - assert(oe->timer_idx == BINHEAP_NOIDX); + assert(oc->timer_idx == BINHEAP_NOIDX); (void)update_object_when(o); - binheap_insert(exp_heap, oe); - assert(oe->timer_idx != BINHEAP_NOIDX); - VTAILQ_INSERT_TAIL(&lru, oe, list); - oe->on_lru = 1; + binheap_insert(exp_heap, oc); + assert(oc->timer_idx != BINHEAP_NOIDX); + VTAILQ_INSERT_TAIL(&lru, oc, list); + oc->on_lru = 1; Lck_Unlock(&exp_mtx); } @@ -207,21 +187,21 @@ void EXP_Touch(const struct object *o, double now) { - struct objexp *oe; + struct objcore *oc; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - oe = o->objexp; - if (oe == NULL) + oc = o->objcore; + if (oc == NULL) return; - CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); - if (oe->lru_stamp + params->lru_timeout > now) + CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); + if (oc->lru_stamp + params->lru_timeout > now) return; if (Lck_Trylock(&exp_mtx)) return; - if (oe->on_lru) { - VTAILQ_REMOVE(&lru, oe, list); - VTAILQ_INSERT_TAIL(&lru, oe, list); - oe->lru_stamp = now; + if (oc->on_lru) { + VTAILQ_REMOVE(&lru, oc, list); + VTAILQ_INSERT_TAIL(&lru, oc, list); + oc->lru_stamp = now; VSL_stats->n_lru_moved++; } Lck_Unlock(&exp_mtx); @@ -239,30 +219,30 @@ void EXP_Rearm(const struct object *o) { - struct objexp *oe; + struct objcore *oc; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - oe = o->objexp; - if (oe == NULL) + oc = o->objcore; + if (oc == NULL) return; - CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); + CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); Lck_Lock(&exp_mtx); /* * The hang-man might have this object of the binheap while * tending to a timer. If so, we do not muck with it here. */ - if (oe->timer_idx != BINHEAP_NOIDX && update_object_when(o)) { + if (oc->timer_idx != BINHEAP_NOIDX && update_object_when(o)) { /* * XXX: this could possibly be optimized by shuffling * XXX: up or down, but that leaves some very nasty * XXX: corner cases, such as shuffling all the way * XXX: down the left half, then back up the right half. */ - assert(oe->timer_idx != BINHEAP_NOIDX); - binheap_delete(exp_heap, oe->timer_idx); - assert(oe->timer_idx == BINHEAP_NOIDX); - binheap_insert(exp_heap, oe); - assert(oe->timer_idx != BINHEAP_NOIDX); + assert(oc->timer_idx != BINHEAP_NOIDX); + binheap_delete(exp_heap, oc->timer_idx); + assert(oc->timer_idx == BINHEAP_NOIDX); + binheap_insert(exp_heap, oc); + assert(oc->timer_idx != BINHEAP_NOIDX); } Lck_Unlock(&exp_mtx); } @@ -278,7 +258,7 @@ exp_timer(void *arg) { struct worker ww; - struct objexp *oe; + struct objcore *oc; struct object *o; double t; struct sess *sp; @@ -299,9 +279,9 @@ t = TIM_real(); while (1) { Lck_Lock(&exp_mtx); - oe = binheap_root(exp_heap); - CHECK_OBJ_ORNULL(oe, OBJEXP_MAGIC); - if (oe == NULL || oe->timer_when > t) { /* XXX: > or >= ? */ + oc = binheap_root(exp_heap); + CHECK_OBJ_ORNULL(oc, OBJCORE_MAGIC); + if (oc == NULL || oc->timer_when > t) { /* XXX: > or >= ? */ Lck_Unlock(&exp_mtx); WSL_Flush(&ww, 0); AZ(sleep(1)); @@ -310,26 +290,26 @@ continue; } - o = oe->obj; + o = oc->obj; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - assert(oe->timer_idx != BINHEAP_NOIDX); - binheap_delete(exp_heap, oe->timer_idx); - assert(oe->timer_idx == BINHEAP_NOIDX); + assert(oc->timer_idx != BINHEAP_NOIDX); + binheap_delete(exp_heap, oc->timer_idx); + assert(oc->timer_idx == BINHEAP_NOIDX); { /* Sanity checking */ - struct objexp *oe2 = binheap_root(exp_heap); - if (oe2 != NULL) { - assert(oe2->timer_idx != BINHEAP_NOIDX); - assert(oe2->timer_when >= oe->timer_when); + struct objcore *oc2 = binheap_root(exp_heap); + if (oc2 != NULL) { + assert(oc2->timer_idx != BINHEAP_NOIDX); + assert(oc2->timer_when >= oc->timer_when); } } - assert(oe->on_lru); + assert(oc->on_lru); Lck_Unlock(&exp_mtx); - WSL(&ww, SLT_ExpPick, 0, "%u %s", o->xid, oe->timer_what); + WSL(&ww, SLT_ExpPick, 0, "%u %s", o->xid, oc->timer_what); - if (oe->timer_what == tmr_prefetch) { + if (oc->timer_what == tmr_prefetch) { o->prefetch = 0.0; sp->obj = o; VCL_prefetch_method(sp); @@ -339,13 +319,13 @@ o->xid); } Lck_Lock(&exp_mtx); - assert(oe->timer_idx == BINHEAP_NOIDX); + assert(oc->timer_idx == BINHEAP_NOIDX); (void)update_object_when(o); - binheap_insert(exp_heap, oe); - assert(oe->timer_idx != BINHEAP_NOIDX); + binheap_insert(exp_heap, oc); + assert(oc->timer_idx != BINHEAP_NOIDX); Lck_Unlock(&exp_mtx); } else { - assert(oe->timer_what == tmr_ttl); + assert(oc->timer_what == tmr_ttl); sp->obj = o; VCL_timeout_method(sp); sp->obj = NULL; @@ -354,12 +334,12 @@ WSL(&ww, SLT_ExpKill, 0, "%u %d", o->xid, (int)(o->ttl - t)); Lck_Lock(&exp_mtx); - assert(oe->timer_idx == BINHEAP_NOIDX); - VTAILQ_REMOVE(&lru, o->objexp, list); - oe->on_lru = 0; + assert(oc->timer_idx == BINHEAP_NOIDX); + VTAILQ_REMOVE(&lru, o->objcore, list); + oc->on_lru = 0; VSL_stats->n_expired++; Lck_Unlock(&exp_mtx); - del_objexp(o); + del_objcore(o); HSH_Deref(&o); } } @@ -374,13 +354,13 @@ int EXP_NukeOne(struct sess *sp) { - struct objexp *oe; + struct objcore *oc; struct object *o; /* * Find the first currently unused object on the LRU. * - * Ideally we would have the refcnt in the objexp so we the object does + * Ideally we would have the refcnt in the objcore so we the object does * not need to get paged in for this check, but it does not pay off * the complexity: The chances of an object being in front of the LRU, * with active references, likely means that it is already in core. An @@ -390,29 +370,29 @@ * another ref while we ponder its destiny without the lock held. */ Lck_Lock(&exp_mtx); - VTAILQ_FOREACH(oe, &lru, list) { - CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); - if (oe->timer_idx == BINHEAP_NOIDX) /* exp_timer has it */ + VTAILQ_FOREACH(oc, &lru, list) { + CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); + if (oc->timer_idx == BINHEAP_NOIDX) /* exp_timer has it */ continue; - if (oe->obj->refcnt == 1) + if (oc->obj->refcnt == 1) break; } - if (oe != NULL) { + if (oc != NULL) { /* * We hazzard the guess that the object is more likely to * be tossed than kept, and forge ahead on the work to save * a lock cycle. If the object is kept, we reverse these * actions below. */ - VTAILQ_REMOVE(&lru, oe, list); - oe->on_lru = 0; - binheap_delete(exp_heap, oe->timer_idx); - assert(oe->timer_idx == BINHEAP_NOIDX); + VTAILQ_REMOVE(&lru, oc, list); + oc->on_lru = 0; + binheap_delete(exp_heap, oc->timer_idx); + assert(oc->timer_idx == BINHEAP_NOIDX); VSL_stats->n_lru_nuked++; } Lck_Unlock(&exp_mtx); - if (oe == NULL) + if (oc == NULL) return (-1); /* @@ -421,14 +401,14 @@ * substitute the object we want to nuke for the sessions own object. */ o = sp->obj; - sp->obj = oe->obj; + sp->obj = oc->obj; VCL_discard_method(sp); sp->obj = o; - o = oe->obj; + o = oc->obj; if (sp->handling == VCL_RET_DISCARD) { WSL(sp->wrk, SLT_ExpKill, 0, "%u LRU", o->xid); - del_objexp(o); + del_objcore(o); HSH_Deref(&o); return (1); } @@ -439,37 +419,37 @@ Lck_Lock(&exp_mtx); VSL_stats->n_lru_nuked--; /* It was premature */ VSL_stats->n_lru_saved++; - binheap_insert(exp_heap, oe); - assert(oe->timer_idx != BINHEAP_NOIDX); - VTAILQ_INSERT_TAIL(&lru, oe, list); - oe->on_lru = 1; + binheap_insert(exp_heap, oc); + assert(oc->timer_idx != BINHEAP_NOIDX); + VTAILQ_INSERT_TAIL(&lru, oc, list); + oc->on_lru = 1; Lck_Unlock(&exp_mtx); return (0); } /*-------------------------------------------------------------------- - * BinHeap helper functions for objexp. + * BinHeap helper functions for objcore. */ static int object_cmp(void *priv, void *a, void *b) { - struct objexp *aa, *bb; + struct objcore *aa, *bb; (void)priv; - CAST_OBJ_NOTNULL(aa, a, OBJEXP_MAGIC); - CAST_OBJ_NOTNULL(bb, b, OBJEXP_MAGIC); + CAST_OBJ_NOTNULL(aa, a, OBJCORE_MAGIC); + CAST_OBJ_NOTNULL(bb, b, OBJCORE_MAGIC); return (aa->timer_when < bb->timer_when); } static void object_update(void *priv, void *p, unsigned u) { - struct objexp *oe; + struct objcore *oc; (void)priv; - CAST_OBJ_NOTNULL(oe, p, OBJEXP_MAGIC); - oe->timer_idx = u; + CAST_OBJ_NOTNULL(oc, p, OBJCORE_MAGIC); + oc->timer_idx = u; } /*--------------------------------------------------------------------*/ From ingvar at projects.linpro.no Wed Feb 11 14:01:42 2009 From: ingvar at projects.linpro.no (ingvar at projects.linpro.no) Date: Wed, 11 Feb 2009 15:01:42 +0100 (CET) Subject: r3751 - branches/2.0/varnish-cache/redhat Message-ID: <20090211140142.AB6A81F74D1@projects.linpro.no> Author: ingvar Date: 2009-02-11 15:01:42 +0100 (Wed, 11 Feb 2009) New Revision: 3751 Modified: branches/2.0/varnish-cache/redhat/varnish.spec Log: - Changelog item to specfile for the rpm package - Added html doc to the rpm package Modified: branches/2.0/varnish-cache/redhat/varnish.spec =================================================================== --- branches/2.0/varnish-cache/redhat/varnish.spec 2009-02-11 11:24:12 UTC (rev 3750) +++ branches/2.0/varnish-cache/redhat/varnish.spec 2009-02-11 14:01:42 UTC (rev 3751) @@ -135,6 +135,10 @@ LD_LIBRARY_PATH="lib/libvarnish/.libs:lib/libvarnishcompat/.libs:lib/libvarnishapi/.libs:lib/libvcl/.libs" bin/varnishd/varnishd -b 127.0.0.1:80 -C -n /tmp/foo %{__make} check LD_LIBRARY_PATH="../../lib/libvarnish/.libs:../../lib/libvarnishcompat/.libs:../../lib/libvarnishapi/.libs:../../lib/libvcl/.libs" +# Remove uneccessary doc src files +mkdir doc.src +mv doc/*.xml doc/*.xsl doc/Makefile* doc.src + %install rm -rf %{buildroot} make install DESTDIR=%{buildroot} INSTALL="install -p" @@ -168,6 +172,7 @@ %{_mandir}/man7/*.7* %doc INSTALL LICENSE README redhat/README.redhat ChangeLog %doc examples +%doc doc %dir %{_sysconfdir}/varnish/ %config(noreplace) %{_sysconfdir}/varnish/default.vcl %config(noreplace) %{_sysconfdir}/sysconfig/varnish @@ -230,6 +235,9 @@ %postun libs -p /sbin/ldconfig %changelog +* Wed Feb 11 2009 Ingvar Hagelund - 2.0.3-1 + New upstream release 2.0.3. A bugfix and feature enhancement release + * Mon Nov 10 2008 Ingvar Hagelund - 2.0.2-1 New upstream release 2.0.2. A bugfix release @@ -247,14 +255,14 @@ * Wed Oct 15 2008 Ingvar Hagelund - 2.0-1 - 2.0 released. New upstream sources -- Disabled jemalloc on ppc and ppc64. Added a note in README.redhat. +- Disabled jemalloc on ppc and ppc64. Added a note in README.redhat - Synced to upstream again. No more patches needed. * Wed Oct 08 2008 Ingvar Hagelund - 2.0-0.11.rc1 - 2.0-rc1 released. New upstream sources - Added a patch for pagesize to match redhat's rhel5 ppc64 koji build boxes - Added a patch for test a00008, from r3269 -- Removed condrestart in postscript at upgrade. We don't want that. +- Removed condrestart in postscript at upgrade. We don't want that * Fri Sep 26 2008 Ingvar Hagelund - 2.0-0.10.beta2 - 2.0-beta2 released. New upstream sources From ingvar at projects.linpro.no Wed Feb 11 14:21:27 2009 From: ingvar at projects.linpro.no (ingvar at projects.linpro.no) Date: Wed, 11 Feb 2009 15:21:27 +0100 (CET) Subject: r3752 - branches/2.0/varnish-cache/redhat Message-ID: <20090211142127.6BA8D1F74D2@projects.linpro.no> Author: ingvar Date: 2009-02-11 15:21:27 +0100 (Wed, 11 Feb 2009) New Revision: 3752 Modified: branches/2.0/varnish-cache/redhat/varnish.spec Log: Added som changelog changes from fedora package Modified: branches/2.0/varnish-cache/redhat/varnish.spec =================================================================== --- branches/2.0/varnish-cache/redhat/varnish.spec 2009-02-11 14:01:42 UTC (rev 3751) +++ branches/2.0/varnish-cache/redhat/varnish.spec 2009-02-11 14:21:27 UTC (rev 3752) @@ -238,6 +238,9 @@ * Wed Feb 11 2009 Ingvar Hagelund - 2.0.3-1 New upstream release 2.0.3. A bugfix and feature enhancement release +* Fri Dec 12 2008 Ingvar Hagelund - 2.0.2-2 + Added a fix for a timeout bug, backported from trunk + * Mon Nov 10 2008 Ingvar Hagelund - 2.0.2-1 New upstream release 2.0.2. A bugfix release @@ -256,7 +259,7 @@ * Wed Oct 15 2008 Ingvar Hagelund - 2.0-1 - 2.0 released. New upstream sources - Disabled jemalloc on ppc and ppc64. Added a note in README.redhat -- Synced to upstream again. No more patches needed. +- Synced to upstream again. No more patches needed * Wed Oct 08 2008 Ingvar Hagelund - 2.0-0.11.rc1 - 2.0-rc1 released. New upstream sources From tfheen at projects.linpro.no Wed Feb 11 14:55:03 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 15:55:03 +0100 (CET) Subject: r3753 - trunk/varnish-cache/redhat Message-ID: <20090211145503.47ED297C57@projects.linpro.no> Author: tfheen Date: 2009-02-11 15:55:02 +0100 (Wed, 11 Feb 2009) New Revision: 3753 Modified: trunk/varnish-cache/redhat/varnish.spec Log: Merge r3751 into trunk: Packaging fixes - Changelog item to specfile for the rpm package - Added html doc to the rpm package Modified: trunk/varnish-cache/redhat/varnish.spec =================================================================== --- trunk/varnish-cache/redhat/varnish.spec 2009-02-11 14:21:27 UTC (rev 3752) +++ trunk/varnish-cache/redhat/varnish.spec 2009-02-11 14:55:02 UTC (rev 3753) @@ -135,6 +135,10 @@ LD_LIBRARY_PATH="lib/libvarnish/.libs:lib/libvarnishcompat/.libs:lib/libvarnishapi/.libs:lib/libvcl/.libs" bin/varnishd/varnishd -b 127.0.0.1:80 -C -n /tmp/foo %{__make} check LD_LIBRARY_PATH="../../lib/libvarnish/.libs:../../lib/libvarnishcompat/.libs:../../lib/libvarnishapi/.libs:../../lib/libvcl/.libs" +# Remove uneccessary doc src files +mkdir doc.src +mv doc/*.xml doc/*.xsl doc/Makefile* doc.src + %install rm -rf %{buildroot} make install DESTDIR=%{buildroot} INSTALL="install -p" @@ -168,6 +172,7 @@ %{_mandir}/man7/*.7* %doc INSTALL LICENSE README redhat/README.redhat ChangeLog %doc examples +%doc doc %dir %{_sysconfdir}/varnish/ %config(noreplace) %{_sysconfdir}/varnish/default.vcl %config(noreplace) %{_sysconfdir}/sysconfig/varnish @@ -230,6 +235,9 @@ %postun libs -p /sbin/ldconfig %changelog +* Wed Feb 11 2009 Ingvar Hagelund - 2.0.3-1 + New upstream release 2.0.3. A bugfix and feature enhancement release + * Mon Nov 10 2008 Ingvar Hagelund - 2.0.2-1 New upstream release 2.0.2. A bugfix release From tfheen at projects.linpro.no Wed Feb 11 14:55:26 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 11 Feb 2009 15:55:26 +0100 (CET) Subject: r3754 - trunk/varnish-cache/redhat Message-ID: <20090211145526.B8A7E97C57@projects.linpro.no> Author: tfheen Date: 2009-02-11 15:55:26 +0100 (Wed, 11 Feb 2009) New Revision: 3754 Modified: trunk/varnish-cache/redhat/varnish.spec Log: Merge r3752: Added som changelog changes from fedora package Modified: trunk/varnish-cache/redhat/varnish.spec =================================================================== --- trunk/varnish-cache/redhat/varnish.spec 2009-02-11 14:55:02 UTC (rev 3753) +++ trunk/varnish-cache/redhat/varnish.spec 2009-02-11 14:55:26 UTC (rev 3754) @@ -238,6 +238,9 @@ * Wed Feb 11 2009 Ingvar Hagelund - 2.0.3-1 New upstream release 2.0.3. A bugfix and feature enhancement release +* Fri Dec 12 2008 Ingvar Hagelund - 2.0.2-2 + Added a fix for a timeout bug, backported from trunk + * Mon Nov 10 2008 Ingvar Hagelund - 2.0.2-1 New upstream release 2.0.2. A bugfix release From tfheen at projects.linpro.no Thu Feb 12 11:15:03 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Thu, 12 Feb 2009 12:15:03 +0100 (CET) Subject: r3755 - tags Message-ID: <20090212111503.8C89597C57@projects.linpro.no> Author: tfheen Date: 2009-02-12 12:15:02 +0100 (Thu, 12 Feb 2009) New Revision: 3755 Added: tags/varnish-2.0.3/ Log: Release 2.0.3 Copied: tags/varnish-2.0.3 (from rev 3754, branches/2.0) From phk at projects.linpro.no Thu Feb 12 17:23:16 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 12 Feb 2009 18:23:16 +0100 (CET) Subject: r3756 - trunk/varnish-cache/bin/varnishd Message-ID: <20090212172316.7D32297C5C@projects.linpro.no> Author: phk Date: 2009-02-12 18:23:16 +0100 (Thu, 12 Feb 2009) New Revision: 3756 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_cli.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/hash_critbit.c trunk/varnish-cache/bin/varnishd/hash_slinger.h Log: Move objcore over objects, so that objhead has a list of objcore which point to the objects. Preallocate objcore with obj+objhead before we enter locked hash sections. Rename objcore.list to objcore.lru_list. Eliminate obj.list and objhead.hashlen Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-12 11:15:02 UTC (rev 3755) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-12 17:23:16 UTC (rev 3756) @@ -183,6 +183,7 @@ #define WORKER_MAGIC 0x6391adcf struct objhead *nobjhead; struct object *nobj; + struct objcore *nobjcore; double lastused; @@ -264,6 +265,7 @@ const char *timer_what; unsigned timer_idx; VTAILQ_ENTRY(objcore) list; + VTAILQ_ENTRY(objcore) lru_list; int on_lru; double lru_stamp; }; @@ -302,7 +304,6 @@ double last_modified; struct http http[1]; - VTAILQ_ENTRY(object) list; VTAILQ_HEAD(, storage) store; Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_cli.c 2009-02-12 11:15:02 UTC (rev 3755) +++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2009-02-12 17:23:16 UTC (rev 3756) @@ -197,6 +197,7 @@ SZOF(struct sess); SZOF(struct vbe_conn); SZOF(struct varnish_stats); + SZOF(struct lock); } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-12 11:15:02 UTC (rev 3755) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-12 17:23:16 UTC (rev 3756) @@ -79,37 +79,6 @@ #define BINHEAP_NOIDX 0 /*-------------------------------------------------------------------- - * Add and Remove objcore's from objects. - */ - -static void -add_objcore(struct object *o) -{ - - CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - AZ(o->objcore); - assert(o->busy); - assert(o->cacheable); - o->objcore = calloc(sizeof *o->objcore, 1); - AN(o->objcore); - o->objcore->magic = OBJCORE_MAGIC; - o->objcore->obj = o; -} - -static void -del_objcore(struct object *o) -{ - struct objcore *oc; - - CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - oc = o->objcore; - o->objcore = NULL; - CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); - assert(oc->timer_idx == BINHEAP_NOIDX); - free(oc); -} - -/*-------------------------------------------------------------------- * When & why does the timer fire for this object ? */ @@ -160,7 +129,7 @@ assert(o->busy); assert(o->cacheable); HSH_Ref(o); - add_objcore(o); + CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC); oc = o->objcore; assert(o->entered != 0 && !isnan(o->entered)); @@ -170,7 +139,7 @@ (void)update_object_when(o); binheap_insert(exp_heap, oc); assert(oc->timer_idx != BINHEAP_NOIDX); - VTAILQ_INSERT_TAIL(&lru, oc, list); + VTAILQ_INSERT_TAIL(&lru, oc, lru_list); oc->on_lru = 1; Lck_Unlock(&exp_mtx); } @@ -199,8 +168,8 @@ if (Lck_Trylock(&exp_mtx)) return; if (oc->on_lru) { - VTAILQ_REMOVE(&lru, oc, list); - VTAILQ_INSERT_TAIL(&lru, oc, list); + VTAILQ_REMOVE(&lru, oc, lru_list); + VTAILQ_INSERT_TAIL(&lru, oc, lru_list); oc->lru_stamp = now; VSL_stats->n_lru_moved++; } @@ -335,11 +304,10 @@ "%u %d", o->xid, (int)(o->ttl - t)); Lck_Lock(&exp_mtx); assert(oc->timer_idx == BINHEAP_NOIDX); - VTAILQ_REMOVE(&lru, o->objcore, list); + VTAILQ_REMOVE(&lru, o->objcore, lru_list); oc->on_lru = 0; VSL_stats->n_expired++; Lck_Unlock(&exp_mtx); - del_objcore(o); HSH_Deref(&o); } } @@ -370,7 +338,7 @@ * another ref while we ponder its destiny without the lock held. */ Lck_Lock(&exp_mtx); - VTAILQ_FOREACH(oc, &lru, list) { + VTAILQ_FOREACH(oc, &lru, lru_list) { CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); if (oc->timer_idx == BINHEAP_NOIDX) /* exp_timer has it */ continue; @@ -384,7 +352,7 @@ * a lock cycle. If the object is kept, we reverse these * actions below. */ - VTAILQ_REMOVE(&lru, oc, list); + VTAILQ_REMOVE(&lru, oc, lru_list); oc->on_lru = 0; binheap_delete(exp_heap, oc->timer_idx); assert(oc->timer_idx == BINHEAP_NOIDX); @@ -408,7 +376,6 @@ if (sp->handling == VCL_RET_DISCARD) { WSL(sp->wrk, SLT_ExpKill, 0, "%u LRU", o->xid); - del_objcore(o); HSH_Deref(&o); return (1); } @@ -421,7 +388,7 @@ VSL_stats->n_lru_saved++; binheap_insert(exp_heap, oc); assert(oc->timer_idx != BINHEAP_NOIDX); - VTAILQ_INSERT_TAIL(&lru, oc, list); + VTAILQ_INSERT_TAIL(&lru, oc, lru_list); oc->on_lru = 1; Lck_Unlock(&exp_mtx); return (0); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-12 11:15:02 UTC (rev 3755) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-12 17:23:16 UTC (rev 3756) @@ -85,6 +85,7 @@ { struct worker *w; struct objhead *oh; + struct objcore *oc; struct object *o; struct storage *st; @@ -92,17 +93,23 @@ CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); w = sp->wrk; + if (w->nobjcore == NULL) { + ALLOC_OBJ(oc, OBJCORE_MAGIC); + w->nobjcore = oc; + } + CHECK_OBJ_NOTNULL(w->nobjcore, OBJCORE_MAGIC); + if (w->nobjhead == NULL) { ALLOC_OBJ(oh, OBJHEAD_MAGIC); XXXAN(oh); oh->refcnt = 1; - VTAILQ_INIT(&oh->objects); + VTAILQ_INIT(&oh->objcs); VTAILQ_INIT(&oh->waitinglist); Lck_New(&oh->mtx); w->nobjhead = oh; VSL_stats->n_objecthead++; - } else - CHECK_OBJ_NOTNULL(w->nobjhead, OBJHEAD_MAGIC); + } + CHECK_OBJ_NOTNULL(w->nobjhead, OBJHEAD_MAGIC); if (w->nobj == NULL) { st = STV_alloc(sp, params->obj_workspace); @@ -128,8 +135,8 @@ w->nobj = o; VSL_stats->n_object++; - } else - CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC); + } + CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC); } void @@ -157,7 +164,6 @@ oh->hash = malloc(sp->lhashptr); XXXAN(oh->hash); - oh->hashlen = sp->lhashptr; b = oh->hash; for (u = 0; u < sp->ihashptr; u += 2) { v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); @@ -166,7 +172,7 @@ *b++ = '#'; } *b++ = '\0'; - assert(b <= oh->hash + oh->hashlen); + assert(b <= oh->hash + sp->lhashptr); } void @@ -229,6 +235,7 @@ { struct worker *w; struct objhead *oh; + struct objcore *oc; struct object *o, *busy_o, *grace_o; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); @@ -257,7 +264,11 @@ busy_o = NULL; grace_o = NULL; - VTAILQ_FOREACH(o, &oh->objects, list) { + o = NULL; + VTAILQ_FOREACH(oc, &oh->objcs, list) { + o = oc->obj; + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + if (o->busy) { busy_o = o; continue; @@ -279,6 +290,10 @@ if (o->ttl + HSH_Grace(o->grace) >= sp->t_req) grace_o = o; } + if (oc == NULL) + o = NULL; + else + AN(o); /* * If we have a object in grace and being fetched, @@ -314,9 +329,15 @@ /* Insert (precreated) object in objecthead */ o = w->nobj; w->nobj = NULL; + + oc = w->nobjcore; + w->nobjcore = NULL; + o->objhead = oh; + o->objcore = oc; + oc->obj = o; /* XXX: Should this not be ..._HEAD now ? */ - VTAILQ_INSERT_TAIL(&oh->objects, o, list); + VTAILQ_INSERT_TAIL(&oh->objcs, oc, list); /* NB: do not deref objhead the new object inherits our reference */ if (grace_o != NULL) { grace_o->child = o; @@ -419,6 +440,7 @@ { struct object *o; struct objhead *oh; + struct objcore *oc; unsigned r; AN(oo); @@ -426,19 +448,22 @@ *oo = NULL; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oh = o->objhead; - if (oh != NULL) { + if (oh == NULL) { + oc = NULL; + assert(o->refcnt > 0); + r = --o->refcnt; + } else { CHECK_OBJ(oh, OBJHEAD_MAGIC); - /* drop ref on object */ + oc = o->objcore; + CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); + Lck_Lock(&oh->mtx); - } - assert(o->refcnt > 0); - r = --o->refcnt; - if (oh != NULL) + assert(o->refcnt > 0); + r = --o->refcnt; + if (!r) + VTAILQ_REMOVE(&oh->objcs, oc, list); hsh_rush(oh); - if (oh != NULL) { - if (!r) - VTAILQ_REMOVE(&oh->objects, o, list); Lck_Unlock(&oh->mtx); } @@ -458,12 +483,16 @@ STV_free(o->objstore); VSL_stats->n_object--; - if (oh == NULL) + if (oh == NULL) { + AZ(oc); return; + } + AN(oc); + FREE_OBJ(oc); /* Drop our ref on the objhead */ if (hash->deref(oh)) return; - assert(VTAILQ_EMPTY(&oh->objects)); + assert(VTAILQ_EMPTY(&oh->objcs)); Lck_Delete(&oh->mtx); VSL_stats->n_objecthead--; free(oh->hash); Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-12 11:15:02 UTC (rev 3755) +++ trunk/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-12 17:23:16 UTC (rev 3756) @@ -432,7 +432,6 @@ } else { free(noh->hash); noh->hash = NULL; - noh->hashlen = 0; VSL_stats->hcb_lock++; #ifdef PHK fprintf(stderr, "hcb_lookup %d\n", __LINE__); Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-12 11:15:02 UTC (rev 3755) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-12 17:23:16 UTC (rev 3756) @@ -73,11 +73,10 @@ struct lock mtx; unsigned refcnt; - VTAILQ_HEAD(,object) objects; + VTAILQ_HEAD(,objcore) objcs; char *hash; - unsigned hashlen; unsigned char digest[DIGEST_LEN]; -#ifdef NOT_YET +#ifndef NOT_YET union { VTAILQ_HEAD(, sess) __u_waitinglist; VTAILQ_ENTRY(objhead) __u_coollist; From phk at projects.linpro.no Thu Feb 12 22:26:44 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 12 Feb 2009 23:26:44 +0100 (CET) Subject: r3757 - trunk/varnish-cache/bin/varnishd Message-ID: <20090212222644.4153E3833C@projects.linpro.no> Author: phk Date: 2009-02-12 23:26:44 +0100 (Thu, 12 Feb 2009) New Revision: 3757 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_expire.c Log: Move the LRU timestamp from the objcore to the object, we only access it when we have used the object anyway. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-12 17:23:16 UTC (rev 3756) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-12 22:26:44 UTC (rev 3757) @@ -267,7 +267,6 @@ VTAILQ_ENTRY(objcore) list; VTAILQ_ENTRY(objcore) lru_list; int on_lru; - double lru_stamp; }; /* Object structure --------------------------------------------------*/ @@ -302,6 +301,7 @@ double prefetch; double last_modified; + double last_lru; struct http http[1]; @@ -463,7 +463,7 @@ void EXP_Insert(struct object *o); void EXP_Init(void); void EXP_Rearm(const struct object *o); -void EXP_Touch(const struct object *o, double now); +int EXP_Touch(const struct object *o); int EXP_NukeOne(struct sess *sp); /* cache_fetch.c */ Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-12 17:23:16 UTC (rev 3756) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-12 22:26:44 UTC (rev 3757) @@ -159,8 +159,10 @@ sp->t_resp = TIM_real(); if (sp->obj->objhead != NULL) { + if ((sp->t_resp - sp->obj->last_lru) > params->lru_timeout && + EXP_Touch(sp->obj)) + sp->obj->last_lru = sp->t_resp; /* XXX: locking ? */ sp->obj->last_use = sp->t_resp; /* XXX: locking ? */ - EXP_Touch(sp->obj, sp->t_resp); } RES_BuildHttp(sp); VCL_deliver_method(sp); Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-12 17:23:16 UTC (rev 3756) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-12 22:26:44 UTC (rev 3757) @@ -133,7 +133,7 @@ oc = o->objcore; assert(o->entered != 0 && !isnan(o->entered)); - oc->lru_stamp = o->entered; + o->last_lru = o->entered; Lck_Lock(&exp_mtx); assert(oc->timer_idx == BINHEAP_NOIDX); (void)update_object_when(o); @@ -153,27 +153,27 @@ * that can be worked around by examining obj.last_use in vcl_discard{} */ -void -EXP_Touch(const struct object *o, double now) +int +EXP_Touch(const struct object *o) { struct objcore *oc; + int retval = 0; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oc = o->objcore; if (oc == NULL) - return; + return (retval); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); - if (oc->lru_stamp + params->lru_timeout > now) - return; if (Lck_Trylock(&exp_mtx)) - return; + return (retval); if (oc->on_lru) { VTAILQ_REMOVE(&lru, oc, lru_list); VTAILQ_INSERT_TAIL(&lru, oc, lru_list); - oc->lru_stamp = now; VSL_stats->n_lru_moved++; + retval = 1; } Lck_Unlock(&exp_mtx); + return (retval); } /*-------------------------------------------------------------------- From phk at projects.linpro.no Fri Feb 13 09:19:51 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 10:19:51 +0100 (CET) Subject: r3758 - trunk/varnish-cache/bin/varnishd Message-ID: <20090213091951.2ACAD1F7500@projects.linpro.no> Author: phk Date: 2009-02-13 10:19:50 +0100 (Fri, 13 Feb 2009) New Revision: 3758 Added: trunk/varnish-cache/bin/varnishd/cache_waiter.h trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c Removed: trunk/varnish-cache/bin/varnishd/cache_acceptor.h trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c trunk/varnish-cache/bin/varnishd/cache_acceptor_ports.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache_acceptor.c trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Due to lack og foresight,the threads that keep an eye on client connections to see if they get reused ended up being named "acceptors", which is a bad name because we have another thread which accepts new connections. Rename the "fake" acceptors to "waiters" Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2009-02-12 22:26:44 UTC (rev 3757) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2009-02-13 09:19:50 UTC (rev 3758) @@ -8,10 +8,10 @@ varnishd_SOURCES = \ cache_acceptor.c \ - cache_acceptor_epoll.c \ - cache_acceptor_kqueue.c \ - cache_acceptor_poll.c \ - cache_acceptor_ports.c \ + cache_waiter_epoll.c \ + cache_waiter_kqueue.c \ + cache_waiter_poll.c \ + cache_waiter_ports.c \ cache_backend.c \ cache_backend_cfg.c \ cache_backend_poll.c \ @@ -60,7 +60,7 @@ noinst_HEADERS = \ acct_fields.h \ cache.h \ - cache_acceptor.h \ + cache_waiter.h \ cache_backend.h \ cache_backend_poll.h \ common.h \ Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2009-02-12 22:26:44 UTC (rev 3757) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2009-02-13 09:19:50 UTC (rev 3758) @@ -47,23 +47,23 @@ #include "cli_priv.h" #include "shmlog.h" #include "cache.h" -#include "cache_acceptor.h" +#include "cache_waiter.h" -static struct acceptor * const vca_acceptors[] = { +static struct waiter * const vca_waiters[] = { #if defined(HAVE_KQUEUE) - &acceptor_kqueue, + &waiter_kqueue, #endif #if defined(HAVE_EPOLL_CTL) - &acceptor_epoll, + &waiter_epoll, #endif #if defined(HAVE_PORT_CREATE) - &acceptor_ports, + &waiter_ports, #endif - &acceptor_poll, + &waiter_poll, NULL, }; -static struct acceptor const *vca_act; +static struct waiter const *vca_act; static pthread_t vca_thread_acct; static struct timeval tv_sndtimeo; @@ -322,7 +322,7 @@ (void)priv; if (vca_act == NULL) - vca_act = vca_acceptors[0]; + vca_act = vca_waiters[0]; AN(vca_act); AN(vca_act->name); @@ -347,7 +347,7 @@ } void -VCA_tweak_acceptor(struct cli *cli, const char *arg) +VCA_tweak_waiter(struct cli *cli, const char *arg) { int i; @@ -358,9 +358,9 @@ cli_out(cli, "%s", vca_act->name); cli_out(cli, " ("); - for (i = 0; vca_acceptors[i] != NULL; i++) + for (i = 0; vca_waiters[i] != NULL; i++) cli_out(cli, "%s%s", i == 0 ? "" : ", ", - vca_acceptors[i]->name); + vca_waiters[i]->name); cli_out(cli, ")"); return; } @@ -368,12 +368,12 @@ vca_act = NULL; return; } - for (i = 0; vca_acceptors[i]->name; i++) { - if (!strcmp(arg, vca_acceptors[i]->name)) { - vca_act = vca_acceptors[i]; + for (i = 0; vca_waiters[i]->name; i++) { + if (!strcmp(arg, vca_waiters[i]->name)) { + vca_act = vca_waiters[i]; return; } } - cli_out(cli, "Unknown acceptor"); + cli_out(cli, "Unknown waiter"); cli_result(cli, CLIS_PARAM); } Deleted: trunk/varnish-cache/bin/varnishd/cache_acceptor.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.h 2009-02-12 22:26:44 UTC (rev 3757) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.h 2009-02-13 09:19:50 UTC (rev 3758) @@ -1,60 +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$ - */ - -struct sess; - -typedef void acceptor_init_f(void); -typedef void acceptor_pass_f(struct sess *); - -extern int vca_pipes[2]; - -struct acceptor { - const char *name; - acceptor_init_f *init; - acceptor_pass_f *pass; -}; - -#if defined(HAVE_EPOLL_CTL) -extern struct acceptor acceptor_epoll; -#endif - -#if defined(HAVE_KQUEUE) -extern struct acceptor acceptor_kqueue; -#endif - -extern struct acceptor acceptor_poll; - -#if defined(HAVE_PORT_CREATE) -extern struct acceptor acceptor_ports; -#endif - -/* vca_acceptor.c */ -void vca_handover(struct sess *sp, int bad); Deleted: trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2009-02-12 22:26:44 UTC (rev 3757) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c 2009-02-13 09:19:50 UTC (rev 3758) @@ -1,141 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * 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$ - * - * XXX: We need to pass sessions back into the event engine when they are - * reused. Not sure what the most efficient way is for that. For now - * write the session pointer to a pipe which the event engine monitors. - */ - -#include "config.h" - -#if defined(HAVE_EPOLL_CTL) - -#include -#include -#include -#include -#include - -#include - -#include "shmlog.h" -#include "cache.h" -#include "cache_acceptor.h" - -static pthread_t vca_epoll_thread; -static int epfd = -1; - -static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); - -static void -vca_add(int fd, void *data) -{ - struct epoll_event ev = { EPOLLIN | EPOLLPRI, { data } }; - AZ(epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev)); -} - -static void -vca_del(int fd) -{ - struct epoll_event ev = { 0, { 0 } }; - AZ(epoll_ctl(epfd, EPOLL_CTL_DEL, fd, &ev)); -} - -static void * -vca_main(void *arg) -{ - struct epoll_event ev; - double deadline; - int dotimer = 0; - double last_timeout = 0, tmp_timeout; - struct sess *sp, *sp2; - int i; - - THR_SetName("cache-epoll"); - (void)arg; - - epfd = epoll_create(16); - assert(epfd >= 0); - - vca_add(vca_pipes[0], vca_pipes); - - while (1) { - if ((dotimer = epoll_wait(epfd, &ev, 1, 100)) > 0) { - if (ev.data.ptr == vca_pipes) { - i = read(vca_pipes[0], &sp, sizeof sp); - assert(i == sizeof sp); - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - VTAILQ_INSERT_TAIL(&sesshead, sp, list); - vca_add(sp->fd, sp); - } else { - CAST_OBJ_NOTNULL(sp, ev.data.ptr, SESS_MAGIC); - i = HTC_Rx(sp->htc); - if (i != 0) { - VTAILQ_REMOVE(&sesshead, sp, list); - vca_del(sp->fd); - vca_handover(sp, i); - } - } - } - tmp_timeout = TIM_mono(); - if ((tmp_timeout - last_timeout) > 60) { - last_timeout = tmp_timeout; - } else { - if (dotimer > 0) - continue; - } - - /* check for timeouts */ - deadline = TIM_real() - params->sess_timeout; - VTAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) { - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - if (sp->t_open > deadline) - continue; - VTAILQ_REMOVE(&sesshead, sp, list); - vca_del(sp->fd); - vca_close_session(sp, "timeout"); - SES_Delete(sp); - } - } -} - -/*--------------------------------------------------------------------*/ - -static void -vca_epoll_init(void) -{ - - AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL)); -} - -struct acceptor acceptor_epoll = { - .name = "epoll", - .init = vca_epoll_init, -}; - -#endif /* defined(HAVE_EPOLL_CTL) */ Deleted: trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2009-02-12 22:26:44 UTC (rev 3757) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2009-02-13 09:19:50 UTC (rev 3758) @@ -1,225 +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$ - * - * XXX: We need to pass sessions back into the event engine when they are - * reused. Not sure what the most efficient way is for that. For now - * write the session pointer to a pipe which the event engine monitors. - */ - -#include "config.h" - -#if defined(HAVE_KQUEUE) - -#include -#include -#include -#include -#include -#include - -#include - -#include "shmlog.h" -#include "cache.h" -#include "cache_acceptor.h" - - -/**********************************************************************/ - - -static pthread_t vca_kqueue_thread; -static int kq = -1; - - -static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); - -#define NKEV 100 - -static struct kevent ki[NKEV]; -static unsigned nki; - -static void -vca_kq_flush(void) -{ - int i; - - if (nki == 0) - return; - i = kevent(kq, ki, nki, NULL, 0, NULL); - assert(i == 0); - nki = 0; -} - -static void -vca_kq_sess(struct sess *sp, short arm) -{ - - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - assert(sp->fd >= 0); - DSL(0x04, SLT_Debug, sp->fd, "KQ: EV_SET sp %p arm %x", sp, arm); - EV_SET(&ki[nki], sp->fd, EVFILT_READ, arm, 0, 0, sp); - if (++nki == NKEV) - vca_kq_flush(); -} - -static void -vca_kev(const struct kevent *kp) -{ - int i, j; - struct sess *sp; - struct sess *ss[NKEV]; - - AN(kp->udata); - if (kp->udata == vca_pipes) { - j = 0; - i = read(vca_pipes[0], ss, sizeof ss); - if (i == -1 && errno == EAGAIN) - return; - while (i >= sizeof ss[0]) { - CHECK_OBJ_NOTNULL(ss[j], SESS_MAGIC); - assert(ss[j]->fd >= 0); - AZ(ss[j]->obj); - VTAILQ_INSERT_TAIL(&sesshead, ss[j], list); - vca_kq_sess(ss[j], EV_ADD | EV_ONESHOT); - j++; - i -= sizeof ss[0]; - } - assert(i == 0); - return; - } - CAST_OBJ_NOTNULL(sp, kp->udata, SESS_MAGIC); - DSL(0x04, SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s", - sp, (unsigned long)kp->data, kp->flags, - (kp->flags & EV_EOF) ? " EOF" : ""); - - assert(sp->id == kp->ident); - assert(sp->fd == sp->id); - if (kp->data > 0) { - i = HTC_Rx(sp->htc); - if (i == 0) { - vca_kq_sess(sp, EV_ADD | EV_ONESHOT); - return; /* more needed */ - } - VTAILQ_REMOVE(&sesshead, sp, list); - vca_handover(sp, i); - return; - } else if (kp->flags & EV_EOF) { - VTAILQ_REMOVE(&sesshead, sp, list); - vca_close_session(sp, "EOF"); - SES_Delete(sp); - return; - } else { - VSL(SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s", - sp, (unsigned long)kp->data, kp->flags, - (kp->flags & EV_EOF) ? " EOF" : ""); - } -} - -/*--------------------------------------------------------------------*/ - -static void * -vca_kqueue_main(void *arg) -{ - struct kevent ke[NKEV], *kp; - int j, n, dotimer; - double deadline; - struct sess *sp; - - THR_SetName("cache-kqueue"); - (void)arg; - - kq = kqueue(); - assert(kq >= 0); - - j = 0; - EV_SET(&ke[j++], 0, EVFILT_TIMER, EV_ADD, 0, 100, NULL); - EV_SET(&ke[j++], vca_pipes[0], EVFILT_READ, EV_ADD, 0, 0, vca_pipes); - AZ(kevent(kq, ke, j, NULL, 0, NULL)); - - nki = 0; - while (1) { - dotimer = 0; - n = kevent(kq, ki, nki, ke, NKEV, NULL); - assert(n >= 1 && n <= NKEV); - nki = 0; - for (kp = ke, j = 0; j < n; j++, kp++) { - if (kp->filter == EVFILT_TIMER) { - dotimer = 1; - continue; - } - assert(kp->filter == EVFILT_READ); - vca_kev(kp); - } - if (!dotimer) - continue; - /* - * Make sure we have no pending changes for the fd's - * we are about to close, in case the accept(2) in the - * other thread creates new fd's betwen our close and - * the kevent(2) at the top of this loop, the kernel - * would not know we meant "the old fd of this number". - */ - vca_kq_flush(); - deadline = TIM_real() - params->sess_timeout; - for (;;) { - sp = VTAILQ_FIRST(&sesshead); - if (sp == NULL) - break; - if (sp->t_open > deadline) - break; - VTAILQ_REMOVE(&sesshead, sp, list); - vca_close_session(sp, "timeout"); - SES_Delete(sp); - } - } -} - -/*--------------------------------------------------------------------*/ - -static void -vca_kqueue_init(void) -{ - int i; - - i = fcntl(vca_pipes[0], F_GETFL); - assert(i != -1); - i |= O_NONBLOCK; - i = fcntl(vca_pipes[0], F_SETFL, i); - assert(i != -1); - - AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL)); -} - -struct acceptor acceptor_kqueue = { - .name = "kqueue", - .init = vca_kqueue_init, -}; - -#endif /* defined(HAVE_KQUEUE) */ Deleted: trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2009-02-12 22:26:44 UTC (rev 3757) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c 2009-02-13 09:19:50 UTC (rev 3758) @@ -1,167 +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 "shmlog.h" -#include "cache.h" -#include "cache_acceptor.h" - -static pthread_t vca_poll_thread; -static struct pollfd *pollfd; -static unsigned npoll, hpoll; - -static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); - -/*--------------------------------------------------------------------*/ - -static void -vca_pollspace(unsigned fd) -{ - struct pollfd *newpollfd = pollfd; - unsigned newnpoll; - - if (fd < npoll) - return; - newnpoll = npoll; - while (fd >= newnpoll) - newnpoll = newnpoll * 2 + 1; - VSL(SLT_Debug, 0, "Acceptor poll space increased to %u", newnpoll); - newpollfd = realloc(newpollfd, newnpoll * sizeof *newpollfd); - XXXAN(newpollfd); /* close offending fd */ - memset(newpollfd + npoll, 0, (newnpoll - npoll) * sizeof *newpollfd); - pollfd = newpollfd; - while (npoll < newnpoll) - pollfd[npoll++].fd = -1; -} - -/*--------------------------------------------------------------------*/ - -static void -vca_poll(int fd) -{ - - assert(fd >= 0); - vca_pollspace((unsigned)fd); - if (hpoll < fd) - hpoll = fd; - pollfd[fd].fd = fd; - pollfd[fd].events = POLLIN; -} - -static void -vca_unpoll(int fd) -{ - - assert(fd >= 0); - vca_pollspace((unsigned)fd); - pollfd[fd].fd = -1; - pollfd[fd].events = 0; - if (hpoll == fd) { - while (pollfd[--hpoll].fd == -1) - continue; - } -} - -/*--------------------------------------------------------------------*/ - -static void * -vca_main(void *arg) -{ - unsigned v; - struct sess *sp, *sp2; - double deadline; - int i, fd; - - THR_SetName("cache-poll"); - (void)arg; - - vca_poll(vca_pipes[0]); - - while (1) { - v = poll(pollfd, hpoll + 1, 100); - if (v && pollfd[vca_pipes[0]].revents) { - v--; - i = read(vca_pipes[0], &sp, sizeof sp); - assert(i == sizeof sp); - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - VTAILQ_INSERT_TAIL(&sesshead, sp, list); - vca_poll(sp->fd); - } - deadline = TIM_real() - params->sess_timeout; - VTAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) { - if (v == 0) - break; - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - fd = sp->fd; - if (pollfd[fd].revents) { - v--; - i = HTC_Rx(sp->htc); - VTAILQ_REMOVE(&sesshead, sp, list); - if (i == 0) { - VTAILQ_INSERT_HEAD(&sesshead, sp, list); - continue; - } - vca_unpoll(fd); - vca_handover(sp, i); - continue; - } - if (sp->t_open > deadline) - continue; - VTAILQ_REMOVE(&sesshead, sp, list); - vca_unpoll(fd); - vca_close_session(sp, "timeout"); - SES_Delete(sp); - } - } -} - -/*--------------------------------------------------------------------*/ - -static void -vca_poll_init(void) -{ - - AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL)); -} - -struct acceptor acceptor_poll = { - .name = "poll", - .init = vca_poll_init, -}; Deleted: trunk/varnish-cache/bin/varnishd/cache_acceptor_ports.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor_ports.c 2009-02-12 22:26:44 UTC (rev 3757) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor_ports.c 2009-02-13 09:19:50 UTC (rev 3758) @@ -1,171 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006 Linpro AS - * Copyright (c) 2007 OmniTI Computer Consulting, Inc. - * Copyright (c) 2007 Theo Schlossnagle - * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - * - * XXX: We need to pass sessions back into the event engine when they are - * reused. Not sure what the most efficient way is for that. For now - * write the session pointer to a pipe which the event engine monitors. - */ - -#include "config.h" -#if defined(HAVE_PORT_CREATE) - -#include -#include -#include -#include -#include - -#include - -#ifndef HAVE_CLOCK_GETTIME -#include "compat/clock_gettime.h" -#endif - -#include "shmlog.h" -#include "cache.h" -#include "cache_acceptor.h" - -#define MAX_EVENTS 256 -static pthread_t vca_ports_thread; -int solaris_dport = -1; - -static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); - -static void -vca_add(int fd, void *data) -{ - AZ(port_associate(solaris_dport, PORT_SOURCE_FD, fd, - POLLIN | POLLERR | POLLPRI, data)); -} - -static void -vca_del(int fd) -{ - port_dissociate(solaris_dport, PORT_SOURCE_FD, fd); -} - -static void -vca_port_ev(port_event_t *ev) { - struct sess *sp; - if(ev->portev_source == PORT_SOURCE_USER) { - sp = ev->portev_user; - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - assert(sp->fd >= 0); - AZ(sp->obj); - VTAILQ_INSERT_TAIL(&sesshead, sp, list); - vca_add(sp->fd, sp); - } else { - int i; - CAST_OBJ_NOTNULL(sp, ev->portev_user, SESS_MAGIC); - if(ev->portev_events & POLLERR) { - VTAILQ_REMOVE(&sesshead, sp, list); - vca_close_session(sp, "EOF"); - SES_Delete(sp); - return; - } - i = HTC_Rx(sp->htc); - if (i == 0) - return; - if (i > 0) { - VTAILQ_REMOVE(&sesshead, sp, list); - if (sp->fd != -1) - vca_del(sp->fd); - vca_handover(sp, i); - } - } - return; -} - -static void * -vca_main(void *arg) -{ - struct sess *sp; - - (void)arg; - - solaris_dport = port_create(); - assert(solaris_dport >= 0); - - while (1) { - port_event_t ev[MAX_EVENTS]; - int nevents, ei; - double deadline; - struct timespec ts; - ts.tv_sec = 0L; - ts.tv_nsec = 50L /*ms*/ * 1000L /*us*/ * 1000L /*ns*/; - nevents = 1; - if (port_getn(solaris_dport, ev, MAX_EVENTS, &nevents, &ts) - == 0) { - for (ei=0; eisess_timeout; - for (;;) { - sp = VTAILQ_FIRST(&sesshead); - if (sp == NULL) - break; - if (sp->t_open > deadline) - break; - VTAILQ_REMOVE(&sesshead, sp, list); - if(sp->fd != -1) - vca_del(sp->fd); - vca_close_session(sp, "timeout"); - SES_Delete(sp); - } - } -} - -static void -vca_ports_pass(struct sess *sp) -{ - int r; - while((r = port_send(solaris_dport, 0, sp)) == -1 && - errno == EAGAIN); - AZ(r); -} - -/*--------------------------------------------------------------------*/ - -static void -vca_ports_init(void) -{ - - AZ(pthread_create(&vca_ports_thread, NULL, vca_main, NULL)); -} - -struct acceptor acceptor_ports = { - .name = "ports", - .init = vca_ports_init, - .pass = vca_ports_pass -}; - -#endif /* defined(HAVE_PORT_CREATE) */ Copied: trunk/varnish-cache/bin/varnishd/cache_waiter.h (from rev 3755, trunk/varnish-cache/bin/varnishd/cache_acceptor.h) =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_waiter.h (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_waiter.h 2009-02-13 09:19:50 UTC (rev 3758) @@ -0,0 +1,60 @@ +/*- + * 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$ + */ + +struct sess; + +typedef void waiter_init_f(void); +typedef void waiter_pass_f(struct sess *); + +extern int vca_pipes[2]; + +struct waiter { + const char *name; + waiter_init_f *init; + waiter_pass_f *pass; +}; + +#if defined(HAVE_EPOLL_CTL) +extern struct waiter waiter_epoll; +#endif + +#if defined(HAVE_KQUEUE) +extern struct waiter waiter_kqueue; +#endif + +extern struct waiter waiter_poll; + +#if defined(HAVE_PORT_CREATE) +extern struct waiter waiter_ports; +#endif + +/* vca_acceptor.c */ +void vca_handover(struct sess *sp, int bad); Copied: trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c (from rev 3755, trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c) =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c 2009-02-13 09:19:50 UTC (rev 3758) @@ -0,0 +1,141 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * 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$ + * + * XXX: We need to pass sessions back into the event engine when they are + * reused. Not sure what the most efficient way is for that. For now + * write the session pointer to a pipe which the event engine monitors. + */ + +#include "config.h" + +#if defined(HAVE_EPOLL_CTL) + +#include +#include +#include +#include +#include + +#include + +#include "shmlog.h" +#include "cache.h" +#include "cache_waiter.h" + +static pthread_t vca_epoll_thread; +static int epfd = -1; + +static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); + +static void +vca_add(int fd, void *data) +{ + struct epoll_event ev = { EPOLLIN | EPOLLPRI, { data } }; + AZ(epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev)); +} + +static void +vca_del(int fd) +{ + struct epoll_event ev = { 0, { 0 } }; + AZ(epoll_ctl(epfd, EPOLL_CTL_DEL, fd, &ev)); +} + +static void * +vca_main(void *arg) +{ + struct epoll_event ev; + double deadline; + int dotimer = 0; + double last_timeout = 0, tmp_timeout; + struct sess *sp, *sp2; + int i; + + THR_SetName("cache-epoll"); + (void)arg; + + epfd = epoll_create(16); + assert(epfd >= 0); + + vca_add(vca_pipes[0], vca_pipes); + + while (1) { + if ((dotimer = epoll_wait(epfd, &ev, 1, 100)) > 0) { + if (ev.data.ptr == vca_pipes) { + i = read(vca_pipes[0], &sp, sizeof sp); + assert(i == sizeof sp); + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + VTAILQ_INSERT_TAIL(&sesshead, sp, list); + vca_add(sp->fd, sp); + } else { + CAST_OBJ_NOTNULL(sp, ev.data.ptr, SESS_MAGIC); + i = HTC_Rx(sp->htc); + if (i != 0) { + VTAILQ_REMOVE(&sesshead, sp, list); + vca_del(sp->fd); + vca_handover(sp, i); + } + } + } + tmp_timeout = TIM_mono(); + if ((tmp_timeout - last_timeout) > 60) { + last_timeout = tmp_timeout; + } else { + if (dotimer > 0) + continue; + } + + /* check for timeouts */ + deadline = TIM_real() - params->sess_timeout; + VTAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) { + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + if (sp->t_open > deadline) + continue; + VTAILQ_REMOVE(&sesshead, sp, list); + vca_del(sp->fd); + vca_close_session(sp, "timeout"); + SES_Delete(sp); + } + } +} + +/*--------------------------------------------------------------------*/ + +static void +vca_epoll_init(void) +{ + + AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL)); +} + +struct waiter waiter_epoll = { + .name = "epoll", + .init = vca_epoll_init, +}; + +#endif /* defined(HAVE_EPOLL_CTL) */ Copied: trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c (from rev 3755, trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c) =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c 2009-02-13 09:19:50 UTC (rev 3758) @@ -0,0 +1,225 @@ +/*- + * 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$ + * + * XXX: We need to pass sessions back into the event engine when they are + * reused. Not sure what the most efficient way is for that. For now + * write the session pointer to a pipe which the event engine monitors. + */ + +#include "config.h" + +#if defined(HAVE_KQUEUE) + +#include +#include +#include +#include +#include +#include + +#include + +#include "shmlog.h" +#include "cache.h" +#include "cache_waiter.h" + + +/**********************************************************************/ + + +static pthread_t vca_kqueue_thread; +static int kq = -1; + + +static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); + +#define NKEV 100 + +static struct kevent ki[NKEV]; +static unsigned nki; + +static void +vca_kq_flush(void) +{ + int i; + + if (nki == 0) + return; + i = kevent(kq, ki, nki, NULL, 0, NULL); + assert(i == 0); + nki = 0; +} + +static void +vca_kq_sess(struct sess *sp, short arm) +{ + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + assert(sp->fd >= 0); + DSL(0x04, SLT_Debug, sp->fd, "KQ: EV_SET sp %p arm %x", sp, arm); + EV_SET(&ki[nki], sp->fd, EVFILT_READ, arm, 0, 0, sp); + if (++nki == NKEV) + vca_kq_flush(); +} + +static void +vca_kev(const struct kevent *kp) +{ + int i, j; + struct sess *sp; + struct sess *ss[NKEV]; + + AN(kp->udata); + if (kp->udata == vca_pipes) { + j = 0; + i = read(vca_pipes[0], ss, sizeof ss); + if (i == -1 && errno == EAGAIN) + return; + while (i >= sizeof ss[0]) { + CHECK_OBJ_NOTNULL(ss[j], SESS_MAGIC); + assert(ss[j]->fd >= 0); + AZ(ss[j]->obj); + VTAILQ_INSERT_TAIL(&sesshead, ss[j], list); + vca_kq_sess(ss[j], EV_ADD | EV_ONESHOT); + j++; + i -= sizeof ss[0]; + } + assert(i == 0); + return; + } + CAST_OBJ_NOTNULL(sp, kp->udata, SESS_MAGIC); + DSL(0x04, SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s", + sp, (unsigned long)kp->data, kp->flags, + (kp->flags & EV_EOF) ? " EOF" : ""); + + assert(sp->id == kp->ident); + assert(sp->fd == sp->id); + if (kp->data > 0) { + i = HTC_Rx(sp->htc); + if (i == 0) { + vca_kq_sess(sp, EV_ADD | EV_ONESHOT); + return; /* more needed */ + } + VTAILQ_REMOVE(&sesshead, sp, list); + vca_handover(sp, i); + return; + } else if (kp->flags & EV_EOF) { + VTAILQ_REMOVE(&sesshead, sp, list); + vca_close_session(sp, "EOF"); + SES_Delete(sp); + return; + } else { + VSL(SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s", + sp, (unsigned long)kp->data, kp->flags, + (kp->flags & EV_EOF) ? " EOF" : ""); + } +} + +/*--------------------------------------------------------------------*/ + +static void * +vca_kqueue_main(void *arg) +{ + struct kevent ke[NKEV], *kp; + int j, n, dotimer; + double deadline; + struct sess *sp; + + THR_SetName("cache-kqueue"); + (void)arg; + + kq = kqueue(); + assert(kq >= 0); + + j = 0; + EV_SET(&ke[j++], 0, EVFILT_TIMER, EV_ADD, 0, 100, NULL); + EV_SET(&ke[j++], vca_pipes[0], EVFILT_READ, EV_ADD, 0, 0, vca_pipes); + AZ(kevent(kq, ke, j, NULL, 0, NULL)); + + nki = 0; + while (1) { + dotimer = 0; + n = kevent(kq, ki, nki, ke, NKEV, NULL); + assert(n >= 1 && n <= NKEV); + nki = 0; + for (kp = ke, j = 0; j < n; j++, kp++) { + if (kp->filter == EVFILT_TIMER) { + dotimer = 1; + continue; + } + assert(kp->filter == EVFILT_READ); + vca_kev(kp); + } + if (!dotimer) + continue; + /* + * Make sure we have no pending changes for the fd's + * we are about to close, in case the accept(2) in the + * other thread creates new fd's betwen our close and + * the kevent(2) at the top of this loop, the kernel + * would not know we meant "the old fd of this number". + */ + vca_kq_flush(); + deadline = TIM_real() - params->sess_timeout; + for (;;) { + sp = VTAILQ_FIRST(&sesshead); + if (sp == NULL) + break; + if (sp->t_open > deadline) + break; + VTAILQ_REMOVE(&sesshead, sp, list); + vca_close_session(sp, "timeout"); + SES_Delete(sp); + } + } +} + +/*--------------------------------------------------------------------*/ + +static void +vca_kqueue_init(void) +{ + int i; + + i = fcntl(vca_pipes[0], F_GETFL); + assert(i != -1); + i |= O_NONBLOCK; + i = fcntl(vca_pipes[0], F_SETFL, i); + assert(i != -1); + + AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL)); +} + +struct waiter waiter_kqueue = { + .name = "kqueue", + .init = vca_kqueue_init, +}; + +#endif /* defined(HAVE_KQUEUE) */ Copied: trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c (from rev 3755, trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c) =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c 2009-02-13 09:19:50 UTC (rev 3758) @@ -0,0 +1,167 @@ +/*- + * 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 "shmlog.h" +#include "cache.h" +#include "cache_waiter.h" + +static pthread_t vca_poll_thread; +static struct pollfd *pollfd; +static unsigned npoll, hpoll; + +static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); + +/*--------------------------------------------------------------------*/ + +static void +vca_pollspace(unsigned fd) +{ + struct pollfd *newpollfd = pollfd; + unsigned newnpoll; + + if (fd < npoll) + return; + newnpoll = npoll; + while (fd >= newnpoll) + newnpoll = newnpoll * 2 + 1; + VSL(SLT_Debug, 0, "Acceptor poll space increased to %u", newnpoll); + newpollfd = realloc(newpollfd, newnpoll * sizeof *newpollfd); + XXXAN(newpollfd); /* close offending fd */ + memset(newpollfd + npoll, 0, (newnpoll - npoll) * sizeof *newpollfd); + pollfd = newpollfd; + while (npoll < newnpoll) + pollfd[npoll++].fd = -1; +} + +/*--------------------------------------------------------------------*/ + +static void +vca_poll(int fd) +{ + + assert(fd >= 0); + vca_pollspace((unsigned)fd); + if (hpoll < fd) + hpoll = fd; + pollfd[fd].fd = fd; + pollfd[fd].events = POLLIN; +} + +static void +vca_unpoll(int fd) +{ + + assert(fd >= 0); + vca_pollspace((unsigned)fd); + pollfd[fd].fd = -1; + pollfd[fd].events = 0; + if (hpoll == fd) { + while (pollfd[--hpoll].fd == -1) + continue; + } +} + +/*--------------------------------------------------------------------*/ + +static void * +vca_main(void *arg) +{ + unsigned v; + struct sess *sp, *sp2; + double deadline; + int i, fd; + + THR_SetName("cache-poll"); + (void)arg; + + vca_poll(vca_pipes[0]); + + while (1) { + v = poll(pollfd, hpoll + 1, 100); + if (v && pollfd[vca_pipes[0]].revents) { + v--; + i = read(vca_pipes[0], &sp, sizeof sp); + assert(i == sizeof sp); + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + VTAILQ_INSERT_TAIL(&sesshead, sp, list); + vca_poll(sp->fd); + } + deadline = TIM_real() - params->sess_timeout; + VTAILQ_FOREACH_SAFE(sp, &sesshead, list, sp2) { + if (v == 0) + break; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + fd = sp->fd; + if (pollfd[fd].revents) { + v--; + i = HTC_Rx(sp->htc); + VTAILQ_REMOVE(&sesshead, sp, list); + if (i == 0) { + VTAILQ_INSERT_HEAD(&sesshead, sp, list); + continue; + } + vca_unpoll(fd); + vca_handover(sp, i); + continue; + } + if (sp->t_open > deadline) + continue; + VTAILQ_REMOVE(&sesshead, sp, list); + vca_unpoll(fd); + vca_close_session(sp, "timeout"); + SES_Delete(sp); + } + } +} + +/*--------------------------------------------------------------------*/ + +static void +vca_poll_init(void) +{ + + AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL)); +} + +struct waiter waiter_poll = { + .name = "poll", + .init = vca_poll_init, +}; Copied: trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c (from rev 3755, trunk/varnish-cache/bin/varnishd/cache_acceptor_ports.c) =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c 2009-02-13 09:19:50 UTC (rev 3758) @@ -0,0 +1,171 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006 Linpro AS + * Copyright (c) 2007 OmniTI Computer Consulting, Inc. + * Copyright (c) 2007 Theo Schlossnagle + * 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + * + * XXX: We need to pass sessions back into the event engine when they are + * reused. Not sure what the most efficient way is for that. For now + * write the session pointer to a pipe which the event engine monitors. + */ + +#include "config.h" +#if defined(HAVE_PORT_CREATE) + +#include +#include +#include +#include +#include + +#include + +#ifndef HAVE_CLOCK_GETTIME +#include "compat/clock_gettime.h" +#endif + +#include "shmlog.h" +#include "cache.h" +#include "cache_waiter.h" + +#define MAX_EVENTS 256 +static pthread_t vca_ports_thread; +int solaris_dport = -1; + +static VTAILQ_HEAD(,sess) sesshead = VTAILQ_HEAD_INITIALIZER(sesshead); + +static void +vca_add(int fd, void *data) +{ + AZ(port_associate(solaris_dport, PORT_SOURCE_FD, fd, + POLLIN | POLLERR | POLLPRI, data)); +} + +static void +vca_del(int fd) +{ + port_dissociate(solaris_dport, PORT_SOURCE_FD, fd); +} + +static void +vca_port_ev(port_event_t *ev) { + struct sess *sp; + if(ev->portev_source == PORT_SOURCE_USER) { + sp = ev->portev_user; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + assert(sp->fd >= 0); + AZ(sp->obj); + VTAILQ_INSERT_TAIL(&sesshead, sp, list); + vca_add(sp->fd, sp); + } else { + int i; + CAST_OBJ_NOTNULL(sp, ev->portev_user, SESS_MAGIC); + if(ev->portev_events & POLLERR) { + VTAILQ_REMOVE(&sesshead, sp, list); + vca_close_session(sp, "EOF"); + SES_Delete(sp); + return; + } + i = HTC_Rx(sp->htc); + if (i == 0) + return; + if (i > 0) { + VTAILQ_REMOVE(&sesshead, sp, list); + if (sp->fd != -1) + vca_del(sp->fd); + vca_handover(sp, i); + } + } + return; +} + +static void * +vca_main(void *arg) +{ + struct sess *sp; + + (void)arg; + + solaris_dport = port_create(); + assert(solaris_dport >= 0); + + while (1) { + port_event_t ev[MAX_EVENTS]; + int nevents, ei; + double deadline; + struct timespec ts; + ts.tv_sec = 0L; + ts.tv_nsec = 50L /*ms*/ * 1000L /*us*/ * 1000L /*ns*/; + nevents = 1; + if (port_getn(solaris_dport, ev, MAX_EVENTS, &nevents, &ts) + == 0) { + for (ei=0; eisess_timeout; + for (;;) { + sp = VTAILQ_FIRST(&sesshead); + if (sp == NULL) + break; + if (sp->t_open > deadline) + break; + VTAILQ_REMOVE(&sesshead, sp, list); + if(sp->fd != -1) + vca_del(sp->fd); + vca_close_session(sp, "timeout"); + SES_Delete(sp); + } + } +} + +static void +vca_ports_pass(struct sess *sp) +{ + int r; + while((r = port_send(solaris_dport, 0, sp)) == -1 && + errno == EAGAIN); + AZ(r); +} + +/*--------------------------------------------------------------------*/ + +static void +vca_ports_init(void) +{ + + AZ(pthread_create(&vca_ports_thread, NULL, vca_main, NULL)); +} + +struct waiter waiter_ports = { + .name = "ports", + .init = vca_ports_init, + .pass = vca_ports_pass +}; + +#endif /* defined(HAVE_PORT_CREATE) */ Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2009-02-12 22:26:44 UTC (rev 3757) +++ trunk/varnish-cache/bin/varnishd/common.h 2009-02-13 09:19:50 UTC (rev 3758) @@ -33,7 +33,7 @@ struct sockaddr; /* cache_acceptor.c */ -void VCA_tweak_acceptor(struct cli *cli, const char *arg); +void VCA_tweak_waiter(struct cli *cli, const char *arg); /* shmlog.c */ void VSL_Panic(int *len, char **ptr); Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2009-02-12 22:26:44 UTC (rev 3757) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2009-02-13 09:19:50 UTC (rev 3758) @@ -413,12 +413,12 @@ /*--------------------------------------------------------------------*/ static void -tweak_acceptor(struct cli *cli, const struct parspec *par, const char *arg) +tweak_waiter(struct cli *cli, const struct parspec *par, const char *arg) { /* XXX should have tweak_generic_string */ (void)par; - VCA_tweak_acceptor(cli, arg); + VCA_tweak_waiter(cli, arg); } /*--------------------------------------------------------------------*/ @@ -701,7 +701,7 @@ "completing.\n" "Setting this too high results in worker threads not doing " "anything for their keep, setting it too low just means that " - "more sessions take a detour around the acceptor.", + "more sessions take a detour around the waiter.", EXPERIMENTAL, "0", "ms" }, { "cli_buffer", tweak_uint, &master.cli_buffer, 4096, UINT_MAX, @@ -726,8 +726,8 @@ "SessionOpen shared memory record.\n", 0, "off", "bool" }, - { "acceptor", tweak_acceptor, NULL, 0, 0, - "Select the acceptor kernel interface.\n", + { "waiter", tweak_waiter, NULL, 0, 0, + "Select the waiter kernel interface.\n", EXPERIMENTAL | MUST_RESTART, "default", NULL }, { "diag_bitmap", tweak_diag_bitmap, 0, 0, 0, From phk at projects.linpro.no Fri Feb 13 09:25:34 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 10:25:34 +0100 (CET) Subject: r3759 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20090213092534.032231F7500@projects.linpro.no> Author: phk Date: 2009-02-13 10:25:33 +0100 (Fri, 13 Feb 2009) New Revision: 3759 Modified: trunk/varnish-cache/bin/varnishtest/tests/b00009.vtc Log: parameter name change "acceptor" -> "waiter" Modified: trunk/varnish-cache/bin/varnishtest/tests/b00009.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/b00009.vtc 2009-02-13 09:19:50 UTC (rev 3758) +++ trunk/varnish-cache/bin/varnishtest/tests/b00009.vtc 2009-02-13 09:25:33 UTC (rev 3759) @@ -7,7 +7,7 @@ txresp -hdr "Connection: close" -body "012345\n" } -start -varnish v1 -arg "-p acceptor=poll" -vcl+backend {} -start +varnish v1 -arg "-p waiter=poll" -vcl+backend {} -start client c1 { txreq -url "/" From phk at projects.linpro.no Fri Feb 13 09:38:58 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 10:38:58 +0100 (CET) Subject: r3760 - in trunk/varnish-cache: include lib/libvarnish Message-ID: <20090213093858.370C81F74FC@projects.linpro.no> Author: phk Date: 2009-02-13 10:38:57 +0100 (Fri, 13 Feb 2009) New Revision: 3760 Modified: trunk/varnish-cache/include/vlu.h trunk/varnish-cache/lib/libvarnish/vlu.c Log: Add VLU_Data() function for injecting input Modified: trunk/varnish-cache/include/vlu.h =================================================================== --- trunk/varnish-cache/include/vlu.h 2009-02-13 09:25:33 UTC (rev 3759) +++ trunk/varnish-cache/include/vlu.h 2009-02-13 09:38:57 UTC (rev 3760) @@ -36,6 +36,7 @@ struct vlu *VLU_New(void *priv, vlu_f *func, unsigned bufsize); int VLU_Fd(int fd, struct vlu *l); int VLU_File(FILE *f, struct vlu *l); +int VLU_Data(const void *ptr, int len, struct vlu *l); void VLU_Destroy(struct vlu *l); #endif Modified: trunk/varnish-cache/lib/libvarnish/vlu.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vlu.c 2009-02-13 09:25:33 UTC (rev 3759) +++ trunk/varnish-cache/lib/libvarnish/vlu.c 2009-02-13 09:38:57 UTC (rev 3760) @@ -134,3 +134,28 @@ l->bufp = strlen(l->buf); return (LineUpProcess(l)); } + +int +VLU_Data(const void *ptr, int len, struct vlu *l) +{ + const char *p; + int i; + + p = ptr; + CHECK_OBJ_NOTNULL(l, LINEUP_MAGIC); + if (len < 0) + len = strlen(p); + while (len > 0) { + i = len; + if (i > l->bufl - l->bufp) + i = l->bufl - l->bufp; + memcpy(l->buf + l->bufp, p, i); + l->bufp += i; + p += i; + len -= i; + i = LineUpProcess(l); + if (i) + break; + } + return (i); +} From phk at projects.linpro.no Fri Feb 13 09:49:11 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 10:49:11 +0100 (CET) Subject: r3761 - trunk/varnish-cache/lib/libvarnish Message-ID: <20090213094911.EC7611F74FC@projects.linpro.no> Author: phk Date: 2009-02-13 10:49:11 +0100 (Fri, 13 Feb 2009) New Revision: 3761 Modified: trunk/varnish-cache/lib/libvarnish/version.c Log: Update copyright year Modified: trunk/varnish-cache/lib/libvarnish/version.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/version.c 2009-02-13 09:38:57 UTC (rev 3760) +++ trunk/varnish-cache/lib/libvarnish/version.c 2009-02-13 09:49:11 UTC (rev 3761) @@ -43,5 +43,5 @@ fprintf(stderr, "%s (%s-%s)\n", progname, PACKAGE_TARNAME, PACKAGE_VERSION); fprintf(stderr, - "Copyright (c) 2006-2008 Linpro AS / Verdens Gang AS\n"); + "Copyright (c) 2006-2009 Linpro AS / Verdens Gang AS\n"); } From phk at projects.linpro.no Fri Feb 13 10:13:27 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 11:13:27 +0100 (CET) Subject: r3762 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20090213101327.5CE4E1F7500@projects.linpro.no> Author: phk Date: 2009-02-13 11:13:27 +0100 (Fri, 13 Feb 2009) New Revision: 3762 Modified: trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/include/cli.h Log: Add a "banner" command to the CLI interface. Add a parameter "cli_banner" (default on) which injects an implicit "banner" CLI command on all cli connections when opened. The net result is that you get a CLI response when you connect to the CLI ports: 200 193 ----------------------------- Varnish HTTP accelerator CLI. ----------------------------- Type 'help' for command list. Type 'quit' to close CLI session. Type 'start' to launch worker process. Presently the contents of the CLI response is "undefined", in the sense that you should not programatically depend on anything besides the "200" reply code. Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2009-02-13 09:49:11 UTC (rev 3761) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2009-02-13 10:13:27 UTC (rev 3762) @@ -195,6 +195,9 @@ /* Get rid of duplicate purges */ unsigned purge_dups; + + /* CLI banner */ + unsigned cli_banner; }; extern volatile struct params *params; Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2009-02-13 09:49:11 UTC (rev 3761) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2009-02-13 10:13:27 UTC (rev 3762) @@ -553,9 +553,7 @@ start_child(NULL); if (child_state == CH_STOPPED) exit(2); - } else - fprintf(stderr, - "Debugging mode, enter \"start\" to start child\n"); + } i = vev_schedule(mgt_evb); if (i != 0) Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-13 09:49:11 UTC (rev 3761) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-13 10:13:27 UTC (rev 3762) @@ -126,9 +126,28 @@ /*--------------------------------------------------------------------*/ +static void +mcf_banner(struct cli *cli, const char *const *av, void *priv) +{ + + (void)av; + (void)priv; + cli_out(cli, "-----------------------------\n"); + cli_out(cli, "Varnish HTTP accelerator CLI.\n"); + cli_out(cli, "-----------------------------\n"); + cli_out(cli, "Type 'help' for command list.\n"); + cli_out(cli, "Type 'quit' to close CLI session.\n"); + if (child_pid < 0) + cli_out(cli, "Type 'start' to launch worker process.\n"); + cli_result(cli, CLIS_OK); +} + +/*--------------------------------------------------------------------*/ + /* XXX: what order should this list be in ? */ static struct cli_proto cli_proto[] = { { CLI_HELP, mcf_help, cli_proto }, + { CLI_BANNER, mcf_banner, NULL }, { CLI_PING, cli_func_ping }, { CLI_SERVER_STATUS, mcf_server_status, NULL }, { CLI_SERVER_START, mcf_server_startstop, NULL }, @@ -250,8 +269,6 @@ return (0); cli_dispatch(cp->cli, cli_proto, p); - vsb_finish(cp->cli->sb); - AZ(vsb_overflowed(cp->cli->sb)); if (cp->cli->result == CLIS_UNKNOWN) { /* * Command not recognized in master, try cacher if it is @@ -275,9 +292,9 @@ cli_out(cp->cli, "%s", q); free(q); } - vsb_finish(cp->cli->sb); - AZ(vsb_overflowed(cp->cli->sb)); } + vsb_finish(cp->cli->sb); + AZ(vsb_overflowed(cp->cli->sb)); /* send the result back */ syslog(LOG_INFO, "CLI %d result %d \"%s\"", @@ -372,6 +389,9 @@ cp->cli->sb = vsb_newauto(); XXXAN(cp->cli->sb); + if (params->cli_banner) + (void)VLU_Data("banner\n", -1, cp->vlu); + cp->ev = calloc(sizeof *cp->ev, 1); cp->ev->name = cp->name; cp->ev->fd = fdi; Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2009-02-13 09:49:11 UTC (rev 3761) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2009-02-13 10:13:27 UTC (rev 3762) @@ -757,6 +757,11 @@ "Detect and eliminate duplicate purges.\n", 0, "off", "bool" }, + { "cli_banner", tweak_bool, &master.cli_banner, 0, 0, + "Emit CLI banner on connect.\n" + "Set to off for compatibility with pre 2.1 versions.\n", + 0, + "on", "bool" }, { NULL, NULL, NULL } }; Modified: trunk/varnish-cache/include/cli.h =================================================================== --- trunk/varnish-cache/include/cli.h 2009-02-13 09:49:11 UTC (rev 3761) +++ trunk/varnish-cache/include/cli.h 2009-02-13 10:13:27 UTC (rev 3762) @@ -225,6 +225,12 @@ "\tCheck status of Varnish cache process.", \ 0, 0 +#define CLI_BANNER \ + "banner", \ + "banner", \ + "\tPrint welcome banner.", \ + 0, 0 + #define CLI_HIDDEN(foo, min_arg, max_arg) \ foo, NULL, NULL, min_arg, max_arg, From phk at projects.linpro.no Fri Feb 13 10:35:46 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 11:35:46 +0100 (CET) Subject: r3763 - trunk/varnish-cache/bin/varnishtest Message-ID: <20090213103546.6600B1F7505@projects.linpro.no> Author: phk Date: 2009-02-13 11:35:46 +0100 (Fri, 13 Feb 2009) New Revision: 3763 Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Disable CLI banner when running tests. Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-13 10:13:27 UTC (rev 3762) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-13 10:35:46 UTC (rev 3763) @@ -207,6 +207,7 @@ AN(vsb); vsb_printf(vsb, "cd ../varnishd &&"); vsb_printf(vsb, " ./varnishd -d -d -n /tmp/__%s", v->name); + vsb_printf(vsb, " -p cli_banner=off); vsb_printf(vsb, " -a '%s' -T %s", v->accept, v->telnet); vsb_printf(vsb, " -P /tmp/__%s/varnishd.pid", v->name); vsb_printf(vsb, " %s", v->args); From phk at projects.linpro.no Fri Feb 13 10:38:22 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 11:38:22 +0100 (CET) Subject: r3764 - trunk/varnish-cache/bin/varnishtest Message-ID: <20090213103822.B04121F7500@projects.linpro.no> Author: phk Date: 2009-02-13 11:38:22 +0100 (Fri, 13 Feb 2009) New Revision: 3764 Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: vi(1) 'x' key misfire. Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-13 10:35:46 UTC (rev 3763) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-13 10:38:22 UTC (rev 3764) @@ -207,7 +207,7 @@ AN(vsb); vsb_printf(vsb, "cd ../varnishd &&"); vsb_printf(vsb, " ./varnishd -d -d -n /tmp/__%s", v->name); - vsb_printf(vsb, " -p cli_banner=off); + vsb_printf(vsb, " -p cli_banner=off"); vsb_printf(vsb, " -a '%s' -T %s", v->accept, v->telnet); vsb_printf(vsb, " -P /tmp/__%s/varnishd.pid", v->name); vsb_printf(vsb, " %s", v->args); From phk at projects.linpro.no Fri Feb 13 10:46:15 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 11:46:15 +0100 (CET) Subject: r3765 - trunk/varnish-cache/bin/varnishd Message-ID: <20090213104615.286381F7508@projects.linpro.no> Author: phk Date: 2009-02-13 11:46:14 +0100 (Fri, 13 Feb 2009) New Revision: 3765 Modified: trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Don't copy the debug flag around, make it a global instead. Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2009-02-13 10:38:22 UTC (rev 3764) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2009-02-13 10:46:14 UTC (rev 3765) @@ -37,9 +37,10 @@ struct cli; extern struct vev_base *mgt_evb; +extern unsigned d_flag; /* mgt_child.c */ -void mgt_run(int dflag, const char *T_arg); +void mgt_run(const char *T_arg); extern pid_t mgt_pid, child_pid; void mgt_stop_child(void); @@ -49,7 +50,7 @@ int mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...); void mgt_cli_start_child(int fdi, int fdo); void mgt_cli_stop_child(void); -void mgt_cli_telnet(int dflag, const char *T_arg); +void mgt_cli_telnet(const char *T_arg); /* mgt_param.c */ void MCF_ParamSync(void); Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2009-02-13 10:38:22 UTC (rev 3764) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2009-02-13 10:46:14 UTC (rev 3765) @@ -499,7 +499,7 @@ */ void -mgt_run(int dflag, const char *T_arg) +mgt_run(const char *T_arg) { struct sigaction sac; struct vev *e; @@ -510,11 +510,11 @@ mgt_evb = vev_new_base(); XXXAN(mgt_evb); - if (dflag) + if (d_flag) mgt_cli_setup(0, 1, 1, "debug"); if (T_arg) - mgt_cli_telnet(dflag, T_arg); + mgt_cli_telnet(T_arg); e = vev_new(); XXXAN(e); @@ -547,9 +547,9 @@ AZ(sigaction(SIGPIPE, &sac, NULL)); AZ(sigaction(SIGHUP, &sac, NULL)); - if (!dflag && !mgt_has_vcl()) + if (!d_flag && !mgt_has_vcl()) REPORT0(LOG_ERR, "No VCL loaded yet"); - else if (!dflag) { + else if (!d_flag) { start_child(NULL); if (child_state == CH_STOPPED) exit(2); Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-13 10:38:22 UTC (rev 3764) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-13 10:46:14 UTC (rev 3765) @@ -74,8 +74,6 @@ static void telnet_close_all(void); static void telnet_close_one(int fd); -static int dflag_copy; - /*--------------------------------------------------------------------*/ static void @@ -335,7 +333,7 @@ (void)close(2); assert(open("/dev/null", O_WRONLY) == 2); - if (dflag_copy == 2) { + if (d_flag == 2) { mgt_stop_child(); telnet_close_all(); } @@ -475,15 +473,13 @@ } void -mgt_cli_telnet(int dflag, const char *T_arg) +mgt_cli_telnet(const char *T_arg) { struct vss_addr **ta; char *addr, *port; int i, n, sock, good; struct telnet *tn; - dflag_copy = dflag; - XXXAZ(VSS_parse(T_arg, &addr, &port)); n = VSS_resolve(addr, port, &ta); if (n == 0) { Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2009-02-13 10:38:22 UTC (rev 3764) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2009-02-13 10:46:14 UTC (rev 3765) @@ -78,6 +78,7 @@ struct heritage heritage; volatile struct params *params; +unsigned d_flag = 0; /*--------------------------------------------------------------------*/ @@ -420,7 +421,6 @@ { int o; unsigned C_flag = 0; - unsigned d_flag = 0; unsigned F_flag = 0; const char *b_arg = NULL; const char *f_arg = NULL; @@ -636,7 +636,7 @@ if (pfh != NULL && vpf_write(pfh)) fprintf(stderr, "NOTE: Could not write PID file\n"); - mgt_run(d_flag, T_arg); + mgt_run(T_arg); if (pfh != NULL) (void)vpf_remove(pfh); From phk at projects.linpro.no Fri Feb 13 11:10:37 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 12:10:37 +0100 (CET) Subject: r3766 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20090213111037.D60151F7508@projects.linpro.no> Author: phk Date: 2009-02-13 12:10:37 +0100 (Fri, 13 Feb 2009) New Revision: 3766 Modified: trunk/varnish-cache/bin/varnishtest/tests/c00014.vtc Log: Use semaphores instead of delays Modified: trunk/varnish-cache/bin/varnishtest/tests/c00014.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00014.vtc 2009-02-13 10:46:14 UTC (rev 3765) +++ trunk/varnish-cache/bin/varnishtest/tests/c00014.vtc 2009-02-13 11:10:37 UTC (rev 3766) @@ -5,10 +5,9 @@ server s1 { rxreq expect req.url == "/foo" + sema r1 sync 2 send "HTTP/1.1 200 Ok\r\nContent-Length: 12\r\n\r\n" - delay .5 send "line1\n" - delay .5 send "line2\n" rxreq @@ -29,11 +28,15 @@ expect resp.http.content-length == 12 expect resp.http.x-varnish == "1001" } -start -delay .2 +sema r1 sync 2 client c2 { txreq -url "/foo" rxresp expect resp.status == 200 expect resp.http.content-length == 6 expect resp.http.x-varnish == "1002" -} -start +} -run + +client c1 -wait + +varnish v1 -expect cache_hitpass == 1 From phk at projects.linpro.no Fri Feb 13 12:16:34 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 13:16:34 +0100 (CET) Subject: r3767 - trunk/varnish-cache/bin/varnishd Message-ID: <20090213121634.865A73833B@projects.linpro.no> Author: phk Date: 2009-02-13 13:16:34 +0100 (Fri, 13 Feb 2009) New Revision: 3767 Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c trunk/varnish-cache/bin/varnishd/mgt_cli.c Log: Add two hidden CLI commands for panic'ing the master and worker process. Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_cli.c 2009-02-13 11:10:37 UTC (rev 3766) +++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2009-02-13 12:16:34 UTC (rev 3767) @@ -223,6 +223,18 @@ /*--------------------------------------------------------------------*/ +static void +ccf_panic(struct cli *cli, const char * const *av, void *priv) +{ + + (void)cli; + (void)av; + (void)priv; + assert(!strcmp("", "You asked for it")); +} + +/*--------------------------------------------------------------------*/ + static struct cli_proto master_cmds[] = { { CLI_PING, cli_func_ping }, { CLI_HELP, ccf_help, NULL }, @@ -233,6 +245,9 @@ { "debug.sizeof", "debug.sizeof", "\tDump sizeof various data structures\n", 0, 0, cli_debug_sizeof }, + { "debug.panic.worker", "debug.panic.worker", + "\tPanic the worker process.\n", + 0, 0, ccf_panic }, { NULL } }; Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-13 11:10:37 UTC (rev 3766) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-13 12:16:34 UTC (rev 3767) @@ -161,14 +161,29 @@ { CLI_PARAM_SET, mcf_param_set, NULL }, { CLI_QUIT, mcf_close, NULL}, -#if 0 - { CLI_SERVER_RESTART }, - { CLI_ZERO }, - { CLI_VERBOSE, m_cli_func_verbose, NULL }, -#endif { NULL } }; +/*--------------------------------------------------------------------*/ + + +static void +mcf_panic(struct cli *cli, const char * const *av, void *priv) +{ + + (void)cli; + (void)av; + (void)priv; + assert(!strcmp("", "You asked for it")); +} + +static struct cli_proto cli_debug[] = { + { "debug.panic.master", "debug.panic.master", + "\tPanic the master process.\n", + 0, 0, mcf_panic, NULL}, + { NULL } +}; + /*-------------------------------------------------------------------- * Ask the child something over CLI, return zero only if everything is * happy happy. @@ -267,6 +282,8 @@ return (0); cli_dispatch(cp->cli, cli_proto, p); + if (cp->cli->result == CLIS_UNKNOWN) + cli_dispatch(cp->cli, cli_debug, p); if (cp->cli->result == CLIS_UNKNOWN) { /* * Command not recognized in master, try cacher if it is From phk at projects.linpro.no Fri Feb 13 13:42:44 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 14:42:44 +0100 (CET) Subject: r3768 - trunk/varnish-cache/bin/varnishd Message-ID: <20090213134244.8E2201F74F4@projects.linpro.no> Author: phk Date: 2009-02-13 14:42:44 +0100 (Fri, 13 Feb 2009) New Revision: 3768 Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c Log: Make sure to clean the VBE properly before releasing it. Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-02-13 12:16:34 UTC (rev 3767) +++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2009-02-13 13:42:44 UTC (rev 3768) @@ -112,8 +112,11 @@ ASSERT_CLI(); VTAILQ_FOREACH_SAFE(vbe, &b->connlist, list, vbe2) { VTAILQ_REMOVE(&b->connlist, vbe, list); - if (vbe->fd >= 0) + if (vbe->fd >= 0) { AZ(close(vbe->fd)); + vbe->fd = -1; + } + vbe->backend = NULL; VBE_ReleaseConn(vbe); } if (b->probe != NULL) From phk at projects.linpro.no Fri Feb 13 13:43:30 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 13 Feb 2009 14:43:30 +0100 (CET) Subject: r3769 - in trunk/varnish-cache/bin/varnishtest: . tests Message-ID: <20090213134330.98BE91F74F4@projects.linpro.no> Author: phk Date: 2009-02-13 14:43:30 +0100 (Fri, 13 Feb 2009) New Revision: 3769 Modified: trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: To prevent masking bugs, disable auto_restart by default. Enable it explicitly in the one testcase where we check that it works. Modified: trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc 2009-02-13 13:42:44 UTC (rev 3768) +++ trunk/varnish-cache/bin/varnishtest/tests/v00010.vtc 2009-02-13 13:43:30 UTC (rev 3769) @@ -17,9 +17,14 @@ panic "Had Panic header: " obj.http.panic; } } -} -start -cli "param.set diag_bitmap 0x00001000" +} -start +varnish v1 -cliok "param.set diag_bitmap 0x00001000" +# varnishtest defaults to auto_restart off, to avoid masking bugs. +varnish v1 -cliok "param.set auto_restart on" + + client c1 { txreq -url "/" rxresp Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-13 13:42:44 UTC (rev 3768) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-13 13:43:30 UTC (rev 3769) @@ -208,6 +208,7 @@ vsb_printf(vsb, "cd ../varnishd &&"); vsb_printf(vsb, " ./varnishd -d -d -n /tmp/__%s", v->name); vsb_printf(vsb, " -p cli_banner=off"); + vsb_printf(vsb, " -p auto_restart=off"); vsb_printf(vsb, " -a '%s' -T %s", v->accept, v->telnet); vsb_printf(vsb, " -P /tmp/__%s/varnishd.pid", v->name); vsb_printf(vsb, " %s", v->args); From phk at projects.linpro.no Mon Feb 16 13:38:39 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 16 Feb 2009 14:38:39 +0100 (CET) Subject: r3770 - trunk/varnish-cache/bin/varnishd Message-ID: <20090216133839.D42041F74E1@projects.linpro.no> Author: phk Date: 2009-02-16 14:38:39 +0100 (Mon, 16 Feb 2009) New Revision: 3770 Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h Log: Reduce objhead size by overloading. Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-13 13:43:30 UTC (rev 3769) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-16 13:38:39 UTC (rev 3770) @@ -76,17 +76,12 @@ VTAILQ_HEAD(,objcore) objcs; char *hash; unsigned char digest[DIGEST_LEN]; -#ifndef NOT_YET union { VTAILQ_HEAD(, sess) __u_waitinglist; VTAILQ_ENTRY(objhead) __u_coollist; } __u; #define waitinglist __u.__u_waitinglist #define coollist __u.__u_coollist -#else - VTAILQ_HEAD(, sess) waitinglist; - VTAILQ_ENTRY(objhead) coollist; -#endif /*---------------------------------------------------- * The fields below are for the sole private use of From des at projects.linpro.no Mon Feb 16 13:40:29 2009 From: des at projects.linpro.no (des at projects.linpro.no) Date: Mon, 16 Feb 2009 14:40:29 +0100 (CET) Subject: r3771 - trunk/varnish-cache/bin/varnishtest Message-ID: <20090216134029.7BEAE3833B@projects.linpro.no> Author: des Date: 2009-02-16 14:40:29 +0100 (Mon, 16 Feb 2009) New Revision: 3771 Modified: trunk/varnish-cache/bin/varnishtest/varnishtest.1 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_sema.c trunk/varnish-cache/bin/varnishtest/vtc_server.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Correct copyright and attribution. Approved by: phk, ssm Modified: trunk/varnish-cache/bin/varnishtest/varnishtest.1 =================================================================== --- trunk/varnish-cache/bin/varnishtest/varnishtest.1 2009-02-16 13:38:39 UTC (rev 3770) +++ trunk/varnish-cache/bin/varnishtest/varnishtest.1 2009-02-16 13:40:29 UTC (rev 3771) @@ -1,5 +1,5 @@ .\"- -.\" Copyright (c) 2006-2008 Linpro AS +.\" Copyright (c) 2008-2009 Linpro AS .\" All rights reserved. .\" .\" Author: Stig Sandbeck Mathisen @@ -27,7 +27,7 @@ .\" .\" $Id$ .\" -.Dd October 29, 2008 +.Dd February 13, 2009 .Dt VARNISHTEST 1 .Os .Sh NAME @@ -201,8 +201,8 @@ ---- c1 EXPECT resp.status (200) == 201 (201) failed .Ed .Sh SEE ALSO +.Xr varnishhist 1 , .Xr varnishlog 1 , -.Xr varnishhist 1 , .Xr varnishncsa 1 , .Xr varnishstat 1 , .Xr varnishtop 1 , @@ -212,8 +212,8 @@ .Nm program was developed by .An Poul-Henning Kamp Aq phk at phk.freebsd.dk -in cooperation with Verdens Gang AS and Linpro AS. This manual page -was written by +in cooperation with Linpro AS. +This manual page was written by .An Stig Sandbeck Mathisen Aq ssm at linpro.no using examples by -.An Poul-Henning Kamp Aq phk at phk.freebsd.dk +.An Poul-Henning Kamp Aq phk at phk.freebsd.dk . Modified: trunk/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.c 2009-02-16 13:38:39 UTC (rev 3770) +++ trunk/varnish-cache/bin/varnishtest/vtc.c 2009-02-16 13:40:29 UTC (rev 3771) @@ -1,7 +1,9 @@ /* - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2008-2009 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: Modified: trunk/varnish-cache/bin/varnishtest/vtc.h =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.h 2009-02-16 13:38:39 UTC (rev 3770) +++ trunk/varnish-cache/bin/varnishtest/vtc.h 2009-02-16 13:40:29 UTC (rev 3771) @@ -1,7 +1,9 @@ /* - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2008-2009 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: Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_client.c 2009-02-16 13:38:39 UTC (rev 3770) +++ trunk/varnish-cache/bin/varnishtest/vtc_client.c 2009-02-16 13:40:29 UTC (rev 3771) @@ -1,7 +1,9 @@ /* - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2008-2009 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: Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2009-02-16 13:38:39 UTC (rev 3770) +++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2009-02-16 13:40:29 UTC (rev 3771) @@ -1,7 +1,9 @@ /* - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2008-2009 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: Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_log.c 2009-02-16 13:38:39 UTC (rev 3770) +++ trunk/varnish-cache/bin/varnishtest/vtc_log.c 2009-02-16 13:40:29 UTC (rev 3771) @@ -1,7 +1,9 @@ /* - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2008-2009 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: Modified: trunk/varnish-cache/bin/varnishtest/vtc_sema.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_sema.c 2009-02-16 13:38:39 UTC (rev 3770) +++ trunk/varnish-cache/bin/varnishtest/vtc_sema.c 2009-02-16 13:40:29 UTC (rev 3771) @@ -1,7 +1,9 @@ /* - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2008-2009 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: Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_server.c 2009-02-16 13:38:39 UTC (rev 3770) +++ trunk/varnish-cache/bin/varnishtest/vtc_server.c 2009-02-16 13:40:29 UTC (rev 3771) @@ -1,7 +1,9 @@ /* - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2008-2009 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: Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-16 13:38:39 UTC (rev 3770) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-16 13:40:29 UTC (rev 3771) @@ -1,7 +1,9 @@ /* - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2008-2009 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: From phk at projects.linpro.no Mon Feb 16 14:22:00 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 16 Feb 2009 15:22:00 +0100 (CET) Subject: r3772 - trunk/varnish-cache/bin/varnishd Message-ID: <20090216142200.8F9521F74E5@projects.linpro.no> Author: phk Date: 2009-02-16 15:22:00 +0100 (Mon, 16 Feb 2009) New Revision: 3772 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_expire.c Log: Compress objcore a bit more by squezing 32 bit fields to 8 bit, still leaving plenty of space. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-16 13:40:29 UTC (rev 3771) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-16 14:22:00 UTC (rev 3772) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2006-2009 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp @@ -262,11 +262,14 @@ #define OBJCORE_MAGIC 0x4d301302 struct object *obj; double timer_when; - const char *timer_what; + unsigned char timer_what; +#define OC_T_TTL 1 +#define OC_T_PREFETCH 2 + unsigned char flags; +#define OC_F_ONLRU (1<<0) unsigned timer_idx; VTAILQ_ENTRY(objcore) list; VTAILQ_ENTRY(objcore) lru_list; - int on_lru; }; /* Object structure --------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-16 13:40:29 UTC (rev 3771) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-16 14:22:00 UTC (rev 3772) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2006-2009 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp @@ -63,14 +63,16 @@ #include "vcl.h" #include "hash_slinger.h" -static const char * const tmr_prefetch = "prefetch"; -static const char * const tmr_ttl = "ttl"; - static pthread_t exp_thread; static struct binheap *exp_heap; static struct lock exp_mtx; static VTAILQ_HEAD(,objcore) lru = VTAILQ_HEAD_INITIALIZER(lru); +static const char *timer_what[] = { + [OC_T_TTL] = "TTL", + [OC_T_PREFETCH] = "Prefetch", +}; + /* * This is a magic marker for the objects currently on the SIOP [look it up] * so that other users of the object will not stumble trying to change the @@ -87,7 +89,7 @@ { struct objcore *oc; double when; - const char *what; + unsigned char what; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oc = o->objcore; @@ -96,14 +98,14 @@ if (o->prefetch < 0.0) { when = o->ttl + o->prefetch; - what = tmr_prefetch; + what = OC_T_PREFETCH; } else if (o->prefetch > 0.0) { assert(o->prefetch <= o->ttl); when = o->prefetch; - what = tmr_prefetch; + what = OC_T_PREFETCH; } else { when = o->ttl + HSH_Grace(o->grace); - what = tmr_ttl; + what = OC_T_TTL; } assert(!isnan(when)); oc->timer_what = what; @@ -140,7 +142,7 @@ binheap_insert(exp_heap, oc); assert(oc->timer_idx != BINHEAP_NOIDX); VTAILQ_INSERT_TAIL(&lru, oc, lru_list); - oc->on_lru = 1; + oc->flags |= OC_F_ONLRU; Lck_Unlock(&exp_mtx); } @@ -166,7 +168,7 @@ CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); if (Lck_Trylock(&exp_mtx)) return (retval); - if (oc->on_lru) { + if (oc->flags & OC_F_ONLRU) { VTAILQ_REMOVE(&lru, oc, lru_list); VTAILQ_INSERT_TAIL(&lru, oc, lru_list); VSL_stats->n_lru_moved++; @@ -273,12 +275,13 @@ } } - assert(oc->on_lru); + assert(oc->flags & OC_F_ONLRU); Lck_Unlock(&exp_mtx); - WSL(&ww, SLT_ExpPick, 0, "%u %s", o->xid, oc->timer_what); + WSL(&ww, SLT_ExpPick, 0, "%u %s", o->xid, + timer_what[oc->timer_what]); - if (oc->timer_what == tmr_prefetch) { + if (oc->timer_what == OC_T_PREFETCH) { o->prefetch = 0.0; sp->obj = o; VCL_prefetch_method(sp); @@ -294,7 +297,7 @@ assert(oc->timer_idx != BINHEAP_NOIDX); Lck_Unlock(&exp_mtx); } else { - assert(oc->timer_what == tmr_ttl); + assert(oc->timer_what == OC_T_TTL); sp->obj = o; VCL_timeout_method(sp); sp->obj = NULL; @@ -305,7 +308,7 @@ Lck_Lock(&exp_mtx); assert(oc->timer_idx == BINHEAP_NOIDX); VTAILQ_REMOVE(&lru, o->objcore, lru_list); - oc->on_lru = 0; + oc->flags &= ~OC_F_ONLRU; VSL_stats->n_expired++; Lck_Unlock(&exp_mtx); HSH_Deref(&o); @@ -353,7 +356,7 @@ * actions below. */ VTAILQ_REMOVE(&lru, oc, lru_list); - oc->on_lru = 0; + oc->flags &= ~OC_F_ONLRU; binheap_delete(exp_heap, oc->timer_idx); assert(oc->timer_idx == BINHEAP_NOIDX); VSL_stats->n_lru_nuked++; @@ -389,7 +392,7 @@ binheap_insert(exp_heap, oc); assert(oc->timer_idx != BINHEAP_NOIDX); VTAILQ_INSERT_TAIL(&lru, oc, lru_list); - oc->on_lru = 1; + oc->flags |= OC_F_ONLRU; Lck_Unlock(&exp_mtx); return (0); } From phk at projects.linpro.no Mon Feb 16 15:06:18 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 16 Feb 2009 16:06:18 +0100 (CET) Subject: r3773 - trunk/varnish-cache/bin/varnishd Message-ID: <20090216150618.8FCC138707@projects.linpro.no> Author: phk Date: 2009-02-16 16:06:18 +0100 (Mon, 16 Feb 2009) New Revision: 3773 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Move the object busy flag up to the objcore. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-16 14:22:00 UTC (rev 3772) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-16 15:06:18 UTC (rev 3773) @@ -267,6 +267,7 @@ #define OC_T_PREFETCH 2 unsigned char flags; #define OC_F_ONLRU (1<<0) +#define OC_F_BUSY (1<<1) unsigned timer_idx; VTAILQ_ENTRY(objcore) list; VTAILQ_ENTRY(objcore) lru_list; @@ -294,7 +295,6 @@ unsigned cacheable; - unsigned busy; unsigned len; double age; @@ -416,7 +416,6 @@ /* Prototypes etc ----------------------------------------------------*/ - /* cache_acceptor.c */ void vca_return_session(struct sess *sp); void vca_close_session(struct sess *sp, const char *why); @@ -698,3 +697,11 @@ t->b = t->e; } } + +static inline unsigned +ObjIsBusy(const struct object *o) +{ + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC); + return (o->objcore->flags & OC_F_BUSY); +} Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-16 14:22:00 UTC (rev 3772) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-16 15:06:18 UTC (rev 3773) @@ -601,7 +601,7 @@ sp->obj = o; /* If we inserted a new object it's a miss */ - if (sp->obj->busy) { + if (ObjIsBusy(sp->obj)) { VSL_stats->cache_miss++; sp->step = STP_MISS; return (0); @@ -730,7 +730,6 @@ HSH_Prealloc(sp); sp->obj = sp->wrk->nobj; sp->wrk->nobj = NULL; - sp->obj->busy = 1; sp->sendbody = 1; sp->step = STP_FETCH; return (0); Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-16 14:22:00 UTC (rev 3772) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-16 15:06:18 UTC (rev 3773) @@ -128,7 +128,7 @@ struct objcore *oc; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - assert(o->busy); + AN(ObjIsBusy(o)); assert(o->cacheable); HSH_Ref(o); CHECK_OBJ_NOTNULL(o->objcore, OBJCORE_MAGIC); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-16 14:22:00 UTC (rev 3772) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2009-02-16 15:06:18 UTC (rev 3773) @@ -326,7 +326,8 @@ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC); AN(sp->director); - AN(sp->obj->busy); + if (sp->obj->objcore != NULL) /* pass has no objcore */ + AN(ObjIsBusy(sp->obj)); AN(sp->bereq); w = sp->wrk; bereq = sp->bereq; Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-16 14:22:00 UTC (rev 3772) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-16 15:06:18 UTC (rev 3773) @@ -96,6 +96,7 @@ if (w->nobjcore == NULL) { ALLOC_OBJ(oc, OBJCORE_MAGIC); w->nobjcore = oc; + oc->flags |= OC_F_BUSY; } CHECK_OBJ_NOTNULL(w->nobjcore, OBJCORE_MAGIC); @@ -126,7 +127,6 @@ http_Setup(o->http, o->ws_o); o->magic = OBJECT_MAGIC; o->http->magic = HTTP_MAGIC; - o->busy = 1; o->refcnt = 1; o->grace = NAN; o->entered = NAN; @@ -269,7 +269,7 @@ o = oc->obj; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - if (o->busy) { + if (ObjIsBusy(o)) { busy_o = o; continue; } @@ -377,7 +377,7 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); o = sp->obj; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - assert(o->busy); + AN(ObjIsBusy(o)); assert(o->refcnt > 0); o->ttl = 0; o->cacheable = 0; @@ -395,7 +395,7 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); o = sp->obj; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - assert(o->busy); + AN(ObjIsBusy(o)); assert(o->refcnt > 0); if (o->ws_o->overflow) VSL_stats->n_objoverflow++; @@ -408,7 +408,7 @@ CHECK_OBJ(oh, OBJHEAD_MAGIC); Lck_Lock(&oh->mtx); } - o->busy = 0; + o->objcore->flags &= ~OC_F_BUSY; if (oh != NULL) hsh_rush(oh); parent = o->parent; Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-16 14:22:00 UTC (rev 3772) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-16 15:06:18 UTC (rev 3773) @@ -643,8 +643,7 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); - - assert(sp->obj->busy); + AN(ObjIsBusy(sp->obj)); if (sp->cur_method != VCL_MET_FETCH) { /* XXX: we should catch this at compile time */ WSP(sp, SLT_VCL_error, From phk at projects.linpro.no Mon Feb 16 15:34:01 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 16 Feb 2009 16:34:01 +0100 (CET) Subject: r3774 - trunk/varnish-cache/bin/varnishd Message-ID: <20090216153401.094D51F74CE@projects.linpro.no> Author: phk Date: 2009-02-16 16:34:00 +0100 (Mon, 16 Feb 2009) New Revision: 3774 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Allow for pass opbjects not having a objcore Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-16 15:06:18 UTC (rev 3773) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-16 15:34:00 UTC (rev 3774) @@ -377,11 +377,13 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); o = sp->obj; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - AN(ObjIsBusy(o)); + if (o->objcore != NULL) /* Pass has no objcore */ + AN(ObjIsBusy(o)); assert(o->refcnt > 0); o->ttl = 0; o->cacheable = 0; - HSH_Unbusy(sp); + if (o->objcore != NULL) /* Pass has no objcore */ + HSH_Unbusy(sp); HSH_Deref(&sp->obj); } Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-16 15:06:18 UTC (rev 3773) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-16 15:34:00 UTC (rev 3774) @@ -643,7 +643,8 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); - AN(ObjIsBusy(sp->obj)); + if (sp->obj->objcore != NULL) /* Pass has no objcore */ + AN(ObjIsBusy(sp->obj)); if (sp->cur_method != VCL_MET_FETCH) { /* XXX: we should catch this at compile time */ WSP(sp, SLT_VCL_error, From tfheen at projects.linpro.no Tue Feb 17 09:09:09 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 17 Feb 2009 10:09:09 +0100 (CET) Subject: r3775 - trunk/varnish-cache/bin/varnishd Message-ID: <20090217090909.079B71F7502@projects.linpro.no> Author: tfheen Date: 2009-02-17 10:09:08 +0100 (Tue, 17 Feb 2009) New Revision: 3775 Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 Log: Add documentation for cli_banner Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2009-02-16 15:34:00 UTC (rev 3774) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2009-02-17 09:09:08 UTC (rev 3775) @@ -414,6 +414,11 @@ .Pp The default is .Dv 60 seconds +.It Va cli_banner +Whether to print a banner whenever a client connects to the CLI interface. +.Pp +The default is +.Dv on . .It Va client_http11 Whether to force the use of HTTP/1.1 when responding to client requests, or just use the same protocol version as that used by the From phk at projects.linpro.no Tue Feb 17 09:46:33 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 17 Feb 2009 10:46:33 +0100 (CET) Subject: r3776 - trunk/varnish-cache/bin/varnishtest Message-ID: <20090217094633.3DAA91F752F@projects.linpro.no> Author: phk Date: 2009-02-17 10:46:33 +0100 (Tue, 17 Feb 2009) New Revision: 3776 Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c Log: Convert assert to error report Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2009-02-17 09:09:08 UTC (rev 3775) +++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2009-02-17 09:46:33 UTC (rev 3776) @@ -340,6 +340,11 @@ int i; i = http_rxchar_eof(hp, n); + if (i <= 0) { + vtc_log(hp->vl, 0, "HTTP rx failed (%s)", + strerror(errno)); + exit (1); + } assert(i > 0); } From tfheen at projects.linpro.no Tue Feb 17 09:48:10 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Tue, 17 Feb 2009 10:48:10 +0100 (CET) Subject: r3777 - trunk/varnish-cache/include Message-ID: <20090217094810.7DAC03833B@projects.linpro.no> Author: tfheen Date: 2009-02-17 10:48:10 +0100 (Tue, 17 Feb 2009) New Revision: 3777 Modified: trunk/varnish-cache/include/vsha256.h Log: Remove __BEGIN_DECLS and __END_DECLS as those do not exist on Solaris (and we do not need them) Modified: trunk/varnish-cache/include/vsha256.h =================================================================== --- trunk/varnish-cache/include/vsha256.h 2009-02-17 09:46:33 UTC (rev 3776) +++ trunk/varnish-cache/include/vsha256.h 2009-02-17 09:48:10 UTC (rev 3777) @@ -37,11 +37,9 @@ unsigned char buf[64]; } SHA256_CTX; -__BEGIN_DECLS void SHA256_Init(SHA256_CTX *); void SHA256_Update(SHA256_CTX *, const void *, size_t); void SHA256_Final(unsigned char [32], SHA256_CTX *); void SHA256_Test(void); -__END_DECLS #endif /* !_SHA256_H_ */ From phk at projects.linpro.no Tue Feb 17 09:50:06 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 17 Feb 2009 10:50:06 +0100 (CET) Subject: r3778 - trunk/varnish-cache/bin/varnishd Message-ID: <20090217095006.0D8151F7502@projects.linpro.no> Author: phk Date: 2009-02-17 10:50:05 +0100 (Tue, 17 Feb 2009) New Revision: 3778 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c Log: Move the pass flag from the object to the objcore. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-17 09:48:10 UTC (rev 3777) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-17 09:50:05 UTC (rev 3778) @@ -268,6 +268,7 @@ unsigned char flags; #define OC_F_ONLRU (1<<0) #define OC_F_BUSY (1<<1) +#define OC_F_PASS (1<<2) unsigned timer_idx; VTAILQ_ENTRY(objcore) list; VTAILQ_ENTRY(objcore) lru_list; @@ -289,8 +290,6 @@ struct ban *ban; - unsigned pass; - unsigned response; unsigned cacheable; Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-17 09:48:10 UTC (rev 3777) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-17 09:50:05 UTC (rev 3778) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2006-2009 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp @@ -414,7 +414,8 @@ sp->step = STP_RECV; return (0); case VCL_RET_PASS: - sp->obj->pass = 1; + if (sp->obj->objcore != NULL) + sp->obj->objcore->flags |= OC_F_PASS; if (sp->obj->ttl - sp->t_req < params->default_ttl) sp->obj->ttl = sp->t_req + params->default_ttl; break; @@ -514,7 +515,7 @@ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); - assert(!sp->obj->pass); + assert(!(sp->obj->objcore->flags & OC_F_PASS)); VCL_hit_method(sp); @@ -607,7 +608,7 @@ return (0); } - if (sp->obj->pass) { + if (sp->obj->objcore->flags & OC_F_PASS) { VSL_stats->cache_hitpass++; WSP(sp, SLT_HitPass, "%u", sp->obj->xid); HSH_Deref(&sp->obj); From phk at projects.linpro.no Tue Feb 17 10:06:19 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 17 Feb 2009 11:06:19 +0100 (CET) Subject: r3779 - trunk/varnish-cache/bin/varnishd Message-ID: <20090217100619.AD6033833B@projects.linpro.no> Author: phk Date: 2009-02-17 11:06:19 +0100 (Tue, 17 Feb 2009) New Revision: 3779 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/rfc2616.c Log: Move the ttl from object up to the objcore Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-17 09:50:05 UTC (rev 3778) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-17 10:06:19 UTC (rev 3779) @@ -262,6 +262,7 @@ #define OBJCORE_MAGIC 0x4d301302 struct object *obj; double timer_when; + double ttl; unsigned char timer_what; #define OC_T_TTL 1 #define OC_T_PREFETCH 2 @@ -298,7 +299,6 @@ double age; double entered; - double ttl; double grace; double prefetch; Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-02-17 09:50:05 UTC (rev 3778) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-02-17 10:06:19 UTC (rev 3779) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2006-2009 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp @@ -528,7 +528,7 @@ o->ban = b0; return (0); } else { - o->ttl = 0; + o->objcore->ttl = 0; WSP(sp, SLT_ExpBan, "%u was banned", o->xid); EXP_Rearm(o); o->ban = NULL; Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-17 09:50:05 UTC (rev 3778) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-17 10:06:19 UTC (rev 3779) @@ -378,6 +378,7 @@ cnt_fetch(struct sess *sp) { int i; + struct objcore *oc; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); @@ -414,10 +415,12 @@ sp->step = STP_RECV; return (0); case VCL_RET_PASS: - if (sp->obj->objcore != NULL) - sp->obj->objcore->flags |= OC_F_PASS; - if (sp->obj->ttl - sp->t_req < params->default_ttl) - sp->obj->ttl = sp->t_req + params->default_ttl; + if (sp->obj->objcore != NULL) { + oc = sp->obj->objcore; + oc->flags |= OC_F_PASS; + if (oc->ttl - sp->t_req < params->default_ttl) + oc->ttl = sp->t_req + params->default_ttl; + } break; case VCL_RET_DELIVER: break; Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-17 09:50:05 UTC (rev 3778) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-17 10:06:19 UTC (rev 3779) @@ -97,14 +97,14 @@ Lck_AssertHeld(&exp_mtx); if (o->prefetch < 0.0) { - when = o->ttl + o->prefetch; + when = oc->ttl + o->prefetch; what = OC_T_PREFETCH; } else if (o->prefetch > 0.0) { - assert(o->prefetch <= o->ttl); + assert(o->prefetch <= oc->ttl); when = o->prefetch; what = OC_T_PREFETCH; } else { - when = o->ttl + HSH_Grace(o->grace); + when = oc->ttl + HSH_Grace(o->grace); what = OC_T_TTL; } assert(!isnan(when)); @@ -304,7 +304,7 @@ assert(sp->handling == VCL_RET_DISCARD); WSL(&ww, SLT_ExpKill, 0, - "%u %d", o->xid, (int)(o->ttl - t)); + "%u %d", o->xid, (int)(o->objcore->ttl - t)); Lck_Lock(&exp_mtx); assert(oc->timer_idx == BINHEAP_NOIDX); VTAILQ_REMOVE(&lru, o->objcore, lru_list); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-17 09:50:05 UTC (rev 3778) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-17 10:06:19 UTC (rev 3779) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2006-2009 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp @@ -275,7 +275,7 @@ } if (!o->cacheable) continue; - if (o->ttl == 0) + if (oc->ttl == 0) continue; if (BAN_CheckObject(o, sp)) continue; @@ -283,11 +283,11 @@ continue; /* If still valid, use it */ - if (o->ttl >= sp->t_req) + if (oc->ttl >= sp->t_req) break; /* Remember any matching objects inside their grace period */ - if (o->ttl + HSH_Grace(o->grace) >= sp->t_req) + if (oc->ttl + HSH_Grace(o->grace) >= sp->t_req) grace_o = o; } if (oc == NULL) @@ -301,7 +301,7 @@ */ if (o == NULL && grace_o != NULL && grace_o->child != NULL && - grace_o->ttl + HSH_Grace(sp->grace) >= sp->t_req) + grace_o->objcore->ttl + HSH_Grace(sp->grace) >= sp->t_req) o = grace_o; if (o != NULL) { @@ -377,10 +377,11 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); o = sp->obj; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - if (o->objcore != NULL) /* Pass has no objcore */ + assert(o->refcnt > 0); + if (o->objcore != NULL) { /* Pass has no objcore */ AN(ObjIsBusy(o)); - assert(o->refcnt > 0); - o->ttl = 0; + o->objcore->ttl = 0; + } o->cacheable = 0; if (o->objcore != NULL) /* Pass has no objcore */ HSH_Unbusy(sp); Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-17 09:50:05 UTC (rev 3778) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-17 10:06:19 UTC (rev 3779) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2006-2009 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp @@ -369,6 +369,8 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ + if (sp->obj->objcore == NULL) + return; WSP(sp, SLT_TTL, "%u VCL %.0f %.0f", sp->obj->xid, a, sp->t_req); /* @@ -378,9 +380,9 @@ * We special case and make sure that rounding does not surprise. */ if (a <= 0) - sp->obj->ttl = sp->t_req - 1; + sp->obj->objcore->ttl = sp->t_req - 1; else - sp->obj->ttl = sp->t_req + a; + sp->obj->objcore->ttl = sp->t_req + a; EXP_Rearm(sp->obj); } @@ -389,7 +391,9 @@ { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ - return (sp->obj->ttl - sp->t_req); + if (sp->obj->objcore == NULL) + return (0.0); + return (sp->obj->objcore->ttl - sp->t_req); } /*-------------------------------------------------------------------- @@ -428,21 +432,23 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ + if (sp->obj->objcore == NULL) + return; sp->obj->prefetch = 0.0; if (a == 0.0) sp->obj->prefetch = a; - else if (a > 0.0 && a + sp->t_req <= sp->obj->ttl) + else if (a > 0.0 && a + sp->t_req <= sp->obj->objcore->ttl) sp->obj->prefetch = a + sp->t_req; - else if (a < 0.0 && a + sp->obj->ttl > sp->t_req) + else if (a < 0.0 && a + sp->obj->objcore->ttl > sp->t_req) sp->obj->prefetch = a; else if (a > 0.0) WSL(sp->wrk, SLT_VCL_info, sp->id, "XID %u: obj.prefetch (%g) after TTL (%g), ignored.", - sp->obj->xid, a, sp->obj->ttl - sp->t_req); + sp->obj->xid, a, sp->obj->objcore->ttl - sp->t_req); else /* if (a < 0.0) */ WSL(sp->wrk, SLT_VCL_info, sp->id, "XID %u: obj.prefetch (%g) less than ttl (%g), ignored.", - sp->obj->xid, a, sp->obj->ttl - sp->t_req); + sp->obj->xid, a, sp->obj->objcore->ttl - sp->t_req); EXP_Rearm(sp->obj); } Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- trunk/varnish-cache/bin/varnishd/rfc2616.c 2009-02-17 09:50:05 UTC (rev 3778) +++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2009-02-17 10:06:19 UTC (rev 3779) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2006-2009 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp @@ -173,6 +173,7 @@ RFC2616_cache_policy(const struct sess *sp, const struct http *hp) { int body = 0; + double ttl; /* * Initial cacheability determination per [RFC2616, 13.4] @@ -196,8 +197,10 @@ break; } - sp->obj->ttl = RFC2616_Ttl(sp, hp, sp->obj); - if (sp->obj->ttl == 0) + ttl = RFC2616_Ttl(sp, hp, sp->obj); + if (sp->obj->objcore != NULL) + sp->obj->objcore->ttl = ttl; + if (ttl == 0) sp->obj->cacheable = 0; return (body); From phk at projects.linpro.no Tue Feb 17 10:12:21 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 17 Feb 2009 11:12:21 +0100 (CET) Subject: r3780 - trunk/varnish-cache/bin/varnishd Message-ID: <20090217101221.C17C81F74AC@projects.linpro.no> Author: phk Date: 2009-02-17 11:12:21 +0100 (Tue, 17 Feb 2009) New Revision: 3780 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/flint.sh Log: Assert that we got an objcore Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-17 10:06:19 UTC (rev 3779) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-17 10:12:21 UTC (rev 3780) @@ -95,6 +95,7 @@ if (w->nobjcore == NULL) { ALLOC_OBJ(oc, OBJCORE_MAGIC); + XXXAN(oc); w->nobjcore = oc; oc->flags |= OC_F_BUSY; } Modified: trunk/varnish-cache/bin/varnishd/flint.sh =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.sh 2009-02-17 10:06:19 UTC (rev 3779) +++ trunk/varnish-cache/bin/varnishd/flint.sh 2009-02-17 10:12:21 UTC (rev 3780) @@ -10,4 +10,11 @@ flint.lnt \ *.c \ ../../lib/libvarnish/*.c \ - ../../lib/libvcl/*.c + ../../lib/libvcl/*.c \ + > $T +if [ -f _flint.old ] ; then + diff -u _flint.old $T + mv $T _flint.old +fi +cat $T +rm $T From phk at projects.linpro.no Tue Feb 17 10:29:20 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 17 Feb 2009 11:29:20 +0100 (CET) Subject: r3781 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20090217102920.67E4D1F74C3@projects.linpro.no> Author: phk Date: 2009-02-17 11:29:20 +0100 (Tue, 17 Feb 2009) New Revision: 3781 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/default.vcl trunk/varnish-cache/bin/varnishd/flint.sh 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_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: Eliminate prefetch, grace was a much better idea. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-17 10:29:20 UTC (rev 3781) @@ -265,7 +265,6 @@ double ttl; unsigned char timer_what; #define OC_T_TTL 1 -#define OC_T_PREFETCH 2 unsigned char flags; #define OC_F_ONLRU (1<<0) #define OC_F_BUSY (1<<1) @@ -300,7 +299,6 @@ double age; double entered; double grace; - double prefetch; double last_modified; double last_lru; Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-17 10:29:20 UTC (rev 3781) @@ -70,7 +70,6 @@ static const char *timer_what[] = { [OC_T_TTL] = "TTL", - [OC_T_PREFETCH] = "Prefetch", }; /* @@ -96,17 +95,8 @@ CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); Lck_AssertHeld(&exp_mtx); - if (o->prefetch < 0.0) { - when = oc->ttl + o->prefetch; - what = OC_T_PREFETCH; - } else if (o->prefetch > 0.0) { - assert(o->prefetch <= oc->ttl); - when = o->prefetch; - what = OC_T_PREFETCH; - } else { - when = oc->ttl + HSH_Grace(o->grace); - what = OC_T_TTL; - } + when = oc->ttl + HSH_Grace(o->grace); + what = OC_T_TTL; assert(!isnan(when)); oc->timer_what = what; if (when == oc->timer_when) @@ -222,7 +212,7 @@ /*-------------------------------------------------------------------- * This thread monitors the root of the binary heap and whenever an * object gets close enough, VCL is asked to decide if it should be - * discarded or prefetched. + * discarded. */ static void * @@ -281,38 +271,21 @@ WSL(&ww, SLT_ExpPick, 0, "%u %s", o->xid, timer_what[oc->timer_what]); - if (oc->timer_what == OC_T_PREFETCH) { - o->prefetch = 0.0; - sp->obj = o; - VCL_prefetch_method(sp); - sp->obj = NULL; - if (sp->handling == VCL_RET_FETCH) { - WSL(&ww, SLT_Debug, 0, "Attempt Prefetch %u", - o->xid); - } - Lck_Lock(&exp_mtx); - assert(oc->timer_idx == BINHEAP_NOIDX); - (void)update_object_when(o); - binheap_insert(exp_heap, oc); - assert(oc->timer_idx != BINHEAP_NOIDX); - Lck_Unlock(&exp_mtx); - } else { - assert(oc->timer_what == OC_T_TTL); - sp->obj = o; - VCL_timeout_method(sp); - sp->obj = NULL; + assert(oc->timer_what == OC_T_TTL); + sp->obj = o; + VCL_timeout_method(sp); + sp->obj = NULL; - assert(sp->handling == VCL_RET_DISCARD); - WSL(&ww, SLT_ExpKill, 0, - "%u %d", o->xid, (int)(o->objcore->ttl - t)); - Lck_Lock(&exp_mtx); - assert(oc->timer_idx == BINHEAP_NOIDX); - VTAILQ_REMOVE(&lru, o->objcore, lru_list); - oc->flags &= ~OC_F_ONLRU; - VSL_stats->n_expired++; - Lck_Unlock(&exp_mtx); - HSH_Deref(&o); - } + assert(sp->handling == VCL_RET_DISCARD); + WSL(&ww, SLT_ExpKill, 0, + "%u %d", o->xid, (int)(o->objcore->ttl - t)); + Lck_Lock(&exp_mtx); + assert(oc->timer_idx == BINHEAP_NOIDX); + VTAILQ_REMOVE(&lru, o->objcore, lru_list); + oc->flags &= ~OC_F_ONLRU; + VSL_stats->n_expired++; + Lck_Unlock(&exp_mtx); + HSH_Deref(&o); } } Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-17 10:29:20 UTC (rev 3781) @@ -424,44 +424,6 @@ /*--------------------------------------------------------------------*/ -/* XXX: the VCL_info messages has unexpected fractions on the ttl */ - -void -VRT_l_obj_prefetch(const struct sess *sp, double a) -{ - - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ - if (sp->obj->objcore == NULL) - return; - sp->obj->prefetch = 0.0; - if (a == 0.0) - sp->obj->prefetch = a; - else if (a > 0.0 && a + sp->t_req <= sp->obj->objcore->ttl) - sp->obj->prefetch = a + sp->t_req; - else if (a < 0.0 && a + sp->obj->objcore->ttl > sp->t_req) - sp->obj->prefetch = a; - else if (a > 0.0) - WSL(sp->wrk, SLT_VCL_info, sp->id, - "XID %u: obj.prefetch (%g) after TTL (%g), ignored.", - sp->obj->xid, a, sp->obj->objcore->ttl - sp->t_req); - else /* if (a < 0.0) */ - WSL(sp->wrk, SLT_VCL_info, sp->id, - "XID %u: obj.prefetch (%g) less than ttl (%g), ignored.", - sp->obj->xid, a, sp->obj->objcore->ttl - sp->t_req); - EXP_Rearm(sp->obj); -} - -double -VRT_r_obj_prefetch(const struct sess *sp) -{ - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ - return (sp->obj->prefetch - sp->t_req); -} - -/*--------------------------------------------------------------------*/ - #define VOBJ(type,onm,field) \ void \ VRT_l_obj_##onm(const struct sess *sp, type a) \ Modified: trunk/varnish-cache/bin/varnishd/default.vcl =================================================================== --- trunk/varnish-cache/bin/varnishd/default.vcl 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/bin/varnishd/default.vcl 2009-02-17 10:29:20 UTC (rev 3781) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2008 Linpro AS + * Copyright (c) 2006-2009 Linpro AS * All rights reserved. * * Author: Poul-Henning Kamp @@ -97,7 +97,6 @@ if (obj.http.Set-Cookie) { return (pass); } - set obj.prefetch = -30s; return (deliver); } @@ -110,11 +109,6 @@ return (discard); } -sub vcl_prefetch { - /* XXX: Do not redefine vcl_prefetch{}, it is not yet supported */ - return (fetch); -} - sub vcl_timeout { /* XXX: Do not redefine vcl_timeout{}, it is not yet supported */ return (discard); Modified: trunk/varnish-cache/bin/varnishd/flint.sh =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.sh 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/bin/varnishd/flint.sh 2009-02-17 10:29:20 UTC (rev 3781) @@ -14,7 +14,7 @@ > $T if [ -f _flint.old ] ; then diff -u _flint.old $T - mv $T _flint.old fi cat $T +cp $T _flint.old rm $T Modified: trunk/varnish-cache/include/vcl.h =================================================================== --- trunk/varnish-cache/include/vcl.h 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/include/vcl.h 2009-02-17 10:29:20 UTC (rev 3781) @@ -22,12 +22,11 @@ #define VCL_MET_HIT (1 << 5) #define VCL_MET_FETCH (1 << 6) #define VCL_MET_DELIVER (1 << 7) -#define VCL_MET_PREFETCH (1 << 8) -#define VCL_MET_TIMEOUT (1 << 9) -#define VCL_MET_DISCARD (1 << 10) -#define VCL_MET_ERROR (1 << 11) +#define VCL_MET_TIMEOUT (1 << 8) +#define VCL_MET_DISCARD (1 << 9) +#define VCL_MET_ERROR (1 << 10) -#define VCL_MET_MAX 12 +#define VCL_MET_MAX 11 /* VCL Returns */ #define VCL_RET_ERROR 0 @@ -71,7 +70,6 @@ vcl_func_f *hit_func; vcl_func_f *fetch_func; vcl_func_f *deliver_func; - 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 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/include/vcl_returns.h 2009-02-17 10:29:20 UTC (rev 3781) @@ -60,10 +60,6 @@ ((1 << VCL_RET_RESTART) | (1 << VCL_RET_DELIVER) )) -VCL_MET_MAC(prefetch,PREFETCH, - ((1 << VCL_RET_FETCH) - | (1 << VCL_RET_PASS) -)) VCL_MET_MAC(timeout,TIMEOUT, ((1 << VCL_RET_FETCH) | (1 << VCL_RET_DISCARD) Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/include/vrt_obj.h 2009-02-17 10:29:20 UTC (rev 3781) @@ -47,8 +47,6 @@ void VRT_l_obj_ttl(const struct sess *, double); double VRT_r_obj_grace(const struct sess *); void VRT_l_obj_grace(const struct sess *, double); -double VRT_r_obj_prefetch(const struct sess *); -void VRT_l_obj_prefetch(const struct sess *, double); double VRT_r_obj_lastuse(const struct sess *); const char * VRT_r_obj_hash(const struct sess *); const char * VRT_r_resp_proto(const struct sess *); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-17 10:29:20 UTC (rev 3781) @@ -174,11 +174,10 @@ vsb_cat(sb, "#define VCL_MET_HIT\t\t(1 << 5)\n"); vsb_cat(sb, "#define VCL_MET_FETCH\t\t(1 << 6)\n"); vsb_cat(sb, "#define VCL_MET_DELIVER\t\t(1 << 7)\n"); - vsb_cat(sb, "#define VCL_MET_PREFETCH\t(1 << 8)\n"); - vsb_cat(sb, "#define VCL_MET_TIMEOUT\t\t(1 << 9)\n"); - vsb_cat(sb, "#define VCL_MET_DISCARD\t\t(1 << 10)\n"); - vsb_cat(sb, "#define VCL_MET_ERROR\t\t(1 << 11)\n"); - vsb_cat(sb, "\n#define VCL_MET_MAX\t\t12\n\n"); + vsb_cat(sb, "#define VCL_MET_TIMEOUT\t\t(1 << 8)\n"); + vsb_cat(sb, "#define VCL_MET_DISCARD\t\t(1 << 9)\n"); + vsb_cat(sb, "#define VCL_MET_ERROR\t\t(1 << 10)\n"); + vsb_cat(sb, "\n#define VCL_MET_MAX\t\t11\n\n"); vsb_cat(sb, "/* VCL Returns */\n#define VCL_RET_ERROR\t\t0\n"); vsb_cat(sb, "#define VCL_RET_LOOKUP\t\t1\n#define VCL_RET_HASH\t\t2"); vsb_cat(sb, "\n#define VCL_RET_PIPE\t\t3\n#define VCL_RET_PASS\t\t4"); @@ -199,10 +198,9 @@ vsb_cat(sb, "\tvcl_func_f\t*pass_func;\n\tvcl_func_f\t*hash_func;\n"); vsb_cat(sb, "\tvcl_func_f\t*miss_func;\n\tvcl_func_f\t*hit_func;\n"); vsb_cat(sb, "\tvcl_func_f\t*fetch_func;\n\tvcl_func_f\t*deliver_fun"); - vsb_cat(sb, "c;\n\tvcl_func_f\t*prefetch_func;\n"); - vsb_cat(sb, "\tvcl_func_f\t*timeout_func;\n\tvcl_func_f\t*discard_f"); - vsb_cat(sb, "unc;\n\tvcl_func_f\t*error_func;\n"); - vsb_cat(sb, "};\n"); + vsb_cat(sb, "c;\n\tvcl_func_f\t*timeout_func;\n"); + vsb_cat(sb, "\tvcl_func_f\t*discard_func;\n\tvcl_func_f\t*error_fun"); + vsb_cat(sb, "c;\n};\n"); /* ../../include/vrt.h */ @@ -235,8 +233,8 @@ vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI"); vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT"); vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"); - vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3541 2009-01-23 21:"); - vsb_cat(sb, "17:02Z phk $\n *\n * Runtime support for compiled VCL "); + vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3542 2009-01-24 10:"); + vsb_cat(sb, "36:46Z phk $\n *\n * Runtime support for compiled VCL "); vsb_cat(sb, "programs.\n *\n * XXX: When this file is changed, lib/"); vsb_cat(sb, "libvcl/vcc_gen_fixed_token.tcl\n"); vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n"); @@ -324,9 +322,9 @@ /* ../../include/vrt_obj.h */ - vsb_cat(sb, "/*\n * $Id: vrt_obj.h 3406 2008-11-19 14:13:57Z petter"); - vsb_cat(sb, " $\n *\n * NB: This file is machine generated, DO NOT"); - vsb_cat(sb, " EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); + vsb_cat(sb, "/*\n * $Id: vcc_gen_obj.tcl 3406 2008-11-19 14:13:57Z "); + vsb_cat(sb, "petter $\n *\n * NB: This file is machine generated, "); + vsb_cat(sb, "DO NOT EDIT!\n *\n * Edit vcc_gen_obj.tcl instead\n"); vsb_cat(sb, " */\n\nstruct sockaddr * VRT_r_client_ip(const struct "); vsb_cat(sb, "sess *);\nstruct sockaddr * VRT_r_server_ip(struct ses"); vsb_cat(sb, "s *);\nint VRT_r_server_port(struct sess *);\n"); @@ -370,8 +368,6 @@ vsb_cat(sb, "void VRT_l_obj_ttl(const struct sess *, double);\n"); vsb_cat(sb, "double VRT_r_obj_grace(const struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_grace(const struct sess *, double);\n"); - vsb_cat(sb, "double VRT_r_obj_prefetch(const struct sess *);\n"); - vsb_cat(sb, "void VRT_l_obj_prefetch(const struct sess *, double);\n"); vsb_cat(sb, "double VRT_r_obj_lastuse(const struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_obj_hash(const struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_resp_proto(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 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-02-17 10:29:20 UTC (rev 3781) @@ -1,7 +1,7 @@ #!/usr/local/bin/tclsh8.4 #- # Copyright (c) 2006 Verdens Gang AS -# Copyright (c) 2006-2008 Linpro AS +# Copyright (c) 2006-2009 Linpro AS # All rights reserved. # # Author: Poul-Henning Kamp @@ -42,7 +42,6 @@ {hit {error restart pass deliver}} {fetch {error restart pass deliver}} {deliver {restart deliver}} - {prefetch {fetch pass}} {timeout {fetch discard}} {discard {discard keep}} {error {deliver}} Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2009-02-17 10:29:20 UTC (rev 3781) @@ -1,7 +1,7 @@ #!/usr/local/bin/tclsh8.4 #- # Copyright (c) 2006 Verdens Gang AS -# Copyright (c) 2006-2008 Linpro AS +# Copyright (c) 2006-2009 Linpro AS # All rights reserved. # # Author: Poul-Henning Kamp @@ -185,11 +185,6 @@ { 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} Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2009-02-17 10:12:21 UTC (rev 3780) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2009-02-17 10:29:20 UTC (rev 3781) @@ -166,11 +166,6 @@ VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT | VCL_MET_ERROR }, - { "obj.prefetch", RTIME, 12, - "VRT_r_obj_prefetch(sp)", "VRT_l_obj_prefetch(sp, ", - V_RW, 0, - VCL_MET_FETCH | VCL_MET_PREFETCH - }, { "obj.lastuse", TIME, 11, "VRT_r_obj_lastuse(sp)", NULL, V_RO, 0, From phk at projects.linpro.no Tue Feb 17 10:50:42 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 17 Feb 2009 11:50:42 +0100 (CET) Subject: r3782 - trunk/varnish-cache/bin/varnishd Message-ID: <20090217105042.64BB51F74C7@projects.linpro.no> Author: phk Date: 2009-02-17 11:50:42 +0100 (Tue, 17 Feb 2009) New Revision: 3782 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_expire.c Log: Now that we only have one timer firing, remove stuff to deal with different events. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-17 10:29:20 UTC (rev 3781) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-17 10:50:42 UTC (rev 3782) @@ -263,8 +263,6 @@ struct object *obj; double timer_when; double ttl; - unsigned char timer_what; -#define OC_T_TTL 1 unsigned char flags; #define OC_F_ONLRU (1<<0) #define OC_F_BUSY (1<<1) Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-17 10:29:20 UTC (rev 3781) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-17 10:50:42 UTC (rev 3782) @@ -68,10 +68,6 @@ static struct lock exp_mtx; static VTAILQ_HEAD(,objcore) lru = VTAILQ_HEAD_INITIALIZER(lru); -static const char *timer_what[] = { - [OC_T_TTL] = "TTL", -}; - /* * This is a magic marker for the objects currently on the SIOP [look it up] * so that other users of the object will not stumble trying to change the @@ -88,7 +84,6 @@ { struct objcore *oc; double when; - unsigned char what; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oc = o->objcore; @@ -96,9 +91,7 @@ Lck_AssertHeld(&exp_mtx); when = oc->ttl + HSH_Grace(o->grace); - what = OC_T_TTL; assert(!isnan(when)); - oc->timer_what = what; if (when == oc->timer_when) return (0); oc->timer_when = when; @@ -268,10 +261,8 @@ assert(oc->flags & OC_F_ONLRU); Lck_Unlock(&exp_mtx); - WSL(&ww, SLT_ExpPick, 0, "%u %s", o->xid, - timer_what[oc->timer_what]); + WSL(&ww, SLT_ExpPick, 0, "%u TTL", o->xid); - assert(oc->timer_what == OC_T_TTL); sp->obj = o; VCL_timeout_method(sp); sp->obj = NULL; From phk at projects.linpro.no Tue Feb 17 11:11:58 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 17 Feb 2009 12:11:58 +0100 (CET) Subject: r3783 - trunk/varnish-cache/bin/varnishd Message-ID: <20090217111158.1F9451F74C7@projects.linpro.no> Author: phk Date: 2009-02-17 12:11:57 +0100 (Tue, 17 Feb 2009) New Revision: 3783 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/rfc2616.c Log: with the prefetch timer out of the way, we do not need the ttl in objcore, only when the timer fires. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-17 10:50:42 UTC (rev 3782) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-17 11:11:57 UTC (rev 3783) @@ -262,7 +262,6 @@ #define OBJCORE_MAGIC 0x4d301302 struct object *obj; double timer_when; - double ttl; unsigned char flags; #define OC_F_ONLRU (1<<0) #define OC_F_BUSY (1<<1) @@ -294,6 +293,7 @@ unsigned len; + double ttl; double age; double entered; double grace; Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-02-17 10:50:42 UTC (rev 3782) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-02-17 11:11:57 UTC (rev 3783) @@ -528,7 +528,7 @@ o->ban = b0; return (0); } else { - o->objcore->ttl = 0; + o->ttl = 0; WSP(sp, SLT_ExpBan, "%u was banned", o->xid); EXP_Rearm(o); o->ban = NULL; Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-17 10:50:42 UTC (rev 3782) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-17 11:11:57 UTC (rev 3783) @@ -378,7 +378,6 @@ cnt_fetch(struct sess *sp) { int i; - struct objcore *oc; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); @@ -415,12 +414,10 @@ sp->step = STP_RECV; return (0); case VCL_RET_PASS: - if (sp->obj->objcore != NULL) { - oc = sp->obj->objcore; - oc->flags |= OC_F_PASS; - if (oc->ttl - sp->t_req < params->default_ttl) - oc->ttl = sp->t_req + params->default_ttl; - } + if (sp->obj->objcore != NULL) + sp->obj->objcore->flags |= OC_F_PASS; + if (sp->obj->ttl - sp->t_req < params->default_ttl) + sp->obj->ttl = sp->t_req + params->default_ttl; break; case VCL_RET_DELIVER: break; Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-17 10:50:42 UTC (rev 3782) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-17 11:11:57 UTC (rev 3783) @@ -90,7 +90,7 @@ CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); Lck_AssertHeld(&exp_mtx); - when = oc->ttl + HSH_Grace(o->grace); + when = o->ttl + HSH_Grace(o->grace); assert(!isnan(when)); if (when == oc->timer_when) return (0); @@ -269,7 +269,7 @@ assert(sp->handling == VCL_RET_DISCARD); WSL(&ww, SLT_ExpKill, 0, - "%u %d", o->xid, (int)(o->objcore->ttl - t)); + "%u %d", o->xid, (int)(o->ttl - t)); Lck_Lock(&exp_mtx); assert(oc->timer_idx == BINHEAP_NOIDX); VTAILQ_REMOVE(&lru, o->objcore, lru_list); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-17 10:50:42 UTC (rev 3782) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-17 11:11:57 UTC (rev 3783) @@ -276,7 +276,7 @@ } if (!o->cacheable) continue; - if (oc->ttl == 0) + if (o->ttl == 0) continue; if (BAN_CheckObject(o, sp)) continue; @@ -284,11 +284,11 @@ continue; /* If still valid, use it */ - if (oc->ttl >= sp->t_req) + if (o->ttl >= sp->t_req) break; /* Remember any matching objects inside their grace period */ - if (oc->ttl + HSH_Grace(o->grace) >= sp->t_req) + if (o->ttl + HSH_Grace(o->grace) >= sp->t_req) grace_o = o; } if (oc == NULL) @@ -302,7 +302,7 @@ */ if (o == NULL && grace_o != NULL && grace_o->child != NULL && - grace_o->objcore->ttl + HSH_Grace(sp->grace) >= sp->t_req) + grace_o->ttl + HSH_Grace(sp->grace) >= sp->t_req) o = grace_o; if (o != NULL) { @@ -381,7 +381,7 @@ assert(o->refcnt > 0); if (o->objcore != NULL) { /* Pass has no objcore */ AN(ObjIsBusy(o)); - o->objcore->ttl = 0; + o->ttl = 0; } o->cacheable = 0; if (o->objcore != NULL) /* Pass has no objcore */ Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-17 10:50:42 UTC (rev 3782) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-17 11:11:57 UTC (rev 3783) @@ -380,9 +380,9 @@ * We special case and make sure that rounding does not surprise. */ if (a <= 0) - sp->obj->objcore->ttl = sp->t_req - 1; + sp->obj->ttl = sp->t_req - 1; else - sp->obj->objcore->ttl = sp->t_req + a; + sp->obj->ttl = sp->t_req + a; EXP_Rearm(sp->obj); } @@ -393,7 +393,7 @@ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ if (sp->obj->objcore == NULL) return (0.0); - return (sp->obj->objcore->ttl - sp->t_req); + return (sp->obj->ttl - sp->t_req); } /*-------------------------------------------------------------------- Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- trunk/varnish-cache/bin/varnishd/rfc2616.c 2009-02-17 10:50:42 UTC (rev 3782) +++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2009-02-17 11:11:57 UTC (rev 3783) @@ -198,8 +198,7 @@ } ttl = RFC2616_Ttl(sp, hp, sp->obj); - if (sp->obj->objcore != NULL) - sp->obj->objcore->ttl = ttl; + sp->obj->ttl = ttl; if (ttl == 0) sp->obj->cacheable = 0; From des at projects.linpro.no Tue Feb 17 17:10:29 2009 From: des at projects.linpro.no (des at projects.linpro.no) Date: Tue, 17 Feb 2009 18:10:29 +0100 (CET) Subject: r3784 - trunk/varnish-cache/bin/varnishd Message-ID: <20090217171029.E3EC41F747A@projects.linpro.no> Author: des Date: 2009-02-17 18:10:29 +0100 (Tue, 17 Feb 2009) New Revision: 3784 Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 Log: Correct and complete description of -a. Modified: trunk/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.1 2009-02-17 11:11:57 UTC (rev 3783) +++ trunk/varnish-cache/bin/varnishd/varnishd.1 2009-02-17 17:10:29 UTC (rev 3784) @@ -1,6 +1,6 @@ .\"- .\" Copyright (c) 2006 Verdens Gang AS -.\" Copyright (c) 2006-2008 Linpro AS +.\" Copyright (c) 2006-2009 Linpro AS .\" All rights reserved. .\" .\" Author: Dag-Erling Sm?rgrav @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd March 8, 2008 +.Dd February 17, 2008 .Dt VARNISHD 1 .Os .Sh NAME @@ -62,7 +62,11 @@ .Pp The following options are available: .Bl -tag -width Fl -.It Fl a Ar address Ns Op : Ns Ar port +.It Xo +.Fl a Ar address Ns Op : Ns Ar port Ns +.Op , Ns Ar address Ns Op : Ns Ar port Ns +.Op ... +.Xc Listen for client requests on the specified .Ar address and @@ -84,11 +88,9 @@ .Ar port is not specified, the default HTTP port as listed in .Pa /etc/services -is used. To listen on multiple hosts or ports, the argument to -.Fl a -can be a (quoted) whitespace separated list of -.Ar address Ns Op : Ns Ar port -tokens. +is used. +Multiple listening addresses and ports can be specified as a +whitespace- or comma-separated list. .It Fl b Ar host Ns Op : Ns Ar port Use the specified .Ar host From tfheen at projects.linpro.no Wed Feb 18 08:15:44 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 18 Feb 2009 09:15:44 +0100 (CET) Subject: r3785 - trunk/varnish-cache Message-ID: <20090218081544.B2DBA1F749A@projects.linpro.no> Author: tfheen Date: 2009-02-18 09:15:44 +0100 (Wed, 18 Feb 2009) New Revision: 3785 Modified: trunk/varnish-cache/configure.ac Log: Make sure we have a C99 compiler Modified: trunk/varnish-cache/configure.ac =================================================================== --- trunk/varnish-cache/configure.ac 2009-02-17 17:10:29 UTC (rev 3784) +++ trunk/varnish-cache/configure.ac 2009-02-18 08:15:44 UTC (rev 3785) @@ -15,6 +15,10 @@ # Checks for programs. AC_GNU_SOURCE AC_PROG_CC +AC_PROG_CC_STDC +if test "x$ac_cv_prog_cc_c99" = xno; then + AC_MSG_ERROR([Could not find a C99 compatible compiler]) +fi AC_PROG_CPP AC_PROG_INSTALL AC_PROG_LIBTOOL From petter at projects.linpro.no Wed Feb 18 15:36:25 2009 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Wed, 18 Feb 2009 16:36:25 +0100 (CET) Subject: r3786 - in trunk/varnish-tools/webgui: . Varnish css templates Message-ID: <20090218153625.6ED891F7499@projects.linpro.no> Author: petter Date: 2009-02-18 16:36:25 +0100 (Wed, 18 Feb 2009) New Revision: 3786 Added: trunk/varnish-tools/webgui/Varnish/DB.pm trunk/varnish-tools/webgui/Varnish/DB_Data.pm trunk/varnish-tools/webgui/Varnish/Group.pm trunk/varnish-tools/webgui/create_db_data.pl trunk/varnish-tools/webgui/templates/view_stats_csv.tmpl trunk/varnish-tools/webgui/varnish_webgui.sql Modified: trunk/varnish-tools/webgui/README trunk/varnish-tools/webgui/Varnish/Management.pm trunk/varnish-tools/webgui/Varnish/Node.pm trunk/varnish-tools/webgui/Varnish/NodeManager.pm trunk/varnish-tools/webgui/Varnish/RequestHandler.pm trunk/varnish-tools/webgui/Varnish/Statistics.pm trunk/varnish-tools/webgui/Varnish/Util.pm trunk/varnish-tools/webgui/css/web.css trunk/varnish-tools/webgui/start.pl trunk/varnish-tools/webgui/templates/configure_parameters.tmpl trunk/varnish-tools/webgui/templates/edit_vcl.tmpl trunk/varnish-tools/webgui/templates/management_console.tmpl trunk/varnish-tools/webgui/templates/master.tmpl trunk/varnish-tools/webgui/templates/node_management.tmpl trunk/varnish-tools/webgui/templates/view_stats.tmpl Log: A mojor update to the web GUI, unfortunately all done in one go. Nevertheless, here it is, and has many improvements to the christmas edition commited in december: - the GUI now uses a sqlite3 database for storage, so all configuratons are stored - aggregated statistics for groups - graphs on demand for raw data - CSV export of stat data - 'Restricted mode' to get a web GUI which prevent you from doing changes - logging of changes performed in the GUI - generall minor improvements in the GUI Additional perl module dependencies are Algorithm::Diff and DBD::Sqlite3 A proper documentation will appear on the wiki in a couple of days to describe all that can be done with the web GUI. Modified: trunk/varnish-tools/webgui/README =================================================================== --- trunk/varnish-tools/webgui/README 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/README 2009-02-18 15:36:25 UTC (rev 3786) @@ -1,28 +1,15 @@ -Web GUI for Varnish, very limited christmas edition -=================================================== +Web GUI for Varnish +=================== -This is a preview of the upcoming web GUI for Varnish, which will be released with version 2.1 It has most of the features intended for the final version, but a number of things are still missing, so it is just inteded to get feedback. The following known things are _not_ implemented - - saving of state: if the web server goes down, the information is lost. - - smart data collection: it stores ALL the polled data with the given poll intervlal. It does not truncate data used for the hour, day, week and month graph. So eventually you will go out of memory. - - simple configuration: currently, you must edit the start.pl script by hand to set the configuration, and edit Varnish/RequestHandler.pl to add graphs and summary statistics. - - security: there is no form for access control or security implemented. - -So I wouldn't use it for anything with 'prod' in its name, but as a preview of what is to come. It should be noted that when adding nodes to an existing group, all the parameters and VCL of that node are replaced with the default parameters and VCL of the group. So if you add more nodes to a group, be aware of this. - -Any feedback is most welcome, so just post it to varnish-misc at projects.linpro.no. - -So what can you actually do with this thing? - - Overview -------- The web GUI is written in Perl and runs in its own server container, so a web server is not required, only the necessary Perl modules. The GUI consists of five sections: 'View stats', 'Configure parameters', 'Edit VCL', 'Node management' and 'Management console'. As the names might suggest, the GUI let you -- view statistics from the Varnish nodes -- configure the parameters of the Varnish nodes and clusters -- edit the VCL for each cluster, which will be shared between all the nodes -- perform node management, like adding clusters and nodes, get the state of the nodes and backend healths +- view statistics and graphs from the Varnish nodes +- configure the parameters of the Varnish nodes and groups +- edit the VCL for each group, which will be shared between all the nodes, and the standalone nodes +- perform node management, like adding groups and nodes, get the state of the nodes and backend healths, starting groups and nodes, stopping etc. - get access to the management console of each node Requirements @@ -34,7 +21,10 @@ - HTML::Template (libhtml-template-perl) - GD::Graph (libgd-graph-perl) - LWP::UserAgent (libwww-perl) +- Algorithm::Diff (libalgorithm-diff-perl) +- DBD::Sqlite3 (libdbd-sqlite3-perl) + The name in the paranthesis are the package name on a standard Ubuntu system. The rest of the modules should be pretty standard. As the management port of the Varnish instances are used for collecting data, this must be enaled when starting varnish. This is done with the -T option to varnish, e.g. like this @@ -44,13 +34,14 @@ Configuration ------------- -The configuration is done directly in the Perl code for this very limited christmas edition, but will be more userfriendly in the final version. As this version doesn't save your state, e.g. the nodes and clusters added, I would recommend adding this in the start.pl. The files needing customisation are +The configuration is done directly in start.pl, which let you set listening port, names of log files and database files etc. It is all well documented in the file. -- start.pl: early in the file you'll see '# Configuration starts here', and this is where to set the config. It is all commented, so should be fairly straight forward. -- Varnish/RequestHandler.pl: this is the main enging of the whole web GUI, including the parts creating the summary stats and graphs. This is well documented in the code, so look at line 380 for adding values to the summary statistics and 826 for adding custom graphs (and removing the dummy 'Missing graph'). +Before using it, you must create a sqlite3 database. This can be done by issuing -That is configuration for this version. Remember that when creating and editing VCLs, the information is stored on the node, so if the web server is restarted, the nodes will still have the VCLs (unless they are restarted too, of course). +$ sqlite3 varnish.db < varnish_webgui.sql +Change varnish.db to the name of the file you set in the config file. + Starting it ----------- @@ -62,17 +53,17 @@ View stats ---------- -In 'View stats' you will see statistics gathered from the nodes. The 'Summary statistics' is/will be customisable (see Configuration) and shows the most important statistics. If you want to see all the statistics from the Varnish nodes you turn 'Raw statistics' on. If you want the page to be refreshed automatically in order to follow the graph 'live', you can turn 'Auto refresh' on. The refresh rate is the same as the rate the statistics are collected from the nodes. +In 'View stats' you will see graphs and statistics gathered from the groups and nodes. The 'Summary statistics' shows the most important statistics, but if you want to see all the statistics from the Varnish nodes you turn 'Raw statistics' on. If you want the page to be refreshed automatically in order to follow the graph 'live', you can turn 'Auto refresh' on. The refresh rate is the same as the rate the statistics are collected from the nodes. If you want to export the raw data as CSV, use the 'Raw data as CSV' link. Configure parameters -------------------- -'Configure' parameters let you configure the parameters for a group (cluster) or a single node. For this version, the parameters for the groups are a copy of the parameters of the first node added to the group, so if a group has not been populated, it will not contain any values. Changing a value in a group will change the same value of all the nodes in that group. Changing a value for node only changes that node, naturally. +'Configure' parameters let you configure the parameters for a group or a single node. Changing a value in a group will change the same value of all the nodes in that group. Changing a value for node only changes that node, naturally. Edit VCL -------- -'Edit VCL' lets you edit the VCL of the group, and any changes made here will be reflected on all the nodes of the group. You can add, edit, save and discard VCLs as well as making a VCL active. It discards without warning (isn't baby safe yet), so be carefull. +'Edit VCL' lets you edit the VCL of a group or standalone node, and any changes made here will be reflected on all the nodes of the group. You can add, edit, save and discard VCLs as well as making a VCL active. A note about the editor: it is a simple text are, with giving you an indent as expected. If you save a VCL with error, the errors are listed and you can click on the 'Line X Pos Y' information in the error list to jump to that position in the editor. @@ -86,22 +77,11 @@ If a health probe is defined in the VCL, a list of backend healths for the running VCL is shown as well. - Since this version does not let you save the configuration, it is recommended that you add groups and nodes in the stat.pl file as explained in Configuration. +WARNING: Adding nodes to a group, or changing the group of a node, will replace that nodes parameter and VCL. - WARNING: as noted earlier, adding nodes to a group will replace that nodes parameter and VCL. - Management console ------------------ 'Management console' gives you access to the management console of each node. The input field has magical tab completion for the CLI commands and a command history accessable by arrow up/down. In addition to the standard CLI commands, 'cls' can be issued to clear the console. The color and size of the console can be changed, but this information is unfortunately not stored when switching nodes. - - -Road ahead -========== - -This is a sneak preview of the web GUI for 2.1, and as such is not complete. It is mostly feature complete (minus things mentioned in the start of this file), so any comments on what is working, what is lacking etc. is most appreciated. Please use the varnish-misc at projects.linpro.no mailing list for discussion. - - -Merry christmas! Added: trunk/varnish-tools/webgui/Varnish/DB.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/DB.pm (rev 0) +++ trunk/varnish-tools/webgui/Varnish/DB.pm 2009-02-18 15:36:25 UTC (rev 3786) @@ -0,0 +1,388 @@ +package Varnish::DB; + +use strict; +use warnings; + +use DBI; +use Varnish::Util; +use Varnish::Node; +use Varnish::Group; +use Varnish::DB_Data; + +{ + my $dbh; + my $stat_type_id_from_name_ref; + my %stat_field_exist; + my %parameter_field; + + sub handle_error { + my ($error, $handler) = @_; + + $dbh->disconnect(); + $dbh = DBI->connect("dbi:SQLite:dbname=test.db", '', '', + { AutoCommit => 0, PrintError => 1, HandleError => \&handle_error } ); + sleep(1); + } + + sub init { + my ($self, $db_filename, $username, $password) = @_; + + $dbh = DBI->connect("dbi:SQLite:dbname=$db_filename", '', '', + { AutoCommit => 0, PrintError => 1}); + + %parameter_field = %{Varnish::DB_Data::get_parameter_field()}; + %stat_field_exist = %{Varnish::DB_Data::get_stat_field_exist()}; + } + + + sub add_stat { + my ($self, $node, $stat_ref, $timestamp) = @_; + + $timestamp ||= time(); + + my @field_values; + my $fields = "time, node_id, has_data"; + my $values = "?, ?, ?"; + my $has_data; + if ($stat_ref) { + $has_data = 1; + my @stat_fields = keys %{$stat_ref}; + for my $stat_field (@stat_fields) { + my $db_field = get_db_friendly_name($stat_field); + if ($stat_field_exist{$db_field}) { + $fields .= ", $db_field"; + $values .= ", ?"; + my $value = $stat_ref->{$stat_field}; + push @field_values, $value; + } + else { + print STDERR "Field $db_field does not exist in the stat table. Please update schema\n"; + } + } + } + else { + $has_data = 0; + } + my $sql = "INSERT INTO stat($fields) VALUES($values)"; + my $sth = $dbh->prepare($sql); + $sth->execute($timestamp, $node->get_id(), $has_data, @field_values); + $sth->finish(); + $dbh->commit(); + } + + sub get_stat_data { + my ($self, $unit, $after_timestamp) = @_; + + my $sql; + if (ref($unit) eq "Varnish::Node") { + $sql = "SELECT time, has_data"; + my @stat_fields = keys %stat_field_exist; + for my $stat_field (@stat_fields) { + $sql .=", $stat_field"; + } + $sql .= " FROM stat WHERE node_id = ? AND time > ? ORDER BY time ASC"; + } + else { + $sql = "SELECT time, SUM(has_data) as has_data"; + my @stat_fields = keys %stat_field_exist; + for my $stat_field (@stat_fields) { + $sql .=", SUM($stat_field) AS $stat_field"; + } + $sql .= " FROM stat WHERE node_id IN (SELECT id FROM node WHERE group_id = ?) AND time >= ? GROUP BY time ORDER BY time ASC"; + } + + return $dbh->selectall_arrayref($sql, {Slice => {}}, $unit->get_id(), $after_timestamp); + } + + sub add_node { + my ($self, $node) = @_; + + my $fields = "name, address, port, group_id, management_port"; + my $sql = "INSERT INTO node($fields) VALUES(?, ?, ?, ?, ?)"; + $dbh->do($sql, undef, + $node->get_name(), + $node->get_address(), + $node->get_port(), + $node->get_group_id(), + $node->get_management_port()); + $dbh->commit(); + + $node->set_id($dbh->func('last_insert_rowid')); + } + + sub update_node { + my ($self, $node) = @_; + + my $sql = + "UPDATE node SET name = ?, address = ?, port = ?, group_id = ?, " + . "management_port = ? where id = ?"; + $dbh->do($sql, undef, $node->get_name, $node->get_address(), $node->get_port(), + $node->get_group_id(), $node->get_management_port(), + $node->get_id()); + $dbh->commit(); + } + + sub remove_node { + my ($self, $node, $commit) = @_; + + $commit = 1 if (!defined($commit)); + + my $sql = "DELETE FROM node WHERE id = ?"; + my $sth = $dbh->prepare($sql); + $sth->execute($node->get_id()); + + $sql = "DELETE FROM parameters WHERE node_id = ?"; + $sth = $dbh->prepare($sql); + $sth->execute($node->get_id()); + + if ($commit) { + $dbh->commit(); + } + } + + sub add_group { + my ($self, $group) = @_; + + my $sql = "INSERT INTO node_group(name) VALUES(?)"; + $dbh->do($sql, undef, $group->get_name()); + my $id = $dbh->func('last_insert_rowid'); + $group->set_id($id); + + $sql = "INSERT INTO parameters(group_id) VALUES(?)"; + $dbh->do($sql, undef, $id); + update_parameters($self, $id, \%parameter_field); + + $dbh->commit(); + } + + sub update_group { + my ($self, $group, $active_vcl) = @_; + + my $sql = "UPDATE node_group SET name = ?, active_vcl = ? WHERE id = ?"; + $dbh->do($sql, undef, $group->get_name(), $group->get_active_vcl(), $group->get_id()); + + $dbh->commit(); + } + + sub remove_group { + my ($self, $group) = @_; + + my $sql = "DELETE FROM node_group WHERE id = ?"; + my $sth = $dbh->prepare($sql); + $sth->execute($group->get_id()); + + $sql = "DELETE FROM parameters WHERE group_id = ?"; + $sth = $dbh->prepare($sql); + $sth->execute($group->get_id()); + + # sqlite doesn't support cascading delete, so we must do it + $sql = "SELECT id FROM node WHERE group_id = ?"; + my $nodes_ref = get_nodes($self, { group_id => $group->get_id()}); + for my $node (@$nodes_ref) { + remove_node($self, $node, 1); + } + + $dbh->commit(); + } + + sub _create_criteria_sql { + my ($criteria_ref) = @_; + + my @values; + my $sql = ""; + if ($criteria_ref) { + my @criterias = keys %$criteria_ref; + for my $criteria (@criterias) { + if ($sql eq "") { + $sql = " WHERE"; + } + else { + $sql .= " AND"; + } + my $value = $criteria_ref->{$criteria}; + $sql .= " $criteria = ?"; + push @values, $value; + } + } + + return ($sql, @values); + } + + sub get_groups { + my ($self, $criteria_ref) = @_; + + my @values; + my $sql = "SELECT * FROM node_group"; + if ($criteria_ref) { + my $criteria_sql; + ($criteria_sql, @values) = _create_criteria_sql($criteria_ref); + $sql .= $criteria_sql; + } + my $group_rows_ref = $dbh->selectall_arrayref($sql, {Slice => {}}, @values); + my @groups = map { Varnish::Group->new($_) } @$group_rows_ref; + + return \@groups; + } + + sub get_nodes { + my ($self, $criteria_ref) = @_; + my @values; + my $sql = "SELECT * FROM node"; + if ($criteria_ref) { + my $criteria_sql; + ($criteria_sql, @values) = _create_criteria_sql($criteria_ref); + $sql .= $criteria_sql; + } + + my $node_rows_ref = $dbh->selectall_arrayref($sql, {Slice => {}}, @values); + my @nodes = map { Varnish::Node->new($_) } @$node_rows_ref; + + return \@nodes; + } + + + sub _clean_up_parameters { + my ($parameter_ref) = @_; + + # rename 'child_user' and 'child_group' to the proper 'user' and 'group' names + $parameter_ref->{'user'} = $parameter_ref->{'child_user'}; + delete $parameter_ref->{'child_user'}; + $parameter_ref->{'group'} = $parameter_ref->{'child_group'}; + delete $parameter_ref->{'child_group'}; + delete $parameter_ref->{'id'}; + delete $parameter_ref->{'group_id'}; + delete $parameter_ref->{'node_id'}; + + return $parameter_ref; + } + + + sub get_group_parameters { + my ($self, $group) = @_; + + my $sql = "SELECT * FROM parameters WHERE group_id = ?"; + my $parameters_ref = $dbh->selectrow_hashref($sql, undef, $group->get_id()); + + return _clean_up_parameters($parameters_ref); + } + + + sub get_node_parameters { + my ($self, $node) = @_; + + my $sql = "SELECT * FROM parameters WHERE node_id = ?"; + my $parameters_ref = $dbh->selectrow_hashref($sql, undef, $node->get_id()); + + # rename 'child_user' and 'child_group' to the proper 'user' and 'group' names + $parameters_ref->{'user'} = $parameters_ref->{'child_user'}; + delete $parameters_ref->{'child_user'}; + $parameters_ref->{'group'} = $parameters_ref->{'child_group'}; + delete $parameters_ref->{'child_group'}; + delete $parameters_ref->{'id'}; + delete $parameters_ref->{'group_id'}; + delete $parameters_ref->{'node_id'}; + + return _clean_up_parameters($parameters_ref); + } + + sub update_parameters { + my ($self, $group_id, $parameter_ref) = @_; + + my @parameters = keys %{$parameter_ref}; + my @values; + my $first = 1; + my $sql = "UPDATE parameters SET"; + for my $parameter (@parameters) { + if (!$first) { + $sql .= ", "; + } + else { + $first = 0; + } + if ($parameter eq 'user' || $parameter eq 'group') { + $sql .= " child_$parameter = ?"; + } + elsif ($parameter_field{$parameter}) { + $sql .= " $parameter = ?"; + } + else { + print STDERR "Field $parameter does not exist in the stat table. Please update schema\n"; + next; + } + push @values, $parameter_ref->{$parameter}->{'value'}; + } + $sql .= " WHERE id = ?"; + $dbh->do($sql, undef, @values, $group_id); + } + + sub get_parameter_info { + my ($self) = @_; + + return $dbh->selectall_hashref("SELECT * FROM parameter_info", 1); + } + + sub get_vcl_infos { + my ($self, $group_id) = @_; + + my $sql = "SELECT name FROM vcl WHERE group_id = ?"; + my $vcl_infos_ref = $dbh->selectall_arrayref($sql, {Slice => {}}, $group_id); + $sql = "SELECT active_vcl FROM node_group WHERE id = ?"; + my ($active_vcl) = $dbh->selectrow_array($sql, undef, $group_id); + if (defined($active_vcl)) { + for my $vcl_info (@$vcl_infos_ref) { + $vcl_info->{'active'} = ($vcl_info->{'name'} eq $active_vcl); + } + } + + return $vcl_infos_ref; + } + + + sub get_vcl { + my ($self, $group_id, $name) = @_; + + my $sql = "SELECT vcl FROM vcl WHERE group_id = ? AND name = ?"; + my ($vcl) = $dbh->selectrow_array($sql, undef, $group_id, $name); + + return $vcl; + } + + sub update_vcl { + my ($self, $group_id, $name, $vcl) = @_; + + my $sql = "UPDATE vcl SET vcl = ? WHERE group_id = ? AND name = ?"; + + return $dbh->do($sql, undef, $vcl, $group_id, $name); + } + + sub discard_vcl { + my ($self, $group_id, $name) = @_; + + my $sql = "DELETE FROM vcl WHERE name = ? and group_id = ?"; + + return $dbh->do($sql, undef, $name, $group_id); + } + + sub add_vcl { + my ($self, $group_id, $name, $vcl) = @_; + + my $sql = "INSERT INTO vcl(group_id, name, vcl) VALUES(?, ?, ?)"; + $dbh->do($sql, undef, $group_id, $name, $vcl); + my $vcl_id = $dbh->func('last_insert_rowid'); + } + + sub clean_up { + my ($self) = @_; + + # 604800 is the number of seconds in a week + my $timestamp_limit = time()- 604800; + my $sql = "DELETE FROM stat WHERE time < ?"; + $dbh->do($sql, undef, $timestamp_limit); + } + + sub finish { + $dbh->disconnect(); + } +} + +1; Added: trunk/varnish-tools/webgui/Varnish/DB_Data.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/DB_Data.pm (rev 0) +++ trunk/varnish-tools/webgui/Varnish/DB_Data.pm 2009-02-18 15:36:25 UTC (rev 3786) @@ -0,0 +1,149 @@ +# This file was auto generated Wed Feb 18 15:58:37 2009 by create_db_files.pl +# DO NOT EDIT BUT RERUN THE SCRIPT! +package Varnish::DB_Data; + +my %parameter_field = ( +'accept_fd_holdoff' => {value => '50'}, +'auto_restart' => {value => 'on'}, +'backend_http11' => {value => 'on'}, +'between_bytes_timeout' => {value => '60.000000'}, +'cache_vbe_conns' => {value => 'off'}, +'cc_command' => {value => '"exec cc -fpic -shared -Wl,-x -o %o %s"'}, +'cli_banner' => {value => 'on'}, +'cli_buffer' => {value => '8192'}, +'cli_timeout' => {value => '5'}, +'client_http11' => {value => 'off'}, +'clock_skew' => {value => '10'}, +'connect_timeout' => {value => '0.400000'}, +'default_grace' => {value => '10'}, +'default_ttl' => {value => '120'}, +'diag_bitmap' => {value => '0x0'}, +'err_ttl' => {value => '0'}, +'esi_syntax' => {value => '0'}, +'fetch_chunksize' => {value => '128'}, +'first_byte_timeout' => {value => '60.000000'}, +'group' => {value => 'nogroup'}, +'listen_address' => {value => ':80'}, +'listen_depth' => {value => '1024'}, +'log_hashstring' => {value => 'off'}, +'log_local_address' => {value => 'off'}, +'lru_interval' => {value => '2'}, +'max_esi_includes' => {value => '5'}, +'max_restarts' => {value => '4'}, +'obj_workspace' => {value => '8192'}, +'overflow_max' => {value => '100'}, +'ping_interval' => {value => '3'}, +'pipe_timeout' => {value => '60'}, +'prefer_ipv6' => {value => 'off'}, +'purge_dups' => {value => 'off'}, +'purge_hash' => {value => 'off'}, +'rush_exponent' => {value => '3'}, +'send_timeout' => {value => '600'}, +'sess_timeout' => {value => '5'}, +'sess_workspace' => {value => '16384'}, +'session_linger' => {value => '0'}, +'shm_reclen' => {value => '255'}, +'shm_workspace' => {value => '8192'}, +'srcaddr_hash' => {value => '1049'}, +'srcaddr_ttl' => {value => '30'}, +'thread_pool_add_delay' => {value => '20'}, +'thread_pool_add_threshold' => {value => '2'}, +'thread_pool_fail_delay' => {value => '200'}, +'thread_pool_max' => {value => '500'}, +'thread_pool_min' => {value => '5'}, +'thread_pool_purge_delay' => {value => '1000'}, +'thread_pool_timeout' => {value => '300'}, +'thread_pools' => {value => '2'}, +'user' => {value => 'nobody'}, +'vcl_trace' => {value => 'off'}, +'waiter' => {value => 'default'}, +); +my %stat_field_exist = ('session_pipeline' => 1, +'shm_mtx_contention' => 1, +'n_overflowed_work_requests' => 1, +'backend_connections_failures' => 1, +'n_worker_threads_limited' => 1, +'sma_outstanding_bytes' => 1, +'backend_connections_too_many' => 1, +'shm_cycles_through_buffer' => 1, +'esi_parse_errors__unlock_' => 1, +'total_pipe' => 1, +'n_worker_threads_created' => 1, +'objects_sent_with_write' => 1, +'backend_connections_success' => 1, +'n_dropped_work_requests' => 1, +'objects_overflowing_workspace' => 1, +'sms_outstanding_bytes' => 1, +'client_requests_received' => 1, +'n_objects_on_deathrow' => 1, +'n_total_active_purges' => 1, +'backend_requests_made' => 1, +'bytes_allocated' => 1, +'outstanding_allocations' => 1, +'objects_esi_parsed__unlock_' => 1, +'n_struct_vbe_conn' => 1, +'cache_hits_for_pass' => 1, +'n_lru_saved_objects' => 1, +'cache_hits' => 1, +'sma_outstanding_allocations' => 1, +'total_pass' => 1, +'backend_connections_reuses' => 1, +'backend_connections_not_attempted' => 1, +'shm_flushes_due_to_overflow' => 1, +'n_duplicate_purges_removed' => 1, +'n_new_purges_added' => 1, +'session_closed' => 1, +'cache_misses' => 1, +'n_struct_srcaddr' => 1, +'sms_allocator_requests' => 1, +'session_herd' => 1, +'n_worker_threads_not_created' => 1, +'n_vcl_discarded' => 1, +'hcb_lookups_without_lock' => 1, +'n_worker_threads' => 1, +'n_lru_nuked_objects' => 1, +'n_queued_work_requests' => 1, +'total_sessions' => 1, +'total_header_bytes' => 1, +'n_objects_tested' => 1, +'n_active_struct_srcaddr' => 1, +'bytes_free' => 1, +'n_vcl_total' => 1, +'n_backends' => 1, +'sma_bytes_free' => 1, +'total_body_bytes' => 1, +'shm_records' => 1, +'n_vcl_available' => 1, +'sma_bytes_allocated' => 1, +'objects_sent_with_sendfile' => 1, +'hcb_lookups_with_lock' => 1, +'n_struct_sess_mem' => 1, +'client_connections_accepted' => 1, +'n_struct_bereq' => 1, +'sms_bytes_freed' => 1, +'sms_outstanding_allocations' => 1, +'sms_bytes_allocated' => 1, +'n_small_free_smf' => 1, +'n_struct_objecthead' => 1, +'total_fetch' => 1, +'sma_allocator_requests' => 1, +'backend_connections_recycles' => 1, +'backend_connections_unused' => 1, +'shm_writes' => 1, +'n_struct_object' => 1, +'total_requests' => 1, +'hcb_inserts' => 1, +'n_lru_moved_objects' => 1, +'n_struct_sess' => 1, +'allocator_requests' => 1, +'n_regexps_tested_against' => 1, +'n_expired_objects' => 1, +'http_header_overflows' => 1, +'n_struct_smf' => 1, +'n_old_purges_deleted' => 1, +'n_large_free_smf' => 1, +'session_read_ahead' => 1, +'session_linger' => 1, +); +sub get_parameter_field() { return \%parameter_field; }sub get_stat_field_exist() { return \%stat_field_exist; } +1; Added: trunk/varnish-tools/webgui/Varnish/Group.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/Group.pm (rev 0) +++ trunk/varnish-tools/webgui/Varnish/Group.pm 2009-02-18 15:36:25 UTC (rev 3786) @@ -0,0 +1,234 @@ +package Varnish::Group; + +use strict; + +use Varnish::DB; +use Varnish::Util; + +{ + my %id_of; + my %name_of; + my %active_vcl_of; + + my $parameter_info_ref; + + sub new { + my ($class, $arg_ref) = @_; + + my $new_object = bless \do{ my $anon_scalar; }, $class; + + $id_of{$new_object} = $arg_ref->{'id'}; + $name_of{$new_object} = $arg_ref->{'name'}; + $active_vcl_of{$new_object} = $arg_ref->{'active_vcl'}; + + return $new_object; + } + + sub get_id { + my ($self) = @_; + + return $id_of{$self}; + } + + sub get_name { + my ($self) = @_; + + return $name_of{$self}; + } + + sub get_active_vcl { + my ($self) = @_; + + return $active_vcl_of{$self}; + } + + sub get_parameters { + my ($self) = @_; + + if (!$parameter_info_ref) { + $parameter_info_ref = Varnish::DB->get_parameter_info(); + } + my $parameter_ref = Varnish::DB->get_group_parameters($self); + while (my ($parameter, $value) = each(%$parameter_ref)) { + $parameter_ref->{$parameter} = { + value => $value, + unit => $parameter_info_ref->{$parameter}->{'unit'}, + description => $parameter_info_ref->{$parameter}->{'description'}, + }; + } + + return $parameter_ref; + } + + sub update_parameters { + my ($self, $parameter_ref) = @_; + + Varnish::DB->update_parameters($id_of{$self}, $parameter_ref); + + my $nodes_ref = Varnish::NodeManager->get_nodes($self); + for my $node (@$nodes_ref) { + $node->update_parameters($parameter_ref); + } + } + + sub set_id { + my ($self, $id) = @_; + + $id_of{$self} = $id; + } + + sub set_name { + my ($self, $name) = @_; + + $name_of{$self} = $name; + } + + sub get_vcl_infos { + my ($self) = @_; + + return Varnish::DB->get_vcl_infos($id_of{$self}); + } + + sub get_vcl { + my ($self, $name) = @_; + + return Varnish::DB->get_vcl($id_of{$self}, $name); + } + + sub save_vcl { + my ($self, $name, $vcl) = @_; + + my $vcl_error; + my $error = ""; + my $nodes_ref = Varnish::NodeManager->get_nodes($self); + for my $node (@$nodes_ref) { + my $management = $node->get_management(); + if ($management) { + if (!$management->set_vcl($name, $vcl)) { + $vcl_error ||= get_error(); + } + } + else { + $error .= "Could not get the management console for " . $node->get_name() . "\n"; + } + } + if ($vcl_error) { + $error .= "VCL compilation errors:\n$vcl_error\n"; + } + else { + if (Varnish::DB->update_vcl($id_of{$self}, $name, $vcl) == 0 ) { + Varnish::DB->add_vcl($id_of{$self}, $name, $vcl); + } + } + + if ($error) { + return set_error($error); + } + else { + return no_error(); + } + } + + sub make_vcl_active { + my ($self, $name) = @_; + + my $error = ""; + my $nodes_ref = Varnish::NodeManager->get_nodes($self); + for my $node (@$nodes_ref) { + my $management = $node->get_management(); + if ($management) { + if (!$management->make_vcl_active($name)) { + $error .= get_error(); + } + } + else { + $error .= "Could not get the management console for " . $node->get_name() . "\n"; + } + } + + $active_vcl_of{$self} = $name; + if (Varnish::DB->update_group($self) == 0 ) { + $error .= "$name is not a valid VCL\n"; + } + + if ($error) { + return set_error($error); + } + else { + return no_error(); + } + } + + sub discard_vcl { + my ($self, $name) = @_; + + my $error = ""; + my $nodes_ref = Varnish::NodeManager->get_nodes($self); + for my $node (@$nodes_ref) { + my $management = $node->get_management(); + if ($management) { + if (!$management->discard_vcl($name)) { + $error .= get_error(); + } + } + else { + $error .= "Could not get the management console for " . $node->get_name() . "\n"; + } + } + if (Varnish::DB->discard_vcl($id_of{$self}, $name) == 0 ) { + $error .= "$name is not a valid VCL\n"; + } + + if ($error) { + return set_error($error); + } + else { + return no_error(); + } + } + + sub start { + my ($self) = @_; + + my $error = ""; + my $nodes_ref = Varnish::NodeManager->get_nodes($self); + for my $node (@$nodes_ref) { + if (!$node->is_running()) { + if (!$node->start()) { + $error .= get_error(); + } + } + } + + if ($error) { + return set_error($error); + } + else { + return no_error(); + } + } + + sub stop { + my ($self) = @_; + + my $error = ""; + my $nodes_ref = Varnish::NodeManager->get_nodes($self); + for my $node (@$nodes_ref) { + if ($node->is_running()) { + if (!$node->stop()) { + $error .= get_error(); + } + } + } + + if ($error) { + return set_error($error); + } + else { + return no_error(); + } + } + +} + +1; Modified: trunk/varnish-tools/webgui/Varnish/Management.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/Management.pm 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/Varnish/Management.pm 2009-02-18 15:36:25 UTC (rev 3786) @@ -4,11 +4,11 @@ use IO::Socket::INET; use Exporter; use List::Util qw(first); +use Varnish::Util qw(set_error get_error no_error); { my %hostname_of; my %port_of; - my %error_of; my %socket_of; sub new { @@ -18,11 +18,27 @@ $hostname_of{$new_object} = $hostname; $port_of{$new_object} = $port; - $error_of{$new_object} = ""; return $new_object; } + sub _read_cli_response { + my ($socket) = @_; + + my ($status_code, $response_size) = <$socket> =~ m/^(\d+) (\d+)/; + my $response; + my $remaining_bytes = $response_size; + while ($remaining_bytes > 0 ) { + my $data; + my $read = read $socket, $data, $remaining_bytes; + $response .= $data; + $remaining_bytes -= $read; + } + my $eat_newline = <$socket>; + + return ($status_code, $response); + } + sub _send_command { my ($self, $command) = @_; @@ -33,22 +49,13 @@ PeerAddr => $hostname_of{$self} ); return ("666", "Could not connect to node") if (!$socket); +# skip the banner + _read_cli_response($socket); $socket_of{$self} = $socket; } my $socket = $socket_of{$self}; - print $socket "$command\n"; - my ($status_code, $response_size) = <$socket> =~ m/^(\d+) (\d+)/; - my $response; - my $remaining_bytes = $response_size; - while ($remaining_bytes > 0 ) { - my $data; - my $read = read $socket, $data, $remaining_bytes; - $response .= $data; - $remaining_bytes -= $read; - } - my $eat_newline = <$socket>; - return ($status_code, $response); + return _read_cli_response($socket); } sub send_command { @@ -56,8 +63,8 @@ my ($status_code, $response) = _send_command($self, $command); - return no_error($self, $response) if $status_code eq "200"; - return set_error($self, $response); + return no_error($response) if $status_code eq "200"; + return set_error($response); } sub get_parameters { @@ -67,17 +74,23 @@ my $current_param; my ($status_code, $response) = _send_command($self, "param.show -l"); - return set_error($self, $response) if ($status_code ne "200"); + return set_error($response) if ($status_code ne "200"); for my $line (split( '\n', $response)) { - if ($line =~ /^(\w+)\s+(\w+) (.*)$/) { + if ($line =~ /^(\w+)\s+(.*?)(?: \[(.*)\])?$/) { + my $value = $2; + my $unit = $3; + $current_param = $1; + + if ($current_param eq "user" || $current_param eq "group" + || $current_param eq "waiter") { + ($value) = split(/ /, $value); + } my %param_info = ( - value => $2, - unit => $3 + value => $value, + unit => $unit ); - - $current_param = $1; - $param{$1} = \%param_info; + $param{$current_param} = \%param_info; } elsif ($line =~ /^\s+(.+)$/) { # The first comment line contains no . and describes the default value. @@ -98,8 +111,8 @@ my ($status_code, $response) = _send_command($self, "param.show $parameter"); - return no_error($self, $1) if ($response =~ /^(?:\w+)\s+(\w+)/); - return set_error($self, $response); + return no_error($1) if ($response =~ /^(?:\w+)\s+(\w+)/); + return set_error($response); } sub set_parameter { @@ -108,29 +121,27 @@ my ($status_code, $response) = _send_command($self, "param.set $parameter $value"); return no_error($self) if ($status_code eq "200"); - return set_error($self, $response); + return set_error($response); } - sub get_vcl_names { + sub get_vcl_infos { my ($self) = @_; my ($status_code, $response) = _send_command($self, "vcl.list"); - return set_error($self, $response) if ($status_code ne "200"); + return set_error($response) if ($status_code ne "200"); - my @vcl_infos = ($response =~ /^(\w+)\s+\d+\s+(\w+)$/gm); + my @vcl_infos = ($response =~ /^(\w+)\s+(?:\d+|N\/A)\s+(\w+)$/gm); my $vcl_names_ref = []; - my $active_vcl_name = ""; while (my ($status, $name) = splice @vcl_infos, 0, 2) { next if ($status eq "discarded"); - - if ($status eq "active") { - $active_vcl_name = $name; - } - push @$vcl_names_ref, $name; + + push @$vcl_names_ref, { + name => $name, + active => $status eq "active", + }; } - unshift @$vcl_names_ref, $active_vcl_name; - return no_error($self, $vcl_names_ref) if ($status_code eq "200"); + return no_error($vcl_names_ref) if ($status_code eq "200"); } sub get_vcl { @@ -138,8 +149,8 @@ my ($status_code, $response) = _send_command($self, "vcl.show $vcl_name"); - return no_error($self, $response) if ($status_code eq "200"); - return set_error($self, $response); + return no_error($response) if ($status_code eq "200"); + return set_error($response); } sub set_vcl { @@ -149,37 +160,36 @@ $vcl =~ s/\n/\\n/g; my $need_restart = 0; - my ($active_vcl_name, @vcl_names) = @{get_vcl_names($self)}; - my $editing_active_vcl = $vcl_name eq $active_vcl_name; + my $vcl_info = first { $_->{'name'} eq $vcl_name } @{get_vcl_infos($self)}; # try to compile the new vcl my ($status_code, $response) = _send_command($self, "vcl.inline _new_vcl \"$vcl\""); if ($status_code ne "200") { _send_command($self, "vcl.discard _new_vcl"); - return set_error($self, $response); + return set_error($response); } - if ($editing_active_vcl) { + if ($vcl_info && $vcl_info->{'active'}) { ($status_code, $response) = _send_command($self, "vcl.use _new_vcl"); } - if (grep { $_ eq $vcl_name } @vcl_names) { + if ($vcl_info) { ($status_code, $response) = _send_command($self, "vcl.discard $vcl_name"); if ($status_code ne "200") { _send_command($self, "vcl.use $vcl_name"); _send_command($self, "vcl.discard _new_vcl"); - return set_error($self, $response); + return set_error($response); } } ($status_code, $response) = _send_command($self, "vcl.inline $vcl_name \"$vcl\""); - if ($editing_active_vcl) { + if ($vcl_info && $vcl_info->{'active'}) { ($status_code, $response) = _send_command($self, "vcl.use $vcl_name"); } _send_command($self, "vcl.discard _new_vcl"); return no_error($self) if ($status_code eq "200"); - return set_error($self, $response); + return set_error($response); } sub discard_vcl { @@ -188,7 +198,7 @@ my ($status_code, $response) = _send_command($self, "vcl.discard $vcl_name"); return no_error($self) if ($status_code eq "200"); - return set_error($self, $response); + return set_error($response); } sub make_vcl_active { @@ -197,7 +207,7 @@ my ($status_code, $response) = _send_command($self, "vcl.use $vcl_name"); return no_error($self) if ($status_code eq "200"); - return set_error($self, $response); + return set_error($response); } sub get_stats { @@ -209,9 +219,8 @@ /^\s*(\d+)\s+(.*?)$/; $2 => $1 } split /\n/, $response; - - return no_error($self, \%stat_counter) if ($status_code eq "200"); - return set_error($self, $response); + return no_error(\%stat_counter) if ($status_code eq "200"); + return set_error($response); } sub ping { @@ -220,7 +229,7 @@ my ($status_code, $response) = _send_command($self, "stats"); return no_error($self) if ($status_code eq "200"); - return set_error($self, $response); + return set_error($response); } sub start { @@ -229,7 +238,7 @@ my ($status_code, $response) = _send_command($self, "start"); return no_error($self) if ($status_code eq "200"); - return set_error($self, $response); + return set_error($response); } sub stop { @@ -238,31 +247,9 @@ my ($status_code, $response) = _send_command($self, "stop"); return no_error($self) if ($status_code eq "200"); - return set_error($self, $response); + return set_error($response); } - sub set_error { - my ($self, $error) = @_; - - $error_of{$self} = $error; - - return; - } - - sub get_error { - my ($self) = @_; - - return $error_of{$self}; - } - - sub no_error { - my ($self, $return_value) = @_; - - $error_of{$self} = ""; - - return defined($return_value) ? $return_value : 1; - } - sub close { my ($self) = @_; @@ -275,11 +262,11 @@ my ($self) = @_; my ($status_code, $response) = _send_command($self, "debug.health"); - return set_error($self, $response) if ($status_code ne "200"); + return set_error($response) if ($status_code ne "200"); my %backend_health = ($response =~ /^Backend (\w+) is (\w+)$/gm); - return no_error($self, \%backend_health); + return no_error(\%backend_health); } } Modified: trunk/varnish-tools/webgui/Varnish/Node.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/Node.pm 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/Varnish/Node.pm 2009-02-18 15:36:25 UTC (rev 3786) @@ -3,41 +3,53 @@ use strict; use LWP::UserAgent; use Varnish::Management; +use Varnish::Util; +use Varnish::DB; { my %name_of; my %address_of; my %port_of; - my %group_of; + my %group_id_of; my %management_of; my %management_port_of; - my %is_master_of; - my %node_id_of; + my %id_of; - my $next_node_id = 1; - sub new { my ($class, $arg_ref) = @_; my $new_object = bless \do{ my $anon_scalar; }, $class; + $id_of{$new_object} = $arg_ref->{'id'}; $name_of{$new_object} = $arg_ref->{'name'}; $address_of{$new_object} = $arg_ref->{'address'}; $port_of{$new_object} = $arg_ref->{'port'}; - $group_of{$new_object} = $arg_ref->{'group'}; + + if ($arg_ref->{'group_id'}) { + $group_id_of{$new_object} = $arg_ref->{'group_id'}; + } + elsif ($arg_ref->{'group'}) { + $group_id_of{$new_object} = Varnish::DB->get_group_id($arg_ref->{'group'}); + } + else { + $group_id_of{$new_object} = 0; + } $management_port_of{$new_object} = $arg_ref->{'management_port'}; $management_of{$new_object} = Varnish::Management->new($arg_ref->{'address'}, $arg_ref->{'management_port'}); - $is_master_of{$new_object} = 0; - $node_id_of{$new_object} = $next_node_id++; - return $new_object; } + sub DESTROY { + my ($self) = @_; + + $management_of{$self}->close(); + } + sub get_id { my ($self) = @_; - return $node_id_of{$self}; + return $id_of{$self}; } sub get_name { @@ -46,24 +58,48 @@ return $name_of{$self}; } + sub set_name { + my ($self, $name) = @_; + + $name_of{$self} = $name; + } + sub get_address { my ($self) = @_; return $address_of{$self}; } + + sub set_address { + my ($self, $address) = @_; + $address_of{$self} = $address; + } + sub get_port { my ($self) = @_; return $port_of{$self}; } - sub get_group { + sub set_port { + my ($self, $port) = @_; + + $port_of{$self} = $port; + } + + sub get_group_id { my ($self) = @_; - return $group_of{$self}; + return $group_id_of{$self}; } + sub set_group_id { + my ($self, $group_id) = @_; + + $group_id_of{$self} = $group_id; + } + sub get_management { my ($self) = @_; @@ -76,16 +112,16 @@ return $management_port_of{$self}; } - sub is_master { - my ($self) = @_; + sub set_management_port { + my ($self, $management_port) = @_; - return $is_master_of{$self}; + $management_port_of{$self} = $management_port; } - sub set_master { - my ($self, $master) = @_; + sub set_id { + my ($self, $id) = @_; - $is_master_of{$self} = $master; + $id_of{$self} = $id; } sub is_running_ok { @@ -123,6 +159,95 @@ return 0; } } + + sub get_parameters { + my ($self) = @_; + + return get_management($self)->get_parameters(); + } + + sub update_parameters { + my ($self, $parameter_ref) = @_; + + my @parameters = keys %$parameter_ref; + my $management = get_management($self); + for my $parameter (@parameters) { + $management->set_parameter($parameter, $parameter_ref->{$parameter}->{'value'}); +# $management->set_parameter($parameter, $parameter_ref->{$parameter}); + } + } + + sub start { + my ($self) = @_; + + my $management = get_management($self); + if ($management->start()) { + return no_error(); + } + else { + return set_error(get_error()); + } + } + + sub stop { + my ($self) = @_; + + my $management = get_management($self); + if ($management->stop()) { + return no_error(); + } + else { + return set_error(get_error()); + } + } + + sub get_backend_health { + my ($self) = @_; + + my $management = get_management($self); + + return $management->get_backend_health(); + } + + sub get_vcl_infos { + my ($self) = @_; + + my $management = get_management($self); + + return $management->get_vcl_infos(); + } + + sub get_vcl { + my ($self, $name) = @_; + + my $management = get_management($self); + + return $management->get_vcl($name); + } + + sub save_vcl { + my ($self, $name, $vcl) = @_; + + my $management = get_management($self); + + return $management->set_vcl($name, $vcl); + } + + sub make_vcl_active { + my ($self, $name) = @_; + + my $management = get_management($self); + + return $management->make_vcl_active($name); + } + + sub discard_vcl { + my ($self, $name) = @_; + + my $management = get_management($self); + + return $management->discard_vcl($name); + } } 1; Modified: trunk/varnish-tools/webgui/Varnish/NodeManager.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/NodeManager.pm 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/Varnish/NodeManager.pm 2009-02-18 15:36:25 UTC (rev 3786) @@ -2,220 +2,155 @@ use strict; use warnings; use Varnish::Node; +use Varnish::Group; +use Varnish::Util qw(set_error no_error get_error); use List::Util qw(first); { - my @groups = (); - my @nodes = (); - my %group_parameters = (); - my $error = ""; - sub add_node { - my ($self, $node) = @_; + sub _clone_unit { + my ($master, $slave) = @_; - my $group = $node->get_group(); - if (! grep { $_->get_group eq $group } @nodes ) { - $node->set_master(1); - my %node_parameters = %{$node->get_management()->get_parameters()}; - while (my ($parameter, $value) = each %node_parameters) { - $group_parameters{$group}->{$parameter} = $value; - } + my $parameter_ref = $master->get_parameters(); + $slave->update_parameters($parameter_ref); + + my $master_vcl_infos_ref = $master->get_vcl_infos(); + for my $vcl_info (@$master_vcl_infos_ref) { + my $name = $vcl_info->{'name'}; + $vcl_info->{'vcl'} = $master->get_vcl($name); } - else { -# inherit the VCL and the parameters of the group - my %group_parameters = %{$group_parameters{$group}}; - my $management = $node->get_management(); - while (my ($parameter, $value) = each %group_parameters) { - $management->set_parameter($parameter, $value->{'value'}); - } - my $vcl_names_ref = $management->get_vcl_names(); - my $active_vcl_name; - my @vcl_names; - if ($vcl_names_ref) { - @vcl_names = @{$vcl_names_ref}; - $active_vcl_name = shift @vcl_names; + my $previous_active_vcl; + my $vcl_infos_ref = $slave->get_vcl_infos(); + for my $vcl_info (@$vcl_infos_ref) { + my $name = $vcl_info->{'name'}; + if ($vcl_info->{'active'}) { + $previous_active_vcl = $name; } + else { + $slave->discard_vcl($name); + } + } - for my $vcl_name (@vcl_names) { - if ($vcl_name ne $active_vcl_name) { - $management->discard_vcl($vcl_name); + for my $vcl_info (@$master_vcl_infos_ref) { + my $name = $vcl_info->{'name'}; + my $vcl = $vcl_info->{'vcl'}; + $slave->save_vcl($name, $vcl); + if ($vcl_info->{'active'}) { + $slave->make_vcl_active($name); + if ($previous_active_vcl) { + $slave->discard_vcl($previous_active_vcl); } } - - my $discard_active_vcl = 1; - my $group_master = first { - $_->get_group() eq $group - && $_->is_master() - } @nodes; - my $master_management = $group_master->get_management(); - my $master_active_vcl_name; - my @master_vcl_names; - my $master_vcl_names_ref = $group_master->get_management()->get_vcl_names(); - if ($master_vcl_names_ref) { - @master_vcl_names = @{$master_vcl_names_ref}; - $master_active_vcl_name = shift @master_vcl_names; - } + } + } - for my $vcl_name (@master_vcl_names) { - my $vcl = $master_management->get_vcl($vcl_name); - $management->set_vcl($vcl_name, $vcl); + sub add_node { + my ($self, $node, $use_as_group_defaults) = @_; - if ($vcl_name eq $master_active_vcl_name) { - $management->make_vcl_active($vcl_name); - } - if ($vcl_name eq $active_vcl_name) { - $discard_active_vcl = 0; - } - } + my $management = $node->get_management(); + if (!$management->ping()) { + return set_error($self, "Could not connect to management port: " + . get_error()); + } + Varnish::DB->add_node($node); - if ($discard_active_vcl) { - $management->discard_vcl($active_vcl_name); + my $group_id = $node->get_group_id(); + if ($group_id > 0) { + my $group = get_group($self, $group_id); + if ($use_as_group_defaults) { + _clone_unit($node, $group); } + else { + _clone_unit($group, $node); + } } - push @nodes, $node; + return no_error(); } sub remove_node { my ($self, $node) = @_; - if ($node) { - @nodes = grep { $_ != $node } @nodes; - - if ($node->is_master()) { - my $new_master = first { - $_->is_master - && $_->get_group() eq $node->get_group() - } @nodes; - if ($new_master) { - $new_master->set_master(1); - } - } - } + Varnish::DB->remove_node($node); } sub get_node { my ($self, $node_id) = @_; - my $node = first { - $_->get_id() == $node_id - } @nodes; + my ($node) = @{Varnish::DB->get_nodes({id => $node_id})}; return $node; } sub add_group { - my ($self, $name) = @_; + my ($self, $group) = @_; - push @groups, $name; + Varnish::DB->add_group($group); } sub remove_group { - my ($self, $name) = @_; - - @groups = grep { $_ ne $name } @groups; - my @nodes_to_remove = grep { $_->get_group() eq $name } @nodes; - for my $node (@nodes_to_remove) { - remove_node($self, $node); - } - } - - sub get_groups { - - return @groups; - } - - sub get_nodes { - - return @nodes; - } - - sub get_nodes_for_group { my ($self, $group) = @_; - return grep { $_->get_group() eq $group } @nodes; + Varnish::DB->remove_group($group); } - sub get_group_masters { - my ($self) = @_; + sub get_group { + my ($self, $group_id) = @_; + + my ($group) = @{Varnish::DB->get_groups({id => $group_id})}; - return grep { $_->is_master() } @nodes; + return $group; } - sub load { + sub get_groups { + return Varnish::DB->get_groups(); } - sub save { - my ($self) = @_; - + sub get_nodes { + my ($self, $group) = @_; + + if (defined($group)) { + return Varnish::DB->get_nodes({group_id => $group->get_id()}); + } + else { + return Varnish::DB->get_nodes(); + } } - sub quit { - my ($self) = @_; - - for my $node (@nodes) { - my $management = $node->get_management(); - if ($management) { - $management->close(); + sub get_group_name { + my ($self, $group_id) = @_; + + if ($group_id > 0) { + my $group = get_group($self, $group_id); + if ($group) { + return $group->get_name(); } } - - save($self); + return ''; } - sub set_error { - my ($self, $new_error) = @_; + sub update_node { + my ($self, $node) = @_; - $error = $new_error; - - return; - } - - sub get_error { - my ($self) = @_; - - return $error; - } - - sub no_error { - my ($self, $return_value) = @_; - - $error = ""; - - return defined($return_value) ? $return_value : 1; - } - - sub set_group_parameter { - my ($self, $group, $parameter, $value) = @_; - - my $error; - - $group_parameters{$group}->{$parameter}->{'value'} = $value; - my @nodes_in_group = grep { $_->get_group() eq $group } @nodes; - for my $node (@nodes_in_group) { - my $management = $node->get_management(); - if (!$management->set_parameter($parameter, $value)) { - $error .= $management->get_error() . "\n"; - } + my $current = get_node($self, $node->get_id()); + if ($current->get_group_id() != $node->get_group_id() + && $node->get_group_id() > 0) { + my $group = get_group($self, $node->get_group_id()); + _clone_unit($group, $node); } - - if ($error) { - return set_error($self, $error); - } - else { - return no_error(); - } + Varnish::DB->update_node($node); } - sub get_group_parameters { + sub update_group { my ($self, $group) = @_; - return $group_parameters{$group}; + Varnish::DB->update_group($group); } + } 1; Modified: trunk/varnish-tools/webgui/Varnish/RequestHandler.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/RequestHandler.pm 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/Varnish/RequestHandler.pm 2009-02-18 15:36:25 UTC (rev 3786) @@ -9,8 +9,8 @@ use Varnish::NodeManager; use Varnish::Node; use Varnish::Statistics; -use URI::Escape; use GD::Graph::lines; +use GD qw(gdTinyFont); use POSIX qw(strftime); use List::Util qw(first); use Socket; @@ -34,6 +34,7 @@ my $server_hostname = gethostbyaddr(inet_aton($server_ip), AF_INET); $master_tmpl_var_of{$new_object}->{'server_host'} = $server_hostname; $master_tmpl_var_of{$new_object}->{'server_port'} = $connection->sockport(); + $master_tmpl_var_of{$new_object}->{'restricted'} = get_config_value('restricted'); return $new_object; } @@ -63,8 +64,7 @@ my %parameter = (); for my $pair (split /&/,$$content_ref) { my ($key,$value) = split /=/,$pair; - $value = uri_unescape($value); - $value =~ s/\+/ /g; + $value = url_decode($value); $parameter{$key} = $value; } @@ -87,14 +87,18 @@ my $content_template; my $response_content; my %request_parameter = _parse_request_parameters(\$content); + + if (0) { + while (my ($k, $v) = each %request_parameter) { + print "$k => $v\n"; + } + print "\n\n"; + } -# while (my ($k, $v) = each %request_parameter) { -# print "$k => $v\n"; -# } - my $param; + my $use_master_template; if ($operation eq 'view_stats' || $operation eq '') { - ($content_template, $param) = view_stats(\%request_parameter); + ($content_template, $param, $use_master_template) = view_stats(\%request_parameter); } elsif ($operation eq 'configure_parameters') { ($content_template, $param) = configure_parameters(\%request_parameter); @@ -125,22 +129,43 @@ else { return; } + + $response_header_ref_of{$self}->{'Connection'} = "Close"; + $use_master_template = + defined($use_master_template) ? $use_master_template : 1; if ($content_template) { - my $template_text = read_file("templates/master.tmpl"); - $template_text =~ s/CONTENT_TEMPLATE/$content_template/; + my %template_options = + (die_on_bad_params => 0, global_vars => 1, loop_context_vars => 1); + if ($use_master_template) { + my $template_text = read_file("templates/master.tmpl"); + $template_text =~ s/CONTENT_TEMPLATE/$content_template/; - my $template = HTML::Template->new_scalar_ref( \$template_text, - die_on_bad_params => 0); + my $template = HTML::Template->new_scalar_ref( \$template_text, + %template_options); - my $tmpl_var = $master_tmpl_var_of{$self}; - if ($param) { - while (my ($parameter, $value) = each %{$param}) { - $tmpl_var->{$parameter} = $value; + my $tmpl_var = $master_tmpl_var_of{$self}; + if ($param) { + while (my ($parameter, $value) = each %{$param}) { + $tmpl_var->{$parameter} = $value; + } } + $template->param($tmpl_var); + $response_content = $template->output; } - $template->param($tmpl_var); - $response_content = $template->output; + else { + my $template = HTML::Template->new_file("templates/$content_template", + %template_options); + + my $tmpl_var = $master_tmpl_var_of{$self}; + if ($param) { + while (my ($parameter, $value) = each %{$param}) { + $tmpl_var->{$parameter} = $value; + } + } + $template->param($tmpl_var); + $response_content = $template->output; + } } $response_content_ref_of{$self} = \$response_content; } @@ -151,7 +176,8 @@ my %param = %{$parameter_ref}; $param{'vcl'} ||= ""; $param{'operation'} ||= "load"; - $param{'group_name'} ||= ""; + $param{'unit_id'} ||= ""; + $param{'is_node'} ||= ""; $param{'vcl_name'} ||= ""; $param{'new_vcl_name'} ||= ""; @@ -162,32 +188,29 @@ $tmpl_var{'vcl_name'} = $param{'vcl_name'}; $tmpl_var{'status'} = ""; $tmpl_var{'vcl_infos'} = []; - $tmpl_var{'group_infos'} = []; + $tmpl_var{'info_infos'} = []; $tmpl_var{'vcl_error'} = ""; $tmpl_var{'vcl'} = ""; my $successfull_save = 0; my $editing_new_vcl = 0; - my @group_masters = Varnish::NodeManager->get_group_masters(); if ($param{'operation'} eq "make_active") { - my $group_master = first { - $_->get_group() eq $param{'group_name'}; - } @group_masters; - - if ($group_master) { - my $management = $group_master->get_management(); - if ($management->make_vcl_active($param{'vcl_name'})) { - my @nodes = Varnish::NodeManager->get_nodes(); - for my $node (@nodes) { - if ($node != $group_master && $node->get_group() eq $param{'group_name'}) { - $node->get_management()->make_vcl_active($param{'vcl_name'}); - } - } + my $unit; + if ($param{'is_node'}) { + $unit = Varnish::NodeManager->get_node($param{'unit_id'}); + } + else { + $unit = Varnish::NodeManager->get_group($param{'unit_id'}); + } + if ($unit) { + if ($unit->make_vcl_active($param{'vcl_name'})) { $tmpl_var{'status'} = "VCL activated successfully"; + log_info("[" . $unit->get_name() . "] [Make VCL active] [" . + $param{'vcl_name'} . "]"); } else { - $tmpl_var{'error'} .= "Error activating configuration:\n" . $management->get_error() . "\n"; + $tmpl_var{'error'} .= "Error activating configuration:\n" . get_error() . "\n"; } } } @@ -204,35 +227,32 @@ } } elsif ($param{'operation'} eq 'save') { - my $group_master = first { - $_->get_group() eq $param{'group_name'} - } @group_masters; - - if ($group_master && $param{'vcl'} ne "" && $param{'vcl_name'} ne "") { - my $master_management = $group_master->get_management(); - if ($master_management->set_vcl($param{'vcl_name'}, $param{'vcl'})) { - my @nodes = Varnish::NodeManager->get_nodes(); - for my $node (@nodes) { - if ($node != $group_master && $node->get_group() eq $param{'group_name'}) { - my $management = $node->get_management(); - if (!$management->set_vcl($param{'vcl_name'}, $param{'vcl'})) { - $tmpl_var{'error'} .= "Error saving configuration for " . $node->get_name() - . ":\n" . $management->get_error() . "\n"; - } - } - } + my $unit; + if ($param{'is_node'}) { + $unit= Varnish::NodeManager->get_node($param{'unit_id'}); + } + else { + $unit= Varnish::NodeManager->get_group($param{'unit_id'}); + } + if ($unit && $param{'vcl'} ne "" && $param{'vcl_name'} ne "") { + my $existing_vcl = $unit->get_vcl($param{'vcl_name'}); + if ($unit->save_vcl($param{'vcl_name'}, $param{'vcl'})) { + my $diff = diff($existing_vcl, $param{'vcl'}); $successfull_save = 1; $tmpl_var{'status'} = "VCL saved successfully"; + log_info("[" . $unit->get_name() . "] [Saved VCL] [" . + $param{'vcl_name'} . "] [" + . url_encode($diff) . "]"); } else { + $editing_new_vcl = 1; + $tmpl_var{'vcl'} = $param{'vcl'}; push @{$tmpl_var{'vcl_infos'}}, { - name => $param{'vcl_name'}, + name => $param{'new_vcl_name'}, selected => 1, active => 0 }; - $editing_new_vcl = 1; - $tmpl_var{'vcl'} = $param{'vcl'}; - my $vcl_error = $master_management->get_error(); + my $vcl_error = get_error(); # it is bad bad bad mixing presentation and code, I know, but sometimes you have to $vcl_error =~ s/Line (\d+) Pos (\d+)/$&<\/a>/g; $vcl_error =~ s/\n//g; @@ -241,97 +261,92 @@ } } elsif ($param{'operation'} eq "discard") { - my ($group_master) = grep { - $_->get_group() eq $param{'group_name'} - } @group_masters; - if ($group_master && $param{'vcl_name'} ne "") { - my $management = $group_master->get_management(); - if ($management->discard_vcl($param{'vcl_name'})) { - my @nodes = Varnish::NodeManager->get_nodes(); - for my $node (@nodes) { - if ($node != $group_master && $node->get_group() eq $param{'group_name'}) { - $node->get_management()->discard_vcl($param{'vcl_name'}); - } - } + my $unit; + if ($param{'is_node'}) { + $unit= Varnish::NodeManager->get_node($param{'unit_id'}); + } + else { + $unit= Varnish::NodeManager->get_group($param{'unit_id'}); + } + if ($unit && $param{'vcl_name'} ne "") { + if ($unit->discard_vcl($param{'vcl_name'})) { $tmpl_var{'vcl_name'} = ""; $tmpl_var{'status'} = "VCL discarded successfully"; + log_info("[" . $unit->get_name() . "] [Discarded VCL] [" . + $param{'vcl_name'} . "]"); } else { - $tmpl_var{'error'} .= "Error discarding configuration:\n" . $management->get_error() . "\n"; + $tmpl_var{'error'} .= "Error discarding configuration:\n" . get_error() . "\n"; } } } - my $selected_group_master; - for my $group_master (@group_masters) { - my %group_info = ( - name => $group_master->get_group(), - selected => 0, - ); - if ($param{'group_name'} eq $group_master->get_group()) { - $group_info{'selected'} = '1'; - $selected_group_master = $group_master; + my $groups_ref = Varnish::NodeManager->get_groups(); + my $nodes_ref = Varnish::NodeManager->get_nodes(Varnish::NodeManager->get_group(0)); + my $selected_unit; + for my $unit (@$groups_ref, @$nodes_ref) { + my $is_node = ref($unit) eq "Varnish::Node"; + next if (!$is_node && $unit->get_id() == 0); + + my $selected = 0; + if (!$selected_unit && + (!$param{'unit_id'} + || ($is_node && $param{'is_node'} && $param{'unit_id'} == $unit->get_id()) + || (!$is_node && !$param{'is_node'} && $param{'unit_id'} == $unit->get_id()))) { + $selected_unit = $unit; + $selected = 1; } - push @{$tmpl_var{'group_infos'}}, \%group_info; + my %unit_info = ( + id => $unit->get_id(), + is_node => $is_node, + name => $unit->get_name(), + selected => $selected, + ); + push @{$tmpl_var{'unit_infos'}}, \%unit_info; } - if (!$selected_group_master && @group_masters > 0) { - $selected_group_master = $group_masters[0]; - $tmpl_var{'group_infos'}->[0]->{'selected'} = 1; - } - - if ($selected_group_master) { - my $active_vcl_name; - my @vcl_names; - my $vcl_names_ref = $selected_group_master->get_management()->get_vcl_names(); - if ($vcl_names_ref) { - @vcl_names = @{$vcl_names_ref}; - $active_vcl_name = shift @vcl_names; - - for my $vcl_name (@vcl_names) { - my %vcl_info = ( - name => $vcl_name, - selected => 0, - active => 0, - ); - if ($vcl_name eq $tmpl_var{'vcl_name'}) { - $vcl_info{'selected'} = 1; - $tmpl_var{'vcl_name'} = $vcl_name; + if ($selected_unit) { + my $vcl_infos_ref = $selected_unit->get_vcl_infos(); + if ($vcl_infos_ref) { + push @{$tmpl_var{'vcl_infos'}}, @$vcl_infos_ref; + if ($tmpl_var{'vcl_name'}) { + for my $vcl_info_ref (@{$tmpl_var{'vcl_infos'}}) { + if ($vcl_info_ref->{'name'} eq $tmpl_var{'vcl_name'}) { + $vcl_info_ref->{'selected'} = 1; + } } - if ($vcl_name eq $active_vcl_name) { - $vcl_info{'active'} = 1; - } - push @{$tmpl_var{'vcl_infos'}}, \%vcl_info; } - if ($tmpl_var{'vcl_name'} eq "") { - FIND_ACTIVE_VCL: + else { + my $active_found = 0; +FIND_ACTIVE_VCL: for my $vcl_info (@{$tmpl_var{'vcl_infos'}}) { if ($vcl_info->{'active'}) { $tmpl_var{'vcl_name'} = $vcl_info->{'name'}; $vcl_info->{'selected'} = 1; + $active_found = 1; last FIND_ACTIVE_VCL; } } - if ($tmpl_var{'vcl_name'} eq "") { - $tmpl_var{'vcl_name'} = $tmpl_var{'vcl_infos'}->[0]->{'name'}; - $tmpl_var{'vcl_infos'}->[0]->{'selected'} = 1; + if (!$active_found && @{$tmpl_var{'vcl_infos'}} > 0) { + my $vcl_info = $tmpl_var{'vcl_infos'}->[0]; + + $tmpl_var{'vcl_name'} = $vcl_info->{'name'}; + $vcl_info->{'selected'} = 1; } } + } - if (!(($param{'operation'} eq 'save' && !$successfull_save - || $param{'operation'} eq 'new'))) { - my $vcl = $selected_group_master->get_management()->get_vcl($tmpl_var{'vcl_name'}); - if ($vcl) { - $tmpl_var{'vcl'} = $vcl; - } - else { - $tmpl_var{'error'} .= "Error retrieving VCL: " . $selected_group_master->get_management()->get_error() . "\n"; - } + if ($tmpl_var{'vcl_name'} && + !(($param{'operation'} eq 'save' && !$successfull_save + || $param{'operation'} eq 'new'))) { + my $vcl = $selected_unit->get_vcl($tmpl_var{'vcl_name'}); + if ($vcl) { + $tmpl_var{'vcl'} = $vcl; } + else { + $tmpl_var{'error'} .= "Error retrieving VCL: " . get_error() . "\n"; + } } - else { - $tmpl_var{'error'} .= "Error retrieving the VCLs: " . $selected_group_master->get_management()->get_error(); - } } $tmpl_var{'editing_new_vcl'} = $editing_new_vcl; @@ -339,8 +354,60 @@ return ($template, \%tmpl_var); } + + sub view_stats_csv{ + my ($show_group, $csv_delim) = @_; + $csv_delim ||= ","; + my $template = "view_stats_csv.tmpl"; + my %tmpl_var; + $tmpl_var{'rows'} = []; + $tmpl_var{'stat_time'} = ''; + + my @stat_names; + my $first_row = 1; + my $nodes_ref = []; + my $groups_ref = []; + if ($show_group > 0) { + my $group = Varnish::NodeManager->get_group($show_group); + push @$groups_ref, $group; + $nodes_ref = Varnish::NodeManager->get_nodes($group); + } + else { + $groups_ref = Varnish::NodeManager->get_groups(); + $nodes_ref = Varnish::NodeManager->get_nodes(); + } + for my $unit (@$groups_ref, @$nodes_ref) { + next if (ref($unit) eq "Varnish::Group" && $unit->get_id() == 0); + my ($stat_time, $stat_ref) = Varnish::Statistics->get_last_measure($unit); + if ($first_row) { + @stat_names = keys(%$stat_ref); + my @column_names = map { {value => $_} } @stat_names; + push @{$tmpl_var{'rows'}}, { + values => \@column_names, + unit => "name", + }; + if ($stat_time) { + $stat_time = strftime("%a %b %e %H:%M:%S %Y", localtime($stat_time)); + } + $first_row = 0; + } + my @values = map { {value => $stat_ref->{$_}} } @stat_names; + push @{$tmpl_var{'rows'}}, { + values => \@values, + unit => $unit->get_name(), + }; + } + + return ($template, \%tmpl_var, 0); + } + sub _get_stat { + my ($name, $stat_ref) = @_; + + return $stat_ref->{get_db_friendly_name($name)}; + } + sub view_stats { my ($parameter_ref) = @_; @@ -349,77 +416,133 @@ my %param = %{$parameter_ref}; $param{'view_raw_stats'} ||= 0; $param{'auto_refresh'} ||= 0; + $param{'show_group'} ||= 0; + $param{'csv'} ||= 0; + if ($param{'csv'}) { + return view_stats_csv($param{'show_group'}); + } + my %tmpl_var; - $tmpl_var{'error'} = ""; - $tmpl_var{'stat_time'} = 0; - $tmpl_var{'node_infos'} = []; + $tmpl_var{'error'} = ''; + $tmpl_var{'stat_time'} = ''; + $tmpl_var{'unit_infos'} = []; $tmpl_var{'summary_stats'} = []; $tmpl_var{'raw_stats'} = []; $tmpl_var{'auto_refresh'} = $param{'toggle_auto_refresh'} ? 1 - $param{'auto_refresh'} : $param{'auto_refresh'}; $tmpl_var{'auto_refresh_interval'} = $tmpl_var{'auto_refresh'} ? get_config_value('poll_interval') : 0; $tmpl_var{'view_raw_stats'} = $param{'view_raw_stats'}; + $tmpl_var{'graph_width'} = get_config_value('graph_width'); + $tmpl_var{'graph_height'} = get_config_value('graph_height'); + $tmpl_var{'large_graph_width'} = get_config_value('large_graph_width'); + $tmpl_var{'large_graph_height'} = get_config_value('large_graph_height'); + $tmpl_var{'show_group'} = $param{'show_group'}; + $tmpl_var{'group_name'} = ''; my $error = ""; - my ($stat_time, $stat_ref) = Varnish::Statistics->get_last_measure(); - my @nodes = Varnish::NodeManager->get_nodes(); - - if ($stat_time) { - $stat_time = strftime("%a %b %e %H:%M:%S %Y", localtime($stat_time)); + my %summary_stat_list; + my %raw_stat_list; + my $nodes_ref = []; + my $groups_ref = []; + if ($tmpl_var{'show_group'} > 0) { + my $group = Varnish::NodeManager->get_group($tmpl_var{'show_group'}); + push @$groups_ref, $group; + $tmpl_var{'group_name'} = $group->get_name(); + $nodes_ref = Varnish::NodeManager->get_nodes($group); } + else { + $groups_ref = Varnish::NodeManager->get_groups(); + my $standalone_group = Varnish::NodeManager->get_group(0); + $nodes_ref = Varnish::NodeManager->get_nodes($standalone_group); + } + for my $unit (@$groups_ref, @$nodes_ref) { + my $unit_id; + my $is_node; + if (ref($unit) eq "Varnish::Node") { + $unit_id = $unit->get_id(); + $is_node = 1; + } + else { + $unit_id = $unit->get_id(); + $is_node = 0; + next if ($unit_id <= 0); + } + my $time_span = 'minute'; + my ($stat_time, $stat_ref) = Varnish::Statistics->get_last_measure($unit); - my %summary_stat_list; - my %raw_stat_list; - for my $node (@nodes) { - push @{$tmpl_var{'node_infos'}}, { - name => $node->get_name(), + next if (!$stat_ref); + + my $running; + my $all_running; + if ($is_node) { + $running = $all_running = $unit->is_running_ok(); + } + else { + my $nodes_ref = Varnish::NodeManager->get_nodes($unit); + my $running_ok = 0; + for my $node (@$nodes_ref) { + if ($node->is_running_ok()) { + $running_ok++; + } + } + $running = $running_ok > 0; + $all_running = $running_ok == @$nodes_ref; + } + + + push @{$tmpl_var{'unit_infos'}}, { + name => $unit->get_name(), + unit_id => $unit_id, + group_id => ($is_node ? $unit->get_group_id() : $unit_id), + is_node => $is_node, + running => $running, + all_running => $all_running, }; - my $node_stat_ref = $stat_ref->{$node}; - my $node_id = $node->get_id(); - my $time_span = 'minute'; + if (!$tmpl_var{'stat_time'}) { + $tmpl_var{'stat_time'} = strftime("%a %b %e %H:%M:%S %Y", localtime($stat_time)); + } # example of adding graph the graph ID must match that of a predefind graph # which is created in generate_graph found around line 826 + push @{$summary_stat_list{'Hit ratio since start'}}, { + is_graph => 1, + unit_id => $unit_id, + is_node => $is_node, + graph_id => 'cache_hit_ratio_since_start', + }; push @{$summary_stat_list{'Hit ratio'}}, { is_graph => 1, - node_id => $node_id, + unit_id => $unit_id, + is_node => $is_node, graph_id => 'cache_hit_ratio', }; push @{$summary_stat_list{'Connect requests'}}, { is_graph => 1, - node_id => $node_id, + unit_id => $unit_id, + is_node => $is_node, graph_id => 'connect_rate', }; - # example of missing graph_id - push @{$summary_stat_list{'Missing graph'}}, { - is_graph => 1, - node_id => $node_id, - graph_id => 'missing_graph', - }; - # to add custom values, just add values by adding it to the list. The # get_formatted_bytes() function is usefull for displaying byte values # as it will convert to MB, GB etc as needed. - push @{$summary_stat_list{'% of requests served from cache'}}, { - value => get_formatted_percentage($$node_stat_ref{'Cache hits'} - , $$node_stat_ref{'Client requests received'}) + push @{$summary_stat_list{'Hit ratio since start (%)'}}, { + value => get_formatted_percentage(_get_stat('Cache hits', $stat_ref) + , _get_stat('Client requests received', $stat_ref)) }; # these are examples of adding plain values from the raw stats - push @{$summary_stat_list{'Client connections accepted'}}, { - value => $$node_stat_ref{'Client connections accepted'} - }; push @{$summary_stat_list{'Client requests received'}}, { - value => $$node_stat_ref{'Client requests received'} + value => _get_stat('Client requests received', $stat_ref) }; my $total_bytes_served; - if ($$node_stat_ref{'Total header bytes'} - && $$node_stat_ref{'Total body bytes'}) { - $total_bytes_served = $$node_stat_ref{'Total header bytes'} + $$node_stat_ref{'Total header bytes'}; + my $total_header_bytes = _get_stat('Total header bytes', $stat_ref); + my $total_body_bytes = _get_stat('Total body bytes', $stat_ref); + if (defined($total_header_bytes) && defined($total_body_bytes)) { + $total_bytes_served = $total_header_bytes + $total_body_bytes; } push @{$summary_stat_list{'Total bytes served'}}, { 'value' @@ -427,44 +550,40 @@ }; if ($param{'view_raw_stats'}) { - while (my ($stat_name, $value) = each %{$node_stat_ref}) { + while (my ($stat_name, $value) = each %{$stat_ref}) { push @{$raw_stat_list{$stat_name}}, { value => $value, + unit_id => $unit_id, + is_node => $is_node, }; } } } - my $row = 1; - while (my ($stat_name, $values_ref) = each %raw_stat_list) { + my @stat_names = sort(keys(%raw_stat_list)); + for my $stat_name (@stat_names) { push @{$tmpl_var{'raw_stats'}}, { name => $stat_name, - values => $values_ref, - odd_row => $row++ % 2, + values => $raw_stat_list{$stat_name}, } } - $row = 1; - my $graph_row = 0; while (my ($stat_name, $values_ref) = each %summary_stat_list) { if ($values_ref->[0]->{'is_graph'}) { unshift @{$tmpl_var{'summary_stats'}}, { name => $stat_name, values => $values_ref, - odd_row => $graph_row++ % 2, } } else { push @{$tmpl_var{'summary_stats'}}, { name => $stat_name, values => $values_ref, - odd_row => $row++ % 2, } } } $tmpl_var{'error'} = $error; - $tmpl_var{'stat_time'} = $stat_time; return ($template, \%tmpl_var); } @@ -473,8 +592,8 @@ my ($parameter_ref) = @_; my %param = %{$parameter_ref}; - $param{'node_id'} = $$parameter_ref{'node_id'} || ""; - $param{'group'} = $$parameter_ref{'group'} || ""; + $param{'node_id'} = -1 if (!defined($param{'node_id'})); + $param{'group_id'} = -1 if (!defined($param{'group_id'})); my $template = "configure_parameters.tmpl"; my %tmpl_var; @@ -486,60 +605,66 @@ my $unit_parameter_ref = {}; my $error = ""; - my %changed_parameters; + my %changed_parameter; while (my ($parameter, $value) = each %$parameter_ref) { if ($parameter =~ /^new_(.*?)$/ && $$parameter_ref{"old_$1"} ne $value) { - $changed_parameters{$1} = $value; + + $changed_parameter{$1}->{'old_value'} = $$parameter_ref{"old_$1"}; + $changed_parameter{$1}->{'value'} = $value; } } - my @nodes = Varnish::NodeManager->get_nodes(); - my @groups = Varnish::NodeManager->get_groups(); - if (%changed_parameters) { - my $node = first { $_->get_id() eq $param{'node_id'} } @nodes; + my $nodes_ref = Varnish::NodeManager->get_nodes(); + my $groups_ref = Varnish::NodeManager->get_groups(); + if (%changed_parameter) { + my $unit_name; + my $node = Varnish::NodeManager->get_node($param{'node_id'}); if ($node) { - my $management = $node->get_management(); - while (my ($parameter, $value) = each %changed_parameters) { - if (!$management->set_parameter($parameter, $value)) { - $error .= "Could not set parameter $parameter: ". $node->get_management()->get_error() . "\n"; - } - } + $node->update_parameters(\%changed_parameter); + $unit_name = $node->get_name(); } else { - my $group = first { $_ eq $param{'group'} } @groups; - if ($group ne "") { - while (my ($parameter, $value) = each %changed_parameters) { - if (!Varnish::NodeManager->set_group_parameter($group, $parameter, $value)) { - $error .= "Could not set parameter $parameter for group $group: " - . Varnish::NodeManager->get_error() . "\n"; - } - } + my $group = Varnish::NodeManager->get_group($param{'group_id'}); + if ($group) { + $unit_name = $group->get_name(); + $group->update_parameters(\%changed_parameter); } } if ($error eq "") { - my @changed_parameters = keys %changed_parameters; - my $status = "Parameter" . (@changed_parameters > 1 ? "s " : " "); - - $status .= shift @changed_parameters; + my @changed_parameters = keys %changed_parameter; + my $status; + for my $parameter (@changed_parameters) { - $status .= ", $parameter"; + my $change; + + $change .= $changed_parameter{$parameter}->{'old_value'} . ' => '; + $change .= $changed_parameter{$parameter}->{'value'}; + if ($status) { + $status .= ", "; + } + $status .= "$parameter ($change)"; + log_info("[$unit_name] [Parameter change] [$parameter] [$change]"); } + $status = "Parameter" . (@changed_parameters > 1 ? "s " : " ") . $status; $status .= " configured successfully"; + $tmpl_var{'status'} = $status; } } - for my $group (@groups) { + for my $group (@$groups_ref) { + next if $group->get_id() == 0; + my %unit_info = ( - name => $group, - id => $group, + id => $group->get_id(), + name => $group->get_name(), is_node => 0, selected => 0, ); - if ($group eq $param{'group'}) { + if ($group->get_id() eq $param{'group_id'}) { $unit_info{'selected'} = 1; - $unit_parameter_ref = Varnish::NodeManager->get_group_parameters($group); + $unit_parameter_ref = $group->get_parameters(); if (!$unit_parameter_ref) { $error .= "Could not get parameters for group $group. You need to have added a node to set these.\n"; } @@ -547,7 +672,7 @@ push @{$tmpl_var{'unit_infos'}}, \%unit_info; } - for my $node (@nodes) { + for my $node (@$nodes_ref) { my %unit_info = ( name => $node->get_name(), id => $node->get_id(), @@ -556,7 +681,7 @@ ); if ($node->get_id() eq $param{'node_id'}) { $unit_info{'selected'} = 1; - $unit_parameter_ref = $node->get_management()->get_parameters(); + $unit_parameter_ref = $node->get_parameters(); if (!$unit_parameter_ref) { $error .= "Could not get parameters for node " . $node->get_name() . "\n"; } @@ -564,33 +689,39 @@ push @{$tmpl_var{'unit_infos'}}, \%unit_info; } - if ($param{'group'} eq "" && $param{'node_id'} eq "" + if ($param{'group_id'} < 0 && $param{'node_id'} < 0 && @{$tmpl_var{'unit_infos'}} > 0) { $tmpl_var{'unit_infos'}->[0]->{'selected'} = 1; - my $group = $tmpl_var{'unit_infos'}->[0]->{'name'}; - $unit_parameter_ref = Varnish::NodeManager->get_group_parameters($group); - if (!$unit_parameter_ref) { - $error .= "Could not get parameters for group $group\n"; + my $id = $tmpl_var{'unit_infos'}->[0]->{'id'}; + if ($tmpl_var{'unit_infos'}->[0]->{'is_node'}) { + $unit_parameter_ref = Varnish::NodeManager->get_node($id)->get_parameters(); } + else { + $unit_parameter_ref = Varnish::NodeManager->get_group($id)->get_parameters(); + } } - my $row = 0; - while (my ($parameter, $info) = each %{$unit_parameter_ref} ) { + my @parameters = sort(keys(%$unit_parameter_ref)); + for my $parameter (@parameters) { + my $info = $unit_parameter_ref->{$parameter}; my $value = $info->{'value'}; my $unit = $info->{'unit'}; - my $is_boolean = $unit eq "[bool]"; + my $is_boolean = $unit && $unit eq "bool"; if ($is_boolean) { - $value = $value eq "on"; + $value = $value && $value eq "on"; $unit = ''; } - + +# my $description = $info->{'description'}; +# $description =~ s/'/''/g; +# print "INSERT INTO parameter_info(name, unit, description) values('$parameter', '$unit', '$description');\n"; + push @{$tmpl_var{'parameter_infos'}}, { name => $parameter, value => $value, unit => $unit, description => $info->{'description'}, is_boolean => $is_boolean, - odd_row => $row++ % 2, }; } @@ -604,13 +735,16 @@ my ($parameter_ref) = @_; my %param = %{$parameter_ref}; - $param{'node_id'} ||= ""; - $param{'group'} ||= ""; + $param{'node_id'} = -1 if (!defined($param{'node_id'})); + $param{'group_id'} = -1 if (!defined($param{'group_id'})); + $param{'group_name'} ||= ""; $param{'operation'} ||= ""; $param{'name'} ||= ""; $param{'address'} = $$parameter_ref{'address'} || ""; $param{'port'} ||= ""; $param{'management_port'} ||= ""; + $param{'inherit_settings'} ||= ""; + $param{'edit_node'} ||= -1; my $template = "node_management.tmpl"; my %tmpl_var = (); @@ -618,98 +752,135 @@ $tmpl_var{'status'} = ""; $tmpl_var{'add_group'} = 0; $tmpl_var{'group_infos'} = []; - $tmpl_var{'group'} = $param{'group'} || ""; + $tmpl_var{'group_id'} = $param{'group_id'}; $tmpl_var{'node_infos'} = []; $tmpl_var{'default_managment_port'} = 9001; $tmpl_var{'backend_health_infos'} = []; + $tmpl_var{'show_group_controls'} = 1; + $tmpl_var{'show_group'} = 0; + $tmpl_var{'show_add_node'} = 1; + $tmpl_var{'show_node_in_backend_health'} = 1; + $tmpl_var{'inherit_settings'} = 0; + $tmpl_var{'show_inherit_settings'} = 1; my $error = ""; my $status = ""; if ($param{'operation'} eq "add_group") { - if ($param{'group'}) { - Varnish::NodeManager->add_group($param{'group'}); - $status .= "Group " . $param{'group'} . " added successfully."; + if ($param{'group_name'}) { + my $new_group = Varnish::Group->new({name => $param{'group_name'}}); + Varnish::NodeManager->add_group($new_group); + $tmpl_var{'group_id'} = $new_group->get_id(); + $status .= "Group " . $param{'group_name'} . " added successfully."; + log_info("[" . $param{'group_name'} . "] [Added group]"); } else { + $tmpl_var{'group_id'} = -2; $tmpl_var{'add_group'} = 1; } } elsif ($param{'operation'} eq "remove_group") { - if ($param{'group'}) { - Varnish::NodeManager->remove_group($param{'group'}); - $status = "Group " . $param{'group'} . " removed successfully"; - $tmpl_var{'group'} = ""; + if ($param{'group_id'} >= 0) { + my $group = Varnish::NodeManager->get_group($param{'group_id'}); + if (Varnish::NodeManager->remove_group($group)) { + $status = "Group ". $group->get_name() . " removed successfully"; + log_info("[" . $group->get_name() . "] [Removed group]"); + } + else { + $error = "Error removing group " . $group->get_name() . ": " . get_error(); + } + $tmpl_var{'group_id'} = -1; } } elsif ($param{'operation'} eq "start_group") { - my $node_errors = ""; - for my $node (Varnish::NodeManager->get_nodes()) { - if ($node->get_group() eq $param{'group'} - && !$node->is_running()) { - my $management = $node->get_management(); - if (!$management->start()) { - $node_errors .= "Could not start " . $node->get_name() . ": " - . $management->get_error() . ". "; - } - } + my $group = Varnish::NodeManager->get_group($param{'group_id'}); + if ($group->start()) { + $status .= "Group " . $group->get_name() . " started successfully."; + log_info("[" . $group->get_name() . "] [Started group]"); } - - if ($node_errors eq "") { - $status .= "Group " . $param{'group'} . " started successfully."; - } else { - $status .= "Group " . $param{'group'} . " started with errors: $node_errors."; + $status .= "Group " . $group->get_name() . " started with errors: " . get_error(); } } elsif ($param{'operation'} eq "stop_group") { - my $node_errors = ""; - for my $node (Varnish::NodeManager->get_nodes()) { - if ($node->get_group() eq $param{'group'} - && $node->is_running()) { - my $management = $node->get_management(); - if (!$management->stop()) { - $node_errors .= "Could not stop " . $node->get_name() . ": " - . $management->get_error() . ". "; - } - } + my $group = Varnish::NodeManager->get_group($param{'group_id'}); + if ($group->stop()) { + $status .= "Group " . $group->get_name() . " stopped successfully."; + log_info("[" . $group->get_name() . "] [Stopped group]"); } - if ($node_errors eq "") { - $status .= "Group " . $param{'group'} . " stopped successfully."; - } else { - $status .= "Group " . $param{'group'} . " stopped with errors: $node_errors."; + $status .= "Group " . $group->get_name() . " started with errors: " . get_error(); } } + elsif ($param{'operation'} eq "rename_group") { + my $group = Varnish::NodeManager->get_group($param{'group_id'}); + if ($group && $param{'group_name'}) { + my $old_name = $group->get_name(); + + $group->set_name($param{'group_name'}); + Varnish::NodeManager->update_group($group); + log_info("[" . $group->get_name() . "] [Renamed group] [$old_name => " + . $group->get_name() . "]"); + } + } elsif ($param{'operation'} eq 'add_node') { if ($param{'name'} && $param{'address'} && $param{'port'} - && $param{'group'} && $param{'management_port'}) { + && $param{'group_id'} >= 0 && $param{'management_port'}) { my $node = Varnish::Node->new({ name => $param{'name'}, address => $param{'address'}, port => $param{'port'}, - group => $param{'group'}, + group_id => $param{'group_id'}, management_port => $param{'management_port'} }); - Varnish::NodeManager->add_node($node); + my $inherit_settings = $param{'inherit_settings'} ne ""; + Varnish::NodeManager->add_node($node, $inherit_settings); $status .= "Node " . $node->get_name() . " added successfully."; + + log_info("[" . $node->get_name() . "] [Added node]" + . " [name=" . $node->get_name() . "]" + . " [address=" . $node->get_address() . "]" + . " [port=" . $node->get_port() . "]" + . " [group=" . $param{'group_name'} . "]" + . " [management_port=" . $node->get_management_port() . "]"); } else { $error .= "Not enough information to add node:\n"; $error .= "Name: " . $param{'name'} . ":\n"; $error .= "Address: " . $param{'address'} . ":\n"; $error .= "Port: " . $param{'port'} . ":\n"; - $error .= "Group: " . $param{'group'} . ":\n"; $error .= "Management port: " . $param{'management_port'} . ":\n"; } } + elsif ($param{'operation'} eq 'update_node') { + my $node = Varnish::NodeManager->get_node($param{'node_id'}); + + if ($node) { + $node->set_name($param{'name'}); + $node->set_address($param{'address'}); + $node->set_port($param{'port'}); + $node->set_group_id($param{'node_group_id'}); + $node->set_management_port($param{'management_port'}); + + Varnish::NodeManager->update_node($node); + + log_info("[" . $node->get_name() . "] [Updated node]" + . " [name=" . $node->get_name() . "]" + . " [address=" . $node->get_address() . "]" + . " [port=" . $node->get_port() . "]" + . " [group=" . $param{'group_name'} . "]" + . " [management_port=" . $node->get_management_port() . "]"); + } + } + elsif ($param{'operation'} eq "remove_node") { - if ($param{'node_id'}) { + if ($param{'node_id'} >= 0) { my $node = Varnish::NodeManager->get_node($param{'node_id'}); if ($node) { - $tmpl_var{'group'} = $node->get_group(); + $tmpl_var{'group_id'} = $node->get_group_id(); Varnish::NodeManager->remove_node($node); $status .= "Node " . $node->get_name() . " removed successfully."; + log_info("[" . $node->get_name() . "] [Removed node]"); } } else { @@ -717,21 +888,18 @@ } } elsif ($param{'operation'} eq "start_node") { - if ($param{'node_id'}) { + if ($param{'node_id'} >= 0) { my $node = Varnish::NodeManager->get_node($param{'node_id'}); if ($node) { - my $management = $node->get_management(); - if ($node->is_running()) { - $status .= "Node " . $node->get_name() . " already running."; - } - elsif ($management->start() ) { + if ($node->start() ) { $status .= "Node " . $node->get_name() . " started successfully."; + log_info("[" . $node->get_name() . "] [Started node]"); } else { $error .= "Could not start " . $node->get_name() - . ": " . $management->get_error() . "\n"; + . ": " . get_error() . "\n"; } - $tmpl_var{'group'} = $node->get_group(); + $tmpl_var{'group_id'} = $node->get_group_id(); } } else { @@ -739,22 +907,19 @@ } } elsif ($param{'operation'} eq "stop_node") { - if ($param{'node_id'}) { + if ($param{'node_id'} >= 0) { my $node = Varnish::NodeManager->get_node($param{'node_id'}); if ($node) { - my $management = $node->get_management(); - if (!$node->is_running()) { - $status .= "Node " . $node->get_name() . " already stopped."; - } - elsif ($management->stop()) { + if ($node->stop()) { $status .= "Node " . $node->get_name() . " stopped successfully."; + log_info("[" . $node->get_name() . "] [Stopped node]"); } else { $error .= "Could not stop " . $node->get_name() - . ": " . $management->get_error() . "\n"; + . ": " . get_error() . "\n"; } } - $tmpl_var{'group'} = $node->get_group(); + $tmpl_var{'group_id'} = $node->get_group_id(); } else { $error .= "Could not stop node: Missing node ID\n"; @@ -762,24 +927,39 @@ } # Populate the node table - my @groups = Varnish::NodeManager->get_groups(); - if (@groups) { - if (!$tmpl_var{'group'} && !$tmpl_var{'add_group'}) { - $tmpl_var{'group'} = $groups[0]; - } + my $groups_ref = Varnish::NodeManager->get_groups(); + if ($groups_ref) { my @group_infos = map { { - name => $_, - selected => $_ eq $tmpl_var{'group'}, + name => $_->get_name(), + id => $_->get_id(), + is_real => $_->get_id() >= 0, + selected => $_->get_id() eq $tmpl_var{'group_id'}, } - } @groups; + } @$groups_ref; + unshift @group_infos, { + name => "All nodes", + id => -1, + selected => -1 == $tmpl_var{'group_id'}, + }; $tmpl_var{'group_infos'} = \@group_infos; - - my @nodes = Varnish::NodeManager->get_nodes(); - for my $node (@nodes) { - next if ($node->get_group() ne $tmpl_var{'group'}); - - push @{$tmpl_var{'node_infos'}}, { + + my $group; + my $nodes_ref; + if ($tmpl_var{'group_id'} != -1) { + $group = Varnish::NodeManager->get_group($tmpl_var{'group_id'}); + $nodes_ref = Varnish::NodeManager->get_nodes($group); + if ($tmpl_var{'group_id'} == 0) { + $tmpl_var{'show_inherit_settings'} = 0; + } + } + else { + $nodes_ref = Varnish::NodeManager->get_nodes(); + } + for my $node (@$nodes_ref) { + my $group_name = ($group ? $group->get_name() + : Varnish::NodeManager->get_group_name($node->get_group_id)); + my $node_info_ref = { id => $node->get_id(), is_running_ok => $node->is_running_ok(), is_running => $node->is_running(), @@ -788,87 +968,125 @@ address => $node->get_address(), port => $node->get_port(), management_port => $node->get_management_port(), - group => $node->get_group(), + group => $group_name, + edit => $node->get_id() == $param{'edit_node'}, }; - - if (@{$tmpl_var{'backend_health_infos'}} == 0) { - my $backend_health = $node->get_management()->get_backend_health(); - if ($backend_health) { - while (my ($backend, $health) = each %{$backend_health}) { - push @{$tmpl_var{'backend_health_infos'}}, { - name => $backend, - health => $health, - }; - } + my $backend_health = $node->get_backend_health(); + if ($backend_health) { + while (my ($backend, $health) = each %{$backend_health}) { + push @{$tmpl_var{'backend_health_infos'}}, { + name => $backend, + health => $health, + node => $node_info_ref->{'name'}, + }; } } + push @{$tmpl_var{'node_infos'}}, $node_info_ref; } + if (@$nodes_ref == 0) { + $tmpl_var{'inherit_settings'} = 1; + } } else { $tmpl_var{'add_group'} = 1; } + my $selected_group = Varnish::NodeManager->get_group($tmpl_var{'group_id'}); + if ($selected_group) { + $tmpl_var{'group_name'} = $selected_group->get_name(); + } + $tmpl_var{'show_group_controls'} = $tmpl_var{'group_id'} > 0; + $tmpl_var{'show_group'} = $tmpl_var{'group_id'} == -1 || $param{'edit_node'} > -1; + $tmpl_var{'show_add_node'} = $tmpl_var{'group_id'} >= 0; $tmpl_var{'error'} = $error; $tmpl_var{'status'} = $status; return ($template, \%tmpl_var); } -sub generate_graph { - my ($parameter_ref) = @_; + sub generate_graph { + my ($parameter_ref) = @_; - my %param = %{$parameter_ref}; - $param{'width'} ||= 250; - $param{'height'} ||= 150; - $param{'time_span'} ||= "minute"; - $param{'type'} ||= ""; - $param{'node_id'} ||= 0; + my %param = %{$parameter_ref}; + $param{'width'} ||= get_config_value('graph_width'); + $param{'height'} ||= get_config_value('graph_height'); + $param{'time_span'} ||= "minute"; + $param{'unit_id'} ||= -1; + $param{'custom_name'} ||= ""; + $param{'custom_divisors'} ||= ""; + $param{'custom_dividends'} ||= ""; + $param{'custom_delta'} ||= ""; - my $interval = get_config_value('poll_interval'); - # this hash holds available graphs which can be added to the summary stats in the view_stats - # function. - my %graph_info = ( - # the name of the graph - cache_hit_ratio => { - # the parameters to GD::Graph. y_number_format should be noted, as it let you format - # the presentation, like multiplying with 100 to get the percentage as shown here - graph_parameter => { - y_label => '%', - title => "Cache hit ratio last " . $param{'time_span'}, - y_max_value => 1, - y_min_value => 0, - y_number_format => sub { return $_[0] * 100 } + my $interval = get_config_value('poll_interval'); + + # this hash holds available graphs which can be added to the summary stats in the view_stats + # function. + my %graph_info = ( + # the name of the graph + cache_hit_ratio_since_start => { + # the parameters to GD::Graph. y_number_format should be noted, as it let you format + # the presentation, like multiplying with 100 to get the percentage as shown here + graph_parameter => { + y_label => '%', + title => 'Cache hit ratio since start', + y_max_value => 1, + #y_min_value => 0, + y_number_format => sub { return sprintf("%.2f", $_[0] * 100) } + }, + # the divisors and dividends are lists of names of the statistics to + # use when calculating the values in the graph. The names can be obtained + # by turning 'Raw statistics' on in the GUI. The value in the graph is calculated + # by taking the sum of divisors and divide witht the sum of the dividends, i.e. + # value = (divisor1 + divisor2 + divisor3 ...) / (dividend1 + dividend 2 +..) + # if divisor or dividend is emitted, the value of 1 is used instead + divisors => [ 'Cache hits' ], + dividends => [ 'Cache hits', 'Cache misses' ], }, - # the divisors and dividends are lists of names of the statistics to - # use when calculating the values in the graph. The names can be obtained - # by turning 'Raw statistics' on in the GUI. The value in the graph is calculated - # by taking the sum of divisors and divide witht the sum of the dividends, i.e. - # value = (divisor1 + divisor2 + divisor3 ...) / (dividend1 + dividend 2 +..) - # if divisor or dividend is emitted, the value of 1 is used instead - divisors => [ 'Cache hits' ], - dividends => [ 'Cache hits', 'Cache misses' ], - }, - connect_rate => { - graph_parameter => { - y_label => 'Reqs', - title => "Reqs / $interval s last " . $param{'time_span'}, - y_min_value => 0, + connect_rate => { + graph_parameter => { + y_label => 'Reqs', + title => "Reqs / s last " . $param{'time_span'}, + y_min_value => 0, + }, + # here we have no dividends as we only want to plot 'Client requests received' + divisors => [ 'Client requests received' ], + # if use_delta is set to 1, the derived value is used, i.e. the difference + # in value between two measurements. This is usefull for graphs showing rates + # like this connect rate + use_delta => 1, }, - # here we have no dividends as we only want to plot 'Client requests received' - divisors => [ 'Client requests received' ], - # if use_delta is set to 1, the derived value is used, i.e. the difference - # in value between two measurements. This is usefull for graphs showing rates - # like this connect rate - use_delta => 1, - }, - ); - my %time_span_graph_parameters = ( + cache_hit_ratio => { + graph_parameter => { + y_label => '%', + title => "Cache hit last " . $param{'time_span'}, + y_number_format => sub { return sprintf("%.2f", $_[0] * 100) } + }, + divisors => [ 'Cache hits' ], + dividends => [ 'Cache hits', 'Cache misses' ], + # with use_delta set to 2, the delta is calculated by doing + # (divsor(n) - divisor(n-1))/(dividend(n) - dividend(n-1)) + # instead of + # ((divisor(n)/dividend(n-1) - (divisor(n-1)/dividend(n-1) + # in the case + # of use_delta = 1 + use_delta => 2, + }, + custom => { + graph_parameter => { + y_label => 'Value', + title => $param{'custom_name'} . + ($param{'custom_delta'} ? " / s " : "") + . " last " . $param{'time_span'}, + }, + use_delta => $param{'custom_delta'}, + }, + ); + my %time_span_graph_parameters = ( minute => { x_label => 'Time', - x_tick_number => 6, # need to be set to make x_number_format work - x_number_format => sub { return strftime(":%S", localtime($_[0])); }, - x_max_value => time + x_tick_number => 4, # need to be set to make x_number_format work + x_number_format => sub { return strftime("%H:%M:%S", localtime($_[0])); }, }, hour => { x_label => 'Time', @@ -888,38 +1106,50 @@ month => { x_label => 'Time', x_tick_number => 4, # need to be set to make x_number_format work - x_number_format => sub { return strftime("%d.%m", localtime($_[0])); }, + x_number_format => sub { return strftime("%d.%m", localtime($_[0])); }, }, - ); - - - if ( !$graph_info{$param{'type'}} - || !$time_span_graph_parameters{$param{'time_span'}}) { - #print "Error: Missing data"; - return; - } - my $data_ref = Varnish::Statistics->generate_graph_data( - $param{'node_id'}, + ); + + if ( !$graph_info{$param{'type'}} + || !$time_span_graph_parameters{$param{'time_span'}}) { + return; + } + + if ($param{'type'} eq 'custom') { + if ($param{'custom_divisors'}) { + my @divisors = split(/,\s*/, $param{'custom_divisors'}); + $graph_info{'custom'}->{'divisors'} = \@divisors; + } + if ($param{'custom_dividends'}) { + my @dividends = split(/,\s*/, $param{'custom_dividends'}); + $graph_info{'custom'}->{'dividends'} = \@dividends; + } + } + my ($data_ref, $x_min_value, $x_max_value) = Varnish::Statistics->generate_graph_data( + $param{'unit_id'}, + $param{'is_node'}, $param{'time_span'}, $graph_info{$param{'type'}}->{'divisors'}, $graph_info{$param{'type'}}->{'dividends'}, - $graph_info{$param{'type'}}->{'use_delta'} - ); - if (!$data_ref) { - #print "Error generating graph data\n"; - return; - } - my $graph = GD::Graph::lines->new($param{'width'}, $param{'height'}); - $graph->set((%{$graph_info{$param{'type'}}->{'graph_parameter'}}, + $graph_info{$param{'type'}}->{'use_delta'}, + $param{'width'} + ); + return if (!$data_ref); + + my $graph = GD::Graph::lines->new($param{'width'}, $param{'height'}); + if ($param{'width'} < 300) { + $graph->set_title_font(gdTinyFont); + $graph->set_legend_font(gdTinyFont); + } + $graph->set((%{$graph_info{$param{'type'}}->{'graph_parameter'}}, %{$time_span_graph_parameters{$param{'time_span'}}}), - dclrs => ["#990200"]); + dclrs => ["#990200"], + x_min_value => $x_min_value, x_max_value => $x_max_value, + skip_undef => 1); my $graph_image = $graph->plot($data_ref); + return if (!$graph_image); - if (!$graph_image) { - return; - } - return $graph_image->png; } @@ -938,10 +1168,10 @@ $tmpl_var{'default_console_cols'} = 80, $tmpl_var{'default_console_rows'} = 30, - my @nodes = Varnish::NodeManager->get_nodes(); - if (@nodes) { - my $node_id = $param{'node_id'} ? $param{'node_id'} : $nodes[0]->get_id(); - for my $node (@nodes) { + my $nodes_ref = Varnish::NodeManager->get_nodes(); + if ($nodes_ref && @$nodes_ref > 0) { + my $node_id = $param{'node_id'} ? $param{'node_id'} : $nodes_ref->[0]->get_id(); + for my $node (@$nodes_ref) { my $selected = $node->get_id() == $node_id; push @{$tmpl_var{'node_infos'}}, { id => $node->get_id(), @@ -968,7 +1198,7 @@ }, { name => 'Retro', - foreground => 'green', + foreground => '#00ff00', background => 'black', } ]; Modified: trunk/varnish-tools/webgui/Varnish/Statistics.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/Statistics.pm 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/Varnish/Statistics.pm 2009-02-18 15:36:25 UTC (rev 3786) @@ -6,58 +6,59 @@ use Varnish::Util; use Varnish::NodeManager; +use Varnish::DB; { - my %data; - my $last_measure_ref; my $last_measure_time; + my $clean_up_time; + sub BEGIN { + my $now = time(); + my ($sec, $min, $hour) = localtime($now); + $clean_up_time = $now + + (23 - $hour) * 3600 + + (59 - $min) * 60 + + (60 - $sec); + } + sub collect_data { my $time_stamp = time(); - my %measure; - my $good_stat_ref; - my @nodes = Varnish::NodeManager->get_nodes(); + my $nodes_ref = Varnish::NodeManager->get_nodes(); - my @bad_nodes; - for my $node (@nodes) { + if ($time_stamp > $clean_up_time) { + Varnish::DB->clean_up(); + $clean_up_time += 86400; + } + + for my $node (@$nodes_ref) { my $management = $node->get_management(); - my $stat_ref; + my $stat_ref = {}; if ($management) { $stat_ref = $management->get_stats(); } - if ($stat_ref) { - $measure{$node} = $stat_ref; - if (!$good_stat_ref) { - $good_stat_ref = $stat_ref; - } - } - else { - push @bad_nodes, $node; - } + Varnish::DB->add_stat($node, $stat_ref, $time_stamp); } - - if (@bad_nodes && $good_stat_ref) { - for my $bad_node (@bad_nodes) { - $measure{$bad_node}->{'missing data'} = 1; - for my $key (keys %$good_stat_ref) { - $measure{$bad_node}->{$key} = -1; - } - } - } - - $data{$time_stamp} = \%measure; - $last_measure_ref = \%measure; $last_measure_time = $time_stamp; } sub get_last_measure { - - return ($last_measure_time, $last_measure_ref); + my ($self, $unit) = @_; + + my $stat_data_ref = Varnish::DB->get_stat_data($unit, $last_measure_time - 1); + if ($stat_data_ref) { + delete $stat_data_ref->[0]->{'has_data'}; + + return ($last_measure_time, $stat_data_ref->[0]); + } + else { + return (undef, undef); + } } sub generate_graph_data { - my ($self, $node_id, $time_span, $divisors_ref, $dividends_ref, $use_delta) = @_; + my ($self, $unit_id, $is_node, $time_span, $divisors_ref, $dividends_ref, $use_delta, $desired_number_of_values) = @_; + $desired_number_of_values ||= 0; my %seconds_for = ( minute => 60, @@ -66,37 +67,59 @@ week => 604800, month => 18144000, # 30 days ); - my $start_time = time() - $seconds_for{$time_span}; + my $current_time = time(); + my $start_time = $current_time - $seconds_for{$time_span}; + my $poll_interval = get_config_value('poll_interval'); if ($use_delta) { - $start_time -= get_config_value('poll_interval'); + $start_time -= $poll_interval; } - my $node = first { - $_->get_id() == $node_id - } Varnish::NodeManager->get_nodes(); + + my $measures_ref; + if ($is_node) { + my $node = Varnish::NodeManager->get_node($unit_id); + return ([],[], -1, -1) if (!$node); + $measures_ref = Varnish::DB->get_stat_data($node, $start_time); + } + else { + my $group = Varnish::NodeManager->get_group($unit_id); + return ([],[], -1, -1) if (!$group); + $measures_ref = Varnish::DB->get_stat_data($group, $start_time); + } - my @measures = grep { - $_ > $start_time - } (sort keys %data); + my @divisors = ($divisors_ref ? + map { get_db_friendly_name($_); } @$divisors_ref : ()); + my @dividends = ($dividends_ref ? + map { get_db_friendly_name($_); } @$dividends_ref : ()); my @values; + my @times; + my $value2; my $last_value; + my $last_divisor; + my $last_dividend; + my $last_total_requests; + my $last_time; + my $x_min; + my $x_max; GENERATE_DATA: - for my $measure (@measures) { + for my $measure_ref (@$measures_ref) { my $value; - if (!$data{$measure}->{$node}->{'missing data'}) { + my $time = $measure_ref->{'time'}; + + if ($measure_ref->{'has_data'}) { my $divisor_value = 0; my $dividend_value = 0; - if ($divisors_ref && @$divisors_ref) { - for my $divisor (@$divisors_ref) { - $divisor_value += $data{$measure}->{$node}->{$divisor}; + if (@divisors > 0) { + for my $divisor (@divisors) { + $divisor_value += $measure_ref->{$divisor}; } } else { $divisor_value = 1; } - if ($dividends_ref && @$dividends_ref) { - for my $dividend (@$dividends_ref) { - $dividend_value += $data{$measure}->{$node}->{$dividend}; + if (@dividends) { + for my $dividend (@dividends) { + $dividend_value += $measure_ref->{$dividend}; } } else { @@ -109,23 +132,102 @@ if ($use_delta) { if (!$last_value) { $last_value = $value; + $last_dividend = $dividend_value; + $last_divisor = $divisor_value; + $last_time = $time; + $last_total_requests = $measure_ref->{'total_requests'}; next GENERATE_DATA; } - my $delta_value = $value - $last_value; + my $delta_time = $time - $last_time; + my $delta_value; + if ($use_delta == 2) { + if ($dividend_value != $last_dividend) { + $delta_value = + ($divisor_value - $last_divisor) / ($dividend_value - $last_dividend); + } + else { + $delta_value = undef; + } + } + else { + $delta_value = ($value - $last_value) / $delta_time; + } + $last_value = $value; - # if the value is negative, then we have had restart and don't plot it. - if ($delta_value < 0) { + # check if node has been restarted, as the delta would be huge + # and negative if it has + my $total_requests = $measure_ref->{'total_requests'}; + if ($total_requests < $last_total_requests) { $value = undef; } else { $value = $delta_value; } + + $last_dividend = $dividend_value; + $last_divisor = $divisor_value; + $last_total_requests = $total_requests; + $last_time = $time; } } + + $x_min ||= $time; + $x_max = $time; + + push @times, $time; push @values, $value; } + + my $possible_number_of_values = $seconds_for{$time_span} / $poll_interval; + if ($desired_number_of_values && + $possible_number_of_values > $desired_number_of_values) { + my $partition_size = $seconds_for{$time_span} / $desired_number_of_values; + my $start_time = shift @times; + my $aggregated_value = shift @values; + my $aggregated_width = (defined($aggregated_value) ? 1 : 0); + my $end_time = $start_time + $partition_size; + my @new_times; + my @new_values; + + while (my $time = shift(@times)) { + my $value = shift @values; + if ($time < $end_time) { + if (defined($value)) { + $aggregated_value += $value; + $aggregated_width++; + } + } + else { + push @new_times, $start_time; + if ($aggregated_width > 0) { + push @new_values, $aggregated_value / $aggregated_width; + } + else { + push @new_values, undef; + } + $start_time = $time; + $end_time = $start_time + $partition_size; + $aggregated_value = $value; + $aggregated_width = (defined($value) ? 1 : 0); + } + } + + push @new_times, $start_time; + if ($aggregated_width > 0) { + push @new_values, $aggregated_value / $aggregated_width; + } + else { + push @new_values, undef; + } - return [ \@measures, \@values ]; + @times = @new_times; + @values = @new_values; + } + + unshift @times, $start_time; + unshift @values, undef; + + return ([\@times, \@values], $x_min, $x_max); } } Modified: trunk/varnish-tools/webgui/Varnish/Util.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/Util.pm 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/Varnish/Util.pm 2009-02-18 15:36:25 UTC (rev 3786) @@ -3,6 +3,9 @@ use strict; use Exporter; use base qw(Exporter); +use POSIX qw(strftime); +use URI::Escape; +use Algorithm::Diff; our @EXPORT = qw( set_config @@ -10,15 +13,35 @@ read_file get_formatted_percentage get_formatted_bytes + get_db_friendly_name + get_error + set_error + no_error + log_info + log_error + url_encode + url_decode + diff ); { my %config; + my $error; + my $log_handle; sub set_config { my ($config_ref) = @_; %config = %{$config_ref}; + + if ($config{'log_filename'}) { + if (!open($log_handle, ">>" . $config{'log_filename'})) { + die "Could not open log file " . $config{'log_filename'} . " for writing"; + } + $log_handle->autoflush(1); # FIXME: Remove it, or is it usefull? + } + + Varnish::DB->init($config{'db_filename'}); } sub get_config_value { @@ -63,6 +86,107 @@ return $bytes . " B"; } } + + sub get_db_friendly_name { + my ($name) = @_; + + $name =~ s/ /_/g; + $name =~ s/\(/_/g; + $name =~ s/\)/_/g; + + return lc($name); + } + + + sub set_error { + my ($new_error) = @_; + + $error = $new_error; + + return; + } + + sub get_error { + + return $error; + } + + sub no_error { + my ($return_value) = @_; + + $error = ""; + + return defined($return_value) ? $return_value : 1; + } + + sub _log { + my ($severity, $string) = @_; + + return if (!$log_handle); + + my $time_stamp = strftime("%Y-%m-%d %H:%M:%S", localtime); + print $log_handle "[$time_stamp] [$severity] $string\n"; + } + + sub log_error { + my ($string) = @_; + + _log("ERROR", $string); + } + + sub log_info { + my ($string) = @_; + + _log("INFO", $string); + } + + sub url_decode { + my ($value) = @_; + + $value = uri_unescape($value); + $value =~ s/\+/ /g; + + return $value; + } + + sub url_encode { + my ($value) = @_; + + $value = uri_escape($value); + $value =~ s/ /\+/g; + + return $value; + } + + sub diff { + my ($old_text, $new_text) = @_; + + my @old_text_lines = split /\n/, $old_text; + my @new_text_lines = split /\n/, $new_text; + my $diff_text = ""; + my $diff = Algorithm::Diff->new( \@old_text_lines, \@new_text_lines ); + $diff->Base( 1 ); # Return line numbers, not indices + while ($diff->Next()) { + next if $diff->Same(); + my $sep = ''; + if (!$diff->Items(2)) { + $diff_text .= sprintf("%d,%dd%d\n", + $diff->Get(qw( Min1 Max1 Max2 ))); + } elsif (!$diff->Items(1)) { + $diff_text .= sprintf("%da%d,%d\n", + $diff->Get(qw( Max1 Min2 Max2 ))); + } else { + $sep = "---\n"; + $diff_text .= sprintf("%d,%dc%d,%d\n", + $diff->Get(qw( Min1 Max1 Min2 Max2 ))); + } + $diff_text .= "< $_" for $diff->Items(1); + $diff_text .= $sep; + $diff_text .= "> $_" for $diff->Items(2); + } + + return $diff_text; + } } 1; Added: trunk/varnish-tools/webgui/create_db_data.pl =================================================================== --- trunk/varnish-tools/webgui/create_db_data.pl (rev 0) +++ trunk/varnish-tools/webgui/create_db_data.pl 2009-02-18 15:36:25 UTC (rev 3786) @@ -0,0 +1,137 @@ +#!/usr/bin/perl +# +# This script generates the database schema SQL and Varnish::DB_Data module needed +# by the web GUI. It connects to the management port of a running Varnish and extracts +# the paramter and stat values. + +use strict; + +use Varnish::Node; +use Varnish::Util; + +# The hostname of the varnish to extract the parameter and stat values from +my $hostname = "localhost"; +my $management_port = 9001; + + +my $node_info_ref = { + name => 'dummy', + address => $hostname, + group_id => 0, + management_port => $management_port, +}; +my $node = Varnish::Node->new($node_info_ref); +if (!$node->get_management()->ping()) { + print STDERR "Could not contact " . $node_info_ref->{'address'} + . ":" . $node_info_ref->{'management_port'} . ": " . get_error() . "\n"; + exit(-1); +} + +my $stat_ref = $node->get_management()->get_stats(); +my $stat_fields_exists_string = "my %stat_field_exist = ("; +my $stat_fields_sql; +for my $stat (keys(%$stat_ref)) { + my $name = get_db_friendly_name($stat); + $stat_fields_sql .= $name . " INTEGER,\n"; + $stat_fields_exists_string .= "'$name' => 1,\n"; +} +$stat_fields_exists_string .= ");\n"; + +my $parameter_ref = $node->get_parameters(); +my $parameter_fields_sql; +my $parameter_info_sql; +my $parameters_field_string = "my %parameter_field = (\n"; +for my $parameter (sort(keys(%$parameter_ref))) { + my $name = get_db_friendly_name($parameter); + if ($name eq "user" || $name eq "group") { + $name = "child_$name"; + } + $parameter_fields_sql .= $name . " TEXT,\n"; + my $unit = $parameter_ref->{$parameter}->{'unit'}; + $unit =~ s/'/''/g; + my $description = $parameter_ref->{$parameter}->{'description'}; + $description =~ s/'/''/g; + $parameter_info_sql .= sprintf("INSERT INTO parameter_info VALUES('%s', '%s', '%s');\n", + $name, $unit, $description); + + my $value = $parameter_ref->{$parameter}->{'value'}; + $value =~ s/'/\\'/g; + $name = get_db_friendly_name($parameter); + $parameters_field_string .= "'$name' => {value => '$value'},\n"; +} +$parameters_field_string .= ");\n"; + +my $sql = <<"END_SQL"; +DROP TABLE node_group; +DROP TABLE node; +DROP TABLE stat; +DROP TABLE parameters; +DROP TABLE parameter_info; +DROP TABLE vcl; + +CREATE TABLE node_group ( + id INTEGER PRIMARY KEY, + active_vcl TEXT, + name text +); + +CREATE TABLE node ( + id INTEGER PRIMARY KEY, + name TEXT, + address TEXT, + port TEXT, + group_id INTEGER, + management_port TEXT, + is_master BOOLEAN +); + +CREATE TABLE stat ( + id INTEGER PRIMARY KEY, + time TIMESTAMP, + node_id INTEGER, +$stat_fields_sql + has_data INTEGER +); + +CREATE TABLE parameters ( + id INTEGER PRIMARY KEY, +$parameter_fields_sql + group_id INTEGER +); + +CREATE TABLE vcl( + group_id INTEGER, + name TEXT, + vcl TEXT +); + +CREATE TABLE parameter_info( + name TEXT PRIMARY KEY, + unit TEXT, + description TEXT +); + +INSERT INTO node_group VALUES(0, 0, 'Standalone'); + +$parameter_info_sql +END_SQL + +my $sql_file = "varnish_webgui.sql"; +open(my $SQL, ">$sql_file") || die "Could not open SQL output file"; +print $SQL "-- This file was auto generated " . localtime() . " by create_db_files.pl\n"; +print $SQL $sql; +close($SQL); +print "Wrote SQL to $sql_file successfully\n"; + +my $db_data_file = "Varnish/DB_Data.pm"; +open(my $DB_DATA, ">$db_data_file") || die "Could not open DB fields"; +print $DB_DATA "# This file was auto generated " . localtime() . " by create_db_files.pl\n"; +print $DB_DATA "# DO NOT EDIT BUT RERUN THE SCRIPT!\n"; +print $DB_DATA "package Varnish::DB_Data;\n\n"; +print $DB_DATA $parameters_field_string; +print $DB_DATA $stat_fields_exists_string; +print $DB_DATA "sub get_parameter_field() { return \\%parameter_field; }"; +print $DB_DATA "sub get_stat_field_exist() { return \\%stat_field_exist; }"; +print $DB_DATA "\n1;\n"; +close $DB_DATA; +print "Wrote SQL to $db_data_file successfully\n"; Property changes on: trunk/varnish-tools/webgui/create_db_data.pl ___________________________________________________________________ Name: svn:executable + * Modified: trunk/varnish-tools/webgui/css/web.css =================================================================== --- trunk/varnish-tools/webgui/css/web.css 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/css/web.css 2009-02-18 15:36:25 UTC (rev 3786) @@ -24,7 +24,7 @@ } #menu { - padding: 5px 3px 5px 3px; + padding: 5px 3px 5px 15px; text-align: center; } @@ -49,6 +49,7 @@ } td.header { + vertical-align: top; font-weight: bold; border-style: solid; border-width: 0px 0px 1px 0px; @@ -187,3 +188,16 @@ background-color: red; padding: 5px; } + +td.addNodeBorder { + margin: 15px; +} + +img.goToNodeManagement { + border-width: 0 0 1px 0; +} + +a.showNodeStats { + font-size: 0.7em; + margin-left: 30px; +} Modified: trunk/varnish-tools/webgui/start.pl =================================================================== --- trunk/varnish-tools/webgui/start.pl 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/start.pl 2009-02-18 15:36:25 UTC (rev 3786) @@ -11,6 +11,7 @@ use Varnish::NodeManager; use Varnish::Node; use Varnish::Statistics; +use Varnish::DB; # Configuration starts here @@ -23,58 +24,29 @@ # 'poll_intervall' is the polling interval for the statistics poll_interval => 5, -); -# create some default groups -my @groups = qw(default images); +# 'restricted' gives a restricted version of the web GUI, disabling the user +# from changing any values + restricted => 0, -# create some default nodes -my @node_params = ( - { - name => 'varnish-1', - address => 'localhost', - port => '80', - group => 'default', - management_port => 9001, - }, - { - name => 'varnish-2', - address => 'localhost', - port => '8181', - group => 'default', - management_port => 9002, - }, - { - name => 'varnish-1', - address => 'localhost', - port => '8888', - group => 'images', - management_port => 9003, - }, -); +# 'graph_width' and 'graph_height' are width and height for the graphs in 'View stats' + graph_width => 250, + graph_height => 125, +# 'large_graph_width' and 'large_graph_height' are width and height for the full size graph +# when clicking a stat graph in 'View stats' + large_graph_width => 1000, + large_graph_height => 500, +# 'log_filename' is the filename to log errors and information about actions done in the GUI + log_filename => "varnish.log", + +# 'db_filename' is the sqlite3 database created with the SQL outputed from create_db_data.pl + db_filename => 'varnish.db', +); # End of configuration set_config(\%config); -for my $group (@groups) { - Varnish::NodeManager->add_group($group); -} - -for my $node_param_ref (@node_params) { - my $group_exists = grep { - $_ eq $node_param_ref->{'group'} - } @groups; - if ($group_exists) { - my $node = Varnish::Node->new($node_param_ref); - Varnish::NodeManager->add_node($node); - } - else { - print "Node " . $node_param_ref->{'name'} . " has an invalid group " - . $node_param_ref->{'group'} . ". Skipping."; - } -} - # catch interupt to stop the daemon $SIG{'INT'} = sub { print "Interrupt detected.\n"; @@ -85,15 +57,23 @@ # print "Pipe ignored\n"; }; +log_info("Starting HTTP daemon"); my $daemon = HTTP::Daemon->new( LocalPort => $config{'port'}, LocalAddr => $config{'address'}, - ReuseAddr => 1 ) || die "Could not start web server"; + ReuseAddr => 1 ); + +if (!$daemon) { + log_error("Could not start HTTP daemon"); + die "Could not start web server"; +} +log_info("HTTP daemon started with URL " . $daemon->url); print "Web server started with URL: " . $daemon->url, "\n"; my $data_collector_handle = threads->create('data_collector_thread'); while (my $connection = $daemon->accept) { REQUEST: while (my $request = $connection->get_request) { $connection->force_last_request; +# print "Request for: " . $request->uri . "\n"; if ($request->uri =~ m{/(.*?\.png)} || $request->uri =~ m{/(.*?\.css)} || $request->uri =~ m{/(.*?\.ico)}) { @@ -114,25 +94,25 @@ $connection->close(); undef($connection); } -print "Shutting down!\n"; +log_info("Shutting down web server"); $daemon->close(); -Varnish::NodeManager->quit(); -print "Stopping data collector thread\n"; +Varnish::DB->finish(); +log_info("Stopping data collector thread"); $data_collector_handle->join(); sub data_collector_thread { my $url = $daemon->url . "collect_data"; my $interval = $config{'poll_interval'}; - print "Data collector thread started. Polling URL $url at $interval seconds interval\n"; - + + log_info("Data collector thread started. Polling URL $url at $interval seconds interval"); sleep 1; # wait for the server to come up while (1) { my $user_agent = LWP::UserAgent->new; - $user_agent->timeout(6); + $user_agent->timeout(10); my $response = $user_agent->get($url); last if ($response->code eq "500"); - sleep $interval; + sleep($interval); } print "Data collector thread stopped.\n"; } Modified: trunk/varnish-tools/webgui/templates/configure_parameters.tmpl =================================================================== --- trunk/varnish-tools/webgui/templates/configure_parameters.tmpl 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/templates/configure_parameters.tmpl 2009-02-18 15:36:25 UTC (rev 3786) @@ -20,15 +20,15 @@ - + - (node) + (N) - (group) + (G) @@ -37,14 +37,25 @@ - + + +
NameValueUnit
+ + +on + +off + + + + + + - @@ -67,7 +77,7 @@ - + @@ -78,9 +88,11 @@
Modified: trunk/varnish-tools/webgui/templates/edit_vcl.tmpl =================================================================== --- trunk/varnish-tools/webgui/templates/edit_vcl.tmpl 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/templates/edit_vcl.tmpl 2009-02-18 15:36:25 UTC (rev 3786) @@ -105,16 +105,18 @@ } - +
- + - + + (N) (G) +
@@ -124,6 +126,7 @@
+ | + + - + - + + -| +| +
Modified: trunk/varnish-tools/webgui/templates/management_console.tmpl =================================================================== --- trunk/varnish-tools/webgui/templates/management_console.tmpl 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/templates/management_console.tmpl 2009-02-18 15:36:25 UTC (rev 3786) @@ -1,3 +1,6 @@ + +Management console disabled in restricted mode. + + + + + - + + + + + - + +
+
+ + + + + + + + + + + + - + + + + + + - + + + - + + + + - + + + + + +
V M NameGroup Address Port Management port
@@ -54,10 +68,44 @@ + + + + + + +
@@ -74,65 +122,115 @@
+ + + + + +
- +
 
checked>Group inherit settings - +
- + + + + + - + + + + +
BackendHealth
NodeBackendHealth
No backend health information available
+ +
+ +
- +
- +
- + + + + +
+
+
+ - +
+
+
+ + Modified: trunk/varnish-tools/webgui/templates/view_stats.tmpl =================================================================== --- trunk/varnish-tools/webgui/templates/view_stats.tmpl 2009-02-18 08:15:44 UTC (rev 3785) +++ trunk/varnish-tools/webgui/templates/view_stats.tmpl 2009-02-18 15:36:25 UTC (rev 3786) @@ -1,17 +1,43 @@ - +

Statistics collected at @@ -24,20 +50,51 @@

- - - + + @@ -47,16 +104,15 @@ - +
-

Summary

+
+

+Summary + +for + +

+ +Back to all groups and standalones +
+ + +src="images/running.png" + + +src="images/running_nok.png" + +src="images/stopped.png" +/> + + + + + +(N) + +(G)
+ +(show group) + +
+
- +
-
+
Last: -Mi -H -D -W -Mo +Mi +H +D +W
@@ -71,29 +127,51 @@
- +
+ + + + + +
-Raw statistics: On Off +Raw statistics: On Off -Raw statistics: On Off +Raw statistics: On Off
| Auto refresh: -On Off +On Off -On Off +On Off +| Raw data as CSV No nodes available
Added: trunk/varnish-tools/webgui/templates/view_stats_csv.tmpl =================================================================== --- trunk/varnish-tools/webgui/templates/view_stats_csv.tmpl (rev 0) +++ trunk/varnish-tools/webgui/templates/view_stats_csv.tmpl 2009-02-18 15:36:25 UTC (rev 3786) @@ -0,0 +1,2 @@ +; + Added: trunk/varnish-tools/webgui/varnish_webgui.sql =================================================================== --- trunk/varnish-tools/webgui/varnish_webgui.sql (rev 0) +++ trunk/varnish-tools/webgui/varnish_webgui.sql 2009-02-18 15:36:25 UTC (rev 3786) @@ -0,0 +1,247 @@ +-- This file was auto generated Wed Feb 18 15:58:37 2009 by create_db_files.pl +DROP TABLE node_group; +DROP TABLE node; +DROP TABLE stat; +DROP TABLE parameters; +DROP TABLE parameter_info; +DROP TABLE vcl; + +CREATE TABLE node_group ( + id INTEGER PRIMARY KEY, + active_vcl TEXT, + name text +); + +CREATE TABLE node ( + id INTEGER PRIMARY KEY, + name TEXT, + address TEXT, + port TEXT, + group_id INTEGER, + management_port TEXT, + is_master BOOLEAN +); + +CREATE TABLE stat ( + id INTEGER PRIMARY KEY, + time TIMESTAMP, + node_id INTEGER, +session_pipeline INTEGER, +shm_mtx_contention INTEGER, +n_overflowed_work_requests INTEGER, +backend_connections_failures INTEGER, +n_worker_threads_limited INTEGER, +sma_outstanding_bytes INTEGER, +backend_connections_too_many INTEGER, +shm_cycles_through_buffer INTEGER, +esi_parse_errors__unlock_ INTEGER, +total_pipe INTEGER, +n_worker_threads_created INTEGER, +objects_sent_with_write INTEGER, +backend_connections_success INTEGER, +n_dropped_work_requests INTEGER, +objects_overflowing_workspace INTEGER, +sms_outstanding_bytes INTEGER, +client_requests_received INTEGER, +n_objects_on_deathrow INTEGER, +n_total_active_purges INTEGER, +backend_requests_made INTEGER, +bytes_allocated INTEGER, +outstanding_allocations INTEGER, +objects_esi_parsed__unlock_ INTEGER, +n_struct_vbe_conn INTEGER, +cache_hits_for_pass INTEGER, +n_lru_saved_objects INTEGER, +cache_hits INTEGER, +sma_outstanding_allocations INTEGER, +total_pass INTEGER, +backend_connections_reuses INTEGER, +backend_connections_not_attempted INTEGER, +shm_flushes_due_to_overflow INTEGER, +n_duplicate_purges_removed INTEGER, +n_new_purges_added INTEGER, +session_closed INTEGER, +cache_misses INTEGER, +n_struct_srcaddr INTEGER, +sms_allocator_requests INTEGER, +session_herd INTEGER, +n_worker_threads_not_created INTEGER, +n_vcl_discarded INTEGER, +hcb_lookups_without_lock INTEGER, +n_worker_threads INTEGER, +n_lru_nuked_objects INTEGER, +n_queued_work_requests INTEGER, +total_sessions INTEGER, +total_header_bytes INTEGER, +n_objects_tested INTEGER, +n_active_struct_srcaddr INTEGER, +bytes_free INTEGER, +n_vcl_total INTEGER, +n_backends INTEGER, +sma_bytes_free INTEGER, +total_body_bytes INTEGER, +shm_records INTEGER, +n_vcl_available INTEGER, +sma_bytes_allocated INTEGER, +objects_sent_with_sendfile INTEGER, +hcb_lookups_with_lock INTEGER, +n_struct_sess_mem INTEGER, +client_connections_accepted INTEGER, +n_struct_bereq INTEGER, +sms_bytes_freed INTEGER, +sms_outstanding_allocations INTEGER, +sms_bytes_allocated INTEGER, +n_small_free_smf INTEGER, +n_struct_objecthead INTEGER, +total_fetch INTEGER, +sma_allocator_requests INTEGER, +backend_connections_recycles INTEGER, +backend_connections_unused INTEGER, +shm_writes INTEGER, +n_struct_object INTEGER, +total_requests INTEGER, +hcb_inserts INTEGER, +n_lru_moved_objects INTEGER, +n_struct_sess INTEGER, +allocator_requests INTEGER, +n_regexps_tested_against INTEGER, +n_expired_objects INTEGER, +http_header_overflows INTEGER, +n_struct_smf INTEGER, +n_old_purges_deleted INTEGER, +n_large_free_smf INTEGER, +session_read_ahead INTEGER, +session_linger INTEGER, + + has_data INTEGER +); + +CREATE TABLE parameters ( + id INTEGER PRIMARY KEY, +accept_fd_holdoff TEXT, +auto_restart TEXT, +backend_http11 TEXT, +between_bytes_timeout TEXT, +cache_vbe_conns TEXT, +cc_command TEXT, +cli_banner TEXT, +cli_buffer TEXT, +cli_timeout TEXT, +client_http11 TEXT, +clock_skew TEXT, +connect_timeout TEXT, +default_grace TEXT, +default_ttl TEXT, +diag_bitmap TEXT, +err_ttl TEXT, +esi_syntax TEXT, +fetch_chunksize TEXT, +first_byte_timeout TEXT, +child_group TEXT, +listen_address TEXT, +listen_depth TEXT, +log_hashstring TEXT, +log_local_address TEXT, +lru_interval TEXT, +max_esi_includes TEXT, +max_restarts TEXT, +obj_workspace TEXT, +overflow_max TEXT, +ping_interval TEXT, +pipe_timeout TEXT, +prefer_ipv6 TEXT, +purge_dups TEXT, +purge_hash TEXT, +rush_exponent TEXT, +send_timeout TEXT, +sess_timeout TEXT, +sess_workspace TEXT, +session_linger TEXT, +shm_reclen TEXT, +shm_workspace TEXT, +srcaddr_hash TEXT, +srcaddr_ttl TEXT, +thread_pool_add_delay TEXT, +thread_pool_add_threshold TEXT, +thread_pool_fail_delay TEXT, +thread_pool_max TEXT, +thread_pool_min TEXT, +thread_pool_purge_delay TEXT, +thread_pool_timeout TEXT, +thread_pools TEXT, +child_user TEXT, +vcl_trace TEXT, +waiter TEXT, + + group_id INTEGER +); + +CREATE TABLE vcl( + group_id INTEGER, + name TEXT, + vcl TEXT +); + +CREATE TABLE parameter_info( + name TEXT PRIMARY KEY, + unit TEXT, + description TEXT +); + +INSERT INTO node_group VALUES(0, 0, 'Standalone'); + +INSERT INTO parameter_info VALUES('accept_fd_holdoff', 'ms', 'Default is 50. If we run out of file descriptors, the accept thread will sleep. This parameter control for how long it will sleep. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('auto_restart', 'bool', 'Default is on. Restart child process automatically if it dies. '); +INSERT INTO parameter_info VALUES('backend_http11', 'bool', 'Default is on. Force all backend requests to be HTTP/1.1. By default we copy the protocol version from the incoming client request. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('between_bytes_timeout', 's', 'Default is 60. Default timeout between bytes when receiving data from backend. We only wait for this many seconds between bytes before giving up. A value of 0 means it will never time out. VCL can override this default value for each backend request and backend request. This parameter does not apply to pipe. '); +INSERT INTO parameter_info VALUES('cache_vbe_conns', 'bool', 'Default is off. Cache vbe_conn''s or rely on malloc, that''s the question. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('cc_command', '', 'Default is exec cc -fpic -shared -Wl,-x -o %o %s. Command used for compiling the C source code to a dlopen(3) loadable object. Any occurrence of %s in the string will be replaced with the source file name, and %o will be replaced with the output file name. NB: This parameter will not take any effect until the VCL programs have been reloaded. '); +INSERT INTO parameter_info VALUES('cli_banner', 'bool', 'Default is on. Emit CLI banner on connect. Set to off for compatibility with pre 2.1 versions. '); +INSERT INTO parameter_info VALUES('cli_buffer', 'bytes', 'Default is 8192. Size of buffer for CLI input. You may need to increase this if you have big VCL files and use the vcl.inline CLI command. NB: Must be specified with -p to have effect. '); +INSERT INTO parameter_info VALUES('cli_timeout', 'seconds', 'Default is 5. Timeout for the childs replies to CLI requests from the master. '); +INSERT INTO parameter_info VALUES('client_http11', 'bool', 'Default is off. Force all client responses to be HTTP/1.1. By default we copy the protocol version from the backend response. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('clock_skew', 's', 'Default is 10. How much clockskew we are willing to accept between the backend and our own clock. '); +INSERT INTO parameter_info VALUES('connect_timeout', 's', 'Default is 0.4. Default connection timeout for backend connections. We only try to connect to the backend for this many seconds before giving up. VCL can override this default value for each backend and backend request. '); +INSERT INTO parameter_info VALUES('default_grace', '', 'Default is 10seconds. Default grace period. We will deliver an object this long after it has expired, provided another thread is attempting to get a new copy. NB: This parameter may take quite some time to take (full) effect. '); +INSERT INTO parameter_info VALUES('default_ttl', 'seconds', 'Default is 120. The TTL assigned to objects if neither the backend nor the VCL code assigns one. Objects already cached will not be affected by changes made until they are fetched from the backend again. To force an immediate effect at the expense of a total flush of the cache use "url.purge ." '); +INSERT INTO parameter_info VALUES('diag_bitmap', 'bitmap', 'Default is 0. Bitmap controlling diagnostics code: 0x00000001 - CNT_Session states. 0x00000002 - workspace debugging. 0x00000004 - kqueue debugging. 0x00000008 - mutex logging. 0x00000010 - mutex contests. 0x00000020 - waiting list. 0x00000040 - object workspace. 0x00001000 - do not core-dump child process. 0x00002000 - only short panic message. 0x00004000 - panic to stderr. 0x00010000 - synchronize shmlog. Use 0x notation and do the bitor in your head :-) '); +INSERT INTO parameter_info VALUES('err_ttl', 'seconds', 'Default is 0. The TTL assigned to the synthesized error pages '); +INSERT INTO parameter_info VALUES('esi_syntax', 'bitmap', 'Default is 0. Bitmap controlling ESI parsing code: 0x00000001 - Don''t check if it looks like XML 0x00000002 - Ignore non-esi elements 0x00000004 - Emit parsing debug records Use 0x notation and do the bitor in your head :-) '); +INSERT INTO parameter_info VALUES('fetch_chunksize', 'kilobytes', 'Default is 128. The default chunksize used by fetcher. This should be bigger than the majority of objects with short TTLs. Internal limits in the storage_file module makes increases above 128kb a dubious idea. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('first_byte_timeout', 's', 'Default is 60. Default timeout for receiving first byte from backend. We only wait for this many seconds for the first byte before giving up. A value of 0 means it will never time out. VCL can override this default value for each backend and backend request. This parameter does not apply to pipe. '); +INSERT INTO parameter_info VALUES('child_group', '', 'Default is . The unprivileged group to run as. NB: This parameter will not take any effect until the child process has been restarted. '); +INSERT INTO parameter_info VALUES('listen_address', '', 'Default is :80. Whitespace separated list of network endpoints where Varnish will accept requests. Possible formats: host, host:port, :port NB: This parameter will not take any effect until the child process has been restarted. '); +INSERT INTO parameter_info VALUES('listen_depth', 'connections', 'Default is 1024. Listen queue depth. NB: This parameter will not take any effect until the child process has been restarted. '); +INSERT INTO parameter_info VALUES('log_hashstring', 'bool', 'Default is off. Log the hash string to shared memory log. '); +INSERT INTO parameter_info VALUES('log_local_address', 'bool', 'Default is off. Log the local address on the TCP connection in the SessionOpen shared memory record. '); +INSERT INTO parameter_info VALUES('lru_interval', 'seconds', 'Default is 2. Grace period before object moves on LRU list. Objects are only moved to the front of the LRU list if they have not been moved there already inside this timeout period. This reduces the amount of lock operations necessary for LRU list access. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('max_esi_includes', 'includes', 'Default is 5. Maximum depth of esi:include processing. '); +INSERT INTO parameter_info VALUES('max_restarts', 'restarts', 'Default is 4. Upper limit on how many times a request can restart. Be aware that restarts are likely to cause a hit against the backend, so don''t increase thoughtlessly. '); +INSERT INTO parameter_info VALUES('obj_workspace', 'bytes', 'Default is 8192. Bytes of HTTP protocol workspace allocated for objects. This space must be big enough for the entire HTTP protocol header and any edits done to it in the VCL code while it is cached. Minimum is 1024 bytes. NB: This parameter may take quite some time to take (full) effect. '); +INSERT INTO parameter_info VALUES('overflow_max', '%', 'Default is 100. Percentage permitted overflow queue length. This sets the ratio of queued requests to worker threads, above which sessions will be dropped instead of queued. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('ping_interval', 'seconds', 'Default is 3. Interval between pings from parent to child. Zero will disable pinging entirely, which makes it possible to attach a debugger to the child. NB: This parameter will not take any effect until the child process has been restarted. '); +INSERT INTO parameter_info VALUES('pipe_timeout', 'seconds', 'Default is 60. Idle timeout for PIPE sessions. If nothing have been received in either direction for this many seconds, the session is closed. '); +INSERT INTO parameter_info VALUES('prefer_ipv6', 'bool', 'Default is off. Prefer IPv6 address when connecting to backends which have both IPv4 and IPv6 addresses. '); +INSERT INTO parameter_info VALUES('purge_dups', 'bool', 'Default is off. Detect and eliminate duplicate purges. '); +INSERT INTO parameter_info VALUES('purge_hash', 'bool', 'Default is off. Enable purge.hash command. NB: this increases storage requirement per object by the length of the hash string. NB: This parameter will not take any effect until the child process has been restarted. '); +INSERT INTO parameter_info VALUES('rush_exponent', 'requests per request', 'Default is 3. How many parked request we start for each completed request on the object. NB: Even with the implict delay of delivery, this parameter controls an exponential increase in number of worker threads. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('send_timeout', 'seconds', 'Default is 600. Send timeout for client connections. If no data has been sent to the client in this many seconds, the session is closed. See setsockopt(2) under SO_SNDTIMEO for more information. NB: This parameter may take quite some time to take (full) effect. '); +INSERT INTO parameter_info VALUES('sess_timeout', 'seconds', 'Default is 5. Idle timeout for persistent sessions. If a HTTP request has not been received in this many seconds, the session is closed. '); +INSERT INTO parameter_info VALUES('sess_workspace', 'bytes', 'Default is 16384. Bytes of HTTP protocol workspace allocated for sessions. This space must be big enough for the entire HTTP protocol header and any edits done to it in the VCL code. Minimum is 1024 bytes. NB: This parameter may take quite some time to take (full) effect. '); +INSERT INTO parameter_info VALUES('session_linger', 'ms', 'Default is 0. How long time the workerthread lingers on the session to see if a new request appears right away. If sessions are reused, as much as half of all reuses happen within the first 100 msec of the previous request completing. Setting this too high results in worker threads not doing anything for their keep, setting it too low just means that more sessions take a detour around the waiter. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('shm_reclen', 'bytes', 'Default is 255. Maximum number of bytes in SHM log record. Maximum is 65535 bytes. '); +INSERT INTO parameter_info VALUES('shm_workspace', 'bytes', 'Default is 8192. Bytes of shmlog workspace allocated for worker threads. If too big, it wastes some ram, if too small it causes needless flushes of the SHM workspace. These flushes show up in stats as "SHM flushes due to overflow". Minimum is 4096 bytes. NB: This parameter may take quite some time to take (full) effect. '); +INSERT INTO parameter_info VALUES('srcaddr_hash', 'buckets', 'Default is 1049. Number of source address hash buckets. Powers of two are bad, prime numbers are good. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. NB: This parameter will not take any effect until the child process has been restarted. '); +INSERT INTO parameter_info VALUES('srcaddr_ttl', 'seconds', 'Default is 30. Lifetime of srcaddr entries. Zero will disable srcaddr accounting entirely. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('thread_pool_add_delay', 'milliseconds', 'Default is 20. Wait at least this long between creating threads. Setting this too long results in insuffient worker threads. Setting this too short increases the risk of worker thread pile-up. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('thread_pool_add_threshold', 'requests', 'Default is 2. Overflow threshold for worker thread creation. Setting this too low, will result in excess worker threads, which is generally a bad idea. Setting it too high results in insuffient worker threads. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('thread_pool_fail_delay', 'milliseconds', 'Default is 200. Wait at least this long after a failed thread creation before trying to create another thread. Failure to create a worker thread is often a sign that the end is near, because the process is running out of RAM resources for thread stacks. This delay tries to not rush it on needlessly. If thread creation failures are a problem, check that thread_pool_max is not too high. It may also help to increase thread_pool_timeout and thread_pool_min, to reduce the rate at which treads are destroyed and later recreated. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('thread_pool_max', 'threads', 'Default is 500. The maximum number of worker threads in all pools combined. Do not set this higher than you have to, since excess worker threads soak up RAM and CPU and generally just get in the way of getting work done. NB: This parameter may take quite some time to take (full) effect. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('thread_pool_min', 'threads', 'Default is 5. The minimum number of threads in each worker pool. Increasing this may help ramp up faster from low load situations where threads have expired. Minimum is 2 threads. NB: This parameter may take quite some time to take (full) effect. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('thread_pool_purge_delay', 'milliseconds', 'Default is 1000. Wait this long between purging threads. This controls the decay of thread pools when idle(-ish). Minimum is 100 milliseconds. NB: This parameter may take quite some time to take (full) effect. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('thread_pool_timeout', 'seconds', 'Default is 300. Thread idle threshold. Threads in excess of thread_pool_min, which have been idle for at least this long are candidates for purging. Minimum is 1 second. NB: This parameter may take quite some time to take (full) effect. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('thread_pools', 'pools', 'Default is 2. Number of worker thread pools. Increasing number of worker pools decreases lock contention. Too many pools waste CPU and RAM resources, and more than one pool for each CPU is probably detrimal to performance. Can be increased on the fly, but decreases require a restart to take effect. NB: This parameter may take quite some time to take (full) effect. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); +INSERT INTO parameter_info VALUES('child_user', '', 'Default is . The unprivileged user to run as. Setting this will also set "group" to the specified user''s primary group. NB: This parameter will not take any effect until the child process has been restarted. '); +INSERT INTO parameter_info VALUES('vcl_trace', 'bool', 'Default is off. Trace VCL execution in the shmlog. Enabling this will allow you to see the path each request has taken through the VCL program. This generates a lot of logrecords so it is off by default. '); +INSERT INTO parameter_info VALUES('waiter', '', 'Default is default. Select the waiter kernel interface. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. NB: This parameter will not take any effect until the child process has been restarted. '); + From petter at projects.linpro.no Thu Feb 19 14:10:35 2009 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Thu, 19 Feb 2009 15:10:35 +0100 (CET) Subject: r3787 - in trunk/varnish-tools/webgui: Varnish css templates Message-ID: <20090219141035.71F3A2846B@projects.linpro.no> Author: petter Date: 2009-02-19 15:10:35 +0100 (Thu, 19 Feb 2009) New Revision: 3787 Modified: trunk/varnish-tools/webgui/Varnish/DB.pm trunk/varnish-tools/webgui/Varnish/RequestHandler.pm trunk/varnish-tools/webgui/css/web.css trunk/varnish-tools/webgui/templates/node_management.tmpl Log: Some minor cosmetics and bugs discovered during documentation writing. Modified: trunk/varnish-tools/webgui/Varnish/DB.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/DB.pm 2009-02-18 15:36:25 UTC (rev 3786) +++ trunk/varnish-tools/webgui/Varnish/DB.pm 2009-02-19 14:10:35 UTC (rev 3787) @@ -131,7 +131,7 @@ my $sth = $dbh->prepare($sql); $sth->execute($node->get_id()); - $sql = "DELETE FROM parameters WHERE node_id = ?"; + $sql = "DELETE FROM stat WHERE node_id = ?"; $sth = $dbh->prepare($sql); $sth->execute($node->get_id()); Modified: trunk/varnish-tools/webgui/Varnish/RequestHandler.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/RequestHandler.pm 2009-02-18 15:36:25 UTC (rev 3786) +++ trunk/varnish-tools/webgui/Varnish/RequestHandler.pm 2009-02-19 14:10:35 UTC (rev 3787) @@ -837,11 +837,13 @@ Varnish::NodeManager->add_node($node, $inherit_settings); $status .= "Node " . $node->get_name() . " added successfully."; + my $group = Varnish::NodeManager->get_group($param{'group_id'}); + my $group_name = ($group ? $group->get_name() : ""); log_info("[" . $node->get_name() . "] [Added node]" . " [name=" . $node->get_name() . "]" . " [address=" . $node->get_address() . "]" . " [port=" . $node->get_port() . "]" - . " [group=" . $param{'group_name'} . "]" + . " [group=" . $group_name . "]" . " [management_port=" . $node->get_management_port() . "]"); } else { @@ -864,11 +866,15 @@ Varnish::NodeManager->update_node($node); + $status .= "Node " . $node->get_name() . " updated successfully."; + + my $group = Varnish::NodeManager->get_group($param{'node_group_id'}); + my $group_name = ($group ? $group->get_name() : ""); log_info("[" . $node->get_name() . "] [Updated node]" . " [name=" . $node->get_name() . "]" . " [address=" . $node->get_address() . "]" . " [port=" . $node->get_port() . "]" - . " [group=" . $param{'group_name'} . "]" + . " [group=" . $group_name . "]" . " [management_port=" . $node->get_management_port() . "]"); } } Modified: trunk/varnish-tools/webgui/css/web.css =================================================================== --- trunk/varnish-tools/webgui/css/web.css 2009-02-18 15:36:25 UTC (rev 3786) +++ trunk/varnish-tools/webgui/css/web.css 2009-02-19 14:10:35 UTC (rev 3787) @@ -189,10 +189,6 @@ padding: 5px; } -td.addNodeBorder { - margin: 15px; -} - img.goToNodeManagement { border-width: 0 0 1px 0; } Modified: trunk/varnish-tools/webgui/templates/node_management.tmpl =================================================================== --- trunk/varnish-tools/webgui/templates/node_management.tmpl 2009-02-18 15:36:25 UTC (rev 3786) +++ trunk/varnish-tools/webgui/templates/node_management.tmpl 2009-02-19 14:10:35 UTC (rev 3787) @@ -42,7 +42,7 @@
Address Port -Management port +Management
port @@ -155,7 +155,7 @@ -checked>Group inherit settings + checked>Group inherit
settings
From phk at projects.linpro.no Thu Feb 19 16:00:22 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 19 Feb 2009 17:00:22 +0100 (CET) Subject: r3788 - trunk/varnish-cache/bin/varnishd Message-ID: <20090219160022.A940838086@projects.linpro.no> Author: phk Date: 2009-02-19 17:00:22 +0100 (Thu, 19 Feb 2009) New Revision: 3788 Added: trunk/varnish-cache/bin/varnishd/stevedore_utils.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/stevedore.h trunk/varnish-cache/bin/varnishd/storage_file.c Log: Split a couple of generally useful routines out of storage_file Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2009-02-19 14:10:35 UTC (rev 3787) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2009-02-19 16:00:22 UTC (rev 3788) @@ -55,6 +55,7 @@ storage_malloc.c \ storage_synth.c \ storage_umem.c \ + stevedore_utils.c \ varnishd.c noinst_HEADERS = \ Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2009-02-19 14:10:35 UTC (rev 3787) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2009-02-19 16:00:22 UTC (rev 3788) @@ -63,5 +63,8 @@ void STV_add(const struct stevedore *stv, int ac, char * const *av); void STV_open(void); +int STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx); +uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx); + /* Synthetic Storage */ void SMS_Init(void); Copied: trunk/varnish-cache/bin/varnishd/stevedore_utils.c (from rev 3787, trunk/varnish-cache/bin/varnishd/storage_file.c) =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore_utils.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/stevedore_utils.c 2009-02-19 16:00:22 UTC (rev 3788) @@ -0,0 +1,237 @@ +/*- + * 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$ + * + * Utility functions for stevedores and storage modules + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_SYS_MOUNT_H +#include +#endif + +#ifdef HAVE_SYS_STATVFS_H +#include +#endif + +#ifdef HAVE_SYS_VFS_H +#include +#endif + +#include "mgt.h" +#include "stevedore.h" + +#ifndef O_LARGEFILE +#define O_LARGEFILE 0 +#endif + +/*-------------------------------------------------------------------- + * Get a storage file. + * + * The fn argument can be an existing file, an existing directory or + * a nonexistent filename in an existing directory. + * + * If a directory is specified, the file will be anonymous (unlinked) + * + * Return: + * 0 if the file was preexisting. + * 1 if the file was created. + * 2 if the file is anonymous. + * + * Uses ARGV_ERR to exit in case of trouble. + */ + +int +STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx) +{ + int fd; + struct stat st; + char *q; + int retval = 1; + + AN(fn); + AN(fnp); + AN(fdp); + *fnp = NULL; + *fdp = -1; + + /* try to create a new file of this name */ + fd = open(fn, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, 0600); + if (fd >= 0) { + *fdp = fd; + *fnp = fn; + return (retval); + } + + if (stat(fn, &st)) + ARGV_ERR( + "(%s) \"%s\" does not exist and could not be created\n", + ctx, fn); + + if (S_ISDIR(st.st_mode)) { + asprintf(&q, "%s/varnish.XXXXXX", fn); + XXXAN(q); + fd = mkstemp(q); + if (fd < 0) + ARGV_ERR("(%s) \"%s\" mkstemp(%s) failed (%s)\n", + ctx, fn, q, strerror(errno)); + *fnp = q; + retval = 2; + } else if (S_ISREG(st.st_mode)) { + fd = open(fn, O_RDWR | O_LARGEFILE); + if (fd < 0) + ARGV_ERR("(%s) \"%s\" could not open (%s)\n", + ctx, fn, strerror(errno)); + *fnp = fn; + retval = 0; + } else + ARGV_ERR( + "(%s) \"%s\" is neither file nor directory\n", ctx, fn); + + AZ(fstat(fd, &st)); + if (!S_ISREG(st.st_mode)) + ARGV_ERR("(%s) \"%s\" was not a file after opening\n", + ctx, fn); + + *fdp = fd; + return (retval); +} + +/*-------------------------------------------------------------------- + * Figure out how much space is in a filesystem + */ + +static uintmax_t +stv_fsspace(int fd, unsigned *bs) +{ +#if defined(HAVE_SYS_STATVFS_H) + struct statvfs fsst; + + AZ(fstatvfs(fd, &fsst)); +#elif defined(HAVE_SYS_MOUNT_H) || defined(HAVE_SYS_VFS_H) + struct statfs fsst; + + AZ(fstatfs(sc->fd, &fsst)); +#else +#error no struct statfs / struct statvfs +#endif + + /* We use units of the larger of filesystem blocksize and pagesize */ + if (*bs < fsst.f_bsize) + *bs = fsst.f_bsize; + xxxassert(*bs % fsst.f_bsize == 0); + return (fsst.f_bsize * fsst.f_bavail); +} + + +/*-------------------------------------------------------------------- + * Decide file size. + * + * If the sizespecification is empty and the file exists with non-zero + * size, use that, otherwise, interpret the specification. + * + * Handle off_t sizes and pointer width limitations. + */ + +uintmax_t +STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx) +{ + uintmax_t l, fssize; + unsigned bs; + const char *q; + int i; + off_t o; + struct stat st; + + AZ(fstat(fd, &st)); + xxxassert(S_ISREG(st.st_mode)); + + bs = *granularity; + fssize = stv_fsspace(fd, &bs); + xxxassert(bs % *granularity == 0); + + if ((size == NULL || *size == '\0') && st.st_size != 0) { + /* + * We have no size specification, but an existing file, + * use it's existing size. + */ + l = st.st_size; + } else { + AN(size); + q = str2bytes(size, &l, fssize); + + if (q != NULL) + ARGV_ERR("(%s) size \"%s\": %s\n", size, ctx, q); + } + + /* + * This trickery wouldn't be necessary if X/Open would + * just add OFF_MAX to ... + */ + i = 0; + while(1) { + o = l; + if (o == l && o > 0) + break; + l >>= 1; + i++; + } + if (i) + fprintf(stderr, "WARNING: (%s) file size reduced" + " to %ju due to system \"off_t\" limitations\n", ctx, l); + else if (l - st.st_size > fssize) { + l = fssize * 80 / 100; + fprintf(stderr, "WARNING: (%s) file size reduced" + " to %ju (80%% of available disk space)\n", ctx, l); + } + + if (sizeof(void *) == 4 && l > INT32_MAX) { /*lint !e506 !e774 */ + fprintf(stderr, + "NB: Storage size limited to 2GB on 32 bit architecture,\n" + "NB: otherwise we could run out of address space.\n" + ); + l = INT32_MAX; + } + + /* round down to multiple of filesystem blocksize or pagesize */ + l -= (l % bs); + + *granularity = bs; + return(l); +} Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2009-02-19 14:10:35 UTC (rev 3787) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2009-02-19 16:00:22 UTC (rev 3788) @@ -38,18 +38,6 @@ #include #include -#ifdef HAVE_SYS_MOUNT_H -#include -#endif - -#ifdef HAVE_SYS_STATVFS_H -#include -#endif - -#ifdef HAVE_SYS_VFS_H -#include -#endif - #include #include #include @@ -120,114 +108,14 @@ /*--------------------------------------------------------------------*/ -static uintmax_t -smf_fsspace(int fd, unsigned *bs) -{ -#if defined(HAVE_SYS_STATVFS_H) - struct statvfs fsst; - - AZ(fstatvfs(fd, &fsst)); -#elif defined(HAVE_SYS_MOUNT_H) || defined(HAVE_SYS_VFS_H) - struct statfs fsst; - - AZ(fstatfs(sc->fd, &fsst)); -#else -#error no struct statfs / struct statvfs -#endif - - /* We use units of the larger of filesystem blocksize and pagesize */ - if (*bs < fsst.f_bsize) - *bs = fsst.f_bsize; - xxxassert(*bs % fsst.f_bsize == 0); - return (fsst.f_bsize * fsst.f_bavail); -} - - -/*--------------------------------------------------------------------*/ - static void -smf_calcsize(struct smf_sc *sc, const char *size, int newfile) +smf_initfile(struct smf_sc *sc, const char *size) { - uintmax_t l, fssize; - unsigned bs; - const char *q; - int i; - off_t o; - struct stat st; + sc->filesize = STV_FileSize(sc->fd, size, &sc->pagesize, "-sfile"); - AN(sc); - AZ(fstat(sc->fd, &st)); - xxxassert(S_ISREG(st.st_mode)); - - bs = sc->pagesize; - fssize = smf_fsspace(sc->fd, &bs); - xxxassert(bs % sc->pagesize == 0); - - if ((size == NULL || *size == '\0') && !newfile) { - /* - * We have no size specification, but an existing file, - * use it's existing size. - */ - l = st.st_size; - } else { - AN(size); - q = str2bytes(size, &l, fssize); - - if (q != NULL) - ARGV_ERR("(-sfile) size \"%s\": %s\n", size, q); - } - - /* - * This trickery wouldn't be necessary if X/Open would - * just add OFF_MAX to ... - */ - i = 0; - while(1) { - o = l; - if (o == l && o > 0) - break; - l >>= 1; - i++; - } - if (i) - fprintf(stderr, "WARNING: storage file size reduced" - " to %ju due to system limitations\n", l); - - if (l < st.st_size) { - 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" - " to %ju (80%% of available disk space)\n", l); - } - - /* round down to multiple of filesystem blocksize or pagesize */ - l -= (l % bs); - - if (l < MINPAGES * (uintmax_t)sc->pagesize) - ARGV_ERR("size too small, at least %ju needed\n", - (uintmax_t)MINPAGES * sc->pagesize); - - if (sizeof(void *) == 4 && l > INT32_MAX) { /*lint !e506 !e774 */ - fprintf(stderr, - "NB: Storage size limited to 2GB on 32 bit architecture,\n" - "NB: otherwise we could run out of address space.\n" - ); - l = INT32_MAX; - l -= (l % bs); - } - printf("storage_file: filename: %s size %ju MB.\n", - sc->filename, l / (1024 * 1024)); + sc->filename, sc->filesize / (1024 * 1024)); - sc->filesize = l; -} - -static void -smf_initfile(struct smf_sc *sc, const char *size, int newfile) -{ - smf_calcsize(sc, size, newfile); - AZ(ftruncate(sc->fd, (off_t)sc->filesize)); /* XXX: force block allocation here or in open ? */ @@ -240,8 +128,6 @@ smf_init(struct stevedore *parent, int ac, char * const *av) { const char *size, *fn, *r; - char *q, *p; - struct stat st; struct smf_sc *sc; unsigned u; uintmax_t page_size; @@ -278,56 +164,10 @@ 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"); - smf_initfile(sc, size, 1); - return; - } + (void)STV_GetFile(fn, &sc->fd, &sc->filename, "-sfile"); - /* it must exist then */ - 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))) - ARGV_ERR("(-sfile) \"%s\" is neither file nor directory\n", fn); - - if (S_ISREG(st.st_mode)) { - 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)) - 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", fn); - XXXAN(q); - sc->fd = mkstemp(q); - if (sc->fd < 0) - ARGV_ERR("(-sfile) \"%s\" " - "mkstemp(%s) failed (%s)\n", fn, q, strerror(errno)); - AZ(unlink(q)); - asprintf(&p, "%s (unlinked)", q); - XXXAN(p); - sc->filename = p; - free(q); - smf_initfile(sc, size, 1); mgt_child_inherit(sc->fd, "storage_file"); + smf_initfile(sc, size); } /*-------------------------------------------------------------------- From petter at projects.linpro.no Fri Feb 20 06:53:55 2009 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Fri, 20 Feb 2009 07:53:55 +0100 (CET) Subject: r3789 - trunk/varnish-tools/webgui/Varnish Message-ID: <20090220065355.627A21F74EC@projects.linpro.no> Author: petter Date: 2009-02-20 07:53:55 +0100 (Fri, 20 Feb 2009) New Revision: 3789 Modified: trunk/varnish-tools/webgui/Varnish/Management.pm Log: Forgot to escape \ when sending VCL to management port Modified: trunk/varnish-tools/webgui/Varnish/Management.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/Management.pm 2009-02-19 16:00:22 UTC (rev 3788) +++ trunk/varnish-tools/webgui/Varnish/Management.pm 2009-02-20 06:53:55 UTC (rev 3789) @@ -155,6 +155,7 @@ sub set_vcl { my ($self, $vcl_name, $vcl) = @_; + $vcl =~ s/\\/\\\\/g; $vcl =~ s/"/\\"/g; $vcl =~ s/\r//g; $vcl =~ s/\n/\\n/g; From phk at projects.linpro.no Fri Feb 20 09:56:49 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 10:56:49 +0100 (CET) Subject: r3790 - trunk/varnish-cache/bin/varnishd Message-ID: <20090220095649.E0B8528371@projects.linpro.no> Author: phk Date: 2009-02-20 10:56:49 +0100 (Fri, 20 Feb 2009) New Revision: 3790 Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c trunk/varnish-cache/bin/varnishd/hash_slinger.h Log: Remove unused hoh_digest Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_classic.c 2009-02-20 06:53:55 UTC (rev 3789) +++ trunk/varnish-cache/bin/varnishd/hash_classic.c 2009-02-20 09:56:49 UTC (rev 3790) @@ -147,7 +147,6 @@ else VTAILQ_INSERT_TAIL(&hp->head, noh, hoh_list); - noh->hoh_digest = digest; noh->hoh_head = hp; HSH_Copy(sp, noh); Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 06:53:55 UTC (rev 3789) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 09:56:49 UTC (rev 3790) @@ -92,12 +92,10 @@ struct { VTAILQ_ENTRY(objhead) u_n_hoh_list; void *u_n_hoh_head; - unsigned u_n_hoh_digest; } n; } u; #define hoh_list u.n.u_n_hoh_list #define hoh_head u.n.u_n_hoh_head -#define hoh_digest u.n.u_n_hoh_digest }; extern unsigned save_hash; From phk at projects.linpro.no Fri Feb 20 11:05:14 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 12:05:14 +0100 (CET) Subject: r3791 - trunk/varnish-cache/bin/varnishd Message-ID: <20090220110514.CC4A91F74E8@projects.linpro.no> Author: phk Date: 2009-02-20 12:05:14 +0100 (Fri, 20 Feb 2009) New Revision: 3791 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/hash_critbit.c trunk/varnish-cache/bin/varnishd/hash_slinger.h Log: Be more defensive around objhead retirement. Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-02-20 09:56:49 UTC (rev 3790) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-02-20 11:05:14 UTC (rev 3791) @@ -469,6 +469,7 @@ return; CHECK_OBJ_NOTNULL(o->ban, BAN_MAGIC); Lck_Lock(&ban_mtx); + assert(o->ban->refcount > 0); o->ban->refcount--; o->ban = NULL; @@ -477,7 +478,6 @@ Lck_Unlock(&ban_mtx); if (b != NULL) BAN_Free(b); - } Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-20 09:56:49 UTC (rev 3790) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-20 11:05:14 UTC (rev 3791) @@ -272,6 +272,7 @@ "%u %d", o->xid, (int)(o->ttl - t)); Lck_Lock(&exp_mtx); assert(oc->timer_idx == BINHEAP_NOIDX); + assert(oc->flags & OC_F_ONLRU); VTAILQ_REMOVE(&lru, o->objcore, lru_list); oc->flags &= ~OC_F_ONLRU; VSL_stats->n_expired++; Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 09:56:49 UTC (rev 3790) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 11:05:14 UTC (rev 3791) @@ -141,6 +141,18 @@ } void +HSH_DeleteObjHead(struct objhead *oh) +{ + + AZ(oh->refcnt); + assert(VTAILQ_EMPTY(&oh->objcs)); + Lck_Delete(&oh->mtx); + VSL_stats->n_objecthead--; + free(oh->hash); + FREE_OBJ(oh); +} + +void HSH_Freestore(struct object *o) { struct storage *st, *stn; @@ -311,7 +323,7 @@ if (o->hits < INT_MAX) o->hits++; Lck_Unlock(&oh->mtx); - (void)hash->deref(oh); + assert(hash->deref(oh)); return (o); } @@ -476,6 +488,7 @@ return; BAN_DestroyObj(o); + AZ(o->ban); DSL(0x40, SLT_Debug, 0, "Object %u workspace min free %u", o->xid, WS_Free(o->ws_o)); @@ -494,13 +507,10 @@ AN(oc); FREE_OBJ(oc); /* Drop our ref on the objhead */ + assert(oh->refcnt > 0); if (hash->deref(oh)) return; - assert(VTAILQ_EMPTY(&oh->objcs)); - Lck_Delete(&oh->mtx); - VSL_stats->n_objecthead--; - free(oh->hash); - FREE_OBJ(oh); + HSH_DeleteObjHead(oh); } void Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-20 09:56:49 UTC (rev 3790) +++ trunk/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-20 11:05:14 UTC (rev 3791) @@ -323,7 +323,7 @@ /**********************************************************************/ -#define COOL_DURATION 15 /* seconds */ +#define COOL_DURATION 60 /* seconds */ static void * hcb_cleaner(void *priv) @@ -337,10 +337,6 @@ (void)sleep(1); Lck_Lock(&hcb_mtx); VTAILQ_FOREACH_SAFE(oh, &laylow, coollist, oh2) { - if (oh->hash != NULL) { - free(oh->hash); - oh->hash = NULL; - } y = (void *)&oh->u; if (y->leaf[0] || y->leaf[1]) continue; @@ -349,8 +345,8 @@ #ifdef PHK fprintf(stderr, "OH %p is cold enough\n", oh); #endif - free(oh); - VSL_stats->n_objecthead--; + oh->refcnt = 0; + HSH_DeleteObjHead(oh); } } Lck_Unlock(&hcb_mtx); @@ -381,6 +377,7 @@ r = 1; CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); Lck_Lock(&oh->mtx); + assert(oh->refcnt > 0); if (--oh->refcnt == 0) { Lck_Lock(&hcb_mtx); hcb_delete(&hcb_root, oh); Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 09:56:49 UTC (rev 3790) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 11:05:14 UTC (rev 3791) @@ -50,6 +50,7 @@ /* cache_hash.c */ void HSH_Prealloc(struct sess *sp); +void HSH_DeleteObjHead(struct objhead *oh); void HSH_Freestore(struct object *o); void HSH_Copy(const struct sess *sp, struct objhead *o); struct object *HSH_Lookup(struct sess *sp); From petter at projects.linpro.no Fri Feb 20 11:45:31 2009 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Fri, 20 Feb 2009 12:45:31 +0100 (CET) Subject: r3792 - in trunk/varnish-tools/webgui: Varnish templates Message-ID: <20090220114531.124A33833A@projects.linpro.no> Author: petter Date: 2009-02-20 12:45:30 +0100 (Fri, 20 Feb 2009) New Revision: 3792 Modified: trunk/varnish-tools/webgui/Varnish/NodeManager.pm trunk/varnish-tools/webgui/Varnish/RequestHandler.pm trunk/varnish-tools/webgui/templates/node_management.tmpl Log: Added possibility to add nodes to a group without have the settings of the group or node altered, which can be usefull to group node logically if the web GUI is used as a monitoring tool. Also fixed a logical bug in the settings inheritance code. Modified: trunk/varnish-tools/webgui/Varnish/NodeManager.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/NodeManager.pm 2009-02-20 11:05:14 UTC (rev 3791) +++ trunk/varnish-tools/webgui/Varnish/NodeManager.pm 2009-02-20 11:45:30 UTC (rev 3792) @@ -21,12 +21,14 @@ $vcl_info->{'vcl'} = $master->get_vcl($name); } - my $previous_active_vcl; + my $slave_active_vcl = ""; + my $discard_slave_active_vcl = 0; my $vcl_infos_ref = $slave->get_vcl_infos(); for my $vcl_info (@$vcl_infos_ref) { my $name = $vcl_info->{'name'}; if ($vcl_info->{'active'}) { - $previous_active_vcl = $name; + $slave_active_vcl = $name; + $discard_slave_active_vcl = 1; } else { $slave->discard_vcl($name); @@ -39,16 +41,20 @@ $slave->save_vcl($name, $vcl); if ($vcl_info->{'active'}) { $slave->make_vcl_active($name); - if ($previous_active_vcl) { - $slave->discard_vcl($previous_active_vcl); - } } + if ($slave_active_vcl eq $name) { + $discard_slave_active_vcl = 0; + } } + if ($discard_slave_active_vcl) { + $slave->discard_vcl($slave_active_vcl); + } } - + sub add_node { - my ($self, $node, $use_as_group_defaults) = @_; + my ($self, $node, $inheritance) = @_; + $inheritance ||= 0; my $management = $node->get_management(); if (!$management->ping()) { return set_error($self, "Could not connect to management port: " @@ -57,12 +63,12 @@ Varnish::DB->add_node($node); my $group_id = $node->get_group_id(); - if ($group_id > 0) { + if ($group_id > 0 && $inheritance) { my $group = get_group($self, $group_id); - if ($use_as_group_defaults) { + if ($inheritance == 1) { _clone_unit($node, $group); } - else { + elsif ($inheritance == 2) { _clone_unit($group, $node); } } Modified: trunk/varnish-tools/webgui/Varnish/RequestHandler.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/RequestHandler.pm 2009-02-20 11:05:14 UTC (rev 3791) +++ trunk/varnish-tools/webgui/Varnish/RequestHandler.pm 2009-02-20 11:45:30 UTC (rev 3792) @@ -743,7 +743,7 @@ $param{'address'} = $$parameter_ref{'address'} || ""; $param{'port'} ||= ""; $param{'management_port'} ||= ""; - $param{'inherit_settings'} ||= ""; + $param{'inheritance'} ||= 0; $param{'edit_node'} ||= -1; my $template = "node_management.tmpl"; @@ -760,8 +760,8 @@ $tmpl_var{'show_group'} = 0; $tmpl_var{'show_add_node'} = 1; $tmpl_var{'show_node_in_backend_health'} = 1; - $tmpl_var{'inherit_settings'} = 0; - $tmpl_var{'show_inherit_settings'} = 1; + $tmpl_var{'show_inheritance_settings'} = 1; + $tmpl_var{'inheritance_settings'} = []; my $error = ""; my $status = ""; @@ -833,18 +833,21 @@ group_id => $param{'group_id'}, management_port => $param{'management_port'} }); - my $inherit_settings = $param{'inherit_settings'} ne ""; - Varnish::NodeManager->add_node($node, $inherit_settings); + Varnish::NodeManager->add_node($node, $param{'inheritance'}); $status .= "Node " . $node->get_name() . " added successfully."; my $group = Varnish::NodeManager->get_group($param{'group_id'}); my $group_name = ($group ? $group->get_name() : ""); + my $inheritance = ($param{'inheritance'} == 0 ? "None" : + $param{'inheritance'} == 1 ? "Group inherited node" : + "Node inherited group"); log_info("[" . $node->get_name() . "] [Added node]" . " [name=" . $node->get_name() . "]" . " [address=" . $node->get_address() . "]" . " [port=" . $node->get_port() . "]" . " [group=" . $group_name . "]" - . " [management_port=" . $node->get_management_port() . "]"); + . " [management_port=" . $node->get_management_port() . "]" + . " [settings_inheritance=$inheritance]"); } else { $error .= "Not enough information to add node:\n"; @@ -955,9 +958,6 @@ if ($tmpl_var{'group_id'} != -1) { $group = Varnish::NodeManager->get_group($tmpl_var{'group_id'}); $nodes_ref = Varnish::NodeManager->get_nodes($group); - if ($tmpl_var{'group_id'} == 0) { - $tmpl_var{'show_inherit_settings'} = 0; - } } else { $nodes_ref = Varnish::NodeManager->get_nodes(); @@ -989,14 +989,35 @@ } push @{$tmpl_var{'node_infos'}}, $node_info_ref; } - if (@$nodes_ref == 0) { - $tmpl_var{'inherit_settings'} = 1; - } } else { $tmpl_var{'add_group'} = 1; } + if ($tmpl_var{'group_id'} > 0) { + my @inheritance_settings; + push @inheritance_settings, { + value => 2, + name => "Node inherits group", + selected => @{$tmpl_var{'node_infos'}} > 0, + }; + push @inheritance_settings, { + value => 1, + name => "Group inherits node", + selected => @{$tmpl_var{'node_infos'}} == 0, + }; + push @inheritance_settings, { + value => 0, + name => "No inheritance", + selected => 0, + }; + $tmpl_var{'inheritance_settings'} = \@inheritance_settings; + } + else { + $tmpl_var{'show_inheritance_settings'} = 0; + } + + my $selected_group = Varnish::NodeManager->get_group($tmpl_var{'group_id'}); if ($selected_group) { $tmpl_var{'group_name'} = $selected_group->get_name(); Modified: trunk/varnish-tools/webgui/templates/node_management.tmpl =================================================================== --- trunk/varnish-tools/webgui/templates/node_management.tmpl 2009-02-20 11:05:14 UTC (rev 3791) +++ trunk/varnish-tools/webgui/templates/node_management.tmpl 2009-02-20 11:45:30 UTC (rev 3792) @@ -43,6 +43,9 @@ Address Port Management
port + +Inheritance
settings +
@@ -88,6 +91,9 @@ + + + @@ -105,6 +111,9 @@ + + +
@@ -154,8 +163,14 @@ - - checked>Group inherit
settings + + + + From petter at projects.linpro.no Fri Feb 20 13:45:36 2009 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Fri, 20 Feb 2009 14:45:36 +0100 (CET) Subject: r3793 - trunk/varnish-tools/webgui/Varnish Message-ID: <20090220134536.C970038085@projects.linpro.no> Author: petter Date: 2009-02-20 14:45:35 +0100 (Fri, 20 Feb 2009) New Revision: 3793 Modified: trunk/varnish-tools/webgui/Varnish/Management.pm Log: Open the socket non-blocking so we can time out if the management console doesn't print a banner Modified: trunk/varnish-tools/webgui/Varnish/Management.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/Management.pm 2009-02-20 11:45:30 UTC (rev 3792) +++ trunk/varnish-tools/webgui/Varnish/Management.pm 2009-02-20 13:45:35 UTC (rev 3793) @@ -2,6 +2,8 @@ use strict; use IO::Socket::INET; +use IO::Select; +use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); use Exporter; use List::Util qw(first); use Varnish::Util qw(set_error get_error no_error); @@ -24,8 +26,11 @@ sub _read_cli_response { my ($socket) = @_; + + my $status_line = <$socket>; + return (undef, undef) if !defined($status_line); + my ($status_code, $response_size) = $status_line =~ m/^(\d+) (\d+)/; - my ($status_code, $response_size) = <$socket> =~ m/^(\d+) (\d+)/; my $response; my $remaining_bytes = $response_size; while ($remaining_bytes > 0 ) { @@ -46,11 +51,21 @@ my $socket = new IO::Socket::INET->new( PeerPort => $port_of{$self}, Proto => 'tcp', - PeerAddr => $hostname_of{$self} + PeerAddr => $hostname_of{$self}, + Blocking => 0, + ); return ("666", "Could not connect to node") if (!$socket); -# skip the banner - _read_cli_response($socket); + + my $select = IO::Select->new(); + $select->add($socket); + # wait 100ms, tops, before assuming we don't get a banner + if ($select->can_read(0.1)) { + _read_cli_response($socket); + } + my $flags = fcntl($socket, F_GETFL, 0); + $flags = fcntl($socket, F_SETFL, $flags & ~O_NONBLOCK); + $socket_of{$self} = $socket; } my $socket = $socket_of{$self}; From phk at projects.linpro.no Fri Feb 20 14:00:16 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 15:00:16 +0100 (CET) Subject: r3794 - in trunk/varnish-cache: bin/varnishd bin/varnishstat bin/varnishtest include Message-ID: <20090220140016.D60441F7497@projects.linpro.no> Author: phk Date: 2009-02-20 15:00:16 +0100 (Fri, 20 Feb 2009) New Revision: 3794 Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/include/stat_field.h trunk/varnish-cache/include/stats.h Log: Add a argument to the stat_field macro, to be used with locking evilness shortly. Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-20 13:45:35 UTC (rev 3793) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2009-02-20 14:00:16 UTC (rev 3794) @@ -84,7 +84,7 @@ (void)priv; AN(VSL_stats); -#define MAC_STAT(n, t, f, d) \ +#define MAC_STAT(n, t, l, f, d) \ cli_out(cli, "%12ju %s\n", (VSL_stats->n), d); #include "stat_field.h" #undef MAC_STAT Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2009-02-20 13:45:35 UTC (rev 3793) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2009-02-20 14:00:16 UTC (rev 3794) @@ -146,7 +146,7 @@ mvprintw(2, 0, "Hitrate avg: %8.4f %8.4f %8.4f", a1, a2, a3); line = 3; -#define MAC_STAT(n, t, f, d) \ +#define MAC_STAT(n, t, l, f, d) \ if ((fields == NULL || show_field( #n, fields )) && line < LINES) { \ ju = VSL_stats->n; \ if (ju == 0 && !seen.n) { \ @@ -228,7 +228,7 @@ ". ", "Child uptime"); } while (0); -#define MAC_STAT(n, t, f, d) \ +#define MAC_STAT(n, t, l, f, d) \ do { \ if (fields != NULL && ! show_field( #n, fields )) break; \ intmax_t ju = VSL_stats->n; \ @@ -271,7 +271,7 @@ fprintf(stderr, "---------- -----------\n"); fprintf(stderr, "uptime Child uptime\n"); -#define MAC_STAT(n, t, f, d) \ +#define MAC_STAT(n, t, l, f, d) \ do { \ fprintf(stderr, "%-20s %s\n", #n, d);\ } while (0); @@ -285,7 +285,7 @@ int i, valid_field, field_length; const char *all_fields[] = { "uptime", -#define MAC_STAT(n, t, f, d) \ +#define MAC_STAT(n, t, l, f, d) \ #n, #include "stat_field.h" #undef MAC_STAT Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-20 13:45:35 UTC (rev 3793) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2009-02-20 14:00:16 UTC (rev 3794) @@ -451,7 +451,7 @@ for (i = 0; i < 10; i++, usleep(100000)) { -#define MAC_STAT(n, t, f, d) \ +#define MAC_STAT(n, t, l, f, d) \ if (!strcmp(av[0], #n)) { \ val = v->stats->n; \ } else Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2009-02-20 13:45:35 UTC (rev 3793) +++ trunk/varnish-cache/include/stat_field.h 2009-02-20 14:00:16 UTC (rev 3794) @@ -29,107 +29,107 @@ * $Id$ */ -MAC_STAT(client_conn, uint64_t, 'a', "Client connections accepted") -MAC_STAT(client_req, uint64_t, 'a', "Client requests received") +MAC_STAT(client_conn, uint64_t, 0, 'a', "Client connections accepted") +MAC_STAT(client_req, uint64_t, 0, 'a', "Client requests received") -MAC_STAT(cache_hit, uint64_t, 'a', "Cache hits") -MAC_STAT(cache_hitpass, uint64_t, 'a', "Cache hits for pass") -MAC_STAT(cache_miss, uint64_t, 'a', "Cache misses") +MAC_STAT(cache_hit, uint64_t, 0, 'a', "Cache hits") +MAC_STAT(cache_hitpass, uint64_t, 0, 'a', "Cache hits for pass") +MAC_STAT(cache_miss, uint64_t, 0, 'a', "Cache misses") -MAC_STAT(backend_conn, uint64_t, 'a', "Backend connections success") -MAC_STAT(backend_unhealthy, uint64_t, 'a', +MAC_STAT(backend_conn, uint64_t, 0, 'a', "Backend connections success") +MAC_STAT(backend_unhealthy, uint64_t, 0, 'a', "Backend connections not attempted") -MAC_STAT(backend_busy, uint64_t, 'a', "Backend connections too many") -MAC_STAT(backend_fail, uint64_t, 'a', "Backend connections failures") -MAC_STAT(backend_reuse, uint64_t, 'a', "Backend connections reuses") -MAC_STAT(backend_recycle, uint64_t, 'a', "Backend connections recycles") -MAC_STAT(backend_unused, uint64_t, 'a', "Backend connections unused") +MAC_STAT(backend_busy, uint64_t, 0, 'a', "Backend connections too many") +MAC_STAT(backend_fail, uint64_t, 0, 'a', "Backend connections failures") +MAC_STAT(backend_reuse, uint64_t, 0, 'a', "Backend connections reuses") +MAC_STAT(backend_recycle, uint64_t, 0, 'a', "Backend connections recycles") +MAC_STAT(backend_unused, uint64_t, 0, 'a', "Backend connections unused") -MAC_STAT(n_srcaddr, uint64_t, 'i', "N struct srcaddr") -MAC_STAT(n_srcaddr_act, uint64_t, 'i', "N active struct srcaddr") -MAC_STAT(n_sess_mem, uint64_t, 'i', "N struct sess_mem") -MAC_STAT(n_sess, uint64_t, 'i', "N struct sess") -MAC_STAT(n_object, uint64_t, 'i', "N struct object") -MAC_STAT(n_objecthead, uint64_t, 'i', "N struct objecthead") -MAC_STAT(n_smf, uint64_t, 'i', "N struct smf") -MAC_STAT(n_smf_frag, uint64_t, 'i', "N small free smf") -MAC_STAT(n_smf_large, uint64_t, 'i', "N large free smf") -MAC_STAT(n_vbe_conn, uint64_t, 'i', "N struct vbe_conn") -MAC_STAT(n_bereq, uint64_t, 'i', "N struct bereq") -MAC_STAT(n_wrk, uint64_t, 'i', "N worker threads") -MAC_STAT(n_wrk_create, uint64_t, 'a', "N worker threads created") -MAC_STAT(n_wrk_failed, uint64_t, 'a', "N worker threads not created") -MAC_STAT(n_wrk_max, uint64_t, 'a', "N worker threads limited") -MAC_STAT(n_wrk_queue, uint64_t, 'a', "N queued work requests") -MAC_STAT(n_wrk_overflow, uint64_t, 'a', "N overflowed work requests") -MAC_STAT(n_wrk_drop, uint64_t, 'a', "N dropped work requests") -MAC_STAT(n_backend, uint64_t, 'i', "N backends") +MAC_STAT(n_srcaddr, uint64_t, 0, 'i', "N struct srcaddr") +MAC_STAT(n_srcaddr_act, uint64_t, 0, 'i', "N active struct srcaddr") +MAC_STAT(n_sess_mem, uint64_t, 0, 'i', "N struct sess_mem") +MAC_STAT(n_sess, uint64_t, 0, 'i', "N struct sess") +MAC_STAT(n_object, uint64_t, 0, 'i', "N struct object") +MAC_STAT(n_objecthead, uint64_t, 0, 'i', "N struct objecthead") +MAC_STAT(n_smf, uint64_t, 0, 'i', "N struct smf") +MAC_STAT(n_smf_frag, uint64_t, 0, 'i', "N small free smf") +MAC_STAT(n_smf_large, uint64_t, 0, 'i', "N large free smf") +MAC_STAT(n_vbe_conn, uint64_t, 0, 'i', "N struct vbe_conn") +MAC_STAT(n_bereq, uint64_t, 0, 'i', "N struct bereq") +MAC_STAT(n_wrk, uint64_t, 0, 'i', "N worker threads") +MAC_STAT(n_wrk_create, uint64_t, 0, 'a', "N worker threads created") +MAC_STAT(n_wrk_failed, uint64_t, 0, 'a', "N worker threads not created") +MAC_STAT(n_wrk_max, uint64_t, 0, 'a', "N worker threads limited") +MAC_STAT(n_wrk_queue, uint64_t, 0, 'a', "N queued work requests") +MAC_STAT(n_wrk_overflow, uint64_t, 0, 'a', "N overflowed work requests") +MAC_STAT(n_wrk_drop, uint64_t, 0, 'a', "N dropped work requests") +MAC_STAT(n_backend, uint64_t, 0, 'i', "N backends") -MAC_STAT(n_expired, uint64_t, 'i', "N expired objects") -MAC_STAT(n_lru_nuked, uint64_t, 'i', "N LRU nuked objects") -MAC_STAT(n_lru_saved, uint64_t, 'i', "N LRU saved objects") -MAC_STAT(n_lru_moved, uint64_t, 'i', "N LRU moved objects") -MAC_STAT(n_deathrow, uint64_t, 'i', "N objects on deathrow") +MAC_STAT(n_expired, uint64_t, 0, 'i', "N expired objects") +MAC_STAT(n_lru_nuked, uint64_t, 0, 'i', "N LRU nuked objects") +MAC_STAT(n_lru_saved, uint64_t, 0, 'i', "N LRU saved objects") +MAC_STAT(n_lru_moved, uint64_t, 0, 'i', "N LRU moved objects") +MAC_STAT(n_deathrow, uint64_t, 0, 'i', "N objects on deathrow") -MAC_STAT(losthdr, uint64_t, 'a', "HTTP header overflows") +MAC_STAT(losthdr, uint64_t, 0, 'a', "HTTP header overflows") -MAC_STAT(n_objsendfile, uint64_t, 'a', "Objects sent with sendfile") -MAC_STAT(n_objwrite, uint64_t, 'a', "Objects sent with write") -MAC_STAT(n_objoverflow, uint64_t, 'a', "Objects overflowing workspace") +MAC_STAT(n_objsendfile, uint64_t, 0, 'a', "Objects sent with sendfile") +MAC_STAT(n_objwrite, uint64_t, 0, 'a', "Objects sent with write") +MAC_STAT(n_objoverflow, uint64_t, 0, 'a', "Objects overflowing workspace") -MAC_STAT(s_sess, uint64_t, 'a', "Total Sessions") -MAC_STAT(s_req, uint64_t, 'a', "Total Requests") -MAC_STAT(s_pipe, uint64_t, 'a', "Total pipe") -MAC_STAT(s_pass, uint64_t, 'a', "Total pass") -MAC_STAT(s_fetch, uint64_t, 'a', "Total fetch") -MAC_STAT(s_hdrbytes, uint64_t, 'a', "Total header bytes") -MAC_STAT(s_bodybytes, uint64_t, 'a', "Total body bytes") +MAC_STAT(s_sess, uint64_t, 0, 'a', "Total Sessions") +MAC_STAT(s_req, uint64_t, 0, 'a', "Total Requests") +MAC_STAT(s_pipe, uint64_t, 0, 'a', "Total pipe") +MAC_STAT(s_pass, uint64_t, 0, 'a', "Total pass") +MAC_STAT(s_fetch, uint64_t, 0, 'a', "Total fetch") +MAC_STAT(s_hdrbytes, uint64_t, 0, 'a', "Total header bytes") +MAC_STAT(s_bodybytes, uint64_t, 0, 'a', "Total body bytes") -MAC_STAT(sess_closed, uint64_t, 'a', "Session Closed") -MAC_STAT(sess_pipeline, uint64_t, 'a', "Session Pipeline") -MAC_STAT(sess_readahead, uint64_t, 'a', "Session Read Ahead") -MAC_STAT(sess_linger, uint64_t, 'a', "Session Linger") -MAC_STAT(sess_herd, uint64_t, 'a', "Session herd") +MAC_STAT(sess_closed, uint64_t, 0, 'a', "Session Closed") +MAC_STAT(sess_pipeline, uint64_t, 0, 'a', "Session Pipeline") +MAC_STAT(sess_readahead, uint64_t, 0, 'a', "Session Read Ahead") +MAC_STAT(sess_linger, uint64_t, 0, 'a', "Session Linger") +MAC_STAT(sess_herd, uint64_t, 0, 'a', "Session herd") -MAC_STAT(shm_records, uint64_t, 'a', "SHM records") -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(shm_records, uint64_t, 0, 'a', "SHM records") +MAC_STAT(shm_writes, uint64_t, 0, 'a', "SHM writes") +MAC_STAT(shm_flushes, uint64_t, 0, 'a', "SHM flushes due to overflow") +MAC_STAT(shm_cont, uint64_t, 0, 'a', "SHM MTX contention") +MAC_STAT(shm_cycles, uint64_t, 0, 'a', "SHM cycles through buffer") -MAC_STAT(sm_nreq, uint64_t, 'a', "allocator requests") -MAC_STAT(sm_nobj, uint64_t, 'i', "outstanding allocations") -MAC_STAT(sm_balloc, uint64_t, 'i', "bytes allocated") -MAC_STAT(sm_bfree, uint64_t, 'i', "bytes free") +MAC_STAT(sm_nreq, uint64_t, 0, 'a', "allocator requests") +MAC_STAT(sm_nobj, uint64_t, 0, 'i', "outstanding allocations") +MAC_STAT(sm_balloc, uint64_t, 0, 'i', "bytes allocated") +MAC_STAT(sm_bfree, uint64_t, 0, 'i', "bytes free") -MAC_STAT(sma_nreq, uint64_t, 'a', "SMA allocator requests") -MAC_STAT(sma_nobj, uint64_t, 'i', "SMA outstanding allocations") -MAC_STAT(sma_nbytes, uint64_t, 'i', "SMA outstanding bytes") -MAC_STAT(sma_balloc, uint64_t, 'i', "SMA bytes allocated") -MAC_STAT(sma_bfree, uint64_t, 'i', "SMA bytes free") +MAC_STAT(sma_nreq, uint64_t, 0, 'a', "SMA allocator requests") +MAC_STAT(sma_nobj, uint64_t, 0, 'i', "SMA outstanding allocations") +MAC_STAT(sma_nbytes, uint64_t, 0, 'i', "SMA outstanding bytes") +MAC_STAT(sma_balloc, uint64_t, 0, 'i', "SMA bytes allocated") +MAC_STAT(sma_bfree, uint64_t, 0, '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 freed") +MAC_STAT(sms_nreq, uint64_t, 0, 'a', "SMS allocator requests") +MAC_STAT(sms_nobj, uint64_t, 0, 'i', "SMS outstanding allocations") +MAC_STAT(sms_nbytes, uint64_t, 0, 'i', "SMS outstanding bytes") +MAC_STAT(sms_balloc, uint64_t, 0, 'i', "SMS bytes allocated") +MAC_STAT(sms_bfree, uint64_t, 0, 'i', "SMS bytes freed") -MAC_STAT(backend_req, uint64_t, 'a', "Backend requests made") +MAC_STAT(backend_req, uint64_t, 0, '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") +MAC_STAT(n_vcl, uint64_t, 0, 'a', "N vcl total") +MAC_STAT(n_vcl_avail, uint64_t, 0, 'a', "N vcl available") +MAC_STAT(n_vcl_discard, uint64_t, 0, '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_obj_test, uint64_t, 'a', "N objects tested") -MAC_STAT(n_purge_re_test, uint64_t, 'a', "N regexps tested against") -MAC_STAT(n_purge_dups, uint64_t, 'a', "N duplicate purges removed") +MAC_STAT(n_purge, uint64_t, 0, 'i', "N total active purges") +MAC_STAT(n_purge_add, uint64_t, 0, 'a', "N new purges added") +MAC_STAT(n_purge_retire, uint64_t, 0, 'a', "N old purges deleted") +MAC_STAT(n_purge_obj_test, uint64_t, 0, 'a', "N objects tested") +MAC_STAT(n_purge_re_test, uint64_t, 0, 'a', "N regexps tested against") +MAC_STAT(n_purge_dups, uint64_t, 0, 'a', "N duplicate purges removed") -MAC_STAT(hcb_nolock, uint64_t, 'a', "HCB Lookups without lock") -MAC_STAT(hcb_lock, uint64_t, 'a', "HCB Lookups with lock") -MAC_STAT(hcb_insert, uint64_t, 'a', "HCB Inserts") +MAC_STAT(hcb_nolock, uint64_t, 0, 'a', "HCB Lookups without lock") +MAC_STAT(hcb_lock, uint64_t, 0, 'a', "HCB Lookups with lock") +MAC_STAT(hcb_insert, uint64_t, 0, 'a', "HCB Inserts") -MAC_STAT(esi_parse, uint64_t, 'a', "Objects ESI parsed (unlock)") -MAC_STAT(esi_errors, uint64_t, 'a', "ESI parse errors (unlock)") +MAC_STAT(esi_parse, uint64_t, 0, 'a', "Objects ESI parsed (unlock)") +MAC_STAT(esi_errors, uint64_t, 0, 'a', "ESI parse errors (unlock)") Modified: trunk/varnish-cache/include/stats.h =================================================================== --- trunk/varnish-cache/include/stats.h 2009-02-20 13:45:35 UTC (rev 3793) +++ trunk/varnish-cache/include/stats.h 2009-02-20 14:00:16 UTC (rev 3794) @@ -33,7 +33,7 @@ struct varnish_stats { time_t start_time; -#define MAC_STAT(n,t,f,e) t n; +#define MAC_STAT(n, t, l, f, e) t n; #include "stat_field.h" #undef MAC_STAT }; From phk at projects.linpro.no Fri Feb 20 15:18:46 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 16:18:46 +0100 (CET) Subject: r3795 - trunk/varnish-cache/bin/varnishd Message-ID: <20090220151846.DDD5A38085@projects.linpro.no> Author: phk Date: 2009-02-20 16:18:46 +0100 (Fri, 20 Feb 2009) New Revision: 3795 Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c Log: Make "hcb.dump" a CLI command Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-20 14:00:16 UTC (rev 3794) +++ trunk/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-20 15:18:46 UTC (rev 3795) @@ -41,6 +41,7 @@ #include "shmlog.h" #include "cache.h" #include "hash_slinger.h" +#include "cli_priv.h" static struct lock hcb_mtx; @@ -282,9 +283,9 @@ } /**********************************************************************/ -#ifdef PHK + static void -dumptree(uintptr_t p, int indent, FILE *fd) +dumptree(struct cli *cli, uintptr_t p, int indent) { int i; const struct objhead *oh; @@ -294,7 +295,7 @@ return; if (hcb_is_node(p)) { oh = hcb_l_node(p); - fprintf(fd, "%*.*sN %d r%u <%02x%02x%02x...> <%s>\n", + cli_out(cli, "%*.*sN %d r%u <%02x%02x%02x...> <%s>\n", indent, indent, "", indent / 2, oh->refcnt, oh->digest[0], oh->digest[1], oh->digest[2], oh->hash); @@ -302,24 +303,38 @@ } assert(hcb_is_y(p)); y = hcb_l_y(p); - fprintf(fd, "%*.*sY c %u p %u b %02x i %d\n", + cli_out(cli, "%*.*sY c %u p %u b %02x i %d\n", indent, indent, "", y->critbit, y->ptr, y->bitmask, indent / 2); indent += 2; for (i = 0; i < 2; i++) - dumptree(y->leaf[i], indent, fd); + dumptree(cli, y->leaf[i], indent); } static void -dump(const struct hcb_root *root, FILE *fd) +hcb_dump(struct cli *cli, const char * const *av, void *priv) { - fprintf(fd, "-------------\n"); - dumptree(root->origo, 0, fd); - fprintf(fd, "-------------\n"); - (void)fflush(fd); + struct objhead *oh, *oh2; + struct hcb_y *y; + + (void)priv; + (void)av; + cli_out(cli, "HCB dump:\n"); + dumptree(cli, hcb_root.origo, 0); + cli_out(cli, "Coollist:\n"); + Lck_Lock(&hcb_mtx); + VTAILQ_FOREACH_SAFE(oh, &laylow, coollist, oh2) { + y = (void *)&oh->u; + cli_out(cli, "%p ref %d, y{%u, %u}\n", oh, + oh->refcnt, y->leaf[0], y->leaf[1]); + } + Lck_Unlock(&hcb_mtx); } -#endif +static struct cli_proto hcb_cmds[] = { + { "hcb.dump", "hcb.dump", "dump HCB tree\n", 0, 0, hcb_dump }, + { NULL } +}; /**********************************************************************/ @@ -362,6 +377,7 @@ pthread_t tp; (void)oh; + CLI_AddFuncs(DEBUG_CLI, hcb_cmds); AZ(pthread_create(&tp, NULL, hcb_cleaner, NULL)); assert(sizeof(struct hcb_y) <= sizeof(oh->u)); memset(&hcb_root, 0, sizeof hcb_root); @@ -387,7 +403,6 @@ Lck_Unlock(&oh->mtx); #ifdef PHK fprintf(stderr, "hcb_defef %d %d <%s>\n", __LINE__, r, oh->hash); - dump(&hcb_root, stderr); #endif return (r); } @@ -424,7 +439,6 @@ VSL_stats->hcb_insert++; #ifdef PHK fprintf(stderr, "hcb_lookup %d\n", __LINE__); - dump(&hcb_root, stderr); #endif } else { free(noh->hash); @@ -432,7 +446,6 @@ VSL_stats->hcb_lock++; #ifdef PHK fprintf(stderr, "hcb_lookup %d\n", __LINE__); - dump(&hcb_root, stderr); #endif } Lck_Unlock(&hcb_mtx); From phk at projects.linpro.no Fri Feb 20 15:25:06 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 16:25:06 +0100 (CET) Subject: r3796 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20090220152506.5DE4138085@projects.linpro.no> Author: phk Date: 2009-02-20 16:25:06 +0100 (Fri, 20 Feb 2009) New Revision: 3796 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/hash_critbit.c trunk/varnish-cache/bin/varnishd/hash_slinger.h trunk/varnish-cache/include/stat_field.h Log: Add a delta-stats structure to worker threads and keep track of n_object and n_objecthead in them. Accumulate into global stats after work is done if the lock is free and always before going idle. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-20 15:18:46 UTC (rev 3795) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-20 15:25:06 UTC (rev 3796) @@ -178,12 +178,25 @@ /*--------------------------------------------------------------------*/ +#define L0(n) +#define L1(n) int n; +#define MAC_STAT(n, t, l, f, e) L##l(n) +struct dstat { +#include "stat_field.h" +}; +#undef MAC_STAT +#undef L0 +#undef L1 + +/*--------------------------------------------------------------------*/ + struct worker { unsigned magic; #define WORKER_MAGIC 0x6391adcf struct objhead *nobjhead; struct object *nobj; struct objcore *nobjcore; + struct dstat *stats; double lastused; @@ -551,6 +564,7 @@ void WRK_Init(void); int WRK_Queue(struct workreq *wrq); void WRK_QueueSession(struct sess *sp); +void WRK_SumStat(struct worker *w); void WRW_Reserve(struct worker *w, int *fd); void WRW_Release(struct worker *w); Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-20 15:18:46 UTC (rev 3795) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-02-20 15:25:06 UTC (rev 3796) @@ -181,7 +181,7 @@ RES_WriteObj(sp); AZ(sp->wrk->wfd); - HSH_Deref(&sp->obj); + HSH_Deref(sp->wrk, &sp->obj); sp->step = STP_DONE; return (0); } @@ -527,7 +527,7 @@ } /* Drop our object, we won't need it */ - HSH_Deref(&sp->obj); + HSH_Deref(sp->wrk, &sp->obj); switch(sp->handling) { case VCL_RET_PASS: @@ -611,7 +611,7 @@ if (sp->obj->objcore->flags & OC_F_PASS) { VSL_stats->cache_hitpass++; WSP(sp, SLT_HitPass, "%u", sp->obj->xid); - HSH_Deref(&sp->obj); + HSH_Deref(sp->wrk, &sp->obj); sp->step = STP_PASS; return (0); } Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-20 15:18:46 UTC (rev 3795) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-20 15:25:06 UTC (rev 3796) @@ -217,16 +217,20 @@ double t; struct sess *sp; unsigned char logbuf[1024]; /* XXX size ? */ + struct dstat stats; THR_SetName("cache-timeout"); (void)arg; sp = SES_New(NULL, 0); XXXAN(sp); + memset(&ww, 0, sizeof ww); + memset(&stats, 0, sizeof stats); sp->wrk = &ww; ww.magic = WORKER_MAGIC; ww.wlp = ww.wlb = logbuf; ww.wle = logbuf + sizeof logbuf; + ww.stats = &stats; AZ(sleep(10)); /* XXX: Takes time for VCL to arrive */ VCL_Get(&sp->vcl); @@ -238,6 +242,7 @@ if (oc == NULL || oc->timer_when > t) { /* XXX: > or >= ? */ Lck_Unlock(&exp_mtx); WSL_Flush(&ww, 0); + WRK_SumStat(&ww); AZ(sleep(1)); VCL_Refresh(&sp->vcl); t = TIM_real(); @@ -277,7 +282,7 @@ oc->flags &= ~OC_F_ONLRU; VSL_stats->n_expired++; Lck_Unlock(&exp_mtx); - HSH_Deref(&o); + HSH_Deref(&ww, &o); } } @@ -344,7 +349,7 @@ if (sp->handling == VCL_RET_DISCARD) { WSL(sp->wrk, SLT_ExpKill, 0, "%u LRU", o->xid); - HSH_Deref(&o); + HSH_Deref(sp->wrk, &o); return (1); } Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 15:18:46 UTC (rev 3795) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 15:25:06 UTC (rev 3796) @@ -109,7 +109,7 @@ VTAILQ_INIT(&oh->waitinglist); Lck_New(&oh->mtx); w->nobjhead = oh; - VSL_stats->n_objecthead++; + w->stats->n_objecthead++; } CHECK_OBJ_NOTNULL(w->nobjhead, OBJHEAD_MAGIC); @@ -134,20 +134,20 @@ VTAILQ_INIT(&o->store); VTAILQ_INIT(&o->esibits); w->nobj = o; - VSL_stats->n_object++; + w->stats->n_object++; } CHECK_OBJ_NOTNULL(w->nobj, OBJECT_MAGIC); } void -HSH_DeleteObjHead(struct objhead *oh) +HSH_DeleteObjHead(struct worker *w, struct objhead *oh) { AZ(oh->refcnt); assert(VTAILQ_EMPTY(&oh->objcs)); Lck_Delete(&oh->mtx); - VSL_stats->n_objecthead--; + w->stats->n_objecthead--; free(oh->hash); FREE_OBJ(oh); } @@ -398,7 +398,7 @@ o->cacheable = 0; if (o->objcore != NULL) /* Pass has no objcore */ HSH_Unbusy(sp); - HSH_Deref(&sp->obj); + HSH_Deref(sp->wrk, &sp->obj); } void @@ -434,7 +434,7 @@ if (oh != NULL) Lck_Unlock(&oh->mtx); if (parent != NULL) - HSH_Deref(&parent); + HSH_Deref(sp->wrk, &parent); } void @@ -452,7 +452,7 @@ } void -HSH_Deref(struct object **oo) +HSH_Deref(struct worker *w, struct object **oo) { struct object *o; struct objhead *oh; @@ -498,7 +498,7 @@ ESI_Destroy(o); HSH_Freestore(o); STV_free(o->objstore); - VSL_stats->n_object--; + w->stats->n_object--; if (oh == NULL) { AZ(oc); @@ -510,7 +510,7 @@ assert(oh->refcnt > 0); if (hash->deref(oh)) return; - HSH_DeleteObjHead(oh); + HSH_DeleteObjHead(w, oh); } void Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2009-02-20 15:18:46 UTC (rev 3795) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2009-02-20 15:25:06 UTC (rev 3796) @@ -98,6 +98,7 @@ static pthread_cond_t herder_cond; static struct lock herder_mtx; +static struct lock wstat_mtx; /*-------------------------------------------------------------------- * Write data to fd @@ -264,6 +265,31 @@ /*--------------------------------------------------------------------*/ +static void +wrk_sumstat(struct worker *w) +{ + + Lck_AssertHeld(&wstat_mtx); +#define L0(n) +#define L1(n) VSL_stats->n += w->stats->n +#define MAC_STAT(n, t, l, f, d) L##l(n); +#include "stat_field.h" +#undef MAC_STAT +#undef L0 +#undef L1 + memset(w->stats, 0, sizeof *w->stats); +} + +void +WRK_SumStat(struct worker *w) +{ + Lck_Lock(&wstat_mtx); + wrk_sumstat(w); + Lck_Unlock(&wstat_mtx); +} + +/*--------------------------------------------------------------------*/ + static void * wrk_thread(void *priv) { @@ -271,12 +297,16 @@ struct wq *qp; unsigned char wlog[params->shm_workspace]; struct SHA256Context sha256; + struct dstat stats; + unsigned stats_clean = 0; THR_SetName("cache-worker"); w = &ww; CAST_OBJ_NOTNULL(qp, priv, WQ_MAGIC); memset(w, 0, sizeof *w); + memset(&stats, 0, sizeof stats); w->magic = WORKER_MAGIC; + w->stats = &stats; w->lastused = NAN; w->wlb = w->wlp = wlog; w->wle = wlog + sizeof wlog; @@ -299,6 +329,12 @@ if (isnan(w->lastused)) w->lastused = TIM_real(); VTAILQ_INSERT_HEAD(&qp->idle, w, list); + if (!stats_clean) { + Lck_Lock(&wstat_mtx); + wrk_sumstat(w); + stats_clean = 1; + Lck_Unlock(&wstat_mtx); + } Lck_CondWait(&w->cond, &qp->mtx); } if (w->wrq == NULL) @@ -307,14 +343,21 @@ AN(w->wrq); AN(w->wrq->func); w->lastused = NAN; + stats_clean = 0; w->wrq->func(w, w->wrq->priv); AZ(w->wfd); assert(w->wlp == w->wlb); w->wrq = NULL; + if (!Lck_Trylock(&wstat_mtx)) { + wrk_sumstat(w); + stats_clean = 1; + Lck_Unlock(&wstat_mtx); + } Lck_Lock(&qp->mtx); } qp->nthr--; Lck_Unlock(&qp->mtx); + AN(stats_clean); VSL(SLT_WorkThread, 0, "%p end", w); if (w->vcl != NULL) @@ -627,6 +670,7 @@ AZ(pthread_cond_init(&herder_cond, NULL)); Lck_New(&herder_mtx); + Lck_New(&wstat_mtx); wrk_addpools(params->wthread_pools); AZ(pthread_create(&tp, NULL, wrk_herdtimer_thread, NULL)); Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-20 15:18:46 UTC (rev 3795) +++ trunk/varnish-cache/bin/varnishd/hash_critbit.c 2009-02-20 15:25:06 UTC (rev 3796) @@ -345,7 +345,14 @@ { struct objhead *oh, *oh2; struct hcb_y *y; + struct worker ww; + struct dstat stats; + memset(&ww, 0, sizeof ww); + memset(&stats, 0, sizeof stats); + ww.magic = WORKER_MAGIC; + ww.stats = &stats; + THR_SetName("hcb_cleaner"); (void)priv; while (1) { @@ -361,10 +368,11 @@ fprintf(stderr, "OH %p is cold enough\n", oh); #endif oh->refcnt = 0; - HSH_DeleteObjHead(oh); + HSH_DeleteObjHead(&ww, oh); } } Lck_Unlock(&hcb_mtx); + WRK_SumStat(&ww); } } Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 15:18:46 UTC (rev 3795) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 15:25:06 UTC (rev 3796) @@ -50,13 +50,11 @@ /* cache_hash.c */ void HSH_Prealloc(struct sess *sp); -void HSH_DeleteObjHead(struct objhead *oh); void HSH_Freestore(struct object *o); void HSH_Copy(const struct sess *sp, struct objhead *o); struct object *HSH_Lookup(struct sess *sp); void HSH_Unbusy(const struct sess *sp); void HSH_Ref(struct object *o); -void HSH_Deref(struct object **o); void HSH_Drop(struct sess *sp); double HSH_Grace(double g); void HSH_Init(void); @@ -100,4 +98,6 @@ }; extern unsigned save_hash; +void HSH_DeleteObjHead(struct worker *w, struct objhead *oh); +void HSH_Deref(struct worker *w, struct object **o); #endif /* VARNISH_CACHE_CHILD */ Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2009-02-20 15:18:46 UTC (rev 3795) +++ trunk/varnish-cache/include/stat_field.h 2009-02-20 15:25:06 UTC (rev 3796) @@ -49,8 +49,8 @@ MAC_STAT(n_srcaddr_act, uint64_t, 0, 'i', "N active struct srcaddr") MAC_STAT(n_sess_mem, uint64_t, 0, 'i', "N struct sess_mem") MAC_STAT(n_sess, uint64_t, 0, 'i', "N struct sess") -MAC_STAT(n_object, uint64_t, 0, 'i', "N struct object") -MAC_STAT(n_objecthead, uint64_t, 0, 'i', "N struct objecthead") +MAC_STAT(n_object, uint64_t, 1, 'i', "N struct object") +MAC_STAT(n_objecthead, uint64_t, 1, 'i', "N struct objecthead") MAC_STAT(n_smf, uint64_t, 0, 'i', "N struct smf") MAC_STAT(n_smf_frag, uint64_t, 0, 'i', "N small free smf") MAC_STAT(n_smf_large, uint64_t, 0, 'i', "N large free smf") From phk at projects.linpro.no Fri Feb 20 17:21:30 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 18:21:30 +0100 (CET) Subject: r3797 - trunk/varnish-cache/bin/varnishd Message-ID: <20090220172130.516881F74E8@projects.linpro.no> Author: phk Date: 2009-02-20 18:21:30 +0100 (Fri, 20 Feb 2009) New Revision: 3797 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/hash_slinger.h Log: Put the cleanup next to the preallocation and remember to release the preallocated objcore Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 15:25:06 UTC (rev 3796) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 17:21:30 UTC (rev 3797) @@ -141,6 +141,27 @@ } void +HSH_Cleanup(struct worker *w) +{ + + if (w->nobjcore != NULL) { + FREE_OBJ(w->nobjcore); + w->nobjcore = NULL; + } + if (w->nobjhead != NULL) { + Lck_Delete(&w->nobjhead->mtx); + FREE_OBJ(w->nobjhead); + w->nobjhead = NULL; + w->stats->n_objecthead--; + } + if (w->nobj != NULL) { + STV_free(w->nobj->objstore); + w->nobj = NULL; + w->stats->n_object--; + } +} + +void HSH_DeleteObjHead(struct worker *w, struct objhead *oh) { Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2009-02-20 15:25:06 UTC (rev 3796) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2009-02-20 17:21:30 UTC (rev 3797) @@ -365,12 +365,8 @@ AZ(pthread_cond_destroy(&w->cond)); if (w->srcaddr != NULL) free(w->srcaddr); - if (w->nobjhead != NULL) { - Lck_Delete(&w->nobjhead->mtx); - FREE_OBJ(w->nobjhead); - } - if (w->nobj!= NULL) - STV_free(w->nobj->objstore); + HSH_Cleanup(w); + WRK_SumStat(w); return (NULL); } Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 15:25:06 UTC (rev 3796) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 17:21:30 UTC (rev 3797) @@ -30,6 +30,7 @@ */ struct sess; +struct worker; struct object; typedef void hash_init_f(int ac, char * const *av); @@ -50,6 +51,7 @@ /* cache_hash.c */ void HSH_Prealloc(struct sess *sp); +void HSH_Cleanup(struct worker *w); void HSH_Freestore(struct object *o); void HSH_Copy(const struct sess *sp, struct objhead *o); struct object *HSH_Lookup(struct sess *sp); From phk at projects.linpro.no Fri Feb 20 18:00:06 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 19:00:06 +0100 (CET) Subject: r3798 - trunk/varnish-cache/bin/varnishd Message-ID: <20090220180006.E356C38085@projects.linpro.no> Author: phk Date: 2009-02-20 19:00:06 +0100 (Fri, 20 Feb 2009) New Revision: 3798 Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_pool.c Log: Add a lot more paranoia asserts Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-20 17:21:30 UTC (rev 3797) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-02-20 18:00:06 UTC (rev 3798) @@ -251,6 +251,7 @@ o = oc->obj; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + CHECK_OBJ_NOTNULL(o->objhead, OBJHEAD_MAGIC); assert(oc->timer_idx != BINHEAP_NOIDX); binheap_delete(exp_heap, oc->timer_idx); assert(oc->timer_idx == BINHEAP_NOIDX); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 17:21:30 UTC (rev 3797) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 18:00:06 UTC (rev 3798) @@ -356,6 +356,7 @@ WSP(sp, SLT_Debug, "on waiting list <%s>", oh->hash); sp->objhead = oh; + sp->wrk = NULL; Lck_Unlock(&oh->mtx); return (NULL); } @@ -393,10 +394,14 @@ unsigned u; struct sess *sp; + CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); + Lck_AssertHeld(&oh->mtx); for (u = 0; u < params->rush_exponent; u++) { sp = VTAILQ_FIRST(&oh->waitinglist); if (sp == NULL) return; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + AZ(sp->wrk); VTAILQ_REMOVE(&oh->waitinglist, sp, list); DSL(0x20, SLT_Debug, sp->id, "off waiting list"); WRK_QueueSession(sp); Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2009-02-20 17:21:30 UTC (rev 3797) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2009-02-20 18:00:06 UTC (rev 3798) @@ -330,10 +330,8 @@ w->lastused = TIM_real(); VTAILQ_INSERT_HEAD(&qp->idle, w, list); if (!stats_clean) { - Lck_Lock(&wstat_mtx); - wrk_sumstat(w); + WRK_SumStat(w); stats_clean = 1; - Lck_Unlock(&wstat_mtx); } Lck_CondWait(&w->cond, &qp->mtx); } @@ -348,6 +346,7 @@ AZ(w->wfd); assert(w->wlp == w->wlb); w->wrq = NULL; + HSH_Cleanup(w); if (!Lck_Trylock(&wstat_mtx)) { wrk_sumstat(w); stats_clean = 1; @@ -430,6 +429,7 @@ struct sess *sess; CAST_OBJ_NOTNULL(sess, priv, SESS_MAGIC); + AZ(sess->wrk); THR_SetSession(sess); sess->wrk = w; CHECK_OBJ_ORNULL(w->nobj, OBJECT_MAGIC); @@ -445,6 +445,8 @@ void WRK_QueueSession(struct sess *sp) { + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + AZ(sp->wrk); sp->workreq.func = wrk_do_cnt_sess; sp->workreq.priv = sp; if (WRK_Queue(&sp->workreq) == 0) From phk at projects.linpro.no Fri Feb 20 18:05:35 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 19:05:35 +0100 (CET) Subject: r3799 - trunk/varnish-cache/bin/varnishd Message-ID: <20090220180535.0C74C38085@projects.linpro.no> Author: phk Date: 2009-02-20 19:05:34 +0100 (Fri, 20 Feb 2009) New Revision: 3799 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c Log: Don't try to rush waiting sessions of refcount is zero, there cannot be any (they would hold a reference). Should be merged to 2.0.3 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 18:00:06 UTC (rev 3798) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 18:05:34 UTC (rev 3799) @@ -505,7 +505,8 @@ r = --o->refcnt; if (!r) VTAILQ_REMOVE(&oh->objcs, oc, list); - hsh_rush(oh); + else + hsh_rush(oh); Lck_Unlock(&oh->mtx); } From phk at projects.linpro.no Fri Feb 20 18:13:43 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 19:13:43 +0100 (CET) Subject: r3800 - trunk/varnish-cache/bin/varnishd Message-ID: <20090220181343.26D742843C@projects.linpro.no> Author: phk Date: 2009-02-20 19:13:42 +0100 (Fri, 20 Feb 2009) New Revision: 3800 Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c Log: Don't clean on every request, that was for debugging only. Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2009-02-20 18:05:34 UTC (rev 3799) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2009-02-20 18:13:42 UTC (rev 3800) @@ -346,7 +346,6 @@ AZ(w->wfd); assert(w->wlp == w->wlb); w->wrq = NULL; - HSH_Cleanup(w); if (!Lck_Trylock(&wstat_mtx)) { wrk_sumstat(w); stats_clean = 1; From phk at projects.linpro.no Fri Feb 20 18:41:58 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 19:41:58 +0100 (CET) Subject: r3801 - trunk/varnish-cache/bin/varnishd Message-ID: <20090220184158.164FB38085@projects.linpro.no> Author: phk Date: 2009-02-20 19:41:57 +0100 (Fri, 20 Feb 2009) New Revision: 3801 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Handle worker thread on subrequests correctly Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-20 18:13:42 UTC (rev 3800) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-02-20 18:41:57 UTC (rev 3801) @@ -759,22 +759,24 @@ { struct esi_bit *eb; struct object *obj; + struct worker *w; - WRW_Reserve(sp->wrk, &sp->fd); + w = sp->wrk; + WRW_Reserve(w, &sp->fd); VTAILQ_FOREACH(eb, &sp->obj->esibits, list) { if (Tlen(eb->verbatim)) { if (sp->http->protover >= 1.1) - (void)WRW_Write(sp->wrk, eb->chunk_length, -1); - sp->acct_req.bodybytes += WRW_Write(sp->wrk, + (void)WRW_Write(w, eb->chunk_length, -1); + sp->acct_req.bodybytes += WRW_Write(w, eb->verbatim.b, Tlen(eb->verbatim)); if (sp->http->protover >= 1.1) - (void)WRW_Write(sp->wrk, "\r\n", -1); + (void)WRW_Write(w, "\r\n", -1); } if (eb->include.b == NULL || sp->esis >= params->max_esi_includes) continue; - if (WRW_FlushRelease(sp->wrk)) { + if (WRW_FlushRelease(w)) { vca_close_session(sp, "remote closed"); return; } @@ -788,7 +790,7 @@ if (eb->host.b != NULL) { http_Unset(sp->http, H_Host); http_Unset(sp->http, H_If_Modified_Since); - http_SetHeader(sp->wrk, sp->fd, sp->http, eb->host.b); + http_SetHeader(w, sp->fd, sp->http, eb->host.b); } /* * XXX: We should decide if we should cache the director @@ -807,14 +809,16 @@ http_Unset(sp->http, H_Content_Length); while (1) { + sp->wrk = w; CNT_Session(sp); if (sp->step == STP_DONE) break; - AN(sp->wrk); - WSL_Flush(sp->wrk, 0); + AZ(sp->wrk); + WSL_Flush(w, 0); DSL(0x20, SLT_Debug, sp->id, "loop waiting for ESI"); (void)usleep(10000); } + AN(sp->wrk); assert(sp->step == STP_DONE); sp->esis--; sp->obj = obj; From phk at projects.linpro.no Fri Feb 20 19:06:07 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 20 Feb 2009 20:06:07 +0100 (CET) Subject: r3802 - trunk/varnish-cache/bin/varnishd Message-ID: <20090220190607.C12091F74DE@projects.linpro.no> Author: phk Date: 2009-02-20 20:06:07 +0100 (Fri, 20 Feb 2009) New Revision: 3802 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/hash_slinger.h Log: Some constifications Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-02-20 18:41:57 UTC (rev 3801) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-02-20 19:06:07 UTC (rev 3802) @@ -564,7 +564,7 @@ void WRK_Init(void); int WRK_Queue(struct workreq *wrq); void WRK_QueueSession(struct sess *sp); -void WRK_SumStat(struct worker *w); +void WRK_SumStat(const struct worker *w); void WRW_Reserve(struct worker *w, int *fd); void WRW_Release(struct worker *w); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 18:41:57 UTC (rev 3801) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 19:06:07 UTC (rev 3802) @@ -162,7 +162,7 @@ } void -HSH_DeleteObjHead(struct worker *w, struct objhead *oh) +HSH_DeleteObjHead(const struct worker *w, struct objhead *oh) { AZ(oh->refcnt); @@ -478,7 +478,7 @@ } void -HSH_Deref(struct worker *w, struct object **oo) +HSH_Deref(const struct worker *w, struct object **oo) { struct object *o; struct objhead *oh; Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2009-02-20 18:41:57 UTC (rev 3801) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2009-02-20 19:06:07 UTC (rev 3802) @@ -266,12 +266,12 @@ /*--------------------------------------------------------------------*/ static void -wrk_sumstat(struct worker *w) +wrk_sumstat(const struct worker *w) { Lck_AssertHeld(&wstat_mtx); #define L0(n) -#define L1(n) VSL_stats->n += w->stats->n +#define L1(n) (VSL_stats->n += w->stats->n) #define MAC_STAT(n, t, l, f, d) L##l(n); #include "stat_field.h" #undef MAC_STAT @@ -281,7 +281,7 @@ } void -WRK_SumStat(struct worker *w) +WRK_SumStat(const struct worker *w) { Lck_Lock(&wstat_mtx); wrk_sumstat(w); Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 18:41:57 UTC (rev 3801) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 19:06:07 UTC (rev 3802) @@ -100,6 +100,6 @@ }; extern unsigned save_hash; -void HSH_DeleteObjHead(struct worker *w, struct objhead *oh); -void HSH_Deref(struct worker *w, struct object **o); +void HSH_DeleteObjHead(const struct worker *w, struct objhead *oh); +void HSH_Deref(const struct worker *w, struct object **o); #endif /* VARNISH_CACHE_CHILD */ From phk at projects.linpro.no Sun Feb 22 16:36:37 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 22 Feb 2009 17:36:37 +0100 (CET) Subject: r3803 - trunk/varnish-cache/bin/varnishd Message-ID: <20090222163637.6FA861F752E@projects.linpro.no> Author: phk Date: 2009-02-22 17:36:37 +0100 (Sun, 22 Feb 2009) New Revision: 3803 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/common.h 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/varnishd.c Log: Move the catalogs of storage and hash modules closer to home. Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-20 19:06:07 UTC (rev 3802) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-02-22 16:36:37 UTC (rev 3803) @@ -549,3 +549,11 @@ if (hash->start != NULL) hash->start(); } + +const struct choice hsh_choice[] = { + { "classic", &hcl_slinger }, + { "simple", &hsl_slinger }, + { "simple_list", &hsl_slinger }, /* backwards compat */ + { "critbit", &hcb_slinger }, + { NULL, NULL } +}; Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2009-02-20 19:06:07 UTC (rev 3802) +++ trunk/varnish-cache/bin/varnishd/common.h 2009-02-22 16:36:37 UTC (rev 3803) @@ -52,3 +52,9 @@ fprintf(stderr, "Error: " __VA_ARGS__); \ exit(2); \ } while (0); + +/* A tiny helper for choosing hash/storage modules */ +struct choice { + const char *name; + void *ptr; +}; Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-20 19:06:07 UTC (rev 3802) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-22 16:36:37 UTC (rev 3803) @@ -103,3 +103,8 @@ void HSH_DeleteObjHead(const struct worker *w, struct objhead *oh); void HSH_Deref(const struct worker *w, struct object **o); #endif /* VARNISH_CACHE_CHILD */ + +extern struct hash_slinger hsl_slinger; +extern struct hash_slinger hcl_slinger; +extern struct hash_slinger hcb_slinger; +extern const struct choice hsh_choice[]; Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2009-02-20 19:06:07 UTC (rev 3802) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2009-02-22 16:36:37 UTC (rev 3803) @@ -76,4 +76,3 @@ fprintf(stderr, fmt "\n", __VA_ARGS__); \ syslog(pri, fmt, __VA_ARGS__); \ } while (0) - Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2009-02-20 19:06:07 UTC (rev 3802) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2009-02-22 16:36:37 UTC (rev 3803) @@ -124,3 +124,12 @@ stv->open(stv); } } + +const struct choice STV_choice[] = { + { "file", &smf_stevedore }, + { "malloc", &sma_stevedore }, +#ifdef HAVE_LIBUMEM + { "umem", &smu_stevedore }, +#endif + { NULL, NULL } +}; Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2009-02-20 19:06:07 UTC (rev 3802) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2009-02-22 16:36:37 UTC (rev 3803) @@ -68,3 +68,11 @@ /* Synthetic Storage */ void SMS_Init(void); + +extern struct stevedore sma_stevedore; +extern struct stevedore smf_stevedore; +#ifdef HAVE_LIBUMEM +extern struct stevedore smu_stevedore; +#endif + +extern const struct choice STV_choice[]; Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2009-02-20 19:06:07 UTC (rev 3802) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2009-02-22 16:36:37 UTC (rev 3803) @@ -82,11 +82,6 @@ /*--------------------------------------------------------------------*/ -struct choice { - const char *name; - void *ptr; -}; - static void * pick(const struct choice *cp, const char *which, const char *kind) { @@ -113,21 +108,7 @@ } /*--------------------------------------------------------------------*/ -extern struct stevedore sma_stevedore; -extern struct stevedore smf_stevedore; -#ifdef HAVE_LIBUMEM -extern struct stevedore smu_stevedore; -#endif -static const struct choice stv_choice[] = { - { "file", &smf_stevedore }, - { "malloc", &sma_stevedore }, -#ifdef HAVE_LIBUMEM - { "umem", &smu_stevedore }, -#endif - { NULL, NULL } -}; - static void setup_storage(const char *spec) { @@ -147,7 +128,7 @@ for (ac = 0; av[ac + 2] != NULL; ac++) continue; - priv = pick(stv_choice, av[1], "storage"); + priv = pick(STV_choice, av[1], "storage"); AN(priv); STV_add(priv, ac, av + 2); @@ -157,18 +138,6 @@ /*--------------------------------------------------------------------*/ -extern struct hash_slinger hsl_slinger; -extern struct hash_slinger hcl_slinger; -extern struct hash_slinger hcb_slinger; - -static const struct choice hsh_choice[] = { - { "classic", &hcl_slinger }, - { "simple", &hsl_slinger }, - { "simple_list", &hsl_slinger }, /* backwards compat */ - { "critbit", &hcb_slinger }, - { NULL, NULL } -}; - static void setup_hash(const char *h_arg) { From phk at projects.linpro.no Sun Feb 22 17:48:25 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 22 Feb 2009 18:48:25 +0100 (CET) Subject: r3804 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20090222174825.15DD128371@projects.linpro.no> Author: phk Date: 2009-02-22 18:48:24 +0100 (Sun, 22 Feb 2009) New Revision: 3804 Added: trunk/varnish-cache/bin/varnishd/storage_persistent.c trunk/varnish-cache/include/persistent.h Modified: trunk/varnish-cache/bin/varnishd/Makefile.am Log: Bring in the first inkling of the persistent storage module Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2009-02-22 16:36:37 UTC (rev 3803) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2009-02-22 17:48:24 UTC (rev 3804) @@ -53,6 +53,7 @@ stevedore.c \ storage_file.c \ storage_malloc.c \ + storage_persistent.c \ storage_synth.c \ storage_umem.c \ stevedore_utils.c \ Added: trunk/varnish-cache/bin/varnishd/storage_persistent.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_persistent.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-02-22 17:48:24 UTC (rev 3804) @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2008-2009 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$ + * + * Persistent storage method + */ + +#include "config.h" + +#include +#include + +#include "cache.h" +#include "stevedore.h" + +#include "persistent.h" + +static void +smp_init(struct stevedore *parent, int ac, char * const *av) +{ + + (void)parent; + (void)ac; + (void)av; + assert(sizeof(struct smp_ident) == SMP_IDENT_SIZE); + assert(sizeof(struct smp_object) == SMP_OBJECT_SIZE); +} + +struct stevedore smp_stevedore = { + .magic = STEVEDORE_MAGIC, + .name = "persistent", + .init = smp_init, + // .open = smf_open, + // .alloc = smf_alloc, + // .trim = smf_trim, + // .free = smf_free, +}; Added: trunk/varnish-cache/include/persistent.h =================================================================== --- trunk/varnish-cache/include/persistent.h (rev 0) +++ trunk/varnish-cache/include/persistent.h 2009-02-22 17:48:24 UTC (rev 3804) @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2008-2009 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$ + */ + +/* + * Overall layout: + * + * struct smp_ident; Identification and geometry + * sha256[...] checksum of same + * + * struct smp_segment[N]; Segment table + * sha256[...] checksum of same + * + * banspace_1; First ban-space + * sha256[...] checksum of same + * + * banspace_2; Second ban-space + * sha256[...] checksum of same + * + * N segments { + * struct smp_object[M] Objects in segment + * sha256[...] checksum of same + * objspace + * } + */ + +/* + * The identblock is located in the first sector of the storage space. + * This is written once and not subsequently modified in normal operation. + * It is immediately followed by a SHA256sum of the structure, as stored. + */ + +struct smp_ident { + char ident[32]; /* Human readable ident + * so people and programs + * can tell what the file + * or device contains. + */ + + uint32_t byte_order; /* 0x12345678 */ + + uint32_t size; /* sizeof(struct smp_ident) */ + + uint32_t major_version; + + uint32_t minor_version; + + uint64_t mediasize; /* ... in bytes */ + + uint32_t granularity; /* smallest ... in bytes */ + + /* XXX: ptr to bans table */ + /* XXX: ptr to segment table */ +}; + +#define SMP_IDENT_SIZE (32 + 4 + 4 + 4 + 4 + 8 + 4 ) + +/* + * A segment descriptor. + */ + +struct smp_segment { + uint64_t offset; + uint64_t length; +}; + +#define SMP_SEGMENT_SIZE (8+8) + +/* + * Ban description + */ + +struct smp_ban { + double ttl; + uint16_t length; + uint8_t valid; +}; + +/* + * An object descriptor + */ + +struct smp_object { + unsigned char hash[32]; + double ttl; + double ban; + uint64_t offset; + uint64_t len; +}; + +#define SMP_OBJECT_SIZE (32 + 8 + 8 + 8 + 8) From petter at projects.linpro.no Mon Feb 23 07:17:20 2009 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Mon, 23 Feb 2009 08:17:20 +0100 (CET) Subject: r3805 - trunk/varnish-tools/webgui Message-ID: <20090223071720.E4BCF1F752C@projects.linpro.no> Author: petter Date: 2009-02-23 08:17:20 +0100 (Mon, 23 Feb 2009) New Revision: 3805 Modified: trunk/varnish-tools/webgui/create_db_data.pl trunk/varnish-tools/webgui/varnish_webgui.sql Log: Gain some speed by at least creating index on the stat table Modified: trunk/varnish-tools/webgui/create_db_data.pl =================================================================== --- trunk/varnish-tools/webgui/create_db_data.pl 2009-02-22 17:48:24 UTC (rev 3804) +++ trunk/varnish-tools/webgui/create_db_data.pl 2009-02-23 07:17:20 UTC (rev 3805) @@ -111,6 +111,9 @@ description TEXT ); +CREATE INDEX stat_time ON stat(time); +CREATE INDEX stat_node_id ON stat(node_id); + INSERT INTO node_group VALUES(0, 0, 'Standalone'); $parameter_info_sql Modified: trunk/varnish-tools/webgui/varnish_webgui.sql =================================================================== --- trunk/varnish-tools/webgui/varnish_webgui.sql 2009-02-22 17:48:24 UTC (rev 3804) +++ trunk/varnish-tools/webgui/varnish_webgui.sql 2009-02-23 07:17:20 UTC (rev 3805) @@ -1,4 +1,4 @@ --- This file was auto generated Wed Feb 18 15:58:37 2009 by create_db_files.pl +-- This file was auto generated Mon Feb 23 08:16:23 2009 by create_db_files.pl DROP TABLE node_group; DROP TABLE node; DROP TABLE stat; @@ -188,6 +188,9 @@ description TEXT ); +CREATE INDEX stat_time ON stat(time); +CREATE INDEX stat_node_id ON stat(node_id); + INSERT INTO node_group VALUES(0, 0, 'Standalone'); INSERT INTO parameter_info VALUES('accept_fd_holdoff', 'ms', 'Default is 50. If we run out of file descriptors, the accept thread will sleep. This parameter control for how long it will sleep. NB: We do not know yet if it is a good idea to change this parameter, or if the default value is even sensible. Caution is advised, and feedback is most welcome. '); From phk at projects.linpro.no Mon Feb 23 10:07:51 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 23 Feb 2009 11:07:51 +0100 (CET) Subject: r3806 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20090223100751.B865F38087@projects.linpro.no> Author: phk Date: 2009-02-23 11:07:51 +0100 (Mon, 23 Feb 2009) New Revision: 3806 Modified: trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/bin/varnishd/stevedore.h trunk/varnish-cache/bin/varnishd/storage_persistent.c trunk/varnish-cache/include/persistent.h Log: Code to create, map and ident the storage silo Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2009-02-23 07:17:20 UTC (rev 3805) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2009-02-23 10:07:51 UTC (rev 3806) @@ -128,6 +128,7 @@ const struct choice STV_choice[] = { { "file", &smf_stevedore }, { "malloc", &sma_stevedore }, + { "persistent", &smp_stevedore }, #ifdef HAVE_LIBUMEM { "umem", &smu_stevedore }, #endif Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2009-02-23 07:17:20 UTC (rev 3805) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2009-02-23 10:07:51 UTC (rev 3806) @@ -71,6 +71,7 @@ extern struct stevedore sma_stevedore; extern struct stevedore smf_stevedore; +extern struct stevedore smp_stevedore; #ifdef HAVE_LIBUMEM extern struct stevedore smu_stevedore; #endif Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-02-23 07:17:20 UTC (rev 3805) +++ trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-02-23 10:07:51 UTC (rev 3806) @@ -32,25 +32,158 @@ #include "config.h" +#include +#include #include +#include +#include #include +#include #include "cache.h" #include "stevedore.h" +#include "vsha256.h" #include "persistent.h" +struct smp_sc { + unsigned magic; +#define SMP_SC_MAGIC 0x7b73af0a + + int fd; + const char *filename; + off_t mediasize; + unsigned granularity; + + uint8_t *ptr; +}; + +/*--------------------------------------------------------------------*/ + static void +smp_make_sign(const void *ptr, off_t len, uint8_t *dest) +{ + struct SHA256Context c; + + SHA256_Init(&c); + SHA256_Update(&c, ptr, len); + SHA256_Final(dest, &c); +} + +/*--------------------------------------------------------------------*/ + +static int +smp_check_sign(const void *ptr, off_t len, const void *sign) +{ + struct SHA256Context c; + unsigned char nsign[32]; + + SHA256_Init(&c); + SHA256_Update(&c, ptr, len); + SHA256_Final(nsign, &c); + return(memcmp(sign, nsign, sizeof nsign)); +} + +/*--------------------------------------------------------------------*/ + +static void +smp_newsilo(struct smp_sc *sc) +{ + struct smp_ident *si; + + assert(strlen(SMP_IDENT_STRING) < sizeof si->ident); + si = (void*)sc->ptr; + memset(si, 0, sizeof *si); + strcpy(si->ident, SMP_IDENT_STRING); + si->byte_order = 0x12345678; + si->size = sizeof *si; + si->major_version = 1; + si->minor_version = 1; + si->mediasize = sc->mediasize; + si->granularity = sc->granularity; + + smp_make_sign(si, sizeof *si, sc->ptr + sizeof *si); +} + +/*--------------------------------------------------------------------*/ + +static int +smp_valid_ident(struct smp_sc *sc) +{ + struct smp_ident *si; + + assert(strlen(SMP_IDENT_STRING) < sizeof si->ident); + si = (void*)sc->ptr; + if (strcmp(si->ident, SMP_IDENT_STRING)) + return (1); + if (si->byte_order != 0x12345678) + return (2); + if (si->size != sizeof *si) + return (3); + if (smp_check_sign(si, sizeof *si, sc->ptr + sizeof *si)) + return (4); + if (si->major_version != 1) + return (5); + if (si->minor_version != 1) + return (6); + if (si->mediasize != sc->mediasize) + return (7); + if (si->granularity != sc->granularity) + return (8); + return (0); +} + +/*--------------------------------------------------------------------*/ + +static void smp_init(struct stevedore *parent, int ac, char * const *av) { + struct smp_sc *sc; + int i; (void)parent; - (void)ac; - (void)av; + + AZ(av[ac]); assert(sizeof(struct smp_ident) == SMP_IDENT_SIZE); assert(sizeof(struct smp_object) == SMP_OBJECT_SIZE); + + /* Allocate softc */ + ALLOC_OBJ(sc, SMP_SC_MAGIC); + XXXAN(sc); + sc->fd = -1; + + /* Argument processing */ + if (ac != 2) + ARGV_ERR("(-spersistent) wrong number of arguments\n"); + + i = STV_GetFile(av[0], &sc->fd, &sc->filename, "-spersistent"); + if (i == 2) + ARGV_ERR("(-spersistent) need filename (not directory)\n"); + + sc->granularity = getpagesize(); + sc->mediasize = STV_FileSize(sc->fd, av[1], &sc->granularity, + "-spersistent"); + + AZ(ftruncate(sc->fd, sc->mediasize)); + + sc->ptr = mmap(NULL, sc->mediasize, PROT_READ|PROT_WRITE, + MAP_NOCORE | MAP_NOSYNC | MAP_SHARED, sc->fd, 0); + + if (sc->ptr == MAP_FAILED) + ARGV_ERR("(-spersistent) failed to mmap (%s)\n", + strerror(errno)); + + fprintf(stderr, "i = %d ms = %jd g = %u\n", + i, (intmax_t)sc->mediasize, sc->granularity); + + fprintf(stderr, "Silo: %d\n", smp_valid_ident(sc)); + smp_newsilo(sc); + fprintf(stderr, "Silo: %d\n", smp_valid_ident(sc)); + exit (2); } +/*--------------------------------------------------------------------*/ + struct stevedore smp_stevedore = { .magic = STEVEDORE_MAGIC, .name = "persistent", Modified: trunk/varnish-cache/include/persistent.h =================================================================== --- trunk/varnish-cache/include/persistent.h 2009-02-23 07:17:20 UTC (rev 3805) +++ trunk/varnish-cache/include/persistent.h 2009-02-23 10:07:51 UTC (rev 3806) @@ -81,6 +81,8 @@ #define SMP_IDENT_SIZE (32 + 4 + 4 + 4 + 4 + 8 + 4 ) +#define SMP_IDENT_STRING "Varnish Persistent Storage Silo" + /* * A segment descriptor. */ From phk at projects.linpro.no Mon Feb 23 10:46:08 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 23 Feb 2009 11:46:08 +0100 (CET) Subject: r3807 - trunk/varnish-cache/include Message-ID: <20090223104608.12FCE1F7530@projects.linpro.no> Author: phk Date: 2009-02-23 11:46:07 +0100 (Mon, 23 Feb 2009) New Revision: 3807 Modified: trunk/varnish-cache/include/vsha256.h Log: Add symbolic SHA256_LEN for the size of the digest. Modified: trunk/varnish-cache/include/vsha256.h =================================================================== --- trunk/varnish-cache/include/vsha256.h 2009-02-23 10:07:51 UTC (rev 3806) +++ trunk/varnish-cache/include/vsha256.h 2009-02-23 10:46:07 UTC (rev 3807) @@ -31,6 +31,8 @@ #include +#define SHA256_LEN 32 + typedef struct SHA256Context { uint32_t state[8]; uint64_t count; @@ -39,7 +41,7 @@ void SHA256_Init(SHA256_CTX *); void SHA256_Update(SHA256_CTX *, const void *, size_t); -void SHA256_Final(unsigned char [32], SHA256_CTX *); +void SHA256_Final(unsigned char [SHA256_LEN], SHA256_CTX *); void SHA256_Test(void); #endif /* !_SHA256_H_ */ From phk at projects.linpro.no Mon Feb 23 10:46:50 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 23 Feb 2009 11:46:50 +0100 (CET) Subject: r3808 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20090223104650.E628F38087@projects.linpro.no> Author: phk Date: 2009-02-23 11:46:50 +0100 (Mon, 23 Feb 2009) New Revision: 3808 Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c trunk/varnish-cache/include/persistent.h Log: Create/validate the three signed tables (ban1+2, segments) Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-02-23 10:46:07 UTC (rev 3807) +++ trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-02-23 10:46:50 UTC (rev 3808) @@ -54,6 +54,7 @@ const char *filename; off_t mediasize; unsigned granularity; + uint32_t unique; uint8_t *ptr; }; @@ -61,10 +62,13 @@ /*--------------------------------------------------------------------*/ static void -smp_make_sign(const void *ptr, off_t len, uint8_t *dest) +smp_make_hash(void *ptr, off_t len) { struct SHA256Context c; + unsigned char *dest; + dest = ptr; + dest += len; SHA256_Init(&c); SHA256_Update(&c, ptr, len); SHA256_Final(dest, &c); @@ -73,25 +77,68 @@ /*--------------------------------------------------------------------*/ static int -smp_check_sign(const void *ptr, off_t len, const void *sign) +smp_check_hash(void *ptr, off_t len) { struct SHA256Context c; - unsigned char nsign[32]; + unsigned char sign[SHA256_LEN]; + unsigned char *dest; + dest = ptr; + dest += len; SHA256_Init(&c); SHA256_Update(&c, ptr, len); - SHA256_Final(nsign, &c); - return(memcmp(sign, nsign, sizeof nsign)); + SHA256_Final(sign, &c); + return(memcmp(sign, dest, sizeof sign)); } /*--------------------------------------------------------------------*/ static void +smp_create_sign(struct smp_sc *sc, uint64_t adr, uint64_t len, const char *id) +{ + struct smp_sign *ss; + + AZ(adr & 0x7); /* Enforce alignment */ + + ss = (void*)(sc->ptr + adr); + memset(ss, 0, sizeof *ss); + assert(strlen(id) < sizeof ss->ident); + strcpy(ss->ident, id); + ss->unique = sc->unique; + ss->mapped = (uintptr_t)(sc->ptr + adr); + ss->length = len; + smp_make_hash(ss, sizeof *ss + len); +} + +/*--------------------------------------------------------------------*/ + +static int +smp_check_sign(struct smp_sc *sc, uint64_t adr, const char *id) +{ + struct smp_sign *ss; + + AZ(adr & 0x7); /* Enforce alignment */ + + ss = (void*)(sc->ptr + adr); + assert(strlen(id) < sizeof ss->ident); + if (strcmp(id, ss->ident)) + return (1); + if (ss->unique != sc->unique) + return (2); + return (smp_check_hash(ss, sizeof *ss + ss->length)); +} + +/*--------------------------------------------------------------------*/ + +static void smp_newsilo(struct smp_sc *sc) { struct smp_ident *si; assert(strlen(SMP_IDENT_STRING) < sizeof si->ident); + + sc->unique = random(); + si = (void*)sc->ptr; memset(si, 0, sizeof *si); strcpy(si->ident, SMP_IDENT_STRING); @@ -99,18 +146,29 @@ si->size = sizeof *si; si->major_version = 1; si->minor_version = 1; + si->unique = sc->unique; si->mediasize = sc->mediasize; si->granularity = sc->granularity; - smp_make_sign(si, sizeof *si, sc->ptr + sizeof *si); + /* XXX: intelligent sizing of things */ + si->stuff[SMP_BAN1_STUFF] = sc->granularity; + si->stuff[SMP_BAN2_STUFF] = si->stuff[SMP_BAN1_STUFF] + 1024*1024; + si->stuff[SMP_SEGS_STUFF] = si->stuff[SMP_BAN2_STUFF] + 1024*1024; + si->stuff[SMP_END_STUFF] = si->mediasize; + smp_create_sign(sc, si->stuff[SMP_BAN1_STUFF], 0, "BAN 1"); + smp_create_sign(sc, si->stuff[SMP_BAN2_STUFF], 0, "BAN 2"); + smp_create_sign(sc, si->stuff[SMP_SEGS_STUFF], 0, "SEGMENT"); + + smp_make_hash(si, sizeof *si); } /*--------------------------------------------------------------------*/ static int -smp_valid_ident(struct smp_sc *sc) +smp_valid_silo(struct smp_sc *sc) { struct smp_ident *si; + int i; assert(strlen(SMP_IDENT_STRING) < sizeof si->ident); si = (void*)sc->ptr; @@ -120,7 +178,7 @@ return (2); if (si->size != sizeof *si) return (3); - if (smp_check_sign(si, sizeof *si, sc->ptr + sizeof *si)) + if (smp_check_hash(si, sizeof *si)) return (4); if (si->major_version != 1) return (5); @@ -130,6 +188,25 @@ return (7); if (si->granularity != sc->granularity) return (8); + sc->unique = si->unique; + + /* XXX: Sanity check stuff[4] */ + + assert(si->stuff[0] > sizeof *si + SHA256_LEN); + assert(si->stuff[1] > si->stuff[0]); + assert(si->stuff[2] > si->stuff[1]); + assert(si->stuff[3] > si->stuff[2]); + assert(si->stuff[3] == sc->mediasize); + + i = smp_check_sign(sc, si->stuff[SMP_BAN1_STUFF], "BAN 1"); + if (i) + return (i + 10); + i = smp_check_sign(sc, si->stuff[SMP_BAN2_STUFF], "BAN 2"); + if (i) + return (i + 20); + i = smp_check_sign(sc, si->stuff[SMP_SEGS_STUFF], "SEGMENT"); + if (i) + return (i + 30); return (0); } @@ -144,7 +221,16 @@ (void)parent; AZ(av[ac]); +#define SZOF(foo) fprintf(stderr, \ + "sizeof(%s) = %zd = 0x%zx\n", #foo, sizeof(foo), sizeof(foo)); + SZOF(struct smp_ident); + SZOF(struct smp_sign); + SZOF(struct smp_segment); + SZOF(struct smp_object); +#undef SZOF + assert(sizeof(struct smp_ident) == SMP_IDENT_SIZE); + assert(sizeof(struct smp_sign) == SMP_SIGN_SIZE); assert(sizeof(struct smp_object) == SMP_OBJECT_SIZE); /* Allocate softc */ @@ -176,9 +262,10 @@ fprintf(stderr, "i = %d ms = %jd g = %u\n", i, (intmax_t)sc->mediasize, sc->granularity); - fprintf(stderr, "Silo: %d\n", smp_valid_ident(sc)); + fprintf(stderr, "Silo: %d\n", smp_valid_silo(sc)); smp_newsilo(sc); - fprintf(stderr, "Silo: %d\n", smp_valid_ident(sc)); + fprintf(stderr, "Silo: %d\n", smp_valid_silo(sc)); + AZ(smp_valid_silo(sc)); exit (2); } Modified: trunk/varnish-cache/include/persistent.h =================================================================== --- trunk/varnish-cache/include/persistent.h 2009-02-23 10:46:07 UTC (rev 3807) +++ trunk/varnish-cache/include/persistent.h 2009-02-23 10:46:50 UTC (rev 3808) @@ -71,19 +71,37 @@ uint32_t minor_version; + uint32_t unique; + uint64_t mediasize; /* ... in bytes */ uint32_t granularity; /* smallest ... in bytes */ - /* XXX: ptr to bans table */ - /* XXX: ptr to segment table */ + uint64_t stuff[4]; /* pointers to stuff */ +#define SMP_BAN1_STUFF 0 +#define SMP_BAN2_STUFF 1 +#define SMP_SEGS_STUFF 2 +#define SMP_END_STUFF 3 }; -#define SMP_IDENT_SIZE (32 + 4 + 4 + 4 + 4 + 8 + 4 ) +#define SMP_IDENT_SIZE (32 + 4 + 4 + 4 + 4 + 4 + 8 + 4 + 4 * 8) #define SMP_IDENT_STRING "Varnish Persistent Storage Silo" /* + * This is used to sign various bits on the disk. + */ + +struct smp_sign { + char ident[8]; + uint32_t unique; + uint64_t mapped; + uint64_t length; +}; + +#define SMP_SIGN_SIZE (8 + 4 + 8 + 8 + 32) + +/* * A segment descriptor. */ From phk at projects.linpro.no Mon Feb 23 11:04:19 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 23 Feb 2009 12:04:19 +0100 (CET) Subject: r3809 - trunk/varnish-cache/bin/varnishd Message-ID: <20090223110419.567E938653@projects.linpro.no> Author: phk Date: 2009-02-23 12:04:19 +0100 (Mon, 23 Feb 2009) New Revision: 3809 Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c Log: A bit of FlexeLint nitpicking Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-02-23 10:46:50 UTC (rev 3808) +++ trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-02-23 11:04:19 UTC (rev 3809) @@ -94,7 +94,7 @@ /*--------------------------------------------------------------------*/ static void -smp_create_sign(struct smp_sc *sc, uint64_t adr, uint64_t len, const char *id) +smp_create_sign(const struct smp_sc *sc, uint64_t adr, uint64_t len, const char *id) { struct smp_sign *ss; @@ -113,7 +113,7 @@ /*--------------------------------------------------------------------*/ static int -smp_check_sign(struct smp_sc *sc, uint64_t adr, const char *id) +smp_check_sign(const struct smp_sc *sc, uint64_t adr, const char *id) { struct smp_sign *ss; @@ -221,13 +221,13 @@ (void)parent; AZ(av[ac]); -#define SZOF(foo) fprintf(stderr, \ - "sizeof(%s) = %zd = 0x%zx\n", #foo, sizeof(foo), sizeof(foo)); - SZOF(struct smp_ident); - SZOF(struct smp_sign); - SZOF(struct smp_segment); - SZOF(struct smp_object); -#undef SZOF +#define SIZOF(foo) fprintf(stderr, \ + "sizeof(%s) = %zu = 0x%zx\n", #foo, sizeof(foo), sizeof(foo)); + SIZOF(struct smp_ident); + SIZOF(struct smp_sign); + SIZOF(struct smp_segment); + SIZOF(struct smp_object); +#undef SIZOF assert(sizeof(struct smp_ident) == SMP_IDENT_SIZE); assert(sizeof(struct smp_sign) == SMP_SIGN_SIZE); From phk at projects.linpro.no Mon Feb 23 11:07:06 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 23 Feb 2009 12:07:06 +0100 (CET) Subject: r3810 - trunk/varnish-cache/include Message-ID: <20090223110706.4B2AC38653@projects.linpro.no> Author: phk Date: 2009-02-23 12:07:06 +0100 (Mon, 23 Feb 2009) New Revision: 3810 Modified: trunk/varnish-cache/include/persistent.h Log: The SHA256 is outside the signature struct Modified: trunk/varnish-cache/include/persistent.h =================================================================== --- trunk/varnish-cache/include/persistent.h 2009-02-23 11:04:19 UTC (rev 3809) +++ trunk/varnish-cache/include/persistent.h 2009-02-23 11:07:06 UTC (rev 3810) @@ -99,7 +99,7 @@ uint64_t length; }; -#define SMP_SIGN_SIZE (8 + 4 + 8 + 8 + 32) +#define SMP_SIGN_SIZE (8 + 4 + 8 + 8) /* * A segment descriptor. From phk at projects.linpro.no Mon Feb 23 11:31:09 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 23 Feb 2009 12:31:09 +0100 (CET) Subject: r3811 - trunk/varnish-cache/bin/varnishd Message-ID: <20090223113109.1BE8A1F7533@projects.linpro.no> Author: phk Date: 2009-02-23 12:31:08 +0100 (Mon, 23 Feb 2009) New Revision: 3811 Modified: trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/bin/varnishd/storage_persistent.c Log: Move on to the worker process side of persistent storage Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2009-02-23 11:07:06 UTC (rev 3810) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2009-02-23 11:31:08 UTC (rev 3811) @@ -60,6 +60,7 @@ stv_next = stv; /* try to allocate from it */ + AN(stv->alloc); st = stv->alloc(stv, size); if (st != NULL) break; Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-02-23 11:07:06 UTC (rev 3810) +++ trunk/varnish-cache/bin/varnishd/storage_persistent.c 2009-02-23 11:31:08 UTC (rev 3811) @@ -28,6 +28,9 @@ * $Id$ * * Persistent storage method + * + * XXX: Before we start the client or maybe after it stops, we should give the + * XXX: stevedores a chance to examine their storage for consistency. */ #include "config.h" @@ -266,7 +269,11 @@ smp_newsilo(sc); fprintf(stderr, "Silo: %d\n", smp_valid_silo(sc)); AZ(smp_valid_silo(sc)); - exit (2); + + parent->priv = sc; + + /* XXX: only for sendfile I guess... */ + mgt_child_inherit(sc->fd, "storage_persistent"); } /*--------------------------------------------------------------------*/ From petter at projects.linpro.no Mon Feb 23 12:44:13 2009 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Mon, 23 Feb 2009 13:44:13 +0100 (CET) Subject: r3812 - trunk/varnish-tools/webgui/Varnish Message-ID: <20090223124413.E5F0C38B95@projects.linpro.no> Author: petter Date: 2009-02-23 13:44:13 +0100 (Mon, 23 Feb 2009) New Revision: 3812 Modified: trunk/varnish-tools/webgui/Varnish/DB.pm trunk/varnish-tools/webgui/Varnish/Statistics.pm Log: Fetching ALL the columns when generating graphs is stupid and time consuming. Now we only fetch the required fields. Modified: trunk/varnish-tools/webgui/Varnish/DB.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/DB.pm 2009-02-23 11:31:08 UTC (rev 3811) +++ trunk/varnish-tools/webgui/Varnish/DB.pm 2009-02-23 12:44:13 UTC (rev 3812) @@ -56,7 +56,7 @@ push @field_values, $value; } else { - print STDERR "Field $db_field does not exist in the stat table. Please update schema\n"; + print STDERR "Field $db_field does not exist in the stat table. Please update schema by running create_db_data.pl\n"; } } } @@ -71,21 +71,25 @@ } sub get_stat_data { - my ($self, $unit, $after_timestamp) = @_; + my ($self, $unit, $after_timestamp, $stat_fields_ref) = @_; + if (!defined($stat_fields_ref)) { + my @stat_fields = keys(%stat_field_exist); + + $stat_fields_ref = \@stat_fields; + } + my $sql; if (ref($unit) eq "Varnish::Node") { $sql = "SELECT time, has_data"; - my @stat_fields = keys %stat_field_exist; - for my $stat_field (@stat_fields) { + for my $stat_field (@$stat_fields_ref) { $sql .=", $stat_field"; } $sql .= " FROM stat WHERE node_id = ? AND time > ? ORDER BY time ASC"; } else { $sql = "SELECT time, SUM(has_data) as has_data"; - my @stat_fields = keys %stat_field_exist; - for my $stat_field (@stat_fields) { + for my $stat_field (@$stat_fields_ref) { $sql .=", SUM($stat_field) AS $stat_field"; } $sql .= " FROM stat WHERE node_id IN (SELECT id FROM node WHERE group_id = ?) AND time >= ? GROUP BY time ORDER BY time ASC"; Modified: trunk/varnish-tools/webgui/Varnish/Statistics.pm =================================================================== --- trunk/varnish-tools/webgui/Varnish/Statistics.pm 2009-02-23 11:31:08 UTC (rev 3811) +++ trunk/varnish-tools/webgui/Varnish/Statistics.pm 2009-02-23 12:44:13 UTC (rev 3812) @@ -55,6 +55,12 @@ return (undef, undef); } } + + sub _union { + my %temp_hash = map { $_ => 1 } @_; + + return keys %temp_hash; + } sub generate_graph_data { my ($self, $unit_id, $is_node, $time_span, $divisors_ref, $dividends_ref, $use_delta, $desired_number_of_values) = @_; @@ -73,23 +79,26 @@ if ($use_delta) { $start_time -= $poll_interval; } + + my @divisors = ($divisors_ref ? + map { get_db_friendly_name($_); } @$divisors_ref : ()); + my @dividends = ($dividends_ref ? + map { get_db_friendly_name($_); } @$dividends_ref : ()); + my @all_fields = _union(@dividends, @divisors); my $measures_ref; if ($is_node) { my $node = Varnish::NodeManager->get_node($unit_id); return ([],[], -1, -1) if (!$node); - $measures_ref = Varnish::DB->get_stat_data($node, $start_time); + $measures_ref = Varnish::DB->get_stat_data($node, $start_time, \@all_fields); } else { my $group = Varnish::NodeManager->get_group($unit_id); return ([],[], -1, -1) if (!$group); - $measures_ref = Varnish::DB->get_stat_data($group, $start_time); + $measures_ref = Varnish::DB->get_stat_data($group, $start_time, \@all_fields); } - my @divisors = ($divisors_ref ? - map { get_db_friendly_name($_); } @$divisors_ref : ()); - my @dividends = ($dividends_ref ? - map { get_db_friendly_name($_); } @$dividends_ref : ()); + my @values; my @times; my $value2; From petter at projects.linpro.no Mon Feb 23 13:42:32 2009 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Mon, 23 Feb 2009 14:42:32 +0100 (CET) Subject: r3813 - trunk/varnish-tools/webgui Message-ID: <20090223134232.D70E338B95@projects.linpro.no> Author: petter Date: 2009-02-23 14:42:32 +0100 (Mon, 23 Feb 2009) New Revision: 3813 Modified: trunk/varnish-tools/webgui/start.pl Log: Fixed issue with response not containing correct headers. CSS was sent as text/plain, causing firefox to ignore it. Modified: trunk/varnish-tools/webgui/start.pl =================================================================== --- trunk/varnish-tools/webgui/start.pl 2009-02-23 12:44:13 UTC (rev 3812) +++ trunk/varnish-tools/webgui/start.pl 2009-02-23 13:42:32 UTC (rev 3813) @@ -75,10 +75,19 @@ $connection->force_last_request; # print "Request for: " . $request->uri . "\n"; if ($request->uri =~ m{/(.*?\.png)} || - $request->uri =~ m{/(.*?\.css)} || $request->uri =~ m{/(.*?\.ico)}) { my $filename = $1; + $connection->send_file_response($filename); + next REQUEST; + } + elsif ($request->uri =~ m{/(.*?\.css)}) { + my $filename = $1; + + $connection->send_basic_header(); + print $connection "Content-Type: text/css"; + $connection->send_crlf(); + $connection->send_crlf(); $connection->send_file($filename); next REQUEST; } From petter at projects.linpro.no Mon Feb 23 13:43:06 2009 From: petter at projects.linpro.no (petter at projects.linpro.no) Date: Mon, 23 Feb 2009 14:43:06 +0100 (CET) Subject: r3814 - trunk/varnish-tools/webgui/templates Message-ID: <20090223134306.599DA38B95@projects.linpro.no> Author: petter Date: 2009-02-23 14:43:06 +0100 (Mon, 23 Feb 2009) New Revision: 3814 Modified: trunk/varnish-tools/webgui/templates/master.tmpl Log: Minor HTML-clean ups Modified: trunk/varnish-tools/webgui/templates/master.tmpl =================================================================== --- trunk/varnish-tools/webgui/templates/master.tmpl 2009-02-23 13:42:32 UTC (rev 3813) +++ trunk/varnish-tools/webgui/templates/master.tmpl 2009-02-23 13:43:06 UTC (rev 3814) @@ -3,7 +3,7 @@ - + @@ -13,7 +13,7 @@