From 6cb77b858ab5e39e71af327d01472cc1692a33f2 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 16 Jun 2006 10:17:25 +0000 Subject: [PATCH] Add trim method to storage backends so chunked encoding can be stored efficiently. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@190 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/stevedore.h | 2 ++ varnish-cache/bin/varnishd/storage_file.c | 20 ++++++++++++++++---- varnish-cache/bin/varnishd/storage_malloc.c | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/varnish-cache/bin/varnishd/stevedore.h b/varnish-cache/bin/varnishd/stevedore.h index 084bd926..12269a94 100644 --- a/varnish-cache/bin/varnishd/stevedore.h +++ b/varnish-cache/bin/varnishd/stevedore.h @@ -8,6 +8,7 @@ struct sess; typedef void storage_init_f(struct stevedore *, const char *spec); typedef void storage_open_f(struct stevedore *); typedef struct storage *storage_alloc_f(struct stevedore *, size_t size); +typedef void storage_trim_f(struct storage *, size_t size); typedef void storage_free_f(struct storage *); typedef void storage_send_f(struct storage *, struct sess *); @@ -16,6 +17,7 @@ struct stevedore { storage_init_f *init; /* 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_send_f *send; diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index 3ad62fbe..060e9daf 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -268,8 +268,6 @@ alloc_smf(struct smf_sc *sc, size_t bytes) { struct smf *sp, *sp2; - bytes += (sc->pagesize - 1); - bytes &= ~(sc->pagesize - 1); TAILQ_FOREACH(sp, &sc->free, status) { if (sp->size >= bytes) break; @@ -454,18 +452,31 @@ static struct storage * smf_alloc(struct stevedore *st, unsigned size) { struct smf *smf; + struct smf_sc *sc = st->priv; - smf = alloc_smf(st->priv, size); + size += (sc->pagesize - 1); + size &= ~(sc->pagesize - 1); + smf = alloc_smf(sc, size); assert(smf != NULL); + smf->s.space = size; smf->s.priv = smf; smf->s.ptr = smf->ptr; - smf->s.len = size; + smf->s.len = 0; smf->s.stevedore = st; return (&smf->s); } /*--------------------------------------------------------------------*/ +static void +smf_trim(struct storage *s, size_t size) +{ + + /* XXX: implement */ +} + +/*--------------------------------------------------------------------*/ + static void smf_free(struct storage *s) { @@ -503,6 +514,7 @@ struct stevedore smf_stevedore = { smf_init, smf_open, smf_alloc, + smf_trim, smf_free, smf_send }; diff --git a/varnish-cache/bin/varnishd/storage_malloc.c b/varnish-cache/bin/varnishd/storage_malloc.c index 01d73217..3bae30bc 100644 --- a/varnish-cache/bin/varnishd/storage_malloc.c +++ b/varnish-cache/bin/varnishd/storage_malloc.c @@ -27,6 +27,7 @@ sma_alloc(struct stevedore *st __unused, unsigned size) sma->s.ptr = malloc(size); assert(sma->s.ptr != NULL); sma->s.len = size; + sma->s.space = size; return (&sma->s); } @@ -45,5 +46,6 @@ struct stevedore sma_stevedore = { NULL, /* init */ NULL, /* open */ sma_alloc, + NULL, /* trim */ sma_free }; -- 2.39.5