Commit 23fba143 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add trim method to storage backends so chunked encoding can be

stored efficiently.


git-svn-id: http://www.varnish-cache.org/svn/trunk@190 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 8a453437
...@@ -8,6 +8,7 @@ struct sess; ...@@ -8,6 +8,7 @@ struct sess;
typedef void storage_init_f(struct stevedore *, const char *spec); typedef void storage_init_f(struct stevedore *, const char *spec);
typedef void storage_open_f(struct stevedore *); typedef void storage_open_f(struct stevedore *);
typedef struct storage *storage_alloc_f(struct stevedore *, size_t size); 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_free_f(struct storage *);
typedef void storage_send_f(struct storage *, struct sess *); typedef void storage_send_f(struct storage *, struct sess *);
...@@ -16,6 +17,7 @@ struct stevedore { ...@@ -16,6 +17,7 @@ struct stevedore {
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;
storage_trim_f *trim;
storage_free_f *free; storage_free_f *free;
storage_send_f *send; storage_send_f *send;
......
...@@ -268,8 +268,6 @@ alloc_smf(struct smf_sc *sc, size_t bytes) ...@@ -268,8 +268,6 @@ alloc_smf(struct smf_sc *sc, size_t bytes)
{ {
struct smf *sp, *sp2; struct smf *sp, *sp2;
bytes += (sc->pagesize - 1);
bytes &= ~(sc->pagesize - 1);
TAILQ_FOREACH(sp, &sc->free, status) { TAILQ_FOREACH(sp, &sc->free, status) {
if (sp->size >= bytes) if (sp->size >= bytes)
break; break;
...@@ -454,18 +452,31 @@ static struct storage * ...@@ -454,18 +452,31 @@ static struct storage *
smf_alloc(struct stevedore *st, unsigned size) smf_alloc(struct stevedore *st, unsigned size)
{ {
struct smf *smf; 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); assert(smf != NULL);
smf->s.space = size;
smf->s.priv = smf; smf->s.priv = smf;
smf->s.ptr = smf->ptr; smf->s.ptr = smf->ptr;
smf->s.len = size; smf->s.len = 0;
smf->s.stevedore = st; smf->s.stevedore = st;
return (&smf->s); return (&smf->s);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static void
smf_trim(struct storage *s, size_t size)
{
/* XXX: implement */
}
/*--------------------------------------------------------------------*/
static void static void
smf_free(struct storage *s) smf_free(struct storage *s)
{ {
...@@ -503,6 +514,7 @@ struct stevedore smf_stevedore = { ...@@ -503,6 +514,7 @@ struct stevedore smf_stevedore = {
smf_init, smf_init,
smf_open, smf_open,
smf_alloc, smf_alloc,
smf_trim,
smf_free, smf_free,
smf_send smf_send
}; };
...@@ -27,6 +27,7 @@ sma_alloc(struct stevedore *st __unused, unsigned size) ...@@ -27,6 +27,7 @@ sma_alloc(struct stevedore *st __unused, unsigned size)
sma->s.ptr = malloc(size); sma->s.ptr = malloc(size);
assert(sma->s.ptr != NULL); assert(sma->s.ptr != NULL);
sma->s.len = size; sma->s.len = size;
sma->s.space = size;
return (&sma->s); return (&sma->s);
} }
...@@ -45,5 +46,6 @@ struct stevedore sma_stevedore = { ...@@ -45,5 +46,6 @@ struct stevedore sma_stevedore = {
NULL, /* init */ NULL, /* init */
NULL, /* open */ NULL, /* open */
sma_alloc, sma_alloc,
NULL, /* trim */
sma_free sma_free
}; };
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