r5539 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Mon Nov 15 11:19:52 CET 2010


Author: phk
Date: 2010-11-15 11:19:52 +0100 (Mon, 15 Nov 2010)
New Revision: 5539

Modified:
   trunk/varnish-cache/bin/varnishd/stevedore.c
   trunk/varnish-cache/bin/varnishd/stevedore.h
   trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
Complain if stevedores do not have unique names.

Add a stevedore named "Transient" if the user did not already do that.
By default it is a size-unconstrained -smalloc.

Do not select the stevedore named "Transient" automatically.



Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c	2010-11-11 11:31:54 UTC (rev 5538)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c	2010-11-15 10:19:52 UTC (rev 5539)
@@ -24,6 +24,11 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * STEVEDORE: one who works at or is responsible for loading and
+ * unloading ships in port.  Example: "on the wharves, stevedores were
+ * unloading cargo from the far corners of the world." Origin: Spanish
+ * estibador, from estibar to pack.  First Known Use: 1788
  */
 
 #include "config.h"
@@ -40,6 +45,8 @@
 #include "stevedore.h"
 #include "cli_priv.h"
 
+#define TRANSIENT_NAME	"Transient"
+
 static VTAILQ_HEAD(, stevedore)	stevedores =
     VTAILQ_HEAD_INITIALIZER(stevedores);
 
@@ -82,6 +89,8 @@
 	AN(stv);
 	AN(stv->name);
 	stv_next = stv;
+	if (stv->transient)
+		stv = stv_pick_stevedore();
 	return (stv);
 }
 
@@ -254,10 +263,13 @@
 	{ NULL,		NULL }
 };
 
-/*--------------------------------------------------------------------*/
+/*--------------------------------------------------------------------
+ * Parse a stevedore argument on the form:
+ *	[ name '=' ] strategy [ ',' arg ] *
+ */
 
 void
-STV_config(const char *spec)
+STV_Config(const char *spec)
 {
 	char **av;
 	const char *p, *q;
@@ -281,7 +293,7 @@
 		ARGV_ERR("%s\n", av[0]);
 
 	if (av[1] == NULL)
-		ARGV_ERR("-s argument is empty\n");
+		ARGV_ERR("-s argument lacks strategy {malloc, file, ...}\n");
 
 	for (ac = 0; av[ac + 2] != NULL; ac++)
 		continue;
@@ -289,7 +301,7 @@
 	stv2 = pick(STV_choice, av[1], "storage");
 	AN(stv2);
 
-	/* Append to ident string */
+	/* Append strategy to ident string */
 	vsb_printf(vident, ",-s%s", av[1]);
 
 	av += 2;
@@ -308,9 +320,19 @@
 		l = p - spec;
 		if (l > sizeof stv->ident - 1)
 			l = sizeof stv->ident - 1;
-		bprintf(stv->ident, "%*.*s", l, l, spec);
+		bprintf(stv->ident, "%.*s", l, spec);
 	}
 
+	if (!strcmp(stv->ident, TRANSIENT_NAME))
+		stv->transient = 1;
+
+	VTAILQ_FOREACH(stv2, &stevedores, list) {
+		if (strcmp(stv2->ident, stv->ident))
+			continue;
+		ARGV_ERR("(-s%s=%s) already defined once\n",
+		    stv->ident, stv->name);
+	}
+
 	stv->lru = LRU_Alloc();
 
 	if (stv->init != NULL)
@@ -326,6 +348,19 @@
 
 /*--------------------------------------------------------------------*/
 
+void
+STV_Config_Transient(void)
+{
+	const struct stevedore *stv;
+
+	VTAILQ_FOREACH(stv, &stevedores, list)
+		if (!strcmp(stv->name, TRANSIENT_NAME))
+			return;
+	STV_Config(TRANSIENT_NAME "=malloc");
+}
+
+/*--------------------------------------------------------------------*/
+
 static void
 stv_cli_list(struct cli *cli, const char * const *av, void *priv)
 {
@@ -347,4 +382,3 @@
 	    0, 0, "", stv_cli_list },
 	{ NULL}
 };
-

Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h	2010-11-11 11:31:54 UTC (rev 5538)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h	2010-11-15 10:19:52 UTC (rev 5539)
@@ -49,6 +49,7 @@
 	unsigned		magic;
 #define STEVEDORE_MAGIC		0x4baf43db
 	const char		*name;
+	unsigned		transient;
 	storage_init_f		*init;		/* called by mgt process */
 	storage_open_f		*open;		/* called by cache process */
 	storage_alloc_f		*alloc;		/* --//-- */
@@ -63,7 +64,7 @@
 	void			*priv;
 
 	VTAILQ_ENTRY(stevedore)	list;
-	char			ident[16];
+	char			ident[16];	/* XXX: match vsm_chunk.ident */
 };
 
 struct object *STV_NewObject(struct sess *sp, unsigned len, double ttl,
@@ -73,8 +74,9 @@
 void STV_free(struct storage *st);
 void STV_open(void);
 void STV_close(void);
-void STV_config(const char *spec);
 struct lru *STV_lru(const struct storage *st);
+void STV_Config(const char *spec);
+void STV_Config_Transient(void);
 
 struct lru *LRU_Alloc(void);
 

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2010-11-11 11:31:54 UTC (rev 5538)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2010-11-15 10:19:52 UTC (rev 5539)
@@ -478,7 +478,7 @@
 			break;
 		case 's':
 			s_arg_given = 1;
-			STV_config(optarg);
+			STV_Config(optarg);
 			break;
 		case 't':
 			MCF_ParamSet(cli, "default_ttl", optarg);
@@ -601,9 +601,13 @@
 	if (C_flag)
 		exit (0);
 
+	/* If no -s argument specified, process default -s argument */
 	if (!s_arg_given)
-		STV_config(s_arg);
+		STV_Config(s_arg);
 
+	/* Configure Transient storage, if user did not */
+	STV_Config_Transient();
+
 	HSH_config(h_arg);
 
 	mgt_SHM_Init(l_arg);




More information about the varnish-commit mailing list