MEDIUM: fd: prepare FD_POLL_* to move to bits 8-15
authorWilly Tarreau <w@1wt.eu>
Tue, 6 Apr 2021 14:55:17 +0000 (16:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Apr 2021 13:08:40 +0000 (15:08 +0200)
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
include/haproxy/fd.h
src/cli.c

index 53bc528..27266dc 100644 (file)
@@ -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) */
index 09fe24c..4863c4a 100644 (file)
@@ -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) |
index 2e4da52..1e45203 100644 (file)
--- 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',