Commit 0ad2c29e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move vca_handover() to SES_Handle()

Move vca_close_session() to SES_Close()
If SES_Delete() gets a reason, it calls SES_Close()

More work on the solaris ports waiter.
parent 74a0b311
......@@ -646,7 +646,6 @@ struct vbc {
/* cache_acceptor.c */
void vca_return_session(struct sess *sp);
void vca_close_session(struct sess *sp, const char *why);
void VCA_Prep(struct sess *sp);
void VCA_Init(void);
void VCA_Shutdown(void);
......@@ -861,7 +860,8 @@ void WRW_Sendfile(struct worker *w, int fd, off_t off, unsigned len);
void SES_Init(void);
struct sess *SES_New(void);
struct sess *SES_Alloc(void);
void SES_Delete(struct sess *sp);
void SES_Close(struct sess *sp, const char *reason);
void SES_Delete(struct sess *sp, const char *reason);
void SES_Charge(struct sess *sp);
/* cache_shmlog.c */
......
......@@ -330,46 +330,9 @@ vca_acct(void *arg)
NEEDLESS_RETURN(NULL);
}
/*--------------------------------------------------------------------*/
void
vca_handover(struct sess *sp, int status)
{
switch (status) {
case -2:
vca_close_session(sp, "blast");
SES_Delete(sp);
break;
case -1:
vca_close_session(sp, "no request");
SES_Delete(sp);
break;
case 1:
sp->step = STP_START;
if (Pool_QueueSession(sp))
VSC_C_main->client_drop_late++;
break;
default:
INCOMPL();
}
}
/*--------------------------------------------------------------------*/
void
vca_close_session(struct sess *sp, const char *why)
{
int i;
VSL(SLT_SessionClose, sp->id, "%s", why);
if (sp->fd >= 0) {
i = close(sp->fd);
assert(i == 0 || errno != EBADF); /* XXX EINVAL seen */
}
sp->fd = -1;
}
void
vca_return_session(struct sess *sp)
{
......@@ -383,7 +346,7 @@ vca_return_session(struct sess *sp)
* acceptor thread, to reduce syscall density of the latter.
*/
if (VTCP_nonblocking(sp->fd))
vca_close_session(sp, "remote closed");
SES_Close(sp, "remote closed");
vca_act->pass(waiter_priv, sp);
}
......
......@@ -116,14 +116,14 @@ cnt_wait(struct sess *sp)
return (0);
}
if (i == -2) {
vca_close_session(sp, "overflow");
SES_Close(sp, "overflow");
return (0);
}
if (i == -1 && Tlen(sp->htc->rxbuf) == 0 &&
(errno == 0 || errno == ECONNRESET))
vca_close_session(sp, "EOF");
SES_Close(sp, "EOF");
else
vca_close_session(sp, "error");
SES_Close(sp, "error");
sp->step = STP_DONE;
return (0);
}
......@@ -364,13 +364,13 @@ cnt_done(struct sess *sp)
* before we close, to get queued data transmitted.
*/
// XXX: not yet (void)VTCP_linger(sp->fd, 0);
vca_close_session(sp, sp->doclose);
SES_Close(sp, sp->doclose);
}
if (sp->fd < 0) {
sp->wrk->stats.sess_closed++;
sp->wrk = NULL;
SES_Delete(sp);
SES_Delete(sp, NULL);
return (1);
}
......@@ -1483,7 +1483,7 @@ cnt_start(struct sess *sp)
/* If we could not even parse the request, just close */
if (done == 400) {
sp->step = STP_DONE;
vca_close_session(sp, "junk");
SES_Close(sp, "junk");
return (0);
}
......
......@@ -335,8 +335,7 @@ ESI_Deliver(struct sess *sp)
st->ptr + off, l2,
obuf, sizeof obuf, &obufl);
if (WRW_Error(sp->wrk)) {
vca_close_session(sp,
"remote closed");
SES_Close(sp, "remote closed");
p = e;
break;
}
......@@ -388,7 +387,7 @@ ESI_Deliver(struct sess *sp)
obufl = 0;
}
if (WRW_Flush(sp->wrk)) {
vca_close_session(sp, "remote closed");
SES_Close(sp, "remote closed");
p = e;
break;
}
......
......@@ -87,7 +87,7 @@ PipeSession(struct sess *sp)
i = WRW_FlushRelease(w);
if (i) {
vca_close_session(sp, "pipe");
SES_Close(sp, "pipe");
VDI_CloseFd(sp);
return;
}
......@@ -127,6 +127,6 @@ PipeSession(struct sess *sp)
fds[1].fd = -1;
}
}
vca_close_session(sp, "pipe");
SES_Close(sp, "pipe");
VDI_CloseFd(sp);
}
......@@ -232,7 +232,6 @@ Pool_QueueSession(struct sess *sp)
* XXX: sleep whichever thread got us here
*/
sp->t_end = TIM_real();
vca_close_session(sp, "dropped");
if (sp->vcl != NULL) {
/*
* A session parked on a busy object can come here
......@@ -240,7 +239,7 @@ Pool_QueueSession(struct sess *sp)
*/
VCL_Rel(&sp->vcl);
}
SES_Delete(sp);
SES_Delete(sp, "dropped");
return (1);
}
......
......@@ -323,7 +323,7 @@ RES_WriteObj(struct sess *sp)
WRW_EndChunk(sp->wrk);
if (WRW_FlushRelease(sp->wrk))
vca_close_session(sp, "remote closed");
SES_Close(sp, "remote closed");
}
/*--------------------------------------------------------------------*/
......@@ -423,5 +423,5 @@ RES_StreamEnd(struct sess *sp)
!(sp->wrk->res_mode & RES_ESI_CHILD))
WRW_EndChunk(sp->wrk);
if (WRW_FlushRelease(sp->wrk))
vca_close_session(sp, "remote closed");
SES_Close(sp, "remote closed");
}
......@@ -48,6 +48,7 @@
#include "cache.h"
#include "cache_backend.h"
#include "cache_waiter.h"
/*--------------------------------------------------------------------*/
......@@ -238,12 +239,55 @@ SES_Alloc(void)
}
/*--------------------------------------------------------------------
* Recycle a session. If the workspace has changed, deleted it,
* Handle a session (from waiter)
*
* Status: see HTC_Rx()
*/
void
SES_Handle(struct sess *sp, int status)
{
switch (status) {
case -2:
SES_Delete(sp, "blast");
break;
case -1:
SES_Delete(sp, "no request");
break;
case 1:
sp->step = STP_START;
if (Pool_QueueSession(sp))
VSC_C_main->client_drop_late++;
break;
default:
WRONG("Unexpected return from HTC_Rx()");
}
}
/*--------------------------------------------------------------------
* Close a sessions connection.
*/
void
SES_Close(struct sess *sp, const char *reason)
{
int i;
assert(sp->fd >= 0);
VSL(SLT_SessionClose, sp->id, "%s", reason);
i = close(sp->fd);
assert(i == 0 || errno != EBADF); /* XXX EINVAL seen */
sp->fd = -1;
}
/*--------------------------------------------------------------------
* (Close &) Recycle a session. If the workspace has changed, deleted it,
* otherwise wash it, and put it up for adoption.
*/
void
SES_Delete(struct sess *sp)
SES_Delete(struct sess *sp, const char *reason)
{
struct acct *b = &sp->acct_ses;
struct sessmem *sm;
......@@ -253,6 +297,10 @@ SES_Delete(struct sess *sp)
sm = sp->mem;
CHECK_OBJ_NOTNULL(sm, SESSMEM_MAGIC);
if (reason != NULL)
SES_Close(sp, reason);
assert(sp->fd < 0);
AZ(sp->obj);
AZ(sp->vcl);
VSC_C_main->n_sess--; /* XXX: locking ? */
......
......@@ -53,5 +53,6 @@ extern struct waiter waiter_poll;
extern struct waiter waiter_ports;
#endif
/* vca_acceptor.c */
void vca_handover(struct sess *sp, int bad);
/* cache_session.c */
void SES_Handle(struct sess *sp, int status);
......@@ -138,19 +138,16 @@ vwe_eev(struct vwe *vwe, const struct epoll_event *ep)
return; /* more needed */
}
VTAILQ_REMOVE(&vwe->sesshead, sp, list);
vca_handover(sp, i);
SES_Handle(sp, i);
} else if (ep->events & EPOLLERR) {
VTAILQ_REMOVE(&vwe->sesshead, sp, list);
vca_close_session(sp, "ERR");
SES_Delete(sp);
SES_Delete(sp, "ERR");
} else if (ep->events & EPOLLHUP) {
VTAILQ_REMOVE(&vwe->sesshead, sp, list);
vca_close_session(sp, "HUP");
SES_Delete(sp);
SES_Delete(sp, "HUP");
} else if (ep->events & EPOLLRDHUP) {
VTAILQ_REMOVE(&vwe->sesshead, sp, list);
vca_close_session(sp, "RHUP");
SES_Delete(sp);
SES_Delete(sp, "RHUP");
}
}
}
......@@ -202,8 +199,7 @@ vwe_thread(void *priv)
break;
VTAILQ_REMOVE(&vwe->sesshead, sp, list);
// XXX: not yet VTCP_linger(sp->fd, 0);
vca_close_session(sp, "timeout");
SES_Delete(sp);
SES_Delete(sp, "timeout");
}
}
return NULL;
......
......@@ -125,12 +125,11 @@ vwk_kev(struct vwk *vwk, const struct kevent *kp)
return; /* more needed */
}
VTAILQ_REMOVE(&vwk->sesshead, sp, list);
vca_handover(sp, i);
SES_Handle(sp, i);
return;
} else if (kp->flags & EV_EOF) {
VTAILQ_REMOVE(&vwk->sesshead, sp, list);
vca_close_session(sp, "EOF");
SES_Delete(sp);
SES_Delete(sp, "EOF");
return;
} else {
VSL(SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s",
......@@ -196,8 +195,7 @@ vwk_thread(void *priv)
break;
VTAILQ_REMOVE(&vwk->sesshead, sp, list);
// XXX: not yet (void)VTCP_linger(sp->fd, 0);
vca_close_session(sp, "timeout");
SES_Delete(sp);
SES_Delete(sp, "timeout");
}
}
}
......
......@@ -165,14 +165,13 @@ vwp_main(void *priv)
VTAILQ_INSERT_HEAD(&vwp->sesshead, sp, list);
} else {
vwp_unpoll(vwp, fd);
vca_handover(sp, i);
SES_Handle(sp, i);
}
} else if (sp->t_open <= deadline) {
VTAILQ_REMOVE(&vwp->sesshead, sp, list);
vwp_unpoll(vwp, fd);
// XXX: not yet (void)VTCP_linger(sp->fd, 0);
vca_close_session(sp, "timeout");
SES_Delete(sp);
SES_Delete(sp, "timeout");
}
}
if (v && vwp->pollfd[vwp->pipes[0]].revents) {
......
......@@ -80,24 +80,23 @@ vws_port_ev(struct vws *vws, port_event_t *ev) {
assert(sp->fd >= 0);
AZ(sp->obj);
VTAILQ_INSERT_TAIL(&vws->sesshead, sp, list);
vws_add(vw, sp->fd, sp);
vws_add(vws, sp->fd, sp);
} else {
int i;
assert(ev->portev_source == PORT_SOURCE_FD);
CAST_OBJ_NOTNULL(sp, ev->portev_user, SESS_MAGIC);
assert(sp->fd >= 0);
if(ev->portev_events & POLLERR) {
vws_del(vws->sp->fd);
vws_del(vws, sp->fd);
VTAILQ_REMOVE(&vws->sesshead, sp, list);
vca_close_session(sp, "EOF");
SES_Delete(sp);
SES_Delete(sp, "EOF");
return;
}
i = HTC_Rx(sp->htc);
if (i == 0) {
/* incomplete header, wait for more data */
vws_add(sp->fd, sp);
vws_add(vws, sp->fd, sp);
return;
}
......@@ -113,11 +112,11 @@ vws_port_ev(struct vws *vws, port_event_t *ev) {
*
* Ref: http://opensolaris.org/jive/thread.jspa?threadID=129476&tstart=0
*/
vws_del(vws->sp->fd);
vws_del(vws, sp->fd);
VTAILQ_REMOVE(&vws->sesshead, sp, list);
/* vca_handover will also handle errors */
vca_handover(sp, i);
/* SES_Handle will also handle errors */
SES_Handle(sp, i);
}
return;
}
......@@ -128,7 +127,7 @@ vws_thread(void *priv)
struct sess *sp;
struct vws *vws;
CAST_OBJ_NOTNULL(vwp, priv, VWP_MAGIC);
CAST_OBJ_NOTNULL(vws, priv, VWS_MAGIC);
/*
* timeouts:
*
......@@ -219,8 +218,7 @@ vws_thread(void *priv)
if(sp->fd != -1) {
vws_del(vws, sp->fd);
}
vca_close_session(sp, "timeout");
SES_Delete(sp);
SES_Delete(sp, "timeout");
}
/*
......@@ -271,7 +269,7 @@ vws_init(void)
ALLOC_OBJ(vws, VWS_MAGIC);
AN(vws);
VTAILQ_INIT(&vws->sesshead);
AZ(pthread_create(&vws_ports_thread, NULL, vws_thread, vws));
AZ(pthread_create(&vws->ports_thread, NULL, vws_thread, vws));
return (vws);
}
......
......@@ -557,7 +557,6 @@ const struct stevedore smf_stevedore = {
#ifdef INCLUDE_TEST_DRIVER
void vca_flush(struct sess *sp) {}
void vca_close_session(struct sess *sp, const char *why) {}
#define N 100
#define M (128*1024)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment