summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2019-08-09 15:06:34 +1000
committerKarolin Seeger <kseeger@samba.org>2019-08-28 09:12:16 +0000
commit4cf26ff2ec350db6b3ad5fa08dea602b3b842baf (patch)
treeba00ae961e7602f1427e7bb18f6a0aa17a6bab2d /ctdb
parent0b4a99c22f5e72d2bc6e2770b070e964866db148 (diff)
downloadsamba-4cf26ff2ec350db6b3ad5fa08dea602b3b842baf.tar.gz
ctdb-tcp: Rename fd -> out_fd
in_fd is coming soon. Fix coding style violations in the affected and adjacent lines. Modernise some debug macros and make them more consistent (e.g. drop logging of errno when strerror(errno) is already logged. 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 c06620169fc178ea6db2631f03edf008285d8cf2)
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/tcp/ctdb_tcp.h2
-rw-r--r--ctdb/tcp/tcp_connect.c97
-rw-r--r--ctdb/tcp/tcp_init.c22
3 files changed, 72 insertions, 49 deletions
diff --git a/ctdb/tcp/ctdb_tcp.h b/ctdb/tcp/ctdb_tcp.h
index 0a998c94da4..acd343fb8f3 100644
--- a/ctdb/tcp/ctdb_tcp.h
+++ b/ctdb/tcp/ctdb_tcp.h
@@ -39,7 +39,7 @@ struct ctdb_incoming {
state associated with one tcp node
*/
struct ctdb_tcp_node {
- int fd;
+ int out_fd;
struct ctdb_queue *out_queue;
struct tevent_fd *connect_fde;
struct tevent_timer *connect_te;
diff --git a/ctdb/tcp/tcp_connect.c b/ctdb/tcp/tcp_connect.c
index d757abdf26c..4253f3bef7c 100644
--- a/ctdb/tcp/tcp_connect.c
+++ b/ctdb/tcp/tcp_connect.c
@@ -50,9 +50,9 @@ void ctdb_tcp_stop_connection(struct ctdb_node *node)
talloc_free(tnode->connect_fde);
tnode->connect_fde = NULL;
tnode->connect_te = NULL;
- if (tnode->fd != -1) {
- close(tnode->fd);
- tnode->fd = -1;
+ if (tnode->out_fd != -1) {
+ close(tnode->out_fd);
+ tnode->out_fd = -1;
}
}
@@ -93,12 +93,13 @@ static void ctdb_node_connect_write(struct tevent_context *ev,
int error = 0;
socklen_t len = sizeof(error);
int one = 1;
+ int ret;
talloc_free(tnode->connect_te);
tnode->connect_te = NULL;
- if (getsockopt(tnode->fd, SOL_SOCKET, SO_ERROR, &error, &len) != 0 ||
- error != 0) {
+ ret = getsockopt(tnode->out_fd, SOL_SOCKET, SO_ERROR, &error, &len);
+ if (ret != 0 || error != 0) {
ctdb_tcp_stop_connection(node);
tnode->connect_te = tevent_add_timer(ctdb->ev, tnode,
timeval_current_ofs(1, 0),
@@ -109,19 +110,28 @@ static void ctdb_node_connect_write(struct tevent_context *ev,
talloc_free(tnode->connect_fde);
tnode->connect_fde = NULL;
- if (setsockopt(tnode->fd,IPPROTO_TCP,TCP_NODELAY,(char *)&one,sizeof(one)) == -1) {
- DEBUG(DEBUG_WARNING, ("Failed to set TCP_NODELAY on fd - %s\n",
- strerror(errno)));
+ ret = setsockopt(tnode->out_fd,
+ IPPROTO_TCP,
+ TCP_NODELAY,
+ (char *)&one,
+ sizeof(one));
+ if (ret == -1) {
+ DBG_WARNING("Failed to set TCP_NODELAY on fd - %s\n",
+ strerror(errno));
}
- if (setsockopt(tnode->fd,SOL_SOCKET,SO_KEEPALIVE,(char *)&one,sizeof(one)) == -1) {
- DEBUG(DEBUG_WARNING, ("Failed to set KEEPALIVE on fd - %s\n",
- strerror(errno)));
+ ret = setsockopt(tnode->out_fd,
+ SOL_SOCKET,
+ SO_KEEPALIVE,(char *)&one,
+ sizeof(one));
+ if (ret == -1) {
+ DBG_WARNING("Failed to set KEEPALIVE on fd - %s\n",
+ strerror(errno));
}
- ctdb_queue_set_fd(tnode->out_queue, tnode->fd);
+ ctdb_queue_set_fd(tnode->out_queue, tnode->out_fd);
/* the queue subsystem now owns this fd */
- tnode->fd = -1;
+ tnode->out_fd = -1;
/* tell the ctdb layer we are connected */
node->ctdb->upcalls->node_connected(node);
@@ -149,26 +159,24 @@ void ctdb_tcp_node_connect(struct tevent_context *ev, struct tevent_timer *te,
sock_out = node->address;
- tnode->fd = socket(sock_out.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
- if (tnode->fd == -1) {
- DEBUG(DEBUG_ERR, (__location__ " Failed to create socket\n"));
+ tnode->out_fd = socket(sock_out.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
+ if (tnode->out_fd == -1) {
+ DBG_ERR("Failed to create socket\n");
return;
}
- ret = set_blocking(tnode->fd, false);
+ ret = set_blocking(tnode->out_fd, false);
if (ret != 0) {
- DEBUG(DEBUG_ERR,
- (__location__
- " failed to set socket non-blocking (%s)\n",
- strerror(errno)));
- close(tnode->fd);
- tnode->fd = -1;
+ DBG_ERR("Failed to set socket non-blocking (%s)\n",
+ strerror(errno));
+ close(tnode->out_fd);
+ tnode->out_fd = -1;
return;
}
- set_close_on_exec(tnode->fd);
+ set_close_on_exec(tnode->out_fd);
- DEBUG(DEBUG_DEBUG, (__location__ " Created TCP SOCKET FD:%d\n", tnode->fd));
+ DBG_DEBUG("Created TCP SOCKET FD:%d\n", tnode->out_fd);
/* Bind our side of the socketpair to the same address we use to listen
* on incoming CTDB traffic.
@@ -197,39 +205,48 @@ void ctdb_tcp_node_connect(struct tevent_context *ev, struct tevent_timer *te,
default:
DEBUG(DEBUG_ERR, (__location__ " unknown family %u\n",
sock_in.sa.sa_family));
- close(tnode->fd);
- tnode->fd = -1;
+ close(tnode->out_fd);
+ tnode->out_fd = -1;
return;
}
- if (bind(tnode->fd, (struct sockaddr *)&sock_in, sockin_size) == -1) {
- DEBUG(DEBUG_ERR, (__location__ " Failed to bind socket %s(%d)\n",
- strerror(errno), errno));
- close(tnode->fd);
- tnode->fd = -1;
+ ret = bind(tnode->out_fd, (struct sockaddr *)&sock_in, sockin_size);
+ if (ret == -1) {
+ DBG_ERR("Failed to bind socket (%s)\n", strerror(errno));
+ close(tnode->out_fd);
+ tnode->out_fd = -1;
return;
}
- if (connect(tnode->fd, (struct sockaddr *)&sock_out, sockout_size) != 0 &&
- errno != EINPROGRESS) {
+ ret = connect(tnode->out_fd,
+ (struct sockaddr *)&sock_out,
+ sockout_size);
+ if (ret != 0 && errno != EINPROGRESS) {
ctdb_tcp_stop_connection(node);
- tnode->connect_te = tevent_add_timer(ctdb->ev, tnode,
+ tnode->connect_te = tevent_add_timer(ctdb->ev,
+ tnode,
timeval_current_ofs(1, 0),
- ctdb_tcp_node_connect, node);
+ ctdb_tcp_node_connect,
+ node);
return;
}
/* non-blocking connect - wait for write event */
- tnode->connect_fde = tevent_add_fd(node->ctdb->ev, tnode, tnode->fd,
+ tnode->connect_fde = tevent_add_fd(node->ctdb->ev,
+ tnode,
+ tnode->out_fd,
TEVENT_FD_WRITE|TEVENT_FD_READ,
- ctdb_node_connect_write, node);
+ ctdb_node_connect_write,
+ node);
/* don't give it long to connect - retry in one second. This ensures
that we find a node is up quickly (tcp normally backs off a syn reply
delay by quite a lot) */
- tnode->connect_te = tevent_add_timer(ctdb->ev, tnode,
+ tnode->connect_te = tevent_add_timer(ctdb->ev,
+ tnode,
timeval_current_ofs(1, 0),
- ctdb_tcp_node_connect, node);
+ ctdb_tcp_node_connect,
+ node);
}
/*
diff --git a/ctdb/tcp/tcp_init.c b/ctdb/tcp/tcp_init.c
index 87d628aba93..6b1299f32b5 100644
--- a/ctdb/tcp/tcp_init.c
+++ b/ctdb/tcp/tcp_init.c
@@ -38,16 +38,16 @@ static int tnode_destructor(struct ctdb_tcp_node *tnode)
{
// struct ctdb_node *node = talloc_find_parent_bytype(tnode, struct ctdb_node);
- if (tnode->fd != -1) {
- close(tnode->fd);
- tnode->fd = -1;
+ if (tnode->out_fd != -1) {
+ close(tnode->out_fd);
+ tnode->out_fd = -1;
}
return 0;
}
/*
- initialise tcp portion of a ctdb node
+ initialise tcp portion of a ctdb node
*/
static int ctdb_tcp_add_node(struct ctdb_node *node)
{
@@ -55,13 +55,19 @@ static int ctdb_tcp_add_node(struct ctdb_node *node)
tnode = talloc_zero(node, struct ctdb_tcp_node);
CTDB_NO_MEMORY(node->ctdb, tnode);
- tnode->fd = -1;
+ tnode->out_fd = -1;
node->private_data = tnode;
talloc_set_destructor(tnode, tnode_destructor);
- tnode->out_queue = ctdb_queue_setup(node->ctdb, node, tnode->fd, CTDB_TCP_ALIGNMENT,
- ctdb_tcp_tnode_cb, node, "to-node-%s", node->name);
-
+ 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;
}