]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: logs: clarify the check of the log range
authorWilly Tarreau <w@1wt.eu>
Wed, 20 Sep 2023 18:13:20 +0000 (20:13 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 20 Sep 2023 19:38:33 +0000 (21:38 +0200)
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.

include/haproxy/log.h
src/log.c

index 4c7b455eadc69526192d17f13c9e7085ec726538..16cc671504070a0959ace32b2ece92dece12d504 100644 (file)
@@ -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 <idx> index numbered from 0 is in <rg> 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).
  */
index b899ad511d3d27877cef04689e7eb972420bf63c..3d9e390410c5e06cec7022eb0a0ee156fadd0578 100644 (file)
--- 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)