r3897 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Mon Mar 9 10:46:04 CET 2009


Author: phk
Date: 2009-03-09 10:46:04 +0100 (Mon, 09 Mar 2009)
New Revision: 3897

Modified:
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_cli.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_main.c
   trunk/varnish-cache/bin/varnishd/hash_slinger.h
   trunk/varnish-cache/bin/varnishd/stevedore.c
   trunk/varnish-cache/bin/varnishd/stevedore.h
   trunk/varnish-cache/bin/varnishd/storage_file.c
   trunk/varnish-cache/bin/varnishd/storage_malloc.c
   trunk/varnish-cache/bin/varnishd/storage_persistent.c
   trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
Implement ->object and ->close methods of stevedores.



Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-03-09 09:46:04 UTC (rev 3897)
@@ -376,9 +376,8 @@
 static int
 cnt_fetch(struct sess *sp)
 {
-	int i;
+	int i, transient;
 	struct http *hp, *hp2;
-	struct object *o;
 	char *b;
 	unsigned handling;
 
@@ -456,17 +455,27 @@
 	 */
 	handling = sp->handling;
 
-	o = HSH_NewObject(sp, handling != VCL_RET_DELIVER);
+	if (sp->objhead == NULL)
+		transient = 1;
+	else if (sp->handling == VCL_RET_DELIVER)
+		transient = 0;
+	else
+		transient = 1;
 
+	/*
+	 * XXX: If we have a Length: header, we should allocate the body
+	 * XXX: also.
+ 	 */
+	sp->obj = HSH_NewObject(sp, transient);
+
 	if (sp->objhead != NULL) {
 		CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
 		CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
-		sp->objcore->obj = o;
-		o->objcore = sp->objcore;
-		o->objhead = sp->objhead;
+		sp->objcore->obj = sp->obj;
+		sp->obj->objcore = sp->objcore;
+		sp->obj->objhead = sp->objhead;
 		sp->objhead = NULL;	/* refcnt follows pointer. */
 	}
-	sp->obj = o;
 
 	BAN_NewObj(sp->obj);
 
@@ -509,6 +518,9 @@
 		return (0);
 	}
 
+	if (!transient)
+		HSH_Object(sp);
+
 	if (sp->wrk->do_esi)
 		ESI_Parse(sp);
 

Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_cli.c	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/cache_cli.c	2009-03-09 09:46:04 UTC (rev 3897)
@@ -160,7 +160,7 @@
 		if (pfd[0].revents & POLLHUP) {
 			fprintf(stderr,
 			    "EOF on CLI connection, exiting\n");
-			exit(0);
+			break;
 		}
 		i = VLU_Fd(heritage.cli_in, vlu);
 		if (i) {

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-03-09 09:46:04 UTC (rev 3897)
@@ -120,6 +120,21 @@
 	return (o);
 }
 
+/*
+ * XXX: this should vector through stevedore.c instead of calling the
+ * XXX: member function directly.
+ */
+
+void
+HSH_Object(const struct sess *sp)
+{
+	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->obj->objstore, STORAGE_MAGIC);
+	CHECK_OBJ_NOTNULL(sp->obj->objstore->stevedore, STEVEDORE_MAGIC);
+	if (sp->obj->objstore->stevedore->object != NULL)
+		sp->obj->objstore->stevedore->object(sp);
+}
+
 /* Precreate an objhead and object for later use */
 void
 HSH_Prealloc(const struct sess *sp)
@@ -649,7 +664,6 @@
 	HSH_DeleteObjHead(w, oh);
 }
 
-
 void
 HSH_Init(void)
 {

Modified: trunk/varnish-cache/bin/varnishd/cache_main.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_main.c	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/cache_main.c	2009-03-09 09:46:04 UTC (rev 3897)
@@ -133,5 +133,7 @@
 
 	CLI_Run();
 
+	STV_close();
+
 	printf("Child dies\n");
 }

Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_slinger.h	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/hash_slinger.h	2009-03-09 09:46:04 UTC (rev 3897)
@@ -51,6 +51,7 @@
 
 /* cache_hash.c */
 struct object *HSH_NewObject(struct sess *sp, int transient);
+void HSH_Object(const struct sess *sp);
 void HSH_Prealloc(const struct sess *sp);
 void HSH_Cleanup(struct worker *w);
 void HSH_Freestore(struct object *o);

Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c	2009-03-09 09:46:04 UTC (rev 3897)
@@ -92,7 +92,7 @@
 }
 
 void
-STV_trim(const struct storage *st, size_t size)
+STV_trim(struct storage *st, size_t size)
 {
 
 	CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
@@ -146,6 +146,17 @@
 	}
 }
 
