]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stconn: rename cs_rx_room_{blk,rdy} to sc_{need,have}_room()
authorWilly Tarreau <w@1wt.eu>
Wed, 25 May 2022 05:29:36 +0000 (07:29 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 27 May 2022 17:33:35 +0000 (19:33 +0200)
The new name mor eclearly indicates that a stream connector cannot make
any more progress because it needs room in the channel buffer, or that
it may be unblocked because the buffer now has more room available. The
testing function is sc_waiting_room(). This is mostly used by applets.
Note that the flags will change soon.

16 files changed:
addons/promex/service-prometheus.c
include/haproxy/conn_stream.h
src/applet.c
src/cache.c
src/cli.c
src/conn_stream.c
src/dns.c
src/flt_spoe.c
src/hlua.c
src/http_ana.c
src/http_client.c
src/peers.c
src/proxy.c
src/resolvers.c
src/stats.c
src/tcp_rules.c

index 23a27d3a233449c0e3ebdbc5cfc3e0da3ab39fc5..8469942ccdde88ab47fbfdeb0185328fcfc7a3fd 100644 (file)
@@ -1337,7 +1337,7 @@ static int promex_dump_metrics(struct appctx *appctx, struct stconn *cs, struct
        return 1;
 
   full:
-       cs_rx_room_blk(cs);
+       sc_need_room(cs);
        return 0;
   error:
        /* unrecoverable error */
@@ -1485,7 +1485,7 @@ static int promex_send_headers(struct appctx *appctx, struct stconn *cs, struct
        return 1;
   full:
        htx_reset(htx);
-       cs_rx_room_blk(cs);
+       sc_need_room(cs);
        return 0;
 }
 
@@ -1516,7 +1516,7 @@ static void promex_appctx_handle_io(struct appctx *appctx)
 
        /* Check if the input buffer is available. */
        if (!b_size(&res->buf)) {
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
                goto out;
        }
 
@@ -1557,7 +1557,7 @@ static void promex_appctx_handle_io(struct appctx *appctx)
                         */
                        if (htx_is_empty(res_htx)) {
                                if (!htx_add_endof(res_htx, HTX_BLK_EOT)) {
-                                       cs_rx_room_blk(cs);
+                                       sc_need_room(cs);
                                        goto out;
                                }
                                channel_add_input(res, 1);
index 490eecf1a8384daedcd7bd1d39fb0f9780bcf4d5..33b908b89249e0a4bcbd3822cf41b5cba82f8ccf 100644 (file)
@@ -289,11 +289,12 @@ static inline int cs_rx_blocked(const struct stconn *cs)
        return !!sc_ep_test(cs, SE_FL_RXBLK_ANY);
 }
 
-
-/* Returns non-zero if the stream connector's Rx path is blocked because of lack
- * of room in the input buffer.
+/* Returns non-zero if the stream connector's Rx path is blocked because of
+ * lack of room in the input buffer. This usually happens after applets failed
+ * to deliver data into the channel's buffer and reported it via sc_need_room().
  */
-static inline int cs_rx_blocked_room(const struct stconn *cs)
+__attribute__((warn_unused_result))
+static inline int sc_waiting_room(const struct stconn *cs)
 {
        return !!sc_ep_test(cs, SE_FL_RXBLK_ROOM);
 }
@@ -354,18 +355,21 @@ static inline void cs_rx_buff_blk(struct stconn *cs)
        sc_ep_set(cs, SE_FL_RXBLK_BUFF);
 }
 
-/* Tell a stream connector some room was made in the input buffer */
-static inline void cs_rx_room_rdy(struct stconn *cs)
+/* Tell a stream connector some room was made in the input buffer and any
+ * failed attempt to inject data into it may be tried again. This is usually
+ * called after a successful transfer of buffer contents to the other side.
+ */
+static inline void sc_have_room(struct stconn *cs)
 {
        sc_ep_clr(cs, SE_FL_RXBLK_ROOM);
 }
 
 /* The stream connector announces it failed to put data into the input buffer
  * by lack of room. Since it indicates a willingness to deliver data to the
- * buffer that will have to be retried, we automatically clear RXBLK_ENDP to
- * be called again as soon as RXBLK_ROOM is cleared.
+ * buffer that will have to be retried. Usually the caller will also clear
+ * RXBLK_ENDP to be called again as soon as RXBLK_ROOM is cleared.
  */
-static inline void cs_rx_room_blk(struct stconn *cs)
+static inline void sc_need_room(struct stconn *cs)
 {
        sc_ep_set(cs, SE_FL_RXBLK_ROOM);
 }
index 1af0dbddf00cfc363bce4acaa3590156f2096aa6..718b2990255e41b3fefe2ef9881b337acaaaae49 100644 (file)
@@ -238,7 +238,7 @@ struct task *task_run_applet(struct task *t, void *context, unsigned int state)
         */
        if (count != co_data(sc_oc(cs))) {
                sc_oc(cs)->flags |= CF_WRITE_PARTIAL | CF_WROTE_DATA;
-               cs_rx_room_rdy(cs_opposite(cs));
+               sc_have_room(cs_opposite(cs));
        }
 
        /* measure the call rate and check for anomalies when too high */
index 22902a355fce06b325600d136f86c715c372bd87..db751699d990fd0135c0952e41257f78785109d2 100644 (file)
@@ -1471,7 +1471,7 @@ static void http_cache_io_handler(struct appctx *appctx)
 
        /* Check if the input buffer is available. */
        if (!b_size(&res->buf)) {
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
                goto out;
        }
 
@@ -1516,7 +1516,7 @@ static void http_cache_io_handler(struct appctx *appctx)
                if (len) {
                        ret = htx_cache_dump_msg(appctx, res_htx, len, HTX_BLK_UNUSED);
                        if (ret < len) {
-                               cs_rx_room_blk(cs);
+                               sc_need_room(cs);
                                goto out;
                        }
                }
index e684620cca441a90d6a7edfcac21eb7e54f91faf..1a1b41850bb160b7f251f87771ccc6c97cd49f19 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -951,7 +951,7 @@ static void cli_io_handler(struct appctx *appctx)
                         * would want to return some info right after parsing.
                         */
                        if (buffer_almost_full(sc_ib(cs))) {
-                               cs_rx_room_blk(cs);
+                               sc_need_room(cs);
                                break;
                        }
 
@@ -1094,7 +1094,7 @@ static void cli_io_handler(struct appctx *appctx)
                                        appctx->st0 = CLI_ST_PROMPT;
                                }
                                else
