[master] 841abfe Absorb struct sesspool into struct pool

Poul-Henning Kamp phk at FreeBSD.org
Tue May 26 22:36:43 CEST 2015


commit 841abfecb197a9182cf949e36d2debc31280a7ec
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 26 20:36:22 2015 +0000

    Absorb struct sesspool into struct pool

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index bb3c61d..399fdcb 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -616,16 +616,6 @@ struct req {
  * works, is not realistic without a lot of code changes.
  */
 
-struct sesspool {
-	unsigned		magic;
-#define SESSPOOL_MAGIC		0xd916e202
-	struct pool		*pool;
-	struct mempool		*mpl_req;
-	struct mempool		*mpl_sess;
-
-	struct waiter		*http1_waiter;
-};
-
 enum sess_attr {
 #define SESS_ATTR(UP, low, typ, len)	SA_##UP,
 #include "tbl/sess_attr.h"
@@ -644,7 +634,7 @@ struct sess {
 
 	/* Cross references ------------------------------------------*/
 
-	struct sesspool		*sesspool;
+	struct pool		*pool;
 
 	struct waited		waited;
 
@@ -686,7 +676,6 @@ typedef enum htc_status_e htc_complete_f(struct http_conn *);
 /* cache_acceptor.c */
 void VCA_Init(void);
 void VCA_Shutdown(void);
-void VCA_New_SessPool(struct pool *pp, struct sesspool *sp);
 
 /* cache_backend_cfg.c */
 void VBE_InitCfg(void);
@@ -990,12 +979,11 @@ int Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req);
 void Req_Fail(struct req *req, enum sess_close reason);
 
 /* cache_session.c [SES] */
-struct sess *SES_New(struct sesspool *);
+struct sess *SES_New(struct pool *);
 void SES_Close(struct sess *sp, enum sess_close reason);
 void SES_Wait(struct sess *sp);
 void SES_Delete(struct sess *sp, enum sess_close reason, double now);
-struct sesspool *SES_NewPool(struct pool *pp, unsigned pool_no);
-void SES_DeletePool(struct sesspool *sp);
+void SES_NewPool(struct pool *pp, unsigned pool_no);
 int SES_Reschedule_Req(struct req *);
 task_func_t SES_Proto_Sess;
 task_func_t SES_Proto_Req;
diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index f4ead24..45a1828 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -41,6 +41,7 @@
 #include <netinet/tcp.h>
 
 #include "cache.h"
+#include "cache_pool.h"
 #include "common/heritage.h"
 
 #include "vcli.h"
@@ -63,7 +64,6 @@ struct wrk_accept {
 	socklen_t		acceptaddrlen;
 	int			acceptsock;
 	struct listen_sock	*acceptlsock;
-	struct sesspool		*sesspool;
 };
 
 struct poolsock {
@@ -71,7 +71,7 @@ struct poolsock {
 #define POOLSOCK_MAGIC			0x1b0a2d38
 	struct listen_sock		*lsock;
 	struct pool_task		task;
-	struct sesspool			*sesspool;
+	struct pool			*pool;
 };
 
 /*--------------------------------------------------------------------
@@ -291,7 +291,6 @@ vca_pace_good(void)
 static void __match_proto__(task_func_t)
 vca_make_session(struct worker *wrk, void *arg)
 {
-	struct sesspool *pp;
 	struct sess *sp;
 	struct wrk_accept *wa;
 	struct sockaddr_storage ss;
@@ -304,11 +303,10 @@ vca_make_session(struct worker *wrk, void *arg)
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CAST_OBJ_NOTNULL(wa, arg, WRK_ACCEPT_MAGIC);
-	pp = wa->sesspool;
 
 	/* Turn accepted socket into a session */
 	AN(wrk->aws->r);
-	sp = SES_New(pp);
+	sp = SES_New(wrk->pool);
 	if (sp == NULL) {
 		/*
 		 * We consider this a DoS situation and silently close the
@@ -397,7 +395,6 @@ vca_accept_task(struct worker *wrk, void *arg)
 
 	while (1) {
 		INIT_OBJ(&wa, WRK_ACCEPT_MAGIC);
-		wa.sesspool = ps->sesspool;
 		wa.acceptlsock = ls;
 
 		vca_pace_check();
@@ -459,7 +456,7 @@ vca_accept_task(struct worker *wrk, void *arg)
  */
 
 void
-VCA_New_SessPool(struct pool *pp, struct sesspool *sp)
+VCA_NewPool(struct pool *pp)
 {
 	struct listen_sock *ls;
 	struct poolsock *ps;
@@ -470,7 +467,7 @@ VCA_New_SessPool(struct pool *pp, struct sesspool *sp)
 		ps->lsock = ls;
 		ps->task.func = vca_accept_task;
 		ps->task.priv = ps;
-		ps->sesspool = sp;
+		ps->pool = pp;
 		AZ(Pool_Task(pp, &ps->task, POOL_QUEUE_BACK));
 	}
 }
diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c
index f71980d..628b18c 100644
--- a/bin/varnishd/cache/cache_pool.c
+++ b/bin/varnishd/cache/cache_pool.c
@@ -145,8 +145,8 @@ pool_mkpool(unsigned pool_no)
 	while (VTAILQ_EMPTY(&pp->idle_queue))
 		(void)usleep(10000);
 
-	pp->sesspool = SES_NewPool(pp, pool_no);
-	AN(pp->sesspool);
+	SES_NewPool(pp, pool_no);
+	VCA_NewPool(pp);
 
 	return (pp);
 }
@@ -182,8 +182,13 @@ pool_poolherder(void *priv)
 			}
 		}
 		/* XXX: remove pools */
