ctdb-daemon: Change ctdb_add_local_iface() to return struct ctdb_interface
authorMartin Schwenke <martin@meltin.net>
Wed, 24 Aug 2016 06:59:46 +0000 (16:59 +1000)
committerAmitay Isaacs <amitay@samba.org>
Thu, 8 Sep 2016 04:57:20 +0000 (06:57 +0200)
This will allow a change to the way interfaces are handled in a VNN.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/server/ctdb_takeover.c

index f34803217f0b3b79c28e5920eda7199a2929bc5f..a1d4db69ad966cb072d2c8292277abb5b3c9178f 100644 (file)
@@ -98,19 +98,20 @@ static const char *ctdb_vnn_iface_string(const struct ctdb_vnn *vnn)
        return iface_string(vnn->iface);
 }
 
-static int ctdb_add_local_iface(struct ctdb_context *ctdb, const char *iface)
+static struct ctdb_interface *
+ctdb_add_local_iface(struct ctdb_context *ctdb, const char *iface)
 {
        struct ctdb_interface *i;
 
        if (strlen(iface) > CTDB_IFACE_SIZE) {
                DEBUG(DEBUG_ERR, ("Interface name too long \"%s\"\n", iface));
-               return -1;
+               return NULL;
        }
 
        /* Verify that we don't have an entry for this ip yet */
        for (i=ctdb->ifaces;i;i=i->next) {
                if (strcmp(i->name, iface) == 0) {
-                       return 0;
+                       return i;
                }
        }
 
@@ -118,20 +119,20 @@ static int ctdb_add_local_iface(struct ctdb_context *ctdb, const char *iface)
        i = talloc_zero(ctdb, struct ctdb_interface);
        if (i == NULL) {
                DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
-               return -1;
+               return NULL;
        }
        i->name = talloc_strdup(i, iface);
        if (i->name == NULL) {
                DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
                talloc_free(i);
-               return -1;
+               return NULL;
        }
 
        i->link_up = true;
 
        DLIST_ADD(ctdb->ifaces, i);
 
-       return 0;
+       return i;
 }
 
 static bool vnn_has_interface_with_name(struct ctdb_vnn *vnn,
@@ -1052,7 +1053,6 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
        uint32_t num = 0;
        char *tmp;
        const char *iface;
-       int ret;
 
        /* Verify that we don't have an entry for this IP yet */
        for (vnn = ctdb->vnn; vnn != NULL; vnn = vnn->next) {
@@ -1083,6 +1083,7 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
                return -1;
        }
        for (iface = strtok(tmp, ","); iface; iface = strtok(NULL, ",")) {
+               struct ctdb_interface *i;
                if (!ctdb_sys_check_iface_exists(iface)) {
                        DEBUG(DEBUG_ERR,
                              ("Unknown interface %s for public address %s\n",
@@ -1091,8 +1092,8 @@ static int ctdb_add_public_address(struct ctdb_context *ctdb,
                        return -1;
                }
 
-               ret = ctdb_add_local_iface(ctdb, iface);
-               if (ret != 0) {
+               i = ctdb_add_local_iface(ctdb, iface);
+               if (i == NULL) {
                        DEBUG(DEBUG_ERR,
                              ("Failed to add interface '%s' "
                               "for public address %s\n",