MINOR: ring: allow to reduce a ring size

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.
This commit is contained in:
Willy Tarreau 2024-03-14 06:48:41 +01:00
parent 0fa05ce171
commit 4e6de42b27
2 changed files with 6 additions and 7 deletions

View 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);

View 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;
}