From: Willy Tarreau Date: Tue, 7 May 2024 17:22:08 +0000 (+0200) Subject: MINOR: applet: report about buffer allocation success X-Git-Tag: v3.0-dev11~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb2d758043e91d81d00787ab3b95a462e769d037;p=thirdparty%2Fhaproxy.git MINOR: applet: report about buffer allocation success 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. --- diff --git a/include/haproxy/applet-t.h b/include/haproxy/applet-t.h index de11163140..a305da67b8 100644 --- a/include/haproxy/applet-t.h +++ b/include/haproxy/applet-t.h @@ -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; diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 2beacf4e45..1c9721d5c2 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -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; diff --git a/src/applet.c b/src/applet.c index 6dc6615cc5..c528963c37 100644 --- a/src/applet.c +++ b/src/applet.c @@ -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; }