From: Willy Tarreau Date: Wed, 20 Sep 2023 18:13:20 +0000 (+0200) Subject: MINOR: logs: clarify the check of the log range X-Git-Tag: v2.9-dev6~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4351364700fb704f57e9787ea14a91a03f5c6262;p=thirdparty%2Fhaproxy.git MINOR: logs: clarify the check of the log range The test of the log range is not very clear, in part due to the reuse of the "curr_idx" name that happens at two levels. The call to in_smp_log_range() applies to the smp_info's index to which 1 is added: it verifies that the next index is still within the current range. Let's just have a local variable "next_index" in process_send_log() that gets assigned the next index (current+1) and compare it to the current range's boundaries. This makes the test much clearer. We can then simply remove in_smp_log_range() that's no longer needed. --- diff --git a/include/haproxy/log.h b/include/haproxy/log.h index 4c7b455ead..16cc671504 100644 --- a/include/haproxy/log.h +++ b/include/haproxy/log.h @@ -155,17 +155,6 @@ char *update_log_hdr(const time_t time); char * get_format_pid_sep1(int format, size_t *len); char * get_format_pid_sep2(int format, size_t *len); -/* - * Test if index numbered from 0 is in range with low and high - * limits of indexes numbered from 1. - */ -static inline int in_smp_log_range(struct smp_log_range *rg, unsigned int idx) -{ - if (idx + 1 <= rg->high && idx + 1 >= rg->low) - return 1; - return 0; -} - /* * Builds a log line for the stream (must be valid). */ diff --git a/src/log.c b/src/log.c index b899ad511d..3d9e390410 100644 --- a/src/log.c +++ b/src/log.c @@ -1831,10 +1831,14 @@ void process_send_log(struct list *logsrvs, int level, int facility, if (logsrv->lb.smp_rgs) { struct smp_log_range *curr_rg; + unsigned int next_idx; HA_SPIN_LOCK(LOGSRV_LOCK, &logsrv->lock); + next_idx = logsrv->lb.curr_idx + 1; curr_rg = &logsrv->lb.smp_rgs[logsrv->lb.curr_rg]; - in_range = in_smp_log_range(curr_rg, logsrv->lb.curr_idx); + + /* check if the index we're going to take is within range */ + in_range = curr_rg->low <= next_idx && next_idx <= curr_rg->high; if (in_range) { /* Let's consume this range. */ curr_rg->curr_idx = (curr_rg->curr_idx + 1) % curr_rg->sz; @@ -1843,7 +1847,7 @@ void process_send_log(struct list *logsrvs, int level, int facility, logsrv->lb.curr_rg = (logsrv->lb.curr_rg + 1) % logsrv->lb.smp_rgs_sz; } } - logsrv->lb.curr_idx = (logsrv->lb.curr_idx + 1) % logsrv->lb.smp_sz; + logsrv->lb.curr_idx = next_idx % logsrv->lb.smp_sz; HA_SPIN_UNLOCK(LOGSRV_LOCK, &logsrv->lock); } if (in_range)