From fbc0850d36fddec8055bc3b52b0e343ef90b0f9f Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Thu, 18 Apr 2024 09:56:11 +0200 Subject: [PATCH] MEDIUM: muxes: Use one callback function to shut a mux stream mux-ops .shutr and .shutw callback functions are merged into a unique functions, called .shut. The shutdown mode is still passed as argument, muxes are responsible to test it. Concretly, .shut() function of each mux is now the content of the old .shutw() followed by the content of the old .shutr(). --- include/haproxy/connection-t.h | 3 +- src/mux_fcgi.c | 20 ++++---------- src/mux_h1.c | 23 +++------------- src/mux_h2.c | 18 +++--------- src/mux_pt.c | 50 ++++++++++++++-------------------- src/mux_quic.c | 7 +++-- src/stconn.c | 20 ++++++++------ 7 files changed, 51 insertions(+), 90 deletions(-) diff --git a/include/haproxy/connection-t.h b/include/haproxy/connection-t.h index bfaece231..342abba5d 100644 --- a/include/haproxy/connection-t.h +++ b/include/haproxy/connection-t.h @@ -411,8 +411,7 @@ struct mux_ops { size_t (*done_fastfwd)(struct stconn *sc); /* Callback to terminate fast data forwarding */ int (*fastfwd)(struct stconn *sc, unsigned int count, unsigned int flags); /* Callback to init fast data forwarding */ int (*resume_fastfwd)(struct stconn *sc, unsigned int flags); /* Callback to resume fast data forwarding */ - void (*shutr)(struct stconn *sc, enum se_shut_mode); /* shutr function */ - void (*shutw)(struct stconn *sc, enum se_shut_mode); /* shutw function */ + void (*shut)(struct stconn *sc, enum se_shut_mode); /* shutdown function */ int (*attach)(struct connection *conn, struct sedesc *, struct session *sess); /* attach a stconn to an outgoing connection */ struct stconn *(*get_first_sc)(const struct connection *); /* retrieves any valid stconn from this connection */ diff --git a/src/mux_fcgi.c b/src/mux_fcgi.c index 3562663c4..b914eadfe 100644 --- a/src/mux_fcgi.c +++ b/src/mux_fcgi.c @@ -3791,23 +3791,16 @@ struct task *fcgi_deferred_shut(struct task *t, void *ctx, unsigned int state) return NULL; } -/* shutr() called by the stream connector (mux_ops.shutr) */ -static void fcgi_shutr(struct stconn *sc, enum se_shut_mode mode) +static void fcgi_shut(struct stconn *sc, enum se_shut_mode mode) { struct fcgi_strm *fstrm = __sc_mux_strm(sc); - TRACE_POINT(FCGI_EV_STRM_SHUT, fstrm->fconn->conn, fstrm); + TRACE_ENTER(FCGI_EV_STRM_SHUT, fstrm->fconn->conn, fstrm); + if (mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) + fcgi_do_shutw(fstrm); if (mode & SE_SHR_RESET) fcgi_do_shutr(fstrm); -} - -/* shutw() called by the stream connector (mux_ops.shutw) */ -static void fcgi_shutw(struct stconn *sc, enum se_shut_mode mode) -{ - struct fcgi_strm *fstrm = __sc_mux_strm(sc); - - TRACE_POINT(FCGI_EV_STRM_SHUT, fstrm->fconn->conn, fstrm); - fcgi_do_shutw(fstrm); + TRACE_LEAVE(FCGI_EV_STRM_SHUT, fstrm->fconn->conn, fstrm); } /* Called from the upper layer, to subscribe to events . The @@ -4261,8 +4254,7 @@ static const struct mux_ops mux_fcgi_ops = { .snd_buf = fcgi_snd_buf, .subscribe = fcgi_subscribe, .unsubscribe = fcgi_unsubscribe, - .shutr = fcgi_shutr, - .shutw = fcgi_shutw, + .shut = fcgi_shut, .ctl = fcgi_ctl, .sctl = fcgi_sctl, .show_fd = fcgi_show_fd, diff --git a/src/mux_h1.c b/src/mux_h1.c index 881fff77b..9e3feb9f7 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -4291,25 +4291,12 @@ static void h1_detach(struct sedesc *sd) TRACE_LEAVE(H1_EV_STRM_END); } - -static void h1_shutr(struct stconn *sc, enum se_shut_mode mode) -{ - struct h1s *h1s = __sc_mux_strm(sc); - struct h1c *h1c; - - if (!h1s) - return; - h1c = h1s->h1c; - - TRACE_POINT(H1_EV_STRM_SHUT, h1c->conn, h1s, 0, (size_t[]){mode}); -} - -static void h1_shutw(struct stconn *sc, enum se_shut_mode mode) +static void h1_shut(struct stconn *sc, enum se_shut_mode mode) { struct h1s *h1s = __sc_mux_strm(sc); struct h1c *h1c; - if (!h1s) + if (!h1s || !(mode & (SE_SHW_SILENT|SE_SHW_NORMAL))) return; h1c = h1s->h1c; @@ -5517,8 +5504,7 @@ static const struct mux_ops mux_http_ops = { .resume_fastfwd = h1_resume_fastfwd, .subscribe = h1_subscribe, .unsubscribe = h1_unsubscribe, - .shutr = h1_shutr, - .shutw = h1_shutw, + .shut = h1_shut, .show_fd = h1_show_fd, .show_sd = h1_show_sd, .ctl = h1_ctl, @@ -5545,8 +5531,7 @@ static const struct mux_ops mux_h1_ops = { .resume_fastfwd = h1_resume_fastfwd, .subscribe = h1_subscribe, .unsubscribe = h1_unsubscribe, - .shutr = h1_shutr, - .shutw = h1_shutw, + .shut = h1_shut, .show_fd = h1_show_fd, .show_sd = h1_show_sd, .ctl = h1_ctl, diff --git a/src/mux_h2.c b/src/mux_h2.c index f76685593..47b1f14cf 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -5079,27 +5079,18 @@ struct task *h2_deferred_shut(struct task *t, void *ctx, unsigned int state) return t; } -/* shutr() called by the stream connector (mux_ops.shutr) */ -static void h2_shutr(struct stconn *sc, enum se_shut_mode mode) +static void h2_shut(struct stconn *sc, enum se_shut_mode mode) { struct h2s *h2s = __sc_mux_strm(sc); TRACE_ENTER(H2_EV_STRM_SHUT, h2s->h2c->conn, h2s); + if (mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) + h2_do_shutw(h2s); if (mode & SE_SHR_RESET) h2_do_shutr(h2s); TRACE_LEAVE(H2_EV_STRM_SHUT, h2s->h2c->conn, h2s); } -/* shutw() called by the stream connector (mux_ops.shutw) */ -static void h2_shutw(struct stconn *sc, enum se_shut_mode mode) -{ - struct h2s *h2s = __sc_mux_strm(sc); - - TRACE_ENTER(H2_EV_STRM_SHUT, h2s->h2c->conn, h2s); - h2_do_shutw(h2s); - TRACE_LEAVE(H2_EV_STRM_SHUT, h2s->h2c->conn, h2s); -} - /* Decode the payload of a HEADERS frame and produce the HTX request or response * depending on the connection's side. Returns a positive value on success, a * negative value on failure, or 0 if it couldn't proceed. May report connection @@ -7746,8 +7737,7 @@ static const struct mux_ops h2_ops = { .destroy = h2_destroy, .avail_streams = h2_avail_streams, .used_streams = h2_used_streams, - .shutr = h2_shutr, - .shutw = h2_shutw, + .shut = h2_shut, .ctl = h2_ctl, .sctl = h2_sctl, .show_fd = h2_show_fd, diff --git a/src/mux_pt.c b/src/mux_pt.c index 2e961abeb..7aa97d793 100644 --- a/src/mux_pt.c +++ b/src/mux_pt.c @@ -462,38 +462,30 @@ static int mux_pt_avail_streams(struct connection *conn) return 1 - mux_pt_used_streams(conn); } -static void mux_pt_shutr(struct stconn *sc, enum se_shut_mode mode) +static void mux_pt_shut(struct stconn *sc, enum se_shut_mode mode) { struct connection *conn = __sc_conn(sc); struct mux_pt_ctx *ctx = conn->ctx; TRACE_ENTER(PT_EV_STRM_SHUT, conn, sc); + if (mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) { + if (conn_xprt_ready(conn) && conn->xprt->shutw) + conn->xprt->shutw(conn, conn->xprt_ctx, (mode & SE_SHW_NORMAL)); + if (conn->flags & CO_FL_SOCK_RD_SH) + conn_full_close(conn); + else + conn_sock_shutw(conn, (mode & SE_SHW_NORMAL)); + } - se_fl_clr(ctx->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM); - if (conn_xprt_ready(conn) && conn->xprt->shutr) - conn->xprt->shutr(conn, conn->xprt_ctx, - (mode & SE_SHR_DRAIN)); - else if (mode & SE_SHR_DRAIN) - conn_ctrl_drain(conn); - if (conn->flags & CO_FL_SOCK_WR_SH) - conn_full_close(conn); - - TRACE_LEAVE(PT_EV_STRM_SHUT, conn, sc); -} - -static void mux_pt_shutw(struct stconn *sc, enum se_shut_mode mode) -{ - struct connection *conn = __sc_conn(sc); - - TRACE_ENTER(PT_EV_STRM_SHUT, conn, sc); - - if (conn_xprt_ready(conn) && conn->xprt->shutw) - conn->xprt->shutw(conn, conn->xprt_ctx, - (mode & SE_SHW_NORMAL)); - if (!(conn->flags & CO_FL_SOCK_RD_SH)) - conn_sock_shutw(conn, (mode & SE_SHW_NORMAL)); - else - conn_full_close(conn); + if (mode & (SE_SHR_RESET|SE_SHR_DRAIN)) { + se_fl_clr(ctx->sd, SE_FL_RCV_MORE | SE_FL_WANT_ROOM); + if (conn_xprt_ready(conn) && conn->xprt->shutr) + conn->xprt->shutr(conn, conn->xprt_ctx, (mode & SE_SHR_DRAIN)); + else if (mode & SE_SHR_DRAIN) + conn_ctrl_drain(conn); + if (conn->flags & CO_FL_SOCK_WR_SH) + conn_full_close(conn); + } TRACE_LEAVE(PT_EV_STRM_SHUT, conn, sc); } @@ -865,8 +857,7 @@ const struct mux_ops mux_tcp_ops = { .destroy = mux_pt_destroy_meth, .ctl = mux_pt_ctl, .sctl = mux_pt_sctl, - .shutr = mux_pt_shutr, - .shutw = mux_pt_shutw, + .shut = mux_pt_shut, .flags = MX_FL_NONE, .name = "PASS", }; @@ -891,8 +882,7 @@ const struct mux_ops mux_pt_ops = { .destroy = mux_pt_destroy_meth, .ctl = mux_pt_ctl, .sctl = mux_pt_sctl, - .shutr = mux_pt_shutr, - .shutw = mux_pt_shutw, + .shut = mux_pt_shut, .flags = MX_FL_NONE|MX_FL_NO_UPG, .name = "PASS", }; diff --git a/src/mux_quic.c b/src/mux_quic.c index 4e8038380..883ef01bb 100644 --- a/src/mux_quic.c +++ b/src/mux_quic.c @@ -3095,11 +3095,14 @@ static int qmux_wake(struct connection *conn) return 1; } -static void qmux_strm_shutw(struct stconn *sc, enum se_shut_mode mode) +static void qmux_strm_shut(struct stconn *sc, enum se_shut_mode mode) { struct qcs *qcs = __sc_mux_strm(sc); struct qcc *qcc = qcs->qcc; + if (!(mode & (SE_SHW_SILENT|SE_SHW_NORMAL))) + return; + TRACE_ENTER(QMUX_EV_STRM_SHUT, qcc->conn, qcs); /* Early closure reported if QC_SF_FIN_STREAM not yet set. */ @@ -3182,7 +3185,7 @@ static const struct mux_ops qmux_ops = { .subscribe = qmux_strm_subscribe, .unsubscribe = qmux_strm_unsubscribe, .wake = qmux_wake, - .shutw = qmux_strm_shutw, + .shut = qmux_strm_shut, .sctl = qmux_sctl, .show_sd = qmux_strm_show_sd, .flags = MX_FL_HTX|MX_FL_NO_UPG|MX_FL_FRAMED, diff --git a/src/stconn.c b/src/stconn.c index ca878436a..930b92b1b 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -140,17 +140,19 @@ void se_shutdown(struct sedesc *sedesc, enum se_shut_mode mode) { if (se_fl_test(sedesc, SE_FL_T_MUX)) { const struct mux_ops *mux = (sedesc->conn ? sedesc->conn->mux : NULL); + unsigned int flags = 0; - if ((mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) && !se_fl_test(sedesc, SE_FL_SHW)) { - if (mux && mux->shutw) - mux->shutw(sedesc->sc, mode); - se_fl_set(sedesc, (mode & SE_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS); - } + if ((mode & (SE_SHW_SILENT|SE_SHW_NORMAL)) && !se_fl_test(sedesc, SE_FL_SHW)) + flags |= (mode & SE_SHW_NORMAL) ? SE_FL_SHWN : SE_FL_SHWS; + + + if ((mode & (SE_SHR_RESET|SE_SHR_DRAIN)) && !se_fl_test(sedesc, SE_FL_SHR)) + flags |= (mode & SE_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR; - if ((mode & (SE_SHR_RESET|SE_SHR_DRAIN)) && !se_fl_test(sedesc, SE_FL_SHR)) { - if (mux && mux->shutr) - mux->shutr(sedesc->sc, mode); - se_fl_set(sedesc, (mode & SE_SHR_DRAIN) ? SE_FL_SHRD : SE_FL_SHRR); + if (flags) { + if (mux && mux->shut) + mux->shut(sedesc->sc, mode); + se_fl_set(sedesc, flags); } } else if (se_fl_test(sedesc, SE_FL_T_APPLET)) { -- 2.47.3