From: Christopher Faulet Date: Thu, 12 May 2022 12:47:52 +0000 (+0200) Subject: MINOR: peers: Add a ref to peers section in the peer structure X-Git-Tag: v2.6-dev11~79 X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=387e79727c3b3a82937d227a79e8741ede62e6d6;p=haproxy.git MINOR: peers: Add a ref to peers section in the peer structure This change is required to handle asynchrone init of the appctx. It is now possible to directly get the peers section associated to a peer. --- diff --git a/include/haproxy/peers-t.h b/include/haproxy/peers-t.h index 6d2a9688a..6a2e74925 100644 --- a/include/haproxy/peers-t.h +++ b/include/haproxy/peers-t.h @@ -80,6 +80,7 @@ struct peer { struct shared_table *tables; struct server *srv; struct dcache *dcache; /* dictionary cache */ + struct peers *peers; /* associated peer section */ struct peer *next; /* next peer in the list */ }; diff --git a/src/cfgparse.c b/src/cfgparse.c index 32b4cb366..b1ec46f2f 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -650,6 +650,7 @@ static struct peer *cfg_peers_add_peer(struct peers *peers, /* the peers are linked backwards first */ peers->count++; + p->peers = peers; p->next = peers->remote; peers->remote = p; p->conf.file = strdup(file); diff --git a/src/peers.c b/src/peers.c index 07520a4b4..267a68d21 100644 --- a/src/peers.c +++ b/src/peers.c @@ -443,11 +443,8 @@ static void peers_trace(enum trace_level level, uint64_t mask, const struct peer *peer = a2; struct peers *peers = NULL; - if (peer->appctx) { - struct stream *s = appctx_strm(peer->appctx); - - peers = strm_fe(s)->parent; - } + if (peer->appctx) + peers = peer->peers; if (peers) chunk_appendf(&trace_buf, " %s", peers->local->id); @@ -1037,16 +1034,9 @@ static int peer_prepare_ackmsg(char *msg, size_t size, struct peer_prep_params * */ void __peer_session_deinit(struct peer *peer) { - struct stream *s; - struct peers *peers; - - if (!peer->appctx) - return; - - s = appctx_strm(peer->appctx); + struct peers *peers = peer->peers; - peers = strm_fe(s)->parent; - if (!peers) + if (!peers || !peer->appctx) return; if (peer->appctx->st0 == PEER_SESS_ST_WAITMSG) @@ -2373,8 +2363,7 @@ static inline int peer_recv_msg(struct appctx *appctx, char *msg_head, size_t ms static inline int peer_treat_awaited_msg(struct appctx *appctx, struct peer *peer, unsigned char *msg_head, char **msg_cur, char *msg_end, int msg_len, int totl) { - struct stream *s = appctx_strm(appctx); - struct peers *peers = strm_fe(s)->parent; + struct peers *peers = peer->peers; if (msg_head[0] == PEER_MSG_CLASS_CONTROL) { if (msg_head[1] == PEER_MSG_CTRL_RESYNCREQ) {