From 1184931001be983b858f44468aeb083140d924ad Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Sat, 9 Jul 2016 08:48:49 +0200 Subject: ctdbd_conn: split ctdbd_init_connection() Split ctdbd_init_connection() into an internal function that does the connection setup and only keep the conn object allocation in ctdbd_init_connection(). This is in preperation of adding ctdbd_reinit_connection() which will use the new internal function as well. Signed-off-by: Ralph Boehme Reviewed-by: Volker Lendecke --- source3/lib/ctdbd_conn.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) (limited to 'source3/lib/ctdbd_conn.c') diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c index d073c72df08..db7bb80c475 100644 --- a/source3/lib/ctdbd_conn.c +++ b/source3/lib/ctdbd_conn.c @@ -405,20 +405,13 @@ static int ctdbd_connection_destructor(struct ctdbd_connection *c) * Get us a ctdbd connection */ -int ctdbd_init_connection(TALLOC_CTX *mem_ctx, - const char *sockname, int timeout, - struct ctdbd_connection **pconn) +static int ctdbd_init_connection_internal(TALLOC_CTX *mem_ctx, + const char *sockname, int timeout, + struct ctdbd_connection *conn) { - struct ctdbd_connection *conn; int ret; - if (!(conn = talloc_zero(mem_ctx, struct ctdbd_connection))) { - DEBUG(0, ("talloc failed\n")); - return ENOMEM; - } - conn->timeout = timeout; - if (conn->timeout == 0) { conn->timeout = -1; } @@ -426,31 +419,53 @@ int ctdbd_init_connection(TALLOC_CTX *mem_ctx, ret = ctdbd_connect(sockname, &conn->fd); if (ret != 0) { DEBUG(1, ("ctdbd_connect failed: %s\n", strerror(ret))); - goto fail; + return ret; } talloc_set_destructor(conn, ctdbd_connection_destructor); ret = get_cluster_vnn(conn, &conn->our_vnn); - if (ret != 0) { DEBUG(10, ("get_cluster_vnn failed: %s\n", strerror(ret))); - goto fail; + return ret; } if (!ctdbd_working(conn, conn->our_vnn)) { DEBUG(2, ("Node is not working, can not connect\n")); - ret = EIO; - goto fail; + return EIO; } generate_random_buffer((unsigned char *)&conn->rand_srvid, sizeof(conn->rand_srvid)); ret = register_with_ctdbd(conn, conn->rand_srvid, NULL, NULL); - if (ret != 0) { DEBUG(5, ("Could not register random srvid: %s\n", strerror(ret))); + return ret; + } + + return 0; +} + +int ctdbd_init_connection(TALLOC_CTX *mem_ctx, + const char *sockname, int timeout, + struct ctdbd_connection **pconn) +{ + struct ctdbd_connection *conn; + int ret; + + if (!(conn = talloc_zero(mem_ctx, struct ctdbd_connection))) { + DEBUG(0, ("talloc failed\n")); + return ENOMEM; + } + + ret = ctdbd_init_connection_internal(mem_ctx, + sockname, + timeout, + conn); + if (ret != 0) { + DBG_ERR("ctdbd_init_connection_internal failed (%s)\n", + strerror(ret)); goto fail; } -- cgit v1.2.1