r426 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Jul 11 14:31:45 CEST 2006


Author: phk
Date: 2006-07-11 14:31:44 +0200 (Tue, 11 Jul 2006)
New Revision: 426

Added:
   trunk/varnish-cache/bin/varnishd/cache_center.c
Modified:
   trunk/varnish-cache/bin/varnishd/Makefile.am
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_pool.c
Log:
Start centralizing the flow of requests through varnish so we get
one source file with the highest level of policy.



Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am	2006-07-11 12:30:23 UTC (rev 425)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am	2006-07-11 12:31:44 UTC (rev 426)
@@ -17,6 +17,7 @@
 	cache_acceptor.c \
 	cache_backend.c \
 	cache_ban.c \
+	cache_center.c \
 	cache_expire.c \
 	cache_fetch.c \
 	cache_hash.c \

Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-07-11 12:30:23 UTC (rev 425)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-07-11 12:31:44 UTC (rev 426)
@@ -205,6 +205,9 @@
 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);

Added: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2006-07-11 12:30:23 UTC (rev 425)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2006-07-11 12:31:44 UTC (rev 426)
@@ -0,0 +1,108 @@
+/*
+ * $Id$
+ *
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sbuf.h>
+
+#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);
+}

Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-07-11 12:30:23 UTC (rev 425)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-07-11 12:31:44 UTC (rev 426)
@@ -28,97 +28,6 @@
 
 /*--------------------------------------------------------------------*/
 
-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 @@
 			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);




More information about the varnish-commit mailing list