mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 14:21:25 +02:00
MINOR: connection: Set the conncetion target during its initialisation
When a new connection is created, its target is always set just after. So the connection target may set when it is created instead, during its initialisation to be precise. It is the purpose of this patch. Now, conn_new() function is called with the connection target as parameter. The target is then passed to conn_init(). It means the target must be passed when cs_new() is called. In this case, the target is only used when the conn-stream is created with no connection. This only happens for tcpchecks for now.
This commit is contained in:
parent
fcc3d8a1c0
commit
236c93b108
@ -312,7 +312,7 @@ static inline void cs_init(struct conn_stream *cs, struct connection *conn)
|
|||||||
* is about to be reused. It also leaves the addresses untouched, which makes
|
* is about to be reused. It also leaves the addresses untouched, which makes
|
||||||
* it usable across connection retries to reset a connection to a known state.
|
* it usable across connection retries to reset a connection to a known state.
|
||||||
*/
|
*/
|
||||||
static inline void conn_init(struct connection *conn)
|
static inline void conn_init(struct connection *conn, void *target)
|
||||||
{
|
{
|
||||||
conn->obj_type = OBJ_TYPE_CONN;
|
conn->obj_type = OBJ_TYPE_CONN;
|
||||||
conn->flags = CO_FL_NONE;
|
conn->flags = CO_FL_NONE;
|
||||||
@ -322,7 +322,7 @@ static inline void conn_init(struct connection *conn)
|
|||||||
conn->send_proxy_ofs = 0;
|
conn->send_proxy_ofs = 0;
|
||||||
conn->handle.fd = DEAD_FD_MAGIC;
|
conn->handle.fd = DEAD_FD_MAGIC;
|
||||||
conn->err_code = CO_ER_NONE;
|
conn->err_code = CO_ER_NONE;
|
||||||
conn->target = NULL;
|
conn->target = target;
|
||||||
conn->destroy_cb = NULL;
|
conn->destroy_cb = NULL;
|
||||||
conn->proxy_netns = NULL;
|
conn->proxy_netns = NULL;
|
||||||
MT_LIST_INIT(&conn->list);
|
MT_LIST_INIT(&conn->list);
|
||||||
@ -388,13 +388,13 @@ static inline void sockaddr_free(struct sockaddr_storage **sap)
|
|||||||
* connection is returned on success, NULL on failure. The connection must
|
* connection is returned on success, NULL on failure. The connection must
|
||||||
* be released using pool_free() or conn_free().
|
* be released using pool_free() or conn_free().
|
||||||
*/
|
*/
|
||||||
static inline struct connection *conn_new()
|
static inline struct connection *conn_new(void *target)
|
||||||
{
|
{
|
||||||
struct connection *conn;
|
struct connection *conn;
|
||||||
|
|
||||||
conn = pool_alloc(pool_head_connection);
|
conn = pool_alloc(pool_head_connection);
|
||||||
if (likely(conn != NULL))
|
if (likely(conn != NULL))
|
||||||
conn_init(conn);
|
conn_init(conn, target);
|
||||||
return conn;
|
return conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ static inline void cs_free(struct conn_stream *cs)
|
|||||||
* to the mux's stream list on success, then returned. On failure, nothing is
|
* to the mux's stream list on success, then returned. On failure, nothing is
|
||||||
* allocated and NULL is returned.
|
* allocated and NULL is returned.
|
||||||
*/
|
*/
|
||||||
static inline struct conn_stream *cs_new(struct connection *conn)
|
static inline struct conn_stream *cs_new(struct connection *conn, void *target)
|
||||||
{
|
{
|
||||||
struct conn_stream *cs;
|
struct conn_stream *cs;
|
||||||
|
|
||||||
@ -423,12 +423,11 @@ static inline struct conn_stream *cs_new(struct connection *conn)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
conn = conn_new();
|
conn = conn_new(target);
|
||||||
if (unlikely(!conn)) {
|
if (unlikely(!conn)) {
|
||||||
cs_free(cs);
|
cs_free(cs);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
conn_init(conn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cs_init(cs, conn);
|
cs_init(cs, conn);
|
||||||
|
@ -372,7 +372,7 @@ static inline struct conn_stream *si_alloc_cs(struct stream_interface *si, struc
|
|||||||
|
|
||||||
si_release_endpoint(si);
|
si_release_endpoint(si);
|
||||||
|
|
||||||
cs = cs_new(conn);
|
cs = cs_new(conn, conn->target);
|
||||||
if (cs)
|
if (cs)
|
||||||
si_attach_cs(si, cs);
|
si_attach_cs(si, cs);
|
||||||
|
|
||||||
|
@ -1368,10 +1368,8 @@ int connect_server(struct stream *s)
|
|||||||
|
|
||||||
/* no reuse or failed to reuse the connection above, pick a new one */
|
/* no reuse or failed to reuse the connection above, pick a new one */
|
||||||
if (!srv_conn) {
|
if (!srv_conn) {
|
||||||
srv_conn = conn_new();
|
srv_conn = conn_new(s->target);
|
||||||
was_unused = 1;
|
was_unused = 1;
|
||||||
if (srv_conn)
|
|
||||||
srv_conn->target = s->target;
|
|
||||||
srv_cs = NULL;
|
srv_cs = NULL;
|
||||||
|
|
||||||
srv_conn->owner = s->sess;
|
srv_conn->owner = s->sess;
|
||||||
|
@ -3436,7 +3436,7 @@ static struct conn_stream *fcgi_attach(struct connection *conn, struct session *
|
|||||||
struct fcgi_conn *fconn = conn->ctx;
|
struct fcgi_conn *fconn = conn->ctx;
|
||||||
|
|
||||||
TRACE_ENTER(FCGI_EV_FSTRM_NEW, conn);
|
TRACE_ENTER(FCGI_EV_FSTRM_NEW, conn);
|
||||||
cs = cs_new(conn);
|
cs = cs_new(conn, conn->target);
|
||||||
if (!cs) {
|
if (!cs) {
|
||||||
TRACE_DEVEL("leaving on CS allocation failure", FCGI_EV_FSTRM_NEW|FCGI_EV_FSTRM_ERR, conn);
|
TRACE_DEVEL("leaving on CS allocation failure", FCGI_EV_FSTRM_NEW|FCGI_EV_FSTRM_ERR, conn);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -473,7 +473,7 @@ static struct conn_stream *h1s_new_cs(struct h1s *h1s)
|
|||||||
struct conn_stream *cs;
|
struct conn_stream *cs;
|
||||||
|
|
||||||
TRACE_ENTER(H1_EV_STRM_NEW, h1s->h1c->conn, h1s);
|
TRACE_ENTER(H1_EV_STRM_NEW, h1s->h1c->conn, h1s);
|
||||||
cs = cs_new(h1s->h1c->conn);
|
cs = cs_new(h1s->h1c->conn, h1s->h1c->conn->target);
|
||||||
if (!cs) {
|
if (!cs) {
|
||||||
TRACE_DEVEL("leaving on CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
|
TRACE_DEVEL("leaving on CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, h1s->h1c->conn, h1s);
|
||||||
goto err;
|
goto err;
|
||||||
@ -2372,7 +2372,7 @@ static struct conn_stream *h1_attach(struct connection *conn, struct session *se
|
|||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
cs = cs_new(h1c->conn);
|
cs = cs_new(h1c->conn, h1c->conn->target);
|
||||||
if (!cs) {
|
if (!cs) {
|
||||||
TRACE_DEVEL("leaving on CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, conn);
|
TRACE_DEVEL("leaving on CS allocation failure", H1_EV_STRM_NEW|H1_EV_STRM_END|H1_EV_STRM_ERR, conn);
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -1352,7 +1352,7 @@ static struct h2s *h2c_frt_stream_new(struct h2c *h2c, int id)
|
|||||||
if (!h2s)
|
if (!h2s)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
cs = cs_new(h2c->conn);
|
cs = cs_new(h2c->conn, h2c->conn->target);
|
||||||
if (!cs)
|
if (!cs)
|
||||||
goto out_close;
|
goto out_close;
|
||||||
|
|
||||||
@ -3818,7 +3818,7 @@ static struct conn_stream *h2_attach(struct connection *conn, struct session *se
|
|||||||
struct h2c *h2c = conn->ctx;
|
struct h2c *h2c = conn->ctx;
|
||||||
|
|
||||||
TRACE_ENTER(H2_EV_H2S_NEW, conn);
|
TRACE_ENTER(H2_EV_H2S_NEW, conn);
|
||||||
cs = cs_new(conn);
|
cs = cs_new(conn, conn->target);
|
||||||
if (!cs) {
|
if (!cs) {
|
||||||
TRACE_DEVEL("leaving on CS allocation failure", H2_EV_H2S_NEW|H2_EV_H2S_ERR, conn);
|
TRACE_DEVEL("leaving on CS allocation failure", H2_EV_H2S_NEW|H2_EV_H2S_ERR, conn);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -100,7 +100,7 @@ static int mux_pt_init(struct connection *conn, struct proxy *prx, struct sessio
|
|||||||
ctx->conn = conn;
|
ctx->conn = conn;
|
||||||
|
|
||||||
if (!cs) {
|
if (!cs) {
|
||||||
cs = cs_new(conn);
|
cs = cs_new(conn, conn->target);
|
||||||
if (!cs)
|
if (!cs)
|
||||||
goto fail_free_ctx;
|
goto fail_free_ctx;
|
||||||
|
|
||||||
@ -167,7 +167,7 @@ static struct conn_stream *mux_pt_attach(struct connection *conn, struct session
|
|||||||
|
|
||||||
if (ctx->wait_event.events)
|
if (ctx->wait_event.events)
|
||||||
conn->xprt->unsubscribe(ctx->conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event);
|
conn->xprt->unsubscribe(ctx->conn, conn->xprt_ctx, SUB_RETRY_RECV, &ctx->wait_event);
|
||||||
cs = cs_new(conn);
|
cs = cs_new(conn, conn->target);
|
||||||
if (!cs)
|
if (!cs)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
|
|||||||
|
|
||||||
ret = -1; /* assume unrecoverable error by default */
|
ret = -1; /* assume unrecoverable error by default */
|
||||||
|
|
||||||
if (unlikely((cli_conn = conn_new()) == NULL))
|
if (unlikely((cli_conn = conn_new(&l->obj_type)) == NULL))
|
||||||
goto out_close;
|
goto out_close;
|
||||||
|
|
||||||
if (!sockaddr_alloc(&cli_conn->src))
|
if (!sockaddr_alloc(&cli_conn->src))
|
||||||
@ -153,7 +153,6 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
|
|||||||
cli_conn->handle.fd = cfd;
|
cli_conn->handle.fd = cfd;
|
||||||
*cli_conn->src = *addr;
|
*cli_conn->src = *addr;
|
||||||
cli_conn->flags |= CO_FL_ADDR_FROM_SET;
|
cli_conn->flags |= CO_FL_ADDR_FROM_SET;
|
||||||
cli_conn->target = &l->obj_type;
|
|
||||||
cli_conn->proxy_netns = l->netns;
|
cli_conn->proxy_netns = l->netns;
|
||||||
|
|
||||||
conn_prepare(cli_conn, l->proto, l->bind_conf->xprt);
|
conn_prepare(cli_conn, l->proto, l->bind_conf->xprt);
|
||||||
|
@ -994,7 +994,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct tcpchec
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* 2- prepare new connection */
|
/* 2- prepare new connection */
|
||||||
cs = cs_new(NULL);
|
cs = cs_new(NULL, (s ? &s->obj_type : &proxy->obj_type));
|
||||||
if (!cs) {
|
if (!cs) {
|
||||||
chunk_printf(&trash, "TCPCHK error allocating connection at step %d",
|
chunk_printf(&trash, "TCPCHK error allocating connection at step %d",
|
||||||
tcpcheck_get_step_id(check, rule));
|
tcpcheck_get_step_id(check, rule));
|
||||||
@ -1028,9 +1028,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct tcpchec
|
|||||||
check->wait_list.events = 0;
|
check->wait_list.events = 0;
|
||||||
if (s) {
|
if (s) {
|
||||||
_HA_ATOMIC_ADD(&s->curr_used_conns, 1);
|
_HA_ATOMIC_ADD(&s->curr_used_conns, 1);
|
||||||
conn->target = &s->obj_type;
|
}
|
||||||
} else
|
|
||||||
conn->target = &proxy->obj_type;
|
|
||||||
|
|
||||||
/* no client address */
|
/* no client address */
|
||||||
if (!sockaddr_alloc(&conn->dst)) {
|
if (!sockaddr_alloc(&conn->dst)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user