From: phk Date: Tue, 11 Jul 2006 12:31:44 +0000 (+0000) Subject: Start centralizing the flow of requests through varnish so we get X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd125ebfb4c3be86ededc131a748370dd84e63b4;p=varnish Start centralizing the flow of requests through varnish so we get one source file with the highest level of policy. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@426 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/Makefile.am b/varnish-cache/bin/varnishd/Makefile.am index c2638717..3e24cc31 100644 --- a/varnish-cache/bin/varnishd/Makefile.am +++ b/varnish-cache/bin/varnishd/Makefile.am @@ -17,6 +17,7 @@ varnishd_SOURCES = \ cache_acceptor.c \ cache_backend.c \ cache_ban.c \ + cache_center.c \ cache_expire.c \ cache_fetch.c \ cache_hash.c \ diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index cd3b5ac6..8ab94f67 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -205,6 +205,9 @@ void cli_func_url_purge(struct cli *cli, char **av, void *priv); void BAN_NewObj(struct object *o); int BAN_CheckObject(struct object *o, const char *url); +/* cache_center.c [CNT] */ +void CNT_Session(struct worker *w, struct sess *sp); + /* cache_expiry.c */ void EXP_Insert(struct object *o); void EXP_Init(void); diff --git a/varnish-cache/bin/varnishd/cache_center.c b/varnish-cache/bin/varnishd/cache_center.c new file mode 100644 index 00000000..fdf95648 --- /dev/null +++ b/varnish-cache/bin/varnishd/cache_center.c @@ -0,0 +1,108 @@ +/* + * $Id$ + * + */ + +#include +#include +#include +#include +#include +#include + +#include "libvarnish.h" +#include "heritage.h" +#include "shmlog.h" +#include "vcl.h" +#include "cache.h" + +/*--------------------------------------------------------------------*/ + +static int +LookupSession(struct worker *w, struct sess *sp) +{ + struct object *o; + + o = HSH_Lookup(w, sp->http); + sp->obj = o; + if (o->busy) { + VSL_stats->cache_miss++; + VCL_miss_method(sp); + } else { + VSL_stats->cache_hit++; + VSL(SLT_Hit, sp->fd, "%u", o->xid); + VCL_hit_method(sp); + } + return (0); +} + +static int +DeliverSession(struct worker *w, struct sess *sp) +{ + + + vca_write_obj(w, sp); + HSH_Deref(sp->obj); + sp->obj = NULL; + return (1); +} + +void +CNT_Session(struct worker *w, struct sess *sp) +{ + int done; + char *b; + + time(&sp->t0); + AZ(pthread_mutex_lock(&sessmtx)); + sp->vcl = GetVCL(); + AZ(pthread_mutex_unlock(&sessmtx)); + + done = http_DissectRequest(sp->http, sp->fd); + if (done != 0) { + RES_Error(w, sp, done, NULL); + goto out; + } + + sp->backend = sp->vcl->backend[0]; + + VCL_recv_method(sp); + + for (done = 0; !done; ) { + switch(sp->handling) { + case VCL_RET_LOOKUP: + done = LookupSession(w, sp); + break; + case VCL_RET_FETCH: + done = FetchSession(w, sp); + break; + case VCL_RET_DELIVER: + done = DeliverSession(w, sp); + break; + case VCL_RET_PIPE: + PipeSession(w, sp); + done = 1; + break; + case VCL_RET_PASS: + PassSession(w, sp); + done = 1; + break; + default: + INCOMPL(); + } + } + if (http_GetHdr(sp->http, "Connection", &b) && + !strcmp(b, "close")) { + vca_close_session(sp, "Connection header"); + } else if (http_GetProto(sp->http, &b) && + strcmp(b, "HTTP/1.1")) { + vca_close_session(sp, "not HTTP/1.1"); + } + +out: + AZ(pthread_mutex_lock(&sessmtx)); + RelVCL(sp->vcl); + AZ(pthread_mutex_unlock(&sessmtx)); + sp->vcl = NULL; + vca_return_session(sp); +} diff --git a/varnish-cache/bin/varnishd/cache_pool.c b/varnish-cache/bin/varnishd/cache_pool.c index d4663777..f7f466f2 100644 --- a/varnish-cache/bin/varnishd/cache_pool.c +++ b/varnish-cache/bin/varnishd/cache_pool.c @@ -28,97 +28,6 @@ static TAILQ_HEAD(, workreq) wrk_reqhead = TAILQ_HEAD_INITIALIZER(wrk_reqhead); /*--------------------------------------------------------------------*/ -static int -LookupSession(struct worker *w, struct sess *sp) -{ - struct object *o; - - o = HSH_Lookup(w, sp->http); - sp->obj = o; - if (o->busy) { - VSL_stats->cache_miss++; - VCL_miss_method(sp); - } else { - VSL_stats->cache_hit++; - VSL(SLT_Hit, sp->fd, "%u", o->xid); - VCL_hit_method(sp); - } - return (0); -} - -static int -DeliverSession(struct worker *w, struct sess *sp) -{ - - - vca_write_obj(w, sp); - HSH_Deref(sp->obj); - sp->obj = NULL; - return (1); -} - -static void -wrk_WorkSession(struct worker *w, struct sess *sp) -{ - int done; - char *b; - - time(&sp->t0); - AZ(pthread_mutex_lock(&sessmtx)); - sp->vcl = GetVCL(); - AZ(pthread_mutex_unlock(&sessmtx)); - - done = http_DissectRequest(sp->http, sp->fd); - if (done != 0) { - RES_Error(w, sp, done, NULL); - goto out; - } - - sp->backend = sp->vcl->backend[0]; - - VCL_recv_method(sp); - - for (done = 0; !done; ) { - switch(sp->handling) { - case VCL_RET_LOOKUP: - done = LookupSession(w, sp); - break; - case VCL_RET_FETCH: - done = FetchSession(w, sp); - break; - case VCL_RET_DELIVER: - done = DeliverSession(w, sp); - break; - case VCL_RET_PIPE: - PipeSession(w, sp); - done = 1; - break; - case VCL_RET_PASS: - PassSession(w, sp); - done = 1; - break; - default: - INCOMPL(); - } - } - if (http_GetHdr(sp->http, "Connection", &b) && - !strcmp(b, "close")) { - vca_close_session(sp, "Connection header"); - } else if (http_GetProto(sp->http, &b) && - strcmp(b, "HTTP/1.1")) { - vca_close_session(sp, "not HTTP/1.1"); - } - -out: - AZ(pthread_mutex_lock(&sessmtx)); - RelVCL(sp->vcl); - AZ(pthread_mutex_unlock(&sessmtx)); - sp->vcl = NULL; - vca_return_session(sp); -} - -/*--------------------------------------------------------------------*/ - static void * wrk_thread(void *priv) { @@ -154,7 +63,7 @@ wrk_thread(void *priv) TAILQ_REMOVE(&wrk_reqhead, wrq, list); AZ(pthread_mutex_unlock(&wrk_mtx)); assert(wrq->sess != NULL); - wrk_WorkSession(w, wrq->sess); + CNT_Session(w, wrq->sess); AZ(pthread_mutex_lock(&wrk_mtx)); VSL_stats->n_wrk_busy--; TAILQ_INSERT_HEAD(&wrk_head, w, list);