[master] be938d3 Wrap obj->len in an accessor function

Poul-Henning Kamp phk at FreeBSD.org
Mon Aug 11 09:31:53 CEST 2014


commit be938d34eea6dfb9ef8c63b41838236b1cf72367
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Aug 11 07:31:36 2014 +0000

    Wrap obj->len in an accessor function

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 810fe4e..1038e85 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1059,6 +1059,7 @@ enum objiter_status ObjIter(struct objiter *, void **, ssize_t *);
 void ObjIterEnd(struct objiter **);
 void ObjTrimStore(struct objcore *, struct dstat *);
 unsigned ObjGetXID(struct objcore *, struct dstat *);
+uint64_t ObjGetLen(struct objcore *oc, struct dstat *ds);
 struct object *ObjGetObj(struct objcore *, struct dstat *);
 void ObjUpdateMeta(struct objcore *);
 void ObjFreeObj(struct objcore *, struct dstat *);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 12cb10f..185378e 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -505,6 +505,7 @@ ESI_DeliverChild(struct req *req)
 	u_char cc;
 	uint32_t icrc;
 	uint32_t ilen;
+	uint64_t olen;
 	uint8_t *dbits;
 	int i, j;
 	uint8_t tailbuf[8];
@@ -534,9 +535,10 @@ ESI_DeliverChild(struct req *req)
 	start = vbe64dec(p);
 	last = vbe64dec(p + 8);
 	stop = vbe64dec(p + 16);
-	assert(start > 0 && start < obj->len * 8);
-	assert(last > 0 && last < obj->len * 8);
-	assert(stop > 0 && stop < obj->len * 8);
+	olen = ObjGetLen(obj->objcore, &req->wrk->stats);
+	assert(start > 0 && start < olen * 8);
+	assert(last > 0 && last < olen * 8);
+	assert(stop > 0 && stop < olen * 8);
 	assert(last >= start);
 	assert(last < stop);
 
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 1c67e9a..d8ebfc6 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -559,6 +559,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 	struct objiter *oi;
 	void *sp;
 	ssize_t sl, al, tl;
+	uint64_t ol;
 	struct storage *st;
 	enum objiter_status ois;
 	char *p;
@@ -606,13 +607,13 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 	st = NULL;
 	al = 0;
 
+	ol = ObjGetLen(bo->ims_oc, bo->stats);
 	oi = ObjIterBegin(wrk, bo->ims_obj);
 	do {
 		ois = ObjIter(oi, &sp, &sl);
 		while (sl > 0) {
 			if (st == NULL)
-				st = VFP_GetStorage(bo->vfc,
-				    bo->ims_obj->len - al);
+				st = VFP_GetStorage(bo->vfc, ol - al);
 			if (st == NULL)
 				break;
 			tl = sl;
@@ -634,8 +635,8 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 	if (!bo->do_stream)
 		HSH_Unbusy(&wrk->stats, obj->objcore);
 
-	assert(al == bo->ims_obj->len);
-	assert(obj->len == al);
+	assert(al == ol);
+	assert(ObjGetLen(bo->fetch_objcore, bo->stats) == al);
 	EXP_Rearm(bo->ims_oc, bo->ims_oc->exp.t_origin, 0, 0, 0);
 
 	/* Recycle the backend connection before setting BOS_FINISHED to
@@ -802,8 +803,6 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
 	}
 	assert(WRW_IsReleased(wrk));
 
-	bo->stats = NULL;
-
 	if (bo->vbc != NULL) {
 		if (bo->doclose != SC_NULL)
 			VDI_CloseFd(&bo->vbc, &bo->acct);
@@ -818,22 +817,8 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
 	if (bo->state == BOS_FINISHED) {
 		AZ(bo->fetch_objcore->flags & OC_F_FAILED);
 		HSH_Complete(bo->fetch_objcore);
-		VSLb(bo->vsl, SLT_Length, "%zd", bo->fetch_obj->len);
-		{
-		/* Sanity check fetch methods accounting */
-			ssize_t uu;
-			struct storage *st;
-
-			uu = 0;
-			VTAILQ_FOREACH(st, &bo->fetch_obj->body->list, list)
-				uu += st->len;
-			if (bo->do_stream)
-				/* Streaming might have started freeing stuff */
-				assert(uu <= bo->fetch_obj->len);
-
-			else
-				assert(uu == bo->fetch_obj->len);
-		}
+		VSLb(bo->vsl, SLT_Length, "%zd",
+		    ObjGetLen(bo->fetch_objcore, bo->stats));
 	}
 	AZ(bo->fetch_objcore->busyobj);
 
@@ -842,6 +827,8 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
 		bo->ims_obj = NULL;
 	}
 
+	bo->stats = NULL;
+
 	VBO_DerefBusyObj(wrk, &bo);
 	THR_SetBusyobj(NULL);
 }
diff --git a/bin/varnishd/cache/cache_http1_deliver.c b/bin/varnishd/cache/cache_http1_deliver.c
index f93d492..2a2b1bc 100644
--- a/bin/varnishd/cache/cache_http1_deliver.c
+++ b/bin/varnishd/cache/cache_http1_deliver.c
@@ -99,7 +99,7 @@ v1d_dorange(struct req *req, struct busyobj *bo, const char *r)
 	if (bo != NULL)
 		len = VBO_waitlen(bo, -1);
 	else
-		len = req->obj->len;
+		len = ObjGetLen(req->objcore, &req->wrk->stats);
 
 	if (strncmp(r, "bytes=", 6))
 		return;
@@ -252,10 +252,11 @@ V1D_Deliver(struct req *req, struct busyobj *bo)
 		/* XXX: Not happy with this convoluted test */
 		req->res_mode |= RES_LEN;
 		if (!(req->objcore->flags & OC_F_PASS) ||
-		    req->obj->len != 0) {
+		    ObjGetLen(req->objcore, &req->wrk->stats) != 0) {
 			http_Unset(req->resp, H_Content_Length);
 			http_PrintfHeader(req->resp,
-			    "Content-Length: %zd", req->obj->len);
+			    "Content-Length: %ju", (uintmax_t)ObjGetLen(
+			    req->objcore, &req->wrk->stats));
 		}
 	}
 
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index d5b7390..f8da916 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -303,6 +303,16 @@ ObjGetXID(struct objcore *oc, struct dstat *ds)
 	return (u);
 }
 
+uint64_t
+ObjGetLen(struct objcore *oc, struct dstat *ds)
+{
+	struct object *o;
+
+	o = ObjGetObj(oc, ds);
+	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
+	return (o->len);
+}
+
 /*--------------------------------------------------------------------
  * There is no well-defined byteorder for IEEE-754 double and the
  * correct solution (frexp(3) and manual encoding) is more work



More information about the varnish-commit mailing list