]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: set the blocking flag in the buffer allocation function
authorWilly Tarreau <w@1wt.eu>
Tue, 7 May 2024 17:16:20 +0000 (19:16 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 May 2024 15:18:13 +0000 (17:18 +0200)
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
src/applet.c
src/cache.c
src/cli.c
src/stats-html.c

index 663f89035893686a29f0be8178a946472362bd6c..e2762458fc6fff30422a7a2667049686b2ff6206 100644 (file)
@@ -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;
 }
index 36f0c03f50a0bceb62bf1b92514b5e5ca0f3bb20..6dc6615cc526857eabc98e56722d3b4b910ec108 100644 (file)
@@ -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;
        }
index c7198cd1a0edd488b74a457b98187874d798c4c5..32f2e471c32da1a972096251e1b99cb42195c922 100644 (file)
@@ -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;
        }
 
index 980735dcdb5f469e9bfa41a88093b439c3b82280..9470d127ad9777ad47047ea2f33005740b7e7c00 100644 (file)
--- 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;
        }
 
index 8707597f20235495c691c635c5d426bb3632f2da..367222976718eaa8ee293740279fa03a6065a883 100644 (file)
@@ -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;
        }