]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: adopt the wait list entry from the CLI
authorWilly Tarreau <w@1wt.eu>
Tue, 19 May 2020 15:07:30 +0000 (17:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 19 May 2020 17:37:12 +0000 (19:37 +0200)
A few fields, including a generic list entry, were added to the CLI context
by commit 300decc8d9 ("MINOR: cli: extend the CLI context with a list and
two offsets"). It turns out that the list entry (l0) is solely used to
consult rings and that the generic ring_write() code is restricted to a
consumer on the CLI due to this, which was not the initial intent. Let's
make it a general purpose wait_entry field that is properly initialized
during appctx_init(). This will allow any applet to wait on a ring, not
just the CLI.

include/proto/applet.h
include/types/applet.h
src/cli.c
src/ring.c

index 31b4d902522694fa3534d251c5a49fd6a25c6d14..14fbca2a12c866fede9747bc1ca16de4ef94655a 100644 (file)
@@ -53,6 +53,7 @@ static inline void appctx_init(struct appctx *appctx, unsigned long thread_mask)
        appctx->call_rate.curr_ctr = 0;
        appctx->call_rate.prev_ctr = 0;
        appctx->state = 0;
+       LIST_INIT(&appctx->wait_entry);
 }
 
 /* Tries to allocate a new appctx and initialize its main fields. The appctx
index b990726f7c9b0a43bf9d78c48953ec3c1caa625e..013c5023d177a92dee1b7269eec569bbad999323 100644 (file)
@@ -73,6 +73,7 @@ struct appctx {
        unsigned long thread_mask;      /* mask of thread IDs authorized to process the applet */
        struct task *t;                  /* task associated to the applet */
        struct freq_ctr call_rate;       /* appctx call rate */
+       struct list wait_entry;          /* entry in a list of waiters for an event (e.g. ring events) */
 
        union {
                struct {
@@ -105,7 +106,6 @@ struct appctx {
                        const char *msg;        /* pointer to a persistent message to be returned in CLI_ST_PRINT state */
                        int severity;           /* severity of the message to be returned according to (syslog) rfc5424 */
                        char *err;              /* pointer to a 'must free' message to be returned in CLI_ST_PRINT_FREE state */
-                       struct list l0;         /* General purpose list element, pointers, offsets and integers for... */
                        void *p0, *p1, *p2;     /* ...registered commands, initialized to 0 by the CLI before first... */
                        size_t o0, o1;          /* ...invocation of the keyword parser, except for the list element which... */
                        int i0, i1;             /* ...is initialized with LIST_INIT(). */
index af178110414f78b238c4232715c68b1a7c9bbeb0..a083ae7f6ab1733bb4b857b392218d1ecdea7466 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -500,7 +500,6 @@ static int cli_parse_request(struct appctx *appctx)
 
        appctx->st2 = 0;
        memset(&appctx->ctx.cli, 0, sizeof(appctx->ctx.cli));
-       LIST_INIT(&appctx->ctx.cli.l0);
 
        p = appctx->chunk->area;
        end = p + appctx->chunk->data;
index ec0656fbcf2a442ed6346ce27066f248c13d55d0..48003b38bc01d2b28e496a83e977cec34dd55bbf 100644 (file)
@@ -191,7 +191,7 @@ ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], siz
        sent = lenlen + totlen + 1;
 
        /* notify potential readers */
-       list_for_each_entry(appctx, &ring->waiters, ctx.cli.l0)
+       list_for_each_entry(appctx, &ring->waiters, wait_entry)
                appctx_wakeup(appctx);
 
  done_buf:
@@ -249,7 +249,7 @@ int cli_io_handler_show_ring(struct appctx *appctx)
                return 1;
 
        HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
-       LIST_DEL_INIT(&appctx->ctx.cli.l0);
+       LIST_DEL_INIT(&appctx->wait_entry);
        HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
 
        HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock);
@@ -324,7 +324,7 @@ int cli_io_handler_show_ring(struct appctx *appctx)
                if (!si_oc(si)->output && !(si_oc(si)->flags & CF_SHUTW)) {
                        /* let's be woken up once new data arrive */
                        HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock);
-                       LIST_ADDQ(&ring->waiters, &appctx->ctx.cli.l0);
+                       LIST_ADDQ(&ring->waiters, &appctx->wait_entry);
                        HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock);
                        si_rx_endp_done(si);
                        ret = 0;
@@ -349,7 +349,7 @@ void cli_io_release_show_ring(struct appctx *appctx)
                /* reader was still attached */
                ofs -= ring->ofs;
                BUG_ON(ofs >= b_size(&ring->buf));
-               LIST_DEL_INIT(&appctx->ctx.cli.l0);
+               LIST_DEL_INIT(&appctx->wait_entry);
                HA_ATOMIC_SUB(b_peek(&ring->buf, ofs), 1);
        }
        HA_ATOMIC_SUB(&ring->readers_count, 1);