[master] 26f6726 Be consistent about filenames: mgt_ is a prefix
Poul-Henning Kamp
phk at FreeBSD.org
Tue May 26 10:44:41 CEST 2015
commit 26f67269a23ab67a83d30bb436784424160da1af
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue May 26 08:44:24 2015 +0000
Be consistent about filenames: mgt_ is a prefix
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 34425f1..ac3b216 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -54,7 +54,7 @@ varnishd_SOURCES = \
common/common_vsc.c \
hash/hash_classic.c \
hash/hash_critbit.c \
- hash/hash_mgt.c \
+ hash/mgt_hash.c \
hash/hash_simple_list.c \
http1/cache_http1_deliver.c \
http1/cache_http1_fetch.c \
@@ -81,12 +81,12 @@ varnishd_SOURCES = \
mgt/mgt_vcl.c \
proxy/cache_proxy_proto.c \
storage/stevedore.c \
- storage/stevedore_mgt.c \
+ storage/mgt_stevedore.c \
storage/stevedore_utils.c \
storage/storage_file.c \
storage/storage_malloc.c \
storage/storage_persistent.c \
- storage/storage_persistent_mgt.c \
+ storage/mgt_storage_persistent.c \
storage/storage_persistent_silo.c \
storage/storage_persistent_subr.c \
storage/storage_umem.c \
diff --git a/bin/varnishd/hash/hash_mgt.c b/bin/varnishd/hash/hash_mgt.c
deleted file mode 100644
index a8cc352..0000000
--- a/bin/varnishd/hash/hash_mgt.c
+++ /dev/null
@@ -1,84 +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 "config.h"
-
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include "mgt/mgt.h"
-#include "common/heritage.h"
-
-#include "hash/hash_slinger.h"
-#include "vav.h"
-
-static const struct choice hsh_choice[] = {
- { "classic", &hcl_slinger },
- { "simple", &hsl_slinger },
- { "simple_list", &hsl_slinger }, /* backwards compat */
- { "critbit", &hcb_slinger },
- { NULL, NULL }
-};
-
-/*--------------------------------------------------------------------*/
-
-void
-HSH_config(const char *h_arg)
-{
- char **av;
- int ac;
- const struct hash_slinger *hp;
-
- ASSERT_MGT();
- av = VAV_Parse(h_arg, NULL, ARGV_COMMA);
- AN(av);
-
- if (av[0] != NULL)
- ARGV_ERR("%s\n", av[0]);
-
- if (av[1] == NULL)
- ARGV_ERR("-h argument is empty\n");
-
- for (ac = 0; av[ac + 2] != NULL; ac++)
- continue;
-
- hp = pick(hsh_choice, av[1], "hash");
- CHECK_OBJ_NOTNULL(hp, SLINGER_MAGIC);
- VSB_printf(vident, ",-h%s", av[1]);
- heritage.hash = hp;
- if (hp->init != NULL)
- hp->init(ac, av + 2);
- else if (ac > 0)
- ARGV_ERR("Hash method \"%s\" takes no arguments\n",
- hp->name);
- /* NB: Don't free av, the hasher is allowed to keep it. */
-}
diff --git a/bin/varnishd/hash/mgt_hash.c b/bin/varnishd/hash/mgt_hash.c
new file mode 100644
index 0000000..a8cc352
--- /dev/null
+++ b/bin/varnishd/hash/mgt_hash.c
@@ -0,0 +1,84 @@
+/*-
+ * 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 "config.h"
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "mgt/mgt.h"
+#include "common/heritage.h"
+
+#include "hash/hash_slinger.h"
+#include "vav.h"
+
+static const struct choice hsh_choice[] = {
+ { "classic", &hcl_slinger },
+ { "simple", &hsl_slinger },
+ { "simple_list", &hsl_slinger }, /* backwards compat */
+ { "critbit", &hcb_slinger },
+ { NULL, NULL }
+};
+
+/*--------------------------------------------------------------------*/
+
+void
+HSH_config(const char *h_arg)
+{
+ char **av;
+ int ac;
+ const struct hash_slinger *hp;
+
+ ASSERT_MGT();
+ av = VAV_Parse(h_arg, NULL, ARGV_COMMA);
+ AN(av);
+
+ if (av[0] != NULL)
+ ARGV_ERR("%s\n", av[0]);
+
+ if (av[1] == NULL)
+ ARGV_ERR("-h argument is empty\n");
+
+ for (ac = 0; av[ac + 2] != NULL; ac++)
+ continue;
+
+ hp = pick(hsh_choice, av[1], "hash");
+ CHECK_OBJ_NOTNULL(hp, SLINGER_MAGIC);
+ VSB_printf(vident, ",-h%s", av[1]);
+ heritage.hash = hp;
+ if (hp->init != NULL)
+ hp->init(ac, av + 2);
+ else if (ac > 0)
+ ARGV_ERR("Hash method \"%s\" takes no arguments\n",
+ hp->name);
+ /* NB: Don't free av, the hasher is allowed to keep it. */
+}
diff --git a/bin/varnishd/storage/mgt_stevedore.c b/bin/varnishd/storage/mgt_stevedore.c
new file mode 100644
index 0000000..109290f
--- /dev/null
+++ b/bin/varnishd/storage/mgt_stevedore.c
@@ -0,0 +1,211 @@
+/*-
+ * Copyright (c) 2007-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Dag-Erling Smørgav <des at des.no>
+ *
+ * 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.
+ *
+ * STEVEDORE: one who works at or is responsible for loading and
+ * unloading ships in port. Example: "on the wharves, stevedores were
+ * unloading cargo from the far corners of the world." Origin: Spanish
+ * estibador, from estibar to pack. First Known Use: 1788
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "mgt/mgt.h"
+#include "vcli_priv.h"
+#include "mgt/mgt_cli.h"
+
+#include "storage/storage.h"
+#include "vav.h"
+
+struct stevedore_head stv_stevedores =
+ VTAILQ_HEAD_INITIALIZER(stv_stevedores);
+
+struct stevedore *stv_transient;
+
+/*--------------------------------------------------------------------*/
+
+static void
+stv_cli_list(struct cli *cli, const char * const *av, void *priv)
+{
+ struct stevedore *stv;
+
+ ASSERT_MGT();
+ (void)av;
+ (void)priv;
+ VCLI_Out(cli, "Storage devices:\n");
+ stv = stv_transient;
+ VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name);
+ VTAILQ_FOREACH(stv, &stv_stevedores, list)
+ VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name);
+}
+
+/*--------------------------------------------------------------------*/
+
+struct cli_proto cli_stv[] = {
+ { "storage.list", "storage.list", "\tList storage devices.",
+ 0, 0, "", stv_cli_list },
+ { NULL}
+};
+
+/*--------------------------------------------------------------------
+ */
+
+static void
+smp_fake_init(struct stevedore *parent, int ac, char * const *av)
+{
+
+ (void)parent;
+ (void)ac;
+ (void)av;
+ ARGV_ERR(
+ "-spersistent has been deprecated, please see:\n"
+ " https://www.varnish-cache.org/docs/trunk/phk/persistent.html\n"
+ "for details.\n"
+ );
+}
+
+
+static const struct stevedore smp_fake_stevedore = {
+ .magic = STEVEDORE_MAGIC,
+ .name = "deprecated_persistent",
+ .init = smp_fake_init,
+};
+
+
+/*--------------------------------------------------------------------
+ * Parse a stevedore argument on the form:
+ * [ name '=' ] strategy [ ',' arg ] *
+ */
+
+static const struct choice STV_choice[] = {
+ { "file", &smf_stevedore },
+ { "malloc", &sma_stevedore },
+ { "deprecated_persistent", &smp_stevedore },
+ { "persistent", &smp_fake_stevedore },
+#ifdef HAVE_LIBUMEM
+ { "umem", &smu_stevedore },
+#endif
+ { NULL, NULL }
+};
+
+void
+STV_Config(const char *spec)
+{
+ char **av;
+ const char *p, *q;
+ struct stevedore *stv;
+ const struct stevedore *stv2;
+ int ac, l;
+ static unsigned seq = 0;
+
+ ASSERT_MGT();
+ p = strchr(spec, '=');
+ q = strchr(spec, ',');
+ if (p != NULL && (q == NULL || q > p)) {
+ av = VAV_Parse(p + 1, NULL, ARGV_COMMA);
+ } else {
+ av = VAV_Parse(spec, NULL, ARGV_COMMA);
+ p = NULL;
+ }
+ AN(av);
+
+ if (av[0] != NULL)
+ ARGV_ERR("%s\n", av[0]);
+
+ if (av[1] == NULL)
+ ARGV_ERR("-s argument lacks strategy {malloc, file, ...}\n");
+
+ for (ac = 0; av[ac + 2] != NULL; ac++)
+ continue;
+
+ stv2 = pick(STV_choice, av[1], "storage");
+ AN(stv2);
+
+ /* Append strategy to ident string */
+ VSB_printf(vident, ",-s%s", av[1]);
+
+ av += 2;
+
+ CHECK_OBJ_NOTNULL(stv2, STEVEDORE_MAGIC);
+ ALLOC_OBJ(stv, STEVEDORE_MAGIC);
+ AN(stv);
+
+ *stv = *stv2;
+ AN(stv->name);
+
+ if (p == NULL)
+ bprintf(stv->ident, "s%u", seq++);
+ else {
+ l = p - spec;
+ if (l > sizeof stv->ident - 1)
+ l = sizeof stv->ident - 1;
+ bprintf(stv->ident, "%.*s", l, spec);
+ }
+
+ VTAILQ_FOREACH(stv2, &stv_stevedores, list) {
+ if (strcmp(stv2->ident, stv->ident))
+ continue;
+ ARGV_ERR("(-s%s=%s) already defined once\n",
+ stv->ident, stv->name);
+ }
+
+ if (stv->init != NULL)
+ stv->init(stv, ac, av);
+ else if (ac != 0)
+ ARGV_ERR("(-s%s) too many arguments\n", stv->name);
+
+ AN(stv->alloc);
+ if (stv->allocobj == NULL)
+ stv->allocobj = stv_default_allocobj;
+
+ if (!strcmp(stv->ident, TRANSIENT_STORAGE)) {
+ stv->transient = 1;
+ AZ(stv_transient);
+ stv_transient = stv;
+ } else {
+ VTAILQ_INSERT_TAIL(&stv_stevedores, stv, list);
+ }
+ /* NB: Do not free av, stevedore gets to keep it */
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+STV_Config_Transient(void)
+{
+
+ ASSERT_MGT();
+
+ if (stv_transient == NULL)
+ STV_Config(TRANSIENT_STORAGE "=malloc");
+}
+
+/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/storage/mgt_storage_persistent.c b/bin/varnishd/storage/mgt_storage_persistent.c
new file mode 100644
index 0000000..76d6436
--- /dev/null
+++ b/bin/varnishd/storage/mgt_storage_persistent.c
@@ -0,0 +1,209 @@
+/*-
+ * Copyright (c) 2008-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.
+ *
+ * Persistent storage method
+ *
+ * XXX: Before we start the client or maybe after it stops, we should give the
+ * XXX: stevedores a chance to examine their storage for consistency.
+ *
+ * XXX: Do we ever free the LRU-lists ?
+ */
+
+#include "config.h"
+
+#include <sys/mman.h>
+
+#include <errno.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "cache/cache.h"
+#include "storage/storage.h"
+
+#include "vsha256.h"
+
+#include "storage/storage_persistent.h"
+
+#ifndef MAP_NOCORE
+#define MAP_NOCORE 0 /* XXX Linux */
+#endif
+
+#ifndef MAP_NOSYNC
+#define MAP_NOSYNC 0 /* XXX Linux */
+#endif
+
+/*--------------------------------------------------------------------
+ * Calculate cleaner metrics from silo dimensions
+ */
+
+static void
+smp_metrics(struct smp_sc *sc)
+{
+
+ /*
+ * We do not want to loose too big chunks of the silos
+ * content when we are forced to clean a segment.
+ *
+ * For now insist that a segment covers no more than 1% of the silo.
+ *
+ * XXX: This should possibly depend on the size of the silo so
+ * XXX: trivially small silos do not run into trouble along
+ * XXX: the lines of "one object per segment".
+ */
+
+ sc->min_nseg = 10;
+ sc->max_segl = smp_stuff_len(sc, SMP_SPC_STUFF) / sc->min_nseg;
+
+ fprintf(stderr, "min_nseg = %u, max_segl = %ju\n",
+ sc->min_nseg, (uintmax_t)sc->max_segl);
+
+ /*
+ * The number of segments are limited by the size of the segment
+ * table(s) and from that follows the minimum size of a segmement.
+ */
+
+ sc->max_nseg = smp_stuff_len(sc, SMP_SEG1_STUFF) / sc->min_nseg;
+ sc->min_segl = smp_stuff_len(sc, SMP_SPC_STUFF) / sc->max_nseg;
+
+ while (sc->min_segl < sizeof(struct object)) {
+ sc->max_nseg /= 2;
+ sc->min_segl = smp_stuff_len(sc, SMP_SPC_STUFF) / sc->max_nseg;
+ }
+
+ fprintf(stderr, "max_nseg = %u, min_segl = %ju\n",
+ sc->max_nseg, (uintmax_t)sc->min_segl);
+
+ /*
+ * Set our initial aim point at the exponential average of the
+ * two extremes.
+ *
+ * XXX: This is a pretty arbitrary choice, but having no idea
+ * XXX: object count, size distribution or ttl pattern at this
+ * XXX: point, we have to do something.
+ */
+
+ sc->aim_nseg =
+ (unsigned) exp((log(sc->min_nseg) + log(sc->max_nseg))*.5);
+ sc->aim_segl = smp_stuff_len(sc, SMP_SPC_STUFF) / sc->aim_nseg;
+
+ fprintf(stderr, "aim_nseg = %u, aim_segl = %ju\n",
+ sc->aim_nseg, (uintmax_t)sc->aim_segl);
+
+ /*
+ * How much space in the free reserve pool ?
+ */
+ sc->free_reserve = sc->aim_segl * 10;
+
+ fprintf(stderr, "free_reserve = %ju\n", (uintmax_t)sc->free_reserve);
+}
+
+/*--------------------------------------------------------------------
+ * Set up persistent storage silo in the master process.
+ */
+
+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();
+
+ AZ(av[ac]);
+
+ /* Necessary alignment. See also smp_object::__filler__ */
+ assert(sizeof(struct smp_object) % 8 == 0);
+
+#define SIZOF(foo) fprintf(stderr, \
+ "sizeof(%s) = %zu = 0x%zx\n", #foo, sizeof(foo), sizeof(foo));
+ SIZOF(struct smp_ident);
+ SIZOF(struct smp_sign);
+ SIZOF(struct smp_segptr);
+ SIZOF(struct smp_object);
+#undef SIZOF
+
+ /* See comments in storage_persistent.h */
+ assert(sizeof(struct smp_ident) == SMP_IDENT_SIZE);
+
+ /* Allocate softc */
+ ALLOC_OBJ(sc, SMP_SC_MAGIC);
+ XXXAN(sc);
+ sc->parent = parent;
+ sc->fd = -1;
+ VTAILQ_INIT(&sc->segments);
+
+ /* Argument processing */
+ if (ac != 2)
+ ARGV_ERR("(-spersistent) wrong number of arguments\n");
+
+ i = STV_GetFile(av[0], &sc->fd, &sc->filename, "-spersistent");
+ if (i == 2)
+ ARGV_ERR("(-spersistent) need filename (not directory)\n");
+
+ sc->align = sizeof(void*) * 2;
+ sc->granularity = getpagesize();
+ sc->mediasize = STV_FileSize(sc->fd, av[1], &sc->granularity,
+ "-spersistent");
+
+ AZ(ftruncate(sc->fd, sc->mediasize));
+
+ /* Try to determine correct mmap address */
+ i = read(sc->fd, &sgn, sizeof sgn);
+ assert(i == sizeof sgn);
+ if (!strcmp(sgn.ident, "SILO"))
+ target = (void*)(uintptr_t)sgn.mapped;
+ else
+ target = NULL;
+
+ sc->base = (void*)mmap(target, sc->mediasize, PROT_READ|PROT_WRITE,
+ MAP_NOCORE | MAP_NOSYNC | MAP_SHARED, sc->fd, 0);
+
+ if (sc->base == MAP_FAILED)
+ ARGV_ERR("(-spersistent) failed to mmap (%s)\n",
+ strerror(errno));
+
+ smp_def_sign(sc, &sc->idn, 0, "SILO");
+ sc->ident = SIGN_DATA(&sc->idn);
+
+ i = smp_valid_silo(sc);
+ 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);
+
+ parent->priv = sc;
+
+ /* XXX: only for sendfile I guess... */
+ mgt_child_inherit(sc->fd, "storage_persistent");
+}
diff --git a/bin/varnishd/storage/stevedore_mgt.c b/bin/varnishd/storage/stevedore_mgt.c
deleted file mode 100644
index 109290f..0000000
--- a/bin/varnishd/storage/stevedore_mgt.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/*-
- * Copyright (c) 2007-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Dag-Erling Smørgav <des at des.no>
- *
- * 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.
- *
- * STEVEDORE: one who works at or is responsible for loading and
- * unloading ships in port. Example: "on the wharves, stevedores were
- * unloading cargo from the far corners of the world." Origin: Spanish
- * estibador, from estibar to pack. First Known Use: 1788
- */
-
-#include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "mgt/mgt.h"
-#include "vcli_priv.h"
-#include "mgt/mgt_cli.h"
-
-#include "storage/storage.h"
-#include "vav.h"
-
-struct stevedore_head stv_stevedores =
- VTAILQ_HEAD_INITIALIZER(stv_stevedores);
-
-struct stevedore *stv_transient;
-
-/*--------------------------------------------------------------------*/
-
-static void
-stv_cli_list(struct cli *cli, const char * const *av, void *priv)
-{
- struct stevedore *stv;
-
- ASSERT_MGT();
- (void)av;
- (void)priv;
- VCLI_Out(cli, "Storage devices:\n");
- stv = stv_transient;
- VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name);
- VTAILQ_FOREACH(stv, &stv_stevedores, list)
- VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name);
-}
-
-/*--------------------------------------------------------------------*/
-
-struct cli_proto cli_stv[] = {
- { "storage.list", "storage.list", "\tList storage devices.",
- 0, 0, "", stv_cli_list },
- { NULL}
-};
-
-/*--------------------------------------------------------------------
- */
-
-static void
-smp_fake_init(struct stevedore *parent, int ac, char * const *av)
-{
-
- (void)parent;
- (void)ac;
- (void)av;
- ARGV_ERR(
- "-spersistent has been deprecated, please see:\n"
- " https://www.varnish-cache.org/docs/trunk/phk/persistent.html\n"
- "for details.\n"
- );
-}
-
-
-static const struct stevedore smp_fake_stevedore = {
- .magic = STEVEDORE_MAGIC,
- .name = "deprecated_persistent",
- .init = smp_fake_init,
-};
-
-
-/*--------------------------------------------------------------------
- * Parse a stevedore argument on the form:
- * [ name '=' ] strategy [ ',' arg ] *
- */
-
-static const struct choice STV_choice[] = {
- { "file", &smf_stevedore },
- { "malloc", &sma_stevedore },
- { "deprecated_persistent", &smp_stevedore },
- { "persistent", &smp_fake_stevedore },
-#ifdef HAVE_LIBUMEM
- { "umem", &smu_stevedore },
-#endif
- { NULL, NULL }
-};
-
-void
-STV_Config(const char *spec)
-{
- char **av;
- const char *p, *q;
- struct stevedore *stv;
- const struct stevedore *stv2;
- int ac, l;
- static unsigned seq = 0;
-
- ASSERT_MGT();
- p = strchr(spec, '=');
- q = strchr(spec, ',');
- if (p != NULL && (q == NULL || q > p)) {
- av = VAV_Parse(p + 1, NULL, ARGV_COMMA);
- } else {
- av = VAV_Parse(spec, NULL, ARGV_COMMA);
- p = NULL;
- }
- AN(av);
-
- if (av[0] != NULL)
- ARGV_ERR("%s\n", av[0]);
-
- if (av[1] == NULL)
- ARGV_ERR("-s argument lacks strategy {malloc, file, ...}\n");
-
- for (ac = 0; av[ac + 2] != NULL; ac++)
- continue;
-
- stv2 = pick(STV_choice, av[1], "storage");
- AN(stv2);
-
- /* Append strategy to ident string */
- VSB_printf(vident, ",-s%s", av[1]);
-
- av += 2;
-
- CHECK_OBJ_NOTNULL(stv2, STEVEDORE_MAGIC);
- ALLOC_OBJ(stv, STEVEDORE_MAGIC);
- AN(stv);
-
- *stv = *stv2;
- AN(stv->name);
-
- if (p == NULL)
- bprintf(stv->ident, "s%u", seq++);
- else {
- l = p - spec;
- if (l > sizeof stv->ident - 1)
- l = sizeof stv->ident - 1;
- bprintf(stv->ident, "%.*s", l, spec);
- }
-
- VTAILQ_FOREACH(stv2, &stv_stevedores, list) {
- if (strcmp(stv2->ident, stv->ident))
- continue;
- ARGV_ERR("(-s%s=%s) already defined once\n",
- stv->ident, stv->name);
- }
-
- if (stv->init != NULL)
- stv->init(stv, ac, av);
- else if (ac != 0)
- ARGV_ERR("(-s%s) too many arguments\n", stv->name);
-
- AN(stv->alloc);
- if (stv->allocobj == NULL)
- stv->allocobj = stv_default_allocobj;
-
- if (!strcmp(stv->ident, TRANSIENT_STORAGE)) {
- stv->transient = 1;
- AZ(stv_transient);
- stv_transient = stv;
- } else {
- VTAILQ_INSERT_TAIL(&stv_stevedores, stv, list);
- }
- /* NB: Do not free av, stevedore gets to keep it */
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-STV_Config_Transient(void)
-{
-
- ASSERT_MGT();
-
- if (stv_transient == NULL)
- STV_Config(TRANSIENT_STORAGE "=malloc");
-}
-
-/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/storage/storage_persistent_mgt.c b/bin/varnishd/storage/storage_persistent_mgt.c
deleted file mode 100644
index 76d6436..0000000
--- a/bin/varnishd/storage/storage_persistent_mgt.c
+++ /dev/null
@@ -1,209 +0,0 @@
-/*-
- * Copyright (c) 2008-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.
- *
- * Persistent storage method
- *
- * XXX: Before we start the client or maybe after it stops, we should give the
- * XXX: stevedores a chance to examine their storage for consistency.
- *
- * XXX: Do we ever free the LRU-lists ?
- */
-
-#include "config.h"
-
-#include <sys/mman.h>
-
-#include <errno.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "cache/cache.h"
-#include "storage/storage.h"
-
-#include "vsha256.h"
-
-#include "storage/storage_persistent.h"
-
-#ifndef MAP_NOCORE
-#define MAP_NOCORE 0 /* XXX Linux */
-#endif
-
-#ifndef MAP_NOSYNC
-#define MAP_NOSYNC 0 /* XXX Linux */
-#endif
-
-/*--------------------------------------------------------------------
- * Calculate cleaner metrics from silo dimensions
- */
-
-static void
-smp_metrics(struct smp_sc *sc)
-{
-
- /*
- * We do not want to loose too big chunks of the silos
- * content when we are forced to clean a segment.
- *
- * For now insist that a segment covers no more than 1% of the silo.
- *
- * XXX: This should possibly depend on the size of the silo so
- * XXX: trivially small silos do not run into trouble along
- * XXX: the lines of "one object per segment".
- */
-
- sc->min_nseg = 10;
- sc->max_segl = smp_stuff_len(sc, SMP_SPC_STUFF) / sc->min_nseg;
-
- fprintf(stderr, "min_nseg = %u, max_segl = %ju\n",
- sc->min_nseg, (uintmax_t)sc->max_segl);
-
- /*
- * The number of segments are limited by the size of the segment
- * table(s) and from that follows the minimum size of a segmement.
- */
-
- sc->max_nseg = smp_stuff_len(sc, SMP_SEG1_STUFF) / sc->min_nseg;
- sc->min_segl = smp_stuff_len(sc, SMP_SPC_STUFF) / sc->max_nseg;
-
- while (sc->min_segl < sizeof(struct object)) {
- sc->max_nseg /= 2;
- sc->min_segl = smp_stuff_len(sc, SMP_SPC_STUFF) / sc->max_nseg;
- }
-
- fprintf(stderr, "max_nseg = %u, min_segl = %ju\n",
- sc->max_nseg, (uintmax_t)sc->min_segl);
-
- /*
- * Set our initial aim point at the exponential average of the
- * two extremes.
- *
- * XXX: This is a pretty arbitrary choice, but having no idea
- * XXX: object count, size distribution or ttl pattern at this
- * XXX: point, we have to do something.
- */
-
- sc->aim_nseg =
- (unsigned) exp((log(sc->min_nseg) + log(sc->max_nseg))*.5);
- sc->aim_segl = smp_stuff_len(sc, SMP_SPC_STUFF) / sc->aim_nseg;
-
- fprintf(stderr, "aim_nseg = %u, aim_segl = %ju\n",
- sc->aim_nseg, (uintmax_t)sc->aim_segl);
-
- /*
- * How much space in the free reserve pool ?
- */
- sc->free_reserve = sc->aim_segl * 10;
-
- fprintf(stderr, "free_reserve = %ju\n", (uintmax_t)sc->free_reserve);
-}
-
-/*--------------------------------------------------------------------
- * Set up persistent storage silo in the master process.
- */
-
-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();
-
- AZ(av[ac]);
-
- /* Necessary alignment. See also smp_object::__filler__ */
- assert(sizeof(struct smp_object) % 8 == 0);
-
-#define SIZOF(foo) fprintf(stderr, \
- "sizeof(%s) = %zu = 0x%zx\n", #foo, sizeof(foo), sizeof(foo));
- SIZOF(struct smp_ident);
- SIZOF(struct smp_sign);
- SIZOF(struct smp_segptr);
- SIZOF(struct smp_object);
-#undef SIZOF
-
- /* See comments in storage_persistent.h */
- assert(sizeof(struct smp_ident) == SMP_IDENT_SIZE);
-
- /* Allocate softc */
- ALLOC_OBJ(sc, SMP_SC_MAGIC);
- XXXAN(sc);
- sc->parent = parent;
- sc->fd = -1;
- VTAILQ_INIT(&sc->segments);
-
- /* Argument processing */
- if (ac != 2)
- ARGV_ERR("(-spersistent) wrong number of arguments\n");
-
- i = STV_GetFile(av[0], &sc->fd, &sc->filename, "-spersistent");
- if (i == 2)
- ARGV_ERR("(-spersistent) need filename (not directory)\n");
-
- sc->align = sizeof(void*) * 2;
- sc->granularity = getpagesize();
- sc->mediasize = STV_FileSize(sc->fd, av[1], &sc->granularity,
- "-spersistent");
-
- AZ(ftruncate(sc->fd, sc->mediasize));
-
- /* Try to determine correct mmap address */
- i = read(sc->fd, &sgn, sizeof sgn);
- assert(i == sizeof sgn);
- if (!strcmp(sgn.ident, "SILO"))
- target = (void*)(uintptr_t)sgn.mapped;
- else
- target = NULL;
-
- sc->base = (void*)mmap(target, sc->mediasize, PROT_READ|PROT_WRITE,
- MAP_NOCORE | MAP_NOSYNC | MAP_SHARED, sc->fd, 0);
-
- if (sc->base == MAP_FAILED)
- ARGV_ERR("(-spersistent) failed to mmap (%s)\n",
- strerror(errno));
-
- smp_def_sign(sc, &sc->idn, 0, "SILO");
- sc->ident = SIGN_DATA(&sc->idn);
-
- i = smp_valid_silo(sc);
- 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);
-
- parent->priv = sc;
-
- /* XXX: only for sendfile I guess... */
- mgt_child_inherit(sc->fd, "storage_persistent");
-}
More information about the varnish-commit
mailing list