[master] f77700f Allocate a small instance structure for each VFP pushed from the bo's workspace and eliminate the hardcoded limit of 5 VFPs.

Poul-Henning Kamp phk at FreeBSD.org
Thu Jul 3 22:13:24 CEST 2014


commit f77700f067a2b43c2a000c80b704caf2e15ebb98
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jul 3 20:12:29 2014 +0000

    Allocate a small instance structure for each VFP pushed from the
    bo's workspace and eliminate the hardcoded limit of 5 VFPs.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index b9e13fa..d0137fe 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -444,6 +444,15 @@ enum busyobj_state_e {
 	BOS_FAILED,		/* something went wrong */
 };
 
+struct vfp_entry {
+	unsigned		magic;
+#define VFP_ENTRY_MAGIC		0xbe32a027
+	const struct vfp	*vfp;
+	// void			*priv1;
+	intptr_t		priv2;
+	VTAILQ_ENTRY(vfp_entry)	list;
+};
+
 struct busyobj {
 	unsigned		magic;
 #define BUSYOBJ_MAGIC		0x23b95567
@@ -461,10 +470,8 @@ struct busyobj {
 
 	uint8_t			*vary;
 
-#define N_VFPS			5
-	const struct vfp	*vfps[N_VFPS];
-	intptr_t		vfps_priv[N_VFPS];
-	int			vfp_nxt;
+	VTAILQ_HEAD(,vfp_entry)	vfp;
+	struct vfp_entry	*vfp_nxt;
 
 	int			failed;
 	enum busyobj_state_e	state;
diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index 45e2845..0483579 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -147,6 +147,7 @@ VBO_GetBusyObj(struct worker *wrk, const struct req *req)
 	bo->director = req->director_hint;
 	bo->vcl = req->vcl;
 	VCL_Ref(bo->vcl);
+	VTAILQ_INIT(&bo->vfp);
 
 	bo->t_first = bo->t_prev = NAN;
 
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index 7e1b30b..20e5d09 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -112,20 +112,20 @@ VFP_GetStorage(struct busyobj *bo, ssize_t sz)
  */
 
 static enum vfp_status
-vfp_call(struct busyobj *bo, int nbr, void *p, ssize_t *lp)
+vfp_call(struct busyobj *bo, struct vfp_entry *vfe, void *p, ssize_t *lp)
 {
-	AN(bo->vfps[nbr]->pull);
-	return (bo->vfps[nbr]->pull(bo, p, lp, &bo->vfps_priv[nbr]));
+	AN(vfe->vfp->pull);
+	return (vfe->vfp->pull(bo, p, lp, &vfe->priv2));
 }
 
 static void
 vfp_suck_fini(struct busyobj *bo)
 {
-	int i;
+	struct vfp_entry *vfe;
 
-	for (i = 0; i < bo->vfp_nxt; i++) {
-		if(bo->vfps[i] != NULL)
-			(void)vfp_call(bo, i, vfp_fini, NULL);
+	VTAILQ_FOREACH(vfe, &bo->vfp, list) {
+		if(vfe->vfp != NULL)
+			(void)vfp_call(bo, vfe, vfp_fini, NULL);
 	}
 }
 
@@ -133,10 +133,10 @@ static enum vfp_status
 vfp_suck_init(struct busyobj *bo)
 {
 	enum vfp_status retval = VFP_ERROR;
-	int i;
+	struct vfp_entry *vfe;
 
-	for (i = 0; i < bo->vfp_nxt; i++) {
-		retval = vfp_call(bo, i, vfp_init, NULL);
+	VTAILQ_FOREACH(vfe, &bo->vfp, list) {
+		retval = vfp_call(bo, vfe, vfp_init, NULL);
 		if (retval != VFP_OK) {
 			vfp_suck_fini(bo);
 			break;
@@ -155,24 +155,29 @@ enum vfp_status
 VFP_Suck(struct busyobj *bo, void *p, ssize_t *lp)
 {
 	enum vfp_status vp;
+	struct vfp_entry *vfe;
 
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	AN(p);
 	AN(lp);
-	assert(bo->vfp_nxt > 0);
-	bo->vfp_nxt--;
-	if (bo->vfps[bo->vfp_nxt] == NULL) {
+	vfe = bo->vfp_nxt;
+	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
+	bo->vfp_nxt = VTAILQ_NEXT(vfe, list);
+
+	if (vfe->vfp == NULL) {
 		*lp = 0;
-		vp = (enum vfp_status)bo->vfps_priv[bo->vfp_nxt];
+		vp = (enum vfp_status)vfe->priv2;
+		bo->vfp_nxt = vfe;
+		return (vp);
 	} else {
-		vp = vfp_call(bo, bo->vfp_nxt, p, lp);
+		vp = vfp_call(bo, vfe, p, lp);
 		if (vp != VFP_OK) {
-			(void)vfp_call(bo, bo->vfp_nxt, vfp_fini, NULL);
-			bo->vfps[bo->vfp_nxt] = NULL;
-			bo->vfps_priv[bo->vfp_nxt] = vp;
+			(void)vfp_call(bo, vfe, vfp_fini, NULL);
+			vfe->vfp = NULL;
+			vfe->priv2 = vp;
 		}
 	}
-	bo->vfp_nxt++;
+	bo->vfp_nxt = vfe;
 	return (vp);
 }
 
@@ -252,11 +257,16 @@ VFP_Fetch_Body(struct busyobj *bo, ssize_t est)
 void
 VFP_Push(struct busyobj *bo, const struct vfp *vfp, intptr_t priv)
 {
+	struct vfp_entry *vfe;
 
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
-	bo->vfps_priv[bo->vfp_nxt] = priv;
-	bo->vfps[bo->vfp_nxt] = vfp;
-	bo->vfp_nxt++;
+	vfe = (void*)WS_Alloc(bo->ws, sizeof *vfe);
+	AN(vfe);
+	vfe->magic = VFP_ENTRY_MAGIC;
+	vfe->vfp = vfp;
+	vfe->priv2 = priv;
+	VTAILQ_INSERT_HEAD(&bo->vfp, vfe, list);
+	bo->vfp_nxt = vfe;
 }
 
 /*--------------------------------------------------------------------



More information about the varnish-commit mailing list