]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tcp: Create outbound queue when the connection becomes writable
authorMartin Schwenke <martin@meltin.net>
Thu, 15 Aug 2019 05:57:31 +0000 (15:57 +1000)
committerKarolin Seeger <kseeger@samba.org>
Wed, 28 Aug 2019 07:36:30 +0000 (07:36 +0000)
Since commit ddd97553f0a8bfaada178ec4a7460d76fa21f079
ctdb_queue_send() doesn't queue a packet if the connection isn't yet
established (i.e. when fd == -1).  So, don't bother creating the
outbound queue during initialisation but create it when the connection
becomes writable.

Now the presence of the queue indicates that the outbound connection
is up.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14084

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
(cherry picked from commit 7f4854d9643a096a6d8a354fcd27b7c6ed24a75e)

ctdb/tcp/tcp_connect.c
ctdb/tcp/tcp_init.c
ctdb/tcp/tcp_io.c

index f2d036fb5f7e875e30dead60e512f93adba41fc9..15ce73103b9f633035f5f3719c4418e2a28a8e0b 100644 (file)
@@ -44,8 +44,8 @@ void ctdb_tcp_stop_connection(struct ctdb_node *node)
 {
        struct ctdb_tcp_node *tnode = talloc_get_type(
                node->private_data, struct ctdb_tcp_node);
-       
-       ctdb_queue_set_fd(tnode->out_queue, -1);
+
+       TALLOC_FREE(tnode->out_queue);
        TALLOC_FREE(tnode->connect_te);
        TALLOC_FREE(tnode->connect_fde);
        if (tnode->out_fd != -1) {
@@ -126,7 +126,24 @@ static void ctdb_node_connect_write(struct tevent_context *ev,
                            strerror(errno));
        }
 
-       ctdb_queue_set_fd(tnode->out_queue, tnode->out_fd);
+       tnode->out_queue = ctdb_queue_setup(node->ctdb,
+                                           tnode,
+                                           tnode->out_fd,
+                                           CTDB_TCP_ALIGNMENT,
+                                           ctdb_tcp_tnode_cb,
+                                           node,
+                                           "to-node-%s",
+                                           node->name);
+       if (tnode->out_queue == NULL) {
+               DBG_ERR("Failed to set up outgoing queue\n");
+               ctdb_tcp_stop_connection(node);
+               tnode->connect_te = tevent_add_timer(ctdb->ev,
+                                                    tnode,
+                                                    timeval_current_ofs(1, 0),
+                                                    ctdb_tcp_node_connect,
+                                                    node);
+               return;
+       }
 
        /* the queue subsystem now owns this fd */
        tnode->out_fd = -1;
index ec45d645c834c0f45ab854f1baae44136f9cd158..91d4e992c8f39c996da32723969d5a625d191884 100644 (file)
@@ -67,15 +67,6 @@ static int ctdb_tcp_add_node(struct ctdb_node *node)
        node->private_data = tnode;
        talloc_set_destructor(tnode, tnode_destructor);
 
-       tnode->out_queue = ctdb_queue_setup(node->ctdb,
-                                           node,
-                                           tnode->out_fd,
-                                           CTDB_TCP_ALIGNMENT,
-                                           ctdb_tcp_tnode_cb,
-                                           node,
-                                           "to-node-%s",
-                                           node->name);
-
        return 0;
 }
 
index be4558b16ea3bc28f352d931e7fa2f93feab9295..e33ed44048ea9e66c1b5413b0b061c65f4431857 100644 (file)
@@ -87,5 +87,10 @@ int ctdb_tcp_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length)
 {
        struct ctdb_tcp_node *tnode = talloc_get_type(node->private_data,
                                                      struct ctdb_tcp_node);
+       if (tnode->out_queue == NULL) {
+               DBG_DEBUG("No outgoing connection, dropping packet\n");
+               return 0;
+       }
+
        return ctdb_queue_send(tnode->out_queue, data, length);
 }