[master] fe362e6 Divorce tcp_pools from backends

Poul-Henning Kamp phk at FreeBSD.org
Thu Oct 5 08:59:10 UTC 2017


commit fe362e60229fd3b6567113e9392627a39e7aeb49
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Oct 5 08:31:48 2017 +0000

    Divorce tcp_pools from backends

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 7e5ce45..895a73c 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -119,6 +119,7 @@ noinst_HEADERS = \
 	cache/cache_obj.h \
 	cache/cache_objhead.h \
 	cache/cache_pool.h \
+	cache/cache_tcp_pool.h \
 	cache/cache_transport.h \
 	cache/cache_varnishd.h \
 	cache/cache_vgz.h \
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 95f2ff2..6473be0 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -43,6 +43,7 @@
 
 #include "cache_director.h"
 #include "cache_backend.h"
+#include "cache_tcp_pool.h"
 #include "cache_transport.h"
 #include "http1/cache_http1.h"
 
@@ -95,7 +96,7 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo)
 	bo->htc->doclose = SC_NULL;
 
 	FIND_TMO(connect_timeout, tmod, bo, bp);
-	vbc = VBT_Get(bp->tcp_pool, tmod, bp, wrk);
+	vbc = VBT_Get(bp->tcp_pool, tmod, wrk);
 	if (vbc == NULL) {
 		// XXX: Per backend stats ?
 		VSC_C_main->backend_fail++;
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index 15cd260..58c6d83 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -77,27 +77,6 @@ struct backend {
 };
 
 /*---------------------------------------------------------------------
- * Backend connection -- private to cache_backend*.c
- */
-
-struct vbc {
-	unsigned		magic;
-#define VBC_MAGIC		0x0c5e6592
-	int			fd;
-	VTAILQ_ENTRY(vbc)	list;
-	const struct suckaddr	*addr;
-	uint8_t			state;
-#define VBC_STATE_AVAIL		(1<<0)
-#define VBC_STATE_USED		(1<<1)
-#define VBC_STATE_STOLEN	(1<<2)
-#define VBC_STATE_CLEANUP	(1<<3)
-	struct waited		waited[1];
-	struct tcp_pool		*tcp_pool;
-
-	pthread_cond_t		*cond;
-};
-
-/*---------------------------------------------------------------------
  * Prototypes
  */
 
@@ -119,17 +98,6 @@ void VBP_Remove(struct backend *b);
 void VBP_Control(const struct backend *b, int stop);
 void VBP_Status(struct cli *cli, const struct backend *, int details);
 
-/* cache_backend_tcp.c */
-struct tcp_pool *VBT_Ref(const struct suckaddr *ip4,
-    const struct suckaddr *ip6);
-void VBT_Rel(struct tcp_pool **tpp);
-int VBT_Open(const struct tcp_pool *tp, double tmo, const struct suckaddr **sa);
-void VBT_Recycle(const struct worker *, struct tcp_pool *, struct vbc **);
-void VBT_Close(struct tcp_pool *tp, struct vbc **vbc);
-struct vbc *VBT_Get(struct tcp_pool *, double tmo, const struct backend *,
-    struct worker *);
-void VBT_Wait(struct worker *, struct vbc *);
-
 /* cache_vcl.c */
 int VCL_AddBackend(struct vcl *, struct backend *);
 void VCL_DelBackend(struct backend *);
diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index d7f126d..6732aca 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -46,6 +46,7 @@
 
 #include "cache_director.h"
 #include "cache_backend.h"
+#include "cache_tcp_pool.h"
 
 #include "VSC_vbe.h"
 
diff --git a/bin/varnishd/cache/cache_backend_probe.c b/bin/varnishd/cache/cache_backend_probe.c
index 55f7e27..028fb33 100644
--- a/bin/varnishd/cache/cache_backend_probe.c
+++ b/bin/varnishd/cache/cache_backend_probe.c
@@ -53,6 +53,7 @@
 
 #include "cache_director.h"
 #include "cache_backend.h"
+#include "cache_tcp_pool.h"
 
 /* Default averaging rate, we want something pretty responsive */
 #define AVG_RATE			4
diff --git a/bin/varnishd/cache/cache_tcp_pool.c b/bin/varnishd/cache/cache_tcp_pool.c
index ce3f052..bd8d9ff 100644
--- a/bin/varnishd/cache/cache_tcp_pool.c
+++ b/bin/varnishd/cache/cache_tcp_pool.c
@@ -27,9 +27,6 @@
  *
  * TCP connection pools.
  *
- * These are really a lot more general than just backends, but backends
- * are all we use them for, so they live here for now.
- *
  */
 
 #include "config.h"
@@ -44,8 +41,7 @@
 #include "vtim.h"
 #include "waiter/waiter.h"
 
-#include "cache_director.h"
-#include "cache_backend.h"
+#include "cache_tcp_pool.h"
 #include "cache_pool.h"
 
 struct tcp_pool {
@@ -348,13 +344,11 @@ VBT_Close(struct tcp_pool *tp, struct vbc **vbcp)
  */
 
 struct vbc *
-VBT_Get(struct tcp_pool *tp, double tmo, const struct backend *be,
-    struct worker *wrk)
+VBT_Get(struct tcp_pool *tp, double tmo, struct worker *wrk)
 {
 	struct vbc *vbc;
 
 	CHECK_OBJ_NOTNULL(tp, TCP_POOL_MAGIC);
-	CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
 	Lck_Lock(&tp->mtx);
diff --git a/bin/varnishd/cache/cache_tcp_pool.h b/bin/varnishd/cache/cache_tcp_pool.h
new file mode 100644
index 0000000..78bfd08
--- /dev/null
+++ b/bin/varnishd/cache/cache_tcp_pool.h
@@ -0,0 +1,63 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2015 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * TCP connection pools
+ *
+ */
+
+struct tcp_pool;
+
+struct vbc {
+	unsigned		magic;
+#define VBC_MAGIC		0x0c5e6592
+	int			fd;
+	VTAILQ_ENTRY(vbc)	list;
+	const struct suckaddr	*addr;
+	uint8_t			state;
+#define VBC_STATE_AVAIL		(1<<0)
+#define VBC_STATE_USED		(1<<1)
+#define VBC_STATE_STOLEN	(1<<2)
+#define VBC_STATE_CLEANUP	(1<<3)
+	struct waited		waited[1];
+	struct tcp_pool		*tcp_pool;
+
+	pthread_cond_t		*cond;
+};
+
+/*---------------------------------------------------------------------
+ * Prototypes
+ */
+
+/* cache_tcp_pool.c */
+struct tcp_pool *VBT_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6);
+void VBT_Rel(struct tcp_pool **tpp);
+int VBT_Open(const struct tcp_pool *tp, double tmo, const struct suckaddr **sa);
+void VBT_Recycle(const struct worker *, struct tcp_pool *, struct vbc **);
+void VBT_Close(struct tcp_pool *tp, struct vbc **vbc);
+struct vbc *VBT_Get(struct tcp_pool *, double tmo, struct worker *);
+void VBT_Wait(struct worker *, struct vbc *);


More information about the varnish-commit mailing list