r180 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Jun 14 09:21:48 CEST 2006


Author: phk
Date: 2006-06-14 09:21:48 +0200 (Wed, 14 Jun 2006)
New Revision: 180

Modified:
   trunk/varnish-cache/bin/varnishd/cache_pool.c
   trunk/varnish-cache/bin/varnishd/stevedore.h
   trunk/varnish-cache/bin/varnishd/storage_file.c
Log:
Give storage backends a "send" method.

Let storage_file use sendfile(2) for it.



Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-06-14 06:58:55 UTC (rev 179)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c	2006-06-14 07:21:48 UTC (rev 180)
@@ -78,8 +78,12 @@
 	    "\r\n", sp->obj->len);
 
 	vca_write(sp, buf, strlen(buf));
-	TAILQ_FOREACH(st, &sp->obj->store, list)
-		vca_write(sp, st->ptr, st->len);
+	TAILQ_FOREACH(st, &sp->obj->store, list) {
+		if (st->stevedore->send != NULL)
+			st->stevedore->send(st, sp);
+		else
+			vca_write(sp, st->ptr, st->len);
+	}
 	vca_flush(sp);
 	return (1);
 }

Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h	2006-06-14 06:58:55 UTC (rev 179)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h	2006-06-14 07:21:48 UTC (rev 180)
@@ -3,11 +3,13 @@
  */
 
 struct stevedore;
+struct sess;
 
 typedef void storage_init_f(struct stevedore *, const char *spec);
 typedef void storage_open_f(struct stevedore *);
 typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
 typedef void storage_free_f(struct storage *);
+typedef void storage_send_f(struct storage *, struct sess *);
 
 struct stevedore {
 	const char		*name;
@@ -15,6 +17,7 @@
 	storage_open_f		*open;	/* called by cache process */
 	storage_alloc_f		*alloc;
 	storage_free_f		*free;
+	storage_send_f		*send;
 
 	/* private fields */
 	void			*priv;

Modified: trunk/varnish-cache/bin/varnishd/storage_file.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_file.c	2006-06-14 06:58:55 UTC (rev 179)
+++ trunk/varnish-cache/bin/varnishd/storage_file.c	2006-06-14 07:21:48 UTC (rev 180)
@@ -19,6 +19,7 @@
 #include <sys/param.h>
 #include <sys/mount.h>
 #include <sys/mman.h>
+#include <sys/socket.h>
 
 #include "vcl_lang.h"
 #include "libvarnish.h"
@@ -409,7 +410,7 @@
 
 	if (sz < *fail && sz < SIZE_T_MAX) {
 		p = mmap(NULL, sz, PROT_READ|PROT_WRITE,
-		    MAP_NOCORE | MAP_NOSYNC | MAP_PRIVATE, sc->fd, off);
+		    MAP_NOCORE | MAP_NOSYNC | MAP_SHARED, sc->fd, off);
 		if (p != MAP_FAILED) {
 			(*sum) += sz;
 			new_smf(sc, p, off, sz);
@@ -459,9 +460,12 @@
 	smf->s.priv = smf;
 	smf->s.ptr = smf->ptr;
 	smf->s.len = size;
+	smf->s.stevedore = st;
 	return (&smf->s);
 }
 
+/*--------------------------------------------------------------------*/
+
 static void
 smf_free(struct storage *s)
 {
@@ -471,10 +475,34 @@
 	free_smf(smf);
 }
 
+/*--------------------------------------------------------------------*/
+
+static void
+smf_send(struct storage *st, struct sess *sp)
+{
+	struct smf *smf;
+	int i;
+	off_t sent;
+
+	smf = st->priv;
+
+	printf("SEND   %12p  %12p %12jx %12jx\n", (void*)smf, (void*)smf->ptr, (uintmax_t)smf->offset, (uintmax_t)smf->size);
+	vca_flush(sp);
+	i = sendfile(smf->sc->fd,
+	    sp->fd,
+	    smf->offset,
+	    st->len, NULL, &sent, 0);
+	printf("sent i=%d sent=%ju size=%ju\n",
+	    i, (uintmax_t)sent, (uintmax_t)st->len);
+}
+
+/*--------------------------------------------------------------------*/
+
 struct stevedore smf_stevedore = {
 	"file",
 	smf_init,
 	smf_open,
 	smf_alloc,
-	smf_free
+	smf_free,
+	smf_send
 };




More information about the varnish-commit mailing list