MEDIUM: peers: don't rely on conn->xprt_ctx anymore

We make the peers code use applet->ptr instead of conn->xprt_ctx to
store the pointer to the current peer. That way it does not depend
on a connection anymore.
This commit is contained in:
Willy Tarreau 2013-07-08 16:05:07 +02:00
parent 306f8306cb
commit 9f68148321
2 changed files with 20 additions and 21 deletions

View File

@ -120,6 +120,7 @@ struct stream_interface {
unsigned int st0; /* CLI state for stats, session state for peers */ unsigned int st0; /* CLI state for stats, session state for peers */
unsigned int st1; /* prompt for stats, session error for peers */ unsigned int st1; /* prompt for stats, session error for peers */
unsigned int st2; /* output state for stats, unused by peers */ unsigned int st2; /* output state for stats, unused by peers */
void *ptr; /* struct peer for peers */
union { union {
struct { struct {

View File

@ -183,11 +183,10 @@ static int peer_prepare_datamsg(struct stksess *ts, struct peer_session *ps, cha
*/ */
static void peer_session_release(struct stream_interface *si) static void peer_session_release(struct stream_interface *si)
{ {
struct task *t = (struct task *)si->owner; struct session *s = session_from_task(si->owner);
struct session *s = (struct session *)t->context; struct peer_session *ps = (struct peer_session *)si->applet.ptr;
struct peer_session *ps = (struct peer_session *)si->conn->xprt_ctx;
/* si->conn->xprt_ctx is not a peer session */ /* si->applet.ptr is not a peer session */
if (si->applet.st0 < PEER_SESSION_SENDSUCCESS) if (si->applet.st0 < PEER_SESSION_SENDSUCCESS)
return; return;
@ -217,8 +216,7 @@ static void peer_session_release(struct stream_interface *si)
*/ */
static void peer_io_handler(struct stream_interface *si) static void peer_io_handler(struct stream_interface *si)
{ {
struct task *t= (struct task *)si->owner; struct session *s = session_from_task(si->owner);
struct session *s = (struct session *)t->context;
struct peers *curpeers = (struct peers *)s->fe->parent; struct peers *curpeers = (struct peers *)s->fe->parent;
int reql = 0; int reql = 0;
int repl = 0; int repl = 0;
@ -227,7 +225,7 @@ static void peer_io_handler(struct stream_interface *si)
switchstate: switchstate:
switch(si->applet.st0) { switch(si->applet.st0) {
case PEER_SESSION_ACCEPT: case PEER_SESSION_ACCEPT:
si->conn->xprt_ctx = NULL; si->applet.ptr = NULL;
si->applet.st0 = PEER_SESSION_GETVERSION; si->applet.st0 = PEER_SESSION_GETVERSION;
/* fall through */ /* fall through */
case PEER_SESSION_GETVERSION: case PEER_SESSION_GETVERSION:
@ -333,12 +331,12 @@ switchstate:
goto switchstate; goto switchstate;
} }
si->conn->xprt_ctx = curpeer; si->applet.ptr = curpeer;
si->applet.st0 = PEER_SESSION_GETTABLE; si->applet.st0 = PEER_SESSION_GETTABLE;
/* fall through */ /* fall through */
} }
case PEER_SESSION_GETTABLE: { case PEER_SESSION_GETTABLE: {
struct peer *curpeer = (struct peer *)si->conn->xprt_ctx; struct peer *curpeer = (struct peer *)si->applet.ptr;
struct shared_table *st; struct shared_table *st;
struct peer_session *ps = NULL; struct peer_session *ps = NULL;
unsigned long key_type; unsigned long key_type;
@ -349,12 +347,12 @@ switchstate:
if (reql <= 0) { /* closed or EOL not found */ if (reql <= 0) { /* closed or EOL not found */
if (reql == 0) if (reql == 0)
goto out; goto out;
si->conn->xprt_ctx = NULL; si->applet.ptr = NULL;
si->applet.st0 = PEER_SESSION_END; si->applet.st0 = PEER_SESSION_END;
goto switchstate; goto switchstate;
} }
/* Re init si->conn->xprt_ctx to null, to handle correctly a release case */ /* Re init si->applet.ptr to null, to handle correctly a release case */
si->conn->xprt_ctx = NULL; si->applet.ptr = NULL;
if (trash.str[reql-1] != '\n') { if (trash.str[reql-1] != '\n') {
/* Incomplete line, we quit */ /* Incomplete line, we quit */
@ -380,7 +378,7 @@ switchstate:
p = strchr(p+1, ' '); p = strchr(p+1, ' ');
if (!p) { if (!p) {
si->conn->xprt_ctx = NULL; si->applet.ptr = NULL;
si->applet.st0 = PEER_SESSION_EXIT; si->applet.st0 = PEER_SESSION_EXIT;
si->applet.st1 = PEER_SESSION_ERRPROTO; si->applet.st1 = PEER_SESSION_ERRPROTO;
goto switchstate; goto switchstate;
@ -444,12 +442,12 @@ switchstate:
goto switchstate; goto switchstate;
} }
si->conn->xprt_ctx = ps; si->applet.ptr = ps;
si->applet.st0 = PEER_SESSION_SENDSUCCESS; si->applet.st0 = PEER_SESSION_SENDSUCCESS;
/* fall through */ /* fall through */
} }
case PEER_SESSION_SENDSUCCESS:{ case PEER_SESSION_SENDSUCCESS:{
struct peer_session *ps = (struct peer_session *)si->conn->xprt_ctx; struct peer_session *ps = (struct peer_session *)si->applet.ptr;
repl = snprintf(trash.str, trash.size, "%d\n", PEER_SESSION_SUCCESSCODE); repl = snprintf(trash.str, trash.size, "%d\n", PEER_SESSION_SUCCESSCODE);
repl = bi_putblk(si->ib, trash.str, repl); repl = bi_putblk(si->ib, trash.str, repl);
@ -499,7 +497,7 @@ switchstate:
goto switchstate; goto switchstate;
} }
case PEER_SESSION_CONNECT: { case PEER_SESSION_CONNECT: {
struct peer_session *ps = (struct peer_session *)si->conn->xprt_ctx; struct peer_session *ps = (struct peer_session *)si->applet.ptr;
/* Send headers */ /* Send headers */
repl = snprintf(trash.str, trash.size, repl = snprintf(trash.str, trash.size,
@ -529,7 +527,7 @@ switchstate:
/* fall through */ /* fall through */
} }
case PEER_SESSION_GETSTATUS: { case PEER_SESSION_GETSTATUS: {
struct peer_session *ps = (struct peer_session *)si->conn->xprt_ctx; struct peer_session *ps = (struct peer_session *)si->applet.ptr;
if (si->ib->flags & CF_WRITE_PARTIAL) if (si->ib->flags & CF_WRITE_PARTIAL)
ps->statuscode = PEER_SESSION_CONNECTEDCODE; ps->statuscode = PEER_SESSION_CONNECTEDCODE;
@ -600,7 +598,7 @@ switchstate:
/* fall through */ /* fall through */
} }
case PEER_SESSION_WAITMSG: { case PEER_SESSION_WAITMSG: {
struct peer_session *ps = (struct peer_session *)si->conn->xprt_ctx; struct peer_session *ps = (struct peer_session *)si->applet.ptr;
struct stksess *ts, *newts = NULL; struct stksess *ts, *newts = NULL;
char c; char c;
int totl = 0; int totl = 0;
@ -1074,7 +1072,7 @@ static void peer_session_forceshutdown(struct session * session)
/* call release to reinit resync states if needed */ /* call release to reinit resync states if needed */
peer_session_release(oldsi); peer_session_release(oldsi);
oldsi->applet.st0 = PEER_SESSION_END; oldsi->applet.st0 = PEER_SESSION_END;
oldsi->conn->xprt_ctx = NULL; oldsi->applet.ptr = NULL;
task_wakeup(session->task, TASK_WOKEN_MSG); task_wakeup(session->task, TASK_WOKEN_MSG);
} }
@ -1089,7 +1087,7 @@ int peer_accept(struct session *s)
/* we have a dedicated I/O handler for the stats */ /* we have a dedicated I/O handler for the stats */
stream_int_register_handler(&s->si[1], &peer_applet); stream_int_register_handler(&s->si[1], &peer_applet);
s->target = s->si[1].conn->target; // for logging only s->target = s->si[1].conn->target; // for logging only
s->si[1].conn->xprt_ctx = s; s->si[1].applet.ptr = s;
s->si[1].applet.st0 = PEER_SESSION_ACCEPT; s->si[1].applet.st0 = PEER_SESSION_ACCEPT;
tv_zero(&s->logs.tv_request); tv_zero(&s->logs.tv_request);
@ -1180,7 +1178,7 @@ static struct session *peer_session_create(struct peer *peer, struct peer_sessio
stream_int_register_handler(&s->si[0], &peer_applet); stream_int_register_handler(&s->si[0], &peer_applet);
s->si[0].applet.st0 = PEER_SESSION_CONNECT; s->si[0].applet.st0 = PEER_SESSION_CONNECT;
s->si[0].conn->xprt_ctx = (void *)ps; s->si[0].applet.ptr = (void *)ps;
s->si[1].conn->t.sock.fd = -1; /* just to help with debugging */ s->si[1].conn->t.sock.fd = -1; /* just to help with debugging */
s->si[1].conn->flags = CO_FL_NONE; s->si[1].conn->flags = CO_FL_NONE;