From 455caef642a8b6b0aad65da7ebb285a431d6fdad Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 5 May 2022 20:16:16 +0200 Subject: [PATCH] CLEANUP: peers: do not use appctx.ctx anymore The peers code already uses its own generic pointer, let's move it to svcctx instead of keeping a struct peers in the appctx union. --- include/haproxy/applet-t.h | 3 --- src/peers.c | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/include/haproxy/applet-t.h b/include/haproxy/applet-t.h index 672755113..87b25fd70 100644 --- a/include/haproxy/applet-t.h +++ b/include/haproxy/applet-t.h @@ -91,9 +91,6 @@ struct appctx { char storage[APPLET_MAX_SVCCTX]; /* storage of svcctx above */ } svc; /* generic storage for most commands */ union { - struct { - void *ptr; /* current peer or NULL, do not use for something else */ - } peers; /* used by the peers applet */ struct { int connected; struct xref xref; /* cross reference with the Lua object owner. */ diff --git a/src/peers.c b/src/peers.c index 34de1f60c..0d9199537 100644 --- a/src/peers.c +++ b/src/peers.c @@ -1082,10 +1082,10 @@ void __peer_session_deinit(struct peer *peer) */ static void peer_session_release(struct appctx *appctx) { - struct peer *peer = appctx->ctx.peers.ptr; + struct peer *peer = appctx->svcctx; TRACE_PROTO("releasing peer session", PEERS_EV_SESSREL, NULL, peer); - /* appctx->ctx.peers.ptr is not a peer session */ + /* appctx->svcctx is not a peer session */ if (appctx->st0 < PEER_SESS_ST_SENDSUCCESS) return; @@ -1286,7 +1286,7 @@ static inline int peer_send_updatemsg(struct shared_table *st, struct appctx *ap .updateid = updateid, .use_identifier = use_identifier, .use_timed = use_timed, - .peer = appctx->ctx.peers.ptr, + .peer = appctx->svcctx, }, }; @@ -2842,7 +2842,7 @@ switchstate: switch(appctx->st0) { case PEER_SESS_ST_ACCEPT: prev_state = appctx->st0; - appctx->ctx.peers.ptr = NULL; + appctx->svcctx = NULL; appctx->st0 = PEER_SESS_ST_GETVERSION; /* fall through */ case PEER_SESS_ST_GETVERSION: @@ -2904,7 +2904,7 @@ switchstate: } curpeer->appctx = appctx; curpeer->flags |= PEER_F_ALIVE; - appctx->ctx.peers.ptr = curpeer; + appctx->svcctx = curpeer; appctx->st0 = PEER_SESS_ST_SENDSUCCESS; _HA_ATOMIC_INC(&active_peers); } @@ -2912,7 +2912,7 @@ switchstate: case PEER_SESS_ST_SENDSUCCESS: { prev_state = appctx->st0; if (!curpeer) { - curpeer = appctx->ctx.peers.ptr; + curpeer = appctx->svcctx; HA_SPIN_LOCK(PEER_LOCK, &curpeer->lock); if (curpeer->appctx != appctx) { appctx->st0 = PEER_SESS_ST_END; @@ -2937,7 +2937,7 @@ switchstate: case PEER_SESS_ST_CONNECT: { prev_state = appctx->st0; if (!curpeer) { - curpeer = appctx->ctx.peers.ptr; + curpeer = appctx->svcctx; HA_SPIN_LOCK(PEER_LOCK, &curpeer->lock); if (curpeer->appctx != appctx) { appctx->st0 = PEER_SESS_ST_END; @@ -2959,7 +2959,7 @@ switchstate: case PEER_SESS_ST_GETSTATUS: { prev_state = appctx->st0; if (!curpeer) { - curpeer = appctx->ctx.peers.ptr; + curpeer = appctx->svcctx; HA_SPIN_LOCK(PEER_LOCK, &curpeer->lock); if (curpeer->appctx != appctx) { appctx->st0 = PEER_SESS_ST_END; @@ -3008,7 +3008,7 @@ switchstate: prev_state = appctx->st0; if (!curpeer) { - curpeer = appctx->ctx.peers.ptr; + curpeer = appctx->svcctx; HA_SPIN_LOCK(PEER_LOCK, &curpeer->lock); if (curpeer->appctx != appctx) { appctx->st0 = PEER_SESS_ST_END; @@ -3183,7 +3183,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer goto out_close; appctx->st0 = PEER_SESS_ST_CONNECT; - appctx->ctx.peers.ptr = (void *)peer; + appctx->svcctx = (void *)peer; sess = session_new(p, NULL, &appctx->obj_type); if (!sess) {