[master] 39c0497 Protect the obj->storage list with bo->mtx during the fetching.

Poul-Henning Kamp phk at varnish-cache.org
Thu Oct 3 09:55:20 CEST 2013


commit 39c049726ffc11332a8dcd50058b40801e93b2e7
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Oct 3 07:54:59 2013 +0000

    Protect the obj->storage list with bo->mtx during the fetching.

diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 8f49b20..3891156 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -228,15 +228,13 @@ ssize_t
 VBO_waitlen(struct busyobj *bo, ssize_t l)
 {
 	Lck_Lock(&bo->mtx);
-	if (bo->state <= BOS_FINISHED)
-		assert(l <= bo->fetch_obj->len);
+	assert(l <= bo->fetch_obj->len || bo->state == BOS_FAILED);
 	while (1) {
-		if (bo->fetch_obj->len > l || bo->state >= BOS_FINISHED) {
-			l = bo->fetch_obj->len;
+		if (bo->fetch_obj->len > l || bo->state >= BOS_FINISHED)
 			break;
-		}
 		(void)Lck_CondWait(&bo->cond, &bo->mtx, NULL);
 	}
+	l = bo->fetch_obj->len;
 	Lck_Unlock(&bo->mtx);
 	return (l);
 }
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index c7d1dcd..b1da1db 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -189,7 +189,9 @@ VFP_GetStorage(struct busyobj *bo, ssize_t sz)
 		return (NULL);
 	}
 	AZ(st->len);
+	Lck_Lock(&bo->mtx);
 	VTAILQ_INSERT_TAIL(&obj->store, st, list);
+	Lck_Unlock(&bo->mtx);
 	return (st);
 }
 
diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c
index 2620912..b2627fd 100644
--- a/bin/varnishd/cache/cache_http1_fetch.c
+++ b/bin/varnishd/cache/cache_http1_fetch.c
@@ -334,7 +334,7 @@ V1F_fetch_body(struct worker *wrk, struct busyobj *bo)
 
 	AN(bo->vfp);
 	AZ(bo->vgz_rx);
-	AZ(VTAILQ_FIRST(&obj->store));
+	assert(VTAILQ_EMPTY(&obj->store));
 
 	/* XXX: pick up estimate from objdr ? */
 	cl = 0;
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 282b996..eadd358 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -93,18 +93,20 @@ ObjIter(struct objiter *oi, void **p, ssize_t *l)
 			if (oi->bo->state == BOS_FAILED)
 				return (OIS_ERROR);
 		}
+		Lck_Lock(&oi->bo->mtx);
 		VTAILQ_FOREACH(oi->st, &oi->obj->store, list) {
-			if (oi->st->len <= ol) {
-				ol -= oi->st->len;
-				nl -= oi->st->len;
-			} else {
+			if (oi->st->len > ol) {
 				*p = oi->st->ptr + ol;
 				*l = (nl - ol);
 				oi->len += *l;
-				return (OIS_STREAM);
+				break;
 			}
+			ol -= oi->st->len;
+			nl -= oi->st->len;
 		}
-		WRONG("ran off end");
+		Lck_Unlock(&oi->bo->mtx);
+		assert(*l > 0);
+		return (OIS_STREAM);
 	}
 }
 



More information about the varnish-commit mailing list