-		if (0)
-			SES_DeletePool(NULL);
+		if (0) {
+			pp = VTAILQ_FIRST(&pools);
+			AN(pp);
+			MPL_Destroy(&pp->mpl_sess);
+			MPL_Destroy(&pp->mpl_req);
+			INCOMPL();
+		}
 		(void)sleep(1);
 		u = 0;
 		VTAILQ_FOREACH(pp, &pools, list)
diff --git a/bin/varnishd/cache/cache_pool.h b/bin/varnishd/cache/cache_pool.h
index 76acc08..ea343e6 100644
--- a/bin/varnishd/cache/cache_pool.h
+++ b/bin/varnishd/cache/cache_pool.h
@@ -50,11 +50,16 @@ struct pool {
 	unsigned			lqueue;
 	uintmax_t			ndropped;
 	uintmax_t			nqueued;
-	struct sesspool			*sesspool;
 	struct dstat			*a_stat;
 	struct dstat			*b_stat;
+
+	struct waitfor			wf;
+	struct mempool			*mpl_req;
+	struct mempool			*mpl_sess;
+	struct waiter			*waiter;
 };
 
 void *pool_herder(void*);
 task_func_t pool_stat_summ;
 extern struct lock			pool_mtx;
+void VCA_NewPool(struct pool *pp);
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index 03c3557..4f02e26 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -38,6 +38,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
+#include "cache_pool.h"
 
 #include "vtim.h"
 
