MINOR: stconn: Extend iobuf to handle a buffer in addition to a pipe
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Aug 2023 13:30:55 +0000 (15:30 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 Oct 2023 16:51:13 +0000 (18:51 +0200)
It is unused for now, but the iobuf structure now owns a pointer to a
buffer. This buffer will be used to perform mux-to-mux fast-forwarding when
splicing is not supported or unusable. This pointer should be filled by an
endpoint to let the opposite one forward data.

Extra fields, in addition to the buffer, are mandatory because the buffer
may already contains some data. the ".offset" field may be used may be used
as the position to start to copy data. Finally, the amount of data copied in
this buffer must be saved in ".data" field.

Some flags are also added to prepare next changes. And helper stconn
fnuctions are updated to also count data in the buffer. For a first
implementation, it is not planned to handle data in the buffer and in the
pipe in same time. But it will be possible to do so.

include/haproxy/stconn-t.h
include/haproxy/stconn.h
src/stconn.c
src/stream.c

index 39b479b..1aace12 100644 (file)
 
 enum iobuf_flags {
        IOBUF_FL_NONE             = 0x00000000, /* For initialization purposes */
+       IOBUF_FL_NO_FF            = 0x00000001, /* Fast-forwarding is not supported */
+       IOBUF_FL_NO_SPLICING      = 0x00000002, /* Splicing is not supported or unusable for this stream */
+       IOBUF_FL_FF_BLOCKED       = 0x00000004, /* Fast-forwarding is blocked (buffer allocation/full) */
 };
 
 struct iobuf {
        struct pipe *pipe;     /* non-NULL only when data present */
+       struct buffer *buf;
+       size_t offset;
+       size_t data;
        unsigned int flags;
 };
 
index d58fd79..12ac81b 100644 (file)
@@ -124,12 +124,12 @@ static inline void se_expect_data(struct sedesc *se)
 
 static inline unsigned int se_have_ff_data(struct sedesc *se)
 {
-       return ((long)se->iobuf.pipe);
+       return (se->iobuf.data | (long)se->iobuf.pipe);
 }
 
 static inline size_t se_ff_data(struct sedesc *se)
 {
-       return ((se->iobuf.pipe ? se->iobuf.pipe->data : 0));
+       return (se->iobuf.data + (se->iobuf.pipe ? se->iobuf.pipe->data : 0));
 }
 
 
index 63d4383..f208678 100644 (file)
@@ -99,6 +99,8 @@ void sedesc_init(struct sedesc *sedesc)
        se_fl_setall(sedesc, SE_FL_NONE);
 
        sedesc->iobuf.pipe = NULL;
+       sedesc->iobuf.buf = NULL;
+       sedesc->iobuf.offset = sedesc->iobuf.data = 0;
        sedesc->iobuf.flags = IOBUF_FL_NONE;
 }
 
index 06db563..6ccbe86 100644 (file)
@@ -3307,6 +3307,14 @@ void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, const ch
        chunk_appendf(buf, " wex=%s\n",
                      sc_ep_snd_ex(scf) ? human_time(TICKS_TO_MS(sc_ep_snd_ex(scf) - now_ms), TICKS_TO_MS(1000)) : "<NEVER>");
 
+       chunk_appendf(&trash, "%s    iobuf.flags=0x%08x .pipe=%d .buf=%u@%p+%u/%u\n", pfx,
+                     scf->sedesc->iobuf.flags,
+                     scf->sedesc->iobuf.pipe ? scf->sedesc->iobuf.pipe->data : 0,
+                     scf->sedesc->iobuf.buf ? (unsigned int)b_data(scf->sedesc->iobuf.buf): 0,
+                     scf->sedesc->iobuf.buf ? b_orig(scf->sedesc->iobuf.buf): NULL,
+                     scf->sedesc->iobuf.buf ? (unsigned int)b_head_ofs(scf->sedesc->iobuf.buf): 0,
+                     scf->sedesc->iobuf.buf ? (unsigned int)b_size(scf->sedesc->iobuf.buf): 0);
+
        if ((conn = sc_conn(scf)) != NULL) {
                if (conn->mux && conn->mux->show_sd) {
                        char muxpfx[100] = "";
@@ -3356,6 +3364,14 @@ void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, const ch
        chunk_appendf(buf, " wex=%s\n",
                      sc_ep_snd_ex(scb) ? human_time(TICKS_TO_MS(sc_ep_snd_ex(scb) - now_ms), TICKS_TO_MS(1000)) : "<NEVER>");
 
+       chunk_appendf(&trash, "%s    iobuf.flags=0x%08x .pipe=%d .buf=%u@%p+%u/%u\n", pfx,
+                     scb->sedesc->iobuf.flags,
+                     scb->sedesc->iobuf.pipe ? scb->sedesc->iobuf.pipe->data : 0,
+                     scb->sedesc->iobuf.buf ? (unsigned int)b_data(scb->sedesc->iobuf.buf): 0,
+                     scb->sedesc->iobuf.buf ? b_orig(scb->sedesc->iobuf.buf): NULL,
+                     scb->sedesc->iobuf.buf ? (unsigned int)b_head_ofs(scb->sedesc->iobuf.buf): 0,
+                     scb->sedesc->iobuf.buf ? (unsigned int)b_size(scb->sedesc->iobuf.buf): 0);
+
        if ((conn = sc_conn(scb)) != NULL) {
                if (conn->mux && conn->mux->show_sd) {
                        char muxpfx[100] = "";
@@ -3408,12 +3424,11 @@ void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, const ch
        }
 
        chunk_appendf(buf,
-                    "%s  req=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
+                    "%s  req=%p (f=0x%06x an=0x%x tofwd=%d total=%lld)\n"
                     "%s      an_exp=%s buf=%p data=%p o=%u p=%u i=%u size=%u\n",
                     pfx,
                     &strm->req,
                     strm->req.flags, strm->req.analysers,
-                    strm->scb->sedesc->iobuf.pipe ? strm->scb->sedesc->iobuf.pipe->data : 0,
                     strm->req.to_forward, strm->req.total,
                     pfx,
                     strm->req.analyse_exp ?
@@ -3441,12 +3456,11 @@ void strm_dump_to_buffer(struct buffer *buf, const struct stream *strm, const ch
        }
 
        chunk_appendf(buf,
-                    "%s  res=%p (f=0x%06x an=0x%x pipe=%d tofwd=%d total=%lld)\n"
+                    "%s  res=%p (f=0x%06x an=0x%x tofwd=%d total=%lld)\n"
                     "%s      an_exp=%s buf=%p data=%p o=%u p=%u i=%u size=%u\n",
                     pfx,
                     &strm->res,
                     strm->res.flags, strm->res.analysers,
-                    strm->scf->sedesc->iobuf.pipe ? strm->scf->sedesc->iobuf.pipe->data : 0,
                     strm->res.to_forward, strm->res.total,
                     pfx,
                     strm->res.analyse_exp ?