r4202 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Tue Aug 18 21:08:06 CEST 2009


Author: phk
Date: 2009-08-18 21:08:06 +0200 (Tue, 18 Aug 2009)
New Revision: 4202

Modified:
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
Log:
A long time ago, I wrote fetch_straight() in fact it was one of the
very first functions ever written in Varnish.   Since I knew
that the file stevedore would always return the size you asked for,
or panic, I didn't bother to actually check how big the storage
segment he allocated was, I just knew it would be the right size.

Guess what, segments are finite size in the -spersistent stevedore
so you may in fact _not_ get what you ask for.

(Cue music: Theme Music from The Keystone Kops)

DuH!


Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2009-08-18 15:57:07 UTC (rev 4201)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2009-08-18 19:08:06 UTC (rev 4202)
@@ -53,7 +53,7 @@
 	int i;
 	unsigned char *p;
 	uintmax_t cll;
-	unsigned cl;
+	unsigned cl, sl;
 	struct storage *st;
 
 	cll = strtoumax(b, NULL, 0);
@@ -63,18 +63,24 @@
 	cl = (unsigned)cll;
 	assert((uintmax_t)cl == cll); /* Protect against bogusly large values */
 
-	st = STV_alloc(sp, cl);
-	VTAILQ_INSERT_TAIL(&sp->obj->store, st, list);
-	st->len = cl;
-	sp->obj->len = cl;
-	p = st->ptr;
+	while (cl > 0) {
+		st = STV_alloc(sp, cl);
+		VTAILQ_INSERT_TAIL(&sp->obj->store, st, list);
+		sl = st->space;
+		if (sl > cl)
+			sl = cl;
+		p = st->ptr;
 
-	while (cl > 0) {
-		i = HTC_Read(htc, p, cl);
-		if (i <= 0)
-			return (-1);
-		p += i;
-		cl -= i;
+		while (sl > 0) {
+			i = HTC_Read(htc, p, sl);
+			if (i <= 0)
+				return (-1);
+			p += i;
+			st->len += i;
+			sp->obj->len += i;
+			sl -= i;
+			cl -= i;
+		}
 	}
 	return (0);
 }



More information about the varnish-commit mailing list