]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdbd_conn: split ctdbd_init_connection()
authorRalph Boehme <slow@samba.org>
Sat, 9 Jul 2016 06:48:49 +0000 (08:48 +0200)
committerRalph Boehme <slow@samba.org>
Mon, 11 Jul 2016 18:05:06 +0000 (20:05 +0200)
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>
source3/lib/ctdbd_conn.c

index d073c72df088aa6e186aa534992ec64028f69be1..db7bb80c475477aa99031a3c23ecea0027888224 100644 (file)
@@ -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;
        }