]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: ring: allow to reduce a ring size
authorWilly Tarreau <w@1wt.eu>
Thu, 14 Mar 2024 05:48:41 +0000 (06:48 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 25 Mar 2024 17:34:19 +0000 (17:34 +0000)
In ring_resize() we used to check if the new ring was at least as large
as the previous one before resizing it, but what counts is that it's as
large as the previous one's contents. Initially it was thought this
would not really matter, but given that rings are initially created as
BUFSIZE, it's currently not possible to shrink them for debugging
purposes. Now with this change it is.

src/ring.c
src/sink.c

index c2668afeca31ed37a0818bdd56c6a2df63780a58..6abbe2caff1e36500539b4b770508bc3c215dbf9 100644 (file)
@@ -115,7 +115,7 @@ struct ring *ring_resize(struct ring *ring, size_t size)
 {
        struct ring_storage *new;
 
-       if (size <= ring_size(ring) + sizeof(*ring->storage))
+       if (size <= ring_data(ring) + sizeof(*ring->storage))
                return ring;
 
        new = malloc(size);
@@ -124,9 +124,8 @@ struct ring *ring_resize(struct ring *ring, size_t size)
 
        thread_isolate();
 
-       /* recheck the buffer's size, it may have changed during the malloc */
-
-       if (size > ring_size(ring) + sizeof(*ring->storage)) {
+       /* recheck the ring's size, it may have changed during the malloc */
+       if (size > ring_data(ring) + sizeof(*ring->storage)) {
                /* copy old contents */
                new->buf = b_make(new->area, size - sizeof(*ring->storage), 0, 0);
                b_getblk(&ring->storage->buf, new->area, ring_data(ring), 0);
index 897f6766f41b4a4c601606f0d0a31e89bb0f0533..7225ddd7f59ab5de7974644bf655012fd3d3ac66 100644 (file)
@@ -907,9 +907,9 @@ int cfg_parse_ring(const char *file, int linenum, char **args, int kwm)
                        goto err;
                }
 
-               if (size < ring_size(cfg_sink->ctx.ring)) {
-                       ha_warning("parsing [%s:%d] : ignoring new size '%llu' that is smaller than current size '%llu' for ring '%s'.\n",
-                                  file, linenum, (ullong)size, (ullong)ring_size(cfg_sink->ctx.ring), cfg_sink->name);
+               if (size < ring_data(cfg_sink->ctx.ring)) {
+                       ha_warning("parsing [%s:%d] : ignoring new size '%llu' that is smaller than contents '%llu' for ring '%s'.\n",
+                                  file, linenum, (ullong)size, (ullong)ring_data(cfg_sink->ctx.ring), cfg_sink->name);
                        err_code |= ERR_WARN;
                        goto err;
                }