[master] 26cfc94 Move cache/mgt common stuff under, you guessed it: common/

Poul-Henning Kamp phk at varnish-cache.org
Sun Nov 13 11:56:48 CET 2011


commit 26cfc94ebbff9946dd9dbdabc83382abb9d77e86
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sun Nov 13 10:38:37 2011 +0000

    Move cache/mgt common stuff under, you guessed it: common/

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 0460303..245bc6b 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -45,14 +45,10 @@ varnishd_SOURCES = \
 	cache_vrt_re.c \
 	cache_vrt_var.c \
 	cache_vrt_vmod.c \
-	waiter/cache_waiter.c \
-	waiter/cache_waiter_epoll.c \
-	waiter/cache_waiter_kqueue.c \
-	waiter/cache_waiter_poll.c \
-	waiter/cache_waiter_ports.c \
 	cache_wrk.c \
 	cache_wrw.c \
 	cache_ws.c \
+	common/common_vsm.c \
 	hash/hash_classic.c \
 	hash/hash_critbit.c \
 	hash/hash_mgt.c \
@@ -76,23 +72,27 @@ varnishd_SOURCES = \
 	storage/storage_persistent_subr.c \
 	storage/storage_synth.c \
 	storage/storage_umem.c \
-	vsm.c
+	waiter/cache_waiter.c \
+	waiter/cache_waiter_epoll.c \
+	waiter/cache_waiter_kqueue.c \
+	waiter/cache_waiter_poll.c \
+	waiter/cache_waiter_ports.c 
 
 noinst_HEADERS = \
 	cache.h \
 	cache_backend.h \
 	cache_esi.h \
-	waiter/cache_waiter.h \
-	common.h \
+	common/common.h \
+	common/heritage.h \
+	common/params.h \
 	default_vcl.h \
 	hash/hash_slinger.h \
-	heritage.h \
 	mgt/mgt.h \
 	mgt/mgt_cli.h \
 	mgt/mgt_param.h \
-	params.h \
 	storage/storage.h \
-	storage/storage_persistent.h
+	storage/storage_persistent.h \
+	waiter/cache_waiter.h
 
 varnishd_CFLAGS = \
 	@PCRE_CFLAGS@ \
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index b21f2d4..653fe77 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -34,7 +34,7 @@
  */
 #define VARNISH_CACHE_CHILD	1
 
-#include "common.h"
+#include "common/common.h"
 
 #include "vapi/vsc_int.h"
 #include "vapi/vsl_int.h"
@@ -55,7 +55,7 @@
 #endif
 
 
