]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: fd: move .linger_risk into fdtab[].state
authorWilly Tarreau <w@1wt.eu>
Tue, 6 Apr 2021 15:49:19 +0000 (17:49 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 7 Apr 2021 16:07:49 +0000 (18:07 +0200)
No need to keep this flag apart any more, let's merge it into the global
state. The CLI's output state was extended to 6 digits and the linger/cloned
flags moved inside the parenthesis.

15 files changed:
include/haproxy/connection.h
include/haproxy/fd-t.h
include/haproxy/fd.h
src/cli.c
src/fd.c
src/proto_quic.c
src/proto_sockpair.c
src/proto_tcp.c
src/proto_uxst.c
src/raw_sock.c
src/session.c
src/sock.c
src/tcp_act.c
src/tcpcheck.c
src/xprt_quic.c

index bccb1abee3e0f3999c97eb8964886210b5270c0f..7011193c22c40302f6f6f99ac432010eee34797b 100644 (file)
@@ -178,7 +178,7 @@ static inline void conn_sock_read0(struct connection *c)
                /* we don't risk keeping ports unusable if we found the
                 * zero from the other side.
                 */
-               fdtab[c->handle.fd].linger_risk = 0;
+               HA_ATOMIC_AND(&fdtab[c->handle.fd].state, ~FD_LINGER_RISK);
        }
 }
 
index 97ae5002b7bff00214376f36fe3654e04eefacca..d15a97715d9841b7c13cbbecd293c0ed5232fa0f 100644 (file)
@@ -62,6 +62,9 @@ enum {
 #define FD_POLL_ERR_BIT   11
 #define FD_POLL_HUP_BIT   12
 
+/* info/config bits */
+#define FD_LINGER_RISK_BIT 16  /* must kill lingering before closing */
+
 
 /* and flag values */
 #define FD_EV_ACTIVE_R  (1U << FD_EV_ACTIVE_R_BIT)
@@ -94,6 +97,8 @@ enum {
 #define FD_POLL_UPDT_MASK   (FD_POLL_IN | FD_POLL_PRI | FD_POLL_OUT)
 #define FD_POLL_ANY_MASK    (FD_POLL_IN | FD_POLL_PRI | FD_POLL_OUT | FD_POLL_ERR | FD_POLL_HUP)
 
+/* information/configuration flags */
+#define FD_LINGER_RISK      (1U << FD_LINGER_RISK_BIT)
 
 /* This is the value used to mark a file descriptor as dead. This value is
  * negative, this is important so that tests on fd < 0 properly match. It
@@ -142,7 +147,6 @@ struct fdtab {
        void (*iocb)(int fd);                /* I/O handler */
        void *owner;                         /* the connection or listener associated with this fd, NULL if closed */
        unsigned int state;                  /* FD state for read and write directions (FD_EV_*) + 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) */
        unsigned char et_possible:1;         /* 1 if edge-triggered is possible on this FD */
index 6d6da691898e460856e52d26f29cded8f82a59d6..df9df1607aebcf417d1cb9df21d058bb2a345cdb 100644 (file)
@@ -433,7 +433,6 @@ static inline void fd_insert(int fd, void *owner, void (*iocb)(int fd), unsigned
        fdtab[fd].owner = owner;
        fdtab[fd].iocb = iocb;
        fdtab[fd].state = 0;
-       fdtab[fd].linger_risk = 0;
        fdtab[fd].cloned = 0;
        fdtab[fd].et_possible = 0;
        fdtab[fd].exported = 0;
index 76956e5c2d98cf147c39d5e29589e273fdacd263..7c1b0291ef4d447043c80251ec66c889cc1176ca 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1190,7 +1190,7 @@ static int cli_io_handler_show_fd(struct appctx *appctx)
                        suspicious = 1;
 
                chunk_printf(&trash,
-                            "  %5d : st=0x%04x(R:%c%c W:%c%c %c%c%c%c%c) [%c%c] tmask=0x%lx umask=0x%lx owner=%p iocb=%p(",
+                            "  %5d : st=0x%06x(R:%c%c W:%c%c %c%c%c%c%c %c%c) tmask=0x%lx umask=0x%lx owner=%p iocb=%p(",
                             fd,
                             fdt.state,
                             (fdt.state & FD_EV_READY_R)  ? 'R' : 'r',
@@ -1202,7 +1202,7 @@ static int cli_io_handler_show_fd(struct appctx *appctx)
                             (fdt.state & FD_POLL_OUT) ? 'O' : 'o',
                             (fdt.state & FD_POLL_PRI) ? 'P' : 'p',
                             (fdt.state & FD_POLL_IN)  ? 'I' : 'i',
-                            fdt.linger_risk ? 'L' : 'l',
+                            (fdt.state & FD_LINGER_RISK) ? 'L' : 'l',
                             fdt.cloned ? 'C' : 'c',
                             fdt.thread_mask, fdt.update_mask,
                             fdt.owner,
index f206d2a621211ada4d9bf74937d50ebc61468809..e29814b628dc2fb541a602255ddd0435e774e43b 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -302,7 +302,7 @@ done:
  */
 void _fd_delete_orphan(int fd)
 {
-       if (fdtab[fd].linger_risk) {
+       if (fdtab[fd].state & FD_LINGER_RISK) {
                /* this is generally set when connecting to servers */
                DISGUISE(setsockopt(fd, SOL_SOCKET, SO_LINGER,
                           (struct linger *) &nolinger, sizeof(struct linger)));
index dac7c2389a2f624ec534e954156f410dd4a91c65..1cac5ab62f02f79867a7b9fd56b5b2034f3a27c0 100644 (file)
@@ -497,7 +497,7 @@ int quic_connect_server(struct connection *conn, int flags)
        conn->flags |= CO_FL_ADDR_TO_SET;
 
        conn_ctrl_init(conn);       /* registers the FD */
-       fdtab[fd].linger_risk = 1;  /* close hard if needed */
+       HA_ATOMIC_OR(&fdtab[fd].state, FD_LINGER_RISK);  /* close hard if needed */
 
        if (conn->flags & CO_FL_WAIT_L4_CONN) {
                fd_want_send(fd);
index 48659c769ba52faa210be808cff218e0009209b2..0cb9ab1e9bd35a99b30fde28ab7bb1d52291c1eb 100644 (file)
@@ -362,7 +362,7 @@ static int sockpair_connect_server(struct connection *conn, int flags)
                conn->flags |= CO_FL_SEND_PROXY;
 
        conn_ctrl_init(conn);       /* registers the FD */
-       fdtab[fd].linger_risk = 0;  /* no need to disable lingering */
+       HA_ATOMIC_AND(&fdtab[fd].state, ~FD_LINGER_RISK);  /* no need to disable lingering */
 
        return SF_ERR_NONE;  /* connection is OK */
 }
index 1317d31377e5ba40ae847436b1d4e7ee33b112c1..1edbea42ac2e0a68207e00a9f966370c27968d33 100644 (file)
@@ -557,7 +557,7 @@ int tcp_connect_server(struct connection *conn, int flags)
        conn->flags |= CO_FL_ADDR_TO_SET;
 
        conn_ctrl_init(conn);       /* registers the FD */
-       fdtab[fd].linger_risk = 1;  /* close hard if needed */
+       HA_ATOMIC_OR(&fdtab[fd].state, FD_LINGER_RISK);  /* close hard if needed */
 
        if (conn->flags & CO_FL_WAIT_L4_CONN) {
                fd_want_send(fd);
index 8156eb8049805c7ef6e7d73a73b4822697f8168d..efa7af9510f4be84c4fcb040aa84db9db723b9b2 100644 (file)
@@ -346,7 +346,7 @@ static int uxst_connect_server(struct connection *conn, int flags)
                conn->flags |= CO_FL_SEND_PROXY;
 
        conn_ctrl_init(conn);       /* registers the FD */
-       fdtab[fd].linger_risk = 0;  /* no need to disable lingering */
+       HA_ATOMIC_AND(&fdtab[fd].state, ~FD_LINGER_RISK);  /* no need to disable lingering */
 
        if (conn->flags & CO_FL_WAIT_L4_CONN) {
                fd_want_send(fd);
index 6d5c8855111123923480902d6acea684ead466b6..a078f2d11a1d78c4ab046d88b73345acfd2eb44a 100644 (file)
@@ -285,7 +285,7 @@ static size_t raw_sock_to_buf(struct connection *conn, void *xprt_ctx, struct bu
                                if (fdtab[conn->handle.fd].state & FD_POLL_HUP)
                                        goto read0;
 
-                               if ((!fdtab[conn->handle.fd].linger_risk) ||
+                               if (!(fdtab[conn->handle.fd].state & FD_LINGER_RISK) ||
                                    (cur_poller.flags & HAP_POLL_F_RDHUP)) {
                                        break;
                                }
index f78c2dfa4d5572e1826a9b35a2c120091db42a92..f4593ba16bf7144d079d4904048091519a9a2bc6 100644 (file)
@@ -209,7 +209,7 @@ int session_accept_fd(struct connection *cli_conn)
                }
 
                if (p->options & PR_O_TCP_NOLING)
-                       fdtab[cfd].linger_risk = 1;
+                       HA_ATOMIC_OR(&fdtab[cfd].state, FD_LINGER_RISK);
 
 #if defined(TCP_MAXSEG)
                if (l->maxseg < 0) {
index 19191c82e073e2cc68cfec2e3634f076feba0aa9..14b15a39e4e4854e0cff216f07e0ad1ed2c54979 100644 (file)
@@ -726,8 +726,8 @@ int sock_conn_check(struct connection *conn)
        /* Write error on the file descriptor. Report it to the connection
         * and disable polling on this FD.
         */
-       fdtab[fd].linger_risk = 0;
        conn->flags |= CO_FL_ERROR | CO_FL_SOCK_RD_SH | CO_FL_SOCK_WR_SH;
+       HA_ATOMIC_AND(&fdtab[fd].state, ~FD_LINGER_RISK);
        fd_stop_both(fd);
        return 0;
 
@@ -870,7 +870,7 @@ int sock_drain(struct connection *conn)
 
  shut:
        /* we're certain the connection was shut down */
-       fdtab[fd].linger_risk = 0;
+       HA_ATOMIC_AND(&fdtab[fd].state, ~FD_LINGER_RISK);
        return 1;
 }
 
index 46157c1026afe3364ce2b75e5502cdb986276b64..fb6b82faa4dd3ac0937ecf1c30170fe0da0c0e9c 100644 (file)
@@ -194,7 +194,7 @@ static enum act_return tcp_exec_action_silent_drop(struct act_rule *rule, struct
        /* We're on the client-facing side, we must force to disable lingering to
         * ensure we will use an RST exclusively and kill any pending data.
         */
-       fdtab[conn->handle.fd].linger_risk = 1;
+       HA_ATOMIC_OR(&fdtab[conn->handle.fd].state, FD_LINGER_RISK);
 
 #ifdef TCP_REPAIR
        if (setsockopt(conn->handle.fd, IPPROTO_TCP, TCP_REPAIR, &one, sizeof(one)) == 0) {
index 52b47eed478b689b779224b58e162682c0e5d98a..a99ec0907be8de323a8b3069406ab34fae3500bb 100644 (file)
@@ -1128,7 +1128,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct tcpchec
 
        if (conn_ctrl_ready(conn) && (connect->options & TCPCHK_OPT_LINGER)) {
                /* Some servers don't like reset on close */
-               fdtab[cs->conn->handle.fd].linger_risk = 0;
+               HA_ATOMIC_AND(&fdtab[cs->conn->handle.fd].state, ~FD_LINGER_RISK);
        }
 
        if (conn_ctrl_ready(conn) && (conn->flags & (CO_FL_SEND_PROXY | CO_FL_SOCKS4))) {
index 862499ccd7fbb7adca07e35bc17872403570f80f..2d51a994ea9f2f2655be47f9982ca38ebb6ded03 100644 (file)
@@ -3933,7 +3933,7 @@ static size_t quic_conn_to_buf(struct connection *conn, void *xprt_ctx, struct b
                                if (fdtab[conn->handle.fd].state & FD_POLL_HUP)
                                        goto read0;
 
-                               if ((!fdtab[conn->handle.fd].linger_risk) ||
+                               if (!(fdtab[conn->handle.fd].state & FD_LINGER_RISK) ||
                                    (cur_poller.flags & HAP_POLL_F_RDHUP)) {
                                        break;
                                }