r5562 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Sun Nov 21 00:23:07 CET 2010


Author: phk
Date: 2010-11-21 00:23:07 +0100 (Sun, 21 Nov 2010)
New Revision: 5562

Modified:
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/stevedore.c
   trunk/varnish-cache/bin/varnishd/stevedore.h
   trunk/varnish-cache/bin/varnishd/storage_persistent.c
Log:
Collapse the object allocation/creation to a 1-phase process which
simplifies stuff somewhat for the main code and remains the same
tricky business for -spersistent.



Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2010-11-20 22:23:56 UTC (rev 5561)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2010-11-20 23:23:07 UTC (rev 5562)
@@ -586,7 +586,6 @@
 	sp->obj->xid = sp->xid;
 	sp->obj->response = sp->err_code;
 	sp->obj->cacheable = sp->wrk->cacheable;
-	sp->obj->ttl = sp->wrk->ttl;
 	sp->obj->grace = sp->wrk->grace;
 	if (sp->obj->ttl == 0. && sp->obj->grace == 0.)
 		sp->obj->cacheable = 0;
@@ -594,6 +593,7 @@
 	sp->obj->entered = sp->wrk->entered;
 	WS_Assert(sp->obj->ws_o);
 
+
 	/* Filter into object */
 	hp = sp->wrk->beresp;
 	hp2 = sp->obj->http;
@@ -625,14 +625,6 @@
 		return (0);
 	}
 
-	if (sp->wrk->cacheable) {
-		/*
-		 * Needs ttl & ban to be in order.
-		 * XXX call oc->updatemeta() instead ?
-		 */
-		STV_Object(sp);
-	}
-
 	if (sp->wrk->do_esi)
 		ESI_Parse(sp);
 

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2010-11-20 22:23:56 UTC (rev 5561)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2010-11-20 23:23:07 UTC (rev 5562)
@@ -96,7 +96,6 @@
 		ALLOC_OBJ(oc, OBJCORE_MAGIC);
 		XXXAN(oc);
 		w->nobjcore = oc;
-		oc->methods = &default_oc_methods;
 		w->stats.n_objectcore++;
 		oc->flags |= OC_F_BUSY;
 	}

Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c	2010-11-20 22:23:56 UTC (rev 5561)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c	2010-11-20 23:23:07 UTC (rev 5562)
@@ -167,7 +167,7 @@
 
 struct object *
 STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
-    struct stv_objsecrets *soc)
+    const struct stv_objsecrets *soc)
 {
 	struct object *o;
 	unsigned l;
@@ -195,18 +195,22 @@
 	o->http->magic = HTTP_MAGIC;
 	o->grace = NAN;
 	o->entered = NAN;
+	o->ttl = soc->ttl;
 	VTAILQ_INIT(&o->store);
 	sp->wrk->stats.n_object++;
 
 	if (sp->objhead != NULL) {
 		CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
 		CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
-		sp->objcore->priv = o; /* XXX */
+
 		o->objcore = sp->objcore;
 		sp->objcore->objhead = sp->objhead;
 		sp->objhead = NULL;     /* refcnt follows pointer. */
 		sp->objcore = NULL;     /* refcnt follows pointer. */
 		BAN_NewObj(o);
+
+		o->objcore->methods = &default_oc_methods;
+		o->objcore->priv = o;
 	}
 	return (o);
 }
@@ -218,7 +222,7 @@
 
 static struct object *
 stv_default_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
-    struct stv_objsecrets *soc)
+    const struct stv_objsecrets *soc)
 {
 	struct object *o;
 	struct storage *st;
@@ -304,17 +308,6 @@
 	.freeobj = default_oc_freeobj,
 };
 
-void
-STV_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);
-	AssertObjBusy(sp->obj);
-	if (sp->obj->objstore->stevedore->object != NULL)
-		sp->obj->objstore->stevedore->object(sp);
-}
-
 /*********************************************************************/
 
 struct storage *

Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h	2010-11-20 22:23:56 UTC (rev 5561)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h	2010-11-20 23:23:07 UTC (rev 5562)
@@ -41,9 +41,8 @@
 typedef struct storage *storage_alloc_f(struct stevedore *, 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(const struct sess *sp);
 typedef struct object *storage_allocobj_f(struct stevedore *, struct sess *sp,
-    unsigned ltot, struct stv_objsecrets *);
+    unsigned ltot, const struct stv_objsecrets *);
 typedef void storage_close_f(const struct stevedore *);
 
 
@@ -57,7 +56,6 @@
 	storage_alloc_f		*alloc;		/* --//-- */
 	storage_trim_f		*trim;		/* --//-- */
 	storage_free_f		*free;		/* --//-- */
-	storage_object_f	*object;	/* --//-- */
 	storage_close_f		*close;		/* --//-- */
 	storage_allocobj_f	*allocobj;	/* --//-- */
 
@@ -71,7 +69,7 @@
 };
 
 struct object *STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
-    struct stv_objsecrets *soc);
+    const struct stv_objsecrets *soc);
 
 struct object *STV_NewObject(struct sess *sp, unsigned len, double ttl,
     unsigned nhttp);
@@ -83,7 +81,6 @@
 struct lru *STV_lru(const struct storage *st);
 void STV_Config(const char *spec);
 void STV_Config_Transient(void);
-void STV_Object(const struct sess *sp);
 
 struct lru *LRU_Alloc(void);
 

Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_persistent.c	2010-11-20 22:23:56 UTC (rev 5561)
+++ trunk/varnish-cache/bin/varnishd/storage_persistent.c	2010-11-20 23:23:07 UTC (rev 5562)
@@ -1286,11 +1286,15 @@
 }
 
 /*--------------------------------------------------------------------
- * Allocate a bite
+ * Allocate a bite, possibly for an object.
+ *
+ * if the segment pointer is provided, we are allocating for an object
+ * structure, and should reserve space for the smp_object structure in
+ * the index.  This complicates things somewhat.
  */
 
 static struct storage *