-                                       cs_rx_room_blk(cs);
+                                       sc_need_room(cs);
                                break;
 
                        case CLI_ST_CALLBACK: /* use custom pointer */
index b60a9c59caef47b3b535dd791c86a58d1829cbb3..caf33e4386ca2cac70c01d8a000b866a1d7bb349 100644 (file)
@@ -596,7 +596,7 @@ static void sc_app_chk_rcv(struct stconn *cs)
 
        if (ic->pipe) {
                /* stop reading */
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
        }
        else {
                /* (re)start reading */
@@ -1021,7 +1021,7 @@ void cs_update_rx(struct stconn *cs)
 
        if (!channel_is_empty(ic) || !channel_may_recv(ic)) {
                /* stop reading, imposed by channel's policy or contents */
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
        }
        else {
                /* (re)start reading and update timeout. Note: we don't recompute the timeout
@@ -1029,7 +1029,7 @@ void cs_update_rx(struct stconn *cs)
                 * update it if is was not yet set. The stream socket handler will already
                 * have updated it if there has been a completed I/O.
                 */
-               cs_rx_room_rdy(cs);
+               sc_have_room(cs);
        }
        if (sc_ep_test(cs, SE_FL_RXBLK_ANY))
                ic->rex = TICK_ETERNITY;
@@ -1169,7 +1169,7 @@ static void cs_notify(struct stconn *cs)
                 * buffer or in the pipe.
                 */
                if (new_len < last_len)
-                       cs_rx_room_rdy(cs);
+                       sc_have_room(cs);
        }
 
        if (!(ic->flags & CF_DONT_READ))
