]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Use the CS to register and release applets instead of SI
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 1 Apr 2022 09:36:58 +0000 (11:36 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 13 Apr 2022 13:10:15 +0000 (15:10 +0200)
si_register_applet() and si_applet_release() are renamed
cs_register_applet() and cs_applet_release() and now manipulate a
conn-stream instead of a stream-inteface.

include/haproxy/conn_stream.h
include/haproxy/stream_interface.h
src/backend.c
src/cache.c
src/conn_stream.c
src/http_ana.c
src/stream.c
src/stream_interface.c

index 269d129f57e961e2a1369f67758fc34b907ac56a..bb1601cebe45dd9d27e5ad55360320ab1c421a6b 100644 (file)
@@ -54,6 +54,9 @@ int cs_reset_endp(struct conn_stream *cs);
 void cs_detach_endp(struct conn_stream *cs);
 void cs_detach_app(struct conn_stream *cs);
 
+struct appctx *cs_register_applet(struct conn_stream *cs, struct applet *app);
+void cs_applet_release(struct conn_stream *cs);
+
 /* Returns the endpoint target without any control */
 static inline void *__cs_endp_target(const struct conn_stream *cs)
 {
index cdc13200a76806d010b3e7cf5d8dba339a565830..93fffff9249e19ef0335289cf544b163b48076b2 100644 (file)
@@ -41,7 +41,6 @@ void si_free(struct stream_interface *si);
 
 /* main event functions used to move data between sockets and buffers */
 int conn_si_send_proxy(struct connection *conn, unsigned int flag);
-struct appctx *si_register_handler(struct stream_interface *si, struct applet *app);
 void si_applet_wake_cb(struct stream_interface *si);
 void si_update_rx(struct stream_interface *si);
 void si_update_tx(struct stream_interface *si);
@@ -110,16 +109,6 @@ static inline int si_init(struct stream_interface *si)
        return 0;
 }
 
-/* call the applet's release function if any. Needs to be called upon close() */
-static inline void si_applet_release(struct stream_interface *si)
-{
-       struct appctx *appctx;
-
-       appctx = __cs_appctx(si->cs);
-       if (appctx->applet->release && !cs_state_in(si->cs->state, CS_SB_DIS|CS_SB_CLO))
-               appctx->applet->release(appctx);
-}
-
 /* Returns non-zero if the stream interface's Rx path is blocked */
 static inline int si_rx_blocked(const struct stream_interface *si)
 {
index 8dc7d1a33d4fead32dc178b18a6f7044648c997a..8983e1d0109a328ebf1c46d58124c11fbec2ddf7 100644 (file)
@@ -2132,7 +2132,7 @@ void back_handle_st_req(struct stream *s)
                struct appctx *appctx = cs_appctx(s->csb);
 
                if (!appctx || appctx->applet != __objt_applet(s->target))
-                       appctx = si_register_handler(cs->si, objt_applet(s->target));
+                       appctx = cs_register_applet(cs, objt_applet(s->target));
 
                if (!appctx) {
                        /* No more memory, let's immediately abort. Force the
index ea3438e5ed540ed999ada6a4efd898064a201415..3e725c719b28e4ea269c673d8f378c20dfda7aac 100644 (file)
@@ -1816,7 +1816,7 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p
                }
 
                s->target = &http_cache_applet.obj_type;
-               if ((appctx = si_register_handler(cs_si(s->csb), objt_applet(s->target)))) {
+               if ((appctx = cs_register_applet(s->csb, objt_applet(s->target)))) {
                        appctx->st0 = HTX_CACHE_INIT;
                        appctx->rule = rule;
                        appctx->ctx.cache.entry = res;
index 2589dc148194125fbf05c7a1d5f9d1486eba3abd..b6b7dfded3b4e3ccf1202bdb66db1ca14aff21ae 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <haproxy/api.h>
+#include <haproxy/applet.h>
 #include <haproxy/connection.h>
 #include <haproxy/conn_stream.h>
 #include <haproxy/pool.h>
@@ -283,8 +284,7 @@ void cs_detach_endp(struct conn_stream *cs)
                struct appctx *appctx = cs_appctx(cs);
 
                cs->endp->flags |= CS_EP_ORPHAN;
-               if (cs->si)
-                       si_applet_release(cs->si);
+               cs_applet_release(cs);
                appctx_free(appctx);
                cs->endp = NULL;
        }
@@ -354,3 +354,36 @@ int cs_reset_endp(struct conn_stream *cs)
        cs->endp->flags |= CS_EP_DETACHED;
        return 0;
 }
+
+
+/* Register an applet to handle a conn-stream as a new appctx. The CS will
+ * wake it up every time it is solicited. The appctx must be deleted by the task
+ * handler using cs_detach_endp(), possibly from within the function itself.
+ * It also pre-initializes the applet's context and returns it (or NULL in case
+ * it could not be allocated).
+ */
+struct appctx *cs_register_applet(struct conn_stream *cs, struct applet *app)
+{
+       struct appctx *appctx;
+
+       DPRINTF(stderr, "registering handler %p for cs %p (was %p)\n", app, cs, cs_strm_task(cs));
+
+       appctx = appctx_new(app, cs->endp);
+       if (!appctx)
+               return NULL;
+       cs_attach_applet(cs, appctx, appctx);
+       appctx->owner = cs;
+       appctx->t->nice = __cs_strm(cs)->task->nice;
+       si_cant_get(cs->si);
+       appctx_wakeup(appctx);
+       return appctx;
+}
+
+/* call the applet's release function if any. Needs to be called upon close() */
+void cs_applet_release(struct conn_stream *cs)
+{
+       struct appctx *appctx = __cs_appctx(cs);
+
+       if (appctx->applet->release && !cs_state_in(cs->state, CS_SB_DIS|CS_SB_CLO))
+               appctx->applet->release(appctx);
+}
index 0a47f1b2e4533f937b67653f1bad792c9efdaf48..8147cf351ce7bbee4be00da5244dad6f0ee2345c 100644 (file)
@@ -423,7 +423,7 @@ int http_process_req_common(struct stream *s, struct channel *req, int an_bit, s
         */
        if (!s->target && http_stats_check_uri(s, txn, px)) {
                s->target = &http_stats_applet.obj_type;
-               if (unlikely(!si_register_handler(cs_si(s->csb), objt_applet(s->target)))) {
+               if (unlikely(!cs_register_applet(s->csb, objt_applet(s->target)))) {
                        s->logs.tv_request = now;
                        if (!(s->flags & SF_ERR_MASK))
                                s->flags |= SF_ERR_RESOURCE;
index bf0895a67f4ac39768a0c006e9f041067760eb56..44ed445ef5179aa77a38eb87ff45206b84c78bc3 100644 (file)
@@ -1012,7 +1012,7 @@ enum act_return process_use_service(struct act_rule *rule, struct proxy *px,
        if (flags & ACT_OPT_FIRST) {
                /* Register applet. this function schedules the applet. */
                s->target = &rule->applet.obj_type;
-               appctx = si_register_handler(cs_si(s->csb), objt_applet(s->target));
+               appctx = cs_register_applet(s->csb, objt_applet(s->target));
                if (unlikely(!appctx))
                        return ACT_RET_ERR;
 
index 7b94812673cfccb512f2efc58987afacadb003eb..85e2b6190db7ea8d6c8768847b823869fd4808b5 100644 (file)
@@ -269,29 +269,6 @@ static void cs_app_chk_snd(struct conn_stream *cs)
                task_wakeup(cs_strm_task(cs), TASK_WOKEN_IO);
 }
 
-/* Register an applet to handle a stream_interface as a new appctx. The SI will
- * wake it up every time it is solicited. The appctx must be deleted by the task
- * handler using si_release_endpoint(), possibly from within the function itself.
- * It also pre-initializes the applet's context and returns it (or NULL in case
- * it could not be allocated).
- */
-struct appctx *si_register_handler(struct stream_interface *si, struct applet *app)
-{
-       struct appctx *appctx;
-
-       DPRINTF(stderr, "registering handler %p for si %p (was %p)\n", app, si, si_task(si));
-
-       appctx = appctx_new(app, si->cs->endp);
-       if (!appctx)
-               return NULL;
-       cs_attach_applet(si->cs, appctx, appctx);
-       appctx->owner = si->cs;
-       appctx->t->nice = si_strm(si)->task->nice;
-       si_cant_get(si);
-       appctx_wakeup(appctx);
-       return appctx;
-}
-
 /* This callback is used to send a valid PROXY protocol line to a socket being
  * established. It returns 0 if it fails in a fatal way or needs to poll to go
  * further, otherwise it returns non-zero and removes itself from the connection's
@@ -1655,7 +1632,7 @@ static void cs_app_shutr_applet(struct conn_stream *cs)
                return;
 
        if (cs_oc(cs)->flags & CF_SHUTW) {
-               si_applet_release(cs->si);
+               cs_applet_release(cs);
                cs->state = CS_ST_DIS;
                __cs_strm(cs)->conn_exp = TICK_ETERNITY;
        }
@@ -1713,7 +1690,7 @@ static void cs_app_shutw_applet(struct conn_stream *cs)
        case CS_ST_QUE:
        case CS_ST_TAR:
                /* Note that none of these states may happen with applets */
-               si_applet_release(cs->si);
+               cs_applet_release(cs);
                cs->state = CS_ST_DIS;
                /* fall through */
        default: