Commit 7d895b2d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Catch up with changes in shmlog format: handle records longer than 256 char

and id's higher than 64k, by employing variable size bitmaps and dynamic
buffers.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4447 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 04deea86
...@@ -47,6 +47,7 @@ SVNID("$Id$") ...@@ -47,6 +47,7 @@ SVNID("$Id$")
#include "shmlog.h" #include "shmlog.h"
#include "vre.h" #include "vre.h"
#include "vbm.h"
#include "miniobj.h" #include "miniobj.h"
#include "varnishapi.h" #include "varnishapi.h"
...@@ -54,8 +55,6 @@ SVNID("$Id$") ...@@ -54,8 +55,6 @@ SVNID("$Id$")
#define SLEEP_USEC (50*1000) #define SLEEP_USEC (50*1000)
#define TIMEOUT_USEC (5*1000*1000) #define TIMEOUT_USEC (5*1000*1000)
#define NFD (256 * 256)
struct VSL_data { struct VSL_data {
unsigned magic; unsigned magic;
#define VSL_MAGIC 0x6e3bd69b #define VSL_MAGIC 0x6e3bd69b
...@@ -67,7 +66,8 @@ struct VSL_data { ...@@ -67,7 +66,8 @@ struct VSL_data {
/* for -r option */ /* for -r option */
int fd; int fd;
unsigned char rbuf[SHMLOG_NEXTTAG + 255 + 1]; unsigned rbuflen;
unsigned char *rbuf;
int b_opt; int b_opt;
int c_opt; int c_opt;
...@@ -77,11 +77,22 @@ struct VSL_data { ...@@ -77,11 +77,22 @@ struct VSL_data {
#define F_SEEN_IX (1 << 0) #define F_SEEN_IX (1 << 0)
#define F_NON_BLOCKING (1 << 1) #define F_NON_BLOCKING (1 << 1)
unsigned char map[NFD]; /*
#define M_CLIENT (1 << 0) * These two bitmaps mark fd's as belonging to client or backend
#define M_BACKEND (1 << 1) * transactions respectively.
#define M_SUPPRESS (1 << 2) */
#define M_SELECT (1 << 3) 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; int regflags;
vre_t *regincl; vre_t *regincl;
...@@ -166,13 +177,18 @@ VSL_New(void) ...@@ -166,13 +177,18 @@ VSL_New(void)
{ {
struct VSL_data *vd; struct VSL_data *vd;
assert(VSL_S_CLIENT == M_CLIENT);
assert(VSL_S_BACKEND == M_BACKEND);
vd = calloc(sizeof *vd, 1); vd = calloc(sizeof *vd, 1);
assert(vd != NULL); assert(vd != NULL);
vd->regflags = 0; vd->regflags = 0;
vd->magic = VSL_MAGIC; vd->magic = VSL_MAGIC;
vd->fd = -1; vd->fd = -1;
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->rbuflen = SHMLOG_NEXTTAG + 256;
vd->rbuf = malloc(vd->rbuflen);
assert(vd->rbuf != NULL);
return (vd); return (vd);
} }
...@@ -183,7 +199,7 @@ VSL_Select(struct VSL_data *vd, unsigned tag) ...@@ -183,7 +199,7 @@ VSL_Select(struct VSL_data *vd, unsigned tag)
{ {
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
vd->map[tag] |= M_SELECT; vbit_set(vd->vbm_select, tag);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
...@@ -235,12 +251,20 @@ vsl_nextlog(struct VSL_data *vd, unsigned char **pp) ...@@ -235,12 +251,20 @@ vsl_nextlog(struct VSL_data *vd, unsigned char **pp)
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (vd->fd != -1) { if (vd->fd != -1) {
assert(vd->rbuflen >= SHMLOG_DATA);
i = read(vd->fd, vd->rbuf, SHMLOG_DATA); i = read(vd->fd, vd->rbuf, SHMLOG_DATA);
if (i != SHMLOG_DATA) if (i != SHMLOG_DATA)
return (-1); return (-1);
i = read(vd->fd, vd->rbuf + SHMLOG_DATA, l = SHMLOG_LEN(vd->rbuf) + SHMLOG_NEXTTAG;
SHMLOG_LEN(vd->rbuf) + 1); if (vd->rbuflen < l) {
if (i != SHMLOG_LEN(vd->rbuf) + 1) l += 200;
vd->rbuf = realloc(vd->rbuf, l);
assert(vd->rbuf != NULL);
vd->rbuflen = l;
}
l = SHMLOG_LEN(vd->rbuf) + 1;
i = read(vd->fd, vd->rbuf + SHMLOG_DATA, l);
if (i != l)
return (-1); return (-1);
*pp = vd->rbuf; *pp = vd->rbuf;
return (1); return (1);
...@@ -271,7 +295,7 @@ vsl_nextlog(struct VSL_data *vd, unsigned char **pp) ...@@ -271,7 +295,7 @@ vsl_nextlog(struct VSL_data *vd, unsigned char **pp)
int int
VSL_NextLog(struct VSL_data *vd, unsigned char **pp) VSL_NextLog(struct VSL_data *vd, unsigned char **pp)
{ {
unsigned char *p; unsigned char *p, t;
unsigned u, l; unsigned u, l;
int i; int i;
...@@ -285,13 +309,13 @@ VSL_NextLog(struct VSL_data *vd, unsigned char **pp) ...@@ -285,13 +309,13 @@ VSL_NextLog(struct VSL_data *vd, unsigned char **pp)
switch(p[SHMLOG_TAG]) { switch(p[SHMLOG_TAG]) {
case SLT_SessionOpen: case SLT_SessionOpen:
case SLT_ReqStart: case SLT_ReqStart:
vd->map[u] |= M_CLIENT; vbit_set(vd->vbm_client, u);
vd->map[u] &= ~M_BACKEND; vbit_clr(vd->vbm_backend, u);
break; break;
case SLT_BackendOpen: case SLT_BackendOpen:
case SLT_BackendXID: case SLT_BackendXID:
vd->map[u] |= M_BACKEND; vbit_clr(vd->vbm_client, u);
vd->map[u] &= ~M_CLIENT; vbit_set(vd->vbm_backend, u);
break; break;
default: default:
break; break;
...@@ -303,15 +327,16 @@ VSL_NextLog(struct VSL_data *vd, unsigned char **pp) ...@@ -303,15 +327,16 @@ VSL_NextLog(struct VSL_data *vd, unsigned char **pp)
if (--vd->keep == 0) if (--vd->keep == 0)
return (-1); return (-1);
} }
if (vd->map[p[SHMLOG_TAG]] & M_SELECT) { t = p[SHMLOG_TAG];
if (vbit_test(vd->vbm_select, t)) {
*pp = p; *pp = p;
return (1); return (1);
} }
if (vd->map[p[SHMLOG_TAG]] & M_SUPPRESS) if (vbit_test(vd->vbm_supress, t))
continue; continue;
if (vd->b_opt && !(vd->map[u] & M_BACKEND)) if (vd->b_opt && !vbit_test(vd->vbm_backend, u))
continue; continue;
if (vd->c_opt && !(vd->map[u] & M_CLIENT)) if (vd->c_opt && !vbit_test(vd->vbm_client, u))
continue; continue;
if (vd->regincl != NULL) { if (vd->regincl != NULL) {
i = VRE_exec(vd->regincl, i = VRE_exec(vd->regincl,
...@@ -340,7 +365,7 @@ int ...@@ -340,7 +365,7 @@ int
VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv) VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv)
{ {
int i; int i;
unsigned u, l; unsigned u, l, s;
unsigned char *p; unsigned char *p;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC); CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
...@@ -350,10 +375,13 @@ VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv) ...@@ -350,10 +375,13 @@ VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv)
return (i); return (i);
u = SHMLOG_ID(p); u = SHMLOG_ID(p);
l = SHMLOG_LEN(p); l = SHMLOG_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, if (func(priv,
p[SHMLOG_TAG], u, l, p[SHMLOG_TAG], u, l, s, (char *)p + SHMLOG_DATA))
vd->map[u] & (VSL_S_CLIENT|VSL_S_BACKEND),
(char *)p + SHMLOG_DATA))
return (1); return (1);
} }
} }
...@@ -444,7 +472,7 @@ vsl_ix_arg(struct VSL_data *vd, const char *opt, int arg) ...@@ -444,7 +472,7 @@ vsl_ix_arg(struct VSL_data *vd, const char *opt, int arg)
/* If first option is 'i', set all bits for supression */ /* If first option is 'i', set all bits for supression */
if (arg == 'i' && !(vd->flags & F_SEEN_IX)) if (arg == 'i' && !(vd->flags & F_SEEN_IX))
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
vd->map[i] |= M_SUPPRESS; vbit_set(vd->vbm_supress, i);
vd->flags |= F_SEEN_IX; vd->flags |= F_SEEN_IX;
for (b = opt; *b; b = e) { for (b = opt; *b; b = e) {
...@@ -470,9 +498,9 @@ vsl_ix_arg(struct VSL_data *vd, const char *opt, int arg) ...@@ -470,9 +498,9 @@ vsl_ix_arg(struct VSL_data *vd, const char *opt, int arg)
continue; continue;
if (arg == 'x') if (arg == 'x')
vd->map[i] |= M_SUPPRESS; vbit_set(vd->vbm_supress, i);
else else
vd->map[i] &= ~M_SUPPRESS; vbit_clr(vd->vbm_supress, i);
break; break;
} }
if (i == 256) { if (i == 256) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment