From 8d27c203ed40e5bbdc4585a384f99aca10a1a434 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 6 Apr 2021 16:55:17 +0200 Subject: [PATCH] MEDIUM: fd: prepare FD_POLL_* to move to bits 8-15 In preparation of merging FD_POLL* and FD_EV*, this only changes the value of FD_POLL_* to use bits 8-15 (the second byte). The size of the field has been temporarily extended to 32 bits already, as well as the temporary variables that carry the new composite value inside fd_update_events(). The resulting fdtab entry becomes temporarily unaligned. All places making access to .ev or FD_POLL_* were carefully inspected to make sure they were safe regarding this change. Only one temporary update was needed for the "show fd" code. The code was only slightly inflated at this step. --- include/haproxy/fd-t.h | 12 ++++++------ include/haproxy/fd.h | 6 +++--- src/cli.c | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/haproxy/fd-t.h b/include/haproxy/fd-t.h index 53bc528a6..27266dce9 100644 --- a/include/haproxy/fd-t.h +++ b/include/haproxy/fd-t.h @@ -36,11 +36,11 @@ enum { * FD_POLL_OUT remains set as long as the fd accepts to write data. * FD_POLL_ERR and FD_POLL_ERR remain set forever (until processed). */ -#define FD_POLL_IN 0x01 -#define FD_POLL_PRI 0x02 -#define FD_POLL_OUT 0x04 -#define FD_POLL_ERR 0x08 -#define FD_POLL_HUP 0x10 +#define FD_POLL_IN 0x00000100 +#define FD_POLL_PRI 0x00000200 +#define FD_POLL_OUT 0x00000400 +#define FD_POLL_ERR 0x00000800 +#define FD_POLL_HUP 0x00001000 #define FD_POLL_UPDT_MASK (FD_POLL_IN | FD_POLL_PRI | FD_POLL_OUT) @@ -128,7 +128,7 @@ struct fdtab { void (*iocb)(int fd); /* I/O handler */ void *owner; /* the connection or listener associated with this fd, NULL if closed */ unsigned char state; /* FD state for read and write directions (FD_EV_*) */ - unsigned char ev; /* event seen in return of poll() : FD_POLL_* */ + unsigned int ev; /* event seen in return of poll() : FD_POLL_* */ unsigned char linger_risk:1; /* 1 if we must kill lingering before closing */ unsigned char cloned:1; /* 1 if a cloned socket, requires EPOLL_CTL_DEL on close */ unsigned char initialized:1; /* 1 if init phase was done on this fd (e.g. set non-blocking) */ diff --git a/include/haproxy/fd.h b/include/haproxy/fd.h index 09fe24cfd..4863c4aa2 100644 --- a/include/haproxy/fd.h +++ b/include/haproxy/fd.h @@ -354,11 +354,11 @@ static inline long fd_clr_running(int fd) * doesn't need to also pass FD_EV_SHUT_*, it's implied. ERR and SHUT are * allowed to be reported regardless of R/W readiness. */ -static inline void fd_update_events(int fd, unsigned char evts) +static inline void fd_update_events(int fd, uint evts) { unsigned long locked = atleast2(fdtab[fd].thread_mask); - unsigned char old, new; - int new_flags, must_stop; + uint old, new; + uint new_flags, must_stop; new_flags = ((evts & FD_EV_READY_R) ? FD_POLL_IN : 0) | diff --git a/src/cli.c b/src/cli.c index 2e4da522f..1e4520353 100644 --- a/src/cli.c +++ b/src/cli.c @@ -1197,7 +1197,7 @@ static int cli_io_handler_show_fd(struct appctx *appctx) (fdt.state & FD_EV_ACTIVE_R) ? 'A' : 'a', (fdt.state & FD_EV_READY_W) ? 'R' : 'r', (fdt.state & FD_EV_ACTIVE_W) ? 'A' : 'a', - fdt.ev, + fdt.ev >> 8, (fdt.ev & FD_POLL_HUP) ? 'H' : 'h', (fdt.ev & FD_POLL_ERR) ? 'E' : 'e', (fdt.ev & FD_POLL_OUT) ? 'O' : 'o',