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 @@
* 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"
......@@ -40,6 +45,8 @@ SVNID("$Id$")
#include "stevedore.h"
#include "cli_priv.h"
#define TRANSIENT_NAME "Transient"
static VTAILQ_HEAD(, stevedore) stevedores =
VTAILQ_HEAD_INITIALIZER(stevedores);
......@@ -82,6 +89,8 @@ stv_pick_stevedore(void)
AN(stv);
AN(stv->name);
stv_next = stv;
if (stv->transient)
stv = stv_pick_stevedore();
return (stv);
}
......@@ -254,10 +263,13 @@ static const struct choice STV_choice[] = {
{ NULL, NULL }
};
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------
* Parse a stevedore argument on the form:
* [ name '=' ] strategy [ ',' arg ] *
*/
void
STV_config(const char *spec)
STV_Config(const char *spec)
{
char **av;
const char *p, *q;
......@@ -281,7 +293,7 @@ STV_config(const char *spec)
ARGV_ERR("%s\n", av[0]);
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++)
continue;
......@@ -289,7 +301,7 @@ STV_config(const char *spec)
stv2 = pick(STV_choice, av[1], "storage");
AN(stv2);
/* Append to ident string */
/* Append strategy to ident string */
vsb_printf(vident, ",-s%s", av[1]);
av += 2;
......@@ -308,7 +320,17 @@ STV_config(const char *spec)
l = p - spec;
if (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();
......@@ -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
stv_cli_list(struct cli *cli, const char * const *av, void *priv)
{
......@@ -347,4 +382,3 @@ struct cli_proto cli_stv[] = {
0, 0, "", stv_cli_list },
{ NULL}
};
......@@ -49,6 +49,7 @@ struct stevedore {
unsigned magic;
#define STEVEDORE_MAGIC 0x4baf43db
const char *name;
unsigned transient;
storage_init_f *init; /* called by mgt process */
storage_open_f *open; /* called by cache process */
storage_alloc_f *alloc; /* --//-- */
......@@ -63,7 +64,7 @@ struct stevedore {
void *priv;
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,
......@@ -73,8 +74,9 @@ void STV_trim(struct storage *st, size_t size);
void STV_free(struct storage *st);
void STV_open(void);
void STV_close(void);
void STV_config(const char *spec);
struct lru *STV_lru(const struct storage *st);
void STV_Config(const char *spec);
void STV_Config_Transient(void);
struct lru *LRU_Alloc(void);
......
......@@ -478,7 +478,7 @@ main(int argc, char * const *argv)
break;
case 's':
s_arg_given = 1;
STV_config(optarg);
STV_Config(optarg);
break;
case 't':
MCF_ParamSet(cli, "default_ttl", optarg);
......@@ -601,8 +601,12 @@ main(int argc, char * const *argv)
if (C_flag)
exit (0);
/* If no -s argument specified, process default -s argument */
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);
......
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