r170 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Jun 13 09:57:33 CEST 2006


Author: phk
Date: 2006-06-13 09:57:32 +0200 (Tue, 13 Jun 2006)
New Revision: 170

Added:
   trunk/varnish-cache/bin/varnishd/_stevedore.h
Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/cache_main.c
   trunk/varnish-cache/bin/varnishd/heritage.h
   trunk/varnish-cache/bin/varnishd/mgt.h
   trunk/varnish-cache/bin/varnishd/storage_malloc.c
   trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
Put more meat on the stevedore (storage backend) interface:

Pull the struct definition into _stevedore.h and include this from
cache.h and mgt.h, they both need to be able to see it.

Add the stevedore pointer as an argument to the stevedore alloc function
so multiple stevedores is possible later on.

Add the stevedore pointer to the storage object, so freeing it again is
possible.

Add -s argument processing to select a given stevedore, call it's ->init
method and pass the stevedore in the heritage.

In the cache process pick stevedore out from heritage, call its open method.




Added: trunk/varnish-cache/bin/varnishd/_stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/_stevedore.h	2006-06-13 07:26:20 UTC (rev 169)
+++ trunk/varnish-cache/bin/varnishd/_stevedore.h	2006-06-13 07:57:32 UTC (rev 170)
@@ -0,0 +1,21 @@
+/*
+ * $Id: cache.h 164 2006-05-01 12:45:20Z phk $
+ */
+
+struct stevedore;
+
+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 *);
+
+struct stevedore {
+	const char		*name;
+	storage_init_f		*init;	/* called by mgt process */
+	storage_open_f		*open;	/* called by cache process */
+	storage_alloc_f		*alloc;
+	storage_free_f		*free;
+
+	/* private fields */
+	void			*priv;
+};

Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-06-13 07:26:20 UTC (rev 169)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-06-13 07:57:32 UTC (rev 170)
@@ -42,21 +42,16 @@
 	unsigned char		*ptr;
 	unsigned		len;
 	void			*priv;
+	struct stevedore	*stevedore;
 };
 
-typedef void storage_init_f(void);
-typedef struct storage *storage_alloc_f(unsigned size);
-typedef void storage_free_f(struct storage *);
+#include "_stevedore.h"
 
-struct stevedore {
-	const char		*name;
-	storage_init_f		*init;
-	storage_alloc_f		*alloc;
-	storage_free_f		*free;
-};
-
-extern struct stevedore sma_stevedore;
-
+/*
+ * XXX: in the longer term, we want to support multiple stevedores,
+ * XXX: selected by some kind of heuristics based on size, lifetime
+ * XXX: etc etc.  For now we support only one.
+ */
 extern struct stevedore *stevedore;
 
 /* Prototypes etc ----------------------------------------------------*/

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-06-13 07:26:20 UTC (rev 169)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-06-13 07:57:32 UTC (rev 170)
@@ -33,7 +33,7 @@
 
 	cl = strtoumax(b, NULL, 0);
 
-	st = stevedore->alloc(cl);
+	st = stevedore->alloc(stevedore, cl);
 	TAILQ_INSERT_TAIL(&sp->obj->store, st, list);
 	st->len = cl;
 	sp->obj->len = cl;
@@ -104,7 +104,7 @@
 		q++;
 		if (u == 0)
 			break;
-		st = stevedore->alloc(u);
+		st = stevedore->alloc(stevedore, u);
 		TAILQ_INSERT_TAIL(&sp->obj->store, st, list);
 		st->len = u;
 		sp->obj->len += u;

Modified: trunk/varnish-cache/bin/varnishd/cache_main.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_main.c	2006-06-13 07:26:20 UTC (rev 169)
+++ trunk/varnish-cache/bin/varnishd/cache_main.c	2006-06-13 07:57:32 UTC (rev 170)
@@ -125,9 +125,9 @@
 	if (hash->init != NULL)
 		hash->init();
 
-	stevedore = &sma_stevedore;
-	if (stevedore->init != NULL)
-		stevedore->init();
+	stevedore = heritage.stevedore;
+	if (stevedore->open != NULL)
+		stevedore->open(stevedore);
 
 	CVCL_Load(heritage.vcl_file, "boot");
 	cli = cli_setup(eb, heritage.fds[2], heritage.fds[1], 0, cli_proto);

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h	2006-06-13 07:26:20 UTC (rev 169)
+++ trunk/varnish-cache/bin/varnishd/heritage.h	2006-06-13 07:57:32 UTC (rev 170)
@@ -18,15 +18,18 @@
 	 * interface IP number).
 	 */
 #define HERITAGE_NSOCKS		2	/* IPv4 + IPv6 */
-	int	sock_local[HERITAGE_NSOCKS];
-	int	sock_remote[HERITAGE_NSOCKS];
+	int			sock_local[HERITAGE_NSOCKS];
+	int			sock_remote[HERITAGE_NSOCKS];
 
 	/* Share memory log fd and size (incl header) */