-#include "params.h"
+#include "common/params.h"
 
 enum body_status {
 #define BODYSTATUS(U,l)	BS_##U,
diff --git a/bin/varnishd/cache_acceptor.c b/bin/varnishd/cache_acceptor.c
index 5161b09..8c83121 100644
--- a/bin/varnishd/cache_acceptor.c
+++ b/bin/varnishd/cache_acceptor.c
@@ -31,7 +31,7 @@
 #include "config.h"
 
 #include "cache.h"
-#include "heritage.h"
+#include "common/heritage.h"
 
 #include "vcli.h"
 #include "vcli_priv.h"
diff --git a/bin/varnishd/cache_cli.c b/bin/varnishd/cache_cli.c
index 0bbf94b..f29f86a 100644
--- a/bin/varnishd/cache_cli.c
+++ b/bin/varnishd/cache_cli.c
@@ -39,7 +39,7 @@
 #include <stddef.h>			// offsetof
 
 #include "cache.h"
-#include "heritage.h"
+#include "common/heritage.h"
 
 #include "cache_backend.h"		// struct vbc
 #include "hash/hash_slinger.h"		// struct objhead
diff --git a/bin/varnishd/cache_main.c b/bin/varnishd/cache_main.c
index 7a3bcd9..eb3fa1d 100644
--- a/bin/varnishd/cache_main.c
+++ b/bin/varnishd/cache_main.c
@@ -33,7 +33,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
-#include "heritage.h"
+#include "common/heritage.h"
 
 #include "waiter/cache_waiter.h"
 #include "hash/hash_slinger.h"
diff --git a/bin/varnishd/cache_pool.c b/bin/varnishd/cache_pool.c
index be49548..79a5fcd 100644
--- a/bin/varnishd/cache_pool.c
+++ b/bin/varnishd/cache_pool.c
@@ -46,7 +46,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
-#include "heritage.h"
+#include "common/heritage.h"
 
 #include "waiter/cache_waiter.h"
 #include "vtcp.h"
diff --git a/bin/varnishd/cache_vrt_var.c b/bin/varnishd/cache_vrt_var.c
index a9bf87f..860c7aa 100644
--- a/bin/varnishd/cache_vrt_var.c
+++ b/bin/varnishd/cache_vrt_var.c
@@ -34,7 +34,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
-#include "heritage.h"
+#include "common/heritage.h"
 
 #include "cache_backend.h"
 #include "vrt_obj.h"
diff --git a/bin/varnishd/common.h b/bin/varnishd/common.h
deleted file mode 100644
index 4e56a40..0000000
--- a/bin/varnishd/common.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-#include <errno.h>
-#include <stdint.h>
-
-#include <sys/types.h>
-
-#include "miniobj.h"
-#include "vas.h"
-#include "vcs.h"
-#include "vdef.h"
-#include "vqueue.h"
-#include "vsb.h"
-
-struct cli;
-
-extern pid_t mgt_pid;
-#define ASSERT_MGT() do { assert(getpid() == mgt_pid);} while (0)
-
-/* mgt_shmem.c */
-extern struct VSC_C_main *VSC_C_main;
-
-/* varnishd.c */
-struct vsb;
-extern struct vsb *vident;
-int Symbol_Lookup(struct vsb *vsb, void *ptr);
-
-#define TRUST_ME(ptr)	((void*)(uintptr_t)(ptr))
-
-
-/* Help shut up FlexeLint */
-#define __match_proto__(xxx) /*lint -e{818} */
-
-/* Really belongs in mgt.h, but storage_file chokes on both */
-void mgt_child_inherit(int fd, const char *what);
-
-#define ARGV_ERR(...)						\
-	do {							\
-		fprintf(stderr, "Error: " __VA_ARGS__);		\
-		exit(2);					\
-	} while (0);
-
-/* A tiny helper for choosing hash/storage modules */
-struct choice {
-	const char      *name;
-	const void	*ptr;
-};
-const void *pick(const struct choice *cp, const char *which, const char *kind);
-
-#define NEEDLESS_RETURN(foo)	return (foo)
-
-/* stevedore.c */
-void STV_Config(const char *spec);
-void STV_Config_Transient(void);
-
-/* vsm.c */
-// extern struct VSM_head		*VSM_head;
-// extern const struct VSM_chunk	*vsm_end;
-
-/*
- * These three should not be called directly, but only through
- * proper vectors in mgt.h/cache.h, hence the __
- */
-void *VSM__Alloc(unsigned size, const char *class, const char *type,
-    const char *ident);
-void VSM__Free(const void *ptr);
-void VSM__Clean(void);
-
-/* These classes are opaque to other programs, so we define the here */
-#define VSM_CLASS_FREE	"Free"
-#define VSM_CLASS_COOL	"Cool"
-#define VSM_CLASS_PARAM	"Params"
-#define VSM_CLASS_MARK	"MgrCld"
-#define VSM_COOL_TIME	5
-
-/* cache_lck.c */
-struct lock { void *priv; };		// Opaque
-
-/*---------------------------------------------------------------------
- * Generic power-2 rounding macros
- */
-
-#define PWR2(x)     ((((x)-1)&(x))==0)		/* Is a power of two */
-#define RDN2(x, y)  ((x)&(~((y)-1)))		/* if y is powers of two */
-#define RUP2(x, y)  (((x)+((y)-1))&(~((y)-1)))	/* if y is powers of two */
diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h
new file mode 100644
index 0000000..4e56a40
--- /dev/null
+++ b/bin/varnishd/common/common.h
@@ -0,0 +1,113 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <errno.h>
+#include <stdint.h>
+
+#include <sys/types.h>
+
+#include "miniobj.h"
+#include "vas.h"
+#include "vcs.h"
+#include "vdef.h"
+#include "vqueue.h"
+#include "vsb.h"
+
+struct cli;
+
+extern pid_t mgt_pid;
+#define ASSERT_MGT() do { assert(getpid() == mgt_pid);} while (0)
+
+/* mgt_shmem.c */
+extern struct VSC_C_main *VSC_C_main;
+
+/* varnishd.c */
+struct vsb;
+extern struct vsb *vident;
+int Symbol_Lookup(struct vsb *vsb, void *ptr);
+
+#define TRUST_ME(ptr)	((void*)(uintptr_t)(ptr))
+
+
+/* Help shut up FlexeLint */
+#define __match_proto__(xxx) /*lint -e{818} */
+
+/* Really belongs in mgt.h, but storage_file chokes on both */
+void mgt_child_inherit(int fd, const char *what);
+
+#define ARGV_ERR(...)						\
+	do {							\
+		fprintf(stderr, "Error: " __VA_ARGS__);		\
+		exit(2);					\
+	} while (0);
+
+/* A tiny helper for choosing hash/storage modules */
+struct choice {
+	const char      *name;
+	const void	*ptr;
+};
+const void *pick(const struct choice *cp, const char *which, const char *kind);
+
+#define NEEDLESS_RETURN(foo)	return (foo)
+
+/* stevedore.c */
+void STV_Config(const char *spec);
+void STV_Config_Transient(void);
+
+/* vsm.c */
+// extern struct VSM_head		*VSM_head;
+// extern const struct VSM_chunk	*vsm_end;
+
+/*
+ * These three should not be called directly, but only through
+ * proper vectors in mgt.h/cache.h, hence the __
+ */
+void *VSM__Alloc(unsigned size, const char *class, const char *type,
+    const char *ident);
+void VSM__Free(const void *ptr);
+void VSM__Clean(void);
+
+/* These classes are opaque to other programs, so we define the here */
+#define VSM_CLASS_FREE	"Free"
+#define VSM_CLASS_COOL	"Cool"
+#define VSM_CLASS_PARAM	"Params"
+#define VSM_CLASS_MARK	"MgrCld"
+#define VSM_COOL_TIME	5
+
+/* cache_lck.c */
+struct lock { void *priv; };		// Opaque
+
+/*---------------------------------------------------------------------
+ * Generic power-2 rounding macros
+ */
+
+#define PWR2(x)     ((((x)-1)&(x))==0)		/* Is a power of two */
+#define RDN2(x, y)  ((x)&(~((y)-1)))		/* if y is powers of two */
+#define RUP2(x, y)  (((x)+((y)-1))&(~((y)-1)))	/* if y is powers of two */
diff --git a/bin/varnishd/common/common_vsm.c b/bin/varnishd/common/common_vsm.c
new file mode 100644
index 0000000..5298381
--- /dev/null
+++ b/bin/varnishd/common/common_vsm.c
@@ -0,0 +1,238 @@
+/*-
+ * Copyright (c) 2010-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * VSM stuff common to manager and child.
+ *
+ * We have three potential conflicts we need to lock against here:
+ *
+ * VSM-studying programs (varnishstat...) vs. everybody else
+ *	The VSM studying programs only have read-only access to the VSM
+ *	so everybody else must use memory barriers, stable storage and
+ *	similar tricks to keep the VSM image in sync (long enough) for
+ *	the studying programs.
+ *
+ * Manager process vs child process.
+ *	Will only muck about in VSM when child process is not running
+ *	Responsible for cleaning up any mess left behind by dying child.
+ *
+ * Child process threads
+ *	Pthread locking necessary.
+ *
+ * XXX: not all of this is in place yet.
+ */
+
+#include "config.h"
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "common.h"
+
+#include "vapi/vsm_int.h"
+#include "vmb.h"
+#include "vtim.h"
+
+/* These two come from beyond (mgt_shmem.c actually) */
+struct VSM_head		*VSM_head;
+const struct VSM_chunk	*vsm_end;
+
+static unsigned
+vsm_mark(void)
+{
+	unsigned seq;
+
+	seq = VSM_head->alloc_seq;
+	VSM_head->alloc_seq = 0;
+	VWMB();
+	return (seq);
+}
+
+static void
+vsm_release(unsigned seq)
+{
+
+	if (seq == 0)
+		return;
+	VWMB();
+	do
+		VSM_head->alloc_seq = ++seq;
+	while (VSM_head->alloc_seq == 0);
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+vsm_cleanup(void)
+{
+	unsigned now = (unsigned)VTIM_mono();
+	struct VSM_chunk *sha, *sha2;
+	unsigned seq;
+
+	CHECK_OBJ_NOTNULL(VSM_head, VSM_HEAD_MAGIC);
+	VSM_ITER(sha) {
+		if (strcmp(sha->class, VSM_CLASS_COOL))
+			continue;
+		if (sha->state + VSM_COOL_TIME < now)
+			break;
+	}
+	if (sha == NULL)
+		return;
+	seq = vsm_mark();
+	/* First pass, free, and collapse with next if applicable */
+	VSM_ITER(sha) {
+		if (strcmp(sha->class, VSM_CLASS_COOL))
+			continue;
+		if (sha->state + VSM_COOL_TIME >= now)
+			continue;
+
+		bprintf(sha->class, "%s", VSM_CLASS_FREE);
+		bprintf(sha->type, "%s", "");
+		bprintf(sha->ident, "%s", "");
+		sha2 = VSM_NEXT(sha);
+		assert(sha2 <= vsm_end);
+		if (sha2 == vsm_end)
+			break;
+		CHECK_OBJ_NOTNULL(sha2, VSM_CHUNK_MAGIC);
+		if (!strcmp(sha2->class, VSM_CLASS_FREE)) {
+			sha->len += sha2->len;
+			memset(sha2, 0, sizeof *sha2);
+		}
+		sha->state = 0;
+	}
+	/* Second pass, collaps with prev if applicable */
+	VSM_ITER(sha) {
+		if (strcmp(sha->class, VSM_CLASS_FREE))
+			continue;
+		sha2 = VSM_NEXT(sha);
+		assert(sha2 <= vsm_end);
+		if (sha2 == vsm_end)
+			break;
+		CHECK_OBJ_NOTNULL(sha2, VSM_CHUNK_MAGIC);
+		if (!strcmp(sha2->class, VSM_CLASS_FREE)) {
+			sha->len += sha2->len;
+			memset(sha2, 0, sizeof *sha2);
+		}
+	}
+	vsm_release(seq);
+}
+
+/*--------------------------------------------------------------------*/
+
+void *
+VSM__Alloc(unsigned size, const char *class, const char *type, const char *ident)
+{
+	struct VSM_chunk *sha, *sha2;
+	unsigned seq;
+
+	CHECK_OBJ_NOTNULL(VSM_head, VSM_HEAD_MAGIC);
+
+	vsm_cleanup();
+
+	/* Round up to pointersize */
+	size = RUP2(size, sizeof(void*));
+
+	size += sizeof *sha;		/* Make space for the header */
+
+	VSM_ITER(sha) {
+		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
+
+		if (strcmp(sha->class, VSM_CLASS_FREE))
+			continue;
+
+		if (size > sha->len)
+			continue;
+
+		/* Mark as inconsistent while we write string fields */
+		seq = vsm_mark();
+
+		if (size + sizeof (*sha) < sha->len) {
+			sha2 = (void*)((uintptr_t)sha + size);
+
+			memset(sha2, 0, sizeof *sha2);
+			sha2->magic = VSM_CHUNK_MAGIC;
+			sha2->len = sha->len - size;
+			bprintf(sha2->class, "%s", VSM_CLASS_FREE);
+			sha->len = size;
+		}
+
+		bprintf(sha->class, "%s", class);
+		bprintf(sha->type, "%s", type);
+		bprintf(sha->ident, "%s", ident);
+
+		vsm_release(seq);
+		return (VSM_PTR(sha));
+	}
+	return (NULL);
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+VSM__Free(const void *ptr)
+{
+	struct VSM_chunk *sha;
+	unsigned seq;
+
+	CHECK_OBJ_NOTNULL(VSM_head, VSM_HEAD_MAGIC);
+	VSM_ITER(sha)
+		if (VSM_PTR(sha) == ptr)
+			break;
+	AN(sha);
+	seq = vsm_mark();
+	bprintf(sha->class, "%s", VSM_CLASS_COOL);
+	sha->state = (unsigned)VTIM_mono();
+	vsm_release(seq);
+}
+
+/*--------------------------------------------------------------------
+ * Free all allocations after the mark (ie: allocated by child).
+ */
+
+void
+VSM__Clean(void)
+{
+	struct VSM_chunk *sha;
+	unsigned f, seq;
+
+	CHECK_OBJ_NOTNULL(VSM_head, VSM_HEAD_MAGIC);
+	f = 0;
+	seq = vsm_mark();
+	VSM_ITER(sha) {
+		if (f == 0 && !strcmp(sha->class, VSM_CLASS_MARK)) {
+			f = 1;
+			continue;
+		}
+		if (f == 0)
+			continue;
+		if (strcmp(sha->class, VSM_CLASS_FREE) &&
+		    strcmp(sha->class, VSM_CLASS_COOL))
+			VSM__Free(VSM_PTR(sha));
+	}
+	vsm_release(seq);
+}
diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h
new file mode 100644
index 0000000..36433bb
--- /dev/null
+++ b/bin/varnishd/common/heritage.h
@@ -0,0 +1,65 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file contains the heritage passed when mgt forks cache
+ */
+
+struct listen_sock {
+	unsigned			magic;
+#define LISTEN_SOCK_MAGIC		0x999e4b57
+	VTAILQ_ENTRY(listen_sock)	list;
+	int				sock;
+	char				*name;
+	struct vss_addr			*addr;
+};
+
+VTAILQ_HEAD(listen_sock_head, listen_sock);
+
+struct heritage {
+
+	/* Two pipe(2)'s for CLI connection between cache and mgt.  */
+	int				cli_in;
+	int				cli_out;
+
+	/* File descriptor for stdout/stderr */
+	int				std_fd;
+
+	/* Sockets from which to accept connections */
+	struct listen_sock_head		socks;
+	unsigned			nsocks;
+
+	/* Hash method */
+	const struct hash_slinger	*hash;
+
+	char				*name;
+	char                            identity[1024];
+};
+
+extern struct heritage heritage;
+
+void child_main(void);
diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h
new file mode 100644
index 0000000..fb71e33
--- /dev/null
+++ b/bin/varnishd/common/params.h
@@ -0,0 +1,194 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file contains the heritage passed when mgt forks cache
+ */
+
+#include "vre.h"
+
+struct params {
+
+	/* Unprivileged user / group */
+	char			*user;
+	uid_t			uid;
+	char			*group;
+	gid_t			gid;
+
+	/* TTL used for lack of anything better */
+	double			default_ttl;
+
+	/* Default grace period */
+	double			default_grace;
+
+	/* Default keep period */
+	double			default_keep;
+
+	/* Maximum concurrent sessions */
+	unsigned		max_sess;
+
+	/* Worker threads and pool */
+	unsigned		wthread_min;
+	unsigned		wthread_max;
+	unsigned		wthread_timeout;
+	unsigned		wthread_pools;
+	unsigned		wthread_add_threshold;
+	unsigned		wthread_add_delay;
+	unsigned		wthread_fail_delay;
+	unsigned		wthread_purge_delay;
+	unsigned		wthread_stats_rate;
+	unsigned		wthread_stacksize;
+	unsigned		wthread_workspace;
+
+	unsigned		queue_max;
+
+	/* Memory allocation hints */
+	unsigned		sess_workspace;
+	unsigned		shm_workspace;
+	unsigned		http_req_size;
+	unsigned		http_req_hdr_len;
+	unsigned		http_resp_size;
+	unsigned		http_resp_hdr_len;
+	unsigned		http_max_hdr;
+
+	unsigned		shm_reclen;
+
+	/* Acceptor hints */
+	unsigned		sess_timeout;
+	unsigned		pipe_timeout;
+	unsigned		send_timeout;
+	unsigned		idle_send_timeout;
+
+	/* Management hints */
+	unsigned		auto_restart;
+
+	/* Fetcher hints */
+	unsigned		fetch_chunksize;
+	unsigned		fetch_maxchunksize;
+	unsigned		nuke_limit;
+
+#ifdef SENDFILE_WORKS
+	/* Sendfile object minimum size */
+	unsigned		sendfile_threshold;
+#endif
+
+	/* VCL traces */
+	unsigned		vcl_trace;
+
+	/* Listen address */
+	char			*listen_address;
+
+	/* Listen depth */
+	unsigned		listen_depth;
+
+	/* CLI related */
+	unsigned		cli_timeout;
+	unsigned		ping_interval;
+
+	/* LRU list ordering interval */
+	unsigned		lru_timeout;
+
+	/* Maximum restarts allowed */
+	unsigned		max_restarts;
+
+	/* Maximum esi:include depth allowed */
+	unsigned		max_esi_depth;
+
+	/* ESI parser hints */
+	unsigned		esi_syntax;
+
+	/* Rush exponent */
+	unsigned		rush_exponent;
+
+	/* Default connection_timeout */
+	double			connect_timeout;
+
+	/* Read timeouts for backend */
+	double			first_byte_timeout;
+	double			between_bytes_timeout;
+
+	/* How long to linger on sessions */
+	unsigned		session_linger;
+
+	/* CLI buffer size */
+	unsigned		cli_buffer;
+
+	/* Control diagnostic code */
+	unsigned		diag_bitmap;
+
+	/* Log hash string to shm */
+	unsigned		log_hash;
+
+	/* Log local socket address to shm */
+	unsigned		log_local_addr;
+
+	/* Prefer IPv6 connections to backend*/
+	unsigned		prefer_ipv6;
+
+	/* Acceptable clockskew with backends */
+	unsigned		clock_skew;
+
+	/* Expiry pacer parameters */
+	double			expiry_sleep;
+
+	/* Acceptor pacer parameters */
+	double			acceptor_sleep_max;
+	double			acceptor_sleep_incr;
+	double			acceptor_sleep_decay;
+
+	/* Get rid of duplicate bans */
+	unsigned		ban_dups;
+
+	/* How long time does the ban lurker sleep */
+	double			ban_lurker_sleep;
+
+	/* Max size of the saintmode list. 0 == no saint mode. */
+	unsigned		saintmode_threshold;
+
+	unsigned		syslog_cli_traffic;
+
+	unsigned		http_range_support;
+
+	unsigned		http_gzip_support;
+	unsigned		gzip_stack_buffer;
+	unsigned		gzip_tmp_space;
+	unsigned		gzip_level;
+	unsigned		gzip_window;
+	unsigned		gzip_memlevel;
+
+	double			critbit_cooloff;
+
+	double			shortlived;
+
+	struct vre_limits	vre_limits;
+};
+
+/*
+ * We declare this a volatile pointer, so that reads of parameters
+ * become atomic, leaving the CLI thread lattitude to change the values
+ */
+extern volatile struct params * cache_param;
diff --git a/bin/varnishd/flint.sh b/bin/varnishd/flint.sh
index 4beb9d5..756f65a 100755
--- a/bin/varnishd/flint.sh
+++ b/bin/varnishd/flint.sh
@@ -16,6 +16,7 @@ flexelint \
 	-I/usr/local/include \
 	-DVARNISH_STATE_DIR=\"foo\" \
 	*.c \
+	common/*.c \
 	storage/*.c \
 	waiter/*.c \
 	hash/*.c \
diff --git a/bin/varnishd/hash/hash_mgt.c b/bin/varnishd/hash/hash_mgt.c
index 6226749..ffbba29 100644
--- a/bin/varnishd/hash/hash_mgt.c
+++ b/bin/varnishd/hash/hash_mgt.c
@@ -36,7 +36,7 @@
 #include <unistd.h>
 
 #include "mgt/mgt.h"
-#include "heritage.h"
+#include "common/heritage.h"
 
 #include "hash/hash_slinger.h"
 #include "vav.h"
diff --git a/bin/varnishd/heritage.h b/bin/varnishd/heritage.h
deleted file mode 100644
index 36433bb..0000000
--- a/bin/varnishd/heritage.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file contains the heritage passed when mgt forks cache
- */
-
-struct listen_sock {
-	unsigned			magic;
-#define LISTEN_SOCK_MAGIC		0x999e4b57
-	VTAILQ_ENTRY(listen_sock)	list;
-	int				sock;
-	char				*name;
-	struct vss_addr			*addr;
-};
-
-VTAILQ_HEAD(listen_sock_head, listen_sock);
-
-struct heritage {
-
-	/* Two pipe(2)'s for CLI connection between cache and mgt.  */
-	int				cli_in;
-	int				cli_out;
-
-	/* File descriptor for stdout/stderr */
-	int				std_fd;
-
-	/* Sockets from which to accept connections */
-	struct listen_sock_head		socks;
-	unsigned			nsocks;
-
-	/* Hash method */
-	const struct hash_slinger	*hash;
-
-	char				*name;
-	char                            identity[1024];
-};
-
-extern struct heritage heritage;
-
-void child_main(void);
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 61493b3..54352a0 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -30,7 +30,7 @@
 
 #include <stdint.h>
 
-#include "common.h"
+#include "common/common.h"
 
 struct cli;
 
diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c
index d2e0abd..a2c0b58 100644
--- a/bin/varnishd/mgt/mgt_child.c
+++ b/bin/varnishd/mgt/mgt_child.c
@@ -44,8 +44,8 @@
 #include <unistd.h>
 
 #include "mgt/mgt.h"
-#include "heritage.h"
-#include "params.h"
+#include "common/heritage.h"
+#include "common/params.h"
 
 #include "vapi/vsm_int.h"
 #include "vbm.h"
diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c
index 3fdb432..3a6f365 100644
--- a/bin/varnishd/mgt/mgt_cli.c
+++ b/bin/varnishd/mgt/mgt_cli.c
@@ -43,8 +43,8 @@
 #include <unistd.h>
 
 #include "mgt/mgt.h"
-#include "heritage.h"
-#include "params.h"
+#include "common/heritage.h"
+#include "common/params.h"
 
 #include "vcli.h"
 #include "vcli_common.h"
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index ccda130..981841b 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -44,8 +44,8 @@
 #include <unistd.h>
 
 #include "mgt/mgt.h"
-#include "heritage.h"
-#include "params.h"
+#include "common/heritage.h"
+#include "common/params.h"
 
 #include "hash/hash_slinger.h"
 #include "vav.h"
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 8fff352..8050d08 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -38,8 +38,8 @@
 #include <unistd.h>
 
 #include "mgt/mgt.h"
-#include "heritage.h"
-#include "params.h"
+#include "common/heritage.h"
+#include "common/params.h"
 
 #include "mgt/mgt_param.h"
 #include "waiter/cache_waiter.h"
diff --git a/bin/varnishd/mgt/mgt_pool.c b/bin/varnishd/mgt/mgt_pool.c
index 6f61553..e8c4f27 100644
--- a/bin/varnishd/mgt/mgt_pool.c
+++ b/bin/varnishd/mgt/mgt_pool.c
@@ -48,8 +48,8 @@
 #include <unistd.h>
 
 #include "mgt/mgt.h"
-#include "heritage.h"
-#include "params.h"
+#include "common/heritage.h"
+#include "common/params.h"
 
 #include "mgt/mgt_param.h"
 
diff --git a/bin/varnishd/mgt/mgt_sandbox.c b/bin/varnishd/mgt/mgt_sandbox.c
index a9fce93..cdba825 100644
--- a/bin/varnishd/mgt/mgt_sandbox.c
+++ b/bin/varnishd/mgt/mgt_sandbox.c
@@ -53,8 +53,8 @@
 #include <unistd.h>
 
 #include "mgt/mgt.h"
-#include "heritage.h"
-#include "params.h"
+#include "common/heritage.h"
+#include "common/params.h"
 
 /*--------------------------------------------------------------------*/
 
diff --git a/bin/varnishd/mgt/mgt_sandbox_solaris.c b/bin/varnishd/mgt/mgt_sandbox_solaris.c
index 8c26d69..79f6650 100644
--- a/bin/varnishd/mgt/mgt_sandbox_solaris.c
+++ b/bin/varnishd/mgt/mgt_sandbox_solaris.c
@@ -44,7 +44,7 @@
 
 #include "mgt/mgt.h"
 
-#include "heritage.h"
+#include "common/heritage.h"
 
 /*--------------------------------------------------------------------
  * SOLARIS PRIVILEGES: Note on use of symbolic PRIV_* constants
diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c
index bb87a8f..d4346df 100644
--- a/bin/varnishd/mgt/mgt_shmem.c
+++ b/bin/varnishd/mgt/mgt_shmem.c
@@ -98,8 +98,8 @@
 #include <unistd.h>
 
 #include "mgt/mgt.h"
-#include "heritage.h"
-#include "params.h"
+#include "common/heritage.h"
+#include "common/params.h"
 
 #include "flopen.h"
 #include "vapi/vsc_int.h"
diff --git a/bin/varnishd/params.h b/bin/varnishd/params.h
deleted file mode 100644
index fb71e33..0000000
--- a/bin/varnishd/params.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This file contains the heritage passed when mgt forks cache
- */
-
-#include "vre.h"
-
-struct params {
-
-	/* Unprivileged user / group */
-	char			*user;
-	uid_t			uid;
-	char			*group;
-	gid_t			gid;
-
-	/* TTL used for lack of anything better */
-	double			default_ttl;
-
-	/* Default grace period */
-	double			default_grace;
-
-	/* Default keep period */
-	double			default_keep;
-
-	/* Maximum concurrent sessions */
-	unsigned		max_sess;
-
-	/* Worker threads and pool */
-	unsigned		wthread_min;
-	unsigned		wthread_max;
-	unsigned		wthread_timeout;
-	unsigned		wthread_pools;
-	unsigned		wthread_add_threshold;
-	unsigned		wthread_add_delay;
-	unsigned		wthread_fail_delay;
-	unsigned		wthread_purge_delay;
-	unsigned		wthread_stats_rate;
-	unsigned		wthread_stacksize;
-	unsigned		wthread_workspace;
-
-	unsigned		queue_max;
-
-	/* Memory allocation hints */
-	unsigned		sess_workspace;
-	unsigned		shm_workspace;
-	unsigned		http_req_size;
-	unsigned		http_req_hdr_len;
-	unsigned		http_resp_size;
-	unsigned		http_resp_hdr_len;
-	unsigned		http_max_hdr;
-
-	unsigned		shm_reclen;
-
-	/* Acceptor hints */
-	unsigned		sess_timeout;
-	unsigned		pipe_timeout;
-	unsigned		send_timeout;
-	unsigned		idle_send_timeout;
-
-	/* Management hints */
-	unsigned		auto_restart;
-
-	/* Fetcher hints */
-	unsigned		fetch_chunksize;
-	unsigned		fetch_maxchunksize;
-	unsigned		nuke_limit;
-
-#ifdef SENDFILE_WORKS
-	/* Sendfile object minimum size */
-	unsigned		sendfile_threshold;
-#endif
-
-	/* VCL traces */
-	unsigned		vcl_trace;
-
-	/* Listen address */
-	char			*listen_address;
-
-	/* Listen depth */
-	unsigned		listen_depth;
-
-	/* CLI related */
-	unsigned		cli_timeout;
-	unsigned		ping_interval;
-
-	/* LRU list ordering interval */
-	unsigned		lru_timeout;
-
-	/* Maximum restarts allowed */
-	unsigned		max_restarts;
-
-	/* Maximum esi:include depth allowed */
-	unsigned		max_esi_depth;
-
-	/* ESI parser hints */
-	unsigned		esi_syntax;
-
-	/* Rush exponent */
-	unsigned		rush_exponent;
-
-	/* Default connection_timeout */
-	double			connect_timeout;
-
-	/* Read timeouts for backend */
-	double			first_byte_timeout;
-	double			between_bytes_timeout;
-
-	/* How long to linger on sessions */
-	unsigned		session_linger;
-
-	/* CLI buffer size */
-	unsigned		cli_buffer;
-
-	/* Control diagnostic code */
-	unsigned		diag_bitmap;
-
-	/* Log hash string to shm */
-	unsigned		log_hash;
-
-	/* Log local socket address to shm */
-	unsigned		log_local_addr;
-
-	/* Prefer IPv6 connections to backend*/
-	unsigned		prefer_ipv6;
-
-	/* Acceptable clockskew with backends */
-	unsigned		clock_skew;
-
-	/* Expiry pacer parameters */
-	double			expiry_sleep;
-
-	/* Acceptor pacer parameters */
-	double			acceptor_sleep_max;
-	double			acceptor_sleep_incr;
-	double			acceptor_sleep_decay;
-
-	/* Get rid of duplicate bans */
-	unsigned		ban_dups;
-
-	/* How long time does the ban lurker sleep */
-	double			ban_lurker_sleep;
-
-	/* Max size of the saintmode list. 0 == no saint mode. */
-	unsigned		saintmode_threshold;
-
-	unsigned		syslog_cli_traffic;
-
-	unsigned		http_range_support;
-
-	unsigned		http_gzip_support;
-	unsigned		gzip_stack_buffer;
-	unsigned		gzip_tmp_space;
-	unsigned		gzip_level;
-	unsigned		gzip_window;
-	unsigned		gzip_memlevel;
-
-	double			critbit_cooloff;
-
-	double			shortlived;
-
-	struct vre_limits	vre_limits;
-};
-
-/*
- * We declare this a volatile pointer, so that reads of parameters
- * become atomic, leaving the CLI thread lattitude to change the values
- */
-extern volatile struct params * cache_param;
diff --git a/bin/varnishd/vsm.c b/bin/varnishd/vsm.c
deleted file mode 100644
index 5298381..0000000
--- a/bin/varnishd/vsm.c
+++ /dev/null
@@ -1,238 +0,0 @@
-/*-
- * Copyright (c) 2010-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * VSM stuff common to manager and child.
- *
- * We have three potential conflicts we need to lock against here:
- *
- * VSM-studying programs (varnishstat...) vs. everybody else
- *	The VSM studying programs only have read-only access to the VSM
- *	so everybody else must use memory barriers, stable storage and
- *	similar tricks to keep the VSM image in sync (long enough) for
- *	the studying programs.
- *
- * Manager process vs child process.
- *	Will only muck about in VSM when child process is not running
- *	Responsible for cleaning up any mess left behind by dying child.
- *
- * Child process threads
- *	Pthread locking necessary.
- *
- * XXX: not all of this is in place yet.
- */
-
-#include "config.h"
-
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "common.h"
-
-#include "vapi/vsm_int.h"
-#include "vmb.h"
-#include "vtim.h"
-
-/* These two come from beyond (mgt_shmem.c actually) */
-struct VSM_head		*VSM_head;
-const struct VSM_chunk	*vsm_end;
-
-static unsigned
-vsm_mark(void)
-{
-	unsigned seq;
-
-	seq = VSM_head->alloc_seq;
-	VSM_head->alloc_seq = 0;
-	VWMB();
-	return (seq);
-}
-
-static void
-vsm_release(unsigned seq)
-{
-
-	if (seq == 0)
-		return;
-	VWMB();
-	do
-		VSM_head->alloc_seq = ++seq;
-	while (VSM_head->alloc_seq == 0);
-}
-
-/*--------------------------------------------------------------------*/
-
-static void
-vsm_cleanup(void)
-{
-	unsigned now = (unsigned)VTIM_mono();
-	struct VSM_chunk *sha, *sha2;
-	unsigned seq;
-
-	CHECK_OBJ_NOTNULL(VSM_head, VSM_HEAD_MAGIC);
-	VSM_ITER(sha) {
-		if (strcmp(sha->class, VSM_CLASS_COOL))
-			continue;
-		if (sha->state + VSM_COOL_TIME < now)
-			break;
-	}
-	if (sha == NULL)
-		return;
-	seq = vsm_mark();
-	/* First pass, free, and collapse with next if applicable */
-	VSM_ITER(sha) {
-		if (strcmp(sha->class, VSM_CLASS_COOL))
-			continue;
-		if (sha->state + VSM_COOL_TIME >= now)
-			continue;
-
-		bprintf(sha->class, "%s", VSM_CLASS_FREE);
-		bprintf(sha->type, "%s", "");
-		bprintf(sha->ident, "%s", "");
-		sha2 = VSM_NEXT(sha);
-		assert(sha2 <= vsm_end);
-		if (sha2 == vsm_end)
-			break;
-		CHECK_OBJ_NOTNULL(sha2, VSM_CHUNK_MAGIC);
-		if (!strcmp(sha2->class, VSM_CLASS_FREE)) {
-			sha->len += sha2->len;
-			memset(sha2, 0, sizeof *sha2);
-		}
-		sha->state = 0;
-	}
-	/* Second pass, collaps with prev if applicable */
-	VSM_ITER(sha) {
-		if (strcmp(sha->class, VSM_CLASS_FREE))
-			continue;
-		sha2 = VSM_NEXT(sha);
-		assert(sha2 <= vsm_end);
-		if (sha2 == vsm_end)
-			break;
-		CHECK_OBJ_NOTNULL(sha2, VSM_CHUNK_MAGIC);
-		if (!strcmp(sha2->class, VSM_CLASS_FREE)) {
-			sha->len += sha2->len;
-			memset(sha2, 0, sizeof *sha2);
-		}
-	}
-	vsm_release(seq);
-}
-
-/*--------------------------------------------------------------------*/
-
-void *
-VSM__Alloc(unsigned size, const char *class, const char *type, const char *ident)
-{
-	struct VSM_chunk *sha, *sha2;
-	unsigned seq;
-
-	CHECK_OBJ_NOTNULL(VSM_head, VSM_HEAD_MAGIC);
-
-	vsm_cleanup();
-
-	/* Round up to pointersize */
-	size = RUP2(size, sizeof(void*));
-
-	size += sizeof *sha;		/* Make space for the header */
-
-	VSM_ITER(sha) {
-		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
-
-		if (strcmp(sha->class, VSM_CLASS_FREE))
-			continue;
-
-		if (size > sha->len)
-			continue;
-
-		/* Mark as inconsistent while we write string fields */
-		seq = vsm_mark();
-
-		if (size + sizeof (*sha) < sha->len) {
-			sha2 = (void*)((uintptr_t)sha + size);
-
-			memset(sha2, 0, sizeof *sha2);
-			sha2->magic = VSM_CHUNK_MAGIC;
-			sha2->len = sha->len - size;
-			bprintf(sha2->class, "%s", VSM_CLASS_FREE);
-			sha->len = size;
-		}
-
-		bprintf(sha->class, "%s", class);
-		bprintf(sha->type, "%s", type);
-		bprintf(sha->ident, "%s", ident);
-
-		vsm_release(seq);
-		return (VSM_PTR(sha));
-	}
-	return (NULL);
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-VSM__Free(const void *ptr)
-{
-	struct VSM_chunk *sha;
-	unsigned seq;
-
-	CHECK_OBJ_NOTNULL(VSM_head, VSM_HEAD_MAGIC);
-	VSM_ITER(sha)
-		if (VSM_PTR(sha) == ptr)
-			break;
-	AN(sha);
-	seq = vsm_mark();
-	bprintf(sha->class, "%s", VSM_CLASS_COOL);
-	sha->state = (unsigned)VTIM_mono();
-	vsm_release(seq);
-}
-
-/*--------------------------------------------------------------------
- * Free all allocations after the mark (ie: allocated by child).
- */
-
-void
-VSM__Clean(void)
-{
-	struct VSM_chunk *sha;
-	unsigned f, seq;
-
-	CHECK_OBJ_NOTNULL(VSM_head, VSM_HEAD_MAGIC);
-	f = 0;
-	seq = vsm_mark();
-	VSM_ITER(sha) {
-		if (f == 0 && !strcmp(sha->class, VSM_CLASS_MARK)) {
-			f = 1;
-			continue;
-		}
-		if (f == 0)
-			continue;
-		if (strcmp(sha->class, VSM_CLASS_FREE) &&
-		    strcmp(sha->class, VSM_CLASS_COOL))
-			VSM__Free(VSM_PTR(sha));
-	}
-	vsm_release(seq);
-}



More information about the varnish-commit mailing list