r245 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Wed Jun 28 12:30:57 CEST 2006


Author: phk
Date: 2006-06-28 12:30:57 +0200 (Wed, 28 Jun 2006)
New Revision: 245

Modified:
   trunk/varnish-cache/bin/varnishd/storage_file.c
Log:
Implement ->trim()


Modified: trunk/varnish-cache/bin/varnishd/storage_file.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_file.c	2006-06-28 09:39:25 UTC (rev 244)
+++ trunk/varnish-cache/bin/varnishd/storage_file.c	2006-06-28 10:30:57 UTC (rev 245)
@@ -347,6 +347,29 @@
 }
 
 /*--------------------------------------------------------------------
+ * 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 @@
 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);
 }
 
 /*--------------------------------------------------------------------*/




More information about the varnish-commit mailing list