this happens when all you want to do is get vmod_example to compile again
>From 3ff0e02fc2881f3a07dd466c5ae4f1022122959b Mon Sep 17 00:00:00 2001
From: Nils Goroll <[email protected]>
Date: Thu, 28 May 2015 19:50:41 +0200
Subject: [PATCH] Remove the waiter interface from cache.h, split
waited/waitfor, session: struct waited on ws
* We should not include waiter.h from cache.h as vmods requiring cache.h
should not need the waiter interface (otherwise we'd need to install waiter.h)
* Split the waiter/waitfor interfaces to avoid a multiple definition include mess
* For sessions, temporarily alloc struct waited on the ws - we don't need
the workspace while we are waiting, and we don't need struct waited unless
we are waiting
* Add Waiter_Done to invalidate struct waited and change the signature of
Wait_Call / waiter_handle_f to struct waited ** to allow for invalidation
of the struct waited pointer.
---
bin/varnishd/Makefile.am | 3 ++-
bin/varnishd/cache/cache.h | 5 ++--
bin/varnishd/cache/cache_backend.h | 2 ++
bin/varnishd/cache/cache_backend_tcp.c | 7 +++---
bin/varnishd/cache/cache_pool.h | 1 +
bin/varnishd/cache/cache_session.c | 33 ++++++++++++++++---------
bin/varnishd/waiter/cache_waiter.c | 20 +++++++++------
bin/varnishd/waiter/cache_waiter_epoll.c | 12 +++++----
bin/varnishd/waiter/cache_waiter_kqueue.c | 6 ++---
bin/varnishd/waiter/cache_waiter_poll.c | 6 +++--
bin/varnishd/waiter/cache_waiter_ports.c | 6 +++--
bin/varnishd/waiter/waiter.h | 16 ++++++------
bin/varnishd/waiter/waiter_priv.h | 2 +-
bin/varnishd/waiter/waitfor.h | 41 +++++++++++++++++++++++++++++++
14 files changed, 112 insertions(+), 48 deletions(-)
create mode 100644 bin/varnishd/waiter/waitfor.h
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 1b11581..0b3d3a5 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -95,7 +95,7 @@ varnishd_SOURCES = \
waiter/cache_waiter_epoll.c \
waiter/cache_waiter_kqueue.c \
waiter/cache_waiter_poll.c \
- waiter/cache_waiter_ports.c
+ waiter/cache_waiter_ports.c
noinst_HEADERS = \
builtin_vcl.h \
@@ -109,6 +109,7 @@ noinst_HEADERS = \
storage/storage.h \
storage/storage_persistent.h \
waiter/waiter.h \
+ waiter/waitfor.h \
waiter/waiter_priv.h \
waiter/mgt_waiter.h
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 399fdcb..b5836df 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -41,8 +41,6 @@
#include "vapi/vsl_int.h"
#include "vapi/vsm_int.h"
-#include "waiter/waiter.h"
-
#include <sys/socket.h>
#include <pthread.h>
@@ -124,6 +122,7 @@ struct vsb;
struct waitinglist;
struct worker;
struct v1l;
+struct waited;
#define DIGEST_LEN 32
@@ -636,7 +635,7 @@ struct sess {
struct pool *pool;
- struct waited waited;
+ struct waited *waited; // on ws while waiting
/* Session related fields ------------------------------------*/
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index 11f14bd..8b7ce94 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -37,6 +37,8 @@
*
*/
+#include "waiter/waiter.h"
+
struct vbp_target;
struct vbc;
struct vrt_backend_probe;
diff --git a/bin/varnishd/cache/cache_backend_tcp.c b/bin/varnishd/cache/cache_backend_tcp.c
index 70afa2e..588b897 100644
--- a/bin/varnishd/cache/cache_backend_tcp.c
+++ b/bin/varnishd/cache/cache_backend_tcp.c
@@ -76,12 +76,13 @@ static VTAILQ_HEAD(, tcp_pool) pools = VTAILQ_HEAD_INITIALIZER(pools);
*/
static void __match_proto__(waiter_handle_f)
-tcp_handle(struct waited *w, enum wait_event ev, double now)
+tcp_handle(struct waited **w, enum wait_event ev, double now)
{
struct vbc *vbc;
struct tcp_pool *tp;
- CAST_OBJ_NOTNULL(vbc, w->ptr, VBC_MAGIC);
+ CAST_OBJ_NOTNULL(vbc, (*w)->ptr, VBC_MAGIC);
+ Waiter_Done(w);
(void)ev;
(void)now;
CHECK_OBJ_NOTNULL(vbc->tcp_pool, TCP_POOL_MAGIC);
@@ -266,6 +267,7 @@ VBT_Recycle(const struct worker *wrk, struct tcp_pool *tp, struct vbc **vbcp)
Lck_Lock(&tp->mtx);
tp->n_used--;
+ INIT_OBJ(vbc->waited, WAITED_MAGIC);
vbc->waited->ptr = vbc;
vbc->waited->fd = vbc->fd;
vbc->waited->idle = VTIM_real();
@@ -375,7 +377,6 @@ VBT_Get(struct tcp_pool *tp, double tmo, struct backend *be, struct worker *wrk)
ALLOC_OBJ(vbc, VBC_MAGIC);
AN(vbc);
- INIT_OBJ(vbc->waited, WAITED_MAGIC);
vbc->state = VBC_STATE_USED;
vbc->tcp_pool = tp;
vbc->backend = be;
diff --git a/bin/varnishd/cache/cache_pool.h b/bin/varnishd/cache/cache_pool.h
index ea343e6..b16807f 100644
--- a/bin/varnishd/cache/cache_pool.h
+++ b/bin/varnishd/cache/cache_pool.h
@@ -30,6 +30,7 @@
*/
#include "config.h"
+#include "waiter/waitfor.h"
VTAILQ_HEAD(taskhead, pool_task);
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 2d55cba..40c24b8 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -47,7 +47,7 @@
#include "cache.h"
#include "cache_pool.h"
-
+#include "waiter/waiter.h"
#include "vsa.h"
#include "vtcp.h"
#include "vtim.h"
@@ -423,16 +423,21 @@ SES_Reschedule_Req(struct req *req)
*/
static void __match_proto__(waiter_handle_f)
-ses_handle(struct waited *wp, enum wait_event ev, double now)
+ses_handle(struct waited **wp, enum wait_event ev, double now)
{
struct sess *sp;
struct pool *pp;
struct pool_task *tp;
- CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
- CAST_OBJ_NOTNULL(sp, wp->ptr, SESS_MAGIC);
+ AN(wp);
+ CHECK_OBJ_NOTNULL(*wp, WAITED_MAGIC);
+ CAST_OBJ_NOTNULL(sp, (*wp)->ptr, SESS_MAGIC);
+ assert(sp->waited == *wp);
+ Waiter_Done(wp);
+ sp->waited = NULL;
- AZ(sp->ws->r);
+ AN(sp->ws->r);
+ WS_Release(sp->ws, 0);
switch (ev) {
case WAITER_TIMEOUT:
@@ -478,12 +483,18 @@ SES_Wait(struct sess *sp)
SES_Delete(sp, SC_REM_CLOSE, NAN);
return;
}
- sp->waited.magic = WAITED_MAGIC;
- sp->waited.fd = sp->fd;
- sp->waited.ptr = sp;
- sp->waited.idle = sp->t_idle;
- sp->waited.waitfor = &pp->wf;
- if (Wait_Enter(pp->waiter, &sp->waited))
+ if (WS_Reserve(sp->ws, sizeof(struct waited))
+ < sizeof(struct waited)) {
+ SES_Delete(sp, SC_OVERLOAD, NAN);
+ }
+ AZ(sp->waited);
+ sp->waited = (void*)sp->ws->f;
+ INIT_OBJ(sp->waited, WAITED_MAGIC);
+ sp->waited->fd = sp->fd;
+ sp->waited->ptr = sp;
+ sp->waited->idle = sp->t_idle;
+ sp->waited->waitfor = &pp->wf;
+ if (Wait_Enter(pp->waiter, sp->waited))
SES_Delete(sp, SC_PIPE_OVERFLOW, NAN);
}
diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c
index 7d23da5..c22fb50 100644
--- a/bin/varnishd/waiter/cache_waiter.c
+++ b/bin/varnishd/waiter/cache_waiter.c
@@ -38,6 +38,8 @@
#include "cache/cache.h"
+#include "waiter/waiter.h"
+#include "waiter/waitfor.h"
#include "waiter/waiter_priv.h"
#include "waiter/mgt_waiter.h"
@@ -68,16 +70,18 @@ waited_update(void *priv, void *p, unsigned u)
void
Wait_Call(const struct waiter *w,
- struct waited *wp, enum wait_event ev, double now)
+ struct waited **wp, enum wait_event ev, double now)
{
CHECK_OBJ_NOTNULL(w, WAITER_MAGIC);
- CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
- CHECK_OBJ_NOTNULL(wp->waitfor, WAITFOR_MAGIC);
- AN(wp->waitfor->func);
- if (wp->idx != BINHEAP_NOIDX)
- binheap_delete(w->heap, wp->idx);
- assert(wp->idx == BINHEAP_NOIDX);
- wp->waitfor->func(wp, ev, now);
+ AN(wp);
+ CHECK_OBJ_NOTNULL(*wp, WAITED_MAGIC);
+ CHECK_OBJ_NOTNULL((*wp)->waitfor, WAITFOR_MAGIC);
+ AN((*wp)->waitfor->func);
+ if ((*wp)->idx != BINHEAP_NOIDX)
+ binheap_delete(w->heap, (*wp)->idx);
+ assert((*wp)->idx == BINHEAP_NOIDX);
+ (*wp)->waitfor->func(wp, ev, now);
+ AZ(*wp);
}
/**********************************************************************/
diff --git a/bin/varnishd/waiter/cache_waiter_epoll.c b/bin/varnishd/waiter/cache_waiter_epoll.c
index 47b036f..afd4f06 100644
--- a/bin/varnishd/waiter/cache_waiter_epoll.c
+++ b/bin/varnishd/waiter/cache_waiter_epoll.c
@@ -41,6 +41,8 @@
#include "cache/cache.h"
+#include "waiter/waiter.h"
+#include "waiter/waitfor.h"
#include "waiter/waiter_priv.h"
#include "waiter/mgt_waiter.h"
#include "vtim.h"
@@ -102,7 +104,7 @@ vwe_thread(void *priv)
CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
AZ(epoll_ctl(vwe->epfd, EPOLL_CTL_DEL, wp->fd, NULL));
vwe->nwaited--;
- Wait_Call(w, wp, WAITER_TIMEOUT, now);
+ Wait_Call(w, &wp, WAITER_TIMEOUT, now);
}
then = vwe->next - now;
i = (int)ceil(1e3 * then);
@@ -122,13 +124,13 @@ vwe_thread(void *priv)
AZ(epoll_ctl(vwe->epfd, EPOLL_CTL_DEL, wp->fd, NULL));
vwe->nwaited--;
if (ep->events & EPOLLIN)
- Wait_Call(w, wp, WAITER_ACTION, now);
+ Wait_Call(w, &wp, WAITER_ACTION, now);
else if (ep->events & EPOLLERR)
- Wait_Call(w, wp, WAITER_REMCLOSE, now);
+ Wait_Call(w, &wp, WAITER_REMCLOSE, now);
else if (ep->events & EPOLLHUP)
- Wait_Call(w, wp, WAITER_REMCLOSE, now);
+ Wait_Call(w, &wp, WAITER_REMCLOSE, now);
else
- Wait_Call(w, wp, WAITER_REMCLOSE, now);
+ Wait_Call(w, &wp, WAITER_REMCLOSE, now);
}
if (vwe->nwaited == 0 && vwe->die)
break;
diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c
index baeed5c..0096beb 100644
--- a/bin/varnishd/waiter/cache_waiter_kqueue.c
+++ b/bin/varnishd/waiter/cache_waiter_kqueue.c
@@ -97,7 +97,7 @@ vwk_thread(void *priv)
CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
EV_SET(ke, wp->fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
AZ(kevent(vwk->kq, ke, 1, NULL, 0, NULL));
- Wait_Call(w, wp, WAITER_TIMEOUT, now);
+ Wait_Call(w, &wp, WAITER_TIMEOUT, now);
}
then = vwk->next - now;
ts.tv_sec = (time_t)floor(then);
@@ -117,9 +117,9 @@ vwk_thread(void *priv)
CAST_OBJ_NOTNULL(wp, ke[j].udata, WAITED_MAGIC);
vwk->nwaited--;
if (kp->flags & EV_EOF)
- Wait_Call(w, wp, WAITER_REMCLOSE, now);
+ Wait_Call(w, &wp, WAITER_REMCLOSE, now);
else
- Wait_Call(w, wp, WAITER_ACTION, now);
+ Wait_Call(w, &wp, WAITER_ACTION, now);
}
if (vwk->nwaited == 0 && vwk->die)
break;
diff --git a/bin/varnishd/waiter/cache_waiter_poll.c b/bin/varnishd/waiter/cache_waiter_poll.c
index 471d9e7..10509e8 100644
--- a/bin/varnishd/waiter/cache_waiter_poll.c
+++ b/bin/varnishd/waiter/cache_waiter_poll.c
@@ -36,6 +36,8 @@
#include "cache/cache.h"
+#include "waiter/waiter.h"
+#include "waiter/waitfor.h"
#include "waiter/waiter_priv.h"
#include "waiter/mgt_waiter.h"
#include "vtim.h"
@@ -185,12 +187,12 @@ vwp_main(void *priv)
v--;
then = Wait_When(wp);
if (then <= now) {
- Wait_Call(vwp->waiter, wp, WAITER_TIMEOUT, now);
+ Wait_Call(vwp->waiter, &wp, WAITER_TIMEOUT, now);
vwp_del(vwp, i);
} else if (vwp->pollfd[i].revents & POLLIN) {
assert(wp->fd > 0);
assert(wp->fd == vwp->pollfd[i].fd);
- Wait_Call(vwp->waiter, wp, WAITER_ACTION, now);
+ Wait_Call(vwp->waiter, &wp, WAITER_ACTION, now);
vwp_del(vwp, i);
} else {
i++;
diff --git a/bin/varnishd/waiter/cache_waiter_ports.c b/bin/varnishd/waiter/cache_waiter_ports.c
index f44959e..6db2965 100644
--- a/bin/varnishd/waiter/cache_waiter_ports.c
+++ b/bin/varnishd/waiter/cache_waiter_ports.c
@@ -72,6 +72,8 @@
#include "cache/cache.h"
+#include "waiter/waiter.h"
+#include "waiter/waitfor.h"
#include "waiter/waiter_priv.h"
#include "waiter/mgt_waiter.h"
#include "vtim.h"
@@ -124,7 +126,7 @@ vws_port_ev(struct vws *vws, struct waiter *w, port_event_t *ev, double now) {
* threadID=129476&tstart=0
*/
vws_del(vws, wp->fd);
- Wait_Call(w, wp, ev->portev_events & POLLERR ?
+ Wait_Call(w, &wp, ev->portev_events & POLLERR ?
WAITER_REMCLOSE : WAITER_ACTION,
now);
}
@@ -163,7 +165,7 @@ vws_thread(void *priv)
}
CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC);
vws_del(vws, wp->fd);
- Wait_Call(w, wp, WAITER_TIMEOUT, now);
+ Wait_Call(w, &wp, WAITER_TIMEOUT, now);
}
then = vws->next - now;
ts.tv_sec = (time_t)floor(then);
diff --git a/bin/varnishd/waiter/waiter.h b/bin/varnishd/waiter/waiter.h
index 488c8e3..57c1a00 100644
--- a/bin/varnishd/waiter/waiter.h
+++ b/bin/varnishd/waiter/waiter.h
@@ -44,6 +44,7 @@
struct waited;
struct waiter;
+struct waitfor;
enum wait_event {
WAITER_REMCLOSE,
@@ -52,15 +53,6 @@ enum wait_event {
WAITER_CLOSE
};
-typedef void waiter_handle_f(struct waited *, enum wait_event, double now);
-
-struct waitfor {
- unsigned magic;
-#define WAITFOR_MAGIC 0x16b79246
- waiter_handle_f *func;
- volatile double *tmo;
-};
-
struct waited {
unsigned magic;
#define WAITED_MAGIC 0x1743992d
@@ -71,6 +63,12 @@ struct waited {
double idle;
};
+static inline void
+Waiter_Done(struct waited **wpp) {
+ (*wpp)->magic = 0xde1e7ed;
+ *wpp = NULL;
+}
+
/* cache_waiter.c */
int Wait_Enter(const struct waiter *, struct waited *);
struct waiter *Waiter_New(void);
diff --git a/bin/varnishd/waiter/waiter_priv.h b/bin/varnishd/waiter/waiter_priv.h
index f4e5261..a605f8c 100644
--- a/bin/varnishd/waiter/waiter_priv.h
+++ b/bin/varnishd/waiter/waiter_priv.h
@@ -75,7 +75,7 @@ Wait_When(const struct waited *wp)
return (wp->idle + *wp->waitfor->tmo);
}
-void Wait_Call(const struct waiter *, struct waited *,
+void Wait_Call(const struct waiter *, struct waited **,
enum wait_event ev, double now);
void Wait_HeapInsert(const struct waiter *, struct waited *);
double Wait_HeapDue(const struct waiter *, struct waited **);
diff --git a/bin/varnishd/waiter/waitfor.h b/bin/varnishd/waiter/waitfor.h
new file mode 100644
index 0000000..745a5f8
--- /dev/null
+++ b/bin/varnishd/waiter/waitfor.h
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <[email protected]>
+ *
+ * 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.
+ *
+ */
+
+struct waited;
+enum wait_event;
+
+typedef void waiter_handle_f(struct waited **, enum wait_event, double now);
+
+struct waitfor {
+ unsigned magic;
+#define WAITFOR_MAGIC 0x16b79246
+ waiter_handle_f *func;
+ volatile double *tmo;
+};
--
2.1.4
_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev