[master] 0783808 Split the init and fini functions out for VFP's.

Poul-Henning Kamp phk at FreeBSD.org
Mon Jul 7 11:50:54 CEST 2014


commit 0783808a49d0f4fdcc6d5b35eec0f510c85b1108
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jul 7 09:35:19 2014 +0000

    Split the init and fini functions out for VFP's.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 996d3dc..a83ae19 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -885,8 +885,6 @@ void VFP_Init(void);
 void VFP_Fetch_Body(struct busyobj *bo, ssize_t est);
 void VFP_Push(struct busyobj *, const struct vfp *, intptr_t priv);
 enum vfp_status VFP_Suck(struct busyobj *, void *p, ssize_t *lp);
-extern char vfp_init[];
-extern char vfp_fini[];
 
 /* cache_gzip.c */
 struct vgz;
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 5b5f9ce..49f2e3d 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -141,6 +141,29 @@ vfp_esi_end(struct busyobj *bo, struct vef_priv *vef, enum vfp_status retval)
 	return (retval);
 }
 
+static enum vfp_status __match_proto__(vfp_init_f)
+vfp_esi_gzip_init(struct busyobj *bo, struct vfp_entry *vfe)
+{
+	struct vef_priv *vef;
+
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
+	ALLOC_OBJ(vef, VEF_MAGIC);
+	if (vef == NULL)
+		return (VFP_ERROR);
+	vef->vgz = VGZ_NewGzip(bo->vsl, "G F E");
+	vef->vep = VEP_Init(bo, vfp_vep_callback, vef);
+	vef->ibuf_sz = cache_param->gzip_buffer;
+	vef->ibuf = calloc(1L, vef->ibuf_sz);
+	if (vef->ibuf == NULL)
+		return (vfp_esi_end(bo, vef, VFP_ERROR));
+	XXXAN(vef->ibuf);
+	vef->ibuf_i = vef->ibuf;
+	vef->ibuf_o = vef->ibuf;
+	vfe->priv1 = vef;
+	return (VFP_OK);
+}
+
 static enum vfp_status __match_proto__(vfp_pull_f)
 vfp_esi_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp,
     struct vfp_entry *vfe)
@@ -151,29 +174,10 @@ vfp_esi_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp,
 
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
-	if (p == vfp_init) {
-		ALLOC_OBJ(vef, VEF_MAGIC);
-		XXXAN(vef);
-		vef->vgz = VGZ_NewGzip(bo->vsl, "G F E");
-		vef->vep = VEP_Init(bo, vfp_vep_callback, vef);
-		vef->ibuf_sz = cache_param->gzip_buffer;
-		vef->ibuf = calloc(1L, vef->ibuf_sz);
-		XXXAN(vef->ibuf);
-		vef->ibuf_i = vef->ibuf;
-		vef->ibuf_o = vef->ibuf;
-		vfe->priv1 = vef;
-		return (VFP_OK);
-	}
-	if (p == vfp_fini) {
-		if (vfe->priv1 != NULL)
-			(void)vfp_esi_end(bo, vfe->priv1, VFP_ERROR);
-		vfe->priv1 = NULL;
-		return (VFP_ERROR);
-	}
+	CAST_OBJ_NOTNULL(vef, vfe->priv1, VEF_MAGIC);
 	AN(p);
 	AN(lp);
 	*lp = 0;
-	CAST_OBJ_NOTNULL(vef, vfe->priv1, VEF_MAGIC);
 	l = vef->ibuf_sz - (vef->ibuf_i - vef->ibuf);
 	if (DO_DEBUG(DBG_ESI_CHOP)) {
 		d = (random() & 3) + 1;
@@ -203,6 +207,19 @@ vfp_esi_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp,
 	return (vp);
 }
 
