Mailing List Archive

r3428 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2008-11-24 16:53:26 +0100 (Mon, 24 Nov 2008)
New Revision: 3428

Modified:
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/mgt_param.c
trunk/varnish-cache/bin/varnishd/shmlog.c
Log:
Make the maximum record length in the shm log a paramter "shm_reclen".



Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h 2008-11-24 14:41:36 UTC (rev 3427)
+++ trunk/varnish-cache/bin/varnishd/heritage.h 2008-11-24 15:53:26 UTC (rev 3428)
@@ -98,6 +98,8 @@
unsigned obj_workspace;
unsigned shm_workspace;

+ unsigned shm_reclen;
+
/* Acceptor hints */
unsigned sess_timeout;
unsigned pipe_timeout;

Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-11-24 14:41:36 UTC (rev 3427)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-11-24 15:53:26 UTC (rev 3428)
@@ -636,6 +636,11 @@
"Minimum is 4096 bytes.",
DELAYED_EFFECT,
"8192", "bytes" },
+ { "shm_reclen", tweak_uint, &master.shm_reclen, 16, 65535,
+ "Maximum number of bytes in SHM log record.\n"
+ "Maximum is 65535 bytes.",
+ 0,
+ "255", "bytes" },
{ "default_grace", tweak_uint, &master.default_grace, 0, UINT_MAX,
"Default grace period. We will deliver an object "
"this long after it has expired, provided another thread "

Modified: trunk/varnish-cache/bin/varnishd/shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/shmlog.c 2008-11-24 14:41:36 UTC (rev 3427)
+++ trunk/varnish-cache/bin/varnishd/shmlog.c 2008-11-24 15:53:26 UTC (rev 3428)
@@ -81,6 +81,8 @@
vsl_hdr(enum shmlogtag tag, unsigned char *p, unsigned len, unsigned id)
{

+ assert(len < 0x10000);
+ assert(id < 0x10000);
p[__SHMLOG_LEN_HIGH] = (len >> 8) & 0xff;
p[__SHMLOG_LEN_LOW] = len & 0xff;
p[__SHMLOG_ID_HIGH] = (id >> 8) & 0xff;
@@ -100,14 +102,15 @@
VSLR(enum shmlogtag tag, int id, txt t)
{
unsigned char *p;
- unsigned l;
+ unsigned l, mlen;

Tcheck(t);
+ mlen = params->shm_reclen;

/* Truncate */
l = Tlen(t);
- if (l > 255) {
- l = 255;
+ if (l > mlen) {
+ l = mlen;
t.e = t.b + l;
}

@@ -136,11 +139,12 @@
{
va_list ap;
unsigned char *p;
- unsigned n;
+ unsigned n, mlen;
txt t;

AN(fmt);
va_start(ap, fmt);
+ mlen = params->shm_reclen;

if (strchr(fmt, '%') == NULL) {
t.b = TRUST_ME(fmt);
@@ -153,13 +157,14 @@
assert(loghead->ptr < loghead->size);

/* Wrap if we cannot fit a full size record */
- if (loghead->ptr + SHMLOG_NEXTTAG + 255 + 1 >= loghead->size)
+ if (loghead->ptr + SHMLOG_NEXTTAG + mlen + 1 >= loghead->size)
vsl_wrap();

p = logstart + loghead->ptr;
- n = vsnprintf((char *)(p + SHMLOG_DATA), 256, fmt, ap);
- if (n > 255)
- n = 255; /* we truncate long fields */
+ /* +1 for the NUL */
+ n = vsnprintf((char *)(p + SHMLOG_DATA), mlen + 1, fmt, ap);
+ if (n > mlen)
+ n = mlen; /* we truncate long fields */
vsl_hdr(tag, p, n, id);
loghead->ptr += SHMLOG_NEXTTAG + n;
assert(loghead->ptr < loghead->size);
@@ -203,14 +208,15 @@
WSLR(struct worker *w, enum shmlogtag tag, int id, txt t)
{
unsigned char *p;
- unsigned l;
+ unsigned l, mlen;

Tcheck(t);
+ mlen = params->shm_reclen;

/* Truncate */
l = Tlen(t);
- if (l > 255) {
- l = 255;
+ if (l > mlen) {
+ l = mlen;
t.e = t.b + l;
}

@@ -234,11 +240,12 @@
{
va_list ap;
unsigned char *p;
- unsigned n;
+ unsigned n, mlen;
txt t;

AN(fmt);
va_start(ap, fmt);
+ mlen = params->shm_reclen;

if (strchr(fmt, '%') == NULL) {
t.b = TRUST_ME(fmt);
@@ -248,13 +255,14 @@
assert(w->wlp < w->wle);

/* Wrap if we cannot fit a full size record */
- if (w->wlp + SHMLOG_NEXTTAG + 255 + 1 >= w->wle)
+ if (w->wlp + SHMLOG_NEXTTAG + mlen + 1 >= w->wle)
WSL_Flush(w, 1);

p = w->wlp;
- n = vsnprintf((char *)(p + SHMLOG_DATA), 256, fmt, ap);
- if (n > 255)
- n = 255; /* we truncate long fields */
+ /* +1 for the NUL */
+ n = vsnprintf((char *)(p + SHMLOG_DATA), mlen + 1, fmt, ap);
+ if (n > mlen)
+ n = mlen; /* we truncate long fields */
vsl_hdr(tag, p, n, id);
w->wlp += SHMLOG_NEXTTAG + n;
assert(w->wlp < w->wle);