]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: listeners: remove the do_close argument to unbind_listener()
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2020 13:55:23 +0000 (15:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Oct 2020 16:41:56 +0000 (18:41 +0200)
And also remove it from its callers. This subtle distinction was added as
sort of a hack for the seamless reload feature but is not needed anymore
since the do_close turned unused since commit previous commit ("MEDIUM:
listener: let do_unbind_listener() decide whether to close or not").
This also removes the unbind_listener_no_close() function.

include/haproxy/listener.h
src/listener.c
src/mworker.c
src/proto_uxst.c

index bb6f38f9f48716156a10d092df6da2f98171ac65..c30dc73fd93cd83d3510427aa3d730c0fe5b4cad 100644 (file)
@@ -71,23 +71,23 @@ void dequeue_all_listeners();
 /* Dequeues all listeners waiting for a resource in proxy <px>'s queue */
 void dequeue_proxy_listeners(struct proxy *px);
 
-/* Must be called with the lock held. Depending on <do_close> value, it does
- * what unbind_listener or unbind_listener_no_close should do.
+/* This function closes the listening socket for the specified listener,
+ * provided that it's already in a listening state. The listener enters the
+ * LI_ASSIGNED state, except if the FD is not closed, in which case it may
+ * remain in LI_LISTEN. Depending on the process' status (master or worker),
+ * the listener's bind options and the receiver's origin, it may or may not
+ * close the receiver's FD. Must be called with the lock held.
  */
-void do_unbind_listener(struct listener *listener, int do_close);
+void do_unbind_listener(struct listener *listener);
 
 /* This function closes the listening socket for the specified listener,
  * provided that it's already in a listening state. The listener enters the
- * LI_ASSIGNED state. This function is intended to be used as a generic
+ * LI_ASSIGNED state, except if the FD is not closed, in which case it may
+ * remain in LI_LISTEN. This function is intended to be used as a generic
  * function for standard protocols.
  */
 void unbind_listener(struct listener *listener);
 
-/* This function pretends the listener is dead, but keeps the FD opened, so
- * that we can provide it, for conf reloading.
- */
-void unbind_listener_no_close(struct listener *listener);
-
 /* creates one or multiple listeners for bind_conf <bc> on sockaddr <ss> on port
  * range <portl> to <porth>, and possibly attached to fd <fd> (or -1 for auto
  * allocation). The address family is taken from ss->ss_family, and the protocol
index 5002879dceb198ee67c0b082c130771e143b7c24..94db9579e5a0ad5be00aa6ce46beb33ecafabc65 100644 (file)
@@ -289,7 +289,7 @@ void enable_listener(struct listener *listener)
         */
        if ((master && !(listener->options & LI_O_MWORKER)) ||
            (!master && (listener->options & LI_O_MWORKER))) {
-               do_unbind_listener(listener, 1);
+               do_unbind_listener(listener);
        }
 
        if (listener->state == LI_LISTEN) {
@@ -299,12 +299,7 @@ void enable_listener(struct listener *listener)
                        /* we don't want to enable this listener and don't
                         * want any fd event to reach it.
                         */
-                       if (!(global.tune.options & GTUNE_SOCKET_TRANSFER))
-                               do_unbind_listener(listener, 1);
-                       else {
-                               do_unbind_listener(listener, 0);
-                               listener_set_state(listener, LI_LISTEN);
-                       }
+                       do_unbind_listener(listener);
                }
                else if (!listener->maxconn || listener->nbconn < listener->maxconn) {
                        listener->rx.proto->enable(listener);
@@ -329,7 +324,6 @@ void enable_listener(struct listener *listener)
 void stop_listener(struct listener *l, int lpx, int lpr, int lli)
 {
        struct proxy *px = l->bind_conf->frontend;
-       int must_close;
 
        if (l->options & LI_O_NOSTOP) {
                /* master-worker sockpairs are never closed but don't count as a
@@ -338,16 +332,6 @@ void stop_listener(struct listener *l, int lpx, int lpr, int lli)
                return;
        }
 
-       /* There are several cases where we must not close an FD:
-        *   - we're starting up and we have socket transfers enabled;
-        *   - we're the master and this FD was inherited;
-        */
-       if ((global.tune.options & GTUNE_SOCKET_TRANSFER && global.mode & MODE_STARTING) ||
-           (master && (l->rx.flags & RX_F_INHERITED)))
-               must_close = 0;
-       else
-               must_close = 1;
-
        if (!lpx)
                HA_SPIN_LOCK(PROXY_LOCK, &px->lock);
 
@@ -358,7 +342,7 @@ void stop_listener(struct listener *l, int lpx, int lpr, int lli)
                HA_SPIN_LOCK(LISTENER_LOCK, &l->lock);
 
        if (l->state > LI_INIT) {
-               do_unbind_listener(l, must_close);
+               do_unbind_listener(l);
 
                if (l->state >= LI_ASSIGNED)
                        __delete_listener(l);
@@ -556,11 +540,14 @@ void dequeue_proxy_listeners(struct proxy *px)
        }
 }
 
-/* Must be called with the lock held. Depending on <do_close> value, it does
- * what unbind_listener or unbind_listener_no_close should do. It can also
- * close a zombie listener's FD when called in early states.
+/* This function closes the listening socket for the specified listener,
+ * provided that it's already in a listening state. The listener enters the
+ * LI_ASSIGNED state, except if the FD is not closed, in which case it may
+ * remain in LI_LISTEN. Depending on the process' status (master or worker),
+ * the listener's bind options and the receiver's origin, it may or may not
+ * close the receiver's FD. Must be called with the lock held.
  */
-void do_unbind_listener(struct listener *listener, int do_close)
+void do_unbind_listener(struct listener *listener)
 {
        MT_LIST_DEL(&listener->wait_queue);
 
@@ -611,23 +598,14 @@ void do_unbind_listener(struct listener *listener, int do_close)
 
 /* This function closes the listening socket for the specified listener,
  * provided that it's already in a listening state. The listener enters the
- * LI_ASSIGNED state. This function is intended to be used as a generic
+ * LI_ASSIGNED state, except if the FD is not closed, in which case it may
+ * remain in LI_LISTEN. This function is intended to be used as a generic
  * function for standard protocols.
  */
 void unbind_listener(struct listener *listener)
 {
        HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
-       do_unbind_listener(listener, 1);
-       HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
-}
-
-/* This function pretends the listener is dead, but keeps the FD opened, so
- * that we can provide it, for conf reloading.
- */
-void unbind_listener_no_close(struct listener *listener)
-{
-       HA_SPIN_LOCK(LISTENER_LOCK, &listener->lock);
-       do_unbind_listener(listener, 0);
+       do_unbind_listener(listener);
        HA_SPIN_UNLOCK(LISTENER_LOCK, &listener->lock);
 }
 
index 2ef7e7dd742c42b2f2270a2b421a02b9361740d3..f3147a18b3b128e577c15b19d115c6c5da60c989 100644 (file)
@@ -423,13 +423,7 @@ void mworker_cleanlisteners()
                list_for_each_entry_safe(l, l_next, &curproxy->conf.listeners, by_fe) {
                        /* remove the listener, but not those we need in the master... */
                        if (!(l->options & LI_O_MWORKER)) {
-                               /* unbind the listener but does not close if
-                                  the FD is inherited with fd@ from the parent
-                                  process */
-                               if (l->rx.flags & RX_F_INHERITED)
-                                       unbind_listener_no_close(l);
-                               else
-                                       unbind_listener(l);
+                               unbind_listener(l);
                                delete_listener(l);
                        } else {
                                listen_in_master = 1;
index 4ec672ffc393e61ac443edc8198934e3bcaba5c5..250c630189311ff09e33895f467493574f78fb66 100644 (file)
@@ -185,7 +185,7 @@ static int uxst_suspend_receiver(struct receiver *rx)
 
        /* Listener's lock already held. Call lockless version of
         * unbind_listener. */
-       do_unbind_listener(l, 1);
+       do_unbind_listener(l);
        return 0;
 }