From martin at varnish-software.com Wed Aug 2 10:01:12 2017 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Wed, 02 Aug 2017 12:01:12 +0200 Subject: [master] 09731b2 Correctly handle bogusly large chunk sizes Message-ID: commit 09731b24b2225e3c0d66d3ec1b4fedef6fa22b6e Author: Martin Blix Grydeland Date: Thu Jul 27 11:52:58 2017 +0200 Correctly handle bogusly large chunk sizes This fixes a denial of service attack vector where bogusly large chunk sizes in requests could be used to force restarts of the Varnish server. This is Varnish Security Vulnerability VSV00001 For more information visit: https://varnish-cache.org/security/VSV00001 Fixes: #2379 diff --git a/bin/varnishd/http1/cache_http1_vfp.c b/bin/varnishd/http1/cache_http1_vfp.c index 715a110..e57262c 100644 --- a/bin/varnishd/http1/cache_http1_vfp.c +++ b/bin/varnishd/http1/cache_http1_vfp.c @@ -152,7 +152,7 @@ v1f_pull_chunked(struct vfp_ctx *vc, struct vfp_entry *vfe, void *ptr, if (q == NULL || *q != '\0') return (VFP_Error(vc, "chunked header number syntax")); cl = (ssize_t)cll; - if ((uintmax_t)cl != cll) + if (cl < 0 || (uintmax_t)cl != cll) return (VFP_Error(vc, "bogusly large chunk size")); vfe->priv2 = cl; diff --git a/bin/varnishtest/tests/f00001.vtc b/bin/varnishtest/tests/f00001.vtc new file mode 100644 index 0000000..dc9fd9b --- /dev/null +++ b/bin/varnishtest/tests/f00001.vtc @@ -0,0 +1,40 @@ +varnishtest "Check that we handle bogusly large chunks correctly" + +# Check that the bug has been fixed + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { +} -start + +client c1 { + send "POST / HTTP/1.1\r\n" + send "Transfer-Encoding: chunked\r\n\r\n" + send "FFFFFFFFFFFFFFED\r\n" + send "0\r\n\r\n" + + rxresp + expect resp.status == 503 +} -run + +# Check that the published workaround does not cause harm + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.http.transfer-encoding ~ "(?i)chunked") { + return (fail); + } + } +} + +client c1 { + send "POST / HTTP/1.1\r\n" + send "Transfer-Encoding: chunked\r\n\r\n" + send "FFFFFFFFFFFFFFED\r\n" + + rxresp + expect resp.status == 503 +} -run From phk at FreeBSD.org Wed Aug 2 10:01:12 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 02 Aug 2017 12:01:12 +0200 Subject: [master] 9ab6a53 VSV0001 rant Message-ID: commit 9ab6a531918312f35d2ecb0b506ebf8fa56f43b9 Author: Poul-Henning Kamp Date: Wed Aug 2 10:00:39 2017 +0000 VSV0001 rant diff --git a/doc/sphinx/phk/VSV00001.rst b/doc/sphinx/phk/VSV00001.rst new file mode 100644 index 0000000..69e1503 --- /dev/null +++ b/doc/sphinx/phk/VSV00001.rst @@ -0,0 +1,179 @@ +.. _phk_vsv00001: + +Yah! A security issue - finally! +================================= + +As embarrased as I am to find out that after 35 years of writing +C-programs I *still* dont understand signed/unsigned variables, I +am also incredibly proud that it took eleven years before Varnish +had a major security incident. + +One side-effect of this episode is that the ink is still wet on +most of the policies for handling security issues in the Varnish +Project. + +We are, in the inimitable words of Amanda F. Palmer, +*"guilty of making shit up as you go along."* + +So here is what we made up: + +VWV - Vulnerability Workaround in VCL +------------------------------------- + +Rolling a new Varnish release, even with an trivial one-line patch +is not a fast operation, getting from patch to packages rolled and +pushed into operating system respositories takes at least several +days, provided you can get everybodys attention. + +Being able to offer users a way to mitigate security issues in VCL +bypasses all that red tape: The moment you have the advisory in +hand, you can defend your Varnish instance. + +VCL mititation will always be our priority number one. + +WLIC - We Love Inline C +----------------------- + +Brian W. Kernighan famously said that `he didn't like the +programming language PASCAL `_ +because *"There is no escape."* + +That quote is why Varnish got inline-C code from day one, to make sure +there would always be an escape. + +However, recently we have been wondering if we should discontinue +inline-C code, now that we have the much nicer and more structured +VMOD facility. + +Well, that's all settled now: Inline-C stays, because it enabled us +to craft the VCL-snippets to mitigate this "deep-code" security issue. + +VSV - Varnish Security Vulnerability +------------------------------------ + +To my utter surprise, I could not get an embargoed CVE number, +without having to reveal what was going on. + +There are good and sane reasons for that, and I harbour no +ill feelings against the people who refused. Their policies +need to target the really buggy software, and history has +shown that to be anything but easy. + +But being unable to get a CVE number when we needed one, left us +without a handle, and there being no signs that this was a fluke, +we decided to start our own numbering of Varnish Security +Vulnerabilities. + +We are starting from VSV number 1, as this one is the first real +flag day for us, and we have reserved VTC testnames `f%05d` to +go with it. + +Five digits should be enough for everybody. + +As soon as possible, if possible, we will of course try to get a +unique CVE number attached to each VSV, but the VSV will be +our own primary handle. + +VIVU - Very Important Varnish Users +----------------------------------- + +I have been struggling with this problem for a long time, because +sooner or later we would hit this event. + +Clearly some people deserve to get an early heads-up on +security advisories, but who ? + +Any list big enough to be fair would also be too easy to sneak into +for people who should not be on it. + +Such a list would also be a major head-ache for us to maintain, not +to mention setting and judging the qualification criteria, and +dealing with appeals from the ones we rejected. + +Instead I have decided that we are simply going to follow the money. + +People and companies who paid at least ?1000 for a `Varnish Moral +License `_ in the 12 months before the +publication date, get advance warning of our security advisories. + +Those ?1000 per year goes almost [#f1]_ 100% to maintain, develop and +improve Varnish, so even if there are no security advisories, the +money will be well spent beneficially for a Varnish user. + +Of course nothing prevents Wile E. Hacker from also paying ?1000 +every year to receive advance notice, but I suspect it would sting +a bit to know that your own money is being used to prevent the event +you are gambling on - and that it might take eleven years for the +ball to stop. + +But we will *also* maintain a VIVU-list, for people and companies +who contribute materially to the Varnish Project in some way, +(documentation, code, machines, testing, meeting-rooms...) or +people we judge should be there for some other good reason. + +If you feel you should be on the VIVU list, drop me an email, +don't forget to include your PGP key. + +VQS - Varnish Quality Software +------------------------------ + +From the very first line of code, Varnish has also been a software +quality experiment, I wanted to show the world that software +does not have to suck. + +Strange as it sounds, now that we finally had a major security +issue, I feel kind of vindicated, in a strange kind of *"The house +burned down but I'm happy to know that the fire-alarm did work"* +kind of way. + +We have had some CVE's before, but none of them were major issues. + +The closest was probably +`CVE-2013-4484 `_ +four years ago, which in many ways was like VSV00001, but it only affected users +with a not so common VCL construct. + +VSV00001 on the other hand exposes all contemporary Varnishes, +it doesn't get any more major than that. + +But it took eleven years [#f2]_ to get to that point, primarily +because Varnish is a software quality experiment. + +How unusual our level of software quality is, was brought home by +the response to my request for a CVE number under embargo: +*"I can do an embargoed CVE, but I'm not comfortable assigning one +blindly to someone who doesn't have a history of requesting them."* +- that sounds like praise by faint damnation to me. + +Anyway, I will not promise that we will have no major security +issues until the year 2028, but I'll do my damnest to make it so. + +VDR - Varnish Developers Rock +----------------------------- + +When this issue surfaced I had contractors and moving boxes all +around me and barely had workable internet connectivity in the new +house. + +The usual gang of Varnish developers did a smashing job, largely on +their own, and I am incredibly thankful for that. + +Much appreciated guys! + +And also a big round of thanks to the sponsors and VML contributors +who have had patience with me trying to do the right thing, even +if it took a while longer: I hope you agree that it has been +worth it. + +*phk* + +PS: This was written before the public announcement. + +.. rubric:: Footnotes + +.. [#f1] There is practically no overhead on the VML, only the banking + fees to receive the payments. + +.. [#f2] It can be argued that we should only count until the bug was + introduced in the codebase, rather than until it was discovered. + In that case it is not eleven years but "only" eight years. diff --git a/doc/sphinx/phk/index.rst b/doc/sphinx/phk/index.rst index 8dd4f13..8f21795 100644 --- a/doc/sphinx/phk/index.rst +++ b/doc/sphinx/phk/index.rst @@ -8,6 +8,7 @@ You may or may not want to know what Poul-Henning thinks. .. toctree:: :maxdepth: 1 + VSV00001.rst somethinghappened.rst trialerror.rst farfaraway.rst From hermunn at varnish-software.com Wed Aug 2 10:02:06 2017 From: hermunn at varnish-software.com (Pål Hermunn Johansen) Date: Wed, 02 Aug 2017 12:02:06 +0200 Subject: [4.0] 138015a Correctly handle bogusly large chunk sizes Message-ID: commit 138015a3a5251da2ce56389435fe046c4b7da135 Author: Martin Blix Grydeland Date: Thu Jul 27 11:52:58 2017 +0200 Correctly handle bogusly large chunk sizes This fixes a denial of service attack vector where bogusly large chunk sizes in requests could be used to force restarts of the Varnish server. This is Varnish Security Vulnerability VSV00001 For more information visit: https://varnish-cache.org/security/VSV00001 Fixes: #2379 diff --git a/bin/varnishd/cache/cache_http1_proto.c b/bin/varnishd/cache/cache_http1_proto.c index 1142011..a6ff014 100644 --- a/bin/varnishd/cache/cache_http1_proto.c +++ b/bin/varnishd/cache/cache_http1_proto.c @@ -586,7 +586,7 @@ HTTP1_Chunked(struct http_conn *htc, intptr_t *priv, const char **error, if (q == NULL || *q != '\0') ERR("chunked header number syntax"); cl = (ssize_t)cll; - if((uintmax_t)cl != cll) + if (cl < 0 || (uintmax_t)cl != cll) ERR("bogusly large chunk size"); *priv = cl; diff --git a/bin/varnishtest/tests/f00001.vtc b/bin/varnishtest/tests/f00001.vtc new file mode 100644 index 0000000..32d54f7 --- /dev/null +++ b/bin/varnishtest/tests/f00001.vtc @@ -0,0 +1,83 @@ +varnishtest "Check that we handle bogusly large chunks correctly" + +# Check that the bug has been fixed + +server s1 { + rxreq + txresp + + accept + rxreq + txresp +} -start + +varnish v1 -vcl+backend { +} -start + +client c1 { + send "POST / HTTP/1.1\r\n" + send "Transfer-Encoding: chunked\r\n\r\n" + send "FFFFFFFFFFFFFFED\r\n" + send "0\r\n\r\n" + + rxresp + expect resp.status == 503 +} -run + +# Check that the published workaround does not cause harm + +varnish v1 -cliok "param.set vcc_allow_inline_c true" + +varnish v1 -vcl+backend { + sub exploit_workaround { + # This needs to be defined before your vcl_recv function + # Make sure that the runtime parameter vcc_allow_inline_c is set to true + # This code is only valid with version 4.0 of Varnish Cache + if (req.http.transfer-encoding ~ "(?i)chunked") { + C{ + struct dummy_req { + unsigned magic; + int restarts; + int esi_level; + int disable_esi; + char hash_ignore_busy; + char hash_always_miss; + void *sp; + void *wrk; + int req_step; + struct { + void * a; + void * b; + }; + int req_body_status; + }; + ((struct dummy_req *)ctx->req)->req_body_status = 6; + }C + + return (synth(503, "Bad request")); + } + } + + sub vcl_recv { + # Call this early in your vcl_recv function + call exploit_workaround; + } +} + +client c1 { + send "POST / HTTP/1.1\r\n" + send "Transfer-Encoding: chunked\r\n\r\n" + send "FFFFFFFFFFFFFFED\r\n" + send "0\r\n\r\n" + + rxresp + expect resp.status == 400 +} -run + +# Make sure that varnish is still running + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run diff --git a/doc/changes.rst b/doc/changes.rst index f663c45..50d9fc7 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -1,3 +1,14 @@ +======================================== +Changes from 4.0.4 to 4.0.5 (unreleased) +======================================== + +Bugs fixed +---------- + +* 2379_ - Correctly handle bogusly large chunk sizes (VSV00001) + +.. _2379: https://github.com/varnishcache/varnish-cache/issues/2379 + ============================================== Changes from 4.0.4-beta1 to 4.0.4 (2016-11-30) ============================================== From hermunn at varnish-software.com Wed Aug 2 10:02:06 2017 From: hermunn at varnish-software.com (Pål Hermunn Johansen) Date: Wed, 02 Aug 2017 12:02:06 +0200 Subject: [4.0] 07eff4c Prepare for 4.0.5 release Message-ID: commit 07eff4c29d0ffd51cbd087480b8725914da77f2a Author: P?l Hermunn Johansen Date: Tue Aug 1 12:48:42 2017 +0200 Prepare for 4.0.5 release diff --git a/configure.ac b/configure.ac index 886e645..576949d 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2006 Verdens Gang AS Copyright (c) 2006-2016 Varnish Software AS]) AC_REVISION([$Id$]) -AC_INIT([Varnish], [4.0.4], [varnish-dev at varnish-cache.org]) +AC_INIT([Varnish], [4.0.5], [varnish-dev at varnish-cache.org]) AC_CONFIG_SRCDIR(include/miniobj.h) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/doc/changes.rst b/doc/changes.rst index 50d9fc7..6aa5139 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -1,5 +1,5 @@ ======================================== -Changes from 4.0.4 to 4.0.5 (unreleased) +Changes from 4.0.4 to 4.0.5 (2017-08-02) ======================================== Bugs fixed From hermunn at varnish-software.com Wed Aug 2 10:03:06 2017 From: hermunn at varnish-software.com (Pål Hermunn Johansen) Date: Wed, 02 Aug 2017 12:03:06 +0200 Subject: [5.1] c8a4411 Correctly handle bogusly large chunk sizes Message-ID: commit c8a4411527a2dbce0fa9f1998dc0cd2d8314d126 Author: Martin Blix Grydeland Date: Thu Jul 27 11:52:58 2017 +0200 Correctly handle bogusly large chunk sizes This fixes a denial of service attack vector where bogusly large chunk sizes in requests could be used to force restarts of the Varnish server. This is Varnish Security Vulnerability VSV00001 For more information visit: https://varnish-cache.org/security/VSV00001 Fixes: #2379 diff --git a/bin/varnishd/http1/cache_http1_vfp.c b/bin/varnishd/http1/cache_http1_vfp.c index 715a110..e57262c 100644 --- a/bin/varnishd/http1/cache_http1_vfp.c +++ b/bin/varnishd/http1/cache_http1_vfp.c @@ -152,7 +152,7 @@ v1f_pull_chunked(struct vfp_ctx *vc, struct vfp_entry *vfe, void *ptr, if (q == NULL || *q != '\0') return (VFP_Error(vc, "chunked header number syntax")); cl = (ssize_t)cll; - if ((uintmax_t)cl != cll) + if (cl < 0 || (uintmax_t)cl != cll) return (VFP_Error(vc, "bogusly large chunk size")); vfe->priv2 = cl; diff --git a/bin/varnishtest/tests/f00001.vtc b/bin/varnishtest/tests/f00001.vtc new file mode 100644 index 0000000..dc9fd9b --- /dev/null +++ b/bin/varnishtest/tests/f00001.vtc @@ -0,0 +1,40 @@ +varnishtest "Check that we handle bogusly large chunks correctly" + +# Check that the bug has been fixed + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { +} -start + +client c1 { + send "POST / HTTP/1.1\r\n" + send "Transfer-Encoding: chunked\r\n\r\n" + send "FFFFFFFFFFFFFFED\r\n" + send "0\r\n\r\n" + + rxresp + expect resp.status == 503 +} -run + +# Check that the published workaround does not cause harm + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.http.transfer-encoding ~ "(?i)chunked") { + return (fail); + } + } +} + +client c1 { + send "POST / HTTP/1.1\r\n" + send "Transfer-Encoding: chunked\r\n\r\n" + send "FFFFFFFFFFFFFFED\r\n" + + rxresp + expect resp.status == 503 +} -run diff --git a/doc/changes.rst b/doc/changes.rst index 41d83d0..42637d7 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -1,4 +1,15 @@ ================================ +Varnish Cache 5.1.3 (unreleased) +================================ + +Bugs fixed +---------- + +* 2379_ - Correctly handle bogusly large chunk sizes (VSV00001) + +.. _2379: https://github.com/varnishcache/varnish-cache/issues/2379 + +================================ Varnish Cache 5.1.2 (2017-04-07) ================================ From hermunn at varnish-software.com Wed Aug 2 10:03:06 2017 From: hermunn at varnish-software.com (Pål Hermunn Johansen) Date: Wed, 02 Aug 2017 12:03:06 +0200 Subject: [5.1] 05c5ac6 Prepare for 5.1.3 release Message-ID: commit 05c5ac6b90cf8114f897046bdaacc68dc57e9aac Author: P?l Hermunn Johansen Date: Tue Aug 1 13:07:59 2017 +0200 Prepare for 5.1.3 release diff --git a/configure.ac b/configure.ac index 4f9b4f2..66e47ec 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2006 Verdens Gang AS Copyright (c) 2006-2017 Varnish Software]) AC_REVISION([$Id$]) -AC_INIT([Varnish], [5.1.2], [varnish-dev at varnish-cache.org]) +AC_INIT([Varnish], [5.1.3], [varnish-dev at varnish-cache.org]) AC_CONFIG_SRCDIR(include/miniobj.h) AC_CONFIG_HEADERS([config.h]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/doc/changes.rst b/doc/changes.rst index 42637d7..5cc9c89 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -1,5 +1,5 @@ ================================ -Varnish Cache 5.1.3 (unreleased) +Varnish Cache 5.1.3 (2017-08-02) ================================ Bugs fixed From varnish-commit at varnish-cache.org Thu Aug 3 15:30:57 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: Thu, 03 Aug 2017 19:30:57 +0400 Subject: Hello! Message-ID: <598341B1.4090701@varnish-cache.org> i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Anastasiya82 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Fri Aug 4 12:10:48 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: Fri, 04 Aug 2017 13:10:48 +0100 Subject: taste my @ss! Message-ID: <59846448.2030205@varnish-cache.org> i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Gyliane62 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Fri Aug 4 10:07:53 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 4 Aug 2017 06:07:53 -0400 Subject: I burn with passion Message-ID: i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Dian99 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From phk at FreeBSD.org Fri Aug 4 16:22:11 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 04 Aug 2017 18:22:11 +0200 Subject: [master] 1be486c Typo Message-ID: commit 1be486cf7876217e8eff0878d2fd70530c201693 Author: Poul-Henning Kamp Date: Fri Aug 4 16:21:35 2017 +0000 Typo diff --git a/doc/sphinx/phk/VSV00001.rst b/doc/sphinx/phk/VSV00001.rst index 69e1503..70d69b7 100644 --- a/doc/sphinx/phk/VSV00001.rst +++ b/doc/sphinx/phk/VSV00001.rst @@ -29,7 +29,7 @@ Being able to offer users a way to mitigate security issues in VCL bypasses all that red tape: The moment you have the advisory in hand, you can defend your Varnish instance. -VCL mititation will always be our priority number one. +VCL mitigation will always be our priority number one. WLIC - We Love Inline C ----------------------- From varnish-commit at varnish-cache.org Fri Aug 4 12:42:41 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 4 Aug 2017 06:42:41 -0600 Subject: I burn with passion Message-ID: i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Claudy43 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Sat Aug 5 12:04:33 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: Sat, 05 Aug 2017 18:04:33 +0600 Subject: hot g!rl want you! Message-ID: <5985B451.2030801@varnish-cache.org> i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Ulia54 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Sat Aug 5 12:50:51 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 5 Aug 2017 14:50:51 +0200 Subject: Hi! Message-ID: <5985C4CB.1697.62A75F@varnish-commit.varnish-cache.org> i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Sofia31 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From nils.goroll at uplex.de Sat Aug 5 11:48:10 2017 From: nils.goroll at uplex.de (Nils Goroll) Date: Sat, 05 Aug 2017 13:48:10 +0200 Subject: [master] d909232 wrap VSC_lck_Destroy as Lck_DestroyClass for cache.h dependend vmods Message-ID: commit d909232d803b23ac02d69b245483277910faf120 Author: Nils Goroll Date: Sat Aug 5 13:26:16 2017 +0200 wrap VSC_lck_Destroy as Lck_DestroyClass for cache.h dependend vmods diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 86410bd..87338d8 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -839,6 +839,7 @@ int Lck_CondWait(pthread_cond_t *cond, struct lock *lck, double); } while (0) struct VSC_lck *Lck_CreateClass(const char *name); +void Lck_DestroyClass(struct VSC_lck **vsclck); #define LOCK(nam) extern struct VSC_lck *lck_##nam; #include "tbl/locks.h" diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c index eb39cbd..52cec50 100644 --- a/bin/varnishd/cache/cache_lck.c +++ b/bin/varnishd/cache/cache_lck.c @@ -250,6 +250,12 @@ Lck_CreateClass(const char *name) return(VSC_lck_New(name)); } +void +Lck_DestroyClass(struct VSC_lck **vsclck) +{ + VSC_lck_Destroy(vsclck); +} + #define LOCK(nam) struct VSC_lck *lck_##nam; #include "tbl/locks.h" From varnish-commit at varnish-cache.org Sun Aug 6 02:24:33 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 6 Aug 2017 09:24:33 +0700 Subject: want hot night? Message-ID: <9C143809E9B025D8507C4DADF4619C14@GW309WR62> i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Verona61 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Sat Aug 5 22:47:51 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 5 Aug 2017 23:47:51 +0100 Subject: my p*ssy is wet Message-ID: <004901d30e41$055ff071$d77b4ca8$@varnish-cache.org> i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Ani22 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Sat Aug 5 18:02:34 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 5 Aug 2017 14:02:34 -0400 Subject: hot g!rl want you! Message-ID: i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Nastenka19 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Sun Aug 6 11:24:12 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 6 Aug 2017 17:24:12 +0600 Subject: I burn with passion Message-ID: i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Dian72 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Mon Aug 7 01:20:20 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 7 Aug 2017 07:20:20 +0600 Subject: want hot night? Message-ID: <2B858A06A724092B858A06A724092B85@OT8HWNDOT8> i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Sveetlana41 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Mon Aug 7 13:38:30 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 7 Aug 2017 15:38:30 +0200 Subject: Hello! Message-ID: <08856E8FDAE3643BB65DBCE9D0570885@NXUXU961> i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Viktori11 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From fgsch at lodoss.net Mon Aug 7 12:07:10 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 07 Aug 2017 14:07:10 +0200 Subject: [4.1] 32fceb3 VSC n_vcl, n_vcl_avail, n_vcl_discard are gauge Message-ID: commit 32fceb3bd3922a52d536a12b77e8c7e1d3d49198 Author: Federico G. Schwindt Date: Mon Aug 7 13:02:32 2017 +0100 VSC n_vcl, n_vcl_avail, n_vcl_discard are gauge From Emmanuel Hocdet (manu-at-gandi-dot-net) via #2373. diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h index ab926d9..c3b53bd 100644 --- a/include/tbl/vsc_f_main.h +++ b/include/tbl/vsc_f_main.h @@ -442,15 +442,15 @@ VSC_F(backend_req, uint64_t, 0, 'c', 'i', info, /*--------------------------------------------------------------------*/ -VSC_F(n_vcl, uint64_t, 0, 'c', 'i', info, +VSC_F(n_vcl, uint64_t, 0, 'g', 'i', info, "Number of loaded VCLs in total", "" ) -VSC_F(n_vcl_avail, uint64_t, 0, 'c', 'i', diag, +VSC_F(n_vcl_avail, uint64_t, 0, 'g', 'i', diag, "Number of VCLs available", "" ) -VSC_F(n_vcl_discard, uint64_t, 0, 'c', 'i', diag, +VSC_F(n_vcl_discard, uint64_t, 0, 'g', 'i', diag, "Number of discarded VCLs", "" ) From fgsch at lodoss.net Mon Aug 7 13:00:09 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 07 Aug 2017 15:00:09 +0200 Subject: [master] 57cacb2 Fields type and ident are gone from varnishstat Message-ID: commit 57cacb273cfca256f66e015671af42b01146c054 Author: Federico G. Schwindt Date: Mon Aug 7 13:35:41 2017 +0100 Fields type and ident are gone from varnishstat Fixes #2377. diff --git a/bin/varnishstat/varnishstat.xsd b/bin/varnishstat/varnishstat.xsd index f5f14aa..aaef80f 100644 --- a/bin/varnishstat/varnishstat.xsd +++ b/bin/varnishstat/varnishstat.xsd @@ -6,10 +6,6 @@ - - diff --git a/doc/sphinx/reference/varnishstat.rst b/doc/sphinx/reference/varnishstat.rst index 09bab41..89f1f27 100644 --- a/doc/sphinx/reference/varnishstat.rst +++ b/doc/sphinx/reference/varnishstat.rst @@ -116,8 +116,6 @@ The XML output format is:: - FIELD TYPE - FIELD IDENT FIELD NAME FIELD VALUE FIELD SEMANTICS @@ -133,20 +131,19 @@ The JSON output format is:: "timestamp": "YYYY-MM-DDTHH:mm:SS", "FIELD NAME": { "description": "FIELD DESCRIPTION", - "type": "FIELD TYPE", "ident": "FIELD IDENT", "flag": "FIELD SEMANTICS", "format": "FIELD DISPLAY FORMAT", + "flag": "FIELD SEMANTICS", "format": "FIELD DISPLAY FORMAT", "value": FIELD VALUE }, "FIELD NAME": { "description": "FIELD DESCRIPTION", - "type": "FIELD TYPE", "ident": "FIELD IDENT", "flag": "FIELD SEMANTICS", "format": "FIELD DISPLAY FORMAT", + "flag": "FIELD SEMANTICS", "format": "FIELD DISPLAY FORMAT", "value": FIELD VALUE }, [..] } -Type and ident are optional. Timestamp is the time when the report was -generated by varnishstat. +Timestamp is the time when the report was generated by varnishstat. SEE ALSO From fgsch at lodoss.net Mon Aug 7 13:18:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 07 Aug 2017 15:18:06 +0200 Subject: [master] 787133e Correct regexp in examples Message-ID: commit 787133e6967652df6dbcf3b83b3f9b9b1a1e7ad7 Author: Federico G. Schwindt Date: Mon Aug 7 14:16:10 2017 +0100 Correct regexp in examples Fixes #2380. diff --git a/doc/sphinx/reference/varnish-cli.rst b/doc/sphinx/reference/varnish-cli.rst index 6557284..37d4760 100644 --- a/doc/sphinx/reference/varnish-cli.rst +++ b/doc/sphinx/reference/varnish-cli.rst @@ -355,7 +355,7 @@ Ban all documents where the serving host is "example.com" or "www.example.com", and where the Set-Cookie header received from the backend contains "USERID=1663":: - ban req.http.host ~ "^(?i)(www\\.)example.com$" && obj.http.set-cookie ~ "USERID=1663" + ban req.http.host ~ "^(?i)(www\\.)?example\\.com$" && obj.http.set-cookie ~ "USERID=1663" AUTHORS ======= diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index cb50b6e..e826779 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -158,7 +158,7 @@ To send flags to the PCRE engine, such as to do case insensitive matching, add the flag within parens following a question mark, like this:: # If host is NOT example dot com.. - if (req.http.host !~ "(?i)example.com$") { + if (req.http.host !~ "(?i)example\.com$") { ... } From varnish-commit at varnish-cache.org Mon Aug 7 16:05:15 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 7 Aug 2017 09:05:15 -0700 Subject: Hi! Message-ID: i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Linna19 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Mon Aug 7 22:57:39 2017 From: varnish-commit at varnish-cache.org (=?utf-8?B?5Ya35YWI55Sf?=) Date: Tue, 8 Aug 2017 06:57:39 +0800 Subject: =?utf-8?B?5Lia5Yqh5ZGY5aSW6K6t5byA6K++6YCa55+l?= Message-ID: <20170808065749340457@mdspacc.com> An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ?????.docx Type: application/octet-stream Size: 21787 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ???18?????.xlsx Type: application/octet-stream Size: 21407 bytes Desc: not available URL: From dridi.boukelmoune at gmail.com Tue Aug 8 08:33:06 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Tue, 08 Aug 2017 10:33:06 +0200 Subject: [master] 465b8b8 Fix sourcing of varnish.m4 when building on FreeBSD Message-ID: commit 465b8b8cde4510c409ce98578ed396fda3f3ccd7 Author: Mark Felder Date: Mon Aug 7 19:16:42 2017 -0500 Fix sourcing of varnish.m4 when building on FreeBSD diff --git a/Makefile.am b/Makefile.am index f018bc8..006c770 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -ACLOCAL_AMFLAGS = -I m4 +ACLOCAL_AMFLAGS = -I m4 -I . SUBDIRS = include lib bin etc doc man From hermunn at varnish-software.com Tue Aug 8 09:36:06 2017 From: hermunn at varnish-software.com (Pål Hermunn Johansen) Date: Tue, 08 Aug 2017 11:36:06 +0200 Subject: [4.1] 07271b8 Both Upgrade and Connection headers are needed now Message-ID: commit 07271b8f3532b762ec9c10f588330b1ac58a0a98 Author: Federico G. Schwindt Date: Fri Jul 21 11:18:21 2017 +0100 Both Upgrade and Connection headers are needed now Related to #2337 and #2366. diff --git a/doc/sphinx/users-guide/vcl-example-websockets.rst b/doc/sphinx/users-guide/vcl-example-websockets.rst index 9401b37..f4aed70 100644 --- a/doc/sphinx/users-guide/vcl-example-websockets.rst +++ b/doc/sphinx/users-guide/vcl-example-websockets.rst @@ -6,7 +6,7 @@ WebSockets is a technology for creating a bidirectional stream-based channel over HTTP. To run WebSockets through Varnish you need to pipe the request and copy -the Upgrade header as follows:: +the Upgrade and Connection headers as follows:: sub vcl_recv { if (req.http.upgrade ~ "(?i)websocket") { @@ -17,5 +17,6 @@ the Upgrade header as follows:: sub vcl_pipe { if (req.http.upgrade) { set bereq.http.upgrade = req.http.upgrade; + set bereq.http.connection = req.http.connection; } } From hermunn at varnish-software.com Tue Aug 8 09:36:06 2017 From: hermunn at varnish-software.com (Pål Hermunn Johansen) Date: Tue, 08 Aug 2017 11:36:06 +0200 Subject: [4.1] 1e09758 Add the vtc feature ignore_unknown_macro. Message-ID: commit 1e09758e0d5e5a27b3a6643f450554f558f5031d Author: Geoff Simmons Date: Wed Jul 5 07:26:31 2017 +0200 Add the vtc feature ignore_unknown_macro. Closes: #2357 diff --git a/bin/varnishtest/tests/a00018.vtc b/bin/varnishtest/tests/a00018.vtc new file mode 100644 index 0000000..036aa45 --- /dev/null +++ b/bin/varnishtest/tests/a00018.vtc @@ -0,0 +1,35 @@ +varnishtest "feature ignore_unknown_macro" + +feature ignore_unknown_macro + +server s1 { + rxreq + expect req.http.Foo == "${foo}" + txresp -hdr "Bar: ${bar}" +} -start + +varnish v1 -vcl { + backend default { + .host = "${s1_addr}"; + .port = "${s1_port}"; + } + + sub vcl_deliver { + if (resp.http.Bar == "${bar}") { + set resp.http.Baz = "${baz}"; + } + } +} -start + +client c1 { + txreq -hdr "Foo: ${foo}" + rxresp + expect resp.status == 200 + expect resp.http.Bar == "${bar}" + expect resp.http.Baz == "${baz}" +} -run + +shell { + touch ${tmpdir}/tst + rm ${tmpdir}/tst +} diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c index ba9a18a..0405e19 100644 --- a/bin/varnishtest/vtc.c +++ b/bin/varnishtest/vtc.c @@ -56,6 +56,7 @@ volatile sig_atomic_t vtc_error; /* Error encountered */ int vtc_stop; /* Stops current test without error */ pthread_t vtc_thread; static struct vtclog *vltop; +static int ign_unknown_macro = 0; /********************************************************************** * Macro facility @@ -197,13 +198,18 @@ macro_expand(struct vtclog *vl, const char *text) p += 2; m = macro_get(p, q); if (m == NULL) { - VSB_delete(vsb); - vtc_log(vl, 0, "Macro ${%.*s} not found", (int)(q - p), - p); - return (NULL); + if (!ign_unknown_macro) { + VSB_delete(vsb); + vtc_log(vl, 0, "Macro ${%.*s} not found", + (int)(q - p), p); + return (NULL); + } + VSB_printf(vsb, "${%.*s}", (int)(q - p), p); + } + else { + VSB_printf(vsb, "%s", m); + free(m); } - VSB_printf(vsb, "%s", m); - free(m); text = q + 1; } AZ(VSB_finish(vsb)); @@ -744,6 +750,9 @@ cmd_feature(CMD_ARGS) good = 1; else vtc_stop = 1; + } else if (!strcmp(*av, "ignore_unknown_macro")) { + ign_unknown_macro = 1; + good = 1; } if (good) continue; From hermunn at varnish-software.com Tue Aug 8 09:52:06 2017 From: hermunn at varnish-software.com (Pål Hermunn Johansen) Date: Tue, 08 Aug 2017 11:52:06 +0200 Subject: [4.1] 610b309 Correct regexp in examples Message-ID: commit 610b309cbc6c20d29c9959c7a5bbfb456d3dcb59 Author: Federico G. Schwindt Date: Mon Aug 7 14:16:10 2017 +0100 Correct regexp in examples Fixes #2380. diff --git a/doc/sphinx/reference/varnish-cli.rst b/doc/sphinx/reference/varnish-cli.rst index 02c86a4..023c7aa 100644 --- a/doc/sphinx/reference/varnish-cli.rst +++ b/doc/sphinx/reference/varnish-cli.rst @@ -426,7 +426,7 @@ Example: Ban all documents where the serving host is "example.com" or "www.example.com", and where the Set-Cookie header received from the backend contains "USERID=1663":: - req.http.host ~ "^(?i)(www\.)example.com$" && obj.http.set-cookie ~ "USERID=1663" + ban req.http.host ~ "^(?i)(www\\.)?example\\.com$" && obj.http.set-cookie ~ "USERID=1663" AUTHORS ======= diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 553fd72..4be83c5 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -145,7 +145,7 @@ To send flags to the PCRE engine, such as to do case insensitive matching, add the flag within parens following a question mark, like this:: # If host is NOT example dot com.. - if (req.http.host !~ "(?i)example.com$") { + if (req.http.host !~ "(?i)example\.com$") { ... } From nils.goroll at uplex.de Tue Aug 8 09:56:06 2017 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 08 Aug 2017 11:56:06 +0200 Subject: [master] 560d274 retire s_req - it is identical to client_req Message-ID: commit 560d2744f08169cc6e7b1ba3aa1908f76614a0be Author: Nils Goroll Date: Tue Aug 1 15:06:41 2017 +0200 retire s_req - it is identical to client_req Merges #2381 diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index 1bbc552..bd3e4af 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -79,7 +79,6 @@ cnt_transport(struct worker *wrk, struct req *req) } wrk->stats->client_req++; - wrk->stats->s_req++; AZ(req->err_code); req->ws_req = WS_Snapshot(req->ws); diff --git a/bin/varnishd/main.vsc b/bin/varnishd/main.vsc index 8292c1e..dd53b9e 100644 --- a/bin/varnishd/main.vsc +++ b/bin/varnishd/main.vsc @@ -305,10 +305,6 @@ :oneliner: Total sessions seen -.. varnish_vsc:: s_req - :oneliner: Total requests seen - - .. varnish_vsc:: s_pipe :oneliner: Total pipe sessions seen diff --git a/bin/varnishtest/tests/b00000.vtc b/bin/varnishtest/tests/b00000.vtc index c33038a..7937df8 100644 --- a/bin/varnishtest/tests/b00000.vtc +++ b/bin/varnishtest/tests/b00000.vtc @@ -30,6 +30,5 @@ varnish v1 -expect sess_conn == 1 varnish v1 -expect client_req == 1 varnish v1 -expect cache_miss == 1 varnish v1 -expect s_sess == 1 -varnish v1 -expect s_req == 1 varnish v1 -expect s_resp_bodybytes == 7 varnish v1 -expect s_resp_hdrbytes == 178 diff --git a/bin/varnishtest/tests/b00001.vtc b/bin/varnishtest/tests/b00001.vtc index b45ddb5..95dc08d 100644 --- a/bin/varnishtest/tests/b00001.vtc +++ b/bin/varnishtest/tests/b00001.vtc @@ -34,5 +34,4 @@ varnish v1 -expect n_object == 0 varnish v1 -expect sess_conn == 1 varnish v1 -expect client_req == 1 varnish v1 -expect s_sess == 1 -varnish v1 -expect s_req == 1 varnish v1 -expect s_pipe == 1 diff --git a/bin/varnishtest/tests/b00002.vtc b/bin/varnishtest/tests/b00002.vtc index 4426904..d0f3cc6 100644 --- a/bin/varnishtest/tests/b00002.vtc +++ b/bin/varnishtest/tests/b00002.vtc @@ -39,7 +39,6 @@ varnish v1 -expect SMA.Transient.g_alloc == 0 varnish v1 -expect sess_conn == 1 varnish v1 -expect client_req == 1 varnish v1 -expect s_sess == 1 -varnish v1 -expect s_req == 1 varnish v1 -expect s_pass == 1 logexpect l1 -wait diff --git a/bin/varnishtest/tests/b00003.vtc b/bin/varnishtest/tests/b00003.vtc index 77b6972..435d3ef 100644 --- a/bin/varnishtest/tests/b00003.vtc +++ b/bin/varnishtest/tests/b00003.vtc @@ -29,5 +29,4 @@ 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 diff --git a/bin/varnishtest/tests/c00020.vtc b/bin/varnishtest/tests/c00020.vtc index 91fcd12..efcfe24 100644 --- a/bin/varnishtest/tests/c00020.vtc +++ b/bin/varnishtest/tests/c00020.vtc @@ -69,5 +69,4 @@ 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 diff --git a/bin/varnishtest/tests/r01857.vtc b/bin/varnishtest/tests/r01857.vtc index 8bb1aa4..5686be8 100644 --- a/bin/varnishtest/tests/r01857.vtc +++ b/bin/varnishtest/tests/r01857.vtc @@ -28,5 +28,4 @@ varnish v1 -expect cache_hit == 1 varnish v1 -expect cache_miss == 1 varnish v1 -expect client_req == 2 varnish v1 -expect s_sess == 1 -varnish v1 -expect s_req == 2 varnish v1 -expect s_fetch == 1 diff --git a/bin/varnishtest/tests/v00042.vtc b/bin/varnishtest/tests/v00042.vtc index e7901b1..54dccca 100644 --- a/bin/varnishtest/tests/v00042.vtc +++ b/bin/varnishtest/tests/v00042.vtc @@ -72,4 +72,4 @@ client c1 { expect resp.http.o1 == "/b0" } -run -varnish v1 -expect s_req == 2 +varnish v1 -expect client_req == 2 diff --git a/bin/varnishtest/tests/v00043.vtc b/bin/varnishtest/tests/v00043.vtc index 7e7a4f9..9aaae1a 100644 --- a/bin/varnishtest/tests/v00043.vtc +++ b/bin/varnishtest/tests/v00043.vtc @@ -74,4 +74,4 @@ client c1 { expect resp.http.o1 == "/b0" } -run -varnish v1 -expect s_req == 2 +varnish v1 -expect client_req == 2 diff --git a/doc/changes.rst b/doc/changes.rst index a40d0a3..fe16406 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -15,6 +15,10 @@ Varnish Cache Trunk (ongoing) * varnishd honors vcl_path (#2342) +* The ``MAIN.s_req`` statistic has been removed, as tt was identical to + ``MAIN.client_req``. VSM consumers should be changed to use the + latter if necessary. + ================================ Varnish Cache 5.1.2 (2017-04-07) ================================ From nils.goroll at uplex.de Tue Aug 8 09:56:06 2017 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 08 Aug 2017 11:56:06 +0200 Subject: [master] d7f8b53 Expose to VCL whether or not a fetch is a background fetch (bgfetch) Message-ID: commit d7f8b531bd63fcb5bc01c680d859a969b2c4525d Author: Nils Goroll Date: Fri Jul 21 14:18:51 2017 +0200 Expose to VCL whether or not a fetch is a background fetch (bgfetch) The use case are cluster requests: Intra-cluster bgfetches should trigger a synchronous fetch on the peer-varnish in order to avoid additional short-lived / expired objects being created. Or, in other words, a bgfetch should actually get a fresh object and not one in grace from another cache. Merges #2376 diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index e82fe5c..b8066a1 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -1020,20 +1020,28 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc, AN(oc->flags & OC_F_BUSY); CHECK_OBJ_ORNULL(oldoc, OBJCORE_MAGIC); - - switch (mode) { - case VBF_PASS: how = "pass"; break; - case VBF_NORMAL: how = "fetch"; break; - case VBF_BACKGROUND: how = "bgfetch"; break; - default: WRONG("Wrong fetch mode"); - } - bo = VBO_GetBusyObj(wrk, req); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); boc = HSH_RefBoc(oc); CHECK_OBJ_NOTNULL(boc, BOC_MAGIC); + switch (mode) { + case VBF_PASS: + how = "pass"; + bo->do_pass = 1; + break; + case VBF_NORMAL: + how = "fetch"; + break; + case VBF_BACKGROUND: + how = "bgfetch"; + bo->is_bgfetch = 1; + break; + default: + WRONG("Wrong fetch mode"); + } + VSLb(bo->vsl, SLT_Begin, "bereq %u %s", VXID(req->vsl->wid), how); VSLb(req->vsl, SLT_Link, "bereq %u %s", VXID(bo->vsl->wid), how); @@ -1044,9 +1052,6 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc, AN(bo->vcl); - if (mode == VBF_PASS) - bo->do_pass = 1; - oc->boc->vary = req->vary_b; req->vary_b = NULL; diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index ec85e64..f99b2a6 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -203,6 +203,14 @@ VRT_r_beresp_##field(VRT_CTX) \ /*--------------------------------------------------------------------*/ unsigned +VRT_r_bereq_is_bgfetch(VRT_CTX) +{ + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); + return (ctx->bo->is_bgfetch); +} + +unsigned VRT_r_bereq_uncacheable(VRT_CTX) { CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); diff --git a/bin/varnishtest/tests/r01399.vtc b/bin/varnishtest/tests/r01399.vtc index c7adffa..e33da79 100644 --- a/bin/varnishtest/tests/r01399.vtc +++ b/bin/varnishtest/tests/r01399.vtc @@ -4,6 +4,7 @@ barrier b1 cond 2 server s1 { rxreq + expect req.http.Is-bg == "false" txresp -bodylen 1 barrier b1 sync @@ -19,11 +20,15 @@ server s1 { # And see if it has all its marbles still... rxreq expect req.url == "/" + expect req.http.Is-bg == "true" txresp -bodylen 2 } -start varnish v1 -vcl+backend { + sub vcl_backend_fetch { + set bereq.http.Is-bg = bereq.is_bgfetch; + } sub vcl_backend_response { set beresp.do_stream = false; set beresp.ttl = 2s; diff --git a/doc/changes.rst b/doc/changes.rst index fe16406..5dd2bb1 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -19,6 +19,8 @@ Varnish Cache Trunk (ongoing) ``MAIN.client_req``. VSM consumers should be changed to use the latter if necessary. +* Added ``bereq.is_bgfetch`` which is true for background fetches. + ================================ Varnish Cache 5.1.2 (2017-04-07) ================================ diff --git a/include/tbl/bo_flags.h b/include/tbl/bo_flags.h index 221f9a3..5757699 100644 --- a/include/tbl/bo_flags.h +++ b/include/tbl/bo_flags.h @@ -39,6 +39,7 @@ BO_FLAG(uncacheable, 0, 0, "") BO_FLAG(is_gzip, 0, 0, "") BO_FLAG(is_gunzip, 0, 0, "") BO_FLAG(was_304, 1, 0, "") +BO_FLAG(is_bgfetch, 0, 0, "") #undef BO_FLAG /*lint -restore */ diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 7faf58c..13645ea 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -478,6 +478,13 @@ sp_variables = [ backend. Not available in pipe mode. """ ), + ('bereq.is_bgfetch', + 'BOOL', + ('backend', ), + (), """ + True for background fetches. + """ + ), ('beresp', 'HTTP', ('backend_response', 'backend_error'), From nils.goroll at uplex.de Tue Aug 8 09:56:06 2017 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 08 Aug 2017 11:56:06 +0200 Subject: [master] 8580229 changelog tlc Message-ID: commit 8580229767a562bbe3bdd8b80b6a43ab2fa399aa Author: Nils Goroll Date: Tue Aug 8 11:50:36 2017 +0200 changelog tlc diff --git a/doc/changes.rst b/doc/changes.rst index 5dd2bb1..4432802 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -2,25 +2,36 @@ Varnish Cache Trunk (ongoing) ============================= -* Default the -i argument to gethostname(3) - -* On platforms with setproctitle(3), use the -i argument rather than -n - -* VRT_purge fails a transaction if used outside of ``vcl_hit`` and - ``vcl_miss`` (#2339) +Usage +----- -* VSM_Name() returns the -i argument name, rather than the -n name. +* The default for the the -i argument is now the hostname as returned + by gethostname(3) -* VUT.name is gone, use VSM_Name(VUT.vsm) +* Where possible (on platforms with setproctitle(3)), the -i argument + rather than the -n argument is used for process names -* varnishd honors vcl_path (#2342) +* varnishd honors ``vcl_path`` (#2342) -* The ``MAIN.s_req`` statistic has been removed, as tt was identical to +* The ``MAIN.s_req`` statistic has been removed, as it was identical to ``MAIN.client_req``. VSM consumers should be changed to use the latter if necessary. +VCL +--- + +* VRT_purge fails a transaction if used outside of ``vcl_hit`` and + ``vcl_miss`` (#2339) + * Added ``bereq.is_bgfetch`` which is true for background fetches. +C APIs (for vmod authors) +------------------------- + +* ``VSM_Name()`` returns the -i argument name, rather than the -n name. + +* ``VUT.name`` is gone, use ``VSM_Name(VUT.vsm)`` + ================================ Varnish Cache 5.1.2 (2017-04-07) ================================ From nils.goroll at uplex.de Tue Aug 8 09:56:06 2017 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 08 Aug 2017 11:56:06 +0200 Subject: [master] f3b17eb pull 5.1.3 info into changelog Message-ID: commit f3b17eb83610ad4cf09208effef30250e1002a60 Author: Nils Goroll Date: Tue Aug 8 11:54:29 2017 +0200 pull 5.1.3 info into changelog diff --git a/doc/changes.rst b/doc/changes.rst index 4432802..ef5938a 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -33,6 +33,17 @@ C APIs (for vmod authors) * ``VUT.name`` is gone, use ``VSM_Name(VUT.vsm)`` ================================ +Varnish Cache 5.1.3 (2017-08-02) +================================ + +Bugs fixed +---------- + +* 2379_ - Correctly handle bogusly large chunk sizes (VSV00001) + +.. _2379: https://github.com/varnishcache/varnish-cache/issues/2379 + +================================ Varnish Cache 5.1.2 (2017-04-07) ================================ From varnish-commit at varnish-cache.org Tue Aug 8 10:39:39 2017 From: varnish-commit at varnish-cache.org (=?utf-8?B?6JOd57uP55CG?=) Date: Tue, 8 Aug 2017 18:39:39 +0800 Subject: =?utf-8?B?SFLmlbDmja7ljJY=?= Message-ID: <20170808183948210627@petsnook.com> ?????? 1?HR????????????????????????????????? 2?HR????????????????????????????? 3?HR????????????????????????????????? 4?HR??????????????????????????KPI????? 5?HR????????????????????????? ????? ??1?HR????? ??2?????????? ??3? ??????HR???? ??4? HR??????? ??5?????? ??6? HR??? ???????? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: HR???.xls Type: application/octet-stream Size: 32768 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ????? .docx Type: application/octet-stream Size: 21779 bytes Desc: not available URL: From daghf at varnish-software.com Tue Aug 8 13:49:06 2017 From: daghf at varnish-software.com (Dag Haavi Finstad) Date: Tue, 08 Aug 2017 15:49:06 +0200 Subject: [master] 76ae363 Verify padding and priority flag numbers in h2_rx_headers Message-ID: commit 76ae363534d4e81e35700b99213b4612b56b534c Author: Dag Haavi Finstad Date: Thu Jul 6 17:26:55 2017 +0200 Verify padding and priority flag numbers in h2_rx_headers Unchecked decoding of the padding length and also the priority flag turns into an integer underrun when the input length is smaller than what we end up subtracting. rfc7540 doesn't seem to adress what should be the error condition when the priority flag is enabled but the payload is smaller than what could contain the priority bits. Seeing as a HEADERS frame changes connection state I assume closing down via PROTOCOL_ERROR is the proper handling. Fixes: #2349 diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c index 87dca6e..f820d05 100644 --- a/bin/varnishd/http2/cache_http2_proto.c +++ b/bin/varnishd/http2/cache_http2_proto.c @@ -577,14 +577,17 @@ h2_rx_headers(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2) AN(r2->decode); h2h_decode_init(h2, r2->decode); - /* XXX: Error handling */ p = h2->rxf_data; l = h2->rxf_len; if (h2->rxf_flags & H2FF_HEADERS_PADDED) { + if (*p > l) + return (H2CE_PROTOCOL_ERROR); // rfc7540,l,1884,1887 l -= 1 + *p; p += 1; } if (h2->rxf_flags & H2FF_HEADERS_PRIORITY) { + if (l < 5) + return (H2CE_PROTOCOL_ERROR); l -= 5; p += 5; } diff --git a/bin/varnishtest/tests/t02003.vtc b/bin/varnishtest/tests/t02003.vtc index 2f32a51..86417a0 100644 --- a/bin/varnishtest/tests/t02003.vtc +++ b/bin/varnishtest/tests/t02003.vtc @@ -369,6 +369,41 @@ client c1 { } -run } -run + +#2349: Padding exceeds frame size +client c1 { + stream 1 { + sendhex 000001 + sendhex 01 + sendhex 09 + sendhex 00000001 + sendhex { ff } + } -run + stream 0 { + rxgoaway + expect goaway.err == PROTOCOL_ERROR + expect goaway.laststream == 1 + } -run + expect_close +} -run + +#2349: Integer underrun may also occur when the padding flag is set +client c1 { + stream 1 { + sendhex 000004 + sendhex 01 + sendhex 21 + sendhex 00000001 + sendhex { aabb ccdd } + } -run + stream 0 { + rxgoaway + expect goaway.err == PROTOCOL_ERROR + expect goaway.laststream == 1 + } -run + expect_close +} -run + varnish v1 -vsl_catchup varnish v1 -expect MEMPOOL.req0.live == 0 From daghf at varnish-software.com Tue Aug 8 13:49:06 2017 From: daghf at varnish-software.com (Dag Haavi Finstad) Date: Tue, 08 Aug 2017 15:49:06 +0200 Subject: [master] aefd39e Free the allocation for the HPACK dynamic table Message-ID: commit aefd39e7b913e32793aa3902e33f6c8bb734e2b3 Author: Dag Haavi Finstad Date: Fri Jul 7 13:58:44 2017 +0200 Free the allocation for the HPACK dynamic table This adds a call to VHT_Fini just before we let go of the h2_sess in h2_del_req. diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c index f820d05..a264626 100644 --- a/bin/varnishd/http2/cache_http2_proto.c +++ b/bin/varnishd/http2/cache_http2_proto.c @@ -185,6 +185,7 @@ h2_del_req(struct worker *wrk, struct h2_req *r2) if (r) return; /* All streams gone, including stream #0, clean up */ + VHT_Fini(h2->dectbl); req = h2->srq; AZ(req->ws->r); Req_Cleanup(sp, wrk, req); diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c index 80f50aa..e30eb8e 100644 --- a/bin/varnishd/http2/cache_http2_session.c +++ b/bin/varnishd/http2/cache_http2_session.c @@ -103,7 +103,6 @@ h2_new_sess(const struct worker *wrk, struct sess *sp, struct req *srq) h2->local_settings = H2_proto_settings; h2->remote_settings = H2_proto_settings; - /* XXX: Lacks a VHT_Fini counterpart. Will leak memory. */ AZ(VHT_Init(h2->dectbl, h2->local_settings.header_table_size)); From daghf at varnish-software.com Tue Aug 8 13:49:06 2017 From: daghf at varnish-software.com (Dag Haavi Finstad) Date: Tue, 08 Aug 2017 15:49:06 +0200 Subject: [master] 5e98181 Fix a race in the h/2 Upgrade code Message-ID: commit 5e98181a6180a50df0836539b2bc12b2264fb8fe Author: Dag Haavi Finstad Date: Wed Jul 12 14:46:21 2017 +0200 Fix a race in the h/2 Upgrade code Make sure we flag the request as scheduled when dispatched from the h/2 Upgrade code. Without this, the h/2 code will happily clean it up once the client hangs up even though it is still being processed in a different thread. Fixes: #2310 diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c index e30eb8e..adbe94c 100644 --- a/bin/varnishd/http2/cache_http2_session.c +++ b/bin/varnishd/http2/cache_http2_session.c @@ -230,6 +230,7 @@ h2_ou_session(struct worker *wrk, struct h2_sess *h2, req->req_step = R_STP_TRANSPORT; req->task.func = h2_do_req; req->task.priv = req; + r2->scheduled = 1; req->err_code = 0; http_SetH(req->http, HTTP_HDR_PROTO, "HTTP/2.0"); diff --git a/bin/varnishtest/tests/r02310.vtc b/bin/varnishtest/tests/r02310.vtc new file mode 100644 index 0000000..2f30369 --- /dev/null +++ b/bin/varnishtest/tests/r02310.vtc @@ -0,0 +1,40 @@ +varnishtest "#2310: Panic on premature hangup after Upgrade: h2c" + +barrier b1 cond 2 + +server s1 { + rxreq + barrier b1 sync + txresp +} -start + +varnish v1 -vcl+backend {} -start + +varnish v1 -cliok "param.set feature +http2" + +client c1 { + send "GET / HTTP/1.1\r\n" + send "Host: foo\r\n" + send "Connection: Upgrade, HTTP2-Settings\r\n" + send "Upgrade: h2c\r\n" + send "HTTP2-Settings: AAMAAABkAARAAAAA\r\n" + send "\r\n" + rxresp + expect resp.status == 101 + expect resp.http.upgrade == h2c + expect resp.http.connection == Upgrade + txpri + stream 0 { + rxsettings + txsettings + txsettings -ack + rxsettings + expect settings.ack == true + } -run + +} -run + +barrier b1 sync +varnish v1 -expect client_req != 0 +varnish v1 -wait + From daghf at varnish-software.com Tue Aug 8 13:49:06 2017 From: daghf at varnish-software.com (Dag Haavi Finstad) Date: Tue, 08 Aug 2017 15:49:06 +0200 Subject: [master] 4460caa Properly handle END_STREAM for HEADERS+CONTINUATION Message-ID: commit 4460caa89ec340e07284917b6b6085c4f960fa87 Author: Dag Haavi Finstad Date: Thu Jul 13 17:35:37 2017 +0200 Properly handle END_STREAM for HEADERS+CONTINUATION In a sequence of HEADERS and CONTINUATION frames, the END_STREAM flag is set in the HEADERS frame, and the END_HEADERS flag is set in the last CONTINUATION frame. diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c index a264626..25c18a2 100644 --- a/bin/varnishd/http2/cache_http2_proto.c +++ b/bin/varnishd/http2/cache_http2_proto.c @@ -526,9 +526,6 @@ h2_end_headers(struct worker *wrk, const struct h2_sess *h2, } VSLb_ts_req(req, "Req", req->t_req); - if (h2->rxf_flags & H2FF_HEADERS_END_STREAM) - req->req_body_status = REQ_BODY_NONE; - req->req_step = R_STP_TRANSPORT; req->task.func = h2_do_req; req->task.priv = req; @@ -602,6 +599,10 @@ h2_rx_headers(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2) h2_del_req(wrk, r2); return (h2e); } + + if (h2->rxf_flags & H2FF_HEADERS_END_STREAM) + req->req_body_status = REQ_BODY_NONE; + if (h2->rxf_flags & H2FF_HEADERS_END_HEADERS) return (h2_end_headers(wrk, h2, req, r2)); return (0); diff --git a/bin/varnishtest/tests/t02003.vtc b/bin/varnishtest/tests/t02003.vtc index 86417a0..34b88c2 100644 --- a/bin/varnishtest/tests/t02003.vtc +++ b/bin/varnishtest/tests/t02003.vtc @@ -445,6 +445,15 @@ client c1 { } -run } -run +client c1 { + stream 1 { + txreq -nohdrend + txcont -hdr "bar" "foo" + rxresp + expect resp.status == 200 + } -run +} -run + varnish v1 -vsl_catchup varnish v1 -expect MEMPOOL.req0.live == 0 From daghf at varnish-software.com Tue Aug 8 13:49:06 2017 From: daghf at varnish-software.com (Dag Haavi Finstad) Date: Tue, 08 Aug 2017 15:49:06 +0200 Subject: [master] 9dfcbe3 Don't process a CONTINUATION frame on a closed stream Message-ID: commit 9dfcbe3394651e4b55183c3e53fdc3eaae06f966 Author: Dag Haavi Finstad Date: Wed Jul 12 16:25:22 2017 +0200 Don't process a CONTINUATION frame on a closed stream Fixes: #2350 diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c index 25c18a2..a2892d9 100644 --- a/bin/varnishd/http2/cache_http2_proto.c +++ b/bin/varnishd/http2/cache_http2_proto.c @@ -619,8 +619,7 @@ h2_rx_continuation(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2) h2_error h2e; ASSERT_RXTHR(h2); - AN(r2); - if (r2->state != H2_S_OPEN) + if (r2 == NULL || r2->state != H2_S_OPEN) return (H2CE_PROTOCOL_ERROR); // XXX spec ? req = r2->req; h2e = h2h_decode_bytes(h2, r2->decode, h2->rxf_data, h2->rxf_len); diff --git a/bin/varnishtest/tests/t02003.vtc b/bin/varnishtest/tests/t02003.vtc index 34b88c2..20b5f3c 100644 --- a/bin/varnishtest/tests/t02003.vtc +++ b/bin/varnishtest/tests/t02003.vtc @@ -454,6 +454,20 @@ client c1 { } -run } -run +# 2350: Don't accept a continuation frame after stream is closed +client c1 { + stream 1 { + txreq + rxresp + txcont -hdr "foo" "bar" + } -run + + stream 0 { + rxgoaway + expect goaway.err == PROTOCOL_ERROR + } -run +} -run + varnish v1 -vsl_catchup varnish v1 -expect MEMPOOL.req0.live == 0 From varnish-commit at varnish-cache.org Wed Aug 9 08:55:09 2017 From: varnish-commit at varnish-cache.org (varnish-commit) Date: Wed, 9 Aug 2017 16:55:09 +0800 Subject: =?utf-8?B?6ZmE5Lu26L2sSFLlronmjpLlpJborq3vvJvljaLmgLs=?= Message-ID: <20170809165515550156@plannedtvarts.com> ???HR??????? 2017/8/9 ??? ?? 4:55:15 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ????? .docx Type: application/octet-stream Size: 21788 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ???????????.xlsx Type: application/octet-stream Size: 18430 bytes Desc: not available URL: From Connie at varnish-cache.org Wed Aug 9 13:58:14 2017 From: Connie at varnish-cache.org (Connie at varnish-cache.org) Date: Wed, 09 Aug 2017 13:58:14 -0000 Subject: E 2017-08-09 (08).doc Message-ID: <157191992.3.9736380172232@Server> An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: E 2017-08-09 (08).zip Type: application/octet-stream Size: 2109 bytes Desc: not available URL: From varnish-commit at varnish-cache.org Thu Aug 10 05:43:24 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 10 Aug 2017 07:43:24 +0200 Subject: hot g!rl want you! Message-ID: <004701d3119c$049bdaee$c864d3a9$@varnish-cache.org> i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Claudy95 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From varnish-commit at varnish-cache.org Thu Aug 10 19:03:11 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 10 Aug 2017 21:03:11 +0200 Subject: taste my @ss! Message-ID: <592896851301192459275480@varnish-cache.org> i'm not into commitment. i just want a hard f*ck think u can give me what i want? my username is Helen29 my profile is here -------------- next part -------------- An HTML attachment was scrubbed... URL: From daghf at varnish-software.com Fri Aug 11 09:20:16 2017 From: daghf at varnish-software.com (Dag Haavi Finstad) Date: Fri, 11 Aug 2017 11:20:16 +0200 Subject: [master] bea0e67 Fix an off-by-one mistake introduced in 76ae363534 Message-ID: commit bea0e671417df655a9b510c9da2c5d68f2f833df Author: Dag Haavi Finstad Date: Fri Aug 11 11:00:23 2017 +0200 Fix an off-by-one mistake introduced in 76ae363534 We could still trigger the integer underflow condition in #2349 by supplying a padding length equal to the frame size. diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c index a2892d9..40a5a9b 100644 --- a/bin/varnishd/http2/cache_http2_proto.c +++ b/bin/varnishd/http2/cache_http2_proto.c @@ -578,7 +578,7 @@ h2_rx_headers(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2) p = h2->rxf_data; l = h2->rxf_len; if (h2->rxf_flags & H2FF_HEADERS_PADDED) { - if (*p > l) + if (*p + 1 > l) return (H2CE_PROTOCOL_ERROR); // rfc7540,l,1884,1887 l -= 1 + *p; p += 1; diff --git a/bin/varnishtest/tests/t02003.vtc b/bin/varnishtest/tests/t02003.vtc index 20b5f3c..b355fd4 100644 --- a/bin/varnishtest/tests/t02003.vtc +++ b/bin/varnishtest/tests/t02003.vtc @@ -387,7 +387,24 @@ client c1 { expect_close } -run -#2349: Integer underrun may also occur when the padding flag is set +#2349: Padding equal to frame size +client c1 { + stream 1 { + sendhex 000001 + sendhex 01 + sendhex 09 + sendhex 00000001 + sendhex 01 + } -run + stream 0 { + rxgoaway + expect goaway.err == PROTOCOL_ERROR + expect goaway.laststream == 1 + } -run + expect_close +} -run + +#2349: Integer underrun may also occur when the priority flag is set client c1 { stream 1 { sendhex 000004 From daghf at varnish-software.com Fri Aug 11 12:10:10 2017 From: daghf at varnish-software.com (Dag Haavi Finstad) Date: Fri, 11 Aug 2017 14:10:10 +0200 Subject: [master] 3a82481 Make t02007.vtc less flaky Message-ID: commit 3a82481f9a998784bdaab79d0d84158ab9fc0ba7 Author: Dag Haavi Finstad Date: Fri Aug 11 14:07:24 2017 +0200 Make t02007.vtc less flaky Add a barrier sync to ensure we get the WINDOW_UPDATE and the DATA frames in the expected order. diff --git a/bin/varnishtest/tests/t02007.vtc b/bin/varnishtest/tests/t02007.vtc index 8fe8b8d..e4d4699 100644 --- a/bin/varnishtest/tests/t02007.vtc +++ b/bin/varnishtest/tests/t02007.vtc @@ -1,5 +1,7 @@ varnishtest "H2 Huge response headers" +barrier b1 sock 2 + server s1 { rxreq expect req.proto == HTTP/1.1 @@ -19,10 +21,22 @@ server s1 { expect req.url == /5 } -start -varnish v1 -vcl+backend {} -cliok "param.set feature +http2" -start + +varnish v1 -cliok "param.set feature +http2" varnish v1 -cliok "param.set debug +syncvsl" varnish v1 -cliok "param.set debug +h2_nocheck" +varnish v1 -vcl+backend { + import debug; + sub vcl_deliver { + if (req.url == "/1") { + if (!debug.barrier_sync("${b1_sock}")) { + return (synth(400)); + } + } + } +} -start + client c1 { stream 0 { txsettings -framesize 64 @@ -31,6 +45,7 @@ client c1 { stream 1 { txreq \ -req POST \ + -url /1 \ -hdr content-type text/plain \ -nostrend \ -nohdrend @@ -50,6 +65,7 @@ client c1 { -data request rxwinup + barrier b1 sync rxresp expect resp.status == 200 expect resp.http.content-Type == "text/plain" From phk at FreeBSD.org Sat Aug 12 13:08:11 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 12 Aug 2017 15:08:11 +0200 Subject: [master] a08370f Centralize the code to handle a named command line argument. Message-ID: commit a08370f3db98e0c8db0e93297b156f9ba50f4eb1 Author: Poul-Henning Kamp Date: Sat Aug 12 13:04:13 2017 +0000 Centralize the code to handle a named command line argument. diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 07b8c61..2a230db 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -180,6 +180,8 @@ void mgt_DumpRstVsl(void); struct vsb *mgt_BuildVident(void); void MGT_Complain(const char *, const char *, ...) __v_printflike(2, 3); const void *MGT_Pick(const struct choice *, const char *, const char *); +char **MGT_NamedArg(const char *arg, const char **name, const char *what); + /* stevedore_mgt.c */ void STV_Config(const char *spec); diff --git a/bin/varnishd/mgt/mgt_util.c b/bin/varnishd/mgt/mgt_util.c index 15bee9f..9263af8 100644 --- a/bin/varnishd/mgt/mgt_util.c +++ b/bin/varnishd/mgt/mgt_util.c @@ -43,6 +43,9 @@ #include "common/heritage.h" +#include "vav.h" +#include "vct.h" + /*--------------------------------------------------------------------*/ char * @@ -184,3 +187,33 @@ MGT_Pick(const struct choice *cp, const char *which, const char *kind) } ARGV_ERR("Unknown %s method \"%s\"\n", kind, which); } + +/*--------------------------------------------------------------------*/ + +char ** +MGT_NamedArg(const char *spec, const char **name, const char *what) +{ + const char *p, *q; + char **av; + + ASSERT_MGT(); + p = strchr(spec, '='); + q = strchr(spec, ','); + if (p == NULL || (q != NULL && q < p)) { + av = VAV_Parse(spec, NULL, ARGV_COMMA); + p = NULL; + } else if (VCT_invalid_name(spec, p) != NULL) { + ARGV_ERR("invalid %s name \"%.*s\"=[...]\n", + what, (int)(p - spec), spec); + } else if (p[1] == '\0') { + ARGV_ERR("Empty named %s argument \"%s\"\n", what, spec); + } else { + av = VAV_Parse(p + 1, NULL, ARGV_COMMA); + } + AN(av); + + if (av[0] != NULL) + ARGV_ERR("%s\n", av[0]); + *name = p; + return (av); +} diff --git a/bin/varnishd/storage/mgt_stevedore.c b/bin/varnishd/storage/mgt_stevedore.c index 0b0dac2..60791a7 100644 --- a/bin/varnishd/storage/mgt_stevedore.c +++ b/bin/varnishd/storage/mgt_stevedore.c @@ -41,8 +41,6 @@ #include "vcli_serve.h" #include "storage/storage.h" -#include "vav.h" -#include "vct.h" static VTAILQ_HEAD(, stevedore) stevedores = VTAILQ_HEAD_INITIALIZER(stevedores); @@ -146,26 +144,15 @@ void STV_Config(const char *spec) { char **av; - const char *p, *q; + const char *name; struct stevedore *stv; const struct stevedore *stv2; int ac, l; static unsigned seq = 0; - ASSERT_MGT(); - p = strchr(spec, '='); - q = strchr(spec, ','); - if (p != NULL && (q == NULL || q > p)) { - av = VAV_Parse(p + 1, NULL, ARGV_COMMA); - } else { - av = VAV_Parse(spec, NULL, ARGV_COMMA); - p = NULL; - } + av = MGT_NamedArg(spec, &name, "-s"); AN(av); - if (av[0] != NULL) - ARGV_ERR("%s\n", av[0]); - if (av[1] == NULL) ARGV_ERR("-s argument lacks strategy {malloc, file, ...}\n"); @@ -187,13 +174,11 @@ STV_Config(const char *spec) *stv = *stv2; AN(stv->name); - if (p == NULL) + if (name == NULL) bprintf(stv->ident, "s%u", seq++); else { - if (VCT_invalid_name(spec, p) != NULL) - ARGV_ERR("invalid storage name (-s %s)\n", spec); /* XXX: no need for truncation once VSM ident becomes dynamic */ - l = p - spec; + l = name - spec; if (l > sizeof stv->ident - 1) l = sizeof stv->ident - 1; bprintf(stv->ident, "%.*s", l, spec); diff --git a/bin/varnishtest/tests/r02325.vtc b/bin/varnishtest/tests/r02325.vtc index 0c6ad4d..7b357e5 100644 --- a/bin/varnishtest/tests/r02325.vtc +++ b/bin/varnishtest/tests/r02325.vtc @@ -1,5 +1,8 @@ varnishtest "validate storage identifiers" -shell -err -expect "Error: invalid storage name (-s ...=malloc)" { - varnishd -a :0 -n ${tmpdir} -F -f '' -s ...=malloc +shell -err -expect {Error: invalid -s name "///"=[...]} { + varnishd -a :0 -n ${tmpdir} -F -f '' -s ///=malloc +} +shell -err -expect {Error: Empty named -s argument "foo="} { + varnishd -a :0 -n ${tmpdir} -F -f '' -s foo= } From phk at FreeBSD.org Sat Aug 12 21:08:16 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 12 Aug 2017 23:08:16 +0200 Subject: [master] 26d26d3 Rename the acceptor field "name" to "endpoint" Message-ID: commit 26d26d309f4bf50cb98c9fdd1ad604e05c099174 Author: Poul-Henning Kamp Date: Sat Aug 12 13:08:31 2017 +0000 Rename the acceptor field "name" to "endpoint" diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 1cb34f1..fc99491 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -358,7 +358,7 @@ vca_make_session(struct worker *wrk, void *arg) VSL(SLT_Begin, sp->vxid, "sess 0 %s", wa->acceptlsock->transport->name); VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s %.6f %d", - raddr, rport, wa->acceptlsock->name, laddr, lport, + raddr, rport, wa->acceptlsock->endpoint, laddr, lport, sp->t_open, sp->fd); WS_Release(wrk->aws, 0); diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h index 3955690..987b072 100644 --- a/bin/varnishd/common/heritage.h +++ b/bin/varnishd/common/heritage.h @@ -38,7 +38,7 @@ struct listen_arg { unsigned magic; #define LISTEN_ARG_MAGIC 0xbb2fc333 VTAILQ_ENTRY(listen_arg) list; - const char *name; + const char *endpoint; VTAILQ_HEAD(,listen_sock) socks; const struct transport *transport; }; @@ -49,7 +49,7 @@ struct listen_sock { VTAILQ_ENTRY(listen_sock) list; VTAILQ_ENTRY(listen_sock) arglist; int sock; - char *name; + char *endpoint; struct suckaddr *addr; const struct transport *transport; }; diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index 38be706..83969b4 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -89,11 +89,11 @@ MAC_reopen_sockets(struct cli *cli) if (cli == NULL) MGT_Complain(C_ERR, "Could not reopen listen socket %s: %s", - ls->name, strerror(fail)); + ls->endpoint, strerror(fail)); else VCLI_Out(cli, "Could not reopen listen socket %s: %s\n", - ls->name, strerror(fail)); + ls->endpoint, strerror(fail)); } } @@ -113,26 +113,26 @@ mac_callback(void *priv, const struct suckaddr *sa) VTAILQ_FOREACH(ls, &heritage.socks, list) { if (!VSA_Compare(sa, ls->addr)) ARGV_ERR("-a arguments %s and %s have same address\n", - ls->name, la->name); + ls->endpoint, la->endpoint); } ALLOC_OBJ(ls, LISTEN_SOCK_MAGIC); AN(ls); ls->sock = -1; ls->addr = VSA_Clone(sa); AN(ls->addr); - ls->name = strdup(la->name); - AN(ls->name); + ls->endpoint = strdup(la->endpoint); + AN(ls->endpoint); ls->transport = la->transport; VJ_master(JAIL_MASTER_PRIVPORT); fail = mac_opensocket(ls); VJ_master(JAIL_MASTER_LOW); if (fail) { free(ls->addr); - free(ls->name); + free(ls->endpoint); FREE_OBJ(ls); if (fail != EAFNOSUPPORT) ARGV_ERR("Could not get socket %s: %s\n", - la->name, strerror(fail)); + la->endpoint, strerror(fail)); return(0); } if (VSA_Port(ls->addr) == 0) { @@ -146,7 +146,7 @@ mac_callback(void *priv, const struct suckaddr *sa) VTCP_myname(ls->sock, abuf, sizeof abuf, pbuf, sizeof pbuf); bprintf(nbuf, "%s:%s", abuf, pbuf); - REPLACE(ls->name, nbuf); + REPLACE(ls->endpoint, nbuf); } VTAILQ_INSERT_TAIL(&la->socks, ls, arglist); VTAILQ_INSERT_TAIL(&heritage.socks, ls, list); @@ -172,7 +172,7 @@ MAC_Arg(const char *arg) AN(la); VTAILQ_INIT(&la->socks); VTAILQ_INSERT_TAIL(&listen_args, la, list); - la->name = av[1]; + la->endpoint = av[1]; if (av[2] == NULL) { xp = XPORT_Find("http/1"); From phk at FreeBSD.org Sat Aug 12 21:08:16 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 12 Aug 2017 23:08:16 +0200 Subject: [master] 0630b48 Copy the argument name to malloc'ed storage. Message-ID: commit 0630b480fa35b0f8d4dbf8b9e9bece6173f10010 Author: Poul-Henning Kamp Date: Sat Aug 12 14:31:23 2017 +0000 Copy the argument name to malloc'ed storage. diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 2a230db..0a4efbd 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -180,7 +180,7 @@ void mgt_DumpRstVsl(void); struct vsb *mgt_BuildVident(void); void MGT_Complain(const char *, const char *, ...) __v_printflike(2, 3); const void *MGT_Pick(const struct choice *, const char *, const char *); -char **MGT_NamedArg(const char *arg, const char **name, const char *what); +char **MGT_NamedArg(const char *, const char **, const char *); /* stevedore_mgt.c */ diff --git a/bin/varnishd/mgt/mgt_util.c b/bin/varnishd/mgt/mgt_util.c index 9263af8..2431532 100644 --- a/bin/varnishd/mgt/mgt_util.c +++ b/bin/varnishd/mgt/mgt_util.c @@ -194,7 +194,9 @@ char ** MGT_NamedArg(const char *spec, const char **name, const char *what) { const char *p, *q; + char *r; char **av; + int l; ASSERT_MGT(); p = strchr(spec, '='); @@ -214,6 +216,15 @@ MGT_NamedArg(const char *spec, const char **name, const char *what) if (av[0] != NULL) ARGV_ERR("%s\n", av[0]); - *name = p; + if (p == NULL) { + *name = NULL; + } else { + l = p - spec; + r = malloc(1L + l); + AN(r); + memcpy(r, spec, l); + r[l] = '\0'; + *name = r; + } return (av); } diff --git a/bin/varnishd/storage/mgt_stevedore.c b/bin/varnishd/storage/mgt_stevedore.c index 60791a7..f6ce78e 100644 --- a/bin/varnishd/storage/mgt_stevedore.c +++ b/bin/varnishd/storage/mgt_stevedore.c @@ -178,10 +178,10 @@ STV_Config(const char *spec) bprintf(stv->ident, "s%u", seq++); else { /* XXX: no need for truncation once VSM ident becomes dynamic */ - l = name - spec; + l = strlen(name); if (l > sizeof stv->ident - 1) l = sizeof stv->ident - 1; - bprintf(stv->ident, "%.*s", l, spec); + bprintf(stv->ident, "%.*s", l, name); } stv_check_ident(spec, stv->ident); From phk at FreeBSD.org Sat Aug 12 21:08:16 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 12 Aug 2017 23:08:16 +0200 Subject: [master] 1fa2d44 Make it possible to name -a arguments Message-ID: commit 1fa2d446c80359163989f56c99caac9afdea4749 Author: Poul-Henning Kamp Date: Sat Aug 12 21:07:17 2017 +0000 Make it possible to name -a arguments diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h index 987b072..528bc1e 100644 --- a/bin/varnishd/common/heritage.h +++ b/bin/varnishd/common/heritage.h @@ -39,6 +39,7 @@ struct listen_arg { #define LISTEN_ARG_MAGIC 0xbb2fc333 VTAILQ_ENTRY(listen_arg) list; const char *endpoint; + const char *name; VTAILQ_HEAD(,listen_sock) socks; const struct transport *transport; }; @@ -50,6 +51,7 @@ struct listen_sock { VTAILQ_ENTRY(listen_sock) arglist; int sock; char *endpoint; + const char *name; struct suckaddr *addr; const struct transport *transport; }; diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index 83969b4..a4e7e41 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -122,6 +122,7 @@ mac_callback(void *priv, const struct suckaddr *sa) AN(ls->addr); ls->endpoint = strdup(la->endpoint); AN(ls->endpoint); + la->name = ls->name; ls->transport = la->transport; VJ_master(JAIL_MASTER_PRIVPORT); fail = mac_opensocket(ls); @@ -154,25 +155,24 @@ mac_callback(void *priv, const struct suckaddr *sa) } void -MAC_Arg(const char *arg) +MAC_Arg(const char *spec) { char **av; struct listen_arg *la; const char *err; int error; const struct transport *xp; + const char *name; - av = VAV_Parse(arg, NULL, ARGV_COMMA); - if (av == NULL) - ARGV_ERR("Parse error: out of memory\n"); - if (av[0] != NULL) - ARGV_ERR("%s\n", av[0]); + av = MGT_NamedArg(spec, &name, "-a"); + AN(av); ALLOC_OBJ(la, LISTEN_ARG_MAGIC); AN(la); VTAILQ_INIT(&la->socks); VTAILQ_INSERT_TAIL(&listen_args, la, list); la->endpoint = av[1]; + la->name = name; if (av[2] == NULL) { xp = XPORT_Find("http/1"); diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 31f9bf7..8b6c643 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -838,7 +838,7 @@ main(int argc, char * const *argv) } if (VTAILQ_EMPTY(&heritage.socks)) - MAC_Arg(":80"); + MAC_Arg(":80\0"); // XXX: extra NUL for FlexeLint assert(!VTAILQ_EMPTY(&heritage.socks)); From phk at FreeBSD.org Sun Aug 13 08:16:10 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sun, 13 Aug 2017 10:16:10 +0200 Subject: [master] b7fada9 Log the named acceptors name in SessOpen instead of the endpoint. Message-ID: commit b7fada92f9b73fb471679c5ec14b990c4d6e529d Author: Poul-Henning Kamp Date: Sun Aug 13 08:14:57 2017 +0000 Log the named acceptors name in SessOpen instead of the endpoint. diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index fc99491..f86f648 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -358,7 +358,10 @@ vca_make_session(struct worker *wrk, void *arg) VSL(SLT_Begin, sp->vxid, "sess 0 %s", wa->acceptlsock->transport->name); VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s %.6f %d", - raddr, rport, wa->acceptlsock->endpoint, laddr, lport, + raddr, rport, + wa->acceptlsock->name != NULL ? + wa->acceptlsock->name : wa->acceptlsock->endpoint, + laddr, lport, sp->t_open, sp->fd); WS_Release(wrk->aws, 0); diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index a4e7e41..48e54a0 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -122,7 +122,7 @@ mac_callback(void *priv, const struct suckaddr *sa) AN(ls->addr); ls->endpoint = strdup(la->endpoint); AN(ls->endpoint); - la->name = ls->name; + ls->name = la->name; ls->transport = la->transport; VJ_master(JAIL_MASTER_PRIVPORT); fail = mac_opensocket(ls); diff --git a/bin/varnishtest/tests/r01804.vtc b/bin/varnishtest/tests/r01804.vtc index c6705eb..983091d 100644 --- a/bin/varnishtest/tests/r01804.vtc +++ b/bin/varnishtest/tests/r01804.vtc @@ -6,14 +6,16 @@ server s1 { } -start -varnish v1 -proto "PROXY" -vcl+backend { +varnish v1 -arg "-afoo=127.0.0.1:0,PROXY" -vcl+backend { } -start logexpect l1 -v v1 -d 0 -g session { expect * * Begin {^sess .* PROXY$} + expect * = SessOpen {^.* foo .*} expect * = Proxy {^1 } expect * * Begin {^req} expect * * Begin {^sess .* PROXY$} + expect * = SessOpen {^.* foo .*} expect * = Proxy {^2 } expect * * Begin {^req} } -start diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 04e490c..30d8456 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -78,6 +78,7 @@ struct varnish { struct vsm *vd; /* vsc use */ struct vsm *vdl; /* log use */ + int has_a_arg; struct vsm_fantom mgt_arg_i; unsigned vsl_tag_count[256]; @@ -433,9 +434,11 @@ varnish_launch(struct varnish *v) VSB_printf(vsb, " -p sigsegv_handler=on"); VSB_printf(vsb, " -p thread_pool_min=10"); VSB_printf(vsb, " -p debug=+vtc_mode"); - VSB_printf(vsb, " -a '%s'", "127.0.0.1:0"); - if (v->proto != NULL) - VSB_printf(vsb, ",%s", v->proto); + if (!v->has_a_arg) { + VSB_printf(vsb, " -a '%s'", "127.0.0.1:0"); + if (v->proto != NULL) + VSB_printf(vsb, ",%s", v->proto); + } VSB_printf(vsb, " -M '%s %s'", abuf, pbuf); VSB_printf(vsb, " -P %s/varnishd.pid", v->workdir); if (vmod_path != NULL) @@ -1105,6 +1108,8 @@ cmd_varnish(CMD_ARGS) AZ(v->pid); VSB_cat(v->args, " "); VSB_cat(v->args, av[1]); + if (av[1][0] == '-' && av[1][1] == 'a') + v->has_a_arg = 1; av++; continue; } From phk at FreeBSD.org Mon Aug 14 06:56:05 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 14 Aug 2017 08:56:05 +0200 Subject: [master] ccc0ca0 Add some protective asserts Message-ID: commit ccc0ca079aa7657abe241b6488bed641510ed3a5 Author: Poul-Henning Kamp Date: Mon Aug 14 06:55:18 2017 +0000 Add some protective asserts diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c index 8954b92..68ded26 100644 --- a/lib/libvarnishapi/vut.c +++ b/lib/libvarnishapi/vut.c @@ -209,6 +209,11 @@ VUT_Init(const char *progname, int argc, char * const *argv, const struct vopt_spec *voc) { + AN(progname); + AN(argv); + AN(voc); + AZ(VUT.progname); + if (argc == 2 && !strcmp(argv[1], "--synopsis")) exit(vut_synopsis(voc)); if (argc == 2 && !strcmp(argv[1], "--options")) @@ -293,6 +298,8 @@ VUT_Setup(void) void VUT_Fini(void) { + AN(VUT.progname); + free(VUT.n_arg); free(VUT.r_arg); free(VUT.P_arg); From varnish-commit at varnish-cache.org Mon Aug 14 06:58:17 2017 From: varnish-commit at varnish-cache.org (=?utf-8?B?6bq7?=) Date: Mon, 14 Aug 2017 14:58:17 +0800 Subject: =?utf-8?B?56CU5Y+R57uP55CG55qE6aKG5a+85Yqb5LiO5omn6KGM5YqbIDIwMTfvvJvpurs=?= Message-ID: <20170814145822538234@mes.zhonghai.net> ???????? -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ???????????? 2017.docx Type: application/octet-stream Size: 156136 bytes Desc: not available URL: From phk at FreeBSD.org Mon Aug 14 07:13:16 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 14 Aug 2017 09:13:16 +0200 Subject: [master] 9ce0967 De-constify part of the VSM api in preparation for the New World Order. Message-ID: commit 9ce096796841ca1f9ba4214447e85aa862127827 Author: Poul-Henning Kamp Date: Mon Aug 14 07:11:42 2017 +0000 De-constify part of the VSM api in preparation for the New World Order. diff --git a/include/vapi/vsm.h b/include/vapi/vsm.h index ce851b0..6a22c70 100644 --- a/include/vapi/vsm.h +++ b/include/vapi/vsm.h @@ -88,7 +88,7 @@ void VSM_ResetError(struct vsm *vd); #define VSM_n_USAGE "[-n varnish_name]" -int VSM_n_Arg(struct vsm *vd, const char *n_arg); +int VSM_n_Arg(struct vsm *, const char *n_arg); /* * Configure which varnishd instance to access. * Uses hostname if n_arg is NULL or "". @@ -98,14 +98,14 @@ int VSM_n_Arg(struct vsm *vd, const char *n_arg); * <0 on failure, VSM_Error() returns diagnostic string */ -int VSM_Start(struct vsm *vd, double patience, int progress_fd); +int VSM_Start(struct vsm *, double patience, int progress_fd); -const char *VSM_Name(const struct vsm *vd); +const char *VSM_Name(struct vsm *); /* * Return the instance name (-i argument to varnishd) */ -int VSM_Open(struct vsm *vd); +int VSM_Open(struct vsm *); /* * Attempt to open and map the VSM file. * @@ -144,8 +144,8 @@ void VSM_Close(struct vsm *vd); */ -void VSM__iter0(const struct vsm *vd, struct vsm_fantom *vf); -int VSM__itern(const struct vsm *vd, struct vsm_fantom *vf); +void VSM__iter0(struct vsm *, struct vsm_fantom *vf); +int VSM__itern(struct vsm *, struct vsm_fantom *vf); #define VSM_FOREACH(vf, vd) \ for (VSM__iter0((vd), (vf)); VSM__itern((vd), (vf));) @@ -155,8 +155,8 @@ int VSM__itern(const struct vsm *vd, struct vsm_fantom *vf); * vd = "struct vsm *" */ -int VSM_Map(struct vsm *vd, struct vsm_fantom *vf); -int VSM_Unmap(struct vsm *vd, struct vsm_fantom *vf); +int VSM_Map(struct vsm *, struct vsm_fantom *vf); +int VSM_Unmap(struct vsm *, struct vsm_fantom *vf); struct vsm_valid { const char *name; @@ -166,8 +166,7 @@ extern const struct vsm_valid VSM_invalid[]; extern const struct vsm_valid VSM_valid[]; extern const struct vsm_valid VSM_similar[]; -const struct vsm_valid *VSM_StillValid(const struct vsm *vd, - struct vsm_fantom *vf); +const struct vsm_valid *VSM_StillValid(struct vsm *, struct vsm_fantom *vf); /* * Check the validity of a previously looked up vsm_fantom. * @@ -198,7 +197,7 @@ const struct vsm_valid *VSM_StillValid(const struct vsm *vd, * VSM_similar: a fantom with same dimensions exist in same position. */ -int VSM_Get(const struct vsm *vd, struct vsm_fantom *vf, +int VSM_Get(struct vsm *, struct vsm_fantom *vf, const char *class, const char *ident); /* * Find a chunk, produce fantom for it. diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index a92a84c..b397912 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -238,7 +238,7 @@ VSM_Start(struct vsm *vd, double patience, int progress) /*--------------------------------------------------------------------*/ const char * -VSM_Name(const struct vsm *vd) +VSM_Name(struct vsm *vd) { struct vsm_fantom vt; @@ -426,7 +426,7 @@ VSM_Abandoned(struct vsm *vd) /*--------------------------------------------------------------------*/ void -VSM__iter0(const struct vsm *vd, struct vsm_fantom *vf) +VSM__iter0(struct vsm *vd, struct vsm_fantom *vf) { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); @@ -436,7 +436,7 @@ VSM__iter0(const struct vsm *vd, struct vsm_fantom *vf) } int -VSM__itern(const struct vsm *vd, struct vsm_fantom *vf) +VSM__itern(struct vsm *vd, struct vsm_fantom *vf) { struct VSM_chunk *c = NULL; @@ -512,7 +512,7 @@ VSM_Unmap(struct vsm *vd, struct vsm_fantom *vf) /*--------------------------------------------------------------------*/ const struct vsm_valid * -VSM_StillValid(const struct vsm *vd, struct vsm_fantom *vf) +VSM_StillValid(struct vsm *vd, struct vsm_fantom *vf) { struct vsm_fantom f2; @@ -542,7 +542,7 @@ VSM_StillValid(const struct vsm *vd, struct vsm_fantom *vf) } int -VSM_Get(const struct vsm *vd, struct vsm_fantom *vf, +VSM_Get(struct vsm *vd, struct vsm_fantom *vf, const char *class, const char *ident) { From dridi.boukelmoune at gmail.com Mon Aug 14 09:02:06 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 11:02:06 +0200 Subject: [master] 9713099 Simplify VCL global symbols registration Message-ID: commit 971309930ad4fdb5820b87dfe9956bc86bc04d2f Author: Dridi Boukelmoune Date: Thu Jun 22 17:37:35 2017 +0200 Simplify VCL global symbols registration Instead of a printf format, a mandatory prefix is expected. Refs #2325 diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c index c98dfea..08fc9d8 100644 --- a/lib/libvcc/vcc_acl.c +++ b/lib/libvcc/vcc_acl.c @@ -485,7 +485,7 @@ vcc_ParseAcl(struct vcc *tl) acln = TlDupTok(tl, an); - (void)VCC_HandleSymbol(tl, an, ACL, "&vrt_acl_named_%s", acln); + (void)VCC_HandleSymbol(tl, an, ACL, "&vrt_acl_named"); ERRCHK(tl); SkipToken(tl, '{'); diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c index 7909044..7377af6 100644 --- a/lib/libvcc/vcc_backend.c +++ b/lib/libvcc/vcc_backend.c @@ -258,8 +258,7 @@ vcc_ParseProbe(struct vcc *tl) t_probe = tl->t; vcc_NextToken(tl); - (void)VCC_HandleSymbol(tl, t_probe, PROBE, "&vgc_probe_%.*s", - PF(t_probe)); + (void)VCC_HandleSymbol(tl, t_probe, PROBE, "&vgc_probe"); ERRCHK(tl); vcc_ParseProbeSpec(tl, t_probe, &p); @@ -481,7 +480,7 @@ vcc_ParseBackend(struct vcc *tl) bprintf(vgcname, "vgc_backend_%.*s", PF(t_be)); Fh(tl, 0, "\nstatic struct director *%s;\n", vgcname); - sym = VCC_HandleSymbol(tl, t_be, BACKEND, "%s", vgcname); + sym = VCC_HandleSymbol(tl, t_be, BACKEND, "vgc_backend"); ERRCHK(tl); vcc_ParseHostDef(tl, t_be, vgcname); diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index 2ab1a66..1768bdd 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -280,7 +280,7 @@ void vcc_Eval_Func(struct vcc *tl, const char *spec, const char *extra, const struct symbol *sym); enum symkind VCC_HandleKind(vcc_type_t fmt); struct symbol *VCC_HandleSymbol(struct vcc *, const struct token *, - vcc_type_t fmt, const char *str, ...); + vcc_type_t fmt, const char *pfx); /* vcc_obj.c */ extern const struct var vcc_vars[]; diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c index 0d68e48..1d33597 100644 --- a/lib/libvcc/vcc_symb.c +++ b/lib/libvcc/vcc_symb.c @@ -179,14 +179,16 @@ VCC_WalkSymbols(struct vcc *tl, symwalk_f *func, enum symkind kind) } static void -vcc_global(struct vcc *tl, struct symbol *sym, - vcc_type_t fmt, const char *str, va_list ap) +vcc_global(struct vcc *tl, struct symbol *sym, vcc_type_t fmt, const char *pfx) { struct vsb *vsb; + CHECK_OBJ_NOTNULL(sym, SYMBOL_MAGIC); + AN(pfx); + vsb = VSB_new_auto(); AN(vsb); - VSB_vprintf(vsb, str, ap); + VSB_printf(vsb, "%s_%s", pfx, sym->name); AZ(VSB_finish(vsb)); if (tl != NULL) sym->rname = TlDup(tl, VSB_data(vsb)); @@ -194,6 +196,7 @@ vcc_global(struct vcc *tl, struct symbol *sym, sym->rname = strdup(VSB_data(vsb)); AN(sym->rname); VSB_destroy(&vsb); + sym->fmt = fmt; sym->kind = VCC_HandleKind(sym->fmt); if (sym->kind != SYM_NONE) @@ -207,12 +210,11 @@ vcc_global(struct vcc *tl, struct symbol *sym, struct symbol * VCC_HandleSymbol(struct vcc *tl, const struct token *tk, vcc_type_t fmt, - const char *str, ...) + const char *pfx) { struct symbol *sym; enum symkind kind; const char *p; - va_list ap; kind = VCC_HandleKind(fmt); assert(kind != SYM_NONE); @@ -245,9 +247,7 @@ VCC_HandleSymbol(struct vcc *tl, const struct token *tk, vcc_type_t fmt, sym = VCC_SymbolTok(tl, NULL, tk, kind, 1); AN(sym); AZ(sym->ndef); - va_start(ap, str); - vcc_global(tl, sym, fmt, str, ap); - va_end(ap); + vcc_global(tl, sym, fmt, pfx); sym->ndef = 1; if (sym->def_b == NULL) sym->def_b = tk; diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c index b378ccf..e3449ea 100644 --- a/lib/libvcc/vcc_vmod.c +++ b/lib/libvcc/vcc_vmod.c @@ -282,7 +282,7 @@ vcc_ParseNew(struct vcc *tl) ExpectErr(tl, ID); vcc_ExpectCid(tl, "VCL object"); ERRCHK(tl); - sy1 = VCC_HandleSymbol(tl, tl->t, INSTANCE, "XXX"); + sy1 = VCC_HandleSymbol(tl, tl->t, INSTANCE, "vo"); ERRCHK(tl); /* We allow implicit use of VMOD objects: Pretend it's ref'ed */ @@ -309,10 +309,10 @@ vcc_ParseNew(struct vcc *tl) s_obj = p; p += strlen(p) + 1; - Fh(tl, 0, "static %s *vo_%s;\n\n", p, sy1->name); + Fh(tl, 0, "static %s *%s;\n\n", p, sy1->rname); p += strlen(p) + 1; - bprintf(buf1, ", &vo_%s, \"%s\"", sy1->name, sy1->name); + bprintf(buf1, ", &%s, \"%s\"", sy1->rname, sy1->name); vcc_Eval_Func(tl, p, buf1, sy2); ExpectErr(tl, ';'); @@ -322,14 +322,14 @@ vcc_ParseNew(struct vcc *tl) ifp = New_IniFin(tl); p += strlen(p) + 1; - VSB_printf(ifp->fin, "\t\t%s(&vo_%s);", p, sy1->name); + VSB_printf(ifp->fin, "\t\t%s(&%s);", p, sy1->rname); while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0') p++; p += 3; /* Instantiate symbols for the methods */ - bprintf(buf1, ", vo_%s", sy1->name); + bprintf(buf1, ", %s", sy1->rname); while (*p != '\0') { p += strlen(s_obj); bprintf(buf2, "%s%s", sy1->name, p); From dridi.boukelmoune at gmail.com Mon Aug 14 09:02:06 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 11:02:06 +0200 Subject: [master] bdbba2e Return the symbol when referenced or defined Message-ID: commit bdbba2ec194513cd79ab4ea533328cf21e4ea2cb Author: Dridi Boukelmoune Date: Wed Jun 28 08:51:39 2017 +0200 Return the symbol when referenced or defined diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c index 924e3ed..17293f5 100644 --- a/lib/libvcc/vcc_action.c +++ b/lib/libvcc/vcc_action.c @@ -46,7 +46,7 @@ parse_call(struct vcc *tl) vcc_NextToken(tl); ExpectErr(tl, ID); vcc_AddCall(tl, tl->t); - vcc_AddRef(tl, tl->t, SYM_SUB); + (void)vcc_AddRef(tl, tl->t, SYM_SUB); Fb(tl, 1, "VGC_function_%.*s(ctx);\n", PF(tl->t)); vcc_NextToken(tl); } diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c index 7377af6..6c9a178 100644 --- a/lib/libvcc/vcc_backend.c +++ b/lib/libvcc/vcc_backend.c @@ -263,7 +263,7 @@ vcc_ParseProbe(struct vcc *tl) vcc_ParseProbeSpec(tl, t_probe, &p); if (vcc_IdIs(t_probe, "default")) { - vcc_AddRef(tl, t_probe, SYM_PROBE); + (void)vcc_AddRef(tl, t_probe, SYM_PROBE); tl->default_probe = p; } } @@ -395,7 +395,7 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname) return; } Fb(tl, 0, "\t.probe = &vgc_probe_%.*s,\n", PF(tl->t)); - vcc_AddRef(tl, tl->t, SYM_PROBE); + (void)vcc_AddRef(tl, tl->t, SYM_PROBE); vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "probe")) { diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c index 1f9b0eb..bf57ee9 100644 --- a/lib/libvcc/vcc_compile.c +++ b/lib/libvcc/vcc_compile.c @@ -619,7 +619,7 @@ vcc_CompileSource(struct vcc *tl, struct source *sp) } /* Configure the default director */ - vcc_AddRef(tl, tl->t_default_director, SYM_BACKEND); + (void)vcc_AddRef(tl, tl->t_default_director, SYM_BACKEND); /* Check for orphans */ if (vcc_CheckReferences(tl)) diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index 1768bdd..bc43b78 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -337,8 +337,10 @@ void vcc_ParseImport(struct vcc *tl); void vcc_ParseNew(struct vcc *tl); /* vcc_xref.c */ -int vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind type); -void vcc_AddRef(struct vcc *tl, const struct token *t, enum symkind type); +struct symbol *vcc_AddDef(struct vcc *tl, const struct token *t, + enum symkind type); +struct symbol *vcc_AddRef(struct vcc *tl, const struct token *t, + enum symkind type); int vcc_CheckReferences(struct vcc *tl); void VCC_XrefTable(struct vcc *); diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index abd210e..0d41901 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -469,10 +469,10 @@ vcc_Eval_Handle(struct vcc *tl, struct expr **e, const struct symbol *sym, if (sym->fmt != STRING && (fmt == STRING || fmt == STRING_LIST)) { *e = vcc_mk_expr(STRING, "\"%s\"", sym->name); - vcc_AddRef(tl, tl->t, sym->kind); + (void)vcc_AddRef(tl, tl->t, sym->kind); } else { vcc_ExpectCid(tl, "handle"); - vcc_AddRef(tl, tl->t, sym->kind); + (void)vcc_AddRef(tl, tl->t, sym->kind); *e = vcc_mk_expr(sym->fmt, "%s", sym->rname); (*e)->constant = EXPR_VAR; /* XXX ? */ } @@ -1203,7 +1203,7 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt) not = tl->t->tok == '~' ? "" : "!"; vcc_NextToken(tl); vcc_ExpectCid(tl, "ACL"); - vcc_AddRef(tl, tl->t, SYM_ACL); + (void)vcc_AddRef(tl, tl->t, SYM_ACL); bprintf(buf, "%smatch_acl_named_%.*s(ctx, \v1)", not, PF(tl->t)); vcc_NextToken(tl); diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c index 6e28970..abc58b2 100644 --- a/lib/libvcc/vcc_parse.c +++ b/lib/libvcc/vcc_parse.c @@ -209,6 +209,7 @@ vcc_Compound(struct vcc *tl) static void vcc_ParseFunction(struct vcc *tl) { + struct symbol *sym; int m, i; vcc_NextToken(tl); @@ -229,7 +230,7 @@ vcc_ParseFunction(struct vcc *tl) tl->fb = tl->fm[m]; if (tl->mprocs[m] == NULL) { (void)vcc_AddDef(tl, tl->t, SYM_SUB); - vcc_AddRef(tl, tl->t, SYM_SUB); + (void)vcc_AddRef(tl, tl->t, SYM_SUB); tl->mprocs[m] = vcc_AddProc(tl, tl->t); } tl->curproc = tl->mprocs[m]; @@ -238,8 +239,8 @@ vcc_ParseFunction(struct vcc *tl) Fb(tl, 0, " */\n"); } else { tl->fb = tl->fc; - i = vcc_AddDef(tl, tl->t, SYM_SUB); - if (i > 1) { + sym = vcc_AddDef(tl, tl->t, SYM_SUB); + if (sym->ndef > 1) { VSB_printf(tl->sb, "Function '%.*s' redefined\n", PF(tl->t)); vcc_ErrWhere(tl, tl->t); diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c index 166bfe4..7b6f6a7 100644 --- a/lib/libvcc/vcc_xref.c +++ b/lib/libvcc/vcc_xref.c @@ -73,7 +73,7 @@ struct proc { * Keep track of definitions and references */ -void +struct symbol * vcc_AddRef(struct vcc *tl, const struct token *t, enum symkind kind) { struct symbol *sym; @@ -83,9 +83,10 @@ vcc_AddRef(struct vcc *tl, const struct token *t, enum symkind kind) sym->ref_b = t; AN(sym); sym->nref++; + return (sym); } -int +struct symbol * vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind kind) { struct symbol *sym; @@ -95,7 +96,7 @@ vcc_AddDef(struct vcc *tl, const struct token *t, enum symkind kind) sym->def_b = t; AN(sym); sym->ndef++; - return (sym->ndef); + return (sym); } /*--------------------------------------------------------------------*/ From dridi.boukelmoune at gmail.com Mon Aug 14 09:02:06 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 11:02:06 +0200 Subject: [master] d488c05 Allow direct calls to global symbol registration Message-ID: commit d488c050a8746f3952720ab52169c1bd6d7e0064 Author: Dridi Boukelmoune Date: Wed Jun 28 10:15:28 2017 +0200 Allow direct calls to global symbol registration Refs #2325 diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c index bf57ee9..f6660fd 100644 --- a/lib/libvcc/vcc_compile.c +++ b/lib/libvcc/vcc_compile.c @@ -568,9 +568,9 @@ vcc_CompileSource(struct vcc *tl, struct source *sp) sym->fmt = v->fmt; sym->eval = vcc_Eval_Var; sym->r_methods = v->r_methods; - sym->rname = v->rname; sym->w_methods = v->w_methods; sym->lname = v->lname; + REPLACE(sym->rname, v->rname); } Fh(tl, 0, "/* ---===### VCC generated .h code ###===---*/\n"); diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index bc43b78..17ceba0 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -137,7 +137,7 @@ struct symbol { const char *extra; /* SYM_VAR */ - const char *rname; + char *rname; unsigned r_methods; const char *lname; unsigned w_methods; @@ -279,6 +279,7 @@ sym_expr_t vcc_Eval_SymFunc; void vcc_Eval_Func(struct vcc *tl, const char *spec, const char *extra, const struct symbol *sym); enum symkind VCC_HandleKind(vcc_type_t fmt); +void VCC_GlobalSymbol(struct symbol *, vcc_type_t fmt, const char *pfx); struct symbol *VCC_HandleSymbol(struct vcc *, const struct token *, vcc_type_t fmt, const char *pfx); diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 0d41901..3ab20b6 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -1150,6 +1150,7 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt) const char *re; const char *not; struct token *tk; + struct symbol *sym; enum symkind kind; *e = NULL; diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c index 1d33597..045a239 100644 --- a/lib/libvcc/vcc_symb.c +++ b/lib/libvcc/vcc_symb.c @@ -178,8 +178,8 @@ VCC_WalkSymbols(struct vcc *tl, symwalk_f *func, enum symkind kind) vcc_walksymbols(tl, tl->symbols, func, kind); } -static void -vcc_global(struct vcc *tl, struct symbol *sym, vcc_type_t fmt, const char *pfx) +void +VCC_GlobalSymbol(struct symbol *sym, vcc_type_t fmt, const char *pfx) { struct vsb *vsb; @@ -190,10 +190,7 @@ vcc_global(struct vcc *tl, struct symbol *sym, vcc_type_t fmt, const char *pfx) AN(vsb); VSB_printf(vsb, "%s_%s", pfx, sym->name); AZ(VSB_finish(vsb)); - if (tl != NULL) - sym->rname = TlDup(tl, VSB_data(vsb)); - else - sym->rname = strdup(VSB_data(vsb)); + REPLACE(sym->rname, VSB_data(vsb)); AN(sym->rname); VSB_destroy(&vsb); @@ -247,7 +244,7 @@ VCC_HandleSymbol(struct vcc *tl, const struct token *tk, vcc_type_t fmt, sym = VCC_SymbolTok(tl, NULL, tk, kind, 1); AN(sym); AZ(sym->ndef); - vcc_global(tl, sym, fmt, pfx); + VCC_GlobalSymbol(sym, fmt, pfx); sym->ndef = 1; if (sym->def_b == NULL) sym->def_b = tk; diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c index 6428b86..50fa9e9 100644 --- a/lib/libvcc/vcc_var.c +++ b/lib/libvcc/vcc_var.c @@ -29,6 +29,9 @@ #include "config.h" +#include +#include + #include "vcc_compile.h" #include "vct.h" @@ -90,9 +93,9 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, sym->fmt = v->fmt; sym->eval = vcc_Eval_Var; sym->r_methods = v->r_methods; - sym->rname = v->rname; sym->w_methods = v->w_methods; sym->lname = v->lname; + REPLACE(sym->rname, v->rname); } /*--------------------------------------------------------------------*/ From dridi.boukelmoune at gmail.com Mon Aug 14 09:02:06 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 11:02:06 +0200 Subject: [master] d1a614e Emit named ACLs using their symbol Message-ID: commit d1a614ee7e88825429686fd79f0cfc487df0247f Author: Dridi Boukelmoune Date: Wed Jun 28 10:31:54 2017 +0200 Emit named ACLs using their symbol For that, an indirection via VRT_acl_match is needed, because ACLs are a special case being functions. However they've had "regular" symbols ever since VMODs learned to use them. Refs #2325 diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c index 08fc9d8..2a733d2 100644 --- a/lib/libvcc/vcc_acl.c +++ b/lib/libvcc/vcc_acl.c @@ -485,7 +485,7 @@ vcc_ParseAcl(struct vcc *tl) acln = TlDupTok(tl, an); - (void)VCC_HandleSymbol(tl, an, ACL, "&vrt_acl_named"); + (void)VCC_HandleSymbol(tl, an, ACL, ACL_SYMBOL_PREFIX); ERRCHK(tl); SkipToken(tl, '{'); diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index 17ceba0..0a05d21 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -360,3 +360,5 @@ int vcc_CheckUses(struct vcc *tl); do { vcc__Expect(a, b, __LINE__); ERRCHK(a);} while (0) #define SkipToken(a, b) \ do { vcc__Expect(a, b, __LINE__); ERRCHK(a); vcc_NextToken(a); } while (0) + +#define ACL_SYMBOL_PREFIX "&vrt_acl_named" diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 3ab20b6..238ee9d 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -1204,9 +1204,9 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt) not = tl->t->tok == '~' ? "" : "!"; vcc_NextToken(tl); vcc_ExpectCid(tl, "ACL"); - (void)vcc_AddRef(tl, tl->t, SYM_ACL); - bprintf(buf, "%smatch_acl_named_%.*s(ctx, \v1)", - not, PF(tl->t)); + sym = vcc_AddRef(tl, tl->t, SYM_ACL); + VCC_GlobalSymbol(sym, ACL, ACL_SYMBOL_PREFIX); + bprintf(buf, "%sVRT_acl_match(ctx, %s, \v1)", not, sym->rname); vcc_NextToken(tl); *e = vcc_expr_edit(BOOL, buf, *e, NULL); return; From dridi.boukelmoune at gmail.com Mon Aug 14 09:02:06 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 11:02:06 +0200 Subject: [master] 94d0acd Never emit C symbols using VCL tokens Message-ID: commit 94d0acd337b0bfa62a4926076c72ec7da100fbc1 Author: Dridi Boukelmoune Date: Thu Jun 22 17:54:48 2017 +0200 Never emit C symbols using VCL tokens There's already an impedence mismatch between both languages and it's going to increase soon. Refs #2325 diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 13645ea..ed31ae9 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -827,6 +827,7 @@ stv_variables = ( vcltypes = { 'STRING_LIST': "void*", + 'SUB': "void*", } fi = open(join(srcroot, "include/vrt.h")) diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c index 2a733d2..b97ad2c 100644 --- a/lib/libvcc/vcc_acl.c +++ b/lib/libvcc/vcc_acl.c @@ -353,7 +353,7 @@ vcc_acl_emit(struct vcc *tl, const char *acln, int anon) Fh(tl, 0, "\nstatic int __match_proto__(acl_match_f)\n"); Fh(tl, 0, "match_acl_%s_%s(VRT_CTX, const VCL_IP p)\n", - anon ? "anon" : "named", acln); + anon ? "anon" : "named", acln); /* XXX: acln isn't an rname */ Fh(tl, 0, "{\n"); Fh(tl, 0, "\tconst unsigned char *a;\n"); Fh(tl, 0, "\tint fam;\n"); @@ -447,10 +447,10 @@ vcc_acl_emit(struct vcc *tl, const char *acln, int anon) return; /* Emit the struct that will be referenced */ - Fh(tl, 0, "\nconst struct vrt_acl vrt_acl_named_%s = {\n", acln); + Fh(tl, 0, "\nconst struct vrt_acl vrt_acl_named_%s[] = {{\n", acln); Fh(tl, 0, "\t.magic = VRT_ACL_MAGIC,\n"); Fh(tl, 0, "\t.match = &match_acl_named_%s,\n", acln); - Fh(tl, 0, "};\n\n"); + Fh(tl, 0, "}};\n\n"); } void @@ -473,7 +473,7 @@ void vcc_ParseAcl(struct vcc *tl) { struct token *an; - char *acln; + struct symbol *sym; vcc_NextToken(tl); VTAILQ_INIT(&tl->acl); @@ -483,10 +483,9 @@ vcc_ParseAcl(struct vcc *tl) an = tl->t; vcc_NextToken(tl); - acln = TlDupTok(tl, an); - - (void)VCC_HandleSymbol(tl, an, ACL, ACL_SYMBOL_PREFIX); + sym = VCC_HandleSymbol(tl, an, ACL, ACL_SYMBOL_PREFIX); ERRCHK(tl); + AN(sym); SkipToken(tl, '{'); @@ -497,5 +496,5 @@ vcc_ParseAcl(struct vcc *tl) } SkipToken(tl, '}'); - vcc_acl_emit(tl, acln, 0); + vcc_acl_emit(tl, sym->name, 0); } diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c index 17293f5..2c9b046 100644 --- a/lib/libvcc/vcc_action.c +++ b/lib/libvcc/vcc_action.c @@ -42,12 +42,14 @@ static void parse_call(struct vcc *tl) { + struct symbol *sym; vcc_NextToken(tl); ExpectErr(tl, ID); vcc_AddCall(tl, tl->t); - (void)vcc_AddRef(tl, tl->t, SYM_SUB); - Fb(tl, 1, "VGC_function_%.*s(ctx);\n", PF(tl->t)); + sym = vcc_AddRef(tl, tl->t, SYM_SUB); + VCC_GlobalSymbol(sym, SUB, "VGC_function"); + Fb(tl, 1, "%s(ctx);\n", sym->rname); vcc_NextToken(tl); } @@ -251,25 +253,25 @@ parse_return_vcl(struct vcc *tl) return; } if (sym->eval_priv == NULL) { - VSB_printf(tl->fi, "%s VCL %.*s */\n", - VCC_INFO_PREFIX, PF(tl->t)); + VSB_printf(tl->fi, "%s VCL %s */\n", VCC_INFO_PREFIX, + sym->name); bprintf(buf, "vgc_vcl_%u", tl->unique++); sym->eval_priv = strdup(buf); AN(sym->eval_priv); Fh(tl, 0, "static VCL_VCL %s;", buf); - Fh(tl, 0, "\t/* VCL %.*s */\n", PF(tl->t)); + Fh(tl, 0, "\t/* VCL %s */\n", sym->name); p = New_IniFin(tl); AN(p); - VSB_printf(p->ini, "\t%s = VRT_vcl_get(ctx, \"%.*s\");", - buf, PF(tl->t)); + VSB_printf(p->ini, "\t%s = VRT_vcl_get(ctx, \"%s\");", + buf, sym->name); VSB_printf(p->fin, "\tVRT_vcl_rel(ctx, %s);", buf); } - Fb(tl, 1, "VRT_vcl_select(ctx, %s);\t/* %.*s */\n", - (const char*)sym->eval_priv, PF(tl->t)); + Fb(tl, 1, "VRT_vcl_select(ctx, %s);\t/* %s */\n", + (const char*)sym->eval_priv, sym->name); vcc_NextToken(tl); ExpectErr(tl, ')'); vcc_NextToken(tl); diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c index 6c9a178..5775ee2 100644 --- a/lib/libvcc/vcc_backend.c +++ b/lib/libvcc/vcc_backend.c @@ -91,7 +91,7 @@ vcc_ProbeRedef(struct vcc *tl, struct token **t_did, } static void -vcc_ParseProbeSpec(struct vcc *tl, const struct token *nm, char **name) +vcc_ParseProbeSpec(struct vcc *tl, const struct symbol *sym, char **name) { struct fld_spec *fs; struct token *t_field; @@ -117,12 +117,13 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct token *nm, char **name) vsb = VSB_new_auto(); AN(vsb); - if (nm != NULL) - VSB_printf(vsb, "vgc_probe_%.*s", PF(nm)); + if (sym != NULL) + VSB_cat(vsb, sym->rname); else VSB_printf(vsb, "vgc_probe__%d", tl->nprobe++); AZ(VSB_finish(vsb)); retval = TlDup(tl, VSB_data(vsb)); + AN(retval); VSB_destroy(&vsb); if (name != NULL) *name = retval; @@ -131,7 +132,7 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct token *nm, char **name) threshold = 0; initial = 0; status = 0; - Fh(tl, 0, "static const struct vrt_backend_probe %s = {\n", retval); + Fh(tl, 0, "static const struct vrt_backend_probe %s[] = {{\n", retval); Fh(tl, 0, "\t.magic = VRT_BACKEND_PROBE_MAGIC,\n"); while (tl->t->tok != '}') { @@ -237,7 +238,7 @@ vcc_ParseProbeSpec(struct vcc *tl, const struct token *nm, char **name) Fh(tl, 0, "\t.initial = ~0U,\n"); if (status > 0) Fh(tl, 0, "\t.exp_status = %u,\n", status); - Fh(tl, 0, "};\n"); + Fh(tl, 0, "}};\n"); SkipToken(tl, '}'); } @@ -249,6 +250,7 @@ void vcc_ParseProbe(struct vcc *tl) { struct token *t_probe; + struct symbol *sym; char *p; vcc_NextToken(tl); /* ID: probe */ @@ -258,10 +260,11 @@ vcc_ParseProbe(struct vcc *tl) t_probe = tl->t; vcc_NextToken(tl); - (void)VCC_HandleSymbol(tl, t_probe, PROBE, "&vgc_probe"); + sym = VCC_HandleSymbol(tl, t_probe, PROBE, "vgc_probe"); ERRCHK(tl); + AN(sym); - vcc_ParseProbeSpec(tl, t_probe, &p); + vcc_ParseProbeSpec(tl, sym, &p); if (vcc_IdIs(t_probe, "default")) { (void)vcc_AddRef(tl, t_probe, SYM_PROBE); tl->default_probe = p; @@ -282,6 +285,7 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname) struct token *t_host = NULL; struct token *t_port = NULL; struct token *t_hosthdr = NULL; + struct symbol *pb; struct fld_spec *fs; struct inifin *ifp; struct vsb *vsb; @@ -385,16 +389,17 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be, const char *vgcname) Fb(tl, 0, "\t.proxy_header = %u,\n", u); } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == '{') { vcc_ParseProbeSpec(tl, NULL, &p); - Fb(tl, 0, "\t.probe = &%s,\n", p); + Fb(tl, 0, "\t.probe = %s,\n", p); ERRCHK(tl); } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == ID) { - if (!VCC_SymbolTok(tl, NULL, tl->t, SYM_PROBE, 0)) { + pb = VCC_SymbolTok(tl, NULL, tl->t, SYM_PROBE, 0); + if (pb == NULL) { VSB_printf(tl->sb, "Probe %.*s not found\n", PF(tl->t)); vcc_ErrWhere(tl, tl->t); return; } - Fb(tl, 0, "\t.probe = &vgc_probe_%.*s,\n", PF(tl->t)); + Fb(tl, 0, "\t.probe = %s,\n", pb->rname); (void)vcc_AddRef(tl, tl->t, SYM_PROBE); vcc_NextToken(tl); SkipToken(tl, ';'); @@ -457,7 +462,6 @@ vcc_ParseBackend(struct vcc *tl) { struct token *t_first, *t_be; struct symbol *sym; - char vgcname[MAX_BACKEND_NAME + 20]; t_first = tl->t; vcc_NextToken(tl); /* ID: backend */ @@ -465,6 +469,7 @@ vcc_ParseBackend(struct vcc *tl) vcc_ExpectCid(tl, "backend"); /* ID: name */ ERRCHK(tl); + /* XXX: lift this limit once VSM ident becomes dynamic */ if (tl->t->e - tl->t->b > MAX_BACKEND_NAME) { VSB_printf(tl->sb, "Name of %.*s too long (max %d, is %zu):\n", @@ -477,13 +482,12 @@ vcc_ParseBackend(struct vcc *tl) t_be = tl->t; vcc_NextToken(tl); - bprintf(vgcname, "vgc_backend_%.*s", PF(t_be)); - Fh(tl, 0, "\nstatic struct director *%s;\n", vgcname); - sym = VCC_HandleSymbol(tl, t_be, BACKEND, "vgc_backend"); ERRCHK(tl); - vcc_ParseHostDef(tl, t_be, vgcname); + Fh(tl, 0, "\nstatic struct director *%s;\n", sym->rname); + + vcc_ParseHostDef(tl, t_be, sym->rname); ERRCHK(tl); if (tl->err) { diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c index f6660fd..290aa8e 100644 --- a/lib/libvcc/vcc_compile.c +++ b/lib/libvcc/vcc_compile.c @@ -411,7 +411,7 @@ EmitStruct(const struct vcc *tl) Fc(tl, 0, "\t.event_vcl = VGC_Event,\n"); Fc(tl, 0, "\t.default_director = &%s,\n", tl->default_director); if (tl->default_probe != NULL) - Fc(tl, 0, "\t.default_probe = &%s,\n", tl->default_probe); + Fc(tl, 0, "\t.default_probe = %s,\n", tl->default_probe); Fc(tl, 0, "\t.ref = VGC_ref,\n"); Fc(tl, 0, "\t.nref = VGC_NREFS,\n"); Fc(tl, 0, "\t.nsrc = VGC_NSRCS,\n"); diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index 0a05d21..6859df2 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -361,4 +361,4 @@ int vcc_CheckUses(struct vcc *tl); #define SkipToken(a, b) \ do { vcc__Expect(a, b, __LINE__); ERRCHK(a); vcc_NextToken(a); } while (0) -#define ACL_SYMBOL_PREFIX "&vrt_acl_named" +#define ACL_SYMBOL_PREFIX "vrt_acl_named" diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c index abc58b2..1e144b4 100644 --- a/lib/libvcc/vcc_parse.c +++ b/lib/libvcc/vcc_parse.c @@ -240,17 +240,17 @@ vcc_ParseFunction(struct vcc *tl) } else { tl->fb = tl->fc; sym = vcc_AddDef(tl, tl->t, SYM_SUB); + VCC_GlobalSymbol(sym, SUB, "VGC_function"); if (sym->ndef > 1) { VSB_printf(tl->sb, - "Function '%.*s' redefined\n", PF(tl->t)); + "Function '%s' redefined\n", sym->name); vcc_ErrWhere(tl, tl->t); return; } tl->curproc = vcc_AddProc(tl, tl->t); - Fh(tl, 0, "void VGC_function_%.*s(VRT_CTX);\n", PF(tl->t)); + Fh(tl, 0, "void %s(VRT_CTX);\n", sym->rname); Fc(tl, 1, "\nvoid __match_proto__(vcl_func_t)\n"); - Fc(tl, 1, "VGC_function_%.*s(VRT_CTX)\n", - PF(tl->t)); + Fc(tl, 1, "%s(VRT_CTX)\n", sym->rname); } vcc_NextToken(tl); tl->indent += INDENT; diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c index 045a239..8fc56dc 100644 --- a/lib/libvcc/vcc_symb.c +++ b/lib/libvcc/vcc_symb.c @@ -45,6 +45,7 @@ VCC_HandleKind(vcc_type_t fmt) if (fmt == BACKEND) return(SYM_BACKEND); if (fmt == PROBE) return(SYM_PROBE); if (fmt == STEVEDORE) return(SYM_STEVEDORE); + if (fmt == SUB) return(SYM_SUB); if (fmt == INSTANCE) return(SYM_INSTANCE); return(SYM_NONE); } diff --git a/lib/libvcc/vcc_types.c b/lib/libvcc/vcc_types.c index af41455..00a2198 100644 --- a/lib/libvcc/vcc_types.c +++ b/lib/libvcc/vcc_types.c @@ -140,6 +140,11 @@ const struct type STRING_LIST[1] = {{ .tostring = "VRT_CollectString(ctx,\n\v1,\nvrt_magic_string_end)", }}; +const struct type SUB[1] = {{ + .magic = TYPE_MAGIC, + .name = "SUB", +}}; + const struct type TIME[1] = {{ .magic = TYPE_MAGIC, .name = "TIME", From dridi.boukelmoune at gmail.com Mon Aug 14 09:02:06 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 11:02:06 +0200 Subject: [master] c0fd77a Ensure valid C symbols for both headers and vars Message-ID: commit c0fd77a0664e2abbe90f781cc7d363e4919b1dc9 Author: Dridi Boukelmoune Date: Wed Jun 28 12:46:38 2017 +0200 Ensure valid C symbols for both headers and vars Refs #2325 diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c index b97ad2c..f6acc44 100644 --- a/lib/libvcc/vcc_acl.c +++ b/lib/libvcc/vcc_acl.c @@ -342,31 +342,36 @@ vcc_acl_entry(struct vcc *tl) */ static void -vcc_acl_emit(struct vcc *tl, const char *acln, int anon) +vcc_acl_emit(struct vcc *tl, const char *name, const char *rname, int anon) { struct acl_e *ae; int depth, l, m, i; unsigned at[VRT_ACL_MAXADDR + 1]; struct token *t; struct inifin *ifp; + struct vsb *func; + + func = VSB_new_auto(); + AN(func); + VSB_printf(func, "match_acl_%s_", anon ? "anon" : "named"); + VCC_PrintCName(func, name, NULL); + AZ(VSB_finish(func)); Fh(tl, 0, "\nstatic int __match_proto__(acl_match_f)\n"); - Fh(tl, 0, - "match_acl_%s_%s(VRT_CTX, const VCL_IP p)\n", - anon ? "anon" : "named", acln); /* XXX: acln isn't an rname */ + Fh(tl, 0, "%s(VRT_CTX, const VCL_IP p)\n", VSB_data(func)); Fh(tl, 0, "{\n"); Fh(tl, 0, "\tconst unsigned char *a;\n"); Fh(tl, 0, "\tint fam;\n"); Fh(tl, 0, "\n"); Fh(tl, 0, "\tfam = VRT_VSA_GetPtr(p, &a);\n"); Fh(tl, 0, "\tif (fam < 0) {\n"); - Fh(tl, 0, "\t\tVRT_acl_log(ctx, \"NO_FAM %s\");\n", acln); + Fh(tl, 0, "\t\tVRT_acl_log(ctx, \"NO_FAM %s\");\n", name); Fh(tl, 0, "\t\treturn(0);\n"); Fh(tl, 0, "\t}\n\n"); if (!tl->err_unref && !anon) { ifp = New_IniFin(tl); VSB_printf(ifp->ini, - "\tif (0) match_acl_named_%s(0, 0);\n", acln); + "\tif (0) %s(0, 0);\n", VSB_data(func)); } depth = -1; at[0] = 256; @@ -414,7 +419,7 @@ vcc_acl_emit(struct vcc *tl, const char *acln, int anon) if (!anon) { Fh(tl, 0, "\t%*sVRT_acl_log(ctx, \"%sMATCH %s \" ", - -i, "", ae->not ? "NEG_" : "", acln); + -i, "", ae->not ? "NEG_" : "", name); t = ae->t_addr; do { if (t->tok == CSTR) { @@ -440,33 +445,34 @@ vcc_acl_emit(struct vcc *tl, const char *acln, int anon) /* Deny by default */ if (!anon) - Fh(tl, 0, "\tVRT_acl_log(ctx, \"NO_MATCH %s\");\n", acln); + Fh(tl, 0, "\tVRT_acl_log(ctx, \"NO_MATCH %s\");\n", name); Fh(tl, 0, "\treturn (0);\n}\n"); if (anon) return; /* Emit the struct that will be referenced */ - Fh(tl, 0, "\nconst struct vrt_acl vrt_acl_named_%s[] = {{\n", acln); + Fh(tl, 0, "\nconst struct vrt_acl %s[] = {{\n", rname); Fh(tl, 0, "\t.magic = VRT_ACL_MAGIC,\n"); - Fh(tl, 0, "\t.match = &match_acl_named_%s,\n", acln); + Fh(tl, 0, "\t.match = &%s,\n", VSB_data(func)); Fh(tl, 0, "}};\n\n"); + VSB_destroy(&func); } void vcc_Acl_Hack(struct vcc *tl, char *b, size_t bl) { - char acln[32]; + char name[32]; unsigned tcond; VTAILQ_INIT(&tl->acl); tcond = tl->t->tok; vcc_NextToken(tl); - bprintf(acln, "%u", tl->unique++); + bprintf(name, "%u", tl->unique++); vcc_acl_entry(tl); - vcc_acl_emit(tl, acln, 1); + vcc_acl_emit(tl, name, name, 1); assert(snprintf(b, bl - 1, "%smatch_acl_anon_%s(ctx, \v1)", - (tcond == T_NEQ ? "!" : ""), acln) < bl - 1); + (tcond == T_NEQ ? "!" : ""), name) < bl - 1); } void @@ -496,5 +502,5 @@ vcc_ParseAcl(struct vcc *tl) } SkipToken(tl, '}'); - vcc_acl_emit(tl, sym->name, 0); + vcc_acl_emit(tl, sym->name, sym->rname, 0); } diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index 6859df2..6826e1e 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -300,6 +300,7 @@ void Resolve_Sockaddr(struct vcc *tl, const char *host, const char *defport, void vcc_stevedore(struct vcc *vcc, const char *stv_name); /* vcc_symb.c */ +void VCC_PrintCName(struct vsb *vsb, const char *b, const char *e); struct symbol *VCC_Symbol(struct vcc *, struct symbol *, const char *, const char *, enum symkind, int); #define VCC_SymbolTok(vcc, sym, tok, kind, create) \ diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c index 8fc56dc..513f4c0 100644 --- a/lib/libvcc/vcc_symb.c +++ b/lib/libvcc/vcc_symb.c @@ -36,6 +36,8 @@ #include "vcc_compile.h" +#include "vct.h" + /*--------------------------------------------------------------------*/ enum symkind @@ -63,6 +65,24 @@ VCC_SymKind(struct vcc *tl, const struct symbol *s) } } +void +VCC_PrintCName(struct vsb *vsb, const char *b, const char *e) +{ + + AN(vsb); + AN(b); + + if (e == NULL) + e = strchr(b, '\0'); + assert(b < e); + + for (; b < e; b++) + if (vct_isalnum(*b)) + VSB_putc(vsb, *b); + else + VSB_printf(vsb, "_%02x_", *b); +} + static struct symbol * vcc_new_symbol(struct vcc *tl, const char *b, const char *e) { @@ -189,7 +209,8 @@ VCC_GlobalSymbol(struct symbol *sym, vcc_type_t fmt, const char *pfx) vsb = VSB_new_auto(); AN(vsb); - VSB_printf(vsb, "%s_%s", pfx, sym->name); + VSB_printf(vsb, "%s_", pfx); + VCC_PrintCName(vsb, sym->name, NULL); AZ(VSB_finish(vsb)); REPLACE(sym->rname, VSB_data(vsb)); AN(sym->rname); diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c index 50fa9e9..4e69db2 100644 --- a/lib/libvcc/vcc_var.c +++ b/lib/libvcc/vcc_var.c @@ -44,9 +44,8 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym; struct var *v; const struct var *vh; - unsigned u; - const char *p; struct vsb *vsb; + unsigned len; vh = parent->wildcard_priv; assert(vh->fmt == HEADER); @@ -68,17 +67,14 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, vsb = VSB_new_auto(); AN(vsb); VSB_printf(vsb, "&VGC_%s_", vh->rname); - for (p = b, u = 1; p < e; p++, u++) - if (vct_isalnum(*p)) - VSB_putc(vsb, *p); - else - VSB_printf(vsb, "_%02x_", *p); + VCC_PrintCName(vsb, b, e); AZ(VSB_finish(vsb)); /* Create the static identifier */ + len = (unsigned)(e - b); Fh(tl, 0, "static const struct gethdr_s %s =\n", VSB_data(vsb) + 1); Fh(tl, 0, " { %s, \"\\%03o%.*s:\"};\n", - vh->rname, u, (int)(e - b), b); + vh->rname, len + 1, len, b); /* Create the symbol r/l values */ v->rname = TlDup(tl, VSB_data(vsb)); From dridi.boukelmoune at gmail.com Mon Aug 14 09:02:07 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 11:02:07 +0200 Subject: [master] 31e03bf Switch VCL symbols from C to Varnish identifiers Message-ID: commit 31e03bf3bc8bd34c9018fff092d9dafd6cb7072b Author: Dridi Boukelmoune Date: Fri Jun 23 10:22:29 2017 +0200 Switch VCL symbols from C to Varnish identifiers This does not include VMOD space, but that is pretty much everything else. Refs #2325 diff --git a/bin/varnishtest/tests/c00084.vtc b/bin/varnishtest/tests/c00084.vtc new file mode 100644 index 0000000..6ec8dee --- /dev/null +++ b/bin/varnishtest/tests/c00084.vtc @@ -0,0 +1,38 @@ +varnishtest "legal symbol names" + +varnish v1 -arg "-s my-store=malloc" -vcl { + import directors; + + acl my-acl { "127.0.0.1"; } + + probe my-pb { } + backend my-be { + .host = "${bad_backend}"; + .probe = my-pb; + } + + sub vcl_init { + new my-dir = directors.round_robin(); + my-dir.add_backend(my-be); + } + + sub vcl_recv { + call my-sub; + } + + sub my-sub { + if (client.ip ~ my-acl) { } + set req.storage = storage.my-store; + set req.backend_hint = my-dir.backend(); + } +} -start + +varnish v1 -cli "vcl.label my-label vcl1" + +varnish v1 -vcl { + backend dummy { .host = "${bad_backend}"; } + + sub vcl_recv { + return (vcl(my-label)); + } +} diff --git a/bin/varnishtest/tests/d00006.vtc b/bin/varnishtest/tests/d00006.vtc index 195e8ba..fc35395 100644 --- a/bin/varnishtest/tests/d00006.vtc +++ b/bin/varnishtest/tests/d00006.vtc @@ -22,11 +22,11 @@ server s4 { txresp -body "4444" } -start -varnish v1 -errvcl {Name of VCL object, 'rr1-xx', contains illegal character '-'} { +varnish v1 -errvcl {Name of VCL object, 'rr1.xx', contains illegal character '.'} { import directors; backend b1 { .host = "127.0.0.1"; .port = "8080";} sub vcl_init { - new rr1-xx = directors.round_robin(); + new rr1.xx = directors.round_robin(); } } diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc index ba76e2d..bf31e4e 100644 --- a/bin/varnishtest/tests/v00020.vtc +++ b/bin/varnishtest/tests/v00020.vtc @@ -204,12 +204,12 @@ varnish v1 -errvcl {IP + IP not possible.} { } } -varnish v1 -errvcl {Name of function, 'foo-bar', contains illegal character '-'} { +varnish v1 -errvcl {Name of function, 'foo.bar', contains illegal character '.'} { backend b { .host = "127.0.0.1"; } - sub foo-bar { + sub foo.bar { } sub vcl_recv { - call foo-bar; + call foo.bar; } } @@ -238,9 +238,9 @@ varnish v1 -errvcl {'beresp.status': Not available in method 'vcl_recv'.} { } } -varnish v1 -errvcl {Name of ACL, 'foo-bar', contains illegal character '-'} { +varnish v1 -errvcl {Name of ACL, 'foo.bar', contains illegal character '.'} { backend b { .host = "127.0.0.1"; } - acl foo-bar { + acl foo.bar { } sub vcl_recv { if (client.ip ~ foo.bar) { diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c index f6acc44..0a6a15a 100644 --- a/lib/libvcc/vcc_acl.c +++ b/lib/libvcc/vcc_acl.c @@ -484,7 +484,7 @@ vcc_ParseAcl(struct vcc *tl) vcc_NextToken(tl); VTAILQ_INIT(&tl->acl); - vcc_ExpectCid(tl, "ACL"); + vcc_ExpectVid(tl, "ACL"); ERRCHK(tl); an = tl->t; vcc_NextToken(tl); diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c index 5775ee2..bc0c096 100644 --- a/lib/libvcc/vcc_backend.c +++ b/lib/libvcc/vcc_backend.c @@ -255,7 +255,7 @@ vcc_ParseProbe(struct vcc *tl) vcc_NextToken(tl); /* ID: probe */ - vcc_ExpectCid(tl, "backend probe"); /* ID: name */ + vcc_ExpectVid(tl, "backend probe"); /* ID: name */ ERRCHK(tl); t_probe = tl->t; vcc_NextToken(tl); @@ -466,7 +466,7 @@ vcc_ParseBackend(struct vcc *tl) t_first = tl->t; vcc_NextToken(tl); /* ID: backend */ - vcc_ExpectCid(tl, "backend"); /* ID: name */ + vcc_ExpectVid(tl, "backend"); /* ID: name */ ERRCHK(tl); /* XXX: lift this limit once VSM ident becomes dynamic */ diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index 6826e1e..3a417e2 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -318,7 +318,7 @@ void vcc_ErrWhere2(struct vcc *, const struct token *, const struct token *); void vcc__Expect(struct vcc *tl, unsigned tok, unsigned line); int vcc_IdIs(const struct token *t, const char *p); -void vcc_ExpectCid(struct vcc *tl, const char *what); +void vcc_ExpectVid(struct vcc *tl, const char *what); void vcc_Lexer(struct vcc *tl, struct source *sp); void vcc_NextToken(struct vcc *tl); void vcc__ErrInternal(struct vcc *tl, const char *func, diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 238ee9d..78e26a7 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -471,7 +471,7 @@ vcc_Eval_Handle(struct vcc *tl, struct expr **e, const struct symbol *sym, *e = vcc_mk_expr(STRING, "\"%s\"", sym->name); (void)vcc_AddRef(tl, tl->t, sym->kind); } else { - vcc_ExpectCid(tl, "handle"); + vcc_ExpectVid(tl, "handle"); (void)vcc_AddRef(tl, tl->t, sym->kind); *e = vcc_mk_expr(sym->fmt, "%s", sym->rname); (*e)->constant = EXPR_VAR; /* XXX ? */ @@ -1203,7 +1203,7 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt) (tl->t->tok == '~' || tl->t->tok == T_NOMATCH)) { not = tl->t->tok == '~' ? "" : "!"; vcc_NextToken(tl); - vcc_ExpectCid(tl, "ACL"); + vcc_ExpectVid(tl, "ACL"); sym = vcc_AddRef(tl, tl->t, SYM_ACL); VCC_GlobalSymbol(sym, ACL, ACL_SYMBOL_PREFIX); bprintf(buf, "%sVRT_acl_match(ctx, %s, \v1)", not, sym->rname); diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c index 1e144b4..a3839b3 100644 --- a/lib/libvcc/vcc_parse.c +++ b/lib/libvcc/vcc_parse.c @@ -213,7 +213,7 @@ vcc_ParseFunction(struct vcc *tl) int m, i; vcc_NextToken(tl); - vcc_ExpectCid(tl, "function"); + vcc_ExpectVid(tl, "function"); ERRCHK(tl); m = IsMethod(tl->t); diff --git a/lib/libvcc/vcc_token.c b/lib/libvcc/vcc_token.c index a262ded..368f57c 100644 --- a/lib/libvcc/vcc_token.c +++ b/lib/libvcc/vcc_token.c @@ -291,26 +291,25 @@ vcc_IdIs(const struct token *t, const char *p) } /*-------------------------------------------------------------------- - * Check that we have a C-identifier + * Check that we have a Varnish identifier */ void -vcc_ExpectCid(struct vcc *tl, const char *what) +vcc_ExpectVid(struct vcc *tl, const char *what) { - const char *q; + const char *bad; ExpectErr(tl, ID); ERRCHK(tl); - /* XXX: too soon to use vct_invalid_name() */ - for (q = tl->t->b; q < tl->t->e; q++) { - if (!vct_isalnum(*q) && *q != '_') { - VSB_printf(tl->sb, "Name of %s, ", what); - vcc_ErrToken(tl, tl->t); - VSB_printf(tl->sb, - ", contains illegal character '%c'\n", *q); - vcc_ErrWhere(tl, tl->t); - return; - } + + bad = VCT_invalid_name(tl->t->b, tl->t->e); + if (bad != NULL) { + VSB_printf(tl->sb, "Name of %s, ", what); + vcc_ErrToken(tl, tl->t); + VSB_printf(tl->sb, + ", contains illegal character '%c'\n", *bad); + vcc_ErrWhere(tl, tl->t); + return; } } diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c index e3449ea..d46e496 100644 --- a/lib/libvcc/vcc_vmod.c +++ b/lib/libvcc/vcc_vmod.c @@ -280,7 +280,7 @@ vcc_ParseNew(struct vcc *tl) vcc_NextToken(tl); ExpectErr(tl, ID); - vcc_ExpectCid(tl, "VCL object"); + vcc_ExpectVid(tl, "VCL object"); ERRCHK(tl); sy1 = VCC_HandleSymbol(tl, tl->t, INSTANCE, "vo"); ERRCHK(tl); From phk at FreeBSD.org Mon Aug 14 11:21:06 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 14 Aug 2017 13:21:06 +0200 Subject: [master] ed35f9f Cleaner scoping of waiter descriptions Message-ID: commit ed35f9f3a203187635f1373c994c07577015333e Author: Poul-Henning Kamp Date: Mon Aug 14 11:17:59 2017 +0000 Cleaner scoping of waiter descriptions diff --git a/bin/varnishd/waiter/cache_waiter_epoll.c b/bin/varnishd/waiter/cache_waiter_epoll.c index ffbf947..5c40597 100644 --- a/bin/varnishd/waiter/cache_waiter_epoll.c +++ b/bin/varnishd/waiter/cache_waiter_epoll.c @@ -219,6 +219,8 @@ vwe_fini(struct waiter *w) /*--------------------------------------------------------------------*/ +#include "waiter/mgt_waiter.h" + const struct waiter_impl waiter_epoll = { .name = "epoll", .init = vwe_init, diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c index e757e40..24cd446 100644 --- a/bin/varnishd/waiter/cache_waiter_kqueue.c +++ b/bin/varnishd/waiter/cache_waiter_kqueue.c @@ -41,7 +41,6 @@ #include #include "waiter/waiter_priv.h" -#include "waiter/mgt_waiter.h" #include "vtim.h" #define NKEV 256 @@ -202,6 +201,8 @@ vwk_fini(struct waiter *w) /*--------------------------------------------------------------------*/ +#include "waiter/mgt_waiter.h" + const struct waiter_impl waiter_kqueue = { .name = "kqueue", .init = vwk_init, diff --git a/bin/varnishd/waiter/cache_waiter_poll.c b/bin/varnishd/waiter/cache_waiter_poll.c index 7d84c03..4b3ffc4 100644 --- a/bin/varnishd/waiter/cache_waiter_poll.c +++ b/bin/varnishd/waiter/cache_waiter_poll.c @@ -269,6 +269,8 @@ vwp_fini(struct waiter *w) /*--------------------------------------------------------------------*/ +#include "waiter/mgt_waiter.h" + const struct waiter_impl waiter_poll = { .name = "poll", .init = vwp_init, From phk at FreeBSD.org Mon Aug 14 11:21:06 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 14 Aug 2017 13:21:06 +0200 Subject: [master] cce139a Staticize Message-ID: commit cce139aaf060e4fdd441a94533e14420d8bc6e04 Author: Poul-Henning Kamp Date: Mon Aug 14 11:18:19 2017 +0000 Staticize diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 8b6c643..0f50910 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -74,7 +74,7 @@ static struct vpf_fh *pfh1 = NULL; static struct vpf_fh *pfh2 = NULL; static struct vfil_path *vcl_path = NULL; -VTAILQ_HEAD(,f_arg) f_args = VTAILQ_HEAD_INITIALIZER(f_args); +static VTAILQ_HEAD(,f_arg) f_args = VTAILQ_HEAD_INITIALIZER(f_args); int optreset; // Some has it, some doesn't. Cheaper than auto* From phk at FreeBSD.org Mon Aug 14 11:21:06 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 14 Aug 2017 13:21:06 +0200 Subject: [master] 95cc31e Staticize Message-ID: commit 95cc31e09b5f8c42fdc9aa74ada946a8ab328f22 Author: Poul-Henning Kamp Date: Mon Aug 14 11:18:33 2017 +0000 Staticize diff --git a/lib/libvarnishapi/vjsn.c b/lib/libvarnishapi/vjsn.c index 6ae82fa..10a8faf 100644 --- a/lib/libvarnishapi/vjsn.c +++ b/lib/libvarnishapi/vjsn.c @@ -545,7 +545,7 @@ vjsn_dump(const struct vjsn *js, FILE *fo) */ -const char *good[] = { +static const char *good[] = { "\x5b\x31\x32\x33\x65\x36\x35\x5d", "\x5b\x5b\x5d\x20\x20\x20\x5d", "\x5b\x22\x22\x5d", @@ -680,7 +680,7 @@ const char *good[] = { "\x20\x5b\x5d\x20", NULL }; -const char *bad[] = { +static const char *bad[] = { "\x5b\x31\x20\x74\x72\x75\x65\x5d", "\x5b\x61\xe5\x5d", "\x5b\x22\x22\x3a\x20\x31\x5d", From dridi.boukelmoune at gmail.com Mon Aug 14 12:38:10 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 14:38:10 +0200 Subject: [master] 3199e69 Introduce `$ABI [strict|vrt]` for VMOD descriptors Message-ID: commit 3199e694965217cfa5415b0a2cb3d4770f612b23 Author: Dridi Boukelmoune Date: Wed May 17 10:18:27 2017 +0200 Introduce `$ABI [strict|vrt]` for VMOD descriptors When versioning appeared in the VRT API, the goal was to allow loose ABI compliance on loaded VMODs based on the major/minor revision against which it was built. Strict checking was performed if Varnish was built from the master branch in the VCC code, but omitted by the child. This however has two flaws: 1) Release management might go wrong like it happened in 5.1.2 that got released from the master branch. 2) This doesn't solve the original problem that some VMODs might rely on supported symbols encompassed by the VRT major/minor while others may choose to integrate deeper with Varnish and lose guarantees. This patch retires the `VCS_Branch` macro that is no longer needed and provides a new `$ABI` stanza that defaults to strict when omitted. To help discovery, in-tree modules advertise a strict match. To indicate that a VMOD needs the exact Varnish build to be loaded, the VMOD's metadata contains 0.0 for the VRT major/minor revision. In addition, both the VCC and child now perform the full ABI compliance check, picking the strict or vrt option depending on the VMOD's metadata. Closes #2330 diff --git a/bin/varnishd/cache/cache_vrt_vmod.c b/bin/varnishd/cache/cache_vrt_vmod.c index 65e7074..719df9f 100644 --- a/bin/varnishd/cache/cache_vrt_vmod.c +++ b/bin/varnishd/cache/cache_vrt_vmod.c @@ -38,6 +38,7 @@ #include #include "vcli_serve.h" +#include "vmod_abi.h" #include "vrt.h" /*-------------------------------------------------------------------- @@ -65,6 +66,16 @@ struct vmod { static VTAILQ_HEAD(,vmod) vmods = VTAILQ_HEAD_INITIALIZER(vmods); +static unsigned +vmod_abi_mismatch(const struct vmod_data *d) +{ + + if (d->vrt_major == 0 && d->vrt_minor == 0) + return (d->abi == NULL || strcmp(d->abi, VMOD_ABI_Version)); + + return (d->vrt_major != VRT_MAJOR_VERSION || + d->vrt_minor > VRT_MINOR_VERSION); +} int VRT_Vmod_Init(VRT_CTX, struct vmod **hdl, void *ptr, int len, const char *nm, @@ -112,15 +123,13 @@ VRT_Vmod_Init(VRT_CTX, struct vmod **hdl, void *ptr, int len, const char *nm, FREE_OBJ(v); return (1); } - if (d->vrt_major != VRT_MAJOR_VERSION || - d->vrt_minor > VRT_MINOR_VERSION || + if (vmod_abi_mismatch(d) || d->name == NULL || strcmp(d->name, nm) || d->func == NULL || d->func_len <= 0 || d->proto == NULL || - d->spec == NULL || - d->abi == NULL) { + d->spec == NULL) { VSB_printf(ctx->msg, "Loading VMOD %s from %s:\n", nm, path); VSB_printf(ctx->msg, "VMOD data is mangled.\n"); diff --git a/config.phk b/config.phk index 7356757..b54257a 100644 --- a/config.phk +++ b/config.phk @@ -107,25 +107,23 @@ fi VCSF=include/vcs_version.h VMAV=include/vmod_abi.h +V=NOGIT if [ -d ./.git ] ; then V=`git show -s --pretty=format:%h` - B=`git rev-parse --abbrev-ref HEAD` -else - V="NOGIT" - B="NOGIT" fi -( -echo "/* $V */" -echo "/*" -echo " * NB: This file is machine generated, DO NOT EDIT!" -echo " *" -echo " * make(1) updates this when necessary" -echo " *" -echo " */" -echo "#define VCS_Version \"$V\"" -echo "#define VCS_Branch \"$B\"" -) > ${VCSF}_ + +cat > ${VCSF}_ <vrt_major == 0 && vmd->vrt_minor == 0 && strcmp(vmd->abi, VMOD_ABI_Version) != 0) { VSB_printf(tl->sb, "Incompatible VMOD %.*s\n", PF(mod)); VSB_printf(tl->sb, "\tFile name: %s\n", fnp); @@ -164,8 +164,8 @@ vcc_ParseImport(struct vcc *tl) vcc_ErrWhere(tl, mod); return; } - if (vmd->vrt_major != VRT_MAJOR_VERSION || - vmd->vrt_minor > VRT_MINOR_VERSION) { + if (vmd->vrt_major != 0 && (vmd->vrt_major != VRT_MAJOR_VERSION || + vmd->vrt_minor > VRT_MINOR_VERSION)) { VSB_printf(tl->sb, "Incompatible VMOD %.*s\n", PF(mod)); VSB_printf(tl->sb, "\tFile name: %s\n", fnp); VSB_printf(tl->sb, "\tVMOD version %u.%u\n", diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py index 90b888e..ab78cff 100755 --- a/lib/libvcc/vmodtool.py +++ b/lib/libvcc/vmodtool.py @@ -44,6 +44,7 @@ import unittest import random rstfmt = False +strict_abi = True ctypes = { 'ACL': "VCL_ACL", @@ -434,6 +435,13 @@ class s_module(stanza): fo.write("* :ref:`%s`\n" % i[1]) fo.write("\n") +class s_abi(stanza): + def parse(self): + if self.line[1] not in ('strict', 'vrt'): + err("Valid ABI types are 'strict' or 'vrt', got '%s'\n" % + self.line[1]) + strict_abi = self.line[1] == 'strict' + class s_event(stanza): def parse(self): self.event_func = self.line[1] @@ -651,6 +659,8 @@ class vcc(object): err("$Module must be first stanze") if c[0] == "Module": s_module(c, b[1:], self) + elif c[0] == "ABI": + s_abi(c, b[1:], self) elif c[0] == "Event": s_event(c, b[1:], self) elif c[0] == "Function": @@ -734,8 +744,12 @@ class vcc(object): fo.write("\n/*lint -esym(%d, Vmod_%s_Data) */\n" % (i, self.modname)) fo.write("const struct vmod_data Vmod_%s_Data = {\n" % self.modname) - fo.write("\t.vrt_major =\tVRT_MAJOR_VERSION,\n") - fo.write("\t.vrt_minor =\tVRT_MINOR_VERSION,\n") + if strict_abi: + fo.write("\t.vrt_major =\t0,\n") + fo.write("\t.vrt_minor =\t0,\n") + else: + fo.write("\t.vrt_major =\tVRT_MAJOR_VERSION,\n") + fo.write("\t.vrt_minor =\tVRT_MINOR_VERSION,\n") fo.write('\t.name =\t\t"%s",\n' % self.modname) fo.write('\t.func =\t\t&Vmod_Func,\n') fo.write('\t.func_len =\tsizeof(Vmod_Func),\n') diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc index 9323488..1b7889d 100644 --- a/lib/libvmod_debug/vmod.vcc +++ b/lib/libvmod_debug/vmod.vcc @@ -26,6 +26,7 @@ # SUCH DAMAGE. $Module debug 3 Development, test and debug +$ABI strict DESCRIPTION =========== diff --git a/lib/libvmod_directors/vmod.vcc b/lib/libvmod_directors/vmod.vcc index cce8acb..9282ba3 100644 --- a/lib/libvmod_directors/vmod.vcc +++ b/lib/libvmod_directors/vmod.vcc @@ -33,6 +33,7 @@ # SUCH DAMAGE. $Module directors 3 Varnish Directors Module +$ABI strict DESCRIPTION =========== diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc index 0923fb7..c98eb26 100644 --- a/lib/libvmod_std/vmod.vcc +++ b/lib/libvmod_std/vmod.vcc @@ -26,6 +26,7 @@ # SUCH DAMAGE. $Module std 3 Varnish Standard Module +$ABI strict DESCRIPTION =========== From dridi.boukelmoune at gmail.com Mon Aug 14 14:41:10 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 16:41:10 +0200 Subject: [master] ac5e880 Introduce the vmod vtc for varnishtest Message-ID: commit ac5e880a37f22d9458a4320ffe10ca1e18162926 Author: Dridi Boukelmoune Date: Thu Jul 6 14:42:47 2017 +0200 Introduce the vmod vtc for varnishtest This is moving some of the generally useful functions of vmod debug to a new one that is installed for use out of the Varnish source tree. Things weren't just moved from one source file to another, some functions were sligthly renamed, and the behavior of `barrier_sync` was changed to adhere to the "universal fail" and no longer returns a boolean. While at it, I added missing __match_proto__ macros to vmod debug. Refs #2276 Closes #2362 diff --git a/bin/varnishtest/tests/c00070.vtc b/bin/varnishtest/tests/c00070.vtc index a3064d8..973af28 100644 --- a/bin/varnishtest/tests/c00070.vtc +++ b/bin/varnishtest/tests/c00070.vtc @@ -1,4 +1,4 @@ -varnishtest "Test workspace functions in vmod_debug" +varnishtest "Test workspace functions in vmod_vtc" server s1 { rxreq @@ -9,20 +9,20 @@ server s1 { } -start varnish v1 -vcl+backend { - import debug; + import vtc; sub vcl_backend_response { - set beresp.http.free_backend = debug.workspace_free(backend); + set beresp.http.free_backend = vtc.workspace_free(backend); } sub vcl_deliver { - set resp.http.free_session = debug.workspace_free(session); - set resp.http.free_thread = debug.workspace_free(thread); + set resp.http.free_session = vtc.workspace_free(session); + set resp.http.free_thread = vtc.workspace_free(thread); - set resp.http.overflowed = debug.workspace_overflowed(client); - debug.workspace_allocate(client, 2048); + set resp.http.overflowed = vtc.workspace_overflowed(client); + vtc.workspace_alloc(client, 2048); if (req.url == "/bar") { - debug.workspace_overflow(client); + vtc.workspace_overflow(client); } } } -start diff --git a/bin/varnishtest/tests/c00071.vtc b/bin/varnishtest/tests/c00071.vtc index befa08d..fdeb2f8 100644 --- a/bin/varnishtest/tests/c00071.vtc +++ b/bin/varnishtest/tests/c00071.vtc @@ -12,9 +12,9 @@ server s1 { } -start varnish v1 -vcl+backend { - import debug; + import vtc; sub vcl_deliver { - debug.workspace_allocate(client, -192); + vtc.workspace_alloc(client, -192); if (req.url ~ "/bar") { set resp.http.x-foo = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; @@ -22,7 +22,7 @@ varnish v1 -vcl+backend { else if (req.url ~ "/baz") { set resp.http.x-foo = regsub(req.url, "baz", "baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz"); } - set resp.http.x-of = debug.workspace_overflowed(client); + set resp.http.x-of = vtc.workspace_overflowed(client); } } -start diff --git a/bin/varnishtest/tests/c00074.vtc b/bin/varnishtest/tests/c00074.vtc index 61f2dec..1642e97 100644 --- a/bin/varnishtest/tests/c00074.vtc +++ b/bin/varnishtest/tests/c00074.vtc @@ -6,14 +6,14 @@ server s1 { } -start varnish v1 -vcl+backend { - import debug; import std; + import vtc; sub vcl_recv { - set req.http.ws-free = debug.workspace_free(session); - debug.workspace_allocate(session, std.integer(req.http.ws-free, 0)); - debug.workspace_snap(session); - debug.workspace_reset(session); + set req.http.ws-free = vtc.workspace_free(session); + vtc.workspace_alloc(session, std.integer(req.http.ws-free, 0)); + vtc.workspace_snapshot(session); + vtc.workspace_reset(session); } } -start diff --git a/bin/varnishtest/tests/c00078.vtc b/bin/varnishtest/tests/c00078.vtc index 3a33888..613b971 100644 --- a/bin/varnishtest/tests/c00078.vtc +++ b/bin/varnishtest/tests/c00078.vtc @@ -10,14 +10,14 @@ varnish v1 \ -arg "-ss2=malloc,1m" \ -arg "-ss0=malloc,1m" \ -vcl+backend { - import debug; + import vtc; sub vcl_backend_response { if (bereq.url == "/1") { set beresp.storage_hint = "invalid"; } else if (bereq.url == "/2") { set beresp.storage_hint = "s1"; } else if (bereq.url == "/6") { - set beresp.storage = debug.no_stevedore(); + set beresp.storage = vtc.no_stevedore(); } set beresp.http.storage = beresp.storage; } diff --git a/bin/varnishtest/tests/d00011.vtc b/bin/varnishtest/tests/d00011.vtc index 21fd684..cecfbaf 100644 --- a/bin/varnishtest/tests/d00011.vtc +++ b/bin/varnishtest/tests/d00011.vtc @@ -13,6 +13,7 @@ server s2 { varnish v1 -vcl { import std; import debug; + import vtc; backend dummy { .host = "${bad_backend}"; } @@ -30,7 +31,7 @@ varnish v1 -vcl { sub vcl_backend_fetch { set bereq.backend = s1.backend(); # hot swap should happen while we sleep - debug.sleep(2s); + vtc.sleep(2s); if (std.healthy(bereq.backend)) { return(abandon); } else { diff --git a/bin/varnishtest/tests/d00013.vtc b/bin/varnishtest/tests/d00013.vtc index a9b1826..1a5a610 100644 --- a/bin/varnishtest/tests/d00013.vtc +++ b/bin/varnishtest/tests/d00013.vtc @@ -13,6 +13,7 @@ server s2 { varnish v1 -vcl { import std; import debug; + import vtc; backend dummy { .host = "${bad_backend}"; } @@ -27,7 +28,7 @@ varnish v1 -vcl { } set req.backend_hint = s1.backend(); # hot swap should happen while we sleep - debug.sleep(2s); + vtc.sleep(2s); if (std.healthy(req.backend_hint)) { return(synth(800)); } else { diff --git a/bin/varnishtest/tests/d00014.vtc b/bin/varnishtest/tests/d00014.vtc index 3053db0..437cb95 100644 --- a/bin/varnishtest/tests/d00014.vtc +++ b/bin/varnishtest/tests/d00014.vtc @@ -3,10 +3,10 @@ varnishtest "Backend as a boolean expression" server s1 -start varnish v1 -vcl+backend { - import debug; + import vtc; sub vcl_recv { - set req.backend_hint = debug.no_backend(); + set req.backend_hint = vtc.no_backend(); if (!req.backend_hint) { return (synth(404)); } diff --git a/bin/varnishtest/tests/m00012.vtc b/bin/varnishtest/tests/m00012.vtc index de3e835..276fa08 100644 --- a/bin/varnishtest/tests/m00012.vtc +++ b/bin/varnishtest/tests/m00012.vtc @@ -6,10 +6,10 @@ server s1 { } -start varnish v1 -vcl+backend { - import debug; + import vtc; sub vcl_deliver { - set resp.http.foo = debug.blob2hex(debug.str2blob("gunk")); + set resp.http.foo = vtc.blob2hex(vtc.str2blob("gunk")); } } -start @@ -25,10 +25,10 @@ varnish v1 -errvcl {BLOBs can only be used as arguments to VMOD functions.} { backend b1 {.host = "127.0.0.1";} - import debug; + import vtc; sub vcl_deliver { - set resp.http.foo = debug.str2blob("gunk"); + set resp.http.foo = vtc.str2blob("gunk"); } } @@ -36,9 +36,9 @@ varnish v1 -errvcl {Wrong argument type. Expected BLOB. Got STRING.} { backend b1 {.host = "127.0.0.1";} - import debug; + import vtc; sub vcl_deliver { - set resp.http.foo = debug.blob2hex("gunk"); + set resp.http.foo = vtc.blob2hex("gunk"); } } diff --git a/bin/varnishtest/tests/m00024.vtc b/bin/varnishtest/tests/m00024.vtc index 2124589..f7d9f7d 100644 --- a/bin/varnishtest/tests/m00024.vtc +++ b/bin/varnishtest/tests/m00024.vtc @@ -1,4 +1,4 @@ -varnishtest "Test debug.barrier_sync" +varnishtest "Test vtc.barrier_sync" barrier b1 sock 2 barrier b2 sock 2 @@ -9,18 +9,14 @@ server s1 { } -start varnish v1 -vcl+backend { - import debug; + import vtc; sub vcl_recv { - if (!debug.barrier_sync("${b1_sock}")) { - return (synth(400)); - } + vtc.barrier_sync("${b1_sock}"); } sub vcl_backend_response { - if (!debug.barrier_sync("${b2_sock}")) { - return (abandon); - } + vtc.barrier_sync("${b2_sock}"); } } -start diff --git a/bin/varnishtest/tests/r01501.vtc b/bin/varnishtest/tests/r01501.vtc index 38f220c..bcf1f4c 100644 --- a/bin/varnishtest/tests/r01501.vtc +++ b/bin/varnishtest/tests/r01501.vtc @@ -6,11 +6,10 @@ server s1 { } -start varnish v1 -vcl+backend { - - import debug; + import vtc; sub vcl_recv { - set req.backend_hint = debug.no_backend(); + set req.backend_hint = vtc.no_backend(); } } -start diff --git a/bin/varnishtest/tests/r01739.vtc b/bin/varnishtest/tests/r01739.vtc index dbbd04d..c839542 100644 --- a/bin/varnishtest/tests/r01739.vtc +++ b/bin/varnishtest/tests/r01739.vtc @@ -6,12 +6,12 @@ server s1 { } -start -varnish v1 \ - -vcl+backend { - import debug; +varnish v1 -vcl+backend { + import vtc; + sub vcl_backend_response { set beresp.do_gzip = true; - debug.workspace_allocate(backend, debug.workspace_free(backend) - 16); + vtc.workspace_alloc(backend, vtc.workspace_free(backend) - 16); } } -start diff --git a/bin/varnishtest/tests/r01834.vtc b/bin/varnishtest/tests/r01834.vtc index e5e1dbc..827105b 100644 --- a/bin/varnishtest/tests/r01834.vtc +++ b/bin/varnishtest/tests/r01834.vtc @@ -10,15 +10,15 @@ server s1 -repeat 64 { } -start varnish v1 -vcl+backend { - import debug; import std; + import vtc; sub vcl_recv { return (pass); } sub vcl_backend_fetch { - debug.workspace_allocate(backend, -1 * std.integer(bereq.http.WS, 256)); + vtc.workspace_alloc(backend, -1 * std.integer(bereq.http.WS, 256)); } } -start diff --git a/bin/varnishtest/tests/r01990.vtc b/bin/varnishtest/tests/r01990.vtc index 7c72f0f..2b9dbbd 100644 --- a/bin/varnishtest/tests/r01990.vtc +++ b/bin/varnishtest/tests/r01990.vtc @@ -1,7 +1,7 @@ varnishtest "workspace overflow with failed backend fetch" varnish v1 -vcl { - import debug; + import vtc; backend default { .host = "${bad_backend}"; @@ -10,8 +10,7 @@ varnish v1 -vcl { sub vcl_backend_fetch { # avoid LostHeader b Host: %s set bereq.http.Host = "127.0.0.1"; - debug.workspace_allocate(backend, - debug.workspace_free(backend)); + vtc.workspace_alloc(backend, vtc.workspace_free(backend)); } sub vcl_backend_error { diff --git a/bin/varnishtest/tests/r02233.vtc b/bin/varnishtest/tests/r02233.vtc index f877f60..67fb20c 100644 --- a/bin/varnishtest/tests/r02233.vtc +++ b/bin/varnishtest/tests/r02233.vtc @@ -6,11 +6,11 @@ server s1 { } -start varnish v1 -vcl+backend { - import debug; import std; + import vtc; sub vcl_recv { - debug.workspace_allocate(client, -92); + vtc.workspace_alloc(client, -92); if (std.querysort(req.url) == req.url) { std.log("querysort failed"); } diff --git a/bin/varnishtest/tests/r02275.vtc b/bin/varnishtest/tests/r02275.vtc index a5b2e27..0a56c16 100644 --- a/bin/varnishtest/tests/r02275.vtc +++ b/bin/varnishtest/tests/r02275.vtc @@ -12,17 +12,17 @@ server s1 -repeat 2 { } -start varnish v1 -vcl+backend { - import debug; + import vtc; sub vcl_deliver { if (req.url == "/1") { - debug.workspace_allocate(client, - -1 * (40 + debug.typesize("p") * 25)); + vtc.workspace_alloc(client, + -1 * (40 + vtc.typesize("p") * 25)); } else { - debug.workspace_allocate(client, - -1 * (56 + debug.typesize("p") * 25)); + vtc.workspace_alloc(client, + -1 * (56 + vtc.typesize("p") * 25)); } - set resp.http.foo = debug.workspace_free(client); + set resp.http.foo = vtc.workspace_free(client); } } -start diff --git a/bin/varnishtest/tests/r02339.vtc b/bin/varnishtest/tests/r02339.vtc index d9e7fbe..b1d4477 100644 --- a/bin/varnishtest/tests/r02339.vtc +++ b/bin/varnishtest/tests/r02339.vtc @@ -7,6 +7,7 @@ server s1 -repeat 12 { varnish v1 -arg "-p thread_pools=1" -vcl+backend { import debug; + import vtc; sub vcl_recv { if (req.url == "recv") { debug.purge(); } @@ -38,7 +39,7 @@ varnish v1 -arg "-p thread_pools=1" -vcl+backend { sub vcl_backend_fetch { if (bereq.url == "fetch") { debug.purge(); } if (bereq.url == "error") { - set bereq.backend = debug.no_backend(); + set bereq.backend = vtc.no_backend(); } } sub vcl_backend_error { diff --git a/bin/varnishtest/tests/t02004.vtc b/bin/varnishtest/tests/t02004.vtc index b757660..58e8743 100644 --- a/bin/varnishtest/tests/t02004.vtc +++ b/bin/varnishtest/tests/t02004.vtc @@ -6,10 +6,10 @@ server s1 { } -start varnish v1 -vcl+backend { - import debug; + import vtc; sub vcl_recv { - debug.panic("H2 panic"); + vtc.panic("H2 panic"); } } -start diff --git a/bin/varnishtest/tests/t02007.vtc b/bin/varnishtest/tests/t02007.vtc index e4d4699..b3fd521 100644 --- a/bin/varnishtest/tests/t02007.vtc +++ b/bin/varnishtest/tests/t02007.vtc @@ -21,18 +21,15 @@ server s1 { expect req.url == /5 } -start - varnish v1 -cliok "param.set feature +http2" varnish v1 -cliok "param.set debug +syncvsl" varnish v1 -cliok "param.set debug +h2_nocheck" varnish v1 -vcl+backend { - import debug; + import vtc; sub vcl_deliver { if (req.url == "/1") { - if (!debug.barrier_sync("${b1_sock}")) { - return (synth(400)); - } + vtc.barrier_sync("${b1_sock}"); } } } -start diff --git a/bin/varnishtest/tests/v00010.vtc b/bin/varnishtest/tests/v00010.vtc index 43fb083..1c65a90 100644 --- a/bin/varnishtest/tests/v00010.vtc +++ b/bin/varnishtest/tests/v00010.vtc @@ -25,17 +25,16 @@ server s1 { } -start varnish v1 -arg "-smalloc,1m" -vcl+backend { - - import debug; + import vtc; sub vcl_backend_response { if (beresp.http.panic == "fetch") { - debug.panic("Had Panic header: " + beresp.http.panic); + vtc.panic("Had Panic header: " + beresp.http.panic); } } sub vcl_deliver { if (resp.http.panic == "deliver") { - debug.panic("Had Panic header: " + resp.http.panic); + vtc.panic("Had Panic header: " + resp.http.panic); } } } -start diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc index bf31e4e..de031db 100644 --- a/bin/varnishtest/tests/v00020.vtc +++ b/bin/varnishtest/tests/v00020.vtc @@ -223,10 +223,10 @@ varnish v1 -errvcl {VCL sub's named 'vcl*' are reserved names.} { } varnish v1 -errvcl {Function returns VOID} { - import debug; + import vtc; backend b { .host = "127.0.0.1"; } sub vcl_recv { - set req.http.foo = debug.sleep(1m); + set req.http.foo = vtc.sleep(1m); } } @@ -253,10 +253,10 @@ varnish v1 -errvcl {Expected 'from path ...'} { } varnish v1 -errvcl {INT * BLOB not possible.} { - import debug; + import vtc; backend b { .host = "127.0.0.1"; } sub vcl_deliver { - set resp.status = 100 * debug.str2blob("a"); + set resp.status = 100 * vtc.str2blob("a"); } } diff --git a/bin/varnishtest/vmods.h b/bin/varnishtest/vmods.h index f951b22..6f51d9e 100644 --- a/bin/varnishtest/vmods.h +++ b/bin/varnishtest/vmods.h @@ -30,3 +30,4 @@ VTC_VMOD(std) VTC_VMOD(debug) VTC_VMOD(directors) +VTC_VMOD(vtc) diff --git a/configure.ac b/configure.ac index a3adfb6..abcd5d1 100644 --- a/configure.ac +++ b/configure.ac @@ -729,6 +729,7 @@ AC_CONFIG_FILES([ lib/libvmod_debug/Makefile lib/libvmod_std/Makefile lib/libvmod_directors/Makefile + lib/libvmod_vtc/Makefile man/Makefile varnishapi.pc varnishapi-uninstalled.pc diff --git a/doc/changes.rst b/doc/changes.rst index ef5938a..bed6ac5 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -25,13 +25,15 @@ VCL * Added ``bereq.is_bgfetch`` which is true for background fetches. -C APIs (for vmod authors) -------------------------- +C APIs (for vmod and utility authors) +------------------------------------- * ``VSM_Name()`` returns the -i argument name, rather than the -n name. * ``VUT.name`` is gone, use ``VSM_Name(VUT.vsm)`` +* New vmod vtc for advanced varnishtest usage (#2276) + ================================ Varnish Cache 5.1.3 (2017-08-02) ================================ diff --git a/doc/sphinx/reference/varnishtest.rst b/doc/sphinx/reference/varnishtest.rst index dd49963..bb18f6c 100644 --- a/doc/sphinx/reference/varnishtest.rst +++ b/doc/sphinx/reference/varnishtest.rst @@ -184,6 +184,7 @@ SEE ALSO * :ref:`varnishtop(1)` * :ref:`vcl(7)` * :ref:`vtc(7)` +* :ref:`vmod_vtc(3)` HISTORY ======= diff --git a/doc/sphinx/reference/vtc.rst b/doc/sphinx/reference/vtc.rst index d08ec22..876b809 100644 --- a/doc/sphinx/reference/vtc.rst +++ b/doc/sphinx/reference/vtc.rst @@ -66,6 +66,7 @@ SEE ALSO ======== * :ref:`varnishtest(1)` +* :ref:`vmod_vtc(3)` COPYRIGHT ========= diff --git a/lib/Makefile.am b/lib/Makefile.am index 871cbaf..dbb4ad9 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -7,4 +7,5 @@ SUBDIRS = \ libvgz \ libvmod_debug \ libvmod_std \ - libvmod_directors + libvmod_directors \ + libvmod_vtc diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c index d8e2910..e76e08b 100644 --- a/lib/libvmod_debug/vmod_debug.c +++ b/lib/libvmod_debug/vmod_debug.c @@ -202,7 +202,7 @@ vmod_rot52(VRT_CTX, VCL_HTTP hp) http_PrintfHeader(hp, "Encrypted: ROT52"); } -VCL_STRING +VCL_STRING __match_proto__(td_debug_argtest) vmod_argtest(VRT_CTX, VCL_STRING one, VCL_REAL two, VCL_STRING three, VCL_STRING comma, VCL_INT four) { @@ -212,7 +212,7 @@ vmod_argtest(VRT_CTX, VCL_STRING one, VCL_REAL two, VCL_STRING three, return (WS_Copy(ctx->ws, buf, -1)); } -VCL_INT +VCL_INT __match_proto__(td_debug_vre_limit) vmod_vre_limit(VRT_CTX) { (void)ctx; @@ -239,7 +239,7 @@ obj_cb(struct worker *wrk, void *priv, struct objcore *oc, unsigned event) (intmax_t)(uintptr_t)oc); } -VCL_VOID __match_proto__() +VCL_VOID __match_proto__(td_debug_register_obj_events) vmod_register_obj_events(VRT_CTX, struct vmod_priv *priv) { struct priv_vcl *priv_vcl; @@ -252,7 +252,7 @@ vmod_register_obj_events(VRT_CTX, struct vmod_priv *priv) VSL(SLT_Debug, 0, "Subscribed to Object Events"); } -VCL_VOID __match_proto__() +VCL_VOID __match_proto__(td_debug_fail) vmod_fail(VRT_CTX) { @@ -487,7 +487,7 @@ vmod_workspace_overflow(VRT_CTX, VCL_ENUM which) WS_MarkOverflow(ws); } -void +VCL_VOID __match_proto__(td_debug_vcl_release_delay) vmod_vcl_release_delay(VRT_CTX, VCL_DURATION delay) { @@ -496,7 +496,7 @@ vmod_vcl_release_delay(VRT_CTX, VCL_DURATION delay) vcl_release_delay = delay; } -VCL_BOOL +VCL_BOOL __match_proto__(td_debug_match_acl) vmod_match_acl(VRT_CTX, VCL_ACL acl, VCL_IP ip) { @@ -539,7 +539,7 @@ vmod_barrier_sync(VRT_CTX, VCL_STRING addr) return (0); } -VCL_VOID +VCL_VOID __match_proto__(td_debug_test_probe) vmod_test_probe(VRT_CTX, VCL_PROBE probe, VCL_PROBE same) { @@ -573,7 +573,7 @@ vmod_typesize(VRT_CTX, VCL_STRING s) return ((VCL_INT)i); } -VCL_VOID +VCL_VOID __match_proto__(td_debug_purge) vmod_purge(VRT_CTX, double ttl, double grace, double keep) { diff --git a/lib/libvmod_vtc/Makefile.am b/lib/libvmod_vtc/Makefile.am new file mode 100644 index 0000000..98baa91 --- /dev/null +++ b/lib/libvmod_vtc/Makefile.am @@ -0,0 +1,41 @@ +# +AM_LDFLAGS = $(AM_LT_LDFLAGS) + +AM_CPPFLAGS = \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/bin/varnishd \ + -I$(top_builddir)/include + +vmoddir = $(pkglibdir)/vmods +vmod_srcdir = $(top_srcdir)/lib/libvmod_vtc +vmodtool = $(top_srcdir)/lib/libvcc/vmodtool.py +vmodtoolargs = + +vmod_LTLIBRARIES = libvmod_vtc.la + +libvmod_vtc_la_CFLAGS = \ + @SAN_CFLAGS@ + +libvmod_vtc_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version -shared -rpath /nowhere \ + @SAN_LDFLAGS@ + +libvmod_vtc_la_SOURCES = \ + vmod_vtc.c + +nodist_libvmod_vtc_la_SOURCES = \ + vcc_if.c \ + vcc_if.h + +# BUILT_SOURCES is only a hack and dependency tracking does not help for the first build +$(libvmod_vtc_la_OBJECTS):vcc_if.h + +vcc_if.h vmod_vtc.rst vmod_vtc.man.rst: vcc_if.c + +vcc_if.c: $(vmodtool) $(vmod_srcdir)/vmod.vcc + @PYTHON@ $(vmodtool) $(vmodtoolargs) $(vmod_srcdir)/vmod.vcc + +EXTRA_DIST = vmod.vcc + +CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h \ + $(builddir)/vmod_vtc.rst \ + $(builddir)/vmod_vtc.man.rst diff --git a/lib/libvmod_vtc/vmod.vcc b/lib/libvmod_vtc/vmod.vcc new file mode 100644 index 0000000..a932343 --- /dev/null +++ b/lib/libvmod_vtc/vmod.vcc @@ -0,0 +1,149 @@ +# +# Copyright (c) 2017 Varnish Software AS +# All rights reserved. +# +# Author: Dridi Boukelmoune +# +# 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. + +$Module vtc 3 Utility module for varnishtest + +DESCRIPTION +=========== + +The goal for this VMOD is to provide VCL users and VMOD authors means to +test corner cases or reach certain conditions with varnishtest. + +$Function VOID barrier_sync(STRING addr, DURATION timeout = 0) + +When writing test cases, the most common pattern is to start a mock server +instance, a Varnish instance, and spin up a mock client. Those entities run +asynchronously, and others exist like background processes (``process``) or +log readers (``logexpect``). While you can synchronize with individual +entities and wait for their completion, you must use a barrier if you need +to synchronize two or more entities, or wait until a certain point instead +of completion. + +Not only is it possible to synchronize between test entities, with the +``barrier_sync`` function you can even synchronize VCL code:: + + sub vcl_recv { + # wait for some barrier b1 to complete + vtc.barrier_sync("${b1_sock}"); + } + +If the function fails to synchronize with the barrier for some reason, or if +it reaches the optional timeout, it fails the VCL transaction. + +MISCELLANEOUS +============= + +$Function BACKEND no_backend() + +Fails at backend selection. + +$Function STEVEDORE no_stevedore() + +Fails at storage selection. + +$Function VOID panic(STRING_LIST) + +It can be useful to crash the child process in order to test the robustness +of a VMOD. + +$Function VOID sleep(DURATION) + +Block the current worker thread. + +WORKSPACES +========== + +It can be useful to put a workspace in a given state when testing corner +cases like resource exhaustion for a transaction, especially for VMOD +development. All functions available allow to pick which workspace you +need to tamper with, available values are ``client``, ``backend``, ``session`` +and ``thread``. + +$Function VOID workspace_alloc(ENUM { client, backend, session, thread }, + INT size) + +Allocate and zero out memory from a workspace. A negative size will allocate +as much as needed to leave that many bytes free. The actual allocation size +may be higher to comply with memory alignment requirements of the CPU +architecture. A failed allocation fails the transaction. + +$Function INT workspace_free(ENUM { client, backend, session, thread }) + +Find how much unallocated space there is left in a workspace. + +$Function VOID workspace_snapshot(ENUM { client, backend, session, thread}) + +Snapshot a workspace. Only one snapshot may be active at a time. + +$Function VOID workspace_reset(ENUM { client, backend, session, thread }) + +Reset to the previous snapshot of a workspace, it must be the same workspace +too. + +$Function BOOL workspace_overflowed(ENUM { client, backend, session, thread }) + +Find whether the workspace overflow mark is set or not. + +$Function VOID workspace_overflow(ENUM { client, backend, session, thread }) + +Mark a workspace as overflowed. + +$Function INT typesize(STRING) + +Returns the size in bytes of a collection of C-datatypes: + +* ``'p'``: pointer +* ``'i'``: ``int`` +* ``'d'``: ``double`` +* ``'f'``: ``float`` +* ``'l'``: ``long`` +* ``'s'``: ``short`` +* ``'z'``: ``size_t`` +* ``'o'``: ``off_t`` +* ``'j'``: ``intmax_t`` + +This can be useful for VMOD authors in conjunction with workspace operations. + +BLOBS +===== + +For VMODs dealing with BLOB arguments or return values, the following functions +offer convenience conversions to and from STRING. + +$Function BLOB str2blob(STRING src) + +Turn a string into a blob. + +$Function STRING blob2hex(BLOB src) + +Hexdump a blob. + +SEE ALSO +======== + +* :ref:`vtc(7)` +* :ref:`vcl(7)` diff --git a/lib/libvmod_vtc/vmod_vtc.c b/lib/libvmod_vtc/vmod_vtc.c new file mode 100644 index 0000000..c4e18cf --- /dev/null +++ b/lib/libvmod_vtc/vmod_vtc.c @@ -0,0 +1,262 @@ +/*- + * Copyright (c) 2012-2017 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * Author: Dridi Boukelmoune + * + * 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. + */ + +#include "config.h" + +#include +#include + +#include "cache/cache.h" + +#include "vrt.h" +#include "vtcp.h" +#include "vtim.h" + +#include "vcc_if.h" + +VCL_VOID __match_proto__(td_vtc_barrier_sync) +vmod_barrier_sync(VRT_CTX, VCL_STRING addr, VCL_DURATION tmo) +{ + const char *err; + char buf[32]; + int sock, i; + ssize_t sz; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + AN(addr); + AN(*addr); + assert(tmo >= 0.0); + + VSLb(ctx->vsl, SLT_Debug, "barrier_sync(\"%s\")", addr); + sock = VTCP_open(addr, NULL, 0., &err); + if (sock < 0) { + VRT_fail(ctx, "Barrier connection failed: %s", err); + return; + } + + sz = VTCP_read(sock, buf, sizeof buf, tmo); + i = errno; + closefd(&sock); + if (sz < 0) + VRT_fail(ctx, "Barrier read failed: %s (errno=%d)", + strerror(i), i); + if (sz > 0) + VRT_fail(ctx, "Barrier unexpected data (%zdB)", sz); +} + +/*--------------------------------------------------------------------*/ + +VCL_BACKEND __match_proto__(td_vtc_no_backend) +vmod_no_backend(VRT_CTX) +{ + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + return (NULL); +} + +VCL_STEVEDORE __match_proto__(td_vtc_no_stevedore) +vmod_no_stevedore(VRT_CTX) +{ + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + return (NULL); +} + +/*--------------------------------------------------------------------*/ + +VCL_VOID __match_proto__(td_vtc_panic) +vmod_panic(VRT_CTX, const char *str, ...) +{ + va_list ap; + const char *b; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + + va_start(ap, str); + b = VRT_String(ctx->ws, "PANIC: ", str, ap); + va_end(ap); + VAS_Fail("VCL", "", 0, b, VAS_VCL); +} + +/*--------------------------------------------------------------------*/ + +VCL_VOID __match_proto__(td_vtc_sleep) +vmod_sleep(VRT_CTX, VCL_DURATION t) +{ + + CHECK_OBJ_ORNULL(ctx, VRT_CTX_MAGIC); + VTIM_sleep(t); +} + +/*--------------------------------------------------------------------*/ + +static uintptr_t vtc_ws_snapshot; + +static struct ws * +vtc_ws_find(VRT_CTX, VCL_ENUM which) +{ + + if (!strcmp(which, "client")) + return (ctx->ws); + if (!strcmp(which, "backend")) + return (ctx->bo->ws); + if (!strcmp(which, "session")) + return (ctx->req->sp->ws); + if (!strcmp(which, "thread")) + return (ctx->req->wrk->aws); + + VRT_fail(ctx, "Unknown workspace: '%s'", which); + return (NULL); +} + +VCL_VOID __match_proto__(td_vtc_workspace_alloc) +vmod_workspace_alloc(VRT_CTX, VCL_ENUM which, VCL_INT size) +{ + struct ws *ws; + void *p; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + + ws = vtc_ws_find(ctx, which); + WS_Assert(ws); + + if (size < 0) { + size += WS_Reserve(ws, 0); + WS_Release(ws, 0); + } + + p = WS_Alloc(ws, size); + if (p == NULL) + VRT_fail(ctx, "vtc.workspace_alloc"); + else + memset(p, '\0', size); +} + +VCL_INT __match_proto__(td_vtc_workspace_free) +vmod_workspace_free(VRT_CTX, VCL_ENUM which) +{ + struct ws *ws; + unsigned u; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + + ws = vtc_ws_find(ctx, which); + WS_Assert(ws); + + u = WS_Reserve(ws, 0); + WS_Release(ws, 0); + return (u); +} + +#define VTC_WS_OP(type, name, op) \ +VCL_##type __match_proto__(td_vtc_workspace_##name) \ +vmod_workspace_##name(VRT_CTX, VCL_ENUM which) \ +{ \ + struct ws *ws; \ + \ + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \ + \ + ws = vtc_ws_find(ctx, which); \ + WS_Assert(ws); \ + \ + op; \ +} +VTC_WS_OP(VOID, snapshot, vtc_ws_snapshot = WS_Snapshot(ws)) +VTC_WS_OP(VOID, reset, WS_Reset(ws, vtc_ws_snapshot)) +VTC_WS_OP(VOID, overflow, WS_MarkOverflow(ws)) +VTC_WS_OP(BOOL, overflowed, return (WS_Overflowed(ws))) +#undef VTC_WS_OP + +/*--------------------------------------------------------------------*/ + +VCL_INT __match_proto__(td_vtc_typesize) +vmod_typesize(VRT_CTX, VCL_STRING s) +{ + VCL_INT i = 0; + const char *p; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + + for (p = s; *p; p++) { + switch (*p) { +#define VTC_TYPESIZE(c, t) case c: i += sizeof(t); break; + VTC_TYPESIZE('d', double) + VTC_TYPESIZE('f', float) + VTC_TYPESIZE('i', int) + VTC_TYPESIZE('j', intmax_t) + VTC_TYPESIZE('l', long) + VTC_TYPESIZE('o', off_t) + VTC_TYPESIZE('p', void *) + VTC_TYPESIZE('s', short) + VTC_TYPESIZE('z', size_t) +#undef VTC_TYPESIZE + default: return (-1); + } + } + return (i); +} + +/*--------------------------------------------------------------------*/ + +VCL_BLOB __match_proto__(td_vtc_str2blob) +vmod_str2blob(VRT_CTX, VCL_STRING s) +{ + struct vmod_priv *p; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + + p = WS_Alloc(ctx->ws, sizeof *p); + AN(p); + memset(p, 0, sizeof *p); + p->len = strlen(s); + p->priv = WS_Copy(ctx->ws, s, -1); + return (p); +} + +VCL_STRING __match_proto__(td_vtc_blob2hex) +vmod_blob2hex(VRT_CTX, VCL_BLOB b) +{ + char *s, *p; + uint8_t *q; + int i; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + + s = WS_Alloc(ctx->ws, b->len * 2 + 2); + AN(s); + p = s; + q = b->priv; + for (i = 0; i < b->len; i++) { + assert(snprintf(p, 3, "%02x", *q) == 2); + p += 2; + q += 1; + } + VRT_priv_fini(b); + return (s); +} diff --git a/man/Makefile.am b/man/Makefile.am index d5332f6..fd7ee1a 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -16,7 +16,8 @@ dist_man_MANS = \ vtc.7 \ varnishtop.1 \ vmod_directors.3 \ - vmod_std.3 + vmod_std.3 \ + vmod_vtc.3 CLEANFILES = $(dist_man_MANS) @@ -83,10 +84,13 @@ varnishhist.1: \ $(top_builddir)/doc/sphinx/include/varnishhist_synopsis.rst ${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnishhist.rst $@ +vmod_directors.3: $(top_builddir)/lib/libvmod_directors/vmod_directors.man.rst + ${RST2MAN} $(RST2ANY_FLAGS) $? $@ + vmod_std.3: $(top_builddir)/lib/libvmod_std/vmod_std.man.rst ${RST2MAN} $(RST2ANY_FLAGS) $? $@ -vmod_directors.3: $(top_builddir)/lib/libvmod_directors/vmod_directors.man.rst +vmod_vtc.3: $(top_builddir)/lib/libvmod_vtc/vmod_vtc.man.rst ${RST2MAN} $(RST2ANY_FLAGS) $? $@ .NOPATH: $(dist_man_MANS) From dridi.boukelmoune at gmail.com Mon Aug 14 14:41:10 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 16:41:10 +0200 Subject: [master] 5a13178 Warn about vmod-debug functions moved to vmod-vtc Message-ID: commit 5a1317874786d88693ccfcc11ce43503559da889 Author: Dridi Boukelmoune Date: Mon Aug 14 16:36:03 2017 +0200 Warn about vmod-debug functions moved to vmod-vtc Refs #2362 diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c index e76e08b..e588a95 100644 --- a/lib/libvmod_debug/vmod_debug.c +++ b/lib/libvmod_debug/vmod_debug.c @@ -42,6 +42,14 @@ #include "vtim.h" #include "vcc_if.h" +#define WARN_RETIRED() \ + do { \ + VSL(SLT_Error, 0, \ + "debug.%s is deprecated, use vmod-vtc instead.", \ + __func__); \ + } while (0) + + struct priv_vcl { unsigned magic; #define PRIV_VCL_MAGIC 0x8E62FA9D @@ -60,6 +68,7 @@ vmod_panic(VRT_CTX, const char *str, ...) const char *b; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); va_start(ap, str); b = VRT_String(ctx->ws, "PANIC: ", str, ap); va_end(ap); @@ -148,6 +157,7 @@ vmod_str2blob(VRT_CTX, VCL_STRING s) struct vmod_priv *p; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); p = (void*)WS_Alloc(ctx->ws, sizeof *p); AN(p); memset(p, 0, sizeof *p); @@ -163,6 +173,7 @@ vmod_blob2hex(VRT_CTX, VCL_BLOB b) uint8_t *q; int i; + WARN_RETIRED(); s = WS_Alloc(ctx->ws, b->len * 2 + 2); AN(s); p = s; @@ -181,6 +192,7 @@ vmod_no_backend(VRT_CTX) { CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); return (NULL); } @@ -189,6 +201,7 @@ vmod_no_stevedore(VRT_CTX) { CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); return (NULL); } @@ -380,6 +393,7 @@ vmod_sleep(VRT_CTX, VCL_DURATION t) { CHECK_OBJ_ORNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); VTIM_sleep(t); } @@ -404,6 +418,7 @@ vmod_workspace_allocate(VRT_CTX, VCL_ENUM which, VCL_INT size) struct ws *ws; char *s; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); ws = wsfind(ctx, which); @@ -427,6 +442,7 @@ vmod_workspace_free(VRT_CTX, VCL_ENUM which) unsigned u; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); ws = wsfind(ctx, which); @@ -442,6 +458,7 @@ vmod_workspace_overflowed(VRT_CTX, VCL_ENUM which) { struct ws *ws; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); ws = wsfind(ctx, which); WS_Assert(ws); @@ -456,6 +473,7 @@ vmod_workspace_snap(VRT_CTX, VCL_ENUM which) { struct ws *ws; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); ws = wsfind(ctx, which); WS_Assert(ws); @@ -468,6 +486,7 @@ vmod_workspace_reset(VRT_CTX, VCL_ENUM which) { struct ws *ws; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); ws = wsfind(ctx, which); WS_Assert(ws); @@ -480,6 +499,7 @@ vmod_workspace_overflow(VRT_CTX, VCL_ENUM which) { struct ws *ws; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); ws = wsfind(ctx, which); WS_Assert(ws); @@ -516,6 +536,7 @@ vmod_barrier_sync(VRT_CTX, VCL_STRING addr) ssize_t sz; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + WARN_RETIRED(); AN(addr); AN(*addr); @@ -555,6 +576,7 @@ vmod_typesize(VRT_CTX, VCL_STRING s) size_t i = 0; const char *p; + WARN_RETIRED(); (void)ctx; for (p = s; *p; p++) { switch (*p) { From dridi.boukelmoune at gmail.com Mon Aug 14 15:12:11 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 14 Aug 2017 17:12:11 +0200 Subject: [master] e235adf Add vmod-vtc to the sphinx docs Message-ID: commit e235adf974f84ebfc2e01e9e4731cd9fd3da6feb Author: Dridi Boukelmoune Date: Mon Aug 14 17:10:08 2017 +0200 Add vmod-vtc to the sphinx docs Spotted by @fgsch diff --git a/doc/sphinx/Makefile.am b/doc/sphinx/Makefile.am index dc14c84..3978423 100644 --- a/doc/sphinx/Makefile.am +++ b/doc/sphinx/Makefile.am @@ -205,6 +205,10 @@ reference/vmod_directors.generated.rst: reference $(top_builddir)/lib/libvmod_di cp $(top_builddir)/lib/libvmod_directors/vmod_directors.rst $@ || true BUILT_SOURCES += reference/vmod_directors.generated.rst +reference/vmod_vtc.generated.rst: reference $(top_builddir)/lib/libvmod_vtc/vmod_vtc.rst + cp $(top_builddir)/lib/libvmod_vtc/vmod_vtc.rst $@ || true +BUILT_SOURCES += reference/vmod_vtc.generated.rst + EXTRA_DIST += $(BUILT_SOURCES) MAINTAINERCLEANFILES = $(EXTRA_DIST) diff --git a/doc/sphinx/reference/index.rst b/doc/sphinx/reference/index.rst index 917fe60..936b3a7 100644 --- a/doc/sphinx/reference/index.rst +++ b/doc/sphinx/reference/index.rst @@ -22,6 +22,7 @@ The Varnish Reference Manual vmod.rst vmod_std.generated.rst vmod_directors.generated.rst + vmod_vtc.generated.rst directors.rst varnish-counters.rst vsl.rst From varnish-commit at varnish-cache.org Mon Aug 14 12:19:37 2017 From: varnish-commit at varnish-cache.org (varnish-commit at varnish-cache.org) Date: 14 Aug 2017 06:19:37 -0600 Subject: Civilities Message-ID: <706163899.201708140647@varnish-cache.org> Salutation I'm addressing you on behalf of the HR department of a large company. Our company is well known in various fields as follows: - Consulting services - Traiding support - etc. We need employees: - salary $5.300 + bonus - part-time job - flexible work time If you would like to work with us, please provide us your contact information on visit our web page. -------------- next part -------------- An HTML attachment was scrubbed... URL: From phk at FreeBSD.org Mon Aug 14 21:50:10 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 14 Aug 2017 23:50:10 +0200 Subject: [master] 4beea86 TlDupTok() is no longer used. Message-ID: commit 4beea862df080f1e86c5fd06a231220b9be7e138 Author: Poul-Henning Kamp Date: Mon Aug 14 21:11:08 2017 +0000 TlDupTok() is no longer used. diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c index 290aa8e..a8d0352 100644 --- a/lib/libvcc/vcc_compile.c +++ b/lib/libvcc/vcc_compile.c @@ -93,20 +93,6 @@ TlDup(struct vcc *tl, const char *s) return (p); } -char * -TlDupTok(struct vcc *tl, const struct token *tok) -{ - char *p; - int i; - - i = tok->e - tok->b; - p = TlAlloc(tl, i + 1); - AN(p); - memcpy(p, tok->b, i); - p[i] = '\0'; - return (p); -} - /*--------------------------------------------------------------------*/ struct inifin * diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index 3a417e2..547b2bc 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -264,7 +264,6 @@ void EncToken(struct vsb *sb, const struct token *t); int IsMethod(const struct token *t); void *TlAlloc(struct vcc *tl, unsigned len); char *TlDup(struct vcc *tl, const char *s); -char *TlDupTok(struct vcc *tl, const struct token *tok); /* vcc_expr.c */ double vcc_DoubleVal(struct vcc *tl); From phk at FreeBSD.org Mon Aug 14 21:50:10 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 14 Aug 2017 23:50:10 +0200 Subject: [master] 8b9770e Minor FlexeLintery Message-ID: commit 8b9770eebc956420a61d17dbae79ca5230a83c70 Author: Poul-Henning Kamp Date: Mon Aug 14 21:48:54 2017 +0000 Minor FlexeLintery diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c index 0a6a15a..3fcc333 100644 --- a/lib/libvcc/vcc_acl.c +++ b/lib/libvcc/vcc_acl.c @@ -448,14 +448,13 @@ vcc_acl_emit(struct vcc *tl, const char *name, const char *rname, int anon) Fh(tl, 0, "\tVRT_acl_log(ctx, \"NO_MATCH %s\");\n", name); Fh(tl, 0, "\treturn (0);\n}\n"); - if (anon) - return; - - /* Emit the struct that will be referenced */ - Fh(tl, 0, "\nconst struct vrt_acl %s[] = {{\n", rname); - Fh(tl, 0, "\t.magic = VRT_ACL_MAGIC,\n"); - Fh(tl, 0, "\t.match = &%s,\n", VSB_data(func)); - Fh(tl, 0, "}};\n\n"); + if (!anon) { + /* Emit the struct that will be referenced */ + Fh(tl, 0, "\nconst struct vrt_acl %s[] = {{\n", rname); + Fh(tl, 0, "\t.magic = VRT_ACL_MAGIC,\n"); + Fh(tl, 0, "\t.match = &%s,\n", VSB_data(func)); + Fh(tl, 0, "}};\n\n"); + } VSB_destroy(&func); } diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c index 4e69db2..ea69923 100644 --- a/lib/libvcc/vcc_var.c +++ b/lib/libvcc/vcc_var.c @@ -33,7 +33,6 @@ #include #include "vcc_compile.h" -#include "vct.h" /*--------------------------------------------------------------------*/ diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c index 06ca562..64b5564 100644 --- a/lib/libvcc/vcc_vmod.c +++ b/lib/libvcc/vcc_vmod.c @@ -35,8 +35,6 @@ #include "vcc_compile.h" -#include "vcs_version.h" - #include "libvcc.h" #include "vfil.h" #include "vmod_abi.h" From fgsch at lodoss.net Tue Aug 15 08:32:16 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 15 Aug 2017 10:32:16 +0200 Subject: [master] 0aa0836 Use strncmp to avoid potential overruns Message-ID: commit 0aa08363a015a2f2add8b258823d736bcb579b92 Author: Federico G. Schwindt Date: Tue Aug 15 09:29:42 2017 +0100 Use strncmp to avoid potential overruns diff --git a/lib/libvarnishapi/vjsn.c b/lib/libvarnishapi/vjsn.c index 10a8faf..c4d2254 100644 --- a/lib/libvarnishapi/vjsn.c +++ b/lib/libvarnishapi/vjsn.c @@ -373,15 +373,15 @@ vjsn_value(struct vjsn *js) AN(jsv->value); return (jsv); } - if (!memcmp(js->ptr, "true", 4)) { + if (!strncmp(js->ptr, "true", 4)) { js->ptr += 4; return (vjsn_val_new(VJSN_TRUE)); } - if (!memcmp(js->ptr, "false", 5)) { + if (!strncmp(js->ptr, "false", 5)) { js->ptr += 5; return (vjsn_val_new(VJSN_FALSE)); } - if (!memcmp(js->ptr, "null", 4)) { + if (!strncmp(js->ptr, "null", 4)) { js->ptr += 4; return (vjsn_val_new(VJSN_NULL)); } From daghf at varnish-software.com Tue Aug 15 09:00:10 2017 From: daghf at varnish-software.com (Dag Haavi Finstad) Date: Tue, 15 Aug 2017 11:00:10 +0200 Subject: [master] c41ab01 Move req->ws_req snapshotting until after VFP_Setup Message-ID: commit c41ab01506053bf6844a895e9c66219f88460fc6 Author: Dag Haavi Finstad Date: Mon Aug 14 16:02:41 2017 +0200 Move req->ws_req snapshotting until after VFP_Setup This lets the request's vfp stack survive a VCL label change. Fixes: #2367 diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index bd3e4af..2697b4c 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -81,7 +81,6 @@ cnt_transport(struct worker *wrk, struct req *req) wrk->stats->client_req++; AZ(req->err_code); - req->ws_req = WS_Snapshot(req->ws); req->doclose = http_DoConnection(req->http); if (req->doclose == SC_RX_BAD) { @@ -97,6 +96,7 @@ cnt_transport(struct worker *wrk, struct req *req) req->transport->req_body(req); } + req->ws_req = WS_Snapshot(req->ws); HTTP_Copy(req->http0, req->http); // For ESI & restart req->req_step = R_STP_RECV; return (REQ_FSM_MORE); diff --git a/bin/varnishtest/tests/r02367.vtc b/bin/varnishtest/tests/r02367.vtc new file mode 100644 index 0000000..3ae0cb9 --- /dev/null +++ b/bin/varnishtest/tests/r02367.vtc @@ -0,0 +1,22 @@ +varnishtest "POST and return(vcl(..))" + +server s1 { + rxreq + expect req.bodylen == 4 + txresp +} -start + +varnish v1 -vcl+backend {} -start +varnish v1 -cliok "vcl.label vclA vcl1" + +varnish v1 -vcl+backend { + sub vcl_recv { + return (vcl(vclA)); + } +} + +client c1 { + txreq -req POST -body "asdf" + rxresp + expect resp.status == 200 +} -run From hermunn at varnish-software.com Wed Aug 16 11:53:05 2017 From: hermunn at varnish-software.com (Pål Hermunn Johansen) Date: Wed, 16 Aug 2017 13:53:05 +0200 Subject: [master] c21fae9 Fix problem with purging and the n_obj_purged counter Message-ID: commit c21fae9a2bb3c8aaddffae96086c181ea6296574 Author: P?l Hermunn Johansen Date: Mon Aug 14 14:27:18 2017 +0200 Fix problem with purging and the n_obj_purged counter When the do..while loop in HSH_Purge executes on a oh with many popular variants, there is a potential problem with the "array" of oc pointers, allocated in the thread workspace. If many of the oc's have positive refcounts, they will fill up the array and EXP_Rearm(oc, now, ttl, grace, keep); (void)HSH_DerefObjCore(wrk, &oc, 0); will be called several on the same oc's. At the same time, the counter n_obj_purged will be updated with a too low number. The test case demonstrates how we get a too low value for this counter, but it is not able to force varnishd to use a siginificant amount of CPU. diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index 986af6f..56d06c2 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -590,7 +590,7 @@ HSH_Purge(struct worker *wrk, struct objhead *oh, double ttl, double grace, double keep) { struct objcore *oc, **ocp; - unsigned spc, ospc, nobj, n; + unsigned spc, ospc, nobj, n, n_tot = 0; int more = 0; double now; @@ -598,6 +598,20 @@ double keep) CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); ospc = WS_Reserve(wrk->aws, 0); assert(ospc >= sizeof *ocp); + /* + * Because of "soft" purges, there might be oc's in the list that has + * the OC_F_PURGED flag set. We do not want to let these slip through, + * so we need to clear the flag before entering the do..while loop. + */ + Lck_Lock(&oh->mtx); + assert(oh->refcnt > 0); + VTAILQ_FOREACH(oc, &oh->objcs, hsh_list) { + CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); + assert(oc->objhead == oh); + oc->flags &= ~OC_F_PURGED; + } + Lck_Unlock(&oh->mtx); + do { more = 0; spc = ospc; @@ -621,6 +635,15 @@ double keep) } if (oc->flags & OC_F_DYING) continue; + if (oc->flags & OC_F_PURGED) { + /* + * We have already called EXP_Rearm on this + * object, and we do not want to do it + * again. Plus the space in the ocp array may + * be limited. + */ + continue; + } if (spc < sizeof *ocp) { /* Iterate if aws is not big enough */ more = 1; @@ -629,6 +652,7 @@ double keep) oc->refcnt++; spc -= sizeof *ocp; ocp[nobj++] = oc; + oc->flags |= OC_F_PURGED; } Lck_Unlock(&oh->mtx); @@ -638,9 +662,10 @@ double keep) EXP_Rearm(oc, now, ttl, grace, keep); (void)HSH_DerefObjCore(wrk, &oc, 0); } + n_tot += nobj; } while (more); WS_Release(wrk->aws, 0); - Pool_PurgeStat(nobj); + Pool_PurgeStat(n_tot); } /*--------------------------------------------------------------------- diff --git a/bin/varnishtest/tests/r02372.vtc b/bin/varnishtest/tests/r02372.vtc new file mode 100644 index 0000000..649ccfe --- /dev/null +++ b/bin/varnishtest/tests/r02372.vtc @@ -0,0 +1,32 @@ +varnishtest "Count purges when there are many variants" + +server s1 -repeat 40 { + rxreq + txresp -hdr "Vary: foo" +} -start + +varnish v1 -arg "-p workspace_thread=256" -vcl+backend { + import std; + + sub vcl_recv { + if (req.method == "PURGE") { + return (purge); + } + set req.http.foo = "x" + std.random(1,10) * 1000000000; + } +} -start + +client c1 -repeat 40 { + txreq + rxresp +} -run + +client c2 { + txreq -req "PURGE" + rxresp +} -run + +varnish v1 -expect n_lru_nuked == 0 +varnish v1 -expect cache_hit == 0 +varnish v1 -expect n_purges == 1 +varnish v1 -expect n_obj_purged == 40 diff --git a/include/tbl/oc_flags.h b/include/tbl/oc_flags.h index 78059aa..bdace60 100644 --- a/include/tbl/oc_flags.h +++ b/include/tbl/oc_flags.h @@ -28,6 +28,7 @@ /*lint -save -e525 -e539 */ +OC_FLAG(PURGED, purged, (1<<0)) OC_FLAG(BUSY, busy, (1<<1)) OC_FLAG(PASS, pass, (1<<2)) OC_FLAG(HFP, hfp, (1<<3)) From varnish-commit at varnish-cache.org Wed Aug 16 13:36:35 2017 From: varnish-commit at varnish-cache.org (varnish-commit) Date: Wed, 16 Aug 2017 21:36:35 +0800 Subject: varnish-commit Message-ID: <20170816213647883366@ebizrouter.com> An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ????? .docx Type: application/octet-stream Size: 21792 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: ???????? 2017.docx Type: application/octet-stream Size: 28112 bytes Desc: not available URL: From vm at varnish-cache.org Wed Aug 16 23:53:01 2017 From: vm at varnish-cache.org (vm at varnish-cache.org) Date: Wed, 16 Aug 2017 19:53:01 -0400 Subject: Voice Message Attached from 01315343950 - name unavailable Message-ID: Time: Wed, 16 Aug 2017 19:53:01 -0400 Click attachment to listen to Voice Message -------------- next part -------------- A non-text attachment was scrubbed... Name: 013599315343950_3614902_771470.rar Type: application/octet-stream Size: 2023 bytes Desc: not available URL: From vm at varnish-cache.org Thu Aug 17 02:37:54 2017 From: vm at varnish-cache.org (vm at varnish-cache.org) Date: Thu, 17 Aug 2017 09:37:54 +0700 Subject: Voice Message Attached from 01441508647 - name unavailable Message-ID: Time: Thu, 17 Aug 2017 09:37:54 +0700 Click attachment to listen to Voice Message -------------- next part -------------- A non-text attachment was scrubbed... Name: 013599441508647_2336608_897478.rar Type: application/octet-stream Size: 2015 bytes Desc: not available URL: From vm at varnish-cache.org Thu Aug 17 03:40:54 2017 From: vm at varnish-cache.org (vm at varnish-cache.org) Date: Thu, 17 Aug 2017 06:40:54 +0300 Subject: Voice Message Attached from 01129816550 - name unavailable Message-ID: Time: Thu, 17 Aug 2017 06:40:54 +0300 Click attachment to listen to Voice Message -------------- next part -------------- A non-text attachment was scrubbed... Name: 013599129816550_2226320_479618.rar Type: application/octet-stream Size: 2028 bytes Desc: not available URL: From phk at FreeBSD.org Thu Aug 17 05:17:05 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 17 Aug 2017 07:17:05 +0200 Subject: [master] 5d1998e Supress a flexelint warning Message-ID: commit 5d1998eea62402da709343c891480fde947e6e3f Author: Poul-Henning Kamp Date: Thu Aug 17 05:16:30 2017 +0000 Supress a flexelint warning diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c index 24cd446..5d06b2d 100644 --- a/bin/varnishd/waiter/cache_waiter_kqueue.c +++ b/bin/varnishd/waiter/cache_waiter_kqueue.c @@ -37,7 +37,6 @@ #include -#include #include #include "waiter/waiter_priv.h" diff --git a/include/tbl/oc_flags.h b/include/tbl/oc_flags.h index bdace60..fc8788b 100644 --- a/include/tbl/oc_flags.h +++ b/include/tbl/oc_flags.h @@ -28,7 +28,7 @@ /*lint -save -e525 -e539 */ -OC_FLAG(PURGED, purged, (1<<0)) +OC_FLAG(PURGED, purged, (1<<0)) //lint !e835 OC_FLAG(BUSY, busy, (1<<1)) OC_FLAG(PASS, pass, (1<<2)) OC_FLAG(HFP, hfp, (1<<3)) From dridi.boukelmoune at gmail.com Thu Aug 17 09:20:07 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Thu, 17 Aug 2017 11:20:07 +0200 Subject: [master] dbbfa11 Make sure there is always a listen address name Message-ID: commit dbbfa11f106ea099fdaab3dbcdd4a8712bb4e934 Author: Dridi Boukelmoune Date: Thu Aug 17 11:13:48 2017 +0200 Make sure there is always a listen address name Otherwise a field goes missing in SessOpen records. diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index 48e54a0..9284bd0 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -163,6 +163,8 @@ MAC_Arg(const char *spec) int error; const struct transport *xp; const char *name; + char name_buf[8]; + static unsigned seq = 0; av = MGT_NamedArg(spec, &name, "-a"); AN(av); @@ -172,6 +174,12 @@ MAC_Arg(const char *spec) VTAILQ_INIT(&la->socks); VTAILQ_INSERT_TAIL(&listen_args, la, list); la->endpoint = av[1]; + + if (name == NULL) { + bprintf(name_buf, "a%u", seq++); + name = strdup(name_buf); + AN(name); + } la->name = name; if (av[2] == NULL) { diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 4261ce2..0592c7d 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -15,7 +15,7 @@ HTTP accelerator daemon SYNOPSIS ======== -varnishd [-a address[:port][,PROTO]] [-b host[:port]] [-C] [-d] [-F] [-f config] [-h type[,options]] [-I clifile] [-i identity] [-j jail[,jailoptions]] [-l vsl[,vsm]] [-M address:port] [-n name] [-P file] [-p param=value] [-r param[,param...]] [-S secret-file] [-s [name=]kind[,options]] [-T address[:port]] [-t TTL] [-V] [-W waiter] [-x parameter|vsl|cli|builtin] [-?] +varnishd [-a [name=]address[:port][,PROTO]] [-b host[:port]] [-C] [-d] [-F] [-f config] [-h type[,options]] [-I clifile] [-i identity] [-j jail[,jailoptions]] [-l vsl[,vsm]] [-M address:port] [-n name] [-P file] [-p param=value] [-r param[,param...]] [-S secret-file] [-s [name=]kind[,options]] [-T address[:port]] [-t TTL] [-V] [-W waiter] [-x parameter|vsl|cli|builtin] [-?] DESCRIPTION =========== @@ -32,14 +32,15 @@ OPTIONS Basic options ------------- --a +-a <[name=]address[:port][,PROTO]> Listen for client requests on the specified address and port. The address can be a host name ("localhost"), an IPv4 dotted-quad ("127.0.0.1"), or an IPv6 address enclosed in square brackets ("[::1]"). If address is not specified, `varnishd` will listen on all available IPv4 and IPv6 interfaces. If port is not specified, port - 80 (http) is used. + 80 (http) is used. Names are referenced in logs, and when omitted they fall + back to "a0", "a1" etc. An additional protocol type can be set for the listening socket with PROTO. Valid protocol types are: HTTP/1 (default), and PROXY. Multiple listening addresses can be specified by using multiple -a arguments. @@ -168,7 +169,8 @@ Tuning options Use the specified storage backend. See `Storage Backend`_ section. This option can be used multiple times to specify multiple storage - files. Names are referenced in logs, VCL, statistics, etc. + files. Names are referenced in logs, VCL, statistics... When omitted + names fall back to "s0", "s1" etc. -l diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index 65191d2..c34df04 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -72,7 +72,7 @@ SLTM(SessOpen, 0, "Client connection opened", "\t| | | | | +- File descriptor number\n" "\t| | | | +---- Local TCP port\n" "\t| | | +------- Local IPv4/6 address\n" - "\t| | +---------- Listen socket (-a argument)\n" + "\t| | +---------- Socket name (from -a argument)\n" "\t| +------------- Remote TCP port\n" "\t+---------------- Remote IPv4/6 address\n" "\n" From dridi.boukelmoune at gmail.com Thu Aug 17 09:20:07 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Thu, 17 Aug 2017 11:20:07 +0200 Subject: [master] b0a28d2 Break the varnishd(1) synopsys in three Message-ID: commit b0a28d246bc032cf950e08ea6977954b846e560f Author: Dridi Boukelmoune Date: Thu Aug 17 11:18:28 2017 +0200 Break the varnishd(1) synopsys in three diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 0592c7d..fe7b744 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -15,7 +15,11 @@ HTTP accelerator daemon SYNOPSIS ======== -varnishd [-a [name=]address[:port][,PROTO]] [-b host[:port]] [-C] [-d] [-F] [-f config] [-h type[,options]] [-I clifile] [-i identity] [-j jail[,jailoptions]] [-l vsl[,vsm]] [-M address:port] [-n name] [-P file] [-p param=value] [-r param[,param...]] [-S secret-file] [-s [name=]kind[,options]] [-T address[:port]] [-t TTL] [-V] [-W waiter] [-x parameter|vsl|cli|builtin] [-?] +varnishd [-a [name=]address[:port][,PROTO]] [-b host[:port]] [-C] [-d] [-F] [-f config] [-h type[,options]] [-I clifile] [-i identity] [-j jail[,jailoptions]] [-l vsl[,vsm]] [-M address:port] [-n name] [-P file] [-p param=value] [-r param[,param...]] [-S secret-file] [-s [name=]kind[,options]] [-T address[:port]] [-t TTL] [-V] [-W waiter] + +varnishd [-x parameter|vsl|cli|builtin] + +varnishd [-?] DESCRIPTION =========== From fgsch at lodoss.net Fri Aug 18 11:02:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 18 Aug 2017 13:02:06 +0200 Subject: [master] 7b0505f Plug memleak on error Message-ID: commit 7b0505fc11fac107ca0ab08724b6ab8a74eda791 Author: Federico G. Schwindt Date: Fri Aug 18 02:56:01 2017 +0100 Plug memleak on error diff --git a/lib/libvarnishapi/vjsn.c b/lib/libvarnishapi/vjsn.c index c4d2254..1ad4fec 100644 --- a/lib/libvarnishapi/vjsn.c +++ b/lib/libvarnishapi/vjsn.c @@ -266,8 +266,11 @@ vjsn_object(struct vjsn *js) vjsn_skip_ws(js); VJSN_EXPECT(js, ':', jsv); jsve = vjsn_value(js); - if (js->err != NULL) + if (js->err != NULL) { + if (jsve != NULL) + vjsn_val_delete(jsve); return (jsv); + } CHECK_OBJ_NOTNULL(jsve, VJSN_VAL_MAGIC); jsve->name = s; VTAILQ_INSERT_TAIL(&jsv->children, jsve, list); @@ -295,8 +298,11 @@ vjsn_array(struct vjsn *js) if (*js->ptr != ']') { while (1) { jsve = vjsn_value(js); - if (js->err != NULL) + if (js->err != NULL) { + if (jsve != NULL) + vjsn_val_delete(jsve); return (jsv); + } CHECK_OBJ_NOTNULL(jsve, VJSN_VAL_MAGIC); VTAILQ_INSERT_TAIL(&jsv->children, jsve, list); vjsn_skip_ws(js); From fgsch at lodoss.net Fri Aug 18 11:02:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 18 Aug 2017 13:02:06 +0200 Subject: [master] 8cde66b Fix grammar and style Message-ID: commit 8cde66ba207b33fa2448f3b05334896a0ba06e86 Author: Federico G. Schwindt Date: Fri Aug 18 03:08:17 2017 +0100 Fix grammar and style diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index fe7b744..b8455c6 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -15,7 +15,7 @@ HTTP accelerator daemon SYNOPSIS ======== -varnishd [-a [name=]address[:port][,PROTO]] [-b host[:port]] [-C] [-d] [-F] [-f config] [-h type[,options]] [-I clifile] [-i identity] [-j jail[,jailoptions]] [-l vsl[,vsm]] [-M address:port] [-n name] [-P file] [-p param=value] [-r param[,param...]] [-S secret-file] [-s [name=]kind[,options]] [-T address[:port]] [-t TTL] [-V] [-W waiter] +varnishd [-a [name=][address][:port][,PROTO]] [-b host[:port]] [-C] [-d] [-F] [-f config] [-h type[,options]] [-I clifile] [-i identity] [-j jail[,jailoptions]] [-l vsl[,vsm]] [-M address:port] [-n name] [-P file] [-p param=value] [-r param[,param...]] [-S secret-file] [-s [name=]kind[,options]] [-T address[:port]] [-t TTL] [-V] [-W waiter] varnishd [-x parameter|vsl|cli|builtin] @@ -36,18 +36,22 @@ OPTIONS Basic options ------------- --a <[name=]address[:port][,PROTO]> +-a <[name=][address][:port][,PROTO]> Listen for client requests on the specified address and port. The address can be a host name ("localhost"), an IPv4 dotted-quad ("127.0.0.1"), or an IPv6 address enclosed in square brackets - ("[::1]"). If address is not specified, `varnishd` will listen on all - available IPv4 and IPv6 interfaces. If port is not specified, port - 80 (http) is used. Names are referenced in logs, and when omitted they fall - back to "a0", "a1" etc. - An additional protocol type can be set for the listening socket with PROTO. - Valid protocol types are: HTTP/1 (default), and PROXY. - Multiple listening addresses can be specified by using multiple -a arguments. + ("[::1]"). If address is not specified, `varnishd` will listen + on all available IPv4 and IPv6 interfaces. If port is not specified, + port 80 (http) is used. At least one of address or port is required. + + Name is referenced in logs. If name is not specified, "a0", "a1", + etc. is used. An additional protocol type can be set for the + listening socket with PROTO. Valid protocol types are: HTTP/1 + (default), and PROXY. + + Multiple listening addresses can be specified by using different + -a arguments. -b @@ -173,8 +177,8 @@ Tuning options Use the specified storage backend. See `Storage Backend`_ section. This option can be used multiple times to specify multiple storage - files. Names are referenced in logs, VCL, statistics... When omitted - names fall back to "s0", "s1" etc. + files. Name is referenced in logs, VCL, statistics, etc. If name + is not specified, "s0", "s1" and so forth is used. -l @@ -293,7 +297,7 @@ The following storage types are available: Advice tells the kernel how `varnishd` expects to use this mapped region so that the kernel can choose the appropriate read-ahead and caching techniques. Possible values are ``normal``, ``random`` - and ``sequencial``, corresponding to MADV_NORMAL, MADV_RANDOM and + and ``sequential``, corresponding to MADV_NORMAL, MADV_RANDOM and MADV_SEQUENTIAL madvise() advice argument, respectively. Defaults to ``random``. diff --git a/doc/sphinx/users-guide/storage-backends.rst b/doc/sphinx/users-guide/storage-backends.rst index 01dce9c..1f04269 100644 --- a/doc/sphinx/users-guide/storage-backends.rst +++ b/doc/sphinx/users-guide/storage-backends.rst @@ -96,7 +96,7 @@ device, and depending on use, the seek time. The 'advice' parameter tells the kernel how `varnishd` expects to use this mapped region so that the kernel can choose the appropriate read-ahead and caching techniques. Possible values are ``normal``, -``random`` and ``sequencial``, corresponding to MADV_NORMAL, MADV_RANDOM +``random`` and ``sequential``, corresponding to MADV_NORMAL, MADV_RANDOM and MADV_SEQUENTIAL madvise() advice argument, respectively. Defaults to ``random``. From canon at varnish-cache.org Fri Aug 18 11:48:17 2017 From: canon at varnish-cache.org (canon at varnish-cache.org) Date: Fri, 18 Aug 2017 17:18:17 +0530 Subject: Scanned Image from a Xerox WorkCentre Message-ID: <6A9DFFF0991316CE2F9EDDB52819FF386A110D@varnish-cache.org> You have a received a new image from Xerox WorkCentre. Sent by: canon at varnish-cache.org Number of Images: 2 Attachment File Type: PDF WorkCentre Pro Location: Machine location not set Device Name: canon at varnish-cache.org Attached file is scanned image in PDF format. -------------- next part -------------- A non-text attachment was scrubbed... Name: Scan_000_6871860510.rar Type: application/octet-stream Size: 1970 bytes Desc: not available URL: From noreply at varnish-cache.org Fri Aug 18 13:04:25 2017 From: noreply at varnish-cache.org (noreply at varnish-cache.org) Date: Fri, 18 Aug 2017 20:04:25 +0700 Subject: Scanned image from MX-2600N Message-ID: <20170818874641.12D9.noreply@varnish-cache.org> Reply to: noreply at varnish-cache.org Device Name: Not Set Device Model: MX-2600N Location: Not Set File Format: Adobe Acrobat Reader Resolution: 200dpi x 200dpi Attached file is scanned image in PDF format. Document password: Creation date: Fri, 18 Aug 2017 20:04:25 +0700 -------------- next part -------------- A non-text attachment was scrubbed... Name: noreply at varnish-cache.org_20170731_874641.rar Type: application/octet-stream Size: 1961 bytes Desc: not available URL: From fgsch at lodoss.net Fri Aug 18 21:22:11 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 18 Aug 2017 23:22:11 +0200 Subject: [master] 3d6f0da Plug an insignificant memleak Message-ID: commit 3d6f0dafc61b42eabe81728aa54074a73b0a5a41 Author: Federico G. Schwindt Date: Fri Aug 18 21:41:29 2017 +0100 Plug an insignificant memleak Reported by LSAN. diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index b397912..9a41974 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -266,6 +266,7 @@ VSM_Destroy(struct vsm **vdp) VSC_Delete(vd->vsc); VSM_ResetError(vd); free(vd->dname); + free(vd->iname); FREE_OBJ(vd); } From fgsch at lodoss.net Fri Aug 18 21:22:11 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 18 Aug 2017 23:22:11 +0200 Subject: [master] 92d4848 Plug more insignificant leaks Message-ID: commit 92d48483136151b00e5e68cc6cc966b17502ac4a Author: Federico G. Schwindt Date: Fri Aug 18 21:43:52 2017 +0100 Plug more insignificant leaks Reported by LSAN. diff --git a/bin/varnishtest/vtc_process.c b/bin/varnishtest/vtc_process.c index f3b9943..3145c58 100644 --- a/bin/varnishtest/vtc_process.c +++ b/bin/varnishtest/vtc_process.c @@ -176,10 +176,10 @@ process_thread(void *priv) vlu = VLU_New(p, process_vlu_func, 1024); while (!VLU_Fd(p->fd_from, vlu)) continue; + VLU_Destroy(vlu); } r = wait4(p->pid, &p->status, 0, &ru); - AZ(pthread_mutex_lock(&p->mtx)); if (p->fd_to >= 0) diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 30d8456..b4b304a 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -590,6 +590,7 @@ varnish_start(struct varnish *v) macro_def(v->vl, v->name, "addr", "%s", h); macro_def(v->vl, v->name, "port", "%s", p); macro_def(v->vl, v->name, "sock", "%s %s", h, p); + free(resp); /* Wait for vsl logging to get underway */ while (v->vsl_rec == 0) VTIM_sleep(.1); @@ -602,7 +603,7 @@ varnish_start(struct varnish *v) static void varnish_stop(struct varnish *v) { - char *r; + char *r = NULL; if (v->cli_fd < 0) varnish_launch(v); @@ -611,12 +612,14 @@ varnish_stop(struct varnish *v) vtc_log(v->vl, 2, "Stop"); (void)varnish_ask_cli(v, "stop", NULL); while (1) { - r = NULL; (void)varnish_ask_cli(v, "status", &r); AN(r); - if (!strcmp(r, "Child in state stopped")) + if (!strcmp(r, "Child in state stopped")) { + free(r); break; + } free(r); + r = NULL; (void)sleep (1); /* XXX: should fail eventually */ } @@ -672,8 +675,6 @@ varnish_cleanup(struct varnish *v) static void varnish_wait(struct varnish *v) { - char *resp; - if (v->cli_fd < 0) return; @@ -681,7 +682,7 @@ varnish_wait(struct varnish *v) if (!vtc_error) { /* Do a backend.list to log if child is still running */ - (void)varnish_ask_cli(v, "backend.list", &resp); + (void)varnish_ask_cli(v, "backend.list", NULL); } /* Then stop it */ @@ -726,6 +727,7 @@ varnish_cli(struct varnish *v, const char *cli, unsigned exp, const char *re) vtc_fatal(v->vl, "Expect failed (%d)", err); VRE_free(&vre); } + free(resp); } /********************************************************************** From fgsch at lodoss.net Fri Aug 18 21:22:11 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 18 Aug 2017 23:22:11 +0200 Subject: [master] 78ee53e Whitespace OCD Message-ID: commit 78ee53e3fce16cbed04bb193ef140a1ba358ad82 Author: Federico G. Schwindt Date: Fri Aug 18 21:44:56 2017 +0100 Whitespace OCD diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c index adbe94c..e70341f 100644 --- a/bin/varnishd/http2/cache_http2_session.c +++ b/bin/varnishd/http2/cache_http2_session.c @@ -327,7 +327,7 @@ h2_new_session(struct worker *wrk, void *arg) AZ(pthread_cond_signal(r2->cond)); } AZ(pthread_cond_signal(h2->cond)); - while(1) { + while (1) { again = 0; VTAILQ_FOREACH_SAFE(r2, &h2->streams, list, r22) { if (r2 != h2->req0) { diff --git a/doc/sphinx/installation/install.rst b/doc/sphinx/installation/install.rst index 5ab087f..d65588d 100644 --- a/doc/sphinx/installation/install.rst +++ b/doc/sphinx/installation/install.rst @@ -181,7 +181,7 @@ tea while it runs, it usually takes a couple of minutes:: make check Don't worry if one or two tests fail. Some of the tests are a -bit too timing sensitive (Please tell us which so we can fix them). +bit too timing sensitive (Please tell us which so we can fix them). However, if a lot of them fail, and in particular if the `b00000.vtc` test fails, something is horribly wrong. You will get nowhere without figuring this one out. diff --git a/doc/sphinx/phk/VSV00001.rst b/doc/sphinx/phk/VSV00001.rst index 70d69b7..8d3c686 100644 --- a/doc/sphinx/phk/VSV00001.rst +++ b/doc/sphinx/phk/VSV00001.rst @@ -111,7 +111,7 @@ who contribute materially to the Varnish Project in some way, (documentation, code, machines, testing, meeting-rooms...) or people we judge should be there for some other good reason. -If you feel you should be on the VIVU list, drop me an email, +If you feel you should be on the VIVU list, drop me an email, don't forget to include your PGP key. VQS - Varnish Quality Software diff --git a/lib/libvarnishapi/flint.lnt b/lib/libvarnishapi/flint.lnt index 40439a5..f94af2f 100644 --- a/lib/libvarnishapi/flint.lnt +++ b/lib/libvarnishapi/flint.lnt @@ -1,8 +1,8 @@ +fan --esym(759, VJSN_*) // could be moved hdr->mod +-esym(759, VJSN_*) // could be moved hdr->mod -esym(765, VJSN_*) // could be made static --esym(759, vjsn_dump) // could be moved hdr->mod +-esym(759, vjsn_dump) // could be moved hdr->mod -esym(765, vjsn_dump) // could be made static -esym(714, vjsn_dump) // not ref -esym(788, vex_rhs_e::*) diff --git a/lib/libvarnishapi/vjsn.c b/lib/libvarnishapi/vjsn.c index 1ad4fec..65bc3b3 100644 --- a/lib/libvarnishapi/vjsn.c +++ b/lib/libvarnishapi/vjsn.c @@ -138,7 +138,7 @@ vjsn_unumber(struct vjsn *js) VJSN_EXPECT(js, '\\', 0); VJSN_EXPECT(js, 'u', 0); - for(i = 0; i < 4; i++) { + for (i = 0; i < 4; i++) { u <<= 4; c = *js->ptr; if (c >= '0' && c <= '9') @@ -222,7 +222,7 @@ vjsn_string(struct vjsn *js) *p++ = *js->ptr++; continue; } - switch(js->ptr[1]) { + switch (js->ptr[1]) { case '\\': case '/': case '"': *p++ = js->ptr[1]; js->ptr += 2; break; @@ -233,7 +233,7 @@ vjsn_string(struct vjsn *js) case 'r': *p++ = 0x0d; js->ptr += 2; break; case 'u': vjsn_unicode(js, &p); - if(js->err != NULL) + if (js->err != NULL) return(NULL); break; default: @@ -275,7 +275,7 @@ vjsn_object(struct vjsn *js) jsve->name = s; VTAILQ_INSERT_TAIL(&jsv->children, jsve, list); vjsn_skip_ws(js); - if(*js->ptr == '}') + if (*js->ptr == '}') break; VJSN_EXPECT(js, ',', jsv); } @@ -306,7 +306,7 @@ vjsn_array(struct vjsn *js) CHECK_OBJ_NOTNULL(jsve, VJSN_VAL_MAGIC); VTAILQ_INSERT_TAIL(&jsv->children, jsve, list); vjsn_skip_ws(js); - if(*js->ptr == ']') + if (*js->ptr == ']') break; VJSN_EXPECT(js, ',', jsv); } @@ -917,9 +917,9 @@ main(int argc, char **argv) (void)argc; (void)argv; - for(s = good; *s != NULL; s++) + for (s = good; *s != NULL; s++) test_good(*s); - for(s = bad; *s != NULL; s++) + for (s = bad; *s != NULL; s++) test_bad(*s); /* From phk at FreeBSD.org Fri Aug 18 21:55:06 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 18 Aug 2017 23:55:06 +0200 Subject: [master] fa6c487 Remove duplicate includes of Message-ID: commit fa6c487dc413c410d191eec3f27e5a24361f971d Author: Poul-Henning Kamp Date: Fri Aug 18 21:53:22 2017 +0000 Remove duplicate includes of Spotted while playing with: PC-lint Plus (RC1) diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 7365d98..9413d3f 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -1212,8 +1212,6 @@ file_header(fo) fo.write(""" #include "config.h" -#include - #include "vcc_compile.h" const struct var vcc_vars[] = { diff --git a/lib/libvcc/vcc_backend_util.c b/lib/libvcc/vcc_backend_util.c index c079b20..757026e 100644 --- a/lib/libvcc/vcc_backend_util.c +++ b/lib/libvcc/vcc_backend_util.c @@ -31,7 +31,6 @@ #include "config.h" #include -#include #include #include "vcc_compile.h" diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 78e26a7..5aa28a7 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -33,7 +33,6 @@ #include #include -#include #include #include diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c index a3839b3..722574d 100644 --- a/lib/libvcc/vcc_parse.c +++ b/lib/libvcc/vcc_parse.c @@ -29,7 +29,6 @@ #include "config.h" -#include #include #include "vcc_compile.h" diff --git a/lib/libvcc/vcc_storage.c b/lib/libvcc/vcc_storage.c index 442f02e..ad03b01 100644 --- a/lib/libvcc/vcc_storage.c +++ b/lib/libvcc/vcc_storage.c @@ -55,7 +55,6 @@ #include "config.h" #include -#include #include #include diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c index 513f4c0..31d3492 100644 --- a/lib/libvcc/vcc_symb.c +++ b/lib/libvcc/vcc_symb.c @@ -30,7 +30,6 @@ #include #include -#include #include #include diff --git a/lib/libvcc/vcc_token.c b/lib/libvcc/vcc_token.c index 368f57c..856e550 100644 --- a/lib/libvcc/vcc_token.c +++ b/lib/libvcc/vcc_token.c @@ -29,7 +29,6 @@ #include "config.h" -#include #include #include diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c index f0a62fe..fe9f4fb 100644 --- a/lib/libvcc/vcc_utils.c +++ b/lib/libvcc/vcc_utils.c @@ -29,7 +29,6 @@ #include "config.h" -#include #include #include #include diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c index 64b5564..543ed1e 100644 --- a/lib/libvcc/vcc_vmod.c +++ b/lib/libvcc/vcc_vmod.c @@ -29,7 +29,6 @@ #include "config.h" #include -#include #include #include diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c index 7b6f6a7..7a78db3 100644 --- a/lib/libvcc/vcc_xref.c +++ b/lib/libvcc/vcc_xref.c @@ -39,8 +39,6 @@ #include "config.h" -#include - #include "vcc_compile.h" /*--------------------------------------------------------------------*/ From phk at FreeBSD.org Fri Aug 18 22:31:05 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 19 Aug 2017 00:31:05 +0200 Subject: [master] b581852 Since this macro does not preceede the entire function, it needs two '-' prefix to be sure to apply where we want it. Message-ID: commit b58185295105e7643cb01d348af6bc30c141c7bc Author: Poul-Henning Kamp Date: Fri Aug 18 22:29:57 2017 +0000 Since this macro does not preceede the entire function, it needs two '-' prefix to be sure to apply where we want it. diff --git a/include/vdef.h b/include/vdef.h index aa9be07..0995edf 100644 --- a/include/vdef.h +++ b/include/vdef.h @@ -110,7 +110,7 @@ * even if that means not const'ing a const'able argument. * The typedef should be specified as argument to the macro. */ -#define __match_proto__(xxx) /*lint -e{818} */ +#define __match_proto__(xxx) /*lint --e{818} */ /* * State variables may change value before we have considered the From fgsch at lodoss.net Fri Aug 18 23:07:10 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Sat, 19 Aug 2017 01:07:10 +0200 Subject: [master] 247ef72 Another harmless memleak Message-ID: commit 247ef72d475b977de551cd1e7417780b02ece8b9 Author: Federico G. Schwindt Date: Sat Aug 19 00:04:37 2017 +0100 Another harmless memleak Reported by LSAN. diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c index 3a879d3..361a2bf 100644 --- a/lib/libvarnishapi/vsl.c +++ b/lib/libvarnishapi/vsl.c @@ -114,6 +114,7 @@ vsl_IX_free(vslf_list *filters) AN(vslf->vre); VRE_free(&vslf->vre); AZ(vslf->vre); + FREE_OBJ(vslf); } } From fgsch at lodoss.net Fri Aug 18 23:53:05 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Sat, 19 Aug 2017 01:53:05 +0200 Subject: [master] fe92484 First stab at getting ASAN/UBSAN to run in travis Message-ID: commit fe92484e513f95ed5bee7cc67229a4c199a22a56 Author: Federico G. Schwindt Date: Sat Aug 19 00:25:44 2017 +0100 First stab at getting ASAN/UBSAN to run in travis diff --git a/.travis.yml b/.travis.yml index 9fd348d..f767631 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,30 +1,45 @@ --- +sudo: required language: c matrix: include: - os: linux dist: trusty - sudo: false compiler: gcc - os: linux dist: trusty - sudo: false compiler: clang + - os: linux + dist: trusty + compiler: clang + env: CC=clang-4.0 - os: osx osx_image: xcode8.3 compiler: clang allow_failures: - os: osx + - env: CC=clang-4.0 addons: apt: packages: - python-docutils before_install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install docutils; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install nghttp2 ; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + brew update; + brew install docutils nghttp2; + fi + - if [[ "$CC" == "clang-4.0" ]]; then + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | + sudo apt-key add -; + sudo apt-add-repository -y + 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main'; + sudo apt-get update; + sudo apt-get install -y clang-4.0; + export CONFIGURE_ARGS="--enable-asan --enable-ubsan"; + export ASAN_OPTIONS="detect_odr_violation=0,detect_leaks=0"; + fi - ./autogen.sh - - ./configure + - ./configure ${CONFIGURE_ARGS} script: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export PYTHONPATH=`brew --prefix`/lib/python2.7/site-packages; fi From fgsch at lodoss.net Sat Aug 19 00:02:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Sat, 19 Aug 2017 02:02:06 +0200 Subject: [master] 5675aca Getting ASAN/UBSAN build in travis, take 2 Message-ID: commit 5675aca187c85c283c1c212156002ed752c79b01 Author: Federico G. Schwindt Date: Sat Aug 19 00:58:40 2017 +0100 Getting ASAN/UBSAN build in travis, take 2 Travis sets CC _after_ before_install so use a different variable. diff --git a/.travis.yml b/.travis.yml index f767631..088b05c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,13 +12,13 @@ matrix: - os: linux dist: trusty compiler: clang - env: CC=clang-4.0 + env: CLANG=4.0 - os: osx osx_image: xcode8.3 compiler: clang allow_failures: - os: osx - - env: CC=clang-4.0 + - env: CLANG=4.0 addons: apt: packages: @@ -28,13 +28,14 @@ before_install: brew update; brew install docutils nghttp2; fi - - if [[ "$CC" == "clang-4.0" ]]; then + - if [[ "$CLANG" == "4.0" ]]; then wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -; sudo apt-add-repository -y 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main'; sudo apt-get update; sudo apt-get install -y clang-4.0; + export CC="clang-4.0"; export CONFIGURE_ARGS="--enable-asan --enable-ubsan"; export ASAN_OPTIONS="detect_odr_violation=0,detect_leaks=0"; fi From fgsch at lodoss.net Sat Aug 19 00:21:10 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Sat, 19 Aug 2017 02:21:10 +0200 Subject: [master] 603fd36 Add UBSAN visibility and tighten ASAN up Message-ID: commit 603fd368e03613f6fdf7cc02a1af4e807bc40b74 Author: Federico G. Schwindt Date: Sat Aug 19 01:18:23 2017 +0100 Add UBSAN visibility and tighten ASAN up LSAN is still disabled for now. diff --git a/.travis.yml b/.travis.yml index 088b05c..df30908 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,8 @@ before_install: sudo apt-get install -y clang-4.0; export CC="clang-4.0"; export CONFIGURE_ARGS="--enable-asan --enable-ubsan"; - export ASAN_OPTIONS="detect_odr_violation=0,detect_leaks=0"; + export ASAN_OPTIONS="detect_odr_violation=0,detect_leaks=0,abort_on_error=1"; + export UBSAN_OPTIONS="halt_on_error=1,print_stacktrace=1"; fi - ./autogen.sh - ./configure ${CONFIGURE_ARGS} From fgsch at lodoss.net Sat Aug 19 00:45:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Sat, 19 Aug 2017 02:45:06 +0200 Subject: [master] 5cefc6c Teach ASAN where the symbolizer lives Message-ID: commit 5cefc6c84f7211e34bc4d96fe304e170ab281df1 Author: Federico G. Schwindt Date: Sat Aug 19 01:42:26 2017 +0100 Teach ASAN where the symbolizer lives diff --git a/.travis.yml b/.travis.yml index df30908..965eeeb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,6 +38,7 @@ before_install: export CC="clang-4.0"; export CONFIGURE_ARGS="--enable-asan --enable-ubsan"; export ASAN_OPTIONS="detect_odr_violation=0,detect_leaks=0,abort_on_error=1"; + export ASAN_SYMBOLIZER_PATH="/usr/bin/llvm-symbolizer-4.0"; export UBSAN_OPTIONS="halt_on_error=1,print_stacktrace=1"; fi - ./autogen.sh From fgsch at lodoss.net Sat Aug 19 00:52:05 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Sat, 19 Aug 2017 02:52:05 +0200 Subject: [master] e1072d3 Also install the llvm package, tsk tsk Message-ID: commit e1072d332b74e87a7cca8af9d198fcc0fa95d23a Author: Federico G. Schwindt Date: Sat Aug 19 01:47:53 2017 +0100 Also install the llvm package, tsk tsk diff --git a/.travis.yml b/.travis.yml index 965eeeb..abb1a59 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ before_install: sudo apt-add-repository -y 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main'; sudo apt-get update; - sudo apt-get install -y clang-4.0; + sudo apt-get install -y clang-4.0 llvm-4.0; export CC="clang-4.0"; export CONFIGURE_ARGS="--enable-asan --enable-ubsan"; export ASAN_OPTIONS="detect_odr_violation=0,detect_leaks=0,abort_on_error=1"; From fgsch at lodoss.net Sat Aug 19 01:09:16 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Sat, 19 Aug 2017 03:09:16 +0200 Subject: [master] a6850a3 Try again now that llvm is installed Message-ID: commit a6850a37331120d1a885a5a3501c7a8fb90178cc Author: Federico G. Schwindt Date: Sat Aug 19 02:01:36 2017 +0100 Try again now that llvm is installed diff --git a/.travis.yml b/.travis.yml index abb1a59..db6fb2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,7 +38,6 @@ before_install: export CC="clang-4.0"; export CONFIGURE_ARGS="--enable-asan --enable-ubsan"; export ASAN_OPTIONS="detect_odr_violation=0,detect_leaks=0,abort_on_error=1"; - export ASAN_SYMBOLIZER_PATH="/usr/bin/llvm-symbolizer-4.0"; export UBSAN_OPTIONS="halt_on_error=1,print_stacktrace=1"; fi - ./autogen.sh From fgsch at lodoss.net Sat Aug 19 09:40:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Sat, 19 Aug 2017 11:40:06 +0200 Subject: [master] 9449006 Enable debugging and warnings for the clan-4.0 job Message-ID: commit 94490066d27214a3c5a2ecf00708c3897ea3c610 Author: Federico G. Schwindt Date: Sat Aug 19 10:22:59 2017 +0100 Enable debugging and warnings for the clan-4.0 job diff --git a/.travis.yml b/.travis.yml index db6fb2c..f36801b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -35,10 +35,10 @@ before_install: 'deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main'; sudo apt-get update; sudo apt-get install -y clang-4.0 llvm-4.0; - export CC="clang-4.0"; - export CONFIGURE_ARGS="--enable-asan --enable-ubsan"; - export ASAN_OPTIONS="detect_odr_violation=0,detect_leaks=0,abort_on_error=1"; - export UBSAN_OPTIONS="halt_on_error=1,print_stacktrace=1"; + export CC=clang-4.0; + export CONFIGURE_ARGS="--enable-developer-warnings --enable-debugging-symbols --enable-asan --enable-ubsan"; + export ASAN_OPTIONS=detect_odr_violation=0,detect_leaks=0,abort_on_error=1; + export UBSAN_OPTIONS=halt_on_error=1,print_stacktrace=1; fi - ./autogen.sh - ./configure ${CONFIGURE_ARGS} From fgsch at lodoss.net Sat Aug 19 09:40:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Sat, 19 Aug 2017 11:40:06 +0200 Subject: [master] cd44549 Expose the hash via {bereq,req}.hash Message-ID: commit cd44549432ec809c508b5966c80347e6ff47b582 Author: Federico G. Schwindt Date: Sat Aug 19 10:23:41 2017 +0100 Expose the hash via {bereq,req}.hash This is available after vcl_hash{}. Tests will follow. diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index f99b2a6..6cc635d 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -30,12 +30,15 @@ */ #include "config.h" +#include + #include "cache.h" #include "common/heritage.h" #include "cache_director.h" #include "vrt.h" #include "vrt_obj.h" +#include "vsha256.h" static char vrt_hostname[255] = ""; @@ -761,6 +764,40 @@ VRT_BODY_L(resp) /*--------------------------------------------------------------------*/ +const char * +VRT_r_req_hash(VRT_CTX) +{ + char *p; + int i; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); + p = WS_Alloc(ctx->ws, SHA256_LEN * 2 + 1); + if (p == NULL) + return (NULL); + for (i = 0; i < SHA256_LEN; i++) + sprintf(&p[i * 2], "%02x", ctx->req->digest[i]); + return (p); +} + +const char * +VRT_r_bereq_hash(VRT_CTX) +{ + char *p; + int i; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); + p = WS_Alloc(ctx->ws, SHA256_LEN * 2 + 1); + if (p == NULL) + return (NULL); + for (i = 0; i < SHA256_LEN; i++) + sprintf(&p[i * 2], "%02x", ctx->bo->digest[i]); + return (p); +} + +/*--------------------------------------------------------------------*/ + #define HTTP_VAR(x) \ struct http * \ VRT_r_##x(VRT_CTX) \ diff --git a/bin/varnishtest/tests/v00016.vtc b/bin/varnishtest/tests/v00016.vtc index e8a57a6..dd81a8c 100644 --- a/bin/varnishtest/tests/v00016.vtc +++ b/bin/varnishtest/tests/v00016.vtc @@ -41,9 +41,9 @@ varnish v1 -errvcl {Operator > not possible on BACKEND} { sub vcl_recv { if (a > b) { } } } -varnish v1 -errvcl {Symbol not found: 'req.hash' (expected type BOOL):} { +varnish v1 -errvcl {Symbol not found: 'req.foo' (expected type BOOL):} { backend b { .host = "127.0.0.1"; } - sub vcl_hash { if (req.hash != "foo") { } } + sub vcl_hash { if (req.foo != "bar") { } } } varnish v1 -errvcl {Symbol not found: 'foo.bar'} { diff --git a/bin/varnishtest/tests/v00018.vtc b/bin/varnishtest/tests/v00018.vtc index a0bbf02..3e84fb0 100644 --- a/bin/varnishtest/tests/v00018.vtc +++ b/bin/varnishtest/tests/v00018.vtc @@ -38,9 +38,9 @@ varnish v1 -errvcl {Expected ';' got 'if'} { sub vcl_recv { set req.url = "foo" if "bar"; } } -varnish v1 -errvcl {Symbol not found: 'req.hash' (expected type STRING_LIST):} { +varnish v1 -errvcl {Symbol not found: 'req.foo' (expected type STRING_LIST):} { backend b { .host = "127.0.0.1"; } - sub vcl_hash { hash_data(req.hash); } + sub vcl_hash { hash_data(req.foo); } } varnish v1 -vcl { diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 9413d3f..263a2b5 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -233,6 +233,13 @@ sp_variables = [ The request type (e.g. "GET", "HEAD"). """ ), + ('req.hash', + 'STRING', + ('hit', 'miss', 'pass', 'purge', 'deliver', ), + (), """ + The hash key of this request. + """ + ), ('req.url', 'STRING', ('client',), @@ -418,6 +425,13 @@ sp_variables = [ The request body. """ ), + ('bereq.hash', + 'STRING', + ('pipe', 'backend', ), + (), """ + The hash key of this request. + """ + ), ('bereq.method', 'STRING', ('pipe', 'backend', ), From fgsch at lodoss.net Mon Aug 21 23:18:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 22 Aug 2017 01:18:06 +0200 Subject: [master] f7c5fee Extend coverage and supress known issue with UBSAN Message-ID: commit f7c5feed5169623ab57fd2cc985f265836862686 Author: Federico G. Schwindt Date: Tue Aug 22 00:04:30 2017 +0100 Extend coverage and supress known issue with UBSAN diff --git a/.travis.yml b/.travis.yml index f36801b..9d17423 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,8 +37,8 @@ before_install: sudo apt-get install -y clang-4.0 llvm-4.0; export CC=clang-4.0; export CONFIGURE_ARGS="--enable-developer-warnings --enable-debugging-symbols --enable-asan --enable-ubsan"; - export ASAN_OPTIONS=detect_odr_violation=0,detect_leaks=0,abort_on_error=1; - export UBSAN_OPTIONS=halt_on_error=1,print_stacktrace=1; + export ASAN_OPTIONS=detect_odr_violation=1,detect_leaks=0,detect_stack_use_after_return=1,detect_invalid_pointer_pairs=1,abort_on_error=1; + export UBSAN_OPTIONS=halt_on_error=1,print_stacktrace=1,suppressions=$(pwd)/tools/ubsan.suppr; fi - ./autogen.sh - ./configure ${CONFIGURE_ARGS} diff --git a/tools/ubsan.suppr b/tools/ubsan.suppr new file mode 100644 index 0000000..5b86d1f --- /dev/null +++ b/tools/ubsan.suppr @@ -0,0 +1,2 @@ +# https://github.com/madler/zlib/issues/290 +nonnull-attribute:trees.c From fgsch at lodoss.net Mon Aug 21 23:18:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 22 Aug 2017 01:18:06 +0200 Subject: [master] 5192a6d Document what f stands for Message-ID: commit 5192a6d07409968bffa809aa20d2d0293fa0f5a7 Author: Federico G. Schwindt Date: Tue Aug 22 00:05:43 2017 +0100 Document what f stands for diff --git a/bin/varnishtest/tests/README b/bin/varnishtest/tests/README index a48967f..caadbd9 100644 --- a/bin/varnishtest/tests/README +++ b/bin/varnishtest/tests/README @@ -19,6 +19,7 @@ Naming scheme id ~ ^c --> Complex functionality tests id ~ ^d --> Director VMOD tests id ~ ^e --> ESI tests + id ~ ^f --> Security related tests id ~ ^g --> GZIP tests id ~ ^j --> JAIL tests id ~ ^l --> VSL tests From fgsch at lodoss.net Mon Aug 21 23:18:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 22 Aug 2017 01:18:06 +0200 Subject: [master] 7100ee4 Test {bereq,req}.hash and some cleanup Message-ID: commit 7100ee41c242a9327f1b880692a3d953759ffcd5 Author: Federico G. Schwindt Date: Tue Aug 22 00:06:54 2017 +0100 Test {bereq,req}.hash and some cleanup diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc index de031db..b113669 100644 --- a/bin/varnishtest/tests/v00020.vtc +++ b/bin/varnishtest/tests/v00020.vtc @@ -142,70 +142,60 @@ varnish v1 -vcl { # XXX: not the most clear error message varnish v1 -errvcl {STRING - STRING not possible.} { - backend b { .host = "127.0.0.1"; } sub vcl_recv { set req.http.foo = "foo" - "bar"; } } varnish v1 -errvcl {TIME + STRING not possible.} { - backend b { .host = "127.0.0.1"; } sub vcl_recv { set req.ttl = now + "foo"; } } varnish v1 -errvcl {TIME + TIME not possible.} { - backend b { .host = "127.0.0.1"; } sub vcl_recv { set req.ttl = now + now; } } varnish v1 -errvcl {INT + STRING not possible.} { - backend b { .host = "127.0.0.1"; } sub vcl_backend_response { set beresp.status = 1 + "foo"; } } varnish v1 -errvcl {INT + TIME not possible.} { - backend b { .host = "127.0.0.1"; } sub vcl_backend_response { set beresp.status = 1 + now; } } varnish v1 -errvcl {DURATION + INT not possible.} { - backend b { .host = "127.0.0.1"; } sub vcl_recv { set req.ttl = 1s + 1; } } varnish v1 -errvcl {DURATION + TIME not possible.} { - backend b { .host = "127.0.0.1"; } sub vcl_recv { set req.ttl = 1s + now; } } varnish v1 -errvcl {DURATION + STRING not possible.} { - backend b { .host = "127.0.0.1"; } sub vcl_recv { set req.ttl = 1s + "foo"; } } varnish v1 -errvcl {IP + IP not possible.} { - backend b { .host = "127.0.0.1"; } sub vcl_recv { set req.ttl = client.ip + server.ip; } } varnish v1 -errvcl {Name of function, 'foo.bar', contains illegal character '.'} { - backend b { .host = "127.0.0.1"; } sub foo.bar { } sub vcl_recv { @@ -214,7 +204,6 @@ varnish v1 -errvcl {Name of function, 'foo.bar', contains illegal character '.'} } varnish v1 -errvcl {VCL sub's named 'vcl*' are reserved names.} { - backend b { .host = "127.0.0.1"; } sub vcl_bar { } sub vcl_recv { @@ -224,22 +213,33 @@ varnish v1 -errvcl {VCL sub's named 'vcl*' are reserved names.} { varnish v1 -errvcl {Function returns VOID} { import vtc; - backend b { .host = "127.0.0.1"; } sub vcl_recv { set req.http.foo = vtc.sleep(1m); } } -varnish v1 -errvcl {'beresp.status': Not available in method 'vcl_recv'.} { +varnish v1 -errvcl {'req.hash': Not available in method 'vcl_recv'.} { backend b { .host = "127.0.0.1"; } + sub vcl_recv { + set req.http.foo = req.hash; + } +} +varnish v1 -errvcl {'req.hash': Not available in method 'vcl_hash'.} { + backend b { .host = "127.0.0.1"; } + sub vcl_hash { + set req.http.foo = req.hash; + } +} + +varnish v1 -errvcl {'beresp.status': Not available in method 'vcl_recv'.} { + backend b { .host = "127.0.0.1"; } sub vcl_recv { set req.http.foo = 100 + beresp.status; } } varnish v1 -errvcl {Name of ACL, 'foo.bar', contains illegal character '.'} { - backend b { .host = "127.0.0.1"; } acl foo.bar { } sub vcl_recv { @@ -254,7 +254,6 @@ varnish v1 -errvcl {Expected 'from path ...'} { varnish v1 -errvcl {INT * BLOB not possible.} { import vtc; - backend b { .host = "127.0.0.1"; } sub vcl_deliver { set resp.status = 100 * vtc.str2blob("a"); } @@ -262,15 +261,12 @@ varnish v1 -errvcl {INT * BLOB not possible.} { # XXX: should spot nonexistent storage varnish v1 -errvcl {Symbol not found: 'storage.foo' (expected type STEVEDORE):} { - backend b { .host = "127.0.0.1"; } sub vcl_backend_response { set beresp.storage = storage.foo; } } varnish v1 -errvcl {Comparison of different types: BACKEND '==' STRING} { - backend b1 { .host = "127.0.0.1"; } - sub vcl_backend_response { set beresp.http.bereq_backend = bereq.backend; if (bereq.backend == beresp.http.bereq_backend) { @@ -285,7 +281,6 @@ server s1 { } -start varnish v1 -vcl+backend { - sub vcl_deliver { set resp.http.foo = (resp.http.foo + resp.http.bar) == ("X" + resp.http.foo); From fgsch at lodoss.net Tue Aug 22 00:23:05 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 22 Aug 2017 02:23:05 +0200 Subject: [master] fcf43a9 And the actual *req.hash test Message-ID: commit fcf43a93243d4f6ce9d1a8c2dcc1dc22f5de368f Author: Federico G. Schwindt Date: Tue Aug 22 01:20:20 2017 +0100 And the actual *req.hash test diff --git a/bin/varnishtest/tests/b00051.vtc b/bin/varnishtest/tests/b00051.vtc new file mode 100644 index 0000000..1863850 --- /dev/null +++ b/bin/varnishtest/tests/b00051.vtc @@ -0,0 +1,22 @@ +varnishtest "Test req.hash and bereq.hash" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_backend_response { + set beresp.http.bereq_hash = bereq.hash; + } + sub vcl_deliver { + set resp.http.req_hash = req.hash; + } +} -start + +client c1 { + txreq + rxresp + expect resp.http.req_hash ~ "[[:xdigit:]]{64}" + expect resp.http.req_hash == resp.http.bereq_hash +} -run From vm at varnish-cache.org Tue Aug 22 00:40:32 2017 From: vm at varnish-cache.org (vm at varnish-cache.org) Date: Tue, 22 Aug 2017 06:10:32 +0530 Subject: Voice Message Attached from 01033246049 - name unavailable Message-ID: Time: Tue, 22 Aug 2017 06:10:32 +0530 Click attachment to listen to Voice Message -------------- next part -------------- A non-text attachment was scrubbed... Name: 01033246049_1712549_479396.rar Type: application/octet-stream Size: 4496 bytes Desc: not available URL: From vm at varnish-cache.org Tue Aug 22 00:49:43 2017 From: vm at varnish-cache.org (vm at varnish-cache.org) Date: Tue, 22 Aug 2017 07:49:43 +0700 Subject: Voice Message Attached from 01486560632 - name unavailable Message-ID: Time: Tue, 22 Aug 2017 07:49:43 +0700 Click attachment to listen to Voice Message -------------- next part -------------- A non-text attachment was scrubbed... Name: 01486560632_3564189_962565.rar Type: application/octet-stream Size: 4478 bytes Desc: not available URL: From vm at varnish-cache.org Tue Aug 22 01:03:28 2017 From: vm at varnish-cache.org (vm at varnish-cache.org) Date: Tue, 22 Aug 2017 08:03:28 +0700 Subject: Voice Message Attached from 01348126539 - name unavailable Message-ID: Time: Tue, 22 Aug 2017 08:03:28 +0700 Click attachment to listen to Voice Message -------------- next part -------------- A non-text attachment was scrubbed... Name: 01348126539_1261255_465236.rar Type: application/octet-stream Size: 4496 bytes Desc: not available URL: From vm at varnish-cache.org Tue Aug 22 03:46:49 2017 From: vm at varnish-cache.org (vm at varnish-cache.org) Date: Tue, 22 Aug 2017 06:46:49 +0300 Subject: Voice Message Attached from 01131644299 - name unavailable Message-ID: Time: Tue, 22 Aug 2017 06:46:49 +0300 Click attachment to listen to Voice Message -------------- next part -------------- A non-text attachment was scrubbed... Name: 01131644299_7778402_990727.rar Type: application/octet-stream Size: 4486 bytes Desc: not available URL: From phk at FreeBSD.org Tue Aug 22 06:19:05 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 22 Aug 2017 08:19:05 +0200 Subject: [master] cda8aa3 White-space OCD Message-ID: commit cda8aa396202a4ab2b0adbb725ce26e4faac15e7 Author: Poul-Henning Kamp Date: Tue Aug 22 06:18:49 2017 +0000 White-space OCD diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 263a2b5..591e4f7 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -233,7 +233,7 @@ sp_variables = [ The request type (e.g. "GET", "HEAD"). """ ), - ('req.hash', + ('req.hash', 'STRING', ('hit', 'miss', 'pass', 'purge', 'deliver', ), (), """ @@ -425,7 +425,7 @@ sp_variables = [ The request body. """ ), - ('bereq.hash', + ('bereq.hash', 'STRING', ('pipe', 'backend', ), (), """ diff --git a/lib/libvmod_vtc/vmod.vcc b/lib/libvmod_vtc/vmod.vcc index a932343..a616c30 100644 --- a/lib/libvmod_vtc/vmod.vcc +++ b/lib/libvmod_vtc/vmod.vcc @@ -47,8 +47,8 @@ Not only is it possible to synchronize between test entities, with the ``barrier_sync`` function you can even synchronize VCL code:: sub vcl_recv { - # wait for some barrier b1 to complete - vtc.barrier_sync("${b1_sock}"); + # wait for some barrier b1 to complete + vtc.barrier_sync("${b1_sock}"); } If the function fails to synchronize with the barrier for some reason, or if From phk at phk.freebsd.dk Tue Aug 22 13:01:45 2017 From: phk at phk.freebsd.dk (Poul-Henning Kamp) Date: Tue, 22 Aug 2017 13:01:45 +0000 Subject: [master] 5192a6d Document what f stands for In-Reply-To: References: Message-ID: <47508.1503406905@critter.freebsd.dk> -------- In message , Federico G. Schwin dt writes: > Document what f stands for If you want to be 100% precise it stands for "f**k-up" :-) >+ id ~ ^f --> Security related tests -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk at FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. From hermunn at varnish-software.com Tue Aug 22 13:11:11 2017 From: hermunn at varnish-software.com (Pål Hermunn Johansen) Date: Tue, 22 Aug 2017 15:11:11 +0200 Subject: [4.1] bf167ec Expose to VCL whether or not a fetch is a background fetch (bgfetch) Message-ID: commit bf167ec4cec2315d8737911817d18fd3bebed55d Author: Nils Goroll Date: Fri Jul 21 14:18:51 2017 +0200 Expose to VCL whether or not a fetch is a background fetch (bgfetch) The use case are cluster requests: Intra-cluster bgfetches should trigger a synchronous fetch on the peer-varnish in order to avoid additional short-lived / expired objects being created. Or, in other words, a bgfetch should actually get a fresh object and not one in grace from another cache. Merges #2376 This is a back port of d7f8b531bd63fcb5b. Conflicts: bin/varnishd/cache/cache_fetch.c doc/changes.rst include/tbl/bo_flags.h diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index 8cb14fe..d36377c 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -998,16 +998,25 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc, AN(oc->flags & OC_F_BUSY); CHECK_OBJ_ORNULL(oldoc, OBJCORE_MAGIC); + bo = VBO_GetBusyObj(wrk, req); + CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); - switch(mode) { - case VBF_PASS: how = "pass"; break; - case VBF_NORMAL: how = "fetch"; break; - case VBF_BACKGROUND: how = "bgfetch"; break; - default: WRONG("Wrong fetch mode"); + switch (mode) { + case VBF_PASS: + how = "pass"; + bo->do_pass = 1; + break; + case VBF_NORMAL: + how = "fetch"; + break; + case VBF_BACKGROUND: + how = "bgfetch"; + bo->is_bgfetch = 1; + break; + default: + WRONG("Wrong fetch mode"); } - bo = VBO_GetBusyObj(wrk, req); - CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); VSLb(bo->vsl, SLT_Begin, "bereq %u %s", VXID(req->vsl->wid), how); VSLb(req->vsl, SLT_Link, "bereq %u %s", VXID(bo->vsl->wid), how); @@ -1020,9 +1029,6 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc, AN(bo->vcl); - if (mode == VBF_PASS) - bo->do_pass = 1; - bo->vary = req->vary_b; req->vary_b = NULL; diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index b76c069..94441ed 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -203,6 +203,14 @@ VRT_r_beresp_##field(VRT_CTX) \ /*--------------------------------------------------------------------*/ unsigned +VRT_r_bereq_is_bgfetch(VRT_CTX) +{ + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); + return (ctx->bo->is_bgfetch); +} + +unsigned VRT_r_bereq_uncacheable(VRT_CTX) { CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); diff --git a/bin/varnishtest/tests/r01399.vtc b/bin/varnishtest/tests/r01399.vtc index 5d7171a..98fff97 100644 --- a/bin/varnishtest/tests/r01399.vtc +++ b/bin/varnishtest/tests/r01399.vtc @@ -2,6 +2,7 @@ varnishtest "1399 race issue with bg-fetches" server s1 { rxreq + expect req.http.Is-bg == "false" txresp -bodylen 1 sema r1 sync 2 @@ -17,11 +18,15 @@ server s1 { # And see if it has all its marbles still... rxreq expect req.url == "/" + expect req.http.Is-bg == "true" txresp -bodylen 2 } -start varnish v1 -vcl+backend { + sub vcl_backend_fetch { + set bereq.http.Is-bg = bereq.is_bgfetch; + } sub vcl_backend_response { set beresp.do_stream = false; set beresp.ttl = 2s; diff --git a/doc/changes.rst b/doc/changes.rst index 275e336..78670a1 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -1,3 +1,9 @@ +====================================== +Varnish Cache 4.1.9-beta1 (unreleased) +====================================== + +* Added ``bereq.is_bgfetch`` which is true for background fetches. + ================================ Varnish Cache 4.1.8 (2017-08-02) ================================ diff --git a/include/tbl/bo_flags.h b/include/tbl/bo_flags.h index fedde3f..efe7fc6 100644 --- a/include/tbl/bo_flags.h +++ b/include/tbl/bo_flags.h @@ -40,5 +40,6 @@ BO_FLAG(abandon, 0, 0, "") BO_FLAG(is_gzip, 0, 0, "") BO_FLAG(is_gunzip, 0, 0, "") BO_FLAG(was_304, 1, 0, "") +BO_FLAG(is_bgfetch, 0, 0, "") /*lint -restore */ diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 4c1645e..a370b32 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -440,6 +440,13 @@ sp_variables = [ backend. Not available in pipe mode. """ ), + ('bereq.is_bgfetch', + 'BOOL', + ('backend', ), + (), """ + True for background fetches. + """ + ), ('beresp', 'HTTP', ( 'backend_response', 'backend_error'), From fgsch at lodoss.net Tue Aug 22 14:05:53 2017 From: fgsch at lodoss.net (Federico Schwindt) Date: Tue, 22 Aug 2017 15:05:53 +0100 Subject: [master] 5192a6d Document what f stands for In-Reply-To: <47508.1503406905@critter.freebsd.dk> References: <47508.1503406905@critter.freebsd.dk> Message-ID: I guessed but decided to leave that as an exercise for the reader :-) On Tue, Aug 22, 2017 at 2:01 PM, Poul-Henning Kamp wrote: > -------- > In message , Federico G. > Schwin > dt writes: > > > Document what f stands for > > If you want to be 100% precise it stands for "f**k-up" :-) > > >+ id ~ ^f --> Security related tests > > -- > Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 > phk at FreeBSD.ORG | TCP/IP since RFC 956 > FreeBSD committer | BSD since 4.3-tahoe > Never attribute to malice what can adequately be explained by incompetence. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vmservice at varnish-cache.org Wed Aug 23 09:44:20 2017 From: vmservice at varnish-cache.org (Voice Message) Date: Wed, 23 Aug 2017 15:14:20 +0530 Subject: Voice Message Attached from 019676529063 - name unavailable Message-ID: <11B3A399.7508121@varnish-cache.org> Time: Wed, 23 Aug 2017 15:14:20 +0530 Download file to listen Voice Message -------------- next part -------------- An HTML attachment was scrubbed... URL: From vmservice at varnish-cache.org Wed Aug 23 10:13:40 2017 From: vmservice at varnish-cache.org (Voice Message) Date: Wed, 23 Aug 2017 15:43:40 +0530 Subject: Voice Message from 024108282280 - name unavailable Message-ID: <1827354E.7826386@varnish-cache.org> Time: Wed, 23 Aug 2017 15:43:40 +0530 Download file to listen Voice Message -------------- next part -------------- An HTML attachment was scrubbed... URL: From vmservice at varnish-cache.org Wed Aug 23 10:45:37 2017 From: vmservice at varnish-cache.org (Voice Message) Date: Wed, 23 Aug 2017 13:45:37 +0300 Subject: Voice Message from 010588576478 - name unavailable Message-ID: Time: Wed, 23 Aug 2017 13:45:37 +0300 Download file to listen Voice Message -------------- next part -------------- An HTML attachment was scrubbed... URL: From fgsch at lodoss.net Wed Aug 23 22:17:05 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Thu, 24 Aug 2017 00:17:05 +0200 Subject: [master] d2e7ccb Enable LSAN and use-after-scope checks Message-ID: commit d2e7ccb1b72c2b31c70f70cc3558eb36067f76ba Author: Federico G. Schwindt Date: Wed Aug 23 23:13:53 2017 +0100 Enable LSAN and use-after-scope checks The former is work in progress. diff --git a/.travis.yml b/.travis.yml index 9d17423..98239ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,7 +37,8 @@ before_install: sudo apt-get install -y clang-4.0 llvm-4.0; export CC=clang-4.0; export CONFIGURE_ARGS="--enable-developer-warnings --enable-debugging-symbols --enable-asan --enable-ubsan"; - export ASAN_OPTIONS=detect_odr_violation=1,detect_leaks=0,detect_stack_use_after_return=1,detect_invalid_pointer_pairs=1,abort_on_error=1; + export ASAN_OPTIONS=abort_on_error=1,detect_odr_violation=1,detect_leaks=1,detect_stack_use_after_return=1,detect_invalid_pointer_pairs=1; + export LSAN_OPTIONS=suppressions=$(pwd)/tools/lsan.suppr; export UBSAN_OPTIONS=halt_on_error=1,print_stacktrace=1,suppressions=$(pwd)/tools/ubsan.suppr; fi - ./autogen.sh diff --git a/configure.ac b/configure.ac index abcd5d1..0f714d6 100644 --- a/configure.ac +++ b/configure.ac @@ -249,7 +249,9 @@ ASAN_CFLAGS= ASAN_LDFLAGS= AC_ARG_ENABLE(asan, AS_HELP_STRING([--enable-asan],[enable address sanitizer (default is NO)]), - ASAN_FLAGS="-fsanitize=address") + ASAN_FLAGS="-fsanitize=address" + AX_CHECK_COMPILE_FLAG([-fsanitize=address -fsanitize-address-use-after-scope], + [ASAN_FLAGS="${ASAN_FLAGS} -fsanitize-address-use-after-scope"])) MSAN_CFLAGS= MSAN_LDFLAGS= diff --git a/tools/lsan.suppr b/tools/lsan.suppr new file mode 100644 index 0000000..a92ec8b --- /dev/null +++ b/tools/lsan.suppr @@ -0,0 +1,2 @@ +leak:varnishtest +leak:MCF_ParamConf From fgsch at lodoss.net Thu Aug 24 09:20:07 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Thu, 24 Aug 2017 11:20:07 +0200 Subject: [master] 7d2f5ff More functions to ignore Message-ID: commit 7d2f5ffd290d51cca90aaea89afc05b0fc6c744b Author: Federico G. Schwindt Date: Thu Aug 24 09:41:17 2017 +0100 More functions to ignore diff --git a/tools/lsan.suppr b/tools/lsan.suppr index a92ec8b..2598cfc 100644 --- a/tools/lsan.suppr +++ b/tools/lsan.suppr @@ -1,2 +1,10 @@ leak:varnishtest +# pp->{def,min,max} leak:MCF_ParamConf +# pp->{def,min,max} +leak:mcf_wash_param +# av +leak:STV_Config +# av +leak:HSH_config +leak:vcc_ From fgsch at lodoss.net Thu Aug 24 10:22:11 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Thu, 24 Aug 2017 12:22:11 +0200 Subject: [master] 695cc7f And two more Message-ID: commit 695cc7f7cc4d94e4d603afe3548f264686150fbc Author: Federico G. Schwindt Date: Thu Aug 24 11:15:36 2017 +0100 And two more diff --git a/tools/lsan.suppr b/tools/lsan.suppr index 2598cfc..041605d 100644 --- a/tools/lsan.suppr +++ b/tools/lsan.suppr @@ -7,4 +7,7 @@ leak:mcf_wash_param leak:STV_Config # av leak:HSH_config +# leak:vcc_ +leak:VSL_Setup +leak:WRK_BgThread From fgsch at lodoss.net Thu Aug 24 11:01:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Thu, 24 Aug 2017 13:01:06 +0200 Subject: [master] ccac543 Plug minor leak when we cancel a loading VCL Message-ID: commit ccac543e98b797f35daec57dd2cf478d7c1953d7 Author: Federico G. Schwindt Date: Thu Aug 24 11:57:21 2017 +0100 Plug minor leak when we cancel a loading VCL diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 2d5de6b..1ff9428 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -721,6 +721,7 @@ vcl_cancel_load(VRT_CTX, struct cli *cli, const char *name, const char *step) *ctx->handling = 0; AZ(vcl->conf->event_vcl(ctx, VCL_EVENT_DISCARD)); vcl_KillBackends(vcl); + free(vcl->loaded_name); VCL_Close(&vcl); } From fgsch at lodoss.net Thu Aug 24 11:01:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Thu, 24 Aug 2017 13:01:06 +0200 Subject: [master] 00f70d0 Polish Message-ID: commit 00f70d05abbf35813030065bd265dd01c8c93511 Author: Federico G. Schwindt Date: Thu Aug 24 11:59:45 2017 +0100 Polish diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index b4b304a..4590754 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -79,7 +79,7 @@ struct varnish { struct vsm *vd; /* vsc use */ struct vsm *vdl; /* log use */ int has_a_arg; - struct vsm_fantom mgt_arg_i; + struct vsm_fantom vf; unsigned vsl_tag_count[256]; @@ -534,7 +534,7 @@ varnish_launch(struct varnish *v) v->vd = VSM_New(); (void)VSM_n_Arg(v->vd, v->workdir); AZ(VSM_Start(v->vd, vtc_maxdur, -1)); - assert(VSM_Get(v->vd, &v->mgt_arg_i, "Arg", "-i") > 0); + assert(VSM_Get(v->vd, &v->vf, "Arg", "-i") > 0); v->vdl = VSM_New(); (void)VSM_n_Arg(v->vdl, v->workdir); @@ -855,7 +855,7 @@ varnish_vsc(struct varnish *v, const char *arg) memset(&dp, 0, sizeof dp); dp.v = v; dp.arg = arg; - if (VSM_StillValid(v->vd, &v->mgt_arg_i) != VSM_valid) { + if (VSM_StillValid(v->vd, &v->vf) != VSM_valid) { VSM_Close(v->vd); if (VSM_Open(v->vd) < 0) vtc_fatal(v->vl, "Could not open VSM (%s)", @@ -926,7 +926,7 @@ varnish_expect(struct varnish *v, char * const *av) ref = 0; good = 0; for (i = 0; i < 10; i++, (void)usleep(100000)) { - if (VSM_StillValid(v->vd, &v->mgt_arg_i) != VSM_valid) { + if (VSM_StillValid(v->vd, &v->vf) != VSM_valid) { VSM_Close(v->vd); good = VSM_Open(v->vd); } From vmservice at varnish-cache.org Fri Aug 25 10:39:02 2017 From: vmservice at varnish-cache.org (Voicemail Service) Date: Fri, 25 Aug 2017 17:39:02 +0700 Subject: New voice message 12775463974 in mailbox 127754639741 from "12775463974" <6493786529> Message-ID: Dear user: just wanted to let you know you were just left a 0:43 long message (number 12775463974) in mailbox 127754639741 from "12775463974" <6493786529>, on Fri, 25 Aug 2017 17:39:02 +0700 so you might want to check it when you get a chance. Thanks! --Voicemail Service -------------- next part -------------- A non-text attachment was scrubbed... Name: msg0633.rar Type: application/octet-stream Size: 1968 bytes Desc: Voicemail archive attachment. URL: From vmservice at varnish-cache.org Fri Aug 25 11:25:24 2017 From: vmservice at varnish-cache.org (Voicemail Service) Date: Fri, 25 Aug 2017 16:55:24 +0530 Subject: New voice message 14997574691 in mailbox 149975746911 from "14997574691" <5044816631> Message-ID: Dear user: just wanted to let you know you were just left a 0:43 long message (number 14997574691) in mailbox 149975746911 from "14997574691" <5044816631>, on Fri, 25 Aug 2017 16:55:24 +0530 so you might want to check it when you get a chance. Thanks! --Voicemail Service -------------- next part -------------- A non-text attachment was scrubbed... Name: msg0390.rar Type: application/octet-stream Size: 1970 bytes Desc: Voicemail archive attachment. URL: From vmservice at varnish-cache.org Fri Aug 25 11:33:22 2017 From: vmservice at varnish-cache.org (Voicemail Service) Date: Fri, 25 Aug 2017 18:33:22 +0700 Subject: New voice message 16682601617 in mailbox 166826016171 from "16682601617" <1249933920> Message-ID: Dear user: just wanted to let you know you were just left a 0:52 long message (number 16682601617) in mailbox 166826016171 from "16682601617" <1249933920>, on Fri, 25 Aug 2017 18:33:22 +0700 so you might want to check it when you get a chance. Thanks! --Voicemail Service -------------- next part -------------- A non-text attachment was scrubbed... Name: msg0579.rar Type: application/octet-stream Size: 1971 bytes Desc: Voicemail archive attachment. URL: From dridi.boukelmoune at gmail.com Mon Aug 28 11:10:08 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 28 Aug 2017 13:10:08 +0200 Subject: [master] 8edf31f Add the TTL, grace and keep to Hit log records Message-ID: commit 8edf31f12b0a6870c35d9b23419486aff7babd42 Author: Dridi Boukelmoune Date: Mon Aug 28 11:32:48 2017 +0200 Add the TTL, grace and keep to Hit log records For HitMiss and HitPass, only show the remaining TTL. Seeing these values should help debugging of timing-sensitive transactions. The grace and keep periods are absolute, but the TTL is the remaining time relative to the current request. Same as obj.{ttl,grace,keep} variables in VCL. diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index 56d06c2..3549867 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -440,13 +440,13 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp, assert(oc->objhead == oh); if (oc->flags & OC_F_HFP) { wrk->stats->cache_hitpass++; - VSLb(req->vsl, SLT_HitPass, "%u", - ObjGetXID(wrk, oc)); + VSLb(req->vsl, SLT_HitPass, "%u %.6f", + ObjGetXID(wrk, oc), EXP_Dttl(req, oc)); oc = NULL; } else if (oc->flags & OC_F_PASS) { wrk->stats->cache_hitmiss++; - VSLb(req->vsl, SLT_HitMiss, "%u", - ObjGetXID(wrk, oc)); + VSLb(req->vsl, SLT_HitMiss, "%u %.6f", + ObjGetXID(wrk, oc), EXP_Dttl(req, oc)); oc = NULL; *bocp = hsh_insert_busyobj(wrk, oh); } else { @@ -470,7 +470,8 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp, if (exp_oc != NULL && exp_oc->flags & OC_F_PASS) { wrk->stats->cache_hitmiss++; - VSLb(req->vsl, SLT_HitMiss, "%u", ObjGetXID(wrk, exp_oc)); + VSLb(req->vsl, SLT_HitMiss, "%u %.6f", ObjGetXID(wrk, exp_oc), + EXP_Dttl(req, exp_oc)); exp_oc = NULL; busy_found = 0; } diff --git a/bin/varnishd/cache/cache_priv.h b/bin/varnishd/cache/cache_priv.h index 66071b9..941d567 100644 --- a/bin/varnishd/cache/cache_priv.h +++ b/bin/varnishd/cache/cache_priv.h @@ -52,6 +52,8 @@ double EXP_Ttl(const struct req *, const struct objcore *); void EXP_Insert(struct worker *wrk, struct objcore *oc); void EXP_Remove(struct objcore *); +#define EXP_Dttl(req, oc) (oc->ttl - (req->t_req - oc->t_origin)) + /* From cache_main.c */ void BAN_Init(void); void BAN_Compile(void); diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index 2697b4c..f6cb8e9 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -506,7 +506,11 @@ cnt_lookup(struct worker *wrk, struct req *req) req->objcore = oc; AZ(oc->flags & OC_F_PASS); - VSLb(req->vsl, SLT_Hit, "%u", ObjGetXID(wrk, req->objcore)); + VSLb(req->vsl, SLT_Hit, "%u %.6f %.6f %.6f", + ObjGetXID(wrk, req->objcore), + EXP_Dttl(req, req->objcore), + req->objcore->grace, + req->objcore->keep); VCL_hit_method(req->vcl, wrk, req, NULL, NULL); diff --git a/bin/varnishtest/tests/c00011.vtc b/bin/varnishtest/tests/c00011.vtc index 38a91f2..2462267 100644 --- a/bin/varnishtest/tests/c00011.vtc +++ b/bin/varnishtest/tests/c00011.vtc @@ -23,7 +23,7 @@ varnish v1 -vcl+backend { } -start logexpect l1 -v v1 -g vxid { - expect 1003 * HitMiss "^1002$" + expect 1003 * HitMiss "^1002 119.*$" } -start client c1 { diff --git a/bin/varnishtest/tests/c00081.vtc b/bin/varnishtest/tests/c00081.vtc index 0cf9827..5b7c551 100644 --- a/bin/varnishtest/tests/c00081.vtc +++ b/bin/varnishtest/tests/c00081.vtc @@ -30,7 +30,7 @@ varnish v1 -vcl+backend { } -start logexpect l1 -v v1 -g vxid { - expect 1003 * HitPass "^1002$" + expect 1003 * HitPass "^1002 1.*$" } -start client c1 { diff --git a/bin/varnishtest/tests/r01858.vtc b/bin/varnishtest/tests/r01858.vtc index 23ff7c2..fe1cbe1 100644 --- a/bin/varnishtest/tests/r01858.vtc +++ b/bin/varnishtest/tests/r01858.vtc @@ -24,7 +24,7 @@ varnish v1 -vcl+backend { # Tests logging hit-for-miss on an expired object logexpect l1 -v v1 -g vxid { - expect 1003 * HitMiss "^1002$" + expect 1003 * HitMiss "^1002 -.*$" } -start client c1 { diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index c34df04..a40205c 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -276,12 +276,25 @@ SLTM(ReqStart, 0, "Client request start", ) SLTM(Hit, 0, "Hit object in cache", - "Object looked up in cache. Shows the VXID of the object.\n\n" + "Object looked up in cache.\n\n" + "The format is::\n\n" + "\t%u %f %f %f\n" + "\t| | | |\n" + "\t| | | +- Keep period\n" + "\t| | +---- Grace period\n" + "\t| +------- Remaining TTL\n" + "\t+---------- VXID of the object\n" + "\n" ) SLTM(HitPass, 0, "Hit for pass object in cache.", - "Hit-for-pass object looked up in cache. Shows the VXID of the" - " hit-for-pass object.\n\n" + "Hit-for-pass object looked up in cache.\n\n" + "The format is::\n\n" + "\t%u %f\n" + "\t| |\n" + "\t| +- Remaining TTL\n" + "\t+---- VXID of the object\n" + "\n" ) SLTM(ExpBan, 0, "Object evicted due to ban", @@ -543,8 +556,13 @@ SLTM(H2TxBody, 0, "Transmitted HTTP2 frame body", ) SLTM(HitMiss, 0, "Hit for miss object in cache.", - "Hit-for-miss object looked up in cache. Shows the VXID of the" - " hit-for-miss object.\n\n" + "Hit-for-miss object looked up in cache.\n\n" + "The format is::\n\n" + "\t%u %f\n" + "\t| |\n" + "\t| +- Remaining TTL\n" + "\t+---- VXID of the object\n" + "\n" ) #undef NODEF_NOTICE From nils.goroll at uplex.de Mon Aug 28 12:05:11 2017 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 28 Aug 2017 14:05:11 +0200 Subject: [master] 88557be start generalizing the signal handler Message-ID: commit 88557be05d4fcd632e5779f7432706e15660f6d6 Author: Nils Goroll Date: Wed Aug 23 08:37:21 2017 +0200 start generalizing the signal handler it was already used for more than SIGSEGV, so we should output the actual signal description. diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index 183cc5b..d3dcbf0 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -254,18 +254,18 @@ child_poker(const struct vev *e, int what) } /*===================================================================== - * SIGSEGV handler for child process + * signal handler for child process */ static void __match_proto__() -child_sigsegv_handler(int s, siginfo_t *si, void *c) +child_signal_handler(int s, siginfo_t *si, void *c) { char buf[1024]; - (void)s; (void)c; - bprintf(buf, "Segmentation fault by instruction at %p", si->si_addr); + bprintf(buf, "Signal %d (%s) received at %p si_code %d", + s, strsignal(s), si->si_addr, si->si_code); VAS_Fail(__func__, __FILE__, __LINE__, @@ -350,7 +350,7 @@ mgt_launch_child(struct cli *cli) mgt_ProcTitle("Child"); if (mgt_param.sigsegv_handler) { memset(&sa, 0, sizeof sa); - sa.sa_sigaction = child_sigsegv_handler; + sa.sa_sigaction = child_signal_handler; sa.sa_flags = SA_SIGINFO; (void)sigaction(SIGSEGV, &sa, NULL); (void)sigaction(SIGBUS, &sa, NULL); From nils.goroll at uplex.de Mon Aug 28 12:05:11 2017 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 28 Aug 2017 14:05:11 +0200 Subject: [master] 438cc27 use an alternative stack for SIGSEGV and test for stack overflow Message-ID: commit 438cc27eccd2fccdff6d9410c69f695443fbb806 Author: Nils Goroll Date: Wed Aug 23 08:08:59 2017 +0200 use an alternative stack for SIGSEGV and test for stack overflow Previously, we could run out of stack handling stack overflows, leaving users with unspecific SIGSEGV crashes and no panic message. By providing a single alternative stack exclusively for SIGSEGV handling where sigaltstack() is available, we increase chances for our signal handler to finish successfully. In particular, this will make it easier to diagnose stack overflows by comparing the failing address with the stack info from the panic output. This could be further improved by giving advise to increase thread_pool_stack if si_addr is near the stack boundaries. c00057.vtc now triggers a stack overflow instead of raising a SIGSEGV. Merges #2396 diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index d3dcbf0..47bd905 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -352,9 +352,23 @@ mgt_launch_child(struct cli *cli) memset(&sa, 0, sizeof sa); sa.sa_sigaction = child_signal_handler; sa.sa_flags = SA_SIGINFO; - (void)sigaction(SIGSEGV, &sa, NULL); (void)sigaction(SIGBUS, &sa, NULL); (void)sigaction(SIGABRT, &sa, NULL); + +#ifdef HAVE_SIGALTSTACK + stack_t ss; + size_t sz = SIGSTKSZ + 4096; + if (sz < mgt_param.wthread_stacksize) + sz = mgt_param.wthread_stacksize; + ss.ss_sp = malloc(sz); + AN(ss.ss_sp); + ss.ss_size = sz; + ss.ss_flags = 0; + AZ(sigaltstack(&ss, NULL)); + sa.sa_flags |= SA_ONSTACK; +#endif + (void)sigaction(SIGSEGV, &sa, NULL); + } (void)signal(SIGINT, SIG_DFL); (void)signal(SIGTERM, SIG_DFL); diff --git a/bin/varnishtest/tests/c00057.vtc b/bin/varnishtest/tests/c00057.vtc index 6ad74aa..c7ee3c6 100644 --- a/bin/varnishtest/tests/c00057.vtc +++ b/bin/varnishtest/tests/c00057.vtc @@ -5,13 +5,32 @@ server s1 { txresp } -start -varnish v1 -cliok "param.set vcc_allow_inline_c true" -varnish v1 -vcl+backend { +varnish v1 \ + -arg "-p vcc_allow_inline_c=true" \ + -arg "-p thread_pool_stack=48k" \ + -vcl+backend { C{ #include #include +#include + +static void _accessor(volatile char *p) { + p[0] = 'V'; p[1] = '\0'; + fprintf(stderr, "%p %s\n", p, p); +} +void (*accessor)(volatile char *p) = _accessor; + }C - sub vcl_recv { C{ raise(SIGSEGV); sleep(2); }C } + sub vcl_recv { C{ + int i; + volatile char overflow[48*1024]; + + /* for downwards stack, take care to hit a single guard page */ + for (i = 47*1024; i >= 0; i -= 1024) + accessor(overflow + i); + /* NOTREACHED */ + sleep(2); + }C } } -start client c1 { diff --git a/configure.ac b/configure.ac index 0f714d6..4c58ea1 100644 --- a/configure.ac +++ b/configure.ac @@ -199,6 +199,7 @@ AC_CHECK_FUNCS([nanosleep]) AC_CHECK_FUNCS([setppriv]) AC_CHECK_FUNCS([fallocate]) AC_CHECK_FUNCS([closefrom]) +AC_CHECK_FUNCS([sigaltstack]) save_LIBS="${LIBS}" LIBS="${PTHREAD_LIBS}" From phk at FreeBSD.org Mon Aug 28 21:24:07 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 28 Aug 2017 23:24:07 +0200 Subject: [master] 74328de This MegaCommit replaces the VSM implementation. Message-ID: commit 74328de8eeb2703591fe59190f73fcabf057adbe Author: Poul-Henning Kamp Date: Mon Aug 28 21:23:17 2017 +0000 This MegaCommit replaces the VSM implementation. Instead of having a single mmap(2)'ed file inside which we allocate the necessary chunks, put each chunk in its own file and use two index files (MGR/CHILD) to keep track of them. Major benefits: * You don't need to guess how much VSM space you need at startup. * VSM chunk Identifier (and therefore VSC counter names) are unlimited length. Minor benefits: * VSM API has simpler and explainable semantics now. * The bogo-you-didnt-guess-right-malloc-VSM allocations are gone. * -t argument moves up/down to VSM level and works the same through-out. * VSM/VUT utils now stay attached even if the MGT process restarts. Some relatively minor adjustments are still to come before the VSM API is frozen and the .map file finalized for the release. diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c index 43cab6f..aa3bf6d 100644 --- a/bin/varnishadm/varnishadm.c +++ b/bin/varnishadm/varnishadm.c @@ -389,44 +389,32 @@ usage(int status) } static int -n_arg_sock(const char *n_arg) +n_arg_sock(const char *n_arg, const char *t_arg) { char *T_arg = NULL, *T_start = NULL; char *S_arg = NULL; struct vsm *vsm; char *p; int sock; - struct vsm_fantom vt; vsm = VSM_New(); AN(vsm); - if (VSM_n_Arg(vsm, n_arg) < 0) { - fprintf(stderr, "%s\n", VSM_Error(vsm)); - VSM_Destroy(&vsm); - return (-1); - } - if (VSM_Start(vsm, 0, -1)) { + if (VSM_Arg(vsm, 'n', n_arg) < 0 || + VSM_Arg(vsm, 't', t_arg) < 0 || + VSM_Attach(vsm, STDERR_FILENO) < 0) { fprintf(stderr, "%s\n", VSM_Error(vsm)); VSM_Destroy(&vsm); return (-1); } - if (!VSM_Get(vsm, &vt, "Arg", "-T")) { - fprintf(stderr, "No -T arg in shared memory\n"); - VSM_Destroy(&vsm); + T_start = T_arg = VSM_Dup(vsm, "Arg", "-T"); + S_arg = VSM_Dup(vsm, "Arg", "-S"); + VSM_Destroy(&vsm); + + if (T_arg == NULL) { + fprintf(stderr, "No -T in shared memory\n"); return (-1); } - AZ(VSM_Map(vsm, &vt)); - AN(vt.b); - T_start = T_arg = strdup(vt.b); - - if (VSM_Get(vsm, &vt, "Arg", "-S")) { - AZ(VSM_Map(vsm, &vt)); - AN(vt.b); - S_arg = strdup(vt.b); - } - - VSM_Destroy(&vsm); sock = -1; while (*T_arg) { @@ -449,6 +437,7 @@ main(int argc, char * const *argv) const char *T_arg = NULL; const char *S_arg = NULL; const char *n_arg = NULL; + const char *t_arg = NULL; int opt, sock; /* @@ -474,9 +463,7 @@ main(int argc, char * const *argv) T_arg = optarg; break; case 't': - timeout = VNUM(optarg); - if (isnan(timeout)) - usage(1); + t_arg = optarg; break; default: usage(1); @@ -486,27 +473,23 @@ main(int argc, char * const *argv) argc -= optind; argv += optind; - if (n_arg != NULL) { - if (T_arg != NULL || S_arg != NULL) + if (T_arg != NULL) { + if (n_arg != NULL) usage(1); - sock = n_arg_sock(n_arg); - } else if (T_arg == NULL) { - sock = n_arg_sock(""); - } else { - assert(T_arg != NULL); sock = cli_sock(T_arg, S_arg); + } else { + if (S_arg != NULL) + usage(1); + sock = n_arg_sock(n_arg, t_arg); } if (sock < 0) exit(2); if (argc > 0) do_args(sock, argc, argv); - else { - if (isatty(0)) { - interactive(sock); - } else { - pass(sock); - } - } + else if (isatty(0)) + interactive(sock); + else + pass(sock); exit(0); } diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am index 8248966..c6228b8 100644 --- a/bin/varnishd/Makefile.am +++ b/bin/varnishd/Makefile.am @@ -53,7 +53,6 @@ varnishd_SOURCES = \ cache/cache_wrk.c \ cache/cache_ws.c \ common/common_vsc.c \ - common/common_vsm.c \ hash/hash_classic.c \ hash/hash_critbit.c \ hash/mgt_hash.c \ diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 87338d8..7645198 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -970,9 +970,6 @@ void SES_Set_String_Attr(struct sess *sp, enum sess_attr a, const char *src); const char *SES_Get_String_Attr(const struct sess *sp, enum sess_attr a); /* cache_shmlog.c */ -void *VSM_Alloc(unsigned size, const char *class, const char *type, - const char *ident); -void VSM_Free(void *ptr); #ifdef VSL_ENDMARKER void VSLv(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, va_list va); void VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...) diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index da5ffdc..15cd260 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -105,6 +105,7 @@ struct vbc { void VBE_fill_director(struct backend *be); /* cache_backend_cfg.c */ +void VBE_SetHappy(const struct backend *, uint64_t); unsigned VBE_Healthy(const struct backend *b, double *changed); #ifdef VCL_MET_MAX void VBE_Event(struct backend *, enum vcl_event_e); diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index 976b647..1ec9ef5 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -165,6 +165,16 @@ VRT_delete_backend(VRT_CTX, struct director **dp) // this is why we don't bust the director's magic number. } +void +VBE_SetHappy(const struct backend *be, uint64_t happy) +{ + + Lck_Lock(&backends_mtx); + if (be->vsc != NULL) + be->vsc->happy = happy; + Lck_Unlock(&backends_mtx); +} + /*--------------------------------------------------------------------- * These are for cross-calls with cache_vcl.c only. */ @@ -176,8 +186,10 @@ VBE_Event(struct backend *be, enum vcl_event_e ev) CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); if (ev == VCL_EVENT_WARM) { + Lck_Lock(&backends_mtx); be->vsc = VSC_vbe_New(be->display_name); AN(be->vsc); + Lck_Unlock(&backends_mtx); } if (be->probe != NULL && ev == VCL_EVENT_WARM) @@ -186,8 +198,11 @@ VBE_Event(struct backend *be, enum vcl_event_e ev) if (be->probe != NULL && ev == VCL_EVENT_COLD) VBP_Control(be, 0); - if (ev == VCL_EVENT_COLD) + if (ev == VCL_EVENT_COLD) { + Lck_Lock(&backends_mtx); VSC_vbe_Destroy(&be->vsc); + Lck_Unlock(&backends_mtx); + } } void diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c index af3336d..75a49a5 100644 --- a/bin/varnishd/cache/cache_backend_probe.c +++ b/bin/varnishd/cache/cache_backend_probe.c @@ -53,8 +53,6 @@ #include "cache_director.h" #include "cache_backend.h" -#include "VSC_vbe.h" - /* Default averaging rate, we want something pretty responsive */ #define AVG_RATE 4 @@ -167,6 +165,7 @@ vbp_update_backend(struct vbp_target *vt) bits[i++] = (vt->n & 1) ? c : '-'; #include "tbl/backend_poll.h" bits[i] = '\0'; + assert(i < sizeof bits); if (vt->good >= vt->threshold) { if (vt->backend->healthy) @@ -188,8 +187,7 @@ vbp_update_backend(struct vbp_target *vt) vt->backend->display_name, logmsg, bits, vt->good, vt->threshold, vt->window, vt->last, vt->avg, vt->resp_buf); - if (vt->backend != NULL && vt->backend->vsc != NULL) - vt->backend->vsc->happy = vt->happy; + VBE_SetHappy(vt->backend, vt->happy); } Lck_Unlock(&vbp_mtx); } diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c index 986f685..1c24dc2 100644 --- a/bin/varnishd/cache/cache_shmlog.c +++ b/bin/varnishd/cache/cache_shmlog.c @@ -42,11 +42,11 @@ #include "vgz.h" #include "vsl_priv.h" #include "vmb.h" -#include "vtim.h" +#include "vsmw.h" /* These cannot be struct lock, which depends on vsm/vsl working */ static pthread_mutex_t vsl_mtx; -static pthread_mutex_t vsm_mtx = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t vsm_mtx; static struct VSL_head *vsl_head; static const uint32_t *vsl_end; @@ -471,20 +471,16 @@ VSL_End(struct vsl_log *vsl) vsl->wid = 0; } -/*--------------------------------------------------------------------*/ +static void +vsm_vsc_lock(void) +{ + AZ(pthread_mutex_lock(&vsm_mtx)); +} -static void * -vsm_cleaner(void *priv) +static void +vsm_vsc_unlock(void) { - (void)priv; - THR_SetName("vsm_cleaner"); - while (1) { - AZ(pthread_mutex_lock(&vsm_mtx)); - CVSM_cleaner(heritage.vsm, (void*)VSC_C_main); - AZ(pthread_mutex_unlock(&vsm_mtx)); - VTIM_sleep(1.1); - } - NEEDLESS(return NULL); + AZ(pthread_mutex_unlock(&vsm_mtx)); } /*--------------------------------------------------------------------*/ @@ -493,14 +489,21 @@ void VSM_Init(void) { int i; - pthread_t tp; assert(UINT_MAX % VSL_SEGMENTS == VSL_SEGMENTS - 1); AZ(pthread_mutex_init(&vsl_mtx, NULL)); AZ(pthread_mutex_init(&vsm_mtx, NULL)); - vsl_head = VSM_Alloc(cache_param->vsl_space, VSL_CLASS, "", ""); + vsc_lock = vsm_vsc_lock; + vsc_unlock = vsm_vsc_unlock; + + VSC_C_main = VSC_main_New(""); + AN(VSC_C_main); + + AN(proc_vsmw); + vsl_head = VSMW_Allocf(proc_vsmw, VSL_CLASS, + cache_param->vsl_space, VSL_CLASS); AN(vsl_head); vsl_segsize = ((cache_param->vsl_space - sizeof *vsl_head) / sizeof *vsl_end) / VSL_SEGMENTS; @@ -520,32 +523,4 @@ VSM_Init(void) vsl_head->offset[i] = -1; VWMB(); memcpy(vsl_head->marker, VSL_HEAD_MARKER, sizeof vsl_head->marker); - - VSC_C_main = VSC_main_New(""); - AN(VSC_C_main); - - AZ(pthread_create(&tp, NULL, vsm_cleaner, NULL)); -} - -/*--------------------------------------------------------------------*/ - -void * -VSM_Alloc(unsigned size, const char *class, const char *type, - const char *ident) -{ - volatile void *p; - - AZ(pthread_mutex_lock(&vsm_mtx)); - p = CVSM_alloc(heritage.vsm, size, class, type, ident); - AZ(pthread_mutex_unlock(&vsm_mtx)); - return (TRUST_ME(p)); -} - -void -VSM_Free(void *ptr) -{ - - AZ(pthread_mutex_lock(&vsm_mtx)); - CVSM_free(heritage.vsm, ptr); - AZ(pthread_mutex_unlock(&vsm_mtx)); } diff --git a/bin/varnishd/common/common_vsc.c b/bin/varnishd/common/common_vsc.c index 00a1ab0..eb40edf 100644 --- a/bin/varnishd/common/common_vsc.c +++ b/bin/varnishd/common/common_vsc.c @@ -38,15 +38,12 @@ #include "common/common_vsm.h" #include "vend.h" +#include "vsmw.h" #include "vgz.h" #include "vmb.h" #include "vapi/vsc_int.h" -/*--------------------------------------------------------------------*/ - -void *VSM_Alloc(unsigned size, const char *class, const char *type, - const char *ident); -void VSM_Free(void *ptr); +struct vsmw *proc_vsmw; /*--------------------------------------------------------------------*/ @@ -54,6 +51,7 @@ struct vsc_segs { unsigned magic; #define VSC_SEGS_MAGIC 0x9b355991 + const char *nm; VTAILQ_ENTRY(vsc_segs) list; void *seg; void *ptr; @@ -62,25 +60,30 @@ struct vsc_segs { static VTAILQ_HEAD(,vsc_segs) vsc_seglist = VTAILQ_HEAD_INITIALIZER(vsc_seglist); +vsc_callback_f *vsc_lock; +vsc_callback_f *vsc_unlock; + void * -VSC_Alloc(const char *nm, size_t sd, - size_t sj, const unsigned char *zj, size_t szj, - const char *fmt, va_list va) +VSC_Alloc(const char *nm, size_t sd, size_t sj, const unsigned char *zj, + size_t szj, const char *fmt, va_list va) { char *p; z_stream vz; struct vsc_segs *vsg; + char buf[1024]; - (void)nm; - (void)fmt; - (void)va; + if (vsc_lock != NULL) + vsc_lock(); + if (*fmt == '\0') + bprintf(buf, "%s", nm); + else + bprintf(buf, "%s.%s", nm, fmt); - p = VSM_Alloc(8 + sd + sj, VSC_CLASS, nm, fmt); + AN(proc_vsmw); + p = VSMW_Allocv(proc_vsmw, VSC_CLASS, 8 + sd + sj, buf, va); AN(p); - memset(p, 0, sd); - memset(&vz, 0, sizeof vz); assert(Z_OK == inflateInit2(&vz, 31)); vz.next_in = TRUST_ME(zj); @@ -96,6 +99,9 @@ VSC_Alloc(const char *nm, size_t sd, VTAILQ_INSERT_TAIL(&vsc_seglist, vsg, list); VWMB(); vbe64enc(p, sd); + vsg->nm = nm; + if (vsc_unlock != NULL) + vsc_unlock(); return (p + 8); } @@ -104,14 +110,19 @@ VSC_Destroy(const char *nm, const void *p) { struct vsc_segs *vsg; - (void)nm; + if (vsc_lock != NULL) + vsc_lock(); + + AN(proc_vsmw); VTAILQ_FOREACH(vsg, &vsc_seglist, list) { if (vsg->ptr != p) continue; - VSM_Free(vsg->seg); + assert(vsg->nm == nm); + VSMW_Free(proc_vsmw, &vsg->seg); VTAILQ_REMOVE(&vsc_seglist, vsg, list); FREE_OBJ(vsg); - return; + break; } - WRONG("Freeing unknown VSC"); + if (vsc_unlock != NULL) + vsc_unlock(); } diff --git a/bin/varnishd/common/common_vsm.c b/bin/varnishd/common/common_vsm.c deleted file mode 100644 index f900b26..0000000 --- a/bin/varnishd/common/common_vsm.c +++ /dev/null @@ -1,395 +0,0 @@ -/*- - * Copyright (c) 2010-2011 Varnish Software 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. - * - * VSM stuff common to manager and child. - * - * Please see comments in for details of protocols and - * data consistency. - * - */ - -#include "config.h" - -#include -#include -#include - -#include "common.h" -#include "common/com_params.h" -#include "common/common_vsm.h" - -#include "vsm_priv.h" -#include "vmb.h" -#include "vtim.h" - -#include "VSC_main.h" - -extern volatile struct params * cache_param; - -/*--------------------------------------------------------------------*/ - -struct vsm_range { - unsigned magic; -#define VSM_RANGE_MAGIC 0x8d30f14 - VTAILQ_ENTRY(vsm_range) list; - ssize_t off; - ssize_t len; - double cool; - struct VSM_chunk *chunk; - void *ptr; -}; - -struct vsm_sc { - unsigned magic; -#define VSM_SC_MAGIC 0x8b83270d - char *b; - ssize_t len; - struct VSM_head *head; - double t0; - VTAILQ_HEAD(,vsm_range) r_used; - VTAILQ_HEAD(,vsm_range) r_cooling; - VTAILQ_HEAD(,vsm_range) r_free; - VTAILQ_HEAD(,vsm_range) r_bogus; - uint64_t g_free; - uint64_t g_used; - uint64_t g_cooling; - uint64_t g_overflow; - uint64_t c_overflow; -}; - -/*-------------------------------------------------------------------- - * The free list is sorted by size, which means that collapsing ranges - * on free becomes a multi-pass operation. - */ - -static void -vsm_common_insert_free(struct vsm_sc *sc, struct vsm_range *vr) -{ - struct vsm_range *vr2; - - CHECK_OBJ_NOTNULL(sc, VSM_SC_MAGIC); - CHECK_OBJ_NOTNULL(vr, VSM_RANGE_MAGIC); - - /* First try to see if we can collapse anything */ - VTAILQ_FOREACH(vr2, &sc->r_free, list) { - if (vr2->off == vr->off + vr->len) { - vr2->off = vr->off; - vr2->len += vr->len; - FREE_OBJ(vr); - VTAILQ_REMOVE(&sc->r_free, vr2, list); - vsm_common_insert_free(sc, vr2); - return; - } - if (vr->off == vr2->off + vr2->len) { - vr2->len += vr->len; - FREE_OBJ(vr); - VTAILQ_REMOVE(&sc->r_free, vr2, list); - vsm_common_insert_free(sc, vr2); - return; - } - } - /* Insert in size order */ - VTAILQ_FOREACH(vr2, &sc->r_free, list) { - if (vr2->len > vr->len) { - VTAILQ_INSERT_BEFORE(vr2, vr, list); - return; - } - } - /* At tail, if everything in the list is smaller */ - VTAILQ_INSERT_TAIL(&sc->r_free, vr, list); -} - -/*-------------------------------------------------------------------- - * Initialize a new VSM segment - */ - -struct vsm_sc * -CVSM_new(void *p, ssize_t l) -{ - struct vsm_sc *sc; - struct vsm_range *vr; - - assert(PAOK(sizeof(struct VSM_chunk))); - assert(PAOK(p)); - ALLOC_OBJ(sc, VSM_SC_MAGIC); - AN(sc); - VTAILQ_INIT(&sc->r_used); - VTAILQ_INIT(&sc->r_cooling); - VTAILQ_INIT(&sc->r_free); - VTAILQ_INIT(&sc->r_bogus); - sc->b = p; - sc->len = l; - sc->t0 = VTIM_mono(); - - sc->head = (void *)sc->b; - /* This should not be necessary, but just in case...*/ - memset(sc->head, 0, sizeof *sc->head); - memcpy(sc->head->marker, VSM_HEAD_MARKER, sizeof sc->head->marker); - sc->head->hdrsize = sizeof *sc->head; - sc->head->shm_size = l; - sc->head->alloc_seq = random() | 1; - VWMB(); - - ALLOC_OBJ(vr, VSM_RANGE_MAGIC); - AN(vr); - vr->off = RUP2(sizeof(*sc->head), 16); - vr->len = RDN2(l - vr->off, 16); - VTAILQ_INSERT_TAIL(&sc->r_free, vr, list); - sc->g_free = vr->len; - return (sc); -} - -/*-------------------------------------------------------------------- - * Move from cooling list to free list - */ - -void -CVSM_cleaner(struct vsm_sc *sc, struct VSC_main *stats) -{ - double now = VTIM_real(); - struct vsm_range *vr, *vr2; - - CHECK_OBJ_NOTNULL(sc, VSM_SC_MAGIC); - - /* Move cooled off stuff to free list */ - VTAILQ_FOREACH_SAFE(vr, &sc->r_cooling, list, vr2) { - if (vr->cool > now) - break; - VTAILQ_REMOVE(&sc->r_cooling, vr, list); - sc->g_cooling -= vr->len; - sc->g_free += vr->len; - vsm_common_insert_free(sc, vr); - } - stats->vsm_free = sc->g_free; - stats->vsm_used = sc->g_used; - stats->vsm_cooling = sc->g_cooling; - stats->vsm_overflow = sc->g_overflow; - stats->vsm_overflowed = sc->c_overflow; -} - -/*-------------------------------------------------------------------- - * Allocate a chunk from VSM - */ - -void * -CVSM_alloc(struct vsm_sc *sc, ssize_t size, - const char *class, const char *type, const char *ident) -{ - struct vsm_range *vr, *vr2, *vr3; - unsigned l1, l2; - - CHECK_OBJ_NOTNULL(sc, VSM_SC_MAGIC); - AN(size); - - /* XXX: silent truncation instead of assert ? */ - AN(class); - assert(strlen(class) < sizeof(vr->chunk->class)); - AN(type); - assert(strlen(type) < sizeof(vr->chunk->type)); - AN(ident); - assert(strlen(ident) < sizeof(vr->chunk->ident)); - - l1 = RUP2(size + sizeof(struct VSM_chunk), 16); - l2 = RUP2(size + 2 * sizeof(struct VSM_chunk), 16); - - /* Find space in free-list */ - VTAILQ_FOREACH_SAFE(vr, &sc->r_free, list, vr2) { - if (vr->len < l1) - continue; - if (vr->len <= l2) { - VTAILQ_REMOVE(&sc->r_free, vr, list); - } else { - ALLOC_OBJ(vr3, VSM_RANGE_MAGIC); - AN(vr3); - vr3->off = vr->off; - vr3->len = l1; - vr->off += l1; - vr->len -= l1; - VTAILQ_REMOVE(&sc->r_free, vr, list); - vsm_common_insert_free(sc, vr); - vr = vr3; - } - break; - } - - if (vr == NULL) { - /* - * No space in VSM, return malloc'd space - * This space will not be visible via the VSM - */ - ALLOC_OBJ(vr, VSM_RANGE_MAGIC); - AN(vr); - vr->ptr = calloc(size, 1); - AN(vr->ptr); - vr->len = size; - VTAILQ_INSERT_TAIL(&sc->r_bogus, vr, list); - sc->g_overflow += vr->len; - sc->c_overflow += vr->len; - return (vr->ptr); - } - - sc->g_free -= vr->len; - sc->g_used += vr->len; - - /* Zero the entire allocation, to avoid garbage confusing readers */ - memset(sc->b + vr->off, 0, vr->len); - - vr->chunk = (void *)(sc->b + vr->off); - vr->ptr = (vr->chunk + 1); - - memcpy(vr->chunk->marker, VSM_CHUNK_MARKER, sizeof vr->chunk->marker); - vr->chunk->len = vr->len; - strcpy(vr->chunk->class, class); - strcpy(vr->chunk->type, type); - strcpy(vr->chunk->ident, ident); - VWMB(); - - vr3 = VTAILQ_FIRST(&sc->r_used); - VTAILQ_INSERT_HEAD(&sc->r_used, vr, list); - - if (vr3 != NULL) { - AZ(vr3->chunk->next); - vr3->chunk->next = vr->off; - } else { - sc->head->first = vr->off; - } - sc->head->alloc_seq += 2; - VWMB(); - return (vr->ptr); -} - -/*-------------------------------------------------------------------- - * Free a chunk - */ - -void -CVSM_free(struct vsm_sc *sc, void *ptr) -{ - struct vsm_range *vr, *vr2; - - CHECK_OBJ_NOTNULL(sc, VSM_SC_MAGIC); - AN(ptr); - - /* Look in used list, move to cooling list */ - VTAILQ_FOREACH(vr, &sc->r_used, list) { - if (vr->ptr != ptr) - continue; - - sc->g_used -= vr->len; - sc->g_cooling += vr->len; - - vr2 = VTAILQ_NEXT(vr, list); - VTAILQ_REMOVE(&sc->r_used, vr, list); - VTAILQ_INSERT_TAIL(&sc->r_cooling, vr, list); - vr->cool = VTIM_real() + cache_param->vsm_free_cooldown; - if (vr2 != NULL) - vr2->chunk->next = vr->chunk->next; - else - sc->head->first = vr->chunk->next; - VWMB(); - vr->chunk->len = 0; - sc->head->alloc_seq += 2; - VWMB(); - return; - } - - /* Look in bogus list, free */ - VTAILQ_FOREACH(vr, &sc->r_bogus, list) { - if (vr->ptr != ptr) - continue; - - sc->g_overflow -= vr->len; - - VTAILQ_REMOVE(&sc->r_bogus, vr, list); - FREE_OBJ(vr); - free(ptr); - return; - } - /* Panic */ - assert(ptr == NULL); -} - -/*-------------------------------------------------------------------- - * Delete a VSM segment - */ - -void -CVSM_delete(struct vsm_sc **scp) -{ - struct vsm_range *vr, *vr2; - struct vsm_sc *sc; - - TAKE_OBJ_NOTNULL(sc, scp, VSM_SC_MAGIC); - VTAILQ_FOREACH_SAFE(vr, &sc->r_free, list, vr2) - FREE_OBJ(vr); - VTAILQ_FOREACH_SAFE(vr, &sc->r_used, list, vr2) - FREE_OBJ(vr); - VTAILQ_FOREACH_SAFE(vr, &sc->r_cooling, list, vr2) - FREE_OBJ(vr); - VTAILQ_FOREACH_SAFE(vr, &sc->r_bogus, list, vr2) { - free(vr->ptr); - FREE_OBJ(vr); - } - - /* Mark VSM as abandoned */ - sc->head->alloc_seq = 0; - - VWMB(); - FREE_OBJ(sc); -} - -/*-------------------------------------------------------------------- - * Copy all chunks in one VSM segment to another VSM segment - */ - -void -CVSM_copy(struct vsm_sc *to, const struct vsm_sc *from) -{ - struct vsm_range *vr; - void *p; - - CHECK_OBJ_NOTNULL(to, VSM_SC_MAGIC); - CHECK_OBJ_NOTNULL(from, VSM_SC_MAGIC); - VTAILQ_FOREACH(vr, &from->r_used, list) { - p = CVSM_alloc(to, vr->chunk->len, - vr->chunk->class, vr->chunk->type, vr->chunk->ident); - AN(p); - memcpy(p, vr->chunk + 1, vr->chunk->len); - } -} - -/*-------------------------------------------------------------------- - * Update age - */ - -void -CVSM_ageupdate(const struct vsm_sc *sc) -{ - - CHECK_OBJ_NOTNULL(sc, VSM_SC_MAGIC); - sc->head->age = (uint64_t)(VTIM_mono() - sc->t0); -} diff --git a/bin/varnishd/common/common_vsm.h b/bin/varnishd/common/common_vsm.h index 45e6dd8..f675d07 100644 --- a/bin/varnishd/common/common_vsm.h +++ b/bin/varnishd/common/common_vsm.h @@ -33,17 +33,14 @@ #endif #define COMMON_COMMON_VSM_H -/* common_vsm.c */ -struct vsm_sc; -struct VSC_main; -struct vsm_sc *CVSM_new(void *ptr, ssize_t len); -void *CVSM_alloc(struct vsm_sc *sc, ssize_t size, - const char *class, const char *type, const char *ident); -void CVSM_free(struct vsm_sc *sc, void *ptr); -void CVSM_delete(struct vsm_sc **sc); -void CVSM_copy(struct vsm_sc *to, const struct vsm_sc *from); -void CVSM_cleaner(struct vsm_sc *sc, struct VSC_main *stats); -void CVSM_ageupdate(const struct vsm_sc *sc); +struct vsmw; + +extern struct vsmw *proc_vsmw; + +typedef void vsc_callback_f(void); + +extern vsc_callback_f *vsc_lock; +extern vsc_callback_f *vsc_unlock; void *VSC_Alloc(const char *, size_t, size_t, const unsigned char *, size_t, const char *, va_list); diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h index 528bc1e..95f6c3e 100644 --- a/bin/varnishd/common/heritage.h +++ b/bin/varnishd/common/heritage.h @@ -29,7 +29,7 @@ * This file contains the heritage passed when mgt forks cache */ -struct vsm_sc; +struct vsmw; struct suckaddr; struct listen_sock; struct transport; @@ -67,14 +67,14 @@ struct heritage { /* File descriptor for stdout/stderr */ int std_fd; + int vsm_fd; + /* Sockets from which to accept connections */ struct listen_sock_head socks; /* Hash method */ const struct hash_slinger *hash; - struct vsm_sc *vsm; - struct params *param; const char *identity; diff --git a/bin/varnishd/main.vsc b/bin/varnishd/main.vsc index dd53b9e..726ee9e 100644 --- a/bin/varnishd/main.vsc +++ b/bin/varnishd/main.vsc @@ -725,53 +725,4 @@ from a backend. They are done to verify the gzip stream while it's inserted in storage. -.. varnish_vsc:: vsm_free - :type: gauge - :format: bytes - :level: diag - :oneliner: Free VSM space - - Number of bytes free in the shared memory used to communicate with - tools like varnishstat, varnishlog etc. - -.. varnish_vsc:: vsm_used - :type: gauge - :format: bytes - :level: diag - :oneliner: Used VSM space - - Number of bytes used in the shared memory used to communicate with - tools like varnishstat, varnishlog etc. - -.. varnish_vsc:: vsm_cooling - :type: gauge - :format: bytes - :level: debug - :oneliner: Cooling VSM space - - Number of bytes which will soon (max 1 minute) be freed in the - shared memory used to communicate with tools like varnishstat, - varnishlog etc. - -.. varnish_vsc:: vsm_overflow - :type: gauge - :format: bytes - :level: diag - :oneliner: Overflow VSM space - - Number of bytes which does not fit in the shared memory used to - communicate with tools like varnishstat, varnishlog etc. If this - counter is not zero, consider increasing the runtime variable - vsm_space. - -.. varnish_vsc:: vsm_overflowed - :level: diag - :format: bytes - :oneliner: Overflowed VSM space - - Total number of bytes which did not fit in the shared memory used - to communicate with tools like varnishstat, varnishlog etc. If this - counter is not zero, consider increasing the runtime variable - vsm_space. - .. varnish_vsc_end:: main diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 0a4efbd..6549d78 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -133,7 +133,6 @@ extern const struct jail_tech jail_tech_solaris; /* mgt_main.c */ extern struct VSC_mgt *VSC_C_mgt; -extern struct VSC_mgt static_VSC_C_mgt; struct choice { const char *name; const void *ptr; @@ -165,10 +164,14 @@ extern struct params mgt_param; /* mgt_shmem.c */ void mgt_SHM_Init(void); void mgt_SHM_static_alloc(const void *, ssize_t size, - const char *class, const char *type, const char *ident); + const char *class, const char *ident); void mgt_SHM_Create(void); void mgt_SHM_Destroy(int keep); -void mgt_SHM_Size_Adjust(void); + +extern struct vsmw *mgt_vsmw; +extern struct vsmw *child_vsmw; +void mgt_SHM_ChildNew(void); +void mgt_SHM_ChildDestroy(void); /* mgt_param_tcp.c */ void MCF_TcpParams(void); diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index 47bd905..91d6c5e 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -44,6 +44,7 @@ #include "mgt/mgt.h" #include "common/heritage.h" +#include "common/common_vsm.h" #include "vbm.h" #include "vcli_serve.h" @@ -51,6 +52,7 @@ #include "vfil.h" #include "vlu.h" #include "vtim.h" +#include "vsmw.h" static pid_t child_pid = -1; @@ -139,7 +141,7 @@ mch_cli_panic_clear(struct cli *cli, const char * const *av, void *priv) VCLI_Out(cli, "Unknown parameter \"%s\".", av[2]); return; } else if (av[2] != NULL) { - VSC_C_mgt->child_panic = static_VSC_C_mgt.child_panic = 0; + VSC_C_mgt->child_panic = 0; if (child_panic == NULL) return; } @@ -312,17 +314,19 @@ mgt_launch_child(struct cli *cli) heritage.std_fd = cp[1]; child_output = cp[0]; - AN(heritage.vsm); - mgt_SHM_Size_Adjust(); - AN(heritage.vsm); + mgt_SHM_ChildNew(); + AN(heritage.param); + AN(heritage.panic_str); if ((pid = fork()) < 0) { - /* XXX */ perror("Could not fork child"); - exit(1); + exit(1); // XXX Harsh ? } if (pid == 0) { + proc_vsmw = VSMW_New(heritage.vsm_fd, 0640, "_.index"); + AN(proc_vsmw); + /* Redirect stdin/out/err */ VFIL_null_fd(STDIN_FILENO); assert(dup2(heritage.std_fd, STDOUT_FILENO) == STDOUT_FILENO); @@ -381,7 +385,7 @@ mgt_launch_child(struct cli *cli) } assert(pid > 1); MGT_Complain(C_DEBUG, "Child (%jd) Started", (intmax_t)pid); - VSC_C_mgt->child_start = ++static_VSC_C_mgt.child_start; + VSC_C_mgt->child_start++; /* Close stuff the child got */ closefd(&heritage.std_fd); @@ -512,20 +516,20 @@ mgt_reap_child(void) VSB_printf(vsb, " status=%d", WEXITSTATUS(status)); exit_status |= 0x20; if (WEXITSTATUS(status) == 1) - VSC_C_mgt->child_exit = ++static_VSC_C_mgt.child_exit; + VSC_C_mgt->child_exit++; else - VSC_C_mgt->child_stop = ++static_VSC_C_mgt.child_stop; + VSC_C_mgt->child_stop++; } if (WIFSIGNALED(status)) { VSB_printf(vsb, " signal=%d", WTERMSIG(status)); exit_status |= 0x40; - VSC_C_mgt->child_died = ++static_VSC_C_mgt.child_died; + VSC_C_mgt->child_died++; } #ifdef WCOREDUMP if (WCOREDUMP(status)) { VSB_printf(vsb, " (core dumped)"); exit_status |= 0x80; - VSC_C_mgt->child_dump = ++static_VSC_C_mgt.child_dump; + VSC_C_mgt->child_dump++; } #endif AZ(VSB_finish(vsb)); @@ -535,12 +539,10 @@ mgt_reap_child(void) /* Dispose of shared memory but evacuate panic messages first */ if (heritage.panic_str[0] != '\0') { mgt_panic_record(r); - mgt_SHM_Destroy(1); - VSC_C_mgt->child_panic = ++static_VSC_C_mgt.child_panic; - } else { - mgt_SHM_Destroy(MGT_DO_DEBUG(DBG_VSM_KEEP)); + VSC_C_mgt->child_panic++; } - mgt_SHM_Create(); + + mgt_SHM_ChildDestroy(); if (child_state == CH_RUNNING) child_state = CH_DIED; diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index 3694263..2d6481c 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -503,7 +503,7 @@ mgt_cli_secret(const char *S_arg) char buf[BUFSIZ]; /* Save in shmem */ - mgt_SHM_static_alloc(S_arg, strlen(S_arg) + 1L, "Arg", "", "-S"); + mgt_SHM_static_alloc(S_arg, strlen(S_arg) + 1L, "Arg", "-S"); VJ_master(JAIL_MASTER_FILE); fd = open(S_arg, O_RDONLY); @@ -573,7 +573,7 @@ mgt_cli_telnet(const char *T_arg) if (VSB_len(vsb) == 0) ARGV_ERR("-T %s could not be listened on.\n", T_arg); /* Save in shmem */ - mgt_SHM_static_alloc(VSB_data(vsb), VSB_len(vsb) + 1, "Arg", "", "-T"); + mgt_SHM_static_alloc(VSB_data(vsb), VSB_len(vsb) + 1, "Arg", "-T"); VSB_destroy(&vsb); } diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 0f50910..abd4445 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -43,7 +43,6 @@ #include "mgt/mgt.h" #include "common/heritage.h" -#include "common/common_vsm.h" #include "hash/hash_slinger.h" #include "vav.h" @@ -65,7 +64,6 @@ pid_t mgt_pid; struct vev_base *mgt_evb; int exit_status = 0; struct vsb *vident; -struct VSC_mgt static_VSC_C_mgt; struct VSC_mgt *VSC_C_mgt; static int I_fd = -1; static char Cn_arg[] = "/tmp/varnishd_C_XXXXXXX"; @@ -418,10 +416,7 @@ mgt_uptime(const struct vev *e, int what) AN(VSC_C_mgt); if (mgt_uptime_t0 == 0) mgt_uptime_t0 = VTIM_real(); - VSC_C_mgt->uptime = static_VSC_C_mgt.uptime = - (uint64_t)(VTIM_real() - mgt_uptime_t0); - if (heritage.vsm != NULL) - CVSM_ageupdate(heritage.vsm); + VSC_C_mgt->uptime = (uint64_t)(VTIM_real() - mgt_uptime_t0); return (0); } @@ -458,7 +453,6 @@ mgt_f_read(const char *fn) if (VFIL_searchpath(vcl_path, NULL, &f, fn, &fnp) || f == NULL) { ARGV_ERR("Cannot read -f file '%s' (%s)\n", fnp != NULL ? fnp : fn, strerror(errno)); - free(fnp); } free(fa->farg); fa->farg = fnp; @@ -597,10 +591,6 @@ main(int argc, char * const *argv) mgt_pid = getpid(); } - /* Set up the mgt counters */ - memset(&static_VSC_C_mgt, 0, sizeof static_VSC_C_mgt); - VSC_C_mgt = &static_VSC_C_mgt; - VRND_SeedAll(); vident = mgt_BuildVident(); @@ -848,7 +838,8 @@ main(int argc, char * const *argv) mgt_SHM_Init(); - mgt_SHM_static_alloc(i_arg, strlen(i_arg) + 1L, "Arg", "-i", "-i"); + mgt_SHM_static_alloc(i_arg, strlen(i_arg) + 1L, "Arg", "-i"); + VSC_C_mgt = VSC_mgt_New(""); if (M_arg != NULL) mgt_cli_master(M_arg); @@ -872,8 +863,6 @@ main(int argc, char * const *argv) if (strcmp(S_arg, "none")) mgt_cli_secret(S_arg); - mgt_SHM_Create(); - memset(&sac, 0, sizeof sac); sac.sa_handler = SIG_IGN; sac.sa_flags = SA_RESTART; diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c index 7c05ff7..f0832b1 100644 --- a/bin/varnishd/mgt/mgt_shmem.c +++ b/bin/varnishd/mgt/mgt_shmem.c @@ -30,7 +30,7 @@ #include "config.h" -#include +#include #include #include @@ -42,239 +42,93 @@ #include "common/heritage.h" #include "common/common_vsm.h" -#include "vfl.h" #include "vsm_priv.h" -#include "vfil.h" +#include "vsmw.h" -#ifndef MAP_HASSEMAPHORE -#define MAP_HASSEMAPHORE 0 /* XXX Linux */ -#endif - -#ifndef MAP_NOSYNC -#define MAP_NOSYNC 0 /* XXX Linux */ -#endif - -#define PAN_CLASS "Panic" - -static void *mgt_vsm_p; -static ssize_t mgt_vsm_l; +struct vsmw *mgt_vsmw; +struct vsmw *child_vsmw; /*-------------------------------------------------------------------- - * Use a bogo-VSM to hold master-copies of the VSM chunks the master - * publishes, such as -S & -T arguments. */ -static struct vsm_sc *static_vsm; -static char static_vsm_buf[1024]; - void mgt_SHM_static_alloc(const void *ptr, ssize_t size, - const char *class, const char *type, const char *ident) + const char *class, const char *ident) { void *p; - p = CVSM_alloc(static_vsm, size, class, type, ident); + p = VSMW_Allocf(mgt_vsmw, class, size, "%s", ident); AN(p); memcpy(p, ptr, size); - if (heritage.vsm != NULL) { - p = CVSM_alloc(heritage.vsm, size, class, type, ident); - AN(p); - memcpy(p, ptr, size); - } } /*-------------------------------------------------------------------- - * Build a zeroed file + * Exit handler that clears the owning pid from the SHMLOG */ -static int -vsm_zerofile(const char *fn, ssize_t size) +static void +mgt_shm_atexit(void) { - int fd; - int flags; - fd = VFL_Open(fn, O_RDWR | O_CREAT | O_EXCL | O_NONBLOCK, 0640); - if (fd < 0) { - MGT_Complain(C_ERR, "Could not create %s: %s", - fn, strerror(errno)); - return (-1); - } - VJ_fix_vsm_file(fd); - flags = fcntl(fd, F_GETFL); - assert(flags != -1); - flags &= ~O_NONBLOCK; - AZ(fcntl(fd, F_SETFL, flags)); - if (VFIL_allocate(fd, (off_t)size, 1)) { - MGT_Complain(C_ERR, "File allocation error %s: %s", - fn, strerror(errno)); - return (-1); + /* Do not let VCC kill our VSM */ + if (getpid() != mgt_pid) + return; + VSMW_Destroy(&mgt_vsmw); + if (!MGT_DO_DEBUG(DBG_VTC_MODE)) { + AZ(system("rm -rf " VSM_MGT_DIRNAME)); + AZ(system("rm -rf " VSM_CHILD_DIRNAME)); } - return (fd); } /*-------------------------------------------------------------------- - * Create a VSM instance + * Initialize VSM subsystem */ -static size_t -mgt_shm_size(void) +void +mgt_SHM_Init(void) { - size_t size, ps; - size = mgt_param.vsl_space + mgt_param.vsm_space; - ps = getpagesize(); - size = RUP2(size, ps); - return (size); -} + // XXX: VJ/mode/owner/group + AZ(system("rm -rf " VSM_MGT_DIRNAME)); + AZ(mkdir(VSM_MGT_DIRNAME, 0755)); + mgt_vsmw = VSMW_New(open(VSM_MGT_DIRNAME, O_RDONLY), 0640, "_.index"); + AN(mgt_vsmw); -static void -mgt_shm_cleanup(void) -{ - char fnbuf[64]; + proc_vsmw = mgt_vsmw; - bprintf(fnbuf, "%s.%jd", VSM_FILENAME, (intmax_t)getpid()); - VJ_master(JAIL_MASTER_FILE); - (void)unlink(fnbuf); - VJ_master(JAIL_MASTER_LOW); + /* Setup atexit handler */ + AZ(atexit(mgt_shm_atexit)); } void -mgt_SHM_Create(void) +mgt_SHM_ChildNew(void) { - size_t size; - void *p; - char fnbuf[64]; - int vsm_fd; - - AZ(heritage.vsm); - size = mgt_shm_size(); - - bprintf(fnbuf, "%s.%jd", VSM_FILENAME, (intmax_t)getpid()); - - VJ_master(JAIL_MASTER_FILE); - vsm_fd = vsm_zerofile(fnbuf, size); - VJ_master(JAIL_MASTER_LOW); - if (vsm_fd < 0) { - mgt_shm_cleanup(); - exit(1); - } - - p = (void *)mmap(NULL, size, - PROT_READ|PROT_WRITE, - MAP_HASSEMAPHORE | MAP_NOSYNC | MAP_SHARED, - vsm_fd, 0); - - closefd(&vsm_fd); - if (p == MAP_FAILED) { - MGT_Complain(C_ERR, "Mmap error %s: %s", - fnbuf, strerror(errno)); - mgt_shm_cleanup(); - exit(1); - } - - mgt_vsm_p = p; - mgt_vsm_l = size; - - /* This may or may not work */ - (void)mlock(p, size); + AZ(system("rm -rf " VSM_CHILD_DIRNAME)); + AZ(mkdir(VSM_CHILD_DIRNAME, 0755)); - heritage.vsm = CVSM_new(p, size); + heritage.vsm_fd = open(VSM_CHILD_DIRNAME, O_RDONLY); + assert(heritage.vsm_fd >= 0); + MCH_Fd_Inherit(heritage.vsm_fd, "VSMW"); - CVSM_copy(heritage.vsm, static_vsm); - - heritage.param = CVSM_alloc(heritage.vsm, - sizeof *heritage.param, VSM_CLASS_PARAM, "", ""); + heritage.param = VSMW_Allocf(mgt_vsmw, VSM_CLASS_PARAM, + sizeof *heritage.param, ""); AN(heritage.param); *heritage.param = mgt_param; heritage.panic_str_len = 64 * 1024; - heritage.panic_str = CVSM_alloc(heritage.vsm, - heritage.panic_str_len, PAN_CLASS, "", ""); + heritage.panic_str = VSMW_Allocf(mgt_vsmw, "Panic", + heritage.panic_str_len, ""); AN(heritage.panic_str); - - /* Copy management counters to shm and update pointer */ - VSC_C_mgt = VSC_mgt_New(""); - AN(VSC_C_mgt); - *VSC_C_mgt = static_VSC_C_mgt; - -#ifdef __OpenBSD__ - /* Commit changes, for OS's without coherent VM/buf */ - AZ(msync(p, getpagesize(), MS_SYNC)); -#endif - VJ_master(JAIL_MASTER_FILE); - if (rename(fnbuf, VSM_FILENAME)) { - MGT_Complain(C_ERR, "Rename failed %s -> %s: %s", - fnbuf, VSM_FILENAME, strerror(errno)); - (void)unlink(fnbuf); - exit(1); - } - VJ_master(JAIL_MASTER_LOW); } -/*-------------------------------------------------------------------- - * Destroy a VSM instance - */ - void -mgt_SHM_Destroy(int keep) +mgt_SHM_ChildDestroy(void) { - /* Point mgt counters back at static version */ - VSC_C_mgt = &static_VSC_C_mgt; - - AN(heritage.vsm); - if (keep) - (void)rename(VSM_FILENAME, VSM_FILENAME ".keep"); + closefd(&heritage.vsm_fd); + if (!MGT_DO_DEBUG(DBG_VTC_MODE)) + AZ(system("rm -rf " VSM_CHILD_DIRNAME)); heritage.panic_str = NULL; - heritage.panic_str_len = 0; heritage.param = NULL; - CVSM_delete(&heritage.vsm); - AZ(munmap(mgt_vsm_p, mgt_vsm_l)); - mgt_vsm_p = NULL; - mgt_vsm_l = 0; -} - -/*-------------------------------------------------------------------- - * Destroy and recreate VSM if its size should change - */ - -void -mgt_SHM_Size_Adjust(void) -{ - - AN(heritage.vsm); - if (mgt_vsm_l == mgt_shm_size()) - return; - mgt_SHM_Destroy(0); - mgt_SHM_Create(); -} - -/*-------------------------------------------------------------------- - * Exit handler that clears the owning pid from the SHMLOG - */ - -static void -mgt_shm_atexit(void) -{ - - /* Do not let VCC kill our VSM */ - if (getpid() != mgt_pid) - return; - if (heritage.vsm != NULL) - CVSM_delete(&heritage.vsm); -} - -/*-------------------------------------------------------------------- - * Initialize VSM subsystem - */ - -void -mgt_SHM_Init(void) -{ - /* Create our static VSM instance */ - static_vsm = CVSM_new(static_vsm_buf, sizeof static_vsm_buf); - - /* Setup atexit handler */ - AZ(atexit(mgt_shm_atexit)); } diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c index bc38a2c..b33b55e 100644 --- a/bin/varnishhist/varnishhist.c +++ b/bin/varnishhist/varnishhist.c @@ -76,6 +76,7 @@ static double timebend = 0, t0; static double vsl_t0 = 0, vsl_to, vsl_ts = 0; static pthread_cond_t timebend_cv; static double log_ten; +static char *ident; static const int scales[] = { 1, @@ -153,7 +154,7 @@ update(void) if (end_of_file) mvprintw(0, 0, "%*s", COLS - 1, "EOF"); else - mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(VUT.vsm)); + mvprintw(0, 0, "%*s", COLS - 1, ident); /* count our flock */ for (i = 0; i < n; ++i) @@ -605,6 +606,7 @@ main(int argc, char **argv) log_ten = log(10.0); VUT_Setup(); + ident = VSM_Dup(VUT.vsm, "Arg", "-i"); if (pthread_create(&thr, NULL, do_curses, NULL) != 0) VUT_Error(1, "pthread_create(): %s", strerror(errno)); VUT.dispatch_f = accumulate; diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c index 1cb5f94..c9270cf 100644 --- a/bin/varnishstat/varnishstat.c +++ b/bin/varnishstat/varnishstat.c @@ -253,7 +253,6 @@ int main(int argc, char * const *argv) { struct vsm *vd; - double t_arg = 5.0; int once = 0, xml = 0, json = 0, f_list = 0, curses = 0; signed char opt; int i; @@ -273,17 +272,6 @@ main(int argc, char * const *argv) case 'l': f_list = 1; break; - case 't': - if (!strcasecmp(optarg, "off")) - t_arg = -1.; - else { - t_arg = VNUM(optarg); - if (isnan(t_arg)) - VUT_Error(1, "-t: Syntax error"); - if (t_arg < 0.) - VUT_Error(1, "-t: Range error"); - } - break; case 'V': VCS_Message("varnishstat"); exit(0); @@ -308,7 +296,7 @@ main(int argc, char * const *argv) if (!(xml || json || once || f_list)) curses = 1; - if (VSM_Start(vd, t_arg, STDERR_FILENO)) + if (VSM_Attach(vd, STDERR_FILENO)) VUT_Error(1, "%s", VSM_Error(vd)); if (curses) diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c index 791ce69..dbf6036 100644 --- a/bin/varnishstat/varnishstat_curses.c +++ b/bin/varnishstat/varnishstat_curses.c @@ -1043,6 +1043,8 @@ handle_keypress(int ch) redraw = 1; } +#include + void do_curses(struct vsm *vd, double delay) { @@ -1070,14 +1072,13 @@ do_curses(struct vsm *vd, double delay) init_hitrate(); while (keep_running) { - if (VSM_Abandoned(vd)) { + if (VSM_Status(vd) | (VSM_MGT_CHANGED|VSM_WRK_CHANGED)) { init_hitrate(); delete_pt_list(); - VSM_Close(vd); - VSM_Open(vd); - } - if (VSM_valid != VSM_StillValid(vd, &f_iter)) build_pt_list(vd, &f_iter); + rebuild = 1; + redraw = 1; + } now = VTIM_mono(); if (now - t_sample > interval) @@ -1107,6 +1108,6 @@ do_curses(struct vsm *vd, double delay) break; } } - VSM_Close(vd); + VSM_Destroy(&vd); AZ(endwin()); } diff --git a/bin/varnishtest/tests/b00000.vtc b/bin/varnishtest/tests/b00000.vtc index 7937df8..388c9b8 100644 --- a/bin/varnishtest/tests/b00000.vtc +++ b/bin/varnishtest/tests/b00000.vtc @@ -14,10 +14,12 @@ varnish v1 -vcl+backend { varnish v1 -cliok "param.set debug +workspace" varnish v1 -cliok "param.set debug +witness" -varnish v1 -expect n_object == 0 -varnish v1 -expect sess_conn == 0 -varnish v1 -expect client_req == 0 -varnish v1 -expect cache_miss == 0 +varnish v1 -vsc * + +varnish v1 -expect MAIN.n_object == 0 +varnish v1 -expect MAIN.sess_conn == 0 +varnish v1 -expect MAIN.client_req == 0 +varnish v1 -expect MAIN.cache_miss == 0 client c1 { txreq -url "/" diff --git a/bin/varnishtest/tests/c00083.vtc b/bin/varnishtest/tests/c00083.vtc deleted file mode 100644 index 9b80321..0000000 --- a/bin/varnishtest/tests/c00083.vtc +++ /dev/null @@ -1,30 +0,0 @@ -varnishtest "VSM overflow allocation" - -server s1 { - rxreq - txresp -} -start - -varnish v1 -arg "-pvcc_allow_inline_c=true" -vcl+backend { - - C{ - void *VSM_Alloc(unsigned size, const char *class, const char *type, - const char *ident); - void VSM_Free(void *ptr); - }C - - sub vcl_recv { - C{ - void *p; - p = VSM_Alloc(3 * 1024 * 1024, "TEST", "TYPE", "0"); - VSM_Free(p); - }C - } - -} -start - -client c1 { - txreq - rxresp -} -run - diff --git a/bin/varnishtest/tests/m00029.vtc b/bin/varnishtest/tests/m00029.vtc index c92b839..023fee0 100644 --- a/bin/varnishtest/tests/m00029.vtc +++ b/bin/varnishtest/tests/m00029.vtc @@ -10,7 +10,7 @@ varnish v1 -vcl+backend { sub vcl_deliver { set resp.http.existsA = std.file_exists("/non/existent"); - set resp.http.existsB = std.file_exists("${tmpdir}/v1/_.vsm"); + set resp.http.existsB = std.file_exists("${tmpdir}/v1/_.vsm_mgt/_.index"); } } -start diff --git a/bin/varnishtest/tests/r01984.vtc b/bin/varnishtest/tests/r01984.vtc deleted file mode 100644 index b8b4a12..0000000 --- a/bin/varnishtest/tests/r01984.vtc +++ /dev/null @@ -1,18 +0,0 @@ -varnishtest "g_cooldown counter test" - -server s1 {} -start -varnish v1 -vcl+backend {} -start -varnish v1 -cliok "param.set vsm_free_cooldown 10.0" - -# Load and use a new VCL, freeze the first -varnish v1 -vcl+backend {} -varnish v1 -cliok "vcl.state vcl1 cold" - -# the VSM_common_cleaner runs every 1.1 seconds. -# Wait for it to update vsm_cooling -delay 2 -varnish v1 -expect vsm_cooling > 0 - -# Wait long enough for all the cooling vsm memory to be transfered to the free list: -delay 12 -varnish v1 -expect vsm_cooling == 0 diff --git a/bin/varnishtest/tests/r02270.vtc b/bin/varnishtest/tests/r02270.vtc index 8547ca5..2959e8d 100644 --- a/bin/varnishtest/tests/r02270.vtc +++ b/bin/varnishtest/tests/r02270.vtc @@ -16,4 +16,6 @@ varnish v1 -expect VBE.vcl2.s1.happy >= 0 delay 5 +varnish v1 -vsc VBE.* + varnish v1 -expect !VBE.vcl2.s1.happy diff --git a/bin/varnishtest/tests/u00005.vtc b/bin/varnishtest/tests/u00005.vtc index 5d91958..52242be 100644 --- a/bin/varnishtest/tests/u00005.vtc +++ b/bin/varnishtest/tests/u00005.vtc @@ -37,9 +37,11 @@ shell -expect "Copyright (c) 2006 Verdens Gang AS" \ "varnishstat -V" shell -err -expect "Usage: varnishstat " \ "varnishstat extra" -shell -err -expect "-t: Range error" \ +shell -err -expect "-t: Invalid argument: -1" \ "varnishstat -t -1" -shell -err -expect "-t: Syntax error" \ +shell -err -expect "-t: Invalid argument: Nan" \ + "varnishstat -t Nan" +shell -err -expect "-t: Invalid argument: foo" \ "varnishstat -t foo" shell -err -expect "Could not get hold of varnishd" \ "varnishstat -n /nonexistent -t 1" diff --git a/bin/varnishtest/tests/u00006.vtc b/bin/varnishtest/tests/u00006.vtc index a36eff2..e87e4da 100644 --- a/bin/varnishtest/tests/u00006.vtc +++ b/bin/varnishtest/tests/u00006.vtc @@ -41,10 +41,12 @@ shell -err -expect {-I: "Resp" is ambiguous} \ "varnishlog -I Resp:bar" shell -err -expect {-I: Regex error at position 4 (missing ))} \ {varnishlog -I "(foo"} -shell -err -expect "-t: Range error" \ +shell -err -expect "-t: Invalid argument" \ "varnishlog -t -1" -shell -err -expect "-t: Syntax error" \ +shell -err -expect "-t: Invalid argument" \ "varnishlog -t foo" +shell -err -expect "-t: Invalid argument" \ + "varnishlog -t NaN" shell -err -expect {-x: Syntax error in "**"} \ {varnishlog -x "**"} shell -err -expect {-X: Syntax error in "**"} \ diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c index 1c5a696..7f7d054 100644 --- a/bin/varnishtest/vtc_logexp.c +++ b/bin/varnishtest/vtc_logexp.c @@ -227,10 +227,12 @@ logexp_new(const char *name, const char *varg) VSB_destroy(&vsb); if (n_arg == NULL) vtc_fatal(le->vl, "-v argument problems"); - if (VSM_n_Arg(le->vsm, VSB_data(n_arg)) <= 0) + if (VSM_Arg(le->vsm, 'n', VSB_data(n_arg)) <= 0) vtc_fatal(le->vl, "-v argument error: %s", VSM_Error(le->vsm)); VSB_destroy(&n_arg); + if (VSM_Attach(le->vsm, -1)) + vtc_fatal(le->vl, "VSM_Attach: %s", VSM_Error(le->vsm)); return (le); } @@ -378,7 +380,6 @@ logexp_close(struct logexp *le) if (le->vslq) VSLQ_Delete(&le->vslq); AZ(le->vslq); - VSM_Close(le->vsm); } static void @@ -390,9 +391,8 @@ logexp_start(struct logexp *le) AN(le->vsl); AZ(le->vslq); - if (VSM_Start(le->vsm, 0, -1)) - vtc_fatal(le->vl, "VSM_Start: %s", VSM_Error(le->vsm)); AN(le->vsl); + (void)VSM_Status(le->vsm); c = VSL_CursorVSM(le->vsl, le->vsm, (le->d_arg ? 0 : VSL_COPT_TAIL) | VSL_COPT_BATCH); if (c == NULL) diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 4590754..3b5014c 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -76,10 +76,8 @@ struct varnish { char *jail; char *proto; - struct vsm *vd; /* vsc use */ - struct vsm *vdl; /* log use */ + struct vsm *vd; int has_a_arg; - struct vsm_fantom vf; unsigned vsl_tag_count[256]; @@ -212,15 +210,7 @@ varnishlog_thread(void *priv) vsl = VSL_New(); AN(vsl); - vsm = v->vdl; -#if 0 - //vsm = VSM_New(); - AN(vsm); - (void)VSM_n_Arg(vsm, v->workdir); - - if (VSM_Start(vsm, vtc_maxdur, 2)) - vtc_fatal(v->vl, "vsm|%s", VSM_Error(vsm)); -#endif + vsm = v->vd; c = NULL; opt = 0; @@ -229,16 +219,10 @@ varnishlog_thread(void *priv) if (vtc_error) break; VTIM_sleep(0.1); - if (VSM_Open(vsm)) { - vtc_log(v->vl, 3, "vsm|%s", - VSM_Error(vsm)); - VSM_ResetError(vsm); - continue; - } + (void)VSM_Status(vsm); c = VSL_CursorVSM(vsl, vsm, opt); if (c == NULL) { - vtc_log(v->vl, 3, "vsl|%s", - VSL_Error(vsl)); + vtc_log(v->vl, 3, "vsl|%s", VSL_Error(vsl)); VSL_ResetError(vsl); continue; } @@ -271,12 +255,17 @@ varnishlog_thread(void *priv) if (i == 0) { /* Nothing to do but wait */ v->vsl_idle++; - VTIM_sleep(0.1); + if (!(VSM_Status(vsm) & VSM_WRK_RUNNING)) { + /* Abandoned - try reconnect */ + VSL_DeleteCursor(c); + c = NULL; + } else { + VTIM_sleep(0.1); + } } else if (i == -2) { /* Abandoned - try reconnect */ VSL_DeleteCursor(c); c = NULL; - VSM_Close(vsm); } else break; } @@ -284,7 +273,6 @@ varnishlog_thread(void *priv) if (c) VSL_DeleteCursor(c); VSL_Delete(vsl); - VSM_Destroy(&v->vdl); return (NULL); } @@ -532,13 +520,9 @@ varnish_launch(struct varnish *v) free(r); v->vd = VSM_New(); - (void)VSM_n_Arg(v->vd, v->workdir); - AZ(VSM_Start(v->vd, vtc_maxdur, -1)); - assert(VSM_Get(v->vd, &v->vf, "Arg", "-i") > 0); + (void)VSM_Arg(v->vd, 'n', v->workdir); + AZ(VSM_Attach(v->vd, -1)); - v->vdl = VSM_New(); - (void)VSM_n_Arg(v->vdl, v->workdir); - AZ(VSM_Start(v->vdl, vtc_maxdur, -1)); AZ(pthread_create(&v->tp_vsl, NULL, varnishlog_thread, v)); } @@ -848,19 +832,14 @@ do_stat_dump_cb(void *priv, const struct VSC_point * const pt) } static void -varnish_vsc(struct varnish *v, const char *arg) +varnish_vsc(const struct varnish *v, const char *arg) { struct dump_priv dp; memset(&dp, 0, sizeof dp); dp.v = v; dp.arg = arg; - if (VSM_StillValid(v->vd, &v->vf) != VSM_valid) { - VSM_Close(v->vd); - if (VSM_Open(v->vd) < 0) - vtc_fatal(v->vl, "Could not open VSM (%s)", - VSM_Error(v->vd)); - } + (void)VSM_Status(v->vd); (void)VSC_Iter(v->vd, NULL, do_stat_dump_cb, &dp); } @@ -876,7 +855,7 @@ struct stat_priv { }; static int -do_stat_cb(void *priv, const struct VSC_point * const pt) +do_expect_cb(void *priv, const struct VSC_point * const pt) { struct stat_priv *sp = priv; @@ -896,7 +875,7 @@ do_stat_cb(void *priv, const struct VSC_point * const pt) */ static void -varnish_expect(struct varnish *v, char * const *av) +varnish_expect(const struct varnish *v, char * const *av) { uint64_t ref; int good; @@ -925,15 +904,10 @@ varnish_expect(struct varnish *v, char * const *av) sp.v = v; ref = 0; good = 0; - for (i = 0; i < 10; i++, (void)usleep(100000)) { - if (VSM_StillValid(v->vd, &v->vf) != VSM_valid) { - VSM_Close(v->vd); - good = VSM_Open(v->vd); - } - if (good < 0) - continue; + for (i = 0; i < 50; i++, (void)usleep(100000)) { + (void)VSM_Status(v->vd); - good = VSC_Iter(v->vd, NULL, do_stat_cb, &sp); + good = VSC_Iter(v->vd, NULL, do_expect_cb, &sp); if (!good) { good = -2; continue; diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c index ca4df6d..1d7ebe0 100644 --- a/bin/varnishtop/varnishtop.c +++ b/bin/varnishtop/varnishtop.c @@ -75,6 +75,7 @@ static unsigned ntop; static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; static int f_flag = 0; static unsigned maxfieldlen = 0; +static char *ident; static volatile sig_atomic_t quit = 0; @@ -201,7 +202,7 @@ update(int p) if (n < p) n++; AC(erase()); - q = VSM_Name(VUT.vsm); + q = ident; len = COLS - strlen(q); if (end_of_file) AC(mvprintw(0, len - (1 + 6), "%s (EOF)", q)); @@ -360,6 +361,7 @@ main(int argc, char **argv) usage(1); VUT_Setup(); + ident = VSM_Dup(VUT.vsm, "Arg", "-i"); if (!once) { if (pthread_create(&thr, NULL, do_curses, NULL) != 0) { fprintf(stderr, "pthread_create(): %s\n", diff --git a/include/vapi/vsc.h b/include/vapi/vsc.h index 022ccfc..7a87f70 100644 --- a/include/vapi/vsc.h +++ b/include/vapi/vsc.h @@ -44,7 +44,7 @@ struct vsm_fantom; * VSC level access functions */ -int VSC_Arg(struct vsm *vd, int arg, const char *opt); +int VSC_Arg(struct vsm *vd, char arg, const char *opt); /* * Handle standard stat-presenter arguments * Return: diff --git a/include/vapi/vsm.h b/include/vapi/vsm.h index 6a22c70..0ccbd44 100644 --- a/include/vapi/vsm.h +++ b/include/vapi/vsm.h @@ -36,7 +36,6 @@ #ifndef VAPI_VSM_H_INCLUDED #define VAPI_VSM_H_INCLUDED -struct VSM_chunk; struct vsm; /* @@ -44,16 +43,15 @@ struct vsm; */ struct vsm_fantom { + uintptr_t priv; /* VSM private */ struct VSM_chunk *chunk; void *b; /* first byte of payload */ void *e; /* first byte past payload */ - uintptr_t priv; /* VSM private */ char *class; - char *type; char *ident; }; -#define VSM_FANTOM_NULL { 0, 0, 0, 0, 0, 0, 0 } +#define VSM_FANTOM_NULL { 0, 0, 0, 0, 0, 0 } /*--------------------------------------------------------------------- * VSM level access functions @@ -62,7 +60,7 @@ struct vsm_fantom { struct vsm *VSM_New(void); /* * Allocate and initialize a VSL_data handle structure. - * This is the first thing you will have to do, always. + * This is the first thing you will always have to do. * You can have multiple active vsm handles at the same time * referencing the same or different shared memory files. * Returns: @@ -73,78 +71,70 @@ struct vsm *VSM_New(void); void VSM_Destroy(struct vsm **vd); /* * Close and deallocate all storage and mappings. - * (including any VSC and VSL "sub-classes") + * (including any VSC and VSL "sub-classes" XXX?) */ const char *VSM_Error(const struct vsm *vd); /* - * Return the latest error message. + * Return the first recorded error message. */ void VSM_ResetError(struct vsm *vd); /* - * Reset any error message. + * Reset recorded error message. */ #define VSM_n_USAGE "[-n varnish_name]" +#define VSM_t_USAGE "[-t ]" -int VSM_n_Arg(struct vsm *, const char *n_arg); +int VSM_Arg(struct vsm *, char flag, const char *t_arg); /* - * Configure which varnishd instance to access. - * Uses hostname if n_arg is NULL or "". + * Handle all VSM specific command line arguments. * * Returns: * 1 on success * <0 on failure, VSM_Error() returns diagnostic string - */ - -int VSM_Start(struct vsm *, double patience, int progress_fd); - -const char *VSM_Name(struct vsm *); - /* - * Return the instance name (-i argument to varnishd) - */ - -int VSM_Open(struct vsm *); - /* - * Attempt to open and map the VSM file. * - * Returns: - * 0 on success, or the VSM log was already open - * <0 on failure, VSM_Error() returns diagnostic string - */ - -int VSM_IsOpen(const struct vsm *vd); - /* - * Check if the VSM is open. + * 't' Configure patience during startup * - * Returns: - * 1: Is open - * 0: Is closed + * If t_arg is "off", VSM_Attach() will wait forever. + * Otherwise t_arg is the number of seconds to be patient + * while the varnishd manager process gets started. + * + * The default is five seconds. + * + * 'n' Configure varnishd instance to access + * + * The default is the hostname. */ -int VSM_Abandoned(struct vsm *vd); +int VSM_Attach(struct vsm *, int progress); /* - * Find out if the VSM file has been abandoned or closed and should - * be reopened. This function calls stat(2) and should only be - * used when lack of activity or invalidation of fantoms indicate - * abandonment. + * Attach to the master process VSM segment, according to + * the 't' argument. If `progress_fd` is non-negative, a + * period ('.') will be output for each second waited, and if + * any periods were output, a NL ('\n') is outout before the + * function returns. * * Returns: - * 0 No reopen needed. - * 1 VSM abandoned. + * 0 Attached + * -1 Not Attached. */ -void VSM_Close(struct vsm *vd); +#define VSM_MGT_RUNNING (1U<<1) +#define VSM_MGT_CHANGED (1U<<2) +#define VSM_MGT_RESTARTED (1U<<3) +#define VSM_WRK_RUNNING (1U<<9) +#define VSM_WRK_CHANGED (1U<<10) +#define VSM_WRK_RESTARTED (1U<<11) + +unsigned VSM_Status(struct vsm *); /* - * Close and unmap shared memory, if open. Any reference to - * previously returned memory areas will cause segmentation - * fault. This includes any VSC counter areas or any VSL SHM - * record references. + * Returns a bitmap of the current status and changes in it + * since the previous call to VSM_Status */ - -void VSM__iter0(struct vsm *, struct vsm_fantom *vf); +void VSM__iter0(const struct vsm *, struct vsm_fantom *vf); int VSM__itern(struct vsm *, struct vsm_fantom *vf); #define VSM_FOREACH(vf, vd) \ @@ -164,37 +154,20 @@ struct vsm_valid { extern const struct vsm_valid VSM_invalid[]; extern const struct vsm_valid VSM_valid[]; -extern const struct vsm_valid VSM_similar[]; -const struct vsm_valid *VSM_StillValid(struct vsm *, struct vsm_fantom *vf); +const struct vsm_valid *VSM_StillValid(const struct vsm *, const struct vsm_fantom *vf); /* * Check the validity of a previously looked up vsm_fantom. * * VSM_invalid means that the SHM chunk this fantom points to does - * not exist in the log file any longer. Using the fantom's - * pointer gives undefined results. Further checking with - * VSM_Abandoned() may be a good idea. - * - * VSM_valid means that the SHM structure has not changed since - * the fantom was looked up or since the last call to - * VSM_StillValid(). + * not exist in the log file any longer. * - * VSM_similar means that the SHM structure has changed, but there - * is still a valid chunk present with the same the same type and - * identifier. The fantom's pointers and dimensions haven't - * changed. The next call to VSM_StillValid() on this fantom will - * return VSM_valid. - * - * Applications using the fantom to monitor a single chunk can - * treat VSM_similar as equal to VSM_valid. Applications using a - * fantom to monitor the SHM file for new or removed chunks, - * should reiterate over the chunks on VSM_similar as the - * structure has changed. + * VSM_valid means that the SHM chunk this fantom points to is still + * good. * * Return: * VSM_invalid: fantom is not valid any more. * VSM_valid: fantom is still the same. - * VSM_similar: a fantom with same dimensions exist in same position. */ int VSM_Get(struct vsm *, struct vsm_fantom *vf, @@ -205,4 +178,13 @@ int VSM_Get(struct vsm *, struct vsm_fantom *vf, * class is mandatory, ident optional. */ +char *VSM_Dup(struct vsm*, const char *class, const char *ident); + /* + * Returns a malloc'ed copy of the fanton. + * + * Return: + * NULL = Failure + * !NULL = malloc'ed pointer + */ + #endif /* VAPI_VSM_H_INCLUDED */ diff --git a/include/vsm_priv.h b/include/vsm_priv.h index 20f4f90..00619fc 100644 --- a/include/vsm_priv.h +++ b/include/vsm_priv.h @@ -26,98 +26,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * Define the layout of the shared memory log segment. - * - * NB: THIS IS NOT A PUBLIC API TO VARNISH! - * - * There is a lot of diplomacy and protocol involved with the VSM segment - * since there is no way to (and no desire to!) lock between the readers - * and the writer. - * - * In particular we want the readers to seamlessly jump from one VSM instance - * to another when the child restarts. - * - * The VSM segment life-cycle is: - * - * Manager creates VSM file under temp name - * - * Temp VSM file is initialized such that VSM_head is consistent - * with a non-zero alloc_seq - * - * Manager renames Temp VSM file to correct filename as atomic - * operation. - * - * When manager abandons VSM file, alloc_seq is set to zero, which - * never happens in any other circumstances. - * - * If a manager is started and finds and old abandoned VSM segment - * it will zero the alloc_seq in it, before replacing the file. - * - * Subscribers will have to monitor three things to make sure they look at - * the right thing: The alloc_seq field, the age counter and the dev+inode - * of the path-name. The former check is by far the cheaper, the second - * can be used to check that varnishd is still alive and the last check - * should only be employed when lack of activity in the VSM segment raises - * suspicion that something has happened. - * - * The allocations ("chunks") in the VSM forms a linked list, starting with - * VSM_head->first, with the first/next fields being byte offsets relative - * to the start of the VSM segment. - * - * The last chunk on the list, has next == 0. - * - * New chunks are appended to the list, no matter where in the VSM - * they happen to be allocated. - * - * Chunk allocation sequence is: - * Find free space - * Zero payload - * Init Chunk header - * Write memory barrier - * update hdr->first or $last->next pointer - * hdr->alloc_seq changes - * Write memory barrier - * - * Chunk contents should be designed so that zero bytes are not mistaken - * for valid contents. - * - * Chunk deallocation sequence is: - * update hdr->first or $prev->next pointer - * Write memory barrier - * this->len = 0 - * hdr->alloc_seq changes - * Write memory barrier - * - * The space occupied by the chunk is put on a cooling list and is not - * recycled for at least a minute. - * */ #ifndef VSM_PRIV_H_INCLUDED #define VSM_PRIV_H_INCLUDED -#define VSM_FILENAME "_.vsm" -#define VSM_MARKER_LEN 8 -#define VSM_IDENT_LEN 128 +#define VSM_MGT_DIRNAME "_.vsm_mgt" +#define VSM_CHILD_DIRNAME "_.vsm_child" -struct VSM_chunk { -#define VSM_CHUNK_MARKER "VSMCHUNK" - char marker[VSM_MARKER_LEN]; - ssize_t len; /* Incl VSM_chunk */ - ssize_t next; /* Offset in shmem */ - char class[VSM_MARKER_LEN]; - char type[VSM_MARKER_LEN]; - char ident[VSM_IDENT_LEN]; -}; - -struct VSM_head { -#define VSM_HEAD_MARKER "VSMHEAD0" /* Incr. as version# */ - char marker[VSM_MARKER_LEN]; - ssize_t hdrsize; - ssize_t shm_size; - ssize_t first; /* Offset, first chunk */ - unsigned alloc_seq; - uint64_t age; -}; +#define VSM_MARKER_LEN 8 #endif /* VSM_PRIV_H_INCLUDED */ diff --git a/include/vut.h b/include/vut.h index 981524e..346d7bd 100644 --- a/include/vut.h +++ b/include/vut.h @@ -45,7 +45,7 @@ struct VUT { char *P_arg; char *q_arg; char *r_arg; - double t_arg; + char *t_arg; /* State */ struct VSL_data *vsl; diff --git a/lib/libvarnish/vfil.c b/lib/libvarnish/vfil.c index 55da29f..6df5af6 100644 --- a/lib/libvarnish/vfil.c +++ b/lib/libvarnish/vfil.c @@ -223,14 +223,17 @@ VFIL_fsinfo(int fd, unsigned *pbs, uintmax_t *psize, uintmax_t *pspace) * * Returns 0 on success, -1 on failure with errno set. */ + int VFIL_allocate(int fd, off_t size, int insist) { struct stat st; uintmax_t fsspace; size_t l; - ssize_t l2; - char buf[64 * 1024]; + ssize_t l2, l3; + char *buf; + ssize_t bufsiz; + int retval = 0; if (ftruncate(fd, size)) return (-1); @@ -268,18 +271,26 @@ VFIL_allocate(int fd, off_t size, int insist) /* Write size zero bytes to make sure the entire file is allocated in the file system */ - memset(buf, 0, sizeof buf); + if (size > 65536) + bufsiz = 64 * 1024; + else + bufsiz = size; + buf = calloc(bufsiz, 1); + AN(buf); assert(lseek(fd, 0, SEEK_SET) == 0); for (l = 0; l < size; l += l2) { - l2 = sizeof buf; + l2 = bufsiz; if (l + l2 > size) l2 = size - l; - l2 = write(fd, buf, l2); - if (l2 < 0) - return (-1); + l3 = write(fd, buf, l2); + if (l3 != l2) { + retval = -1; + break; + } } assert(lseek(fd, 0, SEEK_SET) == 0); - return (0); + free(buf); + return (retval); } struct vfil_dir { diff --git a/lib/libvarnish/vin.c b/lib/libvarnish/vin.c index f2a3119..5a3d948 100644 --- a/lib/libvarnish/vin.c +++ b/lib/libvarnish/vin.c @@ -38,7 +38,6 @@ #include #include -#include "vsm_priv.h" #include "vas.h" // XXX Flexelint "not used" - but req'ed for assert() #include "vdef.h" #include "vin.h" @@ -75,12 +74,6 @@ VIN_n_Arg(const char *n_arg, char **dir) bprintf(dn, "%s/%s", VARNISH_STATE_DIR, nm); } - /* Definitive length check */ - if (strlen(dn) + 1 + strlen(VSM_FILENAME) >= sizeof dn) { - errno = ENAMETOOLONG; - return (-1); - } - strcat(dn, "/"); if (dir != NULL) { diff --git a/lib/libvarnish/vsmw.c b/lib/libvarnish/vsmw.c index d57557e..3d1c095 100644 --- a/lib/libvarnish/vsmw.c +++ b/lib/libvarnish/vsmw.c @@ -85,11 +85,22 @@ struct vsmw { char *idx; VTAILQ_HEAD(, vsmwseg) segs; struct vsb *vsb; + pid_t pid; + time_t birth; }; /*--------------------------------------------------------------------*/ static void +vsmw_idx_head(const struct vsmw *vsmw, int fd) +{ + char buf[64]; + + bprintf(buf, "# %jd %jd\n", (intmax_t)vsmw->pid, (intmax_t)vsmw->birth); + assert(write(fd, buf, strlen(buf)) == strlen(buf)); +} + +static void vsmw_write_index(const struct vsmw *vsmw, int fd, const struct vsmwseg *seg) { ssize_t s; @@ -116,7 +127,9 @@ vsmw_mkent(const struct vsmw *vsmw, const char *pfx) while (1) { VSB_clear(vsmw->vsb); - VSB_printf(vsmw->vsb, "%s.%lx", pfx, VRND_RandomTestable()); + VSB_printf(vsmw->vsb, "_.%s", pfx); + VSB_printf(vsmw->vsb, ".%08lx", VRND_RandomTestable()); + VSB_printf(vsmw->vsb, "%08lx", VRND_RandomTestable()); AZ(VSB_finish(vsmw->vsb)); fd = openat(vsmw->vdirfd, VSB_data(vsmw->vsb), O_RDONLY); if (fd < 0 && errno == ENOENT) @@ -215,12 +228,13 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx) vsmw_mkent(vsmw, vsmw->idx); REPLACE(t, VSB_data(vsmw->vsb)); AN(t); - fd = open(t, O_WRONLY|O_CREAT|O_EXCL, vsmw->mode); + fd = openat(vsmw->vdirfd, t, O_WRONLY|O_CREAT|O_EXCL, vsmw->mode); assert(fd >= 0); + vsmw_idx_head(vsmw, fd); VTAILQ_FOREACH(seg, &vsmw->segs, list) vsmw_write_index(vsmw, fd, seg); AZ(close(fd)); - AZ(rename(t, vsmw->idx)); + AZ(renameat(vsmw->vdirfd, t, vsmw->vdirfd, vsmw->idx)); REPLACE(t, NULL); } } @@ -256,19 +270,24 @@ VSMW_New(int vdirfd, int mode, const char *idxname) assert(vdirfd > 0); assert(mode > 0); AN(idxname); + ALLOC_OBJ(vsmw, VSMW_MAGIC); AN(vsmw); + VTAILQ_INIT(&vsmw->segs); vsmw->vsb = VSB_new_auto(); AN(vsmw->vsb); REPLACE(vsmw->idx, idxname); vsmw->mode = mode; vsmw->vdirfd = vdirfd; + vsmw->pid = getpid(); + vsmw->birth = time(NULL); (void)unlinkat(vdirfd, vsmw->idx, 0); fd = openat(vdirfd, vsmw->idx, O_APPEND | O_WRONLY | O_CREAT, vsmw->mode); assert(fd >= 0); + vsmw_idx_head(vsmw, fd); AZ(close(fd)); return (vsmw); diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am index 54f1884..fbd4014 100644 --- a/lib/libvarnishapi/Makefile.am +++ b/lib/libvarnishapi/Makefile.am @@ -23,6 +23,7 @@ libvarnishapi_la_SOURCES = \ ../../include/vcs_version.h \ ../libvarnish/version.c \ ../libvarnish/vcli_proto.c \ + ../libvarnish/vfil.c \ ../libvarnish/vfl.c \ ../libvarnish/vin.c \ ../libvarnish/vmb.c \ diff --git a/lib/libvarnishapi/libvarnishapi.map b/lib/libvarnishapi/libvarnishapi.map index c860e7d..6a7cab2 100644 --- a/lib/libvarnishapi/libvarnishapi.map +++ b/lib/libvarnishapi/libvarnishapi.map @@ -188,4 +188,9 @@ LIBVARNISHAPI_1.7 { VSM_Unmap; VSC_Destroy_Point; VSC_Clone_Point; + VSM_Refresh; + VSM_Attach; + VSM_Status; + VSM_Arg; + VSM_Dup; } LIBVARNISHAPI_1.0; diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c index c4245b7..399c054 100644 --- a/lib/libvarnishapi/vsc.c +++ b/lib/libvarnishapi/vsc.c @@ -193,12 +193,14 @@ vsc_f_arg(struct vsm *vd, const char *opt) /*--------------------------------------------------------------------*/ int -VSC_Arg(struct vsm *vd, int arg, const char *opt) +VSC_Arg(struct vsm *vd, char arg, const char *opt) { switch (arg) { case 'f': return (vsc_f_arg(vd, opt)); - case 'n': return (VSM_n_Arg(vd, opt)); + case 'n': + case 't': + return (VSM_Arg(vd, arg, opt)); default: return (0); } @@ -241,10 +243,7 @@ vsc_iter_elem(struct vsm *vd, const struct vsm_fantom *fantom, assert(vt->type == VJSN_STRING); VSB_clear(vsb); - VSB_printf(vsb, "%s", fantom->type); - if (*fantom->ident) - VSB_printf(vsb, ".%s", fantom->ident); - VSB_printf(vsb, ".%s", vt->value); + VSB_printf(vsb, "%s.%s", fantom->ident, vt->value); AZ(VSB_finish(vsb)); if (vsc_filter(vd, VSB_data(vsb))) @@ -314,6 +313,7 @@ vsc_iter_fantom(struct vsm *vd, const struct vsm_fantom *fantom, struct vjsn_val *vv, *vve; p = (char*)fantom->b + 8 + vbe64dec(fantom->b); + assert (p < (char*)fantom->e); vj = vjsn_parse(p, &e); if (e != NULL) { fprintf(stderr, "%s\n", p); @@ -360,7 +360,8 @@ VSC_Iter(struct vsm *vd, struct vsm_fantom *fantom, VSC_iter_f *func, if (fantom != NULL) *fantom = ifantom; i = vsc_iter_fantom(vd, &ifantom, vsb, func, priv); - AZ(VSM_Unmap(vd, &ifantom)); + if (fantom == NULL) + AZ(VSM_Unmap(vd, &ifantom)); if (i) break; } diff --git a/lib/libvarnishapi/vsl_cursor.c b/lib/libvarnishapi/vsl_cursor.c index c161abb..0424922 100644 --- a/lib/libvarnishapi/vsl_cursor.c +++ b/lib/libvarnishapi/vsl_cursor.c @@ -77,6 +77,7 @@ vslc_vsm_delete(const struct VSL_cursor *cursor) struct vslc_vsm *c; CAST_OBJ_NOTNULL(c, cursor->priv_data, VSLC_VSM_MAGIC); + AZ(VSM_Unmap(c->vsm, &c->vf)); assert(&c->cursor == cursor); FREE_OBJ(c); } @@ -143,8 +144,7 @@ vslc_vsm_next(const struct VSL_cursor *cursor) } if (t == VSL_ENDMARKER) { - if (VSM_invalid == VSM_StillValid(c->vsm, &c->vf) || - VSM_Abandoned(c->vsm)) + if (VSM_StillValid(c->vsm, &c->vf) != VSM_valid) return (-2); /* VSL abandoned */ if (c->options & VSL_COPT_TAILSTOP) return (-1); /* EOF */ @@ -252,16 +252,22 @@ VSL_CursorVSM(struct VSL_data *vsl, struct vsm *vsm, unsigned options) "No VSL chunk found (child not started ?)"); return (NULL); } - AZ(VSM_Map(vsm, &vf)); + if (VSM_Map(vsm, &vf)) { + (void)vsl_diag(vsl, + "VSM_Map(): %s", VSM_Error(vsm)); + return (NULL); + } AN(vf.b); head = vf.b; if (memcmp(head->marker, VSL_HEAD_MARKER, sizeof head->marker)) { + AZ(VSM_Unmap(vsm, &vf)); (void)vsl_diag(vsl, "Not a VSL chunk"); return (NULL); } ALLOC_OBJ(c, VSLC_VSM_MAGIC); if (c == NULL) { + AZ(VSM_Unmap(vsm, &vf)); (void)vsl_diag(vsl, "Out of memory"); return (NULL); } diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 9a41974..4c0e9ed 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -35,8 +35,11 @@ #include #include +#include +#include #include #include +#include #include #include #include @@ -45,85 +48,76 @@ #include "vas.h" #include "miniobj.h" +#include "vav.h" #include "vin.h" #include "vsb.h" #include "vsm_priv.h" #include "vsc_priv.h" +#include "vqueue.h" #include "vtim.h" #include "vapi/vsm.h" - #ifndef MAP_HASSEMAPHORE #define MAP_HASSEMAPHORE 0 /* XXX Linux */ #endif const struct vsm_valid VSM_invalid[1] = {{"invalid"}}; const struct vsm_valid VSM_valid[1] = {{"valid"}}; -const struct vsm_valid VSM_similar[1] = {{"similar"}}; /*--------------------------------------------------------------------*/ -struct vsc; +struct vsm_set; -struct vsm { +struct vsm_seg { unsigned magic; -#define VSM_MAGIC 0x6e3bd69b - - struct vsb *diag; - - char *dname; - char *iname; - - struct stat fstat; - - int vsm_fd; - struct VSM_head *head; - char *b; - char *e; - - uint64_t age_ok; - double t_ok; - - int started; - - struct vsc *vsc; +#define VSM_SEG_MAGIC 0xeb6c6dfd + VTAILQ_ENTRY(vsm_seg) list; + int markscan; + int stale; + struct vsm_set *set; + char **av; + int refs; + void *b; + void *e; + size_t sz; + uintptr_t serial; }; -/*--------------------------------------------------------------------*/ - -struct vsm * -VSM_New(void) -{ - struct vsm *vd; +struct vsm_set { + unsigned magic; +#define VSM_SET_MAGIC 0xdee401b8 + const char *dname; + VTAILQ_HEAD(,vsm_seg) segs; + VTAILQ_HEAD(,vsm_seg) stale; - ALLOC_OBJ(vd, VSM_MAGIC); - if (vd == NULL) - return (vd); + int dfd; + struct stat dst; - vd->vsm_fd = -1; + int fd; + struct stat fst; - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - return (vd); -} + uintmax_t id1, id2; +}; -/*--------------------------------------------------------------------*/ +struct vsm { + unsigned magic; +#define VSM_MAGIC 0x6e3bd69b -void -VSM_SetVSC(struct vsm *vd, struct vsc *vsc) -{ - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + struct vsb *diag; + uintptr_t serial; - vd->vsc = vsc; -} + int dfd; + struct stat dst; + char *dname; -struct vsc * -VSM_GetVSC(const struct vsm *vd) -{ - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + struct vsc *vsc; + struct vsm_set *mgt; + struct vsm_set *child; - return (vd->vsc); -} + int attached; + double patience; +}; /*--------------------------------------------------------------------*/ @@ -145,344 +139,490 @@ vsm_diag(struct vsm *vd, const char *fmt, ...) AZ(VSB_finish(vd->diag)); return (-1); } + /*--------------------------------------------------------------------*/ -const char * -VSM_Error(const struct vsm *vd) +static struct vsm_set * +vsm_newset(const char *dirname) { + struct vsm_set *vs; + + ALLOC_OBJ(vs, VSM_SET_MAGIC); + AN(vs); + VTAILQ_INIT(&vs->segs); + VTAILQ_INIT(&vs->stale); + vs->dname = dirname; + vs->dfd = vs->fd = -1; + return (vs); +} - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - - if (vd->diag == NULL) - return (NULL); - else - return (VSB_data(vd->diag)); +static void +vsm_delset(struct vsm_set **p) +{ + struct vsm_set *vs; + + AN(p); + vs = *p; + *p = NULL; + if (vs->fd >= 0) + closefd(&vs->fd); + if (vs->dfd >= 0) + closefd(&vs->dfd); + // XXX: delete segments + FREE_OBJ(vs); } /*--------------------------------------------------------------------*/ -void -VSM_ResetError(struct vsm *vd) +struct vsm * +VSM_New(void) { + struct vsm *vd; - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + ALLOC_OBJ(vd, VSM_MAGIC); + AN(vd); - if (vd->diag == NULL) - return; - VSB_destroy(&vd->diag); + vd->mgt = vsm_newset(VSM_MGT_DIRNAME); + vd->child = vsm_newset(VSM_CHILD_DIRNAME); + vd->dfd = -1; + vd->patience = 5; + return (vd); } /*--------------------------------------------------------------------*/ int -VSM_n_Arg(struct vsm *vd, const char *arg) +VSM_Arg(struct vsm *vd, char flag, const char *arg) { - char *dname = NULL; - struct vsb *vsb; + char *p = NULL; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - AZ(vd->started); - - if (vd->head) - return (vsm_diag(vd, "VSM_n_Arg: Already open")); - if (VIN_n_Arg(arg, &dname)) - return (vsm_diag(vd, "Invalid instance name: %s", - strerror(errno))); - AN(dname); - vsb = VSB_new_auto(); - AN(vsb); - VSB_printf(vsb, "%s%s", dname, VSM_FILENAME); - AZ(VSB_finish(vsb)); - REPLACE(vd->dname, dname); - REPLACE(vd->iname, VSB_data(vsb)); + if (arg == NULL) + return (1); + switch (flag) { + case 't': + if (!strcasecmp(arg, "off")) { + vd->patience = -1; + } else { + vd->patience = strtod(arg, &p); + if ((p != NULL && *p != '\0') || + !isfinite(vd->patience) || vd->patience < 0) + return (vsm_diag(vd, + "-t: Invalid argument: %s", arg)); + } + break; + case 'n': + if (VIN_n_Arg(arg, &p)) + return (vsm_diag(vd, "Invalid instance name: %s", + strerror(errno))); + AN(p); + REPLACE(vd->dname, p); + free(p); + break; + default: + return (vsm_diag(vd, "Unknown VSM_Arg('%c')", flag)); + } + return (1); +} - VSB_destroy(&vsb); - free(dname); +/*--------------------------------------------------------------------*/ - return (1); +void +VSM_Destroy(struct vsm **vdp) +{ + struct vsm *vd; + + AN(vdp); + vd = *vdp; + *vdp = NULL; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + + if (vd->vsc != NULL) + VSC_Delete(vd->vsc); + VSM_ResetError(vd); + free(vd->dname); + vsm_delset(&vd->mgt); + vsm_delset(&vd->child); + if (vd->dfd >= 0) + closefd(&vd->dfd); + FREE_OBJ(vd); } /*--------------------------------------------------------------------*/ -int -VSM_Start(struct vsm *vd, double patience, int progress) +void +VSM_SetVSC(struct vsm *vd, struct vsc *vsc) { - double t0; - int i, n = 0; + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + + vd->vsc = vsc; +} +struct vsc * +VSM_GetVSC(const struct vsm *vd) +{ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - t0 = VTIM_mono(); - while (1) { - VSM_ResetError(vd); - i = VSM_Open(vd); - AN(vd->dname); - if (patience <= 0. || i == 0) { - if (progress >= 0 && n > 4) - (void)write(progress, "\n", 1); - vd->started = 1; - return (i); - } - if (t0 + patience < VTIM_mono()) { - if (progress >= 0 && n > 4) - (void)write(progress, "\n", 1); - return (vsm_diag(vd, - "Could not get hold of varnishd, is it running?")); - } - if (progress >= 0 && !(++n % 4)) - (void)write(progress, ".", 1); - VTIM_sleep(.25); - } + + return (vd->vsc); } /*--------------------------------------------------------------------*/ const char * -VSM_Name(struct vsm *vd) +VSM_Error(const struct vsm *vd) { - struct vsm_fantom vt; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - if (VSM_Get(vd, &vt, "Arg", "-i")) - return (vt.b); - return (""); + + if (vd->diag == NULL) + return ("No VSM error"); + else + return (VSB_data(vd->diag)); } /*--------------------------------------------------------------------*/ void -VSM_Destroy(struct vsm **vdp) +VSM_ResetError(struct vsm *vd) { - struct vsm *vd; - - AN(vdp); - vd = *vdp; - *vdp = NULL; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - VSM_Close(vd); - if (vd->vsc != NULL) - VSC_Delete(vd->vsc); - VSM_ResetError(vd); - free(vd->dname); - free(vd->iname); - FREE_OBJ(vd); + if (vd->diag == NULL) + return; + VSB_destroy(&vd->diag); } /*-------------------------------------------------------------------- - * The VSM open function - * - * Return: - * 0 = success - * <0 = failure - * */ -/*--------------------------------------------------------------------*/ +#define VSM_NUKE_ALL (1U << 16) -static void *ppp; +static int +vsm_cmp_av(char * const *a1, char * const *a2) +{ -int -VSM_Open(struct vsm *vd) + while (1) { + if (*a1 == NULL && *a2 == NULL) + return (0); + if (*a1 == NULL || *a2 == NULL) + return (1); + if (strcmp(*a1, *a2)) + return (1); + a1++; + a2++; + } +} + +static unsigned +vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs, struct vsb *vsb) { - int i; - struct VSM_head slh; - void *v; + unsigned retval = 0; + struct stat st; + char buf[BUFSIZ]; + ssize_t sz; + int i, ac; + char *p, *e; + uintmax_t id1, id2; + char **av; + struct vsm_seg *vg, *vg2; + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + CHECK_OBJ_NOTNULL(vs, VSM_SET_MAGIC); + if (vs->dfd >= 0) { + if (fstatat(vd->dfd, vs->dname, &st, AT_SYMLINK_NOFOLLOW)) { + closefd(&vs->dfd); + vs->id1 = vs->id2 = 0; + return (VSM_MGT_RESTARTED|VSM_NUKE_ALL); + } + if (st.st_ino != vs->dst.st_ino || + st.st_dev != vs->dst.st_dev || + st.st_mode != vs->dst.st_mode) { + closefd(&vs->dfd); + vs->id1 = vs->id2 = 0; + } + } - if (vd->head != NULL) - /* Already open */ - return (0); + if (vs->dfd < 0) { + if (vs->fd >= 0) + closefd(&vs->fd); + vs->dfd = openat(vd->dfd, vs->dname, O_RDONLY); + retval |= VSM_MGT_RESTARTED; + if (vs->dfd < 0) { + vs->id1 = vs->id2 = 0; + return (retval|VSM_NUKE_ALL); + } + AZ(fstat(vs->dfd, &vs->dst)); + } - if (vd->dname == NULL) { - /* Use default (hostname) */ - i = VSM_n_Arg(vd, ""); - if (i < 0) - return (i); - AN(vd->dname); + if (vs->fd >= 0 && ( + fstatat(vs->dfd, "_.index", &st, AT_SYMLINK_NOFOLLOW) || + st.st_ino != vs->fst.st_ino || + st.st_dev != vs->fst.st_dev || + st.st_mode != vs->fst.st_mode || + st.st_size != vs->fst.st_size || + st.st_nlink < 1 || + memcmp(&st.st_mtim, &vs->fst.st_mtim, sizeof st.st_mtim))) { + closefd(&vs->fd); } - vd->vsm_fd = open(vd->iname, O_RDONLY); - if (vd->vsm_fd < 0) - return (vsm_diag(vd, "Cannot open %s: %s", - vd->iname, strerror(errno))); - AZ(fstat(vd->vsm_fd, &vd->fstat)); - if (!S_ISREG(vd->fstat.st_mode)) { - closefd(&vd->vsm_fd); - return (vsm_diag(vd, "%s is not a regular file", vd->iname)); - } + if (vs->fd >= 0) + return (retval|VSM_MGT_RUNNING); - i = read(vd->vsm_fd, &slh, sizeof slh); - if (i != sizeof slh) { - closefd(&vd->vsm_fd); - return (vsm_diag(vd, "Cannot read %s: %s", - vd->iname, strerror(errno))); - } + retval |= VSM_MGT_CHANGED; + vs->fd = openat(vs->dfd, "_.index", O_RDONLY); + if (vs->fd < 0) + return (retval|VSM_NUKE_ALL); - if (memcmp(slh.marker, VSM_HEAD_MARKER, sizeof slh.marker)) { - closefd(&vd->vsm_fd); - return (vsm_diag(vd, "Not a VSM file %s", vd->iname)); - } + AZ(fstat(vs->fd, &vs->fst)); - if (slh.alloc_seq == 0) { - closefd(&vd->vsm_fd); - return (vsm_diag(vd, - "Abandoned VSM file (Varnish not running?) %s", - vd->iname)); - } + VSB_clear(vsb); + do { + sz = read(vs->fd, buf, sizeof buf); + if (sz > 0) + VSB_bcat(vsb, buf, sz); + } while (sz > 0); + AZ(VSB_finish(vsb)); + + vs->fst.st_size = VSB_len(vsb); + + if (VSB_len(vsb) == 0) + return (retval|VSM_NUKE_ALL); - v = mmap(ppp, slh.shm_size, - PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsm_fd, 0); - if (v == MAP_FAILED) - v = mmap(NULL, slh.shm_size, - PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsm_fd, 0); - if (v == MAP_FAILED) { - closefd(&vd->vsm_fd); - return (vsm_diag(vd, "Cannot mmap %s: %s", - vd->iname, strerror(errno))); - } /* - * Force failure of client depends on remapping at same address. + * Examine the ident line + * XXX: for now ignore that one of the ID's is a pid which could + * XXX: be kill(pid,0)'ed for more rapid abandonment detection. */ - ppp = (char*)v + getpagesize() * 1000; + i = sscanf(VSB_data(vsb), "# %ju %ju\n%n", &id1, &id2, &ac); + if (i != 2) { + retval |= VSM_MGT_RESTARTED; + return (retval|VSM_NUKE_ALL); + } + if (id1 != vs->id1 || id2 != vs->id2) { + retval |= VSM_MGT_RESTARTED; + vs->id1 = id1; + vs->id2 = id2; + } + p = VSB_data(vsb) + ac; + retval |= VSM_MGT_RUNNING; + + VTAILQ_FOREACH(vg, &vs->segs, list) + vg->markscan = 0; + + vg = VTAILQ_FIRST(&vs->segs); + while (p != NULL && *p != '\0') { + e = strchr(p, '\n'); + if (e == NULL) + break; + *e = '\0'; + av = VAV_Parse(p, &ac, 0); + p = e + 1; + + if (av[0] != NULL || ac < 4 || ac > 5) { + (void)(vsm_diag(vd, "VSM_Open: bad index (%d/%s)", + ac, av[0])); + VAV_Free(av); + break; + } + while (vg != NULL && !vsm_cmp_av(vg->av, av)) + vg = VTAILQ_NEXT(vg, list); + + if (vg != NULL) { + VAV_Free(av); + vg->markscan = 1; + vg = VTAILQ_NEXT(vg, list); + } else { + ALLOC_OBJ(vg2, VSM_SEG_MAGIC); + AN(vg2); + vg2->av = av; + vg2->set = vs; + vg2->markscan = 1; + vg2->serial = ++vd->serial; + VTAILQ_INSERT_TAIL(&vs->segs, vg2, list); + } - vd->head = v; - vd->b = v; - vd->e = vd->b + slh.shm_size; - vd->age_ok = vd->head->age; - vd->t_ok = VTIM_mono(); - return (0); + } + return (retval); } -/*--------------------------------------------------------------------*/ - -int -VSM_IsOpen(const struct vsm *vd) +static unsigned +vsm_refresh_set(struct vsm *vd, struct vsm_set *vs, struct vsb *vsb) { - - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - return (vd->head != NULL); + unsigned retval; + struct vsm_seg *vg, *vg2; + + retval = vsm_refresh_set2(vd, vs, vsb); + if (retval & VSM_NUKE_ALL) + retval |= VSM_MGT_CHANGED; + VTAILQ_FOREACH_SAFE(vg, &vs->segs, list, vg2) { + if (!vg->markscan || (retval & VSM_NUKE_ALL)) { + VTAILQ_REMOVE(&vs->segs, vg, list); + if (vg->refs) { + vg->stale = 1; + VTAILQ_INSERT_TAIL(&vs->stale, vg, list); + } else { + // XXX: munmap + VAV_Free(vg->av); + FREE_OBJ(vg); + } + } + } + return (retval & ~VSM_NUKE_ALL); } /*--------------------------------------------------------------------*/ -void -VSM_Close(struct vsm *vd) +unsigned +VSM_Status(struct vsm *vd) { + unsigned retval = 0, u; + struct stat st; + struct vsb *vsb; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - if (vd->head == NULL) - return; + /* See if the -n workdir changed */ + if (vd->dfd >= 0) { + AZ(fstat(vd->dfd, &st)); + if (st.st_ino != vd->dst.st_ino || + st.st_dev != vd->dst.st_dev || + st.st_mode != vd->dst.st_mode || + st.st_nlink == 0) { + closefd(&vd->dfd); + retval |= VSM_MGT_CHANGED; + retval |= VSM_WRK_CHANGED; + } + } - assert(vd->vsm_fd >= 0); - AZ(munmap((void*)vd->b, vd->e - vd->b)); - vd->b = NULL; - vd->e = NULL; - vd->head = NULL; - closefd(&vd->vsm_fd); + /* Open workdir */ + if (vd->dfd < 0) { + vd->dfd = open(vd->dname, O_RDONLY); + if (vd->dfd < 0) + (void)vsm_diag(vd, "VSM_Open: Cannot open workdir"); + else + AZ(fstat(vd->dfd, &vd->dst)); + } + + vsb = VSB_new_auto(); + AN(vsb); + + u = vsm_refresh_set(vd, vd->mgt, vsb); + retval |= u; + if (u & VSM_MGT_RUNNING) + retval |= vsm_refresh_set(vd, vd->child, vsb) << 8; + VSB_destroy(&vsb); + return (retval); } /*--------------------------------------------------------------------*/ int -VSM_Abandoned(struct vsm *vd) +VSM_Attach(struct vsm *vd, int progress) { - struct stat st; - double now; + double t0; + unsigned u; + int n = 0; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - if (vd->head == NULL) - /* Not open */ - return (1); - if (!vd->head->alloc_seq) - /* Flag of abandonment set by mgt */ - return (1); - if (vd->head->age < vd->age_ok) - /* Age going backwards */ - return (1); - now = VTIM_mono(); - if (vd->head->age == vd->age_ok && now - vd->t_ok > 2.) { - /* No age change for 2 seconds, stat the file */ - if (stat(vd->iname, &st)) - return (1); - if (st.st_dev != vd->fstat.st_dev) - return (1); - if (st.st_ino != vd->fstat.st_ino) - return (1); - vd->t_ok = now; - } else if (vd->head->age > vd->age_ok) { - /* It is aging, update timestamps */ - vd->t_ok = now; - vd->age_ok = vd->head->age; + if (vd->patience < 0) + t0 = DBL_MAX; + else + t0 = VTIM_mono() + vd->patience; + + AZ(vd->attached); + while (1) { + u = VSM_Status(vd); + VSM_ResetError(vd); + if (u & VSM_MGT_RUNNING) { + if (progress >= 0 && n > 4) + (void)write(progress, "\n", 1); + vd->attached = 1; + return (0); + } + if (t0 < VTIM_mono()) { + if (progress >= 0 && n > 4) + (void)write(progress, "\n", 1); + return (vsm_diag(vd, + "Could not get hold of varnishd, is it running?")); + } + if (progress >= 0 && !(++n % 4)) + (void)write(progress, ".", 1); + VTIM_sleep(.25); } - return (0); +} + +/*--------------------------------------------------------------------*/ + +static struct vsm_seg * +vsm_findseg(const struct vsm *vd, const struct vsm_fantom *vf) +{ + struct vsm_set *vs; + struct vsm_seg *vg; + uintptr_t x; + + x = vf->priv; + vs = vd->mgt; + VTAILQ_FOREACH(vg, &vs->segs, list) + if (vg->serial == x) + return (vg); + VTAILQ_FOREACH(vg, &vs->stale, list) + if (vg->serial == x) + return (vg); + vs = vd->child; + VTAILQ_FOREACH(vg, &vs->segs, list) + if (vg->serial == x) + return (vg); + VTAILQ_FOREACH(vg, &vs->stale, list) + if (vg->serial == x) + return (vg); + return (NULL); } /*--------------------------------------------------------------------*/ void -VSM__iter0(struct vsm *vd, struct vsm_fantom *vf) +VSM__iter0(const struct vsm *vd, struct vsm_fantom *vf) { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); AN(vf); + AN(vd->attached); memset(vf, 0, sizeof *vf); } int VSM__itern(struct vsm *vd, struct vsm_fantom *vf) { - struct VSM_chunk *c = NULL; + struct vsm_seg *vg, *vg2; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + AN(vd->attached); AN(vf); - if (!vd->head) - return (0); /* Not open */ - if (vd->head->alloc_seq == 0) - return (0); /* abandoned VSM */ - else if (vf->chunk != NULL) { - /* get next chunk */ - if (vf->priv != vd->head->alloc_seq) - return (0); /* changes during iteration */ - if (vf->chunk->len == 0) - return (0); /* free'd during iteration */ - if (vf->chunk->next == 0) - return (0); /* last */ - c = (struct VSM_chunk *)(void*)(vd->b + vf->chunk->next); - assert(c != vf->chunk); - } else if (vd->head->first == 0) { - return (0); /* empty vsm */ + if (vf->priv == 0) { + vg2 = VTAILQ_FIRST(&vd->mgt->segs); } else { - /* get first chunk */ - AZ(vf->chunk); - c = (struct VSM_chunk *)(void*)(vd->b + vd->head->first); + vg = vsm_findseg(vd, vf); + if (vg == NULL) + return (vsm_diag(vd, "VSM_FOREACH: inconsistency")); + vg2 = VTAILQ_NEXT(vg, list); + if (vg2 == NULL && vg->set == vd->mgt) + vg2 = VTAILQ_FIRST(&vd->child->segs); } - AN(c); - if (memcmp(c->marker, VSM_CHUNK_MARKER, sizeof c->marker)) - return (0); /* XXX - assert? */ - - vf->chunk = c; - vf->priv = vd->head->alloc_seq; - vf->b = (void*)(vf->chunk + 1); - vf->e = (char*)vf->b + vf->chunk->len; - - AZ(vf->chunk->class[sizeof vf->chunk->class - 1]); - REPLACE(vf->class, vf->chunk->class); - - AZ(vf->chunk->type[sizeof vf->chunk->type - 1]); - REPLACE(vf->type, vf->chunk->type); - - AZ(vf->chunk->ident[sizeof vf->chunk->ident - 1]); - REPLACE(vf->ident, vf->chunk->ident); - + if (vg2 == NULL) + return (0); + memset(vf, 0, sizeof *vf); + vf->priv = vg2->serial; + vf->class = vg2->av[3]; + vf->ident = vg2->av[4]; return (1); } @@ -491,10 +631,66 @@ VSM__itern(struct vsm *vd, struct vsm_fantom *vf) int VSM_Map(struct vsm *vd, struct vsm_fantom *vf) { + struct vsm_seg *vg; + size_t sz, ps, len; + struct vsb *vsb; + int fd; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + AN(vd->attached); AN(vf); - AN(vf->b); + vg = vsm_findseg(vd, vf); + if (vg == NULL) + return (vsm_diag(vd, "VSM_Map: bad fantom")); + + assert(vg->serial == vf->priv); + assert(vg->av[3] == vf->class); + assert(vg->av[4] == vf->ident); + + if (vg->b != NULL) { + assert(vg->refs > 0); + AN(vg->e); + vf->b = vg->b; + vf->e = vg->e; + vg->refs++; + return (0); + } + + sz = strtoul(vg->av[2], NULL, 10); + assert(sz > 0); + ps = getpagesize(); + len = RUP2(sz, ps); + + vsb = VSB_new_auto(); + AN(vsb); + VSB_printf(vsb, "%s/%s/%s", vd->dname, vg->set->dname, vg->av[1]); + AZ(VSB_finish(vsb)); + + fd = open(VSB_data(vsb), O_RDONLY); // XXX: openat + if (fd < 0) { + VSB_destroy(&vsb); + return (vsm_diag(vd, "Could not open segment")); + } + + vg->b = (void*)mmap(NULL, len, + PROT_READ, + MAP_HASSEMAPHORE | MAP_NOSYNC | MAP_SHARED, + fd, 0); + + VSB_destroy(&vsb); + + + closefd(&fd); + if (vg->b == MAP_FAILED) + return (vsm_diag(vd, "Could not mmap segment")); + vg->e = (char *)vg->b + sz; + vg->sz = len; + + vf->b = vg->b; + vf->e = vg->e; + + vg->refs++; + return (0); } @@ -503,51 +699,61 @@ VSM_Map(struct vsm *vd, struct vsm_fantom *vf) int VSM_Unmap(struct vsm *vd, struct vsm_fantom *vf) { + struct vsm_seg *vg; + size_t sz, ps, len; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + AN(vd->attached); AN(vf); AN(vf->b); + vg = vsm_findseg(vd, vf); + if (vg == NULL) + return (vsm_diag(vd, "VSM_Map: bad fantom")); + assert(vg->refs > 0); + vg->refs--; + vf->b = NULL; + vf->e = NULL; + if (vg->refs > 0) + return(0); + if (vg->stale) { + VTAILQ_REMOVE(&vg->set->stale, vg, list); + VAV_Free(vg->av); + FREE_OBJ(vg); + } else { + sz = strtoul(vg->av[2], NULL, 10); + assert(sz > 0); + ps = getpagesize(); + len = RUP2(sz, ps); + AZ(munmap(vg->b, len)); + vg->b = vg->e = NULL; + } return (0); } /*--------------------------------------------------------------------*/ const struct vsm_valid * -VSM_StillValid(struct vsm *vd, struct vsm_fantom *vf) +VSM_StillValid(const struct vsm *vd, const struct vsm_fantom *vf) { - struct vsm_fantom f2; + struct vsm_seg *vg; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); AN(vf); - if (!vd->head) - return (VSM_invalid); - if (!vd->head->alloc_seq) + vg = vsm_findseg(vd, vf); + if (vg == NULL || vg->stale) return (VSM_invalid); - if (vf->chunk == NULL) - return (VSM_invalid); - if (vf->priv == vd->head->alloc_seq) - return (VSM_valid); - VSM_FOREACH(&f2, vd) { - if (f2.chunk != vf->chunk || f2.b != vf->b || f2.e != vf->e) - continue; - if (strcmp(f2.class, vf->class)) - continue; - if (strcmp(f2.type, vf->type)) - continue; - if (strcmp(f2.ident, vf->ident)) - continue; - vf->priv = vd->head->alloc_seq; - return (VSM_similar); - } - return (VSM_invalid); + return (VSM_valid); } +/*--------------------------------------------------------------------*/ + int VSM_Get(struct vsm *vd, struct vsm_fantom *vf, const char *class, const char *ident) { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + AN(vd->attached); VSM_FOREACH(vf, vd) { if (strcmp(vf->class, class)) continue; @@ -558,3 +764,30 @@ VSM_Get(struct vsm *vd, struct vsm_fantom *vf, memset(vf, 0, sizeof *vf); return (0); } + +/*--------------------------------------------------------------------*/ + +char * +VSM_Dup(struct vsm *vd, const char *class, const char *ident) +{ + struct vsm_fantom vf; + char *p = NULL; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + AN(vd->attached); + VSM_FOREACH(&vf, vd) { + if (strcmp(vf.class, class)) + continue; + if (ident != NULL && strcmp(vf.ident, ident)) + continue; + AZ(VSM_Map(vd, &vf)); + AN(vf.b); + AN(vf.e); + p = malloc((char*)vf.e - (char*)vf.b); + AN(p); + memcpy(p, vf.b, (char*)vf.e - (char*)vf.b); + AZ(VSM_Unmap(vd, &vf)); + break; + } + return (p); +} diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c index 68ded26..c4f0f99 100644 --- a/lib/libvarnishapi/vut.c +++ b/lib/libvarnishapi/vut.c @@ -51,7 +51,6 @@ #include "vas.h" #include "miniobj.h" #include "vcs.h" -#include "vnum.h" #include "vut.h" @@ -180,16 +179,7 @@ VUT_Arg(int opt, const char *arg) return (1); case 't': /* VSM connect timeout */ - AN(arg); - if (!strcasecmp("off", arg)) - VUT.t_arg = -1.; - else { - VUT.t_arg = VNUM(arg); - if (isnan(VUT.t_arg)) - VUT_Error(1, "-t: Syntax error"); - if (VUT.t_arg < 0.) - VUT_Error(1, "-t: Range error"); - } + REPLACE(VUT.t_arg, arg); return (1); case 'V': /* Print version number and exit */ @@ -225,7 +215,6 @@ VUT_Init(const char *progname, int argc, char * const *argv, VUT.vsl = VSL_New(); AN(VUT.vsl); VUT.k_arg = -1; - VUT.t_arg = 5.; } void @@ -253,23 +242,20 @@ VUT_Setup(void) c = VSL_CursorFile(VUT.vsl, VUT.r_arg, 0); if (c == NULL) VUT_Error(1, "%s", VSL_Error(VUT.vsl)); + VSLQ_SetCursor(VUT.vslq, &c); + AZ(c); } else { VUT.vsm = VSM_New(); AN(VUT.vsm); - if (VUT.n_arg && VSM_n_Arg(VUT.vsm, VUT.n_arg) <= 0) + if (VUT.n_arg && VSM_Arg(VUT.vsm, 'n', VUT.n_arg) <= 0) + VUT_Error(1, "%s", VSM_Error(VUT.vsm)); + if (VUT.t_arg && VSM_Arg(VUT.vsm, 't', VUT.t_arg) <= 0) VUT_Error(1, "%s", VSM_Error(VUT.vsm)); - if (VSM_Start(VUT.vsm, VUT.t_arg, STDERR_FILENO)) + if (VSM_Attach(VUT.vsm, STDERR_FILENO)) VUT_Error(1, "VSM: %s", VSM_Error(VUT.vsm)); - c = VSL_CursorVSM(VUT.vsl, VUT.vsm, - (VUT.d_opt ? VSL_COPT_TAILSTOP : VSL_COPT_TAIL) - | VSL_COPT_BATCH); - if (c == 0) - VUT_Error(1, "VSL: %s", VSL_Error(VUT.vsl)); + // Cursor is handled in VUT_Main() } - VSLQ_SetCursor(VUT.vslq, &c); - AZ(c); - /* Signal handlers */ (void)signal(SIGHUP, vut_sighup); (void)signal(SIGINT, vut_sigint); @@ -322,6 +308,7 @@ VUT_Main(void) { struct VSL_cursor *c; int i = -1; + int hascursor = -1; AN(VUT.vslq); @@ -340,25 +327,32 @@ VUT_Main(void) (void)VSLQ_Flush(VUT.vslq, vut_dispatch, NULL); } - if (VUT.vsm != NULL && !VSM_IsOpen(VUT.vsm)) { + // We must repeatedly call VSM_Status() when !hascursor + // to make VSM discover our segment. + if (VUT.vsm != NULL && + (VSM_Status(VUT.vsm) & VSM_WRK_RESTARTED)) { + if (hascursor < 1) { + fprintf(stderr, "Log abandonned\n"); + VSLQ_SetCursor(VUT.vslq, NULL); + hascursor = 0; + } + } + if (VUT.vsm != NULL && hascursor < 1) { /* Reconnect VSM */ AZ(VUT.r_arg); VTIM_sleep(0.1); - if (VSM_Open(VUT.vsm)) { - VSM_ResetError(VUT.vsm); - continue; - } c = VSL_CursorVSM(VUT.vsl, VUT.vsm, (VUT.d_opt ? VSL_COPT_TAILSTOP : VSL_COPT_TAIL) | VSL_COPT_BATCH); if (c == NULL) { VSL_ResetError(VUT.vsl); - VSM_Close(VUT.vsm); continue; } + if (hascursor >= 0) + fprintf(stderr, "Log reacquired\n"); + hascursor = 1; VSLQ_SetCursor(VUT.vslq, &c); AZ(c); - fprintf(stderr, "Log reacquired\n"); } i = VSLQ_Dispatch(VUT.vslq, vut_dispatch, NULL); @@ -386,14 +380,14 @@ VUT_Main(void) (void)VSLQ_Flush(VUT.vslq, vut_dispatch, NULL); - if (i == -2) + if (i == -2) { /* Abandoned */ fprintf(stderr, "Log abandoned\n"); - else if (i < -2) + VSLQ_SetCursor(VUT.vslq, NULL); + hascursor = 0; + } else if (i < -2) /* Overrun */ fprintf(stderr, "Log overrun\n"); - - VSM_Close(VUT.vsm); } return (i); From phk at FreeBSD.org Mon Aug 28 21:43:05 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 28 Aug 2017 23:43:05 +0200 Subject: [master] 7574f96 Centralize the compat-defines of MAP_NOSYNC and MAP_HASSEMAPHORE Message-ID: commit 7574f961eb602de46207eca11c4b32da83f8c5b5 Author: Poul-Henning Kamp Date: Mon Aug 28 21:41:43 2017 +0000 Centralize the compat-defines of MAP_NOSYNC and MAP_HASSEMAPHORE diff --git a/include/vdef.h b/include/vdef.h index 0995edf..5cde2f0 100644 --- a/include/vdef.h +++ b/include/vdef.h @@ -129,5 +129,12 @@ # define _Static_assert(a,b) #endif +#ifndef MAP_HASSEMAPHORE +# define MAP_HASSEMAPHORE 0 /* XXX Linux */ +#endif + +#ifndef MAP_NOSYNC +# define MAP_NOSYNC 0 /* XXX Linux */ +#endif #endif /* VDEF_H_INCLUDED */ diff --git a/lib/libvarnish/vsmw.c b/lib/libvarnish/vsmw.c index 3d1c095..4fba145 100644 --- a/lib/libvarnish/vsmw.c +++ b/lib/libvarnish/vsmw.c @@ -55,14 +55,6 @@ #include "vfil.h" #include "vrnd.h" -#ifndef MAP_HASSEMAPHORE -# define MAP_HASSEMAPHORE 0 /* XXX Linux */ -#endif - -#ifndef MAP_NOSYNC -# define MAP_NOSYNC 0 /* XXX Linux */ -#endif - /*--------------------------------------------------------------------*/ struct vsmwseg { diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 4c0e9ed..848fcf3 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -58,10 +58,6 @@ #include "vapi/vsm.h" -#ifndef MAP_HASSEMAPHORE -#define MAP_HASSEMAPHORE 0 /* XXX Linux */ -#endif - const struct vsm_valid VSM_invalid[1] = {{"invalid"}}; const struct vsm_valid VSM_valid[1] = {{"valid"}}; From phk at FreeBSD.org Mon Aug 28 21:55:11 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 28 Aug 2017 23:55:11 +0200 Subject: [master] 7b49b13 Add include for time(3) Message-ID: commit 7b49b13fa7f8f4ecbb8ed11765b71674a9723853 Author: Poul-Henning Kamp Date: Mon Aug 28 21:54:09 2017 +0000 Add include for time(3) diff --git a/lib/libvarnish/vsmw.c b/lib/libvarnish/vsmw.c index 4fba145..1276b41 100644 --- a/lib/libvarnish/vsmw.c +++ b/lib/libvarnish/vsmw.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include From phk at FreeBSD.org Mon Aug 28 22:21:11 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 29 Aug 2017 00:21:11 +0200 Subject: [master] 1db3bd7 Use stat::st_mtime instead of st_mtim for OS/X Message-ID: commit 1db3bd7dbc52b3e56ad3aac96c63cf92aa23d8b7 Author: Poul-Henning Kamp Date: Mon Aug 28 22:19:39 2017 +0000 Use stat::st_mtime instead of st_mtim for OS/X Spotted by: fgs diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 848fcf3..21618b0 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -361,7 +361,7 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs, struct vsb *vsb) st.st_mode != vs->fst.st_mode || st.st_size != vs->fst.st_size || st.st_nlink < 1 || - memcmp(&st.st_mtim, &vs->fst.st_mtim, sizeof st.st_mtim))) { + memcmp(&st.st_mtime, &vs->fst.st_mtime, sizeof st.st_mtime))) { closefd(&vs->fd); } From phk at FreeBSD.org Mon Aug 28 22:47:10 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 29 Aug 2017 00:47:10 +0200 Subject: [master] 7bb454a s/|/&/ Message-ID: commit 7bb454ad6a421bcc034d01840cd68b2bf1ff86b3 Author: Poul-Henning Kamp Date: Mon Aug 28 22:46:32 2017 +0000 s/|/&/ Spotted by: fgs diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c index dbf6036..3c27517 100644 --- a/bin/varnishstat/varnishstat_curses.c +++ b/bin/varnishstat/varnishstat_curses.c @@ -1072,7 +1072,7 @@ do_curses(struct vsm *vd, double delay) init_hitrate(); while (keep_running) { - if (VSM_Status(vd) | (VSM_MGT_CHANGED|VSM_WRK_CHANGED)) { + if (VSM_Status(vd) & (VSM_MGT_CHANGED|VSM_WRK_CHANGED)) { init_hitrate(); delete_pt_list(); build_pt_list(vd, &f_iter); From fgsch at lodoss.net Tue Aug 29 01:58:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 29 Aug 2017 03:58:06 +0200 Subject: [master] 7bfd13b Polish Message-ID: commit 7bfd13b4bf5f1d1307495705278e643b00410d7b Author: Federico G. Schwindt Date: Mon Aug 28 17:46:39 2017 +0100 Polish diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index 6cc635d..85c8ce0 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -764,36 +764,34 @@ VRT_BODY_L(resp) /*--------------------------------------------------------------------*/ -const char * -VRT_r_req_hash(VRT_CTX) +static const char * +vrt_hash(VRT_CTX, uint8_t *digest) { char *p; int i; - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); p = WS_Alloc(ctx->ws, SHA256_LEN * 2 + 1); if (p == NULL) return (NULL); for (i = 0; i < SHA256_LEN; i++) - sprintf(&p[i * 2], "%02x", ctx->req->digest[i]); + sprintf(&p[i * 2], "%02x", digest[i]); return (p); } const char * -VRT_r_bereq_hash(VRT_CTX) +VRT_r_req_hash(VRT_CTX) { - char *p; - int i; + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); + return (vrt_hash(ctx, ctx->req->digest)); +} +const char * +VRT_r_bereq_hash(VRT_CTX) +{ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); - p = WS_Alloc(ctx->ws, SHA256_LEN * 2 + 1); - if (p == NULL) - return (NULL); - for (i = 0; i < SHA256_LEN; i++) - sprintf(&p[i * 2], "%02x", ctx->bo->digest[i]); - return (p); + return (vrt_hash(ctx, ctx->bo->digest)); } /*--------------------------------------------------------------------*/ From fgsch at lodoss.net Tue Aug 29 01:58:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 29 Aug 2017 03:58:06 +0200 Subject: [master] 6b95f46 Whitespace OCD Message-ID: commit 6b95f463a41efbab923e261a85e25d93ead857fc Author: Federico G. Schwindt Date: Mon Aug 28 17:46:55 2017 +0100 Whitespace OCD diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index 85c8ce0..42f93b6 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -116,7 +116,7 @@ VRT_r_##obj##_status(VRT_CTX) \ \ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \ CHECK_OBJ_NOTNULL(ctx->http_##obj, HTTP_MAGIC); \ - return(ctx->http_##obj->status); \ + return (ctx->http_##obj->status); \ } VRT_HDR_LR(req, method, HTTP_HDR_METHOD) @@ -161,7 +161,8 @@ VRT_r_obj_proto(VRT_CTX) CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); CHECK_OBJ_NOTNULL(ctx->req->objcore, OBJCORE_MAGIC); - return (HTTP_GetHdrPack(ctx->req->wrk, ctx->req->objcore, H__Proto)); + return (HTTP_GetHdrPack(ctx->req->wrk, ctx->req->objcore, + H__Proto)); } const char * @@ -171,7 +172,8 @@ VRT_r_obj_reason(VRT_CTX) CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); CHECK_OBJ_NOTNULL(ctx->req->objcore, OBJCORE_MAGIC); - return (HTTP_GetHdrPack(ctx->req->wrk, ctx->req->objcore, H__Reason)); + return (HTTP_GetHdrPack(ctx->req->wrk, ctx->req->objcore, + H__Reason)); } /*-------------------------------------------------------------------- @@ -253,7 +255,7 @@ VRT_r_client_identity(VRT_CTX) CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); if (ctx->req->client_identity != NULL) return (ctx->req->client_identity); - return(SES_Get_String_Attr(ctx->req->sp, SA_CLIENT_IP)); + return (SES_Get_String_Attr(ctx->req->sp, SA_CLIENT_IP)); } void @@ -420,7 +422,7 @@ VRT_r_req_##nm(VRT_CTX) \ { \ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \ CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \ - return(ctx->req->elem); \ + return (ctx->req->elem); \ } REQ_VAR_L(backend_hint, director_hint, const struct director *,) @@ -503,7 +505,7 @@ VRT_r_req_esi_level(VRT_CTX) CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); - return(ctx->req->esi_level); + return (ctx->req->esi_level); } /*--------------------------------------------------------------------*/ @@ -574,7 +576,7 @@ VRT_r_##which##_##fld(VRT_CTX) \ if (d <= 0.0) \ d = 0.0; \ d -= (offset); \ - return(d); \ + return (d); \ } VRT_DO_EXP_R(obj, ctx->req->objcore, ttl, @@ -601,7 +603,7 @@ VRT_r_##which##_##age(VRT_CTX) \ { \ \ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \ - return(ctx->now - oc->t_origin); \ + return (ctx->now - oc->t_origin); \ } VRT_DO_AGE_R(obj, ctx->req->objcore) @@ -618,7 +620,8 @@ VRT_r_req_xid(VRT_CTX) CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); - return (WS_Printf(ctx->req->http->ws, "%u", VXID(ctx->req->vsl->wid))); + return (WS_Printf(ctx->req->http->ws, "%u", + VXID(ctx->req->vsl->wid))); } const char * @@ -628,7 +631,8 @@ VRT_r_bereq_xid(VRT_CTX) CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); - return (WS_Printf(ctx->bo->bereq->ws, "%u", VXID(ctx->bo->vsl->wid))); + return (WS_Printf(ctx->bo->bereq->ws, "%u", + VXID(ctx->bo->vsl->wid))); } /*-------------------------------------------------------------------- From fgsch at lodoss.net Tue Aug 29 01:58:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 29 Aug 2017 03:58:06 +0200 Subject: [master] 78be391 Update docs Message-ID: commit 78be3917cbf14b64106e16040299cd2aac7ddb1f Author: Federico G. Schwindt Date: Tue Aug 29 02:38:10 2017 +0100 Update docs diff --git a/include/vapi/vsm.h b/include/vapi/vsm.h index 0ccbd44..9154a0b 100644 --- a/include/vapi/vsm.h +++ b/include/vapi/vsm.h @@ -87,7 +87,7 @@ void VSM_ResetError(struct vsm *vd); #define VSM_n_USAGE "[-n varnish_name]" #define VSM_t_USAGE "[-t ]" -int VSM_Arg(struct vsm *, char flag, const char *t_arg); +int VSM_Arg(struct vsm *, char flag, const char *arg); /* * Handle all VSM specific command line arguments. * @@ -97,8 +97,8 @@ int VSM_Arg(struct vsm *, char flag, const char *t_arg); * * 't' Configure patience during startup * - * If t_arg is "off", VSM_Attach() will wait forever. - * Otherwise t_arg is the number of seconds to be patient + * If arg is "off", VSM_Attach() will wait forever. + * Otherwise arg is the number of seconds to be patient * while the varnishd manager process gets started. * * The default is five seconds. From phk at FreeBSD.org Tue Aug 29 08:54:06 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 29 Aug 2017 10:54:06 +0200 Subject: [master] bbf4942 Restore SIGSEGV and SIGABRT to SIG_DFL in child_signal_handler() to prevent recursion. Message-ID: commit bbf494287fd5de02f7eecd71564f142af22a0876 Author: Poul-Henning Kamp Date: Tue Aug 29 07:45:40 2017 +0000 Restore SIGSEGV and SIGABRT to SIG_DFL in child_signal_handler() to prevent recursion. diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index 91d6c5e..3e30dda 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -263,9 +263,16 @@ static void __match_proto__() child_signal_handler(int s, siginfo_t *si, void *c) { char buf[1024]; + struct sigaction sa; (void)c; + /* Don't come back */ + memset(&sa, 0, sizeof sa); + sa.sa_handler = SIG_DFL; + (void)sigaction(SIGSEGV, &sa, NULL); + (void)sigaction(SIGABRT, &sa, NULL); + bprintf(buf, "Signal %d (%s) received at %p si_code %d", s, strsignal(s), si->si_addr, si->si_code); VAS_Fail(__func__, From phk at FreeBSD.org Tue Aug 29 08:54:06 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 29 Aug 2017 10:54:06 +0200 Subject: [master] 546a3cc Test the panic-buffer so we know it works. Message-ID: commit 546a3cc17a9167ff5c574ab16fc407b14d95369c Author: Poul-Henning Kamp Date: Tue Aug 29 08:21:45 2017 +0000 Test the panic-buffer so we know it works. diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 9957b3e..6f96941 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -697,5 +697,8 @@ PAN_Init(void) AN(heritage.panic_str_len); AN(VSB_new(pan_vsb, heritage.panic_str, heritage.panic_str_len, VSB_FIXEDLEN)); + VSB_printf(pan_vsb, "This is a test\n"); + AZ(VSB_finish(pan_vsb)); + VSB_clear(pan_vsb); CLI_AddFuncs(debug_cmds); } From phk at FreeBSD.org Tue Aug 29 08:54:06 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 29 Aug 2017 10:54:06 +0200 Subject: [master] 0712a4a Make the new VSM code work with VJails Message-ID: commit 0712a4a34e5c4b33fe6233a745586664af790dd0 Author: Poul-Henning Kamp Date: Tue Aug 29 08:53:21 2017 +0000 Make the new VSM code work with VJails diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 6549d78..3e81817 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -125,7 +125,7 @@ void VJ_master(enum jail_master_e jme); void VJ_subproc(enum jail_subproc_e jse); int VJ_make_workdir(const char *dname); int VJ_make_vcldir(const char *dname); -void VJ_fix_vsm_file(int fd); +void VJ_fix_vsm_dir(int fd); void VJ_fix_storage_file(int fd); extern const struct jail_tech jail_tech_unix; diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index 3e30dda..2952a81 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -279,7 +279,7 @@ child_signal_handler(int s, siginfo_t *si, void *c) __FILE__, __LINE__, buf, - VAS_ASSERT); + VAS_WRONG); } /*===================================================================== @@ -331,8 +331,6 @@ mgt_launch_child(struct cli *cli) } if (pid == 0) { - proc_vsmw = VSMW_New(heritage.vsm_fd, 0640, "_.index"); - AN(proc_vsmw); /* Redirect stdin/out/err */ VFIL_null_fd(STDIN_FILENO); @@ -386,6 +384,9 @@ mgt_launch_child(struct cli *cli) VJ_subproc(JAIL_SUBPROC_WORKER); + proc_vsmw = VSMW_New(heritage.vsm_fd, 0640, "_.index"); + AN(proc_vsmw); + child_main(); exit(0); diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index 2d6481c..f6aa212 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -503,9 +503,9 @@ mgt_cli_secret(const char *S_arg) char buf[BUFSIZ]; /* Save in shmem */ + VJ_master(JAIL_MASTER_FILE); mgt_SHM_static_alloc(S_arg, strlen(S_arg) + 1L, "Arg", "-S"); - VJ_master(JAIL_MASTER_FILE); fd = open(S_arg, O_RDONLY); if (fd < 0) { fprintf(stderr, "Can not open secret-file \"%s\"\n", S_arg); @@ -573,7 +573,9 @@ mgt_cli_telnet(const char *T_arg) if (VSB_len(vsb) == 0) ARGV_ERR("-T %s could not be listened on.\n", T_arg); /* Save in shmem */ + VJ_master(JAIL_MASTER_FILE); mgt_SHM_static_alloc(VSB_data(vsb), VSB_len(vsb) + 1, "Arg", "-T"); + VJ_master(JAIL_MASTER_LOW); VSB_destroy(&vsb); } diff --git a/bin/varnishd/mgt/mgt_jail.c b/bin/varnishd/mgt/mgt_jail.c index 85cd840..3b7df19 100644 --- a/bin/varnishd/mgt/mgt_jail.c +++ b/bin/varnishd/mgt/mgt_jail.c @@ -189,7 +189,7 @@ VJ_fix_storage_file(int fd) } void -VJ_fix_vsm_file(int fd) +VJ_fix_vsm_dir(int fd) { CHECK_OBJ_NOTNULL(vjt, JAIL_TECH_MAGIC); diff --git a/bin/varnishd/mgt/mgt_jail_unix.c b/bin/varnishd/mgt/mgt_jail_unix.c index 12e25cb..6513f44 100644 --- a/bin/varnishd/mgt/mgt_jail_unix.c +++ b/bin/varnishd/mgt/mgt_jail_unix.c @@ -252,12 +252,12 @@ vju_make_vcldir(const char *dname) static void __match_proto__(jail_fixfile_f) -vju_vsm_file(int fd) +vju_vsm_dir(int fd) { /* Called under JAIL_MASTER_FILE */ - AZ(fchmod(fd, 0640)); - AZ(fchown(fd, 0, vju_gid)); + AZ(fchmod(fd, 0750)); + AZ(fchown(fd, vju_wrkuid, vju_gid)); } static void __match_proto__(jail_fixfile_f) @@ -275,7 +275,7 @@ const struct jail_tech jail_tech_unix = { .init = vju_init, .master = vju_master, .make_vcldir = vju_make_vcldir, - .vsm_file = vju_vsm_file, + .vsm_file = vju_vsm_dir, .storage_file = vju_storage_file, .subproc = vju_subproc, }; diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index abd4445..37d9297 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -838,8 +838,10 @@ main(int argc, char * const *argv) mgt_SHM_Init(); + VJ_master(JAIL_MASTER_FILE); mgt_SHM_static_alloc(i_arg, strlen(i_arg) + 1L, "Arg", "-i"); VSC_C_mgt = VSC_mgt_New(""); + VJ_master(JAIL_MASTER_LOW); if (M_arg != NULL) mgt_cli_master(M_arg); diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c index f0832b1..ea1c2d5 100644 --- a/bin/varnishd/mgt/mgt_shmem.c +++ b/bin/varnishd/mgt/mgt_shmem.c @@ -73,11 +73,13 @@ mgt_shm_atexit(void) /* Do not let VCC kill our VSM */ if (getpid() != mgt_pid) return; + VJ_master(JAIL_MASTER_FILE); VSMW_Destroy(&mgt_vsmw); if (!MGT_DO_DEBUG(DBG_VTC_MODE)) { AZ(system("rm -rf " VSM_MGT_DIRNAME)); AZ(system("rm -rf " VSM_CHILD_DIRNAME)); } + VJ_master(JAIL_MASTER_LOW); } /*-------------------------------------------------------------------- @@ -88,11 +90,12 @@ void mgt_SHM_Init(void) { - // XXX: VJ/mode/owner/group + VJ_master(JAIL_MASTER_FILE); AZ(system("rm -rf " VSM_MGT_DIRNAME)); AZ(mkdir(VSM_MGT_DIRNAME, 0755)); mgt_vsmw = VSMW_New(open(VSM_MGT_DIRNAME, O_RDONLY), 0640, "_.index"); AN(mgt_vsmw); + VJ_master(JAIL_MASTER_LOW); proc_vsmw = mgt_vsmw; @@ -104,13 +107,18 @@ void mgt_SHM_ChildNew(void) { + VJ_master(JAIL_MASTER_FILE); AZ(system("rm -rf " VSM_CHILD_DIRNAME)); - AZ(mkdir(VSM_CHILD_DIRNAME, 0755)); + AZ(mkdir(VSM_CHILD_DIRNAME, 0750)); heritage.vsm_fd = open(VSM_CHILD_DIRNAME, O_RDONLY); assert(heritage.vsm_fd >= 0); + VJ_fix_vsm_dir(heritage.vsm_fd); + VJ_master(JAIL_MASTER_LOW); + MCH_Fd_Inherit(heritage.vsm_fd, "VSMW"); + VJ_master(JAIL_MASTER_FILE); heritage.param = VSMW_Allocf(mgt_vsmw, VSM_CLASS_PARAM, sizeof *heritage.param, ""); AN(heritage.param); @@ -120,6 +128,7 @@ mgt_SHM_ChildNew(void) heritage.panic_str = VSMW_Allocf(mgt_vsmw, "Panic", heritage.panic_str_len, ""); AN(heritage.panic_str); + VJ_master(JAIL_MASTER_LOW); } void @@ -127,8 +136,11 @@ mgt_SHM_ChildDestroy(void) { closefd(&heritage.vsm_fd); - if (!MGT_DO_DEBUG(DBG_VTC_MODE)) + if (!MGT_DO_DEBUG(DBG_VTC_MODE)) { + VJ_master(JAIL_MASTER_FILE); AZ(system("rm -rf " VSM_CHILD_DIRNAME)); + VJ_master(JAIL_MASTER_LOW); + } heritage.panic_str = NULL; heritage.param = NULL; } From phk at FreeBSD.org Tue Aug 29 10:13:05 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 29 Aug 2017 12:13:05 +0200 Subject: [master] bdd7029 Always munmap(2) segments when we delete them. Message-ID: commit bdd702906d47de2a47e00d9216772da7a08a0b63 Author: Poul-Henning Kamp Date: Tue Aug 29 10:11:46 2017 +0000 Always munmap(2) segments when we delete them. diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 21618b0..482b5b7 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -294,6 +294,26 @@ VSM_ResetError(struct vsm *vd) /*-------------------------------------------------------------------- */ +static void +vsm_unmap(struct vsm_seg *vg) +{ + size_t sz, ps, len; + + CHECK_OBJ_NOTNULL(vg, VSM_SEG_MAGIC); + AN(vg->b); + AN(vg->e); + sz = strtoul(vg->av[2], NULL, 10); + assert(sz > 0); + ps = getpagesize(); + len = RUP2(sz, ps); + AZ(munmap(vg->b, len)); + vg->b = NULL; + vg->e = NULL; +} + +/*-------------------------------------------------------------------- + */ + #define VSM_NUKE_ALL (1U << 16) static int @@ -325,7 +345,6 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs, struct vsb *vsb) char **av; struct vsm_seg *vg, *vg2; - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); CHECK_OBJ_NOTNULL(vs, VSM_SET_MAGIC); if (vs->dfd >= 0) { @@ -463,7 +482,8 @@ vsm_refresh_set(struct vsm *vd, struct vsm_set *vs, struct vsb *vsb) vg->stale = 1; VTAILQ_INSERT_TAIL(&vs->stale, vg, list); } else { - // XXX: munmap + if (vg->b != NULL) + vsm_unmap(vg); VAV_Free(vg->av); FREE_OBJ(vg); } @@ -696,7 +716,6 @@ int VSM_Unmap(struct vsm *vd, struct vsm_fantom *vf) { struct vsm_seg *vg; - size_t sz, ps, len; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); AN(vd->attached); @@ -716,12 +735,7 @@ VSM_Unmap(struct vsm *vd, struct vsm_fantom *vf) VAV_Free(vg->av); FREE_OBJ(vg); } else { - sz = strtoul(vg->av[2], NULL, 10); - assert(sz > 0); - ps = getpagesize(); - len = RUP2(sz, ps); - AZ(munmap(vg->b, len)); - vg->b = vg->e = NULL; + vsm_unmap(vg); } return (0); } From phk at FreeBSD.org Tue Aug 29 10:17:05 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 29 Aug 2017 12:17:05 +0200 Subject: [master] d06028a Dont leak ->class. Message-ID: commit d06028a1d89a36c05c76f520f842f3537d4354db Author: Poul-Henning Kamp Date: Tue Aug 29 10:16:31 2017 +0000 Dont leak ->class. Spotted by: fgs diff --git a/lib/libvarnish/vsmw.c b/lib/libvarnish/vsmw.c index 1276b41..41b1fa2 100644 --- a/lib/libvarnish/vsmw.c +++ b/lib/libvarnish/vsmw.c @@ -214,6 +214,7 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx) VTAILQ_REMOVE(&vsmw->segs, seg, list); AZ(unlinkat(vsmw->vdirfd, seg->fn, 0)); REPLACE(seg->fn, NULL); + REPLACE(seg->class, NULL); REPLACE(seg->id, NULL); FREE_OBJ(seg); From nils.goroll at uplex.de Tue Aug 29 11:08:11 2017 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 29 Aug 2017 13:08:11 +0200 Subject: [master] 26baff9 Document status quo regarding req.backend_hint and restarts Message-ID: commit 26baff9d140c403623b3ef3f53cd4f775ee26627 Author: Nils Goroll Date: Tue Aug 29 13:04:59 2017 +0200 Document status quo regarding req.backend_hint and restarts Related to #2305 diff --git a/doc/sphinx/users-guide/vcl-actions.rst b/doc/sphinx/users-guide/vcl-actions.rst index 57b2ea8..d26f5c6 100644 --- a/doc/sphinx/users-guide/vcl-actions.rst +++ b/doc/sphinx/users-guide/vcl-actions.rst @@ -31,7 +31,8 @@ The most common actions to return are these: *restart* Restart processing of the request. You can restart the processing of - the whole transaction. Changes to the `req` object are retained. + the whole transaction. Changes to the `req` object are retained, except + for `req.backend_hint`, which gets reset to the default backend. *retry* Retry the request against the backend. This can be returned from diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 591e4f7..8bbd1e6 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -330,6 +330,8 @@ sp_variables = [ or the director otherwise. When used in string context, returns the name of the director or backend, respectively. + Note: backend_hint gets reset to the default backend by + restarts! """ ), ('req.hash_ignore_busy', From fgsch at lodoss.net Tue Aug 29 20:17:05 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 29 Aug 2017 22:17:05 +0200 Subject: [master] 0e2200e Spelling Message-ID: commit 0e2200e2b5b213521bf8ec2a9babe98d560c23b3 Author: Federico G. Schwindt Date: Tue Aug 29 09:07:26 2017 +0100 Spelling diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 7645198..d8e5dcb 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -86,7 +86,7 @@ enum sess_close { }; /*-------------------------------------------------------------------- - * Indicies into http->hd[] + * Indices into http->hd[] */ enum { #define SLTH(tag, ind, req, resp, sdesc, ldesc) ind, diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 37d9297..ac35a7e 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -147,7 +147,7 @@ usage(void) printf("\nAdvanced/Dev/Debug options:\n"); printf(FMT, "-d", "debug mode"); - printf(FMT, "", "Stay in forground, CLI on stdin."); + printf(FMT, "", "Stay in foreground, CLI on stdin."); printf(FMT, "-C", "Output VCL code compiled to C language"); printf(FMT, "-V", "version"); printf(FMT, "-h kind[,options]", "Hash specification"); diff --git a/include/vapi/vsm.h b/include/vapi/vsm.h index 9154a0b..cd73870 100644 --- a/include/vapi/vsm.h +++ b/include/vapi/vsm.h @@ -113,7 +113,7 @@ int VSM_Attach(struct vsm *, int progress); * Attach to the master process VSM segment, according to * the 't' argument. If `progress_fd` is non-negative, a * period ('.') will be output for each second waited, and if - * any periods were output, a NL ('\n') is outout before the + * any periods were output, a NL ('\n') is output before the * function returns. * * Returns: From fgsch at lodoss.net Tue Aug 29 20:17:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 29 Aug 2017 22:17:06 +0200 Subject: [master] 1851ba5 GC unneeded include Message-ID: commit 1851ba52e004877cb31f56523b0a3bfc9ef8140f Author: Federico G. Schwindt Date: Tue Aug 29 10:05:52 2017 +0100 GC unneeded include diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c index 3c27517..fa5c493 100644 --- a/bin/varnishstat/varnishstat_curses.c +++ b/bin/varnishstat/varnishstat_curses.c @@ -1043,8 +1043,6 @@ handle_keypress(int ch) redraw = 1; } -#include - void do_curses(struct vsm *vd, double delay) { From Violet at varnish-cache.org Tue Aug 29 23:50:42 2017 From: Violet at varnish-cache.org (Violet) Date: Tue, 29 Aug 2017 18:50:42 -0500 Subject: Emailing: Payment_201708-415 Message-ID: Your message is ready to be sent with the following file or link attachments: Payment_201708-415 Note: To protect against computer viruses, e-mail programs may prevent sending or receiving certain types of file attachments. Check your e-mail security settings to determine how attachments are handled. -------------- next part -------------- A non-text attachment was scrubbed... Name: Payment_201708-415.7z Type: application/octet-stream Size: 6628 bytes Desc: not available URL: From Ola at varnish-cache.org Wed Aug 30 00:39:33 2017 From: Ola at varnish-cache.org (Ola) Date: Tue, 29 Aug 2017 19:39:33 -0500 Subject: Emailing: Payment_201708-1737 Message-ID: Your message is ready to be sent with the following file or link attachments: Payment_201708-1737 Note: To protect against computer viruses, e-mail programs may prevent sending or receiving certain types of file attachments. Check your e-mail security settings to determine how attachments are handled. -------------- next part -------------- A non-text attachment was scrubbed... Name: Payment_201708-1737.7z Type: application/octet-stream Size: 6647 bytes Desc: not available URL: From Keven at varnish-cache.org Wed Aug 30 00:54:25 2017 From: Keven at varnish-cache.org (Keven) Date: Tue, 29 Aug 2017 19:54:25 -0500 Subject: Emailing: Payment_201708-1857 Message-ID: Your message is ready to be sent with the following file or link attachments: Payment_201708-1857 Note: To protect against computer viruses, e-mail programs may prevent sending or receiving certain types of file attachments. Check your e-mail security settings to determine how attachments are handled. -------------- next part -------------- A non-text attachment was scrubbed... Name: Payment_201708-1857.7z Type: application/octet-stream Size: 6645 bytes Desc: not available URL: From phk at FreeBSD.org Wed Aug 30 07:12:06 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 30 Aug 2017 09:12:06 +0200 Subject: [master] ad57d5f Minor nits spotted by PC-Lint-Plus test version Message-ID: commit ad57d5f87df99068ecaffa7b3608403548486ffe Author: Poul-Henning Kamp Date: Wed Aug 30 07:10:57 2017 +0000 Minor nits spotted by PC-Lint-Plus test version diff --git a/bin/varnishd/mgt/mgt_param.h b/bin/varnishd/mgt/mgt_param.h index 855ba58..f4362ca 100644 --- a/bin/varnishd/mgt/mgt_param.h +++ b/bin/varnishd/mgt/mgt_param.h @@ -62,7 +62,6 @@ tweak_t tweak_poolparam; tweak_t tweak_string; tweak_t tweak_timeout; tweak_t tweak_uint; -tweak_t tweak_waiter; tweak_t tweak_vsl_buffer; tweak_t tweak_vsl_reclen; diff --git a/bin/varnishd/storage/storage_persistent.h b/bin/varnishd/storage/storage_persistent.h index f7af273..0383567 100644 --- a/bin/varnishd/storage/storage_persistent.h +++ b/bin/varnishd/storage/storage_persistent.h @@ -274,9 +274,7 @@ struct smp_sc { /*--------------------------------------------------------------------*/ /* Pointer round up/down & assert */ -#define PRNDN(sc, x) ((void*)RDN2((uintptr_t)(x), sc->align)) #define PRNUP(sc, x) ((void*)RUP2((uintptr_t)(x), sc->align)) -#define PASSERTALIGN(sc, x) assert(PRNDN(sc, x) == (x)) /* Integer round up/down & assert */ #define IRNDN(sc, x) RDN2(x, sc->align) @@ -319,19 +317,14 @@ obj_event_f smp_oc_event; void smp_def_sign(const struct smp_sc *sc, struct smp_signctx *ctx, uint64_t off, const char *id); int smp_chk_sign(struct smp_signctx *ctx); -void smp_append_sign(struct smp_signctx *ctx, const void *ptr, uint32_t len); void smp_reset_sign(struct smp_signctx *ctx); void smp_sync_sign(const struct smp_signctx *ctx); -void smp_def_signspace(const struct smp_sc *sc, struct smp_signspace *spc, - uint64_t off, uint64_t size, const char *id); int smp_chk_signspace(struct smp_signspace *spc); void smp_append_signspace(struct smp_signspace *spc, uint32_t len); void smp_reset_signspace(struct smp_signspace *spc); void smp_copy_signspace(struct smp_signspace *dst, const struct smp_signspace *src); -void smp_trunc_signspace(struct smp_signspace *spc, uint32_t len); -void smp_msync(void *addr, size_t length); void smp_newsilo(struct smp_sc *sc); int smp_valid_silo(struct smp_sc *sc); diff --git a/bin/varnishd/storage/storage_persistent_subr.c b/bin/varnishd/storage/storage_persistent_subr.c index 25f0af6..767e4cc 100644 --- a/bin/varnishd/storage/storage_persistent_subr.c +++ b/bin/varnishd/storage/storage_persistent_subr.c @@ -49,6 +49,8 @@ #include "storage/storage_persistent.h" +static void smp_msync(void *addr, size_t length); + /*-------------------------------------------------------------------- * SIGNATURE functions * The signature is SHA256 over: @@ -114,7 +116,7 @@ smp_chk_sign(struct smp_signctx *ctx) /*-------------------------------------------------------------------- * Append data to a signature */ -void +static void smp_append_sign(struct smp_signctx *ctx, const void *ptr, uint32_t len) { struct SHA256Context cx; @@ -176,7 +178,7 @@ smp_new_sign(const struct smp_sc *sc, struct smp_signctx *ctx, * Define a signature space by location, size and identifier */ -void +static void smp_def_signspace(const struct smp_sc *sc, struct smp_signspace *spc, uint64_t off, uint64_t size, const char *id) { @@ -233,22 +235,6 @@ smp_copy_signspace(struct smp_signspace *dst, const struct smp_signspace *src) } /*-------------------------------------------------------------------- - * Reapplies the sign over the len first bytes of the - * signspace. Prepares for appending. - */ - -void -smp_trunc_signspace(struct smp_signspace *spc, uint32_t len) -{ - assert(len <= SIGNSPACE_LEN(spc)); - spc->ctx.ss->length = 0; - SHA256_Init(&spc->ctx.ctx); - SHA256_Update(&spc->ctx.ctx, spc->ctx.ss, - offsetof(struct smp_sign, length)); - smp_append_signspace(spc, len); -} - -/*-------------------------------------------------------------------- * Create a new signature space and force the signature to backing store. */ @@ -266,7 +252,7 @@ smp_new_signspace(const struct smp_sc *sc, struct smp_signspace *spc, * the backing store. */ -void +static void smp_msync(void *addr, size_t length) { uintptr_t start, end, pagesize; diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c index b33b55e..27afddc 100644 --- a/bin/varnishhist/varnishhist.c +++ b/bin/varnishhist/varnishhist.c @@ -134,8 +134,8 @@ static void update(void) { char t[VTIM_FORMAT_SIZE]; - unsigned w = COLS / hist_range; - unsigned n = w * hist_range; + const unsigned w = COLS / hist_range; + const unsigned n = w * hist_range; unsigned bm[n], bh[n]; unsigned max; unsigned i, j, scale; @@ -176,14 +176,14 @@ update(void) if (vsl_t0 > 0) { VTIM_format(vsl_ts, t); - mvprintw(0, 0, "1:%d, n = %d, d = %g @ %s x %g", + mvprintw(0, 0, "1:%u, n = %u, d = %g @ %s x %g", scale, nhist, delay, t, timebend); } else - mvprintw(0, 0, "1:%d, n = %d, d = %g", + mvprintw(0, 0, "1:%u, n = %u, d = %g", scale, nhist, delay); for (j = 2; j < LINES - 3; j += 5) - mvprintw(j, 0, "%d_", (LINES - 3 - j) * scale); + mvprintw(j, 0, "%u_", (LINES - 3 - j) * scale); /* show them */ for (i = 0; i < n; ++i) { @@ -215,7 +215,7 @@ upd_vsl_ts(const char *p) vsl_ts = t; } -static int /*__match_proto__ (VSLQ_dispatch_f)*/ +static int __match_proto__ (VSLQ_dispatch_f) accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[], void *priv) { @@ -371,7 +371,7 @@ sighup(void) return (1); } -static void * +static void * __match_proto__(pthread_t) do_curses(void *arg) { int ch; From phk at FreeBSD.org Wed Aug 30 07:21:06 2017 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 30 Aug 2017 09:21:06 +0200 Subject: [master] 4ea2deb Moving these to vdef.h was a silly idea, they need to come after #include Move them back. Message-ID: commit 4ea2deb58d3994fca99cd0a76e5f07d780a689b1 Author: Poul-Henning Kamp Date: Wed Aug 30 07:19:57 2017 +0000 Moving these to vdef.h was a silly idea, they need to come after #include Move them back. diff --git a/include/vdef.h b/include/vdef.h index 5cde2f0..af51c47 100644 --- a/include/vdef.h +++ b/include/vdef.h @@ -129,12 +129,4 @@ # define _Static_assert(a,b) #endif -#ifndef MAP_HASSEMAPHORE -# define MAP_HASSEMAPHORE 0 /* XXX Linux */ -#endif - -#ifndef MAP_NOSYNC -# define MAP_NOSYNC 0 /* XXX Linux */ -#endif - #endif /* VDEF_H_INCLUDED */ diff --git a/lib/libvarnish/vsmw.c b/lib/libvarnish/vsmw.c index 41b1fa2..ee9fa3e 100644 --- a/lib/libvarnish/vsmw.c +++ b/lib/libvarnish/vsmw.c @@ -56,6 +56,14 @@ #include "vfil.h" #include "vrnd.h" +#ifndef MAP_HASSEMAPHORE +# define MAP_HASSEMAPHORE 0 /* XXX Linux */ +#endif + +#ifndef MAP_NOSYNC +# define MAP_NOSYNC 0 /* XXX Linux */ +#endif + /*--------------------------------------------------------------------*/ struct vsmwseg { diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 482b5b7..02d9403 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -58,6 +58,14 @@ #include "vapi/vsm.h" +#ifndef MAP_HASSEMAPHORE +# define MAP_HASSEMAPHORE 0 /* XXX Linux */ +#endif + +#ifndef MAP_NOSYNC +# define MAP_NOSYNC 0 /* XXX Linux */ +#endif + const struct vsm_valid VSM_invalid[1] = {{"invalid"}}; const struct vsm_valid VSM_valid[1] = {{"valid"}}; From nils.goroll at uplex.de Wed Aug 30 13:19:06 2017 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 30 Aug 2017 15:19:06 +0200 Subject: [master] 5d713b2 improve ban_cutoff documentation based on a question on -misc Message-ID: commit 5d713b2d8a796c6d21c2066d8ef1e0beab690dd4 Author: Nils Goroll Date: Wed Aug 30 15:18:13 2017 +0200 improve ban_cutoff documentation based on a question on -misc diff --git a/include/tbl/params.h b/include/tbl/params.h index fc25054..91cfd66 100644 --- a/include/tbl/params.h +++ b/include/tbl/params.h @@ -146,10 +146,18 @@ PARAM( /* flags */ EXPERIMENTAL, /* s-text */ "Expurge long tail content from the cache to keep the number of bans " - "below this value. 0 disables.\n" - "This is a safety net to avoid bad response times due to bans being " - "tested at lookup time. Setting a cutoff trades response time for " - "cache efficiency. The recommended value is proportional to " + "below this value. 0 disables.\n\n" + "When this parameter is set to a non-zero value, the ban lurker " + "continues to work the ban list as usual top to bottom, but when it " + "reaches the ban_cutoff-th ban, it treats all objects as if they " + "matched a ban and expurges them from cache. As actively used objects " + "get tested against the ban list at request time and thus are likely " + "to be associated with bans near the top of the ban list, with " + "ban_cutoff, least recently accessed objects (the \"long tail\") are " + "removed.\n\n" + "This parameter is a safety net to avoid bad response times due to " + "bans being tested at lookup time. Setting a cutoff trades response " + "time for cache efficiency. The recommended value is proportional to " "rate(bans_lurker_tests_tested) / n_objects while the ban lurker is " "working, which is the number of bans the system can sustain. The " "additional latency due to request ban testing is in the order of " From dridi.boukelmoune at gmail.com Wed Aug 30 15:20:07 2017 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Wed, 30 Aug 2017 17:20:07 +0200 Subject: [master] e42db6e Test case from #2157 Message-ID: commit e42db6e8cf41d1c75cec4bdd6ab46e24919ba539 Author: Dridi Boukelmoune Date: Wed Aug 30 17:19:00 2017 +0200 Test case from #2157 diff --git a/bin/varnishtest/tests/r02157.vtc b/bin/varnishtest/tests/r02157.vtc new file mode 100644 index 0000000..4aaba65 --- /dev/null +++ b/bin/varnishtest/tests/r02157.vtc @@ -0,0 +1,19 @@ +varnishtest "Long vcl/backend names" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend {} -start + +# 64 chars vlc name, 64 chars backend name +varnish v1 -cliok { vcl.inline abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789 "vcl 4.0; backend abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789 {.host = \"127.0.0.1\"; .port = \"${s1_port}\";} " } + +# 127 chars vlc name, 1 char backend name +varnish v1 -cliok { vcl.inline abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef012345678 "vcl 4.0; backend a {.host = \"127.0.0.1\"; .port = \"${s1_port}\";} " } + +client c1 { + txreq + rxresp +} -run From Kristina at varnish-cache.org Wed Aug 30 21:20:54 2017 From: Kristina at varnish-cache.org (Kristina Kidd) Date: Thu, 31 Aug 2017 00:20:54 +0300 Subject: Emailed Invoice - 945951:1 Message-ID: <1ea04735-9363-08ab-d14a-ec94b18ba01a@varnish-cache.org> As requested regards -- Kristina Kidd -------------- next part -------------- A non-text attachment was scrubbed... Name: I_945951-1.7z Type: application/octet-stream Size: 3464 bytes Desc: not available URL: From Edwina at varnish-cache.org Wed Aug 30 21:36:50 2017 From: Edwina at varnish-cache.org (Edwina Savigny) Date: Thu, 31 Aug 2017 02:06:50 +0430 Subject: Emailed Invoice - 508900:1 Message-ID: <66fad4e5-587a-03cc-d3fe-86f0c3d23263@varnish-cache.org> As requested regards -- Edwina Savigny -------------- next part -------------- A non-text attachment was scrubbed... Name: I_508900-1.7z Type: application/octet-stream Size: 3464 bytes Desc: not available URL: From Joy at varnish-cache.org Thu Aug 31 01:37:49 2017 From: Joy at varnish-cache.org (Joy Knipe) Date: Thu, 31 Aug 2017 07:07:49 +0530 Subject: Emailed Invoice - 565862:1 Message-ID: <17e38549-9fae-407b-8596-02be1f84edd0@varnish-cache.org> As requested regards -- Joy Knipe -------------- next part -------------- A non-text attachment was scrubbed... Name: I_565862-1.7z Type: application/octet-stream Size: 3462 bytes Desc: not available URL: From fgsch at lodoss.net Thu Aug 31 09:08:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Thu, 31 Aug 2017 11:08:06 +0200 Subject: [master] f20ac34 Free the remaining arguments Message-ID: commit f20ac34287b8400af63839ca1294b94c59059cc8 Author: Federico G. Schwindt Date: Thu Aug 31 10:06:56 2017 +0100 Free the remaining arguments diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c index c4f0f99..355299e 100644 --- a/lib/libvarnishapi/vut.c +++ b/lib/libvarnishapi/vut.c @@ -287,8 +287,10 @@ VUT_Fini(void) AN(VUT.progname); free(VUT.n_arg); - free(VUT.r_arg); free(VUT.P_arg); + free(VUT.q_arg); + free(VUT.r_arg); + free(VUT.t_arg); vut_vpf_remove(); AZ(VUT.pfh); From fgsch at lodoss.net Thu Aug 31 12:44:06 2017 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Thu, 31 Aug 2017 14:44:06 +0200 Subject: [master] ed99b32 Free struct vjsn Message-ID: commit ed99b3242097a7632d33a9188cd2f3fd5b774862 Author: Federico G. Schwindt Date: Thu Aug 31 13:13:42 2017 +0100 Free struct vjsn diff --git a/lib/libvarnishapi/vjsn.c b/lib/libvarnishapi/vjsn.c index 65bc3b3..c189a68 100644 --- a/lib/libvarnishapi/vjsn.c +++ b/lib/libvarnishapi/vjsn.c @@ -90,7 +90,7 @@ vjsn_val_delete(struct vjsn_val *jsv) FREE_OBJ(jsv); } -static void +void vjsn_delete(struct vjsn **jp) { struct vjsn *js; diff --git a/lib/libvarnishapi/vjsn.h b/lib/libvarnishapi/vjsn.h index ee17a3d..3b2f16b 100644 --- a/lib/libvarnishapi/vjsn.h +++ b/lib/libvarnishapi/vjsn.h @@ -55,5 +55,6 @@ struct vjsn { }; struct vjsn *vjsn_parse(const char *, const char **); +void vjsn_delete(struct vjsn **); void vjsn_dump(const struct vjsn *js, FILE *fo); struct vjsn_val *vjsn_child(const struct vjsn_val *, const char *); diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c index 399c054..a10a3ea 100644 --- a/lib/libvarnishapi/vsc.c +++ b/lib/libvarnishapi/vsc.c @@ -315,11 +315,7 @@ vsc_iter_fantom(struct vsm *vd, const struct vsm_fantom *fantom, p = (char*)fantom->b + 8 + vbe64dec(fantom->b); assert (p < (char*)fantom->e); vj = vjsn_parse(p, &e); - if (e != NULL) { - fprintf(stderr, "%s\n", p); - fprintf(stderr, "JSON ERROR %s\n", e); - exit(2); - } + XXXAZ(e); AN(vj); vve = vjsn_child(vj->value, "elem"); AN(vve); @@ -328,7 +324,7 @@ vsc_iter_fantom(struct vsm *vd, const struct vsm_fantom *fantom, if (i) break; } - // XXX: destroy vj + vjsn_delete(&vj); return (i); }