[master] 8fc1898 Make the length a property of the body.

Poul-Henning Kamp phk at FreeBSD.org
Mon Aug 11 11:37:20 CEST 2014


commit 8fc18981fa02f2e3eaf74fedcd2112d80e5bb723
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Aug 11 09:35:29 2014 +0000

    Make the length a property of the body.
    
    Use vfp_ctx as argument for ObjSetattr()
    
    Make OA_ESIDATA the first "real" attribute where allocation is done
    by the ObjSetattr() function.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 1038e85..9a0d53d 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -544,6 +544,7 @@ VTAILQ_HEAD(storagehead, storage);
 struct body {
 	struct stevedore	*stevedore;
 	struct storagehead	list;
+	ssize_t			len;
 };
 
 enum obj_attr {
@@ -569,7 +570,6 @@ struct object {
 	/* Bit positions in the gzip stream */
 	char			oa_gzipbits[24];
 
-	ssize_t			len;
 
 	/* VCL only variables */
 	char			oa_lastmodified[8];
@@ -932,7 +932,7 @@ int VGZ_ObufFull(const struct vgz *vg);
 enum vgzret_e VGZ_Gzip(struct vgz *, const void **, size_t *len, enum vgz_flag);
 enum vgzret_e VGZ_Gunzip(struct vgz *, const void **, size_t *len);
 enum vgzret_e VGZ_Destroy(struct vgz **);
-void VGZ_UpdateObj(struct dstat *ds, const struct vgz*, struct objcore *);
+void VGZ_UpdateObj(const struct vfp_ctx *, const struct vgz*);
 vdp_bytes VDP_gunzip;
 
 int VGZ_WrwInit(struct vgz *vg);
@@ -1066,16 +1066,15 @@ void ObjFreeObj(struct objcore *, struct dstat *);
 struct lru *ObjGetLRU(const struct objcore *);
 void *ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
     ssize_t *len);
-void *ObjSetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
-    ssize_t len);
-int ObjCopyAttr(struct objcore *ocd, struct objcore *ocs, struct dstat *ds,
-    enum obj_attr attr);
+void *ObjSetattr(const struct vfp_ctx *, enum obj_attr attr, ssize_t len);
+int ObjCopyAttr(const struct vfp_ctx *, struct objcore *, enum obj_attr attr);
+
+int ObjSetDouble(const struct vfp_ctx*, enum obj_attr, double);
+int ObjSetU32(const struct vfp_ctx *, enum obj_attr, uint32_t);
+int ObjSetU64(const struct vfp_ctx *, enum obj_attr, uint64_t);
 
-int ObjSetDouble(struct objcore *, struct dstat *, enum obj_attr, double);
 int ObjGetDouble(struct objcore *, struct dstat *, enum obj_attr, double *);
-int ObjSetU32(struct objcore *, struct dstat *, enum obj_attr, uint32_t);
 int ObjGetU32(struct objcore *, struct dstat *, enum obj_attr, uint32_t *);
-int ObjSetU64(struct objcore *, struct dstat *, enum obj_attr, uint64_t);
 int ObjGetU64(struct objcore *, struct dstat *, enum obj_attr, uint64_t *);
 
 /* cache_panic.c */
diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 17874f1..abbf03f 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -168,7 +168,6 @@ VBO_DerefBusyObj(struct worker *wrk, struct busyobj **pbo)
 	*pbo = NULL;
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_ORNULL(bo->fetch_objcore, OBJCORE_MAGIC);
-	CHECK_OBJ_ORNULL(bo->fetch_obj, OBJECT_MAGIC);
 	if (bo->fetch_objcore != NULL) {
 		oc = bo->fetch_objcore;
 		CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
@@ -222,15 +221,15 @@ 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);
+	CHECK_OBJ_NOTNULL(bo->vfc, VFP_CTX_MAGIC);
 	if (l == 0)
 		return;
 	assert(l > 0);
 	Lck_Lock(&bo->mtx);
-	st = VTAILQ_LAST(&bo->fetch_obj->body->list, storagehead);
+	st = VTAILQ_LAST(&bo->vfc->body->list, storagehead);
 	CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
 	st->len += l;
-	bo->fetch_obj->len += l;
+	bo->vfc->body->len += l;
 	AZ(pthread_cond_broadcast(&bo->cond));
 	Lck_Unlock(&bo->mtx);
 }
