[master] 23c608f Update st->len inside the bo->mtx in VBO_extend() so that it is always synchronized with obj->len.

Poul-Henning Kamp phk at varnish-cache.org
Tue Nov 5 23:36:45 CET 2013


commit 23c608f75f895ec4c2e5b9a306b3683d5526216e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Nov 5 22:36:07 2013 +0000

    Update st->len inside the bo->mtx in VBO_extend() so that it
    is always synchronized with obj->len.

diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 3891156..38da061 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -212,6 +212,7 @@ VBO_DerefBusyObj(struct worker *wrk, struct busyobj **pbo)
 void
 VBO_extend(struct busyobj *bo, ssize_t l)
 {
+	struct storage *st;
 
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(bo->fetch_obj, OBJECT_MAGIC);
@@ -219,6 +220,8 @@ VBO_extend(struct busyobj *bo, ssize_t l)
 		return;
 	assert(l > 0);
 	Lck_Lock(&bo->mtx);
+	st = VTAILQ_LAST(&bo->fetch_obj->store, storagehead);
+	st->len += l;
 	bo->fetch_obj->len += l;
 	AZ(pthread_cond_signal(&bo->cond));
 	Lck_Unlock(&bo->mtx);
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index c3274b1..6218cc2 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -101,7 +101,6 @@ vfp_esi_bytes_uu(struct busyobj *bo, const struct vef_priv *vef,
 		if (wl <= 0)
 			return (wl);
 		VEP_Parse(bo, (const char *)st->ptr + st->len, wl);
-		st->len += wl;
 		VBO_extend(bo, wl);
 		bytes -= wl;
 	}
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 49ea75f..ce74d35 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -541,7 +541,6 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 			if (tl > st->space - st->len)
 				tl = st->space - st->len;
 			memcpy(st->ptr + st->len, sp, tl);
-			st->len += tl;
 			al += tl;
 			sp = (char *)sp + tl;
 			sl -= tl;
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index b1da1db..97a35c2 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -129,7 +129,6 @@ vfp_nop_bytes(struct busyobj *bo, struct http_conn *htc, ssize_t bytes)
 		wl = HTTP1_Read(htc, st->ptr + st->len, l);
 		if (wl <= 0)
 			return (wl);
-		st->len += wl;
 		VBO_extend(bo, wl);
 		bytes -= wl;
 	}
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index a95c4d4..4c8f9e2 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -55,8 +55,6 @@ struct vgz {
 	char			*tmp_snapshot;
 	int			last_i;
 
-	struct storage		*st_obuf;
-
 	/* Wrw stuff */
 	char			*m_buf;
 	ssize_t			m_sz;
@@ -210,7 +208,6 @@ VGZ_ObufStorage(struct busyobj *bo, struct vgz *vg)
 	if (st == NULL)
 		return (-1);
 
-	vg->st_obuf = st;
 	VGZ_Obuf(vg, st->ptr + st->len, st->space - st->len);
 
 	return (0);
@@ -237,8 +234,6 @@ VGZ_Gunzip(struct vgz *vg, const void **pptr, size_t *plen)
 		*pptr = before;
 		l = (const uint8_t *)vg->vz.next_out - before;
 		*plen = l;
-		if (vg->st_obuf != NULL)
-			vg->st_obuf->len += l;
 	}
 	vg->last_i = i;
 	if (i == Z_OK)
@@ -280,8 +275,6 @@ VGZ_Gzip(struct vgz *vg, const void **pptr, size_t *plen, enum vgz_flag flags)
 		*pptr = before;
 		l = (const uint8_t *)vg->vz.next_out - before;
 		*plen = l;
-		if (vg->st_obuf != NULL)
-			vg->st_obuf->len += l;
 	}
 	vg->last_i = i;
 	if (i == Z_OK)
@@ -683,7 +676,6 @@ vfp_testgzip_bytes(struct busyobj *bo, struct http_conn *htc, ssize_t bytes)
 			return (wl);
 		bytes -= wl;
 		VGZ_Ibuf(vg, st->ptr + st->len, wl);
-		st->len += wl;
 		VBO_extend(bo, wl);
 
 		while (!VGZ_IbufEmpty(vg)) {
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 5b3dab9..c59ebf9 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -63,7 +63,6 @@ ObjIter(struct objiter *oi, void **p, ssize_t *l)
 {
 	ssize_t ol;
 	ssize_t nl;
-	volatile unsigned u;
 
 	CHECK_OBJ_NOTNULL(oi, OBJITER_MAGIC);
 	CHECK_OBJ_NOTNULL(oi->obj, OBJECT_MAGIC);
@@ -98,15 +97,16 @@ ObjIter(struct objiter *oi, void **p, ssize_t *l)
 		Lck_Lock(&oi->bo->mtx);
 		AZ(VTAILQ_EMPTY(&oi->obj->store));
 		VTAILQ_FOREACH(oi->st, &oi->obj->store, list) {
-			u = (volatile unsigned)(oi->st->len);
-			if (u > ol) {
+			if (oi->st->len > ol) {
 				*p = oi->st->ptr + ol;
-				*l = u - ol;
+				*l = oi->st->len - ol;
 				oi->len += *l;
 				break;
 			}
-			ol -= u;
-			nl -= u;
+			ol -= oi->st->len;
+			assert(ol >= 0);
+			nl -= oi->st->len;
+			assert(nl > 0);
 		}
 		CHECK_OBJ_NOTNULL(oi->obj, OBJECT_MAGIC);
 		CHECK_OBJ_NOTNULL(oi->st, STORAGE_MAGIC);



More information about the varnish-commit mailing list