[master] 6eb3f1e Update the magic gzip bit positions whenever we spot them changing.

Poul-Henning Kamp phk at FreeBSD.org
Fri May 15 01:10:48 CEST 2015


commit 6eb3f1eb75e8cbaf5f3bec5c8eb5ae0b563c6ec5
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu May 14 22:44:33 2015 +0000

    Update the magic gzip bit positions whenever we spot them changing.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index f9e5326..cad336e 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -822,7 +822,14 @@ enum vgzret_e VGZ_Gzip(struct vgz *, const void **, ssize_t *len,
     enum vgz_flag);
 // enum vgzret_e VGZ_Gunzip(struct vgz *, const void **, ssize_t *len);
 enum vgzret_e VGZ_Destroy(struct vgz **);
-void VGZ_UpdateObj(const struct vfp_ctx *, const struct vgz*, int input);
+
+enum vgz_ua_e {
+	VUA_UPDATE,		// Update start/stop/last bits if changed
+	VUA_END_GZIP,		// Record uncompressed size
+	VUA_END_GUNZIP,		// Record uncompressed size
+};
+
+void VGZ_UpdateObj(const struct vfp_ctx *, struct vgz*, enum vgz_ua_e);
 
 /* cache_http.c */
 unsigned HTTP_estimate(unsigned nhttp);
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 0765302..558ee15 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -94,6 +94,7 @@ vfp_vep_callback(struct vfp_ctx *vc, void *priv, ssize_t l, enum vgz_flag flg)
 		}
 		VGZ_Obuf(vef->vgz, ptr, dl);
 		i = VGZ_Gzip(vef->vgz, &dp, &dl, flg);
+		VGZ_UpdateObj(vc, vef->vgz, VUA_UPDATE);
 		vef->tot += dl;
 		VBO_extend(vc->bo, dl);
 	} while (i != VGZ_ERROR &&
@@ -131,7 +132,7 @@ vfp_esi_end(struct vfp_ctx *vc, struct vef_priv *vef,
 	}
 
 	if (vef->vgz != NULL) {
-		VGZ_UpdateObj(vc, vef->vgz, 1);
+		VGZ_UpdateObj(vc, vef->vgz, VUA_END_GZIP);
 		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_gzip.c b/bin/varnishd/cache/cache_gzip.c
index d0b1ee0..272a284 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -59,6 +59,8 @@ struct vgz {
 	ssize_t			m_sz;
 	ssize_t			m_len;
 
+	intmax_t		bits;
+
 	z_stream		vz;
 };
 
@@ -348,19 +350,24 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
 /*--------------------------------------------------------------------*/
 
 void
-VGZ_UpdateObj(const struct vfp_ctx *vc, const struct vgz *vg, int input)
+VGZ_UpdateObj(const struct vfp_ctx *vc, struct vgz *vg, enum vgz_ua_e e)
 {
 	char *p;
+	intmax_t ii;
 
 	CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
+	ii = vg->vz.start_bit + vg->vz.last_bit + vg->vz.stop_bit;
+	if (e == VUA_UPDATE && ii == vg->bits)
+		return;
+	vg->bits = ii;
 	p = ObjSetattr(vc->wrk, vc->oc, OA_GZIPBITS, 32, NULL);
 	AN(p);
 	vbe64enc(p, vg->vz.start_bit);
 	vbe64enc(p + 8, vg->vz.last_bit);
 	vbe64enc(p + 16, vg->vz.stop_bit);
-	if (input)
+	if (e == VUA_END_GZIP)
 		vbe64enc(p + 24, vg->vz.total_in);
-	else
+	if (e == VUA_END_GUNZIP)
 		vbe64enc(p + 24, vg->vz.total_out);
 }
 
@@ -553,6 +560,7 @@ vfp_gzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
 			if (vr < VGZ_OK)
 				return (VFP_Error(vc, "Gzip failed"));
 			if (dl > 0) {
+				VGZ_UpdateObj(vc, vg, VUA_UPDATE);
 				*lp = dl;
 				assert(dp == p);
 				return (VFP_OK);
@@ -563,7 +571,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, vg, 1);
+	VGZ_UpdateObj(vc, vg, VUA_END_GZIP);
 	return (VFP_END);
 }
 
@@ -605,10 +613,11 @@ vfp_testgunzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
 				    "Invalid Gzip data: %s", vg->vz.msg));
 		} while (!VGZ_IbufEmpty(vg));
 	}
+	VGZ_UpdateObj(vc, vg, VUA_UPDATE);
 	if (vp == VFP_END) {
 		if (vr != VGZ_END)
 			return (VFP_Error(vc, "tGunzip failed"));
-		VGZ_UpdateObj(vc, vg, 0);
+		VGZ_UpdateObj(vc, vg, VUA_END_GUNZIP);
 	}
 	return (vp);
 }



More information about the varnish-commit mailing list