@@ -1375,7 +1375,7 @@ static int sc_conn_recv(struct stconn *cs)
                        /* the pipe is full or we have read enough data that it
                         * could soon be full. Let's stop before needing to poll.
                         */
-                       cs_rx_room_blk(cs);
+                       sc_need_room(cs);
                        goto done_recv;
                }
 
@@ -1445,7 +1445,7 @@ static int sc_conn_recv(struct stconn *cs)
                         */
                        BUG_ON(c_empty(ic));
 
-                       cs_rx_room_blk(cs);
+                       sc_need_room(cs);
                        /* Add READ_PARTIAL because some data are pending but
                         * cannot be xferred to the channel
                         */
@@ -1459,7 +1459,7 @@ static int sc_conn_recv(struct stconn *cs)
                         * here to proceed.
                         */
                        if (flags & CO_RFL_BUF_FLUSH)
-                               cs_rx_room_blk(cs);
+                               sc_need_room(cs);
                        break;
                }
 
@@ -1753,7 +1753,7 @@ static int sc_conn_send(struct stconn *cs)
                if (cs->state == SC_ST_CON)
                        cs->state = SC_ST_RDY;
 
-               cs_rx_room_rdy(cs_opposite(cs));
+               sc_have_room(cs_opposite(cs));
        }
 
        if (sc_ep_test(cs, SE_FL_ERROR | SE_FL_ERR_PENDING)) {
index 6156dbad6aa40da14bb103eff3e0881ba9c68919..29e7f3e3fedc87fd6ae56dfc9a54e1090d46ce59 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -536,7 +536,7 @@ static void dns_session_io_handler(struct appctx *appctx)
 
                                /* check if there is enough room to put message len and query id */
                                if (available_room < sizeof(slen) + sizeof(new_qid)) {
-                                       cs_rx_room_blk(cs);
+                                       sc_need_room(cs);
                                        ret = 0;
                                        break;
                                }
@@ -594,7 +594,7 @@ static void dns_session_io_handler(struct appctx *appctx)
 
                        /* check if it remains available room on output chan */
                        if (unlikely(!available_room)) {
-                               cs_rx_room_blk(cs);
+                               sc_need_room(cs);
                                ret = 0;
                                break;
                        }
@@ -629,7 +629,7 @@ static void dns_session_io_handler(struct appctx *appctx)
                        if (ds->tx_msg_offset) {
                                /* msg was not fully processed, we must  be awake to drain pending data */
 
-                               cs_rx_room_blk(cs);
+                               sc_need_room(cs);
                                ret = 0;
                                break;
                        }
index 47537d770c7fbacbee809f903a83d138b375eab6..ac48c0669cefe72e79236bc4570a91f95b90b1a1 100644 (file)
@@ -1149,7 +1149,7 @@ spoe_send_frame(struct appctx *appctx, char *buf, size_t framesz)
        if (ret <= 0) {
                if ((ret == -3 && b_is_null(&sc_ic(cs)->buf)) || ret == -1) {
                        /* WT: is this still needed for the case ret==-3 ? */
-                       cs_rx_room_blk(cs);
+                       sc_need_room(cs);
                        return 1; /* retry */
                }
                SPOE_APPCTX(appctx)->status_code = SPOE_FRM_ERR_IO;
index 26017555c04caf44f4e18e555173c9dbac003003..e9316106b0e2ab32c27cc7184b847c9bb8b0dce0 100644 (file)
@@ -4662,7 +4662,7 @@ __LJMP static int hlua_applet_tcp_send_yield(lua_State *L, int status, lua_KCont
         * applet, and returns a yield.
         */
        if (l < len) {
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
                MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_tcp_send_yield, TICK_ETERNITY, 0));
        }
 
@@ -5205,7 +5205,7 @@ __LJMP static int hlua_applet_http_send_yield(lua_State *L, int status, lua_KCon
        if (l < len) {
          snd_yield:
                htx_to_buf(htx, &res->buf);
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
                MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_send_yield, TICK_ETERNITY, 0));
        }
 