-smp_allocx(struct stevedore *st, size_t size, struct objcore *oc)
+smp_allocx(struct stevedore *st, size_t size, struct smp_seg **sgp)
 {
 	struct smp_sc *sc;
 	struct storage *ss;
@@ -1310,17 +1314,16 @@
 
 		overhead = C_ALIGN(sizeof *ss);
 		overhead += SEG_SPACE * 2;
-		if (oc == NULL) {
+		if (sgp == NULL) {
 			overhead += C_ALIGN(sc->objreserv);
 		} else {
-			CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 			overhead +=
 			    C_ALIGN(sizeof(struct smp_object) + sc->objreserv);
 		}
 		needed = overhead + size;
 		left = smp_spaceleft(sg);
 
-		if (oc == NULL && needed > left && (overhead + 4096) < left) {
+		if (sgp == NULL && needed > left && (overhead + 4096) < left) {
 			/* XXX: Also check the bit we cut off isn't silly
 			 * short
 			 */
@@ -1337,7 +1340,7 @@
 
 		/* If there is space, fine */
 		if (needed <= left &&
-		    (oc == NULL || sg->nalloc1 < sc->aim_nobj))
+		    (sgp == NULL || sg->nalloc1 < sc->aim_nobj))
 			break;
 
 		smp_close_seg(sc, sc->cur_seg);
@@ -1364,13 +1367,21 @@
 	/* Paint our marker */
 	memcpy(sc->ptr + sg->next_addr, "HERE", 4);
 
-	if (oc != NULL) {
+	if (sgp != NULL) {
 		/* Make reservation in the index */
 		assert(sg->nalloc1 < sc->aim_nobj);
 		sg->nalloc1++;
 		sc->objreserv += sizeof (struct smp_object);
 		assert(sc->objreserv <= smp_spaceleft(sg));
-		oc->priv2 = sg;
+		/*
+		 * NB: Tricky.
+		 * We can not use the smp_getobj() method yet, because the
+		 * smp_object's position is not finalized until the segment
+		 * closes.  Fortunately we don't need to either, because newly
+		 * created objects will never regress into NEEDFIXUP state, 
+		 * so the default oc->methods, will do just fine.
+		 */
+		*sgp = sg;
 	}
 
 	sg->nalloc++;
@@ -1398,57 +1409,52 @@
 
 static struct object *
 smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
-    struct stv_objsecrets *soc)
+    const struct stv_objsecrets *soc)
 {
 	struct object *o;
 	struct storage *st;
-
-	st = smp_allocx(stv, ltot, sp->objcore);
-	XXXAN(st);
-	xxxassert(st->space >= ltot);
-	ltot = st->len = st->space;
-	o = STV_MkObject(sp, st->ptr, ltot, soc);
-	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-	o->objstore = st;
-	return (o);
-}
-
-
-/*--------------------------------------------------------------------
- * Designate object
- */
-
-static void
-smp_object(const struct sess *sp)
-{
 	struct smp_sc	*sc;
 	struct smp_seg *sg;
 	struct smp_object *so;
+	struct objcore *oc;
 
+	CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
 
-	CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->obj->objstore, STORAGE_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->obj->objstore->stevedore, STEVEDORE_MAGIC);
-	CHECK_OBJ_NOTNULL(sp->obj->objcore, OBJCORE_MAGIC);
-	CAST_OBJ_NOTNULL(sg, sp->obj->objcore->priv2, SMP_SEG_MAGIC);
-	CAST_OBJ_NOTNULL(sc, sp->obj->objstore->priv, SMP_SC_MAGIC);
+	/* XXX: temporary sanity */
+	AN(sp->objhead);
+	AN(sp->wrk->cacheable);
 
-	sp->obj->objcore->flags |= OC_F_LRUDONTMOVE;
+	sg = NULL;
+	st = smp_allocx(stv, ltot, &sg);
+	if (st == NULL)
+		return (NULL);
 
+	assert(st->space >= ltot);
+	ltot = st->len = st->space;
+
+	o = STV_MkObject(sp, st->ptr, ltot, soc);
+	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
+	o->objstore = st;
+	
+	oc = o->objcore;
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	oc->flags |= OC_F_LRUDONTMOVE;
+
 	Lck_Lock(&sc->mtx);
 	assert(sg->nalloc2 < sg->nalloc1);
 
-	sp->obj->smp_index = sg->nalloc2++;
-	so = &sg->objs[sp->obj->smp_index];
+	o->smp_index = sg->nalloc2++;
+	so = &sg->objs[o->smp_index];
 	sg->nfixed++;
 	sg->nobj++;
 	assert(sizeof so->hash == DIGEST_LEN);
-	memcpy(so->hash, sp->obj->objcore->objhead->digest, DIGEST_LEN);
-	so->ttl = sp->obj->ttl;
-	so->ptr = sp->obj;
-	so->ban = sp->obj->ban_t;
+	memcpy(so->hash, oc->objhead->digest, DIGEST_LEN);
+	so->ttl = o->ttl;
+	so->ptr = o;
+	so->ban = o->ban_t;
 
 	Lck_Unlock(&sc->mtx);
+	return (o);
 }
 
 /*--------------------------------------------------------------------
@@ -1538,7 +1544,6 @@
 	.close	=	smp_close,
 	.alloc	=	smp_alloc,
 	.allocobj =	smp_allocobj,
-	.object	=	smp_object,
 	.free	=	smp_free,
 	.trim	=	smp_trim,
 };




More information about the varnish-commit mailing list