]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: report about buffer allocation success
authorWilly Tarreau <w@1wt.eu>
Tue, 7 May 2024 17:22:08 +0000 (19:22 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 May 2024 15:18:13 +0000 (17:18 +0200)
When appctx_buf_available() is called, it now sets APPCTX_FL_IN_MAYALLOC
or APPCTX_FL_OUT_MAYALLOC depending on the reportedly permitted buffer
allocation, and these flags are cleared when the said buffers are
allocated. For now they're not used for anything else.

include/haproxy/applet-t.h
include/haproxy/applet.h
src/applet.c

index de11163140dda0c14aec92f45f0c71864c597e2a..a305da67b8565d1925e854100589ce7a8011b7b9 100644 (file)
@@ -48,6 +48,8 @@
 #define APPCTX_FL_WANT_DIE       0x00000200  /* applet was running and requested to die */
 #define APPCTX_FL_INOUT_BUFS     0x00000400  /* applet uses its own buffers */
 #define APPCTX_FL_FASTFWD        0x00000800  /* zero-copy forwarding is in-use, don't fill the outbuf */
+#define APPCTX_FL_IN_MAYALLOC    0x00001000  /* applet may try again to allocate its inbuf */
+#define APPCTX_FL_OUT_MAYALLOC   0x00002000  /* applet may try again to allocate its outbuf */
 
 struct appctx;
 struct proxy;
index 2beacf4e455d5cafb99039e78941982f2f727f4a..1c9721d5c2c9496d4c69fc49d9892974ed8017f9 100644 (file)
@@ -60,6 +60,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 forceinline void applet_fl_clr(struct appctx *appctx, uint off);
 
 static inline struct appctx *appctx_new_here(struct applet *applet, struct sedesc *sedesc)
 {
@@ -87,7 +88,8 @@ 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 and
  * sets the relevant blocking flag depending on the side (assuming that bptr is
- * either &appctx->inbuf or &appctx->outbuf)
+ * either &appctx->inbuf or &appctx->outbuf). Upon success it will also clear
+ * the equivalent MAYALLOC flags.
  */
 static inline struct buffer *appctx_get_buf(struct appctx *appctx, struct buffer *bptr)
 {
@@ -98,6 +100,8 @@ static inline struct buffer *appctx_get_buf(struct appctx *appctx, struct buffer
                if (unlikely((buf = b_alloc(bptr, is_inbuf ? DB_MUX_TX : DB_SE_RX)) == NULL)) {
                        b_queue(is_inbuf ? DB_MUX_TX : DB_SE_RX, &appctx->buffer_wait, appctx, appctx_buf_available);
                        applet_fl_set(appctx, is_inbuf ? APPCTX_FL_INBLK_ALLOC : APPCTX_FL_OUTBLK_ALLOC);
+               } else {
+                       applet_fl_clr(appctx, is_inbuf ? APPCTX_FL_IN_MAYALLOC : APPCTX_FL_OUT_MAYALLOC);
                }
        }
        return buf;
index 6dc6615cc526857eabc98e56722d3b4b910ec108..c528963c3721babfe04087eab460134be5c7b8af 100644 (file)
@@ -447,12 +447,14 @@ int appctx_buf_available(void *arg)
 
        if (applet_fl_test(appctx, APPCTX_FL_INBLK_ALLOC)) {
                applet_fl_clr(appctx, APPCTX_FL_INBLK_ALLOC);
+               applet_fl_set(appctx, APPCTX_FL_IN_MAYALLOC);
                TRACE_STATE("unblocking appctx on inbuf allocation", APPLET_EV_RECV|APPLET_EV_BLK|APPLET_EV_WAKE, appctx);
                ret = 1;
        }
 
        if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC)) {
                applet_fl_clr(appctx, APPCTX_FL_OUTBLK_ALLOC);
+               applet_fl_set(appctx, APPCTX_FL_OUT_MAYALLOC);
                TRACE_STATE("unblocking appctx on outbuf allocation", APPLET_EV_SEND|APPLET_EV_BLK|APPLET_EV_WAKE, appctx);
                ret = 1;
        }