From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id EAAF75A026F for ; Wed, 20 Dec 2023 08:09:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1703056152; bh=7+yS6Or2QKEofdBlR+wjkA2js0Aab4Ym4mEckV6h2Ik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YVYRLgFwsVbssksfWvl9T9xnJohfKT7giD0Ti2Bh/vwgTwUwSzaA2NXn3xAD6n4U4 Gr1IQZXgXXnjrgcw/9BMDP6SB0PDQdOs5FpPkvJ03/0HATd7pRirSRxtiWSWK5b7qG W4d3E+innOauB6Glpnu2vhRO3lUcUALVGVtCWQ4se/2xXn1bMJxijre9P8+Npfpl+X jdqol4z8fRbyyqeIxKB663KcfbZCUwTdBiRhBfudV7qfi/ADBmKKTfSoXhIsvM76mv UoZEb37o2DAlJQdXnpei+B3SDorpzolenNmlIVCsU1HGXQVztAhtzgJGgRYySJEf57 8SUF+ZcfVlrWg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Sw4Rr1gd0z4x1v; Wed, 20 Dec 2023 18:09:12 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 02/13] treewide: Standardise on 'now' for current timestamp variables Date: Wed, 20 Dec 2023 18:08:57 +1100 Message-ID: <20231220070908.2506277-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231220070908.2506277-1-david@gibson.dropbear.id.au> References: <20231220070908.2506277-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: O7A4LZMO5DFRVP2OSX2FFX4FAUW7SYAM X-Message-ID-Hash: O7A4LZMO5DFRVP2OSX2FFX4FAUW7SYAM X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In a number of places we pass around a struct timespec representing the (more or less) current time. Sometimes we call it 'now', and sometimes we call it 'ts'. Standardise on the more informative 'now'. Signed-off-by: David Gibson --- icmp.c | 12 ++++++------ icmp.h | 2 +- log.c | 34 +++++++++++++++++----------------- tcp.c | 6 +++--- tcp.h | 2 +- udp.c | 16 ++++++++-------- udp.h | 2 +- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/icmp.c b/icmp.c index a1de8ae..a9fbcb2 100644 --- a/icmp.c +++ b/icmp.c @@ -290,14 +290,14 @@ fail_sock: * @c: Execution context * @v6: Set for IPv6 echo identifier bindings * @id: Echo identifier, host order - * @ts: Timestamp from caller + * @now: Current timestamp */ static void icmp_timer_one(const struct ctx *c, int v6, uint16_t id, - const struct timespec *ts) + const struct timespec *now) { struct icmp_id_sock *id_map = &icmp_id_map[v6 ? V6 : V4][id]; - if (ts->tv_sec - id_map->ts <= ICMP_ECHO_TIMEOUT) + if (now->tv_sec - id_map->ts <= ICMP_ECHO_TIMEOUT) return; bitmap_clear(icmp_act[v6 ? V6 : V4], id); @@ -311,9 +311,9 @@ static void icmp_timer_one(const struct ctx *c, int v6, uint16_t id, /** * icmp_timer() - Scan activity bitmap for identifiers with timed events * @c: Execution context - * @ts: Timestamp from caller + * @now: Current timestamp */ -void icmp_timer(const struct ctx *c, const struct timespec *ts) +void icmp_timer(const struct ctx *c, const struct timespec *now) { long *word, tmp; unsigned int i; @@ -325,7 +325,7 @@ v6: tmp = *word; while ((n = ffsl(tmp))) { tmp &= ~(1UL << (n - 1)); - icmp_timer_one(c, v6, i * 8 + n - 1, ts); + icmp_timer_one(c, v6, i * 8 + n - 1, now); } } diff --git a/icmp.h b/icmp.h index 44cc495..1a08594 100644 --- a/icmp.h +++ b/icmp.h @@ -15,7 +15,7 @@ void icmpv6_sock_handler(const struct ctx *c, union epoll_ref ref); int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af, const void *saddr, const void *daddr, const struct pool *p, const struct timespec *now); -void icmp_timer(const struct ctx *c, const struct timespec *ts); +void icmp_timer(const struct ctx *c, const struct timespec *now); void icmp_init(void); /** diff --git a/log.c b/log.c index b206f72..d7f6d35 100644 --- a/log.c +++ b/log.c @@ -216,11 +216,11 @@ void logfile_init(const char *name, const char *path, size_t size) /** * logfile_rotate_fallocate() - Write header, set log_written after fallocate() * @fd: Log file descriptor - * @ts: Current timestamp + * @now: Current timestamp * * #syscalls lseek ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek */ -static void logfile_rotate_fallocate(int fd, const struct timespec *ts) +static void logfile_rotate_fallocate(int fd, const struct timespec *now) { char buf[BUFSIZ], *nl; int n; @@ -232,8 +232,8 @@ static void logfile_rotate_fallocate(int fd, const struct timespec *ts) n = snprintf(buf, BUFSIZ, "%s - log truncated at %lli.%04lli", log_header, - (long long int)(ts->tv_sec - log_start), - (long long int)(ts->tv_nsec / (100L * 1000))); + (long long int)(now->tv_sec - log_start), + (long long int)(now->tv_nsec / (100L * 1000))); /* Avoid partial lines by padding the header with spaces */ nl = memchr(buf + n + 1, '\n', BUFSIZ - n - 1); @@ -252,20 +252,20 @@ static void logfile_rotate_fallocate(int fd, const struct timespec *ts) /** * logfile_rotate_move() - Fallback: move recent entries toward start, then cut * @fd: Log file descriptor - * @ts: Current timestamp + * @now: Current timestamp * * #syscalls lseek ppc64le:_llseek ppc64:_llseek armv6l:_llseek armv7l:_llseek * #syscalls ftruncate */ -static void logfile_rotate_move(int fd, const struct timespec *ts) +static void logfile_rotate_move(int fd, const struct timespec *now) { int header_len, write_offset, end, discard, n; char buf[BUFSIZ], *nl; header_len = snprintf(buf, BUFSIZ, "%s - log truncated at %lli.%04lli\n", log_header, - (long long int)(ts->tv_sec - log_start), - (long long int)(ts->tv_nsec / (100L * 1000))); + (long long int)(now->tv_sec - log_start), + (long long int)(now->tv_nsec / (100L * 1000))); if (lseek(fd, 0, SEEK_SET) == -1) return; if (write(fd, buf, header_len) == -1) @@ -314,7 +314,7 @@ out: /** * logfile_rotate() - "Rotate" log file once it's full * @fd: Log file descriptor - * @ts: Current timestamp + * @now: Current timestamp * * Return: 0 on success, negative error code on failure * @@ -322,7 +322,7 @@ out: * * fallocate() passed as EXTRA_SYSCALL only if FALLOC_FL_COLLAPSE_RANGE is there */ -static int logfile_rotate(int fd, const struct timespec *ts) +static int logfile_rotate(int fd, const struct timespec *now) { if (fcntl(fd, F_SETFL, O_RDWR /* Drop O_APPEND: explicit lseek() */)) return -errno; @@ -330,10 +330,10 @@ static int logfile_rotate(int fd, const struct timespec *ts) #ifdef FALLOC_FL_COLLAPSE_RANGE /* Only for Linux >= 3.15, extent-based ext4 or XFS, glibc >= 2.18 */ if (!fallocate(fd, FALLOC_FL_COLLAPSE_RANGE, 0, log_cut_size)) - logfile_rotate_fallocate(fd, ts); + logfile_rotate_fallocate(fd, now); else #endif - logfile_rotate_move(fd, ts); + logfile_rotate_move(fd, now); if (fcntl(fd, F_SETFL, O_RDWR | O_APPEND)) return -errno; @@ -349,16 +349,16 @@ static int logfile_rotate(int fd, const struct timespec *ts) */ void logfile_write(int pri, const char *format, va_list ap) { - struct timespec ts; + struct timespec now; char buf[BUFSIZ]; int n; - if (clock_gettime(CLOCK_REALTIME, &ts)) + if (clock_gettime(CLOCK_REALTIME, &now)) return; n = snprintf(buf, BUFSIZ, "%lli.%04lli: %s", - (long long int)(ts.tv_sec - log_start), - (long long int)(ts.tv_nsec / (100L * 1000)), + (long long int)(now.tv_sec - log_start), + (long long int)(now.tv_nsec / (100L * 1000)), logfile_prefix[pri]); n += vsnprintf(buf + n, BUFSIZ - n, format, ap); @@ -366,7 +366,7 @@ void logfile_write(int pri, const char *format, va_list ap) if (format[strlen(format)] != '\n') n += snprintf(buf + n, BUFSIZ - n, "\n"); - if ((log_written + n >= log_size) && logfile_rotate(log_file, &ts)) + if ((log_written + n >= log_size) && logfile_rotate(log_file, &now)) return; if ((n = write(log_file, buf, n)) >= 0) diff --git a/tcp.c b/tcp.c index 422770f..1628896 100644 --- a/tcp.c +++ b/tcp.c @@ -3180,13 +3180,13 @@ static int tcp_port_rebind_outbound(void *arg) /** * tcp_timer() - Periodic tasks: port detection, closed connections, pool refill * @c: Execution context - * @ts: Unused + * @now: Current timestamp */ -void tcp_timer(struct ctx *c, const struct timespec *ts) +void tcp_timer(struct ctx *c, const struct timespec *now) { union flow *flow; - (void)ts; + (void)now; if (c->mode == MODE_PASTA) { if (c->tcp.fwd_out.mode == FWD_AUTO) { diff --git a/tcp.h b/tcp.h index 27b1166..594d71a 100644 --- a/tcp.h +++ b/tcp.h @@ -20,7 +20,7 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af, int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr, const char *ifname, in_port_t port); int tcp_init(struct ctx *c); -void tcp_timer(struct ctx *c, const struct timespec *ts); +void tcp_timer(struct ctx *c, const struct timespec *now); void tcp_defer_handler(struct ctx *c); void tcp_sock_set_bufsize(const struct ctx *c, int s); diff --git a/udp.c b/udp.c index 1f8c306..0b4582c 100644 --- a/udp.c +++ b/udp.c @@ -1140,10 +1140,10 @@ int udp_init(struct ctx *c) * @v6: Set for IPv6 connections * @type: Socket type * @port: Port number, host order - * @ts: Timestamp from caller + * @now: Current timestamp */ static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type, - in_port_t port, const struct timespec *ts) + in_port_t port, const struct timespec *now) { struct udp_splice_port *sp; struct udp_tap_port *tp; @@ -1153,7 +1153,7 @@ static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type, case UDP_ACT_TAP: tp = &udp_tap_map[v6 ? V6 : V4][port]; - if (ts->tv_sec - tp->ts > UDP_CONN_TIMEOUT) { + if (now->tv_sec - tp->ts > UDP_CONN_TIMEOUT) { sockp = &tp->sock; tp->flags = 0; } @@ -1162,14 +1162,14 @@ static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type, case UDP_ACT_SPLICE_INIT: sp = &udp_splice_init[v6 ? V6 : V4][port]; - if (ts->tv_sec - sp->ts > UDP_CONN_TIMEOUT) + if (now->tv_sec - sp->ts > UDP_CONN_TIMEOUT) sockp = &sp->sock; break; case UDP_ACT_SPLICE_NS: sp = &udp_splice_ns[v6 ? V6 : V4][port]; - if (ts->tv_sec - sp->ts > UDP_CONN_TIMEOUT) + if (now->tv_sec - sp->ts > UDP_CONN_TIMEOUT) sockp = &sp->sock; break; @@ -1249,9 +1249,9 @@ static int udp_port_rebind_outbound(void *arg) /** * udp_timer() - Scan activity bitmaps for ports with associated timed events * @c: Execution context - * @ts: Timestamp from caller + * @now: Current timestamp */ -void udp_timer(struct ctx *c, const struct timespec *ts) +void udp_timer(struct ctx *c, const struct timespec *now) { int n, t, v6 = 0; unsigned int i; @@ -1281,7 +1281,7 @@ v6: tmp = *word; while ((n = ffsl(tmp))) { tmp &= ~(1UL << (n - 1)); - udp_timer_one(c, v6, t, i * 8 + n - 1, ts); + udp_timer_one(c, v6, t, i * 8 + n - 1, now); } } } diff --git a/udp.h b/udp.h index 85ebaaa..087e482 100644 --- a/udp.h +++ b/udp.h @@ -17,7 +17,7 @@ int udp_tap_handler(struct ctx *c, uint8_t pif, int af, int udp_sock_init(const struct ctx *c, int ns, sa_family_t af, const void *addr, const char *ifname, in_port_t port); int udp_init(struct ctx *c); -void udp_timer(struct ctx *c, const struct timespec *ts); +void udp_timer(struct ctx *c, const struct timespec *now); void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s); /** -- 2.43.0