From 15da9f20b18ddcd4a03339161d0ea89310966354 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 18 Jun 2006 09:16:26 +0000 Subject: [PATCH] Add wrappers around VCL methos so logging and checking of returned handling can be centralized. Remove old handling callbacks. Call hit/miss methods instead of lookup method. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@198 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 4 ++ varnish-cache/bin/varnishd/cache_fetch.c | 5 +- varnish-cache/bin/varnishd/cache_pool.c | 32 +++-------- varnish-cache/bin/varnishd/cache_vcl.c | 71 ++++++++++++++++++------ 4 files changed, 69 insertions(+), 43 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index f547968e..10cfc696 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -120,6 +120,10 @@ void VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...); void RelVCL(struct VCL_conf *vc); struct VCL_conf *GetVCL(void); int CVCL_Load(const char *fn, const char *name); +void VCL_recv_method(struct sess *); +void VCL_hit_method(struct sess *); +void VCL_miss_method(struct sess *); +void VCL_fetch_method(struct sess *); #ifdef CLI_PRIV_H cli_func_t cli_func_config_list; cli_func_t cli_func_config_load; diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 87abf185..b227702f 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -242,10 +242,7 @@ FetchSession(struct worker *w, struct sess *sp) break; } - sp->handling = HND_Insert; - sp->vcl->fetch_func(sp); - - assert(sp->handling == HND_Insert); + VCL_fetch_method(sp); if (http_GetHdr(hp, "Content-Length", &b)) cls = fetch_straight(w, sp, fd, hp, b); diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index 6a08e6c4..8ef10d5c 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -23,6 +23,8 @@ static TAILQ_HEAD(, sess) shd = TAILQ_HEAD_INITIALIZER(shd); static pthread_cond_t shdcnd; +/*--------------------------------------------------------------------*/ + static int LookupSession(struct worker *w, struct sess *sp) { @@ -31,6 +33,7 @@ LookupSession(struct worker *w, struct sess *sp) MD5_CTX ctx; char *b; + /* Make sure worker thread has a fresh object at hand */ if (w->nobj == NULL) { w->nobj = calloc(sizeof *w->nobj, 1); assert(w->nobj != NULL); @@ -43,24 +46,15 @@ LookupSession(struct worker *w, struct sess *sp) MD5Update(&ctx, b, strlen(b)); MD5Final(key, &ctx); o = hash->lookup(key, w->nobj); + sp->obj = o; if (o == w->nobj) { VSL(SLT_Debug, 0, "Lookup new %p %s", o, b); w->nobj = NULL; + VCL_miss_method(sp); } else { + /* XXX: wait while obj->busy */ VSL(SLT_Debug, 0, "Lookup found %p %s", o, b); - } - /* - * XXX: if obj is busy, park session on it - */ - - sp->obj = o; - sp->handling = HND_Unclass; - sp->vcl->lookup_func(sp); - if (sp->handling == HND_Unclass) { - if (o->valid && o->cacheable) - sp->handling = HND_Deliver; - else - sp->handling = HND_Pass; + VCL_hit_method(sp); } return (0); } @@ -110,13 +104,7 @@ CacheWorker(void *priv) sp->backend = sp->vcl->default_backend; - /* - * Call the VCL recv function. - * Default action is to lookup - */ - sp->handling = HND_Lookup; - - sp->vcl->recv_func(sp); + VCL_recv_method(sp); for (done = 0; !done; ) { switch(sp->handling) { @@ -142,9 +130,7 @@ CacheWorker(void *priv) done = 1; break; default: - VSL(SLT_Handling, sp->fd, "Unclass"); - assert(sp->handling == HND_Unclass); - assert(sp->handling != HND_Unclass); + INCOMPL(); } } if (http_GetHdr(sp->http, "Connection", &b) && diff --git a/varnish-cache/bin/varnishd/cache_vcl.c b/varnish-cache/bin/varnishd/cache_vcl.c index 1e72f86c..0fdca8e0 100644 --- a/varnish-cache/bin/varnishd/cache_vcl.c +++ b/varnish-cache/bin/varnishd/cache_vcl.c @@ -190,22 +190,6 @@ cli_func_config_use(struct cli *cli, char **av, void *priv) /*--------------------------------------------------------------------*/ -void -VCL_pass(VCL_FARGS) -{ - - sess->handling = HND_Pass; - sess->done++; -} - -void VCL_insert(VCL_FARGS) { } -void VCL_deliver(VCL_FARGS) { } - -void VCL_fetch(VCL_FARGS) { - sess->handling = HND_Fetch; - sess->done++; -} - void VCL_error(VCL_FARGS, unsigned err, const char *str) { @@ -220,3 +204,58 @@ VCL_count(unsigned u) VSL(SLT_VCL, 0, "%u", u); } +/*--------------------------------------------------------------------*/ + +static const char * +HandlingName(unsigned u) +{ + + switch (u) { + case HND_Error: return ("Error"); + case HND_Pass: return ("Pass"); + case HND_Pipe: return ("Pipe"); + case HND_Lookup: return ("Lookup"); + case HND_Fetch: return ("Fetch"); + case HND_Insert: return ("Insert"); + case HND_Deliver: return ("Deliver"); + default: return (NULL); + } +} + +static void +CheckHandling(struct sess *sp, const char *func, unsigned bitmap) +{ + unsigned u; + const char *n; + + u = sp->handling; + n = HandlingName(u); + if (n != NULL) + VSL(SLT_Handling, sp->fd, "%s(): %s", func, n); + else + VSL(SLT_Handling, sp->fd, "%s(): Illegal: 0x%x", func, u); + if (u & (u - 1)) + VSL(SLT_Debug, sp->fd, + "Illegal handling after %s function: 0x%x", func, u); + else if (!(u & bitmap)) + VSL(SLT_Debug, sp->fd, + "Wrong handling after %s function: 0x%x", func, u); + else + return; + sp->handling = HND_Error; +} + +#define VCL_method(func, bitmap) \ +void \ +VCL_##func##_method(struct sess *sp) \ +{ \ + \ + sp->handling = 0; \ + sp->vcl->func##_func(sp); \ + CheckHandling(sp, #func, (bitmap)); \ +} + +VCL_method(recv, HND_Error|HND_Pass|HND_Pipe|HND_Lookup) +VCL_method(miss, HND_Error|HND_Pass|HND_Pipe|HND_Fetch) +VCL_method(hit, HND_Error|HND_Pass|HND_Pipe|HND_Deliver) +VCL_method(fetch, HND_Error|HND_Pass|HND_Pipe|HND_Insert) -- 2.39.5