r3829 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Thu Feb 26 13:22:50 CET 2009


Author: phk
Date: 2009-02-26 13:22:50 +0100 (Thu, 26 Feb 2009)
New Revision: 3829

Modified:
   trunk/varnish-cache/bin/varnishd/stevedore.c
   trunk/varnish-cache/bin/varnishd/storage_persistent.c
Log:
Add a alloc/free function.



Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c	2009-02-26 08:36:28 UTC (rev 3828)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c	2009-02-26 12:22:50 UTC (rev 3829)
@@ -55,6 +55,7 @@
 		if (stv == NULL)
 			stv = VTAILQ_FIRST(&stevedores);
 		AN(stv);
+		AN(stv->name);
 
 		 /* XXX: only safe as long as pointer writes are atomic */
 		stv_next = stv;
@@ -103,6 +104,8 @@
 	AN(stv);
 
 	*stv = *stv2;
+	AN(stv->name);
+	AN(stv->alloc);
 
 	if (stv->init != NULL)
 		stv->init(stv, ac, av);

Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_persistent.c	2009-02-26 08:36:28 UTC (rev 3828)
+++ trunk/varnish-cache/bin/varnishd/storage_persistent.c	2009-02-26 12:22:50 UTC (rev 3829)
@@ -64,6 +64,7 @@
 	VTAILQ_ENTRY(smp_seg)	list;
 	uint64_t		offset;
 	uint64_t		length;
+	struct smp_segment	segment;
 };
 
 struct smp_sc {
@@ -81,6 +82,8 @@
 	struct smp_ident	*ident;
 
 	VTAILQ_HEAD(, smp_seg)	segments;
+	struct smp_seg		*cur_seg;
+	uint64_t		next_addr;
 };
 
 /*--------------------------------------------------------------------
@@ -311,7 +314,7 @@
     "sizeof(%s) = %zu = 0x%zx\n", #foo, sizeof(foo), sizeof(foo));
 	SIZOF(struct smp_ident);
 	SIZOF(struct smp_sign);
-	SIZOF(struct smp_segment);
+	SIZOF(struct smp_segptr);
 	SIZOF(struct smp_object);
 #undef SIZOF
 
@@ -375,7 +378,7 @@
 static void
 smp_save_seg(struct smp_sc *sc, uint64_t adr, const char *id)
 {
-	struct smp_segment *ss;
+	struct smp_segptr *ss;
 	struct smp_seg *sg;
 	void *ptr;
 	uint64_t length;
@@ -411,7 +414,7 @@
 {
 	void *ptr;
 	uint64_t length;
-	struct smp_segment *ss;
+	struct smp_segptr *ss;
 	struct smp_seg *sg;
 
 	if (smp_open_sign(sc, sc->ident->stuff[stuff], &ptr, &length, id))
@@ -426,18 +429,44 @@
 		VTAILQ_INSERT_TAIL(&sc->segments, sg, list);
 fprintf(stderr, "RD SEG %jx %jx\n", sg->offset, sg->length);
 	}
-	if (VTAILQ_EMPTY(&sc->segments)) {
-		ALLOC_OBJ(sg, SMP_SEG_MAGIC);
-		AN(sg);
-		sg->offset = sc->ident->stuff[SMP_SPC_STUFF];
-		sg->length = sc->ident->stuff[SMP_END_STUFF] - sg->offset;
-		VTAILQ_INSERT_TAIL(&sc->segments, sg, list);
+	return (0);
+}
+
+/*--------------------------------------------------------------------
+ * Create a new segment
+ */
+
+static void
+smp_new_seg(struct smp_sc *sc)
+{
+	struct smp_seg *sg;
+	void *ptr;
+	uint64_t length;
+
+	ALLOC_OBJ(sg, SMP_SEG_MAGIC);
+	AN(sg);
+	/* XXX: find where */
+	sg->offset = sc->ident->stuff[SMP_SPC_STUFF];
+	sg->length = sc->ident->stuff[SMP_END_STUFF] - sg->offset;
+	VTAILQ_INSERT_TAIL(&sc->segments, sg, list);
 fprintf(stderr, "MK SEG %jx %jx\n", sg->offset, sg->length);
-	}
 
-	/* XXX: sanity check pointer+length for validity and non-overlap */
+	/* Neuter the new segment in case there is an old one there */
+	(void)smp_open_sign(sc, sg->offset, &ptr, &length, "SEGMENT");
+	memcpy(ptr, &sg->segment, sizeof sg->segment);
+	smp_create_sign(sc, sg->offset, sizeof sg->segment, "SEGMENT");
+	smp_sync_sign(sc, sg->offset, sizeof sg->segment);
 
-	return (0);
+	/* Then add it to the segment list. */
+	smp_save_segs(sc);
+
+	/* Set up our allocation point */
+	sc->cur_seg = sg;
+	sc->next_addr = sg->offset +
+	    sizeof (struct smp_sign) +
+	    sizeof (struct smp_segment) +
+	    SHA256_LEN;
+	memcpy(sc->ptr + sc->next_addr, "HERE", 4);
 }
 
 /*--------------------------------------------------------------------
@@ -463,9 +492,49 @@
 	 */
 	if (smp_open_segs(sc, SMP_SEG1_STUFF, "SEG 1"))
 		AZ(smp_open_segs(sc, SMP_SEG2_STUFF, "SEG 2"));
-	smp_save_segs(sc);
+
+	smp_new_seg(sc);
 }
 
+/*--------------------------------------------------------------------
+ * Allocate a bite
+ */
+
+static struct storage *
+smp_alloc(struct stevedore *st, size_t size)
+{
+	struct smp_sc *sc;
+	struct storage *ss;
+
+	CAST_OBJ_NOTNULL(sc, st->priv, SMP_SC_MAGIC);
+
+	/* XXX: size fit check */
+	AN(sc->next_addr);
+
+	/* Grab and fill a storage structure */
+	ss = (void *)(sc->ptr + sc->next_addr);
+	memset(ss, 0, sizeof *ss);
+	ss->magic = STORAGE_MAGIC;
+	ss->space = size;
+	ss->ptr = (void *)(ss + 1);
+	ss->priv = sc->cur_seg;			/* XXX ? */
+	ss->stevedore = st;
+	ss->fd = sc->fd;
+	ss->where = sc->next_addr + sizeof *ss;
+
+	sc->next_addr += size + sizeof *ss;
+	return (ss);
+}
+
+static void
+smp_free(struct storage *st)
+{
+
+	/* XXX */
+	(void)st;
+}
+
+
 /*--------------------------------------------------------------------*/
 
 struct stevedore smp_stevedore = {
@@ -473,7 +542,6 @@
 	.name	=	"persistent",
 	.init	=	smp_init,
 	.open	=	smp_open,
-	// .alloc	=	smf_alloc,
-	// .trim	=	smf_trim,
-	// .free	=	smf_free,
+	.alloc	=	smp_alloc,
+	.free	=	smp_free,
 };



More information about the varnish-commit mailing list