-	int		vsl_fd;
-	unsigned	vsl_size;
+	int			vsl_fd;
+	unsigned		vsl_size;
 
 	/* Initial VCL file */
-	char		*vcl_file;
+	char			*vcl_file;
+
+	/* Storage method */
+	struct stevedore	*stevedore;
 };
 
 extern struct heritage heritage;

Modified: trunk/varnish-cache/bin/varnishd/mgt.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt.h	2006-06-13 07:26:20 UTC (rev 169)
+++ trunk/varnish-cache/bin/varnishd/mgt.h	2006-06-13 07:57:32 UTC (rev 170)
@@ -13,3 +13,7 @@
 
 /* tcp.c */
 int open_tcp(const char *port);
+
+#include "_stevedore.h"
+
+extern struct stevedore sma_stevedore;

Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_malloc.c	2006-06-13 07:26:20 UTC (rev 169)
+++ trunk/varnish-cache/bin/varnishd/storage_malloc.c	2006-06-13 07:57:32 UTC (rev 170)
@@ -17,7 +17,7 @@
 };
 
 static struct storage *
-sma_alloc(unsigned size)
+sma_alloc(struct stevedore *st __unused, unsigned size)
 {
 	struct sma *sma;
 
@@ -41,8 +41,9 @@
 }
 
 struct stevedore sma_stevedore = {
-	"Malloc",
+	"malloc",
 	NULL,			/* init */
+	NULL,			/* open */
 	sma_alloc,
 	sma_free
 };

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2006-06-13 07:26:20 UTC (rev 169)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2006-06-13 07:57:32 UTC (rev 170)
@@ -277,10 +277,12 @@
 usage(void)
 {
 	fprintf(stderr, "usage: varnishd [options]\n");
-	fprintf(stderr, "    %-20s # %s\n", "-b", "backend_IP_number");
-	fprintf(stderr, "    %-20s # %s\n", "-d", "debug");
-	fprintf(stderr, "    %-20s # %s\n", "-f", "VCL_file");
-	fprintf(stderr, "    %-20s # %s\n", "-p number", "TCP listen port");
+	fprintf(stderr, "    %-28s # %s\n", "-b", "backend_IP_number");
+	fprintf(stderr, "    %-28s # %s\n", "-d", "debug");
+	fprintf(stderr, "    %-28s # %s\n", "-f", "VCL_file");
+	fprintf(stderr, "    %-28s # %s\n", "-p number", "TCP listen port");
+	fprintf(stderr, "    %-28s # %s\n",
+	    "-s kind[,storageoptions]", "Backend storage specification");
 #if 0
 	-c clusterid at cluster_controller
 	-m memory_limit
@@ -294,6 +296,37 @@
 
 /*--------------------------------------------------------------------*/
 
+static int
+cmp_storage(struct stevedore *s, const char *p, const char *q)
+{
+	if (strlen(s->name) != q - p)
+		return (1);
+	if (strncmp(s->name, p, q - p))
+		return (1);
+	return (0);
+}
+
+static void
+setup_storage(const char *sflag)
+{
+	const char *p;
+
+	p = strchr(sflag, ',');
+	if (p == NULL)
+		p = strchr(sflag, '\0');
+	if (!cmp_storage(&sma_stevedore, sflag, p)) {
+		heritage.stevedore = &sma_stevedore;
+	} else {
+		fprintf(stderr, "Unknown storage method \"%*.*s\"\n",
+			p - sflag, p - sflag, sflag);
+		exit (2);
+	}
+	if (heritage.stevedore->init != NULL)
+		heritage.stevedore->init(heritage.stevedore, p);
+}
+
+/*--------------------------------------------------------------------*/
+
 #include "shmlog.h"
 
 static void
@@ -324,6 +357,7 @@
 	AZ(ftruncate(heritage.vsl_fd, sizeof slh + size));
 	heritage.vsl_size = slh.size + slh.start;
 }
+
 /*--------------------------------------------------------------------*/
 
 /* for development purposes */
@@ -338,6 +372,7 @@
 	unsigned dflag = 1;	/* XXX: debug=on for now */
 	const char *bflag = NULL;
 	const char *fflag = NULL;
+	const char *sflag = "malloc";
 
 	register_printf_render_std((const unsigned char *)"HVQ");
  
@@ -357,6 +392,9 @@
 		case 'p':
 			portnumber = optarg;
 			break;
+		case 's':
+			sflag = optarg;
+			break;
 		default:
 			usage();
 		}
@@ -385,6 +423,8 @@
 	if (heritage.vcl_file == NULL)
 		exit (1);
 
+	setup_storage(sflag);
+
 	/*
 	 * XXX: Lacking the suspend/resume facility (due to the socket API
 	 * missing an unlisten(2) facility) we may want to push this into
@@ -398,6 +438,5 @@
 
 	testme();
 
-
 	exit(0);
 }




More information about the varnish-commit mailing list