CLEANUP: stconn: rename all occurrences of stconn "cs" to "sc"

Function arguments and local variables called "cs" were renamed to "sc"
to avoid future confusion. The change is huge (~580 lines), so extreme
care was given not to change anything else.
This commit is contained in:
Willy Tarreau 2022-05-27 10:02:48 +02:00
parent 61f5675cb4
commit 0adb281fb0
3 changed files with 578 additions and 578 deletions

View File

@ -33,74 +33,74 @@
#include <haproxy/stconn.h>
#include <haproxy/stream.h>
void sc_update_rx(struct stconn *cs);
void sc_update_tx(struct stconn *cs);
void sc_update_rx(struct stconn *sc);
void sc_update_tx(struct stconn *sc);
struct task *sc_conn_io_cb(struct task *t, void *ctx, unsigned int state);
int sc_conn_sync_recv(struct stconn *cs);
void sc_conn_sync_send(struct stconn *cs);
int sc_conn_sync_recv(struct stconn *sc);
void sc_conn_sync_send(struct stconn *sc);
/* returns the channel which receives data from this stream connector (input channel) */
static inline struct channel *sc_ic(const struct stconn *cs)
static inline struct channel *sc_ic(const struct stconn *sc)
{
struct stream *strm = __sc_strm(cs);
struct stream *strm = __sc_strm(sc);
return ((cs->flags & SC_FL_ISBACK) ? &(strm->res) : &(strm->req));
return ((sc->flags & SC_FL_ISBACK) ? &(strm->res) : &(strm->req));
}
/* returns the channel which feeds data to this stream connector (output channel) */
static inline struct channel *sc_oc(const struct stconn *cs)
static inline struct channel *sc_oc(const struct stconn *sc)
{
struct stream *strm = __sc_strm(cs);
struct stream *strm = __sc_strm(sc);
return ((cs->flags & SC_FL_ISBACK) ? &(strm->req) : &(strm->res));
return ((sc->flags & SC_FL_ISBACK) ? &(strm->req) : &(strm->res));
}
/* returns the buffer which receives data from this stream connector (input channel's buffer) */
static inline struct buffer *sc_ib(const struct stconn *cs)
static inline struct buffer *sc_ib(const struct stconn *sc)
{
return &sc_ic(cs)->buf;
return &sc_ic(sc)->buf;
}
/* returns the buffer which feeds data to this stream connector (output channel's buffer) */
static inline struct buffer *sc_ob(const struct stconn *cs)
static inline struct buffer *sc_ob(const struct stconn *sc)
{
return &sc_oc(cs)->buf;
return &sc_oc(sc)->buf;
}
/* returns the stream's task associated to this stream connector */
static inline struct task *sc_strm_task(const struct stconn *cs)
static inline struct task *sc_strm_task(const struct stconn *sc)
{
struct stream *strm = __sc_strm(cs);
struct stream *strm = __sc_strm(sc);
return strm->task;
}
/* returns the stream connector on the other side. Used during forwarding. */
static inline struct stconn *sc_opposite(const struct stconn *cs)
static inline struct stconn *sc_opposite(const struct stconn *sc)
{
struct stream *strm = __sc_strm(cs);
struct stream *strm = __sc_strm(sc);
return ((cs->flags & SC_FL_ISBACK) ? strm->scf : strm->scb);
return ((sc->flags & SC_FL_ISBACK) ? strm->scf : strm->scb);
}
/* to be called only when in SC_ST_DIS with SC_FL_ERR */
static inline void sc_report_error(struct stconn *cs)
static inline void sc_report_error(struct stconn *sc)
{
if (!__sc_strm(cs)->conn_err_type)
__sc_strm(cs)->conn_err_type = STRM_ET_DATA_ERR;
if (!__sc_strm(sc)->conn_err_type)
__sc_strm(sc)->conn_err_type = STRM_ET_DATA_ERR;
sc_oc(cs)->flags |= CF_WRITE_ERROR;
sc_ic(cs)->flags |= CF_READ_ERROR;
sc_oc(sc)->flags |= CF_WRITE_ERROR;
sc_ic(sc)->flags |= CF_READ_ERROR;
}
/* sets the current and previous state of a stream connector to <state>. This is
* mainly used to create one in the established state on incoming conncetions.
*/
static inline void sc_set_state(struct stconn *cs, int state)
static inline void sc_set_state(struct stconn *sc, int state)
{
cs->state = __sc_strm(cs)->prev_conn_state = state;
sc->state = __sc_strm(sc)->prev_conn_state = state;
}
/* returns a bit for a stream connector state, to match against SC_SB_* */
@ -117,12 +117,12 @@ static inline int sc_state_in(enum sc_state state, enum sc_state_bit mask)
return !!(sc_state_bit(state) & mask);
}
/* Returns true if a connection is attached to the stream connector <cs> and if this
/* Returns true if a connection is attached to the stream connector <sc> and if this
* connection is ready.
*/
static inline int sc_conn_ready(const struct stconn *cs)
static inline int sc_conn_ready(const struct stconn *sc)
{
const struct connection *conn = sc_conn(cs);
const struct connection *conn = sc_conn(sc);
return conn && conn_ctrl_ready(conn) && conn_xprt_ready(conn);
}
@ -134,14 +134,14 @@ static inline int sc_conn_ready(const struct stconn *cs)
* may hold pending data. This function returns true if such an error was
* reported. Both the CS and the CONN must be valid.
*/
static inline int sc_is_conn_error(const struct stconn *cs)
static inline int sc_is_conn_error(const struct stconn *sc)
{
const struct connection *conn;
if (cs->state >= SC_ST_EST)
if (sc->state >= SC_ST_EST)
return 0;
conn = __sc_conn(cs);
conn = __sc_conn(sc);
BUG_ON(!conn);
return !!(conn->flags & CO_FL_ERROR);
}
@ -154,13 +154,13 @@ static inline int sc_is_conn_error(const struct stconn *cs)
* stream connector and SE_FL_HAVE_NO_DATA cleared. The requester will be responsible
* for calling this function to try again once woken up.
*/
static inline int sc_alloc_ibuf(struct stconn *cs, struct buffer_wait *wait)
static inline int sc_alloc_ibuf(struct stconn *sc, struct buffer_wait *wait)
{
int ret;
ret = channel_alloc_buffer(sc_ic(cs), wait);
ret = channel_alloc_buffer(sc_ic(sc), wait);
if (!ret)
sc_need_buff(cs);
sc_need_buff(sc);
return ret;
}
@ -169,14 +169,14 @@ static inline int sc_alloc_ibuf(struct stconn *cs, struct buffer_wait *wait)
* the session for frontend CS and the server connection for the backend CS. It
* returns a const address on success or NULL on failure.
*/
static inline const struct sockaddr_storage *sc_src(const struct stconn *cs)
static inline const struct sockaddr_storage *sc_src(const struct stconn *sc)
{
if (cs->src)
return cs->src;
if (!(cs->flags & SC_FL_ISBACK))
return sess_src(strm_sess(__sc_strm(cs)));
if (sc->src)
return sc->src;
if (!(sc->flags & SC_FL_ISBACK))
return sess_src(strm_sess(__sc_strm(sc)));
else {
struct connection *conn = sc_conn(cs);
struct connection *conn = sc_conn(sc);
if (conn)
return conn_src(conn);
@ -189,14 +189,14 @@ static inline const struct sockaddr_storage *sc_src(const struct stconn *cs)
* on the session for frontend CS and the server connection for the backend
* CS. It returns a const address on success or NULL on failure.
*/
static inline const struct sockaddr_storage *sc_dst(const struct stconn *cs)
static inline const struct sockaddr_storage *sc_dst(const struct stconn *sc)
{
if (cs->dst)
return cs->dst;
if (!(cs->flags & SC_FL_ISBACK))
return sess_dst(strm_sess(__sc_strm(cs)));
if (sc->dst)
return sc->dst;
if (!(sc->flags & SC_FL_ISBACK))
return sess_dst(strm_sess(__sc_strm(sc)));
else {
struct connection *conn = sc_conn(cs);
struct connection *conn = sc_conn(sc);
if (conn)
return conn_dst(conn);
@ -210,17 +210,17 @@ static inline const struct sockaddr_storage *sc_dst(const struct stconn *cs)
* source address is copied from the session one for frontend CS and the server
* connection for the backend CS.
*/
static inline int sc_get_src(struct stconn *cs)
static inline int sc_get_src(struct stconn *sc)
{
const struct sockaddr_storage *src = NULL;
if (cs->src)
if (sc->src)
return 1;
if (!(cs->flags & SC_FL_ISBACK))
src = sess_src(strm_sess(__sc_strm(cs)));
if (!(sc->flags & SC_FL_ISBACK))
src = sess_src(strm_sess(__sc_strm(sc)));
else {
struct connection *conn = sc_conn(cs);
struct connection *conn = sc_conn(sc);
if (conn)
src = conn_src(conn);
@ -228,7 +228,7 @@ static inline int sc_get_src(struct stconn *cs)
if (!src)
return 0;
if (!sockaddr_alloc(&cs->src, src, sizeof(*src)))
if (!sockaddr_alloc(&sc->src, src, sizeof(*src)))
return 0;
return 1;
@ -240,17 +240,17 @@ static inline int sc_get_src(struct stconn *cs)
* stream connector destination address is copied from the session one for frontend
* CS and the server connection for the backend CS.
*/
static inline int sc_get_dst(struct stconn *cs)
static inline int sc_get_dst(struct stconn *sc)
{
const struct sockaddr_storage *dst = NULL;
if (cs->dst)
if (sc->dst)
return 1;
if (!(cs->flags & SC_FL_ISBACK))
dst = sess_dst(strm_sess(__sc_strm(cs)));
if (!(sc->flags & SC_FL_ISBACK))
dst = sess_dst(strm_sess(__sc_strm(sc)));
else {
struct connection *conn = sc_conn(cs);
struct connection *conn = sc_conn(sc);
if (conn)
dst = conn_dst(conn);
@ -258,7 +258,7 @@ static inline int sc_get_dst(struct stconn *cs)
if (!dst)
return 0;
if (!sockaddr_alloc(&cs->dst, dst, sizeof(*dst)))
if (!sockaddr_alloc(&sc->dst, dst, sizeof(*dst)))
return 0;
return 1;
@ -266,24 +266,24 @@ static inline int sc_get_dst(struct stconn *cs)
/* Marks on the stream connector that next shutw must kill the whole connection */
static inline void sc_must_kill_conn(struct stconn *cs)
static inline void sc_must_kill_conn(struct stconn *sc)
{
sc_ep_set(cs, SE_FL_KILL_CONN);
sc_ep_set(sc, SE_FL_KILL_CONN);
}
/* Sends a shutr to the endpoint using the data layer */
static inline void sc_shutr(struct stconn *cs)
static inline void sc_shutr(struct stconn *sc)
{
if (likely(cs->app_ops->shutr))
cs->app_ops->shutr(cs);
if (likely(sc->app_ops->shutr))
sc->app_ops->shutr(sc);
}
/* Sends a shutw to the endpoint using the data layer */
static inline void sc_shutw(struct stconn *cs)
static inline void sc_shutw(struct stconn *sc)
{
if (likely(cs->app_ops->shutw))
cs->app_ops->shutw(cs);
if (likely(sc->app_ops->shutw))
sc->app_ops->shutw(sc);
}
/* Returns non-zero if the stream connector is allowed to receive from the
@ -316,35 +316,35 @@ static inline int sc_is_recv_allowed(const struct stconn *sc)
* point in order to avoid useless repeated wakeups.
* It will then call ->chk_rcv() to enable receipt of new data.
*/
static inline void sc_chk_rcv(struct stconn *cs)
static inline void sc_chk_rcv(struct stconn *sc)
{
if (sc_ep_test(cs, SE_FL_APPLET_NEED_CONN) &&
sc_state_in(sc_opposite(cs)->state, SC_SB_RDY|SC_SB_EST|SC_SB_DIS|SC_SB_CLO))
sc_ep_clr(cs, SE_FL_APPLET_NEED_CONN);
if (sc_ep_test(sc, SE_FL_APPLET_NEED_CONN) &&
sc_state_in(sc_opposite(sc)->state, SC_SB_RDY|SC_SB_EST|SC_SB_DIS|SC_SB_CLO))
sc_ep_clr(sc, SE_FL_APPLET_NEED_CONN);
if (!sc_is_recv_allowed(cs))
if (!sc_is_recv_allowed(sc))
return;
if (!sc_state_in(cs->state, SC_SB_RDY|SC_SB_EST))
if (!sc_state_in(sc->state, SC_SB_RDY|SC_SB_EST))
return;
sc_ep_set(cs, SE_FL_HAVE_NO_DATA);
if (likely(cs->app_ops->chk_rcv))
cs->app_ops->chk_rcv(cs);
sc_ep_set(sc, SE_FL_HAVE_NO_DATA);
if (likely(sc->app_ops->chk_rcv))
sc->app_ops->chk_rcv(sc);
}
/* Calls chk_snd on the endpoint using the data layer */
static inline void sc_chk_snd(struct stconn *cs)
static inline void sc_chk_snd(struct stconn *sc)
{
if (likely(cs->app_ops->chk_snd))
cs->app_ops->chk_snd(cs);
if (likely(sc->app_ops->chk_snd))
sc->app_ops->chk_snd(sc);
}
/* Combines both sc_update_rx() and sc_update_tx() at once */
static inline void sc_update(struct stconn *cs)
static inline void sc_update(struct stconn *sc)
{
sc_update_rx(cs);
sc_update_tx(cs);
sc_update_rx(sc);
sc_update_tx(sc);
}
/* for debugging, reports the stream connector state name */

View File

@ -33,7 +33,7 @@ struct appctx;
struct stream;
struct check;
#define IS_HTX_SC(cs) (sc_conn(cs) && IS_HTX_CONN(__sc_conn(cs)))
#define IS_HTX_SC(sc) (sc_conn(sc) && IS_HTX_CONN(__sc_conn(sc)))
struct sedesc *sedesc_new();
void sedesc_free(struct sedesc *sedesc);
@ -41,15 +41,15 @@ void sedesc_free(struct sedesc *sedesc);
struct stconn *sc_new_from_endp(struct sedesc *sedesc, struct session *sess, struct buffer *input);
struct stconn *sc_new_from_strm(struct stream *strm, unsigned int flags);
struct stconn *sc_new_from_check(struct check *check, unsigned int flags);
void sc_free(struct stconn *cs);
void sc_free(struct stconn *sc);
int sc_attach_mux(struct stconn *cs, void *target, void *ctx);
int sc_attach_strm(struct stconn *cs, struct stream *strm);
int sc_attach_mux(struct stconn *sc, void *target, void *ctx);
int sc_attach_strm(struct stconn *sc, struct stream *strm);
void sc_destroy(struct stconn *cs);
int sc_reset_endp(struct stconn *cs);
void sc_destroy(struct stconn *sc);
int sc_reset_endp(struct stconn *sc);
struct appctx *sc_applet_create(struct stconn *cs, struct applet *app);
struct appctx *sc_applet_create(struct stconn *sc, struct applet *app);
/* The se_fl_*() set of functions manipulate the stream endpoint flags from
* the stream endpoint itself. The sc_ep_*() set of functions manipulate the
@ -134,32 +134,32 @@ static forceinline uint sc_ep_get(const struct stconn *sc)
/* Returns the stream endpoint from an connector, without any control */
static inline void *__sc_endp(const struct stconn *cs)
static inline void *__sc_endp(const struct stconn *sc)
{
return cs->sedesc->se;
return sc->sedesc->se;
}
/* Returns the connection from a cs if the endpoint is a mux stream. Otherwise
/* Returns the connection from a sc if the endpoint is a mux stream. Otherwise
* NULL is returned. __sc_conn() returns the connection without any control
* while sc_conn() check the endpoint type.
*/
static inline struct connection *__sc_conn(const struct stconn *cs)
static inline struct connection *__sc_conn(const struct stconn *sc)
{
return cs->sedesc->conn;
return sc->sedesc->conn;
}
static inline struct connection *sc_conn(const struct stconn *cs)
static inline struct connection *sc_conn(const struct stconn *sc)
{
if (sc_ep_test(cs, SE_FL_T_MUX))
return __sc_conn(cs);
if (sc_ep_test(sc, SE_FL_T_MUX))
return __sc_conn(sc);
return NULL;
}
/* Returns the mux ops of the connection from an stconn if the endpoint is a
* mux stream. Otherwise NULL is returned.
*/
static inline const struct mux_ops *sc_mux_ops(const struct stconn *cs)
static inline const struct mux_ops *sc_mux_ops(const struct stconn *sc)
{
const struct connection *conn = sc_conn(cs);
const struct connection *conn = sc_conn(sc);
return (conn ? conn->mux : NULL);
}
@ -168,119 +168,119 @@ static inline const struct mux_ops *sc_mux_ops(const struct stconn *cs)
* a mux. Otherwise NULL is returned. __sc_mux_strm() returns the mux without
* any control while sc_mux_strm() checks the endpoint type.
*/
static inline void *__sc_mux_strm(const struct stconn *cs)
static inline void *__sc_mux_strm(const struct stconn *sc)
{
return __sc_endp(cs);
return __sc_endp(sc);
}
static inline struct appctx *sc_mux_strm(const struct stconn *cs)
static inline struct appctx *sc_mux_strm(const struct stconn *sc)
{
if (sc_ep_test(cs, SE_FL_T_MUX))
return __sc_mux_strm(cs);
if (sc_ep_test(sc, SE_FL_T_MUX))
return __sc_mux_strm(sc);
return NULL;
}
/* Returns the appctx from a cs if the endpoint is an appctx. Otherwise
/* Returns the appctx from a sc if the endpoint is an appctx. Otherwise
* NULL is returned. __sc_appctx() returns the appctx without any control
* while sc_appctx() checks the endpoint type.
*/
static inline struct appctx *__sc_appctx(const struct stconn *cs)
static inline struct appctx *__sc_appctx(const struct stconn *sc)
{
return __sc_endp(cs);
return __sc_endp(sc);
}
static inline struct appctx *sc_appctx(const struct stconn *cs)
static inline struct appctx *sc_appctx(const struct stconn *sc)
{
if (sc_ep_test(cs, SE_FL_T_APPLET))
return __sc_appctx(cs);
if (sc_ep_test(sc, SE_FL_T_APPLET))
return __sc_appctx(sc);
return NULL;
}
/* Returns the stream from a cs if the application is a stream. Otherwise
/* Returns the stream from a sc if the application is a stream. Otherwise
* NULL is returned. __sc_strm() returns the stream without any control
* while sc_strm() check the application type.
*/
static inline struct stream *__sc_strm(const struct stconn *cs)
static inline struct stream *__sc_strm(const struct stconn *sc)
{
return __objt_stream(cs->app);
return __objt_stream(sc->app);
}
static inline struct stream *sc_strm(const struct stconn *cs)
static inline struct stream *sc_strm(const struct stconn *sc)
{
if (obj_type(cs->app) == OBJ_TYPE_STREAM)
return __sc_strm(cs);
if (obj_type(sc->app) == OBJ_TYPE_STREAM)
return __sc_strm(sc);
return NULL;
}
/* Returns the healthcheck from a cs if the application is a
/* Returns the healthcheck from a sc if the application is a
* healthcheck. Otherwise NULL is returned. __sc_check() returns the healthcheck
* without any control while sc_check() check the application type.
*/
static inline struct check *__sc_check(const struct stconn *cs)
static inline struct check *__sc_check(const struct stconn *sc)
{
return __objt_check(cs->app);
return __objt_check(sc->app);
}
static inline struct check *sc_check(const struct stconn *cs)
static inline struct check *sc_check(const struct stconn *sc)
{
if (obj_type(cs->app) == OBJ_TYPE_CHECK)
return __objt_check(cs->app);
if (obj_type(sc->app) == OBJ_TYPE_CHECK)
return __objt_check(sc->app);
return NULL;
}
/* Returns the name of the application layer's name for the stconn,
* or "NONE" when none is attached.
*/
static inline const char *sc_get_data_name(const struct stconn *cs)
static inline const char *sc_get_data_name(const struct stconn *sc)
{
if (!cs->app_ops)
if (!sc->app_ops)
return "NONE";
return cs->app_ops->name;
return sc->app_ops->name;
}
/* shut read */
static inline void sc_conn_shutr(struct stconn *cs, enum co_shr_mode mode)
static inline void sc_conn_shutr(struct stconn *sc, enum co_shr_mode mode)
{
const struct mux_ops *mux;
BUG_ON(!sc_conn(cs));
BUG_ON(!sc_conn(sc));
if (sc_ep_test(cs, SE_FL_SHR))
if (sc_ep_test(sc, SE_FL_SHR))
return;
/* clean data-layer shutdown */
mux = sc_mux_ops(cs);
mux = sc_mux_ops(sc);
if (mux && mux->shutr)
mux->shutr(cs, mode);
sc_ep_set(cs, (mode == CO_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR);
mux->shutr(sc, mode);
sc_ep_set(sc, (mode == CO_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR);
}
/* shut write */
static inline void sc_conn_shutw(struct stconn *cs, enum co_shw_mode mode)
static inline void sc_conn_shutw(struct stconn *sc, enum co_shw_mode mode)
{
const struct mux_ops *mux;
BUG_ON(!sc_conn(cs));
BUG_ON(!sc_conn(sc));
if (sc_ep_test(cs, SE_FL_SHW))
if (sc_ep_test(sc, SE_FL_SHW))
return;
/* clean data-layer shutdown */
mux = sc_mux_ops(cs);
mux = sc_mux_ops(sc);
if (mux && mux->shutw)
mux->shutw(cs, mode);
sc_ep_set(cs, (mode == CO_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS);
mux->shutw(sc, mode);
sc_ep_set(sc, (mode == CO_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS);
}
/* completely close a stream connector (but do not detach it) */
static inline void sc_conn_shut(struct stconn *cs)
static inline void sc_conn_shut(struct stconn *sc)
{
sc_conn_shutw(cs, CO_SHW_SILENT);
sc_conn_shutr(cs, CO_SHR_RESET);
sc_conn_shutw(sc, CO_SHW_SILENT);
sc_conn_shutr(sc, CO_SHR_RESET);
}
/* completely close a stream connector after draining possibly pending data (but do not detach it) */
static inline void sc_conn_drain_and_shut(struct stconn *cs)
static inline void sc_conn_drain_and_shut(struct stconn *sc)
{
sc_conn_shutw(cs, CO_SHW_SILENT);
sc_conn_shutr(cs, CO_SHR_DRAIN);
sc_conn_shutw(sc, CO_SHW_SILENT);
sc_conn_shutr(sc, CO_SHR_DRAIN);
}
/* Returns non-zero if the stream connector's Rx path is blocked because of

File diff suppressed because it is too large Load Diff