]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: poller: program the update in fd_update_events() for a migrated FD
authorWilly Tarreau <w@1wt.eu>
Sat, 9 Jul 2022 16:55:37 +0000 (18:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 15 Jul 2022 17:43:10 +0000 (19:43 +0200)
When an FD is migrated, all pollers program an update. That's useless
code duplication, and when thread groups will be supported, this will
require an extra round of locking just to verify the update_mask on
return. Let's just program the update direction from fd_update_events()
as it already does for closed FDs, this becomes more logical.

src/ev_epoll.c
src/ev_evports.c
src/ev_kqueue.c
src/ev_poll.c
src/fd.c

index 1917ed1acae585f914f05047d9e89609e99e2163..354a18793a0ddc99faf05b5d28d257216b767670 100644 (file)
@@ -214,7 +214,6 @@ static void _do_poll(struct poller *p, int exp, int wake)
 
        for (count = 0; count < status; count++) {
                unsigned int n, e;
-               int ret;
 
                e = epoll_events[count].events;
                fd = epoll_events[count].data.fd;
@@ -231,13 +230,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
                    ((e & EPOLLHUP)   ? FD_EV_SHUT_RW : 0) |
                    ((e & EPOLLERR)   ? FD_EV_ERR_RW  : 0);
 
-               ret = fd_update_events(fd, n);
-
-               if (ret == FD_UPDT_MIGRATED) {
-                       /* FD has been migrated */
-                       if (!HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
-                               fd_updt[fd_nbupdt++] = fd;
-               }
+               fd_update_events(fd, n);
        }
        /* the caller will take care of cached events */
 }
index 301e86eef948901f28eec396f53c9ce1af1209e7..05c9ebccaba6702bf76a726d5801d36f5626eb54 100644 (file)
@@ -244,12 +244,9 @@ static void _do_poll(struct poller *p, int exp, int wake)
                 */
                ret = fd_update_events(fd, n);
 
-               /* disable polling on this instance if the FD was migrated */
-               if (ret == FD_UPDT_MIGRATED) {
-                       if (!HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
-                               fd_updt[fd_nbupdt++] = fd;
+               /* polling will be on this instance if the FD was migrated */
+               if (ret == FD_UPDT_MIGRATED)
                        continue;
-               }
 
                /*
                 * This file descriptor was closed during the processing of
index 43643fb38754d46435ae100f2e2c6eb7ac1bdd94..ff377625baea6c2b4d50db068fddb4d06dcff08d 100644 (file)
@@ -178,7 +178,6 @@ static void _do_poll(struct poller *p, int exp, int wake)
 
        for (count = 0; count < status; count++) {
                unsigned int n = 0;
-               int ret;
 
                fd = kev[count].ident;
 
@@ -197,13 +196,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
                                n |= FD_EV_ERR_RW;
                }
 
-               ret = fd_update_events(fd, n);
-
-               if (ret == FD_UPDT_MIGRATED) {
-                       /* FD was migrated, let's stop polling it */
-                       if (!HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
-                               fd_updt[fd_nbupdt++] = fd;
-               }
+               fd_update_events(fd, n);
        }
 }
 
index 92e45a634fb9a92089ad7385137c8da6e1791023..3cc41dc687078c48a8370b8553eee424c2974d0a 100644 (file)
@@ -213,8 +213,8 @@ static void _do_poll(struct poller *p, int exp, int wake)
 
        for (count = 0; status > 0 && count < nbfd; count++) {
                unsigned int n;
-               int ret;
                int e = poll_events[count].revents;
+
                fd = poll_events[count].fd;
 
                if ((e & POLLRDHUP) && !(cur_poller.flags & HAP_POLL_F_RDHUP))
@@ -235,13 +235,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
                    ((e & POLLHUP)   ? FD_EV_SHUT_RW : 0) |
                    ((e & POLLERR)   ? FD_EV_ERR_RW  : 0);
 
-               ret = fd_update_events(fd, n);
-
-               if (ret == FD_UPDT_MIGRATED) {
-                       /* FD was migrated, let's stop polling it */
-                       if (!HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
-                               fd_updt[fd_nbupdt++] = fd;
-               }
+               fd_update_events(fd, n);
        }
 }
 
index 29a14135f01320646d6d15e5929d15100b8354e3..ee6cbd2a7b4999e01d872390a0f7cd5bc8a63bbd 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -483,6 +483,10 @@ int fd_update_events(int fd, uint evts)
                if (!(tmask & tid_bit)) {
                        /* a takeover has started */
                        activity[tid].poll_skip_fd++;
+
+                       /* Let the poller know this FD was lost */
+                       if (!HA_ATOMIC_BTS(&fdtab[fd].update_mask, tid))
+                               fd_updt[fd_nbupdt++] = fd;
                        return FD_UPDT_MIGRATED;
                }
        } while (!HA_ATOMIC_CAS(&fdtab[fd].running_mask, &rmask, rmask | tid_bit));