[master] e8a63f4 Try to read the silo signature to find the correct address to map the silo into VM. If this fails or we get garbage, the silo will be cleared.

Poul-Henning Kamp phk at varnish-cache.org
Thu Aug 11 16:12:30 CEST 2011


commit e8a63f4d5e687cf3a04d34f696c661446d6c8d25
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Aug 11 14:11:42 2011 +0000

    Try to read the silo signature to find the correct address to map
    the silo into VM.  If this fails or we get garbage, the silo will
    be cleared.
    
    Fixes	#962

diff --git a/bin/varnishd/storage_persistent_mgt.c b/bin/varnishd/storage_persistent_mgt.c
index 0681264..a22cc59 100644
--- a/bin/varnishd/storage_persistent_mgt.c
+++ b/bin/varnishd/storage_persistent_mgt.c
@@ -120,6 +120,8 @@ void
 smp_mgt_init(struct stevedore *parent, int ac, char * const *av)
 {
 	struct smp_sc		*sc;
+	struct smp_sign		sgn;
+	void *target;
 	int i;
 
 	ASSERT_MGT();
@@ -158,7 +160,15 @@ smp_mgt_init(struct stevedore *parent, int ac, char * const *av)
 
 	AZ(ftruncate(sc->fd, sc->mediasize));
 
-	sc->base = mmap(NULL, sc->mediasize, PROT_READ|PROT_WRITE,
+	/* Try to determine correct mmap address */
+	i = read(sc->fd, &sgn, sizeof sgn);
+	assert(i == sizeof sgn);
+	if (!strcmp(sgn.ident, "SILO"))
+		target = (void*)sgn.mapped;
+	else
+		target = NULL;
+
+	sc->base = mmap(target, sc->mediasize, PROT_READ|PROT_WRITE,
 	    MAP_NOCORE | MAP_NOSYNC | MAP_SHARED, sc->fd, 0);
 
 	if (sc->base == MAP_FAILED)
@@ -169,8 +179,11 @@ smp_mgt_init(struct stevedore *parent, int ac, char * const *av)
 	sc->ident = SIGN_DATA(&sc->idn);
 
 	i = smp_valid_silo(sc);
-	if (i)
+	if (i) {
+		printf("Warning SILO (%s) not reloaded (reason=%d)\n",
+		    sc->filename, i);
 		smp_newsilo(sc);
+	}
 	AZ(smp_valid_silo(sc));
 
 	smp_metrics(sc);
diff --git a/bin/varnishd/storage_persistent_subr.c b/bin/varnishd/storage_persistent_subr.c
index 552c0be..6fad388 100644
--- a/bin/varnishd/storage_persistent_subr.c
+++ b/bin/varnishd/storage_persistent_subr.c
@@ -238,26 +238,27 @@ smp_valid_silo(struct smp_sc *sc)
 
 	assert(strlen(SMP_IDENT_STRING) < sizeof si->ident);
 
-	if (smp_chk_sign(&sc->idn))
-		return (1);
+	i = smp_chk_sign(&sc->idn);
+	if (i)
+		return (i);
 
 	si = sc->ident;
 	if (strcmp(si->ident, SMP_IDENT_STRING))
-		return (2);
+		return (12);
 	if (si->byte_order != 0x12345678)
-		return (3);
+		return (13);
 	if (si->size != sizeof *si)
-		return (4);
+		return (14);
 	if (si->major_version != 2)
-		return (5);
+		return (15);
 	if (si->mediasize != sc->mediasize)
-		return (7);
+		return (17);
 	if (si->granularity != sc->granularity)
-		return (8);
+		return (18);
 	if (si->align < sizeof(void*))
-		return (9);
+		return (19);
 	if (!PWR2(si->align))
-		return (10);
+		return (20);
 	sc->align = si->align;
 	sc->unique = si->unique;
 
diff --git a/bin/varnishtest/tests/r00962.vtc b/bin/varnishtest/tests/r00962.vtc
new file mode 100644
index 0000000..66f447b
--- /dev/null
+++ b/bin/varnishtest/tests/r00962.vtc
@@ -0,0 +1,47 @@
+varnishtest "Test address remapping"
+
+server s1 {
+	rxreq 
+	txresp 
+} -start
+
+shell "rm -f ${tmpdir}/_.per?"
+
+varnish v1 \
+	-arg "-pdiag_bitmap=0x20000" \
+	-storage "-spersistent,${tmpdir}/_.per1,10m -spersistent,${tmpdir}/_.per2,10m" \
+	-vcl+backend { 
+	sub vcl_fetch {
+		set beresp.storage = "s0";
+	}
+} -start 
+
+varnish v1 -stop
+
+varnish v1 -start
+
+client c1 {
+	txreq -url "/"
+	rxresp
+	expect resp.status == 200
+	expect resp.http.X-Varnish == "1001"
+} -run
+
+varnish v1 -cliok "storage.list"
+varnish v1 -cliok "debug.persistent s0 dump"
+varnish v1 -cliok "debug.persistent s0 sync"
+varnish v1 -stop
+
+varnish v2 \
+	-arg "-pdiag_bitmap=0x20000" \
+	-storage "-spersistent,${tmpdir}/_.per2,10m -spersistent,${tmpdir}/_.per1,10m" \
+	-vcl+backend { } -start 
+
+client c1 -connect ${v2_sock} {
+	txreq -url "/"
+	rxresp
+	expect resp.status == 200
+	expect resp.http.X-Varnish == "1001"
+} -run
+
+# shell "rm -f /tmp/__v1/_.per"



More information about the varnish-commit mailing list