mirror of
http://git.haproxy.org/git/haproxy.git
synced 2026-02-18 00:06:47 +02:00
MAJOR: ring: insert an intermediary ring_storage level
We'll need to add more complex structures in the ring, such as wait queues. That's far too much to be stored into the area in case of file-backed contents, so let's split the ring definition and its storage once for all. This patch introduces a struct ring_storage which is assigned to ring->storage, which contains minimal information to represent the storage layout, i.e. for now only the buffer, and all the rest remains in the ring itself. The storage is appended immediately after it and the buffer's pointer always points to that area. It has the benefit of remaining 100% compatible with the existing file-backed layout. In memory, the allocation loses the size of a struct buffer. It's not even certain it's worth placing the size there, given that it's constant and that a dump of a ring wouldn't really need it (the file size is sufficient). But for now everything comes with the struct buffer, and later this will change once split into head and tail. Also this area may be completed with more information in the future (e.g. storage version, format, endianness, word size etc).
This commit is contained in:
@@ -103,9 +103,16 @@
|
||||
#define RING_WRITING_SIZE 255 /* the next message's size is being written */
|
||||
#define RING_MAX_READERS 254 /* highest supported value for RC */
|
||||
|
||||
/* this is the mmapped part */
|
||||
struct ring_storage {
|
||||
struct buffer buf; // storage layout
|
||||
char area[0]; // storage area begins immediately here
|
||||
};
|
||||
|
||||
/* this is the ring definition, config, waiters etc */
|
||||
struct ring {
|
||||
struct buffer buf; // storage area
|
||||
struct list waiters; // list of waiters, for now, CLI "show event"
|
||||
struct ring_storage *storage; // the mapped part
|
||||
struct list waiters; // list of waiters, for now, CLI "show event"
|
||||
__decl_thread(HA_RWLOCK_T lock);
|
||||
int readers_count;
|
||||
uint flags; // RING_FL_*
|
||||
|
||||
@@ -29,9 +29,8 @@
|
||||
struct appctx;
|
||||
|
||||
struct ring *ring_new(size_t size);
|
||||
struct ring *ring_make_from_area(void *area, size_t size);
|
||||
struct ring *ring_cast_from_area(void *area);
|
||||
void ring_init(struct ring *ring, void* area, size_t size);
|
||||
struct ring *ring_make_from_area(void *area, size_t size, int reset);
|
||||
void ring_init(struct ring *ring, void *area, size_t size, int reset);
|
||||
struct ring *ring_resize(struct ring *ring, size_t size);
|
||||
void ring_free(struct ring *ring);
|
||||
ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], size_t npfx, const struct ist msg[], size_t nmsg);
|
||||
@@ -48,31 +47,31 @@ int ring_dispatch_messages(struct ring *ring, void *ctx, size_t *ofs_ptr, size_t
|
||||
/* returns the ring storage's area */
|
||||
static inline void *ring_area(const struct ring *ring)
|
||||
{
|
||||
return b_orig(&ring->buf);
|
||||
return b_orig(&ring->storage->buf);
|
||||
}
|
||||
|
||||
/* returns the number of bytes in the ring */
|
||||
static inline size_t ring_data(const struct ring *ring)
|
||||
{
|
||||
return b_data(&ring->buf);
|
||||
return b_data(&ring->storage->buf);
|
||||
}
|
||||
|
||||
/* returns the allocated size in bytes for the ring */
|
||||
static inline size_t ring_size(const struct ring *ring)
|
||||
{
|
||||
return b_size(&ring->buf);
|
||||
return b_size(&ring->storage->buf);
|
||||
}
|
||||
|
||||
/* returns the head offset of the ring */
|
||||
static inline size_t ring_head(const struct ring *ring)
|
||||
{
|
||||
return b_head_ofs(&ring->buf);
|
||||
return b_head_ofs(&ring->storage->buf);
|
||||
}
|
||||
|
||||
/* returns the tail offset of the ring */
|
||||
static inline size_t ring_tail(const struct ring *ring)
|
||||
{
|
||||
return b_tail_ofs(&ring->buf);
|
||||
return b_tail_ofs(&ring->storage->buf);
|
||||
}
|
||||
|
||||
/* duplicates ring <src> over ring <dst> for no more than <max> bytes or no
|
||||
@@ -85,8 +84,8 @@ static inline size_t ring_dup(struct ring *dst, const struct ring *src, size_t m
|
||||
if (max > ring_data(src))
|
||||
max = ring_data(src);
|
||||
|
||||
b_reset(&dst->buf);
|
||||
b_ncat(&dst->buf, &src->buf, max);
|
||||
b_reset(&dst->storage->buf);
|
||||
b_ncat(&dst->storage->buf, &src->storage->buf, max);
|
||||
return max;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user