@@ -5510,7 +5510,7 @@ __LJMP static int hlua_applet_http_start_response_yield(lua_State *L, int status
        struct channel *res = sc_ic(cs);
 
        if (co_data(res)) {
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
                MAY_LJMP(hlua_yieldk(L, 0, 0, hlua_applet_http_start_response_yield, TICK_ETERNITY, 0));
        }
        return MAY_LJMP(hlua_applet_http_send_response(L));
@@ -9527,7 +9527,7 @@ void hlua_applet_http_fct(struct appctx *ctx)
 
        /* Check if the input buffer is available. */
        if (!b_size(&res->buf)) {
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
                goto out;
        }
        /* check that the output is not closed */
@@ -9607,7 +9607,7 @@ void hlua_applet_http_fct(struct appctx *ctx)
                 */
                if (htx_is_empty(res_htx) && (strm->txn->rsp.flags & (HTTP_MSGF_XFER_LEN|HTTP_MSGF_CNT_LEN)) == HTTP_MSGF_XFER_LEN) {
                        if (!htx_add_endof(res_htx, HTX_BLK_EOT)) {
-                               cs_rx_room_blk(cs);
+                               sc_need_room(cs);
                                goto out;
                        }
                        channel_add_input(res, 1);
@@ -10165,7 +10165,7 @@ static int hlua_cli_io_handler_fct(struct appctx *appctx)
        case HLUA_E_AGAIN:
                /* We want write. */
                if (HLUA_IS_WAKERESWR(hlua))
-                       cs_rx_room_blk(cs);
+                       sc_need_room(cs);
                /* Set the timeout. */
                if (hlua->wake_time != TICK_ETERNITY)
                        task_schedule(hlua->task, hlua->wake_time);
index 6f09f2a2017a6ce6451bf4667c724755e034d6b2..9bcca5d919d943ae01b8f6f152d559594748a21a 100644 (file)
@@ -4193,7 +4193,7 @@ enum rule_result http_wait_for_msg_body(struct stream *s, struct channel *chn,
        if ((htx->flags & HTX_FL_EOM) ||
            htx_get_tail_type(htx) > HTX_BLK_DATA ||
            channel_htx_full(chn, htx, global.tune.maxrewrite) ||
-           cs_rx_blocked_room(chn_prod(chn)))
+           sc_waiting_room(chn_prod(chn)))
                goto end;
 
        if (bytes) {
index 910cd0f5f024fddca946b5fd2c6f1fd274012de3..d0b2a58a20bd9408a3b7d64b272ae102429fbf7f 100644 (file)
@@ -247,7 +247,7 @@ static int hc_cli_io_handler(struct appctx *appctx)
 out:
        /* we didn't clear every flags, we should come back to finish things */
        if (ctx->flags)
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
 
        free_trash_chunk(trash);
        return 0;
@@ -917,7 +917,7 @@ process_data:
 more:
        /* There was not enough data in the response channel */
 
-       cs_rx_room_blk(cs);
+       sc_need_room(cs);
 
        if (appctx->st0 == HTTPCLIENT_S_RES_END)
                goto end;
index cfa0b53f441919ab04bc15a63f8b253b9517897d..81af529d786de828b6f3cca0a168ab2a49af9392 100644 (file)
@@ -1215,7 +1215,7 @@ static inline int peer_send_msg(struct appctx *appctx,
        if (ret <= 0) {
                if (ret == -1) {
                        /* No more write possible */
-                       cs_rx_room_blk(cs);
+                       sc_need_room(cs);
                        return -1;
                }
                appctx->st0 = PEER_SESS_ST_END;
@@ -2861,7 +2861,7 @@ static void peer_io_handler(struct appctx *appctx)
 
        /* Check if the input buffer is available. */
        if (sc_ib(cs)->size == 0) {
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
                goto out;
        }
 
index 26a4ad80cc98b4b80027901ad27727f194967356..df460858d7fba54118256b9e0b35fe05cac3783d 100644 (file)
@@ -3296,7 +3296,7 @@ static int cli_io_handler_show_errors(struct appctx *appctx)
  cant_send_unlock:
        HA_RWLOCK_RDUNLOCK(PROXY_LOCK, &ctx->px->lock);
  cant_send:
-       cs_rx_room_blk(cs);
+       sc_need_room(cs);
        return 0;
 }
 
index f46aaeffd4b6d5344a5a75176ff69e9e84fe45ea..2b3e128f7b854b2e6df5624cef14a954437b9308 100644 (file)
@@ -2615,7 +2615,7 @@ static int stats_dump_resolv_to_buffer(struct stconn *cs,
        return 1;
 
   full:
-       cs_rx_room_rdy(cs);
+       sc_have_room(cs);
        return 0;
 }
 
@@ -2662,7 +2662,7 @@ int stats_dump_resolvers(struct stconn *cs,
        return 1;
 
   full:
-       cs_rx_room_blk(cs);
+       sc_need_room(cs);
        return 0;
 }
 
index 5aee44967fa7a7c1fe4df20e105a8fcdb671aa5b..8b55114c9daaf9b3e66dfac47c7c61e814117d91 100644 (file)
@@ -3216,7 +3216,7 @@ int stats_dump_proxy_to_buffer(struct stconn *cs, struct htx *htx,
        }
 
   full:
-       cs_rx_room_blk(cs);
+       sc_need_room(cs);
        return 0;
 }
 
@@ -3711,7 +3711,7 @@ static int stats_dump_proxies(struct stconn *cs,
        return 1;
 
   full:
-       cs_rx_room_blk(cs);
+       sc_need_room(cs);
        return 0;
 }
 
@@ -3815,7 +3815,7 @@ static int stats_dump_stat_to_buffer(struct stconn *cs, struct htx *htx,
        }
 
   full:
-       cs_rx_room_blk(cs);
+       sc_need_room(cs);
        return 0;
 
 }
@@ -4210,7 +4210,7 @@ static int stats_send_http_headers(struct stconn *cs, struct htx *htx)
 
   full:
        htx_reset(htx);
-       cs_rx_room_blk(cs);
+       sc_need_room(cs);
        return 0;
 }
 
@@ -4270,7 +4270,7 @@ static int stats_send_http_redirect(struct stconn *cs, struct htx *htx)
 
 full:
        htx_reset(htx);
-       cs_rx_room_blk(cs);
+       sc_need_room(cs);
        return 0;
 }
 
