From: Willy Tarreau Date: Tue, 7 May 2024 15:11:14 +0000 (+0200) Subject: MINOR: stconn: report that a buffer allocation succeeded X-Git-Tag: v3.0-dev11~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7aff64518c2a678060595fc23bf64f8ca4ce16e8;p=thirdparty%2Fhaproxy.git MINOR: stconn: report that a buffer allocation succeeded We used to have two states for the channel's input buffer used by the SC, NEED_BUFF or not, flipped by sc_need_buff() and sc_have_buff(). We want to have a 3rd state, indicating that we've just got a desired buffer. Let's add an HAVE_BUFF flag that is set by sc_have_buff() and that is cleared by sc_used_buff(). This way by looking at HAVE_BUFF we know that we're coming back from the allocation callback and that the offered buffer has not yet been used. --- diff --git a/include/haproxy/sc_strm.h b/include/haproxy/sc_strm.h index 445bbde4f2..4eaef8864f 100644 --- a/include/haproxy/sc_strm.h +++ b/include/haproxy/sc_strm.h @@ -155,8 +155,11 @@ static inline int sc_alloc_ibuf(struct stconn *sc, struct buffer_wait *wait) int ret; ret = channel_alloc_buffer(sc_ic(sc), wait); - if (!ret) + if (ret) + sc_used_buff(sc); + else sc_need_buff(sc); + return ret; } diff --git a/include/haproxy/stconn-t.h b/include/haproxy/stconn-t.h index 8f0460d337..f418e95b5f 100644 --- a/include/haproxy/stconn-t.h +++ b/include/haproxy/stconn-t.h @@ -204,6 +204,7 @@ enum sc_flags { SC_FL_SHUT_DONE = 0x00020000, /* A shutdown was performed for the SC */ SC_FL_EOS = 0x00040000, /* End of stream was reached (from down side to up side) */ + SC_FL_HAVE_BUFF = 0x00080000, /* A buffer is ready, flag will be cleared once allocated */ }; /* This function is used to report flags in debugging tools. Please reflect @@ -221,7 +222,7 @@ static forceinline char *sc_show_flags(char *buf, size_t len, const char *delim, _(SC_FL_NEED_BUFF, _(SC_FL_NEED_ROOM, _(SC_FL_RCV_ONCE, _(SC_FL_SND_ASAP, _(SC_FL_SND_NEVERWAIT, _(SC_FL_SND_EXP_MORE, _(SC_FL_ABRT_WANTED, _(SC_FL_SHUT_WANTED, _(SC_FL_ABRT_DONE, _(SC_FL_SHUT_DONE, - _(SC_FL_EOS))))))))))))))))))); + _(SC_FL_EOS, _(SC_FL_HAVE_BUFF)))))))))))))))))))); /* epilogue */ _(~0U); return buf; diff --git a/include/haproxy/stconn.h b/include/haproxy/stconn.h index 14ccd75a2d..f60eaa88db 100644 --- a/include/haproxy/stconn.h +++ b/include/haproxy/stconn.h @@ -377,12 +377,15 @@ static inline void se_need_remote_conn(struct sedesc *se) } /* The application layer tells the stream connector that it just got the input - * buffer it was waiting for. A read activity is reported. + * buffer it was waiting for. A read activity is reported. The SC_FL_HAVE_BUFF + * flag is set and held until sc_used_buff() is called to indicatee it was + * used. */ static inline void sc_have_buff(struct stconn *sc) { if (sc->flags & SC_FL_NEED_BUFF) { sc->flags &= ~SC_FL_NEED_BUFF; + sc->flags |= SC_FL_HAVE_BUFF; sc_ep_report_read_activity(sc); } } @@ -397,6 +400,14 @@ static inline void sc_need_buff(struct stconn *sc) sc->flags |= SC_FL_NEED_BUFF; } +/* The stream connector indicates that it has successfully allocated the buffer + * it was previously waiting for so it drops the SC_FL_HAVE_BUFF bit. + */ +static inline void sc_used_buff(struct stconn *sc) +{ + sc->flags &= ~SC_FL_HAVE_BUFF; +} + /* Tell a stream connector some room was made in the input buffer and any * failed attempt to inject data into it may be tried again. This is usually * called after a successful transfer of buffer contents to the other side.