r3914 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Mar 11 15:31:17 CET 2009


Author: phk
Date: 2009-03-11 15:31:16 +0100 (Wed, 11 Mar 2009)
New Revision: 3914

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_ban.c
   trunk/varnish-cache/bin/varnishd/cache_expire.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/storage_persistent.c
Log:
Give objects a back-pointer to their entry in the segment object index.

Have the objcore point to the smp_object until fixup, so that we catch
any attempt to muck with it before that and so that we hve the address
available in Fixup.

Since we don't have the silos coordinates at fixup time, make the
smp_object point to the object.

Add callbacks for updating BAN and TTL information in the segment object
index.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2009-03-11 13:51:43 UTC (rev 3913)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2009-03-11 14:31:16 UTC (rev 3914)
@@ -93,6 +93,7 @@
 struct cli_proto;
 struct ban;
 struct SHA256Context;
+struct smp_object;
 
 struct lock { void *priv; };		// Opaque
 
@@ -299,6 +300,8 @@
 	struct storage		*objstore;
 	struct objcore		*objcore;
 
+	struct smp_object	*smp;
+
 	struct ws		ws_o[1];
 	unsigned char		*vary;
 
@@ -661,6 +664,8 @@
 
 /* storage_persistent.c */
 void SMP_Fixup(struct sess *sp, struct objhead *oh, struct objcore *oc);
+void SMP_BANchanged(const struct object *o);
+void SMP_TTLchanged(const struct object *o);
 
 /*
  * A normal pointer difference is signed, but we never want a negative value

Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_ban.c	2009-03-11 13:51:43 UTC (rev 3913)
+++ trunk/varnish-cache/bin/varnishd/cache_ban.c	2009-03-11 14:31:16 UTC (rev 3914)
@@ -528,12 +528,16 @@
 
 	if (b == o->ban) {	/* not banned */
 		o->ban = b0;
+		if (o->smp != NULL)
+			SMP_BANchanged(o);
 		return (0);
 	} else {
 		o->ttl = 0;
+		o->ban = NULL;
+		SMP_TTLchanged(o);
+		/* BAN also changed, but that is not important any more */
 		WSP(sp, SLT_ExpBan, "%u was banned", o->xid);
 		EXP_Rearm(o);
-		o->ban = NULL;
 		return (1);
 	}
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_expire.c	2009-03-11 13:51:43 UTC (rev 3913)
+++ trunk/varnish-cache/bin/varnishd/cache_expire.c	2009-03-11 14:31:16 UTC (rev 3914)
@@ -127,6 +127,8 @@
 	VTAILQ_INSERT_TAIL(&lru, oc, lru_list);
 	oc->flags |= OC_F_ONLRU;
 	Lck_Unlock(&exp_mtx);
+	if (o->smp != NULL)
+		SMP_TTLchanged(o);
 }
 
 /*--------------------------------------------------------------------
@@ -199,6 +201,7 @@
 		assert(oc->timer_idx != BINHEAP_NOIDX);
 	}
 	Lck_Unlock(&exp_mtx);
+	SMP_TTLchanged(o);
 }
 
 

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-03-11 13:51:43 UTC (rev 3913)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-03-11 14:31:16 UTC (rev 3914)
@@ -401,7 +401,6 @@
 	oc = w->nobjcore;
 	w->nobjcore = NULL;
 	AZ(oc->flags & OC_F_BUSY);
-	CHECK_OBJ_NOTNULL(oc->obj, OBJECT_MAGIC);
 
 	/* XXX: Should this not be ..._HEAD now ? */
 	VTAILQ_INSERT_TAIL(&oh->objcs, oc, list);

Modified: trunk/varnish-cache/bin/varnishd/storage_persistent.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_persistent.c	2009-03-11 13:51:43 UTC (rev 3913)
+++ trunk/varnish-cache/bin/varnishd/storage_persistent.c	2009-03-11 14:31:16 UTC (rev 3914)
@@ -420,8 +420,18 @@
 void
 SMP_Fixup(struct sess *sp, struct objhead *oh, struct objcore *oc)
 {
+	struct smp_object *so;
+
 fprintf(stderr, "Fixup %p %p\n", sp, oc);
 
+	so = (void*)oc->obj;
+	oc->obj = so->ptr;
+
+	/* XXX: This should fail gracefully */
+	CHECK_OBJ_NOTNULL(oc->obj, OBJECT_MAGIC);
+
+	oc->obj->smp = so;
+
 	oc->flags &= ~OC_F_PERSISTENT;
 
 	oc->obj->refcnt = 0;
@@ -434,7 +444,34 @@
 }
 
 /*--------------------------------------------------------------------
+ * Update objects
+ */
+
+void
+SMP_BANchanged(const struct object *o)
+{
+	assert(o->smp != NULL);
+}
+
+void
+SMP_TTLchanged(const struct object *o)
+{
+
+	assert(o->smp != NULL);
+}
+
+/*--------------------------------------------------------------------
  * Load segments
+ *
+ * The overall objective is to register the existence of an object, based
+ * only on the minimally sized struct smp_object, without causing the
+ * main object to be faulted in.
+ *
+ * XXX: We can test this by mprotecting the main body of the segment
+ * XXX: until the first fixup happens, or even just over this loop,
+ * XXX: However: the requires that the smp_objects starter further
+ * XXX: into the segment than a page so that they do not get hit
+ * XXX: by the protection.
  */
 
 static void
@@ -458,12 +495,12 @@
 	for (;no > 0; so++,no--) {
 		if (so->ttl < t_now)
 			continue;
-		fprintf(stderr, "OBJ %p dTTL: %g PTR %jx\n",
-		    so, so->ttl - t_now, so->offset);
+		fprintf(stderr, "OBJ %p dTTL: %g PTR %p\n",
+		    so, so->ttl - t_now, so->ptr);
 		HSH_Prealloc(sp);
 		sp->wrk->nobjcore->flags |= OC_F_PERSISTENT;
 		sp->wrk->nobjcore->flags &= ~OC_F_BUSY;
-		sp->wrk->nobjcore->obj = (void*)(so->offset + sc->ptr);
+		sp->wrk->nobjcore->obj = (void*)so;
 		memcpy(sp->wrk->nobjhead->digest, so->hash, SHA256_LEN);
 		(void)HSH_Insert(sp);
 	}
@@ -666,7 +703,7 @@
 	so = &sg->objs[sg->nalloc++];
 	memcpy(so->hash, sp->obj->objhead->digest, DIGEST_LEN);
 	so->ttl = sp->obj->ttl;
-	so->offset = (uint8_t*)sp->obj - sc->ptr;
+	so->ptr = sp->obj;
 
 fprintf(stderr, "Object(%p %p)\n", sp, sp->obj);
 }



More information about the varnish-commit mailing list