[master] 0f13e7e Split stevedore.c in a cache and a worker source file.
Poul-Henning Kamp
phk at varnish-cache.org
Tue Nov 15 22:08:03 CET 2011
commit 0f13e7ebf1bd4f2e6f9e3b91353c407ba9b8295e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Nov 15 21:07:39 2011 +0000
Split stevedore.c in a cache and a worker source file.
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 850a18a..359373d 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -64,6 +64,7 @@ varnishd_SOURCES = \
mgt/mgt_shmem.c \
mgt/mgt_vcc.c \
storage/stevedore.c \
+ storage/stevedore_mgt.c \
storage/stevedore_utils.c \
storage/storage_file.c \
storage/storage_malloc.c \
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 653fe77..129dbf0 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -114,9 +114,6 @@ struct worker;
#define DIGEST_LEN 32
-/* Name of transient storage */
-#define TRANSIENT_STORAGE "Transient"
-
/*--------------------------------------------------------------------
* Pointer aligment magic
*/
diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h
index 4e56a40..ff06c64 100644
--- a/bin/varnishd/common/common.h
+++ b/bin/varnishd/common/common.h
@@ -42,6 +42,9 @@
struct cli;
+/* Name of transient storage */
+#define TRANSIENT_STORAGE "Transient"
+
extern pid_t mgt_pid;
#define ASSERT_MGT() do { assert(getpid() == mgt_pid);} while (0)
@@ -68,13 +71,6 @@ void mgt_child_inherit(int fd, const char *what);
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 */
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 54352a0..4aec482 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -57,13 +57,19 @@ void mgt_cli_master(const char *M_arg);
void mgt_cli_secret(const char *S_arg);
void mgt_cli_close_all(void);
+/* mgt_main.c */
+struct choice {
+ const char *name;
+ const void *ptr;
+};
+const void *pick(const struct choice *cp, const char *which, const char *kind);
+
/* mgt_param.c */
void MCF_ParamInit(struct cli *);
void MCF_ParamSet(struct cli *, const char *param, const char *val);
void MCF_DumpRst(void);
extern struct params mgt_param;
-
/* mgt_sandbox.c */
void mgt_sandbox(void);
@@ -88,7 +94,6 @@ extern const char *mgt_vcl_dir;
extern const char *mgt_vmod_dir;
extern unsigned mgt_vcc_err_unref;
-
#define REPORT0(pri, fmt) \
do { \
fprintf(stderr, fmt "\n"); \
@@ -105,7 +110,6 @@ extern unsigned mgt_vcc_err_unref;
#define VSM_Free(a) VSM__Free(a)
#define VSM_Clean() VSM__Clean()
-
#if defined(PTHREAD_CANCELED) || defined(PTHREAD_MUTEX_DEFAULT)
#error "Keep pthreads out of in manager process"
#endif
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 3978f64..9b22cd3 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -39,18 +39,12 @@
#include "cache/cache.h"
#include "storage/storage.h"
-#include "vav.h"
#include "vcli_priv.h"
#include "vrt.h"
#include "vrt_obj.h"
-static VTAILQ_HEAD(, stevedore) stevedores =
- VTAILQ_HEAD_INITIALIZER(stevedores);
-
static const struct stevedore * volatile stv_next;
-static struct stevedore *stv_transient;
-
/*---------------------------------------------------------------------
* Default objcore methods
*/
@@ -130,7 +124,7 @@ stv_pick_stevedore(const struct sess *sp, const char **hint)
AN(hint);
if (*hint != NULL && **hint != '\0') {
- VTAILQ_FOREACH(stv, &stevedores, list) {
+ VTAILQ_FOREACH(stv, &stv_stevedores, list) {
if (!strcmp(stv->ident, *hint))
return (stv);
}
@@ -144,7 +138,7 @@ stv_pick_stevedore(const struct sess *sp, const char **hint)
/* pick a stevedore and bump the head along */
stv = VTAILQ_NEXT(stv_next, list);
if (stv == NULL)
- stv = VTAILQ_FIRST(&stevedores);
+ stv = VTAILQ_FIRST(&stv_stevedores);
AN(stv);
AN(stv->name);
stv_next = stv;
@@ -271,7 +265,7 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
* implement persistent storage can rely on.
*/
-static struct object *
+struct object *
stv_default_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
const struct stv_objsecrets *soc)
{
@@ -402,7 +396,7 @@ STV_open(void)
{
struct stevedore *stv;
- VTAILQ_FOREACH(stv, &stevedores, list) {
+ VTAILQ_FOREACH(stv, &stv_stevedores, list) {
stv->lru = LRU_Alloc();
if (stv->open != NULL)
stv->open(stv);
@@ -412,6 +406,7 @@ STV_open(void)
stv->lru = LRU_Alloc();
stv->open(stv);
}
+ stv_next = VTAILQ_FIRST(&stv_stevedores);
}
void
@@ -419,7 +414,7 @@ STV_close(void)
{
struct stevedore *stv;
- VTAILQ_FOREACH(stv, &stevedores, list)
+ VTAILQ_FOREACH(stv, &stv_stevedores, list)
if (stv->close != NULL)
stv->close(stv);
stv = stv_transient;
@@ -427,113 +422,6 @@ STV_close(void)
stv->close(stv);
}
-/*--------------------------------------------------------------------
- * Parse a stevedore argument on the form:
- * [ name '=' ] strategy [ ',' arg ] *
- */
-
-static const struct choice STV_choice[] = {
- { "file", &smf_stevedore },
- { "malloc", &sma_stevedore },
- { "persistent", &smp_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);
- AN(stv->alloc);
- if (stv->allocobj == NULL)
- stv->allocobj = stv_default_allocobj;
-
- 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, &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);
-
- if (!strcmp(stv->ident, TRANSIENT_STORAGE)) {
- stv->transient = 1;
- AZ(stv_transient);
- stv_transient = stv;
- } else {
- VTAILQ_INSERT_TAIL(&stevedores, stv, list);
- if (!stv_next)
- stv_next = VTAILQ_FIRST(&stevedores);
- }
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-STV_Config_Transient(void)
-{
-
- ASSERT_MGT();
-
- if (stv_transient == NULL)
- STV_Config(TRANSIENT_STORAGE "=malloc");
-}
-
/*--------------------------------------------------------------------*/
static void
@@ -547,7 +435,7 @@ stv_cli_list(struct cli *cli, const char * const *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, &stevedores, list)
+ VTAILQ_FOREACH(stv, &stv_stevedores, list)
VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name);
}
@@ -568,7 +456,7 @@ stv_find(const char *nm)
{
const struct stevedore *stv;
- VTAILQ_FOREACH(stv, &stevedores, list)
+ VTAILQ_FOREACH(stv, &stv_stevedores, list)
if (!strcmp(stv->ident, nm))
return (stv);
if (!strcmp(TRANSIENT_STORAGE, nm))
diff --git a/bin/varnishd/storage/stevedore_mgt.c b/bin/varnishd/storage/stevedore_mgt.c
new file mode 100644
index 0000000..fc0d6a6
--- /dev/null
+++ b/bin/varnishd/storage/stevedore_mgt.c
@@ -0,0 +1,156 @@
+/*-
+ * 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 "storage/storage.h"
+#include "vav.h"
+
+struct stevedore_head stv_stevedores =
+ VTAILQ_HEAD_INITIALIZER(stv_stevedores);
+
+struct stevedore *stv_transient;
+
+/*--------------------------------------------------------------------
+ * Parse a stevedore argument on the form:
+ * [ name '=' ] strategy [ ',' arg ] *
+ */
+
+static const struct choice STV_choice[] = {
+ { "file", &smf_stevedore },
+ { "malloc", &sma_stevedore },
+ { "persistent", &smp_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);
+ AN(stv->alloc);
+ if (stv->allocobj == NULL)
+ stv->allocobj = stv_default_allocobj;
+
+ 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);
+
+ if (!strcmp(stv->ident, TRANSIENT_STORAGE)) {
+ stv->transient = 1;
+ AZ(stv_transient);
+ stv_transient = stv;
+ } else {
+ VTAILQ_INSERT_TAIL(&stv_stevedores, stv, list);
+ }
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+STV_Config_Transient(void)
+{
+
+ ASSERT_MGT();
+
+ if (stv_transient == NULL)
+ STV_Config(TRANSIENT_STORAGE "=malloc");
+}
+
+/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index 80cad13..a813a36 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -50,6 +50,8 @@ typedef void storage_close_f(const struct stevedore *);
#include "tbl/vrt_stv_var.h"
#undef VRTSTVTYPE
+extern storage_allocobj_f stv_default_allocobj;
+
/*--------------------------------------------------------------------*/
struct stevedore {
@@ -78,6 +80,11 @@ struct stevedore {
char ident[16]; /* XXX: match VSM_chunk.ident */
};
+VTAILQ_HEAD(stevedore_head, stevedore);
+
+extern struct stevedore_head stv_stevedores;
+extern struct stevedore *stv_transient;
+
/*--------------------------------------------------------------------*/
int STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx);
uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity,
More information about the varnish-commit
mailing list