Commit b5d5336e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Constify what pick() finds.

Move hash & storage config out to cache_hash.c and stevedore.c.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4817 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 158df7ab
......@@ -749,10 +749,43 @@ HSH_Init(void)
hash->start();
}
const struct choice hsh_choice[] = {
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;
av = ParseArgv(h_arg, 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);
}
......@@ -66,9 +66,9 @@ void mgt_child_inherit(int fd, const char *what);
/* A tiny helper for choosing hash/storage modules */
struct choice {
const char *name;
void *ptr; /* XXX: constify */
const void *ptr;
};
void *pick(const struct choice *cp, const char *which, const char *kind);
const void *pick(const struct choice *cp, const char *which, const char *kind);
#define NEEDLESS_RETURN(foo) return (foo)
......
......@@ -65,6 +65,7 @@ void HSH_DerefObjCore(struct sess *sp);
void HSH_FindBan(struct sess *sp, struct objcore **oc);
struct objcore *HSH_Insert(const struct sess *sp);
void HSH_Purge(struct sess *, struct objhead *, double ttl, double grace);
void HSH_config(const char *h_arg);
#ifdef VARNISH_CACHE_CHILD
......@@ -105,4 +106,3 @@ void HSH_Deref(struct worker *w, struct object **o);
extern struct hash_slinger hsl_slinger;
extern struct hash_slinger hcl_slinger;
extern struct hash_slinger hcb_slinger;
extern const struct choice hsh_choice[];
......@@ -56,7 +56,7 @@ struct heritage {
unsigned nsocks;
/* Hash method */
struct hash_slinger *hash;
const struct hash_slinger *hash;
char *name;
char identity[1024];
......
......@@ -213,31 +213,6 @@ STV_free(struct storage *st)
st->stevedore->free(st);
}
void
STV_add(const struct stevedore *stv2, int ac, char * const *av)
{
struct stevedore *stv;
CHECK_OBJ_NOTNULL(stv2, STEVEDORE_MAGIC);
ALLOC_OBJ(stv, STEVEDORE_MAGIC);
AN(stv);
*stv = *stv2;
AN(stv->name);
AN(stv->alloc);
stv->lru = LRU_Alloc();
if (stv->init != NULL)
stv->init(stv, ac, av);
else if (ac != 0)
ARGV_ERR("(-s%s) too many arguments\n", stv->name);
VTAILQ_INSERT_TAIL(&stevedores, stv, list);
if (!stv_next)
stv_next = VTAILQ_FIRST(&stevedores);
}
void
STV_ready(void)
{
......@@ -280,7 +255,7 @@ STV_lru(const struct storage *st)
return (st->stevedore->lru);
}
const struct choice STV_choice[] = {
static const struct choice STV_choice[] = {
{ "file", &smf_stevedore },
{ "malloc", &sma_stevedore },
{ "persistent", &smp_stevedore },
......@@ -289,3 +264,51 @@ const struct choice STV_choice[] = {
#endif
{ NULL, NULL }
};
/*--------------------------------------------------------------------*/
void
STV_config(const char *spec)
{
char **av;
struct stevedore *stv;
const struct stevedore *stv2;
int ac;
av = ParseArgv(spec, ARGV_COMMA);
AN(av);
if (av[0] != NULL)
ARGV_ERR("%s\n", av[0]);
if (av[1] == NULL)
ARGV_ERR("-s argument is empty\n");
for (ac = 0; av[ac + 2] != NULL; ac++)
continue;
stv2 = pick(STV_choice, av[1], "storage");
AN(stv2);
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);
stv->lru = LRU_Alloc();
if (stv->init != NULL)
stv->init(stv, ac, av);
else if (ac != 0)
ARGV_ERR("(-s%s) too many arguments\n", stv->name);
VTAILQ_INSERT_TAIL(&stevedores, stv, list);
if (!stv_next)
stv_next = VTAILQ_FIRST(&stevedores);
}
......@@ -50,14 +50,14 @@ struct stevedore {
unsigned magic;
#define STEVEDORE_MAGIC 0x4baf43db
const char *name;
storage_init_f *init; /* called by mgt process */
storage_ready_f *ready; /* called by mgt process */
storage_open_f *open; /* called by cache process */
storage_alloc_f *alloc;
storage_trim_f *trim;
storage_free_f *free;
storage_object_f *object;
storage_close_f *close;
storage_init_f *init; /* called by mgt process */
storage_ready_f *ready; /* called by mgt process */
storage_open_f *open; /* called by cache process */
storage_alloc_f *alloc; /* --//-- */
storage_trim_f *trim; /* --//-- */
storage_free_f *free; /* --//-- */
storage_object_f *object; /* --//-- */
storage_close_f *close; /* --//-- */
struct lru *lru;
......@@ -72,10 +72,10 @@ struct object *STV_NewObject(struct sess *sp, unsigned len, double ttl,
struct storage *STV_alloc(struct sess *sp, size_t size, struct objcore *oc);
void STV_trim(struct storage *st, size_t size);
void STV_free(struct storage *st);
void STV_add(const struct stevedore *stv, int ac, char * const *av);
void STV_ready(void);
void STV_open(void);
void STV_close(void);
void STV_config(const char *spec);
struct lru *STV_lru(const struct storage *st);
struct lru *LRU_Alloc(void);
......@@ -94,4 +94,3 @@ extern struct stevedore smp_stevedore;
extern struct stevedore smu_stevedore;
#endif
extern const struct choice STV_choice[];
......@@ -102,7 +102,7 @@ build_vident(void)
/*--------------------------------------------------------------------*/
void *
const void *
pick(const struct choice *cp, const char *which, const char *kind)
{
......@@ -129,68 +129,6 @@ arg_ul(const char *p)
/*--------------------------------------------------------------------*/
static void
setup_storage(const char *spec)
{
char **av;
void *priv;
int ac;
av = ParseArgv(spec, ARGV_COMMA);
AN(av);
if (av[0] != NULL)
ARGV_ERR("%s\n", av[0]);
if (av[1] == NULL)
ARGV_ERR("-s argument is empty\n");
for (ac = 0; av[ac + 2] != NULL; ac++)
continue;
priv = pick(STV_choice, av[1], "storage");
AN(priv);
vsb_printf(vident, ",-s%s", av[1]);
STV_add(priv, ac, av + 2);
/* We do not free av, to make life simpler for stevedores */
}
/*--------------------------------------------------------------------*/
static void
setup_hash(const char *h_arg)
{
char **av;
int ac;
struct hash_slinger *hp;
av = ParseArgv(h_arg, 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);
}
/*--------------------------------------------------------------------*/
static void
usage(void)
{
......@@ -554,7 +492,7 @@ main(int argc, char * const *argv)
break;
case 's':
s_arg_given = 1;
setup_storage(optarg);
STV_config(optarg);
break;
case 't':
MCF_ParamSet(cli, "default_ttl", optarg);
......@@ -595,7 +533,7 @@ main(int argc, char * const *argv)
if (L_arg) {
/* Learner mode */
if (!s_arg_given) {
setup_storage("malloc,1m");
STV_config("malloc,1m");
s_arg_given = 1;
}
}
......@@ -679,9 +617,9 @@ main(int argc, char * const *argv)
exit (0);
if (!s_arg_given)
setup_storage(s_arg);
STV_config(s_arg);
setup_hash(h_arg);
HSH_config(h_arg);
mgt_SHM_Init(SHMLOG_FILENAME, l_arg);
......
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