+static enum vfp_status __match_proto__(vfp_init_f)
+vfp_esi_init(struct busyobj *bo, struct vfp_entry *vfe)
+{
+	struct vef_priv *vef;
+
+	ALLOC_OBJ(vef, VEF_MAGIC);
+	if (vef == NULL)
+		return (VFP_ERROR);
+	vef->vep = VEP_Init(bo, NULL, NULL);
+	vfe->priv1 = vef;
+	return (VFP_OK);
+}
+
 static enum vfp_status __match_proto__(vfp_pull_f)
 vfp_esi_pull(struct busyobj *bo, void *p, ssize_t *lp, struct vfp_entry *vfe)
 {
@@ -212,22 +229,9 @@ vfp_esi_pull(struct busyobj *bo, void *p, ssize_t *lp, struct vfp_entry *vfe)
 
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
-	if (p == vfp_init) {
-		ALLOC_OBJ(vef, VEF_MAGIC);
-		XXXAN(vef);
-		vef->vep = VEP_Init(bo, NULL, NULL);
-		vfe->priv1 = vef;
-		return (VFP_OK);
-	}
-	if (p == vfp_fini) {
-		if (vfe->priv1 != NULL)
-			(void)vfp_esi_end(bo, vfe->priv1, VFP_ERROR);
-		vfe->priv1 = NULL;
-		return (VFP_ERROR);
-	}
+	CAST_OBJ_NOTNULL(vef, vfe->priv1, VEF_MAGIC);
 	AN(p);
 	AN(lp);
-	CAST_OBJ_NOTNULL(vef, vfe->priv1, VEF_MAGIC);
 	if (DO_DEBUG(DBG_ESI_CHOP)) {
 		d = (random() & 3) + 1;
 		if (d < *lp)
@@ -243,10 +247,27 @@ vfp_esi_pull(struct busyobj *bo, void *p, ssize_t *lp, struct vfp_entry *vfe)
 	return (vp);
 }
 
+static void __match_proto__(vfp_fini_f)
+vfp_esi_fini(struct busyobj *bo, struct vfp_entry *vfe)
+{
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
+
+	if (vfe->priv1 != NULL)
+		(void)vfp_esi_end(bo, vfe->priv1, VFP_ERROR);
+	vfe->priv1 = NULL;
+}
+
 const struct vfp vfp_esi = {
+	.name = "ESI",
+	.init = vfp_esi_init,
 	.pull = vfp_esi_pull,
+	.fini = vfp_esi_fini,
 };
 
 const struct vfp vfp_esi_gzip = {
+	.name = "ESI_GZIP",
+	.init = vfp_esi_gzip_init,
 	.pull = vfp_esi_gzip_pull,
+	.fini = vfp_esi_fini,
 };
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index eae386d..ca3b172 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -43,9 +43,6 @@
 
 static unsigned fetchfrag;
 
-char vfp_init[] = "<init>";
-char vfp_fini[] = "<fini>";
-
 /*--------------------------------------------------------------------
  * We want to issue the first error we encounter on fetching and
  * supress the rest.  This function does that.
@@ -111,35 +108,33 @@ VFP_GetStorage(struct busyobj *bo, ssize_t sz)
 /**********************************************************************
  */
 
-static enum vfp_status
-vfp_call(struct busyobj *bo, struct vfp_entry *vfe, void *p, ssize_t *lp)
-{
-	AN(vfe->vfp->pull);
-	return (vfe->vfp->pull(bo, p, lp, vfe));
-}
-
 static void
 vfp_suck_fini(struct busyobj *bo)
 {
 	struct vfp_entry *vfe;
 
 	VTAILQ_FOREACH(vfe, &bo->vfp, list) {
-		if(vfe->vfp != NULL)
-			(void)vfp_call(bo, vfe, vfp_fini, NULL);
+		if(vfe->vfp != NULL && vfe->vfp->fini != NULL)
+			vfe->vfp->fini(bo, vfe);
 	}
 }
 
 static enum vfp_status
 vfp_suck_init(struct busyobj *bo)
 {
-	enum vfp_status retval = VFP_ERROR;
+	enum vfp_status retval = VFP_OK;
 	struct vfp_entry *vfe;
 
 	VTAILQ_FOREACH(vfe, &bo->vfp, list) {
-		retval = vfp_call(bo, vfe, vfp_init, NULL);
+		if (vfe->vfp->init == NULL)
+			continue;
+		retval = vfe->vfp->init(bo, vfe);
 		if (retval != VFP_OK) {
+			(void)VFP_Error(bo,
+			    "Fetch filter %s failed to initialize",
+			    vfe->vfp->name);
 			vfp_suck_fini(bo);
-			break;
+			return (retval);
 		}
 	}
 	return (retval);
@@ -170,9 +165,13 @@ VFP_Suck(struct busyobj *bo, void *p, ssize_t *lp)
 		bo->vfp_nxt = vfe;
 		return (vp);
 	} else {
-		vp = vfp_call(bo, vfe, p, lp);
+		vp = vfe->vfp->pull(bo, p, lp, vfe);
+		if (vp == VFP_ERROR)
+			(void)VFP_Error(bo, "Fetch filter %s returned %d",
+			    vfe->vfp->name, vp);
 		if (vp != VFP_OK) {
-			(void)vfp_call(bo, vfe, vfp_fini, NULL);
+			if (vfe->vfp->fini != NULL)
+				vfe->vfp->fini(bo, vfe);
 			vfe->vfp = NULL;
 			vfe->priv2 = vp;
 		}
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
index 0d0c670..2f0ce3c 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -38,11 +38,19 @@ enum vfp_status {
 	VFP_OK = 0,
 	VFP_END = 1,
 };
+
+typedef enum vfp_status vfp_init_f(struct busyobj *, struct vfp_entry *);
 typedef enum vfp_status
     vfp_pull_f(struct busyobj *, void *ptr, ssize_t *len, struct vfp_entry *);
+typedef void vfp_fini_f(struct busyobj *, struct vfp_entry *);
 
 struct vfp {
+	const char	*name;
+	vfp_init_f	*init;
 	vfp_pull_f	*pull;
+	vfp_fini_f	*fini;
+	const void	*priv1;
+	intptr_t	priv2;
 };
 
 extern const struct vfp vfp_gunzip;
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index bbae538..7653630 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -444,6 +444,30 @@ VGZ_Destroy(struct vgz **vgp)
 	return (vr);
 }
 
+/*--------------------------------------------------------------------*/
+
+static enum vfp_status __match_proto__(vfp_init_f)
+vfp_gzip_init(struct busyobj *bo, struct vfp_entry *vfe)
+{
+	struct vgz *vg;
+
+        CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
+
+	if (vfe->vfp->priv2)
+		vg = VGZ_NewGzip(bo->vsl, vfe->vfp->priv1);
+	else
+		vg = VGZ_NewUngzip(bo->vsl, vfe->vfp->priv1);
+	if (vg == NULL)
+		return (VFP_ERROR);
+	if (vgz_getmbuf(vg))
+		return (VFP_ERROR);
+	vfe->priv1 = vg;
+	VGZ_Ibuf(vg, vg->m_buf, 0);
+	AZ(vg->m_len);
+	return (VFP_OK);
+}
+
 /*--------------------------------------------------------------------
  * VFP_GUNZIP
  *
@@ -462,26 +486,9 @@ vfp_gunzip_pull(struct busyobj *bo, void *p, ssize_t *lp, struct vfp_entry *vfe)
 
         CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
-	if (p == vfp_init) {
-		vg = VGZ_NewUngzip(bo->vsl, "U F -");
-		XXXAZ(vgz_getmbuf(vg));
-		vfe->priv1 = vg;
-		VGZ_Ibuf(vg, vg->m_buf, 0);
-		AZ(vg->m_len);
-		return (VFP_OK);
-	}
-	if (p == vfp_fini) {
-		if (vfe->priv1 != NULL) {
-			CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC);
-			vfe->priv1 = NULL;
-			(void)VGZ_Destroy(&vg);
-		}
-		vfe->priv1 = NULL;
-		return (VFP_ERROR);
-	}
+	CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC);
         AN(p);
         AN(lp);
-	CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC);
 	l = *lp;
 	*lp = 0;
 	VGZ_Obuf(vg, p, l);
@@ -513,10 +520,6 @@ vfp_gunzip_pull(struct busyobj *bo, void *p, ssize_t *lp, struct vfp_entry *vfe)
 	return (vp);
 }
 
-const struct vfp vfp_gunzip = {
-	.pull = vfp_gunzip_pull,
-};
-
 
 /*--------------------------------------------------------------------
  * VFP_GZIP
@@ -536,26 +539,9 @@ vfp_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, struct vfp_entry *vfe)
 
         CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
-	if (p == vfp_init) {
-		vg = VGZ_NewGzip(bo->vsl, "G F -");
-		XXXAZ(vgz_getmbuf(vg));
-		vfe->priv1 = vg;
-		VGZ_Ibuf(vg, vg->m_buf, 0);
-		AZ(vg->m_len);
-		vg->flag = VGZ_NORMAL;
-		return (VFP_OK);
-	}
-	if (p == vfp_fini) {
-		if (vfe->priv1 != NULL) {
-			CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC);
-			vfe->priv1 = NULL;
-			(void)VGZ_Destroy(&vg);
-		}
-		return (VFP_ERROR);
-	}
+	CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC);
         AN(p);
         AN(lp);
-	CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC);
 	l = *lp;
 	*lp = 0;
 	VGZ_Obuf(vg, p, l);
@@ -588,10 +574,6 @@ vfp_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, struct vfp_entry *vfe)
 	return (VFP_END);
 }
 
-const struct vfp vfp_gzip = {
-	.pull = vfp_gzip_pull,
-};
-
 /*--------------------------------------------------------------------
  * VFP_TESTGZIP
  *
@@ -611,21 +593,7 @@ vfp_testgunzip_pull(struct busyobj *bo, void *p, ssize_t *lp,
 
         CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
-	if (p == vfp_init) {
-		vg = VGZ_NewUngzip(bo->vsl, "u F -");
-		XXXAZ(vgz_getmbuf(vg));
-		vfe->priv1 = vg;
-		AZ(vg->m_len);
-		return (VFP_OK);
-	}
-	if (p == vfp_fini) {
-		if (vfe->priv1 != NULL) {
-			CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC);
-			vfe->priv1 = NULL;
-			(void)VGZ_Destroy(&vg);
-		}
-		return (VFP_ERROR);
-	}
+	CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC);
         AN(p);
         AN(lp);
 	CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC);
@@ -652,6 +620,46 @@ vfp_testgunzip_pull(struct busyobj *bo, void *p, ssize_t *lp,
 	return (vp);
 }
 
+/*--------------------------------------------------------------------*/
+
+static void __match_proto__(vfp_fini_f)
+vfp_gzip_fini(struct busyobj *bo, struct vfp_entry *vfe)
+{
+	struct vgz *vg;
+
+        CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
+
+	if (vfe->priv1 != NULL) {
+		CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC);
+		vfe->priv1 = NULL;
+		(void)VGZ_Destroy(&vg);
+	}
+}
+
+/*--------------------------------------------------------------------*/
+
+const struct vfp vfp_gunzip = {
+	.name = "GUNZIP",
+	.init = vfp_gzip_init,
+	.pull = vfp_gunzip_pull,
+	.fini = vfp_gzip_fini,
+	.priv1 = "U F -",
+};
+
+const struct vfp vfp_gzip = {
+	.name = "GZIP",
+	.init = vfp_gzip_init,
+	.pull = vfp_gzip_pull,
+	.fini = vfp_gzip_fini,
+	.priv1 = "G F -",
+	.priv2 = 1,
+};
+
 const struct vfp vfp_testgunzip = {
+	.name = "TESTGUNZIP",
+	.init = vfp_gzip_init,
 	.pull = vfp_testgunzip_pull,
+	.fini = vfp_gzip_fini,
+	.priv1 = "u F -",
 };
diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c
index 9fa7258..4fe1855 100644
--- a/bin/varnishd/cache/cache_http1_fetch.c
+++ b/bin/varnishd/cache/cache_http1_fetch.c
@@ -77,10 +77,6 @@ v1f_pull_straight(struct busyobj *bo, void *p, ssize_t *lp,
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
 
-	if (p == vfp_init)
-		return (VFP_OK);
-	if (p == vfp_fini)
-		return (VFP_ERROR);
 	AN(p);
 	AN(lp);
 
@@ -103,6 +99,7 @@ v1f_pull_straight(struct busyobj *bo, void *p, ssize_t *lp,
 }
 
 static const struct vfp v1f_straight = {
+	.name = "V1F_STRAIGHT",
 	.pull = v1f_pull_straight,
 };
 
@@ -121,10 +118,6 @@ v1f_pull_chunked(struct busyobj *bo, void *p, ssize_t *lp,
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
 
-	if (p == vfp_init)
-		return (VFP_OK);
-	if (p == vfp_fini)
-		return (VFP_ERROR);
 	AN(p);
 	AN(lp);
 
@@ -142,6 +135,7 @@ v1f_pull_chunked(struct busyobj *bo, void *p, ssize_t *lp,
 }
 
 static const struct vfp v1f_chunked = {
+	.name = "V1F_CHUNKED",
 	.pull = v1f_pull_chunked,
 };
 
@@ -154,10 +148,6 @@ v1f_pull_eof(struct busyobj *bo, void *p, ssize_t *lp, struct vfp_entry *vfe)
 
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
-	if (p == vfp_init)
-		return (VFP_OK);
-	if (p == vfp_fini)
-		return (VFP_ERROR);
 	AN(p);
 	AN(lp);
 
@@ -173,6 +163,7 @@ v1f_pull_eof(struct busyobj *bo, void *p, ssize_t *lp, struct vfp_entry *vfe)
 }
 
 static const struct vfp v1f_eof = {
+	.name = "V1F_EOF",
 	.pull = v1f_pull_eof,
 };
 
diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt
index be84816..d394f75 100644
--- a/bin/varnishd/flint.lnt
+++ b/bin/varnishd/flint.lnt
@@ -113,6 +113,7 @@
 -sem(EXP_Inject, custodial(1))
 -sem(WS_Init, custodial(2))
 -sem(http_Setup, custodial(2))
+-sem(vfp_esi_end, custodial(2))
 
 -sem(vdi_dns_cache_list_add, custodial(3))
 



More information about the varnish-commit mailing list