@@ -48,7 +49,7 @@
 struct req *
 Req_New(const struct worker *wrk, struct sess *sp)
 {
-	struct sesspool *pp;
+	struct pool *pp;
 	struct req *req;
 	uint16_t nhttp;
 	unsigned sz, hl;
@@ -56,9 +57,8 @@ Req_New(const struct worker *wrk, struct sess *sp)
 
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	pp = sp->sesspool;
-	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
-	AN(pp->pool);
+	pp = sp->pool;
+	CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
 
 	req = MPL_Get(pp->mpl_req, &sz);
 	AN(req);
@@ -114,7 +114,7 @@ void
 Req_Release(struct req *req)
 {
 	struct sess *sp;
-	struct sesspool *pp;
+	struct pool *pp;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 
@@ -129,9 +129,8 @@ Req_Release(struct req *req)
 		VSL_End(req->vsl);
 	sp = req->sp;
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	pp = sp->sesspool;
-	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
-	AN(pp->pool);
+	pp = sp->pool;
+	CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	MPL_AssertSane(req);
 	VSL_Flush(req->vsl, 0);
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index d49decc..76d47b8 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -46,6 +46,7 @@
 #include <stdlib.h>
 
 #include "cache.h"
+#include "cache_pool.h"
 
 #include "vsa.h"
 #include "vtcp.h"
@@ -299,16 +300,16 @@ SES_RxReq(const struct worker *wrk, struct req *req, htc_complete_f *func)
  */
 
 struct sess *
-SES_New(struct sesspool *pp)
+SES_New(struct pool *pp)
 {
 	struct sess *sp;
 	unsigned sz;
 	char *p, *e;
 
-	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
+	CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
 	sp = MPL_Get(pp->mpl_sess, &sz);
 	sp->magic = SESS_MAGIC;
-	sp->sesspool = pp;
+	sp->pool = pp;
 	memset(sp->sattr, 0xff, sizeof sp->sattr);
 
 	e = (char*)sp + sz;
@@ -403,19 +404,18 @@ int
 SES_Reschedule_Req(struct req *req)
 {
 	struct sess *sp;
-	struct sesspool *pp;
+	struct pool *pp;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	sp = req->sp;
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	pp = sp->sesspool;
-	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
-	AN(pp->pool);
+	pp = sp->pool;
+	CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
 
 	req->task.func = SES_Proto_Req;
 	req->task.priv = req;
 
-	return (Pool_Task(pp->pool, &req->task, POOL_QUEUE_FRONT));
+	return (Pool_Task(pp, &req->task, POOL_QUEUE_FRONT));
 }
 
 /*--------------------------------------------------------------------
@@ -426,7 +426,7 @@ static void __match_proto__(waiter_handle_f)
 ses_handle(struct waited *wp, enum wait_event ev, double now)
 {
 	struct sess *sp;
-	struct sesspool *pp;
+	struct pool *pp;
 	struct pool_task *tp;
 
 	CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
@@ -442,14 +442,13 @@ ses_handle(struct waited *wp, enum wait_event ev, double now)
 		SES_Delete(sp, SC_REM_CLOSE, now);
 		break;
 	case WAITER_ACTION:
-		pp = sp->sesspool;
-		CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
-		AN(pp->pool);
+		pp = sp->pool;
+		CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
 		assert(sizeof *tp == WS_Reserve(sp->ws, sizeof *tp));
 		tp = (void*)sp->ws->f;
 		tp->func = SES_Proto_Sess;
 		tp->priv = sp;
-		if (Pool_Task(pp->pool, tp, POOL_QUEUE_FRONT))
+		if (Pool_Task(pp, tp, POOL_QUEUE_FRONT))
 			SES_Delete(sp, SC_OVERLOAD, now);
 		break;
 	case WAITER_CLOSE:
@@ -466,11 +465,11 @@ ses_handle(struct waited *wp, enum wait_event ev, double now)
 void
 SES_Wait(struct sess *sp)
 {
-	struct sesspool *pp;
+	struct pool *pp;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	pp = sp->sesspool;
-	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
+	pp = sp->pool;
+	CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
 	/*
 	 * XXX: waiter_epoll prevents us from zeroing the struct because
 	 * XXX: it keeps state across calls.
@@ -483,7 +482,7 @@ SES_Wait(struct sess *sp)
 	sp->waited.fd = sp->fd;
 	sp->waited.ptr = sp;
 	sp->waited.idle = sp->t_idle;
-	if (Wait_Enter(pp->http1_waiter, &sp->waited))
+	if (Wait_Enter(pp->waiter, &sp->waited))
 		SES_Delete(sp, SC_PIPE_OVERFLOW, NAN);
 }
 
@@ -541,12 +540,11 @@ SES_Close(struct sess *sp, enum sess_close reason)
 void
 SES_Delete(struct sess *sp, enum sess_close reason, double now)
 {
-	struct sesspool *pp;
+	struct pool *pp;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	pp = sp->sesspool;
-	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
-	AN(pp->pool);
+	pp = sp->pool;
+	CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
 
 	if (reason != SC_NULL)
 		SES_Close(sp, reason);
@@ -573,17 +571,12 @@ SES_Delete(struct sess *sp, enum sess_close reason, double now)
  * Create and delete pools
  */
 
-static struct waitfor ses_wf;
-
-struct sesspool *
-SES_NewPool(struct pool *wp, unsigned pool_no)
+void
+SES_NewPool(struct pool *pp, unsigned pool_no)
 {
-	struct sesspool *pp;
 	char nb[8];
 
-	ALLOC_OBJ(pp, SESSPOOL_MAGIC);
-	AN(pp);
-	pp->pool = wp;
+	CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
 	bprintf(nb, "req%u", pool_no);
 	pp->mpl_req = MPL_New(nb, &cache_param->req_pool,
 	    &cache_param->workspace_client);
@@ -591,23 +584,8 @@ SES_NewPool(struct pool *wp, unsigned pool_no)
 	pp->mpl_sess = MPL_New(nb, &cache_param->sess_pool,
 	    &cache_param->workspace_session);
 
-	INIT_OBJ(&ses_wf, WAITFOR_MAGIC);
-	ses_wf.func = ses_handle;
-	ses_wf.tmo = &cache_param->timeout_idle;
-	pp->http1_waiter = Waiter_New(&ses_wf);
-
-	VCA_New_SessPool(wp, pp);
-	return (pp);
-}
-
-void
-SES_DeletePool(struct sesspool *pp)
-{
-
-	CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
-	MPL_Destroy(&pp->mpl_sess);
-	MPL_Destroy(&pp->mpl_req);
-	/* Delete session pool must stop acceptor threads */
-	FREE_OBJ(pp);
-	INCOMPL();
+	INIT_OBJ(&pp->wf, WAITFOR_MAGIC);
+	pp->wf.func = ses_handle;
+	pp->wf.tmo = &cache_param->timeout_idle;
+	pp->waiter = Waiter_New(&pp->wf);
 }



More information about the varnish-commit mailing list