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

Complain if stevedores do not have unique names.

Add a stevedore named "Transient" if the user did not already do that.
By default it is a size-unconstrained -smalloc.

Do not select the stevedore named "Transient" automatically.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5539 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 4b81ae6f
...@@ -24,6 +24,11 @@ ...@@ -24,6 +24,11 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * 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 "config.h"
...@@ -40,6 +45,8 @@ SVNID("$Id$") ...@@ -40,6 +45,8 @@ SVNID("$Id$")
#include "stevedore.h" #include "stevedore.h"
#include "cli_priv.h" #include "cli_priv.h"
#define TRANSIENT_NAME "Transient"
static VTAILQ_HEAD(, stevedore) stevedores = static VTAILQ_HEAD(, stevedore) stevedores =
VTAILQ_HEAD_INITIALIZER(stevedores); VTAILQ_HEAD_INITIALIZER(stevedores);
...@@ -82,6 +89,8 @@ stv_pick_stevedore(void) ...@@ -82,6 +89,8 @@ stv_pick_stevedore(void)
AN(stv); AN(stv);
AN(stv->name); AN(stv->name);
stv_next = stv; stv_next = stv;
if (stv->transient)
stv = stv_pick_stevedore();
return (stv); return (stv);
} }
...@@ -254,10 +263,13 @@ static const struct choice STV_choice[] = { ...@@ -254,10 +263,13 @@ static const struct choice STV_choice[] = {
{ NULL, NULL } { NULL, NULL }
}; };
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------
* Parse a stevedore argument on the form:
* [ name '=' ] strategy [ ',' arg ] *
*/
void void
STV_config(const char *spec) STV_Config(const char *spec)
{ {
char **av; char **av;
const char *p, *q; const char *p, *q;
...@@ -281,7 +293,7 @@ STV_config(const char *spec) ...@@ -281,7 +293,7 @@ STV_config(const char *spec)
ARGV_ERR("%s\n", av[0]); ARGV_ERR("%s\n", av[0]);
if (av[1] == NULL) if (av[1] == NULL)
ARGV_ERR("-s argument is empty\n"); ARGV_ERR("-s argument lacks strategy {malloc, file, ...}\n");
for (ac = 0; av[ac + 2] != NULL; ac++) for (ac = 0; av[ac + 2] != NULL; ac++)
continue; continue;
...@@ -289,7 +301,7 @@ STV_config(const char *spec) ...@@ -289,7 +301,7 @@ STV_config(const char *spec)
stv2 = pick(STV_choice, av[1], "storage"); stv2 = pick(STV_choice, av[1], "storage");
AN(stv2); AN(stv2);
/* Append to ident string */ /* Append strategy to ident string */
vsb_printf(vident, ",-s%s", av[1]); vsb_printf(vident, ",-s%s", av[1]);
av += 2; av += 2;
...@@ -308,7 +320,17 @@ STV_config(const char *spec) ...@@ -308,7 +320,17 @@ STV_config(const char *spec)
l = p - spec; l = p - spec;
if (l > sizeof stv->ident - 1) if (l > sizeof stv->ident - 1)
l = sizeof stv->ident - 1; l = sizeof stv->ident - 1;
bprintf(stv->ident, "%*.*s", l, l, spec); bprintf(stv->ident, "%.*s", l, spec);
}
if (!strcmp(stv->ident, TRANSIENT_NAME))
stv->transient = 1;
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);
} }
stv->lru = LRU_Alloc(); stv->lru = LRU_Alloc();
...@@ -326,6 +348,19 @@ STV_config(const char *spec) ...@@ -326,6 +348,19 @@ STV_config(const char *spec)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void
STV_Config_Transient(void)
{
const struct stevedore *stv;
VTAILQ_FOREACH(stv, &stevedores, list)
if (!strcmp(stv->name, TRANSIENT_NAME))
return;
STV_Config(TRANSIENT_NAME "=malloc");
}
/*--------------------------------------------------------------------*/
static void static void
stv_cli_list(struct cli *cli, const char * const *av, void *priv) stv_cli_list(struct cli *cli, const char * const *av, void *priv)
{ {
...@@ -347,4 +382,3 @@ struct cli_proto cli_stv[] = { ...@@ -347,4 +382,3 @@ struct cli_proto cli_stv[] = {
0, 0, "", stv_cli_list }, 0, 0, "", stv_cli_list },
{ NULL} { NULL}
}; };
...@@ -49,6 +49,7 @@ struct stevedore { ...@@ -49,6 +49,7 @@ struct stevedore {
unsigned magic; unsigned magic;
#define STEVEDORE_MAGIC 0x4baf43db #define STEVEDORE_MAGIC 0x4baf43db
const char *name; const char *name;
unsigned transient;
storage_init_f *init; /* called by mgt process */ storage_init_f *init; /* called by mgt process */
storage_open_f *open; /* called by cache process */ storage_open_f *open; /* called by cache process */
storage_alloc_f *alloc; /* --//-- */ storage_alloc_f *alloc; /* --//-- */
...@@ -63,7 +64,7 @@ struct stevedore { ...@@ -63,7 +64,7 @@ struct stevedore {
void *priv; void *priv;
VTAILQ_ENTRY(stevedore) list; VTAILQ_ENTRY(stevedore) list;
char ident[16]; char ident[16]; /* XXX: match vsm_chunk.ident */
}; };
struct object *STV_NewObject(struct sess *sp, unsigned len, double ttl, struct object *STV_NewObject(struct sess *sp, unsigned len, double ttl,
...@@ -73,8 +74,9 @@ void STV_trim(struct storage *st, size_t size); ...@@ -73,8 +74,9 @@ void STV_trim(struct storage *st, size_t size);
void STV_free(struct storage *st); void STV_free(struct storage *st);
void STV_open(void); void STV_open(void);
void STV_close(void); void STV_close(void);
void STV_config(const char *spec);
struct lru *STV_lru(const struct storage *st); struct lru *STV_lru(const struct storage *st);
void STV_Config(const char *spec);
void STV_Config_Transient(void);
struct lru *LRU_Alloc(void); struct lru *LRU_Alloc(void);
......
...@@ -478,7 +478,7 @@ main(int argc, char * const *argv) ...@@ -478,7 +478,7 @@ main(int argc, char * const *argv)
break; break;
case 's': case 's':
s_arg_given = 1; s_arg_given = 1;
STV_config(optarg); STV_Config(optarg);
break; break;
case 't': case 't':
MCF_ParamSet(cli, "default_ttl", optarg); MCF_ParamSet(cli, "default_ttl", optarg);
...@@ -601,8 +601,12 @@ main(int argc, char * const *argv) ...@@ -601,8 +601,12 @@ main(int argc, char * const *argv)
if (C_flag) if (C_flag)
exit (0); exit (0);
/* If no -s argument specified, process default -s argument */
if (!s_arg_given) if (!s_arg_given)
STV_config(s_arg); STV_Config(s_arg);
/* Configure Transient storage, if user did not */
STV_Config_Transient();
HSH_config(h_arg); HSH_config(h_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