[master] 612d9de Make obj->gzip_bits a full OA also

Poul-Henning Kamp phk at FreeBSD.org
Wed Jul 30 14:10:11 CEST 2014


commit 612d9de41d27e712b9da3c0853459afa48e58046
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jul 30 12:09:47 2014 +0000

    Make obj->gzip_bits a full OA also

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index b13e997..6674100 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -564,7 +564,7 @@ struct object {
 	unsigned		changed_gzip:1;
 
 	/* Bit positions in the gzip stream */
-	ssize_t			gzip_bits[3];
+	char			oa_gzipbits[24];
 
 	ssize_t			len;
 
@@ -928,7 +928,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(const struct vgz*, struct object *);
+void VGZ_UpdateObj(struct dstat *ds, const struct vgz*, struct objcore *);
 vdp_bytes VDP_gunzip;
 
 int VGZ_WrwInit(struct vgz *vg);
@@ -1057,10 +1057,12 @@ struct object *ObjGetObj(struct objcore *, struct dstat *);
 void ObjUpdateMeta(struct objcore *);
 void ObjFreeObj(struct objcore *, struct dstat *);
 struct lru *ObjGetLRU(const struct objcore *);
-ssize_t ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
-    void **ptr);
+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);
 
 /* cache_panic.c */
 void PAN_Init(void);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index d74371a..3266ade 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -252,7 +252,6 @@ void
 ESI_Deliver(struct req *req)
 {
 	struct storage *st;
-	void *vp;
 	uint8_t *p, *e, *q, *r;
 	unsigned off;
 	ssize_t l, l2, l_icrc = 0;
@@ -265,9 +264,9 @@ ESI_Deliver(struct req *req)
 	int i;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	l = ObjGetattr(req->obj->objcore, &req->wrk->stats, OA_ESIDATA, &vp);
+	p = ObjGetattr(req->obj->objcore, &req->wrk->stats, OA_ESIDATA, &l);
+	AN(p);
 	assert(l > 0);
-	p = vp;
 	e = p + l;
 
 	if (*p == VEC_GZ) {
@@ -496,8 +495,8 @@ ESI_DeliverChild(struct req *req)
 	struct storage *st;
 	struct object *obj;
 	ssize_t start, last, stop, lpad;
-	void *vp;
-	ssize_t l, gzip_bits[3];
+	ssize_t l;
+	char *p;
 	u_char cc;
 	uint32_t icrc;
 	uint32_t ilen;
@@ -521,12 +520,12 @@ ESI_DeliverChild(struct req *req)
 	AN(dbits);
 	obj = req->obj;
 	CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
-	l = ObjGetattr(obj->objcore, &req->wrk->stats, OA_GZIPBITS, &vp);
-	assert(l == sizeof gzip_bits);
-	memcpy(gzip_bits, vp, l);
-	start = gzip_bits[0];
-	last = gzip_bits[1];
-	stop = gzip_bits[2];
+	p = ObjGetattr(obj->objcore, &req->wrk->stats, OA_GZIPBITS, &l);
+	AN(p);
+	assert(l == 24);
+	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);
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index c4bcef9..8014ca9 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -132,7 +132,7 @@ vfp_esi_end(struct vfp_ctx *vc, struct vef_priv *vef,
 	}
 
 	if (vef->vgz != NULL) {
-		VGZ_UpdateObj(vef->vgz, vc->bo->fetch_obj);
+		VGZ_UpdateObj(vc->bo->stats, vef->vgz, vc->bo->fetch_objcore);
 		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 a169e38..44bd58e 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -597,7 +597,8 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 	}
 
 	obj->gziped = bo->ims_obj->gziped;
-	memcpy(obj->gzip_bits, bo->ims_obj->gzip_bits, sizeof obj->gzip_bits);
+
+	AZ(ObjCopyAttr(bo->fetch_objcore, bo->ims_oc,  bo->stats, OA_GZIPBITS));
 
 	AZ(WS_Overflowed(bo->ws_o));
 	if (bo->do_stream) {
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index 0521a5f..e8112e8 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -42,6 +42,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
+#include "vend.h"
 
 #include "vgz.h"
 
@@ -390,14 +391,17 @@ VGZ_WrwFlush(struct req *req, struct vgz *vg)
 /*--------------------------------------------------------------------*/
 
 void
-VGZ_UpdateObj(const struct vgz *vg, struct object *obj)
+VGZ_UpdateObj(struct dstat *ds, const struct vgz *vg, struct objcore *oc)
 {
+	char *p;
 
 	CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
-	CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
-	obj->gzip_bits[0] = vg->vz.start_bit;
-	obj->gzip_bits[1] = vg->vz.last_bit;
-	obj->gzip_bits[2] = vg->vz.stop_bit;
+	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+	p = ObjSetattr(oc, ds, OA_GZIPBITS, 24);
+	AN(p);
+	vbe64enc(p, vg->vz.start_bit);
+	vbe64enc(p + 8, vg->vz.last_bit);
+	vbe64enc(p + 16, vg->vz.stop_bit);
 }
 
 /*--------------------------------------------------------------------
@@ -597,7 +601,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(vg, vc->bo->fetch_obj);
+	VGZ_UpdateObj(vc->bo->stats, vg, vc->bo->fetch_objcore);
 	return (VFP_END);
 }
 
@@ -643,7 +647,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(vg, vc->bo->fetch_obj);
+		VGZ_UpdateObj(vc->bo->stats, vg, vc->bo->fetch_objcore);
 	}
 	return (vp);
 }
diff --git a/bin/varnishd/cache/cache_obj.c b/bin/varnishd/cache/cache_obj.c
index 47fd31b..5ad3e4c 100644
--- a/bin/varnishd/cache/cache_obj.c
+++ b/bin/varnishd/cache/cache_obj.c
@@ -214,30 +214,29 @@ ObjGetLRU(const struct objcore *oc)
 	return (m->getlru(oc));
 }
 
-ssize_t
-ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr, void **ptr)
+void *
+ObjGetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
+   ssize_t *len)
 {
 	struct object *o;
-	void *dummy;
 
 	CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
 	AN(ds);
-	if (ptr == NULL)
-		ptr = &dummy;
+	AN(len);
 	o = ObjGetObj(oc, ds);
 	CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
 	switch (attr) {
 	case OA_VXID:
-		*ptr = o->oa_vxid;
-		return (sizeof o->oa_vxid);
+		*len = sizeof o->oa_vxid;
+		return (o->oa_vxid);
 	case OA_GZIPBITS:
-		*ptr = o->gzip_bits;
-		return (sizeof o->gzip_bits);
+		*len = sizeof o->oa_gzipbits;
+		return (o->oa_gzipbits);
 	case OA_ESIDATA:
 		if (o->esidata == NULL)
-			return (-1);
-		*ptr = o->esidata->ptr;
-		return (o->esidata->len);
+			return (NULL);
+		*len = o->esidata->len;
+		return (o->esidata->ptr);
 	default:
 		break;
 	}
@@ -257,18 +256,41 @@ ObjSetattr(struct objcore *oc, struct dstat *ds, enum obj_attr attr,
 	case OA_VXID:
 		assert(len == sizeof o->oa_vxid);
 		return (o->oa_vxid);
+	case OA_GZIPBITS:
+		assert(len == sizeof o->oa_gzipbits);
+		return (o->oa_gzipbits);
 	default:
 		break;
 	}
 	WRONG("Unsupported OBJ_ATTR");
 }
 
+int
+ObjCopyAttr(struct objcore *ocd, struct objcore *ocs, struct dstat *ds,
+    enum obj_attr attr)
+{
+	void *vps, *vpd;
+	ssize_t l;
+
+	vps = ObjGetattr(ocs, ds, 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);
+	if (vpd == NULL)
+		return (-1);
+	memcpy(vpd, vps, l);
+	return (0);
+}
 
 unsigned
 ObjGetXID(struct objcore *oc, struct dstat *ds)
 {
+	ssize_t l;
 	void *p;
 
-	assert(ObjGetattr(oc, ds, OA_VXID, &p) == 4);
+	p = ObjGetattr(oc, ds, OA_VXID, &l);
+	AN(p);
+	assert(l == 4);
 	return (vbe32dec(p));
 }



More information about the varnish-commit mailing list