[master] 625e615 Split vapi/vsm_int.h into those (minor) bits which we have to reveal to vapi/vsm.h for it to work, and the truly private parts needed to implement things internally (vsm_priv.h)
Poul-Henning Kamp
phk at FreeBSD.org
Wed Mar 4 11:55:32 CET 2015
commit 625e61506820149c689ae4b8af0ebd447be7b77c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Mar 4 10:54:03 2015 +0000
Split vapi/vsm_int.h into those (minor) bits which we have to
reveal to vapi/vsm.h for it to work, and the truly private parts
needed to implement things internally (vsm_priv.h)
diff --git a/bin/varnishd/common/common_vsm.c b/bin/varnishd/common/common_vsm.c
index 9d4863e..94c3e3c 100644
--- a/bin/varnishd/common/common_vsm.c
+++ b/bin/varnishd/common/common_vsm.c
@@ -42,7 +42,7 @@
#include "common.h"
-#include "vapi/vsm_int.h"
+#include "vsm_priv.h"
#include "vmb.h"
#include "vtim.h"
diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c
index 04634b8..837e165 100644
--- a/bin/varnishd/mgt/mgt_shmem.c
+++ b/bin/varnishd/mgt/mgt_shmem.c
@@ -45,7 +45,7 @@
#include "common/params.h"
#include "flopen.h"
-#include "vapi/vsm_int.h"
+#include "vsm_priv.h"
#include "vmb.h"
#include "vfil.h"
diff --git a/include/Makefile.am b/include/Makefile.am
index bda6e37..ec6c2aa 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -79,6 +79,7 @@ nobase_noinst_HEADERS = \
vnum.h \
vpf.h \
vrnd.h \
+ vsm_priv.h \
vsub.h \
vss.h \
vtcp.h \
diff --git a/include/vapi/vsm_int.h b/include/vapi/vsm_int.h
index 11c40e4..4b84c44 100644
--- a/include/vapi/vsm_int.h
+++ b/include/vapi/vsm_int.h
@@ -26,71 +26,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * Define the layout of the shared memory log segment.
+ * Define the internal details which must be kept in sync between
+ * vsm_priv.h and vapi/vsm.h, and this file SHALL not be included
+ * from anywhere but those two files.
*
* NB: THIS IS NOT A PUBLIC API TO VARNISH!
*
- * There is a lot of diplomacy and protocol involved with the VSM segment
- * since there is no way to (and no desire to!) lock between the readers
- * and the writer.
- *
- * In particular we want the readers to seamlessly jump from one VSM instance
- * to another when the child restarts.
- *
- * The VSM segment life-cycle is:
- *
- * Manager creates VSM file under temp name
- *
- * Temp VSM file is initialized such that VSM_head is consistent
- * with a non-zero alloc_seq
- *
- * Manager renames Temp VSM file to correct filename as atomic
- * operation.
- *
- * When manager abandons VSM file, alloc_seq is set to zero, which
- * never happens in any other circumstances.
- *
- * If a manager is started and finds and old abandoned VSM segment
- * it will zero the alloc_seq in it, before replacing the file.
- *
- * Subscribers will have to monitor three things to make sure they look at
- * the right thing: The alloc_seq field, the age counter and the dev+inode
- * of the path-name. The former check is by far the cheaper, the second
- * can be used to check that Varnishd is still alive and the last check
- * should only be employed when lack of activity in the VSM segment raises
- * suspicion that something has happened.
- *
- * The allocations ("chunks") in the VSM forms a linked list, starting with
- * VSM_head->first, with the first/next fields being byte offsets relative
- * to the start of the VSM segment.
- *
- * The last chunk on the list, has next == 0.
- *
- * New chunks are appended to the list, no matter where in the VSM
- * they happen to be allocated.
- *
- * Chunk allocation sequence is:
- * Find free space
- * Zero payload
- * Init Chunk header
- * Write memory barrier
- * update hdr->first or $last->next pointer
- * hdr->alloc_seq changes
- * Write memory barrier
- *
- * Chunk contents should be designed so that zero bytes are not mistaken
- * for valid contents.
- *
- * Chunk deallocation sequence is:
- * update hdr->first or $prev->next pointer
- * Write memory barrier
- * this->len = 0
- * hdr->alloc_seq changes
- * Write memory barrier
- *
- * The space occupied by the chunk is put on a cooling list and is not
- * recycled for at least a minute.
- *
*/
#ifndef VSM_INT_H_INCLUDED
@@ -100,24 +41,4 @@
#define VSM_MARKER_LEN 8
#define VSM_IDENT_LEN 128
-struct VSM_chunk {
-#define VSM_CHUNK_MARKER "VSMCHUNK"
- char marker[VSM_MARKER_LEN];
- ssize_t len; /* Incl VSM_chunk */
- ssize_t next; /* Offset in shmem */
- char class[VSM_MARKER_LEN];
- char type[VSM_MARKER_LEN];
- char ident[VSM_IDENT_LEN];
-};
-
-struct VSM_head {
-#define VSM_HEAD_MARKER "VSMHEAD0" /* Incr. as version# */
- char marker[VSM_MARKER_LEN];
- ssize_t hdrsize;
- ssize_t shm_size;
- ssize_t first; /* Offset, first chunk */
- unsigned alloc_seq;
- uint64_t age;
-};
-
#endif /* VSM_INT_H_INCLUDED */
diff --git a/include/vsm_priv.h b/include/vsm_priv.h
new file mode 100644
index 0000000..0cc1a9f
--- /dev/null
+++ b/include/vsm_priv.h
@@ -0,0 +1,121 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2014 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.
+ *
+ * Define the layout of the shared memory log segment.
+ *
+ * NB: THIS IS NOT A PUBLIC API TO VARNISH!
+ *
+ * There is a lot of diplomacy and protocol involved with the VSM segment
+ * since there is no way to (and no desire to!) lock between the readers
+ * and the writer.
+ *
+ * In particular we want the readers to seamlessly jump from one VSM instance
+ * to another when the child restarts.
+ *
+ * The VSM segment life-cycle is:
+ *
+ * Manager creates VSM file under temp name
+ *
+ * Temp VSM file is initialized such that VSM_head is consistent
+ * with a non-zero alloc_seq
+ *
+ * Manager renames Temp VSM file to correct filename as atomic
+ * operation.
+ *
+ * When manager abandons VSM file, alloc_seq is set to zero, which
+ * never happens in any other circumstances.
+ *
+ * If a manager is started and finds and old abandoned VSM segment
+ * it will zero the alloc_seq in it, before replacing the file.
+ *
+ * Subscribers will have to monitor three things to make sure they look at
+ * the right thing: The alloc_seq field, the age counter and the dev+inode
+ * of the path-name. The former check is by far the cheaper, the second
+ * can be used to check that Varnishd is still alive and the last check
+ * should only be employed when lack of activity in the VSM segment raises
+ * suspicion that something has happened.
+ *
+ * The allocations ("chunks") in the VSM forms a linked list, starting with
+ * VSM_head->first, with the first/next fields being byte offsets relative
+ * to the start of the VSM segment.
+ *
+ * The last chunk on the list, has next == 0.
+ *
+ * New chunks are appended to the list, no matter where in the VSM
+ * they happen to be allocated.
+ *
+ * Chunk allocation sequence is:
+ * Find free space
+ * Zero payload
+ * Init Chunk header
+ * Write memory barrier
+ * update hdr->first or $last->next pointer
+ * hdr->alloc_seq changes
+ * Write memory barrier
+ *
+ * Chunk contents should be designed so that zero bytes are not mistaken
+ * for valid contents.
+ *
+ * Chunk deallocation sequence is:
+ * update hdr->first or $prev->next pointer
+ * Write memory barrier
+ * this->len = 0
+ * hdr->alloc_seq changes
+ * Write memory barrier
+ *
+ * The space occupied by the chunk is put on a cooling list and is not
+ * recycled for at least a minute.
+ *
+ */
+
+#ifndef VSM_PRIV_H_INCLUDED
+#define VSM_PRIV_H_INCLUDED
+
+#include <vapi/vsm_int.h>
+
+struct VSM_chunk {
+#define VSM_CHUNK_MARKER "VSMCHUNK"
+ char marker[VSM_MARKER_LEN];
+ ssize_t len; /* Incl VSM_chunk */
+ ssize_t next; /* Offset in shmem */
+ char class[VSM_MARKER_LEN];
+ char type[VSM_MARKER_LEN];
+ char ident[VSM_IDENT_LEN];
+};
+
+struct VSM_head {
+#define VSM_HEAD_MARKER "VSMHEAD0" /* Incr. as version# */
+ char marker[VSM_MARKER_LEN];
+ ssize_t hdrsize;
+ ssize_t shm_size;
+ ssize_t first; /* Offset, first chunk */
+ unsigned alloc_seq;
+ uint64_t age;
+};
+
+#endif /* VSM_PRIV_H_INCLUDED */
diff --git a/lib/libvarnish/vin.c b/lib/libvarnish/vin.c
index 4dba302..be5b0bd 100644
--- a/lib/libvarnish/vin.c
+++ b/lib/libvarnish/vin.c
@@ -37,7 +37,7 @@
#include <string.h>
#include <unistd.h>
-#include "vapi/vsm_int.h"
+#include "vsm_priv.h"
#include "vas.h"
#include "vdef.h"
#include "vin.h"
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index 38dd5fb..6505704 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -44,7 +44,6 @@
#include "vapi/vsc.h"
#include "vapi/vsm.h"
-#include "vapi/vsm_int.h"
#include "vqueue.h"
#include "vsm_api.h"
diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c
index 949028f..92f65ac 100644
--- a/lib/libvarnishapi/vsl.c
+++ b/lib/libvarnishapi/vsl.c
@@ -47,7 +47,6 @@
#include "vapi/vsm.h"
#include "vapi/vsl.h"
-#include "vapi/vsm_int.h"
#include "vbm.h"
#include "vmb.h"
#include "vre.h"
diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c
index f05f184..2e4532e 100644
--- a/lib/libvarnishapi/vsm.c
+++ b/lib/libvarnishapi/vsm.c
@@ -47,7 +47,7 @@
#include "vas.h"
#include "vapi/vsm.h"
-#include "vapi/vsm_int.h"
+#include "vsm_priv.h"
#include "vtim.h"
#include "vin.h"
#include "vsb.h"
More information about the varnish-commit
mailing list