summaryrefslogtreecommitdiff
path: root/source3/lib/ctdbd_conn.c
diff options
context:
space:
mode:
authorRalph Boehme <slow@samba.org>2016-07-09 08:48:49 +0200
committerRalph Boehme <slow@samba.org>2016-07-11 20:05:06 +0200
commit1184931001be983b858f44468aeb083140d924ad (patch)
treea9d0483b3b9255d438d71d1d2125a1ea8e8807e0 /source3/lib/ctdbd_conn.c
parent2f95ada1494b19eec02e86eaf3f9270fa8b08318 (diff)
downloadsamba-1184931001be983b858f44468aeb083140d924ad.tar.gz
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 <slow@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'source3/lib/ctdbd_conn.c')
-rw-r--r--source3/lib/ctdbd_conn.c47
1 files changed, 31 insertions, 16 deletions
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;
}