From: Amaury Denoyelle Date: Thu, 7 Nov 2024 16:15:15 +0000 (+0100) Subject: MINOR: applet: define applet_putchk_stress() alternative X-Git-Tag: v3.2-dev2~96 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1f458b3ea8ec156d09ed87439784d145d0e13809;p=thirdparty%2Fhaproxy.git MINOR: applet: define applet_putchk_stress() alternative Previous patch introduced stress mode to be able to easily test alternative code paths. The first point would be to force interruption of stats dump on every line and check reentrant patchs, in particular while adding and removing servers instances. The purpose of this patch is to be able to use applet_putchk_stress() during stats dump while not impacting other applets. To support this, extract applet_putchk() into an internal _applet_putchk() which have a new argument stress. Define two helpers applet_putchk() and applet_putchk_stress(), the latter to set the stress argument to true. For the moment, applet_putchk_stress() is not used. This will be the subject of the next patch. --- diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 1c9721d5c2..17e1c77daa 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -279,16 +279,16 @@ static inline void applet_expect_data(struct appctx *appctx) se_fl_clr(appctx->sedesc, SE_FL_EXP_NO_DATA); } -/* writes chunk into the input channel of the stream attached to this - * appctx's endpoint, and marks the SC_FL_NEED_ROOM on a channel full error. - * See ci_putchk() for the list of return codes. - */ -static inline int applet_putchk(struct appctx *appctx, struct buffer *chunk) +/* Should only be used via wrappers applet_putchk() / applet_putchk_stress(). */ +static inline int _applet_putchk(struct appctx *appctx, struct buffer *chunk, + int stress) { int ret; if (appctx->flags & APPCTX_FL_INOUT_BUFS) { - if (b_data(chunk) > b_room(&appctx->outbuf)) { + if (unlikely(stress) ? + b_data(&appctx->outbuf) : + b_data(chunk) > b_room(&appctx->outbuf)) { applet_fl_set(appctx, APPCTX_FL_OUTBLK_FULL); ret = -1; } @@ -300,8 +300,8 @@ static inline int applet_putchk(struct appctx *appctx, struct buffer *chunk) else { struct sedesc *se = appctx->sedesc; - ret = ci_putchk(sc_ic(se->sc), chunk); - if (ret < 0) { + if ((unlikely(stress) && ci_data(sc_ic(se->sc))) || + (ret = ci_putchk(sc_ic(se->sc), chunk)) < 0) { /* XXX: Handle all errors as a lack of space because callers * don't handles other cases for now. So applets must be * careful to handles shutdown (-2) and invalid calls (-3) by @@ -311,9 +311,25 @@ static inline int applet_putchk(struct appctx *appctx, struct buffer *chunk) ret = -1; } } + return ret; } +/* writes chunk into the input channel of the stream attached to this + * appctx's endpoint, and marks the SC_FL_NEED_ROOM on a channel full error. + * See ci_putchk() for the list of return codes. + */ +static inline int applet_putchk(struct appctx *appctx, struct buffer *chunk) +{ + return _applet_putchk(appctx, chunk, 0); +} + +/* Equivalent of applet_putchk() but with stress condition alternatives activated. */ +static inline int applet_putchk_stress(struct appctx *appctx, struct buffer *chunk) +{ + return _applet_putchk(appctx, chunk, 1); +} + /* writes chars from into the input channel of the stream attached * to this appctx's endpoint, and marks the SC_FL_NEED_ROOM on a channel full * error. See ci_putblk() for the list of return codes.