MINOR: stconn: Use a dedicated function to get the opposite sedesc

se_opposite() function is added to let an endpoint retrieve the opposite
endpoint descriptor. Muxes supportng the zero-copy forwarding can now use
it. The se_shutdown() function too. This will be use by the SPOP multiplexer
to be able to retrieve the SPOE agent configuration attached to the applet
on client side.

The related issue is #2502.
This commit is contained in:
Christopher Faulet 2024-07-04 10:24:06 +02:00
parent 4b8098bf48
commit 51ebf644e5
5 changed files with 24 additions and 46 deletions

View File

@ -27,6 +27,7 @@
#include <haproxy/htx-t.h> #include <haproxy/htx-t.h>
#include <haproxy/obj_type.h> #include <haproxy/obj_type.h>
#include <haproxy/stconn-t.h> #include <haproxy/stconn-t.h>
#include <haproxy/xref.h>
struct buffer; struct buffer;
struct session; struct session;
@ -134,6 +135,19 @@ static inline size_t se_ff_data(struct sedesc *se)
return (se->iobuf.data + (se->iobuf.pipe ? se->iobuf.pipe->data : 0)); return (se->iobuf.data + (se->iobuf.pipe ? se->iobuf.pipe->data : 0));
} }
static inline struct sedesc *se_opposite(struct sedesc *se)
{
struct xref *peer = xref_get_peer_and_lock(&se->xref);
struct sedesc *seo = NULL;;
if (peer) {
seo = container_of(peer, struct sedesc, xref);
xref_unlock(&se->xref, peer);
}
return seo;
}
/* stream connector version */ /* stream connector version */
static forceinline void sc_ep_zero(struct stconn *sc) static forceinline void sc_ep_zero(struct stconn *sc)
{ {

View File

@ -25,7 +25,6 @@
#include <haproxy/task.h> #include <haproxy/task.h>
#include <haproxy/trace.h> #include <haproxy/trace.h>
#include <haproxy/vecpair.h> #include <haproxy/vecpair.h>
#include <haproxy/xref.h>
unsigned int nb_applets = 0; unsigned int nb_applets = 0;
@ -646,7 +645,6 @@ size_t appctx_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig
int appctx_fastfwd(struct stconn *sc, unsigned int count, unsigned int flags) int appctx_fastfwd(struct stconn *sc, unsigned int count, unsigned int flags)
{ {
struct appctx *appctx = __sc_appctx(sc); struct appctx *appctx = __sc_appctx(sc);
struct xref *peer;
struct sedesc *sdo = NULL; struct sedesc *sdo = NULL;
unsigned int len, nego_flags = NEGO_FF_FL_NONE; unsigned int len, nego_flags = NEGO_FF_FL_NONE;
int ret = 0; int ret = 0;
@ -661,13 +659,11 @@ int appctx_fastfwd(struct stconn *sc, unsigned int count, unsigned int flags)
return -1; return -1;
} }
peer = xref_get_peer_and_lock(&appctx->sedesc->xref); sdo = se_opposite(appctx->sedesc);
if (!peer) { if (!sdo) {
TRACE_STATE("Opposite endpoint not available yet", APPLET_EV_RECV, appctx); TRACE_STATE("Opposite endpoint not available yet", APPLET_EV_RECV, appctx);
goto end; goto end;
} }
sdo = container_of(peer, struct sedesc, xref);
xref_unlock(&appctx->sedesc->xref, peer);
if (appctx->to_forward && count > appctx->to_forward) { if (appctx->to_forward && count > appctx->to_forward) {
count = appctx->to_forward; count = appctx->to_forward;

View File

@ -31,7 +31,6 @@
#include <haproxy/stconn.h> #include <haproxy/stconn.h>
#include <haproxy/stream.h> #include <haproxy/stream.h>
#include <haproxy/trace.h> #include <haproxy/trace.h>
#include <haproxy/xref.h>
/* H1 connection descriptor */ /* H1 connection descriptor */
struct h1c { struct h1c {
@ -4603,16 +4602,7 @@ static size_t h1_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, in
static inline struct sedesc *h1s_opposite_sd(struct h1s *h1s) static inline struct sedesc *h1s_opposite_sd(struct h1s *h1s)
{ {
struct xref *peer; return se_opposite(h1s->sd);
struct sedesc *sdo;
peer = xref_get_peer_and_lock(&h1s->sd->xref);
if (!peer)
return NULL;
sdo = container_of(peer, struct sedesc, xref);
xref_unlock(&h1s->sd->xref, peer);
return sdo;
} }
static size_t h1_nego_ff(struct stconn *sc, struct buffer *input, size_t count, unsigned int flags) static size_t h1_nego_ff(struct stconn *sc, struct buffer *input, size_t count, unsigned int flags)

View File

@ -19,7 +19,6 @@
#include <haproxy/stream.h> #include <haproxy/stream.h>
#include <haproxy/task.h> #include <haproxy/task.h>
#include <haproxy/trace.h> #include <haproxy/trace.h>
#include <haproxy/xref.h>
struct mux_pt_ctx { struct mux_pt_ctx {
struct sedesc *sd; struct sedesc *sd;
@ -561,16 +560,7 @@ static size_t mux_pt_snd_buf(struct stconn *sc, struct buffer *buf, size_t count
static inline struct sedesc *mux_pt_opposite_sd(struct mux_pt_ctx *ctx) static inline struct sedesc *mux_pt_opposite_sd(struct mux_pt_ctx *ctx)
{ {
struct xref *peer; return se_opposite(ctx->sd);
struct sedesc *sdo;
peer = xref_get_peer_and_lock(&ctx->sd->xref);
if (!peer)
return NULL;
sdo = container_of(peer, struct sedesc, xref);
xref_unlock(&ctx->sd->xref, peer);
return sdo;
} }
static size_t mux_pt_nego_ff(struct stconn *sc, struct buffer *input, size_t count, unsigned int flags) static size_t mux_pt_nego_ff(struct stconn *sc, struct buffer *input, size_t count, unsigned int flags)

View File

@ -141,6 +141,8 @@ void sedesc_free(struct sedesc *sedesc)
*/ */
void se_shutdown(struct sedesc *sedesc, enum se_shut_mode mode) void se_shutdown(struct sedesc *sedesc, enum se_shut_mode mode)
{ {
struct sedesc *sdo;
struct se_abort_info *reason = NULL;
unsigned int flags = 0; unsigned int flags = 0;
if ((mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) && !se_fl_test(sedesc, SE_FL_SHW)) if ((mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) && !se_fl_test(sedesc, SE_FL_SHW))
@ -153,16 +155,9 @@ void se_shutdown(struct sedesc *sedesc, enum se_shut_mode mode)
if (flags) { if (flags) {
if (mux && mux->shut) { if (mux && mux->shut) {
struct se_abort_info *reason = NULL; sdo = se_opposite(sedesc);
struct xref *peer = xref_get_peer_and_lock(&sedesc->xref); if (sdo)
if (peer) {
struct sedesc *sdo = container_of(peer, struct sedesc, xref);
reason = &sdo->abort_info; reason = &sdo->abort_info;
xref_unlock(&sedesc->xref, peer);
}
mux->shut(sedesc->sc, mode, reason); mux->shut(sedesc->sc, mode, reason);
} }
se_fl_set(sedesc, flags); se_fl_set(sedesc, flags);
@ -173,16 +168,9 @@ void se_shutdown(struct sedesc *sedesc, enum se_shut_mode mode)
if (flags) { if (flags) {
if (appctx->applet->shut) { if (appctx->applet->shut) {
struct se_abort_info *reason = NULL; sdo = se_opposite(sedesc);
struct xref *peer = xref_get_peer_and_lock(&sedesc->xref); if (sdo)
if (peer) {
struct sedesc *sdo = container_of(peer, struct sedesc, xref);
reason = &sdo->abort_info; reason = &sdo->abort_info;
xref_unlock(&sedesc->xref, peer);
}
appctx->applet->shut(appctx, mode, reason); appctx->applet->shut(appctx, mode, reason);
} }
se_fl_set(sedesc, flags); se_fl_set(sedesc, flags);