From phk at varnish-cache.org Tue Jun 1 07:58:18 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 1 Jun 2010 09:58:18 +0200 Subject: r4871 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-01 09:58:17 +0200 (Tue, 01 Jun 2010) New Revision: 4871 Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c Log: Minor polish Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-05-31 17:43:25 UTC (rev 4870) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-01 07:58:17 UTC (rev 4871) @@ -167,6 +167,10 @@ return (1); } +/*-------------------------------------------------------------------- + * Build a new shmlog file + */ + static void vsl_buildnew(const char *fn, unsigned size, int fill) { @@ -178,7 +182,7 @@ (void)unlink(fn); vsl_fd = open(fn, O_RDWR | O_CREAT | O_EXCL, 0644); if (vsl_fd < 0) { - fprintf(stderr, "Could not open %s: %s\n", + fprintf(stderr, "Could not create %s: %s\n", fn, strerror(errno)); exit (1); } @@ -291,15 +295,14 @@ (void)mlock((void*)loghead, size); /* Initialize pool */ - loghead->alloc_seq = 0; - MEMORY_BARRIER(); + loghead->alloc_seq = 0; /* Zero means "inconsistent" */ + VWMB(); memset(&loghead->head, 0, sizeof loghead->head); loghead->head.magic = SHMALLOC_MAGIC; loghead->head.len = (uint8_t*)(loghead) + size - (uint8_t*)&loghead->head; bprintf(loghead->head.class, "%s", "Free"); - MEMORY_BARRIER(); VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, VSL_CLASS_STAT, VSL_TYPE_STAT, ""); @@ -315,12 +318,10 @@ vsl_log_end = vsl_log_start + s1; vsl_log_nxt = vsl_log_start + 1; *vsl_log_nxt = SLT_ENDMARKER; - MEMORY_BARRIER(); *vsl_log_start = random(); - MEMORY_BARRIER(); + VWMB(); loghead->alloc_seq = random(); - MEMORY_BARRIER(); } void From phk at varnish-cache.org Tue Jun 1 07:59:14 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 1 Jun 2010 09:59:14 +0200 Subject: r4872 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-01 09:59:13 +0200 (Tue, 01 Jun 2010) New Revision: 4872 Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c Log: Remember vmb include Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-01 07:58:17 UTC (rev 4871) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-01 07:59:13 UTC (rev 4872) @@ -44,6 +44,7 @@ #include "shmlog.h" #include "mgt.h" #include "heritage.h" +#include "vmb.h" #ifndef MAP_HASSEMAPHORE #define MAP_HASSEMAPHORE 0 /* XXX Linux */ From phk at varnish-cache.org Tue Jun 1 09:12:00 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 1 Jun 2010 11:12:00 +0200 Subject: r4873 - in trunk/varnish-cache: bin/varnishd doc/sphinx/reference Message-ID: Author: phk Date: 2010-06-01 11:11:59 +0200 (Tue, 01 Jun 2010) New Revision: 4873 Added: trunk/varnish-cache/doc/sphinx/reference/shmem.rst Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/doc/sphinx/reference/index.rst Log: Second stab at making dynamic shared memory understandable. Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-01 07:59:13 UTC (rev 4872) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-01 09:11:59 UTC (rev 4873) @@ -91,25 +91,25 @@ seq = loghead->alloc_seq; loghead->alloc_seq = 0; - MEMORY_BARRIER(); + VWMB(); memset(sha2, 0, sizeof *sha2); sha2->magic = SHMALLOC_MAGIC; sha2->len = sha->len - size; bprintf(sha2->class, "%s", "Free"); - MEMORY_BARRIER(); sha->len = size; bprintf(sha->class, "%s", class); bprintf(sha->type, "%s", type); bprintf(sha->ident, "%s", ident); - MEMORY_BARRIER(); - loghead->alloc_seq = seq++; - MEMORY_BARRIER(); + VWMB(); + if (seq != 0) + do + loghead->alloc_seq = seq++; + while (loghead->alloc_seq == 0); return (SHA_PTR(sha)); - } return (NULL); } @@ -304,6 +304,7 @@ loghead->head.len = (uint8_t*)(loghead) + size - (uint8_t*)&loghead->head; bprintf(loghead->head.class, "%s", "Free"); + VWMB(); VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, VSL_CLASS_STAT, VSL_TYPE_STAT, ""); @@ -319,10 +320,16 @@ vsl_log_end = vsl_log_start + s1; vsl_log_nxt = vsl_log_start + 1; *vsl_log_nxt = SLT_ENDMARKER; - *vsl_log_start = random(); + VWMB(); - VWMB(); - loghead->alloc_seq = random(); + do + *vsl_log_start = random(); + while (*vsl_log_start == 0); + + do + loghead->alloc_seq = random(); + while (loghead->alloc_seq == 0); + } void Modified: trunk/varnish-cache/doc/sphinx/reference/index.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/index.rst 2010-06-01 07:59:13 UTC (rev 4872) +++ trunk/varnish-cache/doc/sphinx/reference/index.rst 2010-06-01 09:11:59 UTC (rev 4873) @@ -1,7 +1,14 @@ -%%%%%%%%%%%%%%%%%%%%% -The Varnish Reference -%%%%%%%%%%%%%%%%%%%%% +.. _reference-index: +%%%%%%%%%%%%%%%%%%%%%%%%%%%% +The Varnish Reference Manual +%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +.. toctree:: + + varnishadm.rst + shmem.rst + .. todo:: The programs: . varnishd manual page @@ -32,4 +39,6 @@ . - rollback Varnishtest . syntax etc. + Shared Memory + . internals Added: trunk/varnish-cache/doc/sphinx/reference/shmem.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/shmem.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/shmem.rst 2010-06-01 09:11:59 UTC (rev 4873) @@ -0,0 +1,59 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Shared Memory Logging and Statistics +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +Varnish uses shared memory for logging and statistics, because it +is faster and much more efficient. But it is also tricky in ways +a regular logfile is not. + +Collision Detection +------------------- + +When you open a file in "append" mode, the operating system guarantees +that whatever you write will not overwrite existing data in the file. +The neat result of this is that multiple procesess or threads writing +to the same file does not even need to know about each other it all +works just as you would expect. + +With shared memory you get no such seatbelts. + +When Varnishd starts, it could find an existing shared memory file, +being used by another varnishd, either because somebody gave the wrong +(or no) -n argument, or because the old varnishd was not dead when +some kind of process-nanny restarted varnishd anew. + +If the shared memory file has a different version or layout it will +be deleted and a new created. + +If the process listed in the "master_pid" field is running, +varnishd will abort startup, assuming you got a wrong -n argument. + +If the process listed in the "child_pid" field is (still?) running, +or if the file as a size different from that specified in the -l +argument, it will be deleted and a new file created. + +The upshot of this, is that programs subscribing to the shared memory +file should periodically do a stat(2) on the name, and if the +st_dev or st_inode fields changed, switch to the new shared memory file. + +Also, the master_pid field should be monitored, if it changes, the +shared memory file should be "reopened" with respect to the linked +list of allocations. + +Allocations +----------- + +Sections inside the shared memory file are allocated dynamically, +for instance when a new backend is added. + +While changes happen to the linked list of allocations, the "alloc_seq" +header field is zero, and after the change, it gets a value different +from what it had before. + +Deallocations +------------- + +When a section is freed, its class will change to "Cool" for at +least 10 seconds, giving programs using it time to detect the +change in alloc_seq header field and/or the change of class. + From perbu at varnish-cache.org Tue Jun 1 11:09:29 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Tue, 1 Jun 2010 13:09:29 +0200 Subject: r4874 - trunk/varnish-cache/doc/sphinx/reference Message-ID: Author: perbu Date: 2010-06-01 13:09:28 +0200 (Tue, 01 Jun 2010) New Revision: 4874 Added: trunk/varnish-cache/doc/sphinx/reference/varnishstat.rst Modified: trunk/varnish-cache/doc/sphinx/reference/varnishadm.rst Log: added varnishstat + minor fixup~ Modified: trunk/varnish-cache/doc/sphinx/reference/varnishadm.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishadm.rst 2010-06-01 09:11:59 UTC (rev 4873) +++ trunk/varnish-cache/doc/sphinx/reference/varnishadm.rst 2010-06-01 11:09:28 UTC (rev 4874) @@ -1,6 +1,6 @@ -=========== - varnishadm -=========== +========== +varnishadm +========== ---------------------------------- Control a running varnish instance Added: trunk/varnish-cache/doc/sphinx/reference/varnishstat.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishstat.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/varnishstat.rst 2010-06-01 11:09:28 UTC (rev 4874) @@ -0,0 +1,90 @@ +=========== +varnishstat +=========== + +--------------------------- +HTTP accelerator statistics +--------------------------- + +:Author: Dag-Erling Sm?rgrav +:Author: Per Buer +:Date: 2010-06-1 +:Version: 1.0 +:Manual section: 1 + + +SYNOPSIS +======== + +varnishstat [-1] [-f field_list] [-l] [-n varnish_name] [-V] [-w delay] + +DESCRIPTION +=========== + +The varnishstat utility displays statistics from a running varnishd(1) instance. + +The following options are available: + +-1 Instead of presenting of a continuously updated display, print the statistics once and exit. + +-f A comma separated list of the fields to display. If it starts with '^' it is used as an exclusion + list. + +-l Lists the available fields to use with the -f option. + +-n Specifies the name of the varnishd instance to get logs from. If -n is not specified, the host name + is used. + +-V Display the version number and exit. + +-w delay Wait delay seconds between updates. The default is 1. + +The columns in the main display are, from left to right: + +1. Value + +2. Per-second average in the period since last update, or a period if the value can not be averaged + +3. Per-second average over process lifetime, or a period if the value can not be averaged + +4. Descriptive text + + +When using the -1 option, the columns in the output are, from left to right: + +1. Symbolic entry name + +2. Value + +3. Per-second average over process lifetime, or a period if the value can not be averaged + +4. Descriptive text + +SEE ALSO +======== + +* varnishd(1) +* varnishhist(1) +* varnishlog(1) +* varnishncsa(1) +* varnishtop(1) +* curses(3) + +HISTORY +======= + +The varnishstat utility was originally developed by Poul-Henning Kamp +?phk at phk.freebsd.dk? in cooperation with Verdens Gang AS, Linpro AS +and Varnish Software. Manual page written by Dag-Erling Sm?rgrav, +and Per Buer. + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright (c) 2006 Verdens Gang AS +* Copyright (c) 2006-2008 Linpro AS +* Copyright (c) 2008-2010 Redpill Linpro AS +* Copyright (c) 2010 Varnish Software AS From perbu at varnish-cache.org Tue Jun 1 13:05:10 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Tue, 1 Jun 2010 15:05:10 +0200 Subject: r4875 - trunk/varnish-cache/doc/sphinx/installation Message-ID: Author: perbu Date: 2010-06-01 15:05:09 +0200 (Tue, 01 Jun 2010) New Revision: 4875 Modified: trunk/varnish-cache/doc/sphinx/installation/install.rst Log: added build deps. reformatted. added headings. Modified: trunk/varnish-cache/doc/sphinx/installation/install.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/installation/install.rst 2010-06-01 11:09:28 UTC (rev 4874) +++ trunk/varnish-cache/doc/sphinx/installation/install.rst 2010-06-01 13:05:09 UTC (rev 4875) @@ -7,11 +7,6 @@ With open source software, you can choose to install binary packages or compile stuff from source-code. -In general, from a point of principle, I would argue that -everybody should compile from source, but realistically -binary packages are *so much easier* so lets cover that first: - - Installing Varnish from packages ================================ @@ -19,29 +14,41 @@ be done with with the systems package manager, typical examples being: -**FreeBSD** +FreeBSD +~~~~~~~ - FreeBSD (from source) +From source: ``cd /usr/ports/varnish && make install clean`` - FreeBSD (binary package) +Binary package: ``pkg_add -r varnish`` -**CentOS/RedHat 5.4 - RPM files** +CentOS/RedHat 5.4 +~~~~~~~~~~~~~~~~~ - We try to keep the lastest version available as prebuildt RPMs (el4 & el5) on `SourceForge `_. +We try to keep the lastest version available as prebuildt RPMs (el4 & +el5) on `SourceForge `_. - Varnish is included in the `EPEL `_ repository. **BUT** unfortunatly we had a syntax change in Varnish 2.0.6->2.1.X. This means that we can not update Varnish in `EPEL `_ so the latest version there is Varnish 2.0.6. In the future (EPEL6) we should be available with Varnish 2.1.X or higher. +Varnish is included in the `EPEL +`_ repository. Unfortunatly we +had a syntax change in Varnish 2.0.6->2.1.X. This means that we can +not update Varnish in `EPEL `_ so +the latest version there is Varnish 2.0.6. -**Debian/Ubuntu - DEB files** +EPEL6 should have Varnish 2.1 available once it releases. - Varnish is distributed to the *unstable* repository of Debian. You should be able to get a hold of the lastest version there. - - Ubuntu syncronize the *unstable* Debian repository. See `Ubuntu Packages `_. +Debian/Ubuntu - DEB files +~~~~~~~~~~~~~~~~~~~~~~~~~ -**Other systems** +Varnish is distributed with both Debian and Ubuntu. In order to get +Varnish up and running type `sudo apt-get install varnish`. Please +note that this might not be the latest version of Varnish. - You are probably best of compiling your own code. See `Compiling Varnish from source`_. +Other systems +~~~~~~~~~~~~~ +You are probably best of compiling your own code. See `Compiling +Varnish from source`_. + If that worked for you, you can skip the rest of this document for now, and and start reading the much more interesting :ref:`tutorial-index` instead. @@ -59,20 +66,52 @@ your system. There is usually a binary package, try substituting "subversion" for "varnish" in the examples above, it might just work. -To get the development source code:: +To fetch the current (2.1) production branch::: + svn co http://varnish-cache.org/svn/varnish/branches/2.1 + +To get the development source code::: + svn co http://varnish-cache.org/svn/varnish/trunk -or if you want the production branch:: +Build dependencies on Debian / Ubuntu +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - svn co http://varnish-cache.org/svn/varnish/branches/2.1 +In order to build Varnish from source you need a number of packages +installed. On a Debian or Ubuntu system these are: -Next, configuration: For this you will need ``libtoolize``, ``aclocal``, -``autoheader``, ``automake`` and ``autoconf``, also known as *the -autocrap tools* installed on your system. +* autotools-dev +* automake1.9 +* libtool +* autoconf +* libncurses-dev +* xsltproc +* groff-base +* libpcre3-dev -Once you have them:: +To install all these just type ``sudo apt-get install autotools-dev automake1.9 libtool autoconf libncurses-dev xsltproc groff-base libpcre3-dev``. +Build dependencies on Red Hat / Centos +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To build Varnish on a Red Hat or Centos system you need the following +packages installed: + +* automake +* autoconf +* libtool +* ncurses-devel +* libxslt +* groff +* pcre-devel +* pkgconfig + +Configuring and compiling +~~~~~~~~~~~~~~~~~~~~~~~~~ + +Next, configuration: The configuration will need the dependencies +above satisfied. Once that is take care of::: + cd varnish-cache sh autogen.sh sh configure @@ -93,8 +132,14 @@ fails, something is horribly wrong, and you will get nowhere without figuring out what. +Installing +~~~~~~~~~~ + And finally, the true test of a brave heart:: make install +Varnish will now be installed in /usr/local. The varnishd binary is in +/usr/local/sbin/varnishd and its + .. _SubVersion: http://subversion.tigris.org/ From perbu at varnish-cache.org Tue Jun 1 13:27:10 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Tue, 1 Jun 2010 15:27:10 +0200 Subject: r4876 - trunk/varnish-cache/doc/sphinx/installation Message-ID: Author: perbu Date: 2010-06-01 15:27:09 +0200 (Tue, 01 Jun 2010) New Revision: 4876 Modified: trunk/varnish-cache/doc/sphinx/installation/install.rst Log: type. intro. exit. Modified: trunk/varnish-cache/doc/sphinx/installation/install.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/installation/install.rst 2010-06-01 13:05:09 UTC (rev 4875) +++ trunk/varnish-cache/doc/sphinx/installation/install.rst 2010-06-01 13:27:09 UTC (rev 4876) @@ -4,9 +4,13 @@ Installing Varnish on your computer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -With open source software, you can choose to install binary -packages or compile stuff from source-code. +With open source software, you can choose to install binary packages +or compile stuff from source-code. To install a package or compile +from source is a matter of personal taste. If you don't know which +method too choose read the whole document and choose the method you +are most confortable with. + Installing Varnish from packages ================================ @@ -22,8 +26,8 @@ Binary package: ``pkg_add -r varnish`` -CentOS/RedHat 5.4 -~~~~~~~~~~~~~~~~~ +CentOS/RedHat +~~~~~~~~~~~~~ We try to keep the lastest version available as prebuildt RPMs (el4 & el5) on `SourceForge `_. @@ -36,8 +40,8 @@ EPEL6 should have Varnish 2.1 available once it releases. -Debian/Ubuntu - DEB files -~~~~~~~~~~~~~~~~~~~~~~~~~ +Debian/Ubuntu +~~~~~~~~~~~~~ Varnish is distributed with both Debian and Ubuntu. In order to get Varnish up and running type `sudo apt-get install varnish`. Please @@ -49,9 +53,9 @@ You are probably best of compiling your own code. See `Compiling Varnish from source`_. -If that worked for you, you can skip the rest of this document -for now, and and start reading the much more interesting :ref:`tutorial-index` -instead. +If that worked for you, you can skip the rest of this document for +now, and and start reading the much more interesting +:ref:`tutorial-index` instead. Compiling Varnish from source @@ -110,7 +114,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~ Next, configuration: The configuration will need the dependencies -above satisfied. Once that is take care of::: +above satisfied. Once that is taken care of::: cd varnish-cache sh autogen.sh @@ -140,6 +144,9 @@ make install Varnish will now be installed in /usr/local. The varnishd binary is in -/usr/local/sbin/varnishd and its +/usr/local/sbin/varnishd and its default configuration will be +/usr/local/etc/varnish/default.vcl. +You can now proceed to the :ref:`tutorial-index`. + .. _SubVersion: http://subversion.tigris.org/ From phk at varnish-cache.org Wed Jun 2 08:55:43 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 2 Jun 2010 10:55:43 +0200 Subject: r4877 - in trunk/varnish-cache: bin/varnishd doc/sphinx/reference Message-ID: Author: phk Date: 2010-06-02 10:55:43 +0200 (Wed, 02 Jun 2010) New Revision: 4877 Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/doc/sphinx/reference/shmem.rst Log: Give up on reusing shmem files, it is not worth the added code complexity. Do a -n collision check, and create a new file always. Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-01 13:27:09 UTC (rev 4876) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-02 08:55:43 UTC (rev 4877) @@ -115,12 +115,12 @@ } /*-------------------------------------------------------------------- - * Try to reuse an existing shmem file, but try to not disturb another - * varnishd using the file. + * Check that we are not started with the same -n argument as an already + * running varnishd */ -static int -vsl_goodold(int fd, unsigned size) +static void +vsl_n_check(int fd) { struct shmloghead slh; int i; @@ -133,11 +133,11 @@ memset(&slh, 0, sizeof slh); /* XXX: for flexelint */ i = read(fd, &slh, sizeof slh); if (i != sizeof slh) - return (0); + return; if (slh.magic != SHMLOGHEAD_MAGIC) - return (0); + return; if (slh.hdrsize != sizeof slh) - return (0); + return; if (slh.master_pid != 0 && !kill(slh.master_pid, 0)) { fprintf(stderr, @@ -148,24 +148,6 @@ "instances.)\n"); exit(2); } - - if (slh.child_pid != 0 && !kill(slh.child_pid, 0)) { - fprintf(stderr, - "SHMFILE used by orphan varnishd child process (pid=%jd)\n", - (intmax_t)slh.child_pid); - fprintf(stderr, "(We assume that process is busy dying.)\n"); - return (0); - } - - /* Sanity checks */ - - if (slh.shm_size != size) - return (0); - - if (st.st_size != size) - return (0); - - return (1); } /*-------------------------------------------------------------------- @@ -278,14 +260,13 @@ size &= ~(ps - 1); i = open(fn, O_RDWR, 0644); - if (i >= 0 && vsl_goodold(i, size)) { - fprintf(stderr, "Using old SHMFILE\n"); - vsl_fd = i; - } else { - fprintf(stderr, "Creating new SHMFILE\n"); + if (i >= 0) { + vsl_n_check(i); (void)close(i); - vsl_buildnew(fn, size, fill); - } + } + fprintf(stderr, "Creating new SHMFILE\n"); + (void)close(i); + vsl_buildnew(fn, size, fill); loghead = (void *)mmap(NULL, size, PROT_READ|PROT_WRITE, Modified: trunk/varnish-cache/doc/sphinx/reference/shmem.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/shmem.rst 2010-06-01 13:27:09 UTC (rev 4876) +++ trunk/varnish-cache/doc/sphinx/reference/shmem.rst 2010-06-02 08:55:43 UTC (rev 4877) @@ -6,40 +6,46 @@ is faster and much more efficient. But it is also tricky in ways a regular logfile is not. -Collision Detection -------------------- - When you open a file in "append" mode, the operating system guarantees that whatever you write will not overwrite existing data in the file. The neat result of this is that multiple procesess or threads writing -to the same file does not even need to know about each other it all +to the same file does not even need to know about each other, it all works just as you would expect. -With shared memory you get no such seatbelts. +With a shared memory log, we get no help from the kernel, the writers +need to make sure they do not stomp on each other, and they need to +make it possible and safe for the readers to access the data. -When Varnishd starts, it could find an existing shared memory file, -being used by another varnishd, either because somebody gave the wrong -(or no) -n argument, or because the old varnishd was not dead when -some kind of process-nanny restarted varnishd anew. +The "CS101" way, is to introduce locks, and much time is spent examining +the relative merits of the many kinds of locks available. -If the shared memory file has a different version or layout it will -be deleted and a new created. +Inside the varnishd (worker) process, we use mutexes to guarantee +consistency, both with respect to allocations, log entries and stats +counters. -If the process listed in the "master_pid" field is running, -varnishd will abort startup, assuming you got a wrong -n argument. +We do not want a varnishncsa trying to push data through a stalled +ssh connection to stall the delivery of content, so readers like +that are purely read-only, they do not get to affect the varnishd +process and that means no locks for them. -If the process listed in the "child_pid" field is (still?) running, -or if the file as a size different from that specified in the -l -argument, it will be deleted and a new file created. +Instead we use "stable storage" concepts, to make sure the view +seen by the readers is consistent at all times. -The upshot of this, is that programs subscribing to the shared memory -file should periodically do a stat(2) on the name, and if the -st_dev or st_inode fields changed, switch to the new shared memory file. +As long as you only add stuff, that is trivial, but taking away +stuff, such as when a backend is taken out of the configuration, +we need to give the readers a chance to discover this, a "cooling +off" period. -Also, the master_pid field should be monitored, if it changes, the -shared memory file should be "reopened" with respect to the linked -list of allocations. +When Varnishd starts, if it finds an existing shared memory file, +and it can safely read the master_pid field, it will check if that +process is running, and if so, fail with an error message, indicating +that -n arguments collide. +In all other cases, it will delete and create a new shmlog file, +in order to provide running readers a cooling off period, where +they can discover that there is a new shmlog file, by doing a +stat(2) call and checking the st_dev & st_inode fields. + Allocations ----------- From perbu at varnish-cache.org Wed Jun 2 16:33:59 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Wed, 2 Jun 2010 18:33:59 +0200 Subject: r4878 - trunk/varnish-cache/doc/sphinx/reference Message-ID: Author: perbu Date: 2010-06-02 18:33:59 +0200 (Wed, 02 Jun 2010) New Revision: 4878 Added: trunk/varnish-cache/doc/sphinx/reference/varnishlog.rst trunk/varnish-cache/doc/sphinx/reference/varnishreplay.rst trunk/varnish-cache/doc/sphinx/reference/varnishsizes.rst Modified: trunk/varnish-cache/doc/sphinx/reference/varnishadm.rst Log: converted/cleaned up a few more man pages Modified: trunk/varnish-cache/doc/sphinx/reference/varnishadm.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishadm.rst 2010-06-02 08:55:43 UTC (rev 4877) +++ trunk/varnish-cache/doc/sphinx/reference/varnishadm.rst 2010-06-02 16:33:59 UTC (rev 4878) @@ -78,7 +78,6 @@ This document is licensed under the same licence as Varnish itself. See LICENCE for details. -* Copyright (c) 2006 Verdens Gang AS -* Copyright (c) 2006-2008 Linpro AS +* Copyright (c) 2007-2008 Linpro AS * Copyright (c) 2008-2010 Redpill Linpro AS * Copyright (c) 2010 Varnish Software AS Added: trunk/varnish-cache/doc/sphinx/reference/varnishlog.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishlog.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/varnishlog.rst 2010-06-02 16:33:59 UTC (rev 4878) @@ -0,0 +1,173 @@ +========== +varnishlog +========== + +-------------------- +Display Varnish logs +-------------------- + +:Author: Dag-Erling Sm?rgrav +:Author: Per Buer +:Date: 2010-05-31 +:Version: 0.2 +:Manual section: 1 + + +SYNOPSIS +======== + +varnishlog [-a] [-b] [-C] [-c] [-D] [-d] [-I regex] [-i tag] [-k keep] +[-n varnish_name] [-o] [-P file] [-r file] [-s num] [-u] [-V] +[-w file] [-X regex] [-x tag] [tag regex] + +DESCRIPTION +=========== + + +The varnishlog utility reads and presents varnishd(1) shared memory logs. + +The following options are available: + +-a When writing to a file, append to it rather than overwrite it. + +-b Include log entries which result from communication with a backend server. + If neither -b nor -c is specified, varnishlog acts as if they both were. + +-C Ignore case when matching regular expressions. + +-c Include log entries which result from communication with a client. + If neither -b nor -c is specified, varnishlog acts as if they both were. + +-D Daemonize. + +-d Process old log entries on startup. Normally, varnishlog will only process entries + which are written to the log after it starts. + +-I regex Include log entries which match the specified regular expression. If + neither -I nor -i is specified, all log entries are included. + +-i tag Include log entries with the specified tag. If neither -I nor -i is specified, + all log entries are included. + +-k num Only show the first num log records. + +-n Specifies the name of the varnishd instance to get logs from. If -n is not + specified, the host name is used. + +-o Group log entries by request ID. This has no effect when writing to a + file using the -w option. + +-P file Write the process's PID to the specified file. + +-r file Read log entries from file instead of shared memory. + +-s num Skip the first num log records. + +-u Unbuffered output. + +-V Display the version number and exit. + +-w file Write log entries to file instead of displaying them. The file + will be overwritten unless the -a option was specified. If + varnishlog receives a SIGHUP while writing to a file, it will + reopen the file, allowing the old one to be rotated away. + +-X regex Exclude log entries which match the specified regular expression. + +-x tag Exclude log entries with the specified tag. + +If the -o option was specified, an additional tag and regex may be +specified to select only requests which generated a log entry with the +given tag whose contents match the given regex. + +TAGS +==== +The following log entry tags are currently defined: + +* Backend +* BackendClose +* BackendOpen +* BackendReuse +* BackendXID +* CLI +* ClientAddr +* Debug +* Error +* ExpBan +* ExpKill +* ExpPick +* Hit +* HitPass +* HttpError +* HttpGarbage +* Length +* ObjHeader +* ObjLostHeader +* ObjProtocol +* ObjRequest +* ObjResponse +* ObjStatus +* ObjURL +* ReqEnd +* ReqStart +* RxHeader +* RxLostHeader +* RxProtocol +* RxRequest +* RxResponse +* RxStatus +* RxURL +* SessionClose +* SessionOpen +* StatAddr +* StatSess +* TTL +* TxHeader +* TxLostHeader +* TxProtocol +* TxRequest +* TxResponse +* TxStatus +* TxURL +* VCL_acl +* VCL_call +* VCL_return +* VCL_trace +* WorkThread + +EXAMPLES +======== + +The following command line simply copies all log entries to a log file::: + + $ varnishlog -w /var/log/varnish.log + +The following command line reads that same log file and displays requests for the front page::: + + $ varnishlog -r /var/log/varnish.log -c -o RxURL '^/$' + +SEE ALSO +======== +* varnishd(1) +* varnishhist(1) +* varnishncsa(1) +* varnishstat(1) +* varnishtop(1) + +HISTORY +======= + +The varnishlog utility was developed by Poul-Henning Kamp ?phk at phk.freebsd.dk? in cooperation with Verdens Gang +AS, Linpro AS and Varnish Software. This manual page was initially written by Dag-Erling Sm?rgrav. + + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright (c) 2006 Verdens Gang AS +* Copyright (c) 2006-2008 Linpro AS +* Copyright (c) 2008-2010 Redpill Linpro AS +* Copyright (c) 2010 Varnish Software AS Added: trunk/varnish-cache/doc/sphinx/reference/varnishreplay.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishreplay.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/varnishreplay.rst 2010-06-02 16:33:59 UTC (rev 4878) @@ -0,0 +1,57 @@ +============= +varnishreplay +============= + +------------------------ +HTTP traffic replay tool +------------------------ + +:Author: Cecilie Fritzvold +:Author: Per Buer +:Date: 2010-05-31 +:Version: 1.0 +:Manual section: 1 + + +SYNOPSIS +======== +varnishreplay [-D] -a address:port -r file + +DESCRIPTION +=========== + +The varnishreplay utility parses varnish logs and attempts to +reproduce the traffic. It is typcally used to *warm* up caches or +various forms of testing. + +The following options are available: + +-a backend Send the traffic over tcp to this server, specified by an + address and a port. This option is + mandatory. Only IPV4 is supported at this time. + +-D Turn on debugging mode. + +-r file Parse logs from this file. This option is mandatory. + + +SEE ALSO +======== + +* varnishd(1) +* varnishlog(1) + +HISTORY +======= + +The varnishreplay utility and this manual page were written by Cecilie +Fritzvold and later updated by Per Buer. + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright (c) 2007 Linpro AS +* Copyright (c) 2010 Varnish Software AS Added: trunk/varnish-cache/doc/sphinx/reference/varnishsizes.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishsizes.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/varnishsizes.rst 2010-06-02 16:33:59 UTC (rev 4878) @@ -0,0 +1,87 @@ +============ +varnishsizes +============ + +------------------------------------- +Varnish object size request histogram +------------------------------------- + +:Author: Dag Erling Sm?rgrav +:Author: Kristian Lyngst?l +:Author: Per Buer +:Date: 2010-05-31 +:Version: 1.0 +:Manual section: 1 + + +SYNOPSIS +======== + +varnishsizes [-b] [-C] [-c] [-d] [-I regex] [-i tag] [-n varnish_name] + [-r file] [-V] [-w delay] [-X regex] [-x tag] + +DESCRIPTION +=========== + +The varnishsizes utility reads varnishd(1) shared memory logs and presents a continuously updated histogram +showing the distribution of the last N requests by their processing. The value of N and the vertical scale are +displayed in the top left corner. The horizontal scale is logarithmic. Hits are marked with a pipe character +("|"), and misses are marked with a hash character ("#"). + +The following options are available: + +-b Include log entries which result from communication with a backend server. + If neither -b nor -c is specified, varnishsizes acts as if they both were. + +-C Ignore case when matching regular expressions. + +-c Include log entries which result from communication with a client. + If neither -b nor -c is specified, varnishsizes acts as if they both were. + +-d Process old log entries on startup. Normally, varnishsizes will only + process entries which are written to the log after it starts. + +-I regex Include log entries which match the specified regular expression. + If neither -I nor -i is specified, all log entries are included. + +-i tag Include log entries with the specified tag. If neither -I nor -i + is specified, all log entries are included. + +-n Specifies the name of the varnishd instance to get logs from. + If -n is not specified, the host name is used. + +-r file Read log entries from file instead of shared memory. + +-V Display the version number and exit. + +-w delay Wait at least delay seconds between each update. The default is 1. + file instead of displaying them. The file will be overwritten + unless the -a option was specified. + +-X regex Exclude log entries which match the specified regular expression. + +-x tag Exclude log entries with the specified tag. + +SEE ALSO +======== + +* varnishd(1) +* varnishlog(1) +* varnishncsa(1) +* varnishstat(1) +* varnishtop(1) + +HISTORY +======= + +The varnishsizes utility was developed by Kristian Lyngst?l based on +varnishhist. This manual page was written by Kristian Lyngst?l, +Dag-Erling Sm?rgrav and Per Buer. + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright (c) 2010 Varnish Software AS From perbu at varnish-cache.org Wed Jun 2 18:51:21 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Wed, 2 Jun 2010 20:51:21 +0200 Subject: r4879 - trunk/varnish-cache/doc/sphinx/reference Message-ID: Author: perbu Date: 2010-06-02 20:51:21 +0200 (Wed, 02 Jun 2010) New Revision: 4879 Added: trunk/varnish-cache/doc/sphinx/reference/vcl.rst Log: Converted/cleaned up the vcl manpage. Still needs a bit of tlc. Added: trunk/varnish-cache/doc/sphinx/reference/vcl.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/vcl.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/vcl.rst 2010-06-02 18:51:21 UTC (rev 4879) @@ -0,0 +1,787 @@ +=== +VCL +=== + +------------------------------ +Varnish Configuration Language +------------------------------ + +:Author: Dag-Erling Sm?rgrav +:Author: Poul-Henning Kamp +:Author: Kristian Lyngst?l +:Author: Per Buer +:Date: 2010-06-02 +:Version: 1.0 +:Manual section: 7 + +DESCRIPTION +=========== + +The VCL language is a small domain-specific language designed to be +used to define request handling and document caching policies for the +Varnish HTTP accelerator. + +When a new configuration is loaded, the varnishd management process +translates the VCL code to C and compiles it to a shared object which +is then dynamically linked into the server process. + +SYNTAX +====== + +The VCL syntax is very simple, and deliberately similar to C and Perl. +Blocks are delimited by curly braces, statements end with semicolons, +and comments may be written as in C, C++ or Perl according to your own +preferences. + +In addition to the C-like assignment (=), comparison (==) and boolean +(!, && and \|\|) operators, VCL supports regular expression and ACL +matching using the ~ operator. + +Unlike C and Perl, the backslash (\) character has no special meaning +in strings in VCL, which use the (%xx) escape mechanism just like +URLs, so it can be freely used in regular expressions without +doubling. + +Strings are concatenated by just putting them one after each other +without any operator in between. + +Assignments are introduced with the set keyword. There are no +user-defined variables; values can only be assigned to variables +attached to backend, request or document objects. Most of these are +typed, and the values assigned to them must have a compatible unit +suffix. + +VCL has if tests, but no loops. + +The contents of another VCL file may be inserted at any point in the +code by using the include keyword followed by the name of the other +file as a quoted string. + +Backend declarations +-------------------- + +A backend declaration creates and initializes a named backend object::: + + backend www { + .host = "www.example.com"; + .port = "http"; + } + +The backend object can later be used to select a backend at request time::: + + if (req.http.host ~ "^(www.)?example.com$") { + set req.backend = www; + } + +To avoid overloading backend servers, .max_connections can be set to +limit the maximum number of concurrent backend connections. + +The timeout parameters can be overridden in the backend declaration. +The timeout parameters are .connect_timeout for the time to wait for a +backend connection, .first_byte_timeout for the time to wait for the +first byte from the backend and .between_bytes_timeout for time to +wait between each received byte. + +These can be set in the declaration like this::: + + backend www { + .host = "www.example.com"; + .port = "http"; + .connect_timeout = 1s; + .first_byte_timeout = 5s; + .between_bytes_timeout = 2s; + } + +To mark a backend as unhealthy after number of items have been added +to it's saintmode list .saintmode_threshold can be set to the maximum +list size. Setting a value of 0 disables saintmode checking entirely +for that backend. The value in the backend declaration overrides the +parameter. + +Directors +--------- + +Directors choose from different backends based on health status and a +per-director algorithm. There currently exists a round-robin and a +random director. + +Directors are defined using::: + + director b2 random { + .retries = 5; + { + // We can refer to named backends + .backend = b1; + .weight = 7; + } + { + // Or define them inline + .backend = { + .host = "fs2"; + } + .weight = 3; + } + } + +The random director +~~~~~~~~~~~~~~~~~~~ + +The random director takes one per director option .retries. This +specifies how many tries it will use to find a working backend. The +default is the same as the number of backends defined for the +director. + +There is also a per-backend option: weight which defines the portion +of traffic to send to the particular backend. + +The round-robin director +~~~~~~~~~~~~~~~~~~~~~~~~ + +The round-robin does not take any options. + +Backend probes +-------------- + +Backends can be probed to see whether they should be considered +healthy or not. The return status can also be checked by using +req.backend.healthy .window is how many of the latest polls we +examine, while .threshold is how many of those must have succeeded for +us to consider the backend healthy. .initial is how many of the +probes are considered good when Varnish starts - defaults to the same +amount as the threshold. + +A backend with a probe can be defined like this::: + + backend www { + .host = "www.example.com"; + .port = "http"; + .probe = { + .url = "/test.jpg"; + .timeout = 0.3 s; + .window = 8; + .threshold = 3; + .initial = 3; + } + } + +It is also possible to specify the raw HTTP request:: + + backend www { + .host = "www.example.com"; + .port = "http"; + .probe = { + # NB: \r\n automatically inserted after each string! + .request = + "GET / HTTP/1.1" + "Host: www.foo.bar" + "Connection: close"; + } + } + +ACLs +---- + +An ACL declaration creates and initializes a named access control list +which can later be used to match client addresses::: + + acl local { + "localhost"; // myself + "192.0.2.0"/24; // and everyone on the local network + ! "192.0.2.23"; // except for the dialin router + } + +If an ACL entry specifies a host name which Varnish is unable to +resolve, it will match any address it is com? pared to. Consequently, +if it is preceded by a negation mark, it will reject any address it is +compared to, which may not be what you intended. If the entry is +enclosed in parentheses, however, it will simply be ignored. + +To match an IP address against an ACL, simply use the match operator::: + + if (client.ip ~ local) { + pipe; + } + +Grace +----- + +If the backend takes a long time to generate an object there is a risk +of a thread pile up. In order to prevent this you can enable grace. +This allows varnish to serve an expired version of the object while a +fresh object is being generated by the backend. + +The following vcl code will make Varnish serve expired objects. All +object will be kept up to two minutes past their expiration time or a +fresh object is generated.:: + + sub vcl_recv { + set req.grace = 2m; + } + sub vcl_fetch { + set beresp.grace = 2m; + } + +Functions +--------- + +The following built-in functions are available: + +regsub(str, regex, sub) + Returns a copy of str with the first occurrence of the regular + expression regex replaced with sub. Within sub, \0 (which can + also be spelled &) is replaced with the entire matched string, + and \n is replaced with the contents of subgroup n in the + matched string. + +regsuball(str, regex, sub) + As regsuball() but this replaces all occurrences. + +purge_url(regex) + Purge all objects in cache whose URLs match regex. + +Subroutines +~~~~~~~~~~~ + +A subroutine is used to group code for legibility or reusability::: + + sub pipe_if_local { + if (client.ip ~ local) { + pipe; + } + } + +Subroutines in VCL do not take arguments, nor do they return values. + +To call a subroutine, use the call keyword followed by the subroutine's name: + +call pipe_if_local; + +There are a number of special subroutines which hook into the Varnish +workflow. These subroutines may inspect and manipulate HTTP headers +and various other aspects of each request, and to a certain extent +decide how the request should be handled. Each subroutine terminates +by calling one of a small number of keywords which indi? cates the +desired outcome. + +vcl_recv + Called at the beginning of a request, after the complete request has + been received and parsed. Its purpose is to decide whether or not + to serve the request, how to do it, and, if applicable, which backend + to use. + + The vcl_recv subroutine may terminate with one of the following keywords: + + error code [reason] + Return the specified error code to the client and abandon the request. + + pass + Switch to pass mode. Control will eventually pass to vcl_pass. + + pipe + Switch to pipe mode. Control will eventually pass to vcl_pipe. + + lookup + Look up the requested object in the cache. Control will + eventually pass to vcl_hit or vcl_miss, depending on whether the + object is in the cache. + +vcl_pipe + Called upon entering pipe mode. In this mode, the request is passed + on to the backend, and any further data from either client or + backend is passed on unaltered until either end closes the + connection. + + The vcl_pipe subroutine may terminate with one of the following keywords: + + error code [reason] + Return the specified error code to the client and abandon the request. + + pipe + Proceed with pipe mode. + +vcl_pass + Called upon entering pass mode. In this mode, the request is passed + on to the backend, and the backend's response is passed on to the + client, but is not entered into the cache. Subsequent requests sub? + mitted over the same client connection are handled normally. + + The vcl_pass subroutine may terminate with one of the following keywords: + + error code [reason] + Return the specified error code to the client and abandon the request. + + pass + Proceed with pass mode. + +vcl_hash + Use req.hash += req.http.Cookie or similar to include the Cookie HTTP + header in the hash string. The vcl_hash subroutine may terminate with + one of the following keywords: + + hash + Proceed. + +vcl_hit + Called after a cache lookup if the requested document was found in the cache. + + The vcl_hit subroutine may terminate with one of the following keywords: + + error code [reason] + Return the specified error code to the client and abandon the request. + + pass + Switch to pass mode. Control will eventually pass to vcl_pass. + + deliver + Deliver the cached object to the client. Control will eventually + pass to vcl_deliver. + +vcl_miss + Called after a cache lookup if the requested document was not found + in the cache. Its purpose is to decide whether or not to attempt to + retrieve the document from the backend, and which backend to use. + + The vcl_miss subroutine may terminate with one of the following keywords: + + error code [reason] + Return the specified error code to the client and abandon the request. + + pass + Switch to pass mode. Control will eventually pass to vcl_pass. + + fetch + Retrieve the requested object from the backend. Control will + eventually pass to vcl_fetch. + +vcl_fetch + Called after a document has been successfully retrieved from the backend. + + The vcl_fetch subroutine may terminate with one of the following keywords: + + error code [reason] + Return the specified error code to the client and abandon the request. + + pass + Switch to pass mode. Control will eventually pass to vcl_pass. + + deliver + Possibly insert the object into the cache, then deliver it to the + client. Control will eventually pass to vcl_deliver. + + esi + ESI-process the document which has just been fetched. + +vcl_deliver + Called before a cached object is delivered to the client. + + The vcl_deliver subroutine may terminate with one of the following + keywords: + + error code [reason] + Return the specified error code to the client and abandon the request. + + deliver + Deliver the object to the client. + +If one of these subroutines is left undefined or terminates without +reaching a handling decision, control will be handed over to the +builtin default. See the EXAMPLES section for a listing of the +default code. + +Multiple subroutines +~~~~~~~~~~~~~~~~~~~~ +If multiple subroutines with the same name are defined, they are +concatenated in the order in which the appear in the source. + +Example::: + + # in file "main.vcl" + include "backends.vcl"; + include "purge.vcl"; + + # in file "backends.vcl" + sub vcl_recv { + if (req.http.host ~ "example.com") { + set req.backend = foo; + } elsif (req.http.host ~ "example.org") { + set req.backend = bar; + } + } + + # in file "purge.vcl" + sub vcl_recv { + if (client.ip ~ admin_network) { + if (req.http.Cache-Control ~ "no-cache") { + purge_url(req.url); + } + } + } + +The builtin default subroutines are implicitly appended in this way. + +Variables +~~~~~~~~~ + +Although subroutines take no arguments, the necessary information is +made available to the handler subroutines through global variables. + +The following variables are always available: + +now + The current time, in seconds since the epoch. + +The following variables are available in backend declarations: + +.host + Host name or IP address of a backend. + +.port + Service name or port number of a backend. + +The following variables are available while processing a request: + +client.ip + The client's IP address. + +server.hostname + The host name of the server. + +server.identity + The identity of the server, as set by the -i + parameter. If the -i parameter is not passed to varnishd, + server.identity will be set to the name of the instance, as + specified by the -n parameter. + +server.ip + The IP address of the socket on which the client connection was received. + +server.port + The port number of the socket on which the client connection was received. + +req.request + The request type (e.g. "GET", "HEAD"). + +req.url + The requested URL. + +req.proto + The HTTP protocol version used by the client. + +req.backend + The backend to use to service the request. + +req.backend.healthy + Whether the backend is healthy or not. + +req.http.header + The corresponding HTTP header. + +The following variables are available while preparing a backend +request (either for a cache miss or for pass or pipe mode): + +bereq.request + The request type (e.g. "GET", "HEAD"). + +bereq.url + The requested URL. + +bereq.proto + The HTTP protocol version used to talk to the server. + +bereq.http.header + The corresponding HTTP header. + +bereq.connect_timeout + The time in seconds to wait for a backend connection. + +bereq.first_byte_timeout + The time in seconds to wait for the first byte from the backend. Not + available in pipe mode. + +bereq.between_bytes_timeout + The time in seconds to wait between each received byte from the + backend. Not available in pipe mode. + +XXX: Aren't these beresp now? + +The following variables are available after the requested object has +been retrieved from cache or from the backend: + +obj.proto + The HTTP protocol version used when the object was retrieved. + +obj.status + The HTTP status code returned by the server. + +obj.response +The HTTP status message returned by the server. + +obj.cacheable + True if the request resulted in a cacheable response. A response is + considered cacheable if it is valid (see above), and the HTTP status + code is 200, 203, 300, 301, 302, 404 or 410. + +obj.ttl + The object's remaining time to live, in seconds. + +obj.lastuse + The approximate time elapsed since the object was last requests, in + seconds. + +obj.hits + The approximate number of times the object has been delivered. A value + of 0 indicates a cache miss. + +The following variables are available while determining the hash key +of an object: + +req.hash + The hash key used to refer to an object in the cache. Used when + both reading from and writing to the cache. + +The following variables are available while preparing a response to the client: + +resp.proto + The HTTP protocol version to use for the response. + +resp.status + The HTTP status code that will be returned. + +resp.response + The HTTP status message that will be returned. + +resp.http.header + The corresponding HTTP header. + +Values may be assigned to variables using the set keyword::: + + sub vcl_recv { + # Normalize the Host: header + if (req.http.host ~ "^(www.)?example.com$") { + set req.http.host = "www.example.com"; + } + } + +HTTP headers can be removed entirely using the remove keyword::: + + sub vcl_fetch { + # Don't cache cookies + remove obj.http.Set-Cookie; + } + +EXAMPLES +======== + +The following code is the equivalent of the default configuration with +the backend address set to "backend.example.com" and no backend port +specified::: + + backend default { + .host = "backend.example.com"; + .port = "http"; + } + + sub vcl_recv { + if (req.http.x-forwarded-for) { + set req.http.X-Forwarded-For = req.http.X-Forwarded-For ", " client.ip; + } else { + set req.http.X-Forwarded-For = client.ip; + } + + if (req.request != "GET" && + req.request != "HEAD" && + req.request != "PUT" && + req.request != "POST" && + req.request != "TRACE" && + req.request != "OPTIONS" && + req.request != "DELETE") { + // Non-RFC2616 or CONNECT which is weird. + return (pipe); + } + if (req.request != "GET" && req.request != "HEAD") { + // We only deal with GET and HEAD by default + return (pass); + } + if (req.http.Authorization || req.http.Cookie) { + // Not cacheable by default + return (pass); + } + return (lookup); + } + + sub vcl_pipe { + # Note that only the first request to the backend will have + # X-Forwarded-For set. If you use X-Forwarded-For and want to + # have it set for all requests, make sure to have: + # set req.http.connection = "close"; + # here. It is not set by default as it might break some broken web + # applications, like IIS with NTLM authentication. + return (pipe); + } + + sub vcl_pass { + return (pass); + } + + sub vcl_hash { + set req.hash += req.url; + if (req.http.host) { + set req.hash += req.http.host; + } else { + set req.hash += server.ip; + } + return (hash); + } + + sub vcl_hit { + if (!obj.cacheable) { + return (pass); + } + return (deliver); + } + + sub vcl_miss { + return (fetch); + } + + sub vcl_fetch { + if (!beresp.cacheable) { + return (pass); + } + if (beresp.http.Set-Cookie) { + return (pass); + } + return (deliver); + } + + sub vcl_deliver { + return (deliver); + } + + sub vcl_error { + set obj.http.Content-Type = "text/html; charset=utf-8"; + synthetic {" + + + + + "} obj.status " " obj.response {" + + +

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

+

"} obj.response {"

+

Guru Meditation:

+

XID: "} req.xid {"

+
+ Varnish cache server + + + "}; + return (deliver); + } + +The following example shows how to support multiple sites running on +separate backends in the same Varnish instance, by selecting backends +based on the request URL::: + + backend www { + .host = "www.example.com"; + .port = "80"; + } + + backend images { + .host = "images.example.com"; + .port = "80"; + } + + sub vcl_recv { + if (req.http.host ~ "^(www.)?example.com$") { + set req.http.host = "www.example.com"; + set req.backend = www; + } elsif (req.http.host ~ "^images.example.com$") { + set req.backend = images; + } else { + error 404 "Unknown virtual host"; + } + } + + The following snippet demonstrates how to force a minimum TTL for + all documents. Note that this is not the same as setting the + default_ttl run-time parameter, as that only affects document for + which the backend did not specify a TTL::: + + sub vcl_fetch { + if (obj.ttl < 120s) { + set obj.ttl = 120s; + } + } + +The following snippet demonstrates how to force Varnish to cache +documents even when cookies are present::: + + sub vcl_recv { + if (req.request == "GET" && req.http.cookie) { + call(lookup); + } + } + + sub vcl_fetch { + if (beresp.http.Set-Cookie) { + deliver; + } + } + +The following code implements the HTTP PURGE method as used by Squid +for object invalidation::: + + acl purge { + "localhost"; + "192.0.2.1"/24; + } + + sub vcl_recv { + if (req.request == "PURGE") { + if (!client.ip ~ purge) { + error 405 "Not allowed."; + } + lookup; + } + } + + sub vcl_hit { + if (req.request == "PURGE") { + set obj.ttl = 0s; + error 200 "Purged."; + } + } + + sub vcl_miss { + if (req.request == "PURGE") { + error 404 "Not in cache."; + } + } + +SEE ALSO +======== + +* varnishd(1) + +HISTORY +======= + +The VCL language was developed by Poul-Henning Kamp in cooperation +with Verdens Gang AS, Linpro AS and Varnish Software. This manual +page was written by Dag-Erling Sm?rgrav and later edited by +Poul-Henning Kamp and Per Buer. + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright (c) 2006 Verdens Gang AS +* Copyright (c) 2006-2008 Linpro AS +* Copyright (c) 2008-2010 Redpill Linpro AS +* Copyright (c) 2010 Varnish Software AS From perbu at varnish-cache.org Wed Jun 2 19:01:05 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Wed, 2 Jun 2010 21:01:05 +0200 Subject: r4880 - trunk/varnish-cache/doc/sphinx/tutorial Message-ID: Author: perbu Date: 2010-06-02 21:01:05 +0200 (Wed, 02 Jun 2010) New Revision: 4880 Modified: trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst Log: on vary and user agents Modified: trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst 2010-06-02 18:51:21 UTC (rev 4879) +++ trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst 2010-06-02 19:01:05 UTC (rev 4880) @@ -221,6 +221,17 @@ The code sets the Accept-Encoding header from the client to either gzip, deflate with a preference for gzip. +Pitfall - Vary: User-Agent +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Some applications or application servers send *Vary: User-Agent* along +with their content. This instructs Varnish to cache a separate copy +for every variation of User-Agent there is. There are plenty. Even a +single patchlevel of the same browser will generate at least 10 +different User-Agent headers based just on what operating system they +are running. So if you need to Vary based on User-Agent be sure to +normalize the header or your hit rate will suffer badly. + .. _tutorial-increasing_your_hitrate-pragma: Pragma From perbu at varnish-cache.org Thu Jun 3 07:57:44 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Thu, 3 Jun 2010 09:57:44 +0200 Subject: r4881 - trunk/varnish-cache/doc/sphinx/reference Message-ID: Author: perbu Date: 2010-06-03 09:57:44 +0200 (Thu, 03 Jun 2010) New Revision: 4881 Modified: trunk/varnish-cache/doc/sphinx/reference/index.rst Log: added man pages to toc Modified: trunk/varnish-cache/doc/sphinx/reference/index.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/index.rst 2010-06-02 19:01:05 UTC (rev 4880) +++ trunk/varnish-cache/doc/sphinx/reference/index.rst 2010-06-03 07:57:44 UTC (rev 4881) @@ -5,9 +5,14 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%% .. toctree:: - + varnishadm.rst shmem.rst + vcl.rst + varnishstat.rst + varnishsizes.rst + varnishreplay.rst + varnishlog.rst .. todo:: The programs: From phk at varnish-cache.org Fri Jun 4 09:46:25 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Fri, 4 Jun 2010 11:46:25 +0200 Subject: r4882 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-04 11:46:24 +0200 (Fri, 04 Jun 2010) New Revision: 4882 Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl.h trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c Log: Move the -n processing up to VSL_Arg() time Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-03 07:57:44 UTC (rev 4881) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-04 09:46:24 UTC (rev 4882) @@ -108,32 +108,25 @@ { int i; struct shmloghead slh; - char *logname; if (vd->vsl_lh != NULL) return (0); - if (vin_n_arg(vd->n_opt, NULL, NULL, &logname)) { - fprintf(stderr, "Invalid instance name: %s\n", - strerror(errno)); - return (1); - } - - vd->vsl_fd = open(logname, O_RDONLY); + vd->vsl_fd = open(vd->vsl, O_RDONLY); if (vd->vsl_fd < 0) { fprintf(stderr, "Cannot open %s: %s\n", - logname, strerror(errno)); + vd->vsl, strerror(errno)); return (1); } i = read(vd->vsl_fd, &slh, sizeof slh); if (i != sizeof slh) { fprintf(stderr, "Cannot read %s: %s\n", - logname, strerror(errno)); + vd->vsl, strerror(errno)); return (1); } if (slh.magic != SHMLOGHEAD_MAGIC) { fprintf(stderr, "Wrong magic number in file %s\n", - logname); + vd->vsl); return (1); } @@ -141,7 +134,7 @@ PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsl_fd, 0); if (vd->vsl_lh == MAP_FAILED) { fprintf(stderr, "Cannot mmap %s: %s\n", - logname, strerror(errno)); + vd->vsl, strerror(errno)); return (1); } vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-03 07:57:44 UTC (rev 4881) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-04 09:46:24 UTC (rev 4882) @@ -37,6 +37,7 @@ unsigned magic; #define VSL_MAGIC 0x6e3bd69b + char *vsl; int vsl_fd; struct shmloghead *vsl_lh; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-03 07:57:44 UTC (rev 4881) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-04 09:46:24 UTC (rev 4882) @@ -212,6 +212,11 @@ free(vd->n_opt); vd->n_opt = strdup(opt); assert(vd->n_opt != NULL); + if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->vsl)) { + fprintf(stderr, "Invalid instance name: %s\n", + strerror(errno)); + return (-1); + } return (1); case 'r': return (vsl_r_arg(vd, opt)); case 's': return (vsl_s_arg(vd, opt)); From phk at varnish-cache.org Fri Jun 4 10:52:59 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Fri, 4 Jun 2010 12:52:59 +0200 Subject: r4883 - in trunk/varnish-cache: include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-04 12:52:58 +0200 (Fri, 04 Jun 2010) New Revision: 4883 Modified: trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/base64.c trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl.h trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c trunk/varnish-cache/lib/libvarnishapi/vsl_log.c Log: cleanups Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-04 09:46:24 UTC (rev 4882) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-04 10:52:58 UTC (rev 4883) @@ -60,13 +60,13 @@ int VSL_Open(struct VSL_data *vd); void VSL_Delete(struct VSL_data *vd); struct varnish_stats *VSL_OpenStats(struct VSL_data *vd); -const char *VSL_Name(struct VSL_data *vd); +const char *VSL_Name(const struct VSL_data *vd); extern const char *VSL_tags[256]; void *VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident, unsigned *lenp); -struct shmalloc *vsl_iter0(struct VSL_data *vd); -void vsl_itern(struct VSL_data *vd, struct shmalloc **pp); +struct shmalloc *vsl_iter0(const struct VSL_data *vd); +void vsl_itern(const struct VSL_data *vd, struct shmalloc **pp); #define VSL_FOREACH(var, vd) \ for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var))) Modified: trunk/varnish-cache/lib/libvarnishapi/base64.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/base64.c 2010-06-04 09:46:24 UTC (rev 4882) +++ trunk/varnish-cache/lib/libvarnishapi/base64.c 2010-06-04 10:52:58 UTC (rev 4883) @@ -10,10 +10,9 @@ SVNID("$Id$") #include -#include #include "varnishapi.h" -static const char *b64 = +static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static char i64[256]; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-04 09:46:24 UTC (rev 4882) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-04 10:52:58 UTC (rev 4883) @@ -34,12 +34,11 @@ #include #include +#include #include -#include #include #include -#include #include #include #include @@ -98,6 +97,7 @@ vbit_destroy(vd->vbm_select); free(vd->n_opt); free(vd->rbuf); + free(vd->fname); free(vd); } @@ -112,21 +112,28 @@ if (vd->vsl_lh != NULL) return (0); - vd->vsl_fd = open(vd->vsl, O_RDONLY); + vd->vsl_fd = open(vd->fname, O_RDONLY); if (vd->vsl_fd < 0) { fprintf(stderr, "Cannot open %s: %s\n", - vd->vsl, strerror(errno)); + vd->fname, strerror(errno)); return (1); } + + assert(fstat(vd->vsl_fd, &vd->fstat) == 0); + if (!S_ISREG(vd->fstat.st_mode)) { + fprintf(stderr, "%s is not a regular file\n", vd->fname); + return (1); + } + i = read(vd->vsl_fd, &slh, sizeof slh); if (i != sizeof slh) { fprintf(stderr, "Cannot read %s: %s\n", - vd->vsl, strerror(errno)); + vd->fname, strerror(errno)); return (1); } if (slh.magic != SHMLOGHEAD_MAGIC) { fprintf(stderr, "Wrong magic number in file %s\n", - vd->vsl); + vd->fname); return (1); } @@ -134,7 +141,7 @@ PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsl_fd, 0); if (vd->vsl_lh == MAP_FAILED) { fprintf(stderr, "Cannot mmap %s: %s\n", - vd->vsl, strerror(errno)); + vd->fname, strerror(errno)); return (1); } vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size; @@ -160,7 +167,7 @@ /*--------------------------------------------------------------------*/ struct shmalloc * -vsl_iter0(struct VSL_data *vd) +vsl_iter0(const struct VSL_data *vd) { CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); @@ -171,7 +178,7 @@ } void -vsl_itern(struct VSL_data *vd, struct shmalloc **pp) +vsl_itern(const struct VSL_data *vd, struct shmalloc **pp) { CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); @@ -191,7 +198,7 @@ /*--------------------------------------------------------------------*/ static struct shmalloc * -vsl_find_alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident) +vsl_find_alloc(const struct VSL_data *vd, const char *class, const char *type, const char *ident) { struct shmalloc *sha; @@ -272,7 +279,7 @@ /*--------------------------------------------------------------------*/ const char * -VSL_Name(struct VSL_data *vd) +VSL_Name(const struct VSL_data *vd) { return (vd->n_opt); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-04 09:46:24 UTC (rev 4882) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-04 10:52:58 UTC (rev 4883) @@ -37,7 +37,8 @@ unsigned magic; #define VSL_MAGIC 0x6e3bd69b - char *vsl; + char *fname; + struct stat fstat; int vsl_fd; struct shmloghead *vsl_lh; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-04 09:46:24 UTC (rev 4882) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-04 10:52:58 UTC (rev 4883) @@ -33,13 +33,12 @@ SVNID("$Id$") #include -#include +#include #include #include #include #include -#include #include #include #include @@ -212,7 +211,7 @@ free(vd->n_opt); vd->n_opt = strdup(opt); assert(vd->n_opt != NULL); - if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->vsl)) { + if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) { fprintf(stderr, "Invalid instance name: %s\n", strerror(errno)); return (-1); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-04 09:46:24 UTC (rev 4882) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-04 10:52:58 UTC (rev 4883) @@ -33,13 +33,9 @@ SVNID("$Id$") #include -#include +#include #include -#include -#include -#include -#include #include #include #include From phk at varnish-cache.org Fri Jun 4 11:19:57 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Fri, 4 Jun 2010 13:19:57 +0200 Subject: r4884 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-04 13:19:57 +0200 (Fri, 04 Jun 2010) New Revision: 4884 Added: trunk/varnish-cache/include/vas.h Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/Makefile.am trunk/varnish-cache/include/libvarnish.h trunk/varnish-cache/lib/libvarnish/assert.c trunk/varnish-cache/lib/libvarnish/num.c trunk/varnish-cache/lib/libvarnishapi/Makefile.am trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c trunk/varnish-cache/lib/libvarnishapi/vsl_log.c Log: Use the same assert code in libvarnishapi as in libvarnish Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2010-06-04 10:52:58 UTC (rev 4883) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2010-06-04 11:19:57 UTC (rev 4884) @@ -367,7 +367,7 @@ PAN_Init(void) { - lbv_assert = pan_ic; + vas_fail = pan_ic; vsp = &vsps; AN(vsb_new(vsp, loghead->panicstr, sizeof loghead->panicstr, VSB_FIXEDLEN)); Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-06-04 10:52:58 UTC (rev 4883) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-06-04 11:19:57 UTC (rev 4884) @@ -902,7 +902,7 @@ va_start(ap, str); b = vrt_assemble_string(sp->http, "PANIC: ", str, ap); va_end(ap); - lbv_assert("VCL", "", 0, b, 0, 2); + vas_fail("VCL", "", 0, b, 0, 2); } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/include/Makefile.am =================================================================== --- trunk/varnish-cache/include/Makefile.am 2010-06-04 10:52:58 UTC (rev 4883) +++ trunk/varnish-cache/include/Makefile.am 2010-06-04 11:19:57 UTC (rev 4884) @@ -29,6 +29,7 @@ persistent.h \ purge_vars.h \ svnid.h \ + vas.h \ vsha256.h \ vqueue.h \ vpf.h \ Modified: trunk/varnish-cache/include/libvarnish.h =================================================================== --- trunk/varnish-cache/include/libvarnish.h 2010-06-04 10:52:58 UTC (rev 4883) +++ trunk/varnish-cache/include/libvarnish.h 2010-06-04 11:19:57 UTC (rev 4884) @@ -33,6 +33,8 @@ #include #include +#include "vas.h" + #ifndef NULL #define NULL ((void*)0) #endif @@ -103,48 +105,6 @@ int vtmpfile(char *); char *vreadfile(const char *fn); -/* - * assert(), AN() and AZ() are static checks that should not happen. - * In general asserts should be cheap, such as checking return - * values and similar. - * diagnostic() are asserts which are so expensive that we may want - * to compile them out for performance at a later date. - * xxxassert(), XXXAN() and XXXAZ() marks conditions we ought to - * handle gracefully, such as malloc failure. - */ - -typedef void lbv_assert_f(const char *, const char *, int, const char *, - int, int); - -extern lbv_assert_f *lbv_assert; - -#ifdef WITHOUT_ASSERTS -#define assert(e) ((void)(e)) -#else /* WITH_ASSERTS */ -#define assert(e) \ -do { \ - if (!(e)) \ - lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 0); \ -} while (0) -#endif - -#define xxxassert(e) \ -do { \ - if (!(e)) \ - lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 1); \ -} while (0) - -/* Assert zero return value */ -#define AZ(foo) do { assert((foo) == 0); } while (0) -#define AN(foo) do { assert((foo) != 0); } while (0) -#define XXXAZ(foo) do { xxxassert((foo) == 0); } while (0) -#define XXXAN(foo) do { xxxassert((foo) != 0); } while (0) -#define diagnostic(foo) assert(foo) -#define WRONG(expl) \ -do { \ - lbv_assert(__func__, __FILE__, __LINE__, expl, errno, 3); \ - abort(); \ -} while (0) const char* svn_version(void); /* Safe printf into a fixed-size buffer */ Copied: trunk/varnish-cache/include/vas.h (from rev 4881, trunk/varnish-cache/include/libvarnish.h) =================================================================== --- trunk/varnish-cache/include/vas.h (rev 0) +++ trunk/varnish-cache/include/vas.h 2010-06-04 11:19:57 UTC (rev 4884) @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2009 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + * + * assert(), AN() and AZ() are static checks that should not happen. + * In general asserts should be cheap, such as checking return + * values and similar. + * diagnostic() are asserts which are so expensive that we may want + * to compile them out for performance at a later date. + * xxxassert(), XXXAN() and XXXAZ() marks conditions we ought to + * handle gracefully, such as malloc failure. + */ + +#ifndef VAS_H_INCLUDED +#define VAS_H_INCLUDED + +#include + +typedef void vas_f(const char *, const char *, int, const char *, int, int); + +extern vas_f *vas_fail; + +#ifdef WITHOUT_ASSERTS +#define assert(e) ((void)(e)) +#else /* WITH_ASSERTS */ +#define assert(e) \ +do { \ + if (!(e)) \ + vas_fail(__func__, __FILE__, __LINE__, #e, errno, 0); \ +} while (0) +#endif + +#define xxxassert(e) \ +do { \ + if (!(e)) \ + vas_fail(__func__, __FILE__, __LINE__, #e, errno, 1); \ +} while (0) + +/* Assert zero return value */ +#define AZ(foo) do { assert((foo) == 0); } while (0) +#define AN(foo) do { assert((foo) != 0); } while (0) +#define XXXAZ(foo) do { xxxassert((foo) == 0); } while (0) +#define XXXAN(foo) do { xxxassert((foo) != 0); } while (0) +#define diagnostic(foo) assert(foo) +#define WRONG(expl) \ +do { \ + vas_fail(__func__, __FILE__, __LINE__, expl, errno, 3); \ + abort(); \ +} while (0) + +#endif Modified: trunk/varnish-cache/lib/libvarnish/assert.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/assert.c 2010-06-04 10:52:58 UTC (rev 4883) +++ trunk/varnish-cache/lib/libvarnish/assert.c 2010-06-04 11:19:57 UTC (rev 4884) @@ -41,7 +41,7 @@ #include "libvarnish.h" static void -lbv_assert_default(const char *func, const char *file, int line, +vas_fail_default(const char *func, const char *file, int line, const char *cond, int err, int xxx) { @@ -62,4 +62,4 @@ abort(); } -lbv_assert_f *lbv_assert = lbv_assert_default; +vas_f *vas_fail = vas_fail_default; Modified: trunk/varnish-cache/lib/libvarnish/num.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/num.c 2010-06-04 10:52:58 UTC (rev 4883) +++ trunk/varnish-cache/lib/libvarnish/num.c 2010-06-04 11:19:57 UTC (rev 4884) @@ -115,7 +115,7 @@ #ifdef NUM_C_TEST /* Compile with: "cc -o foo -DNUM_C_TEST -I../.. -I../../include num.c -lm" */ -#include +#include "vas.h" #include #include #include Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-04 10:52:58 UTC (rev 4883) +++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-04 11:19:57 UTC (rev 4884) @@ -10,6 +10,7 @@ vsl.h \ \ ../libvarnish/vin.c \ + ../libvarnish/assert.c \ base64.c \ vsl.c \ vsl_arg.c \ Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-04 10:52:58 UTC (rev 4883) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-04 11:19:57 UTC (rev 4884) @@ -36,7 +36,6 @@ #include #include -#include #include #include #include @@ -44,6 +43,7 @@ #include #include +#include "vas.h" #include "shmlog.h" #include "vre.h" #include "vbm.h" Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-04 10:52:58 UTC (rev 4883) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-04 11:19:57 UTC (rev 4884) @@ -35,7 +35,6 @@ #include #include -#include #include #include #include @@ -44,6 +43,7 @@ #include #include +#include "vas.h" #include "shmlog.h" #include "vre.h" #include "vbm.h" Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-04 10:52:58 UTC (rev 4883) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-04 11:19:57 UTC (rev 4884) @@ -35,12 +35,12 @@ #include #include -#include #include #include #include #include +#include "vas.h" #include "shmlog.h" #include "vre.h" #include "vbm.h" From phk at varnish-cache.org Fri Jun 4 11:59:35 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Fri, 4 Jun 2010 13:59:35 +0200 Subject: r4885 - trunk/varnish-cache/bin/varnishstat Message-ID: Author: phk Date: 2010-06-04 13:59:35 +0200 (Fri, 04 Jun 2010) New Revision: 4885 Modified: trunk/varnish-cache/bin/varnishstat/Makefile.am Log: We do not need libvarnish here. (It should be readily possible to access the shmlog using just libvarnishapi, but for some of or more advanced support programs, we will use the smart stuff in libvarnish to improve code quality) Modified: trunk/varnish-cache/bin/varnishstat/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishstat/Makefile.am 2010-06-04 11:19:57 UTC (rev 4884) +++ trunk/varnish-cache/bin/varnishstat/Makefile.am 2010-06-04 11:59:35 UTC (rev 4885) @@ -13,7 +13,6 @@ varnishstat_curses.c varnishstat_LDADD = \ - $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${CURSES_LIBS} ${RT_LIBS} ${PTHREAD_LIBS} From phk at varnish-cache.org Fri Jun 4 12:02:19 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Fri, 4 Jun 2010 14:02:19 +0200 Subject: r4886 - in trunk/varnish-cache/bin: varnishhist varnishsizes varnishtop Message-ID: Author: phk Date: 2010-06-04 14:02:19 +0200 (Fri, 04 Jun 2010) New Revision: 4886 Modified: trunk/varnish-cache/bin/varnishhist/Makefile.am trunk/varnish-cache/bin/varnishsizes/Makefile.am trunk/varnish-cache/bin/varnishtop/Makefile.am Log: These do not need libvarnish Modified: trunk/varnish-cache/bin/varnishhist/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishhist/Makefile.am 2010-06-04 11:59:35 UTC (rev 4885) +++ trunk/varnish-cache/bin/varnishhist/Makefile.am 2010-06-04 12:02:19 UTC (rev 4886) @@ -9,7 +9,6 @@ varnishhist_SOURCES = varnishhist.c varnishhist_LDADD = \ - $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ -lm \ Modified: trunk/varnish-cache/bin/varnishsizes/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishsizes/Makefile.am 2010-06-04 11:59:35 UTC (rev 4885) +++ trunk/varnish-cache/bin/varnishsizes/Makefile.am 2010-06-04 12:02:19 UTC (rev 4886) @@ -9,7 +9,6 @@ varnishsizes_SOURCES = varnishsizes.c varnishsizes_LDADD = \ - $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ -lm \ Modified: trunk/varnish-cache/bin/varnishtop/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishtop/Makefile.am 2010-06-04 11:59:35 UTC (rev 4885) +++ trunk/varnish-cache/bin/varnishtop/Makefile.am 2010-06-04 12:02:19 UTC (rev 4886) @@ -9,7 +9,6 @@ varnishtop_SOURCES = varnishtop.c varnishtop_LDADD = \ - $(top_builddir)/lib/libvarnish/libvarnish.la \ $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ $(top_builddir)/lib/libvarnishapi/libvarnishapi.la \ ${CURSES_LIBS} ${PTHREAD_LIBS} From phk at varnish-cache.org Fri Jun 4 12:30:42 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Fri, 4 Jun 2010 14:30:42 +0200 Subject: r4887 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-04 14:30:42 +0200 (Fri, 04 Jun 2010) New Revision: 4887 Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am Log: Add bits from libvarnish to libvarnishapi for improved stand-alone-ish-ness. Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-04 12:02:19 UTC (rev 4886) +++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-04 12:30:42 UTC (rev 4887) @@ -1,6 +1,6 @@ # $Id$ -INCLUDES = -I$(top_srcdir)/include +INCLUDES = -I$(top_srcdir)/include @PCRE_CFLAGS@ lib_LTLIBRARIES = libvarnishapi.la @@ -9,8 +9,11 @@ libvarnishapi_la_SOURCES = \ vsl.h \ \ + ../libvarnish/assert.c \ + ../libvarnish/svn_version.c \ + ../libvarnish/version.c \ ../libvarnish/vin.c \ - ../libvarnish/assert.c \ + ../libvarnish/vre.c \ base64.c \ vsl.c \ vsl_arg.c \ @@ -18,3 +21,5 @@ libvarnishapi_la_CFLAGS = \ -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' + +libvarnishapi_la_LIBADD = @PCRE_LIBS@ From perbu at varnish-cache.org Fri Jun 4 18:35:27 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Fri, 4 Jun 2010 20:35:27 +0200 Subject: r4888 - in trunk/varnish-cache/doc/sphinx: installation reference Message-ID: Author: perbu Date: 2010-06-04 20:35:26 +0200 (Fri, 04 Jun 2010) New Revision: 4888 Added: trunk/varnish-cache/doc/sphinx/reference/varnishd.rst trunk/varnish-cache/doc/sphinx/reference/varnishhist.rst trunk/varnish-cache/doc/sphinx/reference/varnishncsa.rst trunk/varnish-cache/doc/sphinx/reference/varnishtest.rst trunk/varnish-cache/doc/sphinx/reference/varnishtop.rst Modified: trunk/varnish-cache/doc/sphinx/installation/install.rst trunk/varnish-cache/doc/sphinx/reference/index.rst Log: another bunch of man pages. Some have rendering issues that need I need to work out Modified: trunk/varnish-cache/doc/sphinx/installation/install.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/installation/install.rst 2010-06-04 12:30:42 UTC (rev 4887) +++ trunk/varnish-cache/doc/sphinx/installation/install.rst 2010-06-04 18:35:26 UTC (rev 4888) @@ -1,8 +1,7 @@ .. _install-doc: -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -Installing Varnish on your computer -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +Installing Varnish +================== With open source software, you can choose to install binary packages or compile stuff from source-code. To install a package or compile @@ -11,8 +10,8 @@ are most confortable with. -Installing Varnish from packages -================================ +Source or packages? +~~~~~~~~~~~~~~~~~~~ Installing Varnish on most relevant operating systems can usually be done with with the systems package manager, typical examples Modified: trunk/varnish-cache/doc/sphinx/reference/index.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/index.rst 2010-06-04 12:30:42 UTC (rev 4887) +++ trunk/varnish-cache/doc/sphinx/reference/index.rst 2010-06-04 18:35:26 UTC (rev 4888) @@ -5,14 +5,19 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%% .. toctree:: - + + vcl.rst varnishadm.rst + varnishd.rst + varnishhist.rst + varnishlog.rst + varnishncsa.rst + varnishreplay.rst + varnishsizes.rst + varnishstat.rst + varnishtest.rst + varnishtop.rst shmem.rst - vcl.rst - varnishstat.rst - varnishsizes.rst - varnishreplay.rst - varnishlog.rst .. todo:: The programs: Added: trunk/varnish-cache/doc/sphinx/reference/varnishd.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishd.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/varnishd.rst 2010-06-04 18:35:26 UTC (rev 4888) @@ -0,0 +1,829 @@ +========= + varnishd +========= + +----------------------- +HTTP accelerator daemon +----------------------- + +:Author: Dag-Erling Sm?rgrav +:Author: Stig Sandbeck Mathisen +:Author: Per Buer +:Date: 2010-05-31 +:Version: 1.0 +:Manual section: 1 + + +SYNOPSIS +======== + +varnishd [-a address[:port]] [-b host[:port]] [-d] [-F] [-f config] + [-g group] [-h type[,options]] [-i identity] + [-l shmlogsize] [-n name] [-P file] [-p param=value] + [-s type[,options]] [-T address[:port]] [-t ttl] + [-u user] [-V] [-w min[,max[,timeout]]] + +DESCRIPTION +=========== + +The varnishd daemon accepts HTTP requests from clients, passes them on to a backend server and caches the +returned documents to better satisfy future requests for the same document. + +OPTIONS +======= + +-a address[:port][,address[:port][...] + 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, the default HTTP port as + listed in /etc/services is used. Multiple listening addresses and ports can be speci? + fied as a whitespace- or comma-separated list. + +-b host[:port] + Use the specified host as backend server. If port is not specified, + the default is 8080. + +-d Enables debugging mode: The parent process runs in the foreground with a CLI connection + on stdin/stdout, and the child process must be started explicitly with a CLI command. + Terminating the parent process will also terminate the child. + +-F Run in the foreground. + +-f config Use the specified VCL configuration file instead of the builtin default. See vcl(7) for + details on VCL syntax. + +-g group Specifies the name of an unprivileged group to which the child process should switch + before it starts accepting connections. This is a shortcut for specifying the group + run-time parameter. + +-h type[,options] + Specifies the hash algorithm. See Hash Algorithms for a list of supported algorithms. + +-i identity + Specify the identity of the varnish server. This can be accessed using server.identity + from VCL + +-l shmlogsize + Specify size of shmlog file. Scaling suffixes like 'k', 'm' can be used up to + (e)tabytes. Default is 80 Megabytes. Specifying less than 8 Megabytes is unwise. + +-n name Specify a name for this instance. Amonst other things, this name is used to construct + the name of the directory in which varnishd keeps temporary files and persistent state. + If the specified name begins with a forward slash, it is interpreted as the absolute + path to the directory which should be used for this purpose. + +-P file Write the process's PID to the specified file. + +-p param=value + Set the parameter specified by param to the specified value. See Run-Time + Parameters for a list of parameters. This option can be used multiple + times to specify multiple parameters. + +-S file Path to a file containing a secret used for authorizing access to the management port. + +-s type[,options] + Use the specified storage backend. See Storage Types for a list of supported storage + types. This option can be used multiple times to specify multiple storage files. + +-T address[:port] + Offer a management interface on the specified address and port. See Management + Interface for a list of management commands. + +-t ttl Specifies a hard minimum time to live for cached documents. This is a shortcut for + specifying the default_ttl run-time parameter. + +-u user Specifies the name of an unprivileged user to which the child process should switch + before it starts accepting connections. This is a shortcut for specifying the user run- + time parameter. + + If specifying both a user and a group, the user should be specified first. + +-V Display the version number and exit. + +-w min[,max[,timeout]] + Start at least min but no more than max worker threads with the specified idle timeout. + This is a shortcut for specifying the thread_pool_min, thread_pool_max and + thread_pool_timeout run-time parameters. + + If only one number is specified, thread_pool_min and thread_pool_max are both set to + this number, and thread_pool_timeout has no effect. + + + + + +Hash Algorithms +--------------- + +The following hash algorithms are available: + +simple_list + A simple doubly-linked list. Not recommended for production use. + +classic[,buckets] + A standard hash table. This is the default. The hash key is the + CRC32 of the object's URL modulo the size of the hash table. Each + table entry points to a list of elements which share the same hash + key. The buckets parameter specifies the number of entries in the + hash table. The default is 16383. + +critbit XXX + Very nice. + +Storage Types +------------- + +The following storage types are available: + +malloc[,size] + Storage for each object is allocated with malloc(3). + + The size parameter specifies the maximum amount of memory varnishd will allocate. The size is assumed to + be in bytes, unless followed by one of the following suffixes: + + K, k The size is expressed in kibibytes. + + M, m The size is expressed in mebibytes. + + G, g The size is expressed in gibibytes. + + T, t The size is expressed in tebibytes. + + The default size is unlimited. + +file[,path[,size[,granularity]]] + Storage for each object is allocated from an arena backed by a file. This is the default. + + The path parameter specifies either the path to the backing file or the path to a directory in which + varnishd will create the backing file. The default is /tmp. + + The size parameter specifies the size of the backing file. The size is assumed to be in bytes, unless fol? + lowed by one of the following suffixes: + + K, k The size is expressed in kibibytes. + + M, m The size is expressed in mebibytes. + + G, g The size is expressed in gibibytes. + + T, t The size is expressed in tebibytes. + + % The size is expressed as a percentage of the free space on the file system where it resides. + + The default size is 50%. + + If the backing file already exists, it will be truncated or expanded to the specified size. + + Note that if varnishd has to create or expand the file, it will not pre-allocate the added space, leading + to fragmentation, which may adversely impact performance. Pre-creating the storage file using dd(1) will + reduce fragmentation to a minimum. + + The granularity parameter specifies the granularity of allocation. All allocations are rounded up to this + size. The size is assumed to be in bytes, unless followed by one of the suffixes described for size except + for %. + + The default size is the VM page size. The size should be reduced if you have many small objects. + +persistence[XXX] + New, shiny, better. + + +Management Interface +-------------------- + +If the -T option was specified, varnishd will offer a command-line management interface on the specified address +and port. The following commands are available: + +help [command] + Display a list of available commands. + + If the command is specified, display help for this command. + +param.set param value + Set the parameter specified by param to the specified value. See Run-Time Parameters for a list of parame? + ters. + +param.show [-l] [param] + Display a list if run-time parameters and their values. + + If the -l option is specified, the list includes a brief explanation of each parameter. + + If a param is specified, display only the value and explanation for this parameter. + +ping [timestamp] + Ping the Varnish cache process, keeping the connection alive. + +purge field operator argument [&& field operator argument [...]] + Immediately invalidate all documents matching the purge expression. See Purge expressions for more docu? + mentation and examples. + +purge.list + Display the purge list. + + All requests for objects from the cache are matched against items on the purge list. If an object in the + cache is older than a matching purge list item, it is considered "purged", and will be fetched from the + backend instead. + + When a purge expression is older than all the objects in the cache, it is removed from the list. + +purge.url regexp + Immediately invalidate all documents whose URL matches the specified regular expression. + +quit Close the connection to the varnish admin port. + +start + Start the Varnish cache process if it is not already running. + +stats + Show summary statistics. + + All the numbers presented are totals since server startup; for a better idea of the current situation, use + the varnishstat(1) utility. + +status + Check the status of the Varnish cache process. + +stop Stop the Varnish cache process. + +url.purge regexp + Deprecated, see purge.url instead. + +vcl.discard configname + Discard the configuration specified by configname. This will have no effect if the specified configuration + has a non-zero reference count. + +vcl.inline configname vcl + Create a new configuration named configname with the VCL code specified by vcl, which must be a quoted + string. + +vcl.list + List available configurations and their respective reference counts. The active configuration is indicated + with an asterisk ("*"). + +vcl.load configname filename + Create a new configuration named configname with the contents of the specified file. + +vcl.show configname + Display the source code for the specified configuration. + +vcl.use configname + Start using the configuration specified by configname for all new requests. Existing requests will con? + tinue using whichever configuration was in use when they arrived. + +Run-Time Parameters +------------------- + +Runtime parameters are marked with shorthand flags to avoid repeating the same text over and over in the table +below. The meaning of the flags are: + +experimental + We have no solid information about good/bad/optimal values for this parameter. Feedback with experience + and observations are most welcome. + +delayed + This parameter can be changed on the fly, but will not take effect immediately. + +restart + The worker process must be stopped and restarted, before this parameter takes effect. + +reload + The VCL programs must be reloaded for this parameter to take effect. + +Here is a list of all parameters, current as of last time we remembered to update the manual page. This text is +produced from the same text you will find in the CLI if you use the param.show command, so should there be a new +parameter which is not listed here, you can find the description using the CLI commands. + +Be aware that on 32 bit systems, certain default values, such as sess_workspace (=16k) and thread_pool_stack +(=64k) are reduced relative to the values listed here, in order to conserve VM space. + +acceptor_sleep_decay + Default: 0.900 + Flags: experimental + + If we run out of resources, such as file descriptors or worker threads, the acceptor will sleep between + accepts. + This parameter (multiplicatively) reduce the sleep duration for each succesfull accept. (ie: 0.9 = reduce + by 10%) + +acceptor_sleep_incr + Units: s + Default: 0.001 + Flags: experimental + + If we run out of resources, such as file descriptors or worker threads, the acceptor will sleep between + accepts. + This parameter control how much longer we sleep, each time we fail to accept a new connection. + +acceptor_sleep_max + Units: s + Default: 0.050 + Flags: experimental + + If we run out of resources, such as file descriptors or worker threads, the acceptor will sleep between + accepts. + This parameter limits how long it can sleep between attempts to accept new connections. + +auto_restart + Units: bool + Default: on + + Restart child process automatically if it dies. + +ban_lurker_sleep + Units: s + Default: 0.0 + + How long time does the ban lurker thread sleeps between successfull attempts to push the last item up the + purge list. It always sleeps a second when nothing can be done. + A value of zero disables the ban lurker. + +between_bytes_timeout + Units: s + Default: 60 + + Default timeout between bytes when receiving data from backend. We only wait for this many seconds between + bytes before giving up. A value of 0 means it will never time out. VCL can override this default value for + each backend request and backend request. This parameter does not apply to pipe. + +cache_vbe_conns + Units: bool + Default: off + Flags: experimental + + Cache vbe_conn's or rely on malloc, that's the question. + +cc_command + Default: exec cc -fpic -shared -Wl,-x -o %o %s + Flags: must_reload + + Command used for compiling the C source code to a dlopen(3) loadable object. Any occurrence of %s in the + string will be replaced with the source file name, and %o will be replaced with the output file name. + +cli_buffer + Units: bytes + Default: 8192 + + Size of buffer for CLI input. + You may need to increase this if you have big VCL files and use the vcl.inline CLI command. + NB: Must be specified with -p to have effect. + +cli_timeout + Units: seconds + Default: 10 + + Timeout for the childs replies to CLI requests from the master. + +clock_skew + Units: s + Default: 10 + + How much clockskew we are willing to accept between the backend and our own clock. + +connect_timeout + Units: s + Default: 0.4 + + Default connection timeout for backend connections. We only try to connect to the backend for this many + seconds before giving up. VCL can override this default value for each backend and backend request. + +default_grace + Default: 10seconds + Flags: delayed + + Default grace period. We will deliver an object this long after it has expired, provided another thread is + attempting to get a new copy. + +default_ttl + Units: seconds + Default: 120 + + The TTL assigned to objects if neither the backend nor the VCL code assigns one. + Objects already cached will not be affected by changes made until they are fetched from the backend again. + To force an immediate effect at the expense of a total flush of the cache use "purge.url ." + +diag_bitmap + Units: bitmap + Default: 0 + Bitmap controlling diagnostics code:: + + 0x00000001 - CNT_Session states. + 0x00000002 - workspace debugging. + 0x00000004 - kqueue debugging. + 0x00000008 - mutex logging. + 0x00000010 - mutex contests. + 0x00000020 - waiting list. + 0x00000040 - object workspace. + 0x00001000 - do not core-dump child process. + 0x00002000 - only short panic message. + 0x00004000 - panic to stderr. + 0x00008000 - panic to abort2(). + 0x00010000 - synchronize shmlog. + 0x00020000 - synchronous start of persistence. + 0x80000000 - do edge-detection on digest. + + Use 0x notation and do the bitor in your head :-) + +err_ttl + Units: seconds + Default: 0 + + The TTL assigned to the synthesized error pages + +esi_syntax + Units: bitmap + Default: 0 + Bitmap controlling ESI parsing code:: + + 0x00000001 - Don't check if it looks like XML + 0x00000002 - Ignore non-esi elements + 0x00000004 - Emit parsing debug records + + Use 0x notation and do the bitor in your head :-) + +fetch_chunksize + Units: kilobytes + Default: 128 + Flags: experimental + + The default chunksize used by fetcher. This should be bigger than the majority of objects with short TTLs. + Internal limits in the storage_file module makes increases above 128kb a dubious idea. + +first_byte_timeout + Units: s + Default: 60 + + Default timeout for receiving first byte from backend. We only wait for this many seconds for the first + byte before giving up. A value of 0 means it will never time out. VCL can override this default value for + each backend and backend request. This parameter does not apply to pipe. + +group + Default: ..... + Flags: must_restart + + The unprivileged group to run as. + +http_headers + Units: header lines + Default: 64 + + Maximum number of HTTP headers we will deal with. + This space is preallocated in sessions and workthreads only objects allocate only space for the headers + they store. + +listen_address + Default: :80 + Flags: must_restart + + Whitespace separated list of network endpoints where Varnish will accept requests. + Possible formats: host, host:port, :port + +listen_depth + Units: connections + Default: 1024 + Flags: must_restart + + Listen queue depth. + +log_hashstring + Units: bool + Default: off + + Log the hash string to shared memory log. + +log_local_address + Units: bool + Default: off + + Log the local address on the TCP connection in the SessionOpen shared memory record. + +lru_interval + Units: seconds + Default: 2 + Flags: experimental + + Grace period before object moves on LRU list. + Objects are only moved to the front of the LRU list if they have not been moved there already inside this + timeout period. This reduces the amount of lock operations necessary for LRU list access. + +max_esi_includes + Units: includes + Default: 5 + + Maximum depth of esi:include processing. + +max_restarts + Units: restarts + Default: 4 + + Upper limit on how many times a request can restart. + Be aware that restarts are likely to cause a hit against the backend, so don't increase thoughtlessly. + +overflow_max + Units: % + Default: 100 + Flags: experimental + + Percentage permitted overflow queue length. + + This sets the ratio of queued requests to worker threads, above which sessions will be dropped instead of + queued. + +ping_interval + Units: seconds + Default: 3 + Flags: must_restart + + Interval between pings from parent to child. + Zero will disable pinging entirely, which makes it possible to attach a debugger to the child. + +pipe_timeout + Units: seconds + Default: 60 + + Idle timeout for PIPE sessions. If nothing have been received in either direction for this many seconds, + the session is closed. + +prefer_ipv6 + Units: bool + Default: off + + Prefer IPv6 address when connecting to backends which have both IPv4 and IPv6 addresses. + +purge_dups + Units: bool + Default: on + + Detect and eliminate duplicate purges. + +rush_exponent + Units: requests per request + Default: 3 + Flags: experimental + + How many parked request we start for each completed request on the object. + NB: Even with the implict delay of delivery, this parameter controls an exponential increase in number of + worker threads. + +saintmode_threshold + Units: objects + Default: 10 + Flags: experimental + + The maximum number of objects held off by saint mode before no further will be made to the backend until + one times out. A value of 0 disables saintmode. +send_timeout + Units: seconds + Default: 600 + Flags: delayed + + Send timeout for client connections. If no data has been sent to the client in this many seconds, the ses? + sion is closed. + See setsockopt(2) under SO_SNDTIMEO for more information. + +sendfile_threshold + Units: bytes + Default: -1 + Flags: experimental + + The minimum size of objects transmitted with sendfile. + +sess_timeout + Units: seconds + Default: 5 + + Idle timeout for persistent sessions. If a HTTP request has not been received in this many seconds, the + session is closed. + +sess_workspace + Units: bytes + Default: 65536 + Flags: delayed + + Bytes of HTTP protocol workspace allocated for sessions. This space must be big enough for the entire HTTP + protocol header and any edits done to it in the VCL code. + Minimum is 1024 bytes. + +session_linger + Units: ms + Default: 50 + Flags: experimental + + How long time the workerthread lingers on the session to see if a new request appears right away. + If sessions are reused, as much as half of all reuses happen within the first 100 msec of the previous + request completing. + Setting this too high results in worker threads not doing anything for their keep, setting it too low just + means that more sessions take a detour around the waiter. + +session_max + Units: sessions + Default: 100000 + + Maximum number of sessions we will allocate before just dropping connections. + This is mostly an anti-DoS measure, and setting it plenty high should not hurt, as long as you have the + memory for it. + +shm_reclen + Units: bytes + Default: 255 + + Maximum number of bytes in SHM log record. + Maximum is 65535 bytes. + +shm_workspace + Units: bytes + Default: 8192 + Flags: delayed + + Bytes of shmlog workspace allocated for worker threads. If too big, it wastes some ram, if too small it + causes needless flushes of the SHM workspace. + These flushes show up in stats as "SHM flushes due to overflow". + Minimum is 4096 bytes. + +syslog_cli_traffic + Units: bool + Default: on + + Log all CLI traffic to syslog(LOG_INFO). + +thread_pool_add_delay + Units: milliseconds + Default: 20 + Flags: experimental + + Wait at least this long between creating threads. + + Setting this too long results in insuffient worker threads. + + Setting this too short increases the risk of worker thread pile-up. + +thread_pool_add_threshold + Units: requests + Default: 2 + Flags: experimental + + Overflow threshold for worker thread creation. + + Setting this too low, will result in excess worker threads, which is generally a bad idea. + + Setting it too high results in insuffient worker threads. + +thread_pool_fail_delay + Units: milliseconds + Default: 200 + Flags: experimental + + Wait at least this long after a failed thread creation before trying to create another thread. + + Failure to create a worker thread is often a sign that the end is near, because the process is running out + of RAM resources for thread stacks. + This delay tries to not rush it on needlessly. + + If thread creation failures are a problem, check that thread_pool_max is not too high. + + It may also help to increase thread_pool_timeout and thread_pool_min, to reduce the rate at which treads + are destroyed and later recreated. + +thread_pool_max + Units: threads + Default: 500 + Flags: delayed, experimental + + The maximum number of worker threads in all pools combined. + + Do not set this higher than you have to, since excess worker threads soak up RAM and CPU and generally just + get in the way of getting work done. + +thread_pool_min + Units: threads + Default: 5 + Flags: delayed, experimental + + The minimum number of threads in each worker pool. + + Increasing this may help ramp up faster from low load situations where threads have expired. + + Minimum is 2 threads. + +thread_pool_purge_delay + Units: milliseconds + Default: 1000 + Flags: delayed, experimental + + Wait this long between purging threads. + + This controls the decay of thread pools when idle(-ish). + + Minimum is 100 milliseconds. + +thread_pool_stack + Units: bytes + Default: -1 + Flags: experimental + + Worker thread stack size. In particular on 32bit systems you may need to tweak this down to fit many + threads into the limited address space. + +thread_pool_timeout + Units: seconds + Default: 300 + Flags: delayed, experimental + + Thread idle threshold. + + Threads in excess of thread_pool_min, which have been idle for at least this long are candidates for purg? + ing. + + Minimum is 1 second. + +thread_pools + Units: pools + Default: 2 + Flags: delayed, experimental + + Number of worker thread pools. + + Increasing number of worker pools decreases lock contention. + + Too many pools waste CPU and RAM resources, and more than one pool for each CPU is probably detrimal to + performance. + + Can be increased on the fly, but decreases require a restart to take effect. + +thread_stats_rate + Units: requests + Default: 10 + Flags: experimental + + Worker threads accumulate statistics, and dump these into the global stats counters if the lock is free + when they finish a request. + This parameters defines the maximum number of requests a worker thread may handle, before it is forced to + dump its accumulated stats into the global counters. + +user Default: ..... + Flags: must_restart + + The unprivileged user to run as. Setting this will also set "group" to the specified user's primary group. + +vcl_trace + Units: bool + Default: off + + Trace VCL execution in the shmlog. + Enabling this will allow you to see the path each request has taken through the VCL program. + This generates a lot of logrecords so it is off by default. + +waiter + Default: default + Flags: must_restart, experimental + + Select the waiter kernel interface. + + +Purge expressions +----------------- + +A purge expression consists of one or more conditions. A condition consists of a field, an operator, and an +argument. Conditions can be ANDed together with "&&". + +A field can be any of the variables from VCL, for instance req.url, req.http.host or obj.set-cookie. + +Operators are "==" for direct comparision, "~" for a regular expression match, and ">" or "<" for size compar? +isons. Prepending an operator with "!" negates the expression. + +The argument could be a quoted string, a regexp, or an integer. Integers can have "KB", "MB", "GB" or "TB" +appended for size related fields. + +Simple example: All requests where req.url exactly matches the string /news are purged from the cache. + + req.url == "/news" + +Example: Purge all documents where the name does not end with ".ogg", and where the size of the object is greater +than 10 megabytes. + + req.url !~ "\.ogg$" && obj.size > 10MB + +Example: Purge 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 ~ "^(www\.)example.com$" && obj.set-cookie ~ "USERID=1663" + +SEE ALSO +======== + +* varnishlog(1) +* varnishhist(1) +* varnishncsa(1) +* varnishstat(1) +* varnishtop(1) +* vcl(7) + +HISTORY +======= + +The varnishd daemon was developed by Poul-Henning Kamp in cooperation +with Verdens Gang AS, Linpro AS and Varnish Software. + +This manual page was written by Dag-Erling Sm?rgrav with updates by +Stig Sandbeck Mathisen ?ssm at debian.org? + Added: trunk/varnish-cache/doc/sphinx/reference/varnishhist.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishhist.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/varnishhist.rst 2010-06-04 18:35:26 UTC (rev 4888) @@ -0,0 +1,86 @@ +=========== +varnishhist +=========== + +------------------------- +Varnish request histogram +------------------------- + +SYNOPSIS +======== + +varnishhist [-b] [-C] [-c] [-d] [-I regex] [-i tag] [-n varnish_name] +[-r file] [-V] [-w delay] [-X regex] [-x tag] + +DESCRIPTION +=========== + +The varnishhist utility reads varnishd(1) shared memory logs and +presents a continuously updated histogram show? ing the distribution +of the last N requests by their processing. The value of N and the +vertical scale are dis? played in the top left corner. The horizontal +scale is logarithmic. Hits are marked with a pipe character ("|"), +and misses are marked with a hash character ("#"). + +The following options are available: + +-b Include log entries which result from communication with + a backend server. If neither -b nor -c is + specified, varnishhist acts as if they both were. + +-C Ignore case when matching regular expressions. + +-c Include log entries which result from communication with + a client. If neither -b nor -c is specified, + varnishhist acts as if they both were. + +-d Process old log entries on startup. Normally, varnishhist + will only process entries which are written to the + log after it starts. + +-I regex Include log entries which match the specified + regular expression. If neither -I nor -i is specified, + all log entries are included. + +-i tag Include log entries with the specified tag. If neither + -I nor -i is specified, all log entries are included. + +-n Specifies the name of the varnishd instance to get logs + from. If -n is not specified, the host name is used. + +-r file Read log entries from file instead of shared memory. + +-V Display the version number and exit. + +-w delay Wait at least delay seconds between each update. The + default is 1. file instead of displaying them. The file + will be overwritten unless the -a option was specified. + +-X regex Exclude log entries which match the specified regular expression. + +-x tag Exclude log entries with the specified tag. + +SEE ALSO +======== + +* varnishd(1) +* varnishlog(1) +* varnishncsa(1) +* varnishstat(1) +* varnishtop(1) + +HISTORY +======= +The varnishhist utility was developed by Poul-Henning Kamp in cooperation with Verdens Gang +AS and Linpro AS. This manual page was written by Dag-Erling Sm?rgrav and Per Buer. + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright (c) 2006 Verdens Gang AS +* Copyright (c) 2006-2008 Linpro AS +* Copyright (c) 2008-2010 Redpill Linpro AS +* Copyright (c) 2010 Varnish Software AS Added: trunk/varnish-cache/doc/sphinx/reference/varnishncsa.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishncsa.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/varnishncsa.rst 2010-06-04 18:35:26 UTC (rev 4888) @@ -0,0 +1,88 @@ +=========== +varnishncsa +=========== + +--------------------------------------------------------- +Display Varnish logs in Apache / NCSA combined log format +--------------------------------------------------------- + +SYNOPSIS +======== + +varnishncsa [-a] [-b] [-C] [-c] [-D] [-d] [-f] [-I regex] +[-i tag] [-n varnish_name] [-P file] [-r file] [-V] +[-w file] [-X regex] [-x tag] + +DESCRIPTION +=========== + +The varnishncsa utility reads varnishd(1) shared memory logs and +presents them in the Apache / NCSA "combined" log format. + +The following options are available: + +-a When writing to a file, append to it rather than overwrite it. + +-b Include log entries which result from communication with a + backend server. If neither -b nor -c is + specified, varnishncsa acts as if they both were. + +-C Ignore case when matching regular expressions. + +-c Include log entries which result from communication + with a client. If neither -b nor -c is specified, + varnishncsa acts as if they both were. + +-D Daemonize. + +-d Process old log entries on startup. Normally, varnishncsa + will only process entries which are written to the log + after it starts. + +-f Prefer the X-Forwarded-For HTTP header over client.ip in + the log output. + +-I regex Include log entries which match the specified regular + expression. If neither -I nor -i is specified, + all log entries are included. + +-i tag Include log entries with the specified tag. If neither -I nor + -i is specified, all log entries are included. + +-n Specifies the name of the varnishd instance to get logs + from. If -n is not specified, the host name is used. + +-P file Write the process's PID to the specified file. + +-r file Read log entries from file instead of shared memory. + +-V Display the version number and exit. + +-w file Write log entries to file instead of displaying them. + The file will be overwritten unless the -a + option was specified. + + If varnishncsa receives a SIGHUP while writing to a file, + it will reopen the file, allowing the old one to be + rotated away. + +-X regex Exclude log entries which match the specified + regular expression. + +-x tag Exclude log entries with the specified tag. + +SEE ALSO +======== + +* varnishd(1) +* varnishhist(1) +* varnishlog(1) +* varnishstat(1) +* varnishtop(1) + +HISTORY +======= + +The varnishncsa utility was developed by Poul-Henning Kamp in +cooperation with Verdens Gang AS and Linpro AS. This manual page was +written by Dag-Erling Sm?rgrav ?des at des.no?. Added: trunk/varnish-cache/doc/sphinx/reference/varnishtest.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishtest.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/varnishtest.rst 2010-06-04 18:35:26 UTC (rev 4888) @@ -0,0 +1,205 @@ +=========== +varnishtest +=========== + +------------------------ +Test program for Varnish +------------------------ + +:Author: Stig Sandbeck Mathisen +:Date: 2010-05-31 +:Version: 1.0 +:Manual section: 1 + + +SYNOPSIS +======== + varnishtest [-n iter] [-q] [-v] file [file ...] + +DESCRIPTION +=========== + +The varnishtest program is a script driven program used to test the +varnish HTTP accelerator. + +The varnishtest program, when started and given one or more script +files, can create a number of threads repre senting backends, some +threads representing clients, and a varnishd process. + +The following options are available: + +-n iter Run iter number of iterations. + +-q Be quiet. + +-v Be verbose. + +-L port Listen on *port*. + +-t Dunno. + +file File to use as a script + + +SCRIPTS +======= + +Example script +~~~~~~~~~~~~~~ +:: + + # Start a varnish instance called "v1" + varnish v1 -arg "-b localhost:9080" -start + + # Create a server thread called "s1" + server s1 { + # Receive a request + rxreq + # Send a standard response + txresp -hdr "Connection: close" -body "012345\n" + } + + # Start the server thread + server s1 -start + + # Create a client thread called "c1" + client c1 { + # Send a request + txreq -url "/" + # Wait for a response + rxresp + # Insist that it be a success + expect resp.status == 200 + } + + # Run the client + client c1 -run + + # Wait for the server to die + server s1 -wait + + # (Forcefully) Stop the varnish instance. + varnish v1 -stop + +Example script output +~~~~~~~~~~~~~~~~~~~~~ + +The output, running this script looks as follows. The "bargraph" at +the beginning of the line is an indication of the level of detail in +the line. The second field where the message comes from. The rest of +the line is anyones guess :-) +:: + + # TEST tests/b00000.vtc starting + ### v1 CMD: cd ../varnishd && ./varnishd -d -d -n v1 -a :9081 -T :9001 -b localhost:9080 + ### v1 opening CLI connection + #### v1 debug| NB: Storage size limited to 2GB on 32 bit architecture,\n + #### v1 debug| NB: otherwise we could run out of address space.\n + #### v1 debug| storage_file: filename: ./varnish.Shkoq5 (unlinked) size 2047 MB.\n + ### v1 CLI connection fd = 3 + #### v1 CLI TX| start + #### v1 debug| Using old SHMFILE\n + #### v1 debug| Notice: locking SHMFILE in core failed: Operation not permitted\n + #### v1 debug| bind(): Address already in use\n + #### v1 debug| rolling(1)... + #### v1 debug| \n + #### v1 debug| rolling(2)...\n + #### v1 debug| Debugging mode, enter "start" to start child\n + ### v1 CLI 200 + ## s1 Starting server + ### s1 listen on :9080 (fd 6) + ## c1 Starting client + ## c1 Waiting for client + ## s1 started on :9080 + ## c1 started + ### c1 connect to :9081 + ### c1 connected to :9081 fd is 8 + #### c1 | GET / HTTP/1.1\r\n + #### c1 | \r\n + ### c1 rxresp + #### s1 Accepted socket 7 + ### s1 rxreq + #### s1 | GET / HTTP/1.1\r\n + #### s1 | X-Varnish: 422080121\r\n + #### s1 | X-Forwarded-For: 127.0.0.1\r\n + #### s1 | Host: localhost\r\n + #### s1 | \r\n + #### s1 http[ 0] | GET + #### s1 http[ 1] | / + #### s1 http[ 2] | HTTP/1.1 + #### s1 http[ 3] | X-Varnish: 422080121 + #### s1 http[ 4] | X-Forwarded-For: 127.0.0.1 + #### s1 http[ 5] | Host: localhost + #### s1 | HTTP/1.1 200 Ok\r\n + #### s1 | Connection: close\r\n + #### s1 | \r\n + #### s1 | 012345\n + #### s1 | \r\n + ## s1 ending + #### c1 | HTTP/1.1 200 Ok\r\n + #### c1 | Content-Length: 9\r\n + #### c1 | Date: Mon, 16 Jun 2008 22:16:55 GMT\r\n + #### c1 | X-Varnish: 422080121\r\n + #### c1 | Age: 0\r\n + #### c1 | Via: 1.1 varnish\r\n + #### c1 | Connection: keep-alive\r\n + #### c1 | \r\n + #### c1 http[ 0] | HTTP/1.1 + #### c1 http[ 1] | 200 + #### c1 http[ 2] | Ok + #### c1 http[ 3] | Content-Length: 9 + #### c1 http[ 4] | Date: Mon, 16 Jun 2008 22:16:55 GMT + #### c1 http[ 5] | X-Varnish: 422080121 + #### c1 http[ 6] | Age: 0 + #### c1 http[ 7] | Via: 1.1 varnish + #### c1 http[ 8] | Connection: keep-alive + #### c1 EXPECT resp.status (200) == 200 (200) match + ## c1 ending + ## s1 Waiting for server + #### v1 CLI TX| stop + ### v1 CLI 200 + # TEST tests/b00000.vtc completed + +If instead of 200 we had expected 201 with the line::: + + expect resp.status == 201 + +The output would have ended with::: + + #### c1 http[ 0] | HTTP/1.1 + #### c1 http[ 1] | 200 + #### c1 http[ 2] | Ok + #### c1 http[ 3] | Content-Length: 9 + #### c1 http[ 4] | Date: Mon, 16 Jun 2008 22:26:35 GMT + #### c1 http[ 5] | X-Varnish: 648043653 648043652 + #### c1 http[ 6] | Age: 6 + #### c1 http[ 7] | Via: 1.1 varnish + #### c1 http[ 8] | Connection: keep-alive + ---- c1 EXPECT resp.status (200) == 201 (201) failed + +SEE ALSO +======== + +* varnishhist(1) +* varnishlog(1) +* varnishncsa(1) +* varnishstat(1) +* varnishtop(1) +* vcl(7) + +HISTORY +======= + +The varnishtest program was developed by Poul-Henning Kamp +?phk at phk.freebsd.dk? in cooperation with Linpro AS. This manual page +was written by Stig Sandbeck Mathisen ?ssm at linpro.no? using examples +by Poul-Henning Kamp ?phk at phk.freebsd.dk?. + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright (c) 2007-2008 Linpro AS +* Copyright (c) 2010 Varnish Software AS Added: trunk/varnish-cache/doc/sphinx/reference/varnishtop.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishtop.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/reference/varnishtop.rst 2010-06-04 18:35:26 UTC (rev 4888) @@ -0,0 +1,95 @@ +============ +varnishtop +============ + +------------------------- +Varnish log entry ranking +------------------------- + +SYNOPSIS +======== + +varnishtop [-1] [-b] [-C] [-c] [-d] [-f] [-I regex] +[-i tag] [-n varnish_name] [-r file] [-V] [-X regex] +[-x tag] + +DESCRIPTION +=========== + +The varnishtop utility reads varnishd(1) shared memory logs and +presents a continuously updated list of the most commonly occurring +log entries. With suitable filtering using the -I, -i, -X and -x +options, it can be used to display a ranking of requested documents, +clients, user agents, or any other information which is recorded in +the log. + +The following options are available: + +-1 Instead of presenting of a continuously updated display, + print the statistics once and exit. Implies -d. + +-b Include log entries which result from communication + with a backend server. If neither -b nor -c is + specified, varnishtop acts as if they both were. + +-C Ignore case when matching regular expressions. + +-c Include log entries which result from communication + with a client. If neither -b nor -c is specified, + varnishtop acts as if they both were. + +-d Process old log entries on startup. Normally, varnishtop + will only process entries which are written to the log + after it starts. + +-f Sort and group only on the first field of each log entry. + This is useful when displaying e.g. stataddr entries, + where the first field is the client IP address. + +-I regex Include log entries which match the specified regular + expression. If neither -I nor -i is specified, all log + entries are included. + +-i tag Include log entries with the specified tag. If neither -I + nor -i is specified, all log entries are included. + +-n Specifies the name of the varnishd instance to get logs from. + If -n is not specified, the host name is used. + +-r file Read log entries from file instead of shared memory. + +-V Display the version number and exit. + +-X regex Exclude log entries which match the specified regular expression. + +-x tag Exclude log entries with the specified tag. + +EXAMPLES +======== + +The following example displays a continuously updated list of the most +frequently requested URLs::: + + varnishtop -i RxURL + +The following example displays a continuously updated list of the most +commonly used user agents::: + + varnishtop -i RxHeader -C -I ^User-Agent + +SEE ALSO +======== + +* varnishd(1) +* varnishhist(1) +* varnishlog(1) +* varnishncsa(1) +* varnishstat(1) + +HISTORY +======= + +The varnishtop utility was originally developed by Poul-Henning Kamp +in cooperation with Verdens Gang AS and Linpro AS, and later +substantially rewritten by Dag-Erling Sm?rgrav. This manual page was +written by Dag-Erling Sm?rgrav. From perbu at varnish-cache.org Sat Jun 5 07:26:12 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Sat, 5 Jun 2010 09:26:12 +0200 Subject: r4889 - in trunk/varnish-cache/doc/sphinx: . reference Message-ID: Author: perbu Date: 2010-06-05 09:26:11 +0200 (Sat, 05 Jun 2010) New Revision: 4889 Modified: trunk/varnish-cache/doc/sphinx/conf.py trunk/varnish-cache/doc/sphinx/reference/varnishd.rst trunk/varnish-cache/doc/sphinx/reference/varnishhist.rst trunk/varnish-cache/doc/sphinx/reference/varnishncsa.rst trunk/varnish-cache/doc/sphinx/reference/varnishtop.rst Log: style changes, headers, etc Modified: trunk/varnish-cache/doc/sphinx/conf.py =================================================================== --- trunk/varnish-cache/doc/sphinx/conf.py 2010-06-04 18:35:26 UTC (rev 4888) +++ trunk/varnish-cache/doc/sphinx/conf.py 2010-06-05 07:26:11 UTC (rev 4889) @@ -96,8 +96,35 @@ # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# +# topp background: #437EB2 +# left column: #EEEEEE; +# h3: #222222; +# color: #222222; +# a: #336590 + +html_theme_options = { + "bgcolor" : "white", + + "relbarbgcolor" : "#437EB2", + "relbartextcolor" : "white", + + "sidebarbgcolor" : "#EEEEEE", + "sidebartextcolor" : "#222222", + "sidebarlinkcolor" : "#336590", + + "textcolor" : "#222222", + "linkcolor" : "#336590", + + + # "codebgcolor" : "#EEEEEE", + "codetextcolor" : "#222222", + "headtextcolor" : "#222222", + "headlinkcolor" : "#336590", + + } + # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] Modified: trunk/varnish-cache/doc/sphinx/reference/varnishd.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishd.rst 2010-06-04 18:35:26 UTC (rev 4888) +++ trunk/varnish-cache/doc/sphinx/reference/varnishd.rst 2010-06-05 07:26:11 UTC (rev 4889) @@ -827,3 +827,13 @@ This manual page was written by Dag-Erling Sm?rgrav with updates by Stig Sandbeck Mathisen ?ssm at debian.org? + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright (c) 2007-2008 Linpro AS +* Copyright (c) 2008-2010 Redpill Linpro AS +* Copyright (c) 2010 Varnish Software AS Modified: trunk/varnish-cache/doc/sphinx/reference/varnishhist.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishhist.rst 2010-06-04 18:35:26 UTC (rev 4888) +++ trunk/varnish-cache/doc/sphinx/reference/varnishhist.rst 2010-06-05 07:26:11 UTC (rev 4889) @@ -2,6 +2,12 @@ varnishhist =========== +:Author: Dag-Erling Sm?rgrav +:Date: 2010-05-31 +:Version: 1.0 +:Manual section: 1 + + ------------------------- Varnish request histogram ------------------------- @@ -72,7 +78,7 @@ HISTORY ======= The varnishhist utility was developed by Poul-Henning Kamp in cooperation with Verdens Gang -AS and Linpro AS. This manual page was written by Dag-Erling Sm?rgrav and Per Buer. +AS and Linpro AS. This manual page was written by Dag-Erling Sm?rgrav. COPYRIGHT ========= Modified: trunk/varnish-cache/doc/sphinx/reference/varnishncsa.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishncsa.rst 2010-06-04 18:35:26 UTC (rev 4888) +++ trunk/varnish-cache/doc/sphinx/reference/varnishncsa.rst 2010-06-05 07:26:11 UTC (rev 4889) @@ -2,6 +2,12 @@ varnishncsa =========== +:Author: Dag-Erling Sm?rgrav +:Date: 2010-05-31 +:Version: 1.0 +:Manual section: 1 + + --------------------------------------------------------- Display Varnish logs in Apache / NCSA combined log format --------------------------------------------------------- @@ -86,3 +92,15 @@ The varnishncsa utility was developed by Poul-Henning Kamp in cooperation with Verdens Gang AS and Linpro AS. This manual page was written by Dag-Erling Sm?rgrav ?des at des.no?. + + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright (c) 2006 Verdens Gang AS +* Copyright (c) 2006-2008 Linpro AS +* Copyright (c) 2008-2010 Redpill Linpro AS +* Copyright (c) 2010 Varnish Software AS Modified: trunk/varnish-cache/doc/sphinx/reference/varnishtop.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishtop.rst 2010-06-04 18:35:26 UTC (rev 4888) +++ trunk/varnish-cache/doc/sphinx/reference/varnishtop.rst 2010-06-05 07:26:11 UTC (rev 4889) @@ -6,6 +6,13 @@ Varnish log entry ranking ------------------------- +:Author: Dag-Erling Sm?rgrav +:Date: 2010-05-31 +:Version: 1.0 +:Manual section: 1 + + + SYNOPSIS ======== @@ -93,3 +100,14 @@ in cooperation with Verdens Gang AS and Linpro AS, and later substantially rewritten by Dag-Erling Sm?rgrav. This manual page was written by Dag-Erling Sm?rgrav. + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright (c) 2006 Verdens Gang AS +* Copyright (c) 2006-2008 Linpro AS +* Copyright (c) 2008-2010 Redpill Linpro AS +* Copyright (c) 2010 Varnish Software AS From phk at varnish-cache.org Sat Jun 5 08:48:34 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 10:48:34 +0200 Subject: r4890 - trunk/varnish-cache/doc/sphinx/reference Message-ID: Author: phk Date: 2010-06-05 10:48:34 +0200 (Sat, 05 Jun 2010) New Revision: 4890 Modified: trunk/varnish-cache/doc/sphinx/reference/index.rst Log: add more todo notes Modified: trunk/varnish-cache/doc/sphinx/reference/index.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/index.rst 2010-06-05 07:26:11 UTC (rev 4889) +++ trunk/varnish-cache/doc/sphinx/reference/index.rst 2010-06-05 08:48:34 UTC (rev 4890) @@ -51,4 +51,7 @@ . syntax etc. Shared Memory . internals + . Log records + Libvarnishapi + . function descriptions From phk at varnish-cache.org Sat Jun 5 08:57:15 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 10:57:15 +0200 Subject: r4891 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-05 10:57:14 +0200 (Sat, 05 Jun 2010) New Revision: 4891 Added: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl.h Log: Split stats to its own source file Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-05 08:48:34 UTC (rev 4890) +++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-05 08:57:14 UTC (rev 4891) @@ -17,7 +17,8 @@ base64.c \ vsl.c \ vsl_arg.c \ - vsl_log.c + vsl_log.c \ + vsl_stat.c libvarnishapi_la_CFLAGS = \ -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-05 08:48:34 UTC (rev 4890) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-05 08:57:14 UTC (rev 4891) @@ -197,7 +197,7 @@ /*--------------------------------------------------------------------*/ -static struct shmalloc * +struct shmalloc * vsl_find_alloc(const struct VSL_data *vd, const char *class, const char *type, const char *ident) { struct shmalloc *sha; @@ -237,21 +237,6 @@ /*--------------------------------------------------------------------*/ -struct varnish_stats * -VSL_OpenStats(struct VSL_data *vd) -{ - struct shmalloc *sha; - - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - if (VSL_Open(vd)) - return (NULL); - sha = vsl_find_alloc(vd, VSL_CLASS_STAT, "", ""); - assert(sha != NULL); - return (SHA_PTR(sha)); -} - -/*--------------------------------------------------------------------*/ - int VSL_OpenLog(struct VSL_data *vd) { Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-05 08:48:34 UTC (rev 4890) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-05 08:57:14 UTC (rev 4891) @@ -88,3 +88,6 @@ unsigned long skip; unsigned long keep; }; + +struct shmalloc *vsl_find_alloc(const struct VSL_data *vd, const char *class, + const char *type, const char *ident); Added: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c (rev 0) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 08:57:14 UTC (rev 4891) @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2010 Redpill Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "config.h" + +#include "svnid.h" +SVNID("$Id$") + +#include +#include + +#include "vas.h" +#include "shmlog.h" +#include "vre.h" +#include "miniobj.h" +#include "varnishapi.h" + +#include "vsl.h" + +/*--------------------------------------------------------------------*/ + +struct varnish_stats * +VSL_OpenStats(struct VSL_data *vd) +{ + struct shmalloc *sha; + + CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + if (VSL_Open(vd)) + return (NULL); + sha = vsl_find_alloc(vd, VSL_CLASS_STAT, "", ""); + assert(sha != NULL); + return (SHA_PTR(sha)); +} From phk at varnish-cache.org Sat Jun 5 09:58:51 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 11:58:51 +0200 Subject: r4892 - in trunk/varnish-cache: include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-05 11:58:51 +0200 (Sat, 05 Jun 2010) New Revision: 4892 Modified: trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Log: Add a new function for walking over all stats counters, including dynamically allocated such. Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-05 08:57:14 UTC (rev 4891) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-05 09:58:51 UTC (rev 4892) @@ -71,4 +71,16 @@ #define VSL_FOREACH(var, vd) \ for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var))) +typedef int vsl_stat_f( + void *priv, /* private context */ + const char *type, /* stat struct type */ + const char *ident, /* stat struct ident */ + const char *nm, /* field name */ + const char *fmt, /* field format ("uint64_t") */ + int flag, /* 'a' = counter, 'i' = gauge */ + const char *desc, /* description */ + volatile void *ptr); /* field value */ + +int VSL_IterStat(struct VSL_data *vd, vsl_stat_f *func, void *priv); + #endif Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 08:57:14 UTC (rev 4891) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 09:58:51 UTC (rev 4892) @@ -34,6 +34,7 @@ #include #include +#include #include "vas.h" #include "shmlog.h" @@ -57,3 +58,62 @@ assert(sha != NULL); return (SHA_PTR(sha)); } + +/*-------------------------------------------------------------------- + * -1 -> unknown stats encountered. + */ + +static int +iter_main(struct shmalloc *sha, vsl_stat_f *func, void *priv) +{ + struct varnish_stats *st = SHA_PTR(sha); + int i; + +#define MAC_STAT(nn, tt, ll, ff, dd) \ + i = func(priv, "", "", \ + #nn, #tt, ff, dd, &st->nn); \ + if (i) \ + return(i); +#include "stat_field.h" +#undef MAC_STAT + return (0); +} + +static int +iter_sma(struct shmalloc *sha, vsl_stat_f *func, void *priv) +{ + struct varnish_stats_sma *st = SHA_PTR(sha); + int i; + +#define MAC_STAT_SMA(nn, tt, ll, ff, dd) \ + i = func(priv, VSL_TYPE_STAT_SMA, sha->ident, \ + #nn, #tt, ff, dd, &st->nn); \ + if (i) \ + return(i); +#include "stat_field.h" +#undef MAC_STAT_SMA + return (0); +} + +int +VSL_IterStat(struct VSL_data *vd, vsl_stat_f *func, void *priv) +{ + struct shmalloc *sha; + int i; + + i = 0; + VSL_FOREACH(sha, vd) { + CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC); + if (strcmp(sha->class, VSL_CLASS_STAT)) + continue; + if (!strcmp(sha->type, VSL_TYPE_STAT)) + i = iter_main(sha, func, priv); + else if (!strcmp(sha->type, VSL_TYPE_STAT_SMA)) + i = iter_sma(sha, func, priv); + else + i = -1; + if (i != 0) + break; + } + return (i); +} From phk at varnish-cache.org Sat Jun 5 10:03:27 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 12:03:27 +0200 Subject: r4893 - in trunk/varnish-cache: bin/varnishstat include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-05 12:03:27 +0200 (Sat, 05 Jun 2010) New Revision: 4893 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Log: Tighten prototype consting. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 09:58:51 UTC (rev 4892) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 10:03:27 UTC (rev 4893) @@ -81,57 +81,121 @@ return (!match_value); } +/*--------------------------------------------------------------------*/ + +struct xml_priv { + const char *fields; +}; + +static int +do_xml_cb( + void *priv, /* private context */ + const char *type, /* stat struct type */ + const char *ident, /* stat struct ident */ + const char *nm, /* field name */ + const char *fmt, /* field format ("uint64_t") */ + int flag, /* 'a' = counter, 'i' = gauge */ + const char *desc, /* description */ + const volatile void *const ptr) /* field value */ +{ + uint64_t val; + struct xml_priv *xp; + + xp = priv; + if (xp->fields != NULL && !show_field(nm, xp->fields)) + return (0); + assert(!strcmp(fmt, "uint64_t")); + val = *(const volatile uint64_t*)ptr; + + printf("\t\n"); + if (strcmp(type, "")) + printf("\t\t%s\n", type); + if (strcmp(ident, "")) + printf("\t\t%s\n", ident); + printf("\t\t%s\n", nm); + printf("\t\t%ju\n", val); + printf("\t\t%c\n", flag); + printf("\t\t%s\n", desc); + printf("\t\n"); + return (0); +} + static void -do_xml(const struct varnish_stats *VSL_stats, const char* fields) +do_xml(struct VSL_data *vd, const char* fields) { char time_stamp[20]; time_t now; + struct xml_priv xp; + xp.fields = fields; + printf("\n"); now = time(NULL); (void)strftime(time_stamp, 20, "%Y-%m-%dT%H:%M:%S", localtime(&now)); printf("\n", time_stamp); -#define MAC_STAT(n, t, l, f, d) \ - do { \ - if (fields != NULL && ! show_field( #n, fields )) \ - break; \ - intmax_t ju = VSL_stats->n; \ - printf("\t\n"); \ - printf("\t\t%s\n", #n); \ - printf("\t\t%ju\n", ju); \ - printf("\t\t%s\n", d); \ - printf("\t\n"); \ - } while (0); -#include "stat_field.h" -#undef MAC_STAT + (void)VSL_IterStat(vd, do_xml_cb, &xp); printf("\n"); } +/*--------------------------------------------------------------------*/ + +struct once_priv { + double up; + const char *fields; + int pad; +}; + +static int +do_once_cb( + void *priv, /* private context */ + const char *type, /* stat struct type */ + const char *ident, /* stat struct ident */ + const char *nm, /* field name */ + const char *fmt, /* field format ("uint64_t") */ + int flag, /* 'a' = counter, 'i' = gauge */ + const char *desc, /* description */ + const volatile void * const ptr) /* field value */ +{ + struct once_priv *op; + uint64_t val; + int i; + + op = priv; + if (op->fields != NULL && !show_field(nm, op->fields)) + return (0); + assert(!strcmp(fmt, "uint64_t")); + val = *(const volatile uint64_t*)ptr; + i = 0; + if (strcmp(type, "")) + i += printf("%s.", type); + if (strcmp(ident, "")) + i += printf("%s.", ident); + i += printf("%s", nm); + if (i > op->pad) + op->pad = i + 1; + printf("%*.*s", op->pad - i, op->pad - i, ""); + if (flag == 'a') + printf("%12ju %12.2f %s\n", val, val / op->up, desc); + else + printf("%12ju %12s %s\n", val, ". ", desc); + return (0); +} + static void -do_once(const struct varnish_stats *VSL_stats, const char* fields) +do_once(struct VSL_data *vd, const struct varnish_stats *VSL_stats, const char* fields) { - struct timeval tv; - double up; + struct once_priv op; - AZ(gettimeofday(&tv, NULL)); - up = VSL_stats->uptime; + memset(&op, 0, sizeof op); + op.up = VSL_stats->uptime; + op.fields = fields; + op.pad = 18; -#define MAC_STAT(n, t, l, ff, d) \ - do { \ - if (fields != NULL && ! show_field( #n, fields )) \ - break; \ - intmax_t ju = VSL_stats->n; \ - if (ff == 'a') \ - printf("%-16s %12ju %12.2f %s\n", \ - #n, ju, ju / up, d); \ - else \ - printf("%-16s %12ju %12s %s\n", \ - #n, ju, ". ", d); \ - } while (0); -#include "stat_field.h" -#undef MAC_STAT + (void)VSL_IterStat(vd, do_once_cb, &op); } +/*--------------------------------------------------------------------*/ + static void usage(void) { @@ -266,9 +330,9 @@ } if (xml) - do_xml(VSL_stats, fields); + do_xml(vd, fields); else if (once) - do_once(VSL_stats, fields); + do_once(vd, VSL_stats, fields); else do_curses(vd, VSL_stats, delay, fields); Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-05 09:58:51 UTC (rev 4892) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-05 10:03:27 UTC (rev 4893) @@ -79,8 +79,8 @@ const char *fmt, /* field format ("uint64_t") */ int flag, /* 'a' = counter, 'i' = gauge */ const char *desc, /* description */ - volatile void *ptr); /* field value */ + const volatile void * const ptr); /* field value */ -int VSL_IterStat(struct VSL_data *vd, vsl_stat_f *func, void *priv); +int VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv); #endif Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 09:58:51 UTC (rev 4892) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 10:03:27 UTC (rev 4893) @@ -96,7 +96,7 @@ } int -VSL_IterStat(struct VSL_data *vd, vsl_stat_f *func, void *priv) +VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv) { struct shmalloc *sha; int i; From phk at varnish-cache.org Sat Jun 5 10:04:40 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 12:04:40 +0200 Subject: r4894 - trunk/varnish-cache/bin/varnishstat Message-ID: Author: phk Date: 2010-06-05 12:04:39 +0200 (Sat, 05 Jun 2010) New Revision: 4894 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c Log: Oops! r4893 contained most of what should go in this commit: Rewrite -1 and -x handing to use new VSL_IterStat() support. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 10:03:27 UTC (rev 4893) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 10:04:39 UTC (rev 4894) @@ -96,7 +96,7 @@ const char *fmt, /* field format ("uint64_t") */ int flag, /* 'a' = counter, 'i' = gauge */ const char *desc, /* description */ - const volatile void *const ptr) /* field value */ + const volatile void *const ptr) /* field value */ { uint64_t val; struct xml_priv *xp; @@ -154,7 +154,7 @@ const char *fmt, /* field format ("uint64_t") */ int flag, /* 'a' = counter, 'i' = gauge */ const char *desc, /* description */ - const volatile void * const ptr) /* field value */ + const volatile void * const ptr) /* field value */ { struct once_priv *op; uint64_t val; From phk at varnish-cache.org Sat Jun 5 10:16:01 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 12:16:01 +0200 Subject: r4895 - trunk/varnish-cache/bin/varnishstat Message-ID: Author: phk Date: 2010-06-05 12:16:01 +0200 (Sat, 05 Jun 2010) New Revision: 4895 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c Log: Rewrite curses support to use VSL_IterStat() Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 10:04:39 UTC (rev 4894) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 10:16:01 UTC (rev 4895) @@ -121,7 +121,7 @@ } static void -do_xml(struct VSL_data *vd, const char* fields) +do_xml(const struct VSL_data *vd, const char* fields) { char time_stamp[20]; time_t now; @@ -182,7 +182,7 @@ } static void -do_once(struct VSL_data *vd, const struct varnish_stats *VSL_stats, const char* fields) +do_once(const struct VSL_data *vd, const struct varnish_stats *VSL_stats, const char* fields) { struct once_priv op; Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 10:04:39 UTC (rev 4894) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 10:16:01 UTC (rev 4895) @@ -51,7 +51,6 @@ #include "vqueue.h" #include "varnishapi.h" #include "varnishstat.h" -#include "miniobj.h" #define AC(x) assert((x) != ERR) @@ -59,88 +58,75 @@ VTAILQ_ENTRY(pt) next; const volatile uint64_t *ptr; uint64_t ref; - char type; + int type; char seen; const char *name; }; static VTAILQ_HEAD(, pt) pthead = VTAILQ_HEAD_INITIALIZER(pthead); -static struct pt * -add_pt(const uint64_t *ptr, int type, const char *c, const char *t, const char *i) + +struct curses_priv { + const char *fields; +}; + +static int +do_curses_cb( + void *priv, /* private context */ + const char *type, /* stat struct type */ + const char *ident, /* stat struct ident */ + const char *nm, /* field name */ + const char *fmt, /* field format ("uint64_t") */ + int flag, /* 'a' = counter, 'i' = gauge */ + const char *desc, /* description */ + const volatile void *const ptr) /* field value */ { + struct curses_priv *cp; struct pt *pt; char buf[128]; + cp = priv; + if (cp->fields != NULL && !show_field(nm, cp->fields)) + return (0); + assert(!strcmp(fmt, "uint64_t")); + pt = calloc(sizeof *pt, 1); AN(pt); VTAILQ_INSERT_TAIL(&pthead, pt, next); pt->ptr = ptr; - pt->ref = *ptr; - pt->type = type; + pt->ref = *pt->ptr; + pt->type = flag; *buf = '\0'; - if (c != NULL) { - strcat(buf, c); + if (strcmp(type, "")) { + strcat(buf, type); strcat(buf, "."); } - if (t != NULL) { - strcat(buf, t); + if (strcmp(ident, "")) { + strcat(buf, ident); strcat(buf, "."); } - if (i != NULL) { - strcat(buf, i); - strcat(buf, "."); - } + strcat(buf, nm); + strcat(buf, " - "); + strcat(buf, desc); pt->name = strdup(buf); AN(pt->name); - return (pt); + return (0); } static void -main_stat(void *ptr, const char *fields) +prep_pts(struct VSL_data *vd, const char *fields) { - struct varnish_stats *st = ptr; + struct curses_priv cp; -#define MAC_STAT(nn, tt, ll, ff, dd) \ - if (fields == NULL || show_field( #nn, fields )) \ - (void)add_pt(&st->nn, ff, NULL, NULL, dd); -#include "stat_field.h" -#undef MAC_STAT -} + cp.fields = fields; -static void -sma_stat(struct shmalloc *sha, const char *fields) -{ - struct varnish_stats_sma *st = SHA_PTR(sha); + (void)VSL_IterStat(vd, do_curses_cb, &cp); -#define MAC_STAT_SMA(nn, tt, ll, ff, dd) \ - if (fields == NULL || show_field( #nn, fields )) \ - (void)add_pt(&st->nn, ff, "SMA", sha->ident, dd); -#include "stat_field.h" -#undef MAC_STAT_SMA } static void -prep_pts(struct VSL_data *vd, const char *fields) -{ - struct shmalloc *sha; - - VSL_FOREACH(sha, vd) { - CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC); - if (strcmp(sha->class, VSL_CLASS_STAT)) - continue; - if (!strcmp(sha->type, VSL_TYPE_STAT)) - main_stat(SHA_PTR(sha), fields); - else if (!strcmp(sha->type, VSL_TYPE_STAT_SMA)) - sma_stat(sha, fields); - else - fprintf(stderr, "Unknwon Statistics"); - } -} - -static void myexp(double *acc, double val, unsigned *n, unsigned nmax) { From phk at varnish-cache.org Sat Jun 5 11:04:17 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 13:04:17 +0200 Subject: r4896 - in trunk/varnish-cache: include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-05 13:04:17 +0200 (Sat, 05 Jun 2010) New Revision: 4896 Modified: trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsl.c Log: Add VSL_ReOpen() to detect shmfile changes (ie: master restarts) Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-05 10:16:01 UTC (rev 4895) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-05 11:04:17 UTC (rev 4896) @@ -65,6 +65,8 @@ void *VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident, unsigned *lenp); +int VSL_ReOpen(struct VSL_data *vd); + struct shmalloc *vsl_iter0(const struct VSL_data *vd); void vsl_itern(const struct VSL_data *vd, struct shmalloc **pp); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-05 10:16:01 UTC (rev 4895) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-05 11:04:17 UTC (rev 4896) @@ -103,8 +103,8 @@ /*--------------------------------------------------------------------*/ -int -VSL_Open(struct VSL_data *vd) +static int +vsl_open(struct VSL_data *vd, int rep) { int i; struct shmloghead slh; @@ -114,42 +114,57 @@ vd->vsl_fd = open(vd->fname, O_RDONLY); if (vd->vsl_fd < 0) { - fprintf(stderr, "Cannot open %s: %s\n", - vd->fname, strerror(errno)); + if (rep) + fprintf(stderr, "Cannot open %s: %s\n", + vd->fname, strerror(errno)); return (1); } assert(fstat(vd->vsl_fd, &vd->fstat) == 0); if (!S_ISREG(vd->fstat.st_mode)) { - fprintf(stderr, "%s is not a regular file\n", vd->fname); + if (rep) + fprintf(stderr, "%s is not a regular file\n", + vd->fname); return (1); } i = read(vd->vsl_fd, &slh, sizeof slh); if (i != sizeof slh) { - fprintf(stderr, "Cannot read %s: %s\n", - vd->fname, strerror(errno)); + if (rep) + fprintf(stderr, "Cannot read %s: %s\n", + vd->fname, strerror(errno)); return (1); } if (slh.magic != SHMLOGHEAD_MAGIC) { - fprintf(stderr, "Wrong magic number in file %s\n", - vd->fname); + if (rep) + fprintf(stderr, "Wrong magic number in file %s\n", + vd->fname); return (1); } vd->vsl_lh = (void *)mmap(NULL, slh.shm_size, PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsl_fd, 0); if (vd->vsl_lh == MAP_FAILED) { - fprintf(stderr, "Cannot mmap %s: %s\n", - vd->fname, strerror(errno)); + if (rep) + fprintf(stderr, "Cannot mmap %s: %s\n", + vd->fname, strerror(errno)); return (1); } vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size; + while(slh.alloc_seq == 0) + usleep(50000); vd->alloc_seq = slh.alloc_seq; return (0); } +int +VSL_Open(struct VSL_data *vd) +{ + + return (vsl_open(vd, 1)); +} + /*--------------------------------------------------------------------*/ void @@ -166,6 +181,33 @@ /*--------------------------------------------------------------------*/ +int +VSL_ReOpen(struct VSL_data *vd) +{ + struct stat st; + int i; + + if (vd->vsl_lh == NULL) + return (-1); + + if (stat(vd->fname, &st)) + return (0); + + if (st.st_dev == vd->fstat.st_dev && st.st_ino == vd->fstat.st_ino) + return (0); + + VSL_Close(vd); + for (i = 0; i < 5; i++) { + if (!vsl_open(vd, 0)) + return (1); + } + if (vsl_open(vd, 1)) + return (-1); + return (1); +} + +/*--------------------------------------------------------------------*/ + struct shmalloc * vsl_iter0(const struct VSL_data *vd) { From phk at varnish-cache.org Sat Jun 5 11:05:06 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 13:05:06 +0200 Subject: r4897 - trunk/varnish-cache/bin/varnishstat Message-ID: Author: phk Date: 2010-06-05 13:05:04 +0200 (Sat, 05 Jun 2010) New Revision: 4897 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c Log: Teach varnishstat (curses mode) to reopen shmlog if varnishd master is restarted. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 11:04:17 UTC (rev 4896) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 11:05:04 UTC (rev 4897) @@ -60,7 +60,7 @@ uint64_t ref; int type; char seen; - const char *name; + char *name; }; static VTAILQ_HEAD(, pt) pthead = VTAILQ_HEAD_INITIALIZER(pthead); @@ -116,10 +116,16 @@ } static void -prep_pts(struct VSL_data *vd, const char *fields) +prep_pts(const struct VSL_data *vd, const char *fields) { struct curses_priv cp; + struct pt *pt, *pt2; + VTAILQ_FOREACH_SAFE(pt, &pthead, next, pt2) { + VTAILQ_REMOVE(&pthead, pt, next); + free(pt->name); + free(pt); + } cp.fields = fields; (void)VSL_IterStat(vd, do_curses_cb, &cp); @@ -136,120 +142,143 @@ } void -do_curses(struct VSL_data *vd, const struct varnish_stats *VSL_stats, int delay, const char *fields) +do_curses(struct VSL_data *vd, const struct varnish_stats *VSL_stats, + int delay, const char *fields) { - struct varnish_stats copy; intmax_t ju; struct timeval tv; - double tt, lt, hit, miss, ratio, up; + double tt, lt, lhit, hit, lmiss, miss, hr, mr, ratio, up; double a1, a2, a3; unsigned n1, n2, n3; time_t rt; int ch, line; struct pt *pt; + double act, lact; - prep_pts(vd, fields); - memset(©, 0, sizeof copy); - - a1 = a2 = a3 = 0.0; - n1 = n2 = n3 = 0; - (void)initscr(); AC(raw()); AC(noecho()); AC(nonl()); AC(intrflush(stdscr, FALSE)); AC(curs_set(0)); - AC(erase()); - lt = 0; while (1) { - AZ(gettimeofday(&tv, NULL)); - tt = tv.tv_usec * 1e-6 + tv.tv_sec; - lt = tt - lt; + /* + * Initialization goes in outher loop + */ + prep_pts(vd, fields); + AC(erase()); + AC(refresh()); - rt = VSL_stats->uptime; - up = rt; + a1 = a2 = a3 = 0.0; + n1 = n2 = n3 = 0; + lt = 0; + lhit = 0; + lmiss = 0; + lact = 0; - AC(mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd))); - AC(mvprintw(0, 0, "%d+%02d:%02d:%02d", rt / 86400, - (rt % 86400) / 3600, (rt % 3600) / 60, rt % 60)); + while (1) { + /* + * Break to outher loop if we need to re-read file. + * Only check if it looks like nothing is happening. + */ + act = VSL_stats->cache_hit + VSL_stats->cache_miss + 1; + if (act == lact && VSL_ReOpen(vd)) + break; + lact = act; - hit = VSL_stats->cache_hit - copy.cache_hit; - miss = VSL_stats->cache_miss - copy.cache_miss; - hit /= lt; - miss /= lt; - if (hit + miss != 0) { - ratio = hit / (hit + miss); - myexp(&a1, ratio, &n1, 10); - myexp(&a2, ratio, &n2, 100); - myexp(&a3, ratio, &n3, 1000); - } - AC(mvprintw(1, 0, "Hitrate ratio: %8u %8u %8u", n1, n2, n3)); - AC(mvprintw(2, 0, "Hitrate avg: %8.4f %8.4f %8.4f", a1, a2, a3)); + AZ(gettimeofday(&tv, NULL)); + tt = tv.tv_usec * 1e-6 + tv.tv_sec; + lt = tt - lt; - line = 3; - VTAILQ_FOREACH(pt, &pthead, next) { - if (line >= LINES) + rt = VSL_stats->uptime; + up = rt; + + AC(mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd))); + AC(mvprintw(0, 0, "%d+%02d:%02d:%02d", rt / 86400, + (rt % 86400) / 3600, (rt % 3600) / 60, rt % 60)); + + hit = VSL_stats->cache_hit; + miss = VSL_stats->cache_miss; + hr = (hit - lhit) / lt; + mr = (miss - lmiss) / lt; + lhit = hit; + lmiss = miss; + if (hr + mr != 0) { + ratio = hr / (hr + mr); + myexp(&a1, ratio, &n1, 10); + myexp(&a2, ratio, &n2, 100); + myexp(&a3, ratio, &n3, 1000); + } + AC(mvprintw(1, 0, "Hitrate ratio: %8u %8u %8u", + n1, n2, n3)); + AC(mvprintw(2, 0, "Hitrate avg: %8.4f %8.4f %8.4f", + a1, a2, a3)); + + line = 3; + VTAILQ_FOREACH(pt, &pthead, next) { + if (line >= LINES) + break; + ju = *pt->ptr; + if (ju == 0 && !pt->seen) + continue; + pt->seen = 1; + line++; + if (pt->type == 'a') { + AC(mvprintw(line, 0, + "%12ju %12.2f %12.2f %s\n", + ju, (ju - (intmax_t)pt->ref)/lt, + ju / up, pt->name)); + pt->ref = ju; + } else { + AC(mvprintw(line, 0, + "%12ju %12s %12s %s\n", + ju, ". ", ". ", pt->name)); + } + } + lt = tt; + AC(refresh()); + timeout(delay * 1000); + switch ((ch = getch())) { + case ERR: break; - ju = *pt->ptr; - if (ju == 0 && !pt->seen) - continue; - pt->seen = 1; - line++; - if (pt->type == 'a') { - AC(mvprintw(line, 0, - "%12ju %12.2f %12.2f %s\n", - ju, (ju - (intmax_t)pt->ref)/lt, - ju / up, pt->name)); - pt->ref = ju; - } else { - AC(mvprintw(line, 0, "%12ju %12s %12s %s\n", - ju, ". ", ". ", pt->name)); - } - } - lt = tt; - AC(refresh()); - timeout(delay * 1000); - switch ((ch = getch())) { - case ERR: - break; #ifdef KEY_RESIZE - case KEY_RESIZE: - AC(erase()); - break; + case KEY_RESIZE: + AC(erase()); + break; #endif - case '\014': /* Ctrl-L */ - case '\024': /* Ctrl-T */ - AC(redrawwin(stdscr)); - AC(refresh()); - break; - case '\003': /* Ctrl-C */ - AZ(raise(SIGINT)); - break; - case '\032': /* Ctrl-Z */ - AZ(raise(SIGTSTP)); - break; - case '\021': /* Ctrl-Q */ - case 'Q': - case 'q': - AC(endwin()); - exit(0); - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - delay = 1U << (ch - '0'); - break; - default: - AC(beep()); - break; + case '\014': /* Ctrl-L */ + case '\024': /* Ctrl-T */ + AC(redrawwin(stdscr)); + AC(refresh()); + break; + case '\003': /* Ctrl-C */ + AZ(raise(SIGINT)); + break; + case '\032': /* Ctrl-Z */ + AZ(raise(SIGTSTP)); + break; + case '\021': /* Ctrl-Q */ + case 'Q': + case 'q': + AC(endwin()); + exit(0); + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + delay = 1U << (ch - '0'); + break; + default: + AC(beep()); + break; + } } } } From phk at varnish-cache.org Sat Jun 5 12:40:56 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 14:40:56 +0200 Subject: r4898 - in trunk/varnish-cache: bin/varnishstat include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-05 14:40:56 +0200 (Sat, 05 Jun 2010) New Revision: 4898 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Log: Wrap all the details in a struct for the VSL_IterStat() callback, it is faster, more handy and easier to extend in the future. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 11:05:04 UTC (rev 4897) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 12:40:56 UTC (rev 4898) @@ -88,34 +88,26 @@ }; static int -do_xml_cb( - void *priv, /* private context */ - const char *type, /* stat struct type */ - const char *ident, /* stat struct ident */ - const char *nm, /* field name */ - const char *fmt, /* field format ("uint64_t") */ - int flag, /* 'a' = counter, 'i' = gauge */ - const char *desc, /* description */ - const volatile void *const ptr) /* field value */ +do_xml_cb(void *priv, const struct vsl_statpt * const pt) { uint64_t val; struct xml_priv *xp; xp = priv; - if (xp->fields != NULL && !show_field(nm, xp->fields)) + if (xp->fields != NULL && !show_field(pt->nm, xp->fields)) return (0); - assert(!strcmp(fmt, "uint64_t")); - val = *(const volatile uint64_t*)ptr; + assert(!strcmp(pt->fmt, "uint64_t")); + val = *(const volatile uint64_t*)pt->ptr; printf("\t\n"); - if (strcmp(type, "")) - printf("\t\t%s\n", type); - if (strcmp(ident, "")) - printf("\t\t%s\n", ident); - printf("\t\t%s\n", nm); + if (strcmp(pt->type, "")) + printf("\t\t%s\n", pt->type); + if (strcmp(pt->ident, "")) + printf("\t\t%s\n", pt->ident); + printf("\t\t%s\n", pt->nm); printf("\t\t%ju\n", val); - printf("\t\t%c\n", flag); - printf("\t\t%s\n", desc); + printf("\t\t%c\n", pt->flag); + printf("\t\t%s\n", pt->desc); printf("\t\n"); return (0); } @@ -146,38 +138,30 @@ }; static int -do_once_cb( - void *priv, /* private context */ - const char *type, /* stat struct type */ - const char *ident, /* stat struct ident */ - const char *nm, /* field name */ - const char *fmt, /* field format ("uint64_t") */ - int flag, /* 'a' = counter, 'i' = gauge */ - const char *desc, /* description */ - const volatile void * const ptr) /* field value */ +do_once_cb(void *priv, const struct vsl_statpt * const pt) { struct once_priv *op; uint64_t val; int i; op = priv; - if (op->fields != NULL && !show_field(nm, op->fields)) + if (op->fields != NULL && !show_field(pt->nm, op->fields)) return (0); - assert(!strcmp(fmt, "uint64_t")); - val = *(const volatile uint64_t*)ptr; + assert(!strcmp(pt->fmt, "uint64_t")); + val = *(const volatile uint64_t*)pt->ptr; i = 0; - if (strcmp(type, "")) - i += printf("%s.", type); - if (strcmp(ident, "")) - i += printf("%s.", ident); - i += printf("%s", nm); + if (strcmp(pt->type, "")) + i += printf("%s.", pt->type); + if (strcmp(pt->ident, "")) + i += printf("%s.", pt->ident); + i += printf("%s", pt->nm); if (i > op->pad) op->pad = i + 1; printf("%*.*s", op->pad - i, op->pad - i, ""); - if (flag == 'a') - printf("%12ju %12.2f %s\n", val, val / op->up, desc); + if (pt->flag == 'a') + printf("%12ju %12.2f %s\n", val, val / op->up, pt->desc); else - printf("%12ju %12s %s\n", val, ". ", desc); + printf("%12ju %12s %s\n", val, ". ", pt->desc); return (0); } Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 11:05:04 UTC (rev 4897) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 12:40:56 UTC (rev 4898) @@ -71,45 +71,37 @@ }; static int -do_curses_cb( - void *priv, /* private context */ - const char *type, /* stat struct type */ - const char *ident, /* stat struct ident */ - const char *nm, /* field name */ - const char *fmt, /* field format ("uint64_t") */ - int flag, /* 'a' = counter, 'i' = gauge */ - const char *desc, /* description */ - const volatile void *const ptr) /* field value */ +do_curses_cb(void *priv, const struct vsl_statpt * const sp) { struct curses_priv *cp; struct pt *pt; char buf[128]; cp = priv; - if (cp->fields != NULL && !show_field(nm, cp->fields)) + if (cp->fields != NULL && !show_field(sp->nm, cp->fields)) return (0); - assert(!strcmp(fmt, "uint64_t")); + assert(!strcmp(sp->fmt, "uint64_t")); pt = calloc(sizeof *pt, 1); AN(pt); VTAILQ_INSERT_TAIL(&pthead, pt, next); - pt->ptr = ptr; + pt->ptr = sp->ptr; pt->ref = *pt->ptr; - pt->type = flag; + pt->type = sp->flag; *buf = '\0'; - if (strcmp(type, "")) { - strcat(buf, type); + if (strcmp(sp->type, "")) { + strcat(buf, sp->type); strcat(buf, "."); } - if (strcmp(ident, "")) { - strcat(buf, ident); + if (strcmp(sp->ident, "")) { + strcat(buf, sp->ident); strcat(buf, "."); } - strcat(buf, nm); + strcat(buf, sp->nm); strcat(buf, " - "); - strcat(buf, desc); + strcat(buf, sp->desc); pt->name = strdup(buf); AN(pt->name); return (0); Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-05 11:05:04 UTC (rev 4897) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-05 12:40:56 UTC (rev 4898) @@ -73,16 +73,18 @@ #define VSL_FOREACH(var, vd) \ for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var))) -typedef int vsl_stat_f( - void *priv, /* private context */ - const char *type, /* stat struct type */ - const char *ident, /* stat struct ident */ - const char *nm, /* field name */ - const char *fmt, /* field format ("uint64_t") */ - int flag, /* 'a' = counter, 'i' = gauge */ - const char *desc, /* description */ - const volatile void * const ptr); /* field value */ +struct vsl_statpt { + const char *type; /* stat struct type */ + const char *ident; /* stat struct ident */ + const char *nm; /* field name */ + const char *fmt; /* field format ("uint64_t") */ + int flag; /* 'a' = counter, 'i' = gauge */ + const char *desc; /* description */ + const volatile void *ptr; /* field value */ +}; +typedef int vsl_stat_f(void *priv, const struct vsl_statpt *const pt); + int VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv); #endif Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 11:05:04 UTC (rev 4897) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 12:40:56 UTC (rev 4898) @@ -67,11 +67,18 @@ iter_main(struct shmalloc *sha, vsl_stat_f *func, void *priv) { struct varnish_stats *st = SHA_PTR(sha); + struct vsl_statpt sp; int i; + sp.type = ""; + sp.ident = ""; #define MAC_STAT(nn, tt, ll, ff, dd) \ - i = func(priv, "", "", \ - #nn, #tt, ff, dd, &st->nn); \ + sp.nm = #nn; \ + sp.fmt = #tt; \ + sp.flag = ff; \ + sp.desc = dd; \ + sp.ptr = &st->nn; \ + i = func(priv, &sp); \ if (i) \ return(i); #include "stat_field.h" @@ -83,11 +90,18 @@ iter_sma(struct shmalloc *sha, vsl_stat_f *func, void *priv) { struct varnish_stats_sma *st = SHA_PTR(sha); + struct vsl_statpt sp; int i; + sp.type = VSL_TYPE_STAT_SMA; + sp.ident = sha->ident; #define MAC_STAT_SMA(nn, tt, ll, ff, dd) \ - i = func(priv, VSL_TYPE_STAT_SMA, sha->ident, \ - #nn, #tt, ff, dd, &st->nn); \ + sp.nm = #nn; \ + sp.fmt = #tt; \ + sp.flag = ff; \ + sp.desc = dd; \ + sp.ptr = &st->nn; \ + i = func(priv, &sp); \ if (i) \ return(i); #include "stat_field.h" From phk at varnish-cache.org Sat Jun 5 12:49:00 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 14:49:00 +0200 Subject: r4899 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-05 14:48:59 +0200 (Sat, 05 Jun 2010) New Revision: 4899 Modified: trunk/varnish-cache/lib/libvarnishapi/base64.c trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c trunk/varnish-cache/lib/libvarnishapi/vsl_log.c Log: polish Modified: trunk/varnish-cache/lib/libvarnishapi/base64.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/base64.c 2010-06-05 12:40:56 UTC (rev 4898) +++ trunk/varnish-cache/lib/libvarnishapi/base64.c 2010-06-05 12:48:59 UTC (rev 4899) @@ -26,7 +26,7 @@ for (i = 0; i < 256; i++) i64[i] = -1; for (p = b64, i = 0; *p; p++, i++) - i64[(int)*p] = i; + i64[(int)*p] = (char)i; i64['='] = 0; } Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-05 12:40:56 UTC (rev 4898) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-05 12:48:59 UTC (rev 4899) @@ -52,10 +52,6 @@ #include "vsl.h" -#ifndef MAP_HASSEMAPHORE -#define MAP_HASSEMAPHORE 0 /* XXX Linux */ -#endif - /*--------------------------------------------------------------------*/ static int Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-05 12:40:56 UTC (rev 4898) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-05 12:48:59 UTC (rev 4899) @@ -49,10 +49,6 @@ #include "vsl.h" -#ifndef MAP_HASSEMAPHORE -#define MAP_HASSEMAPHORE 0 /* XXX Linux */ -#endif - static int vsl_nextlog(struct VSL_data *vd, unsigned char **pp); /*--------------------------------------------------------------------*/ From phk at varnish-cache.org Sat Jun 5 12:51:33 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 14:51:33 +0200 Subject: r4900 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-05 14:51:33 +0200 (Sat, 05 Jun 2010) New Revision: 4900 Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c Log: Just an XXX observation Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-05 12:48:59 UTC (rev 4899) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-05 12:51:33 UTC (rev 4900) @@ -187,7 +187,12 @@ return (1); } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * XXX: Should really be split into three: + * VSL_Arg() for generic args for all programs (-n) + * VSL_Log_Arg() for log readers. + * VSL_Stat_Arg() for stat reporters. + */ int VSL_Arg(struct VSL_data *vd, int arg, const char *opt) From phk at varnish-cache.org Sat Jun 5 13:03:56 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 15:03:56 +0200 Subject: r4901 - in trunk/varnish-cache/bin: . varnishd varnishncsa varnishtest Message-ID: Author: phk Date: 2010-06-05 15:03:56 +0200 (Sat, 05 Jun 2010) New Revision: 4901 Added: trunk/varnish-cache/bin/flint.lnt Modified: trunk/varnish-cache/bin/varnishd/flint.lnt trunk/varnish-cache/bin/varnishd/flint.sh trunk/varnish-cache/bin/varnishd/vclflint.lnt trunk/varnish-cache/bin/varnishncsa/flint.lnt trunk/varnish-cache/bin/varnishncsa/flint.sh trunk/varnish-cache/bin/varnishtest/flint.lnt trunk/varnish-cache/bin/varnishtest/flint.sh Log: Start unifying FlexeLint instructions, to curb spreading copy&paste-itis Added: trunk/varnish-cache/bin/flint.lnt =================================================================== --- trunk/varnish-cache/bin/flint.lnt (rev 0) +++ trunk/varnish-cache/bin/flint.lnt 2010-06-05 13:03:56 UTC (rev 4901) @@ -0,0 +1,12 @@ +-passes=3 + +/////////////////////////////////////////////////////////////////////// +// ../../config.h magic +-header(../../config.h) ++libh ../../config.h +-efile(451, ../../config.h) + + +/////////////////////////////////////////////////////////////////////// +// assert() support, common to libvarnish and libvarnishapi +-sem(vas_fail, r_no) Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2010-06-05 12:51:33 UTC (rev 4900) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2010-06-05 13:03:56 UTC (rev 4901) @@ -1,4 +1,3 @@ - -d__flexelint_v9__=1 -libdir(../../include) @@ -75,7 +74,6 @@ -e777 // float equality comparison -e679 // Suspicious Truncation in arithmetic expression combining with pointer --esym(458, lbv_assert) // unlocked access -esym(458, params) // unlocked access -emacro(835, HTTPH) // Info 835: A zero has been given as left argument to operator '&' @@ -109,10 +107,8 @@ -esym(528, svnid) ////////////// --passes=3 +libh mgt_event.h -+libh ../../config.h -emacro((???),va_arg) // the va_arg() macro can yield 415, 416, 661, 662 // 796 and 797 (out-of-bounds errors). @@ -128,7 +124,6 @@ -// -header(../../config.h) // Fix strchr() semtics, it can only return NULL if arg2 != 0 -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) @@ -136,8 +131,6 @@ -sem(vsb_new, @p == (1p ? 1p : malloc(1))) -sem(vsb_delete, custodial(1)) -sem(pthread_create, custodial(4)) --sem(lbv_assert, r_no) --sem(lbv_xxxassert, r_no) -sem(WS_Init, custodial(2)) -sem(http_Setup, custodial(2)) Modified: trunk/varnish-cache/bin/varnishd/flint.sh =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.sh 2010-06-05 12:51:33 UTC (rev 4900) +++ trunk/varnish-cache/bin/varnishd/flint.sh 2010-06-05 13:03:56 UTC (rev 4901) @@ -1,6 +1,7 @@ #!/bin/sh flexelint \ + ../flint.lnt \ flint.lnt \ -I. \ -I../../include \ Modified: trunk/varnish-cache/bin/varnishd/vclflint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/vclflint.lnt 2010-06-05 12:51:33 UTC (rev 4900) +++ trunk/varnish-cache/bin/varnishd/vclflint.lnt 2010-06-05 13:03:56 UTC (rev 4901) @@ -1,8 +1,6 @@ // Flexelint configuration file for VCL compiler output // --passes=3 - -esym(763, sess) // Redundant declaration for symbol 'sess' // Harmless Modified: trunk/varnish-cache/bin/varnishncsa/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishncsa/flint.lnt 2010-06-05 12:51:33 UTC (rev 4900) +++ trunk/varnish-cache/bin/varnishncsa/flint.lnt 2010-06-05 13:03:56 UTC (rev 4901) @@ -1,7 +1,4 @@ --passes=3 --header(../../config.h) - +d__attribute__()= // Fix strchr() semtics, it can only return NULL if arg2 != 0 Modified: trunk/varnish-cache/bin/varnishncsa/flint.sh =================================================================== --- trunk/varnish-cache/bin/varnishncsa/flint.sh 2010-06-05 12:51:33 UTC (rev 4900) +++ trunk/varnish-cache/bin/varnishncsa/flint.sh 2010-06-05 13:03:56 UTC (rev 4901) @@ -5,6 +5,7 @@ -I/usr/include \ -I. \ -I../../include \ + ../flint.lnt \ flint.lnt \ *.c > $T 2>&1 Modified: trunk/varnish-cache/bin/varnishtest/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishtest/flint.lnt 2010-06-05 12:51:33 UTC (rev 4900) +++ trunk/varnish-cache/bin/varnishtest/flint.lnt 2010-06-05 13:03:56 UTC (rev 4901) @@ -1,7 +1,5 @@ --passes=3 +libh mgt_event.h -+libh ../../config.h -emacro((???),va_arg) // the va_arg() macro can yield 415, 416, 661, 662 // 796 and 797 (out-of-bounds errors). @@ -20,11 +18,6 @@ - - - -// -header(../../config.h) - // Fix strchr() semtics, it can only return NULL if arg2 != 0 -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) // Modified: trunk/varnish-cache/bin/varnishtest/flint.sh =================================================================== --- trunk/varnish-cache/bin/varnishtest/flint.sh 2010-06-05 12:51:33 UTC (rev 4900) +++ trunk/varnish-cache/bin/varnishtest/flint.sh 2010-06-05 13:03:56 UTC (rev 4901) @@ -5,5 +5,6 @@ -I. \ -I../../include \ -I../.. \ + ../flint.lnt \ flint.lnt \ *.c From phk at varnish-cache.org Sat Jun 5 13:20:16 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 15:20:16 +0200 Subject: r4902 - trunk/varnish-cache/bin/varnishtest Message-ID: Author: phk Date: 2010-06-05 15:20:16 +0200 (Sat, 05 Jun 2010) New Revision: 4902 Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c Log: Oops, missing {...} Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_log.c 2010-06-05 13:03:56 UTC (rev 4901) +++ trunk/varnish-cache/bin/varnishtest/vtc_log.c 2010-06-05 13:20:16 UTC (rev 4902) @@ -183,7 +183,7 @@ if (str == NULL) vsb_printf(vl->vsb, "%s %-4s %s(null)\n", lead[lvl], vl->id, pfx); - else + else { l = 0; for(; *str != '\0'; str++) { if (++l > 512) { @@ -207,6 +207,7 @@ else vsb_printf(vl->vsb, "%c", *str); } + } if (!nl) vsb_printf(vl->vsb, "\n"); vsb_finish(vl->vsb); From phk at varnish-cache.org Sat Jun 5 13:21:13 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 15:21:13 +0200 Subject: r4903 - in trunk/varnish-cache/bin: . varnishd varnishncsa varnishtest Message-ID: Author: phk Date: 2010-06-05 15:21:13 +0200 (Sat, 05 Jun 2010) New Revision: 4903 Modified: trunk/varnish-cache/bin/flint.lnt trunk/varnish-cache/bin/varnishd/flint.lnt trunk/varnish-cache/bin/varnishncsa/flint.lnt trunk/varnish-cache/bin/varnishtest/flint.lnt Log: More FlexeLint centralization Modified: trunk/varnish-cache/bin/flint.lnt =================================================================== --- trunk/varnish-cache/bin/flint.lnt 2010-06-05 13:20:16 UTC (rev 4902) +++ trunk/varnish-cache/bin/flint.lnt 2010-06-05 13:21:13 UTC (rev 4903) @@ -1,12 +1,41 @@ -passes=3 +-ffc // No automatic custody + /////////////////////////////////////////////////////////////////////// // ../../config.h magic -header(../../config.h) +libh ../../config.h --efile(451, ../../config.h) +-efile(451, ../../config.h) // No include guard /////////////////////////////////////////////////////////////////////// +// varargs stuff + +-emacro((???), va_arg) // 415, 416, 416, 661, 662, 796, 797 ... + +/////////////////////////////////////////////////////////////////////// // assert() support, common to libvarnish and libvarnishapi -sem(vas_fail, r_no) + +/////////////////////////////////////////////////////////////////////// +// Ignore return values OK for these functions + +-esym(534, printf) +-esym(534, fprintf) +-esym(534, sprintf) + +-esym(534, memset) +-esym(534, memcpy) +-esym(534, memmove) + +-esym(534, strcat) +-esym(534, strcpy) +-esym(534, strlcpy) + +-esym(534, vsb_cat) +-esym(534, vsb_bcat) +-esym(534, vsb_putc) +-esym(534, vsb_printf) +-esym(534, vsb_vprintf) +-esym(534, vsb_putc) Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2010-06-05 13:20:16 UTC (rev 4902) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2010-06-05 13:21:13 UTC (rev 4903) @@ -110,8 +110,6 @@ +libh mgt_event.h --emacro((???),va_arg) // the va_arg() macro can yield 415, 416, 661, 662 - // 796 and 797 (out-of-bounds errors). -elib(123) // size is both a variable and a macro with args -emacro(736, isnan) // isnanf -efile(766, ../../config.h) @@ -134,8 +132,6 @@ -sem(WS_Init, custodial(2)) -sem(http_Setup, custodial(2)) --ffc // No automatic custody - -e455 // thread lock -e458 // unprotected read -e763 // Redundant declaration for symbol '...' previously declared @@ -156,22 +152,6 @@ -esym(759, vcc_ProcAction) // could be moved to module -esym(714, vcc_ProcAction) // not ref. --esym(534, sprintf) // Ignoring return value of function --esym(534, asprintf) // Ignoring return value of function --esym(534, printf) // Ignoring return value of function --esym(534, fprintf) // Ignoring return value of function --esym(534, memset) // Ignoring return value of function --esym(534, memcpy) // Ignoring return value of function --esym(534, memmove) // Ignoring return value of function --esym(534, strcpy) // Ignoring return value of function --esym(534, vsb_printf) // Ignoring return value of function --esym(534, vsb_vprintf) // Ignoring return value of function --esym(534, vsb_cat) // Ignoring return value of function --esym(534, vsb_bcat) // Ignoring return value of function --esym(534, vsb_putc) // Ignoring return value of function --esym(534, strcat) // Ignoring return value of function --esym(534, strcpy) // Ignoring return value of function --esym(534, strlcpy) // Ignoring return value of function -esym(765, panicstr) // Could be static -emacro(506, isnan, isfinite) // constant value boolean Modified: trunk/varnish-cache/bin/varnishncsa/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishncsa/flint.lnt 2010-06-05 13:20:16 UTC (rev 4902) +++ trunk/varnish-cache/bin/varnishncsa/flint.lnt 2010-06-05 13:21:13 UTC (rev 4903) @@ -4,8 +4,6 @@ // Fix strchr() semtics, it can only return NULL if arg2 != 0 -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) --ffc // No automatic custody - -e763 // Redundant declaration for symbol '...' previously declared -e726 // Extraneous comma ignored -e728 // Symbol ... not explicitly initialized @@ -17,14 +15,6 @@ -emacro((826), TAILQ_PREV) // Suspicious pointer-to-pointer conversion (area too small) --esym(534, printf) // Ignoring return value of function --esym(534, fprintf) // Ignoring return value of function --esym(534, memset) // Ignoring return value of function --esym(534, memcpy) // Ignoring return value of function --esym(534, memmove) // Ignoring return value of function --esym(534, strcpy) // Ignoring return value of function --esym(534, vsb_printf) // Ignoring return value of function --esym(534, vsb_cat) // Ignoring return value of function // cache.h -emacro(506, INCOMPL) // Constant value Boolean Modified: trunk/varnish-cache/bin/varnishtest/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishtest/flint.lnt 2010-06-05 13:20:16 UTC (rev 4902) +++ trunk/varnish-cache/bin/varnishtest/flint.lnt 2010-06-05 13:21:13 UTC (rev 4903) @@ -1,8 +1,6 @@ +libh mgt_event.h --emacro((???),va_arg) // the va_arg() macro can yield 415, 416, 661, 662 - // 796 and 797 (out-of-bounds errors). -elib(123) // size is both a variable and a macro with args -emacro(736, isnan) // isnanf -efile(766, ../../config.h) @@ -11,8 +9,6 @@ -esym(528, svnid) --ffc // No automatic custody - -e712 // 14 Info 712 Loss of precision (___) (___ to ___) -e747 // 16 Info 747 Significant prototype coercion (___) ___ to ___ @@ -46,22 +42,6 @@ -emacro(774, REPLACE) // if(bool) always true -emacro(506, REPLACE) // const bool // --esym(534, sprintf) // Ignoring return value of function -// -esym(534, asprintf) // Ignoring return value of function --esym(534, printf) // Ignoring return value of function --esym(534, fprintf) // Ignoring return value of function --esym(534, memset) // Ignoring return value of function -// -esym(534, memcpy) // Ignoring return value of function -// -esym(534, memmove) // Ignoring return value of function -// -esym(534, strcpy) // Ignoring return value of function --esym(534, vsb_printf) // Ignoring return value of function --esym(534, vsb_cat) // Ignoring return value of function --esym(534, vsb_bcat) // Ignoring return value of function --esym(534, vsb_putc) // Ignoring return value of function --esym(534, strcat) // Ignoring return value of function --esym(534, strcpy) // Ignoring return value of function --esym(534, strlcpy) // Ignoring return value of function -// // -emacro(506, isnan) // constant value boolean // -emacro(747, isnan) // significant coersion // -emacro(506, assert) // constant value boolean From phk at varnish-cache.org Sat Jun 5 13:30:56 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 15:30:56 +0200 Subject: r4904 - in trunk/varnish-cache/bin: . varnishd varnishncsa varnishtest Message-ID: Author: phk Date: 2010-06-05 15:30:55 +0200 (Sat, 05 Jun 2010) New Revision: 4904 Modified: trunk/varnish-cache/bin/flint.lnt trunk/varnish-cache/bin/varnishd/flint.lnt trunk/varnish-cache/bin/varnishncsa/flint.lnt trunk/varnish-cache/bin/varnishtest/flint.lnt Log: More .lnt centralizing Modified: trunk/varnish-cache/bin/flint.lnt =================================================================== --- trunk/varnish-cache/bin/flint.lnt 2010-06-05 13:21:13 UTC (rev 4903) +++ trunk/varnish-cache/bin/flint.lnt 2010-06-05 13:30:55 UTC (rev 4904) @@ -19,6 +19,43 @@ -sem(vas_fail, r_no) /////////////////////////////////////////////////////////////////////// +// + +-esym(755, VLIST_*) // Global macro not ref. +-esym(755, VSLIST_*) +-esym(755, VSTAILQ_*) +-esym(755, VTAILQ_*) + +-emacro((826), VTAILQ_LAST) // Suspicious pointer-to-pointer conversion (area too small) +-emacro((826), VTAILQ_PREV) // Suspicious pointer-to-pointer conversion (area too small) +-emacro(506, VTAILQ_FOREACH_SAFE) // constant value boolean +-emacro(506, VSTAILQ_FOREACH_SAFE) // constant value boolean +-emacro(740, VTAILQ_LAST) // Unusual pointer cast (incompatible indirect types) +-emacro(740, VTAILQ_PREV) // Unusual pointer cast (incompatible indirect types) +-esym(755, VTAILQ_*) + +/////////////////////////////////////////////////////////////////////// +// miniobj + +-emacro(755, CAST_OBJ) + +/////////////////////////////////////////////////////////////////////// +// VSB + +-esym(759, vsb_*) // header decl could be moved +-esym(765, vsb_*) // exten could be made static +-esym(714, vsb_*) // symb not ref +-sem(vsb_new, @p == (1p ? 1p : malloc(1))) +-sem(vsb_delete, custodial(1)) + +-esym(534, vsb_cat) // Ignore retval +-esym(534, vsb_bcat) +-esym(534, vsb_putc) +-esym(534, vsb_printf) +-esym(534, vsb_vprintf) +-esym(534, vsb_putc) + +/////////////////////////////////////////////////////////////////////// // Ignore return values OK for these functions -esym(534, printf) @@ -32,10 +69,3 @@ -esym(534, strcat) -esym(534, strcpy) -esym(534, strlcpy) - --esym(534, vsb_cat) --esym(534, vsb_bcat) --esym(534, vsb_putc) --esym(534, vsb_printf) --esym(534, vsb_vprintf) --esym(534, vsb_putc) Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2010-06-05 13:21:13 UTC (rev 4903) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2010-06-05 13:30:55 UTC (rev 4904) @@ -12,9 +12,6 @@ -esym(759, vev_*) -esym(765, vev_*) -esym(714, vev_*) --esym(759, vsb_*) --esym(765, vsb_*) --esym(714, vsb_*) -esym(759, vpf_*) -esym(765, vpf_*) -esym(714, vpf_*) @@ -33,11 +30,6 @@ -esym(759, CLI_*) -esym(755, CLI_*) --esym(755, VLIST_*) --esym(755, VSLIST_*) --esym(755, VSTAILQ_*) --esym(755, VTAILQ_*) - // XXX: I think this is a flexelint bug: -esym(522, vbit_clr) @@ -126,8 +118,6 @@ // Fix strchr() semtics, it can only return NULL if arg2 != 0 -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) --sem(vsb_new, @p == (1p ? 1p : malloc(1))) --sem(vsb_delete, custodial(1)) -sem(pthread_create, custodial(4)) -sem(WS_Init, custodial(2)) -sem(http_Setup, custodial(2)) @@ -141,13 +131,6 @@ -e785 // Too few initializers for aggregate -e786 // String concatenation within initializer --emacro(740, VTAILQ_PREV) // Unusual pointer cast (incompatible indirect types) --emacro(740, VTAILQ_LAST) // Unusual pointer cast (incompatible indirect types) --emacro((826), VTAILQ_PREV) // Suspicious pointer-to-pointer conversion (area too small) --emacro((826), VTAILQ_LAST) // Suspicious pointer-to-pointer conversion (area too small) --emacro(506, VTAILQ_FOREACH_SAFE) // constant value boolean --emacro(506, VSTAILQ_FOREACH_SAFE) // constant value boolean - -esym(765, vcc_ProcAction) // could be made static -esym(759, vcc_ProcAction) // could be moved to module -esym(714, vcc_ProcAction) // not ref. Modified: trunk/varnish-cache/bin/varnishncsa/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishncsa/flint.lnt 2010-06-05 13:21:13 UTC (rev 4903) +++ trunk/varnish-cache/bin/varnishncsa/flint.lnt 2010-06-05 13:30:55 UTC (rev 4904) @@ -11,11 +11,6 @@ -e785 // Too few initializers for aggregate -e786 // String concatenation within initializer --emacro(740, TAILQ_PREV) // Unusual pointer cast (incompatible indirect types) --emacro((826), TAILQ_PREV) // Suspicious pointer-to-pointer conversion (area too small) - - - // cache.h -emacro(506, INCOMPL) // Constant value Boolean Modified: trunk/varnish-cache/bin/varnishtest/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishtest/flint.lnt 2010-06-05 13:21:13 UTC (rev 4903) +++ trunk/varnish-cache/bin/varnishtest/flint.lnt 2010-06-05 13:30:55 UTC (rev 4904) @@ -33,11 +33,6 @@ // -e785 // Too few initializers for aggregate // -e786 // String concatenation within initializer // -// -emacro(740, VTAILQ_PREV) // Unusual pointer cast (incompatible indirect types) -// -emacro(740, VTAILQ_LAST) // Unusual pointer cast (incompatible indirect types) -// -emacro((826), VTAILQ_PREV) // Suspicious pointer-to-pointer conversion (area too small) -// -emacro((826), VTAILQ_LAST) // Suspicious pointer-to-pointer conversion (area too small) --emacro(506, VTAILQ_FOREACH_SAFE) // constant value boolean -emacro(779, REPLACE) // string constant != -emacro(774, REPLACE) // if(bool) always true -emacro(506, REPLACE) // const bool From phk at varnish-cache.org Sat Jun 5 14:24:04 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 16:24:04 +0200 Subject: r4905 - in trunk/varnish-cache/bin: . varnishd varnishncsa varnishtest Message-ID: Author: phk Date: 2010-06-05 16:24:04 +0200 (Sat, 05 Jun 2010) New Revision: 4905 Modified: trunk/varnish-cache/bin/flint.lnt trunk/varnish-cache/bin/varnishd/flint.lnt trunk/varnish-cache/bin/varnishncsa/flint.lnt trunk/varnish-cache/bin/varnishtest/flint.lnt Log: More flexelint cleanup Modified: trunk/varnish-cache/bin/flint.lnt =================================================================== --- trunk/varnish-cache/bin/flint.lnt 2010-06-05 13:30:55 UTC (rev 4904) +++ trunk/varnish-cache/bin/flint.lnt 2010-06-05 14:24:04 UTC (rev 4905) @@ -3,20 +3,23 @@ -ffc // No automatic custody /////////////////////////////////////////////////////////////////////// -// ../../config.h magic +// Weirdness relating to varnish includes etc. + -header(../../config.h) +libh ../../config.h -efile(451, ../../config.h) // No include guard +-esym(528, svnid) // Sym not ref -/////////////////////////////////////////////////////////////////////// -// varargs stuff +-efile(451, shmlog_tags.h) // No include guard --emacro((???), va_arg) // 415, 416, 416, 661, 662, 796, 797 ... - /////////////////////////////////////////////////////////////////////// // assert() support, common to libvarnish and libvarnishapi -sem(vas_fail, r_no) +-emacro(506, assert) // constant value boolean +-emacro(827, assert) // loop not reachable +-emacro(774, assert) // booelan always true +-emacro(527, WRONG) // unreachable code /////////////////////////////////////////////////////////////////////// // @@ -37,9 +40,18 @@ /////////////////////////////////////////////////////////////////////// // miniobj --emacro(755, CAST_OBJ) +// -emacro(755, CAST_OBJ) // glob macro not ref +-emacro(779, REPLACE) // string constant != +-emacro(774, REPLACE) // if(bool) always true +-emacro(506, REPLACE) // const bool /////////////////////////////////////////////////////////////////////// +// VMB +-emacro(755, VMB) // glob macro not ref +-emacro(755, VRMB) // glob macro not ref +-emacro(755, VWMB) // glob macro not ref + +/////////////////////////////////////////////////////////////////////// // VSB -esym(759, vsb_*) // header decl could be moved @@ -56,9 +68,16 @@ -esym(534, vsb_putc) /////////////////////////////////////////////////////////////////////// -// Ignore return values OK for these functions +// System library/POSIX related +/////////////////////////////////////////////////////////////////////// --esym(534, printf) +// vararg simulation is imperfect (XXX: why ??) +-emacro((???), va_arg) // 415, 416, 416, 661, 662, 796, 797 ... + +// Fix strchr() semtics, it can only return NULL if arg2 != 0 +-sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) + +-esym(534, printf) // Ignore retval -esym(534, fprintf) -esym(534, sprintf) @@ -69,3 +88,11 @@ -esym(534, strcat) -esym(534, strcpy) -esym(534, strlcpy) + +-sem(pthread_create, custodial(4)) +-emacro(413, offsetof) // likely null pointer +-emacro(736, isnan) // loss of prec. + ++libh(/usr/include/curses.h) +-elib(659) // no tokens after struct def. +-elib(123) // macro def. with arg at, (just warn) Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2010-06-05 13:30:55 UTC (rev 4904) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2010-06-05 14:24:04 UTC (rev 4905) @@ -1,13 +1,5 @@ -d__flexelint_v9__=1 --libdir(../../include) --libdir(../../lib/) - -// -efile(765, ../../lib/) -// -efile(765, ../../include/) -// -efile(759, ../../lib/) -// -efile(759, ../../include/) - -esym(755, vct_*) -esym(759, vev_*) -esym(765, vev_*) @@ -96,29 +88,16 @@ -esym(458, VSL_stats) -esym(458, heritage) -esym(458, name_key) --esym(528, svnid) ////////////// +libh mgt_event.h --elib(123) // size is both a variable and a macro with args --emacro(736, isnan) // isnanf --efile(766, ../../config.h) --emacro(413, offsetof) // likely null pointer --emacro(527, WRONG) // unreachable code -emacro(527, NEEDLESS_RETURN) // unreachable code -emacro(702, WEXITSTATUS) // signed shift right -efunc(525, VCC_Return_Name) // Negative indent - - - -// Fix strchr() semtics, it can only return NULL if arg2 != 0 --sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) - --sem(pthread_create, custodial(4)) -sem(WS_Init, custodial(2)) -sem(http_Setup, custodial(2)) @@ -140,9 +119,6 @@ -emacro(506, isnan, isfinite) // constant value boolean -emacro(736, isfinite) // loss of precision -emacro(747, isnan) // significant coersion --emacro(506, assert) // constant value boolean --emacro(827, assert) // loop not reachable --emacro(774, assert) // booelan always true -emacro(774, HTTPH) // always false -emacro(527, ARGV_ERR) // unreachable Modified: trunk/varnish-cache/bin/varnishncsa/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishncsa/flint.lnt 2010-06-05 13:30:55 UTC (rev 4904) +++ trunk/varnish-cache/bin/varnishncsa/flint.lnt 2010-06-05 14:24:04 UTC (rev 4905) @@ -1,9 +1,6 @@ +d__attribute__()= -// Fix strchr() semtics, it can only return NULL if arg2 != 0 --sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) - -e763 // Redundant declaration for symbol '...' previously declared -e726 // Extraneous comma ignored -e728 // Symbol ... not explicitly initialized @@ -11,9 +8,6 @@ -e785 // Too few initializers for aggregate -e786 // String concatenation within initializer -// cache.h --emacro(506, INCOMPL) // Constant value Boolean - // cache_center.c -efunc(525, CNT_Session) // Negative indentation from line -efunc(525, http_FilterHeader) // Negative indentation from line Modified: trunk/varnish-cache/bin/varnishtest/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishtest/flint.lnt 2010-06-05 13:30:55 UTC (rev 4904) +++ trunk/varnish-cache/bin/varnishtest/flint.lnt 2010-06-05 14:24:04 UTC (rev 4905) @@ -1,63 +1,12 @@ -+libh mgt_event.h - --elib(123) // size is both a variable and a macro with args --emacro(736, isnan) // isnanf --efile(766, ../../config.h) - -esym(850, av) --esym(528, svnid) - -e712 // 14 Info 712 Loss of precision (___) (___ to ___) -e747 // 16 Info 747 Significant prototype coercion (___) ___ to ___ - -// Fix strchr() semtics, it can only return NULL if arg2 != 0 --sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) -// -// -sem(vsb_new, @p == malloc(1)) -// -sem(vsb_delete, custodial(1)) --sem(lbv_assert, r_no) --sem(lbv_xxxassert, r_no) -// -sem(WS_Init, custodial(2)) -// -sem(http_Setup, custodial(2)) -// -// -ffc // No automatic custody -// -e763 // Redundant declaration for symbol '...' previously declared -// -e726 // Extraneous comma ignored -// -e728 // Symbol ... not explicitly initialized -e716 // while(1) ... -// -e785 // Too few initializers for aggregate -// -e786 // String concatenation within initializer -// --emacro(779, REPLACE) // string constant != --emacro(774, REPLACE) // if(bool) always true --emacro(506, REPLACE) // const bool -// -// -emacro(506, isnan) // constant value boolean -// -emacro(747, isnan) // significant coersion -// -emacro(506, assert) // constant value boolean -// -emacro(827, assert) // loop not reachable -// -emacro(774, assert) // booelan always true -// -emacro(774, HTTPH) // always false -// -// // cache.h -// -emacro(506, INCOMPL) // Constant value Boolean -// -// // cache_center.c -// -efunc(525, CNT_Session) // Negative indentation from line -// -efunc(525, http_FilterFields) // Negative indentation from line -// -efunc(539, http_FilterFields) // Positive indentation from line -// -// // cache_vcl.c -// -efunc(525, vcl_handlingname) // Negative indentation from line -// -esym(528, vcl_handlingname) // Not referenced -// -e641 // Converting enum 'cli_status_e' to int -// -// // Review all below this line /////////////////////////////////////////////// -e457 // unprotected write access -e459 // unprotected access @@ -67,17 +16,3 @@ -e737 // [45] Loss of sign in promotion from int to unsigned -e713 // Loss of precision (assignment) (unsigned long long to long long) -e574 // Signed-unsigned mix with relational -// -e712 // Loss of precision (assignment) (long long to -// -e747 // Significant prototype coercion (arg. no. 2) long -// -// /* -// -// -e767 // Macro redef (system queue.h vs ours ) -// -// -e506 // Constant value boolean -// -e818 // Pointer parameter '...' could be declared as pointing to const -// -e774 // Boolean within 'if' always evaluates to False -// -e534 // Ignoring return value of function -// -e557 // unrecog format -// -// */ From phk at varnish-cache.org Sat Jun 5 14:33:07 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 16:33:07 +0200 Subject: r4906 - in trunk/varnish-cache/bin: . varnishtest Message-ID: Author: phk Date: 2010-06-05 16:33:07 +0200 (Sat, 05 Jun 2010) New Revision: 4906 Modified: trunk/varnish-cache/bin/flint.lnt trunk/varnish-cache/bin/varnishtest/vtc.c trunk/varnish-cache/bin/varnishtest/vtc_http.c trunk/varnish-cache/bin/varnishtest/vtc_log.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Flexelint polishing Modified: trunk/varnish-cache/bin/flint.lnt =================================================================== --- trunk/varnish-cache/bin/flint.lnt 2010-06-05 14:24:04 UTC (rev 4905) +++ trunk/varnish-cache/bin/flint.lnt 2010-06-05 14:33:07 UTC (rev 4906) @@ -12,6 +12,7 @@ -esym(528, svnid) // Sym not ref -efile(451, shmlog_tags.h) // No include guard +-efile(451, stat_field.h) // No include guard /////////////////////////////////////////////////////////////////////// // assert() support, common to libvarnish and libvarnishapi Modified: trunk/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.c 2010-06-05 14:24:04 UTC (rev 4905) +++ trunk/varnish-cache/bin/varnishtest/vtc.c 2010-06-05 14:33:07 UTC (rev 4906) @@ -175,6 +175,7 @@ *q = '\0'; m = macro_get(p); if (m == NULL) { + vsb_delete(vsb); vtc_log(vl, 0, "Macro ${%s} not found", p); return (NULL); } Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2010-06-05 14:24:04 UTC (rev 4905) +++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2010-06-05 14:33:07 UTC (rev 4906) @@ -870,7 +870,7 @@ AN(av[1]); AN(av[2]); AZ(av[3]); - n = strtod(av[1], NULL); + n = strtoul(av[1], NULL, 0); for (m = 1 ; m <= n; m++) { vtc_log(vl, 4, "Loop #%u", m); s = strdup(av[2]); Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_log.c 2010-06-05 14:24:04 UTC (rev 4905) +++ trunk/varnish-cache/bin/varnishtest/vtc_log.c 2010-06-05 14:33:07 UTC (rev 4906) @@ -122,7 +122,7 @@ #define NLEAD (sizeof(lead)/sizeof(lead[0])) static void -vtc_log_emit(struct vtclog *vl, unsigned lvl) +vtc_log_emit(const struct vtclog *vl, unsigned lvl) { if (vtc_stop && lvl == 0) return; Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-05 14:24:04 UTC (rev 4905) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-05 14:33:07 UTC (rev 4906) @@ -526,6 +526,7 @@ u = varnish_ask_cli(v, vsb_data(vsb), NULL); if (u != expect) { + vsb_delete(vsb); vtc_log(v->vl, 0, "VCL compilation got %u expected %u", u, expect); @@ -581,6 +582,8 @@ u = varnish_ask_cli(v, vsb_data(vsb), NULL); if (u != CLIS_OK) { + vsb_delete(vsb); + vsb_delete(vsb2); vtc_log(v->vl, 0, "FAIL VCL does not compile"); return; } From phk at varnish-cache.org Sat Jun 5 14:53:27 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 16:53:27 +0200 Subject: r4907 - trunk/varnish-cache/bin/varnishtest Message-ID: Author: phk Date: 2010-06-05 16:53:26 +0200 (Sat, 05 Jun 2010) New Revision: 4907 Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Convert varnishtest to handle dynamic stats counters Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-05 14:33:07 UTC (rev 4906) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-05 14:53:26 UTC (rev 4907) @@ -601,51 +601,87 @@ * Check statistics */ +struct stat_priv { + const char *target; + uintmax_t val; +}; + +static int +do_stat_cb(void *priv, const struct vsl_statpt * const pt) +{ + struct stat_priv *sp = priv; + const char *p = sp->target; + int i; + + if (strcmp(pt->type, "")) { + i = strlen(pt->type); + if (memcmp(pt->type, p, i)) + return (0); + p += i; + if (*p != '.') + return (0); + p++; + } + if (strcmp(pt->ident, "")) { + i = strlen(pt->ident); + if (memcmp(pt->ident, p, i)) + return (0); + p += i; + if (*p != '.') + return (0); + p++; + } + if (strcmp(pt->nm, p)) + return (0); + + assert(!strcmp(pt->fmt, "uint64_t")); + sp->val = *(const volatile uint64_t*)pt->ptr; + return (1); +} + static void varnish_expect(const struct varnish *v, char * const *av) { - uint64_t val, ref; + uint64_t ref; int good; char *p; int i; + struct stat_priv sp; + + good = -1; - good = 0; - + sp.target = av[0]; + sp.val = 0; for (i = 0; i < 10; i++, (void)usleep(100000)) { + good = -1; + if (!VSL_IterStat(v->vd, do_stat_cb, &sp)) + continue; + good = 0; -#define MAC_STAT(n, t, l, f, d) \ - if (!strcmp(av[0], #n)) { \ - val = v->stats->n; \ - } else -#include "stat_field.h" -#undef MAC_STAT - { - val = 0; - vtc_log(v->vl, 0, "stats field %s unknown", av[0]); - } - ref = strtoumax(av[2], &p, 0); if (ref == UINTMAX_MAX || *p) vtc_log(v->vl, 0, "Syntax error in number (%s)", av[2]); - if (!strcmp(av[1], "==")) { if (val == ref) good = 1; } - else if (!strcmp(av[1], "!=")) { if (val != ref) good = 1; } - else if (!strcmp(av[1], ">")) { if (val > ref) good = 1; } - else if (!strcmp(av[1], "<")) { if (val < ref) good = 1; } - else if (!strcmp(av[1], ">=")) { if (val >= ref) good = 1; } - else if (!strcmp(av[1], "<=")) { if (val <= ref) good = 1; } + if (!strcmp(av[1], "==")) { if (sp.val == ref) good = 1; } + else if (!strcmp(av[1], "!=")) { if (sp.val != ref) good = 1; } + else if (!strcmp(av[1], ">")) { if (sp.val > ref) good = 1; } + else if (!strcmp(av[1], "<")) { if (sp.val < ref) good = 1; } + else if (!strcmp(av[1], ">=")) { if (sp.val >= ref) good = 1; } + else if (!strcmp(av[1], "<=")) { if (sp.val <= ref) good = 1; } else { vtc_log(v->vl, 0, "comparison %s unknown", av[1]); } if (good) break; } - if (good) { + if (good == -1) { + vtc_log(v->vl, 0, "stats field %s unknown", av[0]); + } else if (good) { vtc_log(v->vl, 2, "as expected: %s (%ju) %s %s", - av[0], val, av[1], av[2]); - return; + av[0], sp.val, av[1], av[2]); + } else { + vtc_log(v->vl, 0, "Not true: %s (%ju) %s %s (%ju)", + av[0], sp.val, av[1], av[2], ref); } - vtc_log(v->vl, 0, "Not true: %s (%ju) %s %s (%ju)", - av[0], val, av[1], av[2], ref); } /********************************************************************** From phk at varnish-cache.org Sat Jun 5 15:14:43 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 17:14:43 +0200 Subject: r4908 - in trunk/varnish-cache/bin: . varnishd varnishtest Message-ID: Author: phk Date: 2010-06-05 17:14:43 +0200 (Sat, 05 Jun 2010) New Revision: 4908 Modified: trunk/varnish-cache/bin/flint.lnt trunk/varnish-cache/bin/varnishd/flint.lnt trunk/varnish-cache/bin/varnishtest/flint.lnt trunk/varnish-cache/bin/varnishtest/vtc.c trunk/varnish-cache/bin/varnishtest/vtc.h trunk/varnish-cache/bin/varnishtest/vtc_http.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: More flexelinting Modified: trunk/varnish-cache/bin/flint.lnt =================================================================== --- trunk/varnish-cache/bin/flint.lnt 2010-06-05 14:53:26 UTC (rev 4907) +++ trunk/varnish-cache/bin/flint.lnt 2010-06-05 15:14:43 UTC (rev 4908) @@ -97,3 +97,5 @@ +libh(/usr/include/curses.h) -elib(659) // no tokens after struct def. -elib(123) // macro def. with arg at, (just warn) + +-emacro(702, WEXITSTATUS) // signed shift right Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2010-06-05 14:53:26 UTC (rev 4907) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2010-06-05 15:14:43 UTC (rev 4908) @@ -95,7 +95,6 @@ -emacro(527, NEEDLESS_RETURN) // unreachable code --emacro(702, WEXITSTATUS) // signed shift right -efunc(525, VCC_Return_Name) // Negative indent -sem(WS_Init, custodial(2)) Modified: trunk/varnish-cache/bin/varnishtest/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishtest/flint.lnt 2010-06-05 14:53:26 UTC (rev 4907) +++ trunk/varnish-cache/bin/varnishtest/flint.lnt 2010-06-05 15:14:43 UTC (rev 4908) @@ -4,7 +4,13 @@ -e712 // 14 Info 712 Loss of precision (___) (___ to ___) -e747 // 16 Info 747 Significant prototype coercion (___) ___ to ___ +-e445 // Reuse of for loop variable '___' at '___' could cause chaos +-e850 // for loop index variable '___' whose type category is '___' is modified in body of the for loop that began at '___' +-e443 // for clause irregularity: variable '___' initialized in 1st expression does not match '___' modified in 3rd + +-e679 // Suspicious Truncation in arithmetic expression combining with pointer + -e763 // Redundant declaration for symbol '...' previously declared -e716 // while(1) ... Modified: trunk/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.c 2010-06-05 14:53:26 UTC (rev 4907) +++ trunk/varnish-cache/bin/varnishtest/vtc.c 2010-06-05 15:14:43 UTC (rev 4908) @@ -133,14 +133,16 @@ } static char * -macro_get(const char *name) +macro_get(const char *b, const char *e) { struct macro *m; + int l; char *retval = NULL; AZ(pthread_mutex_lock(¯o_mtx)); + l = e - b; VTAILQ_FOREACH(m, ¯o_list, list) - if (!strcmp(name, m->name)) + if (!memcmp(b, m->name, l) && m->name[l] == '\0') break; if (m != NULL) retval = strdup(m->val); @@ -152,7 +154,8 @@ macro_expand(struct vtclog *vl, const char *text) { struct vsb *vsb; - char *p, *q, *m; + const char *p, *q; + char *m; vsb = vsb_newauto(); AN(vsb); @@ -172,8 +175,7 @@ assert(p[1] == '{'); assert(q[0] == '}'); p += 2; - *q = '\0'; - m = macro_get(p); + m = macro_get(p, q); if (m == NULL) { vsb_delete(vsb); vtc_log(vl, 0, "Macro ${%s} not found", p); @@ -402,23 +404,6 @@ } /********************************************************************** - * Dump command arguments - */ - -void -cmd_dump(CMD_ARGS) -{ - - (void)cmd; - (void)vl; - if (av == NULL) - return; - printf("cmd_dump(%p)\n", priv); - while (*av) - printf("\t<%s>\n", *av++); -} - -/********************************************************************** * Check random generator */ Modified: trunk/varnish-cache/bin/varnishtest/vtc.h =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.h 2010-06-05 14:53:26 UTC (rev 4907) +++ trunk/varnish-cache/bin/varnishtest/vtc.h 2010-06-05 15:14:43 UTC (rev 4908) @@ -47,7 +47,6 @@ void parse_string(char *buf, const struct cmds *cmd, void *priv, struct vtclog *vl); -cmd_f cmd_dump; cmd_f cmd_delay; cmd_f cmd_server; cmd_f cmd_client; Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2010-06-05 14:53:26 UTC (rev 4907) +++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2010-06-05 15:14:43 UTC (rev 4908) @@ -116,8 +116,8 @@ k = '!'; l = k; } else { - b[j] = l++; - if (l == '~') + b[j] = (char)l; + if (++l == '~') l = '!'; } } @@ -505,7 +505,7 @@ const char *proto = "HTTP/1.1"; const char *status = "200"; const char *msg = "Ok"; - int bodylen; + int bodylen = 0; char *b, *c; char *body = NULL; Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-05 14:53:26 UTC (rev 4907) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-05 15:14:43 UTC (rev 4908) @@ -226,7 +226,7 @@ int i; CAST_OBJ_NOTNULL(v, priv, VARNISH_MAGIC); - TCP_nonblocking(v->fds[0]); + (void)TCP_nonblocking(v->fds[0]); while (1) { fds = &fd; memset(fds, 0, sizeof fds); @@ -332,7 +332,6 @@ AZ(close(v->cli_fd)); v->cli_fd = nfd; - nfd = -1; vtc_log(v->vl, 3, "CLI connection fd = %d", v->cli_fd); assert(v->cli_fd >= 0); @@ -365,7 +364,7 @@ if (v->stats != NULL) VSL_Close(v->vd); - VSL_Arg(v->vd, 'n', v->workdir); + (void)VSL_Arg(v->vd, 'n', v->workdir); v->stats = VSL_OpenStats(v->vd); } @@ -651,6 +650,7 @@ sp.target = av[0]; sp.val = 0; + ref = 0; for (i = 0; i < 10; i++, (void)usleep(100000)) { good = -1; From phk at varnish-cache.org Sat Jun 5 20:17:36 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 22:17:36 +0200 Subject: r4909 - in trunk/varnish-cache: bin/varnishadm bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishsizes bin/varnishstat bin/varnishtest bin/varnishtop include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-05 22:17:36 +0200 (Sat, 05 Jun 2010) New Revision: 4909 Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c trunk/varnish-cache/bin/varnishhist/varnishhist.c trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/bin/varnishncsa/varnishncsa.c trunk/varnish-cache/bin/varnishreplay/varnishreplay.c trunk/varnish-cache/bin/varnishsizes/varnishsizes.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/bin/varnishtop/varnishtop.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c Log: Split VSL_Arg() into VSL_Log_Arg() and VSL_Stat_Arg() Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.c 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.c 2010-06-05 20:17:36 UTC (rev 4909) @@ -244,7 +244,7 @@ if (n_arg != NULL) { vsd = VSL_New(); - assert(VSL_Arg(vsd, 'n', n_arg)); + assert(VSL_Log_Arg(vsd, 'n', n_arg)); if (!VSL_Open(vsd)) { if (T_arg == NULL) { p = VSL_Find_Alloc(vsd, "Arg", "-T", "", NULL); Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-05 20:17:36 UTC (rev 4909) @@ -332,7 +332,7 @@ delay = atoi(optarg); break; default: - if (VSL_Arg(vd, o, optarg) > 0) + if (VSL_Log_Arg(vd, o, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-05 20:17:36 UTC (rev 4909) @@ -325,11 +325,11 @@ break; case 'b': b_flag = 1; - VSL_Arg(vd, c, optarg); + VSL_Log_Arg(vd, c, optarg); break; case 'c': c_flag = 1; - VSL_Arg(vd, c, optarg); + VSL_Log_Arg(vd, c, optarg); break; case 'D': D_flag = 1; @@ -350,7 +350,7 @@ w_arg = optarg; break; default: - if (VSL_Arg(vd, c, optarg) > 0) + if (VSL_Log_Arg(vd, c, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-05 20:17:36 UTC (rev 4909) @@ -557,13 +557,13 @@ /* XXX: Silently ignored: it's required anyway */ break; default: - if (VSL_Arg(vd, c, optarg) > 0) + if (VSL_Log_Arg(vd, c, optarg) > 0) break; usage(); } } - VSL_Arg(vd, 'c', optarg); + VSL_Log_Arg(vd, 'c', optarg); if (VSL_OpenLog(vd)) exit(1); Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-05 20:17:36 UTC (rev 4909) @@ -723,7 +723,7 @@ vd = VSL_New(); debug = 0; - VSL_Arg(vd, 'c', NULL); + VSL_Log_Arg(vd, 'c', NULL); while ((c = getopt(argc, argv, "a:Dr:n:")) != -1) { switch (c) { case 'a': @@ -733,7 +733,7 @@ ++debug; break; default: - if (VSL_Arg(vd, c, optarg) > 0) + if (VSL_Log_Arg(vd, c, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/bin/varnishsizes/varnishsizes.c =================================================================== --- trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-05 20:17:36 UTC (rev 4909) @@ -333,7 +333,7 @@ delay = atoi(optarg); break; default: - if (VSL_Arg(vd, o, optarg) > 0) + if (VSL_Log_Arg(vd, o, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 20:17:36 UTC (rev 4909) @@ -296,7 +296,7 @@ xml = 1; break; default: - if (VSL_Arg(vd, c, optarg) > 0) + if (VSL_Stat_Arg(vd, c, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-05 20:17:36 UTC (rev 4909) @@ -364,7 +364,7 @@ if (v->stats != NULL) VSL_Close(v->vd); - (void)VSL_Arg(v->vd, 'n', v->workdir); + (void)VSL_Log_Arg(v->vd, 'n', v->workdir); v->stats = VSL_OpenStats(v->vd); } Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-05 20:17:36 UTC (rev 4909) @@ -309,7 +309,7 @@ while ((o = getopt(argc, argv, VSL_LOG_ARGS "1fV")) != -1) { switch (o) { case '1': - VSL_Arg(vd, 'd', NULL); + VSL_Log_Arg(vd, 'd', NULL); once = 1; break; case 'f': @@ -319,7 +319,7 @@ varnish_version("varnishtop"); exit(0); default: - if (VSL_Arg(vd, o, optarg) > 0) + if (VSL_Log_Arg(vd, o, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-05 20:17:36 UTC (rev 4909) @@ -55,7 +55,8 @@ void VSL_NonBlocking(struct VSL_data *vd, int nb); int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv); int VSL_NextLog(struct VSL_data *lh, unsigned char **pp); -int VSL_Arg(struct VSL_data *vd, int arg, const char *opt); +int VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt); +int VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt); void VSL_Close(struct VSL_data *vd); int VSL_Open(struct VSL_data *vd); void VSL_Delete(struct VSL_data *vd); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-05 15:14:43 UTC (rev 4908) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-05 20:17:36 UTC (rev 4909) @@ -167,6 +167,7 @@ } return (1); } + /*--------------------------------------------------------------------*/ static int @@ -187,15 +188,26 @@ return (1); } -/*-------------------------------------------------------------------- - * XXX: Should really be split into three: - * VSL_Arg() for generic args for all programs (-n) - * VSL_Log_Arg() for log readers. - * VSL_Stat_Arg() for stat reporters. - */ +/*--------------------------------------------------------------------*/ +static int +vsl_n_arg(struct VSL_data *vd, const char *opt) +{ + + REPLACE(vd->n_opt, opt); + AN(vd->n_opt); + if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) { + fprintf(stderr, "Invalid instance name: %s\n", + strerror(errno)); + return (-1); + } + return (1); +} + +/*--------------------------------------------------------------------*/ + int -VSL_Arg(struct VSL_data *vd, int arg, const char *opt) +VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt) { CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); @@ -208,16 +220,7 @@ return (1); case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg)); case 'k': return (vsl_k_arg(vd, opt)); - case 'n': - free(vd->n_opt); - vd->n_opt = strdup(opt); - assert(vd->n_opt != NULL); - if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) { - fprintf(stderr, "Invalid instance name: %s\n", - strerror(errno)); - return (-1); - } - return (1); + case 'n': return (vsl_n_arg(vd, opt)); case 'r': return (vsl_r_arg(vd, opt)); case 's': return (vsl_s_arg(vd, opt)); case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg)); @@ -236,3 +239,17 @@ return (0); } } + +/*--------------------------------------------------------------------*/ + +int +VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt) +{ + + CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + switch (arg) { + case 'n': return (vsl_n_arg(vd, opt)); + default: + return (0); + } +} From phk at varnish-cache.org Sat Jun 5 20:50:01 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 5 Jun 2010 22:50:01 +0200 Subject: r4910 - trunk/varnish-cache/include Message-ID: Author: phk Date: 2010-06-05 22:50:01 +0200 (Sat, 05 Jun 2010) New Revision: 4910 Added: trunk/varnish-cache/include/argv.h Modified: trunk/varnish-cache/include/libvarnish.h Log: Split argv.h into its own header Copied: trunk/varnish-cache/include/argv.h (from rev 4904, trunk/varnish-cache/include/libvarnish.h) =================================================================== --- trunk/varnish-cache/include/argv.h (rev 0) +++ trunk/varnish-cache/include/argv.h 2010-06-05 20:50:01 UTC (rev 4910) @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2009 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +void FreeArgv(char **argv); +char **ParseArgv(const char *s, int flag); +char *BackSlashDecode(const char *s, const char *e); +int BackSlash(const char *s, char *res); +#define ARGV_COMMENT (1 << 0) +#define ARGV_COMMA (1 << 1) Modified: trunk/varnish-cache/include/libvarnish.h =================================================================== --- trunk/varnish-cache/include/libvarnish.h 2010-06-05 20:17:36 UTC (rev 4909) +++ trunk/varnish-cache/include/libvarnish.h 2010-06-05 20:50:01 UTC (rev 4910) @@ -41,13 +41,7 @@ struct vsb; -/* from libvarnish/argv.c */ -void FreeArgv(char **argv); -char **ParseArgv(const char *s, int flag); -char *BackSlashDecode(const char *s, const char *e); -int BackSlash(const char *s, char *res); -#define ARGV_COMMENT (1 << 0) -#define ARGV_COMMA (1 << 1) +#include "argv.h" /* from libvarnish/num.c */ const char *str2bytes(const char *p, uintmax_t *r, uintmax_t rel); From phk at varnish-cache.org Sat Jun 5 22:41:54 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sun, 6 Jun 2010 00:41:54 +0200 Subject: r4911 - in trunk/varnish-cache: bin/varnishstat bin/varnishtest include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-06 00:41:54 +0200 (Sun, 06 Jun 2010) New Revision: 4911 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishstat/varnishstat.h trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/Makefile.am trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl.h trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c trunk/varnish-cache/lib/libvarnishapi/vsl_log.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Log: Move the varnishstat -f argument into varnishapi, it is broadly applicable and can be implemented more efficiently this way. The new syntax is an expansion of the old, which allows "class.ident.name" or just "name" patterns to be specified. A pattern which starts with '^' excludes the matching fields, otherwise the pattern includes them. If the first pattern is an exclude pattern, all fields start out included, and vice versa. Notice that "class" and "ident" fields always must have their trailing '.' even if they are empty. Each subcomponent can have a '*' suffix, which will ("glob") match anything. Multiple "-f" arguments can be given, they will be concatenated. All patterns will be tested sequentially, and the last one that matches determines the result. Example: -f "SMA..sma_nreq,^SMA.ba*." -f "shm_*" This will return: SMA.storage_0.sma_nreq shm_records shm_writes ... but not: SMA.storage_0.sma_nobj SMA.bar.sma_nreq sms_nreq ... Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-05 22:41:54 UTC (rev 4911) @@ -49,62 +49,23 @@ #include "varnishapi.h" #include "varnishstat.h" -#define FIELD_EXCLUSION_CHARACTER '^' - -int -show_field(const char* field, const char *fields) -{ - const char* field_start; - const char* field_end; - int field_length; - int match_value = 1; - - if (fields[0] == FIELD_EXCLUSION_CHARACTER) { - match_value = 0; - fields++; - } - - field_start = strstr(fields, field); - if (field_start != NULL) { - field_length = strlen( field ); - - while (field_start != NULL) { - field_end = field_start + field_length; - if ((field_start == fields || - *(field_start - 1) == ',') && - (*field_end == ',' || *field_end == '\0')) - return (match_value); - field_start = strstr( field_end, field ); - } - } - - return (!match_value); -} - /*--------------------------------------------------------------------*/ -struct xml_priv { - const char *fields; -}; - static int do_xml_cb(void *priv, const struct vsl_statpt * const pt) { uint64_t val; - struct xml_priv *xp; - xp = priv; - if (xp->fields != NULL && !show_field(pt->nm, xp->fields)) - return (0); + (void)priv; assert(!strcmp(pt->fmt, "uint64_t")); val = *(const volatile uint64_t*)pt->ptr; printf("\t\n"); - if (strcmp(pt->type, "")) - printf("\t\t%s\n", pt->type); + if (strcmp(pt->class, "")) + printf("\t\t%s\n", pt->class); if (strcmp(pt->ident, "")) printf("\t\t%s\n", pt->ident); - printf("\t\t%s\n", pt->nm); + printf("\t\t%s\n", pt->name); printf("\t\t%ju\n", val); printf("\t\t%c\n", pt->flag); printf("\t\t%s\n", pt->desc); @@ -113,19 +74,16 @@ } static void -do_xml(const struct VSL_data *vd, const char* fields) +do_xml(const struct VSL_data *vd) { char time_stamp[20]; time_t now; - struct xml_priv xp; - xp.fields = fields; - printf("\n"); now = time(NULL); (void)strftime(time_stamp, 20, "%Y-%m-%dT%H:%M:%S", localtime(&now)); printf("\n", time_stamp); - (void)VSL_IterStat(vd, do_xml_cb, &xp); + (void)VSL_IterStat(vd, do_xml_cb, NULL); printf("\n"); } @@ -133,7 +91,6 @@ struct once_priv { double up; - const char *fields; int pad; }; @@ -145,16 +102,14 @@ int i; op = priv; - if (op->fields != NULL && !show_field(pt->nm, op->fields)) - return (0); assert(!strcmp(pt->fmt, "uint64_t")); val = *(const volatile uint64_t*)pt->ptr; i = 0; - if (strcmp(pt->type, "")) - i += printf("%s.", pt->type); + if (strcmp(pt->class, "")) + i += printf("%s.", pt->class); if (strcmp(pt->ident, "")) i += printf("%s.", pt->ident); - i += printf("%s", pt->nm); + i += printf("%s", pt->name); if (i > op->pad) op->pad = i + 1; printf("%*.*s", op->pad - i, op->pad - i, ""); @@ -166,13 +121,12 @@ } static void -do_once(const struct VSL_data *vd, const struct varnish_stats *VSL_stats, const char* fields) +do_once(const struct VSL_data *vd, const struct varnish_stats *VSL_stats) { struct once_priv op; memset(&op, 0, sizeof op); op.up = VSL_stats->uptime; - op.fields = fields; op.pad = 18; (void)VSL_IterStat(vd, do_once_cb, &op); @@ -180,7 +134,37 @@ /*--------------------------------------------------------------------*/ +static int +do_list_cb(void *priv, const struct vsl_statpt * const pt) +{ + int i; + + (void)priv; + i = 0; + if (strcmp(pt->class, "")) + i += fprintf(stderr, "%s.", pt->class); + if (strcmp(pt->ident, "")) + i += fprintf(stderr, "%s.", pt->ident); + i += fprintf(stderr, "%s", pt->name); + if (i < 30) + fprintf(stderr, "%*s", i - 30, ""); + fprintf(stderr, " %s\n", pt->desc); + return (0); +} + static void +list_fields(const struct VSL_data *vd) +{ + fprintf(stderr, "Varnishstat -f option fields:\n"); + fprintf(stderr, "Field name Description\n"); + fprintf(stderr, "---------- -----------\n"); + + (void)VSL_IterStat(vd, do_list_cb, NULL); +} + +/*--------------------------------------------------------------------*/ + +static void usage(void) { #define FMT " %-28s # %s\n" @@ -204,66 +188,6 @@ exit(1); } -static void -list_fields(void) -{ - fprintf(stderr, "Varnishstat -f option fields:\n"); - fprintf(stderr, "Field name Description\n"); - fprintf(stderr, "---------- -----------\n"); - -#define MAC_STAT(n, t, l, f, d) \ - do { \ - fprintf(stderr, "%-20s %s\n", #n, d); \ - } while (0); -#include "stat_field.h" -#undef MAC_STAT -} - -static int -valid_fields(const char* fields) -{ - int i, valid_field, field_length; - const char *all_fields[] = { -#define MAC_STAT(n, t, l, f, d) \ - #n, -#include "stat_field.h" -#undef MAC_STAT - NULL }; - const char *field_start, *field_end; - - if (fields[0] == FIELD_EXCLUSION_CHARACTER) - fields++; - - for (field_start = fields; ; field_start = field_end + 1) { - field_end = strchr(field_start, ','); - if (field_end != NULL) - field_length = field_end - field_start; - else - field_length = strlen(field_start); - - valid_field = 0; - for (i = 0; all_fields[i] != NULL; i++) { - if (strncmp(field_start, all_fields[i], field_length) - == 0 && field_length == strlen( all_fields[i])) { - valid_field = 1; - break; - } - } - - if (!valid_field) { - (void)fputs("The field '", stderr); - (void)fwrite(field_start, 1, field_length, stderr); - (void)fputs("' is not a valid field\n", stderr); - return (0); - } - - if (field_end == NULL || *field_end == '\0') - break; - } - - return (1); -} - int main(int argc, char * const *argv) { @@ -271,7 +195,6 @@ struct VSL_data *vd; const struct varnish_stats *VSL_stats; int delay = 1, once = 0, xml = 0; - const char *fields = NULL; vd = VSL_New(); @@ -281,10 +204,12 @@ once = 1; break; case 'f': - fields = optarg; + (void)VSL_Stat_Arg(vd, c, optarg); break; case 'l': - list_fields(); + if (VSL_Open(vd)) + exit(1); + list_fields(vd); exit(0); case 'V': varnish_version("varnishstat"); @@ -308,17 +233,12 @@ if ((VSL_stats = VSL_OpenStats(vd)) == NULL) exit(1); - if (fields != NULL && !valid_fields(fields)) { - usage(); - exit(1); - } - if (xml) - do_xml(vd, fields); + do_xml(vd); else if (once) - do_once(vd, VSL_stats, fields); + do_once(vd, VSL_stats); else - do_curses(vd, VSL_stats, delay, fields); + do_curses(vd, VSL_stats, delay); exit(0); } Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.h =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.h 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.h 2010-06-05 22:41:54 UTC (rev 4911) @@ -27,5 +27,4 @@ * */ -int show_field(const char* field, const char *fields); -void do_curses(struct VSL_data *vd, const struct varnish_stats *VSL_stats, int delay, const char *fields); +void do_curses(struct VSL_data *vd, const struct varnish_stats *VSL_stats, int delay); Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-05 22:41:54 UTC (rev 4911) @@ -65,21 +65,13 @@ static VTAILQ_HEAD(, pt) pthead = VTAILQ_HEAD_INITIALIZER(pthead); - -struct curses_priv { - const char *fields; -}; - static int do_curses_cb(void *priv, const struct vsl_statpt * const sp) { - struct curses_priv *cp; struct pt *pt; char buf[128]; - cp = priv; - if (cp->fields != NULL && !show_field(sp->nm, cp->fields)) - return (0); + (void)priv; assert(!strcmp(sp->fmt, "uint64_t")); pt = calloc(sizeof *pt, 1); @@ -91,15 +83,15 @@ pt->type = sp->flag; *buf = '\0'; - if (strcmp(sp->type, "")) { - strcat(buf, sp->type); + if (strcmp(sp->class, "")) { + strcat(buf, sp->class); strcat(buf, "."); } if (strcmp(sp->ident, "")) { strcat(buf, sp->ident); strcat(buf, "."); } - strcat(buf, sp->nm); + strcat(buf, sp->name); strcat(buf, " - "); strcat(buf, sp->desc); pt->name = strdup(buf); @@ -108,9 +100,8 @@ } static void -prep_pts(const struct VSL_data *vd, const char *fields) +prep_pts(const struct VSL_data *vd) { - struct curses_priv cp; struct pt *pt, *pt2; VTAILQ_FOREACH_SAFE(pt, &pthead, next, pt2) { @@ -118,10 +109,8 @@ free(pt->name); free(pt); } - cp.fields = fields; - (void)VSL_IterStat(vd, do_curses_cb, &cp); - + (void)VSL_IterStat(vd, do_curses_cb, NULL); } static void @@ -135,7 +124,7 @@ void do_curses(struct VSL_data *vd, const struct varnish_stats *VSL_stats, - int delay, const char *fields) + int delay) { intmax_t ju; struct timeval tv; @@ -158,7 +147,7 @@ /* * Initialization goes in outher loop */ - prep_pts(vd, fields); + prep_pts(vd); AC(erase()); AC(refresh()); Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-05 22:41:54 UTC (rev 4911) @@ -612,9 +612,9 @@ const char *p = sp->target; int i; - if (strcmp(pt->type, "")) { - i = strlen(pt->type); - if (memcmp(pt->type, p, i)) + if (strcmp(pt->class, "")) { + i = strlen(pt->class); + if (memcmp(pt->class, p, i)) return (0); p += i; if (*p != '.') @@ -630,7 +630,7 @@ return (0); p++; } - if (strcmp(pt->nm, p)) + if (strcmp(pt->name, p)) return (0); assert(!strcmp(pt->fmt, "uint64_t")); Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-05 22:41:54 UTC (rev 4911) @@ -75,9 +75,9 @@ for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var))) struct vsl_statpt { - const char *type; /* stat struct type */ + const char *class; /* stat struct type */ const char *ident; /* stat struct ident */ - const char *nm; /* field name */ + const char *name; /* field name */ const char *fmt; /* field format ("uint64_t") */ int flag; /* 'a' = counter, 'i' = gauge */ const char *desc; /* description */ Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-05 22:41:54 UTC (rev 4911) @@ -10,6 +10,7 @@ vsl.h \ \ ../libvarnish/assert.c \ + ../libvarnish/argv.c \ ../libvarnish/svn_version.c \ ../libvarnish/version.c \ ../libvarnish/vin.c \ Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-05 22:41:54 UTC (rev 4911) @@ -47,6 +47,7 @@ #include "shmlog.h" #include "vre.h" #include "vbm.h" +#include "vqueue.h" #include "miniobj.h" #include "varnishapi.h" @@ -81,6 +82,8 @@ vd->rbuf = malloc(vd->rbuflen); assert(vd->rbuf != NULL); + VTAILQ_INIT(&vd->sf_list); + return (vd); } @@ -89,6 +92,7 @@ void VSL_Delete(struct VSL_data *vd) { + struct vsl_sf *sf; VSL_Close(vd); vbit_destroy(vd->vbm_client); @@ -98,6 +102,16 @@ free(vd->n_opt); free(vd->rbuf); free(vd->fname); + + while(!VTAILQ_EMPTY(&vd->sf_list)) { + sf = VTAILQ_FIRST(&vd->sf_list); + VTAILQ_REMOVE(&vd->sf_list, sf, next); + free(sf->class); + free(sf->ident); + free(sf->name); + free(sf); + } + free(vd); } Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-05 22:41:54 UTC (rev 4911) @@ -33,6 +33,20 @@ #define SLEEP_USEC (50*1000) #define TIMEOUT_USEC (5*1000*1000) +struct vsl_sf { + unsigned magic; +#define VSL_SF_MAGIC 0x558478dd + VTAILQ_ENTRY(vsl_sf) next; + int flags; +#define VSL_SF_EXCL (1 << 0) +#define VSL_SF_CL_WC (1 << 1) +#define VSL_SF_ID_WC (1 << 2) +#define VSL_SF_NM_WC (1 << 3) + char *class; + char *ident; + char *name; +}; + struct VSL_data { unsigned magic; #define VSL_MAGIC 0x6e3bd69b @@ -45,6 +59,13 @@ void *vsl_end; unsigned alloc_seq; + /* Stuff relating the stats fields start here */ + + int sf_init; + VTAILQ_HEAD(, vsl_sf) sf_list; + + /* Stuff relating the log records below here */ + unsigned char *log_start; unsigned char *log_end; unsigned char *log_ptr; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-05 22:41:54 UTC (rev 4911) @@ -44,9 +44,11 @@ #include #include "vas.h" +#include "argv.h" #include "shmlog.h" #include "vre.h" #include "vbm.h" +#include "vqueue.h" #include "miniobj.h" #include "varnishapi.h" @@ -242,12 +244,93 @@ /*--------------------------------------------------------------------*/ +static int +vsl_sf_arg(struct VSL_data *vd, const char *opt) +{ + struct vsl_sf *sf; + char **av, *q, *p; + int i; + + CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + + if (VTAILQ_EMPTY(&vd->sf_list)) { + if (*opt == '^') + vd->sf_init = 1; + } + + av = ParseArgv(opt, ARGV_COMMA); + AN(av); + if (av[0] != NULL) { + fprintf(stderr, "Parse error: %s", av[0]); + exit (1); + } + for (i = 1; av[i] != NULL; i++) { + ALLOC_OBJ(sf, VSL_SF_MAGIC); + AN(sf); + VTAILQ_INSERT_TAIL(&vd->sf_list, sf, next); + + p = av[i]; + if (*p == '^') { + sf->flags |= VSL_SF_EXCL; + p++; + } + + q = strchr(p, '.'); + if (q != NULL) { + *q++ = '\0'; + if (*p != '\0') + REPLACE(sf->class, p); + p = q; + if (*p != '\0') { + q = strchr(p, '.'); + if (q != NULL) { + *q++ = '\0'; + if (*p != '\0') + REPLACE(sf->ident, p); + p = q; + } + } + } + if (*p != '\0') { + REPLACE(sf->name, p); + } + + /* Check for wildcards */ + if (sf->class != NULL) { + q = strchr(sf->class, '*'); + if (q != NULL && q[1] == '\0') { + *q = '\0'; + sf->flags |= VSL_SF_CL_WC; + } + } + if (sf->ident != NULL) { + q = strchr(sf->ident, '*'); + if (q != NULL && q[1] == '\0') { + *q = '\0'; + sf->flags |= VSL_SF_ID_WC; + } + } + if (sf->name != NULL) { + q = strchr(sf->name, '*'); + if (q != NULL && q[1] == '\0') { + *q = '\0'; + sf->flags |= VSL_SF_NM_WC; + } + } + } + FreeArgv(av); + return (1); +} + +/*--------------------------------------------------------------------*/ + int VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt) { CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); switch (arg) { + case 'f': return (vsl_sf_arg(vd, opt)); case 'n': return (vsl_n_arg(vd, opt)); default: return (0); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-05 22:41:54 UTC (rev 4911) @@ -44,6 +44,7 @@ #include "shmlog.h" #include "vre.h" #include "vbm.h" +#include "vqueue.h" #include "miniobj.h" #include "varnishapi.h" Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 20:50:01 UTC (rev 4910) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-05 22:41:54 UTC (rev 4911) @@ -39,6 +39,7 @@ #include "vas.h" #include "shmlog.h" #include "vre.h" +#include "vqueue.h" #include "miniobj.h" #include "varnishapi.h" @@ -52,6 +53,7 @@ struct shmalloc *sha; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + if (VSL_Open(vd)) return (NULL); sha = vsl_find_alloc(vd, VSL_CLASS_STAT, "", ""); @@ -63,22 +65,63 @@ * -1 -> unknown stats encountered. */ +static inline int +iter_test(const char *s1, const char *s2, int wc) +{ + + if (s1 == NULL) + return (0); + if (!wc) + return (strcmp(s1, s2)); + for (; *s1 != '\0' && *s1 == *s2; s1++, s2++) + continue; + return (*s1 != '\0'); +} + static int -iter_main(struct shmalloc *sha, vsl_stat_f *func, void *priv) +iter_call(const struct VSL_data *vd, vsl_stat_f *func, void *priv, + const struct vsl_statpt *const sp) { + struct vsl_sf *sf; + int good = vd->sf_init; + + if (VTAILQ_EMPTY(&vd->sf_list)) + return (func(priv, sp)); + + VTAILQ_FOREACH(sf, &vd->sf_list, next) { + if (iter_test(sf->class, sp->class, sf->flags & VSL_SF_CL_WC)) + continue; + if (iter_test(sf->ident, sp->ident, sf->flags & VSL_SF_ID_WC)) + continue; + if (iter_test(sf->name, sp->name, sf->flags & VSL_SF_NM_WC)) + continue; + if (sf->flags & VSL_SF_EXCL) + good = 0; + else + good = 1; + } + if (!good) + return (0); + return (func(priv, sp)); +} + +static int +iter_main(const struct VSL_data *vd, struct shmalloc *sha, vsl_stat_f *func, + void *priv) +{ struct varnish_stats *st = SHA_PTR(sha); struct vsl_statpt sp; int i; - sp.type = ""; + sp.class = ""; sp.ident = ""; #define MAC_STAT(nn, tt, ll, ff, dd) \ - sp.nm = #nn; \ + sp.name = #nn; \ sp.fmt = #tt; \ sp.flag = ff; \ sp.desc = dd; \ sp.ptr = &st->nn; \ - i = func(priv, &sp); \ + i = iter_call(vd, func, priv, &sp); \ if (i) \ return(i); #include "stat_field.h" @@ -87,21 +130,22 @@ } static int -iter_sma(struct shmalloc *sha, vsl_stat_f *func, void *priv) +iter_sma(const struct VSL_data *vd, struct shmalloc *sha, vsl_stat_f *func, + void *priv) { struct varnish_stats_sma *st = SHA_PTR(sha); struct vsl_statpt sp; int i; - sp.type = VSL_TYPE_STAT_SMA; + sp.class = VSL_TYPE_STAT_SMA; sp.ident = sha->ident; #define MAC_STAT_SMA(nn, tt, ll, ff, dd) \ - sp.nm = #nn; \ + sp.name = #nn; \ sp.fmt = #tt; \ sp.flag = ff; \ sp.desc = dd; \ sp.ptr = &st->nn; \ - i = func(priv, &sp); \ + i = iter_call(vd, func, priv, &sp); \ if (i) \ return(i); #include "stat_field.h" @@ -121,9 +165,9 @@ if (strcmp(sha->class, VSL_CLASS_STAT)) continue; if (!strcmp(sha->type, VSL_TYPE_STAT)) - i = iter_main(sha, func, priv); + i = iter_main(vd, sha, func, priv); else if (!strcmp(sha->type, VSL_TYPE_STAT_SMA)) - i = iter_sma(sha, func, priv); + i = iter_sma(vd, sha, func, priv); else i = -1; if (i != 0) From phk at varnish-cache.org Sun Jun 6 09:40:49 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sun, 6 Jun 2010 11:40:49 +0200 Subject: r4912 - trunk/varnish-cache/include Message-ID: Author: phk Date: 2010-06-06 11:40:49 +0200 (Sun, 06 Jun 2010) New Revision: 4912 Modified: trunk/varnish-cache/include/vmb.h Log: Revisit the memory barriers, and try to catch some common platforms with inline assembler. I cannot possibly express the magnitude of this particular POSIX FAIL! Modified: trunk/varnish-cache/include/vmb.h =================================================================== --- trunk/varnish-cache/include/vmb.h 2010-06-05 22:41:54 UTC (rev 4911) +++ trunk/varnish-cache/include/vmb.h 2010-06-06 09:40:49 UTC (rev 4912) @@ -29,6 +29,10 @@ * * Memory barriers * + * XXX: It is utterly braindamaged, that no standard facility for this + * XXX: is available. The "just use pthreads locking" excuse does not + * XXX: make sense, and does not apply to two unthreaded programs sharing + * XXX: a memory segment. */ #ifndef VMB_H_INCLUDED @@ -37,15 +41,43 @@ void vmb_pthread(void); #if defined(__FreeBSD__) + #include #include -#define VMB() mb() -#define VWMB() wmb() -#define VRMB() rmb() +#define VMB() mb() +#define VWMB() wmb() +#define VRMB() rmb() + +#elif defined(__amd64__) && defined(__GNUC__) + +#define VMB() __asm __volatile("mfence;" : : : "memory") +#define VWMB() __asm __volatile("sfence;" : : : "memory") +#define VRMB() __asm __volatile("lfence;" : : : "memory") + +#elif defined(__arm__) + +#define VMB() +#define VWMB() +#define VRMB() + +#elif defined(__i386__) && defined(__GNUC__) + +#define VMB() __asm __volatile("lock; addl $0,(%%esp)" : : : "memory") +#define VWMB() __asm __volatile("lock; addl $0,(%%esp)" : : : "memory") +#define VRMB() __asm __volatile("lock; addl $0,(%%esp)" : : : "memory") + +#elif defined(__sparc64__) && defined(__GNUC__) + +#define VMB() __asm__ __volatile__ ("membar #MemIssue": : :"memory") +#define VWMB() VMB() +#define VRMB() VMB() + #else -#define VMB() vmb_pthread() -#define VWMB() vmb_pthread() -#define VRMB() vmb_pthread() + +#define VMB() vmb_pthread() +#define VWMB() vmb_pthread() +#define VRMB() vmb_pthread() + #endif #endif /* VMB_H_INCLUDED */ From phk at varnish-cache.org Sun Jun 6 12:39:15 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sun, 6 Jun 2010 14:39:15 +0200 Subject: r4913 - in trunk/varnish-cache: bin/varnishd bin/varnishlog bin/varnishtop include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-06 14:39:15 +0200 (Sun, 06 Jun 2010) New Revision: 4913 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/bin/varnishtop/varnishtop.c trunk/varnish-cache/include/shmlog.h trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl.h trunk/varnish-cache/lib/libvarnishapi/vsl_log.c Log: First part of shmlog rewrite: Handle shmlog in 32bit byte aligned words, that saves wear and tear on cpu write combining and makes things a bit faster. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/bin/varnishd/cache.h 2010-06-06 12:39:15 UTC (rev 4913) @@ -225,7 +225,7 @@ struct VCL_conf *vcl; - unsigned char *wlb, *wlp, *wle; + uint32_t *wlb, *wlp, *wle; unsigned wlr; struct SHA256Context *sha256ctx; Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2010-06-06 12:39:15 UTC (rev 4913) @@ -121,7 +121,7 @@ unsigned nhttp, unsigned http_space, unsigned siov) { struct worker *w, ww; - unsigned char wlog[shm_workspace]; + uint32_t wlog[shm_workspace / 4]; unsigned char ws[sess_workspace]; unsigned char http0[http_space]; unsigned char http1[http_space]; @@ -136,7 +136,7 @@ w->magic = WORKER_MAGIC; w->lastused = NAN; w->wlb = w->wlp = wlog; - w->wle = wlog + sizeof wlog; + w->wle = wlog + (sizeof wlog) / 4; w->sha256ctx = &sha256; w->http[0] = HTTP_create(http0, nhttp); w->http[1] = HTTP_create(http1, nhttp); @@ -557,7 +557,7 @@ struct bgthread *bt; struct worker ww; struct sess *sp; - unsigned char logbuf[1024]; /* XXX: size ? */ + uint32_t logbuf[1024]; /* XXX: size ? */ CAST_OBJ_NOTNULL(bt, arg, BGTHREAD_MAGIC); THR_SetName(bt->name); @@ -567,7 +567,7 @@ sp->wrk = &ww; ww.magic = WORKER_MAGIC; ww.wlp = ww.wlb = logbuf; - ww.wle = logbuf + sizeof logbuf; + ww.wle = logbuf + (sizeof logbuf) / 4; (void)bt->func(sp, bt->priv); Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-06 12:39:15 UTC (rev 4913) @@ -38,9 +38,18 @@ #include "shmlog.h" #include "cache.h" +#include "vmb.h" static pthread_mutex_t vsl_mtx; +static inline uint32_t +vsl_w0(uint32_t type, uint32_t length) +{ + + assert(length < 0x10000); + return (((type & 0xff) << 24) | length); +} + #define LOCKSHM(foo) \ do { \ if (pthread_mutex_trylock(foo)) { \ @@ -56,47 +65,58 @@ { assert(vsl_log_nxt < vsl_log_end); - vsl_log_start[1] = SLT_ENDMARKER; - MEMORY_BARRIER(); - *vsl_log_nxt = SLT_WRAPMARKER; - MEMORY_BARRIER(); - vsl_log_start[0]++; + assert(((uintptr_t)vsl_log_nxt & 0x3) == 0); + + vsl_log_start[1] = vsl_w0(SLT_ENDMARKER, 0); + do + vsl_log_start[0]++; + while (vsl_log_start[0] == 0); + VWMB(); + *vsl_log_nxt = vsl_w0(SLT_WRAPMARKER, 0); vsl_log_nxt = vsl_log_start + 1; VSL_stats->shm_cycles++; } -static void -vsl_hdr(enum shmlogtag tag, unsigned char *p, unsigned len, unsigned id) +/*--------------------------------------------------------------------*/ + +static inline void +vsl_hdr(enum shmlogtag tag, uint32_t *p, unsigned len, unsigned id) { - assert(vsl_log_nxt + SHMLOG_NEXTTAG + len < vsl_log_end); - assert(len < 0x10000); - p[__SHMLOG_LEN_HIGH] = (len >> 8) & 0xff; - p[__SHMLOG_LEN_LOW] = len & 0xff; - p[__SHMLOG_ID_HIGH] = (id >> 24) & 0xff; - p[__SHMLOG_ID_MEDHIGH] = (id >> 16) & 0xff; - p[__SHMLOG_ID_MEDLOW] = (id >> 8) & 0xff; - p[__SHMLOG_ID_LOW] = id & 0xff; - p[SHMLOG_DATA + len] = '\0'; - MEMORY_BARRIER(); - p[SHMLOG_TAG] = tag; + assert(((uintptr_t)p & 0x3) == 0); + + p[1] = id; + VMB(); + p[0] = vsl_w0(tag, len); } -static uint8_t * +/*-------------------------------------------------------------------- + * Reserve bytes for a record, wrap if necessary + */ + +static uint32_t * vsl_get(unsigned len) { - uint8_t *p; + uint32_t *p; + uint32_t u; assert(vsl_log_nxt < vsl_log_end); + assert(((uintptr_t)vsl_log_nxt & 0x3) == 0); + u = VSL_WORDS(len); + /* Wrap if necessary */ - if (vsl_log_nxt + SHMLOG_NEXTTAG + len + 1 >= vsl_log_end) /* XXX: + 1 ?? */ + if (VSL_NEXT(vsl_log_nxt, len) >= vsl_log_end) vsl_wrap(); + p = vsl_log_nxt; + vsl_log_nxt = VSL_NEXT(vsl_log_nxt, len); - vsl_log_nxt += SHMLOG_NEXTTAG + len; assert(vsl_log_nxt < vsl_log_end); - *vsl_log_nxt = SLT_ENDMARKER; + assert(((uintptr_t)vsl_log_nxt & 0x3) == 0); + + *vsl_log_nxt = vsl_w0(SLT_ENDMARKER, 0); + printf("GET %p -> %p\n", p, vsl_log_nxt); return (p); } @@ -106,30 +126,26 @@ */ static void -VSLR(enum shmlogtag tag, int id, txt t) +VSLR(enum shmlogtag tag, int id, const char *b, unsigned len) { - unsigned char *p; - unsigned l, mlen; + uint32_t *p; + unsigned mlen; - Tcheck(t); mlen = params->shm_reclen; /* Truncate */ - l = Tlen(t); - if (l > mlen) { - l = mlen; - t.e = t.b + l; - } + if (len > mlen) + len = mlen; /* Only hold the lock while we find our space */ LOCKSHM(&vsl_mtx); VSL_stats->shm_writes++; VSL_stats->shm_records++; - p = vsl_get(l); + p = vsl_get(len); UNLOCKSHM(&vsl_mtx); - memcpy(p + SHMLOG_DATA, t.b, l); - vsl_hdr(tag, p, l, id); + memcpy(p + 2, b, len); + vsl_hdr(tag, p, len, id); } /*--------------------------------------------------------------------*/ @@ -138,9 +154,8 @@ VSL(enum shmlogtag tag, int id, const char *fmt, ...) { va_list ap; - unsigned char *p; - unsigned n, mlen; - txt t; + unsigned n, mlen = params->shm_reclen; + char buf[mlen]; /* * XXX: consider formatting into a stack buffer then move into @@ -148,35 +163,14 @@ */ AN(fmt); va_start(ap, fmt); - mlen = params->shm_reclen; if (strchr(fmt, '%') == NULL) { - t.b = TRUST_ME(fmt); - t.e = strchr(t.b, '\0'); - VSLR(tag, id, t); + VSLR(tag, id, fmt, strlen(fmt)); } else { - LOCKSHM(&vsl_mtx); - VSL_stats->shm_writes++; - VSL_stats->shm_records++; - assert(vsl_log_nxt < vsl_log_end); - - /* Wrap if we cannot fit a full size record */ - if (vsl_log_nxt + SHMLOG_NEXTTAG + mlen + 1 >= vsl_log_end) - vsl_wrap(); - - p = vsl_log_nxt; - /* +1 for the NUL */ - n = vsnprintf((char *)(p + SHMLOG_DATA), mlen + 1L, fmt, ap); + n = vsnprintf(buf, mlen, fmt, ap); if (n > mlen) - n = mlen; /* we truncate long fields */ - - vsl_log_nxt += SHMLOG_NEXTTAG + n; - assert(vsl_log_nxt < vsl_log_end); - *vsl_log_nxt = SLT_ENDMARKER; - - UNLOCKSHM(&vsl_mtx); - - vsl_hdr(tag, p, n, id); + n = mlen; + VSLR(tag, id, buf, n); } va_end(ap); } @@ -186,21 +180,24 @@ void WSL_Flush(struct worker *w, int overflow) { - uint8_t *p; + uint32_t *p; unsigned l; l = pdiff(w->wlb, w->wlp); if (l == 0) return; + + assert(l >= 8); + LOCKSHM(&vsl_mtx); VSL_stats->shm_flushes += overflow; VSL_stats->shm_writes++; VSL_stats->shm_records += w->wlr; - p = vsl_get(l); + p = vsl_get(l - 8); UNLOCKSHM(&vsl_mtx); - memcpy(p + 1, w->wlb + 1, l - 1); - MEMORY_BARRIER(); + memcpy(p + 1, w->wlb + 1, l - 4); + VWMB(); p[0] = w->wlb[0]; w->wlp = w->wlb; w->wlr = 0; @@ -211,7 +208,6 @@ void WSLR(struct worker *w, enum shmlogtag tag, int id, txt t) { - unsigned char *p; unsigned l, mlen; Tcheck(t); @@ -227,13 +223,13 @@ assert(w->wlp < w->wle); /* Wrap if necessary */ - if (w->wlp + SHMLOG_NEXTTAG + l + 1 >= w->wle) + if (VSL_NEXT(w->wlp, l) >= w->wle) WSL_Flush(w, 1); - p = w->wlp; - w->wlp += SHMLOG_NEXTTAG + l; + assert (VSL_NEXT(w->wlp, l) < w->wle); + memcpy(VSL_DATA(w->wlp), t.b, l); + vsl_hdr(tag, w->wlp, l, id); + w->wlp = VSL_NEXT(w->wlp, l); assert(w->wlp < w->wle); - memcpy(p + SHMLOG_DATA, t.b, l); - vsl_hdr(tag, p, l, id); w->wlr++; if (params->diag_bitmap & 0x10000) WSL_Flush(w, 0); @@ -245,7 +241,7 @@ WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...) { va_list ap; - unsigned char *p; + char *p; unsigned n, mlen; txt t; @@ -261,16 +257,15 @@ assert(w->wlp < w->wle); /* Wrap if we cannot fit a full size record */ - if (w->wlp + SHMLOG_NEXTTAG + mlen + 1 >= w->wle) + if (VSL_NEXT(w->wlp, mlen) >= w->wle) WSL_Flush(w, 1); - p = w->wlp; - /* +1 for the NUL */ - n = vsnprintf((char *)(p + SHMLOG_DATA), mlen + 1L, fmt, ap); + p = VSL_DATA(w->wlp); + n = vsnprintf(p, mlen, fmt, ap); if (n > mlen) n = mlen; /* we truncate long fields */ - vsl_hdr(tag, p, n, id); - w->wlp += SHMLOG_NEXTTAG + n; + vsl_hdr(tag, w->wlp, n, id); + w->wlp = VSL_NEXT(w->wlp, n); assert(w->wlp < w->wle); w->wlr++; } Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/bin/varnishd/common.h 2010-06-06 12:39:15 UTC (rev 4913) @@ -42,9 +42,9 @@ void *mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident); extern struct varnish_stats *VSL_stats; extern struct shmloghead *loghead; -extern uint8_t *vsl_log_start; -extern uint8_t *vsl_log_end; -extern uint8_t *vsl_log_nxt; +extern uint32_t *vsl_log_start; +extern uint32_t *vsl_log_end; +extern uint32_t *vsl_log_nxt; /* varnishd.c */ struct vsb; Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2010-06-06 12:39:15 UTC (rev 4913) @@ -203,7 +203,7 @@ * We declare this a volatile pointer, so that reads of parameters * become atomic, leaving the CLI thread lattitude to change the values */ -extern volatile struct params *params; +extern volatile struct params * volatile params; extern struct heritage heritage; void child_main(void); Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-06 12:39:15 UTC (rev 4913) @@ -56,9 +56,9 @@ struct varnish_stats *VSL_stats; struct shmloghead *loghead; -uint8_t *vsl_log_start; -uint8_t *vsl_log_end; -uint8_t *vsl_log_nxt; +uint32_t *vsl_log_start; +uint32_t *vsl_log_end; +uint32_t *vsl_log_nxt; static int vsl_fd = -1; @@ -264,7 +264,6 @@ vsl_n_check(i); (void)close(i); } - fprintf(stderr, "Creating new SHMFILE\n"); (void)close(i); vsl_buildnew(fn, size, fill); @@ -276,10 +275,6 @@ xxxassert(loghead != MAP_FAILED); (void)mlock((void*)loghead, size); - /* Initialize pool */ - loghead->alloc_seq = 0; /* Zero means "inconsistent" */ - VWMB(); - memset(&loghead->head, 0, sizeof loghead->head); loghead->head.magic = SHMALLOC_MAGIC; loghead->head.len = @@ -298,15 +293,16 @@ vsl_log_start = mgt_SHM_Alloc(s1, VSL_CLASS_LOG, "", ""); AN(vsl_log_start); - vsl_log_end = vsl_log_start + s1; + vsl_log_end = (void*)((uint8_t *)vsl_log_start + s1); vsl_log_nxt = vsl_log_start + 1; - *vsl_log_nxt = SLT_ENDMARKER; - VWMB(); + *vsl_log_nxt = (SLT_ENDMARKER << 24); do - *vsl_log_start = random(); + *vsl_log_start = random() & 0xffff; while (*vsl_log_start == 0); + VWMB(); + do loghead->alloc_seq = random(); while (loghead->alloc_seq == 0); Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-06 12:39:15 UTC (rev 4913) @@ -78,7 +78,7 @@ #endif struct heritage heritage; -volatile struct params *params; +volatile struct params * volatile params; unsigned d_flag = 0; pid_t mgt_pid; struct vev_base *mgt_evb; Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-06 12:39:15 UTC (rev 4913) @@ -271,7 +271,7 @@ do_write(struct VSL_data *vd, const char *w_arg, int a_flag) { int fd, i, l; - unsigned char *p; + uint32_t *p; fd = open_log(w_arg, a_flag); signal(SIGHUP, sighup); @@ -280,8 +280,8 @@ if (i < 0) break; if (i > 0) { - l = SHMLOG_LEN(p); - i = write(fd, p, SHMLOG_NEXTTAG + l); + l = VSL_LEN(p); + i = write(fd, p, 8 + VSL_WORDS(l) * 4); if (i < 0) { perror(w_arg); exit(1); Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-06 12:39:15 UTC (rev 4913) @@ -55,8 +55,8 @@ #include "varnishapi.h" struct top { - unsigned char rec[4]; - unsigned char *rec_data; + uint8_t tag; + char *rec_data; unsigned clen; unsigned hash; VTAILQ_ENTRY(top) list; @@ -76,33 +76,36 @@ static unsigned maxfieldlen = 0; static void -accumulate(const unsigned char *p) +accumulate(uint32_t *p) { struct top *tp, *tp2; - const unsigned char *q; + const char *q; unsigned int u, l; + uint8_t t; int i; - // fprintf(stderr, "%*.*s\n", p[1], p[1], p + 4); + // fprintf(stderr, "%p %08x %08x\n", p, p[0], p[1]); u = 0; - q = p + SHMLOG_DATA; - l = SHMLOG_LEN(p); + q = VSL_DATA(p); + l = VSL_LEN(p); + t = VSL_TAG(p); for (i = 0; i < l; i++, q++) { - if (f_flag && (*q == ':' || isspace(*q))) + if (f_flag && (*q == ':' || isspace(*q))) { + l = q - VSL_DATA(p); break; + } u += *q; } VTAILQ_FOREACH(tp, &top_head, list) { if (tp->hash != u) continue; - if (tp->rec[SHMLOG_TAG] != p[SHMLOG_TAG]) + if (tp->tag != t) continue; - if (tp->clen != q - p) + if (tp->clen != l) continue; - if (memcmp(p + SHMLOG_DATA, tp->rec_data, - q - (p + SHMLOG_DATA))) + if (memcmp(VSL_DATA(p), tp->rec_data, l)) continue; tp->count += 1.0; break; @@ -111,15 +114,16 @@ ntop++; tp = calloc(sizeof *tp, 1); assert(tp != NULL); - tp->rec_data = calloc(l, 1); + tp->rec_data = calloc(l + 1, 1); assert(tp->rec_data != NULL); tp->hash = u; tp->count = 1.0; - tp->clen = q - p; + tp->clen = l; + tp->tag = t; + memcpy(tp->rec_data, VSL_DATA(p), l); + tp->rec_data[l] = '\0'; VTAILQ_INSERT_TAIL(&top_head, tp, list); } - memcpy(tp->rec, p, SHMLOG_DATA - 1); - memcpy(tp->rec_data, p + SHMLOG_DATA, l); while (1) { tp2 = VTAILQ_PREV(tp, tophead, list); if (tp2 == NULL || tp2->count >= tp->count) @@ -156,12 +160,12 @@ mvprintw(0, 0, "list length %u", ntop); VTAILQ_FOREACH_SAFE(tp, &top_head, list, tp2) { if (++l < LINES) { - len = SHMLOG_LEN(tp->rec); + len = tp->clen; if (len > COLS - 20) len = COLS - 20; mvprintw(l, 0, "%9.2f %-*.*s %*.*s\n", tp->count, maxfieldlen, maxfieldlen, - VSL_tags[tp->rec[SHMLOG_TAG]], + VSL_tags[tp->tag], len, len, tp->rec_data); t = tp->count; } @@ -180,10 +184,10 @@ accumulate_thread(void *arg) { struct VSL_data *vd = arg; + uint32_t *p; + int i; for (;;) { - unsigned char *p; - int i; i = VSL_NextLog(vd, &p); if (i < 0) @@ -268,22 +272,20 @@ dump(void) { struct top *tp, *tp2; - int len; VTAILQ_FOREACH_SAFE(tp, &top_head, list, tp2) { if (tp->count <= 1.0) break; - len = SHMLOG_LEN(tp->rec); printf("%9.2f %s %*.*s\n", - tp->count, VSL_tags[tp->rec[SHMLOG_TAG]], - len, len, tp->rec_data); + tp->count, VSL_tags[tp->tag], + tp->clen, tp->clen, tp->rec_data); } } static void do_once(struct VSL_data *vd) { - unsigned char *p; + uint32_t *p; while (VSL_NextLog(vd, &p) > 0) accumulate(p); Modified: trunk/varnish-cache/include/shmlog.h =================================================================== --- trunk/varnish-cache/include/shmlog.h 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/include/shmlog.h 2010-06-06 12:39:15 UTC (rev 4913) @@ -60,7 +60,7 @@ #define SHA_PTR(sha) ((void*)((uintptr_t)((sha) + 1))) struct shmloghead { -#define SHMLOGHEAD_MAGIC 4185512501U /* From /dev/random */ +#define SHMLOGHEAD_MAGIC 4185512502U /* From /dev/random */ unsigned magic; unsigned hdrsize; @@ -83,31 +83,26 @@ #define VSL_CLASS_STAT "Stat" /* - * Record format is as follows: + * Shared memory log format * - * 1 byte field type (enum shmlogtag) - * 2 bytes length of contents - * 4 bytes record identifier - * n bytes field contents (isgraph(c) || isspace(c)) allowed. + * The log is structured as an array of 32bit unsigned integers. + * + * The first integer contains a non-zero serial number, which changes + * whenever writing the log starts from the front. + * + * Each logrecord consist of: + * [n] = ((type & 0xff) << 24) | (length & 0xffff) + * [n + 1] = identifier + * [n + 2] ... [m] = content */ -#define SHMLOG_TAG 0 -#define __SHMLOG_LEN_HIGH 1 -#define __SHMLOG_LEN_LOW 2 -#define __SHMLOG_ID_HIGH 3 -#define __SHMLOG_ID_MEDHIGH 4 -#define __SHMLOG_ID_MEDLOW 5 -#define __SHMLOG_ID_LOW 6 -#define SHMLOG_DATA 7 -#define SHMLOG_NEXTTAG 8 /* ... + len */ +#define VSL_WORDS(len) (((len) + 3) / 4) +#define VSL_NEXT(ptr, len) ((ptr) + 2 + VSL_WORDS(len)) +#define VSL_LEN(ptr) ((ptr)[0] & 0xffff) +#define VSL_TAG(ptr) ((ptr)[0] >> 24) +#define VSL_ID(ptr) ((ptr)[1]) +#define VSL_DATA(ptr) ((char*)((ptr)+2)) -#define SHMLOG_LEN(p) (((p)[__SHMLOG_LEN_HIGH] << 8) | (p)[__SHMLOG_LEN_LOW]) -#define SHMLOG_ID(p) ( \ - ((p)[__SHMLOG_ID_HIGH] << 24) | \ - ((p)[__SHMLOG_ID_MEDHIGH] << 16) | \ - ((p)[__SHMLOG_ID_MEDLOW] << 8) | \ - (p)[__SHMLOG_ID_LOW]) - /* * The identifiers in shmlogtag are "SLT_" + XML tag. A script may be run * on this file to extract the table rather than handcode it @@ -117,7 +112,7 @@ #define SLTM(foo) SLT_##foo, #include "shmlog_tags.h" #undef SLTM - SLT_WRAPMARKER = 255 + SLT_WRAPMARKER = 255U }; /* This function lives in both libvarnish and libvarnishapi */ Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-06 12:39:15 UTC (rev 4913) @@ -54,7 +54,7 @@ int VSL_OpenLog(struct VSL_data *vd); void VSL_NonBlocking(struct VSL_data *vd, int nb); int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv); -int VSL_NextLog(struct VSL_data *lh, unsigned char **pp); +int VSL_NextLog(struct VSL_data *lh, uint32_t **pp); int VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt); int VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt); void VSL_Close(struct VSL_data *vd); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-06 12:39:15 UTC (rev 4913) @@ -78,8 +78,8 @@ vd->r_fd = -1; /* XXX: Allocate only if -r option given ? */ - vd->rbuflen = SHMLOG_NEXTTAG + 256; - vd->rbuf = malloc(vd->rbuflen); + vd->rbuflen = 256; /* XXX ?? */ + vd->rbuf = malloc(vd->rbuflen * 4); assert(vd->rbuf != NULL); VTAILQ_INIT(&vd->sf_list); @@ -293,32 +293,6 @@ /*--------------------------------------------------------------------*/ -int -VSL_OpenLog(struct VSL_data *vd) -{ - unsigned char *p; - struct shmalloc *sha; - - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - if (VSL_Open(vd)) - return (-1); - sha = vsl_find_alloc(vd, VSL_CLASS_LOG, VSL_TYPE_STAT_SMA, ""); - assert(sha != NULL); - - vd->log_start = SHA_PTR(sha); - vd->log_end = vd->log_start + sha->len - sizeof *sha; - vd->log_ptr = vd->log_start + 1; - - if (!vd->d_opt && vd->r_fd == -1) { - for (p = vd->log_ptr; *p != SLT_ENDMARKER; ) - p += SHMLOG_LEN(p) + SHMLOG_NEXTTAG; - vd->log_ptr = p; - } - return (0); -} - -/*--------------------------------------------------------------------*/ - const char * VSL_Name(const struct VSL_data *vd) { Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-06 12:39:15 UTC (rev 4913) @@ -66,14 +66,14 @@ /* Stuff relating the log records below here */ - unsigned char *log_start; - unsigned char *log_end; - unsigned char *log_ptr; + uint32_t *log_start; + uint32_t *log_end; + uint32_t *log_ptr; /* for -r option */ int r_fd; unsigned rbuflen; - unsigned char *rbuf; + uint32_t *rbuf; unsigned L_opt; char *n_opt; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-06 09:40:49 UTC (rev 4912) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-06 12:39:15 UTC (rev 4913) @@ -50,7 +50,7 @@ #include "vsl.h" -static int vsl_nextlog(struct VSL_data *vd, unsigned char **pp); +static int vsl_nextlog(struct VSL_data *vd, uint32_t **pp); /*--------------------------------------------------------------------*/ @@ -85,59 +85,58 @@ /*--------------------------------------------------------------------*/ static int -vsl_nextlog(struct VSL_data *vd, unsigned char **pp) +vsl_nextlog(struct VSL_data *vd, uint32_t **pp) { - unsigned char *p; unsigned w, l; + uint8_t t; int i; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); if (vd->r_fd != -1) { - assert(vd->rbuflen >= SHMLOG_DATA); - i = read(vd->r_fd, vd->rbuf, SHMLOG_DATA); - if (i != SHMLOG_DATA) + assert(vd->rbuflen >= 8); + i = read(vd->r_fd, vd->rbuf, 8); + if (i != 8) return (-1); - l = SHMLOG_LEN(vd->rbuf) + SHMLOG_NEXTTAG; + l = 2 + VSL_WORDS(VSL_LEN(vd->rbuf)); if (vd->rbuflen < l) { - l += 200; - vd->rbuf = realloc(vd->rbuf, l); + l += 256; + vd->rbuf = realloc(vd->rbuf, l * 4); assert(vd->rbuf != NULL); vd->rbuflen = l; } - l = SHMLOG_LEN(vd->rbuf) + 1; - i = read(vd->r_fd, vd->rbuf + SHMLOG_DATA, l); + i = read(vd->r_fd, vd->rbuf + 2, l * 4 - 8); if (i != l) return (-1); *pp = vd->rbuf; return (1); } - - p = vd->log_ptr; for (w = 0; w < TIMEOUT_USEC;) { - if (*p == SLT_WRAPMARKER) { - p = vd->log_start + 1; + t = VSL_TAG(vd->log_ptr); + if (t == SLT_WRAPMARKER) { + vd->log_ptr = vd->log_start + 1; continue; } - if (*p == SLT_ENDMARKER) { + if (t == SLT_ENDMARKER) { + /* XXX: check log_start[0] */ if (vd->flags & F_NON_BLOCKING) return (-1); w += SLEEP_USEC; usleep(SLEEP_USEC); continue; } - l = SHMLOG_LEN(p); - vd->log_ptr = p + l + SHMLOG_NEXTTAG; - *pp = p; + *pp = vd->log_ptr; + vd->log_ptr = VSL_NEXT(vd->log_ptr, VSL_LEN(vd->log_ptr)); return (1); } - vd->log_ptr = p; + *pp = NULL; return (0); } int -VSL_NextLog(struct VSL_data *vd, unsigned char **pp) +VSL_NextLog(struct VSL_data *vd, uint32_t **pp) { - unsigned char *p, t; + uint32_t *p; + unsigned char t; unsigned u, l; int i; @@ -146,9 +145,10 @@ i = vsl_nextlog(vd, &p); if (i != 1) return (i); - u = SHMLOG_ID(p); - l = SHMLOG_LEN(p); - switch(p[SHMLOG_TAG]) { + u = VSL_ID(p); + l = VSL_LEN(p); + t = VSL_TAG(p); + switch(t) { case SLT_SessionOpen: case SLT_ReqStart: vbit_set(vd->vbm_client, u); @@ -169,7 +169,7 @@ if (--vd->keep == 0) return (-1); } - t = p[SHMLOG_TAG]; + if (vbit_test(vd->vbm_select, t)) { *pp = p; return (1); @@ -182,16 +182,16 @@ continue; if (vd->regincl != NULL) { i = VRE_exec(vd->regincl, - (char *)p + SHMLOG_DATA, - SHMLOG_LEN(p) - SHMLOG_DATA, /* Length */ + VSL_DATA(p), + VSL_LEN(p), /* Length */ 0, 0, NULL, 0); if (i == VRE_ERROR_NOMATCH) continue; } if (vd->regexcl != NULL) { i = VRE_exec(vd->regincl, - (char *)p + SHMLOG_DATA, - SHMLOG_LEN(p) - SHMLOG_DATA, /* Length */ + VSL_DATA(p), + VSL_LEN(p), /* Length */ 0, 0, NULL, 0); if (i != VRE_ERROR_NOMATCH) continue; @@ -208,22 +208,21 @@ { int i; unsigned u, l, s; - unsigned char *p; + uint32_t *p; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); while (1) { i = VSL_NextLog(vd, &p); - if (i <= 0) + if (i != 1) return (i); - u = SHMLOG_ID(p); - l = SHMLOG_LEN(p); + u = VSL_ID(p); + l = VSL_LEN(p); s = 0; if (vbit_test(vd->vbm_backend, u)) s |= VSL_S_BACKEND; if (vbit_test(vd->vbm_client, u)) s |= VSL_S_CLIENT; - if (func(priv, - p[SHMLOG_TAG], u, l, s, (char *)p + SHMLOG_DATA)) + if (func(priv, VSL_TAG(p), u, l, s, VSL_DATA(p))) return (1); } } @@ -257,3 +256,28 @@ fprintf(fo, "%5d %-12s %c %.*s\n", fd, VSL_tags[tag], type, len, ptr); return (0); } + +/*--------------------------------------------------------------------*/ + +int +VSL_OpenLog(struct VSL_data *vd) +{ + struct shmalloc *sha; + + CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + if (VSL_Open(vd)) + return (-1); + sha = vsl_find_alloc(vd, VSL_CLASS_LOG, "", ""); + assert(sha != NULL); + + vd->log_start = SHA_PTR(sha); + vd->log_end = (void*)((char *)vd->log_start + sha->len - sizeof *sha); + vd->log_ptr = vd->log_start + 1; + + if (!vd->d_opt && vd->r_fd == -1) { + while (VSL_TAG(vd->log_ptr) != SLT_ENDMARKER) + vd->log_ptr = VSL_NEXT(vd->log_ptr, VSL_LEN(vd->log_ptr)); + } + return (0); +} + From phk at varnish-cache.org Sun Jun 6 13:14:02 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sun, 6 Jun 2010 15:14:02 +0200 Subject: r4914 - in trunk/varnish-cache: bin/varnishd lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-06 15:14:02 +0200 (Sun, 06 Jun 2010) New Revision: 4914 Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/lib/libvarnishapi/vsl_log.c Log: Clean up and unify shmlog writing in the worker process. Always wrap the log on worker process startup. Detect such wraps in libvarnishapi Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-06 12:39:15 UTC (rev 4913) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-06 13:14:02 UTC (rev 4914) @@ -50,23 +50,25 @@ return (((type & 0xff) << 24) | length); } -#define LOCKSHM(foo) \ - do { \ - if (pthread_mutex_trylock(foo)) { \ - AZ(pthread_mutex_lock(foo)); \ - VSL_stats->shm_cont++; \ - } \ - } while (0); +/*--------------------------------------------------------------------*/ -#define UNLOCKSHM(foo) AZ(pthread_mutex_unlock(foo)) +static inline void +vsl_hdr(enum shmlogtag tag, uint32_t *p, unsigned len, unsigned id) +{ + assert(((uintptr_t)p & 0x3) == 0); + + p[1] = id; + VMB(); + p[0] = vsl_w0(tag, len); +} + +/*--------------------------------------------------------------------*/ + static void vsl_wrap(void) { - assert(vsl_log_nxt < vsl_log_end); - assert(((uintptr_t)vsl_log_nxt & 0x3) == 0); - vsl_log_start[1] = vsl_w0(SLT_ENDMARKER, 0); do vsl_log_start[0]++; @@ -77,46 +79,39 @@ VSL_stats->shm_cycles++; } -/*--------------------------------------------------------------------*/ - -static inline void -vsl_hdr(enum shmlogtag tag, uint32_t *p, unsigned len, unsigned id) -{ - - assert(((uintptr_t)p & 0x3) == 0); - - p[1] = id; - VMB(); - p[0] = vsl_w0(tag, len); -} - /*-------------------------------------------------------------------- * Reserve bytes for a record, wrap if necessary */ static uint32_t * -vsl_get(unsigned len) +vsl_get(unsigned len, unsigned records, unsigned flushes) { uint32_t *p; - uint32_t u; + if (pthread_mutex_trylock(&vsl_mtx)) { + AZ(pthread_mutex_lock(&vsl_mtx)); + VSL_stats->shm_cont++; + } assert(vsl_log_nxt < vsl_log_end); assert(((uintptr_t)vsl_log_nxt & 0x3) == 0); - u = VSL_WORDS(len); + VSL_stats->shm_writes++; + VSL_stats->shm_flushes += flushes; + VSL_stats->shm_records += records; /* Wrap if necessary */ - if (VSL_NEXT(vsl_log_nxt, len) >= vsl_log_end) + if (VSL_NEXT(vsl_log_nxt, len) >= vsl_log_end) vsl_wrap(); p = vsl_log_nxt; vsl_log_nxt = VSL_NEXT(vsl_log_nxt, len); + *vsl_log_nxt = vsl_w0(SLT_ENDMARKER, 0); + assert(vsl_log_nxt < vsl_log_end); assert(((uintptr_t)vsl_log_nxt & 0x3) == 0); + AZ(pthread_mutex_unlock(&vsl_mtx)); - *vsl_log_nxt = vsl_w0(SLT_ENDMARKER, 0); - printf("GET %p -> %p\n", p, vsl_log_nxt); return (p); } @@ -137,12 +132,7 @@ if (len > mlen) len = mlen; - /* Only hold the lock while we find our space */ - LOCKSHM(&vsl_mtx); - VSL_stats->shm_writes++; - VSL_stats->shm_records++; - p = vsl_get(len); - UNLOCKSHM(&vsl_mtx); + p = vsl_get(len, 1, 0); memcpy(p + 2, b, len); vsl_hdr(tag, p, len, id); @@ -189,12 +179,7 @@ assert(l >= 8); - LOCKSHM(&vsl_mtx); - VSL_stats->shm_flushes += overflow; - VSL_stats->shm_writes++; - VSL_stats->shm_records += w->wlr; - p = vsl_get(l - 8); - UNLOCKSHM(&vsl_mtx); + p = vsl_get(l - 8, w->wlr, overflow); memcpy(p + 1, w->wlb + 1, l - 4); VWMB(); @@ -281,7 +266,8 @@ { AZ(pthread_mutex_init(&vsl_mtx, NULL)); - loghead->starttime = TIM_real(); + vsl_wrap(); + loghead->starttime = (intmax_t)TIM_real(); loghead->panicstr[0] = '\0'; memset(VSL_stats, 0, sizeof *VSL_stats); loghead->child_pid = getpid(); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-06 12:39:15 UTC (rev 4913) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-06 13:14:02 UTC (rev 4914) @@ -90,6 +90,7 @@ unsigned w, l; uint8_t t; int i; + uint32_t seq; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); if (vd->r_fd != -1) { @@ -110,23 +111,28 @@ *pp = vd->rbuf; return (1); } + seq = vd->log_start[0]; for (w = 0; w < TIMEOUT_USEC;) { t = VSL_TAG(vd->log_ptr); - if (t == SLT_WRAPMARKER) { + + if (t != SLT_ENDMARKER) { + *pp = vd->log_ptr; + vd->log_ptr = VSL_NEXT(vd->log_ptr, VSL_LEN(vd->log_ptr)); + return (1); + } + + if (t == SLT_WRAPMARKER || vd->log_start[0] != seq) { vd->log_ptr = vd->log_start + 1; + seq = vd->log_start[0]; continue; } - if (t == SLT_ENDMARKER) { - /* XXX: check log_start[0] */ - if (vd->flags & F_NON_BLOCKING) - return (-1); - w += SLEEP_USEC; - usleep(SLEEP_USEC); - continue; - } - *pp = vd->log_ptr; - vd->log_ptr = VSL_NEXT(vd->log_ptr, VSL_LEN(vd->log_ptr)); - return (1); + + + /* XXX: check log_start[0] */ + if (vd->flags & F_NON_BLOCKING) + return (-1); + w += SLEEP_USEC; + usleep(SLEEP_USEC); } *pp = NULL; return (0); From phk at varnish-cache.org Sun Jun 6 13:39:58 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sun, 6 Jun 2010 15:39:58 +0200 Subject: r4915 - trunk/varnish-cache/bin/varnishtop Message-ID: Author: phk Date: 2010-06-06 15:39:58 +0200 (Sun, 06 Jun 2010) New Revision: 4915 Added: trunk/varnish-cache/bin/varnishtop/flint.lnt trunk/varnish-cache/bin/varnishtop/flint.sh Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c Log: FlexeLint cleanup Added: trunk/varnish-cache/bin/varnishtop/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishtop/flint.lnt (rev 0) +++ trunk/varnish-cache/bin/varnishtop/flint.lnt 2010-06-06 13:39:58 UTC (rev 4915) @@ -0,0 +1,21 @@ + +-e712 // 14 Info 712 Loss of precision (___) (___ to ___) +-e747 // 16 Info 747 Significant prototype coercion (___) ___ to ___ + +-e763 // Redundant declaration for symbol '...' previously declared +-e716 // while(1) ... + +-e457 // unprotected write access +-e459 // unprotected access +-e458 // unprotected access + +-e732 // Loss of sign (arg. no. 2) (int to unsigned +-e737 // [45] Loss of sign in promotion from int to unsigned +-e713 // Loss of precision (assignment) (unsigned long long to long long) +-e574 // Signed-unsigned mix with relational + +/////////////////////////////////////////////////////////////////////// +// Varnishstat specific + +/// -e850 // for loop index variable '___' whose type category is '___' is modified in body of the for loop that began at '___' + Added: trunk/varnish-cache/bin/varnishtop/flint.sh =================================================================== --- trunk/varnish-cache/bin/varnishtop/flint.sh (rev 0) +++ trunk/varnish-cache/bin/varnishtop/flint.sh 2010-06-06 13:39:58 UTC (rev 4915) @@ -0,0 +1,11 @@ +#!/bin/sh + +flexelint \ + -I/usr/include \ + -I. \ + -I../../include \ + -I../.. \ + ../flint.lnt \ + flint.lnt \ + *.c \ + ../../lib/libvarnishapi/*.c Property changes on: trunk/varnish-cache/bin/varnishtop/flint.sh ___________________________________________________________________ Added: svn:executable + * Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-06 13:14:02 UTC (rev 4914) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-06 13:39:58 UTC (rev 4915) @@ -54,10 +54,12 @@ #include "shmlog.h" #include "varnishapi.h" +#define AC(x) assert((x) != ERR) + struct top { uint8_t tag; char *rec_data; - unsigned clen; + int clen; unsigned hash; VTAILQ_ENTRY(top) list; double count; @@ -76,7 +78,7 @@ static unsigned maxfieldlen = 0; static void -accumulate(uint32_t *p) +accumulate(uint32_t * const p) { struct top *tp, *tp2; const char *q; @@ -141,12 +143,12 @@ } static void -update(struct VSL_data *vd) +update(const struct VSL_data *vd) { struct top *tp, *tp2; int l, len; double t = 0; - static time_t last; + static time_t last = 0; time_t now; now = time(NULL); @@ -154,19 +156,19 @@ return; last = now; - erase(); l = 1; - mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd)); - mvprintw(0, 0, "list length %u", ntop); + AC(erase()); + AC(mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd))); + AC(mvprintw(0, 0, "list length %u", ntop)); VTAILQ_FOREACH_SAFE(tp, &top_head, list, tp2) { if (++l < LINES) { len = tp->clen; if (len > COLS - 20) len = COLS - 20; - mvprintw(l, 0, "%9.2f %-*.*s %*.*s\n", + AC(mvprintw(l, 0, "%9.2f %-*.*s %*.*s\n", tp->count, maxfieldlen, maxfieldlen, VSL_tags[tp->tag], - len, len, tp->rec_data); + len, len, tp->rec_data)); t = tp->count; } tp->count *= .999; @@ -177,7 +179,7 @@ ntop--; } } - refresh(); + AC(refresh()); } static void * @@ -193,13 +195,13 @@ if (i < 0) break; if (i == 0) { - usleep(50000); + AZ(usleep(50000)); continue; } - pthread_mutex_lock(&mtx); + AZ(pthread_mutex_lock(&mtx)); accumulate(p); - pthread_mutex_unlock(&mtx); + AZ(pthread_mutex_unlock(&mtx)); } return (arg); } @@ -208,7 +210,6 @@ do_curses(struct VSL_data *vd) { pthread_t thr; - int ch; int i; for (i = 0; i < 256; i++) { @@ -223,46 +224,46 @@ exit(1); } - initscr(); - raw(); - noecho(); - nonl(); - intrflush(stdscr, FALSE); - curs_set(0); - erase(); + (void)initscr(); + AC(raw()); + AC(noecho()); + AC(nonl()); + AC(intrflush(stdscr, FALSE)); + AC(curs_set(0)); + AC(erase()); for (;;) { - pthread_mutex_lock(&mtx); + AZ(pthread_mutex_lock(&mtx)); update(vd); - pthread_mutex_unlock(&mtx); + AZ(pthread_mutex_unlock(&mtx)); timeout(1000); - switch ((ch = getch())) { + switch (getch()) { case ERR: break; #ifdef KEY_RESIZE case KEY_RESIZE: - erase(); + AC(erase()); break; #endif case '\014': /* Ctrl-L */ case '\024': /* Ctrl-T */ - redrawwin(stdscr); - refresh(); + AC(redrawwin(stdscr)); + AC(refresh()); break; case '\003': /* Ctrl-C */ - raise(SIGINT); + AZ(raise(SIGINT)); break; case '\032': /* Ctrl-Z */ - endwin(); - raise(SIGTSTP); + AC(endwin()); + AZ(raise(SIGTSTP)); break; case '\021': /* Ctrl-Q */ case 'Q': case 'q': - endwin(); + AC(endwin()); return; default: - beep(); + AC(beep()); break; } } @@ -311,7 +312,7 @@ while ((o = getopt(argc, argv, VSL_LOG_ARGS "1fV")) != -1) { switch (o) { case '1': - VSL_Log_Arg(vd, 'd', NULL); + AN(VSL_Log_Arg(vd, 'd', NULL)); once = 1; break; case 'f': From phk at varnish-cache.org Sun Jun 6 13:54:02 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sun, 6 Jun 2010 15:54:02 +0200 Subject: r4916 - in trunk/varnish-cache/bin: . varnishlog Message-ID: Author: phk Date: 2010-06-06 15:54:01 +0200 (Sun, 06 Jun 2010) New Revision: 4916 Added: trunk/varnish-cache/bin/varnishlog/flint.lnt trunk/varnish-cache/bin/varnishlog/flint.sh Modified: trunk/varnish-cache/bin/flint.lnt trunk/varnish-cache/bin/varnishlog/varnishlog.c Log: FlexeLint cleanup Modified: trunk/varnish-cache/bin/flint.lnt =================================================================== --- trunk/varnish-cache/bin/flint.lnt 2010-06-06 13:39:58 UTC (rev 4915) +++ trunk/varnish-cache/bin/flint.lnt 2010-06-06 13:54:01 UTC (rev 4916) @@ -20,6 +20,8 @@ -emacro(506, assert) // constant value boolean -emacro(827, assert) // loop not reachable -emacro(774, assert) // booelan always true +-emacro(731, assert) // booelan arg to eq/non-eq +-emacro(731, xxxassert) // arg to eq/non-eq -emacro(527, WRONG) // unreachable code /////////////////////////////////////////////////////////////////////// Added: trunk/varnish-cache/bin/varnishlog/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishlog/flint.lnt (rev 0) +++ trunk/varnish-cache/bin/varnishlog/flint.lnt 2010-06-06 13:54:01 UTC (rev 4916) @@ -0,0 +1,18 @@ + +-e712 // 14 Info 712 Loss of precision (___) (___ to ___) +-e747 // 16 Info 747 Significant prototype coercion (___) ___ to ___ + +-e763 // Redundant declaration for symbol '...' previously declared +-e716 // while(1) ... + +-e457 // unprotected write access +-e459 // unprotected access +-e458 // unprotected access + +-e732 // Loss of sign (arg. no. 2) (int to unsigned +-e737 // [45] Loss of sign in promotion from int to unsigned +-e713 // Loss of precision (assignment) (unsigned long long to long long) +-e574 // Signed-unsigned mix with relational + +-e788 // enum constant '___' not used within defaulted switch + Added: trunk/varnish-cache/bin/varnishlog/flint.sh =================================================================== --- trunk/varnish-cache/bin/varnishlog/flint.sh (rev 0) +++ trunk/varnish-cache/bin/varnishlog/flint.sh 2010-06-06 13:54:01 UTC (rev 4916) @@ -0,0 +1,11 @@ +#!/bin/sh + +flexelint \ + -I/usr/include \ + -I. \ + -I../../include \ + -I../.. \ + ../flint.lnt \ + flint.lnt \ + *.c \ + ../../lib/libvarnishapi/*.c Property changes on: trunk/varnish-cache/bin/varnishlog/flint.sh ___________________________________________________________________ Added: svn:executable + * Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-06 13:39:58 UTC (rev 4915) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-06 13:54:01 UTC (rev 4916) @@ -124,7 +124,7 @@ if (!(spec & (VSL_S_CLIENT|VSL_S_BACKEND))) { if (!b_flag && !c_flag) - VSL_H_Print(stdout, tag, fd, len, spec, ptr); + (void)VSL_H_Print(stdout, tag, fd, len, spec, ptr); return (0); } if (ob[fd] == NULL) { @@ -195,7 +195,7 @@ } static void -do_order(struct VSL_data *vd, int argc, char **argv) +do_order(struct VSL_data *vd, int argc, char * const *argv) { int i; const char *error; @@ -227,7 +227,7 @@ i = VSL_Dispatch(vd, h_order, NULL); if (i == 0) { clean_order(); - fflush(stdout); + AZ(fflush(stdout)); } else if (i < 0) break; @@ -274,7 +274,8 @@ uint32_t *p; fd = open_log(w_arg, a_flag); - signal(SIGHUP, sighup); + XXXAN(fd >= 0); + (void)signal(SIGHUP, sighup); while (1) { i = VSL_NextLog(vd, &p); if (i < 0) @@ -288,8 +289,9 @@ } } if (reopen) { - close(fd); + AZ(close(fd)); fd = open_log(w_arg, a_flag); + XXXAN(fd >= 0); reopen = 0; } } @@ -307,7 +309,7 @@ } int -main(int argc, char **argv) +main(int argc, char * const *argv) { int c; int a_flag = 0, D_flag = 0, o_flag = 0, u_flag = 0; @@ -325,11 +327,11 @@ break; case 'b': b_flag = 1; - VSL_Log_Arg(vd, c, optarg); + AN(VSL_Log_Arg(vd, c, optarg)); break; case 'c': c_flag = 1; - VSL_Log_Arg(vd, c, optarg); + AN(VSL_Log_Arg(vd, c, optarg)); break; case 'D': D_flag = 1; From phk at varnish-cache.org Mon Jun 7 07:46:27 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 7 Jun 2010 09:46:27 +0200 Subject: r4917 - in trunk/varnish-cache: bin/varnishd include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-07 09:46:27 +0200 (Mon, 07 Jun 2010) New Revision: 4917 Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/include/shmlog.h trunk/varnish-cache/lib/libvarnishapi/vsl_log.c Log: Sanitize macros Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-06 13:54:01 UTC (rev 4916) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-07 07:46:27 UTC (rev 4917) @@ -100,11 +100,11 @@ VSL_stats->shm_records += records; /* Wrap if necessary */ - if (VSL_NEXT(vsl_log_nxt, len) >= vsl_log_end) + if (VSL_END(vsl_log_nxt, len) >= vsl_log_end) vsl_wrap(); p = vsl_log_nxt; - vsl_log_nxt = VSL_NEXT(vsl_log_nxt, len); + vsl_log_nxt = VSL_END(vsl_log_nxt, len); *vsl_log_nxt = vsl_w0(SLT_ENDMARKER, 0); @@ -208,12 +208,12 @@ assert(w->wlp < w->wle); /* Wrap if necessary */ - if (VSL_NEXT(w->wlp, l) >= w->wle) + if (VSL_END(w->wlp, l) >= w->wle) WSL_Flush(w, 1); - assert (VSL_NEXT(w->wlp, l) < w->wle); + assert (VSL_END(w->wlp, l) < w->wle); memcpy(VSL_DATA(w->wlp), t.b, l); vsl_hdr(tag, w->wlp, l, id); - w->wlp = VSL_NEXT(w->wlp, l); + w->wlp = VSL_END(w->wlp, l); assert(w->wlp < w->wle); w->wlr++; if (params->diag_bitmap & 0x10000) @@ -242,7 +242,7 @@ assert(w->wlp < w->wle); /* Wrap if we cannot fit a full size record */ - if (VSL_NEXT(w->wlp, mlen) >= w->wle) + if (VSL_END(w->wlp, mlen) >= w->wle) WSL_Flush(w, 1); p = VSL_DATA(w->wlp); @@ -250,7 +250,7 @@ if (n > mlen) n = mlen; /* we truncate long fields */ vsl_hdr(tag, w->wlp, n, id); - w->wlp = VSL_NEXT(w->wlp, n); + w->wlp = VSL_END(w->wlp, n); assert(w->wlp < w->wle); w->wlr++; } Modified: trunk/varnish-cache/include/shmlog.h =================================================================== --- trunk/varnish-cache/include/shmlog.h 2010-06-06 13:54:01 UTC (rev 4916) +++ trunk/varnish-cache/include/shmlog.h 2010-06-07 07:46:27 UTC (rev 4917) @@ -97,7 +97,8 @@ */ #define VSL_WORDS(len) (((len) + 3) / 4) -#define VSL_NEXT(ptr, len) ((ptr) + 2 + VSL_WORDS(len)) +#define VSL_END(ptr, len) ((ptr) + 2 + VSL_WORDS(len)) +#define VSL_NEXT(ptr) VSL_END(ptr, VSL_LEN(ptr)) #define VSL_LEN(ptr) ((ptr)[0] & 0xffff) #define VSL_TAG(ptr) ((ptr)[0] >> 24) #define VSL_ID(ptr) ((ptr)[1]) Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-06 13:54:01 UTC (rev 4916) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-07 07:46:27 UTC (rev 4917) @@ -117,7 +117,7 @@ if (t != SLT_ENDMARKER) { *pp = vd->log_ptr; - vd->log_ptr = VSL_NEXT(vd->log_ptr, VSL_LEN(vd->log_ptr)); + vd->log_ptr = VSL_NEXT(vd->log_ptr); return (1); } @@ -282,7 +282,7 @@ if (!vd->d_opt && vd->r_fd == -1) { while (VSL_TAG(vd->log_ptr) != SLT_ENDMARKER) - vd->log_ptr = VSL_NEXT(vd->log_ptr, VSL_LEN(vd->log_ptr)); + vd->log_ptr = VSL_NEXT(vd->log_ptr); } return (0); } From phk at varnish-cache.org Mon Jun 7 07:59:53 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 7 Jun 2010 09:59:53 +0200 Subject: r4918 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvarnish lib/libvarnishapi lib/libvcl Message-ID: Author: phk Date: 2010-06-07 09:59:53 +0200 (Mon, 07 Jun 2010) New Revision: 4918 Modified: trunk/varnish-cache/bin/varnishtest/tests/b00032.vtc trunk/varnish-cache/bin/varnishtest/tests/r00693.vtc trunk/varnish-cache/bin/varnishtest/tests/r00694.vtc trunk/varnish-cache/bin/varnishtest/tests/r00700.vtc trunk/varnish-cache/bin/varnishtest/tests/r00702.vtc trunk/varnish-cache/bin/varnishtest/tests/r00704.vtc trunk/varnish-cache/lib/libvarnish/vin.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c trunk/varnish-cache/lib/libvcl/generate.py Log: Set Id expansion Property changes on: trunk/varnish-cache/bin/varnishtest/tests/b00032.vtc ___________________________________________________________________ Added: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00693.vtc ___________________________________________________________________ Added: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00694.vtc ___________________________________________________________________ Added: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00700.vtc ___________________________________________________________________ Added: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00702.vtc ___________________________________________________________________ Added: svn:keywords + Id Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00704.vtc ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/varnish-cache/lib/libvarnish/vin.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vin.c 2010-06-07 07:46:27 UTC (rev 4917) +++ trunk/varnish-cache/lib/libvarnish/vin.c 2010-06-07 07:59:53 UTC (rev 4918) @@ -31,7 +31,7 @@ #include "config.h" #include "svnid.h" -SVNID("$Id: instance.c 4093 2009-06-06 15:56:17Z des $") +SVNID("$Id$") #include #include Property changes on: trunk/varnish-cache/lib/libvarnish/vin.c ___________________________________________________________________ Added: svn:keywords + Id Property changes on: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c ___________________________________________________________________ Added: svn:keywords + Id Property changes on: trunk/varnish-cache/lib/libvcl/generate.py ___________________________________________________________________ Added: svn:keywords + Id From phk at varnish-cache.org Mon Jun 7 08:02:54 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 7 Jun 2010 10:02:54 +0200 Subject: r4919 - in trunk/varnish-cache: include lib/libvcl Message-ID: Author: phk Date: 2010-06-07 10:02:53 +0200 (Mon, 07 Jun 2010) New Revision: 4919 Modified: trunk/varnish-cache/include/vend.h trunk/varnish-cache/include/vmb.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: More Id expansion Property changes on: trunk/varnish-cache/include/vend.h ___________________________________________________________________ Added: svn:keywords + Id Property changes on: trunk/varnish-cache/include/vmb.h ___________________________________________________________________ Added: svn:keywords + Id Property changes on: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c ___________________________________________________________________ Added: svn:keywords + Id Property changes on: trunk/varnish-cache/lib/libvcl/vcc_obj.c ___________________________________________________________________ Added: svn:keywords + Id From phk at varnish-cache.org Mon Jun 7 08:12:25 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 7 Jun 2010 10:12:25 +0200 Subject: r4920 - in trunk/varnish-cache: bin/varnishd bin/varnishstat bin/varnishtest include lib/libvarnishapi lib/libvcl Message-ID: Author: phk Date: 2010-06-07 10:12:24 +0200 (Mon, 07 Jun 2010) New Revision: 4920 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/bin/varnishd/hash_critbit.c trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c trunk/varnish-cache/bin/varnishtest/vtc_log.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/include/shmlog.h trunk/varnish-cache/include/vmb.h trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl.h trunk/varnish-cache/lib/libvarnishapi/vsl_log.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c trunk/varnish-cache/lib/libvcl/generate.py trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Whitespace cleanup Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/bin/varnishd/cache.h 2010-06-07 08:12:24 UTC (rev 4920) @@ -225,7 +225,7 @@ struct VCL_conf *vcl; - uint32_t *wlb, *wlp, *wle; + uint32_t *wlb, *wlp, *wle; unsigned wlr; struct SHA256Context *sha256ctx; Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -129,7 +129,7 @@ mlen = params->shm_reclen; /* Truncate */ - if (len > mlen) + if (len > mlen) len = mlen; p = vsl_get(len, 1, 0); Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_critbit.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/bin/varnishd/hash_critbit.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -428,7 +428,7 @@ unsigned with_lock; (void)sp; - + with_lock = 0; while (1) { if (with_lock) { @@ -453,7 +453,7 @@ VSL_stats->hcb_insert++; assert(oh->refcnt > 0); return (oh); - } + } if (oh == NULL) { assert(!with_lock); Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -104,7 +104,7 @@ bprintf(sha->ident, "%s", ident); VWMB(); - if (seq != 0) + if (seq != 0) do loghead->alloc_seq = seq++; while (loghead->alloc_seq == 0); @@ -207,7 +207,7 @@ av = ParseArgv(l_arg, ARGV_COMMA); AN(av); - if (av[0] != NULL) + if (av[0] != NULL) ARGV_ERR("\t-l ...: %s", av[0]); ap = av + 1; @@ -249,7 +249,7 @@ fill = 1; } - if (*ap != NULL) + if (*ap != NULL) ARGV_ERR("\t-l ...: Too many sub-args\n"); FreeArgv(av); @@ -263,7 +263,7 @@ if (i >= 0) { vsl_n_check(i); (void)close(i); - } + } (void)close(i); vsl_buildnew(fn, size, fill); Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -337,7 +337,7 @@ (void)f_arg; if (L_arg && b_arg == NULL) { - bprintf(buf, + bprintf(buf, "backend default {\n" " .host = \"127.0.0.1\";\n" " .port = %s;\n" Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -105,7 +105,7 @@ assert(!strcmp(pt->fmt, "uint64_t")); val = *(const volatile uint64_t*)pt->ptr; i = 0; - if (strcmp(pt->class, "")) + if (strcmp(pt->class, "")) i += printf("%s.", pt->class); if (strcmp(pt->ident, "")) i += printf("%s.", pt->ident); @@ -113,7 +113,7 @@ if (i > op->pad) op->pad = i + 1; printf("%*.*s", op->pad - i, op->pad - i, ""); - if (pt->flag == 'a') + if (pt->flag == 'a') printf("%12ju %12.2f %s\n", val, val / op->up, pt->desc); else printf("%12ju %12s %s\n", val, ". ", pt->desc); @@ -141,7 +141,7 @@ (void)priv; i = 0; - if (strcmp(pt->class, "")) + if (strcmp(pt->class, "")) i += fprintf(stderr, "%s.", pt->class); if (strcmp(pt->ident, "")) i += fprintf(stderr, "%s.", pt->ident); Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -209,7 +209,7 @@ AC(mvprintw(line, 0, "%12ju %12.2f %12.2f %s\n", ju, (ju - (intmax_t)pt->ref)/lt, - ju / up, pt->name)); + ju / up, pt->name)); pt->ref = ju; } else { AC(mvprintw(line, 0, Modified: trunk/varnish-cache/bin/varnishtest/vtc_log.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_log.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/bin/varnishtest/vtc_log.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -187,7 +187,7 @@ l = 0; for(; *str != '\0'; str++) { if (++l > 512) { - vsb_printf(vl->vsb, "..."); + vsb_printf(vl->vsb, "..."); break; } if (nl) { Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -81,7 +81,7 @@ int vcl_nbr; char *workdir; - struct VSL_data *vd; + struct VSL_data *vd; }; static VTAILQ_HEAD(, varnish) varnishes = @@ -645,7 +645,7 @@ char *p; int i; struct stat_priv sp; - + good = -1; sp.target = av[0]; Modified: trunk/varnish-cache/include/shmlog.h =================================================================== --- trunk/varnish-cache/include/shmlog.h 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/include/shmlog.h 2010-06-07 08:12:24 UTC (rev 4920) @@ -91,8 +91,8 @@ * whenever writing the log starts from the front. * * Each logrecord consist of: - * [n] = ((type & 0xff) << 24) | (length & 0xffff) - * [n + 1] = identifier + * [n] = ((type & 0xff) << 24) | (length & 0xffff) + * [n + 1] = identifier * [n + 2] ... [m] = content */ Modified: trunk/varnish-cache/include/vmb.h =================================================================== --- trunk/varnish-cache/include/vmb.h 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/include/vmb.h 2010-06-07 08:12:24 UTC (rev 4920) @@ -56,9 +56,9 @@ #elif defined(__arm__) -#define VMB() -#define VWMB() -#define VRMB() +#define VMB() +#define VWMB() +#define VRMB() #elif defined(__i386__) && defined(__GNUC__) Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -104,7 +104,7 @@ free(vd->fname); while(!VTAILQ_EMPTY(&vd->sf_list)) { - sf = VTAILQ_FIRST(&vd->sf_list); + sf = VTAILQ_FIRST(&vd->sf_list); VTAILQ_REMOVE(&vd->sf_list, sf, next); free(sf->class); free(sf->ident); @@ -175,7 +175,7 @@ int VSL_Open(struct VSL_data *vd) { - + return (vsl_open(vd, 1)); } @@ -261,7 +261,7 @@ assert (vd->vsl_lh != NULL); VSL_FOREACH(sha, vd) { CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC); - if (strcmp(sha->class, class)) + if (strcmp(sha->class, class)) continue; if (type != NULL && strcmp(sha->type, type)) continue; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-07 08:12:24 UTC (rev 4920) @@ -55,7 +55,7 @@ struct stat fstat; int vsl_fd; - struct shmloghead *vsl_lh; + struct shmloghead *vsl_lh; void *vsl_end; unsigned alloc_seq; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -127,7 +127,6 @@ continue; } - /* XXX: check log_start[0] */ if (vd->flags & F_NON_BLOCKING) return (-1); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -65,7 +65,7 @@ * -1 -> unknown stats encountered. */ -static inline int +static inline int iter_test(const char *s1, const char *s2, int wc) { Modified: trunk/varnish-cache/lib/libvcl/generate.py =================================================================== --- trunk/varnish-cache/lib/libvcl/generate.py 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/lib/libvcl/generate.py 2010-06-07 08:12:24 UTC (rev 4920) @@ -381,10 +381,10 @@ 'HDR_OBJ': "const char *", 'HDR_REQ': "const char *", 'HDR_BEREQ': "const char *", - 'HOSTNAME': "const char *", - 'PORTNAME': "const char *", - 'HASH': "const char *", - 'SET': "struct vrt_backend_entry *", + 'HOSTNAME': "const char *", + 'PORTNAME': "const char *", + 'HASH': "const char *", + 'SET': "struct vrt_backend_entry *", } ####################################################################### @@ -443,9 +443,11 @@ l = len(j) while (k < l): fo.write("p[%d] == '%s'" % (k, j[k])) - fo.write(" && ") + fo.write(" &&") if (k % 3) == 0: fo.write("\n\t\t ") + else: + fo.write(" ") k += 1 fo.write("!isvar(p[%d])) {\n" % l) fo.write("\t\t\t*q = p + %d;\n" % l) Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2010-06-07 08:02:53 UTC (rev 4919) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2010-06-07 08:12:24 UTC (rev 4920) @@ -68,25 +68,25 @@ M2('>', T_SHR); M1(); case 'e': - if (p[1] == 'l' && p[2] == 's' && p[3] == 'e' && + if (p[1] == 'l' && p[2] == 's' && p[3] == 'e' && p[4] == 'i' && p[5] == 'f' && !isvar(p[6])) { *q = p + 6; return (T_ELSEIF); } - if (p[1] == 'l' && p[2] == 's' && p[3] == 'i' && + if (p[1] == 'l' && p[2] == 's' && p[3] == 'i' && p[4] == 'f' && !isvar(p[5])) { *q = p + 5; return (T_ELSIF); } - if (p[1] == 'l' && p[2] == 's' && p[3] == 'e' && + if (p[1] == 'l' && p[2] == 's' && p[3] == 'e' && !isvar(p[4])) { *q = p + 4; return (T_ELSE); } return (0); case 'i': - if (p[1] == 'n' && p[2] == 'c' && p[3] == 'l' && - p[4] == 'u' && p[5] == 'd' && p[6] == 'e' && + if (p[1] == 'n' && p[2] == 'c' && p[3] == 'l' && + p[4] == 'u' && p[5] == 'd' && p[6] == 'e' && !isvar(p[7])) { *q = p + 7; return (T_INCLUDE); From phk at varnish-cache.org Mon Jun 7 08:19:51 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 7 Jun 2010 10:19:51 +0200 Subject: r4921 - trunk/varnish-cache/bin/varnishstat Message-ID: Author: phk Date: 2010-06-07 10:19:51 +0200 (Mon, 07 Jun 2010) New Revision: 4921 Added: trunk/varnish-cache/bin/varnishstat/flint.lnt trunk/varnish-cache/bin/varnishstat/flint.sh Log: Forgot to add flexelint files for varnishstat Added: trunk/varnish-cache/bin/varnishstat/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishstat/flint.lnt (rev 0) +++ trunk/varnish-cache/bin/varnishstat/flint.lnt 2010-06-07 08:19:51 UTC (rev 4921) @@ -0,0 +1,29 @@ + ++libh mgt_event.h + +-esym(850, av) + +-e712 // 14 Info 712 Loss of precision (___) (___ to ___) +-e747 // 16 Info 747 Significant prototype coercion (___) ___ to ___ + +-e763 // Redundant declaration for symbol '...' previously declared +-e716 // while(1) ... + +-e457 // unprotected write access +-e459 // unprotected access +-e458 // unprotected access + +-e732 // Loss of sign (arg. no. 2) (int to unsigned +-e737 // [45] Loss of sign in promotion from int to unsigned +-e713 // Loss of precision (assignment) (unsigned long long to long long) +-e574 // Signed-unsigned mix with relational + +/////////////////////////////////////////////////////////////////////// +// Varnishstat specific + +-emacro(774, MAC_STAT) +-emacro(506, MAC_STAT) +-emacro(525, MAC_STAT) +-efile(451, "*/include/stat_field.h") +-e850 // for loop index variable '___' whose type category is '___' is modified in body of the for loop that began at '___' + Added: trunk/varnish-cache/bin/varnishstat/flint.sh =================================================================== --- trunk/varnish-cache/bin/varnishstat/flint.sh (rev 0) +++ trunk/varnish-cache/bin/varnishstat/flint.sh 2010-06-07 08:19:51 UTC (rev 4921) @@ -0,0 +1,11 @@ +#!/bin/sh + +flexelint \ + -I/usr/include \ + -I. \ + -I../../include \ + -I../.. \ + ../flint.lnt \ + flint.lnt \ + *.c \ + ../../lib/libvarnishapi/*.c Property changes on: trunk/varnish-cache/bin/varnishstat/flint.sh ___________________________________________________________________ Added: svn:executable + * From perbu at varnish-cache.org Mon Jun 7 08:35:11 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Mon, 7 Jun 2010 10:35:11 +0200 Subject: r4922 - in trunk/varnish-cache/doc/sphinx: . reference Message-ID: Author: perbu Date: 2010-06-07 10:35:10 +0200 (Mon, 07 Jun 2010) New Revision: 4922 Modified: trunk/varnish-cache/doc/sphinx/index.rst trunk/varnish-cache/doc/sphinx/reference/varnishd.rst Log: intro + some layout Modified: trunk/varnish-cache/doc/sphinx/index.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/index.rst 2010-06-07 08:19:51 UTC (rev 4921) +++ trunk/varnish-cache/doc/sphinx/index.rst 2010-06-07 08:35:10 UTC (rev 4922) @@ -1,17 +1,17 @@ .. Varnish documentation master file, created by sphinx-quickstart on Tue Apr 20 13:02:15 2010. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. Welcome to Varnish's documentation! =================================== -Arnold's Laws of Documentation: - (1) If it should exist, it doesn't. - (2) If it does exist, it's out of date. - (3) Only documentation for useless programs transcends the - first two laws. +Varnish is a state of the art web accelerator. Its mission is to sit +in front of a web server an cache the content. It makes your web site +go fast. +We suggest you start by reading the :ref:`_Installation`. Once you +have Varnish up and running go through the :ref:`_tutorial-index`. + + Contents: .. toctree:: Modified: trunk/varnish-cache/doc/sphinx/reference/varnishd.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishd.rst 2010-06-07 08:19:51 UTC (rev 4921) +++ trunk/varnish-cache/doc/sphinx/reference/varnishd.rst 2010-06-07 08:35:10 UTC (rev 4922) @@ -794,17 +794,17 @@ The argument could be a quoted string, a regexp, or an integer. Integers can have "KB", "MB", "GB" or "TB" appended for size related fields. -Simple example: All requests where req.url exactly matches the string /news are purged from the cache. +Simple example: All requests where req.url exactly matches the string /news are purged from the cache::: req.url == "/news" Example: Purge all documents where the name does not end with ".ogg", and where the size of the object is greater -than 10 megabytes. +than 10 megabytes::: req.url !~ "\.ogg$" && obj.size > 10MB Example: Purge 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". +Cookie header received from the backend contains "USERID=1663"::: req.http.host ~ "^(www\.)example.com$" && obj.set-cookie ~ "USERID=1663" From perbu at varnish-cache.org Mon Jun 7 08:38:37 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Mon, 7 Jun 2010 10:38:37 +0200 Subject: r4923 - in trunk/varnish-cache/doc/sphinx: . installation Message-ID: Author: perbu Date: 2010-06-07 10:38:36 +0200 (Mon, 07 Jun 2010) New Revision: 4923 Modified: trunk/varnish-cache/doc/sphinx/index.rst trunk/varnish-cache/doc/sphinx/installation/index.rst Log: lame typo Modified: trunk/varnish-cache/doc/sphinx/index.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/index.rst 2010-06-07 08:35:10 UTC (rev 4922) +++ trunk/varnish-cache/doc/sphinx/index.rst 2010-06-07 08:38:36 UTC (rev 4923) @@ -8,8 +8,8 @@ in front of a web server an cache the content. It makes your web site go fast. -We suggest you start by reading the :ref:`_Installation`. Once you -have Varnish up and running go through the :ref:`_tutorial-index`. +We suggest you start by reading the :ref:`install-index`. Once you +have Varnish up and running go through the :ref:`tutorial-index`. Contents: Modified: trunk/varnish-cache/doc/sphinx/installation/index.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/installation/index.rst 2010-06-07 08:35:10 UTC (rev 4922) +++ trunk/varnish-cache/doc/sphinx/installation/index.rst 2010-06-07 08:38:36 UTC (rev 4923) @@ -1,4 +1,4 @@ -.. _Installation: +.. _install-index: %%%%%%%%%%%%%%%%%%%% Varnish Installation From phk at varnish-cache.org Mon Jun 7 12:56:09 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 7 Jun 2010 14:56:09 +0200 Subject: r4924 - in trunk/varnish-cache: bin/varnishd bin/varnishlog include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-07 14:56:09 +0200 (Mon, 07 Jun 2010) New Revision: 4924 Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/bin/varnishlog/flint.lnt trunk/varnish-cache/include/shmlog.h trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/Makefile.am trunk/varnish-cache/lib/libvarnishapi/vsl.h trunk/varnish-cache/lib/libvarnishapi/vsl_log.c Log: Tighten on the relative accesses to wrap-sequence and special marker values in the shmlog. PS: Sometimes I really long for the days when computers executed the instructions in the order written. Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-07 08:38:36 UTC (rev 4923) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-07 12:56:09 UTC (rev 4924) @@ -69,12 +69,12 @@ vsl_wrap(void) { - vsl_log_start[1] = vsl_w0(SLT_ENDMARKER, 0); + vsl_log_start[1] = VSL_ENDMARKER; do vsl_log_start[0]++; while (vsl_log_start[0] == 0); VWMB(); - *vsl_log_nxt = vsl_w0(SLT_WRAPMARKER, 0); + *vsl_log_nxt = VSL_WRAPMARKER; vsl_log_nxt = vsl_log_start + 1; VSL_stats->shm_cycles++; } @@ -106,7 +106,7 @@ p = vsl_log_nxt; vsl_log_nxt = VSL_END(vsl_log_nxt, len); - *vsl_log_nxt = vsl_w0(SLT_ENDMARKER, 0); + *vsl_log_nxt = VSL_ENDMARKER; assert(vsl_log_nxt < vsl_log_end); assert(((uintptr_t)vsl_log_nxt & 0x3) == 0); Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-07 08:38:36 UTC (rev 4923) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-07 12:56:09 UTC (rev 4924) @@ -295,7 +295,8 @@ AN(vsl_log_start); vsl_log_end = (void*)((uint8_t *)vsl_log_start + s1); vsl_log_nxt = vsl_log_start + 1; - *vsl_log_nxt = (SLT_ENDMARKER << 24); + *vsl_log_nxt = VSL_ENDMARKER; + VWMB(); do *vsl_log_start = random() & 0xffff; Modified: trunk/varnish-cache/bin/varnishlog/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishlog/flint.lnt 2010-06-07 08:38:36 UTC (rev 4923) +++ trunk/varnish-cache/bin/varnishlog/flint.lnt 2010-06-07 12:56:09 UTC (rev 4924) @@ -15,4 +15,5 @@ -e574 // Signed-unsigned mix with relational -e788 // enum constant '___' not used within defaulted switch +-e641 // Converting enum '___' to '___' Modified: trunk/varnish-cache/include/shmlog.h =================================================================== --- trunk/varnish-cache/include/shmlog.h 2010-06-07 08:38:36 UTC (rev 4923) +++ trunk/varnish-cache/include/shmlog.h 2010-06-07 12:56:09 UTC (rev 4924) @@ -96,24 +96,26 @@ * [n + 2] ... [m] = content */ -#define VSL_WORDS(len) (((len) + 3) / 4) -#define VSL_END(ptr, len) ((ptr) + 2 + VSL_WORDS(len)) -#define VSL_NEXT(ptr) VSL_END(ptr, VSL_LEN(ptr)) -#define VSL_LEN(ptr) ((ptr)[0] & 0xffff) -#define VSL_TAG(ptr) ((ptr)[0] >> 24) -#define VSL_ID(ptr) ((ptr)[1]) -#define VSL_DATA(ptr) ((char*)((ptr)+2)) +#define VSL_WORDS(len) (((len) + 3) / 4) +#define VSL_END(ptr, len) ((ptr) + 2 + VSL_WORDS(len)) +#define VSL_NEXT(ptr) VSL_END(ptr, VSL_LEN(ptr)) +#define VSL_LEN(ptr) ((ptr)[0] & 0xffff) +#define VSL_TAG(ptr) ((ptr)[0] >> 24) +#define VSL_ID(ptr) ((ptr)[1]) +#define VSL_DATA(ptr) ((char*)((ptr)+2)) +#define VSL_ENDMARKER (((uint32_t)SLT_Reserved << 24) | 0x454545) /* "EEE" */ +#define VSL_WRAPMARKER (((uint32_t)SLT_Reserved << 24) | 0x575757) /* "WWW" */ + /* * The identifiers in shmlogtag are "SLT_" + XML tag. A script may be run * on this file to extract the table rather than handcode it */ enum shmlogtag { - SLT_ENDMARKER = 0, #define SLTM(foo) SLT_##foo, #include "shmlog_tags.h" #undef SLTM - SLT_WRAPMARKER = 255U + SLT_Reserved = 255 }; /* This function lives in both libvarnish and libvarnishapi */ Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-07 08:38:36 UTC (rev 4923) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-07 12:56:09 UTC (rev 4924) @@ -50,7 +50,7 @@ vsl_handler VSL_H_Print; struct VSL_data; struct VSL_data *VSL_New(void); -void VSL_Select(struct VSL_data *vd, unsigned tag); +void VSL_Select(const struct VSL_data *vd, unsigned tag); int VSL_OpenLog(struct VSL_data *vd); void VSL_NonBlocking(struct VSL_data *vd, int nb); int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv); Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-07 08:38:36 UTC (rev 4923) +++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-07 12:56:09 UTC (rev 4924) @@ -14,6 +14,7 @@ ../libvarnish/svn_version.c \ ../libvarnish/version.c \ ../libvarnish/vin.c \ + ../libvarnish/vmb.c \ ../libvarnish/vre.c \ base64.c \ vsl.c \ Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-07 08:38:36 UTC (rev 4923) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-07 12:56:09 UTC (rev 4924) @@ -66,10 +66,12 @@ /* Stuff relating the log records below here */ - uint32_t *log_start; - uint32_t *log_end; - uint32_t *log_ptr; + volatile uint32_t *log_start; + volatile uint32_t *log_end; + volatile uint32_t *log_ptr; + volatile uint32_t last_seq; + /* for -r option */ int r_fd; unsigned rbuflen; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-07 08:38:36 UTC (rev 4923) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-07 12:56:09 UTC (rev 4924) @@ -49,6 +49,7 @@ #include "varnishapi.h" #include "vsl.h" +#include "vmb.h" static int vsl_nextlog(struct VSL_data *vd, uint32_t **pp); @@ -63,7 +64,7 @@ /*--------------------------------------------------------------------*/ void -VSL_Select(struct VSL_data *vd, unsigned tag) +VSL_Select(const struct VSL_data *vd, unsigned tag) { CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); @@ -88,9 +89,8 @@ vsl_nextlog(struct VSL_data *vd, uint32_t **pp) { unsigned w, l; - uint8_t t; + uint32_t t; int i; - uint32_t seq; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); if (vd->r_fd != -1) { @@ -111,27 +111,26 @@ *pp = vd->rbuf; return (1); } - seq = vd->log_start[0]; for (w = 0; w < TIMEOUT_USEC;) { - t = VSL_TAG(vd->log_ptr); + t = *vd->log_ptr; - if (t != SLT_ENDMARKER) { - *pp = vd->log_ptr; - vd->log_ptr = VSL_NEXT(vd->log_ptr); - return (1); - } - - if (t == SLT_WRAPMARKER || vd->log_start[0] != seq) { + if (t == VSL_WRAPMARKER || + (t == VSL_ENDMARKER && vd->last_seq != vd->log_start[0])) { vd->log_ptr = vd->log_start + 1; - seq = vd->log_start[0]; + vd->last_seq = vd->log_start[0]; + VRMB(); continue; } - - /* XXX: check log_start[0] */ - if (vd->flags & F_NON_BLOCKING) - return (-1); - w += SLEEP_USEC; - usleep(SLEEP_USEC); + if (t == VSL_ENDMARKER) { + if (vd->flags & F_NON_BLOCKING) + return (-1); + w += SLEEP_USEC; + AZ(usleep(SLEEP_USEC)); + continue; + } + *pp = (void*)(uintptr_t)vd->log_ptr; /* Loose volatile */ + vd->log_ptr = VSL_NEXT(vd->log_ptr); + return (1); } *pp = NULL; return (0); @@ -142,7 +141,7 @@ { uint32_t *p; unsigned char t; - unsigned u, l; + unsigned u; int i; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); @@ -151,7 +150,6 @@ if (i != 1) return (i); u = VSL_ID(p); - l = VSL_LEN(p); t = VSL_TAG(p); switch(t) { case SLT_SessionOpen: @@ -186,18 +184,14 @@ if (vd->c_opt && !vbit_test(vd->vbm_client, u)) continue; if (vd->regincl != NULL) { - i = VRE_exec(vd->regincl, - VSL_DATA(p), - VSL_LEN(p), /* Length */ - 0, 0, NULL, 0); + i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p), + 0, 0, NULL, 0); if (i == VRE_ERROR_NOMATCH) continue; } if (vd->regexcl != NULL) { - i = VRE_exec(vd->regincl, - VSL_DATA(p), - VSL_LEN(p), /* Length */ - 0, 0, NULL, 0); + i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p), + 0, 0, NULL, 0); if (i != VRE_ERROR_NOMATCH) continue; } @@ -247,7 +241,7 @@ (spec & VSL_S_BACKEND) ? 'b' : '-'; if (tag == SLT_Debug) { - fprintf(fo, "%5d %-12s %c \"", fd, VSL_tags[tag], type); + fprintf(fo, "%5u %-12s %c \"", fd, VSL_tags[tag], type); while (len-- > 0) { if (*ptr >= ' ' && *ptr <= '~') fprintf(fo, "%c", *ptr); @@ -258,7 +252,7 @@ fprintf(fo, "\"\n"); return (0); } - fprintf(fo, "%5d %-12s %c %.*s\n", fd, VSL_tags[tag], type, len, ptr); + fprintf(fo, "%5u %-12s %c %.*s\n", fd, VSL_tags[tag], type, len, ptr); return (0); } @@ -276,13 +270,14 @@ assert(sha != NULL); vd->log_start = SHA_PTR(sha); - vd->log_end = (void*)((char *)vd->log_start + sha->len - sizeof *sha); + vd->log_end = SHA_NEXT(sha); vd->log_ptr = vd->log_start + 1; + vd->last_seq = vd->log_start[0]; + VRMB(); if (!vd->d_opt && vd->r_fd == -1) { - while (VSL_TAG(vd->log_ptr) != SLT_ENDMARKER) + while (*vd->log_ptr != VSL_ENDMARKER) vd->log_ptr = VSL_NEXT(vd->log_ptr); } return (0); } - From phk at varnish-cache.org Tue Jun 8 08:42:16 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 10:42:16 +0200 Subject: r4925 - in trunk/varnish-cache: bin/varnishadm bin/varnishstat include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 10:42:15 +0200 (Tue, 08 Jun 2010) New Revision: 4925 Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl.h trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c trunk/varnish-cache/lib/libvarnishapi/vsl_log.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Log: Begin a major round of polishing of the VarnishAPI to make it sensible general-ish and explainable. Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.c 2010-06-07 12:56:09 UTC (rev 4924) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.c 2010-06-08 08:42:15 UTC (rev 4925) @@ -245,7 +245,7 @@ if (n_arg != NULL) { vsd = VSL_New(); assert(VSL_Log_Arg(vsd, 'n', n_arg)); - if (!VSL_Open(vsd)) { + if (!VSL_Open(vsd, 1)) { if (T_arg == NULL) { p = VSL_Find_Alloc(vsd, "Arg", "-T", "", NULL); if (p != NULL) { Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-07 12:56:09 UTC (rev 4924) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-08 08:42:15 UTC (rev 4925) @@ -207,7 +207,7 @@ (void)VSL_Stat_Arg(vd, c, optarg); break; case 'l': - if (VSL_Open(vd)) + if (VSL_Open(vd, 1)) exit(1); list_fields(vd); exit(0); @@ -227,7 +227,7 @@ } } - if (VSL_Open(vd)) + if (VSL_Open(vd, 1)) exit(1); if ((VSL_stats = VSL_OpenStats(vd)) == NULL) Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-07 12:56:09 UTC (rev 4924) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-08 08:42:15 UTC (rev 4925) @@ -164,7 +164,7 @@ * Only check if it looks like nothing is happening. */ act = VSL_stats->cache_hit + VSL_stats->cache_miss + 1; - if (act == lact && VSL_ReOpen(vd)) + if (act == lact && VSL_ReOpen(vd, 1)) break; lact = act; Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-07 12:56:09 UTC (rev 4924) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-08 08:42:15 UTC (rev 4925) @@ -34,10 +34,87 @@ #include "shmlog.h" -/* base64.c */ -void base64_init(void); -int base64_decode(char *d, unsigned dlen, const char *s); +/* + * Various notes: + * All malloc failures will result in assert tripping. + * API use failures will trip assert. + */ + +/*--------------------------------------------------------------------- + * Level 0: Create and destroy the VSL_data handle structure + */ + +struct VSL_data *VSL_New(void); + /* + * Allocate and initialize a VSL_data handle structure. + * This is the first thing you will have to do, always. + * You can have multiple active VSL_data handles at the same time + * referencing the same or different shared memory files. + * Returns: + * Pointer to usable VSL_data handle. + */ + +typedef void vsl_diag_f(void *priv, const char *fmt, ...); + +void VSL_Diag(struct VSL_data *vd, vsl_diag_f *func, void *priv); + /* + * Set the diagnostics reporting function. + * Default is fprintf(stderr, ...) + * If func is NULL, diagnostics are disabled. + */ + +int VSL_n_Arg(struct VSL_data *vd, const char *n_arg); + /* + * Configure which varnishd instance to access. + * Can also be, and normally is done through the VSL_Log_arg() + * and VSL_Stat_Arg() functions. + * Returns: + * 1 on success + * -1 on failure, with diagnostic on stderr. + */ + +const char *VSL_Name(const struct VSL_data *vd); + /* + * Return the instance name. + */ + +void VSL_Delete(struct VSL_data *vd); + /* + * Close and deallocate all storage and mappings. + */ + +/* XXX: extension: Patience argument for sleeps */ + +/*--------------------------------------------------------------------- + * Level 1: Open/Close and find allocation in shared memory segment + */ + +int VSL_Open(struct VSL_data *vd, int diag); + /* + * Attempt to open and map the shared memory file. + * If diag is non-zero, diagnostics are emitted. + * Returns: + * 0 on success + * != 0 on failure + */ + +int VSL_ReOpen(struct VSL_data *vd, int diag); + /* + * Check if shared memory segment needs to be reopened/remapped + * typically when the varnishd master process restarts. + * diag is passed to VSL_Open() + * Returns: + * 0 No reopen needed. + * 1 shared memory reopened/remapped. + * -1 failure to reopen. + */ + +void *VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, + const char *ident, unsigned *lenp); +void VSL_Close(struct VSL_data *vd); + + /* shmlog.c */ typedef int vsl_handler(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr); @@ -49,7 +126,6 @@ " [-r file] [-s skip] [-X regexp] [-x tag]" vsl_handler VSL_H_Print; struct VSL_data; -struct VSL_data *VSL_New(void); void VSL_Select(const struct VSL_data *vd, unsigned tag); int VSL_OpenLog(struct VSL_data *vd); void VSL_NonBlocking(struct VSL_data *vd, int nb); @@ -57,16 +133,9 @@ int VSL_NextLog(struct VSL_data *lh, uint32_t **pp); int VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt); int VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt); -void VSL_Close(struct VSL_data *vd); -int VSL_Open(struct VSL_data *vd); -void VSL_Delete(struct VSL_data *vd); struct varnish_stats *VSL_OpenStats(struct VSL_data *vd); -const char *VSL_Name(const struct VSL_data *vd); extern const char *VSL_tags[256]; -void *VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, - const char *ident, unsigned *lenp); -int VSL_ReOpen(struct VSL_data *vd); struct shmalloc *vsl_iter0(const struct VSL_data *vd); void vsl_itern(const struct VSL_data *vd, struct shmalloc **pp); @@ -88,4 +157,8 @@ int VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv); +/* base64.c */ +void base64_init(void); +int base64_decode(char *d, unsigned dlen, const char *s); + #endif Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-07 12:56:09 UTC (rev 4924) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 08:42:15 UTC (rev 4925) @@ -64,12 +64,16 @@ { struct VSL_data *vd; - vd = calloc(sizeof *vd, 1); - assert(vd != NULL); - vd->regflags = 0; - vd->magic = VSL_MAGIC; + ALLOC_OBJ(vd, VSL_MAGIC); + AN(vd); + + vd->diag = (vsl_diag_f*)fprintf; + vd->priv = stderr; + vd->vsl_fd = -1; + vd->regflags = 0; + /* XXX: Allocate only if log access */ vd->vbm_client = vbit_init(4096); vd->vbm_backend = vbit_init(4096); @@ -84,16 +88,59 @@ VTAILQ_INIT(&vd->sf_list); + CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); return (vd); } /*--------------------------------------------------------------------*/ void +VSL_Diag(struct VSL_data *vd, vsl_diag_f *func, void *priv) +{ + + CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + if (func == NULL) + vd->diag = (vsl_diag_f*)getpid; + else + vd->diag = func; + vd->priv = priv; +} + +/*--------------------------------------------------------------------*/ + +int +VSL_n_Arg(struct VSL_data *vd, const char *opt) +{ + + CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + REPLACE(vd->n_opt, opt); + AN(vd->n_opt); + if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) { + vd->diag(vd->priv, "Invalid instance name: %s\n", + strerror(errno)); + return (-1); + } + return (1); +} + +/*--------------------------------------------------------------------*/ + +const char * +VSL_Name(const struct VSL_data *vd) +{ + + CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + return (vd->n_opt); +} + +/*--------------------------------------------------------------------*/ + +void VSL_Delete(struct VSL_data *vd) { struct vsl_sf *sf; + CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); VSL_Close(vd); vbit_destroy(vd->vbm_client); vbit_destroy(vd->vbm_backend); @@ -118,7 +165,7 @@ /*--------------------------------------------------------------------*/ static int -vsl_open(struct VSL_data *vd, int rep) +vsl_open(struct VSL_data *vd, int diag) { int i; struct shmloghead slh; @@ -128,30 +175,30 @@ vd->vsl_fd = open(vd->fname, O_RDONLY); if (vd->vsl_fd < 0) { - if (rep) - fprintf(stderr, "Cannot open %s: %s\n", + if (diag) + vd->diag(vd->priv, "Cannot open %s: %s\n", vd->fname, strerror(errno)); return (1); } assert(fstat(vd->vsl_fd, &vd->fstat) == 0); if (!S_ISREG(vd->fstat.st_mode)) { - if (rep) - fprintf(stderr, "%s is not a regular file\n", + if (diag) + vd->diag(vd->priv, "%s is not a regular file\n", vd->fname); return (1); } i = read(vd->vsl_fd, &slh, sizeof slh); if (i != sizeof slh) { - if (rep) - fprintf(stderr, "Cannot read %s: %s\n", + if (diag) + vd->diag(vd->priv, "Cannot read %s: %s\n", vd->fname, strerror(errno)); return (1); } if (slh.magic != SHMLOGHEAD_MAGIC) { - if (rep) - fprintf(stderr, "Wrong magic number in file %s\n", + if (diag) + vd->diag(vd->priv, "Wrong magic number in file %s\n", vd->fname); return (1); } @@ -159,24 +206,27 @@ vd->vsl_lh = (void *)mmap(NULL, slh.shm_size, PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsl_fd, 0); if (vd->vsl_lh == MAP_FAILED) { - if (rep) - fprintf(stderr, "Cannot mmap %s: %s\n", + if (diag) + vd->diag(vd->priv, "Cannot mmap %s: %s\n", vd->fname, strerror(errno)); return (1); } vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size; while(slh.alloc_seq == 0) - usleep(50000); + usleep(50000); /* XXX limit total sleep */ vd->alloc_seq = slh.alloc_seq; return (0); } +/*--------------------------------------------------------------------*/ + int -VSL_Open(struct VSL_data *vd) +VSL_Open(struct VSL_data *vd, int diag) + { - return (vsl_open(vd, 1)); + return (vsl_open(vd, diag)); } /*--------------------------------------------------------------------*/ @@ -196,13 +246,12 @@ /*--------------------------------------------------------------------*/ int -VSL_ReOpen(struct VSL_data *vd) +VSL_ReOpen(struct VSL_data *vd, int diag) { struct stat st; int i; - if (vd->vsl_lh == NULL) - return (-1); + AN(vd->vsl_lh); if (stat(vd->fname, &st)) return (0); @@ -211,11 +260,11 @@ return (0); VSL_Close(vd); - for (i = 0; i < 5; i++) { + for (i = 0; i < 5; i++) { /* XXX param */ if (!vsl_open(vd, 0)) return (1); } - if (vsl_open(vd, 1)) + if (vsl_open(vd, diag)) return (-1); return (1); } @@ -281,8 +330,6 @@ struct shmalloc *sha; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - if (VSL_Open(vd)) - return (NULL); sha = vsl_find_alloc(vd, class, type, ident); if (sha == NULL) return (NULL); @@ -290,12 +337,3 @@ *lenp = sha->len - sizeof *sha; return (SHA_PTR(sha)); } - -/*--------------------------------------------------------------------*/ - -const char * -VSL_Name(const struct VSL_data *vd) -{ - - return (vd->n_opt); -} Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-07 12:56:09 UTC (rev 4924) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-08 08:42:15 UTC (rev 4925) @@ -51,7 +51,13 @@ unsigned magic; #define VSL_MAGIC 0x6e3bd69b + vsl_diag_f *diag; + void *priv; + + char *n_opt; char *fname; + + struct stat fstat; int vsl_fd; @@ -78,7 +84,6 @@ uint32_t *rbuf; unsigned L_opt; - char *n_opt; int b_opt; int c_opt; int d_opt; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-07 12:56:09 UTC (rev 4924) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 08:42:15 UTC (rev 4925) @@ -192,22 +192,6 @@ /*--------------------------------------------------------------------*/ -static int -vsl_n_arg(struct VSL_data *vd, const char *opt) -{ - - REPLACE(vd->n_opt, opt); - AN(vd->n_opt); - if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) { - fprintf(stderr, "Invalid instance name: %s\n", - strerror(errno)); - return (-1); - } - return (1); -} - -/*--------------------------------------------------------------------*/ - int VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt) { @@ -222,7 +206,7 @@ return (1); case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg)); case 'k': return (vsl_k_arg(vd, opt)); - case 'n': return (vsl_n_arg(vd, opt)); + case 'n': return (VSL_n_Arg(vd, opt)); case 'r': return (vsl_r_arg(vd, opt)); case 's': return (vsl_s_arg(vd, opt)); case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg)); @@ -331,7 +315,7 @@ CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); switch (arg) { case 'f': return (vsl_sf_arg(vd, opt)); - case 'n': return (vsl_n_arg(vd, opt)); + case 'n': return (VSL_n_Arg(vd, opt)); default: return (0); } Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-07 12:56:09 UTC (rev 4924) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 08:42:15 UTC (rev 4925) @@ -264,8 +264,6 @@ struct shmalloc *sha; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - if (VSL_Open(vd)) - return (-1); sha = vsl_find_alloc(vd, VSL_CLASS_LOG, "", ""); assert(sha != NULL); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-07 12:56:09 UTC (rev 4924) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 08:42:15 UTC (rev 4925) @@ -54,8 +54,6 @@ CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - if (VSL_Open(vd)) - return (NULL); sha = vsl_find_alloc(vd, VSL_CLASS_STAT, "", ""); assert(sha != NULL); return (SHA_PTR(sha)); From phk at varnish-cache.org Tue Jun 8 08:46:15 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 10:46:15 +0200 Subject: r4926 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 10:46:15 +0200 (Tue, 08 Jun 2010) New Revision: 4926 Added: trunk/varnish-cache/lib/libvarnishapi/vslapi.h Removed: trunk/varnish-cache/lib/libvarnishapi/vsl.h Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c trunk/varnish-cache/lib/libvarnishapi/vsl_log.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Log: Rename vsl.h to vslapi.h Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-08 08:42:15 UTC (rev 4925) +++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-08 08:46:15 UTC (rev 4926) @@ -7,7 +7,7 @@ libvarnishapi_la_LDFLAGS = -version-info 1:0:0 libvarnishapi_la_SOURCES = \ - vsl.h \ + vslapi.h \ \ ../libvarnish/assert.c \ ../libvarnish/argv.c \ Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 08:42:15 UTC (rev 4925) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 08:46:15 UTC (rev 4926) @@ -51,7 +51,7 @@ #include "miniobj.h" #include "varnishapi.h" -#include "vsl.h" +#include "vslapi.h" #ifndef MAP_HASSEMAPHORE #define MAP_HASSEMAPHORE 0 /* XXX Linux */ Deleted: trunk/varnish-cache/lib/libvarnishapi/vsl.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-08 08:42:15 UTC (rev 4925) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.h 2010-06-08 08:46:15 UTC (rev 4926) @@ -1,121 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2010 Redpill Linpro AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - */ - -/* Parameters */ -#define SLEEP_USEC (50*1000) -#define TIMEOUT_USEC (5*1000*1000) - -struct vsl_sf { - unsigned magic; -#define VSL_SF_MAGIC 0x558478dd - VTAILQ_ENTRY(vsl_sf) next; - int flags; -#define VSL_SF_EXCL (1 << 0) -#define VSL_SF_CL_WC (1 << 1) -#define VSL_SF_ID_WC (1 << 2) -#define VSL_SF_NM_WC (1 << 3) - char *class; - char *ident; - char *name; -}; - -struct VSL_data { - unsigned magic; -#define VSL_MAGIC 0x6e3bd69b - - vsl_diag_f *diag; - void *priv; - - char *n_opt; - char *fname; - - - struct stat fstat; - - int vsl_fd; - struct shmloghead *vsl_lh; - void *vsl_end; - unsigned alloc_seq; - - /* Stuff relating the stats fields start here */ - - int sf_init; - VTAILQ_HEAD(, vsl_sf) sf_list; - - /* Stuff relating the log records below here */ - - volatile uint32_t *log_start; - volatile uint32_t *log_end; - volatile uint32_t *log_ptr; - - volatile uint32_t last_seq; - - /* for -r option */ - int r_fd; - unsigned rbuflen; - uint32_t *rbuf; - - unsigned L_opt; - int b_opt; - int c_opt; - int d_opt; - - unsigned flags; -#define F_SEEN_IX (1 << 0) -#define F_NON_BLOCKING (1 << 1) - - /* - * These two bitmaps mark fd's as belonging to client or backend - * transactions respectively. - */ - struct vbitmap *vbm_client; - struct vbitmap *vbm_backend; - - /* - * Bit map of programatically selected tags, that cannot be suppressed. - * This way programs can make sure they will see certain tags, even - * if the user tries to supress them with -x/-X - */ - struct vbitmap *vbm_select; /* index: tag */ - - /* Bit map of tags selected/supressed with -[iIxX] options */ - struct vbitmap *vbm_supress; /* index: tag */ - - int regflags; - vre_t *regincl; - vre_t *regexcl; - - unsigned long skip; - unsigned long keep; -}; - -struct shmalloc *vsl_find_alloc(const struct VSL_data *vd, const char *class, - const char *type, const char *ident); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 08:42:15 UTC (rev 4925) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 08:46:15 UTC (rev 4926) @@ -52,7 +52,7 @@ #include "miniobj.h" #include "varnishapi.h" -#include "vsl.h" +#include "vslapi.h" /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 08:42:15 UTC (rev 4925) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 08:46:15 UTC (rev 4926) @@ -48,7 +48,7 @@ #include "miniobj.h" #include "varnishapi.h" -#include "vsl.h" +#include "vslapi.h" #include "vmb.h" static int vsl_nextlog(struct VSL_data *vd, uint32_t **pp); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 08:42:15 UTC (rev 4925) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 08:46:15 UTC (rev 4926) @@ -43,7 +43,7 @@ #include "miniobj.h" #include "varnishapi.h" -#include "vsl.h" +#include "vslapi.h" /*--------------------------------------------------------------------*/ Copied: trunk/varnish-cache/lib/libvarnishapi/vslapi.h (from rev 4925, trunk/varnish-cache/lib/libvarnishapi/vsl.h) =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vslapi.h (rev 0) +++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 08:46:15 UTC (rev 4926) @@ -0,0 +1,121 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2010 Redpill Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +/* Parameters */ +#define SLEEP_USEC (50*1000) +#define TIMEOUT_USEC (5*1000*1000) + +struct vsl_sf { + unsigned magic; +#define VSL_SF_MAGIC 0x558478dd + VTAILQ_ENTRY(vsl_sf) next; + int flags; +#define VSL_SF_EXCL (1 << 0) +#define VSL_SF_CL_WC (1 << 1) +#define VSL_SF_ID_WC (1 << 2) +#define VSL_SF_NM_WC (1 << 3) + char *class; + char *ident; + char *name; +}; + +struct VSL_data { + unsigned magic; +#define VSL_MAGIC 0x6e3bd69b + + vsl_diag_f *diag; + void *priv; + + char *n_opt; + char *fname; + + + struct stat fstat; + + int vsl_fd; + struct shmloghead *vsl_lh; + void *vsl_end; + unsigned alloc_seq; + + /* Stuff relating the stats fields start here */ + + int sf_init; + VTAILQ_HEAD(, vsl_sf) sf_list; + + /* Stuff relating the log records below here */ + + volatile uint32_t *log_start; + volatile uint32_t *log_end; + volatile uint32_t *log_ptr; + + volatile uint32_t last_seq; + + /* for -r option */ + int r_fd; + unsigned rbuflen; + uint32_t *rbuf; + + unsigned L_opt; + int b_opt; + int c_opt; + int d_opt; + + unsigned flags; +#define F_SEEN_IX (1 << 0) +#define F_NON_BLOCKING (1 << 1) + + /* + * These two bitmaps mark fd's as belonging to client or backend + * transactions respectively. + */ + struct vbitmap *vbm_client; + struct vbitmap *vbm_backend; + + /* + * Bit map of programatically selected tags, that cannot be suppressed. + * This way programs can make sure they will see certain tags, even + * if the user tries to supress them with -x/-X + */ + struct vbitmap *vbm_select; /* index: tag */ + + /* Bit map of tags selected/supressed with -[iIxX] options */ + struct vbitmap *vbm_supress; /* index: tag */ + + int regflags; + vre_t *regincl; + vre_t *regexcl; + + unsigned long skip; + unsigned long keep; +}; + +struct shmalloc *vsl_find_alloc(const struct VSL_data *vd, const char *class, + const char *type, const char *ident); From phk at varnish-cache.org Tue Jun 8 09:09:50 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 11:09:50 +0200 Subject: r4927 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 11:09:49 +0200 (Tue, 08 Jun 2010) New Revision: 4927 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/bin/varnishd/storage_malloc.c trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/include/shmlog.h trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnish/vin.c trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl_log.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c trunk/varnish-cache/lib/libvarnishapi/vslapi.h Log: Begin splitting shared memory log stuff into its three distinct parts: VSM handling of the shared memory, allocations etc. VSL Shared memory Log VSC Shared memory Counters Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/bin/varnishd/cache.h 2010-06-08 09:09:49 UTC (rev 4927) @@ -634,7 +634,7 @@ /* cache_shmlog.c */ void VSL_Init(void); -#ifdef SHMLOGHEAD_MAGIC +#ifdef VSM_HEAD_MAGIC void VSL(enum shmlogtag tag, int id, const char *fmt, ...); void WSLR(struct worker *w, enum shmlogtag tag, int id, txt t); void WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...); Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/bin/varnishd/common.h 2010-06-08 09:09:49 UTC (rev 4927) @@ -41,7 +41,7 @@ /* mgt_shmem.c */ void *mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident); extern struct varnish_stats *VSL_stats; -extern struct shmloghead *loghead; +extern struct vsm_head *loghead; extern uint32_t *vsl_log_start; extern uint32_t *vsl_log_end; extern uint32_t *vsl_log_nxt; Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-08 09:09:49 UTC (rev 4927) @@ -55,7 +55,7 @@ #endif struct varnish_stats *VSL_stats; -struct shmloghead *loghead; +struct vsm_head *loghead; uint32_t *vsl_log_start; uint32_t *vsl_log_end; uint32_t *vsl_log_nxt; @@ -67,7 +67,7 @@ void * mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident) { - struct shmalloc *sha, *sha2; + struct vsm_chunk *sha, *sha2; unsigned seq; ASSERT_MGT(); @@ -79,10 +79,10 @@ size += sizeof *sha; sha = &loghead->head; while (1) { - CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC); + CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); if (strcmp(sha->class, "Free")) { - sha = SHA_NEXT(sha); + sha = VSM_NEXT(sha); continue; } assert(size <= sha->len); @@ -94,7 +94,7 @@ VWMB(); memset(sha2, 0, sizeof *sha2); - sha2->magic = SHMALLOC_MAGIC; + sha2->magic = VSM_CHUNK_MAGIC; sha2->len = sha->len - size; bprintf(sha2->class, "%s", "Free"); @@ -109,7 +109,7 @@ loghead->alloc_seq = seq++; while (loghead->alloc_seq == 0); - return (SHA_PTR(sha)); + return (VSM_PTR(sha)); } return (NULL); } @@ -122,7 +122,7 @@ static void vsl_n_check(int fd) { - struct shmloghead slh; + struct vsm_head slh; int i; struct stat st; @@ -134,7 +134,7 @@ i = read(fd, &slh, sizeof slh); if (i != sizeof slh) return; - if (slh.magic != SHMLOGHEAD_MAGIC) + if (slh.magic != VSM_HEAD_MAGIC) return; if (slh.hdrsize != sizeof slh) return; @@ -157,7 +157,7 @@ static void vsl_buildnew(const char *fn, unsigned size, int fill) { - struct shmloghead slh; + struct vsm_head slh; int i; unsigned u; char buf[64*1024]; @@ -171,7 +171,7 @@ } memset(&slh, 0, sizeof slh); - slh.magic = SHMLOGHEAD_MAGIC; + slh.magic = VSM_HEAD_MAGIC; slh.hdrsize = sizeof slh; slh.shm_size = size; i = write(vsl_fd, &slh, sizeof slh); @@ -276,14 +276,14 @@ (void)mlock((void*)loghead, size); memset(&loghead->head, 0, sizeof loghead->head); - loghead->head.magic = SHMALLOC_MAGIC; + loghead->head.magic = VSM_CHUNK_MAGIC; loghead->head.len = (uint8_t*)(loghead) + size - (uint8_t*)&loghead->head; bprintf(loghead->head.class, "%s", "Free"); VWMB(); VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, - VSL_CLASS_STAT, VSL_TYPE_STAT, ""); + VSM_CLASS_STAT, VSL_TYPE_STAT, ""); AN(VSL_stats); pp = mgt_SHM_Alloc(sizeof *pp, "Params", "", ""); @@ -291,7 +291,7 @@ *pp = *params; params = pp; - vsl_log_start = mgt_SHM_Alloc(s1, VSL_CLASS_LOG, "", ""); + vsl_log_start = mgt_SHM_Alloc(s1, VSM_CLASS_LOG, "", ""); AN(vsl_log_start); vsl_log_end = (void*)((uint8_t *)vsl_log_start + s1); vsl_log_nxt = vsl_log_start + 1; Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2010-06-08 09:09:49 UTC (rev 4927) @@ -189,7 +189,7 @@ CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC); sma_sc->stats = mgt_SHM_Alloc(sizeof *sma_sc->stats, - VSL_CLASS_STAT, VSL_TYPE_STAT_SMA, st->ident); + VSM_CLASS_STAT, VSL_TYPE_STAT_SMA, st->ident); memset(sma_sc->stats, 0, sizeof *sma_sc->stats); } Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-08 09:09:49 UTC (rev 4927) @@ -623,7 +623,7 @@ HSH_config(h_arg); - mgt_SHM_Init(SHMLOG_FILENAME, l_arg); + mgt_SHM_Init(VSM_FILENAME, l_arg); vsb_finish(vident); AZ(vsb_overflowed(vident)); Modified: trunk/varnish-cache/include/shmlog.h =================================================================== --- trunk/varnish-cache/include/shmlog.h 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/include/shmlog.h 2010-06-08 09:09:49 UTC (rev 4927) @@ -36,7 +36,7 @@ #ifndef SHMLOG_H_INCLUDED #define SHMLOG_H_INCLUDED -#define SHMLOG_FILENAME "_.vsl" +#define VSM_FILENAME "_.vsm" #include #include @@ -47,8 +47,8 @@ * This structure describes each allocation from the shmlog */ -struct shmalloc { -#define SHMALLOC_MAGIC 0x43907b6e /* From /dev/random */ +struct vsm_chunk { +#define VSM_CHUNK_MAGIC 0x43907b6e /* From /dev/random */ unsigned magic; unsigned len; char class[8]; @@ -56,11 +56,11 @@ char ident[16]; }; -#define SHA_NEXT(sha) ((void*)((uintptr_t)(sha) + (sha)->len)) -#define SHA_PTR(sha) ((void*)((uintptr_t)((sha) + 1))) +#define VSM_NEXT(sha) ((void*)((uintptr_t)(sha) + (sha)->len)) +#define VSM_PTR(sha) ((void*)((uintptr_t)((sha) + 1))) -struct shmloghead { -#define SHMLOGHEAD_MAGIC 4185512502U /* From /dev/random */ +struct vsm_head { +#define VSM_HEAD_MAGIC 4185512502U /* From /dev/random */ unsigned magic; unsigned hdrsize; @@ -76,11 +76,11 @@ unsigned alloc_seq; /* Must be last element */ - struct shmalloc head; + struct vsm_chunk head; }; -#define VSL_CLASS_LOG "Log" -#define VSL_CLASS_STAT "Stat" +#define VSM_CLASS_LOG "Log" +#define VSM_CLASS_STAT "Stat" /* * Shared memory log format Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-08 09:09:49 UTC (rev 4927) @@ -137,8 +137,8 @@ extern const char *VSL_tags[256]; -struct shmalloc *vsl_iter0(const struct VSL_data *vd); -void vsl_itern(const struct VSL_data *vd, struct shmalloc **pp); +struct vsm_chunk *vsl_iter0(const struct VSL_data *vd); +void vsl_itern(const struct VSL_data *vd, struct vsm_chunk **pp); #define VSL_FOREACH(var, vd) \ for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var))) Modified: trunk/varnish-cache/lib/libvarnish/vin.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vin.c 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/lib/libvarnish/vin.c 2010-06-08 09:09:49 UTC (rev 4927) @@ -75,7 +75,7 @@ } /* Definitive length check */ - if (strlen(dn) + 1 + strlen(SHMLOG_FILENAME) >= sizeof dn) { + if (strlen(dn) + 1 + strlen(VSM_FILENAME) >= sizeof dn) { errno = ENAMETOOLONG; return (-1); } @@ -93,7 +93,7 @@ return (-1); } if (vsl != NULL) { - bprintf(nm, "%s%s", dn, SHMLOG_FILENAME); + bprintf(nm, "%s%s", dn, VSM_FILENAME); *vsl = strdup(nm); if (*vsl == NULL) return (-1); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 09:09:49 UTC (rev 4927) @@ -168,7 +168,7 @@ vsl_open(struct VSL_data *vd, int diag) { int i; - struct shmloghead slh; + struct vsm_head slh; if (vd->vsl_lh != NULL) return (0); @@ -196,7 +196,7 @@ vd->fname, strerror(errno)); return (1); } - if (slh.magic != SHMLOGHEAD_MAGIC) { + if (slh.magic != VSM_HEAD_MAGIC) { if (diag) vd->diag(vd->priv, "Wrong magic number in file %s\n", vd->fname); @@ -271,19 +271,19 @@ /*--------------------------------------------------------------------*/ -struct shmalloc * +struct vsm_chunk * vsl_iter0(const struct VSL_data *vd) { CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); if (vd->alloc_seq != vd->vsl_lh->alloc_seq) return(NULL); - CHECK_OBJ_NOTNULL(&vd->vsl_lh->head, SHMALLOC_MAGIC); + CHECK_OBJ_NOTNULL(&vd->vsl_lh->head, VSM_CHUNK_MAGIC); return (&vd->vsl_lh->head); } void -vsl_itern(const struct VSL_data *vd, struct shmalloc **pp) +vsl_itern(const struct VSL_data *vd, struct vsm_chunk **pp) { CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); @@ -291,25 +291,25 @@ *pp = NULL; return; } - CHECK_OBJ_NOTNULL(*pp, SHMALLOC_MAGIC); - *pp = SHA_NEXT(*pp); + CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); + *pp = VSM_NEXT(*pp); if ((void*)(*pp) >= vd->vsl_end) { *pp = NULL; return; } - CHECK_OBJ_NOTNULL(*pp, SHMALLOC_MAGIC); + CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); } /*--------------------------------------------------------------------*/ -struct shmalloc * +struct vsm_chunk * vsl_find_alloc(const struct VSL_data *vd, const char *class, const char *type, const char *ident) { - struct shmalloc *sha; + struct vsm_chunk *sha; assert (vd->vsl_lh != NULL); VSL_FOREACH(sha, vd) { - CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC); + CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); if (strcmp(sha->class, class)) continue; if (type != NULL && strcmp(sha->type, type)) @@ -327,7 +327,7 @@ VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident, unsigned *lenp) { - struct shmalloc *sha; + struct vsm_chunk *sha; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); sha = vsl_find_alloc(vd, class, type, ident); @@ -335,5 +335,5 @@ return (NULL); if (lenp != NULL) *lenp = sha->len - sizeof *sha; - return (SHA_PTR(sha)); + return (VSM_PTR(sha)); } Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 09:09:49 UTC (rev 4927) @@ -261,14 +261,14 @@ int VSL_OpenLog(struct VSL_data *vd) { - struct shmalloc *sha; + struct vsm_chunk *sha; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - sha = vsl_find_alloc(vd, VSL_CLASS_LOG, "", ""); + sha = vsl_find_alloc(vd, VSM_CLASS_LOG, "", ""); assert(sha != NULL); - vd->log_start = SHA_PTR(sha); - vd->log_end = SHA_NEXT(sha); + vd->log_start = VSM_PTR(sha); + vd->log_end = VSM_NEXT(sha); vd->log_ptr = vd->log_start + 1; vd->last_seq = vd->log_start[0]; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 09:09:49 UTC (rev 4927) @@ -50,13 +50,13 @@ struct varnish_stats * VSL_OpenStats(struct VSL_data *vd) { - struct shmalloc *sha; + struct vsm_chunk *sha; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - sha = vsl_find_alloc(vd, VSL_CLASS_STAT, "", ""); + sha = vsl_find_alloc(vd, VSM_CLASS_STAT, "", ""); assert(sha != NULL); - return (SHA_PTR(sha)); + return (VSM_PTR(sha)); } /*-------------------------------------------------------------------- @@ -104,10 +104,10 @@ } static int -iter_main(const struct VSL_data *vd, struct shmalloc *sha, vsl_stat_f *func, +iter_main(const struct VSL_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, void *priv) { - struct varnish_stats *st = SHA_PTR(sha); + struct varnish_stats *st = VSM_PTR(sha); struct vsl_statpt sp; int i; @@ -128,10 +128,10 @@ } static int -iter_sma(const struct VSL_data *vd, struct shmalloc *sha, vsl_stat_f *func, +iter_sma(const struct VSL_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, void *priv) { - struct varnish_stats_sma *st = SHA_PTR(sha); + struct varnish_stats_sma *st = VSM_PTR(sha); struct vsl_statpt sp; int i; @@ -154,13 +154,13 @@ int VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv) { - struct shmalloc *sha; + struct vsm_chunk *sha; int i; i = 0; VSL_FOREACH(sha, vd) { - CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC); - if (strcmp(sha->class, VSL_CLASS_STAT)) + CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); + if (strcmp(sha->class, VSM_CLASS_STAT)) continue; if (!strcmp(sha->type, VSL_TYPE_STAT)) i = iter_main(vd, sha, func, priv); Modified: trunk/varnish-cache/lib/libvarnishapi/vslapi.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 08:46:15 UTC (rev 4926) +++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 09:09:49 UTC (rev 4927) @@ -61,7 +61,7 @@ struct stat fstat; int vsl_fd; - struct shmloghead *vsl_lh; + struct vsm_head *vsl_lh; void *vsl_end; unsigned alloc_seq; @@ -117,5 +117,5 @@ unsigned long keep; }; -struct shmalloc *vsl_find_alloc(const struct VSL_data *vd, const char *class, +struct vsm_chunk *vsl_find_alloc(const struct VSL_data *vd, const char *class, const char *type, const char *ident); From phk at varnish-cache.org Tue Jun 8 09:23:38 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 11:23:38 +0200 Subject: r4928 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 11:23:38 +0200 (Tue, 08 Jun 2010) New Revision: 4928 Added: trunk/varnish-cache/include/vin.h trunk/varnish-cache/include/vsm.h Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_panic.c trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/include/Makefile.am trunk/varnish-cache/include/shmlog.h trunk/varnish-cache/lib/libvarnish/vin.c trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c trunk/varnish-cache/lib/libvarnishapi/vsl_log.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Log: Move vin stuff into vin.h and vsm stuff into vsm.h Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/bin/varnishd/cache.h 2010-06-08 09:23:38 UTC (rev 4928) @@ -634,7 +634,7 @@ /* cache_shmlog.c */ void VSL_Init(void); -#ifdef VSM_HEAD_MAGIC +#ifdef VSL_ENDMARKER void VSL(enum shmlogtag tag, int id, const char *fmt, ...); void WSLR(struct worker *w, enum shmlogtag tag, int id, txt t); void WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...); Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2010-06-08 09:23:38 UTC (rev 4928) @@ -44,6 +44,7 @@ #include #endif #include "cache.h" +#include "vsm.h" #include "shmlog.h" #include "cache_backend.h" #include "vcl.h" Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-08 09:23:38 UTC (rev 4928) @@ -36,6 +36,7 @@ #include #include +#include "vsm.h" #include "shmlog.h" #include "cache.h" #include "vmb.h" Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2010-06-08 09:23:38 UTC (rev 4928) @@ -71,7 +71,7 @@ #endif /* mgt_shmem.c */ -void mgt_SHM_Init(const char *fn, const char *arg); +void mgt_SHM_Init(const char *arg); void mgt_SHM_Pid(void); /* mgt_vcc.c */ Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2010-06-08 09:23:38 UTC (rev 4928) @@ -59,7 +59,7 @@ #endif #include "mgt.h" -#include "shmlog.h" +#include "vsm.h" #include "heritage.h" #include "cli.h" #include "cli_priv.h" Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-08 09:23:38 UTC (rev 4928) @@ -41,6 +41,7 @@ #include #include +#include "vsm.h" #include "shmlog.h" #include "mgt.h" #include "heritage.h" @@ -194,7 +195,7 @@ } void -mgt_SHM_Init(const char *fn, const char *l_arg) +mgt_SHM_Init(const char *l_arg) { int i, fill; struct params *pp; @@ -259,13 +260,13 @@ size += ps - 1; size &= ~(ps - 1); - i = open(fn, O_RDWR, 0644); + i = open(VSM_FILENAME, O_RDWR, 0644); if (i >= 0) { vsl_n_check(i); (void)close(i); } (void)close(i); - vsl_buildnew(fn, size, fill); + vsl_buildnew(VSM_FILENAME, size, fill); loghead = (void *)mmap(NULL, size, PROT_READ|PROT_WRITE, Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-08 09:23:38 UTC (rev 4928) @@ -66,7 +66,7 @@ #include "cli_priv.h" #include "cli_common.h" -#include "shmlog.h" +#include "vin.h" #include "heritage.h" #include "mgt.h" #include "hash_slinger.h" @@ -623,7 +623,7 @@ HSH_config(h_arg); - mgt_SHM_Init(VSM_FILENAME, l_arg); + mgt_SHM_Init(l_arg); vsb_finish(vident); AZ(vsb_overflowed(vident)); Modified: trunk/varnish-cache/include/Makefile.am =================================================================== --- trunk/varnish-cache/include/Makefile.am 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/include/Makefile.am 2010-06-08 09:23:38 UTC (rev 4928) @@ -1,6 +1,7 @@ # $Id$ pkginclude_HEADERS = \ + vsm.h \ shmlog.h \ shmlog_tags.h \ stat_field.h \ Modified: trunk/varnish-cache/include/shmlog.h =================================================================== --- trunk/varnish-cache/include/shmlog.h 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/include/shmlog.h 2010-06-08 09:23:38 UTC (rev 4928) @@ -36,49 +36,8 @@ #ifndef SHMLOG_H_INCLUDED #define SHMLOG_H_INCLUDED -#define VSM_FILENAME "_.vsm" - -#include -#include - #include "stats.h" -/* - * This structure describes each allocation from the shmlog - */ - -struct vsm_chunk { -#define VSM_CHUNK_MAGIC 0x43907b6e /* From /dev/random */ - unsigned magic; - unsigned len; - char class[8]; - char type[8]; - char ident[16]; -}; - -#define VSM_NEXT(sha) ((void*)((uintptr_t)(sha) + (sha)->len)) -#define VSM_PTR(sha) ((void*)((uintptr_t)((sha) + 1))) - -struct vsm_head { -#define VSM_HEAD_MAGIC 4185512502U /* From /dev/random */ - unsigned magic; - - unsigned hdrsize; - - time_t starttime; - pid_t master_pid; - pid_t child_pid; - - unsigned shm_size; - - /* Panic message buffer */ - char panicstr[64 * 1024]; - - unsigned alloc_seq; - /* Must be last element */ - struct vsm_chunk head; -}; - #define VSM_CLASS_LOG "Log" #define VSM_CLASS_STAT "Stat" @@ -118,12 +77,4 @@ SLT_Reserved = 255 }; -/* This function lives in both libvarnish and libvarnishapi */ -int vin_n_arg(const char *n_arg, char **name, char **dir, char **vsl); -char *vin_L_arg(unsigned L_arg); -#define VIN_L_LOW 1024 -#define VIN_L_HIGH 65000 -#define VIN_L_OK(a) (a >= VIN_L_LOW && a <= VIN_L_HIGH) -#define VIN_L_MSG "-L argument must be [1024...65000]" - #endif Copied: trunk/varnish-cache/include/vin.h (from rev 4927, trunk/varnish-cache/include/shmlog.h) =================================================================== --- trunk/varnish-cache/include/vin.h (rev 0) +++ trunk/varnish-cache/include/vin.h 2010-06-08 09:23:38 UTC (rev 4928) @@ -0,0 +1,44 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2009 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + * + */ + +#ifndef VIN_H_INCLUDED +#define VIN_H_INCLUDED + +/* This function lives in both libvarnish and libvarnishapi */ +int vin_n_arg(const char *n_arg, char **name, char **dir, char **vsl); +char *vin_L_arg(unsigned L_arg); +#define VIN_L_LOW 1024 +#define VIN_L_HIGH 65000 +#define VIN_L_OK(a) (a >= VIN_L_LOW && a <= VIN_L_HIGH) +#define VIN_L_MSG "-L argument must be [1024...65000]" + +#endif Copied: trunk/varnish-cache/include/vsm.h (from rev 4927, trunk/varnish-cache/include/shmlog.h) =================================================================== --- trunk/varnish-cache/include/vsm.h (rev 0) +++ trunk/varnish-cache/include/vsm.h 2010-06-08 09:23:38 UTC (rev 4928) @@ -0,0 +1,80 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2009 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + * + * Define the layout of the shared memory log segment. + * + * NB: THIS IS NOT A PUBLIC API TO VARNISH! + */ + +#ifndef VSM_H_INCLUDED +#define VSM_H_INCLUDED + +#define VSM_FILENAME "_.vsm" + +#include +#include + +/* + * This structure describes each allocation from the shmlog + */ + +struct vsm_chunk { +#define VSM_CHUNK_MAGIC 0x43907b6e /* From /dev/random */ + unsigned magic; + unsigned len; + char class[8]; + char type[8]; + char ident[16]; +}; + +#define VSM_NEXT(sha) ((void*)((uintptr_t)(sha) + (sha)->len)) +#define VSM_PTR(sha) ((void*)((uintptr_t)((sha) + 1))) + +struct vsm_head { +#define VSM_HEAD_MAGIC 4185512502U /* From /dev/random */ + unsigned magic; + + unsigned hdrsize; + + time_t starttime; + pid_t master_pid; + pid_t child_pid; + + unsigned shm_size; + + /* Panic message buffer */ + char panicstr[64 * 1024]; + + unsigned alloc_seq; + /* Must be last element */ + struct vsm_chunk head; +}; + +#endif Modified: trunk/varnish-cache/lib/libvarnish/vin.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vin.c 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/lib/libvarnish/vin.c 2010-06-08 09:23:38 UTC (rev 4928) @@ -40,7 +40,8 @@ #include #include "libvarnish.h" -#include "shmlog.h" +#include "vsm.h" +#include "vin.h" int vin_n_arg(const char *n_arg, char **name, char **dir, char **vsl) Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 09:23:38 UTC (rev 4928) @@ -44,7 +44,8 @@ #include #include "vas.h" -#include "shmlog.h" +#include "vin.h" +#include "vsm.h" #include "vre.h" #include "vbm.h" #include "vqueue.h" Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 09:23:38 UTC (rev 4928) @@ -45,7 +45,7 @@ #include "vas.h" #include "argv.h" -#include "shmlog.h" +#include "vin.h" #include "vre.h" #include "vbm.h" #include "vqueue.h" Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 09:23:38 UTC (rev 4928) @@ -41,6 +41,7 @@ #include #include "vas.h" +#include "vsm.h" #include "shmlog.h" #include "vre.h" #include "vbm.h" Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 09:09:49 UTC (rev 4927) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 09:23:38 UTC (rev 4928) @@ -37,6 +37,7 @@ #include #include "vas.h" +#include "vsm.h" #include "shmlog.h" #include "vre.h" #include "vqueue.h" From phk at varnish-cache.org Tue Jun 8 09:46:28 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 11:46:28 +0200 Subject: r4929 - in trunk/varnish-cache: bin/varnishd bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishsizes bin/varnishstat bin/varnishtest bin/varnishtop include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 11:46:28 +0200 (Tue, 08 Jun 2010) New Revision: 4929 Added: trunk/varnish-cache/include/vsc.h trunk/varnish-cache/include/vsl.h trunk/varnish-cache/include/vsl_tags.h Removed: trunk/varnish-cache/include/shmlog.h trunk/varnish-cache/include/shmlog_tags.h trunk/varnish-cache/include/stats.h Modified: trunk/varnish-cache/bin/varnishd/acct_fields.h trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_acceptor.c trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c trunk/varnish-cache/bin/varnishd/cache_backend_poll.c trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_cli.c trunk/varnish-cache/bin/varnishd/cache_dir_random.c trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c trunk/varnish-cache/bin/varnishd/cache_esi.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_httpconn.c trunk/varnish-cache/bin/varnishd/cache_lck.c trunk/varnish-cache/bin/varnishd/cache_main.c trunk/varnish-cache/bin/varnishd/cache_panic.c trunk/varnish-cache/bin/varnishd/cache_pipe.c trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/cache_response.c trunk/varnish-cache/bin/varnishd/cache_session.c trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/bin/varnishd/cache_vcl.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/bin/varnishd/cache_vrt_re.c trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c trunk/varnish-cache/bin/varnishd/cache_wrw.c trunk/varnish-cache/bin/varnishd/cache_ws.c trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/hash_classic.c trunk/varnish-cache/bin/varnishd/hash_critbit.c trunk/varnish-cache/bin/varnishd/hash_simple_list.c trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/bin/varnishd/rfc2616.c trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/storage_malloc.c trunk/varnish-cache/bin/varnishd/storage_persistent.c trunk/varnish-cache/bin/varnishd/storage_synth.c trunk/varnish-cache/bin/varnishd/storage_umem.c trunk/varnish-cache/bin/varnishhist/varnishhist.c trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/bin/varnishncsa/varnishncsa.c trunk/varnish-cache/bin/varnishsizes/varnishsizes.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishstat/varnishstat.h trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/bin/varnishtop/varnishtop.c trunk/varnish-cache/include/Makefile.am trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsl_log.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Log: Split and rename shmlog.h to vsl.h and vsc.h Modified: trunk/varnish-cache/bin/varnishd/acct_fields.h =================================================================== --- trunk/varnish-cache/bin/varnishd/acct_fields.h 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/acct_fields.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -30,7 +30,7 @@ * * These are the stats we keep track of per session. They will be summed, * via the sp->wrk->stats into the s_ fields in the SHM file. - * NB: Remember to mark those in stat_field.h to be included in struct dstat. + * NB: Remember to mark those in vsc_fields.h to be included in struct dstat. */ ACCT(sess) Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -62,6 +62,9 @@ #include "heritage.h" #include "miniobj.h" +#include "vsc.h" +#include "vsl.h" + enum { /* Fields from the first line of HTTP proto */ HTTP_HDR_REQ, @@ -193,7 +196,7 @@ #define L1(n) int n; #define MAC_STAT(n, t, l, f, e) L##l(n) struct dstat { -#include "stat_field.h" +#include "vsc_fields.h" }; #undef MAC_STAT #undef L0 Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -46,7 +46,6 @@ #include "cli.h" #include "cli_priv.h" -#include "shmlog.h" #include "cache.h" #include "cache_waiter.h" Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -44,7 +44,6 @@ #include -#include "shmlog.h" #include "cache.h" #include "cache_backend.h" #include "vrt.h" Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -43,7 +43,6 @@ #include -#include "shmlog.h" #include "cache.h" #include "vrt.h" #include "vsha256.h" Modified: trunk/varnish-cache/bin/varnishd/cache_backend_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -49,7 +49,6 @@ #include -#include "shmlog.h" #include "cli_priv.h" #include "cache.h" #include "vrt.h" Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -51,7 +51,6 @@ #include #include -#include "shmlog.h" #include "cli.h" #include "cli_priv.h" #include "cache.h" Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -72,7 +72,6 @@ #include "compat/srandomdev.h" #endif -#include "shmlog.h" #include "vcl.h" #include "cli_priv.h" #include "cache.h" Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_cli.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -46,7 +46,6 @@ #include #include -#include "shmlog.h" #include "cli.h" #include "cli_priv.h" #include "cli_common.h" @@ -137,7 +136,7 @@ SZOF(struct objhead); SZOF(struct sess); SZOF(struct vbe_conn); - SZOF(struct varnish_stats); + SZOF(struct vsc_main); SZOF(struct lock); } Modified: trunk/varnish-cache/bin/varnishd/cache_dir_random.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_dir_random.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -53,7 +53,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "cache_backend.h" #include "vrt.h" Modified: trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_dir_round_robin.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -40,7 +40,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "cache_backend.h" #include "vrt.h" Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -50,7 +50,6 @@ #include #include -#include "shmlog.h" #include "vrt.h" #include "vcl.h" #include "vct.h" Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -48,7 +48,6 @@ #include #include -#include "shmlog.h" #include "binary_heap.h" #include "cache.h" #include "vcl.h" Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -38,7 +38,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "stevedore.h" #include "cli_priv.h" @@ -380,7 +379,7 @@ return (__LINE__); } - /* Checkpoint the shmlog here */ + /* Checkpoint the vsl.here */ WSL_Flush(w, 0); /* XXX is this the right place? */ Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -63,7 +63,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "stevedore.h" #include "hash_slinger.h" Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -41,7 +41,6 @@ #include #include -#include "shmlog.h" #include "vct.h" #include "cache.h" Modified: trunk/varnish-cache/bin/varnishd/cache_httpconn.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_httpconn.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_httpconn.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -40,7 +40,6 @@ #include #include -#include "shmlog.h" #include "cache.h" /*-------------------------------------------------------------------- Modified: trunk/varnish-cache/bin/varnishd/cache_lck.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_lck.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_lck.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -46,7 +46,6 @@ #endif #include -#include "shmlog.h" #include "cache.h" /*The constability of lck depends on platform pthreads implementation */ Modified: trunk/varnish-cache/bin/varnishd/cache_main.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_main.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_main.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -37,7 +37,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "stevedore.h" #include "hash_slinger.h" Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -45,7 +45,6 @@ #endif #include "cache.h" #include "vsm.h" -#include "shmlog.h" #include "cache_backend.h" #include "vcl.h" #include "libvcl.h" Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -41,7 +41,6 @@ #include #include -#include "shmlog.h" #include "cache.h" static int Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -54,7 +54,6 @@ #include #include -#include "shmlog.h" #include "vcl.h" #include "cli_priv.h" #include "cache.h" @@ -98,7 +97,7 @@ #define L0(n) #define L1(n) (VSL_stats->n += w->stats.n) #define MAC_STAT(n, t, l, f, d) L##l(n); -#include "stat_field.h" +#include "vsc_fields.h" #undef MAC_STAT #undef L0 #undef L1 @@ -361,7 +360,7 @@ */ static void -wrk_decimate_flock(struct wq *qp, double t_idle, struct varnish_stats *vs) +wrk_decimate_flock(struct wq *qp, double t_idle, struct vsc_main *vs) { struct worker *w = NULL; @@ -403,7 +402,7 @@ { volatile unsigned u; double t_idle; - struct varnish_stats vsm, *vs; + struct vsc_main vsm, *vs; int errno_is_multi_threaded; THR_SetName("wrk_herdtimer"); Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -38,7 +38,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "vct.h" Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -49,7 +49,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "cache_backend.h" Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -37,7 +37,6 @@ #include #include "vsm.h" -#include "shmlog.h" #include "cache.h" #include "vmb.h" Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vcl.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_vcl.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -44,7 +44,6 @@ #include "cli.h" #include "cli_priv.h" -#include "shmlog.h" #include "vcl.h" #include "cache.h" #include "libvcl.h" Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -46,7 +46,6 @@ #include #include -#include "shmlog.h" #include "vrt.h" #include "vrt_obj.h" #include "vcl.h" Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_re.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_re.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_re.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -41,7 +41,6 @@ #include #include -#include "shmlog.h" #include "vrt.h" #include "vre.h" #include "vcl.h" Modified: trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_waiter_epoll.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -51,7 +51,6 @@ # define EPOLLRDHUP 0 #endif -#include "shmlog.h" #include "cache.h" #include "cache_waiter.h" Modified: trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_waiter_kqueue.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -47,7 +47,6 @@ #include -#include "shmlog.h" #include "cache.h" #include "cache_waiter.h" Modified: trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_waiter_poll.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -40,7 +40,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "cache_waiter.h" Modified: trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_waiter_ports.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -49,7 +49,6 @@ #include "compat/clock_gettime.h" #endif -#include "shmlog.h" #include "cache.h" #include "cache_waiter.h" Modified: trunk/varnish-cache/bin/varnishd/cache_wrw.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_wrw.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_wrw.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -60,7 +60,6 @@ #endif #endif /* SENDFILE_WORKS */ -#include "shmlog.h" #include "cache.h" /*-------------------------------------------------------------------- Modified: trunk/varnish-cache/bin/varnishd/cache_ws.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ws.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/cache_ws.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -42,7 +42,6 @@ #include #include -#include "shmlog.h" #include "vcl.h" #include "cli_priv.h" #include "cache.h" Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/common.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -40,7 +40,7 @@ /* mgt_shmem.c */ void *mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident); -extern struct varnish_stats *VSL_stats; +extern struct vsc_main *VSL_stats; extern struct vsm_head *loghead; extern uint32_t *vsl_log_start; extern uint32_t *vsl_log_end; Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_classic.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/hash_classic.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -39,7 +39,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "hash_slinger.h" Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_critbit.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/hash_critbit.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -39,7 +39,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "hash_slinger.h" #include "cli_priv.h" Modified: trunk/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -38,7 +38,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "hash_slinger.h" Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -55,7 +55,7 @@ #include "cli_common.h" #include "cli_serve.h" #include "vev.h" -#include "shmlog.h" +#include "vsc.h" #include "vlu.h" #include "vss.h" @@ -84,7 +84,7 @@ #define MAC_STAT(n, t, l, f, d) \ if (VSL_stats->n != 0) \ cli_out(cli, "%12ju %s\n", (VSL_stats->n), d); -#include "stat_field.h" +#include "vsc_fields.h" #undef MAC_STAT } Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -42,7 +42,8 @@ #include #include "vsm.h" -#include "shmlog.h" +#include "vsc.h" +#include "vsl.h" #include "mgt.h" #include "heritage.h" #include "vmb.h" @@ -55,7 +56,7 @@ #define MAP_NOSYNC 0 /* XXX Linux */ #endif -struct varnish_stats *VSL_stats; +struct vsc_main *VSL_stats; struct vsm_head *loghead; uint32_t *vsl_log_start; uint32_t *vsl_log_end; @@ -284,7 +285,7 @@ VWMB(); VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, - VSM_CLASS_STAT, VSL_TYPE_STAT, ""); + VSC_CLASS, VSC_TYPE_MAIN, ""); AN(VSL_stats); pp = mgt_SHM_Alloc(sizeof *pp, "Params", "", ""); Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- trunk/varnish-cache/bin/varnishd/rfc2616.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -39,7 +39,6 @@ #include #include -#include "shmlog.h" #include "cache.h" Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -46,7 +46,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "stevedore.h" Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -39,7 +39,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "stevedore.h" @@ -48,7 +47,7 @@ #define SMA_SC_MAGIC 0x1ac8a345 struct lock sma_mtx; size_t sma_max; - struct varnish_stats_sma *stats; + struct vsc_sma *stats; }; struct sma { @@ -189,7 +188,7 @@ CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC); sma_sc->stats = mgt_SHM_Alloc(sizeof *sma_sc->stats, - VSM_CLASS_STAT, VSL_TYPE_STAT_SMA, st->ident); + VSC_CLASS, VSC_TYPE_SMA, st->ident); memset(sma_sc->stats, 0, sizeof *sma_sc->stats); } Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_persistent.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/storage_persistent.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -46,7 +46,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "stevedore.h" #include "hash_slinger.h" Modified: trunk/varnish-cache/bin/varnishd/storage_synth.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_synth.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/storage_synth.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -39,7 +39,6 @@ #include #include -#include "shmlog.h" #include "cache.h" #include "vsb.h" #include "stevedore.h" Modified: trunk/varnish-cache/bin/varnishd/storage_umem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_umem.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishd/storage_umem.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -45,7 +45,6 @@ #include #include "config.h" -#include "shmlog.h" #include "cache.h" #include "stevedore.h" Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -49,7 +49,7 @@ #include #include "libvarnish.h" -#include "shmlog.h" +#include "vsl.h" #include "varnishapi.h" #define HIST_N 2000 /* how far back we remember */ Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -49,7 +49,7 @@ #include "vpf.h" #include "libvarnish.h" -#include "shmlog.h" +#include "vsl.h" #include "vre.h" #include "varnishapi.h" Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -78,7 +78,7 @@ #include "vpf.h" #include "libvarnish.h" -#include "shmlog.h" +#include "vsl.h" #include "varnishapi.h" static volatile sig_atomic_t reopen; Modified: trunk/varnish-cache/bin/varnishsizes/varnishsizes.c =================================================================== --- trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -49,7 +49,7 @@ #include #include "libvarnish.h" -#include "shmlog.h" +#include "vsl.h" #include "varnishapi.h" #define HIST_N 2000 /* how far back we remember */ Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -45,7 +45,7 @@ #include #include "libvarnish.h" -#include "shmlog.h" +#include "vsc.h" #include "varnishapi.h" #include "varnishstat.h" @@ -121,7 +121,7 @@ } static void -do_once(const struct VSL_data *vd, const struct varnish_stats *VSL_stats) +do_once(const struct VSL_data *vd, const struct vsc_main *VSL_stats) { struct once_priv op; @@ -193,7 +193,7 @@ { int c; struct VSL_data *vd; - const struct varnish_stats *VSL_stats; + const struct vsc_main *VSL_stats; int delay = 1, once = 0, xml = 0; vd = VSL_New(); Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.h =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.h 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -27,4 +27,4 @@ * */ -void do_curses(struct VSL_data *vd, const struct varnish_stats *VSL_stats, int delay); +void do_curses(struct VSL_data *vd, const struct vsc_main *VSL_stats, int delay); Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -47,7 +47,7 @@ #include #include "libvarnish.h" -#include "shmlog.h" +#include "vsc.h" #include "vqueue.h" #include "varnishapi.h" #include "varnishstat.h" @@ -123,7 +123,7 @@ } void -do_curses(struct VSL_data *vd, const struct varnish_stats *VSL_stats, +do_curses(struct VSL_data *vd, const struct vsc_main *VSL_stats, int delay) { intmax_t ju; Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -67,7 +67,7 @@ struct vtclog *vl1; VTAILQ_ENTRY(varnish) list; - struct varnish_stats *stats; + struct vsc_main *stats; struct vsb *storage; Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -51,7 +51,7 @@ #include "vsb.h" #include "libvarnish.h" -#include "shmlog.h" +#include "vsl.h" #include "varnishapi.h" #define AC(x) assert((x) != ERR) Modified: trunk/varnish-cache/include/Makefile.am =================================================================== --- trunk/varnish-cache/include/Makefile.am 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/include/Makefile.am 2010-06-08 09:46:28 UTC (rev 4929) @@ -2,10 +2,10 @@ pkginclude_HEADERS = \ vsm.h \ - shmlog.h \ - shmlog_tags.h \ - stat_field.h \ - stats.h \ + vsl.h \ + vsl_tags.h \ + vsc_fields.h \ + vsc.h \ varnishapi.h nobase_noinst_HEADERS = \ Deleted: trunk/varnish-cache/include/shmlog.h =================================================================== --- trunk/varnish-cache/include/shmlog.h 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/include/shmlog.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -1,80 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2009 Linpro AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - * - * Define the layout of the shared memory log segment. - * - * NB: THIS IS NOT A PUBLIC API TO VARNISH! - */ - -#ifndef SHMLOG_H_INCLUDED -#define SHMLOG_H_INCLUDED - -#include "stats.h" - -#define VSM_CLASS_LOG "Log" -#define VSM_CLASS_STAT "Stat" - -/* - * Shared memory log format - * - * The log is structured as an array of 32bit unsigned integers. - * - * The first integer contains a non-zero serial number, which changes - * whenever writing the log starts from the front. - * - * Each logrecord consist of: - * [n] = ((type & 0xff) << 24) | (length & 0xffff) - * [n + 1] = identifier - * [n + 2] ... [m] = content - */ - -#define VSL_WORDS(len) (((len) + 3) / 4) -#define VSL_END(ptr, len) ((ptr) + 2 + VSL_WORDS(len)) -#define VSL_NEXT(ptr) VSL_END(ptr, VSL_LEN(ptr)) -#define VSL_LEN(ptr) ((ptr)[0] & 0xffff) -#define VSL_TAG(ptr) ((ptr)[0] >> 24) -#define VSL_ID(ptr) ((ptr)[1]) -#define VSL_DATA(ptr) ((char*)((ptr)+2)) - -#define VSL_ENDMARKER (((uint32_t)SLT_Reserved << 24) | 0x454545) /* "EEE" */ -#define VSL_WRAPMARKER (((uint32_t)SLT_Reserved << 24) | 0x575757) /* "WWW" */ - -/* - * The identifiers in shmlogtag are "SLT_" + XML tag. A script may be run - * on this file to extract the table rather than handcode it - */ -enum shmlogtag { -#define SLTM(foo) SLT_##foo, -#include "shmlog_tags.h" -#undef SLTM - SLT_Reserved = 255 -}; - -#endif Deleted: trunk/varnish-cache/include/shmlog_tags.h =================================================================== --- trunk/varnish-cache/include/shmlog_tags.h 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/include/shmlog_tags.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -1,98 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2009 Linpro AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - * - * Define the tags in the shared memory in a reusable format. - * Whoever includes this get to define what the SLTM macro does. - * - * REMEMBER to update the documentation (especially the varnishlog(1) man - * page) whenever this list changes. - * - * XXX: Please add new entries a the end to not break saved log-segments. - * XXX: we can resort them when we have a major release. - */ - -SLTM(Debug) -SLTM(Error) -SLTM(CLI) -SLTM(StatSess) -SLTM(ReqEnd) -SLTM(SessionOpen) -SLTM(SessionClose) -SLTM(BackendOpen) -SLTM(BackendXID) -SLTM(BackendReuse) -SLTM(BackendClose) -SLTM(HttpGarbage) -SLTM(Backend) -SLTM(Length) - -SLTM(FetchError) - -SLTM(RxRequest) -SLTM(RxResponse) -SLTM(RxStatus) -SLTM(RxURL) -SLTM(RxProtocol) -SLTM(RxHeader) - -SLTM(TxRequest) -SLTM(TxResponse) -SLTM(TxStatus) -SLTM(TxURL) -SLTM(TxProtocol) -SLTM(TxHeader) - -SLTM(ObjRequest) -SLTM(ObjResponse) -SLTM(ObjStatus) -SLTM(ObjURL) -SLTM(ObjProtocol) -SLTM(ObjHeader) - -SLTM(LostHeader) - -SLTM(TTL) -SLTM(VCL_acl) -SLTM(VCL_call) -SLTM(VCL_trace) -SLTM(VCL_return) -SLTM(VCL_error) -SLTM(ReqStart) -SLTM(Hit) -SLTM(HitPass) -SLTM(ExpBan) -SLTM(ExpKill) -SLTM(WorkThread) - -SLTM(ESI_xmlerror) - -SLTM(Hash) - -SLTM(Backend_health) Deleted: trunk/varnish-cache/include/stats.h =================================================================== --- trunk/varnish-cache/include/stats.h 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/include/stats.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -1,48 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2009 Linpro AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - */ - -#include - -#define VSL_TYPE_STAT "" - -struct varnish_stats { -#define MAC_STAT(n, t, l, f, e) t n; -#include "stat_field.h" -#undef MAC_STAT -}; - -#define VSL_TYPE_STAT_SMA "SMA" - -struct varnish_stats_sma { -#define MAC_STAT_SMA(n, t, l, f, e) t n; -#include "stat_field.h" -#undef MAC_STAT_SMA -}; Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -32,7 +32,7 @@ #ifndef VARNISHAPI_H_INCLUDED #define VARNISHAPI_H_INCLUDED -#include "shmlog.h" +#include "vsl.h" /* * Various notes: @@ -133,7 +133,7 @@ int VSL_NextLog(struct VSL_data *lh, uint32_t **pp); int VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt); int VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt); -struct varnish_stats *VSL_OpenStats(struct VSL_data *vd); +struct vsc_main *VSL_OpenStats(struct VSL_data *vd); extern const char *VSL_tags[256]; Copied: trunk/varnish-cache/include/vsc.h (from rev 4916, trunk/varnish-cache/include/stats.h) =================================================================== --- trunk/varnish-cache/include/vsc.h (rev 0) +++ trunk/varnish-cache/include/vsc.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2009 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +#include + +#define VSC_CLASS "Stat" + +#define VSC_TYPE_MAIN "" + +struct vsc_main { +#define MAC_STAT(n, t, l, f, e) t n; +#include "vsc_fields.h" +#undef MAC_STAT +}; + +#define VSC_TYPE_SMA "SMA" + +struct vsc_sma { +#define MAC_STAT_SMA(n, t, l, f, e) t n; +#include "vsc_fields.h" +#undef MAC_STAT_SMA +}; Copied: trunk/varnish-cache/include/vsl.h (from rev 4928, trunk/varnish-cache/include/shmlog.h) =================================================================== --- trunk/varnish-cache/include/vsl.h (rev 0) +++ trunk/varnish-cache/include/vsl.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2009 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + * + * Define the layout of the shared memory log segment. + * + * NB: THIS IS NOT A PUBLIC API TO VARNISH! + */ + +#ifndef SHMLOG_H_INCLUDED +#define SHMLOG_H_INCLUDED + +#define VSM_CLASS_LOG "Log" + +/* + * Shared memory log format + * + * The log is structured as an array of 32bit unsigned integers. + * + * The first integer contains a non-zero serial number, which changes + * whenever writing the log starts from the front. + * + * Each logrecord consist of: + * [n] = ((type & 0xff) << 24) | (length & 0xffff) + * [n + 1] = identifier + * [n + 2] ... [m] = content + */ + +#define VSL_WORDS(len) (((len) + 3) / 4) +#define VSL_END(ptr, len) ((ptr) + 2 + VSL_WORDS(len)) +#define VSL_NEXT(ptr) VSL_END(ptr, VSL_LEN(ptr)) +#define VSL_LEN(ptr) ((ptr)[0] & 0xffff) +#define VSL_TAG(ptr) ((ptr)[0] >> 24) +#define VSL_ID(ptr) ((ptr)[1]) +#define VSL_DATA(ptr) ((char*)((ptr)+2)) + +#define VSL_ENDMARKER (((uint32_t)SLT_Reserved << 24) | 0x454545) /* "EEE" */ +#define VSL_WRAPMARKER (((uint32_t)SLT_Reserved << 24) | 0x575757) /* "WWW" */ + +/* + * The identifiers in shmlogtag are "SLT_" + XML tag. A script may be run + * on this file to extract the table rather than handcode it + */ +enum shmlogtag { +#define SLTM(foo) SLT_##foo, +#include "vsl_tags.h" +#undef SLTM + SLT_Reserved = 255 +}; + +#endif Copied: trunk/varnish-cache/include/vsl_tags.h (from rev 4916, trunk/varnish-cache/include/shmlog_tags.h) =================================================================== --- trunk/varnish-cache/include/vsl_tags.h (rev 0) +++ trunk/varnish-cache/include/vsl_tags.h 2010-06-08 09:46:28 UTC (rev 4929) @@ -0,0 +1,98 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2009 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + * + * Define the tags in the shared memory in a reusable format. + * Whoever includes this get to define what the SLTM macro does. + * + * REMEMBER to update the documentation (especially the varnishlog(1) man + * page) whenever this list changes. + * + * XXX: Please add new entries a the end to not break saved log-segments. + * XXX: we can resort them when we have a major release. + */ + +SLTM(Debug) +SLTM(Error) +SLTM(CLI) +SLTM(StatSess) +SLTM(ReqEnd) +SLTM(SessionOpen) +SLTM(SessionClose) +SLTM(BackendOpen) +SLTM(BackendXID) +SLTM(BackendReuse) +SLTM(BackendClose) +SLTM(HttpGarbage) +SLTM(Backend) +SLTM(Length) + +SLTM(FetchError) + +SLTM(RxRequest) +SLTM(RxResponse) +SLTM(RxStatus) +SLTM(RxURL) +SLTM(RxProtocol) +SLTM(RxHeader) + +SLTM(TxRequest) +SLTM(TxResponse) +SLTM(TxStatus) +SLTM(TxURL) +SLTM(TxProtocol) +SLTM(TxHeader) + +SLTM(ObjRequest) +SLTM(ObjResponse) +SLTM(ObjStatus) +SLTM(ObjURL) +SLTM(ObjProtocol) +SLTM(ObjHeader) + +SLTM(LostHeader) + +SLTM(TTL) +SLTM(VCL_acl) +SLTM(VCL_call) +SLTM(VCL_trace) +SLTM(VCL_return) +SLTM(VCL_error) +SLTM(ReqStart) +SLTM(Hit) +SLTM(HitPass) +SLTM(ExpBan) +SLTM(ExpKill) +SLTM(WorkThread) + +SLTM(ESI_xmlerror) + +SLTM(Hash) + +SLTM(Backend_health) Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -42,7 +42,7 @@ #include "vas.h" #include "vsm.h" -#include "shmlog.h" +#include "vsl.h" #include "vre.h" #include "vbm.h" #include "vqueue.h" @@ -58,7 +58,7 @@ const char *VSL_tags[256] = { #define SLTM(foo) [SLT_##foo] = #foo, -#include "shmlog_tags.h" +#include "vsl_tags.h" #undef SLTM }; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 09:23:38 UTC (rev 4928) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 09:46:28 UTC (rev 4929) @@ -38,7 +38,7 @@ #include "vas.h" #include "vsm.h" -#include "shmlog.h" +#include "vsc.h" #include "vre.h" #include "vqueue.h" #include "miniobj.h" @@ -48,14 +48,14 @@ /*--------------------------------------------------------------------*/ -struct varnish_stats * +struct vsc_main * VSL_OpenStats(struct VSL_data *vd) { struct vsm_chunk *sha; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - sha = vsl_find_alloc(vd, VSM_CLASS_STAT, "", ""); + sha = vsl_find_alloc(vd, VSC_CLASS, "", ""); assert(sha != NULL); return (VSM_PTR(sha)); } @@ -108,7 +108,7 @@ iter_main(const struct VSL_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, void *priv) { - struct varnish_stats *st = VSM_PTR(sha); + struct vsc_main *st = VSM_PTR(sha); struct vsl_statpt sp; int i; @@ -123,7 +123,7 @@ i = iter_call(vd, func, priv, &sp); \ if (i) \ return(i); -#include "stat_field.h" +#include "vsc_fields.h" #undef MAC_STAT return (0); } @@ -132,11 +132,11 @@ iter_sma(const struct VSL_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, void *priv) { - struct varnish_stats_sma *st = VSM_PTR(sha); + struct vsc_sma *st = VSM_PTR(sha); struct vsl_statpt sp; int i; - sp.class = VSL_TYPE_STAT_SMA; + sp.class = VSC_TYPE_SMA; sp.ident = sha->ident; #define MAC_STAT_SMA(nn, tt, ll, ff, dd) \ sp.name = #nn; \ @@ -147,7 +147,7 @@ i = iter_call(vd, func, priv, &sp); \ if (i) \ return(i); -#include "stat_field.h" +#include "vsc_fields.h" #undef MAC_STAT_SMA return (0); } @@ -161,11 +161,11 @@ i = 0; VSL_FOREACH(sha, vd) { CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); - if (strcmp(sha->class, VSM_CLASS_STAT)) + if (strcmp(sha->class, VSC_CLASS)) continue; - if (!strcmp(sha->type, VSL_TYPE_STAT)) + if (!strcmp(sha->type, VSC_TYPE_MAIN)) i = iter_main(vd, sha, func, priv); - else if (!strcmp(sha->type, VSL_TYPE_STAT_SMA)) + else if (!strcmp(sha->type, VSC_TYPE_SMA)) i = iter_sma(vd, sha, func, priv); else i = -1; From phk at varnish-cache.org Tue Jun 8 09:49:37 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 11:49:37 +0200 Subject: r4930 - trunk/varnish-cache/include Message-ID: Author: phk Date: 2010-06-08 11:49:36 +0200 (Tue, 08 Jun 2010) New Revision: 4930 Added: trunk/varnish-cache/include/vsc_fields.h Log: Not sure why this didn't get included in last commit Added: trunk/varnish-cache/include/vsc_fields.h =================================================================== --- trunk/varnish-cache/include/vsc_fields.h (rev 0) +++ trunk/varnish-cache/include/vsc_fields.h 2010-06-08 09:49:36 UTC (rev 4930) @@ -0,0 +1,177 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2009 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: vsc_fields.h 4857 2010-05-25 10:47:20Z phk $ + * + * 3rd argument marks fields for inclusion in the per worker-thread + * stats structure. + */ + +#ifndef MAC_STAT +#define MAC_STAT(a, b, c, d, e) +#define __MAC_STAT +#endif + + +MAC_STAT(client_conn, uint64_t, 0, 'a', "Client connections accepted") +MAC_STAT(client_drop, uint64_t, 0, 'a', "Connection dropped, no sess/wrk") +MAC_STAT(client_req, uint64_t, 1, 'a', "Client requests received") + +MAC_STAT(cache_hit, uint64_t, 1, 'a', "Cache hits") +MAC_STAT(cache_hitpass, uint64_t, 1, 'a', "Cache hits for pass") +MAC_STAT(cache_miss, uint64_t, 1, 'a', "Cache misses") + +MAC_STAT(backend_conn, uint64_t, 0, 'a', "Backend conn. success") +MAC_STAT(backend_unhealthy, uint64_t, 0, 'a', "Backend conn. not attempted") +MAC_STAT(backend_busy, uint64_t, 0, 'a', "Backend conn. too many") +MAC_STAT(backend_fail, uint64_t, 0, 'a', "Backend conn. failures") +MAC_STAT(backend_reuse, uint64_t, 0, 'a', "Backend conn. reuses") +MAC_STAT(backend_toolate, uint64_t, 0, 'a', "Backend conn. was closed") +MAC_STAT(backend_recycle, uint64_t, 0, 'a', "Backend conn. recycles") +MAC_STAT(backend_unused, uint64_t, 0, 'a', "Backend conn. unused") + +MAC_STAT(fetch_head, uint64_t, 1, 'a', "Fetch head") +MAC_STAT(fetch_length, uint64_t, 1, 'a', "Fetch with Length") +MAC_STAT(fetch_chunked, uint64_t, 1, 'a', "Fetch chunked") +MAC_STAT(fetch_eof, uint64_t, 1, 'a', "Fetch EOF") +MAC_STAT(fetch_bad, uint64_t, 1, 'a', "Fetch had bad headers") +MAC_STAT(fetch_close, uint64_t, 1, 'a', "Fetch wanted close") +MAC_STAT(fetch_oldhttp, uint64_t, 1, 'a', "Fetch pre HTTP/1.1 closed") +MAC_STAT(fetch_zero, uint64_t, 1, 'a', "Fetch zero len") +MAC_STAT(fetch_failed, uint64_t, 1, 'a', "Fetch failed") + + +MAC_STAT(n_sess_mem, uint64_t, 0, 'i', "N struct sess_mem") +MAC_STAT(n_sess, uint64_t, 0, 'i', "N struct sess") +MAC_STAT(n_object, uint64_t, 1, 'i', "N struct object") +MAC_STAT(n_vampireobject, uint64_t, 1, 'i', "N unresurrected objects") +MAC_STAT(n_objectcore, uint64_t, 1, 'i', "N struct objectcore") +MAC_STAT(n_objecthead, uint64_t, 1, 'i', "N struct objecthead") +MAC_STAT(n_smf, uint64_t, 0, 'i', "N struct smf") +MAC_STAT(n_smf_frag, uint64_t, 0, 'i', "N small free smf") +MAC_STAT(n_smf_large, uint64_t, 0, 'i', "N large free smf") +MAC_STAT(n_vbe_conn, uint64_t, 0, 'i', "N struct vbe_conn") +MAC_STAT(n_wrk, uint64_t, 0, 'i', "N worker threads") +MAC_STAT(n_wrk_create, uint64_t, 0, 'a', "N worker threads created") +MAC_STAT(n_wrk_failed, uint64_t, 0, 'a', + "N worker threads not created") +MAC_STAT(n_wrk_max, uint64_t, 0, 'a', "N worker threads limited") +MAC_STAT(n_wrk_queue, uint64_t, 0, 'a', "N queued work requests") +MAC_STAT(n_wrk_overflow, uint64_t, 0, 'a', "N overflowed work requests") +MAC_STAT(n_wrk_drop, uint64_t, 0, 'a', "N dropped work requests") +MAC_STAT(n_backend, uint64_t, 0, 'i', "N backends") + +MAC_STAT(n_expired, uint64_t, 0, 'i', "N expired objects") +MAC_STAT(n_lru_nuked, uint64_t, 0, 'i', "N LRU nuked objects") +MAC_STAT(n_lru_saved, uint64_t, 0, 'i', "N LRU saved objects") +MAC_STAT(n_lru_moved, uint64_t, 0, 'i', "N LRU moved objects") +MAC_STAT(n_deathrow, uint64_t, 0, 'i', "N objects on deathrow") + +MAC_STAT(losthdr, uint64_t, 0, 'a', "HTTP header overflows") + +MAC_STAT(n_objsendfile, uint64_t, 0, 'a', "Objects sent with sendfile") +MAC_STAT(n_objwrite, uint64_t, 0, 'a', "Objects sent with write") +MAC_STAT(n_objoverflow, uint64_t, 1, 'a', + "Objects overflowing workspace") + +MAC_STAT(s_sess, uint64_t, 1, 'a', "Total Sessions") +MAC_STAT(s_req, uint64_t, 1, 'a', "Total Requests") +MAC_STAT(s_pipe, uint64_t, 1, 'a', "Total pipe") +MAC_STAT(s_pass, uint64_t, 1, 'a', "Total pass") +MAC_STAT(s_fetch, uint64_t, 1, 'a', "Total fetch") +MAC_STAT(s_hdrbytes, uint64_t, 1, 'a', "Total header bytes") +MAC_STAT(s_bodybytes, uint64_t, 1, 'a', "Total body bytes") + +MAC_STAT(sess_closed, uint64_t, 1, 'a', "Session Closed") +MAC_STAT(sess_pipeline, uint64_t, 1, 'a', "Session Pipeline") +MAC_STAT(sess_readahead, uint64_t, 1, 'a', "Session Read Ahead") +MAC_STAT(sess_linger, uint64_t, 1, 'a', "Session Linger") +MAC_STAT(sess_herd, uint64_t, 1, 'a', "Session herd") + +MAC_STAT(shm_records, uint64_t, 0, 'a', "SHM records") +MAC_STAT(shm_writes, uint64_t, 0, 'a', "SHM writes") +MAC_STAT(shm_flushes, uint64_t, 0, 'a', "SHM flushes due to overflow") +MAC_STAT(shm_cont, uint64_t, 0, 'a', "SHM MTX contention") +MAC_STAT(shm_cycles, uint64_t, 0, 'a', "SHM cycles through buffer") + +MAC_STAT(sm_nreq, uint64_t, 0, 'a', "allocator requests") +MAC_STAT(sm_nobj, uint64_t, 0, 'i', "outstanding allocations") +MAC_STAT(sm_balloc, uint64_t, 0, 'i', "bytes allocated") +MAC_STAT(sm_bfree, uint64_t, 0, 'i', "bytes free") + +MAC_STAT(sms_nreq, uint64_t, 0, 'a', "SMS allocator requests") +MAC_STAT(sms_nobj, uint64_t, 0, 'i', "SMS outstanding allocations") +MAC_STAT(sms_nbytes, uint64_t, 0, 'i', "SMS outstanding bytes") +MAC_STAT(sms_balloc, uint64_t, 0, 'i', "SMS bytes allocated") +MAC_STAT(sms_bfree, uint64_t, 0, 'i', "SMS bytes freed") + +MAC_STAT(backend_req, uint64_t, 0, 'a', "Backend requests made") + +MAC_STAT(n_vcl, uint64_t, 0, 'a', "N vcl total") +MAC_STAT(n_vcl_avail, uint64_t, 0, 'a', "N vcl available") +MAC_STAT(n_vcl_discard, uint64_t, 0, 'a', "N vcl discarded") + +MAC_STAT(n_purge, uint64_t, 0, 'i', "N total active purges") +MAC_STAT(n_purge_add, uint64_t, 0, 'a', "N new purges added") +MAC_STAT(n_purge_retire, uint64_t, 0, 'a', "N old purges deleted") +MAC_STAT(n_purge_obj_test, uint64_t, 0, 'a', "N objects tested") +MAC_STAT(n_purge_re_test, uint64_t, 0, 'a', "N regexps tested against") +MAC_STAT(n_purge_dups, uint64_t, 0, 'a', "N duplicate purges removed") + +MAC_STAT(hcb_nolock, uint64_t, 0, 'a', "HCB Lookups without lock") +MAC_STAT(hcb_lock, uint64_t, 0, 'a', "HCB Lookups with lock") +MAC_STAT(hcb_insert, uint64_t, 0, 'a', "HCB Inserts") + +MAC_STAT(esi_parse, uint64_t, 0, 'a', "Objects ESI parsed (unlock)") +MAC_STAT(esi_errors, uint64_t, 0, 'a', "ESI parse errors (unlock)") +MAC_STAT(accept_fail, uint64_t, 0, 'a', "Accept failures") +MAC_STAT(client_drop_late, uint64_t, 0, 'a', "Connection dropped late") +MAC_STAT(uptime, uint64_t, 0, 'a', "Client uptime") + +MAC_STAT(critbit_cooler, uint64_t, 0, 'i', "Objhdr's on cool list") + +#ifdef __MAC_STAT +#undef MAC_STAT +#undef __MAC_STAT +#endif + +#ifndef MAC_STAT_SMA +#define MAC_STAT_SMA(a, b, c, d, e) +#define __MAC_STAT_SMA +#endif + +MAC_STAT_SMA(sma_nreq, uint64_t, 0, 'a', "Allocator requests") +MAC_STAT_SMA(sma_nobj, uint64_t, 0, 'i', "Outstanding allocations") +MAC_STAT_SMA(sma_nbytes, uint64_t, 0, 'i', "Outstanding bytes") +MAC_STAT_SMA(sma_balloc, uint64_t, 0, 'i', "Bytes allocated") +MAC_STAT_SMA(sma_bfree, uint64_t, 0, 'i', "Bytes free") + +#ifdef __MAC_STAT_SMA +#undef MAC_STAT_SMA +#undef __MAC_STAT_SMA +#endif From phk at varnish-cache.org Tue Jun 8 09:55:14 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 11:55:14 +0200 Subject: r4931 - trunk/varnish-cache/bin/varnishtest Message-ID: Author: phk Date: 2010-06-08 11:55:14 +0200 (Tue, 08 Jun 2010) New Revision: 4931 Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c Log: Explicitly open the VSM Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-08 09:49:36 UTC (rev 4930) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-08 09:55:14 UTC (rev 4931) @@ -365,6 +365,7 @@ if (v->stats != NULL) VSL_Close(v->vd); (void)VSL_Log_Arg(v->vd, 'n', v->workdir); + AZ(VSL_Open(v->vd, 1)); v->stats = VSL_OpenStats(v->vd); } From phk at varnish-cache.org Tue Jun 8 10:01:46 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 12:01:46 +0200 Subject: r4932 - in trunk/varnish-cache: bin/varnishd bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishsizes include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 12:01:46 +0200 (Tue, 08 Jun 2010) New Revision: 4932 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/bin/varnishhist/varnishhist.c trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/bin/varnishncsa/varnishncsa.c trunk/varnish-cache/bin/varnishreplay/varnishreplay.c trunk/varnish-cache/bin/varnishsizes/varnishsizes.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/include/vsc.h trunk/varnish-cache/include/vsc_fields.h trunk/varnish-cache/include/vsl.h trunk/varnish-cache/lib/libvarnishapi/vsl_log.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Log: More wanton renaming Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishd/cache.h 2010-06-08 10:01:46 UTC (rev 4932) @@ -194,11 +194,11 @@ #define L0(n) #define L1(n) int n; -#define MAC_STAT(n, t, l, f, e) L##l(n) +#define VSC_F_MAIN(n, t, l, f, e) L##l(n) struct dstat { #include "vsc_fields.h" }; -#undef MAC_STAT +#undef VSC_F_MAIN #undef L0 #undef L1 @@ -638,9 +638,9 @@ /* cache_shmlog.c */ void VSL_Init(void); #ifdef VSL_ENDMARKER -void VSL(enum shmlogtag tag, int id, const char *fmt, ...); -void WSLR(struct worker *w, enum shmlogtag tag, int id, txt t); -void WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...); +void VSL(enum vsl_tag tag, int id, const char *fmt, ...); +void WSLR(struct worker *w, enum vsl_tag tag, int id, txt t); +void WSL(struct worker *w, enum vsl_tag tag, int id, const char *fmt, ...); void WSL_Flush(struct worker *w, int overflow); #define DSL(flag, tag, id, ...) \ Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -64,14 +64,14 @@ LOGMTX2(ax, HTTP_HDR_FIRST, Header), \ } -static const enum shmlogtag logmtx[][HTTP_HDR_FIRST + 1] = { +static const enum vsl_tag logmtx[][HTTP_HDR_FIRST + 1] = { [HTTP_Rx] = LOGMTX1(Rx), [HTTP_Tx] = LOGMTX1(Tx), [HTTP_Obj] = LOGMTX1(Obj) }; /*lint -restore */ -static enum shmlogtag +static enum vsl_tag http2shmlog(const struct http *hp, int t) { Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -96,9 +96,9 @@ Lck_AssertHeld(&wstat_mtx); #define L0(n) #define L1(n) (VSL_stats->n += w->stats.n) -#define MAC_STAT(n, t, l, f, d) L##l(n); +#define VSC_F_MAIN(n, t, l, f, d) L##l(n); #include "vsc_fields.h" -#undef MAC_STAT +#undef VSC_F_MAIN #undef L0 #undef L1 memset(&w->stats, 0, sizeof w->stats); Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -53,7 +53,7 @@ /*--------------------------------------------------------------------*/ static inline void -vsl_hdr(enum shmlogtag tag, uint32_t *p, unsigned len, unsigned id) +vsl_hdr(enum vsl_tag tag, uint32_t *p, unsigned len, unsigned id) { assert(((uintptr_t)p & 0x3) == 0); @@ -121,7 +121,7 @@ */ static void -VSLR(enum shmlogtag tag, int id, const char *b, unsigned len) +VSLR(enum vsl_tag tag, int id, const char *b, unsigned len) { uint32_t *p; unsigned mlen; @@ -141,7 +141,7 @@ /*--------------------------------------------------------------------*/ void -VSL(enum shmlogtag tag, int id, const char *fmt, ...) +VSL(enum vsl_tag tag, int id, const char *fmt, ...) { va_list ap; unsigned n, mlen = params->shm_reclen; @@ -191,7 +191,7 @@ /*--------------------------------------------------------------------*/ void -WSLR(struct worker *w, enum shmlogtag tag, int id, txt t) +WSLR(struct worker *w, enum vsl_tag tag, int id, txt t) { unsigned l, mlen; @@ -223,7 +223,7 @@ /*--------------------------------------------------------------------*/ void -WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...) +WSL(struct worker *w, enum vsl_tag tag, int id, const char *fmt, ...) { va_list ap; char *p; Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -81,11 +81,11 @@ (void)priv; AN(VSL_stats); -#define MAC_STAT(n, t, l, f, d) \ +#define VSC_F_MAIN(n, t, l, f, d) \ if (VSL_stats->n != 0) \ cli_out(cli, "%12ju %s\n", (VSL_stats->n), d); #include "vsc_fields.h" -#undef MAC_STAT +#undef VSC_F_MAIN } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -293,7 +293,7 @@ *pp = *params; params = pp; - vsl_log_start = mgt_SHM_Alloc(s1, VSM_CLASS_LOG, "", ""); + vsl_log_start = mgt_SHM_Alloc(s1, VSL_CLASS, "", ""); AN(vsl_log_start); vsl_log_end = (void*)((uint8_t *)vsl_log_start + s1); vsl_log_nxt = vsl_log_start + 1; Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -148,7 +148,7 @@ } static int -h_hist(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, +h_hist(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) { double b; Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -75,7 +75,7 @@ static struct vsb *ob[65536]; static unsigned char flg[65536]; -static enum shmlogtag last[65536]; +static enum vsl_tag last[65536]; #define F_INVCL (1 << 0) #define F_MATCH (1 << 1) @@ -112,7 +112,7 @@ } static int -h_order(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, +h_order(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) { char type; Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -178,7 +178,7 @@ } static int -collect_backend(struct logline *lp, enum shmlogtag tag, unsigned spec, +collect_backend(struct logline *lp, enum vsl_tag tag, unsigned spec, const char *ptr, unsigned len) { const char *end, *next; @@ -261,7 +261,7 @@ } static int -collect_client(struct logline *lp, enum shmlogtag tag, unsigned spec, +collect_client(struct logline *lp, enum vsl_tag tag, unsigned spec, const char *ptr, unsigned len) { const char *end, *next; @@ -353,7 +353,7 @@ } static int -h_ncsa(void *priv, enum shmlogtag tag, unsigned fd, +h_ncsa(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) { struct logline *lp; Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -97,7 +97,7 @@ */ struct message { - enum shmlogtag tag; + enum vsl_tag tag; size_t len; char *ptr; VSTAILQ_ENTRY(message) list; @@ -500,7 +500,7 @@ char space[1] = " ", crlf[2] = "\r\n"; struct replay_thread *thr = arg; struct message *msg; - enum shmlogtag tag; + enum vsl_tag tag; size_t len; char *ptr; const char *next; @@ -642,7 +642,7 @@ } static int -gen_traffic(void *priv, enum shmlogtag tag, unsigned fd, +gen_traffic(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) { struct replay_thread *thr; Modified: trunk/varnish-cache/bin/varnishsizes/varnishsizes.c =================================================================== --- trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -148,7 +148,7 @@ } static int -h_hist(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, +h_hist(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) { double b; Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-08 10:01:46 UTC (rev 4932) @@ -116,7 +116,7 @@ /* shmlog.c */ -typedef int vsl_handler(void *priv, enum shmlogtag tag, unsigned fd, +typedef int vsl_handler(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr); #define VSL_S_CLIENT (1 << 0) #define VSL_S_BACKEND (1 << 1) Modified: trunk/varnish-cache/include/vsc.h =================================================================== --- trunk/varnish-cache/include/vsc.h 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/include/vsc.h 2010-06-08 10:01:46 UTC (rev 4932) @@ -36,15 +36,15 @@ #define VSC_TYPE_MAIN "" struct vsc_main { -#define MAC_STAT(n, t, l, f, e) t n; +#define VSC_F_MAIN(n, t, l, f, e) t n; #include "vsc_fields.h" -#undef MAC_STAT +#undef VSC_F_MAIN }; #define VSC_TYPE_SMA "SMA" struct vsc_sma { -#define MAC_STAT_SMA(n, t, l, f, e) t n; +#define VSC_F_SMA(n, t, l, f, e) t n; #include "vsc_fields.h" -#undef MAC_STAT_SMA +#undef VSC_F_SMA }; Modified: trunk/varnish-cache/include/vsc_fields.h =================================================================== --- trunk/varnish-cache/include/vsc_fields.h 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/include/vsc_fields.h 2010-06-08 10:01:46 UTC (rev 4932) @@ -32,146 +32,147 @@ * stats structure. */ -#ifndef MAC_STAT -#define MAC_STAT(a, b, c, d, e) -#define __MAC_STAT +#ifndef VSC_F_MAIN +#define VSC_F_MAIN(a, b, c, d, e) +#define __VSC_F_MAIN #endif -MAC_STAT(client_conn, uint64_t, 0, 'a', "Client connections accepted") -MAC_STAT(client_drop, uint64_t, 0, 'a', "Connection dropped, no sess/wrk") -MAC_STAT(client_req, uint64_t, 1, 'a', "Client requests received") +VSC_F_MAIN(client_conn, uint64_t, 0, 'a', "Client connections accepted") +VSC_F_MAIN(client_drop, uint64_t, 0, 'a', + "Connection dropped, no sess/wrk") +VSC_F_MAIN(client_req, uint64_t, 1, 'a', "Client requests received") -MAC_STAT(cache_hit, uint64_t, 1, 'a', "Cache hits") -MAC_STAT(cache_hitpass, uint64_t, 1, 'a', "Cache hits for pass") -MAC_STAT(cache_miss, uint64_t, 1, 'a', "Cache misses") +VSC_F_MAIN(cache_hit, uint64_t, 1, 'a', "Cache hits") +VSC_F_MAIN(cache_hitpass, uint64_t, 1, 'a', "Cache hits for pass") +VSC_F_MAIN(cache_miss, uint64_t, 1, 'a', "Cache misses") -MAC_STAT(backend_conn, uint64_t, 0, 'a', "Backend conn. success") -MAC_STAT(backend_unhealthy, uint64_t, 0, 'a', "Backend conn. not attempted") -MAC_STAT(backend_busy, uint64_t, 0, 'a', "Backend conn. too many") -MAC_STAT(backend_fail, uint64_t, 0, 'a', "Backend conn. failures") -MAC_STAT(backend_reuse, uint64_t, 0, 'a', "Backend conn. reuses") -MAC_STAT(backend_toolate, uint64_t, 0, 'a', "Backend conn. was closed") -MAC_STAT(backend_recycle, uint64_t, 0, 'a', "Backend conn. recycles") -MAC_STAT(backend_unused, uint64_t, 0, 'a', "Backend conn. unused") +VSC_F_MAIN(backend_conn, uint64_t, 0, 'a', "Backend conn. success") +VSC_F_MAIN(backend_unhealthy, uint64_t, 0, 'a', "Backend conn. not attempted") +VSC_F_MAIN(backend_busy, uint64_t, 0, 'a', "Backend conn. too many") +VSC_F_MAIN(backend_fail, uint64_t, 0, 'a', "Backend conn. failures") +VSC_F_MAIN(backend_reuse, uint64_t, 0, 'a', "Backend conn. reuses") +VSC_F_MAIN(backend_toolate, uint64_t, 0, 'a', "Backend conn. was closed") +VSC_F_MAIN(backend_recycle, uint64_t, 0, 'a', "Backend conn. recycles") +VSC_F_MAIN(backend_unused, uint64_t, 0, 'a', "Backend conn. unused") -MAC_STAT(fetch_head, uint64_t, 1, 'a', "Fetch head") -MAC_STAT(fetch_length, uint64_t, 1, 'a', "Fetch with Length") -MAC_STAT(fetch_chunked, uint64_t, 1, 'a', "Fetch chunked") -MAC_STAT(fetch_eof, uint64_t, 1, 'a', "Fetch EOF") -MAC_STAT(fetch_bad, uint64_t, 1, 'a', "Fetch had bad headers") -MAC_STAT(fetch_close, uint64_t, 1, 'a', "Fetch wanted close") -MAC_STAT(fetch_oldhttp, uint64_t, 1, 'a', "Fetch pre HTTP/1.1 closed") -MAC_STAT(fetch_zero, uint64_t, 1, 'a', "Fetch zero len") -MAC_STAT(fetch_failed, uint64_t, 1, 'a', "Fetch failed") +VSC_F_MAIN(fetch_head, uint64_t, 1, 'a', "Fetch head") +VSC_F_MAIN(fetch_length, uint64_t, 1, 'a', "Fetch with Length") +VSC_F_MAIN(fetch_chunked, uint64_t, 1, 'a', "Fetch chunked") +VSC_F_MAIN(fetch_eof, uint64_t, 1, 'a', "Fetch EOF") +VSC_F_MAIN(fetch_bad, uint64_t, 1, 'a', "Fetch had bad headers") +VSC_F_MAIN(fetch_close, uint64_t, 1, 'a', "Fetch wanted close") +VSC_F_MAIN(fetch_oldhttp, uint64_t, 1, 'a', "Fetch pre HTTP/1.1 closed") +VSC_F_MAIN(fetch_zero, uint64_t, 1, 'a', "Fetch zero len") +VSC_F_MAIN(fetch_failed, uint64_t, 1, 'a', "Fetch failed") -MAC_STAT(n_sess_mem, uint64_t, 0, 'i', "N struct sess_mem") -MAC_STAT(n_sess, uint64_t, 0, 'i', "N struct sess") -MAC_STAT(n_object, uint64_t, 1, 'i', "N struct object") -MAC_STAT(n_vampireobject, uint64_t, 1, 'i', "N unresurrected objects") -MAC_STAT(n_objectcore, uint64_t, 1, 'i', "N struct objectcore") -MAC_STAT(n_objecthead, uint64_t, 1, 'i', "N struct objecthead") -MAC_STAT(n_smf, uint64_t, 0, 'i', "N struct smf") -MAC_STAT(n_smf_frag, uint64_t, 0, 'i', "N small free smf") -MAC_STAT(n_smf_large, uint64_t, 0, 'i', "N large free smf") -MAC_STAT(n_vbe_conn, uint64_t, 0, 'i', "N struct vbe_conn") -MAC_STAT(n_wrk, uint64_t, 0, 'i', "N worker threads") -MAC_STAT(n_wrk_create, uint64_t, 0, 'a', "N worker threads created") -MAC_STAT(n_wrk_failed, uint64_t, 0, 'a', +VSC_F_MAIN(n_sess_mem, uint64_t, 0, 'i', "N struct sess_mem") +VSC_F_MAIN(n_sess, uint64_t, 0, 'i', "N struct sess") +VSC_F_MAIN(n_object, uint64_t, 1, 'i', "N struct object") +VSC_F_MAIN(n_vampireobject, uint64_t, 1, 'i', "N unresurrected objects") +VSC_F_MAIN(n_objectcore, uint64_t, 1, 'i', "N struct objectcore") +VSC_F_MAIN(n_objecthead, uint64_t, 1, 'i', "N struct objecthead") +VSC_F_MAIN(n_smf, uint64_t, 0, 'i', "N struct smf") +VSC_F_MAIN(n_smf_frag, uint64_t, 0, 'i', "N small free smf") +VSC_F_MAIN(n_smf_large, uint64_t, 0, 'i', "N large free smf") +VSC_F_MAIN(n_vbe_conn, uint64_t, 0, 'i', "N struct vbe_conn") +VSC_F_MAIN(n_wrk, uint64_t, 0, 'i', "N worker threads") +VSC_F_MAIN(n_wrk_create, uint64_t, 0, 'a', "N worker threads created") +VSC_F_MAIN(n_wrk_failed, uint64_t, 0, 'a', "N worker threads not created") -MAC_STAT(n_wrk_max, uint64_t, 0, 'a', "N worker threads limited") -MAC_STAT(n_wrk_queue, uint64_t, 0, 'a', "N queued work requests") -MAC_STAT(n_wrk_overflow, uint64_t, 0, 'a', "N overflowed work requests") -MAC_STAT(n_wrk_drop, uint64_t, 0, 'a', "N dropped work requests") -MAC_STAT(n_backend, uint64_t, 0, 'i', "N backends") +VSC_F_MAIN(n_wrk_max, uint64_t, 0, 'a', "N worker threads limited") +VSC_F_MAIN(n_wrk_queue, uint64_t, 0, 'a', "N queued work requests") +VSC_F_MAIN(n_wrk_overflow, uint64_t, 0, 'a', "N overflowed work requests") +VSC_F_MAIN(n_wrk_drop, uint64_t, 0, 'a', "N dropped work requests") +VSC_F_MAIN(n_backend, uint64_t, 0, 'i', "N backends") -MAC_STAT(n_expired, uint64_t, 0, 'i', "N expired objects") -MAC_STAT(n_lru_nuked, uint64_t, 0, 'i', "N LRU nuked objects") -MAC_STAT(n_lru_saved, uint64_t, 0, 'i', "N LRU saved objects") -MAC_STAT(n_lru_moved, uint64_t, 0, 'i', "N LRU moved objects") -MAC_STAT(n_deathrow, uint64_t, 0, 'i', "N objects on deathrow") +VSC_F_MAIN(n_expired, uint64_t, 0, 'i', "N expired objects") +VSC_F_MAIN(n_lru_nuked, uint64_t, 0, 'i', "N LRU nuked objects") +VSC_F_MAIN(n_lru_saved, uint64_t, 0, 'i', "N LRU saved objects") +VSC_F_MAIN(n_lru_moved, uint64_t, 0, 'i', "N LRU moved objects") +VSC_F_MAIN(n_deathrow, uint64_t, 0, 'i', "N objects on deathrow") -MAC_STAT(losthdr, uint64_t, 0, 'a', "HTTP header overflows") +VSC_F_MAIN(losthdr, uint64_t, 0, 'a', "HTTP header overflows") -MAC_STAT(n_objsendfile, uint64_t, 0, 'a', "Objects sent with sendfile") -MAC_STAT(n_objwrite, uint64_t, 0, 'a', "Objects sent with write") -MAC_STAT(n_objoverflow, uint64_t, 1, 'a', +VSC_F_MAIN(n_objsendfile, uint64_t, 0, 'a', "Objects sent with sendfile") +VSC_F_MAIN(n_objwrite, uint64_t, 0, 'a', "Objects sent with write") +VSC_F_MAIN(n_objoverflow, uint64_t, 1, 'a', "Objects overflowing workspace") -MAC_STAT(s_sess, uint64_t, 1, 'a', "Total Sessions") -MAC_STAT(s_req, uint64_t, 1, 'a', "Total Requests") -MAC_STAT(s_pipe, uint64_t, 1, 'a', "Total pipe") -MAC_STAT(s_pass, uint64_t, 1, 'a', "Total pass") -MAC_STAT(s_fetch, uint64_t, 1, 'a', "Total fetch") -MAC_STAT(s_hdrbytes, uint64_t, 1, 'a', "Total header bytes") -MAC_STAT(s_bodybytes, uint64_t, 1, 'a', "Total body bytes") +VSC_F_MAIN(s_sess, uint64_t, 1, 'a', "Total Sessions") +VSC_F_MAIN(s_req, uint64_t, 1, 'a', "Total Requests") +VSC_F_MAIN(s_pipe, uint64_t, 1, 'a', "Total pipe") +VSC_F_MAIN(s_pass, uint64_t, 1, 'a', "Total pass") +VSC_F_MAIN(s_fetch, uint64_t, 1, 'a', "Total fetch") +VSC_F_MAIN(s_hdrbytes, uint64_t, 1, 'a', "Total header bytes") +VSC_F_MAIN(s_bodybytes, uint64_t, 1, 'a', "Total body bytes") -MAC_STAT(sess_closed, uint64_t, 1, 'a', "Session Closed") -MAC_STAT(sess_pipeline, uint64_t, 1, 'a', "Session Pipeline") -MAC_STAT(sess_readahead, uint64_t, 1, 'a', "Session Read Ahead") -MAC_STAT(sess_linger, uint64_t, 1, 'a', "Session Linger") -MAC_STAT(sess_herd, uint64_t, 1, 'a', "Session herd") +VSC_F_MAIN(sess_closed, uint64_t, 1, 'a', "Session Closed") +VSC_F_MAIN(sess_pipeline, uint64_t, 1, 'a', "Session Pipeline") +VSC_F_MAIN(sess_readahead, uint64_t, 1, 'a', "Session Read Ahead") +VSC_F_MAIN(sess_linger, uint64_t, 1, 'a', "Session Linger") +VSC_F_MAIN(sess_herd, uint64_t, 1, 'a', "Session herd") -MAC_STAT(shm_records, uint64_t, 0, 'a', "SHM records") -MAC_STAT(shm_writes, uint64_t, 0, 'a', "SHM writes") -MAC_STAT(shm_flushes, uint64_t, 0, 'a', "SHM flushes due to overflow") -MAC_STAT(shm_cont, uint64_t, 0, 'a', "SHM MTX contention") -MAC_STAT(shm_cycles, uint64_t, 0, 'a', "SHM cycles through buffer") +VSC_F_MAIN(shm_records, uint64_t, 0, 'a', "SHM records") +VSC_F_MAIN(shm_writes, uint64_t, 0, 'a', "SHM writes") +VSC_F_MAIN(shm_flushes, uint64_t, 0, 'a', "SHM flushes due to overflow") +VSC_F_MAIN(shm_cont, uint64_t, 0, 'a', "SHM MTX contention") +VSC_F_MAIN(shm_cycles, uint64_t, 0, 'a', "SHM cycles through buffer") -MAC_STAT(sm_nreq, uint64_t, 0, 'a', "allocator requests") -MAC_STAT(sm_nobj, uint64_t, 0, 'i', "outstanding allocations") -MAC_STAT(sm_balloc, uint64_t, 0, 'i', "bytes allocated") -MAC_STAT(sm_bfree, uint64_t, 0, 'i', "bytes free") +VSC_F_MAIN(sm_nreq, uint64_t, 0, 'a', "allocator requests") +VSC_F_MAIN(sm_nobj, uint64_t, 0, 'i', "outstanding allocations") +VSC_F_MAIN(sm_balloc, uint64_t, 0, 'i', "bytes allocated") +VSC_F_MAIN(sm_bfree, uint64_t, 0, 'i', "bytes free") -MAC_STAT(sms_nreq, uint64_t, 0, 'a', "SMS allocator requests") -MAC_STAT(sms_nobj, uint64_t, 0, 'i', "SMS outstanding allocations") -MAC_STAT(sms_nbytes, uint64_t, 0, 'i', "SMS outstanding bytes") -MAC_STAT(sms_balloc, uint64_t, 0, 'i', "SMS bytes allocated") -MAC_STAT(sms_bfree, uint64_t, 0, 'i', "SMS bytes freed") +VSC_F_MAIN(sms_nreq, uint64_t, 0, 'a', "SMS allocator requests") +VSC_F_MAIN(sms_nobj, uint64_t, 0, 'i', "SMS outstanding allocations") +VSC_F_MAIN(sms_nbytes, uint64_t, 0, 'i', "SMS outstanding bytes") +VSC_F_MAIN(sms_balloc, uint64_t, 0, 'i', "SMS bytes allocated") +VSC_F_MAIN(sms_bfree, uint64_t, 0, 'i', "SMS bytes freed") -MAC_STAT(backend_req, uint64_t, 0, 'a', "Backend requests made") +VSC_F_MAIN(backend_req, uint64_t, 0, 'a', "Backend requests made") -MAC_STAT(n_vcl, uint64_t, 0, 'a', "N vcl total") -MAC_STAT(n_vcl_avail, uint64_t, 0, 'a', "N vcl available") -MAC_STAT(n_vcl_discard, uint64_t, 0, 'a', "N vcl discarded") +VSC_F_MAIN(n_vcl, uint64_t, 0, 'a', "N vcl total") +VSC_F_MAIN(n_vcl_avail, uint64_t, 0, 'a', "N vcl available") +VSC_F_MAIN(n_vcl_discard, uint64_t, 0, 'a', "N vcl discarded") -MAC_STAT(n_purge, uint64_t, 0, 'i', "N total active purges") -MAC_STAT(n_purge_add, uint64_t, 0, 'a', "N new purges added") -MAC_STAT(n_purge_retire, uint64_t, 0, 'a', "N old purges deleted") -MAC_STAT(n_purge_obj_test, uint64_t, 0, 'a', "N objects tested") -MAC_STAT(n_purge_re_test, uint64_t, 0, 'a', "N regexps tested against") -MAC_STAT(n_purge_dups, uint64_t, 0, 'a', "N duplicate purges removed") +VSC_F_MAIN(n_purge, uint64_t, 0, 'i', "N total active purges") +VSC_F_MAIN(n_purge_add, uint64_t, 0, 'a', "N new purges added") +VSC_F_MAIN(n_purge_retire, uint64_t, 0, 'a', "N old purges deleted") +VSC_F_MAIN(n_purge_obj_test, uint64_t, 0, 'a', "N objects tested") +VSC_F_MAIN(n_purge_re_test, uint64_t, 0, 'a', "N regexps tested against") +VSC_F_MAIN(n_purge_dups, uint64_t, 0, 'a', "N duplicate purges removed") -MAC_STAT(hcb_nolock, uint64_t, 0, 'a', "HCB Lookups without lock") -MAC_STAT(hcb_lock, uint64_t, 0, 'a', "HCB Lookups with lock") -MAC_STAT(hcb_insert, uint64_t, 0, 'a', "HCB Inserts") +VSC_F_MAIN(hcb_nolock, uint64_t, 0, 'a', "HCB Lookups without lock") +VSC_F_MAIN(hcb_lock, uint64_t, 0, 'a', "HCB Lookups with lock") +VSC_F_MAIN(hcb_insert, uint64_t, 0, 'a', "HCB Inserts") -MAC_STAT(esi_parse, uint64_t, 0, 'a', "Objects ESI parsed (unlock)") -MAC_STAT(esi_errors, uint64_t, 0, 'a', "ESI parse errors (unlock)") -MAC_STAT(accept_fail, uint64_t, 0, 'a', "Accept failures") -MAC_STAT(client_drop_late, uint64_t, 0, 'a', "Connection dropped late") -MAC_STAT(uptime, uint64_t, 0, 'a', "Client uptime") +VSC_F_MAIN(esi_parse, uint64_t, 0, 'a', "Objects ESI parsed (unlock)") +VSC_F_MAIN(esi_errors, uint64_t, 0, 'a', "ESI parse errors (unlock)") +VSC_F_MAIN(accept_fail, uint64_t, 0, 'a', "Accept failures") +VSC_F_MAIN(client_drop_late, uint64_t, 0, 'a', "Connection dropped late") +VSC_F_MAIN(uptime, uint64_t, 0, 'a', "Client uptime") -MAC_STAT(critbit_cooler, uint64_t, 0, 'i', "Objhdr's on cool list") +VSC_F_MAIN(critbit_cooler, uint64_t, 0, 'i', "Objhdr's on cool list") -#ifdef __MAC_STAT -#undef MAC_STAT -#undef __MAC_STAT +#ifdef __VSC_F_MAIN +#undef VSC_F_MAIN +#undef __VSC_F_MAIN #endif -#ifndef MAC_STAT_SMA -#define MAC_STAT_SMA(a, b, c, d, e) -#define __MAC_STAT_SMA +#ifndef VSC_F_SMA +#define VSC_F_SMA(a, b, c, d, e) +#define __VSC_F_SMA #endif -MAC_STAT_SMA(sma_nreq, uint64_t, 0, 'a', "Allocator requests") -MAC_STAT_SMA(sma_nobj, uint64_t, 0, 'i', "Outstanding allocations") -MAC_STAT_SMA(sma_nbytes, uint64_t, 0, 'i', "Outstanding bytes") -MAC_STAT_SMA(sma_balloc, uint64_t, 0, 'i', "Bytes allocated") -MAC_STAT_SMA(sma_bfree, uint64_t, 0, 'i', "Bytes free") +VSC_F_SMA(sma_nreq, uint64_t, 0, 'a', "Allocator requests") +VSC_F_SMA(sma_nobj, uint64_t, 0, 'i', "Outstanding allocations") +VSC_F_SMA(sma_nbytes, uint64_t, 0, 'i', "Outstanding bytes") +VSC_F_SMA(sma_balloc, uint64_t, 0, 'i', "Bytes allocated") +VSC_F_SMA(sma_bfree, uint64_t, 0, 'i', "Bytes free") -#ifdef __MAC_STAT_SMA -#undef MAC_STAT_SMA -#undef __MAC_STAT_SMA +#ifdef __VSC_F_SMA +#undef VSC_F_SMA +#undef __VSC_F_SMA #endif Modified: trunk/varnish-cache/include/vsl.h =================================================================== --- trunk/varnish-cache/include/vsl.h 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/include/vsl.h 2010-06-08 10:01:46 UTC (rev 4932) @@ -36,7 +36,7 @@ #ifndef SHMLOG_H_INCLUDED #define SHMLOG_H_INCLUDED -#define VSM_CLASS_LOG "Log" +#define VSL_CLASS "Log" /* * Shared memory log format @@ -67,7 +67,7 @@ * The identifiers in shmlogtag are "SLT_" + XML tag. A script may be run * on this file to extract the table rather than handcode it */ -enum shmlogtag { +enum vsl_tag { #define SLTM(foo) SLT_##foo, #include "vsl_tags.h" #undef SLTM Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -230,7 +230,7 @@ /*--------------------------------------------------------------------*/ int -VSL_H_Print(void *priv, enum shmlogtag tag, unsigned fd, unsigned len, +VSL_H_Print(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr) { FILE *fo = priv; @@ -265,7 +265,7 @@ struct vsm_chunk *sha; CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - sha = vsl_find_alloc(vd, VSM_CLASS_LOG, "", ""); + sha = vsl_find_alloc(vd, VSL_CLASS, "", ""); assert(sha != NULL); vd->log_start = VSM_PTR(sha); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 09:55:14 UTC (rev 4931) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 10:01:46 UTC (rev 4932) @@ -114,7 +114,7 @@ sp.class = ""; sp.ident = ""; -#define MAC_STAT(nn, tt, ll, ff, dd) \ +#define VSC_F_MAIN(nn, tt, ll, ff, dd) \ sp.name = #nn; \ sp.fmt = #tt; \ sp.flag = ff; \ @@ -124,7 +124,7 @@ if (i) \ return(i); #include "vsc_fields.h" -#undef MAC_STAT +#undef VSC_F_MAIN return (0); } @@ -138,7 +138,7 @@ sp.class = VSC_TYPE_SMA; sp.ident = sha->ident; -#define MAC_STAT_SMA(nn, tt, ll, ff, dd) \ +#define VSC_F_SMA(nn, tt, ll, ff, dd) \ sp.name = #nn; \ sp.fmt = #tt; \ sp.flag = ff; \ @@ -148,7 +148,7 @@ if (i) \ return(i); #include "vsc_fields.h" -#undef MAC_STAT_SMA +#undef VSC_F_SMA return (0); } From phk at varnish-cache.org Tue Jun 8 10:15:00 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 12:15:00 +0200 Subject: r4933 - in trunk/varnish-cache: bin/varnishadm bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishsizes bin/varnishstat bin/varnishtest bin/varnishtop include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 12:15:00 +0200 (Tue, 08 Jun 2010) New Revision: 4933 Added: trunk/varnish-cache/lib/libvarnishapi/vsm.c Removed: trunk/varnish-cache/lib/libvarnishapi/vsl.c Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c trunk/varnish-cache/bin/varnishhist/varnishhist.c trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/bin/varnishncsa/varnishncsa.c trunk/varnish-cache/bin/varnishreplay/varnishreplay.c trunk/varnish-cache/bin/varnishsizes/varnishsizes.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishstat/varnishstat.h trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/bin/varnishtop/varnishtop.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/Makefile.am trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c trunk/varnish-cache/lib/libvarnishapi/vsl_log.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c trunk/varnish-cache/lib/libvarnishapi/vslapi.h Log: Wanton renaming in libvarnishapi Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -216,7 +216,7 @@ const char *T_arg = NULL; const char *S_arg = NULL; const char *n_arg = NULL; - struct VSL_data *vsd; + struct VSM_data *vsd; char *p; int opt, sock; @@ -243,17 +243,17 @@ argv += optind; if (n_arg != NULL) { - vsd = VSL_New(); + vsd = VSM_New(); assert(VSL_Log_Arg(vsd, 'n', n_arg)); - if (!VSL_Open(vsd, 1)) { + if (!VSM_Open(vsd, 1)) { if (T_arg == NULL) { - p = VSL_Find_Alloc(vsd, "Arg", "-T", "", NULL); + p = VSM_Find_Chunk(vsd, "Arg", "-T", "", NULL); if (p != NULL) { T_arg = strdup(p); } } if (S_arg == NULL) { - p = VSL_Find_Alloc(vsd, "Arg", "-S", "", NULL); + p = VSM_Find_Chunk(vsd, "Arg", "-S", "", NULL); if (p != NULL) { S_arg = strdup(p); } Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -96,7 +96,7 @@ }; static void -update(struct VSL_data *vd) +update(struct VSM_data *vd) { int w = COLS / HIST_RANGE; int n = w * HIST_RANGE; @@ -116,7 +116,7 @@ mvprintw(LINES - 1, w * i, "|1e%d", j); } - mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd)); + mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd)); /* count our flock */ for (i = 0; i < n; ++i) @@ -224,7 +224,7 @@ static void * accumulate_thread(void *arg) { - struct VSL_data *vd = arg; + struct VSM_data *vd = arg; int i; for (;;) { @@ -238,7 +238,7 @@ } static void -do_curses(struct VSL_data *vd) +do_curses(struct VSM_data *vd) { pthread_t thr; int ch; @@ -319,9 +319,9 @@ main(int argc, char **argv) { int o; - struct VSL_data *vd; + struct VSM_data *vd; - vd = VSL_New(); + vd = VSM_New(); while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) { switch (o) { @@ -338,7 +338,7 @@ } } - if (VSL_OpenLog(vd)) + if (VSM_OpenLog(vd)) exit(1); log_ten = log(10.0); Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -195,7 +195,7 @@ } static void -do_order(struct VSL_data *vd, int argc, char * const *argv) +do_order(struct VSM_data *vd, int argc, char * const *argv) { int i; const char *error; @@ -268,7 +268,7 @@ } static void -do_write(struct VSL_data *vd, const char *w_arg, int a_flag) +do_write(struct VSM_data *vd, const char *w_arg, int a_flag) { int fd, i, l; uint32_t *p; @@ -316,9 +316,9 @@ const char *P_arg = NULL; const char *w_arg = NULL; struct pidfh *pfh = NULL; - struct VSL_data *vd; + struct VSM_data *vd; - vd = VSL_New(); + vd = VSM_New(); while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDoP:uVw:")) != -1) { switch (c) { @@ -361,7 +361,7 @@ if (o_flag && w_arg != NULL) usage(); - if (VSL_OpenLog(vd)) + if (VSM_OpenLog(vd)) exit(1); if (P_arg && (pfh = vpf_open(P_arg, 0644, NULL)) == NULL) { Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -524,10 +524,10 @@ const char *P_arg = NULL; const char *w_arg = NULL; struct pidfh *pfh = NULL; - struct VSL_data *vd; + struct VSM_data *vd; FILE *of; - vd = VSL_New(); + vd = VSM_New(); while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDP:Vw:f")) != -1) { switch (c) { @@ -565,7 +565,7 @@ VSL_Log_Arg(vd, 'c', optarg); - if (VSL_OpenLog(vd)) + if (VSM_OpenLog(vd)) exit(1); if (P_arg && (pfh = vpf_open(P_arg, 0644, NULL)) == NULL) { Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -717,10 +717,10 @@ main(int argc, char *argv[]) { int c; - struct VSL_data *vd; + struct VSM_data *vd; const char *address = NULL; - vd = VSL_New(); + vd = VSM_New(); debug = 0; VSL_Log_Arg(vd, 'c', NULL); @@ -743,7 +743,7 @@ usage(); } - if (VSL_OpenLog(vd)) + if (VSM_OpenLog(vd)) exit(1); addr_info = init_connection(address); Modified: trunk/varnish-cache/bin/varnishsizes/varnishsizes.c =================================================================== --- trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -96,7 +96,7 @@ }; static void -update(struct VSL_data *vd) +update(struct VSM_data *vd) { int w = COLS / HIST_RANGE; int n = w * HIST_RANGE; @@ -116,7 +116,7 @@ mvprintw(LINES - 1, w * i, "|1e%d", j); } - mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd)); + mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd)); /* count our flock */ for (i = 0; i < n; ++i) @@ -225,7 +225,7 @@ static void * accumulate_thread(void *arg) { - struct VSL_data *vd = arg; + struct VSM_data *vd = arg; int i; for (;;) { @@ -239,7 +239,7 @@ } static void -do_curses(struct VSL_data *vd) +do_curses(struct VSM_data *vd) { pthread_t thr; int ch; @@ -320,9 +320,9 @@ main(int argc, char **argv) { int o; - struct VSL_data *vd; + struct VSM_data *vd; - vd = VSL_New(); + vd = VSM_New(); while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) { switch (o) { @@ -339,7 +339,7 @@ } } - if (VSL_OpenLog(vd)) + if (VSM_OpenLog(vd)) exit(1); log_ten = log(10.0); Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -74,7 +74,7 @@ } static void -do_xml(const struct VSL_data *vd) +do_xml(const struct VSM_data *vd) { char time_stamp[20]; time_t now; @@ -121,7 +121,7 @@ } static void -do_once(const struct VSL_data *vd, const struct vsc_main *VSL_stats) +do_once(const struct VSM_data *vd, const struct vsc_main *VSL_stats) { struct once_priv op; @@ -153,7 +153,7 @@ } static void -list_fields(const struct VSL_data *vd) +list_fields(const struct VSM_data *vd) { fprintf(stderr, "Varnishstat -f option fields:\n"); fprintf(stderr, "Field name Description\n"); @@ -192,11 +192,11 @@ main(int argc, char * const *argv) { int c; - struct VSL_data *vd; + struct VSM_data *vd; const struct vsc_main *VSL_stats; int delay = 1, once = 0, xml = 0; - vd = VSL_New(); + vd = VSM_New(); while ((c = getopt(argc, argv, VSL_STAT_ARGS "1f:lVw:x")) != -1) { switch (c) { @@ -207,7 +207,7 @@ (void)VSL_Stat_Arg(vd, c, optarg); break; case 'l': - if (VSL_Open(vd, 1)) + if (VSM_Open(vd, 1)) exit(1); list_fields(vd); exit(0); @@ -227,10 +227,10 @@ } } - if (VSL_Open(vd, 1)) + if (VSM_Open(vd, 1)) exit(1); - if ((VSL_stats = VSL_OpenStats(vd)) == NULL) + if ((VSL_stats = VSM_OpenStats(vd)) == NULL) exit(1); if (xml) Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.h =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.h 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.h 2010-06-08 10:15:00 UTC (rev 4933) @@ -27,4 +27,4 @@ * */ -void do_curses(struct VSL_data *vd, const struct vsc_main *VSL_stats, int delay); +void do_curses(struct VSM_data *vd, const struct vsc_main *VSL_stats, int delay); Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -100,7 +100,7 @@ } static void -prep_pts(const struct VSL_data *vd) +prep_pts(const struct VSM_data *vd) { struct pt *pt, *pt2; @@ -123,7 +123,7 @@ } void -do_curses(struct VSL_data *vd, const struct vsc_main *VSL_stats, +do_curses(struct VSM_data *vd, const struct vsc_main *VSL_stats, int delay) { intmax_t ju; @@ -164,7 +164,7 @@ * Only check if it looks like nothing is happening. */ act = VSL_stats->cache_hit + VSL_stats->cache_miss + 1; - if (act == lact && VSL_ReOpen(vd, 1)) + if (act == lact && VSM_ReOpen(vd, 1)) break; lact = act; @@ -175,7 +175,7 @@ rt = VSL_stats->uptime; up = rt; - AC(mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd))); + AC(mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd))); AC(mvprintw(0, 0, "%d+%02d:%02d:%02d", rt / 86400, (rt % 86400) / 3600, (rt % 3600) / 60, rt % 60)); Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -81,7 +81,7 @@ int vcl_nbr; char *workdir; - struct VSL_data *vd; + struct VSM_data *vd; }; static VTAILQ_HEAD(, varnish) varnishes = @@ -200,7 +200,7 @@ vtc_logclose(v->vl); free(v->name); free(v->workdir); - VSL_Delete(v->vd); + VSM_Delete(v->vd); /* * We do not delete the workdir, it may contain stuff people @@ -261,7 +261,7 @@ enum cli_status_e u; char *r; - v->vd = VSL_New(); + v->vd = VSM_New(); /* Create listener socket */ nap = VSS_resolve("127.0.0.1", "0", &ap); @@ -363,10 +363,10 @@ free(r); if (v->stats != NULL) - VSL_Close(v->vd); + VSM_Close(v->vd); (void)VSL_Log_Arg(v->vd, 'n', v->workdir); - AZ(VSL_Open(v->vd, 1)); - v->stats = VSL_OpenStats(v->vd); + AZ(VSM_Open(v->vd, 1)); + v->stats = VSM_OpenStats(v->vd); } /********************************************************************** Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -143,7 +143,7 @@ } static void -update(const struct VSL_data *vd) +update(const struct VSM_data *vd) { struct top *tp, *tp2; int l, len; @@ -158,7 +158,7 @@ l = 1; AC(erase()); - AC(mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd))); + AC(mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd))); AC(mvprintw(0, 0, "list length %u", ntop)); VTAILQ_FOREACH_SAFE(tp, &top_head, list, tp2) { if (++l < LINES) { @@ -185,7 +185,7 @@ static void * accumulate_thread(void *arg) { - struct VSL_data *vd = arg; + struct VSM_data *vd = arg; uint32_t *p; int i; @@ -207,7 +207,7 @@ } static void -do_curses(struct VSL_data *vd) +do_curses(struct VSM_data *vd) { pthread_t thr; int i; @@ -284,7 +284,7 @@ } static void -do_once(struct VSL_data *vd) +do_once(struct VSM_data *vd) { uint32_t *p; @@ -304,10 +304,10 @@ int main(int argc, char **argv) { - struct VSL_data *vd; + struct VSM_data *vd; int o, once = 0; - vd = VSL_New(); + vd = VSM_New(); while ((o = getopt(argc, argv, VSL_LOG_ARGS "1fV")) != -1) { switch (o) { @@ -328,7 +328,7 @@ } } - if (VSL_OpenLog(vd)) + if (VSM_OpenLog(vd)) exit (1); if (once) { Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-08 10:15:00 UTC (rev 4933) @@ -42,10 +42,10 @@ /*--------------------------------------------------------------------- - * Level 0: Create and destroy the VSL_data handle structure + * VSM level access functions */ -struct VSL_data *VSL_New(void); +struct VSM_data *VSM_New(void); /* * Allocate and initialize a VSL_data handle structure. * This is the first thing you will have to do, always. @@ -55,16 +55,16 @@ * Pointer to usable VSL_data handle. */ -typedef void vsl_diag_f(void *priv, const char *fmt, ...); +typedef void vsm_diag_f(void *priv, const char *fmt, ...); -void VSL_Diag(struct VSL_data *vd, vsl_diag_f *func, void *priv); +void VSM_Diag(struct VSM_data *vd, vsm_diag_f *func, void *priv); /* * Set the diagnostics reporting function. * Default is fprintf(stderr, ...) * If func is NULL, diagnostics are disabled. */ -int VSL_n_Arg(struct VSL_data *vd, const char *n_arg); +int VSM_n_Arg(struct VSM_data *vd, const char *n_arg); /* * Configure which varnishd instance to access. * Can also be, and normally is done through the VSL_Log_arg() @@ -74,23 +74,19 @@ * -1 on failure, with diagnostic on stderr. */ -const char *VSL_Name(const struct VSL_data *vd); +const char *VSM_Name(const struct VSM_data *vd); /* * Return the instance name. */ -void VSL_Delete(struct VSL_data *vd); +void VSM_Delete(struct VSM_data *vd); /* * Close and deallocate all storage and mappings. */ /* XXX: extension: Patience argument for sleeps */ -/*--------------------------------------------------------------------- - * Level 1: Open/Close and find allocation in shared memory segment - */ - -int VSL_Open(struct VSL_data *vd, int diag); +int VSM_Open(struct VSM_data *vd, int diag); /* * Attempt to open and map the shared memory file. * If diag is non-zero, diagnostics are emitted. @@ -99,22 +95,33 @@ * != 0 on failure */ -int VSL_ReOpen(struct VSL_data *vd, int diag); +int VSM_ReOpen(struct VSM_data *vd, int diag); /* * Check if shared memory segment needs to be reopened/remapped * typically when the varnishd master process restarts. - * diag is passed to VSL_Open() + * diag is passed to VSM_Open() * Returns: * 0 No reopen needed. * 1 shared memory reopened/remapped. * -1 failure to reopen. */ -void *VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, +struct vsm_head *VSM_Head(struct VSM_data *vd); + /* + * Return the head of the VSM. + */ + +void *VSM_Find_Chunk(struct VSM_data *vd, const char *class, const char *type, const char *ident, unsigned *lenp); -void VSL_Close(struct VSL_data *vd); +void VSM_Close(struct VSM_data *vd); +struct vsm_chunk *vsm_iter0(const struct VSM_data *vd); +void vsm_itern(const struct VSM_data *vd, struct vsm_chunk **pp); +#define VSM_FOREACH(var, vd) \ + for((var) = vsm_iter0((vd)); (var) != NULL; vsm_itern((vd), &(var))) + + /* shmlog.c */ typedef int vsl_handler(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr); @@ -125,24 +132,18 @@ #define VSL_USAGE "[-bCcd] [-i tag] [-I regexp] [-k keep]" \ " [-r file] [-s skip] [-X regexp] [-x tag]" vsl_handler VSL_H_Print; -struct VSL_data; -void VSL_Select(const struct VSL_data *vd, unsigned tag); -int VSL_OpenLog(struct VSL_data *vd); -void VSL_NonBlocking(struct VSL_data *vd, int nb); -int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv); -int VSL_NextLog(struct VSL_data *lh, uint32_t **pp); -int VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt); -int VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt); -struct vsc_main *VSL_OpenStats(struct VSL_data *vd); +struct VSM_data; +void VSL_Select(const struct VSM_data *vd, unsigned tag); +int VSM_OpenLog(struct VSM_data *vd); +void VSL_NonBlocking(struct VSM_data *vd, int nb); +int VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv); +int VSL_NextLog(struct VSM_data *lh, uint32_t **pp); +int VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt); +int VSL_Stat_Arg(struct VSM_data *vd, int arg, const char *opt); +struct vsc_main *VSM_OpenStats(struct VSM_data *vd); extern const char *VSL_tags[256]; -struct vsm_chunk *vsl_iter0(const struct VSL_data *vd); -void vsl_itern(const struct VSL_data *vd, struct vsm_chunk **pp); - -#define VSL_FOREACH(var, vd) \ - for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var))) - struct vsl_statpt { const char *class; /* stat struct type */ const char *ident; /* stat struct ident */ @@ -155,7 +156,7 @@ typedef int vsl_stat_f(void *priv, const struct vsl_statpt *const pt); -int VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv); +int VSL_IterStat(const struct VSM_data *vd, vsl_stat_f *func, void *priv); /* base64.c */ void base64_init(void); Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-08 10:15:00 UTC (rev 4933) @@ -17,7 +17,7 @@ ../libvarnish/vmb.c \ ../libvarnish/vre.c \ base64.c \ - vsl.c \ + vsm.c \ vsl_arg.c \ vsl_log.c \ vsl_stat.c Deleted: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -1,340 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2010 Redpill Linpro AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "config.h" - -#include "svnid.h" -SVNID("$Id$") - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "vas.h" -#include "vin.h" -#include "vsm.h" -#include "vre.h" -#include "vbm.h" -#include "vqueue.h" -#include "miniobj.h" -#include "varnishapi.h" - -#include "vslapi.h" - -#ifndef MAP_HASSEMAPHORE -#define MAP_HASSEMAPHORE 0 /* XXX Linux */ -#endif - -/*--------------------------------------------------------------------*/ - -struct VSL_data * -VSL_New(void) -{ - struct VSL_data *vd; - - ALLOC_OBJ(vd, VSL_MAGIC); - AN(vd); - - vd->diag = (vsl_diag_f*)fprintf; - vd->priv = stderr; - - vd->vsl_fd = -1; - - vd->regflags = 0; - - /* XXX: Allocate only if log access */ - vd->vbm_client = vbit_init(4096); - vd->vbm_backend = vbit_init(4096); - vd->vbm_supress = vbit_init(256); - vd->vbm_select = vbit_init(256); - - vd->r_fd = -1; - /* XXX: Allocate only if -r option given ? */ - vd->rbuflen = 256; /* XXX ?? */ - vd->rbuf = malloc(vd->rbuflen * 4); - assert(vd->rbuf != NULL); - - VTAILQ_INIT(&vd->sf_list); - - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - return (vd); -} - -/*--------------------------------------------------------------------*/ - -void -VSL_Diag(struct VSL_data *vd, vsl_diag_f *func, void *priv) -{ - - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - if (func == NULL) - vd->diag = (vsl_diag_f*)getpid; - else - vd->diag = func; - vd->priv = priv; -} - -/*--------------------------------------------------------------------*/ - -int -VSL_n_Arg(struct VSL_data *vd, const char *opt) -{ - - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - REPLACE(vd->n_opt, opt); - AN(vd->n_opt); - if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) { - vd->diag(vd->priv, "Invalid instance name: %s\n", - strerror(errno)); - return (-1); - } - return (1); -} - -/*--------------------------------------------------------------------*/ - -const char * -VSL_Name(const struct VSL_data *vd) -{ - - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - return (vd->n_opt); -} - -/*--------------------------------------------------------------------*/ - -void -VSL_Delete(struct VSL_data *vd) -{ - struct vsl_sf *sf; - - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - VSL_Close(vd); - vbit_destroy(vd->vbm_client); - vbit_destroy(vd->vbm_backend); - vbit_destroy(vd->vbm_supress); - vbit_destroy(vd->vbm_select); - free(vd->n_opt); - free(vd->rbuf); - free(vd->fname); - - while(!VTAILQ_EMPTY(&vd->sf_list)) { - sf = VTAILQ_FIRST(&vd->sf_list); - VTAILQ_REMOVE(&vd->sf_list, sf, next); - free(sf->class); - free(sf->ident); - free(sf->name); - free(sf); - } - - free(vd); -} - -/*--------------------------------------------------------------------*/ - -static int -vsl_open(struct VSL_data *vd, int diag) -{ - int i; - struct vsm_head slh; - - if (vd->vsl_lh != NULL) - return (0); - - vd->vsl_fd = open(vd->fname, O_RDONLY); - if (vd->vsl_fd < 0) { - if (diag) - vd->diag(vd->priv, "Cannot open %s: %s\n", - vd->fname, strerror(errno)); - return (1); - } - - assert(fstat(vd->vsl_fd, &vd->fstat) == 0); - if (!S_ISREG(vd->fstat.st_mode)) { - if (diag) - vd->diag(vd->priv, "%s is not a regular file\n", - vd->fname); - return (1); - } - - i = read(vd->vsl_fd, &slh, sizeof slh); - if (i != sizeof slh) { - if (diag) - vd->diag(vd->priv, "Cannot read %s: %s\n", - vd->fname, strerror(errno)); - return (1); - } - if (slh.magic != VSM_HEAD_MAGIC) { - if (diag) - vd->diag(vd->priv, "Wrong magic number in file %s\n", - vd->fname); - return (1); - } - - vd->vsl_lh = (void *)mmap(NULL, slh.shm_size, - PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsl_fd, 0); - if (vd->vsl_lh == MAP_FAILED) { - if (diag) - vd->diag(vd->priv, "Cannot mmap %s: %s\n", - vd->fname, strerror(errno)); - return (1); - } - vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size; - - while(slh.alloc_seq == 0) - usleep(50000); /* XXX limit total sleep */ - vd->alloc_seq = slh.alloc_seq; - return (0); -} - -/*--------------------------------------------------------------------*/ - -int -VSL_Open(struct VSL_data *vd, int diag) - -{ - - return (vsl_open(vd, diag)); -} - -/*--------------------------------------------------------------------*/ - -void -VSL_Close(struct VSL_data *vd) -{ - if (vd->vsl_lh == NULL) - return; - assert(0 == munmap((void*)vd->vsl_lh, vd->vsl_lh->shm_size)); - vd->vsl_lh = NULL; - assert(vd->vsl_fd >= 0); - assert(0 == close(vd->vsl_fd)); - vd->vsl_fd = -1; -} - -/*--------------------------------------------------------------------*/ - -int -VSL_ReOpen(struct VSL_data *vd, int diag) -{ - struct stat st; - int i; - - AN(vd->vsl_lh); - - if (stat(vd->fname, &st)) - return (0); - - if (st.st_dev == vd->fstat.st_dev && st.st_ino == vd->fstat.st_ino) - return (0); - - VSL_Close(vd); - for (i = 0; i < 5; i++) { /* XXX param */ - if (!vsl_open(vd, 0)) - return (1); - } - if (vsl_open(vd, diag)) - return (-1); - return (1); -} - -/*--------------------------------------------------------------------*/ - -struct vsm_chunk * -vsl_iter0(const struct VSL_data *vd) -{ - - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - if (vd->alloc_seq != vd->vsl_lh->alloc_seq) - return(NULL); - CHECK_OBJ_NOTNULL(&vd->vsl_lh->head, VSM_CHUNK_MAGIC); - return (&vd->vsl_lh->head); -} - -void -vsl_itern(const struct VSL_data *vd, struct vsm_chunk **pp) -{ - - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - if (vd->alloc_seq != vd->vsl_lh->alloc_seq) { - *pp = NULL; - return; - } - CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); - *pp = VSM_NEXT(*pp); - if ((void*)(*pp) >= vd->vsl_end) { - *pp = NULL; - return; - } - CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); -} - -/*--------------------------------------------------------------------*/ - -struct vsm_chunk * -vsl_find_alloc(const struct VSL_data *vd, const char *class, const char *type, const char *ident) -{ - struct vsm_chunk *sha; - - assert (vd->vsl_lh != NULL); - VSL_FOREACH(sha, vd) { - CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); - if (strcmp(sha->class, class)) - continue; - if (type != NULL && strcmp(sha->type, type)) - continue; - if (ident != NULL && strcmp(sha->ident, ident)) - continue; - return (sha); - } - return (NULL); -} - -/*--------------------------------------------------------------------*/ - -void * -VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident, - unsigned *lenp) -{ - struct vsm_chunk *sha; - - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - sha = vsl_find_alloc(vd, class, type, ident); - if (sha == NULL) - return (NULL); - if (lenp != NULL) - *lenp = sha->len - sizeof *sha; - return (VSM_PTR(sha)); -} Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -57,10 +57,10 @@ /*--------------------------------------------------------------------*/ static int -vsl_r_arg(struct VSL_data *vd, const char *opt) +vsl_r_arg(struct VSM_data *vd, const char *opt) { - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); if (!strcmp(opt, "-")) vd->r_fd = STDIN_FILENO; else @@ -75,13 +75,13 @@ /*--------------------------------------------------------------------*/ static int -vsl_IX_arg(struct VSL_data *vd, const char *opt, int arg) +vsl_IX_arg(struct VSM_data *vd, const char *opt, int arg) { vre_t **rp; const char *error; int erroroffset; - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); if (arg == 'I') rp = &vd->regincl; else @@ -101,12 +101,12 @@ /*--------------------------------------------------------------------*/ static int -vsl_ix_arg(struct VSL_data *vd, const char *opt, int arg) +vsl_ix_arg(struct VSM_data *vd, const char *opt, int arg) { int i, j, l; const char *b, *e, *p, *q; - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); /* If first option is 'i', set all bits for supression */ if (arg == 'i' && !(vd->flags & F_SEEN_IX)) for (i = 0; i < 256; i++) @@ -153,11 +153,11 @@ /*--------------------------------------------------------------------*/ static int -vsl_s_arg(struct VSL_data *vd, const char *opt) +vsl_s_arg(struct VSM_data *vd, const char *opt) { char *end; - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); if (*opt == '\0') { fprintf(stderr, "number required for -s\n"); return (-1); @@ -173,11 +173,11 @@ /*--------------------------------------------------------------------*/ static int -vsl_k_arg(struct VSL_data *vd, const char *opt) +vsl_k_arg(struct VSM_data *vd, const char *opt) { char *end; - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); if (*opt == '\0') { fprintf(stderr, "number required for -k\n"); return (-1); @@ -193,10 +193,10 @@ /*--------------------------------------------------------------------*/ int -VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt) +VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt) { - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); switch (arg) { case 'b': vd->b_opt = !vd->b_opt; return (1); case 'c': vd->c_opt = !vd->c_opt; return (1); @@ -206,7 +206,7 @@ return (1); case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg)); case 'k': return (vsl_k_arg(vd, opt)); - case 'n': return (VSL_n_Arg(vd, opt)); + case 'n': return (VSM_n_Arg(vd, opt)); case 'r': return (vsl_r_arg(vd, opt)); case 's': return (vsl_s_arg(vd, opt)); case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg)); @@ -229,13 +229,13 @@ /*--------------------------------------------------------------------*/ static int -vsl_sf_arg(struct VSL_data *vd, const char *opt) +vsl_sf_arg(struct VSM_data *vd, const char *opt) { struct vsl_sf *sf; char **av, *q, *p; int i; - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); if (VTAILQ_EMPTY(&vd->sf_list)) { if (*opt == '^') @@ -309,13 +309,13 @@ /*--------------------------------------------------------------------*/ int -VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt) +VSL_Stat_Arg(struct VSM_data *vd, int arg, const char *opt) { - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); switch (arg) { case 'f': return (vsl_sf_arg(vd, opt)); - case 'n': return (VSL_n_Arg(vd, opt)); + case 'n': return (VSM_n_Arg(vd, opt)); default: return (0); } Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -52,7 +52,7 @@ #include "vslapi.h" #include "vmb.h" -static int vsl_nextlog(struct VSL_data *vd, uint32_t **pp); +static int vsl_nextlog(struct VSM_data *vd, uint32_t **pp); /*--------------------------------------------------------------------*/ @@ -65,10 +65,10 @@ /*--------------------------------------------------------------------*/ void -VSL_Select(const struct VSL_data *vd, unsigned tag) +VSL_Select(const struct VSM_data *vd, unsigned tag) { - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); vbit_set(vd->vbm_select, tag); } @@ -76,7 +76,7 @@ /*--------------------------------------------------------------------*/ void -VSL_NonBlocking(struct VSL_data *vd, int nb) +VSL_NonBlocking(struct VSM_data *vd, int nb) { if (nb) vd->flags |= F_NON_BLOCKING; @@ -87,13 +87,13 @@ /*--------------------------------------------------------------------*/ static int -vsl_nextlog(struct VSL_data *vd, uint32_t **pp) +vsl_nextlog(struct VSM_data *vd, uint32_t **pp) { unsigned w, l; uint32_t t; int i; - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); if (vd->r_fd != -1) { assert(vd->rbuflen >= 8); i = read(vd->r_fd, vd->rbuf, 8); @@ -138,14 +138,14 @@ } int -VSL_NextLog(struct VSL_data *vd, uint32_t **pp) +VSL_NextLog(struct VSM_data *vd, uint32_t **pp) { uint32_t *p; unsigned char t; unsigned u; int i; - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); while (1) { i = vsl_nextlog(vd, &p); if (i != 1) @@ -204,13 +204,13 @@ /*--------------------------------------------------------------------*/ int -VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv) +VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv) { int i; unsigned u, l, s; uint32_t *p; - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); while (1) { i = VSL_NextLog(vd, &p); if (i != 1) @@ -260,12 +260,12 @@ /*--------------------------------------------------------------------*/ int -VSL_OpenLog(struct VSL_data *vd) +VSM_OpenLog(struct VSM_data *vd) { struct vsm_chunk *sha; - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); - sha = vsl_find_alloc(vd, VSL_CLASS, "", ""); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + sha = vsm_find_alloc(vd, VSL_CLASS, "", ""); assert(sha != NULL); vd->log_start = VSM_PTR(sha); Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -49,13 +49,13 @@ /*--------------------------------------------------------------------*/ struct vsc_main * -VSL_OpenStats(struct VSL_data *vd) +VSM_OpenStats(struct VSM_data *vd) { struct vsm_chunk *sha; - CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - sha = vsl_find_alloc(vd, VSC_CLASS, "", ""); + sha = vsm_find_alloc(vd, VSC_CLASS, "", ""); assert(sha != NULL); return (VSM_PTR(sha)); } @@ -78,7 +78,7 @@ } static int -iter_call(const struct VSL_data *vd, vsl_stat_f *func, void *priv, +iter_call(const struct VSM_data *vd, vsl_stat_f *func, void *priv, const struct vsl_statpt *const sp) { struct vsl_sf *sf; @@ -105,7 +105,7 @@ } static int -iter_main(const struct VSL_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, +iter_main(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, void *priv) { struct vsc_main *st = VSM_PTR(sha); @@ -129,7 +129,7 @@ } static int -iter_sma(const struct VSL_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, +iter_sma(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, void *priv) { struct vsc_sma *st = VSM_PTR(sha); @@ -153,13 +153,13 @@ } int -VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv) +VSL_IterStat(const struct VSM_data *vd, vsl_stat_f *func, void *priv) { struct vsm_chunk *sha; int i; i = 0; - VSL_FOREACH(sha, vd) { + VSM_FOREACH(sha, vd) { CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); if (strcmp(sha->class, VSC_CLASS)) continue; Modified: trunk/varnish-cache/lib/libvarnishapi/vslapi.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 10:01:46 UTC (rev 4932) +++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 10:15:00 UTC (rev 4933) @@ -47,11 +47,11 @@ char *name; }; -struct VSL_data { +struct VSM_data { unsigned magic; -#define VSL_MAGIC 0x6e3bd69b +#define VSM_MAGIC 0x6e3bd69b - vsl_diag_f *diag; + vsm_diag_f *diag; void *priv; char *n_opt; @@ -117,5 +117,5 @@ unsigned long keep; }; -struct vsm_chunk *vsl_find_alloc(const struct VSL_data *vd, const char *class, +struct vsm_chunk *vsm_find_alloc(const struct VSM_data *vd, const char *class, const char *type, const char *ident); Copied: trunk/varnish-cache/lib/libvarnishapi/vsm.c (from rev 4928, trunk/varnish-cache/lib/libvarnishapi/vsl.c) =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm.c (rev 0) +++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-08 10:15:00 UTC (rev 4933) @@ -0,0 +1,358 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2010 Redpill Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "config.h" + +#include "svnid.h" +SVNID("$Id$") + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "vas.h" +#include "vin.h" +#include "vsm.h" +#include "vre.h" +#include "vbm.h" +#include "vqueue.h" +#include "miniobj.h" +#include "varnishapi.h" + +#include "vslapi.h" + +#ifndef MAP_HASSEMAPHORE +#define MAP_HASSEMAPHORE 0 /* XXX Linux */ +#endif + +/*--------------------------------------------------------------------*/ + +struct VSM_data * +VSM_New(void) +{ + struct VSM_data *vd; + + ALLOC_OBJ(vd, VSM_MAGIC); + AN(vd); + + vd->diag = (vsm_diag_f*)fprintf; + vd->priv = stderr; + + vd->vsl_fd = -1; + + vd->regflags = 0; + + /* XXX: Allocate only if log access */ + vd->vbm_client = vbit_init(4096); + vd->vbm_backend = vbit_init(4096); + vd->vbm_supress = vbit_init(256); + vd->vbm_select = vbit_init(256); + + vd->r_fd = -1; + /* XXX: Allocate only if -r option given ? */ + vd->rbuflen = 256; /* XXX ?? */ + vd->rbuf = malloc(vd->rbuflen * 4); + assert(vd->rbuf != NULL); + + VTAILQ_INIT(&vd->sf_list); + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + return (vd); +} + +/*--------------------------------------------------------------------*/ + +void +VSM_Diag(struct VSM_data *vd, vsm_diag_f *func, void *priv) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + if (func == NULL) + vd->diag = (vsm_diag_f*)getpid; + else + vd->diag = func; + vd->priv = priv; +} + +/*--------------------------------------------------------------------*/ + +int +VSM_n_Arg(struct VSM_data *vd, const char *opt) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + REPLACE(vd->n_opt, opt); + AN(vd->n_opt); + if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) { + vd->diag(vd->priv, "Invalid instance name: %s\n", + strerror(errno)); + return (-1); + } + return (1); +} + +/*--------------------------------------------------------------------*/ + +const char * +VSM_Name(const struct VSM_data *vd) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + return (vd->n_opt); +} + +/*--------------------------------------------------------------------*/ + +void +VSM_Delete(struct VSM_data *vd) +{ + struct vsl_sf *sf; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + VSM_Close(vd); + vbit_destroy(vd->vbm_client); + vbit_destroy(vd->vbm_backend); + vbit_destroy(vd->vbm_supress); + vbit_destroy(vd->vbm_select); + free(vd->n_opt); + free(vd->rbuf); + free(vd->fname); + + while(!VTAILQ_EMPTY(&vd->sf_list)) { + sf = VTAILQ_FIRST(&vd->sf_list); + VTAILQ_REMOVE(&vd->sf_list, sf, next); + free(sf->class); + free(sf->ident); + free(sf->name); + free(sf); + } + + free(vd); +} + +/*--------------------------------------------------------------------*/ + +static int +vsl_open(struct VSM_data *vd, int diag) +{ + int i; + struct vsm_head slh; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + if (vd->vsl_lh != NULL) + return (0); + + vd->vsl_fd = open(vd->fname, O_RDONLY); + if (vd->vsl_fd < 0) { + if (diag) + vd->diag(vd->priv, "Cannot open %s: %s\n", + vd->fname, strerror(errno)); + return (1); + } + + assert(fstat(vd->vsl_fd, &vd->fstat) == 0); + if (!S_ISREG(vd->fstat.st_mode)) { + if (diag) + vd->diag(vd->priv, "%s is not a regular file\n", + vd->fname); + return (1); + } + + i = read(vd->vsl_fd, &slh, sizeof slh); + if (i != sizeof slh) { + if (diag) + vd->diag(vd->priv, "Cannot read %s: %s\n", + vd->fname, strerror(errno)); + return (1); + } + if (slh.magic != VSM_HEAD_MAGIC) { + if (diag) + vd->diag(vd->priv, "Wrong magic number in file %s\n", + vd->fname); + return (1); + } + + vd->vsl_lh = (void *)mmap(NULL, slh.shm_size, + PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsl_fd, 0); + if (vd->vsl_lh == MAP_FAILED) { + if (diag) + vd->diag(vd->priv, "Cannot mmap %s: %s\n", + vd->fname, strerror(errno)); + return (1); + } + vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size; + + while(slh.alloc_seq == 0) + usleep(50000); /* XXX limit total sleep */ + vd->alloc_seq = slh.alloc_seq; + return (0); +} + +/*--------------------------------------------------------------------*/ + +int +VSM_Open(struct VSM_data *vd, int diag) + +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + return (vsl_open(vd, diag)); +} + +/*--------------------------------------------------------------------*/ + +void +VSM_Close(struct VSM_data *vd) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + if (vd->vsl_lh == NULL) + return; + assert(0 == munmap((void*)vd->vsl_lh, vd->vsl_lh->shm_size)); + vd->vsl_lh = NULL; + assert(vd->vsl_fd >= 0); + assert(0 == close(vd->vsl_fd)); + vd->vsl_fd = -1; +} + +/*--------------------------------------------------------------------*/ + +int +VSM_ReOpen(struct VSM_data *vd, int diag) +{ + struct stat st; + int i; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + AN(vd->vsl_lh); + + if (stat(vd->fname, &st)) + return (0); + + if (st.st_dev == vd->fstat.st_dev && st.st_ino == vd->fstat.st_ino) + return (0); + + VSM_Close(vd); + for (i = 0; i < 5; i++) { /* XXX param */ + if (!vsl_open(vd, 0)) + return (1); + } + if (vsl_open(vd, diag)) + return (-1); + return (1); +} + +/*--------------------------------------------------------------------*/ + +struct vsm_head * +VSM_Head(struct VSM_data *vd) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + AN(vd->vsl_lh); + return(vd->vsl_lh); +} + + +/*--------------------------------------------------------------------*/ + +struct vsm_chunk * +vsm_find_alloc(const struct VSM_data *vd, const char *class, const char *type, const char *ident) +{ + struct vsm_chunk *sha; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + assert (vd->vsl_lh != NULL); + VSM_FOREACH(sha, vd) { + CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); + if (strcmp(sha->class, class)) + continue; + if (type != NULL && strcmp(sha->type, type)) + continue; + if (ident != NULL && strcmp(sha->ident, ident)) + continue; + return (sha); + } + return (NULL); +} + +/*--------------------------------------------------------------------*/ + +void * +VSM_Find_Chunk(struct VSM_data *vd, const char *class, const char *type, const char *ident, + unsigned *lenp) +{ + struct vsm_chunk *sha; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + sha = vsm_find_alloc(vd, class, type, ident); + if (sha == NULL) + return (NULL); + if (lenp != NULL) + *lenp = sha->len - sizeof *sha; + return (VSM_PTR(sha)); +} + +/*--------------------------------------------------------------------*/ + +struct vsm_chunk * +vsm_iter0(const struct VSM_data *vd) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + if (vd->alloc_seq != vd->vsl_lh->alloc_seq) + return(NULL); + CHECK_OBJ_NOTNULL(&vd->vsl_lh->head, VSM_CHUNK_MAGIC); + return (&vd->vsl_lh->head); +} + +void +vsm_itern(const struct VSM_data *vd, struct vsm_chunk **pp) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + if (vd->alloc_seq != vd->vsl_lh->alloc_seq) { + *pp = NULL; + return; + } + CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); + *pp = VSM_NEXT(*pp); + if ((void*)(*pp) >= vd->vsl_end) { + *pp = NULL; + return; + } + CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); +} From phk at varnish-cache.org Tue Jun 8 10:19:34 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 12:19:34 +0200 Subject: r4934 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 12:19:34 +0200 (Tue, 08 Jun 2010) New Revision: 4934 Added: trunk/varnish-cache/lib/libvarnishapi/vsc.c trunk/varnish-cache/lib/libvarnishapi/vsl.c Removed: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am Log: rename files to match subject matter Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-08 10:15:00 UTC (rev 4933) +++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-08 10:19:34 UTC (rev 4934) @@ -19,8 +19,8 @@ base64.c \ vsm.c \ vsl_arg.c \ - vsl_log.c \ - vsl_stat.c + vsl.c \ + vsc.c libvarnishapi_la_CFLAGS = \ -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' Copied: trunk/varnish-cache/lib/libvarnishapi/vsc.c (from rev 4933, trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c) =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsc.c (rev 0) +++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 10:19:34 UTC (rev 4934) @@ -0,0 +1,176 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2010 Redpill Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "config.h" + +#include "svnid.h" +SVNID("$Id$") + +#include +#include +#include + +#include "vas.h" +#include "vsm.h" +#include "vsc.h" +#include "vre.h" +#include "vqueue.h" +#include "miniobj.h" +#include "varnishapi.h" + +#include "vslapi.h" + +/*--------------------------------------------------------------------*/ + +struct vsc_main * +VSM_OpenStats(struct VSM_data *vd) +{ + struct vsm_chunk *sha; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + + sha = vsm_find_alloc(vd, VSC_CLASS, "", ""); + assert(sha != NULL); + return (VSM_PTR(sha)); +} + +/*-------------------------------------------------------------------- + * -1 -> unknown stats encountered. + */ + +static inline int +iter_test(const char *s1, const char *s2, int wc) +{ + + if (s1 == NULL) + return (0); + if (!wc) + return (strcmp(s1, s2)); + for (; *s1 != '\0' && *s1 == *s2; s1++, s2++) + continue; + return (*s1 != '\0'); +} + +static int +iter_call(const struct VSM_data *vd, vsl_stat_f *func, void *priv, + const struct vsl_statpt *const sp) +{ + struct vsl_sf *sf; + int good = vd->sf_init; + + if (VTAILQ_EMPTY(&vd->sf_list)) + return (func(priv, sp)); + + VTAILQ_FOREACH(sf, &vd->sf_list, next) { + if (iter_test(sf->class, sp->class, sf->flags & VSL_SF_CL_WC)) + continue; + if (iter_test(sf->ident, sp->ident, sf->flags & VSL_SF_ID_WC)) + continue; + if (iter_test(sf->name, sp->name, sf->flags & VSL_SF_NM_WC)) + continue; + if (sf->flags & VSL_SF_EXCL) + good = 0; + else + good = 1; + } + if (!good) + return (0); + return (func(priv, sp)); +} + +static int +iter_main(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, + void *priv) +{ + struct vsc_main *st = VSM_PTR(sha); + struct vsl_statpt sp; + int i; + + sp.class = ""; + sp.ident = ""; +#define VSC_F_MAIN(nn, tt, ll, ff, dd) \ + sp.name = #nn; \ + sp.fmt = #tt; \ + sp.flag = ff; \ + sp.desc = dd; \ + sp.ptr = &st->nn; \ + i = iter_call(vd, func, priv, &sp); \ + if (i) \ + return(i); +#include "vsc_fields.h" +#undef VSC_F_MAIN + return (0); +} + +static int +iter_sma(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, + void *priv) +{ + struct vsc_sma *st = VSM_PTR(sha); + struct vsl_statpt sp; + int i; + + sp.class = VSC_TYPE_SMA; + sp.ident = sha->ident; +#define VSC_F_SMA(nn, tt, ll, ff, dd) \ + sp.name = #nn; \ + sp.fmt = #tt; \ + sp.flag = ff; \ + sp.desc = dd; \ + sp.ptr = &st->nn; \ + i = iter_call(vd, func, priv, &sp); \ + if (i) \ + return(i); +#include "vsc_fields.h" +#undef VSC_F_SMA + return (0); +} + +int +VSL_IterStat(const struct VSM_data *vd, vsl_stat_f *func, void *priv) +{ + struct vsm_chunk *sha; + int i; + + i = 0; + VSM_FOREACH(sha, vd) { + CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); + if (strcmp(sha->class, VSC_CLASS)) + continue; + if (!strcmp(sha->type, VSC_TYPE_MAIN)) + i = iter_main(vd, sha, func, priv); + else if (!strcmp(sha->type, VSC_TYPE_SMA)) + i = iter_sma(vd, sha, func, priv); + else + i = -1; + if (i != 0) + break; + } + return (i); +} Copied: trunk/varnish-cache/lib/libvarnishapi/vsl.c (from rev 4933, trunk/varnish-cache/lib/libvarnishapi/vsl_log.c) =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c (rev 0) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 10:19:34 UTC (rev 4934) @@ -0,0 +1,282 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2010 Redpill Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "config.h" + +#include "svnid.h" +SVNID("$Id$") + +#include +#include + +#include +#include +#include +#include + +#include "vas.h" +#include "vsm.h" +#include "vsl.h" +#include "vre.h" +#include "vbm.h" +#include "vqueue.h" +#include "miniobj.h" +#include "varnishapi.h" + +#include "vslapi.h" +#include "vmb.h" + +static int vsl_nextlog(struct VSM_data *vd, uint32_t **pp); + +/*--------------------------------------------------------------------*/ + +const char *VSL_tags[256] = { +#define SLTM(foo) [SLT_##foo] = #foo, +#include "vsl_tags.h" +#undef SLTM +}; + +/*--------------------------------------------------------------------*/ + +void +VSL_Select(const struct VSM_data *vd, unsigned tag) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vbit_set(vd->vbm_select, tag); +} + + +/*--------------------------------------------------------------------*/ + +void +VSL_NonBlocking(struct VSM_data *vd, int nb) +{ + if (nb) + vd->flags |= F_NON_BLOCKING; + else + vd->flags &= ~F_NON_BLOCKING; +} + +/*--------------------------------------------------------------------*/ + +static int +vsl_nextlog(struct VSM_data *vd, uint32_t **pp) +{ + unsigned w, l; + uint32_t t; + int i; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + if (vd->r_fd != -1) { + assert(vd->rbuflen >= 8); + i = read(vd->r_fd, vd->rbuf, 8); + if (i != 8) + return (-1); + l = 2 + VSL_WORDS(VSL_LEN(vd->rbuf)); + if (vd->rbuflen < l) { + l += 256; + vd->rbuf = realloc(vd->rbuf, l * 4); + assert(vd->rbuf != NULL); + vd->rbuflen = l; + } + i = read(vd->r_fd, vd->rbuf + 2, l * 4 - 8); + if (i != l) + return (-1); + *pp = vd->rbuf; + return (1); + } + for (w = 0; w < TIMEOUT_USEC;) { + t = *vd->log_ptr; + + if (t == VSL_WRAPMARKER || + (t == VSL_ENDMARKER && vd->last_seq != vd->log_start[0])) { + vd->log_ptr = vd->log_start + 1; + vd->last_seq = vd->log_start[0]; + VRMB(); + continue; + } + if (t == VSL_ENDMARKER) { + if (vd->flags & F_NON_BLOCKING) + return (-1); + w += SLEEP_USEC; + AZ(usleep(SLEEP_USEC)); + continue; + } + *pp = (void*)(uintptr_t)vd->log_ptr; /* Loose volatile */ + vd->log_ptr = VSL_NEXT(vd->log_ptr); + return (1); + } + *pp = NULL; + return (0); +} + +int +VSL_NextLog(struct VSM_data *vd, uint32_t **pp) +{ + uint32_t *p; + unsigned char t; + unsigned u; + int i; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + while (1) { + i = vsl_nextlog(vd, &p); + if (i != 1) + return (i); + u = VSL_ID(p); + t = VSL_TAG(p); + switch(t) { + case SLT_SessionOpen: + case SLT_ReqStart: + vbit_set(vd->vbm_client, u); + vbit_clr(vd->vbm_backend, u); + break; + case SLT_BackendOpen: + case SLT_BackendXID: + vbit_clr(vd->vbm_client, u); + vbit_set(vd->vbm_backend, u); + break; + default: + break; + } + if (vd->skip) { + --vd->skip; + continue; + } else if (vd->keep) { + if (--vd->keep == 0) + return (-1); + } + + if (vbit_test(vd->vbm_select, t)) { + *pp = p; + return (1); + } + if (vbit_test(vd->vbm_supress, t)) + continue; + if (vd->b_opt && !vbit_test(vd->vbm_backend, u)) + continue; + if (vd->c_opt && !vbit_test(vd->vbm_client, u)) + continue; + if (vd->regincl != NULL) { + i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p), + 0, 0, NULL, 0); + if (i == VRE_ERROR_NOMATCH) + continue; + } + if (vd->regexcl != NULL) { + i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p), + 0, 0, NULL, 0); + if (i != VRE_ERROR_NOMATCH) + continue; + } + *pp = p; + return (1); + } +} + +/*--------------------------------------------------------------------*/ + +int +VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv) +{ + int i; + unsigned u, l, s; + uint32_t *p; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + while (1) { + i = VSL_NextLog(vd, &p); + if (i != 1) + return (i); + u = VSL_ID(p); + l = VSL_LEN(p); + s = 0; + if (vbit_test(vd->vbm_backend, u)) + s |= VSL_S_BACKEND; + if (vbit_test(vd->vbm_client, u)) + s |= VSL_S_CLIENT; + if (func(priv, VSL_TAG(p), u, l, s, VSL_DATA(p))) + return (1); + } +} + +/*--------------------------------------------------------------------*/ + +int +VSL_H_Print(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, + unsigned spec, const char *ptr) +{ + FILE *fo = priv; + int type; + + assert(fo != NULL); + + type = (spec & VSL_S_CLIENT) ? 'c' : + (spec & VSL_S_BACKEND) ? 'b' : '-'; + + if (tag == SLT_Debug) { + fprintf(fo, "%5u %-12s %c \"", fd, VSL_tags[tag], type); + while (len-- > 0) { + if (*ptr >= ' ' && *ptr <= '~') + fprintf(fo, "%c", *ptr); + else + fprintf(fo, "%%%02x", (unsigned char)*ptr); + ptr++; + } + fprintf(fo, "\"\n"); + return (0); + } + fprintf(fo, "%5u %-12s %c %.*s\n", fd, VSL_tags[tag], type, len, ptr); + return (0); +} + +/*--------------------------------------------------------------------*/ + +int +VSM_OpenLog(struct VSM_data *vd) +{ + struct vsm_chunk *sha; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + sha = vsm_find_alloc(vd, VSL_CLASS, "", ""); + assert(sha != NULL); + + vd->log_start = VSM_PTR(sha); + vd->log_end = VSM_NEXT(sha); + vd->log_ptr = vd->log_start + 1; + + vd->last_seq = vd->log_start[0]; + VRMB(); + if (!vd->d_opt && vd->r_fd == -1) { + while (*vd->log_ptr != VSL_ENDMARKER) + vd->log_ptr = VSL_NEXT(vd->log_ptr); + } + return (0); +} Deleted: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 10:15:00 UTC (rev 4933) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c 2010-06-08 10:19:34 UTC (rev 4934) @@ -1,282 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2010 Redpill Linpro AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "config.h" - -#include "svnid.h" -SVNID("$Id$") - -#include -#include - -#include -#include -#include -#include - -#include "vas.h" -#include "vsm.h" -#include "vsl.h" -#include "vre.h" -#include "vbm.h" -#include "vqueue.h" -#include "miniobj.h" -#include "varnishapi.h" - -#include "vslapi.h" -#include "vmb.h" - -static int vsl_nextlog(struct VSM_data *vd, uint32_t **pp); - -/*--------------------------------------------------------------------*/ - -const char *VSL_tags[256] = { -#define SLTM(foo) [SLT_##foo] = #foo, -#include "vsl_tags.h" -#undef SLTM -}; - -/*--------------------------------------------------------------------*/ - -void -VSL_Select(const struct VSM_data *vd, unsigned tag) -{ - - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - vbit_set(vd->vbm_select, tag); -} - - -/*--------------------------------------------------------------------*/ - -void -VSL_NonBlocking(struct VSM_data *vd, int nb) -{ - if (nb) - vd->flags |= F_NON_BLOCKING; - else - vd->flags &= ~F_NON_BLOCKING; -} - -/*--------------------------------------------------------------------*/ - -static int -vsl_nextlog(struct VSM_data *vd, uint32_t **pp) -{ - unsigned w, l; - uint32_t t; - int i; - - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - if (vd->r_fd != -1) { - assert(vd->rbuflen >= 8); - i = read(vd->r_fd, vd->rbuf, 8); - if (i != 8) - return (-1); - l = 2 + VSL_WORDS(VSL_LEN(vd->rbuf)); - if (vd->rbuflen < l) { - l += 256; - vd->rbuf = realloc(vd->rbuf, l * 4); - assert(vd->rbuf != NULL); - vd->rbuflen = l; - } - i = read(vd->r_fd, vd->rbuf + 2, l * 4 - 8); - if (i != l) - return (-1); - *pp = vd->rbuf; - return (1); - } - for (w = 0; w < TIMEOUT_USEC;) { - t = *vd->log_ptr; - - if (t == VSL_WRAPMARKER || - (t == VSL_ENDMARKER && vd->last_seq != vd->log_start[0])) { - vd->log_ptr = vd->log_start + 1; - vd->last_seq = vd->log_start[0]; - VRMB(); - continue; - } - if (t == VSL_ENDMARKER) { - if (vd->flags & F_NON_BLOCKING) - return (-1); - w += SLEEP_USEC; - AZ(usleep(SLEEP_USEC)); - continue; - } - *pp = (void*)(uintptr_t)vd->log_ptr; /* Loose volatile */ - vd->log_ptr = VSL_NEXT(vd->log_ptr); - return (1); - } - *pp = NULL; - return (0); -} - -int -VSL_NextLog(struct VSM_data *vd, uint32_t **pp) -{ - uint32_t *p; - unsigned char t; - unsigned u; - int i; - - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - while (1) { - i = vsl_nextlog(vd, &p); - if (i != 1) - return (i); - u = VSL_ID(p); - t = VSL_TAG(p); - switch(t) { - case SLT_SessionOpen: - case SLT_ReqStart: - vbit_set(vd->vbm_client, u); - vbit_clr(vd->vbm_backend, u); - break; - case SLT_BackendOpen: - case SLT_BackendXID: - vbit_clr(vd->vbm_client, u); - vbit_set(vd->vbm_backend, u); - break; - default: - break; - } - if (vd->skip) { - --vd->skip; - continue; - } else if (vd->keep) { - if (--vd->keep == 0) - return (-1); - } - - if (vbit_test(vd->vbm_select, t)) { - *pp = p; - return (1); - } - if (vbit_test(vd->vbm_supress, t)) - continue; - if (vd->b_opt && !vbit_test(vd->vbm_backend, u)) - continue; - if (vd->c_opt && !vbit_test(vd->vbm_client, u)) - continue; - if (vd->regincl != NULL) { - i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p), - 0, 0, NULL, 0); - if (i == VRE_ERROR_NOMATCH) - continue; - } - if (vd->regexcl != NULL) { - i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p), - 0, 0, NULL, 0); - if (i != VRE_ERROR_NOMATCH) - continue; - } - *pp = p; - return (1); - } -} - -/*--------------------------------------------------------------------*/ - -int -VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv) -{ - int i; - unsigned u, l, s; - uint32_t *p; - - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - while (1) { - i = VSL_NextLog(vd, &p); - if (i != 1) - return (i); - u = VSL_ID(p); - l = VSL_LEN(p); - s = 0; - if (vbit_test(vd->vbm_backend, u)) - s |= VSL_S_BACKEND; - if (vbit_test(vd->vbm_client, u)) - s |= VSL_S_CLIENT; - if (func(priv, VSL_TAG(p), u, l, s, VSL_DATA(p))) - return (1); - } -} - -/*--------------------------------------------------------------------*/ - -int -VSL_H_Print(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, - unsigned spec, const char *ptr) -{ - FILE *fo = priv; - int type; - - assert(fo != NULL); - - type = (spec & VSL_S_CLIENT) ? 'c' : - (spec & VSL_S_BACKEND) ? 'b' : '-'; - - if (tag == SLT_Debug) { - fprintf(fo, "%5u %-12s %c \"", fd, VSL_tags[tag], type); - while (len-- > 0) { - if (*ptr >= ' ' && *ptr <= '~') - fprintf(fo, "%c", *ptr); - else - fprintf(fo, "%%%02x", (unsigned char)*ptr); - ptr++; - } - fprintf(fo, "\"\n"); - return (0); - } - fprintf(fo, "%5u %-12s %c %.*s\n", fd, VSL_tags[tag], type, len, ptr); - return (0); -} - -/*--------------------------------------------------------------------*/ - -int -VSM_OpenLog(struct VSM_data *vd) -{ - struct vsm_chunk *sha; - - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - sha = vsm_find_alloc(vd, VSL_CLASS, "", ""); - assert(sha != NULL); - - vd->log_start = VSM_PTR(sha); - vd->log_end = VSM_NEXT(sha); - vd->log_ptr = vd->log_start + 1; - - vd->last_seq = vd->log_start[0]; - VRMB(); - if (!vd->d_opt && vd->r_fd == -1) { - while (*vd->log_ptr != VSL_ENDMARKER) - vd->log_ptr = VSL_NEXT(vd->log_ptr); - } - return (0); -} Deleted: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 10:15:00 UTC (rev 4933) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c 2010-06-08 10:19:34 UTC (rev 4934) @@ -1,176 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2010 Redpill Linpro AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "config.h" - -#include "svnid.h" -SVNID("$Id$") - -#include -#include -#include - -#include "vas.h" -#include "vsm.h" -#include "vsc.h" -#include "vre.h" -#include "vqueue.h" -#include "miniobj.h" -#include "varnishapi.h" - -#include "vslapi.h" - -/*--------------------------------------------------------------------*/ - -struct vsc_main * -VSM_OpenStats(struct VSM_data *vd) -{ - struct vsm_chunk *sha; - - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - - sha = vsm_find_alloc(vd, VSC_CLASS, "", ""); - assert(sha != NULL); - return (VSM_PTR(sha)); -} - -/*-------------------------------------------------------------------- - * -1 -> unknown stats encountered. - */ - -static inline int -iter_test(const char *s1, const char *s2, int wc) -{ - - if (s1 == NULL) - return (0); - if (!wc) - return (strcmp(s1, s2)); - for (; *s1 != '\0' && *s1 == *s2; s1++, s2++) - continue; - return (*s1 != '\0'); -} - -static int -iter_call(const struct VSM_data *vd, vsl_stat_f *func, void *priv, - const struct vsl_statpt *const sp) -{ - struct vsl_sf *sf; - int good = vd->sf_init; - - if (VTAILQ_EMPTY(&vd->sf_list)) - return (func(priv, sp)); - - VTAILQ_FOREACH(sf, &vd->sf_list, next) { - if (iter_test(sf->class, sp->class, sf->flags & VSL_SF_CL_WC)) - continue; - if (iter_test(sf->ident, sp->ident, sf->flags & VSL_SF_ID_WC)) - continue; - if (iter_test(sf->name, sp->name, sf->flags & VSL_SF_NM_WC)) - continue; - if (sf->flags & VSL_SF_EXCL) - good = 0; - else - good = 1; - } - if (!good) - return (0); - return (func(priv, sp)); -} - -static int -iter_main(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, - void *priv) -{ - struct vsc_main *st = VSM_PTR(sha); - struct vsl_statpt sp; - int i; - - sp.class = ""; - sp.ident = ""; -#define VSC_F_MAIN(nn, tt, ll, ff, dd) \ - sp.name = #nn; \ - sp.fmt = #tt; \ - sp.flag = ff; \ - sp.desc = dd; \ - sp.ptr = &st->nn; \ - i = iter_call(vd, func, priv, &sp); \ - if (i) \ - return(i); -#include "vsc_fields.h" -#undef VSC_F_MAIN - return (0); -} - -static int -iter_sma(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, - void *priv) -{ - struct vsc_sma *st = VSM_PTR(sha); - struct vsl_statpt sp; - int i; - - sp.class = VSC_TYPE_SMA; - sp.ident = sha->ident; -#define VSC_F_SMA(nn, tt, ll, ff, dd) \ - sp.name = #nn; \ - sp.fmt = #tt; \ - sp.flag = ff; \ - sp.desc = dd; \ - sp.ptr = &st->nn; \ - i = iter_call(vd, func, priv, &sp); \ - if (i) \ - return(i); -#include "vsc_fields.h" -#undef VSC_F_SMA - return (0); -} - -int -VSL_IterStat(const struct VSM_data *vd, vsl_stat_f *func, void *priv) -{ - struct vsm_chunk *sha; - int i; - - i = 0; - VSM_FOREACH(sha, vd) { - CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); - if (strcmp(sha->class, VSC_CLASS)) - continue; - if (!strcmp(sha->type, VSC_TYPE_MAIN)) - i = iter_main(vd, sha, func, priv); - else if (!strcmp(sha->type, VSC_TYPE_SMA)) - i = iter_sma(vd, sha, func, priv); - else - i = -1; - if (i != 0) - break; - } - return (i); -} From phk at varnish-cache.org Tue Jun 8 10:31:30 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 12:31:30 +0200 Subject: r4935 - in trunk/varnish-cache: bin/varnishstat bin/varnishtest include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 12:31:30 +0200 (Tue, 08 Jun 2010) New Revision: 4935 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsc.c trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c Log: More wanton renaming, this time varnishapi::VSC Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-08 10:19:34 UTC (rev 4934) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-08 10:31:30 UTC (rev 4935) @@ -52,7 +52,7 @@ /*--------------------------------------------------------------------*/ static int -do_xml_cb(void *priv, const struct vsl_statpt * const pt) +do_xml_cb(void *priv, const struct vsc_point * const pt) { uint64_t val; @@ -83,7 +83,7 @@ now = time(NULL); (void)strftime(time_stamp, 20, "%Y-%m-%dT%H:%M:%S", localtime(&now)); printf("\n", time_stamp); - (void)VSL_IterStat(vd, do_xml_cb, NULL); + (void)VSC_Iter(vd, do_xml_cb, NULL); printf("\n"); } @@ -95,7 +95,7 @@ }; static int -do_once_cb(void *priv, const struct vsl_statpt * const pt) +do_once_cb(void *priv, const struct vsc_point * const pt) { struct once_priv *op; uint64_t val; @@ -129,13 +129,13 @@ op.up = VSL_stats->uptime; op.pad = 18; - (void)VSL_IterStat(vd, do_once_cb, &op); + (void)VSC_Iter(vd, do_once_cb, &op); } /*--------------------------------------------------------------------*/ static int -do_list_cb(void *priv, const struct vsl_statpt * const pt) +do_list_cb(void *priv, const struct vsc_point * const pt) { int i; @@ -159,7 +159,7 @@ fprintf(stderr, "Field name Description\n"); fprintf(stderr, "---------- -----------\n"); - (void)VSL_IterStat(vd, do_list_cb, NULL); + (void)VSC_Iter(vd, do_list_cb, NULL); } /*--------------------------------------------------------------------*/ @@ -204,7 +204,7 @@ once = 1; break; case 'f': - (void)VSL_Stat_Arg(vd, c, optarg); + (void)VSC_Arg(vd, c, optarg); break; case 'l': if (VSM_Open(vd, 1)) @@ -221,7 +221,7 @@ xml = 1; break; default: - if (VSL_Stat_Arg(vd, c, optarg) > 0) + if (VSC_Arg(vd, c, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-08 10:19:34 UTC (rev 4934) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-08 10:31:30 UTC (rev 4935) @@ -66,7 +66,7 @@ static VTAILQ_HEAD(, pt) pthead = VTAILQ_HEAD_INITIALIZER(pthead); static int -do_curses_cb(void *priv, const struct vsl_statpt * const sp) +do_curses_cb(void *priv, const struct vsc_point * const sp) { struct pt *pt; char buf[128]; @@ -110,7 +110,7 @@ free(pt); } - (void)VSL_IterStat(vd, do_curses_cb, NULL); + (void)VSC_Iter(vd, do_curses_cb, NULL); } static void Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-08 10:19:34 UTC (rev 4934) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-08 10:31:30 UTC (rev 4935) @@ -607,7 +607,7 @@ }; static int -do_stat_cb(void *priv, const struct vsl_statpt * const pt) +do_stat_cb(void *priv, const struct vsc_point * const pt) { struct stat_priv *sp = priv; const char *p = sp->target; @@ -655,7 +655,7 @@ for (i = 0; i < 10; i++, (void)usleep(100000)) { good = -1; - if (!VSL_IterStat(v->vd, do_stat_cb, &sp)) + if (!VSC_Iter(v->vd, do_stat_cb, &sp)) continue; good = 0; Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-08 10:19:34 UTC (rev 4934) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-08 10:31:30 UTC (rev 4935) @@ -68,7 +68,7 @@ /* * Configure which varnishd instance to access. * Can also be, and normally is done through the VSL_Log_arg() - * and VSL_Stat_Arg() functions. + * and VSC_Arg() functions. * Returns: * 1 on success * -1 on failure, with diagnostic on stderr. @@ -121,7 +121,31 @@ #define VSM_FOREACH(var, vd) \ for((var) = vsm_iter0((vd)); (var) != NULL; vsm_itern((vd), &(var))) +/*--------------------------------------------------------------------- + * VSC level access functions + */ +int VSC_Arg(struct VSM_data *vd, int arg, const char *opt); +struct vsc_main *VSM_OpenStats(struct VSM_data *vd); + +struct vsc_point { + const char *class; /* stat struct type */ + const char *ident; /* stat struct ident */ + const char *name; /* field name */ + const char *fmt; /* field format ("uint64_t") */ + int flag; /* 'a' = counter, 'i' = gauge */ + const char *desc; /* description */ + const volatile void *ptr; /* field value */ +}; + +typedef int vsc_iter_f(void *priv, const struct vsc_point *const pt); + +int VSC_Iter(const struct VSM_data *vd, vsc_iter_f *func, void *priv); + +/*--------------------------------------------------------------------- + * VSL level access functions + */ + /* shmlog.c */ typedef int vsl_handler(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr); @@ -139,25 +163,9 @@ int VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv); int VSL_NextLog(struct VSM_data *lh, uint32_t **pp); int VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt); -int VSL_Stat_Arg(struct VSM_data *vd, int arg, const char *opt); -struct vsc_main *VSM_OpenStats(struct VSM_data *vd); extern const char *VSL_tags[256]; -struct vsl_statpt { - const char *class; /* stat struct type */ - const char *ident; /* stat struct ident */ - const char *name; /* field name */ - const char *fmt; /* field format ("uint64_t") */ - int flag; /* 'a' = counter, 'i' = gauge */ - const char *desc; /* description */ - const volatile void *ptr; /* field value */ -}; - -typedef int vsl_stat_f(void *priv, const struct vsl_statpt *const pt); - -int VSL_IterStat(const struct VSM_data *vd, vsl_stat_f *func, void *priv); - /* base64.c */ void base64_init(void); int base64_decode(char *d, unsigned dlen, const char *s); Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 10:19:34 UTC (rev 4934) +++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 10:31:30 UTC (rev 4935) @@ -35,11 +35,14 @@ #include #include #include +#include +#include #include "vas.h" #include "vsm.h" #include "vsc.h" #include "vre.h" +#include "argv.h" #include "vqueue.h" #include "miniobj.h" #include "varnishapi.h" @@ -48,6 +51,101 @@ /*--------------------------------------------------------------------*/ +static int +vsc_sf_arg(struct VSM_data *vd, const char *opt) +{ + struct vsl_sf *sf; + char **av, *q, *p; + int i; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + + if (VTAILQ_EMPTY(&vd->sf_list)) { + if (*opt == '^') + vd->sf_init = 1; + } + + av = ParseArgv(opt, ARGV_COMMA); + AN(av); + if (av[0] != NULL) { + fprintf(stderr, "Parse error: %s", av[0]); + exit (1); + } + for (i = 1; av[i] != NULL; i++) { + ALLOC_OBJ(sf, VSL_SF_MAGIC); + AN(sf); + VTAILQ_INSERT_TAIL(&vd->sf_list, sf, next); + + p = av[i]; + if (*p == '^') { + sf->flags |= VSL_SF_EXCL; + p++; + } + + q = strchr(p, '.'); + if (q != NULL) { + *q++ = '\0'; + if (*p != '\0') + REPLACE(sf->class, p); + p = q; + if (*p != '\0') { + q = strchr(p, '.'); + if (q != NULL) { + *q++ = '\0'; + if (*p != '\0') + REPLACE(sf->ident, p); + p = q; + } + } + } + if (*p != '\0') { + REPLACE(sf->name, p); + } + + /* Check for wildcards */ + if (sf->class != NULL) { + q = strchr(sf->class, '*'); + if (q != NULL && q[1] == '\0') { + *q = '\0'; + sf->flags |= VSL_SF_CL_WC; + } + } + if (sf->ident != NULL) { + q = strchr(sf->ident, '*'); + if (q != NULL && q[1] == '\0') { + *q = '\0'; + sf->flags |= VSL_SF_ID_WC; + } + } + if (sf->name != NULL) { + q = strchr(sf->name, '*'); + if (q != NULL && q[1] == '\0') { + *q = '\0'; + sf->flags |= VSL_SF_NM_WC; + } + } + } + FreeArgv(av); + return (1); +} + +/*--------------------------------------------------------------------*/ + +int +VSC_Arg(struct VSM_data *vd, int arg, const char *opt) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + switch (arg) { + case 'f': return (vsc_sf_arg(vd, opt)); + case 'n': return (VSM_n_Arg(vd, opt)); + default: + return (0); + } +} + +/*--------------------------------------------------------------------*/ + struct vsc_main * VSM_OpenStats(struct VSM_data *vd) { @@ -78,8 +176,8 @@ } static int -iter_call(const struct VSM_data *vd, vsl_stat_f *func, void *priv, - const struct vsl_statpt *const sp) +iter_call(const struct VSM_data *vd, vsc_iter_f *func, void *priv, + const struct vsc_point *const sp) { struct vsl_sf *sf; int good = vd->sf_init; @@ -105,11 +203,11 @@ } static int -iter_main(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, +iter_main(const struct VSM_data *vd, struct vsm_chunk *sha, vsc_iter_f *func, void *priv) { struct vsc_main *st = VSM_PTR(sha); - struct vsl_statpt sp; + struct vsc_point sp; int i; sp.class = ""; @@ -129,11 +227,11 @@ } static int -iter_sma(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func, +iter_sma(const struct VSM_data *vd, struct vsm_chunk *sha, vsc_iter_f *func, void *priv) { struct vsc_sma *st = VSM_PTR(sha); - struct vsl_statpt sp; + struct vsc_point sp; int i; sp.class = VSC_TYPE_SMA; @@ -153,7 +251,7 @@ } int -VSL_IterStat(const struct VSM_data *vd, vsl_stat_f *func, void *priv) +VSC_Iter(const struct VSM_data *vd, vsc_iter_f *func, void *priv) { struct vsm_chunk *sha; int i; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 10:19:34 UTC (rev 4934) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 10:31:30 UTC (rev 4935) @@ -225,98 +225,3 @@ return (0); } } - -/*--------------------------------------------------------------------*/ - -static int -vsl_sf_arg(struct VSM_data *vd, const char *opt) -{ - struct vsl_sf *sf; - char **av, *q, *p; - int i; - - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - - if (VTAILQ_EMPTY(&vd->sf_list)) { - if (*opt == '^') - vd->sf_init = 1; - } - - av = ParseArgv(opt, ARGV_COMMA); - AN(av); - if (av[0] != NULL) { - fprintf(stderr, "Parse error: %s", av[0]); - exit (1); - } - for (i = 1; av[i] != NULL; i++) { - ALLOC_OBJ(sf, VSL_SF_MAGIC); - AN(sf); - VTAILQ_INSERT_TAIL(&vd->sf_list, sf, next); - - p = av[i]; - if (*p == '^') { - sf->flags |= VSL_SF_EXCL; - p++; - } - - q = strchr(p, '.'); - if (q != NULL) { - *q++ = '\0'; - if (*p != '\0') - REPLACE(sf->class, p); - p = q; - if (*p != '\0') { - q = strchr(p, '.'); - if (q != NULL) { - *q++ = '\0'; - if (*p != '\0') - REPLACE(sf->ident, p); - p = q; - } - } - } - if (*p != '\0') { - REPLACE(sf->name, p); - } - - /* Check for wildcards */ - if (sf->class != NULL) { - q = strchr(sf->class, '*'); - if (q != NULL && q[1] == '\0') { - *q = '\0'; - sf->flags |= VSL_SF_CL_WC; - } - } - if (sf->ident != NULL) { - q = strchr(sf->ident, '*'); - if (q != NULL && q[1] == '\0') { - *q = '\0'; - sf->flags |= VSL_SF_ID_WC; - } - } - if (sf->name != NULL) { - q = strchr(sf->name, '*'); - if (q != NULL && q[1] == '\0') { - *q = '\0'; - sf->flags |= VSL_SF_NM_WC; - } - } - } - FreeArgv(av); - return (1); -} - -/*--------------------------------------------------------------------*/ - -int -VSL_Stat_Arg(struct VSM_data *vd, int arg, const char *opt) -{ - - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - switch (arg) { - case 'f': return (vsl_sf_arg(vd, opt)); - case 'n': return (VSM_n_Arg(vd, opt)); - default: - return (0); - } -} From phk at varnish-cache.org Tue Jun 8 10:35:15 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 12:35:15 +0200 Subject: r4936 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 12:35:14 +0200 (Tue, 08 Jun 2010) New Revision: 4936 Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c trunk/varnish-cache/lib/libvarnishapi/vslapi.h trunk/varnish-cache/lib/libvarnishapi/vsm.c Log: One more vsl->vsc rename Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 10:31:30 UTC (rev 4935) +++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 10:35:14 UTC (rev 4936) @@ -54,7 +54,7 @@ static int vsc_sf_arg(struct VSM_data *vd, const char *opt) { - struct vsl_sf *sf; + struct vsc_sf *sf; char **av, *q, *p; int i; @@ -179,7 +179,7 @@ iter_call(const struct VSM_data *vd, vsc_iter_f *func, void *priv, const struct vsc_point *const sp) { - struct vsl_sf *sf; + struct vsc_sf *sf; int good = vd->sf_init; if (VTAILQ_EMPTY(&vd->sf_list)) Modified: trunk/varnish-cache/lib/libvarnishapi/vslapi.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 10:31:30 UTC (rev 4935) +++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 10:35:14 UTC (rev 4936) @@ -33,10 +33,10 @@ #define SLEEP_USEC (50*1000) #define TIMEOUT_USEC (5*1000*1000) -struct vsl_sf { +struct vsc_sf { unsigned magic; #define VSL_SF_MAGIC 0x558478dd - VTAILQ_ENTRY(vsl_sf) next; + VTAILQ_ENTRY(vsc_sf) next; int flags; #define VSL_SF_EXCL (1 << 0) #define VSL_SF_CL_WC (1 << 1) @@ -68,7 +68,7 @@ /* Stuff relating the stats fields start here */ int sf_init; - VTAILQ_HEAD(, vsl_sf) sf_list; + VTAILQ_HEAD(, vsc_sf) sf_list; /* Stuff relating the log records below here */ Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-08 10:31:30 UTC (rev 4935) +++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-08 10:35:14 UTC (rev 4936) @@ -139,7 +139,7 @@ void VSM_Delete(struct VSM_data *vd) { - struct vsl_sf *sf; + struct vsc_sf *sf; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); VSM_Close(vd); From phk at varnish-cache.org Tue Jun 8 11:34:54 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 13:34:54 +0200 Subject: r4937 - in trunk/varnish-cache: bin/varnishstat bin/varnishtest include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 13:34:54 +0200 (Tue, 08 Jun 2010) New Revision: 4937 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsc.c trunk/varnish-cache/lib/libvarnishapi/vslapi.h trunk/varnish-cache/lib/libvarnishapi/vsm.c Log: Redo the VSC api new-style. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-08 10:35:14 UTC (rev 4936) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-08 11:34:54 UTC (rev 4937) @@ -197,6 +197,7 @@ int delay = 1, once = 0, xml = 0; vd = VSM_New(); + VSC_Setup(vd); while ((c = getopt(argc, argv, VSL_STAT_ARGS "1f:lVw:x")) != -1) { switch (c) { @@ -207,7 +208,7 @@ (void)VSC_Arg(vd, c, optarg); break; case 'l': - if (VSM_Open(vd, 1)) + if (VSC_Open(vd, 1)) exit(1); list_fields(vd); exit(0); @@ -227,11 +228,10 @@ } } - if (VSM_Open(vd, 1)) + if (VSC_Open(vd, 1)) exit(1); - if ((VSL_stats = VSM_OpenStats(vd)) == NULL) - exit(1); + VSL_stats = VSC_Main(vd); if (xml) do_xml(vd); Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-08 10:35:14 UTC (rev 4936) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-08 11:34:54 UTC (rev 4937) @@ -67,8 +67,6 @@ struct vtclog *vl1; VTAILQ_ENTRY(varnish) list; - struct vsc_main *stats; - struct vsb *storage; struct vsb *args; @@ -262,6 +260,7 @@ char *r; v->vd = VSM_New(); + VSC_Setup(v->vd); /* Create listener socket */ nap = VSS_resolve("127.0.0.1", "0", &ap); @@ -362,11 +361,8 @@ vtc_log(v->vl, 0, "CLI auth command failed: %u %s", u, r); free(r); - if (v->stats != NULL) - VSM_Close(v->vd); (void)VSL_Log_Arg(v->vd, 'n', v->workdir); - AZ(VSM_Open(v->vd, 1)); - v->stats = VSM_OpenStats(v->vd); + AZ(VSC_Open(v->vd, 1)); } /********************************************************************** Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-08 10:35:14 UTC (rev 4936) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-08 11:34:54 UTC (rev 4937) @@ -125,9 +125,12 @@ * VSC level access functions */ +void VSC_Setup(struct VSM_data *vd); int VSC_Arg(struct VSM_data *vd, int arg, const char *opt); -struct vsc_main *VSM_OpenStats(struct VSM_data *vd); +int VSC_Open(struct VSM_data *vd, int diag); +struct vsc_main *VSC_Main(struct VSM_data *vd); + struct vsc_point { const char *class; /* stat struct type */ const char *ident; /* stat struct ident */ @@ -146,7 +149,6 @@ * VSL level access functions */ -/* shmlog.c */ typedef int vsl_handler(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr); #define VSL_S_CLIENT (1 << 0) Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 10:35:14 UTC (rev 4936) +++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 11:34:54 UTC (rev 4937) @@ -49,20 +49,75 @@ #include "vslapi.h" +struct vsc_sf { + unsigned magic; +#define VSL_SF_MAGIC 0x558478dd + VTAILQ_ENTRY(vsc_sf) next; + int flags; +#define VSL_SF_EXCL (1 << 0) +#define VSL_SF_CL_WC (1 << 1) +#define VSL_SF_ID_WC (1 << 2) +#define VSL_SF_NM_WC (1 << 3) + char *class; + char *ident; + char *name; +}; + +struct vsc { + unsigned magic; +#define VSC_MAGIC 0x3373554a + + int sf_init; + VTAILQ_HEAD(, vsc_sf) sf_list; + +}; + + /*--------------------------------------------------------------------*/ +void +VSC_Setup(struct VSM_data *vd) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + AZ(vd->vsc); + // XXX: AZ(vd->vsm); + ALLOC_OBJ(vd->vsc, VSC_MAGIC); + AN(vd->vsc); + VTAILQ_INIT(&vd->vsc->sf_list); +} + +void +vsc_delete(struct VSM_data *vd) +{ + struct vsc_sf *sf; + struct vsc *vsc = vd->vsc; + + CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); + while(!VTAILQ_EMPTY(&vsc->sf_list)) { + sf = VTAILQ_FIRST(&vsc->sf_list); + VTAILQ_REMOVE(&vsc->sf_list, sf, next); + free(sf->class); + free(sf->ident); + free(sf->name); + free(sf); + } +} + +/*--------------------------------------------------------------------*/ + static int -vsc_sf_arg(struct VSM_data *vd, const char *opt) +vsc_sf_arg(struct vsc *vsc, const char *opt) { struct vsc_sf *sf; char **av, *q, *p; int i; - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); - if (VTAILQ_EMPTY(&vd->sf_list)) { + if (VTAILQ_EMPTY(&vsc->sf_list)) { if (*opt == '^') - vd->sf_init = 1; + vsc->sf_init = 1; } av = ParseArgv(opt, ARGV_COMMA); @@ -74,7 +129,7 @@ for (i = 1; av[i] != NULL; i++) { ALLOC_OBJ(sf, VSL_SF_MAGIC); AN(sf); - VTAILQ_INSERT_TAIL(&vd->sf_list, sf, next); + VTAILQ_INSERT_TAIL(&vsc->sf_list, sf, next); p = av[i]; if (*p == '^') { @@ -134,10 +189,13 @@ int VSC_Arg(struct VSM_data *vd, int arg, const char *opt) { + struct vsc *vsc; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vsc = vd->vsc; + CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); switch (arg) { - case 'f': return (vsc_sf_arg(vd, opt)); + case 'f': return (vsc_sf_arg(vsc, opt)); case 'n': return (VSM_n_Arg(vd, opt)); default: return (0); @@ -146,12 +204,27 @@ /*--------------------------------------------------------------------*/ +int +VSC_Open(struct VSM_data *vd, int diag) +{ + int i; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + AN(vd->vsc); + + i = VSM_Open(vd, diag); + return (i); +} + +/*--------------------------------------------------------------------*/ + struct vsc_main * -VSM_OpenStats(struct VSM_data *vd) +VSC_Main(struct VSM_data *vd) { struct vsm_chunk *sha; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + CHECK_OBJ_NOTNULL(vd->vsc, VSC_MAGIC); sha = vsm_find_alloc(vd, VSC_CLASS, "", ""); assert(sha != NULL); @@ -176,16 +249,20 @@ } static int -iter_call(const struct VSM_data *vd, vsc_iter_f *func, void *priv, +iter_call(const struct vsc *vsc, vsc_iter_f *func, void *priv, const struct vsc_point *const sp) { struct vsc_sf *sf; - int good = vd->sf_init; + int good; - if (VTAILQ_EMPTY(&vd->sf_list)) + CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); + + if (VTAILQ_EMPTY(&vsc->sf_list)) return (func(priv, sp)); - VTAILQ_FOREACH(sf, &vd->sf_list, next) { + good = vsc->sf_init; + + VTAILQ_FOREACH(sf, &vsc->sf_list, next) { if (iter_test(sf->class, sp->class, sf->flags & VSL_SF_CL_WC)) continue; if (iter_test(sf->ident, sp->ident, sf->flags & VSL_SF_ID_WC)) @@ -203,13 +280,17 @@ } static int -iter_main(const struct VSM_data *vd, struct vsm_chunk *sha, vsc_iter_f *func, +iter_main(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func, void *priv) { - struct vsc_main *st = VSM_PTR(sha); + struct vsc_main *st; struct vsc_point sp; int i; + CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); + CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); + + st = VSM_PTR(sha); sp.class = ""; sp.ident = ""; #define VSC_F_MAIN(nn, tt, ll, ff, dd) \ @@ -218,7 +299,7 @@ sp.flag = ff; \ sp.desc = dd; \ sp.ptr = &st->nn; \ - i = iter_call(vd, func, priv, &sp); \ + i = iter_call(vsc, func, priv, &sp); \ if (i) \ return(i); #include "vsc_fields.h" @@ -227,13 +308,17 @@ } static int -iter_sma(const struct VSM_data *vd, struct vsm_chunk *sha, vsc_iter_f *func, +iter_sma(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func, void *priv) { - struct vsc_sma *st = VSM_PTR(sha); + struct vsc_sma *st; struct vsc_point sp; int i; + CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); + CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); + st = VSM_PTR(sha); + sp.class = VSC_TYPE_SMA; sp.ident = sha->ident; #define VSC_F_SMA(nn, tt, ll, ff, dd) \ @@ -242,7 +327,7 @@ sp.flag = ff; \ sp.desc = dd; \ sp.ptr = &st->nn; \ - i = iter_call(vd, func, priv, &sp); \ + i = iter_call(vsc, func, priv, &sp); \ if (i) \ return(i); #include "vsc_fields.h" @@ -253,18 +338,23 @@ int VSC_Iter(const struct VSM_data *vd, vsc_iter_f *func, void *priv) { + struct vsc *vsc; struct vsm_chunk *sha; int i; + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vsc = vd->vsc; + CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); + i = 0; VSM_FOREACH(sha, vd) { CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); if (strcmp(sha->class, VSC_CLASS)) continue; if (!strcmp(sha->type, VSC_TYPE_MAIN)) - i = iter_main(vd, sha, func, priv); + i = iter_main(vsc, sha, func, priv); else if (!strcmp(sha->type, VSC_TYPE_SMA)) - i = iter_sma(vd, sha, func, priv); + i = iter_sma(vsc, sha, func, priv); else i = -1; if (i != 0) Modified: trunk/varnish-cache/lib/libvarnishapi/vslapi.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 10:35:14 UTC (rev 4936) +++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 11:34:54 UTC (rev 4937) @@ -33,19 +33,7 @@ #define SLEEP_USEC (50*1000) #define TIMEOUT_USEC (5*1000*1000) -struct vsc_sf { - unsigned magic; -#define VSL_SF_MAGIC 0x558478dd - VTAILQ_ENTRY(vsc_sf) next; - int flags; -#define VSL_SF_EXCL (1 << 0) -#define VSL_SF_CL_WC (1 << 1) -#define VSL_SF_ID_WC (1 << 2) -#define VSL_SF_NM_WC (1 << 3) - char *class; - char *ident; - char *name; -}; +struct vsc; struct VSM_data { unsigned magic; @@ -67,8 +55,7 @@ /* Stuff relating the stats fields start here */ - int sf_init; - VTAILQ_HEAD(, vsc_sf) sf_list; + struct vsc *vsc; /* Stuff relating the log records below here */ @@ -119,3 +106,6 @@ struct vsm_chunk *vsm_find_alloc(const struct VSM_data *vd, const char *class, const char *type, const char *ident); + +void vsc_delete(struct VSM_data *vd); + Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-08 10:35:14 UTC (rev 4936) +++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-08 11:34:54 UTC (rev 4937) @@ -87,8 +87,6 @@ vd->rbuf = malloc(vd->rbuflen * 4); assert(vd->rbuf != NULL); - VTAILQ_INIT(&vd->sf_list); - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); return (vd); } @@ -139,7 +137,6 @@ void VSM_Delete(struct VSM_data *vd) { - struct vsc_sf *sf; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); VSM_Close(vd); @@ -151,14 +148,7 @@ free(vd->rbuf); free(vd->fname); - while(!VTAILQ_EMPTY(&vd->sf_list)) { - sf = VTAILQ_FIRST(&vd->sf_list); - VTAILQ_REMOVE(&vd->sf_list, sf, next); - free(sf->class); - free(sf->ident); - free(sf->name); - free(sf); - } + vsc_delete(vd); free(vd); } From phk at varnish-cache.org Tue Jun 8 11:43:52 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 13:43:52 +0200 Subject: r4938 - in trunk/varnish-cache: include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 13:43:51 +0200 (Tue, 08 Jun 2010) New Revision: 4938 Modified: trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsc.c Log: Document VSC api Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-08 11:34:54 UTC (rev 4937) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-08 11:43:51 UTC (rev 4938) @@ -113,23 +113,58 @@ void *VSM_Find_Chunk(struct VSM_data *vd, const char *class, const char *type, const char *ident, unsigned *lenp); + /* + * Find a given chunk in the shared memory. + * Returns pointer or NULL. + * Lenp, if non-NULL, is set to length of chunk. + */ + void VSM_Close(struct VSM_data *vd); + /* + * Unmap shared memory + * Deallocate all storage (including VSC and VSL allocations) + */ struct vsm_chunk *vsm_iter0(const struct VSM_data *vd); void vsm_itern(const struct VSM_data *vd, struct vsm_chunk **pp); #define VSM_FOREACH(var, vd) \ - for((var) = vsm_iter0((vd)); (var) != NULL; vsm_itern((vd), &(var))) + for((var) = vsm_iter0((vd)); (var) != NULL; vsm_itern((vd), &(var))) + /* + * Iterate over all chunks in shared memory + * var = "struct vsm_chunk *" + * vd = "struct VSM_data" + */ + /*--------------------------------------------------------------------- * VSC level access functions */ void VSC_Setup(struct VSM_data *vd); + /* + * Setup vd for use with VSC functions. + */ + int VSC_Arg(struct VSM_data *vd, int arg, const char *opt); + /* + * Handle standard stat-presenter arguments + * Return: + * -1 error + * 0 not handled + * 1 Handled. + */ + int VSC_Open(struct VSM_data *vd, int diag); + /* + * Open shared memory for VSC processing. + * args and returns as VSM_Open() + */ struct vsc_main *VSC_Main(struct VSM_data *vd); + /* + * return Main stats structure + */ struct vsc_point { const char *class; /* stat struct type */ @@ -144,6 +179,10 @@ typedef int vsc_iter_f(void *priv, const struct vsc_point *const pt); int VSC_Iter(const struct VSM_data *vd, vsc_iter_f *func, void *priv); + /* + * Iterate over all statistics counters, calling "func" for + * each counter not suppressed by any "-f" arguments. + */ /*--------------------------------------------------------------------- * VSL level access functions Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 11:34:54 UTC (rev 4937) +++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 11:43:51 UTC (rev 4938) @@ -35,7 +35,6 @@ #include #include #include -#include #include #include "vas.h" @@ -107,12 +106,15 @@ /*--------------------------------------------------------------------*/ static int -vsc_sf_arg(struct vsc *vsc, const char *opt) +vsc_sf_arg(struct VSM_data *vd, const char *opt) { + struct vsc *vsc; struct vsc_sf *sf; char **av, *q, *p; int i; + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vsc = vd->vsc; CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); if (VTAILQ_EMPTY(&vsc->sf_list)) { @@ -123,8 +125,8 @@ av = ParseArgv(opt, ARGV_COMMA); AN(av); if (av[0] != NULL) { - fprintf(stderr, "Parse error: %s", av[0]); - exit (1); + vd->diag(vd->priv, "Parse error: %s", av[0]); + return (-1); } for (i = 1; av[i] != NULL; i++) { ALLOC_OBJ(sf, VSL_SF_MAGIC); @@ -189,13 +191,11 @@ int VSC_Arg(struct VSM_data *vd, int arg, const char *opt) { - struct vsc *vsc; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - vsc = vd->vsc; - CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); + AN(vd->vsc); switch (arg) { - case 'f': return (vsc_sf_arg(vsc, opt)); + case 'f': return (vsc_sf_arg(vd, opt)); case 'n': return (VSM_n_Arg(vd, opt)); default: return (0); From phk at varnish-cache.org Tue Jun 8 12:07:47 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 8 Jun 2010 14:07:47 +0200 Subject: r4939 - in trunk/varnish-cache: bin include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-08 14:07:47 +0200 (Tue, 08 Jun 2010) New Revision: 4939 Modified: trunk/varnish-cache/bin/flint.lnt trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsc.c trunk/varnish-cache/lib/libvarnishapi/vslapi.h trunk/varnish-cache/lib/libvarnishapi/vsm.c Log: FlexeLint VSC api Modified: trunk/varnish-cache/bin/flint.lnt =================================================================== --- trunk/varnish-cache/bin/flint.lnt 2010-06-08 11:43:51 UTC (rev 4938) +++ trunk/varnish-cache/bin/flint.lnt 2010-06-08 12:07:47 UTC (rev 4939) @@ -11,8 +11,8 @@ -esym(528, svnid) // Sym not ref --efile(451, shmlog_tags.h) // No include guard --efile(451, stat_field.h) // No include guard +-efile(451, vsl_tags.h) // No include guard +-efile(451, vsc_fields.h) // No include guard /////////////////////////////////////////////////////////////////////// // assert() support, common to libvarnish and libvarnishapi Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-08 11:43:51 UTC (rev 4938) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-08 12:07:47 UTC (rev 4939) @@ -106,13 +106,13 @@ * -1 failure to reopen. */ -struct vsm_head *VSM_Head(struct VSM_data *vd); +struct vsm_head *VSM_Head(const struct VSM_data *vd); /* * Return the head of the VSM. */ -void *VSM_Find_Chunk(struct VSM_data *vd, const char *class, const char *type, - const char *ident, unsigned *lenp); +void *VSM_Find_Chunk(const struct VSM_data *vd, const char *class, + const char *type, const char *ident, unsigned *lenp); /* * Find a given chunk in the shared memory. * Returns pointer or NULL. @@ -161,7 +161,7 @@ * args and returns as VSM_Open() */ -struct vsc_main *VSC_Main(struct VSM_data *vd); +struct vsc_main *VSC_Main(const struct VSM_data *vd); /* * return Main stats structure */ Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 11:43:51 UTC (rev 4938) +++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 12:07:47 UTC (rev 4939) @@ -87,7 +87,7 @@ } void -vsc_delete(struct VSM_data *vd) +vsc_delete(const struct VSM_data *vd) { struct vsc_sf *sf; struct vsc *vsc = vd->vsc; @@ -106,7 +106,7 @@ /*--------------------------------------------------------------------*/ static int -vsc_sf_arg(struct VSM_data *vd, const char *opt) +vsc_sf_arg(const struct VSM_data *vd, const char *opt) { struct vsc *vsc; struct vsc_sf *sf; @@ -219,7 +219,7 @@ /*--------------------------------------------------------------------*/ struct vsc_main * -VSC_Main(struct VSM_data *vd) +VSC_Main(const struct VSM_data *vd) { struct vsm_chunk *sha; Modified: trunk/varnish-cache/lib/libvarnishapi/vslapi.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 11:43:51 UTC (rev 4938) +++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 12:07:47 UTC (rev 4939) @@ -107,5 +107,5 @@ struct vsm_chunk *vsm_find_alloc(const struct VSM_data *vd, const char *class, const char *type, const char *ident); -void vsc_delete(struct VSM_data *vd); +void vsc_delete(const struct VSM_data *vd); Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-08 11:43:51 UTC (rev 4938) +++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-08 12:07:47 UTC (rev 4939) @@ -48,7 +48,6 @@ #include "vsm.h" #include "vre.h" #include "vbm.h" -#include "vqueue.h" #include "miniobj.h" #include "varnishapi.h" @@ -84,7 +83,7 @@ vd->r_fd = -1; /* XXX: Allocate only if -r option given ? */ vd->rbuflen = 256; /* XXX ?? */ - vd->rbuf = malloc(vd->rbuflen * 4); + vd->rbuf = malloc(vd->rbuflen * 4L); assert(vd->rbuf != NULL); CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); @@ -206,7 +205,7 @@ vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size; while(slh.alloc_seq == 0) - usleep(50000); /* XXX limit total sleep */ + (void)usleep(50000); /* XXX limit total sleep */ vd->alloc_seq = slh.alloc_seq; return (0); } @@ -268,7 +267,7 @@ /*--------------------------------------------------------------------*/ struct vsm_head * -VSM_Head(struct VSM_data *vd) +VSM_Head(const struct VSM_data *vd) { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); @@ -302,8 +301,8 @@ /*--------------------------------------------------------------------*/ void * -VSM_Find_Chunk(struct VSM_data *vd, const char *class, const char *type, const char *ident, - unsigned *lenp) +VSM_Find_Chunk(const struct VSM_data *vd, const char *class, const char *type, + const char *ident, unsigned *lenp) { struct vsm_chunk *sha; From phk at varnish-cache.org Wed Jun 9 09:34:55 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 9 Jun 2010 11:34:55 +0200 Subject: r4940 - in trunk/varnish-cache: bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishsizes bin/varnishtop include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-09 11:34:55 +0200 (Wed, 09 Jun 2010) New Revision: 4940 Added: trunk/varnish-cache/lib/libvarnishapi/vsm_api.h Removed: trunk/varnish-cache/lib/libvarnishapi/vslapi.h Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/bin/varnishncsa/varnishncsa.c trunk/varnish-cache/bin/varnishreplay/varnishreplay.c trunk/varnish-cache/bin/varnishsizes/varnishsizes.c trunk/varnish-cache/bin/varnishtop/varnishtop.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/Makefile.am trunk/varnish-cache/lib/libvarnishapi/vsc.c trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c trunk/varnish-cache/lib/libvarnishapi/vsm.c Log: Delaminate the VSL api from the VSM api Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-09 09:34:55 UTC (rev 4940) @@ -322,6 +322,7 @@ struct VSM_data *vd; vd = VSM_New(); + VSL_Setup(vd); while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) { switch (o) { @@ -338,7 +339,7 @@ } } - if (VSM_OpenLog(vd)) + if (VSL_Open(vd, 1)) exit(1); log_ten = log(10.0); Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-09 09:34:55 UTC (rev 4940) @@ -41,7 +41,6 @@ #include #include #include -#include #include "compat/daemon.h" @@ -80,7 +79,7 @@ #define F_MATCH (1 << 1) static int match_tag = -1; -static vre_t *match_re; +static const vre_t *match_re; static void h_order_finish(int fd) @@ -195,7 +194,7 @@ } static void -do_order(struct VSM_data *vd, int argc, char * const *argv) +do_order(const struct VSM_data *vd, int argc, char * const *argv) { int i; const char *error; @@ -268,7 +267,7 @@ } static void -do_write(struct VSM_data *vd, const char *w_arg, int a_flag) +do_write(const struct VSM_data *vd, const char *w_arg, int a_flag) { int fd, i, l; uint32_t *p; @@ -282,7 +281,7 @@ break; if (i > 0) { l = VSL_LEN(p); - i = write(fd, p, 8 + VSL_WORDS(l) * 4); + i = write(fd, p, 8L + VSL_WORDS(l) * 4L); if (i < 0) { perror(w_arg); exit(1); @@ -319,6 +318,7 @@ struct VSM_data *vd; vd = VSM_New(); + VSL_Setup(vd); while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDoP:uVw:")) != -1) { switch (c) { @@ -361,7 +361,7 @@ if (o_flag && w_arg != NULL) usage(); - if (VSM_OpenLog(vd)) + if (VSL_Open(vd, 1)) exit(1); if (P_arg && (pfh = vpf_open(P_arg, 0644, NULL)) == NULL) { Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-09 09:34:55 UTC (rev 4940) @@ -528,6 +528,7 @@ FILE *of; vd = VSM_New(); + VSL_Setup(vd); while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDP:Vw:f")) != -1) { switch (c) { @@ -565,7 +566,7 @@ VSL_Log_Arg(vd, 'c', optarg); - if (VSM_OpenLog(vd)) + if (VSL_Open(vd, 1)) exit(1); if (P_arg && (pfh = vpf_open(P_arg, 0644, NULL)) == NULL) { Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-09 09:34:55 UTC (rev 4940) @@ -721,6 +721,7 @@ const char *address = NULL; vd = VSM_New(); + VSL_Setup(vd); debug = 0; VSL_Log_Arg(vd, 'c', NULL); @@ -743,7 +744,7 @@ usage(); } - if (VSM_OpenLog(vd)) + if (VSL_Open(vd, 1)) exit(1); addr_info = init_connection(address); Modified: trunk/varnish-cache/bin/varnishsizes/varnishsizes.c =================================================================== --- trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-09 09:34:55 UTC (rev 4940) @@ -323,6 +323,7 @@ struct VSM_data *vd; vd = VSM_New(); + VSL_Setup(vd); while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) { switch (o) { @@ -339,7 +340,7 @@ } } - if (VSM_OpenLog(vd)) + if (VSL_Open(vd, 1)) exit(1); log_ten = log(10.0); Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-09 09:34:55 UTC (rev 4940) @@ -308,6 +308,7 @@ int o, once = 0; vd = VSM_New(); + VSL_Setup(vd); while ((o = getopt(argc, argv, VSL_LOG_ARGS "1fV")) != -1) { switch (o) { @@ -328,7 +329,7 @@ } } - if (VSM_OpenLog(vd)) + if (VSL_Open(vd, 1)) exit (1); if (once) { Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-09 09:34:55 UTC (rev 4940) @@ -188,6 +188,21 @@ * VSL level access functions */ +void VSL_Setup(struct VSM_data *vd); + /* + * Setup vd for use with VSL functions. + */ + +int VSL_Open(struct VSM_data *vd, int diag); + /* + * Attempt to open and map the shared memory file. + * If diag is non-zero, diagnostics are emitted. + * Returns: + * 0 on success + * != 0 on failure + */ + + typedef int vsl_handler(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr); #define VSL_S_CLIENT (1 << 0) @@ -199,10 +214,9 @@ vsl_handler VSL_H_Print; struct VSM_data; void VSL_Select(const struct VSM_data *vd, unsigned tag); -int VSM_OpenLog(struct VSM_data *vd); -void VSL_NonBlocking(struct VSM_data *vd, int nb); -int VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv); -int VSL_NextLog(struct VSM_data *lh, uint32_t **pp); +void VSL_NonBlocking(const struct VSM_data *vd, int nb); +int VSL_Dispatch(const struct VSM_data *vd, vsl_handler *func, void *priv); +int VSL_NextLog(const struct VSM_data *lh, uint32_t **pp); int VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt); extern const char *VSL_tags[256]; Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-09 09:34:55 UTC (rev 4940) @@ -7,7 +7,8 @@ libvarnishapi_la_LDFLAGS = -version-info 1:0:0 libvarnishapi_la_SOURCES = \ - vslapi.h \ + vsm_api.h \ + vsl_api.h \ \ ../libvarnish/assert.c \ ../libvarnish/argv.c \ Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-09 09:34:55 UTC (rev 4940) @@ -40,13 +40,12 @@ #include "vas.h" #include "vsm.h" #include "vsc.h" -#include "vre.h" #include "argv.h" #include "vqueue.h" #include "miniobj.h" #include "varnishapi.h" -#include "vslapi.h" +#include "vsm_api.h" struct vsc_sf { unsigned magic; @@ -80,18 +79,23 @@ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); AZ(vd->vsc); - // XXX: AZ(vd->vsm); + AZ(vd->vsl); ALLOC_OBJ(vd->vsc, VSC_MAGIC); AN(vd->vsc); VTAILQ_INIT(&vd->vsc->sf_list); } +/*--------------------------------------------------------------------*/ + void -vsc_delete(const struct VSM_data *vd) +vsc_delete(struct VSM_data *vd) { struct vsc_sf *sf; - struct vsc *vsc = vd->vsc; + struct vsc *vsc; + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vsc = vd->vsc; + vd->vsc = NULL; CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); while(!VTAILQ_EMPTY(&vsc->sf_list)) { sf = VTAILQ_FIRST(&vsc->sf_list); @@ -99,7 +103,7 @@ free(sf->class); free(sf->ident); free(sf->name); - free(sf); + FREE_OBJ(sf); } } Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-09 09:34:55 UTC (rev 4940) @@ -45,15 +45,13 @@ #include "vsl.h" #include "vre.h" #include "vbm.h" -#include "vqueue.h" #include "miniobj.h" #include "varnishapi.h" -#include "vslapi.h" +#include "vsm_api.h" +#include "vsl_api.h" #include "vmb.h" -static int vsl_nextlog(struct VSM_data *vd, uint32_t **pp); - /*--------------------------------------------------------------------*/ const char *VSL_tags[256] = { @@ -65,72 +63,132 @@ /*--------------------------------------------------------------------*/ void +VSL_Setup(struct VSM_data *vd) +{ + struct vsl *vsl; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + AZ(vd->vsc); + AZ(vd->vsl); + ALLOC_OBJ(vsl, VSL_MAGIC); + AN(vsl); + + vd->vsl = vsl; + + vsl->regflags = 0; + + /* XXX: Allocate only if log access */ + vsl->vbm_client = vbit_init(4096); + vsl->vbm_backend = vbit_init(4096); + vsl->vbm_supress = vbit_init(256); + vsl->vbm_select = vbit_init(256); + + vsl->r_fd = -1; + /* XXX: Allocate only if -r option given ? */ + vsl->rbuflen = 256; /* XXX ?? */ + vsl->rbuf = malloc(vsl->rbuflen * 4L); + assert(vsl->rbuf != NULL); +} + +/*--------------------------------------------------------------------*/ + +void +vsl_delete(struct VSM_data *vd) +{ + struct vsl *vsl; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vsl = vd->vsl; + vd->vsl = NULL; + CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); + + vbit_destroy(vsl->vbm_client); + vbit_destroy(vsl->vbm_backend); + vbit_destroy(vsl->vbm_supress); + vbit_destroy(vsl->vbm_select); + free(vsl->rbuf); + + FREE_OBJ(vsl); +} + +/*--------------------------------------------------------------------*/ + +void VSL_Select(const struct VSM_data *vd, unsigned tag) { + struct vsl *vsl; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - vbit_set(vd->vbm_select, tag); + vsl = vd->vsl; + CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); + vbit_set(vsl->vbm_select, tag); } /*--------------------------------------------------------------------*/ void -VSL_NonBlocking(struct VSM_data *vd, int nb) +VSL_NonBlocking(const struct VSM_data *vd, int nb) { + struct vsl *vsl; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vsl = vd->vsl; + CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); if (nb) - vd->flags |= F_NON_BLOCKING; + vsl->flags |= F_NON_BLOCKING; else - vd->flags &= ~F_NON_BLOCKING; + vsl->flags &= ~F_NON_BLOCKING; } /*--------------------------------------------------------------------*/ static int -vsl_nextlog(struct VSM_data *vd, uint32_t **pp) +vsl_nextlog(struct vsl *vsl, uint32_t **pp) { unsigned w, l; uint32_t t; int i; - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - if (vd->r_fd != -1) { - assert(vd->rbuflen >= 8); - i = read(vd->r_fd, vd->rbuf, 8); + CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); + + if (vsl->r_fd != -1) { + assert(vsl->rbuflen >= 8); + i = read(vsl->r_fd, vsl->rbuf, 8); if (i != 8) return (-1); - l = 2 + VSL_WORDS(VSL_LEN(vd->rbuf)); - if (vd->rbuflen < l) { + l = 2 + VSL_WORDS(VSL_LEN(vsl->rbuf)); + if (vsl->rbuflen < l) { l += 256; - vd->rbuf = realloc(vd->rbuf, l * 4); - assert(vd->rbuf != NULL); - vd->rbuflen = l; + vsl->rbuf = realloc(vsl->rbuf, l * 4L); + assert(vsl->rbuf != NULL); + vsl->rbuflen = l; } - i = read(vd->r_fd, vd->rbuf + 2, l * 4 - 8); + i = read(vsl->r_fd, vsl->rbuf + 2, l * 4L - 8L); if (i != l) return (-1); - *pp = vd->rbuf; + *pp = vsl->rbuf; return (1); } for (w = 0; w < TIMEOUT_USEC;) { - t = *vd->log_ptr; + t = *vsl->log_ptr; if (t == VSL_WRAPMARKER || - (t == VSL_ENDMARKER && vd->last_seq != vd->log_start[0])) { - vd->log_ptr = vd->log_start + 1; - vd->last_seq = vd->log_start[0]; + (t == VSL_ENDMARKER && vsl->last_seq != vsl->log_start[0])) { + vsl->log_ptr = vsl->log_start + 1; + vsl->last_seq = vsl->log_start[0]; VRMB(); continue; } if (t == VSL_ENDMARKER) { - if (vd->flags & F_NON_BLOCKING) + if (vsl->flags & F_NON_BLOCKING) return (-1); w += SLEEP_USEC; AZ(usleep(SLEEP_USEC)); continue; } - *pp = (void*)(uintptr_t)vd->log_ptr; /* Loose volatile */ - vd->log_ptr = VSL_NEXT(vd->log_ptr); + *pp = (void*)(uintptr_t)vsl->log_ptr; /* Loose volatile */ + vsl->log_ptr = VSL_NEXT(vsl->log_ptr); return (1); } *pp = NULL; @@ -138,16 +196,20 @@ } int -VSL_NextLog(struct VSM_data *vd, uint32_t **pp) +VSL_NextLog(const struct VSM_data *vd, uint32_t **pp) { + struct vsl *vsl; uint32_t *p; unsigned char t; unsigned u; int i; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vsl = vd->vsl; + CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); + while (1) { - i = vsl_nextlog(vd, &p); + i = vsl_nextlog(vsl, &p); if (i != 1) return (i); u = VSL_ID(p); @@ -155,43 +217,43 @@ switch(t) { case SLT_SessionOpen: case SLT_ReqStart: - vbit_set(vd->vbm_client, u); - vbit_clr(vd->vbm_backend, u); + vbit_set(vsl->vbm_client, u); + vbit_clr(vsl->vbm_backend, u); break; case SLT_BackendOpen: case SLT_BackendXID: - vbit_clr(vd->vbm_client, u); - vbit_set(vd->vbm_backend, u); + vbit_clr(vsl->vbm_client, u); + vbit_set(vsl->vbm_backend, u); break; default: break; } - if (vd->skip) { - --vd->skip; + if (vsl->skip) { + --vsl->skip; continue; - } else if (vd->keep) { - if (--vd->keep == 0) + } else if (vsl->keep) { + if (--vsl->keep == 0) return (-1); } - if (vbit_test(vd->vbm_select, t)) { + if (vbit_test(vsl->vbm_select, t)) { *pp = p; return (1); } - if (vbit_test(vd->vbm_supress, t)) + if (vbit_test(vsl->vbm_supress, t)) continue; - if (vd->b_opt && !vbit_test(vd->vbm_backend, u)) + if (vsl->b_opt && !vbit_test(vsl->vbm_backend, u)) continue; - if (vd->c_opt && !vbit_test(vd->vbm_client, u)) + if (vsl->c_opt && !vbit_test(vsl->vbm_client, u)) continue; - if (vd->regincl != NULL) { - i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p), + if (vsl->regincl != NULL) { + i = VRE_exec(vsl->regincl, VSL_DATA(p), VSL_LEN(p), 0, 0, NULL, 0); if (i == VRE_ERROR_NOMATCH) continue; } - if (vd->regexcl != NULL) { - i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p), + if (vsl->regexcl != NULL) { + i = VRE_exec(vsl->regincl, VSL_DATA(p), VSL_LEN(p), 0, 0, NULL, 0); if (i != VRE_ERROR_NOMATCH) continue; @@ -204,13 +266,17 @@ /*--------------------------------------------------------------------*/ int -VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv) +VSL_Dispatch(const struct VSM_data *vd, vsl_handler *func, void *priv) { + struct vsl *vsl; int i; unsigned u, l, s; uint32_t *p; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vsl = vd->vsl; + CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); + while (1) { i = VSL_NextLog(vd, &p); if (i != 1) @@ -218,9 +284,9 @@ u = VSL_ID(p); l = VSL_LEN(p); s = 0; - if (vbit_test(vd->vbm_backend, u)) + if (vbit_test(vsl->vbm_backend, u)) s |= VSL_S_BACKEND; - if (vbit_test(vd->vbm_client, u)) + if (vbit_test(vsl->vbm_client, u)) s |= VSL_S_CLIENT; if (func(priv, VSL_TAG(p), u, l, s, VSL_DATA(p))) return (1); @@ -260,23 +326,32 @@ /*--------------------------------------------------------------------*/ int -VSM_OpenLog(struct VSM_data *vd) +VSL_Open(struct VSM_data *vd, int diag) { + struct vsl *vsl; struct vsm_chunk *sha; + int i; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vsl = vd->vsl; + CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); + + i = VSM_Open(vd, diag); + if (i) + return (i); + sha = vsm_find_alloc(vd, VSL_CLASS, "", ""); assert(sha != NULL); - vd->log_start = VSM_PTR(sha); - vd->log_end = VSM_NEXT(sha); - vd->log_ptr = vd->log_start + 1; + vsl->log_start = VSM_PTR(sha); + vsl->log_end = VSM_NEXT(sha); + vsl->log_ptr = vsl->log_start + 1; - vd->last_seq = vd->log_start[0]; + vsl->last_seq = vsl->log_start[0]; VRMB(); - if (!vd->d_opt && vd->r_fd == -1) { - while (*vd->log_ptr != VSL_ENDMARKER) - vd->log_ptr = VSL_NEXT(vd->log_ptr); + if (!vsl->d_opt && vsl->r_fd == -1) { + while (*vsl->log_ptr != VSL_ENDMARKER) + vsl->log_ptr = VSL_NEXT(vsl->log_ptr); } return (0); } Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-09 09:34:55 UTC (rev 4940) @@ -44,28 +44,27 @@ #include #include "vas.h" -#include "argv.h" #include "vin.h" #include "vre.h" #include "vbm.h" -#include "vqueue.h" #include "miniobj.h" #include "varnishapi.h" -#include "vslapi.h" +#include "vsm_api.h" +#include "vsl_api.h" /*--------------------------------------------------------------------*/ static int -vsl_r_arg(struct VSM_data *vd, const char *opt) +vsl_r_arg(const struct VSM_data *vd, const char *opt) { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); if (!strcmp(opt, "-")) - vd->r_fd = STDIN_FILENO; + vd->vsl->r_fd = STDIN_FILENO; else - vd->r_fd = open(opt, O_RDONLY); - if (vd->r_fd < 0) { + vd->vsl->r_fd = open(opt, O_RDONLY); + if (vd->vsl->r_fd < 0) { perror(opt); return (-1); } @@ -75,7 +74,7 @@ /*--------------------------------------------------------------------*/ static int -vsl_IX_arg(struct VSM_data *vd, const char *opt, int arg) +vsl_IX_arg(const struct VSM_data *vd, const char *opt, int arg) { vre_t **rp; const char *error; @@ -83,14 +82,14 @@ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); if (arg == 'I') - rp = &vd->regincl; + rp = &vd->vsl->regincl; else - rp = &vd->regexcl; + rp = &vd->vsl->regexcl; if (*rp != NULL) { fprintf(stderr, "Option %c can only be given once", arg); return (-1); } - *rp = VRE_compile(opt, vd->regflags, &error, &erroroffset); + *rp = VRE_compile(opt, vd->vsl->regflags, &error, &erroroffset); if (*rp == NULL) { fprintf(stderr, "Illegal regex: %s\n", error); return (-1); @@ -101,17 +100,17 @@ /*--------------------------------------------------------------------*/ static int -vsl_ix_arg(struct VSM_data *vd, const char *opt, int arg) +vsl_ix_arg(const struct VSM_data *vd, const char *opt, int arg) { int i, j, l; const char *b, *e, *p, *q; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); /* If first option is 'i', set all bits for supression */ - if (arg == 'i' && !(vd->flags & F_SEEN_IX)) + if (arg == 'i' && !(vd->vsl->flags & F_SEEN_IX)) for (i = 0; i < 256; i++) - vbit_set(vd->vbm_supress, i); - vd->flags |= F_SEEN_IX; + vbit_set(vd->vsl->vbm_supress, i); + vd->vsl->flags |= F_SEEN_IX; for (b = opt; *b; b = e) { while (isspace(*b)) @@ -136,9 +135,9 @@ continue; if (arg == 'x') - vbit_set(vd->vbm_supress, i); + vbit_set(vd->vsl->vbm_supress, i); else - vbit_clr(vd->vbm_supress, i); + vbit_clr(vd->vsl->vbm_supress, i); break; } if (i == 256) { @@ -153,7 +152,7 @@ /*--------------------------------------------------------------------*/ static int -vsl_s_arg(struct VSM_data *vd, const char *opt) +vsl_s_arg(const struct VSM_data *vd, const char *opt) { char *end; @@ -162,7 +161,7 @@ fprintf(stderr, "number required for -s\n"); return (-1); } - vd->skip = strtoul(opt, &end, 10); + vd->vsl->skip = strtoul(opt, &end, 10); if (*end != '\0') { fprintf(stderr, "invalid number for -s\n"); return (-1); @@ -173,7 +172,7 @@ /*--------------------------------------------------------------------*/ static int -vsl_k_arg(struct VSM_data *vd, const char *opt) +vsl_k_arg(const struct VSM_data *vd, const char *opt) { char *end; @@ -182,7 +181,7 @@ fprintf(stderr, "number required for -k\n"); return (-1); } - vd->keep = strtoul(opt, &end, 10); + vd->vsl->keep = strtoul(opt, &end, 10); if (*end != '\0') { fprintf(stderr, "invalid number for -k\n"); return (-1); @@ -198,11 +197,11 @@ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); switch (arg) { - case 'b': vd->b_opt = !vd->b_opt; return (1); - case 'c': vd->c_opt = !vd->c_opt; return (1); + case 'b': vd->vsl->b_opt = !vd->vsl->b_opt; return (1); + case 'c': vd->vsl->c_opt = !vd->vsl->c_opt; return (1); case 'd': - vd->d_opt = !vd->d_opt; - vd->flags |= F_NON_BLOCKING; + vd->vsl->d_opt = !vd->vsl->d_opt; + vd->vsl->flags |= F_NON_BLOCKING; return (1); case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg)); case 'k': return (vsl_k_arg(vd, opt)); @@ -210,15 +209,15 @@ case 'r': return (vsl_r_arg(vd, opt)); case 's': return (vsl_s_arg(vd, opt)); case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg)); - case 'C': vd->regflags = VRE_CASELESS; return (1); + case 'C': vd->vsl->regflags = VRE_CASELESS; return (1); case 'L': - vd->L_opt = strtoul(opt, NULL, 0); - if (vd->L_opt < 1024 || vd->L_opt > 65000) { + vd->vsl->L_opt = strtoul(opt, NULL, 0); + if (vd->vsl->L_opt < 1024 || vd->vsl->L_opt > 65000) { fprintf(stderr, "%s\n", VIN_L_MSG); exit (1); } free(vd->n_opt); - vd->n_opt = vin_L_arg(vd->L_opt); + vd->n_opt = vin_L_arg(vd->vsl->L_opt); assert(vd->n_opt != NULL); return (1); default: Deleted: trunk/varnish-cache/lib/libvarnishapi/vslapi.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-09 09:34:55 UTC (rev 4940) @@ -1,111 +0,0 @@ -/*- - * Copyright (c) 2006 Verdens Gang AS - * Copyright (c) 2006-2010 Redpill Linpro AS - * All rights reserved. - * - * Author: Poul-Henning Kamp - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $Id$ - */ - -/* Parameters */ -#define SLEEP_USEC (50*1000) -#define TIMEOUT_USEC (5*1000*1000) - -struct vsc; - -struct VSM_data { - unsigned magic; -#define VSM_MAGIC 0x6e3bd69b - - vsm_diag_f *diag; - void *priv; - - char *n_opt; - char *fname; - - - struct stat fstat; - - int vsl_fd; - struct vsm_head *vsl_lh; - void *vsl_end; - unsigned alloc_seq; - - /* Stuff relating the stats fields start here */ - - struct vsc *vsc; - - /* Stuff relating the log records below here */ - - volatile uint32_t *log_start; - volatile uint32_t *log_end; - volatile uint32_t *log_ptr; - - volatile uint32_t last_seq; - - /* for -r option */ - int r_fd; - unsigned rbuflen; - uint32_t *rbuf; - - unsigned L_opt; - int b_opt; - int c_opt; - int d_opt; - - unsigned flags; -#define F_SEEN_IX (1 << 0) -#define F_NON_BLOCKING (1 << 1) - - /* - * These two bitmaps mark fd's as belonging to client or backend - * transactions respectively. - */ - struct vbitmap *vbm_client; - struct vbitmap *vbm_backend; - - /* - * Bit map of programatically selected tags, that cannot be suppressed. - * This way programs can make sure they will see certain tags, even - * if the user tries to supress them with -x/-X - */ - struct vbitmap *vbm_select; /* index: tag */ - - /* Bit map of tags selected/supressed with -[iIxX] options */ - struct vbitmap *vbm_supress; /* index: tag */ - - int regflags; - vre_t *regincl; - vre_t *regexcl; - - unsigned long skip; - unsigned long keep; -}; - -struct vsm_chunk *vsm_find_alloc(const struct VSM_data *vd, const char *class, - const char *type, const char *ident); - -void vsc_delete(const struct VSM_data *vd); - Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-08 12:07:47 UTC (rev 4939) +++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-09 09:34:55 UTC (rev 4940) @@ -46,12 +46,11 @@ #include "vas.h" #include "vin.h" #include "vsm.h" -#include "vre.h" #include "vbm.h" #include "miniobj.h" #include "varnishapi.h" -#include "vslapi.h" +#include "vsm_api.h" #ifndef MAP_HASSEMAPHORE #define MAP_HASSEMAPHORE 0 /* XXX Linux */ @@ -72,20 +71,6 @@ vd->vsl_fd = -1; - vd->regflags = 0; - - /* XXX: Allocate only if log access */ - vd->vbm_client = vbit_init(4096); - vd->vbm_backend = vbit_init(4096); - vd->vbm_supress = vbit_init(256); - vd->vbm_select = vbit_init(256); - - vd->r_fd = -1; - /* XXX: Allocate only if -r option given ? */ - vd->rbuflen = 256; /* XXX ?? */ - vd->rbuf = malloc(vd->rbuflen * 4L); - assert(vd->rbuf != NULL); - CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); return (vd); } @@ -138,16 +123,16 @@ { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + VSM_Close(vd); - vbit_destroy(vd->vbm_client); - vbit_destroy(vd->vbm_backend); - vbit_destroy(vd->vbm_supress); - vbit_destroy(vd->vbm_select); + free(vd->n_opt); - free(vd->rbuf); free(vd->fname); - vsc_delete(vd); + if (vd->vsc != NULL) + vsc_delete(vd); + if (vd->vsl != NULL) + vsl_delete(vd); free(vd); } Copied: trunk/varnish-cache/lib/libvarnishapi/vsm_api.h (from rev 4939, trunk/varnish-cache/lib/libvarnishapi/vslapi.h) =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm_api.h (rev 0) +++ trunk/varnish-cache/lib/libvarnishapi/vsm_api.h 2010-06-09 09:34:55 UTC (rev 4940) @@ -0,0 +1,66 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2010 Redpill Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id$ + */ + +/* Parameters */ +#define SLEEP_USEC (50*1000) +#define TIMEOUT_USEC (5*1000*1000) + +struct vsc; + +struct VSM_data { + unsigned magic; +#define VSM_MAGIC 0x6e3bd69b + + vsm_diag_f *diag; + void *priv; + + char *n_opt; + char *fname; + + + struct stat fstat; + + int vsl_fd; + struct vsm_head *vsl_lh; + void *vsl_end; + unsigned alloc_seq; + + /* Stuff relating the stats fields start here */ + + struct vsc *vsc; + struct vsl *vsl; +}; + +struct vsm_chunk *vsm_find_alloc(const struct VSM_data *vd, const char *class, + const char *type, const char *ident); + +void vsc_delete(struct VSM_data *vd); +void vsl_delete(struct VSM_data *vd); From phk at varnish-cache.org Wed Jun 9 09:37:59 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 9 Jun 2010 11:37:59 +0200 Subject: r4941 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-09 11:37:58 +0200 (Wed, 09 Jun 2010) New Revision: 4941 Added: trunk/varnish-cache/lib/libvarnishapi/vsl_api.h Log: Hmm, not sure SVN and I fully agree on "svn cp" and "svn mv" commands. Add this file explicitly. Added: trunk/varnish-cache/lib/libvarnishapi/vsl_api.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_api.h (rev 0) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_api.h 2010-06-09 09:37:58 UTC (rev 4941) @@ -0,0 +1,81 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2010 Redpill Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: vsm_api.h -1 $ + */ + +struct vsl { + unsigned magic; +#define VSL_MAGIC 0x7a31db38 + + /* Stuff relating the log records below here */ + + volatile uint32_t *log_start; + volatile uint32_t *log_end; + volatile uint32_t *log_ptr; + + volatile uint32_t last_seq; + + /* for -r option */ + int r_fd; + unsigned rbuflen; + uint32_t *rbuf; + + unsigned L_opt; + int b_opt; + int c_opt; + int d_opt; + + unsigned flags; +#define F_SEEN_IX (1 << 0) +#define F_NON_BLOCKING (1 << 1) + + /* + * These two bitmaps mark fd's as belonging to client or backend + * transactions respectively. + */ + struct vbitmap *vbm_client; + struct vbitmap *vbm_backend; + + /* + * Bit map of programatically selected tags, that cannot be suppressed. + * This way programs can make sure they will see certain tags, even + * if the user tries to supress them with -x/-X + */ + struct vbitmap *vbm_select; /* index: tag */ + + /* Bit map of tags selected/supressed with -[iIxX] options */ + struct vbitmap *vbm_supress; /* index: tag */ + + int regflags; + vre_t *regincl; + vre_t *regexcl; + + unsigned long skip; + unsigned long keep; +}; From phk at varnish-cache.org Wed Jun 9 11:28:34 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 9 Jun 2010 13:28:34 +0200 Subject: r4942 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-09 13:28:33 +0200 (Wed, 09 Jun 2010) New Revision: 4942 Modified: trunk/varnish-cache/lib/libvarnishapi/base64.c Log: Add necessary include Modified: trunk/varnish-cache/lib/libvarnishapi/base64.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/base64.c 2010-06-09 09:37:58 UTC (rev 4941) +++ trunk/varnish-cache/lib/libvarnishapi/base64.c 2010-06-09 11:28:33 UTC (rev 4942) @@ -9,6 +9,7 @@ #include "svnid.h" SVNID("$Id$") +#include #include #include "varnishapi.h" From phk at varnish-cache.org Wed Jun 9 12:08:36 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 9 Jun 2010 14:08:36 +0200 Subject: r4943 - in trunk/varnish-cache: include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-09 14:08:35 +0200 (Wed, 09 Jun 2010) New Revision: 4943 Modified: trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/base64.c Log: Include stdint.h in varnishapi.h, that's easier. Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-09 11:28:33 UTC (rev 4942) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-09 12:08:35 UTC (rev 4943) @@ -32,6 +32,8 @@ #ifndef VARNISHAPI_H_INCLUDED #define VARNISHAPI_H_INCLUDED +#include + #include "vsl.h" /* Modified: trunk/varnish-cache/lib/libvarnishapi/base64.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/base64.c 2010-06-09 11:28:33 UTC (rev 4942) +++ trunk/varnish-cache/lib/libvarnishapi/base64.c 2010-06-09 12:08:35 UTC (rev 4943) @@ -9,7 +9,6 @@ #include "svnid.h" SVNID("$Id$") -#include #include #include "varnishapi.h" From phk at varnish-cache.org Wed Jun 9 12:13:58 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 9 Jun 2010 14:13:58 +0200 Subject: r4944 - trunk/varnish-cache/include Message-ID: Author: phk Date: 2010-06-09 14:13:57 +0200 (Wed, 09 Jun 2010) New Revision: 4944 Modified: trunk/varnish-cache/include/vct.h Log: Another necessary Modified: trunk/varnish-cache/include/vct.h =================================================================== --- trunk/varnish-cache/include/vct.h 2010-06-09 12:08:35 UTC (rev 4943) +++ trunk/varnish-cache/include/vct.h 2010-06-09 12:13:57 UTC (rev 4944) @@ -29,6 +29,8 @@ * $Id$ */ +#include + /* from libvarnish/vct.c */ #define VCT_SP (1<<0) From phk at varnish-cache.org Wed Jun 9 14:02:30 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 9 Jun 2010 16:02:30 +0200 Subject: r4945 - trunk/varnish-cache/include Message-ID: Author: phk Date: 2010-06-09 16:02:30 +0200 (Wed, 09 Jun 2010) New Revision: 4945 Modified: trunk/varnish-cache/include/Makefile.am Log: Add a couple of missing includes Modified: trunk/varnish-cache/include/Makefile.am =================================================================== --- trunk/varnish-cache/include/Makefile.am 2010-06-09 12:13:57 UTC (rev 4944) +++ trunk/varnish-cache/include/Makefile.am 2010-06-09 14:02:30 UTC (rev 4945) @@ -9,6 +9,7 @@ varnishapi.h nobase_noinst_HEADERS = \ + argv.h \ binary_heap.h \ cli.h \ cli_common.h \ @@ -40,6 +41,7 @@ vct.h \ vend.h \ vev.h \ + vin.h \ vlu.h \ vbm.h \ vmb.h \ From perbu at varnish-cache.org Thu Jun 10 17:03:29 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Thu, 10 Jun 2010 19:03:29 +0200 Subject: r4946 - trunk/varnish-cache/doc/sphinx/reference Message-ID: Author: perbu Date: 2010-06-10 19:03:28 +0200 (Thu, 10 Jun 2010) New Revision: 4946 Modified: trunk/varnish-cache/doc/sphinx/reference/varnishd.rst Log: man varnishd was missing the -C option Modified: trunk/varnish-cache/doc/sphinx/reference/varnishd.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/varnishd.rst 2010-06-09 14:02:30 UTC (rev 4945) +++ trunk/varnish-cache/doc/sphinx/reference/varnishd.rst 2010-06-10 17:03:28 UTC (rev 4946) @@ -44,6 +44,9 @@ Use the specified host as backend server. If port is not specified, the default is 8080. +-C Print VCL code compiled to C language and exit. Specify the VCL file + to compile with the -f option. + -d Enables debugging mode: The parent process runs in the foreground with a CLI connection on stdin/stdout, and the child process must be started explicitly with a CLI command. Terminating the parent process will also terminate the child. From perbu at varnish-cache.org Thu Jun 10 21:19:45 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Thu, 10 Jun 2010 23:19:45 +0200 Subject: r4947 - trunk/varnish-cache/doc/sphinx/tutorial Message-ID: Author: perbu Date: 2010-06-10 23:19:45 +0200 (Thu, 10 Jun 2010) New Revision: 4947 Modified: trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst Log: Some text on purging and bans. I guess we would need to rename url.purge at some point. This is quite confusing. Modified: trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst 2010-06-10 17:03:28 UTC (rev 4946) +++ trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst 2010-06-10 21:19:45 UTC (rev 4947) @@ -274,12 +274,91 @@ Purging ~~~~~~~ +One of the most effective way of increasing your hit ratio is to +increase the time-to-live (ttl) of your objects. In this twitterific +day of age serving content that is outdated is bad for business. +The solution is to notify Varnish when there is fresh content +available. This can be done through two mechanisms. HTTP purging and +bans. First, let me explain the HTTP purges. + + HTTP Purges ~~~~~~~~~~~ +An HTTP purge is similar to a HTTP GET request, except that the +*method* is PURGE. Actually you can call the method whatever you'd +like, but most people refer to this as purging. Squid supports the +same mechanism. In order to support purging in Varnish you need the +following VCL in place::: + + acl purge { + "localhost"; + "192.168.55.0/24"; + } + + sub vcl_recv { + # allow PURGE from localhost and 192.168.55... + + if (req.request == "PURGE") { + if (!client.ip ~ purge) { + error 405 "Not allowed."; + } + lookup; + } + } + + sub vcl_hit { + if (req.request == "PURGE") { + # Note that setting ttl to 0 is magical. + # the object is zapped from cache. + set obj.ttl = 0s; + error 200 "Purged."; + } + } + + sub vcl_miss { + if (req.request == "PURGE") { + + error 404 "Not in cache."; + } + } + + +So for vg.no to invalidate their front page they would call out to +varnish like this::: + + PURGE / HTTP/1.0 + Host: vg.no + +And Varnish would then discard the front page. If there are several +variants of the same URL in the cache however, only the matching +variant will be purged. To purge a gzip variant of the same page the +request would have to look like this::: + + PURGE / HTTP/1.0 + Host: vg.no + Accept-Encoding: gzip + Bans ~~~~ +There is another way to invalidate content. Bans. You can think of +bans as a sort of a filter. You *ban* certain content from being +served from your cache. You can ban content based on any metadata we +have. +Support for bans is built into Varnish and available in the CLI +interface. For VG to ban every png object belonging on vg.no they could +issue::: + purge req.http.host ~ ^vg.no && req.http.url ~ \.png$ + +Quite powerful, really. + +Bans are checked when we hit an object in the cache, but before we +deliver it. An object is only checked against newer bans. If you have +a lot of objects with long TTL in your cache you should be aware of a +potential performance impact of having many bans. + + From perbu at varnish-cache.org Fri Jun 11 09:07:35 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Fri, 11 Jun 2010 11:07:35 +0200 Subject: r4948 - trunk/varnish-cache/doc/sphinx/tutorial Message-ID: Author: perbu Date: 2010-06-11 11:07:34 +0200 (Fri, 11 Jun 2010) New Revision: 4948 Modified: trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst Log: Bans via VCL/HTTP Modified: trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst 2010-06-10 21:19:45 UTC (rev 4947) +++ trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst 2010-06-11 09:07:34 UTC (rev 4948) @@ -352,7 +352,7 @@ interface. For VG to ban every png object belonging on vg.no they could issue::: - purge req.http.host ~ ^vg.no && req.http.url ~ \.png$ + purge req.http.host == "vg.no" && req.http.url ~ "\.png$" Quite powerful, really. @@ -361,4 +361,22 @@ a lot of objects with long TTL in your cache you should be aware of a potential performance impact of having many bans. +You can also add bans to Varnish via HTTP. Doing so requires a bit of VCL.:: + sub vcl_recv { + if (req.request == "BAN") { + # Same ACL check as above: + if (!client.ip ~ purge) { + error 405 "Not allowed."; + } + purge("req.http.host == " req.http.host + "&& req.url == " req.url); + + # Throw a synthetic page so the + # request wont go to the backend. + error 200 "Ban added" + } + } + +This VCL sniplet enables Varnish to handle a HTTP BAN method. Adding a +ban on the URL, including the host part. From perbu at varnish-cache.org Sat Jun 12 08:26:18 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Sat, 12 Jun 2010 10:26:18 +0200 Subject: r4949 - in trunk/varnish-cache/doc/sphinx: reference tutorial Message-ID: Author: perbu Date: 2010-06-12 10:26:18 +0200 (Sat, 12 Jun 2010) New Revision: 4949 Added: trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst Modified: trunk/varnish-cache/doc/sphinx/reference/vcl.rst trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst trunk/varnish-cache/doc/sphinx/tutorial/index.rst trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst Log: advanced topics pointed out + some minor fixes Modified: trunk/varnish-cache/doc/sphinx/reference/vcl.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/reference/vcl.rst 2010-06-11 09:07:34 UTC (rev 4948) +++ trunk/varnish-cache/doc/sphinx/reference/vcl.rst 2010-06-12 08:26:18 UTC (rev 4949) @@ -1,3 +1,5 @@ +.. _reference-vcl: + === VCL === Added: trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst 2010-06-12 08:26:18 UTC (rev 4949) @@ -0,0 +1,63 @@ +.. _tutorial-advanced_topics: + +Advanced topics +--------------- + +This tutorial has covered the basics in Varnish. If you read through +it all you should now have the skills to run Varnish. + +Here is a short overview of topics that we haven't covered in the tutorial. + +More VCL +~~~~~~~~ + +VCL is a bit more complex then what we've covered so far. There are a +few more subroutines available and there a few actions that we haven't +discussed. For a complete(ish) guide to VCL have a look at the VCL man +page - `ref`:reference-vcl. + +Using Inline C to extend Varnish +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can use *inline C* to extend Varnish. Please note that you can +seriously mess up Varnish this way. The C code runs within the Varnish +Cache process so if your code generates a segfault the cache will crash. + +One of the first uses I saw of Inline C was logging to syslog.:: + + # The include statements must be outside the subroutines. + C{ + #include + }C + + sub vcl_something { + C{ + syslog(LOG_INFO, "Something happened at VCL line XX."); + }C + } + + +Edge Side Includes +~~~~~~~~~~~~~~~~~~ + +Varnish can cache create web pages by putting different pages +together. These *fragments* can have individual cache policies. If you +have a web site with a list showing the 5 most popular articles on +your site this list can probably be cached as a fragment and included +in all the other pages. Used properly it can dramatically increase +your hitrate and reduce the load on your servers. ESI looks like this:: + + + + The time is: + at this very moment. + + + +ESI is processed in vcl_fetch by using the *esi* keyword.:: + + sub vcl_fetch { + if (req.url == "/test.html") { + esi; /* Do ESI processing */ + } + } Modified: trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst 2010-06-11 09:07:34 UTC (rev 4948) +++ trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst 2010-06-12 08:26:18 UTC (rev 4949) @@ -116,6 +116,22 @@ varnishlog -i TxHeader -I ^Age +Overriding the time-to-live (ttl) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Sometimes your backend will misbehave. It might, depending on your +setup, be easier to override the ttl in Varnish then to fix your +somewhat cumbersome backend. + +You need VCL to identify the objects you want and then you set the +beresp.ttl to whatever you want.:: + + sub vcl_fetch { + if (req.url ~ "^/legacy_broken_cms/") { + set beresp.ttl = 5d; + } + } + Cookies ~~~~~~~ @@ -304,7 +320,7 @@ if (!client.ip ~ purge) { error 405 "Not allowed."; } - lookup; + return (lookup); } } @@ -324,6 +340,11 @@ } } +As you can see we have used to new VCL subroutines, vcl_hit and +vcl_miss. When we call lookup Varnish will try to lookup the object in +its cache. It will either hit an object or miss it and so the +corresponding subroutine is called. In vcl_hit the object that is +stored in cache is available and we can set the TTL. So for vg.no to invalidate their front page they would call out to varnish like this::: Modified: trunk/varnish-cache/doc/sphinx/tutorial/index.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/tutorial/index.rst 2010-06-11 09:07:34 UTC (rev 4948) +++ trunk/varnish-cache/doc/sphinx/tutorial/index.rst 2010-06-12 08:26:18 UTC (rev 4949) @@ -15,7 +15,7 @@ We assume you have a web server and a web application up and running and that you want to accelerate this application with Varnish. -Furthermore we assume you have read the :ref:`Installation` and that +Furthermore we assume you have read the :ref:`install-index` and that it is installed with the default configuration. @@ -31,6 +31,7 @@ increasing_your_hitrate.rst advanced_backend_servers.rst handling_misbehaving_servers.rst + advanced_topics.rst troubleshooting.rst .. todo:: Modified: trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst 2010-06-11 09:07:34 UTC (rev 4948) +++ trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst 2010-06-12 08:26:18 UTC (rev 4949) @@ -32,9 +32,11 @@ received and parsed. Its purpose is to decide whether or not to serve the request, how to do it, and, if applicable, which backend to use. -In vcl_recv you can also alter the request, dropping cookies, rewrite -headers. +In vcl_recv you can also alter the request. Typically you can alter +the cookies and add and remove request headers. +Note that in vcl_recv only the request object, req is availble. + vcl_fetch ~~~~~~~~~ @@ -43,6 +45,11 @@ trigger ESI processing, try alternate backend servers in case the request failed. +In vcl_fetch you still have the request object, req, available. There +is also a *backend response*, beresp. beresp will contain the HTTP +headers from the backend. + + actions ~~~~~~~ From perbu at varnish-cache.org Sat Jun 12 08:29:24 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Sat, 12 Jun 2010 10:29:24 +0200 Subject: r4950 - trunk/varnish-cache/doc/sphinx/tutorial Message-ID: Author: perbu Date: 2010-06-12 10:29:24 +0200 (Sat, 12 Jun 2010) New Revision: 4950 Modified: trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst Log: syntax error Modified: trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst 2010-06-12 08:26:18 UTC (rev 4949) +++ trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst 2010-06-12 08:29:24 UTC (rev 4950) @@ -14,7 +14,7 @@ VCL is a bit more complex then what we've covered so far. There are a few more subroutines available and there a few actions that we haven't discussed. For a complete(ish) guide to VCL have a look at the VCL man -page - `ref`:reference-vcl. +page - ref:`reference-vcl`. Using Inline C to extend Varnish ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From phk at varnish-cache.org Mon Jun 14 07:31:42 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 14 Jun 2010 09:31:42 +0200 Subject: r4951 - trunk/varnish-cache/bin/varnishstat Message-ID: Author: phk Date: 2010-06-14 09:31:42 +0200 (Mon, 14 Jun 2010) New Revision: 4951 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c Log: Don't check return value of curs_set(), appearantly the old SVID bug is still on the loose. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-12 08:29:24 UTC (rev 4950) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-14 07:31:42 UTC (rev 4951) @@ -141,7 +141,7 @@ AC(noecho()); AC(nonl()); AC(intrflush(stdscr, FALSE)); - AC(curs_set(0)); + (void)curs_set(0); /* XXX: too many implementations are bogus */ while (1) { /* From phk at varnish-cache.org Mon Jun 14 07:41:27 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 14 Jun 2010 09:41:27 +0200 Subject: r4952 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-14 09:41:26 +0200 (Mon, 14 Jun 2010) New Revision: 4952 Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c trunk/varnish-cache/lib/libvarnishapi/vsm_api.h Log: Rename vsm stuff from vsl to vsm for consistency Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-14 07:31:42 UTC (rev 4951) +++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-14 07:41:26 UTC (rev 4952) @@ -69,7 +69,7 @@ vd->diag = (vsm_diag_f*)fprintf; vd->priv = stderr; - vd->vsl_fd = -1; + vd->vsm_fd = -1; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); return (vd); @@ -140,24 +140,23 @@ /*--------------------------------------------------------------------*/ static int -vsl_open(struct VSM_data *vd, int diag) +vsm_open(struct VSM_data *vd, int diag) { int i; struct vsm_head slh; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - if (vd->vsl_lh != NULL) - return (0); + AZ(vd->vsm_head); - vd->vsl_fd = open(vd->fname, O_RDONLY); - if (vd->vsl_fd < 0) { + vd->vsm_fd = open(vd->fname, O_RDONLY); + if (vd->vsm_fd < 0) { if (diag) vd->diag(vd->priv, "Cannot open %s: %s\n", vd->fname, strerror(errno)); return (1); } - assert(fstat(vd->vsl_fd, &vd->fstat) == 0); + assert(fstat(vd->vsm_fd, &vd->fstat) == 0); if (!S_ISREG(vd->fstat.st_mode)) { if (diag) vd->diag(vd->priv, "%s is not a regular file\n", @@ -165,7 +164,7 @@ return (1); } - i = read(vd->vsl_fd, &slh, sizeof slh); + i = read(vd->vsm_fd, &slh, sizeof slh); if (i != sizeof slh) { if (diag) vd->diag(vd->priv, "Cannot read %s: %s\n", @@ -179,15 +178,15 @@ return (1); } - vd->vsl_lh = (void *)mmap(NULL, slh.shm_size, - PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsl_fd, 0); - if (vd->vsl_lh == MAP_FAILED) { + vd->vsm_head = (void *)mmap(NULL, slh.shm_size, + PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsm_fd, 0); + if (vd->vsm_head == MAP_FAILED) { if (diag) vd->diag(vd->priv, "Cannot mmap %s: %s\n", vd->fname, strerror(errno)); return (1); } - vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size; + vd->vsm_end = (uint8_t *)vd->vsm_head + slh.shm_size; while(slh.alloc_seq == 0) (void)usleep(50000); /* XXX limit total sleep */ @@ -203,7 +202,8 @@ { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - return (vsl_open(vd, diag)); + AZ(vd->vsm_head); + return (vsm_open(vd, diag)); } /*--------------------------------------------------------------------*/ @@ -213,13 +213,12 @@ { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - if (vd->vsl_lh == NULL) - return; - assert(0 == munmap((void*)vd->vsl_lh, vd->vsl_lh->shm_size)); - vd->vsl_lh = NULL; - assert(vd->vsl_fd >= 0); - assert(0 == close(vd->vsl_fd)); - vd->vsl_fd = -1; + AN(vd->vsm_head); + assert(0 == munmap((void*)vd->vsm_head, vd->vsm_head->shm_size)); + vd->vsm_head = NULL; + assert(vd->vsm_fd >= 0); + assert(0 == close(vd->vsm_fd)); + vd->vsm_fd = -1; } /*--------------------------------------------------------------------*/ @@ -231,7 +230,7 @@ int i; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - AN(vd->vsl_lh); + AN(vd->vsm_head); if (stat(vd->fname, &st)) return (0); @@ -241,10 +240,10 @@ VSM_Close(vd); for (i = 0; i < 5; i++) { /* XXX param */ - if (!vsl_open(vd, 0)) + if (!vsm_open(vd, 0)) return (1); } - if (vsl_open(vd, diag)) + if (vsm_open(vd, diag)) return (-1); return (1); } @@ -256,8 +255,8 @@ { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - AN(vd->vsl_lh); - return(vd->vsl_lh); + AN(vd->vsm_head); + return(vd->vsm_head); } @@ -269,7 +268,7 @@ struct vsm_chunk *sha; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - assert (vd->vsl_lh != NULL); + AN(vd->vsm_head); VSM_FOREACH(sha, vd) { CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); if (strcmp(sha->class, class)) @@ -307,10 +306,10 @@ { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - if (vd->alloc_seq != vd->vsl_lh->alloc_seq) + if (vd->alloc_seq != vd->vsm_head->alloc_seq) return(NULL); - CHECK_OBJ_NOTNULL(&vd->vsl_lh->head, VSM_CHUNK_MAGIC); - return (&vd->vsl_lh->head); + CHECK_OBJ_NOTNULL(&vd->vsm_head->head, VSM_CHUNK_MAGIC); + return (&vd->vsm_head->head); } void @@ -318,13 +317,13 @@ { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - if (vd->alloc_seq != vd->vsl_lh->alloc_seq) { + if (vd->alloc_seq != vd->vsm_head->alloc_seq) { *pp = NULL; return; } CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); *pp = VSM_NEXT(*pp); - if ((void*)(*pp) >= vd->vsl_end) { + if ((void*)(*pp) >= vd->vsm_end) { *pp = NULL; return; } Modified: trunk/varnish-cache/lib/libvarnishapi/vsm_api.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm_api.h 2010-06-14 07:31:42 UTC (rev 4951) +++ trunk/varnish-cache/lib/libvarnishapi/vsm_api.h 2010-06-14 07:41:26 UTC (rev 4952) @@ -48,9 +48,9 @@ struct stat fstat; - int vsl_fd; - struct vsm_head *vsl_lh; - void *vsl_end; + int vsm_fd; + struct vsm_head *vsm_head; + void *vsm_end; unsigned alloc_seq; /* Stuff relating the stats fields start here */ From phk at varnish-cache.org Mon Jun 14 08:03:45 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 14 Jun 2010 10:03:45 +0200 Subject: r4953 - in trunk/varnish-cache: bin/varnishadm bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishsizes bin/varnishstat bin/varnishtest bin/varnishtop include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-14 10:03:45 +0200 (Mon, 14 Jun 2010) New Revision: 4953 Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c trunk/varnish-cache/bin/varnishhist/varnishhist.c trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/bin/varnishncsa/varnishncsa.c trunk/varnish-cache/bin/varnishreplay/varnishreplay.c trunk/varnish-cache/bin/varnishsizes/varnishsizes.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/bin/varnishtop/varnishtop.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c Log: Cleanup around arg processing. Need to think a bit more about usage strings, before I continue. Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c =================================================================== --- trunk/varnish-cache/bin/varnishadm/varnishadm.c 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/bin/varnishadm/varnishadm.c 2010-06-14 08:03:45 UTC (rev 4953) @@ -244,7 +244,7 @@ if (n_arg != NULL) { vsd = VSM_New(); - assert(VSL_Log_Arg(vsd, 'n', n_arg)); + assert(VSL_Arg(vsd, 'n', n_arg)); if (!VSM_Open(vsd, 1)) { if (T_arg == NULL) { p = VSM_Find_Chunk(vsd, "Arg", "-T", "", NULL); Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c =================================================================== --- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-14 08:03:45 UTC (rev 4953) @@ -324,7 +324,7 @@ vd = VSM_New(); VSL_Setup(vd); - while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) { + while ((o = getopt(argc, argv, VSL_ARGS "Vw:")) != -1) { switch (o) { case 'V': varnish_version("varnishhist"); @@ -333,7 +333,7 @@ delay = atoi(optarg); break; default: - if (VSL_Log_Arg(vd, o, optarg) > 0) + if (VSL_Arg(vd, o, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-14 08:03:45 UTC (rev 4953) @@ -320,18 +320,18 @@ vd = VSM_New(); VSL_Setup(vd); - while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDoP:uVw:")) != -1) { + while ((c = getopt(argc, argv, VSL_ARGS "aDoP:uVw:")) != -1) { switch (c) { case 'a': a_flag = 1; break; case 'b': b_flag = 1; - AN(VSL_Log_Arg(vd, c, optarg)); + AN(VSL_Arg(vd, c, optarg)); break; case 'c': c_flag = 1; - AN(VSL_Log_Arg(vd, c, optarg)); + AN(VSL_Arg(vd, c, optarg)); break; case 'D': D_flag = 1; @@ -352,7 +352,7 @@ w_arg = optarg; break; default: - if (VSL_Log_Arg(vd, c, optarg) > 0) + if (VSL_Arg(vd, c, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c =================================================================== --- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-14 08:03:45 UTC (rev 4953) @@ -530,7 +530,7 @@ vd = VSM_New(); VSL_Setup(vd); - while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDP:Vw:f")) != -1) { + while ((c = getopt(argc, argv, VSL_ARGS "aDP:Vw:f")) != -1) { switch (c) { case 'a': a_flag = 1; @@ -558,13 +558,13 @@ /* XXX: Silently ignored: it's required anyway */ break; default: - if (VSL_Log_Arg(vd, c, optarg) > 0) + if (VSL_Arg(vd, c, optarg) > 0) break; usage(); } } - VSL_Log_Arg(vd, 'c', optarg); + VSL_Arg(vd, 'c', optarg); if (VSL_Open(vd, 1)) exit(1); Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c =================================================================== --- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-14 08:03:45 UTC (rev 4953) @@ -724,7 +724,7 @@ VSL_Setup(vd); debug = 0; - VSL_Log_Arg(vd, 'c', NULL); + VSL_Arg(vd, 'c', NULL); while ((c = getopt(argc, argv, "a:Dr:n:")) != -1) { switch (c) { case 'a': @@ -734,7 +734,7 @@ ++debug; break; default: - if (VSL_Log_Arg(vd, c, optarg) > 0) + if (VSL_Arg(vd, c, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/bin/varnishsizes/varnishsizes.c =================================================================== --- trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-14 08:03:45 UTC (rev 4953) @@ -325,7 +325,7 @@ vd = VSM_New(); VSL_Setup(vd); - while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) { + while ((o = getopt(argc, argv, VSL_ARGS "Vw:")) != -1) { switch (o) { case 'V': varnish_version("varnishsizes"); @@ -334,7 +334,7 @@ delay = atoi(optarg); break; default: - if (VSL_Log_Arg(vd, o, optarg) > 0) + if (VSL_Arg(vd, o, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-14 08:03:45 UTC (rev 4953) @@ -169,7 +169,9 @@ { #define FMT " %-28s # %s\n" fprintf(stderr, "usage: varnishstat " - "[-1lV] [-f field_list] [-n varnish_name] [-w delay]\n"); + "[-1lV] [-f field_list] " + VSC_n_USAGE " " + "[-w delay]\n"); fprintf(stderr, FMT, "-1", "Print the statistics once and exit"); fprintf(stderr, FMT, "-f field_list", "Comma separated list of fields to display. "); @@ -199,7 +201,7 @@ vd = VSM_New(); VSC_Setup(vd); - while ((c = getopt(argc, argv, VSL_STAT_ARGS "1f:lVw:x")) != -1) { + while ((c = getopt(argc, argv, VSC_ARGS "1f:lVw:x")) != -1) { switch (c) { case '1': once = 1; Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-14 08:03:45 UTC (rev 4953) @@ -361,7 +361,7 @@ vtc_log(v->vl, 0, "CLI auth command failed: %u %s", u, r); free(r); - (void)VSL_Log_Arg(v->vd, 'n', v->workdir); + (void)VSL_Arg(v->vd, 'n', v->workdir); AZ(VSC_Open(v->vd, 1)); } Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-14 08:03:45 UTC (rev 4953) @@ -310,10 +310,10 @@ vd = VSM_New(); VSL_Setup(vd); - while ((o = getopt(argc, argv, VSL_LOG_ARGS "1fV")) != -1) { + while ((o = getopt(argc, argv, VSL_ARGS "1fV")) != -1) { switch (o) { case '1': - AN(VSL_Log_Arg(vd, 'd', NULL)); + AN(VSL_Arg(vd, 'd', NULL)); once = 1; break; case 'f': @@ -323,7 +323,7 @@ varnish_version("varnishtop"); exit(0); default: - if (VSL_Log_Arg(vd, o, optarg) > 0) + if (VSL_Arg(vd, o, optarg) > 0) break; usage(); } Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-14 08:03:45 UTC (rev 4953) @@ -66,6 +66,8 @@ * If func is NULL, diagnostics are disabled. */ +#define VSM_n_USAGE "[-n varnish_name]" + int VSM_n_Arg(struct VSM_data *vd, const char *n_arg); /* * Configure which varnishd instance to access. @@ -148,6 +150,10 @@ * Setup vd for use with VSC functions. */ +#define VSC_ARGS "L:n:" +#define VSC_n_USAGE VSM_n_USAGE +#define VSC_USAGE VSC_N_USAGE + int VSC_Arg(struct VSM_data *vd, int arg, const char *opt); /* * Handle standard stat-presenter arguments @@ -204,22 +210,48 @@ * != 0 on failure */ +#define VSL_ARGS "bCcdI:i:k:L:n:r:s:X:x:" +#define VSL_b_USAGE "[-b]" +#define VSL_c_USAGE "[-c]" +#define VSL_C_USAGE "[-C]" +#define VSL_d_USAGE "[-d]" +#define VSL_i_USAGE "[-i tag]" +#define VSL_I_USAGE "[-I regexp]" +#define VSL_k_USAGE "[-k keep]" +#define VSL_n_USAGE VSM_n_USAGE +#define VSL_r_USAGE "[-r file]" +#define VSL_s_USAGE "[-s skip]" +#define VSL_x_USAGE "[-x tag]" +#define VSL_X_USAGE "[-X regexp]" +#define VSL_USAGE "[-bCcd] " \ + VSL_i_USAGE " " \ + VSL_I_USAGE " " \ + VSL_k_USAGE " " \ + VSL_n_USAGE " " \ + VSL_r_USAGE " " \ + VSL_s_USAGE " " \ + VSL_X_USAGE " " \ + VSL_x_USAGE + +int VSL_Arg(struct VSM_data *vd, int arg, const char *opt); + /* + * Handle standard log-presenter arguments + * Return: + * -1 error + * 0 not handled + * 1 Handled. + */ typedef int vsl_handler(void *priv, enum vsl_tag tag, unsigned fd, unsigned len, unsigned spec, const char *ptr); #define VSL_S_CLIENT (1 << 0) #define VSL_S_BACKEND (1 << 1) -#define VSL_LOG_ARGS "bCcdI:i:k:L:n:r:s:X:x:" -#define VSL_STAT_ARGS "L:n:" -#define VSL_USAGE "[-bCcd] [-i tag] [-I regexp] [-k keep]" \ - " [-r file] [-s skip] [-X regexp] [-x tag]" vsl_handler VSL_H_Print; struct VSM_data; void VSL_Select(const struct VSM_data *vd, unsigned tag); void VSL_NonBlocking(const struct VSM_data *vd, int nb); int VSL_Dispatch(const struct VSM_data *vd, vsl_handler *func, void *priv); int VSL_NextLog(const struct VSM_data *lh, uint32_t **pp); -int VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt); extern const char *VSL_tags[256]; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-14 07:41:26 UTC (rev 4952) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-14 08:03:45 UTC (rev 4953) @@ -192,7 +192,7 @@ /*--------------------------------------------------------------------*/ int -VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt) +VSL_Arg(struct VSM_data *vd, int arg, const char *opt) { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); From phk at varnish-cache.org Mon Jun 14 08:40:05 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 14 Jun 2010 10:40:05 +0200 Subject: r4954 - in trunk/varnish-cache: bin/varnishd bin/varnishstat bin/varnishtest include lib/libvarnish lib/libvarnishapi lib/libvcl Message-ID: Author: phk Date: 2010-06-14 10:40:04 +0200 (Mon, 14 Jun 2010) New Revision: 4954 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishtest/vtc.c trunk/varnish-cache/bin/varnishtest/vtc.h trunk/varnish-cache/bin/varnishtest/vtc_client.c trunk/varnish-cache/bin/varnishtest/vtc_http.c trunk/varnish-cache/bin/varnishtest/vtc_server.c trunk/varnish-cache/bin/varnishtest/vtc_varnish.c trunk/varnish-cache/include/libvcl.h trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/include/vin.h trunk/varnish-cache/lib/libvarnish/vin.c trunk/varnish-cache/lib/libvarnishapi/vsl_api.h trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c trunk/varnish-cache/lib/libvarnishapi/vsm.c trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h Log: Remove the -L option stuff, it will not be needed for docs. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -336,15 +336,7 @@ /* XXX: annotate vcl with -b/-f arg so people know where it came from */ (void)f_arg; - if (L_arg && b_arg == NULL) { - bprintf(buf, - "backend default {\n" - " .host = \"127.0.0.1\";\n" - " .port = %s;\n" - "}\n", "Learn(0)"); - vcl = strdup(buf); - AN(vcl); - } else if (b_arg != NULL) { + if (b_arg != NULL) { AZ(vcl); /* * XXX: should do a "HEAD /" on the -b argument to see that @@ -456,7 +448,7 @@ mgt_vcc_init(void) { - VCC_InitCompile(default_vcl, L_arg); + VCC_InitCompile(default_vcl); AZ(atexit(mgt_vcc_atexit)); } Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -84,7 +84,6 @@ struct vev_base *mgt_evb; int exit_status = 0; struct vsb *vident; -unsigned L_arg = 0; static void build_vident(void) @@ -365,7 +364,6 @@ struct cli cli[1]; struct pidfh *pfh = NULL; char *dirname; - char tmpbuf[128]; /* * Start out by closing all unwanted file descriptors we might @@ -460,20 +458,6 @@ case 'l': l_arg = optarg; break; - case 'L': - L_arg = strtoul(optarg, NULL, 0); - if (!VIN_L_OK(L_arg)) { - fprintf(stderr, "%s\n", VIN_L_MSG); - exit (1); - } - d_flag++; - n_arg = vin_L_arg(L_arg); - MCF_ParamSet(cli, "ping_interval", "0"); - - bprintf(tmpbuf, "127.0.0.1:%u", L_arg); - MCF_ParamSet(cli, "listen_address", tmpbuf); - - break; case 'M': M_arg = optarg; break; @@ -532,14 +516,6 @@ mgt_vcc_init(); - if (L_arg) { - /* Learner mode */ - if (!s_arg_given) { - STV_config("malloc,1m"); - s_arg_given = 1; - } - } - if (argc != 0) { fprintf(stderr, "Too many arguments (%s...)\n", argv[0]); usage(); @@ -611,7 +587,7 @@ exit(1); } - if (b_arg != NULL || f_arg != NULL || L_arg > 0) + if (b_arg != NULL || f_arg != NULL) if (mgt_vcc_default(b_arg, f_arg, vcl, C_flag)) exit (2); @@ -654,10 +630,6 @@ mgt_cli_master(M_arg); if (T_arg != NULL) mgt_cli_telnet(T_arg); - else if (L_arg > 0) { - bprintf(tmpbuf, "127.0.0.1:%u", L_arg + 1); - mgt_cli_telnet(tmpbuf); - } STV_ready(); /* Complete initialization */ Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -206,9 +206,6 @@ case '1': once = 1; break; - case 'f': - (void)VSC_Arg(vd, c, optarg); - break; case 'l': if (VSC_Open(vd, 1)) exit(1); Modified: trunk/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/bin/varnishtest/vtc.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -64,8 +64,6 @@ static pthread_mutex_t vtc_mtx; static pthread_cond_t vtc_cond; -int vtc_learn = 0; - /********************************************************************** * Macro facility */ @@ -119,11 +117,9 @@ va_end(ap); m->val = strdup(buf2); AN(m->val); - if (!vtc_learn) - vtc_log(vl, 4, "macro def %s=%s", name, m->val); + vtc_log(vl, 4, "macro def %s=%s", name, m->val); } else if (m != NULL) { - if (!vtc_learn) - vtc_log(vl, 4, "macro undef %s", name); + vtc_log(vl, 4, "macro undef %s", name); VTAILQ_REMOVE(¯o_list, m, list); free(m->name); free(m->val); @@ -623,17 +619,6 @@ AN(vltop); while ((ch = getopt(argc, argv, "L:n:qt:v")) != -1) { switch (ch) { - case 'L': - /* XXX: append "/tutorial" to default search path */ - vtc_learn = strtoul(optarg, NULL, 0); - if (vtc_learn > 65000) { - fprintf(stderr, - "-L argument must be 1...65000\n"); - exit(1); - } - vtc_verbosity += 2; - dur = 60 * 3; /* seconds */ - break; case 'n': ntest = strtoul(optarg, NULL, 0); break; Modified: trunk/varnish-cache/bin/varnishtest/vtc.h =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.h 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/bin/varnishtest/vtc.h 2010-06-14 08:40:04 UTC (rev 4954) @@ -53,7 +53,6 @@ cmd_f cmd_varnish; cmd_f cmd_sema; -extern int vtc_learn; /* Non-zero in Learners mode */ extern int vtc_verbosity; extern int vtc_error; /* Error, bail out */ extern int vtc_stop; /* Abandon current test, no error */ Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_client.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/bin/varnishtest/vtc_client.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -136,10 +136,7 @@ if (*c->name != 'c') vtc_log(c->vl, 0, "Client name must start with 'c'"); - if (vtc_learn) - bprintf(c->connect, "127.0.0.1:%d", vtc_learn); - else - bprintf(c->connect, "%s", "${v1_sock}"); + bprintf(c->connect, "%s", "${v1_sock}"); VTAILQ_INSERT_TAIL(&clients, c, list); return (c); } @@ -183,8 +180,7 @@ void *res; CHECK_OBJ_NOTNULL(c, CLIENT_MAGIC); - if (!vtc_learn) - vtc_log(c->vl, 2, "Waiting for client"); + vtc_log(c->vl, 2, "Waiting for client"); AZ(pthread_join(c->tp, &res)); if (res != NULL) vtc_log(c->vl, 0, "Client returned \"%s\"", (char *)res); @@ -242,11 +238,7 @@ if (vtc_error) break; if (!strcmp(*av, "-connect")) { - if (vtc_learn) - bprintf(c->connect, "127.0.0.1:%d", - vtc_learn + atoi(av[1])); - else - bprintf(c->connect, "%s", av[1]); + bprintf(c->connect, "%s", av[1]); av++; continue; } Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -915,10 +915,7 @@ ALLOC_OBJ(hp, HTTP_MAGIC); AN(hp); hp->fd = sock; - if (vtc_learn) - hp->timeout = 120 * 1000; - else - hp->timeout = 3000; + hp->timeout = 3000; hp->nrxbuf = 640*1024; hp->vsb = vsb_newauto(); hp->rxbuf = malloc(hp->nrxbuf); /* XXX */ Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_server.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/bin/varnishtest/vtc_server.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -137,10 +137,7 @@ if (*s->name != 's') vtc_log(s->vl, 0, "Server name must start with 's'"); - if (vtc_learn) - bprintf(s->listen, "127.0.0.1:%d", vtc_learn + 10); - else - bprintf(s->listen, "127.0.0.1:%d", 0); + bprintf(s->listen, "127.0.0.1:%d", 0); AZ(VSS_parse(s->listen, &s->addr, &s->port)); s->repeat = 1; s->depth = 1; @@ -174,8 +171,7 @@ int naddr; CHECK_OBJ_NOTNULL(s, SERVER_MAGIC); - if (!vtc_learn) - vtc_log(s->vl, 2, "Starting server"); + vtc_log(s->vl, 2, "Starting server"); if (s->sock < 0) { naddr = VSS_resolve(s->addr, s->port, &s->vss_addr); if (naddr != 1) @@ -194,8 +190,7 @@ if (!strcmp(s->port, "0")) REPLACE(s->port, s->aport); } - if (!vtc_learn) - vtc_log(s->vl, 1, "Listen on %s:%s", s->addr, s->port); + vtc_log(s->vl, 1, "Listen on %s:%s", s->addr, s->port); s->run = 1; AZ(pthread_create(&s->tp, NULL, server_thread, s)); } @@ -210,8 +205,7 @@ void *res; CHECK_OBJ_NOTNULL(s, SERVER_MAGIC); - if (!vtc_learn) - vtc_log(s->vl, 2, "Waiting for server"); + vtc_log(s->vl, 2, "Waiting for server"); AZ(pthread_join(s->tp, &res)); if (res != NULL && !vtc_stop) vtc_log(s->vl, 0, "Server returned \"%p\"", @@ -300,11 +294,7 @@ continue; } if (!strcmp(*av, "-listen")) { - if (vtc_learn) - bprintf(s->listen, "127.0.0.1:%d", - vtc_learn + 10 + atoi(av[1])); - else - bprintf(s->listen, "%s", av[1]); + bprintf(s->listen, "%s", av[1]); AZ(VSS_parse(s->listen, &s->addr, &s->port)); av++; continue; Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -459,7 +459,7 @@ AZ(close(v->cli_fd)); v->cli_fd = -1; - AZ(close(v->fds[1])); + (void)close(v->fds[1]); /* May already have been closed */ AZ(pthread_join(v->tp, &p)); AZ(close(v->fds[0])); Modified: trunk/varnish-cache/include/libvcl.h =================================================================== --- trunk/varnish-cache/include/libvcl.h 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/include/libvcl.h 2010-06-14 08:40:04 UTC (rev 4954) @@ -30,6 +30,6 @@ */ char *VCC_Compile(struct vsb *sb, const char *b, const char *e); -void VCC_InitCompile(const char *default_vcl, unsigned L_arg); +void VCC_InitCompile(const char *default_vcl); const char *VCC_Return_Name(unsigned action); Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-14 08:40:04 UTC (rev 4954) @@ -150,7 +150,7 @@ * Setup vd for use with VSC functions. */ -#define VSC_ARGS "L:n:" +#define VSC_ARGS "f:n:" #define VSC_n_USAGE VSM_n_USAGE #define VSC_USAGE VSC_N_USAGE @@ -210,7 +210,7 @@ * != 0 on failure */ -#define VSL_ARGS "bCcdI:i:k:L:n:r:s:X:x:" +#define VSL_ARGS "bCcdI:i:k:n:r:s:X:x:" #define VSL_b_USAGE "[-b]" #define VSL_c_USAGE "[-c]" #define VSL_C_USAGE "[-C]" Modified: trunk/varnish-cache/include/vin.h =================================================================== --- trunk/varnish-cache/include/vin.h 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/include/vin.h 2010-06-14 08:40:04 UTC (rev 4954) @@ -35,10 +35,4 @@ /* This function lives in both libvarnish and libvarnishapi */ int vin_n_arg(const char *n_arg, char **name, char **dir, char **vsl); -char *vin_L_arg(unsigned L_arg); -#define VIN_L_LOW 1024 -#define VIN_L_HIGH 65000 -#define VIN_L_OK(a) (a >= VIN_L_LOW && a <= VIN_L_HIGH) -#define VIN_L_MSG "-L argument must be [1024...65000]" - #endif Modified: trunk/varnish-cache/lib/libvarnish/vin.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vin.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/lib/libvarnish/vin.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -101,13 +101,3 @@ } return (0); } - -char * -vin_L_arg(unsigned L_arg) -{ - char p[PATH_MAX]; - - assert(VIN_L_OK(L_arg)); - bprintf(p, "/tmp/varnish_L_%u", L_arg); - return (strdup(p)); -} Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_api.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_api.h 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_api.h 2010-06-14 08:40:04 UTC (rev 4954) @@ -46,7 +46,6 @@ unsigned rbuflen; uint32_t *rbuf; - unsigned L_opt; int b_opt; int c_opt; int d_opt; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -210,16 +210,6 @@ case 's': return (vsl_s_arg(vd, opt)); case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg)); case 'C': vd->vsl->regflags = VRE_CASELESS; return (1); - case 'L': - vd->vsl->L_opt = strtoul(opt, NULL, 0); - if (vd->vsl->L_opt < 1024 || vd->vsl->L_opt > 65000) { - fprintf(stderr, "%s\n", VIN_L_MSG); - exit (1); - } - free(vd->n_opt); - vd->n_opt = vin_L_arg(vd->vsl->L_opt); - assert(vd->n_opt != NULL); - return (1); default: return (0); } Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -213,7 +213,8 @@ { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - AN(vd->vsm_head); + if (vd->vsm_head == NULL) + return; assert(0 == munmap((void*)vd->vsm_head, vd->vsm_head->shm_size)); vd->vsm_head = NULL; assert(vd->vsm_fd >= 0); Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -393,9 +393,7 @@ struct fld_spec *fs; struct vsb *vsb; unsigned u; - unsigned tL_port = 0; double t; - char tmpbuf[20]; Fh(tl, 1, "\n#define VGC_backend_%s %d\n", vgcname, tl->ndirector); @@ -449,39 +447,10 @@ vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "port")) { - if (Learn_mode) { - ExpectErr(tl, ID); - if (!vcc_IdIs(tl->t, "Learn")) { - vsb_printf(tl->sb, - "Expected \"Learn\"\n"); - vcc_ErrToken(tl, tl->t); - vcc_ErrWhere(tl, tl->t); - return; - } - vcc_NextToken(tl); - - ExpectErr(tl, '('); - vcc_NextToken(tl); - - ExpectErr(tl, CNUM); - t_port = tl->t; - tL_port = vcc_UintVal(tl); - if (tL_port > 9) { - vsb_printf(tl->sb, - "Learn port > 9\n"); - vcc_ErrToken(tl, t_port); - vcc_ErrWhere(tl, t_port); - return; - } - - ExpectErr(tl, ')'); - vcc_NextToken(tl); - } else { - ExpectErr(tl, CSTR); - assert(tl->t->dec != NULL); - t_port = tl->t; - vcc_NextToken(tl); - } + ExpectErr(tl, CSTR); + assert(tl->t->dec != NULL); + t_port = tl->t; + vcc_NextToken(tl); SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "host_header")) { ExpectErr(tl, CSTR); @@ -550,10 +519,7 @@ } /* Check that the portname makes sense */ - if (Learn_mode && t_port != NULL && t_port->tok == CNUM) { - bprintf(tmpbuf, "%u", Learn_mode + 10 + tL_port); - Emit_Sockaddr(tl, t_host, tmpbuf); - } else if (t_port != NULL) { + if (t_port != NULL) { ep = CheckHostPort("127.0.0.1", t_port->dec); if (ep != NULL) { vsb_printf(tl->sb, Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-14 08:40:04 UTC (rev 4954) @@ -86,8 +86,6 @@ static const char *vcc_default_vcl_b, *vcc_default_vcl_e; -unsigned Learn_mode = 0; - /*--------------------------------------------------------------------*/ static void @@ -675,10 +673,9 @@ */ void -VCC_InitCompile(const char *default_vcl, unsigned L_arg) +VCC_InitCompile(const char *default_vcl) { - Learn_mode = L_arg; vcc_default_vcl_b = default_vcl; vcc_default_vcl_e = strchr(default_vcl, '\0'); assert(vcc_default_vcl_e != NULL); Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-14 08:03:45 UTC (rev 4953) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-14 08:40:04 UTC (rev 4954) @@ -163,7 +163,6 @@ /* vcc_compile.c */ extern struct method method_tab[]; -extern unsigned Learn_mode; /* * H -> Header, before the C code * C -> C-code From phk at varnish-cache.org Mon Jun 14 09:17:49 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 14 Jun 2010 11:17:49 +0200 Subject: r4955 - in trunk/varnish-cache: bin/varnishlog include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-14 11:17:49 +0200 (Mon, 14 Jun 2010) New Revision: 4955 Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsl.c trunk/varnish-cache/lib/libvarnishapi/vsm.c trunk/varnish-cache/lib/libvarnishapi/vsm_api.h Log: Make VSL_Dispatch reopen the vsm when idle-timeout kicks in. Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c =================================================================== --- trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-14 08:40:04 UTC (rev 4954) +++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-14 09:17:49 UTC (rev 4955) @@ -194,7 +194,7 @@ } static void -do_order(const struct VSM_data *vd, int argc, char * const *argv) +do_order(struct VSM_data *vd, int argc, char * const *argv) { int i; const char *error; Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-14 08:40:04 UTC (rev 4954) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-14 09:17:49 UTC (rev 4955) @@ -250,7 +250,7 @@ struct VSM_data; void VSL_Select(const struct VSM_data *vd, unsigned tag); void VSL_NonBlocking(const struct VSM_data *vd, int nb); -int VSL_Dispatch(const struct VSM_data *vd, vsl_handler *func, void *priv); +int VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv); int VSL_NextLog(const struct VSM_data *lh, uint32_t **pp); extern const char *VSL_tags[256]; Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-14 08:40:04 UTC (rev 4954) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-14 09:17:49 UTC (rev 4955) @@ -266,7 +266,7 @@ /*--------------------------------------------------------------------*/ int -VSL_Dispatch(const struct VSM_data *vd, vsl_handler *func, void *priv) +VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv) { struct vsl *vsl; int i; @@ -279,6 +279,8 @@ while (1) { i = VSL_NextLog(vd, &p); + if (i == 0 && VSM_ReOpen(vd, 0) == 1) + continue; if (i != 1) return (i); u = VSL_ID(p); @@ -325,21 +327,15 @@ /*--------------------------------------------------------------------*/ -int -VSL_Open(struct VSM_data *vd, int diag) +void +vsl_open_cb(struct VSM_data *vd) { struct vsl *vsl; struct vsm_chunk *sha; - int i; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); vsl = vd->vsl; CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); - - i = VSM_Open(vd, diag); - if (i) - return (i); - sha = vsm_find_alloc(vd, VSL_CLASS, "", ""); assert(sha != NULL); @@ -349,6 +345,24 @@ vsl->last_seq = vsl->log_start[0]; VRMB(); +} + +/*--------------------------------------------------------------------*/ + +int +VSL_Open(struct VSM_data *vd, int diag) +{ + struct vsl *vsl; + int i; + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + vsl = vd->vsl; + CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC); + + i = VSM_Open(vd, diag); + if (i) + return (i); + if (!vsl->d_opt && vsl->r_fd == -1) { while (*vsl->log_ptr != VSL_ENDMARKER) vsl->log_ptr = VSL_NEXT(vsl->log_ptr); Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-14 08:40:04 UTC (rev 4954) +++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-14 09:17:49 UTC (rev 4955) @@ -191,6 +191,9 @@ while(slh.alloc_seq == 0) (void)usleep(50000); /* XXX limit total sleep */ vd->alloc_seq = slh.alloc_seq; + + if (vd->vsl != NULL) + vsl_open_cb(vd); return (0); } Modified: trunk/varnish-cache/lib/libvarnishapi/vsm_api.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm_api.h 2010-06-14 08:40:04 UTC (rev 4954) +++ trunk/varnish-cache/lib/libvarnishapi/vsm_api.h 2010-06-14 09:17:49 UTC (rev 4955) @@ -64,3 +64,4 @@ void vsc_delete(struct VSM_data *vd); void vsl_delete(struct VSM_data *vd); +void vsl_open_cb(struct VSM_data *vd); From phk at varnish-cache.org Mon Jun 14 09:35:30 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 14 Jun 2010 11:35:30 +0200 Subject: r4956 - trunk/varnish-cache/bin/varnishtest Message-ID: Author: phk Date: 2010-06-14 11:35:30 +0200 (Mon, 14 Jun 2010) New Revision: 4956 Modified: trunk/varnish-cache/bin/varnishtest/vtc.c Log: Pull in srandomdev() compat if needed. Modified: trunk/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc.c 2010-06-14 09:17:49 UTC (rev 4955) +++ trunk/varnish-cache/bin/varnishtest/vtc.c 2010-06-14 09:35:30 UTC (rev 4956) @@ -52,6 +52,10 @@ #include "vtc.h" +#ifndef HAVE_SRANDOMDEV +#include "compat/srandomdev.h" +#endif + #define MAX_FILESIZE (1024 * 1024) #define MAX_TOKENS 200 From phk at varnish-cache.org Wed Jun 16 08:44:00 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 16 Jun 2010 10:44:00 +0200 Subject: r4957 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-16 10:44:00 +0200 (Wed, 16 Jun 2010) New Revision: 4957 Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c Log: Add a comment about desirable but complex error recovery Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-14 09:35:30 UTC (rev 4956) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-16 08:44:00 UTC (rev 4957) @@ -25,6 +25,63 @@ * 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. + * + * + * TODO: + * + * There is a risk that the child process might corrupt the VSM segment + * and we should capture that event and recover gracefully. + * + * A possible state diagram could be: + * + * [manager start] + * | + * v + * Open old VSM, + * check pid --------> exit/fail (-n message) + * | + * +<----------------------+ + * | ^ + * v | + * Create new VSM | + * | | + * v | + * Init header | + * Alloc VSL | + * Alloc VSC:Main | + * Alloc Args etc. | + * | | + * +<--------------+ | + * | ^ | + * v | | + * start worker | | + * | | | + * | | +<---- worker crash + * v | ^ + * Reset VSL ptr. | | + * Reset VSC counters | | + * | | | + * +<------+ | | + * | ^ | | + * v | | | + * alloc dynamics | | | + * free dynamics | | | + * | | | | + * v | | | + * +------>+ | | + * | | | + * v | | + * stop worker | | + * | | | + * v | | + * Check consist---------- | ----->+ + * | | + * v | + * Free dynamics | + * | | + * v | + * +-------------->+ + * */ #include "config.h" From phk at varnish-cache.org Wed Jun 16 09:51:06 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 16 Jun 2010 11:51:06 +0200 Subject: r4958 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-16 11:51:06 +0200 (Wed, 16 Jun 2010) New Revision: 4958 Added: trunk/varnish-cache/bin/varnishd/vsm.c Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/mgt_shmem.c Log: VSM allocations/frees need to happen from both manager and child process start abstracting this stuff to a common file (vsm.c). Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2010-06-16 08:44:00 UTC (rev 4957) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2010-06-16 09:51:06 UTC (rev 4958) @@ -57,7 +57,8 @@ storage_synth.c \ storage_umem.c \ stevedore_utils.c \ - varnishd.c + varnishd.c \ + vsm.c noinst_HEADERS = \ acct_fields.h \ Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-16 08:44:00 UTC (rev 4957) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-16 09:51:06 UTC (rev 4958) @@ -42,6 +42,10 @@ static pthread_mutex_t vsl_mtx; +static uint32_t *vsl_start; +static uint32_t *vsl_end; +static uint32_t *vsl_ptr; + static inline uint32_t vsl_w0(uint32_t type, uint32_t length) { @@ -69,13 +73,17 @@ vsl_wrap(void) { - vsl_log_start[1] = VSL_ENDMARKER; + assert(vsl_ptr >= vsl_start + 1); + assert(vsl_ptr < vsl_end); + vsl_start[1] = VSL_ENDMARKER; do - vsl_log_start[0]++; - while (vsl_log_start[0] == 0); + vsl_start[0]++; + while (vsl_start[0] == 0); VWMB(); - *vsl_log_nxt = VSL_WRAPMARKER; - vsl_log_nxt = vsl_log_start + 1; + if (vsl_ptr != vsl_start + 1) { + *vsl_ptr = VSL_WRAPMARKER; + vsl_ptr = vsl_start + 1; + } VSL_stats->shm_cycles++; } @@ -92,24 +100,24 @@ AZ(pthread_mutex_lock(&vsl_mtx)); VSL_stats->shm_cont++; } - assert(vsl_log_nxt < vsl_log_end); - assert(((uintptr_t)vsl_log_nxt & 0x3) == 0); + assert(vsl_ptr < vsl_end); + assert(((uintptr_t)vsl_ptr & 0x3) == 0); VSL_stats->shm_writes++; VSL_stats->shm_flushes += flushes; VSL_stats->shm_records += records; /* Wrap if necessary */ - if (VSL_END(vsl_log_nxt, len) >= vsl_log_end) + if (VSL_END(vsl_ptr, len) >= vsl_end) vsl_wrap(); - p = vsl_log_nxt; - vsl_log_nxt = VSL_END(vsl_log_nxt, len); + p = vsl_ptr; + vsl_ptr = VSL_END(vsl_ptr, len); - *vsl_log_nxt = VSL_ENDMARKER; + *vsl_ptr = VSL_ENDMARKER; - assert(vsl_log_nxt < vsl_log_end); - assert(((uintptr_t)vsl_log_nxt & 0x3) == 0); + assert(vsl_ptr < vsl_end); + assert(((uintptr_t)vsl_ptr & 0x3) == 0); AZ(pthread_mutex_unlock(&vsl_mtx)); return (p); @@ -264,8 +272,18 @@ void VSL_Init(void) { + struct vsm_chunk *vsc; AZ(pthread_mutex_init(&vsl_mtx, NULL)); + + VSM_ITER(vsc) + if (!strcmp(vsc->class, VSL_CLASS)) + break; + AN(vsc); + vsl_start = VSM_PTR(vsc); + vsl_end = VSM_NEXT(vsc); + vsl_ptr = vsl_start + 1; + vsl_wrap(); loghead->starttime = (intmax_t)TIM_real(); loghead->panicstr[0] = '\0'; Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2010-06-16 08:44:00 UTC (rev 4957) +++ trunk/varnish-cache/bin/varnishd/common.h 2010-06-16 09:51:06 UTC (rev 4958) @@ -42,9 +42,6 @@ void *mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident); extern struct vsc_main *VSL_stats; extern struct vsm_head *loghead; -extern uint32_t *vsl_log_start; -extern uint32_t *vsl_log_end; -extern uint32_t *vsl_log_nxt; /* varnishd.c */ struct vsb; @@ -72,16 +69,11 @@ #define NEEDLESS_RETURN(foo) return (foo) -/********************************************************************** - * Guess what: There is no POSIX standard for memory barriers. - * XXX: Please try to find the minimal #ifdef to use here, rely on OS - * supplied facilities if at all possible, to avoid descending into the - * full cpu/compiler explosion. - */ +/* vsm.c */ +extern struct vsm_head *vsm_head; +extern void *vsm_end; -#ifdef __FreeBSD__ -#include -#define MEMORY_BARRIER() mb() -#else -#define MEMORY_BARRIER() close(-1) -#endif +struct vsm_chunk *vsm_iter_0(void); +void vsm_iter_n(struct vsm_chunk **pp); + +#define VSM_ITER(vd) for ((vd) = vsm_iter_0(); (vd) != NULL; vsm_iter_n(&vd)) Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-16 08:44:00 UTC (rev 4957) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-16 09:51:06 UTC (rev 4958) @@ -115,9 +115,6 @@ struct vsc_main *VSL_stats; struct vsm_head *loghead; -uint32_t *vsl_log_start; -uint32_t *vsl_log_end; -uint32_t *vsl_log_nxt; static int vsl_fd = -1; @@ -260,6 +257,7 @@ const char *q; uintmax_t size, s1, s2, ps; char **av, **ap; + uint32_t *vsl_log_start; if (l_arg == NULL) l_arg = ""; @@ -341,6 +339,9 @@ bprintf(loghead->head.class, "%s", "Free"); VWMB(); + vsm_head = loghead; + vsm_end = (uint8_t*)loghead + size; + VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, VSC_CLASS, VSC_TYPE_MAIN, ""); AN(VSL_stats); @@ -352,9 +353,7 @@ vsl_log_start = mgt_SHM_Alloc(s1, VSL_CLASS, "", ""); AN(vsl_log_start); - vsl_log_end = (void*)((uint8_t *)vsl_log_start + s1); - vsl_log_nxt = vsl_log_start + 1; - *vsl_log_nxt = VSL_ENDMARKER; + vsl_log_start[1] = VSL_ENDMARKER; VWMB(); do Copied: trunk/varnish-cache/bin/varnishd/vsm.c (from rev 4957, trunk/varnish-cache/bin/varnishd/mgt_shmem.c) =================================================================== --- trunk/varnish-cache/bin/varnishd/vsm.c (rev 0) +++ trunk/varnish-cache/bin/varnishd/vsm.c 2010-06-16 09:51:06 UTC (rev 4958) @@ -0,0 +1,70 @@ +/*- + * Copyright (c) 2010 Redpill Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * VSM stuff common to manager and child. + * + */ + +#include "config.h" + +#include "svnid.h" +SVNID("$Id$") + +#include + +#include "miniobj.h" +#include "libvarnish.h" +#include "common.h" +#include "vsm.h" + +struct vsm_head *vsm_head; +void *vsm_end; + +/*--------------------------------------------------------------------*/ + +struct vsm_chunk * +vsm_iter_0(void) +{ + + CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC); + CHECK_OBJ_NOTNULL(&vsm_head->head, VSM_CHUNK_MAGIC); + return (&vsm_head->head); +} + +void +vsm_iter_n(struct vsm_chunk **pp) +{ + + CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC); + CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); + *pp = VSM_NEXT(*pp); + if ((void*)(*pp) >= vsm_end) { + *pp = NULL; + return; + } + CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); +} From phk at varnish-cache.org Wed Jun 16 10:19:34 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 16 Jun 2010 12:19:34 +0200 Subject: r4959 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-16 12:19:34 +0200 (Wed, 16 Jun 2010) New Revision: 4959 Modified: trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/bin/varnishd/storage_malloc.c trunk/varnish-cache/bin/varnishd/vsm.c Log: Move VSM allocation to common code Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2010-06-16 09:51:06 UTC (rev 4958) +++ trunk/varnish-cache/bin/varnishd/common.h 2010-06-16 10:19:34 UTC (rev 4959) @@ -73,6 +73,9 @@ extern struct vsm_head *vsm_head; extern void *vsm_end; +void *VSM_Alloc(unsigned size, const char *class, const char *type, + const char *ident); + struct vsm_chunk *vsm_iter_0(void); void vsm_iter_n(struct vsm_chunk **pp); Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2010-06-16 09:51:06 UTC (rev 4958) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2010-06-16 10:19:34 UTC (rev 4959) @@ -511,7 +511,7 @@ /* Save in shmem */ i = strlen(S_arg); - p = mgt_SHM_Alloc(i + 1, "Arg", "-S", ""); + p = VSM_Alloc(i + 1, "Arg", "-S", ""); AN(p); strcpy(p, S_arg); @@ -546,7 +546,7 @@ /* Save in shmem */ i = strlen(T_arg); - p = mgt_SHM_Alloc(i + 1, "Arg", "-T", ""); + p = VSM_Alloc(i + 1, "Arg", "-T", ""); AN(p); strcpy(p, T_arg); Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-16 09:51:06 UTC (rev 4958) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-16 10:19:34 UTC (rev 4959) @@ -118,58 +118,6 @@ static int vsl_fd = -1; -/*--------------------------------------------------------------------*/ - -void * -mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident) -{ - struct vsm_chunk *sha, *sha2; - unsigned seq; - - ASSERT_MGT(); - AN(loghead); - /* Round up to pointersize */ - size += sizeof(sha) - 1; - size &= ~(sizeof(sha) - 1); - - size += sizeof *sha; - sha = &loghead->head; - while (1) { - CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); - - if (strcmp(sha->class, "Free")) { - sha = VSM_NEXT(sha); - continue; - } - assert(size <= sha->len); - - sha2 = (void*)((uintptr_t)sha + size); - - seq = loghead->alloc_seq; - loghead->alloc_seq = 0; - VWMB(); - - memset(sha2, 0, sizeof *sha2); - sha2->magic = VSM_CHUNK_MAGIC; - sha2->len = sha->len - size; - bprintf(sha2->class, "%s", "Free"); - - sha->len = size; - bprintf(sha->class, "%s", class); - bprintf(sha->type, "%s", type); - bprintf(sha->ident, "%s", ident); - - VWMB(); - if (seq != 0) - do - loghead->alloc_seq = seq++; - while (loghead->alloc_seq == 0); - - return (VSM_PTR(sha)); - } - return (NULL); -} - /*-------------------------------------------------------------------- * Check that we are not started with the same -n argument as an already * running varnishd @@ -342,16 +290,16 @@ vsm_head = loghead; vsm_end = (uint8_t*)loghead + size; - VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, + VSL_stats = VSM_Alloc(sizeof *VSL_stats, VSC_CLASS, VSC_TYPE_MAIN, ""); AN(VSL_stats); - pp = mgt_SHM_Alloc(sizeof *pp, "Params", "", ""); + pp = VSM_Alloc(sizeof *pp, "Params", "", ""); AN(pp); *pp = *params; params = pp; - vsl_log_start = mgt_SHM_Alloc(s1, VSL_CLASS, "", ""); + vsl_log_start = VSM_Alloc(s1, VSL_CLASS, "", ""); AN(vsl_log_start); vsl_log_start[1] = VSL_ENDMARKER; VWMB(); Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2010-06-16 09:51:06 UTC (rev 4958) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2010-06-16 10:19:34 UTC (rev 4959) @@ -187,7 +187,7 @@ struct sma_sc *sma_sc; CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC); - sma_sc->stats = mgt_SHM_Alloc(sizeof *sma_sc->stats, + sma_sc->stats = VSM_Alloc(sizeof *sma_sc->stats, VSC_CLASS, VSC_TYPE_SMA, st->ident); memset(sma_sc->stats, 0, sizeof *sma_sc->stats); } Modified: trunk/varnish-cache/bin/varnishd/vsm.c =================================================================== --- trunk/varnish-cache/bin/varnishd/vsm.c 2010-06-16 09:51:06 UTC (rev 4958) +++ trunk/varnish-cache/bin/varnishd/vsm.c 2010-06-16 10:19:34 UTC (rev 4959) @@ -35,11 +35,14 @@ SVNID("$Id$") #include +#include +#include #include "miniobj.h" #include "libvarnish.h" #include "common.h" #include "vsm.h" +#include "vmb.h" struct vsm_head *vsm_head; void *vsm_end; @@ -68,3 +71,55 @@ } CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); } + +/*--------------------------------------------------------------------*/ + +void * +VSM_Alloc(unsigned size, const char *class, const char *type, const char *ident) +{ + struct vsm_chunk *sha, *sha2; + unsigned seq; + + CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC); + + /* Round up to pointersize */ + size += sizeof(void *) - 1; + size &= ~(sizeof(void *) - 1); + + size += sizeof *sha; /* Make space for the header */ + + VSM_ITER(sha) { + CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); + + if (strcmp(sha->class, "Free")) + continue; + + xxxassert(size <= sha->len); + + sha2 = (void*)((uintptr_t)sha + size); + + /* Mark as inconsistent while we write string fields */ + seq = vsm_head->alloc_seq; + vsm_head->alloc_seq = 0; + VWMB(); + + memset(sha2, 0, sizeof *sha2); + sha2->magic = VSM_CHUNK_MAGIC; + sha2->len = sha->len - size; + bprintf(sha2->class, "%s", "Free"); + + sha->len = size; + bprintf(sha->class, "%s", class); + bprintf(sha->type, "%s", type); + bprintf(sha->ident, "%s", ident); + + VWMB(); + if (seq != 0) + do + loghead->alloc_seq = seq++; + while (loghead->alloc_seq == 0); + + return (VSM_PTR(sha)); + } + return (NULL); +} From phk at varnish-cache.org Wed Jun 16 10:39:10 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 16 Jun 2010 12:39:10 +0200 Subject: r4960 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-16 12:39:09 +0200 (Wed, 16 Jun 2010) New Revision: 4960 Modified: trunk/varnish-cache/bin/varnishd/vsm.c Log: Preincrement seq#, otherwise it makes no difference. Modified: trunk/varnish-cache/bin/varnishd/vsm.c =================================================================== --- trunk/varnish-cache/bin/varnishd/vsm.c 2010-06-16 10:19:34 UTC (rev 4959) +++ trunk/varnish-cache/bin/varnishd/vsm.c 2010-06-16 10:39:09 UTC (rev 4960) @@ -116,7 +116,7 @@ VWMB(); if (seq != 0) do - loghead->alloc_seq = seq++; + loghead->alloc_seq = ++seq; while (loghead->alloc_seq == 0); return (VSM_PTR(sha)); From phk at varnish-cache.org Wed Jun 16 10:39:33 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 16 Jun 2010 12:39:33 +0200 Subject: r4961 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-16 12:39:33 +0200 (Wed, 16 Jun 2010) New Revision: 4961 Modified: trunk/varnish-cache/bin/varnishd/stevedore.c trunk/varnish-cache/bin/varnishd/stevedore.h trunk/varnish-cache/bin/varnishd/storage_malloc.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Move SMA stats allocation to child process Modified: trunk/varnish-cache/bin/varnishd/stevedore.c =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.c 2010-06-16 10:39:09 UTC (rev 4960) +++ trunk/varnish-cache/bin/varnishd/stevedore.c 2010-06-16 10:39:33 UTC (rev 4961) @@ -215,18 +215,6 @@ } void -STV_ready(void) -{ - struct stevedore *stv; - - ASSERT_MGT(); - VTAILQ_FOREACH(stv, &stevedores, list) { - if (stv->ready != NULL) - stv->ready(stv); - } -} - -void STV_open(void) { struct stevedore *stv; Modified: trunk/varnish-cache/bin/varnishd/stevedore.h =================================================================== --- trunk/varnish-cache/bin/varnishd/stevedore.h 2010-06-16 10:39:09 UTC (rev 4960) +++ trunk/varnish-cache/bin/varnishd/stevedore.h 2010-06-16 10:39:33 UTC (rev 4961) @@ -36,7 +36,6 @@ struct objcore; typedef void storage_init_f(struct stevedore *, int ac, char * const *av); -typedef void storage_ready_f(struct stevedore *); typedef void storage_open_f(const struct stevedore *); typedef struct storage *storage_alloc_f(struct stevedore *, size_t size, struct objcore *); @@ -51,7 +50,6 @@ #define STEVEDORE_MAGIC 0x4baf43db const char *name; storage_init_f *init; /* called by mgt process */ - storage_ready_f *ready; /* called by mgt process */ storage_open_f *open; /* called by cache process */ storage_alloc_f *alloc; /* --//-- */ storage_trim_f *trim; /* --//-- */ @@ -73,7 +71,6 @@ struct storage *STV_alloc(struct sess *sp, size_t size, struct objcore *oc); void STV_trim(struct storage *st, size_t size); void STV_free(struct storage *st); -void STV_ready(void); void STV_open(void); void STV_close(void); void STV_config(const char *spec); Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_malloc.c 2010-06-16 10:39:09 UTC (rev 4960) +++ trunk/varnish-cache/bin/varnishd/storage_malloc.c 2010-06-16 10:39:33 UTC (rev 4961) @@ -182,30 +182,21 @@ } static void -sma_ready(struct stevedore *st) +sma_open(const struct stevedore *st) { struct sma_sc *sma_sc; CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC); + Lck_New(&sma_sc->sma_mtx); sma_sc->stats = VSM_Alloc(sizeof *sma_sc->stats, VSC_CLASS, VSC_TYPE_SMA, st->ident); memset(sma_sc->stats, 0, sizeof *sma_sc->stats); } -static void -sma_open(const struct stevedore *st) -{ - struct sma_sc *sma_sc; - - CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC); - Lck_New(&sma_sc->sma_mtx); -} - const struct stevedore sma_stevedore = { .magic = STEVEDORE_MAGIC, .name = "malloc", .init = sma_init, - .ready = sma_ready, .open = sma_open, .alloc = sma_alloc, .free = sma_free, Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-16 10:39:09 UTC (rev 4960) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-16 10:39:33 UTC (rev 4961) @@ -631,8 +631,6 @@ if (T_arg != NULL) mgt_cli_telnet(T_arg); - STV_ready(); /* Complete initialization */ - MGT_Run(); if (pfh != NULL) From phk at varnish-cache.org Wed Jun 16 10:40:00 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 16 Jun 2010 12:40:00 +0200 Subject: r4962 - in trunk/varnish-cache: bin/varnishstat include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-16 12:40:00 +0200 (Wed, 16 Jun 2010) New Revision: 4962 Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c trunk/varnish-cache/include/varnishapi.h trunk/varnish-cache/lib/libvarnishapi/vsc.c trunk/varnish-cache/lib/libvarnishapi/vsm.c trunk/varnish-cache/lib/libvarnishapi/vsm_api.h Log: Make varnishstat discover dynamic allocations in curses mode. Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-16 10:39:33 UTC (rev 4961) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-16 10:40:00 UTC (rev 4962) @@ -74,7 +74,7 @@ } static void -do_xml(const struct VSM_data *vd) +do_xml(struct VSM_data *vd) { char time_stamp[20]; time_t now; @@ -121,7 +121,7 @@ } static void -do_once(const struct VSM_data *vd, const struct vsc_main *VSL_stats) +do_once(struct VSM_data *vd, const struct vsc_main *VSL_stats) { struct once_priv op; @@ -153,7 +153,7 @@ } static void -list_fields(const struct VSM_data *vd) +list_fields(struct VSM_data *vd) { fprintf(stderr, "Varnishstat -f option fields:\n"); fprintf(stderr, "Field name Description\n"); Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-16 10:39:33 UTC (rev 4961) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-16 10:40:00 UTC (rev 4962) @@ -100,7 +100,7 @@ } static void -prep_pts(const struct VSM_data *vd) +prep_pts(struct VSM_data *vd) { struct pt *pt, *pt2; @@ -135,6 +135,7 @@ int ch, line; struct pt *pt; double act, lact; + unsigned seq; (void)initscr(); AC(raw()); @@ -147,6 +148,7 @@ /* * Initialization goes in outher loop */ + seq = VSM_Seq(vd); prep_pts(vd); AC(erase()); AC(refresh()); @@ -159,6 +161,8 @@ lact = 0; while (1) { + if (seq != VSM_Seq(vd)) + break; /* * Break to outher loop if we need to re-read file. * Only check if it looks like nothing is happening. Modified: trunk/varnish-cache/include/varnishapi.h =================================================================== --- trunk/varnish-cache/include/varnishapi.h 2010-06-16 10:39:33 UTC (rev 4961) +++ trunk/varnish-cache/include/varnishapi.h 2010-06-16 10:40:00 UTC (rev 4962) @@ -110,12 +110,17 @@ * -1 failure to reopen. */ +unsigned VSM_Seq(struct VSM_data *vd); + /* + * Return the allocation sequence number + */ + struct vsm_head *VSM_Head(const struct VSM_data *vd); /* * Return the head of the VSM. */ -void *VSM_Find_Chunk(const struct VSM_data *vd, const char *class, +void *VSM_Find_Chunk(struct VSM_data *vd, const char *class, const char *type, const char *ident, unsigned *lenp); /* * Find a given chunk in the shared memory. @@ -129,7 +134,7 @@ * Deallocate all storage (including VSC and VSL allocations) */ -struct vsm_chunk *vsm_iter0(const struct VSM_data *vd); +struct vsm_chunk *vsm_iter0(struct VSM_data *vd); void vsm_itern(const struct VSM_data *vd, struct vsm_chunk **pp); #define VSM_FOREACH(var, vd) \ @@ -169,7 +174,7 @@ * args and returns as VSM_Open() */ -struct vsc_main *VSC_Main(const struct VSM_data *vd); +struct vsc_main *VSC_Main(struct VSM_data *vd); /* * return Main stats structure */ @@ -186,7 +191,7 @@ typedef int vsc_iter_f(void *priv, const struct vsc_point *const pt); -int VSC_Iter(const struct VSM_data *vd, vsc_iter_f *func, void *priv); +int VSC_Iter(struct VSM_data *vd, vsc_iter_f *func, void *priv); /* * Iterate over all statistics counters, calling "func" for * each counter not suppressed by any "-f" arguments. Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-16 10:39:33 UTC (rev 4961) +++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-16 10:40:00 UTC (rev 4962) @@ -223,7 +223,7 @@ /*--------------------------------------------------------------------*/ struct vsc_main * -VSC_Main(const struct VSM_data *vd) +VSC_Main(struct VSM_data *vd) { struct vsm_chunk *sha; @@ -340,7 +340,7 @@ } int -VSC_Iter(const struct VSM_data *vd, vsc_iter_f *func, void *priv) +VSC_Iter(struct VSM_data *vd, vsc_iter_f *func, void *priv) { struct vsc *vsc; struct vsm_chunk *sha; Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-16 10:39:33 UTC (rev 4961) +++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-16 10:40:00 UTC (rev 4962) @@ -267,7 +267,7 @@ /*--------------------------------------------------------------------*/ struct vsm_chunk * -vsm_find_alloc(const struct VSM_data *vd, const char *class, const char *type, const char *ident) +vsm_find_alloc(struct VSM_data *vd, const char *class, const char *type, const char *ident) { struct vsm_chunk *sha; @@ -289,7 +289,7 @@ /*--------------------------------------------------------------------*/ void * -VSM_Find_Chunk(const struct VSM_data *vd, const char *class, const char *type, +VSM_Find_Chunk(struct VSM_data *vd, const char *class, const char *type, const char *ident, unsigned *lenp) { struct vsm_chunk *sha; @@ -306,12 +306,15 @@ /*--------------------------------------------------------------------*/ struct vsm_chunk * -vsm_iter0(const struct VSM_data *vd) +vsm_iter0(struct VSM_data *vd) { CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); - if (vd->alloc_seq != vd->vsm_head->alloc_seq) - return(NULL); + vd->alloc_seq = vd->vsm_head->alloc_seq; + while (vd->alloc_seq == 0) { + usleep(50000); + vd->alloc_seq = vd->vsm_head->alloc_seq; + } CHECK_OBJ_NOTNULL(&vd->vsm_head->head, VSM_CHUNK_MAGIC); return (&vd->vsm_head->head); } @@ -333,3 +336,12 @@ } CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); } + +/*--------------------------------------------------------------------*/ +unsigned +VSM_Seq(struct VSM_data *vd) +{ + + CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); + return (vd->vsm_head->alloc_seq); +} Modified: trunk/varnish-cache/lib/libvarnishapi/vsm_api.h =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm_api.h 2010-06-16 10:39:33 UTC (rev 4961) +++ trunk/varnish-cache/lib/libvarnishapi/vsm_api.h 2010-06-16 10:40:00 UTC (rev 4962) @@ -59,7 +59,7 @@ struct vsl *vsl; }; -struct vsm_chunk *vsm_find_alloc(const struct VSM_data *vd, const char *class, +struct vsm_chunk *vsm_find_alloc(struct VSM_data *vd, const char *class, const char *type, const char *ident); void vsc_delete(struct VSM_data *vd); From phk at varnish-cache.org Wed Jun 16 11:16:09 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 16 Jun 2010 13:16:09 +0200 Subject: r4963 - trunk/varnish-cache/include Message-ID: Author: phk Date: 2010-06-16 13:16:09 +0200 (Wed, 16 Jun 2010) New Revision: 4963 Modified: trunk/varnish-cache/include/vsm.h Log: Add a state field for deletes. Modified: trunk/varnish-cache/include/vsm.h =================================================================== --- trunk/varnish-cache/include/vsm.h 2010-06-16 10:40:00 UTC (rev 4962) +++ trunk/varnish-cache/include/vsm.h 2010-06-16 11:16:09 UTC (rev 4963) @@ -49,6 +49,7 @@ #define VSM_CHUNK_MAGIC 0x43907b6e /* From /dev/random */ unsigned magic; unsigned len; + unsigned state; char class[8]; char type[8]; char ident[16]; From phk at varnish-cache.org Wed Jun 16 12:25:47 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 16 Jun 2010 14:25:47 +0200 Subject: r4964 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-16 14:25:46 +0200 (Wed, 16 Jun 2010) New Revision: 4964 Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c Log: Better error handling, limit how long time we wait for initialization to complete. Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-16 11:16:09 UTC (rev 4963) +++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-16 12:25:46 UTC (rev 4964) @@ -142,7 +142,7 @@ static int vsm_open(struct VSM_data *vd, int diag) { - int i; + int i, j; struct vsm_head slh; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); @@ -161,6 +161,8 @@ if (diag) vd->diag(vd->priv, "%s is not a regular file\n", vd->fname); + AZ(close(vd->vsm_fd)); + vd->vsm_fd = -1; return (1); } @@ -169,12 +171,16 @@ if (diag) vd->diag(vd->priv, "Cannot read %s: %s\n", vd->fname, strerror(errno)); + AZ(close(vd->vsm_fd)); + vd->vsm_fd = -1; return (1); } if (slh.magic != VSM_HEAD_MAGIC) { if (diag) vd->diag(vd->priv, "Wrong magic number in file %s\n", vd->fname); + AZ(close(vd->vsm_fd)); + vd->vsm_fd = -1; return (1); } @@ -188,8 +194,17 @@ } vd->vsm_end = (uint8_t *)vd->vsm_head + slh.shm_size; - while(slh.alloc_seq == 0) - (void)usleep(50000); /* XXX limit total sleep */ + for (j = 0; j < 20 && slh.alloc_seq == 0; j++) + (void)usleep(50000); + if (slh.alloc_seq == 0) { + if (diag) + vd->diag(vd->priv, "File not initialized %s\n", + vd->fname); + assert(0 == munmap((void*)vd->vsm_head, slh.shm_size)); + AZ(close(vd->vsm_fd)); + vd->vsm_fd = -1; + return (1); + } vd->alloc_seq = slh.alloc_seq; if (vd->vsl != NULL) From phk at varnish-cache.org Wed Jun 16 12:47:08 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 16 Jun 2010 14:47:08 +0200 Subject: r4965 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-16 14:47:07 +0200 (Wed, 16 Jun 2010) New Revision: 4965 Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/mgt_child.c trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/bin/varnishd/vsm.c Log: Add mark/clean facility to VSM, so that all dynamic allocations gets Freeed (cooled) on child start. Modified: trunk/varnish-cache/bin/varnishd/cache_panic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_panic.c 2010-06-16 12:25:46 UTC (rev 4964) +++ trunk/varnish-cache/bin/varnishd/cache_panic.c 2010-06-16 12:47:07 UTC (rev 4965) @@ -341,18 +341,18 @@ vsb_bcat(vsp, "", 1); /* NUL termination */ if (params->diag_bitmap & 0x4000) - (void)fputs(loghead->panicstr, stderr); + (void)fputs(vsm_head->panicstr, stderr); #ifdef HAVE_ABORT2 if (params->diag_bitmap & 0x8000) { void *arg[1]; char *p; - for (p = loghead->panicstr; *p; p++) + for (p = vsm_head->panicstr; *p; p++) if (*p == '\n') *p = ' '; - arg[0] = loghead->panicstr; - abort2(loghead->panicstr, 1, arg); + arg[0] = vsm_head->panicstr; + abort2(vsm_head->panicstr, 1, arg); } #endif if (params->diag_bitmap & 0x1000) @@ -369,6 +369,6 @@ vas_fail = pan_ic; vsp = &vsps; - AN(vsb_new(vsp, loghead->panicstr, sizeof loghead->panicstr, + AN(vsb_new(vsp, vsm_head->panicstr, sizeof vsm_head->panicstr, VSB_FIXEDLEN)); } Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-16 12:25:46 UTC (rev 4964) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-16 12:47:07 UTC (rev 4965) @@ -43,7 +43,7 @@ static pthread_mutex_t vsl_mtx; static uint32_t *vsl_start; -static uint32_t *vsl_end; +static const uint32_t *vsl_end; static uint32_t *vsl_ptr; static inline uint32_t @@ -276,6 +276,8 @@ AZ(pthread_mutex_init(&vsl_mtx, NULL)); + VSM_Clean(); + VSM_ITER(vsc) if (!strcmp(vsc->class, VSL_CLASS)) break; @@ -285,8 +287,8 @@ vsl_ptr = vsl_start + 1; vsl_wrap(); - loghead->starttime = (intmax_t)TIM_real(); - loghead->panicstr[0] = '\0'; + vsm_head->starttime = (intmax_t)TIM_real(); + vsm_head->panicstr[0] = '\0'; memset(VSL_stats, 0, sizeof *VSL_stats); - loghead->child_pid = getpid(); + vsm_head->child_pid = getpid(); } Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2010-06-16 12:25:46 UTC (rev 4964) +++ trunk/varnish-cache/bin/varnishd/common.h 2010-06-16 12:47:07 UTC (rev 4965) @@ -71,12 +71,22 @@ /* vsm.c */ extern struct vsm_head *vsm_head; -extern void *vsm_end; +extern const struct vsm_chunk *vsm_end; void *VSM_Alloc(unsigned size, const char *class, const char *type, const char *ident); +void VSM_Free(const void *ptr); +void VSM_Clean(void); + struct vsm_chunk *vsm_iter_0(void); void vsm_iter_n(struct vsm_chunk **pp); #define VSM_ITER(vd) for ((vd) = vsm_iter_0(); (vd) != NULL; vsm_iter_n(&vd)) + +/* These classes are opaque to other programs, so we define the here */ +#define VSM_CLASS_FREE "Free" +#define VSM_CLASS_COOL "Cool" +#define VSM_CLASS_PARAM "Params" +#define VSM_CLASS_MARK "MgrCld" +#define VSM_COOL_TIME 5 Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_child.c 2010-06-16 12:25:46 UTC (rev 4964) +++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2010-06-16 12:47:07 UTC (rev 4965) @@ -461,10 +461,10 @@ mgt_report_panic(pid_t r) { - if (loghead->panicstr[0] == '\0') + if (vsm_head->panicstr[0] == '\0') return; REPORT(LOG_ERR, "Child (%jd) Panic message: %s", - (intmax_t)r, loghead->panicstr); + (intmax_t)r, vsm_head->panicstr); } /*--------------------------------------------------------------------*/ Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-16 12:25:46 UTC (rev 4964) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-16 12:47:07 UTC (rev 4965) @@ -114,7 +114,6 @@ #endif struct vsc_main *VSL_stats; -struct vsm_head *loghead; static int vsl_fd = -1; @@ -272,29 +271,28 @@ (void)close(i); vsl_buildnew(VSM_FILENAME, size, fill); - loghead = (void *)mmap(NULL, size, + vsm_head = (void *)mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_HASSEMAPHORE | MAP_NOSYNC | MAP_SHARED, vsl_fd, 0); - loghead->master_pid = getpid(); - xxxassert(loghead != MAP_FAILED); - (void)mlock((void*)loghead, size); + vsm_head->master_pid = getpid(); + xxxassert(vsm_head != MAP_FAILED); + (void)mlock((void*)vsm_head, size); - memset(&loghead->head, 0, sizeof loghead->head); - loghead->head.magic = VSM_CHUNK_MAGIC; - loghead->head.len = - (uint8_t*)(loghead) + size - (uint8_t*)&loghead->head; - bprintf(loghead->head.class, "%s", "Free"); + memset(&vsm_head->head, 0, sizeof vsm_head->head); + vsm_head->head.magic = VSM_CHUNK_MAGIC; + vsm_head->head.len = + (uint8_t*)(vsm_head) + size - (uint8_t*)&vsm_head->head; + bprintf(vsm_head->head.class, "%s", VSM_CLASS_FREE); VWMB(); - vsm_head = loghead; - vsm_end = (uint8_t*)loghead + size; + vsm_end = (void*)((uint8_t*)vsm_head + size); VSL_stats = VSM_Alloc(sizeof *VSL_stats, VSC_CLASS, VSC_TYPE_MAIN, ""); AN(VSL_stats); - pp = VSM_Alloc(sizeof *pp, "Params", "", ""); + pp = VSM_Alloc(sizeof *pp, VSM_CLASS_PARAM, "", ""); AN(pp); *pp = *params; params = pp; @@ -311,8 +309,8 @@ VWMB(); do - loghead->alloc_seq = random(); - while (loghead->alloc_seq == 0); + vsm_head->alloc_seq = random(); + while (vsm_head->alloc_seq == 0); } @@ -320,5 +318,5 @@ mgt_SHM_Pid(void) { - loghead->master_pid = getpid(); + vsm_head->master_pid = getpid(); } Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-16 12:25:46 UTC (rev 4964) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-16 12:47:07 UTC (rev 4965) @@ -631,6 +631,8 @@ if (T_arg != NULL) mgt_cli_telnet(T_arg); + VSM_Alloc(0, VSM_CLASS_MARK, "", ""); + MGT_Run(); if (pfh != NULL) Modified: trunk/varnish-cache/bin/varnishd/vsm.c =================================================================== --- trunk/varnish-cache/bin/varnishd/vsm.c 2010-06-16 12:25:46 UTC (rev 4964) +++ trunk/varnish-cache/bin/varnishd/vsm.c 2010-06-16 12:47:07 UTC (rev 4965) @@ -45,8 +45,31 @@ #include "vmb.h" struct vsm_head *vsm_head; -void *vsm_end; +const struct vsm_chunk *vsm_end; +static unsigned +vsm_mark(void) +{ + unsigned seq; + + seq = vsm_head->alloc_seq; + vsm_head->alloc_seq = 0; + VWMB(); + return (seq); +} + +static void +vsm_release(unsigned seq) +{ + + if (seq == 0) + return; + VWMB(); + do + vsm_head->alloc_seq = ++seq; + while (vsm_head->alloc_seq == 0); +} + /*--------------------------------------------------------------------*/ struct vsm_chunk * @@ -65,7 +88,7 @@ CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC); CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC); *pp = VSM_NEXT(*pp); - if ((void*)(*pp) >= vsm_end) { + if (*pp >= vsm_end) { *pp = NULL; return; } @@ -74,6 +97,63 @@ /*--------------------------------------------------------------------*/ +static void +vsm_cleanup(void) +{ + unsigned now = (unsigned)TIM_mono(); + struct vsm_chunk *sha, *sha2; + unsigned seq; + + CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC); + VSM_ITER(sha) { + if (strcmp(sha->class, VSM_CLASS_COOL)) + continue; + if (sha->state + VSM_COOL_TIME < now) + break; + } + if (sha == NULL) + return; + seq = vsm_mark(); + /* First pass, free, and collaps with next if applicable */ + VSM_ITER(sha) { + if (strcmp(sha->class, VSM_CLASS_COOL)) + continue; + if (sha->state + VSM_COOL_TIME >= now) + continue; + + bprintf(sha->class, "%s", VSM_CLASS_FREE); + bprintf(sha->type, "%s", ""); + bprintf(sha->ident, "%s", ""); + sha2 = VSM_NEXT(sha); + assert(sha2 <= vsm_end); + if (sha2 == vsm_end) + break; + CHECK_OBJ_NOTNULL(sha2, VSM_CHUNK_MAGIC); + if (!strcmp(sha2->class, VSM_CLASS_FREE)) { + sha->len += sha2->len; + memset(sha2, 0, sizeof *sha2); + } + sha->state = 0; + } + /* Second pass, collaps with prev if applicable */ + VSM_ITER(sha) { + if (strcmp(sha->class, VSM_CLASS_FREE)) + continue; + sha2 = VSM_NEXT(sha); + assert(sha2 <= vsm_end); + if (sha2 == vsm_end) + break; + CHECK_OBJ_NOTNULL(sha2, VSM_CHUNK_MAGIC); + if (!strcmp(sha2->class, VSM_CLASS_FREE)) { + sha->len += sha2->len; + memset(sha2, 0, sizeof *sha2); + } + } + vsm_release(seq); +} + +/*--------------------------------------------------------------------*/ + void * VSM_Alloc(unsigned size, const char *class, const char *type, const char *ident) { @@ -82,6 +162,8 @@ CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC); + vsm_cleanup(); + /* Round up to pointersize */ size += sizeof(void *) - 1; size &= ~(sizeof(void *) - 1); @@ -91,35 +173,77 @@ VSM_ITER(sha) { CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); - if (strcmp(sha->class, "Free")) + if (strcmp(sha->class, VSM_CLASS_FREE)) continue; - xxxassert(size <= sha->len); + if (size > sha->len) + continue; - sha2 = (void*)((uintptr_t)sha + size); + /* Mark as inconsistent while we write string fields */ + seq = vsm_mark(); - /* Mark as inconsistent while we write string fields */ - seq = vsm_head->alloc_seq; - vsm_head->alloc_seq = 0; - VWMB(); + if (size < sha->len) { + sha2 = (void*)((uintptr_t)sha + size); - memset(sha2, 0, sizeof *sha2); - sha2->magic = VSM_CHUNK_MAGIC; - sha2->len = sha->len - size; - bprintf(sha2->class, "%s", "Free"); + memset(sha2, 0, sizeof *sha2); + sha2->magic = VSM_CHUNK_MAGIC; + sha2->len = sha->len - size; + bprintf(sha2->class, "%s", VSM_CLASS_FREE); + sha->len = size; + } - sha->len = size; bprintf(sha->class, "%s", class); bprintf(sha->type, "%s", type); bprintf(sha->ident, "%s", ident); - VWMB(); - if (seq != 0) - do - loghead->alloc_seq = ++seq; - while (loghead->alloc_seq == 0); - + vsm_release(seq); return (VSM_PTR(sha)); } return (NULL); } + +/*--------------------------------------------------------------------*/ + +void +VSM_Free(const void *ptr) +{ + struct vsm_chunk *sha; + unsigned seq; + + CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC); + VSM_ITER(sha) + if (VSM_PTR(sha) == ptr) + break; + AN(sha); + seq = vsm_mark(); + bprintf(sha->class, "%s", VSM_CLASS_COOL); + sha->state = (unsigned)TIM_mono(); + vsm_release(seq); +} + +/*-------------------------------------------------------------------- + * Free all allocations after the mark (ie: allocated by child). + */ + +void +VSM_Clean(void) +{ + struct vsm_chunk *sha; + unsigned f, seq; + + CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC); + f = 0; + seq = vsm_mark(); + VSM_ITER(sha) { + if (f == 0 && !strcmp(sha->class, VSM_CLASS_MARK)) { + f = 1; + continue; + } + if (f == 0) + continue; + if (strcmp(sha->class, VSM_CLASS_FREE) && + strcmp(sha->class, VSM_CLASS_COOL)) + VSM_Free(VSM_PTR(sha)); + } + vsm_release(seq); +} From phk at varnish-cache.org Wed Jun 16 20:23:12 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 16 Jun 2010 22:23:12 +0200 Subject: r4966 - in trunk/varnish-cache: bin/varnishd include lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-16 22:23:12 +0200 (Wed, 16 Jun 2010) New Revision: 4966 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/include/vsc.h trunk/varnish-cache/include/vsc_fields.h trunk/varnish-cache/lib/libvarnishapi/vsc.c Log: Introduce the first per-backend stats counter: number of VCLs referencing this set of counters. Backend stats counters are indexed purely by the backend name, across all VCLs: If you redefine or have conflicting definitions of a backend with a given name, in different VCLs loaded at the same time, they will share stats counters. Not optimal, but I think the alternative would be worse. Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2010-06-16 12:47:07 UTC (rev 4965) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2010-06-16 20:23:12 UTC (rev 4966) @@ -456,6 +456,73 @@ } /*-------------------------------------------------------------------- + * Backend VSC counters + * + * We use a private list, because we do not trust the content of the + * VSM (to hold our refcount). + * + * Backend stats are indexed purely by name, across all VCLs. + */ + +struct vbe_cnt { + unsigned magic; +#define CNT_PRIV_MAGIC 0x1acda1f5 + VTAILQ_ENTRY(vbe_cnt) list; + char *name; + int refcnt; + struct vsc_vbe *vsc_vbe; +}; + +static VTAILQ_HEAD(, vbe_cnt) vbe_cnt_head = + VTAILQ_HEAD_INITIALIZER(vbe_cnt_head); + +static struct vsc_vbe * +vbe_stat_ref(const char *name) +{ + struct vbe_cnt *vc; + + ASSERT_CLI(); + VTAILQ_FOREACH(vc, &vbe_cnt_head, list) { + if (!strcmp(vc->name, name)) { + vc->refcnt++; + vc->vsc_vbe->vcls = vc->refcnt; + return (vc->vsc_vbe); + } + } + ALLOC_OBJ(vc, CNT_PRIV_MAGIC); + AN(vc); + REPLACE(vc->name, name); + VTAILQ_INSERT_HEAD(&vbe_cnt_head, vc, list); + vc->vsc_vbe = VSM_Alloc(sizeof *vc->vsc_vbe, + VSC_CLASS, VSC_TYPE_VBE, name); + AN(vc->vsc_vbe); + vc->refcnt = 1; + vc->vsc_vbe->vcls = vc->refcnt; + return (vc->vsc_vbe); +} + +static void +vbe_stat_deref(const char *name) +{ + struct vbe_cnt *vc; + + ASSERT_CLI(); + VTAILQ_FOREACH(vc, &vbe_cnt_head, list) + if (!strcmp(vc->name, name)) + break; + AN(vc); + vc->refcnt--; + vc->vsc_vbe->vcls = vc->refcnt; + if (vc->refcnt > 0) + return; + AZ(vc->refcnt); + VTAILQ_REMOVE(&vbe_cnt_head, vc, list); + VSM_Free(vc->vsc_vbe); + FREE_OBJ(vc); +} + + +/*-------------------------------------------------------------------- * The "simple" director really isn't, since thats where all the actual * connections happen. Nontheless, pretend it is simple by sequestering * the directoricity of it under this line. @@ -466,6 +533,7 @@ #define VDI_SIMPLE_MAGIC 0x476d25b7 struct director dir; struct backend *backend; + struct vsc_vbe *stats; }; static struct vbe_conn * @@ -507,6 +575,7 @@ CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC); VBE_DropRef(vs->backend); + vbe_stat_deref(vs->dir.vcl_name); free(vs->dir.vcl_name); vs->dir.magic = 0; FREE_OBJ(vs); @@ -534,6 +603,7 @@ vs->dir.healthy = vdi_simple_healthy; vs->backend = VBE_AddBackend(cli, t); + vs->stats = vbe_stat_ref(t->vcl_name); bp[idx] = &vs->dir; } Modified: trunk/varnish-cache/include/vsc.h =================================================================== --- trunk/varnish-cache/include/vsc.h 2010-06-16 12:47:07 UTC (rev 4965) +++ trunk/varnish-cache/include/vsc.h 2010-06-16 20:23:12 UTC (rev 4966) @@ -48,3 +48,11 @@ #include "vsc_fields.h" #undef VSC_F_SMA }; + +#define VSC_TYPE_VBE "VBE" + +struct vsc_vbe { +#define VSC_F_VBE(n, t, l, f, e) t n; +#include "vsc_fields.h" +#undef VSC_F_VBE +}; Modified: trunk/varnish-cache/include/vsc_fields.h =================================================================== --- trunk/varnish-cache/include/vsc_fields.h 2010-06-16 12:47:07 UTC (rev 4965) +++ trunk/varnish-cache/include/vsc_fields.h 2010-06-16 20:23:12 UTC (rev 4966) @@ -32,12 +32,12 @@ * stats structure. */ +/**********************************************************************/ #ifndef VSC_F_MAIN #define VSC_F_MAIN(a, b, c, d, e) #define __VSC_F_MAIN #endif - VSC_F_MAIN(client_conn, uint64_t, 0, 'a', "Client connections accepted") VSC_F_MAIN(client_drop, uint64_t, 0, 'a', "Connection dropped, no sess/wrk") @@ -161,6 +161,8 @@ #undef __VSC_F_MAIN #endif +/**********************************************************************/ + #ifndef VSC_F_SMA #define VSC_F_SMA(a, b, c, d, e) #define __VSC_F_SMA @@ -176,3 +178,17 @@ #undef VSC_F_SMA #undef __VSC_F_SMA #endif + +/**********************************************************************/ + +#ifndef VSC_F_VBE +#define VSC_F_VBE(a, b, c, d, e) +#define __VSC_F_VBE +#endif + +VSC_F_VBE(vcls, uint64_t, 0, 'i', "VCL references") + +#ifdef __VSC_F_VBE +#undef VSC_F_VBE +#undef __VSC_F_VBE +#endif Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-16 12:47:07 UTC (rev 4965) +++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-16 20:23:12 UTC (rev 4966) @@ -339,6 +339,34 @@ return (0); } +static int +iter_vbe(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func, + void *priv) +{ + struct vsc_vbe *st; + struct vsc_point sp; + int i; + + CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); + CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC); + st = VSM_PTR(sha); + + sp.class = VSC_TYPE_VBE; + sp.ident = sha->ident; +#define VSC_F_VBE(nn, tt, ll, ff, dd) \ + sp.name = #nn; \ + sp.fmt = #tt; \ + sp.flag = ff; \ + sp.desc = dd; \ + sp.ptr = &st->nn; \ + i = iter_call(vsc, func, priv, &sp); \ + if (i) \ + return(i); +#include "vsc_fields.h" +#undef VSC_F_VBE + return (0); +} + int VSC_Iter(struct VSM_data *vd, vsc_iter_f *func, void *priv) { @@ -359,6 +387,8 @@ i = iter_main(vsc, sha, func, priv); else if (!strcmp(sha->type, VSC_TYPE_SMA)) i = iter_sma(vsc, sha, func, priv); + else if (!strcmp(sha->type, VSC_TYPE_VBE)) + i = iter_vbe(vsc, sha, func, priv); else i = -1; if (i != 0) From phk at varnish-cache.org Wed Jun 16 22:15:27 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Thu, 17 Jun 2010 00:15:27 +0200 Subject: r4967 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl Message-ID: Author: phk Date: 2010-06-17 00:15:27 +0200 (Thu, 17 Jun 2010) New Revision: 4967 Added: trunk/varnish-cache/bin/varnishtest/tests/r00722.vtc Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_xref.c Log: Fix a problem in director teardown at vcl.discard time: We didn't create/destroy directors and backends in a consistent order, and in some case we even destroyed directors more than once. Always destroy in opposite order of creation (which follows VCL source order). Turn the bottom element of the array into (only) an indication of which backend/director is the default. Fixes: #722 Added: trunk/varnish-cache/bin/varnishtest/tests/r00722.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/r00722.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/r00722.vtc 2010-06-16 22:15:27 UTC (rev 4967) @@ -0,0 +1,31 @@ +# $Id$ + +test "Director cleanup fails on vcl.discard" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + director foo random { + { .backend = s1; .weight = 1; } + { .backend = { .host = "${s1_addr}"; .port = "${s1_port}";} .weight =1; } + { .backend = { .host = "${s1_addr}"; .port = "${s1_port}";} .weight =1; } + } + sub vcl_recv { + set req.backend = foo; + } +} -start + + +varnish v1 -vcl+backend { } + +varnish v1 -cliok "vcl.list" +varnish v1 -cliok "vcl.discard vcl1" + +client c1 { + txreq + rxresp +} -run + Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-16 20:23:12 UTC (rev 4966) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-16 22:15:27 UTC (rev 4967) @@ -607,8 +607,6 @@ sprintf(vgcname, "%.*s_%d", PF(tl->t_dir), serial); - Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(_%.*s));\n", - PF(tl->t_dir)); vcc_ParseHostDef(tl, serial, vgcname); if (tl->err) { vsb_printf(tl->sb, @@ -672,6 +670,7 @@ { struct token *t_first; struct dirlist const *dl; + int isfirst; t_first = tl->t; vcc_NextToken(tl); /* ID: director | backend */ @@ -682,14 +681,12 @@ vcc_NextToken(tl); + isfirst = tl->ndirector; if (vcc_IdIs(t_first, "backend")) { tl->t_policy = t_first; vcc_ParseSimpleDirector(tl); } else { - Fh(tl, 1, "\n#define VGC_backend__%.*s %d\n", - PF(tl->t_dir), tl->ndirector); vcc_AddDef(tl, tl->t_dir, R_BACKEND); - tl->ndirector++; ExpectErr(tl, ID); /* ID: policy */ tl->t_policy = tl->t; vcc_NextToken(tl); @@ -708,9 +705,14 @@ dl->func(tl); if (!tl->err) SkipToken(tl, '}'); + Fh(tl, 1, "\n#define VGC_backend__%.*s %d\n", + PF(tl->t_dir), tl->ndirector); + tl->ndirector++; Fi(tl, 0, "\tVRT_init_dir(cli, VCL_conf.director, \"%.*s\",\n", PF(tl->t_policy)); + Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(_%.*s));\n", + PF(tl->t_dir)); Fi(tl, 0, "\t VGC_backend__%.*s, &vgc_dir_priv_%.*s);\n", PF(tl->t_dir), PF(tl->t_dir)); @@ -722,6 +724,18 @@ vcc_ErrWhere(tl, t_first); return; } + + if (isfirst == 1) { + /* + * If this is the first backend|director explicitly + * defined, use it as default backend. + */ + Fi(tl, 0, + "\tVCL_conf.director[0] = VCL_conf.director[%d];\n", + tl->ndirector - 1); + vcc_AddRef(tl, tl->t_dir, R_BACKEND); + } + tl->t_policy = NULL; tl->t_dir = NULL; } Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-16 20:23:12 UTC (rev 4966) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-16 22:15:27 UTC (rev 4967) @@ -469,6 +469,7 @@ VTAILQ_INIT(&tl->sources); tl->nsources = 0; + tl->ndirector = 1; /* General C code */ tl->fc = vsb_newauto(); @@ -580,7 +581,7 @@ return (vcc_DestroyTokenList(tl, NULL)); /* Check if we have any backends at all */ - if (tl->ndirector == 0) { + if (tl->ndirector == 1) { vsb_printf(tl->sb, "No backends or directors found in VCL program, " "at least one is necessary.\n"); Modified: trunk/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_xref.c 2010-06-16 20:23:12 UTC (rev 4966) +++ trunk/varnish-cache/lib/libvcl/vcc_xref.c 2010-06-16 22:15:27 UTC (rev 4967) @@ -143,10 +143,6 @@ } r->defcnt++; r->name = t; - - /* The first backend is the default and thus has an implicit ref */ - if (type == R_BACKEND && tl->ndirector == 0) - r->refcnt++; } /*--------------------------------------------------------------------*/ From phk at varnish-cache.org Thu Jun 17 08:45:34 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Thu, 17 Jun 2010 10:45:34 +0200 Subject: r4968 - trunk/varnish-cache/lib/libvcl Message-ID: Author: phk Date: 2010-06-17 10:45:34 +0200 (Thu, 17 Jun 2010) New Revision: 4968 Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c Log: Destroy directors before their embedded backends. Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-16 22:15:27 UTC (rev 4967) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-17 08:45:34 UTC (rev 4968) @@ -701,6 +701,8 @@ vcc_ErrWhere(tl, tl->t_policy); return; } + Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(_%.*s));\n", + PF(tl->t_dir)); SkipToken(tl, '{'); dl->func(tl); if (!tl->err) @@ -711,8 +713,6 @@ Fi(tl, 0, "\tVRT_init_dir(cli, VCL_conf.director, \"%.*s\",\n", PF(tl->t_policy)); - Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(_%.*s));\n", - PF(tl->t_dir)); Fi(tl, 0, "\t VGC_backend__%.*s, &vgc_dir_priv_%.*s);\n", PF(tl->t_dir), PF(tl->t_dir)); From phk at varnish-cache.org Thu Jun 17 08:46:17 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Thu, 17 Jun 2010 10:46:17 +0200 Subject: r4969 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-17 10:46:17 +0200 (Thu, 17 Jun 2010) New Revision: 4969 Modified: trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/hash_slinger.h Log: FlexeLint inspired garbage collection Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2010-06-17 08:45:34 UTC (rev 4968) +++ trunk/varnish-cache/bin/varnishd/common.h 2010-06-17 08:46:17 UTC (rev 4969) @@ -39,15 +39,12 @@ void VCA_tweak_waiter(struct cli *cli, const char *arg); /* mgt_shmem.c */ -void *mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident); extern struct vsc_main *VSL_stats; -extern struct vsm_head *loghead; /* varnishd.c */ struct vsb; extern struct vsb *vident; int Symbol_Lookup(struct vsb *vsb, void *ptr); -extern unsigned L_arg; #define TRUST_ME(ptr) ((void*)(uintptr_t)(ptr)) Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2010-06-17 08:45:34 UTC (rev 4968) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2010-06-17 08:46:17 UTC (rev 4969) @@ -77,26 +77,20 @@ int refcnt; VTAILQ_HEAD(,objcore) objcs; unsigned char digest[DIGEST_LEN]; - union { - VTAILQ_HEAD(, sess) __u_waitinglist; - VTAILQ_ENTRY(objhead) __u_coollist; - } __u; -#define waitinglist __u.__u_waitinglist -#define coollist __u.__u_coollist + VTAILQ_HEAD(, sess) waitinglist; /*---------------------------------------------------- * The fields below are for the sole private use of * the hash implementation(s). */ union { - void *filler[3]; struct { VTAILQ_ENTRY(objhead) u_n_hoh_list; void *u_n_hoh_head; } n; - } u; -#define hoh_list u.n.u_n_hoh_list -#define hoh_head u.n.u_n_hoh_head + } _u; +#define hoh_list _u.n.u_n_hoh_list +#define hoh_head _u.n.u_n_hoh_head }; void HSH_DeleteObjHead(struct worker *w, struct objhead *oh); From phk at varnish-cache.org Thu Jun 17 08:47:20 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Thu, 17 Jun 2010 10:47:20 +0200 Subject: r4970 - in trunk/varnish-cache/bin: varnishd varnishstat Message-ID: Author: phk Date: 2010-06-17 10:47:19 +0200 (Thu, 17 Jun 2010) New Revision: 4970 Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_esi.c trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_pool.c trunk/varnish-cache/bin/varnishd/cache_response.c trunk/varnish-cache/bin/varnishd/cache_session.c trunk/varnish-cache/bin/varnishd/cache_shmlog.c trunk/varnish-cache/bin/varnishd/cache_vcl.c trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/hash_critbit.c trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/mgt_shmem.c trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/storage_synth.c trunk/varnish-cache/bin/varnishd/storage_umem.c trunk/varnish-cache/bin/varnishstat/varnishstat.c trunk/varnish-cache/bin/varnishstat/varnishstat.h trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c Log: Rename main counter struct from VSL to VSC namespace Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -265,19 +265,19 @@ TIM_sleep(pace); i = poll(pfd, heritage.nsocks, 1000); now = TIM_real(); - VSL_stats->uptime = (uint64_t)(now - t0); + VSC_main->uptime = (uint64_t)(now - t0); u = 0; VTAILQ_FOREACH(ls, &heritage.socks, list) { if (ls->sock < 0) continue; if (pfd[u++].revents == 0) continue; - VSL_stats->client_conn++; + VSC_main->client_conn++; l = sizeof addr_s; addr = (void*)&addr_s; i = accept(ls->sock, addr, &l); if (i < 0) { - VSL_stats->accept_fail++; + VSC_main->accept_fail++; switch (errno) { case EAGAIN: case ECONNABORTED: @@ -300,7 +300,7 @@ sp = SES_New(); if (sp == NULL) { AZ(close(i)); - VSL_stats->client_drop++; + VSC_main->client_drop++; pace += params->acceptor_sleep_incr; continue; } @@ -315,7 +315,7 @@ sp->step = STP_FIRST; if (WRK_QueueSession(sp)) { - VSL_stats->client_drop++; + VSC_main->client_drop++; pace += params->acceptor_sleep_incr; } else { pace *= params->acceptor_sleep_decay; @@ -343,7 +343,7 @@ case 1: sp->step = STP_START; if (WRK_QueueSession(sp)) - VSL_stats->client_drop_late++; + VSC_main->client_drop_late++; break; default: INCOMPL(); Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -80,11 +80,11 @@ if (params->cache_vbe_conns) { Lck_Lock(&VBE_mtx); VTAILQ_INSERT_HEAD(&vbe_conns, vc, list); - VSL_stats->backend_unused++; + VSC_main->backend_unused++; Lck_Unlock(&VBE_mtx); } else { Lck_Lock(&VBE_mtx); - VSL_stats->n_vbe_conn--; + VSC_main->n_vbe_conn--; Lck_Unlock(&VBE_mtx); free(vc); } @@ -212,7 +212,7 @@ Lck_Lock(&VBE_mtx); vc = VTAILQ_FIRST(&vbe_conns); if (vc != NULL) { - VSL_stats->backend_unused--; + VSC_main->backend_unused--; VTAILQ_REMOVE(&vbe_conns, vc, list); } Lck_Unlock(&VBE_mtx); @@ -224,7 +224,7 @@ vc->magic = VBE_CONN_MAGIC; vc->fd = -1; Lck_Lock(&VBE_mtx); - VSL_stats->n_vbe_conn++; + VSC_main->n_vbe_conn++; Lck_Unlock(&VBE_mtx); return (vc); } @@ -335,23 +335,23 @@ break; if (vbe_CheckFd(vc->fd)) { /* XXX locking of stats */ - VSL_stats->backend_reuse += 1; + VSC_main->backend_reuse += 1; WSP(sp, SLT_Backend, "%d %s %s", vc->fd, sp->director->vcl_name, bp->vcl_name); return (vc); } - VSL_stats->backend_toolate++; + VSC_main->backend_toolate++; sp->vbe = vc; VBE_ClosedFd(sp); } if (!vbe_Healthy(sp->t_req, (uintptr_t)sp->objhead, bp)) { - VSL_stats->backend_unhealthy++; + VSC_main->backend_unhealthy++; return (NULL); } if (bp->max_conn > 0 && bp->n_conn >= bp->max_conn) { - VSL_stats->backend_busy++; + VSC_main->backend_busy++; return (NULL); } @@ -361,11 +361,11 @@ vc->fd = bes_conn_try(sp, bp); if (vc->fd < 0) { VBE_ReleaseConn(vc); - VSL_stats->backend_fail++; + VSC_main->backend_fail++; return (NULL); } vc->backend = bp; - VSL_stats->backend_conn++; + VSC_main->backend_conn++; WSP(sp, SLT_Backend, "%d %s %s", vc->fd, sp->director->vcl_name, bp->vcl_name); return (vc); @@ -412,7 +412,7 @@ */ WSL_Flush(sp->wrk, 0); Lck_Lock(&bp->mtx); - VSL_stats->backend_recycle++; + VSC_main->backend_recycle++; VTAILQ_INSERT_HEAD(&bp->connlist, sp->vbe, list); sp->vbe = NULL; VBE_DropRefLocked(bp); Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -72,7 +72,7 @@ free(b->ipv4); free(b->ipv6); FREE_OBJ(b); - VSL_stats->n_backend--; + VSC_main->n_backend--; } /*-------------------------------------------------------------------- @@ -253,7 +253,7 @@ VBP_Start(b, &vb->probe); VTAILQ_INSERT_TAIL(&backends, b, list); - VSL_stats->n_backend++; + VSC_main->n_backend++; return (b); } Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -323,8 +323,8 @@ Lck_Lock(&ban_mtx); VTAILQ_INSERT_HEAD(&ban_head, b, list); ban_start = b; - VSL_stats->n_purge++; - VSL_stats->n_purge_add++; + VSC_main->n_purge++; + VSC_main->n_purge_add++; be = VTAILQ_LAST(&ban_head, banhead); if (params->purge_dups && be != b) @@ -352,7 +352,7 @@ } Lck_Lock(&ban_mtx); be->refcount--; - VSL_stats->n_purge_dups += pcount; + VSC_main->n_purge_dups += pcount; Lck_Unlock(&ban_mtx); } @@ -379,8 +379,8 @@ Lck_AssertHeld(&ban_mtx); b = VTAILQ_LAST(&ban_head, banhead); if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) { - VSL_stats->n_purge--; - VSL_stats->n_purge_retire++; + VSC_main->n_purge--; + VSC_main->n_purge_retire++; VTAILQ_REMOVE(&ban_head, b, list); } else { b = NULL; @@ -455,8 +455,8 @@ VTAILQ_INSERT_TAIL(&b0->objcore, o->objcore, ban_list); b0->refcount++; } - VSL_stats->n_purge_obj_test++; - VSL_stats->n_purge_re_test += tests; + VSC_main->n_purge_obj_test++; + VSC_main->n_purge_re_test += tests; Lck_Unlock(&ban_mtx); if (b == o->ban) { /* not banned */ @@ -629,8 +629,8 @@ break; } - VSL_stats->n_purge++; - VSL_stats->n_purge_add++; + VSC_main->n_purge++; + VSC_main->n_purge_add++; b2 = BAN_New(); AN(b2); Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -200,7 +200,7 @@ char buf[256], *q; txt t; - VSL_stats->esi_errors++; + VSC_main->esi_errors++; if (i == 0) i = p - ew->t.b; if (i > 20) { @@ -733,7 +733,7 @@ /* XXX: debugging hack */ hack = sp->wrk->ws->f; - VSL_stats->esi_parse++; + VSC_main->esi_parse++; /* XXX: only if GET ? */ ew = eww; memset(eww, 0, sizeof eww); Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -194,7 +194,7 @@ if (oc->flags & OC_F_ONLRU) { /* XXX ?? */ VLIST_REMOVE(oc, lru_list); VLIST_INSERT_BEFORE(&lru->senteniel, oc, lru_list); - VSL_stats->n_lru_moved++; + VSC_main->n_lru_moved++; retval = 1; } Lck_Unlock(&exp_mtx); @@ -288,7 +288,7 @@ oc->flags &= ~OC_F_ONLRU; } - VSL_stats->n_expired++; + VSC_main->n_expired++; Lck_Unlock(&exp_mtx); @@ -353,7 +353,7 @@ oc->flags &= ~OC_F_ONLRU; binheap_delete(exp_heap, oc->timer_idx); assert(oc->timer_idx == BINHEAP_NOIDX); - VSL_stats->n_lru_nuked++; + VSC_main->n_lru_nuked++; } Lck_Unlock(&exp_mtx); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -383,7 +383,7 @@ WSL_Flush(w, 0); /* XXX is this the right place? */ - VSL_stats->backend_req++; + VSC_main->backend_req++; /* Receive response */ Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -484,7 +484,7 @@ * We could not schedule the session, leave the * rest on the busy list. */ - VSL_stats->client_drop_late++; + VSC_main->client_drop_late++; break; } } Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -408,7 +408,7 @@ WSLH(w, fd, hp, hp->nhd); hp->nhd++; } else { - VSL_stats->losthdr++; + VSC_main->losthdr++; WSL(w, SLT_LostHeader, fd, "%.*s", q - p, p); return (400); } @@ -650,7 +650,7 @@ to->hdf[to->nhd] = 0; to->nhd++; } else { - VSL_stats->losthdr++; + VSC_main->losthdr++; WSLR(w, SLT_LostHeader, fd, fm->hd[n]); } } @@ -759,7 +759,7 @@ hp->hd[u].e = p + l; } else { /* XXX This leaves a slot empty */ - VSL_stats->losthdr++; + VSC_main->losthdr++; WSLR(w, SLT_LostHeader, fd, hp->hd[u]); hp->hd[u].b = NULL; hp->hd[u].e = NULL; @@ -787,7 +787,7 @@ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC); if (to->nhd >= to->shd) { - VSL_stats->losthdr++; + VSC_main->losthdr++; WSL(w, SLT_LostHeader, fd, "%s", hdr); return; } @@ -859,7 +859,7 @@ n = vsnprintf(to->ws->f, l, fmt, ap); va_end(ap); if (n + 1 >= l || to->nhd >= to->shd) { - VSL_stats->losthdr++; + VSC_main->losthdr++; WSL(w, SLT_LostHeader, fd, "%s", to->ws->f); WS_Release(to->ws, 0); } else { Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pool.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -95,7 +95,7 @@ Lck_AssertHeld(&wstat_mtx); #define L0(n) -#define L1(n) (VSL_stats->n += w->stats.n) +#define L1(n) (VSC_main->n += w->stats.n) #define VSC_F_MAIN(n, t, l, f, d) L##l(n); #include "vsc_fields.h" #undef VSC_F_MAIN @@ -445,10 +445,10 @@ for (u = 0; u < nwq; u++) wrk_decimate_flock(wq[u], t_idle, vs); - VSL_stats->n_wrk= vs->n_wrk; - VSL_stats->n_wrk_queue = vs->n_wrk_queue; - VSL_stats->n_wrk_drop = vs->n_wrk_drop; - VSL_stats->n_wrk_overflow = vs->n_wrk_overflow; + VSC_main->n_wrk= vs->n_wrk; + VSC_main->n_wrk_queue = vs->n_wrk_queue; + VSC_main->n_wrk_drop = vs->n_wrk_drop; + VSC_main->n_wrk_overflow = vs->n_wrk_overflow; TIM_sleep(params->wthread_purge_delay * 1e-3); } @@ -472,15 +472,15 @@ (qp->nqueue > params->wthread_add_threshold && /* more needed */ qp->nqueue > qp->lqueue)) { /* not getting better since last */ if (qp->nthr >= nthr_max) { - VSL_stats->n_wrk_max++; + VSC_main->n_wrk_max++; } else if (pthread_create(&tp, tp_attr, wrk_thread, qp)) { VSL(SLT_Debug, 0, "Create worker thread failed %d %s", errno, strerror(errno)); - VSL_stats->n_wrk_failed++; + VSC_main->n_wrk_failed++; TIM_sleep(params->wthread_fail_delay * 1e-3); } else { AZ(pthread_detach(tp)); - VSL_stats->n_wrk_create++; + VSC_main->n_wrk_create++; TIM_sleep(params->wthread_add_delay * 1e-3); } } Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -343,12 +343,12 @@ */ if (st->fd >= 0 && st->len >= params->sendfile_threshold) { - VSL_stats->n_objsendfile++; + VSC_main->n_objsendfile++; WRW_Sendfile(sp->wrk, st->fd, st->where + off, len); continue; } #endif /* SENDFILE_WORKS */ - VSL_stats->n_objwrite++; + VSC_main->n_objwrite++; (void)WRW_Write(sp->wrk, st->ptr + off, len); } assert(u == sp->obj->len); Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -107,7 +107,7 @@ volatile unsigned nhttp; unsigned l, hl; - if (VSL_stats->n_sess_mem >= params->max_sess) + if (VSC_main->n_sess_mem >= params->max_sess) return (NULL); /* * It is not necessary to lock these, but we need to @@ -124,7 +124,7 @@ q = p + l; Lck_Lock(&stat_mtx); - VSL_stats->n_sess_mem++; + VSC_main->n_sess_mem++; Lck_Unlock(&stat_mtx); /* Don't waste time zeroing the workspace */ @@ -216,7 +216,7 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); } - VSL_stats->n_sess++; /* XXX: locking ? */ + VSC_main->n_sess++; /* XXX: locking ? */ return (sp); } @@ -256,7 +256,7 @@ AZ(sp->obj); AZ(sp->vcl); - VSL_stats->n_sess--; /* XXX: locking ? */ + VSC_main->n_sess--; /* XXX: locking ? */ assert(!isnan(b->first)); assert(!isnan(sp->t_end)); VSL(SLT_StatSess, sp->id, "%s %s %.0f %ju %ju %ju %ju %ju %ju %ju", @@ -265,7 +265,7 @@ b->fetch, b->hdrbytes, b->bodybytes); if (sm->workspace != params->sess_workspace) { Lck_Lock(&stat_mtx); - VSL_stats->n_sess_mem--; + VSC_main->n_sess_mem--; Lck_Unlock(&stat_mtx); free(sm); } else { @@ -277,7 +277,7 @@ } /* Try to precreate some ses-mem so the acceptor will not have to */ - if (VSL_stats->n_sess_mem < VSL_stats->n_sess + 10) { + if (VSC_main->n_sess_mem < VSC_main->n_sess + 10) { sm = ses_sm_alloc(); if (sm != NULL) { ses_setup(sm); Modified: trunk/varnish-cache/bin/varnishd/cache_shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -84,7 +84,7 @@ *vsl_ptr = VSL_WRAPMARKER; vsl_ptr = vsl_start + 1; } - VSL_stats->shm_cycles++; + VSC_main->shm_cycles++; } /*-------------------------------------------------------------------- @@ -98,14 +98,14 @@ if (pthread_mutex_trylock(&vsl_mtx)) { AZ(pthread_mutex_lock(&vsl_mtx)); - VSL_stats->shm_cont++; + VSC_main->shm_cont++; } assert(vsl_ptr < vsl_end); assert(((uintptr_t)vsl_ptr & 0x3) == 0); - VSL_stats->shm_writes++; - VSL_stats->shm_flushes += flushes; - VSL_stats->shm_records += records; + VSC_main->shm_writes++; + VSC_main->shm_flushes += flushes; + VSC_main->shm_records += records; /* Wrap if necessary */ if (VSL_END(vsl_ptr, len) >= vsl_end) @@ -289,6 +289,6 @@ vsl_wrap(); vsm_head->starttime = (intmax_t)TIM_real(); vsm_head->panicstr[0] = '\0'; - memset(VSL_stats, 0, sizeof *VSL_stats); + memset(VSC_main, 0, sizeof *VSC_main); vsm_head->child_pid = getpid(); } Modified: trunk/varnish-cache/bin/varnishd/cache_vcl.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vcl.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/cache_vcl.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -180,8 +180,8 @@ Lck_Unlock(&vcl_mtx); cli_out(cli, "Loaded \"%s\" as \"%s\"", fn , name); vcl->conf->init_func(cli); - VSL_stats->n_vcl++; - VSL_stats->n_vcl_avail++; + VSC_main->n_vcl++; + VSC_main->n_vcl_avail++; return (0); } @@ -203,8 +203,8 @@ free(vcl->name); (void)dlclose(vcl->dlh); FREE_OBJ(vcl); - VSL_stats->n_vcl--; - VSL_stats->n_vcl_discard--; + VSC_main->n_vcl--; + VSC_main->n_vcl_discard--; } /*--------------------------------------------------------------------*/ @@ -278,8 +278,8 @@ cli_out(cli, "VCL %s is the active VCL", av[2]); return; } - VSL_stats->n_vcl_discard++; - VSL_stats->n_vcl_avail--; + VSC_main->n_vcl_discard++; + VSC_main->n_vcl_avail--; vcl->conf->discard = 1; Lck_Unlock(&vcl_mtx); if (vcl->conf->busy == 0) Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/common.h 2010-06-17 08:47:19 UTC (rev 4970) @@ -39,7 +39,7 @@ void VCA_tweak_waiter(struct cli *cli, const char *arg); /* mgt_shmem.c */ -extern struct vsc_main *VSL_stats; +extern struct vsc_main *VSC_main; /* varnishd.c */ struct vsb; Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_critbit.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/hash_critbit.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -437,19 +437,19 @@ } AN(sp->wrk->nhashpriv); Lck_Lock(&hcb_mtx); - VSL_stats->hcb_lock++; + VSC_main->hcb_lock++; assert(noh->refcnt == 1); oh = hcb_insert(sp->wrk, &hcb_root, noh, 1); Lck_Unlock(&hcb_mtx); } else { - VSL_stats->hcb_nolock++; + VSC_main->hcb_nolock++; oh = hcb_insert(sp->wrk, &hcb_root, noh, 0); } if (oh != NULL && oh == noh) { /* Assert that we only muck with the tree with a lock */ assert(with_lock); - VSL_stats->hcb_insert++; + VSC_main->hcb_insert++; assert(oh->refcnt > 0); return (oh); } Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -80,10 +80,10 @@ (void)av; (void)priv; - AN(VSL_stats); + AN(VSC_main); #define VSC_F_MAIN(n, t, l, f, d) \ - if (VSL_stats->n != 0) \ - cli_out(cli, "%12ju %s\n", (VSL_stats->n), d); + if (VSC_main->n != 0) \ + cli_out(cli, "%12ju %s\n", (VSC_main->n), d); #include "vsc_fields.h" #undef VSC_F_MAIN } Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -113,7 +113,7 @@ #define MAP_NOSYNC 0 /* XXX Linux */ #endif -struct vsc_main *VSL_stats; +struct vsc_main *VSC_main; static int vsl_fd = -1; @@ -288,9 +288,9 @@ vsm_end = (void*)((uint8_t*)vsm_head + size); - VSL_stats = VSM_Alloc(sizeof *VSL_stats, + VSC_main = VSM_Alloc(sizeof *VSC_main, VSC_CLASS, VSC_TYPE_MAIN, ""); - AN(VSL_stats); + AN(VSC_main); pp = VSM_Alloc(sizeof *pp, VSM_CLASS_PARAM, "", ""); AN(pp); Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -181,9 +181,9 @@ b = sp->size / sc->pagesize; if (b >= NBUCKET) { b = NBUCKET - 1; - VSL_stats->n_smf_large++; + VSC_main->n_smf_large++; } else { - VSL_stats->n_smf_frag++; + VSC_main->n_smf_frag++; } sp->flist = &sc->free[b]; ns = b * sc->pagesize; @@ -211,9 +211,9 @@ b = sp->size / sc->pagesize; if (b >= NBUCKET) { b = NBUCKET - 1; - VSL_stats->n_smf_large--; + VSC_main->n_smf_large--; } else { - VSL_stats->n_smf_frag--; + VSC_main->n_smf_frag--; } assert(sp->flist == &sc->free[b]); VTAILQ_REMOVE(sp->flist, sp, status); @@ -259,7 +259,7 @@ /* Split from front */ sp2 = malloc(sizeof *sp2); XXXAN(sp2); - VSL_stats->n_smf++; + VSC_main->n_smf++; *sp2 = *sp; sp->offset += bytes; @@ -301,7 +301,7 @@ VTAILQ_REMOVE(&sc->order, sp2, order); remfree(sc, sp2); free(sp2); - VSL_stats->n_smf--; + VSC_main->n_smf--; } sp2 = VTAILQ_PREV(sp, smfhead, order); @@ -313,7 +313,7 @@ sp2->size += sp->size; VTAILQ_REMOVE(&sc->order, sp, order); free(sp); - VSL_stats->n_smf--; + VSC_main->n_smf--; sp = sp2; } @@ -338,7 +338,7 @@ CHECK_OBJ_NOTNULL(sp, SMF_MAGIC); sp2 = malloc(sizeof *sp2); XXXAN(sp2); - VSL_stats->n_smf++; + VSC_main->n_smf++; *sp2 = *sp; sp2->size -= bytes; @@ -364,7 +364,7 @@ XXXAN(sp); sp->magic = SMF_MAGIC; sp->s.magic = STORAGE_MAGIC; - VSL_stats->n_smf++; + VSC_main->n_smf++; sp->sc = sc; sp->size = len; @@ -450,7 +450,7 @@ if (sum < MINPAGES * (off_t)getpagesize()) exit (2); - VSL_stats->sm_bfree += sc->filesize; + VSC_main->sm_bfree += sc->filesize; } /*--------------------------------------------------------------------*/ @@ -466,16 +466,16 @@ size += (sc->pagesize - 1); size &= ~(sc->pagesize - 1); Lck_Lock(&sc->mtx); - VSL_stats->sm_nreq++; + VSC_main->sm_nreq++; smf = alloc_smf(sc, size); if (smf == NULL) { Lck_Unlock(&sc->mtx); return (NULL); } CHECK_OBJ_NOTNULL(smf, SMF_MAGIC); - VSL_stats->sm_nobj++; - VSL_stats->sm_balloc += smf->size; - VSL_stats->sm_bfree -= smf->size; + VSC_main->sm_nobj++; + VSC_main->sm_balloc += smf->size; + VSC_main->sm_bfree -= smf->size; Lck_Unlock(&sc->mtx); CHECK_OBJ_NOTNULL(&smf->s, STORAGE_MAGIC); /*lint !e774 */ XXXAN(smf); @@ -509,8 +509,8 @@ size &= ~(sc->pagesize - 1); if (smf->size > size) { Lck_Lock(&sc->mtx); - VSL_stats->sm_balloc -= (smf->size - size); - VSL_stats->sm_bfree += (smf->size - size); + VSC_main->sm_balloc -= (smf->size - size); + VSC_main->sm_bfree += (smf->size - size); trim_smf(smf, size); assert(smf->size == size); Lck_Unlock(&sc->mtx); @@ -531,9 +531,9 @@ CAST_OBJ_NOTNULL(smf, s->priv, SMF_MAGIC); sc = smf->sc; Lck_Lock(&sc->mtx); - VSL_stats->sm_nobj--; - VSL_stats->sm_balloc -= smf->size; - VSL_stats->sm_bfree += smf->size; + VSC_main->sm_nobj--; + VSC_main->sm_balloc -= smf->size; + VSC_main->sm_bfree += smf->size; free_smf(smf); Lck_Unlock(&sc->mtx); } Modified: trunk/varnish-cache/bin/varnishd/storage_synth.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_synth.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/storage_synth.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -52,9 +52,9 @@ CHECK_OBJ_NOTNULL(sto, STORAGE_MAGIC); Lck_Lock(&sms_mtx); - VSL_stats->sms_nobj--; - VSL_stats->sms_nbytes -= sto->len; - VSL_stats->sms_bfree += sto->len; + VSC_main->sms_nobj--; + VSC_main->sms_nbytes -= sto->len; + VSC_main->sms_bfree += sto->len; Lck_Unlock(&sms_mtx); vsb_delete(sto->priv); free(sto); @@ -84,8 +84,8 @@ obj->len = 0; Lck_Lock(&sms_mtx); - VSL_stats->sms_nreq++; - VSL_stats->sms_nobj++; + VSC_main->sms_nreq++; + VSC_main->sms_nobj++; Lck_Unlock(&sms_mtx); sto = calloc(sizeof *sto, 1); @@ -120,6 +120,6 @@ sto->len = vsb_len(vsb); sto->space = vsb_len(vsb); obj->len = sto->len; - VSL_stats->sms_nbytes += sto->len; - VSL_stats->sms_balloc += sto->len; + VSC_main->sms_nbytes += sto->len; + VSC_main->sms_balloc += sto->len; } Modified: trunk/varnish-cache/bin/varnishd/storage_umem.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_umem.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishd/storage_umem.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -62,13 +62,13 @@ struct smu *smu; Lck_Lock(&smu_mtx); - VSL_stats->sma_nreq++; - if (VSL_stats->sma_nbytes + size > smu_max) + VSC_main->sma_nreq++; + if (VSC_main->sma_nbytes + size > smu_max) size = 0; else { - VSL_stats->sma_nobj++; - VSL_stats->sma_nbytes += size; - VSL_stats->sma_balloc += size; + VSC_main->sma_nobj++; + VSC_main->sma_nbytes += size; + VSC_main->sma_balloc += size; } Lck_Unlock(&smu_mtx); @@ -100,9 +100,9 @@ smu = s->priv; assert(smu->sz == smu->s.space); Lck_Lock(&smu_mtx); - VSL_stats->sma_nobj--; - VSL_stats->sma_nbytes -= smu->sz; - VSL_stats->sma_bfree += smu->sz; + VSC_main->sma_nobj--; + VSC_main->sma_nbytes -= smu->sz; + VSC_main->sma_bfree += smu->sz; Lck_Unlock(&smu_mtx); umem_free(smu->s.ptr, smu->s.space); umem_free(smu, sizeof *smu); @@ -121,8 +121,8 @@ memcpy(p, smu->s.ptr, size); umem_free(smu->s.ptr, smu->s.space); Lck_Lock(&smu_mtx); - VSL_stats->sma_nbytes -= (smu->sz - size); - VSL_stats->sma_bfree += smu->sz - size; + VSC_main->sma_nbytes -= (smu->sz - size); + VSC_main->sma_bfree += smu->sz - size; smu->sz = size; Lck_Unlock(&smu_mtx); smu->s.ptr = p; Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -121,12 +121,12 @@ } static void -do_once(struct VSM_data *vd, const struct vsc_main *VSL_stats) +do_once(struct VSM_data *vd, const struct vsc_main *VSC_main) { struct once_priv op; memset(&op, 0, sizeof op); - op.up = VSL_stats->uptime; + op.up = VSC_main->uptime; op.pad = 18; (void)VSC_Iter(vd, do_once_cb, &op); @@ -195,7 +195,7 @@ { int c; struct VSM_data *vd; - const struct vsc_main *VSL_stats; + const struct vsc_main *VSC_main; int delay = 1, once = 0, xml = 0; vd = VSM_New(); @@ -230,14 +230,14 @@ if (VSC_Open(vd, 1)) exit(1); - VSL_stats = VSC_Main(vd); + VSC_main = VSC_Main(vd); if (xml) do_xml(vd); else if (once) - do_once(vd, VSL_stats); + do_once(vd, VSC_main); else - do_curses(vd, VSL_stats, delay); + do_curses(vd, VSC_main, delay); exit(0); } Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.h =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat.h 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishstat/varnishstat.h 2010-06-17 08:47:19 UTC (rev 4970) @@ -27,4 +27,4 @@ * */ -void do_curses(struct VSM_data *vd, const struct vsc_main *VSL_stats, int delay); +void do_curses(struct VSM_data *vd, const struct vsc_main *VSC_main, int delay); Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c =================================================================== --- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-17 08:46:17 UTC (rev 4969) +++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c 2010-06-17 08:47:19 UTC (rev 4970) @@ -123,7 +123,7 @@ } void -do_curses(struct VSM_data *vd, const struct vsc_main *VSL_stats, +do_curses(struct VSM_data *vd, const struct vsc_main *VSC_main, int delay) { intmax_t ju; @@ -167,7 +167,7 @@ * Break to outher loop if we need to re-read file. * Only check if it looks like nothing is happening. */ - act = VSL_stats->cache_hit + VSL_stats->cache_miss + 1; + act = VSC_main->cache_hit + VSC_main->cache_miss + 1; if (act == lact && VSM_ReOpen(vd, 1)) break; lact = act; @@ -176,15 +176,15 @@ tt = tv.tv_usec * 1e-6 + tv.tv_sec; lt = tt - lt; - rt = VSL_stats->uptime; + rt = VSC_main->uptime; up = rt; AC(mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd))); AC(mvprintw(0, 0, "%d+%02d:%02d:%02d", rt / 86400, (rt % 86400) / 3600, (rt % 3600) / 60, rt % 60)); - hit = VSL_stats->cache_hit; - miss = VSL_stats->cache_miss; + hit = VSC_main->cache_hit; + miss = VSC_main->cache_miss; hr = (hit - lhit) / lt; mr = (miss - lmiss) / lt; lhit = hit; From phk at varnish-cache.org Fri Jun 18 09:12:52 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Fri, 18 Jun 2010 11:12:52 +0200 Subject: r4971 - trunk/varnish-cache/lib/libvcl Message-ID: Author: phk Date: 2010-06-18 11:12:52 +0200 (Fri, 18 Jun 2010) New Revision: 4971 Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_parse.c Log: Use ExpectErr() instead of Expect, so that we get compiler error messages rather than panics. Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2010-06-17 08:47:19 UTC (rev 4970) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2010-06-18 09:12:52 UTC (rev 4971) @@ -283,7 +283,7 @@ vcc_NextToken(tl); - Expect(tl, '('); + ExpectErr(tl, '('); vcc_NextToken(tl); if (tl->t->tok == VAR) { @@ -352,7 +352,7 @@ Fb(tl, 0, "vrt_magic_string_end);\n"); } - Expect(tl, ')'); + ExpectErr(tl, ')'); vcc_NextToken(tl); } @@ -363,7 +363,7 @@ { vcc_NextToken(tl); - Expect(tl, '('); + ExpectErr(tl, '('); vcc_NextToken(tl); Fb(tl, 1, "VRT_ban(sp, \"req.url\", \"~\", "); @@ -371,7 +371,7 @@ vcc_ExpectedStringval(tl); return; } - Expect(tl, ')'); + ExpectErr(tl, ')'); vcc_NextToken(tl); Fb(tl, 0, ", 0);\n"); } @@ -423,9 +423,9 @@ int retval = 0; vcc_NextToken(tl); - Expect(tl, '('); + ExpectErr(tl, '('); vcc_NextToken(tl); - Expect(tl, ID); + ExpectErr(tl, ID); #define VCL_RET_MAC(l, U) \ do { \ @@ -443,7 +443,7 @@ ERRCHK(tl); } vcc_NextToken(tl); - Expect(tl, ')'); + ExpectErr(tl, ')'); vcc_NextToken(tl); } Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2010-06-17 08:47:19 UTC (rev 4970) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2010-06-18 09:12:52 UTC (rev 4971) @@ -34,6 +34,7 @@ #include #include +#include #include "vsb.h" @@ -153,6 +154,8 @@ const char *p; Expect(tl, CNUM); + if (tl->err) + return (NAN); for (p = tl->t->b; p < tl->t->e; p++) { d *= 10; d += *p - '0'; From phk at varnish-cache.org Sat Jun 19 16:51:44 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Sat, 19 Jun 2010 18:51:44 +0200 Subject: r4972 - trunk/varnish-cache/bin/varnishtop Message-ID: Author: phk Date: 2010-06-19 18:51:43 +0200 (Sat, 19 Jun 2010) New Revision: 4972 Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c Log: Too many bogus SVID versions out there, don't assert set_curs() return. Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c =================================================================== --- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-18 09:12:52 UTC (rev 4971) +++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-19 16:51:43 UTC (rev 4972) @@ -229,7 +229,7 @@ AC(noecho()); AC(nonl()); AC(intrflush(stdscr, FALSE)); - AC(curs_set(0)); + (void)curs_set(0); AC(erase()); for (;;) { AZ(pthread_mutex_lock(&mtx)); From phk at varnish-cache.org Mon Jun 21 07:48:01 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 21 Jun 2010 09:48:01 +0200 Subject: r4973 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-21 09:48:01 +0200 (Mon, 21 Jun 2010) New Revision: 4973 Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c Log: Use WSP instead of VSL for ordering and performance Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-19 16:51:43 UTC (rev 4972) +++ trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-21 07:48:01 UTC (rev 4973) @@ -262,7 +262,7 @@ ew->eb->verbatim.e = TRUST_ME(verbatim + len); sprintf(ew->eb->chunk_length, "%x\r\n", Tlen(ew->eb->verbatim)); if (params->esi_syntax & 0x4) - VSL(SLT_Debug, ew->sp->fd, "AddBit: %d <%.*s>", + WSP(ew->sp, SLT_Debug, "AddBit: %d <%.*s>", Tlen(ew->eb->verbatim), Tlen(ew->eb->verbatim), ew->eb->verbatim.b); @@ -399,10 +399,10 @@ if (ew->eb == NULL || ew->eb->include.b != NULL) esi_addbit(ew, NULL, 0); eb = ew->eb; - VSL(SLT_Debug, ew->sp->fd, "Incl \"%.*s\"", t.e - t.b, t.b); + WSP(ew->sp, SLT_Debug, "Incl \"%.*s\"", t.e - t.b, t.b); while (esi_attrib(ew, &t, &tag, &val) == 1) { if (params->esi_syntax & 0x4) - VSL(SLT_Debug, ew->sp->fd, "<%.*s> -> <%.*s>", + WSP(ew->sp, SLT_Debug, "<%.*s> -> <%.*s>", tag.e - tag.b, tag.b, val.e - val.b, val.b); if (Tlen(tag) != 3 || memcmp(tag.b, "src", 3)) continue; @@ -650,7 +650,7 @@ ew->tag.b += 4 + (closing ? 1 : 0); l = Tlen(ew->tag); - VSL(SLT_Debug, ew->sp->fd, + WSP(ew->sp, SLT_Debug, "tag {%.*s} %d %d %d", l, ew->tag.b, ew->remflg, empty, closing); if (l >= 6 && !memcmp(ew->tag.b, "remove", 6)) { if (empty) { From phk at varnish-cache.org Mon Jun 21 08:01:16 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 21 Jun 2010 10:01:16 +0200 Subject: r4974 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-21 10:01:16 +0200 (Mon, 21 Jun 2010) New Revision: 4974 Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c Log: Minor nitpicking Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-21 07:48:01 UTC (rev 4973) +++ trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-21 08:01:16 UTC (rev 4974) @@ -394,7 +394,6 @@ txt tag; txt val; unsigned u, v, s; - struct ws *ws; if (ew->eb == NULL || ew->eb->include.b != NULL) esi_addbit(ew, NULL, 0); @@ -412,9 +411,7 @@ continue; } - /* Wee are saving the original string */ - ws = ew->sp->obj->ws_o; - WS_Assert(ws); + /* We are saving the original string */ s = 0; if (val.b != val.e) { From phk at varnish-cache.org Mon Jun 21 08:15:12 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 21 Jun 2010 10:15:12 +0200 Subject: r4975 - in trunk/varnish-cache/bin: varnishd varnishtest/tests Message-ID: Author: phk Date: 2010-06-21 10:15:11 +0200 (Mon, 21 Jun 2010) New Revision: 4975 Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc Log: Fix a bug when ESI elements span storage elements, which only the tightfisted -smalloc would trigger. Fixes: #719 Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-21 08:01:16 UTC (rev 4974) +++ trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-21 08:15:11 UTC (rev 4975) @@ -622,8 +622,8 @@ * XXX: Ideally, we should only pull together the bits * XXX: we need, like the filename. */ - ew->tag.b = ew->sp->obj->ws_o->f; - ew->tag.e = ew->tag.b + WS_Reserve(ew->sp->obj->ws_o, 0); + ew->tag.b = ew->sp->wrk->ws->f; + ew->tag.e = ew->tag.b + WS_Reserve(ew->sp->wrk->ws, 0); px = ew->s; q = ew->tag.b; while (px.p != ew->p.p) { @@ -632,7 +632,7 @@ Nep(&px); } ew->tag.e = q; - WS_Release(ew->sp->obj->ws_o, Tlen(ew->tag)); + WS_Release(ew->sp->wrk->ws, Tlen(ew->tag)); } ll = Tlen(ew->tag); ew->tag.b++; Modified: trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc 2010-06-21 08:01:16 UTC (rev 4974) +++ trunk/varnish-cache/bin/varnishtest/tests/e00007.vtc 2010-06-21 08:15:11 UTC (rev 4975) @@ -31,7 +31,7 @@ } } -start -varnish v1 -vcl+backend { +varnish v1 -storage "-smalloc,2m" -vcl+backend { sub vcl_fetch { esi; } From phk at varnish-cache.org Mon Jun 21 08:16:04 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 21 Jun 2010 10:16:04 +0200 Subject: r4976 - trunk/varnish-cache/bin Message-ID: Author: phk Date: 2010-06-21 10:16:03 +0200 (Mon, 21 Jun 2010) New Revision: 4976 Modified: trunk/varnish-cache/bin/flint.lnt Log: Silence a bogus pthread warning Modified: trunk/varnish-cache/bin/flint.lnt =================================================================== --- trunk/varnish-cache/bin/flint.lnt 2010-06-21 08:15:11 UTC (rev 4975) +++ trunk/varnish-cache/bin/flint.lnt 2010-06-21 08:16:03 UTC (rev 4976) @@ -92,6 +92,8 @@ -esym(534, strcpy) -esym(534, strlcpy) ++typename(844) +-etype(844, struct pthread *) -sem(pthread_create, custodial(4)) -emacro(413, offsetof) // likely null pointer -emacro(736, isnan) // loss of prec. From phk at varnish-cache.org Mon Jun 21 08:44:29 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 21 Jun 2010 10:44:29 +0200 Subject: r4977 - trunk/varnish-cache/include Message-ID: Author: phk Date: 2010-06-21 10:44:29 +0200 (Mon, 21 Jun 2010) New Revision: 4977 Modified: trunk/varnish-cache/include/vmb.h Log: Check __FreeBSD_version for memory barrier definition Modified: trunk/varnish-cache/include/vmb.h =================================================================== --- trunk/varnish-cache/include/vmb.h 2010-06-21 08:16:03 UTC (rev 4976) +++ trunk/varnish-cache/include/vmb.h 2010-06-21 08:44:29 UTC (rev 4977) @@ -40,7 +40,7 @@ void vmb_pthread(void); -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) && __FreeBSD_version >= 800058 #include #include From phk at varnish-cache.org Mon Jun 21 12:31:26 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 21 Jun 2010 14:31:26 +0200 Subject: r4978 - trunk/varnish-cache/lib/libvcl Message-ID: Author: phk Date: 2010-06-21 14:31:25 +0200 (Mon, 21 Jun 2010) New Revision: 4978 Modified: trunk/varnish-cache/lib/libvcl/generate.py trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: bereq.connect_timeout should be available in vcl_pipe Modified: trunk/varnish-cache/lib/libvcl/generate.py =================================================================== --- trunk/varnish-cache/lib/libvcl/generate.py 2010-06-21 08:44:29 UTC (rev 4977) +++ trunk/varnish-cache/lib/libvcl/generate.py 2010-06-21 12:31:25 UTC (rev 4978) @@ -216,8 +216,8 @@ ), ('bereq.connect_timeout', 'RTIME', - ( 'pass', 'miss',), - ( 'pass', 'miss',), + ( 'pipe', 'pass', 'miss',), + ( 'pipe', 'pass', 'miss',), 'struct sess *' ), ('bereq.first_byte_timeout', Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2010-06-21 08:44:29 UTC (rev 4977) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2010-06-21 12:31:25 UTC (rev 4978) @@ -194,9 +194,9 @@ }, { "bereq.connect_timeout", RTIME, 21, "VRT_r_bereq_connect_timeout(sp)", - VCL_MET_PASS | VCL_MET_MISS, + VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS, "VRT_l_bereq_connect_timeout(sp, ", - VCL_MET_PASS | VCL_MET_MISS, + VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS, 0, }, { "bereq.first_byte_timeout", RTIME, 24, From phk at varnish-cache.org Mon Jun 21 15:33:56 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 21 Jun 2010 17:33:56 +0200 Subject: r4979 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-21 17:33:56 +0200 (Mon, 21 Jun 2010) New Revision: 4979 Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c Log: Emit a Length record on fetches from the backend. Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2010-06-21 12:31:25 UTC (rev 4978) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2010-06-21 15:33:56 UTC (rev 4979) @@ -516,6 +516,8 @@ return (__LINE__); } + WSL(sp->wrk, SLT_Length, sp->vbe->fd, "%u", sp->obj->len); + { /* Sanity check fetch methods accounting */ unsigned uu; From phk at varnish-cache.org Tue Jun 22 07:15:18 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 22 Jun 2010 09:15:18 +0200 Subject: r4980 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-22 09:15:16 +0200 (Tue, 22 Jun 2010) New Revision: 4980 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_response.c Log: Emit Length for client side right before ReqEnd, to summarize ESI transactions correctly. Only Emmit Length and ReqEnd if we have an XID. Fixes: #709 Fixes: #720 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2010-06-21 15:33:56 UTC (rev 4979) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2010-06-22 07:15:16 UTC (rev 4980) @@ -245,12 +245,14 @@ if (sp->xid == 0) { sp->t_req = sp->t_end; sp->t_resp = sp->t_end; + } else { + dp = sp->t_resp - sp->t_req; + da = sp->t_end - sp->t_resp; + dh = sp->t_req - sp->t_open; + WSP(sp, SLT_Length, "%u", sp->acct_req.bodybytes); + WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %.9f %.9f %.9f %.9f %.9f", + sp->xid, sp->t_req, sp->t_end, dh, dp, da); } - dp = sp->t_resp - sp->t_req; - da = sp->t_end - sp->t_resp; - dh = sp->t_req - sp->t_open; - WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %.9f %.9f %.9f %.9f %.9f", - sp->xid, sp->t_req, sp->t_end, dh, dp, da); sp->xid = 0; sp->t_open = sp->t_end; Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2010-06-21 15:33:56 UTC (rev 4979) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2010-06-22 07:15:16 UTC (rev 4980) @@ -49,8 +49,6 @@ char lm[64]; char *p; - WSP(sp, SLT_Length, "%u", 0); - http_ClrHeader(sp->wrk->resp); sp->wrk->resp->logtag = HTTP_Tx; http_SetResp(sp->wrk->resp, "HTTP/1.1", "304", "Not Modified"); @@ -202,8 +200,6 @@ if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp)) return; - WSP(sp, SLT_Length, "%u", sp->obj->len); - http_ClrHeader(sp->wrk->resp); sp->wrk->resp->logtag = HTTP_Tx; http_CopyResp(sp->wrk->resp, sp->obj->http); From phk at varnish-cache.org Tue Jun 22 07:37:19 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 22 Jun 2010 09:37:19 +0200 Subject: r4981 - trunk/varnish-cache/lib/libvarnishapi Message-ID: Author: phk Date: 2010-06-22 09:37:19 +0200 (Tue, 22 Jun 2010) New Revision: 4981 Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c Log: Typo in -X matching in varnishapi Fixes: #681 Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c =================================================================== --- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-22 07:15:16 UTC (rev 4980) +++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-22 07:37:19 UTC (rev 4981) @@ -253,7 +253,7 @@ continue; } if (vsl->regexcl != NULL) { - i = VRE_exec(vsl->regincl, VSL_DATA(p), VSL_LEN(p), + i = VRE_exec(vsl->regexcl, VSL_DATA(p), VSL_LEN(p), 0, 0, NULL, 0); if (i != VRE_ERROR_NOMATCH) continue; From phk at varnish-cache.org Tue Jun 22 12:10:45 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 22 Jun 2010 14:10:45 +0200 Subject: r4982 - trunk/varnish-cache/lib/libvcl Message-ID: Author: phk Date: 2010-06-22 14:10:45 +0200 (Tue, 22 Jun 2010) New Revision: 4982 Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h Log: If there is a backend or director named "default", make that the default, otherwise use the first backend or director we find as default. Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-22 07:37:19 UTC (rev 4981) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-22 12:10:45 UTC (rev 4982) @@ -725,15 +725,9 @@ return; } - if (isfirst == 1) { - /* - * If this is the first backend|director explicitly - * defined, use it as default backend. - */ - Fi(tl, 0, - "\tVCL_conf.director[0] = VCL_conf.director[%d];\n", - tl->ndirector - 1); - vcc_AddRef(tl, tl->t_dir, R_BACKEND); + if (isfirst == 1 || vcc_IdIs(tl->t_dir, "default")) { + tl->defaultdir = tl->ndirector - 1; + tl->t_defaultdir = tl->t_dir; } tl->t_policy = NULL; Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-22 07:37:19 UTC (rev 4981) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-22 12:10:45 UTC (rev 4982) @@ -589,6 +589,11 @@ return (vcc_DestroyTokenList(tl, NULL)); } + /* Configure the default director */ + Fi(tl, 0, "\tVCL_conf.director[0] = VCL_conf.director[%d];\n", + tl->defaultdir); + vcc_AddRef(tl, tl->t_defaultdir, R_BACKEND); + /* Check for orphans */ if (vcc_CheckReferences(tl)) return (vcc_DestroyTokenList(tl, NULL)); Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-22 07:37:19 UTC (rev 4981) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-22 12:10:45 UTC (rev 4982) @@ -88,6 +88,8 @@ VTAILQ_HEAD(, acl_e) acl; + int defaultdir; + struct token *t_defaultdir; struct token *t_dir; struct token *t_policy; From phk at varnish-cache.org Tue Jun 22 12:22:03 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 22 Jun 2010 14:22:03 +0200 Subject: r4983 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: Author: phk Date: 2010-06-22 14:22:03 +0200 (Tue, 22 Jun 2010) New Revision: 4983 Added: trunk/varnish-cache/bin/varnishtest/tests/v00027.vtc Log: Add testcase to check that backends named "default" get used as such. Added: trunk/varnish-cache/bin/varnishtest/tests/v00027.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00027.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00027.vtc 2010-06-22 12:22:03 UTC (rev 4983) @@ -0,0 +1,36 @@ +# $Id$ + +test "Check that backend named 'default' is the default" + +server s1 { + rxreq + txresp -bodylen 25 +} -start + +server s2 { + rxreq + txresp -bodylen 52 +} -start + +varnish v1 -vcl { + backend s1 { + .host = "${s1_addr}"; + .port = "${s1_port}"; + } + backend default { + .host = "${s2_addr}"; + .port = "${s2_port}"; + } + + sub vcl_recv { + if (req.url != req.url) { + set req.backend = s1; + } + } +} -start + +client c1 { + txreq + rxresp + expect resp.bodylen == 52 +} -run From phk at varnish-cache.org Tue Jun 22 13:01:22 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 22 Jun 2010 15:01:22 +0200 Subject: r4984 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: Author: phk Date: 2010-06-22 15:01:22 +0200 (Tue, 22 Jun 2010) New Revision: 4984 Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c trunk/varnish-cache/bin/varnishd/cache_backend_poll.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Emit probe-specs as separate free-standing structs, and point to them from backend specs. Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2010-06-22 12:22:03 UTC (rev 4983) +++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c 2010-06-22 13:01:22 UTC (rev 4984) @@ -251,7 +251,7 @@ assert(b->ipv4 != NULL || b->ipv6 != NULL); - VBP_Start(b, &vb->probe); + VBP_Start(b, vb->probe); VTAILQ_INSERT_TAIL(&backends, b, list); VSC_main->n_backend++; return (b); Modified: trunk/varnish-cache/bin/varnishd/cache_backend_poll.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2010-06-22 12:22:03 UTC (rev 4983) +++ trunk/varnish-cache/bin/varnishd/cache_backend_poll.c 2010-06-22 13:01:22 UTC (rev 4984) @@ -424,14 +424,13 @@ ASSERT_CLI(); - ALLOC_OBJ(vt, VBP_TARGET_MAGIC); - AN(vt); - if (!memcmp(&vt->probe, p, sizeof *p)) { - FREE_OBJ(vt); - /* No probe defined for this backend, set it healthy */ + if (p == NULL) { b->healthy = 1; return; } + + ALLOC_OBJ(vt, VBP_TARGET_MAGIC); + AN(vt); vt->backend = b; vt->probe = *p; Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2010-06-22 12:22:03 UTC (rev 4983) +++ trunk/varnish-cache/include/vrt.h 2010-06-22 13:01:22 UTC (rev 4984) @@ -74,7 +74,7 @@ double between_bytes_timeout; unsigned max_connections; unsigned saintmode_threshold; - struct vrt_backend_probe probe; + const struct vrt_backend_probe *probe; }; /* Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-22 12:22:03 UTC (rev 4983) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-22 13:01:22 UTC (rev 4984) @@ -228,11 +228,9 @@ /* .url and .request are mutually exclusive */ if (*t_did != NULL) { - vsb_printf(tl->sb, - "Probe request redefinition at:\n"); + vsb_printf(tl->sb, "Probe request redefinition at:\n"); vcc_ErrWhere(tl, t_field); - vsb_printf(tl->sb, - "Previous definition:\n"); + vsb_printf(tl->sb, "Previous definition:\n"); vcc_ErrWhere(tl, *t_did); return; } @@ -240,7 +238,7 @@ } static void -vcc_ParseProbe(struct tokenlist *tl) +vcc_ParseProbeSpec(struct tokenlist *tl) { struct fld_spec *fs; struct token *t_field; @@ -266,7 +264,8 @@ threshold = 0; initial = 0; status = 0; - Fb(tl, 0, "\t.probe = {\n"); + Fh(tl, 0, "static const struct vrt_backend_probe vgc_probe_%d = {\n", + tl->nprobe++); while (tl->t->tok != '}') { vcc_IsField(tl, &t_field, fs); @@ -275,32 +274,32 @@ vcc_ProbeRedef(tl, &t_did, t_field); ERRCHK(tl); ExpectErr(tl, CSTR); - Fb(tl, 0, "\t\t.url = "); - EncToken(tl->fb, tl->t); - Fb(tl, 0, ",\n"); + Fh(tl, 0, "\t.url = "); + EncToken(tl->fh, tl->t); + Fh(tl, 0, ",\n"); vcc_NextToken(tl); } else if (vcc_IdIs(t_field, "request")) { vcc_ProbeRedef(tl, &t_did, t_field); ERRCHK(tl); ExpectErr(tl, CSTR); - Fb(tl, 0, "\t\t.request =\n"); + Fh(tl, 0, "\t.request =\n"); while (tl->t->tok == CSTR) { - Fb(tl, 0, "\t\t\t"); - EncToken(tl->fb, tl->t); - Fb(tl, 0, " \"\\r\\n\"\n"); + Fh(tl, 0, "\t\t"); + EncToken(tl->fh, tl->t); + Fh(tl, 0, " \"\\r\\n\"\n"); vcc_NextToken(tl); } - Fb(tl, 0, "\t\t\t\"\\r\\n\",\n"); + Fh(tl, 0, "\t\t\"\\r\\n\",\n"); } else if (vcc_IdIs(t_field, "timeout")) { - Fb(tl, 0, "\t\t.timeout = "); + Fh(tl, 0, "\t.timeout = "); vcc_TimeVal(tl, &t); ERRCHK(tl); - Fb(tl, 0, "%g,\n", t); + Fh(tl, 0, "%g,\n", t); } else if (vcc_IdIs(t_field, "interval")) { - Fb(tl, 0, "\t\t.interval = "); + Fh(tl, 0, "\t.interval = "); vcc_TimeVal(tl, &t); ERRCHK(tl); - Fb(tl, 0, "%g,\n", t); + Fh(tl, 0, "%g,\n", t); } else if (vcc_IdIs(t_field, "window")) { t_window = tl->t; window = vcc_UintVal(tl); @@ -361,16 +360,16 @@ AN(t_window); vcc_ErrWhere(tl, t_window); } - Fb(tl, 0, "\t\t.window = %u,\n", window); - Fb(tl, 0, "\t\t.threshold = %u,\n", threshold); + Fh(tl, 0, "\t.window = %u,\n", window); + Fh(tl, 0, "\t.threshold = %u,\n", threshold); } if (t_initial != NULL) - Fb(tl, 0, "\t\t.initial = %u,\n", initial); + Fh(tl, 0, "\t.initial = %u,\n", initial); else - Fb(tl, 0, "\t\t.initial = ~0U,\n", initial); + Fh(tl, 0, "\t.initial = ~0U,\n", initial); if (status > 0) - Fb(tl, 0, "\t\t.exp_status = %u,\n", status); - Fb(tl, 0, "\t},\n"); + Fh(tl, 0, "\t.exp_status = %u,\n", status); + Fh(tl, 0, "};\n"); SkipToken(tl, '}'); } @@ -496,8 +495,9 @@ ERRCHK(tl); saint = u; SkipToken(tl, ';'); - } else if (vcc_IdIs(t_field, "probe")) { - vcc_ParseProbe(tl); + } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == '{') { + Fb(tl, 0, "\t.probe = &vgc_probe_%d,\n", tl->nprobe); + vcc_ParseProbeSpec(tl); ERRCHK(tl); } else { ErrInternal(tl); Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-22 12:22:03 UTC (rev 4983) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-22 13:01:22 UTC (rev 4984) @@ -88,6 +88,8 @@ VTAILQ_HEAD(, acl_e) acl; + int nprobe; + int defaultdir; struct token *t_defaultdir; struct token *t_dir; Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2010-06-22 12:22:03 UTC (rev 4983) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2010-06-22 13:01:22 UTC (rev 4984) @@ -233,8 +233,8 @@ "char\t\t*ipv6_sockaddr;\n\n\tdouble\t\t\t\tconnect_timeout;\n" "\tdouble\t\t\t\tfirst_byte_timeout;\n\tdouble\t\t\t\tbetween_byt" "es_timeout;\n\tunsigned\t\t\tmax_connections;\n\tunsigned\t" - "\t\tsaintmode_threshold;\n\tstruct vrt_backend_probe\tprobe;\n" - "};\n\n/*\n * A director with an unpredictable reply\n" + "\t\tsaintmode_threshold;\n\tconst struct vrt_backend_probe\t" + "*probe;\n};\n\n/*\n * A director with an unpredictable reply\n" " */\n\nstruct vrt_dir_random_entry {\n\tint\t\t\t\t\thost;\n" "\tdouble\t\t\t\t\tweight;\n};\n\nstruct vrt_dir_random {\n" "\tconst char\t\t\t\t*name;\n\tunsigned\t\t\t\tretries;\n" From phk at varnish-cache.org Tue Jun 22 13:36:18 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 22 Jun 2010 15:36:18 +0200 Subject: r4985 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl Message-ID: Author: phk Date: 2010-06-22 15:36:18 +0200 (Tue, 22 Jun 2010) New Revision: 4985 Modified: trunk/varnish-cache/bin/varnishtest/tests/v00014.vtc trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_parse.c trunk/varnish-cache/lib/libvcl/vcc_xref.c Log: Make it possible to declare stand-alone backend probes and reference them by name: probe foo { .url = "/"; .timeout = 1s; } director default random { { .backend = {.host = "10.0.0.1"; .probe = foo; } .weight = 1; } { .backend = {.host = "10.0.0.2"; .probe = foo; } .weight = 1; } { .backend = {.host = "10.0.0.3"; .probe = foo; } .weight = 1; } { .backend = {.host = "10.0.0.4"; .probe = foo; } .weight = 1; } { .backend = {.host = "10.0.0.5"; .probe = foo; } .weight = 1; } { .backend = {.host = "10.0.0.6"; .probe = foo; } .weight = 1; } { .backend = {.host = "10.0.0.7"; .probe = foo; } .weight = 1; } } Modified: trunk/varnish-cache/bin/varnishtest/tests/v00014.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00014.vtc 2010-06-22 13:01:22 UTC (rev 4984) +++ trunk/varnish-cache/bin/varnishtest/tests/v00014.vtc 2010-06-22 13:36:18 UTC (rev 4985) @@ -10,18 +10,20 @@ varnish v1 -vcl { + probe foo { + .url = "/"; + .timeout = 1s; + .interval = 1s; + .window = 3; + .threshold = 2; + .initial = 0; + } + backend default { .host = "${s1_addr}"; .port = "${s1_port}"; .max_connections = 1; - .probe = { - .url = "/"; - .timeout = 1s; - .interval = 1s; - .window = 3; - .threshold = 2; - .initial = 0; - } + .probe = foo; } sub vcl_recv { Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-22 13:01:22 UTC (rev 4984) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-22 13:36:18 UTC (rev 4985) @@ -264,7 +264,7 @@ threshold = 0; initial = 0; status = 0; - Fh(tl, 0, "static const struct vrt_backend_probe vgc_probe_%d = {\n", + Fh(tl, 0, "static const struct vrt_backend_probe vgc_probe__%d = {\n", tl->nprobe++); while (tl->t->tok != '}') { @@ -374,6 +374,28 @@ } /*-------------------------------------------------------------------- + * Parse and emit a probe definition + */ + +void +vcc_ParseProbe(struct tokenlist *tl) +{ + struct token *t_probe; + + vcc_NextToken(tl); /* ID: probe */ + + vcc_ExpectCid(tl); /* ID: name */ + ERRCHK(tl); + t_probe = tl->t; + vcc_NextToken(tl); + vcc_AddDef(tl, t_probe, R_PROBE); + + Fh(tl, 0, "\n#define vgc_probe_%.*s\tvgc_probe__%d\n", + PF(t_probe), tl->nprobe); + vcc_ParseProbeSpec(tl); +} + +/*-------------------------------------------------------------------- * Parse and emit a backend host definition * * The struct vrt_backend is emitted to Fh(). @@ -496,9 +518,21 @@ saint = u; SkipToken(tl, ';'); } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == '{') { - Fb(tl, 0, "\t.probe = &vgc_probe_%d,\n", tl->nprobe); + Fb(tl, 0, "\t.probe = &vgc_probe__%d,\n", tl->nprobe); vcc_ParseProbeSpec(tl); ERRCHK(tl); + } else if (vcc_IdIs(t_field, "probe") && tl->t->tok == ID) { + Fb(tl, 0, "\t.probe = &vgc_probe_%.*s,\n", PF(tl->t)); + vcc_AddRef(tl, tl->t, R_PROBE); + vcc_NextToken(tl); + SkipToken(tl, ';'); + } else if (vcc_IdIs(t_field, "probe")) { + vsb_printf(tl->sb, + "Expected '{' or name of probe."); + vcc_ErrToken(tl, tl->t); + vsb_printf(tl->sb, " at\n"); + vcc_ErrWhere(tl, tl->t); + return; } else { ErrInternal(tl); return; Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-22 13:01:22 UTC (rev 4984) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-22 13:36:18 UTC (rev 4985) @@ -116,7 +116,8 @@ enum ref_type { R_FUNC, R_ACL, - R_BACKEND + R_BACKEND, + R_PROBE }; struct ref { @@ -158,6 +159,7 @@ struct fld_spec; typedef void parsedirector_f(struct tokenlist *tl); +void vcc_ParseProbe(struct tokenlist *tl); void vcc_ParseDirector(struct tokenlist *tl); void vcc_ParseBackendHost(struct tokenlist *tl, int serial, char **nm); struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...); Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2010-06-22 13:01:22 UTC (rev 4984) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2010-06-22 13:36:18 UTC (rev 4985) @@ -570,6 +570,7 @@ { "sub", vcc_Function }, { "backend", vcc_ParseDirector }, { "director", vcc_ParseDirector }, + { "probe", vcc_ParseProbe }, { NULL, NULL } }; Modified: trunk/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_xref.c 2010-06-22 13:01:22 UTC (rev 4984) +++ trunk/varnish-cache/lib/libvcl/vcc_xref.c 2010-06-22 13:36:18 UTC (rev 4985) @@ -86,6 +86,7 @@ case R_FUNC: return ("function"); case R_ACL: return ("acl"); case R_BACKEND: return ("backend"); + case R_PROBE: return ("probe"); default: ErrInternal(tl); vsb_printf(tl->sb, "Ref "); @@ -153,6 +154,7 @@ struct ref *r; const char *type; int nerr = 0; + const char *sep = ""; VTAILQ_FOREACH(r, &tl->refs, list) { if (r->defcnt != 0 && r->refcnt != 0) @@ -163,15 +165,16 @@ if (r->defcnt == 0) { vsb_printf(tl->sb, - "Undefined %s %.*s, first reference:\n", - type, PF(r->name)); + "%sUndefined %s %.*s, first reference:\n", + sep, type, PF(r->name)); vcc_ErrWhere(tl, r->name); continue; } - vsb_printf(tl->sb, "Unused %s %.*s, defined:\n", - type, PF(r->name)); + vsb_printf(tl->sb, "%sUnused %s %.*s, defined:\n", + sep, type, PF(r->name)); vcc_ErrWhere(tl, r->name); + sep = "\n"; } return (nerr); } From phk at varnish-cache.org Wed Jun 23 09:41:48 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 23 Jun 2010 11:41:48 +0200 Subject: r4986 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: Author: phk Date: 2010-06-23 11:41:48 +0200 (Wed, 23 Jun 2010) New Revision: 4986 Added: trunk/varnish-cache/bin/varnishtest/tests/b00033.vtc Log: Add a code coverage test for the classic hasher, now that critbit is the default Added: trunk/varnish-cache/bin/varnishtest/tests/b00033.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/b00033.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/b00033.vtc 2010-06-23 09:41:48 UTC (rev 4986) @@ -0,0 +1,44 @@ +# $Id$ + +test "classic hash code coverage" + +server s1 { + rxreq + expect req.url == /1 + txresp -bodylen 5 + + rxreq + expect req.url == /2 + txresp -bodylen 6 + + rxreq + expect req.url == /1 + txresp -bodylen 7 + + rxreq + expect req.url == /2 + txresp -bodylen 8 + +} -start + +varnish v1 -arg "-hclassic,11" -vcl+backend {} -start + +client c1 { + txreq -url /1 + rxresp + expect resp.bodylen == 5 + txreq -url /2 + rxresp + expect resp.bodylen == 6 +} -run + +varnish v1 -cliok "purge req.url ~ ." + +client c1 { + txreq -url /1 + rxresp + expect resp.bodylen == 7 + txreq -url /2 + rxresp + expect resp.bodylen == 8 +} -run From phk at varnish-cache.org Mon Jun 28 08:26:19 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 28 Jun 2010 10:26:19 +0200 Subject: r4987 - trunk/varnish-cache/doc/sphinx/phk Message-ID: Author: phk Date: 2010-06-28 10:26:19 +0200 (Mon, 28 Jun 2010) New Revision: 4987 Added: trunk/varnish-cache/doc/sphinx/phk/barriers.rst Modified: trunk/varnish-cache/doc/sphinx/phk/index.rst Log: Explain the security-barriers influence on Varnish' design. Added: trunk/varnish-cache/doc/sphinx/phk/barriers.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/phk/barriers.rst (rev 0) +++ trunk/varnish-cache/doc/sphinx/phk/barriers.rst 2010-06-28 08:26:19 UTC (rev 4987) @@ -0,0 +1,124 @@ +.. _phk_barriers: + +============================ +Security barriers in Varnish +============================ + +Security is a very important design driver in Varnish, more likely than not, +if you find yourself thinking "Why did he do _that_ ? the answer has to +do with security. + +The Varnish security model is based on some very crude but easy to understand +barriers between the various components:: + + .-->- provides ->---------------------------------------. + | | | + (ADMIN)--+-->- runs ----->---. | | + | | | | + |-->- cli_req -->---| v v + '--<- cli_resp -<---| VCL MODULE + | | | + (OPER) | |reads | + | | | | + |runs | | | + | .-<- create -<-. | .->- fork ->-. v | + v |->- check -->-|-- MGR --| |-- VCC <- loads -| + VSM |-<- write --<-' | '-<- wait -<-' | | + TOOLS | | | | + ^ | .-------------' | | + | | | |writes | + |reads | |->- fork ----->-. | | + | | |->- cli_req -->-| | | + VSM ----' |-<- cli_resp -<-| v | + | '-<- wait -----<-| VCL.SO | + | | | | + | | | | + |---->----- inherit --->------|--<-- loads -------' | + |---->----- reads ---->------| | + '----<----- writes ----<------|--<-- loads --------------------' + | + | + | + .--->-- http_req --->--. | .-->-- http_req --->--. + (ANON) --| |-- CLD --| |-- (BACKEND) + '---<-- http_resp --<--' '--<-- http_resp --<--' + +(ASCII-ART rules!) + +The really Important Barrier +============================ + +The central actor in Varnish is the Manager process, "MGR", which is the +proces the administrator "(ADMIN)" starts to get web-cache service. + +Having been there myself, I do not subscribe to the "I feel cool and important +when I get woken up at 3AM to restart a dead process" school of thought, in +fact, I think that is a clear sign of mindless stupidity: If we cannot +get a computer to restart a dead process, why do we even have them ? + +The task of the Manager process is therefore not cache web content, +but to make sure there always is a process which does that, the +Child "CLD" process. + +That is the major barrier in Varnish: All management happens in +one process all actual movement of traffic happens in another, and +the Manager process does not trust the Child process at all. + +The Child process is in a the totally unprotected domain: Any +computer on the InterNet "(ANON)" can connect to the Child process +and ask for some web-object. + +If John D. Criminal manages to exploit a security hole in Varnish, it is +the Child process he subverts. If he carries out a DoS attack, it is +the Child process he tries to fell. + +Therefore the Manager starts the Child with as low priviledge as practically +possible, and we close all filedescriptors it should not have access to and +so on. + +There are only three channels of communication back to the Manager +process: An exit code, a CLI response or writing stuff into the +shared memory file "VSM" used for statistics and logging, all of +these are well defended by the Manager process. + +The Admin/Oper Barrier +====================== + +If you look at the top left corner of the diagram, you will see that Varnish +operates with separate Administrator "(ADMIN)" and Operator "(OPER)" roles. + +The Administrator does things, changes stuff etc. The Operator keeps an +eye on things to make sure they are as they should be. + +These days Operators are often scripts and data collection tools, and +there is no reason to assume they are bugfree, so Varnish does not +trust the Operator role, that is a pure one-way relationship. + +(Trick: If the Child process us run under user "nobody", you can +allow marginally trusted operations personel access to the "nobody" +account (for instance using .ssh/authorized_keys2), and they will +be able to kill the Child process, prompting the Manager process to +restart it again with the same parameters and settings.) + +The Administrator has the final say, and of course, the administrator +can decide under which circumstances that authority will be shared. + +Needless to say, if the system on which Varnish runs is not properly +secured, the Administators monopoly of control will be compromised. + +All the other barriers +====================== + +There are more barriers, you can spot them by following the arrows in +the diagram, but they are more sort of "technical" than "political" and +generally try to guard against programming flaws as much as security +compromise. + +For instance the VCC compiler runs in a separate child process, to make +sure that a memory leak or other flaw in the compiler does not accumulate +trouble for the Manager process. + +Hope this explanation helps understand why Varnish is not just a single +process like all other server programs. + +Poul-Henning, 2010-06-28 Modified: trunk/varnish-cache/doc/sphinx/phk/index.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/phk/index.rst 2010-06-23 09:41:48 UTC (rev 4986) +++ trunk/varnish-cache/doc/sphinx/phk/index.rst 2010-06-28 08:26:19 UTC (rev 4987) @@ -8,6 +8,7 @@ .. toctree:: + barriers.rst thoughts.rst autocrap.rst sphinx.rst From phk at varnish-cache.org Mon Jun 28 11:53:34 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 28 Jun 2010 13:53:34 +0200 Subject: r4988 - trunk/varnish-cache/doc/sphinx/installation Message-ID: Author: phk Date: 2010-06-28 13:53:33 +0200 (Mon, 28 Jun 2010) New Revision: 4988 Modified: trunk/varnish-cache/doc/sphinx/installation/install.rst Log: Fix SVN urls. Fixes: #723 Modified: trunk/varnish-cache/doc/sphinx/installation/install.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/installation/install.rst 2010-06-28 08:26:19 UTC (rev 4987) +++ trunk/varnish-cache/doc/sphinx/installation/install.rst 2010-06-28 11:53:33 UTC (rev 4988) @@ -71,11 +71,11 @@ To fetch the current (2.1) production branch::: - svn co http://varnish-cache.org/svn/varnish/branches/2.1 + svn co http://varnish-cache.org/svn/branches/2.1 To get the development source code::: - svn co http://varnish-cache.org/svn/varnish/trunk + svn co http://varnish-cache.org/svn/trunk Build dependencies on Debian / Ubuntu ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From phk at varnish-cache.org Mon Jun 28 14:28:37 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Mon, 28 Jun 2010 16:28:37 +0200 Subject: r4989 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-28 16:28:36 +0200 (Mon, 28 Jun 2010) New Revision: 4989 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_acceptor.c trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_esi.c trunk/varnish-cache/bin/varnishd/cache_response.c trunk/varnish-cache/bin/varnishd/cache_session.c Log: Fix a problem with accounting of ESI transactions, in particular make the Length header match the actual composite object sent to the client. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2010-06-28 11:53:33 UTC (rev 4988) +++ trunk/varnish-cache/bin/varnishd/cache.h 2010-06-28 14:28:36 UTC (rev 4989) @@ -434,8 +434,9 @@ struct sessmem *mem; struct workreq workreq; - struct acct acct; + struct acct acct_tmp; struct acct acct_req; + struct acct acct_ses; #if defined(HAVE_EPOLL_CTL) struct epoll_event ev; Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2010-06-28 11:53:33 UTC (rev 4988) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2010-06-28 14:28:36 UTC (rev 4989) @@ -176,7 +176,7 @@ VSL(SLT_SessionOpen, sp->fd, "%s %s %s", sp->addr, sp->port, sp->mylsock->name); } - sp->acct.first = sp->t_open; + sp->acct_ses.first = sp->t_open; if (need_test) sock_test(sp->fd); if (need_linger) Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2010-06-28 11:53:33 UTC (rev 4988) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2010-06-28 14:28:36 UTC (rev 4989) @@ -240,31 +240,33 @@ sp->vcl = NULL; } + SES_Charge(sp); + sp->t_end = TIM_real(); sp->wrk->lastused = sp->t_end; if (sp->xid == 0) { sp->t_req = sp->t_end; sp->t_resp = sp->t_end; - } else { + } else if (sp->esis == 0) { dp = sp->t_resp - sp->t_req; da = sp->t_end - sp->t_resp; dh = sp->t_req - sp->t_open; + /* XXX: Add StatReq == StatSess */ WSP(sp, SLT_Length, "%u", sp->acct_req.bodybytes); WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %.9f %.9f %.9f %.9f %.9f", sp->xid, sp->t_req, sp->t_end, dh, dp, da); } - sp->xid = 0; sp->t_open = sp->t_end; sp->t_resp = NAN; WSL_Flush(sp->wrk, 0); /* If we did an ESI include, don't mess up our state */ - if (sp->esis > 0) { - SES_Charge(sp); + if (sp->esis > 0) return (1); - } + memset(&sp->acct_req, 0, sizeof sp->acct_req); + sp->t_req = NAN; if (sp->fd >= 0 && sp->doclose != NULL) { @@ -276,8 +278,6 @@ vca_close_session(sp, sp->doclose); } - SES_Charge(sp); - if (sp->fd < 0) { sp->wrk->stats.sess_closed++; sp->wrk = NULL; @@ -647,7 +647,7 @@ AN(sp->obj->ban); HSH_Unbusy(sp); } - sp->acct_req.fetch++; + sp->acct_tmp.fetch++; sp->wrk->bereq = NULL; sp->wrk->beresp = NULL; sp->wrk->beresp1 = NULL; @@ -679,7 +679,7 @@ /* Receive a HTTP protocol request */ HTC_Init(sp->htc, sp->ws, sp->fd); sp->wrk->lastused = sp->t_open; - sp->acct_req.sess++; + sp->acct_tmp.sess++; sp->step = STP_WAIT; return (0); @@ -946,7 +946,7 @@ return (0); } assert(sp->handling == VCL_RET_PASS); - sp->acct_req.pass++; + sp->acct_tmp.pass++; sp->sendbody = 1; sp->step = STP_FETCH; return (0); @@ -984,7 +984,7 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); - sp->acct_req.pipe++; + sp->acct_tmp.pipe++; WS_Reset(sp->wrk->ws, NULL); sp->wrk->bereq = sp->wrk->http[0]; http_Setup(sp->wrk->bereq, sp->wrk->ws); @@ -1108,7 +1108,7 @@ sp->wrk->stats.client_req++; sp->t_req = TIM_real(); sp->wrk->lastused = sp->t_req; - sp->acct_req.req++; + sp->acct_tmp.req++; /* Assign XID and log */ sp->xid = ++xids; /* XXX not locked */ Modified: trunk/varnish-cache/bin/varnishd/cache_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-28 11:53:33 UTC (rev 4988) +++ trunk/varnish-cache/bin/varnishd/cache_esi.c 2010-06-28 14:28:36 UTC (rev 4989) @@ -859,6 +859,7 @@ char *ws_wm; struct http http_save; struct esidata *ed; + unsigned sxid; w = sp->wrk; WRW_Reserve(w, &sp->fd); @@ -869,7 +870,7 @@ if (Tlen(eb->verbatim)) { if (sp->http->protover >= 1.1) (void)WRW_Write(w, eb->chunk_length, -1); - sp->acct_req.bodybytes += WRW_Write(w, + sp->acct_tmp.bodybytes += WRW_Write(w, eb->verbatim.b, Tlen(eb->verbatim)); if (sp->http->protover >= 1.1) (void)WRW_Write(w, "\r\n", -1); @@ -919,6 +920,7 @@ /* Client content already taken care of */ http_Unset(sp->http, H_Content_Length); + sxid = sp->xid; while (1) { sp->wrk = w; CNT_Session(sp); @@ -929,6 +931,7 @@ DSL(0x20, SLT_Debug, sp->id, "loop waiting for ESI"); (void)usleep(10000); } + sp->xid = sxid; AN(sp->wrk); assert(sp->step == STP_DONE); sp->esis--; Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2010-06-28 11:53:33 UTC (rev 4988) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2010-06-28 14:28:36 UTC (rev 4989) @@ -258,7 +258,7 @@ if (sp->esis == 0) /* no headers for interior ESI includes */ - sp->acct_req.hdrbytes += + sp->acct_tmp.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1); if (WRW_FlushRelease(sp->wrk)) { @@ -283,7 +283,7 @@ http_GetHdr(sp->http, H_Range, &r)) res_dorange(sp, r, &low, &high); - sp->acct_req.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1); + sp->acct_tmp.hdrbytes += http_Write(sp->wrk, sp->wrk->resp, 1); } else if (!sp->disable_esi && sp->esis > 0 && sp->http->protover >= 1.1 && @@ -329,7 +329,7 @@ ptr += len; - sp->acct_req.bodybytes += len; + sp->acct_tmp.bodybytes += len; #ifdef SENDFILE_WORKS /* * XXX: the overhead of setting up sendfile is not Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2010-06-28 11:53:33 UTC (rev 4988) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2010-06-28 14:28:36 UTC (rev 4989) @@ -83,11 +83,12 @@ void SES_Charge(struct sess *sp) { - struct acct *a = &sp->acct_req; + struct acct *a = &sp->acct_tmp; -#define ACCT(foo) \ +#define ACCT(foo) \ sp->wrk->stats.s_##foo += a->foo; \ - sp->acct.foo += a->foo; \ + sp->acct_req.foo += a->foo; \ + sp->acct_ses.foo += a->foo; \ a->foo = 0; #include "acct_fields.h" #undef ACCT @@ -247,7 +248,7 @@ void SES_Delete(struct sess *sp) { - struct acct *b = &sp->acct; + struct acct *b = &sp->acct_ses; struct sessmem *sm; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); From phk at varnish-cache.org Tue Jun 29 10:01:59 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 29 Jun 2010 12:01:59 +0200 Subject: r4990 - trunk/varnish-cache/bin/varnishd Message-ID: Author: phk Date: 2010-06-29 12:01:59 +0200 (Tue, 29 Jun 2010) New Revision: 4990 Modified: trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Add a vcl_dir parameter to resolve relative VCL pathnames from (vcl.load/include) Does not do anything yet. Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2010-06-28 14:28:36 UTC (rev 4989) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2010-06-29 10:01:59 UTC (rev 4990) @@ -80,6 +80,7 @@ int mgt_push_vcls_and_start(unsigned *status, char **p); int mgt_has_vcl(void); extern char *mgt_cc_cmd; +extern char *mgt_vcl_dir; #define REPORT0(pri, fmt) \ Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2010-06-28 14:28:36 UTC (rev 4989) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2010-06-29 10:01:59 UTC (rev 4990) @@ -429,17 +429,16 @@ /*--------------------------------------------------------------------*/ static void -tweak_cc_command(struct cli *cli, const struct parspec *par, const char *arg) +tweak_string(struct cli *cli, const struct parspec *par, const char *arg) { + char **p = TRUST_ME(par->priv); + AN(p); /* XXX should have tweak_generic_string */ - (void)par; if (arg == NULL) { - cli_quote(cli, mgt_cc_cmd); + cli_quote(cli, *p); } else { - free(mgt_cc_cmd); - mgt_cc_cmd = strdup(arg); - XXXAN(mgt_cc_cmd); + REPLACE(*p, arg); } } @@ -629,14 +628,13 @@ "operations necessary for LRU list access.", EXPERIMENTAL, "2", "seconds" }, - { "cc_command", tweak_cc_command, NULL, 0, 0, + { "cc_command", tweak_string, &mgt_cc_cmd, 0, 0, "Command used for compiling the C source code to a " "dlopen(3) loadable object. Any occurrence of %s in " "the string will be replaced with the source file name, " "and %o will be replaced with the output file name.", MUST_RELOAD, - VCC_CC - , NULL }, + VCC_CC , NULL }, { "max_restarts", tweak_uint, &master.max_restarts, 0, UINT_MAX, "Upper limit on how many times a request can restart." "\nBe aware that restarts are likely to cause a hit against " @@ -824,6 +822,11 @@ "A value of zero disables the ban lurker.", EXPERIMENTAL, "180.0", "s" }, + { "vcl_dir", tweak_string, &mgt_vcl_dir, 0, 0, + "Directory from which relative VCL filenames (vcl.load and " + "include) are opened.", + 0, + ".", NULL }, { NULL, NULL, NULL } }; Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2010-06-28 14:28:36 UTC (rev 4989) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2010-06-29 10:01:59 UTC (rev 4990) @@ -67,6 +67,7 @@ static VTAILQ_HEAD(, vclprog) vclhead = VTAILQ_HEAD_INITIALIZER(vclhead); char *mgt_cc_cmd; +char *mgt_vcl_dir; /*--------------------------------------------------------------------*/ From phk at varnish-cache.org Tue Jun 29 11:15:21 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 29 Jun 2010 13:15:21 +0200 Subject: r4991 - trunk/varnish-cache/lib/libvcl Message-ID: Author: phk Date: 2010-06-29 13:15:20 +0200 (Tue, 29 Jun 2010) New Revision: 4991 Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_backend.c trunk/varnish-cache/lib/libvcl/vcc_backend_util.c trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h trunk/varnish-cache/lib/libvcl/vcc_dir_random.c trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c trunk/varnish-cache/lib/libvcl/vcc_parse.c trunk/varnish-cache/lib/libvcl/vcc_string.c trunk/varnish-cache/lib/libvcl/vcc_token.c trunk/varnish-cache/lib/libvcl/vcc_var.c trunk/varnish-cache/lib/libvcl/vcc_xref.c Log: Rename "struct tokenlist" to "struct vcc", it is much more than a simple list of tokens and we need it to learn even more tricks now, which will expose the type name outside this source directory. Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_acl.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_acl.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -97,7 +97,7 @@ static void -vcc_acl_add_entry(struct tokenlist *tl, const struct acl_e *ae, int l, +vcc_acl_add_entry(struct vcc *tl, const struct acl_e *ae, int l, const unsigned char *u, int fam) { struct acl_e *ae2, *aen; @@ -162,7 +162,7 @@ } static void -vcc_acl_try_getaddrinfo(struct tokenlist *tl, struct acl_e *ae) +vcc_acl_try_getaddrinfo(struct vcc *tl, struct acl_e *ae) { struct addrinfo *res0, *res, hint; struct sockaddr_in *sin4; @@ -246,7 +246,7 @@ */ static int -vcc_acl_try_netnotation(struct tokenlist *tl, struct acl_e *ae) +vcc_acl_try_netnotation(struct vcc *tl, struct acl_e *ae) { unsigned char b[4]; int i, j, k; @@ -275,7 +275,7 @@ } static void -vcc_acl_entry(struct tokenlist *tl) +vcc_acl_entry(struct vcc *tl) { struct acl_e *ae; @@ -332,7 +332,7 @@ /*lint -save -e506 -e774 -e550 */ static void -c_is_a_silly_language(const struct tokenlist *tl) +c_is_a_silly_language(const struct vcc *tl) { struct sockaddr sa; @@ -351,7 +351,7 @@ /*lint -restore */ static void -vcc_acl_emit(const struct tokenlist *tl, const char *acln, int anon) +vcc_acl_emit(const struct vcc *tl, const char *acln, int anon) { struct acl_e *ae; int depth, l, m, i; @@ -449,7 +449,7 @@ } void -vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl) +vcc_Cond_Ip(const struct var *vp, struct vcc *tl) { unsigned tcond; char acln[32]; @@ -486,7 +486,7 @@ } void -vcc_Acl(struct tokenlist *tl) +vcc_Acl(struct vcc *tl) { struct token *an; char acln[1024]; Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -47,7 +47,7 @@ /*--------------------------------------------------------------------*/ static void -parse_call(struct tokenlist *tl) +parse_call(struct vcc *tl) { vcc_NextToken(tl); @@ -63,7 +63,7 @@ /*--------------------------------------------------------------------*/ static void -parse_error(struct tokenlist *tl) +parse_error(struct vcc *tl) { struct var *vp; @@ -102,7 +102,7 @@ /*--------------------------------------------------------------------*/ static void -illegal_assignment(const struct tokenlist *tl, const char *type) +illegal_assignment(const struct vcc *tl, const char *type) { vsb_printf(tl->sb, "Invalid assignment operator "); @@ -112,7 +112,7 @@ } static void -parse_set(struct tokenlist *tl) +parse_set(struct vcc *tl) { struct var *vp; struct token *at, *vt; @@ -244,7 +244,7 @@ /*--------------------------------------------------------------------*/ static void -parse_unset(struct tokenlist *tl) +parse_unset(struct vcc *tl) { struct var *vp; @@ -277,7 +277,7 @@ }; static void -parse_purge(struct tokenlist *tl) +parse_purge(struct vcc *tl) { const struct purge_var *pv; @@ -359,7 +359,7 @@ /*--------------------------------------------------------------------*/ static void -parse_purge_url(struct tokenlist *tl) +parse_purge_url(struct vcc *tl) { vcc_NextToken(tl); @@ -379,7 +379,7 @@ /*--------------------------------------------------------------------*/ static void -parse_esi(struct tokenlist *tl) +parse_esi(struct vcc *tl) { vcc_NextToken(tl); @@ -389,7 +389,7 @@ /*--------------------------------------------------------------------*/ static void -parse_new_syntax(struct tokenlist *tl) +parse_new_syntax(struct vcc *tl) { vsb_printf(tl->sb, "Please change \"%.*s\" to \"return(%.*s)\".\n", @@ -400,7 +400,7 @@ /*--------------------------------------------------------------------*/ static void -parse_panic(struct tokenlist *tl) +parse_panic(struct vcc *tl) { vcc_NextToken(tl); @@ -418,7 +418,7 @@ /*--------------------------------------------------------------------*/ static void -parse_return(struct tokenlist *tl) +parse_return(struct vcc *tl) { int retval = 0; @@ -450,7 +450,7 @@ /*--------------------------------------------------------------------*/ static void -parse_rollback(struct tokenlist *tl) +parse_rollback(struct vcc *tl) { vcc_NextToken(tl); @@ -460,7 +460,7 @@ /*--------------------------------------------------------------------*/ static void -parse_synthetic(struct tokenlist *tl) +parse_synthetic(struct vcc *tl) { vcc_NextToken(tl); @@ -477,7 +477,7 @@ /*--------------------------------------------------------------------*/ -typedef void action_f(struct tokenlist *tl); +typedef void action_f(struct vcc *tl); static struct action_table { const char *name; @@ -507,7 +507,7 @@ }; int -vcc_ParseAction(struct tokenlist *tl) +vcc_ParseAction(struct vcc *tl) { struct token *at; struct action_table *atp; Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -97,7 +97,7 @@ */ static void -Emit_Sockaddr(struct tokenlist *tl, const struct token *t_host, +Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const char *port) { struct addrinfo *res, *res0, *res1, hint; @@ -190,7 +190,7 @@ */ static void -vcc_EmitBeIdent(const struct tokenlist *tl, struct vsb *v, +vcc_EmitBeIdent(const struct vcc *tl, struct vsb *v, int serial, const struct token *first, const struct token *last) { @@ -222,7 +222,7 @@ */ static void -vcc_ProbeRedef(struct tokenlist *tl, struct token **t_did, +vcc_ProbeRedef(struct vcc *tl, struct token **t_did, struct token *t_field) { /* .url and .request are mutually exclusive */ @@ -238,7 +238,7 @@ } static void -vcc_ParseProbeSpec(struct tokenlist *tl) +vcc_ParseProbeSpec(struct vcc *tl) { struct fld_spec *fs; struct token *t_field; @@ -378,7 +378,7 @@ */ void -vcc_ParseProbe(struct tokenlist *tl) +vcc_ParseProbe(struct vcc *tl) { struct token *t_probe; @@ -402,7 +402,7 @@ */ static void -vcc_ParseHostDef(struct tokenlist *tl, int serial, const char *vgcname) +vcc_ParseHostDef(struct vcc *tl, int serial, const char *vgcname) { struct token *t_field; struct token *t_first; @@ -612,7 +612,7 @@ */ void -vcc_ParseBackendHost(struct tokenlist *tl, int serial, char **nm) +vcc_ParseBackendHost(struct vcc *tl, int serial, char **nm) { struct host *h; struct token *t; @@ -666,7 +666,7 @@ */ static void -vcc_ParseSimpleDirector(struct tokenlist *tl) +vcc_ParseSimpleDirector(struct vcc *tl) { struct host *h; char vgcname[BUFSIZ]; @@ -700,7 +700,7 @@ }; void -vcc_ParseDirector(struct tokenlist *tl) +vcc_ParseDirector(struct vcc *tl) { struct token *t_first; struct dirlist const *dl; Modified: trunk/varnish-cache/lib/libvcl/vcc_backend_util.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_backend_util.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_backend_util.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -67,7 +67,7 @@ } struct fld_spec * -vcc_FldSpec(struct tokenlist *tl, const char *first, ...) +vcc_FldSpec(struct vcc *tl, const char *first, ...) { struct fld_spec f[100], *r; int n = 0; @@ -94,7 +94,7 @@ } void -vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs) +vcc_IsField(struct vcc *tl, struct token **t, struct fld_spec *fs) { struct token *t_field; @@ -128,7 +128,7 @@ } void -vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs) +vcc_FieldsOk(struct vcc *tl, const struct fld_spec *fs) { for (; fs->name != NULL; fs++) { Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -89,7 +89,7 @@ /*--------------------------------------------------------------------*/ static void -TlDoFree(struct tokenlist *tl, void *p) +TlDoFree(struct vcc *tl, void *p) { struct membit *mb; @@ -101,7 +101,7 @@ void * -TlAlloc(struct tokenlist *tl, unsigned len) +TlAlloc(struct vcc *tl, unsigned len) { void *p; @@ -130,7 +130,7 @@ */ void -Fh(const struct tokenlist *tl, int indent, const char *fmt, ...) +Fh(const struct vcc *tl, int indent, const char *fmt, ...) { va_list ap; @@ -142,7 +142,7 @@ } void -Fb(const struct tokenlist *tl, int indent, const char *fmt, ...) +Fb(const struct vcc *tl, int indent, const char *fmt, ...) { va_list ap; @@ -155,7 +155,7 @@ } void -Fc(const struct tokenlist *tl, int indent, const char *fmt, ...) +Fc(const struct vcc *tl, int indent, const char *fmt, ...) { va_list ap; @@ -167,7 +167,7 @@ } void -Fi(const struct tokenlist *tl, int indent, const char *fmt, ...) +Fi(const struct vcc *tl, int indent, const char *fmt, ...) { va_list ap; @@ -179,7 +179,7 @@ } void -Ff(const struct tokenlist *tl, int indent, const char *fmt, ...) +Ff(const struct vcc *tl, int indent, const char *fmt, ...) { va_list ap; @@ -239,7 +239,7 @@ */ static void -LocTable(const struct tokenlist *tl) +LocTable(const struct vcc *tl) { struct token *t; unsigned lin, pos; @@ -288,7 +288,7 @@ /*--------------------------------------------------------------------*/ static void -EmitInitFunc(const struct tokenlist *tl) +EmitInitFunc(const struct vcc *tl) { Fc(tl, 0, "\nstatic void\nVGC_Init(struct cli *cli)\n{\n\n"); @@ -299,7 +299,7 @@ } static void -EmitFiniFunc(const struct tokenlist *tl) +EmitFiniFunc(const struct vcc *tl) { Fc(tl, 0, "\nstatic void\nVGC_Fini(struct cli *cli)\n{\n\n"); @@ -312,7 +312,7 @@ /*--------------------------------------------------------------------*/ static void -EmitStruct(const struct tokenlist *tl) +EmitStruct(const struct vcc *tl) { struct source *sp; @@ -405,7 +405,7 @@ /*--------------------------------------------------------------------*/ static void -vcc_resolve_includes(struct tokenlist *tl) +vcc_resolve_includes(struct vcc *tl) { struct token *t, *t1, *t2; struct source *sp; @@ -453,10 +453,10 @@ /*--------------------------------------------------------------------*/ -static struct tokenlist * +static struct vcc * vcc_NewTokenList(void) { - struct tokenlist *tl; + struct vcc *tl; int i; tl = calloc(sizeof *tl, 1); @@ -498,7 +498,7 @@ /*--------------------------------------------------------------------*/ static char * -vcc_DestroyTokenList(struct tokenlist *tl, char *ret) +vcc_DestroyTokenList(struct vcc *tl, char *ret) { struct membit *mb; struct source *sp; @@ -534,7 +534,7 @@ static char * vcc_CompileSource(struct vsb *sb, struct source *sp) { - struct tokenlist *tl; + struct vcc *tl; char *of; int i; Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-29 11:15:20 UTC (rev 4991) @@ -63,7 +63,7 @@ VTAILQ_HEAD(tokenhead, token); -struct tokenlist { +struct vcc { struct tokenhead tokens; VTAILQ_HEAD(, source) sources; VTAILQ_HEAD(, membit) membits; @@ -149,23 +149,23 @@ /* vcc_acl.c */ -void vcc_Acl(struct tokenlist *tl); -void vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl); +void vcc_Acl(struct vcc *tl); +void vcc_Cond_Ip(const struct var *vp, struct vcc *tl); /* vcc_action.c */ -int vcc_ParseAction(struct tokenlist *tl); +int vcc_ParseAction(struct vcc *tl); /* vcc_backend.c */ struct fld_spec; -typedef void parsedirector_f(struct tokenlist *tl); +typedef void parsedirector_f(struct vcc *tl); -void vcc_ParseProbe(struct tokenlist *tl); -void vcc_ParseDirector(struct tokenlist *tl); -void vcc_ParseBackendHost(struct tokenlist *tl, int serial, char **nm); -struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...); +void vcc_ParseProbe(struct vcc *tl); +void vcc_ParseDirector(struct vcc *tl); +void vcc_ParseBackendHost(struct vcc *tl, int serial, char **nm); +struct fld_spec * vcc_FldSpec(struct vcc *tl, const char *first, ...); void vcc_ResetFldSpec(struct fld_spec *f); -void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs); -void vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs); +void vcc_IsField(struct vcc *tl, struct token **t, struct fld_spec *fs); +void vcc_FieldsOk(struct vcc *tl, const struct fld_spec *fs); /* vcc_compile.c */ extern struct method method_tab[]; @@ -176,14 +176,14 @@ * I -> Initializer function * F -> Finish function */ -void Fh(const struct tokenlist *tl, int indent, const char *fmt, ...); -void Fc(const struct tokenlist *tl, int indent, const char *fmt, ...); -void Fb(const struct tokenlist *tl, int indent, const char *fmt, ...); -void Fi(const struct tokenlist *tl, int indent, const char *fmt, ...); -void Ff(const struct tokenlist *tl, int indent, const char *fmt, ...); +void Fh(const struct vcc *tl, int indent, const char *fmt, ...); +void Fc(const struct vcc *tl, int indent, const char *fmt, ...); +void Fb(const struct vcc *tl, int indent, const char *fmt, ...); +void Fi(const struct vcc *tl, int indent, const char *fmt, ...); +void Ff(const struct vcc *tl, int indent, const char *fmt, ...); void EncToken(struct vsb *sb, const struct token *t); int IsMethod(const struct token *t); -void *TlAlloc(struct tokenlist *tl, unsigned len); +void *TlAlloc(struct vcc *tl, unsigned len); /* vcc_dir_random.c */ parsedirector_f vcc_ParseRandomDirector; @@ -195,52 +195,52 @@ extern struct var vcc_vars[]; /* vcc_parse.c */ -void vcc_Parse(struct tokenlist *tl); -void vcc_RTimeVal(struct tokenlist *tl, double *); -void vcc_TimeVal(struct tokenlist *tl, double *); -void vcc_SizeVal(struct tokenlist *tl, double *); -unsigned vcc_UintVal(struct tokenlist *tl); -double vcc_DoubleVal(struct tokenlist *tl); +void vcc_Parse(struct vcc *tl); +void vcc_RTimeVal(struct vcc *tl, double *); +void vcc_TimeVal(struct vcc *tl, double *); +void vcc_SizeVal(struct vcc *tl, double *); +unsigned vcc_UintVal(struct vcc *tl); +double vcc_DoubleVal(struct vcc *tl); /* vcc_string.c */ -char *vcc_regexp(struct tokenlist *tl); -int vcc_StringVal(struct tokenlist *tl); -void vcc_ExpectedStringval(struct tokenlist *tl); +char *vcc_regexp(struct vcc *tl); +int vcc_StringVal(struct vcc *tl); +void vcc_ExpectedStringval(struct vcc *tl); /* vcc_token.c */ -void vcc_Coord(const struct tokenlist *tl, struct vsb *vsb, +void vcc_Coord(const struct vcc *tl, struct vsb *vsb, const struct token *t); -void vcc_ErrToken(const struct tokenlist *tl, const struct token *t); -void vcc_ErrWhere(struct tokenlist *tl, const struct token *t); -void vcc__Expect(struct tokenlist *tl, unsigned tok, int line); +void vcc_ErrToken(const struct vcc *tl, const struct token *t); +void vcc_ErrWhere(struct vcc *tl, const struct token *t); +void vcc__Expect(struct vcc *tl, unsigned tok, int line); int vcc_Teq(const struct token *t1, const struct token *t2); int vcc_IdIs(const struct token *t, const char *p); -void vcc_ExpectCid(struct tokenlist *tl); -void vcc_Lexer(struct tokenlist *tl, struct source *sp); -void vcc_NextToken(struct tokenlist *tl); -void vcc__ErrInternal(struct tokenlist *tl, const char *func, +void vcc_ExpectCid(struct vcc *tl); +void vcc_Lexer(struct vcc *tl, struct source *sp); +void vcc_NextToken(struct vcc *tl); +void vcc__ErrInternal(struct vcc *tl, const char *func, unsigned line); -void vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, +void vcc_AddToken(struct vcc *tl, unsigned tok, const char *b, const char *e); /* vcc_var.c */ -struct var *vcc_FindVar(struct tokenlist *tl, const struct token *t, +struct var *vcc_FindVar(struct vcc *tl, const struct token *t, struct var *vl, int wr_access, const char *use); -void vcc_VarVal(struct tokenlist *tl, const struct var *vp, +void vcc_VarVal(struct vcc *tl, const struct var *vp, const struct token *vt); /* vcc_xref.c */ -void vcc_AddDef(struct tokenlist *tl, struct token *t, enum ref_type type); -void vcc_AddRef(struct tokenlist *tl, struct token *t, enum ref_type type); -int vcc_CheckReferences(struct tokenlist *tl); +void vcc_AddDef(struct vcc *tl, struct token *t, enum ref_type type); +void vcc_AddRef(struct vcc *tl, struct token *t, enum ref_type type); +int vcc_CheckReferences(struct vcc *tl); -void vcc_AddCall(struct tokenlist *tl, struct token *t); -struct proc *vcc_AddProc(struct tokenlist *tl, struct token *t); +void vcc_AddCall(struct vcc *tl, struct token *t); +struct proc *vcc_AddProc(struct vcc *tl, struct token *t); void vcc_ProcAction(struct proc *p, unsigned action, struct token *t); -int vcc_CheckAction(struct tokenlist *tl); -void vcc_AddUses(struct tokenlist *tl, const struct token *t, unsigned mask, +int vcc_CheckAction(struct vcc *tl); +void vcc_AddUses(struct vcc *tl, const struct token *t, unsigned mask, const char *use); -int vcc_CheckUses(struct tokenlist *tl); +int vcc_CheckUses(struct vcc *tl); #define ERRCHK(tl) do { if ((tl)->err) return; } while (0) #define ErrInternal(tl) vcc__ErrInternal(tl, __func__, __LINE__) Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -50,7 +50,7 @@ */ void -vcc_ParseRandomDirector(struct tokenlist *tl) +vcc_ParseRandomDirector(struct vcc *tl) { struct token *t_field, *t_be; int nelem; Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_dir_round_robin.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -49,7 +49,7 @@ */ void -vcc_ParseRoundRobinDirector(struct tokenlist *tl) +vcc_ParseRoundRobinDirector(struct vcc *tl) { struct token *t_field, *t_be; int nelem; Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -44,8 +44,8 @@ /*--------------------------------------------------------------------*/ -static void vcc_Compound(struct tokenlist *tl); -static void vcc_Cond_0(struct tokenlist *tl); +static void vcc_Compound(struct vcc *tl); +static void vcc_Cond_0(struct vcc *tl); /*--------------------------------------------------------------------*/ @@ -65,7 +65,7 @@ */ static double -vcc_TimeUnit(struct tokenlist *tl) +vcc_TimeUnit(struct vcc *tl) { double sc = 1.0; @@ -98,7 +98,7 @@ */ static double -vcc_SizeUnit(struct tokenlist *tl) +vcc_SizeUnit(struct vcc *tl) { double sc = 1.0; @@ -128,7 +128,7 @@ */ unsigned -vcc_UintVal(struct tokenlist *tl) +vcc_UintVal(struct vcc *tl) { unsigned d = 0; const char *p; @@ -148,7 +148,7 @@ */ double -vcc_DoubleVal(struct tokenlist *tl) +vcc_DoubleVal(struct vcc *tl) { double d = 0.0, e = 0.1; const char *p; @@ -177,7 +177,7 @@ /*--------------------------------------------------------------------*/ void -vcc_RTimeVal(struct tokenlist *tl, double *d) +vcc_RTimeVal(struct vcc *tl, double *d) { double v, sc; int sign = 1; @@ -196,7 +196,7 @@ /*--------------------------------------------------------------------*/ void -vcc_TimeVal(struct tokenlist *tl, double *d) +vcc_TimeVal(struct vcc *tl, double *d) { double v, sc; @@ -210,7 +210,7 @@ /*--------------------------------------------------------------------*/ void -vcc_SizeVal(struct tokenlist *tl, double *d) +vcc_SizeVal(struct vcc *tl, double *d) { double v, sc; @@ -224,7 +224,7 @@ /*--------------------------------------------------------------------*/ static void -vcc_Cond_String(const struct var *vp, struct tokenlist *tl) +vcc_Cond_String(const struct var *vp, struct vcc *tl) { char *p; @@ -258,7 +258,7 @@ } static void -vcc_Cond_Int(const struct var *vp, struct tokenlist *tl) +vcc_Cond_Int(const struct var *vp, struct vcc *tl) { Fb(tl, 1, "%s ", vp->rname); @@ -287,14 +287,14 @@ } static void -vcc_Cond_Bool(const struct var *vp, const struct tokenlist *tl) +vcc_Cond_Bool(const struct var *vp, const struct vcc *tl) { Fb(tl, 1, "%s\n", vp->rname); } static void -vcc_Cond_Backend(const struct var *vp, struct tokenlist *tl) +vcc_Cond_Backend(const struct var *vp, struct vcc *tl) { Fb(tl, 1, "%s\n", vp->rname); @@ -320,7 +320,7 @@ } static void -vcc_Cond_2(struct tokenlist *tl) +vcc_Cond_2(struct vcc *tl) { struct var *vp; @@ -370,7 +370,7 @@ } static void -vcc_Cond_1(struct tokenlist *tl) +vcc_Cond_1(struct vcc *tl) { Fb(tl, 1, "(\n"); @@ -384,7 +384,7 @@ } static void -vcc_Cond_0(struct tokenlist *tl) +vcc_Cond_0(struct vcc *tl) { Fb(tl, 1, "(\n"); @@ -398,7 +398,7 @@ } static void -vcc_Conditional(struct tokenlist *tl) +vcc_Conditional(struct vcc *tl) { SkipToken(tl, '('); @@ -412,7 +412,7 @@ /*--------------------------------------------------------------------*/ static void -vcc_IfStmt(struct tokenlist *tl) +vcc_IfStmt(struct vcc *tl) { SkipToken(tl, T_IF); @@ -451,7 +451,7 @@ /*--------------------------------------------------------------------*/ static void -vcc_Compound(struct tokenlist *tl) +vcc_Compound(struct vcc *tl) { int i; @@ -505,7 +505,7 @@ /*--------------------------------------------------------------------*/ static void -vcc_Function(struct tokenlist *tl) +vcc_Function(struct vcc *tl) { int m; @@ -560,7 +560,7 @@ * End of input */ -typedef void parse_f(struct tokenlist *tl); +typedef void parse_f(struct vcc *tl); static struct toplev { const char *name; @@ -575,7 +575,7 @@ }; void -vcc_Parse(struct tokenlist *tl) +vcc_Parse(struct vcc *tl) { struct toplev *tp; Modified: trunk/varnish-cache/lib/libvcl/vcc_string.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_string.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_string.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -47,7 +47,7 @@ /*--------------------------------------------------------------------*/ char * -vcc_regexp(struct tokenlist *tl) +vcc_regexp(struct vcc *tl) { char buf[BUFSIZ], *p; vre_t *t; @@ -81,7 +81,7 @@ /*--------------------------------------------------------------------*/ static int -vcc_regsub(struct tokenlist *tl, int all) +vcc_regsub(struct vcc *tl, int all) { char *p; @@ -140,7 +140,7 @@ */ int -vcc_StringVal(struct tokenlist *tl) +vcc_StringVal(struct vcc *tl) { struct var *vp; @@ -198,7 +198,7 @@ } void -vcc_ExpectedStringval(struct tokenlist *tl) +vcc_ExpectedStringval(struct vcc *tl) { if (!tl->err) { Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_token.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -48,7 +48,7 @@ /*--------------------------------------------------------------------*/ void -vcc_ErrToken(const struct tokenlist *tl, const struct token *t) +vcc_ErrToken(const struct vcc *tl, const struct token *t) { if (t->tok == EOI) @@ -60,7 +60,7 @@ } void -vcc__ErrInternal(struct tokenlist *tl, const char *func, unsigned line) +vcc__ErrInternal(struct vcc *tl, const char *func, unsigned line) { vsb_printf(tl->sb, "VCL compiler internal error at %s():%u\n", @@ -97,7 +97,7 @@ } void -vcc_Coord(const struct tokenlist *tl, struct vsb *vsb, const struct token *t) +vcc_Coord(const struct vcc *tl, struct vsb *vsb, const struct token *t) { if (t == NULL) @@ -106,7 +106,7 @@ } void -vcc_ErrWhere(struct tokenlist *tl, const struct token *t) +vcc_ErrWhere(struct vcc *tl, const struct token *t) { unsigned x, y; const char *p, *l, *e; @@ -156,7 +156,7 @@ /*--------------------------------------------------------------------*/ void -vcc_NextToken(struct tokenlist *tl) +vcc_NextToken(struct vcc *tl) { tl->t = VTAILQ_NEXT(tl->t, list); @@ -170,7 +170,7 @@ } void -vcc__Expect(struct tokenlist *tl, unsigned tok, int line) +vcc__Expect(struct vcc *tl, unsigned tok, int line) { if (tl->t->tok == tok) return; @@ -228,7 +228,7 @@ } void -vcc_ExpectCid(struct tokenlist *tl) +vcc_ExpectCid(struct vcc *tl) { ExpectErr(tl, ID); @@ -260,7 +260,7 @@ } static int -vcc_decstr(struct tokenlist *tl) +vcc_decstr(struct vcc *tl) { const char *p; char *q; @@ -309,7 +309,7 @@ */ void -vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char *e) +vcc_AddToken(struct vcc *tl, unsigned tok, const char *b, const char *e) { struct token *t; @@ -331,7 +331,7 @@ */ void -vcc_Lexer(struct tokenlist *tl, struct source *sp) +vcc_Lexer(struct vcc *tl, struct source *sp) { const char *p, *q; unsigned u; Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_var.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_var.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -44,7 +44,7 @@ /*--------------------------------------------------------------------*/ static struct var * -HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh) +HeaderVar(struct vcc *tl, const struct token *t, const struct var *vh) { char *p; struct var *v; @@ -87,7 +87,7 @@ /*--------------------------------------------------------------------*/ struct var * -vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl, +vcc_FindVar(struct vcc *tl, const struct token *t, struct var *vl, int wr_access, const char *use) { struct var *v; @@ -132,7 +132,7 @@ /*--------------------------------------------------------------------*/ void -vcc_VarVal(struct tokenlist *tl, const struct var *vp, const struct token *vt) +vcc_VarVal(struct vcc *tl, const struct var *vp, const struct token *vt) { double d; Modified: trunk/varnish-cache/lib/libvcl/vcc_xref.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_xref.c 2010-06-29 10:01:59 UTC (rev 4990) +++ trunk/varnish-cache/lib/libvcl/vcc_xref.c 2010-06-29 11:15:20 UTC (rev 4991) @@ -80,7 +80,7 @@ /*--------------------------------------------------------------------*/ static const char * -vcc_typename(struct tokenlist *tl, const struct ref *r) +vcc_typename(struct vcc *tl, const struct ref *r) { switch (r->type) { case R_FUNC: return ("function"); @@ -102,7 +102,7 @@ */ static struct ref * -vcc_findref(struct tokenlist *tl, struct token *t, enum ref_type type) +vcc_findref(struct vcc *tl, struct token *t, enum ref_type type) { struct ref *r; @@ -121,14 +121,14 @@ } void -vcc_AddRef(struct tokenlist *tl, struct token *t, enum ref_type type) +vcc_AddRef(struct vcc *tl, struct token *t, enum ref_type type) { vcc_findref(tl, t, type)->refcnt++; } void -vcc_AddDef(struct tokenlist *tl, struct token *t, enum ref_type type) +vcc_AddDef(struct vcc *tl, struct token *t, enum ref_type type) { struct ref *r; const char *tp; @@ -149,7 +149,7 @@ /*--------------------------------------------------------------------*/ int -vcc_CheckReferences(struct tokenlist *tl) +vcc_CheckReferences(struct vcc *tl) { struct ref *r; const char *type; @@ -184,7 +184,7 @@ */ static struct proc * -vcc_findproc(struct tokenlist *tl, struct token *t) +vcc_findproc(struct vcc *tl, struct token *t) { struct proc *p; @@ -201,7 +201,7 @@ } struct proc * -vcc_AddProc(struct tokenlist *tl, struct token *t) +vcc_AddProc(struct vcc *tl, struct token *t) { struct proc *p; @@ -212,7 +212,7 @@ } void -vcc_AddUses(struct tokenlist *tl, const struct token *t, unsigned mask, +vcc_AddUses(struct vcc *tl, const struct token *t, unsigned mask, const char *use) { struct procuse *pu; @@ -229,7 +229,7 @@ } void -vcc_AddCall(struct tokenlist *tl, struct token *t) +vcc_AddCall(struct vcc *tl, struct token *t) { struct proccall *pc; struct proc *p; @@ -254,7 +254,7 @@ } static int -vcc_CheckActionRecurse(struct tokenlist *tl, struct proc *p, unsigned bitmap) +vcc_CheckActionRecurse(struct vcc *tl, struct proc *p, unsigned bitmap) { unsigned u; struct proccall *pc; @@ -299,7 +299,7 @@ } int -vcc_CheckAction(struct tokenlist *tl) +vcc_CheckAction(struct vcc *tl) { struct proc *p; struct method *m; @@ -348,7 +348,7 @@ } static int -vcc_CheckUseRecurse(struct tokenlist *tl, const struct proc *p, +vcc_CheckUseRecurse(struct vcc *tl, const struct proc *p, struct method *m) { struct proccall *pc; @@ -377,7 +377,7 @@ } int -vcc_CheckUses(struct tokenlist *tl) +vcc_CheckUses(struct vcc *tl) { struct proc *p; struct method *m; From perbu at varnish-cache.org Tue Jun 29 12:19:22 2010 From: perbu at varnish-cache.org (perbu at varnish-cache.org) Date: Tue, 29 Jun 2010 14:19:22 +0200 Subject: r4992 - trunk/varnish-cache/doc/sphinx/tutorial Message-ID: Author: perbu Date: 2010-06-29 14:19:22 +0200 (Tue, 29 Jun 2010) New Revision: 4992 Modified: trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst Log: more on vcl: pipe, deliver, ACLs, purging Modified: trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst =================================================================== --- trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst 2010-06-29 11:15:20 UTC (rev 4991) +++ trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst 2010-06-29 12:19:22 UTC (rev 4992) @@ -22,7 +22,7 @@ code commented out in default.vcl. 99% of all the changes you'll need to do will be done in two of these -subroutines. vcl_recv and vcl_fetch. +subroutines. *vcl_recv* and *vcl_fetch*. vcl_recv ~~~~~~~~ @@ -35,7 +35,7 @@ In vcl_recv you can also alter the request. Typically you can alter the cookies and add and remove request headers. -Note that in vcl_recv only the request object, req is availble. +Note that in vcl_recv only the request object, req is available. vcl_fetch ~~~~~~~~~ @@ -66,13 +66,67 @@ should be passed. You can't call lookup from vcl_fetch. *pipe* - + Pipe can be called from vcl_recv as well. Pipe short circuits the + client and the backend connections and Varnish will just sit there + and shuffle bytes back and forth. Varnish will not look at the data being + send back and forth - so your logs will be incomplete. + Beware that with HTTP 1.1 a client can send several requests on the same + connection and so you should instruct Varnish to add a "Connection: close" + header before actually calling pipe. *deliver* + Deliver the cached object to the client. Usually called in vcl_fetch. *esi* ESI-process the fetched document. +Requests, responses and objects +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +In VCL, there are three important data structures. The request, coming +from the client, the response coming from the backend server and the +object, stored in cache. + +In VCL you should know the following structures. + +*req* + The request object. When Varnish has received the request the req object is + created and populated. Most of the work you do in vcl_recv you + do on or with the req object. + +*beresp* + The backend respons object. It contains the headers of the object + comming from the backend. Most of the work you do in vcl_fetch you + do on the beresp object. + +*obj* + The cached object. Mostly a read only object that resides in memory. + obj.ttl is writable, the rest is read only. + +Operators +~~~~~~~~~ + +The following operators are available in VCL. See the examples further +down for, uhm, examples. + += + Assignment operator. + +== + Comparison. + +~ + Match. Can either be used with regular expressions or ACLs. + +! + Negation. + +&& + Logical *and* + +|| + Logical *or* + Example 1 - manipulating headers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -87,20 +141,10 @@ Now, when the request is handled to the backend server there will be no cookie header. The interesting line is the one with the -if-statement. It probably needs a bit of explaining. Varnish has a few -objects that are available throughout the VCL. The important ones are: +if-statement. It matches the URL, taken from the request object, and +matches it against the regular expression. Note the match operator. If +it matches the Cookie: header of the request is unset (deleted). -*req* - The request object. Each HTTP transaction contains a request and a - response. When Varnish has recieved the request the req object is - created and populated. Most of the work you do in vcl_fetch you - do on or with the req object. - -*beresp* - The backend respons object. It contains the headers of the object - comming from the backend. Most of the work you do in vcl_fetch you - do on the beresp object. - Example 2 - manipulating beresp ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -116,3 +160,35 @@ Example 3 - ACLs ~~~~~~~~~~~~~~~~ + +You create a named access control list with the *acl* keyword. You can match +the IP address of the client against an ACL with the match operator.:: + + # Who is allowed to purge.... + acl local { + "localhost"; + "192.168.1.0"/24; /* and everyone on the local network */ + ! "192.168.1.23"; /* except for the dialin router */ + } + + sub vcl_recv { + if (req.request == "PURGE") { + if (client.ip ~ local) { + return(lookup); + } + } + } + + sub vcl_hit { + if (req.request == "PURGE") { + set obj.ttl = 0s; + error 200 "Purged."; + } + } + + sub vcl_miss { + if (req.request == "PURGE") { + error 404 "Not in cache."; + } + } + From phk at varnish-cache.org Tue Jun 29 12:29:00 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Tue, 29 Jun 2010 14:29:00 +0200 Subject: r4993 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: Author: phk Date: 2010-06-29 14:29:00 +0200 (Tue, 29 Jun 2010) New Revision: 4993 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/include/libvcl.h trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_compile.h Log: Change API to VCC to be handle/object based. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2010-06-29 12:19:22 UTC (rev 4992) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2010-06-29 12:29:00 UTC (rev 4993) @@ -69,6 +69,8 @@ char *mgt_cc_cmd; char *mgt_vcl_dir; +static struct vcc *vcc; + /*--------------------------------------------------------------------*/ /* @@ -151,7 +153,7 @@ vp = priv; sb = vsb_newauto(); XXXAN(sb); - csrc = VCC_Compile(sb, vp->vcl, NULL); + csrc = VCC_Compile(vcc, sb, vp->vcl); vsb_finish(sb); AZ(vsb_overflowed(sb)); if (vsb_len(sb)) @@ -449,7 +451,9 @@ mgt_vcc_init(void) { - VCC_InitCompile(default_vcl); + vcc = VCC_New(); + AN(vcc); + VCC_Default_VCL(vcc, default_vcl); AZ(atexit(mgt_vcc_atexit)); } Modified: trunk/varnish-cache/include/libvcl.h =================================================================== --- trunk/varnish-cache/include/libvcl.h 2010-06-29 12:19:22 UTC (rev 4992) +++ trunk/varnish-cache/include/libvcl.h 2010-06-29 12:29:00 UTC (rev 4993) @@ -29,7 +29,11 @@ * $Id$ */ -char *VCC_Compile(struct vsb *sb, const char *b, const char *e); -void VCC_InitCompile(const char *default_vcl); +struct vcc; + +struct vcc *VCC_New(void); +void VCC_Default_VCL(struct vcc *, const char *str); +void VCC_VCL_dir(struct vcc *, const char *str); + +char *VCC_Compile(const struct vcc *, struct vsb *sb, const char *b); const char *VCC_Return_Name(unsigned action); - Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-29 12:19:22 UTC (rev 4992) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-29 12:29:00 UTC (rev 4993) @@ -84,10 +84,6 @@ /*--------------------------------------------------------------------*/ -static const char *vcc_default_vcl_b, *vcc_default_vcl_e; - -/*--------------------------------------------------------------------*/ - static void TlDoFree(struct vcc *tl, void *p) { @@ -454,13 +450,17 @@ /*--------------------------------------------------------------------*/ static struct vcc * -vcc_NewTokenList(void) +vcc_NewVcc(const struct vcc *tl0) { struct vcc *tl; int i; - tl = calloc(sizeof *tl, 1); - assert(tl != NULL); + ALLOC_OBJ(tl, VCC_MAGIC); + AN(tl); + if (tl0 != NULL) { + REPLACE(tl->default_vcl, tl0->default_vcl); + REPLACE(tl->vcl_dir, tl0->vcl_dir); + } VTAILQ_INIT(&tl->hosts); VTAILQ_INIT(&tl->membits); VTAILQ_INIT(&tl->tokens); @@ -532,13 +532,13 @@ */ static char * -vcc_CompileSource(struct vsb *sb, struct source *sp) +vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp) { struct vcc *tl; char *of; int i; - tl = vcc_NewTokenList(); + tl = vcc_NewVcc(tl0); tl->sb = sb; vcl_output_lang_h(tl->fh); @@ -556,7 +556,7 @@ return (vcc_DestroyTokenList(tl, NULL)); /* Register and lex the default VCL */ - sp = vcc_new_source(vcc_default_vcl_b, vcc_default_vcl_e, "Default"); + sp = vcc_new_source(tl->default_vcl, NULL, "Default"); assert(sp != NULL); VTAILQ_INSERT_TAIL(&tl->sources, sp, list); sp->idx = tl->nsources++; @@ -646,15 +646,15 @@ */ char * -VCC_Compile(struct vsb *sb, const char *b, const char *e) +VCC_Compile(const struct vcc *tl, struct vsb *sb, const char *b) { struct source *sp; char *r; - sp = vcc_new_source(b, e, "input"); + sp = vcc_new_source(b, NULL, "input"); if (sp == NULL) return (NULL); - r = vcc_CompileSource(sb, sp); + r = vcc_CompileSource(tl, sb, sp); return (r); } @@ -674,15 +674,38 @@ } /*-------------------------------------------------------------------- - * Initialize the compiler and register the default VCL code for later - * compilation runs. + * Allocate a compiler instance */ +struct vcc * +VCC_New(void) +{ + struct vcc *tl; + + tl = vcc_NewVcc(NULL); + return (tl); +} + +/*-------------------------------------------------------------------- + * Configure default VCL source code + */ + void -VCC_InitCompile(const char *default_vcl) +VCC_Default_VCL(struct vcc *tl, const char *str) { - vcc_default_vcl_b = default_vcl; - vcc_default_vcl_e = strchr(default_vcl, '\0'); - assert(vcc_default_vcl_e != NULL); + CHECK_OBJ_NOTNULL(tl, VCC_MAGIC); + REPLACE(tl->default_vcl, str); } + +/*-------------------------------------------------------------------- + * Configure default VCL source directory + */ + +void +VCC_VCL_dir(struct vcc *tl, const char *str) +{ + + CHECK_OBJ_NOTNULL(tl, VCC_MAGIC); + REPLACE(tl->vcl_dir, str); +} Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-29 12:19:22 UTC (rev 4992) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-06-29 12:29:00 UTC (rev 4993) @@ -31,6 +31,7 @@ #include "vqueue.h" +#include "miniobj.h" #include "vcl.h" #define INDENT 2 @@ -64,6 +65,14 @@ VTAILQ_HEAD(tokenhead, token); struct vcc { + unsigned magic; +#define VCC_MAGIC 0x24ad719d + + /* Parameter/Template section */ + char *default_vcl; + char *vcl_dir; + + /* Instance section */ struct tokenhead tokens; VTAILQ_HEAD(, source) sources; VTAILQ_HEAD(, membit) membits; From phk at varnish-cache.org Wed Jun 30 12:55:57 2010 From: phk at varnish-cache.org (phk at varnish-cache.org) Date: Wed, 30 Jun 2010 14:55:57 +0200 Subject: r4994 - in trunk/varnish-cache: bin/varnishd include lib/libvarnish lib/libvcl Message-ID: Author: phk Date: 2010-06-30 14:55:57 +0200 (Wed, 30 Jun 2010) New Revision: 4994 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishd/varnishd.c trunk/varnish-cache/include/libvarnish.h trunk/varnish-cache/lib/libvarnish/vtmpfile.c trunk/varnish-cache/lib/libvcl/vcc_compile.c Log: Make vcl_dir work for vcl.load and include filenames. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2010-06-29 12:29:00 UTC (rev 4993) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2010-06-30 12:55:57 UTC (rev 4994) @@ -153,6 +153,7 @@ vp = priv; sb = vsb_newauto(); XXXAN(sb); + VCC_VCL_dir(vcc, mgt_vcl_dir); csrc = VCC_Compile(vcc, sb, vp->vcl); vsb_finish(sb); AZ(vsb_overflowed(sb)); @@ -212,7 +213,7 @@ } if (C_flag) { - csrc = vreadfile(sf); + csrc = vreadfile(NULL, sf); XXXAN(csrc); (void)fputs(csrc, stdout); free(csrc); @@ -513,7 +514,7 @@ return; } - vcl = vreadfile(av[3]); + vcl = vreadfile(mgt_vcl_dir, av[3]); if (vcl == NULL) { cli_out(cli, "Cannot open '%s'", av[3]); cli_result(cli, CLIS_PARAM); Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-29 12:29:00 UTC (rev 4993) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2010-06-30 12:55:57 UTC (rev 4994) @@ -541,7 +541,7 @@ } if (f_arg != NULL) { - vcl = vreadfile(f_arg); + vcl = vreadfile(NULL, f_arg); if (vcl == NULL) { fprintf(stderr, "Cannot read '%s': %s\n", f_arg, strerror(errno)); Modified: trunk/varnish-cache/include/libvarnish.h =================================================================== --- trunk/varnish-cache/include/libvarnish.h 2010-06-29 12:29:00 UTC (rev 4993) +++ trunk/varnish-cache/include/libvarnish.h 2010-06-30 12:55:57 UTC (rev 4994) @@ -97,7 +97,7 @@ /* from libvarnish/vtmpfile.c */ int vtmpfile(char *); -char *vreadfile(const char *fn); +char *vreadfile(const char *pfx, const char *fn); const char* svn_version(void); Modified: trunk/varnish-cache/lib/libvarnish/vtmpfile.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vtmpfile.c 2010-06-29 12:29:00 UTC (rev 4993) +++ trunk/varnish-cache/lib/libvarnish/vtmpfile.c 2010-06-30 12:55:57 UTC (rev 4994) @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -98,12 +99,19 @@ } char * -vreadfile(const char *fn) +vreadfile(const char *pfx, const char *fn) { int fd, err; char *r; + char fnb[PATH_MAX + 1]; - fd = open(fn, O_RDONLY); + if (fn[0] == '/') + fd = open(fn, O_RDONLY); + else if (pfx != NULL) { + bprintf(fnb, "/%s/%s", pfx, fn); /* XXX: graceful length check */ + fd = open(fnb, O_RDONLY); + } else + fd = open(fn, O_RDONLY); if (fd < 0) return (NULL); r = vreadfd(fd); Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-29 12:29:00 UTC (rev 4993) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2010-06-30 12:55:57 UTC (rev 4994) @@ -382,12 +382,12 @@ /*--------------------------------------------------------------------*/ static struct source * -vcc_file_source(struct vsb *sb, const char *fn) +vcc_file_source(struct vcc *tl, struct vsb *sb, const char *fn) { char *f; struct source *sp; - f = vreadfile(fn); + f = vreadfile(tl->vcl_dir, fn); if (f == NULL) { vsb_printf(sb, "Cannot read file '%s': %s\n", fn, strerror(errno)); @@ -428,7 +428,7 @@ } assert(t2 != NULL); - sp = vcc_file_source(tl->sb, t1->dec); + sp = vcc_file_source(tl, tl->sb, t1->dec); if (sp == NULL) { vcc_ErrWhere(tl, t1); return;