]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stconn: report that a buffer allocation succeeded
authorWilly Tarreau <w@1wt.eu>
Tue, 7 May 2024 15:11:14 +0000 (17:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 May 2024 15:18:13 +0000 (17:18 +0200)
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.

include/haproxy/sc_strm.h
include/haproxy/stconn-t.h
include/haproxy/stconn.h

index 445bbde4f2cc26b0353e098f7fc348b947e07f22..4eaef8864f19ef4c47b2c55c28d1b97b55e958b0 100644 (file)
@@ -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;
 }
 
index 8f0460d3378691ff9c00d9e4bb6f8ad8b94f9cf8..f418e95b5fe8aa9086c73535e7183137fc6d4310 100644 (file)
@@ -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;
index 14ccd75a2d597f80e359d19148515b535ad9dba8..f60eaa88db3653f15021915f890f286d1820bd45 100644 (file)
@@ -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.