From d991a8f6929503b8a6ecead6919d39fdbee2de0e Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 24 Nov 2008 15:53:26 +0000 Subject: [PATCH] Make the maximum record length in the shm log a paramter "shm_reclen". git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3428 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/heritage.h | 2 ++ varnish-cache/bin/varnishd/mgt_param.c | 5 ++++ varnish-cache/bin/varnishd/shmlog.c | 40 +++++++++++++++----------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index a044964b..8be6f7af 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -98,6 +98,8 @@ struct params { unsigned obj_workspace; unsigned shm_workspace; + unsigned shm_reclen; + /* Acceptor hints */ unsigned sess_timeout; unsigned pipe_timeout; diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index c59680ef..060d305c 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -636,6 +636,11 @@ static const struct parspec parspec[] = { "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 " diff --git a/varnish-cache/bin/varnishd/shmlog.c b/varnish-cache/bin/varnishd/shmlog.c index 0387a572..7794a334 100644 --- a/varnish-cache/bin/varnishd/shmlog.c +++ b/varnish-cache/bin/varnishd/shmlog.c @@ -81,6 +81,8 @@ static void 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 @@ static void 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 @@ VSL(enum shmlogtag tag, int id, const char *fmt, ...) { 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 @@ VSL(enum shmlogtag tag, int id, const char *fmt, ...) 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 @@ void 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 @@ WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...) { 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 @@ WSL(struct worker *w, enum shmlogtag tag, int id, const char *fmt, ...) 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); -- 2.39.5