Commit 0f13e7eb authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Split stevedore.c in a cache and a worker source file.

parent 5cfe903c
...@@ -64,6 +64,7 @@ varnishd_SOURCES = \ ...@@ -64,6 +64,7 @@ varnishd_SOURCES = \
mgt/mgt_shmem.c \ mgt/mgt_shmem.c \
mgt/mgt_vcc.c \ mgt/mgt_vcc.c \
storage/stevedore.c \ storage/stevedore.c \
storage/stevedore_mgt.c \
storage/stevedore_utils.c \ storage/stevedore_utils.c \
storage/storage_file.c \ storage/storage_file.c \
storage/storage_malloc.c \ storage/storage_malloc.c \
......
...@@ -114,9 +114,6 @@ struct worker; ...@@ -114,9 +114,6 @@ struct worker;
#define DIGEST_LEN 32 #define DIGEST_LEN 32
/* Name of transient storage */
#define TRANSIENT_STORAGE "Transient"
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Pointer aligment magic * Pointer aligment magic
*/ */
......
...@@ -42,6 +42,9 @@ ...@@ -42,6 +42,9 @@
struct cli; struct cli;
/* Name of transient storage */
#define TRANSIENT_STORAGE "Transient"
extern pid_t mgt_pid; extern pid_t mgt_pid;
#define ASSERT_MGT() do { assert(getpid() == mgt_pid);} while (0) #define ASSERT_MGT() do { assert(getpid() == mgt_pid);} while (0)
...@@ -68,13 +71,6 @@ void mgt_child_inherit(int fd, const char *what); ...@@ -68,13 +71,6 @@ void mgt_child_inherit(int fd, const char *what);
exit(2); \ exit(2); \
} while (0); } 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) #define NEEDLESS_RETURN(foo) return (foo)
/* stevedore.c */ /* stevedore.c */
......
...@@ -57,13 +57,19 @@ void mgt_cli_master(const char *M_arg); ...@@ -57,13 +57,19 @@ void mgt_cli_master(const char *M_arg);
void mgt_cli_secret(const char *S_arg); void mgt_cli_secret(const char *S_arg);
void mgt_cli_close_all(void); 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 */ /* mgt_param.c */
void MCF_ParamInit(struct cli *); void MCF_ParamInit(struct cli *);
void MCF_ParamSet(struct cli *, const char *param, const char *val); void MCF_ParamSet(struct cli *, const char *param, const char *val);
void MCF_DumpRst(void); void MCF_DumpRst(void);
extern struct params mgt_param; extern struct params mgt_param;
/* mgt_sandbox.c */ /* mgt_sandbox.c */
void mgt_sandbox(void); void mgt_sandbox(void);
...@@ -88,7 +94,6 @@ extern const char *mgt_vcl_dir; ...@@ -88,7 +94,6 @@ extern const char *mgt_vcl_dir;
extern const char *mgt_vmod_dir; extern const char *mgt_vmod_dir;
extern unsigned mgt_vcc_err_unref; extern unsigned mgt_vcc_err_unref;
#define REPORT0(pri, fmt) \ #define REPORT0(pri, fmt) \
do { \ do { \
fprintf(stderr, fmt "\n"); \ fprintf(stderr, fmt "\n"); \
...@@ -105,7 +110,6 @@ extern unsigned mgt_vcc_err_unref; ...@@ -105,7 +110,6 @@ extern unsigned mgt_vcc_err_unref;
#define VSM_Free(a) VSM__Free(a) #define VSM_Free(a) VSM__Free(a)
#define VSM_Clean() VSM__Clean() #define VSM_Clean() VSM__Clean()
#if defined(PTHREAD_CANCELED) || defined(PTHREAD_MUTEX_DEFAULT) #if defined(PTHREAD_CANCELED) || defined(PTHREAD_MUTEX_DEFAULT)
#error "Keep pthreads out of in manager process" #error "Keep pthreads out of in manager process"
#endif #endif
...@@ -39,18 +39,12 @@ ...@@ -39,18 +39,12 @@
#include "cache/cache.h" #include "cache/cache.h"
#include "storage/storage.h" #include "storage/storage.h"
#include "vav.h"
#include "vcli_priv.h" #include "vcli_priv.h"
#include "vrt.h" #include "vrt.h"
#include "vrt_obj.h" #include "vrt_obj.h"
static VTAILQ_HEAD(, stevedore) stevedores =
VTAILQ_HEAD_INITIALIZER(stevedores);
static const struct stevedore * volatile stv_next; static const struct stevedore * volatile stv_next;
static struct stevedore *stv_transient;
/*--------------------------------------------------------------------- /*---------------------------------------------------------------------
* Default objcore methods * Default objcore methods
*/ */
...@@ -130,7 +124,7 @@ stv_pick_stevedore(const struct sess *sp, const char **hint) ...@@ -130,7 +124,7 @@ stv_pick_stevedore(const struct sess *sp, const char **hint)
AN(hint); AN(hint);
if (*hint != NULL && **hint != '\0') { if (*hint != NULL && **hint != '\0') {
VTAILQ_FOREACH(stv, &stevedores, list) { VTAILQ_FOREACH(stv, &stv_stevedores, list) {
if (!strcmp(stv->ident, *hint)) if (!strcmp(stv->ident, *hint))
return (stv); return (stv);
} }
...@@ -144,7 +138,7 @@ stv_pick_stevedore(const struct sess *sp, const char **hint) ...@@ -144,7 +138,7 @@ stv_pick_stevedore(const struct sess *sp, const char **hint)
/* pick a stevedore and bump the head along */ /* pick a stevedore and bump the head along */
stv = VTAILQ_NEXT(stv_next, list); stv = VTAILQ_NEXT(stv_next, list);
if (stv == NULL) if (stv == NULL)
stv = VTAILQ_FIRST(&stevedores); stv = VTAILQ_FIRST(&stv_stevedores);
AN(stv); AN(stv);
AN(stv->name); AN(stv->name);
stv_next = stv; stv_next = stv;
...@@ -271,7 +265,7 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot, ...@@ -271,7 +265,7 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
* implement persistent storage can rely on. * implement persistent storage can rely on.
*/ */
static struct object * struct object *
stv_default_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot, stv_default_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
const struct stv_objsecrets *soc) const struct stv_objsecrets *soc)
{ {
...@@ -402,7 +396,7 @@ STV_open(void) ...@@ -402,7 +396,7 @@ STV_open(void)
{ {
struct stevedore *stv; struct stevedore *stv;
VTAILQ_FOREACH(stv, &stevedores, list) { VTAILQ_FOREACH(stv, &stv_stevedores, list) {
stv->lru = LRU_Alloc(); stv->lru = LRU_Alloc();
if (stv->open != NULL) if (stv->open != NULL)
stv->open(stv); stv->open(stv);
...@@ -412,6 +406,7 @@ STV_open(void) ...@@ -412,6 +406,7 @@ STV_open(void)
stv->lru = LRU_Alloc(); stv->lru = LRU_Alloc();
stv->open(stv); stv->open(stv);
} }
stv_next = VTAILQ_FIRST(&stv_stevedores);
} }
void void
...@@ -419,7 +414,7 @@ STV_close(void) ...@@ -419,7 +414,7 @@ STV_close(void)
{ {
struct stevedore *stv; struct stevedore *stv;
VTAILQ_FOREACH(stv, &stevedores, list) VTAILQ_FOREACH(stv, &stv_stevedores, list)
if (stv->close != NULL) if (stv->close != NULL)
stv->close(stv); stv->close(stv);
stv = stv_transient; stv = stv_transient;
...@@ -427,113 +422,6 @@ STV_close(void) ...@@ -427,113 +422,6 @@ STV_close(void)
stv->close(stv); 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 static void
...@@ -547,7 +435,7 @@ stv_cli_list(struct cli *cli, const char * const *av, void *priv) ...@@ -547,7 +435,7 @@ stv_cli_list(struct cli *cli, const char * const *av, void *priv)
VCLI_Out(cli, "Storage devices:\n"); VCLI_Out(cli, "Storage devices:\n");
stv = stv_transient; stv = stv_transient;
VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name); 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); VCLI_Out(cli, "\tstorage.%s = %s\n", stv->ident, stv->name);
} }
...@@ -568,7 +456,7 @@ stv_find(const char *nm) ...@@ -568,7 +456,7 @@ stv_find(const char *nm)
{ {
const struct stevedore *stv; const struct stevedore *stv;
VTAILQ_FOREACH(stv, &stevedores, list) VTAILQ_FOREACH(stv, &stv_stevedores, list)
if (!strcmp(stv->ident, nm)) if (!strcmp(stv->ident, nm))
return (stv); return (stv);
if (!strcmp(TRANSIENT_STORAGE, nm)) if (!strcmp(TRANSIENT_STORAGE, nm))
......
/*-
* Copyright (c) 2007-2011 Varnish Software AS
* All rights reserved.
*
* Author: Dag-Erling Smørgav <des@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");
}
/*--------------------------------------------------------------------*/
...@@ -50,6 +50,8 @@ typedef void storage_close_f(const struct stevedore *); ...@@ -50,6 +50,8 @@ typedef void storage_close_f(const struct stevedore *);
#include "tbl/vrt_stv_var.h" #include "tbl/vrt_stv_var.h"
#undef VRTSTVTYPE #undef VRTSTVTYPE
extern storage_allocobj_f stv_default_allocobj;
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
struct stevedore { struct stevedore {
...@@ -78,6 +80,11 @@ struct stevedore { ...@@ -78,6 +80,11 @@ struct stevedore {
char ident[16]; /* XXX: match VSM_chunk.ident */ 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); 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, uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment