Skip to content

Commit

Permalink
CLEANUP: conn_stream: apply cs_endp_flags.cocci tree-wide
Browse files Browse the repository at this point in the history
This changes all main uses of cs->endp->flags to the sc_ep_*() equivalent
by applying coccinelle script cs_endp_flags.cocci.

Note: 143 locations were touched, manually reviewed and found to be OK,
except a single one that was adjusted in cs_reset_endp() where the flags
are read and filtered to be used as-is and not as a boolean, hence was
replaced with sc_ep_get() & $FLAGS.

The script was applied with all includes:

  spatch --in-place --recursive-includes -I include --sp-file $script $files
  • Loading branch information
wtarreau committed May 27, 2022
1 parent 87b60b2 commit 0cfcc40
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 143 deletions.
54 changes: 27 additions & 27 deletions include/haproxy/conn_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static inline struct connection *__cs_conn(const struct conn_stream *cs)
}
static inline struct connection *cs_conn(const struct conn_stream *cs)
{
if (cs->endp->flags & CS_EP_T_MUX)
if (sc_ep_test(cs, CS_EP_T_MUX))
return __cs_conn(cs);
return NULL;
}
Expand All @@ -165,7 +165,7 @@ static inline void *__cs_mux(const struct conn_stream *cs)
}
static inline struct appctx *cs_mux(const struct conn_stream *cs)
{
if (cs->endp->flags & CS_EP_T_MUX)
if (sc_ep_test(cs, CS_EP_T_MUX))
return __cs_mux(cs);
return NULL;
}
Expand All @@ -180,7 +180,7 @@ static inline struct appctx *__cs_appctx(const struct conn_stream *cs)
}
static inline struct appctx *cs_appctx(const struct conn_stream *cs)
{
if (cs->endp->flags & CS_EP_T_APPLET)
if (sc_ep_test(cs, CS_EP_T_APPLET))
return __cs_appctx(cs);
return NULL;
}
Expand Down Expand Up @@ -229,14 +229,14 @@ static inline void cs_conn_shutr(struct conn_stream *cs, enum co_shr_mode mode)

BUG_ON(!cs_conn(cs));

if (cs->endp->flags & CS_EP_SHR)
if (sc_ep_test(cs, CS_EP_SHR))
return;

/* clean data-layer shutdown */
mux = cs_conn_mux(cs);
if (mux && mux->shutr)
mux->shutr(cs, mode);
cs->endp->flags |= (mode == CO_SHR_DRAIN) ? CS_EP_SHRD : CS_EP_SHRR;
sc_ep_set(cs, (mode == CO_SHR_DRAIN) ? CS_EP_SHRD : CS_EP_SHRR);
}

/* shut write */
Expand All @@ -246,14 +246,14 @@ static inline void cs_conn_shutw(struct conn_stream *cs, enum co_shw_mode mode)

BUG_ON(!cs_conn(cs));

if (cs->endp->flags & CS_EP_SHW)
if (sc_ep_test(cs, CS_EP_SHW))
return;

/* clean data-layer shutdown */
mux = cs_conn_mux(cs);
if (mux && mux->shutw)
mux->shutw(cs, mode);
cs->endp->flags |= (mode == CO_SHW_NORMAL) ? CS_EP_SHWN : CS_EP_SHWS;
sc_ep_set(cs, (mode == CO_SHW_NORMAL) ? CS_EP_SHWN : CS_EP_SHWS);
}

/* completely close a conn_stream (but do not detach it) */
Expand Down Expand Up @@ -301,7 +301,7 @@ static inline struct conn_stream *cs_conn_get_first(const struct connection *con
/* Returns non-zero if the conn-stream's Rx path is blocked */
static inline int cs_rx_blocked(const struct conn_stream *cs)
{
return !!(cs->endp->flags & CS_EP_RXBLK_ANY);
return !!sc_ep_test(cs, CS_EP_RXBLK_ANY);
}


Expand All @@ -310,55 +310,55 @@ static inline int cs_rx_blocked(const struct conn_stream *cs)
*/
static inline int cs_rx_blocked_room(const struct conn_stream *cs)
{
return !!(cs->endp->flags & CS_EP_RXBLK_ROOM);
return !!sc_ep_test(cs, CS_EP_RXBLK_ROOM);
}

/* Returns non-zero if the conn-stream's endpoint is ready to receive */
static inline int cs_rx_endp_ready(const struct conn_stream *cs)
{
return !(cs->endp->flags & CS_EP_RX_WAIT_EP);
return !sc_ep_test(cs, CS_EP_RX_WAIT_EP);
}

/* The conn-stream announces it is ready to try to deliver more data to the input buffer */
static inline void cs_rx_endp_more(struct conn_stream *cs)
{
cs->endp->flags &= ~CS_EP_RX_WAIT_EP;
sc_ep_clr(cs, CS_EP_RX_WAIT_EP);
}

/* The conn-stream announces it doesn't have more data for the input buffer */
static inline void cs_rx_endp_done(struct conn_stream *cs)
{
cs->endp->flags |= CS_EP_RX_WAIT_EP;
sc_ep_set(cs, CS_EP_RX_WAIT_EP);
}

/* Tell a conn-stream the input channel is OK with it sending it some data */
static inline void cs_rx_chan_rdy(struct conn_stream *cs)
{
cs->endp->flags &= ~CS_EP_RXBLK_CHAN;
sc_ep_clr(cs, CS_EP_RXBLK_CHAN);
}

/* Tell a conn-stream the input channel is not OK with it sending it some data */
static inline void cs_rx_chan_blk(struct conn_stream *cs)
{
cs->endp->flags |= CS_EP_RXBLK_CHAN;
sc_ep_set(cs, CS_EP_RXBLK_CHAN);
}

/* Tell a conn-stream the other side is connected */
static inline void cs_rx_conn_rdy(struct conn_stream *cs)
{
cs->endp->flags &= ~CS_EP_RXBLK_CONN;
sc_ep_clr(cs, CS_EP_RXBLK_CONN);
}

/* Tell a conn-stream it must wait for the other side to connect */
static inline void cs_rx_conn_blk(struct conn_stream *cs)
{
cs->endp->flags |= CS_EP_RXBLK_CONN;
sc_ep_set(cs, CS_EP_RXBLK_CONN);
}

/* The conn-stream just got the input buffer it was waiting for */
static inline void cs_rx_buff_rdy(struct conn_stream *cs)
{
cs->endp->flags &= ~CS_EP_RXBLK_BUFF;
sc_ep_clr(cs, CS_EP_RXBLK_BUFF);
}

/* The conn-stream failed to get an input buffer and is waiting for it.
Expand All @@ -368,13 +368,13 @@ static inline void cs_rx_buff_rdy(struct conn_stream *cs)
*/
static inline void cs_rx_buff_blk(struct conn_stream *cs)
{
cs->endp->flags |= CS_EP_RXBLK_BUFF;
sc_ep_set(cs, CS_EP_RXBLK_BUFF);
}

/* Tell a conn-stream some room was made in the input buffer */
static inline void cs_rx_room_rdy(struct conn_stream *cs)
{
cs->endp->flags &= ~CS_EP_RXBLK_ROOM;
sc_ep_clr(cs, CS_EP_RXBLK_ROOM);
}

/* The conn-stream announces it failed to put data into the input buffer
Expand All @@ -384,7 +384,7 @@ static inline void cs_rx_room_rdy(struct conn_stream *cs)
*/
static inline void cs_rx_room_blk(struct conn_stream *cs)
{
cs->endp->flags |= CS_EP_RXBLK_ROOM;
sc_ep_set(cs, CS_EP_RXBLK_ROOM);
}

/* The conn-stream announces it will never put new data into the input
Expand All @@ -393,43 +393,43 @@ static inline void cs_rx_room_blk(struct conn_stream *cs)
*/
static inline void cs_rx_shut_blk(struct conn_stream *cs)
{
cs->endp->flags |= CS_EP_RXBLK_SHUT;
sc_ep_set(cs, CS_EP_RXBLK_SHUT);
}

/* Returns non-zero if the conn-stream's Tx path is blocked */
static inline int cs_tx_blocked(const struct conn_stream *cs)
{
return !!(cs->endp->flags & CS_EP_WAIT_DATA);
return !!sc_ep_test(cs, CS_EP_WAIT_DATA);
}

/* Returns non-zero if the conn-stream's endpoint is ready to transmit */
static inline int cs_tx_endp_ready(const struct conn_stream *cs)
{
return (cs->endp->flags & CS_EP_WANT_GET);
return sc_ep_test(cs, CS_EP_WANT_GET);
}

/* Report that a conn-stream wants to get some data from the output buffer */
static inline void cs_want_get(struct conn_stream *cs)
{
cs->endp->flags |= CS_EP_WANT_GET;
sc_ep_set(cs, CS_EP_WANT_GET);
}

/* Report that a conn-stream failed to get some data from the output buffer */
static inline void cs_cant_get(struct conn_stream *cs)
{
cs->endp->flags |= CS_EP_WANT_GET | CS_EP_WAIT_DATA;
sc_ep_set(cs, CS_EP_WANT_GET | CS_EP_WAIT_DATA);
}

/* Report that a conn-stream doesn't want to get data from the output buffer */
static inline void cs_stop_get(struct conn_stream *cs)
{
cs->endp->flags &= ~CS_EP_WANT_GET;
sc_ep_clr(cs, CS_EP_WANT_GET);
}

/* Report that a conn-stream won't get any more data from the output buffer */
static inline void cs_done_get(struct conn_stream *cs)
{
cs->endp->flags &= ~(CS_EP_WANT_GET | CS_EP_WAIT_DATA);
sc_ep_clr(cs, CS_EP_WANT_GET | CS_EP_WAIT_DATA);
}

#endif /* _HAPROXY_CONN_STREAM_H */
6 changes: 3 additions & 3 deletions include/haproxy/cs_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ static inline int cs_get_dst(struct conn_stream *cs)
/* Marks on the conn-stream that next shutw must kill the whole connection */
static inline void cs_must_kill_conn(struct conn_stream *cs)
{
cs->endp->flags |= CS_EP_KILL_CONN;
sc_ep_set(cs, CS_EP_KILL_CONN);
}


Expand All @@ -292,7 +292,7 @@ static inline void cs_shutw(struct conn_stream *cs)
*/
static inline void cs_chk_rcv(struct conn_stream *cs)
{
if (cs->endp->flags & CS_EP_RXBLK_CONN && cs_state_in(cs_opposite(cs)->state, CS_SB_RDY|CS_SB_EST|CS_SB_DIS|CS_SB_CLO))
if (sc_ep_test(cs, CS_EP_RXBLK_CONN) && cs_state_in(cs_opposite(cs)->state, CS_SB_RDY|CS_SB_EST|CS_SB_DIS|CS_SB_CLO))
cs_rx_conn_rdy(cs);

if (cs_rx_blocked(cs) || !cs_rx_endp_ready(cs))
Expand All @@ -301,7 +301,7 @@ static inline void cs_chk_rcv(struct conn_stream *cs)
if (!cs_state_in(cs->state, CS_SB_RDY|CS_SB_EST))
return;

cs->endp->flags |= CS_EP_RX_WAIT_EP;
sc_ep_set(cs, CS_EP_RX_WAIT_EP);
cs->ops->chk_rcv(cs);
}

Expand Down
20 changes: 10 additions & 10 deletions src/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ static int connect_server(struct stream *s)
srv_conn = NULL;
if (cs_reset_endp(s->csb) < 0)
return SF_ERR_INTERNAL;
s->csb->endp->flags &= CS_EP_DETACHED;
sc_ep_clr(s->csb, ~CS_EP_DETACHED);
}
}
else
Expand Down Expand Up @@ -1826,15 +1826,15 @@ static int connect_server(struct stream *s)
* loopback on a heavily loaded system.
*/
if (srv_conn->flags & CO_FL_ERROR)
s->csb->endp->flags |= CS_EP_ERROR;
sc_ep_set(s->csb, CS_EP_ERROR);

/* If we had early data, and the handshake ended, then
* we can remove the flag, and attempt to wake the task up,
* in the event there's an analyser waiting for the end of
* the handshake.
*/
if (!(srv_conn->flags & (CO_FL_WAIT_XPRT | CO_FL_EARLY_SSL_HS)))
s->csb->endp->flags &= ~CS_EP_WAIT_FOR_HS;
sc_ep_clr(s->csb, CS_EP_WAIT_FOR_HS);

if (!cs_state_in(s->csb->state, CS_SB_EST|CS_SB_DIS|CS_SB_CLO) &&
(srv_conn->flags & CO_FL_WAIT_XPRT) == 0) {
Expand All @@ -1851,7 +1851,7 @@ static int connect_server(struct stream *s)
* wake callback. Otherwise si_cs_recv()/si_cs_send() already take
* care of it.
*/
if ((s->csb->endp->flags & CS_EP_EOI) && !(cs_ic(s->csb)->flags & CF_EOI))
if (sc_ep_test(s->csb, CS_EP_EOI) && !(cs_ic(s->csb)->flags & CF_EOI))
cs_ic(s->csb)->flags |= (CF_EOI|CF_READ_PARTIAL);

/* catch all sync connect while the mux is not already installed */
Expand Down Expand Up @@ -2045,7 +2045,7 @@ void back_try_conn_req(struct stream *s)
* allocation problem, so we want to retry now.
*/
cs->state = CS_ST_CER;
cs->endp->flags &= ~CS_EP_ERROR;
sc_ep_clr(cs, CS_EP_ERROR);
back_handle_st_cer(s);

DBG_TRACE_STATE("connection error, retry", STRM_EV_STRM_PROC|STRM_EV_CS_ST|STRM_EV_STRM_ERR, s);
Expand Down Expand Up @@ -2262,9 +2262,9 @@ void back_handle_st_con(struct stream *s)

done:
/* retryable error ? */
if ((s->flags & SF_CONN_EXP) || (cs->endp->flags & CS_EP_ERROR)) {
if ((s->flags & SF_CONN_EXP) || sc_ep_test(cs, CS_EP_ERROR)) {
if (!s->conn_err_type) {
if (cs->endp->flags & CS_EP_ERROR)
if (sc_ep_test(cs, CS_EP_ERROR))
s->conn_err_type = STRM_ET_CONN_ERR;
else
s->conn_err_type = STRM_ET_CONN_TO;
Expand All @@ -2290,7 +2290,7 @@ void back_handle_st_con(struct stream *s)
void back_handle_st_cer(struct stream *s)
{
struct conn_stream *cs = s->csb;
int must_tar = (cs->endp->flags & CS_EP_ERROR);
int must_tar = sc_ep_test(cs, CS_EP_ERROR);

DBG_TRACE_ENTER(STRM_EV_STRM_PROC|STRM_EV_CS_ST, s);

Expand All @@ -2310,7 +2310,7 @@ void back_handle_st_cer(struct stream *s)
_HA_ATOMIC_DEC(&__objt_server(s->target)->cur_sess);
}

if ((cs->endp->flags & CS_EP_ERROR) &&
if (sc_ep_test(cs, CS_EP_ERROR) &&
conn && conn->err_code == CO_ER_SSL_MISMATCH_SNI) {
/* We tried to connect to a server which is configured
* with "verify required" and which doesn't have the
Expand Down Expand Up @@ -2489,7 +2489,7 @@ void back_handle_st_rdy(struct stream *s)
}

/* retryable error ? */
if (cs->endp->flags & CS_EP_ERROR) {
if (sc_ep_test(cs, CS_EP_ERROR)) {
if (!s->conn_err_type)
s->conn_err_type = STRM_ET_CONN_ERR;
cs->state = CS_ST_CER;
Expand Down
14 changes: 7 additions & 7 deletions src/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ void chk_report_conn_err(struct check *check, int errno_bck, int expired)
retrieve_errno_from_socket(conn);

if (conn && !(conn->flags & CO_FL_ERROR) &&
cs && !(cs->endp->flags & CS_EP_ERROR) && !expired)
cs && !sc_ep_test(cs, CS_EP_ERROR) && !expired)
return;

TRACE_ENTER(CHK_EV_HCHK_END|CHK_EV_HCHK_ERR, check, 0, 0, (size_t[]){expired});
Expand Down Expand Up @@ -912,7 +912,7 @@ void chk_report_conn_err(struct check *check, int errno_bck, int expired)
}
else if (conn->flags & CO_FL_WAIT_L4_CONN) {
/* L4 not established (yet) */
if (conn->flags & CO_FL_ERROR || cs->endp->flags & CS_EP_ERROR)
if (conn->flags & CO_FL_ERROR || sc_ep_test(cs, CS_EP_ERROR))
set_server_check_status(check, HCHK_STATUS_L4CON, err_msg);
else if (expired)
set_server_check_status(check, HCHK_STATUS_L4TOUT, err_msg);
Expand All @@ -927,12 +927,12 @@ void chk_report_conn_err(struct check *check, int errno_bck, int expired)
}
else if (conn->flags & CO_FL_WAIT_L6_CONN) {
/* L6 not established (yet) */
if (conn->flags & CO_FL_ERROR || cs->endp->flags & CS_EP_ERROR)
if (conn->flags & CO_FL_ERROR || sc_ep_test(cs, CS_EP_ERROR))
set_server_check_status(check, HCHK_STATUS_L6RSP, err_msg);
else if (expired)
set_server_check_status(check, HCHK_STATUS_L6TOUT, err_msg);
}
else if (conn->flags & CO_FL_ERROR || cs->endp->flags & CS_EP_ERROR) {
else if (conn->flags & CO_FL_ERROR || sc_ep_test(cs, CS_EP_ERROR)) {
/* I/O error after connection was established and before we could diagnose */
set_server_check_status(check, HCHK_STATUS_SOCKERR, err_msg);
}
Expand Down Expand Up @@ -1038,7 +1038,7 @@ static int wake_srv_chk(struct conn_stream *cs)
cs = check->cs;
conn = cs_conn(cs);

if (unlikely(!conn || !cs || conn->flags & CO_FL_ERROR || cs->endp->flags & CS_EP_ERROR)) {
if (unlikely(!conn || !cs || conn->flags & CO_FL_ERROR || sc_ep_test(cs, CS_EP_ERROR))) {
/* We may get error reports bypassing the I/O handlers, typically
* the case when sending a pure TCP check which fails, then the I/O
* handlers above are not called. This is completely handled by the
Expand Down Expand Up @@ -1146,7 +1146,7 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
/* Here the connection must be defined. Otherwise the
* error would have already been detected
*/
if ((conn && ((conn->flags & CO_FL_ERROR) || (cs->endp->flags & CS_EP_ERROR))) || expired) {
if ((conn && ((conn->flags & CO_FL_ERROR) || sc_ep_test(cs, CS_EP_ERROR))) || expired) {
TRACE_ERROR("report connection error", CHK_EV_TASK_WAKE|CHK_EV_HCHK_END|CHK_EV_HCHK_ERR, check);
chk_report_conn_err(check, 0, expired);
}
Expand All @@ -1159,7 +1159,7 @@ struct task *process_chk_conn(struct task *t, void *context, unsigned int state)
/* error will be handled by tcpcheck_main().
* On success, remove all flags except CS_EP_DETACHED
*/
check->cs->endp->flags &= CS_EP_DETACHED;
sc_ep_clr(check->cs, ~CS_EP_DETACHED);
}
tcpcheck_main(check);
}
Expand Down
Loading

0 comments on commit 0cfcc40

Please sign in to comment.