@@ -4299,7 +4299,7 @@ static void http_stats_io_handler(struct appctx *appctx)
 
        /* Check if the input buffer is available. */
        if (!b_size(&res->buf)) {
-               cs_rx_room_blk(cs);
+               sc_need_room(cs);
                goto out;
        }
 
@@ -4342,7 +4342,7 @@ static void http_stats_io_handler(struct appctx *appctx)
                 */
                if (htx_is_empty(res_htx)) {
                        if (!htx_add_endof(res_htx, HTX_BLK_EOT)) {
-                               cs_rx_room_blk(cs);
+                               sc_need_room(cs);
                                goto out;
                        }
                        channel_add_input(res, 1);
index c8a3cb9c3692304dd08adaef7f559e647c0e90da..f9656c029179af191473f124cb2c994951820b18 100644 (file)
@@ -117,7 +117,7 @@ int tcp_inspect_request(struct stream *s, struct channel *req, int an_bit)
         */
 
        if ((req->flags & (CF_EOI|CF_SHUTR|CF_READ_ERROR)) || channel_full(req, global.tune.maxrewrite) ||
-           cs_rx_blocked_room(chn_prod(req)) ||
+           sc_waiting_room(chn_prod(req)) ||
            !s->be->tcp_req.inspect_delay || tick_is_expired(s->rules_exp, now_ms))
                partial = SMP_OPT_FINAL;
        else
@@ -300,7 +300,7 @@ int tcp_inspect_response(struct stream *s, struct channel *rep, int an_bit)
         * - if one rule returns KO, then return KO
         */
        if ((rep->flags & (CF_EOI|CF_SHUTR|CF_READ_ERROR)) || channel_full(rep, global.tune.maxrewrite) ||
-           cs_rx_blocked_room(chn_prod(rep)) ||
+           sc_waiting_room(chn_prod(rep)) ||
            !s->be->tcp_rep.inspect_delay || tick_is_expired(s->rules_exp, now_ms))
                partial = SMP_OPT_FINAL;
        else