@@ -239,13 +238,13 @@ ssize_t
 VBO_waitlen(struct busyobj *bo, ssize_t l)
 {
 	Lck_Lock(&bo->mtx);
-	assert(l <= bo->fetch_obj->len || bo->state == BOS_FAILED);
 	while (1) {
-		if (bo->fetch_obj->len > l || bo->state >= BOS_FINISHED)
+		assert(l <= bo->vfc->body->len || bo->state == BOS_FAILED);
+		if (bo->vfc->body->len > l || bo->state >= BOS_FINISHED)
 			break;
 		(void)Lck_CondWait(&bo->cond, &bo->mtx, 0);
 	}
-	l = bo->fetch_obj->len;
+	l = bo->vfc->body->len;
 	Lck_Unlock(&bo->mtx);
 	return (l);
 }
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 8014ca9..1608eff 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -106,6 +106,7 @@ vfp_esi_end(struct vfp_ctx *vc, struct vef_priv *vef,
 {
 	struct vsb *vsb;
 	ssize_t l;
+	void *p;
 
 	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(vc->bo, BUSYOBJ_MAGIC);
@@ -117,22 +118,19 @@ vfp_esi_end(struct vfp_ctx *vc, struct vef_priv *vef,
 		if (retval == VFP_END) {
 			l = VSB_len(vsb);
 			assert(l > 0);
-			/* XXX: This is a huge waste of storage... */
-			vc->bo->fetch_obj->esidata = STV_alloc(vc, l);
-			if (vc->bo->fetch_obj->esidata != NULL) {
-				memcpy(vc->bo->fetch_obj->esidata->ptr,
-				    VSB_data(vsb), l);
-				vc->bo->fetch_obj->esidata->len = l;
-			} else {
+			p = ObjSetattr(vc, OA_ESIDATA, l);
+			if (p == NULL) {
 				retval = VFP_Error(vc,
 				    "Could not allocate storage for esidata");
+			} else {
+				memcpy(p, VSB_data(vsb), l);
 			}
 		}
 		VSB_delete(vsb);
 	}
 
 	if (vef->vgz != NULL) {
-		VGZ_UpdateObj(vc->bo->stats, vef->vgz, vc->bo->fetch_objcore);
+		VGZ_UpdateObj(vc, vef->vgz);
 		if (VGZ_Destroy(&vef->vgz) != VGZ_END)
 			retval = VFP_Error(vc,
 			    "ESI+Gzip Failed at the very end");
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index d22d1db..9635293 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -150,8 +150,7 @@ vbf_beresp2obj(struct busyobj *bo)
 		VSB_delete(vary);
 	}
 
-	AZ(ObjSetU32(bo->fetch_objcore, bo->stats, OA_VXID,
-	    VXID(bo->vsl->wid)));
+	AZ(ObjSetU32(bo->vfc, OA_VXID, VXID(bo->vsl->wid)));
 	WS_Assert(bo->ws_o);
 
 	/* Filter into object */
@@ -163,10 +162,9 @@ vbf_beresp2obj(struct busyobj *bo)
 	    ObjGetattr(bo->fetch_objcore, bo->stats, OA_HEADERS, NULL)));
 
 	if (http_GetHdr(bo->beresp, H_Last_Modified, &b))
-		AZ(ObjSetDouble(bo->fetch_objcore, bo->stats, OA_LASTMODIFIED,
-		    VTIM_parse(b)));
+		AZ(ObjSetDouble(bo->vfc, OA_LASTMODIFIED, VTIM_parse(b)));
 	else
-		AZ(ObjSetDouble(bo->fetch_objcore, bo->stats, OA_LASTMODIFIED,
+		AZ(ObjSetDouble(bo->vfc, OA_LASTMODIFIED,
 		    floor(bo->fetch_objcore->exp.t_origin)));
 
 	return (0);
@@ -519,7 +517,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 
 	if (bo->vfc->failed && !bo->do_stream) {
 		assert(bo->state < BOS_STREAM);
-		if (bo->fetch_obj != NULL) {
+		if (bo->fetch_objcore != NULL) {
 			ObjFreeObj(bo->fetch_objcore, bo->stats);
 			bo->fetch_obj = NULL;
 		}
@@ -583,21 +581,12 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 	obj = bo->fetch_obj;
 	bo->vfc->body = obj->body;
 
-	if (bo->ims_obj->esidata != NULL) {
-		sl = bo->ims_obj->esidata->len;
-		obj->esidata = STV_alloc(bo->vfc, sl);
-		if (obj->esidata == NULL || obj->esidata->space < sl) {
-			VSLb(bo->vsl, SLT_Error,
-			    "No space for %zd bytes of ESI data", sl);
-			return (F_STP_FAIL);
-		}
-		memcpy(obj->esidata->ptr, bo->ims_obj->esidata->ptr, sl);
-		obj->esidata->len = sl;
-	}
+	if (ObjGetattr(bo->ims_oc, bo->stats, OA_ESIDATA, NULL) != NULL)
+		AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_ESIDATA));
 
 	obj->gziped = bo->ims_obj->gziped;
 
-	AZ(ObjCopyAttr(bo->fetch_objcore, bo->ims_oc,  bo->stats, OA_GZIPBITS));
+	AZ(ObjCopyAttr(bo->vfc, bo->ims_oc, OA_GZIPBITS));
 
 	AZ(WS_Overflowed(bo->ws_o));
 	if (bo->do_stream) {
@@ -749,7 +738,7 @@ vbf_stp_fail(struct worker *wrk, struct busyobj *bo)
 	HSH_Fail(bo->fetch_objcore);
 	if (bo->fetch_objcore->exp_flags & OC_EF_EXP) {
 		/* Already unbusied - expire it */
-		AN(bo->fetch_obj);
+		AN(bo->fetch_objcore);
 		EXP_Rearm(bo->fetch_objcore,
 		    bo->fetch_objcore->exp.t_origin, 0, 0, 0);
 	}
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index 14b26f2..fd83152 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -231,13 +231,13 @@ VFP_Fetch_Body(struct busyobj *bo)
 		}
 
 		CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC);
-		assert(st == VTAILQ_LAST(&bo->fetch_obj->body->list,
+		assert(st == VTAILQ_LAST(&bo->vfc->body->list,
 		    storagehead));
 		l = st->space - st->len;
 		AZ(bo->vfc->failed);
 		vfps = VFP_Suck(bo->vfc, st->ptr + st->len, &l);
 		if (l > 0 && vfps != VFP_ERROR) {
-			AZ(VTAILQ_EMPTY(&bo->fetch_obj->body->list));
+			AZ(VTAILQ_EMPTY(&bo->vfc->body->list));
 			VBO_extend(bo, l);
 		}
 		if (st->len == st->space)
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index e8112e8..8cafe6b 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -391,13 +391,12 @@ VGZ_WrwFlush(struct req *req, struct vgz *vg)
 /*--------------------------------------------------------------------*/
 
 void
-VGZ_UpdateObj(struct dstat *ds, const struct vgz *vg, struct objcore *oc)
+VGZ_UpdateObj(const struct vfp_ctx *vc, const struct vgz *vg)
 {
 	char *p;
 
 	CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
-	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-	p = ObjSetattr(oc, ds, OA_GZIPBITS, 24);
+	p = ObjSetattr(vc, OA_GZIPBITS, 24);
 	AN(p);
 	vbe64enc(p, vg->vz.start_bit);
 	vbe64enc(p + 8, vg->vz.last_bit);
@@ -601,7 +600,7 @@ vfp_gzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
 
 	if (vr != VGZ_END)
 		return (VFP_Error(vc, "Gzip failed"));
-	VGZ_UpdateObj(vc->bo->stats, vg, vc->bo->fetch_objcore);
+	VGZ_UpdateObj(vc, vg);
 	return (VFP_END);
 }
 
@@ -647,7 +646,7 @@ vfp_testgunzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
 	if (vp == VFP_END) {
 		if (vr != VGZ_END)
 			return (VFP_Error(vc, "tGunzip failed"));
-		VGZ_UpdateObj(vc->bo->stats, vg, vc->bo->fetch_objcore);
+		VGZ_UpdateObj(vc, vg);
 	}
 	return (vp);
 }
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index f249d7b..e18169a 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -173,7 +173,6 @@ ObjTrimStore(struct objcore *oc, struct dstat *ds)
 	}
 }
 
-
 struct object *
 ObjGetObj(struct objcore *oc, struct dstat *ds)
 {
@@ -255,16 +254,23 @@ ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
 }
 
 void *
-ObjSetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
+ObjSetattr(const struct vfp_ctx *vc, enum obj_attr attr,
     ssize_t len)
 {
 	struct object *o;
 
-	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
-	AN(ds);
-	o = ObjGetObj(oc, ds);
+	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(vc->bo, BUSYOBJ_MAGIC);
+	CHECK_OBJ_NOTNULL(vc->bo->fetch_objcore, OBJCORE_MAGIC);
+	o = ObjGetObj(vc->bo->fetch_objcore, vc->bo->stats);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	switch (attr) {
+	case OA_ESIDATA:
+		o->esidata = STV_alloc(vc, len);
+		if (o->esidata == NULL)
+			return (NULL);
+		o->esidata->len = len;
+		return (o->esidata->ptr);
 	case OA_GZIPBITS:
 		assert(len == sizeof o->oa_gzipbits);
 		return (o->oa_gzipbits);
@@ -281,17 +287,18 @@ ObjSetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
 }
 
 int
-ObjCopyAttr(struct objcore *ocd, struct objcore *ocs, struct dstat *ds,
-    enum obj_attr attr)
+ObjCopyAttr(const struct vfp_ctx *vc, struct objcore *ocs, enum obj_attr attr)
 {
 	void *vps, *vpd;
 	ssize_t l;
 
-	vps = ObjGetattr(ocs, ds, attr, &l);
+	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
+
+	vps = ObjGetattr(ocs, vc->bo->stats, attr, &l);
 	// XXX: later we want to have zero-length OA's too
 	if (vps == NULL || l <= 0)
 		return (-1);
-	vpd = ObjSetattr(ocd, ds, attr, l);
+	vpd = ObjSetattr(vc, attr, l);
 	if (vpd == NULL)
 		return (-1);
 	memcpy(vpd, vps, l);
@@ -314,7 +321,7 @@ ObjGetLen(struct objcore *oc, struct dstat *ds)
 
 	o = ObjGetObj(oc, ds);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
-	return (o->len);
+	return (o->body->len);
 }
 
 /*--------------------------------------------------------------------
@@ -326,14 +333,14 @@ ObjGetLen(struct objcore *oc, struct dstat *ds)
  */
 
 int
-ObjSetDouble(struct objcore *oc, struct dstat *ds, enum obj_attr a, double t)
+ObjSetDouble(const struct vfp_ctx *vc, enum obj_attr a, double t)
 {
 	void *vp;
 	uint64_t u;
 
 	assert(sizeof t == sizeof u);
 	memcpy(&u, &t, sizeof u);
-	vp = ObjSetattr(oc, ds, a, sizeof u);
+	vp = ObjSetattr(vc, a, sizeof u);
 	if (vp == NULL)
 		return (-1);
 	vbe64enc(vp, u);
@@ -363,11 +370,11 @@ ObjGetDouble(struct objcore *oc, struct dstat *ds, enum obj_attr a, double *d)
  */
 
 int
-ObjSetU64(struct objcore *oc, struct dstat *ds, enum obj_attr a, uint64_t t)
+ObjSetU64(const struct vfp_ctx *vc, enum obj_attr a, uint64_t t)
 {
 	void *vp;
 
-	vp = ObjSetattr(oc, ds, a, sizeof t);
+	vp = ObjSetattr(vc, a, sizeof t);
 	if (vp == NULL)
 		return (-1);
 	vbe64enc(vp, t);
@@ -389,11 +396,11 @@ ObjGetU64(struct objcore *oc, struct dstat *ds, enum obj_attr a, uint64_t *d)
 }
 
 int
-ObjSetU32(struct objcore *oc, struct dstat *ds, enum obj_attr a, uint32_t t)
+ObjSetU32(const struct vfp_ctx *vc, enum obj_attr a, uint32_t t)
 {
 	void *vp;
 
-	vp = ObjSetattr(oc, ds, a, sizeof t);
+	vp = ObjSetattr(vc, a, sizeof t);
 	if (vp == NULL)
 		return (-1);
 	vbe32enc(vp, t);
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 20225b5..03ef16c 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -218,7 +218,7 @@ pan_object(const char *typ, const struct object *o)
 	VSB_printf(pan_vsp, "  obj (%s) = %p {\n", typ, o);
 	VSB_printf(pan_vsp, "    vxid = %u,\n", VXID(vbe32dec(o->oa_vxid)));
 	pan_http("obj", o->http, 4);
-	VSB_printf(pan_vsp, "    len = %jd,\n", (intmax_t)o->len);
+	VSB_printf(pan_vsp, "    len = %jd,\n", (intmax_t)o->body->len);
 	VSB_printf(pan_vsp, "    store = {\n");
 	VTAILQ_FOREACH(st, &o->body->list, list)
 		pan_storage(st);
diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c
index ba56ddc..103c0bc 100644
--- a/bin/varnishd/storage/storage_persistent_silo.c
+++ b/bin/varnishd/storage/storage_persistent_silo.c
@@ -431,7 +431,7 @@ smp_oc_getobj(struct dstat *ds, struct objcore *oc)
 				break;
 			l += st->len;
 		}
-		if (l != o->len)
+		if (l != o->body->len)
 			bad |= 0x100;
 
 		if(bad) {



More information about the varnish-commit mailing list