From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>
Subject: [PATCH v3 2/6] tcp: cleanup timer creation
Date: Fri, 9 Jan 2026 17:54:34 +0100 [thread overview]
Message-ID: <20260109165438.2492285-3-lvivier@redhat.com> (raw)
In-Reply-To: <20260109165438.2492285-1-lvivier@redhat.com>
Refactor tcp_timer_ctl() to use the epoll_add() helper instead of
manually constructing epoll_event and calling epoll_ctl() directly.
Also separate the error handling for timerfd_create() failure (-1)
from fd overflow (> FD_REF_MAX) to provide more specific debug
messages. The overflow case now logs the actual fd value, using
flow_dbg_perror() in this case was not correct (no errno set).
Delay setting conn->timer until epoll_add() succeeds, removing
redundant conn->timer = -1 assignments in error paths since the
timer is already -1 when we enter this block.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
tcp.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/tcp.c b/tcp.c
index 5141cdc7e839..4b746b4ca16c 100644
--- a/tcp.c
+++ b/tcp.c
@@ -569,30 +569,32 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn)
return;
if (conn->timer == -1) {
- union epoll_ref ref = { .type = EPOLL_TYPE_TCP_TIMER,
- .flow = FLOW_IDX(conn) };
- struct epoll_event ev = { .data.u64 = ref.u64,
- .events = EPOLLIN | EPOLLET };
- int epollfd = flow_epollfd(&conn->f);
+ union epoll_ref ref;
int fd;
fd = timerfd_create(CLOCK_MONOTONIC, 0);
- if (fd == -1 || fd > FD_REF_MAX) {
+ if (fd == -1) {
flow_dbg_perror(conn, "failed to get timer");
- if (fd > -1)
- close(fd);
- conn->timer = -1;
return;
}
- conn->timer = fd;
- ref.fd = conn->timer;
+ if (fd > FD_REF_MAX) {
+ flow_dbg(conn, "timer fd overflow (%d > %d)",
+ fd, FD_REF_MAX);
+ close(fd);
+ return;
+ }
- if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn->timer, &ev)) {
- flow_dbg_perror(conn, "failed to add timer");
- close(conn->timer);
- conn->timer = -1;
+ ref.type = EPOLL_TYPE_TCP_TIMER;
+ ref.flow = FLOW_IDX(conn);
+ ref.fd = fd;
+ if (epoll_add(flow_epollfd(&conn->f), EPOLLIN | EPOLLET,
+ ref) < 0) {
+ flow_dbg(conn, "failed to add timer");
+ close(fd);
return;
}
+
+ conn->timer = fd;
}
if (conn->flags & ACK_TO_TAP_DUE) {
--
2.52.0
next prev parent reply other threads:[~2026-01-09 16:54 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-09 16:54 [PATCH v3 0/6] flow: Introduce flow_epoll_set() to centralize epoll operations Laurent Vivier
2026-01-09 16:54 ` [PATCH v3 1/6] tcp: remove timer update in tcp_epoll_ctl() Laurent Vivier
2026-01-09 16:54 ` Laurent Vivier [this message]
2026-01-09 16:54 ` [PATCH v3 3/6] udp_flow: remove unneeded epoll_ref indirection Laurent Vivier
2026-01-09 16:54 ` [PATCH v3 4/6] udp_flow: Assign socket to flow inside udp_flow_sock() Laurent Vivier
2026-01-09 16:54 ` [PATCH v3 5/6] tcp_splice: Refactor tcp_splice_conn_epoll_events() to per-side computation Laurent Vivier
2026-01-09 16:54 ` [PATCH v3 6/6] flow: Introduce flow_epoll_set() to centralize epoll operations Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260109165438.2492285-3-lvivier@redhat.com \
--to=lvivier@redhat.com \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).