+void
+STV_close(void)
+{
+	struct stevedore *stv;
+
+	VTAILQ_FOREACH(stv, &stevedores, list) {
+		if (stv->close != NULL)
+			stv->close(stv);
+	}
+}
+
 const struct choice STV_choice[] = {
 	{ "file",	&smf_stevedore },
 	{ "malloc",	&sma_stevedore },

Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h	2009-03-09 09:46:04 UTC (rev 3897)
@@ -39,9 +39,9 @@
 typedef void storage_init_f(struct stevedore *, int ac, char * const *av);
 typedef void storage_open_f(const struct stevedore *);
 typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
-typedef void storage_trim_f(const struct storage *, size_t size);
+typedef void storage_trim_f(struct storage *, size_t size);
 typedef void storage_free_f(struct storage *);
-typedef void storage_object_f(struct object *);
+typedef void storage_object_f(const struct sess *sp);
 typedef void storage_close_f(const struct stevedore *);
 
 struct stevedore {
@@ -63,10 +63,11 @@
 };
 
 struct storage *STV_alloc(struct sess *sp, size_t size);
-void STV_trim(const struct storage *st, size_t size);
+void STV_trim(struct storage *st, size_t size);
 void STV_free(struct storage *st);
 void STV_add(const struct stevedore *stv, int ac, char * const *av);
 void STV_open(void);
+void STV_close(void);
 
 int STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx);
 uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx);

Modified: trunk/varnish-cache/bin/varnishd/storage_file.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_file.c	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/storage_file.c	2009-03-09 09:46:04 UTC (rev 3897)
@@ -497,7 +497,7 @@
 /*--------------------------------------------------------------------*/
 
 static void
-smf_trim(const struct storage *s, size_t size)
+smf_trim(struct storage *s, size_t size)
 {
 	struct smf *smf;
 	struct smf_sc *sc;
@@ -518,7 +518,7 @@
 		trim_smf(smf, size);
 		assert(smf->size == size);
 		Lck_Unlock(&sc->mtx);
-		smf->s.space = size;
+		s->space = size;
 	}
 }
 

Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_malloc.c	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/storage_malloc.c	2009-03-09 09:46:04 UTC (rev 3897)
@@ -104,7 +104,7 @@
 }
 
 static void
-sma_trim(const struct storage *s, size_t size)
+sma_trim(struct storage *s, size_t size)
 {
 	struct sma *sma;
 	void *p;
@@ -119,7 +119,7 @@
 		sma->sz = size;
 		Lck_Unlock(&sma_mtx);
 		sma->s.ptr = p;
-		sma->s.space = size;
+		s->space = size;
 	}
 }
 

Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_persistent.c	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/storage_persistent.c	2009-03-09 09:46:04 UTC (rev 3897)
@@ -479,6 +479,7 @@
 	struct smp_sc	*sc;
 
 	CAST_OBJ_NOTNULL(sc, st->priv, SMP_SC_MAGIC);
+fprintf(stderr, "Open Silo(%p)\n", st);
 
 	/* We trust the parent to give us a valid silo, for good measure: */
 	AZ(smp_valid_silo(sc));
@@ -497,6 +498,26 @@
 }
 
 /*--------------------------------------------------------------------
+ * Close a silo
+ */
+
+static void
+smp_close(const struct stevedore *st)
+{
+fprintf(stderr, "Close Silo(%p)\n", st);
+}
+
+/*--------------------------------------------------------------------
+ * Designate object
+ */
+
+static void
+smp_object(const struct sess *sp)
+{
+fprintf(stderr, "Object(%p %p)\n", sp, sp->obj);
+}
+
+/*--------------------------------------------------------------------
  * Allocate a bite
  */
 
@@ -517,16 +538,36 @@
 	ss->magic = STORAGE_MAGIC;
 	ss->space = size;
 	ss->ptr = (void *)(ss + 1);
-	ss->priv = sc->cur_seg;			/* XXX ? */
+	ss->priv = sc;
 	ss->stevedore = st;
 	ss->fd = sc->fd;
 	ss->where = sc->next_addr + sizeof *ss;
 
 	sc->next_addr += size + sizeof *ss;
+	memcpy(sc->ptr + sc->next_addr, "HERE", 4);
 	return (ss);
 }
 
 static void
+smp_trim(struct storage *ss, size_t size)
+{
+	struct smp_sc *sc;
+
+fprintf(stderr, "Trim(%p %u)\n", ss, size);
+	CAST_OBJ_NOTNULL(sc, ss->priv, SMP_SC_MAGIC);
+
+	/* We want 16 bytes alignment */
+	size |= 0xf;
+	size += 1;
+
+	if (ss->ptr + ss->space == sc->next_addr + sc->ptr) {
+		sc->next_addr -= ss->space - size;
+		ss->space = size;
+		memcpy(sc->ptr + sc->next_addr, "HERE", 4);
+	}
+}
+
+static void
 smp_free(struct storage *st)
 {
 
@@ -542,6 +583,9 @@
 	.name	=	"persistent",
 	.init	=	smp_init,
 	.open	=	smp_open,
+	.close	=	smp_close,
 	.alloc	=	smp_alloc,
+	.object	=	smp_object,
 	.free	=	smp_free,
+	.trim	=	smp_trim,
 };

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c	2009-03-06 09:47:18 UTC (rev 3896)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c	2009-03-09 09:46:04 UTC (rev 3897)
@@ -82,7 +82,7 @@
 unsigned		d_flag = 0;
 pid_t			mgt_pid;
 struct vev_base		*mgt_evb;
-int			exit_status;
+int			exit_status = 0;
 
 /*--------------------------------------------------------------------*/
 



More information about the varnish-commit mailing list