Commit fbd8cb9d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make the maximum record length in the shm log a paramter "shm_reclen".



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3428 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 8e48a7ee
...@@ -98,6 +98,8 @@ struct params { ...@@ -98,6 +98,8 @@ struct params {
unsigned obj_workspace; unsigned obj_workspace;
unsigned shm_workspace; unsigned shm_workspace;
unsigned shm_reclen;
/* Acceptor hints */ /* Acceptor hints */
unsigned sess_timeout; unsigned sess_timeout;
unsigned pipe_timeout; unsigned pipe_timeout;
......
...@@ -636,6 +636,11 @@ static const struct parspec parspec[] = { ...@@ -636,6 +636,11 @@ static const struct parspec parspec[] = {
"Minimum is 4096 bytes.", "Minimum is 4096 bytes.",
DELAYED_EFFECT, DELAYED_EFFECT,
"8192", "bytes" }, "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", tweak_uint, &master.default_grace, 0, UINT_MAX,
"Default grace period. We will deliver an object " "Default grace period. We will deliver an object "
"this long after it has expired, provided another thread " "this long after it has expired, provided another thread "
......
...@@ -81,6 +81,8 @@ static void ...@@ -81,6 +81,8 @@ static void
vsl_hdr(enum shmlogtag tag, unsigned char *p, unsigned len, unsigned id) 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_HIGH] = (len >> 8) & 0xff;
p[__SHMLOG_LEN_LOW] = len & 0xff; p[__SHMLOG_LEN_LOW] = len & 0xff;
p[__SHMLOG_ID_HIGH] = (id >> 8) & 0xff; p[__SHMLOG_ID_HIGH] = (id >> 8) & 0xff;
...@@ -100,14 +102,15 @@ static void ...@@ -100,14 +102,15 @@ static void
VSLR(enum shmlogtag tag, int id, txt t) VSLR(enum shmlogtag tag, int id, txt t)
{ {
unsigned char *p; unsigned char *p;
unsigned l; unsigned l, mlen;
Tcheck(t); Tcheck(t);
mlen = params->shm_reclen;
/* Truncate */ /* Truncate */
l = Tlen(t); l = Tlen(t);
if (l > 255) { if (l > mlen) {
l = 255; l = mlen;
t.e = t.b + l; t.e = t.b + l;
} }
...@@ -136,11 +139,12 @@ VSL(enum shmlogtag tag, int id, const char *fmt, ...) ...@@ -136,11 +139,12 @@ VSL(enum shmlogtag tag, int id, const char *fmt, ...)
{ {
va_list ap; va_list ap;
unsigned char *p; unsigned char *p;
unsigned n; unsigned n, mlen;
txt t; txt t;
AN(fmt); AN(fmt);
va_start(ap, fmt); va_start(ap, fmt);
mlen = params->shm_reclen;
if (strchr(fmt, '%') == NULL) { if (strchr(fmt, '%') == NULL) {
t.b = TRUST_ME(fmt); t.b = TRUST_ME(fmt);
...@@ -153,13 +157,14 @@ VSL(enum shmlogtag tag, int id, const char *fmt, ...) ...@@ -153,13 +157,14 @@ VSL(enum shmlogtag tag, int id, const char *fmt, ...)
assert(loghead->ptr < loghead->size); assert(loghead->ptr < loghead->size);
/* Wrap if we cannot fit a full size record */ /* 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(); vsl_wrap();
p = logstart + loghead->ptr; p = logstart + loghead->ptr;
n = vsnprintf((char *)(p + SHMLOG_DATA), 256, fmt, ap); /* +1 for the NUL */
if (n > 255) n = vsnprintf((char *)(p + SHMLOG_DATA), mlen + 1, fmt, ap);
n = 255; /* we truncate long fields */ if (n > mlen)
n = mlen; /* we truncate long fields */
vsl_hdr(tag, p, n, id); vsl_hdr(tag, p, n, id);
loghead->ptr += SHMLOG_NEXTTAG + n; loghead->ptr += SHMLOG_NEXTTAG + n;
assert(loghead->ptr < loghead->size); assert(loghead->ptr < loghead->size);
...@@ -203,14 +208,15 @@ void ...@@ -203,14 +208,15 @@ void
WSLR(struct worker *w, enum shmlogtag tag, int id, txt t) WSLR(struct worker *w, enum shmlogtag tag, int id, txt t)
{ {
unsigned char *p; unsigned char *p;
unsigned l; unsigned l, mlen;
Tcheck(t); Tcheck(t);
mlen = params->shm_reclen;
/* Truncate */ /* Truncate */
l = Tlen(t); l = Tlen(t);
if (l > 255) { if (l > mlen) {
l = 255; l = mlen;
t.e = t.b + l; t.e = t.b + l;
} }
...@@ -234,11 +240,12 @@ WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...) ...@@ -234,11 +240,12 @@ WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...)
{ {
va_list ap; va_list ap;
unsigned char *p; unsigned char *p;
unsigned n; unsigned n, mlen;
txt t; txt t;
AN(fmt); AN(fmt);
va_start(ap, fmt); va_start(ap, fmt);
mlen = params->shm_reclen;
if (strchr(fmt, '%') == NULL) { if (strchr(fmt, '%') == NULL) {
t.b = TRUST_ME(fmt); t.b = TRUST_ME(fmt);
...@@ -248,13 +255,14 @@ WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...) ...@@ -248,13 +255,14 @@ WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...)
assert(w->wlp < w->wle); assert(w->wlp < w->wle);
/* Wrap if we cannot fit a full size record */ /* 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); WSL_Flush(w, 1);
p = w->wlp; p = w->wlp;
n = vsnprintf((char *)(p + SHMLOG_DATA), 256, fmt, ap); /* +1 for the NUL */
if (n > 255) n = vsnprintf((char *)(p + SHMLOG_DATA), mlen + 1, fmt, ap);
n = 255; /* we truncate long fields */ if (n > mlen)
n = mlen; /* we truncate long fields */
vsl_hdr(tag, p, n, id); vsl_hdr(tag, p, n, id);
w->wlp += SHMLOG_NEXTTAG + n; w->wlp += SHMLOG_NEXTTAG + n;
assert(w->wlp < w->wle); assert(w->wlp < w->wle);
......
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