From f236ce2afba6cae1c6093252d9cf75ac27d5639c Mon Sep 17 00:00:00 2001 From: phk Date: Wed, 28 Jun 2006 10:30:57 +0000 Subject: [PATCH] Implement ->trim() git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@245 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/storage_file.c | 32 ++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/varnish-cache/bin/varnishd/storage_file.c b/varnish-cache/bin/varnishd/storage_file.c index ee7d4574..3129cf37 100644 --- a/varnish-cache/bin/varnishd/storage_file.c +++ b/varnish-cache/bin/varnishd/storage_file.c @@ -346,6 +346,29 @@ free_smf(struct smf *sp) TAILQ_INSERT_TAIL(&sc->free, sp, status); } +/*-------------------------------------------------------------------- + * Trim the tail of a range. + */ + +static void +trim_smf(struct smf *sp, size_t bytes) +{ + struct smf *sp2; + struct smf_sc *sc = sp->sc; + + assert(bytes > 0); + sp2 = malloc(sizeof *sp2); + assert(sp2 != NULL); + + sp2->size = sp->size - bytes; + sp->size = bytes; + sp2->ptr = sp->ptr + bytes; + sp2->offset = sp->offset + bytes; + TAILQ_INSERT_TAIL(&sc->used, sp2, status); + TAILQ_INSERT_AFTER(&sc->order, sp, sp2, status); + free_smf(sp2); +} + /*-------------------------------------------------------------------- * Insert a newly created range as busy, then free it to do any collapses */ @@ -463,8 +486,15 @@ smf_alloc(struct stevedore *st, unsigned size) static void smf_trim(struct storage *s, size_t size) { + struct smf *smf; + struct smf_sc *sc = s->priv; - /* XXX: implement */ + assert(size > 0); + size += (sc->pagesize - 1); + size &= ~(sc->pagesize - 1); + smf = (struct smf *)(s->priv); + if (smf->size > size) + trim_smf(smf, size); } /*--------------------------------------------------------------------*/ -- 2.39.5