From 4ffb3b5ebe08e24fb88d125ec1f7e53c2b1b43d3 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 7 May 2024 19:16:20 +0200 Subject: [PATCH] MINOR: applet: set the blocking flag in the buffer allocation function Instead of having each caller of appctx_get_buf() think about setting the blocking flag, better have the function do it, since it's already handling the queue anyway. This way we're sure that both are consistent. --- include/haproxy/applet.h | 14 ++++++++++---- src/applet.c | 2 -- src/cache.c | 1 - src/cli.c | 1 - src/stats-html.c | 1 - 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 663f890358..e2762458fc 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -59,6 +59,7 @@ size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig int appctx_fastfwd(struct stconn *sc, unsigned int count, unsigned int flags); ssize_t applet_append_line(void *ctx, struct ist v1, struct ist v2, size_t ofs, size_t len); +static forceinline void applet_fl_set(struct appctx *appctx, uint on); static inline struct appctx *appctx_new_here(struct applet *applet, struct sedesc *sedesc) { @@ -84,15 +85,20 @@ static inline void appctx_release_buf(struct appctx *appctx, struct buffer *bptr } /* - * Allocate a buffer. If if fails, it adds the appctx in buffer wait queue. + * Allocate a buffer. If if fails, it adds the appctx in buffer wait queue and + * sets the relevant blocking flag depending on the side (assuming that bptr is + * either &appctx->inbuf or &appctx->outbuf) */ static inline struct buffer *appctx_get_buf(struct appctx *appctx, struct buffer *bptr) { struct buffer *buf = NULL; + int is_inbuf = (bptr == &appctx->inbuf); - if (likely(!LIST_INLIST(&appctx->buffer_wait.list)) && - unlikely((buf = b_alloc(bptr, DB_SE_RX)) == NULL)) { - b_queue(DB_SE_RX, &appctx->buffer_wait, appctx, appctx_buf_available); + if (likely(!LIST_INLIST(&appctx->buffer_wait.list))) { + if (unlikely((buf = b_alloc(bptr, DB_SE_RX)) == NULL)) { + b_queue(DB_SE_RX, &appctx->buffer_wait, appctx, appctx_buf_available); + applet_fl_set(appctx, is_inbuf ? APPCTX_FL_INBLK_ALLOC : APPCTX_FL_OUTBLK_ALLOC); + } } return buf; } diff --git a/src/applet.c b/src/applet.c index 36f0c03f50..6dc6615cc5 100644 --- a/src/applet.c +++ b/src/applet.c @@ -528,7 +528,6 @@ size_t appctx_rcv_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig goto end; if (!appctx_get_buf(appctx, &appctx->outbuf)) { - applet_fl_set(appctx, APPCTX_FL_OUTBLK_ALLOC); TRACE_STATE("waiting for appctx outbuf allocation", APPLET_EV_RECV|APPLET_EV_BLK, appctx); goto end; } @@ -626,7 +625,6 @@ size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig goto end; if (!appctx_get_buf(appctx, &appctx->inbuf)) { - applet_fl_set(appctx, APPCTX_FL_INBLK_ALLOC); TRACE_STATE("waiting for appctx inbuf allocation", APPLET_EV_SEND|APPLET_EV_BLK, appctx); goto end; } diff --git a/src/cache.c b/src/cache.c index c7198cd1a0..32f2e471c3 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1790,7 +1790,6 @@ static void http_cache_io_handler(struct appctx *appctx) goto exit; if (!appctx_get_buf(appctx, &appctx->outbuf)) { - applet_fl_set(appctx, APPCTX_FL_OUTBLK_ALLOC); goto exit; } diff --git a/src/cli.c b/src/cli.c index 980735dcdb..9470d127ad 100644 --- a/src/cli.c +++ b/src/cli.c @@ -1058,7 +1058,6 @@ static void cli_io_handler(struct appctx *appctx) goto out; if (!appctx_get_buf(appctx, &appctx->outbuf)) { - applet_fl_set(appctx, APPCTX_FL_OUTBLK_ALLOC); goto out; } diff --git a/src/stats-html.c b/src/stats-html.c index 8707597f20..3672229767 100644 --- a/src/stats-html.c +++ b/src/stats-html.c @@ -1955,7 +1955,6 @@ static void http_stats_io_handler(struct appctx *appctx) goto out; if (!appctx_get_buf(appctx, &appctx->outbuf)) { - applet_fl_set(appctx, APPCTX_FL_OUTBLK_ALLOC); goto out; }