From 1d68bebb7050d869a926a34441ce06ec7fcbe4d0 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 3 Aug 2023 15:30:55 +0200 Subject: [PATCH] MINOR: stconn: Extend iobuf to handle a buffer in addition to a pipe 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 | 6 ++++++ include/haproxy/stconn.h | 4 ++-- src/stconn.c | 2 ++ src/stream.c | 22 ++++++++++++++++++---- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/haproxy/stconn-t.h b/include/haproxy/stconn-t.h index 39b479b0c..1aace1287 100644 --- a/include/haproxy/stconn-t.h +++ b/include/haproxy/stconn-t.h @@ -30,10 +30,16 @@ 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; }; diff --git a/include/haproxy/stconn.h b/include/haproxy/stconn.h index d58fd791e..12ac81b21 100644 --- a/include/haproxy/stconn.h +++ b/include/haproxy/stconn.h @@ -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)); } diff --git a/src/stconn.c b/src/stconn.c index 63d4383e0..f208678da 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -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; } diff --git a/src/stream.c b/src/stream.c index 06db5636f..6ccbe8623 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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)) : ""); + 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)) : ""); + 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 ?