From cbbee154629d584b7af490c4ee3c317884578414 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 20 Sep 2023 20:42:07 +0200 Subject: [PATCH] CLEANUP: ring: rename the ring lock "RING_LOCK" instead of "LOGSRV_LOCK" The ring lock was initially mostly used for the logs and used to inherit its name in lock stats. Now that it's exclusively used by rings, let's rename it accordingly. --- dev/haring/haring.c | 4 ++-- include/haproxy/sink.h | 8 ++++---- include/haproxy/thread.h | 2 +- src/ring.c | 24 ++++++++++++------------ src/sink.c | 28 ++++++++++++++-------------- src/thread.c | 2 +- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/dev/haring/haring.c b/dev/haring/haring.c index df455be735..ee7e1aa4e7 100644 --- a/dev/haring/haring.c +++ b/dev/haring/haring.c @@ -131,7 +131,7 @@ int dump_ring(struct ring *ring, size_t ofs, int flags) } while (1) { - //HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock); + //HA_RWLOCK_RDLOCK(RING_LOCK, &ring->lock); if (ofs >= buf.size) { fprintf(stderr, "FATAL error at %d\n", __LINE__); @@ -199,7 +199,7 @@ int dump_ring(struct ring *ring, size_t ofs, int flags) } //HA_ATOMIC_INC(b_peek(&buf, ofs)); - //HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock); + //HA_RWLOCK_RDUNLOCK(RING_LOCK, &ring->lock); if (!(flags & RING_WF_WAIT_MODE)) break; diff --git a/include/haproxy/sink.h b/include/haproxy/sink.h index 50f82b1c54..59d4b1cafa 100644 --- a/include/haproxy/sink.h +++ b/include/haproxy/sink.h @@ -58,9 +58,9 @@ static inline ssize_t sink_write(struct sink *sink, size_t maxlen, * so that the dropped event arrives exactly at the right * position. */ - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &sink->ctx.lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &sink->ctx.lock); sent = sink_announce_dropped(sink, facility); - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &sink->ctx.lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &sink->ctx.lock); if (!sent) { /* we failed, we don't try to send our log as if it @@ -70,9 +70,9 @@ static inline ssize_t sink_write(struct sink *sink, size_t maxlen, } } - HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &sink->ctx.lock); + HA_RWLOCK_RDLOCK(RING_LOCK, &sink->ctx.lock); sent = __sink_write(sink, maxlen, msg, nmsg, level, facility, metadata); - HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &sink->ctx.lock); + HA_RWLOCK_RDUNLOCK(RING_LOCK, &sink->ctx.lock); fail: if (unlikely(sent <= 0)) diff --git a/include/haproxy/thread.h b/include/haproxy/thread.h index df3c17bc37..b2e60147fc 100644 --- a/include/haproxy/thread.h +++ b/include/haproxy/thread.h @@ -417,7 +417,7 @@ enum lock_label { PIPES_LOCK, TLSKEYS_REF_LOCK, AUTH_LOCK, - LOGSRV_LOCK, + RING_LOCK, DICT_LOCK, PROTO_LOCK, QUEUE_LOCK, diff --git a/src/ring.c b/src/ring.c index 9b8863afe3..06b2cbafc0 100644 --- a/src/ring.c +++ b/src/ring.c @@ -133,7 +133,7 @@ struct ring *ring_resize(struct ring *ring, size_t size) if (!area) return NULL; - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock); /* recheck the buffer's size, it may have changed during the malloc */ if (b_size(&ring->buf) < size) { @@ -143,7 +143,7 @@ struct ring *ring_resize(struct ring *ring, size_t size) ring->buf.size = size; } - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock); free(area); return ring; @@ -200,7 +200,7 @@ ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], siz lenlen = varint_bytes(totlen); - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock); if (lenlen + totlen + 1 + 1 > b_size(buf)) goto done_buf; @@ -254,7 +254,7 @@ ssize_t ring_write(struct ring *ring, size_t maxlen, const struct ist pfx[], siz appctx_wakeup(appctx); done_buf: - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock); return sent; } @@ -285,7 +285,7 @@ void ring_detach_appctx(struct ring *ring, struct appctx *appctx, size_t ofs) if (!ring) return; - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock); if (ofs != ~0) { /* reader was still attached */ if (ofs < b_head_ofs(&ring->buf)) @@ -298,7 +298,7 @@ void ring_detach_appctx(struct ring *ring, struct appctx *appctx, size_t ofs) HA_ATOMIC_DEC(b_peek(&ring->buf, ofs)); } HA_ATOMIC_DEC(&ring->readers_count); - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock); } /* Tries to attach CLI handler as a new reader on ring . This is @@ -353,11 +353,11 @@ int cli_io_handler_show_ring(struct appctx *appctx) if (unlikely(sc_opposite(sc)->flags & SC_FL_SHUT_DONE)) return 1; - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock); LIST_DEL_INIT(&appctx->wait_entry); - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock); - HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_RDLOCK(RING_LOCK, &ring->lock); /* explanation for the initialization below: it would be better to do * this in the parsing function but this would occasionally result in @@ -417,7 +417,7 @@ int cli_io_handler_show_ring(struct appctx *appctx) HA_ATOMIC_INC(b_peek(buf, ofs)); last_ofs = b_tail_ofs(buf); ctx->ofs = b_peek_ofs(buf, ofs); - HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_RDUNLOCK(RING_LOCK, &ring->lock); if (ret && (ctx->flags & RING_WF_WAIT_MODE)) { /* we've drained everything and are configured to wait for more @@ -425,10 +425,10 @@ int cli_io_handler_show_ring(struct appctx *appctx) */ if (!sc_oc(sc)->output && !(sc->flags & SC_FL_SHUT_DONE)) { /* let's be woken up once new data arrive */ - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock); LIST_APPEND(&ring->waiters, &appctx->wait_entry); ofs = b_tail_ofs(&ring->buf); - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock); if (ofs != last_ofs) { /* more data was added into the ring between the * unlock and the lock, and the writer might not diff --git a/src/sink.c b/src/sink.c index 46fc965dc1..8c03e68a54 100644 --- a/src/sink.c +++ b/src/sink.c @@ -346,11 +346,11 @@ static void sink_forward_io_handler(struct appctx *appctx) goto close; } - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock); LIST_DEL_INIT(&appctx->wait_entry); - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock); - HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_RDLOCK(RING_LOCK, &ring->lock); /* explanation for the initialization below: it would be better to do * this in the parsing function but this would occasionally result in @@ -409,14 +409,14 @@ static void sink_forward_io_handler(struct appctx *appctx) last_ofs = b_tail_ofs(buf); sft->ofs = b_peek_ofs(buf, ofs); - HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_RDUNLOCK(RING_LOCK, &ring->lock); if (ret) { /* let's be woken up once new data arrive */ - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock); LIST_APPEND(&ring->waiters, &appctx->wait_entry); ofs = b_tail_ofs(buf); - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock); if (ofs != last_ofs) { /* more data was added into the ring between the * unlock and the lock, and the writer might not @@ -478,11 +478,11 @@ static void sink_forward_oc_io_handler(struct appctx *appctx) goto close; } - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock); LIST_DEL_INIT(&appctx->wait_entry); - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock); - HA_RWLOCK_RDLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_RDLOCK(RING_LOCK, &ring->lock); /* explanation for the initialization below: it would be better to do * this in the parsing function but this would occasionally result in @@ -544,13 +544,13 @@ static void sink_forward_oc_io_handler(struct appctx *appctx) HA_ATOMIC_INC(b_peek(buf, ofs)); sft->ofs = b_peek_ofs(buf, ofs); - HA_RWLOCK_RDUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_RDUNLOCK(RING_LOCK, &ring->lock); if (ret) { /* let's be woken up once new data arrive */ - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &ring->lock); LIST_APPEND(&ring->waiters, &appctx->wait_entry); - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &ring->lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &ring->lock); applet_have_no_more_data(appctx); } HA_SPIN_UNLOCK(SFT_LOCK, &sft->lock); @@ -574,9 +574,9 @@ void __sink_forward_session_deinit(struct sink_forward_target *sft) if (!sink) return; - HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock); + HA_RWLOCK_WRLOCK(RING_LOCK, &sink->ctx.ring->lock); LIST_DEL_INIT(&sft->appctx->wait_entry); - HA_RWLOCK_WRUNLOCK(LOGSRV_LOCK, &sink->ctx.ring->lock); + HA_RWLOCK_WRUNLOCK(RING_LOCK, &sink->ctx.ring->lock); sft->appctx = NULL; task_wakeup(sink->forward_task, TASK_WOKEN_MSG); diff --git a/src/thread.c b/src/thread.c index 6c3eddd366..cabc754171 100644 --- a/src/thread.c +++ b/src/thread.c @@ -450,7 +450,7 @@ static const char *lock_label(enum lock_label label) case PIPES_LOCK: return "PIPES"; case TLSKEYS_REF_LOCK: return "TLSKEYS_REF"; case AUTH_LOCK: return "AUTH"; - case LOGSRV_LOCK: return "LOGSRV"; + case RING_LOCK: return "RING"; case DICT_LOCK: return "DICT"; case PROTO_LOCK: return "PROTO"; case QUEUE_LOCK: return "QUEUE";