r3804 - in trunk/varnish-cache: bin/varnishd include

phk at projects.linpro.no phk at projects.linpro.no
Sun Feb 22 18:48:25 CET 2009


Author: phk
Date: 2009-02-22 18:48:24 +0100 (Sun, 22 Feb 2009)
New Revision: 3804

Added:
   trunk/varnish-cache/bin/varnishd/storage_persistent.c
   trunk/varnish-cache/include/persistent.h
Modified:
   trunk/varnish-cache/bin/varnishd/Makefile.am
Log:
Bring in the first inkling of the persistent storage module



Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am	2009-02-22 16:36:37 UTC (rev 3803)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am	2009-02-22 17:48:24 UTC (rev 3804)
@@ -53,6 +53,7 @@
 	stevedore.c \
 	storage_file.c \
 	storage_malloc.c \
+	storage_persistent.c \
 	storage_synth.c \
 	storage_umem.c \
 	stevedore_utils.c \

Added: trunk/varnish-cache/bin/varnishd/storage_persistent.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_persistent.c	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishd/storage_persistent.c	2009-02-22 17:48:24 UTC (rev 3804)
@@ -0,0 +1,62 @@
+/*-
+ * Copyright (c) 2008-2009 Linpro 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.
+ *
+ * $Id$
+ *
+ * Persistent storage method
+ */
+
+#include "config.h"
+
+#include <stdint.h>
+#include <sys/param.h>
+
+#include "cache.h"
+#include "stevedore.h"
+
+#include "persistent.h"
+
+static void
+smp_init(struct stevedore *parent, int ac, char * const *av)
+{
+	
+	(void)parent;
+	(void)ac;
+	(void)av;
+	assert(sizeof(struct smp_ident) == SMP_IDENT_SIZE);
+	assert(sizeof(struct smp_object) == SMP_OBJECT_SIZE);
+}
+
+struct stevedore smp_stevedore = {
+	.magic	=	STEVEDORE_MAGIC,
+	.name	=	"persistent",
+	.init	=	smp_init,
+	// .open	=	smf_open,
+	// .alloc	=	smf_alloc,
+	// .trim	=	smf_trim,
+	// .free	=	smf_free,
+};

Added: trunk/varnish-cache/include/persistent.h
===================================================================
--- trunk/varnish-cache/include/persistent.h	                        (rev 0)
+++ trunk/varnish-cache/include/persistent.h	2009-02-22 17:48:24 UTC (rev 3804)
@@ -0,0 +1,117 @@
+/*-
+ * Copyright (c) 2008-2009 Linpro 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.
+ *
+ * $Id$
+ */
+
+/*
+ * Overall layout:
+ *
+ *	struct smp_ident;		Identification and geometry 
+ *	sha256[...]			checksum of same
+ *
+ *	struct smp_segment[N];		Segment table
+ *	sha256[...]			checksum of same
+ *
+ *	banspace_1;			First ban-space
+ *	sha256[...]			checksum of same
+ *
+ *	banspace_2;			Second ban-space
+ *	sha256[...]			checksum of same
+ *
+ *	N segments {
+ *		struct smp_object[M]	Objects in segment
+ *		sha256[...]		checksum of same
+ *		objspace
+ *	}
+ */
+
+/*
+ * The identblock is located in the first sector of the storage space.
+ * This is written once and not subsequently modified in normal operation.
+ * It is immediately followed by a SHA256sum of the structure, as stored.
+ */
+
+struct smp_ident {
+	char			ident[32];	/* Human readable ident
+						 * so people and programs
+						 * can tell what the file
+						 * or device contains.
+						 */
+
+	uint32_t		byte_order;	/* 0x12345678 */
+
+	uint32_t		size;		/* sizeof(struct smp_ident) */
+
+	uint32_t		major_version;
+
+	uint32_t		minor_version;
+
+	uint64_t		mediasize;	/* ... in bytes */
+
+	uint32_t		granularity;	/* smallest ... in bytes */
+
+	/* XXX: ptr to bans table */
+	/* XXX: ptr to segment table */
+};
+
+#define SMP_IDENT_SIZE		(32 + 4 + 4 + 4 + 4 + 8 + 4 )
+
+/*
+ * A segment descriptor.
+ */
+
+struct smp_segment {
+	uint64_t		offset;
+	uint64_t		length;
+};
+
+#define SMP_SEGMENT_SIZE	(8+8)
+
+/*
+ * Ban description
+ */
+
+struct smp_ban {
+	double			ttl;
+	uint16_t		length;
+	uint8_t			valid;
+};
+
+/*
+ * An object descriptor
+ */
+
+struct smp_object {
+	unsigned char		hash[32];
+	double  		ttl;
+	double  		ban;
+	uint64_t		offset;
+	uint64_t		len;
+};
+
+#define SMP_OBJECT_SIZE		(32 + 8 + 8 + 8 + 8)



More information about the varnish-commit mailing list