From 509abfe865c0d2e0540b59c37accf327e83b8726 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 22 Feb 2009 17:48:24 +0000 Subject: [PATCH] Bring in the first inkling of the persistent storage module git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3804 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/Makefile.am | 1 + .../bin/varnishd/storage_persistent.c | 62 ++++++++++ varnish-cache/include/persistent.h | 117 ++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 varnish-cache/bin/varnishd/storage_persistent.c create mode 100644 varnish-cache/include/persistent.h diff --git a/varnish-cache/bin/varnishd/Makefile.am b/varnish-cache/bin/varnishd/Makefile.am index c04105d0..2c445fbd 100644 --- a/varnish-cache/bin/varnishd/Makefile.am +++ b/varnish-cache/bin/varnishd/Makefile.am @@ -53,6 +53,7 @@ varnishd_SOURCES = \ stevedore.c \ storage_file.c \ storage_malloc.c \ + storage_persistent.c \ storage_synth.c \ storage_umem.c \ stevedore_utils.c \ diff --git a/varnish-cache/bin/varnishd/storage_persistent.c b/varnish-cache/bin/varnishd/storage_persistent.c new file mode 100644 index 00000000..b039ec8b --- /dev/null +++ b/varnish-cache/bin/varnishd/storage_persistent.c @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2008-2009 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * 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 +#include + +#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, +}; diff --git a/varnish-cache/include/persistent.h b/varnish-cache/include/persistent.h new file mode 100644 index 00000000..3d92ff91 --- /dev/null +++ b/varnish-cache/include/persistent.h @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2008-2009 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * 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) -- 2.39.5