From e469b7edda7c3a78e34c15d78b8bceffc60df55b Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 26 Jun 2008 21:07:07 +0000 Subject: [PATCH] Add an undocumented debug facility that allows us to force a received object to be fragmented into smaller bits are out command. This is necessary to be able to write sensible testcases for the abilities of the ESI parsing code to navigate storage boundaries. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2836 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 1 + varnish-cache/bin/varnishd/cache_fetch.c | 51 ++++++++++++++++++++++++ varnish-cache/bin/varnishd/cache_main.c | 1 + 3 files changed, 53 insertions(+) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 5b2b3a6e..ebffdc03 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -454,6 +454,7 @@ int EXP_NukeOne(struct sess *sp); /* cache_fetch.c */ int Fetch(struct sess *sp); int FetchReqBody(struct sess *sp); +void Fetch_Init(void); /* cache_hash.c */ void HSH_Prealloc(struct sess *sp); diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 40c61d7c..05fdee25 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -40,6 +40,10 @@ #include "shmlog.h" #include "cache.h" #include "stevedore.h" +#include "cli.h" +#include "cli_priv.h" + +static unsigned fetchfrag; /*--------------------------------------------------------------------*/ @@ -199,6 +203,16 @@ fetch_chunked(struct sess *sp, struct http_conn *htc) /*--------------------------------------------------------------------*/ +static void +dump_st(struct sess *sp, struct storage *st) +{ + txt t; + + t.b = (void*)st->ptr; + t.e = (void*)(st->ptr + st->len); + WSLR(sp->wrk, SLT_Debug, sp->fd, t); +} + static int fetch_eof(struct sess *sp, struct http_conn *htc) { @@ -212,10 +226,14 @@ fetch_eof(struct sess *sp, struct http_conn *htc) st = NULL; while (1) { if (v == 0) { + if (st != NULL && fetchfrag > 0) + dump_st(sp, st); st = STV_alloc(sp, params->fetch_chunksize * 1024); VTAILQ_INSERT_TAIL(&sp->obj->store, st, list); p = st->ptr + st->len; v = st->space - st->len; + if (v > fetchfrag) + v = fetchfrag; } AN(p); AN(st); @@ -229,6 +247,8 @@ fetch_eof(struct sess *sp, struct http_conn *htc) st->len += i; sp->obj->len += i; } + if (st != NULL && fetchfrag > 0) + dump_st(sp, st); if (st->len == 0) { VTAILQ_REMOVE(&sp->obj->store, st, list); @@ -442,3 +462,34 @@ Fetch(struct sess *sp) return (0); } + +/*-------------------------------------------------------------------- + * Debugging aids + */ + +static void +debug_fragfetch(struct cli *cli, const char * const *av, void *priv) +{ + (void)priv; + (void)cli; + fetchfrag = strtoul(av[2], NULL, 0); +} + +static struct cli_proto debug_cmds[] = { + { "debug.fragfetch", "debug.fragfetch", + "\tEnable fetch fragmentation\n", 1, 1, debug_fragfetch }, + { NULL } +}; + +/*-------------------------------------------------------------------- + * + */ + +void +Fetch_Init(void) +{ + + CLI_AddFuncs(DEBUG_CLI, debug_cmds); +} + + diff --git a/varnish-cache/bin/varnishd/cache_main.c b/varnish-cache/bin/varnishd/cache_main.c index e0fa3dd3..533ae20f 100644 --- a/varnish-cache/bin/varnishd/cache_main.c +++ b/varnish-cache/bin/varnishd/cache_main.c @@ -72,6 +72,7 @@ child_main(void) THR_Name("cache-main"); CLI_Init(); + Fetch_Init(); CNT_Init(); VCL_Init(); -- 2.39.5