r4817 - trunk/varnish-cache/bin/varnishd
phk at varnish-cache.org
phk at varnish-cache.org
Wed May 19 09:07:15 CEST 2010
Author: phk
Date: 2010-05-19 09:07:15 +0200 (Wed, 19 May 2010)
New Revision: 4817
Modified:
trunk/varnish-cache/bin/varnishd/cache_hash.c
trunk/varnish-cache/bin/varnishd/common.h
trunk/varnish-cache/bin/varnishd/hash_slinger.h
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/stevedore.c
trunk/varnish-cache/bin/varnishd/stevedore.h
trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
Constify what pick() finds.
Move hash & storage config out to cache_hash.c and stevedore.c.
Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c 2010-05-19 07:05:11 UTC (rev 4816)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2010-05-19 07:07:15 UTC (rev 4817)
@@ -749,10 +749,43 @@
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);
+}
+
Modified: trunk/varnish-cache/bin/varnishd/common.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/common.h 2010-05-19 07:05:11 UTC (rev 4816)
+++ trunk/varnish-cache/bin/varnishd/common.h 2010-05-19 07:07:15 UTC (rev 4817)
@@ -66,9 +66,9 @@
/* 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)
Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2010-05-19 07:05:11 UTC (rev 4816)
+++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2010-05-19 07:07:15 UTC (rev 4817)
@@ -65,6 +65,7 @@
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 @@
extern struct hash_slinger hsl_slinger;
extern struct hash_slinger hcl_slinger;
extern struct hash_slinger hcb_slinger;
-extern const struct choice hsh_choice[];
Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h 2010-05-19 07:05:11 UTC (rev 4816)
+++ trunk/varnish-cache/bin/varnishd/heritage.h 2010-05-19 07:07:15 UTC (rev 4817)
@@ -56,7 +56,7 @@
unsigned nsocks;
/* Hash method */
- struct hash_slinger *hash;
+ const struct hash_slinger *hash;
char *name;
char identity[1024];
Modified: trunk/varnish-cache/bin/varnishd/stevedore.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.c 2010-05-19 07:05:11 UTC (rev 4816)
+++ trunk/varnish-cache/bin/varnishd/stevedore.c 2010-05-19 07:07:15 UTC (rev 4817)
@@ -214,31 +214,6 @@
}
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)
{
struct stevedore *stv;
@@ -280,7 +255,7 @@
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 @@
#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);
+}
Modified: trunk/varnish-cache/bin/varnishd/stevedore.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/stevedore.h 2010-05-19 07:05:11 UTC (rev 4816)
+++ trunk/varnish-cache/bin/varnishd/stevedore.h 2010-05-19 07:07:15 UTC (rev 4817)
@@ -50,14 +50,14 @@
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 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 smu_stevedore;
#endif
-extern const struct choice STV_choice[];
Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c 2010-05-19 07:05:11 UTC (rev 4816)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c 2010-05-19 07:07:15 UTC (rev 4817)
@@ -102,7 +102,7 @@
/*--------------------------------------------------------------------*/
-void *
+const void *
pick(const struct choice *cp, const char *which, const char *kind)
{
@@ -130,68 +130,6 @@
/*--------------------------------------------------------------------*/
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)
{
#define FMT " %-28s # %s\n"
@@ -554,7 +492,7 @@
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 @@
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 @@
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);
More information about the varnish-commit
mailing list