diff --git a/addons/promex/service-prometheus.c b/addons/promex/service-prometheus.c index 23a27d3a2..8469942cc 100644 --- a/addons/promex/service-prometheus.c +++ b/addons/promex/service-prometheus.c @@ -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); diff --git a/include/haproxy/conn_stream.h b/include/haproxy/conn_stream.h index 490eecf1a..33b908b89 100644 --- a/include/haproxy/conn_stream.h +++ b/include/haproxy/conn_stream.h @@ -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); } diff --git a/src/applet.c b/src/applet.c index 1af0dbddf..718b29902 100644 --- a/src/applet.c +++ b/src/applet.c @@ -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 */ diff --git a/src/cache.c b/src/cache.c index 22902a355..db751699d 100644 --- a/src/cache.c +++ b/src/cache.c @@ -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; } } diff --git a/src/cli.c b/src/cli.c index e684620cc..1a1b41850 100644 --- 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 */ diff --git a/src/conn_stream.c b/src/conn_stream.c index b60a9c59c..caf33e438 100644 --- a/src/conn_stream.c +++ b/src/conn_stream.c @@ -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)) { diff --git a/src/dns.c b/src/dns.c index 6156dbad6..29e7f3e3f 100644 --- 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; } diff --git a/src/flt_spoe.c b/src/flt_spoe.c index 47537d770..ac48c0669 100644 --- a/src/flt_spoe.c +++ b/src/flt_spoe.c @@ -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; diff --git a/src/hlua.c b/src/hlua.c index 26017555c..e9316106b 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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); diff --git a/src/http_ana.c b/src/http_ana.c index 6f09f2a20..9bcca5d91 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -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) { diff --git a/src/http_client.c b/src/http_client.c index 910cd0f5f..d0b2a58a2 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -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; diff --git a/src/peers.c b/src/peers.c index cfa0b53f4..81af529d7 100644 --- a/src/peers.c +++ b/src/peers.c @@ -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; } diff --git a/src/proxy.c b/src/proxy.c index 26a4ad80c..df460858d 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -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; } diff --git a/src/resolvers.c b/src/resolvers.c index f46aaeffd..2b3e128f7 100644 --- a/src/resolvers.c +++ b/src/resolvers.c @@ -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; } diff --git a/src/stats.c b/src/stats.c index 5aee44967..8b55114c9 100644 --- a/src/stats.c +++ b/src/stats.c @@ -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); diff --git a/src/tcp_rules.c b/src/tcp_rules.c index c8a3cb9c3..f9656c029 100644 --- a/src/tcp_rules.c +++ b/src/tcp_rules.c @@ -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