From: phk Date: Tue, 13 Jun 2006 08:02:59 +0000 (+0000) Subject: Clone the malloc stevedore to the file stevedore X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab8404f3676dad7d66a7d2cf969b8acff6437bb6;p=varnish Clone the malloc stevedore to the file stevedore git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@172 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/Makefile.am b/varnish-cache/bin/varnishd/Makefile.am index ef5b2275..8a23a035 100644 --- a/varnish-cache/bin/varnishd/Makefile.am +++ b/varnish-cache/bin/varnishd/Makefile.am @@ -18,6 +18,7 @@ varnishd_SOURCES = \ cli_event.c \ hash_simple_list.c \ mgt_child.c \ + storage_file.c \ storage_malloc.c \ tcp.c \ varnishd.c diff --git a/varnish-cache/bin/varnishd/mgt.h b/varnish-cache/bin/varnishd/mgt.h index 9cc269e6..89c90d52 100644 --- a/varnish-cache/bin/varnishd/mgt.h +++ b/varnish-cache/bin/varnishd/mgt.h @@ -17,3 +17,4 @@ int open_tcp(const char *port); #include "_stevedore.h" extern struct stevedore sma_stevedore; +extern struct stevedore smf_stevedore; diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c new file mode 100644 index 00000000..3e5c9601 --- /dev/null +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -0,0 +1,49 @@ +/* + * $Id: storage_malloc.c 170 2006-06-13 07:57:32Z phk $ + * + * Storage method based on mmap'ed file + */ + +#include +#include +#include +#include + +#include "vcl_lang.h" +#include "cache.h" + +struct smf { + struct storage s; +}; + +static struct storage * +smf_alloc(struct stevedore *st __unused, unsigned size) +{ + struct smf *smf; + + smf = calloc(sizeof *smf, 1); + assert(smf != NULL); + smf->s.priv = smf; + smf->s.ptr = malloc(size); + assert(smf->s.ptr != NULL); + smf->s.len = size; + return (&smf->s); +} + +static void +smf_free(struct storage *s) +{ + struct smf *smf; + + smf = s->priv; + free(smf->s.ptr); + free(smf); +} + +struct stevedore smf_stevedore = { + "file", + NULL, /* init */ + NULL, /* open */ + smf_alloc, + smf_free +}; diff --git a/varnish-cache/bin/varnishd/varnishd.c b/varnish-cache/bin/varnishd/varnishd.c index 3d0c2e56..de317eb8 100644 --- a/varnish-cache/bin/varnishd/varnishd.c +++ b/varnish-cache/bin/varnishd/varnishd.c @@ -316,6 +316,8 @@ setup_storage(const char *sflag) p = strchr(sflag, '\0'); if (!cmp_storage(&sma_stevedore, sflag, p)) { heritage.stevedore = &sma_stevedore; + } else if (!cmp_storage(&smf_stevedore, sflag, p)) { + heritage.stevedore = &smf_stevedore; } else { fprintf(stderr, "Unknown storage method \"%*.*s\"\n", p - sflag, p - sflag, sflag);