]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: add a generation number to file descriptors
authorWilly Tarreau <w@1wt.eu>
Thu, 30 Jan 2025 15:25:40 +0000 (16:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 30 Jan 2025 18:45:34 +0000 (19:45 +0100)
This patch adds a counter of close() on file descriptors in the fdtab.
The goal is to better detect if reported events concern the current or
a previous file descriptor. For now the counter is only added, and is
showed in "show fd" as "gen". We're reusing unused space at the end of
the struct. If it's needed for something more important later, this
patch can be reverted.

include/haproxy/fd-t.h
src/cli.c
src/fd.c

index c2b2aee2067c7ed8bf13659f39d59ff7798b29ad..5fa3689b4404a6ca0777e5a8370378be1ee6cb70 100644 (file)
@@ -198,6 +198,7 @@ struct fdtab {
         * if the room is needed for more important stuff.
         */
        unsigned int nb_takeover;            /* number of times this FD was taken over since inserted (used for debugging) */
+       unsigned int generation;             /* number of times this FD was closed before (used for epoll strengthening) */
 #ifdef DEBUG_FD
        unsigned int event_count;            /* number of events reported */
 #endif
index d00b5b2410a465c22b57069d8750de7396d20ad3..84aa46fbee31322a25db66fcc4ed5ce63dd0c0d1 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1415,7 +1415,7 @@ static int cli_io_handler_show_fd(struct appctx *appctx)
                        suspicious = 1;
 
                chunk_printf(&trash,
-                            "  %5d : st=0x%06x(%c%c %c%c%c%c%c W:%c%c%c R:%c%c%c) ref=%#x gid=%d tmask=0x%lx umask=0x%lx prmsk=0x%lx pwmsk=0x%lx owner=%p tkov=%u iocb=%p(",
+                            "  %5d : st=0x%06x(%c%c %c%c%c%c%c W:%c%c%c R:%c%c%c) ref=%#x gid=%d tmask=0x%lx umask=0x%lx prmsk=0x%lx pwmsk=0x%lx owner=%p gen=%u tkov=%u iocb=%p(",
                             fd,
                             fdt.state,
                             (fdt.state & FD_CLONED) ? 'C' : 'c',
@@ -1437,6 +1437,7 @@ static int cli_io_handler_show_fd(struct appctx *appctx)
                             polled_mask[fd].poll_recv,
                             polled_mask[fd].poll_send,
                             fdt.owner,
+                            fdt.generation,
                             fdt.nb_takeover,
                             fdt.iocb);
                resolve_sym_name(&trash, NULL, fdt.iocb);
index bf4241ba2131600039576e1787b01f01a4835635..97d58e797fdac3c91797d9e6f3d06a7c1d2de6c8 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -355,8 +355,10 @@ void _fd_delete_orphan(int fd)
        /* perform the close() call last as it's what unlocks the instant reuse
         * of this FD by any other thread.
         */
-       if (!fd_disown)
+       if (!fd_disown) {
+               fdtab[fd].generation++;
                close(fd);
+       }
        _HA_ATOMIC_DEC(&ha_used_fds);
 }